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 #ident "%Z%%M% %I% %E% SMI" /* SunOS */
29 #include <sys/types.h>
30 #include <sys/errno.h>
34 #include <sys/socket.h>
35 #include <sys/sockio.h>
36 #include <sys/tiuser.h>
38 #include <netinet/in_systm.h>
39 #include <netinet/in.h>
40 #include <rpc/types.h>
44 #include <rpc/rpc_msg.h>
45 #include <rpcsvc/yp_prot.h>
48 extern char *dlc_header
;
49 extern jmp_buf xdr_err
;
51 char *sum_ypxfrstat();
52 char *sum_ypmaplist();
53 void detail_ypmaplist();
55 static void niscall(int);
56 static void nisreply(int);
57 static int detail_ypstat(void);
58 static int sum_ypstat(char *);
61 * Defines missing from 5.0 yp_prot.h
63 #define YPBINDPROG ((ulong_t)100007)
64 #define YPBINDVERS ((ulong_t)2)
65 #define YPBINDVERS_ORIG ((ulong_t)1)
67 /* Procedure symbols */
69 #define YPBINDPROC_NULL ((ulong_t)0)
70 #define YPBINDPROC_DOMAIN ((ulong_t)1)
71 #define YPBINDPROC_SETDOM ((ulong_t)2)
73 #define YPBIND_ERR_ERR 1 /* Internal error */
74 #define YPBIND_ERR_NOSERV 2 /* No bound server for passed domain */
75 #define YPBIND_ERR_RESC 3 /* System resource allocation failure */
78 static char *procnames_bind_short
[] = {
84 static char *procnames_bind_long
[] = {
85 "Null procedure", /* 0 */
86 "Get domain name", /* 1 */
87 "Set domain name", /* 2 */
90 static char *procnames_short
[] = {
93 "DOMAIN_NONACK", /* 2 */
106 #define MAXPROC_BIND 2
109 static char *procnames_long
[] = {
110 "Null procedure", /* 0 */
111 "Verify domain support", /* 1 */
112 "Verify domain support (broadcast)", /* 2 */
113 "Return value of a key", /* 3 */
114 "Return first key-value pair in map", /* 4 */
115 "Return next key-value pair in map", /* 5 */
116 "Request map update (old)", /* 6 */
117 "Close current map on server", /* 7 */
118 "Get all key-value pairs in map", /* 8 */
119 "Get master server", /* 9 */
120 "Get order", /* 10 */
121 "Return list of supported maps", /* 11 */
122 "Request map update", /* 12 */
126 interpret_nisbind(flags
, type
, xid
, vers
, proc
, data
, len
)
127 int flags
, type
, xid
, vers
, proc
;
132 char buff
[YPMAXDOMAIN
+ 1];
135 if (proc
< 0 || proc
> MAXPROC_BIND
)
139 if (setjmp(xdr_err
)) {
143 line
= get_sum_line();
148 procnames_bind_short
[proc
]);
149 line
+= strlen(line
);
151 case YPBINDPROC_NULL
:
153 case YPBINDPROC_DOMAIN
:
154 (void) sprintf(line
, " %s",
155 getxdr_string(buff
, YPMAXDOMAIN
));
157 case YPBINDPROC_SETDOM
:
158 (void) sprintf(line
, " %s",
159 getxdr_string(buff
, YPMAXDOMAIN
));
164 check_retransmit(line
, xid
);
166 (void) sprintf(line
, "NISBIND R %s ",
167 procnames_bind_short
[proc
]);
168 line
+= strlen(line
);
170 case YPBINDPROC_NULL
:
172 case YPBINDPROC_DOMAIN
:
173 status
= getxdr_long();
174 if (status
== 1) { /* success */
175 (void) strcat(line
, "OK");
176 } else { /* failure */
177 status
= getxdr_long();
178 (void) sprintf(line
, "ERROR=%s",
179 ypbind_error(status
));
182 case YPBINDPROC_SETDOM
:
190 if (flags
& F_DTAIL
) {
191 show_header("NISBIND:",
192 "Network Information Service Bind", len
);
194 if (setjmp(xdr_err
)) {
197 (void) sprintf(get_line(0, 0),
199 proc
, procnames_bind_long
[proc
]);
202 case YPBINDPROC_NULL
:
204 case YPBINDPROC_DOMAIN
:
205 (void) showxdr_string(YPMAXDOMAIN
,
208 case YPBINDPROC_SETDOM
:
209 (void) showxdr_string(YPMAXDOMAIN
,
211 (void) showxdr_hex(4, "Address=%s");
212 (void) showxdr_hex(2, "Port=%s");
213 (void) showxdr_u_long("Version=%lu");
220 case YPBINDPROC_NULL
:
222 case YPBINDPROC_DOMAIN
:
223 status
= getxdr_u_long();
224 (void) sprintf(get_line(0, 0),
227 status
== 1 ? "OK":"Fail");
229 (void) showxdr_hex(4,
231 (void) showxdr_hex(2,
234 status
= getxdr_u_long();
235 (void) sprintf(get_line(0, 0),
238 ypbind_error(status
));
241 case YPBINDPROC_SETDOM
:
252 interpret_nis(flags
, type
, xid
, vers
, proc
, data
, len
)
253 int flags
, type
, xid
, vers
, proc
;
258 char *dom
, *map
, *key
;
260 /* buffers are all the same size so we don't have to keep track */
261 char buff1
[YPMAXRECORD
+ 1], buff2
[YPMAXRECORD
+ 1];
262 char buff3
[YPMAXRECORD
+ 1];
265 if (setjmp(xdr_err
)) {
269 line
= get_sum_line();
273 (void) sprintf(line
, "NIS C %d", proc
);
277 procnames_short
[proc
]);
278 line
+= strlen(line
);
283 case YPPROC_DOMAIN_NONACK
:
285 /* YPMAXDOMAIN > YPMAXMAP */
286 (void) sprintf(line
, " %s",
287 getxdr_string(buff1
, YPMAXDOMAIN
));
290 dom
= getxdr_string(buff1
, YPMAXDOMAIN
);
291 map
= getxdr_string(buff2
, YPMAXMAP
);
292 (void) sprintf(line
, " %s", map
);
296 dom
= getxdr_string(buff1
, YPMAXDOMAIN
);
297 map
= getxdr_string(buff2
, YPMAXMAP
);
298 key
= getxdr_string(buff3
, YPMAXRECORD
);
305 dom
= getxdr_string(buff1
, YPMAXDOMAIN
);
306 map
= getxdr_string(buff2
, YPMAXMAP
);
316 dom
= getxdr_string(buff1
, YPMAXDOMAIN
);
317 map
= getxdr_string(buff2
, YPMAXMAP
);
325 check_retransmit(line
, xid
);
328 (void) sprintf(line
, "NIS R %d ", proc
);
330 (void) sprintf(line
, "NIS R %s ",
331 procnames_short
[proc
]);
332 line
+= strlen(line
);
337 case YPPROC_DOMAIN_NONACK
:
338 (void) sprintf(line
, "%s",
339 getxdr_long() ? "OK":"Fail");
342 (void) sum_ypstat(line
);
346 if (sum_ypstat(line
) == YP_TRUE
) {
347 line
+= strlen(line
);
348 (void) getxdr_string(buff1
,
350 (void) sprintf(line
, " key=%s",
357 transid
= getxdr_u_long();
358 status
= getxdr_long();
359 (void) sprintf(line
, "transid=%lu %s",
361 sum_ypxfrstat(status
));
366 if (getxdr_u_long()) {
367 (void) sum_ypstat(line
);
368 line
+= strlen(line
);
369 (void) sprintf(line
, " key=%s",
370 getxdr_string(buff1
, YPMAXRECORD
));
377 if (sum_ypstat(line
) == YP_TRUE
) {
378 line
+= strlen(line
);
379 (void) sprintf(line
, " peer=%s",
385 if (sum_ypstat(line
) == YP_TRUE
) {
386 line
+= strlen(line
);
387 (void) sprintf(line
, " order=%lu",
392 if (sum_ypstat(line
) == YP_TRUE
) {
393 line
+= strlen(line
);
394 (void) sprintf(line
, " %s",
404 if (flags
& F_DTAIL
) {
405 show_header("NIS: ", "Network Information Service", len
);
407 if (setjmp(xdr_err
)) {
410 (void) sprintf(get_line(0, 0),
413 proc
> MAXPROC
? "unknown" : procnames_long
[proc
]);
423 * Print out version 2 NIS call packets
434 case YPPROC_DOMAIN_NONACK
:
436 (void) showxdr_string(YPMAXDOMAIN
, "Domain = %s");
439 (void) showxdr_string(YPMAXDOMAIN
, "Domain = %s");
440 (void) showxdr_string(YPMAXMAP
, "Map = %s");
444 (void) showxdr_string(YPMAXDOMAIN
, "Domain = %s");
445 (void) showxdr_string(YPMAXMAP
, "Map = %s");
446 (void) showxdr_string(YPMAXRECORD
, "Key = %s");
449 (void) showxdr_string(YPMAXDOMAIN
, "Domain = %s");
450 (void) showxdr_string(YPMAXMAP
, "Map = %s");
451 (void) showxdr_u_long("Order = %lu");
452 (void) showxdr_string(YPMAXPEER
, "Peer = %s");
453 (void) showxdr_u_long("Transid = %lu");
454 (void) showxdr_u_long("Prog = %lu");
455 (void) showxdr_string(YPMAXPEER
, "Name = %s");
458 (void) showxdr_string(YPMAXDOMAIN
, "Domain = %s");
459 (void) showxdr_string(YPMAXMAP
, "Map = %s");
460 (void) showxdr_u_long("Order = %lu");
461 (void) showxdr_string(YPMAXPEER
, "Peer = %s");
462 (void) showxdr_u_long("Transid = %lu");
463 (void) showxdr_u_long("Prog = %lu");
464 (void) showxdr_u_long("Port = %lu");
471 (void) showxdr_string(YPMAXDOMAIN
, "Domain = %s");
472 (void) showxdr_string(YPMAXMAP
, "Map = %s");
480 * Print out version 2 NIS reply packets
487 unsigned int xfrstat
, more
;
493 case YPPROC_DOMAIN_NONACK
:
494 (void) sprintf(get_line(0, 0),
496 getxdr_u_long() ? "OK":"Fail");
499 (void) detail_ypstat();
500 (void) showxdr_string(YPMAXRECORD
, "Value = %s");
504 (void) detail_ypstat();
505 (void) showxdr_string(YPMAXRECORD
, "Value = %s");
506 (void) showxdr_string(YPMAXRECORD
, "Key = %s");
510 (void) showxdr_u_long("Transid = %lu");
511 xfrstat
= getxdr_u_long();
512 (void) sprintf(get_line(0, 0),
513 "Transfer status = %lu (%s)",
514 xfrstat
, sum_ypxfrstat(xfrstat
));
519 more
= getxdr_u_long();
520 (void) sprintf(get_line(0, 0),
522 more
? "true" : "false");
524 (void) detail_ypstat();
525 (void) showxdr_string(YPMAXRECORD
, "Value = %s");
526 (void) showxdr_string(YPMAXRECORD
, "Key = %s");
530 (void) detail_ypstat();
531 (void) showxdr_string(YPMAXPEER
, "Peer = %s");
533 (void) detail_ypstat();
534 (void) showxdr_u_long("Order=%lu");
537 (void) detail_ypstat();
546 sum_ypxfrstat(status
)
549 static char buff
[16];
552 case 1: return ("Success");
553 case 2: return ("Master's version not newer");
554 case -1: return ("Can't find server for map");
555 case -2: return ("No such domain");
556 case -3: return ("Resource allocation failure");
557 case -4: return ("RPC failure talking to server");
558 case -5: return ("Can't get master address");
559 case -6: return ("NIS server/map db error");
560 case -7: return ("Bad arguments");
561 case -8: return ("Local dbm operation failed");
562 case -9: return ("Local file I/O operation failed");
563 case -10: return ("Map version skew during transfer");
564 case -11: return ("Can't send clear req to local ypserv");
565 case -12: return ("No local order number in map");
566 case -13: return ("Transfer error");
567 case -14: return ("Transfer request refused");
569 (void) sprintf(buff
, "(%d)", status
);
583 status
= getxdr_u_long();
585 case YP_TRUE
: str
= "OK"; break;
586 case YP_NOMORE
: str
= "No more entries"; break;
587 case YP_FALSE
: str
= "Fail"; break;
588 case YP_NOMAP
: str
= "No such map"; break;
589 case YP_NODOM
: str
= "No such domain"; break;
590 case YP_NOKEY
: str
= "No such key"; break;
591 case YP_BADOP
: str
= "Invalid operation"; break;
592 case YP_BADDB
: str
= "Bad database"; break;
593 case YP_YPERR
: str
= "Server error"; break;
594 case YP_BADARGS
:str
= "Bad args"; break;
595 case YP_VERS
: str
= "Version mismatch"; break;
596 default: (void) sprintf(buff
, "(%lu)", status
);
600 (void) strcpy(line
, str
);
601 return ((int)status
);
611 status
= sum_ypstat(buff
);
612 (void) sprintf(get_line(0, 0),
616 return ((int)status
);
622 static char buff
[YPMAXMAP
+ 1];
625 if (setjmp(xdr_err
)) {
626 (void) sprintf(buff
, "%d+ maps", maps
);
630 while (getxdr_long()) {
631 (void) getxdr_string(buff
, YPMAXMAP
);
635 (void) sprintf(buff
, "%d maps", maps
);
644 if (setjmp(xdr_err
)) {
645 (void) sprintf(get_line(0, 0),
646 " %d+ maps. (Frame is incomplete)",
651 (void) sprintf(get_line(0, 0), "Map list");
653 while (getxdr_long()) {
654 (void) showxdr_string(YPMAXMAP
, " %s");
658 (void) sprintf(get_line(0, 0), "%d maps", maps
);
665 static char buff
[16];
668 case YPBIND_ERR_ERR
: return ("Internal error");
669 case YPBIND_ERR_NOSERV
: return ("Internal error");
670 case YPBIND_ERR_RESC
: return ("Resource allocation fail");
672 (void) sprintf(buff
, "(%d)", err
);