#include "portable.h"
#include <stdio.h>
#include <ac/unistd.h>
#include <ac/string.h>
#include "slurp.h"
#include "globals.h"
#define FC_DIRBAD 1
#define FC_DIRUNREAD 2
#define FC_DIRUNWRITE 4
#define FC_FILEBAD 8
#define FC_FILEUNREAD 16
#define FC_FILEUNWRITE 32
static unsigned int filecheck LDAP_P(( char * ));
int
sanity( void )
{
int err = 0;
int rc;
if ( sglob->replicas == NULL ) {
fprintf( stderr, "No replicas in slapd.conf file \"%s\"!\n",
sglob->slapd_configfile );
err++;
}
if ( sglob->slapd_replogfile == NULL ) {
fprintf( stderr, "Fatal error: no \"replogfile\" "
"slapd.conf directive given\n" );
err++;
} else {
rc = filecheck( sglob->slapd_replogfile );
if ( rc & FC_DIRBAD ) {
fprintf( stderr, "Error: %s: directory specified in "
"\"replogfile\" slapd.conf directive does not exist\n",
sglob->slapd_replogfile );
err++;
} else if ( rc & FC_DIRUNREAD ) {
fprintf( stderr, "Error: %s: directory specified in "
"\"replogfile\" slapd.conf directive is not readable\n",
sglob->slapd_replogfile );
err++;
} else if (!( rc & FC_FILEBAD) && ( rc & FC_FILEUNREAD )) {
fprintf( stderr, "Error: %s: file specified in "
"\"replogfile\" slapd.conf directive is not readable\n",
sglob->slapd_replogfile );
err++;
}
}
if ( sglob->slurpd_replogfile == NULL ) {
fprintf( stderr, "Fatal error: no \"replogfile\" directive given\n" );
err++;
} else {
rc = filecheck( sglob->slurpd_replogfile );
if ( rc & FC_DIRBAD ) {
fprintf( stderr, "Error: %s: slurpd \"replogfile\" "
"directory does not exist\n",
sglob->slurpd_replogfile );
err++;
} else if ( rc & FC_DIRUNREAD ) {
fprintf( stderr, "Error: %s: slurpd \"replogfile\" "
"directory not readable\n",
sglob->slurpd_replogfile );
err++;
} else if ( !( rc & FC_FILEBAD ) && ( rc & FC_FILEUNREAD )) {
fprintf( stderr, "Error: %s: slurpd \"replogfile\" not readable\n",
sglob->slurpd_replogfile );
err++;
} else if ( !( rc & FC_FILEBAD ) && ( rc & FC_FILEUNWRITE )) {
fprintf( stderr, "Error: %s: slurpd \"replogfile\" not writeable\n",
sglob->slurpd_replogfile );
err++;
}
}
rc = filecheck( sglob->slurpd_status_file );
if ( rc & FC_DIRBAD ) {
fprintf( stderr, "Error: %s: status directory does not exist\n",
sglob->slurpd_status_file );
err++;
} else if ( rc & FC_DIRUNREAD ) {
fprintf( stderr, "Error: %s: status directory not readable\n",
sglob->slurpd_status_file );
err++;
} else if ( !( rc & FC_FILEBAD ) && ( rc & FC_FILEUNREAD )) {
fprintf( stderr, "Error: %s: status file not readable\n",
sglob->slurpd_status_file );
err++;
} else if ( !( rc & FC_FILEBAD ) && ( rc & FC_FILEUNWRITE )) {
fprintf( stderr, "Error: %s: status file not writeable\n",
sglob->slurpd_status_file );
err++;
}
return ( err == 0 ? 0 : -1 );
}
static unsigned int
filecheck(
char *f
)
{
char dir[ MAXPATHLEN ];
char *p;
unsigned int ret = 0;
strcpy( dir, f );
p = strrchr( dir, '/' );
if ( p != NULL ) {
*p = '\0';
}
if ( access( dir, F_OK ) < 0 ) {
ret |= FC_DIRBAD;
}
if ( access( dir, R_OK ) < 0 ) {
ret |= FC_DIRUNREAD;
}
if ( access( dir, W_OK ) < 0 ) {
ret |= FC_DIRUNWRITE;
}
if ( access( f, F_OK ) < 0 ) {
ret |= FC_FILEBAD;
}
if ( access( f, R_OK ) < 0 ) {
ret |= FC_FILEUNREAD;
}
if ( access( f, W_OK ) < 0 ) {
ret |= FC_FILEUNWRITE;
}
return ret;
}