plugins/pap/posix/pap_plugin_posix.c
// List must be freed bu the user
List must be freed bu the user
List must be freed bu the user
static bool acquire_all_policies(pap_policy_id_list_t** pol_list_head) {
  char pol_id_hex[PAP_POL_ID_MAX_LEN] = {0};
  char* pol_id_buff = NULL;
  char* tok = NULL;
  int pol_id_buff_len = 0;
  pap_policy_id_list_t* temp = NULL;
  FILE* f;
  f = fopen("stored_policies/stored_policies.txt", "r");
  if (f == NULL) {
    log_error(plugin_logger_id, "[%s:%d] file empty.\n", __func__, __LINE__);
    return FALSE;
  }
  fseek(f, 0L, SEEK_END);
  pol_id_buff_len = ftell(f);
  fseek(f, 0L, SEEK_SET);
  pol_id_buff = calloc(pol_id_buff_len * sizeof(char), 1);
  fread(pol_id_buff, pol_id_buff_len, 1, f);
  fclose(f);
  tok = strtok(pol_id_buff, "|");
  while (tok) {
    pap_policy_id_list_t* elem = malloc(sizeof(pap_policy_id_list_t));
    memset(elem, 0, sizeof(pap_policy_id_list_t));
    memset(pol_id_hex, 0, PAP_POL_ID_MAX_LEN);
    if (str_to_hex(tok, pol_id_hex, PAP_POL_ID_MAX_LEN * 2) != UTILS_STRING_SUCCESS) {
      log_error(plugin_logger_id, "[%s:%d] could not convert string to hex value.\n", __func__, __LINE__);
      return FALSE;
    }
    memcpy(elem->policy_id, pol_id_hex, PAP_POL_ID_MAX_LEN);
    if (*pol_list_head == NULL) {
      *pol_list_head = elem;
    } else {
      temp = *pol_list_head;
      while (temp->next != NULL) {
        temp = temp->next;
      }
      temp->next = elem;
    }
    tok = strtok(NULL, "|");
  }
  free(pol_id_buff);
  return TRUE;
}
static bool acquire_all_policies ( pap_policy_id_list_t * * pol_list_head ) { char pol_id_hex [ PAP_POL_ID_MAX_LEN ] = { 0 } ; char * pol_id_buff = NULL ; char * tok = NULL ; int pol_id_buff_len = 0 ; pap_policy_id_list_t * temp = NULL ; FILE * f ; f = fopen ( " " , " " ) ; if ( f == NULL ) { log_error ( plugin_logger_id , " \n " , __func__ , __LINE__ ) ; return FALSE ; } fseek ( f , 0L , SEEK_END ) ; pol_id_buff_len = ftell ( f ) ; fseek ( f , 0L , SEEK_SET ) ; pol_id_buff = calloc ( pol_id_buff_len * sizeof ( char ) , 1 ) ; fread ( pol_id_buff , pol_id_buff_len , 1 , f ) ; fclose ( f ) ; tok = strtok ( pol_id_buff , " " ) ; while ( tok ) { pap_policy_id_list_t * elem = malloc ( sizeof ( pap_policy_id_list_t ) ) ; memset ( elem , 0 , sizeof ( pap_policy_id_list_t ) ) ; memset ( pol_id_hex , 0 , PAP_POL_ID_MAX_LEN ) ; if ( str_to_hex ( tok , pol_id_hex , PAP_POL_ID_MAX_LEN * 2 ) != UTILS_STRING_SUCCESS ) { log_error ( plugin_logger_id , " \n " , __func__ , __LINE__ ) ; return FALSE ; } memcpy ( elem -> policy_id , pol_id_hex , PAP_POL_ID_MAX_LEN ) ; if ( * pol_list_head == NULL ) { * pol_list_head = elem ; } else { temp = * pol_list_head ; while ( temp -> next != NULL ) { temp = temp -> next ; } temp -> next = elem ; } tok = strtok ( NULL , " " ) ; } free ( pol_id_buff ) ; return TRUE ; }
List must be freed bu the user
List must be freed bu the user
// Call function for acquring all policies