113cd4c8960688af11ad23b4c946149015c80d54Joshua Brindle/*
213cd4c8960688af11ad23b4c946149015c80d54Joshua Brindle * Copyright (C) 2006 Tresys Technology, LLC
313cd4c8960688af11ad23b4c946149015c80d54Joshua Brindle *
413cd4c8960688af11ad23b4c946149015c80d54Joshua Brindle *  This library is free software; you can redistribute it and/or
513cd4c8960688af11ad23b4c946149015c80d54Joshua Brindle *  modify it under the terms of the GNU Lesser General Public
613cd4c8960688af11ad23b4c946149015c80d54Joshua Brindle *  License as published by the Free Software Foundation; either
713cd4c8960688af11ad23b4c946149015c80d54Joshua Brindle *  version 2.1 of the License, or (at your option) any later version.
813cd4c8960688af11ad23b4c946149015c80d54Joshua Brindle *
913cd4c8960688af11ad23b4c946149015c80d54Joshua Brindle *  This library is distributed in the hope that it will be useful,
1013cd4c8960688af11ad23b4c946149015c80d54Joshua Brindle *  but WITHOUT ANY WARRANTY; without even the implied warranty of
1113cd4c8960688af11ad23b4c946149015c80d54Joshua Brindle *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
1213cd4c8960688af11ad23b4c946149015c80d54Joshua Brindle *  Lesser General Public License for more details.
1313cd4c8960688af11ad23b4c946149015c80d54Joshua Brindle *
1413cd4c8960688af11ad23b4c946149015c80d54Joshua Brindle *  You should have received a copy of the GNU Lesser General Public
1513cd4c8960688af11ad23b4c946149015c80d54Joshua Brindle *  License along with this library; if not, write to the Free Software
1613cd4c8960688af11ad23b4c946149015c80d54Joshua Brindle *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
1713cd4c8960688af11ad23b4c946149015c80d54Joshua Brindle */
1813cd4c8960688af11ad23b4c946149015c80d54Joshua Brindle
1913cd4c8960688af11ad23b4c946149015c80d54Joshua Brindle/* Copyright (C) 2005 Red Hat, Inc. */
2013cd4c8960688af11ad23b4c946149015c80d54Joshua Brindle
2113cd4c8960688af11ad23b4c946149015c80d54Joshua Brindle#ifndef _SEMANAGE_DATABASE_POLICYDB_INTERNAL_H_
2213cd4c8960688af11ad23b4c946149015c80d54Joshua Brindle#define _SEMANAGE_DATABASE_POLICYDB_INTERNAL_H_
2313cd4c8960688af11ad23b4c946149015c80d54Joshua Brindle
2413cd4c8960688af11ad23b4c946149015c80d54Joshua Brindle#include <sepol/handle.h>
2513cd4c8960688af11ad23b4c946149015c80d54Joshua Brindle#include <sepol/policydb.h>
2613cd4c8960688af11ad23b4c946149015c80d54Joshua Brindle#include "database.h"
2713cd4c8960688af11ad23b4c946149015c80d54Joshua Brindle#include "handle.h"
2813cd4c8960688af11ad23b4c946149015c80d54Joshua Brindle
2913cd4c8960688af11ad23b4c946149015c80d54Joshua Brindlestruct dbase_policydb;
3013cd4c8960688af11ad23b4c946149015c80d54Joshua Brindletypedef struct dbase_policydb dbase_policydb_t;
3113cd4c8960688af11ad23b4c946149015c80d54Joshua Brindle
3213cd4c8960688af11ad23b4c946149015c80d54Joshua Brindletypedef int (*record_policydb_table_add_t) (sepol_handle_t * h,
3313cd4c8960688af11ad23b4c946149015c80d54Joshua Brindle					    sepol_policydb_t * p,
3413cd4c8960688af11ad23b4c946149015c80d54Joshua Brindle					    const record_key_t * rkey,
3513cd4c8960688af11ad23b4c946149015c80d54Joshua Brindle					    const record_t * record);
3613cd4c8960688af11ad23b4c946149015c80d54Joshua Brindle
3713cd4c8960688af11ad23b4c946149015c80d54Joshua Brindletypedef int (*record_policydb_table_modify_t) (sepol_handle_t * h,
3813cd4c8960688af11ad23b4c946149015c80d54Joshua Brindle					       sepol_policydb_t * p,
3913cd4c8960688af11ad23b4c946149015c80d54Joshua Brindle					       const record_key_t * rkey,
4013cd4c8960688af11ad23b4c946149015c80d54Joshua Brindle					       const record_t * record);
4113cd4c8960688af11ad23b4c946149015c80d54Joshua Brindle
4213cd4c8960688af11ad23b4c946149015c80d54Joshua Brindletypedef int (*record_policydb_table_set_t) (sepol_handle_t * h,
4313cd4c8960688af11ad23b4c946149015c80d54Joshua Brindle					    sepol_policydb_t * p,
4413cd4c8960688af11ad23b4c946149015c80d54Joshua Brindle					    const record_key_t * rkey,
4513cd4c8960688af11ad23b4c946149015c80d54Joshua Brindle					    const record_t * record);
4613cd4c8960688af11ad23b4c946149015c80d54Joshua Brindle
4713cd4c8960688af11ad23b4c946149015c80d54Joshua Brindletypedef int (*record_policydb_table_query_t) (sepol_handle_t * h,
4813cd4c8960688af11ad23b4c946149015c80d54Joshua Brindle					      const sepol_policydb_t * p,
4913cd4c8960688af11ad23b4c946149015c80d54Joshua Brindle					      const record_key_t * rkey,
5013cd4c8960688af11ad23b4c946149015c80d54Joshua Brindle					      record_t ** response);
5113cd4c8960688af11ad23b4c946149015c80d54Joshua Brindle
5213cd4c8960688af11ad23b4c946149015c80d54Joshua Brindletypedef int (*record_policydb_table_count_t) (sepol_handle_t * h,
5313cd4c8960688af11ad23b4c946149015c80d54Joshua Brindle					      const sepol_policydb_t * p,
5413cd4c8960688af11ad23b4c946149015c80d54Joshua Brindle					      unsigned int *response);
5513cd4c8960688af11ad23b4c946149015c80d54Joshua Brindle
5613cd4c8960688af11ad23b4c946149015c80d54Joshua Brindletypedef int (*record_policydb_table_exists_t) (sepol_handle_t * h,
5713cd4c8960688af11ad23b4c946149015c80d54Joshua Brindle					       const sepol_policydb_t * p,
5813cd4c8960688af11ad23b4c946149015c80d54Joshua Brindle					       const record_key_t * rkey,
5913cd4c8960688af11ad23b4c946149015c80d54Joshua Brindle					       int *response);
6013cd4c8960688af11ad23b4c946149015c80d54Joshua Brindle
6113cd4c8960688af11ad23b4c946149015c80d54Joshua Brindletypedef int (*record_policydb_table_iterate_t) (sepol_handle_t * h,
6213cd4c8960688af11ad23b4c946149015c80d54Joshua Brindle						const sepol_policydb_t * p,
6313cd4c8960688af11ad23b4c946149015c80d54Joshua Brindle						int (*fn) (const record_t * r,
6413cd4c8960688af11ad23b4c946149015c80d54Joshua Brindle							   void *fn_arg),
6513cd4c8960688af11ad23b4c946149015c80d54Joshua Brindle						void *arg);
6613cd4c8960688af11ad23b4c946149015c80d54Joshua Brindle
6713cd4c8960688af11ad23b4c946149015c80d54Joshua Brindle/* POLICYDB extension to RECORD interface - method table */
6813cd4c8960688af11ad23b4c946149015c80d54Joshua Brindletypedef struct record_policydb_table {
6913cd4c8960688af11ad23b4c946149015c80d54Joshua Brindle	/* Add policy record */
7013cd4c8960688af11ad23b4c946149015c80d54Joshua Brindle	record_policydb_table_add_t add;
7113cd4c8960688af11ad23b4c946149015c80d54Joshua Brindle	/* Modify policy record, or add if
7213cd4c8960688af11ad23b4c946149015c80d54Joshua Brindle	 * the key isn't found */
7313cd4c8960688af11ad23b4c946149015c80d54Joshua Brindle	record_policydb_table_modify_t modify;
7413cd4c8960688af11ad23b4c946149015c80d54Joshua Brindle	/* Set policy record */
7513cd4c8960688af11ad23b4c946149015c80d54Joshua Brindle	record_policydb_table_set_t set;
7613cd4c8960688af11ad23b4c946149015c80d54Joshua Brindle	/* Query policy record  - return the record
7713cd4c8960688af11ad23b4c946149015c80d54Joshua Brindle	 * or NULL if it isn't found */
7813cd4c8960688af11ad23b4c946149015c80d54Joshua Brindle	record_policydb_table_query_t query;
7913cd4c8960688af11ad23b4c946149015c80d54Joshua Brindle	/* Count records */
8013cd4c8960688af11ad23b4c946149015c80d54Joshua Brindle	record_policydb_table_count_t count;
8113cd4c8960688af11ad23b4c946149015c80d54Joshua Brindle	/* Check if a record exists */
8213cd4c8960688af11ad23b4c946149015c80d54Joshua Brindle	record_policydb_table_exists_t exists;
8313cd4c8960688af11ad23b4c946149015c80d54Joshua Brindle	/* Iterate over records */
8413cd4c8960688af11ad23b4c946149015c80d54Joshua Brindle	record_policydb_table_iterate_t iterate;
8513cd4c8960688af11ad23b4c946149015c80d54Joshua Brindle} record_policydb_table_t;
8613cd4c8960688af11ad23b4c946149015c80d54Joshua Brindle
8713cd4c8960688af11ad23b4c946149015c80d54Joshua Brindle/* Initialize database */
8813cd4c8960688af11ad23b4c946149015c80d54Joshua Brindleextern int dbase_policydb_init(semanage_handle_t * handle,
89e37fa2f63be89afab9b5f5ddfedbd589d0676c4eCaleb Case			       const char *path_ro,
90e37fa2f63be89afab9b5f5ddfedbd589d0676c4eCaleb Case			       const char *path_rw,
9113cd4c8960688af11ad23b4c946149015c80d54Joshua Brindle			       record_table_t * rtable,
9213cd4c8960688af11ad23b4c946149015c80d54Joshua Brindle			       record_policydb_table_t * rptable,
9313cd4c8960688af11ad23b4c946149015c80d54Joshua Brindle			       dbase_policydb_t ** dbase);
9413cd4c8960688af11ad23b4c946149015c80d54Joshua Brindle
9513cd4c8960688af11ad23b4c946149015c80d54Joshua Brindle/* Attach to a shared policydb.
9613cd4c8960688af11ad23b4c946149015c80d54Joshua Brindle * This implies drop_cache().
9713cd4c8960688af11ad23b4c946149015c80d54Joshua Brindle * and prevents flush() and drop_cache()
9813cd4c8960688af11ad23b4c946149015c80d54Joshua Brindle * until detached. */
9913cd4c8960688af11ad23b4c946149015c80d54Joshua Brindleextern void dbase_policydb_attach(dbase_policydb_t * dbase,
10013cd4c8960688af11ad23b4c946149015c80d54Joshua Brindle				  sepol_policydb_t * policydb);
10113cd4c8960688af11ad23b4c946149015c80d54Joshua Brindle
10213cd4c8960688af11ad23b4c946149015c80d54Joshua Brindle/* Detach from a shared policdb.
10313cd4c8960688af11ad23b4c946149015c80d54Joshua Brindle * This implies drop_cache. */
10413cd4c8960688af11ad23b4c946149015c80d54Joshua Brindleextern void dbase_policydb_detach(dbase_policydb_t * dbase);
10513cd4c8960688af11ad23b4c946149015c80d54Joshua Brindle
10613cd4c8960688af11ad23b4c946149015c80d54Joshua Brindle/* Release allocated resources */
10713cd4c8960688af11ad23b4c946149015c80d54Joshua Brindleextern void dbase_policydb_release(dbase_policydb_t * dbase);
10813cd4c8960688af11ad23b4c946149015c80d54Joshua Brindle
10913cd4c8960688af11ad23b4c946149015c80d54Joshua Brindle/* POLICYDB database - method table implementation */
11013cd4c8960688af11ad23b4c946149015c80d54Joshua Brindleextern dbase_table_t SEMANAGE_POLICYDB_DTABLE;
11113cd4c8960688af11ad23b4c946149015c80d54Joshua Brindle
11213cd4c8960688af11ad23b4c946149015c80d54Joshua Brindle#endif
113