Hi all,

        I'm sending the patch for the getpwnam_helper. Now it's more useful for
systems that don't have PAM, but want to authenticate from local users
(Slackware Linux, amongst others). It works too for the BSD systems that
don't use the shadow suite, and instead keep the functionality of the
getpwnam(3) call. The helper must be run as root, or have the setuid bit
set, as the PAM helper does. I also think that some documentation is
needed, there is some problem if i write it?

        I tested the helper on Linux and OpenBSD, without a hassle.

Thanks in advance,
-- 
Giancarlo Razzolini
Linux User 172199
Moleque Sem Conteudo Numero #002
Slackware Current
OpenBSD Stable
Snike Tecnologia em Informática
4386 2A6F FFD4 4D5F 5842  6EA0 7ABE BBAB 9C0E 6B85
--- getpwnam_auth.c     2005-04-24 13:28:16.000000000 -0300
+++ getpwnam_auth.c.new 2006-06-08 14:23:02.000000000 -0300
@@ -39,6 +39,9 @@
 #if HAVE_PWD_H
 #include <pwd.h>
 #endif
+#if HAVE_SHADOW_H
+#include <shadow.h>
+#endif
 
 #include "util.h"
 
@@ -49,7 +52,11 @@
 main()
 {
     char buf[256];
+#if HAVE_SHADOW_H
+    struct spwd *pwd;
+#else
     struct passwd *pwd;
+#endif
     char *user, *passwd, *p;
 
     setbuf(stdout, NULL);
@@ -68,11 +75,19 @@
        }
        rfc1738_unescape(user);
        rfc1738_unescape(passwd);
+#if HAVE_SHADOW_H
+       pwd = getspnam(user);
+#else
        pwd = getpwnam(user);
+#endif
        if (pwd == NULL) {
            printf("ERR No such user\n");
        } else {
+#if HAVE_SHADOW_H
+           if (strcmp(pwd->sp_pwdp, crypt(passwd, pwd->sp_pwdp))) {
+#else
            if (strcmp(pwd->pw_passwd, (char *) crypt(passwd, pwd->pw_passwd))) 
{
+#endif
                printf("ERR Wrong password\n");
            } else {
                printf(OK);
21ca63095e16066e0215f4c89f5487c3  getpwnam_auth.c.patch

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to