OpenAFS
OpenAFS distributed network file system
|
00001 /* 00002 * Copyright (c) 2009 Secure Endpoints Inc. 00003 * 00004 * Permission is hereby granted, free of charge, to any person 00005 * obtaining a copy of this software and associated documentation 00006 * files (the "Software"), to deal in the Software without 00007 * restriction, including without limitation the rights to use, copy, 00008 * modify, merge, publish, distribute, sublicense, and/or sell copies 00009 * of the Software, and to permit persons to whom the Software is 00010 * furnished to do so, subject to the following conditions: 00011 * 00012 * The above copyright notice and this permission notice shall be 00013 * included in all copies or substantial portions of the Software. 00014 * 00015 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 00016 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00017 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00018 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 00019 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 00020 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 00021 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 00022 * SOFTWARE. 00023 */ 00024 00025 #pragma once 00026 00027 #include <Rpc.h> 00028 #include <RpcdceP.h> 00029 #include <RpcNdr.h> 00030 #include "cm_nls.h" 00031 00032 #define I_RpcGetBuffer MSRPC_I_GetBuffer 00033 00034 #define I_RpcFreeBuffer MSRPC_I_FreeBuffer 00035 00036 #define NdrServerInitializeNew MSRPC_NdrServerInitializeNew 00037 00045 #define MAX_RPC_MSG_SIZE 102400 00046 00048 #define DEF_RPC_MSG_SIZE 2048 00049 00051 typedef enum msrpc_call_status { 00052 MSRPC_CALL_NONE = 0, 00053 MSRPC_CALL_MSGRECEIVED, 00054 MSRPC_CALL_DISPATCHED, 00055 MSRPC_CALL_MSGSENDING, 00056 MSRPC_CALL_MSGSENT, 00057 MSRPC_CALL_SKIP, 00058 } MSRPC_CALL_STATUS; 00059 00060 typedef enum PDU_type { 00061 PDU_TYPE_REQUEST = 0, 00062 PDU_TYPE_PING = 1, 00063 PDU_TYPE_RESPONSE = 2, 00064 PDU_TYPE_FAULT = 3, 00065 PDU_TYPE_WORKING = 4, 00066 PDU_TYPE_NOCALL = 5, 00067 PDU_TYPE_REJECT = 6, 00068 PDU_TYPE_ACK = 7, 00069 PDU_TYPE_CL_CANCEL = 8, 00070 PDU_TYPE_FACK = 9, 00071 PDU_TYPE_CANCEL_ACK = 10, 00072 PDU_TYPE_BIND = 11, 00073 PDU_TYPE_BIND_ACK = 12, 00074 PDU_TYPE_BIND_NAK = 13, 00075 PDU_TYPE_ALTER_CONTEXT = 14, 00076 PDU_TYPE_ALTER_CONTEXT_RESP = 15, 00077 PDU_TYPE_SHUTDOWN = 16, 00078 PDU_TYPE_CO_CANCEL = 18, 00079 PDU_TYPE_ORPHANED = 19 00080 } PDU_TYPE; 00081 00082 typedef enum msrpc_bind_reject_reason { 00083 BIND_REJ_REASON_NOT_SPECIFIED = 0, 00084 BIND_REJ_TEMPORARY_CONGESTION = 1, 00085 BIND_REJ_LOCAL_LIMIT_EXCEEDED = 2, 00086 BIND_REJ_CALLED_PADDR_UNKNOWN = 3, /* not used */ 00087 BIND_REJ_PROTOCOL_VERSION_NOT_SUPPORTED = 4, 00088 BIND_REJ_DEFAULT_CONTEXT_NOT_SUPPORTED = 5, /* not used */ 00089 BIND_REJ_USER_DATA_NOT_READABLE = 6, /* not used */ 00090 BIND_REJ_NO_PSAP_AVAILABLE = 7 /* not used */ 00091 } BIND_REJECT_REASON; 00092 00093 typedef unsigned __int8 byte; 00094 typedef unsigned __int8 u_int8; 00095 typedef unsigned __int16 u_int16; 00096 typedef unsigned __int32 u_int32; 00097 typedef unsigned __int64 u_int64; 00098 00100 typedef 00101 struct E_CommonHeader { 00102 u_int8 rpc_vers; 00103 u_int8 rpc_vers_minor; 00104 u_int8 PTYPE; 00105 u_int8 pfc_flags; 00107 #define PFC_FIRST_FRAG 0x01 /* First fragment */ 00108 #define PFC_LAST_FRAG 0x02 /* Last fragment */ 00109 #define PFC_PENDING_CANCEL 0x04 /* Cancel was pending at sender */ 00110 #define PFC_RESERVED_1 0x08 00111 #define PFC_CONC_MPX 0x10 /* supports concurrent multiplexing 00112 * of a single connection. */ 00113 #define PFC_DID_NOT_EXECUTE 0x20 /* only meaningful on `fault' packet; 00114 * if true, guaranteed call did not 00115 * execute. */ 00116 #define PFC_MAYBE 0x40 /* `maybe' call semantics requested */ 00117 #define PFC_OBJECT_UUID 0x80 /* if true, a non-nil object UUID 00118 * was specified in the handle, and 00119 * is present in the optional object 00120 * field. If false, the object field 00121 * is omitted. */ 00122 00123 byte packed_drep[4]; 00124 u_int16 frag_length; 00125 u_int16 auth_length; 00126 u_int32 call_id; 00127 } E_CommonHeader; 00128 00129 typedef u_int16 p_context_id_t; /* local context identifier */ 00130 00133 typedef struct msrpc_buffer { 00134 BYTE * buf_data; 00135 unsigned int buf_length; 00136 unsigned int buf_alloc; 00137 unsigned int buf_pos; 00138 00139 PDU_TYPE pdu_type; 00140 } msrpc_buffer; 00141 00142 typedef struct cm_user cm_user_t; 00143 00149 typedef struct msrpc_call { 00150 struct msrpc_call * next; 00151 struct msrpc_call * prev; 00152 00153 MSRPC_CALL_STATUS status; 00154 00155 u_int32 call_id; 00156 p_context_id_t context_id; 00158 E_CommonHeader * in_header; 00162 msrpc_buffer in; 00164 msrpc_buffer out; 00166 RPC_MESSAGE msg; 00167 00168 cm_user_t *cm_userp; 00170 } msrpc_call; 00171 00177 typedef struct _msrpc_conn { 00178 unsigned int max_xmit_frag; 00180 unsigned int max_recv_frag; 00182 u_int32 assoc_group_id; 00185 unsigned int rpc_vers; 00186 unsigned int rpc_vers_minor; 00188 char * secondary_address; 00191 RPC_SERVER_INTERFACE * interface; 00195 msrpc_call * head; 00197 msrpc_call * tail; 00198 } msrpc_conn; 00199 00200 00201 void 00202 MSRPC_Init(void); 00203 00204 void 00205 MSRPC_Shutdown(void); 00206 00207 int 00208 MSRPC_InitConn(msrpc_conn * conn, const char * secondary_address); 00209 00210 int 00211 MSRPC_FreeConn(msrpc_conn * conn); 00212 00213 int 00214 MSRPC_WriteMessage(msrpc_conn * conn, BYTE * buffer, unsigned int len, 00215 cm_user_t * userp); 00216 00217 int 00218 MSRPC_PrepareRead(msrpc_conn * conn); 00219 00220 int 00221 MSRPC_ReadMessageLength(msrpc_conn * conn, unsigned int max_len); 00222 00223 int 00224 MSRPC_ReadMessage(msrpc_conn * conn, BYTE *buffer, unsigned int len); 00225 00226 RPC_STATUS 00227 RPC_ENTRY 00228 I_RpcGetBuffer (IN OUT RPC_MESSAGE __RPC_FAR * Message); 00229 00230 RPC_STATUS 00231 RPC_ENTRY 00232 I_RpcFreeBuffer (IN OUT RPC_MESSAGE __RPC_FAR * Message); 00233 00234 unsigned char * 00235 RPC_ENTRY 00236 NdrServerInitializeNew( 00237 PRPC_MESSAGE pRpcMsg, 00238 PMIDL_STUB_MESSAGE pStubMsg, 00239 PMIDL_STUB_DESC pStubDescriptor 00240 ); 00241 00242 extern cm_user_t * 00243 MSRPC_GetCmUser(void); 00244 00245 extern void RPC_SRVSVC_Init(void); 00246 00247 extern void RPC_SRVSVC_Shutdown(void); 00248 00249 extern int 00250 MSRPC_IsWellKnownService(const clientchar_t * lastNamep);