etc/services - sync with NetBSD-8
[minix.git] / crypto / external / bsd / heimdal / dist / kuser / kcc.c
blob5488083945f308a56a610cafb6a465f6e422bcc1
1 /* $NetBSD: kcc.c,v 1.1.1.2 2014/04/24 12:45:28 pettai Exp $ */
3 /*
4 * Copyright (c) 2010 Kungliga Tekniska Högskolan
5 * (Royal Institute of Technology, Stockholm, Sweden).
6 * All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * 3. Neither the name of the Institute nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
36 #include "kuser_locl.h"
37 #include <krb5/sl.h>
38 #include "kcc-commands.h"
40 krb5_context kcc_context;
41 static int version_flag;
42 static int help_flag;
44 static struct getargs args[] = {
45 { "version", 0, arg_flag, &version_flag, NULL, NULL },
46 { "help", 0, arg_flag, &help_flag, NULL, NULL }
49 static void
50 usage(int ret)
52 arg_printusage_i18n(args,
53 sizeof(args)/sizeof(*args),
54 N_("Usage: ", ""),
55 NULL,
56 "command ..",
57 getarg_i18n);
58 exit (ret);
61 int
62 help(void *opt, int argc, char **argv)
64 sl_slc_help(commands, argc, argv);
65 return 0;
68 int
69 kgetcred(struct kgetcred_options *opt, int argc, char **argv)
71 return 0;
75 * Wrapper for command line compatiblity
78 int
79 kvno(struct kvno_options *opt, int argc, char **argv)
81 struct kgetcred_options k;
82 memset(&k, 0, sizeof(k));
84 k.cache_string = opt->cache_string;
85 k.enctype_string = opt->enctype_string;
87 return kgetcred(&k, argc, argv);
90 static int
91 command_alias(const char *name)
93 const char *aliases[] = {
94 "kinit", "klist", "kswitch", "kgetcred", "kvno", "kdeltkt",
95 "kdestroy", "kcpytkt", NULL
96 }, **p = aliases;
98 while (*p && strcmp(name, *p) != 0)
99 p++;
100 return *p != NULL;
105 main(int argc, char **argv)
107 krb5_error_code ret;
108 int optidx = 0;
109 int exit_status = 0;
111 setprogname (argv[0]);
113 setlocale (LC_ALL, "");
114 bindtextdomain ("heimdal_kuser", HEIMDAL_LOCALEDIR);
115 textdomain("heimdal_kuser");
117 ret = krb5_init_context(&kcc_context);
118 if (ret == KRB5_CONFIG_BADFORMAT)
119 errx (1, "krb5_init_context failed to parse configuration file");
120 else if (ret)
121 errx(1, "krb5_init_context failed: %d", ret);
124 * Support linking of kcc to commands
127 if (!command_alias(getprogname())) {
129 if (argc == 1) {
130 sl_slc_help(commands, 0, NULL);
131 return 1;
134 if(getarg(args, sizeof(args) / sizeof(args[0]), argc, argv, &optidx))
135 usage(1);
137 if (help_flag)
138 usage (0);
140 if(version_flag) {
141 print_version(NULL);
142 exit(0);
145 } else {
146 argv[0] = rk_UNCONST(getprogname());
149 argc -= optidx;
150 argv += optidx;
152 if (argc != 0) {
153 ret = sl_command(commands, argc, argv);
154 if(ret == -1)
155 krb5_warnx(kcc_context, "unrecognized command: %s", argv[0]);
156 else if (ret == -2)
157 ret = 0;
158 if(ret != 0)
159 exit_status = 1;
160 } else {
161 sl_slc_help(commands, argc, argv);
162 exit_status = 1;
165 krb5_free_context(kcc_context);
166 return exit_status;