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
Loading
Loading
Loading
Loading
Loading
+12 −20
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@
#

import os
import pwd
import re
import shutil
import sys
@@ -27,24 +28,15 @@ class SystemUtils(object):

    def userInfo(self, username):
        """
        Parses '/etc/passwd' and returns user, uid and gid associated to
        a given username.
        Returns username, UID and GID associated to a given user,
        using the Python password database module (pwd).
        """
        try:
            fp = open("/etc/passwd", 'r')
        except FileNotFoundError:
            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()
            info = pwd.getpwnam(username)
        except KeyError:
            return False
        else:
            return [ info[0], info[2], info[3] ]

    def findIllegalCharacters(self, name):
        """Checks for file/dir names containing illegal characters."""