From 656869a4a2e0572f9f4179707d3863860fa38632 Mon Sep 17 00:00:00 2001 From: Ludovic Marcotte Date: Fri, 18 Oct 2013 13:16:30 -0400 Subject: [PATCH] Fix for bug #1328 --- SoObjects/SOGo/LDAPSource.h | 8 +---- SoObjects/SOGo/LDAPSource.m | 67 ++++++++++++++++++------------------- 2 files changed, 34 insertions(+), 41 deletions(-) diff --git a/SoObjects/SOGo/LDAPSource.h b/SoObjects/SOGo/LDAPSource.h index 13b37f876..6dd6a2325 100644 --- a/SoObjects/SOGo/LDAPSource.h +++ b/SoObjects/SOGo/LDAPSource.h @@ -1,10 +1,6 @@ /* LDAPSource.h - this file is part of SOGo * - * Copyright (C) 2007-2011 Inverse inc. - * - * Author: Wolfgang Sourdeau - * Ludovic Marcotte - * Francis Lachapelle + * Copyright (C) 2007-2013 Inverse inc. * * This file is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -125,8 +121,6 @@ andMultipleBookingsField: (NSString *) newMultipleBookingsField; - (NGLdapEntry *) lookupGroupEntryByUID: (NSString *) theUID; - (NGLdapEntry *) lookupGroupEntryByEmail: (NSString *) theEmail; -- (NGLdapEntry *) lookupGroupEntryByAttribute: (NSString *) theAttribute - andValue: (NSString *) theValue; @end diff --git a/SoObjects/SOGo/LDAPSource.m b/SoObjects/SOGo/LDAPSource.m index c38f148ed..af71b29eb 100644 --- a/SoObjects/SOGo/LDAPSource.m +++ b/SoObjects/SOGo/LDAPSource.m @@ -1,10 +1,6 @@ /* LDAPSource.m - this file is part of SOGo * - * Copyright (C) 2007-2012 Inverse inc. - * - * Author: Wolfgang Sourdeau - * Ludovic Marcotte - * Francis Lachapelle + * Copyright (C) 2007-2013 Inverse inc. * * This file is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -1245,40 +1241,31 @@ static Class NSStringK; return [_dnCache objectForKey: theLogin]; } -- (NGLdapEntry *) lookupGroupEntryByUID: (NSString *) theUID -{ - return [self lookupGroupEntryByAttribute: UIDField - andValue: theUID]; -} - -- (NGLdapEntry *) lookupGroupEntryByEmail: (NSString *) theEmail -{ -#warning We should support MailFieldNames - return [self lookupGroupEntryByAttribute: @"mail" - andValue: theEmail]; -} - -// This method should accept multiple attributes -- (NGLdapEntry *) lookupGroupEntryByAttribute: (NSString *) theAttribute - andValue: (NSString *) theValue +- (NGLdapEntry *) _lookupGroupEntryByAttributes: (NSArray *) theAttributes + andValue: (NSString *) theValue { EOQualifier *qualifier; - NSString *s; NGLdapEntry *ldapEntry; - - if ([theValue length] > 0) + NSString *s; + + if ([theValue length] > 0 && [theAttributes count] > 0) { - s = [NSString stringWithFormat: @"(%@='%@')", - theAttribute, SafeLDAPCriteria(theValue)]; + if ([theAttributes count] == 1) + { + s = [NSString stringWithFormat: @"(%@='%@')", + [theAttributes lastObject], SafeLDAPCriteria(theValue)]; + + } + else + { + NSString *fieldFormat; + + fieldFormat = [NSString stringWithFormat: @"(%%@='%@')", SafeLDAPCriteria(theValue)]; + s = [[theAttributes stringsWithFormat: fieldFormat] + componentsJoinedByString: @" OR "]; + } + qualifier = [EOQualifier qualifierWithQualifierFormat: s]; - - // We look for additional attributes - the ones related to group - // membership - // attributes = [NSMutableArray arrayWithArray: [self _searchAttributes]]; - // [attributes addObject: @"member"]; - // [attributes addObject: @"uniqueMember"]; - // [attributes addObject: @"memberUid"]; - // [attributes addObject: @"memberOf"]; ldapEntry = [self _lookupLDAPEntry: qualifier]; } else @@ -1287,6 +1274,18 @@ static Class NSStringK; return ldapEntry; } +- (NGLdapEntry *) lookupGroupEntryByUID: (NSString *) theUID +{ + return [self _lookupGroupEntryByAttributes: [NSArray arrayWithObject: UIDField] + andValue: theUID]; +} + +- (NGLdapEntry *) lookupGroupEntryByEmail: (NSString *) theEmail +{ + return [self _lookupGroupEntryByAttributes: mailFields + andValue: theEmail]; +} + - (void) setSourceID: (NSString *) newSourceID { ASSIGN (sourceID, newSourceID);