4 * Server functions which perform operations on user objects.
20 #include <sys/types.h>
23 #if TIME_WITH_SYS_TIME
24 # include <sys/time.h>
28 # include <sys/time.h>
44 #include "dynloader.h"
45 #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 usersupp *usbuf, char name[])
64 char lowercase_name[32];
66 struct cdbdata *cdbus;
68 memset(usbuf, 0, sizeof(struct usersupp));
69 for (a = 0; a <= strlen(name); ++a) {
70 if (a < sizeof(lowercase_name))
71 lowercase_name[a] = tolower(name[a]);
73 lowercase_name[sizeof(lowercase_name) - 1] = 0;
75 cdbus = cdb_fetch(CDB_USERSUPP, lowercase_name, strlen(lowercase_name));
77 return (1); /* user not found */
79 memcpy(usbuf, cdbus->ptr,
80 ((cdbus->len > sizeof(struct usersupp)) ?
81 sizeof(struct usersupp) : cdbus->len));
89 * lgetuser() - same as getuser() but locks the record
91 int lgetuser(struct usersupp *usbuf, char *name)
95 retcode = getuser(usbuf, name);
97 begin_critical_section(S_USERSUPP);
104 * putuser() - write user buffer into the correct place on disk
106 void putuser(struct usersupp *usbuf)
108 char lowercase_name[32];
111 for (a = 0; a <= strlen(usbuf->fullname); ++a) {
112 if (a < sizeof(lowercase_name))
113 lowercase_name[a] = tolower(usbuf->fullname[a]);
115 lowercase_name[sizeof(lowercase_name) - 1] = 0;
117 usbuf->version = REV_LEVEL;
118 cdb_store(CDB_USERSUPP,
119 lowercase_name, strlen(lowercase_name),
120 usbuf, sizeof(struct usersupp));
126 * lputuser() - same as putuser() but locks the record
128 void lputuser(struct usersupp *usbuf)
131 end_critical_section(S_USERSUPP);
135 * Index-generating function used by Ctdl[Get|Set]Relationship
137 int GenerateRelationshipIndex(char *IndexBuf,
149 TheIndex.iRoomID = RoomID;
150 TheIndex.iRoomGen = RoomGen;
151 TheIndex.iUserID = UserID;
153 memcpy(IndexBuf, &TheIndex, sizeof(TheIndex));
154 return (sizeof(TheIndex));
160 * Back end for CtdlSetRelationship()
162 void put_visit(struct visit *newvisit)
167 /* Generate an index */
168 IndexLen = GenerateRelationshipIndex(IndexBuf,
171 newvisit->v_usernum);
173 /* Store the record */
174 cdb_store(CDB_VISIT, IndexBuf, IndexLen,
175 newvisit, sizeof(struct visit)
183 * Define a relationship between a user and a room
185 void CtdlSetRelationship(struct visit *newvisit,
186 struct usersupp *rel_user,
187 struct quickroom *rel_room)
191 /* We don't use these in Citadel because they're implicit by the
192 * index, but they must be present if the database is exported.
194 newvisit->v_roomnum = rel_room->QRnumber;
195 newvisit->v_roomgen = rel_room->QRgen;
196 newvisit->v_usernum = rel_user->usernum;
202 * Locate a relationship between a user and a room
204 void CtdlGetRelationship(struct visit *vbuf,
205 struct usersupp *rel_user,
206 struct quickroom *rel_room)
211 struct cdbdata *cdbvisit;
213 /* Generate an index */
214 IndexLen = GenerateRelationshipIndex(IndexBuf,
219 /* Clear out the buffer */
220 memset(vbuf, 0, sizeof(struct visit));
222 cdbvisit = cdb_fetch(CDB_VISIT, IndexBuf, IndexLen);
223 if (cdbvisit != NULL) {
224 memcpy(vbuf, cdbvisit->ptr,
225 ((cdbvisit->len > sizeof(struct visit)) ?
226 sizeof(struct visit) : cdbvisit->len));
230 /* If this is the first time the user has seen this room,
231 * set the view to be the default for the room.
233 vbuf->v_view = rel_room->QRdefaultview;
236 /* Set v_seen if necessary */
237 if (vbuf->v_seen[0] == 0) {
238 snprintf(vbuf->v_seen, sizeof vbuf->v_seen, "*:%ld", vbuf->v_lastseen);
243 void MailboxName(char *buf, size_t n, const struct usersupp *who, const char *prefix)
245 snprintf(buf, n, "%010ld.%s", who->usernum, prefix);
250 * Is the user currently logged in an Aide?
254 if (CC->usersupp.axlevel >= 6)
262 * Is the user currently logged in an Aide *or* the room aide for this room?
264 int is_room_aide(void)
267 if (!CC->logged_in) {
271 if ((CC->usersupp.axlevel >= 6)
272 || (CC->quickroom.QRroomaide == CC->usersupp.usernum)) {
280 * getuserbynumber() - get user by number
281 * returns 0 if user was found
283 * WARNING: don't use this function unless you absolutely have to. It does
284 * a sequential search and therefore is computationally expensive.
286 int getuserbynumber(struct usersupp *usbuf, long int number)
288 struct cdbdata *cdbus;
290 cdb_rewind(CDB_USERSUPP);
292 while (cdbus = cdb_next_item(CDB_USERSUPP), cdbus != NULL) {
293 memset(usbuf, 0, sizeof(struct usersupp));
294 memcpy(usbuf, cdbus->ptr,
295 ((cdbus->len > sizeof(struct usersupp)) ?
296 sizeof(struct usersupp) : cdbus->len));
298 if (usbuf->usernum == number) {
299 cdb_close_cursor(CDB_USERSUPP);
308 * Back end for cmd_user() and its ilk
310 int CtdlLoginExistingUser(char *trythisname)
318 if (trythisname == NULL) return login_not_found;
319 safestrncpy(username, trythisname, sizeof username);
322 if ((CC->logged_in)) {
323 return login_already_logged_in;
325 found_user = getuser(&CC->usersupp, username);
326 if (found_user != 0) {
327 p = (struct passwd *) getpwnam(username);
329 strcpy(autoname, p->pw_gecos);
330 for (a = 0; a < strlen(autoname); ++a)
331 if (autoname[a] == ',')
333 found_user = getuser(&CC->usersupp, autoname);
336 if (found_user == 0) {
337 if (((CC->nologin)) && (CC->usersupp.axlevel < 6)) {
338 return login_too_many_users;
340 strcpy(CC->curr_user, CC->usersupp.fullname);
344 return login_not_found;
352 void cmd_user(char *cmdbuf)
357 extract(username, cmdbuf, 0);
361 a = CtdlLoginExistingUser(username);
363 case login_already_logged_in:
364 cprintf("%d Already logged in.\n", ERROR);
366 case login_too_many_users:
368 "Too many users are already online "
370 ERROR + MAX_SESSIONS_EXCEEDED,
371 config.c_nodename, config.c_maxsessions);
374 cprintf("%d Password required for %s\n",
375 MORE_DATA, CC->curr_user);
377 case login_not_found:
378 cprintf("%d %s not found.\n", ERROR, username);
380 cprintf("%d Internal error\n", ERROR);
387 * session startup code which is common to both cmd_pass() and cmd_newu()
389 void session_startup(void)
391 syslog(LOG_NOTICE, "session %d: user <%s> logged in",
392 CC->cs_pid, CC->curr_user);
394 lgetuser(&CC->usersupp, CC->curr_user);
395 ++(CC->usersupp.timescalled);
396 time(&CC->usersupp.lastcall);
398 /* If this user's name is the name of the system administrator
399 * (as specified in setup), automatically assign access level 6.
401 if (!strcasecmp(CC->usersupp.fullname, config.c_sysadm)) {
402 CC->usersupp.axlevel = 6;
404 lputuser(&CC->usersupp);
406 /* Run any startup routines registered by loadable modules */
407 PerformSessionHooks(EVT_LOGIN);
409 /* Create any personal rooms required by the system */
410 create_room(SENTITEMS, 4, "", 0, 1, 0);
412 /* Enter the lobby */
413 usergoto(config.c_baseroom, 0, 0, NULL, NULL);
415 /* Record this login in the Citadel log */
416 rec_log(CL_LOGIN, CC->curr_user);
420 void logged_in_response(void)
422 cprintf("%d %s|%d|%ld|%ld|%u|%ld|%ld\n",
423 CIT_OK, CC->usersupp.fullname, CC->usersupp.axlevel,
424 CC->usersupp.timescalled, CC->usersupp.posted,
425 CC->usersupp.flags, CC->usersupp.usernum,
426 CC->usersupp.lastcall);
432 * misc things to be taken care of when a user is logged out
434 void logout(struct CitContext *who)
439 * If there is a download in progress, abort it.
441 if (who->download_fp != NULL) {
442 fclose(who->download_fp);
443 who->download_fp = NULL;
447 * If there is an upload in progress, abort it.
449 if (who->upload_fp != NULL) {
454 * If we were talking to a network node, we're not anymore...
456 if (strlen(who->net_node) > 0) {
457 network_talking_to(who->net_node, NTT_REMOVE);
461 * Yes, we really need to free EVERY LAST BYTE we allocated.
463 if (who->cs_inet_email != NULL) {
464 phree(who->cs_inet_email);
465 who->cs_inet_email = NULL;
468 /* Do modular stuff... */
469 PerformSessionHooks(EVT_LOGOUT);
474 * an alternate version of validpw() which executes `chkpwd' instead of
475 * verifying the password directly
477 static int validpw(uid_t uid, const char *pass)
480 int status, pipev[2];
484 lprintf(1, "pipe failed (%s): denying autologin access for "
485 "uid %ld\n", strerror(errno), (long)uid);
488 switch (pid = fork()) {
490 lprintf(1, "fork failed (%s): denying autologin access for "
491 "uid %ld\n", strerror(errno), (long)uid);
498 if (dup2(pipev[0], 0) == -1) {
504 execl(BBSDIR "/chkpwd", BBSDIR "/chkpwd", NULL);
505 perror(BBSDIR "/chkpwd");
511 snprintf(buf, sizeof buf, "%lu\n", (unsigned long) uid));
512 write(pipev[1], pass, strlen(pass));
513 write(pipev[1], "\n", 1);
516 while (waitpid(pid, &status, 0) == -1)
517 if (errno != EINTR) {
518 lprintf(1, "waitpid failed (%s): denying autologin "
519 "access for uid %ld\n",
520 strerror(errno), (long)uid);
523 if (WIFEXITED(status) && !WEXITSTATUS(status))
537 int CtdlTryPassword(char *password)
541 if ((CC->logged_in)) {
542 lprintf(5, "CtdlTryPassword: already logged in\n");
543 return pass_already_logged_in;
545 if (!strcmp(CC->curr_user, NLI)) {
546 lprintf(5, "CtdlTryPassword: no user selected\n");
549 if (getuser(&CC->usersupp, CC->curr_user)) {
550 lprintf(5, "CtdlTryPassword: internal error\n");
551 return pass_internal_error;
553 if (password == NULL) {
554 lprintf(5, "CtdlTryPassword: NULL password string supplied\n");
555 return pass_wrong_password;
558 if (CC->usersupp.uid == BBSUID) {
560 strproc(CC->usersupp.password);
561 code = strcasecmp(CC->usersupp.password, password);
563 #ifdef ENABLE_AUTOLOGIN
565 if (validpw(CC->usersupp.uid, password)) {
567 lgetuser(&CC->usersupp, CC->curr_user);
568 safestrncpy(CC->usersupp.password, password,
569 sizeof CC->usersupp.password);
570 lputuser(&CC->usersupp);
579 rec_log(CL_BADPW, CC->curr_user);
580 return pass_wrong_password;
585 void cmd_pass(char *buf)
590 extract(password, buf, 0);
591 a = CtdlTryPassword(password);
594 case pass_already_logged_in:
595 cprintf("%d Already logged in.\n", ERROR);
598 cprintf("%d You must send a name with USER first.\n",
601 case pass_wrong_password:
602 cprintf("%d Wrong password.\n", ERROR);
605 logged_in_response();
607 cprintf("%d Can't find user record!\n",
608 ERROR + INTERNAL_ERROR);
615 * Delete a user record *and* all of its related resources.
617 int purge_user(char pname[])
620 struct usersupp usbuf;
621 char lowercase_name[32];
623 struct CitContext *ccptr;
624 int user_is_logged_in = 0;
626 for (a = 0; a <= strlen(pname); ++a) {
627 lowercase_name[a] = tolower(pname[a]);
630 if (getuser(&usbuf, pname) != 0) {
631 lprintf(5, "Cannot purge user <%s> - not found\n", pname);
632 return (ERROR + NO_SUCH_USER);
634 /* Don't delete a user who is currently logged in. Instead, just
635 * set the access level to 0, and let the account get swept up
636 * during the next purge.
638 user_is_logged_in = 0;
639 begin_critical_section(S_SESSION_TABLE);
640 for (ccptr = ContextList; ccptr != NULL; ccptr = ccptr->next) {
641 if (ccptr->usersupp.usernum == usbuf.usernum) {
642 user_is_logged_in = 1;
645 end_critical_section(S_SESSION_TABLE);
646 if (user_is_logged_in == 1) {
647 lprintf(5, "User <%s> is logged in; not deleting.\n", pname);
652 lprintf(5, "Deleting user <%s>\n", pname);
654 /* Perform any purge functions registered by server extensions */
655 PerformUserHooks(usbuf.fullname, usbuf.usernum, EVT_PURGEUSER);
657 /* delete any existing user/room relationships */
658 cdb_delete(CDB_VISIT, &usbuf.usernum, sizeof(long));
660 /* delete the userlog entry */
661 cdb_delete(CDB_USERSUPP, lowercase_name, strlen(lowercase_name));
663 /* remove the user's bio file */
664 snprintf(filename, sizeof filename, "./bio/%ld", usbuf.usernum);
667 /* remove the user's picture */
668 snprintf(filename, sizeof filename, "./userpics/%ld.gif", usbuf.usernum);
676 * create_user() - back end processing to create a new user
678 * Set 'newusername' to the desired account name.
679 * Set 'become_user' to nonzero if this is self-service account creation and we want
680 * to actually log in as the user we just created, otherwise set it to 0.
682 int create_user(char *newusername, int become_user)
684 struct usersupp usbuf;
685 struct quickroom qrbuf;
686 struct passwd *p = NULL;
688 char mailboxname[ROOMNAMELEN];
691 strcpy(username, newusername);
694 #ifdef ENABLE_AUTOLOGIN
695 p = (struct passwd *) getpwnam(username);
698 extract_token(username, p->pw_gecos, 0, ',');
704 if (!getuser(&usbuf, username)) {
705 return (ERROR + ALREADY_EXISTS);
708 /* Go ahead and initialize a new user record */
709 memset(&usbuf, 0, sizeof(struct usersupp));
710 strcpy(usbuf.fullname, username);
711 strcpy(usbuf.password, "");
714 /* These are the default flags on new accounts */
715 usbuf.flags = US_LASTOLD | US_DISAPPEAR | US_PAGINATOR | US_FLOORS;
717 usbuf.timescalled = 0;
719 usbuf.axlevel = config.c_initax;
720 usbuf.USscreenwidth = 80;
721 usbuf.USscreenheight = 24;
722 usbuf.lastcall = time(NULL);
724 /* fetch a new user number */
725 usbuf.usernum = get_new_user_number();
727 /* The very first user created on the system will always be an Aide */
728 if (usbuf.usernum == 1L) {
732 /* add user to userlog */
736 * Give the user a private mailbox and a configuration room.
737 * Make the latter an invisible system room.
739 MailboxName(mailboxname, sizeof mailboxname, &usbuf, MAILROOM);
740 create_room(mailboxname, 5, "", 0, 1, 1);
742 MailboxName(mailboxname, sizeof mailboxname, &usbuf, USERCONFIGROOM);
743 create_room(mailboxname, 5, "", 0, 1, 1);
744 if (lgetroom(&qrbuf, USERCONFIGROOM) == 0) {
745 qrbuf.QRflags2 |= QR2_SYSTEM;
749 /* Everything below this line can be bypassed if administratively
750 creating a user, instead of doing self-service account creation
754 /* Now become the user we just created */
755 memcpy(&CC->usersupp, &usbuf, sizeof(struct usersupp));
756 strcpy(CC->curr_user, username);
759 /* Check to make sure we're still who we think we are */
760 if (getuser(&CC->usersupp, CC->curr_user)) {
761 return (ERROR + INTERNAL_ERROR);
764 rec_log(CL_NEWUSER, CC->curr_user);
774 * cmd_newu() - create a new user account and log in as that user
776 void cmd_newu(char *cmdbuf)
781 if (config.c_disable_newu) {
782 cprintf("%d Self-service user account creation "
783 "is disabled on this system.\n", ERROR);
788 cprintf("%d Already logged in.\n", ERROR);
792 cprintf("%d %s: Too many users are already online (maximum is %d)\n",
793 ERROR + MAX_SESSIONS_EXCEEDED,
794 config.c_nodename, config.c_maxsessions);
796 extract(username, cmdbuf, 0);
800 if (strlen(username) == 0) {
801 cprintf("%d You must supply a user name.\n", ERROR);
805 if ((!strcasecmp(username, "bbs")) ||
806 (!strcasecmp(username, "new")) ||
807 (!strcasecmp(username, "."))) {
808 cprintf("%d '%s' is an invalid login name.\n", ERROR, username);
812 a = create_user(username, 1);
816 logged_in_response();
817 } else if (a == ERROR + ALREADY_EXISTS) {
818 cprintf("%d '%s' already exists.\n",
819 ERROR + ALREADY_EXISTS, username);
821 } else if (a == ERROR + INTERNAL_ERROR) {
822 cprintf("%d Internal error - user record disappeared?\n",
823 ERROR + INTERNAL_ERROR);
826 cprintf("%d unknown error\n", ERROR);
828 rec_log(CL_NEWUSER, CC->curr_user);
836 void cmd_setp(char *new_pw)
838 if (CtdlAccessCheck(ac_logged_in)) {
842 if (CC->usersupp.uid != BBSUID) {
843 cprintf("%d Not allowed. Use the 'passwd' command.\n", ERROR);
847 if (strlen(new_pw) == 0) {
848 cprintf("%d Password unchanged.\n", CIT_OK);
851 lgetuser(&CC->usersupp, CC->curr_user);
852 strcpy(CC->usersupp.password, new_pw);
853 lputuser(&CC->usersupp);
854 cprintf("%d Password changed.\n", CIT_OK);
855 rec_log(CL_PWCHANGE, CC->curr_user);
856 PerformSessionHooks(EVT_SETPASS);
861 * cmd_creu() - administratively create a new user account (do not log in to it)
863 void cmd_creu(char *cmdbuf)
868 if (CtdlAccessCheck(ac_aide)) {
872 extract(username, cmdbuf, 0);
876 if (strlen(username) == 0) {
877 cprintf("%d You must supply a user name.\n", ERROR);
881 a = create_user(username, 0);
884 cprintf("%d ok\n", CIT_OK);
886 } else if (a == ERROR + ALREADY_EXISTS) {
887 cprintf("%d '%s' already exists.\n",
888 ERROR + ALREADY_EXISTS, username);
891 cprintf("%d An error occured creating the user account.\n", ERROR);
893 rec_log(CL_NEWUSER, username);
899 * get user parameters
904 if (CtdlAccessCheck(ac_logged_in))
907 getuser(&CC->usersupp, CC->curr_user);
908 cprintf("%d %d|%d|%d|\n",
910 CC->usersupp.USscreenwidth,
911 CC->usersupp.USscreenheight,
912 (CC->usersupp.flags & US_USER_SET)
917 * set user parameters
919 void cmd_setu(char *new_parms)
921 if (CtdlAccessCheck(ac_logged_in))
924 if (num_parms(new_parms) < 3) {
925 cprintf("%d Usage error.\n", ERROR);
928 lgetuser(&CC->usersupp, CC->curr_user);
929 CC->usersupp.USscreenwidth = extract_int(new_parms, 0);
930 CC->usersupp.USscreenheight = extract_int(new_parms, 1);
931 CC->usersupp.flags = CC->usersupp.flags & (~US_USER_SET);
932 CC->usersupp.flags = CC->usersupp.flags |
933 (extract_int(new_parms, 2) & US_USER_SET);
935 lputuser(&CC->usersupp);
936 cprintf("%d Ok\n", CIT_OK);
940 * set last read pointer
942 void cmd_slrp(char *new_ptr)
947 if (CtdlAccessCheck(ac_logged_in)) {
951 if (!strncasecmp(new_ptr, "highest", 7)) {
952 newlr = CC->quickroom.QRhighest;
954 newlr = atol(new_ptr);
957 lgetuser(&CC->usersupp, CC->curr_user);
959 CtdlGetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
960 vbuf.v_lastseen = newlr;
961 snprintf(vbuf.v_seen, sizeof vbuf.v_seen, "*:%ld", newlr);
962 CtdlSetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
964 lputuser(&CC->usersupp);
965 cprintf("%d %ld\n", CIT_OK, newlr);
969 void cmd_seen(char *argbuf) {
970 long target_msgnum = 0L;
971 int target_setting = 0;
973 if (CtdlAccessCheck(ac_logged_in)) {
977 if (num_parms(argbuf) != 2) {
978 cprintf("%d Invalid parameters\n", ERROR);
982 target_msgnum = extract_long(argbuf, 0);
983 target_setting = extract_int(argbuf, 1);
985 CtdlSetSeen(target_msgnum, target_setting);
986 cprintf("%d OK\n", CIT_OK);
990 void cmd_gtsn(char *argbuf) {
993 if (CtdlAccessCheck(ac_logged_in)) {
998 cprintf("%d %s\n", CIT_OK, buf);
1004 * INVT and KICK commands
1006 void cmd_invt_kick(char *iuser, int op)
1008 { /* 1 = invite, 0 = kick out */
1009 struct usersupp USscratch;
1014 * These commands are only allowed by aides, room aides,
1015 * and room namespace owners
1018 || (atol(CC->quickroom.QRname) == CC->usersupp.usernum) ) {
1019 /* access granted */
1022 cprintf("%d Higher access or room ownership required.\n",
1023 ERROR + HIGHER_ACCESS_REQUIRED);
1027 if (!strncasecmp(CC->quickroom.QRname, config.c_baseroom,
1029 cprintf("%d Can't add/remove users from this room.\n",
1034 if (lgetuser(&USscratch, iuser) != 0) {
1035 cprintf("%d No such user.\n", ERROR);
1038 CtdlGetRelationship(&vbuf, &USscratch, &CC->quickroom);
1041 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
1042 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
1045 vbuf.v_flags = vbuf.v_flags & ~V_ACCESS;
1046 vbuf.v_flags = vbuf.v_flags | V_FORGET | V_LOCKOUT;
1048 CtdlSetRelationship(&vbuf, &USscratch, &CC->quickroom);
1050 lputuser(&USscratch);
1052 /* post a message in Aide> saying what we just did */
1053 snprintf(bbb, sizeof bbb, "%s %s %s> by %s\n",
1055 ((op == 1) ? "invited to" : "kicked out of"),
1056 CC->quickroom.QRname,
1057 CC->usersupp.fullname);
1060 cprintf("%d %s %s %s.\n",
1062 ((op == 1) ? "invited to" : "kicked out of"),
1063 CC->quickroom.QRname);
1069 * Forget (Zap) the current room (API call)
1070 * Returns 0 on success
1072 int CtdlForgetThisRoom(void) {
1075 /* On some systems, Aides are not allowed to forget rooms */
1076 if (is_aide() && (config.c_aide_zap == 0)
1077 && ((CC->quickroom.QRflags & QR_MAILBOX) == 0) ) {
1081 lgetuser(&CC->usersupp, CC->curr_user);
1082 CtdlGetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
1084 vbuf.v_flags = vbuf.v_flags | V_FORGET;
1085 vbuf.v_flags = vbuf.v_flags & ~V_ACCESS;
1087 CtdlSetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
1088 lputuser(&CC->usersupp);
1090 /* Return to the Lobby, so we don't end up in an undefined room */
1091 usergoto(config.c_baseroom, 0, 0, NULL, NULL);
1098 * forget (Zap) the current room
1103 if (CtdlAccessCheck(ac_logged_in)) {
1107 if (CtdlForgetThisRoom() == 0) {
1108 cprintf("%d Ok\n", CIT_OK);
1111 cprintf("%d You may not forget this room.\n", ERROR);
1116 * Get Next Unregistered User
1120 struct cdbdata *cdbus;
1121 struct usersupp usbuf;
1123 if (CtdlAccessCheck(ac_aide)) {
1127 if ((CitControl.MMflags & MM_VALID) == 0) {
1128 cprintf("%d There are no unvalidated users.\n", CIT_OK);
1132 /* There are unvalidated users. Traverse the usersupp database,
1133 * and return the first user we find that needs validation.
1135 cdb_rewind(CDB_USERSUPP);
1136 while (cdbus = cdb_next_item(CDB_USERSUPP), cdbus != NULL) {
1137 memset(&usbuf, 0, sizeof(struct usersupp));
1138 memcpy(&usbuf, cdbus->ptr,
1139 ((cdbus->len > sizeof(struct usersupp)) ?
1140 sizeof(struct usersupp) : cdbus->len));
1142 if ((usbuf.flags & US_NEEDVALID)
1143 && (usbuf.axlevel > 0)) {
1144 cprintf("%d %s\n", MORE_DATA, usbuf.fullname);
1145 cdb_close_cursor(CDB_USERSUPP);
1150 /* If we get to this point, there are no more unvalidated users.
1151 * Therefore we clear the "users need validation" flag.
1154 begin_critical_section(S_CONTROL);
1156 CitControl.MMflags = CitControl.MMflags & (~MM_VALID);
1158 end_critical_section(S_CONTROL);
1159 cprintf("%d *** End of registration.\n", CIT_OK);
1168 void cmd_vali(char *v_args)
1172 struct usersupp userbuf;
1174 extract(user, v_args, 0);
1175 newax = extract_int(v_args, 1);
1177 if (CtdlAccessCheck(ac_aide)) {
1181 if (lgetuser(&userbuf, user) != 0) {
1182 cprintf("%d '%s' not found.\n", ERROR + NO_SUCH_USER, user);
1186 userbuf.axlevel = newax;
1187 userbuf.flags = (userbuf.flags & ~US_NEEDVALID);
1191 /* If the access level was set to zero, delete the user */
1193 if (purge_user(user) == 0) {
1194 cprintf("%d %s Deleted.\n", CIT_OK, userbuf.fullname);
1198 cprintf("%d User '%s' validated.\n", CIT_OK, userbuf.fullname);
1204 * Traverse the user file...
1206 void ForEachUser(void (*CallBack) (struct usersupp * EachUser, void *out_data),
1209 struct usersupp usbuf;
1210 struct cdbdata *cdbus;
1212 cdb_rewind(CDB_USERSUPP);
1214 while (cdbus = cdb_next_item(CDB_USERSUPP), cdbus != NULL) {
1215 memset(&usbuf, 0, sizeof(struct usersupp));
1216 memcpy(&usbuf, cdbus->ptr,
1217 ((cdbus->len > sizeof(struct usersupp)) ?
1218 sizeof(struct usersupp) : cdbus->len));
1220 (*CallBack) (&usbuf, in_data);
1226 * List one user (this works with cmd_list)
1228 void ListThisUser(struct usersupp *usbuf, void *data)
1230 if (usbuf->axlevel > 0) {
1231 if ((CC->usersupp.axlevel >= 6)
1232 || ((usbuf->flags & US_UNLISTED) == 0)
1233 || ((CC->internal_pgm))) {
1234 cprintf("%s|%d|%ld|%ld|%ld|%ld|",
1238 (long)usbuf->lastcall,
1241 if (CC->usersupp.axlevel >= 6)
1242 cprintf("%s", usbuf->password);
1253 cprintf("%d \n", LISTING_FOLLOWS);
1254 ForEachUser(ListThisUser, NULL);
1262 * assorted info we need to check at login
1270 if (CtdlAccessCheck(ac_logged_in)) {
1274 getuser(&CC->usersupp, CC->curr_user); /* no lock is needed here */
1275 if ((REGISCALL != 0) && ((CC->usersupp.flags & US_REGIS) == 0))
1278 if (CC->usersupp.axlevel >= 6) {
1280 if (CitControl.MMflags & MM_VALID)
1284 /* check for mail */
1285 mail = InitialMailCheck();
1287 cprintf("%d %d|%d|%d\n", CIT_OK, mail, regis, vali);
1292 * check to see if a user exists
1294 void cmd_qusr(char *who)
1296 struct usersupp usbuf;
1298 if (getuser(&usbuf, who) == 0) {
1299 cprintf("%d %s\n", CIT_OK, usbuf.fullname);
1301 cprintf("%d No such user.\n", ERROR + NO_SUCH_USER);
1307 * Administrative Get User Parameters
1309 void cmd_agup(char *cmdbuf)
1311 struct usersupp usbuf;
1312 char requested_user[SIZ];
1314 if (CtdlAccessCheck(ac_aide)) {
1318 extract(requested_user, cmdbuf, 0);
1319 if (getuser(&usbuf, requested_user) != 0) {
1320 cprintf("%d No such user.\n", ERROR + NO_SUCH_USER);
1323 cprintf("%d %s|%s|%u|%ld|%ld|%d|%ld|%ld|%d\n",
1330 (int) usbuf.axlevel,
1332 (long)usbuf.lastcall,
1339 * Administrative Set User Parameters
1341 void cmd_asup(char *cmdbuf)
1343 struct usersupp usbuf;
1344 char requested_user[SIZ];
1349 if (CtdlAccessCheck(ac_aide))
1352 extract(requested_user, cmdbuf, 0);
1353 if (lgetuser(&usbuf, requested_user) != 0) {
1354 cprintf("%d No such user.\n", ERROR + NO_SUCH_USER);
1357 np = num_parms(cmdbuf);
1359 extract(usbuf.password, cmdbuf, 1);
1361 usbuf.flags = extract_int(cmdbuf, 2);
1363 usbuf.timescalled = extract_int(cmdbuf, 3);
1365 usbuf.posted = extract_int(cmdbuf, 4);
1367 newax = extract_int(cmdbuf, 5);
1368 if ((newax >= 0) && (newax <= 6)) {
1369 usbuf.axlevel = extract_int(cmdbuf, 5);
1373 usbuf.lastcall = extract_long(cmdbuf, 7);
1376 usbuf.USuserpurge = extract_int(cmdbuf, 8);
1379 if (usbuf.axlevel == 0) {
1380 if (purge_user(requested_user) == 0) {
1384 cprintf("%d Ok", CIT_OK);
1386 cprintf(" (%s deleted)", requested_user);
1393 * Check to see if the user who we just sent mail to is logged in. If yes,
1394 * bump the 'new mail' counter for their session. That enables them to
1395 * receive a new mail notification without having to hit the database.
1397 void BumpNewMailCounter(long which_user) {
1398 struct CitContext *ptr;
1400 begin_critical_section(S_SESSION_TABLE);
1402 for (ptr = ContextList; ptr != NULL; ptr = ptr->next) {
1403 if (ptr->usersupp.usernum == which_user) {
1408 end_critical_section(S_SESSION_TABLE);
1413 * Count the number of new mail messages the user has
1417 int num_newmsgs = 0;
1419 num_newmsgs = CC->newmail;
1422 return (num_newmsgs);
1427 * Count the number of new mail messages the user has
1429 int InitialMailCheck()
1431 int num_newmsgs = 0;
1433 char mailboxname[ROOMNAMELEN];
1434 struct quickroom mailbox;
1436 struct cdbdata *cdbfr;
1437 long *msglist = NULL;
1440 MailboxName(mailboxname, sizeof mailboxname, &CC->usersupp, MAILROOM);
1441 if (getroom(&mailbox, mailboxname) != 0)
1443 CtdlGetRelationship(&vbuf, &CC->usersupp, &mailbox);
1445 cdbfr = cdb_fetch(CDB_MSGLISTS, &mailbox.QRnumber, sizeof(long));
1447 if (cdbfr != NULL) {
1448 msglist = mallok(cdbfr->len);
1449 memcpy(msglist, cdbfr->ptr, cdbfr->len);
1450 num_msgs = cdbfr->len / sizeof(long);
1454 for (a = 0; a < num_msgs; ++a) {
1455 if (msglist[a] > 0L) {
1456 if (msglist[a] > vbuf.v_lastseen) {
1461 if (msglist != NULL)
1464 return (num_newmsgs);
1470 * Set the preferred view for the current user/room combination
1472 void cmd_view(char *cmdbuf) {
1476 if (CtdlAccessCheck(ac_logged_in)) {
1480 requested_view = extract_int(cmdbuf, 0);
1482 CtdlGetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
1483 vbuf.v_view = requested_view;
1484 CtdlSetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
1486 cprintf("%d ok\n", CIT_OK);