1 /* Copyright (C) 2005 Red Hat, Inc. */
2
3 /* Object: semanage_node_t (Network Port)
4 * Object: semanage_node_key_t (Network Port Key)
5 * Implements: record_t (Database Record)
6 * Implements: record_key_t (Database Record Key)
7 */
8
9 #include <sepol/context_record.h>
10 #include <sepol/node_record.h>
11 #include <stddef.h>
12
13 typedef sepol_context_t semanage_context_t;
14 typedef sepol_node_t semanage_node_t;
15 typedef sepol_node_key_t semanage_node_key_t;
16 #define _SEMANAGE_NODE_DEFINED_
17 #define _SEMANAGE_CONTEXT_DEFINED_
18
19 typedef semanage_node_t record_t;
20 typedef semanage_node_key_t record_key_t;
21 #define DBASE_RECORD_DEFINED
22
23 #include "node_internal.h"
24 #include "handle.h"
25 #include "database.h"
26
27 /* Key */
semanage_node_compare(const semanage_node_t * node,const semanage_node_key_t * key)28 int semanage_node_compare(const semanage_node_t * node,
29 const semanage_node_key_t * key)
30 {
31
32 return sepol_node_compare(node, key);
33 }
34
hidden_def(semanage_node_compare)35 hidden_def(semanage_node_compare)
36
37 int semanage_node_compare2(const semanage_node_t * node,
38 const semanage_node_t * node2)
39 {
40
41 return sepol_node_compare2(node, node2);
42 }
43
hidden_def(semanage_node_compare2)44 hidden_def(semanage_node_compare2)
45
46 hidden int semanage_node_compare2_qsort(const semanage_node_t ** node,
47 const semanage_node_t ** node2)
48 {
49
50 return sepol_node_compare2(*node, *node2);
51 }
52
semanage_node_key_create(semanage_handle_t * handle,const char * addr,const char * mask,int proto,semanage_node_key_t ** key_ptr)53 int semanage_node_key_create(semanage_handle_t * handle,
54 const char *addr,
55 const char *mask,
56 int proto, semanage_node_key_t ** key_ptr)
57 {
58
59 return sepol_node_key_create(handle->sepolh, addr, mask, proto,
60 key_ptr);
61 }
62
semanage_node_key_extract(semanage_handle_t * handle,const semanage_node_t * node,semanage_node_key_t ** key_ptr)63 int semanage_node_key_extract(semanage_handle_t * handle,
64 const semanage_node_t * node,
65 semanage_node_key_t ** key_ptr)
66 {
67
68 return sepol_node_key_extract(handle->sepolh, node, key_ptr);
69 }
70
hidden_def(semanage_node_key_extract)71 hidden_def(semanage_node_key_extract)
72
73 void semanage_node_key_free(semanage_node_key_t * key)
74 {
75
76 sepol_node_key_free(key);
77 }
78
hidden_def(semanage_node_key_free)79 hidden_def(semanage_node_key_free)
80
81 /* Address */
82 int semanage_node_get_addr(semanage_handle_t * handle,
83 const semanage_node_t * node, char **addr_ptr)
84 {
85
86 return sepol_node_get_addr(handle->sepolh, node, addr_ptr);
87 }
88
hidden_def(semanage_node_get_addr)89 hidden_def(semanage_node_get_addr)
90
91 int semanage_node_get_addr_bytes(semanage_handle_t * handle,
92 const semanage_node_t * node,
93 char **addr, size_t * addr_sz)
94 {
95
96 return sepol_node_get_addr_bytes(handle->sepolh, node, addr, addr_sz);
97 }
98
hidden_def(semanage_node_get_addr_bytes)99 hidden_def(semanage_node_get_addr_bytes)
100
101 int semanage_node_set_addr(semanage_handle_t * handle,
102 semanage_node_t * node, int proto, const char *addr)
103 {
104
105 return sepol_node_set_addr(handle->sepolh, node, proto, addr);
106 }
107
hidden_def(semanage_node_set_addr)108 hidden_def(semanage_node_set_addr)
109
110 int semanage_node_set_addr_bytes(semanage_handle_t * handle,
111 semanage_node_t * node,
112 const char *addr, size_t addr_sz)
113 {
114
115 return sepol_node_set_addr_bytes(handle->sepolh, node, addr, addr_sz);
116 }
117
hidden_def(semanage_node_set_addr_bytes)118 hidden_def(semanage_node_set_addr_bytes)
119
120 /* Netmask */
121 int semanage_node_get_mask(semanage_handle_t * handle,
122 const semanage_node_t * node, char **mask_ptr)
123 {
124
125 return sepol_node_get_mask(handle->sepolh, node, mask_ptr);
126 }
127
hidden_def(semanage_node_get_mask)128 hidden_def(semanage_node_get_mask)
129
130 int semanage_node_get_mask_bytes(semanage_handle_t * handle,
131 const semanage_node_t * node,
132 char **mask, size_t * mask_sz)
133 {
134
135 return sepol_node_get_mask_bytes(handle->sepolh, node, mask, mask_sz);
136 }
137
hidden_def(semanage_node_get_mask_bytes)138 hidden_def(semanage_node_get_mask_bytes)
139
140 int semanage_node_set_mask(semanage_handle_t * handle,
141 semanage_node_t * node, int proto, const char *mask)
142 {
143
144 return sepol_node_set_mask(handle->sepolh, node, proto, mask);
145 }
146
hidden_def(semanage_node_set_mask)147 hidden_def(semanage_node_set_mask)
148
149 int semanage_node_set_mask_bytes(semanage_handle_t * handle,
150 semanage_node_t * node,
151 const char *mask, size_t mask_sz)
152 {
153
154 return sepol_node_set_mask_bytes(handle->sepolh, node, mask, mask_sz);
155 }
156
hidden_def(semanage_node_set_mask_bytes)157 hidden_def(semanage_node_set_mask_bytes)
158
159 /* Protocol */
160 int semanage_node_get_proto(const semanage_node_t * node)
161 {
162
163 return sepol_node_get_proto(node);
164 }
165
hidden_def(semanage_node_get_proto)166 hidden_def(semanage_node_get_proto)
167
168 void semanage_node_set_proto(semanage_node_t * node, int proto)
169 {
170
171 sepol_node_set_proto(node, proto);
172 }
173
hidden_def(semanage_node_set_proto)174 hidden_def(semanage_node_set_proto)
175
176 const char *semanage_node_get_proto_str(int proto)
177 {
178
179 return sepol_node_get_proto_str(proto);
180 }
181
hidden_def(semanage_node_get_proto_str)182 hidden_def(semanage_node_get_proto_str)
183
184 /* Context */
185 semanage_context_t *semanage_node_get_con(const semanage_node_t * node)
186 {
187
188 return sepol_node_get_con(node);
189 }
190
hidden_def(semanage_node_get_con)191 hidden_def(semanage_node_get_con)
192
193 int semanage_node_set_con(semanage_handle_t * handle,
194 semanage_node_t * node, semanage_context_t * con)
195 {
196
197 return sepol_node_set_con(handle->sepolh, node, con);
198 }
199
hidden_def(semanage_node_set_con)200 hidden_def(semanage_node_set_con)
201
202 /* Create/Clone/Destroy */
203 int semanage_node_create(semanage_handle_t * handle,
204 semanage_node_t ** node_ptr)
205 {
206
207 return sepol_node_create(handle->sepolh, node_ptr);
208 }
209
hidden_def(semanage_node_create)210 hidden_def(semanage_node_create)
211
212 int semanage_node_clone(semanage_handle_t * handle,
213 const semanage_node_t * node,
214 semanage_node_t ** node_ptr)
215 {
216
217 return sepol_node_clone(handle->sepolh, node, node_ptr);
218 }
219
hidden_def(semanage_node_clone)220 hidden_def(semanage_node_clone)
221
222 void semanage_node_free(semanage_node_t * node)
223 {
224
225 sepol_node_free(node);
226 }
227
228 hidden_def(semanage_node_free)
229
230 /* Port base functions */
231 record_table_t SEMANAGE_NODE_RTABLE = {
232 .create = semanage_node_create,
233 .key_extract = semanage_node_key_extract,
234 .key_free = semanage_node_key_free,
235 .clone = semanage_node_clone,
236 .compare = semanage_node_compare,
237 .compare2 = semanage_node_compare2,
238 .compare2_qsort = semanage_node_compare2_qsort,
239 .free = semanage_node_free,
240 };
241