1 /* Authors: Joshua Brindle  <jbrindle@tresys.com>
2  *	    Jason Tang	    <jtang@tresys.com>
3  *
4  * Copyright (C) 2005 Tresys Technology, LLC
5  *
6  *  This library is free software; you can redistribute it and/or
7  *  modify it under the terms of the GNU Lesser General Public
8  *  License as published by the Free Software Foundation; either
9  *  version 2.1 of the License, or (at your option) any later version.
10  *
11  *  This library is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  *  Lesser General Public License for more details.
15  *
16  *  You should have received a copy of the GNU Lesser General Public
17  *  License along with this library; if not, write to the Free Software
18  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19  */
20 
21 #ifndef _SEMANAGE_MODULES_H_
22 #define _SEMANAGE_MODULES_H_
23 
24 #include <stddef.h>
25 #include <stdint.h>
26 #include <semanage/handle.h>
27 
28 typedef struct semanage_module_key semanage_module_key_t;
29 
30 /* High level module management functions. These are all part of
31  * a transaction
32  */
33 
34 int semanage_module_install(semanage_handle_t *,
35 			    char *module_data, size_t data_len, char *name, char *ext_lang);
36 int semanage_module_install_file(semanage_handle_t *,
37 				 const char *module_name);
38 int semanage_module_remove(semanage_handle_t *, char *module_name);
39 
40 /* semanage_module_info is for getting information on installed
41    modules, only name at this time */
42 typedef struct semanage_module_info semanage_module_info_t;
43 
44 int semanage_module_list(semanage_handle_t *,
45 			 semanage_module_info_t **, int *num_modules);
46 void semanage_module_info_datum_destroy(semanage_module_info_t *);
47 semanage_module_info_t *semanage_module_list_nth(semanage_module_info_t * list,
48 						 int n);
49 const char *semanage_module_get_name(semanage_module_info_t *);
50 
51 /* Module Info */
52 
53 /* Creates a module info struct.
54  *
55  * Returns 0 on success and -1 on failure.
56  *
57  * The @modinfo should be destroyed with semanage_module_info_destroy.
58  * The caller should call free() on the struct.
59  */
60 int semanage_module_info_create(semanage_handle_t *sh,
61 				semanage_module_info_t **modinfo);
62 
63 /* Frees the members of the module info struct.
64  *
65  * Returns 0 on success and -1 on failure.
66  *
67  * The caller should call free() on the struct.
68  */
69 int semanage_module_info_destroy(semanage_handle_t *handle,
70 				 semanage_module_info_t *modinfo);
71 
72 /* Module Info Getters */
73 
74 /* Get @priority from @modinfo.
75  *
76  * Returns 0 on success and -1 on error.
77  */
78 int semanage_module_info_get_priority(semanage_handle_t *sh,
79 				      semanage_module_info_t *modinfo,
80 				      uint16_t *priority);
81 
82 /* Get @name from @modinfo. Caller should not free @name.
83  *
84  * Returns 0 on success and -1 on error.
85  */
86 int semanage_module_info_get_name(semanage_handle_t *sh,
87 				  semanage_module_info_t *modinfo,
88 				  const char **name);
89 
90 /* Get @lang_ext from @modinfo. Caller should not free @lang_ext.
91  *
92  * Returns 0 on success and -1 on error.
93  */
94 int semanage_module_info_get_lang_ext(semanage_handle_t *sh,
95 				      semanage_module_info_t *modinfo,
96 				      const char **lang_ext);
97 
98 /* Get @enabled from @modinfo.
99  *
100  * Returns 0 on success and -1 on error.
101  */
102 int semanage_module_info_get_enabled(semanage_handle_t *sh,
103 				     semanage_module_info_t *modinfo,
104 				     int *enabled);
105 
106 /* Module Info Setters */
107 
108 /* Set @priority in @modinfo.
109  *
110  * Returns 0 on success and -1 on error.
111  */
112 int semanage_module_info_set_priority(semanage_handle_t *sh,
113 				      semanage_module_info_t *modinfo,
114 				      uint16_t priority);
115 
116 /* Set @name in @modinfo.
117  *
118  * Returns 0 on success and -1 on error.
119  */
120 int semanage_module_info_set_name(semanage_handle_t *sh,
121 				  semanage_module_info_t *modinfo,
122 				  const char *name);
123 
124 /* Set @lang_ext in @modinfo.
125  *
126  * Returns 0 on success and -1 on error.
127  */
128 int semanage_module_info_set_lang_ext(semanage_handle_t *sh,
129 				      semanage_module_info_t *modinfo,
130 				      const char *lang_ext);
131 
132 /* Set @enabled in @modinfo.
133  *
134  * Returns 0 on success and -1 on error.
135  */
136 int semanage_module_info_set_enabled(semanage_handle_t *sh,
137 				     semanage_module_info_t *modinfo,
138 				     int enabled);
139 
140 /* Module Key */
141 
142 /* Creates a module key struct.
143  *
144  * Return 0 on success, and -1 on error.
145  *
146  * The @modkey should be destroyed with semanage_module_key_destroy.
147  * The caller should call free() on the struct.
148  */
149 int semanage_module_key_create(semanage_handle_t *sh,
150 			       semanage_module_key_t **modkey);
151 
152 /* Frees members of the @modkey, but not the struct. The caller should
153  * call free() on struct.
154  *
155  * Returns 0 on success, and -1 on error.
156  */
157 int semanage_module_key_destroy(semanage_handle_t *sh,
158 				semanage_module_key_t *modkey);
159 
160 /* Module Key Getters */
161 
162 /* Get @name from @modkey. Caller should not free @name.
163  *
164  * Returns 0 on success and -1 on error.
165  */
166 int semanage_module_key_get_name(semanage_handle_t *sh,
167 				 semanage_module_key_t *modkey,
168 				 const char **name);
169 
170 /* Get @name from @modkey.
171  *
172  * Returns 0 on success and -1 on error.
173  */
174 int semanage_module_key_get_priority(semanage_handle_t *sh,
175 				     semanage_module_key_t *modkey,
176 				     uint16_t *priority);
177 
178 /* Module Key Setters */
179 
180 /* Set @name in @modkey.
181  *
182  * Returns 0 on success and -1 on error.
183  */
184 int semanage_module_key_set_name(semanage_handle_t *sh,
185 				 semanage_module_key_t *modkey,
186 				 const char *name);
187 
188 /* Set @priority in @modkey.
189  *
190  * Returns 0 on success and -1 on error.
191  */
192 int semanage_module_key_set_priority(semanage_handle_t *sh,
193 				     semanage_module_key_t *modkey,
194 				     uint16_t priority);
195 
196 /* Set module @enabled status from @modkey. Modules are enabled on a per
197  * module name basis (across all priorities). @modkey only needs to have
198  * name set (priority is ignored).
199  *
200  * Returns 0 on success and -1 on error.
201  */
202 int semanage_module_set_enabled(semanage_handle_t *sh,
203 				const semanage_module_key_t *modkey,
204 				int enabled);
205 
206 /* Lookup @modinfo by @modkey. Caller should use
207  * semanage_module_info_destroy and free on @modinfo.
208  *
209  * Returns 0 on success and -1 on error.
210  */
211 int semanage_module_get_module_info(semanage_handle_t *sh,
212 				    const semanage_module_key_t *modkey,
213 				    semanage_module_info_t **modinfo);
214 
215 /* Create a list of all modules in @modinfos of length @modinfos_len.
216  * The list will be sorted from high priority to low and alphabetically
217  * by module name within a priority.
218  *
219  * Caller should use semanage_module_info_destroy on each modinfo in
220  * @modinfos and free on @modinfos.
221  *
222  * Returns 0 on success and -1 on error.
223  */
224 int semanage_module_list_all(semanage_handle_t *sh,
225 			     semanage_module_info_t **modinfos,
226 			     int *modinfos_len);
227 
228 /* Install the module indicated by @modinfo with input data from
229  * @module_data with length @data_len.
230  *
231  * @modinfo must have all values filled in.
232  * @module_data may be bzip compressed.
233  *
234  * Returns:
235  *	 0	success
236  *	-1	failure, out of memory
237  *	-2	failure, invalid @modinfo
238  *	-3	failure, error writing file
239  */
240 int semanage_module_install_info(semanage_handle_t *sh,
241 				 const semanage_module_info_t *modinfo,
242 				 char *data,
243 				 size_t data_len);
244 
245 /* Remove the module indicated by @modkey.
246  * @modkey must have key values filled in.
247  *
248  * Returns:
249  * 	 0	success
250  *	-1	failure, out of memeory
251  *	-2	failure, @module not found or couldn't be removed
252  */
253 int semanage_module_remove_key(semanage_handle_t *sh,
254 			       const semanage_module_key_t *modkey);
255 
256 /* Module Enabled */
257 
258 /* Get module @enabled status from @modkey. Modules are enabled on a per
259  * module name basis (across all priorities). @modkey only needs to have
260  * name set (priority is ignored).
261  *
262  * Returns 0 on success and -1 on error.
263  */
264 int semanage_module_get_enabled(semanage_handle_t *sh,
265 				const semanage_module_key_t *modkey,
266 				int *enabled);
267 
268 #endif
269