]> granicus.if.org Git - shadow/commitdiff
* libmisc/non_interactive_pam_conv.c,
authornekral-guest <nekral-guest@5a98b0ae-9ef6-0310-add3-de5d479b70d7>
Sat, 9 May 2009 13:15:25 +0000 (13:15 +0000)
committernekral-guest <nekral-guest@5a98b0ae-9ef6-0310-add3-de5d479b70d7>
Sat, 9 May 2009 13:15:25 +0000 (13:15 +0000)
libmisc/pam_pass_non_interractive.c, libmisc/Makefile.am: Renamed.
* libmisc/pam_pass_non_interractive.c, lib/prototypes.h:
non_interactive_password and non_interactive_pam_conv do not need
to be externally visible.
* libmisc/pam_pass_non_interractive.c: Added declaration of
ni_conv.
* libmisc/pam_pass_non_interractive.c: Only compile ifdef USE_PAM.
* libmisc/pam_pass_non_interractive.c, lib/prototypes.h:
Added do_pam_passwd_non_interractive().
* src/chpasswd.c: Use do_pam_passwd_non_interractive().

ChangeLog
lib/prototypes.h
libmisc/Makefile.am
libmisc/pam_pass_non_interractive.c [moved from libmisc/non_interactive_pam_conv.c with 73% similarity]
src/chpasswd.c

index 0d2d4900cf51997fba094e3c052a245258c4089b..45fde2b0eeef15c49a1bf805237076faea3fe221 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2009-05-07  Nicolas François  <nicolas.francois@centraliens.net>
+
+       * libmisc/non_interactive_pam_conv.c,
+       libmisc/pam_pass_non_interractive.c, libmisc/Makefile.am: Renamed.
+       * libmisc/pam_pass_non_interractive.c, lib/prototypes.h:
+       non_interactive_password and non_interactive_pam_conv do not need
+       to be externally visible.
+       * libmisc/pam_pass_non_interractive.c: Added declaration of
+       ni_conv.
+       * libmisc/pam_pass_non_interractive.c: Only compile ifdef USE_PAM.
+       * libmisc/pam_pass_non_interractive.c, lib/prototypes.h:
+       Added do_pam_passwd_non_interractive().
+       * src/chpasswd.c: Use do_pam_passwd_non_interractive().
+
 2009-05-07  Nicolas François  <nicolas.francois@centraliens.net>
 
        * libmisc/pam_pass.c: Removed comment regarding pam_misc. This is
index dfeedfecae482dc934d71b3cb4a8f7372ba390de..f2c7ebbbc15f1a4d378b329036f0ede35333914d 100644 (file)
@@ -238,9 +238,10 @@ extern void motd (void);
 /* myname.c */
 extern /*@null@*/struct passwd *get_my_pwent (void);
 
-/* non_interactive_pam_conv.c */
-/*@null@*/ /*@only@*/extern char *non_interactive_password;
-extern struct pam_conv non_interactive_pam_conv;
+/* pam_pass_non_interractive.c */
+extern int do_pam_passwd_non_interractive (const char *pam_service,
+                                           const char *username,
+                                           const char* password)
 
 /* obscure.c */
 #ifndef USE_PAM
index 12ee065a309ad9c739214fe8913c1fbe573772a0..8b577b29bfc92224c614adce588b37c86f9c56c1 100644 (file)
@@ -38,9 +38,9 @@ libmisc_a_SOURCES = \
        mail.c \
        motd.c \
        myname.c \
-       non_interactive_pam_conv.c \
        obscure.c \
        pam_pass.c \
+       pam_pass_non_interractive.c \
        pwd2spwd.c \
        pwdcheck.c \
        pwd_init.c \
similarity index 73%
rename from libmisc/non_interactive_pam_conv.c
rename to libmisc/pam_pass_non_interractive.c
index e1f2dcb48a3e65ba4176201b62562c963d14e57b..7c597249b267fb2166df905789e38021e033bfb5 100644 (file)
@@ -31,6 +31,7 @@
 
 #ident "$Id:$"
 
