예제 #1
0
	def test_users(self,sh):
		print "Testing users..."

		(status, ulist) = semanage.semanage_user_list(sh)
		if status < 0:
			raise Error("Could not list users")
		print "Query status (commit number): ", status

		if ( len(ulist) == 0):
			print "No users found!"
			print "This is not necessarily a test failure."
			return
		for user in ulist:
			if self.verbose: print "User reference: ", user 
			print "User name: ", semanage.semanage_user_get_name(user)
			print "   User labeling prefix: ", semanage.semanage_user_get_prefix(user)
			print "   User mls level: ", semanage.semanage_user_get_mlslevel(user)
			print "   User mls range: ", semanage.semanage_user_get_mlsrange(user)
			print "   User number of roles: ", semanage.semanage_user_get_num_roles(user)
			print "   User roles: "
			(status, rlist) = semanage.semanage_user_get_roles(sh, user)
			if status < 0:
				raise Error("Could not get user roles")
				
			for role in rlist:
				print "      ", role

			semanage.semanage_user_free(user)
예제 #2
0
    def test_users(self, sh):
        print("Testing users...")

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

        if len(ulist) == 0:
            print("No users found!")
            print("This is not necessarily a test failure.")
            return
        for user in ulist:
            if self.verbose:
                print("User reference: %s" % user)
            print("User name: %s" % semanage.semanage_user_get_name(user))
            print("   User labeling prefix: %s" %
                  semanage.semanage_user_get_prefix(user))
            print("   User mls level: %s" %
                  semanage.semanage_user_get_mlslevel(user))
            print("   User mls range: %s" %
                  semanage.semanage_user_get_mlsrange(user))
            print("   User number of roles: %s" %
                  semanage.semanage_user_get_num_roles(user))
            print("   User roles: ")
            (status, rlist) = semanage.semanage_user_get_roles(sh, user)
            if status < 0:
                raise Error("Could not get user roles")

            for role in rlist:
                print("      %s" % role)

            semanage.semanage_user_free(user)
예제 #3
0
	def test_writeuser(self,sh):
		print "Testing user write..."

		(status, user) = semanage.semanage_user_create(sh)
		if status < 0:
			raise Error("Could not create user object")
		if self.verbose: print "User object created"

		status = semanage.semanage_user_set_name(sh,user, "testPyUser")
		if status < 0:
			raise Error("Could not set user name")
		if self.verbose: print "User name set: ", semanage.semanage_user_get_name(user)
                
		status = semanage.semanage_user_add_role(sh, user, "user_r")	
		if status < 0:
			raise Error("Could not add role")

		status = semanage.semanage_user_set_prefix(sh,user, "user")
		if status < 0:
			raise Error("Could not set labeling prefix")
		if self.verbose: print "User prefix set: ", semanage.semanage_user_get_prefix(user)
	
		status = semanage.semanage_user_set_mlsrange(sh, user, "s0")
		if status < 0:
			raise Error("Could not set MLS range")
		if self.verbose: print "User mlsrange: ", semanage.semanage_user_get_mlsrange(user)

		status = semanage.semanage_user_set_mlslevel(sh, user, "s0")
		if status < 0:
			raise Error("Could not set MLS level")
		if self.verbose: print "User mlslevel: ", semanage.semanage_user_get_mlslevel(user)
                
		(status,key) = semanage.semanage_user_key_extract(sh,user)
		if status < 0:
			raise Error("Could not extract user key")
		if self.verbose: print "User key extracted: ", key
	
		(status,exists) = semanage.semanage_user_exists_local(sh,key)
		if status < 0:
			raise Error("Could not check if user exists")
		if self.verbose: print "Exists status (commit number): ", status

		if exists: 
			(status, old_user) = semanage.semanage_user_query_local(sh, key)
			if status < 0:
				raise Error("Could not query old user")
			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_user_modify_local(sh,key,user)
		if status < 0:
			raise Error("Could not modify user")

		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 user..."
			status = semanage.semanage_user_del_local(sh, key)
			if status < 0:
				raise Error("Could not delete test user")
			if self.verbose: print "User delete: ", status
		else:
			print "Resetting user..."
			status = semanage.semanage_user_modify_local(sh, key, old_user)
			if status < 0:
				raise Error("Could not reset test user")
			if self.verbose: print "User 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_user_key_free(key)
		semanage.semanage_user_free(user)
		if exists: semanage.semanage_user_free(old_user)
예제 #4
0
    def test_writeuser(self, sh):
        print("Testing user write...")

        (status, user) = semanage.semanage_user_create(sh)
        if status < 0:
            raise Error("Could not create user object")
        if self.verbose:
            print("User object created")

        status = semanage.semanage_user_set_name(sh, user, "testPyUser")
        if status < 0:
            raise Error("Could not set user name")
        if self.verbose:
            print("User name set: %s" % semanage.semanage_user_get_name(user))

        status = semanage.semanage_user_add_role(sh, user, "user_r")
        if status < 0:
            raise Error("Could not add role")

        status = semanage.semanage_user_set_prefix(sh, user, "user")
        if status < 0:
            raise Error("Could not set labeling prefix")
        if self.verbose:
            print("User prefix set: %s" %
                  semanage.semanage_user_get_prefix(user))

        status = semanage.semanage_user_set_mlsrange(sh, user, "s0")
        if status < 0:
            raise Error("Could not set MLS range")
        if self.verbose:
            print("User mlsrange: %s" %
                  semanage.semanage_user_get_mlsrange(user))

        status = semanage.semanage_user_set_mlslevel(sh, user, "s0")
        if status < 0:
            raise Error("Could not set MLS level")
        if self.verbose:
            print("User mlslevel: %s" %
                  semanage.semanage_user_get_mlslevel(user))

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

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

        if exists:
            (status, old_user) = semanage.semanage_user_query_local(sh, key)
            if status < 0:
                raise Error("Could not query old user")
            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_user_modify_local(sh, key, user)
        if status < 0:
            raise Error("Could not modify user")

        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 user...")
            status = semanage.semanage_user_del_local(sh, key)
            if status < 0:
                raise Error("Could not delete test user")
            if self.verbose:
                print("User delete: %s" % status)
        else:
            print("Resetting user...")
            status = semanage.semanage_user_modify_local(sh, key, old_user)
            if status < 0:
                raise Error("Could not reset test user")
            if self.verbose:
                print("User 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_user_key_free(key)
        semanage.semanage_user_free(user)
        if exists:
            semanage.semanage_user_free(old_user)