views:

286

answers:

1

The application I'm working on requires the ability to edit certain protected files across Linux, OSX, and Windows [Vista]. Generally, when an application needs to do something with elevated privileges, a password request dialog appears asking the user to verify they want to allow the application to perform those operations as an administrator.

I believe in general, Windows Vista utilizes Manifest files, OSX has the Authorization library (https://developer.apple.com/mac/library/documentation/Security/Reference/authorization%5Fref/Reference/reference.html), and Linux has a variety of sudo frontends.

Is there a generally acceptable cross-platform way of handling this? I don't want my application to have to be run as the root user, but I do want it to be able to open a protected file for read/write operations, then resume back to normal user mode.

A: 

For Windows Vista, you basically need a dedicated process to do administrative actions. As you mention, the admin-enabled process will need a manifest to specify the requested execution level (see this MSDN article for details).

If you look closely at any Windows application that starts non-elevated and supports "elevating" itself, you'll see that it actually opens a whole new process once administrative privileges are needed (e.g. go to Task Manager when UAC is enabled, click "Show processes from all users" and note how it reopens with admin privileges).

So for Windows, the architecture you probably need would require two processes: a standard process to do most of the work, and an admin process to call into to do the admin operations. The two processes would need to communicate via some secure means (perhaps a secure named pipe) so that admin work could be done on behalf of the standard process.

This approach may be generalizable across other platforms, and perhaps could be abstracted in some sort of class/interface so that platform-specific details would not need to leak through.

bobbymcr
Thank you for this information.
Michael