]> code.citadel.org Git - citadel.git/blobdiff - citadel/user_ops.c
* Variable names, comments, documentation, etc... removed the acronym 'BBS'
[citadel.git] / citadel / user_ops.c
index 6f2e12eb4f006b4e61f88cfae419500b096a228e..f375637e16d30342a25121a436faccf51717715c 100644 (file)
@@ -79,7 +79,9 @@ int getuser(struct ctdluser *usbuf, char name[])
        struct cdbdata *cdbus;
        int using_sysuser = 0;
 
-       memset(usbuf, 0, sizeof(struct ctdluser));
+       if (usbuf != NULL) {
+               memset(usbuf, 0, sizeof(struct ctdluser));
+       }
 
 #ifdef ENABLE_AUTOLOGIN
        if (CtdlAssociateSystemUser(sysuser_name, name) == 0) {
@@ -98,9 +100,11 @@ int getuser(struct ctdluser *usbuf, char name[])
        if (cdbus == NULL) {    /* user not found */
                return(1);
        }
-       memcpy(usbuf, cdbus->ptr,
-              ((cdbus->len > sizeof(struct ctdluser)) ?
-               sizeof(struct ctdluser) : cdbus->len));
+       if (usbuf != NULL) {
+               memcpy(usbuf, cdbus->ptr,
+                       ((cdbus->len > sizeof(struct ctdluser)) ?
+                        sizeof(struct ctdluser) : cdbus->len));
+       }
        cdb_free(cdbus);
 
        return (0);
@@ -352,11 +356,10 @@ int CtdlLoginExistingUser(char *trythisname)
        char username[SIZ];
        int found_user;
        struct recptypes *valid = NULL;
-       struct passwd *p = NULL;
 
        if (trythisname == NULL) return login_not_found;
-       safestrncpy(username, trythisname, sizeof username);
-       strproc(username);
+       safestrncpy(username, trythisname, USERNAME_SIZE);
+       striplt(username);
 
        if ((CC->logged_in)) {
                return login_already_logged_in;
@@ -369,7 +372,7 @@ int CtdlLoginExistingUser(char *trythisname)
         * is an e-mail address
         */
        if (found_user != 0) {
-               valid = validate_recipients(trythisname);
+               valid = validate_recipients(username);
                if (valid != NULL) {
                        if (valid->num_local == 1) {
                                found_user = getuser(&CC->user,
@@ -385,7 +388,8 @@ int CtdlLoginExistingUser(char *trythisname)
         * account.
         */
        if (found_user != 0) {
-               p = (struct passwd *) getpwnam(username);
+               struct passwd *p = (struct passwd *) getpwnam(username);
+
                if (p != NULL) {
                        create_user(username, 0);
                        found_user = getuser(&CC->user, username);
@@ -413,10 +417,10 @@ int CtdlLoginExistingUser(char *trythisname)
  */
 void cmd_user(char *cmdbuf)
 {
-       char username[SIZ];
+       char username[256];
        int a;
 
-       extract(username, cmdbuf, 0);
+       extract_token(username, cmdbuf, 0, '|', sizeof username);
        striplt(username);
 
        a = CtdlLoginExistingUser(username);
@@ -483,8 +487,8 @@ void session_startup(void)
        /* Create any personal rooms required by the system.
         * (Technically, MAILROOM should be there already, but just in case...)
         */
-       create_room(MAILROOM, 4, "", 0, 1, 0);
-       create_room(SENTITEMS, 4, "", 0, 1, 0);
+       create_room(MAILROOM, 4, "", 0, 1, 0, VIEW_MAILBOX);
+       create_room(SENTITEMS, 4, "", 0, 1, 0, VIEW_MAILBOX);
 
        /* Run any startup routines registered by loadable modules */
        PerformSessionHooks(EVT_LOGIN);
@@ -585,8 +589,8 @@ static int validpw(uid_t uid, const char *pass)
                }
                close(pipev[0]);
 
-               execl(BBSDIR "/chkpwd", BBSDIR "/chkpwd", NULL);
-               perror(BBSDIR "/chkpwd");
+               execl(CTDLDIR "/chkpwd", CTDLDIR "/chkpwd", NULL);
+               perror(CTDLDIR "/chkpwd");
                exit(1);
        }
 
@@ -642,10 +646,10 @@ int CtdlTryPassword(char *password)
 
 
 #ifdef ENABLE_AUTOLOGIN
-       /* A uid of BBSUID or -1 indicates that this user exists only in
+       /* A uid of CTDLUID or -1 indicates that this user exists only in
         * Citadel, not in the underlying operating system.
         */
-       if ( (CC->user.uid == BBSUID) || (CC->user.uid == (-1)) ) {
+       if ( (CC->user.uid == CTDLUID) || (CC->user.uid == (-1)) ) {
                strproc(password);
                strproc(CC->user.password);
                code = strcasecmp(CC->user.password, password);
@@ -680,10 +684,10 @@ int CtdlTryPassword(char *password)
 
 void cmd_pass(char *buf)
 {
-       char password[SIZ];
+       char password[256];
        int a;
 
-       extract(password, buf, 0);
+       extract_token(password, buf, 0, '|', sizeof password);
        a = CtdlTryPassword(password);
 
        switch (a) {
@@ -700,8 +704,6 @@ void cmd_pass(char *buf)
        case pass_ok:
                logged_in_response();
                return;
-               cprintf("%d Can't find user record!\n",
-                       ERROR + INTERNAL_ERROR);
        }
 }
 
@@ -776,8 +778,7 @@ int create_user(char *newusername, int become_user)
 {
        struct ctdluser usbuf;
        struct ctdlroom qrbuf;
-       struct passwd *p = NULL;
-       char username[SIZ];
+       char username[256];
        char mailboxname[ROOMNAMELEN];
        uid_t uid;
 
@@ -785,12 +786,15 @@ int create_user(char *newusername, int become_user)
        strproc(username);
 
 #ifdef ENABLE_AUTOLOGIN
-       p = (struct passwd *) getpwnam(username);
-       if (p != NULL) {
-               extract_token(username, p->pw_gecos, 0, ',');
-               uid = p->pw_uid;
-       } else {
-               uid = (-1);
+       {
+               struct passwd *p = (struct passwd *) getpwnam(username);
+
+               if (p != NULL) {
+                       extract_token(username, p->pw_gecos, 0, ',', sizeof username);
+                       uid = p->pw_uid;
+               } else {
+                       uid = (-1);
+               }
        }
 #else
        uid = (-1);
@@ -832,10 +836,10 @@ int create_user(char *newusername, int become_user)
         * Make the latter an invisible system room.
         */
        MailboxName(mailboxname, sizeof mailboxname, &usbuf, MAILROOM);
-       create_room(mailboxname, 5, "", 0, 1, 1);
+       create_room(mailboxname, 5, "", 0, 1, 1, VIEW_MAILBOX);
 
        MailboxName(mailboxname, sizeof mailboxname, &usbuf, USERCONFIGROOM);
-       create_room(mailboxname, 5, "", 0, 1, 1);
+       create_room(mailboxname, 5, "", 0, 1, 1, VIEW_BBS);
         if (lgetroom(&qrbuf, mailboxname) == 0) {
                 qrbuf.QRflags2 |= QR2_SYSTEM;
                 lputroom(&qrbuf);
@@ -873,7 +877,7 @@ int create_user(char *newusername, int become_user)
 void cmd_newu(char *cmdbuf)
 {
        int a;
-       char username[SIZ];
+       char username[26];
 
        if (config.c_disable_newu) {
                cprintf("%d Self-service user account creation "
@@ -890,7 +894,7 @@ void cmd_newu(char *cmdbuf)
                        ERROR + MAX_SESSIONS_EXCEEDED,
                        config.c_nodename, config.c_maxsessions);
        }
-       extract(username, cmdbuf, 0);
+       extract_token(username, cmdbuf, 0, '|', sizeof username);
        username[25] = 0;
        strproc(username);
 
@@ -934,7 +938,7 @@ void cmd_setp(char *new_pw)
        if (CtdlAccessCheck(ac_logged_in)) {
                return;
        }
-       if ( (CC->user.uid != BBSUID) && (CC->user.uid != (-1)) ) {
+       if ( (CC->user.uid != CTDLUID) && (CC->user.uid != (-1)) ) {
                cprintf("%d Not allowed.  Use the 'passwd' command.\n", ERROR + NOT_HERE);
                return;
        }
@@ -958,16 +962,16 @@ void cmd_setp(char *new_pw)
 void cmd_creu(char *cmdbuf)
 {
        int a;
-       char username[SIZ];
-       char password[SIZ];
+       char username[26];
+       char password[32];
        struct ctdluser tmp;
 
        if (CtdlAccessCheck(ac_aide)) {
                return;
        }
 
-       extract(username, cmdbuf, 0);
-       extract(password, cmdbuf, 1);
+       extract_token(username, cmdbuf, 0, '|', sizeof username);
+       extract_token(password, cmdbuf, 1, '|', sizeof password);
        username[25] = 0;
        password[31] = 0;
        strproc(username);
@@ -1291,11 +1295,11 @@ void cmd_gnur(void)
  */
 void cmd_vali(char *v_args)
 {
-       char user[SIZ];
+       char user[128];
        int newax;
        struct ctdluser userbuf;
 
-       extract(user, v_args, 0);
+       extract_token(user, v_args, 0, '|', sizeof user);
        newax = extract_int(v_args, 1);
 
        if (CtdlAccessCheck(ac_aide)) {
@@ -1433,13 +1437,13 @@ void cmd_qusr(char *who)
 void cmd_agup(char *cmdbuf)
 {
        struct ctdluser usbuf;
-       char requested_user[SIZ];
+       char requested_user[128];
 
        if (CtdlAccessCheck(ac_aide)) {
                return;
        }
 
-       extract(requested_user, cmdbuf, 0);
+       extract_token(requested_user, cmdbuf, 0, '|', sizeof requested_user);
        if (getuser(&usbuf, requested_user) != 0) {
                cprintf("%d No such user.\n", ERROR + NO_SUCH_USER);
                return;
@@ -1465,7 +1469,7 @@ void cmd_agup(char *cmdbuf)
 void cmd_asup(char *cmdbuf)
 {
        struct ctdluser usbuf;
-       char requested_user[SIZ];
+       char requested_user[128];
        char notify[SIZ];
        int np;
        int newax;
@@ -1474,14 +1478,14 @@ void cmd_asup(char *cmdbuf)
        if (CtdlAccessCheck(ac_aide))
                return;
 
-       extract(requested_user, cmdbuf, 0);
+       extract_token(requested_user, cmdbuf, 0, '|', sizeof requested_user);
        if (lgetuser(&usbuf, requested_user) != 0) {
                cprintf("%d No such user.\n", ERROR + NO_SUCH_USER);
                return;
        }
        np = num_parms(cmdbuf);
        if (np > 1)
-               extract(usbuf.password, cmdbuf, 1);
+               extract_token(usbuf.password, cmdbuf, 1, '|', sizeof usbuf.password);
        if (np > 2)
                usbuf.flags = extract_int(cmdbuf, 2);
        if (np > 3)