File: natest.c

package info (click to toggle)
libapache2-mod-auth-gssapi 1.6.4-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 912 kB
  • sloc: ansic: 9,927; python: 1,114; yacc: 163; sh: 147; makefile: 132; lex: 25
file content (64 lines) | stat: -rw-r--r-- 1,340 bytes parent folder | download | duplicates (3)
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);
}