How do I allow only administrators to access certain parts of an app?

Discussion in 'Mac Programming' started by moonman239, May 31, 2014.

  1. moonman239 macrumors 68000

    Mar 27, 2009
    Let's say I have a user-controlling app, and I want only users who are administrators to be allowed to change the settings. How would I accomplish this?
  2. chown33 macrumors 604

    Aug 9, 2009
    Sailing beyond the sunset
  3. slayerizer macrumors 6502a

    Nov 9, 2012
    in C (should be compatible with objectiveC) you can call getuid()

    int user;
    user = getuid();
    if (user == 0)
    //code to be executed as root
    cout << "root privleges needed";

    you can try your app from the terminal window..

    - launch your app with the current user
    - launch your app via sudo: sudo /path/myapplication

Share This Page