* After initializing the database, chown and chmod all files in the data/
authorArt Cancro <ajc@citadel.org>
Wed, 24 Mar 2004 02:59:19 +0000 (02:59 +0000)
committerArt Cancro <ajc@citadel.org>
Wed, 24 Mar 2004 02:59:19 +0000 (02:59 +0000)
  directory correctly to avoid EPERM errors later on when we drop root privs

citadel/ChangeLog
citadel/database_sleepycat.c
citadel/msgbase.c

index 6c2a64e8fda34eacf1578d07e6bec6d12dc77daf..612706149f0b0322bb631bf9ef9bd10237439c73 100644 (file)
@@ -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 <bryant@cs.usm.maine.edu>
 
 Fri Jul 10 1998 Art Cancro <ajc@uncensored.citadel.org>
        * Initial CVS import
-
index 0d734bfd97c92df0bdef160c313a42c25db22213..5e3fb37a7bb8d40a97dec233a8de4ed972f2a13d 100644 (file)
@@ -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");
 }
 
index 75146cfd0e66421c1e0f8f476f1025b36272bfb6..55c30c31979a3e5fc8f5fc5419370e3cf5cbca63 100644 (file)
@@ -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);
 }