2007-05-09 21:06:15 +02:00
|
|
|
/* LDAPSource.m - this file is part of SOGo
|
|
|
|
*
|
|
|
|
* Copyright (C) 2007 Inverse groupe conseil
|
|
|
|
*
|
|
|
|
* Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This file 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; see the file COPYING. If not, write to
|
|
|
|
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#import <Foundation/NSArray.h>
|
|
|
|
#import <Foundation/NSDictionary.h>
|
|
|
|
#import <Foundation/NSString.h>
|
|
|
|
|
|
|
|
#import <EOControl/EOControl.h>
|
|
|
|
#import <NGLdap/NGLdapConnection.h>
|
|
|
|
#import <NGLdap/NGLdapAttribute.h>
|
|
|
|
#import <NGLdap/NGLdapEntry.h>
|
|
|
|
|
|
|
|
#import "LDAPSource.h"
|
2007-10-10 20:44:26 +02:00
|
|
|
#import "LDAPUserManager.h"
|
2007-05-09 21:06:15 +02:00
|
|
|
|
|
|
|
static NSArray *commonSearchFields;
|
2007-07-23 21:04:54 +02:00
|
|
|
static int timeLimit;
|
|
|
|
static int sizeLimit;
|
2007-05-09 21:06:15 +02:00
|
|
|
|
|
|
|
@implementation LDAPSource
|
|
|
|
|
|
|
|
+ (void) initialize
|
|
|
|
{
|
2007-07-23 21:04:54 +02:00
|
|
|
NSUserDefaults *ud;
|
|
|
|
|
2007-05-09 21:06:15 +02:00
|
|
|
if (!commonSearchFields)
|
|
|
|
{
|
2007-07-23 21:04:54 +02:00
|
|
|
ud = [NSUserDefaults standardUserDefaults];
|
|
|
|
sizeLimit = [ud integerForKey: @"SOGoLDAPQueryLimit"];
|
|
|
|
timeLimit = [ud integerForKey: @"SOGoLDAPQueryTimeout"];
|
|
|
|
|
2007-05-09 21:06:15 +02:00
|
|
|
commonSearchFields = [NSArray arrayWithObjects:
|
|
|
|
@"title",
|
|
|
|
@"company",
|
|
|
|
@"o",
|
|
|
|
@"displayName",
|
|
|
|
@"modifytimestamp",
|
|
|
|
@"mozillaHomeState",
|
|
|
|
@"mozillaHomeUrl",
|
|
|
|
@"homeurl",
|
|
|
|
@"st",
|
|
|
|
@"region",
|
|
|
|
@"mozillaCustom2",
|
|
|
|
@"custom2",
|
|
|
|
@"mozillaHomeCountryName",
|
|
|
|
@"description",
|
|
|
|
@"notes",
|
|
|
|
@"department",
|
|
|
|
@"departmentnumber",
|
|
|
|
@"ou",
|
|
|
|
@"orgunit",
|
|
|
|
@"mobile",
|
|
|
|
@"cellphone",
|
|
|
|
@"carphone",
|
|
|
|
@"mozillaCustom1",
|
|
|
|
@"custom1",
|
|
|
|
@"mozillaNickname",
|
|
|
|
@"xmozillanickname",
|
|
|
|
@"mozillaWorkUrl",
|
|
|
|
@"workurl",
|
|
|
|
@"fax",
|
|
|
|
@"facsimileTelephoneNumber",
|
|
|
|
@"telephoneNumber",
|
|
|
|
@"mozillaHomeStreet",
|
|
|
|
@"mozillaSecondEmail",
|
|
|
|
@"xmozillasecondemail",
|
|
|
|
@"mozillaCustom4",
|
|
|
|
@"custom4",
|
|
|
|
@"nsAIMid",
|
|
|
|
@"nscpaimscreenname",
|
|
|
|
@"street",
|
|
|
|
@"streetAddress",
|
|
|
|
@"postOfficeBox",
|
|
|
|
@"homePhone",
|
|
|
|
@"cn",
|
|
|
|
@"commonname",
|
|
|
|
@"givenName",
|
|
|
|
@"mozillaHomePostalCode",
|
|
|
|
@"mozillaHomeLocalityName",
|
|
|
|
@"mozillaWorkStreet2",
|
|
|
|
@"mozillaUseHtmlMail",
|
|
|
|
@"xmozillausehtmlmail",
|
|
|
|
@"mozillaHomeStreet2",
|
|
|
|
@"postalCode",
|
|
|
|
@"zip",
|
|
|
|
@"c",
|
|
|
|
@"countryname",
|
|
|
|
@"pager",
|
|
|
|
@"pagerphone",
|
|
|
|
@"mail",
|
|
|
|
@"sn",
|
|
|
|
@"surname",
|
|
|
|
@"mozillaCustom3",
|
|
|
|
@"custom3",
|
|
|
|
@"l",
|
|
|
|
@"locality",
|
|
|
|
@"birthyear",
|
|
|
|
@"serialNumber",
|
2007-10-10 20:44:26 +02:00
|
|
|
@"calFBURL", @"proxyAddresses",
|
2007-05-09 21:06:15 +02:00
|
|
|
nil];
|
2007-10-10 20:44:26 +02:00
|
|
|
|
2007-05-09 21:06:15 +02:00
|
|
|
[commonSearchFields retain];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (id) sourceFromUDSource: (NSDictionary *) udSource
|
|
|
|
{
|
|
|
|
id newSource;
|
|
|
|
|
|
|
|
newSource = [[self alloc] initFromUDSource: udSource];
|
|
|
|
[newSource autorelease];
|
|
|
|
|
|
|
|
return newSource;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id) init
|
|
|
|
{
|
|
|
|
if ((self = [super init]))
|
|
|
|
{
|
|
|
|
bindDN = nil;
|
|
|
|
hostname = nil;
|
|
|
|
port = 389;
|
|
|
|
password = nil;
|
2007-10-10 20:44:26 +02:00
|
|
|
sourceID = nil;
|
2007-05-09 21:06:15 +02:00
|
|
|
|
|
|
|
baseDN = nil;
|
|
|
|
IDField = @"cn"; /* the first part of a user DN */
|
|
|
|
CNField = @"cn";
|
|
|
|
UIDField = @"uid";
|
2007-11-18 11:16:25 +01:00
|
|
|
mailFields = [NSArray arrayWithObject: @"mail"];
|
|
|
|
[mailFields retain];
|
2007-05-10 23:18:06 +02:00
|
|
|
bindFields = nil;
|
2007-05-09 21:06:15 +02:00
|
|
|
|
|
|
|
ldapConnection = nil;
|
|
|
|
searchAttributes = nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) dealloc
|
|
|
|
{
|
|
|
|
[bindDN release];
|
|
|
|
[hostname release];
|
|
|
|
[password release];
|
|
|
|
[baseDN release];
|
|
|
|
[IDField release];
|
|
|
|
[CNField release];
|
|
|
|
[UIDField release];
|
2007-11-18 11:16:25 +01:00
|
|
|
[mailFields release];
|
2007-05-10 23:18:06 +02:00
|
|
|
[bindFields release];
|
2007-05-09 21:06:15 +02:00
|
|
|
[ldapConnection release];
|
2007-10-10 20:44:26 +02:00
|
|
|
[sourceID release];
|
2007-11-26 21:41:59 +01:00
|
|
|
[modulesConstraints release];
|
2007-05-09 21:06:15 +02:00
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id) initFromUDSource: (NSDictionary *) udSource
|
|
|
|
{
|
|
|
|
self = [self init];
|
|
|
|
|
2007-10-10 20:44:26 +02:00
|
|
|
ASSIGN(sourceID, [udSource objectForKey: @"id"]);
|
|
|
|
|
2007-05-09 21:06:15 +02:00
|
|
|
[self setBindDN: [udSource objectForKey: @"bindDN"]
|
|
|
|
hostname: [udSource objectForKey: @"hostname"]
|
|
|
|
port: [udSource objectForKey: @"port"]
|
|
|
|
andPassword: [udSource objectForKey: @"bindPassword"]];
|
|
|
|
[self setBaseDN: [udSource objectForKey: @"baseDN"]
|
|
|
|
IDField: [udSource objectForKey: @"IDFieldName"]
|
|
|
|
CNField: [udSource objectForKey: @"CNFieldName"]
|
2007-11-18 11:16:25 +01:00
|
|
|
UIDField: [udSource objectForKey: @"UIDFieldName"]
|
|
|
|
mailFields: [udSource objectForKey: @"MailFieldNames"]
|
2007-05-10 23:18:06 +02:00
|
|
|
andBindFields: [udSource objectForKey: @"bindFields"]];
|
2007-11-26 21:41:59 +01:00
|
|
|
ASSIGN (modulesConstraints, [udSource objectForKey: @"ModulesConstraints"]);
|
2007-05-09 21:06:15 +02:00
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setBindDN: (NSString *) newBindDN
|
|
|
|
hostname: (NSString *) newBindHostname
|
|
|
|
port: (NSString *) newBindPort
|
|
|
|
andPassword: (NSString *) newBindPassword
|
|
|
|
{
|
|
|
|
ASSIGN (bindDN, newBindDN);
|
|
|
|
ASSIGN (hostname, newBindHostname);
|
|
|
|
if (newBindPort)
|
|
|
|
port = [newBindPort intValue];
|
|
|
|
ASSIGN (password, newBindPassword);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setBaseDN: (NSString *) newBaseDN
|
|
|
|
IDField: (NSString *) newIDField
|
|
|
|
CNField: (NSString *) newCNField
|
2007-05-10 23:18:06 +02:00
|
|
|
UIDField: (NSString *) newUIDField
|
2007-11-18 11:16:25 +01:00
|
|
|
mailFields: (NSArray *) newMailFields
|
2007-05-10 23:18:06 +02:00
|
|
|
andBindFields: (NSString *) newBindFields
|
2007-05-09 21:06:15 +02:00
|
|
|
{
|
|
|
|
ASSIGN (baseDN, newBaseDN);
|
|
|
|
if (newIDField)
|
|
|
|
ASSIGN (IDField, newIDField);
|
|
|
|
if (CNField)
|
|
|
|
ASSIGN (CNField, newCNField);
|
|
|
|
if (UIDField)
|
|
|
|
ASSIGN (UIDField, newUIDField);
|
2007-11-18 11:16:25 +01:00
|
|
|
if (newMailFields)
|
|
|
|
ASSIGN (mailFields, newMailFields);
|
2007-05-10 23:18:06 +02:00
|
|
|
if (newBindFields)
|
|
|
|
ASSIGN (bindFields, newBindFields);
|
2007-05-09 21:06:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) _initLDAPConnection
|
|
|
|
{
|
|
|
|
ldapConnection = [[NGLdapConnection alloc] initWithHostName: hostname
|
|
|
|
port: port];
|
|
|
|
[ldapConnection bindWithMethod: @"simple"
|
|
|
|
binddn: bindDN
|
|
|
|
credentials: password];
|
2007-07-23 21:04:54 +02:00
|
|
|
if (sizeLimit > 0)
|
|
|
|
[ldapConnection setQuerySizeLimit: sizeLimit];
|
|
|
|
if (timeLimit > 0)
|
|
|
|
[ldapConnection setQueryTimeLimit: timeLimit];
|
2007-05-09 21:06:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* user management */
|
2007-05-10 23:18:06 +02:00
|
|
|
- (EOQualifier *) _qualifierForBindFilter: (NSString *) uid
|
|
|
|
{
|
|
|
|
NSMutableString *qs;
|
|
|
|
NSEnumerator *fields;
|
|
|
|
NSString *currentField;
|
|
|
|
|
|
|
|
qs = [NSMutableString string];
|
|
|
|
fields = [[bindFields componentsSeparatedByString: @","] objectEnumerator];
|
|
|
|
currentField = [fields nextObject];
|
|
|
|
while (currentField)
|
|
|
|
{
|
|
|
|
[qs appendFormat: @"OR (%@='%@')", currentField, uid];
|
|
|
|
currentField = [fields nextObject];
|
|
|
|
}
|
|
|
|
[qs deleteCharactersInRange: NSMakeRange (0, 3)];
|
|
|
|
|
|
|
|
return [EOQualifier qualifierWithQualifierFormat: qs];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) _fetchUserDNForLogin: (NSString *) loginToCheck
|
|
|
|
{
|
|
|
|
NSString *userDN;
|
|
|
|
NSEnumerator *entries;
|
|
|
|
NGLdapEntry *userEntry;
|
|
|
|
|
|
|
|
[self _initLDAPConnection];
|
|
|
|
entries = [ldapConnection deepSearchAtBaseDN: baseDN
|
|
|
|
qualifier: [self _qualifierForBindFilter: loginToCheck]
|
|
|
|
attributes: [NSArray arrayWithObject: @"dn"]];
|
|
|
|
userEntry = [entries nextObject];
|
|
|
|
if (userEntry)
|
|
|
|
userDN = [userEntry dn];
|
|
|
|
else
|
|
|
|
userDN = nil;
|
|
|
|
[ldapConnection release];
|
|
|
|
|
|
|
|
return userDN;
|
|
|
|
}
|
|
|
|
|
2007-05-09 21:06:15 +02:00
|
|
|
- (BOOL) checkLogin: (NSString *) loginToCheck
|
|
|
|
andPassword: (NSString *) passwordToCheck
|
|
|
|
{
|
|
|
|
BOOL didBind;
|
|
|
|
NSString *userDN;
|
|
|
|
NGLdapConnection *bindConnection;
|
|
|
|
|
2007-08-29 18:01:11 +02:00
|
|
|
didBind = NO;
|
|
|
|
|
2007-05-10 16:56:47 +02:00
|
|
|
if ([loginToCheck length] > 0)
|
|
|
|
{
|
|
|
|
bindConnection = [[NGLdapConnection alloc] initWithHostName: hostname
|
|
|
|
port: port];
|
2007-07-23 21:04:54 +02:00
|
|
|
if (timeLimit > 0)
|
|
|
|
[ldapConnection setQueryTimeLimit: timeLimit];
|
2007-05-10 23:18:06 +02:00
|
|
|
if (bindFields)
|
|
|
|
userDN = [self _fetchUserDNForLogin: loginToCheck];
|
|
|
|
else
|
|
|
|
userDN = [NSString stringWithFormat: @"%@=%@,%@",
|
|
|
|
IDField, loginToCheck, baseDN];
|
|
|
|
if (userDN)
|
|
|
|
{
|
|
|
|
NS_DURING
|
|
|
|
didBind = [bindConnection bindWithMethod: @"simple"
|
|
|
|
binddn: userDN
|
|
|
|
credentials: passwordToCheck];
|
|
|
|
NS_HANDLER
|
|
|
|
NS_ENDHANDLER
|
|
|
|
}
|
2007-05-10 16:56:47 +02:00
|
|
|
[bindConnection release];
|
|
|
|
}
|
2007-05-09 21:06:15 +02:00
|
|
|
|
|
|
|
return didBind;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* contact management */
|
|
|
|
- (EOQualifier *) _qualifierForFilter: (NSString *) filter
|
|
|
|
{
|
|
|
|
NSString *qs;
|
|
|
|
EOQualifier *qualifier;
|
|
|
|
|
2007-05-10 16:56:47 +02:00
|
|
|
if ([filter length] > 0)
|
2007-05-09 21:06:15 +02:00
|
|
|
{
|
|
|
|
if ([filter isEqualToString: @"."])
|
|
|
|
qs = @"(cn='*')";
|
|
|
|
else
|
|
|
|
qs = [NSString stringWithFormat:
|
|
|
|
@"(cn='%@*')"
|
|
|
|
@"OR (sn='%@*')"
|
|
|
|
@"OR (displayName='%@*')"
|
|
|
|
@"OR (mail='%@*')"
|
|
|
|
@"OR (telephoneNumber='*%@*')",
|
|
|
|
filter, filter, filter, filter, filter];
|
|
|
|
qualifier = [EOQualifier qualifierWithQualifierFormat: qs];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
qualifier = nil;
|
|
|
|
|
|
|
|
return qualifier;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (EOQualifier *) _qualifierForUIDFilter: (NSString *) uid
|
|
|
|
{
|
|
|
|
NSString *qs;
|
|
|
|
|
|
|
|
qs = [NSString stringWithFormat: (@"(%@='%@') OR (mail='%@')"
|
|
|
|
@" OR (mozillaSecondEmail='%@')"
|
|
|
|
@" OR (xmozillasecondemail='%@')"),
|
|
|
|
UIDField, uid, uid, uid, uid];
|
|
|
|
|
|
|
|
return [EOQualifier qualifierWithQualifierFormat: qs];
|
|
|
|
}
|
|
|
|
|
2007-11-26 21:41:59 +01:00
|
|
|
- (NSArray *) _contraintsFields
|
|
|
|
{
|
|
|
|
NSMutableArray *fields;
|
|
|
|
NSEnumerator *values;
|
|
|
|
NSDictionary *currentConstraint;
|
|
|
|
|
|
|
|
fields = [NSMutableArray array];
|
|
|
|
values = [[modulesConstraints allValues] objectEnumerator];
|
|
|
|
while ((currentConstraint = [values nextObject]))
|
|
|
|
[fields addObjectsFromArray: [currentConstraint allKeys]];
|
|
|
|
|
|
|
|
return fields;
|
|
|
|
}
|
|
|
|
|
2007-05-09 21:06:15 +02:00
|
|
|
- (NSArray *) _searchAttributes
|
|
|
|
{
|
|
|
|
if (!searchAttributes)
|
|
|
|
{
|
|
|
|
searchAttributes = [NSMutableArray new];
|
|
|
|
if (CNField)
|
|
|
|
[searchAttributes addObject: CNField];
|
|
|
|
if (UIDField)
|
|
|
|
[searchAttributes addObject: UIDField];
|
2007-11-18 11:16:25 +01:00
|
|
|
[searchAttributes addObjectsFromArray: mailFields];
|
2007-11-26 21:41:59 +01:00
|
|
|
[searchAttributes addObjectsFromArray: [self _contraintsFields]];
|
2007-05-09 21:06:15 +02:00
|
|
|
[searchAttributes addObjectsFromArray: commonSearchFields];
|
|
|
|
}
|
|
|
|
|
|
|
|
return searchAttributes;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *) allEntryIDs
|
|
|
|
{
|
|
|
|
NSMutableArray *ids;
|
|
|
|
NSEnumerator *entries;
|
|
|
|
NGLdapEntry *currentEntry;
|
|
|
|
NSString *value;
|
|
|
|
|
|
|
|
ids = [NSMutableArray array];
|
|
|
|
|
2007-05-10 23:18:06 +02:00
|
|
|
[self _initLDAPConnection];
|
2007-05-09 21:06:15 +02:00
|
|
|
entries = [ldapConnection deepSearchAtBaseDN: baseDN
|
|
|
|
qualifier: nil
|
|
|
|
attributes: [NSArray arrayWithObject: IDField]];
|
|
|
|
if (entries)
|
|
|
|
{
|
|
|
|
currentEntry = [entries nextObject];
|
|
|
|
while (currentEntry)
|
|
|
|
{
|
|
|
|
value = [[currentEntry attributeWithName: IDField]
|
|
|
|
stringValueAtIndex: 0];
|
|
|
|
if ([value length] > 0)
|
|
|
|
[ids addObject: value];
|
|
|
|
currentEntry = [entries nextObject];
|
|
|
|
}
|
|
|
|
}
|
2007-05-10 23:18:06 +02:00
|
|
|
[ldapConnection release];
|
2007-05-09 21:06:15 +02:00
|
|
|
|
|
|
|
return ids;
|
|
|
|
}
|
|
|
|
|
2007-11-18 11:16:25 +01:00
|
|
|
- (void) _fillEmailsOfEntry: (NGLdapEntry *) ldapEntry
|
|
|
|
intoContactEntry: (NSMutableDictionary *) contactEntry
|
|
|
|
{
|
|
|
|
NSEnumerator *emailFields;
|
|
|
|
NSString *currentFieldName, *value;
|
|
|
|
NSMutableArray *emails;
|
|
|
|
|
|
|
|
emails = [NSMutableArray new];
|
|
|
|
emailFields = [mailFields objectEnumerator];
|
|
|
|
while ((currentFieldName = [emailFields nextObject]))
|
|
|
|
{
|
2007-11-26 21:41:59 +01:00
|
|
|
value = [[ldapEntry attributeWithName: currentFieldName]
|
|
|
|
stringValueAtIndex: 0];
|
2007-11-18 11:16:25 +01:00
|
|
|
if (value)
|
|
|
|
[emails addObject: value];
|
|
|
|
}
|
|
|
|
[emails autorelease];
|
|
|
|
[contactEntry setObject: emails forKey: @"c_emails"];
|
|
|
|
}
|
|
|
|
|
2007-11-26 21:41:59 +01:00
|
|
|
- (void) _fillConstraints: (NGLdapEntry *) ldapEntry
|
|
|
|
forModule: (NSString *) module
|
|
|
|
intoContactEntry: (NSMutableDictionary *) contactEntry
|
|
|
|
{
|
|
|
|
NSDictionary *constraints;
|
|
|
|
NSEnumerator *matches;
|
|
|
|
NSString *currentMatch, *currentValue, *ldapValue;
|
|
|
|
BOOL result;
|
|
|
|
|
|
|
|
result = YES;
|
|
|
|
|
|
|
|
constraints = [modulesConstraints objectForKey: module];
|
|
|
|
if (constraints)
|
|
|
|
{
|
|
|
|
matches = [[constraints allKeys] objectEnumerator];
|
|
|
|
currentMatch = [matches nextObject];
|
|
|
|
while (result && currentMatch)
|
|
|
|
{
|
|
|
|
ldapValue = [[ldapEntry attributeWithName: currentMatch]
|
|
|
|
stringValueAtIndex: 0];
|
|
|
|
currentValue = [constraints objectForKey: currentMatch];
|
|
|
|
if ([ldapValue isEqualToString: currentValue])
|
|
|
|
currentMatch = [matches nextObject];
|
|
|
|
else
|
|
|
|
result = NO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[contactEntry setObject: [NSNumber numberWithBool: result]
|
|
|
|
forKey: [NSString stringWithFormat: @"%@Access", module]];
|
|
|
|
}
|
|
|
|
|
2007-05-09 21:06:15 +02:00
|
|
|
- (NSDictionary *) _convertLDAPEntryToContact: (NGLdapEntry *) ldapEntry
|
|
|
|
{
|
|
|
|
NSMutableDictionary *contactEntry;
|
|
|
|
NSEnumerator *attributes;
|
|
|
|
NSString *currentAttribute, *value;
|
|
|
|
|
|
|
|
contactEntry = [NSMutableDictionary dictionary];
|
|
|
|
attributes = [[self _searchAttributes] objectEnumerator];
|
|
|
|
currentAttribute = [attributes nextObject];
|
|
|
|
while (currentAttribute)
|
|
|
|
{
|
|
|
|
value = [[ldapEntry attributeWithName: currentAttribute]
|
|
|
|
stringValueAtIndex: 0];
|
|
|
|
if (value)
|
|
|
|
[contactEntry setObject: value forKey: currentAttribute];
|
|
|
|
currentAttribute = [attributes nextObject];
|
|
|
|
}
|
|
|
|
value = [[ldapEntry attributeWithName: IDField] stringValueAtIndex: 0];
|
|
|
|
if (!value)
|
|
|
|
value = @"";
|
|
|
|
[contactEntry setObject: value forKey: @"c_name"];
|
|
|
|
value = [[ldapEntry attributeWithName: UIDField] stringValueAtIndex: 0];
|
|
|
|
if (!value)
|
|
|
|
value = @"";
|
|
|
|
[contactEntry setObject: value forKey: @"c_uid"];
|
|
|
|
value = [[ldapEntry attributeWithName: CNField] stringValueAtIndex: 0];
|
|
|
|
if (!value)
|
|
|
|
value = @"";
|
|
|
|
[contactEntry setObject: value forKey: @"c_cn"];
|
2007-11-18 11:16:25 +01:00
|
|
|
[self _fillEmailsOfEntry: ldapEntry intoContactEntry: contactEntry];
|
2007-11-26 21:41:59 +01:00
|
|
|
[self _fillConstraints: ldapEntry forModule: @"Calendar"
|
|
|
|
intoContactEntry: (NSMutableDictionary *) contactEntry];
|
|
|
|
[self _fillConstraints: ldapEntry forModule: @"Mail"
|
|
|
|
intoContactEntry: (NSMutableDictionary *) contactEntry];
|
2007-05-09 21:06:15 +02:00
|
|
|
|
|
|
|
return contactEntry;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *) fetchContactsMatching: (NSString *) match
|
|
|
|
{
|
|
|
|
NSMutableArray *contacts;
|
|
|
|
NGLdapEntry *currentEntry;
|
|
|
|
NSEnumerator *entries;
|
|
|
|
|
|
|
|
contacts = [NSMutableArray array];
|
|
|
|
|
2007-05-10 16:56:47 +02:00
|
|
|
if ([match length] > 0)
|
2007-05-09 21:06:15 +02:00
|
|
|
{
|
2007-05-10 23:18:06 +02:00
|
|
|
[self _initLDAPConnection];
|
2007-05-10 16:56:47 +02:00
|
|
|
entries = [ldapConnection deepSearchAtBaseDN: baseDN
|
|
|
|
qualifier: [self _qualifierForFilter: match]
|
|
|
|
attributes: [self _searchAttributes]];
|
|
|
|
if (entries)
|
2007-05-09 21:06:15 +02:00
|
|
|
{
|
|
|
|
currentEntry = [entries nextObject];
|
2007-05-10 16:56:47 +02:00
|
|
|
while (currentEntry)
|
|
|
|
{
|
|
|
|
[contacts addObject:
|
|
|
|
[self _convertLDAPEntryToContact: currentEntry]];
|
|
|
|
currentEntry = [entries nextObject];
|
|
|
|
}
|
2007-05-09 21:06:15 +02:00
|
|
|
}
|
2007-05-10 23:18:06 +02:00
|
|
|
[ldapConnection release];
|
2007-05-09 21:06:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return contacts;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSDictionary *) lookupContactEntry: (NSString *) entryID;
|
|
|
|
{
|
|
|
|
NSDictionary *contactEntry;
|
|
|
|
NGLdapEntry *ldapEntry;
|
|
|
|
|
2007-05-10 16:56:47 +02:00
|
|
|
contactEntry = nil;
|
|
|
|
|
|
|
|
if ([entryID length] > 0)
|
|
|
|
{
|
2007-05-10 23:18:06 +02:00
|
|
|
[self _initLDAPConnection];
|
2007-05-10 16:56:47 +02:00
|
|
|
ldapEntry
|
|
|
|
= [ldapConnection entryAtDN: [NSString stringWithFormat: @"%@=%@,%@",
|
|
|
|
IDField, entryID, baseDN]
|
|
|
|
attributes: [self _searchAttributes]];
|
|
|
|
if (ldapEntry)
|
|
|
|
contactEntry = [self _convertLDAPEntryToContact: ldapEntry];
|
2007-05-10 23:18:06 +02:00
|
|
|
[ldapConnection release];
|
2007-05-10 16:56:47 +02:00
|
|
|
}
|
2007-05-09 21:06:15 +02:00
|
|
|
|
|
|
|
return contactEntry;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSDictionary *) lookupContactEntryWithUIDorEmail: (NSString *) uid;
|
|
|
|
{
|
|
|
|
NSDictionary *contactEntry;
|
|
|
|
NGLdapEntry *ldapEntry;
|
|
|
|
NSEnumerator *entries;
|
|
|
|
EOQualifier *qualifier;
|
|
|
|
|
2007-05-10 16:56:47 +02:00
|
|
|
contactEntry = nil;
|
|
|
|
|
|
|
|
if ([uid length] > 0)
|
|
|
|
{
|
2007-05-10 23:18:06 +02:00
|
|
|
[self _initLDAPConnection];
|
2007-05-10 16:56:47 +02:00
|
|
|
qualifier = [self _qualifierForUIDFilter: uid];
|
|
|
|
entries = [ldapConnection deepSearchAtBaseDN: baseDN
|
|
|
|
qualifier: qualifier
|
|
|
|
attributes: [self _searchAttributes]];
|
|
|
|
ldapEntry = [entries nextObject];
|
|
|
|
if (ldapEntry)
|
|
|
|
contactEntry = [self _convertLDAPEntryToContact: ldapEntry];
|
2007-05-10 23:18:06 +02:00
|
|
|
[ldapConnection release];
|
2007-05-10 16:56:47 +02:00
|
|
|
}
|
2007-05-09 21:06:15 +02:00
|
|
|
|
|
|
|
return contactEntry;
|
|
|
|
}
|
|
|
|
|
2007-10-10 20:44:26 +02:00
|
|
|
- (NSString *) sourceID
|
|
|
|
{
|
|
|
|
return sourceID;
|
|
|
|
}
|
|
|
|
|
2007-05-09 21:06:15 +02:00
|
|
|
@end
|