1/* Copyright (c) 2012 Apple Inc. All rights reserved. */
2
3#ifndef _SECURITY_AUTH_ITEMS_H_
4#define _SECURITY_AUTH_ITEMS_H_
5
6#include <Security/Authorization.h>
7#include <xpc/xpc.h>
8
9#if defined(__cplusplus)
10extern "C" {
11#endif
12
13enum {
14    AI_TYPE_UNKNOWN = 0,
15    AI_TYPE_RIGHT,
16    AI_TYPE_STRING,
17    AI_TYPE_INT,
18    AI_TYPE_UINT,
19    AI_TYPE_INT64,
20    AI_TYPE_UINT64,
21    AI_TYPE_DOUBLE,
22    AI_TYPE_BOOL,
23    AI_TYPE_DATA
24};
25
26#pragma mark -
27#pragma mark auth_items_t
28
29/* unordered items */
30
31#ifdef __BLOCKS__
32typedef bool (^auth_items_iterator_t)(const char *key);
33#endif /* __BLOCKS__ */
34
35CFTypeID auth_items_get_type_id(void);
36
37AUTH_WARN_RESULT AUTH_MALLOC AUTH_RETURNS_RETAINED
38auth_items_t auth_items_create(void);
39
40AUTH_WARN_RESULT AUTH_MALLOC AUTH_NONNULL_ALL AUTH_RETURNS_RETAINED
41auth_items_t auth_items_create_with_xpc(const xpc_object_t data);
42
43AUTH_WARN_RESULT AUTH_MALLOC AUTH_NONNULL_ALL AUTH_RETURNS_RETAINED
44auth_items_t auth_items_create_copy(auth_items_t);
45
46AUTH_WARN_RESULT AUTH_NONNULL_ALL
47size_t auth_items_get_count(auth_items_t);
48
49AUTH_WARN_RESULT AUTH_NONNULL_ALL
50AuthorizationItemSet * auth_items_get_item_set(auth_items_t);
51
52AUTH_WARN_RESULT AUTH_NONNULL_ALL
53xpc_object_t auth_items_export_xpc(auth_items_t);
54
55AUTH_NONNULL_ALL
56void auth_items_set_flags(auth_items_t, const char *key, uint32_t flags);
57
58AUTH_NONNULL_ALL
59void auth_items_clear_flags(auth_items_t, const char *key, uint32_t flags);
60
61AUTH_WARN_RESULT AUTH_NONNULL_ALL
62uint32_t auth_items_get_flags(auth_items_t, const char *key);
63
64AUTH_NONNULL_ALL
65bool auth_items_check_flags(auth_items_t, const char *key, uint32_t flags);
66
67AUTH_NONNULL_ALL
68void auth_items_set_key(auth_items_t, const char *key);
69
70AUTH_NONNULL_ALL
71bool auth_items_exist(auth_items_t, const char *key);
72
73AUTH_NONNULL_ALL
74void auth_items_remove(auth_items_t, const char *key);
75
76AUTH_NONNULL_ALL
77void auth_items_remove_with_flags(auth_items_t, uint32_t flags);
78
79AUTH_NONNULL_ALL
80void auth_items_clear(auth_items_t);
81
82AUTH_NONNULL_ALL
83void auth_items_copy(auth_items_t, auth_items_t src);
84
85AUTH_NONNULL_ALL
86void auth_items_copy_xpc(auth_items_t, const xpc_object_t src);
87
88AUTH_NONNULL_ALL
89void auth_items_copy_with_flags(auth_items_t, auth_items_t src, uint32_t flags);
90
91AUTH_NONNULL_ALL
92bool auth_items_iterate(auth_items_t, auth_items_iterator_t iter);
93
94AUTH_NONNULL_ALL
95void auth_items_set_string(auth_items_t, const char *key, const char *value);
96
97AUTH_WARN_RESULT AUTH_NONNULL_ALL
98const char * auth_items_get_string(auth_items_t, const char *key);
99
100AUTH_NONNULL_ALL
101void auth_items_set_data(auth_items_t, const char *key, const void *value, size_t len);
102
103AUTH_WARN_RESULT AUTH_NONNULL_ALL
104const void * auth_items_get_data(auth_items_t, const char *key, size_t * len);
105
106AUTH_NONNULL_ALL
107void auth_items_set_bool(auth_items_t, const char *key, bool value);
108
109AUTH_WARN_RESULT AUTH_NONNULL_ALL
110bool auth_items_get_bool(auth_items_t, const char *key);
111
112AUTH_NONNULL_ALL
113void auth_items_set_int(auth_items_t, const char *key, int32_t value);
114
115AUTH_WARN_RESULT AUTH_NONNULL_ALL
116int32_t auth_items_get_int(auth_items_t, const char *key);
117
118AUTH_NONNULL_ALL
119void auth_items_set_uint(auth_items_t, const char *key, uint32_t value);
120
121AUTH_WARN_RESULT AUTH_NONNULL_ALL
122uint32_t auth_items_get_uint(auth_items_t, const char *key);
123
124AUTH_NONNULL_ALL
125void auth_items_set_int64(auth_items_t, const char *key, int64_t value);
126
127AUTH_WARN_RESULT AUTH_NONNULL_ALL
128int64_t auth_items_get_int64(auth_items_t, const char *key);
129
130AUTH_NONNULL_ALL
131void auth_items_set_uint64(auth_items_t, const char *key, uint64_t value);
132
133AUTH_WARN_RESULT AUTH_NONNULL_ALL
134uint64_t auth_items_get_uint64(auth_items_t, const char *key);
135
136AUTH_NONNULL_ALL
137void auth_items_set_double(auth_items_t, const char *key, double value);
138
139AUTH_WARN_RESULT AUTH_NONNULL_ALL
140double auth_items_get_double(auth_items_t, const char *key);
141
142AUTH_WARN_RESULT AUTH_NONNULL_ALL
143uint32_t auth_items_get_type(auth_items_t, const char *key);
144
145AUTH_WARN_RESULT AUTH_NONNULL_ALL
146size_t auth_items_get_length(auth_items_t, const char *key);
147
148AUTH_NONNULL_ALL
149void auth_items_set_value(auth_items_t, const char *key, uint32_t type, uint32_t flags, const void *value, size_t len);
150
151#pragma mark -
152#pragma mark auth_rights_t
153
154/* ordered items */
155
156AUTH_WARN_RESULT AUTH_MALLOC AUTH_RETURNS_RETAINED
157auth_rights_t auth_rights_create(void);
158
159AUTH_WARN_RESULT AUTH_MALLOC AUTH_NONNULL_ALL AUTH_RETURNS_RETAINED
160auth_rights_t auth_rights_create_with_xpc(const xpc_object_t data);
161
162AUTH_WARN_RESULT AUTH_NONNULL_ALL
163xpc_object_t auth_rights_export_xpc(auth_rights_t);
164
165AUTH_NONNULL_ALL
166void auth_rights_set_flags(auth_rights_t, const char *key, uint32_t flags);
167
168AUTH_NONNULL_ALL
169void auth_rights_clear_flags(auth_rights_t, const char *key, uint32_t flags);
170
171AUTH_WARN_RESULT AUTH_NONNULL_ALL
172uint32_t auth_rights_get_flags(auth_rights_t, const char *key);
173
174AUTH_NONNULL_ALL
175bool auth_rights_check_flags(auth_rights_t, const char *key, uint32_t flags);
176
177AUTH_WARN_RESULT AUTH_NONNULL_ALL
178size_t auth_rights_get_count(auth_rights_t);
179
180AUTH_NONNULL_ALL
181void auth_rights_add(auth_rights_t, const char *key);
182
183AUTH_NONNULL_ALL
184bool auth_rights_exist(auth_rights_t, const char *key);
185
186AUTH_NONNULL_ALL
187void auth_rights_remove(auth_rights_t, const char *key);
188
189AUTH_NONNULL_ALL
190void auth_rights_clear(auth_rights_t);
191
192AUTH_NONNULL_ALL
193bool auth_rights_iterate(auth_rights_t rights, bool(^iter)(const char * key));
194
195#if defined(__cplusplus)
196}
197#endif
198
199#endif /* !_SECURITY_AUTH_ITEMS_H_ */
200