From 5e769233ce3d80ebed0973cd0d3c40047be68bb6 Mon Sep 17 00:00:00 2001 From: alexhudson Date: Sun, 22 Jul 2007 13:33:07 +0000 Subject: [PATCH] Start the msgapi clearout: remove some rarely used functions --- src/agents/avirus/avirus.c | 5 +- src/agents/mailprox/mailprox.c | 12 +- src/agents/rules/rules.c | 11 +- src/libs/msgapi/msgapi.c | 765 +----------------------------- src/libs/python/libbongo/msgapi.c | 252 ---------- 5 files changed, 25 insertions(+), 1020 deletions(-) diff --git a/src/agents/avirus/avirus.c b/src/agents/avirus/avirus.c index a129f0b..dd22b90 100755 --- a/src/agents/avirus/avirus.c +++ b/src/agents/avirus/avirus.c @@ -819,7 +819,8 @@ ProcessConnection(AVClient *client) break; } - if (MsgGetUserFeature(client->dn, FEATURE_ANTIVIRUS, NULL, NULL)) { + // FIXME + // if (MsgGetUserFeature(client->dn, FEATURE_ANTIVIRUS, NULL, NULL)) { XplSafeIncrement(AVirus.stats.messages.scanned); ccode = ScanMessage(client, qID); @@ -870,7 +871,7 @@ ProcessConnection(AVClient *client) XplSafeIncrement(AVirus.stats.attachments.blocked); copy = FALSE; } - } + // } if ((email - 1) > cur + 1) { *(email - 1) = ' '; diff --git a/src/agents/mailprox/mailprox.c b/src/agents/mailprox/mailprox.c index a4cb0d3..b771783 100644 --- a/src/agents/mailprox/mailprox.c +++ b/src/agents/mailprox/mailprox.c @@ -527,7 +527,8 @@ ProxyUser(MailProxyClient *client) } if (update) { - MsgSetUserSetting(client->q->user, MSGSRV_A_PROXY_LIST, accounts); + // FIXME + // MsgSetUserSetting(client->q->user, MSGSRV_A_PROXY_LIST, accounts); } MDBDestroyValueStruct(accounts); @@ -664,10 +665,13 @@ ProxyServer(void *ignored) accounts = MDBShareContext(MailProxy.contexts); } - if ((MsgGetUserSetting(user, MSGSRV_A_MESSAGING_DISABLED, accounts) == 0) || (accounts->Value[accounts->Used - 1][0] != '1')) { + // FIXME + // if ((MsgGetUserSetting(user, MSGSRV_A_MESSAGING_DISABLED, accounts) == 0) || (accounts->Value[accounts->Used - 1][0] != '1')) { + if (accounts->Value[accounts->Used - 1][0] != '1') { MDBFreeValues(accounts); - if (MsgGetUserFeature(user, FEATURE_PROXY, MSGSRV_A_PROXY_LIST, accounts)) { + // FIXME + // if (MsgGetUserFeature(user, FEATURE_PROXY, MSGSRV_A_PROXY_LIST, accounts)) { ptr = strrchr(user, '\\'); if (ptr) { strcpy(queue->user, ptr + 1); @@ -695,7 +699,7 @@ ProxyServer(void *ignored) } LoggerEvent(MailProxy.handle.logging, LOGGER_SUBSYSTEM_GENERAL, LOGGER_EVENT_OUT_OF_MEMORY, LOG_ERROR, 0, __FILE__, queue->user, sizeof(MailProxyClient), __LINE__, NULL, 0); - } + // } if (accounts) { MDBFreeValues(accounts); diff --git a/src/agents/rules/rules.c b/src/agents/rules/rules.c index 207981d..5df00cc 100644 --- a/src/agents/rules/rules.c +++ b/src/agents/rules/rules.c @@ -885,7 +885,8 @@ IsNMAPShare(RulesClient *client, unsigned char *name, unsigned char *type, unsig MDBFreeValues(vs); - MsgGetUserSetting(client->dn, MSGSRV_A_AVAILABLE_SHARES, vs); + // FIXME + // MsgGetUserSetting(client->dn, MSGSRV_A_AVAILABLE_SHARES, vs); /* if (MsgGetUserSettingsDN(client->dn, configDn, vs, FALSE)) { MDBRead(configDn, MSGSRV_A_AVAILABLE_SHARES, vs); @@ -957,7 +958,8 @@ IsNMAPShare(RulesClient *client, unsigned char *name, unsigned char *type, unsig memcpy(pattern + length, client->user, count); count += length; - MsgGetUserSetting(dn, MSGSRV_A_OWNED_SHARES, vs); + //FIXME + //MsgGetUserSetting(dn, MSGSRV_A_OWNED_SHARES, vs); /* if (MsgGetUserSettingsDN(dn, configDn, vs, FALSE)) { MDBRead(configDn, MSGSRV_A_OWNED_SHARES, vs); @@ -1808,8 +1810,9 @@ ProcessConnection(RulesClient *client) if (MsgFindObject(client->recipient, client->dn, NULL, &(client->nmap), vs)) { strcpy(client->user, vs->Value[0]); - if (MDBFreeValues(vs) - && MsgGetUserFeature(client->dn, FEATURE_RULES, MSGSRV_A_RULE, vs)) { + if (MDBFreeValues(vs)) { + // FIXME + // && MsgGetUserFeature(client->dn, FEATURE_RULES, MSGSRV_A_RULE, vs)) { ParseRules(client, vs); if (client->rules.head) { ccode = ProcessRules(client, ©, &flags); diff --git a/src/libs/msgapi/msgapi.c b/src/libs/msgapi/msgapi.c index c6a404f..dd1bcb0 100644 --- a/src/libs/msgapi/msgapi.c +++ b/src/libs/msgapi/msgapi.c @@ -219,23 +219,6 @@ MsgGetServerDN(unsigned char *buffer) return(MsgGlobal.server.dn); } -EXPORT BOOL -MsgFindUserNmap(const unsigned char *user, unsigned char *nmap, int nmap_len, unsigned short *port) -{ - struct sockaddr_in nmap_tmp; - - BOOL retVal = FALSE; - retVal = MsgFindObject(user, NULL, NULL, &nmap_tmp, NULL); - - if (retVal) { - strncpy(nmap, inet_ntoa(nmap_tmp.sin_addr), nmap_len); - *port = ntohs(nmap_tmp.sin_port); - return retVal; - } - - return retVal; -} - EXPORT BOOL MsgFindObject(const unsigned char *user, unsigned char *dn, unsigned char *userType, struct sockaddr_in *nmap, MDBValueStruct *v) { @@ -283,15 +266,6 @@ MsgFindObject(const unsigned char *user, unsigned char *dn, unsigned char *userT } } - if (MsgGetUserSetting(user, MSGSRV_A_MESSAGING_DISABLED, - userCtx) > 0) { - if (userCtx->Value[userCtx->Used-1][0] == '1') { - break; - } else { - MDBFreeValue(userCtx->Used - 1, userCtx); - } - } - if (isUser || isResource) { if (v) { MDBAddValue(rdn, v); @@ -421,17 +395,7 @@ MsgFindObjectEx(const unsigned char *user, unsigned char *dn, unsigned char *use } } - if (MsgGetUserSetting(user, MSGSRV_A_MESSAGING_DISABLED, - userCtx) > 0) { - if (userCtx->Value[userCtx->Used - 1][0] == '1') { - *disabled = TRUE; - } else { - *disabled = FALSE; - } - MDBFreeValue(userCtx->Used - 1, userCtx); - } else { - *disabled = FALSE; - } + *disabled = FALSE; if (isUser || isResource) { if (v) { @@ -600,442 +564,8 @@ MsgReadIP(const unsigned char *object, unsigned char *type, MDBValueStruct *v) EXPORT BOOL MsgDomainExists(const unsigned char *domain, unsigned char *domainObjectDN) { - MDBValueStruct *domains; - unsigned long i; - unsigned long j; - /* FIXME later; when we handle parent objects */ return(FALSE); - - domains = MDBCreateValueStruct(MsgGlobal.directoryHandle, NULL); - - XplRWReadLockAcquire(&MsgGlobal.configLock); - - for (i = 0; i < MsgGlobal.vs.server.names->Used; i++) { - MDBSetValueStructContext(MsgGlobal.vs.server.names->Value[i], domains); - if(MDBRead(MSGSRV_AGENT_SMTP, MSGSRV_A_DOMAIN, domains) > 0) { - for (j = 0; j < domains->Used; j++) { - if (XplStrCaseCmp(domain, domains->Value[j])==0) { - XplRWReadLockRelease(&MsgGlobal.configLock); - MDBDestroyValueStruct(domains); - - return(TRUE); - } - } - } - MDBFreeValues(domains); - } - MDBDestroyValueStruct(domains); - XplRWReadLockRelease(&MsgGlobal.configLock); - - return(FALSE); -} - -EXPORT int -MsgGetParentAttribute(const unsigned char *userDN, unsigned char *attribute, MDBValueStruct *vOut) -{ - char configDn[MDB_MAX_OBJECT_CHARS + 1]; - unsigned long index; - int result = 0; - - configDn[0] = '\0'; - - if (MsgGetUserSettingsDN(userDN, configDn, vOut, FALSE)) { - if (MDBRead(configDn, MSGSRV_A_PARENT_OBJECT, vOut) > 0) { - index = vOut->Used - 1; - if (MDBRead(vOut->Value[index], attribute, vOut)>0) { - MDBFreeValue(index, vOut); - result = vOut->Used; - } else { - MDBFreeValue(index, vOut); - result = MDBRead(userDN, attribute, vOut); - } - } else { - result = MDBRead(userDN, attribute, vOut); - } - } - - return result; -} - -EXPORT unsigned char * -MsgGetUserEmailAddress(const unsigned char *userDNin, MDBValueStruct *userData, unsigned char *buffer, unsigned long bufLen) -{ - unsigned char *emailAddress = NULL; - unsigned long originalValueCount = userData->Used; - unsigned long lastValueCount = originalValueCount; - unsigned char *user = NULL; - unsigned char userDN[MDB_MAX_OBJECT_CHARS + 1]; - unsigned char configDn[MDB_MAX_OBJECT_CHARS + 1]; - unsigned char *delim; - - /* Make a copy so we don't edit the const string */ - strcpy(userDN, userDNin); - - if (!(MsgGlobal.flags & MSGAPI_FLAG_INTERNET_EMAIL_ADDRESS)) { - MDBRead(userDN, A_INTERNET_EMAIL_ADDRESS, userData); - if (userData->Used > lastValueCount) { - - if (strchr(userData->Value[userData->Used - 1], '@')) { - /* The user object has a value in the Internet Email Address Attribute */ - if (buffer) { - if (bufLen > strlen(userData->Value[userData->Used - 1])) { - emailAddress = buffer; - strcpy(emailAddress, userData->Value[userData->Used - 1]); - } - } else { - emailAddress = MemStrdup(userData->Value[userData->Used - 1]); - } - - while (originalValueCount < userData->Used){ - MDBFreeValue(userData->Used - 1, userData); - } - return(emailAddress); - } else { - user = userData->Value[userData->Used - 1]; - lastValueCount++; - } - } - } - - /* The value in the Internet Email Address Attribute still needs a domain */ - - delim = strrchr(userDN, '\\' ); - if (delim) { - if (strchr(delim + 1, '@')) { - /* The username is an address */ - if (buffer) { - if (bufLen > strlen(delim + 1)) { - emailAddress = buffer; - strcpy(emailAddress, delim + 1); - } - } else { - emailAddress = MemStrdup(delim + 1); - } - - while (originalValueCount < userData->Used) { - MDBFreeValue(userData->Used - 1, userData); - } - - return(emailAddress); - } - - if (!user) { - user = delim + 1; - } - - - if (MsgGetParentAttribute(userDN, MSGSRV_A_DOMAIN, userData)) { - /* The user or parent has a domain defined */ - if (buffer) { - if (bufLen > (strlen(user) + strlen(userData->Value[userData->Used - 1]) + 1)) { - emailAddress = buffer; - sprintf(emailAddress, "%s@%s", user, userData->Value[userData->Used - 1]); - } - } else { - emailAddress = MemMalloc(strlen(user) + strlen(userData->Value[userData->Used - 1]) + 2); - if (emailAddress) { - sprintf(emailAddress, "%s@%s", user, userData->Value[userData->Used - 1]); - } - } - - while (originalValueCount < userData->Used){ - MDBFreeValue(userData->Used - 1, userData); - } - - return(emailAddress); - } - - *delim = '\0'; - if (MsgGetUserSettingsDN(userDN, configDn, userData, FALSE)) { - MDBRead(configDn, MSGSRV_A_DOMAIN, userData); - } - - if (userData->Used > lastValueCount) { - /* The container has a domain defined */ - if (buffer) { - if (bufLen > (strlen(user) + strlen(userData->Value[userData->Used - 1]) + 1)) { - emailAddress = buffer; - sprintf(emailAddress, "%s@%s", user, userData->Value[userData->Used - 1]); - } - } else { - emailAddress = MemMalloc(strlen(user) + strlen(userData->Value[userData->Used - 1]) + 2); - if (emailAddress) { - sprintf(emailAddress, "%s@%s", user, userData->Value[userData->Used - 1]); - } - } - } else { - /* Default user@official */ - if (buffer) { - if (bufLen > (strlen(user) + MsgGlobal.official.domainLength + 1)) { - emailAddress = buffer; - sprintf(emailAddress, "%s@%s", user, MsgGlobal.official.domain); - } - } else { - emailAddress = MemMalloc(strlen(user) + MsgGlobal.official.domainLength + 2); - if (emailAddress) { - sprintf(emailAddress, "%s@%s", user, MsgGlobal.official.domain); - } - } - } - - *delim = '\\'; - - for (;originalValueCount < userData->Used;){ - MDBFreeValue(userData->Used - 1, userData); - } - return(emailAddress); - } - - /* The dn does not appear valid. Treat it as rdn and do our best */ - if (buffer) { - if (bufLen > (strlen(userDN) + MsgGlobal.official.domainLength + 1)) { - emailAddress = buffer; - sprintf(emailAddress, "%s@%s", userDN, MsgGlobal.official.domain); - } - } else { - emailAddress = MemMalloc(strlen(userDN) + MsgGlobal.official.domainLength + 2); - if (emailAddress) { - sprintf(emailAddress, "%s@%s", userDN, MsgGlobal.official.domain); - } - } - - while (originalValueCount < userData->Used) { - MDBFreeValue(userData->Used - 1, userData); - } - return(emailAddress); -} - -EXPORT unsigned char * -MsgGetUserDisplayName(const unsigned char *userDN, MDBValueStruct *userData) -{ - unsigned char *displayName = NULL; - unsigned long index = userData->Used; - unsigned char *rdn; - - /* Read the Display Name */ - if ((MDBRead(userDN, A_FULL_NAME, userData) > 0) && (userData->Value[index][0] != '\0')) { - displayName = MemStrdup(userData->Value[index]); - while (index < userData->Used){ - MDBFreeValue(index, userData); - } - return(displayName); - } - - /* Create full name using First and Last */ - MDBRead(userDN, A_GIVEN_NAME, userData); - MDBRead(userDN, A_SURNAME, userData); - if (userData->Used == (index + 2)) { - if ((userData->Value[index][0] != '\0') && (userData->Value[index + 1][0] != '\0')) { - displayName = MemMalloc (strlen (userData->Value[index]) + strlen (userData->Value[index + 1]) + 2); - sprintf(displayName, "%s %s", userData->Value[index], userData->Value[index + 1]); - } else if (userData->Value[index][0] != '\0') { - displayName = MemStrdup(userData->Value[index]); - } else if (userData->Value[index + 1][0] != '\0') { - displayName = MemStrdup(userData->Value[index + 1]); - } else { - if ((rdn = strrchr(userDN, '\\'))) { - displayName = MemStrdup(rdn + 1); - } else { - - displayName = MemStrdup(""); - } - } - } else if (userData->Used == (index + 1)) { - if (!(userData->Value[index][0] == ' ' && userData->Value[index][1] == '\0')) { - displayName = MemStrdup(userData->Value[index]); - } else { - /* FIXME: is this right? */ - if ((rdn = strrchr (userDN, '\\'))) { - displayName = MemStrdup(rdn + 1); - } else { - displayName = MemStrdup(""); - } - } - } else { - if ((rdn = strrchr(userDN, '\\'))) { - displayName = MemStrdup(rdn + 1); - } else { - displayName = MemStrdup(""); - } - - } - - while (index < userData->Used) { - MDBFreeValue(index, userData); - } - - - return(displayName); - -} - -/* Get the container DN where a given user's settings object should exist. - This function is responsible for sorting BongoUserSettings objects into - various partitions under the root BongoUserSettingsContainer. */ -EXPORT BOOL -MsgGetUserSettingsContainerDN(const unsigned char *userDn, - unsigned char *containerDn, MDBValueStruct *v, - BOOL create) -{ - MDBValueStruct *attr, *data; - char servicesDn[MDB_MAX_OBJECT_CHARS + 1]; - char dn[MDB_MAX_OBJECT_CHARS + 1]; - BOOL result = FALSE; - char *bucket; - - /* Use the first letter of the user's name to sort them into containers. - This is not the most optimal solution, but it should allow admins to - find corresponding config objects more easily. */ - - if (MsgGetConfigProperty(servicesDn, MSGSRV_CONFIG_PROP_BONGO_SERVICES)) { - bucket = strrchr(userDn, '\\'); - - if (bucket) { - bucket++; - } else { - bucket = userDn; - } - - sprintf(dn, "%s\\%s\\%c", servicesDn, MSGSRV_USER_SETTINGS_ROOT, - *bucket); - - if (MDBIsObject(dn, v)) { - result = TRUE; - } else if (create) { - attr = MDBShareContext(v); - data = MDBShareContext(v); - - if (attr && data) { - result = MDBCreateObject(dn, MSGSRV_C_USER_SETTINGS_CONTAINER, - attr, data, v); - MDBDestroyValueStruct(attr); - MDBDestroyValueStruct(data); - } - } - } - - if (result) { - strcpy(containerDn, dn); - } - - return result; -} - -/* - * User settings are stored on a corresponding BongoUserSettings object that - * can be discovered by following the SeeAlso attribute on the User. - * This function is for convenience in discovering the config object DN. - */ -EXPORT BOOL -MsgGetUserSettingsDN(const unsigned char *userDn, unsigned char *configDn, - MDBValueStruct *v, BOOL create) -{ - int i; - char type[MDB_MAX_ATTRIBUTE_VALUE_CHARS + 1]; - char containerDn[MDB_MAX_OBJECT_CHARS + 1]; - char *cn; - MDBValueStruct *vTmp, *attr, *data; - BOOL result = FALSE; - - vTmp = MDBShareContext(v); - - if (vTmp) { - if (MDBReadDN(userDn, A_SEE_ALSO, vTmp)) { - for (i = 0; i < vTmp->Used; i++) { - if (!MDBGetObjectDetails(vTmp->Value[i], type, NULL, NULL, - vTmp)) { - break; - } - - if (!strcasecmp(type, MSGSRV_C_USER_SETTINGS)) { - strcpy(configDn, vTmp->Value[i]); - result = TRUE; - break; - } - } - } - - if (!result && create) { - cn = strrchr(userDn, '\\'); - attr = MDBShareContext(vTmp); - data = MDBShareContext(vTmp); - - if (cn && attr && data && - MsgGetUserSettingsContainerDN(userDn, containerDn, vTmp, - TRUE)) { - sprintf(configDn, "%s\\%s", containerDn, ++cn); - - if (MDBCreateObject(configDn, MSGSRV_C_USER_SETTINGS, - attr, data, vTmp) && - MDBAddDN(userDn, A_SEE_ALSO, configDn, vTmp)) { - result = TRUE; - } else { - configDn[0] = '\0'; - } - - MDBDestroyValueStruct(attr); - MDBDestroyValueStruct(data); - } - } - - MDBDestroyValueStruct(vTmp); - } - - return result; -} - -/* - * Try to get the setting first from the user object, then from the user's - * settings object. Parent object may override values on settings object. - */ -EXPORT long -MsgGetUserSetting(const unsigned char *userDn, unsigned char *attribute, - MDBValueStruct *vOut) -{ - char configDn[MDB_MAX_OBJECT_CHARS + 1]; - char parentDn[MDB_MAX_OBJECT_CHARS + 1]; - MDBValueStruct *v; - long result = 0; - - configDn[0] = '\0'; - parentDn[0] = '\0'; - v = MDBShareContext(vOut); - - if (v) { - if (MsgGetUserSettingsDN(userDn, configDn, v, FALSE)) { - if (MDBReadDN(configDn, MSGSRV_A_PARENT_OBJECT, v)) { - strcpy(parentDn, v->Value[0]); - MDBFreeValues(v); - - if (MDBRead(parentDn, MSGSRV_A_FEATURE_INHERITANCE, v)) { - if (v->Value[0][0] != FEATURE_PARENT_FIRST) { - /* child takes precedence */ - parentDn[0] = '\0'; - } - } - } - } - - - /* try parent object */ - if (*parentDn) { - result = MDBRead(parentDn, attribute, vOut); - } - - /* try user object */ - if (!result) { - result = MDBRead(userDn, attribute, vOut); - } - - /* try settings object */ - if (!result && *configDn) { - result = MDBRead(configDn, attribute, vOut); - } - MDBDestroyValueStruct(v); - } - - return result; } /* @@ -1064,178 +594,6 @@ MsgMdbAddAny(const unsigned char *dn, const unsigned char *attribute, return MDBAdd(dn, attribute, value, v); } -/* - * Try to apply changes to the user object first then the config object. If - * the config object doesn't exist, create it. - */ -EXPORT BOOL -MsgSetUserSetting(const unsigned char *userDn, unsigned char *attribute, - MDBValueStruct *v) -{ - char configDn[MDB_MAX_OBJECT_CHARS + 1]; - BOOL result = FALSE; - - if (MDBIsObject(userDn, v) && - !(result = MsgMdbWriteAny(userDn, attribute, v))) { - if (MsgGetUserSettingsDN(userDn, configDn, v, TRUE)) { - /* config objects are created on demand */ - result = MsgMdbWriteAny(configDn, attribute, v); - } - } - - return result; -} - -EXPORT BOOL -MsgAddUserSetting(const unsigned char *userDn, unsigned char *attribute, - unsigned char *value, MDBValueStruct *v) -{ - char configDn[MDB_MAX_OBJECT_CHARS + 1]; - BOOL result = FALSE; - - if (MDBIsObject(userDn, v) && - !(result = MsgMdbAddAny(userDn, attribute, value, v))) { - /* config objects are created on demand */ - if (!MsgGetUserSettingsDN(userDn, configDn, v, TRUE)) { - result = MsgMdbAddAny(configDn, attribute, value, v); - } - } - - return result; -} - -/* - * Here's the logic: - * - * Step 1: We get the DN from the caller; we check if there's a parent DN, - * Step 2: If we have inheritance DN, so we read the inheritance configuration of the parent, if not, go to step 4c - * Step 3a: Inheritance is Parent->User; read features attribute from parent - * Step 3b: Inheritance is User->Parent; read features attribute from user - * Step 4a: If feature disabled return disabled state - * Step 4b: If feature from parent, read parent data attribute - * Step 4c: If feature from user, read user data attribute - * Step 5: If data attribute empty, try opposite DN attribute - * - */ -EXPORT BOOL -MsgGetUserFeature(const unsigned char *userDN, unsigned char featureRow, unsigned long featureCol, unsigned char *attribute, MDBValueStruct *vOut) -{ - MDBValueStruct *v; - unsigned char inheritance = '\0'; - unsigned char parentDN[MDB_MAX_OBJECT_CHARS+1]; - unsigned char configDN[MDB_MAX_OBJECT_CHARS+1]; - const unsigned char *objectDN; - unsigned long i; - BOOL looped; - - v = MDBCreateValueStruct(MsgGlobal.directoryHandle, NULL); - - configDN[0] = '\0'; - MsgGetUserSettingsDN(userDN, configDN, v, FALSE); - - /* Step 1 */ - if (configDN && MDBRead(configDN, MSGSRV_A_PARENT_OBJECT, v) > 0) { - /* We have a parent */ - - /* Step 2 */ - strcpy(parentDN, v->Value[0]); - - if (MDBRead(v->Value[0], MSGSRV_A_FEATURE_INHERITANCE, v) > 0) { - /* We have a configured inheritance */ - if ((inheritance = v->Value[1][0]) == FEATURE_PARENT_FIRST) { - objectDN = parentDN; - } else { - objectDN = configDN; - } - } else { - /* No inheritance configured */ - objectDN = configDN; - } - MDBFreeValues(v); - } else { - parentDN[0] = '\0'; - objectDN = configDN; - } - - /* objectDN now contains the DN we have determined we need to read first */ - - looped=FALSE; - - /* Step 3 */ - ReadFeatureAttribute: - if (MDBRead(objectDN, MSGSRV_A_FEATURE_SET, v) > 0) { - /* We have features defined on the object */ - for (i = 0; i < v->Used; i++) { - /* Find our feature */ - if (v->Value[i][0] == featureRow) { - switch (v->Value[i][featureCol]) { - case FEATURE_NOT_AVAILABLE: { - /* Feature disabled; return */ - MDBDestroyValueStruct(v); - - return(FALSE); - } - - case FEATURE_AVAILABLE: { - /* Feature enabled */ - i = v->Used; - break; - } - - case FEATURE_USE_PARENT: - /* Feature enabled via parent */ - case FEATURE_USE_USER: { - /* Feature enabled via user */ - if (!looped && (parentDN[0] != '\0')) { - if (objectDN == parentDN) { - objectDN = configDN; - } else { - objectDN = parentDN; - } - - MDBFreeValues(v); - looped=TRUE; - goto ReadFeatureAttribute; - } else { - /* If loop exists, use user object */ - objectDN = configDN; - i = v->Used; - } - break; - } - } - } - } - - /* We now have the DN of the object we need to read the data attribute from in ObjectDN */ - MDBFreeValues(v); - } else { - /* We didn't find a feature set configuration */ - if (inheritance == FEATURE_PARENT_FIRST) { - /* We read the parent, didn't have feature config, let's read the user's feature set */ - inheritance = FEATURE_USER_FIRST; - objectDN = configDN; - goto ReadFeatureAttribute; - } else { - /* We read the user, don't have inheritance and don't have a feature set -> return enabled feature! */ - goto ReadDataAttribute; - } - } - - ReadDataAttribute: - /* Beyond this point, we can return success; we returned failure above */ - - /* Clean up */ - MDBDestroyValueStruct(v); - - /* If Attribute NULL we just check if feature disabled */ - if (!attribute) { - return(TRUE); - } - - return MsgGetUserSetting(configDN, attribute, vOut); -} - EXPORT BOOL MsgCleanPath(unsigned char *path) { @@ -1570,81 +928,6 @@ LoadContextList(MDBValueStruct *config) return(TRUE); } -static void -MsgConfigMonitor(void) -{ - MDBValueStruct *config; - unsigned long i; - long prevConfigNumber = 0; - struct tm *timeStruct; - time_t utcTime; - long tmp; - - MsgGlobal.flags |= MSGAPI_FLAG_MONITOR_RUNNING; - - XplRenameThread(XplGetThreadID(), "MsgAPI Config Monitor"); - - config = MDBCreateValueStruct(MsgGlobal.directoryHandle, NULL); - if (!config) { - printf("WARNING: MsgConfigMonitor() couldn't create value struct: directory handle %p\n", - MsgGlobal.directoryHandle); - return; - } - - if (MDBRead(MSGSRV_ROOT, MSGSRV_A_CONFIG_CHANGED, config) > 0) { - prevConfigNumber = atol(config->Value[0]); - } - - while (!(MsgGlobal.flags & MSGAPI_FLAG_EXITING)) { - for (i = 0; (i < 300) && !(MsgGlobal.flags & MSGAPI_FLAG_EXITING); i++) { - XplDelay(1000); - } - - /* Get Server Time Zone Offset */ - tzset(); - utcTime = time(NULL); - timeStruct = localtime(&utcTime); - if (timeStruct) { - tmp = (((((((timeStruct->tm_year - 70) * 365) + timeStruct->tm_yday) * 24) + timeStruct->tm_hour) * 60) + timeStruct->tm_min) * 60; - timeStruct = gmtime(&utcTime); - tmp -= (((((((timeStruct->tm_year - 70) * 365) + timeStruct->tm_yday) * 24) + timeStruct->tm_hour) * 60) + timeStruct->tm_min) * 60; - MsgDateSetUTCOffset(tmp); - } - - MDBFreeValues(config); - - if (!(MsgGlobal.flags & MSGAPI_FLAG_EXITING) && (MDBRead(MSGSRV_ROOT, MSGSRV_A_CONFIG_CHANGED, config)>0) && (atol(config->Value[0]) != prevConfigNumber)) { - /* Clear what we just read */ - prevConfigNumber = atol(config->Value[0]); - MDBFreeValues(config); - - /* Acquire Write Lock */ - XplRWWriteLockAcquire(&MsgGlobal.configLock); - - if (MDBRead(MsgGlobal.server.dn, MSGSRV_A_CONNMGR_CONFIG, config)) { - if (atoi(config->Value[0]) == 1) { - MsgGlobal.flags |= MSGAPI_FLAG_SUPPORT_CONNMGR; - } - } - MDBFreeValues(config); - - if (MsgReadIP(MsgGlobal.server.dn, MSGSRV_A_CONNMGR, config)) { - MsgGlobal.connManager = inet_addr(config->Value[0]); - } - MDBFreeValues(config); - - LoadContextList(config); - - XplRWWriteLockRelease(&MsgGlobal.configLock); - } - } - MDBDestroyValueStruct(config); - - MsgGlobal.flags &= ~MSGAPI_FLAG_MONITOR_RUNNING; - - XplExitThread(TSR_THREAD, 0); -} - static BOOL MsgLibraryStop(void) { @@ -1866,7 +1149,9 @@ MsgLibraryStart(void) MDBDestroyValueStruct(config); +#if 0 XplBeginThread(&ID, MsgConfigMonitor, 32767, NULL, i); +#endif /* Attempt to load the plugable cache mechanism */ sprintf(MsgGlobal.cache.fileName, "%s%s", MsgGlobal.cache.moduleName, XPL_DLL_EXTENSION); @@ -2206,7 +1491,9 @@ MsgLibraryInit(void) return(0); } +#if 0 MsgResolveStart(); +#endif MsgLibraryStart(); MsgDateStart(); @@ -2232,7 +1519,9 @@ MsgLibraryShutdown(void) oldGid = XplSetThreadGroupID(MsgGlobal.groupID); +#if 0 MsgResolveStop(); +#endif MsgLibraryStop(); MemoryManagerClose(NULL); @@ -2251,46 +1540,6 @@ MsgDirectoryHandle(void) return(MsgGlobal.directoryHandle); } -BOOL -MsgResolveStart(void) -{ - MDBValueStruct *config; - unsigned long i; - - if (!XplResolveStart()) { - return FALSE; - } - - config = MDBCreateValueStruct(MsgDirectoryHandle(), NULL); - if (MDBRead(MsgGetServerDN(NULL), MSGSRV_A_RESOLVER, config) > 0) { - for (i = 0; i < config->Used; i++) { - XplDnsAddResolver(config->Value[i]); -/* XplConsolePrintf("[%04d] MSGSRV_A_RESOLVER:%s", __LINE__, config->Value[i]);*/ - } - } else { - MDBSetValueStructContext(MsgGetServerDN(NULL), config); - if (MDBRead(MSGSRV_AGENT_SMTP, MSGSRV_A_RESOLVER, config)>0) { - for (i = 0; i < config->Used; i++) { - XplDnsAddResolver(config->Value[i]); -/* XplConsolePrintf("[%04d] MSGSRV_A_RESOLVER:%s", __LINE__, config->Value[i]);*/ - } - MDBSetValueStructContext(NULL, config); - MDBWrite(MsgGetServerDN(NULL), MSGSRV_A_RESOLVER, config); - } - } - MDBDestroyValueStruct(config); - - return(TRUE); -} - -BOOL -MsgResolveStop(void) -{ - return XplResolveStop(); -} - - - BOOL MsgExiting(void) { diff --git a/src/libs/python/libbongo/msgapi.c b/src/libs/python/libbongo/msgapi.c index b2d053a..0b012c6 100644 --- a/src/libs/python/libbongo/msgapi.c +++ b/src/libs/python/libbongo/msgapi.c @@ -120,31 +120,6 @@ msgapi_FindObject(PyObject *self, PyObject *args) return Py_BuildValue("s", buf); } -PyDoc_STRVAR(FindUserNmap_doc, -"FindUserNmap(u) -> (string host, int port) tuple\n\ -\n\ -Return the ip address and port of user u's document store."); - -static PyObject * -msgapi_FindUserNmap(PyObject *self, PyObject *args) -{ - unsigned char *user; - unsigned int len=33; - unsigned char buf[len]; - unsigned short port; - - if (!PyArg_ParseTuple(args, "s", &user)) { - return NULL; - } - - if (!MsgFindUserNmap(user, buf, len, &port)) { - Py_INCREF(Py_None); - return Py_None; - } - - return Py_BuildValue("si", buf, port); -} - PyDoc_STRVAR(GetUserFeature_doc, "GetUserFeature(dn, featurename, ) -> array of strings\n\ \n\ @@ -177,227 +152,6 @@ static const char *features[] = { NULL }; -PyDoc_STRVAR(GetUserSetting_doc, "GetUserSetting(user, attribute)\n"); - -static PyObject * -msgapi_GetUserSetting(PyObject *self, PyObject *args) -{ - unsigned char *user; - char *attribute; - MDBValueStruct *v; - PyObject *ret = Py_None; - int i; - - if (!PyArg_ParseTuple(args, "ss", &user, &attribute)) { - return NULL; - } - - v = MDBCreateValueStruct(MsgDirectoryHandle(), NULL); - - if (v) { - if (MsgGetUserSetting(user, attribute, v)) { - ret = PyList_New(v->Used); - - for (i = 0; i < v->Used; i++) { - PyList_SetItem(ret, i, PyString_FromString(v->Value[i])); - } - } else { - ret = PyList_New(0); - } - - MDBDestroyValueStruct(v); - } else { - Py_INCREF(Py_None); - } - - return ret; -} - -PyDoc_STRVAR(SetUserSetting_doc, "SetUserSetting(user, attribute, values)\n"); - -static PyObject * -msgapi_SetUserSetting(PyObject *self, PyObject *args) -{ - unsigned char *user; - char *attribute; - char *val; - void *vals; - MDBValueStruct *v; - PyObject *item; - PyObject *ret = Py_False; - int i, size; - - if (!PyArg_ParseTuple(args, "ssO", &user, &attribute, &vals)) { - return NULL; - } - - v = MDBCreateValueStruct(MsgDirectoryHandle(), NULL); - - if (v) { - size = PyList_Size(vals); - - for (i = 0; i < size; i++) { - item = PyList_GetItem(vals, i); - PyArg_Parse(item, "s", &val); - if (!MDBAddValue(val, v)) { - break; - } - } - - if (i == size && MsgSetUserSetting(user, attribute, v)) { - ret = Py_True; - } - - MDBDestroyValueStruct(v); - } - - Py_INCREF(ret); - return ret; -} - -PyDoc_STRVAR(AddUserSetting_doc, "AddUserSetting(user, attribute, value)\n"); - -static PyObject * -msgapi_AddUserSetting(PyObject *self, PyObject *args) -{ - unsigned char *user; - char *attribute; - char *value; - MDBValueStruct *v; - PyObject *ret = Py_False; - - if (!PyArg_ParseTuple(args, "sss", &user, &attribute, &value)) { - return NULL; - } - - v = MDBCreateValueStruct(MsgDirectoryHandle(), NULL); - - if (v) { - if (MsgAddUserSetting(user, attribute, value, v)) { - ret = Py_True; - } - - MDBDestroyValueStruct(v); - } - - Py_INCREF(ret); - return ret; -} - -PyDoc_STRVAR(GetUserDisplayName_doc, -"GetUserDisplayName(user) -> string\n\ -\n\ -Return a string containing the display name of the user."); - -static PyObject * -msgapi_GetUserDisplayName(PyObject *self, PyObject *args) -{ - unsigned char *userDN; - unsigned char *name; - MDBValueStruct *v; - PyObject *ret; - - if (!PyArg_ParseTuple(args, "s", &userDN)) { - return NULL; - } - - v = MDBCreateValueStruct(MsgDirectoryHandle(), NULL); - - if (v) { - name = MsgGetUserDisplayName(userDN, v); - MDBDestroyValueStruct(v); - - ret = Py_BuildValue("s", name); - MemFree(name); - } else { - Py_INCREF(Py_None); - ret = Py_None; - } - - return ret; -} - -PyDoc_STRVAR(GetUserEmailAddress_doc, -"GetUserEmailAddress(user) -> string\n\ -\n\ -Return a string containing the email address of the user."); - -static PyObject * -msgapi_GetUserEmailAddress(PyObject *self, PyObject *args) -{ - unsigned char *userDN; - unsigned char email[400]; /* according to RFC2821, the maximum length of a - user name is 64 chars. A domain name can be - 255. */ - MDBValueStruct *v; - PyObject *ret; - - if (!PyArg_ParseTuple(args, "s", &userDN)) { - return NULL; - } - - v = MDBCreateValueStruct(MsgDirectoryHandle(), NULL); - - if (v) { - MsgGetUserEmailAddress(userDN, v, email, sizeof(email)-1); - MDBDestroyValueStruct(v); - - ret = Py_BuildValue("s", email); - } else { - Py_INCREF(Py_None); - ret = Py_None; - } - - return ret; -} - -static PyObject * -msgapi_GetUserFeature(PyObject *self, PyObject *args) -{ - unsigned char *user; - char *feature; - char *attribute; - unsigned int len=33; - unsigned char buf[len]; - char row; - int col; - - if (!PyArg_ParseTuple(args, "sss", &user, &feature, &attribute)) { - return NULL; - } - - row = 'A'; - for (col = 0; features[col] != NULL; col++) { - if (!strcmp(features[col], feature)) { - break; - } - } - - if (features[col]) { - MDBValueStruct *v; - PyObject *ret; - - v = MDBCreateValueStruct(MsgDirectoryHandle(), NULL); - - if (MsgGetUserFeature(user, row, col, attribute, v)) { - int i; - ret = PyList_New(v->Used); - for (i = 0; i < v->Used; i++) { - PyList_SetItem(ret, i, PyString_FromString(v->Value[i])); - } - } else { - Py_INCREF(Py_None); - ret = Py_None; - } - - MDBDestroyValueStruct(v); - return ret; - } else { - Py_INCREF(Py_None); - return Py_None; - } -} - static void ThrowImportException(int code) { @@ -615,12 +369,6 @@ PyMethodDef MsgApiMethods[] = { {"CollectUser", msgapi_CollectUser, METH_VARARGS | METH_STATIC, CollectUser_doc}, {"DirectoryHandle", msgapi_DirectoryHandle, METH_VARARGS | METH_STATIC, DirectoryHandle_doc}, {"FindObject", msgapi_FindObject, METH_VARARGS | METH_STATIC, FindObject_doc}, - {"FindUserNmap", msgapi_FindUserNmap, METH_VARARGS | METH_STATIC, FindUserNmap_doc}, - {"GetUserSetting", msgapi_GetUserSetting, METH_VARARGS | METH_STATIC, GetUserSetting_doc}, - {"SetUserSetting", msgapi_SetUserSetting, METH_VARARGS | METH_STATIC, SetUserSetting_doc}, - {"GetUserDisplayName", msgapi_GetUserDisplayName, METH_VARARGS | METH_STATIC, GetUserDisplayName_doc}, - {"GetUserEmailAddress", msgapi_GetUserEmailAddress, METH_VARARGS | METH_STATIC, GetUserEmailAddress_doc}, - {"GetUserFeature", msgapi_GetUserFeature, METH_VARARGS | METH_STATIC, GetUserFeature_doc}, {"ImportIcsUrl", msgapi_ImportIcsUrl, METH_VARARGS | METH_STATIC, ImportIcsUrl_doc}, {"ImportIcs", msgapi_ImportIcs, METH_VARARGS | METH_STATIC, ImportIcs_doc}, {"IcsSubscribe", msgapi_IcsSubscribe, METH_VARARGS | METH_STATIC, IcsSubscribe_doc},