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