1 /* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /* lib/krad/t_attr.c - Attribute test program */
4 * Copyright 2013 Red Hat, Inc. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
18 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
21 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 const static unsigned char encoded[] = {
33 0xba, 0xfc, 0xed, 0x50, 0xe1, 0xeb, 0xa6, 0xc3,
34 0xc1, 0x75, 0x20, 0xe9, 0x10, 0xce, 0xc2, 0xcb
37 const static unsigned char auth[] = {
38 0xac, 0x9d, 0xc1, 0x62, 0x08, 0xc4, 0xc7, 0x8b,
39 0xa1, 0x2f, 0x25, 0x0a, 0xc4, 0x1d, 0x36, 0x41
45 unsigned char outbuf[MAX_ATTRSETSIZE];
46 const char *decoded = "accept";
47 const char *secret = "foo";
48 krb5_error_code retval;
54 noerror(krb5_init_context(&ctx));
56 /* Make sure User-Name is 1. */
57 insist(krad_attr_name2num("User-Name") == 1);
59 /* Make sure 2 is User-Password. */
60 tmp = krad_attr_num2name(2);
62 insist(strcmp(tmp, "User-Password") == 0);
65 in = make_data((void *)encoded, sizeof(encoded));
66 noerror(kr_attr_decode(ctx, secret, auth,
67 krad_attr_name2num("User-Password"),
69 insist(len == strlen(decoded));
70 insist(memcmp(outbuf, decoded, len) == 0);
73 in = string2data((char *)decoded);
74 retval = kr_attr_encode(ctx, secret, auth,
75 krad_attr_name2num("User-Password"),
78 insist(len == sizeof(encoded));
79 insist(memcmp(outbuf, encoded, len) == 0);
81 /* Test constraint. */
83 insist(kr_attr_valid(krad_attr_name2num("User-Password"), &in) == 0);
85 insist(kr_attr_valid(krad_attr_name2num("User-Password"), &in) != 0);
87 krb5_free_context(ctx);