]> code.citadel.org Git - citadel.git/blobdiff - citadel/user_ops.c
* Merge LDAP code; bindings are not yet complete
[citadel.git] / citadel / user_ops.c
index 6baed0b2ee2607b20cba91b333a19c4d3ecec395..b574fbd02fde850c39447eb2a9c5211f814d7faf 100644 (file)
@@ -50,6 +50,7 @@
 #include "citadel_dirs.h"
 #include "genstamp.h"
 #include "threads.h"
+#include "citadel_ldap.h"
 
 /* These pipes are used to talk to the chkpwd daemon, which is forked during startup */
 int chkpwd_write_pipe[2];
@@ -541,6 +542,13 @@ int CtdlLoginExistingUser(char *authname, char *trythisname)
 
        }
 
+#ifdef HAVE_LDAP
+       else if (config.c_auth_mode == AUTHMODE_LDAP) {
+
+               /* LDAP auth mode FIXME_LDAP */
+       }
+#endif
+
        else {
                /* native auth mode */
 
@@ -728,9 +736,7 @@ void logout(void)
                purge_user(CCC->user.fullname);
 
        /* Free any output buffers */
-       if (CCC->output_buffer != NULL) {
-               unbuffer_output();
-       }
+       unbuffer_output();
 }
 
 /*
@@ -862,6 +868,13 @@ int CtdlTryPassword(char *password)
                }
        }
 
+#ifdef HAVE_LDAP
+       else if (config.c_auth_mode == AUTHMODE_LDAP) {
+
+               /* LDAP auth mode FIXME_LDAP */
+       }
+#endif
+
        else {
 
                /* native auth mode */
@@ -984,6 +997,40 @@ int purge_user(char pname[])
 }
 
 
+int internal_create_user (char *username, struct ctdluser *usbuf, uid_t uid)
+{
+       if (!getuser(usbuf, username)) {
+               return (ERROR + ALREADY_EXISTS);
+       }
+
+       /* Go ahead and initialize a new user record */
+       memset(usbuf, 0, sizeof(struct ctdluser));
+       safestrncpy(usbuf->fullname, username, sizeof usbuf->fullname);
+       strcpy(usbuf->password, "");
+       usbuf->uid = uid;
+
+       /* These are the default flags on new accounts */
+       usbuf->flags = US_LASTOLD | US_DISAPPEAR | US_PAGINATOR | US_FLOORS;
+
+       usbuf->timescalled = 0;
+       usbuf->posted = 0;
+       usbuf->axlevel = config.c_initax;
+       usbuf->USscreenwidth = 80;
+       usbuf->USscreenheight = 24;
+       usbuf->lastcall = time(NULL);
+
+       /* fetch a new user number */
+       usbuf->usernum = get_new_user_number();
+
+       /* add user to the database */
+       putuser(usbuf);
+       cdb_store(CDB_USERSBYNUMBER, &usbuf->usernum, sizeof(long), usbuf->fullname, strlen(usbuf->fullname)+1);
+
+       return 0;
+}
+
+
+
 /*
  * create_user()  -  back end processing to create a new user
  *
@@ -998,11 +1045,14 @@ int create_user(char *newusername, int become_user)
        char username[256];
        char mailboxname[ROOMNAMELEN];
        char buf[SIZ];
+       int retval;
        uid_t uid = (-1);
+       
 
        safestrncpy(username, newusername, sizeof username);
        strproc(username);
 
+       
        if (config.c_auth_mode == AUTHMODE_HOST) {
 
                /* host auth mode */
@@ -1025,14 +1075,7 @@ int create_user(char *newusername, int become_user)
                        uid = pd.pw_uid;
                        if (IsEmptyStr (username))
                        {
-                               CtdlLogPrintf (CTDL_EMERG, 
-                                        "Can't find Realname for user %s [%d] in the Host Auth Database; giving up.\n", 
-                                        newusername, pd.pw_uid);
-                               snprintf(buf, SIZ, 
-                                        "Can't find Realname for user %s [%d] in the Host Auth Database; giving up.\n",
-                                        newusername, pd.pw_uid);
-                               aide_message(buf, "User Creation Failure Notice");
-
+                               safestrncpy(username, pd.pw_name, sizeof username);
                        }
                }
                else {
@@ -1040,38 +1083,11 @@ int create_user(char *newusername, int become_user)
                }
        }
 
-       if (!getuser(&usbuf, username)) {
-               return (ERROR + ALREADY_EXISTS);
-       }
-
-       /* Go ahead and initialize a new user record */
-       memset(&usbuf, 0, sizeof(struct ctdluser));
-       safestrncpy(usbuf.fullname, username, sizeof usbuf.fullname);
-       strcpy(usbuf.password, "");
-       usbuf.uid = uid;
-
-       /* These are the default flags on new accounts */
-       usbuf.flags = US_LASTOLD | US_DISAPPEAR | US_PAGINATOR | US_FLOORS;
-
-       usbuf.timescalled = 0;
-       usbuf.posted = 0;
-       usbuf.axlevel = config.c_initax;
-       usbuf.USscreenwidth = 80;
-       usbuf.USscreenheight = 24;
-       usbuf.lastcall = time(NULL);
-
-       /* fetch a new user number */
-       usbuf.usernum = get_new_user_number();
-
-       /* The very first user created on the system will always be an Aide */
-       if (usbuf.usernum == 1L) {
-               usbuf.axlevel = 6;
-       }
-
-       /* add user to the database */
-       putuser(&usbuf);
-       cdb_store(CDB_USERSBYNUMBER, &usbuf.usernum, sizeof(long), usbuf.fullname, strlen(usbuf.fullname)+1);
-
+       /* FIXME_LDAP put something here */
+       
+       if ((retval = internal_create_user(username, &usbuf, uid)) != 0)
+               return retval;
+       
        /*
         * Give the user a private mailbox and a configuration room.
         * Make the latter an invisible system room.
@@ -1118,7 +1134,6 @@ int create_user(char *newusername, int become_user)
 
 
 
-
 /*
  * cmd_newu()  -  create a new user account and log in as that user
  */
@@ -1648,16 +1663,13 @@ void ListThisUser(struct ctdluser *usbuf, void *data)
                if ((CC->user.axlevel >= 6)
                    || ((usbuf->flags & US_UNLISTED) == 0)
                    || ((CC->internal_pgm))) {
-                       cprintf("%s|%d|%ld|%ld|%ld|%ld|",
+                       cprintf("%s|%d|%ld|%ld|%ld|%ld||\n",
                                usbuf->fullname,
                                usbuf->axlevel,
                                usbuf->usernum,
                                (long)usbuf->lastcall,
                                usbuf->timescalled,
                                usbuf->posted);
-                       if (CC->user.axlevel >= 6)
-                               cprintf("%s", usbuf->password);
-                       cprintf("\n");
                }
        }
 }