예제 #1
0
    def test_interfaces(self, sh):
        print("Testing network interfaces...")

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

        if len(ilist) == 0:
            print("No network interfaces found!")
            print("This is not necessarily a test failure.")
            return
        for iface in ilist:
            if self.verbose:
                print("Interface reference: %s" % iface)
            name = semanage.semanage_iface_get_name(iface)
            msg_con = semanage.semanage_iface_get_msgcon(iface)
            if_con = semanage.semanage_iface_get_ifcon(iface)
            (rc,
             msg_con_str) = semanage.semanage_context_to_string(sh, msg_con)
            if rc < 0:
                msg_con_str = ""
            (rc, if_con_str) = semanage.semanage_context_to_string(sh, if_con)
            if rc < 0:
                if_con_str = ""
            print("Interface: %s Context: %s Message Context: %s" %
                  (name, if_con_str, msg_con_str))
            semanage.semanage_iface_free(iface)
예제 #2
0
    def test_interfaces(self, sh):
        print("Testing network interfaces...")

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

        if len(ilist) == 0:
            print("No network interfaces found!")
            print("This is not necessarily a test failure.")
            return
        for iface in ilist:
            if self.verbose:
                print("Interface reference: %s" % iface)
            name = semanage.semanage_iface_get_name(iface)
            msg_con = semanage.semanage_iface_get_msgcon(iface)
            if_con = semanage.semanage_iface_get_ifcon(iface)
            (rc, msg_con_str) = semanage.semanage_context_to_string(sh, msg_con)
            if rc < 0:
                msg_con_str = ""
            (rc, if_con_str) = semanage.semanage_context_to_string(sh, if_con)
            if rc < 0:
                if_con_str = ""
            print("Interface: %s Context: %s Message Context: %s" % (name, if_con_str, msg_con_str))
            semanage.semanage_iface_free(iface)
예제 #3
0
	def test_interfaces(self,sh):
		print "Testing network interfaces..."

		(status, ilist) = semanage.semanage_iface_list(sh)
		if status < 0:
			raise Error("Could not list interfaces")
		print "Query status (commit number): ", status

		if (len(ilist) == 0):
			print "No network interfaces found!"
			print "This is not necessarily a test failure."
			return
		for iface in ilist:
			if self.verbose: print "Interface reference: ", iface
			name = semanage.semanage_iface_get_name(iface)
			msg_con = semanage.semanage_iface_get_msgcon(iface)
			if_con = semanage.semanage_iface_get_ifcon(iface)
			(rc, msg_con_str) = semanage.semanage_context_to_string(sh,msg_con)
			if rc < 0: msg_con_str = ""
			(rc, if_con_str) = semanage.semanage_context_to_string(sh, if_con)
			if rc < 0: if_con_str = ""
			print "Interface: ", name, " Context: ", if_con_str, " Message Context: ", msg_con_str
			semanage.semanage_iface_free(iface)
예제 #4
0
    def test_interfaces(self, sh):
        print "Testing network interfaces..."

        (status, ilist) = semanage.semanage_iface_list(sh)
        if status < 0:
            raise Error("Could not list interfaces")
        print "Query status (commit number): ", status

        if (len(ilist) == 0):
            print "No network interfaces found!"
            print "This is not necessarily a test failure."
            return
        for iface in ilist:
            if self.verbose: print "Interface reference: ", iface
            name = semanage.semanage_iface_get_name(iface)
            msg_con = semanage.semanage_iface_get_msgcon(iface)
            if_con = semanage.semanage_iface_get_ifcon(iface)
            (rc,
             msg_con_str) = semanage.semanage_context_to_string(sh, msg_con)
            if rc < 0: msg_con_str = ""
            (rc, if_con_str) = semanage.semanage_context_to_string(sh, if_con)
            if rc < 0: if_con_str = ""
            print "Interface: ", name, " Context: ", if_con_str, " Message Context: ", msg_con_str
            semanage.semanage_iface_free(iface)
