libsepol: remove unused files
PATCH 1/3 libsepol: remove unused files
libsepol/src/roles.c contains functions which do not match its header file libsepol/include/sepol/roles.h:
// In roles.c
int sepol_role_exists(sepol_handle_t * handle __attribute__ ((unused)),
sepol_policydb_t * p, const char *role, int *response)
// In roles.h
extern int sepol_role_exists(const sepol_policydb_t * policydb,
const char *role, int *response);
and:
// In roles.c
int sepol_role_list(sepol_handle_t * handle,
sepol_policydb_t * p, char ***roles, unsigned int *nroles)
// In roles.h
extern int sepol_role_list(const sepol_policydb_t * policydb,
char ***roles, unsigned int *nroles);
Instead of fixing the parameter type (using sepol_handle_t or sepol_policydb_t but not different ones), remove these functions, as they appear not to be used. They are not exported in libsepol.so.
--- libsepol/include/sepol/roles.h | 18 ------------ libsepol/src/roles.c | 53 ---------------------------------- 2 files changed, 71 deletions(-) delete mode 100644 libsepol/include/sepol/roles.h delete mode 100644 libsepol/src/roles.c
libsepol/include/sepol/roles.h deleted +0 -18
@@ -1,18 +0,0 @@ -#ifndef _SEPOL_ROLES_H_ -#define _SEPOL_ROLES_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -extern int sepol_role_exists (const sepol_policydb_t * policydb, -const char *role,int *response); - -extern int sepol_role_list (const sepol_policydb_t * policydb, -char ***roles,unsigned int *nroles); - -#ifdef __cplusplus -} -#endif - -#endif
libsepol/src/roles.c deleted +0 -53
53 lines not on this page · raw message
Signature · 1 line
2.30.0
PATCH 2/3 libsepol: uniformize prototypes of sepol_mls_contains and sepol_mls_check
In libsepol/src/mls.c, functions sepol_mls_contains and sepol_mls_check used "sepol_policydb_t * policydb" even though libsepol/include/sepol/context.h used "const sepol_policydb_t * policydb".
Add const qualifiers in mls.c in order to match the header file. Detect such mismatching error at compile time by including the header file in mls.c.
--- libsepol/src/mls.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
libsepol/src/mls.c +3 -2
@@ -27,6 +27,7 @@* Implementation of the multi-level security (MLS) policy. */ +#include <sepol/context.h> #include <sepol/policydb/policydb.h> #include <sepol/policydb/services.h> #include <sepol/policydb/context.h>
@@ -664,7 +665,7 @@ int mls_compute_sid(policydb_t * policydb, }int sepol_mls_contains (sepol_handle_t * handle, -sepol_policydb_t * policydb, +const sepol_policydb_t * policydb,const char *mls1,const char *mls2,int *response) {
@@ -703,7 +704,7 @@ int sepol_mls_contains(sepol_handle_t * handle, }int sepol_mls_check (sepol_handle_t * handle, -sepol_policydb_t * policydb,const char *mls) +const sepol_policydb_t * policydb,const char *mls) {int ret;
Signature · 1 line
2.30.0
Re: [PATCH 2/3] libsepol: uniformize prototypes of sepol_mls_contains and sepol_mls_check
Quoted 11 lines · Nicolas Iooss
In
libsepol/src/mls.c, functionssepol_mls_containsandsepol_mls_checkused "sepol_policydb_t* policydb" even thoughlibsepol/include/sepol/context.hused "constsepol_policydb_t* policydb".Add const qualifiers in
mls.cin order to match the header file. Detect such mismatching error at compile time by including the header file inmls.c.Signed-off-by Nicolas Iooss <[email protected]>
Quoted 37 lines
--- libsepol/src/mls.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)libsepol/src/mls.c +3
-3@@ -27,6 +27,7 @@* Implementation of the multi-level security (MLS) policy. */ +#include <sepol/context.h> #include <sepol/policydb/policydb.h> #include <sepol/policydb/services.h> #include <sepol/policydb/context.h> @@ -664,7 +665,7 @@ int mls_compute_sid(policydb_t * policydb, }int sepol_mls_contains (sepol_handle_t * handle, -sepol_policydb_t * policydb, +const sepol_policydb_t * policydb,const char *mls1,const char *mls2,int *response) {@@ -703,7 +704,7 @@ int sepol_mls_contains(sepol_handle_t * handle, }int sepol_mls_check (sepol_handle_t * handle, -sepol_policydb_t * policydb,const char *mls) +const sepol_policydb_t * policydb,const char *mls) {int ret; --2.30.0
Re: [PATCH 2/3] libsepol: uniformize prototypes of sepol_mls_contains and sepol_mls_check
Quoted 8 lines · James Carter
Quoted 6 lines · Nicolas Iooss
In
libsepol/src/mls.c, functionssepol_mls_containsandsepol_mls_checkused "sepol_policydb_t* policydb" even thoughlibsepol/include/sepol/context.hused "constsepol_policydb_t* policydb".
Quoted 7 lines
Quoted 5 lines
Add const qualifiers in
mls.cin order to match the header file. Detect such mismatching error at compile time by including the header file inmls.c.Signed-off-by Nicolas Iooss <[email protected]>Acked-by James Carter <[email protected]>
Merged.
Nicolas
Quoted 37 lines
Quoted 37 lines
--- libsepol/src/mls.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)libsepol/src/mls.c +3
-3@@ -27,6 +27,7 @@* Implementation of the multi-level security (MLS) policy. */ +#include <sepol/context.h> #include <sepol/policydb/policydb.h> #include <sepol/policydb/services.h> #include <sepol/policydb/context.h> @@ -664,7 +665,7 @@ int mls_compute_sid(policydb_t * policydb, }int sepol_mls_contains (sepol_handle_t * handle, -sepol_policydb_t * policydb, +const sepol_policydb_t * policydb,const char *mls1,const char *mls2,int *response) {@@ -703,7 +704,7 @@ int sepol_mls_contains(sepol_handle_t * handle, }int sepol_mls_check (sepol_handle_t * handle, -sepol_policydb_t * policydb,const char *mls) +const sepol_policydb_t * policydb,const char *mls) {int ret; --2.30.0
PATCH 3/3 libsepol: include header files in source files when matching declarations
In reply to Nicolas IoossIt is good practise in C to include the header file that specifies the prototype of functions which are defined in the source file. Otherwise, the function prototypes which be different, which could cause unexpected issues.
Add the include directives to do this.
--- libsepol/cil/src/cil_find.c | 1 + libsepol/cil/src/cil_fqn.c | 1 + libsepol/cil/src/cil_mem.c | 1 + libsepol/cil/src/cil_parser.c | 1 + libsepol/cil/src/cil_policy.c | 1 + libsepol/cil/src/cil_reset_ast.c | 1 + libsepol/src/kernel_to_cil.c | 1 + libsepol/src/kernel_to_conf.c | 1 + libsepol/src/services.c | 1 + 9 files changed, 9 insertions(+)
libsepol/cil/src/cil_find.c +1 -0
@@ -30,6 +30,7 @@#include <sepol/policydb/ebitmap.h> #include "cil_internal.h" +#include "cil_find.h" #include "cil_flavor.h" #include "cil_list.h" #include "cil_log.h"
libsepol/cil/src/cil_fqn.c +1 -0
@@ -31,6 +31,7 @@#include <stdio.h> #include <string.h> +#include "cil_fqn.h" #include "cil_internal.h" #include "cil_log.h" #include "cil_strpool.h"
libsepol/cil/src/cil_mem.c +1 -0
@@ -33,6 +33,7 @@#include <string.h> #include "cil_log.h" +#include "cil_mem.h" void *cil_malloc (size_t size) {
libsepol/cil/src/cil_parser.c +1 -0
@@ -38,6 +38,7 @@#include "cil_mem.h" #include "cil_tree.h" #include "cil_lexer.h" +#include "cil_parser.h" #include "cil_strpool.h" #include "cil_stack.h"
libsepol/cil/src/cil_policy.c +1 -0
@@ -41,6 +41,7 @@#include "cil_flavor.h" #include "cil_find.h" #include "cil_mem.h" +#include "cil_policy.h" #include "cil_tree.h" #include "cil_list.h" #include "cil_symtab.h"
libsepol/cil/src/cil_reset_ast.c +1 -0
@@ -2,6 +2,7 @@#include "cil_internal.h" #include "cil_log.h" #include "cil_list.h" +#include "cil_reset_ast.h" #include "cil_symtab.h" static inline void cil_reset_classperms_list (struct cil_list *cp_list);
libsepol/src/kernel_to_cil.c +1 -0
@@ -16,6 +16,7 @@#define IPPROTO_SCTP 132#endif +#include <sepol/kernel_to_cil.h> #include <sepol/policydb/avtab.h> #include <sepol/policydb/conditional.h> #include <sepol/policydb/hashtab.h>
libsepol/src/kernel_to_conf.c +1 -0
@@ -15,6 +15,7 @@#define IPPROTO_SCTP 132#endif +#include <sepol/kernel_to_conf.h> #include <sepol/policydb/avtab.h> #include <sepol/policydb/conditional.h> #include <sepol/policydb/hashtab.h>
libsepol/src/services.c +1 -0
@@ -59,6 +59,7 @@#include <sepol/policydb/services.h> #include <sepol/policydb/conditional.h> #include <sepol/policydb/util.h> +#include <sepol/sepol.h> #include "debug.h" #include "private.h"
Signature · 1 line
2.30.0
Re: [PATCH 3/3] libsepol: include header files in source files when matching declarations
Quoted 9 lines · Nicolas Iooss
It is good practise in C to include the header file that specifies the prototype of functions which are defined in the source file. Otherwise, the function prototypes which be different, which could cause unexpected issues.
Add the include directives to do this.
Signed-off-by Nicolas Iooss <[email protected]>
Quoted 123 lines
--- libsepol/cil/src/cil_find.c | 1 + libsepol/cil/src/cil_fqn.c | 1 + libsepol/cil/src/cil_mem.c | 1 + libsepol/cil/src/cil_parser.c | 1 + libsepol/cil/src/cil_policy.c | 1 + libsepol/cil/src/cil_reset_ast.c | 1 + libsepol/src/kernel_to_cil.c | 1 + libsepol/src/kernel_to_conf.c | 1 + libsepol/src/services.c | 1 + 9 files changed, 9 insertions(+)libsepol/cil/src/cil_find.c +1
-0@@ -30,6 +30,7 @@#include <sepol/policydb/ebitmap.h> #include "cil_internal.h" +#include "cil_find.h" #include "cil_flavor.h" #include "cil_list.h" #include "cil_log.h" libsepol/cil/src/cil_fqn.c +1
-0@@ -31,6 +31,7 @@#include <stdio.h> #include <string.h> +#include "cil_fqn.h" #include "cil_internal.h" #include "cil_log.h" #include "cil_strpool.h" libsepol/cil/src/cil_mem.c +1
-0@@ -33,6 +33,7 @@#include <string.h> #include "cil_log.h" +#include "cil_mem.h" void *cil_malloc (size_t size) {libsepol/cil/src/cil_parser.c +1
-0@@ -38,6 +38,7 @@#include "cil_mem.h" #include "cil_tree.h" #include "cil_lexer.h" +#include "cil_parser.h" #include "cil_strpool.h" #include "cil_stack.h" libsepol/cil/src/cil_policy.c +1
-0@@ -41,6 +41,7 @@#include "cil_flavor.h" #include "cil_find.h" #include "cil_mem.h" +#include "cil_policy.h" #include "cil_tree.h" #include "cil_list.h" #include "cil_symtab.h" libsepol/cil/src/cil_reset_ast.c +1
-0@@ -2,6 +2,7 @@#include "cil_internal.h" #include "cil_log.h" #include "cil_list.h" +#include "cil_reset_ast.h" #include "cil_symtab.h" static inline void cil_reset_classperms_list (struct cil_list *cp_list);libsepol/src/kernel_to_cil.c +1
-0@@ -16,6 +16,7 @@#define IPPROTO_SCTP 132#endif +#include <sepol/kernel_to_cil.h> #include <sepol/policydb/avtab.h> #include <sepol/policydb/conditional.h> #include <sepol/policydb/hashtab.h> libsepol/src/kernel_to_conf.c +1
-0@@ -15,6 +15,7 @@#define IPPROTO_SCTP 132#endif +#include <sepol/kernel_to_conf.h> #include <sepol/policydb/avtab.h> #include <sepol/policydb/conditional.h> #include <sepol/policydb/hashtab.h> libsepol/src/services.c +1
-1@@ -59,6 +59,7 @@#include <sepol/policydb/services.h> #include <sepol/policydb/conditional.h> #include <sepol/policydb/util.h> +#include <sepol/sepol.h> #include "debug.h" #include "private.h" --2.30.0
Re: [PATCH 3/3] libsepol: include header files in source files when matching declarations
Quoted 8 lines · James Carter
Quoted 6 lines · Nicolas Iooss
It is good practise in C to include the header file that specifies the prototype of functions which are defined in the source file. Otherwise, the function prototypes which be different, which could cause unexpected issues.
Quoted 5 lines
Quoted 3 lines
Add the include directives to do this.
Signed-off-by Nicolas Iooss <[email protected]>Acked-by James Carter <[email protected]>
Merged.
Nicolas
Quoted 123 lines
Quoted 123 lines
--- libsepol/cil/src/cil_find.c | 1 + libsepol/cil/src/cil_fqn.c | 1 + libsepol/cil/src/cil_mem.c | 1 + libsepol/cil/src/cil_parser.c | 1 + libsepol/cil/src/cil_policy.c | 1 + libsepol/cil/src/cil_reset_ast.c | 1 + libsepol/src/kernel_to_cil.c | 1 + libsepol/src/kernel_to_conf.c | 1 + libsepol/src/services.c | 1 + 9 files changed, 9 insertions(+)libsepol/cil/src/cil_find.c +1
-0@@ -30,6 +30,7 @@#include <sepol/policydb/ebitmap.h> #include "cil_internal.h" +#include "cil_find.h" #include "cil_flavor.h" #include "cil_list.h" #include "cil_log.h" libsepol/cil/src/cil_fqn.c +1
-0@@ -31,6 +31,7 @@#include <stdio.h> #include <string.h> +#include "cil_fqn.h" #include "cil_internal.h" #include "cil_log.h" #include "cil_strpool.h" libsepol/cil/src/cil_mem.c +1
-0@@ -33,6 +33,7 @@#include <string.h> #include "cil_log.h" +#include "cil_mem.h" void *cil_malloc (size_t size) {libsepol/cil/src/cil_parser.c +1
-0@@ -38,6 +38,7 @@#include "cil_mem.h" #include "cil_tree.h" #include "cil_lexer.h" +#include "cil_parser.h" #include "cil_strpool.h" #include "cil_stack.h" libsepol/cil/src/cil_policy.c +1
-0@@ -41,6 +41,7 @@#include "cil_flavor.h" #include "cil_find.h" #include "cil_mem.h" +#include "cil_policy.h" #include "cil_tree.h" #include "cil_list.h" #include "cil_symtab.h" libsepol/cil/src/cil_reset_ast.c +1
-0@@ -2,6 +2,7 @@#include "cil_internal.h" #include "cil_log.h" #include "cil_list.h" +#include "cil_reset_ast.h" #include "cil_symtab.h" static inline void cil_reset_classperms_list (struct cil_list *cp_list);libsepol/src/kernel_to_cil.c +1
-0@@ -16,6 +16,7 @@#define IPPROTO_SCTP 132#endif +#include <sepol/kernel_to_cil.h> #include <sepol/policydb/avtab.h> #include <sepol/policydb/conditional.h> #include <sepol/policydb/hashtab.h> libsepol/src/kernel_to_conf.c +1
-0@@ -15,6 +15,7 @@#define IPPROTO_SCTP 132#endif +#include <sepol/kernel_to_conf.h> #include <sepol/policydb/avtab.h> #include <sepol/policydb/conditional.h> #include <sepol/policydb/hashtab.h> libsepol/src/services.c +1
-1@@ -59,6 +59,7 @@#include <sepol/policydb/services.h> #include <sepol/policydb/conditional.h> #include <sepol/policydb/util.h> +#include <sepol/sepol.h> #include "debug.h" #include "private.h" --2.30.0
Quoted 20 lines · Nicolas Iooss
libsepol/src/roles.ccontains functions which do not match its header filelibsepol/include/sepol/roles.h:// In
roles.c
int sepol_role_exists(sepol_handle_t * handle__attribute__((unused)),
sepol_policydb_t* p, const char *role, int *response)
// Inroles.h
extern int sepol_role_exists(constsepol_policydb_t* policydb,
const char *role, int *response);and:
// In
roles.c
int sepol_role_list(sepol_handle_t * handle,
sepol_policydb_t* p, char ***roles, unsigned int *nroles)
// Inroles.h
extern int sepol_role_list(constsepol_policydb_t* policydb,
char ***roles, unsigned int *nroles);
Quoted 5 lines
Instead of fixing the parameter type (using
sepol_handle_torsepol_policydb_tbut not different ones), remove these functions, as they appear not to be used. They are not exported in libsepol.so.Signed-off-by Nicolas Iooss <[email protected]>
Quoted 93 lines
--- libsepol/include/sepol/roles.h | 18 ------------ libsepol/src/roles.c | 53 ---------------------------------- 2 files changed, 71 deletions(-) delete mode 100644 libsepol/include/sepol/roles.h delete mode 100644 libsepol/src/roles.clibsepol/include/sepol/roles.h deleted +0
-18@@ -1,18 +0,0 @@ -#ifndef _SEPOL_ROLES_H_ -#define _SEPOL_ROLES_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -extern int sepol_role_exists (const sepol_policydb_t * policydb, -const char *role,int *response); - -extern int sepol_role_list (const sepol_policydb_t * policydb, -char ***roles,unsigned int *nroles); - -#ifdef __cplusplus -} -#endif - -#endif libsepol/src/roles.c deleted +0
-54@@ -1,53 +0,0 @@ -#include <stdlib.h> -#include <string.h> - -#include <sepol/policydb/hashtab.h> -#include <sepol/policydb/policydb.h> - -#include "debug.h" -#include "handle.h" - -/* Check if a role exists */ -int sepol_role_exists (sepol_handle_t * handle __attribute__ ((unused)), -sepol_policydb_t * p,const char *role,int *response) -{ - -policydb_t *policydb = &p->p; - *response = (hashtab_search (policydb->p_roles.table, role) !=NULL ); - -return STATUS_SUCCESS ; -} - -/* Fill an array with all valid roles */ -int sepol_role_list (sepol_handle_t * handle, -sepol_policydb_t * p,char ***roles,unsigned int *nroles) -{ - -policydb_t *policydb = &p->p; -unsigned int tmp_nroles = policydb->p_roles.nprim; -char **tmp_roles = (char **)malloc (tmp_nroles *sizeof (char *)); -char **ptr; -unsigned int i; -if (!tmp_roles) - goto omem; - -for (i =0 ; i < tmp_nroles; i++) { - tmp_roles[i] =strdup (policydb->p_role_val_to_name[i]); -if (!tmp_roles[i]) - goto omem; - } - - *nroles = tmp_nroles; - *roles = tmp_roles; - -return STATUS_SUCCESS ; - - omem: -ERR (handle,"out of memory, could not list roles" ); - - ptr = tmp_roles; -while (ptr && *ptr) -free (*ptr++); -free (tmp_roles); -return STATUS_ERR ; -} --2.30.0
Quoted 22 lines · James Carter
Quoted 20 lines · Nicolas Iooss
libsepol/src/roles.ccontains functions which do not match its header filelibsepol/include/sepol/roles.h:// In
roles.c
int sepol_role_exists(sepol_handle_t * handle__attribute__((unused)),
sepol_policydb_t* p, const char *role, int *response)
// Inroles.h
extern int sepol_role_exists(constsepol_policydb_t* policydb,
const char *role, int *response);and:
// In
roles.c
int sepol_role_list(sepol_handle_t * handle,
sepol_policydb_t* p, char ***roles, unsigned int *nroles)
// Inroles.h
extern int sepol_role_list(constsepol_policydb_t* policydb,
char ***roles, unsigned int *nroles);
Quoted 7 lines
Quoted 5 lines
Instead of fixing the parameter type (using
sepol_handle_torsepol_policydb_tbut not different ones), remove these functions, as they appear not to be used. They are not exported in libsepol.so.Signed-off-by Nicolas Iooss <[email protected]>Acked-by James Carter <[email protected]>
Merged.
Nicolas
Quoted 93 lines
Quoted 93 lines
--- libsepol/include/sepol/roles.h | 18 ------------ libsepol/src/roles.c | 53 ---------------------------------- 2 files changed, 71 deletions(-) delete mode 100644 libsepol/include/sepol/roles.h delete mode 100644 libsepol/src/roles.clibsepol/include/sepol/roles.h deleted +0
-18@@ -1,18 +0,0 @@ -#ifndef _SEPOL_ROLES_H_ -#define _SEPOL_ROLES_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -extern int sepol_role_exists (const sepol_policydb_t * policydb, -const char *role,int *response); - -extern int sepol_role_list (const sepol_policydb_t * policydb, -char ***roles,unsigned int *nroles); - -#ifdef __cplusplus -} -#endif - -#endif libsepol/src/roles.c deleted +0
-54@@ -1,53 +0,0 @@ -#include <stdlib.h> -#include <string.h> - -#include <sepol/policydb/hashtab.h> -#include <sepol/policydb/policydb.h> - -#include "debug.h" -#include "handle.h" - -/* Check if a role exists */ -int sepol_role_exists (sepol_handle_t * handle __attribute__ ((unused)), -sepol_policydb_t * p,const char *role,int *response) -{ - -policydb_t *policydb = &p->p; - *response = (hashtab_search (policydb->p_roles.table, role) !=NULL ); - -return STATUS_SUCCESS ; -} - -/* Fill an array with all valid roles */ -int sepol_role_list (sepol_handle_t * handle, -sepol_policydb_t * p,char ***roles,unsigned int *nroles) -{ - -policydb_t *policydb = &p->p; -unsigned int tmp_nroles = policydb->p_roles.nprim; -char **tmp_roles = (char **)malloc (tmp_nroles *sizeof (char *)); -char **ptr; -unsigned int i; -if (!tmp_roles) - goto omem; - -for (i =0 ; i < tmp_nroles; i++) { - tmp_roles[i] =strdup (policydb->p_role_val_to_name[i]); -if (!tmp_roles[i]) - goto omem; - } - - *nroles = tmp_nroles; - *roles = tmp_roles; - -return STATUS_SUCCESS ; - - omem: -ERR (handle,"out of memory, could not list roles" ); - - ptr = tmp_roles; -while (ptr && *ptr) -free (*ptr++); -free (tmp_roles); -return STATUS_ERR ; -} --2.30.0