Skip to content
Snippets Groups Projects
Commit c1c35b2d authored by Cristiano Urban's avatar Cristiano Urban
Browse files

Use Python password database module in place of /etc/passwd. This seems to...

Use Python password database module in place of /etc/passwd. This seems to work fine also with the SSSD daemon on tn-bastion.ia2.

Signed-off-by: default avatarCristiano Urban <cristiano.urban@inaf.it>
parent 054d2da3
No related branches found
No related tags found
No related merge requests found
Pipeline #13638 passed
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
# #
import os import os
import pwd
import re import re
import shutil import shutil
import sys import sys
...@@ -27,24 +28,15 @@ class SystemUtils(object): ...@@ -27,24 +28,15 @@ class SystemUtils(object):
def userInfo(self, username): def userInfo(self, username):
""" """
Parses '/etc/passwd' and returns user, uid and gid associated to Returns username, UID and GID associated to a given user,
a given username. using the Python password database module (pwd).
""" """
try: try:
fp = open("/etc/passwd", 'r') info = pwd.getpwnam(username)
except FileNotFoundError: except KeyError:
raise
else:
for line in fp:
info = line.split(':')
user = info[0]
uid = int(info[2])
gid = int(info[3])
if user == username:
fp.close()
return [ user, uid, gid ]
fp.close()
return False return False
else:
return [ info[0], info[2], info[3] ]
def findIllegalCharacters(self, name): def findIllegalCharacters(self, name):
"""Checks for file/dir names containing illegal characters.""" """Checks for file/dir names containing illegal characters."""
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment