hplip/SOURCES/hplip-check-userperms.patch
2022-05-17 15:59:07 +00:00

34 lines
1019 B
Diff

diff --git a/base/password.py b/base/password.py
index bd68f2a..bff9f80 100644
--- a/base/password.py
+++ b/base/password.py
@@ -157,6 +157,28 @@ class Password(object):
log.warn("%s distro is not found in AUTH_TYPES" % distro_name)
self.__authType = 'su'
+ # check if caller is in wheel group - use 'su' if he isnt -
+ # or if the caller is root (just for showing 'root' username)
+ # in the prompt
+ import os
+ from grp import getgrnam
+
+ user = os.getenv('USER')
+
+ try:
+ members = getgrnam('wheel').gr_mem
+ except KeyError:
+ try:
+ members = getgrnam('sudo').gr_mem
+ except:
+ return
+
+ if user in members:
+ self.__authType = 'sudo'
+ else:
+ self.__authType = 'su'
+
+
def __getPasswordDisplayString(self):
if self.__authType == "su":
return "Please enter the root/superuser password: "