diff --git a/src/libs/mdb-file/Bongo.rules b/src/libs/mdb-file/Bongo.rules deleted file mode 100644 index fa75cae..0000000 --- a/src/libs/mdb-file/Bongo.rules +++ /dev/null @@ -1,19 +0,0 @@ -# -*- Makefile -*- -mdb_LTLIBRARIES += libmdbfile.la - -libmdbfile_la_SOURCES = \ - src/libs/mdb-file/mdbfile.c \ - src/libs/mdb-file/mdbfilep.h - -libmdbfile_la_CPPFLAGS = $(AM_CPPFLAGS) \ - -DLOCALSTATEDIR=\""$(localstatedir)"\" \ - -DMDB_INTERNAL - -libmdbfile_la_LDFLAGS = -module -avoid-version -libmdbfile_la_LIBADD = \ - libbongoutil.la \ - libbongomemmgr.la \ - libbongoxpl.la - -src/libs/mdb-file/all: libmdbfile.la -src/libs/mdb-file/clean: clean diff --git a/src/libs/mdb-file/Makefile.am b/src/libs/mdb-file/Makefile.am deleted file mode 100644 index 8830401..0000000 --- a/src/libs/mdb-file/Makefile.am +++ /dev/null @@ -1,17 +0,0 @@ -# -*- Makefile -*- -# -# Do not edit! -# -# (unless this is Makefile.am.subdir) -# -# This file is a copy of the toplevel Makefile.am.subdir. If changes -# need to be made, edit that file, and make update-makefiles, and -# check the new files in. -# -# This is a skeletal automake file. The real automake fules for -# building the targets for this directory can be found in the -# Bongo.rules file. This file is simply here so that 'make all' can -# work in each subdirectory. - -all clean install: - @cd $(top_builddir) && $(MAKE) $(MFLAGS) $(subdir)/$@ diff --git a/src/libs/mdb-file/mdbfile.c b/src/libs/mdb-file/mdbfile.c deleted file mode 100644 index 956d05e..0000000 --- a/src/libs/mdb-file/mdbfile.c +++ /dev/null @@ -1,3998 +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. - * - */ - -/* Product defines */ -#define PRODUCT_NAME "MDB Filesystem Driver" -#define PRODUCT_VERSION "$Revision: 1.1 $" - -#include -#include -#include - -#include -#include - -#include "mdbfilep.h" -#include - -#define ChopNL(String) { register unsigned char *p = strchr((String), 0x0a); if (p) {*p = '\0'; if (*(p - 1) == 0x0d) {*(p - 1)='\0'; }}} - -#if !defined(DEBUG) -#define LogMessage if (MDBFile.log.enabled) MDBFILELogMessage -#else -#define LogMessage MDBFILELogMessage -#endif - -typedef struct _MDBFILESchemaAttribute { - unsigned long flags; - unsigned long syntax; - - unsigned char asn1[36]; - unsigned char name[MDB_MAX_ATTRIBUTE_CHARS]; - unsigned char filename[(XPL_MAX_PATH * 3) + 1]; - unsigned char buffer[VALUE_BUFFER_SIZE]; -} MDBFILESchemaAttribute; - -typedef struct _MDBFILESchemaClass { - unsigned long flags; - - unsigned char asn1[256]; - unsigned char name[MDB_MAX_OBJECT_CHARS]; - unsigned char filename[(XPL_MAX_PATH * 3) + 1]; - unsigned char buffer[VALUE_BUFFER_SIZE]; - - MDBValueStruct *defaultACL; - MDBValueStruct *superClass; - MDBValueStruct *contains; - MDBValueStruct *containedBy; - MDBValueStruct *naming; - MDBValueStruct *mandatory; - MDBValueStruct *optional; -} MDBFILESchemaClass; - -struct { - BOOL unload; - - struct { - XplSemaphore shutdown; - } sem; - - struct { - XplThreadID main; - XplThreadID group; - } id; - - unsigned char localTree[MDB_MAX_TREE_CHARS + 1]; - unsigned char replicaDN[MDB_MAX_OBJECT_CHARS + 1]; - unsigned char root[XPL_MAX_PATH + 1]; - unsigned char schema[XPL_MAX_PATH + 1]; - unsigned char base64Chars[66]; - - unsigned int rootLength; - - struct { - BOOL enabled; - BOOL console; - - FILE *fh; - - XplSemaphore sem; - - int bufferSize; - - unsigned char *buffer; - } log; - - MDBHandle directoryHandle; - - struct { - MDBFILEContextStruct **data; - unsigned long used; - unsigned long allocated; - XplSemaphore sem; - } handles; -} MDBFile; - -/* - Prototypes for registration functions -*/ -BOOL MDBFILEGetServerInfo(unsigned char *ServerDN, unsigned char *ServerTree, MDBValueStruct *V); -char *MDBFILEGetBaseDN(MDBValueStruct *V); -MDBHandle MDBFILEAuthenticateFunction(const unsigned char *Object, const unsigned char *Password, const unsigned char *Arguments); -BOOL MDBFILERelease(MDBHandle Context); -MDBValueStruct *MDBFILECreateValueStruct(MDBHandle Handle, const unsigned char *Context); -BOOL MDBFILEFreeValues(MDBValueStruct *V); -BOOL MDBFILEDestroyValueStruct(MDBValueStruct *V); -MDBEnumStruct *MDBFILECreateEnumStruct(MDBValueStruct *V); -BOOL MDBFILEDestroyEnumStruct(MDBEnumStruct *ES, MDBValueStruct *V); -BOOL MDBFILESetValueStructContext(const unsigned char *Context, MDBValueStruct *V); -MDBValueStruct *MDBFILEShareContext(MDBValueStruct *V); -BOOL MDBFILEAddValue(const unsigned char *Value, MDBValueStruct *V); -BOOL MDBFILEFreeValue(unsigned long Index, MDBValueStruct *V); -BOOL MDBFILEDefineAttribute(const unsigned char *Attribute, const unsigned char *ASN1, unsigned long Type, BOOL SingleValue, BOOL ImmediateSync, BOOL Public, MDBValueStruct *V); -BOOL MDBFILEAddAttribute(const unsigned char *Attribute, const unsigned char *Class, MDBValueStruct *V); -BOOL MDBFILEUndefineAttribute(const unsigned char *Attribute, MDBValueStruct *V); -BOOL MDBFILEDefineClass(const unsigned char *Class, const unsigned char *ASN1, BOOL Container, MDBValueStruct *Superclass, MDBValueStruct *Containment, MDBValueStruct *Naming, MDBValueStruct *Mandatory, MDBValueStruct *Optional, MDBValueStruct *V); -BOOL MDBFILEUndefineClass(const unsigned char *Class, MDBValueStruct *V); -BOOL MDBFILEListContainableClasses(const unsigned char *Object, MDBValueStruct *V); -BOOL MDBFILEOpenStream(const unsigned char *Object, const unsigned char *AttributeIn, MDBValueStruct *V); -BOOL MDBFILEReadStream(MDBValueStruct *V); -BOOL MDBFILEWriteStream(MDBValueStruct *V); -BOOL MDBFILECloseStream(MDBValueStruct *V); -BOOL MDBFILEWriteTyped(const unsigned char *Object, const unsigned char *Attribute, const int AttrType, MDBValueStruct *V); -BOOL MDBFILEWrite(const unsigned char *Object, const unsigned char *AttributeIn, MDBValueStruct *V); -BOOL MDBFILEWriteDN(const unsigned char *Object, const unsigned char *AttributeIn, MDBValueStruct *V); -BOOL MDBFILEAdd(const unsigned char *Object, const unsigned char *Attribute, const unsigned char *Value, MDBValueStruct *V); -BOOL MDBFILEAddDN(const unsigned char *Object, const unsigned char *Attribute, const unsigned char *Value, MDBValueStruct *V); -BOOL MDBFILERemove(const unsigned char *Object, const unsigned char *Attribute, const unsigned char *Value, MDBValueStruct *V); -BOOL MDBFILERemoveDN(const unsigned char *Object, const unsigned char *Attribute, const unsigned char *Value, MDBValueStruct *V); -BOOL MDBFILEClear(const unsigned char *Object, const unsigned char *Attribute, MDBValueStruct *V); -BOOL MDBFILEIsObject(const unsigned char *Object, MDBValueStruct *V); -BOOL MDBFILEGetObjectDetails(const unsigned char *Object, unsigned char *Type, unsigned char *RDN, unsigned char *DN, MDBValueStruct *V); -BOOL MDBFILEGetObjectDetailsEx(const unsigned char *Object, MDBValueStruct *Types, unsigned char *RDN, unsigned char *DN, MDBValueStruct *V); -BOOL MDBFILEVerifyPassword(const unsigned char *Object, const unsigned char *Password, MDBValueStruct *V); -BOOL MDBFILEChangePassword(const unsigned char *Object, const unsigned char *OldPassword, const unsigned char *NewPassword, MDBValueStruct *V); -BOOL MDBFILEChangePasswordEx(const unsigned char *Object, const unsigned char *OldPassword, const unsigned char *NewPassword, MDBValueStruct *V); -BOOL MDBFILECreateAlias(const unsigned char *Alias, const unsigned char *AliasedObjectDn, MDBValueStruct *V); -BOOL MDBFILECreateObject(const unsigned char *Object, const unsigned char *Class, MDBValueStruct *Attribute, MDBValueStruct *Data, MDBValueStruct *V); -BOOL MDBFILEDeleteObject(const unsigned char *Object, BOOL Recursive, MDBValueStruct *V); -BOOL MDBFILERenameObject(const unsigned char *ObjectOld, const unsigned char *ObjectNew, MDBValueStruct *V); -BOOL MDBFILEGrantObjectRights(const unsigned char *Object, const unsigned char *TrusteeDN, BOOL Read, BOOL Write, BOOL Delete, BOOL Rename, BOOL Admin, MDBValueStruct *V); -BOOL MDBFILEGrantAttributeRights(const unsigned char *Object, const unsigned char *Attribute, const unsigned char *TrusteeDN, BOOL Read, BOOL Write, BOOL Admin, MDBValueStruct *V); -BOOL MDBFILEAddAddressRestriction(const unsigned char *Object, const unsigned char *Server, MDBValueStruct *V); - -const unsigned char *MDBFILEListContainableClassesEx(const unsigned char *Object, MDBEnumStruct *E, MDBValueStruct *V); -const unsigned char *MDBFILEReadEx(const unsigned char *Object, const unsigned char *Attribute, MDBEnumStruct *E, MDBValueStruct *V); -const unsigned char *MDBFILEEnumerateAttributesEx(const unsigned char *Object, MDBEnumStruct *E, MDBValueStruct *V); -const unsigned char *MDBFILEEnumerateObjectsEx(const unsigned char *Container, const unsigned char *Type, const unsigned char *Pattern, unsigned long Flags, MDBEnumStruct *E, MDBValueStruct *V); - -long MDBFILERead(const unsigned char *Object, const unsigned char *Attribute, MDBValueStruct *V); -long MDBFILEReadDN(const unsigned char *Object, const unsigned char *Attribute, MDBValueStruct *V); -long MDBFILEEnumerateObjects(const unsigned char *Container, const unsigned char *Type, const unsigned char *Pattern, MDBValueStruct *V); - -EXPORT BOOL MDBFILEInit(MDBDriverInitStruct *Init); -EXPORT void MDBFILEShutdown(void); - -static void -MDBFILELogMessage(const unsigned char *Format, ...) -{ - if (MDBFile.log.enabled) { - int length; - va_list arguments; - - XplWaitOnLocalSemaphore(MDBFile.log.sem); - - va_start(arguments, Format); - vsprintf(MDBFile.log.buffer, Format, arguments); - va_end(arguments); - - length = strlen(MDBFile.log.buffer); - - fwrite(MDBFile.log.buffer, sizeof(unsigned char), length, MDBFile.log.fh); - - if (MDBFile.log.console) { - fwrite(MDBFile.log.buffer, sizeof(unsigned char), length, stdout); - } - - XplSignalLocalSemaphore(MDBFile.log.sem); - } - - return; -} - -static int -MDBFILEEncodePathname(const unsigned char *Source, unsigned char *Destination, unsigned char **EndNode) -{ - register const unsigned char *src = Source; - register unsigned char *dest = Destination; - - do { - if (islower(*src)) { - *dest++ = *src++; - - continue; - } - - if (isupper(*src)) { - *dest++ = tolower(*src++); - - continue; - } - - if ((*src == '/') || (*src == '\\')) { - if (EndNode) { - *EndNode = dest; - } - - *dest++ = '/'; - src++; - - continue; - } - - dest += sprintf(dest, "%%%03d", *src); - src++; - } while (*src); - - *dest = '\0'; - - return(dest - Destination); -} - -static int -MDBFILEClassToFilename(const unsigned char *Class, unsigned char *Filename) -{ - register const unsigned char *src = Class; - register unsigned char *dest = Filename; - - dest += sprintf(dest, "%s/classes/", MDBFile.schema); - - dest += MDBFILEEncodePathname(src, dest, NULL); - - return(dest - Filename); -} - -static int -MDBFILEAttributeToFilename(const unsigned char *Attribute, unsigned char *Filename) -{ - register const unsigned char *src = Attribute; - register unsigned char *dest = Filename; - - dest += sprintf(dest, "%s/attributes/", MDBFile.schema); - - dest += MDBFILEEncodePathname(src, dest, NULL); - - return(dest - Filename); -} - -static int -MDBFILEObjectToFilename(const unsigned char *Object, const unsigned char *Attribute, unsigned char *Filename, MDBValueStruct *V, unsigned char **EndNode) -{ - unsigned char path[XPL_MAX_PATH + 1]; - register unsigned char *src = path; - register unsigned char *dest = Filename; - - if (Object) { - if (Object[0] != '\\') { - if (V) { - src += sprintf(src, "%s\\%s", V->BaseDN, Object); - } else { - src += sprintf(src, "%s\\%s", MDBFile.localTree, Object); - } - } else { - src += sprintf(src, "%s", Object); - } - - memcpy(dest, MDBFile.root, MDBFile.rootLength); - dest += MDBFile.rootLength; - } - - if (Attribute) { - src += sprintf(src, "\\%s", Attribute); - } - - src = path; - - dest += MDBFILEEncodePathname(src, dest, EndNode); - - return(dest - Filename); -} - -static BOOL -MDBFILEFilenameToObjectDN(unsigned char *Filename, unsigned char *DN, unsigned char **RDN) -{ - unsigned char *node = Filename; - unsigned char *dn = DN; - unsigned char *delim; - unsigned char *oDelim; - unsigned char *sDelim; - unsigned char buffer[MDB_MAX_OBJECT_CHARS]; - unsigned char oPath[(XPL_MAX_PATH * 4) + 1]; - unsigned char sPath[(XPL_MAX_PATH * 4) + 1]; - FILE *oHandle; - FILE *sHandle; - BOOL result = TRUE; - - if (RDN) { - *RDN = NULL; - } - - oDelim = oPath + sprintf(oPath, "%s", MDBFile.root); - sDelim = sPath + sprintf(sPath, "%s/classes/", MDBFile.schema); - - node = Filename + MDBFile.rootLength; - while (result && node) { - *dn++ = '\\'; - - if (RDN) { - *RDN = dn; - } - - delim = strchr(++node, '/'); - if (delim) { - *delim = '\0'; - } - - *oDelim++ = '/'; - strcpy(oDelim, node); - oDelim += strlen(node); - *oDelim++ = '/'; - - result = FALSE; - - strcpy(oDelim, "object%032class"); - oHandle = fopen(oPath, "rb"); - if (oHandle) { - if (fgets(buffer, sizeof(buffer), oHandle)) { - ChopNL(buffer); - - MDBFILEEncodePathname(buffer, sDelim, NULL); - - result = TRUE; - } - - fclose(oHandle); - } - - if (result) { - result = FALSE; - - strcat(sDelim, "/naming"); - sHandle = fopen(sPath, "rb"); - if (sHandle) { - if (fgets(buffer, sizeof(buffer), sHandle)) { - ChopNL(buffer); - - MDBFILEEncodePathname(buffer, oDelim, NULL); - - result = TRUE; - } - - fclose(sHandle); - } - } - - if (result) { - result = FALSE; - - oHandle = fopen(oPath, "rb"); - if (oHandle) { - if (fgets(dn, MDB_MAX_OBJECT_CHARS, oHandle)) { - ChopNL(dn); - - dn += strlen(dn); - - result = TRUE; - } - - fclose(oHandle); - } - } - - if (delim) { - *delim = '/'; - } - - node = delim; - } - - return(result); -} - -// Converts a filename based attribute name to its real name -// e.g. 'object%032class' -> 'Object Class' -// input: Filename - takes a filename syntax 'cn' -// returns: DN - corrected syntax attribute name - -static BOOL -MDBFILEFilenameToAttributeName(unsigned char *Filename, unsigned char *attrname) -{ - unsigned char *node = Filename; - unsigned char *attr = attrname; - unsigned char *delim; - unsigned char *sDelim; - unsigned char buffer[MDB_MAX_OBJECT_CHARS]; - unsigned char sPath[(XPL_MAX_PATH * 4) + 1]; - FILE *sHandle; - BOOL result = TRUE; - - sDelim = sPath + sprintf(sPath, "%s/attributes/", MDBFile.schema); - - while (result && node) { - - delim = strchr(++node, '/'); - if (delim) { - *delim = '\0'; - } - // get the /naming value from the scheme (e.g. cn, ou) - if (result) { - result = FALSE; - - strcpy(sDelim, Filename); - strcat(sDelim, "/name"); - - sHandle = fopen(sPath, "rb"); - if (sHandle) { - if (fgets(buffer, sizeof(buffer), sHandle)) { - ChopNL(buffer); - - strcpy(attr,buffer); - attr+= strlen(attr); - - result = TRUE; - } - - fclose(sHandle); - } - } - - if (delim) { - *delim = '/'; - } - - node = delim; - } - - return(result); -} - - -static __inline BOOL -MDBFileIsValidHandle(MDBHandle Handle) -{ - unsigned long i; - - for (i = 0; i < MDBFile.handles.used; i++) { - if ((Handle) == (void *)MDBFile.handles.data[i]) { - return(TRUE); - } - } - - return(FALSE); -} - -static __inline BOOL -MDBFileIsReadWrite(MDBValueStruct *V) -{ - if (!V->Handle->ReadOnly) { - return(TRUE); - } else { - unsigned char *e = strrchr(V->Filename, '/'); - - /* Return TRUE for the object that created the handle. */ - return(e && (unsigned)(e - V->Filename) == (unsigned)strlen(V->Handle->Dirname) && - XplStrNCaseCmp(V->Handle->Dirname, V->Filename, e - V->Filename) == 0); - } -} - - -BOOL -MDBFILEGetServerInfo(unsigned char *ServerDN, unsigned char *ServerTree, MDBValueStruct *V) -{ - if (ServerDN) { - strcpy(ServerDN, "Unknown"); - } - - if (ServerTree) { - strcpy(ServerTree, MDBFile.localTree + 1); - } - - return(TRUE); -} - -char * -MDBFILEGetBaseDN(MDBValueStruct *V) -{ - return(MDBFile.localTree); -} - - -static __inline MDBHandle -MDBFileCreateContext(unsigned char *Dirname, BOOL ReadOnly) -{ - MDBFILEContextStruct *handle; - - /* Create a new context */ - handle = malloc(sizeof(MDBFILEContextStruct)); - - strcpy(handle->Dirname, Dirname); - handle->ReadOnly = ReadOnly; - - XplWaitOnLocalSemaphore(MDBFile.handles.sem); - - /* Add the handle to the the list of handles, so that it can be verified later */ - if ((MDBFile.handles.used + 1) > MDBFile.handles.allocated) { - void *ptr = realloc(MDBFile.handles.data, (MDBFile.handles.allocated + 100) * sizeof(MDBFILEContextStruct *)); - - if (ptr) { - MDBFile.handles.data = ptr; - MDBFile.handles.allocated += 100; - } - } - - if ((MDBFile.handles.used + 1) <= MDBFile.handles.allocated) { - MDBFile.handles.data[MDBFile.handles.used] = handle; - MDBFile.handles.used++; - - XplSignalLocalSemaphore(MDBFile.handles.sem); - - return((void *)handle); - } - - XplSignalLocalSemaphore(MDBFile.handles.sem); - - return(NULL); -} - -BOOL MDBFILERelease(MDBHandle Context) -{ - unsigned long i; - - for (i = 0; i < MDBFile.handles.used; i++) { - if (Context == (void *)MDBFile.handles.data[i]) { - /* Free the context */ - XplWaitOnLocalSemaphore(MDBFile.handles.sem); - - free(MDBFile.handles.data[i]); - - if (i < (MDBFile.handles.used - 1)) { - memmove(&MDBFile.handles.data[i], &MDBFile.handles.data[i + 1], - ((MDBFile.handles.used - 1) - i) * sizeof(MDBFILEContextStruct *)); - } - - MDBFile.handles.used--; - - XplSignalLocalSemaphore(MDBFile.handles.sem); - - return(TRUE); - } - } - - return(FALSE); -} - - -MDBValueStruct * -MDBFILECreateValueStruct(MDBHandle Handle, const unsigned char *Context) -{ - MDBValueStruct *v = NULL; - - if (MDBFileIsValidHandle(Handle)) { - v = malloc(sizeof(MDBValueStruct)); - if (v) { - memset(v, 0, sizeof(MDBValueStruct)); - - v->Flags = MDB_FLAGS_CONTEXT_VALID; - v->BaseDN = malloc(XPL_MAX_PATH + 1); - v->Handle = Handle; - - if (!Context) { - sprintf(v->BaseDN, "%s", MDBFile.localTree); - } else { - if (*Context != '\\') { - sprintf(v->BaseDN, "%s\\%s", MDBFile.localTree, Context); - } else { - strcpy(v->BaseDN, Context); - } - - v->Flags |= MDB_FLAGS_BASEDN_CHANGED; - } - } - } - - return(v); -} - -BOOL -MDBFILEFreeValues(MDBValueStruct *V) -{ - register unsigned long i; - - if (V->Allocated) { - for (i = 0; i < V->Used; i++) { - free(V->Value[i]); - } - - if (V->Allocated > VALUE_ALLOC_SIZE) { - if (V->Value) { - free(V->Value); - } - - V->Allocated = 0; - V->Value = NULL; - } - - V->Used = 0; - } - - return(TRUE); -} - -BOOL -MDBFILEDestroyValueStruct(MDBValueStruct *V) -{ - if (V && MDB_CONTEXT_IS_VALID(V)) { - if (!(V->Flags & MDB_FLAGS_CONTEXT_DUPLICATE)) { - free(V->BaseDN); - } - - if (V->Allocated) { - MDBFILEFreeValues(V); - - if (V->Value) { - free(V->Value); - } - } - - free(V); - - return(TRUE); - } - - return(FALSE); -} - -MDBEnumStruct *MDBFILECreateEnumStruct(MDBValueStruct *V) -{ - MDBEnumStruct *es = NULL; - - if (V && MDB_CONTEXT_IS_VALID(V)) { - es = malloc(sizeof(MDBEnumStruct)); - if (es) { - es->Initialized = FALSE; - - es->EntriesLeft = 0; - - es->File = NULL; - es->V = NULL; - } - } - - return(es); -} - -BOOL MDBFILEDestroyEnumStruct(MDBEnumStruct *ES, MDBValueStruct *V) -{ - if (ES) { - if (ES->Initialized) { - if (ES->File) { - fclose(ES->File); - } - - if (ES->V) { - MDBFILEDestroyValueStruct(ES->V); - } - } - - free(ES); - - return(TRUE); - } - - return(FALSE); -} - -BOOL MDBFILESetValueStructContext(const unsigned char *Context, MDBValueStruct *V) -{ - if (V && MDB_CONTEXT_IS_VALID(V)) { - if (!Context || (*Context == '\0')) { - sprintf(V->BaseDN, "%s", MDBFile.localTree); - } else { - if (*Context != '\\') { - sprintf(V->BaseDN, "%s\\%s", MDBFile.localTree, Context); - } else { - strcpy(V->BaseDN, Context); - } - - V->Flags |= MDB_FLAGS_BASEDN_CHANGED; - } - - return(TRUE); - } - - return(FALSE); -} - -MDBValueStruct *MDBFILEShareContext(MDBValueStruct *V) -{ - MDBValueStruct *n = NULL; - - if (V && MDB_CONTEXT_IS_VALID(V)) { - n = malloc(sizeof(MDBValueStruct)); - if (n) { - memset(n, 0, sizeof(MDBValueStruct)); - - n->Flags = MDB_FLAGS_CONTEXT_DUPLICATE | V->Flags; - n->BaseDN = V->BaseDN; - n->Handle = V->Handle; - } - } - - return(n); -} - -BOOL MDBFILEAddValue(const unsigned char *Value, MDBValueStruct *V) -{ - register unsigned char *ptr; - - if (Value && (*Value != '\0')) { - if ((V->Used + 1) > V->Allocated) { - ptr = (unsigned char *)realloc(V->Value, (V->Allocated + VALUE_ALLOC_SIZE) * sizeof(unsigned char *)); - if (ptr) { - V->Value = (unsigned char **)ptr; - V->Allocated += VALUE_ALLOC_SIZE; - } else { - if (V->Allocated) { - MDBFILEFreeValues(V); - - if (V->Value) { - free(V->Value); - } - } - - V->Value = NULL; - - V->Used = 0; - V->Allocated = 0; - - return(FALSE); - } - } - - ptr = strdup(Value); - if (ptr) { - V->Value[V->Used] = ptr; - V->Used++; - - return(TRUE); - } - } - - return(FALSE); -} - -BOOL MDBFILEFreeValue(unsigned long Index, MDBValueStruct *V) -{ - if (Index < V->Used) { - free(V->Value[Index]); - - if (Index < (V->Used - 1)) { - memmove(&V->Value[Index], &V->Value[Index + 1], ((V->Used - 1) - Index) * sizeof(unsigned char *)); - } - - V->Used--; - - return(TRUE); - } - - return(FALSE); -} - -static MDBFILESchemaAttribute * -MDBFILELoadSchemaAttribute(const unsigned char *Attribute) -{ - unsigned char *ptr; - FILE *handle; - struct stat buf; - MDBFILESchemaAttribute *a = NULL; - - a = (MDBFILESchemaAttribute *)malloc(sizeof(MDBFILESchemaAttribute)); - if (a) { - a->flags = 0; - a->syntax = MDB_ATTR_SYN_STRING; - a->asn1[0] = '\0'; - - strcpy(a->name, Attribute); - - ptr = a->filename + MDBFILEAttributeToFilename(Attribute, a->filename); - if (stat(a->filename, &buf) == 0) { - strcpy(ptr, "/name"); - handle = fopen(a->filename, "rb"); - if (handle) { - if (fgets(a->name, sizeof(a->name), handle)) { - ChopNL(a->name); - } - - fclose(handle); - } - - strcpy(ptr, "/flags"); - handle = fopen(a->filename, "rb"); - if (handle) { - if (fgets(a->buffer, sizeof(a->buffer), handle)) { - a->flags = atol(a->buffer); - } - - fclose(handle); - } - - strcpy(ptr, "/syntax"); - handle = fopen(a->filename, "rb"); - if (handle) { - if (fgets(a->buffer, sizeof(a->buffer), handle)) { - a->syntax = atol(a->buffer); - } - - fclose(handle); - } - - strcpy(ptr, "/asn1"); - handle = fopen(a->filename, "rb"); - if (handle) { - fgets(a->asn1, sizeof(a->asn1), handle); - - fclose(handle); - } - } - - *ptr = '\0'; - } - - return(a); -} - -static void -MDBFILECreatePath(unsigned char *Filename) -{ - register unsigned char *ptr; - register unsigned char *ptr2; - struct stat buf; - - if (stat(Filename, &buf) != 0) { - ptr = strchr(Filename, '/'); - - while (ptr) { - *ptr = '\0'; - - if (stat(Filename, &buf) != 0) { - XplMakeDir(Filename); - } - - *ptr = '/'; - ptr2 = ptr; - ptr = strchr(ptr2 + 1, '/'); - } - - if (stat(Filename, &buf) != 0) { - XplMakeDir(Filename); - } - } - - return; -} - -static BOOL -MDBFILESaveSchemaAttribute(MDBFILESchemaAttribute *Attribute) -{ - unsigned char *ptr; - FILE *handle; - - MDBFILECreatePath(Attribute->filename); - - ptr = Attribute->filename + strlen(Attribute->filename); - - strcpy(ptr, "/name"); - handle = fopen(Attribute->filename, "wb"); - if (handle && fprintf(handle, "%s\r\n", Attribute->name)) { - fclose(handle); - } else { - if (handle) { - fclose(handle); - } - - unlink(Attribute->filename); - } - - strcpy(ptr, "/flags"); - handle = fopen(Attribute->filename, "wb"); - if (handle && fprintf(handle, "%lu\r\n", Attribute->flags)) { - fclose(handle); - } else { - if (handle) { - fclose(handle); - } - - unlink(Attribute->filename); - } - - strcpy(ptr, "/syntax"); - handle = fopen(Attribute->filename, "wb"); - if (handle && fprintf(handle, "%lu\r\n", Attribute->syntax)) { - fclose(handle); - } else { - if (handle) { - fclose(handle); - } - - unlink(Attribute->filename); - } - - if (Attribute->asn1[0]) { - strcpy(ptr, "/asn1"); - handle = fopen(Attribute->filename, "wb"); - if (handle && fprintf(handle, "%s\r\n", Attribute->asn1)) { - fclose(handle); - } else { - if (handle) { - fclose(handle); - } - - unlink(Attribute->filename); - } - } - - *ptr = '\0'; - - return(TRUE); -} - -static void -MDBFILEFreeSchemaAttribute(MDBFILESchemaAttribute *Attribute) -{ - if (Attribute) { - free(Attribute); - } - - return; -} - -static void -MDBFILEFreeSchemaClass(MDBFILESchemaClass *Class) -{ - if (Class) { - if (Class->optional) { - MDBFILEDestroyValueStruct(Class->optional); - } - - if (Class->mandatory) { - MDBFILEDestroyValueStruct(Class->mandatory); - } - - if (Class->naming) { - MDBFILEDestroyValueStruct(Class->naming); - } - - if (Class->containedBy) { - MDBFILEDestroyValueStruct(Class->containedBy); - } - - if (Class->contains) { - MDBFILEDestroyValueStruct(Class->contains); - } - - if (Class->superClass) { - MDBFILEDestroyValueStruct(Class->superClass); - } - - if (Class->defaultACL) { - MDBFILEDestroyValueStruct(Class->defaultACL); - } - - free(Class); - } - - return; -} - -static MDBFILESchemaClass * -MDBFILELoadSchemaClass(const unsigned char *Class) -{ - unsigned char *ptr; - FILE *handle; - MDBFILESchemaClass *c = NULL; - struct stat buf; - - c = (MDBFILESchemaClass *)malloc(sizeof(MDBFILESchemaClass)); - if (c) { - c->flags = 0; - c->asn1[0] = '\0'; - - c->defaultACL = MDBFILECreateValueStruct(MDBFile.directoryHandle, NULL); - if (c->defaultACL != NULL) { - c->superClass = MDBFILEShareContext(c->defaultACL); - c->containedBy = MDBFILEShareContext(c->defaultACL); - c->contains = MDBFILEShareContext(c->defaultACL); - c->naming = MDBFILEShareContext(c->defaultACL); - c->mandatory = MDBFILEShareContext(c->defaultACL); - c->optional = MDBFILEShareContext(c->defaultACL); - - if (c->superClass && c->containedBy && c->contains && c->naming && c->mandatory && c->optional) { - strcpy(c->name, Class); - } else { - MDBFILEFreeSchemaClass(c); - - return(NULL); - } - } else { - free(c); - - return(NULL); - } - - ptr = c->filename + MDBFILEClassToFilename(Class, c->filename); - if (stat(c->filename, &buf) == 0) { - strcpy(ptr, "/name"); - handle = fopen(c->filename, "rb"); - if (handle) { - if (fgets(c->name, sizeof(c->name), handle)) { - ChopNL(c->name); - } - - fclose(handle); - } - - strcpy(ptr, "/flags"); - handle = fopen(c->filename, "rb"); - if (handle) { - if (fgets(c->buffer, sizeof(c->buffer), handle)) { - c->flags = atol(c->buffer); - } - - fclose(handle); - } - - strcpy(ptr, "/asn1"); - handle = fopen(c->filename, "rb"); - if (handle) { - fgets(c->asn1, sizeof(c->asn1), handle); - - c->asn1[256] = '\0'; - - fclose(handle); - } - } else { - return(c); - } - - strcpy(ptr, "/defaultacl"); - handle = fopen(c->filename, "rb"); - if (handle) { - while (!feof(handle) && !ferror(handle)) { - if (fgets(c->buffer, sizeof(c->buffer), handle)) { - ChopNL(c->buffer); - - MDBFILEAddValue(c->buffer, c->defaultACL); - } - } - - fclose(handle); - } - - strcpy(ptr, "/superclass"); - handle = fopen(c->filename, "rb"); - if (handle) { - while (!feof(handle) && !ferror(handle)) { - if (fgets(c->buffer, sizeof(c->buffer), handle)) { - ChopNL(c->buffer); - - MDBFILEAddValue(c->buffer, c->superClass); - } - } - - fclose(handle); - } - - strcpy(ptr, "/containedby"); - handle = fopen(c->filename, "rb"); - if (handle) { - while (!feof(handle) && !ferror(handle)) { - if (fgets(c->buffer, sizeof(c->buffer), handle)) { - ChopNL(c->buffer); - - MDBFILEAddValue(c->buffer, c->containedBy); - } - } - - fclose(handle); - } - - strcpy(ptr, "/contains"); - handle = fopen(c->filename, "rb"); - if (handle) { - while (!feof(handle) && !ferror(handle)) { - if (fgets(c->buffer, sizeof(c->buffer), handle)) { - ChopNL(c->buffer); - - MDBFILEAddValue(c->buffer, c->contains); - } - } - - fclose(handle); - } - - strcpy(ptr, "/naming"); - handle = fopen(c->filename, "rb"); - if (handle) { - while (!feof(handle) && !ferror(handle)) { - if (fgets(c->buffer, sizeof(c->buffer), handle)) { - ChopNL(c->buffer); - - MDBFILEAddValue(c->buffer, c->naming); - } - } - - fclose(handle); - } - - strcpy(ptr, "/mandatory"); - handle = fopen(c->filename, "rb"); - if (handle) { - while (!feof(handle) && !ferror(handle)) { - if (fgets(c->buffer, sizeof(c->buffer), handle)) { - ChopNL(c->buffer); - - MDBFILEAddValue(c->buffer, c->mandatory); - } - } - - fclose(handle); - } - - strcpy(ptr, "/optional"); - handle = fopen(c->filename, "rb"); - if (handle) { - while (!feof(handle) && !ferror(handle)) { - if (fgets(c->buffer, sizeof(c->buffer), handle)) { - ChopNL(c->buffer); - - MDBFILEAddValue(c->buffer, c->optional); - } - } - - fclose(handle); - } - - *ptr = '\0'; - } - - return(c); -} - -static BOOL -MDBFILESaveSchemaClass(MDBFILESchemaClass *Class) -{ - unsigned long i; - unsigned char *ptr; - FILE *handle; - - MDBFILECreatePath(Class->filename); - - ptr = Class->filename + strlen(Class->filename); - - strcpy(ptr, "/name"); - handle = fopen(Class->filename, "wb"); - if (handle) { - fprintf(handle, "%s\r\n", Class->name); - fclose(handle); - } - - strcpy(ptr, "/flags"); - handle = fopen(Class->filename, "wb"); - if (handle) { - fprintf(handle, "%lu\r\n", Class->flags); - fclose(handle); - } - - if (Class->asn1[0] != '\0') { - strcpy(ptr, "/asn1"); - handle = fopen(Class->filename, "rb"); - if (handle) { - fprintf(handle, "%s\r\n", Class->asn1); - fclose(handle); - } - } - - if (Class->defaultACL->Used) { - strcpy(ptr, "/defaultacl"); - handle = fopen(Class->filename, "wb"); - if (handle) { - for (i = 0; i < Class->defaultACL->Used; i++) { - fprintf(handle, "%s\r\n", Class->defaultACL->Value[i]); - } - - fclose(handle); - } - } - - if (Class->superClass->Used) { - strcpy(ptr, "/superclass"); - handle = fopen(Class->filename, "wb"); - if (handle) { - for (i = 0; i < Class->superClass->Used; i++) { - fprintf(handle, "%s\r\n", Class->superClass->Value[i]); - } - - fclose(handle); - } - } - - if (Class->containedBy->Used) { - strcpy(ptr, "/containedby"); - handle = fopen(Class->filename, "wb"); - if (handle) { - for (i = 0; i < Class->containedBy->Used; i++) { - fprintf(handle, "%s\r\n", Class->containedBy->Value[i]); - } - - fclose(handle); - } - } else { - LogMessage("[%04d] MDBSaveSchemaClass(\"%s\") has no containment.\r\n", __LINE__, Class->name); - } - - if (Class->contains->Used) { - strcpy(ptr, "/contains"); - handle = fopen(Class->filename, "wb"); - if (handle) { - for (i = 0; i < Class->contains->Used; i++) { - fprintf(handle, "%s\r\n", Class->contains->Value[i]); - } - - fclose(handle); - } - } - - if (Class->naming->Used) { - strcpy(ptr, "/naming"); - handle = fopen(Class->filename, "wb"); - if (handle) { - for (i = 0; i < Class->naming->Used; i++) { - fprintf(handle, "%s\r\n", Class->naming->Value[i]); - } - - fclose(handle); - } - } else { - LogMessage("[%04d] MDBSaveSchemaClass(\"%s\") has no naming.\r\n", __LINE__, Class->name); - } - - if (Class->mandatory->Used) { - strcpy(ptr, "/mandatory"); - handle = fopen(Class->filename, "wb"); - if (handle) { - for (i = 0; i < Class->mandatory->Used; i++) { - fprintf(handle, "%s\r\n", Class->mandatory->Value[i]); - } - - fclose(handle); - } - } - - if (Class->optional->Used) { - strcpy(ptr, "/optional"); - handle = fopen(Class->filename, "wb"); - if (handle) { - for (i = 0; i < Class->optional->Used; i++) { - fprintf(handle, "%s\r\n", Class->optional->Value[i]); - } - - fclose(handle); - } - } - - *ptr = '\0'; - - return(TRUE); -} - -MDBHandle -MDBFILEAuthenticateFunction(const unsigned char *Object, const unsigned char *Password, const unsigned char *Arguments) -{ - FILE *handle; - unsigned char *buffer; - unsigned char objectClass[VALUE_BUFFER_SIZE]; - unsigned char filename[(XPL_MAX_PATH * 3) + 1]; - BOOL result = FALSE; - struct stat sb; - - if (Object) { - MDBFILEObjectToFilename(Object, "Private Key", filename, NULL, NULL); - if (stat(filename, &sb) == 0) { - buffer = (unsigned char *)malloc(sb.st_size + 1); - if (buffer) { - handle = fopen(filename, "rb"); - if (handle) { - if (fread(buffer, sizeof(unsigned char), sb.st_size, handle) == (size_t)sb.st_size) { - buffer[sb.st_size] = '\0'; - - if (strcmp(Password, DecodeBase64(buffer)) == 0) { - result = TRUE; - } else { - LogMessage("[%04d] MDBAuthenticate() password was not correct\r\n", __LINE__); - } - } - - fclose(handle); - } - - free(buffer); - } - } else if (!Password || (Password[0] == '\0')) { - result = TRUE; - } else { - LogMessage("[%04d] MDBAuthenticate() could not access the password file and a password was specified.\r\n", __LINE__); - } - } else { - result = TRUE; - } - - if (result) { - unsigned char *e; - unsigned char classfile[(XPL_MAX_PATH * 3) + 1]; - BOOL readonly = TRUE; - MDBFILESchemaClass *c = NULL; - - /* - If the object authenticating is a user object, other than admin, - then that user is read only. - */ - - /* Get the class name */ - MDBFILEObjectToFilename(Object, "Object Class", classfile, NULL, NULL); - - handle = fopen(classfile, "rb"); - if (handle) { - while (!feof(handle) && !ferror(handle)) { - if (fgets(objectClass, sizeof(objectClass), handle)) { - ChopNL(objectClass); - - c = MDBFILELoadSchemaClass(objectClass); - - break; - } - } - - fclose(handle); - } - - if (Object) { - /* fixme - Set readonly=FALSE; for bongomanagers as well */ - - if ((c && (XplStrCaseCmp(c->name, "user") != 0)) || (XplStrCaseCmp(Object, "\\Tree\\Admin") == 0)) { - readonly = FALSE; - } - - /* Strip off the filename - we only need the dirname */ - e = strrchr(filename, '/'); - if (e) { - *e = '\0'; - } - - MDBFILEFreeSchemaClass(c); - - return((void *)MDBFileCreateContext(filename, readonly)); - } - - MDBFILEFreeSchemaClass(c); - - return((void *)MDBFileCreateContext("/", FALSE)); - } - - return(NULL); -} - -BOOL -MDBFILEDefineAttribute(const unsigned char *Attribute, const unsigned char *ASN1, unsigned long Type, BOOL SingleValue, BOOL ImmediateSync, BOOL Public, MDBValueStruct *V) -{ - BOOL result = FALSE; - MDBFILESchemaAttribute *a; - - if (V && MDB_CONTEXT_IS_VALID(V) && MDBFileIsValidHandle(V->Handle) && !V->Handle->ReadOnly) { - a = MDBFILELoadSchemaAttribute(Attribute); - if (a) { - if (SingleValue) { - a->flags |= 0x00000001; - } else { - a->flags &= ~0x00000001; - } - - if (ImmediateSync) { - a->flags |= 0x00000040; - } else { - a->flags &= ~0x00000040; - } - - if (Public) { - a->flags |= 0x00000080; - } else { - a->flags &= ~0x00000080; - } - - switch (Type) { - case MDB_ATTR_SYN_BOOL: { - /* 'B' */ - a->syntax = 7; - break; - } - - case MDB_ATTR_SYN_DIST_NAME: { - /* 'D' */ - a->syntax = 1; - break; - } - - case MDB_ATTR_SYN_BINARY: { - /* 'O' */ - a->syntax = 9; - break; - } - - case MDB_ATTR_SYN_STRING: { - /* 'S' */ - a->syntax = 3; - break; - } - - default: { - /* Unknown syntax */ - a->syntax = 0; - break; - } - } - - if (ASN1) { - strcpy(a->asn1, ASN1); - } else { - a->asn1[0] = '\0'; - } - - result = MDBFILESaveSchemaAttribute(a); - - MDBFILEFreeSchemaAttribute(a); - } - } - - return(result); -} - -BOOL -MDBFILEAddAttribute(const unsigned char *Attribute, const unsigned char *Class, MDBValueStruct *V) -{ - unsigned long i; - BOOL result = FALSE; - MDBFILESchemaClass *c; - - if (V && MDB_CONTEXT_IS_VALID(V) && MDBFileIsValidHandle(V->Handle) && !V->Handle->ReadOnly) { - c = MDBFILELoadSchemaClass(Class); - if (c) { - for (i = 0; i < c->optional->Used; i++) { - if (strcmp(Attribute, c->optional->Value[i]) != 0) { - continue; - } - - result = TRUE; - break; - } - - if (!result) { - MDBFILEAddValue(Attribute, c->optional); - - result = MDBFILESaveSchemaClass(c); - } - - MDBFILEFreeSchemaClass(c); - } - } - - return(result); -} - -BOOL -MDBFILEUndefineAttribute(const unsigned char *Attribute, MDBValueStruct *V) -{ - LogMessage("[%04d] MDBUndefineAttribute(\"%s\", ...) is not implemented\r\n", __LINE__, Attribute); - - return(FALSE); -} - -static void -MDBFILEInheritContainment(unsigned char *Superclass, MDBValueStruct *ContainedBy) -{ - unsigned long i; - unsigned long j; - BOOL found; - MDBFILESchemaClass *s; - - s = MDBFILELoadSchemaClass(Superclass); - if (s) { - if (s->containedBy && s->containedBy->Used) { - for (i = 0; i < s->containedBy->Used; i++) { - found = FALSE; - - for (j = 0; j < ContainedBy->Used; j++) { - if (XplStrCaseCmp(s->containedBy->Value[i], ContainedBy->Value[j]) != 0) { - continue; - } - - found = TRUE; - break; - } - - if (!found) { - LogMessage("[%04d] MDBFILEInheritContainment(\"%s\", ...) inheriting \"%s\".\r\n", __LINE__, Superclass, s->containedBy->Value[i]); - - MDBFILEAddValue(s->containedBy->Value[i], ContainedBy); - } - } - } else if (s->superClass && s->superClass->Used) { - MDBFILEInheritContainment(s->superClass->Value[0], ContainedBy); - } - - MDBFILEFreeSchemaClass(s); - } - - return; -} - -static void -MDBFILEInheritNaming(unsigned char *Superclass, MDBValueStruct *Naming) -{ - unsigned long i; - unsigned long j; - BOOL found; - MDBFILESchemaClass *s; - - s = MDBFILELoadSchemaClass(Superclass); - if (s) { - if (s->naming && s->naming->Used) { - for (i = 0; i < s->naming->Used; i++) { - found = FALSE; - - for (j = 0; j < Naming->Used; j++) { - if (XplStrCaseCmp(s->naming->Value[i], Naming->Value[j]) != 0) { - continue; - } - - found = TRUE; - break; - } - - if (!found) { - LogMessage("[%04d] MDBFILEInheritNaming(\"%s\", ...) inheriting \"%s\".\r\n", __LINE__, Superclass, s->naming->Value[i]); - - MDBFILEAddValue(s->naming->Value[i], Naming); - } - } - } else if (s->superClass && s->superClass->Used) { - MDBFILEInheritNaming(s->superClass->Value[0], Naming); - } - - MDBFILEFreeSchemaClass(s); - } - - return; -} - -static void -MDBFILEUpdateSchemaContainment(MDBFILESchemaClass *Class, MDBValueStruct *Superclass, MDBValueStruct *Containment) -{ - unsigned long i; - unsigned long j; - BOOL found; - MDBFILESchemaClass *s; - MDBFILESchemaClass *c; - - if (Containment && Containment->Used) { - for (i = 0; i < Containment->Used; i++) { - c = MDBFILELoadSchemaClass(Containment->Value[i]); - if (c) { - found = FALSE; - - for (j = 0; j < c->contains->Used; j++) { - if (XplStrCaseCmp(Class->name, c->contains->Value[j]) != 0) { - continue; - } - - found = TRUE; - break; - } - - if (!found) { - MDBFILEAddValue(Class->name, c->contains); - - MDBFILESaveSchemaClass(c); - } - - MDBFILEFreeSchemaClass(c); - } - } - } else if (Superclass && Superclass->Used) { - s = MDBFILELoadSchemaClass(Superclass->Value[0]); - if (s) { - MDBFILEUpdateSchemaContainment(Class, s->superClass, s->containedBy); - - MDBFILEFreeSchemaClass(s); - } - } - - return; -} - -BOOL -MDBFILEDefineClass(const unsigned char *Class, const unsigned char *ASN1, BOOL Container, MDBValueStruct *Superclass, MDBValueStruct *Containment, MDBValueStruct *Naming, MDBValueStruct *Mandatory, MDBValueStruct *Optional, MDBValueStruct *V) -{ - unsigned long i; - unsigned long j; - BOOL found; - BOOL result = FALSE; - MDBFILESchemaClass *c; - - if (V && MDB_CONTEXT_IS_VALID(V) && MDBFileIsValidHandle(V->Handle) && !V->Handle->ReadOnly) { - c = MDBFILELoadSchemaClass(Class); - if (c) { - if (Container) { - c->flags |= 0x00000003; - } else { - c->flags &= ~0x00000001; - } - - if (Superclass) { - for (i = 0; i < Superclass->Used; i++) { - found = FALSE; - - for (j = 0; j < c->superClass->Used; j++) { - if (XplStrCaseCmp(Superclass->Value[i], c->superClass->Value[j]) != 0) { - continue; - } - - found = TRUE; - break; - } - - if (!found) { - MDBFILEAddValue(Superclass->Value[i], c->superClass); - } - } - } - - if (Containment && Containment->Used) { - for (i = 0; i < Containment->Used; i++) { - found = FALSE; - - for (j = 0; j < c->containedBy->Used; j++) { - if (XplStrCaseCmp(Containment->Value[i], c->containedBy->Value[j]) != 0) { - continue; - } - - found = TRUE; - break; - } - - if (!found) { - MDBFILEAddValue(Containment->Value[i], c->containedBy); - } - } - } else if (c->superClass->Used) { - MDBFILEInheritContainment(c->superClass->Value[0], c->containedBy); - } - - if (Naming && Naming->Used) { - for (i = 0; i < Naming->Used; i++) { - found = FALSE; - - for (j = 0; j < c->naming->Used; j++) { - if (XplStrCaseCmp(Naming->Value[i], c->naming->Value[j]) != 0) { - continue; - } - - found = TRUE; - break; - } - - if (!found) { - MDBFILEAddValue(Naming->Value[i], c->naming); - } - } - } else if (c->superClass->Used) { - MDBFILEInheritNaming(c->superClass->Value[0], c->naming); - } - - if (Mandatory) { - for (i = 0; i < Mandatory->Used; i++) { - found = FALSE; - - for (j = 0; j < c->mandatory->Used; j++) { - if (XplStrCaseCmp(Mandatory->Value[i], c->mandatory->Value[j]) != 0) { - continue; - } - - found = TRUE; - break; - } - - if (!found) { - MDBFILEAddValue(Mandatory->Value[i], c->mandatory); - } - } - } - - if (Optional) { - for (i = 0; i < Optional->Used; i++) { - found = FALSE; - - for (j = 0; j < c->optional->Used; j++) { - if (XplStrCaseCmp(Optional->Value[i], c->optional->Value[j]) != 0) { - continue; - } - - found = TRUE; - break; - } - - if (!found) { - MDBFILEAddValue(Optional->Value[i], c->optional); - } - } - } - - result = MDBFILESaveSchemaClass(c); - if (result) { - MDBFILEUpdateSchemaContainment(c, Superclass, Containment); - } - - MDBFILEFreeSchemaClass(c); - } - } - - return(result); -} - -BOOL -MDBFILEUndefineClass(const unsigned char *Class, MDBValueStruct *V) -{ - LogMessage("[%04d] MDBUndefineClass(\"%s\", ...) is not implemented\r\n", __LINE__, Class); - - return(FALSE); -} - -BOOL -MDBFILEListContainableClasses(const unsigned char *Object, MDBValueStruct *V) -{ - unsigned long i; - FILE *handle; - MDBFILESchemaClass *c; - - if (V && MDB_CONTEXT_IS_VALID(V)) { - V->Buffer[0] = '\0'; - - if (Object && Object[0] && ((Object[0] != '.') || (Object[1] != '\0'))) { - MDBFILEObjectToFilename(Object, "Object Class", V->Filename, V, NULL); - } else { - MDBFILEObjectToFilename(V->BaseDN, "Object Class", V->Filename, V, NULL); - } - - handle = fopen(V->Filename, "rb"); - if (handle) { - if (fgets(V->Buffer, sizeof(V->Buffer), handle)) { - ChopNL(V->Buffer); - } - - fclose(handle); - } - - if (V->Buffer[0]) { - c = MDBFILELoadSchemaClass(V->Buffer); - if (c) { - for (i = 0; i < c->contains->Used; i++) { - MDBFILEAddValue(c->contains->Value[i], V); - } - - MDBFILEFreeSchemaClass(c); - } - - return(TRUE); - } - } - - return(FALSE); -} - -const unsigned char * -MDBFILEListContainableClassesEx(const unsigned char *Object, MDBEnumStruct *E, MDBValueStruct *V) -{ - unsigned char *ptr; - MDBEnumStruct *es = E; - - if (es) { - if (!es->Initialized) { - es->File = NULL; - es->EntriesLeft = 0; - - if (V && MDB_CONTEXT_IS_VALID(V)) { - V->Buffer[0] = '\0'; - - if (Object && Object[0] && ((Object[0] != '.') || (Object[1] != '\0'))) { - MDBFILEObjectToFilename(Object, "Object Class", V->Filename, V, NULL); - } else { - MDBFILEObjectToFilename(V->BaseDN, "Object Class", V->Filename, V, NULL); - } - - es->File = fopen(V->Filename, "rb"); - if (es->File) { - if (fgets(V->Buffer, sizeof(V->Buffer), es->File)) { - ChopNL(V->Buffer); - } - - fclose(es->File); - es->File = NULL; - } - - if (V->Buffer) { - ptr = V->Filename + MDBFILEClassToFilename(V->Buffer, V->Filename); - - strcpy(ptr, "/contains"); - es->File = fopen(V->Filename, "rb"); - if (es->File) { - es->Initialized = TRUE; - es->EntriesLeft = 1; - } - } - } - } - - if (es->EntriesLeft) { - if (!feof(es->File) && !ferror(es->File)) { - if (fgets(es->Buffer, sizeof(es->Buffer), es->File)) { - LogMessage("[%04d] MDBFILEListContainableClassesEx(\"%s\", ...) returning \"%s\".\r\n", __LINE__, Object, es->Buffer); - - return(es->Buffer); - } - } - } - - es->EntriesLeft = 0; - - if (es->File != NULL) { - fclose(es->File); - es->File = NULL; - } - - es->Initialized = FALSE; - } - - return(NULL); -} - -long -MDBFILERead(const unsigned char *Object, const unsigned char *Attribute, MDBValueStruct *V) -{ - int offset; - unsigned long count; - FILE *handle; - MDBFILESchemaAttribute *a; - - if (Attribute && V && MDB_CONTEXT_IS_VALID(V)) { - a = MDBFILELoadSchemaAttribute(Attribute); - if (a) { - if (a->syntax != 1) { - offset = 0; - } else { - offset = strlen(V->BaseDN) + 1; - } - - MDBFILEFreeSchemaAttribute(a); - a = NULL; - - count = V->Used; - } else { - return(0); - } - - if (Object && Object[0] && ((Object[0] != '.') || (Object[1] != '\0'))) { - MDBFILEObjectToFilename(Object, Attribute, V->Filename, V, NULL); - } else { - MDBFILEObjectToFilename(V->BaseDN, Attribute, V->Filename, V, NULL); - } - - handle = fopen(V->Filename, "rb"); - if (handle) { - while (!feof(handle) && !ferror(handle)) { - if (fgets(V->Buffer, sizeof(V->Buffer), handle)) { - ChopNL(V->Buffer); - - /* unescape the attribute value */ - if (offset == 0) { - unsigned char *ptr = strchr(V->Buffer, '\\'); - while (ptr != NULL) { - if (*(ptr+1) == 'r') { - strcpy(ptr, ptr+1); - *ptr = '\r'; - } else if (*(ptr+1) == 'n') { - strcpy(ptr, ptr+1); - *ptr = '\n'; - } else if (*(ptr+1) == '\\') { - strcpy(ptr, ptr+1); - } - ptr = strchr(ptr + 1, '\\'); - } - } - - LogMessage("[%04d] MDBRead(\"%s\", \"%s\", ...) adding \"%s\".\r\n", __LINE__, Object, Attribute, V->Buffer + offset); - - MDBFILEAddValue(V->Buffer + offset, V); - } - } - - fclose(handle); - } else { - LogMessage("[%04d] MDBRead(\"%s\", \"%s\", ...) failed to open \"%s\"; error %d\r\n", __LINE__, Object, Attribute, V->Filename, errno); - } - - return(V->Used - count); - } - - return(0); -} - -const unsigned char * -MDBFILEReadEx(const unsigned char *Object, const unsigned char *Attribute, MDBEnumStruct *E, MDBValueStruct *V) -{ - MDBFILESchemaAttribute *a; - - if (E) { - if (!E->Initialized) { - E->File = NULL; - E->EntriesLeft = 0; - - if (Attribute && V && MDB_CONTEXT_IS_VALID(V)) { - a = MDBFILELoadSchemaAttribute(Attribute); - if (a) { - if (a->syntax != 1) { - E->Offset = 0; - } else { - E->Offset = strlen(V->BaseDN) + 1; - } - - MDBFILEFreeSchemaAttribute(a); - a = NULL; - - if (Object && Object[0] && ((Object[0] != '.') || (Object[1] != '\0'))) { - MDBFILEObjectToFilename(Object, Attribute, V->Filename, V, NULL); - } else { - MDBFILEObjectToFilename(V->BaseDN, Attribute, V->Filename, V, NULL); - } - - E->File = fopen(V->Filename, "rb"); - if (E->File) { - E->Initialized = TRUE; - E->EntriesLeft = 1; - } else { - LogMessage("[%04d] MDBReadEx(\"%s\", \"%s\", ...) failed to open \"%s\"; error %d\r\n", __LINE__, Object, Attribute, V->Filename, errno); - } - } - } - } - - if (E->EntriesLeft) { - if (!feof(E->File) && !ferror(E->File)) { - if (fgets(E->Buffer, sizeof(E->Buffer), E->File)) { - /* unescape the attribute value */ - if (E->Offset == 0) { - unsigned char *ptr = strchr(E->Buffer, '\\'); - while (ptr != NULL) { - if (*(ptr+1) == 'r') { - strcpy(ptr, ptr+1); - *ptr = '\r'; - } else if (*(ptr+1) == 'n') { - strcpy(ptr, ptr+1); - *ptr = '\n'; - } else if (*(ptr+1) == '\\') { - strcpy(ptr, ptr+1); - } - ptr = strchr(ptr + 1, '\\'); - } - } - - LogMessage("[%04d] MDBReadEx(\"%s\", \"%s\", ...) returning \"%s\".\r\n", __LINE__, Object, Attribute, E->Buffer + E->Offset); - - return(E->Buffer + E->Offset); - } - } - } - - E->EntriesLeft = 0; - - if (E->File != NULL) { - fclose(E->File); - E->File = NULL; - } - - E->Initialized = FALSE; - } - - return(NULL); -} - -/* - The MDBFILEReadDN will always return a full DN, instead of a DN relative to the selected context -*/ -long -MDBFILEReadDN(const unsigned char *Object, const unsigned char *Attribute, MDBValueStruct *V) -{ - unsigned long count; - FILE *handle; - - if (Attribute && V && MDB_CONTEXT_IS_VALID(V)) { - count = V->Used; - - if (Object && Object[0] && ((Object[0] != '.') || (Object[1] != '\0'))) { - MDBFILEObjectToFilename(Object, Attribute, V->Filename, V, NULL); - } else { - MDBFILEObjectToFilename(V->BaseDN, Attribute, V->Filename, V, NULL); - } - - handle = fopen(V->Filename, "rb"); - if (handle) { - while (!feof(handle) && !ferror(handle)) { - if (fgets(V->Buffer, sizeof(V->Buffer), handle)) { - ChopNL(V->Buffer); - - LogMessage("[%04d] MDBReadDN(\"%s\", \"%s\", ...) adding \"%s\".\r\n", __LINE__, Object, Attribute, V->Buffer); - - MDBFILEAddValue(V->Buffer, V); - } - } - - fclose(handle); - } else { - LogMessage("[%04d] MDBReadDN(\"%s\", \"%s\", ...) failed to open \"%s\"; error %d\r\n", __LINE__, Object, Attribute, V->Filename, errno); - } - - return(V->Used - count); - } - - return(0); -} - -BOOL -MDBFILEOpenStream(const unsigned char *Object, const unsigned char *AttributeIn, MDBValueStruct *V) -{ - LogMessage("[%04d] MDBOpenStream(...) is not implemented\r\n", __LINE__); - - return(FALSE); -} - -BOOL -MDBFILEReadStream(MDBValueStruct *V) -{ - LogMessage("[%04d] MDBReadStream(...) is not implemented\r\n", __LINE__); - - return(FALSE); -} - -BOOL -MDBFILEWriteStream(MDBValueStruct *V) -{ - LogMessage("[%04d] MDBWriteStream(...) is not implemented\r\n", __LINE__); - - return(FALSE); -} - -BOOL -MDBFILECloseStream(MDBValueStruct *V) -{ - LogMessage("[%04d] MDBCloseStream(...) is not implemented\r\n", __LINE__); - - return(FALSE); -} - -BOOL -MDBFILEWriteTyped(const unsigned char *Object, const unsigned char *Attribute, const int AttrType, MDBValueStruct *V) -{ - unsigned long i; - unsigned char *ptr; - BOOL result = FALSE; - FILE *handle; - - if (Attribute && V && MDB_CONTEXT_IS_VALID(V) && MDBFileIsValidHandle(V->Handle)) { - if (Object && Object[0] && ((Object[0] != '.') || (Object[1] != '\0'))) { - MDBFILEObjectToFilename(Object, Attribute, V->Filename, V, &ptr); - } else { - MDBFILEObjectToFilename(V->BaseDN, Attribute, V->Filename, V, &ptr); - } - - /* Allow a readonly handle to write to the object that opened the handle */ - if (MDBFileIsReadWrite(V)) { - *ptr = '\0'; - MDBFILECreatePath(V->Filename); - *ptr++ = '/'; - - handle = fopen(V->Filename, "wb"); - if (handle) { - result = TRUE; - - for (i = 0; i < V->Used; i++) { - switch(AttrType) { - case MDB_ATTR_SYN_DIST_NAME: { - if (V->Value[i][0] != '\\') { - sprintf(V->Buffer, "%s\\%s", V->BaseDN, V->Value[i]); - } else { - strcpy(V->Buffer, V->Value[i]); - } - - LogMessage("[%04d] MDBWriteDN(\"%s\", \"%s\", V->Value[%d] = \"%s\")\r\n", __LINE__, Object, Attribute, i, V->Buffer); - - fprintf(handle, "%s\r\n", V->Buffer); - - break; - } - - case MDB_ATTR_SYN_STRING: - default: { - unsigned char *special; - - LogMessage("[%04d] MDBWrite(\"%s\", \"%s\", V->Value[%d] = \"%s\")\r\n", __LINE__, Object, Attribute, i, V->Value[i]); - - /* output the attribute value and escape CR, LF & \ as \r, \n & \\ respecitively */ - ptr = V->Value[i]; - while ((special = strpbrk(ptr, "\n\r\\")) != NULL) { - fwrite(ptr, sizeof(unsigned char), special-ptr, handle); - fputc('\\', handle); - if (*special == '\r') { - fputc('r', handle); - } else if (*special == '\n') { - fputc('n', handle); - } else { - fputc(*special, handle); - } - ptr = special + 1; - } - fprintf(handle, "%s\r\n", ptr); - break; - } - } - } - - fclose(handle); - } else { - LogMessage("[%04d] MDBFILEWriteTyped(\"%s\", \"%s\", ...) failed to create \"%s\"; error %d\r\n", __LINE__, Object, Attribute, V->Filename, errno); - } - } - } - - return(result); -} - -BOOL -MDBFILEWrite(const unsigned char *Object, const unsigned char *AttributeIn, MDBValueStruct *V) -{ - return(MDBFILEWriteTyped(Object, AttributeIn, MDB_ATTR_SYN_STRING, V)); -} - -BOOL -MDBFILEWriteDN(const unsigned char *Object, const unsigned char *AttributeIn, MDBValueStruct *V) -{ - return(MDBFILEWriteTyped(Object, AttributeIn, MDB_ATTR_SYN_DIST_NAME, V)); -} - -BOOL -MDBFILEAdd(const unsigned char *Object, const unsigned char *Attribute, const unsigned char *Value, MDBValueStruct *V) -{ - unsigned char *ptr; - FILE *handle; - BOOL result = FALSE; - - if (Attribute && Value && V && MDB_CONTEXT_IS_VALID(V) && MDBFileIsValidHandle(V->Handle)) { - if (Object && Object[0] && ((Object[0] != '.') || (Object[1] != '\0'))) { - MDBFILEObjectToFilename(Object, Attribute, V->Filename, V, &ptr); - } else { - MDBFILEObjectToFilename(V->BaseDN, Attribute, V->Filename, V, &ptr); - } - - /* Allow a readonly handle to write to the object that opened the handle */ - if (MDBFileIsReadWrite(V)) { - *ptr = '\0'; - MDBFILECreatePath(V->Filename); - *ptr = '/'; - - handle = fopen(V->Filename, "ab"); - if (handle) { - LogMessage("[%04d] MDBAdd(\"%s\", \"%s\", \"%s\")\r\n", __LINE__, Object, Attribute, Value); - - fprintf(handle, "%s\r\n", Value); - - fclose(handle); - - result = TRUE; - } else { - LogMessage("[%04d] MDBAdd(\"%s\", \"%s\", ...) failed to append \"%s\" to \"%s\"; error %d\r\n", __LINE__, Object, Attribute, Value, V->Filename, errno); - } - } - } - - return(result); -} - -BOOL -MDBFILEAddDN(const unsigned char *Object, const unsigned char *Attribute, const unsigned char *Value, MDBValueStruct *V) -{ - unsigned char *ptr; - FILE *handle; - BOOL result = FALSE; - - if (Attribute && V && MDB_CONTEXT_IS_VALID(V) && MDBFileIsValidHandle(V->Handle)) { - if (Object && Object[0] && ((Object[0] != '.') || (Object[1] != '\0'))) { - MDBFILEObjectToFilename(Object, Attribute, V->Filename, V, &ptr); - } else { - MDBFILEObjectToFilename(V->BaseDN, Attribute, V->Filename, V, &ptr); - } - - /* Allow a readonly handle to write to the object that opened the handle */ - if (MDBFileIsReadWrite(V)) { - *ptr = '\0'; - MDBFILECreatePath(V->Filename); - *ptr = '/'; - - handle = fopen(V->Filename, "ab"); - if (handle) { - result = TRUE; - - if (Value[0] != '\\') { - sprintf(V->Buffer, "%s\\%s", V->BaseDN, Value); - } else { - strcpy(V->Buffer, Value); - } - - LogMessage("[%04d] MDBAddDN(\"%s\", \"%s\", \"%s\")\r\n", __LINE__, Object, Attribute, V->Buffer); - - fprintf(handle, "%s\r\n", V->Buffer); - - fclose(handle); - } else { - LogMessage("[%04d] MDBAdd(\"%s\", \"%s\", ...) failed to append \"%s\" to \"%s\"; error %d\r\n", __LINE__, Object, Attribute, Value, V->Filename, errno); - } - } - } - - return(result); -} - -BOOL -MDBFILERemove(const unsigned char *Object, const unsigned char *Attribute, const unsigned char *Value, MDBValueStruct *V) -{ - unsigned long i; - unsigned char *ptr; - unsigned char *special; - MDBValueStruct *data; - FILE *handle; - struct stat buf; - BOOL result = FALSE; - - if (V && MDB_CONTEXT_IS_VALID(V) && MDBFileIsValidHandle(V->Handle)) { - data = MDBFILEShareContext(V); - if (data) { - if (Object && Object[0] && ((Object[0] != '.') || (Object[1] != '\0'))) { - MDBFILEObjectToFilename(Object, Attribute, V->Filename, V, &ptr); - } else { - MDBFILEObjectToFilename(V->BaseDN, Attribute, V->Filename, V, &ptr); - } - - /* Allow a readonly handle to write to the object that opened the handle */ - if (MDBFileIsReadWrite(V)) { - *ptr = '\0'; - if (stat(V->Filename, &buf) == 0) { - *ptr = '/'; - - handle = fopen(V->Filename, "rb"); - if (handle) { - const unsigned char *ptrc; - while (!feof(handle) && !ferror(handle)) { - if (fgets(V->Buffer, sizeof(V->Buffer), handle)) { - ChopNL(V->Buffer); - - MDBFILEAddValue(V->Buffer, data); - } - } - - fclose(handle); - - result = FALSE; - - /* escape the attribute value so it's the same as in the file */ - ptrc = Value; - V->Buffer[0] = 0; - while ((special = strpbrk(ptrc, "\n\r\\")) != NULL) { - strncat(V->Buffer, ptrc, special-ptrc); - if (*special == '\r') { - strcat(V->Buffer, "\\r"); - } else if (*special == '\n') { - strcat(V->Buffer, "\\n"); - } else { - strcat(V->Buffer, "\\\\"); - } - ptrc = special + 1; - } - strcat(V->Buffer, ptrc); - - for (i = 0; i < data->Used; ) { - if (XplStrCaseCmp(V->Buffer, data->Value[i]) != 0) { - i++; - continue; - } - - MDBFILEFreeValue(i, data); - - result = TRUE; - } - - if (result) { - LogMessage("[%04d] MDBRemove(\"%s\", \"%s\", \"%s\")\r\n", __LINE__, Object, Attribute, Value); - - if (data->Used) { - handle = fopen(V->Filename, "wb"); - if (handle) { - for (i = 0; i < data->Used; i++) { - fprintf(handle, "%s\r\n", data->Value[i]); - } - - fclose(handle); - } else { - V->ErrNo = ERR_TRANSPORT_FAILURE; - - result = FALSE; - } - } else { - unlink(V->Filename); - } - } else { - V->ErrNo = ERR_NO_SUCH_VALUE; - - result = TRUE; - } - - MDBFILEDestroyValueStruct(data); - } - } else { - V->ErrNo = ERR_NO_SUCH_ENTRY; - } - } - } - } - - return(result); -} - -BOOL -MDBFILERemoveDN(const unsigned char *Object, const unsigned char *Attribute, const unsigned char *Value, MDBValueStruct *V) -{ - unsigned long i; - unsigned char *ptr; - MDBValueStruct *data; - FILE *handle; - struct stat buf; - BOOL result = FALSE; - - if (Attribute && V && MDB_CONTEXT_IS_VALID(V) && MDBFileIsValidHandle(V->Handle)) { - data = MDBFILEShareContext(V); - if (data) { - if (Object && Object[0] && ((Object[0] != '.') || (Object[1] != '\0'))) { - MDBFILEObjectToFilename(Object, Attribute, V->Filename, V, &ptr); - } else { - MDBFILEObjectToFilename(V->BaseDN, Attribute, V->Filename, V, &ptr); - } - - /* Allow a readonly handle to write to the object that opened the handle */ - if (MDBFileIsReadWrite(V)) { - *ptr = '\0'; - if (stat(V->Filename, &buf) == 0) { - *ptr = '/'; - - handle = fopen(V->Filename, "rb"); - if (handle) { - while (!feof(handle) && !ferror(handle)) { - if (fgets(V->Buffer, sizeof(V->Buffer), handle)) { - ChopNL(V->Buffer); - - MDBFILEAddValue(V->Buffer, data); - } - } - - fclose(handle); - - if (Value[0] != '\\') { - sprintf(V->Buffer, "%s\\%s", V->BaseDN, Value); - } else { - strcpy(V->Buffer, Value); - } - - result = FALSE; - for (i = 0; i < data->Used; ) { - if (XplStrCaseCmp(V->Buffer, data->Value[i]) != 0) { - i++; - continue; - } - - MDBFILEFreeValue(i, data); - - result = TRUE; - } - - if (result) { - LogMessage("[%04d] MDBRemoveDN(\"%s\", \"%s\", \"%s\")\r\n", __LINE__, Object, Attribute, V->Buffer); - - if (data->Used) { - handle = fopen(V->Filename, "wb"); - if (handle) { - for (i = 0; i < data->Used; i++) { - fprintf(handle, "%s\r\n", data->Value[i]); - } - - fclose(handle); - } else { - V->ErrNo = ERR_TRANSPORT_FAILURE; - - result = FALSE; - } - } else { - unlink(V->Filename); - } - } else { - V->ErrNo = ERR_NO_SUCH_VALUE; - - result = TRUE; - } - - MDBFILEDestroyValueStruct(data); - } - } else { - V->ErrNo = ERR_NO_SUCH_ENTRY; - } - } - } - } - - return(result); -} - -BOOL -MDBFILEClear(const unsigned char *Object, const unsigned char *Attribute, MDBValueStruct *V) -{ - unsigned char *ptr; - - if (Attribute && V && MDB_CONTEXT_IS_VALID(V) && MDBFileIsValidHandle(V->Handle)) { - if (Object && Object[0] && ((Object[0] != '.') || (Object[1] != '\0'))) { - MDBFILEObjectToFilename(Object, Attribute, V->Filename, V, &ptr); - } else { - MDBFILEObjectToFilename(V->BaseDN, Attribute, V->Filename, V, &ptr); - } - - /* Allow a readonly handle to write to the object that opened the handle */ - if (MDBFileIsReadWrite(V)) { - *ptr = '\0'; - MDBFILECreatePath(V->Filename); - *ptr = '/'; - - unlink(V->Filename); - - return(TRUE); - } - } - - return(FALSE); -} - -BOOL -MDBFILEIsObject(const unsigned char *Object, MDBValueStruct *V) -{ - struct stat buf; - if (V && MDB_CONTEXT_IS_VALID(V)) { - if (Object && Object[0] && ((Object[0] != '.') || (Object[1] != '\0'))) { - MDBFILEObjectToFilename(Object, NULL, V->Filename, V, NULL); - } else { - MDBFILEObjectToFilename(V->BaseDN, NULL, V->Filename, V, NULL); - } - - if (stat(V->Filename, &buf) == 0) { - LogMessage("[%04d] MDBIsObject(\"%s\"...) TRUE.\r\n", __LINE__, Object); - - return(TRUE); - } - - LogMessage("[%04d] MDBIsObject(\"%s\", ...) FALSE.\r\n", __LINE__, Object); - } - - return(FALSE); -} - -static BOOL -GetAliasedObject(const unsigned char *Object, MDBValueStruct *V) -{ - unsigned char *ptr; - FILE *handle; - BOOL result = FALSE; - - MDBFILEObjectToFilename(Object, "Aliased Object Name", V->Filename, V, &ptr); - handle = fopen(V->Filename, "rb"); - if (handle) { - while (!feof(handle) && !ferror(handle)) { - if (fgets(V->Buffer, sizeof(V->Buffer), handle)) { - ChopNL(V->Buffer); - result = TRUE; - break; - } - } - - fclose(handle); - } - - return(result); -} - -static MDBFILESchemaClass * -GetObjectClass(const unsigned char *Object, MDBValueStruct *V) -{ - unsigned char *ptr; - FILE *handle; - MDBFILESchemaClass *c = NULL; - - if (Object && Object[0] && ((Object[0] != '.') || (Object[1] != '\0'))) { - MDBFILEObjectToFilename(Object, "Object Class", V->Filename, V, &ptr); - } else { - MDBFILEObjectToFilename(V->BaseDN, "Object Class", V->Filename, V, &ptr); - } - - handle = fopen(V->Filename, "rb"); - if (handle) { - while (!feof(handle) && !ferror(handle)) { - if (fgets(V->Buffer, sizeof(V->Buffer), handle)) { - ChopNL(V->Buffer); - - c = MDBFILELoadSchemaClass(V->Buffer); - break; - } - } - - fclose(handle); - } - - return c; -} - -__inline static BOOL -FreeSchemaClass(MDBFILESchemaClass *class) -{ - MDBFILEFreeSchemaClass(class); - return(TRUE); -} - -BOOL -MDBFILEGetObjectDetails(const unsigned char *Object, unsigned char *Type, unsigned char *RDN, unsigned char *DN, MDBValueStruct *V) -{ - BOOL result = FALSE; - MDBValueStruct *Types = MDBFILEShareContext(V); - - if (Types) { - result = MDBFILEGetObjectDetailsEx(Object, Types, RDN, DN, V); - - if (result && Types->Used > 0) { - strcpy((char *) Type, (char *) Types->Value[0]); - } - - MDBFILEDestroyValueStruct(Types); - } - - return result; -} - -BOOL -MDBFILEGetObjectDetailsEx(const unsigned char *Object, MDBValueStruct *Types, unsigned char *RDN, unsigned char *DN, MDBValueStruct *V) -{ - unsigned char *ptr; - MDBFILESchemaClass *objectClass = NULL; - BOOL result = TRUE; - - if (V && MDB_CONTEXT_IS_VALID(V)) { - objectClass = GetObjectClass(Object, V); - if (objectClass && - ((strcmp(objectClass->name, "Alias") != 0) || - ((GetAliasedObject(Object, V)) && - FreeSchemaClass(objectClass) && - ((objectClass = GetObjectClass(V->Buffer, V)) != NULL)))) { - - - /* GetObjectClass() leaves the path to the 'object class' file in V->Filename. */ - /* we need to chop the filename off so we can get just the object path. */ - ptr = strrchr(V->Filename, '/'); - if (ptr) { - *ptr = '\0'; - } - - MDBFILEFilenameToObjectDN(V->Filename, V->Buffer, &ptr); - - if (DN) { - strcpy(DN, V->Buffer); - } - - if (RDN) { - strcpy(RDN, ptr); - } - - if (Types) { - result = MDBFILEAddValue(objectClass->name, Types); - } - - - LogMessage("[%04d] MDBGetObjectDetails(\"%s\", \"%s\", \"%s\", \"%s\", ...) success.\r\n", __LINE__, Object, objectClass->name, ptr, V->Buffer); - - MDBFILEFreeSchemaClass(objectClass); - - return(result); - - } - } - - LogMessage("[%04d] MDBGetObjectDetails(\"%s\", ...) failed.\r\n", __LINE__, Object); - - return(FALSE); -} - -BOOL -MDBFILEVerifyPassword(const unsigned char *Object, const unsigned char *Password, MDBValueStruct *V) -{ - unsigned char *buffer; - BOOL result = FALSE; - FILE *handle; - struct stat sb; - - if (V && MDB_CONTEXT_IS_VALID(V)) { - if (Object && Object[0] && ((Object[0] != '.') || (Object[1] != '\0'))) { - MDBFILEObjectToFilename(Object, "Private Key", V->Filename, V, NULL); - } else { - MDBFILEObjectToFilename(V->BaseDN, "Private Key", V->Filename, V, NULL); - } - - if (stat(V->Filename, &sb) == 0) { - buffer = (unsigned char *)malloc(sb.st_size + 1); - if (buffer) { - handle = fopen(V->Filename, "rb"); - if (handle) { - if (fread(buffer, sizeof(unsigned char), sb.st_size, handle) == (size_t)sb.st_size) { - buffer[sb.st_size] = '\0'; - - if (strcmp(Password, DecodeBase64(buffer)) == 0) { - result = TRUE; - } else { - LogMessage("[%04d] MDBVerifyPassword() password was not correct\r\n", __LINE__); - } - } - - fclose(handle); - } else { - LogMessage("[%04d] MDBVerifyPassword() Could not open the password file"); - } - - free(buffer); - } - } else if (!Password || (Password[0] == '\0')) { - result = TRUE; - } else { - LogMessage("[%04d] MDBVerifyPassword() could not access the password file and a password was specified.\r\n", __LINE__); - } - - } else { - LogMessage("[%04d] MDBVerifyPassword() context was not valid\r\n", __LINE__); - } - - return(result); -} - -BOOL -MDBFILEChangePassword(const unsigned char *Object, const unsigned char *OldPassword, const unsigned char *NewPassword, MDBValueStruct *V) -{ - unsigned char *buffer; - unsigned char *encoded; - BOOL result = FALSE; - FILE *handle; - struct stat sb; - - if (V && MDB_CONTEXT_IS_VALID(V) && MDBFileIsValidHandle(V->Handle)) { - if (Object && Object[0] && ((Object[0] != '.') || (Object[1] != '\0'))) { - MDBFILEObjectToFilename(Object, "Private Key", V->Filename, V, NULL); - } else { - MDBFILEObjectToFilename(V->BaseDN, "Private Key", V->Filename, V, NULL); - } - - /* Allow a readonly handle to write to the object that opened the handle */ - if (MDBFileIsReadWrite(V)) { - if (stat(V->Filename, &sb) == 0) { - buffer = (unsigned char *)malloc(sb.st_size + 1); - if (buffer) { - handle = fopen(V->Filename, "rb"); - if (handle) { - if (fread(buffer, sizeof(unsigned char), sb.st_size, handle) == (size_t)sb.st_size) { - buffer[sb.st_size] = '\0'; - - if (strcmp(OldPassword, DecodeBase64(buffer)) == 0) { - result = TRUE; - } - } - - fclose(handle); - } - - free(buffer); - } - } else { - result = TRUE; - } - - if (result) { - result = FALSE; - - handle = fopen(V->Filename, "wb"); - if (handle) { - encoded = EncodeBase64(NewPassword); - if (encoded) { - fwrite(encoded, sizeof(unsigned char), strlen(encoded), handle); - - MemFree(encoded); - - result = TRUE; - } - - fclose(handle); - } - } - } - } - - return(result); -} - -BOOL -MDBFILEChangePasswordEx(const unsigned char *Object, const unsigned char *OldPassword, const unsigned char *NewPassword, MDBValueStruct *V) -{ - unsigned char *encoded; - BOOL result = FALSE; - FILE *handle; - - if (V && MDB_CONTEXT_IS_VALID(V) && MDBFileIsValidHandle(V->Handle)) { - if (Object && Object[0] && ((Object[0] != '.') || (Object[1] != '\0'))) { - MDBFILEObjectToFilename(Object, "Private Key", V->Filename, V, NULL); - } else { - MDBFILEObjectToFilename(V->BaseDN, "Private Key", V->Filename, V, NULL); - } - - /* Allow a readonly handle to write to the object that opened the handle */ - if (MDBFileIsReadWrite(V)) { - handle = fopen(V->Filename, "wb"); - if (handle) { - encoded = EncodeBase64(NewPassword); - if (encoded) { - fwrite(encoded, sizeof(unsigned char), strlen(encoded), handle); - - MemFree(encoded); - - result = TRUE; - } - - fclose(handle); - } - } - } - - return(result); -} - -static BOOL -MDBFILERecurseAttributes(unsigned char *Path, MDBValueStruct *V) -{ - unsigned char *delim; - BOOL result = TRUE; - XplDir *parent; - XplDir *entry; - - delim = Path + strlen(Path); - - parent = XplOpenDir(Path); - if (parent) { - while ((entry = XplReadDir(parent)) != NULL) { - // filter out the object entries (directories) - if (!(entry->d_attr & XPL_A_SUBDIR) && (entry->d_name[0] != '.')) { - delim[0] = '/'; - strcpy(delim + 1, entry->d_name); - - MDBFILEFilenameToAttributeName(entry->d_name, V->Buffer); - - MDBFILEAddValue(V->Buffer, V); - - continue; - } - - } - - XplCloseDir(parent); - } else { - result = FALSE; - } - - return(result); -} - -static BOOL -MDBFILERecurseObjects(unsigned char *Path, const unsigned char *Type, const unsigned char *Pattern, unsigned long Flags, MDBValueStruct *V) -{ - unsigned int offset = strlen(V->BaseDN) + 1; - unsigned char *ptr; - unsigned char *delim; - FILE *handle; - BOOL result = TRUE; - XplDir *parent; - XplDir *entry; - - delim = Path + strlen(Path); - - parent = XplOpenDir(Path); - if (parent) { - while ((entry = XplReadDir(parent)) != NULL) { - if ((entry->d_attr & XPL_A_SUBDIR) && (entry->d_name[0] != '.')) { - if (!Type) { - delim[0] = '/'; - strcpy(delim + 1, entry->d_name); - - MDBFILEFilenameToObjectDN(Path, V->Buffer, NULL); - - MDBFILEAddValue(V->Buffer + offset, V); - - continue; - } else { - ptr = delim + sprintf(delim, "/%s/object%%032class", entry->d_name) - 16; - - handle = fopen(Path, "rb"); - - *ptr = '\0'; - - if (handle) { - if (fgets(V->Buffer, sizeof(V->Buffer), handle)) { - ChopNL(V->Buffer); - } else { - LogMessage("[%04d] MDBFILERecurseObjects(...) read \"%s\" failed; error %d.\r\n", __LINE__, Path, errno); - - result = FALSE; - } - - fclose(handle); - - if (result) { - if (XplStrCaseCmp(V->Buffer, Type) == 0) { - MDBFILEFilenameToObjectDN(Path, V->Buffer, NULL); - - MDBFILEAddValue(V->Buffer + offset, V); - } else if (Flags) { - unsigned char schemapath[(XPL_MAX_PATH * 4) + 1]; - - ptr = schemapath + MDBFILEClassToFilename(V->Buffer, schemapath); - - strcpy(ptr, "/flags"); - handle = fopen(schemapath, "rb"); - if (handle) { - if (fgets(V->Buffer, sizeof(V->Buffer), handle)) { - ChopNL(V->Buffer); - - if (atol(V->Buffer) & 0x01) { - MDBFILEFilenameToObjectDN(Path, V->Buffer, NULL); - - MDBFILEAddValue(V->Buffer + offset, V); - } - } - - fclose(handle); - } - } - } - } else { - LogMessage("[%04d] MDBFILERecurseObjects(...) open \"%s\" failed; error %d.\r\n", __LINE__, Path, errno); - - result = FALSE; - } - } - } - } - - XplCloseDir(parent); - } else { - result = FALSE; - } - - return(result); -} - -long MDBFILEEnumerateObjects(const unsigned char *Container, const unsigned char *Type, const unsigned char *Pattern, MDBValueStruct *V) -{ - unsigned long count; - struct stat buf; - - if (V && MDB_CONTEXT_IS_VALID(V)) { - if (Container && Container[0] && ((Container[0] != '.') || (Container[1] != '\0'))) { - MDBFILEObjectToFilename(Container, NULL, V->Filename, V, NULL); - } else { - MDBFILEObjectToFilename(V->BaseDN, NULL, V->Filename, V, NULL); - } - - LogMessage("[%04d] MDBEnumerateObjects(\"%s\", ...) enumerating \"%s\".\r\n", __LINE__, Container, V->Filename); - - if (stat(V->Filename, &buf) == 0) { - count = V->Used; - - MDBFILERecurseObjects(V->Filename, Type, Pattern, 0, V); - - return(V->Used - count); - } - } - - return(0); -} - -const unsigned char * -MDBFILEEnumerateObjectsEx(const unsigned char *Container, const unsigned char *Type, const unsigned char *Pattern, unsigned long Flags, MDBEnumStruct *E, MDBValueStruct *V) -{ - if (E) { - if (!E->Initialized) { - E->V = NULL; - E->EntriesLeft = 0; - - if (V && MDB_CONTEXT_IS_VALID(V)) { - E->V = MDBFILEShareContext(V); - if (E->V) { - if (Container && Container[0] && ((Container[0] != '.') || (Container[1] != '\0'))) { - MDBFILEObjectToFilename(Container, NULL, E->Filename, E->V, NULL); - } else { - MDBFILEObjectToFilename(E->V->BaseDN, NULL, E->Filename, E->V, NULL); - } - - LogMessage("[%04d] MDBEnumerateObjectsEx(\"%s\", \"%s\", \"%s\", %d, ...) enumerating \"%s\".\r\n", __LINE__, Container, Type, Pattern, Flags, E->Filename); - - if (MDBFILERecurseObjects(E->Filename, Type, Pattern, Flags, E->V)) { - E->Initialized = TRUE; - E->EntriesLeft = E->V->Used; - } - } - } - } - - if (E->EntriesLeft) { - E->EntriesLeft--; - - strcpy(E->Buffer, E->V->Value[0]); - - LogMessage("[%04d] MDBEnumerateObjectsEx(\"%s\", ...) returning \"%s\".\r\n", __LINE__, Container, E->Buffer); - - MDBFILEFreeValue(0, E->V); - - return(E->Buffer); - } - - E->EntriesLeft = 0; - - if (E->V != NULL) { - MDBFILEDestroyValueStruct(E->V); - E->V = NULL; - } - - E->Initialized = FALSE; - } - - return(NULL); -} - -const unsigned char * -MDBFILEEnumerateAttributesEx(const unsigned char *Object, MDBEnumStruct *E, MDBValueStruct *V) -{ - // LogMessage("[%04d] MDBEnumerateAttributesEx(\"%s\", ...) is not implemented\r\n", __LINE__, Object); - if (E) { - if (!E->Initialized) { - E->V = NULL; - E->EntriesLeft = 0; - - if (V && MDB_CONTEXT_IS_VALID(V)) { - E->V = MDBFILEShareContext(V); - if (E->V) { - if (Object && Object[0] && ((Object[0] != '.') || (Object[1] != '\0'))) { - MDBFILEObjectToFilename(Object, NULL, E->Filename, E->V, NULL); - } else { - MDBFILEObjectToFilename(E->V->BaseDN, NULL, E->Filename, E->V, NULL); - } - - LogMessage("[%04d] MDBEnumerateAttributesEx(\"%s\", ...) enumerating \"%s\".\r\n", __LINE__, Object, E->Filename); - - if (MDBFILERecurseAttributes(E->Filename, E->V)) { - E->Initialized = TRUE; - E->EntriesLeft = E->V->Used; - } - } - } - } - - if (E->EntriesLeft) { - E->EntriesLeft--; - strcpy(E->Buffer, E->V->Value[0]); - LogMessage("[%04d] MDBEnumerateAttributesEx(\"%s\", ...) returning \"%s\".\r\n", __LINE__, Object, E->Buffer); - MDBFILEFreeValue(0, E->V); - - return(E->Buffer); - } - - E->EntriesLeft = 0; - - if (E->V != NULL) { - MDBFILEDestroyValueStruct(E->V); - E->V = NULL; - } - E->Initialized = FALSE; - } - - return(NULL); -} - -BOOL -MDBFILECreateAlias(const unsigned char *Alias, const unsigned char *AliasedObjectDn, MDBValueStruct *V) -{ - const unsigned char *Class = "alias"; - unsigned char *ptr; - const unsigned char *rdn; - FILE *handle; - struct stat buf; - BOOL result = FALSE; - MDBFILESchemaClass *c = NULL; - - if (Alias && V && MDB_CONTEXT_IS_VALID(V) && MDBFileIsValidHandle(V->Handle) && !V->Handle->ReadOnly) { - - V->Filename[0] = '\0'; - - c = MDBFILELoadSchemaClass(Class); - if (c) { - if (c->naming && c->naming->Used) { - MDBFILEObjectToFilename(Alias, NULL, V->Filename, V, NULL); - if (V->Filename[0] && (stat(V->Filename, &buf) != 0)) { - MDBFILECreatePath(V->Filename); - - LogMessage("[%04d] MDBCreateObject(\"%s\", \"%s\", ...)\r\n", __LINE__, Alias, Class); - - ptr = V->Filename + strlen(V->Filename); - - strcpy(ptr, "/object%032class"); - handle = fopen(V->Filename, "wb"); - if (handle) { - fprintf(handle, "%s\r\n", c->name); - fclose(handle); - } - - rdn = strrchr(Alias, '\\'); - if (rdn) { - rdn++; - } else { - rdn = Alias; - } - - - MDBFILEObjectToFilename(NULL, c->naming->Value[0], ptr, NULL, NULL); - handle = fopen(V->Filename, "wb"); - if (handle) { - fprintf(handle, "%s\r\n", rdn); - - fclose(handle); - } - - ptr[0] = '/'; - MDBFILEObjectToFilename(NULL, "Aliased Object Name", ptr, NULL, NULL); - handle = fopen(V->Filename, "ab"); - if (handle) { - if (AliasedObjectDn[0] != '\\') { - sprintf(V->Buffer, "%s\\%s", V->BaseDN, AliasedObjectDn); - } else { - strcpy(V->Buffer, AliasedObjectDn); - } - - LogMessage("[%04d] MDBCreateObject(\"%s\", \"%s\", ...) adding DN \"%s\" = \"%s\"\r\n", __LINE__, Alias, Class, "Aliased Object Name", V->Buffer); - - fprintf(handle, "%s\r\n", V->Buffer); - - - fclose(handle); - } - - result = TRUE; - } else { - V->ErrNo = ERR_ENTRY_ALREADY_EXISTS; - } - - - } - } - - } - - if (c) { - MDBFILEFreeSchemaClass(c); - c = NULL; - } - - return(result); -} - -BOOL -MDBFILECreateObject(const unsigned char *Object, const unsigned char *Class, MDBValueStruct *Attribute, MDBValueStruct *Data, MDBValueStruct *V) -{ - unsigned long i; - unsigned char *ptr; - const unsigned char *rdn; - FILE *handle; - struct stat buf; - BOOL result = FALSE; - MDBFILESchemaClass *c = NULL; - - if (Object && Class && V && MDB_CONTEXT_IS_VALID(V) && MDBFileIsValidHandle(V->Handle) && !V->Handle->ReadOnly) { - - V->Filename[0] = '\0'; - - c = MDBFILELoadSchemaClass(Class); - if (c) { - if (c->naming && c->naming->Used) { - MDBFILEObjectToFilename(Object, NULL, V->Filename, V, NULL); - } - } - - if (V->Filename[0] && (stat(V->Filename, &buf) != 0)) { - MDBFILECreatePath(V->Filename); - - LogMessage("[%04d] MDBCreateObject(\"%s\", \"%s\", ...)\r\n", __LINE__, Object, Class); - - ptr = V->Filename + strlen(V->Filename); - - strcpy(ptr, "/object%032class"); - handle = fopen(V->Filename, "wb"); - if (handle) { - fprintf(handle, "%s\r\n", Class); - - fclose(handle); - } - - rdn = strrchr(Object, '\\'); - if (rdn) { - rdn++; - } else { - rdn = Object; - } - - - MDBFILEObjectToFilename(NULL, c->naming->Value[0], ptr, NULL, NULL); - handle = fopen(V->Filename, "wb"); - if (handle) { - fprintf(handle, "%s\r\n", rdn); - - fclose(handle); - } - - if (Attribute && Attribute->Used > 0 && Attribute->Used == Data->Used) { - for (i = 0; i < Attribute->Used; i++) { - ptr[0] = '/'; - MDBFILEObjectToFilename(NULL, Attribute->Value[i] + 1, ptr, NULL, NULL); - handle = fopen(V->Filename, "ab"); - if (handle) { - if (Attribute->Value[i][0] != MDB_ATTR_SYN_DIST_NAME) { - unsigned char *special; - unsigned char *data; - - LogMessage("[%04d] MDBCreateObject(\"%s\", \"%s\", ...) adding \"%s\" = \"%s\"\r\n", __LINE__, Object, Class, Attribute->Value[i] + 1, Data->Value[i]); - - /* output the attribute value and escape CR, LF & \ as \r, \n & \\ respecitively */ - data = Data->Value[i]; - while ((special = strpbrk(data, "\n\r\\")) != NULL) { - fwrite(data, sizeof(unsigned char), special-data, handle); - fputc('\\', handle); - if (*special == '\r') { - fputc('r', handle); - } else if (*special == '\n') { - fputc('n', handle); - } else { - fputc(*special, handle); - } - data = special + 1; - } - fprintf(handle, "%s\r\n", data); - } else { - if (Data->Value[i][0] != '\\') { - sprintf(V->Buffer, "%s\\%s", V->BaseDN, Data->Value[i]); - } else { - strcpy(V->Buffer, Data->Value[i]); - } - - LogMessage("[%04d] MDBCreateObject(\"%s\", \"%s\", ...) adding DN \"%s\" = \"%s\"\r\n", __LINE__, Object, Class, Attribute->Value[i] + 1, V->Buffer); - - fprintf(handle, "%s\r\n", V->Buffer); - } - - fclose(handle); - } - } - } - - result = TRUE; - } else { - V->ErrNo = ERR_ENTRY_ALREADY_EXISTS; - } - } - - if (c) { - MDBFILEFreeSchemaClass(c); - c = NULL; - } - - return(result); -} - -static int -DeleteRecursive(const unsigned char *DirBase, const unsigned char *DirEntry, MDBValueStruct *V) -{ - XplDir *parent; - XplDir *entry; - unsigned char *dirBase; - - dirBase = strdup(DirBase); - if (dirBase) { - sprintf(V->Filename, "%s/%s", dirBase, DirEntry); - parent = XplOpenDir(V->Filename); - if (parent) { - while ((entry = XplReadDir(parent)) != NULL) { - if (entry->d_attr & XPL_A_SUBDIR) { - if ((strcmp(entry->d_name, ".") != 0) && (strcmp(entry->d_name, "..") != 0)) { - sprintf(V->Filename, "%s/%s", dirBase, DirEntry); - if (!DeleteRecursive(V->Filename, entry->d_name, V)) { - return(0); - } - - sprintf(V->Filename, "%s/%s/%s", dirBase, DirEntry, entry->d_name); - rmdir(V->Filename); - } - - continue; - } - - sprintf(V->Filename, "%s/%s/%s", dirBase, DirEntry, entry->d_name); - unlink(V->Filename); - } - - XplCloseDir(parent); - } - - sprintf(V->Filename, "%s/%s", dirBase, DirEntry); - - rmdir(V->Filename); - - unlink(V->Filename); - - free(dirBase); - return(1); - } - return(0); -} - -BOOL -MDBFILEDeleteObject(const unsigned char *Object, BOOL Recursive, MDBValueStruct *V) -{ - BOOL result = FALSE; - unsigned char *delim; - XplDir *parent; - XplDir *entry; - struct stat buf; - - if (V && MDB_CONTEXT_IS_VALID(V) && MDBFileIsValidHandle(V->Handle) && !V->Handle->ReadOnly) { - if (Object && Object[0] && ((Object[0] != '.') || (Object[1] != '\0'))) { - MDBFILEObjectToFilename(Object, NULL, V->Filename, V, NULL); - } else { - MDBFILEObjectToFilename(V->BaseDN, NULL, V->Filename, V, NULL); - } - - delim = V->Filename + strlen(V->Filename); - - if (stat(V->Filename, &buf) == 0) { - LogMessage("[%04d] MDBDeleteObject(\"%s\", \"%s\", ...)\r\n", __LINE__, Object, (Recursive == FALSE)? "FALSE": "TRUE"); - - parent = XplOpenDir(V->Filename); - if (parent) { - while ((entry = XplReadDir(parent)) != NULL) { - if (entry->d_attr & XPL_A_SUBDIR) { - if ((strcmp(entry->d_name, ".") != 0) && (strcmp(entry->d_name, "..") != 0)) { - if (Recursive) { - if (DeleteRecursive(V->Filename, entry->d_name, V)) { - continue; - } - - V->ErrNo = ERR_SYSTEM_FAILURE; - XplCloseDir(parent); - return(FALSE); - } - - V->ErrNo = ERR_ENTRY_IS_NOT_LEAF; - - XplCloseDir(parent); - - return(FALSE); - } - - continue; - } - - *delim = '/'; - strcpy(delim + 1, entry->d_name); - - unlink(V->Filename); - - *delim = '\0'; - } - - XplCloseDir(parent); - } - - if (rmdir(V->Filename) == 0) { - result = TRUE; - } else if (errno == ENOTEMPTY) { - V->ErrNo = ERR_ENTRY_IS_NOT_LEAF; - } else if (errno == ENOENT) { - V->ErrNo = ERR_NO_SUCH_ENTRY; - } else { - V->ErrNo = ERR_TRANSPORT_FAILURE; - } - } else { - V->ErrNo = ERR_NO_SUCH_ENTRY; - } - } - - return(result); -} - -BOOL -MDBFILERenameObject(const unsigned char *ObjectOld, const unsigned char *ObjectNew, MDBValueStruct *V) -{ - unsigned char oldShort[XPL_MAX_PATH + 1]; - unsigned char newShort[XPL_MAX_PATH + 1]; - unsigned char newName[(XPL_MAX_PATH * 4) + 1]; - unsigned char class[XPL_MAX_PATH + 1]; - struct stat buf; - - if (ObjectNew && V && MDB_CONTEXT_IS_VALID(V) && MDBFileIsValidHandle(V->Handle) && !V->Handle->ReadOnly) { - if (ObjectOld && ObjectOld[0] && ((ObjectOld[0] != '.') || (ObjectOld[1] != '\0'))) { - MDBFILEObjectToFilename(ObjectOld, NULL, V->Filename, V, NULL); - } else { - MDBFILEObjectToFilename(V->BaseDN, NULL, V->Filename, V, NULL); - } - - if (stat(V->Filename, &buf) == 0) { - MDBFILEObjectToFilename(ObjectNew, NULL, newName, V, NULL); - if (stat(newName, &buf) != 0) { - XPLLongToDos(V->Filename, oldShort, XPL_MAX_PATH); - XPLLongToDos(newName, newShort, XPL_MAX_PATH); - - if( MDBFILEGetObjectDetails(ObjectOld, class, NULL, NULL, V) ) { - if (rename(oldShort, newShort) == 0) { - unsigned char *ptr; - const unsigned char *rdn; - MDBFILESchemaClass *c = NULL; - - ptr = newShort + strlen(newShort); - - rdn = strrchr(ObjectNew, '\\'); - if (rdn) { - rdn++; - } else { - rdn = ObjectNew; - } - - c = MDBFILELoadSchemaClass(class); - if (c) { - FILE *handle; - MDBFILEObjectToFilename(NULL, c->naming->Value[0], ptr, NULL, NULL); - handle = fopen(newShort, "wb"); - if (handle) { - fprintf(handle, "%s\r\n", rdn); - - fclose(handle); - } - - MDBFILEFreeSchemaClass(c); - c = NULL; - - return(TRUE); - } - - V->ErrNo = ERR_NO_SUCH_CLASS; - } else { - V->ErrNo = ERR_ENTRY_IS_NOT_LEAF; - } - } else { - V->ErrNo = ERR_NO_SUCH_CLASS; - } - } else { - V->ErrNo = ERR_ENTRY_ALREADY_EXISTS; - } - } else { - V->ErrNo = ERR_NO_SUCH_ENTRY; - } - } - - return(FALSE); -} - -BOOL -MDBFILEGrantObjectRights(const unsigned char *Object, const unsigned char *TrusteeDN, BOOL Read, BOOL Write, BOOL Delete, BOOL Rename, BOOL Admin, MDBValueStruct *V) -{ - LogMessage("[%04d] MDBGrantObjectRights(\"%s\", \"%s\", ...) is not implemented\r\n", __LINE__, Object, TrusteeDN); - - return(TRUE); -} - -BOOL -MDBFILEGrantAttributeRights(const unsigned char *Object, const unsigned char *Attribute, const unsigned char *TrusteeDN, BOOL Read, BOOL Write, BOOL Admin, MDBValueStruct *V) -{ - LogMessage("[%04d] MDBGrantAttributeRights(\"%s\", \"%s\", \"%s\", ...) is not implemented\r\n", __LINE__, Object, Attribute, TrusteeDN); - - return(TRUE); -} - -BOOL -MDBFILEAddAddressRestriction(const unsigned char *Object, const unsigned char *Server, MDBValueStruct *V) -{ - LogMessage("[%04d] MDBAddAddressRestriction(\"%s\", \"%s\", ...) is not implemented\r\n", __LINE__, Object, Server); - - return(FALSE); -} - -static BOOL -MDBFILEParseArguments(const unsigned char *Arguments) -{ - unsigned char filename[XPL_MAX_PATH + 1]; - unsigned char *toFree; - unsigned char *ptr; - unsigned char *end; - BOOL result = TRUE; - - toFree = strdup(Arguments); - ptr = toFree; - - while (ptr) { - end = ptr + 1; - do { - end = strchr(end + 1, ','); - } while (end && end[-1] == '\\'); - - if (end) { - *end = '\0'; - } - - if (XplStrNCaseCmp(ptr, "debug=", 6) == 0) { - if (atoi(ptr + 6)) { - MDBFile.log.buffer = (unsigned char *)malloc(VALUE_BUFFER_SIZE); - if (MDBFile.log.buffer) { - MDBFILECreatePath(MDBFile.root); - - sprintf(filename, "%s/log", MDBFile.root); - MDBFile.log.fh = fopen(filename, "wb"); - if (MDBFile.log.fh) { - MDBFile.log.enabled = TRUE; - MDBFile.log.bufferSize = VALUE_BUFFER_SIZE; - - if (atoi(ptr + 6) > 1) { - MDBFile.log.console = TRUE; - } - - XplOpenLocalSemaphore(MDBFile.log.sem, 1); - } else { - free(MDBFile.log.buffer); - } - } - } - } - - /* Restore the buffer */ - if (end) { - *end = ','; - ptr = end + 1; - } else { - ptr = NULL; - } - } - - if (toFree) { - free(toFree); - } - - return(result); -} - -EXPORT BOOL -MDBFILEInit(MDBDriverInitStruct *Init) -{ - unsigned char path[XPL_MAX_PATH + 1]; - struct stat buf; - BOOL result = FALSE; - - MDBFile.unload = FALSE; - - strcpy(MDBFile.localTree, "\\Tree"); - strcpy(MDBFile.replicaDN, "Bongo"); - strcpy(MDBFile.base64Chars, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="); - -#if defined(LINUX) - strcpy(MDBFile.root, XPL_DEFAULT_STATE_DIR "/mdb"); - strcpy(MDBFile.schema, XPL_DEFAULT_STATE_DIR "/mdb/schema"); -#else - strcpy(MDBFile.root, "C:\\program files\\Bongo\\MDB"); - strcpy(MDBFile.schema, "C:\\program files\\Bongo\\MDB\\schema"); -#endif - - MDBFile.rootLength = strlen(MDBFile.root); - - MDBFile.log.enabled = FALSE; - - XplOpenLocalSemaphore(MDBFile.handles.sem, 1); - MDBFile.handles.data = NULL; - MDBFile.handles.used = 0; - MDBFile.handles.allocated = 0; - - if (Init->Arguments) { - MDBFILEParseArguments(Init->Arguments); - } - - strcpy(path, MDBFile.schema); - - MDBFile.directoryHandle = MDBFileCreateContext("/", FALSE); - if (MDBFile.directoryHandle) { - strcpy(MDBFile.directoryHandle->Description, PRODUCT_NAME); - } - - if (stat(path, &buf) != 0) { - unsigned char *cur; - unsigned char *ptr; - MDBValueStruct *v; - MDBValueStruct *superclass; - MDBValueStruct *containedby; - MDBValueStruct *naming; - MDBValueStruct *mandatory; - MDBValueStruct *optional; - MDBValueStruct *attributes; - MDBValueStruct *values; - MDBFILEBaseSchemaAttributes *a; - MDBFILEBaseSchemaClasses *cSource; - MDBFILEBaseSchemaClasses *c; - - v = MDBFILECreateValueStruct(MDBFile.directoryHandle, NULL); - if (v) { - XplMakeDir(path); - - result = TRUE; - } else { - result = FALSE; - } - - a = &MDBFILEBaseSchemaAttributesList[0]; - while (result && (a->name != NULL)) { - result = MDBFILEDefineAttribute(a->name, a->asn1, a->type, a->flags & 0x0001, a->flags & 0x0040, a->flags & 0x0080, v); - - a++; - } - - if (result) { - superclass = MDBFILEShareContext(v); - containedby = MDBFILEShareContext(v); - naming = MDBFILEShareContext(v); - mandatory = MDBFILEShareContext(v); - optional = MDBFILEShareContext(v); - - c = (MDBFILEBaseSchemaClasses *)malloc(sizeof(MDBFILEBaseSchemaClasses)); - if (superclass && containedby && naming && mandatory && optional && c) { - cSource = &MDBFILEBaseSchemaClassesList[0]; - while (result && (cSource->name != NULL)) { - c->flags = cSource->flags; - - c->name = strdup(cSource->name); - - if (cSource->asn1) { - c->asn1 = strdup(cSource->asn1); - } else { - c->asn1 = NULL; - } - - if (cSource->superClass) { - c->superClass = strdup(cSource->superClass); - } else { - c->superClass = NULL; - } - - if (cSource->containedBy) { - c->containedBy = strdup(cSource->containedBy); - } else { - c->containedBy = NULL; - } - - if (cSource->namedBy) { - c->namedBy = strdup(cSource->namedBy); - } else { - c->namedBy = NULL; - } - - if (cSource->mandatory) { - c->mandatory = strdup(cSource->mandatory); - } else { - c->mandatory = NULL; - } - - if (cSource->optional) { - c->optional = strdup(cSource->optional); - } else { - c->optional = NULL; - } - - if (c->superClass) { - MDBFILEAddValue(c->superClass, superclass); - } - - if (c->containedBy) { - ptr = c->containedBy; - - do { - cur = ptr; - ptr = strchr(cur, ','); - if (ptr) { - *ptr = '\0'; - } - - MDBFILEAddValue(cur, containedby); - - if (ptr) { - *ptr = ','; - - ptr++; - } - } while (ptr); - } - - if (c->namedBy) { - ptr = c->namedBy; - - do { - cur = ptr; - ptr = strchr(cur, ','); - if (ptr) { - *ptr = '\0'; - } - - MDBFILEAddValue(cur, naming); - - if (ptr) { - *ptr = ','; - - ptr++; - } - } while (ptr); - } - - if (c->mandatory) { - ptr = c->mandatory; - - do { - cur = ptr; - ptr = strchr(cur, ','); - if (ptr) { - *ptr = '\0'; - } - - MDBFILEAddValue(cur, mandatory); - - if (ptr) { - *ptr = ','; - - ptr++; - } - } while (ptr); - } - - if (c->optional) { - ptr = c->optional; - - do { - cur = ptr; - ptr = strchr(cur, ','); - if (ptr) { - *ptr = '\0'; - } - - MDBFILEAddValue(cur, optional); - - if (ptr) { - *ptr = ','; - - ptr++; - } - } while (ptr); - } - - result = MDBFILEDefineClass(c->name, c->asn1, c->flags & 0x01, superclass, containedby, naming, mandatory, optional, v); - - free(c->name); - c->name = NULL; - - if (c->asn1) { - free(c->asn1); - c->asn1 = NULL; - } - - if (c->superClass) { - free(c->superClass); - c->superClass = NULL; - } - - if (c->containedBy) { - free(c->containedBy); - c->containedBy = NULL; - } - - if (c->namedBy) { - free(c->namedBy); - c->namedBy = NULL; - } - - if (c->mandatory) { - free(c->mandatory); - c->mandatory = NULL; - } - - if (c->optional) { - free(c->optional); - c->optional = NULL; - } - - MDBFILEFreeValues(optional); - MDBFILEFreeValues(mandatory); - MDBFILEFreeValues(naming); - MDBFILEFreeValues(containedby); - MDBFILEFreeValues(superclass); - - cSource++; - } - } - - if (optional) { - MDBFILEDestroyValueStruct(optional); - } - - if (mandatory) { - MDBFILEDestroyValueStruct(mandatory); - } - - if (naming) { - MDBFILEDestroyValueStruct(naming); - } - - if (containedby) { - MDBFILEDestroyValueStruct(containedby); - } - - if (superclass) { - MDBFILEDestroyValueStruct(superclass); - } - - if (c) { - free(c); - } - } - - if (result) { - attributes = MDBFILEShareContext(v); - values = MDBFILEShareContext(v); - - if (attributes && values) { - result = MDBFILECreateObject(MDBFile.localTree, "Top", attributes, values, v); - - if (result) { - MDBFILESetValueStructContext(MDBFile.localTree, v); - - MDBFILEAddValue("SSurname", attributes); - MDBFILEAddValue("Admin", values); - - result = MDBFILECreateObject("admin", "User", attributes, values, v); - - MDBFILEFreeValues(attributes); - MDBFILEFreeValues(values); - - if (result) { - result = MDBFILEChangePasswordEx("admin", NULL, "bongo", v); - } - - MDBFILESetValueStructContext(NULL, v); - } - } - - if (attributes) { - MDBFILEDestroyValueStruct(attributes); - } - - if (values) { - MDBFILEDestroyValueStruct(values); - } - } - - MDBFILEDestroyValueStruct(v); - } else { - result = TRUE; - } - - if (result) { - Init->Interface.MDBAdd=MDBFILEAdd; - Init->Interface.MDBAddAddressRestriction=MDBFILEAddAddressRestriction; - Init->Interface.MDBAddAttribute=MDBFILEAddAttribute; - Init->Interface.MDBAddDN=MDBFILEAddDN; - Init->Interface.MDBAddValue=MDBFILEAddValue; - Init->Interface.MDBAuthenticate=MDBFILEAuthenticateFunction; - Init->Interface.MDBChangePassword=MDBFILEChangePassword; - Init->Interface.MDBChangePasswordEx=MDBFILEChangePasswordEx; - Init->Interface.MDBClear=MDBFILEClear; - Init->Interface.MDBCreateAlias=MDBFILECreateAlias; - Init->Interface.MDBCreateEnumStruct=MDBFILECreateEnumStruct; - Init->Interface.MDBCreateObject=MDBFILECreateObject; - Init->Interface.MDBCreateValueStruct=MDBFILECreateValueStruct; - Init->Interface.MDBDefineAttribute=MDBFILEDefineAttribute; - Init->Interface.MDBDefineClass=MDBFILEDefineClass; - Init->Interface.MDBDeleteObject=MDBFILEDeleteObject; - Init->Interface.MDBDestroyEnumStruct=MDBFILEDestroyEnumStruct; - Init->Interface.MDBDestroyValueStruct=MDBFILEDestroyValueStruct; - Init->Interface.MDBEnumerateAttributesEx=MDBFILEEnumerateAttributesEx; - Init->Interface.MDBEnumerateObjects=MDBFILEEnumerateObjects; - Init->Interface.MDBEnumerateObjectsEx=MDBFILEEnumerateObjectsEx; - Init->Interface.MDBFreeValue=MDBFILEFreeValue; - Init->Interface.MDBFreeValues=MDBFILEFreeValues; - Init->Interface.MDBGetObjectDetails=MDBFILEGetObjectDetails; - Init->Interface.MDBGetObjectDetailsEx=MDBFILEGetObjectDetailsEx; - Init->Interface.MDBGetServerInfo=MDBFILEGetServerInfo; - Init->Interface.MDBGetBaseDN=MDBFILEGetBaseDN; - Init->Interface.MDBGrantAttributeRights=MDBFILEGrantAttributeRights; - Init->Interface.MDBGrantObjectRights=MDBFILEGrantObjectRights; - Init->Interface.MDBIsObject=MDBFILEIsObject; - Init->Interface.MDBListContainableClasses=MDBFILEListContainableClasses; - Init->Interface.MDBListContainableClassesEx=MDBFILEListContainableClassesEx; - Init->Interface.MDBRead=MDBFILERead; - Init->Interface.MDBReadDN=MDBFILEReadDN; - Init->Interface.MDBReadEx=MDBFILEReadEx; - Init->Interface.MDBRelease=MDBFILERelease; - Init->Interface.MDBRemove=MDBFILERemove; - Init->Interface.MDBRemoveDN=MDBFILERemoveDN; - Init->Interface.MDBRenameObject=MDBFILERenameObject; - Init->Interface.MDBSetValueStructContext=MDBFILESetValueStructContext; - Init->Interface.MDBShareContext=MDBFILEShareContext; - Init->Interface.MDBUndefineAttribute=MDBFILEUndefineAttribute; - Init->Interface.MDBUndefineClass=MDBFILEUndefineClass; - Init->Interface.MDBVerifyPassword=MDBFILEVerifyPassword; - Init->Interface.MDBVerifyPasswordEx=MDBFILEVerifyPassword; - Init->Interface.MDBWrite=MDBFILEWrite; - Init->Interface.MDBWriteDN=MDBFILEWriteDN; - Init->Interface.MDBWriteTyped=MDBFILEWriteTyped; - } - - return(result); -} - -EXPORT void -MDBFILEShutdown(void) -{ - MDBFile.unload = TRUE; - - if (MDBFile.log.enabled) { - XplWaitOnLocalSemaphore(MDBFile.log.sem); - - MDBFile.log.enabled = FALSE; - - fclose(MDBFile.log.fh); - - free(MDBFile.log.buffer); - MDBFile.log.buffer = NULL; - MDBFile.log.bufferSize = 0; - - XplCloseLocalSemaphore(MDBFile.log.sem); - } - - if (MDBFile.handles.data) { - unsigned long i; - - XplWaitOnLocalSemaphore(MDBFile.handles.sem); - - for (i = 0; i < MDBFile.handles.used; i++) { - free(MDBFile.handles.data[i]); - } - - free(MDBFile.handles.data); - - XplCloseLocalSemaphore(MDBFile.handles.sem); - } - - return; -} - -#if defined(NETWARE) || defined(LIBC) -int -MDBFILERequestUnload(void) -{ - if (!MDBFile.unload) { - int OldTGid; - - OldTGid=XplSetThreadGroupID(MDBFile.id.group); - - XplConsolePrintf("\rThis NLM will automatically be unloaded by the thread that loaded it.\n"); - XplConsolePrintf("\rIt does not allow manual unloading.\n"); - XplSetCurrentScreen(XplCreateScreen("System Console", 0)); - XplUngetCh('n'); - - XplSetThreadGroupID(OldTGid); - - return(1); - } - - return(0); -} - -void -MDBFILESigHandler(int Signal) -{ - int OldTGid; - - OldTGid=XplSetThreadGroupID(MDBFile.id.group); - - XplSignalLocalSemaphore(MDBFile.sem.shutdown); - XplWaitOnLocalSemaphore(MDBFile.sem.shutdown); - - /* Do any required cleanup */ - MDBFILEShutdown(); - - XplCloseLocalSemaphore(MDBFile.sem.shutdown); - XplSetThreadGroupID(OldTGid); -} - -int -main(int argc, char *argv[]) -{ - MDBFile.id.main=XplGetThreadID(); - MDBFile.id.group=XplGetThreadGroupID(); - - signal(SIGTERM, MDBFILESigHandler); - - /* - 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... - */ - - XplOpenLocalSemaphore(MDBFile.sem.shutdown, 0); - XplWaitOnLocalSemaphore(MDBFile.sem.shutdown); - XplSignalLocalSemaphore(MDBFile.sem.shutdown); - return(0); -} -#endif - -#ifdef WIN32 -BOOL WINAPI -DllMain(HINSTANCE hInst, DWORD Reason, LPVOID Reserved) -{ - if (Reason==DLL_PROCESS_ATTACH) { - DisableThreadLibraryCalls(hInst); - } - - return(TRUE); -} -#endif diff --git a/src/libs/mdb-file/mdbfilep.h b/src/libs/mdb-file/mdbfilep.h deleted file mode 100644 index d336108..0000000 --- a/src/libs/mdb-file/mdbfilep.h +++ /dev/null @@ -1,366 +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 MDBP_H -#define MDBP_H - -/* Little helpers */ -#define MDB_CONTEXT_IS_VALID(ValueStruct) (ValueStruct->Flags & MDB_FLAGS_CONTEXT_VALID) - -/* Bit definitions */ -#define MDB_FLAGS_ALLOCATED_HANDLE (unsigned long)(1<<0) /* The Init function has allocated the handle */ -#define MDB_FLAGS_CONTEXT_VALID (unsigned long)(1<<1) /* The Context handle is valid */ -#define MDB_FLAGS_CONTEXT_DUPLICATE (unsigned long)(1<<2) /* The context handle is duplicated, do not free it */ -#define MDB_FLAGS_BASEDN_CHANGED (unsigned long)(1<<3) /* Caching uses this, if the DN of a context is changed, this is set */ - -#define VALUE_ALLOC_SIZE 20 -#define VALUE_BUFFER_SIZE (10 * 1024) - -#define ERR_NO_SUCH_ENTRY 0xFFFFFDA7 -#define ERR_NO_SUCH_VALUE 0xFFFFFDA6 -#define ERR_NO_SUCH_ATTRIBUTE 0xFFFFFDA5 -#define ERR_NO_SUCH_CLASS 0xFFFFFDA4 -#define ERR_NO_SUCH_PARTITION 0xFFFFFDA3 -#define ERR_ENTRY_ALREADY_EXISTS 0xFFFFFDA2 -#define ERR_NOT_EFFECTIVE_CLASS 0xFFFFFDA1 -#define ERR_ILLEGAL_ATTRIBUTE 0xFFFFFDA0 -#define ERR_MISSING_MANDATORY 0xFFFFFD9F -#define ERR_ILLEGAL_DS_NAME 0xFFFFFD9E -#define ERR_ILLEGAL_CONTAINMENT 0xFFFFFD9D -#define ERR_CANT_HAVE_MULTIPLE_VALUES 0xFFFFFD9C -#define ERR_SYNTAX_VIOLATION 0xFFFFFD9B -#define ERR_DUPLICATE_VALUE 0xFFFFFD9A -#define ERR_ATTRIBUTE_ALREADY_EXISTS 0xFFFFFD99 -#define ERR_MAXIMUM_ENTRIES_EXIST 0xFFFFFD98 -#define ERR_DATABASE_FORMAT 0xFFFFFD97 -#define ERR_INCONSISTENT_DATABASE 0xFFFFFD96 -#define ERR_INVALID_COMPARISON 0xFFFFFD95 -#define ERR_COMPARISON_FAILED 0xFFFFFD94 -#define ERR_TRANSACTIONS_DISABLED 0xFFFFFD93 -#define ERR_INVALID_TRANSPORT 0xFFFFFD92 -#define ERR_SYNTAX_INVALID_IN_NAME 0xFFFFFD91 -#define ERR_TRANSPORT_FAILURE 0xFFFFFD8F -#define ERR_ALL_REFERRALS_FAILED 0xFFFFFD8E -#define ERR_CANT_REMOVE_NAMING_VALUE 0xFFFFFD8D -#define ERR_OBJECT_CLASS_VIOLATION 0xFFFFFD8C -#define ERR_ENTRY_IS_NOT_LEAF 0xFFFFFD8B -#define ERR_DIFFERENT_TREE 0xFFFFFD8A -#define ERR_SYSTEM_FAILURE 0xFFFFFD88 -#define ERR_INVALID_ENTRY_FOR_ROOT 0xFFFFFD87 -#define ERR_NO_REFERRALS 0xFFFFFD86 -#define ERR_REMOTE_FAILURE 0xFFFFFD85 -#define ERR_UNREACHABLE_SERVER 0XFFFFFD84 -#define ERR_NO_CHARACTER_MAPPING 0XFFFFFD82 -#define ERR_INCOMPLETE_AUTHENTICATION 0XFFFFFD81 -#define ERR_INVALID_CERTIFICATE 0xFFFFFD80 -#define ERR_INVALID_REQUEST 0xFFFFFD7F -#define ERR_INVALID_ITERATION 0xFFFFFD7E -#define ERR_SCHEMA_IS_NONREMOVABLE 0xFFFFFD7D -#define ERR_SCHEMA_IS_IN_USE 0xFFFFFD7C -#define ERR_CLASS_ALREADY_EXISTS 0xFFFFFD7B -#define ERR_BAD_NAMING_ATTRIBUTES 0xFFFFFD7A -#define ERR_INSUFFICIENT_STACK 0xFFFFFD78 -#define ERR_INSUFFICIENT_BUFFER 0xFFFFFD77 -#define ERR_AMBIGUOUS_CONTAINMENT 0xFFFFFD76 -#define ERR_AMBIGUOUS_NAMING 0xFFFFFD75 -#define ERR_DUPLICATE_MANDATORY 0xFFFFFD74 -#define ERR_DUPLICATE_OPTIONAL 0xFFFFFD73 -#define ERR_RECORD_IN_USE 0xFFFFFD6C -#define ERR_ENTRY_NOT_CONTAINER 0xFFFFFD64 -#define ERR_FAILED_AUTHENTICATION 0xFFFFFD63 -#define ERR_INVALID_CONTEXT 0xFFFFFD62 -#define ERR_NO_SUCH_PARENT 0xFFFFFD61 -#define ERR_NO_ACCESS 0xFFFFFD60 -#define ERR_INVALID_NAME_SERVICE 0xFFFFFD5E -#define ERR_INVALID_TASK 0xFFFFFD5D -#define ERR_INVALID_CONN_HANDLE 0xFFFFFD5C -#define ERR_INVALID_IDENTITY 0xFFFFFD5B -#define ERR_DUPLICATE_ACL 0xFFFFFD5A -#define ERR_ALIAS_OF_AN_ALIAS 0xFFFFFD57 -#define ERR_INVALID_RDN 0xFFFFFD4E -#define ERR_INCORRECT_BASE_CLASS 0xFFFFFD4C -#define ERR_MISSING_REFERENCE 0xFFFFFD4B -#define ERR_LOST_ENTRY 0xFFFFFD4A -#define ERR_FATAL 0xFFFFFD45 - -typedef struct { - /* Semi-public; known to the main MDB library */ - unsigned char Description[128]; - struct _MDBInterfaceStruct *Interface; - - /* Private */ - unsigned char Dirname[XPL_MAX_PATH + 1]; - BOOL ReadOnly; -} MDBFILEContextStruct; - -typedef MDBFILEContextStruct *MDBHandle; - -typedef struct { - /* Public part, exposed to allow simpler code */ - unsigned char **Value; - unsigned long Used; - unsigned long ErrNo; - struct _MDBInterfaceStruct *Interface; - - /* Private part, not exposed in public header */ - unsigned long Flags; - unsigned long Allocated; - unsigned char *BaseDN; - unsigned char Buffer[VALUE_BUFFER_SIZE]; - unsigned char Path[XPL_MAX_PATH + 1]; - unsigned char Filename[(XPL_MAX_PATH * 4) + 1]; - - MDBFILEContextStruct *Handle; -} MDBValueStruct; - -typedef struct { - BOOL Initialized; - - unsigned int EntriesLeft; - - FILE *File; - - MDBValueStruct *V; - - unsigned char Buffer[VALUE_BUFFER_SIZE]; - unsigned char Filename[(XPL_MAX_PATH * 4) + 1]; - - unsigned long Offset; -} MDBEnumStruct; - -typedef struct _MDBFILEBaseSchemaAttributes { - unsigned char *name; - unsigned long flags; - unsigned long type; - unsigned char *asn1; -} MDBFILEBaseSchemaAttributes; - -typedef struct _MDBFILEBaseSchemaClasses { - unsigned char *name; - unsigned long flags; - unsigned char *asn1; - unsigned char *superClass; - unsigned char *containedBy; - unsigned char *namedBy; - unsigned char *mandatory; - unsigned char *optional; -} MDBFILEBaseSchemaClasses; - -MDBFILEBaseSchemaAttributes MDBFILEBaseSchemaAttributesList[] = { - { "ACL",64,17,"2.16.840.1.113719.1.1.4.1.2" }, - { "Aliased Object Name",69,1,"2.5.4.1" }, - { "Back Link",268,23,"2.16.840.1.113719.1.1.4.1.6" }, - { "Bindery Property",12,32,"2.16.840.1.113719.1.1.4.1.8" }, - { "Bindery Object Restriction",13,8,"2.16.840.1.113719.1.1.4.1.7" }, - { "Bindery Type",45,5,"2.16.840.1.113719.1.1.4.1.9" }, - { "CA Private Key",93,32,"2.16.840.1.113719.1.1.4.1.11" }, - { "CA Public Key",205,32,"2.16.840.1.113719.1.1.4.1.12" }, - { "Cartridge",100,3,"2.16.840.1.113719.1.1.4.1.10" }, - { "CN",102,3,"2.5.4.3" }, - { "Printer Configuration",69,32,"2.16.840.1.113719.1.1.4.1.78" }, - { "Convergence",71,8,"2.16.840.1.113719.1.1.4.1.15" }, - { "C",103,3,"2.5.4.6" }, - { "Default Queue",325,1,"2.16.840.1.113719.1.1.4.1.18" }, - { "Description",102,3,"2.5.4.13" }, - { "Partition Creation Time",205,19,"2.16.840.1.113719.1.1.4.1.64" }, - { "Facsimile Telephone Number",68,11,"2.5.4.23" }, - { "High Convergence Sync Interval",69,27,"2.16.840.1.113719.1.1.4.1.117" }, - { "Group Membership",580,1,"2.16.840.1.113719.1.1.4.1.25" }, - { "Home Directory",71,15,"2.16.840.1.113719.1.1.4.1.26" }, - { "Host Device",69,1,"2.16.840.1.113719.1.1.4.1.27" }, - { "Host Resource Name",101,3,"2.16.840.1.113719.1.1.4.1.28" }, - { "Host Server",69,1,"2.16.840.1.113719.1.1.4.1.29" }, - { "Inherited ACL",76,17,"2.16.840.1.113719.1.1.4.1.30" }, - { "L",102,3,"2.5.4.7" }, - { "Login Allowed Time Map",71,32,"2.16.840.1.113719.1.1.4.1.39" }, - { "Login Disabled",69,7,"2.16.840.1.113719.1.1.4.1.40" }, - { "Login Expiration Time",69,24,"2.16.840.1.113719.1.1.4.1.41" }, - { "Login Grace Limit",69,8,"2.16.840.1.113719.1.1.4.1.42" }, - { "Login Grace Remaining",69,22,"2.16.840.1.113719.1.1.4.1.43" }, - { "Login Intruder Address",69,12,"2.16.840.1.113719.1.1.4.1.44" }, - { "Login Intruder Attempts",69,22,"2.16.840.1.113719.1.1.4.1.45" }, - { "Login Intruder Limit",69,8,"2.16.840.1.113719.1.1.4.1.46" }, - { "Intruder Attempt Reset Interval",69,27,"2.16.840.1.113719.1.1.4.1.31" }, - { "Login Intruder Reset Time",69,24,"2.16.840.1.113719.1.1.4.1.47" }, - { "Login Maximum Simultaneous",69,8,"2.16.840.1.113719.1.1.4.1.48" }, - { "Login Script",69,21,"2.16.840.1.113719.1.1.4.1.49" }, - { "Login Time",5,24,"2.16.840.1.113719.1.1.4.1.50" }, - { "Member",68,1,"2.5.4.31" }, - { "Memory",69,8,"2.16.840.1.113719.1.1.4.1.52" }, - { "EMail Address",228,14,"0.9.2342.19200300.100.1.3" }, - { "Network Address",68,12,"2.16.840.1.113719.1.1.4.1.55" }, - { "Network Address Restriction",68,12,"2.16.840.1.113719.1.1.4.1.56" }, - { "Notify",68,25,"2.16.840.1.113719.1.1.4.1.57" }, - { "Obituary",76,32,"2.16.840.1.113719.1.1.4.1.114" }, - { "Object Class",196,20,"2.5.4.0" }, - { "Operator",324,1,"2.16.840.1.113719.1.1.4.1.59" }, - { "OU",102,3,"2.5.4.11" }, - { "O",102,3,"2.5.4.10" }, - { "Owner",68,1,"2.5.4.32" }, - { "Page Description Language",102,4,"2.16.840.1.113719.1.1.4.1.63" }, - { "Passwords Used",86,32,"2.16.840.1.113719.1.1.4.1.65" }, - { "Password Allow Change",69,7,"2.16.840.1.113719.1.1.4.1.66" }, - { "Password Expiration Interval",69,27,"2.16.840.1.113719.1.1.4.1.67" }, - { "Password Expiration Time",69,24,"2.16.840.1.113719.1.1.4.1.68" }, - { "Password Minimum Length",69,8,"2.16.840.1.113719.1.1.4.1.69" }, - { "Password Required",69,7,"2.16.840.1.113719.1.1.4.1.70" }, - { "Password Unique Required",69,7,"2.16.840.1.113719.1.1.4.1.71" }, - { "Path",68,15,"2.16.840.1.113719.1.1.4.1.72" }, - { "Physical Delivery Office Name",102,3,"2.5.4.19" }, - { "Postal Address",68,18,"2.5.4.16" }, - { "Postal Code",102,3,"2.5.4.17" }, - { "Postal Office Box",102,3,"2.5.4.18" }, - { "Print Job Configuration",69,21,"2.16.840.1.113719.1.1.4.1.80" }, - { "Printer Control",69,21,"2.16.840.1.113719.1.1.4.1.79" }, - { "Private Key",93,32,"2.16.840.1.113719.1.1.4.1.82" }, - { "Profile",69,1,"2.16.840.1.113719.1.1.4.1.83" }, - { "Public Key",205,32,"2.16.840.1.113719.1.1.4.1.84" }, - { "Queue",68,25,"2.16.840.1.113719.1.1.4.1.85" }, - { "Queue Directory",359,3,"2.16.840.1.113719.1.1.4.1.86" }, - { "Reference",1052,1,"2.16.840.1.113719.1.1.4.1.115" }, - { "Replica",204,16,"2.16.840.1.113719.1.1.4.1.88" }, - { "Resource",68,1,"2.16.840.1.113719.1.1.4.1.89" }, - { "Role Occupant",68,1,"2.5.4.33" }, - { "Higher Privileges",836,1,"2.16.840.1.113719.1.1.4.1.116" }, - { "Security Equals",836,1,"2.16.840.1.113719.1.1.4.1.92" }, - { "See Also",68,1,"2.5.4.34" }, - { "Serial Number",102,4,"2.16.840.1.113719.1.1.4.1.94" }, - { "Server",324,1,"2.16.840.1.113719.1.1.4.1.95" }, - { "S",102,3,"2.5.4.8" }, - { "Status",197,8,"2.16.840.1.113719.1.1.4.1.98" }, - { "SA",102,3,"2.5.4.9" }, - { "Supported Typefaces",102,3,"2.16.840.1.113719.1.1.4.1.102" }, - { "Supported Services",102,3,"2.16.840.1.113719.1.1.4.1.101" }, - { "Surname",230,3,"2.5.4.4" }, - { "Telephone Number",100,10,"2.5.4.20" }, - { "Title",102,3,"2.5.4.12" }, - { "Unknown",4,0,"2.16.840.1.113719.1.1.4.1.109" }, - { "User",324,1,"2.16.840.1.113719.1.1.4.1.111" }, - { "Version",231,3,"2.16.840.1.113719.1.1.4.1.112" }, - { "Account Balance",69,22,"2.16.840.1.113719.1.1.4.1.1" }, - { "Allow Unlimited Credit",69,7,"2.16.840.1.113719.1.1.4.1.4" }, - { "Low Convergence Reset Time",69,24,"2.16.840.1.113719.1.1.4.1.118" }, - { "Minimum Account Balance",69,8,"2.16.840.1.113719.1.1.4.1.54" }, - { "Low Convergence Sync Interval",69,27,"2.16.840.1.113719.1.1.4.1.104" }, - { "Device",68,1,"2.16.840.1.113719.1.1.4.1.21" }, - { "Message Server",69,1,"2.16.840.1.113719.1.1.4.1.53" }, - { "Language",69,6,"2.16.840.1.113719.1.1.4.1.34" }, - { "Supported Connections",69,8,"2.16.840.1.113719.1.1.4.1.100" }, - { "Type Creator Map",69,21,"2.16.840.1.113719.1.1.4.1.107" }, - { "UID",69,8,"2.16.840.1.113719.1.1.4.1.108" }, - { "GID",69,8,"2.16.840.1.113719.1.1.4.1.24" }, - { "Unknown Base Class",39,3,"2.16.840.1.113719.1.1.4.1.110" }, - { "Received Up To",204,19,"2.16.840.1.113719.1.1.4.1.87" }, - { "Synchronized Up To",1164,19,"2.16.840.1.113719.1.1.4.1.33" }, - { "Authority Revocation",77,32,"2.16.840.1.113719.1.1.4.1.5" }, - { "Certificate Revocation",77,32,"2.16.840.1.113719.1.1.4.1.13" }, - { "Cross Certificate Pair",68,32,"2.16.840.1.113719.1.1.4.1.17" }, - { "Locked By Intruder",69,7,"2.16.840.1.113719.1.1.4.1.37" }, - { "Printer",68,25,"2.16.840.1.113719.1.1.4.1.77" }, - { "Detect Intruder",69,7,"2.16.840.1.113719.1.1.4.1.20" }, - { "Lockout After Detection",69,7,"2.16.840.1.113719.1.1.4.1.38" }, - { "Intruder Lockout Reset Interval",69,27,"2.16.840.1.113719.1.1.4.1.32" }, - { "Server Holds",68,26,"2.16.840.1.113719.1.1.4.1.96" }, - { "SAP Name",103,3,"2.16.840.1.113719.1.1.4.1.91" }, - { "Volume",69,1,"2.16.840.1.113719.1.1.4.1.113" }, - { "Last Login Time",13,24,"2.16.840.1.113719.1.1.4.1.35" }, - { "Print Server",69,25,"2.16.840.1.113719.1.1.4.1.81" }, - { "NNS Domain",102,3,"2.16.840.1.113719.1.1.4.1.119" }, - { "Full Name",102,3,"2.16.840.1.113719.1.1.4.1.120" }, - { "Partition Control",204,25,"2.16.840.1.113719.1.1.4.1.121" }, - { "Revision",2189,22,"2.16.840.1.113719.1.1.4.1.122" }, - { "Certificate Validity Interval",71,27,"2.16.840.1.113719.1.1.4.1.123" }, - { "External Synchronizer",68,32,"2.16.840.1.113719.1.1.4.1.124" }, - { "Messaging Database Location",69,15,"2.16.840.1.113719.1.1.4.1.125" }, - { "Message Routing Group",68,1,"2.16.840.1.113719.1.1.4.1.126" }, - { "Messaging Server",68,1,"2.16.840.1.113719.1.1.4.1.127" }, - { "Postmaster",68,1,"2.16.840.1.113719.1.1.4.1.128" }, - { "Mailbox Location",197,1,"2.16.840.1.113719.1.1.4.1.162" }, - { "Mailbox ID",231,3,"2.16.840.1.113719.1.1.4.1.163" }, - { "External Name",69,32,"2.16.840.1.113719.1.1.4.1.164" }, - { "Security Flags",69,8,"2.16.840.1.113719.1.1.4.1.165" }, - { "Messaging Server Type",103,3,"2.16.840.1.113719.1.1.4.1.166" }, - { "Last Referenced Time",1029,19,"2.16.840.1.113719.1.1.4.1.167" }, - { "Given Name",230,3,"2.5.4.42" }, - { "Initials",230,3,"2.5.4.43" }, - { "Generational Qualifier",231,3,"2.16.840.1.113719.1.1.4.1.170" }, - { "Profile Membership",580,1,"2.16.840.1.113719.1.1.4.1.171" }, - { "DS Revision",197,8,"2.16.840.1.113719.1.1.4.1.172" }, - { "Supported Gateway",102,3,"2.16.840.1.113719.1.1.4.1.173" }, - { "Equivalent To Me",324,1,"2.16.840.1.113719.1.1.4.1.174" }, - { "Replica Up To",1164,32,"2.16.840.1.113719.1.1.4.1.175" }, - { "Partition Status",1164,32,"2.16.840.1.113719.1.1.4.1.176" }, - { "Permanent Config Parms",196,32,"2.16.840.1.113719.1.1.4.1.177" }, - { "Timezone",133,32,"2.16.840.1.113719.1.1.4.1.178" }, - { "Bindery Restriction Level",5,8,"2.16.840.1.113719.1.1.4.1.179" }, - { "Transitive Vector",2252,32,"2.16.840.1.113719.1.1.4.1.180" }, - { "T",102,3,"2.16.840.1.113719.1.1.4.1.181" }, - { "Purge Vector",3212,19,"2.16.840.1.113719.1.1.4.1.183" }, - { "Synchronization Tolerance",196,19,"2.16.840.1.113719.1.1.4.1.184" }, - { "Password Management",69,0,"2.16.840.1.113719.1.1.4.1.185" }, - { "Used By",332,15,"2.16.840.1.113719.1.1.4.1.186" }, - { "Uses",332,15,"2.16.840.1.113719.1.1.4.1.187" }, - { "Obituary Notify",76,32,"2.16.840.1.113719.1.1.4.1.500" }, - { "GUID",207,32,"2.16.840.1.113719.1.1.4.1.501" }, - { "Other GUID",198,32,"2.16.840.1.113719.1.1.4.1.502" }, - { NULL,0,0,NULL }, -}; - -MDBFILEBaseSchemaClasses MDBFILEBaseSchemaClassesList[] = { - { "[Nothing]",3,NULL,NULL,NULL,NULL,NULL,NULL }, - { "Top",3,"2.5.6.0",NULL,NULL,"T","Object Class,T","CA Public Key,Private Key,Certificate Validity Interval,Authority Revocation,Last Referenced Time,Equivalent To Me,ACL,Back Link,Bindery Property,Obituary,Reference,Revision,Cross Certificate Pair,Certificate Revocation,Used By,GUID,Other GUID" }, - { "Tree Root",3,"2.16.840.1.113719.1.1.6.1.32","Top","[Nothing]",NULL,NULL,NULL }, - { "Alias",2,"2.5.6.1","Top",NULL,NULL,"Aliased Object Name",NULL }, - { "Country",3,"2.5.6.2","Top","Top,Tree Root,[Nothing]","C","C","Description" }, - { "Locality",3,"2.5.6.3","Top","Locality,Country,Organizational Unit,Organization","L,S",NULL,"Description,L,See Also,S,SA" }, - { "Organization",3,"2.5.6.4",NULL,"Top,Tree Root,Country,Locality,[Nothing]","O","O","Description,Facsimile Telephone Number,L,Login Script,EMail Address,Physical Delivery Office Name,Postal Address,Postal Code,Postal Office Box,Print Job Configuration,Printer Control,See Also,S,SA,Telephone Number,Login Intruder Limit,Intruder Attempt Reset Interval,Detect Intruder,Lockout After Detection,Intruder Lockout Reset Interval" }, - { "Organizational Unit",3,"2.5.6.5",NULL,"Locality,Organization,Organizational Unit","OU","OU","Description,Facsimile Telephone Number,L,Login Script,EMail Address,Physical Delivery Office Name,Postal Address,Postal Code,Postal Office Box,Print Job Configuration,Printer Control,See Also,S,SA,Telephone Number,Login Intruder Limit,Intruder Attempt Reset Interval,Detect Intruder,Lockout After Detection,Intruder Lockout Reset Interval" }, - { "Organizational Role",2,"2.5.6.8","Top","Organization,Organizational Unit","CN","CN","Description,Facsimile Telephone Number,L,EMail Address,OU,Physical Delivery Office Name,Postal Address,Postal Code,Postal Office Box,Role Occupant,See Also,S,SA,Telephone Number,Mailbox Location,Mailbox ID" }, - { "Group",2,"2.5.6.17","Top","Organization,Organizational Unit","CN","CN","Description,L,Member,OU,O,Owner,See Also,GID,Full Name,EMail Address,Mailbox Location,Mailbox ID,Profile,Profile Membership,Login Script" }, - { "Person",2,"2.5.6.6",NULL,"Organization,Organizational Unit","CN","CN","Description,See Also,Telephone Number,Full Name,Given Name,Initials,Generational Qualifier" }, - { "Organizational Person",2,"2.5.6.7","Person","Organization,Organizational Unit","CN,OU",NULL,"Facsimile Telephone Number,L,EMail Address,OU,Physical Delivery Office Name,Postal Address,Postal Code,Postal Office Box,S,SA,Title,Mailbox Location,Mailbox ID" }, - { "User",2,"2.5.6.10","Organizational Person",NULL,NULL,NULL,"Group Membership,Home Directory,Login Allowed Time Map,Login Disabled,Login Expiration Time,Login Grace Limit,Login Grace Remaining,Login Intruder Address,Login Intruder Attempts,Login Intruder Reset Time,Login Maximum Simultaneous,Login Script,Login Time,Network Address Restriction,Network Address,Passwords Used,Password Allow Change,Password Expiration Interval,Password Expiration Time,Password Minimum Length,Password Required,Password Unique Required,Print Job Configuration,Private Key,Profile,Public Key,Security Equals,Account Balance,Allow Unlimited Credit,Minimum Account Balance,Message Server,Language,UID,Locked By Intruder,Server Holds,Last Login Time,Type Creator Map,Higher Privileges,Printer Control,Security Flags,Profile Membership,Timezone" }, - { "Device",2,"2.16.840.1.113719.1.1.6.1.6","Top","Organization,Organizational Unit","CN","CN","Description,L,Network Address,OU,O,Owner,See Also,Serial Number" }, - { "Computer",2,"2.16.840.1.113719.1.1.6.1.4","Device",NULL,NULL,NULL,"Operator,Server,Status" }, - { "Printer",2,"2.16.840.1.113719.1.1.6.1.17","Device",NULL,NULL,NULL,"Cartridge,Printer Configuration,Default Queue,Host Device,Print Server,Memory,Network Address Restriction,Notify,Operator,Page Description Language,Queue,Status,Supported Typefaces" }, - { "Resource",0,"2.16.840.1.113719.1.1.6.1.21","TOp","Organization,Organizational Unit","CN","CN","Description,Host Resource Name,L,OU,O,See Also,Uses" }, - { "Queue",2,"2.16.840.1.113719.1.1.6.1.20","Resource",NULL,NULL,"Queue Directory","Device,Operator,Server,User,Network Address,Volume,Host Server" }, - { "Bindery Queue",2,"2.16.840.1.113719.1.1.6.1.3","Queue",NULL,"CN","Bindery Type",NULL }, - { "Volume",2,"2.16.840.1.113719.1.1.6.1.26","Resource",NULL,NULL,"Host Server","Status" }, - { "Directory Map",2,"2.16.840.1.113719.1.1.6.1.7","Resource",NULL,NULL,"Host Server","Path" }, - { "Profile",2,"2.16.840.1.113719.1.1.6.1.19","Top","Organization,Organizational Unit","CN","CN,Login Script","Description,L,OU,O,See Also,Full Name" }, - { "Server",0,"2.16.840.1.113719.1.1.6.1.22","Top","Organization,Organizational Unit","CN","CN","Description,Host Device,L,OU,O,Private Key,Public Key,Resource,See Also,Status,User,Version,Network Address,Account Balance,Allow Unlimited Credit,Minimum Account Balance,Full Name,Security Equals,Security Flags,Timezone" }, - { "NCP Server",2,"2.16.840.1.113719.1.1.6.1.10","Server",NULL,NULL,NULL,"Operator,Supported Services,Messaging Server,DS Revision,Permanent Config Parms" }, - { "Print Server",2,"2.16.840.1.113719.1.1.6.1.18","Server",NULL,NULL,NULL,"Operator,Printer,SAP Name" }, - { "CommExec",2,"2.16.840.1.113719.1.1.6.1.31","Server",NULL,NULL,NULL,"Network Address Restriction" }, - { "Bindery Object",2,"2.16.840.1.113719.1.1.6.1.2","Top","Organization,Organizational Unit","CN,Bindery Type","Bindery Object Restriction,Bindery Type,CN",NULL }, - { "Unknown",3,"2.16.840.1.113719.1.1.6.1.24","Top",NULL,NULL,NULL,NULL }, - { "Partition",0,"2.16.840.1.113719.1.1.6.1.15",NULL,NULL,NULL,NULL,"Convergence,Partition Creation Time,Replica,Inherited ACL,Low Convergence Sync Interval,Received Up To,Synchronized Up To,Authority Revocation,Certificate Revocation,CA Private Key,CA Public Key,Cross Certificate Pair,Low Convergence Reset Time,High Convergence Sync Interval,Partition Control,Replica Up To,Partition Status,Transitive Vector,Purge Vector,Synchronization Tolerance,Obituary Notify,Local Received Up To" }, - { "AFP Server",2,"2.16.840.1.113719.1.1.6.1.0","Server",NULL,NULL,NULL,"Serial Number,Supported Connections" }, - { "Messaging Server",2,"2.16.840.1.113719.1.1.6.1.27","Server",NULL,NULL,NULL,"Messaging Database Location,Message Routing Group,Postmaster,Supported Services,Messaging Server Type,Supported Gateway" }, - { "Message Routing Group",2,"2.16.840.1.113719.1.1.6.1.28","Group",NULL,NULL,NULL,NULL }, - { "External Entity",2,"2.16.840.1.113719.1.1.6.1.29","Top","Organization,Organizational Unit","CN,OU","CN","Description,See Also,Facsimile Telephone Number,L,EMail Address,OU,Physical Delivery Office Name,Postal Address,Postal Code,Postal Office Box,S,SA,Title,External Name,Mailbox Location,Mailbox ID" }, - { "List",2,"2.16.840.1.113719.1.1.6.1.30","Top","Organization,Organizational Unit","CN","CN","Description,L,Member,OU,O,EMail Address,Mailbox Location,Mailbox ID,Owner,See Also,Full Name" }, - { NULL,0,NULL,NULL,NULL,NULL,NULL,NULL } -}; - -#endif /* MDBP_H */ diff --git a/src/libs/mdb-odbc/Makefile.am b/src/libs/mdb-odbc/Makefile.am deleted file mode 100644 index 84464a4..0000000 --- a/src/libs/mdb-odbc/Makefile.am +++ /dev/null @@ -1,20 +0,0 @@ -INCLUDES= \ - $(ALL_CFLAGS) \ - -I$(top_srcdir)/include \ - -DLOCALSTATEDIR=\""$(localstatedir)"\" \ - -DMDB_INTERNAL - -LIBS= -lodbc - -mdbdir=$(libdir)/bongomdb - -mdb_LTLIBRARIES=libmdbodbc.la - -libmdbodbc_la_SOURCES = \ - mdbodbc.c \ - mdbodbcp.h - -libmdbodbc_la_LDFLAGS = -module -avoid-version -libmdbodbc_la_LIBADD = \ - ../bongoutil/libbongoutil.la \ - ../xpl/libbongoxpl.la diff --git a/src/libs/mdb-odbc/mdbodbc.c b/src/libs/mdb-odbc/mdbodbc.c deleted file mode 100644 index 4c6ca10..0000000 --- a/src/libs/mdb-odbc/mdbodbc.c +++ /dev/null @@ -1,4466 +0,0 @@ -/* Product defines */ -#define PRODUCT_NAME "MDB ODBC Driver" -#define PRODUCT_VERSION "$Revision: 1.1 $" - -#include -#include -#include -#include - -#include -#include - -#include -#include -#include - -#include "mdbodbcp.h" -#include - -struct { - BOOL unload; - - struct { - XplSemaphore shutdown; - } sem; - - struct { - XplThreadID main; - XplThreadID group; - } id; - - struct { - unsigned char dsn[256 + 1]; - unsigned char user[256 + 1]; - unsigned char pass[256 + 1]; - unsigned char servername[64 + 1]; - unsigned char treename[64 + 1]; - unsigned long treenameLength; - - SQLINTEGER defaultContext; - - /* Special Attibutes, which require extra actions */ - struct { - SQLINTEGER member; - } special; - } config; - - SQLHENV env; -} MDBodbc; - -/* Prototypes for registration functions */ - -BOOL MDBodbcGetServerInfo(unsigned char *ServerDN, unsigned char *ServerTree, MDBValueStruct *V); -char *MDBodbcGetServerInfo(MDBValueStruct *V); -MDBHandle MDBodbcAuthenticate(const unsigned char *Object, const unsigned char *Password, const unsigned char *Arguments); -BOOL MDBodbcRelease(MDBHandle Context); -MDBValueStruct *MDBodbcCreateValueStruct(MDBHandle Handle, const unsigned char *Context); -BOOL MDBodbcFreeValues(MDBValueStruct *V); -BOOL MDBodbcDestroyValueStruct(MDBValueStruct *V); -MDBEnumStruct *MDBodbcCreateEnumStruct(MDBValueStruct *V); -BOOL MDBodbcDestroyEnumStruct(MDBEnumStruct *ES, MDBValueStruct *V); -BOOL MDBodbcSetValueStructContext(const unsigned char *Context, MDBValueStruct *V); -MDBValueStruct *MDBodbcShareContext(MDBValueStruct *V); -BOOL MDBodbcAddValue(const unsigned char *Value, MDBValueStruct *V); -BOOL MDBodbcFreeValue(unsigned long Index, MDBValueStruct *V); -BOOL MDBodbcDefineAttribute(const unsigned char *Attribute, const unsigned char *ASN1, unsigned long Type, BOOL SingleValue, BOOL ImmediateSync, BOOL Public, MDBValueStruct *V); -BOOL MDBodbcAddAttribute(const unsigned char *Attribute, const unsigned char *Class, MDBValueStruct *V); -BOOL MDBodbcUndefineAttribute(const unsigned char *Attribute, MDBValueStruct *V); -BOOL MDBodbcDefineClass(const unsigned char *Class, const unsigned char *ASN1, BOOL Container, MDBValueStruct *Superclass, MDBValueStruct *Containment, MDBValueStruct *Naming, MDBValueStruct *Mandatory, MDBValueStruct *Optional, MDBValueStruct *V); -BOOL MDBodbcUndefineClass(const unsigned char *Class, MDBValueStruct *V); -static __inline BOOL MDBodbcUndefineClassByID(unsigned long class, MDBValueStruct *V); -BOOL MDBodbcListContainableClasses(const unsigned char *Object, MDBValueStruct *V); -BOOL MDBodbcWriteTyped(const unsigned char *Object, const unsigned char *Attribute, const int AttrType, MDBValueStruct *V); -BOOL MDBodbcWrite(const unsigned char *Object, const unsigned char *AttributeIn, MDBValueStruct *V); -BOOL MDBodbcWriteDN(const unsigned char *Object, const unsigned char *AttributeIn, MDBValueStruct *V); -BOOL MDBodbcAdd(const unsigned char *Object, const unsigned char *Attribute, const unsigned char *Value, MDBValueStruct *V); -BOOL MDBodbcAddDN(const unsigned char *Object, const unsigned char *Attribute, const unsigned char *Value, MDBValueStruct *V); -BOOL MDBodbcRemove(const unsigned char *Object, const unsigned char *Attribute, const unsigned char *Value, MDBValueStruct *V); -BOOL MDBodbcRemoveDN(const unsigned char *Object, const unsigned char *Attribute, const unsigned char *Value, MDBValueStruct *V); -BOOL MDBodbcClear(const unsigned char *Object, const unsigned char *Attribute, MDBValueStruct *V); -BOOL MDBodbcIsObject(const unsigned char *Object, MDBValueStruct *V); -BOOL MDBodbcGetObjectDetails(const unsigned char *Object, unsigned char *Type, unsigned char *RDN, unsigned char *DN, MDBValueStruct *V); -BOOL MDBodbcGetObjectDetailsEx(const unsigned char *Object, MDBValueStruct *Types, unsigned char *RDN, unsigned char *DN, MDBValueStruct *V); -BOOL MDBodbcVerifyPassword(const unsigned char *Object, const unsigned char *Password, MDBValueStruct *V); -BOOL MDBodbcChangePassword(const unsigned char *Object, const unsigned char *OldPassword, const unsigned char *NewPassword, MDBValueStruct *V); -BOOL MDBodbcChangePasswordEx(const unsigned char *Object, const unsigned char *OldPassword, const unsigned char *NewPassword, MDBValueStruct *V); -BOOL MDBodbcCreateAlias(const unsigned char *Alias, const unsigned char *AliasedObjectDn, MDBValueStruct *V); -BOOL MDBodbcCreateObject(const unsigned char *Object, const unsigned char *Class, MDBValueStruct *Attribute, MDBValueStruct *Data, MDBValueStruct *V); -BOOL MDBodbcDeleteObject(const unsigned char *Object, BOOL Recursive, MDBValueStruct *V); -static __inline BOOL MDBodbcDeleteObjectByID(signed long id, BOOL Recursive, MDBValueStruct *V); -BOOL MDBodbcRenameObject(const unsigned char *ObjectOld, const unsigned char *ObjectNew, MDBValueStruct *V); -BOOL MDBodbcGrantObjectRights(const unsigned char *Object, const unsigned char *TrusteeDN, BOOL Read, BOOL Write, BOOL Delete, BOOL Rename, BOOL Admin, MDBValueStruct *V); -BOOL MDBodbcGrantAttributeRights(const unsigned char *Object, const unsigned char *Attribute, const unsigned char *TrusteeDN, BOOL Read, BOOL Write, BOOL Admin, MDBValueStruct *V); - -const unsigned char *MDBodbcListContainableClassesEx(const unsigned char *Object, MDBEnumStruct *E, MDBValueStruct *V); -const unsigned char *MDBodbcReadEx(const unsigned char *Object, const unsigned char *Attribute, MDBEnumStruct *E, MDBValueStruct *V); -const unsigned char *MDBodbcEnumerateAttributesEx(const unsigned char *Object, MDBEnumStruct *E, MDBValueStruct *V); -const unsigned char *MDBodbcEnumerateObjectsEx(const unsigned char *Container, const unsigned char *Type, const unsigned char *Pattern, unsigned long Flags, MDBEnumStruct *E, MDBValueStruct *V); - -long MDBodbcRead(const unsigned char *Object, const unsigned char *Attribute, MDBValueStruct *V); -long MDBodbcEnumerateObjects(const unsigned char *Container, const unsigned char *Type, const unsigned char *Pattern, MDBValueStruct *V); - -EXPORT BOOL MDBODBCInit(MDBDriverInitStruct *Init); -EXPORT void MDBODBCShutdown(void); - -void PrintSQLError(MDBValueStruct *V, HSTMT stmt); -static __inline BOOL MDBodbcGetObjectID(const unsigned char *dn, SQLINTEGER *id, SQLINTEGER *class, BOOL *read, BOOL *write, BOOL *delete, BOOL *rename, MDBValueStruct *V); -static __inline BOOL MDBodbcGetObjectDN(unsigned char *dn, const unsigned long maxlength, const signed long id, BOOL relative, MDBValueStruct *V); -static __inline BOOL MDBodbcWriteAny(const unsigned char *Object, const unsigned char *Attribute, const unsigned char Type, const BOOL clear, const unsigned char *Value, MDBValueStruct *V); - -/* Prototype for placeholder */ -BOOL MWHandleNamedTemplate(void *ignored1, unsigned char *ignored2, void *ignored3); - -#define PrepareStatement(stmt, sql, requireBindings, V) \ -{ \ - (requireBindings) = FALSE; \ - \ - if ((stmt) == SQL_NULL_HSTMT) { \ - signed long prepareRC; \ - \ - prepareRC = SQLAllocHandle(SQL_HANDLE_STMT, (V)->handle->connection, &(stmt)); \ - if (prepareRC == SQL_SUCCESS || prepareRC == SQL_SUCCESS_WITH_INFO) { \ - prepareRC = SQLPrepare((stmt), (sql), SQL_NTS); \ - (V)->statementCount++; \ - } \ - \ - if (prepareRC == SQL_SUCCESS || prepareRC == SQL_SUCCESS_WITH_INFO) { \ - (requireBindings) = TRUE; \ - } \ - } \ -} - -#define ReleaseStatement(V, stmt) \ -{ \ - if ((stmt) != SQL_NULL_HSTMT) { \ - (V)->statementCount--; \ - SQLFreeHandle(SQL_HANDLE_STMT, (stmt)); \ - } \ -} - -#ifdef DEBUG -#define ExecuteStatement(stmt) (printf("%s:%d\n", __FILE__, __LINE__) && \ - DebugExecuteStatement((stmt))) - -static __inline SQLRETURN -DebugExecuteStatement(SQLHSTMT stmt) -{ - SQLRETURN rc = SQLExecute(stmt); - if (rc < 0) { - PrintSQLError(NULL, stmt); - } - - return(rc); -} -#else -#define ExecuteStatement(stmt) SQLExecute((stmt)) -#endif - -#define BindLongInput(stmt, position, paramAddr) \ -{ \ - SQLBindParameter((stmt), (position), SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER, \ - 0, 0, (paramAddr), 0, NULL); \ -} - -#define BindCharInput(stmt, position, stringAddr, lengthAddr, size) \ -{ \ - SQLBindParameter((stmt), (position), SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, \ - (size), 0, (stringAddr), 0, (lengthAddr)); \ -} - -#define BindLongResult(stmt, position, resultAddr) \ -{ \ - SQLBindCol((stmt), (position), SQL_C_ULONG, (resultAddr), 0, NULL); \ -} - -#define BindCharResult(stmt, position, resultAddr, resultSize) \ -{ \ - SQLBindCol((stmt), (position), SQL_C_CHAR, &resultAddr, resultSize, NULL); \ -} - -#define StoreCharInput(string, stringAddr, length, maxLength) \ -{ \ - (length) = strlen((string)); \ - if ((length) >= (maxLength)) { \ - (length) = (maxLength); \ - } \ - \ - strncpy((stringAddr), (string), (length)); \ - (stringAddr)[(length)] = '\0'; \ -} - - -#define PrintSQLErr(V, stmt) \ -{ \ - XplConsolePrintf("SQL Error\n %s:%d\n", __FILE__, __LINE__); \ - \ - PrintSQLError((V), (stmt)); \ -} - -void -PrintSQLError(MDBValueStruct *V, HSTMT stmt) -{ - SQLCHAR state[6]; - SQLCHAR msg[SQL_MAX_MESSAGE_LENGTH]; - SQLSMALLINT len; - SQLINTEGER nativeError; - SQLSMALLINT i; - SQLRETURN rc; - - i = 1; - if (MDBodbc.env != SQL_NULL_HENV) { - while ((rc = SQLGetDiagRec(SQL_HANDLE_ENV, (SQLHANDLE)MDBodbc.env, i, state, &nativeError, - msg, sizeof(msg), &len)) == SQL_SUCCESS) - { - XplConsolePrintf(" SQLSTATE = %s\n", state); - XplConsolePrintf(" NATIVE ERROR = %ld\n", nativeError); - XplConsolePrintf(" MSG = %s\n\n", msg); - - i++; - } - } - - if (V && V->handle && V->handle->connection != SQL_NULL_HDBC) { - i = 1; - while ((rc = SQLGetDiagRec(SQL_HANDLE_DBC, (SQLHANDLE)V->handle->connection, i, state, &nativeError, - msg, sizeof(msg), &len)) != SQL_NO_DATA) - { - XplConsolePrintf(" SQLSTATE = %s\n", state); - XplConsolePrintf(" NATIVE ERROR = %ld\n", nativeError); - XplConsolePrintf(" MSG = %s\n\n", msg); - - i++; - } - } - - if (stmt != SQL_NULL_HSTMT) { - i = 1; - while ((rc = SQLGetDiagRec(SQL_HANDLE_STMT, (SQLHANDLE)stmt, i, state, &nativeError, - msg, sizeof(msg), &len)) != SQL_NO_DATA) - { - XplConsolePrintf(" SQLSTATE = %s\n", state); - XplConsolePrintf(" NATIVE ERROR = %ld\n", nativeError); - XplConsolePrintf(" MSG = %s\n\n", msg); - - i++; - } - } -} - -static __inline BOOL -MDBodbcGetObjectID(const unsigned char *dn, SQLINTEGER *id, SQLINTEGER *class, BOOL *read, BOOL *write, BOOL *delete, BOOL *rename, MDBValueStruct *V) -{ - if (dn && id) { - SQLINTEGER rc; - BOOL requireBindings; - BOOL r; - BOOL w; - BOOL d; - BOOL n; - unsigned long now = time(NULL); - - if (now <= V->cache.time + 5 && XplStrCaseCmp(dn, V->cache.dn) == 0) { - /* The value is in the cache, and is still valid */ - if (read) { - *read = V->cache.read; - } - - if (write) { - *write = V->cache.write; - } - - if (delete) { - *delete = V->cache.delete; - } - - if (rename) { - *rename = V->cache.rename; - } - - if (class) { - *class = V->cache.class; - } - - *id = V->cache.id; - - return(TRUE); - } - - PrepareStatement(V->stmts.getRootRights, SQL_GET_ROOT_RIGHTS, requireBindings, V); - if (requireBindings) { - BindLongInput(V->stmts.getRootRights, 1, &V->handle->object); - - BindLongResult(V->stmts.getRootRights, 1, &V->params.getRootRights.read); - BindLongResult(V->stmts.getRootRights, 2, &V->params.getRootRights.write); - BindLongResult(V->stmts.getRootRights, 3, &V->params.getRootRights.delete); - BindLongResult(V->stmts.getRootRights, 4, &V->params.getRootRights.rename); - } - - PrepareStatement(V->stmts.getObjectID, SQL_GET_OBJECT_ID, requireBindings, V); - if (requireBindings) { - BindCharInput(V->stmts.getObjectID, 1, - &V->params.getObjectID.object, &V->params.getObjectID.objectLength, MDB_ODBC_NAME_SIZE); - BindLongInput(V->stmts.getObjectID, 2, &V->params.getObjectID.id); - BindLongInput(V->stmts.getObjectID, 3, &V->handle->object); - - /* Resulting object id */ - BindLongResult(V->stmts.getObjectID, 1, &V->params.getObjectID.id); - BindLongResult(V->stmts.getObjectID, 2, &V->params.getObjectID.class); - - /* Rights if specified */ - BindLongResult(V->stmts.getObjectID, 3, &V->params.getObjectID.read); - BindLongResult(V->stmts.getObjectID, 4, &V->params.getObjectID.write); - BindLongResult(V->stmts.getObjectID, 5, &V->params.getObjectID.delete); - BindLongResult(V->stmts.getObjectID, 6, &V->params.getObjectID.rename); - } - - if (V->stmts.getObjectID != SQL_NULL_HSTMT) { - unsigned char *s = (unsigned char *)dn; - unsigned char *e; - - if (*s == '\\') { - - /* - Check for rights assigned to this object at the root. If there are any, use those. If not then - use the default, (ie readonly). - */ - rc = ExecuteStatement(V->stmts.getRootRights); - if (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) { - rc = SQLFetch(V->stmts.getRootRights); - SQLCloseCursor(V->stmts.getRootRights); - } - - if (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) { - r = V->params.getRootRights.read; - w = V->params.getRootRights.write; - d = V->params.getRootRights.delete; - n = V->params.getRootRights.rename; - } else { - /* Set the default rights */ - r = TRUE; - w = FALSE; - d = FALSE; - n = FALSE; - } - - V->params.getObjectID.id = MDB_ODBC_ROOT_ID; - s++; - } else { - V->params.getObjectID.id = *V->base.id; - - /* Set the default rights */ - r = *V->base.read; - w = *V->base.write; - d = *V->base.delete; - n = *V->base.rename; - } - - do { - while (*s == '\\') { - s++; - } - - e = strchr(s, '\\'); - - if (*s) { - V->params.getObjectID.objectLength = (e) ? (unsigned long) (e - s) : strlen(s); - if (V->params.getObjectID.objectLength >= MDB_ODBC_NAME_SIZE) { - V->params.getObjectID.objectLength = MDB_ODBC_NAME_SIZE; - } - - strncpy(V->params.getObjectID.object, s, V->params.getObjectID.objectLength); - V->params.getObjectID.object[V->params.getObjectID.objectLength] = '\0'; - } else { - V->params.getObjectID.objectLength = strlen(MDBodbc.config.treename); - strcpy(V->params.getObjectID.object, MDBodbc.config.treename); - } - - /* Ok, we're all setup - Do the query */ - rc = ExecuteStatement(V->stmts.getObjectID); - if (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) { - rc = SQLFetch(V->stmts.getObjectID); - SQLCloseCursor(V->stmts.getObjectID); - - if (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) { - if (V->params.getObjectID.read >= 0) { - r = (V->params.getObjectID.read == 1); - } - - if (V->params.getObjectID.write >= 0) { - w = (V->params.getObjectID.write == 1); - } - - if (V->params.getObjectID.delete >= 0) { - d = (V->params.getObjectID.delete == 1); - } - - if (V->params.getObjectID.rename >= 0) { - n = (V->params.getObjectID.rename == 1); - } - } - } - - s = e; - } while (s && *(s++) && (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO)); - - if (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) { - *id = V->params.getObjectID.id; - - if (class) { - *class = V->params.getObjectID.class; - } - - if (read) { - *read = r; - } - - if (write) { - *write = w; - } - - if (delete) { - *delete = d; - } - - if (rename) { - *rename = n; - } - - /* Store the cached value */ - V->cache.read = r; - V->cache.write = w; - V->cache.delete = d; - V->cache.rename = n; - - V->cache.id = *id; - V->cache.class = V->params.getObjectID.class; - V->cache.time = now; - - strcpy(V->cache.dn, dn); - - return(TRUE); - } - } - } - - V->ErrNo = ERR_NO_SUCH_ENTRY; - - return(FALSE); -} - -static __inline BOOL MDBodbcGetObjectDN(unsigned char *dn, const unsigned long maxlength, const signed long id, BOOL relative, MDBValueStruct *V) -{ - unsigned char *s = dn; - signed long i; - signed long u; - BOOL requireBindings; - BOOL result = TRUE; - - if (!dn || !V) { - return(FALSE); - } - - u = (signed long) V->Used; - - PrepareStatement(V->stmts.getParentInfo, SQL_GET_PARENT_INFO, requireBindings, V); - if (requireBindings) { - BindLongInput(V->stmts.getParentInfo, 1, &V->params.getParentInfo.object); - BindLongResult(V->stmts.getParentInfo, 1, &V->params.getParentInfo.object); - BindCharResult(V->stmts.getParentInfo, 2, V->params.getParentInfo.name, MDB_ODBC_NAME_SIZE); - } - - if (V->stmts.getParentInfo == SQL_NULL_HSTMT) { - return(FALSE); - } - - V->params.getParentInfo.object = id; - - do { - SQLINTEGER rc; - - /* Ok, do it */ - rc = ExecuteStatement(V->stmts.getParentInfo); - if (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) { - rc = SQLFetch(V->stmts.getParentInfo); - SQLCloseCursor(V->stmts.getParentInfo); - } - - if (V->params.getParentInfo.object == id) { - /* We need to be sure we are not looping */ - break; - } - - if (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) { - MDBodbcAddValue(V->params.getParentInfo.name, V); - } else { - result = FALSE; - break; - } - } while (V->params.getParentInfo.object != -1 && (!relative || V->params.getParentInfo.object != *(V->base.id))); - - /* If relative is true, then we can be relative even to the root */ - if (V->params.getParentInfo.object == -1 && !relative) { - s += sprintf(s, "\\%s\\", MDBodbc.config.treename); - } - - if (result) { - for (i = V->Used - 1; i >= u ; i--) { - if ((s - dn) + strlen(V->Value[i]) < maxlength) { - s += sprintf(s, "%s\\", V->Value[i]); - } else { - result = FALSE; - break; - } - } - } - - if (result) { - /* Cut off the trailing slash */ - *--s = '\0'; - } - - while (V->Used > (unsigned long)u) { - MDBodbcFreeValue(u, V); - } - - return(result); -} - -static __inline BOOL -MDBodbcRemoveInheritedRights(SQLINTEGER trustee, BOOL first, SQLINTEGER provider, MDBValueStruct *V) -{ - SQLHSTMT getChildrenIDs = SQL_NULL_HSTMT; - SQLINTEGER child; - SQLINTEGER rc; - BOOL requireBindings; - - if (first) { - PrepareStatement(V->stmts.getRightsProviders, SQL_GET_RIGHTS_PROVIDERS, requireBindings, V); - if (requireBindings) { - BindLongInput(V->stmts.getRightsProviders, 1, &V->params.getRightsProviders.trustee); - BindLongResult(V->stmts.getRightsProviders, 1, &V->params.getRightsProviders.provider); - } - - V->params.getRightsProviders.trustee = trustee; - - rc = ExecuteStatement(V->stmts.getRightsProviders); - if (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) { - rc = SQLFetch(V->stmts.getRightsProviders); - - while (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) { - if (!MDBodbcRemoveInheritedRights(trustee, FALSE, V->params.getRightsProviders.provider, V)) { - SQLCloseCursor(V->stmts.getRightsProviders); - return(FALSE); - } - - rc = SQLFetch(V->stmts.getRightsProviders); - } - SQLCloseCursor(V->stmts.getRightsProviders); - } - } else { - PrepareStatement(V->stmts.delRightsByChild, SQL_DEL_RIGHTS_BY_CHILD, requireBindings, V); - if (requireBindings) { - BindLongInput(V->stmts.delRightsByChild, 1, &V->params.delRightsByChild.provider); - BindLongInput(V->stmts.delRightsByChild, 2, &V->params.delRightsByChild.trustee); - } - - V->params.delRightsByChild.provider = provider; - V->params.delRightsByChild.trustee = trustee; - - rc = ExecuteStatement(V->stmts.delRightsByChild); - if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO && rc != SQL_NO_DATA) { - return(FALSE); - } - - /* Get the children */ - PrepareStatement(getChildrenIDs, SQL_GET_CHILDREN_IDS, requireBindings, V); - if (requireBindings) { - BindLongInput(getChildrenIDs, 1, &trustee); - BindLongResult(getChildrenIDs, 1, &child); - } - - if (getChildrenIDs == SQL_NULL_HSTMT) { - return(FALSE); - } - - rc = ExecuteStatement(getChildrenIDs); - if (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) { - rc = SQLFetch(getChildrenIDs); - } - - while (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) { - if (!MDBodbcRemoveInheritedRights(child, FALSE, provider, V)) { - ReleaseStatement(V, getChildrenIDs); - return(FALSE); - } - - rc = SQLFetch(getChildrenIDs); - } - - ReleaseStatement(V, getChildrenIDs); - if (rc != SQL_NO_DATA) { - return(FALSE); - } - } - - return(TRUE); -} - -static __inline BOOL -MDBodbcCopyObjectRights(SQLINTEGER trustee, SQLINTEGER parent, BOOL fromParent, MDBValueStruct *V) -{ - SQLHSTMT getChildrenIDs = SQL_NULL_HSTMT; - SQLINTEGER child; - SQLINTEGER rc; - BOOL requireBindings; - - PrepareStatement(V->stmts.setRights, SQL_SET_RIGHTS, requireBindings, V); - if (requireBindings) { - BindLongInput(V->stmts.setRights, 1, &V->params.setGetRights.object); - BindLongInput(V->stmts.setRights, 2, &V->params.setGetRights.trustee); - BindLongInput(V->stmts.setRights, 3, &V->params.setGetRights.provider); - BindLongInput(V->stmts.setRights, 4, &V->params.setGetRights.parent); - BindLongInput(V->stmts.setRights, 5, &V->params.setGetRights.read); - BindLongInput(V->stmts.setRights, 6, &V->params.setGetRights.write); - BindLongInput(V->stmts.setRights, 7, &V->params.setGetRights.delete); - BindLongInput(V->stmts.setRights, 8, &V->params.setGetRights.rename); - } - - PrepareStatement(V->stmts.getRights, SQL_GET_RIGHTS, requireBindings, V); - if (requireBindings) { - BindLongInput(V->stmts.getRights, 1, &V->params.setGetRights.trustee); - - BindLongResult(V->stmts.getRights, 1, &V->params.setGetRights.provider); - BindLongResult(V->stmts.getRights, 2, &V->params.setGetRights.object); - BindLongResult(V->stmts.getRights, 3, &V->params.setGetRights.read); - BindLongResult(V->stmts.getRights, 4, &V->params.setGetRights.write); - BindLongResult(V->stmts.getRights, 5, &V->params.setGetRights.delete); - BindLongResult(V->stmts.getRights, 6, &V->params.setGetRights.rename); - } - - V->params.setGetRights.trustee = parent; - - /* - Get each set of rights assigned to the parent, and add a copy to each - child. This has to be done as seperate queries because some ODBC drivers - do not support INSERT using data from a SELECT that uses the same table. - */ - rc = ExecuteStatement(V->stmts.getRights); - if (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) { - rc = SQLFetch(V->stmts.getRights); - } - - while (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) { - V->params.setGetRights.trustee = trustee; - V->params.setGetRights.parent = fromParent ? 1 : 0; - - rc = ExecuteStatement(V->stmts.setRights); - - if (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) { - rc = SQLFetch(V->stmts.getRights); - } - } - - SQLCloseCursor(V->stmts.getRights); - - /* Do the same for all the children */ - PrepareStatement(getChildrenIDs, SQL_GET_CHILDREN_IDS, requireBindings, V); - if (requireBindings) { - BindLongInput(getChildrenIDs, 1, &trustee); - BindLongResult(getChildrenIDs, 1, &child); - } - - if (getChildrenIDs == SQL_NULL_HSTMT) { - return(FALSE); - } - - rc = ExecuteStatement(getChildrenIDs); - if (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) { - rc = SQLFetch(getChildrenIDs); - } - - while (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) { - if (!MDBodbcCopyObjectRights(child, trustee, TRUE, V)) { - ReleaseStatement(V, getChildrenIDs); - return(FALSE); - } - - rc = SQLFetch(getChildrenIDs); - } - - ReleaseStatement(V, getChildrenIDs); - if (rc != SQL_NO_DATA) { - return(FALSE); - } - - return(TRUE); -} - -BOOL -MDBodbcGetServerInfo(unsigned char *ServerDN, unsigned char *ServerTree, MDBValueStruct *V) -{ - signed long server; - MDBHandle handle = NULL; - MDBValueStruct *v; - BOOL result = TRUE; - - if (!V) { - handle = MDBodbcAuthenticate(NULL, NULL, NULL); - v = (handle) ? MDBodbcCreateValueStruct(handle, NULL) : NULL; - } else { - v = V; - } - - if (!v) { - if (handle) { - MDBodbcRelease(handle); - } - - return(FALSE); - } - - if (ServerTree) { - strcpy(ServerTree, MDBodbc.config.treename); - } - - if (ServerDN) { - unsigned long base = *(v->base.id); - *(v->base.id) = MDBodbc.config.defaultContext; - - result = FALSE; - if (MDBodbcGetObjectID(MDBodbc.config.servername, &server, NULL, NULL, NULL, NULL, NULL, v)) { - *(v->base.id) = -1; - - if (MDBodbcGetObjectDN(ServerDN, MDB_MAX_OBJECT_CHARS, server, FALSE, v)) { - result = TRUE; - } - } - - *(v->base.id) = base; - - } - - if (handle) { - MDBodbcDestroyValueStruct(v); - MDBodbcRelease(handle); - } - - return(result); -} - -char * -MDBodbcGetBaseDN(MDBValueStruct *V) -{ - return(MDBodbc.config.treename); -} - - -MDBHandle -MDBodbcAuthenticate(const unsigned char *Object, const unsigned char *Password, const unsigned char *Arguments) -{ - BOOL result = TRUE; - - MDBHandle h = malloc(sizeof(MDBodbcContextStruct)); - - if (h) { - SQLINTEGER rc; - - memset(h, 0, sizeof(MDBodbcContextStruct)); - - rc = SQLAllocHandle(SQL_HANDLE_DBC, MDBodbc.env, &h->connection); - if (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) { - SQLSetConnectAttr(h->connection, SQL_LOGIN_TIMEOUT, (SQLPOINTER *)30, 0); - SQLSetConnectAttr(h->connection, SQL_ATTR_AUTOCOMMIT, SQL_AUTOCOMMIT_OFF, 0); - - /* Connect to the datasource */ - rc = SQLConnect(h->connection, (SQLCHAR *) MDBodbc.config.dsn, SQL_NTS, - (SQLCHAR *) MDBodbc.config.user, SQL_NTS, - (SQLCHAR *) MDBodbc.config.pass, SQL_NTS); - - if (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) { - /* We now have a connection */ - if (Object) { - MDBValueStruct *V = MDBodbcCreateValueStruct(h, NULL); - - if (!MDBodbcGetObjectID(Object, &h->object, NULL, NULL, NULL, NULL, NULL, V)) { - /* The object doesn't exist here, lets try again in the default container */ - - *(V->base.id) = MDBodbc.config.defaultContext; - if (*Object != '\\' || !MDBodbcGetObjectID(Object, &h->object, NULL, NULL, NULL, NULL, NULL, V)) { - /* The object doesn't exist */ - result = FALSE; - } - } - - if (result && !MDBodbcVerifyPassword(Object, Password, V)) { - /* Wrong password */ - result = FALSE; - } - - MDBodbcDestroyValueStruct(V); - } - - if (result) { - return(h); - } - } - - SQLDisconnect(h->connection); - } - - free(h); - h = NULL; - } - - return(NULL); -} - -BOOL -MDBodbcRelease(MDBHandle Context) -{ - if (Context) { - SQLEndTran(SQL_HANDLE_DBC, Context->connection, SQL_COMMIT); - SQLDisconnect(Context->connection); - SQLFreeHandle(SQL_HANDLE_DBC, Context->connection); - - free(Context); - return(TRUE); - } else { - return(FALSE); - } -} - -MDBValueStruct * -MDBodbcCreateValueStruct(MDBHandle Handle, const unsigned char *Context) -{ - if (Handle) { - MDBValueStruct *v = malloc(sizeof(MDBValueStruct)); - - if (v) { - memset(v, 0, sizeof(MDBValueStruct)); - - v->handle = Handle; - - v->base.id = &(v->base.value); - v->base.class = &(v->base.classValue); - v->base.read = &(v->base.readValue); - v->base.write = &(v->base.writeValue); - v->base.delete = &(v->base.deleteValue); - v->base.rename = &(v->base.renameValue); - - MDBodbcSetValueStructContext(Context, v); - - /* Everything seems to have worked */ - return(v); - } - } - - return(NULL); -} - -BOOL -MDBodbcFreeValues(MDBValueStruct *V) -{ - register unsigned long i; - - if (V->Allocated) { - for (i = 0; i < V->Used; i++) { - free(V->Value[i]); - } - - if (V->Allocated > VALUE_ALLOC_SIZE) { - if (V->Value) { - free(V->Value); - } - - V->Allocated = 0; - V->Value = NULL; - } - - V->Used = 0; - } - - return(TRUE); -} - -BOOL -MDBodbcDestroyValueStruct(MDBValueStruct *V) -{ - if (V) { - unsigned long i; - - for (i = 0; i < (sizeof(V->stmts) / sizeof(SQLHSTMT)); i++) { - ReleaseStatement(V, V->stmts.asArray[i]); - } - - MDBodbcFreeValues(V); - if (V->Value) { - free(V->Value); - } - - if (V->statementCount) { - XplConsolePrintf("This value struct still has %ld statement handles\n", V->statementCount); - } - - free(V); - return(TRUE); - } else { - return(FALSE); - } -} - -MDBEnumStruct * -MDBodbcCreateEnumStruct(MDBValueStruct *V) -{ - if (V) { - MDBEnumStruct *e = malloc(sizeof(MDBEnumStruct)); - - if (e) { - memset(e, 0, sizeof(MDBEnumStruct)); - - return(e); - } - } - - return(NULL); -} - -BOOL -MDBodbcDestroyEnumStruct(MDBEnumStruct *E, MDBValueStruct *V) -{ - if (E) { - ReleaseStatement(V, E->stmt); - - if (E->largeResult) { - free(E->largeResult); - } - - free(E); - return(TRUE); - } else { - return(FALSE); - } -} - -BOOL -MDBodbcSetValueStructContext(const unsigned char *Context, MDBValueStruct *V) -{ - if (V) { - return(MDBodbcGetObjectID(Context ? Context : (unsigned char *)"\\", V->base.id, V->base.class, V->base.read, V->base.write, V->base.delete, V->base.rename, V)); - } - - return(FALSE); -} - -MDBValueStruct * -MDBodbcShareContext(MDBValueStruct *V) -{ - if (V) { - MDBValueStruct *v = malloc(sizeof(MDBValueStruct)); - - if (v) { - memset(v, 0, sizeof(MDBValueStruct)); - - v->base.id = V->base.id; - v->base.class = V->base.class; - v->base.read = V->base.read; - v->base.write = V->base.write; - v->base.delete = V->base.delete; - v->base.rename = V->base.rename; - - v->handle = V->handle; - - return(v); - } - } - - return(NULL); -} - -BOOL -MDBodbcAddValue(const unsigned char *Value, MDBValueStruct *V) -{ - register unsigned char *ptr; - - if (Value && (*Value != '\0')) { - if ((V->Used + 1) > V->Allocated) { - ptr = (unsigned char *)realloc(V->Value, (V->Allocated + VALUE_ALLOC_SIZE) * sizeof(unsigned char *)); - if (ptr) { - V->Value = (unsigned char **)ptr; - V->Allocated += VALUE_ALLOC_SIZE; - } else { - if (V->Allocated) { - MDBodbcFreeValues(V); - - if (V->Value) { - free(V->Value); - } - } - - V->Value = NULL; - - V->Used = 0; - V->Allocated = 0; - - return(FALSE); - } - } - - ptr = strdup(Value); - if (ptr) { - V->Value[V->Used] = ptr; - V->Used++; - - return(TRUE); - } - } - - return(FALSE); -} - -BOOL -MDBodbcFreeValue(unsigned long Index, MDBValueStruct *V) -{ - if (Index < V->Used) { - free(V->Value[Index]); - - if (Index < (V->Used - 1)) { - memmove(&V->Value[Index], &V->Value[Index + 1], ((V->Used - 1) - Index) * sizeof(unsigned char *)); - } - - V->Used--; - - return(TRUE); - } - - return(FALSE); -} - -BOOL -MDBodbcDefineAttribute(const unsigned char *Attribute, const unsigned char *ASN1, unsigned long Type, BOOL Single, BOOL ImmediateSync, BOOL Public, MDBValueStruct *V) -{ - SQLINTEGER root; - BOOL allowed; - - if (!MDBodbcGetObjectID("\\", &root, NULL, NULL, &allowed, NULL, NULL, V) || !allowed) { - return(FALSE); - } - - if (Attribute) { - SQLINTEGER rc; - BOOL requireBindings; - - PrepareStatement(V->stmts.createAttribute, SQL_CREATE_ATTRIBUTE, requireBindings, V); - if (requireBindings) { - BindCharInput(V->stmts.createAttribute, 1, V->params.createAttribute.name, &V->params.createAttribute.nameLength, MDB_ODBC_NAME_SIZE); - BindLongInput(V->stmts.createAttribute, 2, &V->params.createAttribute.type); - BindLongInput(V->stmts.createAttribute, 3, &V->params.createAttribute.single); - BindLongInput(V->stmts.createAttribute, 4, &V->params.createAttribute.public); - } - - if (V->stmts.createAttribute != SQL_NULL_HSTMT) { - StoreCharInput(Attribute, V->params.createAttribute.name, V->params.createAttribute.nameLength, MDB_ODBC_NAME_SIZE); - - switch (Type) { - case MDB_ATTR_SYN_BOOL: - case MDB_ATTR_SYN_DIST_NAME: - case MDB_ATTR_SYN_BINARY: - case MDB_ATTR_SYN_STRING: { - V->params.createAttribute.type = Type; - break; - } - - default: { - /* Unknown Type */ - V->params.createAttribute.type = 0; - break; - } - } - - V->params.createAttribute.single = Single ? 1 : 0; - V->params.createAttribute.public = Public ? 1 : 0; - - /* Ok, we're ready */ - rc = ExecuteStatement(V->stmts.createAttribute); - if (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) { - SQLEndTran(SQL_HANDLE_DBC, V->handle->connection, SQL_COMMIT); - return(TRUE); - } - } - } - - SQLEndTran(SQL_HANDLE_DBC, V->handle->connection, SQL_ROLLBACK); - return(FALSE); -} - -static __inline BOOL -MDBodbcAddAttributeByID(const unsigned char *Attribute, unsigned long class, MDBValueStruct *V) -{ - SQLINTEGER rc; - BOOL requireBindings; - SQLHSTMT stmt = SQL_NULL_HSTMT; - unsigned long subclass; - SQLINTEGER root; - BOOL allowed; - - if (!MDBodbcGetObjectID("\\", &root, NULL, NULL, &allowed, NULL, NULL, V) || !allowed) { - return(FALSE); - } - - /* Get all subclasses and call add attribute on them as well (recursively) */ - PrepareStatement(stmt, SQL_GET_SUBCLASSES, requireBindings, V); - if (requireBindings) { - BindLongInput(stmt, 1, &class); - BindLongResult(stmt, 1, &subclass); - } - - if (stmt == SQL_NULL_HSTMT) { - ReleaseStatement(V, stmt); - return(FALSE); - } - - rc = ExecuteStatement(stmt); - if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) { - ReleaseStatement(V, stmt); - return(FALSE); - } - - rc = SQLFetch(stmt); - while (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) { - MDBodbcAddAttributeByID(Attribute, subclass, V); - - rc = SQLFetch(stmt); - } - - if (rc != SQL_NO_DATA) { - ReleaseStatement(V, stmt); - return(FALSE); - } - - ReleaseStatement(V, stmt); - - PrepareStatement(V->stmts.createOptional, SQL_CREATE_OPTIONAL, requireBindings, V); - if (requireBindings) { - BindLongInput(V->stmts.createOptional, 1, &V->params.createOptional.class); - BindCharInput(V->stmts.createOptional, 2, V->params.createOptional.name, &V->params.createOptional.nameLength, MDB_ODBC_NAME_SIZE); - } - - if (V->stmts.createOptional == SQL_NULL_HSTMT) { - return(FALSE); - } - - V->params.createOptional.class = class; - StoreCharInput(Attribute, V->params.createOptional.name, V->params.createOptional.nameLength, MDB_ODBC_NAME_SIZE); - - rc = ExecuteStatement(V->stmts.createOptional); - return(rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO); -} - -BOOL -MDBodbcAddAttribute(const unsigned char *Attribute, const unsigned char *Class, MDBValueStruct *V) -{ - SQLINTEGER rc; - BOOL requireBindings; - SQLINTEGER root; - BOOL allowed; - - if (!MDBodbcGetObjectID("\\", &root, NULL, NULL, &allowed, NULL, NULL, V) || !allowed) { - return(FALSE); - } - - PrepareStatement(V->stmts.getClassByName, SQL_GET_CLASS_BY_NAME, requireBindings, V); - if (requireBindings) { - BindCharInput(V->stmts.getClassByName, 1, V->params.getClassByName.name, &V->params.getClassByName.nameLength, MDB_ODBC_NAME_SIZE); - BindLongResult(V->stmts.getClassByName, 1, &V->params.getClassByName.class); - } - - if (V->stmts.getClassByName == SQL_NULL_HSTMT) { - return(FALSE); - } - - StoreCharInput(Class, V->params.getClassByName.name, V->params.getClassByName.nameLength, MDB_ODBC_NAME_SIZE); - - rc = ExecuteStatement(V->stmts.getClassByName); - if (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) { - rc = SQLFetch(V->stmts.getClassByName); - SQLCloseCursor(V->stmts.getClassByName); - - SQLEndTran(SQL_HANDLE_DBC, V->handle->connection, SQL_COMMIT); - return(MDBodbcAddAttributeByID(Attribute, V->params.getClassByName.class, V)); - } else { - SQLEndTran(SQL_HANDLE_DBC, V->handle->connection, SQL_ROLLBACK); - return(FALSE); - } -} - -BOOL -MDBodbcUndefineAttribute(const unsigned char *Attribute, MDBValueStruct *V) -{ - SQLINTEGER attribute; - SQLINTEGER rc; - BOOL requireBindings; - SQLINTEGER root; - BOOL allowed; - - if (!MDBodbcGetObjectID("\\", &root, NULL, NULL, &allowed, NULL, NULL, V) || !allowed) { - return(FALSE); - } - - if (!Attribute || !V) { - return(FALSE); - } - - /* Get the attribute ID */ - BindLongResult(V->stmts.verifyPassword, 1, &V->params.verifyPassword.object); - PrepareStatement(V->stmts.getAttrByName, SQL_GET_ATTRIBUTE_BY_NAME, requireBindings, V); - if (requireBindings) { - BindCharInput(V->stmts.getAttrByName, 1, - V->params.getAttrByName.attribute, &V->params.getAttrByName.attributeLength, MDB_ODBC_NAME_SIZE); - BindLongResult(V->stmts.getAttrByName, 1, &V->params.getAttrByName.id); - } - - if (V->stmts.getAttrByName == SQL_NULL_HSTMT) { - return(FALSE); - } - - StoreCharInput(Attribute, V->params.getAttrByName.attribute, V->params.getAttrByName.attributeLength, MDB_ODBC_NAME_SIZE); - - /* Ok, we're all setup - Do the query */ - rc = ExecuteStatement(V->stmts.getAttrByName); - - if (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) { - rc = SQLFetch(V->stmts.getAttrByName); - SQLCloseCursor(V->stmts.getAttrByName); - attribute = V->params.getAttrByName.id; - } - - /* Remove all references to the attribute */ - PrepareStatement(V->stmts.deleteAttrFromMandatory, SQL_MANDATORY_DELETE_ATTR, requireBindings, V); - if (requireBindings) { - BindLongInput(V->stmts.deleteAttrFromMandatory, 1, &V->params.deleteAttrFromMandatory.attribute); - } - - if (V->stmts.deleteAttrFromMandatory == SQL_NULL_HSTMT) { - SQLEndTran(SQL_HANDLE_DBC, V->handle->connection, SQL_ROLLBACK); - return(FALSE); - } - - V->params.deleteAttrFromMandatory.attribute = attribute; - - rc = ExecuteStatement(V->stmts.deleteAttrFromMandatory); - if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO && rc != SQL_NO_DATA) { - SQLEndTran(SQL_HANDLE_DBC, V->handle->connection, SQL_ROLLBACK); - return(FALSE); - } - - - PrepareStatement(V->stmts.deleteAttrFromOptional, SQL_OPTIONAL_DELETE_ATTR, requireBindings, V); - if (requireBindings) { - BindLongInput(V->stmts.deleteAttrFromOptional, 1, &V->params.deleteAttrFromOptional.attribute); - } - - if (V->stmts.deleteAttrFromOptional == SQL_NULL_HSTMT) { - SQLEndTran(SQL_HANDLE_DBC, V->handle->connection, SQL_ROLLBACK); - return(FALSE); - } - - V->params.deleteAttrFromOptional.attribute = attribute; - - rc = ExecuteStatement(V->stmts.deleteAttrFromOptional); - if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO && rc != SQL_NO_DATA) { - SQLEndTran(SQL_HANDLE_DBC, V->handle->connection, SQL_ROLLBACK); - return(FALSE); - } - - - PrepareStatement(V->stmts.deleteAttrFromNaming, SQL_NAMING_DELETE_ATTR, requireBindings, V); - if (requireBindings) { - BindLongInput(V->stmts.deleteAttrFromNaming, 1, &V->params.deleteAttrFromNaming.attribute); - } - - if (V->stmts.deleteAttrFromNaming == SQL_NULL_HSTMT) { - SQLEndTran(SQL_HANDLE_DBC, V->handle->connection, SQL_ROLLBACK); - return(FALSE); - } - - V->params.deleteAttrFromNaming.attribute = attribute; - - rc = ExecuteStatement(V->stmts.deleteAttrFromNaming); - if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO && rc != SQL_NO_DATA) { - SQLEndTran(SQL_HANDLE_DBC, V->handle->connection, SQL_ROLLBACK); - return(FALSE); - } - - PrepareStatement(V->stmts.deleteAttrFromValues, SQL_VALUES_DELETE_ATTR, requireBindings, V); - if (requireBindings) { - BindLongInput(V->stmts.deleteAttrFromValues, 1, &V->params.deleteAttrFromValues.attribute); - } - - if (V->stmts.deleteAttrFromValues == SQL_NULL_HSTMT) { - SQLEndTran(SQL_HANDLE_DBC, V->handle->connection, SQL_ROLLBACK); - return(FALSE); - } - - V->params.deleteAttrFromValues.attribute = attribute; - - rc = ExecuteStatement(V->stmts.deleteAttrFromValues); - if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO && rc != SQL_NO_DATA) { - SQLEndTran(SQL_HANDLE_DBC, V->handle->connection, SQL_ROLLBACK); - return(FALSE); - } - - - /* Actually remove the attribute */ - PrepareStatement(V->stmts.deleteAttr, SQL_DELETE_ATTRIBUTE, requireBindings, V); - if (requireBindings) { - BindLongInput(V->stmts.deleteAttr, 1, &V->params.deleteAttr.attribute); - } - - if (V->stmts.deleteAttr == SQL_NULL_HSTMT) { - SQLEndTran(SQL_HANDLE_DBC, V->handle->connection, SQL_ROLLBACK); - return(FALSE); - } - - V->params.deleteAttr.attribute = attribute; - - rc = ExecuteStatement(V->stmts.deleteAttr); - if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO && rc != SQL_NO_DATA) { - SQLEndTran(SQL_HANDLE_DBC, V->handle->connection, SQL_ROLLBACK); - return(FALSE); - } - - SQLEndTran(SQL_HANDLE_DBC, V->handle->connection, SQL_COMMIT); - return(TRUE); -} - -/* This driver does not supprt/use the ASN1, or naming fields of a class */ -BOOL -MDBodbcDefineClass(const unsigned char *Class, const unsigned char *ASN1, BOOL Container, MDBValueStruct *Superclass, MDBValueStruct *Containment, MDBValueStruct *Naming, MDBValueStruct *Mandatory, MDBValueStruct *Optional, MDBValueStruct *V) -{ - unsigned long class; - unsigned long i; - BOOL result = TRUE; - SQLINTEGER rc; - BOOL requireBindings; - SQLINTEGER root; - BOOL allowed; - - if (!MDBodbcGetObjectID("\\", &root, NULL, NULL, &allowed, NULL, NULL, V) || !allowed) { - return(FALSE); - } - - /* Add the class */ - PrepareStatement(V->stmts.createClass, SQL_CREATE_CLASS, requireBindings, V); - if (requireBindings) { - BindCharInput(V->stmts.createClass, 1, V->params.createClass.name, &V->params.createClass.nameLength, MDB_ODBC_NAME_SIZE); - BindLongInput(V->stmts.createClass, 2, &V->params.createClass.container); - } - - if (V->stmts.createClass == SQL_NULL_HSTMT) { - return(FALSE); - } - - StoreCharInput(Class, V->params.createClass.name, V->params.createClass.nameLength, MDB_ODBC_NAME_SIZE); - V->params.createClass.container = Container ? 1 : 0; - - rc = ExecuteStatement(V->stmts.createClass); - if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) { - /* The class is already there */ - - SQLEndTran(SQL_HANDLE_DBC, V->handle->connection, SQL_ROLLBACK); - return(TRUE); - } - - /* Get the ID of the newly created class */ - PrepareStatement(V->stmts.getClassByName, SQL_GET_CLASS_BY_NAME, requireBindings, V); - if (requireBindings) { - BindCharInput(V->stmts.getClassByName, 1, V->params.getClassByName.name, &V->params.getClassByName.nameLength, MDB_ODBC_NAME_SIZE); - BindLongResult(V->stmts.getClassByName, 1, &V->params.getClassByName.class); - } - - if (V->stmts.getClassByName == SQL_NULL_HSTMT) { - SQLEndTran(SQL_HANDLE_DBC, V->handle->connection, SQL_ROLLBACK); - return(FALSE); - } - - StoreCharInput(Class, V->params.getClassByName.name, V->params.getClassByName.nameLength, MDB_ODBC_NAME_SIZE); - - rc = ExecuteStatement(V->stmts.getClassByName); - if (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) { - rc = SQLFetch(V->stmts.getClassByName); - SQLCloseCursor(V->stmts.getClassByName); - - class = V->params.getClassByName.class; - } else { - SQLEndTran(SQL_HANDLE_DBC, V->handle->connection, SQL_ROLLBACK); - return(FALSE); - } - - /* Assign the Containment */ - PrepareStatement(V->stmts.createContainment, SQL_CREATE_CONTAINMENT, requireBindings, V); - if (requireBindings) { - BindLongInput(V->stmts.createContainment, 1, &V->params.createContainment.class); - BindCharInput(V->stmts.createContainment, 2, V->params.createContainment.name, &V->params.createContainment.nameLength, MDB_ODBC_NAME_SIZE); - } - - if (V->stmts.createContainment == SQL_NULL_HSTMT) { - result = FALSE; - } - - if (result && Containment) { - V->params.createContainment.class = class; - - for (i = 0; i < Containment->Used; i++) { - StoreCharInput(Containment->Value[i], V->params.createContainment.name, V->params.createContainment.nameLength, MDB_ODBC_NAME_SIZE); - - rc = ExecuteStatement(V->stmts.createContainment); - if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) { - result = FALSE; - } - } - } - - PrepareStatement(V->stmts.createMandatory, SQL_CREATE_MANDATORY, requireBindings, V); - if (requireBindings) { - BindLongInput(V->stmts.createMandatory, 1, &V->params.createMandatory.class); - BindCharInput(V->stmts.createMandatory, 2, V->params.createMandatory.name, &V->params.createMandatory.nameLength, MDB_ODBC_NAME_SIZE); - } - - if (result && Mandatory) { - V->params.createMandatory.class = class; - - for (i = 0; i < Mandatory->Used; i++) { - BOOL create = TRUE; - - /* Naming attributes are always provided by the object name, so there is no need to add them to the mandatory list. */ - if (Naming) { - unsigned long n; - - for (n = 0; n < Naming->Used; n++) { - if (XplStrCaseCmp(Naming->Value[n], Mandatory->Value[i]) == 0) { - create = FALSE; - break; - } - } - } - - if (create) { - StoreCharInput(Mandatory->Value[i], V->params.createMandatory.name, V->params.createMandatory.nameLength, MDB_ODBC_NAME_SIZE); - - rc = ExecuteStatement(V->stmts.createMandatory); - if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) { - result = FALSE; - } - } - } - } - - - /* Assign the Optional Attributes */ - PrepareStatement(V->stmts.createOptional, SQL_CREATE_OPTIONAL, requireBindings, V); - if (requireBindings) { - BindLongInput(V->stmts.createOptional, 1, &V->params.createOptional.class); - BindCharInput(V->stmts.createOptional, 2, V->params.createOptional.name, &V->params.createOptional.nameLength, MDB_ODBC_NAME_SIZE); - } - - if (V->stmts.createOptional == SQL_NULL_HSTMT) { - result = FALSE; - } - - if (result) { - V->params.createOptional.class = class; - - if (Optional) { - for (i = 0; i < Optional->Used; i++) { - StoreCharInput(Optional->Value[i], V->params.createOptional.name, V->params.createOptional.nameLength, MDB_ODBC_NAME_SIZE); - - rc = ExecuteStatement(V->stmts.createOptional); - if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) { - result = FALSE; - } - } - } - - /* We add mandatory attributes as optional as well, so that we only have to check one list in MDBWrite */ - if (Mandatory) { - for (i = 0; i < Mandatory->Used; i++) { - StoreCharInput(Mandatory->Value[i], V->params.createOptional.name, V->params.createOptional.nameLength, MDB_ODBC_NAME_SIZE); - - rc = ExecuteStatement(V->stmts.createOptional); - if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) { - result = FALSE; - } - } - } - } - - /* Assign the Naming Attributes */ - PrepareStatement(V->stmts.createNaming, SQL_CREATE_NAMING, requireBindings, V); - if (requireBindings) { - BindLongInput(V->stmts.createNaming, 1, &V->params.createNaming.class); - BindCharInput(V->stmts.createNaming, 2, V->params.createNaming.name, &V->params.createNaming.nameLength, MDB_ODBC_NAME_SIZE); - } - - if (V->stmts.createNaming == SQL_NULL_HSTMT) { - result = FALSE; - } - - if (result && Naming) { - V->params.createNaming.class = class; - - for (i = 0; i < Naming->Used; i++) { - StoreCharInput(Naming->Value[i], V->params.createNaming.name, V->params.createNaming.nameLength, MDB_ODBC_NAME_SIZE); - - rc = ExecuteStatement(V->stmts.createNaming); - if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) { - result = FALSE; - } - } - } - - /* - Assign the super classes - - This must be done before we do the copying, but we have to be sure to not copy the superclasses - until last, to prevent getting duplicate values. - */ - PrepareStatement(V->stmts.createSuperClass, SQL_CREATE_SUPERCLASS, requireBindings, V); - if (requireBindings) { - BindLongInput(V->stmts.createSuperClass, 1, &V->params.createSuperClass.class); - BindCharInput(V->stmts.createSuperClass, 2, V->params.createSuperClass.name, &V->params.createSuperClass.nameLength, MDB_ODBC_NAME_SIZE); - } - - if (V->stmts.createSuperClass == SQL_NULL_HSTMT) { - result = FALSE; - } - - if (result && Superclass) { - V->params.createSuperClass.class = class; - - for (i = 0; i < Superclass->Used; i++) { - StoreCharInput(Superclass->Value[i], V->params.createSuperClass.name, V->params.createSuperClass.nameLength, MDB_ODBC_NAME_SIZE); - - rc = ExecuteStatement(V->stmts.createSuperClass); - if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) { - result = FALSE; - } - } - } - - /* - Now that we have assigned all the values we need, we need to copy all the same things - from the superclasses. - */ - if (!Containment || Containment->Used == 0) { - /* Containment is only inherited if it is not specified for a class */ - - PrepareStatement(V->stmts.copyContainment, SQL_COPY_CONTAINMENT, requireBindings, V); - if (requireBindings) { - BindLongInput(V->stmts.copyContainment, 1, &V->params.copyContainment.class); - } - - if (V->stmts.copyContainment == SQL_NULL_HSTMT) { - result = FALSE; - } - - if (result) { - V->params.copyContainment.class = class; - - rc = ExecuteStatement(V->stmts.copyContainment); - if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) { - result = FALSE; - } - } - } - - PrepareStatement(V->stmts.copyOptional, SQL_COPY_OPTIONAL, requireBindings, V); - if (requireBindings) { - BindLongInput(V->stmts.copyOptional, 1, &V->params.copyOptional.class); - } - - if (V->stmts.copyOptional == SQL_NULL_HSTMT) { - result = FALSE; - } - - if (result) { - V->params.copyOptional.class = class; - - rc = ExecuteStatement(V->stmts.copyOptional); - if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) { - result = FALSE; - } - } - - PrepareStatement(V->stmts.copyMandatory, SQL_COPY_MANDATORY, requireBindings, V); - if (requireBindings) { - BindLongInput(V->stmts.copyMandatory, 1, &V->params.copyMandatory.class); - } - - if (V->stmts.copyMandatory == SQL_NULL_HSTMT) { - result = FALSE; - } - - if (result) { - V->params.copyMandatory.class = class; - - rc = ExecuteStatement(V->stmts.copyMandatory); - if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) { - result = FALSE; - } - } - - PrepareStatement(V->stmts.copyNaming, SQL_COPY_NAMING, requireBindings, V); - if (requireBindings) { - BindLongInput(V->stmts.copyNaming, 1, &V->params.copyNaming.class); - } - - if (V->stmts.copyNaming == SQL_NULL_HSTMT) { - result = FALSE; - } - - if (result) { - V->params.copyNaming.class = class; - - rc = ExecuteStatement(V->stmts.copyNaming); - if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) { - result = FALSE; - } - } - - /* - Copy the superclasses from the superclasses. This has to be done after the copying - because each class has the info from its superclass already, so if we do this before - we'll get duplicate values. - - This has to be done though so that if an attribute is added to the superclass of a - superclass at a later point that it can be added to this class as well. - */ - PrepareStatement(V->stmts.copySuperClass, SQL_COPY_SUPERCLASSES, requireBindings, V); - if (requireBindings) { - BindLongInput(V->stmts.copySuperClass, 1, &V->params.copySuperClass.class); - BindCharInput(V->stmts.copySuperClass, 2, - V->params.copySuperClass.name, &V->params.copySuperClass.nameLength, MDB_ODBC_NAME_SIZE); - } - - if (V->stmts.copySuperClass == SQL_NULL_HSTMT) { - result = FALSE; - } - - if (result && Superclass) { - V->params.copySuperClass.class = class; - - for (i = 0; i < Superclass->Used; i++) { - StoreCharInput(Superclass->Value[i], V->params.copySuperClass.name, V->params.copySuperClass.nameLength, MDB_ODBC_NAME_SIZE); - - rc = ExecuteStatement(V->stmts.copySuperClass); - if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) { - result = FALSE; - } - } - } - - /* Done */ - SQLEndTran(SQL_HANDLE_DBC, V->handle->connection, result ? SQL_COMMIT : SQL_ROLLBACK); - return(result); -} - -BOOL -MDBodbcUndefineClass(const unsigned char *Class, MDBValueStruct *V) -{ - SQLINTEGER rc; - BOOL requireBindings; - SQLINTEGER root; - BOOL allowed; - - if (!MDBodbcGetObjectID("\\", &root, NULL, NULL, &allowed, NULL, NULL, V) || !allowed) { - return(FALSE); - } - - if (!Class || !V) { - return(FALSE); - } - - /* Get the class ID */ - PrepareStatement(V->stmts.getClassByName, SQL_GET_CLASS_BY_NAME, requireBindings, V); - if (requireBindings) { - BindCharInput(V->stmts.getClassByName, 1, - V->params.getClassByName.name, &V->params.getClassByName.nameLength, MDB_ODBC_NAME_SIZE); - BindLongResult(V->stmts.getClassByName, 1, &V->params.getClassByName.class); - } - - if (V->stmts.getClassByName == SQL_NULL_HSTMT) { - return(FALSE); - } - - StoreCharInput(Class, V->params.getClassByName.name, V->params.getClassByName.nameLength, MDB_ODBC_NAME_SIZE); - - rc = ExecuteStatement(V->stmts.getClassByName); - if (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) { - rc = SQLFetch(V->stmts.getClassByName); - SQLCloseCursor(V->stmts.getClassByName); - - if (MDBodbcUndefineClassByID(V->params.getClassByName.class, V)) { - SQLEndTran(SQL_HANDLE_DBC, V->handle->connection, SQL_COMMIT); - return(TRUE); - } - } - - SQLEndTran(SQL_HANDLE_DBC, V->handle->connection, SQL_ROLLBACK); - return(FALSE); -} - -static __inline BOOL -MDBodbcUndefineClassByID(unsigned long class, MDBValueStruct *V) -{ - SQLINTEGER rc; - BOOL requireBindings; - SQLHSTMT stmt = SQL_NULL_HSTMT; - unsigned long subclass; - unsigned long object; - - /* Get all subclasses and call undefine class on them (recursive) */ - PrepareStatement(stmt, SQL_GET_SUBCLASSES, requireBindings, V); - if (requireBindings) { - BindLongInput(stmt, 1, &class); - BindLongResult(stmt, 1, &subclass); - } - - if (stmt == SQL_NULL_HSTMT) { - ReleaseStatement(V, stmt); - return(FALSE); - } - - rc = ExecuteStatement(stmt); - if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) { - ReleaseStatement(V, stmt); - return(FALSE); - } - - rc = SQLFetch(stmt); - while (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) { - MDBodbcUndefineClassByID(subclass, V); - - rc = SQLFetch(stmt); - } - - if (rc != SQL_NO_DATA) { - ReleaseStatement(V, stmt); - return(FALSE); - } - - ReleaseStatement(V, stmt); - - /* Get all objects of that type and delete recursively */ - stmt = SQL_NULL_HSTMT; - PrepareStatement(stmt, SQL_GET_OBJECTS_BY_CLASS, requireBindings, V); - if (requireBindings) { - BindLongInput(stmt, 1, &class); - BindLongResult(stmt, 1, &object); - } - - if (stmt == SQL_NULL_HSTMT) { - return(FALSE); - } - - rc = ExecuteStatement(stmt); - if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) { - return(FALSE); - } - - rc = SQLFetch(stmt); - while (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) { - MDBodbcDeleteObjectByID(object, TRUE, V); - - rc = SQLFetch(stmt); - } - - if (rc != SQL_NO_DATA) { - return(FALSE); - } - - ReleaseStatement(V, stmt); - - - /* Remove from containment, mandatory, optional, and naming */ - PrepareStatement(V->stmts.deleteClassFromContainment, SQL_CONTAINMENT_DEL_CLASS, requireBindings, V); - if (requireBindings) { - /* Yes these are supposed to be the same */ - BindLongInput(V->stmts.deleteClassFromContainment, 1, &V->params.deleteClassFromContainment.class); - BindLongInput(V->stmts.deleteClassFromContainment, 2, &V->params.deleteClassFromContainment.class); - } - - if (V->stmts.deleteClassFromContainment == SQL_NULL_HSTMT) { - return(FALSE); - } - - V->params.deleteClassFromContainment.class = class; - - rc = ExecuteStatement(V->stmts.deleteClassFromContainment); - if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO && rc != SQL_NO_DATA) { - return(FALSE); - } - - - PrepareStatement(V->stmts.deleteClassFromMandatory, SQL_MANDATORY_DEL_CLASS, requireBindings, V); - if (requireBindings) { - BindLongInput(V->stmts.deleteClassFromMandatory, 1, &V->params.deleteClassFromMandatory.class); - } - - if (V->stmts.deleteClassFromMandatory == SQL_NULL_HSTMT) { - return(FALSE); - } - - V->params.deleteClassFromMandatory.class = class; - - rc = ExecuteStatement(V->stmts.deleteClassFromMandatory); - if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO && rc != SQL_NO_DATA) { - return(FALSE); - } - - PrepareStatement(V->stmts.deleteClassFromOptional, SQL_OPTIONAL_DEL_CLASS, requireBindings, V); - if (requireBindings) { - BindLongInput(V->stmts.deleteClassFromOptional, 1, &V->params.deleteClassFromOptional.class); - } - - if (V->stmts.deleteClassFromOptional == SQL_NULL_HSTMT) { - return(FALSE); - } - - V->params.deleteClassFromOptional.class = class; - - rc = ExecuteStatement(V->stmts.deleteClassFromOptional); - if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO && rc != SQL_NO_DATA) { - return(FALSE); - } - - PrepareStatement(V->stmts.deleteClassFromNaming, SQL_NAMING_DEL_CLASS, requireBindings, V); - if (requireBindings) { - BindLongInput(V->stmts.deleteClassFromNaming, 1, &V->params.deleteClassFromNaming.class); - } - - if (V->stmts.deleteClassFromNaming == SQL_NULL_HSTMT) { - return(FALSE); - } - - V->params.deleteClassFromNaming.class = class; - - rc = ExecuteStatement(V->stmts.deleteClassFromNaming); - if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO && rc != SQL_NO_DATA) { - return(FALSE); - } - - /* Ok delete the actual class now */ - PrepareStatement(V->stmts.deleteClass, SQL_DELETE_CLASS, requireBindings, V); - if (requireBindings) { - BindLongInput(V->stmts.deleteClass, 1, &V->params.deleteClass.class); - } - - if (V->stmts.deleteClass== SQL_NULL_HSTMT) { - return(FALSE); - } - - V->params.deleteClass.class = class; - - rc = ExecuteStatement(V->stmts.deleteClass); - if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO && rc != SQL_NO_DATA) { - return(FALSE); - } - - return(TRUE); -} - -BOOL -MDBodbcListContainableClasses(const unsigned char *Object, MDBValueStruct *V) -{ - signed long id; - SQLINTEGER rc; - BOOL requireBindings; - BOOL allowed; - - if (!V || !Object || !MDBodbcGetObjectID(Object, &id, NULL, &allowed, NULL, NULL, NULL, V) || !allowed) { - return(FALSE); - } - - PrepareStatement(V->stmts.listContainment, SQL_LIST_CONTAINMENT, requireBindings, V); - if (requireBindings) { - BindLongInput(V->stmts.listContainment, 1, &V->params.listContainment.object); - BindCharResult(V->stmts.listContainment, 1, V->params.listContainment.name, MDB_ODBC_NAME_SIZE); - } - - if (V->stmts.listContainment == SQL_NULL_HSTMT) { - return(FALSE); - } - - V->params.listContainment.object = id; - rc = ExecuteStatement(V->stmts.listContainment); - if (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) { - rc = SQLFetch(V->stmts.listContainment); - } - - while (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) { - MDBodbcAddValue(V->params.listContainment.name, V); - - rc = SQLFetch(V->stmts.listContainment); - } - - SQLCloseCursor(V->stmts.listContainment); - - return(V->Used); -} - -const unsigned char * -MDBodbcListContainableClassesEx(const unsigned char *Object, MDBEnumStruct *E, MDBValueStruct *V) -{ - SQLINTEGER rc; - - if (!E || !V) { - return(NULL); - } - - if (E->stmt == SQL_NULL_HSTMT) { - BOOL requireBindings; - BOOL allowed; - - if (!Object || !MDBodbcGetObjectID(Object, &E->object, NULL, &allowed, NULL, NULL, NULL, V) || !allowed) { - return(NULL); - } - - /* We are not in a statement, so prepare one */ - E->sql = SQL_LIST_CONTAINMENT; - PrepareStatement(E->stmt, SQL_LIST_CONTAINMENT, requireBindings, V); - if (requireBindings) { - BindLongInput(E->stmt, 1, &E->object); - BindCharResult(E->stmt, 1, E->result, MDB_ODBC_NAME_SIZE); - } - - rc = ExecuteStatement(E->stmt); - if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO && rc != SQL_NO_DATA) { - ReleaseStatement(V, E->stmt); - E->stmt = SQL_NULL_HSTMT; - } - } - - if (E->stmt != SQL_NULL_HSTMT && E->sql == SQL_LIST_CONTAINMENT) { - rc = SQLFetch(E->stmt); - if (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) { - return(E->result); - } else if (rc == SQL_NO_DATA) { - ReleaseStatement(V, E->stmt); - E->stmt = SQL_NULL_HSTMT; - } - } - - return(NULL); -} - -long -MDBodbcRead(const unsigned char *Object, const unsigned char *Attribute, MDBValueStruct *V) -{ - signed long id; - SQLINTEGER rc; - BOOL requireBindings; - unsigned char *value = NULL; - unsigned long used = 0; - unsigned long before; - BOOL allowed; - - if (!Object || !Attribute || !V || !MDBodbcGetObjectID(Object, &id, NULL, &allowed, NULL, NULL, NULL, V) || !allowed) { - return(FALSE); - } - - before = V->Used; - - PrepareStatement(V->stmts.readValue, SQL_READ_VALUE, requireBindings, V); - if (requireBindings) { - BindLongInput(V->stmts.readValue, 1, &V->params.readValue.object); - BindCharInput(V->stmts.readValue, 2, - &V->params.readValue.attribute, &V->params.readValue.attributeLength, MDB_ODBC_NAME_SIZE); - - BindCharResult(V->stmts.readValue, 1, V->params.readValue.value, MDB_ODBC_PART_SIZE + 1); - BindLongResult(V->stmts.readValue, 2, &V->params.readValue.dn); - BindLongResult(V->stmts.readValue, 3, &V->params.readValue.bool); - BindLongResult(V->stmts.readValue, 4, &V->params.readValue.complete); - BindLongResult(V->stmts.readValue, 5, &V->params.readValue.type); - } - - if (V->stmts.readValue == SQL_NULL_HSTMT) { - return(0); - } - - V->params.readValue.object = id; - StoreCharInput(Attribute, V->params.readValue.attribute, V->params.readValue.attributeLength, MDB_ODBC_NAME_SIZE); - - rc = ExecuteStatement(V->stmts.readValue); - if (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) { - rc = SQLFetch(V->stmts.readValue); - } - - while (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) { - switch (V->params.readValue.type) { - case MDB_ATTR_SYN_STRING: { - if (value || V->params.readValue.complete != 1) { - value = realloc(value, used + MDB_ODBC_PART_SIZE + 1); - - strncpy(value + used, V->params.readValue.value, MDB_ODBC_PART_SIZE + 1); - used += strlen(V->params.readValue.value); - value[used] = '\0'; - } - - if (V->params.readValue.complete == 1) { - MDBodbcAddValue(value ? value : V->params.readValue.value, V); - if (value) { - free(value); - value = NULL; - used = 0; - } - } - - break; - } - - case MDB_ATTR_SYN_DIST_NAME: { - unsigned char dn[MDB_MAX_OBJECT_CHARS + 1]; - - /* We have a DN value */ - if (MDBodbcGetObjectDN(dn, MDB_MAX_OBJECT_CHARS, V->params.readValue.dn, FALSE, V)) { - MDBodbcAddValue(dn, V); - } - - break; - } - - case MDB_ATTR_SYN_BOOL: { - if (V->params.readValue.bool == 1) { - MDBodbcAddValue("1", V); - } else { - MDBodbcAddValue("0", V); - } - - break; - } - } - - V->params.readValue.value[0] = '\0'; - rc = SQLFetch(V->stmts.readValue); - } - - if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO && rc != SQL_NO_DATA) { - XplConsolePrintf("Error reading value: %lu\n", rc); - PrintSQLErr(V, V->stmts.readValue); - } - - SQLCloseCursor(V->stmts.readValue); - - if (value) { - XplConsolePrintf("%s:%d Failed to read the final part of a value\n", __FILE__, __LINE__); - free(value); - } - - return(V->Used - before); -} - -const unsigned char * -MDBodbcReadEx(const unsigned char *Object, const unsigned char *Attribute, MDBEnumStruct *E, MDBValueStruct *V) -{ - SQLINTEGER rc; - - if (!E || !V) { - return(NULL); - } - - if (E->largeResult) { - free(E->largeResult); - E->largeResult = NULL; - } - - if (E->stmt == SQL_NULL_HSTMT) { - BOOL requireBindings; - BOOL allowed; - - if (!Object || !Attribute || !MDBodbcGetObjectID(Object, &E->object, NULL, &allowed, NULL, NULL, NULL, V) || !allowed) { - return(NULL); - } - - /* We are not in a statement, so prepare one */ - E->sql = SQL_READ_VALUE; - PrepareStatement(E->stmt, SQL_READ_VALUE, requireBindings, V); - if (requireBindings) { - unsigned long attributeLength = strlen(Attribute); - - BindLongInput(E->stmt, 1, &E->object); - BindCharInput(E->stmt, 2, &Attribute, &attributeLength, MDB_ODBC_NAME_SIZE); - - BindCharResult(E->stmt, 1, E->result, MDB_ODBC_PART_SIZE + 1); - BindLongResult(E->stmt, 2, &E->id); - BindLongResult(E->stmt, 3, &E->bool); - BindLongResult(E->stmt, 4, &E->complete); - BindLongResult(E->stmt, 5, &E->type); - } - - rc = ExecuteStatement(E->stmt); - if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO && rc != SQL_NO_DATA) { - ReleaseStatement(V, E->stmt); - E->stmt = SQL_NULL_HSTMT; - } - } - - if (E->stmt != SQL_NULL_HSTMT && E->sql == SQL_READ_VALUE) { - rc = SQLFetch(E->stmt); - if (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) { - switch (V->params.readValue.type) { - case MDB_ATTR_SYN_STRING: { - unsigned long used = 0; - - do { - if (E->largeResult || E->complete != 1) { - E->largeResult = realloc(E->largeResult, used + MDB_ODBC_PART_SIZE + 1); - - strncpy(E->largeResult + used, E->result, MDB_ODBC_PART_SIZE + 1); - used += strlen(E->result); - E->largeResult[used] = '\0'; - } - } while (E->complete != 1 && (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO)); - - if (E->complete == 1) { - if (E->largeResult) { - return(E->largeResult); - } else { - return(E->result); - } - } - - break; - } - - case MDB_ATTR_SYN_DIST_NAME: { - /* We have a DN value */ - if (MDBodbcGetObjectDN(E->result, MDB_MAX_OBJECT_CHARS, E->id, FALSE, V)) { - return(E->result); - } - - break; - } - - case MDB_ATTR_SYN_BOOL: { - if (E->bool == 1) { - E->result[0] = '1'; - } else { - E->result[0] = '0'; - } - E->result[1] = '\0'; - - return(E->result); - } - } - } else if (rc == SQL_NO_DATA) { - ReleaseStatement(V, E->stmt); - E->stmt = SQL_NULL_HSTMT; - } - } - - return(NULL); -} - -BOOL -MDBodbcWriteTyped(const unsigned char *Object, const unsigned char *Attribute, const int AttrType, MDBValueStruct *V) -{ - return(MDBodbcWriteAny(Object, Attribute, AttrType, TRUE, NULL, V)); -} - -BOOL -MDBodbcWrite(const unsigned char *Object, const unsigned char *Attribute, MDBValueStruct *V) -{ - return(MDBodbcWriteAny(Object, Attribute, MDB_ATTR_SYN_STRING, TRUE, NULL, V)); -} - -BOOL -MDBodbcWriteDN(const unsigned char *Object, const unsigned char *Attribute, MDBValueStruct *V) -{ - return(MDBodbcWriteAny(Object, Attribute, MDB_ATTR_SYN_DIST_NAME, TRUE, NULL, V)); -} - -BOOL -MDBodbcAdd(const unsigned char *Object, const unsigned char *Attribute, const unsigned char *Value, MDBValueStruct *V) -{ - if (Value) { - return(MDBodbcWriteAny(Object, Attribute, MDB_ATTR_SYN_STRING, FALSE, Value, V)); - } else { - /* WriteAny will attempt to write the values in V if Value is NULL */ - return(FALSE); - } -} - -BOOL -MDBodbcAddDN(const unsigned char *Object, const unsigned char *Attribute, const unsigned char *Value, MDBValueStruct *V) -{ - if (Value) { - return(MDBodbcWriteAny(Object, Attribute, MDB_ATTR_SYN_DIST_NAME, FALSE, Value, V)); - } else { - /* WriteAny will attempt to write the values in V if Value is NULL */ - return(FALSE); - } -} - -static __inline BOOL -MDBodbcWriteAny(const unsigned char *Object, const unsigned char *Attribute, const unsigned char Type, const BOOL clear, const unsigned char *Value, MDBValueStruct *V) -{ - SQLINTEGER object; - SQLINTEGER attribute; - BOOL single; - unsigned char type; - unsigned char **v = (Value) ? (unsigned char **)&(Value) : V->Value; - unsigned long u = (Value) ? 1 : V->Used; - SQLINTEGER rc; - BOOL requireBindings; - BOOL allowed; - - if (!Object || !Attribute || !V || !MDBodbcGetObjectID(Object, &object, NULL, NULL, &allowed, NULL, NULL, V) || !allowed) { - return(FALSE); - } - - PrepareStatement(V->stmts.getObjectAttrInfo, SQL_GET_OBJECT_ATTR_INFO, requireBindings, V); - if (requireBindings) { - BindLongInput(V->stmts.getObjectAttrInfo, 1, &V->params.getObjectAttrInfo.object); - BindCharInput(V->stmts.getObjectAttrInfo, 2, - V->params.getObjectAttrInfo.attribute, &V->params.getObjectAttrInfo.attributeLength, MDB_ODBC_NAME_SIZE); - BindLongResult(V->stmts.getObjectAttrInfo, 1, &V->params.getObjectAttrInfo.id); - BindLongResult(V->stmts.getObjectAttrInfo, 2, &V->params.getObjectAttrInfo.single); - BindLongResult(V->stmts.getObjectAttrInfo, 3, &V->params.getObjectAttrInfo.type); - } - - if (V->stmts.getObjectAttrInfo == SQL_NULL_HSTMT) { - return(FALSE); - } - - V->params.getObjectAttrInfo.object = object; - StoreCharInput(Attribute, V->params.getObjectAttrInfo.attribute, V->params.getObjectAttrInfo.attributeLength, MDB_ODBC_NAME_SIZE); - - /* Ok, we're all setup - Do the query */ - rc = ExecuteStatement(V->stmts.getObjectAttrInfo); - - if (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) { - SQLINTEGER count = 0; - - rc = SQLRowCount(V->stmts.getObjectAttrInfo, &count); - if (count < 1) { - /* No rows will be returned if we are not allowed to write this attribute to this object */ - return(FALSE); - } - } - - if (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) { - rc = SQLFetch(V->stmts.getObjectAttrInfo); - SQLCloseCursor(V->stmts.getObjectAttrInfo); - } - - if (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) { - attribute = V->params.getObjectAttrInfo.id; - single = (V->params.getObjectAttrInfo.single == 1); - type = (unsigned char) V->params.getObjectAttrInfo.type; - } else { - return(FALSE); - } - - /* - We now have the object ID, attribute ID, and the value for single and type. We can now begin. - */ - - /* If they are trying to write multiple values to a single, then bail */ - if (single && u > 1) { - return(FALSE); - } - - /* If it is a single value attribute make sure there are no other values stored already */ - if ((clear || single) && !MDBodbcClear(Object, Attribute, V)) { - return(FALSE); - } - - /* - We can finally add the value. Write it as the type the attribute should hold, even if it does not - match the type that the calling program is trying to write. If they don't match the calling program - is wrong. - */ - switch (type) { - case MDB_ATTR_SYN_DIST_NAME: { - unsigned long i; - - PrepareStatement(V->stmts.addDNValue, SQL_ADD_DN_VALUE, requireBindings, V); - if (requireBindings) { - BindLongInput(V->stmts.addDNValue, 1, &V->params.addDNValue.owner); - BindLongInput(V->stmts.addDNValue, 2, &V->params.addDNValue.attribute); - BindLongInput(V->stmts.addDNValue, 3, &V->params.addDNValue.value); - } - - if (V->stmts.addDNValue == SQL_NULL_HSTMT) { - return(FALSE); - } - - for (i = 0; i < u; i++) { - SQLINTEGER referencee; - - if (MDBodbcGetObjectID(v[i], &referencee, NULL, NULL, NULL, NULL, NULL, V)) { - /* We have to reset these, because GetObjectID will have overwritten then */ - V->params.addDNValue.owner = object; - V->params.addDNValue.attribute = attribute; - V->params.addDNValue.value = referencee; - - /* Ok, we're all setup - Do the query */ - rc = ExecuteStatement(V->stmts.addDNValue); - if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) { - SQLEndTran(SQL_HANDLE_DBC, V->handle->connection, SQL_ROLLBACK); - return(FALSE); - } - - if (attribute == MDBodbc.config.special.member) { - /* This is changing group membership, which means we need to copy rights to the members */ - - if (!MDBodbcCopyObjectRights(referencee, object, FALSE, V)) { - return(FALSE); - } - } - } else { - SQLEndTran(SQL_HANDLE_DBC, V->handle->connection, SQL_ROLLBACK); - return(FALSE); - } - } - - break; - } - - case MDB_ATTR_SYN_BOOL: { - unsigned long i; - - PrepareStatement(V->stmts.addBoolValue, SQL_ADD_BOOL_VALUE, requireBindings, V); - if (requireBindings) { - BindLongInput(V->stmts.addBoolValue, 1, &V->params.addBoolValue.owner); - BindLongInput(V->stmts.addBoolValue, 2, &V->params.addBoolValue.attribute); - BindLongInput(V->stmts.addBoolValue, 3, &V->params.addBoolValue.value); - } - - if (V->stmts.addBoolValue == SQL_NULL_HSTMT) { - return(FALSE); - } - - V->params.addBoolValue.owner = object; - V->params.addBoolValue.attribute = attribute; - - for (i = 0; i < u; i++) { - BOOL value; - - switch (v[i][0]) { - case '1': - case 'Y': - case 'y': - case 'T': - case 't': { - value = TRUE; - } - - case '0': - case 'N': - case 'n': - case 'F': - case 'f': - default: { - value = FALSE; - } - } - - /* Ok, we're all setup - Do the query */ - rc = ExecuteStatement(V->stmts.addBoolValue); - if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) { - SQLEndTran(SQL_HANDLE_DBC, V->handle->connection, SQL_ROLLBACK); - return(FALSE); - } - } - - break; - } - - case MDB_ATTR_SYN_BINARY: { - /* - FIXME - This should be implemented by Base 64ing the data, and storing it as if - it where a string. It would be best if it can be base 64'ed into the param that - is already bound so that we don't have to worry about memory. - */ - break; - } - - case MDB_ATTR_SYN_STRING: { - unsigned long i; - - PrepareStatement(V->stmts.addStringValue, SQL_ADD_STRING_VALUE, requireBindings, V); - if (requireBindings) { - BindLongInput(V->stmts.addStringValue, 1, &V->params.addStringValue.owner); - BindLongInput(V->stmts.addStringValue, 2, &V->params.addStringValue.attribute); - BindCharInput(V->stmts.addStringValue, 3, - V->params.addStringValue.value, &V->params.addStringValue.valueLength, MDB_ODBC_PART_SIZE);; - BindLongInput(V->stmts.addStringValue, 4, &V->params.addStringValue.complete); - } - - if (V->stmts.addStringValue == SQL_NULL_HSTMT) { - return(FALSE); - } - - V->params.addStringValue.owner = object; - V->params.addStringValue.attribute = attribute; - - for (i = 0; i < u; i++) { - unsigned char *value = v[i]; - - /* - It is important to be able to store strings of any length as a value, but it is much easier to deal with - the database if we have fixed sized records. Also some ODBC drivers may not like variable sized records. - - To handle this any string value larger than MDBC_ODBC_PART_SIZE (255) will be split into multiple records - which will be stored in order. The complete row will be set to true on the final record, to allow for easy - reading. Simply read them order by id until complete is true. - - That means they have to be split here though. This should rarely actually happen, because most values will - be much smaller than 255. - */ - - do { - StoreCharInput(value, V->params.addStringValue.value, V->params.addStringValue.valueLength, MDB_ODBC_PART_SIZE); - V->params.addStringValue.complete = (V->params.addStringValue.valueLength != MDB_ODBC_PART_SIZE); - - /* Ok, we're all setup - Do the query */ - rc = ExecuteStatement(V->stmts.addStringValue); - if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) { - SQLEndTran(SQL_HANDLE_DBC, V->handle->connection, SQL_ROLLBACK); - return(FALSE); - } - - value += MDB_ODBC_PART_SIZE; - } while (V->params.addStringValue.valueLength == MDB_ODBC_PART_SIZE); - } - - break; - } - - default: { - return(FALSE); - } - } - - SQLEndTran(SQL_HANDLE_DBC, V->handle->connection, SQL_COMMIT); - return(TRUE); -} - -BOOL -MDBodbcRemove(const unsigned char *Object, const unsigned char *Attribute, const unsigned char *Value, MDBValueStruct *V) -{ - MDBValueStruct *v; - unsigned long i; - - if (!Object || !Attribute || !Value || !V) { - return(FALSE); - } - - v = MDBodbcShareContext(V); - - MDBodbcRead(Object, Attribute, v); - for (i = 0; i < v->Used; i++) { - if (XplStrCaseCmp(v->Value[i], Value)) { - MDBodbcFreeValue(i, v); - MDBodbcWrite(Object, Attribute, v); - MDBodbcDestroyValueStruct(v); - - return(TRUE); - } - } - - V->ErrNo = ERR_NO_SUCH_VALUE; - - MDBodbcDestroyValueStruct(v); - return(FALSE); -} - -BOOL -MDBodbcRemoveDN(const unsigned char *Object, const unsigned char *Attribute, const unsigned char *Value, MDBValueStruct *V) -{ - MDBValueStruct *v; - unsigned long i; - SQLINTEGER value; - - if (!Object || !Attribute || !Value || !V || !MDBodbcGetObjectID(Value, &value, NULL, NULL, NULL, NULL, NULL, V)) { - return(FALSE); - } - - v = MDBodbcShareContext(V); - - MDBodbcRead(Object, Attribute, v); - for (i = 0; i < v->Used; i++) { - SQLINTEGER c; - - if (MDBodbcGetObjectID(v->Value[i], &c, NULL, NULL, NULL, NULL, NULL, V) && c == value) { - MDBodbcFreeValue(i, v); - MDBodbcWriteDN(Object, Attribute, v); - MDBodbcDestroyValueStruct(v); - return(TRUE); - } - } - - V->ErrNo = ERR_NO_SUCH_VALUE; - - MDBodbcDestroyValueStruct(v); - return(FALSE); -} - -BOOL -MDBodbcClear(const unsigned char *Object, const unsigned char *Attribute, MDBValueStruct *V) -{ - SQLINTEGER id; - BOOL allow; - - if (Object && Attribute && V && MDBodbcGetObjectID(Object, &id, NULL, NULL, &allow, NULL, NULL, V) && allow) { - SQLINTEGER attribute = 0; - SQLINTEGER rc; - BOOL requireBindings; - - PrepareStatement(V->stmts.getAttrByName, SQL_GET_ATTRIBUTE_BY_NAME, requireBindings, V); - if (requireBindings) { - BindCharInput(V->stmts.getAttrByName, 1, - V->params.getAttrByName.attribute, &V->params.getAttrByName.attributeLength, MDB_ODBC_NAME_SIZE); - BindLongResult(V->stmts.getAttrByName, 1, &V->params.getAttrByName.id); - } - - if (V->stmts.getAttrByName == SQL_NULL_HSTMT) { - return(FALSE); - } - - StoreCharInput(Attribute, V->params.getAttrByName.attribute, V->params.getAttrByName.attributeLength, MDB_ODBC_NAME_SIZE); - - /* Ok, we're all setup - Do the query */ - rc = ExecuteStatement(V->stmts.getAttrByName); - - if (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) { - rc = SQLFetch(V->stmts.getAttrByName); - SQLCloseCursor(V->stmts.getAttrByName); - } - - if (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) { - attribute = V->params.getAttrByName.id; - } else { - return(FALSE); - } - - if (attribute == MDBodbc.config.special.member) { - /* The attribute is 'Member' so we need to remove the rights that where granted by this group to its members. */ - PrepareStatement(V->stmts.delRightsByProvider, SQL_DEL_RIGHTS_BY_PROVIDER, requireBindings, V); - if (requireBindings) { - BindLongInput(V->stmts.delRightsByProvider, 1, &V->params.delRightsByProvider.provider); - } - - if (V->stmts.delRightsByProvider == SQL_NULL_HSTMT) { - return(FALSE); - } - - V->params.delRightsByProvider.provider = id; - - /* Ok, we're all setup - Do the query */ - rc = ExecuteStatement(V->stmts.delRightsByProvider); - if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO && rc != SQL_NO_DATA) { - return(FALSE); - } - } - - /* Ok try to delete the values now */ - PrepareStatement(V->stmts.clearAttribute, SQL_CLEAR_ATTRIBUTE, requireBindings, V); - if (requireBindings) { - BindLongInput(V->stmts.clearAttribute, 1, &V->params.clearAttribute.object); - BindLongInput(V->stmts.clearAttribute, 2, &V->params.clearAttribute.attribute); - } - - if (V->stmts.clearAttribute == SQL_NULL_HSTMT) { - return(FALSE); - } - - V->params.clearAttribute.object = id; - V->params.clearAttribute.attribute = attribute; - - /* Ok, we're all setup - Do the query */ - rc = ExecuteStatement(V->stmts.clearAttribute); - - if (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO || rc == SQL_NO_DATA) { - SQLEndTran(SQL_HANDLE_DBC, V->handle->connection, SQL_COMMIT); - return(TRUE); - } else { - SQLEndTran(SQL_HANDLE_DBC, V->handle->connection, SQL_ROLLBACK); - return(FALSE); - } - } - - return(FALSE); -} - -BOOL -MDBodbcIsObject(const unsigned char *Object, MDBValueStruct *V) -{ - signed long id; - BOOL allow; - - return(Object && V && MDBodbcGetObjectID(Object, &id, NULL, &allow, NULL, NULL, NULL, V) && allow); -} - -BOOL -MDBodbcGetObjectDetails(const unsigned char *Object, unsigned char *Type, unsigned char *RDN, unsigned char *DN, MDBValueStruct *V) -{ - signed long id; - BOOL allow; - - if (!Object || !V || !MDBodbcGetObjectID(Object, &id, NULL, &allow, NULL, NULL, NULL, V) || !allow) { - return(FALSE); - } - - if (RDN && !MDBodbcGetObjectDN(RDN, MDB_MAX_OBJECT_CHARS, id, TRUE, V)) { - return(FALSE); - } - - if (DN) { - unsigned long base = *(V->base.id); - - *(V->base.id) = -1; - if (!MDBodbcGetObjectDN(DN, MDB_MAX_OBJECT_CHARS, id, FALSE, V)) { - *(V->base.id) = base; - return(FALSE); - } - - *(V->base.id) = base; - } - - if (Type) { - SQLINTEGER rc; - BOOL requireBindings; - - PrepareStatement(V->stmts.getObjectClassName, SQL_GET_OBJECT_CLASSNAME, requireBindings, V); - if (requireBindings) { - BindLongInput(V->stmts.getObjectClassName, 1, &V->params.getObjectClassName.object); - BindCharResult(V->stmts.getObjectClassName, 1, V->params.getObjectClassName.class, MDB_ODBC_NAME_SIZE); - } - - if (V->stmts.getObjectClassName == SQL_NULL_HSTMT) { - return(FALSE); - } - - V->params.getObjectClassName.object = id; - - /* Ok, do it */ - rc = ExecuteStatement(V->stmts.getObjectClassName); - if (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) { - rc = SQLFetch(V->stmts.getObjectClassName); - SQLCloseCursor(V->stmts.getObjectClassName); - } - - if (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) { - strcpy(Type, V->params.getObjectClassName.class); - } else { - return(FALSE); - } - } - - return(TRUE); -} - -BOOL -MDBodbcGetObjectDetailsEx(const unsigned char *Object, MDBValueStruct *Types, unsigned char *RDN, unsigned char *DN, MDBValueStruct *V) -{ - /* FIXME: Implement this function */ - XplConsolePrintf("MDBodbcGetObjectDetailsEx() not implemented!\n"); - return FALSE; -} - -BOOL -MDBodbcVerifyPassword(const unsigned char *Object, const unsigned char *Password, MDBValueStruct *V) -{ - signed long id; - MD5_CTX md5; - unsigned char hash[32 + 1]; - unsigned char digest[16]; - unsigned long i; - SQLINTEGER rc; - BOOL requireBindings; - - if (!Object || !Password || !V || !MDBodbcGetObjectID(Object, &id, NULL, NULL, NULL, NULL, NULL, V)) { - return(FALSE); - } - - MD5_Init(&md5); - MD5_Update(&md5, Password, strlen(Password)); - MD5_Final(digest, &md5); - - for (i = 0; i < 16; i++) { - sprintf(hash + (i * 2), "%02x", digest[i]); - } - - PrepareStatement(V->stmts.verifyPassword, SQL_VERIFY_PASSWORD, requireBindings, V); - if (requireBindings) { - BindLongInput(V->stmts.verifyPassword, 1, &V->params.verifyPassword.object); - BindCharInput(V->stmts.verifyPassword, 2, - &V->params.verifyPassword.pass, &V->params.verifyPassword.passLength, 32); - } - - if (V->stmts.verifyPassword != SQL_NULL_HSTMT) { - V->params.verifyPassword.object = id; - StoreCharInput(hash, V->params.verifyPassword.pass, V->params.verifyPassword.passLength, 32); - - /* Ok, we're ready */ - rc = ExecuteStatement(V->stmts.verifyPassword); - if (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) { - rc = SQLFetch(V->stmts.verifyPassword); - SQLCloseCursor(V->stmts.verifyPassword); - - if (((rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) && - V->params.verifyPassword.object == id) || - (rc == SQL_NO_DATA && Password[0] == '\0')) - { - return(TRUE); - } - } - } - - return(FALSE); -} - -BOOL -MDBodbcChangePassword(const unsigned char *Object, const unsigned char *OldPassword, const unsigned char *NewPassword, MDBValueStruct *V) -{ - if (!OldPassword) { - return(FALSE); - } - - return(MDBodbcChangePasswordEx(Object, OldPassword, NewPassword, V)); -} - -BOOL -MDBodbcChangePasswordEx(const unsigned char *Object, const unsigned char *OldPassword, const unsigned char *NewPassword, MDBValueStruct *V) -{ - signed long id; - MD5_CTX md5; - unsigned char hash[32 + 1]; - unsigned char digest[16]; - unsigned long i; - SQLINTEGER rc; - BOOL requireBindings; - BOOL allow; - - if (!Object || !NewPassword || !V || !MDBodbcGetObjectID(Object, &id, NULL, NULL, &allow, NULL, NULL, V)) { - return(FALSE); - } - - /* - The password can only be changed if the current password is given, or the object logged in has - the right to write to the object. - */ - if ((allow && !OldPassword) || MDBodbcVerifyPassword(Object, OldPassword, V)) { - MD5_Init(&md5); - MD5_Update(&md5, NewPassword, strlen(NewPassword)); - MD5_Final(digest, &md5); - - for (i = 0; i < 16; i++) { - sprintf(hash + (i * 2), "%02x", digest[i]); - } - - /* Ok, set the new password */ - PrepareStatement(V->stmts.setPassword, SQL_SET_PASSWORD, requireBindings, V); - if (requireBindings) { - BindCharInput(V->stmts.setPassword, 1, - &V->params.setPassword.pass, &V->params.setPassword.passLength, 32); - BindLongInput(V->stmts.setPassword, 2, &V->params.setPassword.object); - } - - if (V->stmts.setPassword == SQL_NULL_HSTMT) { - return(FALSE); - } - - V->params.setPassword.object = id; - StoreCharInput(hash, V->params.setPassword.pass, V->params.setPassword.passLength, 32); - - /* Ok, we're ready */ - rc = ExecuteStatement(V->stmts.setPassword); - if (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) { - SQLEndTran(SQL_HANDLE_DBC, V->handle->connection, SQL_COMMIT); - return(TRUE); - } else { - SQLEndTran(SQL_HANDLE_DBC, V->handle->connection, SQL_ROLLBACK); - } - } - - return(FALSE); -} - -static __inline BOOL -checkFilter(unsigned char *value, const unsigned char *filter) -{ - if (filter) { - unsigned char *filt = strdup(filter); - unsigned char *f = filt; - - while (f && *f) { - switch (*f) { - case '?': { - /* A question mark matches one character. */ - if (*value == '\0') { - free(filt); - return(FALSE); - } - - value++; - f++; - - break; - } - - case '*': { - unsigned char *ptr; - unsigned char *e; - unsigned char w = '\0'; - - /* An asterisk matches zero or more characters. */ - - do { - f++; - } while (*f == '*'); - - if (*f == '\0') { - /* The asterisk is the last char, so the string matches */ - free(filt); - return(TRUE); - } - - /* Find the next wildcard */ - e = (unsigned char *) f; - while (*e && *e != '*' && *e != '?') { - e++; - } - - w = *e; - *e = '\0'; - - ptr = strstr(value, f); - if (!ptr) { - free(filt); - return(FALSE); - } - - value = ptr + strlen(f); - f = e; - - *e = w; - break; - } - - default: { - /* All other characters match themselves. */ - if (toupper(*f) != toupper(*value)) { - free(filt); - return(FALSE); - } - - f++; - value++; - - break; - } - } - } - - free(filt); - return(*value == '\0'); - } else { - /* If there is no filter, then it is a match */ - return(TRUE); - } -} - -long -MDBodbcEnumerateObjects(const unsigned char *Container, const unsigned char *Type, const unsigned char *Pattern, MDBValueStruct *V) -{ - signed long id; - SQLINTEGER rc; - BOOL requireBindings; - SQLHSTMT getChildren; - unsigned char dn[MDB_MAX_OBJECT_CHARS + 1]; - unsigned char *e; - BOOL allow; - - if (!Container || !V || !MDBodbcGetObjectID(Container, &id, NULL, &allow, NULL, NULL, NULL, V) || - !allow || !MDBodbcGetObjectDN(dn, MDB_MAX_OBJECT_CHARS, id, TRUE, V)) - { - return(FALSE); - } - - /* Set the position to write the new object names to */ - e = dn + strlen(dn); - *e = '\\'; - e++; - - /* Prepare both the statement with the class and without, bind to the same params */ - PrepareStatement(V->stmts.getChildren, SQL_GET_CHILDREN, requireBindings, V); - if (requireBindings) { - BindLongInput(V->stmts.getChildren, 1, &V->params.getChildren.object); - BindCharResult(V->stmts.getChildren, 1, V->params.getChildren.child, MDB_ODBC_PART_SIZE + 1); - BindLongResult(V->stmts.getChildren, 2, &V->params.getChildren.container); - } - - PrepareStatement(V->stmts.getChildrenByClass, SQL_GET_CHILDREN_BY_CLASS, requireBindings, V); - if (requireBindings) { - BindLongInput(V->stmts.getChildrenByClass, 1, &V->params.getChildren.object); - BindCharInput(V->stmts.getChildrenByClass, 2, - &V->params.getChildren.class, &V->params.getChildren.classLength, MDB_ODBC_NAME_SIZE); - BindLongInput(V->stmts.getChildrenByClass, 3, &V->params.getChildren.allContainers); - BindCharResult(V->stmts.getChildrenByClass, 1, V->params.getChildren.child, MDB_ODBC_PART_SIZE + 1); - BindLongResult(V->stmts.getChildrenByClass, 2, &V->params.getChildren.container); - } - - if (V->stmts.getChildren == SQL_NULL_HSTMT || V->stmts.getChildrenByClass == SQL_NULL_HSTMT) { - return(0); - } - - /* All Containers should be set to -1 for normal use */ - V->params.getChildren.allContainers = -1; - V->params.getChildren.object = id; - - if (Type && Type[0] != '\0' && !(Type[0] == '*' && Type[1] == '\0')) { - StoreCharInput(Type, V->params.getChildren.class, V->params.getChildren.classLength, MDB_ODBC_NAME_SIZE); - getChildren = V->stmts.getChildrenByClass; - } else { - getChildren = V->stmts.getChildren; - } - - rc = ExecuteStatement(getChildren); - - if (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) { - rc = SQLFetch(getChildren); - } - - while (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) { - if (!Pattern || !(*Pattern) || checkFilter(V->params.getChildren.child, Pattern)) { - strncpy(e, V->params.getChildren.child, MDB_MAX_OBJECT_CHARS - (e - dn)); - MDBodbcAddValue(dn, V); - } - - rc = SQLFetch(getChildren); - } - - SQLCloseCursor(getChildren); - - return(V->Used); -} - -const unsigned char * -MDBodbcEnumerateObjectsEx(const unsigned char *Container, const unsigned char *Type, const unsigned char *Pattern, unsigned long Flags, MDBEnumStruct *E, MDBValueStruct *V) -{ - SQLINTEGER rc; - - if (!E || !V) { - return(NULL); - } - - if (E->stmt == SQL_NULL_HSTMT) { - BOOL requireBindings; - BOOL allow; - - if (!Container || !MDBodbcGetObjectID(Container, &E->object, NULL, &allow, NULL, NULL, NULL, V) || - !allow || !MDBodbcGetObjectDN(E->dn, MDB_MAX_OBJECT_CHARS, E->object, FALSE, V)) - { - return(NULL); - } - - E->name = E->dn + strlen(E->dn); - *(E->name) = '\\'; - (E->name)++; - - /* We are not in a statement, so prepare one */ - if (Type && Type[0] != '\0' && !(Type[0] == '*' && Type[1] == '\0')) { - E->classlen = (Type) ? strlen(Type) : 0; - strcpy(E->class, Type); - - E->sql = SQL_GET_CHILDREN_BY_CLASS; - - if (Flags) { - E->allContainers = 1; - } else { - E->allContainers = -1; - } - } else { - E->sql = SQL_GET_CHILDREN; - } - - PrepareStatement(E->stmt, E->sql, requireBindings, V); - if (requireBindings) { - BindLongInput(E->stmt, 1, &E->object); - - if (E->sql == SQL_GET_CHILDREN_BY_CLASS) { - BindCharInput(E->stmt, 2, &E->class, &E->classlen, MDB_ODBC_NAME_SIZE); - BindLongInput(E->stmt, 3, &E->allContainers); - } - - BindCharResult(E->stmt, 1, E->result, MDB_ODBC_NAME_SIZE); - BindLongResult(E->stmt, 2, &E->container); - } - - rc = ExecuteStatement(E->stmt); - if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO && rc != SQL_NO_DATA) { - ReleaseStatement(V, E->stmt); - E->stmt = SQL_NULL_HSTMT; - } - } - - if (E->stmt != SQL_NULL_HSTMT && (E->sql == SQL_GET_CHILDREN || E->sql == SQL_GET_CHILDREN_BY_CLASS)) { - rc = SQLFetch(E->stmt); - while (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) { - if ((Flags && E->container) || !Pattern || !(*Pattern) || checkFilter(E->result, Pattern)) { - strncpy(E->name, E->result, MDB_MAX_OBJECT_CHARS - (E->name - E->dn)); - return(E->dn); - } - - rc = SQLFetch(E->stmt); - } - - if (rc == SQL_NO_DATA) { - ReleaseStatement(V, E->stmt); - E->stmt = SQL_NULL_HSTMT; - } - } - - return(NULL); -} - -const unsigned char * -MDBodbcEnumerateAttributesEx(const unsigned char *Object, MDBEnumStruct *E, MDBValueStruct *V) -{ - return(FALSE); -} - -BOOL -MDBodbcCreateAlias(const unsigned char *Alias, const unsigned char *AliasedObjectDn, MDBValueStruct *V) -{ - return(FALSE); -} - -BOOL -MDBodbcCreateObject(const unsigned char *Object, const unsigned char *Class, MDBValueStruct *Attribute, MDBValueStruct *Data, MDBValueStruct *V) -{ - SQLINTEGER parent; - SQLINTEGER parentClass; - SQLINTEGER id; - unsigned char *ptr; - unsigned char buffer[MDB_MAX_OBJECT_CHARS + 1]; - unsigned long i; - SQLINTEGER rc; - BOOL requireBindings; - BOOL allow; - - strncpy(buffer, Object, MDB_MAX_OBJECT_CHARS); - ptr = strrchr(buffer, '\\'); - - if (ptr == buffer) { - if (!MDBodbcGetObjectID("\\", &parent, &parentClass, NULL, &allow, NULL, NULL, V)) { - return(FALSE); - } - - ptr++; - } else if (ptr) { - *ptr = '\0'; - if (!MDBodbcGetObjectID(buffer, &parent, &parentClass, NULL, &allow, NULL, NULL, V)) { - return(FALSE); - } - - ptr++; - } else { - parent = *(V->base.id); - parentClass = *(V->base.class); - ptr = buffer; - - allow = *(V->base.write); - } - - if (!allow) { - return(FALSE); - } - - /* Verify mandatory attributes */ - PrepareStatement(V->stmts.getMandatoryByName, SQL_GET_MANDATORY_BY_NAME, requireBindings, V); - if (requireBindings) { - BindCharInput(V->stmts.getMandatoryByName, 1, - &V->params.getMandatoryByName.class, &V->params.getMandatoryByName.classLength, MDB_ODBC_NAME_SIZE); - BindCharResult(V->stmts.getMandatoryByName, 1, V->params.getMandatoryByName.class, MDB_ODBC_NAME_SIZE); - } - - if (V->stmts.getMandatoryByName != SQL_NULL_HSTMT) { - StoreCharInput(Class, V->params.getMandatoryByName.class, V->params.getMandatoryByName.classLength, MDB_ODBC_NAME_SIZE); - - rc = ExecuteStatement(V->stmts.getMandatoryByName); - if ((rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) && (!Attribute || Attribute->Used == 0)) { - SQLINTEGER count = 0; - - /* We don't have any attributes, so if we have any mandatorys then we fail right now */ - rc = SQLRowCount(V->stmts.getMandatoryByName, &count); - SQLCloseCursor(V->stmts.getMandatoryByName); - - if (count > 0) { - V->ErrNo = ERR_MISSING_MANDATORY; - return(FALSE); - } - } else { - if (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) { - rc = SQLFetch(V->stmts.getMandatoryByName); - } - - while (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) { - unsigned long i; - BOOL found = FALSE; - - for (i = 0; i < Attribute->Used; i++) { - /* Ignore the first char */ - if (XplStrCaseCmp(Attribute->Value[i] + 1, V->params.getMandatoryByName.class) == 0) { - found = TRUE; - break; - } - } - - if (!found) { - SQLCloseCursor(V->stmts.getMandatoryByName); - V->ErrNo = ERR_MISSING_MANDATORY; - return(FALSE); - } - - rc = SQLFetch(V->stmts.getMandatoryByName); - } - - if (rc != SQL_NO_DATA) { - V->ErrNo = ERR_MISSING_MANDATORY; - return(FALSE); - } else { - SQLCloseCursor(V->stmts.getMandatoryByName); - } - } - } - - PrepareStatement(V->stmts.createObject, SQL_CREATE_OBJECT, requireBindings, V); - if (requireBindings) { - BindCharInput(V->stmts.createObject, 1, - &V->params.createObject.name, &V->params.createObject.nameLength, MDB_ODBC_NAME_SIZE); - BindLongInput(V->stmts.createObject, 2, &V->params.createObject.parent); - BindCharInput(V->stmts.createObject, 3, - &V->params.createObject.class, &V->params.createObject.classLength, MDB_ODBC_NAME_SIZE); - BindLongInput(V->stmts.createObject, 4, &V->params.createObject.parentClass); - } - - if (V->stmts.createObject != SQL_NULL_HSTMT) { - V->params.createObject.parent = parent; - V->params.createObject.parentClass = parentClass; - StoreCharInput(ptr, V->params.createObject.name, V->params.createObject.nameLength, MDB_ODBC_NAME_SIZE); - StoreCharInput(Class, V->params.createObject.class, V->params.createObject.classLength, MDB_ODBC_NAME_SIZE); - - /* Ok, we're ready */ - rc = ExecuteStatement(V->stmts.createObject); - if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) { - SQLEndTran(SQL_HANDLE_DBC, V->handle->connection, SQL_ROLLBACK); - return(FALSE); - } - } - - /* - Setup rights - - Get the ID of the newly created object, and then copy the rights of the parent object - to it, with parent set properly. - */ - if (!MDBodbcGetObjectID(Object, &id, NULL, NULL, NULL, NULL, NULL, V)) { - /* - The object doesn't seem to have actually be created. This implies it can not be - contained in this type of container. - */ - V->ErrNo = ERR_ILLEGAL_CONTAINMENT; - SQLEndTran(SQL_HANDLE_DBC, V->handle->connection, SQL_ROLLBACK); - return(FALSE); - } - - if (!MDBodbcCopyObjectRights(id, parent, TRUE, V)) { - SQLEndTran(SQL_HANDLE_DBC, V->handle->connection, SQL_ROLLBACK); - return(FALSE); - } - - if (Attribute && Data) { - unsigned long l = Attribute->Used; - - if (l > Data->Used) { - l = Data->Used; - } - - for (i = 0; i < l; i++) { - MDBodbcWriteAny(Object, Attribute->Value[i] + 1, Attribute->Value[i][0], FALSE, Data->Value[i], V); - } - } - - SQLEndTran(SQL_HANDLE_DBC, V->handle->connection, SQL_COMMIT); - return(TRUE); -} - -BOOL -MDBodbcDeleteObject(const unsigned char *Object, BOOL Recursive, MDBValueStruct *V) -{ - signed long id; - BOOL allow; - BOOL result; - - if (!Object || !V || !MDBodbcGetObjectID(Object, &id, NULL, NULL, NULL, &allow, NULL, V) || !allow) { - return(FALSE); - } - - result = MDBodbcDeleteObjectByID(id, Recursive, V); - if (result) { - SQLEndTran(SQL_HANDLE_DBC, V->handle->connection, SQL_COMMIT); - return(TRUE); - } else { - SQLEndTran(SQL_HANDLE_DBC, V->handle->connection, SQL_ROLLBACK); - return(FALSE); - } -} - -static __inline BOOL -MDBodbcDeleteObjectByID(signed long id, BOOL Recursive, MDBValueStruct *V) -{ - SQLINTEGER rc; - BOOL requireBindings; - - if (id == -1) { - /* We don't allow deleting the root */ - return(FALSE); - } - - /* Remove all rights associated with this object */ - PrepareStatement(V->stmts.deleteObjectRights, SQL_DELETE_OBJECT_RIGHTS, requireBindings, V); - if (requireBindings) { - BindLongInput(V->stmts.deleteObjectRights, 1, &V->params.deleteObjectRights.object); - } - - if (V->stmts.deleteObjectRights == SQL_NULL_HSTMT) { - return(FALSE); - } - - V->params.deleteObjectRights.object = id; - rc = ExecuteStatement(V->stmts.deleteObjectRights); - - if (Recursive) { - SQLHSTMT getChildrenIDs = SQL_NULL_HSTMT; - signed long child; - - PrepareStatement(getChildrenIDs, SQL_GET_CHILDREN_IDS, requireBindings, V); - if (requireBindings) { - BindLongInput(getChildrenIDs, 1, &id); - BindLongResult(getChildrenIDs, 1, &child); - } - - if (getChildrenIDs == SQL_NULL_HSTMT) { - return(FALSE); - } - - rc = ExecuteStatement(getChildrenIDs); - if (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) { - rc = SQLFetch(getChildrenIDs); - } - - while (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) { - if (!MDBodbcDeleteObjectByID(child, Recursive, V)) { - ReleaseStatement(V, getChildrenIDs); - return(FALSE); - } - - rc = SQLFetch(getChildrenIDs); - } - - ReleaseStatement(V, getChildrenIDs); - if (rc != SQL_NO_DATA) { - return(FALSE); - } - } else { - SQLINTEGER count = 0; - - /* Fail if there are any children */ - PrepareStatement(V->stmts.hasChildren, SQL_HAS_CHILDREN, requireBindings, V); - if (requireBindings) { - BindLongInput(V->stmts.hasChildren, 1, &V->params.hasChildren.object); - BindLongResult(V->stmts.hasChildren, 1, &V->params.hasChildren.child); - } - - if (V->stmts.hasChildren == SQL_NULL_HSTMT) { - return(FALSE); - } - - V->params.hasChildren.object = id; - rc = ExecuteStatement(V->stmts.hasChildren); - SQLRowCount(V->stmts.hasChildren, &count); - SQLCloseCursor(V->stmts.hasChildren); - - if (count > 0) { - return(FALSE); - } - } - - /* Ok delete it now */ - PrepareStatement(V->stmts.deleteObjectValues, SQL_DELETE_OBJECT_VALUES, requireBindings, V); - if (requireBindings) { - BindLongInput(V->stmts.deleteObjectValues, 1, &V->params.deleteObjectValues.object); - } - - if (V->stmts.deleteObjectValues == SQL_NULL_HSTMT) { - return(FALSE); - } - - V->params.deleteObjectValues.object = id; - rc = ExecuteStatement(V->stmts.deleteObjectValues); - - PrepareStatement(V->stmts.deleteObject, SQL_DELETE_OBJECT, requireBindings, V); - if (requireBindings) { - BindLongInput(V->stmts.deleteObject, 1, &V->params.deleteObject.object); - } - - if (V->stmts.deleteObject== SQL_NULL_HSTMT) { - return(FALSE); - } - - V->params.deleteObject.object = id; - rc = ExecuteStatement(V->stmts.deleteObject); - return(rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO); -} - - -BOOL -MDBodbcRenameObject(const unsigned char *ObjectOld, const unsigned char *ObjectNew, MDBValueStruct *V) -{ - signed long object; - signed long id; - unsigned char *new; - unsigned char dn[MDB_MAX_OBJECT_CHARS + 1]; - SQLINTEGER rc; - BOOL requireBindings; - BOOL allow; - SQLINTEGER parent = -1; - - /* Verify that we have good arguments, and that the old object exists and that the new doesn't */ - if (!V || !ObjectNew || !ObjectOld || - !MDBodbcGetObjectID(ObjectOld, &object, NULL, NULL, NULL, NULL, &allow, V) || !allow) - { - return(FALSE); - } - - new = strrchr(ObjectNew, '\\'); - if (new) { - signed long class; - - strncpy(dn, ObjectNew, sizeof(dn)); - - /* A path was given, not just a name. Make sure the object referenced doesn't exist */ - if (MDBodbcGetObjectID(ObjectNew, &id, NULL, NULL, NULL, NULL, NULL, V)) { - return(FALSE); - } - - /* We have a container, so we need to move the object */ - dn[new - ObjectNew] = '\0'; - if (!MDBodbcGetObjectID(dn, &id, NULL, NULL, &allow, NULL, NULL, V) || !allow) { - /* The new container doesn't exist, or we aren't allowed to create in it */ - return(FALSE); - } - - /* Get the class of the object so we can verify containment */ - PrepareStatement(V->stmts.getObjectClass, SQL_GET_OBJECT_CLASS, requireBindings, V); - if (requireBindings) { - BindLongInput(V->stmts.getObjectClass, 1, &V->params.getObjectClass.object); - BindLongResult(V->stmts.getObjectClass, 1, &V->params.getObjectClass.class); - } - - if (V->stmts.getObjectClass == SQL_NULL_HSTMT) { - return(FALSE); - } - - V->params.getObjectClass.object = object; - - /* Ok, do it */ - rc = ExecuteStatement(V->stmts.getObjectClass); - if (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) { - rc = SQLFetch(V->stmts.getObjectClass); - SQLCloseCursor(V->stmts.getObjectClass); - } - - if (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) { - class = V->params.getObjectClass.class; - } else { - return(FALSE); - } - - /* Ok, now verify that the new container can contain this class */ - PrepareStatement(V->stmts.verifyContainment, SQL_VERIFY_CONTAINMENT, requireBindings, V); - if (requireBindings) { - BindLongInput(V->stmts.verifyContainment, 1, &V->params.verifyContainment.object); - BindLongInput(V->stmts.verifyContainment, 2, &V->params.verifyContainment.class); - BindLongResult(V->stmts.verifyContainment, 1, &V->params.verifyContainment.class); - } - - if (V->stmts.verifyContainment == SQL_NULL_HSTMT) { - return(FALSE); - } - - V->params.verifyContainment.object = id; - V->params.verifyContainment.class = class; - - /* Ok, do it */ - rc = ExecuteStatement(V->stmts.verifyContainment); - if (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) { - rc = SQLFetch(V->stmts.verifyContainment); - SQLCloseCursor(V->stmts.verifyContainment); - } - - if ((rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) || - class != V->params.verifyContainment.class) - { - return(FALSE); - } - - /* - Verify that the new parent is not actual below the object we are trying to - move, because that would cause a detached part of the tree. - */ - PrepareStatement(V->stmts.getParentInfo, SQL_GET_PARENT_INFO, requireBindings, V); - if (requireBindings) { - BindLongInput(V->stmts.getParentInfo, 1, &V->params.getParentInfo.object); - BindLongResult(V->stmts.getParentInfo, 1, &V->params.getParentInfo.object); - BindCharResult(V->stmts.getParentInfo, 2, V->params.getParentInfo.name, MDB_ODBC_NAME_SIZE); - } - - if (V->stmts.getParentInfo == SQL_NULL_HSTMT) { - return(FALSE); - } - - V->params.getParentInfo.object = id; - - do { - /* Ok, do it */ - rc = ExecuteStatement(V->stmts.getParentInfo); - if (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) { - if (parent == -1) { - parent = V->params.getParentInfo.object; - } - - rc = SQLFetch(V->stmts.getParentInfo); - SQLCloseCursor(V->stmts.getParentInfo); - } - - if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) { - break; - } - } while (V->params.getParentInfo.object != -1 && V->params.getParentInfo.object != object); - - if (V->params.getParentInfo.object == object) { - /* We can't move an object to a container below it */ - return(FALSE); - } - - /* - Now that we know that the object can be moved to the new container, we need to - remove all rights from this object, and all child objects that this object gets - from its parent container. - - We can not remove rights that are provided at a lower level though. Only remove - rights from the children that the current object has. - */ - if (!MDBodbcRemoveInheritedRights(id, TRUE, -1, V)) { - SQLEndTran(SQL_HANDLE_DBC, V->handle->connection, SQL_ROLLBACK); - return(FALSE); - } - - /* Ok, it has now passed all the checks, so the object can be moved */ - PrepareStatement(V->stmts.moveObject, SQL_MOVE_OBJECT, requireBindings, V); - if (requireBindings) { - BindLongInput(V->stmts.moveObject, 1, &V->params.moveObject.parent); - BindLongInput(V->stmts.moveObject, 2, &V->params.moveObject.object); - } - - if (V->stmts.moveObject == SQL_NULL_HSTMT) { - SQLEndTran(SQL_HANDLE_DBC, V->handle->connection, SQL_ROLLBACK); - return(FALSE); - } - - V->params.moveObject.object = object; - V->params.moveObject.parent = id; - - /* Ok, do it */ - rc = ExecuteStatement(V->stmts.moveObject); - if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) { - SQLEndTran(SQL_HANDLE_DBC, V->handle->connection, SQL_ROLLBACK); - return(FALSE); - } - - /* Update the pointer in case the object still needs to be renamed in its new container */ - new++; - - /* Copy the rights from the new container to the object */ - if (!MDBodbcCopyObjectRights(id, object, TRUE, V)) { - SQLEndTran(SQL_HANDLE_DBC, V->handle->connection, SQL_ROLLBACK); - return(FALSE); - } - } else { - /* Verify that an object doesn't exist with this name already */ - strncpy(dn, ObjectOld, sizeof(dn)); - - new = strrchr(dn, '\\'); - if (new) { - *(++new) = '\0'; - } - - strncpy(new, ObjectNew, sizeof(dn) - (new - dn)); - if (MDBodbcGetObjectID(dn, &id, NULL, NULL, NULL, NULL, NULL, V)) { - return(FALSE); - } - - /* No object exists with that name */ - new = (unsigned char *)ObjectNew; - } - - if (*new) { - /* Ok, time to rename */ - PrepareStatement(V->stmts.renameObject, SQL_RENAME_OBJECT, requireBindings, V); - if (requireBindings) { - BindCharInput(V->stmts.renameObject, 1, - &V->params.renameObject.name, &V->params.renameObject.nameLength, MDB_ODBC_NAME_SIZE); - BindLongInput(V->stmts.renameObject, 2, &V->params.renameObject.object); - } - - if (V->stmts.renameObject == SQL_NULL_HSTMT) { - SQLEndTran(SQL_HANDLE_DBC, V->handle->connection, SQL_ROLLBACK); - return(FALSE); - } - - StoreCharInput(new, V->params.renameObject.name, V->params.renameObject.nameLength, MDB_ODBC_NAME_SIZE); - V->params.renameObject.object = object; - - /* Ok, do it */ - rc = ExecuteStatement(V->stmts.renameObject); - if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) { - SQLEndTran(SQL_HANDLE_DBC, V->handle->connection, SQL_ROLLBACK); - return(FALSE); - } - } - - SQLEndTran(SQL_HANDLE_DBC, V->handle->connection, SQL_COMMIT); - return(TRUE); -} - -static __inline BOOL -MDBodbcSetObjectRightsByID(SQLINTEGER trustee, SQLINTEGER object, BOOL fromParent, SQLINTEGER provider, BOOL Read, BOOL Write, BOOL Delete, BOOL Rename, MDBValueStruct *V) -{ - SQLHSTMT getChildrenIDs = SQL_NULL_HSTMT; - SQLINTEGER child; - SQLINTEGER rc; - BOOL requireBindings; - - PrepareStatement(V->stmts.setRights, SQL_SET_RIGHTS, requireBindings, V); - if (requireBindings) { - BindLongInput(V->stmts.setRights, 1, &V->params.setGetRights.object); - BindLongInput(V->stmts.setRights, 2, &V->params.setGetRights.trustee); - BindLongInput(V->stmts.setRights, 3, &V->params.setGetRights.provider); - BindLongInput(V->stmts.setRights, 4, &V->params.setGetRights.parent); - BindLongInput(V->stmts.setRights, 5, &V->params.setGetRights.read); - BindLongInput(V->stmts.setRights, 6, &V->params.setGetRights.write); - BindLongInput(V->stmts.setRights, 7, &V->params.setGetRights.delete); - BindLongInput(V->stmts.setRights, 8, &V->params.setGetRights.rename); - } - - V->params.setGetRights.object = object; - V->params.setGetRights.trustee = trustee; - - V->params.setGetRights.parent = fromParent ? 1 : 0; - V->params.setGetRights.provider = provider; - - V->params.setGetRights.read = Read ? 1 : 0; - V->params.setGetRights.write = Write ? 1 : 0; - V->params.setGetRights.delete = Delete ? 1 : 0; - V->params.setGetRights.rename = Rename ? 1 : 0; - - rc = ExecuteStatement(V->stmts.setRights); - if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO && rc != SQL_NO_DATA) { - return(FALSE); - } - - /* Get the children */ - PrepareStatement(getChildrenIDs, SQL_GET_CHILDREN_IDS, requireBindings, V); - if (requireBindings) { - BindLongInput(getChildrenIDs, 1, &trustee); - BindLongResult(getChildrenIDs, 1, &child); - } - - if (getChildrenIDs == SQL_NULL_HSTMT) { - return(FALSE); - } - - rc = ExecuteStatement(getChildrenIDs); - if (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) { - rc = SQLFetch(getChildrenIDs); - } - - while (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) { - if (!MDBodbcSetObjectRightsByID(child, object, TRUE, provider, Read, Write, Delete, Rename, V)) { - ReleaseStatement(V, getChildrenIDs); - return(FALSE); - } - - rc = SQLFetch(getChildrenIDs); - } - - ReleaseStatement(V, getChildrenIDs); - if (rc != SQL_NO_DATA) { - return(FALSE); - } - - return(TRUE); -} - -static __inline BOOL -MDBodbcRemoveObjectRightsByID(SQLINTEGER trustee, SQLINTEGER object, MDBValueStruct *V) -{ - SQLHSTMT getChildrenIDs = SQL_NULL_HSTMT; - SQLINTEGER child; - SQLINTEGER rc; - BOOL requireBindings; - - PrepareStatement(V->stmts.delRightsByObject, SQL_DEL_RIGHTS_BY_OBJECT, requireBindings, V); - if (requireBindings) { - BindLongInput(V->stmts.delRightsByObject, 1, &V->params.delRightsByObject.object); - BindLongInput(V->stmts.delRightsByObject, 2, &V->params.delRightsByObject.trustee); - } - - V->params.delRightsByObject.object = object; - V->params.delRightsByObject.trustee = trustee; - - rc = ExecuteStatement(V->stmts.delRightsByObject); - if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO && rc != SQL_NO_DATA) { - return(FALSE); - } - - /* Get the children */ - PrepareStatement(getChildrenIDs, SQL_GET_CHILDREN_IDS, requireBindings, V); - if (requireBindings) { - BindLongInput(getChildrenIDs, 1, &trustee); - BindLongResult(getChildrenIDs, 1, &child); - } - - if (getChildrenIDs == SQL_NULL_HSTMT) { - return(FALSE); - } - - rc = ExecuteStatement(getChildrenIDs); - if (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) { - rc = SQLFetch(getChildrenIDs); - } - - while (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) { - if (!MDBodbcRemoveObjectRightsByID(child, object, V)) { - ReleaseStatement(V, getChildrenIDs); - return(FALSE); - } - - rc = SQLFetch(getChildrenIDs); - } - - ReleaseStatement(V, getChildrenIDs); - if (rc != SQL_NO_DATA) { - return(FALSE); - } - - return(TRUE); -} - -BOOL -MDBodbcGrantObjectRights(const unsigned char *Object, const unsigned char *TrusteeDN, BOOL Read, BOOL Write, BOOL Delete, BOOL Rename, BOOL Admin, MDBValueStruct *V) -{ - BOOL requireBindings; - SQLINTEGER rc; - SQLINTEGER object; - SQLINTEGER trustee; - BOOL r; - BOOL w; - BOOL d; - BOOL n; - BOOL allowed; - unsigned long used; - - /* - Ensure that both objects exist, and that we are allowed to write to the trustee - object. We will also get the rights that the current user has to the object, to - ensure that no rights are given that the current user does not have. - */ - if (!Object || !TrusteeDN || !V || - !MDBodbcGetObjectID(Object, &object, NULL, &r, &w, &d, &n, V) || - !MDBodbcGetObjectID(TrusteeDN, &trustee, NULL, NULL, &allowed, NULL, NULL, V) || - !allowed) - { - return(FALSE); - } - - used = V->Used; - - if ((Read && !r) || (Write && !w) || (Delete && !d) || (Rename && !n)) { - /* An attempt was made to give a right that the current user doesn't have */ - return(FALSE); - } - - /* - Ok, we now have the IDs of both objects, and we know that we are allowed to perform - this operation. First remove any right assignment that may already be in place - between this trustee and this object. By removing all rights to this object, where - the provider matches the trustee we can be sure this will work for all cases (child - objects, groups, security equals, etc) - */ - PrepareStatement(V->stmts.delRightsByProviderAndObject, SQL_DEL_RIGHTS_BY_PROVIDER_AND_OBJ, requireBindings, V); - if (requireBindings) { - BindLongInput(V->stmts.delRightsByProviderAndObject, 1, &V->params.delRightsByProviderAndObject.provider); - BindLongInput(V->stmts.delRightsByProviderAndObject, 2, &V->params.delRightsByProviderAndObject.object); - } - - if (V->stmts.delRightsByProviderAndObject != SQL_NULL_HSTMT) { - rc = ExecuteStatement(V->stmts.delRightsByProviderAndObject); - - if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO && rc != SQL_NO_DATA) { - SQLEndTran(SQL_HANDLE_DBC, V->handle->connection, SQL_ROLLBACK); - return(FALSE); - } - } - - if (!MDBodbcRemoveObjectRightsByID(trustee, object, V)) { - SQLEndTran(SQL_HANDLE_DBC, V->handle->connection, SQL_ROLLBACK); - return(FALSE); - } - - /* Update the rights on group members */ - MDBodbcRead(Object, "Member", V); - - while (V->Used > used) { - SQLINTEGER id; - - if (MDBodbcGetObjectID(V->Value[used], &id, NULL, NULL, NULL, NULL, NULL, V) && - !MDBodbcSetObjectRightsByID(id, object, FALSE, trustee, Read, Write, Delete, Rename, V)) - { - while (V->Used > used) { - MDBodbcFreeValue(used, V); - } - SQLEndTran(SQL_HANDLE_DBC, V->handle->connection, SQL_ROLLBACK); - return(FALSE); - } - - MDBodbcFreeValue(used, V); - } - - /* Alright, now its time to do the same thing, except to assign rights this time. */ - if (MDBodbcSetObjectRightsByID(trustee, object, FALSE, trustee, Read, Write, Delete, Rename, V)) { - SQLEndTran(SQL_HANDLE_DBC, V->handle->connection, SQL_COMMIT); - return(TRUE); - } else { - SQLEndTran(SQL_HANDLE_DBC, V->handle->connection, SQL_ROLLBACK); - return(FALSE); - } -} - -/* MDB-ODBC does not support MDBGrantAttributeRights. As far as I can tell nothing uses it anyway. */ -BOOL -MDBodbcGrantAttributeRights(const unsigned char *Object, const unsigned char *Attribute, const unsigned char *TrusteeDN, BOOL Read, BOOL Write, BOOL Admin, MDBValueStruct *V) -{ - return(TRUE); -} - -static BOOL -MDBodbcParseArguments(const unsigned char *Arguments) -{ - unsigned char *toFree; - unsigned char *ptr; - unsigned char *end; - BOOL result = TRUE; - - toFree = strdup(Arguments); - ptr = toFree; - - while (ptr) { - end = ptr + 1; - do { - end = strchr(end + 1, ','); - } while (end && end[-1] == '\\'); - - if (end) { - *end = '\0'; - } - - if (XplStrNCaseCmp(ptr, "DSN=", 4) == 0) { - strncpy(MDBodbc.config.dsn, ptr + 4, sizeof(MDBodbc.config.dsn)); - } else if (XplStrNCaseCmp(ptr, "user=", 5) == 0) { - strncpy(MDBodbc.config.user, ptr + 5, sizeof(MDBodbc.config.user)); - } else if (XplStrNCaseCmp(ptr, "pass=", 5) == 0) { - strncpy(MDBodbc.config.pass, ptr + 5, sizeof(MDBodbc.config.pass)); - } else if (XplStrNCaseCmp(ptr, "servername=", 11) == 0) { - strncpy(MDBodbc.config.servername, ptr + 11, sizeof(MDBodbc.config.servername)); - } else if (XplStrNCaseCmp(ptr, "treename=", 9) == 0) { - strncpy(MDBodbc.config.treename, ptr + 9, sizeof(MDBodbc.config.treename)); - } - - ptr = end; - if (ptr) { - ptr++; - } - } - - if (toFree) { - free(toFree); - } - - return(result); -} - -/* - Connect to the DB and ensure that all tables have been created, and that an - object exists for this server. -*/ -static BOOL -MDBodbcSetup() -{ - MDBHandle handle = MDBodbcAuthenticate(NULL, NULL, NULL); - MDBValueStruct *V = (handle) ? MDBodbcCreateValueStruct(handle, NULL) : NULL; - SQLHSTMT stmt = SQL_NULL_HSTMT; - SQLINTEGER rc; - BOOL requireBindings; - BOOL result = TRUE; - unsigned long i = 0; - - if (!V) { - if (handle) { - MDBodbcRelease(handle); - } - - XplConsolePrintf("MDBODBC: Failed to connect to database\n"); - - return(FALSE); - } - - /* Assume that the table does not exist */ - while (result && MDBodbcSQLPrepare[i]) { - PrepareStatement(stmt, MDBodbcSQLPrepare[i], requireBindings, V); - - rc = ExecuteStatement(stmt); - ReleaseStatement(V, stmt); - stmt = SQL_NULL_HSTMT; - - /* - Only return FALSE if it is the first line that fails. There are some other - lines which are expected to fail. A few of the table definitions work differently - for one database than they do for others, so both versions are included, and one - will fail. - */ - if (i == 0 && rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) { - SQLEndTran(SQL_HANDLE_DBC, V->handle->connection, SQL_ROLLBACK); - - result = FALSE; - } - - SQLEndTran(SQL_HANDLE_DBC, V->handle->connection, SQL_COMMIT); - i++; - } - - /* Commit the new tables */ - SQLEndTran(SQL_HANDLE_DBC, V->handle->connection, SQL_COMMIT); - - if (result) { - /* Prepare rights for setup. These rights will allow full access, until they are removed later */ - i = 0; - - while (result && MDBodbcSQLSetPrepareRights[i]) { - SQLSMALLINT count; - - PrepareStatement(stmt, MDBodbcSQLSetPrepareRights[i], requireBindings, V); - rc = SQLNumParams(stmt, &count); - - if (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) { - if (count == 1) { - /* We know that the only param required is the treename */ - MDBodbc.config.treenameLength = strlen(MDBodbc.config.treename); - BindCharInput(stmt, 1, MDBodbc.config.treename, &MDBodbc.config.treenameLength, MDB_ODBC_NAME_SIZE); - } - - rc = ExecuteStatement(stmt); - } - - ReleaseStatement(V, stmt); - stmt = SQL_NULL_HSTMT; - - if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) { - SQLEndTran(SQL_HANDLE_DBC, V->handle->connection, SQL_ROLLBACK); - - result = FALSE; - } - - i++; - } - SQLEndTran(SQL_HANDLE_DBC, V->handle->connection, SQL_COMMIT); - - /* Define the default attributes */ - if (result) { - MDBodbcBaseSchemaAttributes *attribute; - - /* End the transaction */ - SQLEndTran(SQL_HANDLE_DBC, V->handle->connection, SQL_COMMIT); - - /* Define the default attributes */ - attribute = &MDBodbcBaseSchemaAttributesList[0]; - while (result && (attribute->name != NULL)) { - result = MDBodbcDefineAttribute(attribute->name, NULL, attribute->type, - attribute->flags & 0x0001, attribute->flags & 0x0040, attribute->flags & 0x0080, V); - - attribute++; - } - } - - /* Define the default classes */ - if (result) { - MDBValueStruct *superclass = MDBodbcShareContext(V); - MDBValueStruct *containedby = MDBodbcShareContext(V); - MDBValueStruct *naming = MDBodbcShareContext(V); - MDBValueStruct *mandatory = MDBodbcShareContext(V); - MDBValueStruct *optional = MDBodbcShareContext(V); - MDBodbcBaseSchemaClasses *c; - MDBodbcBaseSchemaClasses *cSource; - unsigned char *ptr; - unsigned char *cur; - - c = (MDBodbcBaseSchemaClasses *)malloc(sizeof(MDBodbcBaseSchemaClasses)); - if (superclass && containedby && naming && mandatory && optional && c) { - cSource = &MDBodbcBaseSchemaClassesList[0]; - while (result && (cSource->name != NULL)) { - c->flags = cSource->flags; - - c->name = strdup(cSource->name); - - if (cSource->superClass) { - c->superClass = strdup(cSource->superClass); - } else { - c->superClass = NULL; - } - - if (cSource->containedBy) { - c->containedBy = strdup(cSource->containedBy); - } else { - c->containedBy = NULL; - } - - if (cSource->namedBy) { - c->namedBy = strdup(cSource->namedBy); - } else { - c->namedBy = NULL; - } - - if (cSource->mandatory) { - c->mandatory = strdup(cSource->mandatory); - } else { - c->mandatory = NULL; - } - - if (cSource->optional) { - c->optional = strdup(cSource->optional); - } else { - c->optional = NULL; - } - - if (c->superClass) { - MDBodbcAddValue(c->superClass, superclass); - } - - if (c->containedBy) { - ptr = c->containedBy; - - do { - cur = ptr; - ptr = strchr(cur, ','); - if (ptr) { - *ptr = '\0'; - } - - MDBodbcAddValue(cur, containedby); - - if (ptr) { - *ptr = ','; - - ptr++; - } - } while (ptr); - } - - if (c->namedBy) { - ptr = c->namedBy; - - do { - cur = ptr; - ptr = strchr(cur, ','); - if (ptr) { - *ptr = '\0'; - } - - MDBodbcAddValue(cur, naming); - - if (ptr) { - *ptr = ','; - - ptr++; - } - } while (ptr); - } - - if (c->mandatory) { - ptr = c->mandatory; - - do { - cur = ptr; - ptr = strchr(cur, ','); - if (ptr) { - *ptr = '\0'; - } - - MDBodbcAddValue(cur, mandatory); - - if (ptr) { - *ptr = ','; - - ptr++; - } - } while (ptr); - } - - if (c->optional) { - ptr = c->optional; - - do { - cur = ptr; - ptr = strchr(cur, ','); - if (ptr) { - *ptr = '\0'; - } - - MDBodbcAddValue(cur, optional); - - if (ptr) { - *ptr = ','; - - ptr++; - } - } while (ptr); - } - - result = MDBodbcDefineClass(c->name, NULL, c->flags & 0x01, superclass, containedby, naming, mandatory, optional, V); - - free(c->name); - c->name = NULL; - - if (c->superClass) { - free(c->superClass); - c->superClass = NULL; - } - - if (c->containedBy) { - free(c->containedBy); - c->containedBy = NULL; - } - - if (c->namedBy) { - free(c->namedBy); - c->namedBy = NULL; - } - - if (c->mandatory) { - free(c->mandatory); - c->mandatory = NULL; - } - - if (c->optional) { - free(c->optional); - c->optional = NULL; - } - - MDBodbcFreeValues(optional); - MDBodbcFreeValues(mandatory); - MDBodbcFreeValues(naming); - MDBodbcFreeValues(containedby); - MDBodbcFreeValues(superclass); - - cSource++; - } - } - - if (optional) { - MDBodbcDestroyValueStruct(optional); - } - - if (mandatory) { - MDBodbcDestroyValueStruct(mandatory); - } - - if (naming) { - MDBodbcDestroyValueStruct(naming); - } - - if (containedby) { - MDBodbcDestroyValueStruct(containedby); - } - - if (superclass) { - MDBodbcDestroyValueStruct(superclass); - } - - if (c) { - free(c); - } - } - - /* - Create the root of the tree. This must be done after creating the default - class list, but before creating any other objects. This object has an id - of -1. It is the only object with a fixed id, so that we always know where - the root of the tree is. It is also listed as its own parent. This way if - a DN is given with a format of \Tree\Blah\Foo or \Blah\Foo they will both - work correctly. - */ - if (result) { - i = 0; - - while (result && MDBodbcSQLCreateRoot[i]) { - SQLSMALLINT count; - - PrepareStatement(stmt, MDBodbcSQLCreateRoot[i], requireBindings, V); - rc = SQLNumParams(stmt, &count); - - if (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) { - if (count == 1) { - /* We know that the only param required is the treename */ - MDBodbc.config.treenameLength = strlen(MDBodbc.config.treename); - BindCharInput(stmt, 1, MDBodbc.config.treename, &MDBodbc.config.treenameLength, MDB_ODBC_NAME_SIZE); - } - - rc = ExecuteStatement(stmt); - } - - ReleaseStatement(V, stmt); - stmt = SQL_NULL_HSTMT; - - if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) { - SQLEndTran(SQL_HANDLE_DBC, V->handle->connection, SQL_ROLLBACK); - - result = FALSE; - } - - i++; - } - - SQLEndTran(SQL_HANDLE_DBC, V->handle->connection, SQL_COMMIT); - } - - /* - Now that we have created the schema, we need to destroy the value struct we have been using - and create a new one. The cached data in that value struct will now be incorrect because there - was no schema when it was created. - */ - MDBodbcDestroyValueStruct(V); - V = MDBodbcCreateValueStruct(handle, NULL); - - /* Create the base objects */ - if (result) { - if (!MDBodbcCreateObject("\\System", "Organization", NULL, NULL, V) || - !MDBodbcCreateObject("\\System\\admin", "User", NULL, NULL, V) || - !MDBodbcCreateObject("\\System\\administrators", "Group", NULL, NULL, V)) - { - XplConsolePrintf("Failed to create default objects\n"); - - result = FALSE; - } - - if (result) { - result = MDBodbcChangePasswordEx("\\System\\admin", NULL, MDBodbc.config.pass, V); - } - - if (result) { - MDBodbcSetValueStructContext("\\System", V); - result = MDBodbcCreateObject(MDBodbc.config.servername, "NCP Server", NULL, NULL, V); - } - } - - if (result) { - /* Create the tree info entry */ - MDBodbcGetObjectID("\\System", &MDBodbc.config.defaultContext, NULL, NULL, NULL, NULL, NULL, V); - - /* Create the tree info entry */ - PrepareStatement(V->stmts.setTreeInfo, SQL_SET_TREE_INFO, requireBindings, V); - if (requireBindings) { - MDBodbc.config.treenameLength = strlen(MDBodbc.config.treename); - BindCharInput(V->stmts.setTreeInfo, 1, - &MDBodbc.config.treename, &MDBodbc.config.treenameLength, sizeof(MDBodbc.config.treename)); - BindLongInput(V->stmts.setTreeInfo, 2, &MDBodbc.config.defaultContext); - } - - rc = ExecuteStatement(V->stmts.setTreeInfo); - result = (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO); - ReleaseStatement(V, stmt); - } - - if (result) { - i = 0; - - while (result && MDBodbcSQLSetInitialRights[i]) { - PrepareStatement(stmt, MDBodbcSQLSetInitialRights[i], requireBindings, V); - rc = ExecuteStatement(stmt); - - ReleaseStatement(V, stmt); - stmt = SQL_NULL_HSTMT; - - if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) { - SQLEndTran(SQL_HANDLE_DBC, V->handle->connection, SQL_ROLLBACK); - - result = FALSE; - } - - i++; - } - } - - if (!result) { - SQLEndTran(SQL_HANDLE_DBC, V->handle->connection, SQL_ROLLBACK); - } - - MDBodbcDestroyValueStruct(V); - MDBodbcRelease(handle); - ReleaseStatement(V, stmt); - - return(result); - } else { - /* The tree is already setup, just read the tree info */ - PrepareStatement(V->stmts.getTreeInfo, SQL_GET_TREE_INFO, requireBindings, V); - if (requireBindings) { - BindCharResult(V->stmts.getTreeInfo, 1, MDBodbc.config.treename, sizeof(MDBodbc.config.treename)); - BindLongResult(V->stmts.getTreeInfo, 2, &MDBodbc.config.defaultContext); - } - - rc = ExecuteStatement(V->stmts.getTreeInfo); - if (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) { - rc = SQLFetch(V->stmts.getTreeInfo); - } - - if (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) { - SQLCloseCursor(V->stmts.getTreeInfo); - - } - } - - /* - Get the ID of the 'Member' attribute. It is a special attribute in that we - need to update rights whenever it is written to (or cleared). - */ - PrepareStatement(V->stmts.getAttrByName, SQL_GET_ATTRIBUTE_BY_NAME, requireBindings, V); - if (requireBindings) { - BindCharInput(V->stmts.getAttrByName, 1, - V->params.getAttrByName.attribute, &V->params.getAttrByName.attributeLength, MDB_ODBC_NAME_SIZE); - BindLongResult(V->stmts.getAttrByName, 1, &V->params.getAttrByName.id); - } - - StoreCharInput("Member", V->params.getAttrByName.attribute, V->params.getAttrByName.attributeLength, MDB_ODBC_NAME_SIZE); - - /* Ok, we're all setup - Do the query */ - rc = ExecuteStatement(V->stmts.getAttrByName); - - if (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) { - rc = SQLFetch(V->stmts.getAttrByName); - SQLCloseCursor(V->stmts.getAttrByName); - } - - /* Cleanup */ - MDBodbcDestroyValueStruct(V); - MDBodbcRelease(handle); - - if (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) { - MDBodbc.config.special.member = V->params.getAttrByName.id; - return(TRUE); - } else { - return(FALSE); - } -} - -EXPORT BOOL -MDBODBCInit(MDBDriverInitStruct *Init) -{ - MDBodbc.unload = FALSE; - SQLINTEGER rc; - - /* Allocate the ODBC environment */ - MDBodbc.env = SQL_NULL_HENV; - rc = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &MDBodbc.env); - if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) { - return(FALSE); - } - - rc = SQLSetEnvAttr(MDBodbc.env, SQL_ATTR_ODBC_VERSION, (SQLPOINTER)SQL_OV_ODBC3, SQL_IS_INTEGER); - if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) { - SQLFreeHandle(SQL_HANDLE_ENV, MDBodbc.env); - return(FALSE); - } - - /* - Setup some defaults - - If a username or password isn't provided in Init->Arguments we'll have to assume that the - DSN is already configured with a proper username and password. - */ - memset(&MDBodbc.config, 0, sizeof(MDBodbc.config)); - strcpy(MDBodbc.config.dsn, "MDB"); - strcpy(MDBodbc.config.treename, "Tree"); - - gethostname(MDBodbc.config.servername, sizeof(MDBodbc.config.servername)); - - if (Init->Arguments) { - MDBodbcParseArguments(Init->Arguments); - } - - Init->Interface.MDBAdd = MDBodbcAdd; - Init->Interface.MDBAddAttribute = MDBodbcAddAttribute; - Init->Interface.MDBAddDN = MDBodbcAddDN; - Init->Interface.MDBAddValue = MDBodbcAddValue; - Init->Interface.MDBAuthenticate = MDBodbcAuthenticate; - Init->Interface.MDBChangePassword = MDBodbcChangePassword; - Init->Interface.MDBChangePasswordEx = MDBodbcChangePasswordEx; - Init->Interface.MDBClear = MDBodbcClear; - Init->Interface.MDBCreateAlias = MDBodbcCreateAlias; - Init->Interface.MDBCreateEnumStruct = MDBodbcCreateEnumStruct; - Init->Interface.MDBCreateObject = MDBodbcCreateObject; - Init->Interface.MDBCreateValueStruct = MDBodbcCreateValueStruct; - Init->Interface.MDBDefineAttribute = MDBodbcDefineAttribute; - Init->Interface.MDBDefineClass = MDBodbcDefineClass; - Init->Interface.MDBDeleteObject = MDBodbcDeleteObject; - Init->Interface.MDBDestroyEnumStruct = MDBodbcDestroyEnumStruct; - Init->Interface.MDBDestroyValueStruct = MDBodbcDestroyValueStruct; - Init->Interface.MDBEnumerateAttributesEx = MDBodbcEnumerateAttributesEx; - Init->Interface.MDBEnumerateObjects = MDBodbcEnumerateObjects; - Init->Interface.MDBEnumerateObjectsEx = MDBodbcEnumerateObjectsEx; - Init->Interface.MDBFreeValue = MDBodbcFreeValue; - Init->Interface.MDBFreeValues = MDBodbcFreeValues; - Init->Interface.MDBGetObjectDetails = MDBodbcGetObjectDetails; - Init->Interface.MDBGetObjectDetailsEx = MDBodbcGetObjectDetailsEx; - Init->Interface.MDBGetServerInfo = MDBodbcGetServerInfo; - Init->Interface.MDBGetBaseDN = MDBodbcGetBaseDN; - Init->Interface.MDBGrantAttributeRights = MDBodbcGrantAttributeRights; - Init->Interface.MDBGrantObjectRights = MDBodbcGrantObjectRights; - Init->Interface.MDBIsObject = MDBodbcIsObject; - Init->Interface.MDBListContainableClasses = MDBodbcListContainableClasses; - Init->Interface.MDBListContainableClassesEx = MDBodbcListContainableClassesEx; - Init->Interface.MDBRead = MDBodbcRead; - Init->Interface.MDBReadDN = MDBodbcRead; - Init->Interface.MDBReadEx = MDBodbcReadEx; - Init->Interface.MDBRelease = MDBodbcRelease; - Init->Interface.MDBRemove = MDBodbcRemove; - Init->Interface.MDBRemoveDN = MDBodbcRemoveDN; - Init->Interface.MDBRenameObject = MDBodbcRenameObject; - Init->Interface.MDBSetValueStructContext = MDBodbcSetValueStructContext; - Init->Interface.MDBShareContext = MDBodbcShareContext; - Init->Interface.MDBUndefineAttribute = MDBodbcUndefineAttribute; - Init->Interface.MDBUndefineClass = MDBodbcUndefineClass; - Init->Interface.MDBVerifyPassword = MDBodbcVerifyPassword; - Init->Interface.MDBVerifyPasswordEx = MDBodbcVerifyPassword; - Init->Interface.MDBWrite = MDBodbcWrite; - Init->Interface.MDBWriteDN = MDBodbcWriteDN; - Init->Interface.MDBWriteTyped = MDBodbcWriteTyped; - - if (!MDBodbcSetup()) { - SQLFreeHandle(SQL_HANDLE_ENV, MDBodbc.env); - return(FALSE); - } else { - return(TRUE); - } -} - -EXPORT void -MDBODBCShutdown(void) -{ - SQLFreeHandle(SQL_HANDLE_ENV, MDBodbc.env); - MDBodbc.unload = TRUE; - return; -} - -#if defined(NETWARE) || defined(LIBC) -int -MDBodbcRequestUnload(void) -{ - if (!MDBodbc.unload) { - int OldTGid; - - OldTGid=XplSetThreadGroupID(MDBodbc.id.group); - - XplConsolePrintf("\rThis NLM will automatically be unloaded by the thread that loaded it.\n"); - XplConsolePrintf("\rIt does not allow manual unloading.\n"); - XplSetCurrentScreen(XplCreateScreen("System Console", 0)); - XplUngetCh('n'); - - XplSetThreadGroupID(OldTGid); - - return(1); - } - - return(0); -} - -void -MDBodbcSigHandler(int Signal) -{ - int OldTGid; - - OldTGid=XplSetThreadGroupID(MDBodbc.id.group); - - XplSignalLocalSemaphore(MDBodbc.sem.shutdown); - XplWaitOnLocalSemaphore(MDBodbc.sem.shutdown); - - /* Do any required cleanup */ - MDBodbcShutdown(); - - XplCloseLocalSemaphore(MDBodbc.sem.shutdown); - XplSetThreadGroupID(OldTGid); -} - -int -main(int argc, char *argv[]) -{ - MDBodbc.id.main=XplGetThreadID(); - MDBodbc.id.group=XplGetThreadGroupID(); - - signal(SIGTERM, MDBodbcSigHandler); - - /* - 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... - */ - - XplOpenLocalSemaphore(MDBodbc.sem.shutdown, 0); - XplWaitOnLocalSemaphore(MDBodbc.sem.shutdown); - XplSignalLocalSemaphore(MDBodbc.sem.shutdown); - return(0); -} -#endif - -#ifdef WIN32 -BOOL WINAPI -DllMain(HINSTANCE hInst, DWORD Reason, LPVOID Reserved) -{ - if (Reason == DLL_PROCESS_ATTACH) { - DisableThreadLibraryCalls(hInst); - } - - return(TRUE); -} -#endif - -/* StreamIO needs this */ -BOOL -MWHandleNamedTemplate(void *ignored1, unsigned char *ignored2, void *ignored3) -{ - return(FALSE); -} diff --git a/src/libs/mdb-odbc/mdbodbcp.h b/src/libs/mdb-odbc/mdbodbcp.h deleted file mode 100644 index 52bb71b..0000000 --- a/src/libs/mdb-odbc/mdbodbcp.h +++ /dev/null @@ -1,956 +0,0 @@ -#ifndef MDBODBCP_H -#define MDBODBCP_H - -#define MDB_ODBC_ROOT_ID -1 -#define VALUE_ALLOC_SIZE 20 -#define MDB_ODBC_NAME_SIZE 64 -#define MDB_ODBC_PART_SIZE 255 - -typedef struct { - /* Semi-public; known to the main MDB library */ - unsigned char Description[128]; - struct _MDBInterfaceStruct *Interface; - - /* Private */ - signed long object; - SQLHDBC connection; -} MDBodbcContextStruct; - -typedef MDBodbcContextStruct *MDBHandle; - -typedef struct { - /* Public part, exposed to allow simpler code */ - unsigned char **Value; - unsigned long Used; - unsigned long ErrNo; - struct _MDBInterfaceStruct *Interface; - - /* Private part, not exposed in public header */ - unsigned long Allocated; - MDBodbcContextStruct *handle; - - signed long statementCount; - - /* - The base pointer will be used whenever the Base DN ID is needed. This is - a pointer so that it can be set to the address of another value struct when - MDBShareContext() is used. - */ - struct { - SQLINTEGER *id; - SQLINTEGER value; - - SQLINTEGER *class; - SQLINTEGER classValue; - - BOOL *read; - BOOL readValue; - BOOL *write; - BOOL writeValue; - BOOL *delete; - BOOL deleteValue; - BOOL *rename; - BOOL renameValue; - } base; - - struct { - unsigned char dn[255 + 1]; - SQLINTEGER id; - SQLINTEGER class; - - BOOL read; - BOOL write; - BOOL delete; - BOOL rename; - unsigned long time; - } cache; - - struct { - SQLHSTMT asArray[0]; - SQLHSTMT getTreeInfo; - SQLHSTMT setTreeInfo; - SQLHSTMT getRootRights; - SQLHSTMT getRightsProviders; - SQLHSTMT getRights; - SQLHSTMT setRights; - SQLHSTMT delRightsByProviderAndObject; - SQLHSTMT delRightsByProvider; - SQLHSTMT delRightsByObject; - SQLHSTMT delRightsByParent; - SQLHSTMT delRightsByChild; - SQLHSTMT getObjectID; - SQLHSTMT getAttrByName; - SQLHSTMT getClassByName; - SQLHSTMT getObjectAttrInfo; - SQLHSTMT getParentInfo; - SQLHSTMT getObjectClass; - SQLHSTMT getObjectClassName; - SQLHSTMT verifyContainment; - SQLHSTMT listContainment; - SQLHSTMT createObject; - SQLHSTMT createAttribute; - SQLHSTMT createClass; - SQLHSTMT createSuperClass; - SQLHSTMT deleteObjectValues; - SQLHSTMT deleteObjectRights; - SQLHSTMT deleteObject; - SQLHSTMT copySuperClass; - SQLHSTMT createContainment; - SQLHSTMT createMandatory; - SQLHSTMT getMandatoryByName; - SQLHSTMT createOptional; - SQLHSTMT createNaming; - SQLHSTMT copyContainment; - SQLHSTMT copyMandatory; - SQLHSTMT copyOptional; - SQLHSTMT copyNaming; - SQLHSTMT clearAttribute; - SQLHSTMT addDNValue; - SQLHSTMT addStringValue; - SQLHSTMT addBoolValue; - SQLHSTMT moveObject; - SQLHSTMT renameObject; - SQLHSTMT verifyPassword; - SQLHSTMT setPassword; - SQLHSTMT deleteAttr; - SQLHSTMT deleteAttrFromMandatory; - SQLHSTMT deleteAttrFromOptional; - SQLHSTMT deleteAttrFromNaming; - SQLHSTMT deleteAttrFromValues; - SQLHSTMT deleteAttrFromRights; - SQLHSTMT deleteClassFromContainment; - SQLHSTMT deleteClassFromMandatory; - SQLHSTMT deleteClassFromOptional; - SQLHSTMT deleteClassFromNaming; - SQLHSTMT deleteClass; - SQLHSTMT readValue; - SQLHSTMT getChildren; - SQLHSTMT getChildrenByClass; - SQLHSTMT getChildrenIDs; - SQLHSTMT hasChildren; - } stmts; - - union { - struct { - SQLINTEGER read; - SQLINTEGER write; - SQLINTEGER delete; - SQLINTEGER rename; - } getRootRights; - - struct { - SQLINTEGER trustee; - SQLINTEGER provider; - } getRightsProviders; - - /* Used by getRights and setRights */ - struct { - SQLINTEGER object; - SQLINTEGER trustee; - SQLINTEGER provider; - SQLINTEGER parent; - SQLINTEGER read; - SQLINTEGER write; - SQLINTEGER delete; - SQLINTEGER rename; - } setGetRights; - - struct { - SQLINTEGER provider; - SQLINTEGER object; - } delRightsByProviderAndObject; - - struct { - SQLINTEGER provider; - } delRightsByProvider; - - struct { - SQLINTEGER object; - SQLINTEGER trustee; - } delRightsByObject; - - struct { - SQLINTEGER trustee; - } delRightsByParent; - - struct { - SQLINTEGER provider; - SQLINTEGER trustee; - } delRightsByChild; - - struct { - unsigned char object[MDB_ODBC_NAME_SIZE + 1]; - SQLINTEGER objectLength; - SQLINTEGER id; - SQLINTEGER class; - SQLINTEGER read; - SQLINTEGER write; - SQLINTEGER delete; - SQLINTEGER rename; - } getObjectID; - - struct { - unsigned char attribute[MDB_ODBC_NAME_SIZE + 1]; - SQLINTEGER attributeLength; - SQLINTEGER id; - } getAttrByName; - - struct { - SQLINTEGER attribute; - } deleteAttr; - - struct { - SQLINTEGER object; - unsigned char attribute[MDB_ODBC_NAME_SIZE + 1]; - SQLINTEGER attributeLength; - SQLINTEGER id; - SQLINTEGER single; - SQLINTEGER type; - } getObjectAttrInfo; - - struct { - SQLINTEGER object; - unsigned char name[MDB_ODBC_NAME_SIZE + 1]; - } getParentInfo; - - struct { - SQLINTEGER object; - SQLINTEGER class; - } getObjectClass; - - struct { - SQLINTEGER object; - unsigned char class[MDB_ODBC_NAME_SIZE + 1]; - } getObjectClassName; - - struct { - SQLINTEGER object; - SQLINTEGER child; - } hasChildren; - - struct { - SQLINTEGER object; - SQLINTEGER class; - } verifyContainment; - - struct { - SQLINTEGER object; - unsigned char name[MDB_ODBC_NAME_SIZE + 1]; - } listContainment; - - struct { - unsigned char name[MDB_ODBC_NAME_SIZE + 1]; - SQLINTEGER nameLength; - SQLINTEGER parent; - SQLINTEGER parentClass; - unsigned char class[MDB_ODBC_NAME_SIZE + 1]; - SQLINTEGER classLength; - } createObject; - - struct { - unsigned char name[MDB_ODBC_NAME_SIZE + 1]; - SQLINTEGER nameLength; - SQLINTEGER type; - SQLINTEGER single; - SQLINTEGER public; - } createAttribute; - - struct { - unsigned char name[MDB_ODBC_NAME_SIZE + 1]; - SQLINTEGER nameLength; - SQLINTEGER container; - } createClass; - - struct { - unsigned char name[MDB_ODBC_NAME_SIZE + 1]; - SQLINTEGER nameLength; - SQLINTEGER class; - } getClassByName; - - struct { - unsigned char name[MDB_ODBC_NAME_SIZE + 1]; - SQLINTEGER nameLength; - SQLINTEGER class; - } createSuperClass; - - struct { - unsigned char name[MDB_ODBC_NAME_SIZE + 1]; - SQLINTEGER nameLength; - SQLINTEGER class; - } copySuperClass; - - struct { - unsigned char name[MDB_ODBC_NAME_SIZE + 1]; - SQLINTEGER nameLength; - SQLINTEGER class; - } createContainment; - - struct { - unsigned char name[MDB_ODBC_NAME_SIZE + 1]; - SQLINTEGER nameLength; - SQLINTEGER class; - } createMandatory; - - struct { - unsigned char class[MDB_ODBC_NAME_SIZE + 1]; - SQLINTEGER classLength; - } getMandatoryByName; - - struct { - unsigned char name[MDB_ODBC_NAME_SIZE + 1]; - SQLINTEGER nameLength; - SQLINTEGER class; - } createOptional; - - struct { - unsigned char name[MDB_ODBC_NAME_SIZE + 1]; - SQLINTEGER nameLength; - SQLINTEGER class; - } createNaming; - - struct { - SQLINTEGER object; - } deleteObjectValues; - - struct { - SQLINTEGER object; - } deleteObjectRights; - - struct { - SQLINTEGER object; - } deleteObject; - - struct { - SQLINTEGER class; - } copyContainment; - - struct { - SQLINTEGER class; - } copyMandatory; - - struct { - SQLINTEGER class; - } copyOptional; - - struct { - SQLINTEGER class; - } copyNaming; - - struct { - SQLINTEGER object; - SQLINTEGER attribute; - } clearAttribute; - - struct { - SQLINTEGER owner; - SQLINTEGER attribute; - SQLINTEGER value; - } addDNValue; - - struct { - SQLINTEGER owner; - SQLINTEGER attribute; - unsigned char value[MDB_ODBC_PART_SIZE + 1]; - SQLINTEGER valueLength; - SQLINTEGER complete; - } addStringValue; - - struct { - SQLINTEGER owner; - SQLINTEGER attribute; - SQLINTEGER value; - } addBoolValue; - - struct { - SQLINTEGER object; - SQLINTEGER parent; - } moveObject; - - struct { - SQLINTEGER object; - unsigned char name[MDB_ODBC_PART_SIZE + 1]; - SQLINTEGER nameLength; - } renameObject; - - struct { - SQLINTEGER object; - unsigned char pass[32 + 1]; - SQLINTEGER passLength; - } verifyPassword; - - struct { - SQLINTEGER object; - unsigned char pass[32 + 1]; - SQLINTEGER passLength; - } setPassword; - - struct { - SQLINTEGER attribute; - } deleteAttrFromMandatory; - - struct { - SQLINTEGER attribute; - } deleteAttrFromOptional; - - struct { - SQLINTEGER attribute; - } deleteAttrFromNaming; - - struct { - SQLINTEGER attribute; - } deleteAttrFromValues; - - struct { - SQLINTEGER attribute; - } deleteAttrFromRights; - - struct { - SQLINTEGER class; - } deleteClassFromContainment; - - struct { - SQLINTEGER class; - } deleteClassFromMandatory; - - struct { - SQLINTEGER class; - } deleteClassFromOptional; - - struct { - SQLINTEGER class; - } deleteClassFromNaming; - - struct { - SQLINTEGER class; - } deleteClass; - - struct { - SQLINTEGER object; - SQLINTEGER dn; - SQLINTEGER bool; - SQLINTEGER complete; - SQLINTEGER type; - unsigned char attribute[MDB_ODBC_NAME_SIZE + 1]; - unsigned long attributeLength; - unsigned char value[MDB_ODBC_PART_SIZE + 1]; - } readValue; - - /* getChildren is also used by getChildrenByClass */ - struct { - SQLINTEGER object; - SQLINTEGER container; - unsigned char class[MDB_ODBC_NAME_SIZE + 1]; - unsigned long classLength; - unsigned char child[MDB_ODBC_NAME_SIZE + 1]; - SQLINTEGER allContainers; - } getChildren; - - struct { - SQLINTEGER object; - SQLINTEGER child; - } getChildrenIDs; - } params; -} MDBValueStruct; - -typedef struct { - char *sql; - SQLHSTMT stmt; - - /* This buffer should be large enough for any enum response */ - unsigned char result[MDB_ODBC_PART_SIZE + 1]; - - /* Used for returning DN results where only the name changes from response to response */ - unsigned char dn[MDB_ODBC_PART_SIZE + 1]; - unsigned char class[MDB_ODBC_PART_SIZE + 1]; - SQLINTEGER classlen; - unsigned char *name; - - SQLINTEGER object; - - /* These are all included as possible responses */ - SQLINTEGER id; - SQLINTEGER bool; - SQLINTEGER complete; - SQLINTEGER type; - SQLINTEGER container; - SQLINTEGER allContainers; - - /* This should be used if MDBReadEx() reads a value alrger than MDB_ODBC_PART_SIZE */ - unsigned char *largeResult; -} MDBEnumStruct; - -/* - Do as much static setup as can be done here. Some things, such as setting the - admin password, or creating the tree entry will have to be done seperately since - they are dynamic. - - We attempt to create some of the tables twice. This is because mysql does not support - SERIAL. If we fail to create a table using SERIAL then we will try again with - INTEGER AUTO_INCREMENT UNIQUE, which as far as this driver is concerned is the same thing. - - The last line creates the root object. It can not be created with the regular - creation statement for objects because it has no parent object. -*/ -unsigned char *MDBodbcSQLPrepare[] = { - "CREATE TABLE treeinfo" \ - "(" \ - "name varchar(64)," \ - "defaultContainer INTEGER" \ - ");", - "CREATE TABLE objects" \ - "(" \ - "id SERIAL," \ - "name varchar(64)," \ - "class INTEGER," \ - "parent INTEGER," \ - "pass char(32)" \ - ");", - "CREATE TABLE objects" \ - "(" \ - "id INTEGER AUTO_INCREMENT UNIQUE," \ - "name varchar(64)," \ - "class INTEGER," \ - "parent INTEGER," \ - "pass char(32)" \ - ");", - "CREATE TABLE classes" \ - "(" \ - "id SERIAL," \ - "name varchar(64) UNIQUE," \ - "container INTEGER" \ - ");", - "CREATE TABLE classes" \ - "(" \ - "id INTEGER AUTO_INCREMENT UNIQUE," \ - "name varchar(64) UNIQUE," \ - "container INTEGER" \ - ");", - "CREATE TABLE superclasses" \ - "(" \ - "subclass INTEGER," \ - "superclass INTEGER" \ - ");", - "CREATE TABLE containment" \ - "(" \ - "container INTEGER," \ - "leaf INTEGER" \ - ");", - "CREATE TABLE attributes" \ - "(" \ - "id SERIAL," \ - "name varchar(64)," \ - "type INTEGER," \ - "single INTEGER," \ - "public INTEGER" \ - ");", - "CREATE TABLE attributes" \ - "(" \ - "id INTEGER AUTO_INCREMENT UNIQUE," \ - "name varchar(64)," \ - "type INTEGER," \ - "single INTEGER," \ - "public INTEGER" \ - ");", - "CREATE TABLE mandatory" \ - "(" \ - "attribute INTEGER," \ - "class INTEGER" \ - ");", - "CREATE TABLE optional" \ - "(" \ - "attribute INTEGER," \ - "class INTEGER" \ - ");", - "CREATE TABLE naming" \ - "(" \ - "attribute INTEGER," \ - "class INTEGER" \ - ");", - "CREATE TABLE data" \ - "(" \ - "id SERIAL," \ - "object INTEGER," \ - "attribute INTEGER," \ - "value VARCHAR(255)" \ - " DEFAULT ' '," \ - "dnvalue INTEGER DEFAULT -1," \ - "boolvalue INTEGER DEFAULT -1," \ - "complete INTEGER DEFAULT -1" \ - ");", - "CREATE TABLE data" \ - "(" \ - "id INTEGER AUTO_INCREMENT UNIQUE," \ - "object INTEGER," \ - "attribute INTEGER," \ - "value VARCHAR(255)" \ - " DEFAULT ' '," \ - "dnvalue INTEGER DEFAULT -1," \ - "boolvalue INTEGER DEFAULT -1," \ - "complete INTEGER DEFAULT -1" \ - ");", - "CREATE TABLE rights" \ - "(" \ - "object INTEGER DEFAULT -1," \ - "trustee INTEGER DEFAULT -1," \ - "provider INTEGER DEFAULT -1," \ - "r INTEGER DEFAULT -1," \ - "w INTEGER DEFAULT -1," \ - "d INTEGER DEFAULT -1," \ - "n INTEGER DEFAULT -1," \ - "parent INTEGER DEFAULT 0" \ - ");", - - "CREATE INDEX objects_index ON objects (id, parent, class, name);", - "CREATE INDEX classes_index ON classes (id, name);", - "CREATE INDEX superclasses_index ON superclasses (subclass);", - "CREATE INDEX containment_index ON containment (container, leaf);", - "CREATE INDEX attributes_index ON attributes (id, name);", - "CREATE INDEX mandatory_index ON mandatory (class);", - "CREATE INDEX optional_index ON optional (class);", - "CREATE INDEX naming_index ON naming (class);", - "CREATE INDEX values_index ON data (object, attribute);", - "CREATE INDEX rights_index ON rights (object, trustee);", - NULL -}; - -unsigned char *MDBodbcSQLCreateRoot[] = { - "DELETE FROM objects;", - "INSERT INTO objects (id, name, parent, class)" \ - " SELECT -1, ?, -1, id FROM classes WHERE UCASE(name)=UCASE('Top');", - NULL -}; - -/* - Set the rights to be such that anything is allowed by anyone while the setup - is being run. This will be changed after setup is complete. -*/ -unsigned char *MDBodbcSQLSetPrepareRights[] = { - "INSERT INTO objects (id, name, parent, class)" \ - " VALUES (-1, ?, -1, -1);", - "INSERT INTO rights (object, trustee, r, w, d, n)" \ - " VALUES(-1, -1, 1, 1, 1, 1);", - NULL -}; - -/* - Removes the temporary rights used during setup, and set the default rights - which are none. Also provide full rights to the root to the administrators - group, and to admin. -*/ -unsigned char *MDBodbcSQLSetInitialRights[] = { - "DELETE FROM rights;", - "INSERT INTO rights (object) VALUES (-1);", - "INSERT INTO rights (object, provider, trustee, r, w, d, n)" \ - " SELECT -1, objects.id, objects.id, 1, 1, 1, 1" \ - " FROM objects WHERE UCASE(objects.name)=UCASE('Administrators') OR" \ - " UCASE(objects.name)=UCASE('Admin');", - NULL -}; - -#define REMOVE_TABLES "DROP TABLE treeinfo; DROP TABLE objects;" \ - "DROP TABLE classes;DROP TABLE superclasses; DROP TABLE containment;" \ - "DROP TABLE attributes;DROP TABLE mandatory; DROP TABLE optional;" \ - "DROP TABLE data;DROP TABLE rights; DROP TABLE naming;" - -#define SQL_GET_TREE_INFO "SELECT name, defaultContainer FROM treeinfo LIMIT 1;" -#define SQL_SET_TREE_INFO "INSERT INTO treeinfo (name, defaultContainer) VALUES (?, ?);" -#define SQL_GET_ROOT_RIGHTS "SELECT r, w, d, n FROM rights WHERE trustee=? AND object=-1;" -#define SQL_DEL_RIGHTS_BY_PROVIDER_AND_OBJ "DELETE FROM rights WHERE provider=? AND object=?;" -#define SQL_DEL_RIGHTS_BY_OBJECT "DELETE FROM rights WHERE object=? AND trustee=?;" -#define SQL_GET_RIGHTS_PROVIDERS "SELECT provider FROM rights WHERE trustee=? AND parent=1;" -#define SQL_DEL_RIGHTS_BY_CHILD "DELETE FROM rights WHERE provider=? AND trustee=? AND parent=1;" -#define SQL_DEL_RIGHTS_BY_PROVIDER "DELETE FROM rights WHERE provider=? AND provider!=trustee;" - -#define SQL_SET_RIGHTS "INSERT INTO rights (object, trustee, provider, parent, r, w, d, n) VALUES (?, ?, ?, ?, ?, ?, ?, ?);" -#define SQL_GET_RIGHTS "SELECT provider, object, r, w, d, n FROM rights WHERE trustee=?;" - -#define SQL_GET_OBJECT_ID "SELECT objects.id, objects.class, rights.r, rights.w, rights.d, rights.n FROM objects, rights" \ - " WHERE UCASE(objects.name)=UCASE(?) AND objects.parent=? AND" \ - " ((rights.object=objects.id AND rights.trustee=?) OR (rights.object=-1 AND rights.trustee=-1))"\ - " ORDER BY rights.trustee DESC LIMIT 1;" -#define SQL_GET_ATTRIBUTE_BY_NAME "SELECT id FROM attributes WHERE UCASE(name)=UCASE(?);" -#define SQL_GET_CLASS_BY_NAME "SELECT id FROM classes WHERE UCASE(name)=UCASE(?);" - -#define SQL_GET_CHILDREN "SELECT objects.name, classes.container FROM objects, classes WHERE objects.parent=? AND objects.id>0 AND objects.class=classes.id;" -#define SQL_GET_CHILDREN_BY_CLASS "SELECT objects.name, classes.container FROM objects, classes WHERE objects.parent=? AND objects.id>0 AND objects.class=classes.id" \ - " AND (UCASE(classes.name)=UCASE(?) OR classes.container=?);" -#define SQL_HAS_CHILDREN "SELECT id FROM objects WHERE parent=? LIMIT 1;" -#define SQL_GET_CHILDREN_IDS "SELECT id FROM objects WHERE parent=? AND id > 0;" - - -/* - This really nasty bit of SQL will create an object with the specified name, and - specified class in the specified parent container, if that class is allowed in - that container class. -*/ -#define SQL_CREATE_OBJECT \ - "INSERT INTO objects (name, parent, class)" \ - " SELECT ?, ?, classes.id FROM classes, containment" \ - " WHERE UCASE(classes.name)=UCASE(?)" \ - " AND classes.id=containment.leaf" \ - " AND containment.container=?" \ - " LIMIT 1;" - -#define SQL_RENAME_OBJECT "UPDATE objects SET name=? WHERE id=?;" -#define SQL_MOVE_OBJECT "UPDATE objects SET parent=? WHERE id=?;" -#define SQL_VERIFY_CONTAINMENT "SELECT containment.leaf FROM containment, objects WHERE objects.id=? AND objects.class=containment.container AND containment.leaf=?;" -#define SQL_LIST_CONTAINMENT "SELECT classes.name FROM classes, containment, objects WHERE containment.leaf=classes.id AND containment.container=objects.class AND objects.id=?;" - -#define SQL_CREATE_ATTRIBUTE "INSERT INTO attributes (name, type, single, public) VALUES (?, ?, ?, ?);" -#define SQL_CREATE_CLASS "INSERT INTO classes (name, container) VALUES (?, ?);" -#define SQL_CREATE_SUPERCLASS "INSERT INTO superclasses (subclass, superclass) SELECT ?, id FROM classes where UCASE(name)=UCASE(?);" -#define SQL_CREATE_CONTAINMENT "INSERT INTO containment (leaf, container) SELECT ?, id FROM classes where UCASE(name)=UCASE(?);" -#define SQL_CREATE_MANDATORY "INSERT INTO mandatory (class, attribute) SELECT ?, id FROM attributes where UCASE(name)=UCASE(?);" -#define SQL_CREATE_OPTIONAL "INSERT INTO optional (class, attribute) SELECT ?, id FROM attributes where UCASE(name)=UCASE(?);" -#define SQL_CREATE_NAMING "INSERT INTO naming (class, attribute) SELECT ?, id FROM attributes where UCASE(name)=UCASE(?);" - -#define SQL_GET_OBJECT_CLASS "SELECT class FROM objects WHERE id=?;" -#define SQL_GET_OBJECT_CLASSNAME "SELECT classes.name FROM classes, objects WHERE objects.id=? AND objects.class=classes.id;" - - -#define SQL_GET_NAMING "SELECT attributes.name FROM attributes, naming WHERE attributes.id=naming.attribute and naming.class=?;" -#define SQL_GET_MANDATORY "SELECT attributes.name FROM attributes, mandatory WHERE attributes.id=mandatory.attribute and mandatory.class=?;" -#define SQL_GET_MANDATORY_BY_NAME "SELECT attributes.name FROM attributes, classes, mandatory WHERE" \ - " mandatory.attribute=attributes.id AND mandatory.class=classes.id" \ - " and UCASE(classes.name)=UCASE(?);" -#define SQL_GET_PARENT_INFO "SELECT parent, name FROM objects WHERE id=?;" - -/* If the specified attribute can be written to the specified object then a single row will be returned, with the attribute ID and a BOOL specifiying single or multi value */ -#define SQL_GET_OBJECT_ATTR_INFO "SELECT attributes.id, attributes.single, attributes.type FROM attributes, objects, optional WHERE objects.id=? AND objects.class=optional.class AND UCASE(attributes.name)=UCASE(?) AND attributes.id=optional.attribute LIMIT 1;" - -#define SQL_ADD_DN_VALUE "INSERT INTO data (object, attribute, dnvalue) VALUES (?, ?, ?);" -#define SQL_REMOVE_DN_VALUE "DELETE FROM data WHERE object=? AND attribute=? AND dnvalue=?;" -#define SQL_ADD_BOOL_VALUE "INSERT INTO data (object, attribute, boolvalue) VALUES (?, ?, ?);" -#define SQL_REMOVE_BOOL_VALUE "DELETE FROM data WHERE object=? AND attribute=? AND boolvalue=?;" -#define SQL_ADD_STRING_VALUE "INSERT INTO data (object, attribute, value, complete) VALUES (?, ?, ?, ?);" -#define SQL_REMOVE_STRING_VALUE "DELETE FROM data WHERE object=? AND attribute=? AND value=?;" - -#define SQL_READ_VALUE "SELECT data.value, data.dnvalue, data.boolvalue, data.complete, attributes.type FROM data, attributes WHERE data.object=? AND data.attribute=attributes.id AND UCASE(attributes.name)=UCASE(?) ORDER BY data.id;" - -/* Copy data from all superclasses to a new class */ -#define SQL_COPY_SUPERCLASSES "INSERT INTO superclasses (subclass, superclass) SELECT ?, superclasses.superclass FROM superclasses, classes WHERE superclasses.subclass=classes.id AND UCASE(classes.name)=UCASE(?);" -#define SQL_COPY_CONTAINMENT "INSERT INTO containment (container, leaf) SELECT containment.container, superclasses.subclass FROM containment, superclasses WHERE containment.leaf=superclasses.superclass and superclasses.subclass=?;" -#define SQL_COPY_MANDATORY "INSERT INTO mandatory (attribute, class) SELECT mandatory.attribute, superclasses.subclass FROM mandatory, superclasses WHERE mandatory.class=superclasses.superclass and superclasses.subclass=?;" -#define SQL_COPY_OPTIONAL "INSERT INTO optional (attribute, class) SELECT optional.attribute, superclasses.subclass FROM optional, superclasses WHERE optional.class=superclasses.superclass and superclasses.subclass=?;" -#define SQL_COPY_NAMING "INSERT INTO naming (attribute, class) SELECT naming.attribute, superclasses.subclass FROM naming, superclasses WHERE naming.class=superclasses.superclass and superclasses.subclass=?;" - -#define SQL_CLEAR_ATTRIBUTE "DELETE FROM data WHERE object=? AND attribute=?;" - -/* Delete an object */ -#define SQL_DELETE_OBJECT_VALUES "DELETE FROM data WHERE object=?;" -#define SQL_DELETE_OBJECT_RIGHTS "DELETE FROM rights WHERE provider=?;" -#define SQL_DELETE_OBJECT "DELETE FROM objects WHERE id=?;" - -/* Delete an attribute */ -#define SQL_DELETE_ATTRIBUTE "DELETE FROM attributes WHERE id=?;" -#define SQL_MANDATORY_DELETE_ATTR "DELETE FROM mandatory WHERE attribute=?;" -#define SQL_OPTIONAL_DELETE_ATTR "DELETE FROM optional WHERE attribute=?;" -#define SQL_NAMING_DELETE_ATTR "DELETE FROM naming WHERE attribute=?;" -#define SQL_VALUES_DELETE_ATTR "DELETE FROM data WHERE attribute=?;" - -/* Delete a class */ -#define SQL_GET_SUBCLASSES "SELECT subclass FROM superclasses WHERE superclass=?;" -#define SQL_GET_OBJECTS_BY_CLASS "SELECT id FROM objects WHERE class=?;" -#define SQL_CONTAINMENT_DEL_CLASS "DELETE FROM containment WHERE container=? OR leaf=?;" -#define SQL_MANDATORY_DEL_CLASS "DELETE FROM mandatory WHERE class=?;" -#define SQL_OPTIONAL_DEL_CLASS "DELETE FROM optional WHERE class=?;" -#define SQL_NAMING_DEL_CLASS "DELETE FROM naming WHERE class=?;" -#define SQL_DELETE_CLASS "DELETE FROM classes WHERE id=?;" - - -#define SQL_VERIFY_PASSWORD "SELECT id FROM objects WHERE id=? AND pass=?;" -#define SQL_SET_PASSWORD "UPDATE objects SET pass=? WHERE id=?;" - -/* - We need mdb.h for the types used below, but we have to make sure it is included after - we have defined our own ValueStruct, EnumStruct and Handle types. -*/ -#include - -typedef struct _MDBodbcBaseSchemaAttributes { - unsigned char *name; - unsigned long flags; - unsigned long type; -} MDBodbcBaseSchemaAttributes; - -MDBodbcBaseSchemaAttributes MDBodbcBaseSchemaAttributesList[] = { - { "Aliased Object Name", 69, MDB_ATTR_SYN_DIST_NAME }, - { "Back Link", 268, MDB_ATTR_SYN_DIST_NAME }, - { "CA Private Key", 93, MDB_ATTR_SYN_BINARY }, - { "CA Public Key", 205, MDB_ATTR_SYN_BINARY }, - { "CN", 102, MDB_ATTR_SYN_STRING }, - { "C", 103, MDB_ATTR_SYN_STRING }, - { "Description", 102, MDB_ATTR_SYN_STRING }, - { "Facsimile Telephone Number", 68, MDB_ATTR_SYN_STRING }, - { "Group Membership", 580, MDB_ATTR_SYN_DIST_NAME }, - { "L", 102, MDB_ATTR_SYN_STRING }, - { "Login Disabled", 69, MDB_ATTR_SYN_BOOL }, - { "Member", 68, MDB_ATTR_SYN_DIST_NAME }, - { "EMail Address", 228, MDB_ATTR_SYN_STRING }, - { "Internet EMail Address", 228, MDB_ATTR_SYN_STRING }, - { "departmentNumber", 228, MDB_ATTR_SYN_STRING }, - { "Notify", 68, MDB_ATTR_SYN_DIST_NAME }, - { "Operator", 324, MDB_ATTR_SYN_DIST_NAME }, - { "OU", 102, MDB_ATTR_SYN_STRING }, - { "O", 102, MDB_ATTR_SYN_STRING }, - { "Owner", 68, MDB_ATTR_SYN_DIST_NAME }, - { "Page Description Language", 102, MDB_ATTR_SYN_STRING }, - { "Path", 68, MDB_ATTR_SYN_STRING }, - { "Physical Delivery Office Name", 102, MDB_ATTR_SYN_STRING }, - { "Postal Address", 68, MDB_ATTR_SYN_STRING }, - { "Postal Code", 102, MDB_ATTR_SYN_STRING }, - { "Postal Office Box", 102, MDB_ATTR_SYN_STRING }, - { "Private Key", 93, MDB_ATTR_SYN_BINARY }, - { "Profile", 69, MDB_ATTR_SYN_DIST_NAME }, - { "Public Key", 205, MDB_ATTR_SYN_BINARY }, - { "Reference", 1052, MDB_ATTR_SYN_DIST_NAME }, - { "Resource", 68, MDB_ATTR_SYN_DIST_NAME }, - { "Role Occupant", 68, MDB_ATTR_SYN_DIST_NAME }, - { "Higher Privileges", 836, MDB_ATTR_SYN_DIST_NAME }, - { "Security Equals", 836, MDB_ATTR_SYN_DIST_NAME }, - { "See Also", 68, MDB_ATTR_SYN_DIST_NAME }, - { "Serial Number", 102, MDB_ATTR_SYN_STRING }, - { "Server", 324, MDB_ATTR_SYN_DIST_NAME }, - { "S", 102, MDB_ATTR_SYN_STRING }, - { "Status", 197, MDB_ATTR_SYN_STRING }, - { "SA", 102, MDB_ATTR_SYN_STRING }, - { "Surname", 230, MDB_ATTR_SYN_STRING }, - { "Telephone Number", 100, MDB_ATTR_SYN_STRING }, - { "Title", 102, MDB_ATTR_SYN_STRING }, - { "Unknown", 4, MDB_ATTR_SYN_STRING }, - { "User", 324, MDB_ATTR_SYN_DIST_NAME }, - { "Version", 231, MDB_ATTR_SYN_STRING }, - { "Device", 68, MDB_ATTR_SYN_DIST_NAME }, - { "Language", 69, MDB_ATTR_SYN_STRING }, - { "UID", 69, MDB_ATTR_SYN_STRING }, - { "GID", 69, MDB_ATTR_SYN_STRING }, - { "Unknown Base Class", 39, MDB_ATTR_SYN_STRING }, - { "Authority Revocation", 77, MDB_ATTR_SYN_BINARY }, - { "Certificate Revocation", 77, MDB_ATTR_SYN_BINARY }, - { "Cross Certificate Pair", 68, MDB_ATTR_SYN_BINARY }, - { "Full Name", 102, MDB_ATTR_SYN_STRING }, - { "Certificate Validity Interval", 71, MDB_ATTR_SYN_STRING }, - { "External Synchronizer", 68, MDB_ATTR_SYN_BINARY }, - { "Message Routing Group", 68, MDB_ATTR_SYN_DIST_NAME }, - { "Postmaster", 68, MDB_ATTR_SYN_DIST_NAME }, - { "Mailbox Location", 197, MDB_ATTR_SYN_DIST_NAME }, - { "Mailbox ID", 231, MDB_ATTR_SYN_STRING }, - { "External Name", 69, MDB_ATTR_SYN_BINARY }, - { "Security Flags", 69, MDB_ATTR_SYN_STRING }, - { "Last Referenced Time", 1029, MDB_ATTR_SYN_STRING }, - { "Given Name", 230, MDB_ATTR_SYN_STRING }, - { "Initials", 230, MDB_ATTR_SYN_STRING }, - { "Generational Qualifier", 231, MDB_ATTR_SYN_STRING }, - { "Profile Membership", 580, MDB_ATTR_SYN_DIST_NAME }, - { "Equivalent To Me", 324, MDB_ATTR_SYN_DIST_NAME }, - { "Timezone", 133, MDB_ATTR_SYN_BINARY }, - { "T", 102, MDB_ATTR_SYN_STRING }, - { "Used By", 332, MDB_ATTR_SYN_STRING }, - { "Uses", 332, MDB_ATTR_SYN_STRING }, - { "GUID", 207, MDB_ATTR_SYN_BINARY }, - { "Other GUID", 198, MDB_ATTR_SYN_BINARY }, - { NULL, 0, 0 } -}; - -typedef struct _MDBodbcBaseSchemaClasses { - unsigned char *name; - unsigned long flags; - unsigned char *superClass; - unsigned char *containedBy; - unsigned char *namedBy; - unsigned char *mandatory; - unsigned char *optional; -} MDBodbcBaseSchemaClasses; - -MDBodbcBaseSchemaClasses MDBodbcBaseSchemaClassesList[] = { - { "[Nothing]", 3, NULL, NULL, NULL, NULL, NULL }, - { "Top", 3, NULL, NULL, "T", NULL, "CA Public Key,Private Key,Certificate Validity Interval,Authority Revocation,Last Referenced Time,Equivalent To Me,Back Link,Reference,Cross Certificate Pair,Certificate Revocation,Used By,GUID,Other GUID" }, - { "Alias", 2, "Top", NULL, NULL, "Aliased Object Name", NULL }, - { "Country", 3, "Top", "Top,Tree Root,[Nothing]", "C", "C", "Description" }, - { "Organization", 3, NULL, "Top,Tree Root,Country,Locality,[Nothing]", "O", "O","Description,Facsimile Telephone Number,L,EMail Address,Physical Delivery Office Name,Postal Address,Postal Code,Postal Office Box,See Also,S,SA,Telephone Number" }, - { "Organizational Unit", 3, NULL, "Locality,Organization,Organizational Unit", "OU", "OU","Description,Facsimile Telephone Number,L,EMail Address,Physical Delivery Office Name,Postal Address,Postal Code,Postal Office Box,See Also,S,SA,Telephone Number" }, - { "Locality", 3, "Top", "Locality,Country,Organizational Unit,Organization", "L,S", NULL,"Description,L,See Also,S,SA" }, - { "Organizational Role", 2, "Top", "Organization,Organizational Unit", "CN", "CN", "Description,Facsimile Telephone Number,L,EMail Address,OU,Physical Delivery Office Name,Postal Address,Postal Code,Postal Office Box,Role Occupant,See Also,S,SA,Telephone Number,Mailbox Location,Mailbox ID" }, - { "Group", 2, "Top", "Organization,Organizational Unit", "CN", "CN", "Description,L,Member,OU,O,Owner,See Also,GID,Full Name,EMail Address,Mailbox Location,Mailbox ID,Profile,Profile Membership" }, - { "Person", 2, NULL, "Organization,Organizational Unit", "CN", "CN", "Description,See Also,Telephone Number,Full Name,Given Name,Initials,Generational Qualifier" }, - { "Organizational Person", 2, "Person", NULL, "OU", NULL, "Facsimile Telephone Number,L,EMail Address,OU,Physical Delivery Office Name,Postal Address,Postal Code,Postal Office Box,S,SA,Title,Mailbox Location,Mailbox ID" }, - { "User", 2, "Organizational Person", NULL, NULL, NULL, "Group Membership,Login Disabled,Private Key,Profile,Public Key,Security Equals,Minimum Message Server,Language,UID,Type Creator Map,Higher Privileges,Security Flags,Profile Membership,Timezone,Surname,Internet EMail Address,departmentNumber" }, - { "Device", 2, "Top", "Organization,Organizational Unit", "CN", "CN", "Description,L,OU,O,Owner,See Also,Serial Number" }, - { "Computer", 2, "Device", NULL, NULL, NULL, "Operator,Server,Status" }, - { "Resource", 0, "Top", "Organization,Organizational Unit", "CN", "CN", "Description,L,OU,O,See Also,Uses" }, - { "Profile", 2, "Top", "Organization,Organizational Unit", "CN", "CN", "Description,L,OU,O,See Also,Full Name" }, - { "Server", 0, "Top", "Organization,Organizational Unit", "CN", "CN", "Description,L,OU,O,Private Key,Public Key,Resource,See Also,Status,User,Version,Full Name,Security Equals,Security Flags,Timezone" }, - { "NCP Server", 2, "Server", NULL, NULL, NULL, "Operator" }, - { NULL, 0, NULL, NULL, NULL, NULL, NULL } -}; - -#define ERR_NO_SUCH_ENTRY 0xFFFFFDA7 -#define ERR_NO_SUCH_VALUE 0xFFFFFDA6 -#define ERR_NO_SUCH_ATTRIBUTE 0xFFFFFDA5 -#define ERR_NO_SUCH_CLASS 0xFFFFFDA4 -#define ERR_NO_SUCH_PARTITION 0xFFFFFDA3 -#define ERR_ENTRY_ALREADY_EXISTS 0xFFFFFDA2 -#define ERR_NOT_EFFECTIVE_CLASS 0xFFFFFDA1 -#define ERR_ILLEGAL_ATTRIBUTE 0xFFFFFDA0 -#define ERR_MISSING_MANDATORY 0xFFFFFD9F -#define ERR_ILLEGAL_DS_NAME 0xFFFFFD9E -#define ERR_ILLEGAL_CONTAINMENT 0xFFFFFD9D -#define ERR_CANT_HAVE_MULTIPLE_VALUES 0xFFFFFD9C -#define ERR_SYNTAX_VIOLATION 0xFFFFFD9B -#define ERR_DUPLICATE_VALUE 0xFFFFFD9A -#define ERR_ATTRIBUTE_ALREADY_EXISTS 0xFFFFFD99 -#define ERR_MAXIMUM_ENTRIES_EXIST 0xFFFFFD98 -#define ERR_DATABASE_FORMAT 0xFFFFFD97 -#define ERR_INCONSISTENT_DATABASE 0xFFFFFD96 -#define ERR_INVALID_COMPARISON 0xFFFFFD95 -#define ERR_COMPARISON_FAILED 0xFFFFFD94 -#define ERR_TRANSACTIONS_DISABLED 0xFFFFFD93 -#define ERR_INVALID_TRANSPORT 0xFFFFFD92 -#define ERR_SYNTAX_INVALID_IN_NAME 0xFFFFFD91 -#define ERR_TRANSPORT_FAILURE 0xFFFFFD8F -#define ERR_ALL_REFERRALS_FAILED 0xFFFFFD8E -#define ERR_CANT_REMOVE_NAMING_VALUE 0xFFFFFD8D -#define ERR_OBJECT_CLASS_VIOLATION 0xFFFFFD8C -#define ERR_ENTRY_IS_NOT_LEAF 0xFFFFFD8B -#define ERR_DIFFERENT_TREE 0xFFFFFD8A -#define ERR_SYSTEM_FAILURE 0xFFFFFD88 -#define ERR_INVALID_ENTRY_FOR_ROOT 0xFFFFFD87 -#define ERR_NO_REFERRALS 0xFFFFFD86 -#define ERR_REMOTE_FAILURE 0xFFFFFD85 -#define ERR_UNREACHABLE_SERVER 0XFFFFFD84 -#define ERR_NO_CHARACTER_MAPPING 0XFFFFFD82 -#define ERR_INCOMPLETE_AUTHENTICATION 0XFFFFFD81 -#define ERR_INVALID_CERTIFICATE 0xFFFFFD80 -#define ERR_INVALID_REQUEST 0xFFFFFD7F -#define ERR_INVALID_ITERATION 0xFFFFFD7E -#define ERR_SCHEMA_IS_NONREMOVABLE 0xFFFFFD7D -#define ERR_SCHEMA_IS_IN_USE 0xFFFFFD7C -#define ERR_CLASS_ALREADY_EXISTS 0xFFFFFD7B -#define ERR_BAD_NAMING_ATTRIBUTES 0xFFFFFD7A -#define ERR_INSUFFICIENT_STACK 0xFFFFFD78 -#define ERR_INSUFFICIENT_BUFFER 0xFFFFFD77 -#define ERR_AMBIGUOUS_CONTAINMENT 0xFFFFFD76 -#define ERR_AMBIGUOUS_NAMING 0xFFFFFD75 -#define ERR_DUPLICATE_MANDATORY 0xFFFFFD74 -#define ERR_DUPLICATE_OPTIONAL 0xFFFFFD73 -#define ERR_RECORD_IN_USE 0xFFFFFD6C -#define ERR_ENTRY_NOT_CONTAINER 0xFFFFFD64 -#define ERR_FAILED_AUTHENTICATION 0xFFFFFD63 -#define ERR_INVALID_CONTEXT 0xFFFFFD62 -#define ERR_NO_SUCH_PARENT 0xFFFFFD61 -#define ERR_NO_ACCESS 0xFFFFFD60 -#define ERR_INVALID_NAME_SERVICE 0xFFFFFD5E -#define ERR_INVALID_TASK 0xFFFFFD5D -#define ERR_INVALID_CONN_HANDLE 0xFFFFFD5C -#define ERR_INVALID_IDENTITY 0xFFFFFD5B -#define ERR_DUPLICATE_ACL 0xFFFFFD5A -#define ERR_ALIAS_OF_AN_ALIAS 0xFFFFFD57 -#define ERR_INVALID_RDN 0xFFFFFD4E -#define ERR_INCORRECT_BASE_CLASS 0xFFFFFD4C -#define ERR_MISSING_REFERENCE 0xFFFFFD4B -#define ERR_LOST_ENTRY 0xFFFFFD4A -#define ERR_FATAL 0xFFFFFD45 - - - -#endif /* MDBODBCP_H */ diff --git a/src/libs/mdb-xldap/Bongo.rules b/src/libs/mdb-xldap/Bongo.rules deleted file mode 100644 index e430c8e..0000000 --- a/src/libs/mdb-xldap/Bongo.rules +++ /dev/null @@ -1,33 +0,0 @@ -# -*- Makefile -*- -if HAVE_LDAP -mdb_LTLIBRARIES += libmdbldap.la -endif - -libmdbldap_la_SOURCES = \ - src/libs/mdb-xldap/valarray.c \ - src/libs/mdb-xldap/schema.c \ - src/libs/mdb-xldap/mdbldap.c \ - src/libs/mdb-xldap/mdbldapp.h - -libmdbldap_la_CPPFLAGS = $(AM_CPPFLAGS) \ - -DLOCALSTATEDIR=\""$(localstatedir)"\" \ - -DMDB_INTERNAL - -libmdbldap_la_LDFLAGS = -module -avoid-version -libmdbldap_la_LIBADD = \ - $(LDAP_LIBS) \ - libbongoutil.la \ - libbongoxpl.la \ - libbongomemmgr.la \ - libbongostreamio.la \ - $(top_builddir)/import/log4c/log4c/libbongolog4c.la - -if HAVE_LDAP -src/libs/mdb-xldap/all: libmdbldap.la -src/libs/mdb-xldap/install: - @cd $(top_builddir) && $(MAKE) $(MFLAGS) mdb_LTLIBRARIES=libmdbldap.la install-mdbLTLIBRARIES -else -src/libs/mdb-xldap/all: -src/libs/mdb-xldap/install: -endif -src/libs/mdb-xldap/clean: clean diff --git a/src/libs/mdb-xldap/Makefile.am b/src/libs/mdb-xldap/Makefile.am deleted file mode 100644 index 8830401..0000000 --- a/src/libs/mdb-xldap/Makefile.am +++ /dev/null @@ -1,17 +0,0 @@ -# -*- Makefile -*- -# -# Do not edit! -# -# (unless this is Makefile.am.subdir) -# -# This file is a copy of the toplevel Makefile.am.subdir. If changes -# need to be made, edit that file, and make update-makefiles, and -# check the new files in. -# -# This is a skeletal automake file. The real automake fules for -# building the targets for this directory can be found in the -# Bongo.rules file. This file is simply here so that 'make all' can -# work in each subdirectory. - -all clean install: - @cd $(top_builddir) && $(MAKE) $(MFLAGS) $(subdir)/$@ diff --git a/src/libs/mdb-xldap/mdbldap.c b/src/libs/mdb-xldap/mdbldap.c deleted file mode 100644 index 3093c2d..0000000 --- a/src/libs/mdb-xldap/mdbldap.c +++ /dev/null @@ -1,4009 +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 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. - * - ****************************************************************************/ - -#define PRODUCT_NAME "MDB LDAP Driver" -#define PRODUCT_VERSION "$Revision: 1.1 $" -#define LOGGER "MDB LDAP Driver" - -#include -#include "mdbldapp.h" -#include -#include -#include - -#define INIT_VS_LDAP(v) \ -if (v->ldap == NULL) { \ - v->ldap = GetLdapConnection((MDBLDAPContextStruct *) v->context); \ -} - -#if 0 -/* Linked list used to store handles. - Similar methods are often used in MDB drivers to validate handles. - Not sure if this is really necessary. */ -typedef struct _HandleListNode { - MDBHandle *Handle; - _HandleListNode *Next; -} HandleListNode; -#endif - -struct { - char ServerTree[MDB_MAX_OBJECT_CHARS + 1]; - char ServerDn[MDB_MAX_OBJECT_CHARS + 1]; - char *MdbBaseDn; - char *LdapBaseDn; - char *LdapSchemaDn; - char *LdapBindDn; - char *LdapBindPasswd; - char *LdapHostAddress; - int LdapHostPort; - int LdapMinConnections; - int LdapMaxConnections; - int LdapTls; - LDAP *Ldap; - XplMutex LdapMutex; - BongoHashtable *PathTable; - XplRWLock PathLock; - BongoHashtable *AttrTable; - BongoHashtable *ClassTable; - BongoHashtable *TransTable; - BongoHashtable *ExtTable; - /*HandleListNode *HandleList; */ - char *args; -} MdbLdap; - -typedef struct { - char *str; - int len; - int size; -} StringBuilder; - - -static char *TranslateSchemaName(char *Name); - -static void -AppendString(StringBuilder *sb, const char *toAppend) -{ - int fit; - - fit = strlen(toAppend); - - if (sb->size - sb->len <= fit) { - int grow = 512; - if (grow <= fit) { - grow = fit + 1; - } - - sb->size += grow; - sb->str = realloc(sb->str, sb->size); - } - - strcpy(sb->str + sb->len, toAppend); - sb->len += fit; -} - -static char * -vsprintf_dup (const char *format, va_list ap) -{ - char buf[1024]; - int n; - - va_list ap2; - XPL_VA_COPY(ap2, ap); - - n = XplVsnprintf (buf, 1024, format, ap); - - if (n < 1024) { - va_end (ap2); - return strdup (buf); - } else { - char *ret; - ret = malloc (n + 1); - XplVsnprintf (ret, n + 1, format, ap2); - va_end (ap2); - return ret; - } -} - -static char * -sprintf_dup (const char *format, ...) -{ - va_list ap; - char *ret; - - va_start(ap, format); - ret = vsprintf_dup(format, ap); - va_end(ap); - - return ret; -} - -#if 0 -int -HandleListAdd(MDBHandle *Handle) -{ - HandleListNode *node = NULL; - HandleListNode *curr = NULL; - - node = malloc(sizeof(HandleListNode)); - - if (!node) { - return -1; - } - - node->Next = NULL; - node->Handle = Handle; - curr = MdbLdap.HandleList; - - if (curr) { - while (curr->Next) { - curr = curr->Next; - } - - curr->Next = node; - } else { - MdbLdap.HandleList = node; - } - - return 0; -} - -MDBHandle * -HandleListFind(LDAP *Ldap) -{ - HandleListNode *curr = NULL; - - curr = MdbLdap.HandleList; - - while (curr) { - if (curr->Handle->ldap == Ldap) { - return curr->Handle; - } - - curr = curr->Next; - } - - return NULL; -} - -int -HandleListRemove(MDBHandle *Handle) { - HandleListNode *curr = NULL; - HandleListNode *prev = NULL; - - curr = MdbLdap.HandleList; - - while (curr) { - if (curr->Handle == Handle) { - found = 1; - break; - } - - prev = curr; - curr = curr->Next; - } - - if (found) { - if (prev) { - prev->Next = curr->Next; - } else { - MdbLdap.HandleList = curr->Next; - } - - free(curr); - return 0; - } - - return -1; -} -#endif - -/* Function used for normal rebinding. */ -static int -UserRebindProc(LDAP * ld, LDAP_CONST char *url, ber_tag_t request, - ber_int_t msgid, void *params) -{ - /*MDBHandle handle = HandleListGet(ld); */ - MDBHandle handle = NULL; - char *binddn = NULL; - char *passwd = NULL; - - if (params) { - handle = (MDBHandle) params; - binddn = (char *) handle->binddn; - passwd = (char *) handle->passwd; - } - - return ldap_simple_bind_s(ld, binddn, passwd); -} - -static int -DriverRebindProc(LDAP * ld, LDAP_CONST char *url, ber_tag_t request, - ber_int_t msgid, void *params) -{ - return ldap_simple_bind_s(ld, MdbLdap.LdapBindDn, MdbLdap.LdapBindPasswd); -} - -/** - * Create a new DN. - * Remove the tree name and trailing slash. - * Make sure delimiters aren't repeated. - */ -static char * -GetNewDn(const char *DnIn) -{ - char *newDn = NULL; - char *tmpDn = NULL; - char *token; - char *ptr; - - tmpDn = strdup(DnIn); - - if (tmpDn) { - token = strtok_r(tmpDn, "\\", &ptr); - - if (token) { - if (MdbLdap.ServerTree[0] && !strcmp(token, MdbLdap.ServerTree)) { - token = strtok_r(NULL, "\\", &ptr); - } - - newDn = malloc(MDB_MAX_OBJECT_CHARS + 1); - - if (newDn) { - newDn[0] = '\0'; - - if (*DnIn == '\\') { - strcat(newDn, "\\"); - } - - while (token) { - strcat(newDn, token); - token = strtok_r(NULL, "\\", &ptr); - - if (token) { - strcat(newDn, "\\"); - } - } - } - } - - free(tmpDn); - } - - return newDn; -} - -static char * -GetAbsoluteDn(const char *Object, const char *Context) -{ - char tmpDn[MDB_MAX_OBJECT_CHARS + 1]; - - if (*Object == '\\') { - /* already absolute */ - return GetNewDn(Object); - } - - if (!Context) { - Context = MdbLdap.MdbBaseDn; - } - - if (Object[0] == '.' && Object[1] == '\0') { - return GetNewDn(Context); - } - - /* relative */ - sprintf(tmpDn, "%s\\%s", Context, Object); - return GetNewDn (tmpDn); -} - -/** - * Create a DN for Object that is relative to Context. - * Returns an absolute DN if the Object is higher than Context. - */ -static char * -GetRelativeDn(const char *Object, const char *Context) -{ - char *mdbDn = NULL; - char *tmpDn = NULL; - - if (*Object == '\\') { - /* absolute */ - tmpDn = (char *)Object; - - if (Context) { - if (strcmp(Object, Context) && !strncmp(Object, Context, - strlen(Context))) { - tmpDn += strlen(Context) + 1; - } - } else { - if (strcmp(Object, MdbLdap.MdbBaseDn) && - !strncmp(Object, MdbLdap.MdbBaseDn, - strlen(MdbLdap.MdbBaseDn))) { - tmpDn += strlen(MdbLdap.MdbBaseDn) + 1; - } - } - - mdbDn = GetNewDn(tmpDn); - } else { - /* already relative */ - mdbDn = GetNewDn(Object); - } - - return mdbDn; -} - -/** - * Get the LDAP distinguished name. Recursively search the local cache for - * each portion of the DN and update changed/missing parts as they are - * encountered. - * - * MdbDn must be an absolute MDB path! - */ -static char * -MdbToLdap(char *MdbDn) -{ - char *path = NULL; - char *obj = NULL; - char *base = NULL; - char *attrs[] = { "dn", NULL }; - char *dn = NULL; - char **expdn = NULL; - int err; - int scope; - LDAPMessage *res = NULL; - LDAPMessage *entry = NULL; - - XplRWReadLockAcquire(&(MdbLdap.PathLock)); - path = BongoHashtableGet(MdbLdap.PathTable, MdbDn); - if (path) { - path = strdup(path); - } - XplRWReadLockRelease(&(MdbLdap.PathLock)); - - if (!path) { - obj = strrchr(MdbDn, '\\'); - - if (obj) { - if (obj == MdbDn) { - *obj++ = '\0'; - base = malloc(MDB_MAX_OBJECT_CHARS + 1); - base[0] = '\0'; - scope = LDAP_SCOPE_BASE; - } else { - *obj++ = '\0'; - base = MdbToLdap(MdbDn); - scope = LDAP_SCOPE_ONELEVEL; - } - - if (base) { - XplMutexLock(MdbLdap.LdapMutex); - err = ldap_search_s(MdbLdap.Ldap, base, scope, - "(objectClass=*)", attrs, 0, &res); - - if (err == LDAP_SUCCESS) { - entry = ldap_first_entry(MdbLdap.Ldap, res); - - while (!path && entry) { - dn = ldap_get_dn(MdbLdap.Ldap, entry); - - if (dn) { - expdn = ldap_explode_dn(dn, 1); - - if (expdn) { - /* Some directories allow multiple entries at - the same level that have the same name but - different naming types. This comparison - will not honor this case as it stops - searching when it finds the first entry by - the same name. This is a limitation of the - MDB API and can only be fixed by - introducing naming types into MDB or by - restricting use of the directory. */ - if (expdn[0] && !strcasecmp(expdn[0], obj)) { - path = strdup(dn); - } - - ldap_value_free(expdn); - } - /* - else { - ldap_get_option(MdbLdap.Ldap, - LDAP_OPT_ERROR_NUMBER, &err); - Log(LOG_ERROR, "ldap_explode_dn() failed: %s", - ldap_err2string(err)); - Log(LOG_ERROR, "dn: %s", base); - break; - } - */ - - ldap_memfree(dn); - } else { - ldap_get_option(MdbLdap.Ldap, - LDAP_OPT_ERROR_NUMBER, &err); - Log(LOG_ERROR, "ldap_get_dn() failed: %s", - ldap_err2string(err)); - Log(LOG_ERROR, "dn: %s", base); - break; - } - - entry = ldap_next_entry(MdbLdap.Ldap, entry); - } - - ldap_msgfree(res); - } else { - Log(LOG_ERROR, "ldap_search_s() failed: %s", - ldap_err2string(err)); - Log(LOG_ERROR, "dn: %s", base); - } - - XplMutexUnlock(MdbLdap.LdapMutex); - - if (base) { - free(base); - } - } - - /* not sure if this is necessary */ - obj--; - *obj = '\\'; - } - - if (path) { - char *mdbDn, *ldapDn; - mdbDn = strdup(MdbDn); - ldapDn = strdup(path); - XplRWWriteLockAcquire(&(MdbLdap.PathLock)); - if (BongoHashtablePut(MdbLdap.PathTable, mdbDn, ldapDn)) { - free(mdbDn); - free(ldapDn); - } - XplRWWriteLockRelease(&(MdbLdap.PathLock)); - } - } - - return path; -} - -static char * -LdapToMdb(const char *LdapDn) -{ - char *mdbDn = NULL; - char **expdn = NULL; - int i; - - /* this will only work if LDAP DNs are always smaller than MDB DNs */ - mdbDn = malloc(MDB_MAX_OBJECT_CHARS + 1); - - if (mdbDn) { - *mdbDn = '\0'; - expdn = ldap_explode_dn(LdapDn, 1); - - if (expdn) { - for (i = 0; expdn[i]; i++); - - for (i--; i >= 0; i--) { - strcat(mdbDn, "\\"); - strcat(mdbDn, expdn[i]); - } - - ldap_value_free(expdn); - } else { - free(mdbDn); - mdbDn = NULL; - } - } - - return mdbDn; -} - -static char * -LdapToAbsoluteMdb(const char *LdapDn, const char *Base) -{ - char *mdbDn; - char *absDn = NULL; - - mdbDn = LdapToMdb(LdapDn); - - if (mdbDn) { - absDn = GetAbsoluteDn(mdbDn, Base); - free(mdbDn); - } - - return absDn; -} - -static char * -LdapToRelativeMdb(const char *LdapDn, const char *Base) -{ - char *mdbDn; - char *relDn = NULL; - - mdbDn = LdapToMdb(LdapDn); - - if (mdbDn) { - relDn = GetRelativeDn(mdbDn, Base); - free(mdbDn); - } - - return relDn; -} - -static char * -SafeMdbToLdap(const char *MdbDn, const char *Base) -{ - char *absDn; - char *ldapDn = NULL; - - absDn = GetAbsoluteDn(MdbDn, Base); - - if (absDn) { - ldapDn = MdbToLdap(absDn); - free(absDn); - } - - return ldapDn; -} - -static char * -NewSafeMdbToLdap(const char *MdbDn, char *Type, char *Base) -{ - char *newLeaf; - char *mdbContextDn; - char *ldapContextDn; - char *ldapDn = NULL; - int len; - - newLeaf = strrchr(MdbDn, '\\'); - if (newLeaf) { - len = newLeaf - MdbDn; - newLeaf++; - mdbContextDn = malloc(len + 1); - if (mdbContextDn) { - memcpy(mdbContextDn, MdbDn, len); - mdbContextDn[len] = '\0'; - ldapContextDn = SafeMdbToLdap(mdbContextDn, Base); - free(mdbContextDn); - } else { - ldapContextDn = NULL; - } - } else { - ldapContextDn = SafeMdbToLdap("", Base); - newLeaf = (char *)MdbDn; - } - - if (ldapContextDn) { - ldapDn = malloc(strlen(Type) + strlen(newLeaf) + strlen(ldapContextDn) + 3); - if (ldapDn) { - sprintf(ldapDn, "%s=%s,%s", Type, newLeaf, ldapContextDn); - } - free(ldapContextDn); - } - return ldapDn; -} - -/** - * Returns true if the extension is supported by the server. - */ -static BOOL -LdapExtension(const char *Id) -{ - if (BongoHashtableGet(MdbLdap.ExtTable, Id)) { - return TRUE; - } - - return FALSE; -} - -static char * -LdapSearchFilter (MDBValueStruct *types, - const char *pattern, - MDBValueStruct *attributes) -{ - char *typesPart; - char *attributesPart; - unsigned int i; - StringBuilder sb = { 0, }; - - AppendString(&sb, "(&(|"); - - for (i = 0; i < types->Used; i++) { - AppendString(&sb, "(objectclass="); - AppendString(&sb, TranslateSchemaName(types->Value[i])); - AppendString(&sb, ")"); - } - - AppendString(&sb, ")(|"); - - for (i = 0; i < attributes->Used; i++) { - AppendString(&sb, "("); - AppendString(&sb, TranslateSchemaName(attributes->Value[i])); - AppendString(&sb, "="); - AppendString(&sb, pattern); - AppendString(&sb, ")"); - } - - AppendString(&sb, "))"); - - return sb.str; -} - -/** - * Create an LDAP filter based on object class and pattern. - */ -static char * -LdapFilter(const char *type, const char *pattern) -{ - static const char *format = "(&(objectClass=%s)(|(cn=%s)(o=%s)(ou=%s)(dc=%s)(l=%s)(c=%s)))"; - pattern = pattern ? pattern : "*"; - type = type ? type : "*"; - return sprintf_dup (format, type, - pattern, pattern, pattern, pattern, pattern, pattern); -} - -/** - * Read values from the directory using ldap_search_s(). - * - * Base must be a valid LDAP DN. - */ -static char ** -LdapRead(const char *Base, const char *Attr, LDAP *Ldap) -{ - char *atmp[2] = {NULL, NULL}; - char **attrs = NULL; - char **vals = NULL; - char **tmps; - LDAPMessage *res; - LDAPMessage *entry; - int err; - - if (!Ldap) { - return NULL; - } - - if (Attr) { - attrs = atmp; - attrs[0] = (char *)Attr; - } - - err = ldap_search_s(Ldap, Base, LDAP_SCOPE_BASE, "(objectClass=*)", attrs, - 0, &res); - - if (err == LDAP_SUCCESS) { - entry = ldap_first_entry(Ldap, res); - - if (entry) { - tmps = ldap_get_values(Ldap, entry, Attr); - - if (tmps) { - vals = CopyValArray(tmps); - ldap_value_free(tmps); - } else { - ldap_get_option(Ldap, LDAP_OPT_ERROR_NUMBER, &err); - - /* decoding errors occur frequently for empty attrs */ - if (err != LDAP_DECODING_ERROR) { - Log(LOG_ERROR, "ldap_get_values() failed: %s", - ldap_err2string(err)); - Log(LOG_ERROR, "dn: %s", Base); - Log(LOG_ERROR, "attribute: %s", Attr); - } - } - } else { - ldap_get_option(Ldap, LDAP_OPT_ERROR_NUMBER, &err); - Log(LOG_ERROR, "ldap_first_entry() failed: %s", - ldap_err2string(err)); - Log(LOG_ERROR, "dn: %s", Base); - Log(LOG_ERROR, "attribute: %s", Attr); - } - - ldap_msgfree(res); - } else { - Log(LOG_ERROR, "ldap_search_s() failed: %s", ldap_err2string(err)); - Log(LOG_ERROR, "dn: %s", Base); - Log(LOG_ERROR, "attribute: %s", Attr); - } - - return vals; -} - -static BOOL -LdapWrite(const char *Base, const char *Attr, char **Vals, int Op, - LDAP *Ldap) -{ - LDAPMod mod; - LDAPMod *mods[2] = {&mod, NULL}; - int err, i, count; - - if (!Ldap) { - return FALSE; - } - - mod.mod_op = Op; - mod.mod_type = (char *)Attr; - mod.mod_values = Vals; - - err = ldap_modify_s(Ldap, Base, mods); - - if (err == LDAP_SUCCESS) { - return TRUE; - } - - Log(LOG_ERROR, "ldap_modify_s() failed: %s", ldap_err2string(err)); - Log(LOG_ERROR, "dn: %s", Base); - Log(LOG_ERROR, "attribute: %s", Attr); - - if (Vals) { - count = CountValArray(Vals); - - for (i = 0; i < count; i++) { - Log(LOG_ERROR, "%s: %s", Attr, Vals[i]); - } - } - - return FALSE; -} - -static BOOL -LdapCreate(const char *Base, char **Classes, BongoHashtable *Attrs, LDAP *Ldap) -{ - LDAPMod **mods, *mod, classMod, namingMod; - char *namingVals[2], *namingType, *name = NULL, *ptr; - BOOL result = FALSE; - BongoHashtableIter iter; - int i, j, next = 0; - int err; - - if (!Ldap) { - return FALSE; - } - - namingType = strdup(Base); - - if (namingType) { - ptr = strchr(namingType, '='); - if (ptr) { - *ptr++ = '\0'; - name = ptr; - ptr = strchr(name, ','); - if (ptr) { - *ptr = '\0'; - } - } - } - - mods = malloc(sizeof(LDAPMod *) * (BongoHashtableSize(Attrs) + 3)); - - if (mods && namingType && name) { - namingMod.mod_op = LDAP_MOD_ADD; - namingMod.mod_type = namingType; - - namingMod.mod_values = namingVals; - namingMod.mod_values[0] = name; - namingMod.mod_values[1] = NULL; - - classMod.mod_op = LDAP_MOD_ADD; - classMod.mod_type = "objectClass"; - classMod.mod_values = Classes; - - for (BongoHashtableIterFirst(Attrs, &iter); iter.key; - BongoHashtableIterNext(Attrs, &iter)) { - mod = malloc(sizeof(LDAPMod)); - - if (!mod) { - break; - } - - memset(mod, 0, sizeof(LDAPMod)); - mod->mod_op = LDAP_MOD_ADD; - mod->mod_type = iter.key; - mod->mod_values = iter.value; - mods[next++] = mod; - } - - if (next == BongoHashtableSize(Attrs)) { - mods[next] = &classMod; - mods[next + 1] = &namingMod; - mods[next + 2] = NULL; - - err = ldap_add_s(Ldap, Base, mods); - - if (err == LDAP_SUCCESS) { - result = TRUE; - } else { - Log(LOG_ERROR, "ldap_add_s() failed: %s", - ldap_err2string(err)); - Log(LOG_ERROR, "dn: %s", Base); - for (i = 0; mods[i]; i++) { - for (j = 0; mods[i]->mod_values[j]; j++) { - Log(LOG_ERROR, "%s: %s", mods[i]->mod_type, - mods[i]->mod_values[j]); - } - } - } - } - - for (i = 0; i < next; i++) { - free(mods[i]); - } - - free(namingType); - free(mods); - } - - return result; -} - -static char ** -LdapSearch(const char *Base, const char *Filter, int depth, int max, LDAP *Ldap) -{ - char *dn; - char **paths = NULL; - char *attrs[2] = {"dn", NULL}; - LDAPMessage *res; - LDAPMessage *entry; - int err; - int count; - int i = 0; - - if (!Ldap) { - return NULL; - } - - err = ldap_search_s(Ldap, Base, LDAP_SCOPE_ONELEVEL, Filter, attrs, 0, - &res); - - if (err == LDAP_SUCCESS) { - count = ldap_count_entries(Ldap, res); - - if (max != -1 && count > max) { - count = max; - } - - if (count) { - paths = NewValArray(count); - - if (paths) { - entry = ldap_first_entry(Ldap, res); - - while (entry) { - dn = ldap_get_dn(Ldap, entry); - - if (dn) { - paths[i] = strdup(dn); - ldap_memfree(dn); - } - - if (!paths[i]) { - break; - } - - i++; - entry = ldap_next_entry(Ldap, entry); - } - - if (i < count) { - FreeValArray(paths); - free(paths); - paths = NULL; - } - } - } - - ldap_msgfree(res); - } else { - Log(LOG_ERROR, "ldap_search_s() failed: %s", ldap_err2string(err)); - Log(LOG_ERROR, "dn: %s", Base); - } - - return paths; -} - -/** - * Get list of object attributes. - */ -static char ** -LdapAttributes(const char *Base, LDAP *Ldap) -{ - char **vals = NULL; - LDAPMessage *res; - LDAPMessage *entry; - int err = 0; - char *attr; - BerElement *ber; - int inc = 12; - int max = inc; - int i = 0; - - if (!Ldap) { - return NULL; - } - - err = ldap_search_s(Ldap, Base, LDAP_SCOPE_BASE, "(objectClass=*)", NULL, - 0, &res); - - if (err == LDAP_SUCCESS) { - entry = ldap_first_entry(Ldap, res); - - if (entry) { - vals = NewValArray(max); - - if (vals) { - attr = ldap_first_attribute(Ldap, entry, &ber); - err = 0; - - while (attr) { - if (i == max) { - max += inc; - - if (!ExpandValArray(&vals, max)) { - err = 1; - break; - } - } - - vals[i] = strdup(attr); - - if (!vals[i]) { - err = 1; - break; - } - - i++; - attr = ldap_next_attribute(Ldap, entry, ber); - } - - if (err) { - FreeValArray(vals); - free(vals); - vals = NULL; - } - } - } else { - ldap_get_option(Ldap, LDAP_OPT_ERROR_NUMBER, &err); - Log(LOG_ERROR, "ldap_first_entry() failed: %s", - ldap_err2string(err)); - Log(LOG_ERROR, "dn: %s", Base); - } - - ldap_msgfree(res); - } else { - Log(LOG_ERROR, "ldap_search_s() failed: %s", ldap_err2string(err)); - Log(LOG_ERROR, "dn: %s", Base); - } - - return vals; -} - -/** - * Verify object password. - */ -static BOOL -LdapVerify(const char *Base, const char *Password) -{ - LDAP *ldap; - int err, tries; - BOOL result = FALSE; - -#ifdef _SOLARIS_SDK - if (MdbLdap.LdapTls) { - err = ldapssl_client_init(NULL, NULL); - ldap = ldap_init(MdbLdap.LdapHostAddress, MdbLdap.LdapHostPort); - if (ldap) { - if (err == LDAP_SUCCESS) { - err = ldapssl_install_routines(ldap); - } - if (err == LDAP_SUCCESS) { -#ifdef LDAP_OPT_SSL - err = ldap_set_option(ldap, LDAP_OPT_SSL, LDAP_OPT_ON); -#endif - ldap_set_option(ldap, LDAP_OPT_RECONNECT, LDAP_OPT_ON); - } - if (err != LDAP_SUCCESS) { - Log(LOG_ERROR, "Enabling TLS failed: %s", - ldap_err2string(err)); - ldap_unbind_ext(ldap, NULL, NULL); - ldap = NULL; - } - } - } else { - ldap = ldap_init(MdbLdap.LdapHostAddress, MdbLdap.LdapHostPort); - } -#else - ldap = ldap_init(MdbLdap.LdapHostAddress, MdbLdap.LdapHostPort); - if (ldap) { - if (MdbLdap.LdapTls) { - err = ldap_start_tls_s(ldap, NULL, NULL); - if (err != LDAP_SUCCESS) { - Log(LOG_ERROR, "ldap_start_tls_s() failed: %s", - ldap_err2string(err)); - ldap_unbind_ext(ldap, NULL, NULL); - ldap = NULL; - } - } - } -#endif - - if (ldap) { - - for (tries = 0; tries < 3; tries++) { - err = ldap_simple_bind_s(ldap, Base, Password); - - if (err == LDAP_SUCCESS) { - result = TRUE; - break; - } - } - - ldap_unbind_s(ldap); - } - - return result; -} - -/** - * Change object password. - */ -static BOOL -LdapPassword(const char *Base, char *OldPassword, char *NewPassword, - LDAP *Ldap) -{ - BerElement *elem; - struct berval *bv = NULL; - int id = LDAP_OTHER; - int err = LDAP_OTHER; - char *vals[2] = {NewPassword, NULL}; - - if (!Ldap) { - return FALSE; - } - -#ifdef _SOLARIS_SDK - { -#else - if (LdapExtension("1.3.6.1.4.1.4203.1.11.1")) { - /* This method uses the modify password extended operation. - See RFC 3062 for details. */ - elem = ber_alloc_t(LBER_USE_DER); - - ber_printf(elem, "{"); - ber_printf(elem, "ts", LDAP_TAG_EXOP_MODIFY_PASSWD_ID, Base); - - if (*OldPassword != '\0') { - ber_printf(elem, "ts", LDAP_TAG_EXOP_MODIFY_PASSWD_OLD, - OldPassword); - } - - ber_printf(elem, "ts", LDAP_TAG_EXOP_MODIFY_PASSWD_NEW, NewPassword); - ber_printf(elem, "N}"); - - err = ber_flatten(elem, &bv); - - if (err < 0 || !bv->bv_val) { - ber_free(elem, 1); - return FALSE; - } - - err = ldap_extended_operation(Ldap, LDAP_EXOP_MODIFY_PASSWD, bv, NULL, - NULL, &id); - ber_free(elem, 1); - ber_bvfree(bv); - - if (err == LDAP_SUCCESS) { - return TRUE; - } -#if 0 -/* So far I have been unsuccessful in getting this to work on - Active Directory. Also, the BASE64 encoder inserts line breaks, which is - a potential problem if your password is long enough. */ - } else if (BongoHashtableGet(MdbLdap.AttrTable, "unicodePwd")) { - /* Jumping through hoops for Active Directory... */ - /* This will fail without a secure connection. */ - LDAPMod modNewPassword; - LDAPMod modOldPassword; - LDAPMod *modEntry[3] = {NULL, NULL, NULL}; - struct berval newPwdBerVal; - struct berval oldPwdBerVal; - struct berval *newPwd_attr[2] = {&newPwdBerVal, NULL}; - struct berval *oldPwd_attr[2] = {&oldPwdBerVal, NULL}; - char newPwdQuoted[1024]; - char oldPwdQuoted[1024]; - char newPwdEncoded[1024]; - char oldPwdEncoded[1024]; - char tmp[1024]; - int count = 0; - char *codecs[2] = {"UCS-2", "BASE64"}; - BongoStream *stream = BongoStreamCreate(codecs, 2, TRUE); - - if (stream) { - sprintf(newPwdQuoted, "\"%s\"", NewPassword); - BongoStreamPut(stream, newPwdQuoted, strlen(newPwdQuoted)); - BongoStreamEos(stream); - count = BongoStreamGet(stream, newPwdEncoded, 1024); - - if (count == 1024 || BongoStreamGet(stream, tmp, 1024)) { - BongoStreamFree(stream); - Log(LOG_ERROR, "Encoding error: %s", newPwdEncoded); - return FALSE; - } - - newPwdEncoded[count - 2] = '\0'; - newPwdBerVal.bv_len = strlen(newPwdEncoded); - newPwdBerVal.bv_val = (char *) newPwdEncoded; - modNewPassword.mod_type = "unicodePwd"; - modNewPassword.mod_vals.modv_bvals = newPwd_attr; - - if (OldPassword && OldPassword[0]) { - sprintf(oldPwdQuoted, "\"%s\"", OldPassword); - BongoStreamPut(stream, oldPwdQuoted, strlen(oldPwdQuoted)); - BongoStreamEos(stream); - count = BongoStreamGet(stream, oldPwdEncoded, 1024); - - if (count == 1024 || BongoStreamGet(stream, tmp, 1024)) { - BongoStreamFree(stream); - Log(LOG_ERROR, "Encoding error: %s", oldPwdEncoded); - return FALSE; - } - - oldPwdEncoded[count - 2] = '\0'; - oldPwdBerVal.bv_len = strlen(oldPwdEncoded); - oldPwdBerVal.bv_val = (char *) oldPwdEncoded; - modOldPassword.mod_op = LDAP_MOD_DELETE | LDAP_MOD_BVALUES; - modOldPassword.mod_type = "unicodePwd"; - modOldPassword.mod_vals.modv_bvals = oldPwd_attr; - modNewPassword.mod_op = LDAP_MOD_ADD | LDAP_MOD_BVALUES; - modEntry[0] = &modOldPassword; - modEntry[1] = &modNewPassword; - } else { - modNewPassword.mod_op = LDAP_MOD_REPLACE | LDAP_MOD_BVALUES; - modEntry[0] = &modNewPassword; - } - - err = ldap_modify_s(Ldap, Base, modEntry); - - if (err != LDAP_SUCCESS) { - Log(LOG_ERROR, "ldap_modify_s() failed: %s", ldap_err2string(err)); - Log(LOG_ERROR, "dn: %s", Base); - Log(LOG_ERROR, "attribute: %s", modNewPassword.mod_type); - Log(LOG_ERROR, "value: %s", newPwdEncoded); - return FALSE; - } - - BongoStreamFree(stream); - } - - return TRUE; -#endif - } else { -#endif - /* This is the old-school method. - Hopefully the directory performs some sort of encryption for us. */ - if (OldPassword && OldPassword[0] && !LdapVerify(Base, OldPassword)) { - return FALSE; - } - - return LdapWrite(Base, "userPassword", vals, LDAP_MOD_REPLACE, Ldap); - } - - return FALSE; -} - -static LDAP * -InitLdapConnection(char *BindDn, char *Passwd, void *rebind_proc, - MDBLDAPContextStruct *Context) -{ - LDAP *ldap = NULL; - int err, tries; - -#ifdef _SOLARIS_SDK - if (MdbLdap.LdapTls) { - err = ldapssl_client_init(NULL, NULL); - ldap = ldap_init(MdbLdap.LdapHostAddress, MdbLdap.LdapHostPort); - if (ldap) { - if (err == LDAP_SUCCESS) { - err = ldapssl_install_routines(ldap); - } - if (err == LDAP_SUCCESS) { -#ifdef LDAP_OPT_SSL - err = ldap_set_option(ldap, LDAP_OPT_SSL, LDAP_OPT_ON); -#endif - ldap_set_option(ldap, LDAP_OPT_RECONNECT, LDAP_OPT_ON); - } - if (err != LDAP_SUCCESS) { - Log(LOG_ERROR, "Enabling TLS failed: %s", - ldap_err2string(err)); - ldap_unbind_ext(ldap, NULL, NULL); - ldap = NULL; - } - } - } else { - ldap = ldap_init(MdbLdap.LdapHostAddress, MdbLdap.LdapHostPort); - } -#else - ldap = ldap_init(MdbLdap.LdapHostAddress, MdbLdap.LdapHostPort); - if (ldap) { - if (MdbLdap.LdapTls) { - err = ldap_start_tls_s(ldap, NULL, NULL); - if (err != LDAP_SUCCESS) { - Log(LOG_ERROR, "ldap_start_tls_s() failed: %s", - ldap_err2string(err)); - ldap_unbind_ext(ldap, NULL, NULL); - ldap = NULL; - } - } - } -#endif - if (ldap) { - for (tries = 0; tries < 3; tries++) { - err = ldap_simple_bind_s(ldap, BindDn, Passwd); - - if (err == LDAP_SUCCESS) { - break; - } - } - - if (err == LDAP_SUCCESS) { - ldap_set_rebind_proc(ldap, rebind_proc, Context); - } else { - Log(LOG_ERROR, "ldap_simple_bind_s() failed: %s", - ldap_err2string(err)); - Log(LOG_ERROR, "dn: %s", BindDn); - ldap_unbind_s(ldap); - ldap = NULL; - } - } else { - Log(LOG_ERROR, "ldap_init() failed: %s", ldap_err2string(errno)); - Log(LOG_ERROR, "host: %s:%d", MdbLdap.LdapHostAddress, - MdbLdap.LdapHostPort); - } - - return ldap; -} - -static BOOL -DeleteLdapConnection(LDAP *Ldap) -{ - int err; - - if (Ldap) { - err = ldap_unbind_s(Ldap); - - if (err != LDAP_SUCCESS) { - Log(LOG_ERROR, "ldap_unbind() failed: %s", ldap_err2string(err)); - return FALSE; - } - } - - return TRUE; -} - -static LDAP * -GetCachedLdapConnection(MDBLDAPContextStruct *Context) -{ - LDAP *ldap = NULL; - - if (Context->conn.min) { - XplMutexLock(Context->conn.mutex); - - if (Context->conn.next > -1) { - ldap = Context->conn.list[Context->conn.next--]; - } - - XplMutexUnlock(Context->conn.mutex); - } - - return ldap; -} - -static BOOL -AddCachedLdapConnection(MDBLDAPContextStruct *Context, LDAP *Ldap) -{ - BOOL result = FALSE; - - if (Context->conn.min) { - XplMutexLock(Context->conn.mutex); - - if (Context->conn.next + 1 < Context->conn.max) { - Context->conn.list[++Context->conn.next] = Ldap; - result = TRUE; - } - - XplMutexUnlock(Context->conn.mutex); - } - - return result; -} - -static LDAP * -GetLdapConnection(MDBLDAPContextStruct *Context) -{ - LDAP *ldap = NULL; - - ldap = GetCachedLdapConnection(Context); - - if (!ldap) { - ldap = InitLdapConnection(Context->binddn, Context->passwd, - UserRebindProc, Context); - } - - return ldap; -} - -static BOOL -ReleaseLdapConnection(MDBLDAPContextStruct *Context, LDAP *Ldap) -{ - if (!AddCachedLdapConnection(Context, Ldap)) { - return DeleteLdapConnection(Ldap); - } - - return TRUE; -} - -static void -DestroyContext(MDBLDAPContextStruct *context) -{ - if (context->binddn) { - free(context->binddn); - } - - if (context->passwd) { - free(context->passwd); - } - - XplMutexDestroy(context->conn.mutex); - - if (context->conn.list) { - /* clean up connection pool */ - while (context->conn.next >= 0) { - DeleteLdapConnection(context->conn.list[context->conn.next--]); - } - - free(context->conn.list); - } - - free(context); -} - -static MDBLDAPContextStruct * -CreateContext(const char *BindDn, const char *Password) -{ - MDBLDAPContextStruct *context; - char *ldapDn; - - context = malloc(sizeof(MDBLDAPContextStruct)); - - if (context) { - memset(context, 0, sizeof(MDBLDAPContextStruct)); - - if (BindDn && Password) { - ldapDn = SafeMdbToLdap(BindDn, NULL); - - if (ldapDn) { - context->binddn = ldapDn; - context->passwd = strdup(Password); - - if (!context->passwd) { - free(context->binddn); - free(context); - context = NULL; - } - } else { - free(context); - context = NULL; - } - } - - if (context) { - context->conn.next = -1; - context->conn.min = MdbLdap.LdapMinConnections; - context->conn.max = MdbLdap.LdapMaxConnections; - XplMutexInit(context->conn.mutex); - - /* initialize the connection pool */ - context->conn.list = malloc(sizeof(LDAP *) * context->conn.max); - - if (context->conn.list) { - if (context->conn.min) { - /* don't init connections if min is 0 */ - while (context->conn.next < context->conn.min) { - context->conn.list[++context->conn.next] = - InitLdapConnection(context->binddn, - context->passwd, - UserRebindProc, context); - - if (!context->conn.list[context->conn.next]) { - DestroyContext(context); - context = NULL; - break; - } - } - } - } else { - DestroyContext(context); - context = NULL; - } - } - } - - return context; -} - -/** - * Functions for handling the attribute schema cache. - */ - -static void -AttrDel(void *value) -{ - MDBLDAPSchemaAttr *attr = (MDBLDAPSchemaAttr *) value; - - if (attr->refcnt > 1) { - attr->refcnt--; - } else { - free(attr->val); - - if (attr->names) { - free(attr->names); - } - - free(attr); - } -} - -static void -AttrUpdate(char *key, MDBLDAPSchemaAttr *attr, void *data) -{ - MDBLDAPSchemaAttr *ptr = NULL; - - /* fill out incomplete properties on schema attributes by following - superclass hierarchy */ - - if (!attr->visited && attr->sup) { - ptr = BongoHashtableGet(MdbLdap.AttrTable, attr->sup); - - if (!ptr->visited) { - AttrUpdate(attr->sup, ptr, NULL); - } - - if (!attr->desc && ptr->desc) { - attr->desc = ptr->desc; - } - - if (!attr->equality && ptr->equality) { - attr->equality = ptr->equality; - } - - if (!attr->syntax && ptr->syntax) { - attr->syntax = ptr->syntax; - } - - if (!attr->singleval && ptr->singleval) { - attr->singleval = ptr->singleval; - } - - /* FIXME: this function already recurses. - figure out what this is supposed to do. */ -#if 0 - if (ptr->sup) { - ptr = BongoHashtableGet(MdbLdap.AttrTable, ptr->sup); - } else { - ptr = NULL; - } -#endif - } - - attr->visited = TRUE; -} - -#if 0 -static void -AttrPrint(void *key, void *value, void *data) -{ - MDBLDAPSchemaAttr *attr = (MDBLDAPSchemaAttr *) value; - printf("%s: %s\n", key, attr->equality); -} -#endif - -/** - * Read LDAPv3 supported extensions from root - * We use this to quickly determine what the server supports when using LDAP - * functions (especially extended operations). - */ -static BOOL -LoadExtensions(void) -{ - char **vals; - char *ext; - int i; - BOOL result = TRUE; - - XplMutexLock(MdbLdap.LdapMutex); - vals = LdapRead("", "supportedExtension", MdbLdap.Ldap); - XplMutexUnlock(MdbLdap.LdapMutex); - - if (vals) { - for (i = 0; vals[i]; i++) { - ext = strdup(vals[i]); - - if (ext) { - if (BongoHashtablePut(MdbLdap.ExtTable, ext, ext)) { - result = FALSE; - free(ext); - break; - } - } else { - result = FALSE; - break; - } - } - - FreeValArray(vals); - free(vals); - } - - return result; -} - -/** - * Read LDAPv3 attribute schema definitions from SubschemaSubentry object. - */ -static BOOL -LoadSchemaAttrs(void) -{ - char **vals; - int i, j; - MDBLDAPSchemaAttr *attr; - BOOL result = TRUE; - - XplMutexLock(MdbLdap.LdapMutex); - vals = LdapRead(MdbLdap.LdapSchemaDn, "attributeTypes", MdbLdap.Ldap); - XplMutexUnlock(MdbLdap.LdapMutex); - - if (vals) { - for (i = 0; vals[i]; i++) { - attr = malloc(sizeof(MDBLDAPSchemaAttr)); - - if (attr) { - memset(attr, 0, sizeof(MDBLDAPSchemaAttr)); - attr->val = strdup(vals[i]); - result = ParseAttributeTypeDescription(attr->val, attr); - - if (result && attr->names && attr->names[0]) { - for (j = 0; attr->names[j]; j++) { - BongoHashtablePut(MdbLdap.AttrTable, attr->names[j], - attr); - /*XplConsolePrintf("loading attribute: >>%s<<\n", attr->names[j]);*/ - attr->refcnt++; - } - } else { - result = FALSE; - free(attr->val); - free(attr); - break; - } - } else { - result = FALSE; - break; - } - } - - if (result) { - BongoHashtableForeach(MdbLdap.AttrTable, (HashtableForeachFunc)AttrUpdate, NULL); - } - - FreeValArray(vals); - free(vals); - } else { - result = FALSE; - } - - return result; -} - - -/** - * Functions for handling the class schema cache. - */ - -static void -ClassDel(void *value) -{ - MDBLDAPSchemaClass *class = (MDBLDAPSchemaClass *) value; - - if (class->refcnt > 1) { - class->refcnt--; - } else { - free(class->val); - - if (class->names) { - free(class->names); - } - - if (class->sup) { - free(class->sup); - } - - if (class->must) { - free(class->must); - } - - if (class->may) { - free(class->may); - } - - free(class); - } -} - -static void -ClassUpdate(char *key, MDBLDAPSchemaClass *class, void *data) -{ - MDBLDAPSchemaClass *ptr = NULL; - int count; - int inc = 4; - int i, j; - - if (!class->visited && class->sup) { - for (j = 0; class->sup[j]; j++) { - ptr = BongoHashtableGet(MdbLdap.ClassTable, class->sup[j]); - - if (!ptr->visited) { - ClassUpdate(class->sup[j], ptr, NULL); - } - - if (!class->desc && ptr->desc) { - class->desc = ptr->desc; - } - - if (ptr->must) { - if (!class->must) { - class->must = NewValArray(inc); - } - - count = CountValArray(class->must); - - for (i = 0; ptr->must[i]; i++) { - if (!(count % inc)) { - if (!ExpandValArray(&(class->must), count + inc)) { - return; - } - } - - class->must[count++] = ptr->must[i]; - } - } - - if (ptr->may) { - if (!class->may) { - class->may = NewValArray(inc); - } - - count = CountValArray(class->may); - - for (i = 0; ptr->may[i]; i++) { - if (!(count % inc)) { - if (!ExpandValArray(&(class->may), count + inc)) { - return; - } - } - - class->may[count++] = ptr->may[i]; - } - } - - /* It turns out that classes can inherit from multiple - super-classes.. this means we have to pick one of them for - our naming attribute (see the 'HATE LDAP!!' comment below). - This method will use the last super-class. */ - - /* abstract superiors don't define naming attribute */ - /* look at the current class */ - - class->naming = NULL; - - if (class->must) { - for (i = 0; class->must[i]; i++) { - if (!strcasecmp(class->must[i], "cn")) { - class->naming = "cn"; - break; - } else if (!strcasecmp(class->must[i], "o")) { - class->naming = "o"; - break; - } else if (!strcasecmp(class->must[i], "ou")) { - class->naming = "ou"; - break; - } else if (!strcasecmp(class->must[i], "c")) { - class->naming = "c"; - break; - } else if (!strcasecmp(class->must[i], "dc")) { - class->naming = "dc"; - break; - } else if (!strcasecmp(class->must[i], "l")) { - class->naming = "l"; - break; - } - } - } - - if (!class->naming && strcmp(ptr->naming, "cn")) { - class->naming = ptr->naming; - } - - if (!class->naming && class->may) { - for (i = 0; class->may[i]; i++) { - if (!strcasecmp(class->may[i], "cn")) { - class->naming = "cn"; - break; - } else if (!strcasecmp(class->may[i], "o")) { - class->naming = "o"; - break; - } else if (!strcasecmp(class->may[i], "ou")) { - class->naming = "ou"; - break; - } else if (!strcasecmp(class->may[i], "c")) { - class->naming = "c"; - break; - } else if (!strcasecmp(class->may[i], "dc")) { - class->naming = "dc"; - break; - } else if (!strcasecmp(class->may[i], "l")) { - class->naming = "l"; - break; - } - } - } - - if (!class->naming) { - class->naming = "cn"; - } - } - } - - class->visited = TRUE; -} - -#if 0 -static void -ClassPrint(void *key, void *value, void *data) -{ - MDBLDAPSchemaClass *class = (MDBLDAPSchemaClass *) value; - printf("%s: %s\n", key, class->naming); -} -#endif - -/** - * Read LDAPv3 class schema definitions from SubschemaSubentry object. - */ -static BOOL -LoadSchemaClasses(void) -{ - char **vals; - int i, j; - MDBLDAPSchemaClass *class; - BOOL result = TRUE; - - XplMutexLock(MdbLdap.LdapMutex); - vals = LdapRead(MdbLdap.LdapSchemaDn, "objectClasses", MdbLdap.Ldap); - XplMutexUnlock(MdbLdap.LdapMutex); - - if (vals) { - for (i = 0; vals[i]; i++) { - class = malloc(sizeof(MDBLDAPSchemaClass)); - - if (class) { - memset(class, 0, sizeof(MDBLDAPSchemaClass)); - class->val = strdup(vals[i]); - result = ParseObjectClassDescription(class->val, class); - - if (result && class->names && class->names[0]) { - for (j = 0; class->names[j]; j++) { - /* Sometimes I absolutely HATE LDAP!!! - There really is no defined way to determine what the - naming attribute is supposed to be for a particular - object. Sometimes attributes that extend the 'name' - attribute are used, sometimes attributes like 'uid' - are used. Some classes have multiple 'name' - attributes and some don't have any at all. Some naming - attributes are only used for certain classes. I really - wish there was something defined in the schema to help - solve this problem but there is _not_. I've tried my - best to keep schema definitions out of the driver but - it looks like I have to hard-code some here. If the - class is not known, it will have to be added. - Otherwise, all classes will default to 'cn'.*/ - - /* TODO: Maybe 'uid' would be a better default? */ - - if (!strcasecmp(class->names[j], "country")) { - class->naming = "c"; - } else if (!strcasecmp(class->names[j], "dcObject")) { - class->naming = "dc"; - } else if (!strcasecmp(class->names[j], "domain")) { - class->naming = "dc"; - } else if (!strcasecmp(class->names[j], "locality")) { - class->naming = "l"; - } else if (!strcasecmp(class->names[j], "organization")) { - class->naming = "o"; - } else if (!strcasecmp(class->names[j], - "organizationalUnit")) { - class->naming = "ou"; - } else { - class->naming = "cn"; - } - - BongoHashtablePut(MdbLdap.ClassTable, - class->names[j], class); - class->refcnt++; - } - } else { - result = FALSE; - free(class->val); - free(class); - break; - } - } else { - result = FALSE; - break; - } - } - - if (result) { - BongoHashtableForeach(MdbLdap.ClassTable, (HashtableForeachFunc)ClassUpdate, NULL); - } - - FreeValArray(vals); - free(vals); - } else { - result = FALSE; - } - - return result; -} - -/** - * Make a simple translation of an xplschema.h schema name. - * Removes illegal characters from schema name. - */ -static BOOL -RemoveIllegalChars(char *Buffer, char *Name, char *illegal) -{ - char *orig; - char *token; - char *ptr; - - if (strpbrk(Name, illegal)) { - orig = strdup(Name); - - if (orig) { - Buffer[0] = '\0'; - token = strtok_r(orig, illegal, &ptr); - - while (token) { - strcat(Buffer, token); - token = strtok_r(NULL, illegal, &ptr); - } - - free(orig); - } else { - return FALSE; - } - } else { - strcpy(Buffer, Name); - } - - return TRUE; -} - -static BOOL -AddTranslation(char *Orig, char *Trans) -{ - char *orig = strdup(Orig); - char *trans = strdup(Trans); - - if (orig && trans) { - if (BongoHashtablePut(MdbLdap.TransTable, trans, orig)) { - free(orig); - free(trans); - return FALSE; - } - } else { - if (orig) { - free(orig); - } - - return FALSE; - } - - return TRUE; -} - -static BOOL -InitTranslations(void) -{ - /* The schema translation table: - Should include all definitions from xplschema.h with relevant LDAP - translations. If translation is NULL, no specific translation is known. - If the name contains illegal LDAP characters, a translation will be - generated and registered for the name. */ - static char *trans_table[][2] = { - {C_AFP_SERVER, NULL}, - {C_ALIAS, "alias"}, /* RFC2256 */ - {C_BINDERY_OBJECT, NULL}, - {C_BINDERY_QUEUE, NULL}, - {C_COMMEXEC, NULL}, - {C_COMPUTER, NULL}, - {C_COUNTRY, "country"}, /* RFC2256 */ - {C_DEVICE, "device"}, /* RFC2256 */ - {C_DIRECTORY_MAP, NULL}, - {C_EXTERNAL_ENTITY, NULL}, - {C_GROUP, "groupOfNames"}, /* RFC2256 */ - {C_LIST, NULL}, - {C_LOCALITY, "locality"}, /* RFC2256 */ - {C_MESSAGE_ROUTING_GROUP, NULL}, - {C_MESSAGING_ROUTING_GROUP, NULL}, - {C_MESSAGING_SERVER, NULL}, - {C_NCP_SERVER, NULL}, - {C_ORGANIZATION, "organization"}, /* RFC2256 */ - {C_ORGANIZATIONAL_PERSON, "organizationalPerson"}, /* RFC2256 */ - {C_ORGANIZATIONAL_ROLE, "organizationalRole"}, /* RFC2256 */ - {C_ORGANIZATIONAL_UNIT, "organizationalUnit"}, /* RFC2256 */ - {C_PARTITION, NULL}, - {C_PERSON, "person"}, /* RFC2256 */ - {C_PRINT_SERVER, NULL}, - {C_PRINTER, NULL}, - {C_PROFILE, NULL}, - {C_QUEUE, NULL}, - {C_RESOURCE, NULL}, - {C_SERVER, NULL}, - {C_TOP, "top"}, /* RFC2256 */ - {C_TREE_ROOT, NULL}, - {C_UNKNOWN, NULL}, - {C_USER, "inetOrgPerson"}, /* RFC2798 */ - {C_VOLUME, NULL}, - {A_ACCOUNT_BALANCE, NULL}, - {A_ACL, NULL}, - {A_ALIASED_OBJECT_NAME, "aliasedObjectName"}, /* RFC2256 */ - {A_ALLOW_UNLIMITED_CREDIT, NULL}, - {A_AUTHORITY_REVOCATION, NULL}, - {A_BACK_LINK, NULL}, - {A_BINDERY_OBJECT_RESTRICTION, NULL}, - {A_BINDERY_PROPERTY, NULL}, - {A_BINDERY_TYPE, NULL}, - {A_CARTRIDGE, NULL}, - {A_CA_PRIVATE_KEY, NULL}, - {A_CA_PUBLIC_KEY, NULL}, - {A_CERTIFICATE_REVOCATION, NULL}, - {A_CERTIFICATE_VALIDITY_INTERVAL, NULL}, - {A_COMMON_NAME, "cn"}, /* RFC2256 */ - {A_CONVERGENCE, NULL}, - {A_COUNTRY_NAME, "c"}, /* RFC2256 */ - {A_CROSS_CERTIFICATE_PAIR, "crossCertificatePair"}, /* RFC2256 */ - {A_DEFAULT_QUEUE, NULL}, - {A_DESCRIPTION, "description"}, /* RFC2256 */ - {A_DETECT_INTRUDER, NULL}, - {A_DEVICE, NULL}, - {A_DS_REVISION, NULL}, - {A_EMAIL_ADDRESS, "mail"}, /* RFC1274 */ - {A_EQUIVALENT_TO_ME, NULL}, - {A_EXTERNAL_NAME, NULL}, - {A_EXTERNAL_SYNCHRONIZER, NULL}, - {A_FACSIMILE_TELEPHONE_NUMBER, "facsimileTelephoneNumber"}, /*RFC2256*/ - {A_FULL_NAME, NULL}, /* displayName? */ - {A_GENERATIONAL_QUALIFIER, "generationQualifier"}, /* RFC2256 */ - {A_GID, NULL}, /* gidNumber? */ - {A_GIVEN_NAME, "givenName"}, /* RFC2256 */ - {A_GROUP_MEMBERSHIP, NULL}, - {A_HIGH_SYNC_INTERVAL, NULL}, - {A_HIGHER_PRIVILEGES, NULL}, - {A_HOME_DIRECTORY, NULL}, - {A_HOST_DEVICE, NULL}, - {A_HOST_RESOURCE_NAME, NULL}, - {A_HOST_SERVER, NULL}, /* host? */ - {A_INHERITED_ACL, NULL}, - {A_INITIALS, "initials"}, /* RFC2256 */ - {A_INTERNET_EMAIL_ADDRESS, "mail"}, /* RFC 2789 */ - {A_INTRUDER_ATTEMPT_RESET_INTRVL, NULL}, - {A_INTRUDER_LOCKOUT_RESET_INTRVL, NULL}, - {A_LOCALITY_NAME, "l"}, - {A_LANGUAGE, NULL}, /* preferredLanguage? */ - {A_LAST_LOGIN_TIME, NULL}, - {A_LAST_REFERENCED_TIME, NULL}, - {A_LOCKED_BY_INTRUDER, NULL}, - {A_LOCKOUT_AFTER_DETECTION, NULL}, - {A_LOGIN_ALLOWED_TIME_MAP, NULL}, - {A_LOGIN_DISABLED, NULL}, - {A_LOGIN_EXPIRATION_TIME, NULL}, - {A_LOGIN_GRACE_LIMIT, NULL}, - {A_LOGIN_GRACE_REMAINING, NULL}, - {A_LOGIN_INTRUDER_ADDRESS, NULL}, - {A_LOGIN_INTRUDER_ATTEMPTS, NULL}, - {A_LOGIN_INTRUDER_LIMIT, NULL}, - {A_LOGIN_INTRUDER_RESET_TIME, NULL}, - {A_LOGIN_MAXIMUM_SIMULTANEOUS, NULL}, - {A_LOGIN_SCRIPT, NULL}, - {A_LOGIN_TIME, NULL}, - {A_LOW_RESET_TIME, NULL}, - {A_LOW_SYNC_INTERVAL, NULL}, - {A_MAILBOX_ID, NULL}, - {A_MAILBOX_LOCATION, NULL}, - {A_MEMBER, "member"}, /* RFC2256 */ - {A_MEMORY, NULL}, - {A_MESSAGE_SERVER, NULL}, - {A_MESSAGE_ROUTING_GROUP, NULL}, - {A_MESSAGING_DATABASE_LOCATION, NULL}, - {A_MESSAGING_ROUTING_GROUP, NULL}, - {A_MESSAGING_SERVER, NULL}, - {A_MESSAGING_SERVER_TYPE, NULL}, - {A_MINIMUM_ACCOUNT_BALANCE, NULL}, - {A_NETWORK_ADDRESS, NULL}, - {A_NETWORK_ADDRESS_RESTRICTION, NULL}, - {A_NNS_DOMAIN, NULL}, - {A_NOTIFY, NULL}, - {A_OBITUARY, NULL}, - {A_ORGANIZATION_NAME, "o"}, /* RFC2256 */ - {A_OBJECT_CLASS, "objectClass"}, /* RFC2256 */ - {A_OPERATOR, NULL}, - {A_ORGANIZATIONAL_UNIT_NAME, "ou"}, /* RFC2256 */ - {A_OWNER, "owner"}, /* RFC2256 */ - {A_PAGE_DESCRIPTION_LANGUAGE, NULL}, - {A_PARTITION_CONTROL, NULL}, - {A_PARTITION_CREATION_TIME, NULL}, - {A_PARTITION_STATUS, NULL}, - {A_PASSWORD_ALLOW_CHANGE, NULL}, - {A_PASSWORD_EXPIRATION_INTERVAL, NULL}, - {A_PASSWORD_EXPIRATION_TIME, NULL}, - {A_PASSWORD_MANAGEMENT, NULL}, - {A_PASSWORD_MINIMUM_LENGTH, NULL}, - {A_PASSWORD_REQUIRED, NULL}, - {A_PASSWORD_UNIQUE_REQUIRED, NULL}, - {A_PASSWORDS_USED, NULL}, - {A_PATH, NULL}, - {A_PERMANENT_CONFIG_PARMS, NULL}, - {A_PHYSICAL_DELIVERY_OFFICE_NAME, "physicalDeliveryOfficeName"}, - {A_POSTAL_ADDRESS, "postalAddress"}, /* RFC2256 */ - {A_POSTAL_CODE, "postalCode"}, /* RFC2256 */ - {A_POSTAL_OFFICE_BOX, "postalOfficeBox"}, /* RFC2256 */ - {A_POSTMASTER, NULL}, - {A_PRINT_SERVER, NULL}, - {A_PRIVATE_KEY, NULL}, - {A_PRINTER, NULL}, - {A_PRINTER_CONFIGURATION, NULL}, - {A_PRINTER_CONTROL, NULL}, - {A_PRINT_JOB_CONFIGURATION, NULL}, - {A_PROFILE, NULL}, - {A_PROFILE_MEMBERSHIP, NULL}, - {A_PUBLIC_KEY, NULL}, - {A_QUEUE, NULL}, - {A_QUEUE_DIRECTORY, NULL}, - {A_RECEIVED_UP_TO, NULL}, - {A_REFERENCE, NULL}, - {A_REPLICA, NULL}, - {A_REPLICA_UP_TO, NULL}, - {A_RESOURCE, NULL}, - {A_REVISION, NULL}, - {A_ROLE_OCCUPANT, "roleOccupant"}, /* RFC2256 */ - {A_STATE_OR_PROVINCE_NAME, "st"}, /* RFC2256 */ - {A_STREET_ADDRESS, "street"}, /* RFC2256 */ - {A_SAP_NAME, NULL}, - {A_SECURITY_EQUALS, NULL}, - {A_SECURITY_FLAGS, NULL}, - {A_SEE_ALSO, "seeAlso"}, /* RFC2256 */ - {A_SERIAL_NUMBER, "serialNumber"}, /* RFC2256 */ - {A_SERVER, NULL}, - {A_SERVER_HOLDS, NULL}, - {A_STATUS, NULL}, - {A_SUPPORTED_CONNECTIONS, NULL}, - {A_SUPPORTED_GATEWAY, NULL}, - {A_SUPPORTED_SERVICES, NULL}, - {A_SUPPORTED_TYPEFACES, NULL}, - {A_SURNAME, "sn"}, /* RFC2256 */ - {A_IN_SYNC_UP_TO, NULL}, - {A_TELEPHONE_NUMBER, "telephoneNumber"}, /* RFC2256 */ - {A_TITLE, "title"}, /* RFC2256 */ - {A_TYPE_CREATOR_MAP, NULL}, - {A_UID, "uid"}, /* RFC1274 */ - {A_UNKNOWN, NULL}, - {A_UNKNOWN_BASE_CLASS, NULL}, - {A_USER, NULL}, - {A_VERSION, NULL}, - {A_VOLUME, NULL}, - {NULL, NULL} - }; - int i; - char *illegal = " :"; - char trans[512]; - - for (i = 0; trans_table[i][0]; i++) { - if (trans_table[i][1]) { - if (!AddTranslation(trans_table[i][0], trans_table[i][1])) { - return FALSE; - } - - if (!AddTranslation(trans_table[i][1], trans_table[i][0])) { - return FALSE; - } - } else { - if (!RemoveIllegalChars(trans, trans_table[i][0], illegal)) { - return FALSE; - } - - if (strcmp(trans_table[i][0], trans)) { - if (!AddTranslation(trans_table[i][0], trans)) { - return FALSE; - } - - if (!AddTranslation(trans, trans_table[i][0])) { - return FALSE; - } - } - } - } - - return TRUE; -} - -static char * -TranslateSchemaName(char *Name) -{ - char *name; - - if (Name) { - name = BongoHashtableGet(MdbLdap.TransTable, Name); - - if (name) { - return name; - } - } - - return Name; -} - -static char * -SchemaTransFunc(const char *Name, const char *Opt) -{ - char *name; - - name = BongoHashtableGet(MdbLdap.TransTable, Name); - - if (name) { - return strdup(name); - } - - return strdup(Name); -} - -/* Translate an attribute/data value structs to a hashtable of key/valarrays - NOTE: Use with LdapCreate() - */ -static BongoHashtable * -MdbAttrsToLdapAttrs(MDBValueStruct *Attribute, MDBValueStruct *Data) -{ - char *type, *value, **values; - MDBLDAPSchemaAttr *attr = NULL; - int inc = 12, last; - unsigned int i; - BongoHashtable *attrs; - - attrs = BongoHashtableCreateFull(128, (HashFunction)BongoStringHash, (CompareFunction)strcasecmp, NULL, free); - - if (attrs) { - for (i = 0; i < Attribute->Used; i++) { - value = (char *)(Data->Value[i]); - type = (char *)(Attribute->Value[i]); - - if (type[0] == 'S' || type[0] == 'D') { - type = TranslateSchemaName(type + 1); - attr = BongoHashtableGet(MdbLdap.AttrTable, type); - } - - if (!attr) { - type = TranslateSchemaName((char *)Attribute->Value[i]); - attr = BongoHashtableGet(MdbLdap.AttrTable, type); - } - - if (!attr) { - break; - } - - values = BongoHashtableGet(attrs, type); - - if (!values) { - values = NewValArray(inc); - - if (!values) { - break; - } - - if (BongoHashtablePut(attrs, type, values)) { - FreeValArray(values); - break; - } - } - - last = CountValArray(values); - - if (!(last % inc) && last) { - if (!ExpandValArray(&values, last + inc)) { - break; - } - } - - if (MDBLDAP_SYNTAX_DN(attr->syntax)) { - value = SafeMdbToLdap(value, (char *)Attribute->base); - - if (!value) { - break; - } - } - - values[last] = value; - } - - if (i != Attribute->Used) { - BongoHashtableDelete(attrs); - attrs = NULL; - } - } - - return attrs; -} - -/* end internal functions */ -/* begin external driver interface functions */ - -static BOOL -MDBLDAPGetServerInfo(unsigned char *ServerDN, unsigned char *ServerTree, - MDBValueStruct *V) -{ - if (ServerDN) { - strcpy((char *)ServerDN, MdbLdap.ServerDn); - } - - if (ServerTree) { - /* I'm not positive I can get away with this. But since the 'tree' in - MDB and eDir is very similar to what we're calling the Base DN I'm - hoping it won't cause any serious problems inside Bongo. */ - strcpy((char *)ServerTree, MdbLdap.MdbBaseDn); - } - - return TRUE; -} - -static char * -MDBLDAPGetBaseDN(MDBValueStruct *V) -{ - return(MdbLdap.MdbBaseDn); -} - -static MDBHandle -MDBLDAPAuthenticate(const unsigned char *Object, - const unsigned char *Password, - const unsigned char *Arguments) -{ - MDBLDAPContextStruct *context = NULL; - - context = CreateContext((char *)Object, (char *)Password); - - /* no handle lists right now.. - if (context) { - if (!HandleListAdd((MDBHandle) context)) { - if (context->binddn && context->passwd) { - free(context->binddn); - free(context->passwd); - } - - ldap_unbind_s(context->ldap); - DestroyContext(context); - context = NULL; - } - } - */ - - return (MDBHandle) context; -} - -static BOOL -MDBLDAPRelease(MDBHandle Handle) -{ - if (Handle) { - DestroyContext(Handle); - return TRUE; - } - - return FALSE; -} - -static MDBValueStruct * -MDBLDAPCreateValueStruct(MDBHandle Handle, const unsigned char *Context) -{ - MDBValueStruct *v; - - v = malloc(sizeof(MDBValueStruct)); - - if (v) { - memset(v, 0, sizeof(MDBValueStruct)); - v->duplicate = FALSE; - v->context = (MDBLDAPContextStruct *) Handle; - - if (Context) { - v->base = (unsigned char *)GetAbsoluteDn((const char *)Context, NULL); - - if (!v->base) { - free(v); - return NULL; - } - } else { - v->base = NULL; - } - - /* Get connections as needed using INIT_VS_LDAP macro - v->ldap = GetLdapConnection(Handle); - - if (!v->ldap) { - if (v->base) { - free(v->base); - } - - free(v); - v = NULL; - } - */ - } - - return v; -} - -static BOOL -MDBLDAPDestroyValueStruct(MDBValueStruct *V) -{ - BOOL result = TRUE; - - if (V->base && !V->duplicate) { - free(V->base); - } - - if (V->ldap) { - result = ReleaseLdapConnection(V->context, V->ldap); - } - - MDBLDAPFreeValues(V); - free(V); - - return result; -} - -static MDBValueStruct * -MDBLDAPShareContext(MDBValueStruct *V) -{ - MDBValueStruct *v; - - v = malloc(sizeof(MDBValueStruct)); - - if (v) { - memset(v, 0, sizeof(MDBValueStruct)); - v->duplicate = TRUE; - v->context = V->context; - v->base = V->base; - - /* Get connection as needed using INIT_VS_LDAP macro - v->ldap = GetLdapConnection(V->context); - - if (!v->ldap) { - free(v); - v = NULL; - } - */ - } - - return v; -} - -static BOOL -MDBLDAPSetValueStructContext(const unsigned char *Context, MDBValueStruct *V) -{ - char *mdbDn = NULL; - - if (Context) { - mdbDn = GetAbsoluteDn((char *)Context, (char *)V->base); - } else { - mdbDn = strdup(MdbLdap.MdbBaseDn); - } - - if (mdbDn) { - if (V->base && !V->duplicate) { - free(V->base); - } - - if (V->duplicate) { - V->duplicate = FALSE; - } - - V->base = (unsigned char *)mdbDn; - return TRUE; - } - - return FALSE; -} - -static MDBEnumStruct * -MDBLDAPCreateEnumStruct(MDBValueStruct *V) -{ - MDBEnumStruct *e = NULL; - - e = malloc(sizeof(MDBEnumStruct)); - - if (e) { - e->vals = NULL; - e->next = 0; - e->count = 0; - } - - return e; -} - -static BOOL -MDBLDAPDestroyEnumStruct(MDBEnumStruct *E, MDBValueStruct *V) -{ - if (E) { - if (E->vals) { - FreeValArray(E->vals); - free(E->vals); - } - - free(E); - return TRUE; - } - - return FALSE; -} - -BOOL -MDBLDAPFreeValues(MDBValueStruct * V) -{ - unsigned int i; - - if (V->allocated) { - for (i = 0; i < V->Used; i++) { - free(V->Value[i]); - } - - free(V->Value); - V->allocated = 0; - V->Value = NULL; - V->Used = 0; - } - - return TRUE; -} - -BOOL -MDBLDAPAddValue(const unsigned char *Value, MDBValueStruct *V) -{ - unsigned char **ptr; - - if (V->Used + 1 > V->allocated) { - ptr = (unsigned char **)realloc(V->Value, (V->allocated + VALUE_ALLOC_SIZE) * - sizeof(unsigned char *)); - - if (ptr) { - V->Value = ptr; - V->allocated += VALUE_ALLOC_SIZE; - } else { - if (V->allocated) { - MDBLDAPFreeValues(V); - } - return FALSE; - } - } - - V->Value[V->Used] = (unsigned char *)strdup((char *)Value); - - if (V->Value[V->Used]) { - V->Used++; - return TRUE; - } - - return FALSE; -} - -static BOOL -MDBLDAPFreeValue(unsigned long Index, MDBValueStruct * V) -{ - if (Index < V->Used) { - free(V->Value[Index]); - - if (Index < (V->Used - 1)) { - memmove(&V->Value[Index], &V->Value[Index + 1], - ((V->Used - 1) - Index) * sizeof(unsigned char *)); - } - - V->Used--; - - return TRUE; - } - - return FALSE; -} - -static long -MDBLDAPRead(const unsigned char *Object, const unsigned char *Attribute, - MDBValueStruct *V) -{ - char *ldapDn; - char **vals; - char *attribute; - long result = 0; - MDBLDAPSchemaAttr *attr; - - attribute = TranslateSchemaName((char *)Attribute); - ldapDn = SafeMdbToLdap((char *)Object, (char *)V->base); - - if (ldapDn) { - attr = BongoHashtableGet(MdbLdap.AttrTable, attribute); - - if (attr) { - INIT_VS_LDAP(V); - vals = LdapRead(ldapDn, attribute, V->ldap); - - if (vals) { - if (attr->syntax && MDBLDAP_SYNTAX_DN(attr->syntax)) { - result = TranslateValArrayToValueStruct(vals, V, - LdapToRelativeMdb, - (char *)V->base); - } else { - result = ValArrayToValueStruct(vals, V); - } - - FreeValArray(vals); - free(vals); - } - } - - free(ldapDn); - } - - return result; -} - -/** - * Since ldap_get_values() is the only way to retrieve attribute values, we - * have to do it the same as MDBLDAPRead(). - */ -static const unsigned char * -MDBLDAPReadEx(const unsigned char *Object, const unsigned char *Attribute, - MDBEnumStruct * E, MDBValueStruct *V) -{ - char *ldapDn; - char **vals; - char *attribute; - MDBLDAPSchemaAttr *attr; - - if (!E->vals) { - attribute = TranslateSchemaName((char *)Attribute); - ldapDn = SafeMdbToLdap((char *)Object, (char *)V->base); - - if (ldapDn) { - attr = BongoHashtableGet(MdbLdap.AttrTable, attribute); - - if (attr) { - INIT_VS_LDAP(V); - vals = LdapRead(ldapDn, attribute, V->ldap); - - if (vals) { - if (attr->syntax && MDBLDAP_SYNTAX_DN(attr->syntax)) { - E->vals = TranslateValArray(vals, LdapToRelativeMdb, - (char *)V->base); - FreeValArray(vals); - free(vals); - } else { - E->vals = vals; - } - - if (E->vals) { - E->count = CountValArray(E->vals); - E->next = 0; - } - } - } - - free(ldapDn); - } - } - - if (E->vals && E->next < E->count) { - E->next++; - return (unsigned char *)E->vals[E->next - 1]; - } - - /* should this be handled only during *Destroy? */ - if (E->vals) { - FreeValArray(E->vals); - free(E->vals); - E->vals = NULL; - } - - return NULL; -} - -static long -MDBLDAPReadDN(const unsigned char *Object, const unsigned char *Attribute, - MDBValueStruct *V) -{ - char *ldapDn; - char **vals; - char *attribute; - long result = 0; - MDBLDAPSchemaAttr *attr; - - attribute = TranslateSchemaName((char *)Attribute); - ldapDn = SafeMdbToLdap((char *)Object, (char *)V->base); - - if (ldapDn) { - attr = BongoHashtableGet(MdbLdap.AttrTable, attribute); - - if (attr) { - INIT_VS_LDAP(V); - vals = LdapRead(ldapDn, attribute, V->ldap); - - if (vals) { - if (attr->syntax && MDBLDAP_SYNTAX_DN(attr->syntax)) { - result = TranslateValArrayToValueStruct(vals, V, - LdapToRelativeMdb, - (char *)V->base); - } else { - result = ValArrayToValueStruct(vals, V); - } - - FreeValArray(vals); - free(vals); - } - } - - free(ldapDn); - } - - return result; -} - -static BOOL -MDBLDAPWrite(const unsigned char *Object, const unsigned char *Attribute, - MDBValueStruct *V) -{ - char **vals; - char *ldapDn; - char *attribute; - unsigned int count; - BOOL result = FALSE; - - attribute = TranslateSchemaName((char *)Attribute); - ldapDn = SafeMdbToLdap((char *)Object, (char *)V->base); - - if (ldapDn) { - if (V->Used) { - vals = NewValArray(V->Used); - - if (vals) { - count = ValueStructToValArray(V, vals); - - if (count) { - result = TRUE; - } - } - } else { - vals = NULL; - result = TRUE; - } - - if (result) { - INIT_VS_LDAP(V); - result = LdapWrite(ldapDn, attribute, vals, LDAP_MOD_REPLACE, - V->ldap); - } - - if (vals) { - FreeValArray(vals); - free(vals); - } - - free(ldapDn); - } - - return result; -} - -static BOOL -MDBLDAPWriteDN(const unsigned char *Object, const unsigned char *Attribute, - MDBValueStruct *V) -{ - char **vals; - char *ldapDn; - char *attribute; - unsigned int count; - BOOL result = FALSE; - - attribute = TranslateSchemaName((char *)Attribute); - /* should we check to see if Attribute is a DN type? */ - ldapDn = SafeMdbToLdap((char *)Object, (char *)V->base); - - if (ldapDn) { - vals = NewValArray(V->Used); - - if (vals) { - /* the docs say this value can be relative or absolute but since I - can't translate a relative MDB DN into an LDAP DN, I'm going to - force them all to be absolute. */ - count = TranslateValueStructToValArray(V, vals, SafeMdbToLdap, - (char *)V->base); - - if (count) { - INIT_VS_LDAP(V); - result = LdapWrite(ldapDn, attribute, vals, LDAP_MOD_REPLACE, - V->ldap); - } - - FreeValArray(vals); - free(vals); - } - - free(ldapDn); - } - - return result; -} - -static BOOL -MDBLDAPClear(const unsigned char *Object, const unsigned char *Attribute, - MDBValueStruct *V) -{ - char *ldapDn; - char *attribute; - BOOL result = FALSE; - - attribute = TranslateSchemaName((char *)Attribute); - ldapDn = SafeMdbToLdap((char *)Object, (char *)V->base); - - if (ldapDn) { - INIT_VS_LDAP(V); - result = LdapWrite(ldapDn, attribute, NULL, LDAP_MOD_DELETE, - V->ldap); - free(ldapDn); - } - - return result; -} - -static BOOL -MDBLDAPAdd(const unsigned char *Object, const unsigned char *Attribute, - const unsigned char *Value, MDBValueStruct *V) -{ - char *vals[2] = {(char *)Value, NULL}; - char *ldapDn; - char *attribute; - BOOL result = FALSE; - - attribute = TranslateSchemaName((char *)Attribute); - ldapDn = SafeMdbToLdap((char *)Object, (char *)V->base); - - if (ldapDn) { - INIT_VS_LDAP(V); - result = LdapWrite(ldapDn, attribute, vals, LDAP_MOD_ADD, - V->ldap); - free(ldapDn); - } - - return result; -} - -static BOOL -MDBLDAPAddDN(const unsigned char *Object, const unsigned char *Attribute, - const unsigned char *Value, MDBValueStruct *V) -{ - char *vals[2] = {NULL, NULL}; - char *ldapDn; - char *attribute; - BOOL result = FALSE; - - attribute = TranslateSchemaName((char *)Attribute); - ldapDn = SafeMdbToLdap((char *)Object, (char *)V->base); - - if (ldapDn) { - vals[0] = SafeMdbToLdap((char *)Value, NULL); - - if (vals[0]) { - INIT_VS_LDAP(V); - result = LdapWrite(ldapDn, attribute, vals, LDAP_MOD_ADD, - V->ldap); - free(vals[0]); - } - - free(ldapDn); - } - - return result; -} - -static BOOL -MDBLDAPRemove(const unsigned char *Object, const unsigned char *Attribute, - const unsigned char *Value, MDBValueStruct *V) -{ - char *vals[2] = {(char *)Value, NULL}; - char *ldapDn; - char *attribute; - BOOL result = FALSE; - - attribute = TranslateSchemaName((char *)Attribute); - ldapDn = SafeMdbToLdap((char *)Object, (char *)V->base); - - if (ldapDn) { - INIT_VS_LDAP(V); - result = LdapWrite(ldapDn, attribute, vals, LDAP_MOD_DELETE, - V->ldap); - free(ldapDn); - } - - return result; -} - -static BOOL -MDBLDAPRemoveDN(const unsigned char *Object, const unsigned char *Attribute, - const unsigned char *Value, MDBValueStruct *V) -{ - char *vals[2] = {NULL, NULL}; - char *ldapDn; - char *attribute; - BOOL result = FALSE; - - attribute = TranslateSchemaName((char *)Attribute); - ldapDn = SafeMdbToLdap((char *)Object, (char *)V->base); - - if (ldapDn) { - vals[0] = SafeMdbToLdap((char *)Value, NULL); - - if (vals[0]) { - INIT_VS_LDAP(V); - result = LdapWrite(ldapDn, attribute, vals, LDAP_MOD_DELETE, - V->ldap); - free(vals[0]); - } - - free(ldapDn); - } - - return result; -} - -static BOOL -MDBLDAPIsObject(const unsigned char *Object, MDBValueStruct *V) -{ - char *ldapDn; - LDAPMessage *res; - char *attrs[2] = {"dn", NULL}; - int err; - BOOL result = FALSE; - - ldapDn = SafeMdbToLdap((char *)Object, (char *)V->base); - - if (ldapDn) { - INIT_VS_LDAP(V); - - if (V->ldap) { - err = ldap_search_s(V->ldap, ldapDn, LDAP_SCOPE_BASE, - "(objectClass=*)", attrs, 0, &res); - - if (err == LDAP_SUCCESS) { - ldap_msgfree(res); - result = TRUE; - } else { - Log(LOG_ERROR, "ldap_search_s() failed: %s", - ldap_err2string(err)); - Log(LOG_ERROR, "dn: %s", ldapDn); - } - } - - free(ldapDn); - } - - return result; -} - -static BOOL -MDBLDAPGetObjectDetailsEx(const unsigned char *Object, MDBValueStruct *Types, - unsigned char *RDN, unsigned char *DN, - MDBValueStruct *V) -{ - BOOL result = FALSE; - char *absDn; - char *ldapDn; - char **classes; - char *absDnReal; - char *ldapDnReal; - char **classesReal; - char **vals; - - absDn = GetAbsoluteDn((char *)Object, (char *)V->base); - if (absDn) { - ldapDn = MdbToLdap(absDn); - if (ldapDn) { - INIT_VS_LDAP(V); - classes = LdapRead(ldapDn, "objectClass", V->ldap); - if (classes) { - char **objectClass = &classes[0]; - if (*objectClass) { - result = TRUE; - do { - if (strcmp(*objectClass, "alias")) { - objectClass++; - continue; - } - - /* we have an alias, we need to find the real object */ - vals = LdapRead(ldapDn, "aliasedObjectName", V->ldap); - if (vals) { - if (vals[0][0]) { - ldapDnReal = strdup(vals[0]); - if (ldapDnReal) { - absDnReal = LdapToMdb(ldapDnReal); - if(absDnReal) { - classesReal = LdapRead(ldapDnReal, "objectClass", V->ldap); - if (classesReal) { - /* the aliased object is in good shape; switch objects */ - FreeValArray(classes); - free(classes); - classes = classesReal; - free(absDn); - absDn = absDnReal; - free(ldapDn); - ldapDn = ldapDnReal; - break; - } - free(absDnReal); - } - free(ldapDnReal); - } - } - FreeValArray(vals); - free(vals); - } - result = FALSE; - break; - } while(*objectClass != NULL); - - if (result) { - /* we have everything we need (ldapDn, absDn, and classes) to fulfill the request. */ - - if (DN) { - strcpy((char *)DN, absDn); - } - - if (Types) { - TranslateValArrayToValueStruct(classes, Types, - SchemaTransFunc, - NULL); - } - - if (RDN) { - char *relDn = GetRelativeDn((char *)Object, (char *)V->base); - - if (relDn) { - strcpy((char *)RDN, relDn); - free(relDn); - } else { - result = FALSE; - } - } - } - } - - FreeValArray(classes); - free(classes); - } - free(ldapDn); - } - free(absDn); - } - return(result); -} - -static BOOL -MDBLDAPGetObjectDetails(const unsigned char *Object, unsigned char *Type, - unsigned char *RDN, unsigned char *DN, - MDBValueStruct *V) -{ - BOOL result = FALSE; - MDBValueStruct *types = MDBLDAPShareContext(V); - - if (types) { - result = MDBLDAPGetObjectDetailsEx(Object, types, RDN, DN, V); - - if (result && Type && types->Used > 0) { - strcpy((char *) Type, (char *) types->Value[0]); - } - - MDBLDAPDestroyValueStruct(types); - } - - return result; -} - -static BOOL -MDBLDAPVerifyPassword(const unsigned char *Object, - const unsigned char *Password, MDBValueStruct *V) -{ - char *ldapDn; - BOOL result = FALSE; - - ldapDn = SafeMdbToLdap((char *)Object, (char *)V->base); - - if (ldapDn) { - result = LdapVerify(ldapDn, (char *)Password); - free(ldapDn); - } - - return result; -} - -static BOOL -MDBLDAPChangePassword(const unsigned char *Object, - const unsigned char *OldPassword, - const unsigned char *NewPassword, MDBValueStruct *V) -{ - char *ldapDn; - BOOL result = FALSE; - - ldapDn = SafeMdbToLdap((char *)Object, (char *)V->base); - - if (ldapDn) { - INIT_VS_LDAP(V); - result = LdapPassword(ldapDn, (char *)OldPassword, (char *)NewPassword, V->ldap); - free(ldapDn); - } - - return result; -} - -static BOOL -MDBLDAPChangePasswordEx(const unsigned char *Object, - const unsigned char *OldPassword, - const unsigned char *NewPassword, MDBValueStruct *V) -{ - char *ldapDn; - BOOL result = FALSE; - char *oldPassword = ""; - - ldapDn = SafeMdbToLdap((char *)Object, (char *)V->base); - - if (ldapDn) { - if (OldPassword) { - oldPassword = (char *)OldPassword; - } - - INIT_VS_LDAP(V); - result = LdapPassword(ldapDn, oldPassword, (char *)NewPassword, V->ldap); - free(ldapDn); - } - - return result; -} - -static long -MDBLDAPEnumerateObjects(const unsigned char *Container, - const unsigned char *Type, - const unsigned char *Pattern, MDBValueStruct *V) -{ - char *ldapDn; - char **vals; - char *filter; - char *type; - long result = 0; - - type = TranslateSchemaName((char *)Type); - ldapDn = SafeMdbToLdap((char *)Container, (char *)V->base); - - if (ldapDn) { - filter = LdapFilter(type, (char *)Pattern); - - if (filter) { - INIT_VS_LDAP(V); - vals = LdapSearch(ldapDn, filter, LDAP_SCOPE_ONELEVEL, -1, V->ldap); - - if (vals) { - result = TranslateValArrayToValueStruct(vals, V, - LdapToRelativeMdb, - (char *)V->base); - FreeValArray(vals); - free(vals); - } - - free(filter); - } - - free(ldapDn); - } - - return result; -} - -static const unsigned char * -MDBLDAPEnumerateObjectsEx(const unsigned char *Container, - const unsigned char *Type, - const unsigned char *Pattern, unsigned long Flags, - MDBEnumStruct *E, MDBValueStruct *V) -{ - char *ldapDn; - char **vals; - char *filter; - char *type; - - if (!E->vals) { - type = TranslateSchemaName((char *)Type); - ldapDn = SafeMdbToLdap((char *)Container, (char *)V->base); - - if (ldapDn) { - filter = LdapFilter(type, (char *)Pattern); - - if (filter) { - INIT_VS_LDAP(V); - vals = LdapSearch(ldapDn, filter, LDAP_SCOPE_ONELEVEL, -1, V->ldap); - - if (vals) { - E->vals = TranslateValArray(vals, LdapToAbsoluteMdb, - (char *)V->base); - if (E->vals) { - E->count = CountValArray(E->vals); - E->next = 0; - } - - FreeValArray(vals); - free(vals); - } - - free(filter); - } - - free(ldapDn); - } - } - - if (E->vals && E->next < E->count) { - E->next++; - return (unsigned char *)E->vals[E->next - 1]; - } - - /* should this be handled only during *Destroy? */ - if (E->vals) { - FreeValArray(E->vals); - free(E->vals); - E->vals = NULL; - } - - return NULL; -} - -static const unsigned char * -MDBLDAPEnumerateAttributesEx(const unsigned char *Object, MDBEnumStruct *E, - MDBValueStruct *V) -{ - char *ldapDn; - char **vals; - - if (!E->vals) { - ldapDn = SafeMdbToLdap((char *)Object, (char *)V->base); - - if (ldapDn) { - INIT_VS_LDAP(V); - vals = LdapAttributes(ldapDn, V->ldap); - - if (vals) { - E->vals = TranslateValArray(vals, SchemaTransFunc, NULL); - - if (E->vals) { - E->count = CountValArray(E->vals); - E->next = 0; - } - - FreeValArray(vals); - free(vals); - } - - free(ldapDn); - } - } - - if (E->vals && E->next < E->count) { - E->next++; - return (unsigned char *)E->vals[E->next - 1]; - } - - /* should this be handled only during *Destroy? */ - if (E->vals) { - FreeValArray(E->vals); - free(E->vals); - E->vals = NULL; - } - - return NULL; -} - -static BOOL -MDBLDAPCreateAlias(const unsigned char *Alias, - const unsigned char *RealObject, MDBValueStruct *V) -{ - BOOL result = FALSE; - BongoHashtable *attrs; - char *classes[3]; - char *values[2]; - char *ldapRealDn; - char *ldapAliasDn; - char *ptr; - - /* get the ldap dn for the real object */ - ldapRealDn = SafeMdbToLdap((char *)RealObject, (char *)V->base); - if (ldapRealDn) { - /* generate the ldap dn for the alias object*/ - /* we can get the type from the real object dn */ - - ptr = strchr(ldapRealDn, '='); - if (ptr) { - *ptr = '\0'; - ldapAliasDn = NewSafeMdbToLdap((char *)Alias, ldapRealDn, (char *)V->base); - *ptr = '='; - if (ldapAliasDn) { - attrs = BongoHashtableCreate(128,(HashFunction)BongoStringHash, (CompareFunction)strcasecmp); - if (attrs) { - values[0] = ldapRealDn; - values[1] = NULL; - if (!BongoHashtablePut(attrs, "aliasedObjectName", values)) { - /* set up classes */ - classes[0] = "alias"; - classes[1] = "extensibleObject"; - classes[2] = NULL; - - INIT_VS_LDAP(V); - result = LdapCreate(ldapAliasDn, classes, attrs, V->ldap); - } - BongoHashtableDelete(attrs); - } - free(ldapAliasDn); - } - } - free(ldapRealDn); - } - return(result); -} - -static BOOL -MDBLDAPCreateObject(const unsigned char *Object, const unsigned char *Class, - MDBValueStruct *Attribute, MDBValueStruct *Data, - MDBValueStruct *V) -{ - MDBLDAPSchemaClass *class; - char *classes[2]; - char *ldapDn = NULL; - BongoHashtable *attrs; - BOOL result = FALSE; - - classes[0] = TranslateSchemaName((char *)Class); - classes[1] = NULL; - - class = BongoHashtableGet(MdbLdap.ClassTable, classes[0]); - - /* make a new ldap dn for the object */ - if (class) { - ldapDn = NewSafeMdbToLdap((char *)Object, class->naming, (char *)V->base); - } - - if (ldapDn) { - attrs = MdbAttrsToLdapAttrs(Attribute, Data); - - if (attrs) { - INIT_VS_LDAP(V); - result = LdapCreate(ldapDn, classes, attrs, V->ldap); - BongoHashtableDelete(attrs); - } - - free(ldapDn); - } - - return result; -} - -static BOOL -MDBLDAPDeleteObject(const unsigned char *Object, BOOL Recursive, - MDBValueStruct *V) -{ - char *ldapDn; - char **vals; - char *filter; - int i; - int err = 0; - BOOL result = FALSE; - - ldapDn = SafeMdbToLdap((char *)Object, (char *)V->base); - - if (ldapDn) { - if (Recursive) { - filter = LdapFilter(NULL, NULL); - - if (filter) { - err = 0; - INIT_VS_LDAP(V); - vals = LdapSearch(ldapDn, filter, LDAP_SCOPE_ONELEVEL, -1, V->ldap); - - if (vals) { - for (i = 0; !err && vals[i]; i++) { - if (!MDBLDAPDeleteObject((unsigned char *)vals[i], TRUE, V)) { - err = 1; - } - } - - FreeValArray(vals); - free(vals); - } - - free(filter); - } else { - err = 1; - } - } - - if (!err) { - INIT_VS_LDAP(V); - - if (V->ldap) { - err = ldap_delete_s(V->ldap, ldapDn); - - if (err == LDAP_SUCCESS) { - result = TRUE; - } else { - Log(LOG_ERROR, "ldap_delete_s() failed: %s", - ldap_err2string(err)); - Log(LOG_ERROR, "dn: %s", ldapDn); - } - } - } - - free(ldapDn); - } - - return result; -} - -static BOOL -MDBLDAPRenameObject(const unsigned char *ObjectOld, - const unsigned char *ObjectNew, MDBValueStruct *V) -{ - char *baseOld; - char *baseNew; - char *nameOld; - char *nameNew; - char *newSuperior = NULL; - char *ldapDn; - char *naming; - char *newRdn; - char *ptr; - int err = 0; - BOOL result = FALSE; - - baseOld = strdup((char *)ObjectOld); - - if (baseOld) { - nameOld = strrchr(baseOld, '\\'); - *nameOld++ = '\0'; - - baseNew = strdup((char *)ObjectNew); - - if (baseNew) { - nameNew = strrchr(baseNew, '\\'); - *nameNew++ = '\0'; - - if (strcmp(baseOld, baseNew)) { - newSuperior = SafeMdbToLdap(baseNew, (char *)V->base); - - if (!newSuperior) { - err = 1; - } - } - - if (!err) { - ldapDn = SafeMdbToLdap((char *)ObjectOld, (char *)V->base); - - if (ldapDn) { - naming = strdup(ldapDn); - - if (naming) { - ptr = strchr(naming, '='); - *ptr++ = '\0'; - - newRdn = malloc(strlen(naming) + strlen(nameNew) + 2); - - if (newRdn) { - INIT_VS_LDAP(V); - - if (V->ldap) { - sprintf(newRdn, "%s=%s", naming, nameNew); - err = ldap_rename_s(V->ldap, ldapDn, newRdn, - newSuperior, TRUE, NULL, NULL); - - if (err == LDAP_SUCCESS) { - result = TRUE; - } else { - Log(LOG_ERROR, - "ldap_rename_s() failed: %s", - ldap_err2string(err)); - Log(LOG_ERROR, "dn: %s", ldapDn); - - if (newSuperior) { - Log(LOG_ERROR, "new dn: %s,%s", newRdn, - newSuperior); - } else { - Log(LOG_ERROR, "new rdn: %s", newRdn); - } - } - } - - free(newRdn); - } - - free(naming); - } - - free(ldapDn); - } - } - - if (newSuperior) { - free(newSuperior); - } - - free(baseNew); - } - - free(baseOld); - } - - return result; -} - -/* Most of the following functions cannot be easily implemented in LDAP */ - -static BOOL -MDBLDAPDefineAttribute(const unsigned char *Attribute, - const unsigned char *ASN1, unsigned long Type, - BOOL SingleValue, BOOL ImmediateSync, BOOL Public, MDBValueStruct *V) -{ - Log(LOG_ERROR, - "Function MDBDefineAttribute() is not supported by MBDLDAP driver."); - return FALSE; -} - -static BOOL -MDBLDAPUndefineAttribute(const unsigned char *Attribute, MDBValueStruct *V) -{ - Log(LOG_ERROR, - "Function MDBUndefineAttribute() is not supported by MBDLDAP driver."); - return FALSE; -} - -static BOOL -MDBLDAPDefineClass(const unsigned char *Class, const unsigned char *ASN1, - BOOL Container, MDBValueStruct *Superclass, - MDBValueStruct *Containment, MDBValueStruct *Naming, - MDBValueStruct *Mandatory, MDBValueStruct *Optional, - MDBValueStruct *V) -{ - Log(LOG_ERROR, - "Function MDBDefineClass() is not supported by MBDLDAP driver."); - return FALSE; -} - -static BOOL -MDBLDAPAddAttribute(const unsigned char *Attribute, const unsigned char *Class, - MDBValueStruct *V) -{ - Log(LOG_ERROR, - "Function MDBAddAttribute() is not supported by MBDLDAP driver."); - return FALSE; -} - -static BOOL -MDBLDAPUndefineClass(const unsigned char *Class, MDBValueStruct *V) -{ - Log(LOG_ERROR, - "Function MDBUndefineClass() is not supported by MBDLDAP driver."); - return FALSE; -} - -static BOOL -MDBLDAPListContainableClasses(const unsigned char *Object, MDBValueStruct *V) -{ - Log(LOG_ERROR, - "Function MDBListContainableClasses() is not supported by MBDLDAP driver."); - return FALSE; -} - -static const unsigned char * -MDBLDAPListContainableClassesEx(const unsigned char *Container, - MDBEnumStruct *E, MDBValueStruct *V) -{ - Log(LOG_ERROR, - "Function MDBListContainableClassesEx() is not supported by MBDLDAP driver."); - return NULL; -} - -static BOOL -MDBLDAPGrantObjectRights(const unsigned char *Object, - const unsigned char *TrusteeDN, BOOL Read, BOOL Write, - BOOL Delete, BOOL Rename, BOOL Admin, - MDBValueStruct *V) -{ - Log(LOG_ERROR, - "Function MDBGrantObjectRights() is not supported by MBDLDAP driver."); - return FALSE; -} - -static BOOL -MDBLDAPGrantAttributeRights(const unsigned char *Object, - const unsigned char *Attribute, - const unsigned char *TrusteeDN, BOOL Read, - BOOL Write, BOOL Admin, MDBValueStruct *V) -{ - Log(LOG_ERROR, - "Function MDBGrantAttributeRights() is not supported by MBDLDAP driver."); - return FALSE; -} - -/* Undocumented functions */ - -static BOOL -MDBLDAPAddAddressRestriction(const unsigned char *Object, - const unsigned char *Server, MDBValueStruct *V) -{ - Log(LOG_ERROR, - "Undocumented function MDBAddAddressRestriction() requested."); - return FALSE; -} - -static BOOL -MDBLDAPWriteTyped(const unsigned char *Object, const unsigned char *Attribute, - const int AttrType, MDBValueStruct *V) -{ - Log(LOG_ERROR, - "Undocumented function MDBWriteTyped() requested."); - return FALSE; -} - -static BOOL -MDBLDAPFindObjects(const unsigned char *container, - MDBValueStruct *types, - const unsigned char *pattern, - MDBValueStruct *attributes, - int depth, - int max, - MDBValueStruct *V) -{ - char *ldapDn; - char **vals; - char *filter; - char *type; - long result = FALSE; - - ldapDn = SafeMdbToLdap((char *)container, (char *)V->base); - - if (ldapDn) { - filter = LdapSearchFilter(types, (char *)pattern, attributes); - - if (filter) { - INIT_VS_LDAP(V); - vals = LdapSearch(ldapDn, filter, depth, -1, V->ldap); - - if (vals) { - result = TranslateValArrayToValueStruct(vals, V, - LdapToAbsoluteMdb, - (char *)V->base); - FreeValArray(vals); - free(vals); - } - - free(filter); - } - - free(ldapDn); - } - - return result; -} - -#if 0 -static void -PathPrint(void *key, void *value, void *data) -{ - printf("%s: %s\n", key, value); -} -#endif - -EXPORT BOOL -MDBLDAPInit(MDBDriverInitStruct *Init) -{ - int version = LDAP_VERSION3; - char *mdbDn; - char *ldapDn; - BOOL result = TRUE; - char *param; - char *ptr; - char *arg; - char **vals; - - LogStartup(); - - MdbLdap.args = NULL; - MdbLdap.ServerTree[0] = '\0'; - MdbLdap.ServerDn[0] = '\0'; - MdbLdap.MdbBaseDn = NULL; - MdbLdap.LdapBaseDn = NULL; - MdbLdap.LdapSchemaDn = NULL; - MdbLdap.LdapBindDn = NULL; - MdbLdap.LdapBindPasswd = NULL; - MdbLdap.LdapHostAddress = "localhost"; - MdbLdap.LdapHostPort = 389; - MdbLdap.LdapTls = 0; - MdbLdap.LdapMinConnections = MDBLDAP_MIN_CONNECTIONS; - MdbLdap.LdapMaxConnections = MDBLDAP_MAX_CONNECTIONS; - MdbLdap.Ldap = NULL; - MdbLdap.PathTable = NULL; - MdbLdap.AttrTable = NULL; - MdbLdap.ClassTable = NULL; - MdbLdap.TransTable = NULL; - - /* Parse configuration arguments */ - if (Init->Arguments) { - MdbLdap.args = strdup((char *)(Init->Arguments)); - - if (MdbLdap.args) { - param = strtok_r(MdbLdap.args, "=", &ptr); - - while (param) { - arg = strtok_r(NULL, "\"", &ptr); - - if (!strcasecmp(param, "binddn")) { - MdbLdap.LdapBindDn = arg; - } else if (!strcasecmp(param, "password")) { - MdbLdap.LdapBindPasswd = arg; - } else if (!strcasecmp(param, "host")) { - MdbLdap.LdapHostAddress = arg; - } else if (!strcasecmp(param, "port")) { - MdbLdap.LdapHostPort = atoi(arg); - } else if (!strcasecmp(param, "basedn")) { - MdbLdap.LdapBaseDn = arg; - } else if (!strcasecmp(param, "poolmin")) { - MdbLdap.LdapMinConnections = atoi(arg); - } else if (!strcasecmp(param, "poolmax")) { - MdbLdap.LdapMaxConnections = atoi(arg); - } else if (!strcasecmp(param, "tls")) { - MdbLdap.LdapTls = atoi(arg); - } - - param = strtok_r(NULL, "=,", &ptr); - } - } else { - result = FALSE; - } - } - - if (result) { - if (MdbLdap.LdapBaseDn) { - /* Set global LDAP options */ - ldap_set_option(NULL, LDAP_OPT_PROTOCOL_VERSION, &version); - MdbLdap.Ldap = InitLdapConnection(MdbLdap.LdapBindDn, - MdbLdap.LdapBindPasswd, - DriverRebindProc, NULL); - if (MdbLdap.Ldap) { - XplMutexInit(MdbLdap.LdapMutex); - } else { - sprintf((char *)(Init->Error), "Could not initialize LDAP connection"); - result = FALSE; - } - - /* - MdbLdap.Ldap = ldap_init(MdbLdap.LdapHostAddress, - MdbLdap.LdapHostPort); - - if (MdbLdap.Ldap) { - err = ldap_start_tls_s(MdbLdap.Ldap, NULL, NULL); - - if (err == LDAP_SUCCESS) { - err = ldap_simple_bind_s(MdbLdap.Ldap, MdbLdap.LdapBindDn, - MdbLdap.LdapBindPasswd); - - if (err == LDAP_SUCCESS) { - ldap_set_rebind_proc(MdbLdap.Ldap, DriverRebindProc, NULL); - XplMutexInit(MdbLdap.LdapMutex); - } else { - Log(LOG_ERROR, "ldap_simple_bind_s() failed: %s", - ldap_err2string(err)); - Log(LOG_ERROR, "dn: %s", MdbLdap.LdapBindDn); - result = FALSE; - MdbLdap.Ldap = NULL; - } - } else { - Log(LOG_ERROR, "ldap_start_tls_s() failed: %s", - ldap_err2string(err)); - result = FALSE; - MdbLdap.Ldap = NULL; - } - } else { - Log(LOG_ERROR, "ldap_init() failed: %s", - ldap_err2string(errno)); - Log(LOG_ERROR, "host: %s:%d", MdbLdap.LdapHostAddress, - MdbLdap.LdapHostPort); - result = FALSE; - } - */ - } else { - char *err = "Parameter 'baseDn' required for MDB LDAP Init"; - sprintf((char *)(Init->Error), err); - Log(LOG_ERROR, err); - result = FALSE; - } - } - - if (result) { - MdbLdap.MdbBaseDn = LdapToMdb(MdbLdap.LdapBaseDn); - - if (!MdbLdap.MdbBaseDn) { - result = FALSE; - } - } - - /* Initialize MDB -> LDAP DN cache */ - if (result) { - MdbLdap.PathTable = BongoHashtableCreateFull(MDBLDAP_DEFAULT_CACHE_SIZE, - (HashFunction)BongoStringHash, (CompareFunction)strcasecmp, - free, free); - - if (MdbLdap.PathTable) { - XplRWLockInit(&(MdbLdap.PathLock)); - - /* initialize the cache with the base DN */ - mdbDn = strdup(MdbLdap.MdbBaseDn); - - if (mdbDn) { - ldapDn = strdup(MdbLdap.LdapBaseDn); - - if (ldapDn) { - XplRWWriteLockAcquire(&(MdbLdap.PathLock)); - - if (BongoHashtablePut(MdbLdap.PathTable, mdbDn, ldapDn)) { - free(mdbDn); - free(ldapDn); - result = FALSE; - } - - XplRWWriteLockRelease(&(MdbLdap.PathLock)); - } else { - free(mdbDn); - result = FALSE; - } - } else { - result = FALSE; - } - } else { - result = FALSE; - } - } - - /* Initialize supported LDAP extensions cache */ - if (result) { - MdbLdap.ExtTable = BongoHashtableCreateFull(MDBLDAP_DEFAULT_CACHE_SIZE, - (HashFunction)BongoStringHash, (CompareFunction)strcasecmp, - free, NULL); - - if (MdbLdap.ExtTable) { - if (!LoadExtensions()) { - result = FALSE; - } - } else { - result = FALSE; - } - } - - if (result) { - XplMutexLock(MdbLdap.LdapMutex); - vals = LdapRead("", "subschemaSubentry", MdbLdap.Ldap); - XplMutexUnlock(MdbLdap.LdapMutex); - - if (vals) { - if (vals[0]) { - MdbLdap.LdapSchemaDn = strdup(vals[0]); - } - - if (!MdbLdap.LdapSchemaDn) { - result = FALSE; - } - - FreeValArray(vals); - free(vals); - } else { - Log(LOG_ERROR, "Unable to read subschemaSubentry attribute"); - result = FALSE; - } - } - - /* Initialize attributes schema cache */ - if (result) { - MdbLdap.AttrTable = BongoHashtableCreateFull(MDBLDAP_DEFAULT_CACHE_SIZE, - (HashFunction)BongoStringHash, (CompareFunction)strcasecmp, - NULL, AttrDel); - - if (MdbLdap.AttrTable) { - if (!LoadSchemaAttrs()) { - result = FALSE; - } - } else { - result = FALSE; - } - } - - /* Initialize the class schema cache */ - if (result) { - MdbLdap.ClassTable = BongoHashtableCreateFull( - MDBLDAP_DEFAULT_CACHE_SIZE, - (HashFunction)BongoStringHash, (CompareFunction)strcasecmp, - NULL, ClassDel); - - if (MdbLdap.ClassTable) { - if (!LoadSchemaClasses()) { - result = FALSE; - } - } else { - result = FALSE; - } - } - - /* Initialize the MDB/LDAP schema name translation cache */ - if (result) { - MdbLdap.TransTable = BongoHashtableCreateFull( - MDBLDAP_DEFAULT_CACHE_SIZE, - (HashFunction)BongoStringHash, (CompareFunction)strcasecmp, - free, free); - - if (MdbLdap.TransTable) { - if (!InitTranslations()) { - result = FALSE; - } - } else { - result = FALSE; - } - } - - if (result) { - Init->Interface.MDBAdd = MDBLDAPAdd; - Init->Interface.MDBAddAddressRestriction = MDBLDAPAddAddressRestriction; - Init->Interface.MDBAddAttribute = MDBLDAPAddAttribute; - Init->Interface.MDBAddDN = MDBLDAPAddDN; - Init->Interface.MDBAddValue = MDBLDAPAddValue; - Init->Interface.MDBAuthenticate = MDBLDAPAuthenticate; - Init->Interface.MDBChangePassword = MDBLDAPChangePassword; - Init->Interface.MDBChangePasswordEx = MDBLDAPChangePasswordEx; - Init->Interface.MDBClear = MDBLDAPClear; - Init->Interface.MDBCreateAlias = MDBLDAPCreateAlias; - Init->Interface.MDBCreateEnumStruct = MDBLDAPCreateEnumStruct; - Init->Interface.MDBCreateObject = MDBLDAPCreateObject; - Init->Interface.MDBCreateValueStruct = MDBLDAPCreateValueStruct; - Init->Interface.MDBDefineAttribute = MDBLDAPDefineAttribute; - Init->Interface.MDBDefineClass = MDBLDAPDefineClass; - Init->Interface.MDBDeleteObject = MDBLDAPDeleteObject; - Init->Interface.MDBDestroyEnumStruct = MDBLDAPDestroyEnumStruct; - Init->Interface.MDBDestroyValueStruct = MDBLDAPDestroyValueStruct; - Init->Interface.MDBEnumerateAttributesEx = MDBLDAPEnumerateAttributesEx; - Init->Interface.MDBEnumerateObjects = MDBLDAPEnumerateObjects; - Init->Interface.MDBEnumerateObjectsEx = MDBLDAPEnumerateObjectsEx; - Init->Interface.MDBFreeValue = MDBLDAPFreeValue; - Init->Interface.MDBFreeValues = MDBLDAPFreeValues; - Init->Interface.MDBGetBaseDN = MDBLDAPGetBaseDN; - Init->Interface.MDBGetObjectDetails = MDBLDAPGetObjectDetails; - Init->Interface.MDBGetObjectDetailsEx = MDBLDAPGetObjectDetailsEx; - Init->Interface.MDBGetServerInfo = MDBLDAPGetServerInfo; - Init->Interface.MDBGrantAttributeRights = MDBLDAPGrantAttributeRights; - Init->Interface.MDBGrantObjectRights = MDBLDAPGrantObjectRights; - Init->Interface.MDBIsObject = MDBLDAPIsObject; - Init->Interface.MDBListContainableClasses = MDBLDAPListContainableClasses; - Init->Interface.MDBListContainableClassesEx = MDBLDAPListContainableClassesEx; - Init->Interface.MDBRead = MDBLDAPRead; - Init->Interface.MDBReadDN = MDBLDAPReadDN; - Init->Interface.MDBReadEx = MDBLDAPReadEx; - Init->Interface.MDBRelease = MDBLDAPRelease; - Init->Interface.MDBRemove = MDBLDAPRemove; - Init->Interface.MDBRemoveDN = MDBLDAPRemoveDN; - Init->Interface.MDBRenameObject = MDBLDAPRenameObject; - Init->Interface.MDBSetValueStructContext = MDBLDAPSetValueStructContext; - Init->Interface.MDBShareContext = MDBLDAPShareContext; - Init->Interface.MDBUndefineAttribute = MDBLDAPUndefineAttribute; - Init->Interface.MDBUndefineClass = MDBLDAPUndefineClass; - Init->Interface.MDBVerifyPassword = MDBLDAPVerifyPassword; - Init->Interface.MDBVerifyPasswordEx = MDBLDAPVerifyPassword; - Init->Interface.MDBWrite = MDBLDAPWrite; - Init->Interface.MDBWriteDN = MDBLDAPWriteDN; - Init->Interface.MDBWriteTyped = MDBLDAPWriteTyped; - Init->Interface.MDBFindObjects = MDBLDAPFindObjects; - } else { - MDBLDAPShutdown(); - } - - return result; -} - -EXPORT void -MDBLDAPShutdown(void) -{ - int err; - - if (MdbLdap.Ldap) { - err = ldap_unbind(MdbLdap.Ldap); - MdbLdap.Ldap = NULL; - - if (err != LDAP_SUCCESS) { - Log(LOG_ERROR, "ldap_unbind() failed: %s", ldap_err2string(err)); - } - - XplMutexDestroy(MdbLdap.LdapMutex); - } - - if (MdbLdap.TransTable) { - BongoHashtableDelete(MdbLdap.TransTable); - MdbLdap.TransTable = NULL; - } - - if (MdbLdap.AttrTable) { - BongoHashtableDelete(MdbLdap.AttrTable); - MdbLdap.AttrTable = NULL; - } - - if (MdbLdap.ClassTable) { - BongoHashtableDelete(MdbLdap.ClassTable); - MdbLdap.ClassTable = NULL; - } - - if (MdbLdap.ExtTable) { - BongoHashtableDelete(MdbLdap.ExtTable); - MdbLdap.ExtTable = NULL; - } - - if (MdbLdap.PathTable) { - BongoHashtableDelete(MdbLdap.PathTable); - MdbLdap.PathTable = NULL; - XplRWLockDestroy(&(MdbLdap.PathLock)); - } - - if (MdbLdap.MdbBaseDn) { - free(MdbLdap.MdbBaseDn); - MdbLdap.MdbBaseDn = NULL; - } - - if (MdbLdap.LdapSchemaDn) { - free(MdbLdap.LdapSchemaDn); - MdbLdap.LdapSchemaDn = NULL; - } - - if (MdbLdap.args) { - free(MdbLdap.args); - MdbLdap.args = NULL; - } - - LogShutdown(); -} diff --git a/src/libs/mdb-xldap/mdbldapp.h b/src/libs/mdb-xldap/mdbldapp.h deleted file mode 100644 index 9feaf63..0000000 --- a/src/libs/mdb-xldap/mdbldapp.h +++ /dev/null @@ -1,146 +0,0 @@ -#define LDAP_DEPRECATED 1 -#include -#include -#include - -/* compatibility with different client libraries */ -#ifndef LDAP_CONST -#define LDAP_CONST const -#endif -#ifndef LDAP_OPT_SUCCESS -#define LDAP_OPT_SUCCESS 0 -#endif -#ifndef LDAP_EXOP_MODIFY_PASSWD -#define LDAP_EXOP_MODIFY_PASSWD "1.3.6.1.4.1.4203.1.11.1" -#endif -#ifndef LDAP_TAG_EXOP_MODIFY_PASSWD_ID -#define LDAP_TAG_EXOP_MODIFY_PASSWD_ID ((ber_tag_t) 0x80U) -#endif -#ifndef LDAP_TAG_EXOP_MODIFY_PASSWD_OLD -#define LDAP_TAG_EXOP_MODIFY_PASSWD_OLD ((ber_tag_t) 0x81U) -#endif -#ifndef LDAP_TAG_EXOP_MODIFY_PASSWD_NEW -#define LDAP_TAG_EXOP_MODIFY_PASSWD_NEW ((ber_tag_t) 0x82U) -#endif -#ifndef LBER_USE_DER -#define LBER_USE_DER 0x01 -#endif - -#define MDBLDAP_FLAGS_ALLOCATED_HANDLE (unsigned long)(1 << 0) -#define MDBLDAP_FLAGS_CONTEXT_VALID (unsigned long)(1 << 1) -#define MDBLDAP_FLAGS_CONTEXT_DUPLICATE (unsigned long)(1 << 2) -#define MDBLDAP_FLAGS_BASEDB_CHANGED (unsigned long)(1 << 3) - -#define MDBLDAP_MIN_CONNECTIONS 4 -#define MDBLDAP_MAX_CONNECTIONS 8 - -#define MDBLDAP_DEFAULT_CACHE_SIZE 512 - -#define VALUE_ALLOC_SIZE 20 - -typedef struct { - unsigned char Description[128]; - struct _MDBInterfaceStruct *Interface; - char *binddn; - char *passwd; - - struct { - int next; - int min; - int max; - XplMutex mutex; - LDAP **list; - } conn; -} MDBLDAPContextStruct; - -typedef MDBLDAPContextStruct *MDBHandle; - -typedef struct { - unsigned char **Value; - unsigned long Used; - unsigned long ErrNo; - struct _MDBInterfaceStruct *Interface; - - MDBLDAPContextStruct *context; - LDAP *ldap; - unsigned char *base; - unsigned char *lastDn; - unsigned long allocated; - BOOL duplicate; -} MDBValueStruct; - -typedef struct { - char **vals; - int next; - int count; -} MDBEnumStruct; - -#ifndef MDB_INTERNAL -#define MDB_INTERNAL -#endif - -#include - -/* schema.c */ - -typedef struct { - char *val; - char *oid; - char **names; - int namecnt; - char *desc; - char *equality; - char *syntax; - char *sup; - BOOL singleval; - int refcnt; - BOOL visited; -} MDBLDAPSchemaAttr; - -typedef enum { - TYPE_ABSTRACT, - TYPE_AUXILIARY, - TYPE_STRUCTURAL -} ClassTypeEnum; - -typedef struct { - char *val; - char *oid; - char **names; - char *desc; - char **sup; - char **must; - char **may; - char *naming; - ClassTypeEnum type; - int refcnt; - BOOL visited; -} MDBLDAPSchemaClass; - -#define MDBLDAP_SYNTAX_DN(syntax) \ - !strncmp((syntax), "1.3.6.1.4.1.1466.115.121.1.12", 29) - -#define MDBLDAP_SYNTAX_STRING(syntax) \ - !strncmp((syntax), "1.3.6.1.4.1.1466.115.121.1.15", 29) - -BOOL ParseAttributeTypeDescription(char *ptr, MDBLDAPSchemaAttr *attr); -BOOL ParseObjectClassDescription(char *ptr, MDBLDAPSchemaClass *class); - -/* valarray.c */ -typedef char * (* TranslateFunction) (const char *val, const char *opt); -inline char **NewValArray(int size); -inline void FreeValArray(char **vals); -inline int CountValArray(char **vals); -inline char **CopyValArray(char **vals); -inline BOOL ExpandValArray(char ***vals, int size); -inline unsigned int ValueStructToValArray(MDBValueStruct *v, char **vals); -inline int ValArrayToValueStruct(char **vals, MDBValueStruct *v); -inline char **TranslateValArray(char **in, TranslateFunction transfunc, char *opt); -inline unsigned int TranslateValueStructToValArray(MDBValueStruct *v, char **vals, TranslateFunction transfunc, char *opt); -inline int TranslateValArrayToValueStruct(char **vals, MDBValueStruct *v, TranslateFunction transfunc, char *opt); - -BOOL MDBLDAPAddValue(const unsigned char *Value, MDBValueStruct *V); -BOOL MDBLDAPFreeValues(MDBValueStruct * V); - -EXPORT BOOL MDBLDAPInit(MDBDriverInitStruct *Init); -EXPORT void MDBLDAPShutdown(void); diff --git a/src/libs/mdb-xldap/schema.c b/src/libs/mdb-xldap/schema.c deleted file mode 100644 index d030281..0000000 --- a/src/libs/mdb-xldap/schema.c +++ /dev/null @@ -1,286 +0,0 @@ -#include -#include "mdbldapp.h" - -#define CHARS_WHITESPACE " \t\n\f\r" -#define CHARS_DIGIT "0123456789" -#define CHARS_ALPHA_UPPER "ABCDEFGHIJKLMNOPQRSTUVWXYZ" -#define CHARS_ALPHA_LOWER "abcdefghijklmnopqrstuvwxyz" -#define CHARS_ALPHA CHARS_ALPHA_UPPER CHARS_ALPHA_LOWER -#define CHARS_ALPHANUM CHARS_DIGIT CHARS_ALPHA -#define CHARS_WORD "_" CHARS_ALPHANUM -#define CHARS_WHSP CHARS_WHITESPACE -#define CHARS_OID "-." CHARS_WORD - -/** - * Find the first character not among the characters in 'except'. - */ -static char *strnot(const char *string, const char *except) { - char *s = (char *) string; - char *e = (char *) except; - - while (*s != '\0') { - while (*e != '\0') { - if (*s == *e) { - s++; - break; - } - e++; - } - if (*e == '\0') { - break; - } - e = (char *) except; - } - return s; -} - -/** - * Return true if c is among the characters in 'accept'. - */ -static int charin(int c, const char *accept) { - char *a = (char *) accept; - - while (*a != '\0') { - if (c == *a) { - return 1; - } - a++; - } - return 0; -} - -static char *ParseOid(char *ptr, char **oid) { - if (!charin(*ptr, CHARS_OID)) { - return NULL; - } - *oid = ptr; - if (!(ptr = strchr(ptr, ' '))) { - return NULL; - } - *ptr++ = '\0'; - return ptr; -} - -static char *ParseQdescr(char *ptr, char **qdescr) { - if (*ptr != '\'') { - return NULL; - } - *qdescr = ++ptr; - if (!(ptr = strchr(ptr, '\''))) { - return NULL; - } - *ptr++ = '\0'; - return ptr; -} - -static char *ParseNoidlen(char *ptr, char **noidlen) { - /* Active Directory sometimes (incorrectly) uses quotes here */ - if (*ptr == '\'') { - return ParseQdescr(ptr, noidlen); - } - - if (!charin(*ptr, CHARS_OID)) { - return NULL; - } - *noidlen = ptr; - if (!(ptr = strchr(ptr, ' '))) { - } - *ptr++ = '\0'; - return ptr; -} - -static char *ParseOids(char *ptr, char ***oids) { - int inc = 4; - int idx = 0; - - *oids = NewValArray(inc); - if (!*oids) { - return NULL; - } - - if (*ptr == '(') { - ptr = strnot(ptr + 1, CHARS_WHSP); - while (ptr && *ptr != ')') { - if (!(idx % inc)) { - if (!ExpandValArray(oids, idx + inc)) { - FreeValArray(*oids); - free(*oids); - return NULL; - } - } - if (!(ptr = ParseOid(ptr, &((*oids)[idx++]))) || - !(ptr = strnot(ptr, "$" CHARS_WHSP))) { - break; - } - } - if (!ptr || *ptr != ')') { - FreeValArray(*oids); - free(*oids); - return NULL; - } - } else if (charin(*ptr, CHARS_OID)) { - ptr = ParseOid(ptr, &((*oids)[idx++])); - } else { - FreeValArray(*oids); - free(*oids); - return NULL; - } - return ptr; -} - -static char *ParseQdescrs(char *ptr, char ***qdescrs) { - int inc = 4; - int idx = 0; - - *qdescrs = NewValArray(inc); - if (!*qdescrs) { - return NULL; - } - - if (*ptr == '(') { - ptr = strnot(ptr + 1, CHARS_WHSP); - while (ptr && *ptr != ')') { - if (!(idx % inc)) { - if (!ExpandValArray(qdescrs, idx + inc)) { - FreeValArray(*qdescrs); - free(*qdescrs); - return NULL; - } - } - if (!(ptr = ParseQdescr(ptr, &((*qdescrs)[idx++]))) || - !(ptr = strnot(ptr, CHARS_WHSP))) { - break; - } - } - if (!ptr || *ptr != ')') { - FreeValArray(*qdescrs); - free(*qdescrs); - return NULL; - } - } else if (*ptr == '\'') { - if (!(ptr = ParseQdescr(ptr, &((*qdescrs)[idx++])))) { - FreeValArray(*qdescrs); - free(*qdescrs); - return NULL; - } - } else { - FreeValArray(*qdescrs); - free(*qdescrs); - return NULL; - } - return ptr; -} - -BOOL ParseAttributeTypeDescription(char *ptr, MDBLDAPSchemaAttr *attr) { - char *tmp; - - ptr = strnot(ptr, CHARS_WHSP); - if (*ptr != '(') { - return FALSE; - } - - if (!(ptr = strnot(ptr + 1, CHARS_WHSP)) || - !(ptr = ParseOid(ptr, &attr->oid))) { - return FALSE; - } - - if ((tmp = strstr(ptr, "NAME"))) { - ptr = tmp; - if (!(ptr = strnot(ptr + 4, CHARS_WHSP)) || - !(ptr = ParseQdescrs(ptr, &attr->names))) { - return FALSE; - } - } - - if ((tmp = strstr(ptr, "SUP"))) { - ptr = tmp; - if (!(ptr = strnot(ptr + 3, CHARS_WHSP)) || - !(ptr = ParseOid(ptr, &attr->sup))) { - return FALSE; - } - } - - if ((tmp = strstr(ptr, "EQUALITY"))) { - ptr = tmp; - if (!(ptr = strnot(ptr + 8, CHARS_WHSP)) || - !(ptr = ParseOid(ptr, &attr->equality))) { - return FALSE; - } - } - - if ((tmp = strstr(ptr, "SYNTAX"))) { - ptr = tmp; - if (!(ptr = strnot(ptr + 6, CHARS_WHSP)) || - !(ptr = ParseNoidlen(ptr, &attr->syntax))) { - return FALSE; - } - } - - if (!(ptr = strnot(ptr, CHARS_WHSP)) && - !strncmp(ptr, "SINGLE-VALUE", 12)) { - attr->singleval = TRUE; - } - - return TRUE; -} - -BOOL ParseObjectClassDescription(char *ptr, MDBLDAPSchemaClass *class) { - char *tmp; - - ptr = strnot(ptr, CHARS_WHSP); - if (*ptr != '(') { - return FALSE; - } - - if (!(ptr = strnot(ptr + 1, CHARS_WHSP)) || - !(ptr = ParseOid(ptr, &class->oid))) { - return FALSE; - } - - if ((tmp = strstr(ptr, "NAME"))) { - ptr = tmp; - if (!(ptr = strnot(ptr + 4, CHARS_WHSP)) || - !(ptr = ParseQdescrs(ptr, &class->names))) { - return FALSE; - } - } - - if ((tmp = strstr(ptr, "SUP"))) { - ptr = tmp; - if (!(ptr = strnot(ptr + 3, CHARS_WHSP)) || - !(ptr = ParseOids(ptr, &class->sup))) { - return FALSE; - } - } - - /* - ptr = strnot(ptr, CHARS_WHSP); - if (!strncmp(ptr, "ABSTRACT", 8) || - !strncmp(ptr, "STRUCTURAL", 10) || - !strncmp(ptr, "AUXILIARY", 9)) { - type = ptr; - if (!(ptr = strchr(ptr, ' '))) { - return FALSE; - } - *ptr++ = '\0'; - } - */ - - if ((tmp = strstr(ptr, "MUST"))) { - ptr = tmp; - if (!(ptr = strnot(ptr + 4, CHARS_WHSP)) || - !(ptr = ParseOids(ptr, &class->must))) { - return FALSE; - } - } - - if ((tmp = strstr(ptr, "MAY"))) { - ptr = tmp; - if (!(ptr = strnot(ptr + 3, CHARS_WHSP)) || - !(ptr = ParseOids(ptr, &class->may))) { - return FALSE; - } - } - - return TRUE; -} diff --git a/src/libs/mdb-xldap/valarray.c b/src/libs/mdb-xldap/valarray.c deleted file mode 100644 index 9f3a93c..0000000 --- a/src/libs/mdb-xldap/valarray.c +++ /dev/null @@ -1,213 +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 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 "mdbldapp.h" - -/** - * Functions for handling char ** arrays. - */ - -inline char ** -NewValArray(int size) -{ - char **vals; - - vals = malloc(sizeof(char *) * (size + 1)); - if (vals) { - memset(vals, 0, sizeof(char *) * (size + 1)); - } - return vals; -} - -inline void -FreeValArray(char **vals) -{ - int i; - - for (i = 0; vals[i]; i++) { - free(vals[i]); - vals[i] = NULL; - } - /*free(vals);*/ -} - -inline int -CountValArray(char **vals) -{ - int i; - - for (i = 0; vals[i]; i++); - return i; -} - -inline char ** -CopyValArray(char **vals) -{ - char **dup; - int count; - int i; - - count = CountValArray(vals); - dup = NewValArray(count); - if (dup) { - for (i = 0; vals[i]; i++) { - dup[i] = strdup(vals[i]); - if (!dup[i]) { - break; - } - } - if (i < count) { - FreeValArray(dup); - free(dup); - dup = NULL; - } - } - return dup; -} - -inline BOOL -ExpandValArray(char ***vals, int size) -{ - char **tmps; - char **ptr; - int count; - int ext; - - count = CountValArray(*vals); - ext = size - count; - if (ext > 0) { - tmps = realloc(*vals, (sizeof(char *) * (size + 1))); - if (tmps) { - ptr = tmps + count + 1; - memset(ptr, 0, (sizeof(char *) * ext)); - *vals = tmps; - return TRUE; - } - } - return FALSE; -} - -inline unsigned int -ValueStructToValArray(MDBValueStruct *v, char **vals) -{ - unsigned int i; - - for (i = 0; i < v->Used; i++) { - vals[i] = strdup((char *)(v->Value[i])); - if (!vals[i]) { - break; - } - } - if (i < v->Used) { - FreeValArray(vals); - return 0; - } - return i; -} - -inline int -ValArrayToValueStruct(char **vals, MDBValueStruct *v) -{ - int i; - int count; - - count = CountValArray(vals); - for (i = 0; vals[i]; i++) { - if (!MDBLDAPAddValue((unsigned char *)(vals[i]), v)) { - break; - } - } - if (i < count) { - return 0; - } - return i; -} - -inline char ** -TranslateValArray(char **in, TranslateFunction transfunc, char *opt) -{ - char **out; - int count; - int i; - - count = CountValArray(in); - out = NewValArray(count); - - if (out) { - for (i = 0; in[i]; i++) { - out[i] = transfunc(in[i], opt); - if (!out[i]) { - break; - } - } - if (i < count) { - FreeValArray(out); - free(out); - out = NULL; - } - } - return out; -} - -inline unsigned int -TranslateValueStructToValArray(MDBValueStruct *v, char **vals, - TranslateFunction transfunc, char *opt) -{ - unsigned int i; - - for (i = 0; i < v->Used; i++) { - vals[i] = transfunc((char *)(v->Value[i]), opt); - if (!vals[i]) { - break; - } - } - if (i < v->Used) { - FreeValArray(vals); - return 0; - } - return i; -} - -inline int -TranslateValArrayToValueStruct(char **vals, MDBValueStruct *v, - TranslateFunction transfunc, char *opt) -{ - char *val; - int count; - int i; - - count = CountValArray(vals); - for (i = 0; vals[i]; i++) { - val = transfunc(vals[i], opt); - if (val) { - if (!MDBLDAPAddValue((unsigned char *)val, v)) { - break; - } - free(val); - } else { - break; - } - } - if (i < count) { - return 0; - } - return i; -} diff --git a/src/libs/mdb/Bongo.rules b/src/libs/mdb/Bongo.rules deleted file mode 100644 index e997cea..0000000 --- a/src/libs/mdb/Bongo.rules +++ /dev/null @@ -1,21 +0,0 @@ -# -*- Makefile -*- -mdbdir = $(libdir)/bongomdb -mdb_LTLIBRARIES = - -lib_LTLIBRARIES += libbongomdb.la - -libbongomdb_la_SOURCES = \ - src/libs/mdb/mdb.c \ - src/libs/mdb/mdbp.h - -libbongomdb_la_CPPFLAGS = $(AM_CPPFLAGS) \ - -DDRIVER_EXTENSION=\"$(SHARED_POSTFIX)\" \ - -DSYSCONF_DIR=\""$(sysconfdir)"\" \ - -DDRIVER_DIR=\""$(libdir)/bongomdb"\" - -libbongomdb_la_LIBADD = \ - libbongoxpl.la \ - $(DL_LIBS) - -src/libs/mdb/all: libbongomdb.la -src/libs/mdb/clean: clean diff --git a/src/libs/mdb/Makefile.am b/src/libs/mdb/Makefile.am deleted file mode 100644 index 8830401..0000000 --- a/src/libs/mdb/Makefile.am +++ /dev/null @@ -1,17 +0,0 @@ -# -*- Makefile -*- -# -# Do not edit! -# -# (unless this is Makefile.am.subdir) -# -# This file is a copy of the toplevel Makefile.am.subdir. If changes -# need to be made, edit that file, and make update-makefiles, and -# check the new files in. -# -# This is a skeletal automake file. The real automake fules for -# building the targets for this directory can be found in the -# Bongo.rules file. This file is simply here so that 'make all' can -# work in each subdirectory. - -all clean install: - @cd $(top_builddir) && $(MAKE) $(MFLAGS) $(subdir)/$@ diff --git a/src/libs/mdb/mdb.c b/src/libs/mdb/mdb.c deleted file mode 100644 index e3ef35f..0000000 --- a/src/libs/mdb/mdb.c +++ /dev/null @@ -1,887 +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. - * - */ - -/* We use bongo-specific keys/dirs here rather than mdb, so that we don't conflict before - * we merge */ - -#include -#include -#include -#include - -/* Local modification, bongo's xpl no longer defines these */ - -#include -#include "mdbp.h" - -/* Globals */ -LONG Tid; -LONG TGid; -XplSemaphore ShutdownSemaphore; -BOOL MDBInitialized = FALSE; -BOOL MDBLoading = FALSE; -BOOL MDBFailed = FALSE; - - -#define ChopNL(String) { unsigned char *pTr; pTr=strchr((String), 0x0a); if (pTr) *pTr='\0'; pTr=strrchr((String), 0x0d); if (pTr) *pTr='\0'; } - -#if defined(NETWARE) -#define MDB_CONFIG_INIT -#define MDB_CONFIG_FILE "sys:/etc/mdb.cfg" -unsigned char DriverDir[XPL_MAX_PATH+1] = "sys:\\system"; -#elif defined(WIN32) -#define MDB_CONFIG_INIT { \ - HKEY HKey; \ - GetWindowsDirectory(MDB_CONFIG_FILE, sizeof(MDB_CONFIG_FILE)); \ - strcat(MDB_CONFIG_FILE, "/mdb.cfg"); \ - \ - if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\\Bongo\\MDB", 0, KEY_READ, &HKey)==ERROR_SUCCESS) { \ - DWORD BufSize=XPL_MAX_PATH; \ - RegQueryValueEx(HKey, "DriverDir", NULL, NULL, DriverDir, &BufSize); \ - RegCloseKey(HKey); \ - } \ - } - -unsigned char MDB_CONFIG_FILE[256+1]; -unsigned char DriverDir[XPL_MAX_PATH+1] = "C:\\program files\\Bongo\\MDB"; -#elif defined(SUSE) || defined(LINUX) || defined(S390RH) || defined(REDHAT) || defined(SOLARIS) || defined(MACOSX) -#define MDB_CONFIG_INIT -#define MDB_CONFIG_FILE XPL_DEFAULT_CONF_DIR "/mdb.conf" -unsigned char DriverDir[XPL_MAX_PATH+1] = DRIVER_DIR; -#endif - -typedef struct _MDBDriverStruct { - unsigned char Driver[256]; - BOOL Primary; - MDBDriverInitFunc Init; - MDBDriverShutdownFunc Shutdown; - MDBInterfaceStruct Interface; - XplPluginHandle Handle; - void *Data; -} MDBDriverStruct; - -typedef struct { - unsigned char Module[XPL_MAX_PATH]; - unsigned char Driver[XPL_MAX_PATH]; - unsigned char Arguments[512]; -} MDBModuleStruct; - -unsigned long MDBDriverCount = 0; -MDBDriverStruct *MDBDrivers = NULL; - -unsigned long MDBModuleCount = 0; -unsigned long MDBModuleAlloc = 0; -MDBModuleStruct *MDBModules = NULL; - -unsigned long MDBDefaultDriver = 0; - -static unsigned long -MDBFindDriver(const unsigned char *Driver) -{ - unsigned long i; - - for (i=0; iDriver); - strcat (FuncName, "Init"); - - /* FIXME: what do we do about DriverName here */ - Driver->Init=(MDBDriverInitFunc)XplGetDLLFunction(DriverName, FuncName, Driver->Handle); - - if (!Driver->Init) { - if (Error) sprintf(Error, "Driver %s, missing Init function", Driver->Driver); - if (Driver->Primary) { - XplUnloadDLL(Driver->Driver, Driver->Handle); - } - return(-1); - } - - /* Grab the shutdown function */ - strcpy(FuncName, Driver->Driver); - strcat(FuncName, "Shutdown"); - - Driver->Shutdown=(MDBDriverShutdownFunc)XplGetDLLFunction(DriverName, FuncName, Driver->Handle); - if (!Driver->Shutdown) { - if (Error) sprintf(Error, "Driver %s, missing Shutdown function", Driver->Driver); - if (Driver->Primary) { - XplUnloadDLL(Driver->Driver, Driver->Handle); - } - return(-1); - } - - memset(&Init, 0, sizeof(Init)); - Init.Arguments=Arguments; - - if (!Driver->Init(&Init)) { - if (Error) sprintf(Error, "Driver %s, Init failed with: %s", Driver->Driver, Init.Error); - Driver->Shutdown(); - /* Can't unload for now; dclient creates a bunch of threads and they go to hell if we unload this dll */ - //XplUnloadDLL(Driver->Driver, Driver->Handle); - return(-1); - } - memcpy(&Driver->Interface, &Init.Interface, sizeof(MDBInterfaceStruct)); - return 0; -} - - - -static unsigned long -MDBLoadDriver(const unsigned char *DriverNameIn, const unsigned char *Arguments, unsigned char *Error) -{ - unsigned char DriverName[XPL_MAX_PATH+1]; - unsigned char Name[XPL_MAX_PATH+1]; - - unsigned char *ptr; - MDBDriverStruct *Driver; - - /* First, make sure there's enough space in our list */ - MDBDrivers=realloc(MDBDrivers, sizeof(MDBDriverStruct)*(MDBDriverCount+1)); - if (!MDBDrivers) { - return(-1); - } - Driver=&MDBDrivers[MDBDriverCount]; - memset(Driver, 0, sizeof(MDBDriverStruct)); - - strcpy(DriverName, DriverNameIn); - - ptr=DriverName; - while (*ptr) { - *ptr=tolower(*ptr); - ptr++; - } - -TryAgain: - if ((strchr(DriverNameIn, '/')==NULL) && (strchr(DriverNameIn, '\\')==NULL)) { - if ((strlen(DriverName)<5) || (XplStrNCaseCmp(DriverName+strlen(DriverName)-strlen(DRIVER_EXTENSION), DRIVER_EXTENSION, strlen(DRIVER_EXTENSION))!=0)) { - ptr=strrchr(DriverName, '.'); - if (ptr && XplStrNCaseCmp(ptr,".NLM", 4)==0) { - strcpy(ptr, DRIVER_EXTENSION); - goto TryAgain; - } else { - /* No period means possibly no extension, let's add our default extension */ - strcat(DriverName, DRIVER_EXTENSION); - goto TryAgain; - } - if (Error) strcpy(Error, "Bad driver extension"); - return(-1); - } - } else { - unsigned char *ptr; - - if ((ptr=strrchr(DriverNameIn, '/'))==NULL) { - ptr=strrchr(DriverNameIn, '\\'); - } - ptr++; - strcpy(DriverName, ptr); - } - - strcpy(Name, DriverName); - Name[strlen(Name)-strlen(DRIVER_EXTENSION)]='\0'; - ptr=Name; - while (*ptr) { - *ptr=toupper(*ptr); - ptr++; - } - - Driver->Handle=MDBGetDriverHandle(DriverName); - - if (!Driver->Handle) { - if (!(strchr(DriverNameIn, '/')==NULL) && (strchr(DriverNameIn, '\\')==NULL)) { - /* Use the absolute path if it was passed */ - Driver->Handle=XplLoadDLL(DriverNameIn); - } else { - - /* Otherwise try then lib */ - unsigned char Path[XPL_MAX_PATH + 1]; - - sprintf(Path, "%s%c%s", DriverDir, XPL_DIR_SEPARATOR, DriverName); - - Driver->Handle=XplLoadDLL(Path); - if (!Driver->Handle) { - sprintf(Path, "%s%clib%s", DriverDir, XPL_DIR_SEPARATOR, DriverName); - Driver->Handle=XplLoadDLL(Path); - - } - } - Driver->Primary=TRUE; - } - - if (!Driver->Handle) { - if (Error) sprintf(Error, "Could not load driver, error %d", errno); - return(-1); - } - - /* Give the module a chance to initialize */ - - strcpy(Driver->Driver, Name); - if (MDBInitDriver (Driver, Arguments, Error) == 0) { - - //XplConsolePrintf("MDBDriver '%s', successfully loaded\n", DriverName); - return(MDBDriverCount++); - } else { - return(-1); - } -} - -EXPORT int -MDBGetAPIVersion(BOOL WantCompatibleVersion, unsigned char *Description, MDBHandle Context) -{ - if (Description) { - if (Context) { - strncpy(Description, ((MDBContextCacheStruct *)Context)->Description, MDB_MAX_API_DESCRIPTION_CHARS-1); - } else { - strcpy(Description, ""); - } - } - - if (WantCompatibleVersion) { - return(MDB_COMPATIBLE_TO_API); - } else { - return(MDB_CURRENT_API_VERSION); - } -} - -EXPORT BOOL -MDBGetServerInfo(unsigned char *HostDN, unsigned char *HostTree, MDBValueStruct *V) -{ - if (!V) { - return(MDBDrivers[MDBDefaultDriver].Interface.MDBGetServerInfo(HostDN, HostTree, V)); - } else { - return(V->Interface->MDBGetServerInfo(HostDN, HostTree, V)); - } -} - -EXPORT char * -MDBGetBaseDN(MDBValueStruct *V) -{ - if (!V) { - return(MDBDrivers[MDBDefaultDriver].Interface.MDBGetBaseDN(V)); - } else { - return(V->Interface->MDBGetBaseDN(V)); - } -} - - -/* Authentication */ -EXPORT MDBHandle -MDBAuthenticate(const unsigned char *Module, const unsigned char *Object, const unsigned char *Password) -{ - unsigned int i; - unsigned long Driver=MDBDefaultDriver; - MDBHandle Handle; - unsigned char *Arguments=NULL; - - for (i=0; iInterface=&MDBDrivers[Driver].Interface; - } - return(Handle); -} - - -EXPORT BOOL -MDBRelease(MDBHandle Handle) -{ - if (Handle) { - return(((MDBContextCacheStruct *)Handle)->Interface->MDBRelease(Handle)); - } else { - return(FALSE); - } -} - - -EXPORT MDBValueStruct -*MDBCreateValueStruct(MDBHandle Handle, const unsigned char *Context) -{ - MDBValueStruct *V; - - V=((MDBContextCacheStruct *)Handle)->Interface->MDBCreateValueStruct(Handle, Context); - - if (V) { - V->Interface=((MDBContextCacheStruct *)Handle)->Interface; - } - return(V); -} - - -EXPORT BOOL -MDBDestroyValueStruct(MDBValueStruct *V) -{ - return(V->Interface->MDBDestroyValueStruct(V)); -} - - -EXPORT MDBValueStruct -*MDBShareContext(MDBValueStruct *VOld) -{ - MDBValueStruct *VNew; - - VNew=VOld->Interface->MDBShareContext(VOld); - if (VNew) { - VNew->Interface=VOld->Interface; - } - return(VNew); -} - - -EXPORT BOOL -MDBSetValueStructContext(const unsigned char *Context, MDBValueStruct *V) -{ - return(V->Interface->MDBSetValueStructContext(Context, V)); -} - - -EXPORT MDBEnumStruct -*MDBCreateEnumStruct(MDBValueStruct *V) -{ - return(V->Interface->MDBCreateEnumStruct(V)); -} - - -EXPORT BOOL -MDBDestroyEnumStruct(MDBEnumStruct *E, MDBValueStruct *V) -{ - return(V->Interface->MDBDestroyEnumStruct(E, V)); -} - - -EXPORT BOOL -MDBAddValue(const unsigned char *Value, MDBValueStruct *V) -{ - return(V->Interface->MDBAddValue(Value, V)); -} - - -EXPORT BOOL -MDBFreeValue(unsigned long Index, MDBValueStruct *V) -{ - return(V->Interface->MDBFreeValue(Index, V)); -} - - -EXPORT BOOL -MDBFreeValues(MDBValueStruct *V) -{ - return(V->Interface->MDBFreeValues(V)); -} - - -EXPORT long -MDBRead(const unsigned char *Object, const unsigned char *Attribute, MDBValueStruct *V) -{ - return(V->Interface->MDBRead(Object, Attribute, V)); -} - - -EXPORT const unsigned char -*MDBReadEx(const unsigned char *Object, const unsigned char *Attribute, MDBEnumStruct *E, MDBValueStruct *V) -{ - return(V->Interface->MDBReadEx(Object, Attribute, E, V)); -} - - -EXPORT long -MDBReadDN(const unsigned char *Object, const unsigned char *Attribute, MDBValueStruct *V) -{ - return(V->Interface->MDBReadDN(Object, Attribute, V)); -} - - -EXPORT BOOL -MDBWriteTyped(const unsigned char *Object, const unsigned char *Attribute, const int AttrType, MDBValueStruct *V) -{ - return(V->Interface->MDBWriteTyped(Object, Attribute, AttrType, V)); -} - -EXPORT BOOL -MDBWrite(const unsigned char *Object, const unsigned char *Attribute, MDBValueStruct *V) -{ - return(V->Interface->MDBWrite(Object, Attribute, V)); -} - - -EXPORT BOOL -MDBWriteDN(const unsigned char *Object, const unsigned char *Attribute, MDBValueStruct *V) -{ - return(V->Interface->MDBWriteDN(Object, Attribute, V)); -} - - -EXPORT BOOL -MDBClear(const unsigned char *Object, const unsigned char *Attribute, MDBValueStruct *V) -{ - return(V->Interface->MDBClear(Object, Attribute, V)); -} - - -EXPORT BOOL -MDBAdd(const unsigned char *Object, const unsigned char *Attribute, const unsigned char *Value, MDBValueStruct *V) -{ - return(V->Interface->MDBAdd(Object, Attribute, Value, V)); -} - - -EXPORT BOOL -MDBAddDN(const unsigned char *Object, const unsigned char *Attribute, const unsigned char *Value, MDBValueStruct *V) -{ - return(V->Interface->MDBAddDN(Object, Attribute, Value, V)); -} - - -EXPORT BOOL -MDBRemove(const unsigned char *Object, const unsigned char *Attribute, const unsigned char *Value, MDBValueStruct *V) -{ - return(V->Interface->MDBRemove(Object, Attribute, Value, V)); -} - - -EXPORT BOOL -MDBRemoveDN(const unsigned char *Object, const unsigned char *Attribute, const unsigned char *Value, MDBValueStruct *V) -{ - return(V->Interface->MDBRemoveDN(Object, Attribute, Value, V)); -} - - -EXPORT BOOL -MDBIsObject(const unsigned char *Object, MDBValueStruct *V) -{ - return(V->Interface->MDBIsObject(Object, V)); -} - - -EXPORT BOOL -MDBGetObjectDetails(const unsigned char *Object, unsigned char *Type, unsigned char *RDN, unsigned char *DN, MDBValueStruct *V) -{ - return(V->Interface->MDBGetObjectDetails(Object, Type, RDN, DN, V)); -} - -EXPORT BOOL -MDBGetObjectDetailsEx(const unsigned char *Object, MDBValueStruct *Types, unsigned char *RDN, unsigned char *DN, MDBValueStruct *V) -{ - return(V->Interface->MDBGetObjectDetailsEx(Object, Types, RDN, DN, V)); -} - -EXPORT BOOL -MDBVerifyPassword(const unsigned char *Object, const unsigned char *Password, MDBValueStruct *V) -{ - return(V->Interface->MDBVerifyPassword(Object, Password, V)); -} - - -EXPORT BOOL -MDBVerifyPasswordEx(const unsigned char *Object, const unsigned char *Password, MDBValueStruct *V) -{ - return(V->Interface->MDBVerifyPasswordEx(Object, Password, V)); -} - - -EXPORT BOOL -MDBChangePassword(const unsigned char *Object, const unsigned char *OldPassword, const unsigned char *NewPassword, MDBValueStruct *V) -{ - return(V->Interface->MDBChangePassword(Object, OldPassword, NewPassword, V)); -} - - -EXPORT BOOL -MDBChangePasswordEx(const unsigned char *Object, const unsigned char *OldPassword, const unsigned char *NewPassword, MDBValueStruct *V) -{ - return(V->Interface->MDBChangePasswordEx(Object, OldPassword, NewPassword, V)); -} - - -EXPORT long -MDBEnumerateObjects(const unsigned char *Container, const unsigned char *Type, const unsigned char *Pattern, MDBValueStruct *V) -{ - return(V->Interface->MDBEnumerateObjects(Container, Type, Pattern, 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) -{ - return(V->Interface->MDBEnumerateObjectsEx(Container, Type, Pattern, Flags, E, V)); -} - - -EXPORT const unsigned char -*MDBEnumerateAttributesEx(const unsigned char *Object, MDBEnumStruct *E, MDBValueStruct *V) -{ - return(V->Interface->MDBEnumerateAttributesEx(Object, E, V)); -} - -EXPORT BOOL -MDBCreateAlias(const unsigned char *Alias, const unsigned char *AliasedObjectDn, MDBValueStruct *V) -{ - return(V->Interface->MDBCreateAlias(Alias, AliasedObjectDn, V)); -} - -EXPORT BOOL -MDBCreateObject(const unsigned char *Object, const unsigned char *Class, MDBValueStruct *Attribute, MDBValueStruct *Data, MDBValueStruct *V) -{ - return(V->Interface->MDBCreateObject(Object, Class, Attribute, Data, V)); -} - - -EXPORT BOOL -MDBDeleteObject(const unsigned char *Object, BOOL Recursive, MDBValueStruct *V) -{ - return(V->Interface->MDBDeleteObject(Object, Recursive, V)); -} - - -EXPORT BOOL -MDBRenameObject(const unsigned char *ObjectOld, const unsigned char *ObjectNew, MDBValueStruct *V) -{ - return(V->Interface->MDBRenameObject(ObjectOld, ObjectNew, V)); -} - - -EXPORT BOOL -MDBDefineAttribute(const unsigned char *Attribute, const unsigned char *ASN1, unsigned long Type, BOOL SingleValue, BOOL ImmediateSync, BOOL Public, MDBValueStruct *V) -{ - return(V->Interface->MDBDefineAttribute(Attribute, ASN1, Type, SingleValue, ImmediateSync, Public, V)); -} - - -EXPORT BOOL -MDBUndefineAttribute(const unsigned char *Attribute, MDBValueStruct *V) -{ - return(V->Interface->MDBUndefineAttribute(Attribute, 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) -{ - return(V->Interface->MDBDefineClass(Class, ASN1, Container, Superclass, Containment, Naming, Mandatory, Optional, V)); -} - - -EXPORT BOOL -MDBAddAttribute(const unsigned char *Attribute, const unsigned char *Class, MDBValueStruct *V) -{ - return(V->Interface->MDBAddAttribute(Attribute, Class, V)); -} - - -EXPORT BOOL -MDBUndefineClass(const unsigned char *Class, MDBValueStruct *V) -{ - return(V->Interface->MDBUndefineClass(Class, V)); -} - - -EXPORT BOOL -MDBListContainableClasses(const unsigned char *Container, MDBValueStruct *V) -{ - return(V->Interface->MDBListContainableClasses(Container, V)); -} - - -EXPORT const unsigned char -*MDBListContainableClassesEx(const unsigned char *Container, MDBEnumStruct *E, MDBValueStruct *V) -{ - return(V->Interface->MDBListContainableClassesEx(Container, E, V)); -} - - -EXPORT BOOL -MDBGrantObjectRights(const unsigned char *Object, const unsigned char *TrusteeDN, BOOL Read, BOOL Write, BOOL Delete, BOOL Rename, BOOL Admin, MDBValueStruct *V) -{ - return(V->Interface->MDBGrantObjectRights(Object, TrusteeDN, Read, Write, Delete, Rename, Admin, V)); -} - - -EXPORT BOOL -MDBGrantAttributeRights(const unsigned char *Object, const unsigned char *Attribute, const unsigned char *TrusteeDN, BOOL Read, BOOL Write, BOOL Admin, MDBValueStruct *V) -{ - return(V->Interface->MDBGrantAttributeRights(Object, Attribute, TrusteeDN, Read, Write, Admin, V)); -} - -EXPORT BOOL -MDBFindObjects(const unsigned char *Container, - MDBValueStruct *Types, - const unsigned char *Pattern, - MDBValueStruct *Attributes, - int depth, - int max, - MDBValueStruct *V) -{ - if (V->Interface->MDBFindObjects) { - return(V->Interface->MDBFindObjects(Container, Types, Pattern, Attributes, depth, max, V)); - } else { - return FALSE; - } -} - -EXPORT BOOL -MDBDumpValueStruct(MDBValueStruct *V) -{ - unsigned long i; - - if (!V->Used) { - XplConsolePrintf("No data in structure\n"); - } - XplConsolePrintf("ValueStruct: Used:%lu\n", V->Used); - for (i=0; iUsed; i++) { - XplConsolePrintf("Value[%02lu] %-25s", i, V->Value[i]); - if (((i+1) % 2)==0) { - XplConsolePrintf("\n"); - } else { - XplConsolePrintf(" | "); - } - } - XplConsolePrintf("\r\n"); - return(TRUE); -} - - -/* - Config format: - - DriverDir= - Default= - Driver= [DriverArguments] - Module = [DriverArguments] -*/ - -static BOOL -MDBReadConfiguration(void) -{ - FILE *Handle; - unsigned char Buffer[1024]; - unsigned char Error[XPL_MAX_PATH*2]; - unsigned char DefaultDriverName[XPL_MAX_PATH+1] = ""; - - MDB_CONFIG_INIT; - Handle=fopen(MDB_CONFIG_FILE, "rb"); - if (!Handle) { - return(FALSE); - } - - while (!ferror(Handle) && !feof(Handle)) { - if (fgets(Buffer, sizeof(Buffer), Handle)!=NULL) { - ChopNL(Buffer); - if (XplStrNCaseCmp(Buffer, "DriverDir=", 10)==0) { - strcpy(DriverDir, Buffer+10); - } else if (XplStrNCaseCmp(Buffer, "Module ", 7)==0) { - unsigned char *Module; - unsigned char *Driver; - unsigned char *Arguments; - - if ((MDBModuleCount+1)>MDBModuleAlloc) { - MDBModules=realloc(MDBModules, sizeof(MDBModuleStruct)*(MDBModuleAlloc+10)); - if (!MDBModules) { - fclose(Handle); - return(FALSE); - } - MDBModuleAlloc+=10; - } - - Module=Buffer+7; - Driver=strchr(Module, '='); - if (Driver) { - *Driver='\0'; - Driver++; - if ((Arguments=strchr(Driver, ' '))!=NULL) { - *Arguments='\0'; - Arguments++; - } - strcpy(MDBModules[MDBModuleCount].Module, Module); - strcpy(MDBModules[MDBModuleCount].Driver, Driver); - if (Arguments) { - strcpy(MDBModules[MDBModuleCount].Arguments, Arguments); - } else { - MDBModules[MDBModuleCount].Arguments[0]='\0'; - } - MDBModuleCount++; - } - } else if (XplStrNCaseCmp(Buffer, "Driver=", 7)==0) { - unsigned char *Arguments; - - if ((Arguments=strchr(Buffer+7, ' '))!=NULL) { - *Arguments='\0'; - Arguments++; - } - - if (MDBLoadDriver(Buffer+7, Arguments, Error)==(unsigned long)-1) { - XplConsolePrintf("\rDriver %s failed to load:%s\n", Buffer+7, Error); - fclose(Handle); - return(FALSE); - } - } else if (XplStrNCaseCmp(Buffer, "Default=", 8)==0) { - strcpy(DefaultDriverName, Buffer+8); - } - } - } - fclose(Handle); - - if (DefaultDriverName[0]!='\0') { - MDBDefaultDriver=MDBFindDriver(DefaultDriverName); - } - - return(TRUE); -} - -EXPORT BOOL -MDBInit(void) -{ - if (MDBFailed) { - return FALSE; - } - - if (!MDBInitialized && !MDBLoading) { - MDBLoading=TRUE; - /* Read configuration */ - if (!MDBReadConfiguration()) { - unsigned char Error[XPL_MAX_PATH*2]; - - if ((MDBLoadDriver("MDBDS", NULL, Error)==(unsigned long)-1) && (MDBLoadDriver("MDBREG", NULL, Error)==(unsigned long)-1) && (MDBLoadDriver("MDBFILE", NULL, Error)==(unsigned long)-1)) { - MDBLoading = FALSE; - MDBFailed = TRUE; - XplConsolePrintf("Failed to load any MDB driver\n"); - - /* INSERT "fake" MDB driver here */ - return(FALSE); - } - } - - MDBInitialized=TRUE; - } - - while (!MDBInitialized) { - XplDelay(100); - } - - return(MDBInitialized); -} - - -EXPORT BOOL -MDBShutdown(void) -{ - return(TRUE); -} - -#if defined(NETWARE) -void -MDBSigHandler(int Signal) -{ - int OldTGid; - unsigned long i; - - OldTGid=XplSetThreadGroupID(TGid); - - XplSignalLocalSemaphore(ShutdownSemaphore); - XplWaitOnLocalSemaphore(ShutdownSemaphore); - - /* Do any required cleanup */ - for (i=0; i - * 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 MDBP_H -#define MDBP_H - - -typedef struct { - unsigned char Description[128]; - struct _MDBInterfaceStruct *Interface; -} MDBContextCacheStruct; - - -#endif /* MDBP_H */