X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=servers%2Fslapd%2Fslaptest.c;h=ca10c7a6c7e2543192b227d47926f20158c13b87;hb=eb6b2650091656bde96fbbdb87a5b8154cdc319b;hp=2bd5d1b0f383b2b3aadcbbca57d4da7df2dfa487;hpb=dc0eacd40b625258355eea866d62188e5aa7ce3b;p=openldap
diff --git a/servers/slapd/slaptest.c b/servers/slapd/slaptest.c
index 2bd5d1b0f3..ca10c7a6c7 100644
--- a/servers/slapd/slaptest.c
+++ b/servers/slapd/slaptest.c
@@ -1,6 +1,6 @@
/* This work is part of OpenLDAP Software .
*
- * Copyright 2004-2005 The OpenLDAP Foundation.
+ * Copyright 2004-2007 The OpenLDAP Foundation.
* Portions Copyright 2004 Pierangelo Masarati.
* All rights reserved.
*
@@ -26,7 +26,10 @@
#include
#include
#include
+#include
+#include
#include
+#include
#include
#include
@@ -34,6 +37,53 @@
#include "slapcommon.h"
+static int
+test_file( const char *fname, const char *ftype )
+{
+ struct stat st;
+ int save_errno;
+
+ switch ( stat( fname, &st ) ) {
+ case 0:
+ if ( !( st.st_mode & S_IWRITE ) ) {
+ 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;
+ }
+ fclose( fp );
+ 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;
+ }
+
+ return 0;
+}
+
int
slaptest( int argc, char **argv )
{
@@ -42,6 +92,18 @@ slaptest( int argc, char **argv )
slap_tool_init( progname, SLAPTEST, argc, argv );
+ 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;
+ }
+ }
+
fprintf( stderr, "config file testing succeeded\n");
slap_tool_destroy();