From bf17b7946bca97f763f1d86557d1a56ad19ffae7 Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Mon, 28 Aug 2023 22:38:55 -0400 Subject: [PATCH] When opening a cursor, always read through to the end. This should theoretically eliminate the need to ever call cdb_close_cursor() --- citadel/server/control.c | 2 +- citadel/server/modules/ctdlproto/serv_rooms.c | 2 +- citadel/server/modules/ctdlproto/serv_user.c | 8 ++++++-- citadel/server/modules/expire/serv_expire.c | 6 +++--- citadel/server/modules/imap/imap_acl.c | 2 +- citadel/server/room_ops.c | 5 ++--- citadel/server/user_ops.c | 7 +++---- citadel/utils/ctdldump.c | 2 +- 8 files changed, 18 insertions(+), 16 deletions(-) diff --git a/citadel/server/control.c b/citadel/server/control.c index 9476e40be..51e9f7d60 100644 --- a/citadel/server/control.c +++ b/citadel/server/control.c @@ -646,7 +646,7 @@ void cmd_conf(char *argbuf) { cprintf("%d all configuration variables\n", LISTING_FOLLOWS); cdb_rewind(CDB_CONFIG); - while (cdbcfg = cdb_next_item(CDB_CONFIG), cdbcfg.val.ptr!=NULL) { + while (cdbcfg = cdb_next_item(CDB_CONFIG), cdbcfg.val.ptr!=NULL) { // always read to the end if (cdbcfg.val.len < 1020) { keylen = strlen(cdbcfg.val.ptr); key = cdbcfg.val.ptr; diff --git a/citadel/server/modules/ctdlproto/serv_rooms.c b/citadel/server/modules/ctdlproto/serv_rooms.c index 29f57c888..f8d571d1f 100644 --- a/citadel/server/modules/ctdlproto/serv_rooms.c +++ b/citadel/server/modules/ctdlproto/serv_rooms.c @@ -327,7 +327,7 @@ void cmd_whok(char *cmdbuf) { cprintf("%d Who knows room:\n", LISTING_FOLLOWS); cdb_rewind(CDB_USERS); - while (cdbus = cdb_next_item(CDB_USERS), cdbus.val.ptr!=NULL) { + while (cdbus = cdb_next_item(CDB_USERS), cdbus.val.ptr!=NULL) { // always read to the end memset(&temp, 0, sizeof temp); memcpy(&temp, cdbus.val.ptr, sizeof temp); CtdlRoomAccess(&CC->room, &temp, &ra, NULL); diff --git a/citadel/server/modules/ctdlproto/serv_user.c b/citadel/server/modules/ctdlproto/serv_user.c index 48fe21d9f..981b56ff7 100644 --- a/citadel/server/modules/ctdlproto/serv_user.c +++ b/citadel/server/modules/ctdlproto/serv_user.c @@ -383,6 +383,7 @@ void cmd_forg(char *argbuf) { void cmd_gnur(char *argbuf) { struct cdbkeyval cdbus; struct ctdluser usbuf; + int found_it = 0; if (CtdlAccessCheck(ac_aide)) { return; @@ -400,11 +401,14 @@ void cmd_gnur(char *argbuf) { memcpy(&usbuf, cdbus.val.ptr, ((cdbus.val.len > sizeof(struct ctdluser)) ? sizeof(struct ctdluser) : cdbus.val.len)); if ((usbuf.flags & US_NEEDVALID) && (usbuf.axlevel > AxDeleted)) { cprintf("%d %s\n", MORE_DATA, usbuf.fullname); - cdb_close_cursor(CDB_USERS); - return; + found_it = 1; // always read through to the end } } + if (found_it) { + return; + } + // If we get to this point, there are no more unvalidated users. Therefore we clear the "users need validation" flag. begin_critical_section(S_CONTROL); int flags; diff --git a/citadel/server/modules/expire/serv_expire.c b/citadel/server/modules/expire/serv_expire.c index f360804a2..48f76b8f2 100644 --- a/citadel/server/modules/expire/serv_expire.c +++ b/citadel/server/modules/expire/serv_expire.c @@ -505,7 +505,7 @@ int PurgeVisits(void) { // Now traverse through the visits, purging irrelevant records... cdb_rewind(CDB_VISIT); - while(cdbvisit = cdb_next_item(CDB_VISIT), cdbvisit.val.ptr!=NULL) { + while(cdbvisit = cdb_next_item(CDB_VISIT), cdbvisit.val.ptr!=NULL) { // always read through to the end memset(&vbuf, 0, sizeof(struct visit)); memcpy(&vbuf, cdbvisit.val.ptr, ((cdbvisit.val.len > sizeof(struct visit)) ? sizeof(struct visit) : cdbvisit.val.len)); RoomIsValid = 0; @@ -583,7 +583,7 @@ int PurgeUseTable(StrBuf *ErrMsg) { syslog(LOG_DEBUG, "Purge use table: phase 1"); cdb_rewind(CDB_USETABLE); - while(cdbut = cdb_next_item(CDB_USETABLE), cdbut.val.ptr!=NULL) { + while(cdbut = cdb_next_item(CDB_USETABLE), cdbut.val.ptr!=NULL) { // always read through to the end ++total; if (cdbut.val.len > sizeof(struct UseTable)) memcpy(&ut, cdbut.val.ptr, sizeof(struct UseTable)); @@ -626,7 +626,7 @@ int PurgeEuidIndexTable(void) { // Phase 1: traverse through the table, discovering old records... syslog(LOG_DEBUG, "Purge EUID index: phase 1"); cdb_rewind(CDB_EUIDINDEX); - while(cdbei = cdb_next_item(CDB_EUIDINDEX), cdbei.val.ptr!=NULL) { + while(cdbei = cdb_next_item(CDB_EUIDINDEX), cdbei.val.ptr!=NULL) { // always read through to the end memcpy(&msgnum, cdbei.val.ptr, sizeof(long)); diff --git a/citadel/server/modules/imap/imap_acl.c b/citadel/server/modules/imap/imap_acl.c index fbc5460af..69e56301d 100644 --- a/citadel/server/modules/imap/imap_acl.c +++ b/citadel/server/modules/imap/imap_acl.c @@ -136,7 +136,7 @@ void imap_getacl(int num_parms, ConstStr *Params) { // Traverse the userlist rights = NewStrBuf(); cdb_rewind(CDB_USERS); - while (cdbus = cdb_next_item(CDB_USERS), cdbus.val.ptr!=NULL) { + while (cdbus = cdb_next_item(CDB_USERS), cdbus.val.ptr!=NULL) { // always read through to the end memset(&temp, 0, sizeof temp); memcpy(&temp, cdbus.val.ptr, sizeof temp); diff --git a/citadel/server/room_ops.c b/citadel/server/room_ops.c index cabaf96fd..f61e1f126 100644 --- a/citadel/server/room_ops.c +++ b/citadel/server/room_ops.c @@ -526,10 +526,9 @@ void CtdlForEachRoom(ForEachRoomCallBack callback_func, void *in_data) { struct cdbkeyval cdbqr; cdb_rewind(CDB_ROOMS); - - while (cdbqr = cdb_next_item(CDB_ROOMS), cdbqr.val.ptr!=NULL) { + while (cdbqr = cdb_next_item(CDB_ROOMS), cdbqr.val.ptr!=NULL) { // always read through to the end memset(&qrbuf, 0, sizeof(struct ctdlroom)); - memcpy(&qrbuf, cdbqr.val.ptr, ((cdbqr.val.len > sizeof(struct ctdlroom)) ? sizeof(struct ctdlroom) : cdbqr.val.len) ); + memcpy(&qrbuf, cdbqr.val.ptr, ((cdbqr.val.len > sizeof(struct ctdlroom)) ? sizeof(struct ctdlroom) : cdbqr.val.len) ); room_sanity_check(&qrbuf); if (qrbuf.QRflags & QR_INUSE) { callback_func(&qrbuf, in_data); diff --git a/citadel/server/user_ops.c b/citadel/server/user_ops.c index 7c85b0118..61183bcc0 100644 --- a/citadel/server/user_ops.c +++ b/citadel/server/user_ops.c @@ -398,7 +398,7 @@ int getuserbyuid(struct ctdluser *usbuf, uid_t number) { // Yes, we do this the long way. Someday we might want to try an index. // No, we don't use CtdlForEachUser() because that requires multiple reads for each record cdb_rewind(CDB_USERS); - while (cdbus = cdb_next_item(CDB_USERS), cdbus.val.ptr!=NULL) { + while (cdbus = cdb_next_item(CDB_USERS), cdbus.val.ptr!=NULL) { // always read through to the end usptr = (struct ctdluser *) cdbus.val.ptr; if (usptr->uid == number) { @@ -1040,10 +1040,9 @@ void ForEachUser(void (*CallBack) (char *, void *out_data), void *in_data) { } - cdb_rewind(CDB_USERS); - // Phase 1 : build an array of all our user account names - while (cdbus = cdb_next_item(CDB_USERS), cdbus.val.ptr!=NULL) { + cdb_rewind(CDB_USERS); + while (cdbus = cdb_next_item(CDB_USERS), cdbus.val.ptr!=NULL) { // always read through to the end usptr = (struct ctdluser *) cdbus.val.ptr; if (strlen(usptr->fullname) > 0) { array_append(all_users, usptr->fullname); diff --git a/citadel/utils/ctdldump.c b/citadel/utils/ctdldump.c index 0997189de..cf7257813 100644 --- a/citadel/utils/ctdldump.c +++ b/citadel/utils/ctdldump.c @@ -343,7 +343,7 @@ void export_table(int which_cdb) { int num_bad_rows = 0; cdb_rewind(which_cdb); - while (ckv = cdb_next_item(which_cdb), ckv.val.ptr!=NULL) { + while (ckv = cdb_next_item(which_cdb), ckv.val.ptr!=NULL) { // always read through to the end // Call the export function registered to this table export_functions[which_cdb](which_cdb, ckv); } -- 2.39.2