Revert "Revert "Revert "fix(core): added back instance caching for LDAP members"""
This reverts commit 056004bca1
.
feature/mail-identities
parent
cb08abfa67
commit
cddfac82dd
|
@ -72,7 +72,6 @@
|
||||||
NSDictionary *_contactMapping;
|
NSDictionary *_contactMapping;
|
||||||
NSArray *_contactObjectClasses;
|
NSArray *_contactObjectClasses;
|
||||||
NSArray *_groupObjectClasses;
|
NSArray *_groupObjectClasses;
|
||||||
NSMutableArray *_members;
|
|
||||||
|
|
||||||
NSDictionary *_modulesConstraints;
|
NSDictionary *_modulesConstraints;
|
||||||
NSArray *_lookupFields;
|
NSArray *_lookupFields;
|
||||||
|
|
|
@ -98,7 +98,6 @@ static Class NSStringK;
|
||||||
// "name" expands to sn, displayname and cn
|
// "name" expands to sn, displayname and cn
|
||||||
_searchFields = [[NSArray arrayWithObjects: @"name", @"mail", @"telephonenumber", nil] retain];
|
_searchFields = [[NSArray arrayWithObjects: @"name", @"mail", @"telephonenumber", nil] retain];
|
||||||
_groupObjectClasses = [[NSArray arrayWithObjects: @"group", @"groupofnames", @"groupofuniquenames", @"posixgroup", nil] retain];
|
_groupObjectClasses = [[NSArray arrayWithObjects: @"group", @"groupofnames", @"groupofuniquenames", @"posixgroup", nil] retain];
|
||||||
_members = nil;
|
|
||||||
_IMAPHostField = nil;
|
_IMAPHostField = nil;
|
||||||
_IMAPLoginField = nil;
|
_IMAPLoginField = nil;
|
||||||
_SieveHostField = nil;
|
_SieveHostField = nil;
|
||||||
|
@ -145,7 +144,6 @@ static Class NSStringK;
|
||||||
[_mailFields release];
|
[_mailFields release];
|
||||||
[_searchFields release];
|
[_searchFields release];
|
||||||
[_groupObjectClasses release];
|
[_groupObjectClasses release];
|
||||||
[_members release];
|
|
||||||
[_IMAPHostField release];
|
[_IMAPHostField release];
|
||||||
[_IMAPLoginField release];
|
[_IMAPLoginField release];
|
||||||
[_SieveHostField release];
|
[_SieveHostField release];
|
||||||
|
@ -2039,92 +2037,90 @@ _makeLDAPChanges (NGLdapConnection *ldapConnection,
|
||||||
NSAutoreleasePool *pool;
|
NSAutoreleasePool *pool;
|
||||||
int i, c;
|
int i, c;
|
||||||
NGLdapEntry *entry;
|
NGLdapEntry *entry;
|
||||||
|
NSMutableArray *members = nil;
|
||||||
|
|
||||||
if (!_members)
|
if ([uid hasPrefix: @"@"])
|
||||||
|
uid = [uid substringFromIndex: 1];
|
||||||
|
|
||||||
|
entry = [self lookupGroupEntryByUID: uid inDomain: nil];
|
||||||
|
|
||||||
|
if (entry)
|
||||||
{
|
{
|
||||||
if ([uid hasPrefix: @"@"])
|
members = [NSMutableArray new];
|
||||||
uid = [uid substringFromIndex: 1];
|
uids = [NSMutableArray array];
|
||||||
|
dns = [NSMutableArray array];
|
||||||
|
logins = [NSMutableArray array];
|
||||||
|
|
||||||
entry = [self lookupGroupEntryByUID: uid inDomain: nil];
|
// We check if it's a static group
|
||||||
|
// Fetch "members" - we get DNs
|
||||||
|
d = [entry asDictionary];
|
||||||
|
o = [d objectForKey: @"member"];
|
||||||
|
CHECK_CLASS(o);
|
||||||
|
if (o) [dns addObjectsFromArray: o];
|
||||||
|
|
||||||
if (entry)
|
// Fetch "uniqueMembers" - we get DNs
|
||||||
|
o = [d objectForKey: @"uniquemember"];
|
||||||
|
CHECK_CLASS(o);
|
||||||
|
if (o) [dns addObjectsFromArray: o];
|
||||||
|
|
||||||
|
// Fetch "memberUid" - we get UID (like login names)
|
||||||
|
o = [d objectForKey: @"memberuid"];
|
||||||
|
CHECK_CLASS(o);
|
||||||
|
if (o) [uids addObjectsFromArray: o];
|
||||||
|
|
||||||
|
c = [dns count] + [uids count];
|
||||||
|
|
||||||
|
// We deal with a static group, let's add the members
|
||||||
|
if (c)
|
||||||
{
|
{
|
||||||
_members = [[NSMutableArray alloc] init];
|
um = [SOGoUserManager sharedUserManager];
|
||||||
uids = [NSMutableArray array];
|
|
||||||
dns = [NSMutableArray array];
|
|
||||||
logins = [NSMutableArray array];
|
|
||||||
|
|
||||||
// We check if it's a static group
|
// We add members for whom we have their associated DN
|
||||||
// Fetch "members" - we get DNs
|
for (i = 0; i < [dns count]; i++)
|
||||||
d = [entry asDictionary];
|
|
||||||
o = [d objectForKey: @"member"];
|
|
||||||
CHECK_CLASS(o);
|
|
||||||
if (o) [dns addObjectsFromArray: o];
|
|
||||||
|
|
||||||
// Fetch "uniqueMembers" - we get DNs
|
|
||||||
o = [d objectForKey: @"uniquemember"];
|
|
||||||
CHECK_CLASS(o);
|
|
||||||
if (o) [dns addObjectsFromArray: o];
|
|
||||||
|
|
||||||
// Fetch "memberUid" - we get UID (like login names)
|
|
||||||
o = [d objectForKey: @"memberuid"];
|
|
||||||
CHECK_CLASS(o);
|
|
||||||
if (o) [uids addObjectsFromArray: o];
|
|
||||||
|
|
||||||
c = [dns count] + [uids count];
|
|
||||||
|
|
||||||
// We deal with a static group, let's add the members
|
|
||||||
if (c)
|
|
||||||
{
|
{
|
||||||
um = [SOGoUserManager sharedUserManager];
|
pool = [NSAutoreleasePool new];
|
||||||
|
dn = [dns objectAtIndex: i];
|
||||||
// We add members for whom we have their associated DN
|
login = [um getLoginForDN: [dn lowercaseString]];
|
||||||
for (i = 0; i < [dns count]; i++)
|
user = [SOGoUser userWithLogin: login roles: nil];
|
||||||
|
if (user)
|
||||||
{
|
{
|
||||||
pool = [NSAutoreleasePool new];
|
[logins addObject: login];
|
||||||
dn = [dns objectAtIndex: i];
|
[members addObject: [NSDictionary dictionaryWithObject: login
|
||||||
login = [um getLoginForDN: [dn lowercaseString]];
|
forKey: @"c_uid"]];
|
||||||
user = [SOGoUser userWithLogin: login roles: nil];
|
|
||||||
if (user)
|
|
||||||
{
|
|
||||||
[logins addObject: login];
|
|
||||||
[_members addObject: [NSDictionary dictionaryWithObject: login
|
|
||||||
forKey: @"c_uid"]];
|
|
||||||
}
|
|
||||||
[pool release];
|
|
||||||
}
|
}
|
||||||
|
[pool release];
|
||||||
// We add members for whom we have their associated login name
|
|
||||||
for (i = 0; i < [uids count]; i++)
|
|
||||||
{
|
|
||||||
pool = [NSAutoreleasePool new];
|
|
||||||
login = [uids objectAtIndex: i];
|
|
||||||
user = [SOGoUser userWithLogin: login roles: nil];
|
|
||||||
if (user)
|
|
||||||
{
|
|
||||||
[logins addObject: login];
|
|
||||||
[_members addObject: [NSDictionary dictionaryWithObject: login
|
|
||||||
forKey: @"c_uid"]];
|
|
||||||
}
|
|
||||||
[pool release];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// We are done fetching members, let's cache the members of the group
|
|
||||||
// (ie., their UIDs) in memcached to speed up -hasMemberWithUID.
|
|
||||||
[[SOGoCache sharedCache] setValue: [logins componentsJoinedByString: @","]
|
|
||||||
forKey: [NSString stringWithFormat: @"%@+%@", uid, _domain]];
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
// We add members for whom we have their associated login name
|
||||||
|
for (i = 0; i < [uids count]; i++)
|
||||||
{
|
{
|
||||||
// We deal with a dynamic group, let's search all users for whom
|
pool = [NSAutoreleasePool new];
|
||||||
// memberOf is equal to our group's DN.
|
login = [uids objectAtIndex: i];
|
||||||
// We also need to look for labelelURI?
|
user = [SOGoUser userWithLogin: login roles: nil];
|
||||||
|
if (user)
|
||||||
|
{
|
||||||
|
[logins addObject: login];
|
||||||
|
[members addObject: [NSDictionary dictionaryWithObject: login
|
||||||
|
forKey: @"c_uid"]];
|
||||||
|
}
|
||||||
|
[pool release];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// We are done fetching members, let's cache the members of the group
|
||||||
|
// (ie., their UIDs) in memcached to speed up -hasMemberWithUID.
|
||||||
|
[[SOGoCache sharedCache] setValue: [logins componentsJoinedByString: @","]
|
||||||
|
forKey: [NSString stringWithFormat: @"%@+%@", uid, _domain]];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// We deal with a dynamic group, let's search all users for whom
|
||||||
|
// memberOf is equal to our group's DN.
|
||||||
|
// We also need to look for labelelURI?
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return _members;
|
return members;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -2133,49 +2129,30 @@ _makeLDAPChanges (NGLdapConnection *ldapConnection,
|
||||||
- (BOOL) groupWithUIDHasMemberWithUID: (NSString *) uid
|
- (BOOL) groupWithUIDHasMemberWithUID: (NSString *) uid
|
||||||
memberUid: (NSString *) memberUid
|
memberUid: (NSString *) memberUid
|
||||||
{
|
{
|
||||||
|
|
||||||
BOOL rc;
|
BOOL rc;
|
||||||
|
NSString *key, *value;;
|
||||||
|
NSArray *a;
|
||||||
|
|
||||||
rc = NO;
|
rc = NO;
|
||||||
|
|
||||||
// If _members is initialized, we use it as it's very accurate.
|
if ([uid hasPrefix: @"@"])
|
||||||
// Otherwise, we fallback on memcached in order to avoid
|
uid = [uid substringFromIndex: 1];
|
||||||
// decomposing the group all the time just to see if a user
|
|
||||||
// is a member of it.
|
key = [NSString stringWithFormat: @"%@+%@", uid, _domain];
|
||||||
if (_members)
|
value = [[SOGoCache sharedCache] valueForKey: key];
|
||||||
|
|
||||||
|
// If the value isn't in memcached, that probably means -members was never called.
|
||||||
|
// We call it only once here.
|
||||||
|
if (!value)
|
||||||
{
|
{
|
||||||
NSString *currentUID;
|
[self membersForGroupWithUID: uid];
|
||||||
int count, max;
|
|
||||||
|
|
||||||
max = [_members count];
|
|
||||||
for (count = 0; !rc && count < max; count++)
|
|
||||||
{
|
|
||||||
currentUID = [[_members objectAtIndex: count] objectForKey: @"c_uid"];
|
|
||||||
rc = [memberUid isEqualToString: currentUID];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
NSString *key, *value;
|
|
||||||
NSArray *a;
|
|
||||||
|
|
||||||
if ([uid hasPrefix: @"@"])
|
|
||||||
uid = [uid substringFromIndex: 1];
|
|
||||||
|
|
||||||
key = [NSString stringWithFormat: @"%@+%@", uid, _domain];
|
|
||||||
value = [[SOGoCache sharedCache] valueForKey: key];
|
value = [[SOGoCache sharedCache] valueForKey: key];
|
||||||
|
|
||||||
// If the value isn't in memcached, that probably means -members was never called.
|
|
||||||
// We call it only once here.
|
|
||||||
if (!value)
|
|
||||||
{
|
|
||||||
[self membersForGroupWithUID: uid];
|
|
||||||
value = [[SOGoCache sharedCache] valueForKey: key];
|
|
||||||
}
|
|
||||||
|
|
||||||
a = [value componentsSeparatedByString: @","];
|
|
||||||
rc = [a containsObject: memberUid];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
a = [value componentsSeparatedByString: @","];
|
||||||
|
rc = [a containsObject: memberUid];
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue