[Pam-developers] [PATCH] pam_mkhomedir: check and create home directory for the same user (ticket #22)

Dmitry V. Levin ldv at altlinux.org
Mon Jan 20 03:38:16 UTC 2014


Before pam_mkhomedir helper was introduced in commit
7b14630ef39e71f603aeca0c47edf2f384717176, pam_mkhomedir was checking for
existance and creating the same directory - the home directory of the
user NAME returned by pam_get_item(PAM_USER).

The change in behaviour accidentally introduced along with
mkhomedir_helper is not consistent: while the module still checks for
getpwnam(NAME)->pw_dir, the directory created by mkhomedir_helper is
getpwnam(getpwnam(NAME)->pw_name)->pw_dir, which is not necessarily
the same as the directory being checked.

This change brings check and creation back in sync, both handling
getpwnam(NAME)->pw_dir.

* modules/pam_mkhomedir/pam_mkhomedir.c (create_homedir): Replace
"struct passwd *" argument with user's name and home directory.
Pass user's name to MKHOMEDIR_HELPER.
(pam_sm_open_session): Update create_homedir call.
---
 modules/pam_mkhomedir/pam_mkhomedir.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/modules/pam_mkhomedir/pam_mkhomedir.c b/modules/pam_mkhomedir/pam_mkhomedir.c
index 5ac8a0f..0b5fc75 100644
--- a/modules/pam_mkhomedir/pam_mkhomedir.c
+++ b/modules/pam_mkhomedir/pam_mkhomedir.c
@@ -103,14 +103,14 @@ _pam_parse (const pam_handle_t *pamh, int flags, int argc, const char **argv,
 /* Do the actual work of creating a home dir */
 static int
 create_homedir (pam_handle_t *pamh, options_t *opt,
-		const struct passwd *pwd)
+		const char *user, const char *dir)
 {
    int retval, child;
    struct sigaction newsa, oldsa;
 
    /* Mention what is happening, if the notification fails that is OK */
    if (!(opt->ctrl & MKHOMEDIR_QUIET))
-      pam_info(pamh, _("Creating directory '%s'."), pwd->pw_dir);
+      pam_info(pamh, _("Creating directory '%s'."), dir);
 
 
    D(("called."));
@@ -146,7 +146,7 @@ create_homedir (pam_handle_t *pamh, options_t *opt,
 
 	/* exec the mkhomedir helper */
 	args[0] = x_strdup(MKHOMEDIR_HELPER);
-	args[1] = pwd->pw_name;
+	args[1] = (char *) user;
 	args[2] = x_strdup(opt->umask);
 	args[3] = x_strdup(opt->skeldir);
 
@@ -181,7 +181,7 @@ create_homedir (pam_handle_t *pamh, options_t *opt,
 
    if (retval != PAM_SUCCESS && !(opt->ctrl & MKHOMEDIR_QUIET)) {
 	pam_error(pamh, _("Unable to create and initialize directory '%s'."),
-	    pwd->pw_dir);
+		  dir);
    }
 
    D(("returning %d", retval));
@@ -230,7 +230,7 @@ pam_sm_open_session (pam_handle_t *pamh, int flags, int argc,
       return PAM_SUCCESS;
    }
 
-   return create_homedir(pamh, &opt, pwd);
+   return create_homedir(pamh, &opt, user, pwd->pw_dir);
 }
 
 /* Ignore */
-- 
ldv


More information about the Pam-developers mailing list