qpol_internal.h

Go to the documentation of this file.
00001 /**
00002  *  @file
00003  *  Defines common debug symbols and the internal policy structure.
00004  *
00005  *  @author Jeremy A. Mowery jmowery@tresys.com
00006  *  @author Jason Tang jtang@tresys.com
00007  *
00008  *  Copyright (C) 2006-2007 Tresys Technology, LLC
00009  *
00010  *  This library is free software; you can redistribute it and/or
00011  *  modify it under the terms of the GNU Lesser General Public
00012  *  License as published by the Free Software Foundation; either
00013  *  version 2.1 of the License, or (at your option) any later version.
00014  *
00015  *  This library is distributed in the hope that it will be useful,
00016  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  *  Lesser General Public License for more details.
00019  *
00020  *  You should have received a copy of the GNU Lesser General Public
00021  *  License along with this library; if not, write to the Free Software
00022  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00023  */
00024 
00025 #ifndef QPOL_INTERNAL_H
00026 #define QPOL_INTERNAL_H
00027 
00028 #ifdef  __cplusplus
00029 extern "C"
00030 {
00031 #endif
00032 
00033 #include <sepol/handle.h>
00034 #include <qpol/policy.h>
00035 #include <stdio.h>
00036 
00037 #define STATUS_SUCCESS  0
00038 #define STATUS_ERR     -1
00039 #define STATUS_NODATA   1
00040 
00041 #define QPOL_MSG_ERR  1
00042 #define QPOL_MSG_WARN 2
00043 #define QPOL_MSG_INFO 3
00044 
00045         struct qpol_extended_image;
00046         struct qpol_policy;
00047 
00048         struct qpol_module
00049         {
00050                 char *name;
00051                 char *path;
00052                 char *version;
00053                 int type;
00054                 struct sepol_policydb *p;
00055                 int enabled;
00056                 struct qpol_policy *parent;
00057         };
00058 
00059         struct qpol_policy
00060         {
00061                 struct sepol_policydb *p;
00062                 struct sepol_handle *sh;
00063                 qpol_callback_fn_t fn;
00064                 void *varg;
00065                 int options;
00066                 int type;
00067                 int modified;
00068                 struct qpol_extended_image *ext;
00069                 struct qpol_module **modules;
00070                 size_t num_modules;
00071                 char *file_data;
00072                 size_t file_data_sz;
00073                 int file_data_type;
00074         };
00075 /* qpol_policy_t.file_data_type will be one of the following to denote
00076  * the proper method of destroying the data:
00077  * _BIN if policy is from a binary source (modular or kernel) destroy is a no-op
00078  * _MMAP if policy is from a file and destroy should call munmap
00079  * _MEM if policy is from open_from_memory and destroy should call free */
00080 #define QPOL_POLICY_FILE_DATA_TYPE_BIN  0
00081 #define QPOL_POLICY_FILE_DATA_TYPE_MMAP 1
00082 #define QPOL_POLICY_FILE_DATA_TYPE_MEM  2
00083 
00084 /**
00085  *  Create an extended image for a policy. This function modifies the policydb
00086  *  by adding additional records and information about attributes, initial sids
00087  *  and other components not normally written to a binary policy file. Subsequent
00088  *  calls to this function have no effect.
00089  *  @param policy The policy for which the extended image should be created.
00090  *  @return Returns 0 on success and < 0 on failure. If the call fails,
00091  *  errno will be set; the state of the policy is not guaranteed to be stable
00092  *  if this call fails.
00093  */
00094         int policy_extend(qpol_policy_t * policy);
00095 
00096         extern void qpol_handle_msg(const qpol_policy_t * policy, int level, const char *fmt, ...);
00097         int qpol_is_file_binpol(FILE * fp);
00098         int qpol_is_file_mod_pkg(FILE * fp);
00099 /**
00100  * Returns the version number of the binary policy.  Note that this
00101  * will rewind the file pointer.
00102  *
00103  * @return Non-negative policy version, or -1 general error for, -2
00104  * wrong magic number for file, or -3 problem reading file.
00105  */
00106         int qpol_binpol_version(FILE * fp);
00107 
00108 #define ERR(policy, format, ...) qpol_handle_msg(policy, QPOL_MSG_ERR, format, __VA_ARGS__)
00109 #define WARN(policy, format, ...) qpol_handle_msg(policy, QPOL_MSG_WARN, format, __VA_ARGS__)
00110 #define INFO(policy, format, ...) qpol_handle_msg(policy, QPOL_MSG_INFO, format, __VA_ARGS__)
00111 
00112 #ifdef  __cplusplus
00113 }
00114 #endif
00115 
00116 #endif                                 /* QPOL_INTERNAL_H */