/*
* This is a data store backend for the Citadel server which uses Berkeley DB.
*
- * Copyright (c) 1987-2017 by the citadel.org team
+ * Copyright (c) 1987-2018 by the citadel.org team
*
* This program is open source software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License version 3.
static DB_ENV *dbenv; /* The DB environment (global) */
-void cdb_abort(void) {
+void cdb_abort(void)
+{
syslog(LOG_DEBUG, "db: citserver is stopping in order to prevent data loss. uid=%d gid=%d euid=%d egid=%d",
- getuid(),
- getgid(),
- geteuid(),
- getegid()
+ getuid(), getgid(), geteuid(), getegid()
);
exit(CTDLEXIT_DB);
}
/* Verbose logging callback */
-void cdb_verbose_log(const DB_ENV *dbenv, const char *msg)
+void cdb_verbose_log(const DB_ENV * dbenv, const char *msg)
{
if (!IsEmptyStr(msg)) {
syslog(LOG_DEBUG, "db: %s", msg);
/* Verbose logging callback */
-void cdb_verbose_err(const DB_ENV *dbenv, const char *errpfx, const char *msg)
+void cdb_verbose_err(const DB_ENV * dbenv, const char *errpfx, const char *msg)
{
- int *FOO = NULL;
syslog(LOG_ERR, "db: %s", msg);
- *FOO = 1;
}
}
}
+
/* this one is even more helpful than the last. */
static void txcommit(DB_TXN * tid)
{
}
}
+
/* are you sensing a pattern yet? */
static void txbegin(DB_TXN ** tid)
{
}
}
+
static void dbpanic(DB_ENV * env, int errval)
{
syslog(LOG_ERR, "db: PANIC: %s", db_strerror(errval));
}
+
static void cclose(DBC * cursor)
{
int ret;
}
}
+
static void bailIfCursor(DBC ** cursors, const char *msg)
{
int i;
*/
void cdb_cull_logs(void)
{
+#ifndef DB_LOG_AUTO_REMOVE
u_int32_t flags;
int ret;
char **file, **list;
"database log file '%s' because of the "
"following error:\n \n %s\n \n"
" This log file is no longer in use "
- "and may be safely deleted.\n",
- *file, strerror(errno));
+ "and may be safely deleted.\n", *file, strerror(errno));
CtdlAideMessage(errmsg, "Database Warning Message");
}
}
free(list);
}
+#endif /* DB_LOG_AUTO_REMOVE */
}
/* After a successful checkpoint, we can cull the unused logs */
if (CtdlGetConfigInt("c_auto_cull")) {
#ifdef DB_LOG_AUTO_REMOVE
- ret = dbenv->log_set_config(dbenv, DB_LOG_AUTO_REMOVE, 1); // This version of Berkeley DB can cull the logs on its own!
+ // This version of Berkeley DB can cull the logs on its own!
+ ret = dbenv->log_set_config(dbenv, DB_LOG_AUTO_REMOVE, 1);
#else
- cdb_cull_logs(); // Citadel knows how to do it too.
+ cdb_cull_logs(); // Citadel knows how to do it too.
#endif
}
#ifdef DB_LOG_AUTO_REMOVE
}
-
/*
* Open the various databases we'll be using. Any database which
* does not exist should be created. Note that we don't need a
* Silently try to create the database subdirectory. If it's
* already there, no problem.
*/
- if ((mkdir(ctdl_data_dir, 0700) != 0) && (errno != EEXIST)){
+ if ((mkdir(ctdl_data_dir, 0700) != 0) && (errno != EEXIST)) {
syslog(LOG_ERR, "db: unable to create database directory [%s]: %m", ctdl_data_dir);
}
- if (chmod(ctdl_data_dir, 0700) != 0){
+ if (chmod(ctdl_data_dir, 0700) != 0) {
syslog(LOG_ERR, "db: unable to set database directory accessrights [%s]: %m", ctdl_data_dir);
}
- if (chown(ctdl_data_dir, CTDLUID, (-1)) != 0){
+ if (chown(ctdl_data_dir, CTDLUID, (-1)) != 0) {
syslog(LOG_ERR, "db: unable to set the owner for [%s]: %m", ctdl_data_dir);
}
syslog(LOG_DEBUG, "db: Setting up DB environment\n");
*/
snprintf(dbfilename, sizeof dbfilename, "cdb.%02x", i);
- ret = dbp[i]->open(dbp[i],
- NULL,
- dbfilename,
- NULL,
- DB_BTREE,
- DB_CREATE | DB_AUTO_COMMIT | DB_THREAD,
- 0600
- );
+ ret = dbp[i]->open(dbp[i], NULL, dbfilename, NULL, DB_BTREE, DB_CREATE | DB_AUTO_COMMIT | DB_THREAD, 0600);
if (ret) {
syslog(LOG_ERR, "db: db_open[%02x]: %s", i, db_strerror(ret));
if (ret == ENOMEM) {
- syslog(LOG_ERR, "db: You may need to tune your database; please read http://www.citadel.org/doku.php?id=faq:troubleshooting:out_of_lock_entries for more information.");
+ syslog(LOG_ERR,
+ "db: You may need to tune your database; please read http://www.citadel.org/doku.php?id=faq:troubleshooting:out_of_lock_entries for more information.");
}
syslog(LOG_ERR, "db: exit code %d", ret);
exit(CTDLEXIT_DB);
/* Make sure we own all the files, because in a few milliseconds
* we're going to drop root privs.
*/
-void cdb_chmod_data(void) {
+void cdb_chmod_data(void)
+{
DIR *dp;
struct dirent *d;
char filename[PATH_MAX];
{
static int magic = COMPRESS_MAGIC;
- if ((cdb == NULL) ||
- (cdb->ptr == NULL) ||
- (cdb->len < sizeof(magic)) ||
- (memcmp(cdb->ptr, &magic, sizeof(magic))))
- return;
+ if ((cdb == NULL) || (cdb->ptr == NULL) || (cdb->len < sizeof(magic)) || (memcmp(cdb->ptr, &magic, sizeof(magic)))) {
+ return;
+ }
/* At this point we know we're looking at a compressed item. */
uncompressed_data = malloc(zheader.uncompressed_len);
if (uncompress((Bytef *) uncompressed_data,
- (uLongf *) & destLen,
- (const Bytef *) compressed_data,
- (uLong) sourceLen) != Z_OK)
- {
+ (uLongf *) & destLen, (const Bytef *) compressed_data, (uLong) sourceLen) != Z_OK) {
syslog(LOG_EMERG, "db: uncompress() error");
cdb_abort();
}
memset(&dkey, 0, sizeof(DBT));
memset(&ddata, 0, sizeof(DBT));
dkey.size = ckeylen;
- dkey.data = (void *)ckey;
+ dkey.data = (void *) ckey;
ddata.size = cdatalen;
ddata.data = cdata;
/* Only compress Visit and UseTable records. Everything else is uncompressed. */
- if ( (cdb == CDB_VISIT) || (cdb == CDB_USETABLE) ) {
+ if ((cdb == CDB_VISIT) || (cdb == CDB_USETABLE)) {
compressing = 1;
zheader.magic = COMPRESS_MAGIC;
zheader.uncompressed_len = cdatalen;
destLen = (uLongf) buffer_len;
compressed_data = malloc(buffer_len);
if (compress2((Bytef *) (compressed_data + sizeof(struct CtdlCompressHeader)),
- &destLen, (Bytef *) cdata, (uLongf) cdatalen, 1) != Z_OK)
- {
+ &destLen, (Bytef *) cdata, (uLongf) cdatalen, 1) != Z_OK) {
syslog(LOG_EMERG, "db: compress2() error");
cdb_abort();
}
TSD->tid, /* transaction ID */
&dkey, /* key */
&ddata, /* data */
- 0); /* flags */
+ 0 /* flags */
+ );
if (ret) {
syslog(LOG_EMERG, "db: cdb_store(%d): %s", cdb, db_strerror(ret));
cdb_abort();
}
- if (compressing)
+ if (compressing) {
free(compressed_data);
+ }
return ret;
- }
- else {
+ } else {
bailIfCursor(TSD->cursors, "attempt to write during r/o cursor");
retry:
retry:
txbegin(&tid);
- if ((ret = dbp[cdb]->del(dbp[cdb], tid, &dkey, 0))
- && ret != DB_NOTFOUND) {
+ if ((ret = dbp[cdb]->del(dbp[cdb], tid, &dkey, 0)) && ret != DB_NOTFOUND) {
if (ret == DB_LOCK_DEADLOCK) {
txabort(tid);
goto retry;
return ret;
}
+
static DBC *localcursor(int cdb)
{
int ret;
DBC *curs;
- if (TSD->cursors[cdb] == NULL)
+ if (TSD->cursors[cdb] == NULL) {
ret = dbp[cdb]->cursor(dbp[cdb], TSD->tid, &curs, 0);
- else
+ }
+ else {
ret = TSD->cursors[cdb]->c_dup(TSD->cursors[cdb], &curs, DB_POSITION);
+ }
if (ret) {
syslog(LOG_EMERG, "db: localcursor: %s", db_strerror(ret));
memset(&dkey, 0, sizeof(DBT));
dkey.size = keylen;
- dkey.data = (void *)key;
+ dkey.data = (void *) key;
if (TSD->tid != NULL) {
memset(&dret, 0, sizeof(DBT));
cdb_abort();
}
- if (ret != 0)
+ if (ret != 0) {
return NULL;
+ }
+
tempcdb = (struct cdbdata *) malloc(sizeof(struct cdbdata));
if (tempcdb == NULL) {
syslog(LOG_EMERG, "db: cdb_fetch: Cannot allocate memory for tempcdb");
cdb_abort();
- return NULL; /* make it easier for static analysis... */
- }
- else
- {
+ return NULL; /* make it easier for static analysis... */
+ } else {
tempcdb->len = dret.size;
tempcdb->ptr = dret.data;
cdb_decompress_if_necessary(tempcdb);
free(cdb);
}
+
void cdb_close_cursor(int cdb)
{
if (TSD->cursors[cdb] != NULL) {
TSD->cursors[cdb] = NULL;
}
+
/*
* Prepare for a sequential search of an entire database.
* (There is guaranteed to be no more than one traversal in
}
-
/*
* Transaction-based stuff. I'm writing this as I bake cookies...
*/
-
void cdb_begin_transaction(void)
{
txbegin(&TSD->tid);
}
+
void cdb_end_transaction(void)
{
int i;
if (TSD->tid == NULL) {
syslog(LOG_ERR, "db: cdb_end_transaction: ERROR: txcommit(NULL) !!");
cdb_abort();
- }
- else {
+ } else {
txcommit(TSD->tid);
}
TSD->tid = NULL;
}
+
/*
* Truncate (delete every record)
*/
if (TSD->tid != NULL) {
syslog(LOG_EMERG, "db: cdb_trunc must not be called in a transaction.");
cdb_abort();
- }
- else {
+ } else {
bailIfCursor(TSD->cursors, "attempt to write during r/o cursor");
retry:
} else {
syslog(LOG_EMERG, "db: cdb_truncate(%d): %s", cdb, db_strerror(ret));
if (ret == ENOMEM) {
- syslog(LOG_EMERG, "db: You may need to tune your database; please read http://www.citadel.org/doku.php?id=faq:troubleshooting:out_of_lock_entries for more information.");
+ syslog(LOG_EMERG,
+ "db: You may need to tune your database; please read http://www.citadel.org/doku.php?id=faq:troubleshooting:out_of_lock_entries for more information.");
}
exit(CTDLEXIT_DB);
}
memcpy(ut.ut_msgid, SKEY(guid));
ut.ut_timestamp = time(NULL);
cdb_store(CDB_USETABLE, SKEY(guid), &ut, sizeof(struct UseTable));
- return(found);
+ return (found);
}
-void cmd_rsen(char *argbuf) {
+void cmd_rsen(char *argbuf)
+{
char Token[SIZ];
long TLen;
char Time[SIZ];
struct UseTable ut;
struct cdbdata *cdbut;
-
- if (CtdlAccessCheck(ac_aide)) return;
+
+ if (CtdlAccessCheck(ac_aide)) {
+ return;
+ }
TLen = extract_token(Token, argbuf, 1, '|', sizeof Token);
if (strncmp(argbuf, "GET", 3) == 0) {
cdbut = cdb_fetch(CDB_USETABLE, Token, TLen);
if (cdbut != NULL) {
- memcpy(&ut, cdbut->ptr,
- ((cdbut->len > sizeof(struct UseTable)) ?
- sizeof(struct UseTable) : cdbut->len));
-
+ memcpy(&ut, cdbut->ptr, ((cdbut->len > sizeof(struct UseTable)) ? sizeof(struct UseTable) : cdbut->len));
+
cprintf("%d %ld\n", CIT_OK, ut.ut_timestamp);
- }
- else {
+ } else {
cprintf("%d not found\n", ERROR + NOT_HERE);
}
- }
- else if (strncmp(argbuf, "SET", 3) == 0) {
+ } else if (strncmp(argbuf, "SET", 3) == 0) {
memcpy(ut.ut_msgid, Token, TLen);
extract_token(Time, argbuf, 2, '|', sizeof Time);
ut.ut_timestamp = atol(Time);
- cdb_store(CDB_USETABLE,
- Token, TLen,
- &ut, sizeof(struct UseTable) );
+ cdb_store(CDB_USETABLE, Token, TLen, &ut, sizeof(struct UseTable));
cprintf("%d token updated\n", CIT_OK);
- }
- else if (strncmp(argbuf, "DEL", 3) == 0) {
+ } else if (strncmp(argbuf, "DEL", 3) == 0) {
if (cdb_delete(CDB_USETABLE, Token, TLen))
cprintf("%d not found\n", ERROR + NOT_HERE);
else
cprintf("%d deleted.\n", CIT_OK);
- }
- else {
+ } else {
cprintf("%d Usage: [GET|SET|DEL]|Token|timestamp\n", ERROR);
}
}
+
CTDL_MODULE_INIT(database)
{
- if (!threading)
- {
+ if (!threading) {
CtdlRegisterProtoHook(cmd_rsen, "RSEN", "manipulate Aggregators seen database");
}
/* return our module id for the log */
- return "database";
+ return "database";
}
-/* A Bison parser, made by GNU Bison 3.0.2. */
+/* A Bison parser, made by GNU Bison 3.0.4. */
/* Bison implementation for Yacc-like parsers in C
- Copyright (C) 1984, 1989-1990, 2000-2013 Free Software Foundation, Inc.
+ Copyright (C) 1984, 1989-1990, 2000-2015 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
#define YYBISON 1
/* Bison version. */
-#define YYBISON_VERSION "3.0.2"
+#define YYBISON_VERSION "3.0.4"
/* Skeleton name. */
#define YYSKELETON_NAME "yacc.c"
/* Value type. */
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
-typedef union YYSTYPE YYSTYPE;
+
union YYSTYPE
{
#line 114 "parsedate.y" /* yacc.c:355 */
#line 243 "y.tab.c" /* yacc.c:355 */
};
+
+typedef union YYSTYPE YYSTYPE;
# define YYSTYPE_IS_TRIVIAL 1
# define YYSTYPE_IS_DECLARED 1
#endif
/* Copy the second part of user declarations. */
-#line 258 "y.tab.c" /* yacc.c:358 */
+#line 260 "y.tab.c" /* yacc.c:358 */
#ifdef short
# undef short
}
#endif /* lint */
}
-#line 1364 "y.tab.c" /* yacc.c:1646 */
+#line 1366 "y.tab.c" /* yacc.c:1646 */
break;
case 5:
yyHaveTime++;
yyTimezone = (yyvsp[0].Number);
}
-#line 1373 "y.tab.c" /* yacc.c:1646 */
+#line 1375 "y.tab.c" /* yacc.c:1646 */
break;
case 6:
{
yyHaveDate++;
}
-#line 1381 "y.tab.c" /* yacc.c:1646 */
+#line 1383 "y.tab.c" /* yacc.c:1646 */
break;
case 7:
{
yyHaveRel = 1;
}
-#line 1389 "y.tab.c" /* yacc.c:1646 */
+#line 1391 "y.tab.c" /* yacc.c:1646 */
break;
case 8:
yySeconds = 0;
yyMeridian = (yyvsp[0].Meridian);
}
-#line 1406 "y.tab.c" /* yacc.c:1646 */
+#line 1408 "y.tab.c" /* yacc.c:1646 */
break;
case 9:
yySeconds = 0;
yyMeridian = (yyvsp[0].Meridian);
}
-#line 1417 "y.tab.c" /* yacc.c:1646 */
+#line 1419 "y.tab.c" /* yacc.c:1646 */
break;
case 10:
yyMeridian = MER24;
yyDSTmode = DSToff;
}
-#line 1429 "y.tab.c" /* yacc.c:1646 */
+#line 1431 "y.tab.c" /* yacc.c:1646 */
break;
case 11:
yySeconds = (yyvsp[-1].Number);
yyMeridian = (yyvsp[0].Meridian);
}
-#line 1440 "y.tab.c" /* yacc.c:1646 */
+#line 1442 "y.tab.c" /* yacc.c:1646 */
break;
case 12:
yyMeridian = MER24;
yyDSTmode = DSToff;
}
-#line 1453 "y.tab.c" /* yacc.c:1646 */
+#line 1455 "y.tab.c" /* yacc.c:1646 */
break;
case 13:
(yyval.Number) = (yyvsp[0].Number);
yyDSTmode = DSToff;
}
-#line 1462 "y.tab.c" /* yacc.c:1646 */
+#line 1464 "y.tab.c" /* yacc.c:1646 */
break;
case 14:
(yyval.Number) = (yyvsp[0].Number);
yyDSTmode = DSTon;
}
-#line 1471 "y.tab.c" /* yacc.c:1646 */
+#line 1473 "y.tab.c" /* yacc.c:1646 */
break;
case 15:
(yyval.Number) = (yyvsp[0].Number);
yyDSTmode = DSToff;
}
-#line 1484 "y.tab.c" /* yacc.c:1646 */
+#line 1486 "y.tab.c" /* yacc.c:1646 */
break;
case 16:
(yyval.Number) = (yyvsp[0].Number);
yyDSTmode = DSToff;
}
-#line 1493 "y.tab.c" /* yacc.c:1646 */
+#line 1495 "y.tab.c" /* yacc.c:1646 */
break;
case 17:
(yyval.Number) = -(((yyvsp[0].Number) / 100) * 60 + i);
}
}
-#line 1517 "y.tab.c" /* yacc.c:1646 */
+#line 1519 "y.tab.c" /* yacc.c:1646 */
break;
case 18:
yyMonth = (yyvsp[-2].Number);
yyDay = (yyvsp[0].Number);
}
-#line 1526 "y.tab.c" /* yacc.c:1646 */
+#line 1528 "y.tab.c" /* yacc.c:1646 */
break;
case 19:
yyYear = (yyvsp[0].Number);
}
}
-#line 1543 "y.tab.c" /* yacc.c:1646 */
+#line 1545 "y.tab.c" /* yacc.c:1646 */
break;
case 20:
yyMonth = (yyvsp[-1].Number);
yyDay = (yyvsp[0].Number);
}
-#line 1552 "y.tab.c" /* yacc.c:1646 */
+#line 1554 "y.tab.c" /* yacc.c:1646 */
break;
case 21:
yyDay = (yyvsp[-2].Number);
yyYear = (yyvsp[0].Number);
}
-#line 1562 "y.tab.c" /* yacc.c:1646 */
+#line 1564 "y.tab.c" /* yacc.c:1646 */
break;
case 22:
yyDay = (yyvsp[-1].Number);
yyMonth = (yyvsp[0].Number);
}
-#line 1571 "y.tab.c" /* yacc.c:1646 */
+#line 1573 "y.tab.c" /* yacc.c:1646 */
break;
case 23:
yyMonth = (yyvsp[-1].Number);
yyYear = (yyvsp[0].Number);
}
-#line 1581 "y.tab.c" /* yacc.c:1646 */
+#line 1583 "y.tab.c" /* yacc.c:1646 */
break;
case 24:
yyMonth = (yyvsp[-1].Number);
yyYear = (yyvsp[0].Number);
}
-#line 1591 "y.tab.c" /* yacc.c:1646 */
+#line 1593 "y.tab.c" /* yacc.c:1646 */
break;
case 25:
{
yyRelSeconds += (yyvsp[-1].Number) * (yyvsp[0].Number);
}
-#line 1599 "y.tab.c" /* yacc.c:1646 */
+#line 1601 "y.tab.c" /* yacc.c:1646 */
break;
case 26:
{
yyRelSeconds += (yyvsp[-1].Number) * (yyvsp[0].Number);
}
-#line 1607 "y.tab.c" /* yacc.c:1646 */
+#line 1609 "y.tab.c" /* yacc.c:1646 */
break;
case 27:
{
yyRelMonth += (yyvsp[-1].Number) * (yyvsp[0].Number);
}
-#line 1615 "y.tab.c" /* yacc.c:1646 */
+#line 1617 "y.tab.c" /* yacc.c:1646 */
break;
case 28:
{
yyRelMonth += (yyvsp[-1].Number) * (yyvsp[0].Number);
}
-#line 1623 "y.tab.c" /* yacc.c:1646 */
+#line 1625 "y.tab.c" /* yacc.c:1646 */
break;
case 29:
{
(yyval.Meridian) = MER24;
}
-#line 1631 "y.tab.c" /* yacc.c:1646 */
+#line 1633 "y.tab.c" /* yacc.c:1646 */
break;
case 30:
{
(yyval.Meridian) = (yyvsp[0].Meridian);
}
-#line 1639 "y.tab.c" /* yacc.c:1646 */
+#line 1641 "y.tab.c" /* yacc.c:1646 */
break;
-#line 1643 "y.tab.c" /* yacc.c:1646 */
+#line 1645 "y.tab.c" /* yacc.c:1646 */
default: break;
}
/* User semantic actions sometimes alter yychar, and that requires