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)
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)
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)
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)
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
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