]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
Added bsdauth support, patch by Dan Cross
authorTimo Sirainen <tss@iki.fi>
Wed, 29 Oct 2003 14:10:20 +0000 (16:10 +0200)
committerTimo Sirainen <tss@iki.fi>
Wed, 29 Oct 2003 14:10:20 +0000 (16:10 +0200)
--HG--
branch : HEAD

configure.in
src/auth/Makefile.am
src/auth/passdb-bsdauth.c [new file with mode: 0644]
src/auth/passdb.c
src/auth/passdb.h

index 8072b3a954e6ca9c449523ac18c863bb8eb939f2..fcfeb1ed427f16ce1be1d20bcf8979eb303e8e22 100644 (file)
@@ -89,6 +89,15 @@ AC_ARG_WITH(pam,
        fi,
        want_pam=yes)
 
+AC_ARG_WITH(bsdauth,
+[  --with-bsdauth          Build with BSD authentication support (default)],
+       if test x$withval = xno; then
+               want_bsdauth=no
+       else
+               want_bsdauth=yes
+       fi,
+       want_bsdauth=yes)
+
 AC_ARG_WITH(ldap,
 [  --with-ldap             Build with LDAP support],
        if test x$withval = xno; then
@@ -938,6 +947,13 @@ if test $want_pam = yes; then
        ])
 fi
 
+if test $want_bsdauth = yes; then
+       AC_CHECK_FUNC(auth_userokay, [
+               AC_DEFINE(PASSDB_BSDAUTH,, Build with BSD authentication support)
+               passdb="$passdb bsdauth"
+       ])
+fi
+
 if test $want_ldap = yes; then
        AC_CHECK_LIB(ldap, ldap_init, [
                AC_CHECK_HEADER(ldap.h, [
index 1cc13d8208792f30bcd9f7388ab759b3eeee4071..b4814d081c0fb7b9d2f069d577217d81e04e87c1 100644 (file)
@@ -31,6 +31,7 @@ dovecot_auth_SOURCES = \
        mech-digest-md5.c \
        mycrypt.c \
        passdb.c \
+       passdb-bsdauth.c \
        passdb-ldap.c \
        passdb-passwd.c \
        passdb-passwd-file.c \
diff --git a/src/auth/passdb-bsdauth.c b/src/auth/passdb-bsdauth.c
new file mode 100644 (file)
index 0000000..037c968
--- /dev/null
@@ -0,0 +1,70 @@
+/* Copyright (C) 2002-2003 Timo Sirainen */
+
+#include "config.h"
+#undef HAVE_CONFIG_H
+
+#ifdef PASSDB_BSDAUTH
+
+#include "common.h"
+#include "safe-memset.h"
+#include "passdb.h"
+#include "mycrypt.h"
+
+#include <login_cap.h>
+#include <bsd_auth.h>
+#include <pwd.h>
+
+static void
+bsdauth_verify_plain(struct auth_request *request, const char *password,
+                   verify_plain_callback_t *callback)
+{
+       struct passwd *pw;
+       int result;
+
+       pw = getpwnam(request->user);
+       if (pw == NULL) {
+               if (verbose)
+                       i_info("passwd(%s): unknown user", request->user);
+               callback(PASSDB_RESULT_USER_UNKNOWN, request);
+               return;
+       }
+
+       if (!IS_VALID_PASSWD(pw->pw_passwd)) {
+               if (verbose) {
+                       i_info("passwd(%s): invalid password field '%s'",
+                              request->user, pw->pw_passwd);
+               }
+               callback(PASSDB_RESULT_USER_DISABLED, request);
+               return;
+       }
+
+       /* check if the password is valid */
+       result = auth_userokay(request->user, NULL, NULL, password);
+
+       /* clear the passwords from memory */
+       safe_memset(pw->pw_passwd, 0, strlen(pw->pw_passwd));
+
+       if (!result) {
+               if (verbose)
+                       i_info("passwd(%s): password mismatch", request->user);
+               callback(PASSDB_RESULT_PASSWORD_MISMATCH, request);
+               return;
+       }
+
+       callback(PASSDB_RESULT_OK, request);
+}
+
+static void bsdauth_deinit(void)
+{
+       endpwent();
+}
+
+struct passdb_module passdb_bsdauth = {
+       NULL,
+       bsdauth_deinit,
+
+       bsdauth_verify_plain,
+       NULL
+};
+
+#endif
index ea68602b44ed1cfc60bca5604fb6d1559b47bb71..6e6fe281d0bc60b967878cf7b08e1fb5ec311883 100644 (file)
@@ -86,6 +86,10 @@ void passdb_init(void)
        if (strcasecmp(name, "passwd") == 0)
                passdb = &passdb_passwd;
 #endif
+#ifdef PASSDB_BSDAUTH
+       if (strcasecmp(name, "bsdauth") == 0)
+               passdb = &passdb_bsdauth;
+#endif
 #ifdef PASSDB_PASSWD_FILE
        if (strcasecmp(name, "passwd-file") == 0)
                passdb = &passdb_passwd_file;
index 4d28f37aff12dbde160b2e253f38d8d312a8d84d..2650f52d4acf11cb832508e668ee8698a956ed82 100644 (file)
@@ -52,6 +52,7 @@ void passdb_handle_credentials(enum passdb_credentials credentials,
 extern struct passdb_module *passdb;
 
 extern struct passdb_module passdb_passwd;
+extern struct passdb_module passdb_bsdauth;
 extern struct passdb_module passdb_shadow;
 extern struct passdb_module passdb_passwd_file;
 extern struct passdb_module passdb_pam;