Index: /trunk/src/VBox/Runtime/r3/posix/process-creation-posix.cpp
===================================================================
--- /trunk/src/VBox/Runtime/r3/posix/process-creation-posix.cpp	(revision 81250)
+++ /trunk/src/VBox/Runtime/r3/posix/process-creation-posix.cpp	(revision 81251)
@@ -80,6 +80,16 @@
 #endif
 
-#ifdef RT_OS_DARWIN
-# include <mach-o/dyld.h>
+#if !defined(IPRT_USE_PAM) && ( defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD) || defined(RT_OS_OPENBSD) )
+# define IPRT_USE_PAM
+#endif
+#ifdef IPRT_USE_PAM
+# ifdef RT_OS_DARWIN
+#  include <mach-o/dyld.h>
+#  define IPRT_LIBPAM_FILE      "libpam.dylib"
+#  define IPRT_PAM_SERVICE_NAME "login"     /** @todo we've been abusing 'login' here, probably not needed? */
+# else
+#  define IPRT_LIBPAM_FILE      "libpam.so"
+#  define IPRT_PAM_SERVICE_NAME "iprt-as-user"
+# endif
 # include <security/pam_appl.h>
 # include <stdlib.h>
@@ -126,5 +136,5 @@
 *   Structures and Typedefs                                                                                                      *
 *********************************************************************************************************************************/
-#ifdef RT_OS_DARWIN
+#ifdef IPRT_USE_PAM
 /** For passing info between rtCheckCredentials and rtPamConv. */
 typedef struct RTPROCPAMARGS
@@ -138,5 +148,5 @@
 
 
-#ifdef RT_OS_DARWIN
+#ifdef IPRT_USE_PAM
 /**
  * Worker for rtCheckCredentials that feeds password and maybe username to PAM.
@@ -183,8 +193,8 @@
     return PAM_SUCCESS;
 }
-#endif /* RT_OS_DARWIN */
-
-
-#ifdef IPRT_WITH_DYNAMIC_CRYPT_R
+#endif /* IPRT_USE_PAM */
+
+
+#if defined(IPRT_WITH_DYNAMIC_CRYPT_R) && !defined(IPRT_USE_PAM)
 /** Pointer to crypt_r(). */
 typedef char *(*PFNCRYPTR)(const char *, const char *, struct crypt_data *);
@@ -230,5 +240,5 @@
 static int rtCheckCredentials(const char *pszUser, const char *pszPasswd, gid_t *pGid, uid_t *pUid)
 {
-#if defined(RT_OS_DARWIN)
+#ifdef IPRT_USE_PAM
     RTLogPrintf("rtCheckCredentials\n");
 
@@ -251,5 +261,5 @@
      * Note! libpam.2.dylib was introduced with 10.6.x (OpenPAM).
      */
-    void *hModPam = dlopen("libpam.dylib", RTLD_LAZY | RTLD_GLOBAL);
+    void *hModPam = dlopen(IPRT_LIBPAM_FILE, RTLD_LAZY | RTLD_GLOBAL);
     if (hModPam)
     {
@@ -271,12 +281,11 @@
             && pfnPamEnd)
         {
-#define pam_start           pfnPamStart
-#define pam_authenticate    pfnPamAuthenticate
-#define pam_acct_mgmt       pfnPamAcctMgmt
-#define pam_set_item        pfnPamSetItem
-#define pam_end             pfnPamEnd
-
-            /* Do the PAM stuff.
-               Note! Abusing 'login' here for now... */
+# define pam_start           pfnPamStart
+# define pam_authenticate    pfnPamAuthenticate
+# define pam_acct_mgmt       pfnPamAcctMgmt
+# define pam_set_item        pfnPamSetItem
+# define pam_end             pfnPamEnd
+
+            /* Do the PAM stuff. */
             pam_handle_t   *hPam        = NULL;
             RTPROCPAMARGS   PamConvArgs = { pszUser, pszPasswd };
@@ -285,5 +294,5 @@
             PamConversation.appdata_ptr = &PamConvArgs;
             PamConversation.conv        = rtPamConv;
-            int rc = pam_start("login", pszUser, &PamConversation, &hPam);
+            int rc = pam_start(IPRT_PAM_SERVICE_NAME, pszUser, &PamConversation, &hPam);
             if (rc == PAM_SUCCESS)
             {
@@ -316,5 +325,5 @@
     }
     else
-        Log(("rtCheckCredentials: Loading libpam.dylib failed\n"));
+        Log(("rtCheckCredentials: Loading " IPRT_LIBPAM_FILE " failed\n"));
     return VERR_AUTHENTICATION_FAILURE;
 
