Ignore:
Timestamp:
Nov 27, 2012, 4:43:17 PM (13 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: updated trunk to 3.6.0

Location:
trunk/server
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/server

  • trunk/server/source3/libsmb/smbsock_connect.c

    r603 r745  
    1919
    2020#include "includes.h"
    21 #include "../lib/async_req/async_sock.h"
     21#include "../lib/util/tevent_ntstatus.h"
     22#include "client.h"
    2223#include "async_smb.h"
     24#include "libsmb/nmblib.h"
    2325
    2426struct nb_connect_state {
     
    177179        const struct sockaddr_storage *addr;
    178180        const char *called_name;
     181        uint8_t called_type;
    179182        const char *calling_name;
     183        uint8_t calling_type;
    180184        struct tevent_req *req_139;
    181185        struct tevent_req *req_445;
     
    192196                                        struct tevent_context *ev,
    193197                                        const struct sockaddr_storage *addr,
     198                                        uint16_t port,
    194199                                        const char *called_name,
    195                                         const char *calling_name)
     200                                        int called_type,
     201                                        const char *calling_name,
     202                                        int calling_type)
    196203{
    197204        struct tevent_req *req, *subreq;
     
    207214        state->called_name =
    208215                (called_name != NULL) ? called_name : "*SMBSERVER";
     216        state->called_type =
     217                (called_type != -1) ? called_type : 0x20;
    209218        state->calling_name =
    210219                (calling_name != NULL) ? calling_name : global_myname();
     220        state->calling_type =
     221                (calling_type != -1) ? calling_type : 0x00;
    211222
    212223        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         */
    213247
    214248        state->req_445 = open_socket_out_send(state, ev, addr, 445, 5000);
     
    238272        if (state->sock != -1) {
    239273                close(state->sock);
     274                state->sock = -1;
    240275        }
    241276        return 0;
     
    257292        }
    258293        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);
    261298        if (tevent_req_nomem(state->req_139, req)) {
    262299                return;
     
    314351
    315352NTSTATUS smbsock_connect_recv(struct tevent_req *req, int *sock,
    316                           uint16_t *port)
     353                              uint16_t *ret_port)
    317354{
    318355        struct smbsock_connect_state *state = tevent_req_data(
     
    325362        *sock = state->sock;
    326363        state->sock = -1;
    327         if (port != NULL) {
    328                 *port = state->port;
     364        if (ret_port != NULL) {
     365                *ret_port = state->port;
    329366        }
    330367        return NT_STATUS_OK;
    331368}
    332369
    333 NTSTATUS smbsock_connect(const struct sockaddr_storage *addr,
    334                          const char *called_name, const char *calling_name,
    335                          int *pfd, uint16_t *port)
     370NTSTATUS 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)
    336374{
    337375        TALLOC_CTX *frame = talloc_stackframe();
     
    344382                goto fail;
    345383        }
    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);
    347387        if (req == NULL) {
    348388                goto fail;
    349389        }
     390        if ((sec_timeout != 0) &&
     391            !tevent_req_set_endtime(
     392                    req, ev, timeval_current_ofs(sec_timeout, 0))) {
     393                goto fail;
     394        }
    350395        if (!tevent_req_poll_ntstatus(req, ev, &status)) {
    351396                goto fail;
    352397        }
    353         status = smbsock_connect_recv(req, pfd, port);
     398        status = smbsock_connect_recv(req, pfd, ret_port);
    354399 fail:
    355400        TALLOC_FREE(frame);
     
    361406        const struct sockaddr_storage *addrs;
    362407        const char **called_names;
     408        int *called_types;
     409        const char **calling_names;
     410        int *calling_types;
    363411        size_t num_addrs;
     412        uint16_t port;
    364413
    365414        struct tevent_req **requests;
     
    368417
    369418        int fd;
    370         uint16_t port;
     419        uint16_t chosen_port;
    371420        size_t chosen_index;
    372421};
     
    381430                                            const struct sockaddr_storage *addrs,
    382431                                            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)
    384436{
    385437        struct tevent_req *req, *subreq;
     
    395447        state->num_addrs = num_addrs;
    396448        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;
    397453
    398454        if (num_addrs == 0) {
     
    459515        subreq = smbsock_connect_send(
    460516                state->requests, state->ev, &state->addrs[state->num_sent],
     517                state->port,
    461518                (state->called_names != NULL)
    462519                ? 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);
    464526        if (tevent_req_nomem(subreq, req)) {
    465527                return false;
     
    481543        NTSTATUS status;
    482544        int fd;
    483         uint16_t port;
     545        uint16_t chosen_port;
    484546        size_t i;
    485547        size_t chosen_index = 0;
     
    496558        }
    497559
    498         status = smbsock_connect_recv(subreq, &fd, &port);
     560        status = smbsock_connect_recv(subreq, &fd, &chosen_port);
    499561
    500562        TALLOC_FREE(subreq);
     
    507569                TALLOC_FREE(state->requests);
    508570                state->fd = fd;
    509                 state->port = port;
     571                state->chosen_port = chosen_port;
    510572                state->chosen_index = chosen_index;
    511573                tevent_req_done(req);
     
    529591
    530592NTSTATUS 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)
    532595{
    533596        struct smbsock_any_connect_state *state = tevent_req_data(
     
    542605                *chosen_index = state->chosen_index;
    543606        }
    544         if (port != NULL) {
    545                 *port = state->port;
     607        if (chosen_port != NULL) {
     608                *chosen_port = state->chosen_port;
    546609        }
    547610        return NT_STATUS_OK;
     
    549612
    550613NTSTATUS 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)
    553623{
    554624        TALLOC_CTX *frame = talloc_stackframe();
     
    561631                goto fail;
    562632        }
    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);
    565637        if (req == NULL) {
    566638                goto fail;
    567639        }
     640        if ((sec_timeout != 0) &&
     641            !tevent_req_set_endtime(
     642                    req, ev, timeval_current_ofs(sec_timeout, 0))) {
     643                goto fail;
     644        }
    568645        if (!tevent_req_poll_ntstatus(req, ev, &status)) {
    569646                goto fail;
    570647        }
    571         status = smbsock_any_connect_recv(req, pfd, chosen_index, port);
     648        status = smbsock_any_connect_recv(req, pfd, chosen_index, chosen_port);
    572649 fail:
    573650        TALLOC_FREE(frame);
Note: See TracChangeset for help on using the changeset viewer.