From c61307c63378edc18a9adbd628f5fbfc4a78025c Mon Sep 17 00:00:00 2001 From: Dave West Date: Sun, 25 Oct 2009 00:26:06 +0000 Subject: [PATCH] A few more API clean ups. Mainly revolving around user_ops.c --- citadel/file_ops.c | 2 +- citadel/include/ctdl_module.h | 13 ++ citadel/journaling.c | 2 +- citadel/modules/bio/serv_bio.c | 43 +------ citadel/modules/calendar/serv_calendar.c | 8 +- citadel/modules/chat/serv_chat.c | 4 +- citadel/modules/extnotify/extnotify_main.c | 2 +- citadel/modules/imap/imap_acl.c | 2 +- citadel/modules/imap/imap_search.c | 3 + citadel/modules/imap/imap_store.c | 3 +- citadel/msgbase.c | 14 +-- citadel/room_ops.c | 16 +-- citadel/server_main.c | 6 +- citadel/sysdep.c | 2 +- citadel/user_ops.c | 136 ++++++++++++++------- citadel/user_ops.h | 15 ++- citadel/utils/aidepost.c | 2 + citadel/utils/getmail.c | 2 + citadel/utils/sendcommand.c | 1 + citadel/utils/setup.c | 3 + 20 files changed, 161 insertions(+), 118 deletions(-) diff --git a/citadel/file_ops.c b/citadel/file_ops.c index 2544077bd..99009a1b7 100644 --- a/citadel/file_ops.c +++ b/citadel/file_ops.c @@ -326,7 +326,7 @@ void cmd_oimg(char *cmdbuf) if (!strcasecmp(filename, "_userpic_")) { extract_token(which_user, cmdbuf, 1, '|', sizeof which_user); - if (getuser(&usbuf, which_user) != 0) { + if (CtdlGetUser(&usbuf, which_user) != 0) { cprintf("%d No such user.\n", ERROR + NO_SUCH_USER); return; diff --git a/citadel/include/ctdl_module.h b/citadel/include/ctdl_module.h index 345a786f6..c0e24b637 100644 --- a/citadel/include/ctdl_module.h +++ b/citadel/include/ctdl_module.h @@ -41,6 +41,7 @@ #include "sysdep_decls.h" #include "msgbase.h" #include "threads.h" +#include "citadel_dirs.h" /* * define macros for module init stuff */ @@ -269,4 +270,16 @@ struct config { extern struct config config; + + +/* + * Expose API calls from user_ops.c + */ +int CtdlGetUser(struct ctdluser *usbuf, char name[]); +int CtdlGetUserLock(struct ctdluser *usbuf, char *name); +void CtdlPutUser(struct ctdluser *usbuf); +void CtdlPutUserLock(struct ctdluser *usbuf); +int CtdlGetUserByNumber(struct ctdluser *usbuf, long number); + + #endif /* CTDL_MODULE_H */ diff --git a/citadel/journaling.c b/citadel/journaling.c index 6f5e69644..80122f25a 100644 --- a/citadel/journaling.c +++ b/citadel/journaling.c @@ -105,7 +105,7 @@ void local_to_inetemail(char *inetemail, char *localuser, size_t inetemail_len) struct vCard *v; strcpy(inetemail, ""); - if (getuser(&us, localuser) != 0) { + if (CtdlGetUser(&us, localuser) != 0) { return; } diff --git a/citadel/modules/bio/serv_bio.c b/citadel/modules/bio/serv_bio.c index afebe1242..43cc0e98c 100644 --- a/citadel/modules/bio/serv_bio.c +++ b/citadel/modules/bio/serv_bio.c @@ -22,45 +22,10 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "sysdep.h" -#include -#include -#include -#include -#include -#include -#include -#include - -#if TIME_WITH_SYS_TIME -# include -# include -#else -# if HAVE_SYS_TIME_H -# include -# else -# include -# endif -#endif - -#include -#include -#include -#include -#include "citadel.h" -#include "server.h" -#include "citserver.h" -#include "support.h" -#include "config.h" -#include "control.h" -#include "user_ops.h" -#include "policy.h" -#include "database.h" -#include "msgbase.h" -#include "citadel_dirs.h" - #include "ctdl_module.h" + + /* * enter user bio */ @@ -101,7 +66,7 @@ void cmd_rbio(char *cmdbuf) FILE *fp; extract_token(buf, cmdbuf, 0, '|', sizeof buf); - if (getuser(&ruser, buf) != 0) { + if (CtdlGetUser(&ruser, buf) != 0) { cprintf("%d No such user.\n",ERROR + NO_SUCH_USER); return; } @@ -138,7 +103,7 @@ void cmd_lbio(char *cmdbuf) { cprintf("%d\n", LISTING_FOLLOWS); while (fgets(buf, sizeof buf, ls)!=NULL) - if (getuserbynumber(&usbuf,atol(buf))==0) + if (CtdlGetUserByNumber(&usbuf,atol(buf))==0) cprintf("%s\n", usbuf.fullname); pclose(ls); cprintf("000\n"); diff --git a/citadel/modules/calendar/serv_calendar.c b/citadel/modules/calendar/serv_calendar.c index 8fc856111..2e7dc422e 100644 --- a/citadel/modules/calendar/serv_calendar.c +++ b/citadel/modules/calendar/serv_calendar.c @@ -1441,7 +1441,7 @@ void ical_freebusy(char *who) { int config_lines = 0; /* First try an exact match. */ - found_user = getuser(&usbuf, who); + found_user = CtdlGetUser(&usbuf, who); /* If not found, try it as an unqualified email address. */ if (found_user != 0) { @@ -1450,7 +1450,7 @@ void ical_freebusy(char *who) { CtdlLogPrintf(CTDL_DEBUG, "Trying <%s>\n", buf); if (recp != NULL) { if (recp->num_local == 1) { - found_user = getuser(&usbuf, recp->recp_local); + found_user = CtdlGetUser(&usbuf, recp->recp_local); } free_recipients(recp); } @@ -1465,7 +1465,7 @@ void ical_freebusy(char *who) { recp = validate_recipients(buf, NULL, 0); if (recp != NULL) { if (recp->num_local == 1) { - found_user = getuser(&usbuf, recp->recp_local); + found_user = CtdlGetUser(&usbuf, recp->recp_local); } free_recipients(recp); } @@ -1488,7 +1488,7 @@ void ical_freebusy(char *who) { recp = validate_recipients(buf, NULL, 0); if (recp != NULL) { if (recp->num_local == 1) { - found_user = getuser(&usbuf, recp->recp_local); + found_user = CtdlGetUser(&usbuf, recp->recp_local); } free_recipients(recp); } diff --git a/citadel/modules/chat/serv_chat.c b/citadel/modules/chat/serv_chat.c index e0515963f..6b479b06a 100644 --- a/citadel/modules/chat/serv_chat.c +++ b/citadel/modules/chat/serv_chat.c @@ -752,7 +752,7 @@ void cmd_sexp(char *argbuf) if (!strcmp(x_msg, "-")) { message_sent = PerformXmsgHooks(lun, lem, x_user, ""); if (message_sent == 0) { - if (getuser(NULL, x_user)) + if (CtdlGetUser(NULL, x_user)) cprintf("%d '%s' does not exist.\n", ERROR + NO_SUCH_USER, x_user); else @@ -790,7 +790,7 @@ void cmd_sexp(char *argbuf) cprintf(" to %d users", message_sent); cprintf(".\n"); } else { - if (getuser(NULL, x_user)) + if (CtdlGetUser(NULL, x_user)) cprintf("%d '%s' does not exist.\n", ERROR + NO_SUCH_USER, x_user); else diff --git a/citadel/modules/extnotify/extnotify_main.c b/citadel/modules/extnotify/extnotify_main.c index b772bbb09..3255f4b16 100644 --- a/citadel/modules/extnotify/extnotify_main.c +++ b/citadel/modules/extnotify/extnotify_main.c @@ -365,7 +365,7 @@ long extNotify_getConfigMessage(char *username) { int a; // Get the user - getuser(&user, username); + CtdlGetUser(&user, username); MailboxName(configRoomName, sizeof configRoomName, &user, USERCONFIGROOM); // Fill qrbuf diff --git a/citadel/modules/imap/imap_acl.c b/citadel/modules/imap/imap_acl.c index 7ef289db5..be563b7b5 100644 --- a/citadel/modules/imap/imap_acl.c +++ b/citadel/modules/imap/imap_acl.c @@ -249,7 +249,7 @@ void imap_listrights(int num_parms, char *parms[]) { valid = validate_recipients(parms[3], NULL, 0); if (valid != NULL) { if (valid->num_local == 1) { - ret = getuser(&temp, valid->recp_local); + ret = CtdlGetUser(&temp, valid->recp_local); } free_recipients(valid); } diff --git a/citadel/modules/imap/imap_search.c b/citadel/modules/imap/imap_search.c index 90644b1e4..524131816 100644 --- a/citadel/modules/imap/imap_search.c +++ b/citadel/modules/imap/imap_search.c @@ -21,6 +21,9 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include "ctdl_module.h" + + #include "sysdep.h" #include #include diff --git a/citadel/modules/imap/imap_store.c b/citadel/modules/imap/imap_store.c index 892933025..a906d60ea 100644 --- a/citadel/modules/imap/imap_store.c +++ b/citadel/modules/imap/imap_store.c @@ -21,8 +21,9 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include "ctdl_module.h" + -#include "sysdep.h" #include #include #include diff --git a/citadel/msgbase.c b/citadel/msgbase.c index e83a6d36b..357dd1162 100644 --- a/citadel/msgbase.c +++ b/citadel/msgbase.c @@ -608,7 +608,7 @@ int CtdlForEachMessage(int mode, long ref, char *search_string, } /* Learn about the user and room in question */ - getuser(&CC->user, CC->curr_user); + CtdlGetUser(&CC->user, CC->curr_user); CtdlGetRelationship(&vbuf, &CC->user, &CC->room); /* Load the message list */ @@ -2900,9 +2900,9 @@ long CtdlSubmitMsg(struct CtdlMessage *msg, /* message to save */ /* Bump this user's messages posted counter. */ CtdlLogPrintf(CTDL_DEBUG, "Updating user\n"); - lgetuser(&CCC->user, CCC->curr_user); + CtdlGetUserLock(&CCC->user, CCC->curr_user); CCC->user.posted = CCC->user.posted + 1; - lputuser(&CCC->user); + CtdlPutUserLock(&CCC->user); /* Decide where bounces need to be delivered */ if ((recps != NULL) && (recps->bounce_to != NULL)) { @@ -2924,7 +2924,7 @@ long CtdlSubmitMsg(struct CtdlMessage *msg, /* message to save */ '|', sizeof recipient); CtdlLogPrintf(CTDL_DEBUG, "Delivering private local mail to <%s>\n", recipient); - if (getuser(&userbuf, recipient) == 0) { + if (CtdlGetUser(&userbuf, recipient) == 0) { // Add a flag so the Funambol module knows its mail msg->cm_fields['W'] = strdup(recipient); MailboxName(actual_rm, sizeof actual_rm, &userbuf, MAILROOM); @@ -3655,7 +3655,7 @@ struct recptypes *validate_recipients(char *supplied_recipients, CC->room = tempQR2; } - else if (getuser(&tempUS, this_recp) == 0) { + else if (CtdlGetUser(&tempUS, this_recp) == 0) { ++ret->num_local; strcpy(this_recp, tempUS.fullname); if (!IsEmptyStr(ret->recp_local)) { @@ -3663,7 +3663,7 @@ struct recptypes *validate_recipients(char *supplied_recipients, } strcat(ret->recp_local, this_recp); } - else if (getuser(&tempUS, this_recp_cooked) == 0) { + else if (CtdlGetUser(&tempUS, this_recp_cooked) == 0) { ++ret->num_local; strcpy(this_recp, tempUS.fullname); if (!IsEmptyStr(ret->recp_local)) { @@ -4300,7 +4300,7 @@ void cmd_move(char *args) return; } - getuser(&CC->user, CC->curr_user); + CtdlGetUser(&CC->user, CC->curr_user); CtdlRoomAccess(&qtemp, &CC->user, &ra, NULL); /* Check for permission to perform this operation. diff --git a/citadel/room_ops.c b/citadel/room_ops.c index 1ef9f0a94..f0c5cc98e 100644 --- a/citadel/room_ops.c +++ b/citadel/room_ops.c @@ -608,7 +608,7 @@ void cmd_lrms(char *argbuf) if (CtdlAccessCheck(ac_logged_in)) return; - if (getuser(&CC->user, CC->curr_user)) { + if (CtdlGetUser(&CC->user, CC->curr_user)) { cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR); return; } @@ -646,7 +646,7 @@ void cmd_lkra(char *argbuf) if (CtdlAccessCheck(ac_logged_in)) return; - if (getuser(&CC->user, CC->curr_user)) { + if (CtdlGetUser(&CC->user, CC->curr_user)) { cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR); return; } @@ -715,7 +715,7 @@ void cmd_lkrn(char *argbuf) if (CtdlAccessCheck(ac_logged_in)) return; - if (getuser(&CC->user, CC->curr_user)) { + if (CtdlGetUser(&CC->user, CC->curr_user)) { cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR); return; } @@ -754,7 +754,7 @@ void cmd_lkro(char *argbuf) if (CtdlAccessCheck(ac_logged_in)) return; - if (getuser(&CC->user, CC->curr_user)) { + if (CtdlGetUser(&CC->user, CC->curr_user)) { cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR); return; } @@ -793,7 +793,7 @@ void cmd_lzrm(char *argbuf) if (CtdlAccessCheck(ac_logged_in)) return; - if (getuser(&CC->user, CC->curr_user)) { + if (CtdlGetUser(&CC->user, CC->curr_user)) { cprintf("%d Can't locate user!\n", ERROR + INTERNAL_ERROR); return; } @@ -1018,7 +1018,7 @@ void cmd_goto(char *gargs) extract_token(password, gargs, 1, '|', sizeof password); transiently = extract_int(gargs, 2); - getuser(&CC->user, CC->curr_user); + CtdlGetUser(&CC->user, CC->curr_user); /* * Handle some of the macro named rooms @@ -1133,7 +1133,7 @@ void cmd_rdir(char *cmdbuf) if (CtdlAccessCheck(ac_logged_in)) return; CtdlGetRoom(&CC->room, CC->room.QRname); - getuser(&CC->user, CC->curr_user); + CtdlGetUser(&CC->user, CC->curr_user); if ((CC->room.QRflags & QR_DIRECTORY) == 0) { cprintf("%d not here.\n", ERROR + NOT_HERE); @@ -1532,7 +1532,7 @@ void cmd_seta(char *new_ra) if (CtdlAccessCheck(ac_room_aide)) return; - if (getuser(&usbuf, new_ra) != 0) { + if (CtdlGetUser(&usbuf, new_ra) != 0) { newu = (-1L); } else { newu = usbuf.usernum; diff --git a/citadel/server_main.c b/citadel/server_main.c index d57fdcf5f..71f81feb3 100644 --- a/citadel/server_main.c +++ b/citadel/server_main.c @@ -262,12 +262,12 @@ int main(int argc, char **argv) /** * Load the user for the masterCC or create them if they don't exist */ - if (getuser(&masterCC.user, "SYS_Citadel")) + if (CtdlGetUser(&masterCC.user, "SYS_Citadel")) { /** User doesn't exist. We can't use create user here as the user number needs to be 0 */ strcpy (masterCC.user.fullname, "SYS_Citadel") ; - putuser(&masterCC.user); - getuser(&masterCC.user, "SYS_Citadel"); /** Just to be safe */ + CtdlPutUser(&masterCC.user); + CtdlGetUser(&masterCC.user, "SYS_Citadel"); /** Just to be safe */ } /* diff --git a/citadel/sysdep.c b/citadel/sysdep.c index 7cc7fd0c4..c4aa2063c 100644 --- a/citadel/sysdep.c +++ b/citadel/sysdep.c @@ -550,7 +550,7 @@ void CtdlFillSystemContext(struct CitContext *context, char *name) context->user.usernum = get_new_user_number(); CtdlLogPrintf(CTDL_DEBUG, "Upgrading system user \"%s\" from user number 0 to user number %d\n", context->user.fullname, context->user.usernum); /* add user to the database */ - putuser(&(context->user)); + CtdlPutUser(&(context->user)); cdb_store(CDB_USERSBYNUMBER, &(context->user.usernum), sizeof(long), context->user.fullname, strlen(context->user.fullname)+1); } } diff --git a/citadel/user_ops.c b/citadel/user_ops.c index 580699fbe..7c96a1e9f 100644 --- a/citadel/user_ops.c +++ b/citadel/user_ops.c @@ -84,6 +84,16 @@ INLINE void makeuserkey(char *key, char *username) { * returns 0 on success */ int getuser(struct ctdluser *usbuf, char name[]) +{ + return CtdlGetUser(usbuf, name); +} + + +/* + * CtdlGetUser() - retrieve named user into supplied buffer. + * returns 0 on success + */ +int CtdlGetUser(struct ctdluser *usbuf, char name[]) { char usernamekey[USERNAME_SIZE]; @@ -111,13 +121,13 @@ int getuser(struct ctdluser *usbuf, char name[]) /* - * lgetuser() - same as getuser() but locks the record + * CtdlGetUserLock() - same as getuser() but locks the record */ -int lgetuser(struct ctdluser *usbuf, char *name) +int CtdlGetUserLock(struct ctdluser *usbuf, char *name) { int retcode; - retcode = getuser(usbuf, name); + retcode = CtdlGetUser(usbuf, name); if (retcode == 0) { begin_critical_section(S_USERS); } @@ -126,9 +136,18 @@ int lgetuser(struct ctdluser *usbuf, char *name) /* - * putuser() - write user buffer into the correct place on disk + * lgetuser() - same as getuser() but locks the record */ -void putuser(struct ctdluser *usbuf) +int lgetuser(struct ctdluser *usbuf, char *name) +{ + return CtdlGetUserLock(usbuf, name); +} + + +/* + * CtdlPutUser() - write user buffer into the correct place on disk + */ +void CtdlPutUser(struct ctdluser *usbuf) { char usernamekey[USERNAME_SIZE]; @@ -142,13 +161,31 @@ void putuser(struct ctdluser *usbuf) } +/* + * putuser() - write user buffer into the correct place on disk + */ +void putuser(struct ctdluser *usbuf) +{ + CtdlPutUser(usbuf); +} + + +/* + * CtdlPutUserLock() - same as putuser() but locks the record + */ +void CtdlPutUserLock(struct ctdluser *usbuf) +{ + CtdlPutUser(usbuf); + end_critical_section(S_USERS); +} + + /* * lputuser() - same as putuser() but locks the record */ void lputuser(struct ctdluser *usbuf) { - putuser(usbuf); - end_critical_section(S_USERS); + CtdlPutUserLock(usbuf); } @@ -180,12 +217,12 @@ int rename_user(char *oldname, char *newname) { /* Lock up and get going */ begin_critical_section(S_USERS); - if (getuser(&usbuf, newname) == 0) { + if (CtdlGetUser(&usbuf, newname) == 0) { retcode = RENAMEUSER_ALREADY_EXISTS; } else { - if (getuser(&usbuf, oldname) != 0) { + if (CtdlGetUser(&usbuf, oldname) != 0) { retcode = RENAMEUSER_NOT_FOUND; } @@ -198,7 +235,7 @@ int rename_user(char *oldname, char *newname) { CtdlLogPrintf(CTDL_DEBUG, "Renaming <%s> to <%s>\n", oldname, newname); cdb_delete(CDB_USERS, oldnamekey, strlen(oldnamekey)); safestrncpy(usbuf.fullname, newname, sizeof usbuf.fullname); - putuser(&usbuf); + CtdlPutUser(&usbuf); cdb_store(CDB_USERSBYNUMBER, &usbuf.usernum, sizeof(long), usbuf.fullname, strlen(usbuf.fullname)+1 ); @@ -361,12 +398,12 @@ int is_room_aide(void) } /* - * getuserbynumber() - get user by number + * CtdlGetUserByNumber() - get user by number * returns 0 if user was found * * Note: fetching a user this way requires one additional database operation. */ -int getuserbynumber(struct ctdluser *usbuf, long number) +int CtdlGetUserByNumber(struct ctdluser *usbuf, long number) { struct cdbdata *cdbun; int r; @@ -378,11 +415,22 @@ int getuserbynumber(struct ctdluser *usbuf, long number) } CtdlLogPrintf(CTDL_INFO, "User %ld maps to %s\n", number, cdbun->ptr); - r = getuser(usbuf, cdbun->ptr); + r = CtdlGetUser(usbuf, cdbun->ptr); cdb_free(cdbun); return(r); } +/* + * getuserbynumber() - get user by number + * returns 0 if user was found + * + * Note: fetching a user this way requires one additional database operation. + */ +int getuserbynumber(struct ctdluser *usbuf, long number) +{ + return CtdlGetUserByNumber(usbuf, number); +} + /* @@ -578,7 +626,7 @@ int CtdlLoginExistingUser(char *authname, char *trythisname) struct recptypes *valid = NULL; /* First, try to log in as if the supplied name is a display name */ - found_user = getuser(&CC->user, username); + found_user = CtdlGetUser(&CC->user, username); /* If that didn't work, try to log in as if the supplied name * is an e-mail address @@ -587,7 +635,7 @@ int CtdlLoginExistingUser(char *authname, char *trythisname) valid = validate_recipients(username, NULL, 0); if (valid != NULL) { if (valid->num_local == 1) { - found_user = getuser(&CC->user, valid->recp_local); + found_user = CtdlGetUser(&CC->user, valid->recp_local); } free_recipients(valid); } @@ -657,7 +705,7 @@ void do_login(void) CC->logged_in = 1; CtdlLogPrintf(CTDL_NOTICE, "<%s> logged in\n", CC->curr_user); - lgetuser(&CC->user, CC->curr_user); + CtdlGetUserLock(&CC->user, CC->curr_user); ++(CC->user.timescalled); CC->previous_login = CC->user.lastcall; time(&CC->user.lastcall); @@ -678,7 +726,7 @@ void do_login(void) } } - lputuser(&CC->user); + CtdlPutUserLock(&CC->user); /* * Populate CC->cs_inet_email with a default address. This will be @@ -853,7 +901,7 @@ int CtdlTryPassword(char *password) CtdlLogPrintf(CTDL_WARNING, "CtdlTryPassword: no user selected\n"); return pass_no_user; } - if (getuser(&CC->user, CC->curr_user)) { + if (CtdlGetUser(&CC->user, CC->curr_user)) { CtdlLogPrintf(CTDL_ERR, "CtdlTryPassword: internal error\n"); return pass_internal_error; } @@ -882,9 +930,9 @@ int CtdlTryPassword(char *password) * this is a security hazard, comment it out. */ - lgetuser(&CC->user, CC->curr_user); + CtdlGetUserLock(&CC->user, CC->curr_user); safestrncpy(CC->user.password, password, sizeof CC->user.password); - lputuser(&CC->user); + CtdlPutUserLock(&CC->user); /* * (sooper-seekrit hack ends here) @@ -977,7 +1025,7 @@ int purge_user(char pname[]) if (IsEmptyStr(pname)) return (ERROR + NO_SUCH_USER); - if (getuser(&usbuf, pname) != 0) { + if (CtdlGetUser(&usbuf, pname) != 0) { CtdlLogPrintf(CTDL_ERR, "Cannot purge user <%s> - not found\n", pname); return (ERROR + NO_SUCH_USER); } @@ -996,7 +1044,7 @@ int purge_user(char pname[]) if (user_is_logged_in == 1) { CtdlLogPrintf(CTDL_WARNING, "User <%s> is logged in; not deleting.\n", pname); usbuf.axlevel = 0; - putuser(&usbuf); + CtdlPutUser(&usbuf); return (1); } CtdlLogPrintf(CTDL_NOTICE, "Deleting user <%s>\n", pname); @@ -1035,7 +1083,7 @@ int purge_user(char pname[]) int internal_create_user (char *username, struct ctdluser *usbuf, uid_t uid) { - if (!getuser(usbuf, username)) { + if (!CtdlGetUser(usbuf, username)) { return (ERROR + ALREADY_EXISTS); } @@ -1059,7 +1107,7 @@ int internal_create_user (char *username, struct ctdluser *usbuf, uid_t uid) usbuf->usernum = get_new_user_number(); /* add user to the database */ - putuser(usbuf); + CtdlPutUser(usbuf); cdb_store(CDB_USERSBYNUMBER, &usbuf->usernum, sizeof(long), usbuf->fullname, strlen(usbuf->fullname)+1); return 0; @@ -1158,7 +1206,7 @@ int create_user(char *newusername, int become_user) do_login(); /* Check to make sure we're still who we think we are */ - if (getuser(&CC->user, CC->curr_user)) { + if (CtdlGetUser(&CC->user, CC->curr_user)) { return (ERROR + INTERNAL_ERROR); } } @@ -1244,9 +1292,9 @@ void cmd_newu(char *cmdbuf) */ void CtdlSetPassword(char *new_pw) { - lgetuser(&CC->user, CC->curr_user); + CtdlGetUserLock(&CC->user, CC->curr_user); safestrncpy(CC->user.password, new_pw, sizeof(CC->user.password)); - lputuser(&CC->user); + CtdlPutUserLock(&CC->user); CtdlLogPrintf(CTDL_INFO, "Password changed for user <%s>\n", CC->curr_user); PerformSessionHooks(EVT_SETPASS); } @@ -1321,9 +1369,9 @@ void cmd_creu(char *cmdbuf) if (a == 0) { if (!IsEmptyStr(password)) { - lgetuser(&tmp, username); + CtdlGetUserLock(&tmp, username); safestrncpy(tmp.password, password, sizeof(tmp.password)); - lputuser(&tmp); + CtdlPutUserLock(&tmp); } cprintf("%d User '%s' created %s.\n", CIT_OK, username, (!IsEmptyStr(password)) ? "and password set" : @@ -1352,7 +1400,7 @@ void cmd_getu(char *cmdbuf) if (CtdlAccessCheck(ac_logged_in)) return; - getuser(&CC->user, CC->curr_user); + CtdlGetUser(&CC->user, CC->curr_user); cprintf("%d %d|%d|%d|\n", CIT_OK, CC->user.USscreenwidth, @@ -1373,14 +1421,14 @@ void cmd_setu(char *new_parms) cprintf("%d Usage error.\n", ERROR + ILLEGAL_VALUE); return; } - lgetuser(&CC->user, CC->curr_user); + CtdlGetUserLock(&CC->user, CC->curr_user); CC->user.USscreenwidth = extract_int(new_parms, 0); CC->user.USscreenheight = extract_int(new_parms, 1); CC->user.flags = CC->user.flags & (~US_USER_SET); CC->user.flags = CC->user.flags | (extract_int(new_parms, 2) & US_USER_SET); - lputuser(&CC->user); + CtdlPutUserLock(&CC->user); cprintf("%d Ok\n", CIT_OK); } @@ -1403,7 +1451,7 @@ void cmd_slrp(char *new_ptr) newlr = atol(new_ptr); } - lgetuser(&CC->user, CC->curr_user); + CtdlGetUserLock(&CC->user, CC->curr_user); CtdlGetRelationship(&vbuf, &CC->user, &CC->room); memcpy(&original_vbuf, &vbuf, sizeof(struct visit)); @@ -1416,7 +1464,7 @@ void cmd_slrp(char *new_ptr) CtdlSetRelationship(&vbuf, &CC->user, &CC->room); } - lputuser(&CC->user); + CtdlPutUserLock(&CC->user); cprintf("%d %ld\n", CIT_OK, newlr); } @@ -1466,7 +1514,7 @@ int CtdlInvtKick(char *iuser, int op) { struct visit vbuf; char bbb[SIZ]; - if (getuser(&USscratch, iuser) != 0) { + if (CtdlGetUser(&USscratch, iuser) != 0) { return(1); } @@ -1547,14 +1595,14 @@ int CtdlForgetThisRoom(void) { return(1); } - lgetuser(&CC->user, CC->curr_user); + CtdlGetUserLock(&CC->user, CC->curr_user); CtdlGetRelationship(&vbuf, &CC->user, &CC->room); vbuf.v_flags = vbuf.v_flags | V_FORGET; vbuf.v_flags = vbuf.v_flags & ~V_ACCESS; CtdlSetRelationship(&vbuf, &CC->user, &CC->room); - lputuser(&CC->user); + CtdlPutUserLock(&CC->user); /* Return to the Lobby, so we don't end up in an undefined room */ CtdlUserGoto(config.c_baseroom, 0, 0, NULL, NULL); @@ -1647,7 +1695,7 @@ void cmd_vali(char *v_args) return; } - if (lgetuser(&userbuf, user) != 0) { + if (CtdlGetUserLock(&userbuf, user) != 0) { cprintf("%d '%s' not found.\n", ERROR + NO_SUCH_USER, user); return; } @@ -1655,7 +1703,7 @@ void cmd_vali(char *v_args) userbuf.axlevel = newax; userbuf.flags = (userbuf.flags & ~US_NEEDVALID); - lputuser(&userbuf); + CtdlPutUserLock(&userbuf); /* If the access level was set to zero, delete the user */ if (newax == 0) { @@ -1747,7 +1795,7 @@ void cmd_chek(char *argbuf) return; } - getuser(&CC->user, CC->curr_user); /* no lock is needed here */ + CtdlGetUser(&CC->user, CC->curr_user); /* no lock is needed here */ if ((REGISCALL != 0) && ((CC->user.flags & US_REGIS) == 0)) regis = 1; @@ -1771,7 +1819,7 @@ void cmd_qusr(char *who) { struct ctdluser usbuf; - if (getuser(&usbuf, who) == 0) { + if (CtdlGetUser(&usbuf, who) == 0) { cprintf("%d %s\n", CIT_OK, usbuf.fullname); } else { cprintf("%d No such user.\n", ERROR + NO_SUCH_USER); @@ -1792,7 +1840,7 @@ void cmd_agup(char *cmdbuf) } extract_token(requested_user, cmdbuf, 0, '|', sizeof requested_user); - if (getuser(&usbuf, requested_user) != 0) { + if (CtdlGetUser(&usbuf, requested_user) != 0) { cprintf("%d No such user.\n", ERROR + NO_SUCH_USER); return; } @@ -1827,7 +1875,7 @@ void cmd_asup(char *cmdbuf) return; extract_token(requested_user, cmdbuf, 0, '|', sizeof requested_user); - if (lgetuser(&usbuf, requested_user) != 0) { + if (CtdlGetUserLock(&usbuf, requested_user) != 0) { cprintf("%d No such user.\n", ERROR + NO_SUCH_USER); return; } @@ -1852,7 +1900,7 @@ void cmd_asup(char *cmdbuf) if (np > 8) { usbuf.USuserpurge = extract_int(cmdbuf, 8); } - lputuser(&usbuf); + CtdlPutUserLock(&usbuf); if (usbuf.axlevel == 0) { if (purge_user(requested_user) == 0) { deleted = 1; diff --git a/citadel/user_ops.h b/citadel/user_ops.h index 6bf604175..1a61e34dc 100644 --- a/citadel/user_ops.h +++ b/citadel/user_ops.h @@ -1,12 +1,17 @@ /* $Id$ */ int hash (char *str); -int getuser (struct ctdluser *, char *); -int lgetuser (struct ctdluser *, char *); -void putuser (struct ctdluser *); -void lputuser (struct ctdluser *); +/* getuser is deprecated, use CtdlGetUser instead */ +int getuser (struct ctdluser *, char *) __attribute__ ((deprecated)); +/* lgetuser is deprecated, use CtdlGetUserLock instead */ +int lgetuser (struct ctdluser *, char *) __attribute__ ((deprecated)); +/* putuser is deprecated, use CtdlPutUser instead */ +void putuser (struct ctdluser *) __attribute__ ((deprecated)); +/* lputuser is deprecated, use CtdlPutUserLock instead */ +void lputuser (struct ctdluser *) __attribute__ ((deprecated)); int is_aide (void); int is_room_aide (void); -int getuserbynumber (struct ctdluser *usbuf, long int number); +/* getuserbynumber is deprecated, use CtdlGetUserByNumber instead */ +int getuserbynumber (struct ctdluser *usbuf, long int number) __attribute__ ((deprecated)); void rebuild_usersbynumber(void); void cmd_user (char *cmdbuf); void session_startup (void); diff --git a/citadel/utils/aidepost.c b/citadel/utils/aidepost.c index 7b637f548..e3c5c386e 100644 --- a/citadel/utils/aidepost.c +++ b/citadel/utils/aidepost.c @@ -20,6 +20,8 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include "ctdl_module.h" + #include #include #include diff --git a/citadel/utils/getmail.c b/citadel/utils/getmail.c index 0138b01f4..af9780cb8 100644 --- a/citadel/utils/getmail.c +++ b/citadel/utils/getmail.c @@ -20,6 +20,8 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include "ctdl_module.h" + #include #include #include diff --git a/citadel/utils/sendcommand.c b/citadel/utils/sendcommand.c index 501287701..faeb469c1 100644 --- a/citadel/utils/sendcommand.c +++ b/citadel/utils/sendcommand.c @@ -5,6 +5,7 @@ * */ +#include "ctdl_module.h" #include #include diff --git a/citadel/utils/setup.c b/citadel/utils/setup.c index 38c8be06c..c87563c4f 100644 --- a/citadel/utils/setup.c +++ b/citadel/utils/setup.c @@ -5,6 +5,9 @@ * */ +#include "ctdl_module.h" + + #include #include #include -- 2.30.2