xref: /onnv-gate/usr/src/cmd/cmd-inet/usr.sbin/snoop/snoop_nis.c (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate  * Copyright (c) 1991, 1999 by Sun Microsystems, Inc.
24*0Sstevel@tonic-gate  * All rights reserved.
25*0Sstevel@tonic-gate  */
26*0Sstevel@tonic-gate 
27*0Sstevel@tonic-gate #ident	"%Z%%M%	%I%	%E% SMI"	/* SunOS	*/
28*0Sstevel@tonic-gate 
29*0Sstevel@tonic-gate #include <sys/types.h>
30*0Sstevel@tonic-gate #include <sys/errno.h>
31*0Sstevel@tonic-gate #include <setjmp.h>
32*0Sstevel@tonic-gate #include <string.h>
33*0Sstevel@tonic-gate 
34*0Sstevel@tonic-gate #include <sys/socket.h>
35*0Sstevel@tonic-gate #include <sys/sockio.h>
36*0Sstevel@tonic-gate #include <sys/tiuser.h>
37*0Sstevel@tonic-gate #include <net/if.h>
38*0Sstevel@tonic-gate #include <netinet/in_systm.h>
39*0Sstevel@tonic-gate #include <netinet/in.h>
40*0Sstevel@tonic-gate #include <rpc/types.h>
41*0Sstevel@tonic-gate #include <rpc/xdr.h>
42*0Sstevel@tonic-gate #include <rpc/auth.h>
43*0Sstevel@tonic-gate #include <rpc/clnt.h>
44*0Sstevel@tonic-gate #include <rpc/rpc_msg.h>
45*0Sstevel@tonic-gate #include <rpcsvc/yp_prot.h>
46*0Sstevel@tonic-gate #include "snoop.h"
47*0Sstevel@tonic-gate 
48*0Sstevel@tonic-gate extern char *dlc_header;
49*0Sstevel@tonic-gate extern jmp_buf xdr_err;
50*0Sstevel@tonic-gate char *ypbind_error();
51*0Sstevel@tonic-gate char *sum_ypxfrstat();
52*0Sstevel@tonic-gate char *sum_ypmaplist();
53*0Sstevel@tonic-gate void detail_ypmaplist();
54*0Sstevel@tonic-gate 
55*0Sstevel@tonic-gate static void niscall(int);
56*0Sstevel@tonic-gate static void nisreply(int);
57*0Sstevel@tonic-gate static int detail_ypstat(void);
58*0Sstevel@tonic-gate static int sum_ypstat(char *);
59*0Sstevel@tonic-gate 
60*0Sstevel@tonic-gate /*
61*0Sstevel@tonic-gate  * Defines missing from 5.0 yp_prot.h
62*0Sstevel@tonic-gate  */
63*0Sstevel@tonic-gate #define	YPBINDPROG		((ulong_t)100007)
64*0Sstevel@tonic-gate #define	YPBINDVERS		((ulong_t)2)
65*0Sstevel@tonic-gate #define	YPBINDVERS_ORIG		((ulong_t)1)
66*0Sstevel@tonic-gate 
67*0Sstevel@tonic-gate /* Procedure symbols */
68*0Sstevel@tonic-gate 
69*0Sstevel@tonic-gate #define	YPBINDPROC_NULL		((ulong_t)0)
70*0Sstevel@tonic-gate #define	YPBINDPROC_DOMAIN	((ulong_t)1)
71*0Sstevel@tonic-gate #define	YPBINDPROC_SETDOM	((ulong_t)2)
72*0Sstevel@tonic-gate 
73*0Sstevel@tonic-gate #define	YPBIND_ERR_ERR 1		/* Internal error */
74*0Sstevel@tonic-gate #define	YPBIND_ERR_NOSERV 2		/* No bound server for passed domain */
75*0Sstevel@tonic-gate #define	YPBIND_ERR_RESC 3		/* System resource allocation failure */
76*0Sstevel@tonic-gate 
77*0Sstevel@tonic-gate 
78*0Sstevel@tonic-gate static char *procnames_bind_short[] = {
79*0Sstevel@tonic-gate 	"NULL",			/*  0 */
80*0Sstevel@tonic-gate 	"DOMAIN",		/*  1 */
81*0Sstevel@tonic-gate 	"SETDOMAIN",		/*  2 */
82*0Sstevel@tonic-gate };
83*0Sstevel@tonic-gate 
84*0Sstevel@tonic-gate static char *procnames_bind_long[] = {
85*0Sstevel@tonic-gate 	"Null procedure",		/*  0 */
86*0Sstevel@tonic-gate 	"Get domain name",		/*  1 */
87*0Sstevel@tonic-gate 	"Set domain name",		/*  2 */
88*0Sstevel@tonic-gate };
89*0Sstevel@tonic-gate 
90*0Sstevel@tonic-gate static char *procnames_short[] = {
91*0Sstevel@tonic-gate 	"NULL",			/*  0 */
92*0Sstevel@tonic-gate 	"DOMAIN",		/*  1 */
93*0Sstevel@tonic-gate 	"DOMAIN_NONACK",	/*  2 */
94*0Sstevel@tonic-gate 	"MATCH",		/*  3 */
95*0Sstevel@tonic-gate 	"FIRST",		/*  4 */
96*0Sstevel@tonic-gate 	"NEXT",			/*  5 */
97*0Sstevel@tonic-gate 	"XFR",			/*  6 */
98*0Sstevel@tonic-gate 	"CLEAR",		/*  7 */
99*0Sstevel@tonic-gate 	"ALL",			/*  8 */
100*0Sstevel@tonic-gate 	"MASTER",		/*  9 */
101*0Sstevel@tonic-gate 	"ORDER",		/* 10 */
102*0Sstevel@tonic-gate 	"MAPLIST",		/* 11 */
103*0Sstevel@tonic-gate 	"NEWXFR",		/* 12 */
104*0Sstevel@tonic-gate };
105*0Sstevel@tonic-gate 
106*0Sstevel@tonic-gate #define	MAXPROC_BIND	2
107*0Sstevel@tonic-gate #define	MAXPROC		12
108*0Sstevel@tonic-gate 
109*0Sstevel@tonic-gate static char *procnames_long[] = {
110*0Sstevel@tonic-gate 	"Null procedure",			/*  0 */
111*0Sstevel@tonic-gate 	"Verify domain support",		/*  1 */
112*0Sstevel@tonic-gate 	"Verify domain support (broadcast)",	/*  2 */
113*0Sstevel@tonic-gate 	"Return value of a key",		/*  3 */
114*0Sstevel@tonic-gate 	"Return first key-value pair in map",	/*  4 */
115*0Sstevel@tonic-gate 	"Return next key-value pair in map",	/*  5 */
116*0Sstevel@tonic-gate 	"Request map update (old)",		/*  6 */
117*0Sstevel@tonic-gate 	"Close current map on server",		/*  7 */
118*0Sstevel@tonic-gate 	"Get all key-value pairs in map",	/*  8 */
119*0Sstevel@tonic-gate 	"Get master server",			/*  9 */
120*0Sstevel@tonic-gate 	"Get order",				/* 10 */
121*0Sstevel@tonic-gate 	"Return list of supported maps",	/* 11 */
122*0Sstevel@tonic-gate 	"Request map update",			/* 12 */
123*0Sstevel@tonic-gate };
124*0Sstevel@tonic-gate 
125*0Sstevel@tonic-gate void
interpret_nisbind(flags,type,xid,vers,proc,data,len)126*0Sstevel@tonic-gate interpret_nisbind(flags, type, xid, vers, proc, data, len)
127*0Sstevel@tonic-gate 	int flags, type, xid, vers, proc;
128*0Sstevel@tonic-gate 	char *data;
129*0Sstevel@tonic-gate 	int len;
130*0Sstevel@tonic-gate {
131*0Sstevel@tonic-gate 	char *line;
132*0Sstevel@tonic-gate 	char buff[YPMAXDOMAIN + 1];
133*0Sstevel@tonic-gate 	unsigned int status;
134*0Sstevel@tonic-gate 
135*0Sstevel@tonic-gate 	if (proc < 0 || proc > MAXPROC_BIND)
136*0Sstevel@tonic-gate 		return;
137*0Sstevel@tonic-gate 
138*0Sstevel@tonic-gate 	if (flags & F_SUM) {
139*0Sstevel@tonic-gate 		if (setjmp(xdr_err)) {
140*0Sstevel@tonic-gate 			return;
141*0Sstevel@tonic-gate 		}
142*0Sstevel@tonic-gate 
143*0Sstevel@tonic-gate 		line = get_sum_line();
144*0Sstevel@tonic-gate 
145*0Sstevel@tonic-gate 		if (type == CALL) {
146*0Sstevel@tonic-gate 			(void) sprintf(line,
147*0Sstevel@tonic-gate 				"NISBIND C %s",
148*0Sstevel@tonic-gate 				procnames_bind_short[proc]);
149*0Sstevel@tonic-gate 			line += strlen(line);
150*0Sstevel@tonic-gate 			switch (proc) {
151*0Sstevel@tonic-gate 			case YPBINDPROC_NULL:
152*0Sstevel@tonic-gate 				break;
153*0Sstevel@tonic-gate 			case YPBINDPROC_DOMAIN:
154*0Sstevel@tonic-gate 				(void) sprintf(line, " %s",
155*0Sstevel@tonic-gate 					getxdr_string(buff, YPMAXDOMAIN));
156*0Sstevel@tonic-gate 				break;
157*0Sstevel@tonic-gate 			case YPBINDPROC_SETDOM:
158*0Sstevel@tonic-gate 				(void) sprintf(line, " %s",
159*0Sstevel@tonic-gate 					getxdr_string(buff, YPMAXDOMAIN));
160*0Sstevel@tonic-gate 				break;
161*0Sstevel@tonic-gate 			default:
162*0Sstevel@tonic-gate 				break;
163*0Sstevel@tonic-gate 			}
164*0Sstevel@tonic-gate 			check_retransmit(line, xid);
165*0Sstevel@tonic-gate 		} else {
166*0Sstevel@tonic-gate 			(void) sprintf(line, "NISBIND R %s ",
167*0Sstevel@tonic-gate 				procnames_bind_short[proc]);
168*0Sstevel@tonic-gate 			line += strlen(line);
169*0Sstevel@tonic-gate 			switch (proc) {
170*0Sstevel@tonic-gate 			case YPBINDPROC_NULL:
171*0Sstevel@tonic-gate 				break;
172*0Sstevel@tonic-gate 			case YPBINDPROC_DOMAIN:
173*0Sstevel@tonic-gate 				status = getxdr_long();
174*0Sstevel@tonic-gate 				if (status == 1) {	/* success */
175*0Sstevel@tonic-gate 					(void) strcat(line, "OK");
176*0Sstevel@tonic-gate 				} else {		/* failure */
177*0Sstevel@tonic-gate 					status = getxdr_long();
178*0Sstevel@tonic-gate 					(void) sprintf(line, "ERROR=%s",
179*0Sstevel@tonic-gate 						ypbind_error(status));
180*0Sstevel@tonic-gate 				}
181*0Sstevel@tonic-gate 				break;
182*0Sstevel@tonic-gate 			case YPBINDPROC_SETDOM:
183*0Sstevel@tonic-gate 				break;
184*0Sstevel@tonic-gate 			default:
185*0Sstevel@tonic-gate 				break;
186*0Sstevel@tonic-gate 			}
187*0Sstevel@tonic-gate 		}
188*0Sstevel@tonic-gate 	}
189*0Sstevel@tonic-gate 
190*0Sstevel@tonic-gate 	if (flags & F_DTAIL) {
191*0Sstevel@tonic-gate 		show_header("NISBIND:",
192*0Sstevel@tonic-gate 			"Network Information Service Bind", len);
193*0Sstevel@tonic-gate 		show_space();
194*0Sstevel@tonic-gate 		if (setjmp(xdr_err)) {
195*0Sstevel@tonic-gate 			return;
196*0Sstevel@tonic-gate 		}
197*0Sstevel@tonic-gate 		(void) sprintf(get_line(0, 0),
198*0Sstevel@tonic-gate 			"Proc = %d (%s)",
199*0Sstevel@tonic-gate 			proc, procnames_bind_long[proc]);
200*0Sstevel@tonic-gate 		if (type == CALL) {
201*0Sstevel@tonic-gate 			switch (proc) {
202*0Sstevel@tonic-gate 			case YPBINDPROC_NULL:
203*0Sstevel@tonic-gate 				break;
204*0Sstevel@tonic-gate 			case YPBINDPROC_DOMAIN:
205*0Sstevel@tonic-gate 				(void) showxdr_string(YPMAXDOMAIN,
206*0Sstevel@tonic-gate 					"Domain = %s");
207*0Sstevel@tonic-gate 				break;
208*0Sstevel@tonic-gate 			case YPBINDPROC_SETDOM:
209*0Sstevel@tonic-gate 				(void) showxdr_string(YPMAXDOMAIN,
210*0Sstevel@tonic-gate 					"Domain = %s");
211*0Sstevel@tonic-gate 				(void) showxdr_hex(4, "Address=%s");
212*0Sstevel@tonic-gate 				(void) showxdr_hex(2, "Port=%s");
213*0Sstevel@tonic-gate 				(void) showxdr_u_long("Version=%lu");
214*0Sstevel@tonic-gate 				break;
215*0Sstevel@tonic-gate 			default:
216*0Sstevel@tonic-gate 				break;
217*0Sstevel@tonic-gate 			}
218*0Sstevel@tonic-gate 		} else {
219*0Sstevel@tonic-gate 			switch (proc) {
220*0Sstevel@tonic-gate 			case YPBINDPROC_NULL:
221*0Sstevel@tonic-gate 				break;
222*0Sstevel@tonic-gate 			case YPBINDPROC_DOMAIN:
223*0Sstevel@tonic-gate 				status = getxdr_u_long();
224*0Sstevel@tonic-gate 				(void) sprintf(get_line(0, 0),
225*0Sstevel@tonic-gate 					"Status = %lu (%s)",
226*0Sstevel@tonic-gate 					status,
227*0Sstevel@tonic-gate 					status == 1 ? "OK":"Fail");
228*0Sstevel@tonic-gate 				if (status == 1) {
229*0Sstevel@tonic-gate 					(void) showxdr_hex(4,
230*0Sstevel@tonic-gate 						"Address=%s");
231*0Sstevel@tonic-gate 					(void) showxdr_hex(2,
232*0Sstevel@tonic-gate 						"Port=%s");
233*0Sstevel@tonic-gate 				} else {
234*0Sstevel@tonic-gate 					status = getxdr_u_long();
235*0Sstevel@tonic-gate 					(void) sprintf(get_line(0, 0),
236*0Sstevel@tonic-gate 						"Error = %lu (%s)",
237*0Sstevel@tonic-gate 						status,
238*0Sstevel@tonic-gate 						ypbind_error(status));
239*0Sstevel@tonic-gate 				}
240*0Sstevel@tonic-gate 				break;
241*0Sstevel@tonic-gate 			case YPBINDPROC_SETDOM:
242*0Sstevel@tonic-gate 				break;
243*0Sstevel@tonic-gate 			default:
244*0Sstevel@tonic-gate 				break;
245*0Sstevel@tonic-gate 			}
246*0Sstevel@tonic-gate 		}
247*0Sstevel@tonic-gate 		show_trailer();
248*0Sstevel@tonic-gate 	}
249*0Sstevel@tonic-gate }
250*0Sstevel@tonic-gate 
251*0Sstevel@tonic-gate void
interpret_nis(flags,type,xid,vers,proc,data,len)252*0Sstevel@tonic-gate interpret_nis(flags, type, xid, vers, proc, data, len)
253*0Sstevel@tonic-gate 	int flags, type, xid, vers, proc;
254*0Sstevel@tonic-gate 	char *data;
255*0Sstevel@tonic-gate 	int len;
256*0Sstevel@tonic-gate {
257*0Sstevel@tonic-gate 	char *line;
258*0Sstevel@tonic-gate 	char *dom, *map, *key;
259*0Sstevel@tonic-gate 	int transid, status;
260*0Sstevel@tonic-gate 	/* buffers are all the same size so we don't have to keep track */
261*0Sstevel@tonic-gate 	char buff1[YPMAXRECORD + 1], buff2[YPMAXRECORD + 1];
262*0Sstevel@tonic-gate 	char buff3[YPMAXRECORD + 1];
263*0Sstevel@tonic-gate 
264*0Sstevel@tonic-gate 	if (flags & F_SUM) {
265*0Sstevel@tonic-gate 		if (setjmp(xdr_err)) {
266*0Sstevel@tonic-gate 			return;
267*0Sstevel@tonic-gate 		}
268*0Sstevel@tonic-gate 
269*0Sstevel@tonic-gate 		line = get_sum_line();
270*0Sstevel@tonic-gate 
271*0Sstevel@tonic-gate 		if (type == CALL) {
272*0Sstevel@tonic-gate 			if (proc > MAXPROC)
273*0Sstevel@tonic-gate 				(void) sprintf(line, "NIS C %d", proc);
274*0Sstevel@tonic-gate 			else
275*0Sstevel@tonic-gate 				(void) sprintf(line,
276*0Sstevel@tonic-gate 					"NIS C %s",
277*0Sstevel@tonic-gate 					procnames_short[proc]);
278*0Sstevel@tonic-gate 			line += strlen(line);
279*0Sstevel@tonic-gate 			switch (proc) {
280*0Sstevel@tonic-gate 			case YPPROC_NULL:
281*0Sstevel@tonic-gate 				break;
282*0Sstevel@tonic-gate 			case YPPROC_DOMAIN:
283*0Sstevel@tonic-gate 			case YPPROC_DOMAIN_NONACK:
284*0Sstevel@tonic-gate 			case YPPROC_MAPLIST:
285*0Sstevel@tonic-gate 				/* YPMAXDOMAIN > YPMAXMAP */
286*0Sstevel@tonic-gate 				(void) sprintf(line, " %s",
287*0Sstevel@tonic-gate 					getxdr_string(buff1, YPMAXDOMAIN));
288*0Sstevel@tonic-gate 				break;
289*0Sstevel@tonic-gate 			case YPPROC_FIRST:
290*0Sstevel@tonic-gate 				dom = getxdr_string(buff1, YPMAXDOMAIN);
291*0Sstevel@tonic-gate 				map = getxdr_string(buff2, YPMAXMAP);
292*0Sstevel@tonic-gate 				(void) sprintf(line, " %s", map);
293*0Sstevel@tonic-gate 				break;
294*0Sstevel@tonic-gate 			case YPPROC_MATCH:
295*0Sstevel@tonic-gate 			case YPPROC_NEXT:
296*0Sstevel@tonic-gate 				dom = getxdr_string(buff1, YPMAXDOMAIN);
297*0Sstevel@tonic-gate 				map = getxdr_string(buff2, YPMAXMAP);
298*0Sstevel@tonic-gate 				key = getxdr_string(buff3, YPMAXRECORD);
299*0Sstevel@tonic-gate 				(void) sprintf(line,
300*0Sstevel@tonic-gate 					" %s in %s",
301*0Sstevel@tonic-gate 					key, map);
302*0Sstevel@tonic-gate 				break;
303*0Sstevel@tonic-gate 			case YPPROC_NEWXFR:
304*0Sstevel@tonic-gate 			case YPPROC_XFR:
305*0Sstevel@tonic-gate 				dom = getxdr_string(buff1, YPMAXDOMAIN);
306*0Sstevel@tonic-gate 				map = getxdr_string(buff2, YPMAXMAP);
307*0Sstevel@tonic-gate 				(void) sprintf(line,
308*0Sstevel@tonic-gate 					" map %s in %s",
309*0Sstevel@tonic-gate 					map, dom);
310*0Sstevel@tonic-gate 				break;
311*0Sstevel@tonic-gate 			case YPPROC_CLEAR:
312*0Sstevel@tonic-gate 				break;
313*0Sstevel@tonic-gate 			case YPPROC_ALL:
314*0Sstevel@tonic-gate 			case YPPROC_MASTER:
315*0Sstevel@tonic-gate 			case YPPROC_ORDER:
316*0Sstevel@tonic-gate 				dom = getxdr_string(buff1, YPMAXDOMAIN);
317*0Sstevel@tonic-gate 				map = getxdr_string(buff2, YPMAXMAP);
318*0Sstevel@tonic-gate 				(void) sprintf(line,
319*0Sstevel@tonic-gate 					" map %s in %s",
320*0Sstevel@tonic-gate 					map, dom);
321*0Sstevel@tonic-gate 				break;
322*0Sstevel@tonic-gate 			default:
323*0Sstevel@tonic-gate 				break;
324*0Sstevel@tonic-gate 			}
325*0Sstevel@tonic-gate 			check_retransmit(line, xid);
326*0Sstevel@tonic-gate 		} else {
327*0Sstevel@tonic-gate 			if (proc > MAXPROC)
328*0Sstevel@tonic-gate 				(void) sprintf(line, "NIS R %d ", proc);
329*0Sstevel@tonic-gate 			else
330*0Sstevel@tonic-gate 				(void) sprintf(line, "NIS R %s ",
331*0Sstevel@tonic-gate 					procnames_short[proc]);
332*0Sstevel@tonic-gate 			line += strlen(line);
333*0Sstevel@tonic-gate 			switch (proc) {
334*0Sstevel@tonic-gate 			case YPPROC_NULL:
335*0Sstevel@tonic-gate 				break;
336*0Sstevel@tonic-gate 			case YPPROC_DOMAIN:
337*0Sstevel@tonic-gate 			case YPPROC_DOMAIN_NONACK:
338*0Sstevel@tonic-gate 				(void) sprintf(line, "%s",
339*0Sstevel@tonic-gate 					getxdr_long() ? "OK":"Fail");
340*0Sstevel@tonic-gate 				break;
341*0Sstevel@tonic-gate 			case YPPROC_MATCH:
342*0Sstevel@tonic-gate 				(void) sum_ypstat(line);
343*0Sstevel@tonic-gate 				break;
344*0Sstevel@tonic-gate 			case YPPROC_FIRST:
345*0Sstevel@tonic-gate 			case YPPROC_NEXT:
346*0Sstevel@tonic-gate 				if (sum_ypstat(line) == YP_TRUE) {
347*0Sstevel@tonic-gate 					line += strlen(line);
348*0Sstevel@tonic-gate 					(void) getxdr_string(buff1,
349*0Sstevel@tonic-gate 							YPMAXRECORD);
350*0Sstevel@tonic-gate 					(void) sprintf(line, " key=%s",
351*0Sstevel@tonic-gate 						getxdr_string(buff1,
352*0Sstevel@tonic-gate 							YPMAXRECORD));
353*0Sstevel@tonic-gate 				}
354*0Sstevel@tonic-gate 				break;
355*0Sstevel@tonic-gate 			case YPPROC_NEWXFR:
356*0Sstevel@tonic-gate 			case YPPROC_XFR:
357*0Sstevel@tonic-gate 				transid = getxdr_u_long();
358*0Sstevel@tonic-gate 				status  = getxdr_long();
359*0Sstevel@tonic-gate 				(void) sprintf(line, "transid=%lu %s",
360*0Sstevel@tonic-gate 					transid,
361*0Sstevel@tonic-gate 					sum_ypxfrstat(status));
362*0Sstevel@tonic-gate 				break;
363*0Sstevel@tonic-gate 			case YPPROC_CLEAR:
364*0Sstevel@tonic-gate 				break;
365*0Sstevel@tonic-gate 			case YPPROC_ALL:
366*0Sstevel@tonic-gate 				if (getxdr_u_long()) {
367*0Sstevel@tonic-gate 					(void) sum_ypstat(line);
368*0Sstevel@tonic-gate 					line += strlen(line);
369*0Sstevel@tonic-gate 					(void) sprintf(line, " key=%s",
370*0Sstevel@tonic-gate 					    getxdr_string(buff1, YPMAXRECORD));
371*0Sstevel@tonic-gate 				} else {
372*0Sstevel@tonic-gate 					(void) sprintf(line,
373*0Sstevel@tonic-gate 						"No more");
374*0Sstevel@tonic-gate 				}
375*0Sstevel@tonic-gate 				break;
376*0Sstevel@tonic-gate 			case YPPROC_MASTER:
377*0Sstevel@tonic-gate 				if (sum_ypstat(line) == YP_TRUE) {
378*0Sstevel@tonic-gate 					line += strlen(line);
379*0Sstevel@tonic-gate 					(void) sprintf(line, " peer=%s",
380*0Sstevel@tonic-gate 						getxdr_string(buff1,
381*0Sstevel@tonic-gate 							YPMAXPEER));
382*0Sstevel@tonic-gate 				}
383*0Sstevel@tonic-gate 				break;
384*0Sstevel@tonic-gate 			case YPPROC_ORDER:
385*0Sstevel@tonic-gate 				if (sum_ypstat(line) == YP_TRUE) {
386*0Sstevel@tonic-gate 					line += strlen(line);
387*0Sstevel@tonic-gate 					(void) sprintf(line, " order=%lu",
388*0Sstevel@tonic-gate 						getxdr_u_long());
389*0Sstevel@tonic-gate 				}
390*0Sstevel@tonic-gate 				break;
391*0Sstevel@tonic-gate 			case YPPROC_MAPLIST:
392*0Sstevel@tonic-gate 				if (sum_ypstat(line) == YP_TRUE) {
393*0Sstevel@tonic-gate 					line += strlen(line);
394*0Sstevel@tonic-gate 					(void) sprintf(line, " %s",
395*0Sstevel@tonic-gate 						sum_ypmaplist());
396*0Sstevel@tonic-gate 				}
397*0Sstevel@tonic-gate 				break;
398*0Sstevel@tonic-gate 			default:
399*0Sstevel@tonic-gate 				break;
400*0Sstevel@tonic-gate 			}
401*0Sstevel@tonic-gate 		}
402*0Sstevel@tonic-gate 	}
403*0Sstevel@tonic-gate 
404*0Sstevel@tonic-gate 	if (flags & F_DTAIL) {
405*0Sstevel@tonic-gate 		show_header("NIS:  ", "Network Information Service", len);
406*0Sstevel@tonic-gate 		show_space();
407*0Sstevel@tonic-gate 		if (setjmp(xdr_err)) {
408*0Sstevel@tonic-gate 			return;
409*0Sstevel@tonic-gate 		}
410*0Sstevel@tonic-gate 		(void) sprintf(get_line(0, 0),
411*0Sstevel@tonic-gate 			"Proc = %d (%s)",
412*0Sstevel@tonic-gate 			proc,
413*0Sstevel@tonic-gate 			proc > MAXPROC ? "unknown" : procnames_long[proc]);
414*0Sstevel@tonic-gate 		if (type == CALL)
415*0Sstevel@tonic-gate 			niscall(proc);
416*0Sstevel@tonic-gate 		else
417*0Sstevel@tonic-gate 			nisreply(proc);
418*0Sstevel@tonic-gate 		show_trailer();
419*0Sstevel@tonic-gate 	}
420*0Sstevel@tonic-gate }
421*0Sstevel@tonic-gate 
422*0Sstevel@tonic-gate /*
423*0Sstevel@tonic-gate  *  Print out version 2 NIS call packets
424*0Sstevel@tonic-gate  */
425*0Sstevel@tonic-gate 
426*0Sstevel@tonic-gate static void
niscall(proc)427*0Sstevel@tonic-gate niscall(proc)
428*0Sstevel@tonic-gate 	int proc;
429*0Sstevel@tonic-gate {
430*0Sstevel@tonic-gate 	switch (proc) {
431*0Sstevel@tonic-gate 	case YPPROC_NULL:
432*0Sstevel@tonic-gate 		break;
433*0Sstevel@tonic-gate 	case YPPROC_DOMAIN:
434*0Sstevel@tonic-gate 	case YPPROC_DOMAIN_NONACK:
435*0Sstevel@tonic-gate 	case YPPROC_MAPLIST:
436*0Sstevel@tonic-gate 		(void) showxdr_string(YPMAXDOMAIN, "Domain = %s");
437*0Sstevel@tonic-gate 		break;
438*0Sstevel@tonic-gate 	case YPPROC_FIRST:
439*0Sstevel@tonic-gate 		(void) showxdr_string(YPMAXDOMAIN, "Domain = %s");
440*0Sstevel@tonic-gate 		(void) showxdr_string(YPMAXMAP, "Map = %s");
441*0Sstevel@tonic-gate 		break;
442*0Sstevel@tonic-gate 	case YPPROC_MATCH:
443*0Sstevel@tonic-gate 	case YPPROC_NEXT:
444*0Sstevel@tonic-gate 		(void) showxdr_string(YPMAXDOMAIN, "Domain = %s");
445*0Sstevel@tonic-gate 		(void) showxdr_string(YPMAXMAP, "Map = %s");
446*0Sstevel@tonic-gate 		(void) showxdr_string(YPMAXRECORD, "Key = %s");
447*0Sstevel@tonic-gate 		break;
448*0Sstevel@tonic-gate 	case YPPROC_NEWXFR:
449*0Sstevel@tonic-gate 		(void) showxdr_string(YPMAXDOMAIN, "Domain = %s");
450*0Sstevel@tonic-gate 		(void) showxdr_string(YPMAXMAP, "Map = %s");
451*0Sstevel@tonic-gate 		(void) showxdr_u_long("Order = %lu");
452*0Sstevel@tonic-gate 		(void) showxdr_string(YPMAXPEER, "Peer = %s");
453*0Sstevel@tonic-gate 		(void) showxdr_u_long("Transid = %lu");
454*0Sstevel@tonic-gate 		(void) showxdr_u_long("Prog = %lu");
455*0Sstevel@tonic-gate 		(void) showxdr_string(YPMAXPEER, "Name = %s");
456*0Sstevel@tonic-gate 		break;
457*0Sstevel@tonic-gate 	case YPPROC_XFR:
458*0Sstevel@tonic-gate 		(void) showxdr_string(YPMAXDOMAIN, "Domain = %s");
459*0Sstevel@tonic-gate 		(void) showxdr_string(YPMAXMAP, "Map = %s");
460*0Sstevel@tonic-gate 		(void) showxdr_u_long("Order = %lu");
461*0Sstevel@tonic-gate 		(void) showxdr_string(YPMAXPEER, "Peer = %s");
462*0Sstevel@tonic-gate 		(void) showxdr_u_long("Transid = %lu");
463*0Sstevel@tonic-gate 		(void) showxdr_u_long("Prog = %lu");
464*0Sstevel@tonic-gate 		(void) showxdr_u_long("Port = %lu");
465*0Sstevel@tonic-gate 		break;
466*0Sstevel@tonic-gate 	case YPPROC_CLEAR:
467*0Sstevel@tonic-gate 		break;
468*0Sstevel@tonic-gate 	case YPPROC_ALL:
469*0Sstevel@tonic-gate 	case YPPROC_MASTER:
470*0Sstevel@tonic-gate 	case YPPROC_ORDER:
471*0Sstevel@tonic-gate 		(void) showxdr_string(YPMAXDOMAIN, "Domain = %s");
472*0Sstevel@tonic-gate 		(void) showxdr_string(YPMAXMAP, "Map = %s");
473*0Sstevel@tonic-gate 		break;
474*0Sstevel@tonic-gate 	default:
475*0Sstevel@tonic-gate 		break;
476*0Sstevel@tonic-gate 	}
477*0Sstevel@tonic-gate }
478*0Sstevel@tonic-gate 
479*0Sstevel@tonic-gate /*
480*0Sstevel@tonic-gate  *  Print out version 2 NIS reply packets
481*0Sstevel@tonic-gate  */
482*0Sstevel@tonic-gate 
483*0Sstevel@tonic-gate void
nisreply(proc)484*0Sstevel@tonic-gate nisreply(proc)
485*0Sstevel@tonic-gate 	int proc;
486*0Sstevel@tonic-gate {
487*0Sstevel@tonic-gate 	unsigned int xfrstat, more;
488*0Sstevel@tonic-gate 
489*0Sstevel@tonic-gate 	switch (proc) {
490*0Sstevel@tonic-gate 	case YPPROC_NULL:
491*0Sstevel@tonic-gate 		break;
492*0Sstevel@tonic-gate 	case YPPROC_DOMAIN:
493*0Sstevel@tonic-gate 	case YPPROC_DOMAIN_NONACK:
494*0Sstevel@tonic-gate 		(void) sprintf(get_line(0, 0),
495*0Sstevel@tonic-gate 			"Result=%s",
496*0Sstevel@tonic-gate 			getxdr_u_long() ? "OK":"Fail");
497*0Sstevel@tonic-gate 		break;
498*0Sstevel@tonic-gate 	case YPPROC_MATCH:
499*0Sstevel@tonic-gate 		(void) detail_ypstat();
500*0Sstevel@tonic-gate 		(void) showxdr_string(YPMAXRECORD, "Value = %s");
501*0Sstevel@tonic-gate 		break;
502*0Sstevel@tonic-gate 	case YPPROC_FIRST:
503*0Sstevel@tonic-gate 	case YPPROC_NEXT:
504*0Sstevel@tonic-gate 		(void) detail_ypstat();
505*0Sstevel@tonic-gate 		(void) showxdr_string(YPMAXRECORD, "Value = %s");
506*0Sstevel@tonic-gate 		(void) showxdr_string(YPMAXRECORD, "Key = %s");
507*0Sstevel@tonic-gate 		break;
508*0Sstevel@tonic-gate 	case YPPROC_NEWXFR:
509*0Sstevel@tonic-gate 	case YPPROC_XFR:
510*0Sstevel@tonic-gate 		(void) showxdr_u_long("Transid = %lu");
511*0Sstevel@tonic-gate 		xfrstat = getxdr_u_long();
512*0Sstevel@tonic-gate 		(void) sprintf(get_line(0, 0),
513*0Sstevel@tonic-gate 			"Transfer status = %lu (%s)",
514*0Sstevel@tonic-gate 			xfrstat, sum_ypxfrstat(xfrstat));
515*0Sstevel@tonic-gate 		break;
516*0Sstevel@tonic-gate 	case YPPROC_CLEAR:
517*0Sstevel@tonic-gate 		break;
518*0Sstevel@tonic-gate 	case YPPROC_ALL:
519*0Sstevel@tonic-gate 		more = getxdr_u_long();
520*0Sstevel@tonic-gate 		(void) sprintf(get_line(0, 0),
521*0Sstevel@tonic-gate 			"More = %s",
522*0Sstevel@tonic-gate 			more ? "true" : "false");
523*0Sstevel@tonic-gate 		if (more) {
524*0Sstevel@tonic-gate 			(void) detail_ypstat();
525*0Sstevel@tonic-gate 			(void) showxdr_string(YPMAXRECORD, "Value = %s");
526*0Sstevel@tonic-gate 			(void) showxdr_string(YPMAXRECORD, "Key = %s");
527*0Sstevel@tonic-gate 		}
528*0Sstevel@tonic-gate 		break;
529*0Sstevel@tonic-gate 	case YPPROC_MASTER:
530*0Sstevel@tonic-gate 		(void) detail_ypstat();
531*0Sstevel@tonic-gate 		(void) showxdr_string(YPMAXPEER, "Peer = %s");
532*0Sstevel@tonic-gate 	case YPPROC_ORDER:
533*0Sstevel@tonic-gate 		(void) detail_ypstat();
534*0Sstevel@tonic-gate 		(void) showxdr_u_long("Order=%lu");
535*0Sstevel@tonic-gate 		break;
536*0Sstevel@tonic-gate 	case YPPROC_MAPLIST:
537*0Sstevel@tonic-gate 		(void) detail_ypstat();
538*0Sstevel@tonic-gate 		detail_ypmaplist();
539*0Sstevel@tonic-gate 		break;
540*0Sstevel@tonic-gate 	default:
541*0Sstevel@tonic-gate 		break;
542*0Sstevel@tonic-gate 	}
543*0Sstevel@tonic-gate }
544*0Sstevel@tonic-gate 
545*0Sstevel@tonic-gate char *
sum_ypxfrstat(status)546*0Sstevel@tonic-gate sum_ypxfrstat(status)
547*0Sstevel@tonic-gate 	int status;
548*0Sstevel@tonic-gate {
549*0Sstevel@tonic-gate 	static char buff [16];
550*0Sstevel@tonic-gate 
551*0Sstevel@tonic-gate 	switch (status) {
552*0Sstevel@tonic-gate 	case   1:	return ("Success");
553*0Sstevel@tonic-gate 	case   2:	return ("Master's version not newer");
554*0Sstevel@tonic-gate 	case  -1:	return ("Can't find server for map");
555*0Sstevel@tonic-gate 	case  -2:	return ("No such domain");
556*0Sstevel@tonic-gate 	case  -3:	return ("Resource allocation failure");
557*0Sstevel@tonic-gate 	case  -4:	return ("RPC failure talking to server");
558*0Sstevel@tonic-gate 	case  -5:	return ("Can't get master address");
559*0Sstevel@tonic-gate 	case  -6:	return ("NIS server/map db error");
560*0Sstevel@tonic-gate 	case  -7:	return ("Bad arguments");
561*0Sstevel@tonic-gate 	case  -8:	return ("Local dbm operation failed");
562*0Sstevel@tonic-gate 	case  -9:	return ("Local file I/O operation failed");
563*0Sstevel@tonic-gate 	case -10:	return ("Map version skew during transfer");
564*0Sstevel@tonic-gate 	case -11:	return ("Can't send clear req to local ypserv");
565*0Sstevel@tonic-gate 	case -12:	return ("No local order number in map");
566*0Sstevel@tonic-gate 	case -13:	return ("Transfer error");
567*0Sstevel@tonic-gate 	case -14:	return ("Transfer request refused");
568*0Sstevel@tonic-gate 	default:
569*0Sstevel@tonic-gate 		(void) sprintf(buff, "(%d)", status);
570*0Sstevel@tonic-gate 		return (buff);
571*0Sstevel@tonic-gate 	}
572*0Sstevel@tonic-gate 	/* NOTREACHED */
573*0Sstevel@tonic-gate }
574*0Sstevel@tonic-gate 
575*0Sstevel@tonic-gate static int
sum_ypstat(line)576*0Sstevel@tonic-gate sum_ypstat(line)
577*0Sstevel@tonic-gate 	char *line;
578*0Sstevel@tonic-gate {
579*0Sstevel@tonic-gate 	ulong_t status;
580*0Sstevel@tonic-gate 	char *str;
581*0Sstevel@tonic-gate 	char buff[16];
582*0Sstevel@tonic-gate 
583*0Sstevel@tonic-gate 	status = getxdr_u_long();
584*0Sstevel@tonic-gate 	switch (status) {
585*0Sstevel@tonic-gate 	case YP_TRUE:	str = "OK";			break;
586*0Sstevel@tonic-gate 	case YP_NOMORE:	str = "No more entries";	break;
587*0Sstevel@tonic-gate 	case YP_FALSE:	str = "Fail";			break;
588*0Sstevel@tonic-gate 	case YP_NOMAP:	str = "No such map";		break;
589*0Sstevel@tonic-gate 	case YP_NODOM:	str = "No such domain";		break;
590*0Sstevel@tonic-gate 	case YP_NOKEY:	str = "No such key";		break;
591*0Sstevel@tonic-gate 	case YP_BADOP:	str = "Invalid operation";	break;
592*0Sstevel@tonic-gate 	case YP_BADDB:	str = "Bad database";		break;
593*0Sstevel@tonic-gate 	case YP_YPERR:	str = "Server error";		break;
594*0Sstevel@tonic-gate 	case YP_BADARGS:str = "Bad args";		break;
595*0Sstevel@tonic-gate 	case YP_VERS:	str = "Version mismatch";	break;
596*0Sstevel@tonic-gate 	default:	(void) sprintf(buff, "(%lu)", status);
597*0Sstevel@tonic-gate 			str = buff;
598*0Sstevel@tonic-gate 			break;
599*0Sstevel@tonic-gate 	}
600*0Sstevel@tonic-gate 	(void) strcpy(line, str);
601*0Sstevel@tonic-gate 	return ((int)status);
602*0Sstevel@tonic-gate }
603*0Sstevel@tonic-gate 
604*0Sstevel@tonic-gate static int
detail_ypstat()605*0Sstevel@tonic-gate detail_ypstat()
606*0Sstevel@tonic-gate {
607*0Sstevel@tonic-gate 	ulong_t status;
608*0Sstevel@tonic-gate 	char buff[32];
609*0Sstevel@tonic-gate 
610*0Sstevel@tonic-gate 
611*0Sstevel@tonic-gate 	status = sum_ypstat(buff);
612*0Sstevel@tonic-gate 	(void) sprintf(get_line(0, 0),
613*0Sstevel@tonic-gate 		"Status = %d (%s)",
614*0Sstevel@tonic-gate 		status, buff);
615*0Sstevel@tonic-gate 
616*0Sstevel@tonic-gate 	return ((int)status);
617*0Sstevel@tonic-gate }
618*0Sstevel@tonic-gate 
619*0Sstevel@tonic-gate char *
sum_ypmaplist()620*0Sstevel@tonic-gate sum_ypmaplist()
621*0Sstevel@tonic-gate {
622*0Sstevel@tonic-gate 	static char buff[YPMAXMAP + 1];
623*0Sstevel@tonic-gate 	int maps = 0;
624*0Sstevel@tonic-gate 
625*0Sstevel@tonic-gate 	if (setjmp(xdr_err)) {
626*0Sstevel@tonic-gate 		(void) sprintf(buff, "%d+ maps", maps);
627*0Sstevel@tonic-gate 		return (buff);
628*0Sstevel@tonic-gate 	}
629*0Sstevel@tonic-gate 
630*0Sstevel@tonic-gate 	while (getxdr_long()) {
631*0Sstevel@tonic-gate 		(void) getxdr_string(buff, YPMAXMAP);
632*0Sstevel@tonic-gate 		maps++;
633*0Sstevel@tonic-gate 	}
634*0Sstevel@tonic-gate 
635*0Sstevel@tonic-gate 	(void) sprintf(buff, "%d maps", maps);
636*0Sstevel@tonic-gate 	return (buff);
637*0Sstevel@tonic-gate }
638*0Sstevel@tonic-gate 
639*0Sstevel@tonic-gate void
detail_ypmaplist()640*0Sstevel@tonic-gate detail_ypmaplist()
641*0Sstevel@tonic-gate {
642*0Sstevel@tonic-gate 	int maps = 0;
643*0Sstevel@tonic-gate 
644*0Sstevel@tonic-gate 	if (setjmp(xdr_err)) {
645*0Sstevel@tonic-gate 		(void) sprintf(get_line(0, 0),
646*0Sstevel@tonic-gate 			" %d+ maps. (Frame is incomplete)",
647*0Sstevel@tonic-gate 			maps);
648*0Sstevel@tonic-gate 		return;
649*0Sstevel@tonic-gate 	}
650*0Sstevel@tonic-gate 
651*0Sstevel@tonic-gate 	(void) sprintf(get_line(0, 0), "Map list");
652*0Sstevel@tonic-gate 
653*0Sstevel@tonic-gate 	while (getxdr_long()) {
654*0Sstevel@tonic-gate 		(void) showxdr_string(YPMAXMAP, "  %s");
655*0Sstevel@tonic-gate 		maps++;
656*0Sstevel@tonic-gate 	}
657*0Sstevel@tonic-gate 
658*0Sstevel@tonic-gate 	(void) sprintf(get_line(0, 0), "%d maps", maps);
659*0Sstevel@tonic-gate }
660*0Sstevel@tonic-gate 
661*0Sstevel@tonic-gate char *
ypbind_error(err)662*0Sstevel@tonic-gate ypbind_error(err)
663*0Sstevel@tonic-gate 	int err;
664*0Sstevel@tonic-gate {
665*0Sstevel@tonic-gate 	static char buff[16];
666*0Sstevel@tonic-gate 
667*0Sstevel@tonic-gate 	switch (err) {
668*0Sstevel@tonic-gate 	case YPBIND_ERR_ERR:	return ("Internal error");
669*0Sstevel@tonic-gate 	case YPBIND_ERR_NOSERV:	return ("Internal error");
670*0Sstevel@tonic-gate 	case YPBIND_ERR_RESC:	return ("Resource allocation fail");
671*0Sstevel@tonic-gate 	default:
672*0Sstevel@tonic-gate 		(void) sprintf(buff, "(%d)", err);
673*0Sstevel@tonic-gate 		return (buff);
674*0Sstevel@tonic-gate 	}
675*0Sstevel@tonic-gate 	/* NOTREACHED */
676*0Sstevel@tonic-gate }
677