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

    Joined:
    Mar 27, 2009
    #1
    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

    Joined:
    Aug 9, 2009
  3. slayerizer macrumors 6502a

    slayerizer

    Joined:
    Nov 9, 2012
    Location:
    Canada
    #3
    in C (should be compatible with objectiveC) you can call getuid()


    Code:
    int user;
    user = getuid();
    if (user == 0)
    {
    //code to be executed as root
    }
    else
    {
    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