From 62cdc5a13c21814b9765f1f8d873958a76df2d76 Mon Sep 17 00:00:00 2001 From: Ludovic Marcotte Date: Mon, 6 Apr 2009 12:54:03 +0000 Subject: [PATCH] See ChangeLog Monotone-Parent: 9663f3f262f24910bf38ccb82e6718016ca35645 Monotone-Revision: 4c2f6d4f42eaf2a0ba7489c4099bcdf881808c53 Monotone-Author: ludovic@Sophos.ca Monotone-Date: 2009-04-06T12:54:03 Monotone-Branch: ca.inverse.sogo --- ChangeLog | 8 +++ Scripts/sogod-wrapper | 9 ++-- SoObjects/SOGo/LDAPSource.h | 1 + SoObjects/SOGo/LDAPSource.m | 105 +++++++++++++++++++++++++++++------- 4 files changed, 101 insertions(+), 22 deletions(-) diff --git a/ChangeLog b/ChangeLog index d46dedd76..1365f4138 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ + * Improved the sogod-wrapper script in order to + consider the IP address that can be specified + in the WOPort user default. Patch from + Romain LE DISEZ + * SoObjects/SOGo/LDAPSource.{h.m}: Now possible to + specify a scope for LDAP operations. Patch from + Yann Cezard + 2009-04-02 Wolfgang Sourdeau * SoObjects/SOGo/LDAPSource.m: we now support an "encryption" diff --git a/Scripts/sogod-wrapper b/Scripts/sogod-wrapper index 6d5550766..7c7bde3ba 100755 --- a/Scripts/sogod-wrapper +++ b/Scripts/sogod-wrapper @@ -2,7 +2,7 @@ # SOGo daemon wrapper # -# Copyright (C) 2007 Inverse inc. +# Copyright (C) 2007-2009 Inverse inc. # # Author: Wolfgang Sourdeau # @@ -55,10 +55,10 @@ else exit 1 fi -startport=`defaults read sogod WOPort` +woport=`defaults read sogod WOPort` if [ "$?" == "0" ] then - startport=`echo $startport | awk '{print $3}'` + startport=`echo $woport | awk '{print $3}' | sed -e 's/\(.*:\)//'` else startport=20000 fi @@ -69,8 +69,9 @@ then else let "port=$startport + $1 - 1" fi +listen=`echo $woport | awk '{ print $3 }' | sed -e 's/\([0-9]\+\)$/'$port'/g'` # echo "SOGOD: $sogod" 2>&1 -exec $sogod -WOPort $port >> /var/log/sogo/sogod-$port.log 2>&1 & +exec $sogod -WOPort $listen >> /var/log/sogo/sogod-$port.log 2>&1 & echo $! > $PIDFILE diff --git a/SoObjects/SOGo/LDAPSource.h b/SoObjects/SOGo/LDAPSource.h index dbe0fe0e7..df4ebc100 100644 --- a/SoObjects/SOGo/LDAPSource.h +++ b/SoObjects/SOGo/LDAPSource.h @@ -38,6 +38,7 @@ NSString *password; NSString *encryption; NSString *_filter; + NSString *_scope; NSString *baseDN; NSString *IDField; /* the first part of a user DN */ diff --git a/SoObjects/SOGo/LDAPSource.m b/SoObjects/SOGo/LDAPSource.m index b4fc87286..d84743ca6 100644 --- a/SoObjects/SOGo/LDAPSource.m +++ b/SoObjects/SOGo/LDAPSource.m @@ -167,6 +167,7 @@ static NSLock *lock; mailFields = [NSArray arrayWithObject: @"mail"]; [mailFields retain]; bindFields = nil; + _scope = @"sub"; _filter = nil; ldapConnection = nil; @@ -192,6 +193,7 @@ static NSLock *lock; [ldapConnection release]; [sourceID release]; [modulesConstraints release]; + [_scope release]; [super dealloc]; } @@ -199,7 +201,7 @@ static NSLock *lock; { self = [self init]; - ASSIGN (sourceID, [udSource objectForKey: @"id"]); + ASSIGN(sourceID, [udSource objectForKey: @"id"]); [self setBindDN: [udSource objectForKey: @"bindDN"] password: [udSource objectForKey: @"bindPassword"] @@ -212,9 +214,10 @@ static NSLock *lock; UIDField: [udSource objectForKey: @"UIDFieldName"] mailFields: [udSource objectForKey: @"MailFieldNames"] andBindFields: [udSource objectForKey: @"bindFields"]]; - ASSIGN (modulesConstraints, [udSource objectForKey: @"ModulesConstraints"]); - ASSIGN (_filter, [udSource objectForKey: @"filter"]); - + ASSIGN(modulesConstraints, [udSource objectForKey: @"ModulesConstraints"]); + ASSIGN(_filter, [udSource objectForKey: @"filter"]); + ASSIGN(_scope, ([udSource objectForKey: @"scope"] ? (id)[udSource objectForKey: @"scope"]: (id)@"sub")); + return self; } @@ -334,10 +337,31 @@ static NSLock *lock; if ([self _initLDAPConnection]) { - entries = [ldapConnection deepSearchAtBaseDN: baseDN - qualifier: - [self _qualifierForBindFilter: loginToCheck] - attributes: [NSArray arrayWithObject: @"dn"]]; + EOQualifier *qualifier; + NSArray *attributes; + + qualifier = [self _qualifierForBindFilter: loginToCheck]; + attributes = [NSArray arrayWithObject: @"dn"]; + + if ([_scope caseInsensitiveCompare: @"BASE"] == NSOrderedSame) + { + entries = [ldapConnection baseSearchAtBaseDN: baseDN + qualifier: qualifier + attributes: attributes]; + } + else if ([_scope caseInsensitiveCompare: @"ONE"] == NSOrderedSame) + { + entries = [ldapConnection flatSearchAtBaseDN: baseDN + qualifier: qualifier + attributes: attributes]; + } + else /* else we do like it was before */ + { + entries = [ldapConnection deepSearchAtBaseDN: baseDN + qualifier: qualifier + attributes: attributes]; + } + userEntry = [entries nextObject]; } else @@ -507,9 +531,23 @@ static NSLock *lock; ids = [NSMutableArray array]; if ([self _initLDAPConnection]) - entries = [ldapConnection deepSearchAtBaseDN: baseDN - qualifier: nil - attributes: [NSArray arrayWithObject: IDField]]; + { + NSArray *attributes; + + attributes = [NSArray arrayWithObject: IDField]; + if ([_scope caseInsensitiveCompare: @"BASE"] == NSOrderedSame) + entries = [ldapConnection baseSearchAtBaseDN: baseDN + qualifier: nil + attributes: attributes]; + else if ([_scope caseInsensitiveCompare: @"ONE"] == NSOrderedSame) + entries = [ldapConnection flatSearchAtBaseDN: baseDN + qualifier: nil + attributes: attributes]; + else /* else we do like it was before */ + entries = [ldapConnection deepSearchAtBaseDN: baseDN + qualifier: nil + attributes: attributes]; + } else entries = nil; @@ -638,9 +676,26 @@ static NSLock *lock; if ([match length] > 0) { if ([self _initLDAPConnection]) - entries = [ldapConnection deepSearchAtBaseDN: baseDN - qualifier: [self _qualifierForFilter: match] - attributes: [self _searchAttributes]]; + { + EOQualifier *qualifier; + NSArray *attributes; + + qualifier = [self _qualifierForFilter: match]; + attributes = [self _searchAttributes]; + + if ([_scope caseInsensitiveCompare: @"BASE"] == NSOrderedSame) + entries = [ldapConnection baseSearchAtBaseDN: baseDN + qualifier: qualifier + attributes: attributes]; + else if ([_scope caseInsensitiveCompare: @"ONE"] == NSOrderedSame) + entries = [ldapConnection flatSearchAtBaseDN: baseDN + qualifier: qualifier + attributes: attributes]; + else /* else we de like it was before */ + entries = [ldapConnection deepSearchAtBaseDN: baseDN + qualifier: qualifier + attributes: attributes]; + } else entries = nil; @@ -698,7 +753,6 @@ static NSLock *lock; NSDictionary *contactEntry; NGLdapEntry *ldapEntry; NSEnumerator *entries; - EOQualifier *qualifier; #if defined(THREADSAFE) [lock lock]; @@ -710,10 +764,25 @@ static NSLock *lock; { if ([self _initLDAPConnection]) { + EOQualifier *qualifier; + NSArray *attributes; + qualifier = [self _qualifierForUIDFilter: uid]; - entries = [ldapConnection deepSearchAtBaseDN: baseDN - qualifier: qualifier - attributes: [self _searchAttributes]]; + attributes = [self _searchAttributes]; + + if ([_scope caseInsensitiveCompare: @"BASE"] == NSOrderedSame) + entries = [ldapConnection baseSearchAtBaseDN: baseDN + qualifier: qualifier + attributes: attributes]; + else if ([_scope caseInsensitiveCompare: @"ONE"] == NSOrderedSame) + entries = [ldapConnection flatSearchAtBaseDN: baseDN + qualifier: qualifier + attributes: attributes]; + else /* else we do like it was before */ + entries = [ldapConnection deepSearchAtBaseDN: baseDN + qualifier: qualifier + attributes: attributes]; + ldapEntry = [entries nextObject]; } else