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