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)
def test_nodes(self,sh): print "Testing network nodes..." (status, nlist) = semanage.semanage_node_list(sh) if status < 0: raise Error("Could not list network nodes") print "Query status (commit number): ", status if (len(nlist) == 0): print "No network nodes found!" print "This is not necessarily a test failure." return for node in nlist: if self.verbose: print "Network node reference: ", node (status, addr) = semanage.semanage_node_get_addr(sh, node) if status < 0: addr = "" (status, mask) = semanage.semanage_node_get_mask(sh, node) if status < 0: mask = "" proto = semanage.semanage_node_get_proto(node) proto_str = semanage.semanage_node_get_proto_str(proto) con = semanage.semanage_node_get_con(node) (status, con_str) = semanage.semanage_context_to_string(sh, con) if status < 0: con_str = "" print "Network Node: ", addr, "/", mask, " (", proto_str, ")", "Context: ", con_str semanage.semanage_node_free(node)
def test_fcontexts(self,sh): print "Testing file contexts..." (status, flist) = semanage.semanage_fcontext_list(sh) if status < 0: raise Error("Could not list file contexts") print "Query status (commit number): ", status if (len(flist) == 0): print "No file contexts found!" print "This is not necessarily a test failure." return for fcon in flist: if self.verbose: print "File Context reference: ", fcon expr = semanage.semanage_fcontext_get_expr(fcon) type = semanage.semanage_fcontext_get_type(fcon) type_str = semanage.semanage_fcontext_get_type_str(type) con = semanage.semanage_fcontext_get_con(fcon) if not con: con_str = "<<none>>" else: (rc, con_str) = semanage.semanage_context_to_string(sh,con) if rc < 0: con_str = "" print "File Expr: ", expr, " [", type_str, "] Context: ", con_str semanage.semanage_fcontext_free(fcon)
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_nodes(self, sh): print("Testing network nodes...") (status, nlist) = semanage.semanage_node_list(sh) if status < 0: raise Error("Could not list network nodes") print("Query status (commit number): %s" % status) if len(nlist) == 0: print("No network nodes found!") print("This is not necessarily a test failure.") return for node in nlist: if self.verbose: print("Network node reference: %s" % node) (status, addr) = semanage.semanage_node_get_addr(sh, node) if status < 0: addr = "" (status, mask) = semanage.semanage_node_get_mask(sh, node) if status < 0: mask = "" proto = semanage.semanage_node_get_proto(node) proto_str = semanage.semanage_node_get_proto_str(proto) con = semanage.semanage_node_get_con(node) (status, con_str) = semanage.semanage_context_to_string(sh, con) if status < 0: con_str = "" print("Network Node: %s/%s (%s) Context: %s" % (addr, mask, proto_str, con_str)) semanage.semanage_node_free(node)
def test_fcontexts(self, sh): print("Testing file contexts...") (status, flist) = semanage.semanage_fcontext_list(sh) if status < 0: raise Error("Could not list file contexts") print("Query status (commit number): %s" % status) if len(flist) == 0: print("No file contexts found!") print("This is not necessarily a test failure.") return for fcon in flist: if self.verbose: print("File Context reference: %s" % fcon) expr = semanage.semanage_fcontext_get_expr(fcon) type = semanage.semanage_fcontext_get_type(fcon) type_str = semanage.semanage_fcontext_get_type_str(type) con = semanage.semanage_fcontext_get_con(fcon) if not con: con_str = "<<none>>" else: (rc, con_str) = semanage.semanage_context_to_string(sh, con) if rc < 0: con_str = "" print("File Expr: %s [%s] Context: %s" % (expr, type_str, con_str)) semanage.semanage_fcontext_free(fcon)
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 test_nodes(self, sh): print "Testing network nodes..." (status, nlist) = semanage.semanage_node_list(sh) if status < 0: raise Error("Could not list network nodes") print "Query status (commit number): ", status if (len(nlist) == 0): print "No network nodes found!" print "This is not necessarily a test failure." return for node in nlist: if self.verbose: print "Network node reference: ", node (status, addr) = semanage.semanage_node_get_addr(sh, node) if status < 0: addr = "" (status, mask) = semanage.semanage_node_get_mask(sh, node) if status < 0: mask = "" proto = semanage.semanage_node_get_proto(node) proto_str = semanage.semanage_node_get_proto_str(proto) con = semanage.semanage_node_get_con(node) (status, con_str) = semanage.semanage_context_to_string(sh, con) if status < 0: con_str = "" print "Network Node: ", addr, "/", mask, " (", proto_str, ")", "Context: ", con_str semanage.semanage_node_free(node)
def test_fcontexts(self, sh): print "Testing file contexts..." (status, flist) = semanage.semanage_fcontext_list(sh) if status < 0: raise Error("Could not list file contexts") print "Query status (commit number): ", status if (len(flist) == 0): print "No file contexts found!" print "This is not necessarily a test failure." return for fcon in flist: if self.verbose: print "File Context reference: ", fcon expr = semanage.semanage_fcontext_get_expr(fcon) type = semanage.semanage_fcontext_get_type(fcon) type_str = semanage.semanage_fcontext_get_type_str(type) con = semanage.semanage_fcontext_get_con(fcon) if not con: con_str = "<<none>>" else: (rc, con_str) = semanage.semanage_context_to_string(sh, con) if rc < 0: con_str = "" print "File Expr: ", expr, " [", type_str, "] Context: ", con_str semanage.semanage_fcontext_free(fcon)
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 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)
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)