]> code.citadel.org Git - citadel.git/blobdiff - citadel/user_ops.c
* Bump internal version number to 6.08
[citadel.git] / citadel / user_ops.c
index 195573fdb9d27a43211963a9fd82b554a95d5dd9..a631c2cee2bb525c547206444b6089a294a036fa 100644 (file)
@@ -46,7 +46,6 @@
 #include "sysdep_decls.h"
 #include "support.h"
 #include "room_ops.h"
-#include "logging.h"
 #include "file_ops.h"
 #include "control.h"
 #include "msgbase.h"
@@ -63,14 +62,22 @@ int getuser(struct usersupp *usbuf, char name[])
 {
 
        char lowercase_name[USERNAME_SIZE];
+       char sysuser_name[USERNAME_SIZE];
        int a;
        struct cdbdata *cdbus;
+       int using_sysuser = 0;
 
        memset(usbuf, 0, sizeof(struct usersupp));
 
-       if (CtdlAssociateSystemUser(lowercase_name, name) == 0) {
-               for (a = 0; a <= strlen(lowercase_name); ++a) {
-                       lowercase_name[a] = tolower(lowercase_name[a]);
+#ifdef ENABLE_AUTOLOGIN
+       if (CtdlAssociateSystemUser(sysuser_name, name) == 0) {
+               ++using_sysuser;
+       }
+#endif
+
+       if (using_sysuser) {
+               for (a = 0; a <= strlen(sysuser_name); ++a) {
+                       lowercase_name[a] = tolower(sysuser_name[a]);
                }
        }
        else {
@@ -82,8 +89,8 @@ int getuser(struct usersupp *usbuf, char name[])
        lowercase_name[sizeof(lowercase_name) - 1] = 0;
 
        cdbus = cdb_fetch(CDB_USERSUPP, lowercase_name, strlen(lowercase_name));
-       if (cdbus == NULL) {
-               return (1);     /* user not found */
+       if (cdbus == NULL) {    /* user not found */
+               return(1);
        }
        memcpy(usbuf, cdbus->ptr,
               ((cdbus->len > sizeof(struct usersupp)) ?
@@ -416,6 +423,7 @@ void session_startup(void)
 
        lgetuser(&CC->usersupp, CC->curr_user);
        ++(CC->usersupp.timescalled);
+       CC->previous_login = CC->usersupp.lastcall;
        time(&CC->usersupp.lastcall);
 
        /* If this user's name is the name of the system administrator
@@ -450,9 +458,6 @@ void session_startup(void)
 
        /* Enter the lobby */
        usergoto(config.c_baseroom, 0, 0, NULL, NULL);
-
-       /* Record this login in the Citadel log */
-       rec_log(CL_LOGIN, CC->curr_user);
 }
 
 
@@ -462,7 +467,7 @@ void logged_in_response(void)
                CIT_OK, CC->usersupp.fullname, CC->usersupp.axlevel,
                CC->usersupp.timescalled, CC->usersupp.posted,
                CC->usersupp.flags, CC->usersupp.usernum,
-               CC->usersupp.lastcall);
+               CC->previous_login);
 }
 
 
@@ -586,12 +591,18 @@ int CtdlTryPassword(char *password)
                return pass_wrong_password;
        }
        code = (-1);
-       if (CC->usersupp.uid == BBSUID) {
+
+
+#ifdef ENABLE_AUTOLOGIN
+       /* A uid of BBSUID or -1 indicates that this user exists only in
+        * Citadel, not in the underlying operating system.
+        */
+       if ( (CC->usersupp.uid == BBSUID) || (CC->usersupp.uid == (-1)) ) {
                strproc(password);
                strproc(CC->usersupp.password);
                code = strcasecmp(CC->usersupp.password, password);
        }
-#ifdef ENABLE_AUTOLOGIN
+       /* Any other uid means we have to check the system password database */
        else {
                if (validpw(CC->usersupp.uid, password)) {
                        code = 0;
@@ -601,13 +612,19 @@ int CtdlTryPassword(char *password)
                        lputuser(&CC->usersupp);
                }
        }
-#endif
+
+#else /* ENABLE_AUTOLOGIN */
+       strproc(password);
+       strproc(CC->usersupp.password);
+       code = strcasecmp(CC->usersupp.password, password);
+
+#endif /* ENABLE_AUTOLOGIN */
 
        if (!code) {
                do_login();
                return pass_ok;
        } else {
-               rec_log(CL_BADPW, CC->curr_user);
+               lprintf(3, "Bad password specified for <%s>\n", CC->curr_user);
                return pass_wrong_password;
        }
 }
@@ -724,13 +741,15 @@ int create_user(char *newusername, int become_user)
 
 #ifdef ENABLE_AUTOLOGIN
        p = (struct passwd *) getpwnam(username);
-#endif
        if (p != NULL) {
                extract_token(username, p->pw_gecos, 0, ',');
                uid = p->pw_uid;
        } else {
-               uid = BBSUID;
+               uid = (-1);
        }
+#else
+       uid = (-1);
+#endif
 
        if (!getuser(&usbuf, username)) {
                return (ERROR + ALREADY_EXISTS);
@@ -772,7 +791,7 @@ int create_user(char *newusername, int become_user)
 
        MailboxName(mailboxname, sizeof mailboxname, &usbuf, USERCONFIGROOM);
        create_room(mailboxname, 5, "", 0, 1, 1);
-        if (lgetroom(&qrbuf, USERCONFIGROOM) == 0) {
+        if (lgetroom(&qrbuf, mailboxname) == 0) {
                 qrbuf.QRflags2 |= QR2_SYSTEM;
                 lputroom(&qrbuf);
         }
@@ -791,10 +810,9 @@ int create_user(char *newusername, int become_user)
                if (getuser(&CC->usersupp, CC->curr_user)) {
                        return (ERROR + INTERNAL_ERROR);
                }
-       
-               rec_log(CL_NEWUSER, CC->curr_user);
        }
 
+       lprintf(3, "New user <%s> created\n", username);
        return (0);
 }
 
@@ -856,7 +874,6 @@ void cmd_newu(char *cmdbuf)
        } else {
                cprintf("%d unknown error\n", ERROR);
        }
-       rec_log(CL_NEWUSER, CC->curr_user);
 }
 
 
@@ -869,8 +886,7 @@ void cmd_setp(char *new_pw)
        if (CtdlAccessCheck(ac_logged_in)) {
                return;
        }
-
-       if (CC->usersupp.uid != BBSUID) {
+       if ( (CC->usersupp.uid != BBSUID) && (CC->usersupp.uid != (-1)) ) {
                cprintf("%d Not allowed.  Use the 'passwd' command.\n", ERROR);
                return;
        }
@@ -883,7 +899,7 @@ void cmd_setp(char *new_pw)
        strcpy(CC->usersupp.password, new_pw);
        lputuser(&CC->usersupp);
        cprintf("%d Password changed.\n", CIT_OK);
-       rec_log(CL_PWCHANGE, CC->curr_user);
+       lprintf(3, "Password changed for user <%s>\n", CC->curr_user);
        PerformSessionHooks(EVT_SETPASS);
 }
 
@@ -921,7 +937,6 @@ void cmd_creu(char *cmdbuf)
        } else {
                cprintf("%d An error occured creating the user account.\n", ERROR);
        }
-       rec_log(CL_NEWUSER, username);
 }