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 CtdlMailboxName(char *buf, size_t n, const struct ctdluser *who, const char *prefix)
366 snprintf(buf, n, "%010ld.%s", who->usernum, prefix);
370 void MailboxName(char *buf, size_t n, const struct ctdluser *who, const char *prefix)
372 snprintf(buf, n, "%010ld.%s", who->usernum, prefix);
377 * Is the user currently logged in an Aide?
381 if (CC->user.axlevel >= 6)
389 * Is the user currently logged in an Aide *or* the room aide for this room?
391 int is_room_aide(void)
394 if (!CC->logged_in) {
398 if ((CC->user.axlevel >= 6)
399 || (CC->room.QRroomaide == CC->user.usernum)) {
407 * CtdlGetUserByNumber() - get user by number
408 * returns 0 if user was found
410 * Note: fetching a user this way requires one additional database operation.
412 int CtdlGetUserByNumber(struct ctdluser *usbuf, long number)
414 struct cdbdata *cdbun;
417 cdbun = cdb_fetch(CDB_USERSBYNUMBER, &number, sizeof(long));
419 CtdlLogPrintf(CTDL_INFO, "User %ld not found\n", number);
423 CtdlLogPrintf(CTDL_INFO, "User %ld maps to %s\n", number, cdbun->ptr);
424 r = CtdlGetUser(usbuf, cdbun->ptr);
430 * getuserbynumber() - get user by number
431 * returns 0 if user was found
433 * Note: fetching a user this way requires one additional database operation.
435 int getuserbynumber(struct ctdluser *usbuf, long number)
437 return CtdlGetUserByNumber(usbuf, number);
443 * Helper function for rebuild_usersbynumber()
445 void rebuild_ubn_for_user(struct ctdluser *usbuf, void *data) {
448 struct ubnlist *next;
449 char username[USERNAME_SIZE];
453 static struct ubnlist *u = NULL;
454 struct ubnlist *ptr = NULL;
456 /* Lazy programming here. Call this function as a ForEachUser backend
457 * in order to queue up the room names, or call it with a null user
458 * to make it do the processing.
461 ptr = (struct ubnlist *) malloc(sizeof (struct ubnlist));
462 if (ptr == NULL) return;
464 ptr->usernum = usbuf->usernum;
465 safestrncpy(ptr->username, usbuf->fullname, sizeof ptr->username);
472 CtdlLogPrintf(CTDL_DEBUG, "Rebuilding usersbynumber index %10ld : %s\n",
473 u->usernum, u->username);
474 cdb_store(CDB_USERSBYNUMBER, &u->usernum, sizeof(long), u->username, strlen(u->username)+1);
485 * Rebuild the users-by-number index
487 void rebuild_usersbynumber(void) {
488 cdb_trunc(CDB_USERSBYNUMBER); /* delete the old indices */
489 ForEachUser(rebuild_ubn_for_user, NULL); /* enumerate the users */
490 rebuild_ubn_for_user(NULL, NULL); /* and index them */
496 * getuserbyuid() - get user by system uid (for PAM mode authentication)
497 * returns 0 if user was found
499 * WARNING: don't use this function unless you absolutely have to. It does
500 * a sequential search and therefore is computationally expensive.
502 int getuserbyuid(struct ctdluser *usbuf, uid_t number)
504 struct cdbdata *cdbus;
506 cdb_rewind(CDB_USERS);
508 while (cdbus = cdb_next_item(CDB_USERS), cdbus != NULL) {
509 memset(usbuf, 0, sizeof(struct ctdluser));
510 memcpy(usbuf, cdbus->ptr,
511 ((cdbus->len > sizeof(struct ctdluser)) ?
512 sizeof(struct ctdluser) : cdbus->len));
514 if (usbuf->uid == number) {
515 cdb_close_cursor(CDB_USERS);
523 * Back end for cmd_user() and its ilk
525 * NOTE: "authname" should only be used if we are attempting to use the "master user" feature
527 int CtdlLoginExistingUser(char *authname, char *trythisname)
532 CtdlLogPrintf(9, "CtdlLoginExistingUser(%s, %s)\n", authname, trythisname);
534 if ((CC->logged_in)) {
535 return login_already_logged_in;
538 if (trythisname == NULL) return login_not_found;
540 if (!strncasecmp(trythisname, "SYS_", 4))
542 CtdlLogPrintf(CTDL_DEBUG, "System user \"%s\" is not allowed to log in.\n", trythisname);
543 return login_not_found;
546 /* If a "master user" is defined, handle its authentication if specified */
548 if (strlen(config.c_master_user) > 0) if (strlen(config.c_master_pass) > 0) if (authname) {
549 if (!strcasecmp(authname, config.c_master_user)) {
554 /* Continue attempting user validation... */
555 safestrncpy(username, trythisname, USERNAME_SIZE);
558 if (IsEmptyStr(username)) {
559 return login_not_found;
562 if (config.c_auth_mode == AUTHMODE_HOST) {
567 struct passwd *tempPwdPtr;
570 CtdlLogPrintf(CTDL_DEBUG, "asking host about <%s>\n", username);
571 #ifdef HAVE_GETPWNAM_R
572 #ifdef SOLARIS_GETPWUID
573 CtdlLogPrintf(CTDL_DEBUG, "Calling getpwnam_r()\n");
574 tempPwdPtr = getpwnam_r(username, &pd, pwdbuffer, sizeof pwdbuffer);
575 #else // SOLARIS_GETPWUID
576 CtdlLogPrintf(CTDL_DEBUG, "Calling getpwnam_r()\n");
577 getpwnam_r(username, &pd, pwdbuffer, sizeof pwdbuffer, &tempPwdPtr);
578 #endif // SOLARIS_GETPWUID
579 #else // HAVE_GETPWNAM_R
580 CtdlLogPrintf(CTDL_DEBUG, "SHOULD NEVER GET HERE!!!\n");
582 #endif // HAVE_GETPWNAM_R
583 if (tempPwdPtr == NULL) {
584 CtdlLogPrintf(CTDL_DEBUG, "no such user <%s>\n", username);
585 return login_not_found;
588 /* Locate the associated Citadel account.
589 * If not found, make one attempt to create it.
591 found_user = getuserbyuid(&CC->user, pd.pw_uid);
592 CtdlLogPrintf(CTDL_DEBUG, "found it: uid=%ld, gecos=%s here: %d\n",
593 (long)pd.pw_uid, pd.pw_gecos, found_user);
594 if (found_user != 0) {
595 create_user(username, 0);
596 found_user = getuserbyuid(&CC->user, pd.pw_uid);
602 else if ((config.c_auth_mode == AUTHMODE_LDAP) || (config.c_auth_mode == AUTHMODE_LDAP_AD)) {
610 found_user = CtdlTryUserLDAP(username, ldap_dn, sizeof ldap_dn, ldap_cn, sizeof ldap_cn, &ldap_uid);
611 if (found_user != 0) {
612 return login_not_found;
615 found_user = getuserbyuid(&CC->user, ldap_uid);
616 if (found_user != 0) {
617 create_user(trythisname, 0);
618 found_user = getuserbyuid(&CC->user, ldap_uid);
621 if (found_user == 0) {
622 if (CC->ldap_dn != NULL) free(CC->ldap_dn);
623 CC->ldap_dn = strdup(ldap_dn);
630 /* native auth mode */
632 struct recptypes *valid = NULL;
634 /* First, try to log in as if the supplied name is a display name */
635 found_user = CtdlGetUser(&CC->user, username);
637 /* If that didn't work, try to log in as if the supplied name
638 * is an e-mail address
640 if (found_user != 0) {
641 valid = validate_recipients(username, NULL, 0);
643 if (valid->num_local == 1) {
644 found_user = CtdlGetUser(&CC->user, valid->recp_local);
646 free_recipients(valid);
651 /* Did we find something? */
652 if (found_user == 0) {
653 if (((CC->nologin)) && (CC->user.axlevel < 6)) {
654 return login_too_many_users;
656 safestrncpy(CC->curr_user, CC->user.fullname,
657 sizeof CC->curr_user);
661 return login_not_found;
669 void cmd_user(char *cmdbuf)
674 CtdlLogPrintf(CTDL_DEBUG, "cmd_user(%s)\n", cmdbuf);
675 extract_token(username, cmdbuf, 0, '|', sizeof username);
676 CtdlLogPrintf(CTDL_DEBUG, "username: %s\n", username);
678 CtdlLogPrintf(CTDL_DEBUG, "username: %s\n", username);
680 a = CtdlLoginExistingUser(NULL, username);
682 case login_already_logged_in:
683 cprintf("%d Already logged in.\n", ERROR + ALREADY_LOGGED_IN);
685 case login_too_many_users:
687 "Too many users are already online "
689 ERROR + MAX_SESSIONS_EXCEEDED,
690 config.c_nodename, config.c_maxsessions);
693 cprintf("%d Password required for %s\n",
694 MORE_DATA, CC->curr_user);
696 case login_not_found:
697 cprintf("%d %s not found.\n", ERROR + NO_SUCH_USER, username);
700 cprintf("%d Internal error\n", ERROR + INTERNAL_ERROR);
707 * session startup code which is common to both cmd_pass() and cmd_newu()
712 CtdlLogPrintf(CTDL_NOTICE, "<%s> logged in\n", CC->curr_user);
714 CtdlGetUserLock(&CC->user, CC->curr_user);
715 ++(CC->user.timescalled);
716 CC->previous_login = CC->user.lastcall;
717 time(&CC->user.lastcall);
719 /* If this user's name is the name of the system administrator
720 * (as specified in setup), automatically assign access level 6.
722 if (!strcasecmp(CC->user.fullname, config.c_sysadm)) {
723 CC->user.axlevel = 6;
726 /* If we're authenticating off the host system, automatically give
727 * root the highest level of access.
729 if (config.c_auth_mode == AUTHMODE_HOST) {
730 if (CC->user.uid == 0) {
731 CC->user.axlevel = 6;
735 CtdlPutUserLock(&CC->user);
738 * Populate CC->cs_inet_email with a default address. This will be
739 * overwritten with the user's directory address, if one exists, when
740 * the vCard module's login hook runs.
742 snprintf(CC->cs_inet_email, sizeof CC->cs_inet_email, "%s@%s",
743 CC->user.fullname, config.c_fqdn);
744 convert_spaces_to_underscores(CC->cs_inet_email);
746 /* Create any personal rooms required by the system.
747 * (Technically, MAILROOM should be there already, but just in case...)
749 CtdlCreateRoom(MAILROOM, 4, "", 0, 1, 0, VIEW_MAILBOX);
750 CtdlCreateRoom(SENTITEMS, 4, "", 0, 1, 0, VIEW_MAILBOX);
751 CtdlCreateRoom(USERTRASHROOM, 4, "", 0, 1, 0, VIEW_MAILBOX);
752 /* CtdlCreateRoom(USERDRAFTROOM, 4, "", 0, 1, 0, VIEW_MAILBOX); temporarily disabled for 7.60 */
754 /* Run any startup routines registered by loadable modules */
755 PerformSessionHooks(EVT_LOGIN);
757 /* Enter the lobby */
758 CtdlUserGoto(config.c_baseroom, 0, 0, NULL, NULL);
762 void logged_in_response(void)
764 cprintf("%d %s|%d|%ld|%ld|%u|%ld|%ld\n",
765 CIT_OK, CC->user.fullname, CC->user.axlevel,
766 CC->user.timescalled, CC->user.posted,
767 CC->user.flags, CC->user.usernum,
774 * misc things to be taken care of when a user is logged out
778 struct CitContext *CCC = CC; /* CachedCitContext - performance boost */
780 * If there is a download in progress, abort it.
782 if (CCC->download_fp != NULL) {
783 fclose(CCC->download_fp);
784 CCC->download_fp = NULL;
788 * If there is an upload in progress, abort it.
790 if (CCC->upload_fp != NULL) {
795 * If we were talking to a network node, we're not anymore...
797 if (!IsEmptyStr(CCC->net_node)) {
798 network_talking_to(CCC->net_node, NTT_REMOVE);
801 /* Run any hooks registered by modules... */
802 PerformSessionHooks(EVT_LOGOUT);
805 * Clear out some session data. Most likely, the CitContext for this
806 * session is about to get nuked when the session disconnects, but
807 * since it's possible to log in again without reconnecting, we cannot
808 * make that assumption.
810 strcpy(CCC->fake_username, "");
811 strcpy(CCC->fake_hostname, "");
812 strcpy(CCC->fake_roomname, "");
815 /* Check to see if the user was deleted whilst logged in and purge them if necessary */
816 if ((CCC->user.axlevel == 0) && (CCC->user.usernum))
817 purge_user(CCC->user.fullname);
819 /* Free any output buffers */
824 * Validate a password on the host unix system by talking to the chkpwd daemon
826 static int validpw(uid_t uid, const char *pass)
831 if (IsEmptyStr(pass)) {
832 CtdlLogPrintf(CTDL_DEBUG, "refusing to check empty password for uid=%d using chkpwd...\n", uid);
836 CtdlLogPrintf(CTDL_DEBUG, "Validating password for uid=%d using chkpwd...\n", uid);
838 begin_critical_section(S_CHKPWD);
839 rv = write(chkpwd_write_pipe[1], &uid, sizeof(uid_t));
840 rv = write(chkpwd_write_pipe[1], pass, 256);
841 rv = read(chkpwd_read_pipe[0], buf, 4);
842 end_critical_section(S_CHKPWD);
844 if (!strncmp(buf, "PASS", 4)) {
845 CtdlLogPrintf(CTDL_DEBUG, "...pass\n");
849 CtdlLogPrintf(CTDL_DEBUG, "...fail\n");
854 * Start up the chkpwd daemon so validpw() has something to talk to
856 void start_chkpwd_daemon(void) {
858 struct stat filestats;
861 CtdlLogPrintf(CTDL_DEBUG, "Starting chkpwd daemon for host authentication mode\n");
863 if ((stat(file_chkpwd, &filestats)==-1) ||
864 (filestats.st_size==0)){
865 printf("didn't find chkpwd daemon in %s: %s\n", file_chkpwd, strerror(errno));
868 if (pipe(chkpwd_write_pipe) != 0) {
869 CtdlLogPrintf(CTDL_EMERG, "Unable to create pipe for chkpwd daemon: %s\n", strerror(errno));
872 if (pipe(chkpwd_read_pipe) != 0) {
873 CtdlLogPrintf(CTDL_EMERG, "Unable to create pipe for chkpwd daemon: %s\n", strerror(errno));
878 if (chkpwd_pid < 0) {
879 CtdlLogPrintf(CTDL_EMERG, "Unable to fork chkpwd daemon: %s\n", strerror(errno));
882 if (chkpwd_pid == 0) {
883 CtdlLogPrintf(CTDL_DEBUG, "Now calling dup2() write\n");
884 dup2(chkpwd_write_pipe[0], 0);
885 CtdlLogPrintf(CTDL_DEBUG, "Now calling dup2() write\n");
886 dup2(chkpwd_read_pipe[1], 1);
887 CtdlLogPrintf(CTDL_DEBUG, "Now closing stuff\n");
888 for (i=2; i<256; ++i) close(i);
889 CtdlLogPrintf(CTDL_DEBUG, "Now calling execl(%s)\n", file_chkpwd);
890 execl(file_chkpwd, file_chkpwd, NULL);
891 CtdlLogPrintf(CTDL_EMERG, "Unable to exec chkpwd daemon: %s\n", strerror(errno));
898 int CtdlTryPassword(char *password)
902 if ((CC->logged_in)) {
903 CtdlLogPrintf(CTDL_WARNING, "CtdlTryPassword: already logged in\n");
904 return pass_already_logged_in;
906 if (!strcmp(CC->curr_user, NLI)) {
907 CtdlLogPrintf(CTDL_WARNING, "CtdlTryPassword: no user selected\n");
910 if (CtdlGetUser(&CC->user, CC->curr_user)) {
911 CtdlLogPrintf(CTDL_ERR, "CtdlTryPassword: internal error\n");
912 return pass_internal_error;
914 if (password == NULL) {
915 CtdlLogPrintf(CTDL_INFO, "CtdlTryPassword: NULL password string supplied\n");
916 return pass_wrong_password;
921 code = strcmp(password, config.c_master_pass);
924 else if (config.c_auth_mode == AUTHMODE_HOST) {
928 if (validpw(CC->user.uid, password)) {
932 * sooper-seekrit hack: populate the password field in the
933 * citadel database with the password that the user typed,
934 * if it's correct. This allows most sites to convert from
935 * host auth to native auth if they want to. If you think
936 * this is a security hazard, comment it out.
939 CtdlGetUserLock(&CC->user, CC->curr_user);
940 safestrncpy(CC->user.password, password, sizeof CC->user.password);
941 CtdlPutUserLock(&CC->user);
944 * (sooper-seekrit hack ends here)
954 else if ((config.c_auth_mode == AUTHMODE_LDAP) || (config.c_auth_mode == AUTHMODE_LDAP_AD)) {
958 if ((CC->ldap_dn) && (!CtdlTryPasswordLDAP(CC->ldap_dn, password))) {
969 /* native auth mode */
972 strproc(CC->user.password);
973 code = strcasecmp(CC->user.password, password);
975 strproc(CC->user.password);
976 code = strcasecmp(CC->user.password, password);
983 CtdlLogPrintf(CTDL_WARNING, "Bad password specified for <%s>\n", CC->curr_user);
984 return pass_wrong_password;
989 void cmd_pass(char *buf)
994 memset(password, 0, sizeof(password));
995 extract_token(password, buf, 0, '|', sizeof password);
996 a = CtdlTryPassword(password);
999 case pass_already_logged_in:
1000 cprintf("%d Already logged in.\n", ERROR + ALREADY_LOGGED_IN);
1003 cprintf("%d You must send a name with USER first.\n",
1004 ERROR + USERNAME_REQUIRED);
1006 case pass_wrong_password:
1007 cprintf("%d Wrong password.\n", ERROR + PASSWORD_REQUIRED);
1010 logged_in_response();
1018 * Delete a user record *and* all of its related resources.
1020 int purge_user(char pname[])
1023 struct ctdluser usbuf;
1024 char usernamekey[USERNAME_SIZE];
1025 struct CitContext *ccptr;
1026 int user_is_logged_in = 0;
1028 makeuserkey(usernamekey, pname);
1030 /* If the name is empty we can't find them in the DB any way so just return */
1031 if (IsEmptyStr(pname))
1032 return (ERROR + NO_SUCH_USER);
1034 if (CtdlGetUser(&usbuf, pname) != 0) {
1035 CtdlLogPrintf(CTDL_ERR, "Cannot purge user <%s> - not found\n", pname);
1036 return (ERROR + NO_SUCH_USER);
1038 /* Don't delete a user who is currently logged in. Instead, just
1039 * set the access level to 0, and let the account get swept up
1040 * during the next purge.
1042 user_is_logged_in = 0;
1043 begin_critical_section(S_SESSION_TABLE);
1044 for (ccptr = ContextList; ccptr != NULL; ccptr = ccptr->next) {
1045 if (ccptr->user.usernum == usbuf.usernum) {
1046 user_is_logged_in = 1;
1049 end_critical_section(S_SESSION_TABLE);
1050 if (user_is_logged_in == 1) {
1051 CtdlLogPrintf(CTDL_WARNING, "User <%s> is logged in; not deleting.\n", pname);
1053 CtdlPutUser(&usbuf);
1056 CtdlLogPrintf(CTDL_NOTICE, "Deleting user <%s>\n", pname);
1058 /* Perform any purge functions registered by server extensions */
1059 PerformUserHooks(&usbuf, EVT_PURGEUSER);
1061 /* delete any existing user/room relationships */
1062 cdb_delete(CDB_VISIT, &usbuf.usernum, sizeof(long));
1064 /* delete the users-by-number index record */
1065 cdb_delete(CDB_USERSBYNUMBER, &usbuf.usernum, sizeof(long));
1067 /* delete the userlog entry */
1068 cdb_delete(CDB_USERS, usernamekey, strlen(usernamekey));
1070 /* remove the user's bio file */
1078 /* remove the user's picture */
1090 int internal_create_user (char *username, struct ctdluser *usbuf, uid_t uid)
1092 if (!CtdlGetUser(usbuf, username)) {
1093 return (ERROR + ALREADY_EXISTS);
1096 /* Go ahead and initialize a new user record */
1097 memset(usbuf, 0, sizeof(struct ctdluser));
1098 safestrncpy(usbuf->fullname, username, sizeof usbuf->fullname);
1099 strcpy(usbuf->password, "");
1102 /* These are the default flags on new accounts */
1103 usbuf->flags = US_LASTOLD | US_DISAPPEAR | US_PAGINATOR | US_FLOORS;
1105 usbuf->timescalled = 0;
1107 usbuf->axlevel = config.c_initax;
1108 usbuf->USscreenwidth = 80;
1109 usbuf->USscreenheight = 24;
1110 usbuf->lastcall = time(NULL);
1112 /* fetch a new user number */
1113 usbuf->usernum = get_new_user_number();
1115 /* add user to the database */
1117 cdb_store(CDB_USERSBYNUMBER, &usbuf->usernum, sizeof(long), usbuf->fullname, strlen(usbuf->fullname)+1);
1125 * create_user() - back end processing to create a new user
1127 * Set 'newusername' to the desired account name.
1128 * Set 'become_user' to nonzero if this is self-service account creation and we want
1129 * to actually log in as the user we just created, otherwise set it to 0.
1131 int create_user(char *newusername, int become_user)
1133 struct ctdluser usbuf;
1134 struct ctdlroom qrbuf;
1136 char mailboxname[ROOMNAMELEN];
1142 safestrncpy(username, newusername, sizeof username);
1146 if (config.c_auth_mode == AUTHMODE_HOST) {
1148 /* host auth mode */
1151 struct passwd *tempPwdPtr;
1152 char pwdbuffer[256];
1154 #ifdef HAVE_GETPWNAM_R
1155 #ifdef SOLARIS_GETPWUID
1156 tempPwdPtr = getpwnam_r(username, &pd, pwdbuffer, sizeof(pwdbuffer));
1157 #else // SOLARIS_GETPWUID
1158 getpwnam_r(username, &pd, pwdbuffer, sizeof pwdbuffer, &tempPwdPtr);
1159 #endif // SOLARIS_GETPWUID
1160 #else // HAVE_GETPWNAM_R
1162 #endif // HAVE_GETPWNAM_R
1163 if (tempPwdPtr != NULL) {
1164 extract_token(username, pd.pw_gecos, 0, ',', sizeof username);
1166 if (IsEmptyStr (username))
1168 safestrncpy(username, pd.pw_name, sizeof username);
1172 return (ERROR + NO_SUCH_USER);
1177 if ((config.c_auth_mode == AUTHMODE_LDAP) || (config.c_auth_mode == AUTHMODE_LDAP_AD)) {
1178 if (CtdlTryUserLDAP(username, NULL, 0, username, sizeof username, &uid) != 0) {
1179 return(ERROR + NO_SUCH_USER);
1182 #endif /* HAVE_LDAP */
1184 if ((retval = internal_create_user(username, &usbuf, uid)) != 0)
1188 * Give the user a private mailbox and a configuration room.
1189 * Make the latter an invisible system room.
1191 CtdlMailboxName(mailboxname, sizeof mailboxname, &usbuf, MAILROOM);
1192 CtdlCreateRoom(mailboxname, 5, "", 0, 1, 1, VIEW_MAILBOX);
1194 CtdlMailboxName(mailboxname, sizeof mailboxname, &usbuf, USERCONFIGROOM);
1195 CtdlCreateRoom(mailboxname, 5, "", 0, 1, 1, VIEW_BBS);
1196 if (CtdlGetRoomLock(&qrbuf, mailboxname) == 0) {
1197 qrbuf.QRflags2 |= QR2_SYSTEM;
1198 CtdlPutRoomLock(&qrbuf);
1201 /* Perform any create functions registered by server extensions */
1202 PerformUserHooks(&usbuf, EVT_NEWUSER);
1204 /* Everything below this line can be bypassed if administratively
1205 * creating a user, instead of doing self-service account creation
1209 /* Now become the user we just created */
1210 memcpy(&CC->user, &usbuf, sizeof(struct ctdluser));
1211 safestrncpy(CC->curr_user, username, sizeof CC->curr_user);
1214 /* Check to make sure we're still who we think we are */
1215 if (CtdlGetUser(&CC->user, CC->curr_user)) {
1216 return (ERROR + INTERNAL_ERROR);
1221 "New user account <%s> has been created, from host %s [%s].\n",
1226 CtdlAideMessage(buf, "User Creation Notice");
1227 CtdlLogPrintf(CTDL_NOTICE, "New user <%s> created\n", username);
1234 * cmd_newu() - create a new user account and log in as that user
1236 void cmd_newu(char *cmdbuf)
1241 if (config.c_auth_mode != AUTHMODE_NATIVE) {
1242 cprintf("%d This system does not use native mode authentication.\n",
1247 if (config.c_disable_newu) {
1248 cprintf("%d Self-service user account creation "
1249 "is disabled on this system.\n", ERROR + NOT_HERE);
1253 if (CC->logged_in) {
1254 cprintf("%d Already logged in.\n", ERROR + ALREADY_LOGGED_IN);
1258 cprintf("%d %s: Too many users are already online (maximum is %d)\n",
1259 ERROR + MAX_SESSIONS_EXCEEDED,
1260 config.c_nodename, config.c_maxsessions);
1262 extract_token(username, cmdbuf, 0, '|', sizeof username);
1266 if (IsEmptyStr(username)) {
1267 cprintf("%d You must supply a user name.\n", ERROR + USERNAME_REQUIRED);
1271 if ((!strcasecmp(username, "bbs")) ||
1272 (!strcasecmp(username, "new")) ||
1273 (!strcasecmp(username, "."))) {
1274 cprintf("%d '%s' is an invalid login name.\n", ERROR + ILLEGAL_VALUE, username);
1278 a = create_user(username, 1);
1281 logged_in_response();
1282 } else if (a == ERROR + ALREADY_EXISTS) {
1283 cprintf("%d '%s' already exists.\n",
1284 ERROR + ALREADY_EXISTS, username);
1286 } else if (a == ERROR + INTERNAL_ERROR) {
1287 cprintf("%d Internal error - user record disappeared?\n",
1288 ERROR + INTERNAL_ERROR);
1291 cprintf("%d unknown error\n", ERROR + INTERNAL_ERROR);
1297 * set password - back end api code
1299 void CtdlSetPassword(char *new_pw)
1301 CtdlGetUserLock(&CC->user, CC->curr_user);
1302 safestrncpy(CC->user.password, new_pw, sizeof(CC->user.password));
1303 CtdlPutUserLock(&CC->user);
1304 CtdlLogPrintf(CTDL_INFO, "Password changed for user <%s>\n", CC->curr_user);
1305 PerformSessionHooks(EVT_SETPASS);
1310 * set password - citadel protocol implementation
1312 void cmd_setp(char *new_pw)
1314 int generate_random_password = 0;
1316 if (CtdlAccessCheck(ac_logged_in)) {
1319 if ( (CC->user.uid != CTDLUID) && (CC->user.uid != (-1)) ) {
1320 cprintf("%d Not allowed. Use the 'passwd' command.\n", ERROR + NOT_HERE);
1323 if (CC->is_master) {
1324 cprintf("%d The master prefix password cannot be changed with this command.\n",
1329 if (!strcasecmp(new_pw, "GENERATE_RANDOM_PASSWORD")) {
1330 char random_password[17];
1331 generate_random_password = 1;
1332 snprintf(random_password, sizeof random_password, "%08lx%08lx", random(), random());
1333 CtdlSetPassword(random_password);
1334 cprintf("%d %s\n", CIT_OK, random_password);
1338 if (IsEmptyStr(new_pw)) {
1339 cprintf("%d Password unchanged.\n", CIT_OK);
1342 CtdlSetPassword(new_pw);
1343 cprintf("%d Password changed.\n", CIT_OK);
1349 * cmd_creu() - administratively create a new user account (do not log in to it)
1351 void cmd_creu(char *cmdbuf)
1356 struct ctdluser tmp;
1358 if (CtdlAccessCheck(ac_aide)) {
1362 extract_token(username, cmdbuf, 0, '|', sizeof username);
1363 extract_token(password, cmdbuf, 1, '|', sizeof password);
1369 if (IsEmptyStr(username)) {
1370 cprintf("%d You must supply a user name.\n", ERROR + USERNAME_REQUIRED);
1374 a = create_user(username, 0);
1377 if (!IsEmptyStr(password)) {
1378 CtdlGetUserLock(&tmp, username);
1379 safestrncpy(tmp.password, password, sizeof(tmp.password));
1380 CtdlPutUserLock(&tmp);
1382 cprintf("%d User '%s' created %s.\n", CIT_OK, username,
1383 (!IsEmptyStr(password)) ? "and password set" :
1384 "with no password");
1386 } else if (a == ERROR + ALREADY_EXISTS) {
1387 cprintf("%d '%s' already exists.\n", ERROR + ALREADY_EXISTS, username);
1389 } else if ( (config.c_auth_mode != AUTHMODE_NATIVE) && (a == ERROR + NO_SUCH_USER) ) {
1390 cprintf("%d User accounts are not created within Citadel in host authentication mode.\n",
1391 ERROR + NO_SUCH_USER);
1394 cprintf("%d An error occurred creating the user account.\n", ERROR + INTERNAL_ERROR);
1401 * get user parameters
1403 void cmd_getu(char *cmdbuf)
1406 if (CtdlAccessCheck(ac_logged_in))
1409 CtdlGetUser(&CC->user, CC->curr_user);
1410 cprintf("%d %d|%d|%d|\n",
1412 CC->user.USscreenwidth,
1413 CC->user.USscreenheight,
1414 (CC->user.flags & US_USER_SET)
1419 * set user parameters
1421 void cmd_setu(char *new_parms)
1423 if (CtdlAccessCheck(ac_logged_in))
1426 if (num_parms(new_parms) < 3) {
1427 cprintf("%d Usage error.\n", ERROR + ILLEGAL_VALUE);
1430 CtdlGetUserLock(&CC->user, CC->curr_user);
1431 CC->user.USscreenwidth = extract_int(new_parms, 0);
1432 CC->user.USscreenheight = extract_int(new_parms, 1);
1433 CC->user.flags = CC->user.flags & (~US_USER_SET);
1434 CC->user.flags = CC->user.flags |
1435 (extract_int(new_parms, 2) & US_USER_SET);
1437 CtdlPutUserLock(&CC->user);
1438 cprintf("%d Ok\n", CIT_OK);
1442 * set last read pointer
1444 void cmd_slrp(char *new_ptr)
1448 struct visit original_vbuf;
1450 if (CtdlAccessCheck(ac_logged_in)) {
1454 if (!strncasecmp(new_ptr, "highest", 7)) {
1455 newlr = CC->room.QRhighest;
1457 newlr = atol(new_ptr);
1460 CtdlGetUserLock(&CC->user, CC->curr_user);
1462 CtdlGetRelationship(&vbuf, &CC->user, &CC->room);
1463 memcpy(&original_vbuf, &vbuf, sizeof(struct visit));
1464 vbuf.v_lastseen = newlr;
1465 snprintf(vbuf.v_seen, sizeof vbuf.v_seen, "*:%ld", newlr);
1467 /* Only rewrite the record if it changed */
1468 if ( (vbuf.v_lastseen != original_vbuf.v_lastseen)
1469 || (strcmp(vbuf.v_seen, original_vbuf.v_seen)) ) {
1470 CtdlSetRelationship(&vbuf, &CC->user, &CC->room);
1473 CtdlPutUserLock(&CC->user);
1474 cprintf("%d %ld\n", CIT_OK, newlr);
1478 void cmd_seen(char *argbuf) {
1479 long target_msgnum = 0L;
1480 int target_setting = 0;
1482 if (CtdlAccessCheck(ac_logged_in)) {
1486 if (num_parms(argbuf) != 2) {
1487 cprintf("%d Invalid parameters\n", ERROR + ILLEGAL_VALUE);
1491 target_msgnum = extract_long(argbuf, 0);
1492 target_setting = extract_int(argbuf, 1);
1494 CtdlSetSeen(&target_msgnum, 1, target_setting,
1495 ctdlsetseen_seen, NULL, NULL);
1496 cprintf("%d OK\n", CIT_OK);
1500 void cmd_gtsn(char *argbuf) {
1503 if (CtdlAccessCheck(ac_logged_in)) {
1507 CtdlGetSeen(buf, ctdlsetseen_seen);
1508 cprintf("%d %s\n", CIT_OK, buf);
1513 * API function for cmd_invt_kick() and anything else that needs to
1514 * invite or kick out a user to/from a room.
1516 * Set iuser to the name of the user, and op to 1=invite or 0=kick
1518 int CtdlInvtKick(char *iuser, int op) {
1519 struct ctdluser USscratch;
1523 if (CtdlGetUser(&USscratch, iuser) != 0) {
1527 CtdlGetRelationship(&vbuf, &USscratch, &CC->room);
1529 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
1530 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
1533 vbuf.v_flags = vbuf.v_flags & ~V_ACCESS;
1534 vbuf.v_flags = vbuf.v_flags | V_FORGET | V_LOCKOUT;
1536 CtdlSetRelationship(&vbuf, &USscratch, &CC->room);
1538 /* post a message in Aide> saying what we just did */
1539 snprintf(bbb, sizeof bbb, "%s has been %s \"%s\" by %s.\n",
1541 ((op == 1) ? "invited to" : "kicked out of"),
1544 CtdlAideMessage(bbb,"User Admin Message");
1551 * INVT and KICK commands
1553 void cmd_invt_kick(char *iuser, int op) {
1556 * These commands are only allowed by aides, room aides,
1557 * and room namespace owners
1560 || (atol(CC->room.QRname) == CC->user.usernum) ) {
1561 /* access granted */
1564 cprintf("%d Higher access or room ownership required.\n",
1565 ERROR + HIGHER_ACCESS_REQUIRED);
1569 if (!strncasecmp(CC->room.QRname, config.c_baseroom,
1571 cprintf("%d Can't add/remove users from this room.\n",
1576 if (CtdlInvtKick(iuser, op) != 0) {
1577 cprintf("%d No such user.\n", ERROR + NO_SUCH_USER);
1581 cprintf("%d %s %s %s.\n",
1583 ((op == 1) ? "invited to" : "kicked out of"),
1588 void cmd_invt(char *iuser) {cmd_invt_kick(iuser, 1);}
1589 void cmd_kick(char *iuser) {cmd_invt_kick(iuser, 0);}
1592 * Forget (Zap) the current room (API call)
1593 * Returns 0 on success
1595 int CtdlForgetThisRoom(void) {
1598 /* On some systems, Aides are not allowed to forget rooms */
1599 if (is_aide() && (config.c_aide_zap == 0)
1600 && ((CC->room.QRflags & QR_MAILBOX) == 0) ) {
1604 CtdlGetUserLock(&CC->user, CC->curr_user);
1605 CtdlGetRelationship(&vbuf, &CC->user, &CC->room);
1607 vbuf.v_flags = vbuf.v_flags | V_FORGET;
1608 vbuf.v_flags = vbuf.v_flags & ~V_ACCESS;
1610 CtdlSetRelationship(&vbuf, &CC->user, &CC->room);
1611 CtdlPutUserLock(&CC->user);
1613 /* Return to the Lobby, so we don't end up in an undefined room */
1614 CtdlUserGoto(config.c_baseroom, 0, 0, NULL, NULL);
1621 * forget (Zap) the current room
1623 void cmd_forg(char *argbuf)
1626 if (CtdlAccessCheck(ac_logged_in)) {
1630 if (CtdlForgetThisRoom() == 0) {
1631 cprintf("%d Ok\n", CIT_OK);
1634 cprintf("%d You may not forget this room.\n", ERROR + NOT_HERE);
1639 * Get Next Unregistered User
1641 void cmd_gnur(char *argbuf)
1643 struct cdbdata *cdbus;
1644 struct ctdluser usbuf;
1646 if (CtdlAccessCheck(ac_aide)) {
1650 if ((CitControl.MMflags & MM_VALID) == 0) {
1651 cprintf("%d There are no unvalidated users.\n", CIT_OK);
1655 /* There are unvalidated users. Traverse the user database,
1656 * and return the first user we find that needs validation.
1658 cdb_rewind(CDB_USERS);
1659 while (cdbus = cdb_next_item(CDB_USERS), cdbus != NULL) {
1660 memset(&usbuf, 0, sizeof(struct ctdluser));
1661 memcpy(&usbuf, cdbus->ptr,
1662 ((cdbus->len > sizeof(struct ctdluser)) ?
1663 sizeof(struct ctdluser) : cdbus->len));
1665 if ((usbuf.flags & US_NEEDVALID)
1666 && (usbuf.axlevel > 0)) {
1667 cprintf("%d %s\n", MORE_DATA, usbuf.fullname);
1668 cdb_close_cursor(CDB_USERS);
1673 /* If we get to this point, there are no more unvalidated users.
1674 * Therefore we clear the "users need validation" flag.
1677 begin_critical_section(S_CONTROL);
1679 CitControl.MMflags = CitControl.MMflags & (~MM_VALID);
1681 end_critical_section(S_CONTROL);
1682 cprintf("%d *** End of registration.\n", CIT_OK);
1691 void cmd_vali(char *v_args)
1695 struct ctdluser userbuf;
1697 extract_token(user, v_args, 0, '|', sizeof user);
1698 newax = extract_int(v_args, 1);
1700 if (CtdlAccessCheck(ac_aide)) {
1704 if (CtdlGetUserLock(&userbuf, user) != 0) {
1705 cprintf("%d '%s' not found.\n", ERROR + NO_SUCH_USER, user);
1709 userbuf.axlevel = newax;
1710 userbuf.flags = (userbuf.flags & ~US_NEEDVALID);
1712 CtdlPutUserLock(&userbuf);
1714 /* If the access level was set to zero, delete the user */
1716 if (purge_user(user) == 0) {
1717 cprintf("%d %s Deleted.\n", CIT_OK, userbuf.fullname);
1721 cprintf("%d User '%s' validated.\n", CIT_OK, userbuf.fullname);
1727 * Traverse the user file...
1729 void ForEachUser(void (*CallBack) (struct ctdluser * EachUser, void *out_data),
1732 struct ctdluser usbuf;
1733 struct cdbdata *cdbus;
1735 cdb_rewind(CDB_USERS);
1737 while (cdbus = cdb_next_item(CDB_USERS), cdbus != NULL) {
1738 memset(&usbuf, 0, sizeof(struct ctdluser));
1739 memcpy(&usbuf, cdbus->ptr,
1740 ((cdbus->len > sizeof(struct ctdluser)) ?
1741 sizeof(struct ctdluser) : cdbus->len));
1743 (*CallBack) (&usbuf, in_data);
1749 * List one user (this works with cmd_list)
1751 void ListThisUser(struct ctdluser *usbuf, void *data)
1755 searchstring = (char *)data;
1756 if (bmstrcasestr(usbuf->fullname, searchstring) == NULL) {
1760 if (usbuf->axlevel > 0) {
1761 if ((CC->user.axlevel >= 6)
1762 || ((usbuf->flags & US_UNLISTED) == 0)
1763 || ((CC->internal_pgm))) {
1764 cprintf("%s|%d|%ld|%ld|%ld|%ld||\n",
1768 (long)usbuf->lastcall,
1776 * List users (searchstring may be empty to list all users)
1778 void cmd_list(char *cmdbuf)
1780 char searchstring[256];
1781 extract_token(searchstring, cmdbuf, 0, '|', sizeof searchstring);
1782 striplt(searchstring);
1783 cprintf("%d \n", LISTING_FOLLOWS);
1784 ForEachUser(ListThisUser, (void *)searchstring );
1792 * assorted info we need to check at login
1794 void cmd_chek(char *argbuf)
1800 if (CtdlAccessCheck(ac_logged_in)) {
1804 CtdlGetUser(&CC->user, CC->curr_user); /* no lock is needed here */
1805 if ((REGISCALL != 0) && ((CC->user.flags & US_REGIS) == 0))
1808 if (CC->user.axlevel >= 6) {
1810 if (CitControl.MMflags & MM_VALID)
1814 /* check for mail */
1815 mail = InitialMailCheck();
1817 cprintf("%d %d|%d|%d|%s|\n", CIT_OK, mail, regis, vali, CC->cs_inet_email);
1822 * check to see if a user exists
1824 void cmd_qusr(char *who)
1826 struct ctdluser usbuf;
1828 if (CtdlGetUser(&usbuf, who) == 0) {
1829 cprintf("%d %s\n", CIT_OK, usbuf.fullname);
1831 cprintf("%d No such user.\n", ERROR + NO_SUCH_USER);
1837 * Administrative Get User Parameters
1839 void cmd_agup(char *cmdbuf)
1841 struct ctdluser usbuf;
1842 char requested_user[128];
1844 if (CtdlAccessCheck(ac_aide)) {
1848 extract_token(requested_user, cmdbuf, 0, '|', sizeof requested_user);
1849 if (CtdlGetUser(&usbuf, requested_user) != 0) {
1850 cprintf("%d No such user.\n", ERROR + NO_SUCH_USER);
1853 cprintf("%d %s|%s|%u|%ld|%ld|%d|%ld|%ld|%d\n",
1860 (int) usbuf.axlevel,
1862 (long)usbuf.lastcall,
1869 * Administrative Set User Parameters
1871 void cmd_asup(char *cmdbuf)
1873 struct ctdluser usbuf;
1874 char requested_user[128];
1880 if (CtdlAccessCheck(ac_aide))
1883 extract_token(requested_user, cmdbuf, 0, '|', sizeof requested_user);
1884 if (CtdlGetUserLock(&usbuf, requested_user) != 0) {
1885 cprintf("%d No such user.\n", ERROR + NO_SUCH_USER);
1888 np = num_parms(cmdbuf);
1890 extract_token(usbuf.password, cmdbuf, 1, '|', sizeof usbuf.password);
1892 usbuf.flags = extract_int(cmdbuf, 2);
1894 usbuf.timescalled = extract_int(cmdbuf, 3);
1896 usbuf.posted = extract_int(cmdbuf, 4);
1898 newax = extract_int(cmdbuf, 5);
1899 if ((newax >= 0) && (newax <= 6)) {
1900 usbuf.axlevel = extract_int(cmdbuf, 5);
1904 usbuf.lastcall = extract_long(cmdbuf, 7);
1907 usbuf.USuserpurge = extract_int(cmdbuf, 8);
1909 CtdlPutUserLock(&usbuf);
1910 if (usbuf.axlevel == 0) {
1911 if (purge_user(requested_user) == 0) {
1917 snprintf(notify, SIZ,
1918 "User \"%s\" has been deleted by %s.\n",
1919 usbuf.fullname, CC->user.fullname);
1920 CtdlAideMessage(notify, "User Deletion Message");
1923 cprintf("%d Ok", CIT_OK);
1925 cprintf(" (%s deleted)", requested_user);
1932 * Check to see if the user who we just sent mail to is logged in. If yes,
1933 * bump the 'new mail' counter for their session. That enables them to
1934 * receive a new mail notification without having to hit the database.
1936 void BumpNewMailCounter(long which_user) {
1937 struct CitContext *ptr;
1939 begin_critical_section(S_SESSION_TABLE);
1941 for (ptr = ContextList; ptr != NULL; ptr = ptr->next) {
1942 if (ptr->user.usernum == which_user) {
1947 end_critical_section(S_SESSION_TABLE);
1952 * Count the number of new mail messages the user has
1956 int num_newmsgs = 0;
1958 num_newmsgs = CC->newmail;
1961 return (num_newmsgs);
1966 * Count the number of new mail messages the user has
1968 int InitialMailCheck()
1970 int num_newmsgs = 0;
1972 char mailboxname[ROOMNAMELEN];
1973 struct ctdlroom mailbox;
1975 struct cdbdata *cdbfr;
1976 long *msglist = NULL;
1979 CtdlMailboxName(mailboxname, sizeof mailboxname, &CC->user, MAILROOM);
1980 if (CtdlGetRoom(&mailbox, mailboxname) != 0)
1982 CtdlGetRelationship(&vbuf, &CC->user, &mailbox);
1984 cdbfr = cdb_fetch(CDB_MSGLISTS, &mailbox.QRnumber, sizeof(long));
1986 if (cdbfr != NULL) {
1987 msglist = malloc(cdbfr->len);
1988 memcpy(msglist, cdbfr->ptr, cdbfr->len);
1989 num_msgs = cdbfr->len / sizeof(long);
1993 for (a = 0; a < num_msgs; ++a) {
1994 if (msglist[a] > 0L) {
1995 if (msglist[a] > vbuf.v_lastseen) {
2000 if (msglist != NULL)
2003 return (num_newmsgs);
2009 * Set the preferred view for the current user/room combination
2011 void cmd_view(char *cmdbuf) {
2015 if (CtdlAccessCheck(ac_logged_in)) {
2019 requested_view = extract_int(cmdbuf, 0);
2021 CtdlGetRelationship(&vbuf, &CC->user, &CC->room);
2022 vbuf.v_view = requested_view;
2023 CtdlSetRelationship(&vbuf, &CC->user, &CC->room);
2025 cprintf("%d ok\n", CIT_OK);
2032 void cmd_renu(char *cmdbuf)
2035 char oldname[USERNAME_SIZE];
2036 char newname[USERNAME_SIZE];
2038 if (CtdlAccessCheck(ac_aide)) {
2042 extract_token(oldname, cmdbuf, 0, '|', sizeof oldname);
2043 extract_token(newname, cmdbuf, 1, '|', sizeof newname);
2045 retcode = rename_user(oldname, newname);
2048 cprintf("%d '%s' has been renamed to '%s'.\n", CIT_OK, oldname, newname);
2050 case RENAMEUSER_LOGGED_IN:
2051 cprintf("%d '%s' is currently logged in and cannot be renamed.\n",
2052 ERROR + ALREADY_LOGGED_IN , oldname);
2054 case RENAMEUSER_NOT_FOUND:
2055 cprintf("%d '%s' does not exist.\n", ERROR + NO_SUCH_USER, oldname);
2057 case RENAMEUSER_ALREADY_EXISTS:
2058 cprintf("%d A user named '%s' already exists.\n", ERROR + ALREADY_EXISTS, newname);
2062 cprintf("%d An unknown error occurred.\n", ERROR);
2067 /*****************************************************************************/
2068 /* MODULE INITIALIZATION STUFF */
2069 /*****************************************************************************/
2072 CTDL_MODULE_INIT(user_ops)
2074 CtdlRegisterProtoHook(cmd_user, "USER", "Autoconverted. TODO: document me.");
2075 CtdlRegisterProtoHook(cmd_pass, "PASS", "Autoconverted. TODO: document me.");
2076 CtdlRegisterProtoHook(cmd_creu, "CREU", "Autoconverted. TODO: document me.");
2077 CtdlRegisterProtoHook(cmd_setp, "SETP", "Autoconverted. TODO: document me.");
2078 CtdlRegisterProtoHook(cmd_getu, "GETU", "Autoconverted. TODO: document me.");
2079 CtdlRegisterProtoHook(cmd_setu, "SETU", "Autoconverted. TODO: document me.");
2080 CtdlRegisterProtoHook(cmd_slrp, "SLRP", "Autoconverted. TODO: document me.");
2081 CtdlRegisterProtoHook(cmd_invt, "INVT", "Autoconverted. TODO: document me.");
2082 CtdlRegisterProtoHook(cmd_kick, "KICK", "Autoconverted. TODO: document me.");
2083 CtdlRegisterProtoHook(cmd_forg, "FORG", "Autoconverted. TODO: document me.");
2084 CtdlRegisterProtoHook(cmd_gnur, "GNUR", "Autoconverted. TODO: document me.");
2085 CtdlRegisterProtoHook(cmd_vali, "VALI", "Autoconverted. TODO: document me.");
2086 CtdlRegisterProtoHook(cmd_list, "LIST", "Autoconverted. TODO: document me.");
2087 CtdlRegisterProtoHook(cmd_chek, "CHEK", "Autoconverted. TODO: document me.");
2088 CtdlRegisterProtoHook(cmd_qusr, "QUSR", "Autoconverted. TODO: document me.");
2089 CtdlRegisterProtoHook(cmd_agup, "AGUP", "Autoconverted. TODO: document me.");
2090 CtdlRegisterProtoHook(cmd_asup, "ASUP", "Autoconverted. TODO: document me.");
2091 CtdlRegisterProtoHook(cmd_seen, "SEEN", "Autoconverted. TODO: document me.");
2092 CtdlRegisterProtoHook(cmd_gtsn, "GTSN", "Autoconverted. TODO: document me.");
2093 CtdlRegisterProtoHook(cmd_view, "VIEW", "Autoconverted. TODO: document me.");
2094 CtdlRegisterProtoHook(cmd_renu, "RENU", "Autoconverted. TODO: document me.");
2095 CtdlRegisterProtoHook(cmd_newu, "NEWU", "Autoconverted. TODO: document me.");
2096 /* return our Subversion id for the Log */