2011-08-02 22:43:33 +02:00
|
|
|
/* MAPIStorePermissionsTable.m - this file is part of SOGo
|
|
|
|
*
|
2012-08-17 21:04:57 +02:00
|
|
|
* Copyright (C) 2011-2012 Inverse inc
|
2011-08-02 22:43:33 +02:00
|
|
|
*
|
|
|
|
* Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
|
|
|
|
*
|
|
|
|
* 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 3, 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.
|
|
|
|
*/
|
|
|
|
|
2016-02-17 16:09:18 +01:00
|
|
|
#import <Foundation/NSArray.h>
|
|
|
|
#import <Foundation/NSDictionary.h>
|
|
|
|
#import <Foundation/NSString.h>
|
|
|
|
#import <SOGo/SOGoFolder.h>
|
|
|
|
#import <SOGo/SOGoObject.h>
|
|
|
|
#import <SOGo/SOGoUser.h>
|
2011-11-18 16:26:03 +01:00
|
|
|
|
2016-02-17 16:09:18 +01:00
|
|
|
#import "MAPIStoreContext.h"
|
|
|
|
#import "MAPIStoreFolder.h"
|
|
|
|
#import "MAPIStoreTypes.h"
|
|
|
|
#import "MAPIStoreSamDBUtils.h"
|
2011-08-02 22:43:33 +02:00
|
|
|
#import "NSData+MAPIStore.h"
|
|
|
|
#import "NSString+MAPIStore.h"
|
|
|
|
|
2016-02-17 16:09:18 +01:00
|
|
|
#import "MAPIStorePermissionsTable.h"
|
2011-08-02 22:43:33 +02:00
|
|
|
|
2011-11-18 16:26:03 +01:00
|
|
|
#undef DEBUG
|
2016-02-17 16:09:18 +01:00
|
|
|
#include <mapistore/mapistore.h>
|
|
|
|
#include <mapistore/mapistore_errors.h>
|
2011-08-02 22:43:33 +02:00
|
|
|
|
|
|
|
@implementation MAPIStorePermissionEntry
|
|
|
|
|
|
|
|
+ (id) entryWithUserId: (NSString *) newUserId
|
2011-11-18 16:26:03 +01:00
|
|
|
andMemberId: (uint64_t) newMemberId
|
|
|
|
forFolder: (MAPIStoreFolder *) newFolder
|
2011-08-02 22:43:33 +02:00
|
|
|
{
|
|
|
|
MAPIStorePermissionEntry *newEntry;
|
|
|
|
|
2011-11-18 16:26:03 +01:00
|
|
|
newEntry = [[self alloc] initWithUserId: newUserId andMemberId: newMemberId
|
2012-06-29 19:59:38 +02:00
|
|
|
forFolder: newFolder];
|
2011-08-02 22:43:33 +02:00
|
|
|
[newEntry autorelease];
|
|
|
|
|
|
|
|
return newEntry;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id) initWithUserId: (NSString *) newUserId
|
2011-11-18 16:26:03 +01:00
|
|
|
andMemberId: (uint64_t) newMemberId
|
|
|
|
forFolder: (MAPIStoreFolder *) newFolder
|
2011-08-02 22:43:33 +02:00
|
|
|
{
|
2012-06-29 19:59:38 +02:00
|
|
|
if ((self = [self initInContainer: newFolder]))
|
2011-08-02 22:43:33 +02:00
|
|
|
{
|
|
|
|
ASSIGN (userId, newUserId);
|
2011-11-18 16:26:03 +01:00
|
|
|
memberId = newMemberId;
|
2011-08-02 22:43:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) dealloc
|
|
|
|
{
|
|
|
|
[userId release];
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
2011-11-18 16:26:03 +01:00
|
|
|
- (NSString *) userId
|
2011-08-02 22:43:33 +02:00
|
|
|
{
|
2011-11-18 16:26:03 +01:00
|
|
|
return userId;
|
|
|
|
}
|
2011-08-02 22:43:33 +02:00
|
|
|
|
2011-11-18 16:26:03 +01:00
|
|
|
- (uint64_t) memberId
|
|
|
|
{
|
|
|
|
return memberId;
|
|
|
|
}
|
2011-08-02 22:43:33 +02:00
|
|
|
|
2012-03-02 21:44:24 +01:00
|
|
|
- (int) getPidTagMemberId: (void **) data
|
|
|
|
inMemCtx: (TALLOC_CTX *) memCtx
|
2011-11-18 16:26:03 +01:00
|
|
|
{
|
|
|
|
*data = MAPILongLongValue (memCtx, memberId);
|
2011-08-02 22:43:33 +02:00
|
|
|
|
|
|
|
return MAPISTORE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2012-03-02 21:44:24 +01:00
|
|
|
- (int) getPidTagEntryId: (void **) data
|
|
|
|
inMemCtx: (TALLOC_CTX *) memCtx
|
2011-08-02 22:43:33 +02:00
|
|
|
{
|
2011-11-18 16:26:03 +01:00
|
|
|
NSData *entryId;
|
|
|
|
struct mapistore_connection_info *connInfo;
|
|
|
|
|
|
|
|
if (memberId == 0 || memberId == ULLONG_MAX)
|
|
|
|
entryId = [NSData data];
|
|
|
|
else
|
|
|
|
{
|
2012-08-09 21:42:38 +02:00
|
|
|
connInfo = [(MAPIStoreContext *) [container context] connectionInfo];
|
2015-12-30 15:22:08 +01:00
|
|
|
entryId = MAPIStoreInternalEntryId (connInfo, userId);
|
2011-11-18 16:26:03 +01:00
|
|
|
}
|
|
|
|
*data = [entryId asBinaryInMemCtx: memCtx];
|
2011-08-02 22:43:33 +02:00
|
|
|
|
|
|
|
return MAPISTORE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2012-03-02 21:44:24 +01:00
|
|
|
- (int) getPidTagMemberName: (void **) data
|
|
|
|
inMemCtx: (TALLOC_CTX *) memCtx
|
2011-08-02 22:43:33 +02:00
|
|
|
{
|
2011-11-18 16:26:03 +01:00
|
|
|
NSString *displayName;
|
|
|
|
|
|
|
|
if (memberId == 0)
|
|
|
|
displayName = @"";
|
|
|
|
else if (memberId == ULLONG_MAX)
|
|
|
|
displayName = @"Anonymous";
|
|
|
|
else
|
|
|
|
displayName = [[SOGoUser userWithLogin: userId] cn];
|
|
|
|
|
|
|
|
*data = [displayName asUnicodeInMemCtx: memCtx];
|
2011-08-02 22:43:33 +02:00
|
|
|
|
|
|
|
return MAPISTORE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2012-03-02 21:44:24 +01:00
|
|
|
- (int) getPidTagMemberRights: (void **) data
|
|
|
|
inMemCtx: (TALLOC_CTX *) memCtx
|
2011-08-02 22:43:33 +02:00
|
|
|
{
|
2011-11-18 16:26:03 +01:00
|
|
|
uint32_t rights;
|
|
|
|
NSArray *roles;
|
|
|
|
|
|
|
|
roles = [[(MAPIStoreFolder *) container aclFolder] aclsForUser: userId];
|
|
|
|
rights = [(MAPIStoreFolder *) container exchangeRightsForRoles: roles];
|
|
|
|
|
|
|
|
*data = MAPILongValue (memCtx, rights);
|
2011-08-02 22:43:33 +02:00
|
|
|
|
|
|
|
return MAPISTORE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation MAPIStorePermissionsTable
|
|
|
|
|
2011-11-18 16:26:03 +01:00
|
|
|
- (void) dealloc
|
|
|
|
{
|
|
|
|
[entries release];
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) _fetchEntries
|
|
|
|
{
|
|
|
|
NSArray *permEntries;
|
|
|
|
NSUInteger count, max;
|
|
|
|
MAPIStorePermissionEntry *entry;
|
|
|
|
|
|
|
|
entries = [NSMutableDictionary new];
|
|
|
|
permEntries = [(MAPIStoreFolder *) container permissionEntries];
|
|
|
|
max = [permEntries count];
|
|
|
|
for (count = 0; count < max; count++)
|
|
|
|
{
|
|
|
|
entry = [permEntries objectAtIndex: count];
|
|
|
|
[entries setObject: entry forKey: [entry userId]];
|
|
|
|
}
|
|
|
|
|
|
|
|
childKeys = [entries allKeys];
|
|
|
|
[childKeys retain];
|
|
|
|
}
|
|
|
|
|
2011-08-02 22:43:33 +02:00
|
|
|
- (NSArray *) childKeys
|
|
|
|
{
|
2011-11-18 16:26:03 +01:00
|
|
|
if (!entries)
|
|
|
|
[self _fetchEntries];
|
|
|
|
|
|
|
|
return childKeys;
|
2011-08-02 22:43:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *) restrictedChildKeys
|
|
|
|
{
|
|
|
|
return [self childKeys];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id) lookupChild: (NSString *) childKey
|
|
|
|
{
|
2011-11-18 16:26:03 +01:00
|
|
|
if (!entries)
|
|
|
|
[self _fetchEntries];
|
|
|
|
|
|
|
|
return [entries objectForKey: childKey];
|
2011-08-02 22:43:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|