#include "CLDAPConfigs.h"
#include <DirectoryServiceCore/CSharedData.h>
#include <CoreFoundation/CFPriv.h> // used for ::CFCopySearchPathForDirectoriesInDomains
#include <string.h> //used for strcpy, etc.
#include <stdlib.h> //used for malloc
#include <sys/types.h>
#include <sys/stat.h> //used for mkdir and stat
#include <DirectoryService/DirServices.h>
#include <DirectoryService/DirServicesUtils.h>
#include <DirectoryService/DirServicesConst.h>
#define kAllocatorDefault NULL
CLDAPConfigs::CLDAPConfigs ( void )
{
pConfigTable = nil;
pStdAttributeMapTuple = nil;
pStdRecordMapTuple = nil;
fConfigTableLen = 0;
fXMLData = nil;
}
CLDAPConfigs::~CLDAPConfigs ( void )
{
uInt32 iTableIndex = 0;
sInt32 siResult = eDSNoErr;
sLDAPConfigData *pConfig = nil;
for (iTableIndex=0; iTableIndex<fConfigTableLen; iTableIndex++)
{
pConfig = (sLDAPConfigData *)pConfigTable->GetItemData( iTableIndex );
if (pConfig != nil)
{
CleanLDAPConfigData( pConfig );
delete( pConfig );
pConfig = nil;
pConfigTable->RemoveItem( iTableIndex );
}
}
fConfigTableLen = 0;
if ( pConfigTable != nil)
{
delete ( pConfigTable );
pConfigTable = nil;
}
if (fXMLData != nil)
{
CFRelease(fXMLData);
fXMLData = nil;
}
siResult = CleanMapTuple(pStdAttributeMapTuple);
siResult = CleanMapTuple(pStdRecordMapTuple);
}
sInt32 CLDAPConfigs::Init ( CPlugInRef *inConfigTable, uInt32 &inConfigTableLen, sMapTuple **inStdAttributeMapTuple, sMapTuple **inStdRecordMapTuple )
{
sInt32 siResult = eDSNoErr;
sLDAPConfigData *pConfig = nil;
uInt32 sIndex = 0;
uInt32 iTableIndex = 0;
try
{
if (inConfigTableLen != 0)
{
fConfigTableLen = inConfigTableLen;
}
if ( inConfigTable == nil )
{
inConfigTable = new CPlugInRef( nil );
}
pConfigTable = inConfigTable;
if (!CheckForConfig((char *)"unknown", sIndex))
{
pConfig = MakeLDAPConfigData((char *)"Generic",(char *)"unknown",true,120,120,389,false, 0, 0);
pConfigTable->AddItem( fConfigTableLen, pConfig );
fConfigTableLen++;
}
if (fXMLData != nil)
{
CFRelease(fXMLData);
fXMLData = nil;
}
siResult = ReadXMLConfig();
if (siResult == eDSNoErr)
{
if (inConfigTableLen != 0)
{
for (iTableIndex=0; iTableIndex<fConfigTableLen; iTableIndex++)
{
pConfig = (sLDAPConfigData *)pConfigTable->GetItemData( iTableIndex );
if (pConfig != nil)
{
pConfig->bUpdated = false;
}
}
}
siResult = ConfigLDAPServers();
}
inConfigTableLen = fConfigTableLen;
if (pStdAttributeMapTuple == nil)
{
siResult = BuildDefaultStdAttributeMap();
}
if (pStdRecordMapTuple == nil)
{
siResult = BuildDefaultStdRecordMap();
}
if (inStdAttributeMapTuple != nil)
{
*inStdAttributeMapTuple = pStdAttributeMapTuple;
}
if (inStdRecordMapTuple != nil)
{
*inStdRecordMapTuple = pStdRecordMapTuple;
}
} catch( sInt32 err )
{
siResult = err;
}
return( siResult );
}
sInt32 CLDAPConfigs::BuildDefaultStdAttributeMap ( void )
{
sInt32 siResult = eDSNoErr;
sMapTuple *pAttrMapTuple = nil;
sPtrString *tempPtrString = nil;
if (pStdAttributeMapTuple != nil)
{
CleanMapTuple(pStdAttributeMapTuple);
pStdAttributeMapTuple = nil;
}
pAttrMapTuple = new sMapTuple;
if ( pAttrMapTuple != nil )
{
::memset( pAttrMapTuple, 0, sizeof( sMapTuple ) );
pAttrMapTuple->fStandard = new char[1+::strlen(kDSNAttrVFSOpts)];
::strcpy(pAttrMapTuple->fStandard,kDSNAttrVFSOpts);
pAttrMapTuple->fNative = new sPtrString;
if ( pAttrMapTuple->fNative != nil )
{
::memset( pAttrMapTuple->fNative, 0, sizeof( sPtrString ) );
pAttrMapTuple->fNative->fName = new char[1+::strlen("vfsopts")];
::strcpy(pAttrMapTuple->fNative->fName,"vfsopts");
pAttrMapTuple->fNative->pNext = nil;
}
pAttrMapTuple->pNext = pStdAttributeMapTuple;
pStdAttributeMapTuple = pAttrMapTuple;
pAttrMapTuple = nil;
}
pAttrMapTuple = new sMapTuple;
if ( pAttrMapTuple != nil )
{
::memset( pAttrMapTuple, 0, sizeof( sMapTuple ) );
pAttrMapTuple->fStandard = new char[1+::strlen(kDS1AttrVFSLinkDir)];
::strcpy(pAttrMapTuple->fStandard,kDS1AttrVFSLinkDir);
pAttrMapTuple->fNative = new sPtrString;
if ( pAttrMapTuple->fNative != nil )
{
::memset( pAttrMapTuple->fNative, 0, sizeof( sPtrString ) );
pAttrMapTuple->fNative->fName = new char[1+::strlen("vfsdir")];
::strcpy(pAttrMapTuple->fNative->fName,"vfsdir");
pAttrMapTuple->fNative->pNext = nil;
}
pAttrMapTuple->pNext = pStdAttributeMapTuple;
pStdAttributeMapTuple = pAttrMapTuple;
pAttrMapTuple = nil;
}
pAttrMapTuple = new sMapTuple;
if ( pAttrMapTuple != nil )
{
::memset( pAttrMapTuple, 0, sizeof( sMapTuple ) );
pAttrMapTuple->fStandard = new char[1+::strlen(kDS1AttrVFSDumpFreq)];
::strcpy(pAttrMapTuple->fStandard,kDS1AttrVFSDumpFreq);
pAttrMapTuple->fNative = new sPtrString;
if ( pAttrMapTuple->fNative != nil )
{
::memset( pAttrMapTuple->fNative, 0, sizeof( sPtrString ) );
pAttrMapTuple->fNative->fName = new char[1+::strlen("vfsdumpfreq")];
::strcpy(pAttrMapTuple->fNative->fName,"vfsdumpfreq");
pAttrMapTuple->fNative->pNext = nil;
}
pAttrMapTuple->pNext = pStdAttributeMapTuple;
pStdAttributeMapTuple = pAttrMapTuple;
pAttrMapTuple = nil;
}
pAttrMapTuple = new sMapTuple;
if ( pAttrMapTuple != nil )
{
::memset( pAttrMapTuple, 0, sizeof( sMapTuple ) );
pAttrMapTuple->fStandard = new char[1+::strlen(kDS1AttrVFSPassNo)];
::strcpy(pAttrMapTuple->fStandard,kDS1AttrVFSPassNo);
pAttrMapTuple->fNative = new sPtrString;
if ( pAttrMapTuple->fNative != nil )
{
::memset( pAttrMapTuple->fNative, 0, sizeof( sPtrString ) );
pAttrMapTuple->fNative->fName = new char[1+::strlen("passno")];
::strcpy(pAttrMapTuple->fNative->fName,"passno");
pAttrMapTuple->fNative->pNext = nil;
}
pAttrMapTuple->pNext = pStdAttributeMapTuple;
pStdAttributeMapTuple = pAttrMapTuple;
pAttrMapTuple = nil;
}
pAttrMapTuple = new sMapTuple;
if ( pAttrMapTuple != nil )
{
::memset( pAttrMapTuple, 0, sizeof( sMapTuple ) );
pAttrMapTuple->fStandard = new char[1+::strlen(kDS1AttrVFSType)];
::strcpy(pAttrMapTuple->fStandard,kDS1AttrVFSType);
pAttrMapTuple->fNative = new sPtrString;
if ( pAttrMapTuple->fNative != nil )
{
::memset( pAttrMapTuple->fNative, 0, sizeof( sPtrString ) );
pAttrMapTuple->fNative->fName = new char[1+::strlen("vfstype")];
::strcpy(pAttrMapTuple->fNative->fName,"vfstype");
pAttrMapTuple->fNative->pNext = nil;
}
pAttrMapTuple->pNext = pStdAttributeMapTuple;
pStdAttributeMapTuple = pAttrMapTuple;
pAttrMapTuple = nil;
}
pAttrMapTuple = new sMapTuple;
if ( pAttrMapTuple != nil )
{
::memset( pAttrMapTuple, 0, sizeof( sMapTuple ) );
pAttrMapTuple->fStandard = new char[1+::strlen(kDSNAttrIPAddress)];
::strcpy(pAttrMapTuple->fStandard,kDSNAttrIPAddress);
pAttrMapTuple->fNative = new sPtrString;
if ( pAttrMapTuple->fNative != nil )
{
::memset( pAttrMapTuple->fNative, 0, sizeof( sPtrString ) );
pAttrMapTuple->fNative->fName = new char[1+::strlen("ipaddress")];
::strcpy(pAttrMapTuple->fNative->fName,"ipaddress");
pAttrMapTuple->fNative->pNext = nil;
}
pAttrMapTuple->pNext = pStdAttributeMapTuple;
pStdAttributeMapTuple = pAttrMapTuple;
pAttrMapTuple = nil;
}
pAttrMapTuple = new sMapTuple;
if ( pAttrMapTuple != nil )
{
::memset( pAttrMapTuple, 0, sizeof( sMapTuple ) );
pAttrMapTuple->fStandard = new char[1+::strlen(kDSNAttrDNSName)];
::strcpy(pAttrMapTuple->fStandard,kDSNAttrDNSName);
pAttrMapTuple->fNative = new sPtrString;
if ( pAttrMapTuple->fNative != nil )
{
::memset( pAttrMapTuple->fNative, 0, sizeof( sPtrString ) );
pAttrMapTuple->fNative->fName = new char[1+::strlen("dnsname")];
::strcpy(pAttrMapTuple->fNative->fName,"dnsname");
pAttrMapTuple->fNative->pNext = nil;
}
pAttrMapTuple->pNext = pStdAttributeMapTuple;
pStdAttributeMapTuple = pAttrMapTuple;
pAttrMapTuple = nil;
}
pAttrMapTuple = new sMapTuple;
if ( pAttrMapTuple != nil )
{
::memset( pAttrMapTuple, 0, sizeof( sMapTuple ) );
pAttrMapTuple->fStandard = new char[1+::strlen(kDSNAttrURLForNSL)];
::strcpy(pAttrMapTuple->fStandard,kDSNAttrURLForNSL);
pAttrMapTuple->fNative = new sPtrString;
if ( pAttrMapTuple->fNative != nil )
{
::memset( pAttrMapTuple->fNative, 0, sizeof( sPtrString ) );
pAttrMapTuple->fNative->fName = new char[1+::strlen("networklocurl")];
::strcpy(pAttrMapTuple->fNative->fName,"networklocurl");
pAttrMapTuple->fNative->pNext = nil;
}
pAttrMapTuple->pNext = pStdAttributeMapTuple;
pStdAttributeMapTuple = pAttrMapTuple;
pAttrMapTuple = nil;
}
pAttrMapTuple = new sMapTuple;
if ( pAttrMapTuple != nil )
{
::memset( pAttrMapTuple, 0, sizeof( sMapTuple ) );
pAttrMapTuple->fStandard = new char[1+::strlen(kDSNAttrURL)];
::strcpy(pAttrMapTuple->fStandard,kDSNAttrURL);
pAttrMapTuple->fNative = new sPtrString;
if ( pAttrMapTuple->fNative != nil )
{
::memset( pAttrMapTuple->fNative, 0, sizeof( sPtrString ) );
pAttrMapTuple->fNative->fName = new char[1+::strlen("urldata")];
::strcpy(pAttrMapTuple->fNative->fName,"urldata");
pAttrMapTuple->fNative->pNext = nil;
}
pAttrMapTuple->pNext = pStdAttributeMapTuple;
pStdAttributeMapTuple = pAttrMapTuple;
pAttrMapTuple = nil;
}
pAttrMapTuple = new sMapTuple;
if ( pAttrMapTuple != nil )
{
::memset( pAttrMapTuple, 0, sizeof( sMapTuple ) );
pAttrMapTuple->fStandard = new char[1+::strlen(kDSNAttrNBPEntry)];
::strcpy(pAttrMapTuple->fStandard,kDSNAttrNBPEntry);
pAttrMapTuple->fNative = new sPtrString;
if ( pAttrMapTuple->fNative != nil )
{
::memset( pAttrMapTuple->fNative, 0, sizeof( sPtrString ) );
pAttrMapTuple->fNative->fName = new char[1+::strlen("nbpdata")];
::strcpy(pAttrMapTuple->fNative->fName,"nbpdata");
pAttrMapTuple->fNative->pNext = nil;
}
pAttrMapTuple->pNext = pStdAttributeMapTuple;
pStdAttributeMapTuple = pAttrMapTuple;
pAttrMapTuple = nil;
}
pAttrMapTuple = new sMapTuple;
if ( pAttrMapTuple != nil )
{
::memset( pAttrMapTuple, 0, sizeof( sMapTuple ) );
pAttrMapTuple->fStandard = new char[1+::strlen(kDSNAttrPhoneNumber)];
::strcpy(pAttrMapTuple->fStandard,kDSNAttrPhoneNumber);
tempPtrString = new sPtrString;
if ( tempPtrString != nil )
{
::memset( tempPtrString, 0, sizeof( sPtrString ) );
tempPtrString->fName = new char[1+::strlen("phone")];
::strcpy(tempPtrString->fName,"phone");
tempPtrString->pNext = nil;
}
pAttrMapTuple->fNative = new sPtrString;
if ( pAttrMapTuple->fNative != nil )
{
::memset( pAttrMapTuple->fNative, 0, sizeof( sPtrString ) );
pAttrMapTuple->fNative->fName = new char[1+::strlen("telephone")];
::strcpy(pAttrMapTuple->fNative->fName,"telephone");
pAttrMapTuple->fNative->pNext = tempPtrString;
}
pAttrMapTuple->pNext = pStdAttributeMapTuple;
pStdAttributeMapTuple = pAttrMapTuple;
pAttrMapTuple = nil;
}
pAttrMapTuple = new sMapTuple;
if ( pAttrMapTuple != nil )
{
::memset( pAttrMapTuple, 0, sizeof( sMapTuple ) );
pAttrMapTuple->fStandard = new char[1+::strlen(kDSNAttrRecordAlias)];
::strcpy(pAttrMapTuple->fStandard,kDSNAttrRecordAlias);
pAttrMapTuple->fNative = new sPtrString;
if ( pAttrMapTuple->fNative != nil )
{
::memset( pAttrMapTuple->fNative, 0, sizeof( sPtrString ) );
pAttrMapTuple->fNative->fName = new char[1+::strlen("aliasdata")];
::strcpy(pAttrMapTuple->fNative->fName,"aliasdata");
pAttrMapTuple->fNative->pNext = nil;
}
pAttrMapTuple->pNext = pStdAttributeMapTuple;
pStdAttributeMapTuple = pAttrMapTuple;
pAttrMapTuple = nil;
}
pAttrMapTuple = new sMapTuple;
if ( pAttrMapTuple != nil )
{
::memset( pAttrMapTuple, 0, sizeof( sMapTuple ) );
pAttrMapTuple->fStandard = new char[1+::strlen(kDSNAttrGroupMembership)];
::strcpy(pAttrMapTuple->fStandard,kDSNAttrGroupMembership);
pAttrMapTuple->fNative = new sPtrString;
if ( pAttrMapTuple->fNative != nil )
{
::memset( pAttrMapTuple->fNative, 0, sizeof( sPtrString ) );
pAttrMapTuple->fNative->fName = new char[1+::strlen("userlist")];
::strcpy(pAttrMapTuple->fNative->fName,"userlist");
pAttrMapTuple->fNative->pNext = nil;
}
pAttrMapTuple->pNext = pStdAttributeMapTuple;
pStdAttributeMapTuple = pAttrMapTuple;
pAttrMapTuple = nil;
}
pAttrMapTuple = new sMapTuple;
if ( pAttrMapTuple != nil )
{
::memset( pAttrMapTuple, 0, sizeof( sMapTuple ) );
pAttrMapTuple->fStandard = new char[1+::strlen(kDSNAttrGroup)];
::strcpy(pAttrMapTuple->fStandard,kDSNAttrGroup);
pAttrMapTuple->fNative = new sPtrString;
if ( pAttrMapTuple->fNative != nil )
{
::memset( pAttrMapTuple->fNative, 0, sizeof( sPtrString ) );
pAttrMapTuple->fNative->fName = new char[1+::strlen("grouplist")];
::strcpy(pAttrMapTuple->fNative->fName,"grouplist");
pAttrMapTuple->fNative->pNext = nil;
}
pAttrMapTuple->pNext = pStdAttributeMapTuple;
pStdAttributeMapTuple = pAttrMapTuple;
pAttrMapTuple = nil;
}
pAttrMapTuple = new sMapTuple;
if ( pAttrMapTuple != nil )
{
::memset( pAttrMapTuple, 0, sizeof( sMapTuple ) );
pAttrMapTuple->fStandard = new char[1+::strlen(kDS1AttrAuthenticationHint)];
::strcpy(pAttrMapTuple->fStandard,kDS1AttrAuthenticationHint);
pAttrMapTuple->fNative = new sPtrString;
if ( pAttrMapTuple->fNative != nil )
{
::memset( pAttrMapTuple->fNative, 0, sizeof( sPtrString ) );
pAttrMapTuple->fNative->fName = new char[1+::strlen("hint")];
::strcpy(pAttrMapTuple->fNative->fName,"hint");
pAttrMapTuple->fNative->pNext = nil;
}
pAttrMapTuple->pNext = pStdAttributeMapTuple;
pStdAttributeMapTuple = pAttrMapTuple;
pAttrMapTuple = nil;
}
pAttrMapTuple = new sMapTuple;
if ( pAttrMapTuple != nil )
{
::memset( pAttrMapTuple, 0, sizeof( sMapTuple ) );
pAttrMapTuple->fStandard = new char[1+::strlen(kDSNAttrEMailAddress)];
::strcpy(pAttrMapTuple->fStandard,kDSNAttrEMailAddress);
pAttrMapTuple->fNative = new sPtrString;
if ( pAttrMapTuple->fNative != nil )
{
::memset( pAttrMapTuple->fNative, 0, sizeof( sPtrString ) );
pAttrMapTuple->fNative->fName = new char[1+::strlen("mail")];
::strcpy(pAttrMapTuple->fNative->fName,"mail");
pAttrMapTuple->fNative->pNext = nil;
}
pAttrMapTuple->pNext = pStdAttributeMapTuple;
pStdAttributeMapTuple = pAttrMapTuple;
pAttrMapTuple = nil;
}
pAttrMapTuple = new sMapTuple;
if ( pAttrMapTuple != nil )
{
::memset( pAttrMapTuple, 0, sizeof( sMapTuple ) );
pAttrMapTuple->fStandard = new char[1+::strlen(kDS1AttrMailAttribute)];
::strcpy(pAttrMapTuple->fStandard,kDS1AttrMailAttribute);
pAttrMapTuple->fNative = new sPtrString;
if ( pAttrMapTuple->fNative != nil )
{
::memset( pAttrMapTuple->fNative, 0, sizeof( sPtrString ) );
pAttrMapTuple->fNative->fName = new char[1+::strlen("applemail")];
::strcpy(pAttrMapTuple->fNative->fName,"applemail");
pAttrMapTuple->fNative->pNext = nil;
}
pAttrMapTuple->pNext = pStdAttributeMapTuple;
pStdAttributeMapTuple = pAttrMapTuple;
pAttrMapTuple = nil;
}
pAttrMapTuple = new sMapTuple;
if ( pAttrMapTuple != nil )
{
::memset( pAttrMapTuple, 0, sizeof( sMapTuple ) );
pAttrMapTuple->fStandard = new char[1+::strlen(kDS1AttrUserShell)];
::strcpy(pAttrMapTuple->fStandard,kDS1AttrUserShell);
pAttrMapTuple->fNative = new sPtrString;
if ( pAttrMapTuple->fNative != nil )
{
::memset( pAttrMapTuple->fNative, 0, sizeof( sPtrString ) );
pAttrMapTuple->fNative->fName = new char[1+::strlen("shell")];
::strcpy(pAttrMapTuple->fNative->fName,"shell");
pAttrMapTuple->fNative->pNext = nil;
}
pAttrMapTuple->pNext = pStdAttributeMapTuple;
pStdAttributeMapTuple = pAttrMapTuple;
pAttrMapTuple = nil;
}
pAttrMapTuple = new sMapTuple;
if ( pAttrMapTuple != nil )
{
::memset( pAttrMapTuple, 0, sizeof( sMapTuple ) );
pAttrMapTuple->fStandard = new char[1+::strlen(kDSNAttrHomeDirectory)];
::strcpy(pAttrMapTuple->fStandard,kDSNAttrHomeDirectory);
tempPtrString = new sPtrString;
if ( tempPtrString != nil )
{
::memset( tempPtrString, 0, sizeof( sPtrString ) );
tempPtrString->fName = new char[1+::strlen("home")];
::strcpy(tempPtrString->fName,"home");
tempPtrString->pNext = nil;
}
pAttrMapTuple->fNative = new sPtrString;
if ( pAttrMapTuple->fNative != nil )
{
::memset( pAttrMapTuple->fNative, 0, sizeof( sPtrString ) );
pAttrMapTuple->fNative->fName = new char[1+::strlen("homeloc")];
::strcpy(pAttrMapTuple->fNative->fName,"homeloc");
pAttrMapTuple->fNative->pNext = tempPtrString;
}
pAttrMapTuple->pNext = pStdAttributeMapTuple;
pStdAttributeMapTuple = pAttrMapTuple;
pAttrMapTuple = nil;
}
pAttrMapTuple = new sMapTuple;
if ( pAttrMapTuple != nil )
{
::memset( pAttrMapTuple, 0, sizeof( sMapTuple ) );
pAttrMapTuple->fStandard = new char[1+::strlen(kDS1AttrNFSHomeDirectory)];
::strcpy(pAttrMapTuple->fStandard,kDS1AttrNFSHomeDirectory);
pAttrMapTuple->fNative = new sPtrString;
if ( pAttrMapTuple->fNative != nil )
{
::memset( pAttrMapTuple->fNative, 0, sizeof( sPtrString ) );
pAttrMapTuple->fNative->fName = new char[1+::strlen("nfshome")];
::strcpy(pAttrMapTuple->fNative->fName,"nfshome");
pAttrMapTuple->fNative->pNext = nil;
}
pAttrMapTuple->pNext = pStdAttributeMapTuple;
pStdAttributeMapTuple = pAttrMapTuple;
pAttrMapTuple = nil;
}
pAttrMapTuple = new sMapTuple;
if ( pAttrMapTuple != nil )
{
::memset( pAttrMapTuple, 0, sizeof( sMapTuple ) );
pAttrMapTuple->fStandard = new char[1+::strlen(kDS1AttrPrimaryGroupID)];
::strcpy(pAttrMapTuple->fStandard,kDS1AttrPrimaryGroupID);
pAttrMapTuple->fNative = new sPtrString;
if ( pAttrMapTuple->fNative != nil )
{
::memset( pAttrMapTuple->fNative, 0, sizeof( sPtrString ) );
pAttrMapTuple->fNative->fName = new char[1+::strlen("groupid")];
::strcpy(pAttrMapTuple->fNative->fName,"groupid");
pAttrMapTuple->fNative->pNext = nil;
}
pAttrMapTuple->pNext = pStdAttributeMapTuple;
pStdAttributeMapTuple = pAttrMapTuple;
pAttrMapTuple = nil;
}
pAttrMapTuple = new sMapTuple;
if ( pAttrMapTuple != nil )
{
::memset( pAttrMapTuple, 0, sizeof( sMapTuple ) );
pAttrMapTuple->fStandard = new char[1+::strlen(kDS1AttrPassword)];
::strcpy(pAttrMapTuple->fStandard,kDS1AttrPassword);
pAttrMapTuple->fNative = new sPtrString;
if ( pAttrMapTuple->fNative != nil )
{
::memset( pAttrMapTuple->fNative, 0, sizeof( sPtrString ) );
pAttrMapTuple->fNative->fName = new char[1+::strlen("passwd")];
::strcpy(pAttrMapTuple->fNative->fName,"passwd");
pAttrMapTuple->fNative->pNext = nil;
}
pAttrMapTuple->pNext = pStdAttributeMapTuple;
pStdAttributeMapTuple = pAttrMapTuple;
pAttrMapTuple = nil;
}
pAttrMapTuple = new sMapTuple;
if ( pAttrMapTuple != nil )
{
::memset( pAttrMapTuple, 0, sizeof( sMapTuple ) );
pAttrMapTuple->fStandard = new char[1+::strlen(kDS1AttrUniqueID)];
::strcpy(pAttrMapTuple->fStandard,kDS1AttrUniqueID);
pAttrMapTuple->fNative = new sPtrString;
if ( pAttrMapTuple->fNative != nil )
{
::memset( pAttrMapTuple->fNative, 0, sizeof( sPtrString ) );
pAttrMapTuple->fNative->fName = new char[1+::strlen("unixid")];
::strcpy(pAttrMapTuple->fNative->fName,"unixid");
pAttrMapTuple->fNative->pNext = nil;
}
pAttrMapTuple->pNext = pStdAttributeMapTuple;
pStdAttributeMapTuple = pAttrMapTuple;
pAttrMapTuple = nil;
}
pAttrMapTuple = new sMapTuple;
if ( pAttrMapTuple != nil )
{
::memset( pAttrMapTuple, 0, sizeof( sMapTuple ) );
pAttrMapTuple->fStandard = new char[1+::strlen(kDS1AttrDistinguishedName)];
::strcpy(pAttrMapTuple->fStandard,kDS1AttrDistinguishedName);
pAttrMapTuple->fNative = new sPtrString;
if ( pAttrMapTuple->fNative != nil )
{
::memset( pAttrMapTuple->fNative, 0, sizeof( sPtrString ) );
pAttrMapTuple->fNative->fName = new char[1+::strlen("realname")];
::strcpy(pAttrMapTuple->fNative->fName,"realname");
pAttrMapTuple->fNative->pNext = nil;
}
pAttrMapTuple->pNext = pStdAttributeMapTuple;
pStdAttributeMapTuple = pAttrMapTuple;
pAttrMapTuple = nil;
}
pAttrMapTuple = new sMapTuple;
if ( pAttrMapTuple != nil )
{
::memset( pAttrMapTuple, 0, sizeof( sMapTuple ) );
pAttrMapTuple->fStandard = new char[1+::strlen(kDSNAttrRecordName)];
::strcpy(pAttrMapTuple->fStandard,kDSNAttrRecordName);
tempPtrString = new sPtrString;
if ( tempPtrString != nil )
{
::memset( tempPtrString, 0, sizeof( sPtrString ) );
tempPtrString->fName = new char[1+::strlen("sn")];
::strcpy(tempPtrString->fName,"sn");
tempPtrString->pNext = nil;
}
pAttrMapTuple->fNative = new sPtrString;
if ( pAttrMapTuple->fNative != nil )
{
::memset( pAttrMapTuple->fNative, 0, sizeof( sPtrString ) );
pAttrMapTuple->fNative->fName = new char[1+::strlen("cn")];
::strcpy(pAttrMapTuple->fNative->fName,"cn");
pAttrMapTuple->fNative->pNext = tempPtrString;
}
tempPtrString = new sPtrString;
if ( tempPtrString != nil )
{
::memset( tempPtrString, 0, sizeof( sPtrString ) );
tempPtrString->fName = new char[1+::strlen("dn")];
::strcpy(tempPtrString->fName,"dn");
tempPtrString->pNext = nil;
pAttrMapTuple->fNative->pNext->pNext = tempPtrString;
}
pAttrMapTuple->pNext = pStdAttributeMapTuple;
pStdAttributeMapTuple = pAttrMapTuple;
pAttrMapTuple = nil;
}
return( siResult );
}
sInt32 CLDAPConfigs::BuildDefaultStdRecordMap ( void )
{
sInt32 siResult = eDSNoErr;
sMapTuple *pRecMapTuple = nil;
if (pStdRecordMapTuple != nil)
{
CleanMapTuple(pStdRecordMapTuple);
pStdRecordMapTuple = nil;
}
pRecMapTuple = new sMapTuple;
if ( pRecMapTuple != nil )
{
::memset( pRecMapTuple, 0, sizeof( sMapTuple ) );
pRecMapTuple->fStandard = new char[1+::strlen(kDSStdRecordTypeQTSServer)];
::strcpy(pRecMapTuple->fStandard,kDSStdRecordTypeQTSServer);
pRecMapTuple->fNative = new sPtrString;
if ( pRecMapTuple->fNative != nil )
{
::memset( pRecMapTuple->fNative, 0, sizeof( sPtrString ) );
pRecMapTuple->fNative->fName = new char[1+::strlen("ou=qtsserver, o=company name")];
::strcpy(pRecMapTuple->fNative->fName,"ou=qtsserver, o=company name");
pRecMapTuple->fNative->pNext = nil;
}
pRecMapTuple->pNext = pStdRecordMapTuple;
pStdRecordMapTuple = pRecMapTuple;
pRecMapTuple = nil;
}
pRecMapTuple = new sMapTuple;
if ( pRecMapTuple != nil )
{
::memset( pRecMapTuple, 0, sizeof( sMapTuple ) );
pRecMapTuple->fStandard = new char[1+::strlen(kDSStdRecordTypeLDAPServer)];
::strcpy(pRecMapTuple->fStandard,kDSStdRecordTypeLDAPServer);
pRecMapTuple->fNative = new sPtrString;
if ( pRecMapTuple->fNative != nil )
{
::memset( pRecMapTuple->fNative, 0, sizeof( sPtrString ) );
pRecMapTuple->fNative->fName = new char[1+::strlen("ou=ldapserver, o=company name")];
::strcpy(pRecMapTuple->fNative->fName,"ou=ldapserver, o=company name");
pRecMapTuple->fNative->pNext = nil;
}
pRecMapTuple->pNext = pStdRecordMapTuple;
pStdRecordMapTuple = pRecMapTuple;
pRecMapTuple = nil;
}
pRecMapTuple = new sMapTuple;
if ( pRecMapTuple != nil )
{
::memset( pRecMapTuple, 0, sizeof( sMapTuple ) );
pRecMapTuple->fStandard = new char[1+::strlen(kDSStdRecordTypeWebServer)];
::strcpy(pRecMapTuple->fStandard,kDSStdRecordTypeWebServer);
pRecMapTuple->fNative = new sPtrString;
if ( pRecMapTuple->fNative != nil )
{
::memset( pRecMapTuple->fNative, 0, sizeof( sPtrString ) );
pRecMapTuple->fNative->fName = new char[1+::strlen("ou=webserver, o=company name")];
::strcpy(pRecMapTuple->fNative->fName,"ou=webserver, o=company name");
pRecMapTuple->fNative->pNext = nil;
}
pRecMapTuple->pNext = pStdRecordMapTuple;
pStdRecordMapTuple = pRecMapTuple;
pRecMapTuple = nil;
}
pRecMapTuple = new sMapTuple;
if ( pRecMapTuple != nil )
{
::memset( pRecMapTuple, 0, sizeof( sMapTuple ) );
pRecMapTuple->fStandard = new char[1+::strlen(kDSStdRecordTypeNFS)];
::strcpy(pRecMapTuple->fStandard,kDSStdRecordTypeNFS);
pRecMapTuple->fNative = new sPtrString;
if ( pRecMapTuple->fNative != nil )
{
::memset( pRecMapTuple->fNative, 0, sizeof( sPtrString ) );
pRecMapTuple->fNative->fName = new char[1+::strlen("ou=nfs, o=company name")];
::strcpy(pRecMapTuple->fNative->fName,"ou=nfs, o=company name");
pRecMapTuple->fNative->pNext = nil;
}
pRecMapTuple->pNext = pStdRecordMapTuple;
pStdRecordMapTuple = pRecMapTuple;
pRecMapTuple = nil;
}
pRecMapTuple = new sMapTuple;
if ( pRecMapTuple != nil )
{
::memset( pRecMapTuple, 0, sizeof( sMapTuple ) );
pRecMapTuple->fStandard = new char[1+::strlen(kDSStdRecordTypeSMBServer)];
::strcpy(pRecMapTuple->fStandard,kDSStdRecordTypeSMBServer);
pRecMapTuple->fNative = new sPtrString;
if ( pRecMapTuple->fNative != nil )
{
::memset( pRecMapTuple->fNative, 0, sizeof( sPtrString ) );
pRecMapTuple->fNative->fName = new char[1+::strlen("ou=smbserver, o=company name")];
::strcpy(pRecMapTuple->fNative->fName,"ou=smbserver, o=company name");
pRecMapTuple->fNative->pNext = nil;
}
pRecMapTuple->pNext = pStdRecordMapTuple;
pStdRecordMapTuple = pRecMapTuple;
pRecMapTuple = nil;
}
pRecMapTuple = new sMapTuple;
if ( pRecMapTuple != nil )
{
::memset( pRecMapTuple, 0, sizeof( sMapTuple ) );
pRecMapTuple->fStandard = new char[1+::strlen(kDSStdRecordTypeFTPServer)];
::strcpy(pRecMapTuple->fStandard,kDSStdRecordTypeFTPServer);
pRecMapTuple->fNative = new sPtrString;
if ( pRecMapTuple->fNative != nil )
{
::memset( pRecMapTuple->fNative, 0, sizeof( sPtrString ) );
pRecMapTuple->fNative->fName = new char[1+::strlen("ou=ftpserver, o=company name")];
::strcpy(pRecMapTuple->fNative->fName,"ou=ftpserver, o=company name");
pRecMapTuple->fNative->pNext = nil;
}
pRecMapTuple->pNext = pStdRecordMapTuple;
pStdRecordMapTuple = pRecMapTuple;
pRecMapTuple = nil;
}
pRecMapTuple = new sMapTuple;
if ( pRecMapTuple != nil )
{
::memset( pRecMapTuple, 0, sizeof( sMapTuple ) );
pRecMapTuple->fStandard = new char[1+::strlen(kDSStdRecordTypeAFPServer)];
::strcpy(pRecMapTuple->fStandard,kDSStdRecordTypeAFPServer);
pRecMapTuple->fNative = new sPtrString;
if ( pRecMapTuple->fNative != nil )
{
::memset( pRecMapTuple->fNative, 0, sizeof( sPtrString ) );
pRecMapTuple->fNative->fName = new char[1+::strlen("ou=afpserver, o=company name")];
::strcpy(pRecMapTuple->fNative->fName,"ou=afpserver, o=company name");
pRecMapTuple->fNative->pNext = nil;
}
pRecMapTuple->pNext = pStdRecordMapTuple;
pStdRecordMapTuple = pRecMapTuple;
pRecMapTuple = nil;
}
pRecMapTuple = new sMapTuple;
if ( pRecMapTuple != nil )
{
::memset( pRecMapTuple, 0, sizeof( sMapTuple ) );
pRecMapTuple->fStandard = new char[1+::strlen(kDSStdRecordTypePrinters)];
::strcpy(pRecMapTuple->fStandard,kDSStdRecordTypePrinters);
pRecMapTuple->fNative = new sPtrString;
if ( pRecMapTuple->fNative != nil )
{
::memset( pRecMapTuple->fNative, 0, sizeof( sPtrString ) );
pRecMapTuple->fNative->fName = new char[1+::strlen("ou=printers, o=company name")];
::strcpy(pRecMapTuple->fNative->fName,"ou=printers, o=company name");
pRecMapTuple->fNative->pNext = nil;
}
pRecMapTuple->pNext = pStdRecordMapTuple;
pStdRecordMapTuple = pRecMapTuple;
pRecMapTuple = nil;
}
pRecMapTuple = new sMapTuple;
if ( pRecMapTuple != nil )
{
::memset( pRecMapTuple, 0, sizeof( sMapTuple ) );
pRecMapTuple->fStandard = new char[1+::strlen(kDSStdRecordTypeMachines)];
::strcpy(pRecMapTuple->fStandard,kDSStdRecordTypeMachines);
pRecMapTuple->fNative = new sPtrString;
if ( pRecMapTuple->fNative != nil )
{
::memset( pRecMapTuple->fNative, 0, sizeof( sPtrString ) );
pRecMapTuple->fNative->fName = new char[1+::strlen("ou=machines, o=company name")];
::strcpy(pRecMapTuple->fNative->fName,"ou=machines, o=company name");
pRecMapTuple->fNative->pNext = nil;
}
pRecMapTuple->pNext = pStdRecordMapTuple;
pStdRecordMapTuple = pRecMapTuple;
pRecMapTuple = nil;
}
pRecMapTuple = new sMapTuple;
if ( pRecMapTuple != nil )
{
::memset( pRecMapTuple, 0, sizeof( sMapTuple ) );
pRecMapTuple->fStandard = new char[1+::strlen(kDSStdRecordTypeMounts)];
::strcpy(pRecMapTuple->fStandard,kDSStdRecordTypeMounts);
pRecMapTuple->fNative = new sPtrString;
if ( pRecMapTuple->fNative != nil )
{
::memset( pRecMapTuple->fNative, 0, sizeof( sPtrString ) );
pRecMapTuple->fNative->fName = new char[1+::strlen("ou=mounts, o=company name")];
::strcpy(pRecMapTuple->fNative->fName,"ou=mounts, o=company name");
pRecMapTuple->fNative->pNext = nil;
}
pRecMapTuple->pNext = pStdRecordMapTuple;
pStdRecordMapTuple = pRecMapTuple;
pRecMapTuple = nil;
}
pRecMapTuple = new sMapTuple;
if ( pRecMapTuple != nil )
{
::memset( pRecMapTuple, 0, sizeof( sMapTuple ) );
pRecMapTuple->fStandard = new char[1+::strlen(kDSStdRecordTypeGroupAliases)];
::strcpy(pRecMapTuple->fStandard,kDSStdRecordTypeGroupAliases);
pRecMapTuple->fNative = new sPtrString;
if ( pRecMapTuple->fNative != nil )
{
::memset( pRecMapTuple->fNative, 0, sizeof( sPtrString ) );
pRecMapTuple->fNative->fName = new char[1+::strlen("ou=groupaliases, o=company name")];
::strcpy(pRecMapTuple->fNative->fName,"ou=groupaliases, o=company name");
pRecMapTuple->fNative->pNext = nil;
}
pRecMapTuple->pNext = pStdRecordMapTuple;
pStdRecordMapTuple = pRecMapTuple;
pRecMapTuple = nil;
}
pRecMapTuple = new sMapTuple;
if ( pRecMapTuple != nil )
{
::memset( pRecMapTuple, 0, sizeof( sMapTuple ) );
pRecMapTuple->fStandard = new char[1+::strlen(kDSStdRecordTypeUserAliases)];
::strcpy(pRecMapTuple->fStandard,kDSStdRecordTypeUserAliases);
pRecMapTuple->fNative = new sPtrString;
if ( pRecMapTuple->fNative != nil )
{
::memset( pRecMapTuple->fNative, 0, sizeof( sPtrString ) );
pRecMapTuple->fNative->fName = new char[1+::strlen("ou=peoplealiases, o=company name")];
::strcpy(pRecMapTuple->fNative->fName,"ou=peoplealiases, o=company name");
pRecMapTuple->fNative->pNext = nil;
}
pRecMapTuple->pNext = pStdRecordMapTuple;
pStdRecordMapTuple = pRecMapTuple;
pRecMapTuple = nil;
}
pRecMapTuple = new sMapTuple;
if ( pRecMapTuple != nil )
{
::memset( pRecMapTuple, 0, sizeof( sMapTuple ) );
pRecMapTuple->fStandard = new char[1+::strlen(kDSStdRecordTypeGroups)];
::strcpy(pRecMapTuple->fStandard,kDSStdRecordTypeGroups);
pRecMapTuple->fNative = new sPtrString;
if ( pRecMapTuple->fNative != nil )
{
::memset( pRecMapTuple->fNative, 0, sizeof( sPtrString ) );
pRecMapTuple->fNative->fName = new char[1+::strlen("ou=groups, o=company name")];
::strcpy(pRecMapTuple->fNative->fName,"ou=groups, o=company name");
pRecMapTuple->fNative->pNext = nil;
}
pRecMapTuple->pNext = pStdRecordMapTuple;
pStdRecordMapTuple = pRecMapTuple;
pRecMapTuple = nil;
}
pRecMapTuple = new sMapTuple;
if ( pRecMapTuple != nil )
{
::memset( pRecMapTuple, 0, sizeof( sMapTuple ) );
pRecMapTuple->fStandard = new char[1+::strlen(kDSStdRecordTypeUsers)];
::strcpy(pRecMapTuple->fStandard,kDSStdRecordTypeUsers);
pRecMapTuple->fNative = new sPtrString;
if ( pRecMapTuple->fNative != nil )
{
::memset( pRecMapTuple->fNative, 0, sizeof( sPtrString ) );
pRecMapTuple->fNative->fName = new char[1+::strlen("ou=people, o=company name")];
::strcpy(pRecMapTuple->fNative->fName,"ou=people, o=company name");
pRecMapTuple->fNative->pNext = nil;
}
pRecMapTuple->pNext = pStdRecordMapTuple;
pStdRecordMapTuple = pRecMapTuple;
pRecMapTuple = nil;
}
return( siResult );
}
sInt32 CLDAPConfigs::CleanMapTuple ( sMapTuple *inMapTuple )
{
sInt32 siResult = eDSNoErr;
sMapTuple *pMapTuple = nil;
sPtrString *pPtrString = nil;
pMapTuple = inMapTuple;
while (pMapTuple != nil)
{
inMapTuple = pMapTuple->pNext;
if (pMapTuple->fStandard != nil)
{
delete( pMapTuple->fStandard );
}
pPtrString = pMapTuple->fNative;
while (pPtrString != nil)
{
pMapTuple->fNative = pPtrString->pNext;
if (pPtrString->fName != nil)
{
delete( pPtrString->fName );
}
pPtrString->pNext = nil;
delete( pPtrString );
pPtrString = pMapTuple->fNative;
}
pMapTuple->pNext = nil;
delete( pMapTuple );
pMapTuple = inMapTuple;
}
return( siResult );
}
sInt32 CLDAPConfigs::ReadXMLConfig ( void )
{
sInt32 siResult = eDSNoErr;
CFURLRef configFileURL = nil;
CFURLRef configFileCorruptedURL = nil;
CFDataRef xmlData;
bool bReadFile = false;
bool bCorruptedFile = false;
bool bWroteFile = false;
register CFIndex iPath;
CFArrayRef aPaths = nil;
char string[ PATH_MAX ];
char string2[ PATH_MAX ];
struct stat statResult;
CFMutableDictionaryRef configDict;
CFStringRef cfStringRef;
sInt32 errorCode = 0;
CFStringRef sBase = nil;
CFStringRef sPath = nil;
CFStringRef sCorruptedPath;
try
{
aPaths = ::CFCopySearchPathForDirectoriesInDomains( kCFLibraryDirectory, kCFLocalDomainMask, true );
if ( aPaths != nil )
{
iPath = ::CFArrayGetCount( aPaths );
if ( iPath != 0 )
{
while (( iPath-- ) && (!bReadFile))
{
configFileURL = (CFURLRef)::CFArrayGetValueAtIndex( aPaths, iPath );
sBase = ::CFURLCopyFileSystemPath( configFileURL, kCFURLPOSIXPathStyle );
sPath = ::CFStringCreateWithFormat( kCFAllocatorDefault, NULL, CFSTR( "%@/%s" ), sBase, "/Preferences/DirectoryService/DSLDAPPlugInConfig.clpi" );
::memset(string,0,PATH_MAX);
::CFStringGetCString( sPath, string, sizeof( string ), kCFStringEncodingMacRoman );
CShared::LogIt( 0x0F, (char *)"Checking for LDAP XML config file:" );
CShared::LogIt( 0x0F, string );
configFileURL = ::CFURLCreateWithFileSystemPath( kCFAllocatorDefault, sPath, kCFURLPOSIXPathStyle, false );
CFRelease( sPath ); sPath = nil;
siResult = ::stat( string, &statResult );
if (siResult != eDSNoErr)
{
sPath = ::CFStringCreateWithFormat( kCFAllocatorDefault, NULL, CFSTR( "%@/%s" ), sBase, "/Preferences" );
::memset(string2,0,PATH_MAX);
::CFStringGetCString( sPath, string2, sizeof( string2 ), kCFStringEncodingMacRoman );
siResult = ::stat( string2, &statResult );
if (siResult != eDSNoErr)
{
::mkdir( string2 , 0775 );
::chmod( string2, 0775 ); }
CFRelease( sPath ); sPath = nil;
sPath = ::CFStringCreateWithFormat( kCFAllocatorDefault, NULL, CFSTR( "%@/%s" ), sBase, "/Preferences/DirectoryService" );
::memset(string2,0,PATH_MAX);
::CFStringGetCString( sPath, string2, sizeof( string2 ), kCFStringEncodingMacRoman );
siResult = ::stat( string2, &statResult );
if (siResult != eDSNoErr)
{
::mkdir( string2 , 0775 );
::chmod( string2, 0775 ); }
CFRelease( sPath ); sPath = nil;
configDict = CFDictionaryCreateMutable( kCFAllocatorDefault,
0,
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks );
cfStringRef = CFStringCreateWithCString(kCFAllocatorDefault, "DSLDAPPlugIn Version 1.5", kCFStringEncodingMacRoman);
CFDictionarySetValue( configDict, CFSTR( kXMLLDAPVersionKey ), cfStringRef );
CFRelease(cfStringRef);
cfStringRef = nil;
siResult = BuildDefaultStdAttributeMap();
siResult = BuildDefaultStdRecordMap();
siResult = AddDefaultArrays(configDict);
CShared::LogIt( 0x0F, (char *)"Created a new LDAP XML config file since it did not exist" );
xmlData = CFPropertyListCreateXMLData( kCFAllocatorDefault, configDict);
siResult = CFURLWriteDataAndPropertiesToResource( configFileURL,
xmlData,
NULL,
&errorCode);
CFRelease(configDict);
configDict = nil;
CFRelease(xmlData);
xmlData = nil;
} chmod( string, S_IRUSR | S_IWUSR );
bReadFile = CFURLCreateDataAndPropertiesFromResource(
kAllocatorDefault,
configFileURL,
&xmlData, NULL,
NULL,
&siResult);
} }
CFRelease(aPaths); aPaths = nil;
}
if (bReadFile)
{
fXMLData = xmlData;
if (!VerifyXML())
{
CShared::LogIt( 0x0F, (char *)"LDAP XML config file is corrupted" );
bCorruptedFile = true;
sCorruptedPath = ::CFStringCreateWithFormat( kCFAllocatorDefault, NULL, CFSTR( "%@/%s" ), sBase, "/Preferences/DirectoryService/DSLDAPPlugInConfigCorrupted.clpi" );
configFileCorruptedURL = ::CFURLCreateWithFileSystemPath( kCFAllocatorDefault, sCorruptedPath, kCFURLPOSIXPathStyle, false );
CFRelease( sCorruptedPath ); sCorruptedPath = nil;
bWroteFile = CFURLWriteDataAndPropertiesToResource( configFileCorruptedURL,
xmlData,
NULL,
&errorCode);
CFRelease(xmlData);
xmlData = nil;
}
}
else {
CShared::LogIt( 0x0F, (char *)"LDAP XML config file is unreadable" );
bCorruptedFile = true;
}
if (bCorruptedFile)
{
configDict = CFDictionaryCreateMutable( kCFAllocatorDefault,
0,
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks );
cfStringRef = CFStringCreateWithCString(kCFAllocatorDefault, "DSLDAPPlugIn Version 1.5", kCFStringEncodingMacRoman);
CFDictionarySetValue( configDict, CFSTR( kXMLLDAPVersionKey ), cfStringRef );
CFRelease(cfStringRef);
cfStringRef = nil;
if (pStdAttributeMapTuple == nil)
{
siResult = BuildDefaultStdAttributeMap();
}
if (pStdRecordMapTuple == nil)
{
siResult = BuildDefaultStdRecordMap();
}
siResult = AddDefaultArrays(configDict);
CShared::LogIt( 0x0F, (char *)"Writing a new LDAP XML config file" );
xmlData = CFPropertyListCreateXMLData( kCFAllocatorDefault, configDict);
fXMLData = xmlData;
siResult = CFURLWriteDataAndPropertiesToResource( configFileURL,
xmlData,
NULL,
&errorCode);
CFRelease(configDict);
configDict = nil;
}
} catch( sInt32 err )
{
siResult = err;
}
if (configFileURL != nil)
{
CFRelease(configFileURL); configFileURL = nil;
}
if (configFileCorruptedURL != nil)
{
CFRelease(configFileCorruptedURL); configFileCorruptedURL = nil;
}
if (sBase != nil)
{
CFRelease( sBase ); sBase = nil;
}
return( siResult );
}
sInt32 CLDAPConfigs::WriteXMLConfig ( void )
{
sInt32 siResult = eDSNoErr;
CFURLRef configFileURL;
bool bWroteFile = false;
register CFIndex iPath;
CFArrayRef aPaths = nil;
char string[ PATH_MAX ];
struct stat statResult;
sInt32 errorCode = 0;
try
{
aPaths = ::CFCopySearchPathForDirectoriesInDomains( kCFLibraryDirectory, kCFLocalDomainMask, true );
if ( aPaths != nil )
{
iPath = ::CFArrayGetCount( aPaths );
if ( iPath != 0 )
{
while (( iPath-- ) && (!bWroteFile))
{
configFileURL = (CFURLRef)::CFArrayGetValueAtIndex( aPaths, iPath );
CFStringRef sBase, sPath;
sBase = ::CFURLCopyFileSystemPath( configFileURL, kCFURLPOSIXPathStyle );
sPath = ::CFStringCreateWithFormat( kCFAllocatorDefault, NULL, CFSTR( "%@/%s" ), sBase, "/Preferences/DirectoryService/DSLDAPPlugInConfig.clpi" );
::memset(string,0,PATH_MAX);
::CFStringGetCString( sPath, string, sizeof( string ), kCFStringEncodingMacRoman );
CShared::LogIt( 0x0F, (char *)"Checking for LDAP XML config file:" );
CShared::LogIt( 0x0F, string );
configFileURL = ::CFURLCreateWithFileSystemPath( kCFAllocatorDefault, sPath, kCFURLPOSIXPathStyle, false );
CFRelease( sPath ); sPath = nil;
siResult = ::stat( string, &statResult );
if (siResult != eDSNoErr)
{
siResult = eDSNoErr;
sPath = ::CFStringCreateWithFormat( kCFAllocatorDefault, NULL, CFSTR( "%@/%s" ), sBase, "/Preferences" );
::memset(string,0,PATH_MAX);
::CFStringGetCString( sPath, string, sizeof( string ), kCFStringEncodingMacRoman );
siResult = ::stat( string, &statResult );
if (siResult != eDSNoErr)
{
siResult = eDSNoErr;
::mkdir( string , 0775 );
::chmod( string, 0775 ); }
CFRelease( sPath ); sPath = nil;
sPath = ::CFStringCreateWithFormat( kCFAllocatorDefault, NULL, CFSTR( "%@/%s" ), sBase, "/Preferences/DirectoryService" );
::memset(string,0,PATH_MAX);
::CFStringGetCString( sPath, string, sizeof( string ), kCFStringEncodingMacRoman );
siResult = ::stat( string, &statResult );
if (siResult != eDSNoErr)
{
siResult = eDSNoErr;
::mkdir( string , 0775 );
::chmod( string, 0775 ); }
CFRelease( sPath ); sPath = nil;
}
if (fXMLData != nil)
{
bWroteFile = CFURLWriteDataAndPropertiesToResource( configFileURL,
fXMLData,
NULL,
&errorCode);
}
CFRelease( sBase ); sBase = nil;
CFRelease(configFileURL); configFileURL = nil;
} }
CFRelease(aPaths); aPaths = nil;
}
if (bWroteFile)
{
CShared::LogIt( 0x0F, (char *)"Have written the LDAP XML config file:" );
CShared::LogIt( 0x0F, string );
siResult = eDSNoErr;
}
else
{
CShared::LogIt( 0x0F, (char *)"LDAP XML config file has NOT been written" );
CShared::LogIt( 0x0F, (char *)"Update to LDAP Config File Failed" );
siResult = eDSPlugInConfigFileError;
}
} catch( sInt32 err )
{
siResult = err;
}
return( siResult );
}
sInt32 CLDAPConfigs::SetXMLConfig ( CFDataRef xmlData )
{
CFDataRef currentXMLData = fXMLData;
fXMLData = xmlData;
if (VerifyXML())
{
if (currentXMLData != nil)
{
CFRelease(currentXMLData);
currentXMLData = nil;
}
CFRetain(fXMLData);
return eDSNoErr;
}
else
{
fXMLData = currentXMLData;
return eDSInvalidPlugInConfigData;
}
}
CFDataRef CLDAPConfigs::GetXMLConfig ( void )
{
return fXMLData;
}
sInt32 CLDAPConfigs::AddDefaultArrays ( CFMutableDictionaryRef inDict )
{
CFMutableArrayRef cfArrayRef = nil;
CFMutableDictionaryRef cfDictRef = nil;
CFIndex cfMapCount = 0;
CFIndex cfNativeMapCount = 0;
CFStringRef cfStringRef = nil;
CFMutableArrayRef cfNativeArrayRef = nil;
sMapTuple *pMapTuple = nil;
sInt32 siResult = eDSNoErr;
sPtrString *pPtrString = nil;
if ( CFDictionaryContainsKey( inDict, CFSTR( kXMLDefaultAttrTypeMapArrayKey ) ) )
{
CFDictionaryRemoveValue( inDict, CFSTR( kXMLDefaultAttrTypeMapArrayKey ) );
}
if ( !CFDictionaryContainsKey( inDict, CFSTR( kXMLDefaultAttrTypeMapArrayKey ) ) )
{
cfArrayRef = CFArrayCreateMutable(kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks);
CFDictionarySetValue( inDict, CFSTR(kXMLDefaultAttrTypeMapArrayKey), cfArrayRef);
CFRelease(cfArrayRef);
cfArrayRef = nil;
cfArrayRef = (CFMutableArrayRef)CFDictionaryGetValue( inDict, CFSTR( kXMLDefaultAttrTypeMapArrayKey ) );
cfMapCount = 0;
pMapTuple = pStdAttributeMapTuple;
while (pMapTuple != nil)
{
cfDictRef = CFDictionaryCreateMutable( kCFAllocatorDefault,
0,
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks );
CFArrayInsertValueAtIndex(cfArrayRef, cfMapCount, cfDictRef);
if (pMapTuple->fStandard != nil)
{
cfStringRef = CFStringCreateWithCString(kCFAllocatorDefault, pMapTuple->fStandard, kCFStringEncodingMacRoman);
CFDictionarySetValue( cfDictRef, CFSTR(kXMLStdNameKey), cfStringRef);
CFRelease(cfStringRef);
cfStringRef = nil;
cfMapCount++;
}
cfNativeArrayRef = CFArrayCreateMutable(kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks);
CFDictionarySetValue( cfDictRef, CFSTR(kXMLNativeMapArrayKey), cfNativeArrayRef);
CFRelease(cfNativeArrayRef);
cfNativeArrayRef = nil;
cfNativeArrayRef = (CFMutableArrayRef)CFDictionaryGetValue( cfDictRef, CFSTR( kXMLNativeMapArrayKey ) );
cfNativeMapCount = 0;
pPtrString = pMapTuple->fNative;
while (pPtrString != nil)
{
if (pPtrString->fName != nil)
{
cfStringRef = CFStringCreateWithCString(kCFAllocatorDefault, pPtrString->fName, kCFStringEncodingMacRoman);
CFArrayInsertValueAtIndex(cfNativeArrayRef, cfNativeMapCount, cfStringRef);
CFRelease(cfStringRef);
cfStringRef = nil;
cfNativeMapCount++;
}
pPtrString = pPtrString->pNext;
}
pMapTuple = pMapTuple->pNext;
if (cfDictRef != nil)
{
CFRelease(cfDictRef);
cfDictRef = nil;
}
}
}
if ( CFDictionaryContainsKey( inDict, CFSTR( kXMLDefaultRecordTypeMapArrayKey ) ) )
{
CFDictionaryRemoveValue( inDict, CFSTR( kXMLDefaultRecordTypeMapArrayKey ) );
}
if ( !CFDictionaryContainsKey( inDict, CFSTR( kXMLDefaultRecordTypeMapArrayKey ) ) )
{
cfArrayRef = CFArrayCreateMutable(kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks);
CFDictionarySetValue( inDict, CFSTR(kXMLDefaultRecordTypeMapArrayKey), cfArrayRef);
CFRelease(cfArrayRef);
cfArrayRef = nil;
cfArrayRef = (CFMutableArrayRef)CFDictionaryGetValue( inDict, CFSTR( kXMLDefaultRecordTypeMapArrayKey ) );
cfMapCount = 0;
pMapTuple = pStdRecordMapTuple;
while (pMapTuple != nil)
{
cfDictRef = CFDictionaryCreateMutable( kCFAllocatorDefault,
0,
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks );
CFArrayInsertValueAtIndex(cfArrayRef, cfMapCount, cfDictRef);
if (pMapTuple->fStandard != nil)
{
cfStringRef = CFStringCreateWithCString(kCFAllocatorDefault, pMapTuple->fStandard, kCFStringEncodingMacRoman);
CFDictionarySetValue( cfDictRef, CFSTR(kXMLStdNameKey), cfStringRef);
CFRelease(cfStringRef);
cfStringRef = nil;
cfMapCount++;
}
cfNativeArrayRef = CFArrayCreateMutable(kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks);
CFDictionarySetValue( cfDictRef, CFSTR(kXMLNativeMapArrayKey), cfNativeArrayRef);
CFRelease(cfNativeArrayRef);
cfNativeArrayRef = nil;
cfNativeArrayRef = (CFMutableArrayRef)CFDictionaryGetValue( cfDictRef, CFSTR( kXMLNativeMapArrayKey ) );
cfNativeMapCount = 0;
pPtrString = pMapTuple->fNative;
while (pPtrString != nil)
{
if (pPtrString->fName != nil)
{
cfStringRef = CFStringCreateWithCString(kCFAllocatorDefault, pPtrString->fName, kCFStringEncodingMacRoman);
CFArrayInsertValueAtIndex(cfNativeArrayRef, cfNativeMapCount, cfStringRef);
CFRelease(cfStringRef);
cfStringRef = nil;
cfNativeMapCount++;
}
pPtrString = pPtrString->pNext;
}
pMapTuple = pMapTuple->pNext;
if (cfDictRef != nil)
{
CFRelease(cfDictRef);
cfDictRef = nil;
}
}
}
return siResult;
}
bool CLDAPConfigs::VerifyXML ( void )
{
bool verified = false;
CFStringRef errorString;
CFPropertyListRef configPropertyList;
if (fXMLData != nil)
{
configPropertyList = CFPropertyListCreateFromXMLData( kAllocatorDefault,
fXMLData,
kCFPropertyListImmutable,
&errorString);
if (configPropertyList != nil )
{
if ( CFDictionaryGetTypeID() == CFGetTypeID( configPropertyList ) )
{
verified = true;
}
CFRelease(configPropertyList);
configPropertyList = nil;
}
}
return( verified);
}
sInt32 CLDAPConfigs::ConfigLDAPServers ( void )
{
sInt32 siResult = eDSNoErr;
CFStringRef errorString;
CFPropertyListRef configPropertyList = nil;
CFMutableDictionaryRef configDict = nil;
CFArrayRef cfArrayRef = nil;
CFIndex cfConfigCount = 0;
char string[ PATH_MAX ];
CFDataRef xmlData = nil;
char *configVersion = nil;
CFStringRef cfStringRef;
try
{
if (fXMLData != nil)
{
configPropertyList = CFPropertyListCreateFromXMLData( kAllocatorDefault,
fXMLData,
kCFPropertyListImmutable, &errorString);
if (configPropertyList != nil )
{
if ( CFDictionaryGetTypeID() == CFGetTypeID( configPropertyList ) )
{
configDict = (CFMutableDictionaryRef) configPropertyList;
}
if (configDict != nil)
{
configVersion = GetVersion(configDict);
if ( configVersion == nil ) throw( (sInt32)eDSOpenNodeFailed ); if (configVersion != nil)
{
CShared::LogIt( 0x0F, (char *)"Have successfully read the LDAP XML config file:" );
CShared::LogIt( 0x0F, string );
if (strcmp(configVersion,"DSLDAPPlugIn Version 1.5") == 0)
{
cfArrayRef = nil;
cfArrayRef = GetDefaultRecordTypeMapArray(configDict);
if (cfArrayRef != nil)
{
if (pStdRecordMapTuple != nil)
{
CleanMapTuple(pStdRecordMapTuple);
pStdRecordMapTuple = nil;
}
pStdRecordMapTuple = BuildMapTuple(cfArrayRef);
}
cfArrayRef = nil;
cfArrayRef = GetDefaultAttrTypeMapArray(configDict);
if (cfArrayRef != nil)
{
if (pStdAttributeMapTuple != nil)
{
CleanMapTuple(pStdAttributeMapTuple);
pStdAttributeMapTuple = nil;
}
pStdAttributeMapTuple = BuildMapTuple(cfArrayRef);
} }
else
{
CFDictionaryRemoveValue( configDict, CFSTR( kXMLLDAPVersionKey ) );
cfStringRef = CFStringCreateWithCString(kCFAllocatorDefault, "DSLDAPPlugIn Version 1.5", kCFStringEncodingMacRoman);
CFDictionarySetValue( configDict, CFSTR( kXMLLDAPVersionKey ), cfStringRef );
CFRelease(cfStringRef);
cfStringRef = nil;
if (pStdAttributeMapTuple == nil)
{
siResult = BuildDefaultStdAttributeMap();
}
if (pStdRecordMapTuple == nil)
{
siResult = BuildDefaultStdRecordMap();
}
siResult = AddDefaultArrays(configDict);
xmlData = CFPropertyListCreateXMLData( kCFAllocatorDefault, configDict);
siResult = SetXMLConfig(xmlData);
CFRelease(xmlData);
xmlData = nil;
if (siResult == eDSNoErr)
{
WriteXMLConfig();
}
}
cfArrayRef = nil;
cfArrayRef = GetConfigArray(configDict);
if (cfArrayRef != nil)
{
cfConfigCount = ::CFArrayGetCount( cfArrayRef );
for (sInt32 iConfigIndex = 0; iConfigIndex < cfConfigCount; iConfigIndex++)
{
CFDictionaryRef serverConfigDict;
serverConfigDict = (CFDictionaryRef)::CFArrayGetValueAtIndex( cfArrayRef, iConfigIndex );
if ( serverConfigDict != nil )
{
siResult = MakeLDAPConfig(serverConfigDict, fConfigTableLen);
}
}
}
delete(configVersion);
}
}
CFRelease(configPropertyList); configPropertyList = nil;
} }
} catch( sInt32 err )
{
siResult = err;
if (configPropertyList != nil)
{
CFRelease(configPropertyList); configPropertyList = nil;
}
}
return( siResult );
}
sInt32 CLDAPConfigs::MakeLDAPConfig ( CFDictionaryRef ldapDict, sInt32 inIndex )
{
sInt32 siResult = eDSNoErr;
char *tmpBuff = nil;
CFIndex cfBuffSize = 1024;
CFStringRef cfStringRef = nil;
CFDataRef cfDataRef = nil;
CFBooleanRef cfBool = false;
unsigned char cfNumBool = false;
CFNumberRef cfNumber = 0;
char *uiName = nil;
char *server = nil;
char *account = nil;
char *password = nil;
int passwordLen = 0;
int opencloseTO = 0;
int searchTO = 0;
int portNumber = 0;
bool bUseStdMap = false;
bool bUseSecure = false;
bool bUseConfig = false;
sLDAPConfigData *pConfig = nil;
sLDAPConfigData *xConfig = nil;
uInt32 serverIndex = 0;
bool reuseEntry = false;
if ( CFDictionaryContainsKey( ldapDict, CFSTR( kXMLEnableUseFlagKey ) ) )
{
tmpBuff = (char *)::calloc(1, 1024);
cfBool = (CFBooleanRef)CFDictionaryGetValue( ldapDict, CFSTR( kXMLEnableUseFlagKey ) );
if (cfBool != nil)
{
bUseConfig = CFBooleanGetValue( cfBool );
}
if ( bUseConfig )
{
if ( CFDictionaryContainsKey( ldapDict, CFSTR( kXMLServerKey ) ) )
{
cfStringRef = (CFStringRef)CFDictionaryGetValue( ldapDict, CFSTR( kXMLServerKey ) );
if ( cfStringRef != nil )
{
if ( CFGetTypeID( cfStringRef ) == CFStringGetTypeID() )
{
::memset(tmpBuff,0,1024);
if (CFStringGetCString(cfStringRef, tmpBuff, cfBuffSize, kCFStringEncodingMacRoman))
{
server = (char *)::calloc(1+strlen(tmpBuff),1);
::strcpy(server, tmpBuff);
}
}
}
}
if (CheckForConfig(server, serverIndex))
{
reuseEntry = true;
xConfig = (sLDAPConfigData *)pConfigTable->GetItemData( serverIndex );
if (xConfig != nil)
{
CleanLDAPConfigData( xConfig );
delete( xConfig );
xConfig = nil;
pConfigTable->RemoveItem( serverIndex );
}
}
if ( CFDictionaryContainsKey( ldapDict, CFSTR( kXMLOpenCloseTimeoutSecsKey ) ) )
{
cfNumber = (CFNumberRef)CFDictionaryGetValue( ldapDict, CFSTR( kXMLOpenCloseTimeoutSecsKey ) );
if ( cfNumber != nil )
{
cfNumBool = CFNumberGetValue(cfNumber, kCFNumberIntType, &opencloseTO);
}
}
if ( CFDictionaryContainsKey( ldapDict, CFSTR( kXMLSearchTimeoutSecsKey ) ) )
{
cfNumber = (CFNumberRef)CFDictionaryGetValue( ldapDict, CFSTR( kXMLSearchTimeoutSecsKey ) );
if ( cfNumber != nil )
{
cfNumBool = CFNumberGetValue(cfNumber, kCFNumberIntType, &searchTO);
}
}
if ( CFDictionaryContainsKey( ldapDict, CFSTR( kXMLPortNumberKey ) ) )
{
cfNumber = (CFNumberRef)CFDictionaryGetValue( ldapDict, CFSTR( kXMLPortNumberKey ) );
if ( cfNumber != nil )
{
cfNumBool = CFNumberGetValue(cfNumber, kCFNumberIntType, &portNumber);
}
}
if ( CFDictionaryContainsKey( ldapDict, CFSTR( kXMLSecureUseFlagKey ) ) )
{
cfBool= (CFBooleanRef)CFDictionaryGetValue( ldapDict, CFSTR( kXMLSecureUseFlagKey ) );
if (cfBool != nil)
{
bUseSecure = CFBooleanGetValue( cfBool );
}
}
if ( CFDictionaryContainsKey( ldapDict, CFSTR( kXMLUserDefinedNameKey ) ) )
{
cfStringRef = (CFStringRef)CFDictionaryGetValue( ldapDict, CFSTR( kXMLUserDefinedNameKey ) );
if ( cfStringRef != nil )
{
if ( CFGetTypeID( cfStringRef ) == CFStringGetTypeID() )
{
::memset(tmpBuff,0,1024);
if (CFStringGetCString(cfStringRef, tmpBuff, cfBuffSize, kCFStringEncodingMacRoman))
{
uiName = (char *)::calloc(1+strlen(tmpBuff),1);
::strcpy(uiName, tmpBuff);
}
}
}
}
if ( CFDictionaryContainsKey( ldapDict, CFSTR( kXMLServerAccountKey ) ) )
{
cfStringRef = (CFStringRef)CFDictionaryGetValue( ldapDict, CFSTR( kXMLServerAccountKey ) );
if ( cfStringRef != nil )
{
if ( CFGetTypeID( cfStringRef ) == CFStringGetTypeID() )
{
::memset(tmpBuff,0,1024);
if (CFStringGetCString(cfStringRef, tmpBuff, cfBuffSize, kCFStringEncodingMacRoman))
{
account = (char *)::calloc(1+strlen(tmpBuff),1);
::strcpy(account, tmpBuff);
}
}
}
}
if ( CFDictionaryContainsKey( ldapDict, CFSTR( kXMLServerPasswordKey ) ) )
{
cfStringRef = (CFStringRef)CFDictionaryGetValue( ldapDict, CFSTR( kXMLServerPasswordKey ) );
if ( cfStringRef != nil )
{
if ( CFGetTypeID( cfStringRef ) == CFDataGetTypeID() )
{
cfDataRef = (CFDataRef)cfStringRef;
passwordLen = CFDataGetLength(cfDataRef);
password = (char*)::calloc(1+passwordLen,1);
CFDataGetBytes(cfDataRef, CFRangeMake(0,passwordLen), (UInt8*)password);
}
else if ( CFGetTypeID( cfStringRef ) == CFStringGetTypeID() )
{
::memset(tmpBuff,0,1024);
if (CFStringGetCString(cfStringRef, tmpBuff, cfBuffSize, kCFStringEncodingMacRoman))
{
password = (char *)::calloc(1+strlen(tmpBuff),1);
::strcpy(password, tmpBuff);
}
}
}
}
if ( CFDictionaryContainsKey( ldapDict, CFSTR( kXMLStdMapUseFlagKey ) ) )
{
cfBool = (CFBooleanRef)CFDictionaryGetValue( ldapDict, CFSTR( kXMLStdMapUseFlagKey ) );
if (cfBool != nil)
{
bUseStdMap = CFBooleanGetValue( cfBool );
}
}
pConfig = MakeLDAPConfigData( uiName, server, bUseStdMap, opencloseTO, searchTO, portNumber, bUseSecure, account, password );
if ( uiName != nil )
{
free( uiName );
uiName = nil;
}
if ( server != nil )
{
free( server );
server = nil;
}
if ( account != nil )
{
free( account );
account = nil;
}
if ( password != nil )
{
free( password );
password = nil;
}
if (!bUseStdMap)
{
BuildLDAPMap( pConfig, ldapDict );
}
if (reuseEntry)
{
pConfigTable->AddItem( serverIndex, pConfig );
}
else
{
pConfigTable->AddItem( inIndex, pConfig );
fConfigTableLen++;
}
}
delete( tmpBuff );
}
return( siResult );
}
bool CLDAPConfigs::CheckForConfig ( char *inServerName, uInt32 &inConfigTableIndex )
{
bool result = false;
uInt32 iTableIndex = 0;
sLDAPConfigData *pConfig = nil;
for (iTableIndex=0; iTableIndex<fConfigTableLen; iTableIndex++)
{
pConfig = (sLDAPConfigData *)pConfigTable->GetItemData( iTableIndex );
if (pConfig != nil)
{
if (pConfig->fServerName != nil)
{
if (::strcmp(pConfig->fServerName, inServerName) == 0 )
{
result = true;
inConfigTableIndex = iTableIndex;
break;
}
}
}
}
return(result);
}
sInt32 CLDAPConfigs::BuildLDAPMap ( sLDAPConfigData *inConfig, CFDictionaryRef ldapDict )
{
sInt32 siResult = eDSNoErr; CFArrayRef cfArrayRef = nil;
sMapTuple *pRecMapTuple = nil;
sMapTuple *pAttrMapTuple = nil;
cfArrayRef = nil;
cfArrayRef = GetRecordTypeMapArray(ldapDict);
pRecMapTuple = BuildMapTuple(cfArrayRef);
cfArrayRef = nil;
cfArrayRef = GetAttributeTypeMapArray(ldapDict);
pAttrMapTuple = BuildMapTuple(cfArrayRef);
if (pRecMapTuple != nil)
{
inConfig->pRecordMapTuple = pRecMapTuple;
}
else
{
inConfig->pRecordMapTuple = pStdRecordMapTuple;
}
if (pAttrMapTuple != nil)
{
inConfig->pAttributeMapTuple = pAttrMapTuple;
}
else
{
inConfig->pAttributeMapTuple = pStdAttributeMapTuple;
}
return( siResult );
}
sMapTuple *CLDAPConfigs::BuildMapTuple ( CFArrayRef inArray )
{
CFArrayRef cfArrayRef = nil;
CFIndex cfMapCount = 0;
CFIndex cfNativeMapCount = 0;
sInt32 iMapIndex = 0;
sInt32 iNativeMapIndex = 0;
bool bUseMap = false;
CFStringRef cfStringRef = nil;
char *tmpBuff = nil;
CFIndex cfBuffSize = 1024;
char *stdMapType = nil;
char *nativeMapType = nil;
CFArrayRef cfNativeArrayRef = nil;
sMapTuple *pMapTuple = nil;
sMapTuple *currentMapTuple = nil;
sPtrString *currentNativeMap = nil;
sInt32 siResult = eDSNoErr;
cfArrayRef = inArray;
if (cfArrayRef != nil)
{
cfMapCount = ::CFArrayGetCount( cfArrayRef );
if (cfMapCount != 0)
{
tmpBuff = (char *) calloc(1, 1024);
for (iMapIndex = 0; iMapIndex < cfMapCount; iMapIndex++)
{
CFDictionaryRef typeMapDict;
typeMapDict = (CFDictionaryRef)::CFArrayGetValueAtIndex( cfArrayRef, iMapIndex );
if ( typeMapDict != nil )
{
if ( CFDictionaryContainsKey( typeMapDict, CFSTR( kXMLStdNameKey ) ) )
{
cfStringRef = (CFStringRef)CFDictionaryGetValue( typeMapDict, CFSTR( kXMLStdNameKey ) );
if ( cfStringRef != nil )
{
if ( CFGetTypeID( cfStringRef ) == CFStringGetTypeID() )
{
::memset(tmpBuff,0,1024);
if (CFStringGetCString(cfStringRef, tmpBuff, cfBuffSize, kCFStringEncodingMacRoman))
{
stdMapType = new char[1+strlen(tmpBuff)];
::strcpy(stdMapType, tmpBuff);
}
}
}
}
cfNativeArrayRef = nil;
cfNativeArrayRef = GetNativeTypeMapArray(typeMapDict);
if (cfNativeArrayRef != nil)
{
cfNativeMapCount = ::CFArrayGetCount( cfNativeArrayRef );
if ((cfNativeMapCount != 0) && (stdMapType != nil))
{
if (pMapTuple == nil)
{
pMapTuple = new sMapTuple;
currentMapTuple = pMapTuple;
}
else
{
currentMapTuple->pNext = new sMapTuple;
currentMapTuple = currentMapTuple->pNext;
}
if ( currentMapTuple != nil )
{
::memset( currentMapTuple, 0, sizeof( sMapTuple ) );
currentMapTuple->fStandard = stdMapType;
currentMapTuple->pNext = nil;
}
for (iNativeMapIndex = 0; iNativeMapIndex < cfNativeMapCount; iNativeMapIndex++)
{
CFStringRef nativeMapString;
nativeMapString = (CFStringRef)::CFArrayGetValueAtIndex( cfNativeArrayRef, iNativeMapIndex );
if ( nativeMapString != nil )
{
if ( CFGetTypeID( nativeMapString ) == CFStringGetTypeID() )
{
::memset(tmpBuff,0,1024);
if (CFStringGetCString(nativeMapString, tmpBuff, cfBuffSize, kCFStringEncodingMacRoman))
{
nativeMapType = new char[1+strlen(tmpBuff)];
::strcpy(nativeMapType, tmpBuff);
if (currentMapTuple->fNative == nil)
{
currentMapTuple->fNative = new sPtrString;
currentNativeMap = currentMapTuple->fNative;
}
else
{
currentNativeMap->pNext = new sPtrString;
currentNativeMap = currentNativeMap->pNext;
}
if ( currentNativeMap != nil )
{
::memset( currentNativeMap, 0, sizeof( sPtrString ) );
currentNativeMap->fName = nativeMapType;
currentNativeMap->pNext = nil;
bUseMap = true;
}
}
}
}
}
} else if (stdMapType != nil)
{
free( stdMapType );
stdMapType = nil;
}
}
}
}
delete( tmpBuff );
}
}
if (!bUseMap)
{
siResult = CleanMapTuple(pMapTuple);
}
return( pMapTuple );
}
char *CLDAPConfigs::GetVersion ( CFDictionaryRef configDict )
{
char *outVersion = nil;
CFStringRef cfStringRef = nil;
char *tmpBuff = nil;
CFIndex cfBuffSize = 1024;
if ( CFDictionaryContainsKey( configDict, CFSTR( kXMLLDAPVersionKey ) ) )
{
cfStringRef = (CFStringRef)CFDictionaryGetValue( configDict, CFSTR( kXMLLDAPVersionKey ) );
if ( cfStringRef != nil )
{
if ( CFGetTypeID( cfStringRef ) == CFStringGetTypeID() )
{
tmpBuff = new char[1024];
::memset(tmpBuff,0,1024);
if (CFStringGetCString(cfStringRef, tmpBuff, cfBuffSize, kCFStringEncodingMacRoman))
{
outVersion = new char[1+strlen(tmpBuff)];
::strcpy(outVersion, tmpBuff);
}
delete( tmpBuff );
}
}
}
return( outVersion );
}
CFArrayRef CLDAPConfigs::GetConfigArray ( CFDictionaryRef configDict )
{
CFArrayRef cfArrayRef = nil;
if ( CFDictionaryContainsKey( configDict, CFSTR( kXMLConfigArrayKey ) ) )
{
cfArrayRef = (CFArrayRef)CFDictionaryGetValue( configDict, CFSTR( kXMLConfigArrayKey ) );
}
return( cfArrayRef );
}
CFArrayRef CLDAPConfigs::GetDefaultRecordTypeMapArray ( CFDictionaryRef configDict )
{
CFArrayRef cfArrayRef = nil;
if ( CFDictionaryContainsKey( configDict, CFSTR( kXMLDefaultRecordTypeMapArrayKey ) ) )
{
cfArrayRef = (CFArrayRef)CFDictionaryGetValue( configDict, CFSTR( kXMLDefaultRecordTypeMapArrayKey ) );
}
return( cfArrayRef );
}
CFArrayRef CLDAPConfigs::GetDefaultAttrTypeMapArray ( CFDictionaryRef configDict )
{
CFArrayRef cfArrayRef = nil;
if ( CFDictionaryContainsKey( configDict, CFSTR( kXMLDefaultAttrTypeMapArrayKey ) ) )
{
cfArrayRef = (CFArrayRef)CFDictionaryGetValue( configDict, CFSTR( kXMLDefaultAttrTypeMapArrayKey ) );
}
return( cfArrayRef );
}
CFArrayRef CLDAPConfigs::GetRecordTypeMapArray ( CFDictionaryRef configDict )
{
CFArrayRef cfArrayRef = nil;
if ( CFDictionaryContainsKey( configDict, CFSTR( kXMLRecordTypeMapArrayKey ) ) )
{
cfArrayRef = (CFArrayRef)CFDictionaryGetValue( configDict, CFSTR( kXMLRecordTypeMapArrayKey ) );
}
return( cfArrayRef );
}
CFArrayRef CLDAPConfigs::GetAttributeTypeMapArray ( CFDictionaryRef configDict )
{
CFArrayRef cfArrayRef = nil;
if ( CFDictionaryContainsKey( configDict, CFSTR( kXMLAttrTypeMapArrayKey ) ) )
{
cfArrayRef = (CFArrayRef)CFDictionaryGetValue( configDict, CFSTR( kXMLAttrTypeMapArrayKey ) );
}
return( cfArrayRef );
}
CFArrayRef CLDAPConfigs::GetNativeTypeMapArray ( CFDictionaryRef configDict )
{
CFArrayRef cfArrayRef = nil;
if ( CFDictionaryContainsKey( configDict, CFSTR( kXMLNativeMapArrayKey ) ) )
{
cfArrayRef = (CFArrayRef)CFDictionaryGetValue( configDict, CFSTR( kXMLNativeMapArrayKey ) );
}
return( cfArrayRef );
}
sLDAPConfigData *CLDAPConfigs::MakeLDAPConfigData ( char *inName, char *inServerName, bool inUseStd,
int inOpenCloseTO, int inSearchTO, int inPortNum,
bool inUseSecure,
char *inAccount, char *inPassword )
{
sInt32 siResult = eDSNoErr;
sLDAPConfigData *configOut = nil;
configOut = new sLDAPConfigData;
if ( configOut != nil )
{
::memset( configOut, 0, sizeof( sLDAPConfigData ) );
siResult = CleanLDAPConfigData(configOut);
if (inName != nil)
{
configOut->fName = new char[1+::strlen( inName )];
::strcpy(configOut->fName, inName);
}
if (inServerName != nil)
{
configOut->fServerName = new char[1+::strlen( inServerName )];
::strcpy(configOut->fServerName, inServerName);
}
configOut->bUseStdMapping = inUseStd;
configOut->fOpenCloseTimeout = inOpenCloseTO;
configOut->fSearchTimeout = inSearchTO;
configOut->fServerPort = inPortNum;
configOut->bSecureUse = inUseSecure;
configOut->bUpdated = true;
if (inAccount != nil)
{
configOut->fServerAccount = new char[1+::strlen( inAccount )];
::strcpy(configOut->fServerAccount, inAccount);
}
if (inPassword != nil)
{
configOut->fServerPassword = new char[1+::strlen( inPassword )];
::strcpy(configOut->fServerPassword, inPassword);
}
if (inUseStd)
{
configOut->pAttributeMapTuple = pStdAttributeMapTuple;
configOut->pRecordMapTuple = pStdRecordMapTuple;
}
}
return( configOut );
}
sInt32 CLDAPConfigs::CleanLDAPConfigData ( sLDAPConfigData *inConfig )
{
sInt32 siResult = eDSNoErr;
if ( inConfig == nil )
{
siResult = eDSBadContextData; }
else
{
if (inConfig->fName != nil)
{
delete ( inConfig->fName );
}
if (inConfig->fServerName != nil)
{
delete ( inConfig->fServerName );
}
if (inConfig->fServerAccount != nil)
{
delete ( inConfig->fServerAccount );
}
if (inConfig->fServerPassword != nil)
{
delete ( inConfig->fServerPassword );
}
inConfig->fName = nil;
inConfig->fServerName = nil;
inConfig->fServerAccount = nil;
inConfig->fServerPassword = nil;
if (!(inConfig->bUseStdMapping))
{
CleanMapTuple(inConfig->pAttributeMapTuple);
CleanMapTuple(inConfig->pRecordMapTuple);
}
inConfig->bUseStdMapping = true;
inConfig->fOpenCloseTimeout = 120;
inConfig->fSearchTimeout = 120;
inConfig->fServerPort = 389;
inConfig->bSecureUse = false;
inConfig->bAvail = false;
inConfig->bUpdated = false;
}
return( siResult );
}