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