2008-11-11 07:15:35 +08:00
|
|
|
/* $OpenLDAP$ */
|
2004-03-18 07:25:09 +08:00
|
|
|
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
|
|
|
|
*
|
2017-01-04 04:36:47 +08:00
|
|
|
* Copyright 2004-2017 The OpenLDAP Foundation.
|
2004-03-18 07:25:09 +08:00
|
|
|
* Portions Copyright 2004 Pierangelo Masarati.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted only as authorized by the OpenLDAP
|
|
|
|
* Public License.
|
|
|
|
*
|
|
|
|
* A copy of this license is available in file LICENSE in the
|
|
|
|
* top-level directory of the distribution or, alternatively, at
|
|
|
|
* <http://www.OpenLDAP.org/license.html>.
|
|
|
|
*/
|
|
|
|
/* ACKNOWLEDGEMENTS:
|
|
|
|
* This work was initially developed by Pierangelo Masarati for inclusion
|
|
|
|
* in OpenLDAP Software.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "portable.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include <ac/stdlib.h>
|
|
|
|
|
|
|
|
#include <ac/ctype.h>
|
|
|
|
#include <ac/string.h>
|
|
|
|
#include <ac/socket.h>
|
2005-11-01 02:48:12 +08:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
2004-03-18 07:25:09 +08:00
|
|
|
#include <ac/unistd.h>
|
2005-11-01 02:48:12 +08:00
|
|
|
#include <ac/errno.h>
|
2004-03-18 07:25:09 +08:00
|
|
|
|
|
|
|
#include <lber.h>
|
|
|
|
#include <ldif.h>
|
|
|
|
#include <lutil.h>
|
|
|
|
|
|
|
|
#include "slapcommon.h"
|
|
|
|
|
2011-10-13 10:19:52 +08:00
|
|
|
#ifndef S_IWRITE
|
|
|
|
#define S_IWRITE S_IWUSR
|
|
|
|
#endif
|
|
|
|
|
2005-11-01 02:48:12 +08:00
|
|
|
static int
|
|
|
|
test_file( const char *fname, const char *ftype )
|
|
|
|
{
|
|
|
|
struct stat st;
|
|
|
|
int save_errno;
|
|
|
|
|
|
|
|
switch ( stat( fname, &st ) ) {
|
|
|
|
case 0:
|
2006-09-14 15:29:46 +08:00
|
|
|
if ( !( st.st_mode & S_IWRITE ) ) {
|
2005-11-01 02:48:12 +08:00
|
|
|
Debug( LDAP_DEBUG_ANY, "%s file "
|
|
|
|
"\"%s\" exists, but user does not have access\n",
|
|
|
|
ftype, fname, 0 );
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case -1:
|
|
|
|
default:
|
|
|
|
save_errno = errno;
|
|
|
|
if ( save_errno == ENOENT ) {
|
|
|
|
FILE *fp = fopen( fname, "w" );
|
|
|
|
|
|
|
|
if ( fp == NULL ) {
|
|
|
|
save_errno = errno;
|
|
|
|
|
|
|
|
Debug( LDAP_DEBUG_ANY, "unable to open file "
|
|
|
|
"\"%s\": %d (%s)\n",
|
|
|
|
fname,
|
|
|
|
save_errno, strerror( save_errno ) );
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
2006-03-31 20:20:04 +08:00
|
|
|
fclose( fp );
|
2005-11-01 02:48:12 +08:00
|
|
|
unlink( fname );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
Debug( LDAP_DEBUG_ANY, "unable to stat file "
|
|
|
|
"\"%s\": %d (%s)\n",
|
|
|
|
slapd_pid_file,
|
|
|
|
save_errno, strerror( save_errno ) );
|
|
|
|
return -1;
|
|
|
|
}
|
2005-11-07 07:27:09 +08:00
|
|
|
|
|
|
|
return 0;
|
2005-11-01 02:48:12 +08:00
|
|
|
}
|
|
|
|
|
2004-03-18 07:25:09 +08:00
|
|
|
int
|
|
|
|
slaptest( int argc, char **argv )
|
|
|
|
{
|
|
|
|
int rc = EXIT_SUCCESS;
|
|
|
|
const char *progname = "slaptest";
|
|
|
|
|
|
|
|
slap_tool_init( progname, SLAPTEST, argc, argv );
|
|
|
|
|
2005-11-01 02:48:12 +08:00
|
|
|
if ( slapd_pid_file != NULL ) {
|
|
|
|
if ( test_file( slapd_pid_file, "pid" ) ) {
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( slapd_args_file != NULL ) {
|
|
|
|
if ( test_file( slapd_args_file, "args" ) ) {
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-08-14 21:42:40 +08:00
|
|
|
if ( !quiet ) {
|
|
|
|
fprintf( stderr, "config file testing succeeded\n");
|
|
|
|
}
|
2004-03-18 07:25:09 +08:00
|
|
|
|
2008-11-03 21:23:05 +08:00
|
|
|
if ( slap_tool_destroy())
|
|
|
|
rc = EXIT_FAILURE;
|
2004-03-18 07:25:09 +08:00
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|