def forwards(self, orm):
        datastore = get_test_datastore("ldap", 0)
        for person in orm.person.objects.iterator():
            # check if the account is active or deleted
            # note we don't check date_deleted as date_deleted not always set
            if person.user.is_active:
                # Yes - Account is active.
                try:
                    # Try to find LDAP entry with same name as person username. If
                    # one exists, assume it is the same person.
                    p = datastore._accounts().get(uid=person.user.username)
                    if p.userPassword is not None:
                        person.legacy_ldap_password = p.userPassword

                    # If there are no accounts for this person, then delete
                    # the LDAP entry.
                    ua = person.useraccount_set.all()
                    ua = ua.filter(date_deleted__isnull=True)
                    if ua.count() == 0 and 'posixAccount' not in p.objectClass:
                        p.delete()
                except datastore._account.DoesNotExist:
                    # If we cannot find LDAP entry, assume this is because person
                    # has no access.
                    print "+++", person.user.username
                    person.legacy_ldap_password = None

            else:
                # No - Account is deleted, obviously no legacy password
                person.legacy_ldap_password = None


            # Save the updates to the person
            person.save()
    def forwards(self, orm):
        datastore = get_test_datastore("ldap", 0)
        for person in orm.person.objects.iterator():
            # check if the account is active or deleted
            # note we don't check date_deleted as date_deleted not always set
            if person.user.is_active:
                # Yes - Account is active.
                try:
                    # Try to find LDAP entry with same name as person username. If
                    # one exists, assume it is the same person.
                    p = datastore._accounts().get(uid=person.user.username)
                    person.login_enabled = not p.is_locked()
                except datastore._account.DoesNotExist, e:
                    # If we cannot find LDAP entry, assume this is because person
                    # has no access.
                    print "+++", person.username
                    person.login_enabled = False

            else:
                # No - Account is deleted, obviously logins should be disabled.
                person.login_enabled = False


            # Save the updates to the person
            person.save()
示例#3
0
    def forwards(self, orm):
        "Write your forwards methods here."
        # Note: Remember to use orm['appname.ModelName'] rather than "from appname.models..."
        if db.dry_run:
            return

        datastore = get_test_datastore("ldap", 0)

        last_uid = None
        for obj in datastore._accounts():
            if last_uid is None or obj.uidNumber > last_uid:
                last_uid = obj.uidNumber
        if last_uid is not None:
            entry, created = orm['methods.counters'].objects.get_or_create(name="uidNumber", defaults = { 'count': last_uid + 1 })
            if not created:
                entry.count = last_uid + 1
                entry.save()

        last_gid = None
        for obj in datastore._groups():
            if last_gid is None or obj.gidNumber > last_gid:
                last_gid = obj.gidNumber
        if last_gid is not None:
            entry, created = orm['methods.counters'].objects.get_or_create(name="gidNumber", defaults = { 'count': last_gid + 1 })
            if not created:
                entry.count = last_gid + 1
                entry.save()
示例#4
0
文件: tests.py 项目: russell/karaage
    def setUp(self):
        self._datastore = get_test_datastore()

        server = slapd.Slapd()
        server.set_port(38911)
        server.start()
        server.ldapadd("\n".join(test_ldif)+"\n")
        call_command('loaddata', 'karaage/testproject/karaage_data', **{'verbosity': 0})
        self.server = server
示例#5
0
 def forwards(self, orm):
     datastore = get_test_datastore("ldap", 0)
     for account in orm['machines.useraccount'].objects.filter(date_deleted__isnull=True):
         try:
             p = datastore._accounts().get(uid=account.username)
             if p.is_locked():
                 account.shell = account.previous_shell
             else:
                 account.shell = p.loginShell
             if not account.shell:
                 account.shell = "/bin/bash"
             account.save()
         except datastore._account.DoesNotExist, e:
             print "+++", account.username
             pass
示例#6
0
    def forwards(self, orm):
        datastore = get_test_datastore("ldap", 0)
        for software in orm.SoftwarePackage.objects.iterator():
            if software.gid is None:
                software.group = None
                software.save()
            else:
                lgroup = datastore._groups().get(gidNumber=software.gid)

                if not db.dry_run:
                    group, c = orm["people.group"].objects.get_or_create(name=lgroup.cn)
                    software.group = group
                    software.save()

                    for member in lgroup.secondary_accounts.iterator():
                        person = orm["people.person"].objects.get(user__username=member.uid)
                        person.groups.add(group)
示例#7
0
    def forwards(self, orm):
        datastore = get_test_datastore("ldap", 0)
        for institute in orm.Institute.objects.iterator():
            name = str(institute.name.lower().replace(' ', ''))
            try:
                lgroup = datastore._groups().get(gidNumber=institute.gid)
            except datastore._group.DoesNotExist:
                try:
                    print "+++ get by name", institute.name, institute.gid
                    lgroup = datastore._groups().get(cn=name)
                except datastore._group.DoesNotExist:
                    print "+++ create", institute.name, institute.gid
                    lgroup = datastore._groups().create(gidNumber=institute.gid, cn=name)

            if not db.dry_run:
                group,c = orm['people.group'].objects.get_or_create(name=lgroup.cn)
                institute.group = group
                institute.save()

                for member in lgroup.secondary_accounts.iterator():
                    person = orm['people.person'].objects.get(user__username=member.uid)
                    person.groups.add(group)
    def forwards(self, orm):
        "Write your forwards methods here."
        datastore = get_test_datastore("ldap", 0)
        for ua in orm.useraccount.objects.iterator():
            if ua.date_deleted is None:
                # Yes - Account is active.
                try:
                    # Try to find LDAP entry with same name as person username. If
                    # one exists, assume it is the same person.
                    p = datastore._accounts().get(uid=ua.username)
                    ua.login_enabled = not p.is_locked()
                except datastore._account.DoesNotExist, e:
                    # If we cannot find LDAP entry, assume this is because account
                    # has no access.
                    print "+++", ua.username
                    ua.login_enabled = False

            else:
                # No - Account is deleted, obviously logins should be disabled.
                ua.login_enabled = False

            # Save the updates to the person
            ua.save()
示例#9
0
 def backwards(self, orm):
     datastore = get_test_datastore("ldap", 0)
     for institute in orm.Institute.objects.iterator():
         lgroup = datastore._groups().get(cn=institute.group.name)
         institute.gid = lgroup.gidNumber
         institute.save()
示例#10
0
 def backwards(self, orm):
     datastore = get_test_datastore("ldap", 0)
     for software in orm.SoftwarePackage.objects.iterator():
         lgroup = datastore._groups().get(cn=software.group.name)
         software.gid = lgroup.gidNumber
         software.save()