+#ifdef USE_PAM
 #include <assert.h>
 #include <string.h>
 #include <stdio.h>
 #include <security/pam_appl.h>
 #include "prototypes.h"
 
-/*@null@*/ /*@only@*/char *non_interactive_password = NULL;
+/*@null@*/ /*@only@*/static char *non_interactive_password = NULL;
+static int ni_conv (int num_msg,
+                    const struct pam_message **msg,
+                    struct pam_response **resp,
+                    unused void *appdata_ptr);
+static struct pam_conv non_interactive_pam_conv = {
+       ni_conv,
+       NULL
+};
+
 
 
 static int ni_conv (int num_msg,
                     const struct pam_message **msg,
                     struct pam_response **resp,
-                    unused void *appdata_ptr) {
+                    unused void *appdata_ptr)
+{
        struct pam_response *responses;
        int count;
 
@@ -117,8 +128,38 @@ failed_conversation:
        return PAM_CONV_ERR;
 }
 
-struct pam_conv non_interactive_pam_conv = {
-       ni_conv,
-       NULL
-};
 
+/*
+ * Change non interactively the user's password using PAM.
+ *
+ * Return 0 on success, 1 on failure.
+ */
+int do_pam_passwd_non_interractive (const char *pam_service,
+                                    const char *username,
+                                    const char* password)
+{
+       pam_handle_t *pamh = NULL;
+       int ret;
+
+       ret = pam_start (pam_service, username, &non_interactive_pam_conv, &pamh);
+       if (ret != PAM_SUCCESS) {
+               fprintf (stderr,
+                        _("%s: (user %s) pam_start failure %d\n"),
+                        Prog, username, ret);
+               return 1;
+       }
+
+       non_interactive_password = password;
+       ret = pam_chauthtok (pamh, 0);
+       if (ret != PAM_SUCCESS) {
+               fprintf (stderr,
+                        _("%s: (user %s) pam_chauthtok() failed, error:\n"
+                          "%s\n"),
+                        Prog, username, pam_strerror (pamh, ret));
+       }
+
+       (void) pam_end (pamh, PAM_SUCCESS);
+}
+#else                          /* !USE_PAM */
+extern int errno;              /* warning: ANSI C forbids an empty source file */
+#endif                         /* !USE_PAM */
index 53ef8a33d3b6572452b6504349e9ecd752545a4a..8bb5797bef001b03e617dc970b8845ca45701f8b 100644 (file)
@@ -465,35 +465,12 @@ int main (int argc, char **argv)
                newpwd = cp;
 
 #ifdef USE_PAM
-               pam_handle_t *pamh = NULL;
-               int ret;
-               ret = pam_start ("chpasswd", name, &non_interactive_pam_conv, &pamh);
-               if (ret != PAM_SUCCESS) {
+               if (do_pam_passwd_non_interractive ("chpasswd", name, newpwd) != 0) {
                        fprintf (stderr,
-                                _("chpasswd: (user %s) pam_start failure %d\n"),
-                                name, ret);
-                       fprintf (stderr,
-                                _("chpasswd: (user %s) password unchanged\n"),
-                                name);
-                       errors++;
-                       continue;
+                                _("%s: (line %d, user %s) password not changed\n"),
+                                Prog, line, name);
+                       error++;
                }
-
-               non_interactive_password = newpwd;
-               ret = pam_chauthtok (pamh, 0);
-               if (ret != PAM_SUCCESS) {
-                       fprintf (stderr, _("chpasswd: (line %d, user %s) pam_chauthtok() failed, error:\n"
-                                          "          %s\n"),
-                                        line, name, pam_strerror (pamh, ret));
-                       fprintf (stderr,
-                                _("chpasswd: (line %d, user %s) password unchanged\n"),
-                                line, name);
-                       errors++;
-                       continue;
-               }
-
-               (void) pam_end (pamh, PAM_SUCCESS);
-
 #else                          /* !USE_PAM */
                if (   !eflg
                    && (   (NULL == crypt_method)