Merge branch 'fix/email-notif-auth'

pull/13/head
Jean Raby 2013-08-27 14:37:52 -04:00
commit d7851999da
10 changed files with 402 additions and 67 deletions

View File

@ -55,6 +55,7 @@ SOGo_HEADER_FILES = \
SOGoCASSession.h \
SOGoDAVAuthenticator.h \
SOGoProxyAuthenticator.h \
SOGoStaticAuthenticator.h \
SOGoWebAuthenticator.h \
SOGoWebDAVAclManager.h \
SOGoWebDAVValue.h \
@ -67,7 +68,9 @@ SOGo_HEADER_FILES = \
WORequest+SOGo.h \
WOResourceManager+SOGo.h \
WOResponse+SOGo.h \
WOContext+SOGo.h
WOContext+SOGo.h \
\
SOGoCredentialsFile.h
# daemon tool
all::
@ -124,6 +127,7 @@ SOGo_OBJC_FILES = \
SOGoCASSession.m \
SOGoDAVAuthenticator.m \
SOGoProxyAuthenticator.m \
SOGoStaticAuthenticator.m \
SOGoWebAuthenticator.m \
SOGoWebDAVAclManager.m \
SOGoWebDAVValue.m \
@ -136,7 +140,10 @@ SOGo_OBJC_FILES = \
WORequest+SOGo.m \
WOResourceManager+SOGo.m \
WOResponse+SOGo.m \
WOContext+SOGo.m
WOContext+SOGo.m \
\
SOGoCredentialsFile.m
SOGo_RESOURCE_FILES = \
SOGoDefaults.plist \

View File

@ -0,0 +1,43 @@
/* SOGoCredentialsFile.h - this file is part of SOGo
*
* Copyright (C) 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
* 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.
*/
#ifndef SOGOCREDENTIALSFILE_H
#define SOGOCREDENTIALSFILE_H
#import <Foundation/NSObject.h>
@interface SOGoCredentialsFile : NSObject
{
NSString *_credentialsFile;
NSString *_username, *_password;
}
+ (id) credentialsFromFile: (NSString *) file;
- (id) initFromFile: (NSString *) file
withEncoding: (NSStringEncoding) enc;
- (NSString *) username;
- (NSString *) password;
- (NSString *) credentialsFile;
@end
#endif /* SOGOCREDENTIALSFILE_H */

View File

