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