diff --git a/include/mdb.h b/include/mdb.h deleted file mode 100644 index 9ba1f56..0000000 --- a/include/mdb.h +++ /dev/null @@ -1,252 +0,0 @@ -/**************************************************************************** - * - * Copyright (c) 2001 Novell, Inc. All Rights Reserved. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public License - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, contact Novell, Inc. - * - * To contact Novell about this file by physical or electronic mail, you - * may find current contact information at www.novell.com. - * - ****************************************************************************/ - - -#ifndef MDB_H -#define MDB_H - -/* Generic */ -#define MDB_CURRENT_API_VERSION 1 -#define MDB_COMPATIBLE_TO_API 1 -#define MDB_MAX_API_DESCRIPTION_CHARS 256 - -/* Length definitions */ -#define MDB_MAX_OBJECT_CHARS 256 -#define MDB_MAX_UTF8_OBJECT_CHARS 768 -#define MDB_MAX_ATTRIBUTE_VALUE_CHARS 10240 -#define MDB_MAX_ATTRIBUTE_VALUE_UTF8_CHARS (10240*3) -#define MDB_MAX_TREE_CHARS 32 -#define MDB_MAX_ATTRIBUTE_CHARS 32 - -/* Attribute types */ -#define MDB_ATTR_SYN_STRING 'S' -#define MDB_ATTR_SYN_DIST_NAME 'D' -#define MDB_ATTR_SYN_BOOL 'B' -#define MDB_ATTR_SYN_BINARY 'O' - -/* Little helpers */ -#define MDB_IS_MDB_API_COMPATIBLE(Handle) (MDBGetAPIVersion(TRUE, NULL, Handle)<=MDB_CURRENT_API_VERSION) -#define MDB_CURRENT_CONTEXT "." -#define MDBGetLastError(ValueStruct) (ValueStruct->ErrNo) - -/* Depth */ -#define MDB_SCOPE_BASE 0 -#define MDB_SCOPE_ONELEVEL 1 -#define MDB_SCOPE_INFINITE 2 - -/* Used for MDBCreateObject */ -#ifndef __cplusplus -#define MDBAddStringAttribute(AttrName, AttrValue, AttrStruct, DataStruct) { unsigned char Temp[MDB_MAX_UTF8_OBJECT_CHARS]; Temp[0]=MDB_ATTR_SYN_STRING; strcpy(Temp+1, (unsigned char *)((AttrName))); MDBAddValue(Temp, (AttrStruct)); MDBAddValue((const unsigned char *)((AttrValue)), (DataStruct)); } -#define MDBAddDNAttribute(AttrName, AttrValue, AttrStruct, DataStruct) { unsigned char Temp[MDB_MAX_UTF8_OBJECT_CHARS]; Temp[0]=MDB_ATTR_SYN_DIST_NAME; strcpy(Temp+1, (unsigned char *)((AttrName))); MDBAddValue(Temp, (AttrStruct)); MDBAddValue((const unsigned char *)((AttrValue)), (DataStruct)); } -#endif - -#if !defined(MDB_INTERNAL) -typedef void * MDBHandle; -typedef void MDBEnumStruct; - -typedef struct { - unsigned char **Value; - unsigned long Used; - unsigned long ErrNo; - struct _MDBInterfaceStruct *Interface; -} MDBValueStruct; -#endif - -typedef struct _MDBInterfaceStruct { - BOOL (* MDBGetServerInfo)(unsigned char *HostDN, unsigned char *HostTree, MDBValueStruct *V); - MDBHandle (* MDBAuthenticate)(const unsigned char *Object, const unsigned char *Password, const unsigned char *Arguments); - BOOL (* MDBRelease)(MDBHandle Handle); - MDBValueStruct *(* MDBCreateValueStruct)(MDBHandle Handle, const unsigned char *Context); - BOOL (* MDBDestroyValueStruct)(MDBValueStruct *V); - MDBValueStruct *(* MDBShareContext)(MDBValueStruct *VOld); - BOOL (* MDBSetValueStructContext)(const unsigned char *Context, MDBValueStruct *V); - MDBEnumStruct *(* MDBCreateEnumStruct)(MDBValueStruct *V); - BOOL (* MDBDestroyEnumStruct)(MDBEnumStruct *E, MDBValueStruct *V); - BOOL (* MDBAddValue)(const unsigned char *Value, MDBValueStruct *V); - BOOL (* MDBFreeValue)(unsigned long Index, MDBValueStruct *V); - BOOL (* MDBFreeValues)(MDBValueStruct *V); - long (* MDBRead)(const unsigned char *Object, const unsigned char *Attribute, MDBValueStruct *V); - const unsigned char *(* MDBReadEx)(const unsigned char *Object, const unsigned char *Attribute, MDBEnumStruct *E, MDBValueStruct *V); - long (* MDBReadDN)(const unsigned char *Object, const unsigned char *Attribute, MDBValueStruct *V); - BOOL (* MDBWriteTyped)(const unsigned char *Object, const unsigned char *Attribute, const int AttrType, MDBValueStruct *V); - BOOL (* MDBWrite)(const unsigned char *Object, const unsigned char *Attribute, MDBValueStruct *V); - BOOL (* MDBWriteDN)(const unsigned char *Object, const unsigned char *Attribute, MDBValueStruct *V); - BOOL (* MDBClear)(const unsigned char *Object, const unsigned char *Attribute, MDBValueStruct *V); - BOOL (* MDBAdd)(const unsigned char *Object, const unsigned char *Attribute, const unsigned char *Value, MDBValueStruct *V); - BOOL (* MDBAddDN)(const unsigned char *Object, const unsigned char *Attribute, const unsigned char *Value, MDBValueStruct *V); - BOOL (* MDBRemove)(const unsigned char *Object, const unsigned char *Attribute, const unsigned char *Value, MDBValueStruct *V); - BOOL (* MDBRemoveDN)(const unsigned char *Object, const unsigned char *Attribute, const unsigned char *Value, MDBValueStruct *V); - BOOL (* MDBIsObject)(const unsigned char *Object, MDBValueStruct *V); - BOOL (* MDBGetObjectDetails)(const unsigned char *Object, unsigned char *Type, unsigned char *RDN, unsigned char *DN, MDBValueStruct *V); - BOOL (* MDBGetObjectDetailsEx)(const unsigned char *Object, MDBValueStruct *Types, unsigned char *RDN, unsigned char *DN, MDBValueStruct *V); - BOOL (* MDBVerifyPassword)(const unsigned char *Object, const unsigned char *Password, MDBValueStruct *V); - BOOL (* MDBVerifyPasswordEx)(const unsigned char *Object, const unsigned char *Password, MDBValueStruct *V); /* Better error reporting */ - BOOL (* MDBChangePassword)(const unsigned char *Object, const unsigned char *OldPassword, const unsigned char *NewPassword, MDBValueStruct *V); - BOOL (* MDBChangePasswordEx)(const unsigned char *Object, const unsigned char *OldPassword, const unsigned char *NewPassword, MDBValueStruct *V); - long (* MDBEnumerateObjects)(const unsigned char *Container, const unsigned char *Type, const unsigned char *Pattern, MDBValueStruct *V); - const unsigned char *(* MDBEnumerateObjectsEx)(const unsigned char *Container, const unsigned char *Type, const unsigned char *Pattern, unsigned long Flags, MDBEnumStruct *E, MDBValueStruct *V); - BOOL (* MDBAddAddressRestriction)(const unsigned char *Object, const unsigned char *Server, MDBValueStruct *V); - const unsigned char *(* MDBEnumerateAttributesEx)(const unsigned char *Object, MDBEnumStruct *E, MDBValueStruct *V); - BOOL (* MDBCreateObject)(const unsigned char *Object, const unsigned char *Class, MDBValueStruct *Attribute, MDBValueStruct *Data, MDBValueStruct *V); - BOOL (* MDBDeleteObject)(const unsigned char *Object, BOOL Recursive, MDBValueStruct *V); - BOOL (* MDBRenameObject)(const unsigned char *ObjectOld, const unsigned char *ObjectNew, MDBValueStruct *V); - BOOL (* MDBDefineAttribute)(const unsigned char *Attribute, const unsigned char *ASN1, unsigned long Type, BOOL SingleValue, BOOL ImmediateSync, BOOL Public, MDBValueStruct *V); - BOOL (* MDBUndefineAttribute)(const unsigned char *Attribute, MDBValueStruct *V); - BOOL (* MDBDefineClass)(const unsigned char *Class, const unsigned char *ASN1, BOOL Container, MDBValueStruct *Superclass, MDBValueStruct *Containment, MDBValueStruct *Naming, MDBValueStruct *Mandatory, MDBValueStruct *Optional, MDBValueStruct *V); - BOOL (* MDBAddAttribute)(const unsigned char *Attribute, const unsigned char *Class, MDBValueStruct *V); - BOOL (* MDBUndefineClass)(const unsigned char *Class, MDBValueStruct *V); - BOOL (* MDBListContainableClasses)(const unsigned char *Container, MDBValueStruct *V); - const unsigned char *(* MDBListContainableClassesEx)(const unsigned char *Container, MDBEnumStruct *E, MDBValueStruct *V); - BOOL (* MDBGrantObjectRights)(const unsigned char *Object, const unsigned char *TrusteeDN, BOOL Read, BOOL Write, BOOL Delete, BOOL Rename, BOOL Admin, MDBValueStruct *V); - BOOL (* MDBGrantAttributeRights)(const unsigned char *Object, const unsigned char *Attribute, const unsigned char *TrusteeDN, BOOL Read, BOOL Write, BOOL Admin, MDBValueStruct *V); - char *(* MDBGetBaseDN)(MDBValueStruct *V); - BOOL (* MDBCreateAlias)(const unsigned char *Alias, const unsigned char *AliasedObjectDn, MDBValueStruct *V); - BOOL (* MDBFindObjects)(const unsigned char *Container, - MDBValueStruct *Types, - const unsigned char *Pattern, - MDBValueStruct *Attributes, - int depth, - int max, - MDBValueStruct *V); - BOOL (* Reserved3)(void); - BOOL (* Reserved4)(void); - BOOL (* Reserved5)(void); - BOOL (* Reserved6)(void); - BOOL (* Reserved7)(void); - BOOL (* Reserved8)(void); - BOOL (* Reserved9)(void); - BOOL (* Reserved10)(void); - BOOL (* Reserved11)(void); - BOOL (* Reserved12)(void); - BOOL (* Reserved13)(void); - BOOL (* Reserved14)(void); - BOOL (* Reserved15)(void); - BOOL (* Reserved16)(void); - BOOL (* Reserved17)(void); - BOOL (* Reserved18)(void); - BOOL (* Reserved19)(void); -} MDBInterfaceStruct; - -typedef struct { - unsigned char Error[128]; - MDBInterfaceStruct Interface; - const unsigned char *Arguments; -} MDBDriverInitStruct; - -typedef BOOL (* MDBDriverInitFunc)(MDBDriverInitStruct *Init); -typedef BOOL (* MDBDriverShutdownFunc)(void); - -#ifdef __cplusplus -extern "C" { -#endif - -/* Prototypes for generic things */ -EXPORT BOOL MDBInit(void); -EXPORT BOOL MDBShutdown(void); - -EXPORT int MDBGetAPIVersion(BOOL WantCompatibleVersion, unsigned char *Description, MDBHandle Context); -EXPORT BOOL MDBGetServerInfo(unsigned char *HostDN, unsigned char *HostTree, MDBValueStruct *V); /* Deprecated */ -EXPORT char *MDBGetBaseDN(MDBValueStruct *V); - -/* Authentication */ -EXPORT MDBHandle MDBAuthenticate(const unsigned char *Module, const unsigned char *Object, const unsigned char *Password); -EXPORT BOOL MDBRelease(MDBHandle Context); - -/* ValueStruct initialization & manipulation */ -EXPORT MDBValueStruct *MDBCreateValueStruct(MDBHandle Handle, const unsigned char *Context); -EXPORT BOOL MDBDestroyValueStruct(MDBValueStruct *V); -EXPORT MDBValueStruct *MDBShareContext(MDBValueStruct *VOld); -EXPORT BOOL MDBSetValueStructContext(const unsigned char *Context, MDBValueStruct *V); - -EXPORT MDBEnumStruct *MDBCreateEnumStruct(MDBValueStruct *V); -EXPORT BOOL MDBDestroyEnumStruct(MDBEnumStruct *E, MDBValueStruct *V); - -EXPORT BOOL MDBAddValue(const unsigned char *Value, MDBValueStruct *V); -EXPORT BOOL MDBFreeValue(unsigned long Index, MDBValueStruct *V); -EXPORT BOOL MDBFreeValues(MDBValueStruct *V); - - -/* Attribute operations */ -EXPORT long MDBRead(const unsigned char *Object, const unsigned char *Attribute, MDBValueStruct *V); -EXPORT const unsigned char *MDBReadEx(const unsigned char *Object, const unsigned char *Attribute, MDBEnumStruct *E, MDBValueStruct *V); -EXPORT long MDBReadDN(const unsigned char *Object, const unsigned char *Attribute, MDBValueStruct *V); -EXPORT BOOL MDBWriteTyped(const unsigned char *Object, const unsigned char *Attribute, const int AttrType, MDBValueStruct *V); -EXPORT BOOL MDBWrite(const unsigned char *Object, const unsigned char *Attribute, MDBValueStruct *V); -EXPORT BOOL MDBWriteDN(const unsigned char *Object, const unsigned char *Attribute, MDBValueStruct *V); -EXPORT BOOL MDBClear(const unsigned char *Object, const unsigned char *Attribute, MDBValueStruct *V); - -/* Advanced attribute operations */ -EXPORT BOOL MDBAdd(const unsigned char *Object, const unsigned char *Attribute, const unsigned char *Value, MDBValueStruct *V); -EXPORT BOOL MDBAddDN(const unsigned char *Object, const unsigned char *Attribute, const unsigned char *Value, MDBValueStruct *V); -EXPORT BOOL MDBRemove(const unsigned char *Object, const unsigned char *Attribute, const unsigned char *Value, MDBValueStruct *V); -EXPORT BOOL MDBRemoveDN(const unsigned char *Object, const unsigned char *Attribute, const unsigned char *Value, MDBValueStruct *V); - -/* Object operations */ -EXPORT BOOL MDBIsObject(const unsigned char *Object, MDBValueStruct *V); -EXPORT BOOL MDBGetObjectDetails(const unsigned char *Object, unsigned char *Type, unsigned char *RDN, unsigned char *DN, MDBValueStruct *V); -EXPORT BOOL MDBGetObjectDetailsEx(const unsigned char *Object, MDBValueStruct *Types, unsigned char *RDN, unsigned char *DN, MDBValueStruct *V); -EXPORT BOOL MDBVerifyPassword(const unsigned char *Object, const unsigned char *Password, MDBValueStruct *V); -EXPORT BOOL MDBVerifyPasswordEx(const unsigned char *Object, const unsigned char *Password, MDBValueStruct *V); /* Better error reporting */ -EXPORT BOOL MDBChangePassword(const unsigned char *Object, const unsigned char *OldPassword, const unsigned char *NewPassword, MDBValueStruct *V); -EXPORT BOOL MDBChangePasswordEx(const unsigned char *Object, const unsigned char *OldPassword, const unsigned char *NewPassword, MDBValueStruct *V); -EXPORT long MDBEnumerateObjects(const unsigned char *Container, const unsigned char *Type, const unsigned char *Pattern, MDBValueStruct *V); -EXPORT const unsigned char *MDBEnumerateObjectsEx(const unsigned char *Container, const unsigned char *Type, const unsigned char *Pattern, unsigned long Flags, MDBEnumStruct *E, MDBValueStruct *V); - -EXPORT BOOL MDBFindObjects(const unsigned char *Container, - MDBValueStruct *Types, - const unsigned char *Pattern, - MDBValueStruct *Attributes, - int depth, - int max, - MDBValueStruct *V); - - -/* Advanced Object operations */ -EXPORT const unsigned char *MDBEnumerateAttributesEx(const unsigned char *Object, MDBEnumStruct *E, MDBValueStruct *V); - -/* Object manipulation */ -EXPORT BOOL MDBCreateAlias(const unsigned char *Alias, const unsigned char *AliasedObjectDn, MDBValueStruct *V); -EXPORT BOOL MDBCreateObject(const unsigned char *Object, const unsigned char *Class, MDBValueStruct *Attribute, MDBValueStruct *Data, MDBValueStruct *V); -EXPORT BOOL MDBDeleteObject(const unsigned char *Object, BOOL Recursive, MDBValueStruct *V); -EXPORT BOOL MDBRenameObject(const unsigned char *ObjectOld, const unsigned char *ObjectNew, MDBValueStruct *V); - -/* Schema manipulation */ -EXPORT BOOL MDBDefineAttribute(const unsigned char *Attribute, const unsigned char *ASN1, unsigned long Type, BOOL SingleValue, BOOL ImmediateSync, BOOL Public, MDBValueStruct *V); -EXPORT BOOL MDBUndefineAttribute(const unsigned char *Attribute, MDBValueStruct *V); - -EXPORT BOOL MDBDefineClass(const unsigned char *Class, const unsigned char *ASN1, BOOL Container, MDBValueStruct *Superclass, MDBValueStruct *Containment, MDBValueStruct *Naming, MDBValueStruct *Mandatory, MDBValueStruct *Optional, MDBValueStruct *V); -EXPORT BOOL MDBAddAttribute(const unsigned char *Attribute, const unsigned char *Class, MDBValueStruct *V); -EXPORT BOOL MDBUndefineClass(const unsigned char *Class, MDBValueStruct *V); - -EXPORT BOOL MDBListContainableClasses(const unsigned char *Container, MDBValueStruct *V); -EXPORT const unsigned char *MDBListContainableClassesEx(const unsigned char *Container, MDBEnumStruct *E, MDBValueStruct *V); - -/* Object rights */ -EXPORT BOOL MDBGrantObjectRights(const unsigned char *Object, const unsigned char *TrusteeDN, BOOL Read, BOOL Write, BOOL Delete, BOOL Rename, BOOL Admin, MDBValueStruct *V); -EXPORT BOOL MDBGrantAttributeRights(const unsigned char *Object, const unsigned char *Attribute, const unsigned char *TrusteeDN, BOOL Read, BOOL Write, BOOL Admin, MDBValueStruct *V); - -/* Debug helper */ -EXPORT BOOL MDBDumpValueStruct(MDBValueStruct *V); - -#ifdef __cplusplus -} -#endif -#endif /* MDB_H */ diff --git a/src/agents/connmgr/cmmodules/lists/cmlists.c b/src/agents/connmgr/cmmodules/lists/cmlists.c deleted file mode 100644 index 037534e..0000000 --- a/src/agents/connmgr/cmmodules/lists/cmlists.c +++ /dev/null @@ -1,350 +0,0 @@ -/**************************************************************************** - * - * Copyright (c) 2001 Novell, Inc. All Rights Reserved. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public License - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, contact Novell, Inc. - * - * To contact Novell about this file by physical or electronic mail, you - * may find current contact information at www.novell.com. - * - ****************************************************************************/ - -#include -#include -#include -#include -#include - -#include "cmlists.h" - -/* Globals */ -BOOL ListUnloadOk = TRUE; -ListGlobal List; - -static BOOL ReadConfiguration(void); - - -EXPORT int ListsVerify(ConnMgrCommand *command, ConnMgrResult *result) -{ - unsigned long i; - - /* Check Allowed List */ - if ((XplStrCaseCmp(command->event, CM_EVENT_RELAY) == 0) || (XplStrCaseCmp(command->event, CM_EVENT_CONNECT) == 0)) { - for (i = 0; i < List.allowed.count; i++) { - if ((List.allowed.start[i] <= (long) command->address) && ((long) command->address <= List.allowed.end[i])) { - /* We like the guy */ - return(CM_MODULE_ACCEPT | CM_MODULE_PERMANENT | CM_MODULE_FORCE); - } - } - } - - /* Check Blocked List */ - if (XplStrCaseCmp(command->event, CM_EVENT_CONNECT) == 0) { - for (i = 0; i < List.blocked.count; i++) { - if ((List.blocked.start[i] <= (long) command->address) && ((long) command->address <= List.blocked.end[i])) { - /* We don't like the guy */ - return(CM_MODULE_DENY | CM_MODULE_PERMANENT | CM_MODULE_FORCE); - } - } - } - - return(0); -} - -EXPORT BOOL -CMLISTSInit(CMModuleRegistrationStruct *registration, unsigned char *datadir) -{ - if (ListUnloadOk == TRUE) { - XplSafeWrite(List.threadCount, 0); - - List.directoryHandle = (MDBHandle) MsgInit(); - if (List.directoryHandle) { - ListUnloadOk = FALSE; - - List.logHandle = LoggerOpen("cmlist"); - if (List.logHandle == NULL) { - XplConsolePrintf("cmlist: Unable to initialize logging. Logging disabled.\r\n"); - } - - /* Fill out registration information */ - registration->priority = 1; /* It is important that the lists are early */ - registration->Shutdown = ListsShutdown; - registration->Verify = ListsVerify; - registration->Notify = NULL; - - XplSafeIncrement(List.threadCount); - - strcpy(List.config.datadir, datadir); - - return(ReadConfiguration()); - } else { - XplConsolePrintf("cmlist: Failed to obtain directory handle\r\n"); - } - } - - return(FALSE); -} - -static void -AddBlockedAddress(const unsigned char *AddressStart, const unsigned char *AddressEnd) -{ - if ((List.blocked.count + 1) > List.blocked.allocated) { - List.blocked.start = MemRealloc(List.blocked.start, (List.blocked.allocated + 5) * sizeof(unsigned long)); - List.blocked.end = MemRealloc(List.blocked.end, (List.blocked.allocated + 5) * sizeof(unsigned long)); - - if (!List.blocked.start || !List.blocked.end) { - LoggerEvent(List.logHandle, LOGGER_SUBSYSTEM_GENERAL, LOGGER_EVENT_OUT_OF_MEMORY, LOG_ERROR, 0, __FILE__, NULL, ((List.blocked.allocated+5) + (List.blocked.allocated+5)) * sizeof(unsigned long), __LINE__, NULL, 0); - return; - } - - List.blocked.allocated += 5; - } - - if ((List.blocked.start[List.blocked.count] = inet_addr(AddressStart)) != -1) { - List.blocked.start[List.blocked.count] = ntohl(List.blocked.start[List.blocked.count]); - - if ((List.blocked.end[List.blocked.count] = inet_addr(AddressEnd)) != -1) { - List.blocked.end[List.blocked.count] = ntohl(List.blocked.end[List.blocked.count]); - List.blocked.count++; - } - } -} - -static void -FreeBlockedAddresses(void) -{ - if (List.blocked.start) { - MemFree(List.blocked.start); - } - - List.blocked.start = NULL; - - if (List.blocked.end) { - MemFree(List.blocked.end); - } - List.blocked.end = NULL; - - List.blocked.allocated = 0; - List.blocked.count = 0; -} - -static void -AddAllowedAddress(const unsigned char *AddressStart, const unsigned char *AddressEnd) -{ - if ((List.allowed.count + 1) > List.allowed.allocated) { - List.allowed.start = MemRealloc(List.allowed.start, (List.allowed.allocated + 5) * sizeof(unsigned long)); - List.allowed.end = MemRealloc(List.allowed.end, (List.allowed.allocated + 5) * sizeof(unsigned long)); - - if (!List.allowed.start || !List.allowed.end) { - LoggerEvent(List.logHandle, LOGGER_SUBSYSTEM_GENERAL, LOGGER_EVENT_OUT_OF_MEMORY, LOG_ERROR, 0, __FILE__, NULL, ((List.allowed.allocated+5) + (List.allowed.allocated+5)) * sizeof(unsigned long), __LINE__, NULL, 0); - return; - } - - List.allowed.allocated += 5; - } - - if ((List.allowed.start[List.allowed.count] = inet_addr(AddressStart)) != -1) { - List.allowed.start[List.allowed.count] = ntohl(List.allowed.start[List.allowed.count]); - - if ((List.allowed.end[List.allowed.count] = inet_addr(AddressEnd)) != -1) { - List.allowed.end[List.allowed.count] = ntohl(List.allowed.end[List.allowed.count]); - List.allowed.count++; - } - } -} - -static void -FreeAllowedAddresses(void) -{ - if (List.allowed.start) { - MemFree(List.allowed.start); - } - - List.allowed.start = NULL; - - if (List.allowed.end) { - MemFree(List.allowed.end); - } - - List.allowed.end = NULL; - - List.allowed.allocated = 0; - List.allowed.count = 0; -} - -EXPORT BOOL -ListsShutdown(void) -{ - XplSafeDecrement(List.threadCount); - - if (ListUnloadOk == FALSE) { - ListUnloadOk = TRUE; - - /* - Make sure the library lists are gone before beginning to - shutdown. - */ - while (XplSafeRead(List.threadCount)) { - XplDelay(33); - } - - LoggerClose(List.logHandle); - FreeBlockedAddresses(); - FreeAllowedAddresses(); - -#if defined(NETWARE) || defined(LIBC) - XplSignalLocalSemaphore(List.shutdownSemaphore); /* The signal will release main() */ - XplWaitOnLocalSemaphore(List.shutdownSemaphore); /* The wait will wait until main() is gone */ - - XplCloseLocalSemaphore(List.shutdownSemaphore); -#endif - } - - return(FALSE); -} - -static BOOL -ReadConfiguration(void) -{ - MDBValueStruct *config; - const unsigned char *Address; - MDBEnumStruct *e; - unsigned char *ptr; - - config = MDBCreateValueStruct(List.directoryHandle, MsgGetServerDN(NULL)); - e = MDBCreateEnumStruct(config); - - if (MDBRead(MSGSRV_AGENT_CONNMGR "\\" MSGSRV_AGENT_CMLISTS, MSGSRV_A_DISABLED, config)) { - if (atol(config->Value[0]) == 1) { - MDBDestroyValueStruct(config); - ListsShutdown(); - return(FALSE); - } - } - - if (MDBRead(MSGSRV_AGENT_CONNMGR "\\" MSGSRV_AGENT_CMLISTS, MSGSRV_A_CONFIG_CHANGED, config)) { - List.config.last = atol(config->Value[0]); - MDBFreeValues(config); - } else { - List.config.last = 0; - } - - while ((Address = MDBReadEx(MSGSRV_AGENT_CONNMGR "\\" MSGSRV_AGENT_CMLISTS, MSGSRV_A_BLOCKED_ADDRESS, e, config)) != NULL) { - ptr = strchr(Address, '-'); - if (ptr) { - *ptr = '\0'; - AddBlockedAddress(Address, ptr + 1); - *ptr = '-'; - } else { - AddBlockedAddress(Address, Address); - } - } - MDBFreeValues(config); - - while ((Address = MDBReadEx(MSGSRV_AGENT_CONNMGR "\\" MSGSRV_AGENT_CMLISTS, MSGSRV_A_ALLOWED_ADDRESS, e, config)) != NULL) { - ptr = strchr(Address, '-'); - if (ptr) { - *ptr = '\0'; - AddAllowedAddress(Address, ptr + 1); - *ptr = '-'; - } else { - AddAllowedAddress(Address, Address); - } - } - MDBFreeValues(config); - - MDBDestroyEnumStruct(e, config); - MDBDestroyValueStruct(config); - - if (List.blocked.count == 0 && List.allowed.count == 0) { -#if VERBOSE - XplConsolePrintf("cmlists: No addresses blocked or allowed\n"); -#endif - - ListsShutdown(); - return(FALSE); - } - - return(TRUE); -} - -/* - Below are "stock" functions that are basically infrastructure. - However, one might want to add initialization code to main - and takedown code to the signal handler -*/ -void -ListShutdownSigHandler(int Signal) -{ - int oldtgid = XplSetThreadGroupID(List.tgid); - - if (ListUnloadOk == FALSE) { - ListUnloadOk = TRUE; - - /* - Make sure the library lists are gone before beginning to - shutdown. - */ - while (XplSafeRead(List.threadCount) > 1) { - XplDelay(33); - } - - /* Do any required cleanup */ - LoggerClose(List.logHandle); - -#if defined(NETWARE) || defined(LIBC) - XplSignalLocalSemaphore(List.shutdownSemaphore); /* The signal will release main() */ - XplWaitOnLocalSemaphore(List.shutdownSemaphore); /* The wait will wait until main() is gone */ - - XplCloseLocalSemaphore(List.shutdownSemaphore); -#endif - } - - XplSetThreadGroupID(oldtgid); - - return; -} - -int -_NonAppCheckUnload(void) -{ - if (ListUnloadOk == FALSE) { - XplConsolePrintf("\rThis module will automatically be unloaded by the thread that loaded it.\n"); - XplConsolePrintf("\rIt does not allow manual unloading.\n"); - - return(1); - } - - return(0); -} - -int main(int argc, char *argv[]) -{ - /* init globals */ - List.tgid = XplGetThreadGroupID(); - - XplRenameThread(GetThreadID(), "Gate Keeper List Module"); - XplOpenLocalSemaphore(List.shutdownSemaphore, 0); - XplSignalHandler(ListShutdownSigHandler); - - /* - This will "park" the module 'til we get unloaded; - it would not be neccessary to do this on NetWare, - but to prevent from automatically exiting on Unix - we need to keep main around... - */ - XplWaitOnLocalSemaphore(List.shutdownSemaphore); - XplSignalLocalSemaphore(List.shutdownSemaphore); - - return(0); -} diff --git a/src/agents/connmgr/cmmodules/lists/cmlists.h b/src/agents/connmgr/cmmodules/lists/cmlists.h deleted file mode 100644 index 90f6a4c..0000000 --- a/src/agents/connmgr/cmmodules/lists/cmlists.h +++ /dev/null @@ -1,73 +0,0 @@ -/**************************************************************************** - * - * Copyright (c) 2001 Novell, Inc. All Rights Reserved. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public License - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, contact Novell, Inc. - * - * To contact Novell about this file by physical or electronic mail, you - * may find current contact information at www.novell.com. - * - ****************************************************************************/ - -#include -#include -#include - -#include - -#define PRODUCT_SHORT_NAME "cmlist.nlm" -#define PRODUCT_NAME "Bongo Connection Manager Block and Allow List Module" - -typedef struct _ListGlobal { - /* Handles */ - void *logHandle; - MDBHandle directoryHandle; - - /* Module State */ - time_t timeStamp; - int tgid; - BOOL unloadOK; - XplSemaphore shutdownSemaphore; - XplAtomic threadCount; - - struct { - long last; - - unsigned char datadir[XPL_MAX_PATH + 1]; - } config; - - struct { - long *start; - long *end; - unsigned long count; - unsigned long allocated; - } blocked; - - struct { - long *start; - long *end; - unsigned long count; - unsigned long allocated; - } allowed; -} ListGlobal; - -extern ListGlobal List; - -/* cmlist.c */ -void ListShutdownSigHandler(int Signal); -int _NonAppCheckUnload(void); - -EXPORT BOOL CMLISTSInit(CMModuleRegistrationStruct *registration, unsigned char *dataDirectory); -EXPORT BOOL ListsShutdown(void); -EXPORT int ListsVerify(ConnMgrCommand *command, ConnMgrResult *result); - diff --git a/src/agents/connmgr/cmmodules/rbl/cmrbl.c b/src/agents/connmgr/cmmodules/rbl/cmrbl.c deleted file mode 100644 index 2e642e9..0000000 --- a/src/agents/connmgr/cmmodules/rbl/cmrbl.c +++ /dev/null @@ -1,495 +0,0 @@ -/**************************************************************************** - * - * Copyright (c) 2001 Novell, Inc. All Rights Reserved. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public License - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, contact Novell, Inc. - * - * To contact Novell about this file by physical or electronic mail, you - * may find current contact information at www.novell.com. - * - ****************************************************************************/ - -#include -#include -#include -#include -#include - -#include - -#include "cmrbl.h" - -/* Globals */ -BOOL RBLUnloadOk = TRUE; -RBLGlobal RBL; - -static BOOL ReadConfiguration(void); - - -EXPORT int RBLVerify(ConnMgrCommand *command, ConnMgrResult *result) -{ - unsigned long i; - - if (XplStrCaseCmp(command->event, CM_EVENT_CONNECT) == 0) { - XplDnsRecord *dns = NULL; - BOOL blocked = FALSE; - int rc = -1; - int commentID = -1; - - /* Check for a cached value */ - XplWaitOnLocalSemaphore(RBL.sqlite.semaphore); - - sqlite3_bind_int(RBL.sqlite.stmt.get, 1, command->address); - - if ((rc = sqlite3_step(RBL.sqlite.stmt.get)) == SQLITE_ROW) { - blocked = sqlite3_column_int(RBL.sqlite.stmt.get, 0); - strncpy(result->comment, sqlite3_column_text(RBL.sqlite.stmt.get, 1), sizeof(result->comment)); - } - - sqlite3_reset(RBL.sqlite.stmt.get); - XplSignalLocalSemaphore(RBL.sqlite.semaphore); - - if (rc != SQLITE_ROW) { - /* Perform the RBL check */ - for (i = 0; i < RBL.rbl.count; i++) { - unsigned char buffer[MAXEMAILNAMESIZE]; - struct in_addr ip; - - ip.s_addr = command->address; - - /* address is in host byte order. RBL checks require least significant first. */ - snprintf(buffer, sizeof(buffer), "%d.%d.%d.%d.%s", - ip.s_net, - ip.s_host, - ip.s_lh, - ip.s_impno, - RBL.rbl.hosts[i]); - - rc = XplDnsResolve(buffer, &dns, XPL_RR_A); - if (dns) { - MemFree(dns); - } - - if (rc == XPL_DNS_SUCCESS) { - blocked = TRUE; - commentID = RBL.rbl.ids[i]; - strncpy(result->comment, RBL.rbl.comments[i], sizeof(result->comment)); - continue; - } - } - - /* Store new value */ - XplWaitOnLocalSemaphore(RBL.sqlite.semaphore); - - /* - Insert the new value into the table. The time for a negative result is a - full day. The time for a positive result is only 15 minutes however, - because a positive result simply means that the servers do not know anything - about the address. - */ - sqlite3_bind_int(RBL.sqlite.stmt.add, 1, command->address); - sqlite3_bind_text(RBL.sqlite.stmt.add, 2, blocked ? RBL.config.blockTimeout : RBL.config.allowTimeout, -1, SQLITE_TRANSIENT); - sqlite3_bind_int(RBL.sqlite.stmt.add, 3, blocked); - sqlite3_bind_int(RBL.sqlite.stmt.add, 4, commentID); - - sqlite3_step(RBL.sqlite.stmt.add); - - sqlite3_reset(RBL.sqlite.stmt.add); - XplSignalLocalSemaphore(RBL.sqlite.semaphore); - } - - if (blocked) { - /* He was blocked by RBL */ - return(CM_MODULE_DENY | CM_MODULE_PERMANENT | CM_MODULE_FORCE); - } else { - /* He was not blocked, don't force it though */ - return(CM_MODULE_ACCEPT); - } - } - - return(0); -} - -static void -TransactionController(void *ignored) -{ - XplWaitOnLocalSemaphore(RBL.sqlite.semaphore); - if (sqlite3_exec(RBL.sqlite.handle, SQL_BEGIN, NULL, NULL, NULL) != SQLITE_OK) { - XplConsolePrintf("cmrbl: Failed to start transaction controller\n"); - } - XplSignalLocalSemaphore(RBL.sqlite.semaphore); - - while (!RBLUnloadOk) { - unsigned long i; - - for (i = 0; i < 15 && !RBLUnloadOk; i++) { - XplDelay(1000); - } - - XplWaitOnLocalSemaphore(RBL.sqlite.semaphore); - if (sqlite3_exec(RBL.sqlite.handle, SQL_SAVE, NULL, NULL, NULL) != SQLITE_OK) { - XplConsolePrintf("cmrbl: Failed to save cache data\n"); - } - XplSignalLocalSemaphore(RBL.sqlite.semaphore); - } - - XplWaitOnLocalSemaphore(RBL.sqlite.semaphore); - if (sqlite3_exec(RBL.sqlite.handle, SQL_END, NULL, NULL, NULL) != SQLITE_OK) { - XplConsolePrintf("cmrbl: Failed to end transaction controller\n"); - } - XplSignalLocalSemaphore(RBL.sqlite.semaphore); -} - -EXPORT BOOL -CMRBLInit(CMModuleRegistrationStruct *registration, unsigned char *datadir) -{ - if (RBLUnloadOk == TRUE) { - XplSafeWrite(RBL.threadCount, 0); - - RBL.directoryHandle = (MDBHandle) MsgInit(); - if (RBL.directoryHandle) { - RBLUnloadOk = FALSE; - - RBL.logHandle = LoggerOpen("cmrbl"); - if (RBL.logHandle == NULL) { - XplConsolePrintf("cmrbl: Unable to initialize logging. Logging disabled.\r\n"); - } - - /* Fill out registration information */ - registration->priority = 1; /* It is important that the rbl are early */ - registration->Shutdown = RBLShutdown; - registration->Verify = RBLVerify; - registration->Notify = NULL; - - XplSafeIncrement(RBL.threadCount); - - strcpy(RBL.config.datadir, datadir); - - XplOpenLocalSemaphore(RBL.sqlite.semaphore, 1); - - if (ReadConfiguration()) { - unsigned char buffer[XPL_MAX_PATH + 1]; - int ccode; - XplThreadID id; - sqlite3_stmt *stmt; - sqlite3_stmt *stmt2; - unsigned long i; - - snprintf(buffer, sizeof(buffer), "%s/cache.db", datadir); - if (sqlite3_open(buffer, &RBL.sqlite.handle) != SQLITE_OK) { - printf("cmrbl: Failed to open database: %s\n", sqlite3_errmsg(RBL.sqlite.handle)); - } - - if (sqlite3_exec(RBL.sqlite.handle, SQL_CREATE, NULL, NULL, NULL) != SQLITE_OK) { -#if 0 - printf("bongogatekeeper: %s\n", sqlite3_errmsg(RBL.sqlite.handle)); -#endif - sqlite3_exec(RBL.sqlite.handle, SQL_ROLLBACK, NULL, NULL, NULL); - } - - if ((sqlite3_prepare(RBL.sqlite.handle, SQL_ADD, -1, &RBL.sqlite.stmt.add, 0) != SQLITE_OK) || - (sqlite3_prepare(RBL.sqlite.handle, SQL_GET, -1, &RBL.sqlite.stmt.get, 0) != SQLITE_OK) || - (sqlite3_prepare(RBL.sqlite.handle, SQL_CLEAN, -1, &RBL.sqlite.stmt.clean,0) != SQLITE_OK)) - { - printf("cmrbl: Failed to prepare sql: %s\n", sqlite3_errmsg(RBL.sqlite.handle)); - } - - /* Cleanup */ - sqlite3_exec(RBL.sqlite.handle, SQL_COMMENTS_CLEAN1, NULL, NULL, NULL); - - sqlite3_prepare(RBL.sqlite.handle, SQL_COMMENTS_CLEAN2, -1, &stmt, 0); - for (i = 0; i < RBL.rbl.count; i++) { - sqlite3_bind_text(stmt, 1, RBL.rbl.hosts[i], -1, SQLITE_TRANSIENT); - sqlite3_step(stmt); - sqlite3_reset(stmt); - } - sqlite3_finalize(stmt); - - sqlite3_exec(RBL.sqlite.handle, SQL_COMMENTS_CLEAN3, NULL, NULL, NULL); - - /* Ok, add any new ones */ - sqlite3_prepare(RBL.sqlite.handle, SQL_COMMENTS_ADD, -1, &stmt, 0); - sqlite3_prepare(RBL.sqlite.handle, SQL_COMMENTS_UPDATE, -1, &stmt2, 0); - for (i = 0; i < RBL.rbl.count; i++) { - sqlite3_bind_text(stmt, 1, RBL.rbl.hosts[i], -1, SQLITE_TRANSIENT); - sqlite3_bind_text(stmt, 2, RBL.rbl.comments[i], -1, SQLITE_TRANSIENT); - - if (sqlite3_step(stmt) != SQLITE_DONE) { - /* It is already there, so just update the comment in case it changed */ - sqlite3_bind_text(stmt2, 1, RBL.rbl.comments[i], -1, SQLITE_TRANSIENT); - sqlite3_bind_text(stmt2, 2, RBL.rbl.hosts[i], -1, SQLITE_TRANSIENT); - - sqlite3_step(stmt2); - sqlite3_reset(stmt2); - } - - sqlite3_reset(stmt); - } - sqlite3_finalize(stmt); - sqlite3_finalize(stmt2); - - /* Get the IDs for them */ - sqlite3_prepare(RBL.sqlite.handle, SQL_COMMENTS_GET_ID, -1, &stmt, 0); - for (i = 0; i < RBL.rbl.count; i++) { - sqlite3_bind_text(stmt, 1, RBL.rbl.hosts[i], -1, SQLITE_TRANSIENT); - if (sqlite3_step(stmt) == SQLITE_ROW) { - RBL.rbl.ids[i] = sqlite3_column_int(RBL.sqlite.stmt.get, 0); - } else { - RBL.rbl.ids[i] = -1; - } - sqlite3_reset(stmt); - } - sqlite3_finalize(stmt); - - /* Begin the transaction controller thread */ - XplBeginThread(&id, TransactionController, (1024 * 32), NULL, ccode); - - return(TRUE); - } - } else { - XplConsolePrintf("cmrbl: Failed to obtain directory handle\r\n"); - } - } - - return(FALSE); -} - -EXPORT BOOL -RBLShutdown(void) -{ - XplSafeDecrement(RBL.threadCount); - - if (RBLUnloadOk == FALSE) { - unsigned long i; - - RBLUnloadOk = TRUE; - - /* - Make sure the library rbl are gone before beginning to - shutdown. - */ - while (XplSafeRead(RBL.threadCount)) { - XplDelay(33); - } - - LoggerClose(RBL.logHandle); - - sqlite3_finalize(RBL.sqlite.stmt.add); - sqlite3_finalize(RBL.sqlite.stmt.get); - sqlite3_finalize(RBL.sqlite.stmt.clean); - - sqlite3_close(RBL.sqlite.handle); - XplCloseLocalSemaphore(RBL.sqlite.semaphore); - - for (i = 0; i < RBL.rbl.count; i++) { - MemFree(RBL.rbl.hosts[i]); - MemFree(RBL.rbl.comments[i]); - } - - if (RBL.rbl.hosts) { - MemFree(RBL.rbl.hosts); - } - - if (RBL.rbl.comments) { - MemFree(RBL.rbl.comments); - } - - if (RBL.rbl.ids) { - MemFree(RBL.rbl.ids); - } - -#if defined(NETWARE) || defined(LIBC) - XplSignalLocalSemaphore(RBL.shutdownSemaphore); /* The signal will release main() */ - XplWaitOnLocalSemaphore(RBL.shutdownSemaphore); /* The wait will wait until main() is gone */ - - XplCloseLocalSemaphore(RBL.shutdownSemaphore); -#endif - } - - return(FALSE); -} - -static BOOL -ReadConfiguration(void) -{ - MDBValueStruct *config; - - config = MDBCreateValueStruct(RBL.directoryHandle, MsgGetServerDN(NULL)); - - if (MDBRead(MSGSRV_AGENT_CONNMGR "\\" MSGSRV_AGENT_CMRBL, MSGSRV_A_DISABLED, config)) { - if (atol(config->Value[0]) == 1) { - MDBDestroyValueStruct(config); - RBLShutdown(); - return(FALSE); - } - } - - if (MDBRead(MSGSRV_AGENT_CONNMGR "\\" MSGSRV_AGENT_CMRBL, MSGSRV_A_CONFIG_CHANGED, config)) { - RBL.config.last = atol(config->Value[0]); - MDBFreeValues(config); - } else { - RBL.config.last = 0; - } - - if (MDBRead(MSGSRV_AGENT_CONNMGR "\\" MSGSRV_AGENT_CMRBL, MSGSRV_A_RBL_HOST, config) > 0) { - unsigned long i; - - for (i = 0; i < RBL.rbl.count; i++) { - MemFree(RBL.rbl.hosts[i]); - MemFree(RBL.rbl.comments[i]); - } - - if (RBL.rbl.hosts) { - MemFree(RBL.rbl.hosts); - } - - if (RBL.rbl.comments) { - MemFree(RBL.rbl.comments); - } - - if (RBL.rbl.ids) { - MemFree(RBL.rbl.ids); - } - - RBL.rbl.count = config->Used; - RBL.rbl.hosts = MemMalloc(config->Used * sizeof(char *)); - RBL.rbl.comments = MemMalloc(config->Used * sizeof(char *)); - RBL.rbl.ids = MemMalloc(config->Used * sizeof(long)); - - if (!RBL.rbl.hosts || !RBL.rbl.comments || !RBL.rbl.ids) { - LoggerEvent(RBL.logHandle, LOGGER_SUBSYSTEM_GENERAL, LOGGER_EVENT_OUT_OF_MEMORY, LOG_ERROR, 0, __FILE__, NULL, config->Used * sizeof(char *) * 2, __LINE__, NULL, 0); - } else { - for (i = 0; i < RBL.rbl.count; i++) { - unsigned char *ptr = strchr(config->Value[i], ';'); - - if (ptr) { - ptr[0] = '\0'; - } - - RBL.rbl.hosts[i] = MemStrdup(config->Value[i]); - if (ptr) { - RBL.rbl.comments[i] = MemStrdup(ptr + 1); - } else { - RBL.rbl.comments[i] = MemMalloc(sizeof(BLOCKED_STRING) + strlen(RBL.rbl.hosts[i])); - sprintf(RBL.rbl.comments[i], BLOCKED_STRING, RBL.rbl.hosts[i]); - } - - LoggerEvent(RBL.logHandle, LOGGER_SUBSYSTEM_CONFIGURATION, LOGGER_EVENT_CONFIGURATION_STRING, LOG_INFO, 0, "MSGSRV_A_RBL_HOST", config->Value[i], 0, 0, NULL, 0); - } - } - - MDBFreeValues(config); - } - - /* - Store the timeout strings. It is faster to do this once, instead of storing the long value - and creating the string each time, since it must be a string that is bound to the SQL statement. - */ - snprintf(RBL.config.blockTimeout, sizeof(RBL.config.blockTimeout), "%d minutes", (24 * 60)); /* Default to 1 day for a block */ - snprintf(RBL.config.allowTimeout, sizeof(RBL.config.blockTimeout), "%d minutes", 15); /* Default to 15 minutes for allow */ - - if (MDBRead(MSGSRV_AGENT_CONNMGR "\\" MSGSRV_AGENT_CMRBL, MSGSRV_A_CONFIGURATION, config) > 0) { - unsigned long i; - - for (i = 0; i < config->Used; i++) { - if (XplStrNCaseCmp(config->Value[i], BLOCK_TIMEOUT_PREFIX, sizeof(BLOCK_TIMEOUT_PREFIX) - 1) == 0) { - snprintf(RBL.config.blockTimeout, sizeof(RBL.config.blockTimeout), "%lu minutes", atol(config->Value[i] + sizeof(BLOCK_TIMEOUT_PREFIX) - 1)); - } else if (XplStrNCaseCmp(config->Value[i], ALLOW_TIMEOUT_PREFIX, sizeof(ALLOW_TIMEOUT_PREFIX) - 1) == 0) { - snprintf(RBL.config.allowTimeout, sizeof(RBL.config.allowTimeout), "%lu minutes", atol(config->Value[i] + sizeof(ALLOW_TIMEOUT_PREFIX) - 1)); - } - } - } - - MDBDestroyValueStruct(config); - - if (RBL.rbl.count == 0) { -#if VERBOSE - XplConsolePrintf("cmrbl: No RBL zones configured. RBL check is disabled.\n"); -#endif - RBLShutdown(); - return(FALSE); - } - - return(TRUE); -} - -/* - Below are "stock" functions that are basically infrastructure. - However, one might want to add initialization code to main - and takedown code to the signal handler -*/ -void -RBLShutdownSigHandler(int Signal) -{ - int oldtgid = XplSetThreadGroupID(RBL.tgid); - - if (RBLUnloadOk == FALSE) { - RBLUnloadOk = TRUE; - - /* - Make sure the library rbl are gone before beginning to - shutdown. - */ - while (XplSafeRead(RBL.threadCount) > 1) { - XplDelay(33); - } - - /* Do any required cleanup */ - LoggerClose(RBL.logHandle); - -#if defined(NETWARE) || defined(LIBC) - XplSignalLocalSemaphore(RBL.shutdownSemaphore); /* The signal will release main() */ - XplWaitOnLocalSemaphore(RBL.shutdownSemaphore); /* The wait will wait until main() is gone */ - - XplCloseLocalSemaphore(RBL.shutdownSemaphore); -#endif - } - - XplSetThreadGroupID(oldtgid); - - return; -} - -int -_NonAppCheckUnload(void) -{ - if (RBLUnloadOk == FALSE) { - XplConsolePrintf("\rThis module will automatically be unloaded by the thread that loaded it.\n"); - XplConsolePrintf("\rIt does not allow manual unloading.\n"); - - return(1); - } - - return(0); -} - -int main(int argc, char *argv[]) -{ - /* init globals */ - RBL.tgid = XplGetThreadGroupID(); - - XplRenameThread(GetThreadID(), "Gate Keeper RBL Module"); - XplOpenLocalSemaphore(RBL.shutdownSemaphore, 0); - XplSignalHandler(RBLShutdownSigHandler); - - /* - This will "park" the module 'til we get unloaded; - it would not be neccessary to do this on NetWare, - but to prevent from automatically exiting on Unix - we need to keep main around... - */ - XplWaitOnLocalSemaphore(RBL.shutdownSemaphore); - XplSignalLocalSemaphore(RBL.shutdownSemaphore); - - return(0); -} diff --git a/src/agents/connmgr/cmmodules/rbl/cmrbl.h b/src/agents/connmgr/cmmodules/rbl/cmrbl.h deleted file mode 100644 index 7df068f..0000000 --- a/src/agents/connmgr/cmmodules/rbl/cmrbl.h +++ /dev/null @@ -1,123 +0,0 @@ -/**************************************************************************** - * - * Copyright (c) 2001 Novell, Inc. All Rights Reserved. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public License - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, contact Novell, Inc. - * - * To contact Novell about this file by physical or electronic mail, you - * may find current contact information at www.novell.com. - * - ****************************************************************************/ - -#include -#include -#include - -#include - -#include - -#define PRODUCT_SHORT_NAME "cmrbl.nlm" -#define PRODUCT_NAME "Bongo Connection Manager RBL Module" - -#define BLOCKED_STRING "Blocked by RBL %s" - -typedef struct _RBLGlobal { - /* Handles */ - void *logHandle; - MDBHandle directoryHandle; - - /* Module State */ - time_t timeStamp; - int tgid; - BOOL unloadOK; - XplSemaphore shutdownSemaphore; - XplAtomic threadCount; - - struct { - long last; - - unsigned char datadir[XPL_MAX_PATH + 1]; - unsigned char blockTimeout[256]; - unsigned char allowTimeout[256]; - } config; - - struct { - unsigned char **hosts; - unsigned char **comments; - unsigned long *ids; - unsigned long count; - unsigned long allocated; - } rbl; - - struct { - sqlite3 *handle; - XplSemaphore semaphore; - - struct { - sqlite3_stmt *add; - sqlite3_stmt *get; - sqlite3_stmt *clean; - } stmt; - } sqlite; -} RBLGlobal; - -extern RBLGlobal RBL; - -/* cmrbl.c */ -void RBLShutdownSigHandler(int Signal); -int _NonAppCheckUnload(void); - -EXPORT BOOL CMRBLInit(CMModuleRegistrationStruct *registration, unsigned char *dataDirectory); -EXPORT BOOL RBLShutdown(void); -EXPORT int RBLVerify(ConnMgrCommand *command, ConnMgrResult *result); - -/* Config Prefixes */ -#define BLOCK_TIMEOUT_PREFIX "RBLBlockTimeout:" -#define ALLOW_TIMEOUT_PREFIX "RBLAllowTimeout:" - -/* SQL */ -#define SQL_CREATE "BEGIN TRANSACTION;" \ - "CREATE TABLE cache (" \ - "ip INTEGER PRIMARY KEY NOT NULL," \ - "timeout DATETIME," \ - "block BOOL," \ - "commentID INTEGER" \ - ");" \ - "CREATE TABLE comments (" \ - "key INTEGER PRIMARY KEY AUTOINCREMENT," \ - "zone TEXT UNIQUE," \ - "comment TEXT," \ - "keep BOOL default 1" \ - ");" \ - "CREATE INDEX timeout_idx ON cache (timeout);" \ - "CREATE INDEX comment_idx ON cache (commentID);"\ - "END TRANSACTION;" - -#define SQL_ROLLBACK "ROLLBACK;" - -#define SQL_ADD "INSERT OR REPLACE INTO cache (ip, timeout, block, commentID) VALUES (?, DATETIME('now', ?), ?, ?);" -#define SQL_GET "SELECT cache.block, comments.comment FROM cache INNER JOIN comments ON cache.commentID=comments.key WHERE ip=? AND julianday('now') < julianday(timeout);" -#define SQL_CLEAN "DELETE FROM cache WHERE julianday('now') >= julianday(timeout);" - -#define SQL_BEGIN "BEGIN TRANSACTION;" -#define SQL_END "END TRANSACTION;" -#define SQL_SAVE SQL_CLEAN SQL_END SQL_BEGIN - -#define SQL_COMMENTS_CLEAN1 "UPDATE comments SET keep=0;" -#define SQL_COMMENTS_CLEAN2 "UPDATE comments SET keep=1 WHERE zone=?;" -#define SQL_COMMENTS_CLEAN3 "DELETE FROM comments WHERE keep=0" -#define SQL_COMMENTS_ADD "INSERT INTO comments (zone, comment) VALUES (?, ?);" -#define SQL_COMMENTS_UPDATE "UPDATE comments SET comment=? WHERE zone=?;" -#define SQL_COMMENTS_GET_ID "SELECT key FROM comments WHERE zone=?;" - diff --git a/src/agents/connmgr/cmmodules/rdns/cmrdns.c b/src/agents/connmgr/cmmodules/rdns/cmrdns.c deleted file mode 100644 index dc756ba..0000000 --- a/src/agents/connmgr/cmmodules/rdns/cmrdns.c +++ /dev/null @@ -1,360 +0,0 @@ -/**************************************************************************** - * - * Copyright (c) 2001 Novell, Inc. All Rights Reserved. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public License - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, contact Novell, Inc. - * - * To contact Novell about this file by physical or electronic mail, you - * may find current contact information at www.novell.com. - * - ****************************************************************************/ - -#include -#include -#include -#include -#include - -#include - -#include "cmrdns.h" - -/* Globals */ -BOOL RDNSUnloadOk = TRUE; -RDNSGlobal RDNS; - -static BOOL ReadConfiguration(void); - - -EXPORT int RDNSVerify(ConnMgrCommand *command, ConnMgrResult *result) -{ - if (XplStrCaseCmp(command->event, CM_EVENT_CONNECT) == 0) { - XplDnsRecord *dns = NULL; - BOOL blocked = FALSE; - int rc = -1; - - /* Check for a cached value */ - XplWaitOnLocalSemaphore(RDNS.sqlite.semaphore); - - sqlite3_bind_int(RDNS.sqlite.stmt.get, 1, command->address); - - if ((rc = sqlite3_step(RDNS.sqlite.stmt.get)) == SQLITE_ROW) { - blocked = sqlite3_column_int(RDNS.sqlite.stmt.get, 0); - } - - sqlite3_reset(RDNS.sqlite.stmt.get); - XplSignalLocalSemaphore(RDNS.sqlite.semaphore); - - if (rc != SQLITE_ROW) { - unsigned char buffer[MAXEMAILNAMESIZE]; - struct in_addr ip; - - /* Perform the RDNS check */ - - ip.s_addr = command->address; - - /* ip is in host byte order. Reverse DNS requires most significant first. (unless providing the .in-addr.arpa extension) */ - snprintf(buffer, sizeof(buffer), "%d.%d.%d.%d", - ip.s_impno, - ip.s_lh, - ip.s_host, - ip.s_net); - - rc = XplDnsResolve(buffer, &dns, XPL_RR_PTR); - - if (dns) { - MemFree(dns); - } - - if (rc != XPL_DNS_SUCCESS) { - /* We don't like the guy */ - blocked = TRUE; - } - - /* Store new value */ - XplWaitOnLocalSemaphore(RDNS.sqlite.semaphore); - - /* - Insert the new value into the table. The time for a negative result is a - full day. The time for a positive result is only 15 minutes however, - because a positive result simply means that the servers do not know anything - about the address. - */ - sqlite3_bind_int(RDNS.sqlite.stmt.add, 1, command->address); - sqlite3_bind_text(RDNS.sqlite.stmt.add, 2, blocked ? RDNS.config.blockTimeout : RDNS.config.allowTimeout, -1, SQLITE_TRANSIENT); - sqlite3_bind_int(RDNS.sqlite.stmt.add, 3, blocked); - - sqlite3_step(RDNS.sqlite.stmt.add); - - sqlite3_reset(RDNS.sqlite.stmt.add); - XplSignalLocalSemaphore(RDNS.sqlite.semaphore); - } - - if (blocked) { - /* He was blocked by RDNS */ - strncpy(result->comment, CM_COMMENT, sizeof(result->comment)); - } - - result->detail.connect.requireAuth = blocked; - return(CM_MODULE_ACCEPT); - } - - return(0); -} - -static void -TransactionController(void *ignored) -{ - XplWaitOnLocalSemaphore(RDNS.sqlite.semaphore); - if (sqlite3_exec(RDNS.sqlite.handle, SQL_BEGIN, NULL, NULL, NULL) != SQLITE_OK) { - XplConsolePrintf("cmrdns: Failed to start transaction controller\n"); - } - XplSignalLocalSemaphore(RDNS.sqlite.semaphore); - - while (!RDNSUnloadOk) { - unsigned long i; - - for (i = 0; i < 15 && !RDNSUnloadOk; i++) { - XplDelay(1000); - } - - XplWaitOnLocalSemaphore(RDNS.sqlite.semaphore); - if (sqlite3_exec(RDNS.sqlite.handle, SQL_SAVE, NULL, NULL, NULL) != SQLITE_OK) { - XplConsolePrintf("cmrdns: Failed to save cache data\n"); - } - XplSignalLocalSemaphore(RDNS.sqlite.semaphore); - } - - XplWaitOnLocalSemaphore(RDNS.sqlite.semaphore); - if (sqlite3_exec(RDNS.sqlite.handle, SQL_END, NULL, NULL, NULL) != SQLITE_OK) { - XplConsolePrintf("cmrdns: Failed to end transaction controller\n"); - } - XplSignalLocalSemaphore(RDNS.sqlite.semaphore); -} - -EXPORT BOOL -CMRDNSInit(CMModuleRegistrationStruct *registration, unsigned char *datadir) -{ - if (RDNSUnloadOk == TRUE) { - XplSafeWrite(RDNS.threadCount, 0); - - RDNS.directoryHandle = (MDBHandle) MsgInit(); - if (RDNS.directoryHandle) { - RDNSUnloadOk = FALSE; - - RDNS.logHandle = LoggerOpen("cmrdns"); - if (RDNS.logHandle == NULL) { - XplConsolePrintf("cmrdns: Unable to initialize logging. Logging disabled.\r\n"); - } - - /* Fill out registration information */ - registration->priority = 1; /* It is important that the rdns are early */ - registration->Shutdown = RDNSShutdown; - registration->Verify = RDNSVerify; - registration->Notify = NULL; - - XplSafeIncrement(RDNS.threadCount); - - strcpy(RDNS.config.datadir, datadir); - - XplOpenLocalSemaphore(RDNS.sqlite.semaphore, 1); - - if (ReadConfiguration()) { - unsigned char buffer[XPL_MAX_PATH + 1]; - int ccode; - XplThreadID id; - - snprintf(buffer, sizeof(buffer), "%s/cache.db", datadir); - if (sqlite3_open(buffer, &RDNS.sqlite.handle) != SQLITE_OK) { - printf("cmrdns: Failed to open database: %s\n", sqlite3_errmsg(RDNS.sqlite.handle)); - } - - if (sqlite3_exec(RDNS.sqlite.handle, SQL_CREATE, NULL, NULL, NULL) != SQLITE_OK) { -#if 0 - printf("bongogatekeeper: %s\n", sqlite3_errmsg(RDNS.sqlite.handle)); -#endif - sqlite3_exec(RDNS.sqlite.handle, SQL_ROLLBACK, NULL, NULL, NULL); - } - - if ((sqlite3_prepare(RDNS.sqlite.handle, SQL_ADD, -1, &RDNS.sqlite.stmt.add, 0) != SQLITE_OK) || - (sqlite3_prepare(RDNS.sqlite.handle, SQL_GET, -1, &RDNS.sqlite.stmt.get, 0) != SQLITE_OK) || - (sqlite3_prepare(RDNS.sqlite.handle, SQL_CLEAN, -1, &RDNS.sqlite.stmt.clean,0) != SQLITE_OK)) - { - printf("cmrdns: Failed to prepare sql: %s\n", sqlite3_errmsg(RDNS.sqlite.handle)); - } - - /* Begin the transaction controller thread */ - XplBeginThread(&id, TransactionController, (1024 * 32), NULL, ccode); - - return(TRUE); - } - } else { - XplConsolePrintf("cmrdns: Failed to obtain directory handle\r\n"); - } - } - - return(FALSE); -} - -EXPORT BOOL -RDNSShutdown(void) -{ - XplSafeDecrement(RDNS.threadCount); - - if (RDNSUnloadOk == FALSE) { - RDNSUnloadOk = TRUE; - - /* - Make sure the library rdns are gone before beginning to - shutdown. - */ - while (XplSafeRead(RDNS.threadCount)) { - XplDelay(33); - } - - LoggerClose(RDNS.logHandle); - - sqlite3_finalize(RDNS.sqlite.stmt.add); - sqlite3_finalize(RDNS.sqlite.stmt.get); - sqlite3_finalize(RDNS.sqlite.stmt.clean); - - sqlite3_close(RDNS.sqlite.handle); - XplCloseLocalSemaphore(RDNS.sqlite.semaphore); - -#if defined(NETWARE) || defined(LIBC) - XplSignalLocalSemaphore(RDNS.shutdownSemaphore); /* The signal will release main() */ - XplWaitOnLocalSemaphore(RDNS.shutdownSemaphore); /* The wait will wait until main() is gone */ - - XplCloseLocalSemaphore(RDNS.shutdownSemaphore); -#endif - } - - return(FALSE); -} - -static BOOL -ReadConfiguration(void) -{ - MDBValueStruct *config; - - config = MDBCreateValueStruct(RDNS.directoryHandle, MsgGetServerDN(NULL)); - - if (MDBRead(MSGSRV_AGENT_CONNMGR "\\" MSGSRV_AGENT_CMRDNS, MSGSRV_A_DISABLED, config)) { - if (atol(config->Value[0]) == 1) { - MDBDestroyValueStruct(config); - RDNSShutdown(); - return(FALSE); - } - } - - if (MDBRead(MSGSRV_AGENT_CONNMGR "\\" MSGSRV_AGENT_CMRDNS, MSGSRV_A_CONFIG_CHANGED, config)) { - RDNS.config.last = atol(config->Value[0]); - MDBFreeValues(config); - } else { - RDNS.config.last = 0; - } - - /* - Store the timeout strings. It is faster to do this once, instead of storing the long value - and creating the string each time, since it must be a string that is bound to the SQL statement. - */ - snprintf(RDNS.config.blockTimeout, sizeof(RDNS.config.blockTimeout), "%d minutes", (3 * 60)); /* Default to 3 hours */ - snprintf(RDNS.config.allowTimeout, sizeof(RDNS.config.blockTimeout), "%d minutes", (3 * 60)); /* Default to 3 hours */ - - if (MDBRead(MSGSRV_AGENT_CONNMGR "\\" MSGSRV_AGENT_CMRDNS, MSGSRV_A_CONFIGURATION, config) > 0) { - unsigned long i; - - for (i = 0; i < config->Used; i++) { - if (XplStrNCaseCmp(config->Value[i], BLOCK_TIMEOUT_PREFIX, sizeof(BLOCK_TIMEOUT_PREFIX) - 1) == 0) { - snprintf(RDNS.config.blockTimeout, sizeof(RDNS.config.blockTimeout), "%lu minutes", atol(config->Value[i] + sizeof(BLOCK_TIMEOUT_PREFIX) - 1)); - } else if (XplStrNCaseCmp(config->Value[i], ALLOW_TIMEOUT_PREFIX, sizeof(ALLOW_TIMEOUT_PREFIX) - 1) == 0) { - snprintf(RDNS.config.allowTimeout, sizeof(RDNS.config.allowTimeout), "%lu minutes", atol(config->Value[i] + sizeof(ALLOW_TIMEOUT_PREFIX) - 1)); - } - } - } - - MDBDestroyValueStruct(config); - - return(TRUE); -} - -/* - Below are "stock" functions that are basically infrastructure. - However, one might want to add initialization code to main - and takedown code to the signal handler -*/ -void -RDNSShutdownSigHandler(int Signal) -{ - int oldtgid = XplSetThreadGroupID(RDNS.tgid); - - if (RDNSUnloadOk == FALSE) { - RDNSUnloadOk = TRUE; - - /* - Make sure the library rdns are gone before beginning to - shutdown. - */ - while (XplSafeRead(RDNS.threadCount) > 1) { - XplDelay(33); - } - - /* Do any required cleanup */ - LoggerClose(RDNS.logHandle); - -#if defined(NETWARE) || defined(LIBC) - XplSignalLocalSemaphore(RDNS.shutdownSemaphore); /* The signal will release main() */ - XplWaitOnLocalSemaphore(RDNS.shutdownSemaphore); /* The wait will wait until main() is gone */ - - XplCloseLocalSemaphore(RDNS.shutdownSemaphore); -#endif - } - - XplSetThreadGroupID(oldtgid); - - return; -} - -int -_NonAppCheckUnload(void) -{ - if (RDNSUnloadOk == FALSE) { - XplConsolePrintf("\rThis module will automatically be unloaded by the thread that loaded it.\n"); - XplConsolePrintf("\rIt does not allow manual unloading.\n"); - - return(1); - } - - return(0); -} - -int main(int argc, char *argv[]) -{ - /* init globals */ - RDNS.tgid = XplGetThreadGroupID(); - - XplRenameThread(GetThreadID(), "Gate Keeper RDNS Module"); - XplOpenLocalSemaphore(RDNS.shutdownSemaphore, 0); - XplSignalHandler(RDNSShutdownSigHandler); - - /* - This will "park" the module 'til we get unloaded; - it would not be neccessary to do this on NetWare, - but to prevent from automatically exiting on Unix - we need to keep main around... - */ - XplWaitOnLocalSemaphore(RDNS.shutdownSemaphore); - XplSignalLocalSemaphore(RDNS.shutdownSemaphore); - - return(0); -} diff --git a/src/agents/connmgr/cmmodules/rdns/cmrdns.h b/src/agents/connmgr/cmmodules/rdns/cmrdns.h deleted file mode 100644 index 88c0e25..0000000 --- a/src/agents/connmgr/cmmodules/rdns/cmrdns.h +++ /dev/null @@ -1,99 +0,0 @@ -/**************************************************************************** - * - * Copyright (c) 2001 Novell, Inc. All Rights Reserved. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public License - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, contact Novell, Inc. - * - * To contact Novell about this file by physical or electronic mail, you - * may find current contact information at www.novell.com. - * - ****************************************************************************/ - -#include -#include -#include - -#include - -#include - -#define PRODUCT_SHORT_NAME "cmrdns.nlm" -#define PRODUCT_NAME "Bongo Connection Manager Reverse DNS Module" - -#define CM_COMMENT "Your computer does not have a hostname, access blocked" - -typedef struct _RDNSGlobal { - /* Handles */ - void *logHandle; - MDBHandle directoryHandle; - - /* Module State */ - time_t timeStamp; - int tgid; - BOOL unloadOK; - XplSemaphore shutdownSemaphore; - XplAtomic threadCount; - - struct { - long last; - - unsigned char datadir[XPL_MAX_PATH + 1]; - unsigned char blockTimeout[256]; - unsigned char allowTimeout[256]; - } config; - - struct { - sqlite3 *handle; - XplSemaphore semaphore; - - struct { - sqlite3_stmt *add; - sqlite3_stmt *get; - sqlite3_stmt *clean; - } stmt; - } sqlite; -} RDNSGlobal; - -extern RDNSGlobal RDNS; - -/* cmrdns.c */ -void RDNSShutdownSigHandler(int Signal); -int _NonAppCheckUnload(void); - -EXPORT BOOL CMRDNSInit(CMModuleRegistrationStruct *registration, unsigned char *dataDirectory); -EXPORT BOOL RDNSShutdown(void); -EXPORT int RDNSVerify(ConnMgrCommand *command, ConnMgrResult *result); - -/* Config Prefixes */ -#define BLOCK_TIMEOUT_PREFIX "RDNSBlockTimeout:" -#define ALLOW_TIMEOUT_PREFIX "RDNSAllowTimeout:" - -/* SQL */ -#define SQL_CREATE "BEGIN TRANSACTION;" \ - "CREATE TABLE cache (" \ - "ip INTEGER PRIMARY KEY NOT NULL," \ - "timeout DATETIME," \ - "block BOOL" \ - ");" \ - "CREATE INDEX timeout_idx ON cache (timeout);" \ - "END TRANSACTION;" - -#define SQL_ROLLBACK "ROLLBACK;" - -#define SQL_ADD "INSERT OR REPLACE INTO cache (ip, timeout, block) VALUES (?, DATETIME('now', ?), ?);" -#define SQL_GET "SELECT block FROM cache WHERE ip=? AND julianday('now') < julianday(timeout);" -#define SQL_CLEAN "DELETE FROM cache WHERE julianday('now') >= julianday(timeout);" - -#define SQL_BEGIN "BEGIN TRANSACTION;" -#define SQL_END "END TRANSACTION;" -#define SQL_SAVE SQL_CLEAN SQL_END SQL_BEGIN diff --git a/src/agents/connmgr/cmmodules/user/cmuser.c b/src/agents/connmgr/cmmodules/user/cmuser.c deleted file mode 100644 index af37576..0000000 --- a/src/agents/connmgr/cmmodules/user/cmuser.c +++ /dev/null @@ -1,293 +0,0 @@ -/**************************************************************************** - * - * Copyright (c) 2001 Novell, Inc. All Rights Reserved. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public License - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, contact Novell, Inc. - * - * To contact Novell about this file by physical or electronic mail, you - * may find current contact information at www.novell.com. - * - ****************************************************************************/ - -#include -#include -#include -#include -#include - -#include "cmuser.h" - -/* Globals */ -BOOL UserUnloadOk = TRUE; -UserGlobal User; - -static BOOL ReadConfiguration(void); -static void Cleanup(void *param); - - -EXPORT BOOL UserNotify(ConnMgrCommand *command) -{ - /* - CM_EVENT_AUTHENTICATED - When receieved, create a file in datadir where the name is the ip address - and the conntent is the username. - */ - - if (XplStrCaseCmp(command->event, CM_EVENT_AUTHENTICATED) == 0) { - unsigned char buffer[XPL_MAX_PATH + 1]; - FILE *addr; - - snprintf(buffer, sizeof(buffer), "%s/%07lx", User.config.datadir, command->address); - addr = fopen(buffer, "w"); - if (addr) { - fwrite(command->detail.authenticated.user, sizeof(unsigned char), strlen(command->detail.authenticated.user), addr); - fclose(addr); - } - } - - return(TRUE); -} - -EXPORT int UserVerify(ConnMgrCommand *command, ConnMgrResult *result) -{ - /* - CM_EVENT_RELAY - When received, look for a file in datadir with the ip address as the - name, and read the user from the content of the file. Check the time - of the file to see if it has expired. - */ - if (XplStrCaseCmp(command->event, CM_EVENT_RELAY) == 0) { - unsigned char buffer[XPL_MAX_PATH + 1]; - struct stat sb; - - snprintf(buffer, sizeof(buffer), "%s/%07lx", User.config.datadir, command->address); - if (stat(buffer, &sb) != -1) { - if (sb.st_mtime > time(NULL) - (User.config.timeout * 60)) { - FILE *addr = fopen(buffer, "r"); - - if (addr) { - int l = fread(result->detail.user, sizeof(unsigned char), MAXEMAILNAMESIZE, addr); - result->detail.user[l] = '\0'; - - fclose(addr); - return(CM_MODULE_ACCEPT); - } - } else { - unlink(buffer); - } - } - return(CM_MODULE_DENY); - } - - return(0); -} - -EXPORT BOOL -CMUSERInit(CMModuleRegistrationStruct *registration, unsigned char *datadir) -{ - if (UserUnloadOk == TRUE) { - XplSafeWrite(User.threadCount, 0); - - User.directoryHandle = (MDBHandle) MsgInit(); - if (User.directoryHandle) { - UserUnloadOk = FALSE; - - User.logHandle = LoggerOpen("cmuser"); - if (User.logHandle == NULL) { - XplConsolePrintf("cmuser: Unable to initialize logging. Logging disabled.\r\n"); - } - - /* Fill out registration information */ - registration->priority = 5; - registration->Shutdown = UserShutdown; - registration->Verify = UserVerify; - registration->Notify = UserNotify; - - XplSafeIncrement(User.threadCount); - - strcpy(User.config.datadir, datadir); - - if (ReadConfiguration()) { - XplThreadID id; - int ccode; - - XplBeginThread(&id, Cleanup, (1024 * 32), NULL, ccode); - return(TRUE); - } - } else { - XplConsolePrintf("cmuser: Failed to obtain directory handle\r\n"); - } - } - - return(FALSE); -} - -EXPORT BOOL -UserShutdown(void) -{ - XplSafeDecrement(User.threadCount); - - if (UserUnloadOk == FALSE) { - UserUnloadOk = TRUE; - - /* - Make sure the library users are gone before beginning to - shutdown. - */ - while (XplSafeRead(User.threadCount)) { - XplDelay(33); - } - - LoggerClose(User.logHandle); - -#if defined(NETWARE) || defined(LIBC) - XplSignalLocalSemaphore(User.shutdownSemaphore); /* The signal will release main() */ - XplWaitOnLocalSemaphore(User.shutdownSemaphore); /* The wait will wait until main() is gone */ - - XplCloseLocalSemaphore(User.shutdownSemaphore); -#endif - } - - return(FALSE); -} - -static BOOL -ReadConfiguration(void) -{ - MDBValueStruct *config; - - config = MDBCreateValueStruct(User.directoryHandle, MsgGetServerDN(NULL)); - - if (MDBRead(MSGSRV_AGENT_CONNMGR "\\" MSGSRV_AGENT_CMUSER, MSGSRV_A_DISABLED, config)) { - if (atol(config->Value[0]) == 1) { - MDBDestroyValueStruct(config); - UserShutdown(); - return(FALSE); - } - } - - if (MDBRead(MSGSRV_AGENT_CONNMGR "\\" MSGSRV_AGENT_CMUSER, MSGSRV_A_CONFIG_CHANGED, config)) { - User.config.last = atol(config->Value[0]); - MDBFreeValues(config); - } else { - User.config.last = 0; - } - - if (MDBRead(MSGSRV_AGENT_CONNMGR "\\" MSGSRV_AGENT_CMUSER, MSGSRV_A_TIMEOUT, config)) { - User.config.timeout = atol(config->Value[0]); - } else { - User.config.timeout = 15; - } - - MDBDestroyValueStruct(config); - - return(TRUE); -} - -static void -Cleanup(void *param) -{ - while (!UserUnloadOk) { - int i; - XplDir *dir; - XplDir *dirent; - struct stat sb; - - if ((dir = XplOpenDir(User.config.datadir)) != NULL) { - while ((dirent = XplReadDir(dir)) != NULL) { - unsigned char buffer[XPL_MAX_PATH +1 ]; - - snprintf(buffer, sizeof(buffer), "%s/%s", User.config.datadir, dirent->d_nameDOS); - if ((stat(buffer, &sb) != -1) && (sb.st_mtime < time(NULL) - (User.config.timeout * 60))) { - unlink(buffer); - } - } - XplCloseDir(dir); - } - - for (i = 0; i < (User.config.timeout * 60) && !UserUnloadOk; i++) { - XplDelay(1000); - } - } -} - -/* - Below are "stock" functions that are basically infrastructure. - However, one might want to add initialization code to main - and takedown code to the signal handler -*/ -void -UserShutdownSigHandler(int Signal) -{ - int oldtgid = XplSetThreadGroupID(User.tgid); - - if (UserUnloadOk == FALSE) { - UserUnloadOk = TRUE; - - /* - Make sure the library users are gone before beginning to - shutdown. - */ - while (XplSafeRead(User.threadCount) > 1) { - XplDelay(33); - } - - /* Do any required cleanup */ - LoggerClose(User.logHandle); - -#if defined(NETWARE) || defined(LIBC) - XplSignalLocalSemaphore(User.shutdownSemaphore); /* The signal will release main() */ - XplWaitOnLocalSemaphore(User.shutdownSemaphore); /* The wait will wait until main() is gone */ - - XplCloseLocalSemaphore(User.shutdownSemaphore); -#endif - } - - XplSetThreadGroupID(oldtgid); - - return; -} - -int -_NonAppCheckUnload(void) -{ - if (UserUnloadOk == FALSE) { - XplConsolePrintf("\rThis module will automatically be unloaded by the thread that loaded it.\n"); - XplConsolePrintf("\rIt does not allow manual unloading.\n"); - - return(1); - } - - return(0); -} - -int main(int argc, char *argv[]) -{ - /* init globals */ - User.tgid = XplGetThreadGroupID(); - - XplRenameThread(GetThreadID(), "Gate Keeper User Module"); - XplOpenLocalSemaphore(User.shutdownSemaphore, 0); - XplSignalHandler(UserShutdownSigHandler); - - /* - This will "park" the module 'til we get unloaded; - it would not be neccessary to do this on NetWare, - but to prevent from automatically exiting on Unix - we need to keep main around... - */ - XplWaitOnLocalSemaphore(User.shutdownSemaphore); - XplSignalLocalSemaphore(User.shutdownSemaphore); - - return(0); -} diff --git a/src/agents/connmgr/cmmodules/user/cmuser.h b/src/agents/connmgr/cmmodules/user/cmuser.h deleted file mode 100644 index 01155ba..0000000 --- a/src/agents/connmgr/cmmodules/user/cmuser.h +++ /dev/null @@ -1,61 +0,0 @@ -/**************************************************************************** - * - * Copyright (c) 2001 Novell, Inc. All Rights Reserved. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public License - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, contact Novell, Inc. - * - * To contact Novell about this file by physical or electronic mail, you - * may find current contact information at www.novell.com. - * - ****************************************************************************/ - -#include -#include -#include - -#include - -#define PRODUCT_SHORT_NAME "cmuser.nlm" -#define PRODUCT_NAME "Bongo Connection Manager User Authentication Module" - -typedef struct _UserGlobal { - /* Handles */ - void *logHandle; - MDBHandle directoryHandle; - - /* Module State */ - time_t timeStamp; - int tgid; - BOOL unloadOK; - XplSemaphore shutdownSemaphore; - XplAtomic threadCount; - - struct { - long last; - - long timeout; - unsigned char datadir[XPL_MAX_PATH + 1]; - } config; -} UserGlobal; - -extern UserGlobal User; - -/* cmuser.c */ -void UserShutdownSigHandler(int Signal); -int _NonAppCheckUnload(void); - -EXPORT BOOL CMUSERInit(CMModuleRegistrationStruct *registration, unsigned char *dataDirectory); -EXPORT BOOL UserShutdown(void); -EXPORT BOOL UserNotify(ConnMgrCommand *command); -EXPORT int UserVerify(ConnMgrCommand *command, ConnMgrResult *result); - diff --git a/src/agents/connmgr/connmgr.c b/src/agents/connmgr/connmgr.c deleted file mode 100644 index ff27180..0000000 --- a/src/agents/connmgr/connmgr.c +++ /dev/null @@ -1,1286 +0,0 @@ -/**************************************************************************** - * - * Copyright (c) 2001 Novell, Inc. All Rights Reserved. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public License - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, contact Novell, Inc. - * - * To contact Novell about this file by physical or electronic mail, you - * may find current contact information at www.novell.com. - * - ****************************************************************************/ - -#include - -/* Product defines */ -#define PRODUCT_SHORT_NAME "connmgr.nlm" -#define PRODUCT_NAME "Bongo Connection Manager Agent" -#define PRODUCT_DESCRIPTION "Allows agents to keep and retrieve information about hosts that have talked to the system." -#define PRODUCT_VERSION "$Revision: 1.5 $" - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "connmgrp.h" - -#define GetConnMgrClientPoolEntry() MemPrivatePoolGetEntryDirect(ConnMgr.client.pool, __FILE__, __LINE__) - -static void SignalHandler(int sigtype); - -#define QUEUE_WORK_TO_DO(c, id, r) \ -{ \ - XplWaitOnLocalSemaphore(ConnMgr.client.semaphore); \ - if (XplSafeRead(ConnMgr.client.worker.idle)) { \ - (c)->queue.previous = NULL; \ - if (((c)->queue.next = ConnMgr.client.worker.head) != NULL) { \ - (c)->queue.next->queue.previous = (c); \ - } else { \ - ConnMgr.client.worker.tail = (c); \ - } \ - ConnMgr.client.worker.head = (c); \ - (r) = 0; \ - } else if (XplSafeRead(ConnMgr.client.worker.active) < XplSafeRead(ConnMgr.client.worker.maximum)) { \ - XplSafeIncrement(ConnMgr.client.worker.active); \ - XplSignalBlock(); \ - XplBeginThread(&(id), HandleConnection, CONNMGR_STACK_SPACE, XPL_INT_TO_PTR(XplSafeRead(ConnMgr.client.worker.active)), (r)); \ - XplSignalHandler(SignalHandler); \ - if (!(r)) { \ - (c)->queue.previous = NULL; \ - if (((c)->queue.next = ConnMgr.client.worker.head) != NULL) { \ - (c)->queue.next->queue.previous = (c); \ - } else { \ - ConnMgr.client.worker.tail = (c); \ - } \ - ConnMgr.client.worker.head = (c); \ - } else { \ - XplSafeDecrement(ConnMgr.client.worker.active); \ - (r) = CONNMGR_RECEIVER_OUT_OF_MEMORY; \ - } \ - } else { \ - (r) = CONNMGR_RECEIVER_CONNECTION_LIMIT; \ - } \ - XplSignalLocalSemaphore(ConnMgr.client.semaphore); \ -} - -enum ConnMgrStates { - CONNMGR_STARTING = 0, - CONNMGR_INITIALIZING, - CONNMGR_LOADING, - CONNMGR_RUNNING, - CONNMGR_RELOADING, - CONNMGR_UNLOADING, - CONNMGR_STOPPING, - CONNMGR_DONE, - - CONNMGR_MAX_STATES -}; - -enum ConnMgrReceiverStates { - CONNMGR_RECEIVER_SHUTTING_DOWN = 1, - CONNMGR_RECEIVER_DISABLED, - CONNMGR_RECEIVER_CONNECTION_LIMIT, - CONNMGR_RECEIVER_OUT_OF_MEMORY, - - CONNMGR_RECEIVER_MAX_STATES -}; - -enum ConnMgrClientStates { - CONNMGR_CLIENT_FRESH = 0, - CONNMGR_CLIENT_AUTHORIZED, - CONNMGR_CLIENT_ENDING, - - CONNMGR_CLIENT_MAX_STATES -}; - -typedef struct _ConnMgrClient { - enum ConnMgrClientStates state; - Connection *conn; - - ConnMgrCommand *command; - ConnMgrResult reply; -} ConnMgrClient; - -struct { - enum ConnMgrStates state; - BOOL stopped; - - struct { - XplThreadID main; - XplThreadID group; - } id; - - struct { - XplSemaphore main; - XplSemaphore shutdown; - } sem; - - struct { - Connection *conn; - XplAtomic active; - struct sockaddr_in addr; - unsigned char hash[CM_HASH_SIZE]; - unsigned char host[MAXEMAILNAMESIZE + 1]; - } server; - - struct { - XplSemaphore semaphore; - - struct { - XplSemaphore todo; - - XplAtomic maximum; - XplAtomic active; - XplAtomic idle; - - Connection *head; - Connection *tail; - } worker; - - void *pool; - - time_t sleepTime; - } client; - - struct { - struct { - XplAtomic serviced; - } clients; - - XplAtomic badPasswords; - } stats; - - struct { - XplRWLock lock; - - unsigned long *addresses; - unsigned char **handles; - unsigned char **salts; - unsigned long used; - unsigned long allocated; - } authHandles; - - MDBHandle directoryHandle; - void *loggingHandle; - - ModuleStruct *modules; - unsigned char moduleDir[XPL_MAX_PATH + 1]; -} ConnMgr; - -static BOOL HandleConnection(void *param); - -static BOOL ReadConnMgrVariable(unsigned int Variable, unsigned char *Data, size_t *DataLength); -static BOOL WriteConnMgrVariable(unsigned int Variable, unsigned char *Data, size_t DataLength); - -static BOOL ConnMgrShutdown(unsigned char *Arguments, unsigned char **Response, BOOL *CloseConnection); -static BOOL ConnMgrDMCCommandHelp(unsigned char *Arguments, unsigned char **Response, BOOL *CloseConnection); -static BOOL SendConnMgrStatistics(unsigned char *Arguments, unsigned char **Response, BOOL *CloseConnection); - -ManagementVariables ConnMgrManagementVariables[] = { - /* 0 PRODUCT_VERSION */ { DMCMV_REVISIONS, DMCMV_REVISIONS_HELP, ReadConnMgrVariable, NULL }, - /* 1 ConnMgr.client.worker.maximum */ { DMCMV_MAX_CONNECTION_COUNT, DMCMV_MAX_CONNECTION_COUNT_HELP, ReadConnMgrVariable, WriteConnMgrVariable }, - /* 2 ConnMgr.server.active */ { DMCMV_SERVER_THREAD_COUNT, DMCMV_SERVER_THREAD_COUNT_HELP, ReadConnMgrVariable, NULL }, - /* 3 ConnMgr.client.worker.active */ { DMCMV_CONNECTION_COUNT, DMCMV_CONNECTION_COUNT_HELP, ReadConnMgrVariable, NULL }, - /* 4 ConnMgr.client.worker.idle */ { DMCMV_IDLE_CONNECTION_COUNT, DMCMV_IDLE_CONNECTION_COUNT_HELP, ReadConnMgrVariable, NULL }, - /* 5 ConnMgr.stopped */ { DMCMV_RECEIVER_DISABLED, DMCMV_RECEIVER_DISABLED_HELP, ReadConnMgrVariable, WriteConnMgrVariable }, - /* 6 ConnMgr.stats.clients.serviced */ { DMCMV_TOTAL_CONNECTIONS, DMCMV_TOTAL_CONNECTIONS_HELP, ReadConnMgrVariable, WriteConnMgrVariable }, - /* 7 ConnMgr.stats.badPasswords */ { DMCMV_BAD_PASSWORD_COUNT, DMCMV_BAD_PASSWORD_COUNT_HELP, ReadConnMgrVariable, WriteConnMgrVariable }, - /* 8 */ { DMCMV_VERSION, DMCMV_VERSION_HELP, ReadConnMgrVariable, NULL }, -}; - -ManagementCommands ConnMgrManagementCommands[] = { - /* 0 HELP[ ] */ { DMCMC_HELP, ConnMgrDMCCommandHelp }, - /* 1 SHUTDOWN */ { DMCMC_SHUTDOWN, ConnMgrShutdown }, - /* 2 STATS */ { DMCMC_STATS, SendConnMgrStatistics }, - /* 3 MEMORY */ { DMCMC_DUMP_MEMORY_USAGE, ManagementMemoryStats }, - /* 4 CONNTRACEFLAGS */ { DMCMC_CONN_TRACE_USAGE, ManagementConnTrace }, -}; - - -static BOOL -ConnMgrClientAllocCB(void *buffer, void *clientData) -{ - ConnMgrClient *c = (ConnMgrClient *)buffer; - - memset(c, 0, sizeof(ConnMgrClient)); - - c->state = CONNMGR_CLIENT_FRESH; - return(TRUE); -} - -static void -ConnMgrReturnClientPoolEntry(ConnMgrClient *client) -{ - register ConnMgrClient *c = client; - - memset(c, 0, sizeof(ConnMgrClient)); - - c->state = CONNMGR_CLIENT_FRESH; - - MemPrivatePoolReturnEntry(ConnMgr.client.pool, c); - - return; -} - -static BOOL -HandleConnection(void *param) -{ - long threadNumber = (long)param; - time_t last = time(NULL); - time_t current; - ConnMgrClient *client; - - client = GetConnMgrClientPoolEntry(); - if (!client) { - XplSafeDecrement(ConnMgr.client.worker.active); - - return(FALSE); - } - - do { - XplRenameThread(XplGetThreadID(), "Connection Manager Worker"); - - XplSafeIncrement(ConnMgr.client.worker.idle); - XplWaitOnLocalSemaphore(ConnMgr.client.worker.todo); - XplSafeDecrement(ConnMgr.client.worker.idle); - - current = time(NULL); - - XplWaitOnLocalSemaphore(ConnMgr.client.semaphore); - - client->conn = ConnMgr.client.worker.tail; - if (client->conn) { - ConnMgr.client.worker.tail = client->conn->queue.previous; - if (ConnMgr.client.worker.tail) { - ConnMgr.client.worker.tail->queue.next = NULL; - } else { - ConnMgr.client.worker.head = NULL; - } - } - - XplSignalLocalSemaphore(ConnMgr.client.semaphore); - - if (client->conn) { - /* - Pull the request out of client->conn.receive.buffer. (See large comment in ConnMgrServer) - client->conn.receive.buffer has been abused to deliver the request to the client. - */ - client->command = (ConnMgrCommand *)client->conn->receive.buffer; - LoggerEvent(ConnMgr.loggingHandle, LOGGER_SUBSYSTEM_AUTH, LOGGER_EVENT_CONNECTION, LOG_INFO, 0, NULL, NULL, XplHostToLittle(client->conn->socketAddress.sin_addr.s_addr), 0, NULL, 0); - } - -#if 0 - XplConsolePrintf("[%d.%d.%d.%d] Got command: %lu\r\n", - client->conn->socketAddress.sin_addr.s_net, - client->conn->socketAddress.sin_addr.s_host, - client->conn->socketAddress.sin_addr.s_lh, - client->conn->socketAddress.sin_addr.s_impno, - client->command.request); -#endif - - if (client->command) { - unsigned long i; - BOOL allowed = FALSE; - BOOL found = FALSE; - unsigned char salt[256 + 1]; - - salt[0] = '\0'; - client->command->pass[32] = '\0'; - /* - Check the pass string provided in command. If it is not correct for the given - address, then generate a salt and send it. The client can then repeat the - command with a valid pass. - */ - XplRWReadLockAcquire(&ConnMgr.authHandles.lock); - for (i = 0; i < ConnMgr.authHandles.used; i++) { - - if (ConnMgr.authHandles.addresses[i] == client->conn->socketAddress.sin_addr.s_addr) { - found = TRUE; - if (XplStrCaseCmp(client->command->pass, ConnMgr.authHandles.handles[i]) == 0) { - allowed = TRUE; - } else { - strcpy(salt, ConnMgr.authHandles.salts[i]); - } - } - } - - if (!found) { - xpl_hash_context ctx; - unsigned char handle[XPLHASH_MD5_LENGTH]; - - XplRWReadLockRelease(&ConnMgr.authHandles.lock); - - snprintf(salt, sizeof(salt), "%x%s%x", XplGetThreadID(), ConnMgr.server.host, (unsigned int)time(NULL)); - salt[sizeof(salt) - 1] = 0; - - XplHashNew(&ctx, XPLHASH_MD5); - XplHashWrite(&ctx, salt, strlen(salt)); - XplHashWrite(&ctx, ConnMgr.server.hash, CM_HASH_SIZE); - XplHashFinal(&ctx, XPLHASH_LOWERCASE, handle, XPLHASH_MD5_LENGTH); - - XplRWWriteLockAcquire(&ConnMgr.authHandles.lock); - /* Generate the salt and the pass */ - if (ConnMgr.authHandles.used + 1 > ConnMgr.authHandles.allocated) { - ConnMgr.authHandles.allocated += 5; - - ConnMgr.authHandles.addresses = MemRealloc(ConnMgr.authHandles.addresses, sizeof(unsigned long) * ConnMgr.authHandles.allocated); - ConnMgr.authHandles.handles = MemRealloc(ConnMgr.authHandles.handles, sizeof(unsigned char *) * ConnMgr.authHandles.allocated); - ConnMgr.authHandles.salts = MemRealloc(ConnMgr.authHandles.salts, sizeof(unsigned char *) * ConnMgr.authHandles.allocated); - } - - ConnMgr.authHandles.addresses[ConnMgr.authHandles.used] = client->conn->socketAddress.sin_addr.s_addr; - ConnMgr.authHandles.handles[ConnMgr.authHandles.used] = MemStrdup(handle); - ConnMgr.authHandles.salts[ConnMgr.authHandles.used] = MemStrdup(salt); - ConnMgr.authHandles.used++; - - XplRWWriteLockRelease(&ConnMgr.authHandles.lock); - } - - XplRWReadLockRelease(&ConnMgr.authHandles.lock); - - if (allowed) { - /* - If command->address == 0, then resolve the host in command->host and place the - resulting value in command->addres. To keep the command size down host and user - are in a union. This means you can not provide a host when doing a user related - command. - */ - client->command->address = ntohl(client->command->address); - - switch (client->command->command) { - case CM_COMMAND_VERIFY: { - ModulesVerify(ConnMgr.modules, client->command, &client->reply); - break; - } - - case CM_COMMAND_NOTIFY: { - ModulesNotify(ConnMgr.modules, client->command); - client->reply.result = CM_RESULT_OK; - break; - } - - default: { - LoggerEvent(ConnMgr.loggingHandle, LOGGER_SUBSYSTEM_UNHANDLED, LOGGER_EVENT_UNHANDLED_REQUEST, LOG_INFO, 0, NULL, NULL, XplHostToLittle(client->conn->socketAddress.sin_addr.s_addr), 0, NULL, 0); - client->reply.result = CM_RESULT_UNKNOWN_COMMAND; - break; - } - } - - sendto(ConnMgr.server.conn->socket, (unsigned char *)&client->reply, sizeof(ConnMgrResult), 0, (struct sockaddr *)&client->conn->socketAddress, sizeof(client->conn->socketAddress)); - } else { - /* send a result with the salt */ - client->reply.result = CM_RESULT_MUST_AUTH; - strcpy(client->reply.detail.salt, salt); - sendto(ConnMgr.server.conn->socket, (unsigned char *)&client->reply, sizeof(ConnMgrResult), 0, (struct sockaddr *)&client->conn->socketAddress, sizeof(client->conn->socketAddress)); - } - } - - if (client->conn) { - ConnClose(client->conn, 0); - ConnFree(client->conn); - } - - /* Live or die? */ - if (threadNumber == XplSafeRead(ConnMgr.client.worker.active)) { - if ((current - last) > ConnMgr.client.sleepTime) { - break; - } - } - - last = time(NULL); - - memset(client, 0, sizeof(ConnMgrClient)); - - client->state = CONNMGR_CLIENT_FRESH; - } while (ConnMgr.state == CONNMGR_RUNNING); - - ConnMgrReturnClientPoolEntry(client); - - XplSafeDecrement(ConnMgr.client.worker.active); - - return(TRUE); -} - -static int -ServerSocketInit(void) -{ - ConnMgr.server.conn = ConnAlloc(FALSE); - if (ConnMgr.server.conn) { - ConnMgr.server.conn->socketAddress.sin_family = AF_INET; - ConnMgr.server.conn->socketAddress.sin_port = htons(CM_PORT); - ConnMgr.server.conn->socketAddress.sin_addr.s_addr = MsgGetAgentBindIPAddress(); - - /* Get root privs back for the bind. It's ok if this fails - - * the user might not need to be root to bind to the port */ - XplSetEffectiveUserId(0); - - /* Get our socket, and bind. This is normally done with ConnServerSocket() but that is TCP only */ - ConnMgr.server.conn->socket = IPsocket(PF_INET, SOCK_DGRAM, IPPROTO_UDP); - if (ConnMgr.server.conn->socket != -1) { - int ccode; - - setsockopt(ConnMgr.server.conn->socket, SOL_SOCKET, SO_REUSEADDR, (unsigned char *)&ccode, sizeof(ccode)); - ccode = IPbind(ConnMgr.server.conn->socket, (struct sockaddr *)&ConnMgr.server.conn->socketAddress, sizeof(ConnMgr.server.conn->socketAddress)); - if (ccode == -1) { - IPclose(ConnMgr.server.conn->socket); - ConnMgr.server.conn->socket = -1; - } - } - - if (XplSetEffectiveUser(MsgGetUnprivilegedUser()) < 0) { - XplConsolePrintf("bongoconnmgr: Could not drop to unprivileged user '%s'\n", MsgGetUnprivilegedUser()); - return(-1); - } - - if (ConnMgr.server.conn->socket == -1) { - int ret = ConnMgr.server.conn->socket; - XplConsolePrintf("bongoconnmgr: Could not bind to port %d\n", CM_PORT); - ConnFree(ConnMgr.server.conn); - return(ret); - } - } else { - XplConsolePrintf("bongoconnmgr: Could not allocate connection.\n"); - return(-1); - } - - return(0); -} - -static void -ConnMgrServer(void *ignored) -{ - XplThreadID id; - int ccode; - Connection *conn; - unsigned long i; - - XplSafeIncrement(ConnMgr.server.active); - XplRenameThread(XplGetThreadID(), "Connection Manager Server"); - ConnMgr.state = CONNMGR_RUNNING; - - while (ConnMgr.state < CONNMGR_STOPPING) { - ConnMgrCommand command; - long rc = -1; - - /* Must call connAlloc() with FALSE because we do not need the buffers for UDP */ - conn = ConnAlloc(FALSE); - if (conn) { - int size = 0; - ConnMgrResult result; - - while ((ConnMgr.state < CONNMGR_STOPPING) && ((rc == -1) || (rc == EOF) || (size == 0))) { - size = sizeof(conn->socketAddress); - rc = recvfrom(ConnMgr.server.conn->socket, (unsigned char *)&command, sizeof(ConnMgrCommand), 0, (struct sockaddr *)&conn->socketAddress, &size); - } - - - if ((ConnMgr.state < CONNMGR_STOPPING) && !ConnMgr.stopped) { - conn->ssl.enable = FALSE; - - /* - Abuse conn.receive.buffer. This is a pointer in the Connection structure - that is not being used in this case, because we are calling ConnAlloc() - with FALSE. Since in UDP we don't have accept, we are just calling recvfrom - and the result will contain the entire request. We MUST get this request - to the client thread. The only easy way to do that without changing ConnIO - is to put it into the Connection structure somewhere. - */ - conn->receive.buffer = (unsigned char *) MemMalloc(sizeof(ConnMgrCommand)); - memcpy(conn->receive.buffer, &command, sizeof(ConnMgrCommand)); - - QUEUE_WORK_TO_DO(conn, id, ccode); - if (!ccode) { - XplSignalLocalSemaphore(ConnMgr.client.worker.todo); - - continue; - } - } else if (ConnMgr.stopped) { - ccode = CONNMGR_RECEIVER_DISABLED; - } else { - ccode = CONNMGR_RECEIVER_SHUTTING_DOWN; - } - - memset(&result, 0, sizeof(ConnMgrResult)); - switch(ccode) { - case CONNMGR_RECEIVER_SHUTTING_DOWN: { - result.result = CM_RESULT_SHUTTING_DOWN; - break; - } - - case CONNMGR_RECEIVER_DISABLED: { - result.result = CM_RESULT_RECEIVER_DISABLED; - break; - } - - case CONNMGR_RECEIVER_CONNECTION_LIMIT: { - result.result = CM_RESULT_CONNECTION_LIMIT; - break; - } - - case CONNMGR_RECEIVER_OUT_OF_MEMORY: { - result.result = CM_RESULT_NO_MEMORY; - break; - } - - default: { - break; - } - } - - if (result.result >= CM_RESULT_FIRST_ERROR) { - sendto(ConnMgr.server.conn->socket, (unsigned char *)&result, sizeof(ConnMgrResult), 0, (struct sockaddr *)&conn->socketAddress, sizeof(conn->socketAddress)); - } - - /* fixme - we need connection management flags for ConnClose to force the shutdown */ - ConnClose(conn, 1); - - ConnFree(conn); - conn = NULL; - - continue; - } - - switch (errno) { - case ECONNABORTED: -#ifdef EPROTO - case EPROTO: -#endif - case EINTR: { - if (ConnMgr.state < CONNMGR_STOPPING) { - LoggerEvent(ConnMgr.loggingHandle, LOGGER_SUBSYSTEM_GENERAL, LOGGER_EVENT_ACCEPT_FAILURE, LOG_ERROR, 0, "Server", NULL, errno, 0, NULL, 0); - } - - continue; - } - - default: { - if (ConnMgr.state < CONNMGR_STOPPING) { -#if VERBOSE - XplConsolePrintf("bongoconnmgr: Exiting after an recvfrom() failure; error %d\n", errno); -#endif - - LoggerEvent(ConnMgr.loggingHandle, LOGGER_SUBSYSTEM_GENERAL, LOGGER_EVENT_ACCEPT_FAILURE, LOG_ERROR, 0, "Server", NULL, errno, 0, NULL, 0); - } - - ConnMgr.state = CONNMGR_STOPPING; - - break; - } - } - - break; - } - - /* Shutting down */ -#if VERBOSE - XplConsolePrintf("bongoconnmgr: Shutting down.\r\n"); -#endif - ConnMgr.state = CONNMGR_STOPPING; - - id = XplSetThreadGroupID(ConnMgr.id.group); - - if (ConnMgr.server.conn) { - /* fixme - we need connection management flags for ConnClose to force the shutdown */ - ConnClose(ConnMgr.server.conn, 1); - ConnMgr.server.conn = NULL; - } - - /* fixme - we need connection management flags for ConnClose to force the shutdown */ - ConnCloseAll(1); - - /* Management Client Shutdown */ - if (ManagementState() != MANAGEMENT_STOPPED) { - ManagementShutdown(); - - for (ccode = 0; (ManagementState() != MANAGEMENT_STOPPED) && (ccode < 60); ccode++) { - XplDelay(1000); - } - } - - XplWaitOnLocalSemaphore(ConnMgr.client.semaphore); - - ccode = XplSafeRead(ConnMgr.client.worker.idle); - while (ccode--) { - XplSignalLocalSemaphore(ConnMgr.client.worker.todo); - } - - XplSignalLocalSemaphore(ConnMgr.client.semaphore); - - for (ccode = 0; (XplSafeRead(ConnMgr.server.active) > 1) && (ccode < 60); ccode++) { - XplDelay(1000); - } - - if (XplSafeRead(ConnMgr.server.active) > 1) { - XplConsolePrintf("bongoconnmgr: %d server threads outstanding; attempting forceful unload.\r\n", XplSafeRead(ConnMgr.server.active) - 1); - } - -#if VERBOSE - XplConsolePrintf("\rbongoconnmgr: Shutting down %d client threads\r\n", XplSafeRead(ConnMgr.client.worker.active)); -#endif - - /* Make sure the kids have flown the coop. */ - for (ccode = 0; XplSafeRead(ConnMgr.client.worker.active) && (ccode < 60); ccode++) { - XplDelay(1000); - } - - if (XplSafeRead(ConnMgr.client.worker.active)) { - XplConsolePrintf("\rbongoconnmgr: %d threads outstanding; attempting forceful unload.\r\n", XplSafeRead(ConnMgr.client.worker.active)); - } - - XPLCryptoLockDestroy(); - - CONN_TRACE_SHUTDOWN(); - ConnShutdown(); - - /* Close down the modules */ - if (ConnMgr.modules) { - UnloadModules(ConnMgr.modules); - } - - LoggerClose(ConnMgr.loggingHandle); - ConnMgr.loggingHandle = NULL; - - MsgShutdown(); -/* MDBShutdown(); */ - - MemPrivatePoolFree(ConnMgr.client.pool); - MemoryManagerClose(MSGSRV_AGENT_CONNMGR); - - XplSignalLocalSemaphore(ConnMgr.sem.main); - XplWaitOnLocalSemaphore(ConnMgr.sem.shutdown); - - XplCloseLocalSemaphore(ConnMgr.sem.shutdown); - XplCloseLocalSemaphore(ConnMgr.sem.main); - - XplRWLockDestroy(&ConnMgr.authHandles.lock); - - for (i = 0; i < ConnMgr.authHandles.used; i++) { - MemFree(ConnMgr.authHandles.handles[i]); - } - MemFree(ConnMgr.authHandles.handles); - MemFree(ConnMgr.authHandles.addresses); - -#if VERBOSE - XplConsolePrintf("\rbongoconnmgr: Shutdown complete\r\n"); -#endif - XplSetThreadGroupID(id); - - return; -} - -static BOOL -ReadConfiguration(void) -{ - unsigned long i; - MDBValueStruct *config; - - config = MDBCreateValueStruct(ConnMgr.directoryHandle, NULL); - - if (config && MDBRead(MSGSRV_ROOT, MSGSRV_A_ACL, config)) { - gethostname(ConnMgr.server.host, sizeof(ConnMgr.server.host)); - HashCredential(MsgGetServerDN(NULL), config->Value[0], ConnMgr.server.hash); - - MDBFreeValues(config); - } else { - return(FALSE); - } - - MDBSetValueStructContext(MsgGetServerDN(NULL), config); - if (MDBRead(MSGSRV_AGENT_CONNMGR, MSGSRV_A_CONFIGURATION, config)) { - for (i = 0; i < config->Used; i++) { - if (XplStrNCaseCmp(config->Value[i], "MaxLoad:", 8)==0) { - XplSafeWrite(ConnMgr.client.worker.maximum, atol(config->Value[i] + 8)); - } - } - - MDBFreeValues(config); - } - - MsgGetLibDir(ConnMgr.moduleDir); - strcat(ConnMgr.moduleDir, "/connmgr"); - MsgMakePath(ConnMgr.moduleDir); - - MDBDestroyValueStruct(config); - - return(TRUE); -} - -#if defined(NETWARE) || defined(LIBC) || defined(WIN32) -int -_NonAppCheckUnload(void) -{ - int s; - static BOOL checked = FALSE; - XplThreadID id; - - if (!checked) { - checked = ConnMgr.state = CONNMGR_UNLOADING; - - XplWaitOnLocalSemaphore(ConnMgr.sem.shutdown); - - id = XplSetThreadGroupID(ConnMgr.id.group); - if (ConnMgr.server.conn->socket != -1) { - s = ConnMgr.server.conn->socket; - ConnMgr.server.conn->socket = -1; - - IPclose(s); - } - XplSetThreadGroupID(id); - - XplWaitOnLocalSemaphore(ConnMgr.sem.main); - } - - return(0); -} -#endif - -static void -SignalHandler(int sigtype) -{ - switch(sigtype) { - case SIGHUP: { - if (ConnMgr.state < CONNMGR_UNLOADING) { - ConnMgr.state = CONNMGR_UNLOADING; - } - - break; - } - case SIGINT : - case SIGTERM: { - if (ConnMgr.state == CONNMGR_STOPPING) { - XplUnloadApp(getpid()); - } else if (ConnMgr.state < CONNMGR_STOPPING) { - ConnMgr.state = CONNMGR_STOPPING; - } - - break; - } - - default: { - break; - } - } - - return; -} - -static BOOL -ConnMgrShutdown(unsigned char *arguments, unsigned char **response, BOOL *closeConnection) -{ - XplThreadID id; - - if (response) { - if (!arguments) { - if (ConnMgr.server.conn && (ConnMgr.server.conn->socket != -1)) { - *response = MemStrdup("Shutting down.\r\n"); - if (*response) { - id = XplSetThreadGroupID(ConnMgr.id.group); - - ConnMgr.state = CONNMGR_STOPPING; - - if (ConnMgr.server.conn) { - ConnClose(ConnMgr.server.conn, 1); - ConnMgr.server.conn = NULL; - } - - if (closeConnection) { - *closeConnection = TRUE; - } - - XplSetThreadGroupID(id); - } - } else if (ConnMgr.state >= CONNMGR_STOPPING) { - *response = MemStrdup("Shutdown in progress.\r\n"); - } else { - *response = MemStrdup("Unknown shutdown state.\r\n"); - } - - if (*response) { - return(TRUE); - } - - return(FALSE); - } - - *response = MemStrdup("arguments not allowed.\r\n"); - return(TRUE); - } - - return(FALSE); -} - -static BOOL -ConnMgrDMCCommandHelp(unsigned char *arguments, unsigned char **response, BOOL *closeConnection) -{ - BOOL responded = FALSE; - - if (response) { - if (arguments) { - switch(toupper(arguments[0])) { - case 'M': { - if (XplStrCaseCmp(arguments, DMCMC_DUMP_MEMORY_USAGE) == 0) { - if ((*response = MemStrdup(DMCMC_DUMP_MEMORY_USAGE_HELP)) != NULL) { - responded = TRUE; - } - - break; - } - } - - case 'C': { - if (XplStrNCaseCmp(arguments, DMCMC_CONN_TRACE_USAGE, sizeof(DMCMC_CONN_TRACE_USAGE) - 1) == 0) { - if ((*response = MemStrdup(DMCMC_CONN_TRACE_USAGE_HELP)) != NULL) { - responded = TRUE; - } - - break; - } - } - - case 'S': { - if (XplStrCaseCmp(arguments, DMCMC_SHUTDOWN) == 0) { - if ((*response = MemStrdup(DMCMC_SHUTDOWN_HELP)) != NULL) { - responded = TRUE; - } - - break; - } else if (XplStrCaseCmp(arguments, DMCMC_STATS) == 0) { - if ((*response = MemStrdup(DMCMC_STATS_HELP)) != NULL) { - responded = TRUE; - } - - break; - } - } - - default: { - break; - } - } - } else if ((*response = MemStrdup(DMCMC_HELP_HELP)) != NULL) { - responded = TRUE; - } - - if (responded || ((*response = MemStrdup(DMCMC_UNKOWN_COMMAND)) != NULL)) { - return(TRUE); - } - } - - return(FALSE); -} - -static BOOL -SendConnMgrStatistics(unsigned char *arguments, unsigned char **response, BOOL *closeConnection) -{ - MemStatistics poolStats; - - if (!arguments && response) { - memset(&poolStats, 0, sizeof(MemStatistics)); - - *response = MemMalloc(sizeof(PRODUCT_NAME) /* Long Name */ - + sizeof(PRODUCT_SHORT_NAME) /* Short Name */ - + 10 /* PRODUCT_MAJOR_VERSION */ - + 10 /* PRODUCT_MINOR_VERSION */ - + 10 /* PRODUCT_LETTER_VERSION */ - + 10 /* Connection Pool Allocation Count */ - + 10 /* Connection Pool Memory Usage */ - + 10 /* Connection Pool Pitches */ - + 10 /* Connection Pool Strikes */ - + 10 /* DMCMV_SERVER_THREAD_COUNT */ - + 10 /* DMCMV_CONNECTION_COUNT */ - + 10 /* DMCMV_IDLE_CONNECTION_COUNT */ - + 10 /* DMCMV_MAX_CONNECTION_COUNT */ - + 10 /* DMCMV_TOTAL_CONNECTIONS */ - + 10 /* DMCMV_BAD_PASSWORD_COUNT */ - + 28); /* Formatting */ - - // MemPrivatePoolStatistics(ConnMgr.client.pool, &poolStats); - - if (*response) { - sprintf(*response, "%s (%s: v%d.%d.%d)\r\n%lu:%lu:%lu:%lu:%d:%d:%d:%d:%d:%d\r\n", - PRODUCT_NAME, - PRODUCT_SHORT_NAME, - PRODUCT_MAJOR_VERSION, - PRODUCT_MINOR_VERSION, - PRODUCT_LETTER_VERSION, - poolStats.totalAlloc.count, - poolStats.totalAlloc.size, - poolStats.pitches, - poolStats.strikes, - XplSafeRead(ConnMgr.server.active), - XplSafeRead(ConnMgr.client.worker.active), - XplSafeRead(ConnMgr.client.worker.idle), - XplSafeRead(ConnMgr.client.worker.maximum), - XplSafeRead(ConnMgr.stats.clients.serviced), - XplSafeRead(ConnMgr.stats.badPasswords)); - - return(TRUE); - } - - if ((*response = MemStrdup("Out of memory.\r\n")) != NULL) { - return(TRUE); - } - } else if ((arguments) && ((*response = MemStrdup("arguments not allowed.\r\n")) != NULL)) { - return(TRUE); - } - - return(FALSE); -} - -static BOOL -ReadConnMgrVariable(unsigned int variable, unsigned char *data, size_t *dataLength) -{ - size_t count; - unsigned char *ptr; - - switch (variable) { - case 0: { - unsigned char version[30]; - - PVCSRevisionToVersion(PRODUCT_VERSION, version); - count = strlen(version) + 10; - - if (data && (*dataLength > count)) { - ptr = data; - - PVCSRevisionToVersion(PRODUCT_VERSION, version); - ptr += sprintf(ptr, "connmgr.c: %s\r\n", version); - - *dataLength = ptr - data; - } else { - *dataLength = count; - } - - break; - } - - case 1: { - if (data && (*dataLength > 12)) { - sprintf(data, "%010d\r\n", XplSafeRead(ConnMgr.client.worker.maximum)); - } - - *dataLength = 12; - break; - } - - case 2: { - if (data && (*dataLength > 12)) { - sprintf(data, "%010d\r\n", XplSafeRead(ConnMgr.server.active)); - } - - *dataLength = 12; - break; - } - - case 3: { - if (data && (*dataLength > 12)) { - sprintf(data, "%010d\r\n", XplSafeRead(ConnMgr.client.worker.active)); - } - - *dataLength = 12; - break; - } - - case 4: { - if (data && (*dataLength > 12)) { - sprintf(data, "%010d\r\n", XplSafeRead(ConnMgr.client.worker.idle)); - } - - *dataLength = 12; - break; - } - - case 5: { - if (ConnMgr.stopped == FALSE) { - ptr = "FALSE\r\n"; - count = 7; - } else { - ptr = "TRUE\r\n"; - count = 6; - } - - if (data && (*dataLength > count)) { - strcpy(data, ptr); - } - - *dataLength = count; - break; - } - - case 6: { - if (data && (*dataLength > 12)) { - sprintf(data, "%010d\r\n", XplSafeRead(ConnMgr.stats.clients.serviced)); - } - - *dataLength = 12; - break; - } - - case 7: { - if (data && (*dataLength > 12)) { - sprintf(data, "%010d\r\n", XplSafeRead(ConnMgr.stats.badPasswords)); - } - - *dataLength = 12; - break; - } - - case 8: { - DMC_REPORT_PRODUCT_VERSION(data, *dataLength); - break; - } - - default: { - *dataLength = 0; - return(FALSE); - } - } - - return(TRUE); -} - -static BOOL -WriteConnMgrVariable(unsigned int variable, unsigned char *data, size_t dataLength) -{ - unsigned char *ptr; - unsigned char *ptr2; - BOOL result = TRUE; - - if (!data || !dataLength) { - return(FALSE); - } - - switch (variable) { - case 1: { - ptr = strchr(data, '\n'); - if (ptr) { - *ptr = '\0'; - } - - ptr2 = strchr(data, '\r'); - if (ptr2) { - ptr2 = '\0'; - } - - XplSafeWrite(ConnMgr.client.worker.maximum, atol(data)); - - if (ptr) { - *ptr = '\n'; - } - - if (ptr2) { - *ptr2 = 'r'; - } - - break; - } - - case 5: { - if ((toupper(data[0]) == 'T') || (atol(data) != 0)) { - ConnMgr.stopped = TRUE; - } else if ((toupper(data[0] == 'F')) || (atol(data) == 0)) { - ConnMgr.stopped = FALSE; - } else { - result = FALSE; - } - - break; - } - - case 9: { - ptr = strchr(data, '\n'); - if (ptr) { - *ptr = '\0'; - } - - ptr2 = strchr(data, '\r'); - if (ptr2) { - ptr2 = '\0'; - } - - XplSafeWrite(ConnMgr.stats.clients.serviced, atol(data)); - - if (ptr) { - *ptr = '\n'; - } - - if (ptr2) { - *ptr2 = 'r'; - } - - break; - } - - case 10: { - ptr = strchr(data, '\n'); - if (ptr) { - *ptr = '\0'; - } - - ptr2 = strchr(data, '\r'); - if (ptr2) { - ptr2 = '\0'; - } - - XplSafeWrite(ConnMgr.stats.badPasswords, atol(data)); - - if (ptr) { - *ptr = '\n'; - } - - if (ptr2) { - *ptr2 = 'r'; - } - - break; - } - - case 0: - case 2: - case 3: - case 4: - case 6: - case 7: - case 8: - default: { - result = FALSE; - break; - } - } - - return(result); -} - - - -XplServiceCode(SignalHandler) - -int -XplServiceMain(int argc, char *argv[]) -{ - int ccode; - XplThreadID id; - - if (XplSetEffectiveUser(MsgGetUnprivilegedUser()) < 0) { - XplConsolePrintf("bongoconnmgr: Could not drop to unprivileged user '%s', exiting.\n", MsgGetUnprivilegedUser()); - return(-1); - } - XplInit(); - ConnMgr.id.main = XplGetThreadID(); - ConnMgr.id.group = XplGetThreadGroupID(); - - ConnMgr.state = CONNMGR_INITIALIZING; - ConnMgr.stopped = FALSE; - - XplSignalHandler(SignalHandler); - - ConnMgr.client.sleepTime = 60; - ConnMgr.client.pool = NULL; - - ConnMgr.server.conn = NULL; - - ConnMgr.directoryHandle = NULL; - ConnMgr.loggingHandle = NULL; - - XplSafeWrite(ConnMgr.server.active, 0); - - XplSafeWrite(ConnMgr.client.worker.idle, 0); - XplSafeWrite(ConnMgr.client.worker.active, 0); - XplSafeWrite(ConnMgr.client.worker.maximum, 100000); - - XplSafeWrite(ConnMgr.stats.clients.serviced, 0); - XplSafeWrite(ConnMgr.stats.badPasswords, 0); - - if (MemoryManagerOpen(MSGSRV_AGENT_CONNMGR) == TRUE) { - ConnMgr.client.pool = MemPrivatePoolAlloc("Connection Manager Connections", sizeof(ConnMgrClient), 0, 3072, TRUE, FALSE, ConnMgrClientAllocCB, NULL, NULL); - if (ConnMgr.client.pool != NULL) { - XplOpenLocalSemaphore(ConnMgr.sem.main, 0); - XplOpenLocalSemaphore(ConnMgr.sem.shutdown, 1); - XplOpenLocalSemaphore(ConnMgr.client.semaphore, 1); - XplOpenLocalSemaphore(ConnMgr.client.worker.todo, 0); - } else { - MemoryManagerClose(MSGSRV_AGENT_CONNMGR); - - XplConsolePrintf("bongoconnmgr: Unable to create connection pool; shutting down.\r\n"); - return(-1); - } - } else { - XplConsolePrintf("bongoconnmgr: Unable to initialize memory manager; shutting down.\r\n"); - return(-1); - } - - ConnStartup(CONNECTION_TIMEOUT, TRUE); - - MDBInit(); - ConnMgr.directoryHandle = (MDBHandle)MsgInit(); - if (ConnMgr.directoryHandle == NULL) { - XplBell(); - XplConsolePrintf("\rbongoconnmgr: Invalid directory credentials; exiting!\n"); - XplBell(); - - MemoryManagerClose(MSGSRV_AGENT_CONNMGR); - - return(-1); - } - - ConnMgr.loggingHandle = LoggerOpen("bongoconnmgr"); - if (ConnMgr.loggingHandle == NULL) { - XplConsolePrintf("bongoconnmgr: Unable to initialize logging interface. Logging disabled.\r\n"); - } - - if (!ReadConfiguration()) { - XplConsolePrintf("bongoconnmgr: Unable to read configuration. Exiting.\r\n"); - return(-1); - } - CONN_TRACE_INIT((char *)MsgGetWorkDir(NULL), "connmgr"); - // CONN_TRACE_SET_FLAGS(CONN_TRACE_ALL); /* uncomment this line and pass '--enable-conntrace' to autogen to get the agent to trace all connections */ - - - XplRWLockInit(&ConnMgr.authHandles.lock); - - /* Load the modules */ - ConnMgr.modules = LoadModules(ConnMgr.moduleDir, NULL); - if (!ConnMgr.modules) { - XplConsolePrintf("bongoconnmgr: Failed to load any modules. Functionality will be limited.\n"); - } - - if (ServerSocketInit () < 0) { - XplConsolePrintf("bongoconnmgr: Exiting.\n"); - return(-1); - } - - /* Done binding, drop privs permanentely */ - if (XplSetRealUser(MsgGetUnprivilegedUser()) < 0) { - XplConsolePrintf("bongoconnmgr: Could not drop to unprivileged user '%s', exiting.\n", MsgGetUnprivilegedUser()); - return(-1); - } - - /* Management Client Startup */ - if ((ManagementInit(MSGSRV_AGENT_CONNMGR, ConnMgr.directoryHandle)) - && (ManagementSetVariables(ConnMgrManagementVariables, sizeof(ConnMgrManagementVariables) / sizeof(ManagementVariables))) - && (ManagementSetCommands(ConnMgrManagementCommands, sizeof(ConnMgrManagementCommands) / sizeof(ManagementCommands)))) { - XplBeginThread(&id, ManagementServer, DMC_MANAGEMENT_STACKSIZE, NULL, ccode); - } - - ConnMgr.state = CONNMGR_LOADING; - - XplStartMainThread(PRODUCT_SHORT_NAME, &id, ConnMgrServer, 8192, NULL, ccode); - - XplUnloadApp(XplGetThreadID()); - return(0); -} diff --git a/src/agents/connmgr/connmgrp.h b/src/agents/connmgr/connmgrp.h deleted file mode 100644 index f56fd63..0000000 --- a/src/agents/connmgr/connmgrp.h +++ /dev/null @@ -1,42 +0,0 @@ -/**************************************************************************** - * - * Copyright (c) 2001 Novell, Inc. All Rights Reserved. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public License - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, contact Novell, Inc. - * - * To contact Novell about this file by physical or electronic mail, you - * may find current contact information at www.novell.com. - * - ****************************************************************************/ - -#include - -#define CONNMGR_STACK_SPACE (1024 * 32) -#define CONNECTION_TIMEOUT (15 * 60) - -/* modules.c */ -typedef struct _ModuleStruct { - struct _CMModuleRegistrationStruct registration; - - CMInitFunc Init; - XplPluginHandle handle; - struct _ModuleStruct *next; - unsigned char *name; -} ModuleStruct; - - -void ModulesVerify(ModuleStruct *first, ConnMgrCommand *command, ConnMgrResult *result); -void ModulesNotify(ModuleStruct *first, ConnMgrCommand *command); -ModuleStruct * LoadModules(unsigned char *directory, ModuleStruct *first); -void UnloadModules(ModuleStruct *first); - diff --git a/src/agents/connmgr/modules.c b/src/agents/connmgr/modules.c deleted file mode 100644 index db3a069..0000000 --- a/src/agents/connmgr/modules.c +++ /dev/null @@ -1,212 +0,0 @@ -/**************************************************************************** - * - * Copyright (c) 2001 Novell, Inc. All Rights Reserved. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public License - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, contact Novell, Inc. - * - * To contact Novell about this file by physical or electronic mail, you - * may find current contact information at www.novell.com. - * - ****************************************************************************/ - -#include -#include - -#include -#include - -#include "connmgrp.h" - -void -ModulesVerify(ModuleStruct *first, ConnMgrCommand *command, ConnMgrResult *result) -{ - ModuleStruct *module = first; - result->result = command->detail.policy.default_result; - - while (module) { - if (module->registration.Verify) { - int rc = module->registration.Verify(command, result); - - if (rc & CM_MODULE_DENY) { - if (rc & CM_MODULE_PERMANENT) { - result->result = CM_RESULT_DENY_PERMANENT; - } else { - result->result = CM_RESULT_DENY_TEMPORARY; - } - } - - if (rc & CM_MODULE_FORCE) { - if (rc & CM_MODULE_ACCEPT) { - result->result = CM_RESULT_ALLOWED; - } - - return; - } - } - - module = module->next; - } -} - -void -ModulesNotify(ModuleStruct *first, ConnMgrCommand *command) -{ - ModuleStruct *module = first; - - while (module) { - if (module->registration.Notify) { - module->registration.Notify(command); - } - - module = module->next; - } -} - -ModuleStruct * -LoadModules(unsigned char *directory, ModuleStruct *first) -{ - XplDir *dir; - XplDir *dirent; - ModuleStruct *result = first; - - XplMakeDir(XPL_DEFAULT_DBF_DIR "//connmgr"); - - if ((dir = XplOpenDir(directory)) != NULL) { - while ((dirent = XplReadDir(dir)) != NULL) { - unsigned char path[XPL_MAX_PATH +1 ]; - unsigned char name[XPL_MAX_PATH + 1]; - unsigned char *modulename = dirent->d_nameDOS; - ModuleStruct *new = MemMalloc(sizeof(ModuleStruct)); - unsigned char datadir[XPL_MAX_PATH + 1]; - - memset(new, 0, sizeof(ModuleStruct)); - - if (strlen(modulename) > 3) { - snprintf(path, sizeof(path), "%s/lib%s", directory, modulename); - new->handle = XplLoadDLL(path); - - if (!new->handle) { - snprintf(path, sizeof(path), "%s/%s", directory, modulename); - new->handle = XplLoadDLL(path); - } - - if (new->handle) { - unsigned char *ptr; - - /* Initialize the module */ - if (XplStrNCaseCmp(modulename, "lib", 3) == 0) { - BongoStrNCpy(name, modulename + 3, sizeof(name) - strlen("Init")); - } else { - BongoStrNCpy(name, modulename, sizeof(name) - strlen("Init")); - } - - ptr = strrchr(name, '.'); - if (ptr) { - *ptr = '\0'; - } - - /* Setup the work directory for the module */ - ptr = name; - while (*ptr) { - *ptr = tolower(*ptr); - ptr++; - } - - sprintf(datadir, "%s/connmgr/%s", XPL_DEFAULT_DBF_DIR, name); - XplMakeDir(datadir); - - ptr = name; - while (*ptr) { - *ptr = toupper(*ptr); - ptr++; - } - - strcat(name, "Init"); - new->Init = (CMInitFunc)XplGetDLLFunction(modulename, name, new->handle); - name[strlen(name) - 4] = '\0'; -#if 0 - } else { - /* dlerror() is much more useful when dlopen fails than errno is */ - unsigned char *err = dlerror(); - if (err) { - XplConsolePrintf("connmgr: XplLoadDLL failed: %s\n", err); - } - XplConsolePrintf("connmgr: could not load module %s/%s, errno: %d %s\n", directory, modulename, errno, strerror(errno)); -#endif - } - } - - if (new->Init && new->Init(&(new->registration), datadir)) { - new->name = MemStrdup(name); - -#if VERBOSE - XplConsolePrintf("connmgr: loaded module: %s\n", new->name); -#endif - - if (!result) { - result = new; - } else if (result->registration.priority > new->registration.priority) { - new->next = result; - result = new; - } else { - ModuleStruct *n = result; - - /* Find a spot for it */ - while (n && n->next) { - if (n->next->registration.priority > new->registration.priority) { - new->next = n->next; - n->next = new; - n = NULL; - } - - if (n) { - n = n->next; - } - } - - if (n) { - n->next = new; - } - } - } else { - MemFree(new); - } - } - - XplCloseDir(dir); - } - - return(result); -} - -void -UnloadModules(ModuleStruct *first) -{ - ModuleStruct *module = first; - - while (module) { - ModuleStruct *next = module->next; - - if (module->registration.Shutdown) { - module->registration.Shutdown(); - } - - if (module->handle && module->name) { - XplUnloadDLL(module->name, module->handle); - MemFree(module->name); - } - - MemFree(module); - module = next; - } -} diff --git a/src/libs/python/libbongo/mdb.c b/src/libs/python/libbongo/mdb.c deleted file mode 100644 index 233d7e0..0000000 --- a/src/libs/python/libbongo/mdb.c +++ /dev/null @@ -1,1818 +0,0 @@ -/**************************************************************************** - * - * Copyright (c) 2006 Novell, Inc. - * All Rights Reserved. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2.1 of the GNU Lesser General Public - * License as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, contact Novell, Inc. - * - * To contact Novell about this file by physical or electronic mail, - * you may find current contact information at www.novell.com - * - ****************************************************************************/ - -#include -#include -#include -#include - -#include "libs.h" - -#ifdef __cplusplus -extern "C" { -#endif - -PyObject *mdb_Init(PyObject *self, PyObject *args); -PyObject *mdb_Shutdown(PyObject *self, PyObject *args); -PyObject *mdb_GetAPIVersion(PyObject *self, PyObject *args); -PyObject *mdb_GetAPIDescription(PyObject *self, PyObject *args); -PyObject *mdb_GetBaseDN(PyObject *self, PyObject *args); -PyObject *mdb_Authenticate(PyObject *self, PyObject *args); -PyObject *mdb_Release(PyObject *self, PyObject *args); -PyObject *mdb_CreateValueStruct(PyObject *self, PyObject *args); -PyObject *mdb_DestroyValueStruct(PyObject *self, PyObject *args); -PyObject *mdb_VSGetUsed(PyObject *self, PyObject *args); -PyObject *mdb_VSGetValue(PyObject *self, PyObject *args); -PyObject *mdb_VSGetErrNo(PyObject *self, PyObject *args); -PyObject *mdb_VSAddValue(PyObject *self, PyObject *args); -PyObject *mdb_VSFreeValue(PyObject *self, PyObject *args); -PyObject *mdb_VSFreeValues(PyObject *self, PyObject *args); -PyObject *mdb_VSSetContext(PyObject *self, PyObject *args); -PyObject *mdb_ShareContext(PyObject *self, PyObject *args); -PyObject *mdb_CreateEnumStruct(PyObject *self, PyObject *args); -PyObject *mdb_DestroyEnumStruct(PyObject *self, PyObject *args); -PyObject *mdb_Read(PyObject *self, PyObject *args); -PyObject *mdb_ReadEx(PyObject *self, PyObject *args); -PyObject *mdb_ReadDN(PyObject *self, PyObject *args); -PyObject *mdb_Write(PyObject *self, PyObject *args); -PyObject *mdb_WriteTyped(PyObject *self, PyObject *args); -PyObject *mdb_WriteDN(PyObject *self, PyObject *args); -PyObject *mdb_Clear(PyObject *self, PyObject *args); -PyObject *mdb_Add(PyObject *self, PyObject *args); -PyObject *mdb_AddDN(PyObject *self, PyObject *args); -PyObject *mdb_Remove(PyObject *self, PyObject *args); -PyObject *mdb_RemoveDN(PyObject *self, PyObject *args); -PyObject *mdb_IsObject(PyObject *self, PyObject *args); -PyObject *mdb_GetObjectDetails_Type(PyObject *self, PyObject *args); -PyObject *mdb_GetObjectDetails_RDN(PyObject *self, PyObject *args); -PyObject *mdb_GetObjectDetails_DN(PyObject *self, PyObject *args); -PyObject *mdb_VerifyPassword(PyObject *self, PyObject *args); -PyObject *mdb_VerifyPasswordEx(PyObject *self, PyObject *args); -PyObject *mdb_ChangePassword(PyObject *self, PyObject *args); -PyObject *mdb_ChangePasswordEx(PyObject *self, PyObject *args); -PyObject *mdb_EnumerateObjects(PyObject *self, PyObject *args); -PyObject *mdb_EnumerateObjectsEx(PyObject *self, PyObject *args); -PyObject *mdb_EnumerateAttributesEx(PyObject *self, PyObject *args); -PyObject *mdb_CreateObject(PyObject *self, PyObject *args); -PyObject *mdb_DeleteObject(PyObject *self, PyObject *args); -PyObject *mdb_RenameObject(PyObject *self, PyObject *args); -PyObject *mdb_DefineAttribute(PyObject *self, PyObject *args); -PyObject *mdb_UndefineAttribute(PyObject *self, PyObject *args); -PyObject *mdb_AddAttribute(PyObject *self, PyObject *args); -PyObject *mdb_DefineClass(PyObject *self, PyObject *args); -PyObject *mdb_UndefineClass(PyObject *self, PyObject *args); -PyObject *mdb_ListContainableClasses(PyObject *self, PyObject *args); -PyObject *mdb_ListContainableClassesEx(PyObject *self, PyObject *args); -PyObject *mdb_GrantObjectRights(PyObject *self, PyObject *args); -PyObject *mdb_GrantAttributeRights(PyObject *self, PyObject *args); -PyObject *mdb_DumpValueStruct(PyObject *self, PyObject *args); - -PyMethodDef MdbMethods[] = { - {"mdb_Init", mdb_Init, METH_VARARGS | METH_STATIC}, - {"mdb_Shutdown", mdb_Shutdown, METH_VARARGS | METH_STATIC}, - {"mdb_GetAPIVersion", mdb_GetAPIVersion, METH_VARARGS | METH_STATIC}, - {"mdb_GetAPIDescription", mdb_GetAPIDescription, - METH_VARARGS | METH_STATIC}, - {"mdb_GetBaseDN", mdb_GetBaseDN, METH_VARARGS | METH_STATIC}, - {"mdb_Authenticate", mdb_Authenticate, METH_VARARGS | METH_STATIC}, - {"mdb_Release", mdb_Release, METH_VARARGS | METH_STATIC}, - {"mdb_CreateValueStruct", mdb_CreateValueStruct, - METH_VARARGS | METH_STATIC}, - {"mdb_DestroyValueStruct", mdb_DestroyValueStruct, - METH_VARARGS | METH_STATIC}, - {"mdb_VSGetUsed", mdb_VSGetUsed, METH_VARARGS | METH_STATIC}, - {"mdb_VSGetValue", mdb_VSGetValue, METH_VARARGS | METH_STATIC}, - {"mdb_VSGetErrNo", mdb_VSGetErrNo, METH_VARARGS | METH_STATIC}, - {"mdb_VSAddValue", mdb_VSAddValue, METH_VARARGS | METH_STATIC}, - {"mdb_VSFreeValue", mdb_VSFreeValue, METH_VARARGS | METH_STATIC}, - {"mdb_VSFreeValues", mdb_VSFreeValues, METH_VARARGS | METH_STATIC}, - {"mdb_VSSetContext", mdb_VSSetContext, METH_VARARGS | METH_STATIC}, - {"mdb_ShareContext", mdb_ShareContext, METH_VARARGS | METH_STATIC}, - {"mdb_CreateEnumStruct", mdb_CreateEnumStruct, - METH_VARARGS | METH_STATIC}, - {"mdb_DestroyEnumStruct", mdb_DestroyEnumStruct, - METH_VARARGS | METH_STATIC}, - {"mdb_Read", mdb_Read, METH_VARARGS | METH_STATIC}, - {"mdb_ReadEx", mdb_ReadEx, METH_VARARGS | METH_STATIC}, - {"mdb_ReadDN", mdb_ReadDN, METH_VARARGS | METH_STATIC}, - {"mdb_Write", mdb_Write, METH_VARARGS | METH_STATIC}, - {"mdb_WriteTyped", mdb_WriteTyped, METH_VARARGS | METH_STATIC}, - {"mdb_WriteDN", mdb_WriteDN, METH_VARARGS | METH_STATIC}, - {"mdb_Clear", mdb_Clear, METH_VARARGS | METH_STATIC}, - {"mdb_Add", mdb_Add, METH_VARARGS | METH_STATIC}, - {"mdb_AddDN", mdb_AddDN, METH_VARARGS | METH_STATIC}, - {"mdb_Remove", mdb_Remove, METH_VARARGS | METH_STATIC}, - {"mdb_RemoveDN", mdb_RemoveDN, METH_VARARGS | METH_STATIC}, - {"mdb_IsObject", mdb_IsObject, METH_VARARGS | METH_STATIC}, - {"mdb_GetObjectDetails_Type", mdb_GetObjectDetails_Type, - METH_VARARGS | METH_STATIC}, - {"mdb_GetObjectDetails_RDN", mdb_GetObjectDetails_RDN, - METH_VARARGS | METH_STATIC}, - {"mdb_GetObjectDetails_DN", mdb_GetObjectDetails_DN, - METH_VARARGS | METH_STATIC}, - {"mdb_VerifyPassword", mdb_VerifyPassword, METH_VARARGS | METH_STATIC}, - {"mdb_VerifyPasswordEx", mdb_VerifyPasswordEx, METH_VARARGS | METH_STATIC}, - {"mdb_ChangePassword", mdb_ChangePassword, METH_VARARGS | METH_STATIC}, - {"mdb_ChangePasswordEx", mdb_ChangePasswordEx, METH_VARARGS | METH_STATIC}, - {"mdb_EnumerateObjects", mdb_EnumerateObjects, METH_VARARGS | METH_STATIC}, - {"mdb_EnumerateObjectsEx", mdb_EnumerateObjectsEx, - METH_VARARGS | METH_STATIC}, - {"mdb_EnumerateAttributesEx", mdb_EnumerateAttributesEx, - METH_VARARGS | METH_STATIC}, - {"mdb_CreateObject", mdb_CreateObject, METH_VARARGS | METH_STATIC}, - {"mdb_DeleteObject", mdb_DeleteObject, METH_VARARGS | METH_STATIC}, - {"mdb_RenameObject", mdb_RenameObject, METH_VARARGS | METH_STATIC}, - {"mdb_DefineAttribute", mdb_DefineAttribute, METH_VARARGS | METH_STATIC}, - {"mdb_UndefineAttribute", mdb_UndefineAttribute, - METH_VARARGS | METH_STATIC}, - {"mdb_AddAttribute", mdb_AddAttribute, METH_VARARGS | METH_STATIC}, - {"mdb_DefineClass", mdb_DefineClass, METH_VARARGS | METH_STATIC}, - {"mdb_UndefineClass", mdb_UndefineClass, METH_VARARGS | METH_STATIC}, - {"mdb_ListContainableClasses", mdb_ListContainableClasses, - METH_VARARGS | METH_STATIC}, - {"mdb_ListContainableClassesEx", mdb_ListContainableClassesEx, - METH_VARARGS | METH_STATIC}, - {"mdb_GrantObjectRights", mdb_GrantObjectRights, - METH_VARARGS | METH_STATIC}, - {"mdb_GrantAttributeRights", mdb_GrantAttributeRights, - METH_VARARGS | METH_STATIC}, - {"mdb_DumpValueStruct", mdb_DumpValueStruct, METH_VARARGS | METH_STATIC}, - {NULL, NULL} -}; - -EnumItemDef MdbEnums[] = { - {"MDB_CURRENT_API_VERSION", MDB_CURRENT_API_VERSION, NULL}, - {"MDB_COMPATIBLE_TO_API", MDB_COMPATIBLE_TO_API, NULL}, - {"MDB_MAX_OBJECT_CHARS", MDB_MAX_OBJECT_CHARS, NULL}, - {"MDB_MAX_UTF8_OBJECT_CHARS", MDB_MAX_UTF8_OBJECT_CHARS, NULL}, - {"MDB_MAX_ATTRIBUTE_VALUE_CHARS", MDB_MAX_ATTRIBUTE_VALUE_CHARS, NULL}, - {"MDB_MAX_ATTRIBUTE_VALUE_UTF8_CHARS", MDB_MAX_ATTRIBUTE_VALUE_UTF8_CHARS, - NULL}, - {"MDB_MAX_TREE_CHARS", MDB_MAX_TREE_CHARS, NULL}, - {"MDB_MAX_ATTRIBUTE_CHARS", MDB_MAX_ATTRIBUTE_CHARS, NULL}, - /* note: the following are single characters, taken as longs... */ - {"MDB_ATTR_SYN_STRING", MDB_ATTR_SYN_STRING, 0}, - {"MDB_ATTR_SYN_DIST_NAME", MDB_ATTR_SYN_DIST_NAME, 0}, - {"MDB_ATTR_SYN_BOOL", MDB_ATTR_SYN_BOOL, 0}, - {"MDB_ATTR_SYN_BINARY", MDB_ATTR_SYN_BINARY, 0}, - {"C_AFP_SERVER", 0, C_AFP_SERVER}, - {"C_ALIAS", 0, C_ALIAS}, - {"C_BINDERY_OBJECT", 0, C_BINDERY_OBJECT}, - {"C_BINDERY_QUEUE", 0, C_BINDERY_QUEUE}, - {"C_COMMEXEC", 0, C_COMMEXEC}, - {"C_COMPUTER", 0, C_COMPUTER}, - {"C_COUNTRY", 0, C_COUNTRY}, - {"C_DEVICE", 0, C_DEVICE}, - {"C_DIRECTORY_MAP", 0, C_DIRECTORY_MAP}, - {"C_EXTERNAL_ENTITY", 0, C_EXTERNAL_ENTITY}, - {"C_GROUP", 0, C_GROUP}, - {"C_LIST", 0, C_LIST}, - {"C_LOCALITY", 0, C_LOCALITY}, - {"C_MESSAGE_ROUTING_GROUP", 0, C_MESSAGE_ROUTING_GROUP}, - {"C_MESSAGING_ROUTING_GROUP", 0, C_MESSAGING_ROUTING_GROUP}, - {"C_MESSAGING_SERVER", 0, C_MESSAGING_SERVER}, - {"C_NCP_SERVER", 0, C_NCP_SERVER}, - {"C_ORGANIZATION", 0, C_ORGANIZATION}, - {"C_ORGANIZATIONAL_PERSON", 0, C_ORGANIZATIONAL_PERSON}, - {"C_ORGANIZATIONAL_ROLE", 0, C_ORGANIZATIONAL_ROLE}, - {"C_ORGANIZATIONAL_UNIT", 0, C_ORGANIZATIONAL_UNIT}, - {"C_PARTITION", 0, C_PARTITION}, - {"C_PERSON", 0, C_PERSON}, - {"C_PRINT_SERVER", 0, C_PRINT_SERVER}, - {"C_PRINTER", 0, C_PRINTER}, - {"C_PROFILE", 0, C_PROFILE}, - {"C_QUEUE", 0, C_QUEUE}, - {"C_RESOURCE", 0, C_RESOURCE}, - {"C_SERVER", 0, C_SERVER}, - {"C_TOP", 0, C_TOP}, - {"C_TREE_ROOT", 0, C_TREE_ROOT}, - {"C_UNKNOWN", 0, C_UNKNOWN}, - {"C_USER", 0, C_USER}, - {"C_VOLUME", 0, C_VOLUME}, - {"A_ACCOUNT_BALANCE", 0, A_ACCOUNT_BALANCE}, - {"A_ACL", 0, A_ACL}, - {"A_ALIASED_OBJECT_NAME", 0, A_ALIASED_OBJECT_NAME}, - {"A_ALLOW_UNLIMITED_CREDIT", 0, A_ALLOW_UNLIMITED_CREDIT}, - {"A_AUTHORITY_REVOCATION", 0, A_AUTHORITY_REVOCATION}, - {"A_BACK_LINK", 0, A_BACK_LINK}, - {"A_BINDERY_OBJECT_RESTRICTION", 0, A_BINDERY_OBJECT_RESTRICTION}, - {"A_BINDERY_PROPERTY", 0, A_BINDERY_PROPERTY}, - {"A_BINDERY_TYPE", 0, A_BINDERY_TYPE}, - {"A_CARTRIDGE", 0, A_CARTRIDGE}, - {"A_CA_PRIVATE_KEY", 0, A_CA_PRIVATE_KEY}, - {"A_CA_PUBLIC_KEY", 0, A_CA_PUBLIC_KEY}, - {"A_CERTIFICATE_REVOCATION", 0, A_CERTIFICATE_REVOCATION}, - {"A_CERTIFICATE_VALIDITY_INTERVAL", 0, A_CERTIFICATE_VALIDITY_INTERVAL}, - {"A_COMMON_NAME", 0, A_COMMON_NAME}, - {"A_CONVERGENCE", 0, A_CONVERGENCE}, - {"A_COUNTRY_NAME", 0, A_COUNTRY_NAME}, - {"A_CROSS_CERTIFICATE_PAIR", 0, A_CROSS_CERTIFICATE_PAIR}, - {"A_DEFAULT_QUEUE", 0, A_DEFAULT_QUEUE}, - {"A_DESCRIPTION", 0, A_DESCRIPTION}, - {"A_DETECT_INTRUDER", 0, A_DETECT_INTRUDER}, - {"A_DEVICE", 0, A_DEVICE}, - {"A_DS_REVISION", 0, A_DS_REVISION}, - {"A_EMAIL_ADDRESS", 0, A_EMAIL_ADDRESS}, - {"A_EQUIVALENT_TO_ME", 0, A_EQUIVALENT_TO_ME}, - {"A_EXTERNAL_NAME", 0, A_EXTERNAL_NAME}, - {"A_EXTERNAL_SYNCHRONIZER", 0, A_EXTERNAL_SYNCHRONIZER}, - {"A_FACSIMILE_TELEPHONE_NUMBER", 0, A_FACSIMILE_TELEPHONE_NUMBER}, - {"A_FULL_NAME", 0, A_FULL_NAME}, - {"A_GENERATIONAL_QUALIFIER", 0, A_GENERATIONAL_QUALIFIER}, - {"A_GID", 0, A_GID}, - {"A_GIVEN_NAME", 0, A_GIVEN_NAME}, - {"A_GROUP_MEMBERSHIP", 0, A_GROUP_MEMBERSHIP}, - {"A_HIGH_SYNC_INTERVAL", 0, A_HIGH_SYNC_INTERVAL}, - {"A_HIGHER_PRIVILEGES", 0, A_HIGHER_PRIVILEGES}, - {"A_HOME_DIRECTORY", 0, A_HOME_DIRECTORY}, - {"A_HOST_DEVICE", 0, A_HOST_DEVICE}, - {"A_HOST_RESOURCE_NAME", 0, A_HOST_RESOURCE_NAME}, - {"A_HOST_SERVER", 0, A_HOST_SERVER}, - {"A_INHERITED_ACL", 0, A_INHERITED_ACL}, - {"A_INITIALS", 0, A_INITIALS}, - {"A_INTERNET_EMAIL_ADDRESS", 0, A_INTERNET_EMAIL_ADDRESS}, - {"A_INTRUDER_ATTEMPT_RESET_INTRVL", 0, A_INTRUDER_ATTEMPT_RESET_INTRVL}, - {"A_INTRUDER_LOCKOUT_RESET_INTRVL", 0, A_INTRUDER_LOCKOUT_RESET_INTRVL}, - {"A_LOCALITY_NAME", 0, A_LOCALITY_NAME}, - {"A_LANGUAGE", 0, A_LANGUAGE}, - {"A_LAST_LOGIN_TIME", 0, A_LAST_LOGIN_TIME}, - {"A_LAST_REFERENCED_TIME", 0, A_LAST_REFERENCED_TIME}, - {"A_LOCKED_BY_INTRUDER", 0, A_LOCKED_BY_INTRUDER}, - {"A_LOCKOUT_AFTER_DETECTION", 0, A_LOCKOUT_AFTER_DETECTION}, - {"A_LOGIN_ALLOWED_TIME_MAP", 0, A_LOGIN_ALLOWED_TIME_MAP}, - {"A_LOGIN_DISABLED", 0, A_LOGIN_DISABLED}, - {"A_LOGIN_EXPIRATION_TIME", 0, A_LOGIN_EXPIRATION_TIME}, - {"A_LOGIN_GRACE_LIMIT", 0, A_LOGIN_GRACE_LIMIT}, - {"A_LOGIN_GRACE_REMAINING", 0, A_LOGIN_GRACE_REMAINING}, - {"A_LOGIN_INTRUDER_ADDRESS", 0, A_LOGIN_INTRUDER_ADDRESS}, - {"A_LOGIN_INTRUDER_ATTEMPTS", 0, A_LOGIN_INTRUDER_ATTEMPTS}, - {"A_LOGIN_INTRUDER_LIMIT", 0, A_LOGIN_INTRUDER_LIMIT}, - {"A_LOGIN_INTRUDER_RESET_TIME", 0, A_LOGIN_INTRUDER_RESET_TIME}, - {"A_LOGIN_MAXIMUM_SIMULTANEOUS", 0, A_LOGIN_MAXIMUM_SIMULTANEOUS}, - {"A_LOGIN_SCRIPT", 0, A_LOGIN_SCRIPT}, - {"A_LOGIN_TIME", 0, A_LOGIN_TIME}, - {"A_LOW_RESET_TIME", 0, A_LOW_RESET_TIME}, - {"A_LOW_SYNC_INTERVAL", 0, A_LOW_SYNC_INTERVAL}, - {"A_MAILBOX_ID", 0, A_MAILBOX_ID}, - {"A_MAILBOX_LOCATION", 0, A_MAILBOX_LOCATION}, - {"A_MEMBER", 0, A_MEMBER}, - {"A_MEMORY", 0, A_MEMORY}, - {"A_MESSAGE_SERVER", 0, A_MESSAGE_SERVER}, - {"A_MESSAGE_ROUTING_GROUP", 0, A_MESSAGE_ROUTING_GROUP}, - {"A_MESSAGING_DATABASE_LOCATION", 0, A_MESSAGING_DATABASE_LOCATION}, - {"A_MESSAGING_ROUTING_GROUP", 0, A_MESSAGING_ROUTING_GROUP}, - {"A_MESSAGING_SERVER", 0, A_MESSAGING_SERVER}, - {"A_MESSAGING_SERVER_TYPE", 0, A_MESSAGING_SERVER_TYPE}, - {"A_MINIMUM_ACCOUNT_BALANCE", 0, A_MINIMUM_ACCOUNT_BALANCE}, - {"A_NETWORK_ADDRESS", 0, A_NETWORK_ADDRESS}, - {"A_NETWORK_ADDRESS_RESTRICTION", 0, A_NETWORK_ADDRESS_RESTRICTION}, - {"A_NNS_DOMAIN", 0, A_NNS_DOMAIN}, - {"A_NOTIFY", 0, A_NOTIFY}, - {"A_OBITUARY", 0, A_OBITUARY}, - {"A_ORGANIZATION_NAME", 0, A_ORGANIZATION_NAME}, - {"A_OBJECT_CLASS", 0, A_OBJECT_CLASS}, - {"A_OPERATOR", 0, A_OPERATOR}, - {"A_ORGANIZATIONAL_UNIT_NAME", 0, A_ORGANIZATIONAL_UNIT_NAME}, - {"A_OWNER", 0, A_OWNER}, - {"A_PAGE_DESCRIPTION_LANGUAGE", 0, A_PAGE_DESCRIPTION_LANGUAGE}, - {"A_PARTITION_CONTROL", 0, A_PARTITION_CONTROL}, - {"A_PARTITION_CREATION_TIME", 0, A_PARTITION_CREATION_TIME}, - {"A_PARTITION_STATUS", 0, A_PARTITION_STATUS}, - {"A_PASSWORD_ALLOW_CHANGE", 0, A_PASSWORD_ALLOW_CHANGE}, - {"A_PASSWORD_EXPIRATION_INTERVAL", 0, A_PASSWORD_EXPIRATION_INTERVAL}, - {"A_PASSWORD_EXPIRATION_TIME", 0, A_PASSWORD_EXPIRATION_TIME}, - {"A_PASSWORD_MANAGEMENT", 0, A_PASSWORD_MANAGEMENT}, - {"A_PASSWORD_MINIMUM_LENGTH", 0, A_PASSWORD_MINIMUM_LENGTH}, - {"A_PASSWORD_REQUIRED", 0, A_PASSWORD_REQUIRED}, - {"A_PASSWORD_UNIQUE_REQUIRED", 0, A_PASSWORD_UNIQUE_REQUIRED}, - {"A_PASSWORDS_USED", 0, A_PASSWORDS_USED}, - {"A_PATH", 0, A_PATH}, - {"A_PERMANENT_CONFIG_PARMS", 0, A_PERMANENT_CONFIG_PARMS}, - {"A_PHYSICAL_DELIVERY_OFFICE_NAME", 0, A_PHYSICAL_DELIVERY_OFFICE_NAME}, - {"A_POSTAL_ADDRESS", 0, A_POSTAL_ADDRESS}, - {"A_POSTAL_CODE", 0, A_POSTAL_CODE}, - {"A_POSTAL_OFFICE_BOX", 0, A_POSTAL_OFFICE_BOX}, - {"A_POSTMASTER", 0, A_POSTMASTER}, - {"A_PRINT_SERVER", 0, A_PRINT_SERVER}, - {"A_PRIVATE_KEY", 0, A_PRIVATE_KEY}, - {"A_PRINTER", 0, A_PRINTER}, - {"A_PRINTER_CONFIGURATION", 0, A_PRINTER_CONFIGURATION}, - {"A_PRINTER_CONTROL", 0, A_PRINTER_CONTROL}, - {"A_PRINT_JOB_CONFIGURATION", 0, A_PRINT_JOB_CONFIGURATION}, - {"A_PROFILE", 0, A_PROFILE}, - {"A_PROFILE_MEMBERSHIP", 0, A_PROFILE_MEMBERSHIP}, - {"A_PUBLIC_KEY", 0, A_PUBLIC_KEY}, - {"A_QUEUE", 0, A_QUEUE}, - {"A_QUEUE_DIRECTORY", 0, A_QUEUE_DIRECTORY}, - {"A_RECEIVED_UP_TO", 0, A_RECEIVED_UP_TO}, - {"A_REFERENCE", 0, A_REFERENCE}, - {"A_REPLICA", 0, A_REPLICA}, - {"A_REPLICA_UP_TO", 0, A_REPLICA_UP_TO}, - {"A_RESOURCE", 0, A_RESOURCE}, - {"A_REVISION", 0, A_REVISION}, - {"A_ROLE_OCCUPANT", 0, A_ROLE_OCCUPANT}, - {"A_STATE_OR_PROVINCE_NAME", 0, A_STATE_OR_PROVINCE_NAME}, - {"A_STREET_ADDRESS", 0, A_STREET_ADDRESS}, - {"A_SAP_NAME", 0, A_SAP_NAME}, - {"A_SECURITY_EQUALS", 0, A_SECURITY_EQUALS}, - {"A_SECURITY_FLAGS", 0, A_SECURITY_FLAGS}, - {"A_SEE_ALSO", 0, A_SEE_ALSO}, - {"A_SERIAL_NUMBER", 0, A_SERIAL_NUMBER}, - {"A_SERVER", 0, A_SERVER}, - {"A_SERVER_HOLDS", 0, A_SERVER_HOLDS}, - {"A_STATUS", 0, A_STATUS}, - {"A_SUPPORTED_CONNECTIONS", 0, A_SUPPORTED_CONNECTIONS}, - {"A_SUPPORTED_GATEWAY", 0, A_SUPPORTED_GATEWAY}, - {"A_SUPPORTED_SERVICES", 0, A_SUPPORTED_SERVICES}, - {"A_SUPPORTED_TYPEFACES", 0, A_SUPPORTED_TYPEFACES}, - {"A_SURNAME", 0, A_SURNAME}, - {"A_IN_SYNC_UP_TO", 0, A_IN_SYNC_UP_TO}, - {"A_TELEPHONE_NUMBER", 0, A_TELEPHONE_NUMBER}, - {"A_TITLE", 0, A_TITLE}, - {"A_TYPE_CREATOR_MAP", 0, A_TYPE_CREATOR_MAP}, - {"A_UID", 0, A_UID}, - {"A_UNKNOWN", 0, A_UNKNOWN}, - {"A_UNKNOWN_BASE_CLASS", 0, A_UNKNOWN_BASE_CLASS}, - {"A_USER", 0, A_USER}, - {"A_VERSION", 0, A_VERSION}, - {"A_VOLUME", 0, A_VOLUME}, - {NULL, 0} -}; - -PyObject * -mdb_Init(PyObject *self, PyObject *args) -{ - PyObject *result = Py_None; - - if (PyArg_ParseTuple(args, "")) { - result = (MDBInit() ? Py_True : Py_False); - } - Py_INCREF(result); - return result; -} - -PyObject * -mdb_Shutdown(PyObject *self, PyObject *args) -{ - PyObject *result = Py_None; - - if (PyArg_ParseTuple(args, "")) { - result = (MDBShutdown() ? Py_True : Py_False); - } - Py_INCREF(result); - return result; -} - -PyObject * -mdb_GetAPIVersion(PyObject *self, PyObject *args) -{ - PyObject *result = NULL; - int compv; - int apiv; - MDBHandle handle; - PyObject *handleObj; - - if (PyArg_ParseTuple(args, "iO", &compv, &handleObj)) { - handle = PyCObject_AsVoidPtr(handleObj); - apiv = MDBGetAPIVersion((compv ? TRUE : FALSE), NULL, handle); - result = Py_BuildValue("i", apiv); - } - return result; -} - -PyObject * -mdb_GetAPIDescription(PyObject *self, PyObject *args) -{ - PyObject *result = NULL; - unsigned char desc[MDB_MAX_API_DESCRIPTION_CHARS]; - MDBHandle handle; - PyObject *handleObj; - - if (PyArg_ParseTuple (args, "O", &handleObj)) { - handle = PyCObject_AsVoidPtr(handleObj); - MDBGetAPIVersion(TRUE, desc, handle); - result = Py_BuildValue("z", desc); - } - return result; -} - -PyObject * -mdb_GetBaseDN(PyObject *self, PyObject *args) -{ - PyObject *result = NULL; - MDBHandle handle; - PyObject *handleObj; - MDBValueStruct *vs; - PyObject *vsObj = Py_None; - - if (PyArg_ParseTuple(args, "O|O", &handleObj, &vsObj)) { - if(vsObj == Py_None) { - handle = PyCObject_AsVoidPtr(handleObj); - vs = MDBCreateValueStruct(handle, NULL); - } else { - vs = PyCObject_AsVoidPtr(vsObj); - } - if(vs) { - result = Py_BuildValue("z", MDBGetBaseDN(vs)); - } - if(vsObj == Py_None) { - MDBDestroyValueStruct(vs); - } - } - return result; -} - -PyObject * -mdb_Authenticate(PyObject *self, PyObject *args) -{ - PyObject *result = NULL; - unsigned char *module; - unsigned char *object; - unsigned char *password; - MDBHandle handle; - - if (PyArg_ParseTuple(args, "szz", &module, &object, &password)) { - handle = MDBAuthenticate(module, object, password); - if(handle) { - result = PyCObject_FromVoidPtr(handle, NULL); - } else { - result = Py_None; - Py_INCREF(result); - } - } - return result; -} - -PyObject * -mdb_Release(PyObject *self, PyObject *args) -{ - PyObject *result = Py_None; - MDBHandle handle; - PyObject *handleObj; - - if (PyArg_ParseTuple(args, "O", &handleObj)) { - handle = PyCObject_AsVoidPtr(handleObj); - result = (MDBRelease(handle) ? Py_True : Py_False); - } - Py_INCREF(result); - return result; -} - -PyObject * -mdb_CreateValueStruct(PyObject *self, PyObject *args) -{ - PyObject *result = NULL; - MDBHandle handle; - PyObject *handleObj; - MDBValueStruct *vs; - unsigned char *context = NULL; - - if (PyArg_ParseTuple(args, "O|z", &handleObj, &context)) { - handle = PyCObject_AsVoidPtr(handleObj); - vs = MDBCreateValueStruct(handle, context); - result = PyCObject_FromVoidPtr(vs, NULL); - } - return result; -} - -PyObject * -mdb_DestroyValueStruct(PyObject *self, PyObject *args) -{ - PyObject *result = Py_None; - MDBValueStruct *vs; - PyObject *vsObj; - - if (PyArg_ParseTuple(args, "O", &vsObj)) { - vs = PyCObject_AsVoidPtr(vsObj); - result = (MDBDestroyValueStruct(vs) ? Py_True : Py_False); - } - Py_INCREF(result); - return result; -} - -PyObject * -mdb_VSGetUsed(PyObject *self, PyObject *args) -{ - PyObject *result = NULL; - MDBValueStruct *vs; - PyObject *vsObj; - - if (PyArg_ParseTuple(args, "O", &vsObj)) { - vs = PyCObject_AsVoidPtr(vsObj); - result = Py_BuildValue("l", vs->Used); - } - return result; -} - -PyObject * -mdb_VSGetValue(PyObject *self, PyObject *args) -{ - PyObject *result = NULL; - MDBValueStruct *vs; - PyObject *vsObj; - int index; - - if (PyArg_ParseTuple(args, "Oi", &vsObj, &index)) { - vs = PyCObject_AsVoidPtr(vsObj); - result = Py_BuildValue("z", vs->Value[index]); - } - return result; -} - -PyObject * -mdb_VSGetErrNo(PyObject *self, PyObject *args) -{ - PyObject *result = NULL; - MDBValueStruct *vs; - PyObject *vsObj; - - if (PyArg_ParseTuple(args, "O", &vsObj)) { - vs = PyCObject_AsVoidPtr(vsObj); - result = Py_BuildValue("l", vs->ErrNo); - } - return result; -} - -PyObject * -mdb_VSAddValue(PyObject *self, PyObject *args) -{ - PyObject *result = Py_None; - MDBValueStruct *vs; - PyObject *vsObj; - unsigned char *value = NULL; - - if (PyArg_ParseTuple(args, "zO", &value, &vsObj)) { - vs = PyCObject_AsVoidPtr(vsObj); - result = (MDBAddValue(value, vs) ? Py_True : Py_False); - } - Py_INCREF(result); - return result; -} - -PyObject * -mdb_VSFreeValue(PyObject *self, PyObject *args) -{ - PyObject *result = Py_None; - MDBValueStruct *vs; - PyObject *vsObj; - unsigned long index; - - if (PyArg_ParseTuple(args, "lO", &index, &vsObj)) { - vs = PyCObject_AsVoidPtr(vsObj); - result = (MDBFreeValue(index, vs) ? Py_True : Py_False); - } - Py_INCREF(result); - return result; -} - -PyObject * -mdb_VSFreeValues(PyObject *self, PyObject *args) -{ - PyObject *result = Py_None; - MDBValueStruct *vs; - PyObject *vsObj; - - if (PyArg_ParseTuple(args, "O", &vsObj)) { - vs = PyCObject_AsVoidPtr(vsObj); - result = (MDBFreeValues(vs) ? Py_True : Py_False); - } - Py_INCREF(result); - return result; -} - -PyObject * -mdb_VSSetContext(PyObject *self, PyObject *args) -{ - PyObject *result = Py_None; - unsigned char *context; - MDBValueStruct *vs; - PyObject *vsObj; - - if (PyArg_ParseTuple(args, "zO", &context, &vsObj)) { - vs = PyCObject_AsVoidPtr(vsObj); - result = (MDBSetValueStructContext(context, vs) ? Py_True : Py_False); - } - Py_INCREF(result); - return result; -} - -PyObject * -mdb_ShareContext(PyObject *self, PyObject *args) -{ - PyObject *result = NULL; - MDBValueStruct *oldvs; - PyObject *oldvsObj; - MDBValueStruct *newvs; - - if (PyArg_ParseTuple(args, "O", &oldvsObj)) { - oldvsObj = PyCObject_AsVoidPtr(oldvsObj); - newvs = MDBShareContext(oldvs); - result = PyCObject_FromVoidPtr(newvs, NULL); - } - return result; -} - -PyObject * -mdb_CreateEnumStruct(PyObject *self, PyObject *args) -{ - PyObject *result = NULL; - MDBValueStruct *vs; - PyObject *vsObj = Py_None; - MDBEnumStruct *es; - MDBHandle handle; - PyObject *handleObj; - - if (PyArg_ParseTuple(args, "O|O", &handleObj, &vsObj)) { - if(vsObj == Py_None) { - handle = PyCObject_AsVoidPtr(handleObj); - vs = MDBCreateValueStruct(handle, NULL); - } else { - vs = PyCObject_AsVoidPtr(vsObj); - } - if(vs) { - es = MDBCreateEnumStruct(vs); - result = PyCObject_FromVoidPtr(es, NULL); - } - if(vsObj == Py_None) { - MDBDestroyValueStruct(vs); - } - } - return result; -} - -PyObject * -mdb_DestroyEnumStruct(PyObject *self, PyObject *args) -{ - PyObject *result = Py_None; - MDBValueStruct *vs; - PyObject *vsObj = Py_None; - MDBEnumStruct *es; - PyObject *esObj; - MDBHandle handle; - PyObject *handleObj; - - if (PyArg_ParseTuple(args, "OO|O", &handleObj, &esObj, &vsObj)) { - es = PyCObject_AsVoidPtr(esObj); - if(vsObj == Py_None) { - handle = PyCObject_AsVoidPtr(handleObj); - vs = MDBCreateValueStruct(handle, NULL); - } else { - vs = PyCObject_AsVoidPtr(vsObj); - } - if(vs) { - result = (MDBDestroyEnumStruct(es, vs) ? Py_True : Py_False); - } - if(vsObj == Py_None) { - MDBDestroyValueStruct(vs); - } - } - Py_INCREF(result); - return result; -} - -PyObject * -mdb_Read(PyObject *self, PyObject *args) -{ - PyObject *result = NULL; - MDBHandle handle; - PyObject *handleObj; - unsigned char *object; - unsigned char *attribute; - MDBValueStruct *vs; - PyObject *vsObj = Py_None; - long val; - - if (PyArg_ParseTuple(args, "Ozz|O", &handleObj, - &object, &attribute, &vsObj)) { - if(vsObj == Py_None) { - handle = PyCObject_AsVoidPtr(handleObj); - vs = MDBCreateValueStruct(handle, NULL); - } else { - vs = PyCObject_AsVoidPtr(vsObj); - } - if(vs) { - val = MDBRead(object, attribute, vs); - result = Py_BuildValue("l", val); - } - if(vsObj == Py_None) { - MDBDestroyValueStruct(vs); - } - } - return result; -} - -PyObject * -mdb_ReadEx(PyObject *self, PyObject *args) -{ - PyObject *result = NULL; - MDBHandle handle; - PyObject *handleObj; - unsigned char *object; - unsigned char *attribute; - MDBEnumStruct *es; - PyObject *esObj; - MDBValueStruct *vs; - PyObject *vsObj = Py_None; - const unsigned char *val; - - if (PyArg_ParseTuple(args, "OzzO|O", &handleObj, - &object, &attribute, &esObj, &vsObj)) { - if(vsObj == Py_None) { - handle = PyCObject_AsVoidPtr(handleObj); - vs = MDBCreateValueStruct(handle, NULL); - } else { - vs = PyCObject_AsVoidPtr(vsObj); - } - if(vs) { - es = PyCObject_AsVoidPtr(esObj); - val = MDBReadEx(object, attribute, es, vs); - result = Py_BuildValue("z", val); - } - if(vsObj == Py_None) { - MDBDestroyValueStruct(vs); - } - } - return result; -} - -PyObject * -mdb_ReadDN(PyObject *self, PyObject *args) -{ - PyObject *result = NULL; - MDBHandle handle; - PyObject *handleObj; - unsigned char *object; - unsigned char *attribute; - MDBValueStruct *vs; - PyObject *vsObj = Py_None; - long val; - - if (PyArg_ParseTuple(args, "Ozz|O", &handleObj, - &object, &attribute, &vsObj)) { - if(vsObj == Py_None) { - handle = PyCObject_AsVoidPtr(handleObj); - vs = MDBCreateValueStruct(handle, NULL); - } else { - vs = PyCObject_AsVoidPtr(vsObj); - } - if(vs) { - val = MDBReadDN(object, attribute, vs); - result = Py_BuildValue("l", val); - } - if(vsObj == Py_None) { - MDBDestroyValueStruct(vs); - } - } - return result; -} - -PyObject * -mdb_Write(PyObject *self, PyObject *args) -{ - PyObject *result = Py_None; - MDBHandle handle; - PyObject *handleObj; - unsigned char *object; - unsigned char *attribute; - MDBValueStruct *vs; - PyObject *vsObj = Py_None; - - if (PyArg_ParseTuple(args, "Ozz|O", &handleObj, - &object, &attribute, &vsObj)) { - if(vsObj == Py_None) { - handle = PyCObject_AsVoidPtr(handleObj); - vs = MDBCreateValueStruct(handle, NULL); - } else { - vs = PyCObject_AsVoidPtr(vsObj); - } - if(vs) { - result = (MDBWrite(object, attribute, vs) ? Py_True : Py_False); - } - if(vsObj == Py_None) { - MDBDestroyValueStruct(vs); - } - } - Py_INCREF(result); - return result; -} - -PyObject * -mdb_WriteTyped(PyObject *self, PyObject *args) -{ - PyObject *result = Py_None; - MDBHandle handle; - PyObject *handleObj; - unsigned char *object; - unsigned char *attribute; - int attrtype; - MDBValueStruct *vs; - PyObject *vsObj = Py_None; - - if (PyArg_ParseTuple(args, "Ozzi|O", &handleObj, - &object, &attribute, &attrtype, &vsObj)) { - if(vsObj == Py_None) { - handle = PyCObject_AsVoidPtr(handleObj); - vs = MDBCreateValueStruct(handle, NULL); - } else { - vs = PyCObject_AsVoidPtr(vsObj); - } - if(vs) { - result = (MDBWriteTyped(object, attribute, attrtype, vs) ? - Py_True : Py_False); - } - if(vsObj == Py_None) { - MDBDestroyValueStruct(vs); - } - } - Py_INCREF(result); - return result; -} - -PyObject * -mdb_WriteDN(PyObject *self, PyObject *args) -{ - PyObject *result = Py_None; - MDBHandle handle; - PyObject *handleObj; - unsigned char *object; - unsigned char *attribute; - MDBValueStruct *vs; - PyObject *vsObj = Py_None; - - if (PyArg_ParseTuple(args, "Ozz|O", &handleObj, - &object, &attribute, &vsObj)) { - if(vsObj == Py_None) { - handle = PyCObject_AsVoidPtr(handleObj); - vs = MDBCreateValueStruct(handle, NULL); - } else { - vs = PyCObject_AsVoidPtr(vsObj); - } - if(vs) { - result = (MDBWriteDN(object, attribute, vs) ? Py_True : Py_False); - } - if(vsObj == Py_None) { - MDBDestroyValueStruct(vs); - } - } - Py_INCREF(result); - return result; -} - -PyObject * -mdb_Clear(PyObject *self, PyObject *args) -{ - PyObject *result = Py_None; - MDBHandle handle; - PyObject *handleObj; - unsigned char *object; - unsigned char *attribute; - MDBValueStruct *vs; - PyObject *vsObj = Py_None; - - if (PyArg_ParseTuple(args, "Ozz|O", &handleObj, - &object, &attribute, &vsObj)) { - if(vsObj == Py_None) { - handle = PyCObject_AsVoidPtr(handleObj); - vs = MDBCreateValueStruct(handle, NULL); - } else { - vs = PyCObject_AsVoidPtr(vsObj); - } - if(vs) { - result = (MDBClear(object, attribute, vs) ? Py_True : Py_False); - } - if(vsObj == Py_None) { - MDBDestroyValueStruct(vs); - } - } - Py_INCREF(result); - return result; -} - -PyObject * -mdb_Add(PyObject *self, PyObject *args) -{ - PyObject *result = Py_None; - MDBHandle handle; - PyObject *handleObj; - unsigned char *object; - unsigned char *attribute; - unsigned char *value; - MDBValueStruct *vs; - PyObject *vsObj = Py_None; - - if (PyArg_ParseTuple(args, "Ozzz|O", &handleObj, - &object, &attribute, &value, &vsObj)) { - if(vsObj == Py_None) { - handle = PyCObject_AsVoidPtr(handleObj); - vs = MDBCreateValueStruct(handle, NULL); - } else { - vs = PyCObject_AsVoidPtr(vsObj); - } - if(vs) { - result = (MDBAdd(object, attribute, value, vs) ? - Py_True : Py_False); - } - if(vsObj == Py_None) { - MDBDestroyValueStruct(vs); - } - } - Py_INCREF(result); - return result; -} - -PyObject * -mdb_AddDN(PyObject *self, PyObject *args) -{ - PyObject *result = Py_None; - MDBHandle handle; - PyObject *handleObj; - unsigned char *object; - unsigned char *attribute; - unsigned char *value; - MDBValueStruct *vs; - PyObject *vsObj = Py_None; - - if (PyArg_ParseTuple(args, "Ozzz|O", &handleObj, - &object, &attribute, &value, &vsObj)) { - if(vsObj == Py_None) { - handle = PyCObject_AsVoidPtr(handleObj); - vs = MDBCreateValueStruct(handle, NULL); - } else { - vs = PyCObject_AsVoidPtr(vsObj); - } - if(vs) { - result = (MDBAddDN(object, attribute, value, vs) ? Py_True : Py_False); - } - if(vsObj == Py_None) { - MDBDestroyValueStruct(vs); - } - } - Py_INCREF(result); - return result; -} - -PyObject * -mdb_Remove(PyObject *self, PyObject *args) -{ - PyObject *result = Py_None; - MDBHandle handle; - PyObject *handleObj; - unsigned char *object; - unsigned char *attribute; - unsigned char *value; - MDBValueStruct *vs; - PyObject *vsObj = Py_None; - - if (PyArg_ParseTuple(args, "Ozzz|O", &handleObj, - &object, &attribute, &value, &vsObj)) { - if(vsObj == Py_None) { - handle = PyCObject_AsVoidPtr(handleObj); - vs = MDBCreateValueStruct(handle, NULL); - } else { - vs = PyCObject_AsVoidPtr(vsObj); - } - if(vs) { - result = (MDBRemove(object, attribute, value, vs) ? - Py_True : Py_False); - } - if(vsObj == Py_None) { - MDBDestroyValueStruct(vs); - } - } - Py_INCREF(result); - return result; -} - -PyObject * -mdb_RemoveDN(PyObject *self, PyObject *args) -{ - PyObject *result = Py_None; - MDBHandle handle; - PyObject *handleObj; - unsigned char *object; - unsigned char *attribute; - unsigned char *value; - MDBValueStruct *vs; - PyObject *vsObj = Py_None; - - if (PyArg_ParseTuple(args, "Ozzz|O", &handleObj, - &object, &attribute, &value, &vsObj)) { - if(vsObj == Py_None) { - handle = PyCObject_AsVoidPtr(handleObj); - vs = MDBCreateValueStruct(handle, NULL); - } else { - vs = PyCObject_AsVoidPtr(vsObj); - } - if(vs) { - result = (MDBRemoveDN(object, attribute, value, vs) ? - Py_True : Py_False); - } - if(vsObj == Py_None) { - MDBDestroyValueStruct(vs); - } - } - Py_INCREF(result); - return result; -} - -PyObject * -mdb_IsObject(PyObject *self, PyObject *args) -{ - PyObject *result = Py_None; - MDBHandle handle; - PyObject *handleObj; - unsigned char *object; - MDBValueStruct *vs; - PyObject *vsObj = Py_None; - - if (PyArg_ParseTuple(args, "Oz|O", &handleObj, &object, &vsObj)) { - if(vsObj == Py_None) { - handle = PyCObject_AsVoidPtr(handleObj); - vs = MDBCreateValueStruct(handle, NULL); - } else { - vs = PyCObject_AsVoidPtr(vsObj); - } - if(vs) { - result = (MDBIsObject(object, vs) ? Py_True : Py_False); - } - if(vsObj == Py_None) { - MDBDestroyValueStruct(vs); - } - } - Py_INCREF(result); - return result; -} - -PyObject * -mdb_GetObjectDetails_Type(PyObject *self, PyObject *args) -{ - PyObject *result = NULL; - MDBHandle handle; - PyObject *handleObj; - unsigned char *object; - MDBValueStruct *vs; - PyObject *vsObj = Py_None; - unsigned char val[MDB_MAX_OBJECT_CHARS]; - - if (PyArg_ParseTuple(args, "Oz|O", &handleObj, &object, &vsObj)) { - if(vsObj == Py_None) { - handle = PyCObject_AsVoidPtr(handleObj); - vs = MDBCreateValueStruct(handle, NULL); - } else { - vs = PyCObject_AsVoidPtr(vsObj); - } - if(vs) { - if (MDBGetObjectDetails(object, val, NULL, NULL, vs)) { - result = Py_BuildValue("z", val); - } - } - if(vsObj == Py_None) { - MDBDestroyValueStruct(vs); - } - } - return result; -} - -PyObject * -mdb_GetObjectDetails_RDN(PyObject *self, PyObject *args) -{ - PyObject *result = NULL; - MDBHandle handle; - PyObject *handleObj; - unsigned char *object; - MDBValueStruct *vs; - PyObject *vsObj = Py_None; - unsigned char val[MDB_MAX_OBJECT_CHARS]; - - if (PyArg_ParseTuple(args, "Oz|O", &handleObj, &object, &vsObj)) { - if(vsObj == Py_None) { - handle = PyCObject_AsVoidPtr(handleObj); - vs = MDBCreateValueStruct(handle, NULL); - } else { - vs = PyCObject_AsVoidPtr(vsObj); - } - if(vs) { - if (MDBGetObjectDetails(object, NULL, val, NULL, vs)) { - result = Py_BuildValue("z", val); - } - } - if(vsObj == Py_None) { - MDBDestroyValueStruct(vs); - } - } - return result; -} - -PyObject * -mdb_GetObjectDetails_DN(PyObject *self, PyObject *args) -{ - PyObject *result = NULL; - MDBHandle handle; - PyObject *handleObj; - unsigned char *object; - MDBValueStruct *vs; - PyObject *vsObj = Py_None; - unsigned char val[MDB_MAX_OBJECT_CHARS]; - - if (PyArg_ParseTuple(args, "Oz|O", &handleObj, &object, &vsObj)) { - if(vsObj == Py_None) { - handle = PyCObject_AsVoidPtr(handleObj); - vs = MDBCreateValueStruct(handle, NULL); - } else { - vs = PyCObject_AsVoidPtr(vsObj); - } - if(vs) { - if (MDBGetObjectDetails(object, NULL, NULL, val, vs)) { - result = Py_BuildValue("z", val); - } - } - if(vsObj == Py_None) { - MDBDestroyValueStruct(vs); - } - } - return result; -} - -PyObject * -mdb_VerifyPassword(PyObject *self, PyObject *args) -{ - PyObject *result = Py_None; - MDBHandle handle; - PyObject *handleObj; - unsigned char *user; - unsigned char *pass; - MDBValueStruct *vs; - PyObject *vsObj = Py_None; - - if (PyArg_ParseTuple(args, "Ozz|O", &handleObj, &user, &pass, &vsObj)) { - if(user == NULL || pass == NULL) { - Py_INCREF(Py_False); - return Py_False; - } - - if(vsObj == Py_None) { - handle = PyCObject_AsVoidPtr(handleObj); - vs = MDBCreateValueStruct(handle, NULL); - } else { - vs = PyCObject_AsVoidPtr(vsObj); - } - if(vs) { - result = (MDBVerifyPassword(user, pass, vs) ? Py_True : Py_False); - } - if(vsObj == NULL) { - MDBDestroyValueStruct(vs); - } - } - Py_INCREF(result); - return result; -} - -PyObject * -mdb_VerifyPasswordEx(PyObject *self, PyObject *args) -{ - PyObject *result = Py_None; - MDBHandle handle; - PyObject *handleObj; - unsigned char *user; - unsigned char *pass; - MDBValueStruct *vs; - PyObject *vsObj = Py_None; - - if (PyArg_ParseTuple(args, "Ozz|O", &handleObj, &user, &pass, &vsObj)) { - if(vsObj == Py_None) { - handle = PyCObject_AsVoidPtr(handleObj); - vs = MDBCreateValueStruct(handle, NULL); - } else { - vs = PyCObject_AsVoidPtr(vsObj); - } - if(vs) { - result = (MDBVerifyPasswordEx(user, pass, vs) ? - Py_True : Py_False); - } - if(vsObj == Py_None) { - MDBDestroyValueStruct(vs); - } - } - Py_INCREF(result); - return result; -} - -PyObject * -mdb_ChangePassword(PyObject *self, PyObject *args) -{ - PyObject *result = Py_None; - MDBHandle handle; - PyObject *handleObj; - unsigned char *object; - unsigned char *oldpass; - unsigned char *newpass; - MDBValueStruct *vs; - PyObject *vsObj = Py_None; - - if (PyArg_ParseTuple(args, "Ozzz|O", &handleObj, - &object, &oldpass, &newpass, &vsObj)) { - if(vsObj == Py_None) { - handle = PyCObject_AsVoidPtr(handleObj); - vs = MDBCreateValueStruct(handle, NULL); - } else { - vs = PyCObject_AsVoidPtr(vsObj); - } - if(vs) { - result = (MDBChangePassword(object, oldpass, newpass, vs) ? - Py_True : Py_False); - } - if(vsObj == Py_None) { - MDBDestroyValueStruct(vs); - } - } - Py_INCREF(result); - return result; -} - -PyObject * -mdb_ChangePasswordEx(PyObject *self, PyObject *args) -{ - PyObject *result = Py_None; - MDBHandle handle; - PyObject *handleObj; - unsigned char *object; - unsigned char *oldpass; - unsigned char *newpass; - MDBValueStruct *vs; - PyObject *vsObj = Py_None; - - if (PyArg_ParseTuple(args, "Ozzz|O", &handleObj, - &object, &oldpass, &newpass, &vsObj)) { - if(vsObj == Py_None) { - handle = PyCObject_AsVoidPtr(handleObj); - vs = MDBCreateValueStruct(handle, NULL); - } else { - vs = PyCObject_AsVoidPtr(vsObj); - } - if(vs) { - result = (MDBChangePasswordEx(object, oldpass, newpass, vs) ? - Py_True : Py_False); - } - if(vsObj == Py_None) { - MDBDestroyValueStruct(vs); - } - } - Py_INCREF(result); - return result; -} - -PyObject * -mdb_EnumerateObjects(PyObject *self, PyObject *args) -{ - PyObject *result = NULL; - MDBHandle handle; - PyObject *handleObj; - unsigned char *container; - unsigned char *type; - unsigned char *pattern; - MDBValueStruct *vs; - PyObject *vsObj = Py_None; - long val; - - if (PyArg_ParseTuple(args, "Ozzz|O", &handleObj, - &container, &type, &pattern, &vsObj)) { - if(vsObj == Py_None) { - handle = PyCObject_AsVoidPtr(handleObj); - vs = MDBCreateValueStruct(handle, NULL); - } else { - vs = PyCObject_AsVoidPtr(vsObj); - } - if(vs) { - val = MDBEnumerateObjects(container, type, pattern, vs); - result = Py_BuildValue("l", val); - } - if(vsObj == Py_None) { - MDBDestroyValueStruct(vs); - } - } - return result; -} - -PyObject * -mdb_EnumerateObjectsEx(PyObject *self, PyObject *args) -{ - PyObject *result = NULL; - MDBHandle handle; - PyObject *handleObj; - unsigned char *container; - unsigned char *type; - unsigned char *pattern; - long flags; - MDBEnumStruct *es; - PyObject *esObj; - MDBValueStruct *vs; - PyObject *vsObj = Py_None; - const unsigned char *val; - - if (PyArg_ParseTuple(args, "OzzzlO|O", &handleObj, &container, - &type, &pattern, &flags, &esObj, &vsObj)) { - if(vsObj == Py_None) { - vs = MDBCreateValueStruct(handle, NULL); - } else { - handle = PyCObject_AsVoidPtr(handleObj); - vs = PyCObject_AsVoidPtr(vsObj); - } - if(vs) { - es = PyCObject_AsVoidPtr(esObj); - val = MDBEnumerateObjectsEx(container, type, pattern, flags, - es, vs); - result = Py_BuildValue("z", val); - } - if(vsObj == Py_None) { - MDBDestroyValueStruct(vs); - } - } - return result; -} - -PyObject * -mdb_EnumerateAttributesEx(PyObject *self, PyObject *args) -{ - PyObject *result = NULL; - MDBHandle handle; - PyObject *handleObj; - unsigned char *object; - MDBEnumStruct *es; - PyObject *esObj; - MDBValueStruct *vs; - PyObject *vsObj = Py_None; - const unsigned char *val; - - if (PyArg_ParseTuple(args, "OzO|O", &handleObj, &object, &esObj, &vsObj)) { - if(vsObj == Py_None) { - handle = PyCObject_AsVoidPtr(handleObj); - vs = MDBCreateValueStruct(handle, NULL); - } else { - vs = PyCObject_AsVoidPtr(vsObj); - } - if(vs) { - es = PyCObject_AsVoidPtr(esObj); - val = MDBEnumerateAttributesEx(object, es, vs); - result = Py_BuildValue("z", val); - } - if(vsObj == Py_None) { - MDBDestroyValueStruct(vs); - } - } - return result; -} - -PyObject * -mdb_CreateObject(PyObject *self, PyObject *args) -{ - PyObject *result = Py_None; - MDBHandle handle; - PyObject *handleObj; - unsigned char *object; - unsigned char *class; - MDBValueStruct *vsattr; - PyObject *vsattrObj; - MDBValueStruct *vsdata; - PyObject *vsdataObj; - MDBValueStruct *vs; - PyObject *vsObj = Py_None; - - if (PyArg_ParseTuple(args, "OzzOO|O", &handleObj, - &object, &class, &vsattrObj, &vsdataObj, &vsObj)) { - if(vsObj == Py_None) { - handle = PyCObject_AsVoidPtr(handleObj); - vs = MDBCreateValueStruct(handle, NULL); - } else { - vs = PyCObject_AsVoidPtr(vsObj); - } - if(vs) { - vsattr = PyCObject_AsVoidPtr(vsattrObj); - vsdata = PyCObject_AsVoidPtr(vsdataObj); - result = (MDBCreateObject(object, class, vsattr, vsdata, vs) ? - Py_True : Py_False); - } - if(vsObj == Py_None) { - MDBDestroyValueStruct(vs); - } - } - Py_INCREF(result); - return result; -} - -PyObject * -mdb_DeleteObject(PyObject *self, PyObject *args) -{ - PyObject *result = Py_None; - MDBHandle handle; - PyObject *handleObj; - unsigned char *object; - int recursive; - MDBValueStruct *vs; - PyObject *vsObj = Py_None; - - if (PyArg_ParseTuple(args, "Ozi|O", &handleObj, - &object, &recursive, &vsObj)) { - if(vsObj == Py_None) { - handle = PyCObject_AsVoidPtr(handleObj); - vs = MDBCreateValueStruct(handle, NULL); - } else { - vs = PyCObject_AsVoidPtr(vsObj); - } - if(vs) { - result = (MDBDeleteObject(object, (recursive ? TRUE : FALSE), vs) ? - Py_True : Py_False); - } - if(vsObj == Py_None) { - MDBDestroyValueStruct(vs); - } - } - Py_INCREF(result); - return result; -} - -PyObject * -mdb_RenameObject(PyObject *self, PyObject *args) -{ - PyObject *result = Py_None; - MDBHandle handle; - PyObject *handleObj; - unsigned char *oldobject; - unsigned char *newobject; - MDBValueStruct *vs; - PyObject *vsObj = Py_None; - - if (PyArg_ParseTuple(args, "Ozz|O", &handleObj, - &oldobject, &newobject, &vsObj)) { - if(vsObj == Py_None) { - handle = PyCObject_AsVoidPtr(handleObj); - vs = MDBCreateValueStruct(handle, NULL); - } else { - vs = PyCObject_AsVoidPtr(vsObj); - } - if(vs) { - result = (MDBRenameObject(oldobject, newobject, vs) ? - Py_True : Py_False); - } - if(vsObj == Py_None) { - MDBDestroyValueStruct(vs); - } - } - Py_INCREF(result); - return result; -} - -PyObject * -mdb_DefineAttribute(PyObject *self, PyObject *args) -{ - PyObject *result = Py_None; - MDBHandle handle; - PyObject *handleObj; - unsigned char *attribute; - unsigned char *asn1; - long type; - int singleval; - int immediatesync; - int public; - MDBValueStruct *vs; - PyObject *vsObj = Py_None; - - if (PyArg_ParseTuple(args, "Ozzliii|O", &handleObj, &attribute, &asn1, - &type, &singleval, &immediatesync, &public, &vsObj)) { - if(vsObj == Py_None) { - handle = PyCObject_AsVoidPtr(handleObj); - vs = MDBCreateValueStruct(handle, NULL); - } else { - vs = PyCObject_AsVoidPtr(vsObj); - } - if(vs) { - result = (MDBDefineAttribute(attribute, asn1, type, - (singleval ? TRUE : FALSE), - (immediatesync ? TRUE : FALSE), - (public ? TRUE : FALSE), vs) ? - Py_True : Py_False); - } - if(vsObj == Py_None) { - MDBDestroyValueStruct(vs); - } - } - Py_INCREF(result); - return result; -} - -PyObject * -mdb_UndefineAttribute(PyObject *self, PyObject *args) -{ - PyObject *result = Py_None; - MDBHandle handle; - PyObject *handleObj; - unsigned char *attribute; - MDBValueStruct *vs; - PyObject *vsObj = Py_None; - - if (PyArg_ParseTuple(args, "Oz|O", &handleObj, &attribute, &vs)) { - if(vsObj == Py_None) { - handle = PyCObject_AsVoidPtr(handleObj); - vs = MDBCreateValueStruct(handle, NULL); - } else { - vs = PyCObject_AsVoidPtr(vsObj); - } - if(vs) { - result = (MDBUndefineAttribute(attribute, vs) ? - Py_True : Py_False); - } - if(vsObj == Py_None) { - MDBDestroyValueStruct(vs); - } - } - Py_INCREF(result); - return result; -} - -PyObject * -mdb_AddAttribute(PyObject *self, PyObject *args) -{ - PyObject *result = Py_None; - MDBHandle handle; - PyObject *handleObj; - unsigned char *attribute; - unsigned char *class; - MDBValueStruct *vs; - PyObject *vsObj = Py_None; - - if (PyArg_ParseTuple(args, "Ozz|O", &handleObj, - &attribute, &class, &vsObj)) { - if(vsObj == Py_None) { - handle = PyCObject_AsVoidPtr(handleObj); - vs = MDBCreateValueStruct(handle, NULL); - } else { - vs = PyCObject_AsVoidPtr(vsObj); - } - if(vs) { - result = (MDBAddAttribute(attribute, class, vs) ? - Py_True : Py_False); - } - if(vsObj == Py_None) { - MDBDestroyValueStruct(vs); - } - } - Py_INCREF(result); - return result; -} - -PyObject * -mdb_DefineClass(PyObject *self, PyObject *args) -{ - PyObject *result = Py_None; - MDBHandle handle; - PyObject *handleObj; - unsigned char *class; - unsigned char *asn1; - int container; - MDBValueStruct *superclass; - PyObject *superclassObj; - MDBValueStruct *containment; - PyObject *containmentObj; - MDBValueStruct *naming; - PyObject *namingObj; - MDBValueStruct *mandatory; - PyObject *mandatoryObj; - MDBValueStruct *optional; - PyObject *optionalObj; - MDBValueStruct *vs; - PyObject *vsObj = Py_None; - - if (PyArg_ParseTuple(args, "OzziOOOOO|O", &handleObj, - &class, &asn1, &container, - &superclassObj, &containmentObj, &namingObj, - &mandatoryObj, &optionalObj, &vsObj)) { - if(vsObj == Py_None) { - handle = PyCObject_AsVoidPtr(handleObj); - vs = MDBCreateValueStruct(handle, NULL); - } else { - vs = PyCObject_AsVoidPtr(vsObj); - } - if(vs) { - superclass = PyCObject_AsVoidPtr(superclassObj); - containment = PyCObject_AsVoidPtr(containmentObj); - naming = PyCObject_AsVoidPtr(namingObj); - mandatory = PyCObject_AsVoidPtr(mandatoryObj); - optional = PyCObject_AsVoidPtr(optionalObj); - result = (MDBDefineClass(class, asn1, (container ? TRUE : FALSE), - superclass, containment, naming, - mandatory, optional, vs) ? - Py_True : Py_False); - } - if(vsObj == Py_None) { - MDBDestroyValueStruct(vs); - } - } - Py_INCREF(result); - return result; -} - -PyObject * -mdb_UndefineClass(PyObject *self, PyObject *args) -{ - PyObject *result = Py_None; - MDBHandle handle; - PyObject *handleObj; - unsigned char *class; - MDBValueStruct *vs; - PyObject *vsObj = Py_None; - - if (PyArg_ParseTuple(args, "Oz|O", &handleObj, &class, &vsObj)) { - if(vsObj == Py_None) { - handle = PyCObject_AsVoidPtr(handleObj); - vs = MDBCreateValueStruct(handle, NULL); - } else { - vs = PyCObject_AsVoidPtr(vsObj); - } - if(vs) { - result = (MDBUndefineClass(class, vs) ? Py_True : Py_False); - } - if(vsObj == Py_None) { - MDBDestroyValueStruct(vs); - } - } - Py_INCREF(result); - return result; -} - -PyObject * -mdb_ListContainableClasses(PyObject *self, PyObject *args) -{ - PyObject *result = Py_None; - MDBHandle handle; - PyObject *handleObj; - unsigned char *container; - MDBValueStruct *vs; - PyObject *vsObj = Py_None; - - if (PyArg_ParseTuple(args, "Oz|O", &handleObj, &container, &vsObj)) { - if(vsObj == Py_None) { - handle = PyCObject_AsVoidPtr(handleObj); - vs = MDBCreateValueStruct(handle, NULL); - } else { - vs = PyCObject_AsVoidPtr(vsObj); - } - if(vs) { - result = (MDBListContainableClasses(container, vs) ? - Py_True : Py_False); - } - if(vsObj == Py_None) { - MDBDestroyValueStruct(vs); - } - } - Py_INCREF(result); - return result; -} - -PyObject * -mdb_ListContainableClassesEx(PyObject *self, PyObject *args) -{ - PyObject *result = NULL; - MDBHandle handle; - PyObject *handleObj; - unsigned char *container; - MDBEnumStruct *es; - PyObject *esObj; - MDBValueStruct *vs; - PyObject *vsObj = Py_None; - const unsigned char* val = NULL; - - if (PyArg_ParseTuple(args, "OzO|O", &container, &esObj, &vsObj)) { - if(vsObj == Py_None) { - handle = PyCObject_AsVoidPtr(handleObj); - vs = MDBCreateValueStruct(handle, NULL); - } else { - vs = PyCObject_AsVoidPtr(vsObj); - } - if(vs) { - es = PyCObject_AsVoidPtr(esObj); - val = MDBListContainableClassesEx(container, es, vs); - result = Py_BuildValue("z", val); - } - if(vsObj == Py_None) { - MDBDestroyValueStruct(vs); - } - } - return result; -} - -PyObject * -mdb_GrantObjectRights(PyObject *self, PyObject *args) -{ - PyObject *result = Py_None; - MDBHandle handle; - PyObject *handleObj; - unsigned char *object; - unsigned char *trusteedn; - int read; - int write; - int delete; - int rename; - int admin; - MDBValueStruct *vs; - PyObject *vsObj = Py_None; - - if (PyArg_ParseTuple(args, "Ozziiiii|O", &handleObj, &object, &trusteedn, - &read, &write, &delete, &rename, &admin, &vsObj)) { - if(vsObj == Py_None) { - handle = PyCObject_AsVoidPtr(handleObj); - vs = MDBCreateValueStruct(handle, NULL); - } else { - vs = PyCObject_AsVoidPtr(vsObj); - } - if(vs) { - result = (MDBGrantObjectRights(object, trusteedn, - (read ? TRUE : FALSE), - (write ? TRUE : FALSE), - (delete ? TRUE : FALSE), - (rename ? TRUE : FALSE), - (admin ? TRUE : FALSE), vs) ? - Py_True : Py_False); - } - if(vsObj == Py_None) { - MDBDestroyValueStruct(vs); - } - } - Py_INCREF(result); - return result; -} - -PyObject * -mdb_GrantAttributeRights(PyObject *self, PyObject *args) -{ - PyObject *result = Py_None; - MDBHandle handle; - PyObject *handleObj; - unsigned char *object; - unsigned char *attribute; - unsigned char *trusteedn; - int read; - int write; - int admin; - MDBValueStruct *vs; - PyObject *vsObj = Py_None; - - if (PyArg_ParseTuple(args, "Ozzziii|O", &handleObj, - &object, &attribute, &trusteedn, - &read, &write, &admin, &vsObj)) { - if(vsObj == Py_None) { - handle = PyCObject_AsVoidPtr(handleObj); - vs = MDBCreateValueStruct(handle, NULL); - } else { - vs = PyCObject_AsVoidPtr(vsObj); - } - if(vs) { - result = (MDBGrantAttributeRights(object, attribute, trusteedn, - (read ? TRUE : FALSE), - (write ? TRUE : FALSE), - (admin ? TRUE : FALSE), vs) ? - Py_True : Py_False); - } - if(vsObj == Py_None) { - MDBDestroyValueStruct(vs); - } - } - Py_INCREF(result); - return result; -} - -PyObject * -mdb_DumpValueStruct(PyObject *self, PyObject *args) -{ - PyObject *result = Py_None; - MDBValueStruct *vs; - PyObject *vsObj; - - if (PyArg_ParseTuple(args, "O", &vsObj)) { - vs = PyCObject_AsVoidPtr(vsObj); - result = (MDBDumpValueStruct(vs) ? Py_True : Py_False); - } - Py_INCREF(result); - return result; -} - -#ifdef __cplusplus -} -#endif