@ -0,0 +1,113 @@
/* SOGoCredentialsFile.m - this file is part of SOGo
*
* Copyright (C) 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
* 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/NSCharacterSet.h>
#import <Foundation/NSData.h>
#import <Foundation/NSString.h>
#import "SOGoCredentialsFile.h"
@implementation SOGoCredentialsFile
+ (id) credentialsFromFile: (NSString *) file
{
SOGoCredentialsFile *newCreds;
newCreds = [[self alloc] initFromFile: file
withEncoding: NSUTF8StringEncoding];
[newCreds autorelease];
return newCreds;
}
- (id) init
{
if ((self = [super init]))
{
_username = nil;
_password = nil;
_credentialsFile = nil;
}
return self;
}
- (void) dealloc
{
[_username release];
[_password release];
[_credentialsFile release];
[super dealloc];
}
- (id) initFromFile: (NSString *) file
withEncoding: (NSStringEncoding) enc
{
id ret;
NSData *credentialsData;
NSRange r;
NSString *creds;
ret = nil;
if (file)
{
if ((self = [self init]))
{
credentialsData = [NSData dataWithContentsOfFile: file];
if (credentialsData == nil)
NSLog(@"Failed to load credentials file: %@", file);
else
{
creds = [[NSString alloc] initWithData: credentialsData
encoding: enc];
[creds autorelease];
creds = [creds stringByTrimmingCharactersInSet:
[NSCharacterSet characterSetWithCharactersInString: @"\r\n"]];
r = [creds rangeOfString: @":"];
if (r.location == NSNotFound)
NSLog(@"Invalid credentials file content, missing ':' separator (%@)", file);
else
{
_username = [[creds substringToIndex: r.location] retain];
_password = [[creds substringFromIndex: r.location+1] retain];
_credentialsFile = [file retain];
ret = self;
}
}
}
}
return ret;
}
- (NSString *) username
{
return self->_username;
}
- (NSString *) password
{
return self->_password;
}
- (NSString *) credentialsFile
{
return self->_credentialsFile;
}
@end

View File

@ -35,6 +35,7 @@
#import "NSString+Utilities.h"
#import "SOGoAuthenticator.h"
#import "SOGoDomainDefaults.h"
#import "SOGoStaticAuthenticator.h"
#import "SOGoSystemDefaults.h"
#import "SOGoUser.h"
#import "SOGoUserManager.h"
@ -153,9 +154,13 @@
[client connectToAddress: addr];
if ([authenticationType isEqualToString: @"plain"])
{
login = [[SOGoUserManager sharedUserManager]
getExternalLoginForUID: [[authenticator userInContext: woContext] loginInDomain]
inDomain: [[authenticator userInContext: woContext] domain]];
/* XXX Allow static credentials by peeking at the classname */
if ([authenticator isKindOfClass: [SOGoStaticAuthenticator class]])
login = [(SOGoStaticAuthenticator *)authenticator username];
else
login = [[SOGoUserManager sharedUserManager]
getExternalLoginForUID: [[authenticator userInContext: woContext] loginInDomain]
inDomain: [[authenticator userInContext: woContext] domain]];
password = [authenticator passwordInContext: woContext];
if ([login length] == 0

View File

@ -0,0 +1,51 @@
/* SOGoStaticAuthenticator.h - this file is part of SOGo
*
* Copyright (C) 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
* 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.
*/
#ifndef SOGOSTATICAUTHENTICATOR_H
#define SOGOSTATICAUTHENTICATOR_H
#import <Foundation/NSObject.h>
#import "SOGoAuthenticator.h"
/*
SOGoStaticAuthenticator
*/
@interface SOGoStaticAuthenticator : NSObject <SOGoAuthenticator>
{
NSString *_username;
NSString *_password;
}
+ (id) authenticatorWithUser: (NSString *) user
andPassword: (NSString *) password;
- (id) initWithUser: (NSString *) user
andPassword: (NSString *) password;
- (NSString *) username;
@end
#endif /* SOGOSTATICAUTHENTICATOR_H */

View File

@ -0,0 +1,87 @@
/* SOGoStaticAuthenticator.m - this file is part of SOGo
*
* Copyright (C) 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
* 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/NSString.h>
#import "SOGoStaticAuthenticator.h"
@implementation SOGoStaticAuthenticator
+ (id) authenticatorWithUser: (NSString *) user
andPassword: (NSString *) password
{
SOGoStaticAuthenticator *newAuthenticator;
newAuthenticator = [[self alloc] initWithUser: user
andPassword: password];
[newAuthenticator autorelease];
return newAuthenticator;
}
- (id) init
{
if ((self = [super init]))
{
_username = nil;
_password = nil;
}
return self;
}
- (void) dealloc
{
[_username release];
[_password release];
[super dealloc];
}
- (id) initWithUser: (NSString *) user
andPassword: (NSString *) password;
{
if ((self = [self init]))
{
_username = [user retain];
_password = [password retain];
}
return self;
}
- (NSString *) passwordInContext: (WOContext *) context
{
return _password;
}
- (SOGoUser *) userInContext: (WOContext *) context
{
return nil;
}
- (NSString *) username
{
return _username;
}
- (NSString *) imapPasswordInContext: (WOContext *) context
forURL: (NSURL *) server
forceRenew: (BOOL) renew
{
return _password;
}
@end

View File

@ -25,8 +25,11 @@
#import <Foundation/NSObject.h>
#import <SOGo/SOGoStaticAuthenticator.h>
@interface SOGoEAlarmsNotifier : NSObject
{
SOGoStaticAuthenticator *staticAuthenticator;
}
- (BOOL) run;

View File

@ -1,6 +1,6 @@
/* SOGoEAlarmsNotifier.m - this file is part of SOGo
*
* Copyright (C) 2011 Inverse inc.
* Copyright (C) 2011-2013 Inverse inc.
*
* Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
*
@ -27,6 +27,7 @@
#import <Foundation/NSDictionary.h>
#import <Foundation/NSProcessInfo.h>
#import <Foundation/NSString.h>
#import <Foundation/NSUserDefaults.h>
#import <NGExtensions/NGHashMap.h>
#import <NGExtensions/NGQuotedPrintableCoding.h>
@ -38,12 +39,14 @@
#import <NGCards/iCalEntityObject.h>
#import <NGCards/iCalPerson.h>
#import "SOGo/SOGoCredentialsFile.h"
#import <SOGo/NSCalendarDate+SOGo.h>
#import <SOGo/NSString+Utilities.h>
#import <SOGo/SOGoDomainDefaults.h>
#import <SOGo/SOGoSystemDefaults.h>
#import <SOGo/SOGoMailer.h>
#import <SOGo/SOGoProductLoader.h>
#import <SOGo/SOGoStaticAuthenticator.h>
#import <SOGo/SOGoSystemDefaults.h>
#import <SOGo/SOGoUser.h>
#import <Appointments/iCalPerson+SOGo.h>
#import <Appointments/SOGoEMailAlarmsManager.h>
@ -52,6 +55,21 @@
@implementation SOGoEAlarmsNotifier
- (id) init
{
if ((self = [super init]))
{
staticAuthenticator = nil;
}
return self;
}
- (void) dealloc
{
[staticAuthenticator release];
[super dealloc];
}
- (NSString *) _messageID
{
static int pid = 0;
@ -124,11 +142,10 @@
[message setBody: content];
to = [attendee rfc822Email];
/* TODO: SMTP authentication for services */
[mailer sendMimePart: message
toRecipients: [NSArray arrayWithObject: to]
sender: from
withAuthenticator: nil inContext: nil];
withAuthenticator: staticAuthenticator inContext: nil];
}
- (void) _processAlarm: (iCalAlarm *) alarm
@ -160,14 +177,45 @@
withMailer: mailer];
}
- (void) usage
{
fprintf (stderr, "sogo-ealarms-notify [-p credentialFile] [-h]\n\n"
" -p credentialFile Specify the file containing credentials to use for SMTP AUTH\n"
" The file should contain a single line:\n"
" username:password\n"
" -h This message\n"
"\n"
"This program should be configured to run every minute from a crontab.\n");
}
- (BOOL) run
{
SOGoEMailAlarmsManager *eaMgr;
SOGoCredentialsFile *cf;
NSCalendarDate *startDate, *toDate;
NSArray *alarms;
NSMutableArray *owners;
NSString *credsFilename;
int count, max;
if ([[NSUserDefaults standardUserDefaults] stringForKey: @"h"])
{
[self usage];
return YES;
}
credsFilename = [[NSUserDefaults standardUserDefaults] stringForKey: @"p"];
if (credsFilename)
{
cf = [SOGoCredentialsFile credentialsFromFile: credsFilename];
if (!cf)
return NO;
staticAuthenticator =
[SOGoStaticAuthenticator authenticatorWithUser: [cf username]
andPassword: [cf password]];
[staticAuthenticator retain];
}
[[SOGoProductLoader productLoader]
loadProducts: [NSArray arrayWithObject: @"Appointments.SOGo"]];

View File

@ -1,6 +1,6 @@
/* SOGoToolUserPreferences.m - this file is part of SOGo
*
* Copyright (C) 2011 Inverse inc.
* Copyright (C) 2011-2013 Inverse inc.
*
* Author: Francis Lachapelle <flachapelle@inverse.ca>
*
@ -37,10 +37,11 @@
#import <NGExtensions/NSNull+misc.h>
#import <SOGo/NSString+Utilities.h>
#import <SOGo/SOGoUser.h>
#import <SOGo/SOGoSystemDefaults.h>
#import <SOGo/SOGoUserDefaults.h>
#import "SOGo/SOGoCredentialsFile.h"
#import <SOGo/SOGoSieveManager.h>
#import <SOGo/SOGoSystemDefaults.h>
#import <SOGo/SOGoUser.h>
#import <SOGo/SOGoUserDefaults.h>
#import "SOGoTool.h"
@ -180,9 +181,9 @@
- (BOOL) run
{
NSData *credsData;
NSRange r;
NSString *creds, *credsFile, *authname, *authpwd;
NSString *creds, *credsFilename, *authname, *authpwd;
SOGoCredentialsFile *cf;
BOOL rc;
int max;
@ -192,41 +193,34 @@
authpwd = nil;
rc = NO;
credsFile = [[NSUserDefaults standardUserDefaults] stringForKey: @"p"];
if (credsFile)
credsFilename = [[NSUserDefaults standardUserDefaults] stringForKey: @"p"];
if (credsFilename)
{
credsData = [NSData dataWithContentsOfFile: credsFile];
if (credsData == nil)
{
NSLog(@"Error reading credential file '%@'", credsFile);
return NO;
}
creds = [[NSString alloc] initWithData: credsData
encoding: NSUTF8StringEncoding];
[creds autorelease];
creds = [creds stringByTrimmingCharactersInSet:
[NSCharacterSet characterSetWithCharactersInString: @"\r\n"]];
cf = [SOGoCredentialsFile credentialsFromFile: credsFilename];
authname = [cf username];
authpwd = [cf password];
}
/* DEPRECATED: this is only kept around to avoid breaking existing setups */
if (max > 0)
{
/* assume we got the creds directly on the cli */
creds = [sanitizedArguments objectAtIndex: 0];
if (creds)
{
r = [creds rangeOfString: @":"];
if (r.location == NSNotFound)
{
NSLog(@"Invalid credential string format (user:pass)");
}
else
{
authname = [creds substringToIndex: r.location];
authpwd = [creds substringFromIndex: r.location+1];
}
}
}
if (creds)
{
r = [creds rangeOfString: @":"];
if (r.location == NSNotFound)
{
NSLog(@"Invalid credential string format (user:pass)");
}
else
{
authname = [creds substringToIndex: r.location];
authpwd = [creds substringFromIndex: r.location+1];
}
}
if (authname && authpwd)
{

View File

@ -1,6 +1,6 @@
/* SOGoToolUserPreferences.m - this file is part of SOGo
*
* Copyright (C) 2011 Inverse inc.
* Copyright (C) 2011-2013 Inverse inc.
*
* Author: Ludovic Marcotte <lmarcotte@inverse.ca>
*
@ -28,6 +28,7 @@
#import <Foundation/NSUserDefaults.h>
#import <SOGo/NSString+Utilities.h>
#import "SOGo/SOGoCredentialsFile.h"
#import <SOGo/SOGoUser.h>
#import <SOGo/SOGoUserDefaults.h>
#import <SOGo/SOGoUserSettings.h>
@ -109,34 +110,17 @@ typedef enum
[theKey caseInsensitiveCompare: @"Vacation"] == NSOrderedSame)
{
/* credentials file handling */
NSData *credsData;
NSRange r;
NSString *credsFile, *creds, *authname, *authpwd;
authname = nil;
authpwd = nil;
NSString *credsFilename, *authname, *authpwd;
SOGoCredentialsFile *cf;
credsFile = [[NSUserDefaults standardUserDefaults] stringForKey: @"p"];
if (credsFile)
credsFilename = [[NSUserDefaults standardUserDefaults] stringForKey: @"p"];
if (credsFilename)
{
/* TODO: add back support for user:pwd here? */
credsData = [NSData dataWithContentsOfFile: credsFile];
if (credsData == nil)
{
NSLog(@"Error reading credential file '%@'", credsFile);
return NO;
}
creds = [[NSString alloc] initWithData: credsData
encoding: NSUTF8StringEncoding];
[creds autorelease];
creds = [creds stringByTrimmingCharactersInSet:
[NSCharacterSet characterSetWithCharactersInString: @"\r\n"]];
r = [creds rangeOfString: @":"];
authname = [creds substringToIndex: r.location];
authpwd = [creds substringFromIndex: r.location+1];
cf = [SOGoCredentialsFile credentialsFromFile: credsFilename];
authname = [cf username];
authpwd = [cf password];
}
if (authname == nil || authpwd == nil)
{
NSLog(@"To update Sieve scripts, you must provide the \"-p credentialFile\" parameter");