Changeset 745 for trunk/server/source3/libsmb/smbsock_connect.c
- Timestamp:
- Nov 27, 2012, 4:43:17 PM (13 years ago)
- Location:
- trunk/server
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/server
- Property svn:mergeinfo changed
/vendor/current merged: 581,587,591,594,597,600,615,618,740
- Property svn:mergeinfo changed
-
trunk/server/source3/libsmb/smbsock_connect.c
r603 r745 19 19 20 20 #include "includes.h" 21 #include "../lib/async_req/async_sock.h" 21 #include "../lib/util/tevent_ntstatus.h" 22 #include "client.h" 22 23 #include "async_smb.h" 24 #include "libsmb/nmblib.h" 23 25 24 26 struct nb_connect_state { … … 177 179 const struct sockaddr_storage *addr; 178 180 const char *called_name; 181 uint8_t called_type; 179 182 const char *calling_name; 183 uint8_t calling_type; 180 184 struct tevent_req *req_139; 181 185 struct tevent_req *req_445; … … 192 196 struct tevent_context *ev, 193 197 const struct sockaddr_storage *addr, 198 uint16_t port, 194 199 const char *called_name, 195 const char *calling_name) 200 int called_type, 201 const char *calling_name, 202 int calling_type) 196 203 { 197 204 struct tevent_req *req, *subreq; … … 207 214 state->called_name = 208 215 (called_name != NULL) ? called_name : "*SMBSERVER"; 216 state->called_type = 217 (called_type != -1) ? called_type : 0x20; 209 218 state->calling_name = 210 219 (calling_name != NULL) ? calling_name : global_myname(); 220 state->calling_type = 221 (calling_type != -1) ? calling_type : 0x00; 211 222 212 223 talloc_set_destructor(state, smbsock_connect_state_destructor); 224 225 if (port == 139) { 226 subreq = tevent_wakeup_send(state, ev, timeval_set(0, 0)); 227 if (tevent_req_nomem(subreq, req)) { 228 return tevent_req_post(req, ev); 229 } 230 tevent_req_set_callback(subreq, smbsock_connect_do_139, req); 231 return req; 232 } 233 if (port != 0) { 234 state->req_445 = open_socket_out_send(state, ev, addr, port, 235 5000); 236 if (tevent_req_nomem(state->req_445, req)) { 237 return tevent_req_post(req, ev); 238 } 239 tevent_req_set_callback( 240 state->req_445, smbsock_connect_connected, req); 241 return req; 242 } 243 244 /* 245 * port==0, try both 246 */ 213 247 214 248 state->req_445 = open_socket_out_send(state, ev, addr, 445, 5000); … … 238 272 if (state->sock != -1) { 239 273 close(state->sock); 274 state->sock = -1; 240 275 } 241 276 return 0; … … 257 292 } 258 293 state->req_139 = nb_connect_send(state, state->ev, state->addr, 259 state->called_name, 0x20, 260 state->calling_name, 0x0); 294 state->called_name, 295 state->called_type, 296 state->calling_name, 297 state->calling_type); 261 298 if (tevent_req_nomem(state->req_139, req)) { 262 299 return; … … 314 351 315 352 NTSTATUS smbsock_connect_recv(struct tevent_req *req, int *sock, 316 uint16_t *port)353 uint16_t *ret_port) 317 354 { 318 355 struct smbsock_connect_state *state = tevent_req_data( … … 325 362 *sock = state->sock; 326 363 state->sock = -1; 327 if ( port != NULL) {328 * port = state->port;364 if (ret_port != NULL) { 365 *ret_port = state->port; 329 366 } 330 367 return NT_STATUS_OK; 331 368 } 332 369 333 NTSTATUS smbsock_connect(const struct sockaddr_storage *addr, 334 const char *called_name, const char *calling_name, 335 int *pfd, uint16_t *port) 370 NTSTATUS smbsock_connect(const struct sockaddr_storage *addr, uint16_t port, 371 const char *called_name, int called_type, 372 const char *calling_name, int calling_type, 373 int *pfd, uint16_t *ret_port, int sec_timeout) 336 374 { 337 375 TALLOC_CTX *frame = talloc_stackframe(); … … 344 382 goto fail; 345 383 } 346 req = smbsock_connect_send(frame, ev, addr, called_name, calling_name); 384 req = smbsock_connect_send(frame, ev, addr, port, 385 called_name, called_type, 386 calling_name, calling_type); 347 387 if (req == NULL) { 348 388 goto fail; 349 389 } 390 if ((sec_timeout != 0) && 391 !tevent_req_set_endtime( 392 req, ev, timeval_current_ofs(sec_timeout, 0))) { 393 goto fail; 394 } 350 395 if (!tevent_req_poll_ntstatus(req, ev, &status)) { 351 396 goto fail; 352 397 } 353 status = smbsock_connect_recv(req, pfd, port);398 status = smbsock_connect_recv(req, pfd, ret_port); 354 399 fail: 355 400 TALLOC_FREE(frame); … … 361 406 const struct sockaddr_storage *addrs; 362 407 const char **called_names; 408 int *called_types; 409 const char **calling_names; 410 int *calling_types; 363 411 size_t num_addrs; 412 uint16_t port; 364 413 365 414 struct tevent_req **requests; … … 368 417 369 418 int fd; 370 uint16_t port;419 uint16_t chosen_port; 371 420 size_t chosen_index; 372 421 }; … … 381 430 const struct sockaddr_storage *addrs, 382 431 const char **called_names, 383 size_t num_addrs) 432 int *called_types, 433 const char **calling_names, 434 int *calling_types, 435 size_t num_addrs, uint16_t port) 384 436 { 385 437 struct tevent_req *req, *subreq; … … 395 447 state->num_addrs = num_addrs; 396 448 state->called_names = called_names; 449 state->called_types = called_types; 450 state->calling_names = calling_names; 451 state->calling_types = calling_types; 452 state->port = port; 397 453 398 454 if (num_addrs == 0) { … … 459 515 subreq = smbsock_connect_send( 460 516 state->requests, state->ev, &state->addrs[state->num_sent], 517 state->port, 461 518 (state->called_names != NULL) 462 519 ? state->called_names[state->num_sent] : NULL, 463 NULL); 520 (state->called_types != NULL) 521 ? state->called_types[state->num_sent] : -1, 522 (state->calling_names != NULL) 523 ? state->calling_names[state->num_sent] : NULL, 524 (state->calling_types != NULL) 525 ? state->calling_types[state->num_sent] : -1); 464 526 if (tevent_req_nomem(subreq, req)) { 465 527 return false; … … 481 543 NTSTATUS status; 482 544 int fd; 483 uint16_t port;545 uint16_t chosen_port; 484 546 size_t i; 485 547 size_t chosen_index = 0; … … 496 558 } 497 559 498 status = smbsock_connect_recv(subreq, &fd, & port);560 status = smbsock_connect_recv(subreq, &fd, &chosen_port); 499 561 500 562 TALLOC_FREE(subreq); … … 507 569 TALLOC_FREE(state->requests); 508 570 state->fd = fd; 509 state-> port =port;571 state->chosen_port = chosen_port; 510 572 state->chosen_index = chosen_index; 511 573 tevent_req_done(req); … … 529 591 530 592 NTSTATUS smbsock_any_connect_recv(struct tevent_req *req, int *pfd, 531 size_t *chosen_index, uint16_t *port) 593 size_t *chosen_index, 594 uint16_t *chosen_port) 532 595 { 533 596 struct smbsock_any_connect_state *state = tevent_req_data( … … 542 605 *chosen_index = state->chosen_index; 543 606 } 544 if ( port != NULL) {545 * port = state->port;607 if (chosen_port != NULL) { 608 *chosen_port = state->chosen_port; 546 609 } 547 610 return NT_STATUS_OK; … … 549 612 550 613 NTSTATUS smbsock_any_connect(const struct sockaddr_storage *addrs, 551 const char **called_names, size_t num_addrs, 552 int *pfd, size_t *chosen_index, uint16_t *port) 614 const char **called_names, 615 int *called_types, 616 const char **calling_names, 617 int *calling_types, 618 size_t num_addrs, 619 uint16_t port, 620 int sec_timeout, 621 int *pfd, size_t *chosen_index, 622 uint16_t *chosen_port) 553 623 { 554 624 TALLOC_CTX *frame = talloc_stackframe(); … … 561 631 goto fail; 562 632 } 563 req = smbsock_any_connect_send(frame, ev, addrs, called_names, 564 num_addrs); 633 req = smbsock_any_connect_send(frame, ev, addrs, 634 called_names, called_types, 635 calling_names, calling_types, 636 num_addrs, port); 565 637 if (req == NULL) { 566 638 goto fail; 567 639 } 640 if ((sec_timeout != 0) && 641 !tevent_req_set_endtime( 642 req, ev, timeval_current_ofs(sec_timeout, 0))) { 643 goto fail; 644 } 568 645 if (!tevent_req_poll_ntstatus(req, ev, &status)) { 569 646 goto fail; 570 647 } 571 status = smbsock_any_connect_recv(req, pfd, chosen_index, port);648 status = smbsock_any_connect_recv(req, pfd, chosen_index, chosen_port); 572 649 fail: 573 650 TALLOC_FREE(frame);
Note:
See TracChangeset
for help on using the changeset viewer.