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 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");
507 write(pipev[1], buf, sprintf(buf, "%lu\n", (unsigned long) uid));
508 write(pipev[1], pass, strlen(pass));
509 write(pipev[1], "\n", 1);
512 while (waitpid(pid, &status, 0) == -1)
513 if (errno != EINTR) {
514 lprintf(1, "waitpid failed (%s): denying autologin "
515 "access for uid %ld\n",
516 strerror(errno), (long)uid);
519 if (WIFEXITED(status) && !WEXITSTATUS(status))
533 int CtdlTryPassword(char *password)
537 if ((CC->logged_in)) {
538 lprintf(5, "CtdlTryPassword: already logged in\n");
539 return pass_already_logged_in;
541 if (!strcmp(CC->curr_user, NLI)) {
542 lprintf(5, "CtdlTryPassword: no user selected\n");
545 if (getuser(&CC->usersupp, CC->curr_user)) {
546 lprintf(5, "CtdlTryPassword: internal error\n");
547 return pass_internal_error;
549 if (password == NULL) {
550 lprintf(5, "CtdlTryPassword: NULL password string supplied\n");
551 return pass_wrong_password;
554 if (CC->usersupp.uid == BBSUID) {
556 strproc(CC->usersupp.password);
557 code = strcasecmp(CC->usersupp.password, password);
559 #ifdef ENABLE_AUTOLOGIN
561 if (validpw(CC->usersupp.uid, password)) {
563 lgetuser(&CC->usersupp, CC->curr_user);
564 safestrncpy(CC->usersupp.password, password,
565 sizeof CC->usersupp.password);
566 lputuser(&CC->usersupp);
575 rec_log(CL_BADPW, CC->curr_user);
576 return pass_wrong_password;
581 void cmd_pass(char *buf)
586 extract(password, buf, 0);
587 a = CtdlTryPassword(password);
590 case pass_already_logged_in:
591 cprintf("%d Already logged in.\n", ERROR);
594 cprintf("%d You must send a name with USER first.\n",
597 case pass_wrong_password:
598 cprintf("%d Wrong password.\n", ERROR);
601 logged_in_response();
603 cprintf("%d Can't find user record!\n",
604 ERROR + INTERNAL_ERROR);
611 * Delete a user record *and* all of its related resources.
613 int purge_user(char pname[])
616 struct usersupp usbuf;
617 char lowercase_name[32];
619 struct CitContext *ccptr;
620 int user_is_logged_in = 0;
622 for (a = 0; a <= strlen(pname); ++a) {
623 lowercase_name[a] = tolower(pname[a]);
626 if (getuser(&usbuf, pname) != 0) {
627 lprintf(5, "Cannot purge user <%s> - not found\n", pname);
628 return (ERROR + NO_SUCH_USER);
630 /* Don't delete a user who is currently logged in. Instead, just
631 * set the access level to 0, and let the account get swept up
632 * during the next purge.
634 user_is_logged_in = 0;
635 begin_critical_section(S_SESSION_TABLE);
636 for (ccptr = ContextList; ccptr != NULL; ccptr = ccptr->next) {
637 if (ccptr->usersupp.usernum == usbuf.usernum) {
638 user_is_logged_in = 1;
641 end_critical_section(S_SESSION_TABLE);
642 if (user_is_logged_in == 1) {
643 lprintf(5, "User <%s> is logged in; not deleting.\n", pname);
648 lprintf(5, "Deleting user <%s>\n", pname);
650 /* Perform any purge functions registered by server extensions */
651 PerformUserHooks(usbuf.fullname, usbuf.usernum, EVT_PURGEUSER);
653 /* delete any existing user/room relationships */
654 cdb_delete(CDB_VISIT, &usbuf.usernum, sizeof(long));
656 /* delete the userlog entry */
657 cdb_delete(CDB_USERSUPP, lowercase_name, strlen(lowercase_name));
659 /* remove the user's bio file */
660 sprintf(filename, "./bio/%ld", usbuf.usernum);
663 /* remove the user's picture */
664 sprintf(filename, "./userpics/%ld.gif", usbuf.usernum);
672 * create_user() - back end processing to create a new user
674 * Set 'newusername' to the desired account name.
675 * Set 'become_user' to nonzero if this is self-service account creation and we want
676 * to actually log in as the user we just created, otherwise set it to 0.
678 int create_user(char *newusername, int become_user)
680 struct usersupp usbuf;
681 struct passwd *p = NULL;
683 char mailboxname[ROOMNAMELEN];
686 strcpy(username, newusername);
689 #ifdef ENABLE_AUTOLOGIN
690 p = (struct passwd *) getpwnam(username);
693 extract_token(username, p->pw_gecos, 0, ',');
699 if (!getuser(&usbuf, username)) {
700 return (ERROR + ALREADY_EXISTS);
703 /* Go ahead and initialize a new user record */
704 memset(&usbuf, 0, sizeof(struct usersupp));
705 strcpy(usbuf.fullname, username);
706 strcpy(usbuf.password, "");
709 /* These are the default flags on new accounts */
710 usbuf.flags = US_LASTOLD | US_DISAPPEAR | US_PAGINATOR | US_FLOORS;
712 usbuf.timescalled = 0;
714 usbuf.axlevel = config.c_initax;
715 usbuf.USscreenwidth = 80;
716 usbuf.USscreenheight = 24;
717 usbuf.lastcall = time(NULL);
718 usbuf.moderation_filter = config.c_default_filter;
720 /* fetch a new user number */
721 usbuf.usernum = get_new_user_number();
723 /* The very first user created on the system will always be an Aide */
724 if (usbuf.usernum == 1L) {
728 /* add user to userlog */
731 /* give the user a private mailbox */
732 MailboxName(mailboxname, sizeof mailboxname, &usbuf, MAILROOM);
733 create_room(mailboxname, 5, "", 0, 1);
735 /*** Everything below this line can be bypassed if we are administratively
736 creating a user, instead of doing self-service account creation
740 /* Now become the user we just created */
741 memcpy(&CC->usersupp, &usbuf, sizeof(struct usersupp));
742 strcpy(CC->curr_user, username);
745 /* Check to make sure we're still who we think we are */
746 if (getuser(&CC->usersupp, CC->curr_user)) {
747 return (ERROR + INTERNAL_ERROR);
750 rec_log(CL_NEWUSER, CC->curr_user);
760 * cmd_newu() - create a new user account and log in as that user
762 void cmd_newu(char *cmdbuf)
767 if (config.c_disable_newu) {
768 cprintf("%d Self-service user account creation "
769 "is disabled on this system.\n", ERROR);
774 cprintf("%d Already logged in.\n", ERROR);
778 cprintf("%d %s: Too many users are already online (maximum is %d)\n",
779 ERROR + MAX_SESSIONS_EXCEEDED,
780 config.c_nodename, config.c_maxsessions);
782 extract(username, cmdbuf, 0);
786 if (strlen(username) == 0) {
787 cprintf("%d You must supply a user name.\n", ERROR);
791 if ((!strcasecmp(username, "bbs")) ||
792 (!strcasecmp(username, "new")) ||
793 (!strcasecmp(username, "."))) {
794 cprintf("%d '%s' is an invalid login name.\n", ERROR, username);
798 a = create_user(username, 1);
802 logged_in_response();
803 } else if (a == ERROR + ALREADY_EXISTS) {
804 cprintf("%d '%s' already exists.\n",
805 ERROR + ALREADY_EXISTS, username);
807 } else if (a == ERROR + INTERNAL_ERROR) {
808 cprintf("%d Internal error - user record disappeared?\n",
809 ERROR + INTERNAL_ERROR);
812 cprintf("%d unknown error\n", ERROR);
814 rec_log(CL_NEWUSER, CC->curr_user);
822 void cmd_setp(char *new_pw)
824 if (CtdlAccessCheck(ac_logged_in)) {
828 if (CC->usersupp.uid != BBSUID) {
829 cprintf("%d Not allowed. Use the 'passwd' command.\n", ERROR);
833 if (strlen(new_pw) == 0) {
834 cprintf("%d Password unchanged.\n", OK);
837 lgetuser(&CC->usersupp, CC->curr_user);
838 strcpy(CC->usersupp.password, new_pw);
839 lputuser(&CC->usersupp);
840 cprintf("%d Password changed.\n", OK);
841 rec_log(CL_PWCHANGE, CC->curr_user);
842 PerformSessionHooks(EVT_SETPASS);
847 * cmd_creu() - administratively create a new user account (do not log in to it)
849 void cmd_creu(char *cmdbuf)
854 if (CtdlAccessCheck(ac_aide)) {
858 extract(username, cmdbuf, 0);
862 if (strlen(username) == 0) {
863 cprintf("%d You must supply a user name.\n", ERROR);
867 a = create_user(username, 0);
870 cprintf("%d ok\n", OK);
872 } else if (a == ERROR + ALREADY_EXISTS) {
873 cprintf("%d '%s' already exists.\n",
874 ERROR + ALREADY_EXISTS, username);
877 cprintf("%d An error occured creating the user account.\n", ERROR);
879 rec_log(CL_NEWUSER, username);
885 * get user parameters
890 if (CtdlAccessCheck(ac_logged_in))
893 getuser(&CC->usersupp, CC->curr_user);
894 cprintf("%d %d|%d|%d|%d\n",
896 CC->usersupp.USscreenwidth,
897 CC->usersupp.USscreenheight,
898 (CC->usersupp.flags & US_USER_SET),
899 CC->usersupp.moderation_filter
904 * set user parameters
906 void cmd_setu(char *new_parms)
910 if (CtdlAccessCheck(ac_logged_in))
913 if (num_parms(new_parms) < 3) {
914 cprintf("%d Usage error.\n", ERROR);
917 lgetuser(&CC->usersupp, CC->curr_user);
918 CC->usersupp.USscreenwidth = extract_int(new_parms, 0);
919 CC->usersupp.USscreenheight = extract_int(new_parms, 1);
920 CC->usersupp.flags = CC->usersupp.flags & (~US_USER_SET);
921 CC->usersupp.flags = CC->usersupp.flags |
922 (extract_int(new_parms, 2) & US_USER_SET);
924 if (num_parms(new_parms) >= 4) {
925 new_mod = extract_int(new_parms, 3);
926 lprintf(9, "new_mod extracted to %d\n", new_mod);
928 /* Aides cannot set the filter level lower than -100 */
929 if (new_mod < (-100))
932 /* Normal users cannot set the filter level lower than -63 */
933 if ((new_mod < (-63)) && (CC->usersupp.axlevel < 6))
936 /* Nobody can set the filter level higher than +63 */
940 CC->usersupp.moderation_filter = new_mod;
941 lprintf(9, "new_mod processed to %d\n", new_mod);
943 lputuser(&CC->usersupp);
944 cprintf("%d Ok\n", OK);
948 * set last read pointer
950 void cmd_slrp(char *new_ptr)
955 if (CtdlAccessCheck(ac_logged_in)) {
959 if (!strncasecmp(new_ptr, "highest", 7)) {
960 newlr = CC->quickroom.QRhighest;
962 newlr = atol(new_ptr);
965 lgetuser(&CC->usersupp, CC->curr_user);
967 CtdlGetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
968 vbuf.v_lastseen = newlr;
969 sprintf(vbuf.v_seen, "*:%ld", newlr);
970 CtdlSetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
972 lputuser(&CC->usersupp);
973 cprintf("%d %ld\n", OK, newlr);
977 void cmd_seen(char *argbuf) {
978 long target_msgnum = 0L;
979 int target_setting = 0;
981 if (CtdlAccessCheck(ac_logged_in)) {
985 if (num_parms(argbuf) != 2) {
986 cprintf("%d Invalid parameters\n", ERROR);
990 target_msgnum = extract_long(argbuf, 0);
991 target_setting = extract_int(argbuf, 1);
993 CtdlSetSeen(target_msgnum, target_setting);
994 cprintf("%d OK\n", OK);
999 * INVT and KICK commands
1001 void cmd_invt_kick(char *iuser, int op)
1003 { /* 1 = invite, 0 = kick out */
1004 struct usersupp USscratch;
1008 if (CtdlAccessCheck(ac_room_aide))
1011 if (lgetuser(&USscratch, iuser) != 0) {
1012 cprintf("%d No such user.\n", ERROR);
1015 CtdlGetRelationship(&vbuf, &USscratch, &CC->quickroom);
1018 vbuf.v_flags = vbuf.v_flags & ~V_FORGET & ~V_LOCKOUT;
1019 vbuf.v_flags = vbuf.v_flags | V_ACCESS;
1022 vbuf.v_flags = vbuf.v_flags & ~V_ACCESS;
1023 vbuf.v_flags = vbuf.v_flags | V_FORGET | V_LOCKOUT;
1025 CtdlSetRelationship(&vbuf, &USscratch, &CC->quickroom);
1027 lputuser(&USscratch);
1029 /* post a message in Aide> saying what we just did */
1030 sprintf(bbb, "%s %s %s> by %s\n",
1032 ((op == 1) ? "invited to" : "kicked out of"),
1033 CC->quickroom.QRname,
1034 CC->usersupp.fullname);
1037 cprintf("%d %s %s %s.\n",
1039 ((op == 1) ? "invited to" : "kicked out of"),
1040 CC->quickroom.QRname);
1046 * Forget (Zap) the current room (API call)
1047 * Returns 0 on success
1049 int CtdlForgetThisRoom(void) {
1052 /* On some systems, Aides are not allowed to forget rooms */
1053 if (is_aide() && (config.c_aide_zap == 0)
1054 && ((CC->quickroom.QRflags & QR_MAILBOX) == 0) ) {
1058 lgetuser(&CC->usersupp, CC->curr_user);
1059 CtdlGetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
1061 vbuf.v_flags = vbuf.v_flags | V_FORGET;
1062 vbuf.v_flags = vbuf.v_flags & ~V_ACCESS;
1064 CtdlSetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
1065 lputuser(&CC->usersupp);
1067 /* Return to the Lobby, so we don't end up in an undefined room */
1068 usergoto(BASEROOM, 0, NULL, NULL);
1075 * forget (Zap) the current room
1080 if (CtdlAccessCheck(ac_logged_in)) {
1084 if (CtdlForgetThisRoom() == 0) {
1085 cprintf("%d Ok\n", OK);
1088 cprintf("%d You may not forget this room.\n", ERROR);
1093 * Get Next Unregistered User
1097 struct cdbdata *cdbus;
1098 struct usersupp usbuf;
1100 if (CtdlAccessCheck(ac_aide)) {
1104 if ((CitControl.MMflags & MM_VALID) == 0) {
1105 cprintf("%d There are no unvalidated users.\n", OK);
1109 /* There are unvalidated users. Traverse the usersupp database,
1110 * and return the first user we find that needs validation.
1112 cdb_rewind(CDB_USERSUPP);
1113 while (cdbus = cdb_next_item(CDB_USERSUPP), cdbus != NULL) {
1114 memset(&usbuf, 0, sizeof(struct usersupp));
1115 memcpy(&usbuf, cdbus->ptr,
1116 ((cdbus->len > sizeof(struct usersupp)) ?
1117 sizeof(struct usersupp) : cdbus->len));
1119 if ((usbuf.flags & US_NEEDVALID)
1120 && (usbuf.axlevel > 0)) {
1121 cprintf("%d %s\n", MORE_DATA, usbuf.fullname);
1122 cdb_close_cursor(CDB_USERSUPP);
1127 /* If we get to this point, there are no more unvalidated users.
1128 * Therefore we clear the "users need validation" flag.
1131 begin_critical_section(S_CONTROL);
1133 CitControl.MMflags = CitControl.MMflags & (~MM_VALID);
1135 end_critical_section(S_CONTROL);
1136 cprintf("%d *** End of registration.\n", OK);
1145 void cmd_vali(char *v_args)
1149 struct usersupp userbuf;
1151 extract(user, v_args, 0);
1152 newax = extract_int(v_args, 1);
1154 if (CtdlAccessCheck(ac_aide)) {
1158 if (lgetuser(&userbuf, user) != 0) {
1159 cprintf("%d '%s' not found.\n", ERROR + NO_SUCH_USER, user);
1163 userbuf.axlevel = newax;
1164 userbuf.flags = (userbuf.flags & ~US_NEEDVALID);
1168 /* If the access level was set to zero, delete the user */
1170 if (purge_user(user) == 0) {
1171 cprintf("%d %s Deleted.\n", OK, userbuf.fullname);
1175 cprintf("%d User '%s' validated.\n", OK, userbuf.fullname);
1181 * Traverse the user file...
1183 void ForEachUser(void (*CallBack) (struct usersupp * EachUser, void *out_data),
1186 struct usersupp usbuf;
1187 struct cdbdata *cdbus;
1189 cdb_rewind(CDB_USERSUPP);
1191 while (cdbus = cdb_next_item(CDB_USERSUPP), cdbus != NULL) {
1192 memset(&usbuf, 0, sizeof(struct usersupp));
1193 memcpy(&usbuf, cdbus->ptr,
1194 ((cdbus->len > sizeof(struct usersupp)) ?
1195 sizeof(struct usersupp) : cdbus->len));
1197 (*CallBack) (&usbuf, in_data);
1203 * List one user (this works with cmd_list)
1205 void ListThisUser(struct usersupp *usbuf, void *data)
1207 if (usbuf->axlevel > 0) {
1208 if ((CC->usersupp.axlevel >= 6)
1209 || ((usbuf->flags & US_UNLISTED) == 0)
1210 || ((CC->internal_pgm))) {
1211 cprintf("%s|%d|%ld|%ld|%ld|%ld|",
1215 (long)usbuf->lastcall,
1218 if (CC->usersupp.axlevel >= 6)
1219 cprintf("%s", usbuf->password);
1230 cprintf("%d \n", LISTING_FOLLOWS);
1231 ForEachUser(ListThisUser, NULL);
1239 * assorted info we need to check at login
1247 if (CtdlAccessCheck(ac_logged_in)) {
1251 getuser(&CC->usersupp, CC->curr_user); /* no lock is needed here */
1252 if ((REGISCALL != 0) && ((CC->usersupp.flags & US_REGIS) == 0))
1255 if (CC->usersupp.axlevel >= 6) {
1257 if (CitControl.MMflags & MM_VALID)
1261 /* check for mail */
1262 mail = NewMailCount();
1264 cprintf("%d %d|%d|%d\n", OK, mail, regis, vali);
1269 * check to see if a user exists
1271 void cmd_qusr(char *who)
1273 struct usersupp usbuf;
1275 if (getuser(&usbuf, who) == 0) {
1276 cprintf("%d %s\n", OK, usbuf.fullname);
1278 cprintf("%d No such user.\n", ERROR + NO_SUCH_USER);
1284 * Administrative Get User Parameters
1286 void cmd_agup(char *cmdbuf)
1288 struct usersupp usbuf;
1289 char requested_user[SIZ];
1291 if (CtdlAccessCheck(ac_aide)) {
1295 extract(requested_user, cmdbuf, 0);
1296 if (getuser(&usbuf, requested_user) != 0) {
1297 cprintf("%d No such user.\n", ERROR + NO_SUCH_USER);
1300 cprintf("%d %s|%s|%u|%ld|%ld|%d|%ld|%ld|%d\n",
1307 (int) usbuf.axlevel,
1309 (long)usbuf.lastcall,
1316 * Administrative Set User Parameters
1318 void cmd_asup(char *cmdbuf)
1320 struct usersupp usbuf;
1321 char requested_user[SIZ];
1326 if (CtdlAccessCheck(ac_aide))
1329 extract(requested_user, cmdbuf, 0);
1330 if (lgetuser(&usbuf, requested_user) != 0) {
1331 cprintf("%d No such user.\n", ERROR + NO_SUCH_USER);
1334 np = num_parms(cmdbuf);
1336 extract(usbuf.password, cmdbuf, 1);
1338 usbuf.flags = extract_int(cmdbuf, 2);
1340 usbuf.timescalled = extract_int(cmdbuf, 3);
1342 usbuf.posted = extract_int(cmdbuf, 4);
1344 newax = extract_int(cmdbuf, 5);
1345 if ((newax >= 0) && (newax <= 6)) {
1346 usbuf.axlevel = extract_int(cmdbuf, 5);
1350 usbuf.lastcall = extract_long(cmdbuf, 7);
1353 usbuf.USuserpurge = extract_int(cmdbuf, 8);
1356 if (usbuf.axlevel == 0) {
1357 if (purge_user(requested_user) == 0) {
1361 cprintf("%d Ok", OK);
1363 cprintf(" (%s deleted)", requested_user);
1369 * Count the number of new mail messages the user has
1373 int num_newmsgs = 0;
1375 char mailboxname[ROOMNAMELEN];
1376 struct quickroom mailbox;
1378 struct cdbdata *cdbfr;
1379 long *msglist = NULL;
1382 MailboxName(mailboxname, sizeof mailboxname, &CC->usersupp, MAILROOM);
1383 if (getroom(&mailbox, mailboxname) != 0)
1385 CtdlGetRelationship(&vbuf, &CC->usersupp, &mailbox);
1387 cdbfr = cdb_fetch(CDB_MSGLISTS, &mailbox.QRnumber, sizeof(long));
1389 if (cdbfr != NULL) {
1390 msglist = mallok(cdbfr->len);
1391 memcpy(msglist, cdbfr->ptr, cdbfr->len);
1392 num_msgs = cdbfr->len / sizeof(long);
1396 for (a = 0; a < num_msgs; ++a) {
1397 if (msglist[a] > 0L) {
1398 if (msglist[a] > vbuf.v_lastseen) {
1403 if (msglist != NULL)
1406 return (num_newmsgs);