]>
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]))
144 static inline void _dump_kpersona(const char *msg
, uint32_t flags
, const struct kpersona_info
*ki
)
148 info("\t kpersona_info (v%d) {", ki
->persona_info_version
);
149 info("\t\t %cid: %d", flags
& PA_HAS_ID
? '+' : '-', ki
->persona_id
);
150 info("\t\t %ctype: %d", flags
& PA_HAS_TYPE
? '+' : '-', ki
->persona_type
);
151 info("\t\t %cgid: %d", flags
& PA_HAS_GID
? '+' : '-', ki
->persona_gid
);
153 info_start("\t\t ngroups: %d", ki
->persona_ngroups
);
154 for (int i
= 0; i
< ki
->persona_ngroups
; i
++) {
155 if (i
== 0) info_cont(" {");
156 info_cont(" %d", ki
->persona_groups
[i
]);
158 if (ki
->persona_ngroups
> 0)
162 info("\t\t %cgmuid: %d (0x%x)", flags
& PA_HAS_GROUPS
? '+' : '-',
163 (int)ki
->persona_gmuid
, ki
->persona_gmuid
);
164 info("\t\t %clogin: \"%s\"", flags
& PA_HAS_LOGIN
? '+' : '-', ki
->persona_name
);
168 #define dump_kpersona(msg, ki) \
169 _dump_kpersona(msg, 0xffffffff, ki)
171 static inline void dump_persona_args(const char *msg
, const struct persona_args
*pa
)
173 const struct kpersona_info
*ki
= &pa
->kinfo
;
177 info("\t flags: 0x%x", pa
->flags
);
178 info("\t %cuid: %d", pa
->flags
& PA_HAS_UID
? '+' : '-', pa
->override_uid
);
179 _dump_kpersona(NULL
, pa
->flags
, ki
);
182 static int parse_groupspec(struct kpersona_info
*kinfo
, char *spec
)
194 while (*e
&& *e
!= ',')
208 kinfo
->persona_groups
[idx
] = grp
;
211 kinfo
->persona_ngroups
= idx
;
216 #endif /* _PERSONA_TEST_H_ */