Ejemplo n.º 1
0
    def convert_user(self, entry):
        dn = entry['dn']
        entry = dict(entry['attributes'])
        groups = []
        group = None
        nthash = None

        if contains(entry, 'gidNumber'):
            ret = self.search_one(
                self.group_dn,
                '(gidNumber={0})'.format(get(entry, 'gidNumber')),
                attributes=['ipaUniqueID']
            )

            if ret:
                group = dict(ret['attributes'])

        if get(entry, 'memberOf'):
            builder = LdapQueryBuilder()
            qstr = builder.build_query([
                ('member', '=*', dn),
                ('objectClass', '=', 'posixGroup')
            ])

            for r in self.search(self.base_dn, qstr, attributes=['ipaUniqueID']):
                r = dict(r['attributes'])
                groups.append(get(r, 'ipaUniqueID.0'))

        if contains(entry, 'ipaNTHash'):
            nthash = binascii.hexlify(entry['ipaNTHash']).decode('ascii')

        return {
            'id': get(entry, 'ipaUniqueID.0'),
            'uid': int(get(entry, 'uidNumber')),
            'gid': int(get(entry, 'gidNumber')),
            'sid': get(entry, 'ipaNTSecurityIdentifier'),
            'builtin': False,
            'username': get(entry, 'uid.0'),
            'full_name': get(entry, 'gecos', get(entry, 'displayName', '<unknown>')),
            'nthash': nthash,
            'password_changed_at': get(entry, 'krbLastPwdChange'),
            'shell': get(entry, 'loginShell', '/bin/sh'),
            'home': get(entry, 'homeDirectory', '/nonexistent'),
            'sshpubkey': get(entry, 'ipaSshPubKey.0', b'').decode('ascii') or None,
            'group': get(group, 'ipaUniqueID.0') if group else None,
            'groups': groups,
            'sudo': False
        }
Ejemplo n.º 2
0
    def convert_user(self, entry):
        entry = dict(entry['attributes'])
        groups = []
        group = None
        nthash = None

        if contains(entry, 'gidNumber'):
            ret = self.search_one(
                self.group_dn,
                '(gidNumber={0})'.format(get(entry, 'gidNumber'))
            )

            if ret:
                group = dict(ret['attributes'])

        if get(entry, 'memberOf'):
            builder = LdapQueryBuilder()
            qstr = builder.build_query([
                ('dn', 'in', get(entry, 'memberOf'))
            ])

            for r in self.search(self.base_dn, qstr):
                r = dict(r['attributes'])
                groups.append(get(r, 'ipaUniqueID.0'))

        if contains(entry, 'ipaNTHash'):
            nthash = binascii.hexlify(entry['ipaNTHash']).decode('ascii')

        return {
            'id': get(entry, 'ipaUniqueID.0'),
            'uid': int(get(entry, 'uidNumber')),
            'gid': int(get(entry, 'gidNumber')),
            'sid': get(entry, 'ipaNTSecurityIdentifier'),
            'builtin': False,
            'username': get(entry, 'uid.0'),
            'full_name': get(entry, 'gecos', get(entry, 'displayName', '<unknown>')),
            'nthash': nthash,
            'password_changed_at': get(entry, 'krbLastPwdChange'),
            'shell': get(entry, 'loginShell', '/bin/sh'),
            'home': get(entry, 'homeDirectory', '/nonexistent'),
            'sshpubkey': get(entry, 'ipaSshPubKey.0', b'').decode('ascii') or None,
            'group': get(group, 'ipaUniqueID.0') if group else None,
            'groups': groups,
            'sudo': False
        }
Ejemplo n.º 3
0
    def convert_user(self, entry):
        entry = dict(entry['attributes'])
        pwd_change_time = get(entry, 'sambaPwdLastSet')
        groups = []
        group = None
        username = get(entry, 'uid.0')

        if contains(entry, 'gidNumber'):
            ret = self.search_one(
                self.group_dn,
                '(gidNumber={0})'.format(get(entry, 'gidNumber')))

            if ret:
                group = dict(ret['attributes'])

        # Try to find any auxiliary groups
        for i in self.search(self.group_dn,
                             '(memberUid={0})'.format(get(entry, 'uid'))):
            g = dict(i['attributes'])
            groups.append(self.get_id(g))

        return {
            'id':
            self.get_id(entry),
            'sid':
            get(entry, 'sambaSID'),
            'uid':
            int(get(entry, 'uidNumber')),
            'builtin':
            False,
            'username':
            username,
            'full_name':
            get(entry, 'gecos', get(entry, 'displayName')) or '<unknown>',
            'shell':
            get(entry, 'loginShell', '/bin/sh'),
            'home':
            self.context.get_home_directory(self.directory, username),
            'nthash':
            get(entry, 'sambaNTPassword'),
            'lmhash':
            get(entry, 'sambaLMPassword'),
            'password_changed_at':
            datetime.utcfromtimestamp(int(pwd_change_time))
            if pwd_change_time else None,
            'group':
            self.get_id(group) if group else None,
            'groups':
            groups,
            'sudo':
            False
        }
