Nicholas Marriott schrieb am 08.07.2011 um 18:40:46 +0100:
> I think this is wrong. WHat do you expect this line to do?
> 
> > +     user = name;

> I think modifying user might be better left outside.

See diff below.  In my opinion however, extracting the user from the
user:style input, should be done in auth_userpass(), so I left it there.

> Also:
> 
> - You don't need endpwent() for getpwnam() so you can remove that.
> 
> - One of those silly _XFOOBAR defines hides the strsep definition. I
>   guess they can just be removed.
> 
> - gcc shows some other warnings as well.

Done.

Nils
Index: auth_passwd.c
===================================================================
RCS file: /cvs/src/usr.sbin/popa3d/auth_passwd.c,v
retrieving revision 1.2
diff -u -r1.2 auth_passwd.c
--- auth_passwd.c       21 Sep 2001 20:22:06 -0000      1.2
+++ auth_passwd.c       10 Jul 2011 10:14:33 -0000
@@ -1,39 +1,39 @@
 /* $OpenBSD: auth_passwd.c,v 1.2 2001/09/21 20:22:06 camield Exp $ */
 
 /*
- * The /etc/passwd authentication routine.
+ * The BSD authentication routine.
  */
 
 #include "params.h"
 
-#if AUTH_PASSWD && !VIRTUAL_ONLY
+#if BSD_AUTH && !VIRTUAL_ONLY
 
-#define _XOPEN_SOURCE 4
-#define _XOPEN_SOURCE_EXTENDED
-#define _XOPEN_VERSION 4
-#define _XPG4_2
 #include <unistd.h>
 #include <string.h>
 #include <pwd.h>
 #include <sys/types.h>
+#include <login_cap.h>
+#include <bsd_auth.h>
 
-struct passwd *auth_userpass(char *user, char *pass, int *known)
+struct passwd *auth_userpass(char **user, char *pass, int *known)
 {
        struct passwd *pw, *result;
+       char *name;
 
-       *known = (pw = getpwnam(user)) != NULL;
-       endpwent();
+       pw = NULL;
        result = NULL;
 
-       if (!pw || !*pw->pw_passwd ||
-           *pw->pw_passwd == '*' || *pw->pw_passwd == '!')
-               crypt(pass, AUTH_DUMMY_SALT);
-       else
-       if (!strcmp(crypt(pass, pw->pw_passwd), pw->pw_passwd))
+       if ((name = strsep(user, ":")) != NULL)
+               *known = (pw = getpwnam(name)) != NULL;
+
+       if (pw && auth_userokay(name, *user, BSD_AUTH_TYPE, pass))
                result = pw;
 
        if (pw)
                memset(pw->pw_passwd, 0, strlen(pw->pw_passwd));
+
+       if (name != NULL)
+               *user = name;
 
        return result;
 }
Index: params.h
===================================================================
RCS file: /cvs/src/usr.sbin/popa3d/params.h,v
retrieving revision 1.9
diff -u -r1.9 params.h
--- params.h    16 Dec 2009 20:42:26 -0000      1.9
+++ params.h    10 Jul 2011 10:14:33 -0000
@@ -142,15 +142,23 @@
 /*
  * Choose the password authentication method your system uses:
  *
- * AUTH_PASSWD         Use getpwnam(3) only, for *BSD or readable passwd;
- *
- * Note that there's no built-in password aging support.
+ * BSD_AUTH            Use BSD Authentication.
+ * 
  */
-#define AUTH_PASSWD                    1
+#define BSD_AUTH                       1
+
+#if BSD_AUTH
+
+/*
+ * BSD Authentication type
+ */
+#define BSD_AUTH_TYPE                  "auth-popa3d"
+
+#endif
 
 #endif
 
-#if POP_VIRTUAL || AUTH_PASSWD
+#if POP_VIRTUAL
 
 /*
  * A salt used to waste some CPU time on dummy crypt(3) calls and make
Index: pop_root.c
===================================================================
RCS file: /cvs/src/usr.sbin/popa3d/pop_root.c,v
retrieving revision 1.5
diff -u -r1.5 pop_root.c
--- pop_root.c  3 May 2005 05:44:35 -0000       1.5
+++ pop_root.c  10 Jul 2011 10:14:33 -0000
@@ -9,7 +9,7 @@
  * startup.c           if supporting command line options (POP_OPTIONS)
  * standalone.c                if not running via an inetd clone 
(POP_STANDALONE)
  * virtual.c           if supporting virtual domains (POP_VIRTUAL)
- * auth_passwd.c       if using passwd or *BSD (AUTH_PASSWD && !VIRTUAL_ONLY)
+ * auth_passwd.c       if using BSD Auth. (BSD_AUTH && !VIRTUAL_ONLY)
  */
 
 #include <unistd.h>
@@ -34,7 +34,7 @@
 #endif
 
 #if !VIRTUAL_ONLY
-extern struct passwd *auth_userpass(char *user, char *pass, int *known);
+extern struct passwd *auth_userpass(char **user, char *pass, int *known);
 #endif
 
 /* POP_USER's pw_uid and pw_gid, other fields may not be valid */
@@ -133,6 +133,8 @@
        user = auth;
        pass = &user[strlen(user) + 1];
 
+       if (!*user || !*pass) return AUTH_FAILED;
+
        pw = NULL;
 #if POP_VIRTUAL
        if (!(pw = virtual_userpass(user, pass, &known)) && virtual_domain) {
@@ -145,15 +147,18 @@
                memset(pass, 0, strlen(pass));
                return AUTH_FAILED;
        }
+#elif BSD_AUTH
+       if (!pw && !(pw = auth_userpass(&user, pass, &known))) {
+               memset(pass, 0, strlen(pass));
+               return AUTH_FAILED;
+       }
 #else
-       if (!pw && !(pw = auth_userpass(user, pass, &known))) {
+       if (!pw) {
                memset(pass, 0, strlen(pass));
                return AUTH_FAILED;
        }
 #endif
-       if (!*pass) return AUTH_FAILED;
        memset(pass, 0, strlen(pass));
-       if (!*user) return AUTH_FAILED;
 
 #if VIRTUAL_ONLY
        if (!virtual_domain) return AUTH_FAILED;
Index: popa3d.8
===================================================================
RCS file: /cvs/src/usr.sbin/popa3d/popa3d.8,v
retrieving revision 1.14
diff -u -r1.14 popa3d.8
--- popa3d.8    31 May 2007 19:20:27 -0000      1.14
+++ popa3d.8    10 Jul 2011 10:14:33 -0000
@@ -102,6 +102,12 @@
 .Pp
 .Dl pop3 stream tcp nowait root /usr/libexec/tcpd /usr/sbin/popa3d
 .Pp
+.Nm
+uses BSD Authentication with authentication type
+.Dq auth-popa3d
+for the given username and password ; see
+.Xr login.conf 5 .
+.Pp
 For access to a mailbox through the POP3 service, the username must
 be in the password database.
 Additionally,
@@ -165,6 +171,7 @@
 .Sh SEE ALSO
 .Xr hosts_access 5 ,
 .Xr inetd 8 ,
+.Xr login.conf 5 ,
 .Xr sendmail 8 ,
 .Xr tcpd 8
 .Pp

Reply via email to