* Split up some of the code in order to prepare for user accounts to be
authorArt Cancro <ajc@citadel.org>
Sun, 3 Mar 2002 06:05:16 +0000 (06:05 +0000)
committerArt Cancro <ajc@citadel.org>
Sun, 3 Mar 2002 06:05:16 +0000 (06:05 +0000)
  administratively created without logging in to them.

citadel/ChangeLog
citadel/room_ops.c
citadel/routines2.h
citadel/user_ops.c
citadel/user_ops.h

index 5164ccb8d8ee7dc1ef9b7c3a9aa37745a523f817..1f0e457e40175e5190b7361c1e2585d19841909e 100644 (file)
@@ -1,4 +1,8 @@
  $Log$
+ Revision 590.121  2002/03/03 06:05:16  ajc
+ * Split up some of the code in order to prepare for user accounts to be
+   administratively created without logging in to them.
+
  Revision 590.120  2002/03/02 05:56:48  ajc
  * Properly implemented the network filter list.  Finished the server module and
    did a client-side <.A>ide <S>ysconfig <F>ilterlist command.
@@ -3368,5 +3372,3 @@ Sat Jul 11 00:20:48 EDT 1998 Nathan Bryant <bryant@cs.usm.maine.edu>
 
 Fri Jul 10 1998 Art Cancro <ajc@uncensored.citadel.org>
        * Initial CVS import 
-
-
index aa53f6f2fe1c3fabe6281ea760d58a0072b084bb..db224477ae2a4ba901c635146d38cd355ff61887 100644 (file)
@@ -53,6 +53,7 @@ int CtdlRoomAccess(struct quickroom *roombuf, struct usersupp *userbuf)
        int retval = 0;
        struct visit vbuf;
 
