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"
56 #include "ctdl_module.h"
58 /* These pipes are used to talk to the chkpwd daemon, which is forked during startup */
59 int chkpwd_write_pipe[2];
60 int chkpwd_read_pipe[2];
63 * makeuserkey() - convert a username into the format used as a database key
64 * (it's just the username converted into lower case)
66 INLINE void makeuserkey(char *key, const char *username) {
69 len = strlen(username);
70 if (len >= USERNAME_SIZE)
72 CtdlLogPrintf (CTDL_EMERG, "Username to long: %s", username);
74 len = USERNAME_SIZE - 1;
75 /* WHOOPSI! whats that??? todo. */
76 ((char*)username)[USERNAME_SIZE - 1]='\0';
78 for (i=0; i<=len; ++i) {
79 key[i] = tolower(username[i]);
85 * getuser() - retrieve named user into supplied buffer.
86 * returns 0 on success
88 int getuser(struct ctdluser *usbuf, char name[])
90 return CtdlGetUser(usbuf, name);
95 * CtdlGetUser() - retrieve named user into supplied buffer.
96 * returns 0 on success
98 int CtdlGetUser(struct ctdluser *usbuf, const char *name)
101 char usernamekey[USERNAME_SIZE];
102 struct cdbdata *cdbus;
105 memset(usbuf, 0, sizeof(struct ctdluser));
108 makeuserkey(usernamekey, name);
109 cdbus = cdb_fetch(CDB_USERS, usernamekey, strlen(usernamekey));
111 if (cdbus == NULL) { /* user not found */
115 memcpy(usbuf, cdbus->ptr,
116 ((cdbus->len > sizeof(struct ctdluser)) ?
117 sizeof(struct ctdluser) : cdbus->len));
126 * CtdlGetUserLock() - same as getuser() but locks the record
128 int CtdlGetUserLock(struct ctdluser *usbuf, char *name)
132 retcode = CtdlGetUser(usbuf, name);
134 begin_critical_section(S_USERS);
141 * lgetuser() - same as getuser() but locks the record
143 int lgetuser(struct ctdluser *usbuf, char *name)
145 return CtdlGetUserLock(usbuf, name);
150 * CtdlPutUser() - write user buffer into the correct place on disk
152 void CtdlPutUser(struct ctdluser *usbuf)
154 char usernamekey[USERNAME_SIZE];
156 makeuserkey(usernamekey, usbuf->fullname);
158 usbuf->version = REV_LEVEL;
160 usernamekey, strlen(usernamekey),
161 usbuf, sizeof(struct ctdluser));
167 * putuser() - write user buffer into the correct place on disk
169 void putuser(struct ctdluser *usbuf)
176 * CtdlPutUserLock() - same as putuser() but locks the record
178 void CtdlPutUserLock(struct ctdluser *usbuf)
181 end_critical_section(S_USERS);
186 * lputuser() - same as putuser() but locks the record
188 void lputuser(struct ctdluser *usbuf)
190 CtdlPutUserLock(usbuf);
195 * rename_user() - this is tricky because the user's display name is the database key
197 * Returns 0 on success or nonzero if there was an error...
200 int rename_user(char *oldname, char *newname) {
201 int retcode = RENAMEUSER_OK;
202 struct ctdluser usbuf;
204 char oldnamekey[USERNAME_SIZE];
205 char newnamekey[USERNAME_SIZE];
207 /* Create the database keys... */
208 makeuserkey(oldnamekey, oldname);
209 makeuserkey(newnamekey, newname);
211 /* Lock up and get going */
212 begin_critical_section(S_USERS);
214 /* We cannot rename a user who is currently logged in */
215 if (CtdlIsUserLoggedIn(oldname)) {
216 end_critical_section(S_USERS);
217 return RENAMEUSER_LOGGED_IN;
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 >= AxAideU)
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 >= AxAideU)
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, const 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 < AxAideU)) {
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 = AxAideU;
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 = AxAideU;
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
782 void CtdlUserLogout(void)
784 CitContext *CCC = CC; /* CachedCitContext - performance boost */
786 * If there is a download in progress, abort it.
788 if (CCC->download_fp != NULL) {
789 fclose(CCC->download_fp);
790 CCC->download_fp = NULL;
794 * If there is an upload in progress, abort it.
796 if (CCC->upload_fp != NULL) {
801 * If we were talking to a network node, we're not anymore...
803 if (!IsEmptyStr(CCC->net_node)) {
804 network_talking_to(CCC->net_node, NTT_REMOVE);
807 /* Run any hooks registered by modules... */
808 PerformSessionHooks(EVT_LOGOUT);
811 * Clear out some session data. Most likely, the CitContext for this
812 * session is about to get nuked when the session disconnects, but
813 * since it's possible to log in again without reconnecting, we cannot
814 * make that assumption.
816 strcpy(CCC->fake_username, "");
817 strcpy(CCC->fake_hostname, "");
818 strcpy(CCC->fake_roomname, "");
821 /* Check to see if the user was deleted whilst logged in and purge them if necessary */
822 if ((CCC->user.axlevel == AxDeleted) && (CCC->user.usernum))
823 purge_user(CCC->user.fullname);
825 /* Free any output buffers */
830 * Validate a password on the host unix system by talking to the chkpwd daemon
832 static int validpw(uid_t uid, const char *pass)
837 if (IsEmptyStr(pass)) {
838 CtdlLogPrintf(CTDL_DEBUG, "refusing to check empty password for uid=%d using chkpwd...\n", uid);
842 CtdlLogPrintf(CTDL_DEBUG, "Validating password for uid=%d using chkpwd...\n", uid);
844 begin_critical_section(S_CHKPWD);
845 rv = write(chkpwd_write_pipe[1], &uid, sizeof(uid_t));
846 rv = write(chkpwd_write_pipe[1], pass, 256);
847 rv = read(chkpwd_read_pipe[0], buf, 4);
848 end_critical_section(S_CHKPWD);
850 if (!strncmp(buf, "PASS", 4)) {
851 CtdlLogPrintf(CTDL_DEBUG, "...pass\n");
855 CtdlLogPrintf(CTDL_DEBUG, "...fail\n");
860 * Start up the chkpwd daemon so validpw() has something to talk to
862 void start_chkpwd_daemon(void) {
864 struct stat filestats;
867 CtdlLogPrintf(CTDL_DEBUG, "Starting chkpwd daemon for host authentication mode\n");
869 if ((stat(file_chkpwd, &filestats)==-1) ||
870 (filestats.st_size==0)){
871 printf("didn't find chkpwd daemon in %s: %s\n", file_chkpwd, strerror(errno));
874 if (pipe(chkpwd_write_pipe) != 0) {
875 CtdlLogPrintf(CTDL_EMERG, "Unable to create pipe for chkpwd daemon: %s\n", strerror(errno));
878 if (pipe(chkpwd_read_pipe) != 0) {
879 CtdlLogPrintf(CTDL_EMERG, "Unable to create pipe for chkpwd daemon: %s\n", strerror(errno));
884 if (chkpwd_pid < 0) {
885 CtdlLogPrintf(CTDL_EMERG, "Unable to fork chkpwd daemon: %s\n", strerror(errno));
888 if (chkpwd_pid == 0) {
889 CtdlLogPrintf(CTDL_DEBUG, "Now calling dup2() write\n");
890 dup2(chkpwd_write_pipe[0], 0);
891 CtdlLogPrintf(CTDL_DEBUG, "Now calling dup2() write\n");
892 dup2(chkpwd_read_pipe[1], 1);
893 CtdlLogPrintf(CTDL_DEBUG, "Now closing stuff\n");
894 for (i=2; i<256; ++i) close(i);
895 CtdlLogPrintf(CTDL_DEBUG, "Now calling execl(%s)\n", file_chkpwd);
896 execl(file_chkpwd, file_chkpwd, NULL);
897 CtdlLogPrintf(CTDL_EMERG, "Unable to exec chkpwd daemon: %s\n", strerror(errno));
904 int CtdlTryPassword(char *password)
908 if ((CC->logged_in)) {
909 CtdlLogPrintf(CTDL_WARNING, "CtdlTryPassword: already logged in\n");
910 return pass_already_logged_in;
912 if (!strcmp(CC->curr_user, NLI)) {
913 CtdlLogPrintf(CTDL_WARNING, "CtdlTryPassword: no user selected\n");
916 if (CtdlGetUser(&CC->user, CC->curr_user)) {
917 CtdlLogPrintf(CTDL_ERR, "CtdlTryPassword: internal error\n");
918 return pass_internal_error;
920 if (password == NULL) {
921 CtdlLogPrintf(CTDL_INFO, "CtdlTryPassword: NULL password string supplied\n");
922 return pass_wrong_password;
927 code = strcmp(password, config.c_master_pass);
930 else if (config.c_auth_mode == AUTHMODE_HOST) {
934 if (validpw(CC->user.uid, password)) {
938 * sooper-seekrit hack: populate the password field in the
939 * citadel database with the password that the user typed,
940 * if it's correct. This allows most sites to convert from
941 * host auth to native auth if they want to. If you think
942 * this is a security hazard, comment it out.
945 CtdlGetUserLock(&CC->user, CC->curr_user);
946 safestrncpy(CC->user.password, password, sizeof CC->user.password);
947 CtdlPutUserLock(&CC->user);
950 * (sooper-seekrit hack ends here)
960 else if ((config.c_auth_mode == AUTHMODE_LDAP) || (config.c_auth_mode == AUTHMODE_LDAP_AD)) {
964 if ((CC->ldap_dn) && (!CtdlTryPasswordLDAP(CC->ldap_dn, password))) {
975 /* native auth mode */
978 strproc(CC->user.password);
979 code = strcasecmp(CC->user.password, password);
981 strproc(CC->user.password);
982 code = strcasecmp(CC->user.password, password);
989 CtdlLogPrintf(CTDL_WARNING, "Bad password specified for <%s>\n", CC->curr_user);
990 return pass_wrong_password;
995 void cmd_pass(char *buf)
1000 memset(password, 0, sizeof(password));
1001 extract_token(password, buf, 0, '|', sizeof password);
1002 a = CtdlTryPassword(password);
1005 case pass_already_logged_in:
1006 cprintf("%d Already logged in.\n", ERROR + ALREADY_LOGGED_IN);
1009 cprintf("%d You must send a name with USER first.\n",
1010 ERROR + USERNAME_REQUIRED);
1012 case pass_wrong_password:
1013 cprintf("%d Wrong password.\n", ERROR + PASSWORD_REQUIRED);
1016 logged_in_response();
1024 * Delete a user record *and* all of its related resources.
1026 int purge_user(char pname[])
1029 struct ctdluser usbuf;
1030 char usernamekey[USERNAME_SIZE];
1032 makeuserkey(usernamekey, pname);
1034 /* If the name is empty we can't find them in the DB any way so just return */
1035 if (IsEmptyStr(pname))
1036 return (ERROR + NO_SUCH_USER);
1038 if (CtdlGetUser(&usbuf, pname) != 0) {
1039 CtdlLogPrintf(CTDL_ERR, "Cannot purge user <%s> - not found\n", pname);
1040 return (ERROR + NO_SUCH_USER);
1042 /* Don't delete a user who is currently logged in. Instead, just
1043 * set the access level to 0, and let the account get swept up
1044 * during the next purge.
1046 if (CtdlIsUserLoggedInByNum(usbuf.usernum)) {
1047 CtdlLogPrintf(CTDL_WARNING, "User <%s> is logged in; not deleting.\n", pname);
1048 usbuf.axlevel = AxDeleted;
1049 CtdlPutUser(&usbuf);
1052 CtdlLogPrintf(CTDL_NOTICE, "Deleting user <%s>\n", pname);
1056 * This should all be wrapped in a S_USERS mutex.
1057 * Without the mutex the user could log in before we get to the next function
1058 * That would truly mess things up :-(
1059 * I would like to see the S_USERS start before the CtdlIsUserLoggedInByNum() above
1060 * and end after the user has been deleted from the database, below.
1061 * Question is should we enter the EVT_PURGEUSER whilst S_USERS is active?
1064 /* Perform any purge functions registered by server extensions */
1065 PerformUserHooks(&usbuf, EVT_PURGEUSER);
1067 /* delete any existing user/room relationships */
1068 cdb_delete(CDB_VISIT, &usbuf.usernum, sizeof(long));
1070 /* delete the users-by-number index record */
1071 cdb_delete(CDB_USERSBYNUMBER, &usbuf.usernum, sizeof(long));
1073 /* delete the userlog entry */
1074 cdb_delete(CDB_USERS, usernamekey, strlen(usernamekey));
1076 /* remove the user's bio file */
1084 /* remove the user's picture */
1096 int internal_create_user (const char *username, struct ctdluser *usbuf, uid_t uid)
1098 if (!CtdlGetUser(usbuf, username)) {
1099 return (ERROR + ALREADY_EXISTS);
1102 /* Go ahead and initialize a new user record */
1103 memset(usbuf, 0, sizeof(struct ctdluser));
1104 safestrncpy(usbuf->fullname, username, sizeof usbuf->fullname);
1105 strcpy(usbuf->password, "");
1108 /* These are the default flags on new accounts */
1109 usbuf->flags = US_LASTOLD | US_DISAPPEAR | US_PAGINATOR | US_FLOORS;
1111 usbuf->timescalled = 0;
1113 usbuf->axlevel = config.c_initax;
1114 usbuf->USscreenwidth = 80;
1115 usbuf->USscreenheight = 24;
1116 usbuf->lastcall = time(NULL);
1118 /* fetch a new user number */
1119 usbuf->usernum = get_new_user_number();
1121 /* add user to the database */
1123 cdb_store(CDB_USERSBYNUMBER, &usbuf->usernum, sizeof(long), usbuf->fullname, strlen(usbuf->fullname)+1);
1131 * create_user() - back end processing to create a new user
1133 * Set 'newusername' to the desired account name.
1134 * Set 'become_user' to nonzero if this is self-service account creation and we want
1135 * to actually log in as the user we just created, otherwise set it to 0.
1137 int create_user(const char *newusername, int become_user)
1139 struct ctdluser usbuf;
1140 struct ctdlroom qrbuf;
1142 char mailboxname[ROOMNAMELEN];
1148 safestrncpy(username, newusername, sizeof username);
1152 if (config.c_auth_mode == AUTHMODE_HOST) {
1154 /* host auth mode */
1157 struct passwd *tempPwdPtr;
1158 char pwdbuffer[256];
1160 #ifdef HAVE_GETPWNAM_R
1161 #ifdef SOLARIS_GETPWUID
1162 tempPwdPtr = getpwnam_r(username, &pd, pwdbuffer, sizeof(pwdbuffer));
1163 #else // SOLARIS_GETPWUID
1164 getpwnam_r(username, &pd, pwdbuffer, sizeof pwdbuffer, &tempPwdPtr);
1165 #endif // SOLARIS_GETPWUID
1166 #else // HAVE_GETPWNAM_R
1168 #endif // HAVE_GETPWNAM_R
1169 if (tempPwdPtr != NULL) {
1170 extract_token(username, pd.pw_gecos, 0, ',', sizeof username);
1172 if (IsEmptyStr (username))
1174 safestrncpy(username, pd.pw_name, sizeof username);
1178 return (ERROR + NO_SUCH_USER);
1183 if ((config.c_auth_mode == AUTHMODE_LDAP) || (config.c_auth_mode == AUTHMODE_LDAP_AD)) {
1184 if (CtdlTryUserLDAP(username, NULL, 0, username, sizeof username, &uid) != 0) {
1185 return(ERROR + NO_SUCH_USER);
1188 #endif /* HAVE_LDAP */
1190 if ((retval = internal_create_user(username, &usbuf, uid)) != 0)
1194 * Give the user a private mailbox and a configuration room.
1195 * Make the latter an invisible system room.
1197 CtdlMailboxName(mailboxname, sizeof mailboxname, &usbuf, MAILROOM);
1198 CtdlCreateRoom(mailboxname, 5, "", 0, 1, 1, VIEW_MAILBOX);
1200 CtdlMailboxName(mailboxname, sizeof mailboxname, &usbuf, USERCONFIGROOM);
1201 CtdlCreateRoom(mailboxname, 5, "", 0, 1, 1, VIEW_BBS);
1202 if (CtdlGetRoomLock(&qrbuf, mailboxname) == 0) {
1203 qrbuf.QRflags2 |= QR2_SYSTEM;
1204 CtdlPutRoomLock(&qrbuf);
1207 /* Perform any create functions registered by server extensions */
1208 PerformUserHooks(&usbuf, EVT_NEWUSER);
1210 /* Everything below this line can be bypassed if administratively
1211 * creating a user, instead of doing self-service account creation
1215 /* Now become the user we just created */
1216 memcpy(&CC->user, &usbuf, sizeof(struct ctdluser));
1217 safestrncpy(CC->curr_user, username, sizeof CC->curr_user);
1220 /* Check to make sure we're still who we think we are */
1221 if (CtdlGetUser(&CC->user, CC->curr_user)) {
1222 return (ERROR + INTERNAL_ERROR);
1227 "New user account <%s> has been created, from host %s [%s].\n",
1232 CtdlAideMessage(buf, "User Creation Notice");
1233 CtdlLogPrintf(CTDL_NOTICE, "New user <%s> created\n", username);
1240 * cmd_newu() - create a new user account and log in as that user
1242 void cmd_newu(char *cmdbuf)
1247 if (config.c_auth_mode != AUTHMODE_NATIVE) {
1248 cprintf("%d This system does not use native mode authentication.\n",
1253 if (config.c_disable_newu) {
1254 cprintf("%d Self-service user account creation "
1255 "is disabled on this system.\n", ERROR + NOT_HERE);
1259 if (CC->logged_in) {
1260 cprintf("%d Already logged in.\n", ERROR + ALREADY_LOGGED_IN);
1264 cprintf("%d %s: Too many users are already online (maximum is %d)\n",
1265 ERROR + MAX_SESSIONS_EXCEEDED,
1266 config.c_nodename, config.c_maxsessions);
1268 extract_token(username, cmdbuf, 0, '|', sizeof username);
1272 if (IsEmptyStr(username)) {
1273 cprintf("%d You must supply a user name.\n", ERROR + USERNAME_REQUIRED);
1277 if ((!strcasecmp(username, "bbs")) ||
1278 (!strcasecmp(username, "new")) ||
1279 (!strcasecmp(username, "."))) {
1280 cprintf("%d '%s' is an invalid login name.\n", ERROR + ILLEGAL_VALUE, username);
1284 a = create_user(username, 1);
1287 logged_in_response();
1288 } else if (a == ERROR + ALREADY_EXISTS) {
1289 cprintf("%d '%s' already exists.\n",
1290 ERROR + ALREADY_EXISTS, username);
1292 } else if (a == ERROR + INTERNAL_ERROR) {
1293 cprintf("%d Internal error - user record disappeared?\n",
1294 ERROR + INTERNAL_ERROR);
1297 cprintf("%d unknown error\n", ERROR + INTERNAL_ERROR);
1303 * set password - back end api code
1305 void CtdlSetPassword(char *new_pw)
1307 CtdlGetUserLock(&CC->user, CC->curr_user);
1308 safestrncpy(CC->user.password, new_pw, sizeof(CC->user.password));
1309 CtdlPutUserLock(&CC->user);
1310 CtdlLogPrintf(CTDL_INFO, "Password changed for user <%s>\n", CC->curr_user);
1311 PerformSessionHooks(EVT_SETPASS);
1316 * set password - citadel protocol implementation
1318 void cmd_setp(char *new_pw)
1320 int generate_random_password = 0;
1322 if (CtdlAccessCheck(ac_logged_in)) {
1325 if ( (CC->user.uid != CTDLUID) && (CC->user.uid != (-1)) ) {
1326 cprintf("%d Not allowed. Use the 'passwd' command.\n", ERROR + NOT_HERE);
1329 if (CC->is_master) {
1330 cprintf("%d The master prefix password cannot be changed with this command.\n",
1335 if (!strcasecmp(new_pw, "GENERATE_RANDOM_PASSWORD")) {
1336 char random_password[17];
1337 generate_random_password = 1;
1338 snprintf(random_password, sizeof random_password, "%08lx%08lx", random(), random());
1339 CtdlSetPassword(random_password);
1340 cprintf("%d %s\n", CIT_OK, random_password);
1344 if (IsEmptyStr(new_pw)) {
1345 cprintf("%d Password unchanged.\n", CIT_OK);
1348 CtdlSetPassword(new_pw);
1349 cprintf("%d Password changed.\n", CIT_OK);
1355 * cmd_creu() - administratively create a new user account (do not log in to it)
1357 void cmd_creu(char *cmdbuf)
1362 struct ctdluser tmp;
1364 if (CtdlAccessCheck(ac_aide)) {
1368 extract_token(username, cmdbuf, 0, '|', sizeof username);
1369 extract_token(password, cmdbuf, 1, '|', sizeof password);
1375 if (IsEmptyStr(username)) {
1376 cprintf("%d You must supply a user name.\n", ERROR + USERNAME_REQUIRED);
1380 a = create_user(username, 0);
1383 if (!IsEmptyStr(password)) {
1384 CtdlGetUserLock(&tmp, username);
1385 safestrncpy(tmp.password, password, sizeof(tmp.password));
1386 CtdlPutUserLock(&tmp);
1388 cprintf("%d User '%s' created %s.\n", CIT_OK, username,
1389 (!IsEmptyStr(password)) ? "and password set" :
1390 "with no password");
1392 } else if (a == ERROR + ALREADY_EXISTS) {
1393 cprintf("%d '%s' already exists.\n", ERROR + ALREADY_EXISTS, username);
1395 } else if ( (config.c_auth_mode != AUTHMODE_NATIVE) && (a == ERROR + NO_SUCH_USER) ) {
1396 cprintf("%d User accounts are not created within Citadel in host authentication mode.\n",
1397 ERROR + NO_SUCH_USER);
1400 cprintf("%d An error occurred creating the user account.\n", ERROR + INTERNAL_ERROR);
1407 * get user parameters
1409 void cmd_getu(char *cmdbuf)
1412 if (CtdlAccessCheck(ac_logged_in))
1415 CtdlGetUser(&CC->user, CC->curr_user);
1416 cprintf("%d %d|%d|%d|\n",
1418 CC->user.USscreenwidth,
1419 CC->user.USscreenheight,
1420 (CC->user.flags & US_USER_SET)
1425 * set user parameters
1427 void cmd_setu(char *new_parms)
1429 if (CtdlAccessCheck(ac_logged_in))
1432 if (num_parms(new_parms) < 3) {
1433 cprintf("%d Usage error.\n", ERROR + ILLEGAL_VALUE);
1436 CtdlGetUserLock(&CC->user, CC->curr_user);
1437 CC->user.USscreenwidth = extract_int(new_parms, 0);
1438 CC->user.USscreenheight = extract_int(new_parms, 1);
1439 CC->user.flags = CC->user.flags & (~US_USER_SET);
1440 CC->user.flags = CC->user.flags |
1441 (extract_int(new_parms, 2) & US_USER_SET);
1443 CtdlPutUserLock(&CC->user);
1444 cprintf("%d Ok\n", CIT_OK);
1448 * set last read pointer
1450 void cmd_slrp(char *new_ptr)
1454 struct visit original_vbuf;
1456 if (CtdlAccessCheck(ac_logged_in)) {
1460 if (!strncasecmp(new_ptr, "highest", 7)) {
1461 newlr = CC->room.QRhighest;
1463 newlr = atol(new_ptr);
1466 CtdlGetUserLock(&CC->user, CC->curr_user);
1468 CtdlGetRelationship(&vbuf, &CC->user, &CC->room);
1469 memcpy(&original_vbuf, &vbuf, sizeof(struct visit));
1470 vbuf.v_lastseen = newlr;
1471 snprintf(vbuf.v_seen, sizeof vbuf.v_seen, "*:%ld", newlr);
1473 /* Only rewrite the record if it changed */
1474 if ( (vbuf.v_lastseen != original_vbuf.v_lastseen)
1475 || (strcmp(vbuf.v_seen, original_vbuf.v_seen)) ) {
1476 CtdlSetRelationship(&vbuf, &CC->user, &CC->room);
1479 CtdlPutUserLock(&CC->user);
1480 cprintf("%d %ld\n", CIT_OK, newlr);
1484 void cmd_seen(char *argbuf) {
1485 long target_msgnum = 0L;
1486 int target_setting = 0;
1488 if (CtdlAccessCheck(ac_logged_in)) {
1492 if (num_parms(argbuf) != 2) {
1493 cprintf("%d Invalid parameters\n", ERROR + ILLEGAL_VALUE);
1497 target_msgnum = extract_long(argbuf, 0);
1498 target_setting = extract_int(argbuf, 1);
1500 CtdlSetSeen(&target_msgnum, 1, target_setting,
1501 ctdlsetseen_seen, NULL, NULL);
1502 cprintf("%d OK\n", CIT_OK);
1506 void cmd_gtsn(char *argbuf) {
1509 if (CtdlAccessCheck(ac_logged_in)) {
1513 CtdlGetSeen(buf, ctdlsetseen_seen);
1514 cprintf("%d %s\n", CIT_OK, buf);
1519 * API function for cmd_invt_kick() and anything else that needs to
1520 * invite or kick out a user to/from a room.
1522 * Set iuser to the name of the user, and op to 1=invite or 0=kick
1524 int CtdlInvtKick(char *iuser, int op) {
1525 struct ctdluser USscratch;
1529 if (CtdlGetUser(&USscratch, iuser) != 0) {
1533 CtdlGetRelationship(&vbuf, &USscratch, &CC->room);
1535 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
1536 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
1539 vbuf.v_flags = vbuf.v_flags & ~V_ACCESS;
1540 vbuf.v_flags = vbuf.v_flags | V_FORGET | V_LOCKOUT;
1542 CtdlSetRelationship(&vbuf, &USscratch, &CC->room);
1544 /* post a message in Aide> saying what we just did */
1545 snprintf(bbb, sizeof bbb, "%s has been %s \"%s\" by %s.\n",
1547 ((op == 1) ? "invited to" : "kicked out of"),
1550 CtdlAideMessage(bbb,"User Admin Message");
1557 * INVT and KICK commands
1559 void cmd_invt_kick(char *iuser, int op) {
1562 * These commands are only allowed by aides, room aides,
1563 * and room namespace owners
1566 || (atol(CC->room.QRname) == CC->user.usernum) ) {
1567 /* access granted */
1570 cprintf("%d Higher access or room ownership required.\n",
1571 ERROR + HIGHER_ACCESS_REQUIRED);
1575 if (!strncasecmp(CC->room.QRname, config.c_baseroom,
1577 cprintf("%d Can't add/remove users from this room.\n",
1582 if (CtdlInvtKick(iuser, op) != 0) {
1583 cprintf("%d No such user.\n", ERROR + NO_SUCH_USER);
1587 cprintf("%d %s %s %s.\n",
1589 ((op == 1) ? "invited to" : "kicked out of"),
1594 void cmd_invt(char *iuser) {cmd_invt_kick(iuser, 1);}
1595 void cmd_kick(char *iuser) {cmd_invt_kick(iuser, 0);}
1598 * Forget (Zap) the current room (API call)
1599 * Returns 0 on success
1601 int CtdlForgetThisRoom(void) {
1604 /* On some systems, Aides are not allowed to forget rooms */
1605 if (is_aide() && (config.c_aide_zap == 0)
1606 && ((CC->room.QRflags & QR_MAILBOX) == 0) ) {
1610 CtdlGetUserLock(&CC->user, CC->curr_user);
1611 CtdlGetRelationship(&vbuf, &CC->user, &CC->room);
1613 vbuf.v_flags = vbuf.v_flags | V_FORGET;
1614 vbuf.v_flags = vbuf.v_flags & ~V_ACCESS;
1616 CtdlSetRelationship(&vbuf, &CC->user, &CC->room);
1617 CtdlPutUserLock(&CC->user);
1619 /* Return to the Lobby, so we don't end up in an undefined room */
1620 CtdlUserGoto(config.c_baseroom, 0, 0, NULL, NULL);
1627 * forget (Zap) the current room
1629 void cmd_forg(char *argbuf)
1632 if (CtdlAccessCheck(ac_logged_in)) {
1636 if (CtdlForgetThisRoom() == 0) {
1637 cprintf("%d Ok\n", CIT_OK);
1640 cprintf("%d You may not forget this room.\n", ERROR + NOT_HERE);
1645 * Get Next Unregistered User
1647 void cmd_gnur(char *argbuf)
1649 struct cdbdata *cdbus;
1650 struct ctdluser usbuf;
1652 if (CtdlAccessCheck(ac_aide)) {
1656 if ((CitControl.MMflags & MM_VALID) == 0) {
1657 cprintf("%d There are no unvalidated users.\n", CIT_OK);
1661 /* There are unvalidated users. Traverse the user database,
1662 * and return the first user we find that needs validation.
1664 cdb_rewind(CDB_USERS);
1665 while (cdbus = cdb_next_item(CDB_USERS), cdbus != NULL) {
1666 memset(&usbuf, 0, sizeof(struct ctdluser));
1667 memcpy(&usbuf, cdbus->ptr,
1668 ((cdbus->len > sizeof(struct ctdluser)) ?
1669 sizeof(struct ctdluser) : cdbus->len));
1671 if ((usbuf.flags & US_NEEDVALID)
1672 && (usbuf.axlevel > AxDeleted)) {
1673 cprintf("%d %s\n", MORE_DATA, usbuf.fullname);
1674 cdb_close_cursor(CDB_USERS);
1679 /* If we get to this point, there are no more unvalidated users.
1680 * Therefore we clear the "users need validation" flag.
1683 begin_critical_section(S_CONTROL);
1685 CitControl.MMflags = CitControl.MMflags & (~MM_VALID);
1687 end_critical_section(S_CONTROL);
1688 cprintf("%d *** End of registration.\n", CIT_OK);
1697 void cmd_vali(char *v_args)
1701 struct ctdluser userbuf;
1703 extract_token(user, v_args, 0, '|', sizeof user);
1704 newax = extract_int(v_args, 1);
1706 if (CtdlAccessCheck(ac_aide) ||
1707 (newax > AxAideU) ||
1708 (newax < AxDeleted)) {
1712 if (CtdlGetUserLock(&userbuf, user) != 0) {
1713 cprintf("%d '%s' not found.\n", ERROR + NO_SUCH_USER, user);
1717 userbuf.axlevel = newax;
1718 userbuf.flags = (userbuf.flags & ~US_NEEDVALID);
1720 CtdlPutUserLock(&userbuf);
1722 /* If the access level was set to zero, delete the user */
1724 if (purge_user(user) == 0) {
1725 cprintf("%d %s Deleted.\n", CIT_OK, userbuf.fullname);
1729 cprintf("%d User '%s' validated.\n", CIT_OK, userbuf.fullname);
1735 * Traverse the user file...
1737 void ForEachUser(void (*CallBack) (struct ctdluser * EachUser, void *out_data),
1740 struct ctdluser usbuf;
1741 struct cdbdata *cdbus;
1743 cdb_rewind(CDB_USERS);
1745 while (cdbus = cdb_next_item(CDB_USERS), cdbus != NULL) {
1746 memset(&usbuf, 0, sizeof(struct ctdluser));
1747 memcpy(&usbuf, cdbus->ptr,
1748 ((cdbus->len > sizeof(struct ctdluser)) ?
1749 sizeof(struct ctdluser) : cdbus->len));
1751 (*CallBack) (&usbuf, in_data);
1757 * List one user (this works with cmd_list)
1759 void ListThisUser(struct ctdluser *usbuf, void *data)
1763 searchstring = (char *)data;
1764 if (bmstrcasestr(usbuf->fullname, searchstring) == NULL) {
1768 if (usbuf->axlevel > AxDeleted) {
1769 if ((CC->user.axlevel >= AxAideU)
1770 || ((usbuf->flags & US_UNLISTED) == 0)
1771 || ((CC->internal_pgm))) {
1772 cprintf("%s|%d|%ld|%ld|%ld|%ld||\n",
1776 (long)usbuf->lastcall,
1784 * List users (searchstring may be empty to list all users)
1786 void cmd_list(char *cmdbuf)
1788 char searchstring[256];
1789 extract_token(searchstring, cmdbuf, 0, '|', sizeof searchstring);
1790 striplt(searchstring);
1791 cprintf("%d \n", LISTING_FOLLOWS);
1792 ForEachUser(ListThisUser, (void *)searchstring );
1800 * assorted info we need to check at login
1802 void cmd_chek(char *argbuf)
1808 if (CtdlAccessCheck(ac_logged_in)) {
1812 CtdlGetUser(&CC->user, CC->curr_user); /* no lock is needed here */
1813 if ((REGISCALL != 0) && ((CC->user.flags & US_REGIS) == 0))
1816 if (CC->user.axlevel >= AxAideU) {
1818 if (CitControl.MMflags & MM_VALID)
1822 /* check for mail */
1823 mail = InitialMailCheck();
1825 cprintf("%d %d|%d|%d|%s|\n", CIT_OK, mail, regis, vali, CC->cs_inet_email);
1830 * check to see if a user exists
1832 void cmd_qusr(char *who)
1834 struct ctdluser usbuf;
1836 if (CtdlGetUser(&usbuf, who) == 0) {
1837 cprintf("%d %s\n", CIT_OK, usbuf.fullname);
1839 cprintf("%d No such user.\n", ERROR + NO_SUCH_USER);
1845 * Administrative Get User Parameters
1847 void cmd_agup(char *cmdbuf)
1849 struct ctdluser usbuf;
1850 char requested_user[128];
1852 if (CtdlAccessCheck(ac_aide)) {
1856 extract_token(requested_user, cmdbuf, 0, '|', sizeof requested_user);
1857 if (CtdlGetUser(&usbuf, requested_user) != 0) {
1858 cprintf("%d No such user.\n", ERROR + NO_SUCH_USER);
1861 cprintf("%d %s|%s|%u|%ld|%ld|%d|%ld|%ld|%d\n",
1868 (int) usbuf.axlevel,
1870 (long)usbuf.lastcall,
1877 * Administrative Set User Parameters
1879 void cmd_asup(char *cmdbuf)
1881 struct ctdluser usbuf;
1882 char requested_user[128];
1888 if (CtdlAccessCheck(ac_aide))
1891 extract_token(requested_user, cmdbuf, 0, '|', sizeof requested_user);
1892 if (CtdlGetUserLock(&usbuf, requested_user) != 0) {
1893 cprintf("%d No such user.\n", ERROR + NO_SUCH_USER);
1896 np = num_parms(cmdbuf);
1898 extract_token(usbuf.password, cmdbuf, 1, '|', sizeof usbuf.password);
1900 usbuf.flags = extract_int(cmdbuf, 2);
1902 usbuf.timescalled = extract_int(cmdbuf, 3);
1904 usbuf.posted = extract_int(cmdbuf, 4);
1906 newax = extract_int(cmdbuf, 5);
1907 if ((newax >= AxDeleted) && (newax <= AxAideU)) {
1908 usbuf.axlevel = newax;
1912 usbuf.lastcall = extract_long(cmdbuf, 7);
1915 usbuf.USuserpurge = extract_int(cmdbuf, 8);
1917 CtdlPutUserLock(&usbuf);
1918 if (usbuf.axlevel == AxDeleted) {
1919 if (purge_user(requested_user) == 0) {
1925 snprintf(notify, SIZ,
1926 "User \"%s\" has been deleted by %s.\n",
1927 usbuf.fullname, CC->user.fullname);
1928 CtdlAideMessage(notify, "User Deletion Message");
1931 cprintf("%d Ok", CIT_OK);
1933 cprintf(" (%s deleted)", requested_user);
1940 * Count the number of new mail messages the user has
1944 int num_newmsgs = 0;
1946 num_newmsgs = CC->newmail;
1949 return (num_newmsgs);
1954 * Count the number of new mail messages the user has
1956 int InitialMailCheck()
1958 int num_newmsgs = 0;
1960 char mailboxname[ROOMNAMELEN];
1961 struct ctdlroom mailbox;
1963 struct cdbdata *cdbfr;
1964 long *msglist = NULL;
1967 CtdlMailboxName(mailboxname, sizeof mailboxname, &CC->user, MAILROOM);
1968 if (CtdlGetRoom(&mailbox, mailboxname) != 0)
1970 CtdlGetRelationship(&vbuf, &CC->user, &mailbox);
1972 cdbfr = cdb_fetch(CDB_MSGLISTS, &mailbox.QRnumber, sizeof(long));
1974 if (cdbfr != NULL) {
1975 msglist = malloc(cdbfr->len);
1976 memcpy(msglist, cdbfr->ptr, cdbfr->len);
1977 num_msgs = cdbfr->len / sizeof(long);
1981 for (a = 0; a < num_msgs; ++a) {
1982 if (msglist[a] > 0L) {
1983 if (msglist[a] > vbuf.v_lastseen) {
1988 if (msglist != NULL)
1991 return (num_newmsgs);
1997 * Set the preferred view for the current user/room combination
1999 void cmd_view(char *cmdbuf) {
2003 if (CtdlAccessCheck(ac_logged_in)) {
2007 requested_view = extract_int(cmdbuf, 0);
2009 CtdlGetRelationship(&vbuf, &CC->user, &CC->room);
2010 vbuf.v_view = requested_view;
2011 CtdlSetRelationship(&vbuf, &CC->user, &CC->room);
2013 cprintf("%d ok\n", CIT_OK);
2020 void cmd_renu(char *cmdbuf)
2023 char oldname[USERNAME_SIZE];
2024 char newname[USERNAME_SIZE];
2026 if (CtdlAccessCheck(ac_aide)) {
2030 extract_token(oldname, cmdbuf, 0, '|', sizeof oldname);
2031 extract_token(newname, cmdbuf, 1, '|', sizeof newname);
2033 retcode = rename_user(oldname, newname);
2036 cprintf("%d '%s' has been renamed to '%s'.\n", CIT_OK, oldname, newname);
2038 case RENAMEUSER_LOGGED_IN:
2039 cprintf("%d '%s' is currently logged in and cannot be renamed.\n",
2040 ERROR + ALREADY_LOGGED_IN , oldname);
2042 case RENAMEUSER_NOT_FOUND:
2043 cprintf("%d '%s' does not exist.\n", ERROR + NO_SUCH_USER, oldname);
2045 case RENAMEUSER_ALREADY_EXISTS:
2046 cprintf("%d A user named '%s' already exists.\n", ERROR + ALREADY_EXISTS, newname);
2050 cprintf("%d An unknown error occurred.\n", ERROR);
2055 /*****************************************************************************/
2056 /* MODULE INITIALIZATION STUFF */
2057 /*****************************************************************************/
2060 CTDL_MODULE_INIT(user_ops)
2063 CtdlRegisterProtoHook(cmd_user, "USER", "Autoconverted. TODO: document me.");
2064 CtdlRegisterProtoHook(cmd_pass, "PASS", "Autoconverted. TODO: document me.");
2065 CtdlRegisterProtoHook(cmd_creu, "CREU", "Autoconverted. TODO: document me.");
2066 CtdlRegisterProtoHook(cmd_setp, "SETP", "Autoconverted. TODO: document me.");
2067 CtdlRegisterProtoHook(cmd_getu, "GETU", "Autoconverted. TODO: document me.");
2068 CtdlRegisterProtoHook(cmd_setu, "SETU", "Autoconverted. TODO: document me.");
2069 CtdlRegisterProtoHook(cmd_slrp, "SLRP", "Autoconverted. TODO: document me.");
2070 CtdlRegisterProtoHook(cmd_invt, "INVT", "Autoconverted. TODO: document me.");
2071 CtdlRegisterProtoHook(cmd_kick, "KICK", "Autoconverted. TODO: document me.");
2072 CtdlRegisterProtoHook(cmd_forg, "FORG", "Autoconverted. TODO: document me.");
2073 CtdlRegisterProtoHook(cmd_gnur, "GNUR", "Autoconverted. TODO: document me.");
2074 CtdlRegisterProtoHook(cmd_vali, "VALI", "Autoconverted. TODO: document me.");
2075 CtdlRegisterProtoHook(cmd_list, "LIST", "Autoconverted. TODO: document me.");
2076 CtdlRegisterProtoHook(cmd_chek, "CHEK", "Autoconverted. TODO: document me.");
2077 CtdlRegisterProtoHook(cmd_qusr, "QUSR", "Autoconverted. TODO: document me.");
2078 CtdlRegisterProtoHook(cmd_agup, "AGUP", "Autoconverted. TODO: document me.");
2079 CtdlRegisterProtoHook(cmd_asup, "ASUP", "Autoconverted. TODO: document me.");
2080 CtdlRegisterProtoHook(cmd_seen, "SEEN", "Autoconverted. TODO: document me.");
2081 CtdlRegisterProtoHook(cmd_gtsn, "GTSN", "Autoconverted. TODO: document me.");
2082 CtdlRegisterProtoHook(cmd_view, "VIEW", "Autoconverted. TODO: document me.");
2083 CtdlRegisterProtoHook(cmd_renu, "RENU", "Autoconverted. TODO: document me.");
2084 CtdlRegisterProtoHook(cmd_newu, "NEWU", "Autoconverted. TODO: document me.");
2086 /* return our Subversion id for the Log */