Comment 14 for bug 362355

Revision history for this message
Christopher Armstrong (radix) wrote :

[1]

+def get_username():
+ try:
+ username = os.getlogin()
+ except OSError:
+ # Some xterminals do not register themselves with utmp, which
+ # this function uses. If so, fall back to the USER env variable.
+ username = os.getenv("USER")
+ return username
+
+
 def get_default_environment():
- username = os.getlogin()
+ username = get_username()

Instead of working around the bug in os.getlogin(), I think you should instead use pwd.getpwuid(os.getuid())[0] to get the current user's name.

[2] Indentation is off here:

+ # Add the setuid flag to smart-update and it be executable by users in
+ # the landscape group (that normally means landscape itself)
+ smart_update=/usr/lib/smart/smart-update
+ if ! dpkg-statoverride --list $smart_update >/dev/null 2>&1; then
+ dpkg-statoverride --update --add root landscape 4754 $smart_update
+ fi

[3] Why are we setting the real and effective uids and gids?

    setreuid(pwd->pw_uid, pwd->pw_uid);
    setregid(pwd->pw_gid, pwd->pw_gid);

Is it really necessary? I guess it's a protection in case the program being run does something with UIDs, and we want to make sure to give it something consistent? in that case, you may want to use setresuid and setresgid to also set the SAVED uid. :-)

I haven't yet done a very thorough test of this code, but these are the things I noticed with a quick view of the diff.