VirtualBox

Changeset 81251 in vbox for trunk/src/VBox/Runtime


Ignore:
Timestamp:
Oct 14, 2019 11:41:46 AM (5 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
133946
Message:

IPRT/process-creation-posix.cpp: Generalized the PAM option and make *BSD use it to avoid adding lots of -lcrypt. ticketref:18682

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r3/posix/process-creation-posix.cpp

    r80569 r81251  
    8080#endif
    8181
    82 #ifdef RT_OS_DARWIN
    83 # include <mach-o/dyld.h>
     82#if !defined(IPRT_USE_PAM) && ( defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD) || defined(RT_OS_OPENBSD) )
     83# define IPRT_USE_PAM
     84#endif
     85#ifdef IPRT_USE_PAM
     86# ifdef RT_OS_DARWIN
     87#  include <mach-o/dyld.h>
     88#  define IPRT_LIBPAM_FILE      "libpam.dylib"
     89#  define IPRT_PAM_SERVICE_NAME "login"     /** @todo we've been abusing 'login' here, probably not needed? */
     90# else
     91#  define IPRT_LIBPAM_FILE      "libpam.so"
     92#  define IPRT_PAM_SERVICE_NAME "iprt-as-user"
     93# endif
    8494# include <security/pam_appl.h>
    8595# include <stdlib.h>
     
    126136*   Structures and Typedefs                                                                                                      *
    127137*********************************************************************************************************************************/
    128 #ifdef RT_OS_DARWIN
     138#ifdef IPRT_USE_PAM
    129139/** For passing info between rtCheckCredentials and rtPamConv. */
    130140typedef struct RTPROCPAMARGS
     
    138148
    139149
    140 #ifdef RT_OS_DARWIN
     150#ifdef IPRT_USE_PAM
    141151/**
    142152 * Worker for rtCheckCredentials that feeds password and maybe username to PAM.
     
    183193    return PAM_SUCCESS;
    184194}
    185 #endif /* RT_OS_DARWIN */
    186 
    187 
    188 #ifdef IPRT_WITH_DYNAMIC_CRYPT_R
     195#endif /* IPRT_USE_PAM */
     196
     197
     198#if defined(IPRT_WITH_DYNAMIC_CRYPT_R) && !defined(IPRT_USE_PAM)
    189199/** Pointer to crypt_r(). */
    190200typedef char *(*PFNCRYPTR)(const char *, const char *, struct crypt_data *);
     
    230240static int rtCheckCredentials(const char *pszUser, const char *pszPasswd, gid_t *pGid, uid_t *pUid)
    231241{
    232 #if defined(RT_OS_DARWIN)
     242#ifdef IPRT_USE_PAM
    233243    RTLogPrintf("rtCheckCredentials\n");
    234244
     
    251261     * Note! libpam.2.dylib was introduced with 10.6.x (OpenPAM).
    252262     */
    253     void *hModPam = dlopen("libpam.dylib", RTLD_LAZY | RTLD_GLOBAL);
     263    void *hModPam = dlopen(IPRT_LIBPAM_FILE, RTLD_LAZY | RTLD_GLOBAL);
    254264    if (hModPam)
    255265    {
     
    271281            && pfnPamEnd)
    272282        {
    273 #define pam_start           pfnPamStart
    274 #define pam_authenticate    pfnPamAuthenticate
    275 #define pam_acct_mgmt       pfnPamAcctMgmt
    276 #define pam_set_item        pfnPamSetItem
    277 #define pam_end             pfnPamEnd
    278 
    279             /* Do the PAM stuff.
    280                Note! Abusing 'login' here for now... */
     283# define pam_start           pfnPamStart
     284# define pam_authenticate    pfnPamAuthenticate
     285# define pam_acct_mgmt       pfnPamAcctMgmt
     286# define pam_set_item        pfnPamSetItem
     287# define pam_end             pfnPamEnd
     288
     289            /* Do the PAM stuff. */
    281290            pam_handle_t   *hPam        = NULL;
    282291            RTPROCPAMARGS   PamConvArgs = { pszUser, pszPasswd };
     
    285294            PamConversation.appdata_ptr = &PamConvArgs;
    286295            PamConversation.conv        = rtPamConv;
    287             int rc = pam_start("login", pszUser, &PamConversation, &hPam);
     296            int rc = pam_start(IPRT_PAM_SERVICE_NAME, pszUser, &PamConversation, &hPam);
    288297            if (rc == PAM_SUCCESS)
    289298            {
     
    316325    }
    317326    else
    318         Log(("rtCheckCredentials: Loading libpam.dylib failed\n"));
     327        Log(("rtCheckCredentials: Loading " IPRT_LIBPAM_FILE " failed\n"));
    319328    return VERR_AUTHENTICATION_FAILURE;
    320329
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette