static BOOL useLDAP = NO;
static NSString *ldapHost = nil;
static NSString *ldapBaseDN = nil;
-static NSString *fallbackIMAP4Server = nil;
-static NSString *defaultMailDomain = @"equipement.gouv.fr";
+static NSString *fallbackIMAP4Server = nil;
+static NSString *defaultMailDomain = @"equipement.gouv.fr";
+static NSString *shareLDAPClass = @"mineqMelBoite";
+static NSString *shareLoginSeparator = @".-.";
+static NSString *mailEmissionAttrName = @"mineqMelmailEmission";
+
+static NSArray *fromEMailAttrs = nil;
+ (void)initialize {
static BOOL didInit = NO;
NSLog(@"Note: using fallback IMAP4 server: '%@'", fallbackIMAP4Server);
else
fallbackIMAP4Server = nil;
+
+ fromEMailAttrs =
+ [[NSArray alloc] initWithObjects:mailEmissionAttrName, nil];
}
+ (id)sharedUserManager {
- (id)init {
self = [super init];
if(self) {
- self->serverCache = [[SOGoLRUCache alloc] initWithCacheSize:10000];
- self->cnCache = [[SOGoLRUCache alloc] initWithCacheSize:10000];
- self->uidCache = [[SOGoLRUCache alloc] initWithCacheSize:10000];
- self->emailCache = [[SOGoLRUCache alloc] initWithCacheSize:10000];
+ self->serverCache = [[SOGoLRUCache alloc] initWithCacheSize:10000];
+ self->cnCache = [[SOGoLRUCache alloc] initWithCacheSize:10000];
+ self->uidCache = [[SOGoLRUCache alloc] initWithCacheSize:10000];
+ self->emailCache = [[SOGoLRUCache alloc] initWithCacheSize:10000];
+ self->shareStoreCache = [[SOGoLRUCache alloc] initWithCacheSize:10000];
+ self->shareEMailCache = [[SOGoLRUCache alloc] initWithCacheSize:10000];
}
return self;
}
- (void)dealloc {
- [self->serverCache release];
- [self->cnCache release];
- [self->uidCache release];
- [self->emailCache release];
+ [self->shareStoreCache release];
+ [self->shareEMailCache release];
+ [self->serverCache release];
+ [self->cnCache release];
+ [self->uidCache release];
+ [self->emailCache release];
[super dealloc];
}
}
- (NSString *)primaryGetEmailForAgenorUID:(NSString *)_uid {
- static NSArray *emailAttrs = nil;
NGLdapConnection *conn;
EOQualifier *q;
NSEnumerator *resultEnum;
NSString *email;
unsigned count;
- if (emailAttrs == nil)
- emailAttrs = [[NSArray alloc] initWithObjects:@"mineqMelmailEmission",nil];
-
q = [EOQualifier qualifierWithQualifierFormat:@"uid = %@", _uid];
conn = [self ldapConnection];
resultEnum = [conn deepSearchAtBaseDN:ldapBaseDN
qualifier:q
- attributes:emailAttrs];
+ attributes:fromEMailAttrs];
entry = [resultEnum nextObject];
if (entry == nil) {
if(debugOn) {
}
return nil;
}
- emailAttr = [entry attributeWithName:@"mineqMelmailEmission"];
+ emailAttr = [entry attributeWithName:mailEmissionAttrName];
if (emailAttr == nil)
return nil; /* shit happens */
-
+
email = nil;
count = [emailAttr count];
-#if 0
+#if 0 // TODO: explain why this is commented out!
if (count > 1) {
unsigned i;
Sample:
"(&(mineqMelPartages=guizmo.g:*)(objectclass=mineqMelBoite))"
"guizmo.g" is the uid of the user
-
+
Login:
guizmo.g.-.baluh.hommes.tests-montee-en-charge-ogo
(uid + ".-." + share-uid)
-
+
Note: shared mailboxes can be on different hosts!
*/
- static NSString *shareLDAPClass = @"mineqMelBoite";
- static NSString *shareLoginSeparator = @".-.";
NSMutableArray *shares = nil;
NGLdapConnection *conn;
- EOQualifier *q;
- NSString *sharePattern;
- NSEnumerator *resultEnum;
- NGLdapEntry *entry;
+ EOQualifier *q;
+ NSString *sharePattern;
+ NSEnumerator *resultEnum;
+ NGLdapEntry *entry;
if ([_uid length] == 0)
return nil;
@"Note: LDAP access is disabled, returning no shared accounts."];
return nil;
}
+
+ /* check cache */
+ if ((shares = [self->shareStoreCache objectForKey:_uid]) != nil)
+ return shares;
sharePattern = [_uid stringByAppendingString:@":*"];
shareLogin = [shareLogin stringByAppendingString:server];
[shares addObject:shareLogin];
}
+
+ /* ensure that ordering is always the same */
+ [shares sortUsingSelector:@selector(compare:)];
+
+ /* cache */
+ shares = (shares == nil) ? [NSArray array] : [[shares copy] autorelease];
+ [self->shareStoreCache addObject:shares forKey:_uid];
+ return shares;
+}
+
+- (NSArray *)getSharedMailboxEMailsForUID:(NSString *)_uid {
+ NSMutableArray *shares = nil;
+ NGLdapConnection *conn;
+ EOQualifier *q;
+ NSString *gPattern, *cPattern;
+ NSEnumerator *resultEnum;
+ NGLdapEntry *entry;
+
+ if ([_uid length] == 0)
+ return nil;
+
+ if (!useLDAP) {
+ [self logWithFormat:
+ @"Note: LDAP access is disabled, returning no shared froms."];
+ return nil;
+ }
+
+ /* check cache */
+ if ((shares = [self->shareEMailCache objectForKey:_uid]) != nil)
+ return shares;
+
+ /* G and C mean "emission access" */
+ gPattern = [_uid stringByAppendingString:@":G"];
+ cPattern = [_uid stringByAppendingString:@":C"];
+
+ q = [EOQualifier qualifierWithQualifierFormat:
+ @"((mineqMelPartages = %@) OR (mineqMelPartages = %@)) "
+ @"AND (objectclass = %@)",
+ gPattern, cPattern, shareLDAPClass];
+
+ conn = [self ldapConnection];
+
+ resultEnum = [conn deepSearchAtBaseDN:ldapBaseDN
+ qualifier:q
+ attributes:fromEMailAttrs];
+
+ while ((entry = [resultEnum nextObject]) != nil) {
+ id emissionAttr;
+
+ emissionAttr = [entry attributeWithName:mailEmissionAttrName];
+ if ([emissionAttr count] == 0) {
+ [self logWithFormat:@"WARNING: share has no %@ attr: %@",
+ mailEmissionAttrName, [entry dn]];
+ continue;
+ }
+
+ if ([emissionAttr count] > 1) {
+ [self logWithFormat:
+ @"WARNING: share has more than one value in %@ attr: %@",
+ mailEmissionAttrName, [entry dn]];
+ continue;
+ }
+
+ emissionAttr = [emissionAttr stringValueAtIndex:0];
+ if (shares == nil) shares = [NSMutableArray arrayWithCapacity:4];
+ [shares addObject:emissionAttr];
+ }
+
+ /* ensure that ordering is always the same */
+ [shares sortUsingSelector:@selector(compare:)];
+
+ /* cache */
+ shares = (shares == nil) ? [NSArray array] : [[shares copy] autorelease];
+ [self->shareEMailCache addObject:shares forKey:_uid];
return shares;
}
--- /dev/null
+/*
+ Copyright (C) 2005 SKYRIX Software AG
+
+ This file is part of OpenGroupware.org.
+
+ OGo is free software; you can redistribute it and/or modify it under
+ the terms of the GNU Lesser General Public License as published by the
+ Free Software Foundation; either version 2, or (at your option) any
+ later version.
+
+ OGo 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 Lesser General Public
+ License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with OGo; see the file COPYING. If not, write to the
+ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+ 02111-1307, USA.
+*/
+
+#include "AgenorUserManager.h"
+#include "common.h"
+
+static void usage(NSArray *args) {
+ fprintf(stderr, "usage: %s <uid1> <uid2> <uid3>\n",
+ [[args objectAtIndex:0] cString]);
+}
+
+static void handleUID(NSString *uid, AgenorUserManager *userManager) {
+ NSArray *emails;
+ NSString *primary;
+ unsigned i, count;
+
+ primary = [userManager getEmailForUID:uid];
+ emails = [userManager getSharedMailboxEMailsForUID:uid];
+
+ printf("%s:", [uid cString]);
+
+ if ([primary length] > 0)
+ printf(" %s\n", [primary cString]);
+ else
+ printf(" <no primary email found>\n");
+
+ if ((count = [emails count]) == 0) {
+ printf(" <no shares with emitter access>\n");
+ return;
+ }
+
+ for (i = 0; i < count; i++)
+ printf(" %s\n", [[emails objectAtIndex:i] cString]);
+}
+
+static void doIt(NSArray *args) {
+ AgenorUserManager *userManager;
+ NSEnumerator *e;
+ NSString *uid;
+
+ if ([args count] < 2) {
+ usage(args);
+ return;
+ }
+
+ userManager = [AgenorUserManager sharedUserManager];
+
+ e = [args objectEnumerator];
+ [e nextObject]; /* consume the command name */
+
+ while ((uid = [e nextObject]) != nil)
+ handleUID(uid, userManager);
+}
+
+int main(int argc, char **argv, char **env) {
+ NSAutoreleasePool *pool;
+
+ pool = [[NSAutoreleasePool alloc] init];
+#if LIB_FOUNDATION_LIBRARY
+ [NSProcessInfo initializeWithArguments:argv count:argc environment:env];
+#endif
+
+ doIt([[NSProcessInfo processInfo] argumentsWithoutDefaults]);
+
+ [pool release];
+ return 0;
+}