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 * getuser() - retrieve named user into supplied buffer.
59 * returns 0 on success
61 int getuser(struct user *usbuf, char name[])
64 char lowercase_name[USERNAME_SIZE];
65 char sysuser_name[USERNAME_SIZE];
67 struct cdbdata *cdbus;
68 int using_sysuser = 0;
70 memset(usbuf, 0, sizeof(struct user));
72 #ifdef ENABLE_AUTOLOGIN
73 if (CtdlAssociateSystemUser(sysuser_name, name) == 0) {
79 for (a = 0; a <= strlen(sysuser_name); ++a) {
80 lowercase_name[a] = tolower(sysuser_name[a]);
84 for (a = 0; a <= strlen(name); ++a) {
85 if (a < sizeof(lowercase_name))
86 lowercase_name[a] = tolower(name[a]);
89 lowercase_name[sizeof(lowercase_name) - 1] = 0;
91 cdbus = cdb_fetch(CDB_USERS, lowercase_name, strlen(lowercase_name));
92 if (cdbus == NULL) { /* user not found */
95 memcpy(usbuf, cdbus->ptr,
96 ((cdbus->len > sizeof(struct user)) ?
97 sizeof(struct user) : cdbus->len));
105 * lgetuser() - same as getuser() but locks the record
107 int lgetuser(struct user *usbuf, char *name)
111 retcode = getuser(usbuf, name);
113 begin_critical_section(S_USERS);
120 * putuser() - write user buffer into the correct place on disk
122 void putuser(struct user *usbuf)
124 char lowercase_name[USERNAME_SIZE];
127 for (a = 0; a <= strlen(usbuf->fullname); ++a) {
128 if (a < sizeof(lowercase_name))
129 lowercase_name[a] = tolower(usbuf->fullname[a]);
131 lowercase_name[sizeof(lowercase_name) - 1] = 0;
133 usbuf->version = REV_LEVEL;
135 lowercase_name, strlen(lowercase_name),
136 usbuf, sizeof(struct user));
142 * lputuser() - same as putuser() but locks the record
144 void lputuser(struct user *usbuf)
147 end_critical_section(S_USERS);
151 * Index-generating function used by Ctdl[Get|Set]Relationship
153 int GenerateRelationshipIndex(char *IndexBuf,
165 TheIndex.iRoomID = RoomID;
166 TheIndex.iRoomGen = RoomGen;
167 TheIndex.iUserID = UserID;
169 memcpy(IndexBuf, &TheIndex, sizeof(TheIndex));
170 return (sizeof(TheIndex));
176 * Back end for CtdlSetRelationship()
178 void put_visit(struct visit *newvisit)
183 /* Generate an index */
184 IndexLen = GenerateRelationshipIndex(IndexBuf,
187 newvisit->v_usernum);
189 /* Store the record */
190 cdb_store(CDB_VISIT, IndexBuf, IndexLen,
191 newvisit, sizeof(struct visit)
199 * Define a relationship between a user and a room
201 void CtdlSetRelationship(struct visit *newvisit,
202 struct user *rel_user,
203 struct room *rel_room)
207 /* We don't use these in Citadel because they're implicit by the
208 * index, but they must be present if the database is exported.
210 newvisit->v_roomnum = rel_room->QRnumber;
211 newvisit->v_roomgen = rel_room->QRgen;
212 newvisit->v_usernum = rel_user->usernum;
218 * Locate a relationship between a user and a room
220 void CtdlGetRelationship(struct visit *vbuf,
221 struct user *rel_user,
222 struct room *rel_room)
227 struct cdbdata *cdbvisit;
229 /* Generate an index */
230 IndexLen = GenerateRelationshipIndex(IndexBuf,
235 /* Clear out the buffer */
236 memset(vbuf, 0, sizeof(struct visit));
238 cdbvisit = cdb_fetch(CDB_VISIT, IndexBuf, IndexLen);
239 if (cdbvisit != NULL) {
240 memcpy(vbuf, cdbvisit->ptr,
241 ((cdbvisit->len > sizeof(struct visit)) ?
242 sizeof(struct visit) : cdbvisit->len));
246 /* If this is the first time the user has seen this room,
247 * set the view to be the default for the room.
249 vbuf->v_view = rel_room->QRdefaultview;
252 /* Set v_seen if necessary */
253 if (vbuf->v_seen[0] == 0) {
254 snprintf(vbuf->v_seen, sizeof vbuf->v_seen, "*:%ld", vbuf->v_lastseen);
259 void MailboxName(char *buf, size_t n, const struct user *who, const char *prefix)
261 snprintf(buf, n, "%010ld.%s", who->usernum, prefix);
266 * Is the user currently logged in an Aide?
270 if (CC->user.axlevel >= 6)
278 * Is the user currently logged in an Aide *or* the room aide for this room?
280 int is_room_aide(void)
283 if (!CC->logged_in) {
287 if ((CC->user.axlevel >= 6)
288 || (CC->room.QRroomaide == CC->user.usernum)) {
296 * getuserbynumber() - get user by number
297 * returns 0 if user was found
299 * WARNING: don't use this function unless you absolutely have to. It does
300 * a sequential search and therefore is computationally expensive.
302 int getuserbynumber(struct user *usbuf, long int number)
304 struct cdbdata *cdbus;
306 cdb_rewind(CDB_USERS);
308 while (cdbus = cdb_next_item(CDB_USERS), cdbus != NULL) {
309 memset(usbuf, 0, sizeof(struct user));
310 memcpy(usbuf, cdbus->ptr,
311 ((cdbus->len > sizeof(struct user)) ?
312 sizeof(struct user) : cdbus->len));
314 if (usbuf->usernum == number) {
315 cdb_close_cursor(CDB_USERS);
324 * See if we can translate a system login name (i.e. from /etc/passwd)
325 * to a Citadel screen name. Returns 0 if one is found.
327 int CtdlAssociateSystemUser(char *screenname, char *loginname) {
331 p = (struct passwd *) getpwnam(loginname);
333 strcpy(screenname, p->pw_gecos);
334 for (a = 0; a < strlen(screenname); ++a) {
335 if (screenname[a] == ',') {
347 * Back end for cmd_user() and its ilk
349 int CtdlLoginExistingUser(char *trythisname)
354 if (trythisname == NULL) return login_not_found;
355 safestrncpy(username, trythisname, sizeof username);
358 if ((CC->logged_in)) {
359 return login_already_logged_in;
362 found_user = getuser(&CC->user, username);
364 if (found_user == 0) {
365 if (((CC->nologin)) && (CC->user.axlevel < 6)) {
366 return login_too_many_users;
368 strcpy(CC->curr_user, CC->user.fullname);
372 return login_not_found;
380 void cmd_user(char *cmdbuf)
385 extract(username, cmdbuf, 0);
389 a = CtdlLoginExistingUser(username);
391 case login_already_logged_in:
392 cprintf("%d Already logged in.\n", ERROR);
394 case login_too_many_users:
396 "Too many users are already online "
398 ERROR + MAX_SESSIONS_EXCEEDED,
399 config.c_nodename, config.c_maxsessions);
402 cprintf("%d Password required for %s\n",
403 MORE_DATA, CC->curr_user);
405 case login_not_found:
406 cprintf("%d %s not found.\n", ERROR, username);
408 cprintf("%d Internal error\n", ERROR);
415 * session startup code which is common to both cmd_pass() and cmd_newu()
417 void session_startup(void)
421 syslog(LOG_NOTICE, "session %d: user <%s> logged in",
422 CC->cs_pid, CC->curr_user);
424 lgetuser(&CC->user, CC->curr_user);
425 ++(CC->user.timescalled);
426 CC->previous_login = CC->user.lastcall;
427 time(&CC->user.lastcall);
429 /* If this user's name is the name of the system administrator
430 * (as specified in setup), automatically assign access level 6.
432 if (!strcasecmp(CC->user.fullname, config.c_sysadm)) {
433 CC->user.axlevel = 6;
438 * Populate CC->cs_inet_email with a default address. This will be
439 * overwritten with the user's directory address, if one exists, when
440 * the vCard module's login hook runs.
442 snprintf(CC->cs_inet_email, sizeof CC->cs_inet_email, "%s@%s",
443 CC->user.fullname, config.c_fqdn);
444 for (i=0; i<strlen(CC->cs_inet_email); ++i) {
445 if (isspace(CC->cs_inet_email[i])) {
446 CC->cs_inet_email[i] = '_';
450 /* Create any personal rooms required by the system.
451 * (Technically, MAILROOM should be there already, but just in case...)
453 create_room(MAILROOM, 4, "", 0, 1, 0);
454 create_room(SENTITEMS, 4, "", 0, 1, 0);
456 /* Run any startup routines registered by loadable modules */
457 PerformSessionHooks(EVT_LOGIN);
459 /* Enter the lobby */
460 usergoto(config.c_baseroom, 0, 0, NULL, NULL);
464 void logged_in_response(void)
466 cprintf("%d %s|%d|%ld|%ld|%u|%ld|%ld\n",
467 CIT_OK, CC->user.fullname, CC->user.axlevel,
468 CC->user.timescalled, CC->user.posted,
469 CC->user.flags, CC->user.usernum,
476 * misc things to be taken care of when a user is logged out
478 void logout(struct CitContext *who)
483 * If there is a download in progress, abort it.
485 if (who->download_fp != NULL) {
486 fclose(who->download_fp);
487 who->download_fp = NULL;
491 * If there is an upload in progress, abort it.
493 if (who->upload_fp != NULL) {
498 * If we were talking to a network node, we're not anymore...
500 if (strlen(who->net_node) > 0) {
501 network_talking_to(who->net_node, NTT_REMOVE);
504 /* Do modular stuff... */
505 PerformSessionHooks(EVT_LOGOUT);
510 * an alternate version of validpw() which executes `chkpwd' instead of
511 * verifying the password directly
513 static int validpw(uid_t uid, const char *pass)
516 int status, pipev[2];
520 lprintf(1, "pipe failed (%s): denying autologin access for "
521 "uid %ld\n", strerror(errno), (long)uid);
524 switch (pid = fork()) {
526 lprintf(1, "fork failed (%s): denying autologin access for "
527 "uid %ld\n", strerror(errno), (long)uid);
534 if (dup2(pipev[0], 0) == -1) {
540 execl(BBSDIR "/chkpwd", BBSDIR "/chkpwd", NULL);
541 perror(BBSDIR "/chkpwd");
547 snprintf(buf, sizeof buf, "%lu\n", (unsigned long) uid));
548 write(pipev[1], pass, strlen(pass));
549 write(pipev[1], "\n", 1);
552 while (waitpid(pid, &status, 0) == -1)
553 if (errno != EINTR) {
554 lprintf(1, "waitpid failed (%s): denying autologin "
555 "access for uid %ld\n",
556 strerror(errno), (long)uid);
559 if (WIFEXITED(status) && !WEXITSTATUS(status))
573 int CtdlTryPassword(char *password)
577 if ((CC->logged_in)) {
578 lprintf(5, "CtdlTryPassword: already logged in\n");
579 return pass_already_logged_in;
581 if (!strcmp(CC->curr_user, NLI)) {
582 lprintf(5, "CtdlTryPassword: no user selected\n");
585 if (getuser(&CC->user, CC->curr_user)) {
586 lprintf(5, "CtdlTryPassword: internal error\n");
587 return pass_internal_error;
589 if (password == NULL) {
590 lprintf(5, "CtdlTryPassword: NULL password string supplied\n");
591 return pass_wrong_password;
596 #ifdef ENABLE_AUTOLOGIN
597 /* A uid of BBSUID or -1 indicates that this user exists only in
598 * Citadel, not in the underlying operating system.
600 if ( (CC->user.uid == BBSUID) || (CC->user.uid == (-1)) ) {
602 strproc(CC->user.password);
603 code = strcasecmp(CC->user.password, password);
605 /* Any other uid means we have to check the system password database */
607 if (validpw(CC->user.uid, password)) {
609 lgetuser(&CC->user, CC->curr_user);
610 safestrncpy(CC->user.password, password,
611 sizeof CC->user.password);
616 #else /* ENABLE_AUTOLOGIN */
618 strproc(CC->user.password);
619 code = strcasecmp(CC->user.password, password);
621 #endif /* ENABLE_AUTOLOGIN */
627 lprintf(3, "Bad password specified for <%s>\n", CC->curr_user);
628 return pass_wrong_password;
633 void cmd_pass(char *buf)
638 extract(password, buf, 0);
639 a = CtdlTryPassword(password);
642 case pass_already_logged_in:
643 cprintf("%d Already logged in.\n", ERROR);
646 cprintf("%d You must send a name with USER first.\n",
649 case pass_wrong_password:
650 cprintf("%d Wrong password.\n", ERROR);
653 logged_in_response();
655 cprintf("%d Can't find user record!\n",
656 ERROR + INTERNAL_ERROR);
663 * Delete a user record *and* all of its related resources.
665 int purge_user(char pname[])
669 char lowercase_name[USERNAME_SIZE];
671 struct CitContext *ccptr;
672 int user_is_logged_in = 0;
674 for (a = 0; a <= strlen(pname); ++a) {
675 lowercase_name[a] = tolower(pname[a]);
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, lowercase_name, strlen(lowercase_name));
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)
734 struct passwd *p = NULL;
736 char mailboxname[ROOMNAMELEN];
739 strcpy(username, newusername);
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 user));
760 strcpy(usbuf.fullname, username);
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 user));
806 strcpy(CC->curr_user, username);
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 strcpy(CC->user.password, new_pw);
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)
993 if (CtdlAccessCheck(ac_logged_in)) {
997 if (!strncasecmp(new_ptr, "highest", 7)) {
998 newlr = CC->room.QRhighest;
1000 newlr = atol(new_ptr);
1003 lgetuser(&CC->user, CC->curr_user);
1005 CtdlGetRelationship(&vbuf, &CC->user, &CC->room);
1006 vbuf.v_lastseen = newlr;
1007 snprintf(vbuf.v_seen, sizeof vbuf.v_seen, "*:%ld", newlr);
1008 CtdlSetRelationship(&vbuf, &CC->user, &CC->room);
1010 lputuser(&CC->user);
1011 cprintf("%d %ld\n", CIT_OK, newlr);
1015 void cmd_seen(char *argbuf) {
1016 long target_msgnum = 0L;
1017 int target_setting = 0;
1019 if (CtdlAccessCheck(ac_logged_in)) {
1023 if (num_parms(argbuf) != 2) {
1024 cprintf("%d Invalid parameters\n", ERROR);
1028 target_msgnum = extract_long(argbuf, 0);
1029 target_setting = extract_int(argbuf, 1);
1031 CtdlSetSeen(target_msgnum, target_setting);
1032 cprintf("%d OK\n", CIT_OK);
1036 void cmd_gtsn(char *argbuf) {
1039 if (CtdlAccessCheck(ac_logged_in)) {
1044 cprintf("%d %s\n", CIT_OK, buf);
1050 * INVT and KICK commands
1052 void cmd_invt_kick(char *iuser, int op)
1054 { /* 1 = invite, 0 = kick out */
1055 struct user USscratch;
1060 * These commands are only allowed by aides, room aides,
1061 * and room namespace owners
1064 || (atol(CC->room.QRname) == CC->user.usernum) ) {
1065 /* access granted */
1068 cprintf("%d Higher access or room ownership required.\n",
1069 ERROR + HIGHER_ACCESS_REQUIRED);
1073 if (!strncasecmp(CC->room.QRname, config.c_baseroom,
1075 cprintf("%d Can't add/remove users from this room.\n",
1080 if (lgetuser(&USscratch, iuser) != 0) {
1081 cprintf("%d No such user.\n", ERROR);
1084 CtdlGetRelationship(&vbuf, &USscratch, &CC->room);
1087 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
1088 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
1091 vbuf.v_flags = vbuf.v_flags & ~V_ACCESS;
1092 vbuf.v_flags = vbuf.v_flags | V_FORGET | V_LOCKOUT;
1094 CtdlSetRelationship(&vbuf, &USscratch, &CC->room);
1096 lputuser(&USscratch);
1098 /* post a message in Aide> saying what we just did */
1099 snprintf(bbb, sizeof bbb, "%s %s %s> by %s\n",
1101 ((op == 1) ? "invited to" : "kicked out of"),
1106 cprintf("%d %s %s %s.\n",
1108 ((op == 1) ? "invited to" : "kicked out of"),
1115 * Forget (Zap) the current room (API call)
1116 * Returns 0 on success
1118 int CtdlForgetThisRoom(void) {
1121 /* On some systems, Aides are not allowed to forget rooms */
1122 if (is_aide() && (config.c_aide_zap == 0)
1123 && ((CC->room.QRflags & QR_MAILBOX) == 0) ) {
1127 lgetuser(&CC->user, CC->curr_user);
1128 CtdlGetRelationship(&vbuf, &CC->user, &CC->room);
1130 vbuf.v_flags = vbuf.v_flags | V_FORGET;
1131 vbuf.v_flags = vbuf.v_flags & ~V_ACCESS;
1133 CtdlSetRelationship(&vbuf, &CC->user, &CC->room);
1134 lputuser(&CC->user);
1136 /* Return to the Lobby, so we don't end up in an undefined room */
1137 usergoto(config.c_baseroom, 0, 0, NULL, NULL);
1144 * forget (Zap) the current room
1149 if (CtdlAccessCheck(ac_logged_in)) {
1153 if (CtdlForgetThisRoom() == 0) {
1154 cprintf("%d Ok\n", CIT_OK);
1157 cprintf("%d You may not forget this room.\n", ERROR);
1162 * Get Next Unregistered User
1166 struct cdbdata *cdbus;
1169 if (CtdlAccessCheck(ac_aide)) {
1173 if ((CitControl.MMflags & MM_VALID) == 0) {
1174 cprintf("%d There are no unvalidated users.\n", CIT_OK);
1178 /* There are unvalidated users. Traverse the user database,
1179 * and return the first user we find that needs validation.
1181 cdb_rewind(CDB_USERS);
1182 while (cdbus = cdb_next_item(CDB_USERS), cdbus != NULL) {
1183 memset(&usbuf, 0, sizeof(struct user));
1184 memcpy(&usbuf, cdbus->ptr,
1185 ((cdbus->len > sizeof(struct user)) ?
1186 sizeof(struct user) : cdbus->len));
1188 if ((usbuf.flags & US_NEEDVALID)
1189 && (usbuf.axlevel > 0)) {
1190 cprintf("%d %s\n", MORE_DATA, usbuf.fullname);
1191 cdb_close_cursor(CDB_USERS);
1196 /* If we get to this point, there are no more unvalidated users.
1197 * Therefore we clear the "users need validation" flag.
1200 begin_critical_section(S_CONTROL);
1202 CitControl.MMflags = CitControl.MMflags & (~MM_VALID);
1204 end_critical_section(S_CONTROL);
1205 cprintf("%d *** End of registration.\n", CIT_OK);
1214 void cmd_vali(char *v_args)
1218 struct user userbuf;
1220 extract(user, v_args, 0);
1221 newax = extract_int(v_args, 1);
1223 if (CtdlAccessCheck(ac_aide)) {
1227 if (lgetuser(&userbuf, user) != 0) {
1228 cprintf("%d '%s' not found.\n", ERROR + NO_SUCH_USER, user);
1232 userbuf.axlevel = newax;
1233 userbuf.flags = (userbuf.flags & ~US_NEEDVALID);
1237 /* If the access level was set to zero, delete the user */
1239 if (purge_user(user) == 0) {
1240 cprintf("%d %s Deleted.\n", CIT_OK, userbuf.fullname);
1244 cprintf("%d User '%s' validated.\n", CIT_OK, userbuf.fullname);
1250 * Traverse the user file...
1252 void ForEachUser(void (*CallBack) (struct user * EachUser, void *out_data),
1256 struct cdbdata *cdbus;
1258 cdb_rewind(CDB_USERS);
1260 while (cdbus = cdb_next_item(CDB_USERS), cdbus != NULL) {
1261 memset(&usbuf, 0, sizeof(struct user));
1262 memcpy(&usbuf, cdbus->ptr,
1263 ((cdbus->len > sizeof(struct user)) ?
1264 sizeof(struct user) : cdbus->len));
1266 (*CallBack) (&usbuf, in_data);
1272 * List one user (this works with cmd_list)
1274 void ListThisUser(struct user *usbuf, void *data)
1276 if (usbuf->axlevel > 0) {
1277 if ((CC->user.axlevel >= 6)
1278 || ((usbuf->flags & US_UNLISTED) == 0)
1279 || ((CC->internal_pgm))) {
1280 cprintf("%s|%d|%ld|%ld|%ld|%ld|",
1284 (long)usbuf->lastcall,
1287 if (CC->user.axlevel >= 6)
1288 cprintf("%s", usbuf->password);
1299 cprintf("%d \n", LISTING_FOLLOWS);
1300 ForEachUser(ListThisUser, NULL);
1308 * assorted info we need to check at login
1316 if (CtdlAccessCheck(ac_logged_in)) {
1320 getuser(&CC->user, CC->curr_user); /* no lock is needed here */
1321 if ((REGISCALL != 0) && ((CC->user.flags & US_REGIS) == 0))
1324 if (CC->user.axlevel >= 6) {
1326 if (CitControl.MMflags & MM_VALID)
1330 /* check for mail */
1331 mail = InitialMailCheck();
1333 cprintf("%d %d|%d|%d|%s|\n", CIT_OK, mail, regis, vali, CC->cs_inet_email);
1338 * check to see if a user exists
1340 void cmd_qusr(char *who)
1344 if (getuser(&usbuf, who) == 0) {
1345 cprintf("%d %s\n", CIT_OK, usbuf.fullname);
1347 cprintf("%d No such user.\n", ERROR + NO_SUCH_USER);
1353 * Administrative Get User Parameters
1355 void cmd_agup(char *cmdbuf)
1358 char requested_user[SIZ];
1360 if (CtdlAccessCheck(ac_aide)) {
1364 extract(requested_user, cmdbuf, 0);
1365 if (getuser(&usbuf, requested_user) != 0) {
1366 cprintf("%d No such user.\n", ERROR + NO_SUCH_USER);
1369 cprintf("%d %s|%s|%u|%ld|%ld|%d|%ld|%ld|%d\n",
1376 (int) usbuf.axlevel,
1378 (long)usbuf.lastcall,
1385 * Administrative Set User Parameters
1387 void cmd_asup(char *cmdbuf)
1390 char requested_user[SIZ];
1396 if (CtdlAccessCheck(ac_aide))
1399 extract(requested_user, cmdbuf, 0);
1400 if (lgetuser(&usbuf, requested_user) != 0) {
1401 cprintf("%d No such user.\n", ERROR + NO_SUCH_USER);
1404 np = num_parms(cmdbuf);
1406 extract(usbuf.password, cmdbuf, 1);
1408 usbuf.flags = extract_int(cmdbuf, 2);
1410 usbuf.timescalled = extract_int(cmdbuf, 3);
1412 usbuf.posted = extract_int(cmdbuf, 4);
1414 newax = extract_int(cmdbuf, 5);
1415 if ((newax >= 0) && (newax <= 6)) {
1416 usbuf.axlevel = extract_int(cmdbuf, 5);
1420 usbuf.lastcall = extract_long(cmdbuf, 7);
1423 usbuf.USuserpurge = extract_int(cmdbuf, 8);
1426 if (usbuf.axlevel == 0) {
1427 if (purge_user(requested_user) == 0) {
1433 sprintf(notify, "User <%s> deleted by %s\n",
1434 usbuf.fullname, CC->user.fullname);
1435 aide_message(notify);
1438 cprintf("%d Ok", CIT_OK);
1440 cprintf(" (%s deleted)", requested_user);
1447 * Check to see if the user who we just sent mail to is logged in. If yes,
1448 * bump the 'new mail' counter for their session. That enables them to
1449 * receive a new mail notification without having to hit the database.
1451 void BumpNewMailCounter(long which_user) {
1452 struct CitContext *ptr;
1454 begin_critical_section(S_SESSION_TABLE);
1456 for (ptr = ContextList; ptr != NULL; ptr = ptr->next) {
1457 if (ptr->user.usernum == which_user) {
1462 end_critical_section(S_SESSION_TABLE);
1467 * Count the number of new mail messages the user has
1471 int num_newmsgs = 0;
1473 num_newmsgs = CC->newmail;
1476 return (num_newmsgs);
1481 * Count the number of new mail messages the user has
1483 int InitialMailCheck()
1485 int num_newmsgs = 0;
1487 char mailboxname[ROOMNAMELEN];
1488 struct room mailbox;
1490 struct cdbdata *cdbfr;
1491 long *msglist = NULL;
1494 MailboxName(mailboxname, sizeof mailboxname, &CC->user, MAILROOM);
1495 if (getroom(&mailbox, mailboxname) != 0)
1497 CtdlGetRelationship(&vbuf, &CC->user, &mailbox);
1499 cdbfr = cdb_fetch(CDB_MSGLISTS, &mailbox.QRnumber, sizeof(long));
1501 if (cdbfr != NULL) {
1502 msglist = mallok(cdbfr->len);
1503 memcpy(msglist, cdbfr->ptr, cdbfr->len);
1504 num_msgs = cdbfr->len / sizeof(long);
1508 for (a = 0; a < num_msgs; ++a) {
1509 if (msglist[a] > 0L) {
1510 if (msglist[a] > vbuf.v_lastseen) {
1515 if (msglist != NULL)
1518 return (num_newmsgs);
1524 * Set the preferred view for the current user/room combination
1526 void cmd_view(char *cmdbuf) {
1530 if (CtdlAccessCheck(ac_logged_in)) {
1534 requested_view = extract_int(cmdbuf, 0);
1536 CtdlGetRelationship(&vbuf, &CC->user, &CC->room);
1537 vbuf.v_view = requested_view;
1538 CtdlSetRelationship(&vbuf, &CC->user, &CC->room);
1540 cprintf("%d ok\n", CIT_OK);