2 Copyright (C) 2010 by Ronnie Sahlberg <ronniesahlberg@gmail.com>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as published by
6 the Free Software Foundation; either version 2.1 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program; if not, see <http://www.gnu.org/licenses/>.
18 #include "win32_compat.h"
22 #include "libnfs-zdr.h"
24 #include "libnfs-raw.h"
25 #include "libnfs-private.h"
26 #include "libnfs-raw-portmap.h"
31 int rpc_pmap2_null_async(struct rpc_context
*rpc
, rpc_cb cb
, void *private_data
)
35 pdu
= rpc_allocate_pdu(rpc
, PMAP_PROGRAM
, PMAP_V2
, PMAP2_NULL
, cb
, private_data
, (zdrproc_t
)zdr_void
, 0);
37 rpc_set_error(rpc
, "Out of memory. Failed to allocate pdu for PORTMAP2/NULL call");
41 if (rpc_queue_pdu(rpc
, pdu
) != 0) {
42 rpc_set_error(rpc
, "Out of memory. Failed to queue pdu for PORTMAP2/NULL call");
43 rpc_free_pdu(rpc
, pdu
);
50 int rpc_pmap2_getport_async(struct rpc_context
*rpc
, int program
, int version
, int protocol
, rpc_cb cb
, void *private_data
)
53 struct pmap2_mapping m
;
55 pdu
= rpc_allocate_pdu(rpc
, PMAP_PROGRAM
, PMAP_V2
, PMAP2_GETPORT
, cb
, private_data
, (zdrproc_t
)zdr_int
, sizeof(uint32_t));
57 rpc_set_error(rpc
, "Out of memory. Failed to allocate pdu for PORTMAP2/GETPORT call");
65 if (zdr_pmap2_mapping(&pdu
->zdr
, &m
) == 0) {
66 rpc_set_error(rpc
, "ZDR error: Failed to encode data for PORTMAP2/GETPORT call");
67 rpc_free_pdu(rpc
, pdu
);
71 if (rpc_queue_pdu(rpc
, pdu
) != 0) {
72 rpc_set_error(rpc
, "Failed to queue PORTMAP2/GETPORT pdu");
73 rpc_free_pdu(rpc
, pdu
);
80 int rpc_pmap2_set_async(struct rpc_context
*rpc
, int program
, int version
, int protocol
, int port
, rpc_cb cb
, void *private_data
)
83 struct pmap2_mapping m
;
85 pdu
= rpc_allocate_pdu(rpc
, PMAP_PROGRAM
, PMAP_V2
, PMAP2_SET
, cb
, private_data
, (zdrproc_t
)zdr_int
, sizeof(uint32_t));
87 rpc_set_error(rpc
, "Out of memory. Failed to allocate pdu for PORTMAP2/SET call");
95 if (zdr_pmap2_mapping(&pdu
->zdr
, &m
) == 0) {
96 rpc_set_error(rpc
, "ZDR error: Failed to encode data for PORTMAP2/SET call");
97 rpc_free_pdu(rpc
, pdu
);
101 if (rpc_queue_pdu(rpc
, pdu
) != 0) {
102 rpc_set_error(rpc
, "Failed to queue PORTMAP2/SET pdu");
103 rpc_free_pdu(rpc
, pdu
);
110 int rpc_pmap2_unset_async(struct rpc_context
*rpc
, int program
, int version
, int protocol
, int port
, rpc_cb cb
, void *private_data
)
113 struct pmap2_mapping m
;
115 pdu
= rpc_allocate_pdu(rpc
, PMAP_PROGRAM
, PMAP_V2
, PMAP2_UNSET
, cb
, private_data
, (zdrproc_t
)zdr_int
, sizeof(uint32_t));
117 rpc_set_error(rpc
, "Out of memory. Failed to allocate pdu for PORTMAP2/UNSET call");
125 if (zdr_pmap2_mapping(&pdu
->zdr
, &m
) == 0) {
126 rpc_set_error(rpc
, "ZDR error: Failed to encode data for PORTMAP2/UNSET call");
127 rpc_free_pdu(rpc
, pdu
);
131 if (rpc_queue_pdu(rpc
, pdu
) != 0) {
132 rpc_set_error(rpc
, "Failed to queue PORTMAP2/UNSET pdu");
133 rpc_free_pdu(rpc
, pdu
);
140 int rpc_pmap2_dump_async(struct rpc_context
*rpc
, rpc_cb cb
, void *private_data
)
144 pdu
= rpc_allocate_pdu(rpc
, PMAP_PROGRAM
, PMAP_V2
, PMAP2_DUMP
, cb
, private_data
, (zdrproc_t
)zdr_pmap2_dump_result
, sizeof(pmap2_dump_result
));
146 rpc_set_error(rpc
, "Out of memory. Failed to allocate pdu for PORTMAP2/DUMP call");
150 if (rpc_queue_pdu(rpc
, pdu
) != 0) {
151 rpc_set_error(rpc
, "Failed to queue PORTMAP2/DUMP pdu");
152 rpc_free_pdu(rpc
, pdu
);
159 int rpc_pmap2_callit_async(struct rpc_context
*rpc
, int program
, int version
, int procedure
, char *data
, int datalen
, rpc_cb cb
, void *private_data
)
162 struct pmap2_call_args ca
;
164 pdu
= rpc_allocate_pdu(rpc
, PMAP_PROGRAM
, PMAP_V2
, PMAP2_CALLIT
, cb
, private_data
, (zdrproc_t
)zdr_pmap2_call_result
, sizeof(pmap2_call_result
));
166 rpc_set_error(rpc
, "Out of memory. Failed to allocate pdu for PORTMAP2/CALLIT call");
173 ca
.args
.args_len
= datalen
;
174 ca
.args
.args_val
= data
;
176 if (zdr_pmap2_call_args(&pdu
->zdr
, &ca
) == 0) {
177 rpc_set_error(rpc
, "ZDR error: Failed to encode data for PORTMAP2/CALLIT call");
178 rpc_free_pdu(rpc
, pdu
);
182 if (rpc_queue_pdu(rpc
, pdu
) != 0) {
183 rpc_set_error(rpc
, "Failed to queue PORTMAP2/CALLIT pdu: %s", rpc_get_error(rpc
));
193 int rpc_pmap3_null_async(struct rpc_context
*rpc
, rpc_cb cb
, void *private_data
)
197 pdu
= rpc_allocate_pdu(rpc
, PMAP_PROGRAM
, PMAP_V3
, PMAP3_NULL
, cb
, private_data
, (zdrproc_t
)zdr_void
, 0);
199 rpc_set_error(rpc
, "Out of memory. Failed to allocate pdu for PORTMAP3/NULL call");
203 if (rpc_queue_pdu(rpc
, pdu
) != 0) {
204 rpc_set_error(rpc
, "Out of memory. Failed to queue pdu for PORTMAP3/NULL call");
205 rpc_free_pdu(rpc
, pdu
);
212 int rpc_pmap3_set_async(struct rpc_context
*rpc
, struct pmap3_mapping
*map
, rpc_cb cb
, void *private_data
)
216 pdu
= rpc_allocate_pdu(rpc
, PMAP_PROGRAM
, PMAP_V3
, PMAP3_SET
, cb
, private_data
, (zdrproc_t
)zdr_int
, sizeof(uint32_t));
218 rpc_set_error(rpc
, "Out of memory. Failed to allocate pdu for PORTMAP3/SET call");
222 if (zdr_pmap3_mapping(&pdu
->zdr
, map
) == 0) {
223 rpc_set_error(rpc
, "ZDR error: Failed to encode data for PORTMAP3/SET call");
224 rpc_free_pdu(rpc
, pdu
);
228 if (rpc_queue_pdu(rpc
, pdu
) != 0) {
229 rpc_set_error(rpc
, "Failed to queue PORTMAP3/SET pdu");
230 rpc_free_pdu(rpc
, pdu
);
237 int rpc_pmap3_unset_async(struct rpc_context
*rpc
, struct pmap3_mapping
*map
, rpc_cb cb
, void *private_data
)
241 pdu
= rpc_allocate_pdu(rpc
, PMAP_PROGRAM
, PMAP_V3
, PMAP3_UNSET
, cb
, private_data
, (zdrproc_t
)zdr_int
, sizeof(uint32_t));
243 rpc_set_error(rpc
, "Out of memory. Failed to allocate pdu for PORTMAP3/UNSET call");
247 if (zdr_pmap3_mapping(&pdu
->zdr
, map
) == 0) {
248 rpc_set_error(rpc
, "ZDR error: Failed to encode data for PORTMAP3/UNSET call");
249 rpc_free_pdu(rpc
, pdu
);
253 if (rpc_queue_pdu(rpc
, pdu
) != 0) {
254 rpc_set_error(rpc
, "Failed to queue PORTMAP3/UNSET pdu");
255 rpc_free_pdu(rpc
, pdu
);
262 int rpc_pmap3_getaddr_async(struct rpc_context
*rpc
, struct pmap3_mapping
*map
, rpc_cb cb
, void *private_data
)
266 pdu
= rpc_allocate_pdu(rpc
, PMAP_PROGRAM
, PMAP_V3
, PMAP3_GETADDR
, cb
, private_data
, (zdrproc_t
)zdr_pmap3_string_result
, sizeof(pmap3_string_result
));
268 rpc_set_error(rpc
, "Out of memory. Failed to allocate pdu for PORTMAP3/GETADDR call");
272 if (zdr_pmap3_mapping(&pdu
->zdr
, map
) == 0) {
273 rpc_set_error(rpc
, "ZDR error: Failed to encode data for PORTMAP3/GETADDR call");
274 rpc_free_pdu(rpc
, pdu
);
278 if (rpc_queue_pdu(rpc
, pdu
) != 0) {
279 rpc_set_error(rpc
, "Failed to queue PORTMAP3/GETADDR pdu");
280 rpc_free_pdu(rpc
, pdu
);
287 int rpc_pmap3_dump_async(struct rpc_context
*rpc
, rpc_cb cb
, void *private_data
)
291 pdu
= rpc_allocate_pdu(rpc
, PMAP_PROGRAM
, PMAP_V3
, PMAP3_DUMP
, cb
, private_data
, (zdrproc_t
)zdr_pmap3_dump_result
, sizeof(pmap3_dump_result
));
293 rpc_set_error(rpc
, "Out of memory. Failed to allocate pdu for PORTMAP3/DUMP call");
297 if (rpc_queue_pdu(rpc
, pdu
) != 0) {
298 rpc_set_error(rpc
, "Failed to queue PORTMAP3/DUMP pdu");
299 rpc_free_pdu(rpc
, pdu
);
306 int rpc_pmap3_gettime_async(struct rpc_context
*rpc
, rpc_cb cb
, void *private_data
)
310 pdu
= rpc_allocate_pdu(rpc
, PMAP_PROGRAM
, PMAP_V3
, PMAP3_GETTIME
, cb
, private_data
, (zdrproc_t
)zdr_int
, sizeof(uint32_t));
312 rpc_set_error(rpc
, "Out of memory. Failed to allocate pdu for PORTMAP3/GETTIME call");
316 if (rpc_queue_pdu(rpc
, pdu
) != 0) {
317 rpc_set_error(rpc
, "Failed to queue PORTMAP3/GETTIME pdu");
318 rpc_free_pdu(rpc
, pdu
);
325 int rpc_pmap3_callit_async(struct rpc_context
*rpc
, int program
, int version
, int procedure
, char *data
, int datalen
, rpc_cb cb
, void *private_data
)
328 struct pmap3_call_args ca
;
330 pdu
= rpc_allocate_pdu(rpc
, PMAP_PROGRAM
, PMAP_V3
, PMAP3_CALLIT
, cb
, private_data
, (zdrproc_t
)zdr_pmap3_call_result
, sizeof(pmap3_call_result
));
332 rpc_set_error(rpc
, "Out of memory. Failed to allocate pdu for PORTMAP3/CALLIT call");
339 ca
.args
.args_len
= datalen
;
340 ca
.args
.args_val
= data
;
342 if (zdr_pmap3_call_args(&pdu
->zdr
, &ca
) == 0) {
343 rpc_set_error(rpc
, "ZDR error: Failed to encode data for PORTMAP3/CALLIT call");
344 rpc_free_pdu(rpc
, pdu
);
348 if (rpc_queue_pdu(rpc
, pdu
) != 0) {
349 rpc_set_error(rpc
, "Failed to queue PORTMAP3/CALLIT pdu: %s", rpc_get_error(rpc
));
356 int rpc_pmap3_uaddr2taddr_async(struct rpc_context
*rpc
, char *uaddr
, rpc_cb cb
, void *private_data
)
360 pdu
= rpc_allocate_pdu(rpc
, PMAP_PROGRAM
, PMAP_V3
, PMAP3_UADDR2TADDR
, cb
, private_data
, (zdrproc_t
)zdr_pmap3_netbuf
, sizeof(pmap3_netbuf
));
362 rpc_set_error(rpc
, "Out of memory. Failed to allocate pdu for PORTMAP3/UADDR2TADDR call");
366 if (zdr_string(&pdu
->zdr
, &uaddr
, 255) == 0) {
367 rpc_set_error(rpc
, "ZDR error: Failed to encode data for PORTMAP3/UADDR2TADDR call");
368 rpc_free_pdu(rpc
, pdu
);
372 if (rpc_queue_pdu(rpc
, pdu
) != 0) {
373 rpc_set_error(rpc
, "Failed to queue PORTMAP3/UADDR2TADDR pdu: %s", rpc_get_error(rpc
));
380 int rpc_pmap3_taddr2uaddr_async(struct rpc_context
*rpc
, struct pmap3_netbuf
*nb
, rpc_cb cb
, void *private_data
)
384 pdu
= rpc_allocate_pdu(rpc
, PMAP_PROGRAM
, PMAP_V3
, PMAP3_TADDR2UADDR
, cb
, private_data
, (zdrproc_t
)zdr_pmap3_string_result
, sizeof(pmap3_string_result
));
386 rpc_set_error(rpc
, "Out of memory. Failed to allocate pdu for PORTMAP3/TADDR2UADDR call");
390 if (zdr_pmap3_netbuf(&pdu
->zdr
, nb
) == 0) {
391 rpc_set_error(rpc
, "ZDR error: Failed to encode data for PORTMAP3/TADDR2UADDR call");
392 rpc_free_pdu(rpc
, pdu
);
396 if (rpc_queue_pdu(rpc
, pdu
) != 0) {
397 rpc_set_error(rpc
, "Failed to queue PORTMAP3/TADDR2UADDR pdu: %s", rpc_get_error(rpc
));