1 /* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /* lib/krb5/krb/t_ctxprf.c - krb5_init_context_profile() test */
3 /*
4 * Copyright (C) 2024 by the Massachusetts Institute of Technology.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 *
14 * * Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the
17 * distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
24 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
28 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
30 * OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33 /*
34 * This program tests the use of krb5_init_context_profile() with a modified
35 * profile object. If run with the single argument "empty", we create and
36 * modifiemodify an empty profile; otherwise, we retrieve and modify the
37 * profile for a normally created libkrb5 context. In both cases, we set a
38 * realm KDC value in the profile and use k5_locate_kdc() to verify that the
39 * setting is reflected in a libkrb5 context created using the modified
40 * profile.
41 */
42
43 #include "k5-int.h"
44 #include "os-proto.h"
45
46 static void
check(long code)47 check(long code)
48 {
49 assert(code == 0);
50 }
51
52 int
main(int argc,char ** argv)53 main(int argc, char **argv)
54 {
55 profile_t p;
56 krb5_context ctx;
57 const char *names[] = { "realms", "KRBTEST.COM", "kdc", NULL };
58 krb5_data realm = string2data("KRBTEST.COM");
59 struct serverlist sl;
60
61 if (argc > 1 && strcmp(argv[1], "empty") == 0) {
62 check(profile_init(NULL, &p));
63 } else {
64 check(krb5_init_context(&ctx));
65 check(krb5_get_profile(ctx, &p));
66 krb5_free_context(ctx);
67 profile_clear_relation(p, names);
68 }
69 check(profile_add_relation(p, names, "ctx.prf.test"));
70
71 check(krb5_init_context_profile(p, 0, &ctx));
72 check(k5_locate_kdc(ctx, &realm, &sl, FALSE, FALSE));
73 assert(sl.nservers == 1);
74 assert(strcmp(sl.servers[0].hostname, "ctx.prf.test") == 0);
75
76 profile_abandon(p);
77 k5_free_serverlist(&sl);
78 krb5_free_context(ctx);
79 return 0;
80 }
81