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"
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));
71 if (CtdlAssociateSystemUser(lowercase_name, name) == 0) {
72 for (a = 0; a <= strlen(lowercase_name); ++a) {
73 lowercase_name[a] = tolower(lowercase_name[a]);
77 for (a = 0; a <= strlen(name); ++a) {
78 if (a < sizeof(lowercase_name))
79 lowercase_name[a] = tolower(name[a]);
82 lowercase_name[sizeof(lowercase_name) - 1] = 0;
84 cdbus = cdb_fetch(CDB_USERSUPP, lowercase_name, strlen(lowercase_name));
86 return (1); /* user not found */
88 memcpy(usbuf, cdbus->ptr,
89 ((cdbus->len > sizeof(struct usersupp)) ?
90 sizeof(struct usersupp) : cdbus->len));
98 * lgetuser() - same as getuser() but locks the record
100 int lgetuser(struct usersupp *usbuf, char *name)
104 retcode = getuser(usbuf, name);
106 begin_critical_section(S_USERSUPP);
113 * putuser() - write user buffer into the correct place on disk
115 void putuser(struct usersupp *usbuf)
117 char lowercase_name[USERNAME_SIZE];
120 for (a = 0; a <= strlen(usbuf->fullname); ++a) {
121 if (a < sizeof(lowercase_name))
122 lowercase_name[a] = tolower(usbuf->fullname[a]);
124 lowercase_name[sizeof(lowercase_name) - 1] = 0;
126 usbuf->version = REV_LEVEL;
127 cdb_store(CDB_USERSUPP,
128 lowercase_name, strlen(lowercase_name),
129 usbuf, sizeof(struct usersupp));
135 * lputuser() - same as putuser() but locks the record
137 void lputuser(struct usersupp *usbuf)
140 end_critical_section(S_USERSUPP);
144 * Index-generating function used by Ctdl[Get|Set]Relationship
146 int GenerateRelationshipIndex(char *IndexBuf,
158 TheIndex.iRoomID = RoomID;
159 TheIndex.iRoomGen = RoomGen;
160 TheIndex.iUserID = UserID;
162 memcpy(IndexBuf, &TheIndex, sizeof(TheIndex));
163 return (sizeof(TheIndex));
169 * Back end for CtdlSetRelationship()
171 void put_visit(struct visit *newvisit)
176 /* Generate an index */
177 IndexLen = GenerateRelationshipIndex(IndexBuf,
180 newvisit->v_usernum);
182 /* Store the record */
183 cdb_store(CDB_VISIT, IndexBuf, IndexLen,
184 newvisit, sizeof(struct visit)
192 * Define a relationship between a user and a room
194 void CtdlSetRelationship(struct visit *newvisit,
195 struct usersupp *rel_user,
196 struct quickroom *rel_room)
200 /* We don't use these in Citadel because they're implicit by the
201 * index, but they must be present if the database is exported.
203 newvisit->v_roomnum = rel_room->QRnumber;
204 newvisit->v_roomgen = rel_room->QRgen;
205 newvisit->v_usernum = rel_user->usernum;
211 * Locate a relationship between a user and a room
213 void CtdlGetRelationship(struct visit *vbuf,
214 struct usersupp *rel_user,
215 struct quickroom *rel_room)
220 struct cdbdata *cdbvisit;
222 /* Generate an index */
223 IndexLen = GenerateRelationshipIndex(IndexBuf,
228 /* Clear out the buffer */
229 memset(vbuf, 0, sizeof(struct visit));
231 cdbvisit = cdb_fetch(CDB_VISIT, IndexBuf, IndexLen);
232 if (cdbvisit != NULL) {
233 memcpy(vbuf, cdbvisit->ptr,
234 ((cdbvisit->len > sizeof(struct visit)) ?
235 sizeof(struct visit) : cdbvisit->len));
239 /* If this is the first time the user has seen this room,
240 * set the view to be the default for the room.
242 vbuf->v_view = rel_room->QRdefaultview;
245 /* Set v_seen if necessary */
246 if (vbuf->v_seen[0] == 0) {
247 snprintf(vbuf->v_seen, sizeof vbuf->v_seen, "*:%ld", vbuf->v_lastseen);
252 void MailboxName(char *buf, size_t n, const struct usersupp *who, const char *prefix)
254 snprintf(buf, n, "%010ld.%s", who->usernum, prefix);
259 * Is the user currently logged in an Aide?
263 if (CC->usersupp.axlevel >= 6)
271 * Is the user currently logged in an Aide *or* the room aide for this room?
273 int is_room_aide(void)
276 if (!CC->logged_in) {
280 if ((CC->usersupp.axlevel >= 6)
281 || (CC->quickroom.QRroomaide == CC->usersupp.usernum)) {
289 * getuserbynumber() - get user by number
290 * returns 0 if user was found
292 * WARNING: don't use this function unless you absolutely have to. It does
293 * a sequential search and therefore is computationally expensive.
295 int getuserbynumber(struct usersupp *usbuf, long int number)
297 struct cdbdata *cdbus;
299 cdb_rewind(CDB_USERSUPP);
301 while (cdbus = cdb_next_item(CDB_USERSUPP), cdbus != NULL) {
302 memset(usbuf, 0, sizeof(struct usersupp));
303 memcpy(usbuf, cdbus->ptr,
304 ((cdbus->len > sizeof(struct usersupp)) ?
305 sizeof(struct usersupp) : cdbus->len));
307 if (usbuf->usernum == number) {
308 cdb_close_cursor(CDB_USERSUPP);
317 * See if we can translate a system login name (i.e. from /etc/passwd)
318 * to a Citadel screen name. Returns 0 if one is found.
320 int CtdlAssociateSystemUser(char *screenname, char *loginname) {
324 p = (struct passwd *) getpwnam(loginname);
326 strcpy(screenname, p->pw_gecos);
327 for (a = 0; a < strlen(screenname); ++a) {
328 if (screenname[a] == ',') {
340 * Back end for cmd_user() and its ilk
342 int CtdlLoginExistingUser(char *trythisname)
347 if (trythisname == NULL) return login_not_found;
348 safestrncpy(username, trythisname, sizeof username);
351 if ((CC->logged_in)) {
352 return login_already_logged_in;
355 found_user = getuser(&CC->usersupp, username);
357 if (found_user == 0) {
358 if (((CC->nologin)) && (CC->usersupp.axlevel < 6)) {
359 return login_too_many_users;
361 strcpy(CC->curr_user, CC->usersupp.fullname);
365 return login_not_found;
373 void cmd_user(char *cmdbuf)
378 extract(username, cmdbuf, 0);
382 a = CtdlLoginExistingUser(username);
384 case login_already_logged_in:
385 cprintf("%d Already logged in.\n", ERROR);
387 case login_too_many_users:
389 "Too many users are already online "
391 ERROR + MAX_SESSIONS_EXCEEDED,
392 config.c_nodename, config.c_maxsessions);
395 cprintf("%d Password required for %s\n",
396 MORE_DATA, CC->curr_user);
398 case login_not_found:
399 cprintf("%d %s not found.\n", ERROR, username);
401 cprintf("%d Internal error\n", ERROR);
408 * session startup code which is common to both cmd_pass() and cmd_newu()
410 void session_startup(void)
414 syslog(LOG_NOTICE, "session %d: user <%s> logged in",
415 CC->cs_pid, CC->curr_user);
417 lgetuser(&CC->usersupp, CC->curr_user);
418 ++(CC->usersupp.timescalled);
419 time(&CC->usersupp.lastcall);
421 /* If this user's name is the name of the system administrator
422 * (as specified in setup), automatically assign access level 6.
424 if (!strcasecmp(CC->usersupp.fullname, config.c_sysadm)) {
425 CC->usersupp.axlevel = 6;
427 lputuser(&CC->usersupp);
430 * Populate CC->cs_inet_email with a default address. This will be
431 * overwritten with the user's directory address, if one exists, when
432 * the vCard module's login hook runs.
434 snprintf(CC->cs_inet_email, sizeof CC->cs_inet_email, "%s@%s",
435 CC->usersupp.fullname, config.c_fqdn);
436 for (i=0; i<strlen(CC->cs_inet_email); ++i) {
437 if (isspace(CC->cs_inet_email[i])) {
438 CC->cs_inet_email[i] = '_';
442 /* Create any personal rooms required by the system.
443 * (Technically, MAILROOM should be there already, but just in case...)
445 create_room(MAILROOM, 4, "", 0, 1, 0);
446 create_room(SENTITEMS, 4, "", 0, 1, 0);
448 /* Run any startup routines registered by loadable modules */
449 PerformSessionHooks(EVT_LOGIN);
451 /* Enter the lobby */
452 usergoto(config.c_baseroom, 0, 0, NULL, NULL);
454 /* Record this login in the Citadel log */
455 rec_log(CL_LOGIN, CC->curr_user);
459 void logged_in_response(void)
461 cprintf("%d %s|%d|%ld|%ld|%u|%ld|%ld\n",
462 CIT_OK, CC->usersupp.fullname, CC->usersupp.axlevel,
463 CC->usersupp.timescalled, CC->usersupp.posted,
464 CC->usersupp.flags, CC->usersupp.usernum,
465 CC->usersupp.lastcall);
471 * misc things to be taken care of when a user is logged out
473 void logout(struct CitContext *who)
478 * If there is a download in progress, abort it.
480 if (who->download_fp != NULL) {
481 fclose(who->download_fp);
482 who->download_fp = NULL;
486 * If there is an upload in progress, abort it.
488 if (who->upload_fp != NULL) {
493 * If we were talking to a network node, we're not anymore...
495 if (strlen(who->net_node) > 0) {
496 network_talking_to(who->net_node, NTT_REMOVE);
499 /* Do modular stuff... */
500 PerformSessionHooks(EVT_LOGOUT);
505 * an alternate version of validpw() which executes `chkpwd' instead of
506 * verifying the password directly
508 static int validpw(uid_t uid, const char *pass)
511 int status, pipev[2];
515 lprintf(1, "pipe failed (%s): denying autologin access for "
516 "uid %ld\n", strerror(errno), (long)uid);
519 switch (pid = fork()) {
521 lprintf(1, "fork failed (%s): denying autologin access for "
522 "uid %ld\n", strerror(errno), (long)uid);
529 if (dup2(pipev[0], 0) == -1) {
535 execl(BBSDIR "/chkpwd", BBSDIR "/chkpwd", NULL);
536 perror(BBSDIR "/chkpwd");
542 snprintf(buf, sizeof buf, "%lu\n", (unsigned long) uid));
543 write(pipev[1], pass, strlen(pass));
544 write(pipev[1], "\n", 1);
547 while (waitpid(pid, &status, 0) == -1)
548 if (errno != EINTR) {
549 lprintf(1, "waitpid failed (%s): denying autologin "
550 "access for uid %ld\n",
551 strerror(errno), (long)uid);
554 if (WIFEXITED(status) && !WEXITSTATUS(status))
568 int CtdlTryPassword(char *password)
572 if ((CC->logged_in)) {
573 lprintf(5, "CtdlTryPassword: already logged in\n");
574 return pass_already_logged_in;
576 if (!strcmp(CC->curr_user, NLI)) {
577 lprintf(5, "CtdlTryPassword: no user selected\n");
580 if (getuser(&CC->usersupp, CC->curr_user)) {
581 lprintf(5, "CtdlTryPassword: internal error\n");
582 return pass_internal_error;
584 if (password == NULL) {
585 lprintf(5, "CtdlTryPassword: NULL password string supplied\n");
586 return pass_wrong_password;
589 if (CC->usersupp.uid == BBSUID) {
591 strproc(CC->usersupp.password);
592 code = strcasecmp(CC->usersupp.password, password);
594 #ifdef ENABLE_AUTOLOGIN
596 if (validpw(CC->usersupp.uid, password)) {
598 lgetuser(&CC->usersupp, CC->curr_user);
599 safestrncpy(CC->usersupp.password, password,
600 sizeof CC->usersupp.password);
601 lputuser(&CC->usersupp);
610 rec_log(CL_BADPW, CC->curr_user);
611 return pass_wrong_password;
616 void cmd_pass(char *buf)
621 extract(password, buf, 0);
622 a = CtdlTryPassword(password);
625 case pass_already_logged_in:
626 cprintf("%d Already logged in.\n", ERROR);
629 cprintf("%d You must send a name with USER first.\n",
632 case pass_wrong_password:
633 cprintf("%d Wrong password.\n", ERROR);
636 logged_in_response();
638 cprintf("%d Can't find user record!\n",
639 ERROR + INTERNAL_ERROR);
646 * Delete a user record *and* all of its related resources.
648 int purge_user(char pname[])
651 struct usersupp usbuf;
652 char lowercase_name[USERNAME_SIZE];
654 struct CitContext *ccptr;
655 int user_is_logged_in = 0;
657 for (a = 0; a <= strlen(pname); ++a) {
658 lowercase_name[a] = tolower(pname[a]);
661 if (getuser(&usbuf, pname) != 0) {
662 lprintf(5, "Cannot purge user <%s> - not found\n", pname);
663 return (ERROR + NO_SUCH_USER);
665 /* Don't delete a user who is currently logged in. Instead, just
666 * set the access level to 0, and let the account get swept up
667 * during the next purge.
669 user_is_logged_in = 0;
670 begin_critical_section(S_SESSION_TABLE);
671 for (ccptr = ContextList; ccptr != NULL; ccptr = ccptr->next) {
672 if (ccptr->usersupp.usernum == usbuf.usernum) {
673 user_is_logged_in = 1;
676 end_critical_section(S_SESSION_TABLE);
677 if (user_is_logged_in == 1) {
678 lprintf(5, "User <%s> is logged in; not deleting.\n", pname);
683 lprintf(5, "Deleting user <%s>\n", pname);
685 /* Perform any purge functions registered by server extensions */
686 PerformUserHooks(usbuf.fullname, usbuf.usernum, EVT_PURGEUSER);
688 /* delete any existing user/room relationships */
689 cdb_delete(CDB_VISIT, &usbuf.usernum, sizeof(long));
691 /* delete the userlog entry */
692 cdb_delete(CDB_USERSUPP, lowercase_name, strlen(lowercase_name));
694 /* remove the user's bio file */
695 snprintf(filename, sizeof filename, "./bio/%ld", usbuf.usernum);
698 /* remove the user's picture */
699 snprintf(filename, sizeof filename, "./userpics/%ld.gif", usbuf.usernum);
707 * create_user() - back end processing to create a new user
709 * Set 'newusername' to the desired account name.
710 * Set 'become_user' to nonzero if this is self-service account creation and we want
711 * to actually log in as the user we just created, otherwise set it to 0.
713 int create_user(char *newusername, int become_user)
715 struct usersupp usbuf;
716 struct quickroom qrbuf;
717 struct passwd *p = NULL;
719 char mailboxname[ROOMNAMELEN];
722 strcpy(username, newusername);
725 #ifdef ENABLE_AUTOLOGIN
726 p = (struct passwd *) getpwnam(username);
729 extract_token(username, p->pw_gecos, 0, ',');
735 if (!getuser(&usbuf, username)) {
736 return (ERROR + ALREADY_EXISTS);
739 /* Go ahead and initialize a new user record */
740 memset(&usbuf, 0, sizeof(struct usersupp));
741 strcpy(usbuf.fullname, username);
742 strcpy(usbuf.password, "");
745 /* These are the default flags on new accounts */
746 usbuf.flags = US_LASTOLD | US_DISAPPEAR | US_PAGINATOR | US_FLOORS;
748 usbuf.timescalled = 0;
750 usbuf.axlevel = config.c_initax;
751 usbuf.USscreenwidth = 80;
752 usbuf.USscreenheight = 24;
753 usbuf.lastcall = time(NULL);
755 /* fetch a new user number */
756 usbuf.usernum = get_new_user_number();
758 /* The very first user created on the system will always be an Aide */
759 if (usbuf.usernum == 1L) {
763 /* add user to userlog */
767 * Give the user a private mailbox and a configuration room.
768 * Make the latter an invisible system room.
770 MailboxName(mailboxname, sizeof mailboxname, &usbuf, MAILROOM);
771 create_room(mailboxname, 5, "", 0, 1, 1);
773 MailboxName(mailboxname, sizeof mailboxname, &usbuf, USERCONFIGROOM);
774 create_room(mailboxname, 5, "", 0, 1, 1);
775 if (lgetroom(&qrbuf, USERCONFIGROOM) == 0) {
776 qrbuf.QRflags2 |= QR2_SYSTEM;
780 /* Everything below this line can be bypassed if administratively
781 creating a user, instead of doing self-service account creation
785 /* Now become the user we just created */
786 memcpy(&CC->usersupp, &usbuf, sizeof(struct usersupp));
787 strcpy(CC->curr_user, username);
790 /* Check to make sure we're still who we think we are */
791 if (getuser(&CC->usersupp, CC->curr_user)) {
792 return (ERROR + INTERNAL_ERROR);
795 rec_log(CL_NEWUSER, CC->curr_user);
805 * cmd_newu() - create a new user account and log in as that user
807 void cmd_newu(char *cmdbuf)
812 if (config.c_disable_newu) {
813 cprintf("%d Self-service user account creation "
814 "is disabled on this system.\n", ERROR);
819 cprintf("%d Already logged in.\n", ERROR);
823 cprintf("%d %s: Too many users are already online (maximum is %d)\n",
824 ERROR + MAX_SESSIONS_EXCEEDED,
825 config.c_nodename, config.c_maxsessions);
827 extract(username, cmdbuf, 0);
831 if (strlen(username) == 0) {
832 cprintf("%d You must supply a user name.\n", ERROR);
836 if ((!strcasecmp(username, "bbs")) ||
837 (!strcasecmp(username, "new")) ||
838 (!strcasecmp(username, "."))) {
839 cprintf("%d '%s' is an invalid login name.\n", ERROR, username);
843 a = create_user(username, 1);
847 logged_in_response();
848 } else if (a == ERROR + ALREADY_EXISTS) {
849 cprintf("%d '%s' already exists.\n",
850 ERROR + ALREADY_EXISTS, username);
852 } else if (a == ERROR + INTERNAL_ERROR) {
853 cprintf("%d Internal error - user record disappeared?\n",
854 ERROR + INTERNAL_ERROR);
857 cprintf("%d unknown error\n", ERROR);
859 rec_log(CL_NEWUSER, CC->curr_user);
867 void cmd_setp(char *new_pw)
869 if (CtdlAccessCheck(ac_logged_in)) {
873 if (CC->usersupp.uid != BBSUID) {
874 cprintf("%d Not allowed. Use the 'passwd' command.\n", ERROR);
878 if (strlen(new_pw) == 0) {
879 cprintf("%d Password unchanged.\n", CIT_OK);
882 lgetuser(&CC->usersupp, CC->curr_user);
883 strcpy(CC->usersupp.password, new_pw);
884 lputuser(&CC->usersupp);
885 cprintf("%d Password changed.\n", CIT_OK);
886 rec_log(CL_PWCHANGE, CC->curr_user);
887 PerformSessionHooks(EVT_SETPASS);
892 * cmd_creu() - administratively create a new user account (do not log in to it)
894 void cmd_creu(char *cmdbuf)
899 if (CtdlAccessCheck(ac_aide)) {
903 extract(username, cmdbuf, 0);
907 if (strlen(username) == 0) {
908 cprintf("%d You must supply a user name.\n", ERROR);
912 a = create_user(username, 0);
915 cprintf("%d ok\n", CIT_OK);
917 } else if (a == ERROR + ALREADY_EXISTS) {
918 cprintf("%d '%s' already exists.\n",
919 ERROR + ALREADY_EXISTS, username);
922 cprintf("%d An error occured creating the user account.\n", ERROR);
924 rec_log(CL_NEWUSER, username);
930 * get user parameters
935 if (CtdlAccessCheck(ac_logged_in))
938 getuser(&CC->usersupp, CC->curr_user);
939 cprintf("%d %d|%d|%d|\n",
941 CC->usersupp.USscreenwidth,
942 CC->usersupp.USscreenheight,
943 (CC->usersupp.flags & US_USER_SET)
948 * set user parameters
950 void cmd_setu(char *new_parms)
952 if (CtdlAccessCheck(ac_logged_in))
955 if (num_parms(new_parms) < 3) {
956 cprintf("%d Usage error.\n", ERROR);
959 lgetuser(&CC->usersupp, CC->curr_user);
960 CC->usersupp.USscreenwidth = extract_int(new_parms, 0);
961 CC->usersupp.USscreenheight = extract_int(new_parms, 1);
962 CC->usersupp.flags = CC->usersupp.flags & (~US_USER_SET);
963 CC->usersupp.flags = CC->usersupp.flags |
964 (extract_int(new_parms, 2) & US_USER_SET);
966 lputuser(&CC->usersupp);
967 cprintf("%d Ok\n", CIT_OK);
971 * set last read pointer
973 void cmd_slrp(char *new_ptr)
978 if (CtdlAccessCheck(ac_logged_in)) {
982 if (!strncasecmp(new_ptr, "highest", 7)) {
983 newlr = CC->quickroom.QRhighest;
985 newlr = atol(new_ptr);
988 lgetuser(&CC->usersupp, CC->curr_user);
990 CtdlGetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
991 vbuf.v_lastseen = newlr;
992 snprintf(vbuf.v_seen, sizeof vbuf.v_seen, "*:%ld", newlr);
993 CtdlSetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
995 lputuser(&CC->usersupp);
996 cprintf("%d %ld\n", CIT_OK, newlr);
1000 void cmd_seen(char *argbuf) {
1001 long target_msgnum = 0L;
1002 int target_setting = 0;
1004 if (CtdlAccessCheck(ac_logged_in)) {
1008 if (num_parms(argbuf) != 2) {
1009 cprintf("%d Invalid parameters\n", ERROR);
1013 target_msgnum = extract_long(argbuf, 0);
1014 target_setting = extract_int(argbuf, 1);
1016 CtdlSetSeen(target_msgnum, target_setting);
1017 cprintf("%d OK\n", CIT_OK);
1021 void cmd_gtsn(char *argbuf) {
1024 if (CtdlAccessCheck(ac_logged_in)) {
1029 cprintf("%d %s\n", CIT_OK, buf);
1035 * INVT and KICK commands
1037 void cmd_invt_kick(char *iuser, int op)
1039 { /* 1 = invite, 0 = kick out */
1040 struct usersupp USscratch;
1045 * These commands are only allowed by aides, room aides,
1046 * and room namespace owners
1049 || (atol(CC->quickroom.QRname) == CC->usersupp.usernum) ) {
1050 /* access granted */
1053 cprintf("%d Higher access or room ownership required.\n",
1054 ERROR + HIGHER_ACCESS_REQUIRED);
1058 if (!strncasecmp(CC->quickroom.QRname, config.c_baseroom,
1060 cprintf("%d Can't add/remove users from this room.\n",
1065 if (lgetuser(&USscratch, iuser) != 0) {
1066 cprintf("%d No such user.\n", ERROR);
1069 CtdlGetRelationship(&vbuf, &USscratch, &CC->quickroom);
1072 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
1073 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
1076 vbuf.v_flags = vbuf.v_flags & ~V_ACCESS;
1077 vbuf.v_flags = vbuf.v_flags | V_FORGET | V_LOCKOUT;
1079 CtdlSetRelationship(&vbuf, &USscratch, &CC->quickroom);
1081 lputuser(&USscratch);
1083 /* post a message in Aide> saying what we just did */
1084 snprintf(bbb, sizeof bbb, "%s %s %s> by %s\n",
1086 ((op == 1) ? "invited to" : "kicked out of"),
1087 CC->quickroom.QRname,
1088 CC->usersupp.fullname);
1091 cprintf("%d %s %s %s.\n",
1093 ((op == 1) ? "invited to" : "kicked out of"),
1094 CC->quickroom.QRname);
1100 * Forget (Zap) the current room (API call)
1101 * Returns 0 on success
1103 int CtdlForgetThisRoom(void) {
1106 /* On some systems, Aides are not allowed to forget rooms */
1107 if (is_aide() && (config.c_aide_zap == 0)
1108 && ((CC->quickroom.QRflags & QR_MAILBOX) == 0) ) {
1112 lgetuser(&CC->usersupp, CC->curr_user);
1113 CtdlGetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
1115 vbuf.v_flags = vbuf.v_flags | V_FORGET;
1116 vbuf.v_flags = vbuf.v_flags & ~V_ACCESS;
1118 CtdlSetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
1119 lputuser(&CC->usersupp);
1121 /* Return to the Lobby, so we don't end up in an undefined room */
1122 usergoto(config.c_baseroom, 0, 0, NULL, NULL);
1129 * forget (Zap) the current room
1134 if (CtdlAccessCheck(ac_logged_in)) {
1138 if (CtdlForgetThisRoom() == 0) {
1139 cprintf("%d Ok\n", CIT_OK);
1142 cprintf("%d You may not forget this room.\n", ERROR);
1147 * Get Next Unregistered User
1151 struct cdbdata *cdbus;
1152 struct usersupp usbuf;
1154 if (CtdlAccessCheck(ac_aide)) {
1158 if ((CitControl.MMflags & MM_VALID) == 0) {
1159 cprintf("%d There are no unvalidated users.\n", CIT_OK);
1163 /* There are unvalidated users. Traverse the usersupp database,
1164 * and return the first user we find that needs validation.
1166 cdb_rewind(CDB_USERSUPP);
1167 while (cdbus = cdb_next_item(CDB_USERSUPP), cdbus != NULL) {
1168 memset(&usbuf, 0, sizeof(struct usersupp));
1169 memcpy(&usbuf, cdbus->ptr,
1170 ((cdbus->len > sizeof(struct usersupp)) ?
1171 sizeof(struct usersupp) : cdbus->len));
1173 if ((usbuf.flags & US_NEEDVALID)
1174 && (usbuf.axlevel > 0)) {
1175 cprintf("%d %s\n", MORE_DATA, usbuf.fullname);
1176 cdb_close_cursor(CDB_USERSUPP);
1181 /* If we get to this point, there are no more unvalidated users.
1182 * Therefore we clear the "users need validation" flag.
1185 begin_critical_section(S_CONTROL);
1187 CitControl.MMflags = CitControl.MMflags & (~MM_VALID);
1189 end_critical_section(S_CONTROL);
1190 cprintf("%d *** End of registration.\n", CIT_OK);
1199 void cmd_vali(char *v_args)
1203 struct usersupp userbuf;
1205 extract(user, v_args, 0);
1206 newax = extract_int(v_args, 1);
1208 if (CtdlAccessCheck(ac_aide)) {
1212 if (lgetuser(&userbuf, user) != 0) {
1213 cprintf("%d '%s' not found.\n", ERROR + NO_SUCH_USER, user);
1217 userbuf.axlevel = newax;
1218 userbuf.flags = (userbuf.flags & ~US_NEEDVALID);
1222 /* If the access level was set to zero, delete the user */
1224 if (purge_user(user) == 0) {
1225 cprintf("%d %s Deleted.\n", CIT_OK, userbuf.fullname);
1229 cprintf("%d User '%s' validated.\n", CIT_OK, userbuf.fullname);
1235 * Traverse the user file...
1237 void ForEachUser(void (*CallBack) (struct usersupp * EachUser, void *out_data),
1240 struct usersupp usbuf;
1241 struct cdbdata *cdbus;
1243 cdb_rewind(CDB_USERSUPP);
1245 while (cdbus = cdb_next_item(CDB_USERSUPP), cdbus != NULL) {
1246 memset(&usbuf, 0, sizeof(struct usersupp));
1247 memcpy(&usbuf, cdbus->ptr,
1248 ((cdbus->len > sizeof(struct usersupp)) ?
1249 sizeof(struct usersupp) : cdbus->len));
1251 (*CallBack) (&usbuf, in_data);
1257 * List one user (this works with cmd_list)
1259 void ListThisUser(struct usersupp *usbuf, void *data)
1261 if (usbuf->axlevel > 0) {
1262 if ((CC->usersupp.axlevel >= 6)
1263 || ((usbuf->flags & US_UNLISTED) == 0)
1264 || ((CC->internal_pgm))) {
1265 cprintf("%s|%d|%ld|%ld|%ld|%ld|",
1269 (long)usbuf->lastcall,
1272 if (CC->usersupp.axlevel >= 6)
1273 cprintf("%s", usbuf->password);
1284 cprintf("%d \n", LISTING_FOLLOWS);
1285 ForEachUser(ListThisUser, NULL);
1293 * assorted info we need to check at login
1301 if (CtdlAccessCheck(ac_logged_in)) {
1305 getuser(&CC->usersupp, CC->curr_user); /* no lock is needed here */
1306 if ((REGISCALL != 0) && ((CC->usersupp.flags & US_REGIS) == 0))
1309 if (CC->usersupp.axlevel >= 6) {
1311 if (CitControl.MMflags & MM_VALID)
1315 /* check for mail */
1316 mail = InitialMailCheck();
1318 cprintf("%d %d|%d|%d|%s|\n", CIT_OK, mail, regis, vali, CC->cs_inet_email);
1323 * check to see if a user exists
1325 void cmd_qusr(char *who)
1327 struct usersupp usbuf;
1329 if (getuser(&usbuf, who) == 0) {
1330 cprintf("%d %s\n", CIT_OK, usbuf.fullname);
1332 cprintf("%d No such user.\n", ERROR + NO_SUCH_USER);
1338 * Administrative Get User Parameters
1340 void cmd_agup(char *cmdbuf)
1342 struct usersupp usbuf;
1343 char requested_user[SIZ];
1345 if (CtdlAccessCheck(ac_aide)) {
1349 extract(requested_user, cmdbuf, 0);
1350 if (getuser(&usbuf, requested_user) != 0) {
1351 cprintf("%d No such user.\n", ERROR + NO_SUCH_USER);
1354 cprintf("%d %s|%s|%u|%ld|%ld|%d|%ld|%ld|%d\n",
1361 (int) usbuf.axlevel,
1363 (long)usbuf.lastcall,
1370 * Administrative Set User Parameters
1372 void cmd_asup(char *cmdbuf)
1374 struct usersupp usbuf;
1375 char requested_user[SIZ];
1381 if (CtdlAccessCheck(ac_aide))
1384 extract(requested_user, cmdbuf, 0);
1385 if (lgetuser(&usbuf, requested_user) != 0) {
1386 cprintf("%d No such user.\n", ERROR + NO_SUCH_USER);
1389 np = num_parms(cmdbuf);
1391 extract(usbuf.password, cmdbuf, 1);
1393 usbuf.flags = extract_int(cmdbuf, 2);
1395 usbuf.timescalled = extract_int(cmdbuf, 3);
1397 usbuf.posted = extract_int(cmdbuf, 4);
1399 newax = extract_int(cmdbuf, 5);
1400 if ((newax >= 0) && (newax <= 6)) {
1401 usbuf.axlevel = extract_int(cmdbuf, 5);
1405 usbuf.lastcall = extract_long(cmdbuf, 7);
1408 usbuf.USuserpurge = extract_int(cmdbuf, 8);
1411 if (usbuf.axlevel == 0) {
1412 if (purge_user(requested_user) == 0) {
1418 sprintf(notify, "User <%s> deleted by %s\n",
1419 usbuf.fullname, CC->usersupp.fullname);
1420 aide_message(notify);
1423 cprintf("%d Ok", CIT_OK);
1425 cprintf(" (%s deleted)", requested_user);
1432 * Check to see if the user who we just sent mail to is logged in. If yes,
1433 * bump the 'new mail' counter for their session. That enables them to
1434 * receive a new mail notification without having to hit the database.
1436 void BumpNewMailCounter(long which_user) {
1437 struct CitContext *ptr;
1439 begin_critical_section(S_SESSION_TABLE);
1441 for (ptr = ContextList; ptr != NULL; ptr = ptr->next) {
1442 if (ptr->usersupp.usernum == which_user) {
1447 end_critical_section(S_SESSION_TABLE);
1452 * Count the number of new mail messages the user has
1456 int num_newmsgs = 0;
1458 num_newmsgs = CC->newmail;
1461 return (num_newmsgs);
1466 * Count the number of new mail messages the user has
1468 int InitialMailCheck()
1470 int num_newmsgs = 0;
1472 char mailboxname[ROOMNAMELEN];
1473 struct quickroom mailbox;
1475 struct cdbdata *cdbfr;
1476 long *msglist = NULL;
1479 MailboxName(mailboxname, sizeof mailboxname, &CC->usersupp, MAILROOM);
1480 if (getroom(&mailbox, mailboxname) != 0)
1482 CtdlGetRelationship(&vbuf, &CC->usersupp, &mailbox);
1484 cdbfr = cdb_fetch(CDB_MSGLISTS, &mailbox.QRnumber, sizeof(long));
1486 if (cdbfr != NULL) {
1487 msglist = mallok(cdbfr->len);
1488 memcpy(msglist, cdbfr->ptr, cdbfr->len);
1489 num_msgs = cdbfr->len / sizeof(long);
1493 for (a = 0; a < num_msgs; ++a) {
1494 if (msglist[a] > 0L) {
1495 if (msglist[a] > vbuf.v_lastseen) {
1500 if (msglist != NULL)
1503 return (num_newmsgs);
1509 * Set the preferred view for the current user/room combination
1511 void cmd_view(char *cmdbuf) {
1515 if (CtdlAccessCheck(ac_logged_in)) {
1519 requested_view = extract_int(cmdbuf, 0);
1521 CtdlGetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
1522 vbuf.v_view = requested_view;
1523 CtdlSetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
1525 cprintf("%d ok\n", CIT_OK);