changeset 1851:d66d53f57e43 HEAD

Added bsdauth support, patch by Dan Cross
author Timo Sirainen <tss@iki.fi>
date Wed, 29 Oct 2003 16:10:20 +0200
parents e19d3d8632b7
children 29729fa90bb2
files configure.in src/auth/Makefile.am src/auth/passdb-bsdauth.c src/auth/passdb.c src/auth/passdb.h
diffstat 5 files changed, 92 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/configure.in	Wed Oct 29 15:53:12 2003 +0200
+++ b/configure.in	Wed Oct 29 16:10:20 2003 +0200
@@ -89,6 +89,15 @@
 	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 @@
 	])
 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, [
--- a/src/auth/Makefile.am	Wed Oct 29 15:53:12 2003 +0200
+++ b/src/auth/Makefile.am	Wed Oct 29 16:10:20 2003 +0200
@@ -31,6 +31,7 @@
 	mech-digest-md5.c \
 	mycrypt.c \
 	passdb.c \
+	passdb-bsdauth.c \
 	passdb-ldap.c \
 	passdb-passwd.c \
 	passdb-passwd-file.c \
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/auth/passdb-bsdauth.c	Wed Oct 29 16:10:20 2003 +0200
@@ -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
--- a/src/auth/passdb.c	Wed Oct 29 15:53:12 2003 +0200
+++ b/src/auth/passdb.c	Wed Oct 29 16:10:20 2003 +0200
@@ -86,6 +86,10 @@
 	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;
--- a/src/auth/passdb.h	Wed Oct 29 15:53:12 2003 +0200
+++ b/src/auth/passdb.h	Wed Oct 29 16:10:20 2003 +0200
@@ -52,6 +52,7 @@
 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;