types: remove the [u_]quad type and replace with [u]int64
[deb_libnfs.git] / include / nfsc / libnfs-zdr.h
CommitLineData
763cd6e3
RS
1/*
2 Copyright (C) 2012 by Ronnie Sahlberg <ronniesahlberg@gmail.com>
3
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.
8
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.
13
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/>.
16*/
17/*
18 * This file contains definitions for the built in ZDR implementation.
19 * This is a very limited ZDR subset that can only marshal to/from a momory buffer,
20 * i.e. zdrmem_create() buffers.
21 * It aims to be compatible with normal rpcgen generated functions.
22 */
23
aab6538b
RS
24/************************************************************
25 * Definitions copied from RFC 5531
26 * and slightly modified.
27 ************************************************************/
28
763cd6e3
RS
29#ifndef _LIBNFS_ZDR_H_
30#define _LIBNFS_ZDR_H_
31
67a9f57e
RS
32#ifdef WIN32
33#ifndef CADDR_T_DEFINED
34#define CADDR_T_DEFINED
35typedef char *caddr_t;
36#endif
37#endif
38
763cd6e3
RS
39#include <stdio.h>
40#include <assert.h>
41#include <stdint.h>
42#include <sys/types.h>
43
a81c5ea1
AR
44#ifdef __cplusplus
45extern "C" {
46#endif
47
763cd6e3
RS
48#define _RPC_RPC_H 1
49#define _RPC_ZDR_H 1
50#define _RPC_AUTH_H 1
51
52/* we dont need these */
53typedef void CLIENT;
54struct svc_req {
67a9f57e 55 int _dummy_;
763cd6e3
RS
56};
57typedef void SVCXPRT;
58
59
60
61
62
63#define ZDR_INLINE(...) NULL
64#define IZDR_PUT_U_LONG(...) assert(0)
65#define IZDR_GET_U_LONG(...) (assert(0), 0)
66#define IZDR_PUT_LONG(...) assert(0)
67#define IZDR_GET_LONG(...) (assert(0), 0)
68#define IZDR_PUT_BOOL(...) assert(0)
69#define IZDR_GET_BOOL(...) (assert(0), 0)
70
d7c6e9aa 71#ifndef TRUE
763cd6e3 72#define TRUE 1
d7c6e9aa
RS
73#endif
74#ifndef FALSE
763cd6e3 75#define FALSE 0
d7c6e9aa 76#endif
763cd6e3
RS
77
78enum zdr_op {
79 ZDR_ENCODE = 0,
80 ZDR_DECODE = 1
81};
82
83struct zdr_mem {
84 struct zdr_mem *next;
85 caddr_t buf;
86 uint32_t size;
87};
88
89struct ZDR {
90 enum zdr_op x_op;
91 caddr_t buf;
92 int size;
93 int pos;
94 struct zdr_mem *mem;
95};
96typedef struct ZDR ZDR;
97
98
99typedef uint32_t u_int;
100typedef uint32_t enum_t;
101typedef uint32_t bool_t;
102
103typedef int (*zdrproc_t) (ZDR *, void *,...);
104
763cd6e3
RS
105#define AUTH_NONE 0
106#define AUTH_NULL 0
107#define AUTH_UNIX 1
aab6538b 108
763cd6e3
RS
109struct opaque_auth {
110 uint32_t oa_flavor;
111 caddr_t oa_base;
112 uint32_t oa_length;
113};
114extern struct opaque_auth _null_auth;
115
67ba2239 116struct AUTH {
763cd6e3
RS
117 struct opaque_auth ah_cred;
118 struct opaque_auth ah_verf;
119 caddr_t ah_private;
67ba2239 120};
763cd6e3 121
763cd6e3
RS
122#define RPC_MSG_VERSION 2
123
aab6538b
RS
124enum msg_type {
125 CALL = 0,
126 REPLY = 1
763cd6e3
RS
127};
128
aab6538b
RS
129enum reply_stat {
130 MSG_ACCEPTED=0,
131 MSG_DENIED=1
763cd6e3
RS
132};
133
aab6538b
RS
134enum accept_stat {
135 SUCCESS = 0,
136 PROG_UNAVAIL = 1,
137 PROG_MISMATCH = 2,
138 PROC_UNAVAIL = 3,
139 GARBAGE_ARGS = 4,
140 SYSTEM_ERR = 5
763cd6e3
RS
141};
142
143enum reject_stat {
aab6538b
RS
144 RPC_MISMATCH = 0,
145 AUTH_ERROR = 1
763cd6e3
RS
146};
147
148enum auth_stat {
149 AUTH_OK=0,
150 /*
151 * failed at remote end
152 */
aab6538b
RS
153 AUTH_BADCRED = 1, /* bogus credentials (seal broken) */
154 AUTH_REJECTEDCRED = 2, /* client should begin new session */
155 AUTH_BADVERF = 3, /* bogus verifier (seal broken) */
156 AUTH_REJECTEDVERF = 4, /* verifier expired or was replayed */
157 AUTH_TOOWEAK = 5, /* rejected due to security reasons */
763cd6e3
RS
158 /*
159 * failed locally
160 */
aab6538b
RS
161 AUTH_INVALIDRESP = 6, /* bogus response verifier */
162 AUTH_FAILED = 7 /* some unknown reason */
163};
164
165struct call_body {
166 uint32_t rpcvers;
167 uint32_t prog;
168 uint32_t vers;
169 uint32_t proc;
170 struct opaque_auth cred;
171 struct opaque_auth verf;
172};
173
174struct accepted_reply {
175 struct opaque_auth verf;
176 uint32_t stat;
177 union {
178 struct {
179 caddr_t where;
180 zdrproc_t proc;
181 } results;
182 struct {
183 uint32_t low;
184 uint32_t high;
185 } mismatch_info;
186 } reply_data;
763cd6e3
RS
187};
188
189struct rejected_reply {
aab6538b 190 enum reject_stat stat;
763cd6e3
RS
191 union {
192 struct {
d7c6e9aa
RS
193 uint32_t low;
194 uint32_t high;
aab6538b
RS
195 } mismatch_info;
196 enum auth_stat stat;
197 } reject_data;
763cd6e3
RS
198};
199
763cd6e3 200struct reply_body {
aab6538b 201 uint32_t stat;
763cd6e3 202 union {
aab6538b
RS
203 struct accepted_reply areply;
204 struct rejected_reply rreply;
205 } reply;
763cd6e3
RS
206};
207
208struct rpc_msg {
aab6538b 209 uint32_t xid;
763cd6e3 210
aab6538b 211 uint32_t direction;
763cd6e3 212 union {
aab6538b
RS
213 struct call_body cbody;
214 struct reply_body rbody;
215 } body;
763cd6e3 216};
763cd6e3
RS
217
218#define zdrmem_create libnfs_zdrmem_create
219void libnfs_zdrmem_create(ZDR *zdrs, const caddr_t addr, uint32_t size, enum zdr_op xop);
220
221#define zdr_destroy libnfs_zdr_destroy
222void libnfs_zdr_destroy(ZDR *zdrs);
223
224#define zdr_bytes libnfs_zdr_bytes
225bool_t libnfs_zdr_bytes(ZDR *zdrs, char **bufp, uint32_t *size, uint32_t maxsize);
226
227#define zdr_u_int libnfs_zdr_u_int
228bool_t libnfs_zdr_u_int(ZDR *zdrs, uint32_t *u);
229
230#define zdr_int libnfs_zdr_int
231bool_t libnfs_zdr_int(ZDR *zdrs, int32_t *i);
232
bce63d84
RS
233#define zdr_uint64_t libnfs_zdr_uint64_t
234bool_t libnfs_zdr_uint64_t(ZDR *zdrs, uint64_t *u);
763cd6e3 235
bce63d84
RS
236#define zdr_int64_t libnfs_zdr_int64_t
237bool_t libnfs_zdr_int64_t(ZDR *zdrs, int64_t *i);
763cd6e3
RS
238
239#define zdr_enum libnfs_zdr_enum
442b829a 240bool_t libnfs_zdr_enum(ZDR *zdrs, enum_t *e);
763cd6e3
RS
241
242#define zdr_bool libnfs_zdr_bool
243bool_t libnfs_zdr_bool(ZDR *zdrs, bool_t *b);
244
245#define zdr_void libnfs_zdr_void
246bool_t libnfs_zdr_void(void);
247
248#define zdr_pointer libnfs_zdr_pointer
249bool_t libnfs_zdr_pointer(ZDR *zdrs, char **objp, uint32_t size, zdrproc_t proc);
250
251#define zdr_opaque libnfs_zdr_opaque
252bool_t libnfs_zdr_opaque(ZDR *zdrs, char *objp, uint32_t size);
253
254#define zdr_string libnfs_zdr_string
255bool_t libnfs_zdr_string(ZDR *zdrs, char **strp, uint32_t maxsize);
256
257#define zdr_array libnfs_zdr_array
258bool_t libnfs_zdr_array(ZDR *zdrs, char **arrp, uint32_t *size, uint32_t maxsize, uint32_t elsize, zdrproc_t proc);
259
260#define zdr_setpos libnfs_zdr_setpos
261bool_t libnfs_zdr_setpos(ZDR *zdrs, uint32_t pos);
262
263#define zdr_getpos libnfs_zdr_getpos
264uint32_t libnfs_zdr_getpos(ZDR *zdrs);
265
266#define zdr_free libnfs_zdr_free
267void libnfs_zdr_free(zdrproc_t proc, char *objp);
268
f0cb8042
RS
269struct rpc_context;
270
763cd6e3 271#define zdr_callmsg libnfs_zdr_callmsg
f0cb8042 272bool_t libnfs_zdr_callmsg(struct rpc_context *rpc, ZDR *zdrs, struct rpc_msg *msg);
763cd6e3
RS
273
274#define zdr_replymsg libnfs_zdr_replymsg
f0cb8042 275bool_t libnfs_zdr_replymsg(struct rpc_context *rpc, ZDR *zdrs, struct rpc_msg *msg);
763cd6e3
RS
276
277#define authnone_create libnfs_authnone_create
67ba2239 278struct AUTH *libnfs_authnone_create(void);
763cd6e3
RS
279
280#define authunix_create libnfs_authunix_create
67ba2239 281struct AUTH *libnfs_authunix_create(char *host, uint32_t uid, uint32_t gid, uint32_t len, uint32_t *groups);
763cd6e3
RS
282
283#define authunix_create_default libnfs_authunix_create_default
67ba2239 284struct AUTH *libnfs_authunix_create_default(void);
763cd6e3
RS
285
286#define auth_destroy libnfs_auth_destroy
67ba2239 287void libnfs_auth_destroy(struct AUTH *auth);
763cd6e3 288
a81c5ea1
AR
289#ifdef __cplusplus
290}
291#endif
292
763cd6e3 293#endif