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 "dynloader.h"
46 #include "sysdep_decls.h"
55 #include "citserver.h"
59 * getuser() - retrieve named user into supplied buffer.
60 * returns 0 on success
62 int getuser(struct usersupp *usbuf, char name[])
65 char lowercase_name[USERNAME_SIZE];
67 struct cdbdata *cdbus;
69 memset(usbuf, 0, sizeof(struct usersupp));
70 for (a = 0; a <= strlen(name); ++a) {
71 if (a < sizeof(lowercase_name))
72 lowercase_name[a] = tolower(name[a]);
74 lowercase_name[sizeof(lowercase_name) - 1] = 0;
76 cdbus = cdb_fetch(CDB_USERSUPP, lowercase_name, strlen(lowercase_name));
78 return (1); /* user not found */
80 memcpy(usbuf, cdbus->ptr,
81 ((cdbus->len > sizeof(struct usersupp)) ?
82 sizeof(struct usersupp) : cdbus->len));
90 * lgetuser() - same as getuser() but locks the record
92 int lgetuser(struct usersupp *usbuf, char *name)
96 retcode = getuser(usbuf, name);
98 begin_critical_section(S_USERSUPP);
105 * putuser() - write user buffer into the correct place on disk
107 void putuser(struct usersupp *usbuf)
109 char lowercase_name[USERNAME_SIZE];
112 for (a = 0; a <= strlen(usbuf->fullname); ++a) {
113 if (a < sizeof(lowercase_name))
114 lowercase_name[a] = tolower(usbuf->fullname[a]);
116 lowercase_name[sizeof(lowercase_name) - 1] = 0;
118 usbuf->version = REV_LEVEL;
119 cdb_store(CDB_USERSUPP,
120 lowercase_name, strlen(lowercase_name),
121 usbuf, sizeof(struct usersupp));
127 * lputuser() - same as putuser() but locks the record
129 void lputuser(struct usersupp *usbuf)
132 end_critical_section(S_USERSUPP);
136 * Index-generating function used by Ctdl[Get|Set]Relationship
138 int GenerateRelationshipIndex(char *IndexBuf,
150 TheIndex.iRoomID = RoomID;
151 TheIndex.iRoomGen = RoomGen;
152 TheIndex.iUserID = UserID;
154 memcpy(IndexBuf, &TheIndex, sizeof(TheIndex));
155 return (sizeof(TheIndex));
161 * Back end for CtdlSetRelationship()
163 void put_visit(struct visit *newvisit)
168 /* Generate an index */
169 IndexLen = GenerateRelationshipIndex(IndexBuf,
172 newvisit->v_usernum);
174 /* Store the record */
175 cdb_store(CDB_VISIT, IndexBuf, IndexLen,
176 newvisit, sizeof(struct visit)
184 * Define a relationship between a user and a room
186 void CtdlSetRelationship(struct visit *newvisit,
187 struct usersupp *rel_user,
188 struct quickroom *rel_room)
192 /* We don't use these in Citadel because they're implicit by the
193 * index, but they must be present if the database is exported.
195 newvisit->v_roomnum = rel_room->QRnumber;
196 newvisit->v_roomgen = rel_room->QRgen;
197 newvisit->v_usernum = rel_user->usernum;
203 * Locate a relationship between a user and a room
205 void CtdlGetRelationship(struct visit *vbuf,
206 struct usersupp *rel_user,
207 struct quickroom *rel_room)
212 struct cdbdata *cdbvisit;
214 /* Generate an index */
215 IndexLen = GenerateRelationshipIndex(IndexBuf,
220 /* Clear out the buffer */
221 memset(vbuf, 0, sizeof(struct visit));
223 cdbvisit = cdb_fetch(CDB_VISIT, IndexBuf, IndexLen);
224 if (cdbvisit != NULL) {
225 memcpy(vbuf, cdbvisit->ptr,
226 ((cdbvisit->len > sizeof(struct visit)) ?
227 sizeof(struct visit) : cdbvisit->len));
231 /* If this is the first time the user has seen this room,
232 * set the view to be the default for the room.
234 vbuf->v_view = rel_room->QRdefaultview;
237 /* Set v_seen if necessary */
238 if (vbuf->v_seen[0] == 0) {
239 snprintf(vbuf->v_seen, sizeof vbuf->v_seen, "*:%ld", vbuf->v_lastseen);
244 void MailboxName(char *buf, size_t n, const struct usersupp *who, const char *prefix)
246 snprintf(buf, n, "%010ld.%s", who->usernum, prefix);
251 * Is the user currently logged in an Aide?
255 if (CC->usersupp.axlevel >= 6)
263 * Is the user currently logged in an Aide *or* the room aide for this room?
265 int is_room_aide(void)
268 if (!CC->logged_in) {
272 if ((CC->usersupp.axlevel >= 6)
273 || (CC->quickroom.QRroomaide == CC->usersupp.usernum)) {
281 * getuserbynumber() - get user by number
282 * returns 0 if user was found
284 * WARNING: don't use this function unless you absolutely have to. It does
285 * a sequential search and therefore is computationally expensive.
287 int getuserbynumber(struct usersupp *usbuf, long int number)
289 struct cdbdata *cdbus;
291 cdb_rewind(CDB_USERSUPP);
293 while (cdbus = cdb_next_item(CDB_USERSUPP), cdbus != NULL) {
294 memset(usbuf, 0, sizeof(struct usersupp));
295 memcpy(usbuf, cdbus->ptr,
296 ((cdbus->len > sizeof(struct usersupp)) ?
297 sizeof(struct usersupp) : cdbus->len));
299 if (usbuf->usernum == number) {
300 cdb_close_cursor(CDB_USERSUPP);
309 * Back end for cmd_user() and its ilk
311 int CtdlLoginExistingUser(char *trythisname)
319 if (trythisname == NULL) return login_not_found;
320 safestrncpy(username, trythisname, sizeof username);
323 if ((CC->logged_in)) {
324 return login_already_logged_in;
326 found_user = getuser(&CC->usersupp, username);
327 if (found_user != 0) {
328 p = (struct passwd *) getpwnam(username);
330 strcpy(autoname, p->pw_gecos);
331 for (a = 0; a < strlen(autoname); ++a)
332 if (autoname[a] == ',')
334 found_user = getuser(&CC->usersupp, autoname);
337 if (found_user == 0) {
338 if (((CC->nologin)) && (CC->usersupp.axlevel < 6)) {
339 return login_too_many_users;
341 strcpy(CC->curr_user, CC->usersupp.fullname);
345 return login_not_found;
353 void cmd_user(char *cmdbuf)
358 extract(username, cmdbuf, 0);
362 a = CtdlLoginExistingUser(username);
364 case login_already_logged_in:
365 cprintf("%d Already logged in.\n", ERROR);
367 case login_too_many_users:
369 "Too many users are already online "
371 ERROR + MAX_SESSIONS_EXCEEDED,
372 config.c_nodename, config.c_maxsessions);
375 cprintf("%d Password required for %s\n",
376 MORE_DATA, CC->curr_user);
378 case login_not_found:
379 cprintf("%d %s not found.\n", ERROR, username);
381 cprintf("%d Internal error\n", ERROR);
388 * session startup code which is common to both cmd_pass() and cmd_newu()
390 void session_startup(void)
394 syslog(LOG_NOTICE, "session %d: user <%s> logged in",
395 CC->cs_pid, CC->curr_user);
397 lgetuser(&CC->usersupp, CC->curr_user);
398 ++(CC->usersupp.timescalled);
399 time(&CC->usersupp.lastcall);
401 /* If this user's name is the name of the system administrator
402 * (as specified in setup), automatically assign access level 6.
404 if (!strcasecmp(CC->usersupp.fullname, config.c_sysadm)) {
405 CC->usersupp.axlevel = 6;
407 lputuser(&CC->usersupp);
410 * Populate CC->cs_inet_email with a default address. This will be
411 * overwritten with the user's directory address, if one exists, when
412 * the vCard module's login hook runs.
414 snprintf(CC->cs_inet_email, sizeof CC->cs_inet_email, "%s@%s",
415 CC->usersupp.fullname, config.c_fqdn);
416 for (i=0; i<strlen(CC->cs_inet_email); ++i) {
417 if (isspace(CC->cs_inet_email[i])) {
418 CC->cs_inet_email[i] = '_';
422 /* Create any personal rooms required by the system.
423 * (Technically, MAILROOM should be there already, but just in case...)
425 create_room(MAILROOM, 4, "", 0, 1, 0);
426 create_room(SENTITEMS, 4, "", 0, 1, 0);
428 /* Run any startup routines registered by loadable modules */
429 PerformSessionHooks(EVT_LOGIN);
431 /* Enter the lobby */
432 usergoto(config.c_baseroom, 0, 0, NULL, NULL);
434 /* Record this login in the Citadel log */
435 rec_log(CL_LOGIN, CC->curr_user);
439 void logged_in_response(void)
441 cprintf("%d %s|%d|%ld|%ld|%u|%ld|%ld\n",
442 CIT_OK, CC->usersupp.fullname, CC->usersupp.axlevel,
443 CC->usersupp.timescalled, CC->usersupp.posted,
444 CC->usersupp.flags, CC->usersupp.usernum,
445 CC->usersupp.lastcall);
451 * misc things to be taken care of when a user is logged out
453 void logout(struct CitContext *who)
458 * If there is a download in progress, abort it.
460 if (who->download_fp != NULL) {
461 fclose(who->download_fp);
462 who->download_fp = NULL;
466 * If there is an upload in progress, abort it.
468 if (who->upload_fp != NULL) {
473 * If we were talking to a network node, we're not anymore...
475 if (strlen(who->net_node) > 0) {
476 network_talking_to(who->net_node, NTT_REMOVE);
479 /* Do modular stuff... */
480 PerformSessionHooks(EVT_LOGOUT);
485 * an alternate version of validpw() which executes `chkpwd' instead of
486 * verifying the password directly
488 static int validpw(uid_t uid, const char *pass)
491 int status, pipev[2];
495 lprintf(1, "pipe failed (%s): denying autologin access for "
496 "uid %ld\n", strerror(errno), (long)uid);
499 switch (pid = fork()) {
501 lprintf(1, "fork failed (%s): denying autologin access for "
502 "uid %ld\n", strerror(errno), (long)uid);
509 if (dup2(pipev[0], 0) == -1) {
515 execl(BBSDIR "/chkpwd", BBSDIR "/chkpwd", NULL);
516 perror(BBSDIR "/chkpwd");
522 snprintf(buf, sizeof buf, "%lu\n", (unsigned long) uid));
523 write(pipev[1], pass, strlen(pass));
524 write(pipev[1], "\n", 1);
527 while (waitpid(pid, &status, 0) == -1)
528 if (errno != EINTR) {
529 lprintf(1, "waitpid failed (%s): denying autologin "
530 "access for uid %ld\n",
531 strerror(errno), (long)uid);
534 if (WIFEXITED(status) && !WEXITSTATUS(status))
548 int CtdlTryPassword(char *password)
552 if ((CC->logged_in)) {
553 lprintf(5, "CtdlTryPassword: already logged in\n");
554 return pass_already_logged_in;
556 if (!strcmp(CC->curr_user, NLI)) {
557 lprintf(5, "CtdlTryPassword: no user selected\n");
560 if (getuser(&CC->usersupp, CC->curr_user)) {
561 lprintf(5, "CtdlTryPassword: internal error\n");
562 return pass_internal_error;
564 if (password == NULL) {
565 lprintf(5, "CtdlTryPassword: NULL password string supplied\n");
566 return pass_wrong_password;
569 if (CC->usersupp.uid == BBSUID) {
571 strproc(CC->usersupp.password);
572 code = strcasecmp(CC->usersupp.password, password);
574 #ifdef ENABLE_AUTOLOGIN
576 if (validpw(CC->usersupp.uid, password)) {
578 lgetuser(&CC->usersupp, CC->curr_user);
579 safestrncpy(CC->usersupp.password, password,
580 sizeof CC->usersupp.password);
581 lputuser(&CC->usersupp);
590 rec_log(CL_BADPW, CC->curr_user);
591 return pass_wrong_password;
596 void cmd_pass(char *buf)
601 extract(password, buf, 0);
602 a = CtdlTryPassword(password);
605 case pass_already_logged_in:
606 cprintf("%d Already logged in.\n", ERROR);
609 cprintf("%d You must send a name with USER first.\n",
612 case pass_wrong_password:
613 cprintf("%d Wrong password.\n", ERROR);
616 logged_in_response();
618 cprintf("%d Can't find user record!\n",
619 ERROR + INTERNAL_ERROR);
626 * Delete a user record *and* all of its related resources.
628 int purge_user(char pname[])
631 struct usersupp usbuf;
632 char lowercase_name[USERNAME_SIZE];
634 struct CitContext *ccptr;
635 int user_is_logged_in = 0;
637 for (a = 0; a <= strlen(pname); ++a) {
638 lowercase_name[a] = tolower(pname[a]);
641 if (getuser(&usbuf, pname) != 0) {
642 lprintf(5, "Cannot purge user <%s> - not found\n", pname);
643 return (ERROR + NO_SUCH_USER);
645 /* Don't delete a user who is currently logged in. Instead, just
646 * set the access level to 0, and let the account get swept up
647 * during the next purge.
649 user_is_logged_in = 0;
650 begin_critical_section(S_SESSION_TABLE);
651 for (ccptr = ContextList; ccptr != NULL; ccptr = ccptr->next) {
652 if (ccptr->usersupp.usernum == usbuf.usernum) {
653 user_is_logged_in = 1;
656 end_critical_section(S_SESSION_TABLE);
657 if (user_is_logged_in == 1) {
658 lprintf(5, "User <%s> is logged in; not deleting.\n", pname);
663 lprintf(5, "Deleting user <%s>\n", pname);
665 /* Perform any purge functions registered by server extensions */
666 PerformUserHooks(usbuf.fullname, usbuf.usernum, EVT_PURGEUSER);
668 /* delete any existing user/room relationships */
669 cdb_delete(CDB_VISIT, &usbuf.usernum, sizeof(long));
671 /* delete the userlog entry */
672 cdb_delete(CDB_USERSUPP, lowercase_name, strlen(lowercase_name));
674 /* remove the user's bio file */
675 snprintf(filename, sizeof filename, "./bio/%ld", usbuf.usernum);
678 /* remove the user's picture */
679 snprintf(filename, sizeof filename, "./userpics/%ld.gif", usbuf.usernum);
687 * create_user() - back end processing to create a new user
689 * Set 'newusername' to the desired account name.
690 * Set 'become_user' to nonzero if this is self-service account creation and we want
691 * to actually log in as the user we just created, otherwise set it to 0.
693 int create_user(char *newusername, int become_user)
695 struct usersupp usbuf;
696 struct quickroom qrbuf;
697 struct passwd *p = NULL;
699 char mailboxname[ROOMNAMELEN];
702 strcpy(username, newusername);
705 #ifdef ENABLE_AUTOLOGIN
706 p = (struct passwd *) getpwnam(username);
709 extract_token(username, p->pw_gecos, 0, ',');
715 if (!getuser(&usbuf, username)) {
716 return (ERROR + ALREADY_EXISTS);
719 /* Go ahead and initialize a new user record */
720 memset(&usbuf, 0, sizeof(struct usersupp));
721 strcpy(usbuf.fullname, username);
722 strcpy(usbuf.password, "");
725 /* These are the default flags on new accounts */
726 usbuf.flags = US_LASTOLD | US_DISAPPEAR | US_PAGINATOR | US_FLOORS;
728 usbuf.timescalled = 0;
730 usbuf.axlevel = config.c_initax;
731 usbuf.USscreenwidth = 80;
732 usbuf.USscreenheight = 24;
733 usbuf.lastcall = time(NULL);
735 /* fetch a new user number */
736 usbuf.usernum = get_new_user_number();
738 /* The very first user created on the system will always be an Aide */
739 if (usbuf.usernum == 1L) {
743 /* add user to userlog */
747 * Give the user a private mailbox and a configuration room.
748 * Make the latter an invisible system room.
750 MailboxName(mailboxname, sizeof mailboxname, &usbuf, MAILROOM);
751 create_room(mailboxname, 5, "", 0, 1, 1);
753 MailboxName(mailboxname, sizeof mailboxname, &usbuf, USERCONFIGROOM);
754 create_room(mailboxname, 5, "", 0, 1, 1);
755 if (lgetroom(&qrbuf, USERCONFIGROOM) == 0) {
756 qrbuf.QRflags2 |= QR2_SYSTEM;
760 /* Everything below this line can be bypassed if administratively
761 creating a user, instead of doing self-service account creation
765 /* Now become the user we just created */
766 memcpy(&CC->usersupp, &usbuf, sizeof(struct usersupp));
767 strcpy(CC->curr_user, username);
770 /* Check to make sure we're still who we think we are */
771 if (getuser(&CC->usersupp, CC->curr_user)) {
772 return (ERROR + INTERNAL_ERROR);
775 rec_log(CL_NEWUSER, CC->curr_user);
785 * cmd_newu() - create a new user account and log in as that user
787 void cmd_newu(char *cmdbuf)
792 if (config.c_disable_newu) {
793 cprintf("%d Self-service user account creation "
794 "is disabled on this system.\n", ERROR);
799 cprintf("%d Already logged in.\n", ERROR);
803 cprintf("%d %s: Too many users are already online (maximum is %d)\n",
804 ERROR + MAX_SESSIONS_EXCEEDED,
805 config.c_nodename, config.c_maxsessions);
807 extract(username, cmdbuf, 0);
811 if (strlen(username) == 0) {
812 cprintf("%d You must supply a user name.\n", ERROR);
816 if ((!strcasecmp(username, "bbs")) ||
817 (!strcasecmp(username, "new")) ||
818 (!strcasecmp(username, "."))) {
819 cprintf("%d '%s' is an invalid login name.\n", ERROR, username);
823 a = create_user(username, 1);
827 logged_in_response();
828 } else if (a == ERROR + ALREADY_EXISTS) {
829 cprintf("%d '%s' already exists.\n",
830 ERROR + ALREADY_EXISTS, username);
832 } else if (a == ERROR + INTERNAL_ERROR) {
833 cprintf("%d Internal error - user record disappeared?\n",
834 ERROR + INTERNAL_ERROR);
837 cprintf("%d unknown error\n", ERROR);
839 rec_log(CL_NEWUSER, CC->curr_user);
847 void cmd_setp(char *new_pw)
849 if (CtdlAccessCheck(ac_logged_in)) {
853 if (CC->usersupp.uid != BBSUID) {
854 cprintf("%d Not allowed. Use the 'passwd' command.\n", ERROR);
858 if (strlen(new_pw) == 0) {
859 cprintf("%d Password unchanged.\n", CIT_OK);
862 lgetuser(&CC->usersupp, CC->curr_user);
863 strcpy(CC->usersupp.password, new_pw);
864 lputuser(&CC->usersupp);
865 cprintf("%d Password changed.\n", CIT_OK);
866 rec_log(CL_PWCHANGE, CC->curr_user);
867 PerformSessionHooks(EVT_SETPASS);
872 * cmd_creu() - administratively create a new user account (do not log in to it)
874 void cmd_creu(char *cmdbuf)
879 if (CtdlAccessCheck(ac_aide)) {
883 extract(username, cmdbuf, 0);
887 if (strlen(username) == 0) {
888 cprintf("%d You must supply a user name.\n", ERROR);
892 a = create_user(username, 0);
895 cprintf("%d ok\n", CIT_OK);
897 } else if (a == ERROR + ALREADY_EXISTS) {
898 cprintf("%d '%s' already exists.\n",
899 ERROR + ALREADY_EXISTS, username);
902 cprintf("%d An error occured creating the user account.\n", ERROR);
904 rec_log(CL_NEWUSER, username);
910 * get user parameters
915 if (CtdlAccessCheck(ac_logged_in))
918 getuser(&CC->usersupp, CC->curr_user);
919 cprintf("%d %d|%d|%d|\n",
921 CC->usersupp.USscreenwidth,
922 CC->usersupp.USscreenheight,
923 (CC->usersupp.flags & US_USER_SET)
928 * set user parameters
930 void cmd_setu(char *new_parms)
932 if (CtdlAccessCheck(ac_logged_in))
935 if (num_parms(new_parms) < 3) {
936 cprintf("%d Usage error.\n", ERROR);
939 lgetuser(&CC->usersupp, CC->curr_user);
940 CC->usersupp.USscreenwidth = extract_int(new_parms, 0);
941 CC->usersupp.USscreenheight = extract_int(new_parms, 1);
942 CC->usersupp.flags = CC->usersupp.flags & (~US_USER_SET);
943 CC->usersupp.flags = CC->usersupp.flags |
944 (extract_int(new_parms, 2) & US_USER_SET);
946 lputuser(&CC->usersupp);
947 cprintf("%d Ok\n", CIT_OK);
951 * set last read pointer
953 void cmd_slrp(char *new_ptr)
958 if (CtdlAccessCheck(ac_logged_in)) {
962 if (!strncasecmp(new_ptr, "highest", 7)) {
963 newlr = CC->quickroom.QRhighest;
965 newlr = atol(new_ptr);
968 lgetuser(&CC->usersupp, CC->curr_user);
970 CtdlGetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
971 vbuf.v_lastseen = newlr;
972 snprintf(vbuf.v_seen, sizeof vbuf.v_seen, "*:%ld", newlr);
973 CtdlSetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
975 lputuser(&CC->usersupp);
976 cprintf("%d %ld\n", CIT_OK, newlr);
980 void cmd_seen(char *argbuf) {
981 long target_msgnum = 0L;
982 int target_setting = 0;
984 if (CtdlAccessCheck(ac_logged_in)) {
988 if (num_parms(argbuf) != 2) {
989 cprintf("%d Invalid parameters\n", ERROR);
993 target_msgnum = extract_long(argbuf, 0);
994 target_setting = extract_int(argbuf, 1);
996 CtdlSetSeen(target_msgnum, target_setting);
997 cprintf("%d OK\n", CIT_OK);
1001 void cmd_gtsn(char *argbuf) {
1004 if (CtdlAccessCheck(ac_logged_in)) {
1009 cprintf("%d %s\n", CIT_OK, buf);
1015 * INVT and KICK commands
1017 void cmd_invt_kick(char *iuser, int op)
1019 { /* 1 = invite, 0 = kick out */
1020 struct usersupp USscratch;
1025 * These commands are only allowed by aides, room aides,
1026 * and room namespace owners
1029 || (atol(CC->quickroom.QRname) == CC->usersupp.usernum) ) {
1030 /* access granted */
1033 cprintf("%d Higher access or room ownership required.\n",
1034 ERROR + HIGHER_ACCESS_REQUIRED);
1038 if (!strncasecmp(CC->quickroom.QRname, config.c_baseroom,
1040 cprintf("%d Can't add/remove users from this room.\n",
1045 if (lgetuser(&USscratch, iuser) != 0) {
1046 cprintf("%d No such user.\n", ERROR);
1049 CtdlGetRelationship(&vbuf, &USscratch, &CC->quickroom);
1052 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
1053 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
1056 vbuf.v_flags = vbuf.v_flags & ~V_ACCESS;
1057 vbuf.v_flags = vbuf.v_flags | V_FORGET | V_LOCKOUT;
1059 CtdlSetRelationship(&vbuf, &USscratch, &CC->quickroom);
1061 lputuser(&USscratch);
1063 /* post a message in Aide> saying what we just did */
1064 snprintf(bbb, sizeof bbb, "%s %s %s> by %s\n",
1066 ((op == 1) ? "invited to" : "kicked out of"),
1067 CC->quickroom.QRname,
1068 CC->usersupp.fullname);
1071 cprintf("%d %s %s %s.\n",
1073 ((op == 1) ? "invited to" : "kicked out of"),
1074 CC->quickroom.QRname);
1080 * Forget (Zap) the current room (API call)
1081 * Returns 0 on success
1083 int CtdlForgetThisRoom(void) {
1086 /* On some systems, Aides are not allowed to forget rooms */
1087 if (is_aide() && (config.c_aide_zap == 0)
1088 && ((CC->quickroom.QRflags & QR_MAILBOX) == 0) ) {
1092 lgetuser(&CC->usersupp, CC->curr_user);
1093 CtdlGetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
1095 vbuf.v_flags = vbuf.v_flags | V_FORGET;
1096 vbuf.v_flags = vbuf.v_flags & ~V_ACCESS;
1098 CtdlSetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
1099 lputuser(&CC->usersupp);
1101 /* Return to the Lobby, so we don't end up in an undefined room */
1102 usergoto(config.c_baseroom, 0, 0, NULL, NULL);
1109 * forget (Zap) the current room
1114 if (CtdlAccessCheck(ac_logged_in)) {
1118 if (CtdlForgetThisRoom() == 0) {
1119 cprintf("%d Ok\n", CIT_OK);
1122 cprintf("%d You may not forget this room.\n", ERROR);
1127 * Get Next Unregistered User
1131 struct cdbdata *cdbus;
1132 struct usersupp usbuf;
1134 if (CtdlAccessCheck(ac_aide)) {
1138 if ((CitControl.MMflags & MM_VALID) == 0) {
1139 cprintf("%d There are no unvalidated users.\n", CIT_OK);
1143 /* There are unvalidated users. Traverse the usersupp database,
1144 * and return the first user we find that needs validation.
1146 cdb_rewind(CDB_USERSUPP);
1147 while (cdbus = cdb_next_item(CDB_USERSUPP), cdbus != NULL) {
1148 memset(&usbuf, 0, sizeof(struct usersupp));
1149 memcpy(&usbuf, cdbus->ptr,
1150 ((cdbus->len > sizeof(struct usersupp)) ?
1151 sizeof(struct usersupp) : cdbus->len));
1153 if ((usbuf.flags & US_NEEDVALID)
1154 && (usbuf.axlevel > 0)) {
1155 cprintf("%d %s\n", MORE_DATA, usbuf.fullname);
1156 cdb_close_cursor(CDB_USERSUPP);
1161 /* If we get to this point, there are no more unvalidated users.
1162 * Therefore we clear the "users need validation" flag.
1165 begin_critical_section(S_CONTROL);
1167 CitControl.MMflags = CitControl.MMflags & (~MM_VALID);
1169 end_critical_section(S_CONTROL);
1170 cprintf("%d *** End of registration.\n", CIT_OK);
1179 void cmd_vali(char *v_args)
1183 struct usersupp userbuf;
1185 extract(user, v_args, 0);
1186 newax = extract_int(v_args, 1);
1188 if (CtdlAccessCheck(ac_aide)) {
1192 if (lgetuser(&userbuf, user) != 0) {
1193 cprintf("%d '%s' not found.\n", ERROR + NO_SUCH_USER, user);
1197 userbuf.axlevel = newax;
1198 userbuf.flags = (userbuf.flags & ~US_NEEDVALID);
1202 /* If the access level was set to zero, delete the user */
1204 if (purge_user(user) == 0) {
1205 cprintf("%d %s Deleted.\n", CIT_OK, userbuf.fullname);
1209 cprintf("%d User '%s' validated.\n", CIT_OK, userbuf.fullname);
1215 * Traverse the user file...
1217 void ForEachUser(void (*CallBack) (struct usersupp * EachUser, void *out_data),
1220 struct usersupp usbuf;
1221 struct cdbdata *cdbus;
1223 cdb_rewind(CDB_USERSUPP);
1225 while (cdbus = cdb_next_item(CDB_USERSUPP), cdbus != NULL) {
1226 memset(&usbuf, 0, sizeof(struct usersupp));
1227 memcpy(&usbuf, cdbus->ptr,
1228 ((cdbus->len > sizeof(struct usersupp)) ?
1229 sizeof(struct usersupp) : cdbus->len));
1231 (*CallBack) (&usbuf, in_data);
1237 * List one user (this works with cmd_list)
1239 void ListThisUser(struct usersupp *usbuf, void *data)
1241 if (usbuf->axlevel > 0) {
1242 if ((CC->usersupp.axlevel >= 6)
1243 || ((usbuf->flags & US_UNLISTED) == 0)
1244 || ((CC->internal_pgm))) {
1245 cprintf("%s|%d|%ld|%ld|%ld|%ld|",
1249 (long)usbuf->lastcall,
1252 if (CC->usersupp.axlevel >= 6)
1253 cprintf("%s", usbuf->password);
1264 cprintf("%d \n", LISTING_FOLLOWS);
1265 ForEachUser(ListThisUser, NULL);
1273 * assorted info we need to check at login
1281 if (CtdlAccessCheck(ac_logged_in)) {
1285 getuser(&CC->usersupp, CC->curr_user); /* no lock is needed here */
1286 if ((REGISCALL != 0) && ((CC->usersupp.flags & US_REGIS) == 0))
1289 if (CC->usersupp.axlevel >= 6) {
1291 if (CitControl.MMflags & MM_VALID)
1295 /* check for mail */
1296 mail = InitialMailCheck();
1298 cprintf("%d %d|%d|%d|%s|\n", CIT_OK, mail, regis, vali, CC->cs_inet_email);
1303 * check to see if a user exists
1305 void cmd_qusr(char *who)
1307 struct usersupp usbuf;
1309 if (getuser(&usbuf, who) == 0) {
1310 cprintf("%d %s\n", CIT_OK, usbuf.fullname);
1312 cprintf("%d No such user.\n", ERROR + NO_SUCH_USER);
1318 * Administrative Get User Parameters
1320 void cmd_agup(char *cmdbuf)
1322 struct usersupp usbuf;
1323 char requested_user[SIZ];
1325 if (CtdlAccessCheck(ac_aide)) {
1329 extract(requested_user, cmdbuf, 0);
1330 if (getuser(&usbuf, requested_user) != 0) {
1331 cprintf("%d No such user.\n", ERROR + NO_SUCH_USER);
1334 cprintf("%d %s|%s|%u|%ld|%ld|%d|%ld|%ld|%d\n",
1341 (int) usbuf.axlevel,
1343 (long)usbuf.lastcall,
1350 * Administrative Set User Parameters
1352 void cmd_asup(char *cmdbuf)
1354 struct usersupp usbuf;
1355 char requested_user[SIZ];
1361 if (CtdlAccessCheck(ac_aide))
1364 extract(requested_user, cmdbuf, 0);
1365 if (lgetuser(&usbuf, requested_user) != 0) {
1366 cprintf("%d No such user.\n", ERROR + NO_SUCH_USER);
1369 np = num_parms(cmdbuf);
1371 extract(usbuf.password, cmdbuf, 1);
1373 usbuf.flags = extract_int(cmdbuf, 2);
1375 usbuf.timescalled = extract_int(cmdbuf, 3);
1377 usbuf.posted = extract_int(cmdbuf, 4);
1379 newax = extract_int(cmdbuf, 5);
1380 if ((newax >= 0) && (newax <= 6)) {
1381 usbuf.axlevel = extract_int(cmdbuf, 5);
1385 usbuf.lastcall = extract_long(cmdbuf, 7);
1388 usbuf.USuserpurge = extract_int(cmdbuf, 8);
1391 if (usbuf.axlevel == 0) {
1392 if (purge_user(requested_user) == 0) {
1398 sprintf(notify, "User <%s> deleted by %s\n",
1399 usbuf.fullname, CC->usersupp.fullname);
1400 aide_message(notify);
1403 cprintf("%d Ok", CIT_OK);
1405 cprintf(" (%s deleted)", requested_user);
1412 * Check to see if the user who we just sent mail to is logged in. If yes,
1413 * bump the 'new mail' counter for their session. That enables them to
1414 * receive a new mail notification without having to hit the database.
1416 void BumpNewMailCounter(long which_user) {
1417 struct CitContext *ptr;
1419 begin_critical_section(S_SESSION_TABLE);
1421 for (ptr = ContextList; ptr != NULL; ptr = ptr->next) {
1422 if (ptr->usersupp.usernum == which_user) {
1427 end_critical_section(S_SESSION_TABLE);
1432 * Count the number of new mail messages the user has
1436 int num_newmsgs = 0;
1438 num_newmsgs = CC->newmail;
1441 return (num_newmsgs);
1446 * Count the number of new mail messages the user has
1448 int InitialMailCheck()
1450 int num_newmsgs = 0;
1452 char mailboxname[ROOMNAMELEN];
1453 struct quickroom mailbox;
1455 struct cdbdata *cdbfr;
1456 long *msglist = NULL;
1459 MailboxName(mailboxname, sizeof mailboxname, &CC->usersupp, MAILROOM);
1460 if (getroom(&mailbox, mailboxname) != 0)
1462 CtdlGetRelationship(&vbuf, &CC->usersupp, &mailbox);
1464 cdbfr = cdb_fetch(CDB_MSGLISTS, &mailbox.QRnumber, sizeof(long));
1466 if (cdbfr != NULL) {
1467 msglist = mallok(cdbfr->len);
1468 memcpy(msglist, cdbfr->ptr, cdbfr->len);
1469 num_msgs = cdbfr->len / sizeof(long);
1473 for (a = 0; a < num_msgs; ++a) {
1474 if (msglist[a] > 0L) {
1475 if (msglist[a] > vbuf.v_lastseen) {
1480 if (msglist != NULL)
1483 return (num_newmsgs);
1489 * Set the preferred view for the current user/room combination
1491 void cmd_view(char *cmdbuf) {
1495 if (CtdlAccessCheck(ac_logged_in)) {
1499 requested_view = extract_int(cmdbuf, 0);
1501 CtdlGetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
1502 vbuf.v_view = requested_view;
1503 CtdlSetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
1505 cprintf("%d ok\n", CIT_OK);