Beispiel #1
0
	def test_seusers(self,sh):
		print "Testing seusers..."

		(status, slist) = semanage.semanage_seuser_list(sh)
		if status < 0:
			raise Error("Could not list seusers")
		print "Query status (commit number): ", status

		if ( len(slist) == 0):
			print "No seusers found!"
			print "This is not necessarily a test failure."
			return
		for seuser in slist:
			if self.verbose: print "seseuser reference: ", seuser 
			print "seuser name: ", semanage.semanage_seuser_get_name(seuser)
			print "   seuser mls range: ", semanage.semanage_seuser_get_mlsrange(seuser)
			print "   seuser sename: ", semanage.semanage_seuser_get_sename(seuser)
			semanage.semanage_seuser_free(seuser)		
Beispiel #2
0
    def test_seusers(self, sh):
        print("Testing seusers...")

        (status, slist) = semanage.semanage_seuser_list(sh)
        if status < 0:
            raise Error("Could not list seusers")
        print("Query status (commit number): %s" % status)

        if len(slist) == 0:
            print("No seusers found!")
            print("This is not necessarily a test failure.")
            return
        for seuser in slist:
            if self.verbose:
                print("seseuser reference: %s" % seuser)
            print("seuser name: %s" % semanage.semanage_seuser_get_name(seuser))
            print("   seuser mls range: %s" % semanage.semanage_seuser_get_mlsrange(seuser))
            print("   seuser sename: %s" % semanage.semanage_seuser_get_sename(seuser))
            semanage.semanage_seuser_free(seuser)
Beispiel #3
0
	def test_writeseuser(self,sh):
                print "Testing seuser write..."
                
		(status, seuser) = semanage.semanage_seuser_create(sh)
		if status < 0:
			raise Error("Could not create SEUser object")
		if self.verbose: print "SEUser object created."

		status = semanage.semanage_seuser_set_name(sh,seuser, "testPySEUser")
		if status < 0:
			raise Error("Could not set name")
		if self.verbose: print "SEUser name set: ", semanage.semanage_seuser_get_name(seuser)
                
		status = semanage.semanage_seuser_set_sename(sh, seuser, "root")
		if status < 0:
			raise Error("Could not set sename")
                if self.verbose: print "SEUser seuser: "******"s0:c0.c255")
		if status < 0:
			raise Error("Could not set MLS range")
                if self.verbose: print "SEUser mlsrange: ", semanage.semanage_seuser_get_mlsrange(seuser)
                
		(status,key) = semanage.semanage_seuser_key_extract(sh,seuser)
		if status < 0:
			raise Error("Could not extract SEUser key")
                if self.verbose: print "SEUser key extracted: ", key
	
                (status,exists) = semanage.semanage_seuser_exists_local(sh,key)
		if status < 0:
			raise Error("Could not check if SEUser exists")
		if self.verbose: print "Exists status (commit number): ", status

		if exists:
			(status, old_seuser) = semanage.semanage_seuser_query_local(sh, key)
			if status < 0:
				raise Error("Could not query old SEUser")
			if self.verbose: print "Query status (commit number): ", status

		print "Starting transaction..."
		status = semanage.semanage_begin_transaction(sh)
		if status < 0:
			raise Error("Could not start semanage transaction")

		status = semanage.semanage_seuser_modify_local(sh,key,seuser)
		if status < 0:
			raise Error("Could not modify SEUser")

		status = semanage.semanage_commit(sh)
		if status < 0:
			raise Error("Could not commit test transaction")
                print "Commit status (transaction number): ", status

		status = semanage.semanage_begin_transaction(sh)
		if status < 0:
			raise Error("Could not start semanage transaction")

		if not exists:
			print "Removing seuser..."
			status = semanage.semanage_seuser_del_local(sh, key)
			if status < 0:
				raise Error("Could not delete test SEUser")
			if self.verbose: print "Seuser delete: ", status
		else:
			print "Resetting seuser..."
			status = semanage.semanage_seuser_modify_local(sh, key, old_seuser)
			if status < 0:
				raise Error("Could not reset test SEUser")
			if self.verbose: print "Seuser modify: ", status

                status = semanage.semanage_commit(sh)
		if status < 0:
			raise Error("Could not commit reset transaction")
                print "Commit status (transaction number): ", status

		semanage.semanage_seuser_key_free(key)
		semanage.semanage_seuser_free(seuser)
		if exists: semanage.semanage_seuser_free(old_seuser)
Beispiel #4
0
    def test_writeseuser(self, sh):
        print("Testing seuser write...")

        (status, seuser) = semanage.semanage_seuser_create(sh)
        if status < 0:
            raise Error("Could not create SEUser object")
        if self.verbose:
            print("SEUser object created.")

        status = semanage.semanage_seuser_set_name(sh, seuser, "testPySEUser")
        if status < 0:
            raise Error("Could not set name")
        if self.verbose:
            print("SEUser name set: %s" %
                  semanage.semanage_seuser_get_name(seuser))

        status = semanage.semanage_seuser_set_sename(sh, seuser, "root")
        if status < 0:
            raise Error("Could not set sename")
        if self.verbose:
            print("SEUser seuser: %s" %
                  semanage.semanage_seuser_get_sename(seuser))

        status = semanage.semanage_seuser_set_mlsrange(sh, seuser,
                                                       "s0:c0.c255")
        if status < 0:
            raise Error("Could not set MLS range")
        if self.verbose:
            print("SEUser mlsrange: %s" %
                  semanage.semanage_seuser_get_mlsrange(seuser))

        (status, key) = semanage.semanage_seuser_key_extract(sh, seuser)
        if status < 0:
            raise Error("Could not extract SEUser key")
        if self.verbose:
            print("SEUser key extracted: %s" % key)

        (status, exists) = semanage.semanage_seuser_exists_local(sh, key)
        if status < 0:
            raise Error("Could not check if SEUser exists")
        if self.verbose:
            print("Exists status (commit number): %s" % status)

        if exists:
            (status,
             old_seuser) = semanage.semanage_seuser_query_local(sh, key)
            if status < 0:
                raise Error("Could not query old SEUser")
            if self.verbose:
                print("Query status (commit number): %s" % status)

        print("Starting transaction...")
        status = semanage.semanage_begin_transaction(sh)
        if status < 0:
            raise Error("Could not start semanage transaction")

        status = semanage.semanage_seuser_modify_local(sh, key, seuser)
        if status < 0:
            raise Error("Could not modify SEUser")

        status = semanage.semanage_commit(sh)
        if status < 0:
            raise Error("Could not commit test transaction")
        print("Commit status (transaction number): %s" % status)

        status = semanage.semanage_begin_transaction(sh)
        if status < 0:
            raise Error("Could not start semanage transaction")

        if not exists:
            print("Removing seuser...")
            status = semanage.semanage_seuser_del_local(sh, key)
            if status < 0:
                raise Error("Could not delete test SEUser")
            if self.verbose:
                print("Seuser delete: %s" % status)
        else:
            print("Resetting seuser...")
            status = semanage.semanage_seuser_modify_local(sh, key, old_seuser)
            if status < 0:
                raise Error("Could not reset test SEUser")
            if self.verbose:
                print("Seuser modify: %s" % status)

        status = semanage.semanage_commit(sh)
        if status < 0:
            raise Error("Could not commit reset transaction")
        print("Commit status (transaction number): %s" % status)

        semanage.semanage_seuser_key_free(key)
        semanage.semanage_seuser_free(seuser)
        if exists:
            semanage.semanage_seuser_free(old_seuser)