Start the msgapi clearout: remove some rarely used functions
This commit is contained in:
+7
-758
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user