Robert and John: copyPath and Unix permissions.
Robert and John: copyPath and Unix permissions.
- Subject: Robert and John: copyPath and Unix permissions.
- From: Lorenzo Puleo <email@hidden>
- Date: Tue, 09 Apr 2002 13:59:46 +0200
Hi,
may be I have found a solution to the copyPath behaviour. But my friends
robert and john (they really are invented) are not convinced about this.
:-)
They use to backup/sync their files and each one has the full privileges on
the otherone's files.
We know copyPath produces a destination file which gets the current creation
and modification date/time and the current user as owner.
And they don't want this; they want an exact copy of the source file, that
is, the same owner, the same creation and modification date, same
permissions, etc, etc. Since Cocoa doesn't grant a way to change the
creation date of the files, I used an old routine which does that. I'm going
to show the code:
--------------------------------
ok = [manager copyPath:source toPath:dest handler:nil];
// this copies the file but it sets the owner to the current user,
// it sets the creation and modification date/time to the
// current date/time, and Robert and John don't want this, thus...
if(ok){
NSMutableDictionary *freeAttribute = [NSMutableDictionary
dictionary];
[freeAttribute setDictionary:[manager fileAttributesAtPath:dest
traverseLink:NO]];
[freeAttribute setObject:[NSNumber numberWithInt:511]
forKey:@"NSFilePosixPermissions"];
ok = [manager changeFileAttributes:freeAttribute atPath:dest];
// 511 means ReadAndWrite permissions for owner/group/everyone,
// so later we can set the original creation date
if(ok){
// This sets the creation date, backup date, ...
// see the routine below
ok = [self SetCatInfo:source toDest:dest];
if(ok){
// if you logged in as "root", you will be able to
// restore the original owner this way
[freeAttribute setDictionary:[manager
fileAttributesAtPath:source traverseLink:NO]];
ok = [manager changeFileAttributes:freeAttribute atPath:dest];
}
}
}
// we can set more than the creation and backup date with this
- (BOOL)SetCatInfo:(NSString*)sourceItem toDest:(NSString*)destItem
{
int err;
UInt8 *path;
FSRef sourceRef, destRef;
Boolean isFSDirectory;
FSCatalogInfo theInfo;
path = (UInt8*)[sourceItem UTF8String];
err = FSPathMakeRef(path, &sourceRef, &isFSDirectory);
if(err) return NO;
err = FSGetCatalogInfo(&sourceRef, kFSCatInfoSettableInfo, &theInfo,
nil, nil, nil);
if(err) return NO;
path = (UInt8*)[destItem UTF8String];
err = FSPathMakeRef(path, &destRef, &isFSDirectory);
if(err) return NO;
err = FSSetCatalogInfo(&destRef, kFSCatInfoSettableInfo, &theInfo);
if(err) return NO;
return YES;
}
--------------------------------
Well, if I logged in as "root" every file has been copied fine.
But, what does it happen if I logged in as "robert"? Let's go to check that.
If robert backed-up a john's file (robert has the ReadAndWrite permissions)
he obtains a robert's file. The "changeFileAttributes" command can't change
the file owner if the user is not the "root" user.
Let's figure out a backup/sync application which does that...
The john's source file has been copied to the destination disk as a robert's
file.
Then robert modifies this destination file and sync again. Since the
destination file has the most recent modification date, it replaces the
john's source file. Result?
John is not long the owner of his source file.
John screams! I can hear him. ;-)
Other hand, Robert has the privileges to read and write the john's file, so
he expects to be able to copy/duplicate/backup/sync that. He doesn't want to
"purchase" the john's file, but only to mantain it. And John allows this.
The backup application, since the OS behaves this way, just to prevent
changing of the file owner (and to avoid to hear John screaming), denies to
robert to copy the john's files, even if robert has got all the privileges
to do that. Robert is screaming too! He "has" the ReadAndWrite permissions.
They have to call the superuser "root" to backup/sync their files.
What do Robert and John (and me) have to do to obtain this? Both of them are
not superusers (root). Since I'm new to this topic I would really be glad to
get a suggestion.
@end
Thanks for your attention.
--
Lorenzo Puleo
mailto:email@hidden
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.