$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
Fri Jul 10 1998 Art Cancro <ajc@uncensored.citadel.org>
* Initial CVS import
-
#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) */
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");
*/
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);
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");
}
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);
}