(fix) safety checks, fixed remove ALL and added add ALL
This commit is contained in:
parent
505079dfda
commit
6720b9aaed
|
@ -152,34 +152,143 @@ typedef enum
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (NSArray *) _fetchUserIDs
|
||||||
|
{
|
||||||
|
NSMutableArray *allUsers, *allSQLUsers;
|
||||||
|
NSAutoreleasePool *pool;
|
||||||
|
SOGoUserManager *lm;
|
||||||
|
NSDictionary *infos;
|
||||||
|
NSString *u;
|
||||||
|
|
||||||
|
int count, max;
|
||||||
|
|
||||||
|
lm = [SOGoUserManager sharedUserManager];
|
||||||
|
allSQLUsers = [[NSMutableArray alloc] init];
|
||||||
|
allUsers = [[NSMutableArray alloc] init];
|
||||||
|
|
||||||
|
if ([user isEqualToString: @"ALL"])
|
||||||
|
{
|
||||||
|
GCSChannelManager *cm;
|
||||||
|
NSURL *folderLocation;
|
||||||
|
GCSFolderManager *fm;
|
||||||
|
EOAdaptorChannel *fc;
|
||||||
|
NSArray *attrs;
|
||||||
|
NSString *sql;
|
||||||
|
|
||||||
|
fm = [GCSFolderManager defaultFolderManager];
|
||||||
|
cm = [fm channelManager];
|
||||||
|
folderLocation = [fm folderInfoLocation];
|
||||||
|
fc = [cm acquireOpenChannelForURL: folderLocation];
|
||||||
|
if (fc)
|
||||||
|
{
|
||||||
|
allSQLUsers = [NSMutableArray new];
|
||||||
|
sql = [NSString stringWithFormat: @"SELECT DISTINCT c_path2 FROM %@",
|
||||||
|
[folderLocation gcsTableName]];
|
||||||
|
[fc evaluateExpressionX: sql];
|
||||||
|
attrs = [fc describeResults: NO];
|
||||||
|
while ((infos = [fc fetchAttributes: attrs withZone: NULL]))
|
||||||
|
{
|
||||||
|
u = [infos objectForKey: @"c_path2"];
|
||||||
|
if (u)
|
||||||
|
[allSQLUsers addObject: u];
|
||||||
|
}
|
||||||
|
[cm releaseChannel: fc];
|
||||||
|
}
|
||||||
|
|
||||||
|
// We add our system users
|
||||||
|
[allSQLUsers addObject: @"<default>"];
|
||||||
|
|
||||||
|
if ([[SOGoSystemDefaults sharedSystemDefaults] enablePublicAccess])
|
||||||
|
[allSQLUsers addObject: @"anonymous"];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
[allSQLUsers addObject: user];
|
||||||
|
|
||||||
|
pool = [[NSAutoreleasePool alloc] init];
|
||||||
|
max = [allSQLUsers count];
|
||||||
|
|
||||||
|
for (count = 0; count < max; count++)
|
||||||
|
{
|
||||||
|
if (count > 0 && count%100 == 0)
|
||||||
|
{
|
||||||
|
DESTROY(pool);
|
||||||
|
pool = [[NSAutoreleasePool alloc] init];
|
||||||
|
}
|
||||||
|
|
||||||
|
u = [allSQLUsers objectAtIndex: count];
|
||||||
|
|
||||||
|
// We skip lookup for our 'system users' and the owner
|
||||||
|
if ([u isEqualToString: @"anonymous"] || [u isEqualToString: @"<default>"] || [u isEqualToString: owner])
|
||||||
|
continue;
|
||||||
|
|
||||||
|
infos = [lm contactInfosForUserWithUIDorEmail: u];
|
||||||
|
if (infos)
|
||||||
|
[allUsers addObject: [infos objectForKey: @"c_uid"]];
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// We haven't found the user based on the GCS table name
|
||||||
|
// Let's try to strip the domain part and search again.
|
||||||
|
// This can happen when using SOGoEnableDomainBasedUID (YES)
|
||||||
|
// but login in SOGo using a UID without domain (DomainLessLogin gets set)
|
||||||
|
NSRange r;
|
||||||
|
|
||||||
|
r = [u rangeOfString: @"@"];
|
||||||
|
|
||||||
|
if (r.location != NSNotFound)
|
||||||
|
{
|
||||||
|
u = [u substringToIndex: r.location];
|
||||||
|
infos = [lm contactInfosForUserWithUIDorEmail: u];
|
||||||
|
if (infos)
|
||||||
|
[allUsers addObject: [infos objectForKey: @"c_uid"]];
|
||||||
|
else
|
||||||
|
NSLog (@"user '%@' unknown", u);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
NSLog (@"user '%@' unknown", u);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DESTROY(pool);
|
||||||
|
RELEASE(allSQLUsers);
|
||||||
|
|
||||||
|
return AUTORELEASE(allUsers);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
- (void) addACLForUser: (NSString *) theUser
|
- (void) addACLForUser: (NSString *) theUser
|
||||||
folder: (GCSFolder *) theFolder
|
folder: (GCSFolder *) theFolder
|
||||||
{
|
{
|
||||||
NSString *currentRole, *SQL, *path;
|
NSString *currentRole, *SQL, *path, *u;
|
||||||
EOAdaptorChannel *channel;
|
EOAdaptorChannel *channel;
|
||||||
int i;
|
NSArray *allUsers;
|
||||||
|
int i, j;
|
||||||
|
|
||||||
channel = [theFolder acquireAclChannel];
|
channel = [theFolder acquireAclChannel];
|
||||||
path = [NSString stringWithFormat: @"%@/%@", owner, folder];
|
path = [NSString stringWithFormat: @"%@/%@", owner, folder];
|
||||||
|
allUsers = [self _fetchUserIDs];
|
||||||
|
|
||||||
for (i = 0; i < [rights count]; i++)
|
for (i = 0; i < [allUsers count]; i++)
|
||||||
{
|
{
|
||||||
currentRole = [rights objectAtIndex: i];
|
u = [allUsers objectAtIndex: i];
|
||||||
if ([GCSFolderManager singleStoreMode])
|
NSLog(@"Settings rights for user %@", u);
|
||||||
SQL = [NSString stringWithFormat: @"INSERT INTO %@"
|
for (j = 0; j < [rights count]; j++)
|
||||||
@" (c_object, c_uid, c_role, c_folder_id)"
|
{
|
||||||
@" VALUES ('/%@', '%@', '%@', %@)",
|
currentRole = [rights objectAtIndex: j];
|
||||||
[theFolder aclTableName],
|
if ([GCSFolderManager singleStoreMode])
|
||||||
path, user, currentRole, [theFolder folderId]];
|
SQL = [NSString stringWithFormat: @"INSERT INTO %@"
|
||||||
else
|
@" (c_object, c_uid, c_role, c_folder_id)"
|
||||||
SQL = [NSString stringWithFormat: @"INSERT INTO %@"
|
@" VALUES ('/%@', '%@', '%@', %@)",
|
||||||
@" (c_object, c_uid, c_role)"
|
[theFolder aclTableName],
|
||||||
@" VALUES ('/%@', '%@', '%@')",
|
path, u, currentRole, [theFolder folderId]];
|
||||||
[theFolder aclTableName],
|
else
|
||||||
path, user, currentRole];
|
SQL = [NSString stringWithFormat: @"INSERT INTO %@"
|
||||||
[channel evaluateExpressionX: SQL];
|
@" (c_object, c_uid, c_role)"
|
||||||
|
@" VALUES ('/%@', '%@', '%@')",
|
||||||
|
[theFolder aclTableName],
|
||||||
|
path, u, currentRole];
|
||||||
|
[channel evaluateExpressionX: SQL];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) getACLForUser: (NSString *) theUser
|
- (void) getACLForUser: (NSString *) theUser
|
||||||
|
@ -231,13 +340,14 @@ typedef enum
|
||||||
NSString *qs, *path;
|
NSString *qs, *path;
|
||||||
|
|
||||||
if ([theUser isEqualToString: @"ALL"])
|
if ([theUser isEqualToString: @"ALL"])
|
||||||
qualifier = nil;
|
qs = [NSString stringWithFormat: @"c_uid LIKE '\%'", theUser];
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
qs = [NSString stringWithFormat: @"c_uid = '%@'", theUser];
|
qs = [NSString stringWithFormat: @"c_uid = '%@'", theUser];
|
||||||
qualifier = [EOQualifier qualifierWithQualifierFormat: qs];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
qualifier = [EOQualifier qualifierWithQualifierFormat: qs];
|
||||||
|
|
||||||
[theFolder deleteAclMatchingQualifier: qualifier];
|
[theFolder deleteAclMatchingQualifier: qualifier];
|
||||||
|
|
||||||
// We clear the cache. We first strip /Users/ from our path
|
// We clear the cache. We first strip /Users/ from our path
|
||||||
|
@ -261,14 +371,22 @@ typedef enum
|
||||||
fm = [GCSFolderManager defaultFolderManager];
|
fm = [GCSFolderManager defaultFolderManager];
|
||||||
f = [fm folderAtPath: [NSString stringWithFormat: @"/Users/%@/%@", owner, folder]];
|
f = [fm folderAtPath: [NSString stringWithFormat: @"/Users/%@/%@", owner, folder]];
|
||||||
|
|
||||||
if (command == ManageACLGet)
|
if (!f)
|
||||||
[self getACLForUser: user folder: f];
|
{
|
||||||
else if (command == ManageACLRemove)
|
NSLog(@"No folder %@ found for user %@", folder, owner);
|
||||||
[self removeACLForUser: user folder: f];
|
rc = NO;
|
||||||
else if (command == ManageACLAdd)
|
}
|
||||||
[self addACLForUser: user folder: f];
|
|
||||||
else
|
else
|
||||||
[self usage];
|
{
|
||||||
|
if (command == ManageACLGet)
|
||||||
|
[self getACLForUser: user folder: f];
|
||||||
|
else if (command == ManageACLRemove)
|
||||||
|
[self removeACLForUser: user folder: f];
|
||||||
|
else if (command == ManageACLAdd)
|
||||||
|
[self addACLForUser: user folder: f];
|
||||||
|
else
|
||||||
|
[self usage];
|
||||||
|
}
|
||||||
|
|
||||||
[pool release];
|
[pool release];
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue