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[])
89 char usernamekey[USERNAME_SIZE];
90 struct cdbdata *cdbus;
93 memset(usbuf, 0, sizeof(struct ctdluser));
96 makeuserkey(usernamekey, name);
97 cdbus = cdb_fetch(CDB_USERS, usernamekey, strlen(usernamekey));
99 if (cdbus == NULL) { /* user not found */
103 memcpy(usbuf, cdbus->ptr,
104 ((cdbus->len > sizeof(struct ctdluser)) ?
105 sizeof(struct ctdluser) : cdbus->len));
114 * lgetuser() - same as getuser() but locks the record
116 int lgetuser(struct ctdluser *usbuf, char *name)
120 retcode = getuser(usbuf, name);
122 begin_critical_section(S_USERS);
129 * putuser() - write user buffer into the correct place on disk
131 void putuser(struct ctdluser *usbuf)
133 char usernamekey[USERNAME_SIZE];
135 makeuserkey(usernamekey, usbuf->fullname);
137 usbuf->version = REV_LEVEL;
139 usernamekey, strlen(usernamekey),
140 usbuf, sizeof(struct ctdluser));
146 * lputuser() - same as putuser() but locks the record
148 void lputuser(struct ctdluser *usbuf)
151 end_critical_section(S_USERS);
156 * rename_user() - this is tricky because the user's display name is the database key
158 * Returns 0 on success or nonzero if there was an error...
161 int rename_user(char *oldname, char *newname) {
162 struct CitContext *cptr;
163 int retcode = RENAMEUSER_OK;
164 struct ctdluser usbuf;
166 char oldnamekey[USERNAME_SIZE];
167 char newnamekey[USERNAME_SIZE];
169 /* We cannot rename a user who is currently logged in */
170 for (cptr = ContextList; cptr != NULL; cptr = cptr->next) {
171 if (!strcasecmp(cptr->user.fullname, oldname)) {
172 return(RENAMEUSER_LOGGED_IN);
176 /* Create the database keys... */
177 makeuserkey(oldnamekey, oldname);
178 makeuserkey(newnamekey, newname);
180 /* Lock up and get going */
181 begin_critical_section(S_USERS);
183 if (getuser(&usbuf, newname) == 0) {
184 retcode = RENAMEUSER_ALREADY_EXISTS;
188 if (getuser(&usbuf, oldname) != 0) {
189 retcode = RENAMEUSER_NOT_FOUND;
192 else { /* Sanity checks succeeded. Now rename the user. */
193 if (usbuf.usernum == 0)
195 CtdlLogPrintf (CTDL_DEBUG, "Can not rename user \"Citadel\".\n");
196 retcode = RENAMEUSER_NOT_FOUND;
198 CtdlLogPrintf(CTDL_DEBUG, "Renaming <%s> to <%s>\n", oldname, newname);
199 cdb_delete(CDB_USERS, oldnamekey, strlen(oldnamekey));
200 safestrncpy(usbuf.fullname, newname, sizeof usbuf.fullname);
202 cdb_store(CDB_USERSBYNUMBER, &usbuf.usernum, sizeof(long),
203 usbuf.fullname, strlen(usbuf.fullname)+1 );
205 retcode = RENAMEUSER_OK;
211 end_critical_section(S_USERS);
218 * Index-generating function used by Ctdl[Get|Set]Relationship
220 int GenerateRelationshipIndex(char *IndexBuf,
232 TheIndex.iRoomID = RoomID;
233 TheIndex.iRoomGen = RoomGen;
234 TheIndex.iUserID = UserID;
236 memcpy(IndexBuf, &TheIndex, sizeof(TheIndex));
237 return (sizeof(TheIndex));
243 * Back end for CtdlSetRelationship()
245 void put_visit(struct visit *newvisit)
250 memset (IndexBuf, 0, sizeof (IndexBuf));
251 /* Generate an index */
252 IndexLen = GenerateRelationshipIndex(IndexBuf,
255 newvisit->v_usernum);
257 /* Store the record */
258 cdb_store(CDB_VISIT, IndexBuf, IndexLen,
259 newvisit, sizeof(struct visit)
267 * Define a relationship between a user and a room
269 void CtdlSetRelationship(struct visit *newvisit,
270 struct ctdluser *rel_user,
271 struct ctdlroom *rel_room)
275 /* We don't use these in Citadel because they're implicit by the
276 * index, but they must be present if the database is exported.
278 newvisit->v_roomnum = rel_room->QRnumber;
279 newvisit->v_roomgen = rel_room->QRgen;
280 newvisit->v_usernum = rel_user->usernum;
286 * Locate a relationship between a user and a room
288 void CtdlGetRelationship(struct visit *vbuf,
289 struct ctdluser *rel_user,
290 struct ctdlroom *rel_room)
295 struct cdbdata *cdbvisit;
297 /* Generate an index */
298 IndexLen = GenerateRelationshipIndex(IndexBuf,
303 /* Clear out the buffer */
304 memset(vbuf, 0, sizeof(struct visit));
306 cdbvisit = cdb_fetch(CDB_VISIT, IndexBuf, IndexLen);
307 if (cdbvisit != NULL) {
308 memcpy(vbuf, cdbvisit->ptr,
309 ((cdbvisit->len > sizeof(struct visit)) ?
310 sizeof(struct visit) : cdbvisit->len));
314 /* If this is the first time the user has seen this room,
315 * set the view to be the default for the room.
317 vbuf->v_view = rel_room->QRdefaultview;
320 /* Set v_seen if necessary */
321 if (vbuf->v_seen[0] == 0) {
322 snprintf(vbuf->v_seen, sizeof vbuf->v_seen, "*:%ld", vbuf->v_lastseen);
327 void MailboxName(char *buf, size_t n, const struct ctdluser *who, const char *prefix)
329 snprintf(buf, n, "%010ld.%s", who->usernum, prefix);
334 * Is the user currently logged in an Aide?
338 if (CC->user.axlevel >= 6)
346 * Is the user currently logged in an Aide *or* the room aide for this room?
348 int is_room_aide(void)
351 if (!CC->logged_in) {
355 if ((CC->user.axlevel >= 6)
356 || (CC->room.QRroomaide == CC->user.usernum)) {
364 * getuserbynumber() - get user by number
365 * returns 0 if user was found
367 * Note: fetching a user this way requires one additional database operation.
369 int getuserbynumber(struct ctdluser *usbuf, long number)
371 struct cdbdata *cdbun;
374 cdbun = cdb_fetch(CDB_USERSBYNUMBER, &number, sizeof(long));
376 CtdlLogPrintf(CTDL_INFO, "User %ld not found\n", number);
380 CtdlLogPrintf(CTDL_INFO, "User %ld maps to %s\n", number, cdbun->ptr);
381 r = getuser(usbuf, cdbun->ptr);
389 * Helper function for rebuild_usersbynumber()
391 void rebuild_ubn_for_user(struct ctdluser *usbuf, void *data) {
394 struct ubnlist *next;
395 char username[USERNAME_SIZE];
399 static struct ubnlist *u = NULL;
400 struct ubnlist *ptr = NULL;
402 /* Lazy programming here. Call this function as a ForEachUser backend
403 * in order to queue up the room names, or call it with a null user
404 * to make it do the processing.
407 ptr = (struct ubnlist *) malloc(sizeof (struct ubnlist));
408 if (ptr == NULL) return;
410 ptr->usernum = usbuf->usernum;
411 safestrncpy(ptr->username, usbuf->fullname, sizeof ptr->username);
418 CtdlLogPrintf(CTDL_DEBUG, "Rebuilding usersbynumber index %10ld : %s\n",
419 u->usernum, u->username);
420 cdb_store(CDB_USERSBYNUMBER, &u->usernum, sizeof(long), u->username, strlen(u->username)+1);
431 * Rebuild the users-by-number index
433 void rebuild_usersbynumber(void) {
434 cdb_trunc(CDB_USERSBYNUMBER); /* delete the old indices */
435 ForEachUser(rebuild_ubn_for_user, NULL); /* enumerate the users */
436 rebuild_ubn_for_user(NULL, NULL); /* and index them */
442 * getuserbyuid() - get user by system uid (for PAM mode authentication)
443 * returns 0 if user was found
445 * WARNING: don't use this function unless you absolutely have to. It does
446 * a sequential search and therefore is computationally expensive.
448 int getuserbyuid(struct ctdluser *usbuf, uid_t number)
450 struct cdbdata *cdbus;
452 cdb_rewind(CDB_USERS);
454 while (cdbus = cdb_next_item(CDB_USERS), cdbus != NULL) {
455 memset(usbuf, 0, sizeof(struct ctdluser));
456 memcpy(usbuf, cdbus->ptr,
457 ((cdbus->len > sizeof(struct ctdluser)) ?
458 sizeof(struct ctdluser) : cdbus->len));
460 if (usbuf->uid == number) {
461 cdb_close_cursor(CDB_USERS);
469 * Back end for cmd_user() and its ilk
471 * NOTE: "authname" should only be used if we are attempting to use the "master user" feature
473 int CtdlLoginExistingUser(char *authname, char *trythisname)
478 CtdlLogPrintf(9, "CtdlLoginExistingUser(%s, %s)\n", authname, trythisname);
480 if ((CC->logged_in)) {
481 return login_already_logged_in;
484 if (trythisname == NULL) return login_not_found;
486 if (!strncasecmp(trythisname, "SYS_", 4))
488 CtdlLogPrintf(CTDL_DEBUG, "System user \"%s\" is not allowed to log in.\n", trythisname);
489 return login_not_found;
492 /* If a "master user" is defined, handle its authentication if specified */
494 if (strlen(config.c_master_user) > 0) if (strlen(config.c_master_pass) > 0) if (authname) {
495 if (!strcasecmp(authname, config.c_master_user)) {
500 /* Continue attempting user validation... */
501 safestrncpy(username, trythisname, USERNAME_SIZE);
504 if (IsEmptyStr(username)) {
505 return login_not_found;
508 if (config.c_auth_mode == AUTHMODE_HOST) {
513 struct passwd *tempPwdPtr;
516 CtdlLogPrintf(CTDL_DEBUG, "asking host about <%s>\n", username);
517 #ifdef HAVE_GETPWNAM_R
518 #ifdef SOLARIS_GETPWUID
519 CtdlLogPrintf(CTDL_DEBUG, "Calling getpwnam_r()\n");
520 tempPwdPtr = getpwnam_r(username, &pd, pwdbuffer, sizeof pwdbuffer);
521 #else // SOLARIS_GETPWUID
522 CtdlLogPrintf(CTDL_DEBUG, "Calling getpwnam_r()\n");
523 getpwnam_r(username, &pd, pwdbuffer, sizeof pwdbuffer, &tempPwdPtr);
524 #endif // SOLARIS_GETPWUID
525 #else // HAVE_GETPWNAM_R
526 CtdlLogPrintf(CTDL_DEBUG, "SHOULD NEVER GET HERE!!!\n");
528 #endif // HAVE_GETPWNAM_R
529 if (tempPwdPtr == NULL) {
530 CtdlLogPrintf(CTDL_DEBUG, "no such user <%s>\n", username);
531 return login_not_found;
534 /* Locate the associated Citadel account.
535 * If not found, make one attempt to create it.
537 found_user = getuserbyuid(&CC->user, pd.pw_uid);
538 CtdlLogPrintf(CTDL_DEBUG, "found it: uid=%ld, gecos=%s here: %d\n",
539 (long)pd.pw_uid, pd.pw_gecos, found_user);
540 if (found_user != 0) {
541 create_user(username, 0);
542 found_user = getuserbyuid(&CC->user, pd.pw_uid);
548 else if ((config.c_auth_mode == AUTHMODE_LDAP) || (config.c_auth_mode == AUTHMODE_LDAP_AD)) {
556 found_user = CtdlTryUserLDAP(username, ldap_dn, sizeof ldap_dn, ldap_cn, sizeof ldap_cn, &ldap_uid);
557 if (found_user != 0) {
558 return login_not_found;
561 found_user = getuserbyuid(&CC->user, ldap_uid);
562 if (found_user != 0) {
563 create_user(trythisname, 0);
564 found_user = getuserbyuid(&CC->user, ldap_uid);
567 if (found_user == 0) {
568 if (CC->ldap_dn != NULL) free(CC->ldap_dn);
569 CC->ldap_dn = strdup(ldap_dn);
576 /* native auth mode */
578 struct recptypes *valid = NULL;
580 /* First, try to log in as if the supplied name is a display name */
581 found_user = getuser(&CC->user, username);
583 /* If that didn't work, try to log in as if the supplied name
584 * is an e-mail address
586 if (found_user != 0) {
587 valid = validate_recipients(username, NULL, 0);
589 if (valid->num_local == 1) {
590 found_user = getuser(&CC->user, valid->recp_local);
592 free_recipients(valid);
597 /* Did we find something? */
598 if (found_user == 0) {
599 if (((CC->nologin)) && (CC->user.axlevel < 6)) {
600 return login_too_many_users;
602 safestrncpy(CC->curr_user, CC->user.fullname,
603 sizeof CC->curr_user);
607 return login_not_found;
615 void cmd_user(char *cmdbuf)
620 CtdlLogPrintf(CTDL_DEBUG, "cmd_user(%s)\n", cmdbuf);
621 extract_token(username, cmdbuf, 0, '|', sizeof username);
622 CtdlLogPrintf(CTDL_DEBUG, "username: %s\n", username);
624 CtdlLogPrintf(CTDL_DEBUG, "username: %s\n", username);
626 a = CtdlLoginExistingUser(NULL, username);
628 case login_already_logged_in:
629 cprintf("%d Already logged in.\n", ERROR + ALREADY_LOGGED_IN);
631 case login_too_many_users:
633 "Too many users are already online "
635 ERROR + MAX_SESSIONS_EXCEEDED,
636 config.c_nodename, config.c_maxsessions);
639 cprintf("%d Password required for %s\n",
640 MORE_DATA, CC->curr_user);
642 case login_not_found:
643 cprintf("%d %s not found.\n", ERROR + NO_SUCH_USER, username);
646 cprintf("%d Internal error\n", ERROR + INTERNAL_ERROR);
653 * session startup code which is common to both cmd_pass() and cmd_newu()
658 CtdlLogPrintf(CTDL_NOTICE, "<%s> logged in\n", CC->curr_user);
660 lgetuser(&CC->user, CC->curr_user);
661 ++(CC->user.timescalled);
662 CC->previous_login = CC->user.lastcall;
663 time(&CC->user.lastcall);
665 /* If this user's name is the name of the system administrator
666 * (as specified in setup), automatically assign access level 6.
668 if (!strcasecmp(CC->user.fullname, config.c_sysadm)) {
669 CC->user.axlevel = 6;
672 /* If we're authenticating off the host system, automatically give
673 * root the highest level of access.
675 if (config.c_auth_mode == AUTHMODE_HOST) {
676 if (CC->user.uid == 0) {
677 CC->user.axlevel = 6;
684 * Populate CC->cs_inet_email with a default address. This will be
685 * overwritten with the user's directory address, if one exists, when
686 * the vCard module's login hook runs.
688 snprintf(CC->cs_inet_email, sizeof CC->cs_inet_email, "%s@%s",
689 CC->user.fullname, config.c_fqdn);
690 convert_spaces_to_underscores(CC->cs_inet_email);
692 /* Create any personal rooms required by the system.
693 * (Technically, MAILROOM should be there already, but just in case...)
695 create_room(MAILROOM, 4, "", 0, 1, 0, VIEW_MAILBOX);
696 create_room(SENTITEMS, 4, "", 0, 1, 0, VIEW_MAILBOX);
697 create_room(USERTRASHROOM, 4, "", 0, 1, 0, VIEW_MAILBOX);
698 /* create_room(USERDRAFTROOM, 4, "", 0, 1, 0, VIEW_MAILBOX); temporarily disabled for 7.60 */
700 /* Run any startup routines registered by loadable modules */
701 PerformSessionHooks(EVT_LOGIN);
703 /* Enter the lobby */
704 usergoto(config.c_baseroom, 0, 0, NULL, NULL);
708 void logged_in_response(void)
710 cprintf("%d %s|%d|%ld|%ld|%u|%ld|%ld\n",
711 CIT_OK, CC->user.fullname, CC->user.axlevel,
712 CC->user.timescalled, CC->user.posted,
713 CC->user.flags, CC->user.usernum,
720 * misc things to be taken care of when a user is logged out
724 struct CitContext *CCC = CC; /* CachedCitContext - performance boost */
726 * If there is a download in progress, abort it.
728 if (CCC->download_fp != NULL) {
729 fclose(CCC->download_fp);
730 CCC->download_fp = NULL;
734 * If there is an upload in progress, abort it.
736 if (CCC->upload_fp != NULL) {
741 * If we were talking to a network node, we're not anymore...
743 if (!IsEmptyStr(CCC->net_node)) {
744 network_talking_to(CCC->net_node, NTT_REMOVE);
747 /* Run any hooks registered by modules... */
748 PerformSessionHooks(EVT_LOGOUT);
751 * Clear out some session data. Most likely, the CitContext for this
752 * session is about to get nuked when the session disconnects, but
753 * since it's possible to log in again without reconnecting, we cannot
754 * make that assumption.
756 strcpy(CCC->fake_username, "");
757 strcpy(CCC->fake_hostname, "");
758 strcpy(CCC->fake_roomname, "");
761 /* Check to see if the user was deleted whilst logged in and purge them if necessary */
762 if ((CCC->user.axlevel == 0) && (CCC->user.usernum))
763 purge_user(CCC->user.fullname);
765 /* Free any output buffers */
770 * Validate a password on the host unix system by talking to the chkpwd daemon
772 static int validpw(uid_t uid, const char *pass)
777 if (IsEmptyStr(pass)) {
778 CtdlLogPrintf(CTDL_DEBUG, "refusing to check empty password for uid=%d using chkpwd...\n", uid);
782 CtdlLogPrintf(CTDL_DEBUG, "Validating password for uid=%d using chkpwd...\n", uid);
784 begin_critical_section(S_CHKPWD);
785 rv = write(chkpwd_write_pipe[1], &uid, sizeof(uid_t));
786 rv = write(chkpwd_write_pipe[1], pass, 256);
787 rv = read(chkpwd_read_pipe[0], buf, 4);
788 end_critical_section(S_CHKPWD);
790 if (!strncmp(buf, "PASS", 4)) {
791 CtdlLogPrintf(CTDL_DEBUG, "...pass\n");
795 CtdlLogPrintf(CTDL_DEBUG, "...fail\n");
800 * Start up the chkpwd daemon so validpw() has something to talk to
802 void start_chkpwd_daemon(void) {
804 struct stat filestats;
807 CtdlLogPrintf(CTDL_DEBUG, "Starting chkpwd daemon for host authentication mode\n");
809 if ((stat(file_chkpwd, &filestats)==-1) ||
810 (filestats.st_size==0)){
811 printf("didn't find chkpwd daemon in %s: %s\n", file_chkpwd, strerror(errno));
814 if (pipe(chkpwd_write_pipe) != 0) {
815 CtdlLogPrintf(CTDL_EMERG, "Unable to create pipe for chkpwd daemon: %s\n", strerror(errno));
818 if (pipe(chkpwd_read_pipe) != 0) {
819 CtdlLogPrintf(CTDL_EMERG, "Unable to create pipe for chkpwd daemon: %s\n", strerror(errno));
824 if (chkpwd_pid < 0) {
825 CtdlLogPrintf(CTDL_EMERG, "Unable to fork chkpwd daemon: %s\n", strerror(errno));
828 if (chkpwd_pid == 0) {
829 CtdlLogPrintf(CTDL_DEBUG, "Now calling dup2() write\n");
830 dup2(chkpwd_write_pipe[0], 0);
831 CtdlLogPrintf(CTDL_DEBUG, "Now calling dup2() write\n");
832 dup2(chkpwd_read_pipe[1], 1);
833 CtdlLogPrintf(CTDL_DEBUG, "Now closing stuff\n");
834 for (i=2; i<256; ++i) close(i);
835 CtdlLogPrintf(CTDL_DEBUG, "Now calling execl(%s)\n", file_chkpwd);
836 execl(file_chkpwd, file_chkpwd, NULL);
837 CtdlLogPrintf(CTDL_EMERG, "Unable to exec chkpwd daemon: %s\n", strerror(errno));
844 int CtdlTryPassword(char *password)
848 if ((CC->logged_in)) {
849 CtdlLogPrintf(CTDL_WARNING, "CtdlTryPassword: already logged in\n");
850 return pass_already_logged_in;
852 if (!strcmp(CC->curr_user, NLI)) {
853 CtdlLogPrintf(CTDL_WARNING, "CtdlTryPassword: no user selected\n");
856 if (getuser(&CC->user, CC->curr_user)) {
857 CtdlLogPrintf(CTDL_ERR, "CtdlTryPassword: internal error\n");
858 return pass_internal_error;
860 if (password == NULL) {
861 CtdlLogPrintf(CTDL_INFO, "CtdlTryPassword: NULL password string supplied\n");
862 return pass_wrong_password;
867 code = strcmp(password, config.c_master_pass);
870 else if (config.c_auth_mode == AUTHMODE_HOST) {
874 if (validpw(CC->user.uid, password)) {
878 * sooper-seekrit hack: populate the password field in the
879 * citadel database with the password that the user typed,
880 * if it's correct. This allows most sites to convert from
881 * host auth to native auth if they want to. If you think
882 * this is a security hazard, comment it out.
885 lgetuser(&CC->user, CC->curr_user);
886 safestrncpy(CC->user.password, password, sizeof CC->user.password);
890 * (sooper-seekrit hack ends here)
900 else if ((config.c_auth_mode == AUTHMODE_LDAP) || (config.c_auth_mode == AUTHMODE_LDAP_AD)) {
904 if ((CC->ldap_dn) && (!CtdlTryPasswordLDAP(CC->ldap_dn, password))) {
915 /* native auth mode */
918 strproc(CC->user.password);
919 code = strcasecmp(CC->user.password, password);
921 strproc(CC->user.password);
922 code = strcasecmp(CC->user.password, password);
929 CtdlLogPrintf(CTDL_WARNING, "Bad password specified for <%s>\n", CC->curr_user);
930 return pass_wrong_password;
935 void cmd_pass(char *buf)
940 memset(password, 0, sizeof(password));
941 extract_token(password, buf, 0, '|', sizeof password);
942 a = CtdlTryPassword(password);
945 case pass_already_logged_in:
946 cprintf("%d Already logged in.\n", ERROR + ALREADY_LOGGED_IN);
949 cprintf("%d You must send a name with USER first.\n",
950 ERROR + USERNAME_REQUIRED);
952 case pass_wrong_password:
953 cprintf("%d Wrong password.\n", ERROR + PASSWORD_REQUIRED);
956 logged_in_response();
964 * Delete a user record *and* all of its related resources.
966 int purge_user(char pname[])
969 struct ctdluser usbuf;
970 char usernamekey[USERNAME_SIZE];
971 struct CitContext *ccptr;
972 int user_is_logged_in = 0;
974 makeuserkey(usernamekey, pname);
976 /* If the name is empty we can't find them in the DB any way so just return */
977 if (IsEmptyStr(pname))
978 return (ERROR + NO_SUCH_USER);
980 if (getuser(&usbuf, pname) != 0) {
981 CtdlLogPrintf(CTDL_ERR, "Cannot purge user <%s> - not found\n", pname);
982 return (ERROR + NO_SUCH_USER);
984 /* Don't delete a user who is currently logged in. Instead, just
985 * set the access level to 0, and let the account get swept up
986 * during the next purge.
988 user_is_logged_in = 0;
989 begin_critical_section(S_SESSION_TABLE);
990 for (ccptr = ContextList; ccptr != NULL; ccptr = ccptr->next) {
991 if (ccptr->user.usernum == usbuf.usernum) {
992 user_is_logged_in = 1;
995 end_critical_section(S_SESSION_TABLE);
996 if (user_is_logged_in == 1) {
997 CtdlLogPrintf(CTDL_WARNING, "User <%s> is logged in; not deleting.\n", pname);
1002 CtdlLogPrintf(CTDL_NOTICE, "Deleting user <%s>\n", pname);
1004 /* Perform any purge functions registered by server extensions */
1005 PerformUserHooks(&usbuf, EVT_PURGEUSER);
1007 /* delete any existing user/room relationships */
1008 cdb_delete(CDB_VISIT, &usbuf.usernum, sizeof(long));
1010 /* delete the users-by-number index record */
1011 cdb_delete(CDB_USERSBYNUMBER, &usbuf.usernum, sizeof(long));
1013 /* delete the userlog entry */
1014 cdb_delete(CDB_USERS, usernamekey, strlen(usernamekey));
1016 /* remove the user's bio file */
1024 /* remove the user's picture */
1036 int internal_create_user (char *username, struct ctdluser *usbuf, uid_t uid)
1038 if (!getuser(usbuf, username)) {
1039 return (ERROR + ALREADY_EXISTS);
1042 /* Go ahead and initialize a new user record */
1043 memset(usbuf, 0, sizeof(struct ctdluser));
1044 safestrncpy(usbuf->fullname, username, sizeof usbuf->fullname);
1045 strcpy(usbuf->password, "");
1048 /* These are the default flags on new accounts */
1049 usbuf->flags = US_LASTOLD | US_DISAPPEAR | US_PAGINATOR | US_FLOORS;
1051 usbuf->timescalled = 0;
1053 usbuf->axlevel = config.c_initax;
1054 usbuf->USscreenwidth = 80;
1055 usbuf->USscreenheight = 24;
1056 usbuf->lastcall = time(NULL);
1058 /* fetch a new user number */
1059 usbuf->usernum = get_new_user_number();
1061 /* add user to the database */
1063 cdb_store(CDB_USERSBYNUMBER, &usbuf->usernum, sizeof(long), usbuf->fullname, strlen(usbuf->fullname)+1);
1071 * create_user() - back end processing to create a new user
1073 * Set 'newusername' to the desired account name.
1074 * Set 'become_user' to nonzero if this is self-service account creation and we want
1075 * to actually log in as the user we just created, otherwise set it to 0.
1077 int create_user(char *newusername, int become_user)
1079 struct ctdluser usbuf;
1080 struct ctdlroom qrbuf;
1082 char mailboxname[ROOMNAMELEN];
1088 safestrncpy(username, newusername, sizeof username);
1092 if (config.c_auth_mode == AUTHMODE_HOST) {
1094 /* host auth mode */
1097 struct passwd *tempPwdPtr;
1098 char pwdbuffer[256];
1100 #ifdef HAVE_GETPWNAM_R
1101 #ifdef SOLARIS_GETPWUID
1102 tempPwdPtr = getpwnam_r(username, &pd, pwdbuffer, sizeof(pwdbuffer));
1103 #else // SOLARIS_GETPWUID
1104 getpwnam_r(username, &pd, pwdbuffer, sizeof pwdbuffer, &tempPwdPtr);
1105 #endif // SOLARIS_GETPWUID
1106 #else // HAVE_GETPWNAM_R
1108 #endif // HAVE_GETPWNAM_R
1109 if (tempPwdPtr != NULL) {
1110 extract_token(username, pd.pw_gecos, 0, ',', sizeof username);
1112 if (IsEmptyStr (username))
1114 safestrncpy(username, pd.pw_name, sizeof username);
1118 return (ERROR + NO_SUCH_USER);
1123 if ((config.c_auth_mode == AUTHMODE_LDAP) || (config.c_auth_mode == AUTHMODE_LDAP_AD)) {
1124 if (CtdlTryUserLDAP(username, NULL, 0, username, sizeof username, &uid) != 0) {
1125 return(ERROR + NO_SUCH_USER);
1128 #endif /* HAVE_LDAP */
1130 if ((retval = internal_create_user(username, &usbuf, uid)) != 0)
1134 * Give the user a private mailbox and a configuration room.
1135 * Make the latter an invisible system room.
1137 MailboxName(mailboxname, sizeof mailboxname, &usbuf, MAILROOM);
1138 create_room(mailboxname, 5, "", 0, 1, 1, VIEW_MAILBOX);
1140 MailboxName(mailboxname, sizeof mailboxname, &usbuf, USERCONFIGROOM);
1141 create_room(mailboxname, 5, "", 0, 1, 1, VIEW_BBS);
1142 if (lgetroom(&qrbuf, mailboxname) == 0) {
1143 qrbuf.QRflags2 |= QR2_SYSTEM;
1147 /* Perform any create functions registered by server extensions */
1148 PerformUserHooks(&usbuf, EVT_NEWUSER);
1150 /* Everything below this line can be bypassed if administratively
1151 * creating a user, instead of doing self-service account creation
1155 /* Now become the user we just created */
1156 memcpy(&CC->user, &usbuf, sizeof(struct ctdluser));
1157 safestrncpy(CC->curr_user, username, sizeof CC->curr_user);
1160 /* Check to make sure we're still who we think we are */
1161 if (getuser(&CC->user, CC->curr_user)) {
1162 return (ERROR + INTERNAL_ERROR);
1167 "New user account <%s> has been created, from host %s [%s].\n",
1172 aide_message(buf, "User Creation Notice");
1173 CtdlLogPrintf(CTDL_NOTICE, "New user <%s> created\n", username);
1180 * cmd_newu() - create a new user account and log in as that user
1182 void cmd_newu(char *cmdbuf)
1187 if (config.c_auth_mode != AUTHMODE_NATIVE) {
1188 cprintf("%d This system does not use native mode authentication.\n",
1193 if (config.c_disable_newu) {
1194 cprintf("%d Self-service user account creation "
1195 "is disabled on this system.\n", ERROR + NOT_HERE);
1199 if (CC->logged_in) {
1200 cprintf("%d Already logged in.\n", ERROR + ALREADY_LOGGED_IN);
1204 cprintf("%d %s: Too many users are already online (maximum is %d)\n",
1205 ERROR + MAX_SESSIONS_EXCEEDED,
1206 config.c_nodename, config.c_maxsessions);
1208 extract_token(username, cmdbuf, 0, '|', sizeof username);
1212 if (IsEmptyStr(username)) {
1213 cprintf("%d You must supply a user name.\n", ERROR + USERNAME_REQUIRED);
1217 if ((!strcasecmp(username, "bbs")) ||
1218 (!strcasecmp(username, "new")) ||
1219 (!strcasecmp(username, "."))) {
1220 cprintf("%d '%s' is an invalid login name.\n", ERROR + ILLEGAL_VALUE, username);
1224 a = create_user(username, 1);
1227 logged_in_response();
1228 } else if (a == ERROR + ALREADY_EXISTS) {
1229 cprintf("%d '%s' already exists.\n",
1230 ERROR + ALREADY_EXISTS, username);
1232 } else if (a == ERROR + INTERNAL_ERROR) {
1233 cprintf("%d Internal error - user record disappeared?\n",
1234 ERROR + INTERNAL_ERROR);
1237 cprintf("%d unknown error\n", ERROR + INTERNAL_ERROR);
1243 * set password - back end api code
1245 void CtdlSetPassword(char *new_pw)
1247 lgetuser(&CC->user, CC->curr_user);
1248 safestrncpy(CC->user.password, new_pw, sizeof(CC->user.password));
1249 lputuser(&CC->user);
1250 CtdlLogPrintf(CTDL_INFO, "Password changed for user <%s>\n", CC->curr_user);
1251 PerformSessionHooks(EVT_SETPASS);
1256 * set password - citadel protocol implementation
1258 void cmd_setp(char *new_pw)
1260 int generate_random_password = 0;
1262 if (CtdlAccessCheck(ac_logged_in)) {
1265 if ( (CC->user.uid != CTDLUID) && (CC->user.uid != (-1)) ) {
1266 cprintf("%d Not allowed. Use the 'passwd' command.\n", ERROR + NOT_HERE);
1269 if (CC->is_master) {
1270 cprintf("%d The master prefix password cannot be changed with this command.\n",
1275 if (!strcasecmp(new_pw, "GENERATE_RANDOM_PASSWORD")) {
1276 char random_password[17];
1277 generate_random_password = 1;
1278 snprintf(random_password, sizeof random_password, "%08lx%08lx", random(), random());
1279 CtdlSetPassword(random_password);
1280 cprintf("%d %s\n", CIT_OK, random_password);
1284 if (IsEmptyStr(new_pw)) {
1285 cprintf("%d Password unchanged.\n", CIT_OK);
1288 CtdlSetPassword(new_pw);
1289 cprintf("%d Password changed.\n", CIT_OK);
1295 * cmd_creu() - administratively create a new user account (do not log in to it)
1297 void cmd_creu(char *cmdbuf)
1302 struct ctdluser tmp;
1304 if (CtdlAccessCheck(ac_aide)) {
1308 extract_token(username, cmdbuf, 0, '|', sizeof username);
1309 extract_token(password, cmdbuf, 1, '|', sizeof password);
1315 if (IsEmptyStr(username)) {
1316 cprintf("%d You must supply a user name.\n", ERROR + USERNAME_REQUIRED);
1320 a = create_user(username, 0);
1323 if (!IsEmptyStr(password)) {
1324 lgetuser(&tmp, username);
1325 safestrncpy(tmp.password, password, sizeof(tmp.password));
1328 cprintf("%d User '%s' created %s.\n", CIT_OK, username,
1329 (!IsEmptyStr(password)) ? "and password set" :
1330 "with no password");
1332 } else if (a == ERROR + ALREADY_EXISTS) {
1333 cprintf("%d '%s' already exists.\n", ERROR + ALREADY_EXISTS, username);
1335 } else if ( (config.c_auth_mode != AUTHMODE_NATIVE) && (a == ERROR + NO_SUCH_USER) ) {
1336 cprintf("%d User accounts are not created within Citadel in host authentication mode.\n",
1337 ERROR + NO_SUCH_USER);
1340 cprintf("%d An error occurred creating the user account.\n", ERROR + INTERNAL_ERROR);
1347 * get user parameters
1349 void cmd_getu(char *cmdbuf)
1352 if (CtdlAccessCheck(ac_logged_in))
1355 getuser(&CC->user, CC->curr_user);
1356 cprintf("%d %d|%d|%d|\n",
1358 CC->user.USscreenwidth,
1359 CC->user.USscreenheight,
1360 (CC->user.flags & US_USER_SET)
1365 * set user parameters
1367 void cmd_setu(char *new_parms)
1369 if (CtdlAccessCheck(ac_logged_in))
1372 if (num_parms(new_parms) < 3) {
1373 cprintf("%d Usage error.\n", ERROR + ILLEGAL_VALUE);
1376 lgetuser(&CC->user, CC->curr_user);
1377 CC->user.USscreenwidth = extract_int(new_parms, 0);
1378 CC->user.USscreenheight = extract_int(new_parms, 1);
1379 CC->user.flags = CC->user.flags & (~US_USER_SET);
1380 CC->user.flags = CC->user.flags |
1381 (extract_int(new_parms, 2) & US_USER_SET);
1383 lputuser(&CC->user);
1384 cprintf("%d Ok\n", CIT_OK);
1388 * set last read pointer
1390 void cmd_slrp(char *new_ptr)
1394 struct visit original_vbuf;
1396 if (CtdlAccessCheck(ac_logged_in)) {
1400 if (!strncasecmp(new_ptr, "highest", 7)) {
1401 newlr = CC->room.QRhighest;
1403 newlr = atol(new_ptr);
1406 lgetuser(&CC->user, CC->curr_user);
1408 CtdlGetRelationship(&vbuf, &CC->user, &CC->room);
1409 memcpy(&original_vbuf, &vbuf, sizeof(struct visit));
1410 vbuf.v_lastseen = newlr;
1411 snprintf(vbuf.v_seen, sizeof vbuf.v_seen, "*:%ld", newlr);
1413 /* Only rewrite the record if it changed */
1414 if ( (vbuf.v_lastseen != original_vbuf.v_lastseen)
1415 || (strcmp(vbuf.v_seen, original_vbuf.v_seen)) ) {
1416 CtdlSetRelationship(&vbuf, &CC->user, &CC->room);
1419 lputuser(&CC->user);
1420 cprintf("%d %ld\n", CIT_OK, newlr);
1424 void cmd_seen(char *argbuf) {
1425 long target_msgnum = 0L;
1426 int target_setting = 0;
1428 if (CtdlAccessCheck(ac_logged_in)) {
1432 if (num_parms(argbuf) != 2) {
1433 cprintf("%d Invalid parameters\n", ERROR + ILLEGAL_VALUE);
1437 target_msgnum = extract_long(argbuf, 0);
1438 target_setting = extract_int(argbuf, 1);
1440 CtdlSetSeen(&target_msgnum, 1, target_setting,
1441 ctdlsetseen_seen, NULL, NULL);
1442 cprintf("%d OK\n", CIT_OK);
1446 void cmd_gtsn(char *argbuf) {
1449 if (CtdlAccessCheck(ac_logged_in)) {
1453 CtdlGetSeen(buf, ctdlsetseen_seen);
1454 cprintf("%d %s\n", CIT_OK, buf);
1459 * API function for cmd_invt_kick() and anything else that needs to
1460 * invite or kick out a user to/from a room.
1462 * Set iuser to the name of the user, and op to 1=invite or 0=kick
1464 int CtdlInvtKick(char *iuser, int op) {
1465 struct ctdluser USscratch;
1469 if (getuser(&USscratch, iuser) != 0) {
1473 CtdlGetRelationship(&vbuf, &USscratch, &CC->room);
1475 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
1476 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
1479 vbuf.v_flags = vbuf.v_flags & ~V_ACCESS;
1480 vbuf.v_flags = vbuf.v_flags | V_FORGET | V_LOCKOUT;
1482 CtdlSetRelationship(&vbuf, &USscratch, &CC->room);
1484 /* post a message in Aide> saying what we just did */
1485 snprintf(bbb, sizeof bbb, "%s has been %s \"%s\" by %s.\n",
1487 ((op == 1) ? "invited to" : "kicked out of"),
1490 aide_message(bbb,"User Admin Message");
1497 * INVT and KICK commands
1499 void cmd_invt_kick(char *iuser, int op) {
1502 * These commands are only allowed by aides, room aides,
1503 * and room namespace owners
1506 || (atol(CC->room.QRname) == CC->user.usernum) ) {
1507 /* access granted */
1510 cprintf("%d Higher access or room ownership required.\n",
1511 ERROR + HIGHER_ACCESS_REQUIRED);
1515 if (!strncasecmp(CC->room.QRname, config.c_baseroom,
1517 cprintf("%d Can't add/remove users from this room.\n",
1522 if (CtdlInvtKick(iuser, op) != 0) {
1523 cprintf("%d No such user.\n", ERROR + NO_SUCH_USER);
1527 cprintf("%d %s %s %s.\n",
1529 ((op == 1) ? "invited to" : "kicked out of"),
1534 void cmd_invt(char *iuser) {cmd_invt_kick(iuser, 1);}
1535 void cmd_kick(char *iuser) {cmd_invt_kick(iuser, 0);}
1538 * Forget (Zap) the current room (API call)
1539 * Returns 0 on success
1541 int CtdlForgetThisRoom(void) {
1544 /* On some systems, Aides are not allowed to forget rooms */
1545 if (is_aide() && (config.c_aide_zap == 0)
1546 && ((CC->room.QRflags & QR_MAILBOX) == 0) ) {
1550 lgetuser(&CC->user, CC->curr_user);
1551 CtdlGetRelationship(&vbuf, &CC->user, &CC->room);
1553 vbuf.v_flags = vbuf.v_flags | V_FORGET;
1554 vbuf.v_flags = vbuf.v_flags & ~V_ACCESS;
1556 CtdlSetRelationship(&vbuf, &CC->user, &CC->room);
1557 lputuser(&CC->user);
1559 /* Return to the Lobby, so we don't end up in an undefined room */
1560 usergoto(config.c_baseroom, 0, 0, NULL, NULL);
1567 * forget (Zap) the current room
1569 void cmd_forg(char *argbuf)
1572 if (CtdlAccessCheck(ac_logged_in)) {
1576 if (CtdlForgetThisRoom() == 0) {
1577 cprintf("%d Ok\n", CIT_OK);
1580 cprintf("%d You may not forget this room.\n", ERROR + NOT_HERE);
1585 * Get Next Unregistered User
1587 void cmd_gnur(char *argbuf)
1589 struct cdbdata *cdbus;
1590 struct ctdluser usbuf;
1592 if (CtdlAccessCheck(ac_aide)) {
1596 if ((CitControl.MMflags & MM_VALID) == 0) {
1597 cprintf("%d There are no unvalidated users.\n", CIT_OK);
1601 /* There are unvalidated users. Traverse the user database,
1602 * and return the first user we find that needs validation.
1604 cdb_rewind(CDB_USERS);
1605 while (cdbus = cdb_next_item(CDB_USERS), cdbus != NULL) {
1606 memset(&usbuf, 0, sizeof(struct ctdluser));
1607 memcpy(&usbuf, cdbus->ptr,
1608 ((cdbus->len > sizeof(struct ctdluser)) ?
1609 sizeof(struct ctdluser) : cdbus->len));
1611 if ((usbuf.flags & US_NEEDVALID)
1612 && (usbuf.axlevel > 0)) {
1613 cprintf("%d %s\n", MORE_DATA, usbuf.fullname);
1614 cdb_close_cursor(CDB_USERS);
1619 /* If we get to this point, there are no more unvalidated users.
1620 * Therefore we clear the "users need validation" flag.
1623 begin_critical_section(S_CONTROL);
1625 CitControl.MMflags = CitControl.MMflags & (~MM_VALID);
1627 end_critical_section(S_CONTROL);
1628 cprintf("%d *** End of registration.\n", CIT_OK);
1637 void cmd_vali(char *v_args)
1641 struct ctdluser userbuf;
1643 extract_token(user, v_args, 0, '|', sizeof user);
1644 newax = extract_int(v_args, 1);
1646 if (CtdlAccessCheck(ac_aide)) {
1650 if (lgetuser(&userbuf, user) != 0) {
1651 cprintf("%d '%s' not found.\n", ERROR + NO_SUCH_USER, user);
1655 userbuf.axlevel = newax;
1656 userbuf.flags = (userbuf.flags & ~US_NEEDVALID);
1660 /* If the access level was set to zero, delete the user */
1662 if (purge_user(user) == 0) {
1663 cprintf("%d %s Deleted.\n", CIT_OK, userbuf.fullname);
1667 cprintf("%d User '%s' validated.\n", CIT_OK, userbuf.fullname);
1673 * Traverse the user file...
1675 void ForEachUser(void (*CallBack) (struct ctdluser * EachUser, void *out_data),
1678 struct ctdluser usbuf;
1679 struct cdbdata *cdbus;
1681 cdb_rewind(CDB_USERS);
1683 while (cdbus = cdb_next_item(CDB_USERS), cdbus != NULL) {
1684 memset(&usbuf, 0, sizeof(struct ctdluser));
1685 memcpy(&usbuf, cdbus->ptr,
1686 ((cdbus->len > sizeof(struct ctdluser)) ?
1687 sizeof(struct ctdluser) : cdbus->len));
1689 (*CallBack) (&usbuf, in_data);
1695 * List one user (this works with cmd_list)
1697 void ListThisUser(struct ctdluser *usbuf, void *data)
1701 searchstring = (char *)data;
1702 if (bmstrcasestr(usbuf->fullname, searchstring) == NULL) {
1706 if (usbuf->axlevel > 0) {
1707 if ((CC->user.axlevel >= 6)
1708 || ((usbuf->flags & US_UNLISTED) == 0)
1709 || ((CC->internal_pgm))) {
1710 cprintf("%s|%d|%ld|%ld|%ld|%ld||\n",
1714 (long)usbuf->lastcall,
1722 * List users (searchstring may be empty to list all users)
1724 void cmd_list(char *cmdbuf)
1726 char searchstring[256];
1727 extract_token(searchstring, cmdbuf, 0, '|', sizeof searchstring);
1728 striplt(searchstring);
1729 cprintf("%d \n", LISTING_FOLLOWS);
1730 ForEachUser(ListThisUser, (void *)searchstring );
1738 * assorted info we need to check at login
1740 void cmd_chek(char *argbuf)
1746 if (CtdlAccessCheck(ac_logged_in)) {
1750 getuser(&CC->user, CC->curr_user); /* no lock is needed here */
1751 if ((REGISCALL != 0) && ((CC->user.flags & US_REGIS) == 0))
1754 if (CC->user.axlevel >= 6) {
1756 if (CitControl.MMflags & MM_VALID)
1760 /* check for mail */
1761 mail = InitialMailCheck();
1763 cprintf("%d %d|%d|%d|%s|\n", CIT_OK, mail, regis, vali, CC->cs_inet_email);
1768 * check to see if a user exists
1770 void cmd_qusr(char *who)
1772 struct ctdluser usbuf;
1774 if (getuser(&usbuf, who) == 0) {
1775 cprintf("%d %s\n", CIT_OK, usbuf.fullname);
1777 cprintf("%d No such user.\n", ERROR + NO_SUCH_USER);
1783 * Administrative Get User Parameters
1785 void cmd_agup(char *cmdbuf)
1787 struct ctdluser usbuf;
1788 char requested_user[128];
1790 if (CtdlAccessCheck(ac_aide)) {
1794 extract_token(requested_user, cmdbuf, 0, '|', sizeof requested_user);
1795 if (getuser(&usbuf, requested_user) != 0) {
1796 cprintf("%d No such user.\n", ERROR + NO_SUCH_USER);
1799 cprintf("%d %s|%s|%u|%ld|%ld|%d|%ld|%ld|%d\n",
1806 (int) usbuf.axlevel,
1808 (long)usbuf.lastcall,
1815 * Administrative Set User Parameters
1817 void cmd_asup(char *cmdbuf)
1819 struct ctdluser usbuf;
1820 char requested_user[128];
1826 if (CtdlAccessCheck(ac_aide))
1829 extract_token(requested_user, cmdbuf, 0, '|', sizeof requested_user);
1830 if (lgetuser(&usbuf, requested_user) != 0) {
1831 cprintf("%d No such user.\n", ERROR + NO_SUCH_USER);
1834 np = num_parms(cmdbuf);
1836 extract_token(usbuf.password, cmdbuf, 1, '|', sizeof usbuf.password);
1838 usbuf.flags = extract_int(cmdbuf, 2);
1840 usbuf.timescalled = extract_int(cmdbuf, 3);
1842 usbuf.posted = extract_int(cmdbuf, 4);
1844 newax = extract_int(cmdbuf, 5);
1845 if ((newax >= 0) && (newax <= 6)) {
1846 usbuf.axlevel = extract_int(cmdbuf, 5);
1850 usbuf.lastcall = extract_long(cmdbuf, 7);
1853 usbuf.USuserpurge = extract_int(cmdbuf, 8);
1856 if (usbuf.axlevel == 0) {
1857 if (purge_user(requested_user) == 0) {
1863 snprintf(notify, SIZ,
1864 "User \"%s\" has been deleted by %s.\n",
1865 usbuf.fullname, CC->user.fullname);
1866 aide_message(notify, "User Deletion Message");
1869 cprintf("%d Ok", CIT_OK);
1871 cprintf(" (%s deleted)", requested_user);
1878 * Check to see if the user who we just sent mail to is logged in. If yes,
1879 * bump the 'new mail' counter for their session. That enables them to
1880 * receive a new mail notification without having to hit the database.
1882 void BumpNewMailCounter(long which_user) {
1883 struct CitContext *ptr;
1885 begin_critical_section(S_SESSION_TABLE);
1887 for (ptr = ContextList; ptr != NULL; ptr = ptr->next) {
1888 if (ptr->user.usernum == which_user) {
1893 end_critical_section(S_SESSION_TABLE);
1898 * Count the number of new mail messages the user has
1902 int num_newmsgs = 0;
1904 num_newmsgs = CC->newmail;
1907 return (num_newmsgs);
1912 * Count the number of new mail messages the user has
1914 int InitialMailCheck()
1916 int num_newmsgs = 0;
1918 char mailboxname[ROOMNAMELEN];
1919 struct ctdlroom mailbox;
1921 struct cdbdata *cdbfr;
1922 long *msglist = NULL;
1925 MailboxName(mailboxname, sizeof mailboxname, &CC->user, MAILROOM);
1926 if (getroom(&mailbox, mailboxname) != 0)
1928 CtdlGetRelationship(&vbuf, &CC->user, &mailbox);
1930 cdbfr = cdb_fetch(CDB_MSGLISTS, &mailbox.QRnumber, sizeof(long));
1932 if (cdbfr != NULL) {
1933 msglist = malloc(cdbfr->len);
1934 memcpy(msglist, cdbfr->ptr, cdbfr->len);
1935 num_msgs = cdbfr->len / sizeof(long);
1939 for (a = 0; a < num_msgs; ++a) {
1940 if (msglist[a] > 0L) {
1941 if (msglist[a] > vbuf.v_lastseen) {
1946 if (msglist != NULL)
1949 return (num_newmsgs);
1955 * Set the preferred view for the current user/room combination
1957 void cmd_view(char *cmdbuf) {
1961 if (CtdlAccessCheck(ac_logged_in)) {
1965 requested_view = extract_int(cmdbuf, 0);
1967 CtdlGetRelationship(&vbuf, &CC->user, &CC->room);
1968 vbuf.v_view = requested_view;
1969 CtdlSetRelationship(&vbuf, &CC->user, &CC->room);
1971 cprintf("%d ok\n", CIT_OK);
1978 void cmd_renu(char *cmdbuf)
1981 char oldname[USERNAME_SIZE];
1982 char newname[USERNAME_SIZE];
1984 if (CtdlAccessCheck(ac_aide)) {
1988 extract_token(oldname, cmdbuf, 0, '|', sizeof oldname);
1989 extract_token(newname, cmdbuf, 1, '|', sizeof newname);
1991 retcode = rename_user(oldname, newname);
1994 cprintf("%d '%s' has been renamed to '%s'.\n", CIT_OK, oldname, newname);
1996 case RENAMEUSER_LOGGED_IN:
1997 cprintf("%d '%s' is currently logged in and cannot be renamed.\n",
1998 ERROR + ALREADY_LOGGED_IN , oldname);
2000 case RENAMEUSER_NOT_FOUND:
2001 cprintf("%d '%s' does not exist.\n", ERROR + NO_SUCH_USER, oldname);
2003 case RENAMEUSER_ALREADY_EXISTS:
2004 cprintf("%d A user named '%s' already exists.\n", ERROR + ALREADY_EXISTS, newname);
2008 cprintf("%d An unknown error occurred.\n", ERROR);
2013 /*****************************************************************************/
2014 /* MODULE INITIALIZATION STUFF */
2015 /*****************************************************************************/
2018 CTDL_MODULE_INIT(user_ops)
2020 CtdlRegisterProtoHook(cmd_user, "USER", "Autoconverted. TODO: document me.");
2021 CtdlRegisterProtoHook(cmd_pass, "PASS", "Autoconverted. TODO: document me.");
2022 CtdlRegisterProtoHook(cmd_creu, "CREU", "Autoconverted. TODO: document me.");
2023 CtdlRegisterProtoHook(cmd_setp, "SETP", "Autoconverted. TODO: document me.");
2024 CtdlRegisterProtoHook(cmd_getu, "GETU", "Autoconverted. TODO: document me.");
2025 CtdlRegisterProtoHook(cmd_setu, "SETU", "Autoconverted. TODO: document me.");
2026 CtdlRegisterProtoHook(cmd_slrp, "SLRP", "Autoconverted. TODO: document me.");
2027 CtdlRegisterProtoHook(cmd_invt, "INVT", "Autoconverted. TODO: document me.");
2028 CtdlRegisterProtoHook(cmd_kick, "KICK", "Autoconverted. TODO: document me.");
2029 CtdlRegisterProtoHook(cmd_forg, "FORG", "Autoconverted. TODO: document me.");
2030 CtdlRegisterProtoHook(cmd_gnur, "GNUR", "Autoconverted. TODO: document me.");
2031 CtdlRegisterProtoHook(cmd_vali, "VALI", "Autoconverted. TODO: document me.");
2032 CtdlRegisterProtoHook(cmd_list, "LIST", "Autoconverted. TODO: document me.");
2033 CtdlRegisterProtoHook(cmd_chek, "CHEK", "Autoconverted. TODO: document me.");
2034 CtdlRegisterProtoHook(cmd_qusr, "QUSR", "Autoconverted. TODO: document me.");
2035 CtdlRegisterProtoHook(cmd_agup, "AGUP", "Autoconverted. TODO: document me.");
2036 CtdlRegisterProtoHook(cmd_asup, "ASUP", "Autoconverted. TODO: document me.");
2037 CtdlRegisterProtoHook(cmd_seen, "SEEN", "Autoconverted. TODO: document me.");
2038 CtdlRegisterProtoHook(cmd_gtsn, "GTSN", "Autoconverted. TODO: document me.");
2039 CtdlRegisterProtoHook(cmd_view, "VIEW", "Autoconverted. TODO: document me.");
2040 CtdlRegisterProtoHook(cmd_renu, "RENU", "Autoconverted. TODO: document me.");
2041 CtdlRegisterProtoHook(cmd_newu, "NEWU", "Autoconverted. TODO: document me.");
2042 /* return our Subversion id for the Log */