-1

I'm working on an installer program which potentially asks the user for the right to perform administrative actions (e.g. writing to the global program files directory and changing registry keys).

Windows allows using runas and OS X has AuthorizationExecuteWithPrivileges. Linux doesn't seem to feature anything like this.

I considered implementing this functionality by calling out to sudo, but that has a number of downsides:

  • It's not always installed by default.
  • Even if it's installed, it may fail if the current user is not part of the 'sudoers' group.
  • The password prompt differs between sudo versions (sometimes the p in password: is upper case).
  • sudo output is affected by the system language.

I could overcome the last two items, but the first two are kind of showstoppers. I wonder - are there other common approaches to implement this for Linux?

Community
  • 1
  • 1
Frerich Raabe
  • 90,689
  • 19
  • 115
  • 207

1 Answers1

1

As the How to programmatically gain root privileges? answers state, this is commonly done in Linux by using sticky bit and calls to setuid/setgid. In general one possibility is to run the process initially under root and then change the privileges by setuid/setgid as needed.

Community
  • 1
  • 1
EmDroid
  • 5,918
  • 18
  • 18