#include "../../sysdep.h"
#include <sys/stat.h>
#include <stdio.h>
-#include <dirent.h>
#include <zlib.h>
#include <db.h>
#include <libcitadel.h>
exit(CTDLEXIT_DB);
}
- // Silently try to create the database subdirectory. If it's already there, no problem.
- if ((mkdir(ctdl_db_dir, 0700) != 0) && (errno != EEXIST)) {
- syslog(LOG_ERR, "bdb: database directory [%s] does not exist and could not be created: %m", ctdl_db_dir);
- exit(CTDLEXIT_DB);
- }
- if (chmod(ctdl_db_dir, 0700) != 0) {
- syslog(LOG_ERR, "bdb: unable to set database directory permissions [%s]: %m", ctdl_db_dir);
- exit(CTDLEXIT_DB);
- }
- if (chown(ctdl_db_dir, CTDLUID, (-1)) != 0) {
- syslog(LOG_ERR, "bdb: unable to set the owner for [%s]: %m", ctdl_db_dir);
- exit(CTDLEXIT_DB);
- }
syslog(LOG_DEBUG, "bdb: Setting up DB environment");
ret = db_env_create(&dbenv, 0);
if (ret) {
}
-// Make sure we own all the files, because in a few milliseconds we're going to drop root privs.
-void bdb_chmod_data(void) {
- DIR *dp;
- struct dirent *d;
- char filename[PATH_MAX];
-
- dp = opendir(ctdl_db_dir);
- if (dp != NULL) {
- while (d = readdir(dp), d != NULL) {
- if (d->d_name[0] != '.') {
- snprintf(filename, sizeof filename, "%s/%s", ctdl_db_dir, d->d_name);
- syslog(LOG_DEBUG, "bdb: chmod(%s, 0600) returned %d", filename, chmod(filename, 0600));
- syslog(LOG_DEBUG, "bdb: chown(%s, CTDLUID, -1) returned %d", filename, chown(filename, CTDLUID, (-1)));
- }
- }
- closedir(dp);
- }
-}
-
-
// Close all of the db database files we've opened. This can be done in a loop, since it's just a bunch of closes.
void bdb_close_databases(void) {
int i;
cdb_end_transaction = bdb_end_transaction;
cdb_check_handles = bdb_check_handles;
cdb_trunc = bdb_trunc;
- cdb_chmod_data = bdb_chmod_data;
if (pthread_key_create(&bdb_thread_key, NULL) != 0) { // TSD key for this module
syslog(LOG_ERR, "pthread_key_create() : %m");