Skip to contentSkip to conversation

policycoreutils/chcat: Add a fallback in case os.getlogin() returns nothing

PATCH Applied Laurent Bigonville 2 participants 2 messages Dec 13, 2015 – Dec 17, 2015 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 policycoreutils/chcat: Add a fallback in case os.getlogin() returns nothing

From: Laurent Bigonville <[email protected]>

Some teminal emulators (like the latest version of gnome-terminal) are not setting entries in the utmp file, this leads getlogin() to return an empty string.

Fallback to the name of the user running the chcat process.

---
 policycoreutils/scripts/chcat | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
policycoreutils/scripts/chcat +4 -1
index ec527e5..472785c 100755
@@ -372,7 +372,10 @@ def listcats():
 
 def listusercats(users):
     if len(users) == 0:
-        users.append(os.getlogin())
+        try:
+            users.append(os.getlogin())
+        except:
+            users.append(pwd.getpwuid(os.getuid()).pw_name)
 
     verify_users(users)
     for u in users:
Signature · 1 line
2.6.4
#1 lore raw
Quoted 7 lines · Laurent Bigonville

From: Laurent Bigonville <[email protected]>

Some teminal emulators (like the latest version of gnome-terminal) are not setting entries in the utmp file, this leads getlogin() to return an empty string.

Fallback to the name of the user running the chcat process.

Applied. Thanks.

Also, in the future, please add a Signed-off-by line.

Quoted 21 lines
---
 policycoreutils/scripts/chcat | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
policycoreutils/scripts/chcat +4 -1
index ec527e5..472785c 100755
@@ -372,7 +372,10 @@ def listcats():
 
 def listusercats(users):
     if len(users) == 0:
-        users.append(os.getlogin())
+        try:
+            users.append(os.getlogin())
+        except:
+            users.append(pwd.getpwuid(os.getuid()).pw_name)
 
     verify_users(users)
     for u in users: