#ifndef __CLDAPNode_h__
#define __CLDAPNode_h__ 1
#include <stdio.h>
#include <string.h> //used for strcpy, etc.
#include <stdlib.h> //used for malloc
#include <DirectoryService/DirServices.h>
#include <DirectoryService/DirServicesUtils.h>
#include <DirectoryService/DirServicesConst.h>
#include <DirectoryServiceCore/PrivateTypes.h>
#include <DirectoryServiceCore/DSCThread.h>
#include <DirectoryServiceCore/DSMutexSemaphore.h>
#include <LDAP/lber.h>
#include <LDAP/ldap.h>
#include <stdio.h>
#include <map> //STL map class
#include <string> //STL string class
#include <time.h> //time_t usage
using namespace std;
typedef struct sLDAPContextData {
LDAP *fHost; DSMutexSemaphore
*fLDAPSessionMutex; uInt32 fConfigTableIndex; char *fName; int fPort; int fType; bool authCallActive; uInt32 offset; uInt32 index;
char *fOpenRecordType; char *fOpenRecordName; char *fOpenRecordDN; char *fUserName; void *fAuthCredential; char *fAuthType;
tDirReference fPWSRef;
tDirNodeReference fPWSNodeRef;
} sLDAPContextData;
typedef struct sLDAPNodeStruct {
LDAP *fHost; DSMutexSemaphore
*fLDAPSessionMutex; uInt32 fRefCount; uInt32 fLDAPConfigTableIndex; char *fServerName; int fDirectLDAPPort; char *fUserName; void *fAuthCredential; char *fAuthType; bool bHasFailed; time_t fDelayedBindTime; } sLDAPNodeStruct;
typedef map<string, sLDAPNodeStruct*> LDAPNodeMap;
typedef LDAPNodeMap::iterator LDAPNodeMapI;
class CLDAPNode
{
public:
CLDAPNode ( void );
virtual ~CLDAPNode ( void );
sInt32 SafeOpen ( char *inNodeName,
LDAP **outLDAPHost,
uInt32 *outLDAPConfigTableIndex );
sInt32 AuthOpen ( char *inNodeName,
LDAP *inHost,
char *inUserName,
void *inAuthCredential,
char *inAuthType,
LDAP **outLDAPHost,
uInt32 *inOutLDAPConfigTableIndex,
bool shouldCloseOld );
sInt32 RebindSession ( char *inNodeName,
LDAP *inHost,
LDAP **outLDAPHost );
sInt32 SimpleAuth ( char *inNodeName,
char *inUserName,
void *inAuthCredential );
sInt32 RebindAuthSession( char *inNodeName,
LDAP *inHost,
char *inUserName,
void *inAuthCredential,
char *inAuthType,
uInt32 inLDAPConfigTableIndex,
LDAP **outLDAPHost );
sInt32 SafeClose ( char *inNodeName,
LDAP *inHost);
void GetSchema ( sLDAPContextData *inContext );
LDAP* LockSession ( sLDAPContextData *inContext );
void UnLockSession ( sLDAPContextData *inContext );
protected:
sInt32 CleanLDAPNodeStruct ( sLDAPNodeStruct *inLDAPNodeStruct );
sInt32 BindProc ( sLDAPNodeStruct *inLDAPNodeStruct );
sInt32 ParseLDAPNodeName ( char *inNodeName,
char **outLDAPName,
int *outLDAPPort );
sInt32 GetSchemaMessage ( LDAP *inHost,
int inSearchTO,
LDAPMessage **outResultMsg );
bool IsTokenNotATag ( char *inToken );
private:
LDAPNodeMap fLDAPNodeMap;
DSMutexSemaphore fLDAPNodeOpenMutex;
};
#endif // __CLDAPNode_h__