+
        /* for internal programs, always do everything */
        if (((CC->internal_pgm)) && (roombuf->QRflags & QR_INUSE)) {
                return (UA_KNOWN | UA_GOTOALLOWED);
@@ -815,11 +816,16 @@ void cmd_goto(char *gargs)
                ra = CtdlRoomAccess(&QRscratch, &CC->usersupp);
 
                /* normal clients have to pass through security */
-               if (ra & UA_GOTOALLOWED)
+               if (ra & UA_GOTOALLOWED) {
                        ok = 1;
+               }
 
                if (ok == 1) {
-                       if ((QRscratch.QRflags & QR_PASSWORDED) &&
+                       if ((QRscratch.QRflags & QR_MAILBOX) &&
+                           ((ra & UA_GOTOALLOWED))) {
+                               usergoto(towhere, 1, NULL, NULL);
+                               return;
+                       } else if ((QRscratch.QRflags & QR_PASSWORDED) &&
                            ((ra & UA_KNOWN) == 0) &&
                            (strcasecmp(QRscratch.QRpasswd, password)) &&
                            (CC->usersupp.axlevel < 6)
@@ -833,6 +839,7 @@ void cmd_goto(char *gargs)
                                   ((ra & UA_KNOWN) == 0) &&
                                   (CC->usersupp.axlevel < 6)
                                   ) {
+                               lprintf(9, "Failed to acquire private room\n");
                                goto NOPE;
                        } else {
                                usergoto(towhere, 1, NULL, NULL);
index 5750792c9c1b3bdacc9fbed7dbefb7b46a4a8029..cd57d12b1a9744e1a6f1a86dc20da66137847985 100644 (file)
@@ -15,3 +15,4 @@ int room_prompt(int qrflags);
 void do_internet_configuration(void);
 void do_ignet_configuration(void);
 void network_config_management(char *entrytype, char *comment);
+void do_filterlist_configuration(void);
index 5930c71ad8733ef96c5f6a7004ae2b944c29169b..3d22cf86a8d2f0c995d6ab04564fa640f36bd792 100644 (file)
@@ -670,13 +670,18 @@ int purge_user(char pname[])
 
 /*
  * create_user()  -  back end processing to create a new user
+ *
+ * Set 'newusername' to the desired account name.
+ * Set 'become_user' to nonzero if this is self-service account creation and we want
+ * to actually log in as the user we just created, otherwise set it to 0.
  */
-int create_user(char *newusername)
+int create_user(char *newusername, int become_user)
 {
        struct usersupp usbuf;
-       int a;
        struct passwd *p = NULL;
-       char username[64];
+       char username[SIZ];
+       char mailboxname[ROOMNAMELEN];
+       uid_t uid;
 
        strcpy(username, newusername);
        strproc(username);
@@ -685,50 +690,66 @@ int create_user(char *newusername)
        p = (struct passwd *) getpwnam(username);
 #endif
        if (p != NULL) {
-               strcpy(username, p->pw_gecos);
-               for (a = 0; a < strlen(username); ++a) {
-                       if (username[a] == ',')
-                               username[a] = 0;
-               }
-               CC->usersupp.uid = p->pw_uid;
+               extract_token(username, p->pw_gecos, 0, ',');
+               uid = p->pw_uid;
        } else {
-               CC->usersupp.uid = BBSUID;
+               uid = BBSUID;
        }
 
        if (!getuser(&usbuf, username)) {
                return (ERROR + ALREADY_EXISTS);
        }
-       strcpy(CC->curr_user, username);
-       strcpy(CC->usersupp.fullname, username);
-       strcpy(CC->usersupp.password, "");
-       (CC->logged_in) = 1;
+
+       /* Go ahead and initialize a new user record */
+       memset(&usbuf, 0, sizeof(struct usersupp));
+       strcpy(usbuf.fullname, username);
+       strcpy(usbuf.password, "");
+       usbuf.uid = uid;
 
        /* These are the default flags on new accounts */
-       CC->usersupp.flags = US_LASTOLD | US_DISAPPEAR | US_PAGINATOR | US_FLOORS;
+       usbuf.flags = US_LASTOLD | US_DISAPPEAR | US_PAGINATOR | US_FLOORS;
 
-       CC->usersupp.timescalled = 0;
-       CC->usersupp.posted = 0;
-       CC->usersupp.axlevel = config.c_initax;
-       CC->usersupp.USscreenwidth = 80;
-       CC->usersupp.USscreenheight = 24;
-       time(&CC->usersupp.lastcall);
-       CC->usersupp.moderation_filter = config.c_default_filter;
+       usbuf.timescalled = 0;
+       usbuf.posted = 0;
+       usbuf.axlevel = config.c_initax;
+       usbuf.USscreenwidth = 80;
+       usbuf.USscreenheight = 24;
+       usbuf.lastcall = time(NULL);
+       usbuf.moderation_filter = config.c_default_filter;
 
        /* fetch a new user number */
-       CC->usersupp.usernum = get_new_user_number();
+       usbuf.usernum = get_new_user_number();
 
-       if (CC->usersupp.usernum == 1L) {
-               CC->usersupp.axlevel = 6;
+       /* The very first user created on the system will always be an Aide */
+       if (usbuf.usernum == 1L) {
+               usbuf.axlevel = 6;
        }
+
        /* add user to userlog */
-       putuser(&CC->usersupp);
-       if (getuser(&CC->usersupp, CC->curr_user)) {
-               return (ERROR + INTERNAL_ERROR);
-       }
+       putuser(&usbuf);
+
        /* give the user a private mailbox */
-       create_room(MAILROOM, 4, "", 0, 1);
+       MailboxName(mailboxname, &usbuf, MAILROOM);
+       create_room(mailboxname, 5, "", 0, 1);
+
+       /*** Everything below this line can be bypassed if we are administratively
+            creating a user, instead of doing self-service account creation
+        ***/
+
+       if (become_user) {
+               /* Now become the user we just created */
+               memcpy(&CC->usersupp, &usbuf, sizeof(struct usersupp));
+               strcpy(CC->curr_user, username);
+               CC->logged_in = 1;
+       
+               /* Check to make sure we're still who we think we are */
+               if (getuser(&CC->usersupp, CC->curr_user)) {
+                       return (ERROR + INTERNAL_ERROR);
+               }
+       
+               rec_log(CL_NEWUSER, CC->curr_user);
+       }
 
-       rec_log(CL_NEWUSER, CC->curr_user);
        return (0);
 }
 
@@ -743,11 +764,11 @@ void cmd_newu(char *cmdbuf)
        int a;
        char username[SIZ];
 
-       if ((CC->logged_in)) {
+       if (CC->logged_in) {
                cprintf("%d Already logged in.\n", ERROR);
                return;
        }
-       if ((CC->nologin)) {
+       if (CC->nologin) {
                cprintf("%d %s: Too many users are already online (maximum is %d)\n",
                        ERROR + MAX_SESSIONS_EXCEEDED,
                        config.c_nodename, config.c_maxsessions);
@@ -760,14 +781,20 @@ void cmd_newu(char *cmdbuf)
                cprintf("%d You must supply a user name.\n", ERROR);
                return;
        }
-       a = create_user(username);
+
        if ((!strcasecmp(username, "bbs")) ||
            (!strcasecmp(username, "new")) ||
            (!strcasecmp(username, "."))) {
                cprintf("%d '%s' is an invalid login name.\n", ERROR, username);
                return;
        }
-       if (a == ERROR + ALREADY_EXISTS) {
+
+       a = create_user(username, 1);
+
+       if (a == 0) {
+               session_startup();
+               logged_in_response();
+       } else if (a == ERROR + ALREADY_EXISTS) {
                cprintf("%d '%s' already exists.\n",
                        ERROR + ALREADY_EXISTS, username);
                return;
@@ -775,9 +802,6 @@ void cmd_newu(char *cmdbuf)
                cprintf("%d Internal error - user record disappeared?\n",
                        ERROR + INTERNAL_ERROR);
                return;
-       } else if (a == 0) {
-               session_startup();
-               logged_in_response();
        } else {
                cprintf("%d unknown error\n", ERROR);
        }
@@ -791,8 +815,9 @@ void cmd_newu(char *cmdbuf)
  */
 void cmd_setp(char *new_pw)
 {
-       if (CtdlAccessCheck(ac_logged_in))
+       if (CtdlAccessCheck(ac_logged_in)) {
                return;
+       }
 
        if (CC->usersupp.uid != BBSUID) {
                cprintf("%d Not allowed.  Use the 'passwd' command.\n", ERROR);
index f63bbfa39d19bd1c4a3a1b059ddf0d7a55c51a22..e60ef2a7ce616063f7c635fb126f40b9329aa62a 100644 (file)
@@ -12,7 +12,7 @@ void session_startup (void);
 void logout (struct CitContext *who);
 void cmd_pass (char *buf);
 int purge_user (char *pname);
-int create_user (char *newusername);
+int create_user (char *newusername, int become_user);
 void do_login(void);
 void cmd_newu (char *cmdbuf);
 void cmd_setp (char *new_pw);