17c478bd9Sstevel@tonic-gate /*
2*56a424ccSmp  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
37c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
47c478bd9Sstevel@tonic-gate  */
57c478bd9Sstevel@tonic-gate 
67c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
77c478bd9Sstevel@tonic-gate 
87c478bd9Sstevel@tonic-gate /*
97c478bd9Sstevel@tonic-gate  * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
107c478bd9Sstevel@tonic-gate  *
117c478bd9Sstevel@tonic-gate  *	Openvision retains the copyright to derivative works of
127c478bd9Sstevel@tonic-gate  *	this source code.  Do *NOT* create a derivative of this
137c478bd9Sstevel@tonic-gate  *	source code before consulting with your legal department.
147c478bd9Sstevel@tonic-gate  *	Do *NOT* integrate *ANY* of this source code into another
157c478bd9Sstevel@tonic-gate  *	product before consulting with your legal department.
167c478bd9Sstevel@tonic-gate  *
177c478bd9Sstevel@tonic-gate  *	For further information, read the top-level Openvision
187c478bd9Sstevel@tonic-gate  *	copyright which is contained in the top-level MIT Kerberos
197c478bd9Sstevel@tonic-gate  *	copyright.
207c478bd9Sstevel@tonic-gate  *
217c478bd9Sstevel@tonic-gate  * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
227c478bd9Sstevel@tonic-gate  *
237c478bd9Sstevel@tonic-gate  */
247c478bd9Sstevel@tonic-gate 
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate /* ktutil_ct.c - automatically generated from ktutil_ct.ct */
277c478bd9Sstevel@tonic-gate /* Above no longer appears to be true */
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #include <libintl.h>
307c478bd9Sstevel@tonic-gate #include <ss/ss.h>
317c478bd9Sstevel@tonic-gate #include "k5-int.h"
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate /*
347c478bd9Sstevel@tonic-gate  * I18n hack. We sill define gettext(s) to be s here. That way the info_strings
357c478bd9Sstevel@tonic-gate  * will be extracted to the .po file.
367c478bd9Sstevel@tonic-gate  */
377c478bd9Sstevel@tonic-gate 
387c478bd9Sstevel@tonic-gate #define	gettext(s) s
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate #ifndef __STDC__
41*56a424ccSmp #define const
427c478bd9Sstevel@tonic-gate #endif
437c478bd9Sstevel@tonic-gate 
44*56a424ccSmp static char const * const ssu00001[] = {
45*56a424ccSmp "clear_list",
46*56a424ccSmp     "clear",
47*56a424ccSmp     (char const *)0
487c478bd9Sstevel@tonic-gate };
497c478bd9Sstevel@tonic-gate extern void ktutil_clear_list __SS_PROTO;
50*56a424ccSmp static char const * const ssu00002[] = {
51*56a424ccSmp "read_kt",
52*56a424ccSmp     "rkt",
53*56a424ccSmp     (char const *)0
547c478bd9Sstevel@tonic-gate };
557c478bd9Sstevel@tonic-gate extern void ktutil_read_v5 __SS_PROTO;
56*56a424ccSmp static char const * const ssu00003[] = {
57*56a424ccSmp "read_st",
58*56a424ccSmp     "rst",
59*56a424ccSmp     (char const *)0
607c478bd9Sstevel@tonic-gate };
617c478bd9Sstevel@tonic-gate extern void ktutil_read_v4 __SS_PROTO;
62*56a424ccSmp static char const * const ssu00004[] = {
63*56a424ccSmp "write_kt",
64*56a424ccSmp     "wkt",
65*56a424ccSmp     (char const *)0
667c478bd9Sstevel@tonic-gate };
677c478bd9Sstevel@tonic-gate extern void ktutil_write_v5 __SS_PROTO;
68*56a424ccSmp static char const * const ssu00005[] = {
69*56a424ccSmp "write_st",
70*56a424ccSmp     "wst",
71*56a424ccSmp     (char const *)0
727c478bd9Sstevel@tonic-gate };
737c478bd9Sstevel@tonic-gate extern void ktutil_write_v4 __SS_PROTO;
74*56a424ccSmp static char const * const ssu00006[] = {
75*56a424ccSmp "add_entry",
76*56a424ccSmp     "addent",
77*56a424ccSmp     (char const *)0
787c478bd9Sstevel@tonic-gate };
797c478bd9Sstevel@tonic-gate extern void ktutil_add_entry __SS_PROTO;
80*56a424ccSmp static char const * const ssu00007[] = {
81*56a424ccSmp "delete_entry",
82*56a424ccSmp     "delent",
83*56a424ccSmp     (char const *)0
847c478bd9Sstevel@tonic-gate };
857c478bd9Sstevel@tonic-gate extern void ktutil_delete_entry __SS_PROTO;
86*56a424ccSmp static char const * const ssu00008[] = {
87*56a424ccSmp "list",
88*56a424ccSmp     "l",
89*56a424ccSmp     (char const *)0
907c478bd9Sstevel@tonic-gate };
917c478bd9Sstevel@tonic-gate extern void ktutil_list __SS_PROTO;
92*56a424ccSmp static char const * const ssu00009[] = {
93*56a424ccSmp "list_requests",
94*56a424ccSmp     "lr",
95*56a424ccSmp     "?",
96*56a424ccSmp     (char const *)0
977c478bd9Sstevel@tonic-gate };
987c478bd9Sstevel@tonic-gate extern void ss_list_requests __SS_PROTO;
99*56a424ccSmp static char const * const ssu00010[] = {
100*56a424ccSmp "quit",
101*56a424ccSmp     "exit",
102*56a424ccSmp     "q",
103*56a424ccSmp     (char const *)0
1047c478bd9Sstevel@tonic-gate };
1057c478bd9Sstevel@tonic-gate extern void ss_quit __SS_PROTO;
1067c478bd9Sstevel@tonic-gate static ss_request_entry ssu00011[] = {
107*56a424ccSmp     { ssu00001,
108*56a424ccSmp       ktutil_clear_list,
1097c478bd9Sstevel@tonic-gate 		gettext("Clear the current keylist."),
110*56a424ccSmp       0 },
111*56a424ccSmp     { ssu00002,
112*56a424ccSmp       ktutil_read_v5,
1137c478bd9Sstevel@tonic-gate 		gettext("Read a krb5 keytab into the current keylist."),
114*56a424ccSmp       0 },
115*56a424ccSmp     { ssu00003,
116*56a424ccSmp       ktutil_read_v4,
1177c478bd9Sstevel@tonic-gate 		gettext("Read a krb4 srvtab into the current keylist."),
118*56a424ccSmp       0 },
119*56a424ccSmp     { ssu00004,
120*56a424ccSmp       ktutil_write_v5,
1217c478bd9Sstevel@tonic-gate 		gettext("Write the current keylist to a krb5 keytab."),
122*56a424ccSmp       0 },
123*56a424ccSmp     { ssu00005,
124*56a424ccSmp       ktutil_write_v4,
1257c478bd9Sstevel@tonic-gate 		gettext("Write the current keylist to a krb4 srvtab."),
126*56a424ccSmp       0 },
127*56a424ccSmp     { ssu00006,
128*56a424ccSmp       ktutil_add_entry,
1297c478bd9Sstevel@tonic-gate 		gettext("Add an entry to the current keylist."),
130*56a424ccSmp       0 },
131*56a424ccSmp     { ssu00007,
132*56a424ccSmp       ktutil_delete_entry,
1337c478bd9Sstevel@tonic-gate 		gettext("Delete an entry from the current keylist."),
134*56a424ccSmp       0 },
135*56a424ccSmp     { ssu00008,
136*56a424ccSmp       ktutil_list,
1377c478bd9Sstevel@tonic-gate 		gettext("List the current keylist."),
138*56a424ccSmp       0 },
139*56a424ccSmp     { ssu00009,
140*56a424ccSmp       ss_list_requests,
1417c478bd9Sstevel@tonic-gate 		gettext("List available requests."),
142*56a424ccSmp       0 },
143*56a424ccSmp     { ssu00010,
144*56a424ccSmp       ss_quit,
1457c478bd9Sstevel@tonic-gate 		gettext("Exit program."),
146*56a424ccSmp       0 },
147*56a424ccSmp     { 0, 0, 0, 0 }
1487c478bd9Sstevel@tonic-gate };
1497c478bd9Sstevel@tonic-gate 
150*56a424ccSmp ss_request_table ktutil_cmds = { 2, ssu00011 };
1517c478bd9Sstevel@tonic-gate 
1527c478bd9Sstevel@tonic-gate #undef gettext
1537c478bd9Sstevel@tonic-gate 
1547c478bd9Sstevel@tonic-gate /*
1557c478bd9Sstevel@tonic-gate  * This routine is responsible for localizing all the displayable
1567c478bd9Sstevel@tonic-gate  * messages in the table.  This was necessary since ktutil will be
1577c478bd9Sstevel@tonic-gate  * invoking library calls that need to be able to display the messages
1587c478bd9Sstevel@tonic-gate  * in the correct text domain (which only ktutil knows).
1597c478bd9Sstevel@tonic-gate  *
1607c478bd9Sstevel@tonic-gate  * This function assumes that the US version of the messages are
1617c478bd9Sstevel@tonic-gate  * pre-loaded in the table and will be used should gettext not be
1627c478bd9Sstevel@tonic-gate  * successful.  This routine does NOT free the replaced strings as
1637c478bd9Sstevel@tonic-gate  * its expected they may be in the heap (as above) and not malloc'ed.
1647c478bd9Sstevel@tonic-gate  * If the caller malloc'ed the strings, they should retain pointers
1657c478bd9Sstevel@tonic-gate  * and free them if not matching the contents of the table.
1667c478bd9Sstevel@tonic-gate  */
1677c478bd9Sstevel@tonic-gate krb5_error_code
ktutil_initialize_cmds_table(ss_request_table * ktutil_cmds)1687c478bd9Sstevel@tonic-gate ktutil_initialize_cmds_table(ss_request_table *ktutil_cmds)
1697c478bd9Sstevel@tonic-gate {
1707c478bd9Sstevel@tonic-gate 	char *localized_text;
1717c478bd9Sstevel@tonic-gate 	ss_request_entry *ss_cmd;
1727c478bd9Sstevel@tonic-gate 	krb5_error_code retval = 0;
1737c478bd9Sstevel@tonic-gate 
1747c478bd9Sstevel@tonic-gate 	if (ktutil_cmds) {
1757c478bd9Sstevel@tonic-gate 		for (ss_cmd = ktutil_cmds->requests;
1767c478bd9Sstevel@tonic-gate 		ss_cmd->info_string && *(ss_cmd->info_string) != '\0';
1777c478bd9Sstevel@tonic-gate 		++ss_cmd) {
1787c478bd9Sstevel@tonic-gate 			localized_text = gettext(ss_cmd->info_string);
1797c478bd9Sstevel@tonic-gate 
1807c478bd9Sstevel@tonic-gate 			if ((strcmp(localized_text, ss_cmd->info_string))
1817c478bd9Sstevel@tonic-gate 				!= 0) {
1827c478bd9Sstevel@tonic-gate 				ss_cmd->info_string = strdup(localized_text);
1837c478bd9Sstevel@tonic-gate 			}
1847c478bd9Sstevel@tonic-gate 		}
1857c478bd9Sstevel@tonic-gate 	}
1867c478bd9Sstevel@tonic-gate 	else
1877c478bd9Sstevel@tonic-gate 		retval = EINVAL;
1887c478bd9Sstevel@tonic-gate 
1897c478bd9Sstevel@tonic-gate 	return (retval);
1907c478bd9Sstevel@tonic-gate }
191