]>
git.saurik.com Git - apple/xnu.git/blob - tools/tests/personas/persona_test.h
4 * Jeremy C. Andrus <jeremy_andrus@apple.com>
7 #ifndef _PERSONA_TEST_H_
8 #define _PERSONA_TEST_H_
11 #include <spawn_private.h>
12 #include <sys/persona.h>
13 #include <sys/spawn_internal.h>
20 PA_SHOULD_VERIFY
= 0x0002,
26 PA_HAS_GROUPS
= 0x1000,
27 PA_HAS_LOGIN
= 0x2000,
33 struct kpersona_info kinfo
;
38 * Error codes emitted on failure
42 #define ERR_SPAWN_ATTR 31
43 #define ERR_CHILD_FAIL 40
47 #define err(fmt, ...) \
50 fprintf(stderr, "[%4d] [ERROR(%d:%s)] %s:%d: " fmt "\n", \
51 getuid(), errno, strerror(errno), \
52 __func__, __LINE__, ## __VA_ARGS__ ); \
57 #define errc(code, fmt, ...) \
60 fprintf(stderr, "[%4d] [ERROR(%d)] %s:%d: " fmt "\n", \
62 __func__, __LINE__, ## __VA_ARGS__ ); \
64 exit(code ? code : ERR_SYSTEM); \
67 #define err_print(fmt, ...) \
70 fprintf(stderr, "[%4d] [ERROR(%d:%s)] %s:%d: " fmt "\n", \
71 getuid(), errno, strerror(errno), \
72 __func__, __LINE__, ## __VA_ARGS__ ); \
77 #define err__start(fmt, ...) \
79 fprintf(stderr, "[%4d] [ERROR] " fmt, getuid(), ## __VA_ARGS__); \
83 #define err__cont(fmt, ...) \
85 fprintf(stderr, fmt, ## __VA_ARGS__); \
89 #define err__finish(fmt, ...) \
91 fprintf(stderr, fmt "\n", ## __VA_ARGS__); \
97 #define dbg(fmt, ...) \
99 fprintf(stdout, "[%4d] [DEBUG] " fmt "\n", getuid(), ## __VA_ARGS__ ); \
102 #define warn(fmt, ...) \
104 fprintf(stdout, "[%4d] [WARN ] " fmt "\n", getuid(), ## __VA_ARGS__ ); \
112 #define info(fmt, ...) \
114 fprintf(stdout, "[%4d] [INFO ] " fmt "\n", getuid(), ## __VA_ARGS__ ); \
118 #define info_start(fmt, ...) \
120 fprintf(stdout, "[%4d] [INFO ] " fmt, getuid(), ## __VA_ARGS__ ); \
123 #define info_cont(fmt, ...) \
125 fprintf(stdout, fmt, ## __VA_ARGS__ ); \
130 fprintf(stdout, "\n"); \
134 #define infov(fmt, ...) \
136 fprintf(stdout, "[%4d] [vINFO] " fmt "\n", getuid(), ## __VA_ARGS__ ); \
140 #define ARRAY_SZ(a) \
141 (sizeof(a) / sizeof((a)[0]))
145 _dump_kpersona(const char *msg
, uint32_t flags
, const struct kpersona_info
*ki
)
150 info("\t kpersona_info (v%d) {", ki
->persona_info_version
);
151 info("\t\t %cid: %d", flags
& PA_HAS_ID
? '+' : '-', ki
->persona_id
);
152 info("\t\t %ctype: %d", flags
& PA_HAS_TYPE
? '+' : '-', ki
->persona_type
);
153 info("\t\t %cgid: %d", flags
& PA_HAS_GID
? '+' : '-', ki
->persona_gid
);
155 info_start("\t\t ngroups: %d", ki
->persona_ngroups
);
156 for (int i
= 0; i
< ki
->persona_ngroups
; i
++) {
160 info_cont(" %d", ki
->persona_groups
[i
]);
162 if (ki
->persona_ngroups
> 0) {
167 info("\t\t %cgmuid: %d (0x%x)", flags
& PA_HAS_GROUPS
? '+' : '-',
168 (int)ki
->persona_gmuid
, ki
->persona_gmuid
);
169 info("\t\t %clogin: \"%s\"", flags
& PA_HAS_LOGIN
? '+' : '-', ki
->persona_name
);
173 #define dump_kpersona(msg, ki) \
174 _dump_kpersona(msg, 0xffffffff, ki)
177 dump_persona_args(const char *msg
, const struct persona_args
*pa
)
179 const struct kpersona_info
*ki
= &pa
->kinfo
;
184 info("\t flags: 0x%x", pa
->flags
);
185 info("\t %cuid: %d", pa
->flags
& PA_HAS_UID
? '+' : '-', pa
->override_uid
);
186 _dump_kpersona(NULL
, pa
->flags
, ki
);
190 parse_groupspec(struct kpersona_info
*kinfo
, char *spec
)
203 while (*e
&& *e
!= ',') {
220 kinfo
->persona_groups
[idx
] = grp
;
223 kinfo
->persona_ngroups
= idx
;
228 #endif /* _PERSONA_TEST_H_ */