From 73a422963bf40757c43f72877fc2f622f136ccd4 Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Wed, 24 Mar 2004 02:59:19 +0000 Subject: [PATCH] * After initializing the database, chown and chmod all files in the data/ directory correctly to avoid EPERM errors later on when we drop root privs --- citadel/ChangeLog | 5 ++++- citadel/database_sleepycat.c | 23 +++++++++++++++++++++++ citadel/msgbase.c | 5 +++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/citadel/ChangeLog b/citadel/ChangeLog index 6c2a64e8f..612706149 100644 --- a/citadel/ChangeLog +++ b/citadel/ChangeLog @@ -1,4 +1,8 @@ $Log$ + Revision 614.95 2004/03/24 02:59:19 ajc + * After initializing the database, chown and chmod all files in the data/ + directory correctly to avoid EPERM errors later on when we drop root privs + Revision 614.94 2004/03/22 19:37:28 error * sysdep.c: worker_thread(): Make scheduling a little more fair to higher sessions @@ -5586,4 +5590,3 @@ Sat Jul 11 00:20:48 EDT 1998 Nathan Bryant Fri Jul 10 1998 Art Cancro * Initial CVS import - diff --git a/citadel/database_sleepycat.c b/citadel/database_sleepycat.c index 0d734bfd9..5e3fb37a7 100644 --- a/citadel/database_sleepycat.c +++ b/citadel/database_sleepycat.c @@ -55,6 +55,7 @@ #include "database.h" #include "msgbase.h" #include "sysdep_decls.h" +#include "config.h" static DB *dbp[MAXCDB]; /* One DB handle for each Citadel database */ static DB_ENV *dbenv; /* The DB environment (global) */ @@ -283,6 +284,10 @@ void open_databases(void) char dbfilename[SIZ]; u_int32_t flags = 0; char dbdirname[PATH_MAX]; + DIR *dp; + struct dirent *d; + char filename[PATH_MAX]; + getcwd(dbdirname, sizeof dbdirname); strcat(dbdirname, "/data"); @@ -300,6 +305,7 @@ void open_databases(void) */ mkdir(dbdirname, 0700); chmod(dbdirname, 0700); + chown(dbdirname, BBSUID, (-1) ); lprintf(CTDL_DEBUG, "cdb_*: Setting up DB environment\n"); db_env_set_func_yield(sched_yield); @@ -377,6 +383,23 @@ void open_databases(void) cdb_allocate_tsd(); CtdlRegisterSessionHook(cdb_checkpoint, EVT_TIMER); + + /* Now make sure we own all the files, because in a few milliseconds + * we're going to drop root privs. + */ + dp = opendir(dbdirname); + if (dp != NULL) { + while (d = readdir(dp), d != NULL) { + if (d->d_name[0] != '.') { + snprintf(filename, sizeof filename, "%s/%s", + dbdirname, d->d_name); + chmod(filename, 0600); + chown(filename, BBSUID, (-1) ); + } + } + closedir(dp); + } + lprintf(CTDL_DEBUG, "cdb_*: open_databases() finished\n"); } diff --git a/citadel/msgbase.c b/citadel/msgbase.c index 75146cfd0..55c30c319 100644 --- a/citadel/msgbase.c +++ b/citadel/msgbase.c @@ -241,6 +241,11 @@ void get_mm(void) FILE *fp; fp = fopen("citadel.control", "r"); + if (fp == NULL) { + lprintf(CTDL_CRIT, "Cannot open citadel.control: %s\n", + strerror(errno)); + exit(errno); + } fread((char *) &CitControl, sizeof(struct CitControl), 1, fp); fclose(fp); } -- 2.39.2