#include "citadel_dirs.h"
#include "genstamp.h"
#include "threads.h"
+#include "serv_vcard.h" /* FIXME: Get this dependancy out. Needed for vcard_add_alias */
/* These pipes are used to talk to the chkpwd daemon, which is forked during startup */
int chkpwd_write_pipe[2];
char username[SIZ];
int found_user;
+ lprintf(9, "CtdlLoginExistingUser(%s, %s)\n", authname, trythisname);
+
if ((CC->logged_in)) {
return login_already_logged_in;
}
char pwdbuffer[256];
lprintf(CTDL_DEBUG, "asking host about <%s>\n", username);
+#ifdef HAVE_GETPWNAM_R
#ifdef SOLARIS_GETPWUID
+ lprintf(CTDL_DEBUG, "Calling getpwnam_r()\n");
tempPwdPtr = getpwnam_r(username, &pd, pwdbuffer, sizeof pwdbuffer);
-#else
+#else // SOLARIS_GETPWUID
+ lprintf(CTDL_DEBUG, "Calling getpwnam_r()\n");
getpwnam_r(username, &pd, pwdbuffer, sizeof pwdbuffer, &tempPwdPtr);
-#endif
+#endif // SOLARIS_GETPWUID
+#else // HAVE_GETPWNAM_R
+ lprintf(CTDL_DEBUG, "SHOULD NEVER GET HERE!!!\n");
+ tempPwdPtr = NULL;
+#endif // HAVE_GETPWNAM_R
if (tempPwdPtr == NULL) {
+ lprintf(CTDL_DEBUG, "no such user <%s>\n", username);
return login_not_found;
}
* If not found, make one attempt to create it.
*/
found_user = getuserbyuid(&CC->user, pd.pw_uid);
- lprintf(CTDL_DEBUG, "found it: uid=%ld, gecos=%s here: %ld\n", (long)pd.pw_uid, pd.pw_gecos, found_user);
+ lprintf(CTDL_DEBUG, "found it: uid=%ld, gecos=%s here: %d\n",
+ (long)pd.pw_uid, pd.pw_gecos, found_user);
if (found_user != 0) {
create_user(username, 0);
found_user = getuserbyuid(&CC->user, pd.pw_uid);
/* Do modular stuff... */
PerformSessionHooks(EVT_LOGOUT);
+
+ /* Check to see if the user was deleted whilst logged in and purge them if necessary */
+ if (who->user.axlevel == 0)
+ purge_user(who->user.fullname);
/* Free any output buffers */
if (who->output_buffer != NULL) {
{
char buf[256];
+ if (IsEmptyStr(pass)) {
+ lprintf(CTDL_DEBUG, "refusing to check empty password for uid=%d using chkpwd...\n", uid);
+ return 0;
+ }
+
lprintf(CTDL_DEBUG, "Validating password for uid=%d using chkpwd...\n", uid);
begin_critical_section(S_CHKPWD);
makeuserkey(usernamekey, pname);
+ /* If the name is empty we can't find them in the DB any way so just return */
+ if (IsEmptyStr(pname))
+ return (ERROR + NO_SUCH_USER);
+
if (getuser(&usbuf, pname) != 0) {
lprintf(CTDL_ERR, "Cannot purge user <%s> - not found\n", pname);
return (ERROR + NO_SUCH_USER);
}
+
+
/*
* create_user() - back end processing to create a new user
*
struct passwd *tempPwdPtr;
char pwdbuffer[256];
+#ifdef HAVE_GETPWNAM_R
#ifdef SOLARIS_GETPWUID
tempPwdPtr = getpwnam_r(username, &pd, pwdbuffer, sizeof(pwdbuffer));
-#else
+#else // SOLARIS_GETPWUID
getpwnam_r(username, &pd, pwdbuffer, sizeof pwdbuffer, &tempPwdPtr);
-#endif
+#endif // SOLARIS_GETPWUID
+#else // HAVE_GETPWNAM_R
+ tempPwdPtr = NULL;
+#endif // HAVE_GETPWNAM_R
if (tempPwdPtr != NULL) {
extract_token(username, pd.pw_gecos, 0, ',', sizeof username);
uid = pd.pw_uid;
/* Perform any create functions registered by server extensions */
PerformUserHooks(&usbuf, EVT_NEWUSER);
+ /* In host auth mode the user was created with an email address of the users
+ * full name from the passwd gecos field.
+ * Not sure what would have happened if that wasn't set to something
+ * but thats another story
+ * We need to add an email alias to the users vCard for the proper username
+ */
+ if (config.c_auth_mode == AUTHMODE_HOST)
+ {
+ char user_alias[SIZ];
+
+ if (strcmp(username, newusername))
+ {
+ sprintf(user_alias, "%s@%s", newusername, config.c_fqdn);
+ vcard_add_alias(&usbuf, user_alias);
+ }
+ }
+
/* Everything below this line can be bypassed if administratively
* creating a user, instead of doing self-service account creation
*/
}
if (deleted) {
- sprintf(notify, "User \"%s\" has been deleted by %s.\n",
- usbuf.fullname, CC->user.fullname);
+ snprintf(notify, SIZ,
+ "User \"%s\" has been deleted by %s.\n",
+ usbuf.fullname, CC->user.fullname);
aide_message(notify, "User Deletion Message");
}