1999-09-09 03:06:24 +08:00
|
|
|
/* $OpenLDAP$ */
|
2001-01-21 01:49:05 +08:00
|
|
|
/*
|
2002-01-05 05:17:25 +08:00
|
|
|
* Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
|
2001-01-21 01:49:05 +08:00
|
|
|
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
|
|
|
|
*/
|
1998-08-09 08:43:13 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1996 Regents of the University of Michigan.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms are permitted
|
|
|
|
* provided that this notice is preserved and that due credit is given
|
|
|
|
* to the University of Michigan at Ann Arbor. The name of the University
|
|
|
|
* may not be used to endorse or promote products derived from this
|
|
|
|
* software without specific prior written permission. This software
|
|
|
|
* is provided ``as is'' without express or implied warranty.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* sanity.c - perform sanity checks on the environment at startup time,
|
|
|
|
* and report any errors before we disassociate from the controlling tty,
|
|
|
|
* start up our threads, and do other stuff which makes it hard to give
|
|
|
|
* feedback to the users.
|
|
|
|
*/
|
|
|
|
|
1998-10-25 09:41:42 +08:00
|
|
|
#include "portable.h"
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
#include <stdio.h>
|
1998-10-25 09:41:42 +08:00
|
|
|
|
2002-05-16 18:51:45 +08:00
|
|
|
#include <ac/stdlib.h>
|
1998-10-25 09:41:42 +08:00
|
|
|
#include <ac/unistd.h>
|
|
|
|
#include <ac/string.h>
|
1998-08-09 08:43:13 +08:00
|
|
|
|
|
|
|
#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
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Forward declarations
|
|
|
|
*/
|
1998-10-25 09:41:42 +08:00
|
|
|
static unsigned int filecheck LDAP_P(( char * ));
|
1998-08-09 08:43:13 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Take a look around to catch any fatal errors. For example, make sure the
|
|
|
|
* destination directory for our working files exists, check that all
|
|
|
|
* pathnames make sense, and so on. Returns 0 is everything's ok,
|
|
|
|
# -1 if there's something wrong which will keep us from functioning
|
|
|
|
* correctly.
|
|
|
|
*
|
|
|
|
* We do all these checks at startup so we can print a reasonable error
|
|
|
|
* message on stderr before we disassociate from the controlling tty. This
|
|
|
|
* keeps some fatal error messages from "disappearing" into syslog.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
Protoized, moved extern definitions to .h files, fixed related bugs.
Most function and variable definitions are now preceded by its extern
definition, for error checking. Retyped a number of functions, usually
to return void. Fixed a number of printf format errors.
API changes (in ldap/include):
Added avl_dup_ok, avl_prefixapply, removed ber_fatten (probably typo
for ber_flatten), retyped ldap_sort_strcasecmp, grew lutil.h.
A number of `extern' declarations are left (some added by protoize), to
be cleaned away later. Mostly strdup(), strcasecmp(), mktemp(), optind,
optarg, errno.
1998-11-16 06:40:11 +08:00
|
|
|
sanity( void )
|
1998-08-09 08:43:13 +08:00
|
|
|
{
|
|
|
|
int err = 0;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Are there any replicas listed in the slapd config file?
|
|
|
|
*/
|
|
|
|
if ( sglob->replicas == NULL ) {
|
2000-08-18 08:58:00 +08:00
|
|
|
fprintf( stderr, "No replicas in slapd.conf file \"%s\"!\n",
|
1998-08-09 08:43:13 +08:00
|
|
|
sglob->slapd_configfile );
|
|
|
|
err++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Make sure the directory housing the slapd replogfile exists, and
|
|
|
|
* that the slapd replogfile is readable, if it exists.
|
|
|
|
*/
|
|
|
|
if ( sglob->slapd_replogfile == NULL ) {
|
2000-08-18 08:58:00 +08:00
|
|
|
fprintf( stderr, "Fatal error: no \"replogfile\" "
|
|
|
|
"slapd.conf directive given\n" );
|
1998-08-09 08:43:13 +08:00
|
|
|
err++;
|
|
|
|
} else {
|
|
|
|
rc = filecheck( sglob->slapd_replogfile );
|
|
|
|
if ( rc & FC_DIRBAD ) {
|
2000-08-18 08:58:00 +08:00
|
|
|
fprintf( stderr, "Error: %s: directory specified in "
|
|
|
|
"\"replogfile\" slapd.conf directive does not exist\n",
|
1998-08-09 08:43:13 +08:00
|
|
|
sglob->slapd_replogfile );
|
|
|
|
err++;
|
|
|
|
} else if ( rc & FC_DIRUNREAD ) {
|
2000-08-18 08:58:00 +08:00
|
|
|
fprintf( stderr, "Error: %s: directory specified in "
|
|
|
|
"\"replogfile\" slapd.conf directive is not readable\n",
|
1998-08-09 08:43:13 +08:00
|
|
|
sglob->slapd_replogfile );
|
|
|
|
err++;
|
|
|
|
} else if (!( rc & FC_FILEBAD) && ( rc & FC_FILEUNREAD )) {
|
2000-08-18 08:58:00 +08:00
|
|
|
fprintf( stderr, "Error: %s: file specified in "
|
|
|
|
"\"replogfile\" slapd.conf directive is not readable\n",
|
1998-08-09 08:43:13 +08:00
|
|
|
sglob->slapd_replogfile );
|
|
|
|
err++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Make sure the directory for the slurpd replogfile is there, and
|
|
|
|
* that the slurpd replogfile is readable and writable, if it exists.
|
|
|
|
*/
|
|
|
|
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 ) {
|
2000-08-18 08:58:00 +08:00
|
|
|
fprintf( stderr, "Error: %s: slurpd \"replogfile\" "
|
|
|
|
"directory does not exist\n",
|
1998-08-09 08:43:13 +08:00
|
|
|
sglob->slurpd_replogfile );
|
|
|
|
err++;
|
|
|
|
} else if ( rc & FC_DIRUNREAD ) {
|
2000-08-18 08:58:00 +08:00
|
|
|
fprintf( stderr, "Error: %s: slurpd \"replogfile\" "
|
|
|
|
"directory not readable\n",
|
1998-08-09 08:43:13 +08:00
|
|
|
sglob->slurpd_replogfile );
|
|
|
|
err++;
|
|
|
|
} else if ( !( rc & FC_FILEBAD ) && ( rc & FC_FILEUNREAD )) {
|
2000-08-18 08:58:00 +08:00
|
|
|
fprintf( stderr, "Error: %s: slurpd \"replogfile\" not readable\n",
|
1998-08-09 08:43:13 +08:00
|
|
|
sglob->slurpd_replogfile );
|
|
|
|
err++;
|
|
|
|
} else if ( !( rc & FC_FILEBAD ) && ( rc & FC_FILEUNWRITE )) {
|
2000-08-18 08:58:00 +08:00
|
|
|
fprintf( stderr, "Error: %s: slurpd \"replogfile\" not writeable\n",
|
1998-08-09 08:43:13 +08:00
|
|
|
sglob->slurpd_replogfile );
|
|
|
|
err++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Make sure that the directory for the slurpd status file is there, and
|
|
|
|
* that the slurpd status file is writable, if it exists.
|
|
|
|
*/
|
|
|
|
rc = filecheck( sglob->slurpd_status_file );
|
|
|
|
if ( rc & FC_DIRBAD ) {
|
2000-08-18 08:58:00 +08:00
|
|
|
fprintf( stderr, "Error: %s: status directory does not exist\n",
|
1998-08-09 08:43:13 +08:00
|
|
|
sglob->slurpd_status_file );
|
|
|
|
err++;
|
|
|
|
} else if ( rc & FC_DIRUNREAD ) {
|
2000-08-18 08:58:00 +08:00
|
|
|
fprintf( stderr, "Error: %s: status directory not readable\n",
|
1998-08-09 08:43:13 +08:00
|
|
|
sglob->slurpd_status_file );
|
|
|
|
err++;
|
|
|
|
} else if ( !( rc & FC_FILEBAD ) && ( rc & FC_FILEUNREAD )) {
|
2000-08-18 08:58:00 +08:00
|
|
|
fprintf( stderr, "Error: %s: status file not readable\n",
|
1998-08-09 08:43:13 +08:00
|
|
|
sglob->slurpd_status_file );
|
|
|
|
err++;
|
|
|
|
} else if ( !( rc & FC_FILEBAD ) && ( rc & FC_FILEUNWRITE )) {
|
2000-08-18 08:58:00 +08:00
|
|
|
fprintf( stderr, "Error: %s: status file not writeable\n",
|
1998-08-09 08:43:13 +08:00
|
|
|
sglob->slurpd_status_file );
|
|
|
|
err++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ( err == 0 ? 0 : -1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check for the existence of the file and directory leading to the file.
|
|
|
|
* Returns a bitmask which is the logical OR of the following flags:
|
|
|
|
*
|
|
|
|
* FC_DIRBAD: directory containing "f" does not exist.
|
|
|
|
* FC_DIRUNREAD: directory containing "f" exists but is not readable.
|
|
|
|
* FC_DIRUNWRITE: directory containing "f" exists but is not writable.
|
|
|
|
* FC_FILEBAD: "f" does not exist.
|
|
|
|
* FC_FILEUNREAD: "f" exists but is unreadable.
|
|
|
|
* FC_FILEUNWRITE: "f" exists but is unwritable.
|
|
|
|
*
|
|
|
|
* The calling routine is responsible for determining which, if any, of
|
|
|
|
* the returned flags is a problem for a particular file.
|
|
|
|
*/
|
|
|
|
static unsigned int
|
|
|
|
filecheck(
|
|
|
|
char *f
|
|
|
|
)
|
|
|
|
{
|
|
|
|
char dir[ MAXPATHLEN ];
|
|
|
|
char *p;
|
|
|
|
unsigned int ret = 0;
|
|
|
|
|
2002-08-07 03:31:00 +08:00
|
|
|
snprintf( dir, sizeof dir, "%s", f );
|
2002-05-16 18:51:45 +08:00
|
|
|
p = strrchr( dir, LDAP_DIRSEP[0] );
|
1998-08-09 08:43:13 +08:00
|
|
|
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;
|
|
|
|
}
|