/*
* $Id$
*
- * Sleepycat (Berkeley) DB driver for Citadel/UX
+ * Sleepycat (Berkeley) DB driver for Citadel
*
*/
#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) */
static void dest_tsd(void *arg) {
if (arg != NULL) {
check_handles(arg);
- phree(arg);
+ free(arg);
}
}
if (pthread_getspecific(tsdkey) != NULL)
return;
- tsd = mallok(sizeof(struct cdbtsd));
+ tsd = malloc(sizeof(struct cdbtsd));
tsd->tid = NULL;
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");
}
sourceLen = (uLongf) zheader.compressed_len;
destLen = (uLongf) zheader.uncompressed_len;
- uncompressed_data = mallok(zheader.uncompressed_len);
+ uncompressed_data = malloc(zheader.uncompressed_len);
if (uncompress( (Bytef *) uncompressed_data,
&destLen,
abort();
}
- phree(cdb->ptr);
+ free(cdb->ptr);
cdb->len = (size_t) destLen;
cdb->ptr = uncompressed_data;
}
buffer_len = ( (cdatalen * 101) / 100 ) + 100
+ sizeof(struct CtdlCompressHeader) ;
destLen = (uLongf) buffer_len;
- compressed_data = mallok(buffer_len);
+ compressed_data = malloc(buffer_len);
if (compress2(
(Bytef *) (compressed_data +
sizeof(struct CtdlCompressHeader)),
abort();
}
#ifdef HAVE_ZLIB
- if (compressing) phree(compressed_data);
+ if (compressing) free(compressed_data);
#endif
return ret;
{
txcommit(tid);
#ifdef HAVE_ZLIB
- if (compressing) phree(compressed_data);
+ if (compressing) free(compressed_data);
#endif
return ret;
}
}
if (ret != 0) return NULL;
- tempcdb = (struct cdbdata *) mallok(sizeof(struct cdbdata));
+ tempcdb = (struct cdbdata *) malloc(sizeof(struct cdbdata));
if (tempcdb == NULL)
{
*/
void cdb_free(struct cdbdata *cdb)
{
- phree(cdb->ptr);
- phree(cdb);
+ free(cdb->ptr);
+ free(cdb);
}
void cdb_close_cursor(int cdb)
return NULL; /* presumably, end of file */
}
- cdbret = (struct cdbdata *) mallok(sizeof(struct cdbdata));
+ cdbret = (struct cdbdata *) malloc(sizeof(struct cdbdata));
cdbret->len = data.size;
cdbret->ptr = data.data;
#ifdef HAVE_ZLIB