#ifndef _CLDAPNODECONFIG_H
#define _CLDAPNODECONFIG_H
#include "CObject.h"
#include "CLDAPReplicaInfo.h"
#include "CLDAPDefines.h"
#include <DirectoryServiceCore/DSMutexSemaphore.h>
#include <CoreFoundation/CoreFoundation.h>
#include <map>
#include <set>
#include <string>
#include <list>
#include <netdb.h>
#include <dispatch/dispatch.h>
using namespace std;
typedef list<CLDAPReplicaInfo *> ListOfReplicas;
typedef ListOfReplicas::const_iterator ListOfReplicasI;
typedef list<string> listOfStrings;
typedef listOfStrings::const_iterator listOfStringsCI;
typedef set<string> AttrSet;
typedef AttrSet::const_iterator AttrSetCI;
struct sObjectClassSchema {
AttrSet fParentOCs; AttrSet fOtherNames; AttrSet fRequiredAttrs; AttrSet fAllowedAttrs; UInt16 fType; };
typedef map<string,sObjectClassSchema*> ObjectClassMap;
typedef ObjectClassMap::const_iterator ObjectClassMapCI;
class CLDAPv3Configs;
class CLDAPConnection;
class CLDAPNodeConfig : public CObject<CLDAPNodeConfig>
{
public:
CFStringRef fConfigUUID; char *fNodeName; int32_t fDHCPLDAPServer; int32_t fNodeIsLDAPURL;
int32_t fIsSSL; int32_t fIdleMaxCount; int32_t fSearchTimeout; int32_t fOpenCloseTimeout; int32_t fDelayRebindTry; int32_t fAvailable; int32_t fSecureUse; int32_t fSecurityLevel;
int32_t fConfigDeleted; int32_t fEnableUse;
public:
CLDAPNodeConfig ( CLDAPv3Configs *inConfig, const char *inNodeName, CFStringRef inUUID );
CLDAPNodeConfig ( CLDAPv3Configs *inConfig, const char *inLDAPURL, bool inDHCPLDAPServer = true );
LDAP *EstablishConnection ( CLDAPReplicaInfo **inOutReplicaInfo, bool inWriteable, const char *inLDAPUsername,
const char *inKerberosID, const char *inPassword, void *inCallback, void *inParam,
tDirStatus *outStatus);
LDAP *EstablishConnection ( CLDAPReplicaInfo **inOutReplicaInfo, bool inWriteable, const char *inKerberosCache,
void *inCallback, void *inParam, tDirStatus *outStatus );
LDAP *EstablishConnection ( CLDAPReplicaInfo **inOutReplicaInfo, bool inWriteable, void *inCallback, void *inParam,
tDirStatus *outStatus );
bool UpdateDynamicData ( LDAP *inLD, CLDAPReplicaInfo *inReplica );
void ReinitializeReplicaList ( void );
void DeleteConfiguration ( void );
bool UpdateConfiguraton ( CFDictionaryRef inServerConfig, bool inFromServer );
CFDictionaryRef GetConfiguration ( void );
char *CopyUIName ( void );
char *CopyMapSearchBase ( void );
bool CopyCredentials ( char **outUsername, char **outKerberosID, char **outPassword );
char *MapRecToSearchBase ( const char *inRecType, int inIndex, bool *outOCGroup, CFArrayRef *outOCListCFArray,
ber_int_t *outScope );
char *MapAttrToLDAPType ( const char *inRecType, const char *inAttrType, int inIndex,
bool bSkipLiteralMappings = false );
char **MapAttrToLDAPTypeArray( const char *inRecType, const char *inAttrType );
char *ExtractRecMap ( const char *inRecType, int inIndex, bool *outOCGroup, CFArrayRef *outOCListCFArray,
ber_int_t* outScope );
char *ExtractAttrMap ( const char *inRecType, const char *inAttrType, int inIndex );
char *ExtractStdAttrName ( char *inRecType, int &inputIndex );
int AttrMapsCount ( const char *inRecType, const char *inAttrType );
CFDictionaryRef CopyNormalizedMappings ( void );
void GetReqAttrListForObjectList ( CLDAPConnection *inLDAPConnection, listOfStrings &inObjectClassList,
listOfStrings &outReqAttrsList );
char *BuildLDAPQueryFilter ( char *inConstAttrType, const char *inConstAttrName, tDirPatternMatch patternMatch,
bool useWellKnownRecType, const char *inRecType, char *inNativeRecType, bool inbOCANDGroup,
CFArrayRef inOCSearchList );
CFStringRef ParseCompoundExpression ( const char *inConstAttrName, const char *inRecType );
void NetworkTransition ( void );
bool CheckIfFailed ( void );
static void ReachabilityCallback ( SCNetworkReachabilityRef inTarget, SCNetworkConnectionFlags inFlags, void *inInfo );
private:
DSMutexSemaphore fMutex;
CLDAPv3Configs *fConfigObject;
ListOfReplicas fReplicaList;
char *fServerAccount; char *fServerKerberosID; char *fServerPassword;
char *fMapSearchBase; char *fServerName; char *fConfigUIName;
int32_t fGetServerMappings; int32_t fGetReplicas; int32_t fGetSecuritySettings;
dispatch_source_t fDynamicRefreshTimer;
DSSemaphore fMappingsLock;
CFDictionaryRef fNormalizedMappings; CFArrayRef fRecordTypeMapArray;
CFArrayRef fAttrTypeMapArray;
CFMutableArrayRef fReadReplicas;
CFMutableArrayRef fWriteReplicas;
CFMutableArrayRef fDeniedSASLMethods;
ObjectClassMap *fObjectClassSchema;
SCNetworkReachabilityRef fReachabilityRef; CFAbsoluteTime fLastFailedCheck;
int32_t fServerPort; int32_t fReferrals; int32_t fDNSReplicas;
int32_t fServerMappings;
int32_t fLocalSecurityLevel;
private:
virtual ~CLDAPNodeConfig ( void );
void RefreshDynamicData ( void );
void ReachabilityNotification ( SCNetworkConnectionFlags inFlags );
void SetLDAPOptions ( LDAP *inLDAP );
void InitializeVariables ( void );
LDAP *FindSuitableReplica ( CLDAPReplicaInfo **inOutReplicaInfo, bool inForceCheck, bool inWriteable,
void *inCallback, void *inParam );
LDAP *InternalEstablishConnection ( CLDAPReplicaInfo **inOutReplicaInfo, bool inWriteable, void *inCallback, void *inParam );
LDAP *CheckWithSelect ( fd_set &inSet, struct timeval *inCheckTime, int inCount, int *inSockList,
CLDAPReplicaInfo **inReplicas, CLDAPReplicaInfo **outSelectedReplica, void *inCallback,
void *inParam );
void ClearSockList ( int *inSockList, int inSockCount, bool inClose );
bool IsLocalAddress ( struct addrinfo *addrInfo );
tDirStatus AuthenticateUsingCredentials ( LDAP *inLDAP, CLDAPReplicaInfo *inReplica, const char *inLDAPUsername,
const char *inKerberosID, const char *inPassword );
tDirStatus AuthenticateUsingKerberos ( LDAP *inLDAP, CLDAPReplicaInfo *inReplica, const char *inKerberosCache );
bool IsTokenNotATag ( char *inToken );
bool RetrieveServerMappings ( LDAP *inLDAP, CLDAPReplicaInfo *inReplica );
bool RetrieveServerReplicaList ( LDAP *inLDAP, CFMutableArrayRef outRepList, CFMutableArrayRef outWriteableList );
bool RetrieveServerSecuritySettings ( LDAP *inLDAP, CLDAPReplicaInfo *inReplica );
void RetrieveServerSchema ( LDAP *inLDAP );
void MergeArraysRemovingDuplicates ( CFMutableArrayRef cfPrimaryArray, CFArrayRef cfArrayToAdd );
SInt32 GetReplicaListFromDNS ( CFMutableArrayRef inOutRepList );
SInt32 GetReplicaListFromAltServer ( LDAP *inHost, CFMutableArrayRef inOutRepList );
bool GetSInt32FromDictionary ( CFDictionaryRef inDictionary, CFStringRef inKey, int32_t *outValue, int32_t defaultValue );
bool GetCStringFromDictionary ( CFDictionaryRef inDictionary, CFStringRef inKey, char **outValue );
CFDictionaryRef CreateNormalizedAttributeMap ( CFArrayRef inAttrMapArray, CFDictionaryRef inGlobalAttrMap );
CFDictionaryRef CreateNormalizedRecordAttrMap ( CFArrayRef inRecMapArray, CFArrayRef inGlobalAttrMapArray );
int32_t CalculateSecurityPolicy ( CFDictionaryRef inConfiguration );
bool GetUserTGTIfNecessaryAndStore ( const char *inName, const char *inPassword, char **outCacheName );
void BuildReplicaList ( void );
static int SASLInteract ( LDAP *ld, unsigned flags, void *inDefaults, void *inInteract );
};
#endif