1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
|
#ifndef H_RPMSX
#define H_RPMSX
/** \ingroup rpmdep rpmtrans
* \file lib/rpmsx.h
* Structure(s) used for file security context pattern handling
*/
#include <regex.h>
/**
*/
/*@-exportlocal@*/
/*@unchecked@*/
extern int _rpmsx_debug;
/*@=exportlocal@*/
/**
*/
/*@-exportlocal@*/
/*@unchecked@*/
extern int _rpmsx_nopromote;
/*@=exportlocal@*/
typedef /*@abstract@*/ /*@refcounted@*/ struct rpmsx_s * rpmsx;
typedef struct rpmsxp_s * rpmsxp;
typedef struct rpmsxs_s * rpmsxs;
#if defined(_RPMSX_INTERNAL)
/**
* File security context regex pattern.
*/
struct rpmsxp_s {
/*@only@*/ /*@relnull@*/
const char * pattern; /*!< File path regex pattern. */
/*@only@*/ /*@relnull@*/
const char * type; /*!< File type string. */
/*@only@*/ /*@relnull@*/
const char * context; /*!< Security context. */
/*@only@*/ /*@relnull@*/
regex_t * preg; /*!< Compiled regex. */
mode_t fmode; /*!< File type. */
int matches;
int hasMetaChars;
int fstem; /*!< Stem id. */
};
/**
* File/pattern stem.
*/
struct rpmsxs_s {
/*@only@*/ /*@relnull@*/
const char * stem;
int len;
};
/**
* File security context patterns container.
*/
struct rpmsx_s {
/*@only@*/ /*@relnull@*/
rpmsxp sxp; /*!< File context patterns. */
int Count; /*!< No. of file context patterns. */
int i; /*!< Current pattern index. */
/*@only@*/ /*@relnull@*/
rpmsxs sxs; /*!< File stems. */
int nsxs; /*!< No. of file stems. */
int maxsxs; /*!< No. of allocated file stems. */
int reverse; /*!< Reverse traversal? */
/*@refs@*/
int nrefs; /*!< Reference count. */
};
#endif /* defined(_RPMSX_INTERNAL) */
#ifdef __cplusplus
extern "C" {
#endif
/**
* Unreference a security context patterns instance.
* @param sx security context patterns
* @param msg
* @return NULL always
*/
/*@unused@*/ /*@null@*/
rpmsx rpmsxUnlink (/*@killref@*/ /*@only@*/ /*@null@*/ rpmsx sx,
/*@null@*/ const char * msg)
/*@modifies sx @*/;
/** @todo Remove debugging entry from the ABI. */
/*@-exportlocal@*/
/*@null@*/
rpmsx XrpmsxUnlink (/*@killref@*/ /*@only@*/ /*@null@*/ rpmsx sx,
/*@null@*/ const char * msg, const char * fn, unsigned ln)
/*@modifies sx @*/;
/*@=exportlocal@*/
#define rpmsxUnlink(_sx, _msg) XrpmsxUnlink(_sx, _msg, __FILE__, __LINE__)
/**
* Reference a security context patterns instance.
* @param sx security context patterns
* @param msg
* @return new security context patterns reference
*/
/*@-exportlocal@*/
/*@unused@*/ /*@newref@*/ /*@null@*/
rpmsx rpmsxLink (/*@null@*/ rpmsx sx, /*@null@*/ const char * msg)
/*@modifies sx @*/;
/** @todo Remove debugging entry from the ABI. */
/*@newref@*/ /*@null@*/
rpmsx XrpmsxLink (/*@null@*/ rpmsx sx, /*@null@*/ const char * msg,
const char * fn, unsigned ln)
/*@modifies sx @*/;
/*@=exportlocal@*/
#define rpmsxLink(_sx, _msg) XrpmsxLink(_sx, _msg, __FILE__, __LINE__)
/**
* Destroy a security context patterns.
* @param sx security context patterns
* @return NULL always
*/
/*@-exportlocal@*/
/*@null@*/
rpmsx rpmsxFree(/*@killref@*/ /*@only@*/ /*@null@*/ rpmsx sx)
/*@modifies sx@*/;
/*@=exportlocal@*/
/**
* Parse selinux file security context patterns.
* @param sx security context patterns
* @param fn file name to parse
* @return 0 on success
*/
/*@-exportlocal@*/
int rpmsxParse(rpmsx sx, /*@null@*/ const char *fn)
/*@globals rpmGlobalMacroContext, h_errno, fileSystem @*/
/*@modifies sx, rpmGlobalMacroContext, h_errno, fileSystem @*/;
/*@=exportlocal@*/
/**
* Create and load security context patterns.
* @param fn security context patterns file name
* @return new security context patterns
*/
/*@null@*/
rpmsx rpmsxNew(const char * fn)
/*@globals rpmGlobalMacroContext, h_errno, fileSystem @*/
/*@modifies rpmGlobalMacroContext, h_errno, fileSystem @*/;
/**
* Return security context patterns count.
* @param sx security context patterns
* @return current count
*/
int rpmsxCount(/*@null@*/ const rpmsx sx)
/*@*/;
/**
* Return security context patterns index.
* @param sx security context patterns
* @return current index
*/
int rpmsxIx(/*@null@*/ const rpmsx sx)
/*@*/;
/**
* Set security context patterns index.
* @param sx security context patterns
* @param ix new index
* @return current index
*/
int rpmsxSetIx(/*@null@*/ rpmsx sx, int ix)
/*@modifies sx @*/;
/**
* Return current pattern.
* @param sx security context patterns
* @return current pattern, NULL on invalid
*/
/*@-exportlocal@*/
/*@observer@*/ /*@null@*/
extern const char * rpmsxPattern(/*@null@*/ const rpmsx sx)
/*@*/;
/*@=exportlocal@*/
/**
* Return current type.
* @param sx security context patterns
* @return current type, NULL on invalid/missing
*/
/*@-exportlocal@*/
/*@observer@*/ /*@null@*/
extern const char * rpmsxType(/*@null@*/ const rpmsx sx)
/*@*/;
/*@=exportlocal@*/
/**
* Return current context.
* @param sx security context patterns
* @return current context, NULL on invalid
*/
/*@-exportlocal@*/
/*@observer@*/ /*@null@*/
extern const char * rpmsxContext(/*@null@*/ const rpmsx sx)
/*@*/;
/*@=exportlocal@*/
/**
* Return current regex.
* @param sx security context patterns
* @return current context, NULL on invalid
*/
/*@-exportlocal@*/
/*@observer@*/ /*@null@*/
extern regex_t * rpmsxRE(/*@null@*/ const rpmsx sx)
/*@*/;
/*@=exportlocal@*/
/**
* Return current file mode.
* @param sx security context patterns
* @return current file mode, 0 on invalid
*/
/*@-exportlocal@*/
extern mode_t rpmsxFMode(/*@null@*/ const rpmsx sx)
/*@*/;
/*@=exportlocal@*/
/**
* Return current file stem.
* @param sx security context patterns
* @return current file stem, -1 on invalid
*/
/*@-exportlocal@*/
extern int rpmsxFStem(/*@null@*/ const rpmsx sx)
/*@*/;
/*@=exportlocal@*/
/**
* Return next security context patterns iterator index.
* @param sx security context patterns
* @return security context patterns iterator index, -1 on termination
*/
/*@-exportlocal@*/
int rpmsxNext(/*@null@*/ rpmsx sx)
/*@modifies sx @*/;
/*@=exportlocal@*/
/**
* Initialize security context patterns iterator.
* @param sx security context patterns
* @param reverse iterate in reverse order?
* @return security context patterns
*/
/*@-exportlocal@*/
/*@null@*/
rpmsx rpmsxInit(/*@null@*/ rpmsx sx, int reverse)
/*@modifies sx @*/;
/*@=exportlocal@*/
/**
* Find file security context from path and type.
* @param sx security context patterns
* @param fn file path
* @param fmode file mode
* @return file security context
*/
/*@owned@*/ /*@null@*/
const char * rpmsxFContext(/*@null@*/ rpmsx sx, const char * fn, mode_t fmode)
/*@modifies sx @*/;
#ifdef __cplusplus
}
#endif
#endif /* H_RPMSX */
|