Beispiel #1
0
 def __init__(self,login,passwd=None):
     """get user profile from NIS"""
     try:
         p = nis.match(login, 'passwd.byname').split(":")
     except:
         raise NISAUTHError('username')
     # check user password using crypt and 2 character salt from passwd file
     if p[1] == crypt.crypt(passwd, p[1][:2]):
         # check to see if user is in valid support groups
         # will have to include these groups in a settings file eventually
         if not login in nis.match(AUTHORIZED_GROUP, 'group.byname').split(':')[-1].split(',') and p[3] != nis.match(AUTHORIZED_GROUP, 'group.byname').split(':')[2]:
             raise NISAUTHError('group')
         self.uid = p[2]
     else:
         raise NISAUTHError('password')
Beispiel #2
0
    def authenticate(self, username, password, **kwargs):
        """Authenticate the user.

        This will authenticate the username and return the appropriate User
        object, or None.
        """
        import crypt
        import nis

        username = username.strip()

        try:
            passwd = nis.match(username, 'passwd').split(':')
            original_crypted = passwd[1]
            new_crypted = crypt.crypt(password, original_crypted)

            if original_crypted == new_crypted:
                return self.get_or_create_user(username, None, passwd)
        except nis.error:
            # FIXME I'm not sure under what situations this would fail (maybe
            # if their NIS server is down), but it'd be nice to inform the
            # user.
            pass

        return None
Beispiel #3
0
    def get_or_create_user(self, username, request, passwd=None):
        import nis

        username = username.strip()

        try:
            user = User.objects.get(username=username)
        except User.DoesNotExist:
            try:
                if not passwd:
                    passwd = nis.match(username, 'passwd').split(':')

                names = passwd[4].split(',')[0].split(' ', 1)
                first_name = names[0]
                last_name = None
                if len(names) > 1:
                    last_name = names[1]

                email = '%s@%s' % (username, settings.NIS_EMAIL_DOMAIN)

                user = User(username=username,
                            password='',
                            first_name=first_name,
                            last_name=last_name or '',
                            email=email)
                user.is_staff = False
                user.is_superuser = False
                user.set_unusable_password()
                user.save()
            except nis.error:
                pass
        return user
Beispiel #4
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
Beispiel #5
0
    def get_or_create_user(self, username, passwd=None):
        import nis

        username = username.strip()

        try:
            user = User.objects.get(username=username)
        except User.DoesNotExist:
            try:
                if not passwd:
                    passwd = nis.match(username, 'passwd').split(':')

                names = passwd[4].split(',')[0].split(' ', 1)
                first_name = names[0]
                last_name = None
                if len(names) > 1:
                    last_name = names[1]

                email = u'%s@%s' % (username, settings.NIS_EMAIL_DOMAIN)

                user = User(username=username,
                            password='',
                            first_name=first_name,
                            last_name=last_name or '',
                            email=email)
                user.is_staff = False
                user.is_superuser = False
                user.set_unusable_password()
                user.save()
            except nis.error:
                pass
        return user
    def authenticate(self, username, password):
        """Authenticate the user.

        This will authenticate the username and return the appropriate User
        object, or None.
        """
        import crypt
        import nis

        username = username.strip()

        try:
            passwd = nis.match(username, 'passwd').split(':')
            original_crypted = passwd[1]
            new_crypted = crypt.crypt(password, original_crypted)

            if original_crypted == new_crypted:
                return self.get_or_create_user(username, None, passwd)
        except nis.error:
            # FIXME I'm not sure under what situations this would fail (maybe
            # if their NIS server is down), but it'd be nice to inform the
            # user.
            pass

        return None
Beispiel #7
0
 def __init__(self, login, passwd=None):
     """get user profile from NIS"""
     try:
         p = nis.match(login, 'passwd.byname').split(":")
     except:
         raise NISAUTHError('username')
     # check user password using crypt and 2 character salt from passwd file
     if p[1] == crypt.crypt(passwd, p[1][:2]):
         # check to see if user is in valid support groups
         # will have to include these groups in a settings file eventually
         if not login in nis.match(AUTHORIZED_GROUP, 'group.byname').split(
                 ':')[-1].split(',') and p[3] != nis.match(
                     AUTHORIZED_GROUP, 'group.byname').split(':')[2]:
             raise NISAUTHError('group')
         self.uid = p[2]
     else:
         raise NISAUTHError('password')
Beispiel #8
0
 def isblank(s, regex=None):
     if (s == None):
         return True
     if (isinstance(s, str)):
         if (regex == None or s == ""):
             return True
         else:
             return match(s, regex)
     return False
Beispiel #9
0
def realname(host):
	try:
		import nis
	except ImportError:
		return host
	try:
		response = nis.match(host, 'hosts.byaddr')
		words = string.split(response)
		return words[1]
	except nis.error:
		return host
