예제 #1
0
def username(passport):
	if not passport.has_key('sunrpc-unix'):
		raise error, 'no Sun RPC UNIX identity in ILU passport'
	SunRPCAuth = passport['sunrpc-unix']
	map = nis.cat('hosts.byaddr')
	if not map:
		raise error, 'no YP map "hosts.byaddr"'
	map = nis.cat('passwd.byuid')
	if not map:
		raise error, 'no YP map "passwd.byuid"'
	uid = str(SunRPCAuth['uid'])
	if not map.has_key(uid):
		raise error, 'unknown user ID ' + uid
	record = string.splitfields(map[uid], ':')
	return (record[4])
예제 #2
0
def Process_Hosts():
    """Process all the hosts in ypcat
    """
    Index = 0
    for Host in nis.cat("hosts"):
        """Only run a certain number of subprocesses at a time.  
        Clear out the completed ones and check if under 100 every second:
        500 results in "rcmd: socket: Cannot assign requested address"
        """
        while len(The_Thread_List) > 100:
            for Thread in The_Thread_List:
                if Thread.poll() != None:
                    Debug_Print("Removing" + str(Thread))
                    The_Thread_List.remove(Thread)
            Debug_Print("Sleeping")
            time.sleep(1)

        Process_Host(Host)
        Index = Index + 1


#        """Don't try doing them all yet:
#        """
#        if (Index >= 200):
#            break

    Process_Host("calaveras")
    Process_Host("superglide")
예제 #3
0
class NisTests(unittest.TestCase):
    def test_maps(self):
        try:
            maps = nis.maps()
        except nis.error, msg:
            # NIS is probably not active, so this test isn't useful
            if test_support.verbose:
                print "Test Skipped:", msg
            # Can't raise TestSkipped as regrtest only recognizes the exception
            #   import time.
            return
        try:
            # On some systems, this map is only accessible to the
            # super user
            maps.remove("passwd.adjunct.byname")
        except ValueError:
            pass

        done = 0
        for nismap in maps:
            mapping = nis.cat(nismap)
            for k, v in mapping.items():
                if not k:
                    continue
                if nis.match(k, nismap) != v:
                    self.fail("NIS match failed for key `%s' in map `%s'" % (k, nismap))
                else:
                    # just test the one key, otherwise this test could take a
                    # very long time
                    done = 1
                    break
            if done:
                break
예제 #4
0
def Process_Hosts ():
    """Process all the hosts in ypcat
    """
    Index = 0
    for Host in nis.cat ("hosts"):
        """Only run a certain number of subprocesses at a time.  
        Clear out the completed ones and check if under 100 every second:
        500 results in "rcmd: socket: Cannot assign requested address"
        """ 
        while len(The_Thread_List) > 100:
            for Thread in The_Thread_List:
                if Thread.poll() != None:
                    Debug_Print ("Removing" + str (Thread))        
                    The_Thread_List.remove(Thread)
            Debug_Print ("Sleeping")        
            time.sleep (1)      
              
        Process_Host (Host)
        Index = Index + 1
#        """Don't try doing them all yet:
#        """
#        if (Index >= 200):
#            break
            
    Process_Host ("calaveras")  
    Process_Host ("superglide")  
예제 #5
0
def parse_net_group(netgroup):
    """
    Returns a list netgroup hosts
    """
    raw_netgroup = ""
    try:
        raw_netgroup = nis.cat('netgroup')[netgroup]
    except KeyError:
        log.warn(
            "No map named {} found in the netgroup file.".format(netgroup))
    except Exception as error:
        log.error("FAILED to retrieve netgroup map from NIS server: {}".format(
            error))
        log.error("Does 'ypcat netgroup' return a map?")
        raise
    allhosts = []
    # Expecting input format of: "(red,,) (green,,) (blue,,)"
    hosts = re.findall(r"\((\S+),\S*,\S*", raw_netgroup)
    allhosts = list(set().union(allhosts, hosts))
    # Expecting input format of "all servers workstations", strip any hosts
    stripped_groups = re.findall(r'([^(\)]+)(?:$|\()', raw_netgroup)
    # Expecting input format of "all servers workstations"
    if len(stripped_groups) > 0:
        groups = re.findall(r"(\S+)\s", stripped_groups[0])
        for group in groups:
            # Recurse into specified groups, and merge the returned hosts
            allhosts = list(set().union(allhosts, parse_net_group(group)))
    return allhosts
예제 #6
0
파일: nis_plugin.py 프로젝트: nocko/cfmi
 def auth(self, username, password):
     if not self.account_exists(username):
         return False
     try:
         crypt_passwd = nis.cat("passwd.byname")[username].split(':')[1]
     except nis.error as e:
         raise AuthError(e)
     return crypt.crypt(password, crypt_passwd) == crypt_passwd
