If you really want your code to be reliable in a wide variety of Linux configurations, I would suggest that you consider corner cases where someone can use the SELinux or file system ACLs or the “features” functions that have been in the Linux kernel since version 2.2 or so. Your process can run under some shell that used SELinux or some Linux feature library, such as libcap2 libcap-ng or fscaps or elfcap through something more exotic, like the wonderful and sadly underestimated Niels Provos systrace .
All of these methods can be run as non-root, but for your process, the necessary access may have been delegated to perform its work without EUID == 0.
Therefore, I suggest that you consider writing more Pythonically code by porting operations that may fail due to permissions or other problems with exception handling code. If you perform various operations (for example, using the subprocess module), you can offer a prefix for all such calls with sudo (for example, on the command line, environment, or .rc file). If it runs interactively, you can offer to re-execute any commands that increase permission-related exceptions with sudo (optional, only if you find sudo in os.environ ['PATH').
In general, it is true that most Linux and UNIX systems still have most of their administration as a privileged root user. However, this is an old school, and we, as programmers, should try to support newer models. Attempting your work and allowing exception handling to do its job allows your code to work on any system that transparently allows the operations you need, and knowing and is ready to use sudo is a nice touch (since this is the most common tool for controlled delegation of system privileges )
Jim Dennis May 10 '10 at 23:53 2010-05-10 23:53
source share