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"
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[USERNAME_SIZE];
65 char sysuser_name[USERNAME_SIZE];
67 struct cdbdata *cdbus;
68 int using_sysuser = 0;
70 memset(usbuf, 0, sizeof(struct usersupp));
72 #ifdef ENABLE_AUTOLOGIN
73 if (CtdlAssociateSystemUser(sysuser_name, name) == 0) {
79 for (a = 0; a <= strlen(sysuser_name); ++a) {
80 lowercase_name[a] = tolower(sysuser_name[a]);
84 for (a = 0; a <= strlen(name); ++a) {
85 if (a < sizeof(lowercase_name))
86 lowercase_name[a] = tolower(name[a]);
89 lowercase_name[sizeof(lowercase_name) - 1] = 0;
91 cdbus = cdb_fetch(CDB_USERSUPP, lowercase_name, strlen(lowercase_name));
92 if (cdbus == NULL) { /* user not found */
95 memcpy(usbuf, cdbus->ptr,
96 ((cdbus->len > sizeof(struct usersupp)) ?
97 sizeof(struct usersupp) : cdbus->len));
105 * lgetuser() - same as getuser() but locks the record
107 int lgetuser(struct usersupp *usbuf, char *name)
111 retcode = getuser(usbuf, name);
113 begin_critical_section(S_USERSUPP);
120 * putuser() - write user buffer into the correct place on disk
122 void putuser(struct usersupp *usbuf)
124 char lowercase_name[USERNAME_SIZE];
127 for (a = 0; a <= strlen(usbuf->fullname); ++a) {
128 if (a < sizeof(lowercase_name))
129 lowercase_name[a] = tolower(usbuf->fullname[a]);
131 lowercase_name[sizeof(lowercase_name) - 1] = 0;
133 usbuf->version = REV_LEVEL;
134 cdb_store(CDB_USERSUPP,
135 lowercase_name, strlen(lowercase_name),
136 usbuf, sizeof(struct usersupp));
142 * lputuser() - same as putuser() but locks the record
144 void lputuser(struct usersupp *usbuf)
147 end_critical_section(S_USERSUPP);
151 * Index-generating function used by Ctdl[Get|Set]Relationship
153 int GenerateRelationshipIndex(char *IndexBuf,
165 TheIndex.iRoomID = RoomID;
166 TheIndex.iRoomGen = RoomGen;
167 TheIndex.iUserID = UserID;
169 memcpy(IndexBuf, &TheIndex, sizeof(TheIndex));
170 return (sizeof(TheIndex));
176 * Back end for CtdlSetRelationship()
178 void put_visit(struct visit *newvisit)
183 /* Generate an index */
184 IndexLen = GenerateRelationshipIndex(IndexBuf,
187 newvisit->v_usernum);
189 /* Store the record */
190 cdb_store(CDB_VISIT, IndexBuf, IndexLen,
191 newvisit, sizeof(struct visit)
199 * Define a relationship between a user and a room
201 void CtdlSetRelationship(struct visit *newvisit,
202 struct usersupp *rel_user,
203 struct quickroom *rel_room)
207 /* We don't use these in Citadel because they're implicit by the
208 * index, but they must be present if the database is exported.
210 newvisit->v_roomnum = rel_room->QRnumber;
211 newvisit->v_roomgen = rel_room->QRgen;
212 newvisit->v_usernum = rel_user->usernum;
218 * Locate a relationship between a user and a room
220 void CtdlGetRelationship(struct visit *vbuf,
221 struct usersupp *rel_user,
222 struct quickroom *rel_room)
227 struct cdbdata *cdbvisit;
229 /* Generate an index */
230 IndexLen = GenerateRelationshipIndex(IndexBuf,
235 /* Clear out the buffer */
236 memset(vbuf, 0, sizeof(struct visit));
238 cdbvisit = cdb_fetch(CDB_VISIT, IndexBuf, IndexLen);
239 if (cdbvisit != NULL) {
240 memcpy(vbuf, cdbvisit->ptr,
241 ((cdbvisit->len > sizeof(struct visit)) ?
242 sizeof(struct visit) : cdbvisit->len));
246 /* If this is the first time the user has seen this room,
247 * set the view to be the default for the room.
249 vbuf->v_view = rel_room->QRdefaultview;
252 /* Set v_seen if necessary */
253 if (vbuf->v_seen[0] == 0) {
254 snprintf(vbuf->v_seen, sizeof vbuf->v_seen, "*:%ld", vbuf->v_lastseen);
259 void MailboxName(char *buf, size_t n, const struct usersupp *who, const char *prefix)
261 snprintf(buf, n, "%010ld.%s", who->usernum, prefix);
266 * Is the user currently logged in an Aide?
270 if (CC->usersupp.axlevel >= 6)
278 * Is the user currently logged in an Aide *or* the room aide for this room?
280 int is_room_aide(void)
283 if (!CC->logged_in) {
287 if ((CC->usersupp.axlevel >= 6)
288 || (CC->quickroom.QRroomaide == CC->usersupp.usernum)) {
296 * getuserbynumber() - get user by number
297 * returns 0 if user was found
299 * WARNING: don't use this function unless you absolutely have to. It does
300 * a sequential search and therefore is computationally expensive.
302 int getuserbynumber(struct usersupp *usbuf, long int number)
304 struct cdbdata *cdbus;
306 cdb_rewind(CDB_USERSUPP);
308 while (cdbus = cdb_next_item(CDB_USERSUPP), cdbus != NULL) {
309 memset(usbuf, 0, sizeof(struct usersupp));
310 memcpy(usbuf, cdbus->ptr,
311 ((cdbus->len > sizeof(struct usersupp)) ?
312 sizeof(struct usersupp) : cdbus->len));
314 if (usbuf->usernum == number) {
315 cdb_close_cursor(CDB_USERSUPP);
324 * See if we can translate a system login name (i.e. from /etc/passwd)
325 * to a Citadel screen name. Returns 0 if one is found.
327 int CtdlAssociateSystemUser(char *screenname, char *loginname) {
331 p = (struct passwd *) getpwnam(loginname);
333 strcpy(screenname, p->pw_gecos);
334 for (a = 0; a < strlen(screenname); ++a) {
335 if (screenname[a] == ',') {
347 * Back end for cmd_user() and its ilk
349 int CtdlLoginExistingUser(char *trythisname)
354 if (trythisname == NULL) return login_not_found;
355 safestrncpy(username, trythisname, sizeof username);
358 if ((CC->logged_in)) {
359 return login_already_logged_in;
362 found_user = getuser(&CC->usersupp, username);
364 if (found_user == 0) {
365 if (((CC->nologin)) && (CC->usersupp.axlevel < 6)) {
366 return login_too_many_users;
368 strcpy(CC->curr_user, CC->usersupp.fullname);
372 return login_not_found;
380 void cmd_user(char *cmdbuf)
385 extract(username, cmdbuf, 0);
389 a = CtdlLoginExistingUser(username);
391 case login_already_logged_in:
392 cprintf("%d Already logged in.\n", ERROR);
394 case login_too_many_users:
396 "Too many users are already online "
398 ERROR + MAX_SESSIONS_EXCEEDED,
399 config.c_nodename, config.c_maxsessions);
402 cprintf("%d Password required for %s\n",
403 MORE_DATA, CC->curr_user);
405 case login_not_found:
406 cprintf("%d %s not found.\n", ERROR, username);
408 cprintf("%d Internal error\n", ERROR);
415 * session startup code which is common to both cmd_pass() and cmd_newu()
417 void session_startup(void)
421 syslog(LOG_NOTICE, "session %d: user <%s> logged in",
422 CC->cs_pid, CC->curr_user);
424 lgetuser(&CC->usersupp, CC->curr_user);
425 ++(CC->usersupp.timescalled);
426 CC->previous_login = CC->usersupp.lastcall;
427 time(&CC->usersupp.lastcall);
429 /* If this user's name is the name of the system administrator
430 * (as specified in setup), automatically assign access level 6.
432 if (!strcasecmp(CC->usersupp.fullname, config.c_sysadm)) {
433 CC->usersupp.axlevel = 6;
435 lputuser(&CC->usersupp);
438 * Populate CC->cs_inet_email with a default address. This will be
439 * overwritten with the user's directory address, if one exists, when
440 * the vCard module's login hook runs.
442 snprintf(CC->cs_inet_email, sizeof CC->cs_inet_email, "%s@%s",
443 CC->usersupp.fullname, config.c_fqdn);
444 for (i=0; i<strlen(CC->cs_inet_email); ++i) {
445 if (isspace(CC->cs_inet_email[i])) {
446 CC->cs_inet_email[i] = '_';
450 /* Create any personal rooms required by the system.
451 * (Technically, MAILROOM should be there already, but just in case...)
453 create_room(MAILROOM, 4, "", 0, 1, 0);
454 create_room(SENTITEMS, 4, "", 0, 1, 0);
456 /* Run any startup routines registered by loadable modules */
457 PerformSessionHooks(EVT_LOGIN);
459 /* Enter the lobby */
460 usergoto(config.c_baseroom, 0, 0, NULL, NULL);
464 void logged_in_response(void)
466 cprintf("%d %s|%d|%ld|%ld|%u|%ld|%ld\n",
467 CIT_OK, CC->usersupp.fullname, CC->usersupp.axlevel,
468 CC->usersupp.timescalled, CC->usersupp.posted,
469 CC->usersupp.flags, CC->usersupp.usernum,
476 * misc things to be taken care of when a user is logged out
478 void logout(struct CitContext *who)
483 * If there is a download in progress, abort it.
485 if (who->download_fp != NULL) {
486 fclose(who->download_fp);
487 who->download_fp = NULL;
491 * If there is an upload in progress, abort it.
493 if (who->upload_fp != NULL) {
498 * If we were talking to a network node, we're not anymore...
500 if (strlen(who->net_node) > 0) {
501 network_talking_to(who->net_node, NTT_REMOVE);
504 /* Do modular stuff... */
505 PerformSessionHooks(EVT_LOGOUT);
510 * an alternate version of validpw() which executes `chkpwd' instead of
511 * verifying the password directly
513 static int validpw(uid_t uid, const char *pass)
516 int status, pipev[2];
520 lprintf(1, "pipe failed (%s): denying autologin access for "
521 "uid %ld\n", strerror(errno), (long)uid);
524 switch (pid = fork()) {
526 lprintf(1, "fork failed (%s): denying autologin access for "
527 "uid %ld\n", strerror(errno), (long)uid);
534 if (dup2(pipev[0], 0) == -1) {
540 execl(BBSDIR "/chkpwd", BBSDIR "/chkpwd", NULL);
541 perror(BBSDIR "/chkpwd");
547 snprintf(buf, sizeof buf, "%lu\n", (unsigned long) uid));
548 write(pipev[1], pass, strlen(pass));
549 write(pipev[1], "\n", 1);
552 while (waitpid(pid, &status, 0) == -1)
553 if (errno != EINTR) {
554 lprintf(1, "waitpid failed (%s): denying autologin "
555 "access for uid %ld\n",
556 strerror(errno), (long)uid);
559 if (WIFEXITED(status) && !WEXITSTATUS(status))
573 int CtdlTryPassword(char *password)
577 if ((CC->logged_in)) {
578 lprintf(5, "CtdlTryPassword: already logged in\n");
579 return pass_already_logged_in;
581 if (!strcmp(CC->curr_user, NLI)) {
582 lprintf(5, "CtdlTryPassword: no user selected\n");
585 if (getuser(&CC->usersupp, CC->curr_user)) {
586 lprintf(5, "CtdlTryPassword: internal error\n");
587 return pass_internal_error;
589 if (password == NULL) {
590 lprintf(5, "CtdlTryPassword: NULL password string supplied\n");
591 return pass_wrong_password;
596 #ifdef ENABLE_AUTOLOGIN
597 if (CC->usersupp.uid == BBSUID) {
599 strproc(CC->usersupp.password);
600 code = strcasecmp(CC->usersupp.password, password);
603 if (validpw(CC->usersupp.uid, password)) {
605 lgetuser(&CC->usersupp, CC->curr_user);
606 safestrncpy(CC->usersupp.password, password,
607 sizeof CC->usersupp.password);
608 lputuser(&CC->usersupp);
612 #else /* ENABLE_AUTOLOGIN */
614 strproc(CC->usersupp.password);
615 code = strcasecmp(CC->usersupp.password, password);
617 #endif /* ENABLE_AUTOLOGIN */
623 lprintf(3, "Bad password specified for <%s>\n", CC->curr_user);
624 return pass_wrong_password;
629 void cmd_pass(char *buf)
634 extract(password, buf, 0);
635 a = CtdlTryPassword(password);
638 case pass_already_logged_in:
639 cprintf("%d Already logged in.\n", ERROR);
642 cprintf("%d You must send a name with USER first.\n",
645 case pass_wrong_password:
646 cprintf("%d Wrong password.\n", ERROR);
649 logged_in_response();
651 cprintf("%d Can't find user record!\n",
652 ERROR + INTERNAL_ERROR);
659 * Delete a user record *and* all of its related resources.
661 int purge_user(char pname[])
664 struct usersupp usbuf;
665 char lowercase_name[USERNAME_SIZE];
667 struct CitContext *ccptr;
668 int user_is_logged_in = 0;
670 for (a = 0; a <= strlen(pname); ++a) {
671 lowercase_name[a] = tolower(pname[a]);
674 if (getuser(&usbuf, pname) != 0) {
675 lprintf(5, "Cannot purge user <%s> - not found\n", pname);
676 return (ERROR + NO_SUCH_USER);
678 /* Don't delete a user who is currently logged in. Instead, just
679 * set the access level to 0, and let the account get swept up
680 * during the next purge.
682 user_is_logged_in = 0;
683 begin_critical_section(S_SESSION_TABLE);
684 for (ccptr = ContextList; ccptr != NULL; ccptr = ccptr->next) {
685 if (ccptr->usersupp.usernum == usbuf.usernum) {
686 user_is_logged_in = 1;
689 end_critical_section(S_SESSION_TABLE);
690 if (user_is_logged_in == 1) {
691 lprintf(5, "User <%s> is logged in; not deleting.\n", pname);
696 lprintf(5, "Deleting user <%s>\n", pname);
698 /* Perform any purge functions registered by server extensions */
699 PerformUserHooks(usbuf.fullname, usbuf.usernum, EVT_PURGEUSER);
701 /* delete any existing user/room relationships */
702 cdb_delete(CDB_VISIT, &usbuf.usernum, sizeof(long));
704 /* delete the userlog entry */
705 cdb_delete(CDB_USERSUPP, lowercase_name, strlen(lowercase_name));
707 /* remove the user's bio file */
708 snprintf(filename, sizeof filename, "./bio/%ld", usbuf.usernum);
711 /* remove the user's picture */
712 snprintf(filename, sizeof filename, "./userpics/%ld.gif", usbuf.usernum);
720 * create_user() - back end processing to create a new user
722 * Set 'newusername' to the desired account name.
723 * Set 'become_user' to nonzero if this is self-service account creation and we want
724 * to actually log in as the user we just created, otherwise set it to 0.
726 int create_user(char *newusername, int become_user)
728 struct usersupp usbuf;
729 struct quickroom qrbuf;
730 struct passwd *p = NULL;
732 char mailboxname[ROOMNAMELEN];
735 strcpy(username, newusername);
738 #ifdef ENABLE_AUTOLOGIN
739 p = (struct passwd *) getpwnam(username);
741 extract_token(username, p->pw_gecos, 0, ',');
750 if (!getuser(&usbuf, username)) {
751 return (ERROR + ALREADY_EXISTS);
754 /* Go ahead and initialize a new user record */
755 memset(&usbuf, 0, sizeof(struct usersupp));
756 strcpy(usbuf.fullname, username);
757 strcpy(usbuf.password, "");
760 /* These are the default flags on new accounts */
761 usbuf.flags = US_LASTOLD | US_DISAPPEAR | US_PAGINATOR | US_FLOORS;
763 usbuf.timescalled = 0;
765 usbuf.axlevel = config.c_initax;
766 usbuf.USscreenwidth = 80;
767 usbuf.USscreenheight = 24;
768 usbuf.lastcall = time(NULL);
770 /* fetch a new user number */
771 usbuf.usernum = get_new_user_number();
773 /* The very first user created on the system will always be an Aide */
774 if (usbuf.usernum == 1L) {
778 /* add user to userlog */
782 * Give the user a private mailbox and a configuration room.
783 * Make the latter an invisible system room.
785 MailboxName(mailboxname, sizeof mailboxname, &usbuf, MAILROOM);
786 create_room(mailboxname, 5, "", 0, 1, 1);
788 MailboxName(mailboxname, sizeof mailboxname, &usbuf, USERCONFIGROOM);
789 create_room(mailboxname, 5, "", 0, 1, 1);
790 if (lgetroom(&qrbuf, mailboxname) == 0) {
791 qrbuf.QRflags2 |= QR2_SYSTEM;
795 /* Everything below this line can be bypassed if administratively
796 creating a user, instead of doing self-service account creation
800 /* Now become the user we just created */
801 memcpy(&CC->usersupp, &usbuf, sizeof(struct usersupp));
802 strcpy(CC->curr_user, username);
805 /* Check to make sure we're still who we think we are */
806 if (getuser(&CC->usersupp, CC->curr_user)) {
807 return (ERROR + INTERNAL_ERROR);
811 lprintf(3, "New user <%s> created\n", username);
819 * cmd_newu() - create a new user account and log in as that user
821 void cmd_newu(char *cmdbuf)
826 if (config.c_disable_newu) {
827 cprintf("%d Self-service user account creation "
828 "is disabled on this system.\n", ERROR);
833 cprintf("%d Already logged in.\n", ERROR);
837 cprintf("%d %s: Too many users are already online (maximum is %d)\n",
838 ERROR + MAX_SESSIONS_EXCEEDED,
839 config.c_nodename, config.c_maxsessions);
841 extract(username, cmdbuf, 0);
845 if (strlen(username) == 0) {
846 cprintf("%d You must supply a user name.\n", ERROR);
850 if ((!strcasecmp(username, "bbs")) ||
851 (!strcasecmp(username, "new")) ||
852 (!strcasecmp(username, "."))) {
853 cprintf("%d '%s' is an invalid login name.\n", ERROR, username);
857 a = create_user(username, 1);
861 logged_in_response();
862 } else if (a == ERROR + ALREADY_EXISTS) {
863 cprintf("%d '%s' already exists.\n",
864 ERROR + ALREADY_EXISTS, username);
866 } else if (a == ERROR + INTERNAL_ERROR) {
867 cprintf("%d Internal error - user record disappeared?\n",
868 ERROR + INTERNAL_ERROR);
871 cprintf("%d unknown error\n", ERROR);
880 void cmd_setp(char *new_pw)
882 if (CtdlAccessCheck(ac_logged_in)) {
886 if (CC->usersupp.uid != BBSUID) {
887 cprintf("%d Not allowed. Use the 'passwd' command.\n", ERROR);
891 if (strlen(new_pw) == 0) {
892 cprintf("%d Password unchanged.\n", CIT_OK);
895 lgetuser(&CC->usersupp, CC->curr_user);
896 strcpy(CC->usersupp.password, new_pw);
897 lputuser(&CC->usersupp);
898 cprintf("%d Password changed.\n", CIT_OK);
899 lprintf(3, "Password changed for user <%s>\n", CC->curr_user);
900 PerformSessionHooks(EVT_SETPASS);
905 * cmd_creu() - administratively create a new user account (do not log in to it)
907 void cmd_creu(char *cmdbuf)
912 if (CtdlAccessCheck(ac_aide)) {
916 extract(username, cmdbuf, 0);
920 if (strlen(username) == 0) {
921 cprintf("%d You must supply a user name.\n", ERROR);
925 a = create_user(username, 0);
928 cprintf("%d ok\n", CIT_OK);
930 } else if (a == ERROR + ALREADY_EXISTS) {
931 cprintf("%d '%s' already exists.\n",
932 ERROR + ALREADY_EXISTS, username);
935 cprintf("%d An error occured creating the user account.\n", ERROR);
942 * get user parameters
947 if (CtdlAccessCheck(ac_logged_in))
950 getuser(&CC->usersupp, CC->curr_user);
951 cprintf("%d %d|%d|%d|\n",
953 CC->usersupp.USscreenwidth,
954 CC->usersupp.USscreenheight,
955 (CC->usersupp.flags & US_USER_SET)
960 * set user parameters
962 void cmd_setu(char *new_parms)
964 if (CtdlAccessCheck(ac_logged_in))
967 if (num_parms(new_parms) < 3) {
968 cprintf("%d Usage error.\n", ERROR);
971 lgetuser(&CC->usersupp, CC->curr_user);
972 CC->usersupp.USscreenwidth = extract_int(new_parms, 0);
973 CC->usersupp.USscreenheight = extract_int(new_parms, 1);
974 CC->usersupp.flags = CC->usersupp.flags & (~US_USER_SET);
975 CC->usersupp.flags = CC->usersupp.flags |
976 (extract_int(new_parms, 2) & US_USER_SET);
978 lputuser(&CC->usersupp);
979 cprintf("%d Ok\n", CIT_OK);
983 * set last read pointer
985 void cmd_slrp(char *new_ptr)
990 if (CtdlAccessCheck(ac_logged_in)) {
994 if (!strncasecmp(new_ptr, "highest", 7)) {
995 newlr = CC->quickroom.QRhighest;
997 newlr = atol(new_ptr);
1000 lgetuser(&CC->usersupp, CC->curr_user);
1002 CtdlGetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
1003 vbuf.v_lastseen = newlr;
1004 snprintf(vbuf.v_seen, sizeof vbuf.v_seen, "*:%ld", newlr);
1005 CtdlSetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
1007 lputuser(&CC->usersupp);
1008 cprintf("%d %ld\n", CIT_OK, newlr);
1012 void cmd_seen(char *argbuf) {
1013 long target_msgnum = 0L;
1014 int target_setting = 0;
1016 if (CtdlAccessCheck(ac_logged_in)) {
1020 if (num_parms(argbuf) != 2) {
1021 cprintf("%d Invalid parameters\n", ERROR);
1025 target_msgnum = extract_long(argbuf, 0);
1026 target_setting = extract_int(argbuf, 1);
1028 CtdlSetSeen(target_msgnum, target_setting);
1029 cprintf("%d OK\n", CIT_OK);
1033 void cmd_gtsn(char *argbuf) {
1036 if (CtdlAccessCheck(ac_logged_in)) {
1041 cprintf("%d %s\n", CIT_OK, buf);
1047 * INVT and KICK commands
1049 void cmd_invt_kick(char *iuser, int op)
1051 { /* 1 = invite, 0 = kick out */
1052 struct usersupp USscratch;
1057 * These commands are only allowed by aides, room aides,
1058 * and room namespace owners
1061 || (atol(CC->quickroom.QRname) == CC->usersupp.usernum) ) {
1062 /* access granted */
1065 cprintf("%d Higher access or room ownership required.\n",
1066 ERROR + HIGHER_ACCESS_REQUIRED);
1070 if (!strncasecmp(CC->quickroom.QRname, config.c_baseroom,
1072 cprintf("%d Can't add/remove users from this room.\n",
1077 if (lgetuser(&USscratch, iuser) != 0) {
1078 cprintf("%d No such user.\n", ERROR);
1081 CtdlGetRelationship(&vbuf, &USscratch, &CC->quickroom);
1084 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
1085 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
1088 vbuf.v_flags = vbuf.v_flags & ~V_ACCESS;
1089 vbuf.v_flags = vbuf.v_flags | V_FORGET | V_LOCKOUT;
1091 CtdlSetRelationship(&vbuf, &USscratch, &CC->quickroom);
1093 lputuser(&USscratch);
1095 /* post a message in Aide> saying what we just did */
1096 snprintf(bbb, sizeof bbb, "%s %s %s> by %s\n",
1098 ((op == 1) ? "invited to" : "kicked out of"),
1099 CC->quickroom.QRname,
1100 CC->usersupp.fullname);
1103 cprintf("%d %s %s %s.\n",
1105 ((op == 1) ? "invited to" : "kicked out of"),
1106 CC->quickroom.QRname);
1112 * Forget (Zap) the current room (API call)
1113 * Returns 0 on success
1115 int CtdlForgetThisRoom(void) {
1118 /* On some systems, Aides are not allowed to forget rooms */
1119 if (is_aide() && (config.c_aide_zap == 0)
1120 && ((CC->quickroom.QRflags & QR_MAILBOX) == 0) ) {
1124 lgetuser(&CC->usersupp, CC->curr_user);
1125 CtdlGetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
1127 vbuf.v_flags = vbuf.v_flags | V_FORGET;
1128 vbuf.v_flags = vbuf.v_flags & ~V_ACCESS;
1130 CtdlSetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
1131 lputuser(&CC->usersupp);
1133 /* Return to the Lobby, so we don't end up in an undefined room */
1134 usergoto(config.c_baseroom, 0, 0, NULL, NULL);
1141 * forget (Zap) the current room
1146 if (CtdlAccessCheck(ac_logged_in)) {
1150 if (CtdlForgetThisRoom() == 0) {
1151 cprintf("%d Ok\n", CIT_OK);
1154 cprintf("%d You may not forget this room.\n", ERROR);
1159 * Get Next Unregistered User
1163 struct cdbdata *cdbus;
1164 struct usersupp usbuf;
1166 if (CtdlAccessCheck(ac_aide)) {
1170 if ((CitControl.MMflags & MM_VALID) == 0) {
1171 cprintf("%d There are no unvalidated users.\n", CIT_OK);
1175 /* There are unvalidated users. Traverse the usersupp database,
1176 * and return the first user we find that needs validation.
1178 cdb_rewind(CDB_USERSUPP);
1179 while (cdbus = cdb_next_item(CDB_USERSUPP), cdbus != NULL) {
1180 memset(&usbuf, 0, sizeof(struct usersupp));
1181 memcpy(&usbuf, cdbus->ptr,
1182 ((cdbus->len > sizeof(struct usersupp)) ?
1183 sizeof(struct usersupp) : cdbus->len));
1185 if ((usbuf.flags & US_NEEDVALID)
1186 && (usbuf.axlevel > 0)) {
1187 cprintf("%d %s\n", MORE_DATA, usbuf.fullname);
1188 cdb_close_cursor(CDB_USERSUPP);
1193 /* If we get to this point, there are no more unvalidated users.
1194 * Therefore we clear the "users need validation" flag.
1197 begin_critical_section(S_CONTROL);
1199 CitControl.MMflags = CitControl.MMflags & (~MM_VALID);
1201 end_critical_section(S_CONTROL);
1202 cprintf("%d *** End of registration.\n", CIT_OK);
1211 void cmd_vali(char *v_args)
1215 struct usersupp userbuf;
1217 extract(user, v_args, 0);
1218 newax = extract_int(v_args, 1);
1220 if (CtdlAccessCheck(ac_aide)) {
1224 if (lgetuser(&userbuf, user) != 0) {
1225 cprintf("%d '%s' not found.\n", ERROR + NO_SUCH_USER, user);
1229 userbuf.axlevel = newax;
1230 userbuf.flags = (userbuf.flags & ~US_NEEDVALID);
1234 /* If the access level was set to zero, delete the user */
1236 if (purge_user(user) == 0) {
1237 cprintf("%d %s Deleted.\n", CIT_OK, userbuf.fullname);
1241 cprintf("%d User '%s' validated.\n", CIT_OK, userbuf.fullname);
1247 * Traverse the user file...
1249 void ForEachUser(void (*CallBack) (struct usersupp * EachUser, void *out_data),
1252 struct usersupp usbuf;
1253 struct cdbdata *cdbus;
1255 cdb_rewind(CDB_USERSUPP);
1257 while (cdbus = cdb_next_item(CDB_USERSUPP), cdbus != NULL) {
1258 memset(&usbuf, 0, sizeof(struct usersupp));
1259 memcpy(&usbuf, cdbus->ptr,
1260 ((cdbus->len > sizeof(struct usersupp)) ?
1261 sizeof(struct usersupp) : cdbus->len));
1263 (*CallBack) (&usbuf, in_data);
1269 * List one user (this works with cmd_list)
1271 void ListThisUser(struct usersupp *usbuf, void *data)
1273 if (usbuf->axlevel > 0) {
1274 if ((CC->usersupp.axlevel >= 6)
1275 || ((usbuf->flags & US_UNLISTED) == 0)
1276 || ((CC->internal_pgm))) {
1277 cprintf("%s|%d|%ld|%ld|%ld|%ld|",
1281 (long)usbuf->lastcall,
1284 if (CC->usersupp.axlevel >= 6)
1285 cprintf("%s", usbuf->password);
1296 cprintf("%d \n", LISTING_FOLLOWS);
1297 ForEachUser(ListThisUser, NULL);
1305 * assorted info we need to check at login
1313 if (CtdlAccessCheck(ac_logged_in)) {
1317 getuser(&CC->usersupp, CC->curr_user); /* no lock is needed here */
1318 if ((REGISCALL != 0) && ((CC->usersupp.flags & US_REGIS) == 0))
1321 if (CC->usersupp.axlevel >= 6) {
1323 if (CitControl.MMflags & MM_VALID)
1327 /* check for mail */
1328 mail = InitialMailCheck();
1330 cprintf("%d %d|%d|%d|%s|\n", CIT_OK, mail, regis, vali, CC->cs_inet_email);
1335 * check to see if a user exists
1337 void cmd_qusr(char *who)
1339 struct usersupp usbuf;
1341 if (getuser(&usbuf, who) == 0) {
1342 cprintf("%d %s\n", CIT_OK, usbuf.fullname);
1344 cprintf("%d No such user.\n", ERROR + NO_SUCH_USER);
1350 * Administrative Get User Parameters
1352 void cmd_agup(char *cmdbuf)
1354 struct usersupp usbuf;
1355 char requested_user[SIZ];
1357 if (CtdlAccessCheck(ac_aide)) {
1361 extract(requested_user, cmdbuf, 0);
1362 if (getuser(&usbuf, requested_user) != 0) {
1363 cprintf("%d No such user.\n", ERROR + NO_SUCH_USER);
1366 cprintf("%d %s|%s|%u|%ld|%ld|%d|%ld|%ld|%d\n",
1373 (int) usbuf.axlevel,
1375 (long)usbuf.lastcall,
1382 * Administrative Set User Parameters
1384 void cmd_asup(char *cmdbuf)
1386 struct usersupp usbuf;
1387 char requested_user[SIZ];
1393 if (CtdlAccessCheck(ac_aide))
1396 extract(requested_user, cmdbuf, 0);
1397 if (lgetuser(&usbuf, requested_user) != 0) {
1398 cprintf("%d No such user.\n", ERROR + NO_SUCH_USER);
1401 np = num_parms(cmdbuf);
1403 extract(usbuf.password, cmdbuf, 1);
1405 usbuf.flags = extract_int(cmdbuf, 2);
1407 usbuf.timescalled = extract_int(cmdbuf, 3);
1409 usbuf.posted = extract_int(cmdbuf, 4);
1411 newax = extract_int(cmdbuf, 5);
1412 if ((newax >= 0) && (newax <= 6)) {
1413 usbuf.axlevel = extract_int(cmdbuf, 5);
1417 usbuf.lastcall = extract_long(cmdbuf, 7);
1420 usbuf.USuserpurge = extract_int(cmdbuf, 8);
1423 if (usbuf.axlevel == 0) {
1424 if (purge_user(requested_user) == 0) {
1430 sprintf(notify, "User <%s> deleted by %s\n",
1431 usbuf.fullname, CC->usersupp.fullname);
1432 aide_message(notify);
1435 cprintf("%d Ok", CIT_OK);
1437 cprintf(" (%s deleted)", requested_user);
1444 * Check to see if the user who we just sent mail to is logged in. If yes,
1445 * bump the 'new mail' counter for their session. That enables them to
1446 * receive a new mail notification without having to hit the database.
1448 void BumpNewMailCounter(long which_user) {
1449 struct CitContext *ptr;
1451 begin_critical_section(S_SESSION_TABLE);
1453 for (ptr = ContextList; ptr != NULL; ptr = ptr->next) {
1454 if (ptr->usersupp.usernum == which_user) {
1459 end_critical_section(S_SESSION_TABLE);
1464 * Count the number of new mail messages the user has
1468 int num_newmsgs = 0;
1470 num_newmsgs = CC->newmail;
1473 return (num_newmsgs);
1478 * Count the number of new mail messages the user has
1480 int InitialMailCheck()
1482 int num_newmsgs = 0;
1484 char mailboxname[ROOMNAMELEN];
1485 struct quickroom mailbox;
1487 struct cdbdata *cdbfr;
1488 long *msglist = NULL;
1491 MailboxName(mailboxname, sizeof mailboxname, &CC->usersupp, MAILROOM);
1492 if (getroom(&mailbox, mailboxname) != 0)
1494 CtdlGetRelationship(&vbuf, &CC->usersupp, &mailbox);
1496 cdbfr = cdb_fetch(CDB_MSGLISTS, &mailbox.QRnumber, sizeof(long));
1498 if (cdbfr != NULL) {
1499 msglist = mallok(cdbfr->len);
1500 memcpy(msglist, cdbfr->ptr, cdbfr->len);
1501 num_msgs = cdbfr->len / sizeof(long);
1505 for (a = 0; a < num_msgs; ++a) {
1506 if (msglist[a] > 0L) {
1507 if (msglist[a] > vbuf.v_lastseen) {
1512 if (msglist != NULL)
1515 return (num_newmsgs);
1521 * Set the preferred view for the current user/room combination
1523 void cmd_view(char *cmdbuf) {
1527 if (CtdlAccessCheck(ac_logged_in)) {
1531 requested_view = extract_int(cmdbuf, 0);
1533 CtdlGetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
1534 vbuf.v_view = requested_view;
1535 CtdlSetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
1537 cprintf("%d ok\n", CIT_OK);