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