Changeset 427 for vendor/current/source3/rpc_client
- Timestamp:
- Apr 9, 2010, 3:20:58 PM (15 years ago)
- Location:
- vendor/current/source3/rpc_client
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
vendor/current/source3/rpc_client/cli_pipe.c
r414 r427 3032 3032 } 3033 3033 3034 #define RPCCLI_DEFAULT_TIMEOUT 10000 /* 10 seconds. */ 3035 3034 3036 unsigned int rpccli_set_timeout(struct rpc_pipe_client *rpc_cli, 3035 3037 unsigned int timeout) 3036 3038 { 3037 struct cli_state *cli; 3038 3039 if (rpc_cli->transport->transport == NCACN_NP) { 3040 cli = rpc_pipe_np_smb_conn(rpc_cli); 3041 if (cli == NULL) { 3042 return 0; 3043 } 3044 return cli_set_timeout(cli, timeout); 3045 } 3046 3047 if (rpc_cli->transport->transport == NCACN_IP_TCP || 3048 rpc_cli->transport->transport == NCALRPC) { 3049 return rpccli_set_sock_timeout(rpc_cli, timeout); 3050 } 3051 3052 if (rpc_cli->transport->transport == NCACN_INTERNAL) { 3053 cli = rpc_pipe_smbd_smb_conn(rpc_cli); 3054 if (!cli) { 3055 return 0; 3056 } 3057 return cli_set_timeout(cli, timeout); 3058 } 3059 3060 return 0; 3039 unsigned int old; 3040 3041 if (rpc_cli->transport == NULL) { 3042 return RPCCLI_DEFAULT_TIMEOUT; 3043 } 3044 3045 if (rpc_cli->transport->set_timeout == NULL) { 3046 return RPCCLI_DEFAULT_TIMEOUT; 3047 } 3048 3049 old = rpc_cli->transport->set_timeout(rpc_cli->transport->priv, timeout); 3050 if (old == 0) { 3051 return RPCCLI_DEFAULT_TIMEOUT; 3052 } 3053 3054 return old; 3055 } 3056 3057 bool rpccli_is_connected(struct rpc_pipe_client *rpc_cli) 3058 { 3059 if (rpc_cli == NULL) { 3060 return false; 3061 } 3062 3063 if (rpc_cli->transport == NULL) { 3064 return false; 3065 } 3066 3067 return rpc_cli->transport->is_connected(rpc_cli->transport->priv); 3061 3068 } 3062 3069 … … 3563 3570 } 3564 3571 3565 static int rpc_pipe_client_np_destructor(struct rpc_pipe_client *p) 3566 { 3572 struct rpc_pipe_client_np_ref { 3567 3573 struct cli_state *cli; 3568 3569 cli = rpc_pipe_np_smb_conn(p); 3570 if (cli != NULL) { 3571 DLIST_REMOVE(cli->pipe_list, p); 3572 } 3574 struct rpc_pipe_client *pipe; 3575 }; 3576 3577 static int rpc_pipe_client_np_ref_destructor(struct rpc_pipe_client_np_ref *np_ref) 3578 { 3579 DLIST_REMOVE(np_ref->cli->pipe_list, np_ref->pipe); 3573 3580 return 0; 3574 3581 } … … 3593 3600 struct rpc_pipe_client *result; 3594 3601 NTSTATUS status; 3602 struct rpc_pipe_client_np_ref *np_ref; 3595 3603 3596 3604 /* sanity check to protect against crashes */ … … 3631 3639 result->transport->transport = NCACN_NP; 3632 3640 3633 DLIST_ADD(cli->pipe_list, result); 3634 talloc_set_destructor(result, rpc_pipe_client_np_destructor); 3641 np_ref = talloc(result->transport, struct rpc_pipe_client_np_ref); 3642 if (np_ref == NULL) { 3643 TALLOC_FREE(result); 3644 return NT_STATUS_NO_MEMORY; 3645 } 3646 np_ref->cli = cli; 3647 np_ref->pipe = result; 3648 3649 DLIST_ADD(np_ref->cli->pipe_list, np_ref->pipe); 3650 talloc_set_destructor(np_ref, rpc_pipe_client_np_ref_destructor); 3635 3651 3636 3652 *presult = result; -
vendor/current/source3/rpc_client/cli_spoolss.c
r414 r427 766 766 uint32_t offered, 767 767 enum winreg_Type *type, 768 union spoolss_PrinterData *data) 769 { 770 NTSTATUS status; 771 WERROR werror; 772 uint32_t needed; 768 uint32_t *needed_p, 769 uint8_t **data_p) 770 { 771 NTSTATUS status; 772 WERROR werror; 773 uint32_t needed; 774 uint8_t *data; 775 776 data = talloc_zero_array(mem_ctx, uint8_t, offered); 777 W_ERROR_HAVE_NO_MEMORY(data); 773 778 774 779 status = rpccli_spoolss_GetPrinterData(cli, mem_ctx, 775 780 handle, 776 781 value_name, 777 offered,778 782 type, 779 783 data, 784 offered, 780 785 &needed, 781 786 &werror); … … 783 788 if (W_ERROR_EQUAL(werror, WERR_MORE_DATA)) { 784 789 offered = needed; 790 data = talloc_zero_array(mem_ctx, uint8_t, offered); 791 W_ERROR_HAVE_NO_MEMORY(data); 785 792 786 793 status = rpccli_spoolss_GetPrinterData(cli, mem_ctx, 787 794 handle, 788 795 value_name, 789 offered,790 796 type, 791 797 data, 798 offered, 792 799 &needed, 793 800 &werror); 794 801 } 802 803 *data_p = data; 804 *needed_p = needed; 795 805 796 806 return werror; -
vendor/current/source3/rpc_client/ndr.c
r414 r427 184 184 status = cli_do_rpc_ndr_recv(req, mem_ctx); 185 185 186 /*187 * NT_STATUS_IO_TIMEOUT indicates network problem,188 * tear the connection apart.189 */190 if (NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT)) {191 if (cli->transport->transport == NCACN_IP_TCP ||192 cli->transport->transport == NCALRPC) {193 rpccli_close_sock_fd(cli);194 }195 196 if (cli->transport->transport == NCACN_NP) {197 rpccli_close_np_fd(cli);198 }199 }200 186 fail: 201 187 TALLOC_FREE(frame); -
vendor/current/source3/rpc_client/rpc_transport_np.c
r414 r427 29 29 }; 30 30 31 static bool rpc_np_is_connected(void *priv) 32 { 33 struct rpc_transport_np_state *np_transport = talloc_get_type_abort( 34 priv, struct rpc_transport_np_state); 35 bool ok; 36 37 if (np_transport->cli == NULL) { 38 return false; 39 } 40 41 ok = cli_state_is_connected(np_transport->cli); 42 if (!ok) { 43 np_transport->cli = NULL; 44 return false; 45 } 46 47 return true; 48 } 49 50 static unsigned int rpc_np_set_timeout(void *priv, unsigned int timeout) 51 { 52 struct rpc_transport_np_state *np_transport = talloc_get_type_abort( 53 priv, struct rpc_transport_np_state); 54 bool ok; 55 56 if (np_transport->cli == NULL) { 57 return false; 58 } 59 60 ok = rpc_np_is_connected(np_transport); 61 if (!ok) { 62 return 0; 63 } 64 65 return cli_set_timeout(np_transport->cli, timeout); 66 } 67 31 68 static int rpc_transport_np_state_destructor(struct rpc_transport_np_state *s) 32 69 { 33 if ( s->cli->fd == -1) {70 if (!rpc_np_is_connected(s)) { 34 71 DEBUG(10, ("socket was closed, no need to send close request.\n")); 35 72 return 0; 36 73 } 37 74 75 /* TODO: do not use a sync call with a destructor!!! */ 38 76 if (!NT_STATUS_IS_OK(cli_close(s->cli, s->fnum))) { 39 77 DEBUG(1, ("rpc_transport_np_state_destructor: cli_close " … … 49 87 50 88 struct rpc_np_write_state { 89 struct rpc_transport_np_state *np_transport; 51 90 size_t size; 52 91 size_t written; … … 64 103 struct tevent_req *req, *subreq; 65 104 struct rpc_np_write_state *state; 105 bool ok; 66 106 67 107 req = tevent_req_create(mem_ctx, &state, struct rpc_np_write_state); … … 69 109 return NULL; 70 110 } 111 112 ok = rpc_np_is_connected(np_transport); 113 if (!ok) { 114 tevent_req_nterror(req, NT_STATUS_CONNECTION_INVALID); 115 return tevent_req_post(req, ev); 116 } 117 118 state->np_transport = np_transport; 71 119 state->size = size; 120 72 121 73 122 subreq = cli_write_andx_send(mem_ctx, ev, np_transport->cli, … … 93 142 TALLOC_FREE(subreq); 94 143 if (!NT_STATUS_IS_OK(status)) { 144 state->np_transport->cli = NULL; 95 145 tevent_req_nterror(req, status); 96 146 return; … … 113 163 114 164 struct rpc_np_read_state { 165 struct rpc_transport_np_state *np_transport; 115 166 uint8_t *data; 116 167 size_t size; … … 129 180 struct tevent_req *req, *subreq; 130 181 struct rpc_np_read_state *state; 182 bool ok; 131 183 132 184 req = tevent_req_create(mem_ctx, &state, struct rpc_np_read_state); … … 134 186 return NULL; 135 187 } 188 189 ok = rpc_np_is_connected(np_transport); 190 if (!ok) { 191 tevent_req_nterror(req, NT_STATUS_CONNECTION_INVALID); 192 return tevent_req_post(req, ev); 193 } 194 195 state->np_transport = np_transport; 136 196 state->data = data; 137 197 state->size = size; … … 157 217 NTSTATUS status; 158 218 uint8_t *rcvbuf; 219 220 /* We must free subreq in this function as there is 221 a timer event attached to it. */ 159 222 160 223 status = cli_read_andx_recv(subreq, &state->received, &rcvbuf); … … 168 231 if (!NT_STATUS_IS_OK(status)) { 169 232 TALLOC_FREE(subreq); 233 state->np_transport->cli = NULL; 170 234 tevent_req_nterror(req, status); 171 235 return; … … 174 238 if (state->received > state->size) { 175 239 TALLOC_FREE(subreq); 240 state->np_transport->cli = NULL; 176 241 tevent_req_nterror(req, NT_STATUS_INVALID_NETWORK_RESPONSE); 177 242 return; 178 243 } 179 244 245 if (state->received == 0) { 246 TALLOC_FREE(subreq); 247 state->np_transport->cli = NULL; 248 tevent_req_nterror(req, NT_STATUS_PIPE_BROKEN); 249 return; 250 } 251 180 252 memcpy(state->data, rcvbuf, state->received); 253 TALLOC_FREE(subreq); 181 254 tevent_req_done(req); 182 255 } … … 196 269 197 270 struct rpc_np_trans_state { 271 struct rpc_transport_np_state *np_transport; 198 272 uint16_t setup[2]; 273 uint32_t max_rdata_len; 199 274 uint8_t *rdata; 200 275 uint32_t rdata_len; … … 213 288 struct tevent_req *req, *subreq; 214 289 struct rpc_np_trans_state *state; 290 bool ok; 215 291 216 292 req = tevent_req_create(mem_ctx, &state, struct rpc_np_trans_state); … … 218 294 return NULL; 219 295 } 296 297 ok = rpc_np_is_connected(np_transport); 298 if (!ok) { 299 tevent_req_nterror(req, NT_STATUS_CONNECTION_INVALID); 300 return tevent_req_post(req, ev); 301 } 302 303 state->np_transport = np_transport; 304 state->max_rdata_len = max_rdata_len; 220 305 221 306 SSVAL(state->setup+0, 0, TRANSACT_DCERPCCMD); … … 248 333 &state->rdata, &state->rdata_len); 249 334 TALLOC_FREE(subreq); 335 if (NT_STATUS_EQUAL(status, NT_STATUS_BUFFER_TOO_SMALL)) { 336 status = NT_STATUS_OK; 337 } 250 338 if (!NT_STATUS_IS_OK(status)) { 339 state->np_transport->cli = NULL; 251 340 tevent_req_nterror(req, status); 252 341 return; 253 342 } 343 344 if (state->rdata_len > state->max_rdata_len) { 345 state->np_transport->cli = NULL; 346 tevent_req_nterror(req, NT_STATUS_INVALID_NETWORK_RESPONSE); 347 return; 348 } 349 350 if (state->rdata_len == 0) { 351 state->np_transport->cli = NULL; 352 tevent_req_nterror(req, NT_STATUS_PIPE_BROKEN); 353 return; 354 } 355 254 356 tevent_req_done(req); 255 357 } … … 284 386 struct tevent_req *req, *subreq; 285 387 struct rpc_transport_np_init_state *state; 388 bool ok; 286 389 287 390 req = tevent_req_create(mem_ctx, &state, … … 289 392 if (req == NULL) { 290 393 return NULL; 394 } 395 396 ok = cli_state_is_connected(cli); 397 if (!ok) { 398 tevent_req_nterror(req, NT_STATUS_CONNECTION_INVALID); 399 return tevent_req_post(req, ev); 291 400 } 292 401 … … 356 465 state->transport->trans_send = rpc_np_trans_send; 357 466 state->transport->trans_recv = rpc_np_trans_recv; 467 state->transport->is_connected = rpc_np_is_connected; 468 state->transport->set_timeout = rpc_np_set_timeout; 358 469 359 470 *presult = talloc_move(mem_ctx, &state->transport); … … 403 514 return state->cli; 404 515 } 405 406 void rpccli_close_np_fd(struct rpc_pipe_client *p)407 {408 struct cli_state *cli = rpc_pipe_np_smb_conn(p);409 if (cli) {410 if (cli->fd != -1) {411 close(cli->fd);412 cli->fd = -1;413 }414 }415 return;416 } -
vendor/current/source3/rpc_client/rpc_transport_smbd.c
r414 r427 420 420 } 421 421 422 static void rpc_smbd_disconnect(struct rpc_transport_smbd_state *transp) 423 { 424 if (transp == NULL) { 425 return; 426 } 427 428 if (transp->conn == NULL) { 429 return; 430 } 431 432 if (transp->conn->cli == NULL) { 433 return; 434 } 435 436 if (transp->conn->cli->fd != -1) { 437 close(transp->conn->cli->fd); 438 transp->conn->cli->fd = -1; 439 } 440 441 transp->conn = NULL; 442 } 443 444 static bool rpc_smbd_is_connected(void *priv) 445 { 446 struct rpc_transport_smbd_state *transp = talloc_get_type_abort( 447 priv, struct rpc_transport_smbd_state); 448 bool ok; 449 450 if (transp->conn == NULL) { 451 return false; 452 } 453 454 if (transp->sub_transp == NULL) { 455 return false; 456 } 457 458 ok = transp->sub_transp->is_connected(transp->sub_transp->priv); 459 if (!ok) { 460 rpc_smbd_disconnect(transp); 461 return false; 462 } 463 464 return true; 465 } 466 467 static unsigned int rpc_smbd_set_timeout(void *priv, unsigned int timeout) 468 { 469 struct rpc_transport_smbd_state *transp = talloc_get_type_abort( 470 priv, struct rpc_transport_smbd_state); 471 bool ok; 472 473 ok = rpc_smbd_is_connected(transp); 474 if (!ok) { 475 return 0; 476 } 477 478 if (transp->sub_transp->set_timeout == NULL) { 479 return 0; 480 } 481 482 return transp->sub_transp->set_timeout(transp->sub_transp->priv, timeout); 483 } 484 422 485 struct rpc_smbd_write_state { 423 struct rpc_ cli_transport *sub_transp;486 struct rpc_transport_smbd_state *transp; 424 487 ssize_t written; 425 488 }; … … 436 499 struct tevent_req *req, *subreq; 437 500 struct rpc_smbd_write_state *state; 501 bool ok; 438 502 439 503 req = tevent_req_create(mem_ctx, &state, struct rpc_smbd_write_state); … … 441 505 return NULL; 442 506 } 443 state->sub_transp = transp->sub_transp; 507 508 ok = rpc_smbd_is_connected(transp); 509 if (!ok) { 510 tevent_req_nterror(req, NT_STATUS_CONNECTION_INVALID); 511 return tevent_req_post(req, ev); 512 } 513 514 state->transp = transp; 444 515 445 516 subreq = transp->sub_transp->write_send(state, ev, data, size, … … 469 540 NTSTATUS status; 470 541 471 status = state-> sub_transp->write_recv(subreq, &state->written);542 status = state->transp->sub_transp->write_recv(subreq, &state->written); 472 543 TALLOC_FREE(subreq); 473 544 if (!NT_STATUS_IS_OK(status)) { 545 rpc_smbd_disconnect(state->transp); 474 546 tevent_req_nterror(req, status); 475 547 return; … … 492 564 493 565 struct rpc_smbd_read_state { 494 struct rpc_ cli_transport *sub_transp;566 struct rpc_transport_smbd_state *transp; 495 567 ssize_t received; 496 568 }; … … 507 579 struct tevent_req *req, *subreq; 508 580 struct rpc_smbd_read_state *state; 581 bool ok; 509 582 510 583 req = tevent_req_create(mem_ctx, &state, struct rpc_smbd_read_state); … … 512 585 return NULL; 513 586 } 514 state->sub_transp = transp->sub_transp; 587 588 ok = rpc_smbd_is_connected(transp); 589 if (!ok) { 590 tevent_req_nterror(req, NT_STATUS_CONNECTION_INVALID); 591 return tevent_req_post(req, ev); 592 } 593 594 state->transp = transp; 515 595 516 596 subreq = transp->sub_transp->read_send(state, ev, data, size, … … 539 619 NTSTATUS status; 540 620 541 status = state-> sub_transp->read_recv(subreq, &state->received);621 status = state->transp->sub_transp->read_recv(subreq, &state->received); 542 622 TALLOC_FREE(subreq); 543 623 if (!NT_STATUS_IS_OK(status)) { 624 rpc_smbd_disconnect(state->transp); 544 625 tevent_req_nterror(req, status); 545 626 return; … … 646 727 state->transport->trans_send = NULL; 647 728 state->transport->trans_recv = NULL; 729 state->transport->is_connected = rpc_smbd_is_connected; 730 state->transport->set_timeout = rpc_smbd_set_timeout; 648 731 649 732 *presult = talloc_move(mem_ctx, &state->transport); … … 683 766 return status; 684 767 } 685 686 struct cli_state *rpc_pipe_smbd_smb_conn(struct rpc_pipe_client *p)687 {688 struct rpc_transport_smbd_state *state = talloc_get_type(p->transport->priv,689 struct rpc_transport_smbd_state);690 if (!state || !state->conn) {691 return NULL;692 }693 return state->conn->cli;694 } -
vendor/current/source3/rpc_client/rpc_transport_sock.c
r414 r427 28 28 }; 29 29 30 static int rpc_transport_sock_state_destructor(struct rpc_transport_sock_state *s)30 static void rpc_sock_disconnect(struct rpc_transport_sock_state *s) 31 31 { 32 32 if (s->fd != -1) { … … 34 34 s->fd = -1; 35 35 } 36 } 37 38 static int rpc_transport_sock_state_destructor(struct rpc_transport_sock_state *s) 39 { 40 rpc_sock_disconnect(s); 36 41 return 0; 42 } 43 44 static bool rpc_sock_is_connected(void *priv) 45 { 46 struct rpc_transport_sock_state *sock_transp = talloc_get_type_abort( 47 priv, struct rpc_transport_sock_state); 48 49 if (sock_transp->fd == -1) { 50 return false; 51 } 52 53 return true; 54 } 55 56 static unsigned int rpc_sock_set_timeout(void *priv, unsigned int timeout) 57 { 58 struct rpc_transport_sock_state *sock_transp = talloc_get_type_abort( 59 priv, struct rpc_transport_sock_state); 60 int orig_timeout; 61 bool ok; 62 63 ok = rpc_sock_is_connected(sock_transp); 64 if (!ok) { 65 return 0; 66 } 67 68 orig_timeout = sock_transp->timeout; 69 70 sock_transp->timeout = timeout; 71 72 return orig_timeout; 37 73 } 38 74 … … 59 95 return NULL; 60 96 } 61 if ( sock_transp->fd == -1) {97 if (!rpc_sock_is_connected(sock_transp)) { 62 98 tevent_req_nterror(req, NT_STATUS_CONNECTION_INVALID); 63 99 return tevent_req_post(req, ev); … … 89 125 int err; 90 126 127 /* We must free subreq in this function as there is 128 a timer event attached to it. */ 129 91 130 state->received = async_recv_recv(subreq, &err); 131 92 132 if (state->received == -1) { 93 if (state->transp->fd != -1) { 94 close(state->transp->fd); 95 state->transp->fd = -1; 96 } 133 TALLOC_FREE(subreq); 134 rpc_sock_disconnect(state->transp); 97 135 tevent_req_nterror(req, map_nt_error_from_unix(err)); 98 136 return; 99 137 } 138 TALLOC_FREE(subreq); 100 139 tevent_req_done(req); 101 140 } … … 136 175 return NULL; 137 176 } 138 if ( sock_transp->fd == -1) {177 if (!rpc_sock_is_connected(sock_transp)) { 139 178 tevent_req_nterror(req, NT_STATUS_CONNECTION_INVALID); 140 179 return tevent_req_post(req, ev); … … 166 205 int err; 167 206 207 /* We must free subreq in this function as there is 208 a timer event attached to it. */ 209 168 210 state->sent = async_send_recv(subreq, &err); 211 169 212 if (state->sent == -1) { 170 if (state->transp->fd != -1) { 171 close(state->transp->fd); 172 state->transp->fd = -1; 173 } 213 TALLOC_FREE(subreq); 214 rpc_sock_disconnect(state->transp); 174 215 tevent_req_nterror(req, map_nt_error_from_unix(err)); 175 216 return; 176 217 } 218 TALLOC_FREE(subreq); 177 219 tevent_req_done(req); 178 220 } … … 218 260 result->read_send = rpc_sock_read_send; 219 261 result->read_recv = rpc_sock_read_recv; 262 result->is_connected = rpc_sock_is_connected; 263 result->set_timeout = rpc_sock_set_timeout; 220 264 221 265 *presult = result; 222 266 return NT_STATUS_OK; 223 267 } 224 225 int rpccli_set_sock_timeout(struct rpc_pipe_client *cli, int timeout)226 {227 struct rpc_transport_sock_state *state = talloc_get_type(cli->transport->priv,228 struct rpc_transport_sock_state);229 int orig_timeout;230 if (!state) {231 return 0;232 }233 orig_timeout = state->timeout;234 state->timeout = timeout;235 return orig_timeout;236 }237 238 void rpccli_close_sock_fd(struct rpc_pipe_client *cli)239 {240 struct rpc_transport_sock_state *state = talloc_get_type(cli->transport->priv,241 struct rpc_transport_sock_state);242 if (state) {243 if (state->fd != -1) {244 close(state->fd);245 state->fd = -1;246 }247 }248 return;249 }250 251 bool rpc_pipe_tcp_connection_ok(struct rpc_pipe_client *cli)252 {253 struct rpc_transport_sock_state *state = talloc_get_type(cli->transport->priv,254 struct rpc_transport_sock_state);255 if (state && state->fd != -1) {256 return true;257 }258 259 return false;260 }
Note:
See TracChangeset
for help on using the changeset viewer.