1 /* 2 * Copyright (C) 2006 Tresys Technology, LLC 3 * 4 * This library is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU Lesser General Public 6 * License as published by the Free Software Foundation; either 7 * version 2.1 of the License, or (at your option) any later version. 8 * 9 * This library is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 * Lesser General Public License for more details. 13 * 14 * You should have received a copy of the GNU Lesser General Public 15 * License along with this library; if not, write to the Free Software 16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 */ 18 19 /* Copyright (C) 2005 Red Hat, Inc. */ 20 21 #ifndef _SEMANAGE_DATABASE_POLICYDB_INTERNAL_H_ 22 #define _SEMANAGE_DATABASE_POLICYDB_INTERNAL_H_ 23 24 #include <sepol/handle.h> 25 #include <sepol/policydb.h> 26 #include "database.h" 27 #include "handle.h" 28 29 struct dbase_policydb; 30 typedef struct dbase_policydb dbase_policydb_t; 31 32 typedef int (*record_policydb_table_add_t) (sepol_handle_t * h, 33 sepol_policydb_t * p, 34 const record_key_t * rkey, 35 const record_t * record); 36 37 typedef int (*record_policydb_table_modify_t) (sepol_handle_t * h, 38 sepol_policydb_t * p, 39 const record_key_t * rkey, 40 const record_t * record); 41 42 typedef int (*record_policydb_table_set_t) (sepol_handle_t * h, 43 sepol_policydb_t * p, 44 const record_key_t * rkey, 45 const record_t * record); 46 47 typedef int (*record_policydb_table_query_t) (sepol_handle_t * h, 48 const sepol_policydb_t * p, 49 const record_key_t * rkey, 50 record_t ** response); 51 52 typedef int (*record_policydb_table_count_t) (sepol_handle_t * h, 53 const sepol_policydb_t * p, 54 unsigned int *response); 55 56 typedef int (*record_policydb_table_exists_t) (sepol_handle_t * h, 57 const sepol_policydb_t * p, 58 const record_key_t * rkey, 59 int *response); 60 61 typedef int (*record_policydb_table_iterate_t) (sepol_handle_t * h, 62 const sepol_policydb_t * p, 63 int (*fn) (const record_t * r, 64 void *fn_arg), 65 void *arg); 66 67 /* POLICYDB extension to RECORD interface - method table */ 68 typedef struct record_policydb_table { 69 /* Add policy record */ 70 record_policydb_table_add_t add; 71 /* Modify policy record, or add if 72 * the key isn't found */ 73 record_policydb_table_modify_t modify; 74 /* Set policy record */ 75 record_policydb_table_set_t set; 76 /* Query policy record - return the record 77 * or NULL if it isn't found */ 78 record_policydb_table_query_t query; 79 /* Count records */ 80 record_policydb_table_count_t count; 81 /* Check if a record exists */ 82 record_policydb_table_exists_t exists; 83 /* Iterate over records */ 84 record_policydb_table_iterate_t iterate; 85 } record_policydb_table_t; 86 87 /* Initialize database */ 88 extern int dbase_policydb_init(semanage_handle_t * handle, 89 const char *path_ro, 90 const char *path_rw, 91 record_table_t * rtable, 92 record_policydb_table_t * rptable, 93 dbase_policydb_t ** dbase); 94 95 /* Attach to a shared policydb. 96 * This implies drop_cache(). 97 * and prevents flush() and drop_cache() 98 * until detached. */ 99 extern void dbase_policydb_attach(dbase_policydb_t * dbase, 100 sepol_policydb_t * policydb); 101 102 /* Detach from a shared policdb. 103 * This implies drop_cache. */ 104 extern void dbase_policydb_detach(dbase_policydb_t * dbase); 105 106 /* Release allocated resources */ 107 extern void dbase_policydb_release(dbase_policydb_t * dbase); 108 109 /* POLICYDB database - method table implementation */ 110 extern dbase_table_t SEMANAGE_POLICYDB_DTABLE; 111 112 #endif 113