Beispiel #10
0
 def _listOneNISUser(self,username):
     roles=[self.default_role]
     try:
         nis_user=nis.match(username,'passwd.byname')
         username,passwd,other=string.split(nis_user,':',2)
         data={'username':username,
               'password':passwd,
               'roles':roles}
     except nis.error:
         data=None
     return data
Beispiel #11
0
def realname(host):
    try:
        import nis
    except ImportError:
        return host
    try:
        response = nis.match(host, 'hosts.byaddr')
        words = string.split(response)
        return words[1]
    except nis.error:
        return host
Beispiel #12
0
def getRecipientName(address):
    (realname, email_addr) = email.utils.parseaddr(address)
    if realname: return realname
    t = email_addr.split("@")
    login = t[0]
    if len(t) == 1 or t[1].endswith("appen.com.au"):
        try:
            entry = nis.match(login, 'passwd.byname')
            fullname = entry.split(":")[4]
            name = fullname.split(" ")[0]
        except:
            name = login
    else:
        name = login
    return name
Beispiel #13
0
    def authenticate(self, username, password):
        import crypt
        import nis

        username = username.strip()

        try:
            passwd = nis.match(username, 'passwd').split(':')
            original_crypted = passwd[1]
            new_crypted = crypt.crypt(password, original_crypted)

            if original_crypted == new_crypted:
                return self.get_or_create_user(username, passwd)
        except nis.error:
            # FIXME I'm not sure under what situations this would fail (maybe if
            # their NIS server is down), but it'd be nice to inform the user.
            pass
Beispiel #14
0
def nischeck(username,password):
	if username:
		try:
			un=nis.match(username,"passwd").split(":")[1]
			if un.__len__()> 16:
				if crypt.crypt(password,un[0:12])==un:
					return 1
				else:
					return 0
			else:
				if crypt.crypt(password,un)==un:
					return 1
				else:
					return 0
			
		except:
			return 0
Beispiel #15
0
    def _nis_get_passwd(self, username):
        """Return a passwd entry for a user.

        Args:
            username (unicode):
                The username to fetch.

        Returns:
            tuple:
            The parsed passwd entry.

        Raises:
            nis.error:
                The user could not be found, or there was an error performing
                the lookup.
        """
        import nis

        return nis.match(username, 'passwd').split(':')
Beispiel #16
0
def get_nis_info(username):
        try:
            p = pwd.getpwnam(username)
        except KeyError:
           return (None, None, None)

        if p.pw_passwd == "*GONE*":
           return (None, None, None)

        s = string.split(p.pw_gecos, ' ')
        if(len(s) < 2):
            s.append('')
        em = ""
        try:
            em = nis.match(username, 'mail.aliases').partition('@')[0] + "@windriver.com"
        except KeyError:
            em = ""

        return (s[0], s[1], em)
Beispiel #17
0
    def authenticate(self, username, password):
        import crypt
        import nis

        username = username.strip()

        try:
            passwd = nis.match(username, 'passwd').split(':')
            original_crypted = passwd[1]
            new_crypted = crypt.crypt(password, original_crypted)

            if original_crypted == new_crypted:
                return self.get_or_create_user(username, passwd)
        except nis.error:
            # FIXME I'm not sure under what situations this would fail (maybe if
            # their NIS server is down), but it'd be nice to inform the user.
            pass

        return None
Beispiel #18
0
import nis
import string

print nis.cat("ypservers")
print string.split(nis.match("bacon", "hosts.byname"))
Beispiel #19
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
Beispiel #20
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
Beispiel #21
0
#pylint: disable-msg=E1101
print AP2.O_SHLOCK, AP2.O_EXLOCK
#pylint: disable-msg=E1101
print AP3.rpc_paths
#pylint: disable-msg=E1101
print AP4.rpc_paths
print AP5.subversion
print AP6.family
print AP6.type
print AP6.proto

print heapq.nsmallest(1, ['a', 'b'], key=lambda x: 'your mom')
print heapq.nlargest(1, ['a', 'b'], key=lambda x: 'your mom')
print min([], key=lambda x: 'your mom')
print max([], key=lambda x: 'your mom')
print match('foo', domain='lalala')
print maps('foo', domain='lalala')
webbrowser.open(autoraise=True)

######### This is not detectable using pylint machinery, I think.
# try:
#     print 'foo'
# except IOError, e:
#     print 'bar'
# else:
#     print 'baz'
# finally:
#     print 'zoinks'

######### This crashes pylint, so...  no.
# def generator_func():
Beispiel #22
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']
Beispiel #23
0
        raise TestFailed, msg
    # only do this if running under the regression suite
    raise TestSkipped, msg

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:
    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
Beispiel #24
0
        raise TestFailed, msg
    # only do this if running under the regression suite
    raise TestSkipped, msg

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:
    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