directoryservice.cpp revision 289566e681dae45f110170f26eaa0bff964e50f9
/** @file
*
* VirtualBox External Authentication Library:
* Mac OS X Authentication. This is based on
*/
/*
* Copyright (C) 2009-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.
*/
#include <VBox/VBoxAuth.h>
#include <DirectoryService/DirectoryService.h>
/* Globals */
{
/* Create a buffer for the resulting nodes */
if (pTmpBuf)
{
/* Try to find the default search node for local names */
/* Any nodes found? */
&& cNodes >= 1)
/* The first path of the node list is what we looking for. */
else
if (pCtx)
}
else
return dsErr;
}
tDirStatus userAuthInfo(tDirReference pDirRef, tDirNodeReference pNodeRef, const char *pszUsername, tDataListPtr *ppAuthNodeListOut)
{
/* Create a buffer for the resulting authentication info */
if (pTmpBuf)
{
/* Create the necessary lists for kDSNAttrMetaNodeLocation and kDSNAttrRecordName. */
tDataListPtr pRequestedAttributes = dsBuildListFromStrings(pDirRef, kDSNAttrMetaNodeLocation, kDSNAttrRecordName, NULL);
if (!( pRecordType == NULL
|| pRecordName == NULL
|| pRequestedAttributes == NULL))
{
/* Now search for the first matching record */
false,
&cRecords,
&pCtx);
&& cRecords >= 1)
{
/* Process the first found record. Look at any attribute one by one. */
{
{
/* Get the information for this attribute. */
{
/* Has any value? */
if (pAttrEntry->fAttributeValueCount > 0)
{
{
/* Check for kDSNAttrMetaNodeLocation */
{
/* Convert the meta location attribute to a path node list */
"/");
if (pAuthNodeList == NULL)
}
}
}
if (pValueEntry != NULL)
if (pAttrValueListRef)
if (pAttrEntry != NULL)
break;
}
}
}
/* Copy the results */
{
if (pAuthNodeList != NULL)
{
/* Copy out results. */
}
else
}
if (pAuthNodeList != NULL)
{
if (dsCleanErr == eDSNoErr)
}
if (pRecAttrListRef)
}
else
if (pCtx)
}
else
if (pRequestedAttributes != NULL)
{
if (dsCleanErr == eDSNoErr)
}
if (pRecordName != NULL)
{
if (dsCleanErr == eDSNoErr)
}
if (pRecordType != NULL)
{
if (dsCleanErr == eDSNoErr)
}
}
else
return dsErr;
}
tDirStatus authWithNode(tDirReference pDirRef, tDataListPtr pAuthNodeList, const char *pszUsername, const char *pszPassword)
{
/* Open the authentication node. */
{
/* How like we to authenticate! */
if (pAuthMethod)
{
/* Create the memory holding the authentication data. The data
* structure consists of 4 byte length of the username + zero byte,
* the username itself, a 4 byte length of the password & the
* password itself + zero byte. */
if (pAuthOutBuf)
{
unsigned long cLen = 0;
tDataBufferPtr pAuthInBuf = dsDataBufferAllocate(pDirRef, sizeof(cLen) + cUserName + sizeof(cLen) + cPassword);
if (pAuthInBuf)
{
/* Move the data into the buffer. */
pAuthInBuf->fBufferLength = 0;
/* Length of the username */
/* The username itself */
/* Length of the password */
/* The password itself */
/* Now authenticate */
/* Clean up. */
}
else
}
else
}
else
}
return dsErr;
}
const char *szUser,
const char *szPassword,
const char *szDomain,
int fLogon,
unsigned clientId)
{
/* Validate input */
/* Result to a default value */
/* Only process logon requests. */
if (!fLogon)
return result; /* Return value is ignored by the caller. */
/* Connect to the Directory Service. */
{
/* Fetch the default search node */
{
/* Open the default search node */
{
/* Search for the user info, fetch the authentication node &
* the authentication user name. This allows the client to
* specify a long user name even if the name which is used to
* authenticate has the short form. */
{
/* Open the authentication node and do the authentication. */
if (dsCleanErr == eDSNoErr)
}
}
if (dsCleanErr == eDSNoErr)
}
}
return result;
}