1 /* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /* lib/krb5/ccache/ccselect_realm.c - realm ccselect module */
4 * Copyright (C) 2011 by the Massachusetts Institute of Technology.
7 * Export of this software from the United States of America may
8 * require a specific license from the United States Government.
9 * It is the responsibility of any person or organization contemplating
10 * export to obtain such a license before exporting.
12 * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
13 * distribute this software and its documentation for any purpose and
14 * without fee is hereby granted, provided that the above copyright
15 * notice appear in all copies and that both that copyright notice and
16 * this permission notice appear in supporting documentation, and that
17 * the name of M.I.T. not be used in advertising or publicity pertaining
18 * to distribution of the software without specific, written prior
19 * permission. Furthermore if you modify this software you must label
20 * your software as modified software and not distribute it in such a
21 * fashion that it might be confused with the original M.I.T. software.
22 * M.I.T. makes no representations about the suitability of
23 * this software for any purpose. It is provided "as is" without express
24 * or implied warranty.
29 #include <krb5/ccselect_plugin.h>
31 static krb5_error_code
32 realm_init(krb5_context context, krb5_ccselect_moddata *data_out,
36 *priority_out = KRB5_CCSELECT_PRIORITY_HEURISTIC;
40 static krb5_error_code
41 realm_choose(krb5_context context, krb5_ccselect_moddata data,
42 krb5_principal server, krb5_ccache *cache_out,
43 krb5_principal *princ_out)
46 krb5_cccol_cursor cursor;
53 if (krb5_is_referral_realm(&server->realm))
54 return KRB5_PLUGIN_NO_HANDLE;
56 /* Scan the collection for a cache with a client principal in the same
57 * realm as the server principal. */
58 ret = krb5_cccol_cursor_new(context, &cursor);
61 while ((ret = krb5_cccol_cursor_next(context, cursor, &cache)) == 0 &&
63 ret = krb5_cc_get_principal(context, cache, &princ);
65 if (data_eq(princ->realm, server->realm))
67 krb5_free_principal(context, princ);
69 krb5_cc_close(context, cache);
71 krb5_cccol_cursor_free(context, &cursor);
76 return KRB5_PLUGIN_NO_HANDLE;
83 ccselect_realm_initvt(krb5_context context, int maj_ver, int min_ver,
84 krb5_plugin_vtable vtable)
86 krb5_ccselect_vtable vt;
89 return KRB5_PLUGIN_VER_NOTSUPP;
90 vt = (krb5_ccselect_vtable)vtable;
92 vt->init = realm_init;
93 vt->choose = realm_choose;