]> code.citadel.org Git - citadel.git/blobdiff - citadel/user_ops.c
* Moved login-to-screenname code ... no longer part of CtdlTryExistingUser(),
[citadel.git] / citadel / user_ops.c
index 534a0102d9996eb9ea1b9e0887d85b524f76c4f9..195573fdb9d27a43211963a9fd82b554a95d5dd9 100644 (file)
@@ -17,6 +17,7 @@
 #include <fcntl.h>
 #include <signal.h>
 #include <pwd.h>
+#include <ctype.h>
 #include <sys/types.h>
 #include <sys/wait.h>
 
@@ -41,7 +42,7 @@
 #include "server.h"
 #include "database.h"
 #include "user_ops.h"
-#include "dynloader.h"
+#include "serv_extensions.h"
 #include "sysdep_decls.h"
 #include "support.h"
 #include "room_ops.h"
@@ -66,9 +67,17 @@ int getuser(struct usersupp *usbuf, char name[])
        struct cdbdata *cdbus;
 
        memset(usbuf, 0, sizeof(struct usersupp));
-       for (a = 0; a <= strlen(name); ++a) {
-               if (a < sizeof(lowercase_name))
-                       lowercase_name[a] = tolower(name[a]);
+
+       if (CtdlAssociateSystemUser(lowercase_name, name) == 0) {
+               for (a = 0; a <= strlen(lowercase_name); ++a) {
+                       lowercase_name[a] = tolower(lowercase_name[a]);
+               }
+       }
+       else {
+               for (a = 0; a <= strlen(name); ++a) {
+                       if (a < sizeof(lowercase_name))
+                               lowercase_name[a] = tolower(name[a]);
+               }
        }
        lowercase_name[sizeof(lowercase_name) - 1] = 0;
 
@@ -304,16 +313,36 @@ int getuserbynumber(struct usersupp *usbuf, long int number)
 }
 
 
+/*
+ * See if we can translate a system login name (i.e. from /etc/passwd)
+ * to a Citadel screen name.  Returns 0 if one is found.
+ */
+int CtdlAssociateSystemUser(char *screenname, char *loginname) {
+       struct passwd *p;
+       int a;
+
+       p = (struct passwd *) getpwnam(loginname);
+       if (p != NULL) {
+               strcpy(screenname, p->pw_gecos);
+               for (a = 0; a < strlen(screenname); ++a) {
+                       if (screenname[a] == ',') {
+                               screenname[a] = 0;
+                       }
+               }
+               return(0);
+       }
+       return(1);
+}
+
+
+
 /*
  * Back end for cmd_user() and its ilk
  */
 int CtdlLoginExistingUser(char *trythisname)
 {
        char username[SIZ];
-       char autoname[SIZ];
-       int found_user = 0;
-       struct passwd *p;
-       int a;
+       int found_user;
 
        if (trythisname == NULL) return login_not_found;
        safestrncpy(username, trythisname, sizeof username);
@@ -322,17 +351,9 @@ int CtdlLoginExistingUser(char *trythisname)
        if ((CC->logged_in)) {
                return login_already_logged_in;
        }
+
        found_user = getuser(&CC->usersupp, username);
-       if (found_user != 0) {
-               p = (struct passwd *) getpwnam(username);
-               if (p != NULL) {
-                       strcpy(autoname, p->pw_gecos);
-                       for (a = 0; a < strlen(autoname); ++a)
-                               if (autoname[a] == ',')
-                                       autoname[a] = 0;
-                       found_user = getuser(&CC->usersupp, autoname);
-               }
-       }
+
        if (found_user == 0) {
                if (((CC->nologin)) && (CC->usersupp.axlevel < 6)) {
                        return login_too_many_users;
@@ -388,6 +409,8 @@ void cmd_user(char *cmdbuf)
  */
 void session_startup(void)
 {
+       int i;
+
        syslog(LOG_NOTICE, "session %d: user <%s> logged in",
               CC->cs_pid, CC->curr_user);
 
@@ -403,6 +426,19 @@ void session_startup(void)
        }
        lputuser(&CC->usersupp);
 
+       /*
+        * Populate CC->cs_inet_email with a default address.  This will be
+        * overwritten with the user's directory address, if one exists, when
+        * the vCard module's login hook runs.
+        */
+       snprintf(CC->cs_inet_email, sizeof CC->cs_inet_email, "%s@%s",
+               CC->usersupp.fullname, config.c_fqdn);
+       for (i=0; i<strlen(CC->cs_inet_email); ++i) {
+               if (isspace(CC->cs_inet_email[i])) {
+                       CC->cs_inet_email[i] = '_';
+               }
+       }
+
        /* Create any personal rooms required by the system.
         * (Technically, MAILROOM should be there already, but just in case...)
         */
@@ -460,14 +496,6 @@ void logout(struct CitContext *who)
                network_talking_to(who->net_node, NTT_REMOVE);
        }
 
-       /*
-        * Yes, we really need to free EVERY LAST BYTE we allocated.
-        */
-       if (who->cs_inet_email != NULL) {
-               phree(who->cs_inet_email);
-               who->cs_inet_email = NULL;
-       }
-
        /* Do modular stuff... */
        PerformSessionHooks(EVT_LOGOUT);
 }
@@ -1287,7 +1315,7 @@ void cmd_chek(void)
        /* check for mail */
        mail = InitialMailCheck();
 
-       cprintf("%d %d|%d|%d\n", CIT_OK, mail, regis, vali);
+       cprintf("%d %d|%d|%d|%s|\n", CIT_OK, mail, regis, vali, CC->cs_inet_email);
 }