Ejemplo n.º 4
0
    def save(self, this, new=False):
        if new:
            if not q.contains(self.parent.entity, self.parent_path):
                q.set(self.parent.entity, self.parent_path, [])

            q.get(self.parent.entity, self.parent_path).append(this.entity)
        else:
            entity = first_or_default(
                lambda a: a[self.primary_key_name] == this.entity['name'],
                q.get(self.parent.entity, self.parent_path))
            entity.update(this.entity)

        return self.parent.save()
Ejemplo n.º 5
0
    def save(self, this, new=False):
        if new:
            if not q.contains(self.parent.entity, self.parent_path):
                q.set(self.parent.entity, self.parent_path, [])

            q.get(self.parent.entity, self.parent_path).append(this.entity)
        else:
            entity = first_or_default(
                lambda a: a[self.primary_key_name] == this.entity[self.primary_key_name],
                q.get(self.parent.entity, self.parent_path)
            )
            entity.update(this.entity)

        return self.parent.save()
Ejemplo n.º 6
0
    def attr_query(self):
        class Test(object):
            pass

        c = Test()
        d = {}
        q.set(c, 'f', True)
        q.set(d, 'f2', Test())
        q.set(d, 'f2.nested', True)

        if q.get(c, 'f') and q.get(d, 'f2.nested') and isinstance(q.get(d, 'f2'), Test):
            l = [d, c]
            if q.contains(c, 'f'):
                q.delete(c, 'f')

                return bool(q.query(l, ('f2.nested', '=', True), count=True))

        return False
Ejemplo n.º 7
0
    def attr_query(self):
        class Test(object):
            pass

        c = Test()
        d = {}
        q.set(c, 'f', True)
        q.set(d, 'f2', Test())
        q.set(d, 'f2.nested', True)

        if q.get(c, 'f') and q.get(d, 'f2.nested') and isinstance(
                q.get(d, 'f2'), Test):
            l = [d, c]
            if q.contains(c, 'f'):
                q.delete(c, 'f')

                return bool(q.query(l, ('f2.nested', '=', True), count=True))

        return False
Ejemplo n.º 8
0
    def convert_user(self, entry):
        entry = dict(entry['attributes'])
        groups = []
        group = None

        if contains(entry, 'gidNumber.0'):
            ret = self.search_one(
                self.group_dn,
                '(gidNumber={0})'.format(get(entry, 'gidNumber.0'))
            )

            if ret:
                group = dict(ret['attributes'])

        if get(entry, 'memberOf'):
            builder = LdapQueryBuilder()
            qstr = builder.build_query([
                ('dn', 'in', get(entry, 'memberOf'))
            ])

            for r in self.search(self.base_dn, qstr):
                r = dict(r['attributes'])
                groups.append(get(r, 'ipaUniqueID.0'))

        return {
            'id': get(entry, 'ipaUniqueID.0'),
            'uid': int(get(entry, 'uidNumber.0')),
            'gid': int(get(entry, 'gidNumber.0')),
            'builtin': False,
            'username': get(entry, 'uid.0'),
            'full_name': get(entry, 'gecos.0', get(entry, 'displayName.0', '<unknown>')),
            'shell': get(entry, 'loginShell.0', '/bin/sh'),
            'home': get(entry, 'homeDirectory.0', '/nonexistent'),
            'sshpubkey': get(entry, 'ipaSshPubKey.0', None),
            'group': get(group, 'ipaUniqueID.0') if group else None,
            'groups': groups,
            'sudo': False
        }
Ejemplo n.º 9
0
    def convert_user(self, entry):
        entry = dict(entry['attributes'])
        pwd_change_time = get(entry, 'sambaPwdLastSet')
        groups = []
        group = None

        if contains(entry, 'gidNumber'):
            ret = self.search_one(
                self.group_dn,
                '(gidNumber={0})'.format(get(entry, 'gidNumber'))
            )

            if ret:
                group = dict(ret['attributes'])

        # Try to find any auxiliary groups
        for i in self.search(self.group_dn, '(memberUid={0})'.format(get(entry, 'uid'))):
            g = dict(i['attributes'])
            groups.append(self.get_id(g))

        return {
            'id': self.get_id(entry),
            'sid': get(entry, 'sambaSID'),
            'uid': int(get(entry, 'uidNumber')),
            'builtin': False,
            'username': get(entry, 'uid.0'),
            'full_name': get(entry, 'gecos', get(entry, 'displayName', '<unknown>')),
            'shell': get(entry, 'loginShell', '/bin/sh'),
            'home': get(entry, 'homeDirectory', '/nonexistent'),
            'nthash': get(entry, 'sambaNTPassword'),
            'lmhash': get(entry, 'sambaLMPassword'),
            'password_changed_at': datetime.utcfromtimestamp(int(pwd_change_time)) if pwd_change_time else None,
            'group': self.get_id(group) if group else None,
            'groups': groups,
            'sudo': False
        }