예제 #7
0
 def _listNISUsers(self):
     users=[]
     roles=[self.default_role]
     try:
         nis_users=nis.cat('passwd.byname')
         userlist=nis_users.keys()
         userlist.sort()
         for user in userlist:
             username,passwd,other=string.split(nis_users[user],':',2)
             data={'username':username,
                   'password':passwd,
                   'roles':roles}
             users.append(data)
     except nis.error:
         data=None
     
     return users
예제 #8
0
파일: nis_plugin.py 프로젝트: nocko/cfmi
 def get_meta(self, username, full=False):
     current_app.logger.info("{}: User {} metadata cache miss".format(self, username))
     if not self.account_exists(username):
         return {}
     passwd_fields = nis.cat("passwd.byname")[username].split(':')
     meta = {'username': passwd_fields[0],
             'uid': passwd_fields[2],
             'gid': passwd_fields[3],
             'home_dir': passwd_fields[5],
             'shell': passwd_fields[6]}
     gecos = passwd_fields[4]
     while len(gecos.split(',')) < 4:
         gecos += ','
     gecos_fields = gecos.split(',')
     meta['name'] = gecos_fields[0]
     meta['address'] = gecos_fields[1]
     meta['phone'] = gecos_fields[2]
     meta['emerg'] = gecos_fields[3]
     return map_attrs(meta, full=full)
예제 #9
0
def manage_addnisAuthSource(self, REQUEST):
    """ Add a nis Auth Source """
    try:
        if nis.cat('passwd.byname'):
            default_role=REQUEST['nisauth_default_role']
            NoLocalRoles=REQUEST.has_key('nisauth_NoLocalRoles')
            o = nisAuthSource(default_role,NoLocalRoles)
            self._setObject('nisAuthSource', o, None, None, 0)
            o=getattr(self,'nisAuthSource')
            if hasattr(o, 'postInitialisation'):
                o.postInitialisation(REQUEST)
            self.currentAuthSource=o
            return ''
        else:
            return self.MessageDialog(self,REQUEST=REQUEST,
                                    title  ='NIS Error', 
                                    message='No users in passwd.byname',
                                    action ='manage_main')
    except nis.error:        
         return self.MessageDialog(self,REQUEST=REQUEST,
                                    title  ='NIS Error', 
                                    message='NIS server unreachable',
                                    action ='manage_main')
예제 #10
0
파일: nis_plugin.py 프로젝트: nocko/cfmi
 def account_exists(self, username):
     try:
         if nis.cat("passwd.byname")[username]:
             return True
     except KeyError:
         return False
예제 #11
0
 def __iter__(self):
     for key in nis.cat(self.mapname):
         yield self.compoundParser(key)
예제 #12
0
import nis
import string

print nis.cat("ypservers")
print string.split(nis.match("bacon", "hosts.byname"))
예제 #13
0
파일: auth.py 프로젝트: prarobinson/cfmi
def nis_auth(uname, password):
    crypt_passwd = nis.cat("passwd.byname")[uname].split(':')[1]
    return crypt.crypt(password, crypt_passwd) == crypt_passwd
예제 #14
0
 def _listNISUserNames(self):
     nis_users=nis.cat('passwd.byname')
     usernames=nis_users.keys()
     usernames.sort()
     return usernames
예제 #15
0
from test_support import verbose, TestFailed, TestSkipped
import nis
print 'nis.maps()'
try:
    maps = nis.maps()
except nis.error, msg:
    # NIS is probably not active, so this test isn't useful
    if verbose:
        raise TestFailed, msg
    # only do this if running under the regression suite
    raise TestSkipped, msg
done = 0
for nismap in maps:
    if verbose:
        print nismap
    mapping = nis.cat(nismap)
    for k, v in mapping.items():
        if verbose:
            print '    ', k, v
        if not k:
            continue
        if nis.match(k, nismap) != v:
            print "NIS match failed for key `%s' in map `%s'" % (k, nismap)
        else:
            # just test the one key, otherwise this test could take a
            # very long time
            done = 1
            break
    if done:
        break
예제 #16
0
print 'nis.maps()'
try:
    maps = nis.maps()
except nis.error, msg:
    # NIS is probably not active, so this test isn't useful
    if verbose:
        raise TestFailed, msg
    # only do this if running under the regression suite
    raise TestSkipped, msg

done = 0
for nismap in maps:
    if verbose:
        print nismap
    mapping = nis.cat(nismap)
    for k, v in mapping.items():
        if verbose:
            print '    ', k, v
        if not k:
            continue
        if nis.match(k, nismap) <> v:
            print "NIS match failed for key `%s' in map `%s'" % (k, nismap)
        else:
            # just test the one key, otherwise this test could take a
            # very long time
            done = 1
            break
    if done:
        break
예제 #17
0
import nis
import string

print nis.cat("ypservers")
print string.split(nis.match("bacon", "hosts.byname"))

## {'bacon.spam.egg': 'bacon.spam.egg'}
## ['194.18.155.250', 'bacon.spam.egg', 'bacon', 'spam-010']