Re: Group Identity Programming [SOLVED]
Just wanted to say thanks for the help. Your solution worked. :) Jessica CBGroupIdentity is a subclass of CBIdentity. So in the NSArray of CBIdentity items returned from the identity picker, you test whether each item is a CBGroupIdentity or not using the normal Objective-C mechanism: [someItem isKindOfClass:CBGroupIdentity] Once you've identified a CBGroupIdentity, then type-cast it to (CBGroupIdentity*). Then test whether the CBIdentity of the current user is a member of that group using the -members method and searching the resulting NSArray. The search should be recursive, since I saw nothing prohibiting nested membership, only a prohibition against circular membership. Of course, if the array of CBIdentity's from the identity picker doesn't contain any groups, then the user isn't going to be a member of any of them, and you search the identity picker's NSArray for CBIdentity presence. If that sounds like a recursive search of a group's -members NSArray, it is. To me, the problem doesn't seem to have anything to do with group identity per se. It seems to hinge entirely on the subclass/ superclass relationship, and identifying specific subclass types. It's possible I've made an error in the above. I only spent a few minutes reading the class docs and Identity Services Programming Guide, and without looking any further, this seems like the simplest thing that might work. -- GG ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Group Identity Programming
The third thing I tried is getting the gid using: gid_t curGroupID = getgid(); OR int curGroupID = getgid(); CBGroupIdentity *groupIdentity = [CBGroupIdentity groupIdentityWithPosixGID:curGroupID authority:[CBIdentityAuthority defaultIdentityAuthority]]; When I try to show the gid using NSLog, it hangs the program. When I show the groupIdentity object, it returns (null). The above is better. What does the debugger show for curGroupID? There is no reason to hang on NSLog if for curGroupID, as it is really juts an unsigned int. What is the NSLog code you are using? Thank you for your help! The reason NSLog was hanging is that I was using the wrong formatting token. When I use: NSLog(@current group id: %i, curGroupID); I get current group id: 1612776775, which I'm assuming is right. However, I am still getting Current group info: (null) when I do: CBGroupIdentity *groupIdentity = [CBGroupIdentity groupIdentityWithPosixGID:curGroupID authority:[CBIdentityAuthority defaultIdentityAuthority]]; NSLog(@Current group info: %@, groupIdenditity); Unfortunately, I don't know if solving this problem will solve my ultimate problem (although I'm sure it will help!). My ultimate problem is that I have a number of group identities chosen by the identity picker. I need to look at their member lists and see if the logged-in user is in any of those lists. What I can't figure out is how to get access to the member lists of the groups that I get using the identity picker. I think this has to do with the fact that the identity picker returns CBIdentity objects, but how would one make a CBGroupIdentity object using the information from the CBIdentity object for a particular group identity? The only way I can see to make a CBGroupIdentity object is using the above code, but as the documentation says: The getgid() function returns the real group ID of the calling process ... The real group ID is specified at login time. The real group ID is the group of the user who invoked the program. What group is this referring to? If I made a local test_group and put the user in that, would it be the gid of test_group? What if the user is an many groups, both local and managed? This is the heart of my problem. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Group Identity Programming
On Wed, Apr 29, 2009 at 9:36 AM, Jessica Billings slaveofosi...@gmail.com wrote: What group is this referring to? If I made a local test_group and put the user in that, would it be the gid of test_group? What if the user is an many groups, both local and managed? This is the heart of my problem. Users in UNIX have a single primary group and potentially multiple secondary groups. The real gid of a user is that user's primary group, unless it's been changed by setgid. --Kyle Sluder ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Group Identity Programming
Jessica Billings wrote: My ultimate problem is that I have a number of group identities chosen by the identity picker. I need to look at their member lists and see if the logged-in user is in any of those lists. What I can't figure out is how to get access to the member lists of the groups that I get using the identity picker. I think this has to do with the fact that the identity picker returns CBIdentity objects, but how would one make a CBGroupIdentity object using the information from the CBIdentity object for a particular group identity? CBGroupIdentity is a subclass of CBIdentity. So in the NSArray of CBIdentity items returned from the identity picker, you test whether each item is a CBGroupIdentity or not using the normal Objective-C mechanism: [someItem isKindOfClass:CBGroupIdentity] Once you've identified a CBGroupIdentity, then type-cast it to (CBGroupIdentity*). Then test whether the CBIdentity of the current user is a member of that group using the -members method and searching the resulting NSArray. The search should be recursive, since I saw nothing prohibiting nested membership, only a prohibition against circular membership. Of course, if the array of CBIdentity's from the identity picker doesn't contain any groups, then the user isn't going to be a member of any of them, and you search the identity picker's NSArray for CBIdentity presence. If that sounds like a recursive search of a group's -members NSArray, it is. To me, the problem doesn't seem to have anything to do with group identity per se. It seems to hinge entirely on the subclass/ superclass relationship, and identifying specific subclass types. It's possible I've made an error in the above. I only spent a few minutes reading the class docs and Identity Services Programming Guide, and without looking any further, this seems like the simplest thing that might work. -- GG ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Group Identity Programming
On Apr 29, 2009, at 7:36 AM, Jessica Billings wrote: The third thing I tried is getting the gid using: gid_t curGroupID = getgid(); OR int curGroupID = getgid(); CBGroupIdentity *groupIdentity = [CBGroupIdentity groupIdentityWithPosixGID:curGroupID authority:[CBIdentityAuthority defaultIdentityAuthority]]; When I try to show the gid using NSLog, it hangs the program. When I show the groupIdentity object, it returns (null). The above is better. What does the debugger show for curGroupID? There is no reason to hang on NSLog if for curGroupID, as it is really juts an unsigned int. What is the NSLog code you are using? Thank you for your help! The reason NSLog was hanging is that I was using the wrong formatting token. When I use: NSLog(@current group id: %i, curGroupID); I get current group id: 1612776775, which I'm assuming is right. However, I am still getting Current group info: (null) when I do: That is certainly an odd GID, but I suppose it could be. Leopard changed everything again, so who knows. Anyway, remember that there is no correspondence between the Unix user/group management and the Mac OS X system user management. It is possible that the Unix-based means of acquiring UIDs and GIDs doesn't work with the Mac's way of doing things. Check your values against what you expect them to be. To get the UID and GID for a user, right-click on the user in the system accounts pane (system prefs), choosing advanced options. I would also check the getuid() call and see if it returns the expected UID. This will tell you whether the C calls know about Mac user handling. CBGroupIdentity *groupIdentity = [CBGroupIdentity groupIdentityWithPosixGID:curGroupID authority:[CBIdentityAuthority defaultIdentityAuthority]]; NSLog(@Current group info: %@, groupIdenditity); Unfortunately, I don't know if solving this problem will solve my ultimate problem (although I'm sure it will help!). My ultimate problem is that I have a number of group identities chosen by the identity picker. I need to look at their member lists and see if the logged-in user is in any of those lists. What I can't figure out is how to get access to the member lists of the groups that I get using the identity picker. I think this has to do with the fact that the identity picker returns CBIdentity objects, but how would one make a CBGroupIdentity object using the information from the CBIdentity object for a particular group identity? The only way I can see to make a CBGroupIdentity object is using the above code, but as the documentation If the getgid/getuid functions don't work, I don't know what to tell you. You could try digging into the new user management system (man dscl), or NSTask to the id utility (man id). HTH, Keary Suska Esoteritech, Inc. Demystifying technology for your home or business ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Group Identity Programming
Hi all, First of all, I apologize because I have only been developing Cocoa for a few months and I'm learning as I go. Hopefully I'm not making some newbie mistake. I am trying to write a program that, among other things, generates a list of user and group identities using the identity picker and then checks to see if the logged-on user matches any user identity or is a member of any group. I can do the first task, but I am having trouble with the group identity part. My main issue, I believe, is that I cannot get to the group-specific attributes (gid and members). I have tried the function identityWithName:authority: two different ways: CBGroupIdentity *groupID = [CBGroupIdentity identityWithName:[tmpArray objectAtIndex:i] authority:[CBIdentityAuthority defaultIdentityAuthority]]; CBGroupIdentity *groupID = [CBIdentity identityWithName:[tmpArray objectAtIndex:i] authority:[CBIdentityAuthority defaultIdentityAuthority]]; The tmpArray objectAtIndex:i is an NSString representation of the group's name, but I have also tried it with the UUID. This gives me the warning initilization from distinct Objective-C type. When I try to call members or posixGID on either of these, the program hangs. Also, I have tried to just circumvent creating a group identity and get to the heart of the matter by doing the following, using a test group I generated myself on the local machine (the other groups were made by someone else and are not local groups): NSString *user = NSUserName(); CBIdentity *localIdentity = [CBIdentity identityWithName:user authority:[CBIdentityAuthority defaultIdentityAuthority]]; [localIdentity isMemberOfGroup:[CBGroupIdentity identityWithName:@test_group authority:[CBIdentityAuthority localIdentityAuthority]]]; This hangs the program. The third thing I tried is getting the gid using: gid_t curGroupID = getgid(); OR int curGroupID = getgid(); CBGroupIdentity *groupIdentity = [CBGroupIdentity groupIdentityWithPosixGID:curGroupID authority:[CBIdentityAuthority defaultIdentityAuthority]]; When I try to show the gid using NSLog, it hangs the program. When I show the groupIdentity object, it returns (null). I have both the Collaboration and Foundation frameworks imported. If anyone can help me with this, I'd really appreciate it. This is driving me insane. Thanks, Jessica ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Group Identity Programming
On Apr 28, 2009, at 8:58 AM, Jessica Billings wrote: I am trying to write a program that, among other things, generates a list of user and group identities using the identity picker and then checks to see if the logged-on user matches any user identity or is a member of any group. I can do the first task, but I am having trouble with the group identity part. My main issue, I believe, is that I cannot get to the group-specific attributes (gid and members). I have tried the function identityWithName:authority: two different ways: CBGroupIdentity *groupID = [CBGroupIdentity identityWithName:[tmpArray objectAtIndex:i] authority:[CBIdentityAuthority defaultIdentityAuthority]]; CBGroupIdentity *groupID = [CBIdentity identityWithName:[tmpArray objectAtIndex:i] authority:[CBIdentityAuthority defaultIdentityAuthority]]; Why do think this would work at all? It is not consistent with the documentation. -identityWithName:authority: returns a CBIdentity object, not a CBGroupIdentity object. So of course it will not respond to CBGroupIdentity instance methods. The tmpArray objectAtIndex:i is an NSString representation of the group's name, but I have also tried it with the UUID. This gives me the warning initilization from distinct Objective-C type. When I try to call members or posixGID on either of these, the program hangs. This should have been the first clue that you're doing something wrong. Also, I have tried to just circumvent creating a group identity and get to the heart of the matter by doing the following, using a test group I generated myself on the local machine (the other groups were made by someone else and are not local groups): NSString *user = NSUserName(); CBIdentity *localIdentity = [CBIdentity identityWithName:user authority:[CBIdentityAuthority defaultIdentityAuthority]]; [localIdentity isMemberOfGroup:[CBGroupIdentity identityWithName:@test_group authority:[CBIdentityAuthority localIdentityAuthority]]]; Except that you aren't circumventing anything, you are juts doing the same wrong thing: [CBGroupIdentity identityWithName:@test_groupauthority:[CBIdentityAuthority localIdentityAuthority]]. You cannot get a group identity this way. The third thing I tried is getting the gid using: gid_t curGroupID = getgid(); OR int curGroupID = getgid(); CBGroupIdentity *groupIdentity = [CBGroupIdentity groupIdentityWithPosixGID:curGroupID authority:[CBIdentityAuthority defaultIdentityAuthority]]; When I try to show the gid using NSLog, it hangs the program. When I show the groupIdentity object, it returns (null). The above is better. What does the debugger show for curGroupID? There is no reason to hang on NSLog if for curGroupID, as it is really juts an unsigned int. What is the NSLog code you are using? Keary Suska Esoteritech, Inc. Demystifying technology for your home or business ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com