[Fedora-directory-commits] ldapserver/ldap/admin/lib dsalib_conf.c, 1.6, 1.7 dsalib_db.c, 1.5, 1.6 dsalib_location.c, 1.7, 1.8 dsalib_util.c, 1.7, 1.8
Noriko Hosoi (nhosoi)
fedora-directory-commits at redhat.com
Fri Oct 13 01:06:23 UTC 2006
Author: nhosoi
Update of /cvs/dirsec/ldapserver/ldap/admin/lib
In directory cvs-int.fedora.redhat.com:/tmp/cvs-serv23608/ldap/admin/lib
Modified Files:
dsalib_conf.c dsalib_db.c dsalib_location.c dsalib_util.c
Log Message:
[208672] parameterizing the hardcoded paths (phase 2. db, log, lock, pid, cert, and instance dir)
1) introduced these 3 new config attributes:
nsslapd-lockdir, nsslapd-tmpdir, nsslapd-certdir,
and eliminated: nsslapd-instancedir.
2) replaced the hardcoded paths with the corresponding attribute value in the
server as well as in the create/remove instance codes.
3) moved snmp stats file to the nsslapd-tmpdir
4) moved the server instance dir to <prefix>/lib/<brand>-ds/slapd-<id>
Index: dsalib_conf.c
===================================================================
RCS file: /cvs/dirsec/ldapserver/ldap/admin/lib/dsalib_conf.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- dsalib_conf.c 27 Sep 2006 23:40:44 -0000 1.6
+++ dsalib_conf.c 13 Oct 2006 01:06:20 -0000 1.7
@@ -51,7 +51,6 @@
#include "nspr.h"
-#define CONF_FILE_NAME "dse.ldif"
#define CONF_SUFFIX "cn=config"
DS_EXPORT_SYMBOL char *
@@ -83,7 +82,7 @@
return(NULL);
}
- PR_snprintf(conffile, PATH_MAX, "%s/%s", configdir, CONF_FILE_NAME);
+ PR_snprintf(conffile, PATH_MAX, "%s/%s", configdir, DS_CONFIG_FILE);
if ( !(sf = fopen(conffile, "r")) ) {
ds_send_error("could not read config file.", 1);
Index: dsalib_db.c
===================================================================
RCS file: /cvs/dirsec/ldapserver/ldap/admin/lib/dsalib_db.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- dsalib_db.c 19 Apr 2005 22:06:54 -0000 1.5
+++ dsalib_db.c 13 Oct 2006 01:06:20 -0000 1.6
@@ -64,35 +64,42 @@
DS_EXPORT_SYMBOL char **
ds_get_bak_dirs()
{
- char format_str[PATH_MAX];
+ char format_str[PATH_MAX];
char *root;
- int i = 0;
- char **bak_dirs = NULL;
+ int i = 0;
+ char **bak_dirs = NULL;
+ char *bakdir = NULL;
if ( (root = ds_get_install_root()) == NULL )
- {
+ {
ds_send_error("Cannot find server root directory.", 0);
return(bak_dirs);
}
- PR_snprintf( format_str, PATH_MAX, "%s%cbak", root, FILE_SEP );
- bak_dirs = ds_get_file_list( format_str );
- if( bak_dirs )
- {
- while( bak_dirs[i] != NULL )
- {
- /* Prepend the filename with the install root */
- char filename[PATH_MAX];
- PR_snprintf( filename, PATH_MAX, "%s%cbak%c%s", root, FILE_SEP,
- FILE_SEP, bak_dirs[i] );
- free( bak_dirs[i] );
- bak_dirs[i] = strdup( filename );
+ if ( (bakdir = ds_get_bak_dir()) == NULL )
+ {
+ ds_send_error("Cannot find backup directory.", 0);
+ return(bak_dirs);
+ }
+
+ PR_snprintf( format_str, PATH_MAX, "%s", bakdir );
+ bak_dirs = ds_get_file_list( format_str );
+ if( bak_dirs )
+ {
+ while( bak_dirs[i] != NULL )
+ {
+ /* Prepend the filename with the install root */
+ char filename[PATH_MAX];
+ PR_snprintf( filename, PATH_MAX, "%s%c%s",
+ bakdir, FILE_SEP, bak_dirs[i] );
+ free( bak_dirs[i] );
+ bak_dirs[i] = strdup( filename );
#if defined( XP_WIN32 )
- ds_dostounixpath( bak_dirs[i] );
+ ds_dostounixpath( bak_dirs[i] );
#endif
- i++;
- }
- }
+ i++;
+ }
+ }
return(bak_dirs);
}
@@ -113,7 +120,7 @@
int error = -1;
int status;
FILE *sf = NULL;
- struct stat fstats;
+ struct stat fstats;
if ( file == NULL ) {
return DS_NULL_PARAMETER;
@@ -126,8 +133,8 @@
return DS_NO_SERVER_ROOT;
}
- if ( file[strlen(file) - 1] == '\n' ) /* strip out returns */
- file[strlen(file) - 1] = '\0';
+ if ( file[strlen(file) - 1] == '\n' ) /* strip out returns */
+ file[strlen(file) - 1] = '\0';
if( stat( file, &fstats ) == -1 && errno == ENOENT ) {
return DS_CANNOT_OPEN_BACKUP_FILE;
@@ -138,12 +145,12 @@
tmp_dir = ds_get_tmp_dir();
PR_snprintf(statfile, PATH_MAX, "%s%cbak2db.%d", tmp_dir, FILE_SEP, (int)getpid());
PR_snprintf(startup_line, BIG_LINE,
- "%s%cbak2db "
- "%s%s%s > "
- "%s%s%s 2>&1",
- root, FILE_SEP,
- ENQUOTE, file, ENQUOTE,
- ENQUOTE, statfile, ENQUOTE );
+ "%s%cbak2db "
+ "%s%s%s > "
+ "%s%s%s 2>&1",
+ root, FILE_SEP,
+ ENQUOTE, file, ENQUOTE,
+ ENQUOTE, statfile, ENQUOTE );
alter_startup_line(startup_line);
fflush(0);
error = system(startup_line);
@@ -151,19 +158,19 @@
if ( error == -1 ) {
return DS_CANNOT_EXEC;
}
- fflush(0);
+ fflush(0);
if( !(sf = fopen(statfile, "r")) ) {
return DS_CANNOT_OPEN_STAT_FILE;
}
while ( fgets(startup_line, BIG_LINE, sf) ) {
- if ((strstr(startup_line, "- Restoring file")) ||
- (strstr(startup_line, "- Checkpointing"))) {
- ds_show_message(startup_line);
- } else {
- haderror = 1;
- ds_send_error(startup_line, 0);
- }
+ if ((strstr(startup_line, "- Restoring file")) ||
+ (strstr(startup_line, "- Checkpointing"))) {
+ ds_show_message(startup_line);
+ } else {
+ haderror = 1;
+ ds_send_error(startup_line, 0);
+ }
}
fclose(sf);
@@ -189,9 +196,9 @@
int haderror = 0;
int error = -1;
FILE *sf = NULL;
- int lite = 0;
+ int lite = 0;
#ifdef XP_WIN32
- time_t ltime;
+ time_t ltime;
#endif
if ( (root = ds_get_install_root()) == NULL ) {
@@ -201,29 +208,29 @@
if ( (file == NULL) || (strlen(file) == 0) )
file = NULL;
- tmp_dir = ds_get_tmp_dir();
+ tmp_dir = ds_get_tmp_dir();
PR_snprintf(statfile, PATH_MAX, "%s%cdb2bak.%d", tmp_dir, FILE_SEP, (int)getpid());
-
-
+
+
#if defined( XP_WIN32 )
- if( file == NULL )
- {
- file = malloc( BIG_LINE );
-
- time( <ime );
- PR_snprintf( file, BIG_LINE, "%s", ctime( <ime ) );
- ds_timetofname( file );
- }
-
- /* Check if the directory exists or can be created */
- if ( !ds_file_exists( file ) ) {
- char *errmsg = ds_mkdir_p( file, NEWDIR_MODE );
- if( errmsg != NULL ) {
-/* ds_send_error(errmsg, 10);
+ if( file == NULL )
+ {
+ file = malloc( BIG_LINE );
+
+ time( <ime );
+ PR_snprintf( file, BIG_LINE, "%s", ctime( <ime ) );
+ ds_timetofname( file );
+ }
+
+ /* Check if the directory exists or can be created */
+ if ( !ds_file_exists( file ) ) {
+ char *errmsg = ds_mkdir_p( file, NEWDIR_MODE );
+ if( errmsg != NULL ) {
+/* ds_send_error(errmsg, 10);
*/
- return DS_CANNOT_CREATE_DIRECTORY;
- }
- }
+ return DS_CANNOT_CREATE_DIRECTORY;
+ }
+ }
#endif
/* DBDB: note on the following line.
@@ -238,16 +245,16 @@
PR_snprintf(startup_line, sizeof(startup_line),
- "%s%cdb2bak "
- "%s%s%s > "
- "%s%s%s 2>&1",
- root, FILE_SEP,
- ENQUOTE,
- (file == NULL) ? "" : file,
- ENQUOTE,
- ENQUOTE, statfile, ENQUOTE);
+ "%s%cdb2bak "
+ "%s%s%s > "
+ "%s%s%s 2>&1",
+ root, FILE_SEP,
+ ENQUOTE,
+ (file == NULL) ? "" : file,
+ ENQUOTE,
+ ENQUOTE, statfile, ENQUOTE);
- PATH_FOR_PLATFORM( startup_line );
+ PATH_FOR_PLATFORM( startup_line );
alter_startup_line(startup_line);
fflush(0);
error = system(startup_line);
@@ -274,7 +281,7 @@
unlink(statfile);
if ( lite && haderror )
- return DS_HAS_TOBE_READONLY_MODE;
+ return DS_HAS_TOBE_READONLY_MODE;
if ( haderror )
return DS_UNKNOWN_ERROR;
@@ -284,52 +291,52 @@
static void
process_and_report( char *line, int line_size, FILE *cmd )
{
- while(fgets(line, line_size, cmd)) {
- /* Strip off line feeds */
- int ind = strlen( line ) - 1;
- while ( (ind >= 0) &&
- ((line[ind] == '\n') ||
- (line[ind] == '\r')) ) {
- line[ind] = 0;
- ind--;
- }
- if ( ind < 1 ) {
- continue;
- }
- ds_send_status(line);
- }
+ while(fgets(line, line_size, cmd)) {
+ /* Strip off line feeds */
+ int ind = strlen( line ) - 1;
+ while ( (ind >= 0) &&
+ ((line[ind] == '\n') ||
+ (line[ind] == '\r')) ) {
+ line[ind] = 0;
+ ind--;
+ }
+ if ( ind < 1 ) {
+ continue;
+ }
+ ds_send_status(line);
+ }
}
static int exec_and_report( char *startup_line )
{
- FILE *cmd = NULL;
+ FILE *cmd = NULL;
char line[BIG_LINE];
int haderror = 0;
- PATH_FOR_PLATFORM( startup_line );
+ PATH_FOR_PLATFORM( startup_line );
alter_startup_line(startup_line);
- /*
- fprintf( stdout, "Launching <%s>\n", startup_line );
- */
+ /*
+ fprintf( stdout, "Launching <%s>\n", startup_line );
+ */
fflush(0);
- cmd = popen(startup_line, "r");
- if(!cmd) {
+ cmd = popen(startup_line, "r");
+ if(!cmd) {
return DS_CANNOT_EXEC;
}
- process_and_report( line, sizeof(line), cmd );
- pclose(cmd);
+ process_and_report( line, sizeof(line), cmd );
+ pclose(cmd);
/*
** The VLV indexing code prints OK,
** if the index was successfully created.
*/
- if (strcmp(line,"OK")==0) {
- haderror = 0;
- } else {
- haderror = DS_UNKNOWN_ERROR;
- }
+ if (strcmp(line,"OK")==0) {
+ haderror = 0;
+ } else {
+ haderror = DS_UNKNOWN_ERROR;
+ }
return haderror;
}
@@ -345,8 +352,8 @@
char startup_line[BIG_LINE];
char *root;
char *instroot;
- char **vlvc = NULL;
-
+ char **vlvc = NULL;
+
root = ds_get_server_root();
instroot = ds_get_install_root();
@@ -355,21 +362,21 @@
}
PR_snprintf(startup_line, sizeof(startup_line), "%s/bin/slapd/server/%s db2index "
- "-D %s%s/%s "
- "-n %s ",
- root, SLAPD_NAME,
- ENQUOTE, instroot, ENQUOTE,
- backendList[0]);
+ "-D %s%s/%s "
+ "-n %s ",
+ root, SLAPD_NAME,
+ ENQUOTE, instroot, ENQUOTE,
+ backendList[0]);
- /* Create vlv TAG */
- vlvc=vlvList;
- while( *vlvc != NULL ) {
- PR_snprintf( startup_line, sizeof(startup_line), "%s -T %s%s%s", startup_line,"\"",*vlvc,"\"" );
- vlvc++;
- }
+ /* Create vlv TAG */
+ vlvc=vlvList;
+ while( *vlvc != NULL ) {
+ PR_snprintf( startup_line, sizeof(startup_line), "%s -T %s%s%s", startup_line,"\"",*vlvc,"\"" );
+ vlvc++;
+ }
- return exec_and_report( startup_line );
+ return exec_and_report( startup_line );
}
/*
@@ -391,17 +398,17 @@
return DS_NO_SERVER_ROOT;
}
- PR_snprintf(startup_line, sizeof(startup_line), "%s/bin/slapd/server/%s db2index "
- "-D %s%s%s "
- "-n %s",
- root, SLAPD_NAME,
- ENQUOTE, instroot, ENQUOTE,
- backendName);
-
- while( *attrList != NULL ) {
- PR_snprintf( startup_line, sizeof(startup_line), "%s -t %s", startup_line, *attrList );
- attrList++;
- }
+ PR_snprintf(startup_line, sizeof(startup_line), "%s/bin/slapd/server/%s db2index "
+ "-D %s%s%s "
+ "-n %s",
+ root, SLAPD_NAME,
+ ENQUOTE, instroot, ENQUOTE,
+ backendName);
+
+ while( *attrList != NULL ) {
+ PR_snprintf( startup_line, sizeof(startup_line), "%s -t %s", startup_line, *attrList );
+ attrList++;
+ }
- return exec_and_report( startup_line );
+ return exec_and_report( startup_line );
}
Index: dsalib_location.c
===================================================================
RCS file: /cvs/dirsec/ldapserver/ldap/admin/lib/dsalib_location.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- dsalib_location.c 27 Sep 2006 23:40:44 -0000 1.7
+++ dsalib_location.c 13 Oct 2006 01:06:20 -0000 1.8
@@ -133,6 +133,52 @@
}
/*
+ * Returns the bakup dir of the server, where db backup files are put.
+ * Info is returned in a static area. The caller must copy it
+ * for reuse if needed.
+ */
+DS_EXPORT_SYMBOL char *
+ds_get_bak_dir()
+{
+ return getenv("DS_BAK_DIR");
+}
+
+/*
+ * set bak_dir to environment variable DS_BAK_DIR
+ * to retrieve the value using ds_get_bak_dir later.
+ */
+DS_EXPORT_SYMBOL void
+ds_set_bak_dir(char *bak_dir)
+{
+ static char env[PATH_MAX];
+ PR_snprintf(env, sizeof(env), "DS_BAK_DIR=%s", bak_dir);
+ putenv(env);
+}
+
+/*
+ * Returns the tmp dir of the server, where tmp files are put.
+ * Info is returned in a static area. The caller must copy it
+ * for reuse if needed.
+ */
+DS_EXPORT_SYMBOL char *
+ds_get_tmp_dir()
+{
+ return getenv("DS_TMP_DIR");
+}
+
+/*
+ * set bak_dir to environment variable DS_TMP_DIR
+ * to retrieve the value using ds_get_tmp_dir later.
+ */
+DS_EXPORT_SYMBOL void
+ds_set_tmp_dir(char *tmp_dir)
+{
+ static char env[PATH_MAX];
+ PR_snprintf(env, sizeof(env), "DS_TMP_DIR=%s", tmp_dir);
+ putenv(env);
+}
+
+/*
* Returns the install location of the server under the admserv
* directory.
*/
Index: dsalib_util.c
===================================================================
RCS file: /cvs/dirsec/ldapserver/ldap/admin/lib/dsalib_util.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- dsalib_util.c 19 Apr 2005 22:06:54 -0000 1.7
+++ dsalib_util.c 13 Oct 2006 01:06:20 -0000 1.8
@@ -307,51 +307,6 @@
#endif
}
-/* Returns a directory path used for tmp files. */
-DS_EXPORT_SYMBOL char *
-ds_get_tmp_dir()
-{
-#if defined( XP_WIN32 )
- size_t ilen;
- char pch;
-#endif
- static char tmpdir[] = "/tmp";
- static char tmp[256] = {0};
- char* instanceDir = ds_get_install_root();
-
- if(instanceDir == NULL)
- {
- #if defined( XP_WIN32 )
- ilen = sizeof(tmp);
- GetTempPath( ilen, tmp );
- tmp[ilen-1] = (char)0;
- /* Remove trailing slash. */
- ilen = strlen(tmp);
- pch = tmp[ilen-1];
- if( pch == '\\' || pch == '/' )
- tmp[ilen-1] = '\0';
- return tmp;
- #else
- return( tmpdir );
- #endif
- }
-
- PR_snprintf(tmp, sizeof(tmp), "%s/tmp",instanceDir);
-
-#if defined( XP_WIN32 )
- for(ilen=0;ilen < strlen(tmp); ilen++)
- {
- if(tmp[ilen]=='/')
- tmp[ilen]='\\';
- }
-#endif
-
- if(!ds_file_exists(tmp))
- ds_mkdir_p(tmp,00770);
-
- return ( tmp );
-}
-
DS_EXPORT_SYMBOL void
ds_unixtodospath(char *szText)
{
@@ -630,8 +585,10 @@
}
/* returns 1 if string "searchstring" found in file "filename" */
+/* if found, returnstring is allocated and filled with the line */
+/* caller should release the memory */
DS_EXPORT_SYMBOL int
-ds_search_file(char *filename, char *searchstring)
+ds_search_file(char *filename, char *searchstring, char **returnstring)
{
struct stat finfo;
FILE * sf;
@@ -648,6 +605,10 @@
while ( fgets(big_line, BIG_LINE, sf) ) {
if( strstr( big_line, searchstring ) != NULL ) {
+ *returnstring = (char *)malloc(strlen(big_line) + 1);
+ if (NULL != *returnstring) {
+ strcpy(*returnstring, big_line);
+ }
fclose(sf);
return 1;
}
@@ -864,8 +825,6 @@
return static_error;
}
-/* get db path dir info from dse.ldif and remove it if it's not under path
-*/
#ifndef MAXPATHLEN
#define MAXPATHLEN 1024
#endif
@@ -907,7 +866,7 @@
if (fp == NULL)
{
- ds_rm_rf_err_func(fullpath, "opening dse.ldif", arg);
+ ds_rm_rf_err_func(fullpath, "opening the config file", arg);
return;
}
@@ -990,6 +949,43 @@
fclose(fp);
}
+static char *
+get_dir_from_startslapd(char *loc, char *keyword)
+{
+ char *returnstr = NULL;
+ char *ptr = NULL;
+ char *confdir = NULL;
+if (ds_search_file(loc, keyword, &returnstr) > 0 && returnstr) {
+ ptr = strchr(returnstr, '=');
+ if (NULL != ptr) {
+ confdir = strdup(++ptr);
+ }
+ free(returnstr);
+ }
+ return confdir;
+}
+
+static char *
+get_dir_from_config(char *config_dir, char *config_attr)
+{
+ char *configfile = NULL;
+ char *returnstr = NULL;
+ char *ptr = NULL;
+ char *dir = NULL;
+ configfile = PR_smprintf("%s%c%s", config_dir, FILE_PATHSEP, DS_CONFIG_FILE);
+ if (configfile && ds_search_file(configfile, config_attr, &returnstr) > 0
+ && returnstr) {
+ ptr = strchr(returnstr, ':');
+ if (NULL != ptr) {
+ while (' ' == *ptr || '\t' == *ptr) ptr++;
+ dir = strdup(ptr);
+ }
+ free(returnstr);
+ PR_smprintf_free(configfile);
+ }
+ return dir;
+}
+
/* this function will recursively remove a directory hierarchy from the file
system, like "rm -rf"
In order to handle errors, the user supplies a callback function. When an
@@ -1041,9 +1037,61 @@
break;
}
} else {
- /* if dse.ldif, check db dir is under the instance dir or not */
- if (0 == strcmp(dirent->name, "dse.ldif"))
+ /* FHS changes the directory structure.
+ * Config dir is no longer in the instance dir.
+ * The info should be found in start-slapd,
+ * therefore get the path from the file here.
+ */
+ if (0 == strcmp(dirent->name, "start-slapd")) {
+ char *config_dir = ds_get_config_dir();
+ char *run_dir = ds_get_run_dir();
+ if (NULL == config_dir || '\0' == *config_dir) {
+ config_dir = get_dir_from_startslapd(fullpath, DS_CONFIG_DIR);
+ }
+ if (NULL == run_dir || '\0' == *run_dir) {
+ char *ptr = NULL;
+ run_dir = get_dir_from_startslapd(fullpath, PIDFILE);
+ ptr = strrchr(run_dir, FILE_PATHSEP);
+ if (NULL != ptr) {
+ *ptr = '\0'; /* equiv to dirname */
+ }
+ }
+ if (NULL != run_dir) {
+ internal_rm_rf(run_dir, ds_rm_rf_err_func, NULL);
+ free(run_dir);
+ }
+ if (NULL != config_dir) {
+ char *lock_dir = get_dir_from_config(config_dir, DS_CONFIG_LOCKDIR);
+ char *err_log = get_dir_from_config(config_dir, DS_CONFIG_ERRLOG);
+
+ if (NULL != lock_dir) {
+ internal_rm_rf(lock_dir, ds_rm_rf_err_func, NULL);
+ free(lock_dir);
+ }
+ if (NULL != err_log) {
+ char *ptr = strrchr(err_log, FILE_PATHSEP);
+ if (NULL != ptr) {
+ *ptr = '\0'; /* equiv to 'dirname' */
+ internal_rm_rf(err_log, ds_rm_rf_err_func, NULL);
+ }
+ free(err_log);
+ }
+ /* removing db dirs */
+ rm_db_dirs(config_dir, ds_rm_rf_err_func, arg);
+
+ /* removing config dir */
+ internal_rm_rf(config_dir, ds_rm_rf_err_func, NULL);
+ }
+ }
+ /*
+ * When the file is the config file,
+ * check if db dir is in the instance dir or not.
+ * If db dir exists in the instance dir, it's an old structure.
+ * Let's clean the old db here, as well.
+ */
+ if (0 == strcmp(dirent->name, DS_CONFIG_FILE)) {
rm_db_dirs(fullpath, ds_rm_rf_err_func, arg);
+ }
if (PR_Delete(fullpath) != PR_SUCCESS) {
if (!ds_rm_rf_err_func(fullpath, "deleting file", arg)) {
@@ -1086,6 +1134,7 @@
return 1; /* just continue */
}
+/* dir: instance dir, e.g., "$NETSITE_ROOT/slapd-<id>" */
DS_EXPORT_SYMBOL int
ds_rm_rf(const char *dir, DS_RM_RF_ERR_FUNC ds_rm_rf_err_func, void *arg)
{
More information about the Fedora-directory-commits
mailing list