pam_vbox.cpp revision 01de116143b6de7123f7799e9f9b47d112b1091e
/* $Id$ */
/** @file
* pam_vbox - PAM module for auto logons.
*/
/*
* Copyright (C) 2008-2011 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#define PAM_SM_AUTH
#define PAM_SM_ACCOUNT
#define PAM_SM_PASSWORD
#define PAM_SM_SESSION
#ifdef DEBUG
# define PAM_DEBUG
#endif
#ifdef RT_OS_SOLARIS
# include <security/pam_appl.h>
#endif
#include <security/pam_modules.h>
#include <security/pam_appl.h>
#ifdef RT_OS_LINUX
# include <security/_pam_macros.h>
#endif
#include <pwd.h>
#include <syslog.h>
#include <stdlib.h>
#include <iprt/initterm.h>
#include <VBox/VBoxGuestLib.h>
#ifdef VBOX_WITH_GUEST_PROPS
using namespace guestProp;
#endif
#define VBOX_MODULE_NAME "pam_vbox"
/** For debugging. */
#ifdef DEBUG
static pam_handle_t *g_pam_handle;
static int g_verbosity = 99;
#else
static int g_verbosity = 0;
#endif
/**
* Write to system log.
*
* @param pszBuf Buffer to write to the log (NULL-terminated)
*/
static void pam_vbox_writesyslog(char *pszBuf)
{
#ifdef RT_OS_LINUX
closelog();
#elif defined(RT_OS_SOLARIS)
#endif
}
/**
* Displays an error message.
*
* @param pszFormat The message text.
* @param ... Format arguments.
*/
{
char *buf;
{
}
}
/**
* Displays a debug message.
*
* @param pszFormat The message text.
* @param ... Format arguments.
*/
{
if (g_verbosity)
{
char *buf;
{
/* Only do normal logging in debug mode; could contain
* sensitive data! */
/* Log to syslog */
}
}
}
{
if (!iStyle)
int rc = VINF_SUCCESS;
#ifdef RT_OS_SOLARIS
#else
#endif
#ifdef RT_OS_SOLARIS
#else
#endif
if ( pamrc == PAM_SUCCESS
&& conv)
{
#ifdef RT_OS_SOLARIS
#else
#endif
{
{
/** @todo Save response! */
}
}
}
else
rc = VERR_NOT_FOUND;
return rc;
}
{
#ifdef DEBUG
#endif
/* Don't make assertions panic because the PAM stack +
* the current logon module won't work anymore (or just restart).
* This could result in not able to log into the system anymore. */
RTAssertSetMayPanic(false);
if (RT_FAILURE(rc))
{
return PAM_SUCCESS; /* Jump out as early as we can to not mess around. */
}
if (RT_SUCCESS(rc))
{
rc = VbglR3InitUser();
if (RT_FAILURE(rc))
{
switch(rc)
{
case VERR_ACCESS_DENIED:
pam_vbox_error(hPAM, "pam_vbox_init: access is denied to guest driver! Please make sure you run with sufficient rights. Aborting\n");
break;
case VERR_FILE_NOT_FOUND:
pam_vbox_error(hPAM, "pam_vbox_init: guest driver not found! Guest Additions installed? Aborting\n");
break;
default:
break;
}
}
}
if (RT_SUCCESS(rc))
{
#ifdef RT_OS_SOLARIS
#else
#endif
}
return rc;
}
{
VbglR3Term();
}
{
int rc = VbglR3CredentialsQueryAvailability();
if (RT_FAILURE(rc))
{
if (rc == VERR_NOT_FOUND)
else
pam_vbox_error(hPAM, "pam_vbox_check_creds: could not query for credentials! rc=%Rrc. Aborting\n", rc);
}
else
{
char *pszUsername;
char *pszPassword;
char *pszDomain;
if (RT_FAILURE(rc))
{
pam_vbox_error(hPAM, "pam_vbox_check_creds: could not retrieve credentials! rc=%Rrc. Aborting\n", rc);
}
else
{
#ifdef DEBUG
pam_vbox_log(hPAM, "pam_vbox_check_creds: credentials retrieved: user=%s, password=%s, domain=%s\n",
#else
/* Don't log passwords in release mode! */
pam_vbox_log(hPAM, "pam_vbox_check_creds: credentials retrieved: user=%s, password=XXX, domain=%s\n",
#endif
/* Fill credentials into PAM. */
if (pamrc != PAM_SUCCESS)
{
}
else
{
if (pamrc != PAM_SUCCESS)
}
/** @todo Add handling domains as well. */
3 /* Three wipe passes */);
}
}
return rc;
}
#ifdef VBOX_WITH_GUEST_PROPS
{
int rc;
/* The buffer for storing the data and its initial size. We leave a bit
* of space here in case the maximum values are raised. */
int i;
for (i = 0; i < 10; i++)
{
if (pvTmpBuf)
{
uint64_t u64TimestampOut = 0;
0 /* Last timestamp; just wait for next event */, uTimeoutMS,
}
else
rc = VERR_NO_MEMORY;
switch (rc)
{
case VINF_SUCCESS:
break;
case VERR_BUFFER_OVERFLOW:
{
/* Buffer too small, try it with a bigger one next time. */
continue; /* Try next round. */
}
case VERR_INTERRUPTED:
break;
case VERR_TIMEOUT:
break;
case VERR_TOO_MUCH_DATA:
break;
default:
break;
}
/* Everything except VERR_BUFFER_OVERLOW makes us bail out ... */
break;
}
return rc;
}
{
if (RT_SUCCESS(rc))
return rc;
}
#endif
/**
* Performs authentication within the PAM framework.
*
* @todo
*/
{
/* Parse arguments. */
int i;
for (i = 0; i < argc; i++)
{
g_verbosity = 1;
else
}
if (RT_FAILURE(rc))
return PAM_SUCCESS; /* Jump out as early as we can to not mess around. */
bool fFallback = true;
#ifdef VBOX_WITH_GUEST_PROPS
if (RT_SUCCESS(rc))
{
char szVal[256];
if (RT_SUCCESS(rc))
{
/* All calls which are checked against rc2 are not critical, e.g. it does
* not matter if they succeed or not. */
if (RT_SUCCESS(rc2))
{
if (!uTimeoutMS)
{
pam_vbox_error(hPAM, "pam_sm_authenticate: invalid waiting timeout value specified, defaulting to infinite timeout\n");
}
else
}
const char *pszWaitMsg = NULL;
if (RT_SUCCESS(rc2))
pszWaitMsg = szVal;
pam_vbox_error(hPAM, "pam_sm_authenticate: error setting waiting information message, rc=%Rrc\n", rc2);
if (RT_SUCCESS(rc))
{
/* Before we actuall wait for credentials just make sure we didn't already get credentials
* set so that we can skip waiting for them ... */
if (rc == VERR_NOT_FOUND)
{
if (RT_SUCCESS(rc))
{
/* Waiting for credentials succeeded, try getting those ... */
if (RT_FAILURE(rc))
pam_vbox_error(hPAM, "pam_sm_authenticate: no credentials given, even when waited for it, rc=%Rrc\n", rc);
}
else if (rc == VERR_TIMEOUT)
{
if (RT_SUCCESS(rc2))
}
}
/* If we got here we don't need the fallback, so just deactivate it. */
fFallback = false;
}
}
}
#endif /* VBOX_WITH_GUEST_PROPS */
if (fFallback)
{
/* If anything went wrong in the code above we just do a credentials
* check like it was before: Try retrieving the stuff and authenticating. */
if (RT_SUCCESS(rc))
}
/* Never report an error here because if no credentials from the host are available or something
* went wrong we then let do the authentication by the next module in the stack. */
/* We report success here because this is all we can do right now -- we passed the credentials
* password verification to "really" authenticate the user. */
return PAM_SUCCESS;
}
/**
* Modifies / deletes user credentials
*
* @todo
*/
{
return PAM_SUCCESS;
}
{
return PAM_SUCCESS;
}
{
RTPrintf("This session was provided by VirtualBox Guest Additions. Have a lot of fun!\n");
return PAM_SUCCESS;
}
{
return PAM_SUCCESS;
}
{
return PAM_SUCCESS;
}
#ifdef DEBUG
DECLEXPORT(void) RTAssertMsg1Weak(const char *pszExpr, unsigned uLine, const char *pszFile, const char *pszFunction)
{
"\n!!Assertion Failed!!\n"
"Expression: %s\n"
"Location : %s(%d) %s\n",
}
#endif