Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Nov 22, 2010, 09:40 PM   #1
MayPeng
macrumors member
 
Join Date: Nov 2010
How to get current user's status,guest or administrator?

I have a app,and I want to display a warning window if the current user hasn't the admin privilege at the beginning of the app start.So I want to get the current user's identity.
How can I get the user's identity in a simple way?
MayPeng is offline   0 Reply With Quote
Old Nov 23, 2010, 12:58 PM   #2
HiRez
macrumors 601
 
HiRez's Avatar
 
Join Date: Jan 2004
Location: Western US
You can use the NSUserName() function which returns an NSString. That would allow you to check if they're "guest", but wouldn't necessarily tell you if they have admin privileges. You could also maybe do something like call the UNIX 'id' function from an NSTask, which would show if the user is a member of group 80 (admin). There might be an easier or better way, I'm not sure, but those are a couple options.

EDIT: On further investigation, it appears there is an Objective-C SFAuthorization class that might do what you want. Check out the obtainWithRight:flags:error: method, which mentions "pre-authorizting", which sounds like it checks if the user has certain privileges.
__________________
Go outside, the graphics are amazing!

Last edited by HiRez; Nov 23, 2010 at 01:08 PM.
HiRez is offline   0 Reply With Quote
Old Nov 23, 2010, 02:25 PM   #3
chown33
macrumors 603
 
Join Date: Aug 2009
Quote:
Originally Posted by HiRez View Post
You can use the NSUserName() function which returns an NSString. That would allow you to check if they're "guest", but wouldn't necessarily tell you if they have admin privileges. You could also maybe do something like call the UNIX 'id' function from an NSTask, which would show if the user is a member of group 80 (admin). There might be an easier or better way, I'm not sure, but those are a couple options.
'id' is a command, not a function. A function would be a C function, like getgroups(), which can be called directly rather than being executed through NSTask.


In any case, the OP's basic premise is flawed. Just because the current user ID doesn't have admin privileges doesn't mean the person using the computer doesn't know the admin password. I usually run as a non-admin user, and only authenticate as needed. The program as described would incorrectly warn me that I'm not an admin user. The OP needs to read "Authorization Services Programming Guide":
http://developer.apple.com/library/m...uid/TP30000995
chown33 is online now   0 Reply With Quote
Old Nov 23, 2010, 10:53 PM   #4
MayPeng
Thread Starter
macrumors member
 
Join Date: Nov 2010
Quote:
Originally Posted by HiRez View Post
You can use the NSUserName() function which returns an NSString. That would allow you to check if they're "guest", but wouldn't necessarily tell you if they have admin privileges. You could also maybe do something like call the UNIX 'id' function from an NSTask, which would show if the user is a member of group 80 (admin). There might be an easier or better way, I'm not sure, but those are a couple options.

EDIT: On further investigation, it appears there is an Objective-C SFAuthorization class that might do what you want. Check out the obtainWithRight:flags:error: method, which mentions "pre-authorizting", which sounds like it checks if the user has certain privileges.
Thank you for your message.It is very valuable for me.I still have a problem , if I use NSUserName() to have obtained the user name how can I do next step to check whether they are "guest" or "administrator"?

I am unfamiliar to unix command such as "id",could you please tell me how to show if the user is a member of group 80 (admin) using NSTask.

Quote:
Originally Posted by chown33 View Post
'id' is a command, not a function. A function would be a C function, like getgroups(), which can be called directly rather than being executed through NSTask.


In any case, the OP's basic premise is flawed. Just because the current user ID doesn't have admin privileges doesn't mean the person using the computer doesn't know the admin password. I usually run as a non-admin user, and only authenticate as needed. The program as described would incorrectly warn me that I'm not an admin user. The OP needs to read "Authorization Services Programming Guide":
http://developer.apple.com/library/m...uid/TP30000995
Yes, using getgroups() function I can obtain group IDs,but how could it resolve my question? Thank you !

Last edited by kainjow; Nov 24, 2010 at 01:25 PM. Reason: merged posts
MayPeng is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Guest user account bug in 10.9.1 Luba OS X Mavericks (10.9) 8 Jan 21, 2014 04:40 AM
Guest Account User Picture Alfieg OS X Mavericks (10.9) 2 Dec 5, 2013 01:26 AM
how to change user administrator on mb bluebird3 MacBook 4 Oct 7, 2013 08:11 PM
Please help me get rid of guest user Ish Mac Basics and Help 3 Oct 7, 2013 09:11 AM
Administrator can't access standard user settings macmesser Mac OS X 10.7 Lion 2 Jul 12, 2013 01:01 PM

Forum Jump

All times are GMT -5. The time now is 12:17 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC