-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathnatest.c
64 lines (53 loc) · 1.31 KB
/
natest.c
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
/* Copyright (C) 2017 mod_auth_gssapi contributors - See COPYING for (C) terms
*
* Unit tests for the GssapiRequiredNameAttributes option parser.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "../src/mag_parse.h"
void usage(char *name)
{
fprintf(stderr, "%s \"expr\" [\"attr=val\", ...]\n", name);
exit(-1);
}
int main(int argc, char **argv)
{
int ret;
int anum = 0;
const char **attrs = NULL;
const char **vals = NULL;
if (argc < 3)
usage(argv[0]);
ret = mag_check_name_attr_expr(argv[1]);
if (ret != 1) {
fprintf(stderr, "syntax error\n");
exit(1);
}
attrs = calloc(argc - 1, sizeof(*attrs));
vals = calloc(argc - 1, sizeof(*vals));
if (attrs == NULL || vals == NULL) {
fprintf(stderr, "calloc failed\n");
exit(1);
}
for (int i = 2; i < argc; i++) {
char *v, *a = argv[i];
v = strchr(a, '=');
if (v == NULL)
continue;
*v++ = '\0';
if (*v == '\0')
continue;
attrs[anum] = a;
vals[anum++] = v;
}
ret = mag_verify_name_attributes(argv[1], attrs, vals);
if (ret == 1) {
fprintf(stdout, "True\n");
ret = 0;
} else {
fprintf(stdout, "False\n");
ret = 1;
}
exit(ret);
}