4 * Server functions which perform operations on user objects.
21 #include <sys/types.h>
24 #if TIME_WITH_SYS_TIME
25 # include <sys/time.h>
29 # include <sys/time.h>
45 #include "serv_extensions.h"
46 #include "sysdep_decls.h"
54 #include "citserver.h"
58 * makeuserkey() - convert a username into the format used as a database key
59 * (it's just the username converted into lower case)
61 static inline void makeuserkey(char *key, char *username) {
64 len = strlen(username);
65 for (i=0; i<=len; ++i) {
66 key[i] = tolower(username[i]);
72 * getuser() - retrieve named user into supplied buffer.
73 * returns 0 on success
75 int getuser(struct ctdluser *usbuf, char name[])
78 char usernamekey[USERNAME_SIZE];
79 char sysuser_name[USERNAME_SIZE];
80 struct cdbdata *cdbus;
81 int using_sysuser = 0;
83 memset(usbuf, 0, sizeof(struct ctdluser));
85 #ifdef ENABLE_AUTOLOGIN
86 if (CtdlAssociateSystemUser(sysuser_name, name) == 0) {
92 makeuserkey(usernamekey, sysuser_name);
95 makeuserkey(usernamekey, name);
98 cdbus = cdb_fetch(CDB_USERS, usernamekey, strlen(usernamekey));
99 if (cdbus == NULL) { /* user not found */
102 memcpy(usbuf, cdbus->ptr,
103 ((cdbus->len > sizeof(struct ctdluser)) ?
104 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);
153 * Index-generating function used by Ctdl[Get|Set]Relationship
155 int GenerateRelationshipIndex(char *IndexBuf,
167 TheIndex.iRoomID = RoomID;
168 TheIndex.iRoomGen = RoomGen;
169 TheIndex.iUserID = UserID;
171 memcpy(IndexBuf, &TheIndex, sizeof(TheIndex));
172 return (sizeof(TheIndex));
178 * Back end for CtdlSetRelationship()
180 void put_visit(struct visit *newvisit)
185 /* Generate an index */
186 IndexLen = GenerateRelationshipIndex(IndexBuf,
189 newvisit->v_usernum);
191 /* Store the record */
192 cdb_store(CDB_VISIT, IndexBuf, IndexLen,
193 newvisit, sizeof(struct visit)
201 * Define a relationship between a user and a room
203 void CtdlSetRelationship(struct visit *newvisit,
204 struct ctdluser *rel_user,
205 struct ctdlroom *rel_room)
209 /* We don't use these in Citadel because they're implicit by the
210 * index, but they must be present if the database is exported.
212 newvisit->v_roomnum = rel_room->QRnumber;
213 newvisit->v_roomgen = rel_room->QRgen;
214 newvisit->v_usernum = rel_user->usernum;
220 * Locate a relationship between a user and a room
222 void CtdlGetRelationship(struct visit *vbuf,
223 struct ctdluser *rel_user,
224 struct ctdlroom *rel_room)
229 struct cdbdata *cdbvisit;
231 /* Generate an index */
232 IndexLen = GenerateRelationshipIndex(IndexBuf,
237 /* Clear out the buffer */
238 memset(vbuf, 0, sizeof(struct visit));
240 cdbvisit = cdb_fetch(CDB_VISIT, IndexBuf, IndexLen);
241 if (cdbvisit != NULL) {
242 memcpy(vbuf, cdbvisit->ptr,
243 ((cdbvisit->len > sizeof(struct visit)) ?
244 sizeof(struct visit) : cdbvisit->len));
248 /* If this is the first time the user has seen this room,
249 * set the view to be the default for the room.
251 vbuf->v_view = rel_room->QRdefaultview;
254 /* Set v_seen if necessary */
255 if (vbuf->v_seen[0] == 0) {
256 snprintf(vbuf->v_seen, sizeof vbuf->v_seen, "*:%ld", vbuf->v_lastseen);
261 void MailboxName(char *buf, size_t n, const struct ctdluser *who, const char *prefix)
263 snprintf(buf, n, "%010ld.%s", who->usernum, prefix);
268 * Is the user currently logged in an Aide?
272 if (CC->user.axlevel >= 6)
280 * Is the user currently logged in an Aide *or* the room aide for this room?
282 int is_room_aide(void)
285 if (!CC->logged_in) {
289 if ((CC->user.axlevel >= 6)
290 || (CC->room.QRroomaide == CC->user.usernum)) {
298 * getuserbynumber() - get user by number
299 * returns 0 if user was found
301 * WARNING: don't use this function unless you absolutely have to. It does
302 * a sequential search and therefore is computationally expensive.
304 int getuserbynumber(struct ctdluser *usbuf, long int number)
306 struct cdbdata *cdbus;
308 cdb_rewind(CDB_USERS);
310 while (cdbus = cdb_next_item(CDB_USERS), cdbus != NULL) {
311 memset(usbuf, 0, sizeof(struct ctdluser));
312 memcpy(usbuf, cdbus->ptr,
313 ((cdbus->len > sizeof(struct ctdluser)) ?
314 sizeof(struct ctdluser) : cdbus->len));
316 if (usbuf->usernum == number) {
317 cdb_close_cursor(CDB_USERS);
326 * See if we can translate a system login name (i.e. from /etc/passwd)
327 * to a Citadel screen name. Returns 0 if one is found.
329 int CtdlAssociateSystemUser(char *screenname, char *loginname) {
333 p = (struct passwd *) getpwnam(loginname);
335 strcpy(screenname, p->pw_gecos);
336 for (a = 0; a < strlen(screenname); ++a) {
337 if (screenname[a] == ',') {
349 * Back end for cmd_user() and its ilk
351 int CtdlLoginExistingUser(char *trythisname)
356 if (trythisname == NULL) return login_not_found;
357 safestrncpy(username, trythisname, sizeof username);
360 if ((CC->logged_in)) {
361 return login_already_logged_in;
364 found_user = getuser(&CC->user, username);
366 if (found_user == 0) {
367 if (((CC->nologin)) && (CC->user.axlevel < 6)) {
368 return login_too_many_users;
370 safestrncpy(CC->curr_user, CC->user.fullname,
371 sizeof CC->curr_user);
375 return login_not_found;
383 void cmd_user(char *cmdbuf)
388 extract(username, cmdbuf, 0);
392 a = CtdlLoginExistingUser(username);
394 case login_already_logged_in:
395 cprintf("%d Already logged in.\n", ERROR);
397 case login_too_many_users:
399 "Too many users are already online "
401 ERROR + MAX_SESSIONS_EXCEEDED,
402 config.c_nodename, config.c_maxsessions);
405 cprintf("%d Password required for %s\n",
406 MORE_DATA, CC->curr_user);
408 case login_not_found:
409 cprintf("%d %s not found.\n", ERROR, username);
411 cprintf("%d Internal error\n", ERROR);
418 * session startup code which is common to both cmd_pass() and cmd_newu()
420 void session_startup(void)
424 syslog(LOG_NOTICE, "session %d: user <%s> logged in",
425 CC->cs_pid, CC->curr_user);
427 lgetuser(&CC->user, CC->curr_user);
428 ++(CC->user.timescalled);
429 CC->previous_login = CC->user.lastcall;
430 time(&CC->user.lastcall);
432 /* If this user's name is the name of the system administrator
433 * (as specified in setup), automatically assign access level 6.
435 if (!strcasecmp(CC->user.fullname, config.c_sysadm)) {
436 CC->user.axlevel = 6;
441 * Populate CC->cs_inet_email with a default address. This will be
442 * overwritten with the user's directory address, if one exists, when
443 * the vCard module's login hook runs.
445 snprintf(CC->cs_inet_email, sizeof CC->cs_inet_email, "%s@%s",
446 CC->user.fullname, config.c_fqdn);
447 for (i=0; i<strlen(CC->cs_inet_email); ++i) {
448 if (isspace(CC->cs_inet_email[i])) {
449 CC->cs_inet_email[i] = '_';
453 /* Create any personal rooms required by the system.
454 * (Technically, MAILROOM should be there already, but just in case...)
456 create_room(MAILROOM, 4, "", 0, 1, 0);
457 create_room(SENTITEMS, 4, "", 0, 1, 0);
459 /* Run any startup routines registered by loadable modules */
460 PerformSessionHooks(EVT_LOGIN);
462 /* Enter the lobby */
463 usergoto(config.c_baseroom, 0, 0, NULL, NULL);
467 void logged_in_response(void)
469 cprintf("%d %s|%d|%ld|%ld|%u|%ld|%ld\n",
470 CIT_OK, CC->user.fullname, CC->user.axlevel,
471 CC->user.timescalled, CC->user.posted,
472 CC->user.flags, CC->user.usernum,
479 * misc things to be taken care of when a user is logged out
481 void logout(struct CitContext *who)
486 * If there is a download in progress, abort it.
488 if (who->download_fp != NULL) {
489 fclose(who->download_fp);
490 who->download_fp = NULL;
494 * If there is an upload in progress, abort it.
496 if (who->upload_fp != NULL) {
501 * If we were talking to a network node, we're not anymore...
503 if (strlen(who->net_node) > 0) {
504 network_talking_to(who->net_node, NTT_REMOVE);
507 /* Do modular stuff... */
508 PerformSessionHooks(EVT_LOGOUT);
513 * an alternate version of validpw() which executes `chkpwd' instead of
514 * verifying the password directly
516 static int validpw(uid_t uid, const char *pass)
519 int status, pipev[2];
523 lprintf(1, "pipe failed (%s): denying autologin access for "
524 "uid %ld\n", strerror(errno), (long)uid);
527 switch (pid = fork()) {
529 lprintf(1, "fork failed (%s): denying autologin access for "
530 "uid %ld\n", strerror(errno), (long)uid);
537 if (dup2(pipev[0], 0) == -1) {
543 execl(BBSDIR "/chkpwd", BBSDIR "/chkpwd", NULL);
544 perror(BBSDIR "/chkpwd");
550 snprintf(buf, sizeof buf, "%lu\n", (unsigned long) uid));
551 write(pipev[1], pass, strlen(pass));
552 write(pipev[1], "\n", 1);
555 while (waitpid(pid, &status, 0) == -1)
556 if (errno != EINTR) {
557 lprintf(1, "waitpid failed (%s): denying autologin "
558 "access for uid %ld\n",
559 strerror(errno), (long)uid);
562 if (WIFEXITED(status) && !WEXITSTATUS(status))
576 int CtdlTryPassword(char *password)
580 if ((CC->logged_in)) {
581 lprintf(5, "CtdlTryPassword: already logged in\n");
582 return pass_already_logged_in;
584 if (!strcmp(CC->curr_user, NLI)) {
585 lprintf(5, "CtdlTryPassword: no user selected\n");
588 if (getuser(&CC->user, CC->curr_user)) {
589 lprintf(5, "CtdlTryPassword: internal error\n");
590 return pass_internal_error;
592 if (password == NULL) {
593 lprintf(5, "CtdlTryPassword: NULL password string supplied\n");
594 return pass_wrong_password;
599 #ifdef ENABLE_AUTOLOGIN
600 /* A uid of BBSUID or -1 indicates that this user exists only in
601 * Citadel, not in the underlying operating system.
603 if ( (CC->user.uid == BBSUID) || (CC->user.uid == (-1)) ) {
605 strproc(CC->user.password);
606 code = strcasecmp(CC->user.password, password);
608 /* Any other uid means we have to check the system password database */
610 if (validpw(CC->user.uid, password)) {
612 lgetuser(&CC->user, CC->curr_user);
613 safestrncpy(CC->user.password, password,
614 sizeof CC->user.password);
619 #else /* ENABLE_AUTOLOGIN */
621 strproc(CC->user.password);
622 code = strcasecmp(CC->user.password, password);
624 #endif /* ENABLE_AUTOLOGIN */
630 lprintf(3, "Bad password specified for <%s>\n", CC->curr_user);
631 return pass_wrong_password;
636 void cmd_pass(char *buf)
641 extract(password, buf, 0);
642 a = CtdlTryPassword(password);
645 case pass_already_logged_in:
646 cprintf("%d Already logged in.\n", ERROR);
649 cprintf("%d You must send a name with USER first.\n",
652 case pass_wrong_password:
653 cprintf("%d Wrong password.\n", ERROR);
656 logged_in_response();
658 cprintf("%d Can't find user record!\n",
659 ERROR + INTERNAL_ERROR);
666 * Delete a user record *and* all of its related resources.
668 int purge_user(char pname[])
671 struct ctdluser usbuf;
672 char usernamekey[USERNAME_SIZE];
673 struct CitContext *ccptr;
674 int user_is_logged_in = 0;
676 makeuserkey(usernamekey, pname);
678 if (getuser(&usbuf, pname) != 0) {
679 lprintf(5, "Cannot purge user <%s> - not found\n", pname);
680 return (ERROR + NO_SUCH_USER);
682 /* Don't delete a user who is currently logged in. Instead, just
683 * set the access level to 0, and let the account get swept up
684 * during the next purge.
686 user_is_logged_in = 0;
687 begin_critical_section(S_SESSION_TABLE);
688 for (ccptr = ContextList; ccptr != NULL; ccptr = ccptr->next) {
689 if (ccptr->user.usernum == usbuf.usernum) {
690 user_is_logged_in = 1;
693 end_critical_section(S_SESSION_TABLE);
694 if (user_is_logged_in == 1) {
695 lprintf(5, "User <%s> is logged in; not deleting.\n", pname);
700 lprintf(5, "Deleting user <%s>\n", pname);
702 /* Perform any purge functions registered by server extensions */
703 PerformUserHooks(usbuf.fullname, usbuf.usernum, EVT_PURGEUSER);
705 /* delete any existing user/room relationships */
706 cdb_delete(CDB_VISIT, &usbuf.usernum, sizeof(long));
708 /* delete the userlog entry */
709 cdb_delete(CDB_USERS, usernamekey, strlen(usernamekey));
711 /* remove the user's bio file */
712 snprintf(filename, sizeof filename, "./bio/%ld", usbuf.usernum);
715 /* remove the user's picture */
716 snprintf(filename, sizeof filename, "./userpics/%ld.gif", usbuf.usernum);
724 * create_user() - back end processing to create a new user
726 * Set 'newusername' to the desired account name.
727 * Set 'become_user' to nonzero if this is self-service account creation and we want
728 * to actually log in as the user we just created, otherwise set it to 0.
730 int create_user(char *newusername, int become_user)
732 struct ctdluser usbuf;
733 struct ctdlroom qrbuf;
734 struct passwd *p = NULL;
736 char mailboxname[ROOMNAMELEN];
739 safestrncpy(username, newusername, sizeof username);
742 #ifdef ENABLE_AUTOLOGIN
743 p = (struct passwd *) getpwnam(username);
745 extract_token(username, p->pw_gecos, 0, ',');
754 if (!getuser(&usbuf, username)) {
755 return (ERROR + ALREADY_EXISTS);
758 /* Go ahead and initialize a new user record */
759 memset(&usbuf, 0, sizeof(struct ctdluser));
760 safestrncpy(usbuf.fullname, username, sizeof usbuf.fullname);
761 strcpy(usbuf.password, "");
764 /* These are the default flags on new accounts */
765 usbuf.flags = US_LASTOLD | US_DISAPPEAR | US_PAGINATOR | US_FLOORS;
767 usbuf.timescalled = 0;
769 usbuf.axlevel = config.c_initax;
770 usbuf.USscreenwidth = 80;
771 usbuf.USscreenheight = 24;
772 usbuf.lastcall = time(NULL);
774 /* fetch a new user number */
775 usbuf.usernum = get_new_user_number();
777 /* The very first user created on the system will always be an Aide */
778 if (usbuf.usernum == 1L) {
782 /* add user to userlog */
786 * Give the user a private mailbox and a configuration room.
787 * Make the latter an invisible system room.
789 MailboxName(mailboxname, sizeof mailboxname, &usbuf, MAILROOM);
790 create_room(mailboxname, 5, "", 0, 1, 1);
792 MailboxName(mailboxname, sizeof mailboxname, &usbuf, USERCONFIGROOM);
793 create_room(mailboxname, 5, "", 0, 1, 1);
794 if (lgetroom(&qrbuf, mailboxname) == 0) {
795 qrbuf.QRflags2 |= QR2_SYSTEM;
799 /* Everything below this line can be bypassed if administratively
800 creating a user, instead of doing self-service account creation
804 /* Now become the user we just created */
805 memcpy(&CC->user, &usbuf, sizeof(struct ctdluser));
806 safestrncpy(CC->curr_user, username, sizeof CC->curr_user);
809 /* Check to make sure we're still who we think we are */
810 if (getuser(&CC->user, CC->curr_user)) {
811 return (ERROR + INTERNAL_ERROR);
815 lprintf(3, "New user <%s> created\n", username);
823 * cmd_newu() - create a new user account and log in as that user
825 void cmd_newu(char *cmdbuf)
830 if (config.c_disable_newu) {
831 cprintf("%d Self-service user account creation "
832 "is disabled on this system.\n", ERROR);
837 cprintf("%d Already logged in.\n", ERROR);
841 cprintf("%d %s: Too many users are already online (maximum is %d)\n",
842 ERROR + MAX_SESSIONS_EXCEEDED,
843 config.c_nodename, config.c_maxsessions);
845 extract(username, cmdbuf, 0);
849 if (strlen(username) == 0) {
850 cprintf("%d You must supply a user name.\n", ERROR);
854 if ((!strcasecmp(username, "bbs")) ||
855 (!strcasecmp(username, "new")) ||
856 (!strcasecmp(username, "."))) {
857 cprintf("%d '%s' is an invalid login name.\n", ERROR, username);
861 a = create_user(username, 1);
865 logged_in_response();
866 } else if (a == ERROR + ALREADY_EXISTS) {
867 cprintf("%d '%s' already exists.\n",
868 ERROR + ALREADY_EXISTS, username);
870 } else if (a == ERROR + INTERNAL_ERROR) {
871 cprintf("%d Internal error - user record disappeared?\n",
872 ERROR + INTERNAL_ERROR);
875 cprintf("%d unknown error\n", ERROR);
884 void cmd_setp(char *new_pw)
886 if (CtdlAccessCheck(ac_logged_in)) {
889 if ( (CC->user.uid != BBSUID) && (CC->user.uid != (-1)) ) {
890 cprintf("%d Not allowed. Use the 'passwd' command.\n", ERROR);
894 if (strlen(new_pw) == 0) {
895 cprintf("%d Password unchanged.\n", CIT_OK);
898 lgetuser(&CC->user, CC->curr_user);
899 safestrncpy(CC->user.password, new_pw, sizeof(CC->user.password));
901 cprintf("%d Password changed.\n", CIT_OK);
902 lprintf(3, "Password changed for user <%s>\n", CC->curr_user);
903 PerformSessionHooks(EVT_SETPASS);
908 * cmd_creu() - administratively create a new user account (do not log in to it)
910 void cmd_creu(char *cmdbuf)
915 if (CtdlAccessCheck(ac_aide)) {
919 extract(username, cmdbuf, 0);
923 if (strlen(username) == 0) {
924 cprintf("%d You must supply a user name.\n", ERROR);
928 a = create_user(username, 0);
931 cprintf("%d ok\n", CIT_OK);
933 } else if (a == ERROR + ALREADY_EXISTS) {
934 cprintf("%d '%s' already exists.\n",
935 ERROR + ALREADY_EXISTS, username);
938 cprintf("%d An error occured creating the user account.\n", ERROR);
945 * get user parameters
950 if (CtdlAccessCheck(ac_logged_in))
953 getuser(&CC->user, CC->curr_user);
954 cprintf("%d %d|%d|%d|\n",
956 CC->user.USscreenwidth,
957 CC->user.USscreenheight,
958 (CC->user.flags & US_USER_SET)
963 * set user parameters
965 void cmd_setu(char *new_parms)
967 if (CtdlAccessCheck(ac_logged_in))
970 if (num_parms(new_parms) < 3) {
971 cprintf("%d Usage error.\n", ERROR);
974 lgetuser(&CC->user, CC->curr_user);
975 CC->user.USscreenwidth = extract_int(new_parms, 0);
976 CC->user.USscreenheight = extract_int(new_parms, 1);
977 CC->user.flags = CC->user.flags & (~US_USER_SET);
978 CC->user.flags = CC->user.flags |
979 (extract_int(new_parms, 2) & US_USER_SET);
982 cprintf("%d Ok\n", CIT_OK);
986 * set last read pointer
988 void cmd_slrp(char *new_ptr)
992 struct visit original_vbuf;
994 if (CtdlAccessCheck(ac_logged_in)) {
998 if (!strncasecmp(new_ptr, "highest", 7)) {
999 newlr = CC->room.QRhighest;
1001 newlr = atol(new_ptr);
1004 lgetuser(&CC->user, CC->curr_user);
1006 CtdlGetRelationship(&vbuf, &CC->user, &CC->room);
1007 memcpy(&original_vbuf, &vbuf, sizeof(struct visit));
1008 vbuf.v_lastseen = newlr;
1009 snprintf(vbuf.v_seen, sizeof vbuf.v_seen, "*:%ld", newlr);
1011 /* Only rewrite the record if it changed */
1012 if ( (vbuf.v_lastseen != original_vbuf.v_lastseen)
1013 || (strcmp(vbuf.v_seen, original_vbuf.v_seen)) ) {
1014 CtdlSetRelationship(&vbuf, &CC->user, &CC->room);
1017 lputuser(&CC->user);
1018 cprintf("%d %ld\n", CIT_OK, newlr);
1022 void cmd_seen(char *argbuf) {
1023 long target_msgnum = 0L;
1024 int target_setting = 0;
1026 if (CtdlAccessCheck(ac_logged_in)) {
1030 if (num_parms(argbuf) != 2) {
1031 cprintf("%d Invalid parameters\n", ERROR);
1035 target_msgnum = extract_long(argbuf, 0);
1036 target_setting = extract_int(argbuf, 1);
1038 CtdlSetSeen(target_msgnum, target_setting);
1039 cprintf("%d OK\n", CIT_OK);
1043 void cmd_gtsn(char *argbuf) {
1046 if (CtdlAccessCheck(ac_logged_in)) {
1051 cprintf("%d %s\n", CIT_OK, buf);
1057 * INVT and KICK commands
1059 void cmd_invt_kick(char *iuser, int op)
1061 { /* 1 = invite, 0 = kick out */
1062 struct ctdluser USscratch;
1067 * These commands are only allowed by aides, room aides,
1068 * and room namespace owners
1071 || (atol(CC->room.QRname) == CC->user.usernum) ) {
1072 /* access granted */
1075 cprintf("%d Higher access or room ownership required.\n",
1076 ERROR + HIGHER_ACCESS_REQUIRED);
1080 if (!strncasecmp(CC->room.QRname, config.c_baseroom,
1082 cprintf("%d Can't add/remove users from this room.\n",
1087 if (lgetuser(&USscratch, iuser) != 0) {
1088 cprintf("%d No such user.\n", ERROR);
1091 CtdlGetRelationship(&vbuf, &USscratch, &CC->room);
1094 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
1095 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
1098 vbuf.v_flags = vbuf.v_flags & ~V_ACCESS;
1099 vbuf.v_flags = vbuf.v_flags | V_FORGET | V_LOCKOUT;
1101 CtdlSetRelationship(&vbuf, &USscratch, &CC->room);
1103 lputuser(&USscratch);
1105 /* post a message in Aide> saying what we just did */
1106 snprintf(bbb, sizeof bbb, "%s %s %s> by %s\n",
1108 ((op == 1) ? "invited to" : "kicked out of"),
1113 cprintf("%d %s %s %s.\n",
1115 ((op == 1) ? "invited to" : "kicked out of"),
1122 * Forget (Zap) the current room (API call)
1123 * Returns 0 on success
1125 int CtdlForgetThisRoom(void) {
1128 /* On some systems, Aides are not allowed to forget rooms */
1129 if (is_aide() && (config.c_aide_zap == 0)
1130 && ((CC->room.QRflags & QR_MAILBOX) == 0) ) {
1134 lgetuser(&CC->user, CC->curr_user);
1135 CtdlGetRelationship(&vbuf, &CC->user, &CC->room);
1137 vbuf.v_flags = vbuf.v_flags | V_FORGET;
1138 vbuf.v_flags = vbuf.v_flags & ~V_ACCESS;
1140 CtdlSetRelationship(&vbuf, &CC->user, &CC->room);
1141 lputuser(&CC->user);
1143 /* Return to the Lobby, so we don't end up in an undefined room */
1144 usergoto(config.c_baseroom, 0, 0, NULL, NULL);
1151 * forget (Zap) the current room
1156 if (CtdlAccessCheck(ac_logged_in)) {
1160 if (CtdlForgetThisRoom() == 0) {
1161 cprintf("%d Ok\n", CIT_OK);
1164 cprintf("%d You may not forget this room.\n", ERROR);
1169 * Get Next Unregistered User
1173 struct cdbdata *cdbus;
1174 struct ctdluser usbuf;
1176 if (CtdlAccessCheck(ac_aide)) {
1180 if ((CitControl.MMflags & MM_VALID) == 0) {
1181 cprintf("%d There are no unvalidated users.\n", CIT_OK);
1185 /* There are unvalidated users. Traverse the user database,
1186 * and return the first user we find that needs validation.
1188 cdb_rewind(CDB_USERS);
1189 while (cdbus = cdb_next_item(CDB_USERS), cdbus != NULL) {
1190 memset(&usbuf, 0, sizeof(struct ctdluser));
1191 memcpy(&usbuf, cdbus->ptr,
1192 ((cdbus->len > sizeof(struct ctdluser)) ?
1193 sizeof(struct ctdluser) : cdbus->len));
1195 if ((usbuf.flags & US_NEEDVALID)
1196 && (usbuf.axlevel > 0)) {
1197 cprintf("%d %s\n", MORE_DATA, usbuf.fullname);
1198 cdb_close_cursor(CDB_USERS);
1203 /* If we get to this point, there are no more unvalidated users.
1204 * Therefore we clear the "users need validation" flag.
1207 begin_critical_section(S_CONTROL);
1209 CitControl.MMflags = CitControl.MMflags & (~MM_VALID);
1211 end_critical_section(S_CONTROL);
1212 cprintf("%d *** End of registration.\n", CIT_OK);
1221 void cmd_vali(char *v_args)
1225 struct ctdluser userbuf;
1227 extract(user, v_args, 0);
1228 newax = extract_int(v_args, 1);
1230 if (CtdlAccessCheck(ac_aide)) {
1234 if (lgetuser(&userbuf, user) != 0) {
1235 cprintf("%d '%s' not found.\n", ERROR + NO_SUCH_USER, user);
1239 userbuf.axlevel = newax;
1240 userbuf.flags = (userbuf.flags & ~US_NEEDVALID);
1244 /* If the access level was set to zero, delete the user */
1246 if (purge_user(user) == 0) {
1247 cprintf("%d %s Deleted.\n", CIT_OK, userbuf.fullname);
1251 cprintf("%d User '%s' validated.\n", CIT_OK, userbuf.fullname);
1257 * Traverse the user file...
1259 void ForEachUser(void (*CallBack) (struct ctdluser * EachUser, void *out_data),
1262 struct ctdluser usbuf;
1263 struct cdbdata *cdbus;
1265 cdb_rewind(CDB_USERS);
1267 while (cdbus = cdb_next_item(CDB_USERS), cdbus != NULL) {
1268 memset(&usbuf, 0, sizeof(struct ctdluser));
1269 memcpy(&usbuf, cdbus->ptr,
1270 ((cdbus->len > sizeof(struct ctdluser)) ?
1271 sizeof(struct ctdluser) : cdbus->len));
1273 (*CallBack) (&usbuf, in_data);
1279 * List one user (this works with cmd_list)
1281 void ListThisUser(struct ctdluser *usbuf, void *data)
1283 if (usbuf->axlevel > 0) {
1284 if ((CC->user.axlevel >= 6)
1285 || ((usbuf->flags & US_UNLISTED) == 0)
1286 || ((CC->internal_pgm))) {
1287 cprintf("%s|%d|%ld|%ld|%ld|%ld|",
1291 (long)usbuf->lastcall,
1294 if (CC->user.axlevel >= 6)
1295 cprintf("%s", usbuf->password);
1306 cprintf("%d \n", LISTING_FOLLOWS);
1307 ForEachUser(ListThisUser, NULL);
1315 * assorted info we need to check at login
1323 if (CtdlAccessCheck(ac_logged_in)) {
1327 getuser(&CC->user, CC->curr_user); /* no lock is needed here */
1328 if ((REGISCALL != 0) && ((CC->user.flags & US_REGIS) == 0))
1331 if (CC->user.axlevel >= 6) {
1333 if (CitControl.MMflags & MM_VALID)
1337 /* check for mail */
1338 mail = InitialMailCheck();
1340 cprintf("%d %d|%d|%d|%s|\n", CIT_OK, mail, regis, vali, CC->cs_inet_email);
1345 * check to see if a user exists
1347 void cmd_qusr(char *who)
1349 struct ctdluser usbuf;
1351 if (getuser(&usbuf, who) == 0) {
1352 cprintf("%d %s\n", CIT_OK, usbuf.fullname);
1354 cprintf("%d No such user.\n", ERROR + NO_SUCH_USER);
1360 * Administrative Get User Parameters
1362 void cmd_agup(char *cmdbuf)
1364 struct ctdluser usbuf;
1365 char requested_user[SIZ];
1367 if (CtdlAccessCheck(ac_aide)) {
1371 extract(requested_user, cmdbuf, 0);
1372 if (getuser(&usbuf, requested_user) != 0) {
1373 cprintf("%d No such user.\n", ERROR + NO_SUCH_USER);
1376 cprintf("%d %s|%s|%u|%ld|%ld|%d|%ld|%ld|%d\n",
1383 (int) usbuf.axlevel,
1385 (long)usbuf.lastcall,
1392 * Administrative Set User Parameters
1394 void cmd_asup(char *cmdbuf)
1396 struct ctdluser usbuf;
1397 char requested_user[SIZ];
1403 if (CtdlAccessCheck(ac_aide))
1406 extract(requested_user, cmdbuf, 0);
1407 if (lgetuser(&usbuf, requested_user) != 0) {
1408 cprintf("%d No such user.\n", ERROR + NO_SUCH_USER);
1411 np = num_parms(cmdbuf);
1413 extract(usbuf.password, cmdbuf, 1);
1415 usbuf.flags = extract_int(cmdbuf, 2);
1417 usbuf.timescalled = extract_int(cmdbuf, 3);
1419 usbuf.posted = extract_int(cmdbuf, 4);
1421 newax = extract_int(cmdbuf, 5);
1422 if ((newax >= 0) && (newax <= 6)) {
1423 usbuf.axlevel = extract_int(cmdbuf, 5);
1427 usbuf.lastcall = extract_long(cmdbuf, 7);
1430 usbuf.USuserpurge = extract_int(cmdbuf, 8);
1433 if (usbuf.axlevel == 0) {
1434 if (purge_user(requested_user) == 0) {
1440 sprintf(notify, "User <%s> deleted by %s\n",
1441 usbuf.fullname, CC->user.fullname);
1442 aide_message(notify);
1445 cprintf("%d Ok", CIT_OK);
1447 cprintf(" (%s deleted)", requested_user);
1454 * Check to see if the user who we just sent mail to is logged in. If yes,
1455 * bump the 'new mail' counter for their session. That enables them to
1456 * receive a new mail notification without having to hit the database.
1458 void BumpNewMailCounter(long which_user) {
1459 struct CitContext *ptr;
1461 begin_critical_section(S_SESSION_TABLE);
1463 for (ptr = ContextList; ptr != NULL; ptr = ptr->next) {
1464 if (ptr->user.usernum == which_user) {
1469 end_critical_section(S_SESSION_TABLE);
1474 * Count the number of new mail messages the user has
1478 int num_newmsgs = 0;
1480 num_newmsgs = CC->newmail;
1483 return (num_newmsgs);
1488 * Count the number of new mail messages the user has
1490 int InitialMailCheck()
1492 int num_newmsgs = 0;
1494 char mailboxname[ROOMNAMELEN];
1495 struct ctdlroom mailbox;
1497 struct cdbdata *cdbfr;
1498 long *msglist = NULL;
1501 MailboxName(mailboxname, sizeof mailboxname, &CC->user, MAILROOM);
1502 if (getroom(&mailbox, mailboxname) != 0)
1504 CtdlGetRelationship(&vbuf, &CC->user, &mailbox);
1506 cdbfr = cdb_fetch(CDB_MSGLISTS, &mailbox.QRnumber, sizeof(long));
1508 if (cdbfr != NULL) {
1509 msglist = mallok(cdbfr->len);
1510 memcpy(msglist, cdbfr->ptr, cdbfr->len);
1511 num_msgs = cdbfr->len / sizeof(long);
1515 for (a = 0; a < num_msgs; ++a) {
1516 if (msglist[a] > 0L) {
1517 if (msglist[a] > vbuf.v_lastseen) {
1522 if (msglist != NULL)
1525 return (num_newmsgs);
1531 * Set the preferred view for the current user/room combination
1533 void cmd_view(char *cmdbuf) {
1537 if (CtdlAccessCheck(ac_logged_in)) {
1541 requested_view = extract_int(cmdbuf, 0);
1543 CtdlGetRelationship(&vbuf, &CC->user, &CC->room);
1544 vbuf.v_view = requested_view;
1545 CtdlSetRelationship(&vbuf, &CC->user, &CC->room);
1547 cprintf("%d ok\n", CIT_OK);