User Installed Resouces (Admin Access)

  • I'm working on a new feature that allows the end user to install
    additional application resources post-install.

    I want to copy sound files to the application's support folder but I
    also want to give the user the option of installing the files for all
    users. An example of this can be seen in the System Preferences
    application when you install a new preference pane.

    I tried using NSFileManager and NSWorkspace methods to copy the files
    but they both fail and neither request authentication. I have hacked
    together some code that serves as a wrapper to
    AuthorizationExecuteWithPrivileges() allowing me to run arbitrary
    shell commands but I'd rather have a cleaner implementation.

    I'm also looking for a way to determine if the user has the rights to
    write to /Library/Application Support or if I have to put up an
    authorization panel before proceeding.

    Keith
  • On 9/18/07, Keith Duncan <keith_duncan...> wrote:
    > I'm working on a new feature that allows the end user to install
    > additional application resources post-install.
    >
    > I want to copy sound files to the application's support folder but I
    > also want to give the user the option of installing the files for all
    > users. An example of this can be seen in the System Preferences
    > application when you install a new preference pane.
    >
    > I tried using NSFileManager and NSWorkspace methods to copy the files
    > but they both fail and neither request authentication. I have hacked
    > together some code that serves as a wrapper to
    > AuthorizationExecuteWithPrivileges() allowing me to run arbitrary
    > shell commands but I'd rather have a cleaner implementation.
    >
    > I'm also looking for a way to determine if the user has the rights to
    > write to /Library/Application Support or if I have to put up an
    > authorization panel before proceeding.

    The admin group has write permission to /Library/Application Support.
    To determine if the current user has the right permission you could
    use getgrent("admin") to discover the members of the admin group.

    Pseudo code:

    current_user = getpwent();
    group = getgrnam("admin")
    if group.gr_mem contains current_user.pw_name then we are an admin

    S.
  • On 21/09/2007, Stefan Arentz <stefan.arentz...> wrote:
    > The admin group has write permission to /Library/Application Support.
    > To determine if the current user has the right permission you could
    > use getgrent("admin") to discover the members of the admin group.
    >
    > Pseudo code:
    >
    > current_user = getpwent();
    > group = getgrnam("admin")
    > if group.gr_mem contains current_user.pw_name then we are an admin

    Technically I don't think this will necessarily work any more due to
    nested groups etc. You should use the mbr_* API to check group
    membership as of Tiger :o)

    -- Finlay
  • On 9/21/07, Emanuele $B!g(B Vulcano <me...> wrote:
    >
    > Il giorno 21/set/07, alle ore 22:20, Finlay Dobbie ha scritto:
    >
    >> Technically I don't think this will necessarily work any more due to
    >> nested groups etc. You should use the mbr_* API to check group
    >> membership as of Tiger :o)
    >
    > ... or one could use NSFileManager to see if the directory is
    > writable :)

    Yeah that looks like the best way to go here :-)

    S.
previous month september 2007 next month
MTWTFSS
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
Go to today