xref: /onnv-gate/usr/src/cmd/krb5/kadmin/ktutil/ktutil_ct.c (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
3*0Sstevel@tonic-gate  * Use is subject to license terms.
4*0Sstevel@tonic-gate  */
5*0Sstevel@tonic-gate 
6*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
7*0Sstevel@tonic-gate 
8*0Sstevel@tonic-gate /*
9*0Sstevel@tonic-gate  * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
10*0Sstevel@tonic-gate  *
11*0Sstevel@tonic-gate  *	Openvision retains the copyright to derivative works of
12*0Sstevel@tonic-gate  *	this source code.  Do *NOT* create a derivative of this
13*0Sstevel@tonic-gate  *	source code before consulting with your legal department.
14*0Sstevel@tonic-gate  *	Do *NOT* integrate *ANY* of this source code into another
15*0Sstevel@tonic-gate  *	product before consulting with your legal department.
16*0Sstevel@tonic-gate  *
17*0Sstevel@tonic-gate  *	For further information, read the top-level Openvision
18*0Sstevel@tonic-gate  *	copyright which is contained in the top-level MIT Kerberos
19*0Sstevel@tonic-gate  *	copyright.
20*0Sstevel@tonic-gate  *
21*0Sstevel@tonic-gate  * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
22*0Sstevel@tonic-gate  *
23*0Sstevel@tonic-gate  */
24*0Sstevel@tonic-gate 
25*0Sstevel@tonic-gate 
26*0Sstevel@tonic-gate /* ktutil_ct.c - automatically generated from ktutil_ct.ct */
27*0Sstevel@tonic-gate /* Above no longer appears to be true */
28*0Sstevel@tonic-gate 
29*0Sstevel@tonic-gate #include <libintl.h>
30*0Sstevel@tonic-gate #include <ss/ss.h>
31*0Sstevel@tonic-gate #include "k5-int.h"
32*0Sstevel@tonic-gate 
33*0Sstevel@tonic-gate /*
34*0Sstevel@tonic-gate  * I18n hack. We sill define gettext(s) to be s here. That way the info_strings
35*0Sstevel@tonic-gate  * will be extracted to the .po file.
36*0Sstevel@tonic-gate  */
37*0Sstevel@tonic-gate 
38*0Sstevel@tonic-gate #define	gettext(s) s
39*0Sstevel@tonic-gate 
40*0Sstevel@tonic-gate #ifndef __STDC__
41*0Sstevel@tonic-gate #define	const
42*0Sstevel@tonic-gate #endif
43*0Sstevel@tonic-gate 
44*0Sstevel@tonic-gate static char const *const ssu00001[] = {
45*0Sstevel@tonic-gate 	"clear_list",
46*0Sstevel@tonic-gate 	"clear",
47*0Sstevel@tonic-gate 	(char const *) 0
48*0Sstevel@tonic-gate };
49*0Sstevel@tonic-gate extern void ktutil_clear_list __SS_PROTO;
50*0Sstevel@tonic-gate static char const *const ssu00002[] = {
51*0Sstevel@tonic-gate 	"read_kt",
52*0Sstevel@tonic-gate 	"rkt",
53*0Sstevel@tonic-gate 	(char const *) 0
54*0Sstevel@tonic-gate };
55*0Sstevel@tonic-gate extern void ktutil_read_v5 __SS_PROTO;
56*0Sstevel@tonic-gate static char const *const ssu00003[] = {
57*0Sstevel@tonic-gate 	"read_st",
58*0Sstevel@tonic-gate 	"rst",
59*0Sstevel@tonic-gate 	(char const *) 0
60*0Sstevel@tonic-gate };
61*0Sstevel@tonic-gate extern void ktutil_read_v4 __SS_PROTO;
62*0Sstevel@tonic-gate static char const *const ssu00004[] = {
63*0Sstevel@tonic-gate 	"write_kt",
64*0Sstevel@tonic-gate 	"wkt",
65*0Sstevel@tonic-gate 	(char const *) 0
66*0Sstevel@tonic-gate };
67*0Sstevel@tonic-gate extern void ktutil_write_v5 __SS_PROTO;
68*0Sstevel@tonic-gate static char const *const ssu00005[] = {
69*0Sstevel@tonic-gate 	"write_st",
70*0Sstevel@tonic-gate 	"wst",
71*0Sstevel@tonic-gate 	(char const *) 0
72*0Sstevel@tonic-gate };
73*0Sstevel@tonic-gate extern void ktutil_write_v4 __SS_PROTO;
74*0Sstevel@tonic-gate static char const *const ssu00006[] = {
75*0Sstevel@tonic-gate 	"add_entry",
76*0Sstevel@tonic-gate 	"addent",
77*0Sstevel@tonic-gate 	(char const *) 0
78*0Sstevel@tonic-gate };
79*0Sstevel@tonic-gate extern void ktutil_add_entry __SS_PROTO;
80*0Sstevel@tonic-gate static char const *const ssu00007[] = {
81*0Sstevel@tonic-gate 	"delete_entry",
82*0Sstevel@tonic-gate 	"delent",
83*0Sstevel@tonic-gate 	(char const *) 0
84*0Sstevel@tonic-gate };
85*0Sstevel@tonic-gate extern void ktutil_delete_entry __SS_PROTO;
86*0Sstevel@tonic-gate static char const *const ssu00008[] = {
87*0Sstevel@tonic-gate 	"list",
88*0Sstevel@tonic-gate 	"l",
89*0Sstevel@tonic-gate 	(char const *) 0
90*0Sstevel@tonic-gate };
91*0Sstevel@tonic-gate extern void ktutil_list __SS_PROTO;
92*0Sstevel@tonic-gate static char const *const ssu00009[] = {
93*0Sstevel@tonic-gate 	"list_requests",
94*0Sstevel@tonic-gate 	"lr",
95*0Sstevel@tonic-gate 	"?",
96*0Sstevel@tonic-gate 	(char const *) 0
97*0Sstevel@tonic-gate };
98*0Sstevel@tonic-gate extern void ss_list_requests __SS_PROTO;
99*0Sstevel@tonic-gate static char const *const ssu00010[] = {
100*0Sstevel@tonic-gate 	"quit",
101*0Sstevel@tonic-gate 	"exit",
102*0Sstevel@tonic-gate 	"q",
103*0Sstevel@tonic-gate 	(char const *) 0
104*0Sstevel@tonic-gate };
105*0Sstevel@tonic-gate extern void ss_quit __SS_PROTO;
106*0Sstevel@tonic-gate static ss_request_entry ssu00011[] = {
107*0Sstevel@tonic-gate 	{ssu00001,
108*0Sstevel@tonic-gate 		ktutil_clear_list,
109*0Sstevel@tonic-gate 		gettext("Clear the current keylist."),
110*0Sstevel@tonic-gate 	0},
111*0Sstevel@tonic-gate 	{ssu00002,
112*0Sstevel@tonic-gate 		ktutil_read_v5,
113*0Sstevel@tonic-gate 		gettext("Read a krb5 keytab into the current keylist."),
114*0Sstevel@tonic-gate 	0},
115*0Sstevel@tonic-gate 	{ssu00003,
116*0Sstevel@tonic-gate 		ktutil_read_v4,
117*0Sstevel@tonic-gate 		gettext("Read a krb4 srvtab into the current keylist."),
118*0Sstevel@tonic-gate 	0},
119*0Sstevel@tonic-gate 	{ssu00004,
120*0Sstevel@tonic-gate 		ktutil_write_v5,
121*0Sstevel@tonic-gate 		gettext("Write the current keylist to a krb5 keytab."),
122*0Sstevel@tonic-gate 	0},
123*0Sstevel@tonic-gate 	{ssu00005,
124*0Sstevel@tonic-gate 		ktutil_write_v4,
125*0Sstevel@tonic-gate 		gettext("Write the current keylist to a krb4 srvtab."),
126*0Sstevel@tonic-gate 	0},
127*0Sstevel@tonic-gate 	{ssu00006,
128*0Sstevel@tonic-gate 		ktutil_add_entry,
129*0Sstevel@tonic-gate 		gettext("Add an entry to the current keylist."),
130*0Sstevel@tonic-gate 	0},
131*0Sstevel@tonic-gate 	{ssu00007,
132*0Sstevel@tonic-gate 		ktutil_delete_entry,
133*0Sstevel@tonic-gate 		gettext("Delete an entry from the current keylist."),
134*0Sstevel@tonic-gate 	0},
135*0Sstevel@tonic-gate 	{ssu00008,
136*0Sstevel@tonic-gate 		ktutil_list,
137*0Sstevel@tonic-gate 		gettext("List the current keylist."),
138*0Sstevel@tonic-gate 	0},
139*0Sstevel@tonic-gate 	{ssu00009,
140*0Sstevel@tonic-gate 		ss_list_requests,
141*0Sstevel@tonic-gate 		gettext("List available requests."),
142*0Sstevel@tonic-gate 	0},
143*0Sstevel@tonic-gate 	{ssu00010,
144*0Sstevel@tonic-gate 		ss_quit,
145*0Sstevel@tonic-gate 		gettext("Exit program."),
146*0Sstevel@tonic-gate 	0},
147*0Sstevel@tonic-gate 	{0, 0, 0, 0}
148*0Sstevel@tonic-gate };
149*0Sstevel@tonic-gate 
150*0Sstevel@tonic-gate ss_request_table ktutil_cmds = {2, ssu00011};
151*0Sstevel@tonic-gate 
152*0Sstevel@tonic-gate #undef gettext
153*0Sstevel@tonic-gate 
154*0Sstevel@tonic-gate /*
155*0Sstevel@tonic-gate  * This routine is responsible for localizing all the displayable
156*0Sstevel@tonic-gate  * messages in the table.  This was necessary since ktutil will be
157*0Sstevel@tonic-gate  * invoking library calls that need to be able to display the messages
158*0Sstevel@tonic-gate  * in the correct text domain (which only ktutil knows).
159*0Sstevel@tonic-gate  *
160*0Sstevel@tonic-gate  * This function assumes that the US version of the messages are
161*0Sstevel@tonic-gate  * pre-loaded in the table and will be used should gettext not be
162*0Sstevel@tonic-gate  * successful.  This routine does NOT free the replaced strings as
163*0Sstevel@tonic-gate  * its expected they may be in the heap (as above) and not malloc'ed.
164*0Sstevel@tonic-gate  * If the caller malloc'ed the strings, they should retain pointers
165*0Sstevel@tonic-gate  * and free them if not matching the contents of the table.
166*0Sstevel@tonic-gate  */
167*0Sstevel@tonic-gate krb5_error_code
168*0Sstevel@tonic-gate ktutil_initialize_cmds_table(ss_request_table *ktutil_cmds)
169*0Sstevel@tonic-gate {
170*0Sstevel@tonic-gate 	char *localized_text;
171*0Sstevel@tonic-gate 	ss_request_entry *ss_cmd;
172*0Sstevel@tonic-gate 	krb5_error_code retval = 0;
173*0Sstevel@tonic-gate 
174*0Sstevel@tonic-gate 	if (ktutil_cmds) {
175*0Sstevel@tonic-gate 		for (ss_cmd = ktutil_cmds->requests;
176*0Sstevel@tonic-gate 		ss_cmd->info_string && *(ss_cmd->info_string) != '\0';
177*0Sstevel@tonic-gate 		++ss_cmd) {
178*0Sstevel@tonic-gate 			localized_text = gettext(ss_cmd->info_string);
179*0Sstevel@tonic-gate 
180*0Sstevel@tonic-gate 			if ((strcmp(localized_text, ss_cmd->info_string))
181*0Sstevel@tonic-gate 				!= 0) {
182*0Sstevel@tonic-gate 				ss_cmd->info_string = strdup(localized_text);
183*0Sstevel@tonic-gate 			}
184*0Sstevel@tonic-gate 		}
185*0Sstevel@tonic-gate 	}
186*0Sstevel@tonic-gate 	else
187*0Sstevel@tonic-gate 		retval = EINVAL;
188*0Sstevel@tonic-gate 
189*0Sstevel@tonic-gate 	return (retval);
190*0Sstevel@tonic-gate }
191