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 /* These pipes are used to talk to the chkpwd daemon, which is forked during startup */
56 int chkpwd_write_pipe[2];
57 int chkpwd_read_pipe[2];
60 * makeuserkey() - convert a username into the format used as a database key
61 * (it's just the username converted into lower case)
63 INLINE void makeuserkey(char *key, char *username) {
66 len = strlen(username);
67 if (len >= USERNAME_SIZE)
69 CtdlLogPrintf (CTDL_EMERG, "Username to long: %s", username);
71 len = USERNAME_SIZE - 1;
72 username[USERNAME_SIZE - 1]='\0';
74 for (i=0; i<=len; ++i) {
75 key[i] = tolower(username[i]);
81 * getuser() - retrieve named user into supplied buffer.
82 * returns 0 on success
84 int getuser(struct ctdluser *usbuf, char name[])
87 char usernamekey[USERNAME_SIZE];
88 struct cdbdata *cdbus;
91 memset(usbuf, 0, sizeof(struct ctdluser));
94 makeuserkey(usernamekey, name);
95 cdbus = cdb_fetch(CDB_USERS, usernamekey, strlen(usernamekey));
97 if (cdbus == NULL) { /* user not found */
101 memcpy(usbuf, cdbus->ptr,
102 ((cdbus->len > sizeof(struct ctdluser)) ?
103 sizeof(struct ctdluser) : cdbus->len));
112 * lgetuser() - same as getuser() but locks the record
114 int lgetuser(struct ctdluser *usbuf, char *name)
118 retcode = getuser(usbuf, name);
120 begin_critical_section(S_USERS);
127 * putuser() - write user buffer into the correct place on disk
129 void putuser(struct ctdluser *usbuf)
131 char usernamekey[USERNAME_SIZE];
133 makeuserkey(usernamekey, usbuf->fullname);
135 usbuf->version = REV_LEVEL;
137 usernamekey, strlen(usernamekey),
138 usbuf, sizeof(struct ctdluser));
144 * lputuser() - same as putuser() but locks the record
146 void lputuser(struct ctdluser *usbuf)
149 end_critical_section(S_USERS);
154 * rename_user() - this is tricky because the user's display name is the database key
156 * Returns 0 on success or nonzero if there was an error...
159 int rename_user(char *oldname, char *newname) {
160 struct CitContext *cptr;
161 int retcode = RENAMEUSER_OK;
162 struct ctdluser usbuf;
164 char oldnamekey[USERNAME_SIZE];
165 char newnamekey[USERNAME_SIZE];
167 /* We cannot rename a user who is currently logged in */
168 for (cptr = ContextList; cptr != NULL; cptr = cptr->next) {
169 if (!strcasecmp(cptr->user.fullname, oldname)) {
170 return(RENAMEUSER_LOGGED_IN);
174 /* Create the database keys... */
175 makeuserkey(oldnamekey, oldname);
176 makeuserkey(newnamekey, newname);
178 /* Lock up and get going */
179 begin_critical_section(S_USERS);
181 if (getuser(&usbuf, newname) == 0) {
182 retcode = RENAMEUSER_ALREADY_EXISTS;
186 if (getuser(&usbuf, oldname) != 0) {
187 retcode = RENAMEUSER_NOT_FOUND;
190 else { /* Sanity checks succeeded. Now rename the user. */
191 if (usbuf.usernum == 0)
193 CtdlLogPrintf (CTDL_DEBUG, "Can not rename user \"Citadel\".\n");
194 retcode = RENAMEUSER_NOT_FOUND;
196 CtdlLogPrintf(CTDL_DEBUG, "Renaming <%s> to <%s>\n", oldname, newname);
197 cdb_delete(CDB_USERS, oldnamekey, strlen(oldnamekey));
198 safestrncpy(usbuf.fullname, newname, sizeof usbuf.fullname);
200 cdb_store(CDB_USERSBYNUMBER, &usbuf.usernum, sizeof(long),
201 usbuf.fullname, strlen(usbuf.fullname)+1 );
203 retcode = RENAMEUSER_OK;
209 end_critical_section(S_USERS);
216 * Index-generating function used by Ctdl[Get|Set]Relationship
218 int GenerateRelationshipIndex(char *IndexBuf,
230 TheIndex.iRoomID = RoomID;
231 TheIndex.iRoomGen = RoomGen;
232 TheIndex.iUserID = UserID;
234 memcpy(IndexBuf, &TheIndex, sizeof(TheIndex));
235 return (sizeof(TheIndex));
241 * Back end for CtdlSetRelationship()
243 void put_visit(struct visit *newvisit)
248 memset (IndexBuf, 0, sizeof (IndexBuf));
249 /* Generate an index */
250 IndexLen = GenerateRelationshipIndex(IndexBuf,
253 newvisit->v_usernum);
255 /* Store the record */
256 cdb_store(CDB_VISIT, IndexBuf, IndexLen,
257 newvisit, sizeof(struct visit)
265 * Define a relationship between a user and a room
267 void CtdlSetRelationship(struct visit *newvisit,
268 struct ctdluser *rel_user,
269 struct ctdlroom *rel_room)
273 /* We don't use these in Citadel because they're implicit by the
274 * index, but they must be present if the database is exported.
276 newvisit->v_roomnum = rel_room->QRnumber;
277 newvisit->v_roomgen = rel_room->QRgen;
278 newvisit->v_usernum = rel_user->usernum;
284 * Locate a relationship between a user and a room
286 void CtdlGetRelationship(struct visit *vbuf,
287 struct ctdluser *rel_user,
288 struct ctdlroom *rel_room)
293 struct cdbdata *cdbvisit;
295 /* Generate an index */
296 IndexLen = GenerateRelationshipIndex(IndexBuf,
301 /* Clear out the buffer */
302 memset(vbuf, 0, sizeof(struct visit));
304 cdbvisit = cdb_fetch(CDB_VISIT, IndexBuf, IndexLen);
305 if (cdbvisit != NULL) {
306 memcpy(vbuf, cdbvisit->ptr,
307 ((cdbvisit->len > sizeof(struct visit)) ?
308 sizeof(struct visit) : cdbvisit->len));
312 /* If this is the first time the user has seen this room,
313 * set the view to be the default for the room.
315 vbuf->v_view = rel_room->QRdefaultview;
318 /* Set v_seen if necessary */
319 if (vbuf->v_seen[0] == 0) {
320 snprintf(vbuf->v_seen, sizeof vbuf->v_seen, "*:%ld", vbuf->v_lastseen);
325 void MailboxName(char *buf, size_t n, const struct ctdluser *who, const char *prefix)
327 snprintf(buf, n, "%010ld.%s", who->usernum, prefix);
332 * Is the user currently logged in an Aide?
336 if (CC->user.axlevel >= 6)
344 * Is the user currently logged in an Aide *or* the room aide for this room?
346 int is_room_aide(void)
349 if (!CC->logged_in) {
353 if ((CC->user.axlevel >= 6)
354 || (CC->room.QRroomaide == CC->user.usernum)) {
362 * getuserbynumber() - get user by number
363 * returns 0 if user was found
365 * Note: fetching a user this way requires one additional database operation.
367 int getuserbynumber(struct ctdluser *usbuf, long number)
369 struct cdbdata *cdbun;
372 cdbun = cdb_fetch(CDB_USERSBYNUMBER, &number, sizeof(long));
374 CtdlLogPrintf(CTDL_INFO, "User %ld not found\n", number);
378 CtdlLogPrintf(CTDL_INFO, "User %ld maps to %s\n", number, cdbun->ptr);
379 r = getuser(usbuf, cdbun->ptr);
387 * Helper function for rebuild_usersbynumber()
389 void rebuild_ubn_for_user(struct ctdluser *usbuf, void *data) {
392 struct ubnlist *next;
393 char username[USERNAME_SIZE];
397 static struct ubnlist *u = NULL;
398 struct ubnlist *ptr = NULL;
400 /* Lazy programming here. Call this function as a ForEachUser backend
401 * in order to queue up the room names, or call it with a null user
402 * to make it do the processing.
405 ptr = (struct ubnlist *) malloc(sizeof (struct ubnlist));
406 if (ptr == NULL) return;
408 ptr->usernum = usbuf->usernum;
409 safestrncpy(ptr->username, usbuf->fullname, sizeof ptr->username);
416 CtdlLogPrintf(CTDL_DEBUG, "Rebuilding usersbynumber index %10ld : %s\n",
417 u->usernum, u->username);
418 cdb_store(CDB_USERSBYNUMBER, &u->usernum, sizeof(long), u->username, strlen(u->username)+1);
429 * Rebuild the users-by-number index
431 void rebuild_usersbynumber(void) {
432 cdb_trunc(CDB_USERSBYNUMBER); /* delete the old indices */
433 ForEachUser(rebuild_ubn_for_user, NULL); /* enumerate the users */
434 rebuild_ubn_for_user(NULL, NULL); /* and index them */
440 * getuserbyuid() - get user by system uid (for PAM mode authentication)
441 * returns 0 if user was found
443 * WARNING: don't use this function unless you absolutely have to. It does
444 * a sequential search and therefore is computationally expensive.
446 int getuserbyuid(struct ctdluser *usbuf, uid_t number)
448 struct cdbdata *cdbus;
450 cdb_rewind(CDB_USERS);
452 while (cdbus = cdb_next_item(CDB_USERS), cdbus != NULL) {
453 memset(usbuf, 0, sizeof(struct ctdluser));
454 memcpy(usbuf, cdbus->ptr,
455 ((cdbus->len > sizeof(struct ctdluser)) ?
456 sizeof(struct ctdluser) : cdbus->len));
458 if (usbuf->uid == number) {
459 cdb_close_cursor(CDB_USERS);
467 * Back end for cmd_user() and its ilk
469 * NOTE: "authname" should only be used if we are attempting to use the "master user" feature
471 int CtdlLoginExistingUser(char *authname, char *trythisname)
476 CtdlLogPrintf(9, "CtdlLoginExistingUser(%s, %s)\n", authname, trythisname);
478 if ((CC->logged_in)) {
479 return login_already_logged_in;
482 if (trythisname == NULL) return login_not_found;
484 if (!strncasecmp(trythisname, "SYS_", 4))
486 CtdlLogPrintf(CTDL_DEBUG, "System user \"%s\" is not allowed to log in.\n", trythisname);
487 return login_not_found;
490 /* If a "master user" is defined, handle its authentication if specified */
492 if (strlen(config.c_master_user) > 0) if (strlen(config.c_master_pass) > 0) if (authname) {
493 if (!strcasecmp(authname, config.c_master_user)) {
498 /* Continue attempting user validation... */
499 safestrncpy(username, trythisname, USERNAME_SIZE);
502 if (IsEmptyStr(username)) {
503 return login_not_found;
506 if (config.c_auth_mode == AUTHMODE_HOST) {
511 struct passwd *tempPwdPtr;
514 CtdlLogPrintf(CTDL_DEBUG, "asking host about <%s>\n", username);
515 #ifdef HAVE_GETPWNAM_R
516 #ifdef SOLARIS_GETPWUID
517 CtdlLogPrintf(CTDL_DEBUG, "Calling getpwnam_r()\n");
518 tempPwdPtr = getpwnam_r(username, &pd, pwdbuffer, sizeof pwdbuffer);
519 #else // SOLARIS_GETPWUID
520 CtdlLogPrintf(CTDL_DEBUG, "Calling getpwnam_r()\n");
521 getpwnam_r(username, &pd, pwdbuffer, sizeof pwdbuffer, &tempPwdPtr);
522 #endif // SOLARIS_GETPWUID
523 #else // HAVE_GETPWNAM_R
524 CtdlLogPrintf(CTDL_DEBUG, "SHOULD NEVER GET HERE!!!\n");
526 #endif // HAVE_GETPWNAM_R
527 if (tempPwdPtr == NULL) {
528 CtdlLogPrintf(CTDL_DEBUG, "no such user <%s>\n", username);
529 return login_not_found;
532 /* Locate the associated Citadel account.
533 * If not found, make one attempt to create it.
535 found_user = getuserbyuid(&CC->user, pd.pw_uid);
536 CtdlLogPrintf(CTDL_DEBUG, "found it: uid=%ld, gecos=%s here: %d\n",
537 (long)pd.pw_uid, pd.pw_gecos, found_user);
538 if (found_user != 0) {
539 create_user(username, 0);
540 found_user = getuserbyuid(&CC->user, pd.pw_uid);
546 else if (config.c_auth_mode == AUTHMODE_LDAP) {
554 found_user = CtdlTryUserLDAP(username, ldap_dn, sizeof ldap_dn, ldap_cn, sizeof ldap_cn, &ldap_uid);
555 if (found_user != 0) {
556 return login_not_found;
559 found_user = getuserbyuid(&CC->user, ldap_uid);
560 if (found_user != 0) {
561 create_user(ldap_cn, 0);
562 found_user = getuserbyuid(&CC->user, ldap_uid);
565 if (found_user == 0) {
566 if (CC->ldap_dn != NULL) free(CC->ldap_dn);
567 CC->ldap_dn = strdup(ldap_dn);
574 /* native auth mode */
576 struct recptypes *valid = NULL;
578 /* First, try to log in as if the supplied name is a display name */
579 found_user = getuser(&CC->user, username);
581 /* If that didn't work, try to log in as if the supplied name
582 * is an e-mail address
584 if (found_user != 0) {
585 valid = validate_recipients(username, NULL, 0);
587 if (valid->num_local == 1) {
588 found_user = getuser(&CC->user, valid->recp_local);
590 free_recipients(valid);
595 /* Did we find something? */
596 if (found_user == 0) {
597 if (((CC->nologin)) && (CC->user.axlevel < 6)) {
598 return login_too_many_users;
600 safestrncpy(CC->curr_user, CC->user.fullname,
601 sizeof CC->curr_user);
605 return login_not_found;
613 void cmd_user(char *cmdbuf)
618 extract_token(username, cmdbuf, 0, '|', sizeof username);
621 a = CtdlLoginExistingUser(NULL, username);
623 case login_already_logged_in:
624 cprintf("%d Already logged in.\n", ERROR + ALREADY_LOGGED_IN);
626 case login_too_many_users:
628 "Too many users are already online "
630 ERROR + MAX_SESSIONS_EXCEEDED,
631 config.c_nodename, config.c_maxsessions);
634 cprintf("%d Password required for %s\n",
635 MORE_DATA, CC->curr_user);
637 case login_not_found:
638 cprintf("%d %s not found.\n", ERROR + NO_SUCH_USER, username);
641 cprintf("%d Internal error\n", ERROR + INTERNAL_ERROR);
648 * session startup code which is common to both cmd_pass() and cmd_newu()
653 CtdlLogPrintf(CTDL_NOTICE, "<%s> logged in\n", CC->curr_user);
655 lgetuser(&CC->user, CC->curr_user);
656 ++(CC->user.timescalled);
657 CC->previous_login = CC->user.lastcall;
658 time(&CC->user.lastcall);
660 /* If this user's name is the name of the system administrator
661 * (as specified in setup), automatically assign access level 6.
663 if (!strcasecmp(CC->user.fullname, config.c_sysadm)) {
664 CC->user.axlevel = 6;
667 /* If we're authenticating off the host system, automatically give
668 * root the highest level of access.
670 if (config.c_auth_mode == AUTHMODE_HOST) {
671 if (CC->user.uid == 0) {
672 CC->user.axlevel = 6;
679 * Populate CC->cs_inet_email with a default address. This will be
680 * overwritten with the user's directory address, if one exists, when
681 * the vCard module's login hook runs.
683 snprintf(CC->cs_inet_email, sizeof CC->cs_inet_email, "%s@%s",
684 CC->user.fullname, config.c_fqdn);
685 convert_spaces_to_underscores(CC->cs_inet_email);
687 /* Create any personal rooms required by the system.
688 * (Technically, MAILROOM should be there already, but just in case...)
690 create_room(MAILROOM, 4, "", 0, 1, 0, VIEW_MAILBOX);
691 create_room(SENTITEMS, 4, "", 0, 1, 0, VIEW_MAILBOX);
692 create_room(USERTRASHROOM, 4, "", 0, 1, 0, VIEW_MAILBOX);
694 /* Run any startup routines registered by loadable modules */
695 PerformSessionHooks(EVT_LOGIN);
697 /* Enter the lobby */
698 usergoto(config.c_baseroom, 0, 0, NULL, NULL);
702 void logged_in_response(void)
704 cprintf("%d %s|%d|%ld|%ld|%u|%ld|%ld\n",
705 CIT_OK, CC->user.fullname, CC->user.axlevel,
706 CC->user.timescalled, CC->user.posted,
707 CC->user.flags, CC->user.usernum,
714 * misc things to be taken care of when a user is logged out
718 struct CitContext *CCC = CC; /* CachedCitContext - performance boost */
720 * If there is a download in progress, abort it.
722 if (CCC->download_fp != NULL) {
723 fclose(CCC->download_fp);
724 CCC->download_fp = NULL;
728 * If there is an upload in progress, abort it.
730 if (CCC->upload_fp != NULL) {
735 * If we were talking to a network node, we're not anymore...
737 if (!IsEmptyStr(CCC->net_node)) {
738 network_talking_to(CCC->net_node, NTT_REMOVE);
741 /* Run any hooks registered by modules... */
742 PerformSessionHooks(EVT_LOGOUT);
745 * Clear out some session data. Most likely, the CitContext for this
746 * session is about to get nuked when the session disconnects, but
747 * since it's possible to log in again without reconnecting, we cannot
748 * make that assumption.
750 strcpy(CCC->fake_username, "");
751 strcpy(CCC->fake_hostname, "");
752 strcpy(CCC->fake_roomname, "");
755 /* Check to see if the user was deleted whilst logged in and purge them if necessary */
756 if ((CCC->user.axlevel == 0) && (CCC->user.usernum))
757 purge_user(CCC->user.fullname);
759 /* Free any output buffers */
764 * Validate a password on the host unix system by talking to the chkpwd daemon
766 static int validpw(uid_t uid, const char *pass)
770 if (IsEmptyStr(pass)) {
771 CtdlLogPrintf(CTDL_DEBUG, "refusing to check empty password for uid=%d using chkpwd...\n", uid);
775 CtdlLogPrintf(CTDL_DEBUG, "Validating password for uid=%d using chkpwd...\n", uid);
777 begin_critical_section(S_CHKPWD);
778 write(chkpwd_write_pipe[1], &uid, sizeof(uid_t));
779 write(chkpwd_write_pipe[1], pass, 256);
780 read(chkpwd_read_pipe[0], buf, 4);
781 end_critical_section(S_CHKPWD);
783 if (!strncmp(buf, "PASS", 4)) {
784 CtdlLogPrintf(CTDL_DEBUG, "...pass\n");
788 CtdlLogPrintf(CTDL_DEBUG, "...fail\n");
793 * Start up the chkpwd daemon so validpw() has something to talk to
795 void start_chkpwd_daemon(void) {
797 struct stat filestats;
800 CtdlLogPrintf(CTDL_DEBUG, "Starting chkpwd daemon for host authentication mode\n");
802 if ((stat(file_chkpwd, &filestats)==-1) ||
803 (filestats.st_size==0)){
804 printf("didn't find chkpwd daemon in %s: %s\n", file_chkpwd, strerror(errno));
807 if (pipe(chkpwd_write_pipe) != 0) {
808 CtdlLogPrintf(CTDL_EMERG, "Unable to create pipe for chkpwd daemon: %s\n", strerror(errno));
811 if (pipe(chkpwd_read_pipe) != 0) {
812 CtdlLogPrintf(CTDL_EMERG, "Unable to create pipe for chkpwd daemon: %s\n", strerror(errno));
817 if (chkpwd_pid < 0) {
818 CtdlLogPrintf(CTDL_EMERG, "Unable to fork chkpwd daemon: %s\n", strerror(errno));
821 if (chkpwd_pid == 0) {
822 CtdlLogPrintf(CTDL_DEBUG, "Now calling dup2() write\n");
823 dup2(chkpwd_write_pipe[0], 0);
824 CtdlLogPrintf(CTDL_DEBUG, "Now calling dup2() write\n");
825 dup2(chkpwd_read_pipe[1], 1);
826 CtdlLogPrintf(CTDL_DEBUG, "Now closing stuff\n");
827 for (i=2; i<256; ++i) close(i);
828 CtdlLogPrintf(CTDL_DEBUG, "Now calling execl(%s)\n", file_chkpwd);
829 execl(file_chkpwd, file_chkpwd, NULL);
830 CtdlLogPrintf(CTDL_EMERG, "Unable to exec chkpwd daemon: %s\n", strerror(errno));
837 int CtdlTryPassword(char *password)
841 if ((CC->logged_in)) {
842 CtdlLogPrintf(CTDL_WARNING, "CtdlTryPassword: already logged in\n");
843 return pass_already_logged_in;
845 if (!strcmp(CC->curr_user, NLI)) {
846 CtdlLogPrintf(CTDL_WARNING, "CtdlTryPassword: no user selected\n");
849 if (getuser(&CC->user, CC->curr_user)) {
850 CtdlLogPrintf(CTDL_ERR, "CtdlTryPassword: internal error\n");
851 return pass_internal_error;
853 if (password == NULL) {
854 CtdlLogPrintf(CTDL_INFO, "CtdlTryPassword: NULL password string supplied\n");
855 return pass_wrong_password;
860 code = strcmp(password, config.c_master_pass);
863 else if (config.c_auth_mode == AUTHMODE_HOST) {
867 if (validpw(CC->user.uid, password)) {
871 * sooper-seekrit hack: populate the password field in the
872 * citadel database with the password that the user typed,
873 * if it's correct. This allows most sites to convert from
874 * host auth to native auth if they want to. If you think
875 * this is a security hazard, comment it out.
878 lgetuser(&CC->user, CC->curr_user);
879 safestrncpy(CC->user.password, password, sizeof CC->user.password);
883 * (sooper-seekrit hack ends here)
893 else if (config.c_auth_mode == AUTHMODE_LDAP) {
897 if ((CC->ldap_dn) && (!CtdlTryPasswordLDAP(CC->ldap_dn, password))) {
908 /* native auth mode */
911 strproc(CC->user.password);
912 code = strcasecmp(CC->user.password, password);
914 strproc(CC->user.password);
915 code = strcasecmp(CC->user.password, password);
922 CtdlLogPrintf(CTDL_WARNING, "Bad password specified for <%s>\n", CC->curr_user);
923 return pass_wrong_password;
928 void cmd_pass(char *buf)
933 extract_token(password, buf, 0, '|', sizeof password);
934 a = CtdlTryPassword(password);
937 case pass_already_logged_in:
938 cprintf("%d Already logged in.\n", ERROR + ALREADY_LOGGED_IN);
941 cprintf("%d You must send a name with USER first.\n",
942 ERROR + USERNAME_REQUIRED);
944 case pass_wrong_password:
945 cprintf("%d Wrong password.\n", ERROR + PASSWORD_REQUIRED);
948 logged_in_response();
956 * Delete a user record *and* all of its related resources.
958 int purge_user(char pname[])
961 struct ctdluser usbuf;
962 char usernamekey[USERNAME_SIZE];
963 struct CitContext *ccptr;
964 int user_is_logged_in = 0;
966 makeuserkey(usernamekey, pname);
968 /* If the name is empty we can't find them in the DB any way so just return */
969 if (IsEmptyStr(pname))
970 return (ERROR + NO_SUCH_USER);
972 if (getuser(&usbuf, pname) != 0) {
973 CtdlLogPrintf(CTDL_ERR, "Cannot purge user <%s> - not found\n", pname);
974 return (ERROR + NO_SUCH_USER);
976 /* Don't delete a user who is currently logged in. Instead, just
977 * set the access level to 0, and let the account get swept up
978 * during the next purge.
980 user_is_logged_in = 0;
981 begin_critical_section(S_SESSION_TABLE);
982 for (ccptr = ContextList; ccptr != NULL; ccptr = ccptr->next) {
983 if (ccptr->user.usernum == usbuf.usernum) {
984 user_is_logged_in = 1;
987 end_critical_section(S_SESSION_TABLE);
988 if (user_is_logged_in == 1) {
989 CtdlLogPrintf(CTDL_WARNING, "User <%s> is logged in; not deleting.\n", pname);
994 CtdlLogPrintf(CTDL_NOTICE, "Deleting user <%s>\n", pname);
996 /* Perform any purge functions registered by server extensions */
997 PerformUserHooks(&usbuf, EVT_PURGEUSER);
999 /* delete any existing user/room relationships */
1000 cdb_delete(CDB_VISIT, &usbuf.usernum, sizeof(long));
1002 /* delete the users-by-number index record */
1003 cdb_delete(CDB_USERSBYNUMBER, &usbuf.usernum, sizeof(long));
1005 /* delete the userlog entry */
1006 cdb_delete(CDB_USERS, usernamekey, strlen(usernamekey));
1008 /* remove the user's bio file */
1016 /* remove the user's picture */
1028 int internal_create_user (char *username, struct ctdluser *usbuf, uid_t uid)
1030 if (!getuser(usbuf, username)) {
1031 return (ERROR + ALREADY_EXISTS);
1034 /* Go ahead and initialize a new user record */
1035 memset(usbuf, 0, sizeof(struct ctdluser));
1036 safestrncpy(usbuf->fullname, username, sizeof usbuf->fullname);
1037 strcpy(usbuf->password, "");
1040 /* These are the default flags on new accounts */
1041 usbuf->flags = US_LASTOLD | US_DISAPPEAR | US_PAGINATOR | US_FLOORS;
1043 usbuf->timescalled = 0;
1045 usbuf->axlevel = config.c_initax;
1046 usbuf->USscreenwidth = 80;
1047 usbuf->USscreenheight = 24;
1048 usbuf->lastcall = time(NULL);
1050 /* fetch a new user number */
1051 usbuf->usernum = get_new_user_number();
1053 /* add user to the database */
1055 cdb_store(CDB_USERSBYNUMBER, &usbuf->usernum, sizeof(long), usbuf->fullname, strlen(usbuf->fullname)+1);
1063 * create_user() - back end processing to create a new user
1065 * Set 'newusername' to the desired account name.
1066 * Set 'become_user' to nonzero if this is self-service account creation and we want
1067 * to actually log in as the user we just created, otherwise set it to 0.
1069 int create_user(char *newusername, int become_user)
1071 struct ctdluser usbuf;
1072 struct ctdlroom qrbuf;
1074 char mailboxname[ROOMNAMELEN];
1080 safestrncpy(username, newusername, sizeof username);
1084 if (config.c_auth_mode == AUTHMODE_HOST) {
1086 /* host auth mode */
1089 struct passwd *tempPwdPtr;
1090 char pwdbuffer[256];
1092 #ifdef HAVE_GETPWNAM_R
1093 #ifdef SOLARIS_GETPWUID
1094 tempPwdPtr = getpwnam_r(username, &pd, pwdbuffer, sizeof(pwdbuffer));
1095 #else // SOLARIS_GETPWUID
1096 getpwnam_r(username, &pd, pwdbuffer, sizeof pwdbuffer, &tempPwdPtr);
1097 #endif // SOLARIS_GETPWUID
1098 #else // HAVE_GETPWNAM_R
1100 #endif // HAVE_GETPWNAM_R
1101 if (tempPwdPtr != NULL) {
1102 extract_token(username, pd.pw_gecos, 0, ',', sizeof username);
1104 if (IsEmptyStr (username))
1106 safestrncpy(username, pd.pw_name, sizeof username);
1110 return (ERROR + NO_SUCH_USER);
1114 /* FIXME_LDAP put something here */
1116 if ((retval = internal_create_user(username, &usbuf, uid)) != 0)
1120 * Give the user a private mailbox and a configuration room.
1121 * Make the latter an invisible system room.
1123 MailboxName(mailboxname, sizeof mailboxname, &usbuf, MAILROOM);
1124 create_room(mailboxname, 5, "", 0, 1, 1, VIEW_MAILBOX);
1126 MailboxName(mailboxname, sizeof mailboxname, &usbuf, USERCONFIGROOM);
1127 create_room(mailboxname, 5, "", 0, 1, 1, VIEW_BBS);
1128 if (lgetroom(&qrbuf, mailboxname) == 0) {
1129 qrbuf.QRflags2 |= QR2_SYSTEM;
1133 /* Perform any create functions registered by server extensions */
1134 PerformUserHooks(&usbuf, EVT_NEWUSER);
1136 /* Everything below this line can be bypassed if administratively
1137 * creating a user, instead of doing self-service account creation
1141 /* Now become the user we just created */
1142 memcpy(&CC->user, &usbuf, sizeof(struct ctdluser));
1143 safestrncpy(CC->curr_user, username, sizeof CC->curr_user);
1146 /* Check to make sure we're still who we think we are */
1147 if (getuser(&CC->user, CC->curr_user)) {
1148 return (ERROR + INTERNAL_ERROR);
1153 "New user account <%s> has been created, from host %s [%s].\n",
1158 aide_message(buf, "User Creation Notice");
1159 CtdlLogPrintf(CTDL_NOTICE, "New user <%s> created\n", username);
1166 * cmd_newu() - create a new user account and log in as that user
1168 void cmd_newu(char *cmdbuf)
1173 if (config.c_auth_mode != AUTHMODE_NATIVE) {
1174 cprintf("%d This system does not use native mode authentication.\n",
1179 if (config.c_disable_newu) {
1180 cprintf("%d Self-service user account creation "
1181 "is disabled on this system.\n", ERROR + NOT_HERE);
1185 if (CC->logged_in) {
1186 cprintf("%d Already logged in.\n", ERROR + ALREADY_LOGGED_IN);
1190 cprintf("%d %s: Too many users are already online (maximum is %d)\n",
1191 ERROR + MAX_SESSIONS_EXCEEDED,
1192 config.c_nodename, config.c_maxsessions);
1194 extract_token(username, cmdbuf, 0, '|', sizeof username);
1198 if (IsEmptyStr(username)) {
1199 cprintf("%d You must supply a user name.\n", ERROR + USERNAME_REQUIRED);
1203 if ((!strcasecmp(username, "bbs")) ||
1204 (!strcasecmp(username, "new")) ||
1205 (!strcasecmp(username, "."))) {
1206 cprintf("%d '%s' is an invalid login name.\n", ERROR + ILLEGAL_VALUE, username);
1210 a = create_user(username, 1);
1213 logged_in_response();
1214 } else if (a == ERROR + ALREADY_EXISTS) {
1215 cprintf("%d '%s' already exists.\n",
1216 ERROR + ALREADY_EXISTS, username);
1218 } else if (a == ERROR + INTERNAL_ERROR) {
1219 cprintf("%d Internal error - user record disappeared?\n",
1220 ERROR + INTERNAL_ERROR);
1223 cprintf("%d unknown error\n", ERROR + INTERNAL_ERROR);
1229 * set password - back end api code
1231 void CtdlSetPassword(char *new_pw)
1233 lgetuser(&CC->user, CC->curr_user);
1234 safestrncpy(CC->user.password, new_pw, sizeof(CC->user.password));
1235 lputuser(&CC->user);
1236 CtdlLogPrintf(CTDL_INFO, "Password changed for user <%s>\n", CC->curr_user);
1237 PerformSessionHooks(EVT_SETPASS);
1242 * set password - citadel protocol implementation
1244 void cmd_setp(char *new_pw)
1246 int generate_random_password = 0;
1248 if (CtdlAccessCheck(ac_logged_in)) {
1251 if ( (CC->user.uid != CTDLUID) && (CC->user.uid != (-1)) ) {
1252 cprintf("%d Not allowed. Use the 'passwd' command.\n", ERROR + NOT_HERE);
1255 if (CC->is_master) {
1256 cprintf("%d The master prefix password cannot be changed with this command.\n",
1261 if (!strcasecmp(new_pw, "GENERATE_RANDOM_PASSWORD")) {
1262 char random_password[17];
1263 generate_random_password = 1;
1264 snprintf(random_password, sizeof random_password, "%08lx%08lx", random(), random());
1265 CtdlSetPassword(random_password);
1266 cprintf("%d %s\n", CIT_OK, random_password);
1270 if (IsEmptyStr(new_pw)) {
1271 cprintf("%d Password unchanged.\n", CIT_OK);
1274 CtdlSetPassword(new_pw);
1275 cprintf("%d Password changed.\n", CIT_OK);
1281 * cmd_creu() - administratively create a new user account (do not log in to it)
1283 void cmd_creu(char *cmdbuf)
1288 struct ctdluser tmp;
1290 if (CtdlAccessCheck(ac_aide)) {
1294 extract_token(username, cmdbuf, 0, '|', sizeof username);
1295 extract_token(password, cmdbuf, 1, '|', sizeof password);
1301 if (IsEmptyStr(username)) {
1302 cprintf("%d You must supply a user name.\n", ERROR + USERNAME_REQUIRED);
1306 a = create_user(username, 0);
1309 if (!IsEmptyStr(password)) {
1310 lgetuser(&tmp, username);
1311 safestrncpy(tmp.password, password, sizeof(tmp.password));
1314 cprintf("%d User '%s' created %s.\n", CIT_OK, username,
1315 (!IsEmptyStr(password)) ? "and password set" :
1316 "with no password");
1318 } else if (a == ERROR + ALREADY_EXISTS) {
1319 cprintf("%d '%s' already exists.\n", ERROR + ALREADY_EXISTS, username);
1321 } else if ( (config.c_auth_mode != AUTHMODE_NATIVE) && (a == ERROR + NO_SUCH_USER) ) {
1322 cprintf("%d User accounts are not created within Citadel in host authentication mode.\n",
1323 ERROR + NO_SUCH_USER);
1326 cprintf("%d An error occurred creating the user account.\n", ERROR + INTERNAL_ERROR);
1333 * get user parameters
1338 if (CtdlAccessCheck(ac_logged_in))
1341 getuser(&CC->user, CC->curr_user);
1342 cprintf("%d %d|%d|%d|\n",
1344 CC->user.USscreenwidth,
1345 CC->user.USscreenheight,
1346 (CC->user.flags & US_USER_SET)
1351 * set user parameters
1353 void cmd_setu(char *new_parms)
1355 if (CtdlAccessCheck(ac_logged_in))
1358 if (num_parms(new_parms) < 3) {
1359 cprintf("%d Usage error.\n", ERROR + ILLEGAL_VALUE);
1362 lgetuser(&CC->user, CC->curr_user);
1363 CC->user.USscreenwidth = extract_int(new_parms, 0);
1364 CC->user.USscreenheight = extract_int(new_parms, 1);
1365 CC->user.flags = CC->user.flags & (~US_USER_SET);
1366 CC->user.flags = CC->user.flags |
1367 (extract_int(new_parms, 2) & US_USER_SET);
1369 lputuser(&CC->user);
1370 cprintf("%d Ok\n", CIT_OK);
1374 * set last read pointer
1376 void cmd_slrp(char *new_ptr)
1380 struct visit original_vbuf;
1382 if (CtdlAccessCheck(ac_logged_in)) {
1386 if (!strncasecmp(new_ptr, "highest", 7)) {
1387 newlr = CC->room.QRhighest;
1389 newlr = atol(new_ptr);
1392 lgetuser(&CC->user, CC->curr_user);
1394 CtdlGetRelationship(&vbuf, &CC->user, &CC->room);
1395 memcpy(&original_vbuf, &vbuf, sizeof(struct visit));
1396 vbuf.v_lastseen = newlr;
1397 snprintf(vbuf.v_seen, sizeof vbuf.v_seen, "*:%ld", newlr);
1399 /* Only rewrite the record if it changed */
1400 if ( (vbuf.v_lastseen != original_vbuf.v_lastseen)
1401 || (strcmp(vbuf.v_seen, original_vbuf.v_seen)) ) {
1402 CtdlSetRelationship(&vbuf, &CC->user, &CC->room);
1405 lputuser(&CC->user);
1406 cprintf("%d %ld\n", CIT_OK, newlr);
1410 void cmd_seen(char *argbuf) {
1411 long target_msgnum = 0L;
1412 int target_setting = 0;
1414 if (CtdlAccessCheck(ac_logged_in)) {
1418 if (num_parms(argbuf) != 2) {
1419 cprintf("%d Invalid parameters\n", ERROR + ILLEGAL_VALUE);
1423 target_msgnum = extract_long(argbuf, 0);
1424 target_setting = extract_int(argbuf, 1);
1426 CtdlSetSeen(&target_msgnum, 1, target_setting,
1427 ctdlsetseen_seen, NULL, NULL);
1428 cprintf("%d OK\n", CIT_OK);
1432 void cmd_gtsn(char *argbuf) {
1435 if (CtdlAccessCheck(ac_logged_in)) {
1439 CtdlGetSeen(buf, ctdlsetseen_seen);
1440 cprintf("%d %s\n", CIT_OK, buf);
1445 * API function for cmd_invt_kick() and anything else that needs to
1446 * invite or kick out a user to/from a room.
1448 * Set iuser to the name of the user, and op to 1=invite or 0=kick
1450 int CtdlInvtKick(char *iuser, int op) {
1451 struct ctdluser USscratch;
1455 if (getuser(&USscratch, iuser) != 0) {
1459 CtdlGetRelationship(&vbuf, &USscratch, &CC->room);
1461 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
1462 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
1465 vbuf.v_flags = vbuf.v_flags & ~V_ACCESS;
1466 vbuf.v_flags = vbuf.v_flags | V_FORGET | V_LOCKOUT;
1468 CtdlSetRelationship(&vbuf, &USscratch, &CC->room);
1470 /* post a message in Aide> saying what we just did */
1471 snprintf(bbb, sizeof bbb, "%s has been %s \"%s\" by %s.\n",
1473 ((op == 1) ? "invited to" : "kicked out of"),
1476 aide_message(bbb,"User Admin Message");
1483 * INVT and KICK commands
1485 void cmd_invt_kick(char *iuser, int op) {
1488 * These commands are only allowed by aides, room aides,
1489 * and room namespace owners
1492 || (atol(CC->room.QRname) == CC->user.usernum) ) {
1493 /* access granted */
1496 cprintf("%d Higher access or room ownership required.\n",
1497 ERROR + HIGHER_ACCESS_REQUIRED);
1501 if (!strncasecmp(CC->room.QRname, config.c_baseroom,
1503 cprintf("%d Can't add/remove users from this room.\n",
1508 if (CtdlInvtKick(iuser, op) != 0) {
1509 cprintf("%d No such user.\n", ERROR + NO_SUCH_USER);
1513 cprintf("%d %s %s %s.\n",
1515 ((op == 1) ? "invited to" : "kicked out of"),
1522 * Forget (Zap) the current room (API call)
1523 * Returns 0 on success
1525 int CtdlForgetThisRoom(void) {
1528 /* On some systems, Aides are not allowed to forget rooms */
1529 if (is_aide() && (config.c_aide_zap == 0)
1530 && ((CC->room.QRflags & QR_MAILBOX) == 0) ) {
1534 lgetuser(&CC->user, CC->curr_user);
1535 CtdlGetRelationship(&vbuf, &CC->user, &CC->room);
1537 vbuf.v_flags = vbuf.v_flags | V_FORGET;
1538 vbuf.v_flags = vbuf.v_flags & ~V_ACCESS;
1540 CtdlSetRelationship(&vbuf, &CC->user, &CC->room);
1541 lputuser(&CC->user);
1543 /* Return to the Lobby, so we don't end up in an undefined room */
1544 usergoto(config.c_baseroom, 0, 0, NULL, NULL);
1551 * forget (Zap) the current room
1556 if (CtdlAccessCheck(ac_logged_in)) {
1560 if (CtdlForgetThisRoom() == 0) {
1561 cprintf("%d Ok\n", CIT_OK);
1564 cprintf("%d You may not forget this room.\n", ERROR + NOT_HERE);
1569 * Get Next Unregistered User
1573 struct cdbdata *cdbus;
1574 struct ctdluser usbuf;
1576 if (CtdlAccessCheck(ac_aide)) {
1580 if ((CitControl.MMflags & MM_VALID) == 0) {
1581 cprintf("%d There are no unvalidated users.\n", CIT_OK);
1585 /* There are unvalidated users. Traverse the user database,
1586 * and return the first user we find that needs validation.
1588 cdb_rewind(CDB_USERS);
1589 while (cdbus = cdb_next_item(CDB_USERS), cdbus != NULL) {
1590 memset(&usbuf, 0, sizeof(struct ctdluser));
1591 memcpy(&usbuf, cdbus->ptr,
1592 ((cdbus->len > sizeof(struct ctdluser)) ?
1593 sizeof(struct ctdluser) : cdbus->len));
1595 if ((usbuf.flags & US_NEEDVALID)
1596 && (usbuf.axlevel > 0)) {
1597 cprintf("%d %s\n", MORE_DATA, usbuf.fullname);
1598 cdb_close_cursor(CDB_USERS);
1603 /* If we get to this point, there are no more unvalidated users.
1604 * Therefore we clear the "users need validation" flag.
1607 begin_critical_section(S_CONTROL);
1609 CitControl.MMflags = CitControl.MMflags & (~MM_VALID);
1611 end_critical_section(S_CONTROL);
1612 cprintf("%d *** End of registration.\n", CIT_OK);
1621 void cmd_vali(char *v_args)
1625 struct ctdluser userbuf;
1627 extract_token(user, v_args, 0, '|', sizeof user);
1628 newax = extract_int(v_args, 1);
1630 if (CtdlAccessCheck(ac_aide)) {
1634 if (lgetuser(&userbuf, user) != 0) {
1635 cprintf("%d '%s' not found.\n", ERROR + NO_SUCH_USER, user);
1639 userbuf.axlevel = newax;
1640 userbuf.flags = (userbuf.flags & ~US_NEEDVALID);
1644 /* If the access level was set to zero, delete the user */
1646 if (purge_user(user) == 0) {
1647 cprintf("%d %s Deleted.\n", CIT_OK, userbuf.fullname);
1651 cprintf("%d User '%s' validated.\n", CIT_OK, userbuf.fullname);
1657 * Traverse the user file...
1659 void ForEachUser(void (*CallBack) (struct ctdluser * EachUser, void *out_data),
1662 struct ctdluser usbuf;
1663 struct cdbdata *cdbus;
1665 cdb_rewind(CDB_USERS);
1667 while (cdbus = cdb_next_item(CDB_USERS), cdbus != NULL) {
1668 memset(&usbuf, 0, sizeof(struct ctdluser));
1669 memcpy(&usbuf, cdbus->ptr,
1670 ((cdbus->len > sizeof(struct ctdluser)) ?
1671 sizeof(struct ctdluser) : cdbus->len));
1673 (*CallBack) (&usbuf, in_data);
1679 * List one user (this works with cmd_list)
1681 void ListThisUser(struct ctdluser *usbuf, void *data)
1685 searchstring = (char *)data;
1686 if (bmstrcasestr(usbuf->fullname, searchstring) == NULL) {
1690 if (usbuf->axlevel > 0) {
1691 if ((CC->user.axlevel >= 6)
1692 || ((usbuf->flags & US_UNLISTED) == 0)
1693 || ((CC->internal_pgm))) {
1694 cprintf("%s|%d|%ld|%ld|%ld|%ld||\n",
1698 (long)usbuf->lastcall,
1706 * List users (searchstring may be empty to list all users)
1708 void cmd_list(char *cmdbuf)
1710 char searchstring[256];
1711 extract_token(searchstring, cmdbuf, 0, '|', sizeof searchstring);
1712 striplt(searchstring);
1713 cprintf("%d \n", LISTING_FOLLOWS);
1714 ForEachUser(ListThisUser, (void *)searchstring );
1722 * assorted info we need to check at login
1730 if (CtdlAccessCheck(ac_logged_in)) {
1734 getuser(&CC->user, CC->curr_user); /* no lock is needed here */
1735 if ((REGISCALL != 0) && ((CC->user.flags & US_REGIS) == 0))
1738 if (CC->user.axlevel >= 6) {
1740 if (CitControl.MMflags & MM_VALID)
1744 /* check for mail */
1745 mail = InitialMailCheck();
1747 cprintf("%d %d|%d|%d|%s|\n", CIT_OK, mail, regis, vali, CC->cs_inet_email);
1752 * check to see if a user exists
1754 void cmd_qusr(char *who)
1756 struct ctdluser usbuf;
1758 if (getuser(&usbuf, who) == 0) {
1759 cprintf("%d %s\n", CIT_OK, usbuf.fullname);
1761 cprintf("%d No such user.\n", ERROR + NO_SUCH_USER);
1767 * Administrative Get User Parameters
1769 void cmd_agup(char *cmdbuf)
1771 struct ctdluser usbuf;
1772 char requested_user[128];
1774 if (CtdlAccessCheck(ac_aide)) {
1778 extract_token(requested_user, cmdbuf, 0, '|', sizeof requested_user);
1779 if (getuser(&usbuf, requested_user) != 0) {
1780 cprintf("%d No such user.\n", ERROR + NO_SUCH_USER);
1783 cprintf("%d %s|%s|%u|%ld|%ld|%d|%ld|%ld|%d\n",
1790 (int) usbuf.axlevel,
1792 (long)usbuf.lastcall,
1799 * Administrative Set User Parameters
1801 void cmd_asup(char *cmdbuf)
1803 struct ctdluser usbuf;
1804 char requested_user[128];
1810 if (CtdlAccessCheck(ac_aide))
1813 extract_token(requested_user, cmdbuf, 0, '|', sizeof requested_user);
1814 if (lgetuser(&usbuf, requested_user) != 0) {
1815 cprintf("%d No such user.\n", ERROR + NO_SUCH_USER);
1818 np = num_parms(cmdbuf);
1820 extract_token(usbuf.password, cmdbuf, 1, '|', sizeof usbuf.password);
1822 usbuf.flags = extract_int(cmdbuf, 2);
1824 usbuf.timescalled = extract_int(cmdbuf, 3);
1826 usbuf.posted = extract_int(cmdbuf, 4);
1828 newax = extract_int(cmdbuf, 5);
1829 if ((newax >= 0) && (newax <= 6)) {
1830 usbuf.axlevel = extract_int(cmdbuf, 5);
1834 usbuf.lastcall = extract_long(cmdbuf, 7);
1837 usbuf.USuserpurge = extract_int(cmdbuf, 8);
1840 if (usbuf.axlevel == 0) {
1841 if (purge_user(requested_user) == 0) {
1847 snprintf(notify, SIZ,
1848 "User \"%s\" has been deleted by %s.\n",
1849 usbuf.fullname, CC->user.fullname);
1850 aide_message(notify, "User Deletion Message");
1853 cprintf("%d Ok", CIT_OK);
1855 cprintf(" (%s deleted)", requested_user);
1862 * Check to see if the user who we just sent mail to is logged in. If yes,
1863 * bump the 'new mail' counter for their session. That enables them to
1864 * receive a new mail notification without having to hit the database.
1866 void BumpNewMailCounter(long which_user) {
1867 struct CitContext *ptr;
1869 begin_critical_section(S_SESSION_TABLE);
1871 for (ptr = ContextList; ptr != NULL; ptr = ptr->next) {
1872 if (ptr->user.usernum == which_user) {
1877 end_critical_section(S_SESSION_TABLE);
1882 * Count the number of new mail messages the user has
1886 int num_newmsgs = 0;
1888 num_newmsgs = CC->newmail;
1891 return (num_newmsgs);
1896 * Count the number of new mail messages the user has
1898 int InitialMailCheck()
1900 int num_newmsgs = 0;
1902 char mailboxname[ROOMNAMELEN];
1903 struct ctdlroom mailbox;
1905 struct cdbdata *cdbfr;
1906 long *msglist = NULL;
1909 MailboxName(mailboxname, sizeof mailboxname, &CC->user, MAILROOM);
1910 if (getroom(&mailbox, mailboxname) != 0)
1912 CtdlGetRelationship(&vbuf, &CC->user, &mailbox);
1914 cdbfr = cdb_fetch(CDB_MSGLISTS, &mailbox.QRnumber, sizeof(long));
1916 if (cdbfr != NULL) {
1917 msglist = malloc(cdbfr->len);
1918 memcpy(msglist, cdbfr->ptr, cdbfr->len);
1919 num_msgs = cdbfr->len / sizeof(long);
1923 for (a = 0; a < num_msgs; ++a) {
1924 if (msglist[a] > 0L) {
1925 if (msglist[a] > vbuf.v_lastseen) {
1930 if (msglist != NULL)
1933 return (num_newmsgs);
1939 * Set the preferred view for the current user/room combination
1941 void cmd_view(char *cmdbuf) {
1945 if (CtdlAccessCheck(ac_logged_in)) {
1949 requested_view = extract_int(cmdbuf, 0);
1951 CtdlGetRelationship(&vbuf, &CC->user, &CC->room);
1952 vbuf.v_view = requested_view;
1953 CtdlSetRelationship(&vbuf, &CC->user, &CC->room);
1955 cprintf("%d ok\n", CIT_OK);
1962 void cmd_renu(char *cmdbuf)
1965 char oldname[USERNAME_SIZE];
1966 char newname[USERNAME_SIZE];
1968 if (CtdlAccessCheck(ac_aide)) {
1972 extract_token(oldname, cmdbuf, 0, '|', sizeof oldname);
1973 extract_token(newname, cmdbuf, 1, '|', sizeof newname);
1975 retcode = rename_user(oldname, newname);
1978 cprintf("%d '%s' has been renamed to '%s'.\n", CIT_OK, oldname, newname);
1980 case RENAMEUSER_LOGGED_IN:
1981 cprintf("%d '%s' is currently logged in and cannot be renamed.\n",
1982 ERROR + ALREADY_LOGGED_IN , oldname);
1984 case RENAMEUSER_NOT_FOUND:
1985 cprintf("%d '%s' does not exist.\n", ERROR + NO_SUCH_USER, oldname);
1987 case RENAMEUSER_ALREADY_EXISTS:
1988 cprintf("%d A user named '%s' already exists.\n", ERROR + ALREADY_EXISTS, newname);
1992 cprintf("%d An unknown error occurred.\n", ERROR);