16cd6a6acSopenharmony_ci#include <stdlib.h> 26cd6a6acSopenharmony_ci#include <assert.h> 36cd6a6acSopenharmony_ci#include "handle.h" 46cd6a6acSopenharmony_ci#include "debug.h" 56cd6a6acSopenharmony_ci 66cd6a6acSopenharmony_cisepol_handle_t *sepol_handle_create(void) 76cd6a6acSopenharmony_ci{ 86cd6a6acSopenharmony_ci 96cd6a6acSopenharmony_ci sepol_handle_t *sh = malloc(sizeof(sepol_handle_t)); 106cd6a6acSopenharmony_ci if (sh == NULL) 116cd6a6acSopenharmony_ci return NULL; 126cd6a6acSopenharmony_ci 136cd6a6acSopenharmony_ci /* Set callback */ 146cd6a6acSopenharmony_ci sh->msg_callback = sepol_msg_default_handler; 156cd6a6acSopenharmony_ci sh->msg_callback_arg = NULL; 166cd6a6acSopenharmony_ci 176cd6a6acSopenharmony_ci /* by default do not disable dontaudits */ 186cd6a6acSopenharmony_ci sh->disable_dontaudit = 0; 196cd6a6acSopenharmony_ci sh->expand_consume_base = 0; 206cd6a6acSopenharmony_ci 216cd6a6acSopenharmony_ci /* by default needless unused branch of tunables would be discarded */ 226cd6a6acSopenharmony_ci sh->preserve_tunables = 0; 236cd6a6acSopenharmony_ci 246cd6a6acSopenharmony_ci return sh; 256cd6a6acSopenharmony_ci} 266cd6a6acSopenharmony_ci 276cd6a6acSopenharmony_ciint sepol_get_preserve_tunables(sepol_handle_t *sh) 286cd6a6acSopenharmony_ci{ 296cd6a6acSopenharmony_ci assert(sh != NULL); 306cd6a6acSopenharmony_ci return sh->preserve_tunables; 316cd6a6acSopenharmony_ci} 326cd6a6acSopenharmony_ci 336cd6a6acSopenharmony_civoid sepol_set_preserve_tunables(sepol_handle_t * sh, int preserve_tunables) 346cd6a6acSopenharmony_ci{ 356cd6a6acSopenharmony_ci assert(sh !=NULL); 366cd6a6acSopenharmony_ci sh->preserve_tunables = preserve_tunables; 376cd6a6acSopenharmony_ci} 386cd6a6acSopenharmony_ci 396cd6a6acSopenharmony_ciint sepol_get_disable_dontaudit(sepol_handle_t *sh) 406cd6a6acSopenharmony_ci{ 416cd6a6acSopenharmony_ci assert(sh !=NULL); 426cd6a6acSopenharmony_ci return sh->disable_dontaudit; 436cd6a6acSopenharmony_ci} 446cd6a6acSopenharmony_ci 456cd6a6acSopenharmony_civoid sepol_set_disable_dontaudit(sepol_handle_t * sh, int disable_dontaudit) 466cd6a6acSopenharmony_ci{ 476cd6a6acSopenharmony_ci assert(sh !=NULL); 486cd6a6acSopenharmony_ci sh->disable_dontaudit = disable_dontaudit; 496cd6a6acSopenharmony_ci} 506cd6a6acSopenharmony_ci 516cd6a6acSopenharmony_civoid sepol_set_expand_consume_base(sepol_handle_t *sh, int consume_base) 526cd6a6acSopenharmony_ci{ 536cd6a6acSopenharmony_ci assert(sh != NULL); 546cd6a6acSopenharmony_ci sh->expand_consume_base = consume_base; 556cd6a6acSopenharmony_ci} 566cd6a6acSopenharmony_ci 576cd6a6acSopenharmony_civoid sepol_handle_destroy(sepol_handle_t * sh) 586cd6a6acSopenharmony_ci{ 596cd6a6acSopenharmony_ci free(sh); 606cd6a6acSopenharmony_ci} 61