4 * Server functions which perform operations on user objects.
17 #include <sys/types.h>
19 #ifdef HAVE_SYS_STAT_H
23 #if TIME_WITH_SYS_TIME
24 # include <sys/time.h>
28 # include <sys/time.h>
36 #include <libcitadel.h>
42 #include "sysdep_decls.h"
49 #include "citserver.h"
50 #include "citadel_dirs.h"
53 #include "citadel_ldap.h"
55 #include "ctdl_module.h"
57 /* These pipes are used to talk to the chkpwd daemon, which is forked during startup */
58 int chkpwd_write_pipe[2];
59 int chkpwd_read_pipe[2];
62 * makeuserkey() - convert a username into the format used as a database key
63 * (it's just the username converted into lower case)
65 INLINE void makeuserkey(char *key, char *username) {
68 len = strlen(username);
69 if (len >= USERNAME_SIZE)
71 CtdlLogPrintf (CTDL_EMERG, "Username to long: %s", username);
73 len = USERNAME_SIZE - 1;
74 username[USERNAME_SIZE - 1]='\0';
76 for (i=0; i<=len; ++i) {
77 key[i] = tolower(username[i]);
83 * getuser() - retrieve named user into supplied buffer.
84 * returns 0 on success
86 int getuser(struct ctdluser *usbuf, char name[])
88 return CtdlGetUser(usbuf, name);
93 * CtdlGetUser() - retrieve named user into supplied buffer.
94 * returns 0 on success
96 int CtdlGetUser(struct ctdluser *usbuf, char name[])
99 char usernamekey[USERNAME_SIZE];
100 struct cdbdata *cdbus;
103 memset(usbuf, 0, sizeof(struct ctdluser));
106 makeuserkey(usernamekey, name);
107 cdbus = cdb_fetch(CDB_USERS, usernamekey, strlen(usernamekey));
109 if (cdbus == NULL) { /* user not found */
113 memcpy(usbuf, cdbus->ptr,
114 ((cdbus->len > sizeof(struct ctdluser)) ?
115 sizeof(struct ctdluser) : cdbus->len));
124 * CtdlGetUserLock() - same as getuser() but locks the record
126 int CtdlGetUserLock(struct ctdluser *usbuf, char *name)
130 retcode = CtdlGetUser(usbuf, name);
132 begin_critical_section(S_USERS);
139 * lgetuser() - same as getuser() but locks the record
141 int lgetuser(struct ctdluser *usbuf, char *name)
143 return CtdlGetUserLock(usbuf, name);
148 * CtdlPutUser() - write user buffer into the correct place on disk
150 void CtdlPutUser(struct ctdluser *usbuf)
152 char usernamekey[USERNAME_SIZE];
154 makeuserkey(usernamekey, usbuf->fullname);
156 usbuf->version = REV_LEVEL;
158 usernamekey, strlen(usernamekey),
159 usbuf, sizeof(struct ctdluser));
165 * putuser() - write user buffer into the correct place on disk
167 void putuser(struct ctdluser *usbuf)
174 * CtdlPutUserLock() - same as putuser() but locks the record
176 void CtdlPutUserLock(struct ctdluser *usbuf)
179 end_critical_section(S_USERS);
184 * lputuser() - same as putuser() but locks the record
186 void lputuser(struct ctdluser *usbuf)
188 CtdlPutUserLock(usbuf);
193 * rename_user() - this is tricky because the user's display name is the database key
195 * Returns 0 on success or nonzero if there was an error...
198 int rename_user(char *oldname, char *newname) {
199 struct CitContext *cptr;
200 int retcode = RENAMEUSER_OK;
201 struct ctdluser usbuf;
203 char oldnamekey[USERNAME_SIZE];
204 char newnamekey[USERNAME_SIZE];
206 /* We cannot rename a user who is currently logged in */
207 for (cptr = ContextList; cptr != NULL; cptr = cptr->next) {
208 if (!strcasecmp(cptr->user.fullname, oldname)) {
209 return(RENAMEUSER_LOGGED_IN);
213 /* Create the database keys... */
214 makeuserkey(oldnamekey, oldname);
215 makeuserkey(newnamekey, newname);
217 /* Lock up and get going */
218 begin_critical_section(S_USERS);
220 if (CtdlGetUser(&usbuf, newname) == 0) {
221 retcode = RENAMEUSER_ALREADY_EXISTS;
225 if (CtdlGetUser(&usbuf, oldname) != 0) {
226 retcode = RENAMEUSER_NOT_FOUND;
229 else { /* Sanity checks succeeded. Now rename the user. */
230 if (usbuf.usernum == 0)
232 CtdlLogPrintf (CTDL_DEBUG, "Can not rename user \"Citadel\".\n");
233 retcode = RENAMEUSER_NOT_FOUND;
235 CtdlLogPrintf(CTDL_DEBUG, "Renaming <%s> to <%s>\n", oldname, newname);
236 cdb_delete(CDB_USERS, oldnamekey, strlen(oldnamekey));
237 safestrncpy(usbuf.fullname, newname, sizeof usbuf.fullname);
239 cdb_store(CDB_USERSBYNUMBER, &usbuf.usernum, sizeof(long),
240 usbuf.fullname, strlen(usbuf.fullname)+1 );
242 retcode = RENAMEUSER_OK;
248 end_critical_section(S_USERS);
255 * Index-generating function used by Ctdl[Get|Set]Relationship
257 int GenerateRelationshipIndex(char *IndexBuf,
269 TheIndex.iRoomID = RoomID;
270 TheIndex.iRoomGen = RoomGen;
271 TheIndex.iUserID = UserID;
273 memcpy(IndexBuf, &TheIndex, sizeof(TheIndex));
274 return (sizeof(TheIndex));
280 * Back end for CtdlSetRelationship()
282 void put_visit(struct visit *newvisit)
287 memset (IndexBuf, 0, sizeof (IndexBuf));
288 /* Generate an index */
289 IndexLen = GenerateRelationshipIndex(IndexBuf,
292 newvisit->v_usernum);
294 /* Store the record */
295 cdb_store(CDB_VISIT, IndexBuf, IndexLen,
296 newvisit, sizeof(struct visit)
304 * Define a relationship between a user and a room
306 void CtdlSetRelationship(struct visit *newvisit,
307 struct ctdluser *rel_user,
308 struct ctdlroom *rel_room)
312 /* We don't use these in Citadel because they're implicit by the
313 * index, but they must be present if the database is exported.
315 newvisit->v_roomnum = rel_room->QRnumber;
316 newvisit->v_roomgen = rel_room->QRgen;
317 newvisit->v_usernum = rel_user->usernum;
323 * Locate a relationship between a user and a room
325 void CtdlGetRelationship(struct visit *vbuf,
326 struct ctdluser *rel_user,
327 struct ctdlroom *rel_room)
332 struct cdbdata *cdbvisit;
334 /* Generate an index */
335 IndexLen = GenerateRelationshipIndex(IndexBuf,
340 /* Clear out the buffer */
341 memset(vbuf, 0, sizeof(struct visit));
343 cdbvisit = cdb_fetch(CDB_VISIT, IndexBuf, IndexLen);
344 if (cdbvisit != NULL) {
345 memcpy(vbuf, cdbvisit->ptr,
346 ((cdbvisit->len > sizeof(struct visit)) ?
347 sizeof(struct visit) : cdbvisit->len));
351 /* If this is the first time the user has seen this room,
352 * set the view to be the default for the room.
354 vbuf->v_view = rel_room->QRdefaultview;
357 /* Set v_seen if necessary */
358 if (vbuf->v_seen[0] == 0) {
359 snprintf(vbuf->v_seen, sizeof vbuf->v_seen, "*:%ld", vbuf->v_lastseen);
364 void MailboxName(char *buf, size_t n, const struct ctdluser *who, const char *prefix)
366 snprintf(buf, n, "%010ld.%s", who->usernum, prefix);
371 * Is the user currently logged in an Aide?
375 if (CC->user.axlevel >= 6)
383 * Is the user currently logged in an Aide *or* the room aide for this room?
385 int is_room_aide(void)
388 if (!CC->logged_in) {
392 if ((CC->user.axlevel >= 6)
393 || (CC->room.QRroomaide == CC->user.usernum)) {
401 * CtdlGetUserByNumber() - get user by number
402 * returns 0 if user was found
404 * Note: fetching a user this way requires one additional database operation.
406 int CtdlGetUserByNumber(struct ctdluser *usbuf, long number)
408 struct cdbdata *cdbun;
411 cdbun = cdb_fetch(CDB_USERSBYNUMBER, &number, sizeof(long));
413 CtdlLogPrintf(CTDL_INFO, "User %ld not found\n", number);
417 CtdlLogPrintf(CTDL_INFO, "User %ld maps to %s\n", number, cdbun->ptr);
418 r = CtdlGetUser(usbuf, cdbun->ptr);
424 * getuserbynumber() - get user by number
425 * returns 0 if user was found
427 * Note: fetching a user this way requires one additional database operation.
429 int getuserbynumber(struct ctdluser *usbuf, long number)
431 return CtdlGetUserByNumber(usbuf, number);
437 * Helper function for rebuild_usersbynumber()
439 void rebuild_ubn_for_user(struct ctdluser *usbuf, void *data) {
442 struct ubnlist *next;
443 char username[USERNAME_SIZE];
447 static struct ubnlist *u = NULL;
448 struct ubnlist *ptr = NULL;
450 /* Lazy programming here. Call this function as a ForEachUser backend
451 * in order to queue up the room names, or call it with a null user
452 * to make it do the processing.
455 ptr = (struct ubnlist *) malloc(sizeof (struct ubnlist));
456 if (ptr == NULL) return;
458 ptr->usernum = usbuf->usernum;
459 safestrncpy(ptr->username, usbuf->fullname, sizeof ptr->username);
466 CtdlLogPrintf(CTDL_DEBUG, "Rebuilding usersbynumber index %10ld : %s\n",
467 u->usernum, u->username);
468 cdb_store(CDB_USERSBYNUMBER, &u->usernum, sizeof(long), u->username, strlen(u->username)+1);
479 * Rebuild the users-by-number index
481 void rebuild_usersbynumber(void) {
482 cdb_trunc(CDB_USERSBYNUMBER); /* delete the old indices */
483 ForEachUser(rebuild_ubn_for_user, NULL); /* enumerate the users */
484 rebuild_ubn_for_user(NULL, NULL); /* and index them */
490 * getuserbyuid() - get user by system uid (for PAM mode authentication)
491 * returns 0 if user was found
493 * WARNING: don't use this function unless you absolutely have to. It does
494 * a sequential search and therefore is computationally expensive.
496 int getuserbyuid(struct ctdluser *usbuf, uid_t number)
498 struct cdbdata *cdbus;
500 cdb_rewind(CDB_USERS);
502 while (cdbus = cdb_next_item(CDB_USERS), cdbus != NULL) {
503 memset(usbuf, 0, sizeof(struct ctdluser));
504 memcpy(usbuf, cdbus->ptr,
505 ((cdbus->len > sizeof(struct ctdluser)) ?
506 sizeof(struct ctdluser) : cdbus->len));
508 if (usbuf->uid == number) {
509 cdb_close_cursor(CDB_USERS);
517 * Back end for cmd_user() and its ilk
519 * NOTE: "authname" should only be used if we are attempting to use the "master user" feature
521 int CtdlLoginExistingUser(char *authname, char *trythisname)
526 CtdlLogPrintf(9, "CtdlLoginExistingUser(%s, %s)\n", authname, trythisname);
528 if ((CC->logged_in)) {
529 return login_already_logged_in;
532 if (trythisname == NULL) return login_not_found;
534 if (!strncasecmp(trythisname, "SYS_", 4))
536 CtdlLogPrintf(CTDL_DEBUG, "System user \"%s\" is not allowed to log in.\n", trythisname);
537 return login_not_found;
540 /* If a "master user" is defined, handle its authentication if specified */
542 if (strlen(config.c_master_user) > 0) if (strlen(config.c_master_pass) > 0) if (authname) {
543 if (!strcasecmp(authname, config.c_master_user)) {
548 /* Continue attempting user validation... */
549 safestrncpy(username, trythisname, USERNAME_SIZE);
552 if (IsEmptyStr(username)) {
553 return login_not_found;
556 if (config.c_auth_mode == AUTHMODE_HOST) {
561 struct passwd *tempPwdPtr;
564 CtdlLogPrintf(CTDL_DEBUG, "asking host about <%s>\n", username);
565 #ifdef HAVE_GETPWNAM_R
566 #ifdef SOLARIS_GETPWUID
567 CtdlLogPrintf(CTDL_DEBUG, "Calling getpwnam_r()\n");
568 tempPwdPtr = getpwnam_r(username, &pd, pwdbuffer, sizeof pwdbuffer);
569 #else // SOLARIS_GETPWUID
570 CtdlLogPrintf(CTDL_DEBUG, "Calling getpwnam_r()\n");
571 getpwnam_r(username, &pd, pwdbuffer, sizeof pwdbuffer, &tempPwdPtr);
572 #endif // SOLARIS_GETPWUID
573 #else // HAVE_GETPWNAM_R
574 CtdlLogPrintf(CTDL_DEBUG, "SHOULD NEVER GET HERE!!!\n");
576 #endif // HAVE_GETPWNAM_R
577 if (tempPwdPtr == NULL) {
578 CtdlLogPrintf(CTDL_DEBUG, "no such user <%s>\n", username);
579 return login_not_found;
582 /* Locate the associated Citadel account.
583 * If not found, make one attempt to create it.
585 found_user = getuserbyuid(&CC->user, pd.pw_uid);
586 CtdlLogPrintf(CTDL_DEBUG, "found it: uid=%ld, gecos=%s here: %d\n",
587 (long)pd.pw_uid, pd.pw_gecos, found_user);
588 if (found_user != 0) {
589 create_user(username, 0);
590 found_user = getuserbyuid(&CC->user, pd.pw_uid);
596 else if ((config.c_auth_mode == AUTHMODE_LDAP) || (config.c_auth_mode == AUTHMODE_LDAP_AD)) {
604 found_user = CtdlTryUserLDAP(username, ldap_dn, sizeof ldap_dn, ldap_cn, sizeof ldap_cn, &ldap_uid);
605 if (found_user != 0) {
606 return login_not_found;
609 found_user = getuserbyuid(&CC->user, ldap_uid);
610 if (found_user != 0) {
611 create_user(trythisname, 0);
612 found_user = getuserbyuid(&CC->user, ldap_uid);
615 if (found_user == 0) {
616 if (CC->ldap_dn != NULL) free(CC->ldap_dn);
617 CC->ldap_dn = strdup(ldap_dn);
624 /* native auth mode */
626 struct recptypes *valid = NULL;
628 /* First, try to log in as if the supplied name is a display name */
629 found_user = CtdlGetUser(&CC->user, username);
631 /* If that didn't work, try to log in as if the supplied name
632 * is an e-mail address
634 if (found_user != 0) {
635 valid = validate_recipients(username, NULL, 0);
637 if (valid->num_local == 1) {
638 found_user = CtdlGetUser(&CC->user, valid->recp_local);
640 free_recipients(valid);
645 /* Did we find something? */
646 if (found_user == 0) {
647 if (((CC->nologin)) && (CC->user.axlevel < 6)) {
648 return login_too_many_users;
650 safestrncpy(CC->curr_user, CC->user.fullname,
651 sizeof CC->curr_user);
655 return login_not_found;
663 void cmd_user(char *cmdbuf)
668 CtdlLogPrintf(CTDL_DEBUG, "cmd_user(%s)\n", cmdbuf);
669 extract_token(username, cmdbuf, 0, '|', sizeof username);
670 CtdlLogPrintf(CTDL_DEBUG, "username: %s\n", username);
672 CtdlLogPrintf(CTDL_DEBUG, "username: %s\n", username);
674 a = CtdlLoginExistingUser(NULL, username);
676 case login_already_logged_in:
677 cprintf("%d Already logged in.\n", ERROR + ALREADY_LOGGED_IN);
679 case login_too_many_users:
681 "Too many users are already online "
683 ERROR + MAX_SESSIONS_EXCEEDED,
684 config.c_nodename, config.c_maxsessions);
687 cprintf("%d Password required for %s\n",
688 MORE_DATA, CC->curr_user);
690 case login_not_found:
691 cprintf("%d %s not found.\n", ERROR + NO_SUCH_USER, username);
694 cprintf("%d Internal error\n", ERROR + INTERNAL_ERROR);
701 * session startup code which is common to both cmd_pass() and cmd_newu()
706 CtdlLogPrintf(CTDL_NOTICE, "<%s> logged in\n", CC->curr_user);
708 CtdlGetUserLock(&CC->user, CC->curr_user);
709 ++(CC->user.timescalled);
710 CC->previous_login = CC->user.lastcall;
711 time(&CC->user.lastcall);
713 /* If this user's name is the name of the system administrator
714 * (as specified in setup), automatically assign access level 6.
716 if (!strcasecmp(CC->user.fullname, config.c_sysadm)) {
717 CC->user.axlevel = 6;
720 /* If we're authenticating off the host system, automatically give
721 * root the highest level of access.
723 if (config.c_auth_mode == AUTHMODE_HOST) {
724 if (CC->user.uid == 0) {
725 CC->user.axlevel = 6;
729 CtdlPutUserLock(&CC->user);
732 * Populate CC->cs_inet_email with a default address. This will be
733 * overwritten with the user's directory address, if one exists, when
734 * the vCard module's login hook runs.
736 snprintf(CC->cs_inet_email, sizeof CC->cs_inet_email, "%s@%s",
737 CC->user.fullname, config.c_fqdn);
738 convert_spaces_to_underscores(CC->cs_inet_email);
740 /* Create any personal rooms required by the system.
741 * (Technically, MAILROOM should be there already, but just in case...)
743 CtdlCreateRoom(MAILROOM, 4, "", 0, 1, 0, VIEW_MAILBOX);
744 CtdlCreateRoom(SENTITEMS, 4, "", 0, 1, 0, VIEW_MAILBOX);
745 CtdlCreateRoom(USERTRASHROOM, 4, "", 0, 1, 0, VIEW_MAILBOX);
746 /* CtdlCreateRoom(USERDRAFTROOM, 4, "", 0, 1, 0, VIEW_MAILBOX); temporarily disabled for 7.60 */
748 /* Run any startup routines registered by loadable modules */
749 PerformSessionHooks(EVT_LOGIN);
751 /* Enter the lobby */
752 CtdlUserGoto(config.c_baseroom, 0, 0, NULL, NULL);
756 void logged_in_response(void)
758 cprintf("%d %s|%d|%ld|%ld|%u|%ld|%ld\n",
759 CIT_OK, CC->user.fullname, CC->user.axlevel,
760 CC->user.timescalled, CC->user.posted,
761 CC->user.flags, CC->user.usernum,
768 * misc things to be taken care of when a user is logged out
772 struct CitContext *CCC = CC; /* CachedCitContext - performance boost */
774 * If there is a download in progress, abort it.
776 if (CCC->download_fp != NULL) {
777 fclose(CCC->download_fp);
778 CCC->download_fp = NULL;
782 * If there is an upload in progress, abort it.
784 if (CCC->upload_fp != NULL) {
789 * If we were talking to a network node, we're not anymore...
791 if (!IsEmptyStr(CCC->net_node)) {
792 network_talking_to(CCC->net_node, NTT_REMOVE);
795 /* Run any hooks registered by modules... */
796 PerformSessionHooks(EVT_LOGOUT);
799 * Clear out some session data. Most likely, the CitContext for this
800 * session is about to get nuked when the session disconnects, but
801 * since it's possible to log in again without reconnecting, we cannot
802 * make that assumption.
804 strcpy(CCC->fake_username, "");
805 strcpy(CCC->fake_hostname, "");
806 strcpy(CCC->fake_roomname, "");
809 /* Check to see if the user was deleted whilst logged in and purge them if necessary */
810 if ((CCC->user.axlevel == 0) && (CCC->user.usernum))
811 purge_user(CCC->user.fullname);
813 /* Free any output buffers */
818 * Validate a password on the host unix system by talking to the chkpwd daemon
820 static int validpw(uid_t uid, const char *pass)
825 if (IsEmptyStr(pass)) {
826 CtdlLogPrintf(CTDL_DEBUG, "refusing to check empty password for uid=%d using chkpwd...\n", uid);
830 CtdlLogPrintf(CTDL_DEBUG, "Validating password for uid=%d using chkpwd...\n", uid);
832 begin_critical_section(S_CHKPWD);
833 rv = write(chkpwd_write_pipe[1], &uid, sizeof(uid_t));
834 rv = write(chkpwd_write_pipe[1], pass, 256);
835 rv = read(chkpwd_read_pipe[0], buf, 4);
836 end_critical_section(S_CHKPWD);
838 if (!strncmp(buf, "PASS", 4)) {
839 CtdlLogPrintf(CTDL_DEBUG, "...pass\n");
843 CtdlLogPrintf(CTDL_DEBUG, "...fail\n");
848 * Start up the chkpwd daemon so validpw() has something to talk to
850 void start_chkpwd_daemon(void) {
852 struct stat filestats;
855 CtdlLogPrintf(CTDL_DEBUG, "Starting chkpwd daemon for host authentication mode\n");
857 if ((stat(file_chkpwd, &filestats)==-1) ||
858 (filestats.st_size==0)){
859 printf("didn't find chkpwd daemon in %s: %s\n", file_chkpwd, strerror(errno));
862 if (pipe(chkpwd_write_pipe) != 0) {
863 CtdlLogPrintf(CTDL_EMERG, "Unable to create pipe for chkpwd daemon: %s\n", strerror(errno));
866 if (pipe(chkpwd_read_pipe) != 0) {
867 CtdlLogPrintf(CTDL_EMERG, "Unable to create pipe for chkpwd daemon: %s\n", strerror(errno));
872 if (chkpwd_pid < 0) {
873 CtdlLogPrintf(CTDL_EMERG, "Unable to fork chkpwd daemon: %s\n", strerror(errno));
876 if (chkpwd_pid == 0) {
877 CtdlLogPrintf(CTDL_DEBUG, "Now calling dup2() write\n");
878 dup2(chkpwd_write_pipe[0], 0);
879 CtdlLogPrintf(CTDL_DEBUG, "Now calling dup2() write\n");
880 dup2(chkpwd_read_pipe[1], 1);
881 CtdlLogPrintf(CTDL_DEBUG, "Now closing stuff\n");
882 for (i=2; i<256; ++i) close(i);
883 CtdlLogPrintf(CTDL_DEBUG, "Now calling execl(%s)\n", file_chkpwd);
884 execl(file_chkpwd, file_chkpwd, NULL);
885 CtdlLogPrintf(CTDL_EMERG, "Unable to exec chkpwd daemon: %s\n", strerror(errno));
892 int CtdlTryPassword(char *password)
896 if ((CC->logged_in)) {
897 CtdlLogPrintf(CTDL_WARNING, "CtdlTryPassword: already logged in\n");
898 return pass_already_logged_in;
900 if (!strcmp(CC->curr_user, NLI)) {
901 CtdlLogPrintf(CTDL_WARNING, "CtdlTryPassword: no user selected\n");
904 if (CtdlGetUser(&CC->user, CC->curr_user)) {
905 CtdlLogPrintf(CTDL_ERR, "CtdlTryPassword: internal error\n");
906 return pass_internal_error;
908 if (password == NULL) {
909 CtdlLogPrintf(CTDL_INFO, "CtdlTryPassword: NULL password string supplied\n");
910 return pass_wrong_password;
915 code = strcmp(password, config.c_master_pass);
918 else if (config.c_auth_mode == AUTHMODE_HOST) {
922 if (validpw(CC->user.uid, password)) {
926 * sooper-seekrit hack: populate the password field in the
927 * citadel database with the password that the user typed,
928 * if it's correct. This allows most sites to convert from
929 * host auth to native auth if they want to. If you think
930 * this is a security hazard, comment it out.
933 CtdlGetUserLock(&CC->user, CC->curr_user);
934 safestrncpy(CC->user.password, password, sizeof CC->user.password);
935 CtdlPutUserLock(&CC->user);
938 * (sooper-seekrit hack ends here)
948 else if ((config.c_auth_mode == AUTHMODE_LDAP) || (config.c_auth_mode == AUTHMODE_LDAP_AD)) {
952 if ((CC->ldap_dn) && (!CtdlTryPasswordLDAP(CC->ldap_dn, password))) {
963 /* native auth mode */
966 strproc(CC->user.password);
967 code = strcasecmp(CC->user.password, password);
969 strproc(CC->user.password);
970 code = strcasecmp(CC->user.password, password);
977 CtdlLogPrintf(CTDL_WARNING, "Bad password specified for <%s>\n", CC->curr_user);
978 return pass_wrong_password;
983 void cmd_pass(char *buf)
988 memset(password, 0, sizeof(password));
989 extract_token(password, buf, 0, '|', sizeof password);
990 a = CtdlTryPassword(password);
993 case pass_already_logged_in:
994 cprintf("%d Already logged in.\n", ERROR + ALREADY_LOGGED_IN);
997 cprintf("%d You must send a name with USER first.\n",
998 ERROR + USERNAME_REQUIRED);
1000 case pass_wrong_password:
1001 cprintf("%d Wrong password.\n", ERROR + PASSWORD_REQUIRED);
1004 logged_in_response();
1012 * Delete a user record *and* all of its related resources.
1014 int purge_user(char pname[])
1017 struct ctdluser usbuf;
1018 char usernamekey[USERNAME_SIZE];
1019 struct CitContext *ccptr;
1020 int user_is_logged_in = 0;
1022 makeuserkey(usernamekey, pname);
1024 /* If the name is empty we can't find them in the DB any way so just return */
1025 if (IsEmptyStr(pname))
1026 return (ERROR + NO_SUCH_USER);
1028 if (CtdlGetUser(&usbuf, pname) != 0) {
1029 CtdlLogPrintf(CTDL_ERR, "Cannot purge user <%s> - not found\n", pname);
1030 return (ERROR + NO_SUCH_USER);
1032 /* Don't delete a user who is currently logged in. Instead, just
1033 * set the access level to 0, and let the account get swept up
1034 * during the next purge.
1036 user_is_logged_in = 0;
1037 begin_critical_section(S_SESSION_TABLE);
1038 for (ccptr = ContextList; ccptr != NULL; ccptr = ccptr->next) {
1039 if (ccptr->user.usernum == usbuf.usernum) {
1040 user_is_logged_in = 1;
1043 end_critical_section(S_SESSION_TABLE);
1044 if (user_is_logged_in == 1) {
1045 CtdlLogPrintf(CTDL_WARNING, "User <%s> is logged in; not deleting.\n", pname);
1047 CtdlPutUser(&usbuf);
1050 CtdlLogPrintf(CTDL_NOTICE, "Deleting user <%s>\n", pname);
1052 /* Perform any purge functions registered by server extensions */
1053 PerformUserHooks(&usbuf, EVT_PURGEUSER);
1055 /* delete any existing user/room relationships */
1056 cdb_delete(CDB_VISIT, &usbuf.usernum, sizeof(long));
1058 /* delete the users-by-number index record */
1059 cdb_delete(CDB_USERSBYNUMBER, &usbuf.usernum, sizeof(long));
1061 /* delete the userlog entry */
1062 cdb_delete(CDB_USERS, usernamekey, strlen(usernamekey));
1064 /* remove the user's bio file */
1072 /* remove the user's picture */
1084 int internal_create_user (char *username, struct ctdluser *usbuf, uid_t uid)
1086 if (!CtdlGetUser(usbuf, username)) {
1087 return (ERROR + ALREADY_EXISTS);
1090 /* Go ahead and initialize a new user record */
1091 memset(usbuf, 0, sizeof(struct ctdluser));
1092 safestrncpy(usbuf->fullname, username, sizeof usbuf->fullname);
1093 strcpy(usbuf->password, "");
1096 /* These are the default flags on new accounts */
1097 usbuf->flags = US_LASTOLD | US_DISAPPEAR | US_PAGINATOR | US_FLOORS;
1099 usbuf->timescalled = 0;
1101 usbuf->axlevel = config.c_initax;
1102 usbuf->USscreenwidth = 80;
1103 usbuf->USscreenheight = 24;
1104 usbuf->lastcall = time(NULL);
1106 /* fetch a new user number */
1107 usbuf->usernum = get_new_user_number();
1109 /* add user to the database */
1111 cdb_store(CDB_USERSBYNUMBER, &usbuf->usernum, sizeof(long), usbuf->fullname, strlen(usbuf->fullname)+1);
1119 * create_user() - back end processing to create a new user
1121 * Set 'newusername' to the desired account name.
1122 * Set 'become_user' to nonzero if this is self-service account creation and we want
1123 * to actually log in as the user we just created, otherwise set it to 0.
1125 int create_user(char *newusername, int become_user)
1127 struct ctdluser usbuf;
1128 struct ctdlroom qrbuf;
1130 char mailboxname[ROOMNAMELEN];
1136 safestrncpy(username, newusername, sizeof username);
1140 if (config.c_auth_mode == AUTHMODE_HOST) {
1142 /* host auth mode */
1145 struct passwd *tempPwdPtr;
1146 char pwdbuffer[256];
1148 #ifdef HAVE_GETPWNAM_R
1149 #ifdef SOLARIS_GETPWUID
1150 tempPwdPtr = getpwnam_r(username, &pd, pwdbuffer, sizeof(pwdbuffer));
1151 #else // SOLARIS_GETPWUID
1152 getpwnam_r(username, &pd, pwdbuffer, sizeof pwdbuffer, &tempPwdPtr);
1153 #endif // SOLARIS_GETPWUID
1154 #else // HAVE_GETPWNAM_R
1156 #endif // HAVE_GETPWNAM_R
1157 if (tempPwdPtr != NULL) {
1158 extract_token(username, pd.pw_gecos, 0, ',', sizeof username);
1160 if (IsEmptyStr (username))
1162 safestrncpy(username, pd.pw_name, sizeof username);
1166 return (ERROR + NO_SUCH_USER);
1171 if ((config.c_auth_mode == AUTHMODE_LDAP) || (config.c_auth_mode == AUTHMODE_LDAP_AD)) {
1172 if (CtdlTryUserLDAP(username, NULL, 0, username, sizeof username, &uid) != 0) {
1173 return(ERROR + NO_SUCH_USER);
1176 #endif /* HAVE_LDAP */
1178 if ((retval = internal_create_user(username, &usbuf, uid)) != 0)
1182 * Give the user a private mailbox and a configuration room.
1183 * Make the latter an invisible system room.
1185 MailboxName(mailboxname, sizeof mailboxname, &usbuf, MAILROOM);
1186 CtdlCreateRoom(mailboxname, 5, "", 0, 1, 1, VIEW_MAILBOX);
1188 MailboxName(mailboxname, sizeof mailboxname, &usbuf, USERCONFIGROOM);
1189 CtdlCreateRoom(mailboxname, 5, "", 0, 1, 1, VIEW_BBS);
1190 if (CtdlGetRoomLock(&qrbuf, mailboxname) == 0) {
1191 qrbuf.QRflags2 |= QR2_SYSTEM;
1192 CtdlPutRoomLock(&qrbuf);
1195 /* Perform any create functions registered by server extensions */
1196 PerformUserHooks(&usbuf, EVT_NEWUSER);
1198 /* Everything below this line can be bypassed if administratively
1199 * creating a user, instead of doing self-service account creation
1203 /* Now become the user we just created */
1204 memcpy(&CC->user, &usbuf, sizeof(struct ctdluser));
1205 safestrncpy(CC->curr_user, username, sizeof CC->curr_user);
1208 /* Check to make sure we're still who we think we are */
1209 if (CtdlGetUser(&CC->user, CC->curr_user)) {
1210 return (ERROR + INTERNAL_ERROR);
1215 "New user account <%s> has been created, from host %s [%s].\n",
1220 CtdlAideMessage(buf, "User Creation Notice");
1221 CtdlLogPrintf(CTDL_NOTICE, "New user <%s> created\n", username);
1228 * cmd_newu() - create a new user account and log in as that user
1230 void cmd_newu(char *cmdbuf)
1235 if (config.c_auth_mode != AUTHMODE_NATIVE) {
1236 cprintf("%d This system does not use native mode authentication.\n",
1241 if (config.c_disable_newu) {
1242 cprintf("%d Self-service user account creation "
1243 "is disabled on this system.\n", ERROR + NOT_HERE);
1247 if (CC->logged_in) {
1248 cprintf("%d Already logged in.\n", ERROR + ALREADY_LOGGED_IN);
1252 cprintf("%d %s: Too many users are already online (maximum is %d)\n",
1253 ERROR + MAX_SESSIONS_EXCEEDED,
1254 config.c_nodename, config.c_maxsessions);
1256 extract_token(username, cmdbuf, 0, '|', sizeof username);
1260 if (IsEmptyStr(username)) {
1261 cprintf("%d You must supply a user name.\n", ERROR + USERNAME_REQUIRED);
1265 if ((!strcasecmp(username, "bbs")) ||
1266 (!strcasecmp(username, "new")) ||
1267 (!strcasecmp(username, "."))) {
1268 cprintf("%d '%s' is an invalid login name.\n", ERROR + ILLEGAL_VALUE, username);
1272 a = create_user(username, 1);
1275 logged_in_response();
1276 } else if (a == ERROR + ALREADY_EXISTS) {
1277 cprintf("%d '%s' already exists.\n",
1278 ERROR + ALREADY_EXISTS, username);
1280 } else if (a == ERROR + INTERNAL_ERROR) {
1281 cprintf("%d Internal error - user record disappeared?\n",
1282 ERROR + INTERNAL_ERROR);
1285 cprintf("%d unknown error\n", ERROR + INTERNAL_ERROR);
1291 * set password - back end api code
1293 void CtdlSetPassword(char *new_pw)
1295 CtdlGetUserLock(&CC->user, CC->curr_user);
1296 safestrncpy(CC->user.password, new_pw, sizeof(CC->user.password));
1297 CtdlPutUserLock(&CC->user);
1298 CtdlLogPrintf(CTDL_INFO, "Password changed for user <%s>\n", CC->curr_user);
1299 PerformSessionHooks(EVT_SETPASS);
1304 * set password - citadel protocol implementation
1306 void cmd_setp(char *new_pw)
1308 int generate_random_password = 0;
1310 if (CtdlAccessCheck(ac_logged_in)) {
1313 if ( (CC->user.uid != CTDLUID) && (CC->user.uid != (-1)) ) {
1314 cprintf("%d Not allowed. Use the 'passwd' command.\n", ERROR + NOT_HERE);
1317 if (CC->is_master) {
1318 cprintf("%d The master prefix password cannot be changed with this command.\n",
1323 if (!strcasecmp(new_pw, "GENERATE_RANDOM_PASSWORD")) {
1324 char random_password[17];
1325 generate_random_password = 1;
1326 snprintf(random_password, sizeof random_password, "%08lx%08lx", random(), random());
1327 CtdlSetPassword(random_password);
1328 cprintf("%d %s\n", CIT_OK, random_password);
1332 if (IsEmptyStr(new_pw)) {
1333 cprintf("%d Password unchanged.\n", CIT_OK);
1336 CtdlSetPassword(new_pw);
1337 cprintf("%d Password changed.\n", CIT_OK);
1343 * cmd_creu() - administratively create a new user account (do not log in to it)
1345 void cmd_creu(char *cmdbuf)
1350 struct ctdluser tmp;
1352 if (CtdlAccessCheck(ac_aide)) {
1356 extract_token(username, cmdbuf, 0, '|', sizeof username);
1357 extract_token(password, cmdbuf, 1, '|', sizeof password);
1363 if (IsEmptyStr(username)) {
1364 cprintf("%d You must supply a user name.\n", ERROR + USERNAME_REQUIRED);
1368 a = create_user(username, 0);
1371 if (!IsEmptyStr(password)) {
1372 CtdlGetUserLock(&tmp, username);
1373 safestrncpy(tmp.password, password, sizeof(tmp.password));
1374 CtdlPutUserLock(&tmp);
1376 cprintf("%d User '%s' created %s.\n", CIT_OK, username,
1377 (!IsEmptyStr(password)) ? "and password set" :
1378 "with no password");
1380 } else if (a == ERROR + ALREADY_EXISTS) {
1381 cprintf("%d '%s' already exists.\n", ERROR + ALREADY_EXISTS, username);
1383 } else if ( (config.c_auth_mode != AUTHMODE_NATIVE) && (a == ERROR + NO_SUCH_USER) ) {
1384 cprintf("%d User accounts are not created within Citadel in host authentication mode.\n",
1385 ERROR + NO_SUCH_USER);
1388 cprintf("%d An error occurred creating the user account.\n", ERROR + INTERNAL_ERROR);
1395 * get user parameters
1397 void cmd_getu(char *cmdbuf)
1400 if (CtdlAccessCheck(ac_logged_in))
1403 CtdlGetUser(&CC->user, CC->curr_user);
1404 cprintf("%d %d|%d|%d|\n",
1406 CC->user.USscreenwidth,
1407 CC->user.USscreenheight,
1408 (CC->user.flags & US_USER_SET)
1413 * set user parameters
1415 void cmd_setu(char *new_parms)
1417 if (CtdlAccessCheck(ac_logged_in))
1420 if (num_parms(new_parms) < 3) {
1421 cprintf("%d Usage error.\n", ERROR + ILLEGAL_VALUE);
1424 CtdlGetUserLock(&CC->user, CC->curr_user);
1425 CC->user.USscreenwidth = extract_int(new_parms, 0);
1426 CC->user.USscreenheight = extract_int(new_parms, 1);
1427 CC->user.flags = CC->user.flags & (~US_USER_SET);
1428 CC->user.flags = CC->user.flags |
1429 (extract_int(new_parms, 2) & US_USER_SET);
1431 CtdlPutUserLock(&CC->user);
1432 cprintf("%d Ok\n", CIT_OK);
1436 * set last read pointer
1438 void cmd_slrp(char *new_ptr)
1442 struct visit original_vbuf;
1444 if (CtdlAccessCheck(ac_logged_in)) {
1448 if (!strncasecmp(new_ptr, "highest", 7)) {
1449 newlr = CC->room.QRhighest;
1451 newlr = atol(new_ptr);
1454 CtdlGetUserLock(&CC->user, CC->curr_user);
1456 CtdlGetRelationship(&vbuf, &CC->user, &CC->room);
1457 memcpy(&original_vbuf, &vbuf, sizeof(struct visit));
1458 vbuf.v_lastseen = newlr;
1459 snprintf(vbuf.v_seen, sizeof vbuf.v_seen, "*:%ld", newlr);
1461 /* Only rewrite the record if it changed */
1462 if ( (vbuf.v_lastseen != original_vbuf.v_lastseen)
1463 || (strcmp(vbuf.v_seen, original_vbuf.v_seen)) ) {
1464 CtdlSetRelationship(&vbuf, &CC->user, &CC->room);
1467 CtdlPutUserLock(&CC->user);
1468 cprintf("%d %ld\n", CIT_OK, newlr);
1472 void cmd_seen(char *argbuf) {
1473 long target_msgnum = 0L;
1474 int target_setting = 0;
1476 if (CtdlAccessCheck(ac_logged_in)) {
1480 if (num_parms(argbuf) != 2) {
1481 cprintf("%d Invalid parameters\n", ERROR + ILLEGAL_VALUE);
1485 target_msgnum = extract_long(argbuf, 0);
1486 target_setting = extract_int(argbuf, 1);
1488 CtdlSetSeen(&target_msgnum, 1, target_setting,
1489 ctdlsetseen_seen, NULL, NULL);
1490 cprintf("%d OK\n", CIT_OK);
1494 void cmd_gtsn(char *argbuf) {
1497 if (CtdlAccessCheck(ac_logged_in)) {
1501 CtdlGetSeen(buf, ctdlsetseen_seen);
1502 cprintf("%d %s\n", CIT_OK, buf);
1507 * API function for cmd_invt_kick() and anything else that needs to
1508 * invite or kick out a user to/from a room.
1510 * Set iuser to the name of the user, and op to 1=invite or 0=kick
1512 int CtdlInvtKick(char *iuser, int op) {
1513 struct ctdluser USscratch;
1517 if (CtdlGetUser(&USscratch, iuser) != 0) {
1521 CtdlGetRelationship(&vbuf, &USscratch, &CC->room);
1523 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
1524 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
1527 vbuf.v_flags = vbuf.v_flags & ~V_ACCESS;
1528 vbuf.v_flags = vbuf.v_flags | V_FORGET | V_LOCKOUT;
1530 CtdlSetRelationship(&vbuf, &USscratch, &CC->room);
1532 /* post a message in Aide> saying what we just did */
1533 snprintf(bbb, sizeof bbb, "%s has been %s \"%s\" by %s.\n",
1535 ((op == 1) ? "invited to" : "kicked out of"),
1538 CtdlAideMessage(bbb,"User Admin Message");
1545 * INVT and KICK commands
1547 void cmd_invt_kick(char *iuser, int op) {
1550 * These commands are only allowed by aides, room aides,
1551 * and room namespace owners
1554 || (atol(CC->room.QRname) == CC->user.usernum) ) {
1555 /* access granted */
1558 cprintf("%d Higher access or room ownership required.\n",
1559 ERROR + HIGHER_ACCESS_REQUIRED);
1563 if (!strncasecmp(CC->room.QRname, config.c_baseroom,
1565 cprintf("%d Can't add/remove users from this room.\n",
1570 if (CtdlInvtKick(iuser, op) != 0) {
1571 cprintf("%d No such user.\n", ERROR + NO_SUCH_USER);
1575 cprintf("%d %s %s %s.\n",
1577 ((op == 1) ? "invited to" : "kicked out of"),
1582 void cmd_invt(char *iuser) {cmd_invt_kick(iuser, 1);}
1583 void cmd_kick(char *iuser) {cmd_invt_kick(iuser, 0);}
1586 * Forget (Zap) the current room (API call)
1587 * Returns 0 on success
1589 int CtdlForgetThisRoom(void) {
1592 /* On some systems, Aides are not allowed to forget rooms */
1593 if (is_aide() && (config.c_aide_zap == 0)
1594 && ((CC->room.QRflags & QR_MAILBOX) == 0) ) {
1598 CtdlGetUserLock(&CC->user, CC->curr_user);
1599 CtdlGetRelationship(&vbuf, &CC->user, &CC->room);
1601 vbuf.v_flags = vbuf.v_flags | V_FORGET;
1602 vbuf.v_flags = vbuf.v_flags & ~V_ACCESS;
1604 CtdlSetRelationship(&vbuf, &CC->user, &CC->room);
1605 CtdlPutUserLock(&CC->user);
1607 /* Return to the Lobby, so we don't end up in an undefined room */
1608 CtdlUserGoto(config.c_baseroom, 0, 0, NULL, NULL);
1615 * forget (Zap) the current room
1617 void cmd_forg(char *argbuf)
1620 if (CtdlAccessCheck(ac_logged_in)) {
1624 if (CtdlForgetThisRoom() == 0) {
1625 cprintf("%d Ok\n", CIT_OK);
1628 cprintf("%d You may not forget this room.\n", ERROR + NOT_HERE);
1633 * Get Next Unregistered User
1635 void cmd_gnur(char *argbuf)
1637 struct cdbdata *cdbus;
1638 struct ctdluser usbuf;
1640 if (CtdlAccessCheck(ac_aide)) {
1644 if ((CitControl.MMflags & MM_VALID) == 0) {
1645 cprintf("%d There are no unvalidated users.\n", CIT_OK);
1649 /* There are unvalidated users. Traverse the user database,
1650 * and return the first user we find that needs validation.
1652 cdb_rewind(CDB_USERS);
1653 while (cdbus = cdb_next_item(CDB_USERS), cdbus != NULL) {
1654 memset(&usbuf, 0, sizeof(struct ctdluser));
1655 memcpy(&usbuf, cdbus->ptr,
1656 ((cdbus->len > sizeof(struct ctdluser)) ?
1657 sizeof(struct ctdluser) : cdbus->len));
1659 if ((usbuf.flags & US_NEEDVALID)
1660 && (usbuf.axlevel > 0)) {
1661 cprintf("%d %s\n", MORE_DATA, usbuf.fullname);
1662 cdb_close_cursor(CDB_USERS);
1667 /* If we get to this point, there are no more unvalidated users.
1668 * Therefore we clear the "users need validation" flag.
1671 begin_critical_section(S_CONTROL);
1673 CitControl.MMflags = CitControl.MMflags & (~MM_VALID);
1675 end_critical_section(S_CONTROL);
1676 cprintf("%d *** End of registration.\n", CIT_OK);
1685 void cmd_vali(char *v_args)
1689 struct ctdluser userbuf;
1691 extract_token(user, v_args, 0, '|', sizeof user);
1692 newax = extract_int(v_args, 1);
1694 if (CtdlAccessCheck(ac_aide)) {
1698 if (CtdlGetUserLock(&userbuf, user) != 0) {
1699 cprintf("%d '%s' not found.\n", ERROR + NO_SUCH_USER, user);
1703 userbuf.axlevel = newax;
1704 userbuf.flags = (userbuf.flags & ~US_NEEDVALID);
1706 CtdlPutUserLock(&userbuf);
1708 /* If the access level was set to zero, delete the user */
1710 if (purge_user(user) == 0) {
1711 cprintf("%d %s Deleted.\n", CIT_OK, userbuf.fullname);
1715 cprintf("%d User '%s' validated.\n", CIT_OK, userbuf.fullname);
1721 * Traverse the user file...
1723 void ForEachUser(void (*CallBack) (struct ctdluser * EachUser, void *out_data),
1726 struct ctdluser usbuf;
1727 struct cdbdata *cdbus;
1729 cdb_rewind(CDB_USERS);
1731 while (cdbus = cdb_next_item(CDB_USERS), cdbus != NULL) {
1732 memset(&usbuf, 0, sizeof(struct ctdluser));
1733 memcpy(&usbuf, cdbus->ptr,
1734 ((cdbus->len > sizeof(struct ctdluser)) ?
1735 sizeof(struct ctdluser) : cdbus->len));
1737 (*CallBack) (&usbuf, in_data);
1743 * List one user (this works with cmd_list)
1745 void ListThisUser(struct ctdluser *usbuf, void *data)
1749 searchstring = (char *)data;
1750 if (bmstrcasestr(usbuf->fullname, searchstring) == NULL) {
1754 if (usbuf->axlevel > 0) {
1755 if ((CC->user.axlevel >= 6)
1756 || ((usbuf->flags & US_UNLISTED) == 0)
1757 || ((CC->internal_pgm))) {
1758 cprintf("%s|%d|%ld|%ld|%ld|%ld||\n",
1762 (long)usbuf->lastcall,
1770 * List users (searchstring may be empty to list all users)
1772 void cmd_list(char *cmdbuf)
1774 char searchstring[256];
1775 extract_token(searchstring, cmdbuf, 0, '|', sizeof searchstring);
1776 striplt(searchstring);
1777 cprintf("%d \n", LISTING_FOLLOWS);
1778 ForEachUser(ListThisUser, (void *)searchstring );
1786 * assorted info we need to check at login
1788 void cmd_chek(char *argbuf)
1794 if (CtdlAccessCheck(ac_logged_in)) {
1798 CtdlGetUser(&CC->user, CC->curr_user); /* no lock is needed here */
1799 if ((REGISCALL != 0) && ((CC->user.flags & US_REGIS) == 0))
1802 if (CC->user.axlevel >= 6) {
1804 if (CitControl.MMflags & MM_VALID)
1808 /* check for mail */
1809 mail = InitialMailCheck();
1811 cprintf("%d %d|%d|%d|%s|\n", CIT_OK, mail, regis, vali, CC->cs_inet_email);
1816 * check to see if a user exists
1818 void cmd_qusr(char *who)
1820 struct ctdluser usbuf;
1822 if (CtdlGetUser(&usbuf, who) == 0) {
1823 cprintf("%d %s\n", CIT_OK, usbuf.fullname);
1825 cprintf("%d No such user.\n", ERROR + NO_SUCH_USER);
1831 * Administrative Get User Parameters
1833 void cmd_agup(char *cmdbuf)
1835 struct ctdluser usbuf;
1836 char requested_user[128];
1838 if (CtdlAccessCheck(ac_aide)) {
1842 extract_token(requested_user, cmdbuf, 0, '|', sizeof requested_user);
1843 if (CtdlGetUser(&usbuf, requested_user) != 0) {
1844 cprintf("%d No such user.\n", ERROR + NO_SUCH_USER);
1847 cprintf("%d %s|%s|%u|%ld|%ld|%d|%ld|%ld|%d\n",
1854 (int) usbuf.axlevel,
1856 (long)usbuf.lastcall,
1863 * Administrative Set User Parameters
1865 void cmd_asup(char *cmdbuf)
1867 struct ctdluser usbuf;
1868 char requested_user[128];
1874 if (CtdlAccessCheck(ac_aide))
1877 extract_token(requested_user, cmdbuf, 0, '|', sizeof requested_user);
1878 if (CtdlGetUserLock(&usbuf, requested_user) != 0) {
1879 cprintf("%d No such user.\n", ERROR + NO_SUCH_USER);
1882 np = num_parms(cmdbuf);
1884 extract_token(usbuf.password, cmdbuf, 1, '|', sizeof usbuf.password);
1886 usbuf.flags = extract_int(cmdbuf, 2);
1888 usbuf.timescalled = extract_int(cmdbuf, 3);
1890 usbuf.posted = extract_int(cmdbuf, 4);
1892 newax = extract_int(cmdbuf, 5);
1893 if ((newax >= 0) && (newax <= 6)) {
1894 usbuf.axlevel = extract_int(cmdbuf, 5);
1898 usbuf.lastcall = extract_long(cmdbuf, 7);
1901 usbuf.USuserpurge = extract_int(cmdbuf, 8);
1903 CtdlPutUserLock(&usbuf);
1904 if (usbuf.axlevel == 0) {
1905 if (purge_user(requested_user) == 0) {
1911 snprintf(notify, SIZ,
1912 "User \"%s\" has been deleted by %s.\n",
1913 usbuf.fullname, CC->user.fullname);
1914 CtdlAideMessage(notify, "User Deletion Message");
1917 cprintf("%d Ok", CIT_OK);
1919 cprintf(" (%s deleted)", requested_user);
1926 * Check to see if the user who we just sent mail to is logged in. If yes,
1927 * bump the 'new mail' counter for their session. That enables them to
1928 * receive a new mail notification without having to hit the database.
1930 void BumpNewMailCounter(long which_user) {
1931 struct CitContext *ptr;
1933 begin_critical_section(S_SESSION_TABLE);
1935 for (ptr = ContextList; ptr != NULL; ptr = ptr->next) {
1936 if (ptr->user.usernum == which_user) {
1941 end_critical_section(S_SESSION_TABLE);
1946 * Count the number of new mail messages the user has
1950 int num_newmsgs = 0;
1952 num_newmsgs = CC->newmail;
1955 return (num_newmsgs);
1960 * Count the number of new mail messages the user has
1962 int InitialMailCheck()
1964 int num_newmsgs = 0;
1966 char mailboxname[ROOMNAMELEN];
1967 struct ctdlroom mailbox;
1969 struct cdbdata *cdbfr;
1970 long *msglist = NULL;
1973 MailboxName(mailboxname, sizeof mailboxname, &CC->user, MAILROOM);
1974 if (CtdlGetRoom(&mailbox, mailboxname) != 0)
1976 CtdlGetRelationship(&vbuf, &CC->user, &mailbox);
1978 cdbfr = cdb_fetch(CDB_MSGLISTS, &mailbox.QRnumber, sizeof(long));
1980 if (cdbfr != NULL) {
1981 msglist = malloc(cdbfr->len);
1982 memcpy(msglist, cdbfr->ptr, cdbfr->len);
1983 num_msgs = cdbfr->len / sizeof(long);
1987 for (a = 0; a < num_msgs; ++a) {
1988 if (msglist[a] > 0L) {
1989 if (msglist[a] > vbuf.v_lastseen) {
1994 if (msglist != NULL)
1997 return (num_newmsgs);
2003 * Set the preferred view for the current user/room combination
2005 void cmd_view(char *cmdbuf) {
2009 if (CtdlAccessCheck(ac_logged_in)) {
2013 requested_view = extract_int(cmdbuf, 0);
2015 CtdlGetRelationship(&vbuf, &CC->user, &CC->room);
2016 vbuf.v_view = requested_view;
2017 CtdlSetRelationship(&vbuf, &CC->user, &CC->room);
2019 cprintf("%d ok\n", CIT_OK);
2026 void cmd_renu(char *cmdbuf)
2029 char oldname[USERNAME_SIZE];
2030 char newname[USERNAME_SIZE];
2032 if (CtdlAccessCheck(ac_aide)) {
2036 extract_token(oldname, cmdbuf, 0, '|', sizeof oldname);
2037 extract_token(newname, cmdbuf, 1, '|', sizeof newname);
2039 retcode = rename_user(oldname, newname);
2042 cprintf("%d '%s' has been renamed to '%s'.\n", CIT_OK, oldname, newname);
2044 case RENAMEUSER_LOGGED_IN:
2045 cprintf("%d '%s' is currently logged in and cannot be renamed.\n",
2046 ERROR + ALREADY_LOGGED_IN , oldname);
2048 case RENAMEUSER_NOT_FOUND:
2049 cprintf("%d '%s' does not exist.\n", ERROR + NO_SUCH_USER, oldname);
2051 case RENAMEUSER_ALREADY_EXISTS:
2052 cprintf("%d A user named '%s' already exists.\n", ERROR + ALREADY_EXISTS, newname);
2056 cprintf("%d An unknown error occurred.\n", ERROR);
2061 /*****************************************************************************/
2062 /* MODULE INITIALIZATION STUFF */
2063 /*****************************************************************************/
2066 CTDL_MODULE_INIT(user_ops)
2068 CtdlRegisterProtoHook(cmd_user, "USER", "Autoconverted. TODO: document me.");
2069 CtdlRegisterProtoHook(cmd_pass, "PASS", "Autoconverted. TODO: document me.");
2070 CtdlRegisterProtoHook(cmd_creu, "CREU", "Autoconverted. TODO: document me.");
2071 CtdlRegisterProtoHook(cmd_setp, "SETP", "Autoconverted. TODO: document me.");
2072 CtdlRegisterProtoHook(cmd_getu, "GETU", "Autoconverted. TODO: document me.");
2073 CtdlRegisterProtoHook(cmd_setu, "SETU", "Autoconverted. TODO: document me.");
2074 CtdlRegisterProtoHook(cmd_slrp, "SLRP", "Autoconverted. TODO: document me.");
2075 CtdlRegisterProtoHook(cmd_invt, "INVT", "Autoconverted. TODO: document me.");
2076 CtdlRegisterProtoHook(cmd_kick, "KICK", "Autoconverted. TODO: document me.");
2077 CtdlRegisterProtoHook(cmd_forg, "FORG", "Autoconverted. TODO: document me.");
2078 CtdlRegisterProtoHook(cmd_gnur, "GNUR", "Autoconverted. TODO: document me.");
2079 CtdlRegisterProtoHook(cmd_vali, "VALI", "Autoconverted. TODO: document me.");
2080 CtdlRegisterProtoHook(cmd_list, "LIST", "Autoconverted. TODO: document me.");
2081 CtdlRegisterProtoHook(cmd_chek, "CHEK", "Autoconverted. TODO: document me.");
2082 CtdlRegisterProtoHook(cmd_qusr, "QUSR", "Autoconverted. TODO: document me.");
2083 CtdlRegisterProtoHook(cmd_agup, "AGUP", "Autoconverted. TODO: document me.");
2084 CtdlRegisterProtoHook(cmd_asup, "ASUP", "Autoconverted. TODO: document me.");
2085 CtdlRegisterProtoHook(cmd_seen, "SEEN", "Autoconverted. TODO: document me.");
2086 CtdlRegisterProtoHook(cmd_gtsn, "GTSN", "Autoconverted. TODO: document me.");
2087 CtdlRegisterProtoHook(cmd_view, "VIEW", "Autoconverted. TODO: document me.");
2088 CtdlRegisterProtoHook(cmd_renu, "RENU", "Autoconverted. TODO: document me.");
2089 CtdlRegisterProtoHook(cmd_newu, "NEWU", "Autoconverted. TODO: document me.");
2090 /* return our Subversion id for the Log */