1 /* $NetBSD: yptest.c,v 1.8 2004/10/22 18:41:09 peter Exp $ */
4 * Copyright (c) 1994 Mats O Jansson <moj@stacken.kth.se>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
17 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 #include <sys/cdefs.h>
31 __RCSID("$NetBSD: yptest.c,v 1.8 2004/10/22 18:41:09 peter Exp $");
34 #include <sys/types.h>
43 #include <rpcsvc/yp_prot.h>
44 #include <rpcsvc/ypclnt.h>
46 int main(int, char *[]);
47 static int yptest_foreach(int, char *, int, char *, int, char *);
50 main(int argc
, char **argv
)
52 char *Domain
, *Value
, *Key2
;
53 const char *Map
= "passwd.byname";
54 const char *Key
= "root";
55 int KeyLen
, ValLen
, Status
, Order
;
56 struct ypall_callback Callback
;
57 struct ypmaplist
*ypml
, *y
;
60 fprintf(stderr
, "usage: %s\n", getprogname());
64 Status
= yp_get_default_domain(&Domain
);
66 printf("Can't get YP domain name: %s\n", yperr_string(Status
));
70 printf("Test 1: yp_match\n");
72 Status
= yp_match(Domain
, Map
, Key
, KeyLen
, &Value
, &ValLen
);
74 printf("%*.*s\n", ValLen
, ValLen
, Value
);
76 printf("yp error: %s\n", yperr_string(Status
));
78 printf("\nTest 2: yp_first\n");
79 Status
= yp_first(Domain
, Map
, &Key2
, &KeyLen
, &Value
, &ValLen
);
81 printf("%*.*s %*.*s\n", KeyLen
, KeyLen
, Key2
, ValLen
, ValLen
,
84 printf("yp error: %s\n", yperr_string(Status
));
86 printf("\nTest 3: yp_next\n");
88 Status
= yp_next(Domain
, Map
, Key2
, KeyLen
, &Key2
,
89 &KeyLen
, &Value
, &ValLen
);
91 printf("%*.*s %*.*s\n", KeyLen
, KeyLen
, Key2
,
92 ValLen
, ValLen
, Value
);
94 printf("yp error: %s\n", yperr_string(Status
));
97 printf("\nTest 4: yp_master\n");
98 Status
= yp_master(Domain
, Map
, &Key2
);
100 printf("%s\n", Key2
);
102 printf("yp error: %s\n", yperr_string(Status
));
104 printf("\nTest 5: yp_order\n");
105 Status
= yp_order(Domain
, Map
, &Order
);
107 printf("%d\n", Order
);
109 printf("yp error: %s\n", yperr_string(Status
));
111 printf("\nTest 6: yp_maplist\n");
113 switch (yp_maplist(Domain
, &ypml
)) {
117 printf("%s\n", ypml
->ypml_name
);
122 printf("yp error: %s\n", yperr_string(Status
));
126 printf("\nTest 7: yp_all\n");
127 Callback
.foreach
= yptest_foreach
;
128 Status
= yp_all(Domain
, Map
, &Callback
);
130 printf("yp error: %s\n", yperr_string(Status
));
136 yptest_foreach(int status
, char *key
, int keylen
, char *val
, int vallen
,
140 if (status
== YP_NOMORE
)
143 /* key avslutas med NUL */
144 /* val avslutas med NUL */
147 printf("%s %s\n", key
, val
);