Improve port/fcontext type string API
Improve:
[semanage/sepol]_port_get_proto_str
[semanage/sepol]_fcontext_get_type_str
to take the integer code, and not the record as an argument.
This makes more sense, as the removal of several sepol FIXMEs demonstrate (we can get the type code from places other than the record... from its key, or from sepol structures). This is an API change, dependencies fixed in the patch.
libsemanage/include/semanage/fcontext_record.h +1 -1
@@ -60,7 +60,7 @@ extern int semanage_fcontext_get_type( const semanage_fcontext_t* fcontext);extern const char *semanage_fcontext_get_type_str ( -const semanage_fcontext_t * fcontext); +int type); extern void semanage_fcontext_set_type( semanage_fcontext_t* fcontext,
libsemanage/include/semanage/port_record.h +1 -1
@@ -48,7 +48,7 @@ extern void semanage_port_set_proto( int proto);extern const char *semanage_port_get_proto_str ( -const semanage_port_t * port); +int proto);/* Port */ extern int semanage_port_get_low(
libsemanage/src/fcontext_record.c +5 -4
@@ -63,7 +63,7 @@ int semanage_fcontext_key_extract( fcontext->type, key_ptr) < 0) {ERR (handle,"could not extract key from " "file context %s (%s)" , fcontext->expr, -semanage_fcontext_get_type_str (fcontext)); +semanage_fcontext_get_type_str (fcontext->type));return STATUS_ERR ; }
@@ -179,10 +179,9 @@ int semanage_fcontext_get_type(hidden_def (semanage_fcontext_get_type) const char* semanage_fcontext_get_type_str( -const semanage_fcontext_t * fcontext) { +int type) { -switch (fcontext->type) { -default : +switch (type) {case SEMANAGE_FCONTEXT_ALL :return "all files" ;case SEMANAGE_FCONTEXT_REG :
@@ -199,6 +198,8 @@ const char* semanage_fcontext_get_type_sreturn "symbolic link" ;case SEMANAGE_FCONTEXT_PIPE :return "named pipe" ; +default : +return "????" ; } }hidden_def (semanage_fcontext_get_type_str)
libsemanage/src/fcontexts_file.c +6 -4
@@ -50,10 +50,12 @@ static int fcontext_print(char * con_str =NULL ;const char * expr =semanage_fcontext_get_expr (fcontext); -const char * type =type_str (semanage_fcontext_get_type (fcontext)); +int type =semanage_fcontext_get_type (fcontext); +const char * print_str =type_str (type); +const char * type_str =semanage_fcontext_get_type_str (type);semanage_context_t * con =semanage_fcontext_get_con (fcontext); -if (fprintf (str,"%s %s " , expr, type) <0 ) +if (fprintf (str,"%s %s " , expr, print_str) <0 ) goto err;if (con !=NULL ) {
@@ -70,8 +72,8 @@ static int fcontext_print(return STATUS_SUCCESS ; err: -ERR (handle,"could not print file context " -"%s (%s) to stream" , expr, type); +ERR (handle,"could not print file context for " +"%s (%s) to stream" , expr, type_str);free (con_str);return STATUS_ERR ; }
libsemanage/src/fcontexts_local.c +2 -1
@@ -98,7 +98,8 @@ static int validate_handler(/* Unpack fcontext */ const char * expr =semanage_fcontext_get_expr (fcon); -const char * type_str =semanage_fcontext_get_type_str (fcon); +int type =semanage_fcontext_get_type (fcon); +const char * type_str =semanage_fcontext_get_type_str (type);semanage_context_t * con =semanage_fcontext_get_con (fcon);if (sepol_context_check (handle->sepolh, policydb, con) <0 )
libsemanage/src/port_record.c +2 -2
@@ -88,9 +88,9 @@ void semanage_port_set_proto(hidden_def (semanage_port_set_proto) const char* semanage_port_get_proto_str( -const semanage_port_t * port) { +int proto) { -return sepol_port_get_proto_str (port); +return sepol_port_get_proto_str (proto); }hidden_def (semanage_port_get_proto_str)
libsemanage/src/ports_file.c +4 -3
@@ -29,10 +29,11 @@ static int port_print(int low =semanage_port_get_low (port);int high =semanage_port_get_high (port); -const char * proto =semanage_port_get_proto_str (port); +int proto =semanage_port_get_proto (port); +const char * proto_str =semanage_port_get_proto_str (proto);semanage_context_t * con =semanage_port_get_con (port); -if (fprintf (str,"portcon %s " , proto) <0 ) +if (fprintf (str,"portcon %s " , proto_str) <0 ) goto err;if (low == high) {
@@ -53,7 +54,7 @@ static int port_print( err:ERR (handle,"could not print port range %u - %u (%s) to stream" , - low, high, proto); + low, high, proto_str);free (con_str);return STATUS_ERR ; }
libsemanage/src/ports_local.c +2 -2
@@ -95,7 +95,7 @@ int hidden semanage_port_validate_local(int proto =semanage_port_get_proto (ports[i]);int low =semanage_port_get_low (ports[i]);int high =semanage_port_get_high (ports[i]); -const char * proto_str =semanage_port_get_proto_str (ports[i]); +const char * proto_str =semanage_port_get_proto_str (proto);const char * proto_str2;int proto2, low2, high2;
@@ -109,7 +109,7 @@ int hidden semanage_port_validate_local( proto2 =semanage_port_get_proto (ports[j]); low2 =semanage_port_get_low (ports[j]); high2 =semanage_port_get_high (ports[j]); - proto_str2 =semanage_port_get_proto_str (ports[j]); + proto_str2 =semanage_port_get_proto_str (proto2); }while (proto != proto2);
libsemanage/src/pywrap-test.py +6 -3
@@ -205,7 +205,8 @@ class Tests: low = semanage.semanage_port_get_low(port) high = semanage.semanage_port_get_high(port) con = semanage.semanage_port_get_con(port) - proto_str = semanage.semanage_port_get_proto_str(port) + proto = semanage.semanage_port_get_proto_str(port) + proto_str = semanage.semanage_port_get_proto_str(proto) if low == high: range_str = str(low) else:
@@ -234,7 +235,8 @@ class Tests: fcon = semanage.semanage_fcontext_by_idx(flist, idx) if self.verbose: print "File Context reference: ", fcon expr = semanage.semanage_fcontext_get_expr(fcon) - type_str = semanage.semanage_fcontext_get_type_str(fcon) + type = semanage.semanage_fcontext_get_type(type) + type_str = semanage.semanage_fcontext_get_type_str(type) con = semanage.semanage_fcontext_get_con(fcon) if not con: con_str = "<<none>>"
@@ -499,7 +501,8 @@ class Tests: if self.verbose: print "SEPort range set: ", low, "-", high semanage.semanage_port_set_proto(port, semanage.SEMANAGE_PROTO_TCP); - if self.verbose: print "SEPort protocol set: ", semanage.semanage_port_get_proto_str(port) + if self.verbose: print "SEPort protocol set: ", + semanage.semanage_port_get_proto_str(semanage.SEMANAGE_PROTO_TCP) (status, con) = semanage.semanage_context_create(sh) if status < 0:
libsepol/include/sepol/port_record.h +1 -1
@@ -47,7 +47,7 @@ extern void sepol_port_set_proto( int proto);extern const char *sepol_port_get_proto_str ( -const sepol_port_t * port); +int proto);/* Port */ extern int sepol_port_get_low(
libsepol/src/port_record.c +3 -3
@@ -67,7 +67,7 @@ int sepol_port_key_extract( handle, port->low, port->high, port->proto, key_ptr) < 0) {ERR (handle,"could not extract key from port %s %d:%d" , -sepol_port_get_proto_str (port), +sepol_port_get_proto_str (port->proto), port->low, port->high);return STATUS_ERR ;
@@ -178,9 +178,9 @@ int sepol_port_get_proto(hidden_def (sepol_port_get_proto) const char* sepol_port_get_proto_str( -const sepol_port_t * port) { +int proto) { -switch (port->proto) { +switch (proto) {case SEPOL_PROTO_UDP :return "udp" ;case SEPOL_PROTO_TCP :
libsepol/src/ports.c +16 -13
@@ -107,7 +107,7 @@ static int port_to_record (int low = port->u.port.low_port;int high = port->u.port.high_port;context_struct_t * con = &port->context[0 ]; -int rec_proto; +int rec_proto =-1 ;sepol_context_t * tmp_con =NULL ;sepol_port_t * tmp_record =NULL ;
@@ -132,9 +132,8 @@ static int port_to_record (return STATUS_SUCCESS ; err: -/* FIXME: print protocol string */ -ERR (handle,"could not convert port range %u - %u (protocol: %u)" -"to record" , low, high, proto); +ERR (handle,"could not convert port range %u - %u (%s) " +"to record" , low, high,sepol_port_get_proto_str (rec_proto));sepol_context_free (tmp_con);sepol_port_free (tmp_record);return STATUS_ERR ;
@@ -171,7 +170,9 @@ int sepol_port_exists (ocontext_t *c, *head;int low, high, proto; +const char * proto_str;sepol_port_key_unpack (key, &low, &high, &proto); + proto_str =sepol_port_get_proto_str (proto); proto =sepol2ipproto (handle, proto);if (proto <0 ) goto err;
@@ -192,9 +193,8 @@ int sepol_port_exists (return STATUS_SUCCESS ; err: -/* FIXME: print out protocol string */ -ERR (handle,"could not check if port range %u - %u (protocol: %u) exists" , - low, high, proto); +ERR (handle,"could not check if port range %u - %u (%s) exists" , + low, high, proto_str);return STATUS_ERR ; }
@@ -209,7 +209,9 @@ int sepol_port_query(ocontext_t *c, *l, *head;int low, high, proto; +const char * proto_str;sepol_port_key_unpack (key, &low, &high, &proto); + proto_str =sepol_port_get_proto_str (proto); proto =sepol2ipproto (handle, proto);if (proto <0 ) goto err;
@@ -231,9 +233,8 @@ int sepol_port_query(return STATUS_SUCCESS ; err: -/* FIXME: print protocol string */ -ERR (handle,"could not query port range %u - %u (protocol: %u)" , - low, high, proto); +ERR (handle,"could not query port range %u - %u (%s)" , + low, high, proto_str);return STATUS_ERR ; }
@@ -249,7 +250,10 @@ int sepol_port_modify(ocontext_t *c, *head, *prev =NULL , *port =NULL ;int low, high, proto; +const char * proto_str; +sepol_port_key_unpack (key, &low, &high, &proto); + proto_str =sepol_port_get_proto_str (proto); proto =sepol2ipproto (handle, proto);if (proto <0 ) goto err;
@@ -286,9 +290,8 @@ int sepol_port_modify(return STATUS_SUCCESS ; err: -/* FIXME: print protocol string */ -ERR (handle,"could not load port range %u - %u (protocol: %u)" , - low, high, proto); +ERR (handle,"could not load port range %u - %u (%s)" , + low, high, proto_str);if (port !=NULL ) {context_destroy (&port->context[0 ]);free (port);
policycoreutils/semanage/seobject.py +22 -19
71 lines not on this page · raw message
Quoted 10 lines · Ivan Gyurdiev
Improve:
[semanage/sepol]_port_get_proto_str
[semanage/sepol]_fcontext_get_type_strto take the integer code, and not the record as an argument. This makes more sense, as the removal of several sepol FIXMEs demonstrate (we can get the type code from places other than the record... from its key, or from sepol structures). This is an API change, dependencies fixed in the patch.
Merged as of libsepol 1.11.10, libsemanage 1.5.19, and policycoreutils 1.29.16.
Signature · 8 lines
Stephen Smalley National Security Agency -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.