xref: /dragonfly/usr.sbin/rpc.lockd/test.c (revision 984263bc)
1 #ifndef lint
2 #if 0
3 static char sccsid[] = "from: @(#)nlm_prot.x 1.8 87/09/21 Copyr 1987 Sun Micro";
4 static char sccsid[] = "from: * @(#)nlm_prot.x	2.1 88/08/01 4.0 RPCSRC";
5 #endif
6 static const char rcsid[] =
7   "$FreeBSD: src/usr.sbin/rpc.lockd/test.c,v 1.4.2.1 2001/08/01 06:39:36 alfred Exp $";
8 #endif /* not lint */
9 
10 #include <rpc/rpc.h>
11 #include <rpcsvc/nlm_prot.h>
12 
13 /* Default timeout can be changed using clnt_control() */
14 static struct timeval TIMEOUT = { 0, 0 };
15 
16 nlm_testres *
17 nlm_test_1(argp, clnt)
18 	struct nlm_testargs *argp;
19 	CLIENT *clnt;
20 {
21 	static nlm_testres res;
22 
23 	bzero((char *)&res, sizeof(res));
24 	if (clnt_call(clnt, NLM_TEST, xdr_nlm_testargs, argp, xdr_nlm_testres, &res, TIMEOUT) != RPC_SUCCESS) {
25 		return (NULL);
26 	}
27 	return (&res);
28 }
29 
30 
31 nlm_res *
32 nlm_lock_1(argp, clnt)
33 	struct nlm_lockargs *argp;
34 	CLIENT *clnt;
35 {
36 	enum clnt_stat st;
37 	static nlm_res res;
38 
39 	bzero((char *)&res, sizeof(res));
40 	if (st = clnt_call(clnt, NLM_LOCK, xdr_nlm_lockargs, argp, xdr_nlm_res, &res, TIMEOUT) != RPC_SUCCESS) {
41 		printf("clnt_call returns %d\n", st);
42 		clnt_perror(clnt, "humbug");
43 		return (NULL);
44 	}
45 	return (&res);
46 }
47 
48 
49 nlm_res *
50 nlm_cancel_1(argp, clnt)
51 	struct nlm_cancargs *argp;
52 	CLIENT *clnt;
53 {
54 	static nlm_res res;
55 
56 	bzero((char *)&res, sizeof(res));
57 	if (clnt_call(clnt, NLM_CANCEL, xdr_nlm_cancargs, argp, xdr_nlm_res, &res, TIMEOUT) != RPC_SUCCESS) {
58 		return (NULL);
59 	}
60 	return (&res);
61 }
62 
63 
64 nlm_res *
65 nlm_unlock_1(argp, clnt)
66 	struct nlm_unlockargs *argp;
67 	CLIENT *clnt;
68 {
69 	static nlm_res res;
70 
71 	bzero((char *)&res, sizeof(res));
72 	if (clnt_call(clnt, NLM_UNLOCK, xdr_nlm_unlockargs, argp, xdr_nlm_res, &res, TIMEOUT) != RPC_SUCCESS) {
73 		return (NULL);
74 	}
75 	return (&res);
76 }
77 
78 
79 nlm_res *
80 nlm_granted_1(argp, clnt)
81 	struct nlm_testargs *argp;
82 	CLIENT *clnt;
83 {
84 	static nlm_res res;
85 
86 	bzero((char *)&res, sizeof(res));
87 	if (clnt_call(clnt, NLM_GRANTED, xdr_nlm_testargs, argp, xdr_nlm_res, &res, TIMEOUT) != RPC_SUCCESS) {
88 		return (NULL);
89 	}
90 	return (&res);
91 }
92 
93 
94 void *
95 nlm_test_msg_1(argp, clnt)
96 	struct nlm_testargs *argp;
97 	CLIENT *clnt;
98 {
99 	static char res;
100 
101 	bzero((char *)&res, sizeof(res));
102 	if (clnt_call(clnt, NLM_TEST_MSG, xdr_nlm_testargs, argp, xdr_void, &res, TIMEOUT) != RPC_SUCCESS) {
103 		return (NULL);
104 	}
105 	return ((void *)&res);
106 }
107 
108 
109 void *
110 nlm_lock_msg_1(argp, clnt)
111 	struct nlm_lockargs *argp;
112 	CLIENT *clnt;
113 {
114 	static char res;
115 
116 	bzero((char *)&res, sizeof(res));
117 	if (clnt_call(clnt, NLM_LOCK_MSG, xdr_nlm_lockargs, argp, xdr_void, NULL, TIMEOUT) != RPC_SUCCESS) {
118 		clnt_perror(clnt, "nlm_lock_msg_1");
119 		return (NULL);
120 	}
121 	return ((void *)&res);
122 }
123 
124 
125 void *
126 nlm_cancel_msg_1(argp, clnt)
127 	struct nlm_cancargs *argp;
128 	CLIENT *clnt;
129 {
130 	static char res;
131 
132 	bzero((char *)&res, sizeof(res));
133 	if (clnt_call(clnt, NLM_CANCEL_MSG, xdr_nlm_cancargs, argp, xdr_void, &res, TIMEOUT) != RPC_SUCCESS) {
134 		return (NULL);
135 	}
136 	return ((void *)&res);
137 }
138 
139 
140 void *
141 nlm_unlock_msg_1(argp, clnt)
142 	struct nlm_unlockargs *argp;
143 	CLIENT *clnt;
144 {
145 	static char res;
146 
147 	bzero((char *)&res, sizeof(res));
148 	if (clnt_call(clnt, NLM_UNLOCK_MSG, xdr_nlm_unlockargs, argp, xdr_void, &res, TIMEOUT) != RPC_SUCCESS) {
149 		return (NULL);
150 	}
151 	return ((void *)&res);
152 }
153 
154 
155 void *
156 nlm_granted_msg_1(argp, clnt)
157 	struct nlm_testargs *argp;
158 	CLIENT *clnt;
159 {
160 	static char res;
161 
162 	bzero((char *)&res, sizeof(res));
163 	if (clnt_call(clnt, NLM_GRANTED_MSG, xdr_nlm_testargs, argp, xdr_void, &res, TIMEOUT) != RPC_SUCCESS) {
164 		return (NULL);
165 	}
166 	return ((void *)&res);
167 }
168 
169 
170 void *
171 nlm_test_res_1(argp, clnt)
172 	nlm_testres *argp;
173 	CLIENT *clnt;
174 {
175 	static char res;
176 
177 	bzero((char *)&res, sizeof(res));
178 	if (clnt_call(clnt, NLM_TEST_RES, xdr_nlm_testres, argp, xdr_void, &res, TIMEOUT) != RPC_SUCCESS) {
179 		return (NULL);
180 	}
181 	return ((void *)&res);
182 }
183 
184 
185 void *
186 nlm_lock_res_1(argp, clnt)
187 	nlm_res *argp;
188 	CLIENT *clnt;
189 {
190 	static char res;
191 
192 	bzero((char *)&res, sizeof(res));
193 	if (clnt_call(clnt, NLM_LOCK_RES, xdr_nlm_res, argp, xdr_void, &res, TIMEOUT) != RPC_SUCCESS) {
194 		return (NULL);
195 	}
196 	return ((void *)&res);
197 }
198 
199 
200 void *
201 nlm_cancel_res_1(argp, clnt)
202 	nlm_res *argp;
203 	CLIENT *clnt;
204 {
205 	static char res;
206 
207 	bzero((char *)&res, sizeof(res));
208 	if (clnt_call(clnt, NLM_CANCEL_RES, xdr_nlm_res, argp, xdr_void, &res, TIMEOUT) != RPC_SUCCESS) {
209 		return (NULL);
210 	}
211 	return ((void *)&res);
212 }
213 
214 
215 void *
216 nlm_unlock_res_1(argp, clnt)
217 	nlm_res *argp;
218 	CLIENT *clnt;
219 {
220 	static char res;
221 
222 	bzero((char *)&res, sizeof(res));
223 	if (clnt_call(clnt, NLM_UNLOCK_RES, xdr_nlm_res, argp, xdr_void, &res, TIMEOUT) != RPC_SUCCESS) {
224 		return (NULL);
225 	}
226 	return ((void *)&res);
227 }
228 
229 
230 void *
231 nlm_granted_res_1(argp, clnt)
232 	nlm_res *argp;
233 	CLIENT *clnt;
234 {
235 	static char res;
236 
237 	bzero((char *)&res, sizeof(res));
238 	if (clnt_call(clnt, NLM_GRANTED_RES, xdr_nlm_res, argp, xdr_void, &res, TIMEOUT) != RPC_SUCCESS) {
239 		return (NULL);
240 	}
241 	return ((void *)&res);
242 }
243 
244 
245 nlm_shareres *
246 nlm_share_3(argp, clnt)
247 	nlm_shareargs *argp;
248 	CLIENT *clnt;
249 {
250 	static nlm_shareres res;
251 
252 	bzero((char *)&res, sizeof(res));
253 	if (clnt_call(clnt, NLM_SHARE, xdr_nlm_shareargs, argp, xdr_nlm_shareres, &res, TIMEOUT) != RPC_SUCCESS) {
254 		return (NULL);
255 	}
256 	return (&res);
257 }
258 
259 
260 nlm_shareres *
261 nlm_unshare_3(argp, clnt)
262 	nlm_shareargs *argp;
263 	CLIENT *clnt;
264 {
265 	static nlm_shareres res;
266 
267 	bzero((char *)&res, sizeof(res));
268 	if (clnt_call(clnt, NLM_UNSHARE, xdr_nlm_shareargs, argp, xdr_nlm_shareres, &res, TIMEOUT) != RPC_SUCCESS) {
269 		return (NULL);
270 	}
271 	return (&res);
272 }
273 
274 
275 nlm_res *
276 nlm_nm_lock_3(argp, clnt)
277 	nlm_lockargs *argp;
278 	CLIENT *clnt;
279 {
280 	static nlm_res res;
281 
282 	bzero((char *)&res, sizeof(res));
283 	if (clnt_call(clnt, NLM_NM_LOCK, xdr_nlm_lockargs, argp, xdr_nlm_res, &res, TIMEOUT) != RPC_SUCCESS) {
284 		return (NULL);
285 	}
286 	return (&res);
287 }
288 
289 
290 void *
291 nlm_free_all_3(argp, clnt)
292 	nlm_notify *argp;
293 	CLIENT *clnt;
294 {
295 	static char res;
296 
297 	bzero((char *)&res, sizeof(res));
298 	if (clnt_call(clnt, NLM_FREE_ALL, xdr_nlm_notify, argp, xdr_void, &res, TIMEOUT) != RPC_SUCCESS) {
299 		return (NULL);
300 	}
301 	return ((void *)&res);
302 }
303 
304 
305 int main(int argc, char **argv)
306 {
307   CLIENT *cli;
308   nlm_res res_block;
309   nlm_res *out;
310   nlm_lockargs arg;
311   struct timeval tim;
312 
313   if (argc != 2)
314   {
315 	printf("usage: %s <lockd hostname>\n", argv[0]);
316 	exit(1);
317   }
318 
319 
320   printf("Creating client for host %s\n", argv[1]);
321   cli = clnt_create(argv[1], NLM_PROG, NLM_VERS, "udp");
322   if (!cli)
323   {
324     printf("Failed to create client\n");
325     exit(1);
326   }
327 
328 
329   clnt_control(cli, CLGET_TIMEOUT, &tim);
330   printf("Default timeout was %d.%d\n", tim.tv_sec, tim.tv_usec);
331   tim.tv_usec = -1;
332   tim.tv_sec = -1;
333   clnt_control(cli, CLSET_TIMEOUT, &tim);
334   clnt_control(cli, CLGET_TIMEOUT, &tim);
335   printf("timeout now %d.%d\n", tim.tv_sec, tim.tv_usec);
336 
337 
338   arg.cookie.n_len = 4;
339   arg.cookie.n_bytes = "hello";
340   arg.block = 0;
341   arg.exclusive = 0;
342   arg.reclaim = 0;
343   arg.state = 0x1234;
344   arg.alock.caller_name = "localhost";
345   arg.alock.fh.n_len = 32;
346   arg.alock.fh.n_bytes = "\x04\x04\x02\x00\x01\x00\x00\x00\x0c\x00\x00\x00\xff\xff\xff\xd0\x16\x00\x00\x5b\x7c\xff\xff\xff\xec\x2f\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x19\x54\xef\xbf\xd7\x94";
347   arg.alock.oh.n_len = 8;
348   arg.alock.oh.n_bytes = "\x00\x00\x02\xff\xff\xff\xd3";
349   arg.alock.svid = 0x5678;
350   arg.alock.l_offset = 0;
351   arg.alock.l_len = 100;
352 
353   res_block.stat.stat = nlm_granted;
354   res_block.cookie.n_bytes = "hello";
355   res_block.cookie.n_len = 5;
356 
357 #if 0
358   if (nlm_lock_res_1(&res_block, cli)) printf("Success!\n");
359   else printf("Fail\n");
360 #else
361   if (out = nlm_lock_msg_1(&arg, cli))
362   {
363     printf("Success!\n");
364     printf("out->stat = %d", out->stat);
365   }
366   else
367   {
368     printf("Fail\n");
369   }
370 #endif
371 
372   return 0;
373 }
374