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