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));
84 if (usbuf->version < 573) {
85 CC->usersupp.moderation_filter = config.c_default_filter;
92 * lgetuser() - same as getuser() but locks the record
94 int lgetuser(struct usersupp *usbuf, char *name)
98 retcode = getuser(usbuf, name);
100 begin_critical_section(S_USERSUPP);
107 * putuser() - write user buffer into the correct place on disk
109 void putuser(struct usersupp *usbuf)
111 char lowercase_name[32];
114 for (a = 0; a <= strlen(usbuf->fullname); ++a) {
115 if (a < sizeof(lowercase_name))
116 lowercase_name[a] = tolower(usbuf->fullname[a]);
118 lowercase_name[sizeof(lowercase_name) - 1] = 0;
120 usbuf->version = REV_LEVEL;
121 cdb_store(CDB_USERSUPP,
122 lowercase_name, strlen(lowercase_name),
123 usbuf, sizeof(struct usersupp));
129 * lputuser() - same as putuser() but locks the record
131 void lputuser(struct usersupp *usbuf)
134 end_critical_section(S_USERSUPP);
138 * Index-generating function used by Ctdl[Get|Set]Relationship
140 int GenerateRelationshipIndex(char *IndexBuf,
152 TheIndex.iRoomID = RoomID;
153 TheIndex.iRoomGen = RoomGen;
154 TheIndex.iUserID = UserID;
156 memcpy(IndexBuf, &TheIndex, sizeof(TheIndex));
157 return (sizeof(TheIndex));
163 * Back end for CtdlSetRelationship()
165 void put_visit(struct visit *newvisit)
170 /* Generate an index */
171 IndexLen = GenerateRelationshipIndex(IndexBuf,
174 newvisit->v_usernum);
176 /* Store the record */
177 cdb_store(CDB_VISIT, IndexBuf, IndexLen,
178 newvisit, sizeof(struct visit)
186 * Define a relationship between a user and a room
188 void CtdlSetRelationship(struct visit *newvisit,
189 struct usersupp *rel_user,
190 struct quickroom *rel_room)
194 /* We don't use these in Citadel because they're implicit by the
195 * index, but they must be present if the database is exported.
197 newvisit->v_roomnum = rel_room->QRnumber;
198 newvisit->v_roomgen = rel_room->QRgen;
199 newvisit->v_usernum = rel_user->usernum;
205 * Locate a relationship between a user and a room
207 void CtdlGetRelationship(struct visit *vbuf,
208 struct usersupp *rel_user,
209 struct quickroom *rel_room)
214 struct cdbdata *cdbvisit;
216 /* Generate an index */
217 IndexLen = GenerateRelationshipIndex(IndexBuf,
222 /* Clear out the buffer */
223 memset(vbuf, 0, sizeof(struct visit));
225 cdbvisit = cdb_fetch(CDB_VISIT, IndexBuf, IndexLen);
226 if (cdbvisit != NULL) {
227 memcpy(vbuf, cdbvisit->ptr,
228 ((cdbvisit->len > sizeof(struct visit)) ?
229 sizeof(struct visit) : cdbvisit->len));
233 /* If this is the first time the user has seen this room,
234 * set the view to be the default for the room.
236 vbuf->v_view = rel_room->QRdefaultview;
239 /* Set v_seen if necessary */
240 if (vbuf->v_seen[0] == 0) {
241 snprintf(vbuf->v_seen, sizeof vbuf->v_seen, "*:%ld", vbuf->v_lastseen);
246 void MailboxName(char *buf, size_t n, const struct usersupp *who, const char *prefix)
248 snprintf(buf, n, "%010ld.%s", who->usernum, prefix);
253 * Is the user currently logged in an Aide?
257 if (CC->usersupp.axlevel >= 6)
265 * Is the user currently logged in an Aide *or* the room aide for this room?
267 int is_room_aide(void)
270 if (!CC->logged_in) {
274 if ((CC->usersupp.axlevel >= 6)
275 || (CC->quickroom.QRroomaide == CC->usersupp.usernum)) {
283 * getuserbynumber() - get user by number
284 * returns 0 if user was found
286 * WARNING: don't use this function unless you absolutely have to. It does
287 * a sequential search and therefore is computationally expensive.
289 int getuserbynumber(struct usersupp *usbuf, long int number)
291 struct cdbdata *cdbus;
293 cdb_rewind(CDB_USERSUPP);
295 while (cdbus = cdb_next_item(CDB_USERSUPP), cdbus != NULL) {
296 memset(usbuf, 0, sizeof(struct usersupp));
297 memcpy(usbuf, cdbus->ptr,
298 ((cdbus->len > sizeof(struct usersupp)) ?
299 sizeof(struct usersupp) : cdbus->len));
301 if (usbuf->usernum == number) {
302 cdb_close_cursor(CDB_USERSUPP);
311 * Back end for cmd_user() and its ilk
313 int CtdlLoginExistingUser(char *trythisname)
321 if (trythisname == NULL) return login_not_found;
322 safestrncpy(username, trythisname, sizeof username);
325 if ((CC->logged_in)) {
326 return login_already_logged_in;
328 found_user = getuser(&CC->usersupp, username);
329 if (found_user != 0) {
330 p = (struct passwd *) getpwnam(username);
332 strcpy(autoname, p->pw_gecos);
333 for (a = 0; a < strlen(autoname); ++a)
334 if (autoname[a] == ',')
336 found_user = getuser(&CC->usersupp, autoname);
339 if (found_user == 0) {
340 if (((CC->nologin)) && (CC->usersupp.axlevel < 6)) {
341 return login_too_many_users;
343 strcpy(CC->curr_user, CC->usersupp.fullname);
347 return login_not_found;
355 void cmd_user(char *cmdbuf)
360 extract(username, cmdbuf, 0);
364 a = CtdlLoginExistingUser(username);
366 case login_already_logged_in:
367 cprintf("%d Already logged in.\n", ERROR);
369 case login_too_many_users:
371 "Too many users are already online "
373 ERROR + MAX_SESSIONS_EXCEEDED,
374 config.c_nodename, config.c_maxsessions);
377 cprintf("%d Password required for %s\n",
378 MORE_DATA, CC->curr_user);
380 case login_not_found:
381 cprintf("%d %s not found.\n", ERROR, username);
383 cprintf("%d Internal error\n", ERROR);
390 * session startup code which is common to both cmd_pass() and cmd_newu()
392 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);
409 /* Run any startup routines registered by loadable modules */
410 PerformSessionHooks(EVT_LOGIN);
412 /* Create any personal rooms required by the system */
413 create_room(SENTITEMS, 4, "", 0, 1, 0);
415 /* Enter the lobby */
416 usergoto(BASEROOM, 0, NULL, NULL);
418 /* Record this login in the Citadel log */
419 rec_log(CL_LOGIN, CC->curr_user);
423 void logged_in_response(void)
425 cprintf("%d %s|%d|%ld|%ld|%u|%ld|%ld\n",
426 CIT_OK, CC->usersupp.fullname, CC->usersupp.axlevel,
427 CC->usersupp.timescalled, CC->usersupp.posted,
428 CC->usersupp.flags, CC->usersupp.usernum,
429 CC->usersupp.lastcall);
435 * misc things to be taken care of when a user is logged out
437 void logout(struct CitContext *who)
442 * If there is a download in progress, abort it.
444 if (who->download_fp != NULL) {
445 fclose(who->download_fp);
446 who->download_fp = NULL;
450 * If there is an upload in progress, abort it.
452 if (who->upload_fp != NULL) {
457 * If we were talking to a network node, we're not anymore...
459 if (strlen(who->net_node) > 0) {
460 network_talking_to(who->net_node, NTT_REMOVE);
464 * Yes, we really need to free EVERY LAST BYTE we allocated.
466 if (who->cs_inet_email != NULL) {
467 phree(who->cs_inet_email);
468 who->cs_inet_email = NULL;
471 /* Do modular stuff... */
472 PerformSessionHooks(EVT_LOGOUT);
477 * an alternate version of validpw() which executes `chkpwd' instead of
478 * verifying the password directly
480 static int validpw(uid_t uid, const char *pass)
483 int status, pipev[2];
487 lprintf(1, "pipe failed (%s): denying autologin access for "
488 "uid %ld\n", strerror(errno), (long)uid);
491 switch (pid = fork()) {
493 lprintf(1, "fork failed (%s): denying autologin access for "
494 "uid %ld\n", strerror(errno), (long)uid);
501 if (dup2(pipev[0], 0) == -1) {
507 execl(BBSDIR "/chkpwd", BBSDIR "/chkpwd", NULL);
508 perror(BBSDIR "/chkpwd");
514 snprintf(buf, sizeof buf, "%lu\n", (unsigned long) uid));
515 write(pipev[1], pass, strlen(pass));
516 write(pipev[1], "\n", 1);
519 while (waitpid(pid, &status, 0) == -1)
520 if (errno != EINTR) {
521 lprintf(1, "waitpid failed (%s): denying autologin "
522 "access for uid %ld\n",
523 strerror(errno), (long)uid);
526 if (WIFEXITED(status) && !WEXITSTATUS(status))
540 int CtdlTryPassword(char *password)
544 if ((CC->logged_in)) {
545 lprintf(5, "CtdlTryPassword: already logged in\n");
546 return pass_already_logged_in;
548 if (!strcmp(CC->curr_user, NLI)) {
549 lprintf(5, "CtdlTryPassword: no user selected\n");
552 if (getuser(&CC->usersupp, CC->curr_user)) {
553 lprintf(5, "CtdlTryPassword: internal error\n");
554 return pass_internal_error;
556 if (password == NULL) {
557 lprintf(5, "CtdlTryPassword: NULL password string supplied\n");
558 return pass_wrong_password;
561 if (CC->usersupp.uid == BBSUID) {
563 strproc(CC->usersupp.password);
564 code = strcasecmp(CC->usersupp.password, password);
566 #ifdef ENABLE_AUTOLOGIN
568 if (validpw(CC->usersupp.uid, password)) {
570 lgetuser(&CC->usersupp, CC->curr_user);
571 safestrncpy(CC->usersupp.password, password,
572 sizeof CC->usersupp.password);
573 lputuser(&CC->usersupp);
582 rec_log(CL_BADPW, CC->curr_user);
583 return pass_wrong_password;
588 void cmd_pass(char *buf)
593 extract(password, buf, 0);
594 a = CtdlTryPassword(password);
597 case pass_already_logged_in:
598 cprintf("%d Already logged in.\n", ERROR);
601 cprintf("%d You must send a name with USER first.\n",
604 case pass_wrong_password:
605 cprintf("%d Wrong password.\n", ERROR);
608 logged_in_response();
610 cprintf("%d Can't find user record!\n",
611 ERROR + INTERNAL_ERROR);
618 * Delete a user record *and* all of its related resources.
620 int purge_user(char pname[])
623 struct usersupp usbuf;
624 char lowercase_name[32];
626 struct CitContext *ccptr;
627 int user_is_logged_in = 0;
629 for (a = 0; a <= strlen(pname); ++a) {
630 lowercase_name[a] = tolower(pname[a]);
633 if (getuser(&usbuf, pname) != 0) {
634 lprintf(5, "Cannot purge user <%s> - not found\n", pname);
635 return (ERROR + NO_SUCH_USER);
637 /* Don't delete a user who is currently logged in. Instead, just
638 * set the access level to 0, and let the account get swept up
639 * during the next purge.
641 user_is_logged_in = 0;
642 begin_critical_section(S_SESSION_TABLE);
643 for (ccptr = ContextList; ccptr != NULL; ccptr = ccptr->next) {
644 if (ccptr->usersupp.usernum == usbuf.usernum) {
645 user_is_logged_in = 1;
648 end_critical_section(S_SESSION_TABLE);
649 if (user_is_logged_in == 1) {
650 lprintf(5, "User <%s> is logged in; not deleting.\n", pname);
655 lprintf(5, "Deleting user <%s>\n", pname);
657 /* Perform any purge functions registered by server extensions */
658 PerformUserHooks(usbuf.fullname, usbuf.usernum, EVT_PURGEUSER);
660 /* delete any existing user/room relationships */
661 cdb_delete(CDB_VISIT, &usbuf.usernum, sizeof(long));
663 /* delete the userlog entry */
664 cdb_delete(CDB_USERSUPP, lowercase_name, strlen(lowercase_name));
666 /* remove the user's bio file */
667 snprintf(filename, sizeof filename, "./bio/%ld", usbuf.usernum);
670 /* remove the user's picture */
671 snprintf(filename, sizeof filename, "./userpics/%ld.gif", usbuf.usernum);
679 * create_user() - back end processing to create a new user
681 * Set 'newusername' to the desired account name.
682 * Set 'become_user' to nonzero if this is self-service account creation and we want
683 * to actually log in as the user we just created, otherwise set it to 0.
685 int create_user(char *newusername, int become_user)
687 struct usersupp usbuf;
688 struct passwd *p = NULL;
690 char mailboxname[ROOMNAMELEN];
693 strcpy(username, newusername);
696 #ifdef ENABLE_AUTOLOGIN
697 p = (struct passwd *) getpwnam(username);
700 extract_token(username, p->pw_gecos, 0, ',');
706 if (!getuser(&usbuf, username)) {
707 return (ERROR + ALREADY_EXISTS);
710 /* Go ahead and initialize a new user record */
711 memset(&usbuf, 0, sizeof(struct usersupp));
712 strcpy(usbuf.fullname, username);
713 strcpy(usbuf.password, "");
716 /* These are the default flags on new accounts */
717 usbuf.flags = US_LASTOLD | US_DISAPPEAR | US_PAGINATOR | US_FLOORS;
719 usbuf.timescalled = 0;
721 usbuf.axlevel = config.c_initax;
722 usbuf.USscreenwidth = 80;
723 usbuf.USscreenheight = 24;
724 usbuf.lastcall = time(NULL);
725 usbuf.moderation_filter = config.c_default_filter;
727 /* fetch a new user number */
728 usbuf.usernum = get_new_user_number();
730 /* The very first user created on the system will always be an Aide */
731 if (usbuf.usernum == 1L) {
735 /* add user to userlog */
738 /* give the user a private mailbox and a configuration room */
739 MailboxName(mailboxname, sizeof mailboxname, &usbuf, MAILROOM);
740 create_room(mailboxname, 5, "", 0, 1, 1);
741 MailboxName(mailboxname, sizeof mailboxname, &usbuf, USERCONFIGROOM);
742 create_room(mailboxname, 5, "", 0, 1, 1);
744 /* Everything below this line can be bypassed if administratively
745 creating a user, instead of doing self-service account creation
749 /* Now become the user we just created */
750 memcpy(&CC->usersupp, &usbuf, sizeof(struct usersupp));
751 strcpy(CC->curr_user, username);
754 /* Check to make sure we're still who we think we are */
755 if (getuser(&CC->usersupp, CC->curr_user)) {
756 return (ERROR + INTERNAL_ERROR);
759 rec_log(CL_NEWUSER, CC->curr_user);
769 * cmd_newu() - create a new user account and log in as that user
771 void cmd_newu(char *cmdbuf)
776 if (config.c_disable_newu) {
777 cprintf("%d Self-service user account creation "
778 "is disabled on this system.\n", ERROR);
783 cprintf("%d Already logged in.\n", ERROR);
787 cprintf("%d %s: Too many users are already online (maximum is %d)\n",
788 ERROR + MAX_SESSIONS_EXCEEDED,
789 config.c_nodename, config.c_maxsessions);
791 extract(username, cmdbuf, 0);
795 if (strlen(username) == 0) {
796 cprintf("%d You must supply a user name.\n", ERROR);
800 if ((!strcasecmp(username, "bbs")) ||
801 (!strcasecmp(username, "new")) ||
802 (!strcasecmp(username, "."))) {
803 cprintf("%d '%s' is an invalid login name.\n", ERROR, username);
807 a = create_user(username, 1);
811 logged_in_response();
812 } else if (a == ERROR + ALREADY_EXISTS) {
813 cprintf("%d '%s' already exists.\n",
814 ERROR + ALREADY_EXISTS, username);
816 } else if (a == ERROR + INTERNAL_ERROR) {
817 cprintf("%d Internal error - user record disappeared?\n",
818 ERROR + INTERNAL_ERROR);
821 cprintf("%d unknown error\n", ERROR);
823 rec_log(CL_NEWUSER, CC->curr_user);
831 void cmd_setp(char *new_pw)
833 if (CtdlAccessCheck(ac_logged_in)) {
837 if (CC->usersupp.uid != BBSUID) {
838 cprintf("%d Not allowed. Use the 'passwd' command.\n", ERROR);
842 if (strlen(new_pw) == 0) {
843 cprintf("%d Password unchanged.\n", CIT_OK);
846 lgetuser(&CC->usersupp, CC->curr_user);
847 strcpy(CC->usersupp.password, new_pw);
848 lputuser(&CC->usersupp);
849 cprintf("%d Password changed.\n", CIT_OK);
850 rec_log(CL_PWCHANGE, CC->curr_user);
851 PerformSessionHooks(EVT_SETPASS);
856 * cmd_creu() - administratively create a new user account (do not log in to it)
858 void cmd_creu(char *cmdbuf)
863 if (CtdlAccessCheck(ac_aide)) {
867 extract(username, cmdbuf, 0);
871 if (strlen(username) == 0) {
872 cprintf("%d You must supply a user name.\n", ERROR);
876 a = create_user(username, 0);
879 cprintf("%d ok\n", CIT_OK);
881 } else if (a == ERROR + ALREADY_EXISTS) {
882 cprintf("%d '%s' already exists.\n",
883 ERROR + ALREADY_EXISTS, username);
886 cprintf("%d An error occured creating the user account.\n", ERROR);
888 rec_log(CL_NEWUSER, username);
894 * get user parameters
899 if (CtdlAccessCheck(ac_logged_in))
902 getuser(&CC->usersupp, CC->curr_user);
903 cprintf("%d %d|%d|%d|%d\n",
905 CC->usersupp.USscreenwidth,
906 CC->usersupp.USscreenheight,
907 (CC->usersupp.flags & US_USER_SET),
908 CC->usersupp.moderation_filter
913 * set user parameters
915 void cmd_setu(char *new_parms)
919 if (CtdlAccessCheck(ac_logged_in))
922 if (num_parms(new_parms) < 3) {
923 cprintf("%d Usage error.\n", ERROR);
926 lgetuser(&CC->usersupp, CC->curr_user);
927 CC->usersupp.USscreenwidth = extract_int(new_parms, 0);
928 CC->usersupp.USscreenheight = extract_int(new_parms, 1);
929 CC->usersupp.flags = CC->usersupp.flags & (~US_USER_SET);
930 CC->usersupp.flags = CC->usersupp.flags |
931 (extract_int(new_parms, 2) & US_USER_SET);
933 if (num_parms(new_parms) >= 4) {
934 new_mod = extract_int(new_parms, 3);
935 lprintf(9, "new_mod extracted to %d\n", new_mod);
937 /* Aides cannot set the filter level lower than -100 */
938 if (new_mod < (-100))
941 /* Normal users cannot set the filter level lower than -63 */
942 if ((new_mod < (-63)) && (CC->usersupp.axlevel < 6))
945 /* Nobody can set the filter level higher than +63 */
949 CC->usersupp.moderation_filter = new_mod;
950 lprintf(9, "new_mod processed to %d\n", new_mod);
952 lputuser(&CC->usersupp);
953 cprintf("%d Ok\n", CIT_OK);
957 * set last read pointer
959 void cmd_slrp(char *new_ptr)
964 if (CtdlAccessCheck(ac_logged_in)) {
968 if (!strncasecmp(new_ptr, "highest", 7)) {
969 newlr = CC->quickroom.QRhighest;
971 newlr = atol(new_ptr);
974 lgetuser(&CC->usersupp, CC->curr_user);
976 CtdlGetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
977 vbuf.v_lastseen = newlr;
978 snprintf(vbuf.v_seen, sizeof vbuf.v_seen, "*:%ld", newlr);
979 CtdlSetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
981 lputuser(&CC->usersupp);
982 cprintf("%d %ld\n", CIT_OK, newlr);
986 void cmd_seen(char *argbuf) {
987 long target_msgnum = 0L;
988 int target_setting = 0;
990 if (CtdlAccessCheck(ac_logged_in)) {
994 if (num_parms(argbuf) != 2) {
995 cprintf("%d Invalid parameters\n", ERROR);
999 target_msgnum = extract_long(argbuf, 0);
1000 target_setting = extract_int(argbuf, 1);
1002 CtdlSetSeen(target_msgnum, target_setting);
1003 cprintf("%d OK\n", CIT_OK);
1008 * INVT and KICK commands
1010 void cmd_invt_kick(char *iuser, int op)
1012 { /* 1 = invite, 0 = kick out */
1013 struct usersupp USscratch;
1018 * These commands are only allowed by aides, room aides,
1019 * and room namespace owners
1022 || (atol(CC->quickroom.QRname) == CC->usersupp.usernum) ) {
1023 /* access granted */
1027 cprintf("%d Higher access or room ownership required.\n",
1028 ERROR + HIGHER_ACCESS_REQUIRED);
1032 if (lgetuser(&USscratch, iuser) != 0) {
1033 cprintf("%d No such user.\n", ERROR);
1036 CtdlGetRelationship(&vbuf, &USscratch, &CC->quickroom);
1039 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
1040 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
1043 vbuf.v_flags = vbuf.v_flags & ~V_ACCESS;
1044 vbuf.v_flags = vbuf.v_flags | V_FORGET | V_LOCKOUT;
1046 CtdlSetRelationship(&vbuf, &USscratch, &CC->quickroom);
1048 lputuser(&USscratch);
1050 /* post a message in Aide> saying what we just did */
1051 snprintf(bbb, sizeof bbb, "%s %s %s> by %s\n",
1053 ((op == 1) ? "invited to" : "kicked out of"),
1054 CC->quickroom.QRname,
1055 CC->usersupp.fullname);
1058 cprintf("%d %s %s %s.\n",
1060 ((op == 1) ? "invited to" : "kicked out of"),
1061 CC->quickroom.QRname);
1067 * Forget (Zap) the current room (API call)
1068 * Returns 0 on success
1070 int CtdlForgetThisRoom(void) {
1073 /* On some systems, Aides are not allowed to forget rooms */
1074 if (is_aide() && (config.c_aide_zap == 0)
1075 && ((CC->quickroom.QRflags & QR_MAILBOX) == 0) ) {
1079 lgetuser(&CC->usersupp, CC->curr_user);
1080 CtdlGetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
1082 vbuf.v_flags = vbuf.v_flags | V_FORGET;
1083 vbuf.v_flags = vbuf.v_flags & ~V_ACCESS;
1085 CtdlSetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
1086 lputuser(&CC->usersupp);
1088 /* Return to the Lobby, so we don't end up in an undefined room */
1089 usergoto(BASEROOM, 0, NULL, NULL);
1096 * forget (Zap) the current room
1101 if (CtdlAccessCheck(ac_logged_in)) {
1105 if (CtdlForgetThisRoom() == 0) {
1106 cprintf("%d Ok\n", CIT_OK);
1109 cprintf("%d You may not forget this room.\n", ERROR);
1114 * Get Next Unregistered User
1118 struct cdbdata *cdbus;
1119 struct usersupp usbuf;
1121 if (CtdlAccessCheck(ac_aide)) {
1125 if ((CitControl.MMflags & MM_VALID) == 0) {
1126 cprintf("%d There are no unvalidated users.\n", CIT_OK);
1130 /* There are unvalidated users. Traverse the usersupp database,
1131 * and return the first user we find that needs validation.
1133 cdb_rewind(CDB_USERSUPP);
1134 while (cdbus = cdb_next_item(CDB_USERSUPP), cdbus != NULL) {
1135 memset(&usbuf, 0, sizeof(struct usersupp));
1136 memcpy(&usbuf, cdbus->ptr,
1137 ((cdbus->len > sizeof(struct usersupp)) ?
1138 sizeof(struct usersupp) : cdbus->len));
1140 if ((usbuf.flags & US_NEEDVALID)
1141 && (usbuf.axlevel > 0)) {
1142 cprintf("%d %s\n", MORE_DATA, usbuf.fullname);
1143 cdb_close_cursor(CDB_USERSUPP);
1148 /* If we get to this point, there are no more unvalidated users.
1149 * Therefore we clear the "users need validation" flag.
1152 begin_critical_section(S_CONTROL);
1154 CitControl.MMflags = CitControl.MMflags & (~MM_VALID);
1156 end_critical_section(S_CONTROL);
1157 cprintf("%d *** End of registration.\n", CIT_OK);
1166 void cmd_vali(char *v_args)
1170 struct usersupp userbuf;
1172 extract(user, v_args, 0);
1173 newax = extract_int(v_args, 1);
1175 if (CtdlAccessCheck(ac_aide)) {
1179 if (lgetuser(&userbuf, user) != 0) {
1180 cprintf("%d '%s' not found.\n", ERROR + NO_SUCH_USER, user);
1184 userbuf.axlevel = newax;
1185 userbuf.flags = (userbuf.flags & ~US_NEEDVALID);
1189 /* If the access level was set to zero, delete the user */
1191 if (purge_user(user) == 0) {
1192 cprintf("%d %s Deleted.\n", CIT_OK, userbuf.fullname);
1196 cprintf("%d User '%s' validated.\n", CIT_OK, userbuf.fullname);
1202 * Traverse the user file...
1204 void ForEachUser(void (*CallBack) (struct usersupp * EachUser, void *out_data),
1207 struct usersupp usbuf;
1208 struct cdbdata *cdbus;
1210 cdb_rewind(CDB_USERSUPP);
1212 while (cdbus = cdb_next_item(CDB_USERSUPP), cdbus != NULL) {
1213 memset(&usbuf, 0, sizeof(struct usersupp));
1214 memcpy(&usbuf, cdbus->ptr,
1215 ((cdbus->len > sizeof(struct usersupp)) ?
1216 sizeof(struct usersupp) : cdbus->len));
1218 (*CallBack) (&usbuf, in_data);
1224 * List one user (this works with cmd_list)
1226 void ListThisUser(struct usersupp *usbuf, void *data)
1228 if (usbuf->axlevel > 0) {
1229 if ((CC->usersupp.axlevel >= 6)
1230 || ((usbuf->flags & US_UNLISTED) == 0)
1231 || ((CC->internal_pgm))) {
1232 cprintf("%s|%d|%ld|%ld|%ld|%ld|",
1236 (long)usbuf->lastcall,
1239 if (CC->usersupp.axlevel >= 6)
1240 cprintf("%s", usbuf->password);
1251 cprintf("%d \n", LISTING_FOLLOWS);
1252 ForEachUser(ListThisUser, NULL);
1260 * assorted info we need to check at login
1268 if (CtdlAccessCheck(ac_logged_in)) {
1272 getuser(&CC->usersupp, CC->curr_user); /* no lock is needed here */
1273 if ((REGISCALL != 0) && ((CC->usersupp.flags & US_REGIS) == 0))
1276 if (CC->usersupp.axlevel >= 6) {
1278 if (CitControl.MMflags & MM_VALID)
1282 /* check for mail */
1283 mail = NewMailCount();
1285 cprintf("%d %d|%d|%d\n", CIT_OK, mail, regis, vali);
1290 * check to see if a user exists
1292 void cmd_qusr(char *who)
1294 struct usersupp usbuf;
1296 if (getuser(&usbuf, who) == 0) {
1297 cprintf("%d %s\n", CIT_OK, usbuf.fullname);
1299 cprintf("%d No such user.\n", ERROR + NO_SUCH_USER);
1305 * Administrative Get User Parameters
1307 void cmd_agup(char *cmdbuf)
1309 struct usersupp usbuf;
1310 char requested_user[SIZ];
1312 if (CtdlAccessCheck(ac_aide)) {
1316 extract(requested_user, cmdbuf, 0);
1317 if (getuser(&usbuf, requested_user) != 0) {
1318 cprintf("%d No such user.\n", ERROR + NO_SUCH_USER);
1321 cprintf("%d %s|%s|%u|%ld|%ld|%d|%ld|%ld|%d\n",
1328 (int) usbuf.axlevel,
1330 (long)usbuf.lastcall,
1337 * Administrative Set User Parameters
1339 void cmd_asup(char *cmdbuf)
1341 struct usersupp usbuf;
1342 char requested_user[SIZ];
1347 if (CtdlAccessCheck(ac_aide))
1350 extract(requested_user, cmdbuf, 0);
1351 if (lgetuser(&usbuf, requested_user) != 0) {
1352 cprintf("%d No such user.\n", ERROR + NO_SUCH_USER);
1355 np = num_parms(cmdbuf);
1357 extract(usbuf.password, cmdbuf, 1);
1359 usbuf.flags = extract_int(cmdbuf, 2);
1361 usbuf.timescalled = extract_int(cmdbuf, 3);
1363 usbuf.posted = extract_int(cmdbuf, 4);
1365 newax = extract_int(cmdbuf, 5);
1366 if ((newax >= 0) && (newax <= 6)) {
1367 usbuf.axlevel = extract_int(cmdbuf, 5);
1371 usbuf.lastcall = extract_long(cmdbuf, 7);
1374 usbuf.USuserpurge = extract_int(cmdbuf, 8);
1377 if (usbuf.axlevel == 0) {
1378 if (purge_user(requested_user) == 0) {
1382 cprintf("%d Ok", CIT_OK);
1384 cprintf(" (%s deleted)", requested_user);
1390 * Count the number of new mail messages the user has
1394 int num_newmsgs = 0;
1396 char mailboxname[ROOMNAMELEN];
1397 struct quickroom mailbox;
1399 struct cdbdata *cdbfr;
1400 long *msglist = NULL;
1403 MailboxName(mailboxname, sizeof mailboxname, &CC->usersupp, MAILROOM);
1404 if (getroom(&mailbox, mailboxname) != 0)
1406 CtdlGetRelationship(&vbuf, &CC->usersupp, &mailbox);
1408 cdbfr = cdb_fetch(CDB_MSGLISTS, &mailbox.QRnumber, sizeof(long));
1410 if (cdbfr != NULL) {
1411 msglist = mallok(cdbfr->len);
1412 memcpy(msglist, cdbfr->ptr, cdbfr->len);
1413 num_msgs = cdbfr->len / sizeof(long);
1417 for (a = 0; a < num_msgs; ++a) {
1418 if (msglist[a] > 0L) {
1419 if (msglist[a] > vbuf.v_lastseen) {
1424 if (msglist != NULL)
1427 return (num_newmsgs);
1432 * Set the preferred view for the current user/room combination
1434 void cmd_view(char *cmdbuf) {
1438 if (CtdlAccessCheck(ac_logged_in)) {
1442 requested_view = extract_int(cmdbuf, 0);
1444 CtdlGetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
1445 vbuf.v_view = requested_view;
1446 CtdlSetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
1448 cprintf("%d ok\n", CIT_OK);