Esempio n. 1
1
handle = semanage.semanage_handle_create()

if semanage.semanage_is_managed(handle) < 0:
    exit(1)
if semanage.semanage_connect(handle) < 0:
    exit(1)

def print_port(kind, port):
    con = semanage.semanage_port_get_con(port)
    con_str = semanage.semanage_context_to_string(handle, con)
    high = semanage.semanage_port_get_high(port)
    low = semanage.semanage_port_get_low(port)
    proto = semanage.semanage_port_get_proto(port)
    proto_str = semanage.semanage_port_get_proto_str(proto)
    print(kind, con_str[1], high, low, proto_str)

# Always list local ports afterwards so that the provider works correctly
retval, ports = semanage.semanage_port_list(handle)

for port in ports:
    print_port('policy', port)

retval, ports = semanage.semanage_port_list_local(handle)

for port in ports:
    print_port('local', port)

semanage.semanage_disconnect(handle)
semanage.semanage_handle_destroy(handle)
Esempio n. 2
0
	def test_ports(self,sh):
		print "Testing ports..."

		(status, plist) = semanage.semanage_port_list(sh)
		if status < 0:
			raise Error("Could not list ports")
		print "Query status (commit number): ", status

		if ( len(plist) == 0):
			print "No ports found!"
			print "This is not necessarily a test failure."
			return
		for port in plist:
			if self.verbose: print "Port reference: ", port
			low = semanage.semanage_port_get_low(port)
			high = semanage.semanage_port_get_high(port)
			con = semanage.semanage_port_get_con(port)
			proto = semanage.semanage_port_get_proto(port)
			proto_str = semanage.semanage_port_get_proto_str(proto)
			if low == high:
				range_str = str(low)
			else:
				range_str = str(low) + "-" + str(high)
			(rc, con_str) = semanage.semanage_context_to_string(sh,con)
			if rc < 0: con_str = ""
			print "Port: ", range_str, " ", proto_str, " Context: ", con_str
			semanage.semanage_port_free(port)
Esempio n. 3
0
    def test_ports(self, sh):
        print("Testing ports...")

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

        if len(plist) == 0:
            print("No ports found!")
            print("This is not necessarily a test failure.")
            return
        for port in plist:
            if self.verbose:
                print("Port reference: %s" % port)
            low = semanage.semanage_port_get_low(port)
            high = semanage.semanage_port_get_high(port)
            con = semanage.semanage_port_get_con(port)
            proto = semanage.semanage_port_get_proto(port)
            proto_str = semanage.semanage_port_get_proto_str(proto)
            if low == high:
                range_str = str(low)
            else:
                range_str = str(low) + "-" + str(high)
            (rc, con_str) = semanage.semanage_context_to_string(sh, con)
            if rc < 0:
                con_str = ""
            print("Port: %s %s Context: %s" % (range_str, proto_str, con_str))
            semanage.semanage_port_free(port)
Esempio n. 4
0
def list_ports(port_number):

    handle = semanage.semanage_handle_create()
    semanage.semanage_connect(handle)

    (rc, plist) = semanage.semanage_port_list(handle)
    (rc, plocal) = semanage.semanage_port_list_local(handle)

    for port in plist + plocal:
        con = semanage.semanage_port_get_con(port)
        ctype = semanage.semanage_context_get_type(con)
        low = semanage.semanage_port_get_low(port)
        if low == port_number:
            return ctype
Esempio n. 5
0
def list_ports(port_number, port_proto):

    handle = semanage.semanage_handle_create()
    semanage.semanage_connect(handle)

    (rc, plist) = semanage.semanage_port_list(handle)
    (rc, plocal) = semanage.semanage_port_list_local(handle)

    for port in plocal + plist:
        con = semanage.semanage_port_get_con(port)
        ctype = semanage.semanage_context_get_type(con)
        proto = semanage.semanage_port_get_proto(port)
        proto_str = semanage.semanage_port_get_proto_str(proto)
        low = semanage.semanage_port_get_low(port)
        high = semanage.semanage_port_get_high(port)
        if low <= port_number <= high and port_proto == proto_str:
            return ctype
Esempio n. 6
0
if semanage.semanage_is_managed(handle) < 0:
    exit(1)
if semanage.semanage_connect(handle) < 0:
    exit(1)


def print_port(kind, port):
    con = semanage.semanage_port_get_con(port)
    con_str = semanage.semanage_context_to_string(handle, con)
    high = semanage.semanage_port_get_high(port)
    low = semanage.semanage_port_get_low(port)
    proto = semanage.semanage_port_get_proto(port)
    proto_str = semanage.semanage_port_get_proto_str(proto)
    print(kind, con_str[1], high, low, proto_str)


# Always list local ports afterwards so that the provider works correctly
retval, ports = semanage.semanage_port_list(handle)

for port in ports:
    print_port('policy', port)

retval, ports = semanage.semanage_port_list_local(handle)

for port in ports:
    print_port('local', port)

semanage.semanage_disconnect(handle)
semanage.semanage_handle_destroy(handle)