Changeset 740 for vendor/current/source4/librpc
- Timestamp:
- Nov 14, 2012, 12:59:34 PM (13 years ago)
- Location:
- vendor/current/source4/librpc
- Files:
-
- 9 added
- 5 deleted
- 23 edited
Legend:
- Unmodified
- Added
- Removed
-
vendor/current/source4/librpc/dcerpc.pc.in
r414 r740 7 7 Description: DCE/RPC client library 8 8 Requires: ndr 9 Version: 0.0.110 Libs: -L${libdir} -ldcerpc9 Version: @PACKAGE_VERSION@ 10 Libs: @LIB_RPATH@ -L${libdir} -ldcerpc 11 11 Cflags: -I${includedir} -DHAVE_IMMEDIATE_STRUCTURES=1 -
vendor/current/source4/librpc/dcerpc_atsvc.pc.in
r414 r740 7 7 Description: DCE/RPC client library - ATSVC 8 8 Requires.private: dcerpc ndr 9 Version: 0.0.110 Libs: -L${libdir} -ldcerpc_atsvc9 Version: @PACKAGE_VERSION@ 10 Libs: @LIB_RPATH@ -L${libdir} -ldcerpc-atsvc 11 11 Cflags: -I${includedir} -DHAVE_IMMEDIATE_STRUCTURES=1 -
vendor/current/source4/librpc/dcerpc_samr.pc.in
r414 r740 7 7 Description: DCE/RPC client library - SAMR 8 8 Requires.private: dcerpc ndr 9 Version: 0.0.110 Libs: -L${libdir} -ldcerpc_samr9 Version: @PACKAGE_VERSION@ 10 Libs: @LIB_RPATH@ -L${libdir} -ldcerpc-samr 11 11 Cflags: -I${includedir} -DHAVE_IMMEDIATE_STRUCTURES=1 -
vendor/current/source4/librpc/idl/irpc.idl
r414 r740 1 1 #include "idl_types.h" 2 2 3 import "misc.idl", "security.idl", "nbt.idl" ;3 import "misc.idl", "security.idl", "nbt.idl", "netlogon.idl"; 4 4 5 5 /* … … 15 15 } irpc_flags; 16 16 17 typedef struct { 18 security_token *token; 19 } irpc_creds; 20 17 21 typedef [public] struct { 18 22 GUID uuid; … … 22 26 irpc_flags flags; 23 27 NTSTATUS status; 28 [subcontext(4)] irpc_creds creds; 29 [flag(NDR_ALIGN8)] DATA_BLOB _pad; 24 30 } irpc_header; 25 31 … … 149 155 ); 150 156 157 /****************************************************** 158 management calls for the drepl server 159 ******************************************************/ 160 /** 161 * Force dreplsrv to fefresh internal cache. 162 * @param partition_dn Partition to refresh cacheh for. 163 * If empy/NULL, refresh all partitions. 164 */ 165 WERROR dreplsrv_refresh(); 166 167 /* 168 called when role transfer is requested via LDAP 169 */ 170 typedef [v1_enum] enum { 171 DREPL_SCHEMA_MASTER, 172 DREPL_RID_MASTER, 173 DREPL_INFRASTRUCTURE_MASTER, 174 DREPL_NAMING_MASTER, 175 DREPL_PDC_MASTER 176 } drepl_role_master; 177 178 WERROR drepl_takeFSMORole( 179 [in] drepl_role_master role 180 ); 181 182 /* 183 * message to tell the drepl server to initiate a REPL_SECRET 184 * replication of a users secrets 185 */ 186 void drepl_trigger_repl_secret( 187 [in] astring user_dn 188 ); 189 190 /* 191 message to do RODC DNS updates via the dnsupdate task 192 */ 193 NTSTATUS dnsupdate_RODC( 194 [in,unique] dom_sid *dom_sid, 195 [in,unique] [string,charset(UTF16)] uint16 *site_name, 196 [in] uint32 dns_ttl, 197 [in,out,ref] NL_DNS_NAME_INFO_ARRAY *dns_names 198 ); 151 199 } -
vendor/current/source4/librpc/idl/opendb.idl
r414 r740 8 8 */ 9 9 10 import "server_id .idl";10 import "server_id4.idl"; 11 11 12 12 [ -
vendor/current/source4/librpc/idl/winbind.idl
r414 r740 5 5 #include "idl_types.h" 6 6 7 import "netlogon.idl", "lsa.idl", "security.idl" ;7 import "netlogon.idl", "lsa.idl", "security.idl", "idmap.idl"; 8 8 9 9 [ … … 16 16 typedef [switch_type(uint16)] union netr_LogonLevel netr_LogonLevel; 17 17 typedef [switch_type(uint16)] union netr_Validation netr_Validation; 18 19 typedef enum {20 ID_TYPE_NOT_SPECIFIED,21 ID_TYPE_UID,22 ID_TYPE_GID,23 ID_TYPE_BOTH24 } id_type;25 26 typedef struct {27 uint32 id;28 id_type type;29 } unixid;30 31 typedef struct {32 unixid *unixid;33 dom_sid *sid;34 NTSTATUS status;35 } id_mapping;36 18 37 19 /* a call to get runtime informations */ … … 63 45 [in] winbind_get_idmap_level level, 64 46 [in] uint32 count, 65 [in,out] [size_is(count)] id_map pingids[]47 [in,out] [size_is(count)] id_map ids[] 66 48 ); 67 49 50 NTSTATUS winbind_DsrUpdateReadOnlyServerDnsRecords( 51 [in,unique] [string,charset(UTF16)] uint16 *site_name, 52 [in] uint32 dns_ttl, 53 [in,out,ref] NL_DNS_NAME_INFO_ARRAY *dns_names 54 ); 68 55 } -
vendor/current/source4/librpc/idl/winsrepl.idl
r414 r740 12 12 import "nbt.idl"; 13 13 14 interface wrepl 14 [ 15 uuid("915f5653-bac1-431c-97ee-9ffb34526921"), 16 helpstring("WINS Replication PDUs") 17 ] interface wrepl 15 18 { 16 19 const int WINS_REPLICATION_PORT = 42; … … 165 168 166 169 typedef [flag(NDR_BIG_ENDIAN|NDR_PAHEX),public] struct { 167 [value(ndr_size_wrepl_packet(&packet, ndr-> iconv_convenience, ndr->flags))] uint32 size;170 [value(ndr_size_wrepl_packet(&packet, ndr->flags))] uint32 size; 168 171 wrepl_packet packet; 169 172 } wrepl_wrap; -
vendor/current/source4/librpc/ndr/py_misc.c
r414 r740 62 62 static int py_GUID_init(PyObject *self, PyObject *args, PyObject *kwargs) 63 63 { 64 char*str = NULL;64 PyObject *str = NULL; 65 65 NTSTATUS status; 66 66 struct GUID *guid = py_talloc_get_ptr(self); 67 67 const char *kwnames[] = { "str", NULL }; 68 68 69 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "| s", discard_const_p(char *, kwnames), &str))69 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|O", discard_const_p(char *, kwnames), &str)) 70 70 return -1; 71 71 72 72 if (str != NULL) { 73 status = GUID_from_string(str, guid); 73 DATA_BLOB guid_val; 74 75 if (!PyString_Check(str)) { 76 PyErr_SetString(PyExc_TypeError, "Expected a string argument to GUID()"); 77 return -1; 78 } 79 guid_val.data = (uint8_t *)PyString_AsString(str); 80 guid_val.length = PyString_Size(str); 81 status = GUID_from_data_blob(&guid_val, guid); 74 82 if (!NT_STATUS_IS_OK(status)) { 75 83 PyErr_SetNTSTATUS(status); -
vendor/current/source4/librpc/ndr/py_security.c
r414 r740 42 42 } 43 43 44 static PyObject *py_dom_sid_split(PyObject *py_self, PyObject *args) 45 { 46 struct dom_sid *self = py_talloc_get_ptr(py_self); 47 struct dom_sid *domain_sid; 48 TALLOC_CTX *mem_ctx; 49 uint32_t rid; 50 NTSTATUS status; 51 PyObject *py_domain_sid; 52 53 mem_ctx = talloc_new(NULL); 54 if (mem_ctx == NULL) { 55 PyErr_NoMemory(); 56 return NULL; 57 } 58 59 status = dom_sid_split_rid(mem_ctx, self, &domain_sid, &rid); 60 if (!NT_STATUS_IS_OK(status)) { 61 PyErr_SetString(PyExc_RuntimeError, "dom_sid_split_rid failed"); 62 talloc_free(mem_ctx); 63 return NULL; 64 } 65 66 py_domain_sid = py_talloc_steal(&dom_sid_Type, domain_sid); 67 talloc_free(mem_ctx); 68 return Py_BuildValue("(OI)", py_domain_sid, rid); 69 } 70 44 71 static int py_dom_sid_cmp(PyObject *py_self, PyObject *py_other) 45 72 { … … 87 114 } 88 115 116 static PyMethodDef py_dom_sid_extra_methods[] = { 117 { "split", (PyCFunction)py_dom_sid_split, METH_NOARGS, 118 "S.split() -> (domain_sid, rid)\n" 119 "Split a domain sid" }, 120 { NULL } 121 }; 122 123 89 124 static void py_dom_sid_patch(PyTypeObject *type) 90 125 { … … 93 128 type->tp_repr = py_dom_sid_repr; 94 129 type->tp_compare = py_dom_sid_cmp; 130 PyType_AddMethods(type, py_dom_sid_extra_methods); 95 131 } 96 132 -
vendor/current/source4/librpc/rpc/dcerpc.c
r414 r740 31 31 #include "auth/gensec/gensec.h" 32 32 #include "param/param.h" 33 #include "lib/util/tevent_ntstatus.h" 34 #include "librpc/rpc/rpc_common.h" 35 36 enum rpc_request_state { 37 RPC_REQUEST_QUEUED, 38 RPC_REQUEST_PENDING, 39 RPC_REQUEST_DONE 40 }; 41 42 /* 43 handle for an async dcerpc request 44 */ 45 struct rpc_request { 46 struct rpc_request *next, *prev; 47 struct dcerpc_pipe *p; 48 NTSTATUS status; 49 uint32_t call_id; 50 enum rpc_request_state state; 51 DATA_BLOB payload; 52 uint32_t flags; 53 uint32_t fault_code; 54 55 /* this is used to distinguish bind and alter_context requests 56 from normal requests */ 57 void (*recv_handler)(struct rpc_request *conn, 58 DATA_BLOB *blob, struct ncacn_packet *pkt); 59 60 const struct GUID *object; 61 uint16_t opnum; 62 DATA_BLOB request_data; 63 bool ignore_timeout; 64 65 /* use by the ndr level async recv call */ 66 struct { 67 const struct ndr_interface_table *table; 68 uint32_t opnum; 69 void *struct_ptr; 70 TALLOC_CTX *mem_ctx; 71 } ndr; 72 73 struct { 74 void (*callback)(struct rpc_request *); 75 void *private_data; 76 } async; 77 }; 33 78 34 79 _PUBLIC_ NTSTATUS dcerpc_init(struct loadparm_context *lp_ctx) … … 37 82 } 38 83 39 static void dcerpc_connection_dead(struct dcerpc_connection *conn, NTSTATUS status); 40 static void dcerpc_ship_next_request(struct dcerpc_connection *c); 84 static void dcerpc_connection_dead(struct dcecli_connection *conn, NTSTATUS status); 85 static void dcerpc_ship_next_request(struct dcecli_connection *c); 86 87 static struct rpc_request *dcerpc_request_send(struct dcerpc_pipe *p, 88 const struct GUID *object, 89 uint16_t opnum, 90 DATA_BLOB *stub_data); 91 static NTSTATUS dcerpc_request_recv(struct rpc_request *req, 92 TALLOC_CTX *mem_ctx, 93 DATA_BLOB *stub_data); 94 static NTSTATUS dcerpc_ndr_validate_in(struct dcecli_connection *c, 95 TALLOC_CTX *mem_ctx, 96 DATA_BLOB blob, 97 size_t struct_size, 98 ndr_push_flags_fn_t ndr_push, 99 ndr_pull_flags_fn_t ndr_pull); 100 static NTSTATUS dcerpc_ndr_validate_out(struct dcecli_connection *c, 101 struct ndr_pull *pull_in, 102 void *struct_ptr, 103 size_t struct_size, 104 ndr_push_flags_fn_t ndr_push, 105 ndr_pull_flags_fn_t ndr_pull, 106 ndr_print_function_t ndr_print); 41 107 42 108 /* destroy a dcerpc connection */ 43 static int dcerpc_connection_destructor(struct dce rpc_connection *conn)109 static int dcerpc_connection_destructor(struct dcecli_connection *conn) 44 110 { 45 111 if (conn->dead) { … … 55 121 the event context is optional 56 122 */ 57 static struct dcerpc_connection *dcerpc_connection_init(TALLOC_CTX *mem_ctx, 58 struct tevent_context *ev, 59 struct smb_iconv_convenience *ic) 60 { 61 struct dcerpc_connection *c; 62 63 c = talloc_zero(mem_ctx, struct dcerpc_connection); 123 static struct dcecli_connection *dcerpc_connection_init(TALLOC_CTX *mem_ctx, 124 struct tevent_context *ev) 125 { 126 struct dcecli_connection *c; 127 128 c = talloc_zero(mem_ctx, struct dcecli_connection); 64 129 if (!c) { 65 130 return NULL; 66 131 } 67 68 c->iconv_convenience = talloc_reference(c, ic);69 132 70 133 c->event_ctx = ev; … … 90 153 } 91 154 155 struct dcerpc_bh_state { 156 struct dcerpc_pipe *p; 157 }; 158 159 static bool dcerpc_bh_is_connected(struct dcerpc_binding_handle *h) 160 { 161 struct dcerpc_bh_state *hs = dcerpc_binding_handle_data(h, 162 struct dcerpc_bh_state); 163 164 if (!hs->p) { 165 return false; 166 } 167 168 return true; 169 } 170 171 static uint32_t dcerpc_bh_set_timeout(struct dcerpc_binding_handle *h, 172 uint32_t timeout) 173 { 174 struct dcerpc_bh_state *hs = dcerpc_binding_handle_data(h, 175 struct dcerpc_bh_state); 176 uint32_t old; 177 178 if (!hs->p) { 179 return DCERPC_REQUEST_TIMEOUT; 180 } 181 182 old = hs->p->request_timeout; 183 hs->p->request_timeout = timeout; 184 185 return old; 186 } 187 188 struct dcerpc_bh_raw_call_state { 189 struct dcerpc_binding_handle *h; 190 DATA_BLOB in_data; 191 DATA_BLOB out_data; 192 uint32_t out_flags; 193 }; 194 195 static void dcerpc_bh_raw_call_done(struct rpc_request *subreq); 196 197 static struct tevent_req *dcerpc_bh_raw_call_send(TALLOC_CTX *mem_ctx, 198 struct tevent_context *ev, 199 struct dcerpc_binding_handle *h, 200 const struct GUID *object, 201 uint32_t opnum, 202 uint32_t in_flags, 203 const uint8_t *in_data, 204 size_t in_length) 205 { 206 struct dcerpc_bh_state *hs = dcerpc_binding_handle_data(h, 207 struct dcerpc_bh_state); 208 struct tevent_req *req; 209 struct dcerpc_bh_raw_call_state *state; 210 bool ok; 211 struct rpc_request *subreq; 212 213 req = tevent_req_create(mem_ctx, &state, 214 struct dcerpc_bh_raw_call_state); 215 if (req == NULL) { 216 return NULL; 217 } 218 state->h = h; 219 state->in_data.data = discard_const_p(uint8_t, in_data); 220 state->in_data.length = in_length; 221 222 ok = dcerpc_bh_is_connected(h); 223 if (!ok) { 224 tevent_req_nterror(req, NT_STATUS_INVALID_CONNECTION); 225 return tevent_req_post(req, ev); 226 } 227 228 subreq = dcerpc_request_send(hs->p, 229 object, 230 opnum, 231 &state->in_data); 232 if (tevent_req_nomem(subreq, req)) { 233 return tevent_req_post(req, ev); 234 } 235 subreq->async.callback = dcerpc_bh_raw_call_done; 236 subreq->async.private_data = req; 237 238 return req; 239 } 240 241 static void dcerpc_bh_raw_call_done(struct rpc_request *subreq) 242 { 243 struct tevent_req *req = 244 talloc_get_type_abort(subreq->async.private_data, 245 struct tevent_req); 246 struct dcerpc_bh_raw_call_state *state = 247 tevent_req_data(req, 248 struct dcerpc_bh_raw_call_state); 249 NTSTATUS status; 250 uint32_t fault_code; 251 252 state->out_flags = 0; 253 if (subreq->flags & DCERPC_PULL_BIGENDIAN) { 254 state->out_flags |= LIBNDR_FLAG_BIGENDIAN; 255 } 256 257 fault_code = subreq->fault_code; 258 259 status = dcerpc_request_recv(subreq, state, &state->out_data); 260 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) { 261 status = dcerpc_fault_to_nt_status(fault_code); 262 } 263 if (!NT_STATUS_IS_OK(status)) { 264 tevent_req_nterror(req, status); 265 return; 266 } 267 268 tevent_req_done(req); 269 } 270 271 static NTSTATUS dcerpc_bh_raw_call_recv(struct tevent_req *req, 272 TALLOC_CTX *mem_ctx, 273 uint8_t **out_data, 274 size_t *out_length, 275 uint32_t *out_flags) 276 { 277 struct dcerpc_bh_raw_call_state *state = 278 tevent_req_data(req, 279 struct dcerpc_bh_raw_call_state); 280 NTSTATUS status; 281 282 if (tevent_req_is_nterror(req, &status)) { 283 tevent_req_received(req); 284 return status; 285 } 286 287 *out_data = talloc_move(mem_ctx, &state->out_data.data); 288 *out_length = state->out_data.length; 289 *out_flags = state->out_flags; 290 tevent_req_received(req); 291 return NT_STATUS_OK; 292 } 293 294 struct dcerpc_bh_disconnect_state { 295 uint8_t _dummy; 296 }; 297 298 static struct tevent_req *dcerpc_bh_disconnect_send(TALLOC_CTX *mem_ctx, 299 struct tevent_context *ev, 300 struct dcerpc_binding_handle *h) 301 { 302 struct dcerpc_bh_state *hs = dcerpc_binding_handle_data(h, 303 struct dcerpc_bh_state); 304 struct tevent_req *req; 305 struct dcerpc_bh_disconnect_state *state; 306 bool ok; 307 308 req = tevent_req_create(mem_ctx, &state, 309 struct dcerpc_bh_disconnect_state); 310 if (req == NULL) { 311 return NULL; 312 } 313 314 ok = dcerpc_bh_is_connected(h); 315 if (!ok) { 316 tevent_req_nterror(req, NT_STATUS_INVALID_CONNECTION); 317 return tevent_req_post(req, ev); 318 } 319 320 /* TODO: do a real disconnect ... */ 321 hs->p = NULL; 322 323 tevent_req_done(req); 324 return tevent_req_post(req, ev); 325 } 326 327 static NTSTATUS dcerpc_bh_disconnect_recv(struct tevent_req *req) 328 { 329 NTSTATUS status; 330 331 if (tevent_req_is_nterror(req, &status)) { 332 tevent_req_received(req); 333 return status; 334 } 335 336 tevent_req_received(req); 337 return NT_STATUS_OK; 338 } 339 340 static bool dcerpc_bh_push_bigendian(struct dcerpc_binding_handle *h) 341 { 342 struct dcerpc_bh_state *hs = dcerpc_binding_handle_data(h, 343 struct dcerpc_bh_state); 344 345 if (hs->p->conn->flags & DCERPC_PUSH_BIGENDIAN) { 346 return true; 347 } 348 349 return false; 350 } 351 352 static bool dcerpc_bh_ref_alloc(struct dcerpc_binding_handle *h) 353 { 354 struct dcerpc_bh_state *hs = dcerpc_binding_handle_data(h, 355 struct dcerpc_bh_state); 356 357 if (hs->p->conn->flags & DCERPC_NDR_REF_ALLOC) { 358 return true; 359 } 360 361 return false; 362 } 363 364 static bool dcerpc_bh_use_ndr64(struct dcerpc_binding_handle *h) 365 { 366 struct dcerpc_bh_state *hs = dcerpc_binding_handle_data(h, 367 struct dcerpc_bh_state); 368 369 if (hs->p->conn->flags & DCERPC_NDR64) { 370 return true; 371 } 372 373 return false; 374 } 375 376 static void dcerpc_bh_do_ndr_print(struct dcerpc_binding_handle *h, 377 int ndr_flags, 378 const void *_struct_ptr, 379 const struct ndr_interface_call *call) 380 { 381 struct dcerpc_bh_state *hs = dcerpc_binding_handle_data(h, 382 struct dcerpc_bh_state); 383 void *struct_ptr = discard_const(_struct_ptr); 384 385 if (ndr_flags & NDR_IN) { 386 if (hs->p->conn->flags & DCERPC_DEBUG_PRINT_IN) { 387 ndr_print_function_debug(call->ndr_print, 388 call->name, 389 ndr_flags, 390 struct_ptr); 391 } 392 } 393 if (ndr_flags & NDR_OUT) { 394 if (hs->p->conn->flags & DCERPC_DEBUG_PRINT_OUT) { 395 ndr_print_function_debug(call->ndr_print, 396 call->name, 397 ndr_flags, 398 struct_ptr); 399 } 400 } 401 } 402 403 static void dcerpc_bh_ndr_push_failed(struct dcerpc_binding_handle *h, 404 NTSTATUS error, 405 const void *struct_ptr, 406 const struct ndr_interface_call *call) 407 { 408 DEBUG(2,("Unable to ndr_push structure for %s - %s\n", 409 call->name, nt_errstr(error))); 410 } 411 412 static void dcerpc_bh_ndr_pull_failed(struct dcerpc_binding_handle *h, 413 NTSTATUS error, 414 const DATA_BLOB *blob, 415 const struct ndr_interface_call *call) 416 { 417 struct dcerpc_bh_state *hs = dcerpc_binding_handle_data(h, 418 struct dcerpc_bh_state); 419 const uint32_t num_examples = 20; 420 uint32_t i; 421 422 DEBUG(2,("Unable to ndr_pull structure for %s - %s\n", 423 call->name, nt_errstr(error))); 424 425 if (hs->p->conn->packet_log_dir == NULL) return; 426 427 for (i=0;i<num_examples;i++) { 428 char *name=NULL; 429 asprintf(&name, "%s/rpclog/%s-out.%d", 430 hs->p->conn->packet_log_dir, 431 call->name, i); 432 if (name == NULL) { 433 return; 434 } 435 if (!file_exist(name)) { 436 if (file_save(name, blob->data, blob->length)) { 437 DEBUG(10,("Logged rpc packet to %s\n", name)); 438 } 439 free(name); 440 break; 441 } 442 free(name); 443 } 444 } 445 446 static NTSTATUS dcerpc_bh_ndr_validate_in(struct dcerpc_binding_handle *h, 447 TALLOC_CTX *mem_ctx, 448 const DATA_BLOB *blob, 449 const struct ndr_interface_call *call) 450 { 451 struct dcerpc_bh_state *hs = dcerpc_binding_handle_data(h, 452 struct dcerpc_bh_state); 453 454 if (hs->p->conn->flags & DCERPC_DEBUG_VALIDATE_IN) { 455 NTSTATUS status; 456 457 status = dcerpc_ndr_validate_in(hs->p->conn, 458 mem_ctx, 459 *blob, 460 call->struct_size, 461 call->ndr_push, 462 call->ndr_pull); 463 if (!NT_STATUS_IS_OK(status)) { 464 DEBUG(0,("Validation [in] failed for %s - %s\n", 465 call->name, nt_errstr(status))); 466 return status; 467 } 468 } 469 470 DEBUG(10,("rpc request data:\n")); 471 dump_data(10, blob->data, blob->length); 472 473 return NT_STATUS_OK; 474 } 475 476 static NTSTATUS dcerpc_bh_ndr_validate_out(struct dcerpc_binding_handle *h, 477 struct ndr_pull *pull_in, 478 const void *_struct_ptr, 479 const struct ndr_interface_call *call) 480 { 481 struct dcerpc_bh_state *hs = dcerpc_binding_handle_data(h, 482 struct dcerpc_bh_state); 483 void *struct_ptr = discard_const(_struct_ptr); 484 485 DEBUG(10,("rpc reply data:\n")); 486 dump_data(10, pull_in->data, pull_in->data_size); 487 488 if (pull_in->offset != pull_in->data_size) { 489 DEBUG(0,("Warning! ignoring %u unread bytes at ofs:%u (0x%08X) for %s!\n", 490 pull_in->data_size - pull_in->offset, 491 pull_in->offset, pull_in->offset, 492 call->name)); 493 /* we used to return NT_STATUS_INFO_LENGTH_MISMATCH here, 494 but it turns out that early versions of NT 495 (specifically NT3.1) add junk onto the end of rpc 496 packets, so if we want to interoperate at all with 497 those versions then we need to ignore this error */ 498 } 499 500 if (hs->p->conn->flags & DCERPC_DEBUG_VALIDATE_OUT) { 501 NTSTATUS status; 502 503 status = dcerpc_ndr_validate_out(hs->p->conn, 504 pull_in, 505 struct_ptr, 506 call->struct_size, 507 call->ndr_push, 508 call->ndr_pull, 509 call->ndr_print); 510 if (!NT_STATUS_IS_OK(status)) { 511 DEBUG(2,("Validation [out] failed for %s - %s\n", 512 call->name, nt_errstr(status))); 513 return status; 514 } 515 } 516 517 return NT_STATUS_OK; 518 } 519 520 static const struct dcerpc_binding_handle_ops dcerpc_bh_ops = { 521 .name = "dcerpc", 522 .is_connected = dcerpc_bh_is_connected, 523 .set_timeout = dcerpc_bh_set_timeout, 524 .raw_call_send = dcerpc_bh_raw_call_send, 525 .raw_call_recv = dcerpc_bh_raw_call_recv, 526 .disconnect_send = dcerpc_bh_disconnect_send, 527 .disconnect_recv = dcerpc_bh_disconnect_recv, 528 529 .push_bigendian = dcerpc_bh_push_bigendian, 530 .ref_alloc = dcerpc_bh_ref_alloc, 531 .use_ndr64 = dcerpc_bh_use_ndr64, 532 .do_ndr_print = dcerpc_bh_do_ndr_print, 533 .ndr_push_failed = dcerpc_bh_ndr_push_failed, 534 .ndr_pull_failed = dcerpc_bh_ndr_pull_failed, 535 .ndr_validate_in = dcerpc_bh_ndr_validate_in, 536 .ndr_validate_out = dcerpc_bh_ndr_validate_out, 537 }; 538 92 539 /* initialise a dcerpc pipe. */ 93 _PUBLIC_ struct dcerpc_pipe *dcerpc_pipe_init(TALLOC_CTX *mem_ctx, struct tevent_context *ev, 94 struct smb_iconv_convenience *ic) 540 struct dcerpc_binding_handle *dcerpc_pipe_binding_handle(struct dcerpc_pipe *p) 541 { 542 struct dcerpc_binding_handle *h; 543 struct dcerpc_bh_state *hs; 544 545 h = dcerpc_binding_handle_create(p, 546 &dcerpc_bh_ops, 547 NULL, 548 NULL, /* TODO */ 549 &hs, 550 struct dcerpc_bh_state, 551 __location__); 552 if (h == NULL) { 553 return NULL; 554 } 555 hs->p = p; 556 557 dcerpc_binding_handle_set_sync_ev(h, p->conn->event_ctx); 558 559 return h; 560 } 561 562 /* initialise a dcerpc pipe. */ 563 _PUBLIC_ struct dcerpc_pipe *dcerpc_pipe_init(TALLOC_CTX *mem_ctx, struct tevent_context *ev) 95 564 { 96 565 struct dcerpc_pipe *p; 97 566 98 p = talloc (mem_ctx, struct dcerpc_pipe);567 p = talloc_zero(mem_ctx, struct dcerpc_pipe); 99 568 if (!p) { 100 569 return NULL; 101 570 } 102 571 103 p->conn = dcerpc_connection_init(p, ev , ic);572 p->conn = dcerpc_connection_init(p, ev); 104 573 if (p->conn == NULL) { 105 574 talloc_free(p); … … 119 588 } 120 589 590 p->binding_handle = dcerpc_pipe_binding_handle(p); 591 if (p->binding_handle == NULL) { 592 talloc_free(p); 593 return NULL; 594 } 595 121 596 return p; 122 597 } … … 126 601 choose the next call id to use 127 602 */ 128 static uint32_t next_call_id(struct dce rpc_connection *c)603 static uint32_t next_call_id(struct dcecli_connection *c) 129 604 { 130 605 c->call_id++; … … 135 610 } 136 611 137 /* we need to be able to get/set the fragment length without doing a full138 decode */139 void dcerpc_set_frag_length(DATA_BLOB *blob, uint16_t v)140 {141 if (CVAL(blob->data,DCERPC_DREP_OFFSET) & DCERPC_DREP_LE) {142 SSVAL(blob->data, DCERPC_FRAG_LEN_OFFSET, v);143 } else {144 RSSVAL(blob->data, DCERPC_FRAG_LEN_OFFSET, v);145 }146 }147 148 uint16_t dcerpc_get_frag_length(const DATA_BLOB *blob)149 {150 if (CVAL(blob->data,DCERPC_DREP_OFFSET) & DCERPC_DREP_LE) {151 return SVAL(blob->data, DCERPC_FRAG_LEN_OFFSET);152 } else {153 return RSVAL(blob->data, DCERPC_FRAG_LEN_OFFSET);154 }155 }156 157 void dcerpc_set_auth_length(DATA_BLOB *blob, uint16_t v)158 {159 if (CVAL(blob->data,DCERPC_DREP_OFFSET) & DCERPC_DREP_LE) {160 SSVAL(blob->data, DCERPC_AUTH_LEN_OFFSET, v);161 } else {162 RSSVAL(blob->data, DCERPC_AUTH_LEN_OFFSET, v);163 }164 }165 166 167 612 /** 168 613 setup for a ndr pull, also setting up any flags from the binding string 169 614 */ 170 static struct ndr_pull *ndr_pull_init_flags(struct dce rpc_connection *c,615 static struct ndr_pull *ndr_pull_init_flags(struct dcecli_connection *c, 171 616 DATA_BLOB *blob, TALLOC_CTX *mem_ctx) 172 617 { 173 struct ndr_pull *ndr = ndr_pull_init_blob(blob, mem_ctx , c->iconv_convenience);618 struct ndr_pull *ndr = ndr_pull_init_blob(blob, mem_ctx); 174 619 175 620 if (ndr == NULL) return ndr; … … 194 639 input and output packets 195 640 */ 196 static NTSTATUS ncacn_pull(struct dce rpc_connection *c, DATA_BLOB *blob, TALLOC_CTX *mem_ctx,641 static NTSTATUS ncacn_pull(struct dcecli_connection *c, DATA_BLOB *blob, TALLOC_CTX *mem_ctx, 197 642 struct ncacn_packet *pkt) 198 643 { … … 220 665 parse the authentication information on a dcerpc response packet 221 666 */ 222 static NTSTATUS ncacn_pull_request_auth(struct dce rpc_connection *c, TALLOC_CTX *mem_ctx,667 static NTSTATUS ncacn_pull_request_auth(struct dcecli_connection *c, TALLOC_CTX *mem_ctx, 223 668 DATA_BLOB *raw_packet, 224 669 struct ncacn_packet *pkt) 225 670 { 226 struct ndr_pull *ndr;227 671 NTSTATUS status; 228 672 struct dcerpc_auth auth; 229 DATA_BLOB auth_blob; 230 enum ndr_err_code ndr_err; 673 uint32_t auth_length; 231 674 232 675 if (!c->security_state.auth_info || … … 255 698 } 256 699 257 auth_blob.length = 8 + pkt->auth_length; 258 259 /* check for a valid length */ 260 if (pkt->u.response.stub_and_verifier.length < auth_blob.length) { 261 return NT_STATUS_INFO_LENGTH_MISMATCH; 262 } 263 264 auth_blob.data = 265 pkt->u.response.stub_and_verifier.data + 266 pkt->u.response.stub_and_verifier.length - auth_blob.length; 267 pkt->u.response.stub_and_verifier.length -= auth_blob.length; 268 269 /* pull the auth structure */ 270 ndr = ndr_pull_init_flags(c, &auth_blob, mem_ctx); 271 if (!ndr) { 272 return NT_STATUS_NO_MEMORY; 273 } 274 275 if (!(pkt->drep[0] & DCERPC_DREP_LE)) { 276 ndr->flags |= LIBNDR_FLAG_BIGENDIAN; 277 } 278 279 ndr_err = ndr_pull_dcerpc_auth(ndr, NDR_SCALARS|NDR_BUFFERS, &auth); 280 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) { 281 return ndr_map_error2ntstatus(ndr_err); 282 } 283 status = NT_STATUS_OK; 700 status = dcerpc_pull_auth_trailer(pkt, mem_ctx, 701 &pkt->u.response.stub_and_verifier, 702 &auth, &auth_length, false); 703 NT_STATUS_NOT_OK_RETURN(status); 704 705 pkt->u.response.stub_and_verifier.length -= auth_length; 284 706 285 707 /* check signature or unseal the packet */ … … 318 740 } 319 741 320 /* remove the indicated amount of paddi ing */742 /* remove the indicated amount of padding */ 321 743 if (pkt->u.response.stub_and_verifier.length < auth.auth_pad_length) { 322 744 return NT_STATUS_INFO_LENGTH_MISMATCH; … … 331 753 push a dcerpc request packet into a blob, possibly signing it. 332 754 */ 333 static NTSTATUS ncacn_push_request_sign(struct dce rpc_connection *c,755 static NTSTATUS ncacn_push_request_sign(struct dcecli_connection *c, 334 756 DATA_BLOB *blob, TALLOC_CTX *mem_ctx, 335 757 size_t sig_size, … … 345 767 /* non-signed packets are simpler */ 346 768 if (sig_size == 0) { 347 return ncacn_push_auth(blob, mem_ctx, c->iconv_convenience,pkt, NULL);769 return ncacn_push_auth(blob, mem_ctx, pkt, NULL); 348 770 } 349 771 … … 355 777 case DCERPC_AUTH_LEVEL_CONNECT: 356 778 /* TODO: let the gensec mech decide if it wants to generate a signature */ 357 return ncacn_push_auth(blob, mem_ctx, c->iconv_convenience,pkt, NULL);779 return ncacn_push_auth(blob, mem_ctx, pkt, NULL); 358 780 359 781 case DCERPC_AUTH_LEVEL_NONE: 360 return ncacn_push_auth(blob, mem_ctx, c->iconv_convenience,pkt, NULL);782 return ncacn_push_auth(blob, mem_ctx, pkt, NULL); 361 783 362 784 default: … … 364 786 } 365 787 366 ndr = ndr_push_init_ctx(mem_ctx , c->iconv_convenience);788 ndr = ndr_push_init_ctx(mem_ctx); 367 789 if (!ndr) { 368 790 return NT_STATUS_NO_MEMORY; … … 386 808 return ndr_map_error2ntstatus(ndr_err); 387 809 } 388 status = NT_STATUS_OK;389 810 390 811 /* pad to 16 byte multiple in the payload portion of the 391 packet. This matches what w2k3 does */ 392 c->security_state.auth_info->auth_pad_length = 812 packet. This matches what w2k3 does. Note that we can't use 813 ndr_push_align() as that is relative to the start of the 814 whole packet, whereas w2k8 wants it relative to the start 815 of the stub */ 816 c->security_state.auth_info->auth_pad_length = 393 817 (16 - (pkt->u.request.stub_and_verifier.length & 15)) & 15; 394 818 ndr_err = ndr_push_zero(ndr, c->security_state.auth_info->auth_pad_length); … … 396 820 return ndr_map_error2ntstatus(ndr_err); 397 821 } 398 status = NT_STATUS_OK;399 822 400 823 payload_length = pkt->u.request.stub_and_verifier.length + … … 409 832 return ndr_map_error2ntstatus(ndr_err); 410 833 } 411 status = NT_STATUS_OK;412 834 413 835 /* extract the whole packet as a blob */ … … 457 879 458 880 if (creds2.length != sig_size) { 459 DEBUG(0,("ncacn_push_request_sign: creds2.length[%u] != sig_size[%u] pad[%u] stub[%u]\n", 460 creds2.length, (uint32_t)sig_size, 461 c->security_state.auth_info->auth_pad_length, 462 pkt->u.request.stub_and_verifier.length)); 463 return NT_STATUS_INTERNAL_ERROR; 881 /* this means the sig_size estimate for the signature 882 was incorrect. We have to correct the packet 883 sizes. That means we could go over the max fragment 884 length */ 885 DEBUG(3,("ncacn_push_request_sign: creds2.length[%u] != sig_size[%u] pad[%u] stub[%u]\n", 886 (unsigned) creds2.length, 887 (unsigned) sig_size, 888 (unsigned) c->security_state.auth_info->auth_pad_length, 889 (unsigned) pkt->u.request.stub_and_verifier.length)); 890 dcerpc_set_frag_length(blob, blob->length + creds2.length); 891 dcerpc_set_auth_length(blob, creds2.length); 464 892 } 465 893 … … 475 903 fill in the fixed values in a dcerpc header 476 904 */ 477 static void init_ncacn_hdr(struct dce rpc_connection *c, struct ncacn_packet *pkt)905 static void init_ncacn_hdr(struct dcecli_connection *c, struct ncacn_packet *pkt) 478 906 { 479 907 pkt->rpc_vers = 5; … … 535 963 mark the dcerpc connection dead. All outstanding requests get an error 536 964 */ 537 static void dcerpc_connection_dead(struct dce rpc_connection *conn, NTSTATUS status)965 static void dcerpc_connection_dead(struct dcecli_connection *conn, NTSTATUS status) 538 966 { 539 967 if (conn->dead) return; … … 566 994 packets we need to handle 567 995 */ 568 static void dcerpc_request_recv_data(struct dce rpc_connection *c,996 static void dcerpc_request_recv_data(struct dcecli_connection *c, 569 997 DATA_BLOB *raw_packet, struct ncacn_packet *pkt); 570 998 … … 574 1002 dispatch to the appropriate handler 575 1003 */ 576 static void dcerpc_recv_data(struct dce rpc_connection *conn, DATA_BLOB *blob, NTSTATUS status)1004 static void dcerpc_recv_data(struct dcecli_connection *conn, DATA_BLOB *blob, NTSTATUS status) 577 1005 { 578 1006 struct ncacn_packet pkt; … … 600 1028 } 601 1029 602 603 1030 /* 604 1031 Receive a bind reply from the transport … … 608 1035 { 609 1036 struct composite_context *c; 610 struct dce rpc_connection *conn;1037 struct dcecli_connection *conn; 611 1038 612 1039 c = talloc_get_type(req->async.private_data, struct composite_context); … … 623 1050 (pkt->u.bind_ack.num_results == 0) || 624 1051 (pkt->u.bind_ack.ctx_list[0].result != 0)) { 1052 req->p->last_fault_code = DCERPC_NCA_S_PROTO_ERROR; 625 1053 composite_error(c, NT_STATUS_NET_WRITE_FAULT); 626 1054 return; … … 643 1071 644 1072 /* the bind_ack might contain a reply set of credentials */ 645 if (conn->security_state.auth_info && 646 pkt->u.bind_ack.auth_info.length) { 647 enum ndr_err_code ndr_err; 648 ndr_err = ndr_pull_struct_blob( 649 &pkt->u.bind_ack.auth_info, conn, 650 NULL, 651 conn->security_state.auth_info, 652 (ndr_pull_flags_fn_t)ndr_pull_dcerpc_auth); 653 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) { 654 c->status = ndr_map_error2ntstatus(ndr_err); 655 if (!composite_is_ok(c)) return; 1073 if (conn->security_state.auth_info && pkt->u.bind_ack.auth_info.length) { 1074 NTSTATUS status; 1075 uint32_t auth_length; 1076 status = dcerpc_pull_auth_trailer(pkt, conn, &pkt->u.bind_ack.auth_info, 1077 conn->security_state.auth_info, &auth_length, true); 1078 if (!NT_STATUS_IS_OK(status)) { 1079 composite_error(c, status); 1080 return; 656 1081 } 657 1082 } … … 732 1157 733 1158 /* construct the NDR form of the packet */ 734 c->status = ncacn_push_auth(&blob, c, p->conn->iconv_convenience,&pkt,1159 c->status = ncacn_push_auth(&blob, c, &pkt, 735 1160 p->conn->security_state.auth_info); 736 1161 if (!composite_is_ok(c)) return c; … … 791 1216 pkt.call_id = next_call_id(p->conn); 792 1217 pkt.auth_length = 0; 793 pkt.u.auth3._pad = 0;794 1218 pkt.u.auth3.auth_info = data_blob(NULL, 0); 795 1219 … … 804 1228 /* construct the NDR form of the packet */ 805 1229 status = ncacn_push_auth(&blob, mem_ctx, 806 p->conn->iconv_convenience,807 1230 &pkt, 808 1231 p->conn->security_state.auth_info); … … 827 1250 This function frees the data 828 1251 */ 829 static void dcerpc_request_recv_data(struct dce rpc_connection *c,1252 static void dcerpc_request_recv_data(struct dcecli_connection *c, 830 1253 DATA_BLOB *raw_packet, struct ncacn_packet *pkt) 831 1254 { 832 1255 struct rpc_request *req; 833 u int_t length;1256 unsigned int length; 834 1257 NTSTATUS status = NT_STATUS_OK; 835 1258 … … 947 1370 const struct GUID *object, 948 1371 uint16_t opnum, 949 bool async,950 1372 DATA_BLOB *stub_data) 951 1373 { … … 966 1388 req->flags = 0; 967 1389 req->fault_code = 0; 968 req->async_call = async;969 1390 req->ignore_timeout = false; 970 1391 req->async.callback = NULL; … … 1007 1428 */ 1008 1429 1009 static void dcerpc_ship_next_request(struct dce rpc_connection *c)1430 static void dcerpc_ship_next_request(struct dcecli_connection *c) 1010 1431 { 1011 1432 struct rpc_request *req; … … 1017 1438 bool first_packet = true; 1018 1439 size_t sig_size = 0; 1440 bool need_async = false; 1019 1441 1020 1442 req = c->request_queue; … … 1026 1448 stub_data = &req->request_data; 1027 1449 1028 if ( !req->async_call && (c->pending != NULL)) {1029 return;1450 if (c->pending) { 1451 need_async = true; 1030 1452 } 1031 1453 … … 1064 1486 pkt.u.request.object.object = *req->object; 1065 1487 pkt.pfc_flags |= DCERPC_PFC_FLAG_OBJECT_UUID; 1066 chunk_size -= ndr_size_GUID(req->object, NULL,0);1488 chunk_size -= ndr_size_GUID(req->object,0); 1067 1489 } 1068 1490 … … 1095 1517 } 1096 1518 1097 if (last_frag && ! req->async_call) {1519 if (last_frag && !need_async) { 1098 1520 do_trans = true; 1099 1521 } … … 1133 1555 perform the receive side of a async dcerpc request 1134 1556 */ 1135 NTSTATUS dcerpc_request_recv(struct rpc_request *req,1136 1137 1557 static NTSTATUS dcerpc_request_recv(struct rpc_request *req, 1558 TALLOC_CTX *mem_ctx, 1559 DATA_BLOB *stub_data) 1138 1560 { 1139 1561 NTSTATUS status; … … 1158 1580 1159 1581 /* 1160 perform a full request/response pair on a dcerpc pipe1161 */1162 NTSTATUS dcerpc_request(struct dcerpc_pipe *p,1163 struct GUID *object,1164 uint16_t opnum,1165 TALLOC_CTX *mem_ctx,1166 DATA_BLOB *stub_data_in,1167 DATA_BLOB *stub_data_out)1168 {1169 struct rpc_request *req;1170 1171 req = dcerpc_request_send(p, object, opnum, false, stub_data_in);1172 if (req == NULL) {1173 return NT_STATUS_NO_MEMORY;1174 }1175 1176 return dcerpc_request_recv(req, mem_ctx, stub_data_out);1177 }1178 1179 1180 /*1181 1582 this is a paranoid NDR validator. For every packet we push onto the wire 1182 1583 we pull it back again, then push it again. Then we compare the raw NDR data … … 1184 1585 we must have a bug in either the pull or push side of our code 1185 1586 */ 1186 static NTSTATUS dcerpc_ndr_validate_in(struct dce rpc_connection *c,1587 static NTSTATUS dcerpc_ndr_validate_in(struct dcecli_connection *c, 1187 1588 TALLOC_CTX *mem_ctx, 1188 1589 DATA_BLOB blob, … … 1207 1608 } 1208 1609 pull->flags |= LIBNDR_FLAG_REF_ALLOC; 1610 1611 if (c->flags & DCERPC_PUSH_BIGENDIAN) { 1612 pull->flags |= LIBNDR_FLAG_BIGENDIAN; 1613 } 1614 1615 if (c->flags & DCERPC_NDR64) { 1616 pull->flags |= LIBNDR_FLAG_NDR64; 1617 } 1209 1618 1210 1619 ndr_err = ndr_pull(pull, NDR_IN, st); … … 1217 1626 } 1218 1627 1219 push = ndr_push_init_ctx(mem_ctx , c->iconv_convenience);1628 push = ndr_push_init_ctx(mem_ctx); 1220 1629 if (!push) { 1221 1630 return NT_STATUS_NO_MEMORY; 1222 1631 } 1632 1633 if (c->flags & DCERPC_PUSH_BIGENDIAN) { 1634 push->flags |= LIBNDR_FLAG_BIGENDIAN; 1635 } 1636 1637 if (c->flags & DCERPC_NDR64) { 1638 push->flags |= LIBNDR_FLAG_NDR64; 1639 } 1223 1640 1224 1641 ndr_err = ndr_push(push, NDR_IN, st); … … 1253 1670 bug in either the pull or push side of our code 1254 1671 */ 1255 static NTSTATUS dcerpc_ndr_validate_out(struct dce rpc_connection *c,1672 static NTSTATUS dcerpc_ndr_validate_out(struct dcecli_connection *c, 1256 1673 struct ndr_pull *pull_in, 1257 1674 void *struct_ptr, … … 1275 1692 memcpy(st, struct_ptr, struct_size); 1276 1693 1277 push = ndr_push_init_ctx(mem_ctx , c->iconv_convenience);1694 push = ndr_push_init_ctx(mem_ctx); 1278 1695 if (!push) { 1279 1696 return NT_STATUS_NO_MEMORY; … … 1306 1723 } 1307 1724 1308 push = ndr_push_init_ctx(mem_ctx , c->iconv_convenience);1725 push = ndr_push_init_ctx(mem_ctx); 1309 1726 if (!push) { 1310 1727 return NT_STATUS_NO_MEMORY; … … 1356 1773 } 1357 1774 1358 1359 /**1360 send a rpc request given a dcerpc_call structure1361 */1362 struct rpc_request *dcerpc_ndr_request_send(struct dcerpc_pipe *p,1363 const struct GUID *object,1364 const struct ndr_interface_table *table,1365 uint32_t opnum,1366 bool async,1367 TALLOC_CTX *mem_ctx,1368 void *r)1369 {1370 const struct ndr_interface_call *call;1371 struct ndr_push *push;1372 NTSTATUS status;1373 DATA_BLOB request;1374 struct rpc_request *req;1375 enum ndr_err_code ndr_err;1376 1377 call = &table->calls[opnum];1378 1379 /* setup for a ndr_push_* call */1380 push = ndr_push_init_ctx(mem_ctx, p->conn->iconv_convenience);1381 if (!push) {1382 return NULL;1383 }1384 1385 if (p->conn->flags & DCERPC_PUSH_BIGENDIAN) {1386 push->flags |= LIBNDR_FLAG_BIGENDIAN;1387 }1388 1389 if (p->conn->flags & DCERPC_NDR64) {1390 push->flags |= LIBNDR_FLAG_NDR64;1391 }1392 1393 /* push the structure into a blob */1394 ndr_err = call->ndr_push(push, NDR_IN, r);1395 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {1396 status = ndr_map_error2ntstatus(ndr_err);1397 DEBUG(2,("Unable to ndr_push structure in dcerpc_ndr_request_send - %s\n",1398 nt_errstr(status)));1399 talloc_free(push);1400 return NULL;1401 }1402 1403 /* retrieve the blob */1404 request = ndr_push_blob(push);1405 1406 if (p->conn->flags & DCERPC_DEBUG_VALIDATE_IN) {1407 status = dcerpc_ndr_validate_in(p->conn, push, request, call->struct_size,1408 call->ndr_push, call->ndr_pull);1409 if (!NT_STATUS_IS_OK(status)) {1410 DEBUG(2,("Validation failed in dcerpc_ndr_request_send - %s\n",1411 nt_errstr(status)));1412 talloc_free(push);1413 return NULL;1414 }1415 }1416 1417 DEBUG(10,("rpc request data:\n"));1418 dump_data(10, request.data, request.length);1419 1420 /* make the actual dcerpc request */1421 req = dcerpc_request_send(p, object, opnum, async, &request);1422 1423 if (req != NULL) {1424 req->ndr.table = table;1425 req->ndr.opnum = opnum;1426 req->ndr.struct_ptr = r;1427 req->ndr.mem_ctx = mem_ctx;1428 }1429 1430 talloc_free(push);1431 1432 return req;1433 }1434 1435 /*1436 receive the answer from a dcerpc_ndr_request_send()1437 */1438 _PUBLIC_ NTSTATUS dcerpc_ndr_request_recv(struct rpc_request *req)1439 {1440 struct dcerpc_pipe *p = req->p;1441 NTSTATUS status;1442 DATA_BLOB response;1443 struct ndr_pull *pull;1444 uint_t flags;1445 TALLOC_CTX *mem_ctx = req->ndr.mem_ctx;1446 void *r = req->ndr.struct_ptr;1447 uint32_t opnum = req->ndr.opnum;1448 const struct ndr_interface_table *table = req->ndr.table;1449 const struct ndr_interface_call *call = &table->calls[opnum];1450 enum ndr_err_code ndr_err;1451 1452 /* make sure the recv code doesn't free the request, as we1453 need to grab the flags element before it is freed */1454 if (talloc_reference(p, req) == NULL) {1455 return NT_STATUS_NO_MEMORY;1456 }1457 1458 status = dcerpc_request_recv(req, mem_ctx, &response);1459 if (!NT_STATUS_IS_OK(status)) {1460 talloc_unlink(p, req);1461 return status;1462 }1463 1464 flags = req->flags;1465 1466 /* prepare for ndr_pull_* */1467 pull = ndr_pull_init_flags(p->conn, &response, mem_ctx);1468 if (!pull) {1469 talloc_unlink(p, req);1470 return NT_STATUS_NO_MEMORY;1471 }1472 1473 if (pull->data) {1474 pull->data = talloc_steal(pull, pull->data);1475 }1476 talloc_unlink(p, req);1477 1478 if (flags & DCERPC_PULL_BIGENDIAN) {1479 pull->flags |= LIBNDR_FLAG_BIGENDIAN;1480 }1481 1482 DEBUG(10,("rpc reply data:\n"));1483 dump_data(10, pull->data, pull->data_size);1484 1485 /* pull the structure from the blob */1486 ndr_err = call->ndr_pull(pull, NDR_OUT, r);1487 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {1488 status = ndr_map_error2ntstatus(ndr_err);1489 dcerpc_log_packet(p->conn->packet_log_dir,1490 table, opnum, NDR_OUT,1491 &response);1492 return status;1493 }1494 1495 if (p->conn->flags & DCERPC_DEBUG_VALIDATE_OUT) {1496 status = dcerpc_ndr_validate_out(p->conn, pull, r, call->struct_size,1497 call->ndr_push, call->ndr_pull,1498 call->ndr_print);1499 if (!NT_STATUS_IS_OK(status)) {1500 dcerpc_log_packet(p->conn->packet_log_dir,1501 table, opnum, NDR_OUT,1502 &response);1503 return status;1504 }1505 }1506 1507 if (pull->offset != pull->data_size) {1508 DEBUG(0,("Warning! ignoring %d unread bytes in rpc packet!\n",1509 pull->data_size - pull->offset));1510 /* we used to return NT_STATUS_INFO_LENGTH_MISMATCH here,1511 but it turns out that early versions of NT1512 (specifically NT3.1) add junk onto the end of rpc1513 packets, so if we want to interoperate at all with1514 those versions then we need to ignore this error */1515 }1516 1517 /* TODO: make pull context independent from the output mem_ctx and free the pull context */1518 1519 return NT_STATUS_OK;1520 }1521 1522 1523 /*1524 a useful helper function for synchronous rpc requests1525 1526 this can be used when you have ndr push/pull functions in the1527 standard format1528 */1529 _PUBLIC_ NTSTATUS dcerpc_ndr_request(struct dcerpc_pipe *p,1530 const struct GUID *object,1531 const struct ndr_interface_table *table,1532 uint32_t opnum,1533 TALLOC_CTX *mem_ctx,1534 void *r)1535 {1536 struct rpc_request *req;1537 1538 req = dcerpc_ndr_request_send(p, object, table, opnum, false, mem_ctx, r);1539 if (req == NULL) {1540 return NT_STATUS_NO_MEMORY;1541 }1542 1543 return dcerpc_ndr_request_recv(req);1544 }1545 1546 1547 1775 /* 1548 1776 a useful function for retrieving the server name we connected to … … 1563 1791 get the dcerpc auth_level for a open connection 1564 1792 */ 1565 uint32_t dcerpc_auth_level(struct dce rpc_connection *c)1793 uint32_t dcerpc_auth_level(struct dcecli_connection *c) 1566 1794 { 1567 1795 uint8_t auth_level; … … 1600 1828 } 1601 1829 1830 if (pkt->ptype == DCERPC_PKT_FAULT) { 1831 DEBUG(5,("rpc fault: %s\n", dcerpc_errstr(c, pkt->u.fault.status))); 1832 recv_pipe->last_fault_code = pkt->u.fault.status; 1833 composite_error(c, NT_STATUS_NET_WRITE_FAULT); 1834 return; 1835 } 1836 1602 1837 if (pkt->ptype != DCERPC_PKT_ALTER_RESP || 1603 1838 pkt->u.alter_resp.num_results == 0 || 1604 1839 pkt->u.alter_resp.ctx_list[0].result != 0) { 1840 recv_pipe->last_fault_code = DCERPC_NCA_S_PROTO_ERROR; 1605 1841 composite_error(c, NT_STATUS_NET_WRITE_FAULT); 1606 1842 return; … … 1610 1846 if (recv_pipe->conn->security_state.auth_info && 1611 1847 pkt->u.alter_resp.auth_info.length) { 1612 enum ndr_err_code ndr_err; 1613 ndr_err = ndr_pull_struct_blob( 1614 &pkt->u.alter_resp.auth_info, recv_pipe, 1615 NULL, 1616 recv_pipe->conn->security_state.auth_info, 1617 (ndr_pull_flags_fn_t)ndr_pull_dcerpc_auth); 1618 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) { 1619 c->status = ndr_map_error2ntstatus(ndr_err); 1620 if (!composite_is_ok(c)) return; 1848 struct dcecli_connection *conn = recv_pipe->conn; 1849 NTSTATUS status; 1850 uint32_t auth_length; 1851 status = dcerpc_pull_auth_trailer(pkt, conn, &pkt->u.alter_resp.auth_info, 1852 conn->security_state.auth_info, &auth_length, true); 1853 if (!NT_STATUS_IS_OK(status)) { 1854 composite_error(c, status); 1855 return; 1621 1856 } 1622 1857 } … … 1674 1909 1675 1910 /* construct the NDR form of the packet */ 1676 c->status = ncacn_push_auth(&blob, mem_ctx, p->conn->iconv_convenience,&pkt,1911 c->status = ncacn_push_auth(&blob, mem_ctx, &pkt, 1677 1912 p->conn->security_state.auth_info); 1678 1913 if (!composite_is_ok(c)) return c; … … 1725 1960 return dcerpc_alter_context_recv(creq); 1726 1961 } 1962 -
vendor/current/source4/librpc/rpc/dcerpc.h
r414 r740 25 25 * the so version number. */ 26 26 27 #ifndef __ DCERPC_H__28 #define __ DCERPC_H__27 #ifndef __S4_DCERPC_H__ 28 #define __S4_DCERPC_H__ 29 29 30 30 #include "../lib/util/data_blob.h" 31 31 #include "librpc/gen_ndr/dcerpc.h" 32 32 #include "../librpc/ndr/libndr.h" 33 34 enum dcerpc_transport_t { 35 NCA_UNKNOWN, NCACN_NP, NCACN_IP_TCP, NCACN_IP_UDP, NCACN_VNS_IPC, 36 NCACN_VNS_SPP, NCACN_AT_DSP, NCADG_AT_DDP, NCALRPC, NCACN_UNIX_STREAM, 37 NCADG_UNIX_DGRAM, NCACN_HTTP, NCADG_IPX, NCACN_SPX }; 33 #include "../librpc/rpc/rpc_common.h" 34 35 struct tevent_context; 36 struct tevent_req; 37 struct dcerpc_binding_handle; 38 struct tstream_context; 38 39 39 40 /* 40 41 this defines a generic security context for signed/sealed dcerpc pipes. 41 42 */ 42 struct dce rpc_connection;43 struct dcecli_connection; 43 44 struct gensec_settings; 44 struct dce rpc_security {45 struct dcecli_security { 45 46 struct dcerpc_auth *auth_info; 46 47 struct gensec_security *generic_state; 47 48 48 49 /* get the session key */ 49 NTSTATUS (*session_key)(struct dce rpc_connection *, DATA_BLOB *);50 NTSTATUS (*session_key)(struct dcecli_connection *, DATA_BLOB *); 50 51 }; 51 52 … … 53 54 this holds the information that is not specific to a particular rpc context_id 54 55 */ 55 struct dcerpc_connection { 56 struct rpc_request; 57 struct dcecli_connection { 56 58 uint32_t call_id; 57 59 uint32_t srv_max_xmit_frag; 58 60 uint32_t srv_max_recv_frag; 59 61 uint32_t flags; 60 struct dce rpc_security security_state;62 struct dcecli_security security_state; 61 63 const char *binding_string; 62 64 struct tevent_context *event_ctx; 63 struct smb_iconv_convenience *iconv_convenience;64 65 65 66 /** Directory in which to save ndrdump-parseable files */ … … 73 74 void *private_data; 74 75 75 NTSTATUS (*shutdown_pipe)(struct dce rpc_connection *, NTSTATUS status);76 77 const char *(*peer_name)(struct dce rpc_connection *);78 79 const char *(*target_hostname)(struct dce rpc_connection *);76 NTSTATUS (*shutdown_pipe)(struct dcecli_connection *, NTSTATUS status); 77 78 const char *(*peer_name)(struct dcecli_connection *); 79 80 const char *(*target_hostname)(struct dcecli_connection *); 80 81 81 82 /* send a request to the server */ 82 NTSTATUS (*send_request)(struct dce rpc_connection *, DATA_BLOB *, bool trigger_read);83 NTSTATUS (*send_request)(struct dcecli_connection *, DATA_BLOB *, bool trigger_read); 83 84 84 85 /* send a read request to the server */ 85 NTSTATUS (*send_read)(struct dce rpc_connection *);86 NTSTATUS (*send_read)(struct dcecli_connection *); 86 87 87 88 /* a callback to the dcerpc code when a full fragment 88 89 has been received */ 89 void (*recv_data)(struct dce rpc_connection *, DATA_BLOB *, NTSTATUS status);90 void (*recv_data)(struct dcecli_connection *, DATA_BLOB *, NTSTATUS status); 90 91 } transport; 91 92 … … 104 105 */ 105 106 struct dcerpc_pipe { 107 struct dcerpc_binding_handle *binding_handle; 108 106 109 uint32_t context_id; 107 110 … … 111 114 struct ndr_syntax_id transfer_syntax; 112 115 113 struct dce rpc_connection *conn;116 struct dcecli_connection *conn; 114 117 struct dcerpc_binding *binding; 115 118 … … 123 126 /* default timeout for all rpc requests, in seconds */ 124 127 #define DCERPC_REQUEST_TIMEOUT 60 125 126 127 /* dcerpc pipe flags */128 #define DCERPC_DEBUG_PRINT_IN (1<<0)129 #define DCERPC_DEBUG_PRINT_OUT (1<<1)130 #define DCERPC_DEBUG_PRINT_BOTH (DCERPC_DEBUG_PRINT_IN | DCERPC_DEBUG_PRINT_OUT)131 132 #define DCERPC_DEBUG_VALIDATE_IN (1<<2)133 #define DCERPC_DEBUG_VALIDATE_OUT (1<<3)134 #define DCERPC_DEBUG_VALIDATE_BOTH (DCERPC_DEBUG_VALIDATE_IN | DCERPC_DEBUG_VALIDATE_OUT)135 136 #define DCERPC_CONNECT (1<<4)137 #define DCERPC_SIGN (1<<5)138 #define DCERPC_SEAL (1<<6)139 140 #define DCERPC_PUSH_BIGENDIAN (1<<7)141 #define DCERPC_PULL_BIGENDIAN (1<<8)142 143 #define DCERPC_SCHANNEL (1<<9)144 145 #define DCERPC_ANON_FALLBACK (1<<10)146 147 /* use a 128 bit session key */148 #define DCERPC_SCHANNEL_128 (1<<12)149 150 /* check incoming pad bytes */151 #define DCERPC_DEBUG_PAD_CHECK (1<<13)152 153 /* set LIBNDR_FLAG_REF_ALLOC flag when decoding NDR */154 #define DCERPC_NDR_REF_ALLOC (1<<14)155 156 #define DCERPC_AUTH_OPTIONS (DCERPC_SEAL|DCERPC_SIGN|DCERPC_SCHANNEL|DCERPC_AUTH_SPNEGO|DCERPC_AUTH_KRB5|DCERPC_AUTH_NTLM)157 158 /* select spnego auth */159 #define DCERPC_AUTH_SPNEGO (1<<15)160 161 /* select krb5 auth */162 #define DCERPC_AUTH_KRB5 (1<<16)163 164 #define DCERPC_SMB2 (1<<17)165 166 /* select NTLM auth */167 #define DCERPC_AUTH_NTLM (1<<18)168 169 /* this triggers the DCERPC_PFC_FLAG_CONC_MPX flag in the bind request */170 #define DCERPC_CONCURRENT_MULTIPLEX (1<<19)171 172 /* this triggers the DCERPC_PFC_FLAG_SUPPORT_HEADER_SIGN flag in the bind request */173 #define DCERPC_HEADER_SIGNING (1<<20)174 175 /* use NDR64 transport */176 #define DCERPC_NDR64 (1<<21)177 178 /* this describes a binding to a particular transport/pipe */179 struct dcerpc_binding {180 enum dcerpc_transport_t transport;181 struct ndr_syntax_id object;182 const char *host;183 const char *target_hostname;184 const char *endpoint;185 const char **options;186 uint32_t flags;187 uint32_t assoc_group_id;188 };189 128 190 129 … … 199 138 200 139 201 enum rpc_request_state {202 RPC_REQUEST_QUEUED,203 RPC_REQUEST_PENDING,204 RPC_REQUEST_DONE205 };206 207 /*208 handle for an async dcerpc request209 */210 struct rpc_request {211 struct rpc_request *next, *prev;212 struct dcerpc_pipe *p;213 NTSTATUS status;214 uint32_t call_id;215 enum rpc_request_state state;216 DATA_BLOB payload;217 uint32_t flags;218 uint32_t fault_code;219 220 /* this is used to distinguish bind and alter_context requests221 from normal requests */222 void (*recv_handler)(struct rpc_request *conn,223 DATA_BLOB *blob, struct ncacn_packet *pkt);224 225 const struct GUID *object;226 uint16_t opnum;227 DATA_BLOB request_data;228 bool async_call;229 bool ignore_timeout;230 231 /* use by the ndr level async recv call */232 struct {233 const struct ndr_interface_table *table;234 uint32_t opnum;235 void *struct_ptr;236 TALLOC_CTX *mem_ctx;237 } ndr;238 239 struct {240 void (*callback)(struct rpc_request *);241 void *private_data;242 } async;243 };244 245 140 struct epm_tower; 246 141 struct epm_floor; … … 257 152 struct tevent_context *ev, 258 153 struct loadparm_context *lp_ctx); 259 NTSTATUS dcerpc_ndr_request_recv(struct rpc_request *req);260 struct rpc_request *dcerpc_ndr_request_send(struct dcerpc_pipe *p,261 const struct GUID *object,262 const struct ndr_interface_table *table,263 uint32_t opnum,264 bool async,265 TALLOC_CTX *mem_ctx,266 void *r);267 154 const char *dcerpc_server_name(struct dcerpc_pipe *p); 268 struct dcerpc_pipe *dcerpc_pipe_init(TALLOC_CTX *mem_ctx, struct tevent_context *ev, 269 struct smb_iconv_convenience *ic); 155 struct dcerpc_pipe *dcerpc_pipe_init(TALLOC_CTX *mem_ctx, struct tevent_context *ev); 270 156 NTSTATUS dcerpc_pipe_open_smb(struct dcerpc_pipe *p, 271 157 struct smbcli_tree *tree, … … 278 164 NTSTATUS dcerpc_secondary_connection_recv(struct composite_context *c, 279 165 struct dcerpc_pipe **p2); 280 NTSTATUS dcerpc_parse_binding(TALLOC_CTX *mem_ctx, const char *s, struct dcerpc_binding **b_out);281 166 282 167 struct composite_context* dcerpc_pipe_connect_b_send(TALLOC_CTX *parent_ctx, … … 297 182 struct tevent_context *ev, 298 183 struct loadparm_context *lp_ctx); 299 const char *dcerpc_errstr(TALLOC_CTX *mem_ctx, uint32_t fault_code);300 184 301 185 NTSTATUS dcerpc_pipe_auth(TALLOC_CTX *mem_ctx, … … 305 189 struct cli_credentials *credentials, 306 190 struct loadparm_context *lp_ctx); 307 char *dcerpc_binding_string(TALLOC_CTX *mem_ctx, const struct dcerpc_binding *b);308 191 NTSTATUS dcerpc_secondary_connection(struct dcerpc_pipe *p, 309 192 struct dcerpc_pipe **p2, … … 317 200 struct tevent_context *dcerpc_event_context(struct dcerpc_pipe *p); 318 201 NTSTATUS dcerpc_init(struct loadparm_context *lp_ctx); 319 struct smbcli_tree *dcerpc_smb_tree(struct dce rpc_connection *c);320 uint16_t dcerpc_smb_fnum(struct dce rpc_connection *c);202 struct smbcli_tree *dcerpc_smb_tree(struct dcecli_connection *c); 203 uint16_t dcerpc_smb_fnum(struct dcecli_connection *c); 321 204 NTSTATUS dcerpc_secondary_context(struct dcerpc_pipe *p, 322 205 struct dcerpc_pipe **pp2, … … 357 240 struct dcerpc_binding *b); 358 241 void dcerpc_log_packet(const char *lockdir, 359 const struct ndr_interface_table *ndr, 360 uint32_t opnum, uint32_t flags, 361 DATA_BLOB *pkt); 362 NTSTATUS dcerpc_binding_build_tower(TALLOC_CTX *mem_ctx, 363 const struct dcerpc_binding *binding, 364 struct epm_tower *tower); 365 366 NTSTATUS dcerpc_floor_get_lhs_data(const struct epm_floor *epm_floor, struct ndr_syntax_id *syntax); 367 368 enum dcerpc_transport_t dcerpc_transport_by_tower(const struct epm_tower *tower); 369 const char *derpc_transport_string_by_transport(enum dcerpc_transport_t t); 370 371 NTSTATUS dcerpc_ndr_request(struct dcerpc_pipe *p, 372 const struct GUID *object, 373 const struct ndr_interface_table *table, 374 uint32_t opnum, 375 TALLOC_CTX *mem_ctx, 376 void *r); 377 378 NTSTATUS dcerpc_binding_from_tower(TALLOC_CTX *mem_ctx, 379 struct epm_tower *tower, 380 struct dcerpc_binding **b_out); 381 382 NTSTATUS dcerpc_request(struct dcerpc_pipe *p, 383 struct GUID *object, 384 uint16_t opnum, 385 TALLOC_CTX *mem_ctx, 386 DATA_BLOB *stub_data_in, 387 DATA_BLOB *stub_data_out); 388 389 typedef NTSTATUS (*dcerpc_call_fn) (struct dcerpc_pipe *, TALLOC_CTX *, void *); 242 const struct ndr_interface_table *ndr, 243 uint32_t opnum, uint32_t flags, 244 const DATA_BLOB *pkt); 245 390 246 391 247 enum dcerpc_transport_t dcerpc_transport_by_endpoint_protocol(int prot); … … 393 249 const char *dcerpc_floor_get_rhs_data(TALLOC_CTX *mem_ctx, struct epm_floor *epm_floor); 394 250 395 #endif /* __ DCERPC_H__ */251 #endif /* __S4_DCERPC_H__ */ -
vendor/current/source4/librpc/rpc/dcerpc.py
r414 r740 1 #!/usr/bin/ python1 #!/usr/bin/env python 2 2 3 3 # Unix SMB/CIFS implementation. -
vendor/current/source4/librpc/rpc/dcerpc_auth.c
r414 r740 115 115 { 116 116 struct bind_auth_state *state; 117 struct dce rpc_security *sec;117 struct dcecli_security *sec; 118 118 struct composite_context *creq; 119 119 bool more_processing = false; … … 234 234 struct composite_context *c, *creq; 235 235 struct bind_auth_state *state; 236 struct dce rpc_security *sec;236 struct dcecli_security *sec; 237 237 238 238 struct ndr_syntax_id syntax, transfer_syntax; … … 293 293 } 294 294 295 if (p->binding && p->binding->target_principal) { 296 c->status = gensec_set_target_principal(sec->generic_state, 297 p->binding->target_principal); 298 if (!NT_STATUS_IS_OK(c->status)) { 299 DEBUG(1, ("Failed to set GENSEC target principal to %s: %s\n", 300 p->binding->target_principal, nt_errstr(c->status))); 301 composite_error(c, c->status); 302 return c; 303 } 304 } 305 295 306 c->status = gensec_start_mech_by_authtype(sec->generic_state, 296 307 auth_type, auth_level); -
vendor/current/source4/librpc/rpc/dcerpc_connect.c
r414 r740 112 112 remote rpc server */ 113 113 conn->in.dest_host = s->io.binding->host; 114 conn->in.dest_ports = lp _smb_ports(lp_ctx);114 conn->in.dest_ports = lpcfg_smb_ports(lp_ctx); 115 115 if (s->io.binding->target_hostname == NULL) 116 116 conn->in.called_name = "*SMBSERVER"; /* FIXME: This is invalid */ 117 117 else 118 118 conn->in.called_name = s->io.binding->target_hostname; 119 conn->in.socket_options = lp _socket_options(lp_ctx);119 conn->in.socket_options = lpcfg_socket_options(lp_ctx); 120 120 conn->in.service = "IPC$"; 121 121 conn->in.service_type = NULL; 122 conn->in.workgroup = lp_workgroup(lp_ctx); 123 conn->in.gensec_settings = lp_gensec_settings(conn, lp_ctx); 124 conn->in.iconv_convenience = lp_iconv_convenience(lp_ctx); 125 126 lp_smbcli_options(lp_ctx, &conn->in.options); 127 lp_smbcli_session_options(lp_ctx, &conn->in.session_options); 122 conn->in.workgroup = lpcfg_workgroup(lp_ctx); 123 conn->in.gensec_settings = lpcfg_gensec_settings(conn, lp_ctx); 124 125 lpcfg_smbcli_options(lp_ctx, &conn->in.options); 126 lpcfg_smbcli_session_options(lp_ctx, &conn->in.session_options); 128 127 129 128 /* … … 246 245 } 247 246 248 lp _smbcli_options(lp_ctx, &options);247 lpcfg_smbcli_options(lp_ctx, &options); 249 248 250 249 /* send smb2 connect request */ 251 250 conn_req = smb2_connect_send(mem_ctx, s->io.binding->host, 252 lp _parm_string_list(mem_ctx, lp_ctx, NULL, "smb2", "ports", NULL),251 lpcfg_parm_string_list(mem_ctx, lp_ctx, NULL, "smb2", "ports", NULL), 253 252 "IPC$", 254 253 s->io.resolve_ctx, … … 256 255 c->event_ctx, 257 256 &options, 258 lp _socket_options(lp_ctx),259 lp _gensec_settings(mem_ctx, lp_ctx)257 lpcfg_socket_options(lp_ctx), 258 lpcfg_gensec_settings(mem_ctx, lp_ctx) 260 259 ); 261 260 composite_continue(c, conn_req, continue_smb2_connect, c); … … 278 277 struct pipe_ip_tcp_state { 279 278 struct dcerpc_pipe_connect io; 279 const char *localaddr; 280 280 const char *host; 281 281 const char *target_hostname; … … 321 321 /* store input parameters in state structure */ 322 322 s->io = *io; 323 s->localaddr = talloc_reference(c, io->binding->localaddress); 323 324 s->host = talloc_reference(c, io->binding->host); 324 325 s->target_hostname = talloc_reference(c, io->binding->target_hostname); … … 327 328 328 329 /* send pipe open request on tcp/ip */ 329 pipe_req = dcerpc_pipe_open_tcp_send(s->io.pipe->conn, s-> host, s->target_hostname,330 pipe_req = dcerpc_pipe_open_tcp_send(s->io.pipe->conn, s->localaddr, s->host, s->target_hostname, 330 331 s->port, io->resolve_ctx); 331 332 composite_continue(c, pipe_req, continue_pipe_open_ncacn_ip_tcp, c); … … 464 465 465 466 /* send pipe open request */ 466 pipe_req = dcerpc_pipe_open_pipe_send(s->io.pipe->conn, lp _ncalrpc_dir(lp_ctx),467 pipe_req = dcerpc_pipe_open_pipe_send(s->io.pipe->conn, lpcfg_ncalrpc_dir(lp_ctx), 467 468 s->io.binding->endpoint); 468 469 composite_continue(c, pipe_req, continue_pipe_open_ncalrpc, c); … … 516 517 if (!composite_is_ok(c)) return; 517 518 518 DEBUG( 2,("Mapped to DCERPC endpoint %s\n", s->binding->endpoint));519 DEBUG(4,("Mapped to DCERPC endpoint %s\n", s->binding->endpoint)); 519 520 520 521 continue_connect(c, s); … … 539 540 pc.pipe = s->pipe; 540 541 pc.binding = s->binding; 542 pc.pipe_name = NULL; 541 543 pc.interface = s->table; 542 544 pc.creds = s->credentials; 543 pc.resolve_ctx = lp _resolve_context(s->lp_ctx);545 pc.resolve_ctx = lpcfg_resolve_context(s->lp_ctx); 544 546 545 547 /* connect dcerpc pipe depending on required transport */ … … 744 746 745 747 /* initialise dcerpc pipe structure */ 746 s->pipe = dcerpc_pipe_init(c, ev , lp_iconv_convenience(lp_ctx));748 s->pipe = dcerpc_pipe_init(c, ev); 747 749 if (composite_nomem(s->pipe, c)) return c; 748 750 749 751 if (DEBUGLEVEL >= 10) 750 s->pipe->conn->packet_log_dir = lp _lockdir(lp_ctx);752 s->pipe->conn->packet_log_dir = lpcfg_lockdir(lp_ctx); 751 753 752 754 /* store parameters in state structure */ -
vendor/current/source4/librpc/rpc/dcerpc_schannel.c
r414 r740 23 23 24 24 #include "includes.h" 25 #include <tevent.h> 25 26 #include "auth/auth.h" 26 27 #include "libcli/composite/composite.h" … … 50 51 static void continue_secondary_connection(struct composite_context *ctx); 51 52 static void continue_bind_auth_none(struct composite_context *ctx); 52 static void continue_srv_challenge(struct rpc_request *req);53 static void continue_srv_auth2(struct rpc_request *req);53 static void continue_srv_challenge(struct tevent_req *subreq); 54 static void continue_srv_auth2(struct tevent_req *subreq); 54 55 55 56 … … 120 121 struct composite_context *c; 121 122 struct schannel_key_state *s; 122 struct rpc_request *srv_challenge_req;123 struct tevent_req *subreq; 123 124 124 125 c = talloc_get_type(ctx->async.private_data, struct composite_context); … … 141 142 request a netlogon challenge - a rpc request over opened secondary pipe 142 143 */ 143 srv_challenge_req = dcerpc_netr_ServerReqChallenge_send(s->pipe2, c, &s->r); 144 if (composite_nomem(srv_challenge_req, c)) return; 145 146 composite_continue_rpc(c, srv_challenge_req, continue_srv_challenge, c); 144 subreq = dcerpc_netr_ServerReqChallenge_r_send(s, c->event_ctx, 145 s->pipe2->binding_handle, 146 &s->r); 147 if (composite_nomem(subreq, c)) return; 148 149 tevent_req_set_callback(subreq, continue_srv_challenge, c); 147 150 } 148 151 … … 152 155 on the netlogon pipe 153 156 */ 154 static void continue_srv_challenge(struct rpc_request *req) 155 { 156 struct composite_context *c; 157 struct schannel_key_state *s; 158 struct rpc_request *srv_auth2_req; 159 160 c = talloc_get_type(req->async.private_data, struct composite_context); 157 static void continue_srv_challenge(struct tevent_req *subreq) 158 { 159 struct composite_context *c; 160 struct schannel_key_state *s; 161 162 c = tevent_req_callback_data(subreq, struct composite_context); 161 163 s = talloc_get_type(c->private_data, struct schannel_key_state); 162 164 163 165 /* receive rpc request result - netlogon challenge */ 164 c->status = dcerpc_ndr_request_recv(req); 166 c->status = dcerpc_netr_ServerReqChallenge_r_recv(subreq, s); 167 TALLOC_FREE(subreq); 165 168 if (!composite_is_ok(c)) return; 166 169 … … 190 193 authenticate on the netlogon pipe - a rpc request over secondary pipe 191 194 */ 192 srv_auth2_req = dcerpc_netr_ServerAuthenticate2_send(s->pipe2, c, &s->a); 193 if (composite_nomem(srv_auth2_req, c)) return; 194 195 composite_continue_rpc(c, srv_auth2_req, continue_srv_auth2, c); 195 subreq = dcerpc_netr_ServerAuthenticate2_r_send(s, c->event_ctx, 196 s->pipe2->binding_handle, 197 &s->a); 198 if (composite_nomem(subreq, c)) return; 199 200 tevent_req_set_callback(subreq, continue_srv_auth2, c); 196 201 } 197 202 … … 201 206 received credentials 202 207 */ 203 static void continue_srv_auth2(struct rpc_request *req)204 { 205 struct composite_context *c; 206 struct schannel_key_state *s; 207 208 c = t alloc_get_type(req->async.private_data, struct composite_context);208 static void continue_srv_auth2(struct tevent_req *subreq) 209 { 210 struct composite_context *c; 211 struct schannel_key_state *s; 212 213 c = tevent_req_callback_data(subreq, struct composite_context); 209 214 s = talloc_get_type(c->private_data, struct schannel_key_state); 210 215 211 216 /* receive rpc request result - auth2 credentials */ 212 c->status = dcerpc_ndr_request_recv(req); 217 c->status = dcerpc_netr_ServerAuthenticate2_r_recv(subreq, s); 218 TALLOC_FREE(subreq); 213 219 if (!composite_is_ok(c)) return; 214 220 … … 238 244 struct schannel_key_state *s; 239 245 struct composite_context *epm_map_req; 246 enum netr_SchannelType schannel_type = cli_credentials_get_secure_channel_type(credentials); 240 247 241 248 /* composite context allocation and setup */ … … 253 260 /* allocate credentials */ 254 261 /* type of authentication depends on schannel type */ 255 if (s->pipe->conn->flags & DCERPC_SCHANNEL_128) { 262 if (schannel_type == SEC_CHAN_RODC) { 263 s->negotiate_flags = NETLOGON_NEG_AUTH2_RODC_FLAGS; 264 } else if (s->pipe->conn->flags & DCERPC_SCHANNEL_128) { 256 265 s->negotiate_flags = NETLOGON_NEG_AUTH2_ADS_FLAGS; 257 266 } else { … … 260 269 261 270 /* allocate binding structure */ 262 s->binding = talloc (c, struct dcerpc_binding);271 s->binding = talloc_zero(c, struct dcerpc_binding); 263 272 if (composite_nomem(s->binding, c)) return c; 264 273 … … 312 321 struct auth_schannel_state *s = talloc_get_type(c->private_data, 313 322 struct auth_schannel_state); 323 NTSTATUS status; 314 324 315 325 /* receive schannel key */ 316 c->status = dcerpc_schannel_key_recv(ctx);326 status = c->status = dcerpc_schannel_key_recv(ctx); 317 327 if (!composite_is_ok(c)) { 318 DEBUG(1, ("Failed to setup credentials for account %s: %s\n", 319 cli_credentials_get_username(s->credentials), nt_errstr(c->status))); 328 DEBUG(1, ("Failed to setup credentials: %s\n", nt_errstr(status))); 320 329 return; 321 330 } … … 323 332 /* send bind auth request with received creds */ 324 333 auth_req = dcerpc_bind_auth_send(c, s->pipe, s->table, s->credentials, 325 lp _gensec_settings(c, s->lp_ctx),334 lpcfg_gensec_settings(c, s->lp_ctx), 326 335 DCERPC_AUTH_TYPE_SCHANNEL, s->auth_level, 327 336 NULL); -
vendor/current/source4/librpc/rpc/dcerpc_secondary.c
r414 r740 74 74 75 75 /* initialise second dcerpc pipe based on primary pipe's event context */ 76 s->pipe2 = dcerpc_pipe_init(c, s->pipe->conn->event_ctx , s->pipe->conn->iconv_convenience);76 s->pipe2 = dcerpc_pipe_init(c, s->pipe->conn->event_ctx); 77 77 if (composite_nomem(s->pipe2, c)) return c; 78 78 … … 103 103 104 104 pipe_tcp_req = dcerpc_pipe_open_tcp_send(s->pipe2->conn, 105 s->binding->localaddress, 105 106 s->peer_addr->addr, 106 107 s->binding->target_hostname, -
vendor/current/source4/librpc/rpc/dcerpc_smb.c
r414 r740 26 26 #include "librpc/rpc/dcerpc.h" 27 27 #include "librpc/rpc/dcerpc_proto.h" 28 #include "librpc/rpc/rpc_common.h" 28 29 29 30 /* transport private information used by SMB pipe transport */ … … 39 40 tell the dcerpc layer that the transport is dead 40 41 */ 41 static void pipe_dead(struct dce rpc_connection *c, NTSTATUS status)42 static void pipe_dead(struct dcecli_connection *c, NTSTATUS status) 42 43 { 43 44 struct smb_private *smb = (struct smb_private *)c->transport.private_data; … … 67 68 */ 68 69 struct smb_read_state { 69 struct dce rpc_connection *c;70 struct dcecli_connection *c; 70 71 struct smbcli_request *req; 71 72 size_t received; … … 110 111 if (frag_length <= state->received) { 111 112 DATA_BLOB data = state->data; 112 struct dce rpc_connection *c = state->c;113 struct dcecli_connection *c = state->c; 113 114 data.length = state->received; 114 115 talloc_steal(state->c, data.data); … … 141 142 data in the read buffer 142 143 */ 143 static NTSTATUS send_read_request_continue(struct dce rpc_connection *c, DATA_BLOB *blob)144 static NTSTATUS send_read_request_continue(struct dcecli_connection *c, DATA_BLOB *blob) 144 145 { 145 146 struct smb_private *smb = (struct smb_private *)c->transport.private_data; … … 197 198 trigger a read request from the server 198 199 */ 199 static NTSTATUS send_read_request(struct dce rpc_connection *c)200 static NTSTATUS send_read_request(struct dcecli_connection *c) 200 201 { 201 202 struct smb_private *smb = (struct smb_private *)c->transport.private_data; … … 212 213 */ 213 214 struct smb_trans_state { 214 struct dce rpc_connection *c;215 struct dcecli_connection *c; 215 216 struct smbcli_request *req; 216 217 struct smb_trans2 *trans; … … 223 224 { 224 225 struct smb_trans_state *state = (struct smb_trans_state *)req->async.private_data; 225 struct dce rpc_connection *c = state->c;226 struct dcecli_connection *c = state->c; 226 227 NTSTATUS status; 227 228 … … 249 250 send a SMBtrans style request 250 251 */ 251 static NTSTATUS smb_send_trans_request(struct dce rpc_connection *c, DATA_BLOB *blob)252 static NTSTATUS smb_send_trans_request(struct dcecli_connection *c, DATA_BLOB *blob) 252 253 { 253 254 struct smb_private *smb = (struct smb_private *)c->transport.private_data; … … 306 307 static void smb_write_callback(struct smbcli_request *req) 307 308 { 308 struct dce rpc_connection *c = (struct dcerpc_connection *)req->async.private_data;309 struct dcecli_connection *c = (struct dcecli_connection *)req->async.private_data; 309 310 310 311 if (!NT_STATUS_IS_OK(req->status)) { … … 319 320 send a packet to the server 320 321 */ 321 static NTSTATUS smb_send_request(struct dce rpc_connection *c, DATA_BLOB *blob,322 static NTSTATUS smb_send_request(struct dcecli_connection *c, DATA_BLOB *blob, 322 323 bool trigger_read) 323 324 { … … 370 371 shutdown SMB pipe connection 371 372 */ 372 static NTSTATUS smb_shutdown_pipe(struct dce rpc_connection *c, NTSTATUS status)373 static NTSTATUS smb_shutdown_pipe(struct dcecli_connection *c, NTSTATUS status) 373 374 { 374 375 struct smb_private *smb = (struct smb_private *)c->transport.private_data; … … 397 398 return SMB server name (called name) 398 399 */ 399 static const char *smb_peer_name(struct dce rpc_connection *c)400 static const char *smb_peer_name(struct dcecli_connection *c) 400 401 { 401 402 struct smb_private *smb = (struct smb_private *)c->transport.private_data; … … 407 408 return remote name we make the actual connection (good for kerberos) 408 409 */ 409 static const char *smb_target_hostname(struct dce rpc_connection *c)410 static const char *smb_target_hostname(struct dcecli_connection *c) 410 411 { 411 412 struct smb_private *smb = talloc_get_type(c->transport.private_data, struct smb_private); … … 417 418 fetch the user session key 418 419 */ 419 static NTSTATUS smb_session_key(struct dce rpc_connection *c, DATA_BLOB *session_key)420 static NTSTATUS smb_session_key(struct dcecli_connection *c, DATA_BLOB *session_key) 420 421 { 421 422 struct smb_private *smb = (struct smb_private *)c->transport.private_data; … … 431 432 struct pipe_open_smb_state { 432 433 union smb_open *open; 433 struct dce rpc_connection *c;434 struct dcecli_connection *c; 434 435 struct smbcli_tree *tree; 435 436 struct composite_context *ctx; … … 445 446 struct pipe_open_smb_state *state; 446 447 struct smbcli_request *req; 447 struct dce rpc_connection *c = p->conn;448 struct dcecli_connection *c = p->conn; 448 449 449 450 /* if we don't have a binding on this pipe yet, then create one */ … … 477 478 state->open->ntcreatex.level = RAW_OPEN_NTCREATEX; 478 479 state->open->ntcreatex.in.flags = 0; 479 state->open->ntcreatex.in.root_fid = 0;480 state->open->ntcreatex.in.root_fid.fnum = 0; 480 481 state->open->ntcreatex.in.access_mask = 481 482 SEC_STD_READ_CONTROL | … … 515 516 struct pipe_open_smb_state); 516 517 struct composite_context *ctx = state->ctx; 517 struct dce rpc_connection *c = state->c;518 struct dcecli_connection *c = state->c; 518 519 struct smb_private *smb; 519 520 … … 571 572 return the SMB tree used for a dcerpc over SMB pipe 572 573 */ 573 _PUBLIC_ struct smbcli_tree *dcerpc_smb_tree(struct dce rpc_connection *c)574 _PUBLIC_ struct smbcli_tree *dcerpc_smb_tree(struct dcecli_connection *c) 574 575 { 575 576 struct smb_private *smb; … … 586 587 return the SMB fnum used for a dcerpc over SMB pipe (hack for torture operations) 587 588 */ 588 _PUBLIC_ uint16_t dcerpc_smb_fnum(struct dce rpc_connection *c)589 _PUBLIC_ uint16_t dcerpc_smb_fnum(struct dcecli_connection *c) 589 590 { 590 591 struct smb_private *smb; -
vendor/current/source4/librpc/rpc/dcerpc_smb2.c
r414 r740 28 28 #include "librpc/rpc/dcerpc.h" 29 29 #include "librpc/rpc/dcerpc_proto.h" 30 #include "librpc/rpc/rpc_common.h" 30 31 31 32 /* transport private information used by SMB2 pipe transport */ … … 41 42 tell the dcerpc layer that the transport is dead 42 43 */ 43 static void pipe_dead(struct dce rpc_connection *c, NTSTATUS status)44 static void pipe_dead(struct dcecli_connection *c, NTSTATUS status) 44 45 { 45 46 struct smb2_private *smb = (struct smb2_private *)c->transport.private_data; … … 69 70 */ 70 71 struct smb2_read_state { 71 struct dce rpc_connection *c;72 struct dcecli_connection *c; 72 73 DATA_BLOB data; 73 74 }; … … 113 114 if (frag_length <= state->data.length) { 114 115 DATA_BLOB data = state->data; 115 struct dce rpc_connection *c = state->c;116 struct dcecli_connection *c = state->c; 116 117 talloc_steal(c, data.data); 117 118 talloc_free(state); … … 145 146 data in the read buffer 146 147 */ 147 static NTSTATUS send_read_request_continue(struct dce rpc_connection *c, DATA_BLOB *blob)148 static NTSTATUS send_read_request_continue(struct dcecli_connection *c, DATA_BLOB *blob) 148 149 { 149 150 struct smb2_private *smb = (struct smb2_private *)c->transport.private_data; … … 190 191 trigger a read request from the server 191 192 */ 192 static NTSTATUS send_read_request(struct dce rpc_connection *c)193 static NTSTATUS send_read_request(struct dcecli_connection *c) 193 194 { 194 195 struct smb2_private *smb = (struct smb2_private *)c->transport.private_data; … … 205 206 */ 206 207 struct smb2_trans_state { 207 struct dce rpc_connection *c;208 struct dcecli_connection *c; 208 209 }; 209 210 … … 215 216 struct smb2_trans_state *state = talloc_get_type(req->async.private_data, 216 217 struct smb2_trans_state); 217 struct dce rpc_connection *c = state->c;218 struct dcecli_connection *c = state->c; 218 219 NTSTATUS status; 219 220 struct smb2_ioctl io; … … 241 242 send a SMBtrans style request, using a named pipe read_write fsctl 242 243 */ 243 static NTSTATUS smb2_send_trans_request(struct dce rpc_connection *c, DATA_BLOB *blob)244 static NTSTATUS smb2_send_trans_request(struct dcecli_connection *c, DATA_BLOB *blob) 244 245 { 245 246 struct smb2_private *smb = talloc_get_type(c->transport.private_data, … … 282 283 static void smb2_write_callback(struct smb2_request *req) 283 284 { 284 struct dce rpc_connection *c = (struct dcerpc_connection *)req->async.private_data;285 struct dcecli_connection *c = (struct dcecli_connection *)req->async.private_data; 285 286 286 287 if (!NT_STATUS_IS_OK(req->status)) { … … 295 296 send a packet to the server 296 297 */ 297 static NTSTATUS smb2_send_request(struct dce rpc_connection *c, DATA_BLOB *blob,298 static NTSTATUS smb2_send_request(struct dcecli_connection *c, DATA_BLOB *blob, 298 299 bool trigger_read) 299 300 { … … 333 334 shutdown SMB pipe connection 334 335 */ 335 static NTSTATUS smb2_shutdown_pipe(struct dce rpc_connection *c, NTSTATUS status)336 static NTSTATUS smb2_shutdown_pipe(struct dcecli_connection *c, NTSTATUS status) 336 337 { 337 338 struct smb2_private *smb = (struct smb2_private *)c->transport.private_data; … … 358 359 return SMB server name 359 360 */ 360 static const char *smb2_peer_name(struct dce rpc_connection *c)361 static const char *smb2_peer_name(struct dcecli_connection *c) 361 362 { 362 363 struct smb2_private *smb = talloc_get_type(c->transport.private_data, … … 368 369 return remote name we make the actual connection (good for kerberos) 369 370 */ 370 static const char *smb2_target_hostname(struct dce rpc_connection *c)371 static const char *smb2_target_hostname(struct dcecli_connection *c) 371 372 { 372 373 struct smb2_private *smb = talloc_get_type(c->transport.private_data, … … 378 379 fetch the user session key 379 380 */ 380 static NTSTATUS smb2_session_key(struct dce rpc_connection *c, DATA_BLOB *session_key)381 static NTSTATUS smb2_session_key(struct dcecli_connection *c, DATA_BLOB *session_key) 381 382 { 382 383 struct smb2_private *smb = talloc_get_type(c->transport.private_data, … … 390 391 391 392 struct pipe_open_smb2_state { 392 struct dce rpc_connection *c;393 struct dcecli_connection *c; 393 394 struct composite_context *ctx; 394 395 }; … … 404 405 struct smb2_create io; 405 406 struct smb2_request *req; 406 struct dce rpc_connection *c = p->conn;407 struct dcecli_connection *c = p->conn; 407 408 408 409 ctx = composite_create(c, c->event_ctx); … … 453 454 struct pipe_open_smb2_state); 454 455 struct composite_context *ctx = state->ctx; 455 struct dce rpc_connection *c = state->c;456 struct dcecli_connection *c = state->c; 456 457 struct smb2_tree *tree = req->tree; 457 458 struct smb2_private *smb; … … 510 511 return the SMB2 tree used for a dcerpc over SMB2 pipe 511 512 */ 512 struct smb2_tree *dcerpc_smb2_tree(struct dce rpc_connection *c)513 struct smb2_tree *dcerpc_smb2_tree(struct dcecli_connection *c) 513 514 { 514 515 struct smb2_private *smb = talloc_get_type(c->transport.private_data, -
vendor/current/source4/librpc/rpc/dcerpc_sock.c
r414 r740 30 30 #include "librpc/rpc/dcerpc_proto.h" 31 31 #include "libcli/resolve/resolve.h" 32 #include "librpc/rpc/rpc_common.h" 32 33 33 34 /* transport private information used by general socket pipe transports */ … … 47 48 mark the socket dead 48 49 */ 49 static void sock_dead(struct dce rpc_connection *p, NTSTATUS status)50 static void sock_dead(struct dcecli_connection *p, NTSTATUS status) 50 51 { 51 52 struct sock_private *sock = (struct sock_private *)p->transport.private_data; … … 88 89 static void sock_error_handler(void *private_data, NTSTATUS status) 89 90 { 90 struct dce rpc_connection *p = talloc_get_type(private_data,91 struct dce rpc_connection);91 struct dcecli_connection *p = talloc_get_type(private_data, 92 struct dcecli_connection); 92 93 sock_dead(p, status); 93 94 } … … 113 114 static NTSTATUS sock_process_recv(void *private_data, DATA_BLOB blob) 114 115 { 115 struct dce rpc_connection *p = talloc_get_type(private_data,116 struct dce rpc_connection);116 struct dcecli_connection *p = talloc_get_type(private_data, 117 struct dcecli_connection); 117 118 struct sock_private *sock = (struct sock_private *)p->transport.private_data; 118 119 sock->pending_reads--; … … 130 131 uint16_t flags, void *private_data) 131 132 { 132 struct dce rpc_connection *p = talloc_get_type(private_data,133 struct dce rpc_connection);133 struct dcecli_connection *p = talloc_get_type(private_data, 134 struct dcecli_connection); 134 135 struct sock_private *sock = (struct sock_private *)p->transport.private_data; 135 136 … … 151 152 initiate a read request - not needed for dcerpc sockets 152 153 */ 153 static NTSTATUS sock_send_read(struct dce rpc_connection *p)154 static NTSTATUS sock_send_read(struct dcecli_connection *p) 154 155 { 155 156 struct sock_private *sock = (struct sock_private *)p->transport.private_data; … … 164 165 send an initial pdu in a multi-pdu sequence 165 166 */ 166 static NTSTATUS sock_send_request(struct dce rpc_connection *p, DATA_BLOB *data,167 static NTSTATUS sock_send_request(struct dcecli_connection *p, DATA_BLOB *data, 167 168 bool trigger_read) 168 169 { … … 195 196 shutdown sock pipe connection 196 197 */ 197 static NTSTATUS sock_shutdown_pipe(struct dce rpc_connection *p, NTSTATUS status)198 static NTSTATUS sock_shutdown_pipe(struct dcecli_connection *p, NTSTATUS status) 198 199 { 199 200 struct sock_private *sock = (struct sock_private *)p->transport.private_data; … … 209 210 return sock server name 210 211 */ 211 static const char *sock_peer_name(struct dce rpc_connection *p)212 static const char *sock_peer_name(struct dcecli_connection *p) 212 213 { 213 214 struct sock_private *sock = talloc_get_type(p->transport.private_data, struct sock_private); … … 218 219 return remote name we make the actual connection (good for kerberos) 219 220 */ 220 static const char *sock_target_hostname(struct dce rpc_connection *p)221 static const char *sock_target_hostname(struct dcecli_connection *p) 221 222 { 222 223 struct sock_private *sock = talloc_get_type(p->transport.private_data, struct sock_private); … … 226 227 227 228 struct pipe_open_socket_state { 228 struct dce rpc_connection *conn;229 struct dcecli_connection *conn; 229 230 struct socket_context *socket_ctx; 230 231 struct sock_private *sock; 232 struct socket_address *localaddr; 231 233 struct socket_address *server; 232 234 const char *target_hostname; … … 237 239 static void continue_socket_connect(struct composite_context *ctx) 238 240 { 239 struct dce rpc_connection *conn;241 struct dcecli_connection *conn; 240 242 struct sock_private *sock; 241 243 struct composite_context *c = talloc_get_type(ctx->async.private_data, … … 305 307 306 308 static struct composite_context *dcerpc_pipe_open_socket_send(TALLOC_CTX *mem_ctx, 307 struct dcerpc_connection *cn, 309 struct dcecli_connection *cn, 310 struct socket_address *localaddr, 308 311 struct socket_address *server, 309 312 const char *target_hostname, … … 324 327 s->conn = cn; 325 328 s->transport = transport; 329 if (localaddr) { 330 s->localaddr = talloc_reference(c, localaddr); 331 if (composite_nomem(s->localaddr, c)) return c; 332 } 326 333 s->server = talloc_reference(c, server); 327 334 if (composite_nomem(s->server, c)) return c; … … 338 345 s->sock->path = talloc_reference(s->sock, full_path); 339 346 340 conn_req = socket_connect_send(s->socket_ctx, NULL, s->server, 0,347 conn_req = socket_connect_send(s->socket_ctx, s->localaddr, s->server, 0, 341 348 c->event_ctx); 342 349 composite_continue(c, conn_req, continue_socket_connect, c); … … 358 365 const char *address; 359 366 uint32_t port; 367 struct socket_address *localaddr; 360 368 struct socket_address *srvaddr; 361 369 struct resolve_context *resolve_ctx; 362 struct dce rpc_connection *conn;370 struct dcecli_connection *conn; 363 371 }; 364 372 … … 386 394 387 395 /* resolve_nbt_name gives only ipv4 ... - send socket open request */ 388 sock_ipv4_req = dcerpc_pipe_open_socket_send(c, s->conn, 396 sock_ipv4_req = dcerpc_pipe_open_socket_send(c, s->conn, s->localaddr, 389 397 s->srvaddr, s->target_hostname, 390 398 NULL, … … 420 428 421 429 /* try IPv4 if IPv6 fails */ 422 sock_ipv4_req = dcerpc_pipe_open_socket_send(c, s->conn, 430 sock_ipv4_req = dcerpc_pipe_open_socket_send(c, s->conn, s->localaddr, 423 431 s->srvaddr, s->target_hostname, 424 432 NCACN_IP_TCP); … … 453 461 } 454 462 455 456 463 /* 457 464 Send rpc pipe open request to given host:port using 458 465 tcp/ip transport 459 466 */ 460 struct composite_context* dcerpc_pipe_open_tcp_send(struct dcerpc_connection *conn, 467 struct composite_context* dcerpc_pipe_open_tcp_send(struct dcecli_connection *conn, 468 const char *localaddr, 461 469 const char *server, 462 470 const char *target_hostname, … … 487 495 s->conn = conn; 488 496 s->resolve_ctx = resolve_ctx; 497 if (localaddr) { 498 s->localaddr = socket_address_from_strings(s, "ip", localaddr, 0); 499 /* if there is no localaddr, we pass NULL for 500 s->localaddr, which is handled by the socket libraries as 501 meaning no local binding address specified */ 502 } 489 503 490 504 make_nbt_name_server(&name, server); … … 510 524 const char *path; 511 525 struct socket_address *srvaddr; 512 struct dce rpc_connection *conn;526 struct dcecli_connection *conn; 513 527 }; 514 528 … … 536 550 Send pipe open request on unix socket 537 551 */ 538 struct composite_context *dcerpc_pipe_open_unix_stream_send(struct dce rpc_connection *conn,552 struct composite_context *dcerpc_pipe_open_unix_stream_send(struct dcecli_connection *conn, 539 553 const char *path) 540 554 { … … 561 575 562 576 /* send socket open request */ 563 sock_unix_req = dcerpc_pipe_open_socket_send(c, s->conn, 577 sock_unix_req = dcerpc_pipe_open_socket_send(c, s->conn, NULL, 564 578 s->srvaddr, NULL, 565 579 s->path, … … 600 614 Send pipe open request on ncalrpc 601 615 */ 602 struct composite_context* dcerpc_pipe_open_pipe_send(struct dce rpc_connection *conn,616 struct composite_context* dcerpc_pipe_open_pipe_send(struct dcecli_connection *conn, 603 617 const char *ncalrpc_dir, 604 618 const char *identifier) … … 632 646 633 647 /* send socket open request */ 634 sock_np_req = dcerpc_pipe_open_socket_send(c, s->conn, s->srvaddr, NULL, s->path, NCALRPC);648 sock_np_req = dcerpc_pipe_open_socket_send(c, s->conn, NULL, s->srvaddr, NULL, s->path, NCALRPC); 635 649 composite_continue(c, sock_np_req, continue_np_open_socket, c); 636 650 return c; … … 653 667 Open a rpc pipe on a named pipe - sync version 654 668 */ 655 NTSTATUS dcerpc_pipe_open_pipe(struct dce rpc_connection *conn, const char *ncalrpc_dir, const char *identifier)669 NTSTATUS dcerpc_pipe_open_pipe(struct dcecli_connection *conn, const char *ncalrpc_dir, const char *identifier) 656 670 { 657 671 struct composite_context *c = dcerpc_pipe_open_pipe_send(conn, ncalrpc_dir, identifier); … … 659 673 } 660 674 661 const char *dcerpc_unix_socket_path(struct dce rpc_connection *p)675 const char *dcerpc_unix_socket_path(struct dcecli_connection *p) 662 676 { 663 677 struct sock_private *sock = (struct sock_private *)p->transport.private_data; … … 665 679 } 666 680 667 struct socket_address *dcerpc_socket_peer_addr(struct dce rpc_connection *p, TALLOC_CTX *mem_ctx)681 struct socket_address *dcerpc_socket_peer_addr(struct dcecli_connection *p, TALLOC_CTX *mem_ctx) 668 682 { 669 683 struct sock_private *sock = (struct sock_private *)p->transport.private_data; -
vendor/current/source4/librpc/rpc/dcerpc_util.c
r414 r740 32 32 #include "auth/credentials/credentials.h" 33 33 #include "param/param.h" 34 #include "librpc/rpc/rpc_common.h" 34 35 35 36 /* … … 52 53 */ 53 54 NTSTATUS ncacn_push_auth(DATA_BLOB *blob, TALLOC_CTX *mem_ctx, 54 struct smb_iconv_convenience *iconv_convenience, 55 struct ncacn_packet *pkt, 56 struct dcerpc_auth *auth_info) 55 struct ncacn_packet *pkt, 56 struct dcerpc_auth *auth_info) 57 57 { 58 58 struct ndr_push *ndr; 59 59 enum ndr_err_code ndr_err; 60 60 61 ndr = ndr_push_init_ctx(mem_ctx , iconv_convenience);61 ndr = ndr_push_init_ctx(mem_ctx); 62 62 if (!ndr) { 63 63 return NT_STATUS_NO_MEMORY; … … 84 84 85 85 if (auth_info) { 86 #if 0 87 /* the s3 rpc server doesn't handle auth padding in 88 bind requests. Use zero auth padding to keep us 89 working with old servers */ 90 uint32_t offset = ndr->offset; 91 ndr_err = ndr_push_align(ndr, 16); 92 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) { 93 return ndr_map_error2ntstatus(ndr_err); 94 } 95 auth_info->auth_pad_length = ndr->offset - offset; 96 #else 97 auth_info->auth_pad_length = 0; 98 #endif 86 99 ndr_err = ndr_push_dcerpc_auth(ndr, NDR_SCALARS|NDR_BUFFERS, auth_info); 87 100 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) { … … 107 120 struct epm_twr_t twr; 108 121 struct epm_twr_t *twr_r; 122 uint32_t num_towers; 109 123 struct epm_Map r; 110 124 }; … … 112 126 113 127 static void continue_epm_recv_binding(struct composite_context *ctx); 114 static void continue_epm_map(struct rpc_request *req);128 static void continue_epm_map(struct tevent_req *subreq); 115 129 116 130 … … 121 135 static void continue_epm_recv_binding(struct composite_context *ctx) 122 136 { 123 struct rpc_request *map_req;124 125 137 struct composite_context *c = talloc_get_type(ctx->async.private_data, 126 138 struct composite_context); 127 139 struct epm_map_binding_state *s = talloc_get_type(c->private_data, 128 140 struct epm_map_binding_state); 141 struct tevent_req *subreq; 129 142 130 143 /* receive result of rpc pipe connect request */ 131 144 c->status = dcerpc_pipe_connect_b_recv(ctx, c, &s->pipe); 132 145 if (!composite_is_ok(c)) return; 133 134 s->pipe->conn->flags |= DCERPC_NDR_REF_ALLOC;135 146 136 147 /* prepare requested binding parameters */ … … 146 157 s->r.in.max_towers = 1; 147 158 s->r.out.entry_handle = &s->handle; 159 s->r.out.num_towers = &s->num_towers; 148 160 149 161 /* send request for an endpoint mapping - a rpc request on connected pipe */ 150 map_req = dcerpc_epm_Map_send(s->pipe, c, &s->r); 151 if (composite_nomem(map_req, c)) return; 152 153 composite_continue_rpc(c, map_req, continue_epm_map, c); 162 subreq = dcerpc_epm_Map_r_send(s, c->event_ctx, 163 s->pipe->binding_handle, 164 &s->r); 165 if (composite_nomem(subreq, c)) return; 166 167 tevent_req_set_callback(subreq, continue_epm_map, c); 154 168 } 155 169 … … 158 172 Stage 3 of epm_map_binding: Receive endpoint mapping and provide binding details 159 173 */ 160 static void continue_epm_map(struct rpc_request *req)161 { 162 struct composite_context *c = t alloc_get_type(req->async.private_data,163 174 static void continue_epm_map(struct tevent_req *subreq) 175 { 176 struct composite_context *c = tevent_req_callback_data(subreq, 177 struct composite_context); 164 178 struct epm_map_binding_state *s = talloc_get_type(c->private_data, 165 179 struct epm_map_binding_state); 166 180 167 181 /* receive result of a rpc request */ 168 c->status = dcerpc_ndr_request_recv(req); 182 c->status = dcerpc_epm_Map_r_recv(subreq, s); 183 TALLOC_FREE(subreq); 169 184 if (!composite_is_ok(c)) return; 170 185 … … 272 287 epmapper_binding->target_hostname = epmapper_binding->host; 273 288 epmapper_binding->options = NULL; 289 epmapper_binding->localaddress = talloc_reference(epmapper_binding, binding->localaddress); 274 290 epmapper_binding->flags = 0; 275 291 epmapper_binding->assoc_group_id = 0; … … 408 424 struct composite_context *auth_req; 409 425 struct dcerpc_pipe *p2; 426 void *pp; 410 427 411 428 c = talloc_get_type(ctx->async.private_data, struct composite_context); … … 416 433 if (!composite_is_ok(c)) return; 417 434 435 436 /* this is a rather strange situation. When 437 we come into the routine, s is a child of s->pipe, and 438 when we created p2 above, it also became a child of 439 s->pipe. 440 441 Now we want p2 to be a parent of s->pipe, and we want s to 442 be a parent of both of them! If we don't do this very 443 carefully we end up creating a talloc loop 444 */ 445 446 /* we need the new contexts to hang off the same context 447 that s->pipe is on, but the only way to get that is 448 via talloc_parent() */ 449 pp = talloc_parent(s->pipe); 450 451 /* promote s to be at the top */ 452 talloc_steal(pp, s); 453 454 /* and put p2 under s */ 418 455 talloc_steal(s, p2); 456 457 /* now put s->pipe under p2 */ 419 458 talloc_steal(p2, s->pipe); 459 420 460 s->pipe = p2; 421 461 … … 423 463 auth_req = dcerpc_bind_auth_send(c, s->pipe, s->table, 424 464 s->credentials, 425 lp _gensec_settings(c, s->lp_ctx),465 lpcfg_gensec_settings(c, s->lp_ctx), 426 466 DCERPC_AUTH_TYPE_NTLMSSP, 427 467 dcerpc_auth_level(s->pipe->conn), … … 456 496 auth_req = dcerpc_bind_auth_send(c, s->pipe, s->table, 457 497 s->credentials, 458 lp _gensec_settings(c, s->lp_ctx),498 lpcfg_gensec_settings(c, s->lp_ctx), 459 499 DCERPC_AUTH_TYPE_SPNEGO, 460 500 dcerpc_auth_level(s->pipe->conn), … … 494 534 struct composite_context *auth_req; 495 535 struct composite_context *auth_none_req; 496 struct dce rpc_connection *conn;536 struct dcecli_connection *conn; 497 537 uint8_t auth_type; 498 538 … … 581 621 auth_req = dcerpc_bind_auth_send(c, s->pipe, s->table, 582 622 s->credentials, 583 lp _gensec_settings(c, s->lp_ctx),623 lpcfg_gensec_settings(c, s->lp_ctx), 584 624 DCERPC_AUTH_TYPE_SPNEGO, 585 625 dcerpc_auth_level(conn), … … 591 631 auth_req = dcerpc_bind_auth_send(c, s->pipe, s->table, 592 632 s->credentials, 593 lp _gensec_settings(c, s->lp_ctx),633 lpcfg_gensec_settings(c, s->lp_ctx), 594 634 auth_type, 595 635 dcerpc_auth_level(conn), … … 648 688 649 689 650 NTSTATUS dcerpc_generic_session_key(struct dce rpc_connection *c,690 NTSTATUS dcerpc_generic_session_key(struct dcecli_connection *c, 651 691 DATA_BLOB *session_key) 652 692 { … … 684 724 */ 685 725 _PUBLIC_ void dcerpc_log_packet(const char *lockdir, 686 687 uint32_t opnum, uint32_t flags,688 726 const struct ndr_interface_table *ndr, 727 uint32_t opnum, uint32_t flags, 728 const DATA_BLOB *pkt) 689 729 { 690 730 const int num_examples = 20; … … 741 781 p2->binding = talloc_reference(p2, p->binding); 742 782 783 p2->binding_handle = dcerpc_pipe_binding_handle(p2); 784 if (p2->binding_handle == NULL) { 785 talloc_free(p2); 786 return NT_STATUS_NO_MEMORY; 787 } 788 743 789 status = dcerpc_alter_context(p2, p2, &p2->syntax, &p2->transfer_syntax); 744 790 if (!NT_STATUS_IS_OK(status)) { -
vendor/current/source4/librpc/rpc/pyrpc.c
r414 r740 3 3 Samba utility functions 4 4 Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2008 5 5 6 6 This program is free software; you can redistribute it and/or modify 7 7 it under the terms of the GNU General Public License as published by 8 8 the Free Software Foundation; either version 3 of the License, or 9 9 (at your option) any later version. 10 10 11 11 This program is distributed in the hope that it will be useful, 12 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 14 GNU General Public License for more details. 15 15 16 16 You should have received a copy of the GNU General Public License 17 17 along with this program. If not, see <http://www.gnu.org/licenses/>. 18 18 */ 19 19 20 #include <Python.h> 20 21 #include "includes.h" 21 #include <Python.h>22 22 #include <structmember.h> 23 23 #include "librpc/rpc/pyrpc.h" 24 #include "librpc/rpc/dcerpc.h"25 24 #include "lib/events/events.h" 26 25 #include "param/pyparam.h" 26 #include "librpc/rpc/dcerpc.h" 27 #include "librpc/rpc/pyrpc_util.h" 27 28 #include "auth/credentials/pycredentials.h" 28 29 29 #ifndef Py_RETURN_NONE 30 #define Py_RETURN_NONE return Py_INCREF(Py_None), Py_None 31 #endif 32 33 static PyObject *py_dcerpc_run_function(dcerpc_InterfaceObject *iface, 34 const struct PyNdrRpcMethodDef *md, 35 PyObject *args, PyObject *kwargs) 36 { 37 TALLOC_CTX *mem_ctx; 38 NTSTATUS status; 39 void *r; 40 PyObject *result = Py_None; 41 42 if (md->pack_in_data == NULL || md->unpack_out_data == NULL) { 43 PyErr_SetString(PyExc_NotImplementedError, "No marshalling code available yet"); 44 return NULL; 45 } 46 47 mem_ctx = talloc_new(NULL); 48 if (mem_ctx == NULL) { 49 PyErr_NoMemory(); 50 return NULL; 51 } 52 53 r = talloc_zero_size(mem_ctx, md->table->calls[md->opnum].struct_size); 54 if (r == NULL) { 55 PyErr_NoMemory(); 56 return NULL; 57 } 58 59 if (!md->pack_in_data(args, kwargs, r)) { 60 talloc_free(mem_ctx); 61 return NULL; 62 } 63 64 status = md->call(iface->pipe, mem_ctx, r); 65 if (NT_STATUS_IS_ERR(status)) { 66 PyErr_SetDCERPCStatus(iface->pipe, status); 67 talloc_free(mem_ctx); 68 return NULL; 69 } 70 71 result = md->unpack_out_data(r); 72 73 talloc_free(mem_ctx); 74 return result; 75 } 76 77 static PyObject *py_dcerpc_call_wrapper(PyObject *self, PyObject *args, void *wrapped, PyObject *kwargs) 78 { 79 dcerpc_InterfaceObject *iface = (dcerpc_InterfaceObject *)self; 80 const struct PyNdrRpcMethodDef *md = (const struct PyNdrRpcMethodDef *)wrapped; 81 82 return py_dcerpc_run_function(iface, md, args, kwargs); 83 } 84 85 86 bool PyInterface_AddNdrRpcMethods(PyTypeObject *ifacetype, const struct PyNdrRpcMethodDef *mds) 87 { 88 int i; 89 for (i = 0; mds[i].name; i++) { 90 PyObject *ret; 91 struct wrapperbase *wb = (struct wrapperbase *)calloc(sizeof(struct wrapperbase), 1); 92 93 wb->name = discard_const_p(char, mds[i].name); 94 wb->flags = PyWrapperFlag_KEYWORDS; 95 wb->wrapper = (wrapperfunc)py_dcerpc_call_wrapper; 96 wb->doc = discard_const_p(char, mds[i].doc); 97 98 ret = PyDescr_NewWrapper(ifacetype, wb, discard_const_p(void, &mds[i])); 99 100 PyDict_SetItemString(ifacetype->tp_dict, mds[i].name, 101 (PyObject *)ret); 102 } 103 104 return true; 105 } 30 void initbase(void); 31 32 staticforward PyTypeObject dcerpc_InterfaceType; 106 33 107 34 static bool PyString_AsGUID(PyObject *object, struct GUID *uuid) … … 147 74 PyErr_SetString(PyExc_TypeError, "Expected UUID or syntax id tuple"); 148 75 return false; 149 } 76 } 150 77 151 78 static PyObject *py_iface_server_name(PyObject *obj, void *closure) … … 153 80 const char *server_name; 154 81 dcerpc_InterfaceObject *iface = (dcerpc_InterfaceObject *)obj; 155 82 156 83 server_name = dcerpc_server_name(iface->pipe); 157 84 if (server_name == NULL) … … 207 134 { NULL } 208 135 }; 209 210 void PyErr_SetDCERPCStatus(struct dcerpc_pipe *p, NTSTATUS status)211 {212 if (p != NULL && NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {213 const char *errstr = dcerpc_errstr(NULL, p->last_fault_code);214 PyErr_SetObject(PyExc_RuntimeError,215 Py_BuildValue("(i,s)", p->last_fault_code,216 errstr));217 } else {218 PyErr_SetNTSTATUS(status);219 }220 }221 136 222 137 static PyObject *py_iface_request(PyObject *self, PyObject *args, PyObject *kwargs) … … 232 147 struct GUID object_guid; 233 148 TALLOC_CTX *mem_ctx = talloc_new(NULL); 149 uint32_t out_flags = 0; 234 150 const char *kwnames[] = { "opnum", "data", "object", NULL }; 235 151 236 152 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "is#|O:request", 237 153 discard_const_p(char *, kwnames), &opnum, &in_data, &in_length, &object)) { 154 talloc_free(mem_ctx); 238 155 return NULL; 239 156 } … … 245 162 246 163 if (object != NULL && !PyString_AsGUID(object, &object_guid)) { 247 return NULL; 248 } 249 250 status = dcerpc_request(iface->pipe, object?&object_guid:NULL, 251 opnum, mem_ctx, &data_in, &data_out); 252 253 if (NT_STATUS_IS_ERR(status)) { 164 talloc_free(mem_ctx); 165 return NULL; 166 } 167 168 status = dcerpc_binding_handle_raw_call(iface->binding_handle, 169 object?&object_guid:NULL, 170 opnum, 171 0, /* in_flags */ 172 data_in.data, 173 data_in.length, 174 mem_ctx, 175 &data_out.data, 176 &data_out.length, 177 &out_flags); 178 if (!NT_STATUS_IS_OK(status)) { 254 179 PyErr_SetDCERPCStatus(iface->pipe, status); 255 180 talloc_free(mem_ctx); … … 291 216 &transfer_syntax); 292 217 293 if ( NT_STATUS_IS_ERR(status)) {218 if (!NT_STATUS_IS_OK(status)) { 294 219 PyErr_SetDCERPCStatus(iface->pipe, status); 295 220 return NULL; … … 299 224 } 300 225 301 PyObject *py_dcerpc_interface_init_helper(PyTypeObject *type, PyObject *args, PyObject *kwargs, const struct ndr_interface_table *table) 226 static PyMethodDef dcerpc_interface_methods[] = { 227 { "request", (PyCFunction)py_iface_request, METH_VARARGS|METH_KEYWORDS, "S.request(opnum, data, object=None) -> data\nMake a raw request" }, 228 { "alter_context", (PyCFunction)py_iface_alter_context, METH_VARARGS|METH_KEYWORDS, "S.alter_context(syntax)\nChange to a different interface" }, 229 { NULL, NULL, 0, NULL }, 230 }; 231 232 static void dcerpc_interface_dealloc(PyObject* self) 233 { 234 dcerpc_InterfaceObject *interface = (dcerpc_InterfaceObject *)self; 235 talloc_free(interface->mem_ctx); 236 self->ob_type->tp_free(self); 237 } 238 239 static PyObject *dcerpc_interface_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) 302 240 { 303 241 dcerpc_InterfaceObject *ret; … … 305 243 struct cli_credentials *credentials; 306 244 struct loadparm_context *lp_ctx = NULL; 307 PyObject *py_lp_ctx = Py_None, *py_credentials = Py_None , *py_basis = Py_None;308 TALLOC_CTX *mem_ctx = NULL;245 PyObject *py_lp_ctx = Py_None, *py_credentials = Py_None; 246 TALLOC_CTX *mem_ctx; 309 247 struct tevent_context *event_ctx; 310 248 NTSTATUS status; 311 249 250 PyObject *syntax, *py_basis = Py_None; 312 251 const char *kwnames[] = { 313 "binding", " lp_ctx", "credentials", "basis_connection", NULL252 "binding", "syntax", "lp_ctx", "credentials", "basis_connection", NULL 314 253 }; 315 316 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|OOO:samr", discard_const_p(char *, kwnames), &binding_string, &py_lp_ctx, &py_credentials, &py_basis)) { 317 return NULL; 318 } 319 320 lp_ctx = lp_from_py_object(py_lp_ctx); 254 struct ndr_interface_table *table; 255 256 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "sO|OOO:connect", discard_const_p(char *, kwnames), &binding_string, &syntax, &py_lp_ctx, &py_credentials, &py_basis)) { 257 return NULL; 258 } 259 260 mem_ctx = talloc_new(NULL); 261 if (mem_ctx == NULL) { 262 PyErr_NoMemory(); 263 return NULL; 264 } 265 266 lp_ctx = lpcfg_from_py_object(mem_ctx, py_lp_ctx); 321 267 if (lp_ctx == NULL) { 322 268 PyErr_SetString(PyExc_TypeError, "Expected loadparm context"); 323 return NULL; 324 } 325 326 status = dcerpc_init(lp_ctx); 327 if (!NT_STATUS_IS_OK(status)) { 328 PyErr_SetNTSTATUS(status); 329 return NULL; 330 } 269 talloc_free(mem_ctx); 270 return NULL; 271 } 272 331 273 credentials = cli_credentials_from_py_object(py_credentials); 332 274 if (credentials == NULL) { 333 275 PyErr_SetString(PyExc_TypeError, "Expected credentials"); 276 talloc_free(mem_ctx); 334 277 return NULL; 335 278 } 336 279 ret = PyObject_New(dcerpc_InterfaceObject, type); 337 338 event_ctx = event_context_init(mem_ctx); 280 ret->mem_ctx = mem_ctx; 281 282 event_ctx = s4_event_context_init(ret->mem_ctx); 283 284 /* Create a dummy interface table struct. TODO: In the future, we should 285 * rather just allow connecting without requiring an interface table. 286 */ 287 288 table = talloc_zero(ret->mem_ctx, struct ndr_interface_table); 289 290 if (table == NULL) { 291 PyErr_SetString(PyExc_MemoryError, "Allocating interface table"); 292 talloc_free(mem_ctx); 293 return NULL; 294 } 295 296 if (!ndr_syntax_from_py_object(syntax, &table->syntax_id)) { 297 talloc_free(mem_ctx); 298 return NULL; 299 } 300 301 ret->pipe = NULL; 302 ret->binding_handle = NULL; 339 303 340 304 if (py_basis != Py_None) { … … 347 311 } 348 312 349 base_pipe = ((dcerpc_InterfaceObject *)py_basis)->pipe; 313 base_pipe = talloc_reference(ret->mem_ctx, 314 ((dcerpc_InterfaceObject *)py_basis)->pipe); 350 315 351 316 status = dcerpc_secondary_context(base_pipe, &ret->pipe, table); 317 318 ret->pipe = talloc_steal(ret->mem_ctx, ret->pipe); 352 319 } else { 353 status = dcerpc_pipe_connect( NULL, &ret->pipe, binding_string,354 355 } 356 if (NT_STATUS_IS_ERR(status)) { 357 PyErr_SetNTSTATUS(status);358 talloc_free(mem_ctx);359 return NULL;360 }361 320 status = dcerpc_pipe_connect(ret->mem_ctx, &ret->pipe, binding_string, 321 table, credentials, event_ctx, lp_ctx); 322 } 323 324 if (!NT_STATUS_IS_OK(status)) { 325 PyErr_SetDCERPCStatus(ret->pipe, status); 326 talloc_free(ret->mem_ctx); 327 return NULL; 328 } 362 329 ret->pipe->conn->flags |= DCERPC_NDR_REF_ALLOC; 330 ret->binding_handle = ret->pipe->binding_handle; 363 331 return (PyObject *)ret; 364 332 } 365 333 366 static PyMethodDef dcerpc_interface_methods[] = { 367 { "request", (PyCFunction)py_iface_request, METH_VARARGS|METH_KEYWORDS, "S.request(opnum, data, object=None) -> data\nMake a raw request" }, 368 { "alter_context", (PyCFunction)py_iface_alter_context, METH_VARARGS|METH_KEYWORDS, "S.alter_context(syntax)\nChange to a different interface" }, 369 { NULL, NULL, 0, NULL }, 370 }; 371 372 373 static void dcerpc_interface_dealloc(PyObject* self) 374 { 375 dcerpc_InterfaceObject *interface = (dcerpc_InterfaceObject *)self; 376 talloc_free(interface->pipe); 377 PyObject_Del(self); 378 } 379 380 static PyObject *dcerpc_interface_new(PyTypeObject *self, PyObject *args, PyObject *kwargs) 381 { 382 dcerpc_InterfaceObject *ret; 383 const char *binding_string; 384 struct cli_credentials *credentials; 385 struct loadparm_context *lp_ctx = NULL; 386 PyObject *py_lp_ctx = Py_None, *py_credentials = Py_None; 387 TALLOC_CTX *mem_ctx = NULL; 388 struct tevent_context *event_ctx; 389 NTSTATUS status; 390 391 PyObject *syntax, *py_basis = Py_None; 392 const char *kwnames[] = { 393 "binding", "syntax", "lp_ctx", "credentials", "basis_connection", NULL 394 }; 395 struct ndr_interface_table *table; 396 397 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "sO|OOO:connect", discard_const_p(char *, kwnames), &binding_string, &syntax, &py_lp_ctx, &py_credentials, &py_basis)) { 398 return NULL; 399 } 400 401 lp_ctx = lp_from_py_object(py_lp_ctx); 402 if (lp_ctx == NULL) { 403 PyErr_SetString(PyExc_TypeError, "Expected loadparm context"); 404 return NULL; 405 } 406 407 credentials = cli_credentials_from_py_object(py_credentials); 408 if (credentials == NULL) { 409 PyErr_SetString(PyExc_TypeError, "Expected credentials"); 410 return NULL; 411 } 412 ret = PyObject_New(dcerpc_InterfaceObject, &dcerpc_InterfaceType); 413 414 event_ctx = s4_event_context_init(mem_ctx); 415 416 /* Create a dummy interface table struct. TODO: In the future, we should rather just allow 417 * connecting without requiring an interface table. 418 */ 419 420 table = talloc_zero(mem_ctx, struct ndr_interface_table); 421 422 if (table == NULL) { 423 PyErr_SetString(PyExc_MemoryError, "Allocating interface table"); 424 return NULL; 425 } 426 427 if (!ndr_syntax_from_py_object(syntax, &table->syntax_id)) { 428 return NULL; 429 } 430 431 ret->pipe = NULL; 432 433 if (py_basis != Py_None) { 434 struct dcerpc_pipe *base_pipe; 435 436 if (!PyObject_TypeCheck(py_basis, &dcerpc_InterfaceType)) { 437 PyErr_SetString(PyExc_ValueError, "basis_connection must be a DCE/RPC connection"); 438 talloc_free(mem_ctx); 439 return NULL; 440 } 441 442 base_pipe = ((dcerpc_InterfaceObject *)py_basis)->pipe; 443 444 status = dcerpc_secondary_context(base_pipe, &ret->pipe, 445 table); 446 ret->pipe = talloc_steal(NULL, ret->pipe); 447 } else { 448 status = dcerpc_pipe_connect(NULL, &ret->pipe, binding_string, 449 table, credentials, event_ctx, lp_ctx); 450 } 451 452 if (NT_STATUS_IS_ERR(status)) { 453 PyErr_SetDCERPCStatus(ret->pipe, status); 454 talloc_free(mem_ctx); 455 return NULL; 456 } 457 ret->pipe->conn->flags |= DCERPC_NDR_REF_ALLOC; 458 return (PyObject *)ret; 459 } 460 461 PyTypeObject dcerpc_InterfaceType = { 334 static PyTypeObject dcerpc_InterfaceType = { 462 335 PyObject_HEAD_INIT(NULL) 0, 463 336 .tp_name = "dcerpc.ClientConnection", -
vendor/current/source4/librpc/rpc/pyrpc.h
r414 r740 22 22 23 23 #include "libcli/util/pyerrors.h" 24 #include "librpc/rpc/dcerpc.h" 24 25 #ifndef Py_TYPE /* Py_TYPE is only available on Python > 2.6 */ 26 #define Py_TYPE(ob) (((PyObject*)(ob))->ob_type) 27 #endif 25 28 26 29 #define PY_CHECK_TYPE(type, var, fail) \ 27 30 if (!PyObject_TypeCheck(var, type)) {\ 28 PyErr_Format(PyExc_TypeError, "Expected type %s", (type)->tp_name); \31 PyErr_Format(PyExc_TypeError, __location__ ": Expected type '%s' for '%s' of type '%s'", (type)->tp_name, #var, Py_TYPE(var)->tp_name); \ 29 32 fail; \ 30 33 } … … 37 40 #define dom_sid28_Check dom_sid_Check 38 41 39 /* This macro is only provided by Python >= 2.3 */40 #ifndef PyAPI_DATA41 # define PyAPI_DATA(RTYPE) extern RTYPE42 #endif43 44 42 typedef struct { 45 43 PyObject_HEAD 44 TALLOC_CTX *mem_ctx; 46 45 struct dcerpc_pipe *pipe; 46 struct dcerpc_binding_handle *binding_handle; 47 47 } dcerpc_InterfaceObject; 48 48 49 PyAPI_DATA(PyTypeObject) dcerpc_InterfaceType;50 49 51 #define PyErr_FromNdrError(err) Py_BuildValue("(is)", err, ndr_map_error2string(err)) 52 53 #define PyErr_SetNdrError(err) \ 54 PyErr_SetObject(PyExc_RuntimeError, PyErr_FromNdrError(err)) 55 56 void PyErr_SetDCERPCStatus(struct dcerpc_pipe *pipe, NTSTATUS status); 57 58 typedef bool (*py_data_pack_fn) (PyObject *args, PyObject *kwargs, void *r); 59 typedef PyObject *(*py_data_unpack_fn) (void *r); 60 61 struct PyNdrRpcMethodDef { 62 const char *name; 63 const char *doc; 64 dcerpc_call_fn call; 65 py_data_pack_fn pack_in_data; 66 py_data_unpack_fn unpack_out_data; 67 uint32_t opnum; 68 const struct ndr_interface_table *table; 69 }; 70 71 bool PyInterface_AddNdrRpcMethods(PyTypeObject *object, const struct PyNdrRpcMethodDef *mds); 72 PyObject *py_dcerpc_interface_init_helper(PyTypeObject *type, PyObject *args, PyObject *kwargs, const struct ndr_interface_table *table); 50 /* 51 these prototypes should be generated by the python pidl backend, but 52 aren't yet. They are needed when one module that has python access 53 is accessed by another module 54 */ 55 union netr_LogonLevel *py_export_netr_LogonLevel(TALLOC_CTX *mem_ctx, int level, PyObject *in); 56 union netr_Validation; 57 PyObject *py_import_netr_Validation(TALLOC_CTX *mem_ctx, int level, union netr_Validation *in); 73 58 74 59 #endif /* _PYRPC_H_ */ -
vendor/current/source4/librpc/tests/binding_string.c
r414 r740 25 25 #include "librpc/rpc/dcerpc_proto.h" 26 26 #include "torture/torture.h" 27 #include "lib/util/util_net.h" 27 28 28 29 static bool test_BindingString(struct torture_context *tctx, … … 128 129 torture_assert_ntstatus_ok(tctx, dcerpc_parse_binding(tctx, 129 130 "308FB580-1EB2-11CA-923B-08002B1075A7@ncacn_ip_tcp:$SERVER", &b), "parse"); 131 torture_assert_ntstatus_ok(tctx, dcerpc_parse_binding(tctx, "ncacn_ip_tcp:$SERVER[,sign,localaddress=192.168.1.1]", &b), "parse"); 132 torture_assert(tctx, b->transport == NCACN_IP_TCP, "ncacn_ip_tcp expected"); 133 torture_assert(tctx, b->flags == (DCERPC_SIGN | DCERPC_LOCALADDRESS), "sign flag"); 134 torture_assert_str_equal(tctx, b->localaddress, "192.168.1.1", "localaddress"); 135 torture_assert_str_equal(tctx, "ncacn_ip_tcp:$SERVER[,sign,localaddress=192.168.1.1]", 136 dcerpc_binding_string(tctx, b), "back to string"); 130 137 131 138 return true; … … 156 163 { 157 164 int i; 158 struct torture_suite *suite = torture_suite_create(mem_ctx, " BINDING");165 struct torture_suite *suite = torture_suite_create(mem_ctx, "binding"); 159 166 160 167 for (i = 0; i < ARRAY_SIZE(test_strings); i++) {
Note:
See TracChangeset
for help on using the changeset viewer.