From 4784ca02b8038d20477d02e059e753588b3d28a7 Mon Sep 17 00:00:00 2001 From: Dave West Date: Sun, 6 Apr 2008 21:14:34 +0000 Subject: [PATCH] Give the user contained within masterCC a name. Its not a real user but it is stored in the DB and does contain info like how many messages the system has created. We call it Citadel. This make "citadel" an illegal user name. Now this user has a name we need to make sure the auto purger doesn't purge it and make sure no one can login by that name. --- citadel/modules/expire/serv_expire.c | 3 +++ citadel/server_main.c | 17 +++++++++++++++++ citadel/sysdep.c | 2 -- citadel/user_ops.c | 23 +++++++++++++++++------ 4 files changed, 37 insertions(+), 8 deletions(-) diff --git a/citadel/modules/expire/serv_expire.c b/citadel/modules/expire/serv_expire.c index 33d9508e4..ac5debf2c 100644 --- a/citadel/modules/expire/serv_expire.c +++ b/citadel/modules/expire/serv_expire.c @@ -445,6 +445,9 @@ void do_user_purge(struct ctdluser *us, void *data) { */ if (us->usernum < 0L) purge = 1; + /** Don't purge user 0. That user is there for the system */ + if (us->usernum == 0) purge = 0; + /* If the user has no full name entry then we can't purge them * since the actual purge can't find them. * This shouldn't happen but does somehow. diff --git a/citadel/server_main.c b/citadel/server_main.c index 4bf86ee85..37c77ddcd 100644 --- a/citadel/server_main.c +++ b/citadel/server_main.c @@ -71,6 +71,9 @@ const char *CitadelServiceUDS="citadel-UDS"; const char *CitadelServiceTCP="citadel-TCP"; +extern struct CitContext masterCC; + + void go_threading(void); /* @@ -244,6 +247,20 @@ int main(int argc, char **argv) CtdlLogPrintf(CTDL_INFO, "Acquiring control record\n"); get_control(); + +/** + * Initialise the user 0 to have a name. It would be nice to do it in InitializeMasterCC + * since it is contained within the MasterCC but we can't because the DB isn't available + * at that time so we do it seperate. + */ + /** Give user 0 a name and create them if necessary */ + if (getuser(&masterCC.user, "Citadel")) + { + getuserbynumber(&masterCC.user, 0); + strcpy (masterCC.user.fullname, "Citadel"); + putuser(&masterCC.user); + } + /* * Bind the server to a Unix-domain socket. */ diff --git a/citadel/sysdep.c b/citadel/sysdep.c index d634c5496..265f879e7 100644 --- a/citadel/sysdep.c +++ b/citadel/sysdep.c @@ -1051,8 +1051,6 @@ void InitializeMasterCC(void) { - - /* * Bind a thread to a context. (It's inline merely to speed things up.) */ diff --git a/citadel/user_ops.c b/citadel/user_ops.c index e7331e8d2..e376c9d32 100644 --- a/citadel/user_ops.c +++ b/citadel/user_ops.c @@ -187,12 +187,17 @@ int rename_user(char *oldname, char *newname) { } else { /* Sanity checks succeeded. Now rename the user. */ - - 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); - retcode = RENAMEUSER_OK; + if (usbuf.usernum == 0) + { + CtdlLogPrintf (CTDL_DEBUG, "Can not rename user \"Citadel\".\n"); + retcode = RENAMEUSER_NOT_FOUND; + } else { + 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); + retcode = RENAMEUSER_OK; + } } } @@ -421,6 +426,12 @@ int CtdlLoginExistingUser(char *authname, char *trythisname) } if (trythisname == NULL) return login_not_found; + + if (!strcasecmp(trythisname, "Citadel")) + { + CtdlLogPrintf(CTDL_DEBUG, "System user \"Citadel\" is not allowed to log in.\n"); + return login_not_found; + } /* If a "master user" is defined, handle its authentication if specified */ CC->is_master = 0; -- 2.30.2