예제 #5
0
	def test_writeinterface(self,sh):
		print "Testing network interface write..."

		(status, iface) = semanage.semanage_iface_create(sh)
		if status < 0:
			raise Error("Could not create SEIface object")	
		if self.verbose: print "SEIface object created."

		status = semanage.semanage_iface_set_name(sh, iface, "test_iface")
		if status < 0:
			raise Error("Could not set SEIface name")
		if self.verbose: print "SEIface name set: ", semanage.semanage_iface_get_name(iface)	

		(status, con) = semanage.semanage_context_create(sh)
		if status < 0:
			raise Error("Could not create SEContext object")
		if self.verbose: print "SEContext object created (for network interface)"

		status = semanage.semanage_context_set_user(sh, con, "system_u")
		if status < 0:
			raise Error("Could not set interface context user")
		if self.verbose: print "SEContext user: "******"object_r")
		if status < 0:
			raise Error("Could not set interface context role")
		if self.verbose: print "SEContext role: ", semanage.semanage_context_get_role(con)

		status = semanage.semanage_context_set_type(sh, con, "default_t")
		if status < 0:
			raise Error("Could not set interface context type")
		if self.verbose: print "SEContext type: ", semanage.semanage_context_get_type(con)

		status = semanage.semanage_context_set_mls(sh, con, "s0:c0.c255")
		if status < 0:
			raise Error("Could not set interface context MLS fields")
		if self.verbose: print "SEContext mls: ", semanage.semanage_context_get_mls(con)

		status = semanage.semanage_iface_set_ifcon(sh, iface, con)
		if status < 0:
			raise Error("Could not set SEIface interface context")
		if self.verbose: print "SEIface interface context set: ", con

		status = semanage.semanage_iface_set_msgcon(sh, iface, con)
		if status < 0:
			raise Error("Could not set SEIface message context")
		if self.verbose: print "SEIface message context set: ", con

		(status,key) = semanage.semanage_iface_key_extract(sh,iface)
		if status < 0:
			raise Error("Could not extract SEIface key")
		if self.verbose: print "SEIface key extracted: ", key

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

		if exists:
			(status, old_iface) = semanage.semanage_iface_query_local(sh, key)
			if status < 0:
				raise Error("Could not query old SEIface")
			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 begin semanage transaction")

		status = semanage.semanage_iface_modify_local(sh,key,iface)
		if status < 0:
			raise Error("Could not modify SEIface")

		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 begin semanage transaction")

		if not exists:
			print "Removing interface..."
			status = semanage.semanage_iface_del_local(sh, key)
			if status < 0:
				raise Error("Could not delete test SEIface")
			if self.verbose: print "Interface delete: ", status
		else:
			print "Resetting interface..."
			status = semanage.semanage_iface_modify_local(sh, key, old_iface)
			if status < 0:
				raise Error("Could not reset test SEIface")
			if self.verbose: print "Interface 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_context_free(con)
		semanage.semanage_iface_key_free(key)
		semanage.semanage_iface_free(iface)
		if exists: semanage.semanage_iface_free(old_iface)
예제 #6
0
    def test_writeinterface(self, sh):
        print("Testing network interface write...")

        (status, iface) = semanage.semanage_iface_create(sh)
        if status < 0:
            raise Error("Could not create SEIface object")
        if self.verbose:
            print("SEIface object created.")

        status = semanage.semanage_iface_set_name(sh, iface, "test_iface")
        if status < 0:
            raise Error("Could not set SEIface name")
        if self.verbose:
            print("SEIface name set: %s" %
                  semanage.semanage_iface_get_name(iface))

        (status, con) = semanage.semanage_context_create(sh)
        if status < 0:
            raise Error("Could not create SEContext object")
        if self.verbose:
            print("SEContext object created (for network interface)")

        status = semanage.semanage_context_set_user(sh, con, "system_u")
        if status < 0:
            raise Error("Could not set interface context user")
        if self.verbose:
            print("SEContext user: %s" %
                  semanage.semanage_context_get_user(con))

        status = semanage.semanage_context_set_role(sh, con, "object_r")
        if status < 0:
            raise Error("Could not set interface context role")
        if self.verbose:
            print("SEContext role: %s" %
                  semanage.semanage_context_get_role(con))

        status = semanage.semanage_context_set_type(sh, con, "default_t")
        if status < 0:
            raise Error("Could not set interface context type")
        if self.verbose:
            print("SEContext type: %s" %
                  semanage.semanage_context_get_type(con))

        status = semanage.semanage_context_set_mls(sh, con, "s0:c0.c255")
        if status < 0:
            raise Error("Could not set interface context MLS fields")
        if self.verbose:
            print("SEContext mls: %s" % semanage.semanage_context_get_mls(con))

        status = semanage.semanage_iface_set_ifcon(sh, iface, con)
        if status < 0:
            raise Error("Could not set SEIface interface context")
        if self.verbose:
            print("SEIface interface context set: %s" % con)

        status = semanage.semanage_iface_set_msgcon(sh, iface, con)
        if status < 0:
            raise Error("Could not set SEIface message context")
        if self.verbose:
            print("SEIface message context set: %s" % con)

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

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

        if exists:
            (status, old_iface) = semanage.semanage_iface_query_local(sh, key)
            if status < 0:
                raise Error("Could not query old SEIface")
            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 begin semanage transaction")

        status = semanage.semanage_iface_modify_local(sh, key, iface)
        if status < 0:
            raise Error("Could not modify SEIface")

        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 begin semanage transaction")

        if not exists:
            print("Removing interface...")
            status = semanage.semanage_iface_del_local(sh, key)
            if status < 0:
                raise Error("Could not delete test SEIface")
            if self.verbose:
                print("Interface delete: %s" % status)
        else:
            print("Resetting interface...")
            status = semanage.semanage_iface_modify_local(sh, key, old_iface)
            if status < 0:
                raise Error("Could not reset test SEIface")
            if self.verbose:
                print("Interface 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_context_free(con)
        semanage.semanage_iface_key_free(key)
        semanage.semanage_iface_free(iface)
        if exists:
            semanage.semanage_iface_free(old_iface)