xref: /openbsd-src/usr.sbin/rpc.lockd/test.c (revision 54baf1aaf689530344dad21f273614fb3ac5cea7)
1*54baf1aaSjsg /*	$OpenBSD: test.c,v 1.7 2015/09/05 09:38:23 jsg Exp $	*/
22950da7fSmillert 
3084c2ccbSderaadt #include <rpc/rpc.h>
4084c2ccbSderaadt #include <rpcsvc/nlm_prot.h>
5084c2ccbSderaadt 
6084c2ccbSderaadt /* Default timeout can be changed using clnt_control() */
7084c2ccbSderaadt static struct timeval TIMEOUT = {0, 0};
8084c2ccbSderaadt 
9084c2ccbSderaadt nlm_testres *
nlm_test_1(struct nlm_testargs * argp,CLIENT * clnt)102557badaSderaadt nlm_test_1(struct nlm_testargs *argp, CLIENT *clnt)
11084c2ccbSderaadt {
12084c2ccbSderaadt 	static nlm_testres res;
13084c2ccbSderaadt 
14084c2ccbSderaadt 	bzero((char *) &res, sizeof(res));
152557badaSderaadt 	if (clnt_call(clnt, NLM_TEST, xdr_nlm_testargs, argp, xdr_nlm_testres,
162557badaSderaadt 	    &res, TIMEOUT) != RPC_SUCCESS) {
17084c2ccbSderaadt 		return (NULL);
18084c2ccbSderaadt 	}
19084c2ccbSderaadt 	return (&res);
20084c2ccbSderaadt }
21084c2ccbSderaadt 
22084c2ccbSderaadt 
23084c2ccbSderaadt nlm_res *
nlm_lock_1(struct nlm_lockargs * argp,CLIENT * clnt)242557badaSderaadt nlm_lock_1(struct nlm_lockargs *argp, CLIENT *clnt)
25084c2ccbSderaadt {
26084c2ccbSderaadt 	enum clnt_stat st;
27084c2ccbSderaadt 	static nlm_res res;
28084c2ccbSderaadt 
29084c2ccbSderaadt 	bzero((char *) &res, sizeof(res));
30*54baf1aaSjsg 	if ((st = clnt_call(clnt, NLM_LOCK, xdr_nlm_lockargs, argp, xdr_nlm_res,
31*54baf1aaSjsg 	    &res, TIMEOUT)) != RPC_SUCCESS) {
32084c2ccbSderaadt 		printf("clnt_call returns %d\n", st);
33084c2ccbSderaadt 		clnt_perror(clnt, "humbug");
34084c2ccbSderaadt 		return (NULL);
35084c2ccbSderaadt 	}
36084c2ccbSderaadt 	return (&res);
37084c2ccbSderaadt }
38084c2ccbSderaadt 
39084c2ccbSderaadt 
40084c2ccbSderaadt nlm_res *
nlm_cancel_1(struct nlm_cancargs * argp,CLIENT * clnt)412557badaSderaadt nlm_cancel_1(struct nlm_cancargs *argp, CLIENT *clnt)
42084c2ccbSderaadt {
43084c2ccbSderaadt 	static nlm_res res;
44084c2ccbSderaadt 
45084c2ccbSderaadt 	bzero((char *) &res, sizeof(res));
462557badaSderaadt 	if (clnt_call(clnt, NLM_CANCEL, xdr_nlm_cancargs, argp, xdr_nlm_res,
472557badaSderaadt 	    &res, TIMEOUT) != RPC_SUCCESS) {
48084c2ccbSderaadt 		return (NULL);
49084c2ccbSderaadt 	}
50084c2ccbSderaadt 	return (&res);
51084c2ccbSderaadt }
52084c2ccbSderaadt 
53084c2ccbSderaadt 
54084c2ccbSderaadt nlm_res *
nlm_unlock_1(struct nlm_unlockargs * argp,CLIENT * clnt)552557badaSderaadt nlm_unlock_1(struct nlm_unlockargs *argp, CLIENT *clnt)
56084c2ccbSderaadt {
57084c2ccbSderaadt 	static nlm_res res;
58084c2ccbSderaadt 
59084c2ccbSderaadt 	bzero((char *) &res, sizeof(res));
602557badaSderaadt 	if (clnt_call(clnt, NLM_UNLOCK, xdr_nlm_unlockargs, argp, xdr_nlm_res,
612557badaSderaadt 	    &res, TIMEOUT) != RPC_SUCCESS) {
62084c2ccbSderaadt 		return (NULL);
63084c2ccbSderaadt 	}
64084c2ccbSderaadt 	return (&res);
65084c2ccbSderaadt }
66084c2ccbSderaadt 
67084c2ccbSderaadt 
68084c2ccbSderaadt nlm_res *
nlm_granted_1(struct nlm_testargs * argp,CLIENT * clnt)692557badaSderaadt nlm_granted_1(struct nlm_testargs *argp, CLIENT *clnt)
70084c2ccbSderaadt {
71084c2ccbSderaadt 	static nlm_res res;
72084c2ccbSderaadt 
73084c2ccbSderaadt 	bzero((char *) &res, sizeof(res));
742557badaSderaadt 	if (clnt_call(clnt, NLM_GRANTED, xdr_nlm_testargs, argp, xdr_nlm_res,
752557badaSderaadt 	    &res, TIMEOUT) != RPC_SUCCESS) {
76084c2ccbSderaadt 		return (NULL);
77084c2ccbSderaadt 	}
78084c2ccbSderaadt 	return (&res);
79084c2ccbSderaadt }
80084c2ccbSderaadt 
81084c2ccbSderaadt 
82084c2ccbSderaadt void   *
nlm_test_msg_1(struct nlm_testargs * argp,CLIENT * clnt)832557badaSderaadt nlm_test_msg_1(struct nlm_testargs *argp, CLIENT *clnt)
84084c2ccbSderaadt {
85084c2ccbSderaadt 	static char res;
86084c2ccbSderaadt 
87084c2ccbSderaadt 	bzero((char *) &res, sizeof(res));
882557badaSderaadt 	if (clnt_call(clnt, NLM_TEST_MSG, xdr_nlm_testargs, argp, xdr_void,
892557badaSderaadt 	    &res, TIMEOUT) != RPC_SUCCESS) {
90084c2ccbSderaadt 		return (NULL);
91084c2ccbSderaadt 	}
92084c2ccbSderaadt 	return ((void *) &res);
93084c2ccbSderaadt }
94084c2ccbSderaadt 
95084c2ccbSderaadt 
96084c2ccbSderaadt void   *
nlm_lock_msg_1(struct nlm_lockargs * argp,CLIENT * clnt)972557badaSderaadt nlm_lock_msg_1(struct nlm_lockargs *argp, CLIENT *clnt)
98084c2ccbSderaadt {
99084c2ccbSderaadt 	static char res;
100084c2ccbSderaadt 
101084c2ccbSderaadt 	bzero((char *) &res, sizeof(res));
102084c2ccbSderaadt 	if (clnt_call(clnt, NLM_LOCK_MSG, xdr_nlm_lockargs, argp, xdr_void, NULL, TIMEOUT) != RPC_SUCCESS) {
103084c2ccbSderaadt 		clnt_perror(clnt, "nlm_lock_msg_1");
104084c2ccbSderaadt 		return (NULL);
105084c2ccbSderaadt 	}
106084c2ccbSderaadt 	return ((void *) &res);
107084c2ccbSderaadt }
108084c2ccbSderaadt 
109084c2ccbSderaadt 
110084c2ccbSderaadt void   *
nlm_cancel_msg_1(struct nlm_cancargs * argp,CLIENT * clnt)1112557badaSderaadt nlm_cancel_msg_1(struct nlm_cancargs *argp, CLIENT *clnt)
112084c2ccbSderaadt {
113084c2ccbSderaadt 	static char res;
114084c2ccbSderaadt 
115084c2ccbSderaadt 	bzero((char *) &res, sizeof(res));
1162557badaSderaadt 	if (clnt_call(clnt, NLM_CANCEL_MSG, xdr_nlm_cancargs, argp, xdr_void,
1172557badaSderaadt 	    &res, TIMEOUT) != RPC_SUCCESS) {
118084c2ccbSderaadt 		return (NULL);
119084c2ccbSderaadt 	}
120084c2ccbSderaadt 	return ((void *) &res);
121084c2ccbSderaadt }
122084c2ccbSderaadt 
123084c2ccbSderaadt 
124084c2ccbSderaadt void   *
nlm_unlock_msg_1(struct nlm_unlockargs * argp,CLIENT * clnt)1252557badaSderaadt nlm_unlock_msg_1(struct nlm_unlockargs *argp, CLIENT *clnt)
126084c2ccbSderaadt {
127084c2ccbSderaadt 	static char res;
128084c2ccbSderaadt 
129084c2ccbSderaadt 	bzero((char *) &res, sizeof(res));
1302557badaSderaadt 	if (clnt_call(clnt, NLM_UNLOCK_MSG, xdr_nlm_unlockargs, argp, xdr_void,
1312557badaSderaadt 	    &res, TIMEOUT) != RPC_SUCCESS) {
132084c2ccbSderaadt 		return (NULL);
133084c2ccbSderaadt 	}
134084c2ccbSderaadt 	return ((void *) &res);
135084c2ccbSderaadt }
136084c2ccbSderaadt 
137084c2ccbSderaadt 
138084c2ccbSderaadt void   *
nlm_granted_msg_1(struct nlm_testargs * argp,CLIENT * clnt)1392557badaSderaadt nlm_granted_msg_1(struct nlm_testargs *argp, CLIENT *clnt)
140084c2ccbSderaadt {
141084c2ccbSderaadt 	static char res;
142084c2ccbSderaadt 
143084c2ccbSderaadt 	bzero((char *) &res, sizeof(res));
1442557badaSderaadt 	if (clnt_call(clnt, NLM_GRANTED_MSG, xdr_nlm_testargs, argp, xdr_void,
1452557badaSderaadt 	    &res, TIMEOUT) != RPC_SUCCESS) {
146084c2ccbSderaadt 		return (NULL);
147084c2ccbSderaadt 	}
148084c2ccbSderaadt 	return ((void *) &res);
149084c2ccbSderaadt }
150084c2ccbSderaadt 
151084c2ccbSderaadt 
152084c2ccbSderaadt void   *
nlm_test_res_1(nlm_testres * argp,CLIENT * clnt)1532557badaSderaadt nlm_test_res_1(nlm_testres *argp, CLIENT *clnt)
154084c2ccbSderaadt {
155084c2ccbSderaadt 	static char res;
156084c2ccbSderaadt 
157084c2ccbSderaadt 	bzero((char *) &res, sizeof(res));
1582557badaSderaadt 	if (clnt_call(clnt, NLM_TEST_RES, xdr_nlm_testres, argp, xdr_void,
1592557badaSderaadt 	    &res, TIMEOUT) != RPC_SUCCESS) {
160084c2ccbSderaadt 		return (NULL);
161084c2ccbSderaadt 	}
162084c2ccbSderaadt 	return ((void *) &res);
163084c2ccbSderaadt }
164084c2ccbSderaadt 
165084c2ccbSderaadt 
166084c2ccbSderaadt void   *
nlm_lock_res_1(nlm_res * argp,CLIENT * clnt)1672557badaSderaadt nlm_lock_res_1(nlm_res *argp, CLIENT *clnt)
168084c2ccbSderaadt {
169084c2ccbSderaadt 	static char res;
170084c2ccbSderaadt 
171084c2ccbSderaadt 	bzero((char *) &res, sizeof(res));
1722557badaSderaadt 	if (clnt_call(clnt, NLM_LOCK_RES, xdr_nlm_res, argp, xdr_void,
1732557badaSderaadt 	    &res, TIMEOUT) != RPC_SUCCESS) {
174084c2ccbSderaadt 		return (NULL);
175084c2ccbSderaadt 	}
176084c2ccbSderaadt 	return ((void *) &res);
177084c2ccbSderaadt }
178084c2ccbSderaadt 
179084c2ccbSderaadt 
180084c2ccbSderaadt void   *
nlm_cancel_res_1(nlm_res * argp,CLIENT * clnt)1812557badaSderaadt nlm_cancel_res_1(nlm_res *argp, CLIENT *clnt)
182084c2ccbSderaadt {
183084c2ccbSderaadt 	static char res;
184084c2ccbSderaadt 
185084c2ccbSderaadt 	bzero((char *) &res, sizeof(res));
1862557badaSderaadt 	if (clnt_call(clnt, NLM_CANCEL_RES, xdr_nlm_res, argp, xdr_void,
1872557badaSderaadt 	    &res, TIMEOUT) != RPC_SUCCESS) {
188084c2ccbSderaadt 		return (NULL);
189084c2ccbSderaadt 	}
190084c2ccbSderaadt 	return ((void *) &res);
191084c2ccbSderaadt }
192084c2ccbSderaadt 
193084c2ccbSderaadt 
194084c2ccbSderaadt void   *
nlm_unlock_res_1(nlm_res * argp,CLIENT * clnt)1952557badaSderaadt nlm_unlock_res_1(nlm_res *argp, CLIENT *clnt)
196084c2ccbSderaadt {
197084c2ccbSderaadt 	static char res;
198084c2ccbSderaadt 
199084c2ccbSderaadt 	bzero((char *) &res, sizeof(res));
2002557badaSderaadt 	if (clnt_call(clnt, NLM_UNLOCK_RES, xdr_nlm_res, argp, xdr_void,
2012557badaSderaadt 	    &res, TIMEOUT) != RPC_SUCCESS) {
202084c2ccbSderaadt 		return (NULL);
203084c2ccbSderaadt 	}
204084c2ccbSderaadt 	return ((void *) &res);
205084c2ccbSderaadt }
206084c2ccbSderaadt 
207084c2ccbSderaadt 
208084c2ccbSderaadt void   *
nlm_granted_res_1(nlm_res * argp,CLIENT * clnt)2092557badaSderaadt nlm_granted_res_1(nlm_res *argp, CLIENT *clnt)
210084c2ccbSderaadt {
211084c2ccbSderaadt 	static char res;
212084c2ccbSderaadt 
213084c2ccbSderaadt 	bzero((char *) &res, sizeof(res));
2142557badaSderaadt 	if (clnt_call(clnt, NLM_GRANTED_RES, xdr_nlm_res, argp, xdr_void,
2152557badaSderaadt 	    &res, TIMEOUT) != RPC_SUCCESS) {
216084c2ccbSderaadt 		return (NULL);
217084c2ccbSderaadt 	}
218084c2ccbSderaadt 	return ((void *) &res);
219084c2ccbSderaadt }
220084c2ccbSderaadt 
221084c2ccbSderaadt 
222084c2ccbSderaadt nlm_shareres *
nlm_share_3(nlm_shareargs * argp,CLIENT * clnt)2232557badaSderaadt nlm_share_3(nlm_shareargs *argp, CLIENT *clnt)
224084c2ccbSderaadt {
225084c2ccbSderaadt 	static nlm_shareres res;
226084c2ccbSderaadt 
227084c2ccbSderaadt 	bzero((char *) &res, sizeof(res));
2282557badaSderaadt 	if (clnt_call(clnt, NLM_SHARE, xdr_nlm_shareargs, argp, xdr_nlm_shareres,
2292557badaSderaadt 	    &res, TIMEOUT) != RPC_SUCCESS) {
230084c2ccbSderaadt 		return (NULL);
231084c2ccbSderaadt 	}
232084c2ccbSderaadt 	return (&res);
233084c2ccbSderaadt }
234084c2ccbSderaadt 
235084c2ccbSderaadt 
236084c2ccbSderaadt nlm_shareres *
nlm_unshare_3(nlm_shareargs * argp,CLIENT * clnt)2372557badaSderaadt nlm_unshare_3(nlm_shareargs *argp, CLIENT *clnt)
238084c2ccbSderaadt {
239084c2ccbSderaadt 	static nlm_shareres res;
240084c2ccbSderaadt 
241084c2ccbSderaadt 	bzero((char *) &res, sizeof(res));
2422557badaSderaadt 	if (clnt_call(clnt, NLM_UNSHARE, xdr_nlm_shareargs, argp, xdr_nlm_shareres,
2432557badaSderaadt 	    &res, TIMEOUT) != RPC_SUCCESS) {
244084c2ccbSderaadt 		return (NULL);
245084c2ccbSderaadt 	}
246084c2ccbSderaadt 	return (&res);
247084c2ccbSderaadt }
248084c2ccbSderaadt 
249084c2ccbSderaadt 
250084c2ccbSderaadt nlm_res *
nlm_nm_lock_3(nlm_lockargs * argp,CLIENT * clnt)2512557badaSderaadt nlm_nm_lock_3(nlm_lockargs *argp, CLIENT *clnt)
252084c2ccbSderaadt {
253084c2ccbSderaadt 	static nlm_res res;
254084c2ccbSderaadt 
255084c2ccbSderaadt 	bzero((char *) &res, sizeof(res));
2562557badaSderaadt 	if (clnt_call(clnt, NLM_NM_LOCK, xdr_nlm_lockargs, argp, xdr_nlm_res,
2572557badaSderaadt 	    &res, TIMEOUT) != RPC_SUCCESS) {
258084c2ccbSderaadt 		return (NULL);
259084c2ccbSderaadt 	}
260084c2ccbSderaadt 	return (&res);
261084c2ccbSderaadt }
262084c2ccbSderaadt 
263084c2ccbSderaadt 
264084c2ccbSderaadt void   *
nlm_free_all_3(nlm_notify * argp,CLIENT * clnt)2652557badaSderaadt nlm_free_all_3(nlm_notify *argp, CLIENT *clnt)
266084c2ccbSderaadt {
267084c2ccbSderaadt 	static char res;
268084c2ccbSderaadt 
269084c2ccbSderaadt 	bzero((char *) &res, sizeof(res));
2702557badaSderaadt 	if (clnt_call(clnt, NLM_FREE_ALL, xdr_nlm_notify, argp, xdr_void,
2712557badaSderaadt 	    &res, TIMEOUT) != RPC_SUCCESS) {
272084c2ccbSderaadt 		return (NULL);
273084c2ccbSderaadt 	}
274084c2ccbSderaadt 	return ((void *) &res);
275084c2ccbSderaadt }
276084c2ccbSderaadt 
277084c2ccbSderaadt 
278252f0718Sderaadt int
main(int argc,char ** argv)279252f0718Sderaadt main(int argc, char **argv)
280084c2ccbSderaadt {
281084c2ccbSderaadt 	CLIENT *cli;
282084c2ccbSderaadt 	nlm_res res_block;
283084c2ccbSderaadt 	nlm_res *out;
284084c2ccbSderaadt 	nlm_lockargs arg;
285084c2ccbSderaadt 	struct timeval tim;
286084c2ccbSderaadt 
287084c2ccbSderaadt 	printf("Creating client for host %s\n", argv[1]);
288084c2ccbSderaadt 	cli = clnt_create(argv[1], NLM_PROG, NLM_VERS, "udp");
289252f0718Sderaadt 	if (!cli) {
290084c2ccbSderaadt 		printf("Failed to create client\n");
291084c2ccbSderaadt 		exit(1);
292084c2ccbSderaadt 	}
293084c2ccbSderaadt 	clnt_control(cli, CLGET_TIMEOUT, &tim);
2945bfbc77eSderaadt 	printf("Default timeout was %lld.%ld\n", (long long)tim.tv_sec,
2955bfbc77eSderaadt 	    tim.tv_usec);
296084c2ccbSderaadt 	tim.tv_usec = -1;
297084c2ccbSderaadt 	tim.tv_sec = -1;
298084c2ccbSderaadt 	clnt_control(cli, CLSET_TIMEOUT, &tim);
299084c2ccbSderaadt 	clnt_control(cli, CLGET_TIMEOUT, &tim);
3005bfbc77eSderaadt 	printf("timeout now %lld.%ld\n", (long long)tim.tv_sec,
3015bfbc77eSderaadt 	    tim.tv_usec);
302084c2ccbSderaadt 
303084c2ccbSderaadt 	arg.cookie.n_len = 4;
304084c2ccbSderaadt 	arg.cookie.n_bytes = "hello";
305084c2ccbSderaadt 	arg.block = 0;
306084c2ccbSderaadt 	arg.exclusive = 0;
307084c2ccbSderaadt 	arg.reclaim = 0;
308084c2ccbSderaadt 	arg.state = 0x1234;
309084c2ccbSderaadt 	arg.alock.caller_name = "localhost";
310084c2ccbSderaadt 	arg.alock.fh.n_len = 32;
311084c2ccbSderaadt 	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";
312084c2ccbSderaadt 	arg.alock.oh.n_len = 8;
313084c2ccbSderaadt 	arg.alock.oh.n_bytes = "\x00\x00\x02\xff\xff\xff\xd3";
314084c2ccbSderaadt 	arg.alock.svid = 0x5678;
315084c2ccbSderaadt 	arg.alock.l_offset = 0;
316084c2ccbSderaadt 	arg.alock.l_len = 100;
317084c2ccbSderaadt 
318084c2ccbSderaadt 	res_block.stat.stat = nlm_granted;
319084c2ccbSderaadt 	res_block.cookie.n_bytes = "hello";
320084c2ccbSderaadt 	res_block.cookie.n_len = 5;
321084c2ccbSderaadt 
322084c2ccbSderaadt #if 0
323252f0718Sderaadt 	if (nlm_lock_res_1(&res_block, cli))
324252f0718Sderaadt 		printf("Success!\n");
325252f0718Sderaadt 	else
326252f0718Sderaadt 		printf("Fail\n");
327084c2ccbSderaadt #else
328252f0718Sderaadt 	if (out = nlm_lock_msg_1(&arg, cli)) {
329084c2ccbSderaadt 		printf("Success!\n");
330084c2ccbSderaadt 		printf("out->stat = %d", out->stat);
331252f0718Sderaadt 	} else {
332084c2ccbSderaadt 		printf("Fail\n");
333084c2ccbSderaadt 	}
334084c2ccbSderaadt #endif
335084c2ccbSderaadt 
336084c2ccbSderaadt 	return 0;
337084c2ccbSderaadt }
338