(fix) improved previous commit for attributes stripping and UID generation (fixes #3695 and #3696)

pull/210/head
Ludovic Marcotte 2016-05-27 10:53:16 -04:00
parent 604705960e
commit 875a4aca32
3 changed files with 54 additions and 20 deletions

View File

@ -41,12 +41,14 @@
#import <SOGo/NSDictionary+Utilities.h> #import <SOGo/NSDictionary+Utilities.h>
#import <SOGo/NSObject+DAV.h> #import <SOGo/NSObject+DAV.h>
#import <SOGo/NSObject+Utilities.h> #import <SOGo/NSObject+Utilities.h>
#import <SOGo/NSString+Crypto.h>
#import <SOGo/NSString+Utilities.h> #import <SOGo/NSString+Utilities.h>
#import <SOGo/SOGoBuild.h> #import <SOGo/SOGoBuild.h>
#import <SOGo/SOGoMailer.h> #import <SOGo/SOGoMailer.h>
#import <SOGo/SOGoGroup.h> #import <SOGo/SOGoGroup.h>
#import <SOGo/SOGoPermissions.h> #import <SOGo/SOGoPermissions.h>
#import <SOGo/SOGoUser.h> #import <SOGo/SOGoUser.h>
#import <SOGo/SOGoUserSettings.h>
#import <SOGo/SOGoSystemDefaults.h> #import <SOGo/SOGoSystemDefaults.h>
#import <SOGo/SOGoUserManager.h> #import <SOGo/SOGoUserManager.h>
#import <SOGo/SOGoWebDAVAclManager.h> #import <SOGo/SOGoWebDAVAclManager.h>
@ -202,14 +204,21 @@
- (void) _filterComponent: (iCalEntityObject *) component - (void) _filterComponent: (iCalEntityObject *) component
{ {
NSString *type, *summary, *tag; NSString *type, *summary, *tag, *uid;
NSArray *children; SOGoUserSettings *settings;
SOGoUser *calendarOwner;
NSEnumerator *children;
CardElement *element;
NSArray *tags;
int classification, i; int classification;
type = @"vtodo"; type = @"vtodo";
classification = 0; classification = 0;
calendarOwner = [SOGoUser userWithLogin: [self ownerInContext: context]];
settings = [calendarOwner userSettings];
if ([component isKindOfClass: [iCalEvent class]]) if ([component isKindOfClass: [iCalEvent class]])
type = @"vevent"; type = @"vevent";
@ -221,25 +230,23 @@
summary = [self labelForKey: [NSString stringWithFormat: @"%@_class%d", summary = [self labelForKey: [NSString stringWithFormat: @"%@_class%d",
type, classification] type, classification]
inContext: context]; inContext: context];
[component setSummary: summary];
[component setComment: @""];
[component setUserComment: @""];
[component setLocation: @""];
[component setCategories: [NSArray array]];
[component setUrl: @""];
[component setOrganizer: nil];
[component removeAllAttendees];
[component removeAllAlarms];
// We strip all X- tags tags = [NSArray arrayWithObjects: @"DTSTAMP", @"DTSTART", @"DTEND", @"DUE", @"EXDATE", @"EXRULE", @"RRULE", nil];
children = [component children]; uid = [[component uid] asCryptedPassUsingScheme: @"ssha256"
withSalt: [[settings userSalt] dataUsingEncoding: NSASCIIStringEncoding]
andEncoding: encHex];
for (i = 0; i < [children count]; i++) children = [[[[component children] copy] autorelease] objectEnumerator];
while ((element = [children nextObject]))
{ {
tag = [[children objectAtIndex: i] tag]; tag = [element tag];
if ([[tag uppercaseString] hasPrefix: @"X-"]) if (![tags containsObject: [tag uppercaseString]])
[component removeChild: [children objectAtIndex: i]]; [component removeChild: element];
} }
[component setSummary: summary];
[component setUid: uid];
} }
- (NSString *) secureContentAsString - (NSString *) secureContentAsString

View File

@ -1,6 +1,6 @@
/* SOGoUserSettings.h - this file is part of SOGo /* SOGoUserSettings.h - this file is part of SOGo
* *
* Copyright (C) 2009-2014 Inverse inc. * Copyright (C) 2009-2016 Inverse inc.
* *
* This file is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -33,6 +33,7 @@
- (NSArray *) subscribedCalendars; - (NSArray *) subscribedCalendars;
- (NSArray *) subscribedAddressBooks; - (NSArray *) subscribedAddressBooks;
- (NSString *) userSalt;
@end @end

View File

@ -1,6 +1,6 @@
/* SOGoUserSettings.m - this file is part of SOGo /* SOGoUserSettings.m - this file is part of SOGo
* *
* Copyright (C) 2009-2014 Inverse inc. * Copyright (C) 2009-2016 Inverse inc.
* *
* This file is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -19,9 +19,11 @@
*/ */
#import <Foundation/NSDictionary.h> #import <Foundation/NSDictionary.h>
#import <Foundation/NSProcessInfo.h>
#import <Foundation/NSString.h> #import <Foundation/NSString.h>
#import "SOGoUserProfile.h" #import "SOGoUserProfile.h"
#import "NSString+Crypto.h"
#import "SOGoUserSettings.h" #import "SOGoUserSettings.h"
@ -68,4 +70,28 @@ static Class SOGoUserProfileKlass = Nil;
return [self _subscribedFoldersForModule: @"Contacts"]; return [self _subscribedFoldersForModule: @"Contacts"];
} }
- (NSString *) userSalt
{
NSMutableDictionary *values;
NSString *salt;
salt = [[self dictionaryForKey: @"General"] objectForKey: @"Salt"];
if (!salt)
{
salt = [[[NSProcessInfo processInfo] globallyUniqueString] asSHA1String];
values = [self objectForKey: @"General"];
if (!values)
values = [NSMutableDictionary dictionary];
[values setObject: salt forKey: @"Salt"];
[self setObject: values forKey: @"General"];
[self synchronize];
}
return salt;
}
@end @end