IDField = @"cn"; /* the first part of a user DN */
CNField = @"cn";
UIDField = @"uid";
+ bindFields = nil;
ldapConnection = nil;
searchAttributes = nil;
[IDField release];
[CNField release];
[UIDField release];
+ [bindFields release];
[ldapConnection release];
[super dealloc];
}
[self setBaseDN: [udSource objectForKey: @"baseDN"]
IDField: [udSource objectForKey: @"IDFieldName"]
CNField: [udSource objectForKey: @"CNFieldName"]
- andUIDField: [udSource objectForKey: @"UIDFieldName"]];
+ UIDField: [udSource objectForKey: @"UIDFieldName"]
+ andBindFields: [udSource objectForKey: @"bindFields"]];
return self;
}
- (void) setBaseDN: (NSString *) newBaseDN
IDField: (NSString *) newIDField
CNField: (NSString *) newCNField
- andUIDField: (NSString *) newUIDField
+ UIDField: (NSString *) newUIDField
+ andBindFields: (NSString *) newBindFields
{
ASSIGN (baseDN, newBaseDN);
if (newIDField)
ASSIGN (CNField, newCNField);
if (UIDField)
ASSIGN (UIDField, newUIDField);
+ if (newBindFields)
+ ASSIGN (bindFields, newBindFields);
}
- (void) _initLDAPConnection
}
/* user management */
+- (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;
+}
+
- (BOOL) checkLogin: (NSString *) loginToCheck
andPassword: (NSString *) passwordToCheck
{
{
bindConnection = [[NGLdapConnection alloc] initWithHostName: hostname
port: port];
- userDN = [NSString stringWithFormat: @"%@=%@,%@",
- IDField, loginToCheck, baseDN];
- NS_DURING
- didBind = [bindConnection bindWithMethod: @"simple" binddn: userDN
- credentials: passwordToCheck];
- NS_HANDLER
- didBind = NO;
- NS_ENDHANDLER
-
+ 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
+ didBind = NO;
+ NS_ENDHANDLER
+ }
[bindConnection release];
}
else
ids = [NSMutableArray array];
- if (!ldapConnection)
- [self _initLDAPConnection];
+ [self _initLDAPConnection];
entries = [ldapConnection deepSearchAtBaseDN: baseDN
qualifier: nil
attributes: [NSArray arrayWithObject: IDField]];
currentEntry = [entries nextObject];
}
}
+ [ldapConnection release];
return ids;
}
if ([match length] > 0)
{
- if (!ldapConnection)
- [self _initLDAPConnection];
+ [self _initLDAPConnection];
entries = [ldapConnection deepSearchAtBaseDN: baseDN
qualifier: [self _qualifierForFilter: match]
attributes: [self _searchAttributes]];
currentEntry = [entries nextObject];
}
}
+ [ldapConnection release];
}
return contacts;
if ([entryID length] > 0)
{
- if (!ldapConnection)
- [self _initLDAPConnection];
+ [self _initLDAPConnection];
ldapEntry
= [ldapConnection entryAtDN: [NSString stringWithFormat: @"%@=%@,%@",
IDField, entryID, baseDN]
attributes: [self _searchAttributes]];
if (ldapEntry)
contactEntry = [self _convertLDAPEntryToContact: ldapEntry];
+ [ldapConnection release];
}
return contactEntry;
if ([uid length] > 0)
{
- if (!ldapConnection)
- [self _initLDAPConnection];
+ [self _initLDAPConnection];
qualifier = [self _qualifierForUIDFilter: uid];
entries = [ldapConnection deepSearchAtBaseDN: baseDN
qualifier: qualifier
ldapEntry = [entries nextObject];
if (ldapEntry)
contactEntry = [self _convertLDAPEntryToContact: ldapEntry];
+ [ldapConnection release];
}
return contactEntry;