-
Notifications
You must be signed in to change notification settings - Fork 2
/
cfengine36.h
308 lines (264 loc) · 9.37 KB
/
cfengine36.h
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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
typedef struct Policy_ Policy;
typedef struct Bundle_ Bundle;
typedef struct PromiseType_ PromiseType;
typedef struct Promise_ Promise;
typedef struct EvalContext_ EvalContext;
typedef void PromiseActuator(EvalContext *ctx, Promise *pp, void *param);
typedef struct Rlist_ Rlist;
typedef struct Map_ Map;
typedef Map Set;
typedef bool (*MapKeyEqualFn)(const void *key1, const void *key2);
typedef void (*MapDestroyDataFn)(void *key);
typedef unsigned int (*MapHashFn) (const void *p, unsigned int max);
typedef struct
{
void* key;
void *value;
} MapKeyValue;
typedef struct BucketListItem_
{
MapKeyValue value;
struct BucketListItem_ *next;
} BucketListItem;
typedef struct
{
MapKeyEqualFn equal_fn;
MapDestroyDataFn destroy_key_fn;
MapDestroyDataFn destroy_value_fn;
MapKeyValue *values;
short size;
} ArrayMap;
typedef struct
{
ArrayMap *map;
int pos;
} ArrayMapIterator;
typedef struct
{
MapHashFn hash_fn;
MapKeyEqualFn equal_fn;
MapDestroyDataFn destroy_key_fn;
MapDestroyDataFn destroy_value_fn;
BucketListItem **buckets;
} HashMap;
typedef struct
{
HashMap *map;
BucketListItem *cur;
int bucket;
} HashMapIterator;
typedef struct
{
bool is_array;
union
{
ArrayMapIterator arraymap_iter;
HashMapIterator hashmap_iter;
};
} MapIterator;
typedef MapIterator SetIterator;
#define TYPED_SET_DECLARE(Prefix, ElementType) \
typedef struct \
{ \
Set *impl; \
} Prefix##Set; \
\
typedef SetIterator Prefix##SetIterator; \
\
Prefix##Set *Prefix##SetNew(void); \
void Prefix##SetAdd(const Prefix##Set *set, ElementType element); \
bool Prefix##SetContains(const Prefix##Set *Set, const ElementType element); \
bool Prefix##SetRemove(const Prefix##Set *Set, const ElementType element); \
void Prefix##SetClear(Prefix##Set *set); \
size_t Prefix##SetSize(const Prefix##Set *set); \
void Prefix##SetDestroy(Prefix##Set *set); \
Prefix##SetIterator Prefix##SetIteratorInit(Prefix##Set *set); \
ElementType Prefix##SetIteratorNext(Prefix##SetIterator *iter); \
#define TYPED_SET_DEFINE(Prefix, ElementType, hash_fn, equal_fn, destroy_fn) \
\
Prefix##Set *Prefix##SetNew(void) \
{ \
Prefix##Set *set = xcalloc(1, sizeof(Prefix##Set)); \
set->impl = SetNew(hash_fn, equal_fn, destroy_fn); \
return set; \
} \
\
void Prefix##SetAdd(const Prefix##Set *set, ElementType element) \
{ \
SetAdd(set->impl, (void *)element); \
} \
\
bool Prefix##SetContains(const Prefix##Set *set, const ElementType element) \
{ \
return SetContains(set->impl, element); \
} \
\
bool Prefix##SetRemove(const Prefix##Set *set, const ElementType element) \
{ \
return SetRemove(set->impl, element); \
} \
\
void Prefix##SetClear(Prefix##Set *set) \
{ \
return SetClear(set->impl); \
} \
\
size_t Prefix##SetSize(const Prefix##Set *set) \
{ \
return SetSize(set->impl); \
} \
\
void Prefix##SetDestroy(Prefix##Set *set) \
{ \
if (set) \
{ \
SetDestroy(set->impl); \
free(set); \
} \
} \
\
Prefix##SetIterator Prefix##SetIteratorInit(Prefix##Set *set) \
{ \
return SetIteratorInit(set->impl); \
} \
\
ElementType Prefix##SetIteratorNext(Prefix##SetIterator *iter) \
{ \
return SetIteratorNext(iter); \
} \
TYPED_SET_DECLARE(String, char *)
typedef enum
{
RVAL_TYPE_SCALAR = 's',
RVAL_TYPE_LIST = 'l',
RVAL_TYPE_FNCALL = 'f',
RVAL_TYPE_NOPROMISEE = 'X'
} RvalType;
typedef enum
{
AGENT_TYPE_COMMON,
AGENT_TYPE_AGENT,
AGENT_TYPE_SERVER,
AGENT_TYPE_MONITOR,
AGENT_TYPE_EXECUTOR,
AGENT_TYPE_RUNAGENT,
AGENT_TYPE_KEYGEN,
AGENT_TYPE_HUB,
AGENT_TYPE_GENDOC,
AGENT_TYPE_NOAGENT
} AgentType;
struct Map_
{
MapHashFn hash_fn;
union
{
ArrayMap *arraymap;
HashMap *hashmap;
};
};
struct Rlist_
{
void *item;
RvalType type;
Rlist *state_ptr; /* Points to "current" state/element of sub-list */
Rlist *next;
};
typedef struct
{
AgentType agent_type;
Rlist *bundlesequence;
char *original_input_file;
char *input_file;
char *input_dir;
bool check_not_writable_by_others;
bool check_runnable;
StringSet *heap_soft;
StringSet *heap_negated;
bool tty_interactive; // agent is running interactively, via tty/terminal interface
// change to evaluation behavior from the policy itself
bool ignore_missing_bundles;
bool ignore_missing_inputs;
struct
{
struct
{
enum
{
GENERIC_AGENT_CONFIG_COMMON_POLICY_OUTPUT_FORMAT_NONE,
GENERIC_AGENT_CONFIG_COMMON_POLICY_OUTPUT_FORMAT_CF,
GENERIC_AGENT_CONFIG_COMMON_POLICY_OUTPUT_FORMAT_JSON
} policy_output_format;
unsigned int parser_warnings;
unsigned int parser_warnings_error;
} common;
struct
{
char *bootstrap_policy_server;
} agent;
} agent_specific;
} GenericAgentConfig;
typedef struct
{
void **data;
size_t length;
size_t capacity;
void (*ItemDestroy) (void *item);
} Seq;
typedef struct
{
size_t start;
size_t end;
size_t line;
size_t context;
} SourceOffset;
typedef struct
{
void *item;
RvalType type;
} Rval;
struct Policy_
{
Seq *bundles;
Seq *bodies;
};
struct Bundle_
{
Policy *parent_policy;
char *type;
char *name;
char *ns;
Rlist *args;
Seq *promise_types;
char *source_path;
SourceOffset offset;
};
struct PromiseType_
{
Bundle *parent_bundle;
char *name;
Seq *promises;
SourceOffset offset;
};
struct Promise_
{
PromiseType *parent_promise_type;
char *classes;
char *comment;
char *promiser;
Rval promisee;
Seq *conlist;
bool has_subbundles;
const Promise *org_pp; /* A ptr to the unexpanded raw promise */
SourceOffset offset;
};
typedef enum
{
PROMISE_RESULT_SKIPPED,
PROMISE_RESULT_NOOP = 'n',
PROMISE_RESULT_CHANGE = 'c',
PROMISE_RESULT_WARN = 'w', // something wrong but nothing done
PROMISE_RESULT_FAIL = 'f',
PROMISE_RESULT_DENIED = 'd',
PROMISE_RESULT_TIMEOUT = 't',
PROMISE_RESULT_INTERRUPTED = 'i'
} PromiseResult;