Esempio n. 1
0
def test_group(logger, groupname, nnd=False):
    """
    synopsys:
        test_group(groupname)

    service version:
        1

    result:
        In case of success:
            test version, "groupname", groupname

        In case of error:
            NoSuchGroup if group is not found,
            GetentError otherwise
    """
    version = 1

    if not isinstance(groupname, (str, unicode)) or len(groupname) < 1:
        raise TypeError("groupname expected as a string")

    if nnd:
        client = getclient(logger)
        try:
            if not client.testgroup(groupname):
                raise NoSuchGroup(groupname)
        finally:
            client.quit()
    else:
        #will raise if necessary
        test_system_group(logger, groupname)
    return version, "groupname", groupname
Esempio n. 2
0
def test_auth(logger, username, password, nnd=False):
    """
    synopsys:
        test_auth(username, password)

    service version:
        1

    result:
        In case of success:
            test version, "auth", username

        In case of error:
            AuthError
    """
    version = 1
    if nnd:
        client = getclient(logger)
        try:
            #raises if incorrect
            try:
                client.auth2(username, password)
            except Exception, err:
                raise AuthError(username)
        finally:
            client.quit()
    elif not authenticate(username, password, service="nuauth"):
        raise AuthError(username)

    return version, "auth", username
Esempio n. 3
0
def test_user(logger, username, nnd=False):
    """
    synopsys:
        test_user(username)

    service version:
        1

    result:
        In case of success:
            test version, "username", username

        In case of error:
            NoSuchUser if user is not found,
            GetentError otherwise
    """
    version = 1
    if not isinstance(username, (str, unicode)) or len(username) < 1:
        raise TypeError("username expected as a string")
    if nnd:
        client = getclient(logger)
        try:
            if not client.testuser(username):
                raise NoSuchUser(username)
        finally:
            client.quit()
    else:
        test_system_user(logger, username)

    return version, "username", username
Esempio n. 4
0
 def _getGroups(self, only_user_groups):
     groups = []
     if self.use_nnd:
         if self.nnd_client is None:
             self.nnd_client = getclient(self)
         groups = [
             (groupname, "")
             for groupname in self.nnd_client.searchgroups()
             ]
     else:
         system_group_names = self._parseGroup()
         getent = self._parseGetent()
         for entry in getent:
             if only_user_groups and (entry[0] in system_group_names):
                 continue
             groups.append(entry)
     groups.sort()
     return groups