4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright (c) 1991, 1999 by Sun Microsystems, Inc.
24 * All rights reserved.
27 #include <sys/types.h>
28 #include <sys/errno.h>
32 #include <sys/socket.h>
33 #include <sys/sockio.h>
34 #include <sys/tiuser.h>
36 #include <netinet/in_systm.h>
37 #include <netinet/in.h>
38 #include <rpc/types.h>
42 #include <rpc/rpc_msg.h>
43 #include <rpcsvc/yp_prot.h>
46 extern char *dlc_header
;
47 extern jmp_buf xdr_err
;
49 char *sum_ypxfrstat();
50 char *sum_ypmaplist();
51 void detail_ypmaplist();
53 static void niscall(int);
54 static void nisreply(int);
55 static int detail_ypstat(void);
56 static int sum_ypstat(char *);
59 * Defines missing from 5.0 yp_prot.h
61 #define YPBINDPROG ((ulong_t)100007)
62 #define YPBINDVERS ((ulong_t)2)
63 #define YPBINDVERS_ORIG ((ulong_t)1)
65 /* Procedure symbols */
67 #define YPBINDPROC_NULL ((ulong_t)0)
68 #define YPBINDPROC_DOMAIN ((ulong_t)1)
69 #define YPBINDPROC_SETDOM ((ulong_t)2)
71 #define YPBIND_ERR_ERR 1 /* Internal error */
72 #define YPBIND_ERR_NOSERV 2 /* No bound server for passed domain */
73 #define YPBIND_ERR_RESC 3 /* System resource allocation failure */
76 static char *procnames_bind_short
[] = {
82 static char *procnames_bind_long
[] = {
83 "Null procedure", /* 0 */
84 "Get domain name", /* 1 */
85 "Set domain name", /* 2 */
88 static char *procnames_short
[] = {
91 "DOMAIN_NONACK", /* 2 */
104 #define MAXPROC_BIND 2
107 static char *procnames_long
[] = {
108 "Null procedure", /* 0 */
109 "Verify domain support", /* 1 */
110 "Verify domain support (broadcast)", /* 2 */
111 "Return value of a key", /* 3 */
112 "Return first key-value pair in map", /* 4 */
113 "Return next key-value pair in map", /* 5 */
114 "Request map update (old)", /* 6 */
115 "Close current map on server", /* 7 */
116 "Get all key-value pairs in map", /* 8 */
117 "Get master server", /* 9 */
118 "Get order", /* 10 */
119 "Return list of supported maps", /* 11 */
120 "Request map update", /* 12 */
124 interpret_nisbind(int flags
, int type
, int xid
, int vers
, int proc
, char *data
,
128 char buff
[YPMAXDOMAIN
+ 1];
131 if (proc
< 0 || proc
> MAXPROC_BIND
)
135 if (setjmp(xdr_err
)) {
139 line
= get_sum_line();
142 (void) sprintf(line
, "NISBIND C %s",
143 procnames_bind_short
[proc
]);
144 line
+= strlen(line
);
146 case YPBINDPROC_NULL
:
148 case YPBINDPROC_DOMAIN
:
149 (void) sprintf(line
, " %s",
150 getxdr_string(buff
, YPMAXDOMAIN
));
152 case YPBINDPROC_SETDOM
:
153 (void) sprintf(line
, " %s",
154 getxdr_string(buff
, YPMAXDOMAIN
));
159 check_retransmit(line
, xid
);
161 (void) sprintf(line
, "NISBIND R %s ",
162 procnames_bind_short
[proc
]);
163 line
+= strlen(line
);
165 case YPBINDPROC_NULL
:
167 case YPBINDPROC_DOMAIN
:
168 status
= getxdr_long();
169 if (status
== 1) { /* success */
170 (void) strcat(line
, "OK");
171 } else { /* failure */
172 status
= getxdr_long();
173 (void) sprintf(line
, "ERROR=%s",
174 ypbind_error(status
));
177 case YPBINDPROC_SETDOM
:
185 if (flags
& F_DTAIL
) {
186 show_header("NISBIND:",
187 "Network Information Service Bind", len
);
189 if (setjmp(xdr_err
)) {
192 (void) sprintf(get_line(0, 0), "Proc = %d (%s)",
193 proc
, procnames_bind_long
[proc
]);
196 case YPBINDPROC_NULL
:
198 case YPBINDPROC_DOMAIN
:
199 (void) showxdr_string(YPMAXDOMAIN
,
202 case YPBINDPROC_SETDOM
:
203 (void) showxdr_string(YPMAXDOMAIN
,
205 (void) showxdr_hex(4, "Address=%s");
206 (void) showxdr_hex(2, "Port=%s");
207 (void) showxdr_u_long("Version=%lu");
214 case YPBINDPROC_NULL
:
216 case YPBINDPROC_DOMAIN
:
217 status
= getxdr_u_long();
218 (void) sprintf(get_line(0, 0),
221 status
== 1 ? "OK":"Fail");
223 (void) showxdr_hex(4, "Address=%s");
224 (void) showxdr_hex(2, "Port=%s");
226 status
= getxdr_u_long();
227 (void) sprintf(get_line(0, 0),
228 "Error = %lu (%s)", status
,
229 ypbind_error(status
));
232 case YPBINDPROC_SETDOM
:
243 interpret_nis(int flags
, int type
, int xid
, int vers
, int proc
, char *data
,
247 char *dom
, *map
, *key
;
249 /* buffers are all the same size so we don't have to keep track */
250 char buff1
[YPMAXRECORD
+ 1], buff2
[YPMAXRECORD
+ 1];
251 char buff3
[YPMAXRECORD
+ 1];
254 if (setjmp(xdr_err
)) {
258 line
= get_sum_line();
262 (void) sprintf(line
, "NIS C %d", proc
);
264 (void) sprintf(line
, "NIS C %s",
265 procnames_short
[proc
]);
266 line
+= strlen(line
);
271 case YPPROC_DOMAIN_NONACK
:
273 /* YPMAXDOMAIN > YPMAXMAP */
274 (void) sprintf(line
, " %s",
275 getxdr_string(buff1
, YPMAXDOMAIN
));
278 dom
= getxdr_string(buff1
, YPMAXDOMAIN
);
279 map
= getxdr_string(buff2
, YPMAXMAP
);
280 (void) sprintf(line
, " %s", map
);
284 dom
= getxdr_string(buff1
, YPMAXDOMAIN
);
285 map
= getxdr_string(buff2
, YPMAXMAP
);
286 key
= getxdr_string(buff3
, YPMAXRECORD
);
287 (void) sprintf(line
, " %s in %s", key
, map
);
291 dom
= getxdr_string(buff1
, YPMAXDOMAIN
);
292 map
= getxdr_string(buff2
, YPMAXMAP
);
293 (void) sprintf(line
, " map %s in %s", map
, dom
);
300 dom
= getxdr_string(buff1
, YPMAXDOMAIN
);
301 map
= getxdr_string(buff2
, YPMAXMAP
);
302 (void) sprintf(line
, " map %s in %s", map
, dom
);
307 check_retransmit(line
, xid
);
310 (void) sprintf(line
, "NIS R %d ", proc
);
312 (void) sprintf(line
, "NIS R %s ",
313 procnames_short
[proc
]);
314 line
+= strlen(line
);
319 case YPPROC_DOMAIN_NONACK
:
320 (void) sprintf(line
, "%s",
321 getxdr_long() ? "OK":"Fail");
324 (void) sum_ypstat(line
);
328 if (sum_ypstat(line
) == YP_TRUE
) {
329 line
+= strlen(line
);
330 (void) getxdr_string(buff1
,
332 (void) sprintf(line
, " key=%s",
339 transid
= getxdr_u_long();
340 status
= getxdr_long();
341 (void) sprintf(line
, "transid=%lu %s", transid
,
342 sum_ypxfrstat(status
));
347 if (getxdr_u_long()) {
348 (void) sum_ypstat(line
);
349 line
+= strlen(line
);
350 (void) sprintf(line
, " key=%s",
351 getxdr_string(buff1
, YPMAXRECORD
));
353 (void) sprintf(line
, "No more");
357 if (sum_ypstat(line
) == YP_TRUE
) {
358 line
+= strlen(line
);
359 (void) sprintf(line
, " peer=%s",
360 getxdr_string(buff1
, YPMAXPEER
));
364 if (sum_ypstat(line
) == YP_TRUE
) {
365 line
+= strlen(line
);
366 (void) sprintf(line
, " order=%lu",
371 if (sum_ypstat(line
) == YP_TRUE
) {
372 line
+= strlen(line
);
373 (void) sprintf(line
, " %s",
383 if (flags
& F_DTAIL
) {
384 show_header("NIS: ", "Network Information Service", len
);
386 if (setjmp(xdr_err
)) {
389 (void) sprintf(get_line(0, 0), "Proc = %d (%s)", proc
,
390 proc
> MAXPROC
? "unknown" : procnames_long
[proc
]);
400 * Print out version 2 NIS call packets
410 case YPPROC_DOMAIN_NONACK
:
412 (void) showxdr_string(YPMAXDOMAIN
, "Domain = %s");
415 (void) showxdr_string(YPMAXDOMAIN
, "Domain = %s");
416 (void) showxdr_string(YPMAXMAP
, "Map = %s");
420 (void) showxdr_string(YPMAXDOMAIN
, "Domain = %s");
421 (void) showxdr_string(YPMAXMAP
, "Map = %s");
422 (void) showxdr_string(YPMAXRECORD
, "Key = %s");
425 (void) showxdr_string(YPMAXDOMAIN
, "Domain = %s");
426 (void) showxdr_string(YPMAXMAP
, "Map = %s");
427 (void) showxdr_u_long("Order = %lu");
428 (void) showxdr_string(YPMAXPEER
, "Peer = %s");
429 (void) showxdr_u_long("Transid = %lu");
430 (void) showxdr_u_long("Prog = %lu");
431 (void) showxdr_string(YPMAXPEER
, "Name = %s");
434 (void) showxdr_string(YPMAXDOMAIN
, "Domain = %s");
435 (void) showxdr_string(YPMAXMAP
, "Map = %s");
436 (void) showxdr_u_long("Order = %lu");
437 (void) showxdr_string(YPMAXPEER
, "Peer = %s");
438 (void) showxdr_u_long("Transid = %lu");
439 (void) showxdr_u_long("Prog = %lu");
440 (void) showxdr_u_long("Port = %lu");
447 (void) showxdr_string(YPMAXDOMAIN
, "Domain = %s");
448 (void) showxdr_string(YPMAXMAP
, "Map = %s");
456 * Print out version 2 NIS reply packets
462 unsigned int xfrstat
, more
;
468 case YPPROC_DOMAIN_NONACK
:
469 (void) sprintf(get_line(0, 0), "Result=%s",
470 getxdr_u_long() ? "OK":"Fail");
473 (void) detail_ypstat();
474 (void) showxdr_string(YPMAXRECORD
, "Value = %s");
478 (void) detail_ypstat();
479 (void) showxdr_string(YPMAXRECORD
, "Value = %s");
480 (void) showxdr_string(YPMAXRECORD
, "Key = %s");
484 (void) showxdr_u_long("Transid = %lu");
485 xfrstat
= getxdr_u_long();
486 (void) sprintf(get_line(0, 0), "Transfer status = %lu (%s)",
487 xfrstat
, sum_ypxfrstat(xfrstat
));
492 more
= getxdr_u_long();
493 (void) sprintf(get_line(0, 0), "More = %s",
494 more
? "true" : "false");
496 (void) detail_ypstat();
497 (void) showxdr_string(YPMAXRECORD
, "Value = %s");
498 (void) showxdr_string(YPMAXRECORD
, "Key = %s");
502 (void) detail_ypstat();
503 (void) showxdr_string(YPMAXPEER
, "Peer = %s");
506 (void) detail_ypstat();
507 (void) showxdr_u_long("Order=%lu");
510 (void) detail_ypstat();
519 sum_ypxfrstat(int status
)
521 static char buff
[16];
524 case 1: return ("Success");
525 case 2: return ("Master's version not newer");
526 case -1: return ("Can't find server for map");
527 case -2: return ("No such domain");
528 case -3: return ("Resource allocation failure");
529 case -4: return ("RPC failure talking to server");
530 case -5: return ("Can't get master address");
531 case -6: return ("NIS server/map db error");
532 case -7: return ("Bad arguments");
533 case -8: return ("Local dbm operation failed");
534 case -9: return ("Local file I/O operation failed");
535 case -10: return ("Map version skew during transfer");
536 case -11: return ("Can't send clear req to local ypserv");
537 case -12: return ("No local order number in map");
538 case -13: return ("Transfer error");
539 case -14: return ("Transfer request refused");
541 (void) sprintf(buff
, "(%d)", status
);
548 sum_ypstat(char *line
)
554 status
= getxdr_u_long();
556 case YP_TRUE
: str
= "OK"; break;
557 case YP_NOMORE
: str
= "No more entries"; break;
558 case YP_FALSE
: str
= "Fail"; break;
559 case YP_NOMAP
: str
= "No such map"; break;
560 case YP_NODOM
: str
= "No such domain"; break;
561 case YP_NOKEY
: str
= "No such key"; break;
562 case YP_BADOP
: str
= "Invalid operation"; break;
563 case YP_BADDB
: str
= "Bad database"; break;
564 case YP_YPERR
: str
= "Server error"; break;
565 case YP_BADARGS
:str
= "Bad args"; break;
566 case YP_VERS
: str
= "Version mismatch"; break;
567 default: (void) sprintf(buff
, "(%lu)", status
);
571 (void) strcpy(line
, str
);
572 return ((int)status
);
582 status
= sum_ypstat(buff
);
583 (void) sprintf(get_line(0, 0), "Status = %d (%s)", status
, buff
);
585 return ((int)status
);
591 static char buff
[YPMAXMAP
+ 1];
594 if (setjmp(xdr_err
)) {
595 (void) sprintf(buff
, "%d+ maps", maps
);
599 while (getxdr_long()) {
600 (void) getxdr_string(buff
, YPMAXMAP
);
604 (void) sprintf(buff
, "%d maps", maps
);
609 detail_ypmaplist(void)
613 if (setjmp(xdr_err
)) {
614 (void) sprintf(get_line(0, 0),
615 " %d+ maps. (Frame is incomplete)", maps
);
619 (void) sprintf(get_line(0, 0), "Map list");
621 while (getxdr_long()) {
622 (void) showxdr_string(YPMAXMAP
, " %s");
626 (void) sprintf(get_line(0, 0), "%d maps", maps
);
630 ypbind_error(int err
)
632 static char buff
[16];
635 case YPBIND_ERR_ERR
: return ("Internal error");
636 case YPBIND_ERR_NOSERV
: return ("Internal error");
637 case YPBIND_ERR_RESC
: return ("Resource allocation fail");
639 (void) sprintf(buff
, "(%d)", err
);