libnfs-raw.h: wrap in extern "C" for C++ compatibility
[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
44#define _RPC_RPC_H 1
45#define _RPC_ZDR_H 1
46#define _RPC_AUTH_H 1
47
48/* we dont need these */
49typedef void CLIENT;
50struct svc_req {
67a9f57e 51 int _dummy_;
763cd6e3
RS
52};
53typedef void SVCXPRT;
54
55
56
57
58
59#define ZDR_INLINE(...) NULL
60#define IZDR_PUT_U_LONG(...) assert(0)
61#define IZDR_GET_U_LONG(...) (assert(0), 0)
62#define IZDR_PUT_LONG(...) assert(0)
63#define IZDR_GET_LONG(...) (assert(0), 0)
64#define IZDR_PUT_BOOL(...) assert(0)
65#define IZDR_GET_BOOL(...) (assert(0), 0)
66
d7c6e9aa 67#ifndef TRUE
763cd6e3 68#define TRUE 1
d7c6e9aa
RS
69#endif
70#ifndef FALSE
763cd6e3 71#define FALSE 0
d7c6e9aa 72#endif
763cd6e3
RS
73
74enum zdr_op {
75 ZDR_ENCODE = 0,
76 ZDR_DECODE = 1
77};
78
79struct zdr_mem {
80 struct zdr_mem *next;
81 caddr_t buf;
82 uint32_t size;
83};
84
85struct ZDR {
86 enum zdr_op x_op;
87 caddr_t buf;
88 int size;
89 int pos;
90 struct zdr_mem *mem;
91};
92typedef struct ZDR ZDR;
93
94
95typedef uint32_t u_int;
96typedef uint32_t enum_t;
97typedef uint32_t bool_t;
98
99typedef int (*zdrproc_t) (ZDR *, void *,...);
100
763cd6e3
RS
101#define AUTH_NONE 0
102#define AUTH_NULL 0
103#define AUTH_UNIX 1
aab6538b 104
763cd6e3
RS
105struct opaque_auth {
106 uint32_t oa_flavor;
107 caddr_t oa_base;
108 uint32_t oa_length;
109};
110extern struct opaque_auth _null_auth;
111
67ba2239 112struct AUTH {
763cd6e3
RS
113 struct opaque_auth ah_cred;
114 struct opaque_auth ah_verf;
115 caddr_t ah_private;
67ba2239 116};
763cd6e3 117
763cd6e3
RS
118#define RPC_MSG_VERSION 2
119
aab6538b
RS
120enum msg_type {
121 CALL = 0,
122 REPLY = 1
763cd6e3
RS
123};
124
aab6538b
RS
125enum reply_stat {
126 MSG_ACCEPTED=0,
127 MSG_DENIED=1
763cd6e3
RS
128};
129
aab6538b
RS
130enum accept_stat {
131 SUCCESS = 0,
132 PROG_UNAVAIL = 1,
133 PROG_MISMATCH = 2,
134 PROC_UNAVAIL = 3,
135 GARBAGE_ARGS = 4,
136 SYSTEM_ERR = 5
763cd6e3
RS
137};
138
139enum reject_stat {
aab6538b
RS
140 RPC_MISMATCH = 0,
141 AUTH_ERROR = 1
763cd6e3
RS
142};
143
144enum auth_stat {
145 AUTH_OK=0,
146 /*
147 * failed at remote end
148 */
aab6538b
RS
149 AUTH_BADCRED = 1, /* bogus credentials (seal broken) */
150 AUTH_REJECTEDCRED = 2, /* client should begin new session */
151 AUTH_BADVERF = 3, /* bogus verifier (seal broken) */
152 AUTH_REJECTEDVERF = 4, /* verifier expired or was replayed */
153 AUTH_TOOWEAK = 5, /* rejected due to security reasons */
763cd6e3
RS
154 /*
155 * failed locally
156 */
aab6538b
RS
157 AUTH_INVALIDRESP = 6, /* bogus response verifier */
158 AUTH_FAILED = 7 /* some unknown reason */
159};
160
161struct call_body {
162 uint32_t rpcvers;
163 uint32_t prog;
164 uint32_t vers;
165 uint32_t proc;
166 struct opaque_auth cred;
167 struct opaque_auth verf;
168};
169
170struct accepted_reply {
171 struct opaque_auth verf;
172 uint32_t stat;
173 union {
174 struct {
175 caddr_t where;
176 zdrproc_t proc;
177 } results;
178 struct {
179 uint32_t low;
180 uint32_t high;
181 } mismatch_info;
182 } reply_data;
763cd6e3
RS
183};
184
185struct rejected_reply {
aab6538b 186 enum reject_stat stat;
763cd6e3
RS
187 union {
188 struct {
d7c6e9aa
RS
189 uint32_t low;
190 uint32_t high;
aab6538b
RS
191 } mismatch_info;
192 enum auth_stat stat;
193 } reject_data;
763cd6e3
RS
194};
195
763cd6e3 196struct reply_body {
aab6538b 197 uint32_t stat;
763cd6e3 198 union {
aab6538b
RS
199 struct accepted_reply areply;
200 struct rejected_reply rreply;
201 } reply;
763cd6e3
RS
202};
203
204struct rpc_msg {
aab6538b 205 uint32_t xid;
763cd6e3 206
aab6538b 207 uint32_t direction;
763cd6e3 208 union {
aab6538b
RS
209 struct call_body cbody;
210 struct reply_body rbody;
211 } body;
763cd6e3 212};
763cd6e3
RS
213
214#define zdrmem_create libnfs_zdrmem_create
215void libnfs_zdrmem_create(ZDR *zdrs, const caddr_t addr, uint32_t size, enum zdr_op xop);
216
217#define zdr_destroy libnfs_zdr_destroy
218void libnfs_zdr_destroy(ZDR *zdrs);
219
220#define zdr_bytes libnfs_zdr_bytes
221bool_t libnfs_zdr_bytes(ZDR *zdrs, char **bufp, uint32_t *size, uint32_t maxsize);
222
223#define zdr_u_int libnfs_zdr_u_int
224bool_t libnfs_zdr_u_int(ZDR *zdrs, uint32_t *u);
225
226#define zdr_int libnfs_zdr_int
227bool_t libnfs_zdr_int(ZDR *zdrs, int32_t *i);
228
229#define zdr_u_quad_t libnfs_zdr_u_quad_t
230bool_t libnfs_zdr_u_quad_t(ZDR *zdrs, uint64_t *u);
231
232#define zdr_quad_t libnfs_zdr_quad_t
233bool_t libnfs_zdr_quad_t(ZDR *zdrs, int64_t *i);
234
235#define zdr_enum libnfs_zdr_enum
442b829a 236bool_t libnfs_zdr_enum(ZDR *zdrs, enum_t *e);
763cd6e3
RS
237
238#define zdr_bool libnfs_zdr_bool
239bool_t libnfs_zdr_bool(ZDR *zdrs, bool_t *b);
240
241#define zdr_void libnfs_zdr_void
242bool_t libnfs_zdr_void(void);
243
244#define zdr_pointer libnfs_zdr_pointer
245bool_t libnfs_zdr_pointer(ZDR *zdrs, char **objp, uint32_t size, zdrproc_t proc);
246
247#define zdr_opaque libnfs_zdr_opaque
248bool_t libnfs_zdr_opaque(ZDR *zdrs, char *objp, uint32_t size);
249
250#define zdr_string libnfs_zdr_string
251bool_t libnfs_zdr_string(ZDR *zdrs, char **strp, uint32_t maxsize);
252
253#define zdr_array libnfs_zdr_array
254bool_t libnfs_zdr_array(ZDR *zdrs, char **arrp, uint32_t *size, uint32_t maxsize, uint32_t elsize, zdrproc_t proc);
255
256#define zdr_setpos libnfs_zdr_setpos
257bool_t libnfs_zdr_setpos(ZDR *zdrs, uint32_t pos);
258
259#define zdr_getpos libnfs_zdr_getpos
260uint32_t libnfs_zdr_getpos(ZDR *zdrs);
261
262#define zdr_free libnfs_zdr_free
263void libnfs_zdr_free(zdrproc_t proc, char *objp);
264
265#define zdr_callmsg libnfs_zdr_callmsg
266bool_t libnfs_zdr_callmsg(ZDR *zdrs, struct rpc_msg *msg);
267
268#define zdr_replymsg libnfs_zdr_replymsg
269bool_t libnfs_zdr_replymsg(ZDR *zdrs, struct rpc_msg *msg);
270
271#define authnone_create libnfs_authnone_create
67ba2239 272struct AUTH *libnfs_authnone_create(void);
763cd6e3
RS
273
274#define authunix_create libnfs_authunix_create
67ba2239 275struct AUTH *libnfs_authunix_create(char *host, uint32_t uid, uint32_t gid, uint32_t len, uint32_t *groups);
763cd6e3
RS
276
277#define authunix_create_default libnfs_authunix_create_default
67ba2239 278struct AUTH *libnfs_authunix_create_default(void);
763cd6e3
RS
279
280#define auth_destroy libnfs_auth_destroy
67ba2239 281void libnfs_auth_destroy(struct AUTH *auth);
763cd6e3
RS
282
283#endif