• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright (C) 2005 Red Hat, Inc. */
2 
3 /* Object: semanage_user_base_t (SELinux User/Class Policy Object)
4  * Object: semanage_user_key_t (SELinux User/Class Key)
5  * Implements: record_t (Database Record)
6  * Implements: record_key_t (Database Record Key)
7  */
8 
9 #include <sepol/user_record.h>
10 
11 typedef sepol_user_key_t semanage_user_key_t;
12 #define _SEMANAGE_USER_KEY_DEFINED_
13 
14 typedef sepol_user_t semanage_user_base_t;
15 #define _SEMANAGE_USER_BASE_DEFINED_
16 
17 typedef semanage_user_base_t record_t;
18 typedef semanage_user_key_t record_key_t;
19 #define DBASE_RECORD_DEFINED
20 
21 #include <stdlib.h>
22 #include "user_internal.h"
23 #include "handle.h"
24 #include "database.h"
25 #include "debug.h"
26 
27 /* Key */
semanage_user_base_key_extract(semanage_handle_t * handle,const semanage_user_base_t * user,semanage_user_key_t ** key)28 hidden int semanage_user_base_key_extract(semanage_handle_t * handle,
29 					  const semanage_user_base_t * user,
30 					  semanage_user_key_t ** key)
31 {
32 
33 	return sepol_user_key_extract(handle->sepolh, user, key);
34 }
35 
semanage_user_base_compare(const semanage_user_base_t * user,const semanage_user_key_t * key)36 static int semanage_user_base_compare(const semanage_user_base_t * user,
37 				      const semanage_user_key_t * key)
38 {
39 
40 	return sepol_user_compare(user, key);
41 }
42 
semanage_user_base_compare2(const semanage_user_base_t * user,const semanage_user_base_t * user2)43 static int semanage_user_base_compare2(const semanage_user_base_t * user,
44 				       const semanage_user_base_t * user2)
45 {
46 
47 	return sepol_user_compare2(user, user2);
48 }
49 
semanage_user_base_compare2_qsort(const semanage_user_base_t ** user,const semanage_user_base_t ** user2)50 static int semanage_user_base_compare2_qsort(const semanage_user_base_t ** user,
51 					     const semanage_user_base_t **
52 					     user2)
53 {
54 
55 	return sepol_user_compare2(*user, *user2);
56 }
57 
58 /* Name */
semanage_user_base_get_name(const semanage_user_base_t * user)59 hidden const char *semanage_user_base_get_name(const semanage_user_base_t *
60 					       user)
61 {
62 
63 	return sepol_user_get_name(user);
64 }
65 
semanage_user_base_set_name(semanage_handle_t * handle,semanage_user_base_t * user,const char * name)66 hidden int semanage_user_base_set_name(semanage_handle_t * handle,
67 				       semanage_user_base_t * user,
68 				       const char *name)
69 {
70 
71 	return sepol_user_set_name(handle->sepolh, user, name);
72 }
73 
74 /* MLS */
semanage_user_base_get_mlslevel(const semanage_user_base_t * user)75 hidden const char *semanage_user_base_get_mlslevel(const semanage_user_base_t *
76 						   user)
77 {
78 
79 	return sepol_user_get_mlslevel(user);
80 }
81 
semanage_user_base_set_mlslevel(semanage_handle_t * handle,semanage_user_base_t * user,const char * mls_level)82 hidden int semanage_user_base_set_mlslevel(semanage_handle_t * handle,
83 					   semanage_user_base_t * user,
84 					   const char *mls_level)
85 {
86 
87 	return sepol_user_set_mlslevel(handle->sepolh, user, mls_level);
88 }
89 
semanage_user_base_get_mlsrange(const semanage_user_base_t * user)90 hidden const char *semanage_user_base_get_mlsrange(const semanage_user_base_t *
91 						   user)
92 {
93 
94 	return sepol_user_get_mlsrange(user);
95 }
96 
semanage_user_base_set_mlsrange(semanage_handle_t * handle,semanage_user_base_t * user,const char * mls_range)97 hidden int semanage_user_base_set_mlsrange(semanage_handle_t * handle,
98 					   semanage_user_base_t * user,
99 					   const char *mls_range)
100 {
101 
102 	return sepol_user_set_mlsrange(handle->sepolh, user, mls_range);
103 }
104 
105 /* Role management */
semanage_user_base_get_num_roles(const semanage_user_base_t * user)106 hidden int semanage_user_base_get_num_roles(const semanage_user_base_t * user)
107 {
108 
109 	return sepol_user_get_num_roles(user);
110 }
111 
semanage_user_base_add_role(semanage_handle_t * handle,semanage_user_base_t * user,const char * role)112 hidden int semanage_user_base_add_role(semanage_handle_t * handle,
113 				       semanage_user_base_t * user,
114 				       const char *role)
115 {
116 
117 	return sepol_user_add_role(handle->sepolh, user, role);
118 }
119 
semanage_user_base_del_role(semanage_user_base_t * user,const char * role)120 hidden void semanage_user_base_del_role(semanage_user_base_t * user,
121 					const char *role)
122 {
123 
124 	sepol_user_del_role(user, role);
125 }
126 
semanage_user_base_has_role(const semanage_user_base_t * user,const char * role)127 hidden int semanage_user_base_has_role(const semanage_user_base_t * user,
128 				       const char *role)
129 {
130 
131 	return sepol_user_has_role(user, role);
132 }
133 
semanage_user_base_get_roles(semanage_handle_t * handle,const semanage_user_base_t * user,const char *** roles_arr,unsigned int * num_roles)134 hidden int semanage_user_base_get_roles(semanage_handle_t * handle,
135 					const semanage_user_base_t * user,
136 					const char ***roles_arr,
137 					unsigned int *num_roles)
138 {
139 
140 	return sepol_user_get_roles(handle->sepolh, user, roles_arr, num_roles);
141 }
142 
semanage_user_base_set_roles(semanage_handle_t * handle,semanage_user_base_t * user,const char ** roles_arr,unsigned int num_roles)143 hidden int semanage_user_base_set_roles(semanage_handle_t * handle,
144 					semanage_user_base_t * user,
145 					const char **roles_arr,
146 					unsigned int num_roles)
147 {
148 
149 	return sepol_user_set_roles(handle->sepolh, user, roles_arr, num_roles);
150 }
151 
152 /* Create/Clone/Destroy */
semanage_user_base_create(semanage_handle_t * handle,semanage_user_base_t ** user_ptr)153 hidden int semanage_user_base_create(semanage_handle_t * handle,
154 				     semanage_user_base_t ** user_ptr)
155 {
156 
157 	return sepol_user_create(handle->sepolh, user_ptr);
158 }
159 
semanage_user_base_clone(semanage_handle_t * handle,const semanage_user_base_t * user,semanage_user_base_t ** user_ptr)160 hidden int semanage_user_base_clone(semanage_handle_t * handle,
161 				    const semanage_user_base_t * user,
162 				    semanage_user_base_t ** user_ptr)
163 {
164 
165 	return sepol_user_clone(handle->sepolh, user, user_ptr);
166 }
167 
semanage_user_base_free(semanage_user_base_t * user)168 hidden void semanage_user_base_free(semanage_user_base_t * user)
169 {
170 
171 	sepol_user_free(user);
172 }
173 
174 /* Record base functions */
175 record_table_t SEMANAGE_USER_BASE_RTABLE = {
176 	.create = semanage_user_base_create,
177 	.key_extract = semanage_user_base_key_extract,
178 	.key_free = semanage_user_key_free,
179 	.clone = semanage_user_base_clone,
180 	.compare = semanage_user_base_compare,
181 	.compare2 = semanage_user_base_compare2,
182 	.compare2_qsort = semanage_user_base_compare2_qsort,
183 	.free = semanage_user_base_free,
184 };
185