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 /* Set v_seen if necessary */
234 if (vbuf->v_seen[0] == 0) {
235 snprintf(vbuf->v_seen, sizeof vbuf->v_seen, "*:%ld", vbuf->v_lastseen);
240 void MailboxName(char *buf, size_t n, const struct usersupp *who, const char *prefix)
242 snprintf(buf, n, "%010ld.%s", who->usernum, prefix);
247 * Is the user currently logged in an Aide?
251 if (CC->usersupp.axlevel >= 6)
259 * Is the user currently logged in an Aide *or* the room aide for this room?
261 int is_room_aide(void)
264 if (!CC->logged_in) {
268 if ((CC->usersupp.axlevel >= 6)
269 || (CC->quickroom.QRroomaide == CC->usersupp.usernum)) {
277 * getuserbynumber() - get user by number
278 * returns 0 if user was found
280 * WARNING: don't use this function unless you absolutely have to. It does
281 * a sequential search and therefore is computationally expensive.
283 int getuserbynumber(struct usersupp *usbuf, long int number)
285 struct cdbdata *cdbus;
287 cdb_rewind(CDB_USERSUPP);
289 while (cdbus = cdb_next_item(CDB_USERSUPP), cdbus != NULL) {
290 memset(usbuf, 0, sizeof(struct usersupp));
291 memcpy(usbuf, cdbus->ptr,
292 ((cdbus->len > sizeof(struct usersupp)) ?
293 sizeof(struct usersupp) : cdbus->len));
295 if (usbuf->usernum == number) {
296 cdb_close_cursor(CDB_USERSUPP);
305 * Back end for cmd_user() and its ilk
307 int CtdlLoginExistingUser(char *trythisname)
315 if (trythisname == NULL) return login_not_found;
316 safestrncpy(username, trythisname, sizeof username);
319 if ((CC->logged_in)) {
320 return login_already_logged_in;
322 found_user = getuser(&CC->usersupp, username);
323 if (found_user != 0) {
324 p = (struct passwd *) getpwnam(username);
326 strcpy(autoname, p->pw_gecos);
327 for (a = 0; a < strlen(autoname); ++a)
328 if (autoname[a] == ',')
330 found_user = getuser(&CC->usersupp, autoname);
333 if (found_user == 0) {
334 if (((CC->nologin)) && (CC->usersupp.axlevel < 6)) {
335 return login_too_many_users;
337 strcpy(CC->curr_user, CC->usersupp.fullname);
341 return login_not_found;
349 void cmd_user(char *cmdbuf)
354 extract(username, cmdbuf, 0);
358 a = CtdlLoginExistingUser(username);
360 case login_already_logged_in:
361 cprintf("%d Already logged in.\n", ERROR);
363 case login_too_many_users:
365 "Too many users are already online "
367 ERROR + MAX_SESSIONS_EXCEEDED,
368 config.c_nodename, config.c_maxsessions);
371 cprintf("%d Password required for %s\n",
372 MORE_DATA, CC->curr_user);
374 case login_not_found:
375 cprintf("%d %s not found.\n", ERROR, username);
377 cprintf("%d Internal error\n", ERROR);
384 * session startup code which is common to both cmd_pass() and cmd_newu()
386 void session_startup(void)
388 syslog(LOG_NOTICE, "session %d: user <%s> logged in",
389 CC->cs_pid, CC->curr_user);
391 lgetuser(&CC->usersupp, CC->curr_user);
392 ++(CC->usersupp.timescalled);
393 time(&CC->usersupp.lastcall);
395 /* If this user's name is the name of the system administrator
396 * (as specified in setup), automatically assign access level 6.
398 if (!strcasecmp(CC->usersupp.fullname, config.c_sysadm)) {
399 CC->usersupp.axlevel = 6;
401 lputuser(&CC->usersupp);
403 /* Run any startup routines registered by loadable modules */
404 PerformSessionHooks(EVT_LOGIN);
406 /* Create any personal rooms required by the system */
407 create_room(SENTITEMS, 4, "", 0, 1);
409 /* Enter the lobby */
410 usergoto(BASEROOM, 0, NULL, NULL);
412 /* Record this login in the Citadel log */
413 rec_log(CL_LOGIN, CC->curr_user);
417 void logged_in_response(void)
419 cprintf("%d %s|%d|%ld|%ld|%u|%ld|%ld\n",
420 CIT_OK, CC->usersupp.fullname, CC->usersupp.axlevel,
421 CC->usersupp.timescalled, CC->usersupp.posted,
422 CC->usersupp.flags, CC->usersupp.usernum,
423 CC->usersupp.lastcall);
429 * misc things to be taken care of when a user is logged out
431 void logout(struct CitContext *who)
436 * If there is a download in progress, abort it.
438 if (who->download_fp != NULL) {
439 fclose(who->download_fp);
440 who->download_fp = NULL;
444 * If there is an upload in progress, abort it.
446 if (who->upload_fp != NULL) {
451 * If we were talking to a network node, we're not anymore...
453 if (strlen(who->net_node) > 0) {
454 network_talking_to(who->net_node, NTT_REMOVE);
458 * Yes, we really need to free EVERY LAST BYTE we allocated.
460 if (who->cs_inet_email != NULL) {
461 phree(who->cs_inet_email);
462 who->cs_inet_email = NULL;
465 /* Do modular stuff... */
466 PerformSessionHooks(EVT_LOGOUT);
471 * an alternate version of validpw() which executes `chkpwd' instead of
472 * verifying the password directly
474 static int validpw(uid_t uid, const char *pass)
477 int status, pipev[2];
481 lprintf(1, "pipe failed (%s): denying autologin access for "
482 "uid %ld\n", strerror(errno), (long)uid);
485 switch (pid = fork()) {
487 lprintf(1, "fork failed (%s): denying autologin access for "
488 "uid %ld\n", strerror(errno), (long)uid);
495 if (dup2(pipev[0], 0) == -1) {
501 execl(BBSDIR "/chkpwd", BBSDIR "/chkpwd", NULL);
502 perror(BBSDIR "/chkpwd");
508 snprintf(buf, sizeof buf, "%lu\n", (unsigned long) uid));
509 write(pipev[1], pass, strlen(pass));
510 write(pipev[1], "\n", 1);
513 while (waitpid(pid, &status, 0) == -1)
514 if (errno != EINTR) {
515 lprintf(1, "waitpid failed (%s): denying autologin "
516 "access for uid %ld\n",
517 strerror(errno), (long)uid);
520 if (WIFEXITED(status) && !WEXITSTATUS(status))
534 int CtdlTryPassword(char *password)
538 if ((CC->logged_in)) {
539 lprintf(5, "CtdlTryPassword: already logged in\n");
540 return pass_already_logged_in;
542 if (!strcmp(CC->curr_user, NLI)) {
543 lprintf(5, "CtdlTryPassword: no user selected\n");
546 if (getuser(&CC->usersupp, CC->curr_user)) {
547 lprintf(5, "CtdlTryPassword: internal error\n");
548 return pass_internal_error;
550 if (password == NULL) {
551 lprintf(5, "CtdlTryPassword: NULL password string supplied\n");
552 return pass_wrong_password;
555 if (CC->usersupp.uid == BBSUID) {
557 strproc(CC->usersupp.password);
558 code = strcasecmp(CC->usersupp.password, password);
560 #ifdef ENABLE_AUTOLOGIN
562 if (validpw(CC->usersupp.uid, password)) {
564 lgetuser(&CC->usersupp, CC->curr_user);
565 safestrncpy(CC->usersupp.password, password,
566 sizeof CC->usersupp.password);
567 lputuser(&CC->usersupp);
576 rec_log(CL_BADPW, CC->curr_user);
577 return pass_wrong_password;
582 void cmd_pass(char *buf)
587 extract(password, buf, 0);
588 a = CtdlTryPassword(password);
591 case pass_already_logged_in:
592 cprintf("%d Already logged in.\n", ERROR);
595 cprintf("%d You must send a name with USER first.\n",
598 case pass_wrong_password:
599 cprintf("%d Wrong password.\n", ERROR);
602 logged_in_response();
604 cprintf("%d Can't find user record!\n",
605 ERROR + INTERNAL_ERROR);
612 * Delete a user record *and* all of its related resources.
614 int purge_user(char pname[])
617 struct usersupp usbuf;
618 char lowercase_name[32];
620 struct CitContext *ccptr;
621 int user_is_logged_in = 0;
623 for (a = 0; a <= strlen(pname); ++a) {
624 lowercase_name[a] = tolower(pname[a]);
627 if (getuser(&usbuf, pname) != 0) {
628 lprintf(5, "Cannot purge user <%s> - not found\n", pname);
629 return (ERROR + NO_SUCH_USER);
631 /* Don't delete a user who is currently logged in. Instead, just
632 * set the access level to 0, and let the account get swept up
633 * during the next purge.
635 user_is_logged_in = 0;
636 begin_critical_section(S_SESSION_TABLE);
637 for (ccptr = ContextList; ccptr != NULL; ccptr = ccptr->next) {
638 if (ccptr->usersupp.usernum == usbuf.usernum) {
639 user_is_logged_in = 1;
642 end_critical_section(S_SESSION_TABLE);
643 if (user_is_logged_in == 1) {
644 lprintf(5, "User <%s> is logged in; not deleting.\n", pname);
649 lprintf(5, "Deleting user <%s>\n", pname);
651 /* Perform any purge functions registered by server extensions */
652 PerformUserHooks(usbuf.fullname, usbuf.usernum, EVT_PURGEUSER);
654 /* delete any existing user/room relationships */
655 cdb_delete(CDB_VISIT, &usbuf.usernum, sizeof(long));
657 /* delete the userlog entry */
658 cdb_delete(CDB_USERSUPP, lowercase_name, strlen(lowercase_name));
660 /* remove the user's bio file */
661 snprintf(filename, sizeof filename, "./bio/%ld", usbuf.usernum);
664 /* remove the user's picture */
665 snprintf(filename, sizeof filename, "./userpics/%ld.gif", usbuf.usernum);
673 * create_user() - back end processing to create a new user
675 * Set 'newusername' to the desired account name.
676 * Set 'become_user' to nonzero if this is self-service account creation and we want
677 * to actually log in as the user we just created, otherwise set it to 0.
679 int create_user(char *newusername, int become_user)
681 struct usersupp usbuf;
682 struct passwd *p = NULL;
684 char mailboxname[ROOMNAMELEN];
687 strcpy(username, newusername);
690 #ifdef ENABLE_AUTOLOGIN
691 p = (struct passwd *) getpwnam(username);
694 extract_token(username, p->pw_gecos, 0, ',');
700 if (!getuser(&usbuf, username)) {
701 return (ERROR + ALREADY_EXISTS);
704 /* Go ahead and initialize a new user record */
705 memset(&usbuf, 0, sizeof(struct usersupp));
706 strcpy(usbuf.fullname, username);
707 strcpy(usbuf.password, "");
710 /* These are the default flags on new accounts */
711 usbuf.flags = US_LASTOLD | US_DISAPPEAR | US_PAGINATOR | US_FLOORS;
713 usbuf.timescalled = 0;
715 usbuf.axlevel = config.c_initax;
716 usbuf.USscreenwidth = 80;
717 usbuf.USscreenheight = 24;
718 usbuf.lastcall = time(NULL);
719 usbuf.moderation_filter = config.c_default_filter;
721 /* fetch a new user number */
722 usbuf.usernum = get_new_user_number();
724 /* The very first user created on the system will always be an Aide */
725 if (usbuf.usernum == 1L) {
729 /* add user to userlog */
732 /* give the user a private mailbox and a configuration room */
733 MailboxName(mailboxname, sizeof mailboxname, &usbuf, MAILROOM);
734 create_room(mailboxname, 5, "", 0, 1);
735 MailboxName(mailboxname, sizeof mailboxname, &usbuf, USERCONFIGROOM);
736 create_room(mailboxname, 5, "", 0, 1);
738 /* Everything below this line can be bypassed if administratively
739 creating a user, instead of doing self-service account creation
743 /* Now become the user we just created */
744 memcpy(&CC->usersupp, &usbuf, sizeof(struct usersupp));
745 strcpy(CC->curr_user, username);
748 /* Check to make sure we're still who we think we are */
749 if (getuser(&CC->usersupp, CC->curr_user)) {
750 return (ERROR + INTERNAL_ERROR);
753 rec_log(CL_NEWUSER, CC->curr_user);
763 * cmd_newu() - create a new user account and log in as that user
765 void cmd_newu(char *cmdbuf)
770 if (config.c_disable_newu) {
771 cprintf("%d Self-service user account creation "
772 "is disabled on this system.\n", ERROR);
777 cprintf("%d Already logged in.\n", ERROR);
781 cprintf("%d %s: Too many users are already online (maximum is %d)\n",
782 ERROR + MAX_SESSIONS_EXCEEDED,
783 config.c_nodename, config.c_maxsessions);
785 extract(username, cmdbuf, 0);
789 if (strlen(username) == 0) {
790 cprintf("%d You must supply a user name.\n", ERROR);
794 if ((!strcasecmp(username, "bbs")) ||
795 (!strcasecmp(username, "new")) ||
796 (!strcasecmp(username, "."))) {
797 cprintf("%d '%s' is an invalid login name.\n", ERROR, username);
801 a = create_user(username, 1);
805 logged_in_response();
806 } else if (a == ERROR + ALREADY_EXISTS) {
807 cprintf("%d '%s' already exists.\n",
808 ERROR + ALREADY_EXISTS, username);
810 } else if (a == ERROR + INTERNAL_ERROR) {
811 cprintf("%d Internal error - user record disappeared?\n",
812 ERROR + INTERNAL_ERROR);
815 cprintf("%d unknown error\n", ERROR);
817 rec_log(CL_NEWUSER, CC->curr_user);
825 void cmd_setp(char *new_pw)
827 if (CtdlAccessCheck(ac_logged_in)) {
831 if (CC->usersupp.uid != BBSUID) {
832 cprintf("%d Not allowed. Use the 'passwd' command.\n", ERROR);
836 if (strlen(new_pw) == 0) {
837 cprintf("%d Password unchanged.\n", CIT_OK);
840 lgetuser(&CC->usersupp, CC->curr_user);
841 strcpy(CC->usersupp.password, new_pw);
842 lputuser(&CC->usersupp);
843 cprintf("%d Password changed.\n", CIT_OK);
844 rec_log(CL_PWCHANGE, CC->curr_user);
845 PerformSessionHooks(EVT_SETPASS);
850 * cmd_creu() - administratively create a new user account (do not log in to it)
852 void cmd_creu(char *cmdbuf)
857 if (CtdlAccessCheck(ac_aide)) {
861 extract(username, cmdbuf, 0);
865 if (strlen(username) == 0) {
866 cprintf("%d You must supply a user name.\n", ERROR);
870 a = create_user(username, 0);
873 cprintf("%d ok\n", CIT_OK);
875 } else if (a == ERROR + ALREADY_EXISTS) {
876 cprintf("%d '%s' already exists.\n",
877 ERROR + ALREADY_EXISTS, username);
880 cprintf("%d An error occured creating the user account.\n", ERROR);
882 rec_log(CL_NEWUSER, username);
888 * get user parameters
893 if (CtdlAccessCheck(ac_logged_in))
896 getuser(&CC->usersupp, CC->curr_user);
897 cprintf("%d %d|%d|%d|%d\n",
899 CC->usersupp.USscreenwidth,
900 CC->usersupp.USscreenheight,
901 (CC->usersupp.flags & US_USER_SET),
902 CC->usersupp.moderation_filter
907 * set user parameters
909 void cmd_setu(char *new_parms)
913 if (CtdlAccessCheck(ac_logged_in))
916 if (num_parms(new_parms) < 3) {
917 cprintf("%d Usage error.\n", ERROR);
920 lgetuser(&CC->usersupp, CC->curr_user);
921 CC->usersupp.USscreenwidth = extract_int(new_parms, 0);
922 CC->usersupp.USscreenheight = extract_int(new_parms, 1);
923 CC->usersupp.flags = CC->usersupp.flags & (~US_USER_SET);
924 CC->usersupp.flags = CC->usersupp.flags |
925 (extract_int(new_parms, 2) & US_USER_SET);
927 if (num_parms(new_parms) >= 4) {
928 new_mod = extract_int(new_parms, 3);
929 lprintf(9, "new_mod extracted to %d\n", new_mod);
931 /* Aides cannot set the filter level lower than -100 */
932 if (new_mod < (-100))
935 /* Normal users cannot set the filter level lower than -63 */
936 if ((new_mod < (-63)) && (CC->usersupp.axlevel < 6))
939 /* Nobody can set the filter level higher than +63 */
943 CC->usersupp.moderation_filter = new_mod;
944 lprintf(9, "new_mod processed to %d\n", new_mod);
946 lputuser(&CC->usersupp);
947 cprintf("%d Ok\n", CIT_OK);
951 * set last read pointer
953 void cmd_slrp(char *new_ptr)
958 if (CtdlAccessCheck(ac_logged_in)) {
962 if (!strncasecmp(new_ptr, "highest", 7)) {
963 newlr = CC->quickroom.QRhighest;
965 newlr = atol(new_ptr);
968 lgetuser(&CC->usersupp, CC->curr_user);
970 CtdlGetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
971 vbuf.v_lastseen = newlr;
972 snprintf(vbuf.v_seen, sizeof vbuf.v_seen, "*:%ld", newlr);
973 CtdlSetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
975 lputuser(&CC->usersupp);
976 cprintf("%d %ld\n", CIT_OK, newlr);
980 void cmd_seen(char *argbuf) {
981 long target_msgnum = 0L;
982 int target_setting = 0;
984 if (CtdlAccessCheck(ac_logged_in)) {
988 if (num_parms(argbuf) != 2) {
989 cprintf("%d Invalid parameters\n", ERROR);
993 target_msgnum = extract_long(argbuf, 0);
994 target_setting = extract_int(argbuf, 1);
996 CtdlSetSeen(target_msgnum, target_setting);
997 cprintf("%d OK\n", CIT_OK);
1002 * INVT and KICK commands
1004 void cmd_invt_kick(char *iuser, int op)
1006 { /* 1 = invite, 0 = kick out */
1007 struct usersupp USscratch;
1012 * These commands are only allowed by aides, room aides,
1013 * and room namespace owners
1016 || (atol(CC->quickroom.QRname) == CC->usersupp.usernum) ) {
1017 /* access granted */
1021 cprintf("%d Higher access or room ownership required.\n",
1022 ERROR + HIGHER_ACCESS_REQUIRED);
1026 if (lgetuser(&USscratch, iuser) != 0) {
1027 cprintf("%d No such user.\n", ERROR);
1030 CtdlGetRelationship(&vbuf, &USscratch, &CC->quickroom);
1033 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
1034 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
1037 vbuf.v_flags = vbuf.v_flags & ~V_ACCESS;
1038 vbuf.v_flags = vbuf.v_flags | V_FORGET | V_LOCKOUT;
1040 CtdlSetRelationship(&vbuf, &USscratch, &CC->quickroom);
1042 lputuser(&USscratch);
1044 /* post a message in Aide> saying what we just did */
1045 snprintf(bbb, sizeof bbb, "%s %s %s> by %s\n",
1047 ((op == 1) ? "invited to" : "kicked out of"),
1048 CC->quickroom.QRname,
1049 CC->usersupp.fullname);
1052 cprintf("%d %s %s %s.\n",
1054 ((op == 1) ? "invited to" : "kicked out of"),
1055 CC->quickroom.QRname);
1061 * Forget (Zap) the current room (API call)
1062 * Returns 0 on success
1064 int CtdlForgetThisRoom(void) {
1067 /* On some systems, Aides are not allowed to forget rooms */
1068 if (is_aide() && (config.c_aide_zap == 0)
1069 && ((CC->quickroom.QRflags & QR_MAILBOX) == 0) ) {
1073 lgetuser(&CC->usersupp, CC->curr_user);
1074 CtdlGetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
1076 vbuf.v_flags = vbuf.v_flags | V_FORGET;
1077 vbuf.v_flags = vbuf.v_flags & ~V_ACCESS;
1079 CtdlSetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
1080 lputuser(&CC->usersupp);
1082 /* Return to the Lobby, so we don't end up in an undefined room */
1083 usergoto(BASEROOM, 0, NULL, NULL);
1090 * forget (Zap) the current room
1095 if (CtdlAccessCheck(ac_logged_in)) {
1099 if (CtdlForgetThisRoom() == 0) {
1100 cprintf("%d Ok\n", CIT_OK);
1103 cprintf("%d You may not forget this room.\n", ERROR);
1108 * Get Next Unregistered User
1112 struct cdbdata *cdbus;
1113 struct usersupp usbuf;
1115 if (CtdlAccessCheck(ac_aide)) {
1119 if ((CitControl.MMflags & MM_VALID) == 0) {
1120 cprintf("%d There are no unvalidated users.\n", CIT_OK);
1124 /* There are unvalidated users. Traverse the usersupp database,
1125 * and return the first user we find that needs validation.
1127 cdb_rewind(CDB_USERSUPP);
1128 while (cdbus = cdb_next_item(CDB_USERSUPP), cdbus != NULL) {
1129 memset(&usbuf, 0, sizeof(struct usersupp));
1130 memcpy(&usbuf, cdbus->ptr,
1131 ((cdbus->len > sizeof(struct usersupp)) ?
1132 sizeof(struct usersupp) : cdbus->len));
1134 if ((usbuf.flags & US_NEEDVALID)
1135 && (usbuf.axlevel > 0)) {
1136 cprintf("%d %s\n", MORE_DATA, usbuf.fullname);
1137 cdb_close_cursor(CDB_USERSUPP);
1142 /* If we get to this point, there are no more unvalidated users.
1143 * Therefore we clear the "users need validation" flag.
1146 begin_critical_section(S_CONTROL);
1148 CitControl.MMflags = CitControl.MMflags & (~MM_VALID);
1150 end_critical_section(S_CONTROL);
1151 cprintf("%d *** End of registration.\n", CIT_OK);
1160 void cmd_vali(char *v_args)
1164 struct usersupp userbuf;
1166 extract(user, v_args, 0);
1167 newax = extract_int(v_args, 1);
1169 if (CtdlAccessCheck(ac_aide)) {
1173 if (lgetuser(&userbuf, user) != 0) {
1174 cprintf("%d '%s' not found.\n", ERROR + NO_SUCH_USER, user);
1178 userbuf.axlevel = newax;
1179 userbuf.flags = (userbuf.flags & ~US_NEEDVALID);
1183 /* If the access level was set to zero, delete the user */
1185 if (purge_user(user) == 0) {
1186 cprintf("%d %s Deleted.\n", CIT_OK, userbuf.fullname);
1190 cprintf("%d User '%s' validated.\n", CIT_OK, userbuf.fullname);
1196 * Traverse the user file...
1198 void ForEachUser(void (*CallBack) (struct usersupp * EachUser, void *out_data),
1201 struct usersupp usbuf;
1202 struct cdbdata *cdbus;
1204 cdb_rewind(CDB_USERSUPP);
1206 while (cdbus = cdb_next_item(CDB_USERSUPP), cdbus != NULL) {
1207 memset(&usbuf, 0, sizeof(struct usersupp));
1208 memcpy(&usbuf, cdbus->ptr,
1209 ((cdbus->len > sizeof(struct usersupp)) ?
1210 sizeof(struct usersupp) : cdbus->len));
1212 (*CallBack) (&usbuf, in_data);
1218 * List one user (this works with cmd_list)
1220 void ListThisUser(struct usersupp *usbuf, void *data)
1222 if (usbuf->axlevel > 0) {
1223 if ((CC->usersupp.axlevel >= 6)
1224 || ((usbuf->flags & US_UNLISTED) == 0)
1225 || ((CC->internal_pgm))) {
1226 cprintf("%s|%d|%ld|%ld|%ld|%ld|",
1230 (long)usbuf->lastcall,
1233 if (CC->usersupp.axlevel >= 6)
1234 cprintf("%s", usbuf->password);
1245 cprintf("%d \n", LISTING_FOLLOWS);
1246 ForEachUser(ListThisUser, NULL);
1254 * assorted info we need to check at login
1262 if (CtdlAccessCheck(ac_logged_in)) {
1266 getuser(&CC->usersupp, CC->curr_user); /* no lock is needed here */
1267 if ((REGISCALL != 0) && ((CC->usersupp.flags & US_REGIS) == 0))
1270 if (CC->usersupp.axlevel >= 6) {
1272 if (CitControl.MMflags & MM_VALID)
1276 /* check for mail */
1277 mail = NewMailCount();
1279 cprintf("%d %d|%d|%d\n", CIT_OK, mail, regis, vali);
1284 * check to see if a user exists
1286 void cmd_qusr(char *who)
1288 struct usersupp usbuf;
1290 if (getuser(&usbuf, who) == 0) {
1291 cprintf("%d %s\n", CIT_OK, usbuf.fullname);
1293 cprintf("%d No such user.\n", ERROR + NO_SUCH_USER);
1299 * Administrative Get User Parameters
1301 void cmd_agup(char *cmdbuf)
1303 struct usersupp usbuf;
1304 char requested_user[SIZ];
1306 if (CtdlAccessCheck(ac_aide)) {
1310 extract(requested_user, cmdbuf, 0);
1311 if (getuser(&usbuf, requested_user) != 0) {
1312 cprintf("%d No such user.\n", ERROR + NO_SUCH_USER);
1315 cprintf("%d %s|%s|%u|%ld|%ld|%d|%ld|%ld|%d\n",
1322 (int) usbuf.axlevel,
1324 (long)usbuf.lastcall,
1331 * Administrative Set User Parameters
1333 void cmd_asup(char *cmdbuf)
1335 struct usersupp usbuf;
1336 char requested_user[SIZ];
1341 if (CtdlAccessCheck(ac_aide))
1344 extract(requested_user, cmdbuf, 0);
1345 if (lgetuser(&usbuf, requested_user) != 0) {
1346 cprintf("%d No such user.\n", ERROR + NO_SUCH_USER);
1349 np = num_parms(cmdbuf);
1351 extract(usbuf.password, cmdbuf, 1);
1353 usbuf.flags = extract_int(cmdbuf, 2);
1355 usbuf.timescalled = extract_int(cmdbuf, 3);
1357 usbuf.posted = extract_int(cmdbuf, 4);
1359 newax = extract_int(cmdbuf, 5);
1360 if ((newax >= 0) && (newax <= 6)) {
1361 usbuf.axlevel = extract_int(cmdbuf, 5);
1365 usbuf.lastcall = extract_long(cmdbuf, 7);
1368 usbuf.USuserpurge = extract_int(cmdbuf, 8);
1371 if (usbuf.axlevel == 0) {
1372 if (purge_user(requested_user) == 0) {
1376 cprintf("%d Ok", CIT_OK);
1378 cprintf(" (%s deleted)", requested_user);
1384 * Count the number of new mail messages the user has
1388 int num_newmsgs = 0;
1390 char mailboxname[ROOMNAMELEN];
1391 struct quickroom mailbox;
1393 struct cdbdata *cdbfr;
1394 long *msglist = NULL;
1397 MailboxName(mailboxname, sizeof mailboxname, &CC->usersupp, MAILROOM);
1398 if (getroom(&mailbox, mailboxname) != 0)
1400 CtdlGetRelationship(&vbuf, &CC->usersupp, &mailbox);
1402 cdbfr = cdb_fetch(CDB_MSGLISTS, &mailbox.QRnumber, sizeof(long));
1404 if (cdbfr != NULL) {
1405 msglist = mallok(cdbfr->len);
1406 memcpy(msglist, cdbfr->ptr, cdbfr->len);
1407 num_msgs = cdbfr->len / sizeof(long);
1411 for (a = 0; a < num_msgs; ++a) {
1412 if (msglist[a] > 0L) {
1413 if (msglist[a] > vbuf.v_lastseen) {
1418 if (msglist != NULL)
1421 return (num_newmsgs);