$OpenBSD: patch-configure_ac,v 1.6 2011/11/30 11:13:47 ajacoutot Exp $

From d7ab99c00a01bea870cf51d855ecf320e0d23bac Mon Sep 17 00:00:00 2001
From: Antoine Jacoutot <ajacoutot@openbsd.org>
Date: Wed, 30 Nov 2011 12:02:48 +0100
Subject: [PATCH] Implement OpenBSD authentication using bsd_auth(3).

--- configure.ac.orig	Tue Sep  6 21:38:29 2011
+++ configure.ac	Thu Sep  8 09:05:00 2011
@@ -448,6 +448,45 @@ if test "$ac_macosx" = yes; then
 fi
 
 dnl ---------------------------------------------------------------------------
+dnl - Check for bsd_auth(3) (OpenBSD)
+dnl ---------------------------------------------------------------------------
+
+have_bsdauth=no
+with_bsdauth_req=unspecified
+NEED_SETUID=no
+
+case "$host" in                                                                                       
+  *-openbsd*)                                                                                         
+    with_bsdauth=yes
+    AUTH_SCHEME=bsdauth
+    NEED_SETUID=no
+    if test "x$enable_locking" = "xyes"; then
+      with_bsdauth_req=yes
+      NEED_SETUID=yes
+    fi
+esac  
+
+if test "$with_bsdauth" = yes ; then
+  AC_CACHE_CHECK([for BSD Authentication], ac_cv_bsdauth,
+    [AC_TRY_X_COMPILE([#include <stdlib.h>
+                       #include <unistd.h>
+                       #include <sys/types.h>
+                       #include <bsd_auth.h>],
+      [int ok = auth_userokay("x", 0, "x", "x");],
+      [ac_cv_bsdauth=yes],
+      [ac_cv_bsdauth=no])])
+  if test "$ac_cv_bsdauth" = yes; then
+    have_bsdauth=yes
+  fi
+fi
+
+if test "$have_bsdauth" = yes; then
+  AC_DEFINE(HAVE_BSDAUTH, 1, [Define to 1 if using bsd_auth(3) authentication])
+fi
+
+AC_SUBST(NEED_SETUID)
+
+dnl ---------------------------------------------------------------------------
 dnl - Check for PAM
 dnl ---------------------------------------------------------------------------
 
@@ -467,12 +506,13 @@ fi
 AC_SUBST(PAM_PREFIX)
 
 have_pam=no
-if test "x$enable_locking" = "xyes"; then
+if test "x$enable_locking" = "xyes" -a "x$have_bsdauth" = "xno"; then
 AC_CHECK_LIB(pam, pam_start, have_pam=yes)
 fi
 
 if test "x$have_pam" = "xyes"; then
         AUTH_LIBS="${AUTH_LIBS} -lpam"
+        AUTH_SCHEME=pam
         # On Linux, sigtimedwait() is in libc; on Solaris, it's in librt.
         have_timedwait=no
         AC_CHECK_LIB(c, sigtimedwait, [have_timedwait=yes])
@@ -506,14 +546,17 @@ if test "x$have_pam" = "xyes"; then
           AC_MSG_RESULT(unknown)
         fi
 
-else
+elif test "x$have_bsdauth" = "xno"; then
 	AC_MSG_ERROR("PAM libraries not found")
 fi
 AC_SUBST(HAVE_PAM)
 AC_SUBST(AUTH_LIBS)
+AC_SUBST(AUTH_SCHEME)
 
-AC_CHECK_HEADERS([security/pam_modutil.h security/pam_ext.h])
-AC_CHECK_LIB(pam, pam_syslog, [AC_DEFINE(HAVE_PAM_SYSLOG, [], [Define to 1 if you have the pam_syslog function])])
+if test "x$have_pam" = "xyes"; then
+  AC_CHECK_HEADERS([security/pam_modutil.h security/pam_ext.h])
+  AC_CHECK_LIB(pam, pam_syslog, [AC_DEFINE(HAVE_PAM_SYSLOG, [], [Define to 1 if you have the pam_syslog function])])
+fi
 
 dnl test whether struct pam_message is const (Linux) or not (Sun)
 if test "x$have_pam" = "xyes"; then
@@ -695,7 +738,12 @@ echo "
 
         Screen locking enabled:   ${enable_locking}
         Show keyboard indicator:  ${with_kbd_layout_indicator}
+"
+
+if test "x$have_pam" = "xyes" ; then
+echo "\
         PAM prefix:               ${PAM_PREFIX}
 
 "
+fi
 
