Policydb_convert in legacy
PATCH 5/6 Policydb_convert in legacy
The following patch makes legacygenbools.c and genusers.c use
the new policydb_convert functions:
libsepol-2.2-convert_in_legacy.diff
It depends on:
libsepol-2.1-users.diff
src/genbools.c +17 -25
@@ -114,15 +114,8 @@struct policy_file pf;int rc; - pf.type =PF_USE_MEMORY ; - pf.data = data; - pf.len = len; -if (policydb_read (&policydb,&pf,0 )) { -__sepol_debug_printf ("%s: binary policy image is invalid\n" , - __FUNCTION__); - errno =EINVAL ; -return -1 ; - } +if (policydb_from_image (data, len, &policydb) <0 ) + goto err;/* Preserve the policy version of the original policy for the new policy. */
@@ -137,7 +130,7 @@__sepol_debug_printf ("%s: Error while re-evaluating conditionals\n" , __FUNCTION__); errno =EINVAL ; - goto err; + goto err_destroy; } pf.data = data;
@@ -147,14 +140,16 @@__sepol_debug_printf ("%s: Can't write new binary policy image\n" , __FUNCTION__); errno =EINVAL ; - goto err; + goto err_destroy; }policydb_destroy (&policydb);return 0 ; - err: + err_destroy:policydb_destroy (&policydb); + + err:return -1 ; }
@@ -177,15 +172,9 @@int rc, i, errors =0 ;struct cond_bool_datum *datum; - pf.type =PF_USE_MEMORY ; - pf.data = data; - pf.len = len; -if (policydb_read (&policydb,&pf,0 )) { -__sepol_debug_printf ("%s: binary policy image is invalid\n" , - __FUNCTION__); - errno =EINVAL ; -return -1 ; - } +/* Create policy database from image */ +if (policydb_from_image (data, len, &policydb) <0 ) + goto err;/* Preserve the policy version of the original policy for the new policy. */
@@ -211,7 +200,7 @@__sepol_debug_printf ("%s: Error while re-evaluating conditionals\n" , __FUNCTION__); errno =EINVAL ; - goto err; + goto err_destroy; } pf.data = data;
@@ -221,17 +210,20 @@__sepol_debug_printf ("%s: Can't write binary policy\n" , __FUNCTION__); errno =EINVAL ; - goto err; + goto err_destroy; }if (errors) { errno =EINVAL ; - goto err; + goto err_destroy; }policydb_destroy (&policydb);return 0 ; -err: + + err_destroy:policydb_destroy (&policydb); + + err:return -1 ; }
src/genusers.c +11 -65
109 lines not on this page · raw message