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];
66 char sysuser_name[USERNAME_SIZE];
68 struct cdbdata *cdbus;
69 int using_sysuser = 0;
71 memset(usbuf, 0, sizeof(struct usersupp));
73 #ifdef ENABLE_AUTOLOGIN
74 if (CtdlAssociateSystemUser(sysuser_name, name) == 0) {
80 for (a = 0; a <= strlen(sysuser_name); ++a) {
81 lowercase_name[a] = tolower(sysuser_name[a]);
85 for (a = 0; a <= strlen(name); ++a) {
86 if (a < sizeof(lowercase_name))
87 lowercase_name[a] = tolower(name[a]);
90 lowercase_name[sizeof(lowercase_name) - 1] = 0;
92 cdbus = cdb_fetch(CDB_USERSUPP, lowercase_name, strlen(lowercase_name));
93 if (cdbus == NULL) { /* user not found */
96 memcpy(usbuf, cdbus->ptr,
97 ((cdbus->len > sizeof(struct usersupp)) ?
98 sizeof(struct usersupp) : cdbus->len));
106 * lgetuser() - same as getuser() but locks the record
108 int lgetuser(struct usersupp *usbuf, char *name)
112 retcode = getuser(usbuf, name);
114 begin_critical_section(S_USERSUPP);
121 * putuser() - write user buffer into the correct place on disk
123 void putuser(struct usersupp *usbuf)
125 char lowercase_name[USERNAME_SIZE];
128 for (a = 0; a <= strlen(usbuf->fullname); ++a) {
129 if (a < sizeof(lowercase_name))
130 lowercase_name[a] = tolower(usbuf->fullname[a]);
132 lowercase_name[sizeof(lowercase_name) - 1] = 0;
134 usbuf->version = REV_LEVEL;
135 cdb_store(CDB_USERSUPP,
136 lowercase_name, strlen(lowercase_name),
137 usbuf, sizeof(struct usersupp));
143 * lputuser() - same as putuser() but locks the record
145 void lputuser(struct usersupp *usbuf)
148 end_critical_section(S_USERSUPP);
152 * Index-generating function used by Ctdl[Get|Set]Relationship
154 int GenerateRelationshipIndex(char *IndexBuf,
166 TheIndex.iRoomID = RoomID;
167 TheIndex.iRoomGen = RoomGen;
168 TheIndex.iUserID = UserID;
170 memcpy(IndexBuf, &TheIndex, sizeof(TheIndex));
171 return (sizeof(TheIndex));
177 * Back end for CtdlSetRelationship()
179 void put_visit(struct visit *newvisit)
184 /* Generate an index */
185 IndexLen = GenerateRelationshipIndex(IndexBuf,
188 newvisit->v_usernum);
190 /* Store the record */
191 cdb_store(CDB_VISIT, IndexBuf, IndexLen,
192 newvisit, sizeof(struct visit)
200 * Define a relationship between a user and a room
202 void CtdlSetRelationship(struct visit *newvisit,
203 struct usersupp *rel_user,
204 struct quickroom *rel_room)
208 /* We don't use these in Citadel because they're implicit by the
209 * index, but they must be present if the database is exported.
211 newvisit->v_roomnum = rel_room->QRnumber;
212 newvisit->v_roomgen = rel_room->QRgen;
213 newvisit->v_usernum = rel_user->usernum;
219 * Locate a relationship between a user and a room
221 void CtdlGetRelationship(struct visit *vbuf,
222 struct usersupp *rel_user,
223 struct quickroom *rel_room)
228 struct cdbdata *cdbvisit;
230 /* Generate an index */
231 IndexLen = GenerateRelationshipIndex(IndexBuf,
236 /* Clear out the buffer */
237 memset(vbuf, 0, sizeof(struct visit));
239 cdbvisit = cdb_fetch(CDB_VISIT, IndexBuf, IndexLen);
240 if (cdbvisit != NULL) {
241 memcpy(vbuf, cdbvisit->ptr,
242 ((cdbvisit->len > sizeof(struct visit)) ?
243 sizeof(struct visit) : cdbvisit->len));
247 /* If this is the first time the user has seen this room,
248 * set the view to be the default for the room.
250 vbuf->v_view = rel_room->QRdefaultview;
253 /* Set v_seen if necessary */
254 if (vbuf->v_seen[0] == 0) {
255 snprintf(vbuf->v_seen, sizeof vbuf->v_seen, "*:%ld", vbuf->v_lastseen);
260 void MailboxName(char *buf, size_t n, const struct usersupp *who, const char *prefix)
262 snprintf(buf, n, "%010ld.%s", who->usernum, prefix);
267 * Is the user currently logged in an Aide?
271 if (CC->usersupp.axlevel >= 6)
279 * Is the user currently logged in an Aide *or* the room aide for this room?
281 int is_room_aide(void)
284 if (!CC->logged_in) {
288 if ((CC->usersupp.axlevel >= 6)
289 || (CC->quickroom.QRroomaide == CC->usersupp.usernum)) {
297 * getuserbynumber() - get user by number
298 * returns 0 if user was found
300 * WARNING: don't use this function unless you absolutely have to. It does
301 * a sequential search and therefore is computationally expensive.
303 int getuserbynumber(struct usersupp *usbuf, long int number)
305 struct cdbdata *cdbus;
307 cdb_rewind(CDB_USERSUPP);
309 while (cdbus = cdb_next_item(CDB_USERSUPP), cdbus != NULL) {
310 memset(usbuf, 0, sizeof(struct usersupp));
311 memcpy(usbuf, cdbus->ptr,
312 ((cdbus->len > sizeof(struct usersupp)) ?
313 sizeof(struct usersupp) : cdbus->len));
315 if (usbuf->usernum == number) {
316 cdb_close_cursor(CDB_USERSUPP);
325 * See if we can translate a system login name (i.e. from /etc/passwd)
326 * to a Citadel screen name. Returns 0 if one is found.
328 int CtdlAssociateSystemUser(char *screenname, char *loginname) {
332 p = (struct passwd *) getpwnam(loginname);
334 strcpy(screenname, p->pw_gecos);
335 for (a = 0; a < strlen(screenname); ++a) {
336 if (screenname[a] == ',') {
348 * Back end for cmd_user() and its ilk
350 int CtdlLoginExistingUser(char *trythisname)
355 if (trythisname == NULL) return login_not_found;
356 safestrncpy(username, trythisname, sizeof username);
359 if ((CC->logged_in)) {
360 return login_already_logged_in;
363 found_user = getuser(&CC->usersupp, username);
365 if (found_user == 0) {
366 if (((CC->nologin)) && (CC->usersupp.axlevel < 6)) {
367 return login_too_many_users;
369 strcpy(CC->curr_user, CC->usersupp.fullname);
373 return login_not_found;
381 void cmd_user(char *cmdbuf)
386 extract(username, cmdbuf, 0);
390 a = CtdlLoginExistingUser(username);
392 case login_already_logged_in:
393 cprintf("%d Already logged in.\n", ERROR);
395 case login_too_many_users:
397 "Too many users are already online "
399 ERROR + MAX_SESSIONS_EXCEEDED,
400 config.c_nodename, config.c_maxsessions);
403 cprintf("%d Password required for %s\n",
404 MORE_DATA, CC->curr_user);
406 case login_not_found:
407 cprintf("%d %s not found.\n", ERROR, username);
409 cprintf("%d Internal error\n", ERROR);
416 * session startup code which is common to both cmd_pass() and cmd_newu()
418 void session_startup(void)
422 syslog(LOG_NOTICE, "session %d: user <%s> logged in",
423 CC->cs_pid, CC->curr_user);
425 lgetuser(&CC->usersupp, CC->curr_user);
426 ++(CC->usersupp.timescalled);
427 CC->previous_login = CC->usersupp.lastcall;
428 time(&CC->usersupp.lastcall);
430 /* If this user's name is the name of the system administrator
431 * (as specified in setup), automatically assign access level 6.
433 if (!strcasecmp(CC->usersupp.fullname, config.c_sysadm)) {
434 CC->usersupp.axlevel = 6;
436 lputuser(&CC->usersupp);
439 * Populate CC->cs_inet_email with a default address. This will be
440 * overwritten with the user's directory address, if one exists, when
441 * the vCard module's login hook runs.
443 snprintf(CC->cs_inet_email, sizeof CC->cs_inet_email, "%s@%s",
444 CC->usersupp.fullname, config.c_fqdn);
445 for (i=0; i<strlen(CC->cs_inet_email); ++i) {
446 if (isspace(CC->cs_inet_email[i])) {
447 CC->cs_inet_email[i] = '_';
451 /* Create any personal rooms required by the system.
452 * (Technically, MAILROOM should be there already, but just in case...)
454 create_room(MAILROOM, 4, "", 0, 1, 0);
455 create_room(SENTITEMS, 4, "", 0, 1, 0);
457 /* Run any startup routines registered by loadable modules */
458 PerformSessionHooks(EVT_LOGIN);
460 /* Enter the lobby */
461 usergoto(config.c_baseroom, 0, 0, NULL, NULL);
463 /* Record this login in the Citadel log */
464 rec_log(CL_LOGIN, CC->curr_user);
468 void logged_in_response(void)
470 cprintf("%d %s|%d|%ld|%ld|%u|%ld|%ld\n",
471 CIT_OK, CC->usersupp.fullname, CC->usersupp.axlevel,
472 CC->usersupp.timescalled, CC->usersupp.posted,
473 CC->usersupp.flags, CC->usersupp.usernum,
480 * misc things to be taken care of when a user is logged out
482 void logout(struct CitContext *who)
487 * If there is a download in progress, abort it.
489 if (who->download_fp != NULL) {
490 fclose(who->download_fp);
491 who->download_fp = NULL;
495 * If there is an upload in progress, abort it.
497 if (who->upload_fp != NULL) {
502 * If we were talking to a network node, we're not anymore...
504 if (strlen(who->net_node) > 0) {
505 network_talking_to(who->net_node, NTT_REMOVE);
508 /* Do modular stuff... */
509 PerformSessionHooks(EVT_LOGOUT);
514 * an alternate version of validpw() which executes `chkpwd' instead of
515 * verifying the password directly
517 static int validpw(uid_t uid, const char *pass)
520 int status, pipev[2];
524 lprintf(1, "pipe failed (%s): denying autologin access for "
525 "uid %ld\n", strerror(errno), (long)uid);
528 switch (pid = fork()) {
530 lprintf(1, "fork failed (%s): denying autologin access for "
531 "uid %ld\n", strerror(errno), (long)uid);
538 if (dup2(pipev[0], 0) == -1) {
544 execl(BBSDIR "/chkpwd", BBSDIR "/chkpwd", NULL);
545 perror(BBSDIR "/chkpwd");
551 snprintf(buf, sizeof buf, "%lu\n", (unsigned long) uid));
552 write(pipev[1], pass, strlen(pass));
553 write(pipev[1], "\n", 1);
556 while (waitpid(pid, &status, 0) == -1)
557 if (errno != EINTR) {
558 lprintf(1, "waitpid failed (%s): denying autologin "
559 "access for uid %ld\n",
560 strerror(errno), (long)uid);
563 if (WIFEXITED(status) && !WEXITSTATUS(status))
577 int CtdlTryPassword(char *password)
581 if ((CC->logged_in)) {
582 lprintf(5, "CtdlTryPassword: already logged in\n");
583 return pass_already_logged_in;
585 if (!strcmp(CC->curr_user, NLI)) {
586 lprintf(5, "CtdlTryPassword: no user selected\n");
589 if (getuser(&CC->usersupp, CC->curr_user)) {
590 lprintf(5, "CtdlTryPassword: internal error\n");
591 return pass_internal_error;
593 if (password == NULL) {
594 lprintf(5, "CtdlTryPassword: NULL password string supplied\n");
595 return pass_wrong_password;
600 #ifdef ENABLE_AUTOLOGIN
601 if (CC->usersupp.uid == BBSUID) {
603 strproc(CC->usersupp.password);
604 code = strcasecmp(CC->usersupp.password, password);
607 if (validpw(CC->usersupp.uid, password)) {
609 lgetuser(&CC->usersupp, CC->curr_user);
610 safestrncpy(CC->usersupp.password, password,
611 sizeof CC->usersupp.password);
612 lputuser(&CC->usersupp);
616 #else /* ENABLE_AUTOLOGIN */
618 strproc(CC->usersupp.password);
619 code = strcasecmp(CC->usersupp.password, password);
621 #endif /* ENABLE_AUTOLOGIN */
627 rec_log(CL_BADPW, CC->curr_user);
628 return pass_wrong_password;
633 void cmd_pass(char *buf)
638 extract(password, buf, 0);
639 a = CtdlTryPassword(password);
642 case pass_already_logged_in:
643 cprintf("%d Already logged in.\n", ERROR);
646 cprintf("%d You must send a name with USER first.\n",
649 case pass_wrong_password:
650 cprintf("%d Wrong password.\n", ERROR);
653 logged_in_response();
655 cprintf("%d Can't find user record!\n",
656 ERROR + INTERNAL_ERROR);
663 * Delete a user record *and* all of its related resources.
665 int purge_user(char pname[])
668 struct usersupp usbuf;
669 char lowercase_name[USERNAME_SIZE];
671 struct CitContext *ccptr;
672 int user_is_logged_in = 0;
674 for (a = 0; a <= strlen(pname); ++a) {
675 lowercase_name[a] = tolower(pname[a]);
678 if (getuser(&usbuf, pname) != 0) {
679 lprintf(5, "Cannot purge user <%s> - not found\n", pname);
680 return (ERROR + NO_SUCH_USER);
682 /* Don't delete a user who is currently logged in. Instead, just
683 * set the access level to 0, and let the account get swept up
684 * during the next purge.
686 user_is_logged_in = 0;
687 begin_critical_section(S_SESSION_TABLE);
688 for (ccptr = ContextList; ccptr != NULL; ccptr = ccptr->next) {
689 if (ccptr->usersupp.usernum == usbuf.usernum) {
690 user_is_logged_in = 1;
693 end_critical_section(S_SESSION_TABLE);
694 if (user_is_logged_in == 1) {
695 lprintf(5, "User <%s> is logged in; not deleting.\n", pname);
700 lprintf(5, "Deleting user <%s>\n", pname);
702 /* Perform any purge functions registered by server extensions */
703 PerformUserHooks(usbuf.fullname, usbuf.usernum, EVT_PURGEUSER);
705 /* delete any existing user/room relationships */
706 cdb_delete(CDB_VISIT, &usbuf.usernum, sizeof(long));
708 /* delete the userlog entry */
709 cdb_delete(CDB_USERSUPP, lowercase_name, strlen(lowercase_name));
711 /* remove the user's bio file */
712 snprintf(filename, sizeof filename, "./bio/%ld", usbuf.usernum);
715 /* remove the user's picture */
716 snprintf(filename, sizeof filename, "./userpics/%ld.gif", usbuf.usernum);
724 * create_user() - back end processing to create a new user
726 * Set 'newusername' to the desired account name.
727 * Set 'become_user' to nonzero if this is self-service account creation and we want
728 * to actually log in as the user we just created, otherwise set it to 0.
730 int create_user(char *newusername, int become_user)
732 struct usersupp usbuf;
733 struct quickroom qrbuf;
734 struct passwd *p = NULL;
736 char mailboxname[ROOMNAMELEN];
739 strcpy(username, newusername);
742 #ifdef ENABLE_AUTOLOGIN
743 p = (struct passwd *) getpwnam(username);
745 extract_token(username, p->pw_gecos, 0, ',');
754 if (!getuser(&usbuf, username)) {
755 return (ERROR + ALREADY_EXISTS);
758 /* Go ahead and initialize a new user record */
759 memset(&usbuf, 0, sizeof(struct usersupp));
760 strcpy(usbuf.fullname, username);
761 strcpy(usbuf.password, "");
764 /* These are the default flags on new accounts */
765 usbuf.flags = US_LASTOLD | US_DISAPPEAR | US_PAGINATOR | US_FLOORS;
767 usbuf.timescalled = 0;
769 usbuf.axlevel = config.c_initax;
770 usbuf.USscreenwidth = 80;
771 usbuf.USscreenheight = 24;
772 usbuf.lastcall = time(NULL);
774 /* fetch a new user number */
775 usbuf.usernum = get_new_user_number();
777 /* The very first user created on the system will always be an Aide */
778 if (usbuf.usernum == 1L) {
782 /* add user to userlog */
786 * Give the user a private mailbox and a configuration room.
787 * Make the latter an invisible system room.
789 MailboxName(mailboxname, sizeof mailboxname, &usbuf, MAILROOM);
790 create_room(mailboxname, 5, "", 0, 1, 1);
792 MailboxName(mailboxname, sizeof mailboxname, &usbuf, USERCONFIGROOM);
793 create_room(mailboxname, 5, "", 0, 1, 1);
794 if (lgetroom(&qrbuf, mailboxname) == 0) {
795 qrbuf.QRflags2 |= QR2_SYSTEM;
799 /* Everything below this line can be bypassed if administratively
800 creating a user, instead of doing self-service account creation
804 /* Now become the user we just created */
805 memcpy(&CC->usersupp, &usbuf, sizeof(struct usersupp));
806 strcpy(CC->curr_user, username);
809 /* Check to make sure we're still who we think we are */
810 if (getuser(&CC->usersupp, CC->curr_user)) {
811 return (ERROR + INTERNAL_ERROR);
814 rec_log(CL_NEWUSER, CC->curr_user);
824 * cmd_newu() - create a new user account and log in as that user
826 void cmd_newu(char *cmdbuf)
831 if (config.c_disable_newu) {
832 cprintf("%d Self-service user account creation "
833 "is disabled on this system.\n", ERROR);
838 cprintf("%d Already logged in.\n", ERROR);
842 cprintf("%d %s: Too many users are already online (maximum is %d)\n",
843 ERROR + MAX_SESSIONS_EXCEEDED,
844 config.c_nodename, config.c_maxsessions);
846 extract(username, cmdbuf, 0);
850 if (strlen(username) == 0) {
851 cprintf("%d You must supply a user name.\n", ERROR);
855 if ((!strcasecmp(username, "bbs")) ||
856 (!strcasecmp(username, "new")) ||
857 (!strcasecmp(username, "."))) {
858 cprintf("%d '%s' is an invalid login name.\n", ERROR, username);
862 a = create_user(username, 1);
866 logged_in_response();
867 } else if (a == ERROR + ALREADY_EXISTS) {
868 cprintf("%d '%s' already exists.\n",
869 ERROR + ALREADY_EXISTS, username);
871 } else if (a == ERROR + INTERNAL_ERROR) {
872 cprintf("%d Internal error - user record disappeared?\n",
873 ERROR + INTERNAL_ERROR);
876 cprintf("%d unknown error\n", ERROR);
878 rec_log(CL_NEWUSER, CC->curr_user);
886 void cmd_setp(char *new_pw)
888 if (CtdlAccessCheck(ac_logged_in)) {
892 if (CC->usersupp.uid != BBSUID) {
893 cprintf("%d Not allowed. Use the 'passwd' command.\n", ERROR);
897 if (strlen(new_pw) == 0) {
898 cprintf("%d Password unchanged.\n", CIT_OK);
901 lgetuser(&CC->usersupp, CC->curr_user);
902 strcpy(CC->usersupp.password, new_pw);
903 lputuser(&CC->usersupp);
904 cprintf("%d Password changed.\n", CIT_OK);
905 rec_log(CL_PWCHANGE, CC->curr_user);
906 PerformSessionHooks(EVT_SETPASS);
911 * cmd_creu() - administratively create a new user account (do not log in to it)
913 void cmd_creu(char *cmdbuf)
918 if (CtdlAccessCheck(ac_aide)) {
922 extract(username, cmdbuf, 0);
926 if (strlen(username) == 0) {
927 cprintf("%d You must supply a user name.\n", ERROR);
931 a = create_user(username, 0);
934 cprintf("%d ok\n", CIT_OK);
936 } else if (a == ERROR + ALREADY_EXISTS) {
937 cprintf("%d '%s' already exists.\n",
938 ERROR + ALREADY_EXISTS, username);
941 cprintf("%d An error occured creating the user account.\n", ERROR);
943 rec_log(CL_NEWUSER, username);
949 * get user parameters
954 if (CtdlAccessCheck(ac_logged_in))
957 getuser(&CC->usersupp, CC->curr_user);
958 cprintf("%d %d|%d|%d|\n",
960 CC->usersupp.USscreenwidth,
961 CC->usersupp.USscreenheight,
962 (CC->usersupp.flags & US_USER_SET)
967 * set user parameters
969 void cmd_setu(char *new_parms)
971 if (CtdlAccessCheck(ac_logged_in))
974 if (num_parms(new_parms) < 3) {
975 cprintf("%d Usage error.\n", ERROR);
978 lgetuser(&CC->usersupp, CC->curr_user);
979 CC->usersupp.USscreenwidth = extract_int(new_parms, 0);
980 CC->usersupp.USscreenheight = extract_int(new_parms, 1);
981 CC->usersupp.flags = CC->usersupp.flags & (~US_USER_SET);
982 CC->usersupp.flags = CC->usersupp.flags |
983 (extract_int(new_parms, 2) & US_USER_SET);
985 lputuser(&CC->usersupp);
986 cprintf("%d Ok\n", CIT_OK);
990 * set last read pointer
992 void cmd_slrp(char *new_ptr)
997 if (CtdlAccessCheck(ac_logged_in)) {
1001 if (!strncasecmp(new_ptr, "highest", 7)) {
1002 newlr = CC->quickroom.QRhighest;
1004 newlr = atol(new_ptr);
1007 lgetuser(&CC->usersupp, CC->curr_user);
1009 CtdlGetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
1010 vbuf.v_lastseen = newlr;
1011 snprintf(vbuf.v_seen, sizeof vbuf.v_seen, "*:%ld", newlr);
1012 CtdlSetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
1014 lputuser(&CC->usersupp);
1015 cprintf("%d %ld\n", CIT_OK, newlr);
1019 void cmd_seen(char *argbuf) {
1020 long target_msgnum = 0L;
1021 int target_setting = 0;
1023 if (CtdlAccessCheck(ac_logged_in)) {
1027 if (num_parms(argbuf) != 2) {
1028 cprintf("%d Invalid parameters\n", ERROR);
1032 target_msgnum = extract_long(argbuf, 0);
1033 target_setting = extract_int(argbuf, 1);
1035 CtdlSetSeen(target_msgnum, target_setting);
1036 cprintf("%d OK\n", CIT_OK);
1040 void cmd_gtsn(char *argbuf) {
1043 if (CtdlAccessCheck(ac_logged_in)) {
1048 cprintf("%d %s\n", CIT_OK, buf);
1054 * INVT and KICK commands
1056 void cmd_invt_kick(char *iuser, int op)
1058 { /* 1 = invite, 0 = kick out */
1059 struct usersupp USscratch;
1064 * These commands are only allowed by aides, room aides,
1065 * and room namespace owners
1068 || (atol(CC->quickroom.QRname) == CC->usersupp.usernum) ) {
1069 /* access granted */
1072 cprintf("%d Higher access or room ownership required.\n",
1073 ERROR + HIGHER_ACCESS_REQUIRED);
1077 if (!strncasecmp(CC->quickroom.QRname, config.c_baseroom,
1079 cprintf("%d Can't add/remove users from this room.\n",
1084 if (lgetuser(&USscratch, iuser) != 0) {
1085 cprintf("%d No such user.\n", ERROR);
1088 CtdlGetRelationship(&vbuf, &USscratch, &CC->quickroom);
1091 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
1092 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
1095 vbuf.v_flags = vbuf.v_flags & ~V_ACCESS;
1096 vbuf.v_flags = vbuf.v_flags | V_FORGET | V_LOCKOUT;
1098 CtdlSetRelationship(&vbuf, &USscratch, &CC->quickroom);
1100 lputuser(&USscratch);
1102 /* post a message in Aide> saying what we just did */
1103 snprintf(bbb, sizeof bbb, "%s %s %s> by %s\n",
1105 ((op == 1) ? "invited to" : "kicked out of"),
1106 CC->quickroom.QRname,
1107 CC->usersupp.fullname);
1110 cprintf("%d %s %s %s.\n",
1112 ((op == 1) ? "invited to" : "kicked out of"),
1113 CC->quickroom.QRname);
1119 * Forget (Zap) the current room (API call)
1120 * Returns 0 on success
1122 int CtdlForgetThisRoom(void) {
1125 /* On some systems, Aides are not allowed to forget rooms */
1126 if (is_aide() && (config.c_aide_zap == 0)
1127 && ((CC->quickroom.QRflags & QR_MAILBOX) == 0) ) {
1131 lgetuser(&CC->usersupp, CC->curr_user);
1132 CtdlGetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
1134 vbuf.v_flags = vbuf.v_flags | V_FORGET;
1135 vbuf.v_flags = vbuf.v_flags & ~V_ACCESS;
1137 CtdlSetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
1138 lputuser(&CC->usersupp);
1140 /* Return to the Lobby, so we don't end up in an undefined room */
1141 usergoto(config.c_baseroom, 0, 0, NULL, NULL);
1148 * forget (Zap) the current room
1153 if (CtdlAccessCheck(ac_logged_in)) {
1157 if (CtdlForgetThisRoom() == 0) {
1158 cprintf("%d Ok\n", CIT_OK);
1161 cprintf("%d You may not forget this room.\n", ERROR);
1166 * Get Next Unregistered User
1170 struct cdbdata *cdbus;
1171 struct usersupp usbuf;
1173 if (CtdlAccessCheck(ac_aide)) {
1177 if ((CitControl.MMflags & MM_VALID) == 0) {
1178 cprintf("%d There are no unvalidated users.\n", CIT_OK);
1182 /* There are unvalidated users. Traverse the usersupp database,
1183 * and return the first user we find that needs validation.
1185 cdb_rewind(CDB_USERSUPP);
1186 while (cdbus = cdb_next_item(CDB_USERSUPP), cdbus != NULL) {
1187 memset(&usbuf, 0, sizeof(struct usersupp));
1188 memcpy(&usbuf, cdbus->ptr,
1189 ((cdbus->len > sizeof(struct usersupp)) ?
1190 sizeof(struct usersupp) : cdbus->len));
1192 if ((usbuf.flags & US_NEEDVALID)
1193 && (usbuf.axlevel > 0)) {
1194 cprintf("%d %s\n", MORE_DATA, usbuf.fullname);
1195 cdb_close_cursor(CDB_USERSUPP);
1200 /* If we get to this point, there are no more unvalidated users.
1201 * Therefore we clear the "users need validation" flag.
1204 begin_critical_section(S_CONTROL);
1206 CitControl.MMflags = CitControl.MMflags & (~MM_VALID);
1208 end_critical_section(S_CONTROL);
1209 cprintf("%d *** End of registration.\n", CIT_OK);
1218 void cmd_vali(char *v_args)
1222 struct usersupp userbuf;
1224 extract(user, v_args, 0);
1225 newax = extract_int(v_args, 1);
1227 if (CtdlAccessCheck(ac_aide)) {
1231 if (lgetuser(&userbuf, user) != 0) {
1232 cprintf("%d '%s' not found.\n", ERROR + NO_SUCH_USER, user);
1236 userbuf.axlevel = newax;
1237 userbuf.flags = (userbuf.flags & ~US_NEEDVALID);
1241 /* If the access level was set to zero, delete the user */
1243 if (purge_user(user) == 0) {
1244 cprintf("%d %s Deleted.\n", CIT_OK, userbuf.fullname);
1248 cprintf("%d User '%s' validated.\n", CIT_OK, userbuf.fullname);
1254 * Traverse the user file...
1256 void ForEachUser(void (*CallBack) (struct usersupp * EachUser, void *out_data),
1259 struct usersupp usbuf;
1260 struct cdbdata *cdbus;
1262 cdb_rewind(CDB_USERSUPP);
1264 while (cdbus = cdb_next_item(CDB_USERSUPP), cdbus != NULL) {
1265 memset(&usbuf, 0, sizeof(struct usersupp));
1266 memcpy(&usbuf, cdbus->ptr,
1267 ((cdbus->len > sizeof(struct usersupp)) ?
1268 sizeof(struct usersupp) : cdbus->len));
1270 (*CallBack) (&usbuf, in_data);
1276 * List one user (this works with cmd_list)
1278 void ListThisUser(struct usersupp *usbuf, void *data)
1280 if (usbuf->axlevel > 0) {
1281 if ((CC->usersupp.axlevel >= 6)
1282 || ((usbuf->flags & US_UNLISTED) == 0)
1283 || ((CC->internal_pgm))) {
1284 cprintf("%s|%d|%ld|%ld|%ld|%ld|",
1288 (long)usbuf->lastcall,
1291 if (CC->usersupp.axlevel >= 6)
1292 cprintf("%s", usbuf->password);
1303 cprintf("%d \n", LISTING_FOLLOWS);
1304 ForEachUser(ListThisUser, NULL);
1312 * assorted info we need to check at login
1320 if (CtdlAccessCheck(ac_logged_in)) {
1324 getuser(&CC->usersupp, CC->curr_user); /* no lock is needed here */
1325 if ((REGISCALL != 0) && ((CC->usersupp.flags & US_REGIS) == 0))
1328 if (CC->usersupp.axlevel >= 6) {
1330 if (CitControl.MMflags & MM_VALID)
1334 /* check for mail */
1335 mail = InitialMailCheck();
1337 cprintf("%d %d|%d|%d|%s|\n", CIT_OK, mail, regis, vali, CC->cs_inet_email);
1342 * check to see if a user exists
1344 void cmd_qusr(char *who)
1346 struct usersupp usbuf;
1348 if (getuser(&usbuf, who) == 0) {
1349 cprintf("%d %s\n", CIT_OK, usbuf.fullname);
1351 cprintf("%d No such user.\n", ERROR + NO_SUCH_USER);
1357 * Administrative Get User Parameters
1359 void cmd_agup(char *cmdbuf)
1361 struct usersupp usbuf;
1362 char requested_user[SIZ];
1364 if (CtdlAccessCheck(ac_aide)) {
1368 extract(requested_user, cmdbuf, 0);
1369 if (getuser(&usbuf, requested_user) != 0) {
1370 cprintf("%d No such user.\n", ERROR + NO_SUCH_USER);
1373 cprintf("%d %s|%s|%u|%ld|%ld|%d|%ld|%ld|%d\n",
1380 (int) usbuf.axlevel,
1382 (long)usbuf.lastcall,
1389 * Administrative Set User Parameters
1391 void cmd_asup(char *cmdbuf)
1393 struct usersupp usbuf;
1394 char requested_user[SIZ];
1400 if (CtdlAccessCheck(ac_aide))
1403 extract(requested_user, cmdbuf, 0);
1404 if (lgetuser(&usbuf, requested_user) != 0) {
1405 cprintf("%d No such user.\n", ERROR + NO_SUCH_USER);
1408 np = num_parms(cmdbuf);
1410 extract(usbuf.password, cmdbuf, 1);
1412 usbuf.flags = extract_int(cmdbuf, 2);
1414 usbuf.timescalled = extract_int(cmdbuf, 3);
1416 usbuf.posted = extract_int(cmdbuf, 4);
1418 newax = extract_int(cmdbuf, 5);
1419 if ((newax >= 0) && (newax <= 6)) {
1420 usbuf.axlevel = extract_int(cmdbuf, 5);
1424 usbuf.lastcall = extract_long(cmdbuf, 7);
1427 usbuf.USuserpurge = extract_int(cmdbuf, 8);
1430 if (usbuf.axlevel == 0) {
1431 if (purge_user(requested_user) == 0) {
1437 sprintf(notify, "User <%s> deleted by %s\n",
1438 usbuf.fullname, CC->usersupp.fullname);
1439 aide_message(notify);
1442 cprintf("%d Ok", CIT_OK);
1444 cprintf(" (%s deleted)", requested_user);
1451 * Check to see if the user who we just sent mail to is logged in. If yes,
1452 * bump the 'new mail' counter for their session. That enables them to
1453 * receive a new mail notification without having to hit the database.
1455 void BumpNewMailCounter(long which_user) {
1456 struct CitContext *ptr;
1458 begin_critical_section(S_SESSION_TABLE);
1460 for (ptr = ContextList; ptr != NULL; ptr = ptr->next) {
1461 if (ptr->usersupp.usernum == which_user) {
1466 end_critical_section(S_SESSION_TABLE);
1471 * Count the number of new mail messages the user has
1475 int num_newmsgs = 0;
1477 num_newmsgs = CC->newmail;
1480 return (num_newmsgs);
1485 * Count the number of new mail messages the user has
1487 int InitialMailCheck()
1489 int num_newmsgs = 0;
1491 char mailboxname[ROOMNAMELEN];
1492 struct quickroom mailbox;
1494 struct cdbdata *cdbfr;
1495 long *msglist = NULL;
1498 MailboxName(mailboxname, sizeof mailboxname, &CC->usersupp, MAILROOM);
1499 if (getroom(&mailbox, mailboxname) != 0)
1501 CtdlGetRelationship(&vbuf, &CC->usersupp, &mailbox);
1503 cdbfr = cdb_fetch(CDB_MSGLISTS, &mailbox.QRnumber, sizeof(long));
1505 if (cdbfr != NULL) {
1506 msglist = mallok(cdbfr->len);
1507 memcpy(msglist, cdbfr->ptr, cdbfr->len);
1508 num_msgs = cdbfr->len / sizeof(long);
1512 for (a = 0; a < num_msgs; ++a) {
1513 if (msglist[a] > 0L) {
1514 if (msglist[a] > vbuf.v_lastseen) {
1519 if (msglist != NULL)
1522 return (num_newmsgs);
1528 * Set the preferred view for the current user/room combination
1530 void cmd_view(char *cmdbuf) {
1534 if (CtdlAccessCheck(ac_logged_in)) {
1538 requested_view = extract_int(cmdbuf, 0);
1540 CtdlGetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
1541 vbuf.v_view = requested_view;
1542 CtdlSetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
1544 cprintf("%d ok\n", CIT_OK);