1 /* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
3 * Copyright 2011 Red Hat, Inc.
5 * Permission is hereby granted, free of charge, to any person
6 * obtaining a copy of this software and associated documentation files
7 * (the "Software"), to deal in the Software without restriction,
8 * including without limitation the rights to use, copy, modify, merge,
9 * publish, distribute, sublicense, and/or sell copies of the Software,
10 * and to permit persons to whom the Software is furnished to do so,
11 * subject to the following conditions:
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
36 "Usage: t_credstore [-sabi] principal [{key value} ...]\n");
41 main(int argc, char *argv[])
43 OM_uint32 minor, major;
44 gss_key_value_set_desc store;
46 gss_cred_usage_t cred_usage = GSS_C_BOTH;
47 gss_OID_set mechs = GSS_C_NO_OID_SET;
48 gss_cred_id_t cred = GSS_C_NO_CREDENTIAL;
49 krb5_boolean store_creds = FALSE;
53 for (argv++; *argv != NULL && **argv == '-'; argv++) {
58 cred_usage = GSS_C_ACCEPT;
60 cred_usage = GSS_C_BOTH;
62 cred_usage = GSS_C_INITIATE;
67 /* Get the principal name. */
70 name = import_name(*argv++);
72 /* Put any remaining arguments into the store. */
73 store.elements = calloc(argc, sizeof(struct gss_key_value_element_struct));
77 while (*argv != NULL) {
78 if (*(argv + 1) == NULL)
80 store.elements[store.count].key = *argv;
81 store.elements[store.count].value = *(argv + 1);
87 /* Acquire default creds and try to store them in the cred store. */
88 major = gss_acquire_cred(&minor, GSS_C_NO_NAME, 0, GSS_C_NO_OID_SET,
89 GSS_C_INITIATE, &cred, NULL, NULL);
90 check_gsserr("gss_acquire_cred", major, minor);
92 major = gss_store_cred_into(&minor, cred, GSS_C_INITIATE,
93 GSS_C_NO_OID, 1, 0, &store, NULL, NULL);
94 check_gsserr("gss_store_cred_into", major, minor);
96 gss_release_cred(&minor, &cred);
99 /* Try to acquire creds from store. */
100 major = gss_acquire_cred_from(&minor, name, 0, mechs, cred_usage,
101 &store, &cred, NULL, NULL);
102 check_gsserr("gss_acquire_cred_from", major, minor);
104 gss_release_name(&minor, &name);
105 gss_release_cred(&minor, &cred);
106 free(store.elements);