Ignore:
Timestamp:
Apr 9, 2010, 3:20:58 PM (15 years ago)
Author:
Silvan Scherrer
Message:

Samba 3.5.x: update to 3.5.2

Location:
vendor/current/source3/rpc_client
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • vendor/current/source3/rpc_client/cli_pipe.c

    r414 r427  
    30323032}
    30333033
     3034#define RPCCLI_DEFAULT_TIMEOUT 10000 /* 10 seconds. */
     3035
    30343036unsigned int rpccli_set_timeout(struct rpc_pipe_client *rpc_cli,
    30353037                                unsigned int timeout)
    30363038{
    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
     3057bool 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);
    30613068}
    30623069
     
    35633570}
    35643571
    3565 static int rpc_pipe_client_np_destructor(struct rpc_pipe_client *p)
    3566 {
     3572struct rpc_pipe_client_np_ref {
    35673573        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
     3577static 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);
    35733580        return 0;
    35743581}
     
    35933600        struct rpc_pipe_client *result;
    35943601        NTSTATUS status;
     3602        struct rpc_pipe_client_np_ref *np_ref;
    35953603
    35963604        /* sanity check to protect against crashes */
     
    36313639        result->transport->transport = NCACN_NP;
    36323640
    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);
    36353651
    36363652        *presult = result;
  • vendor/current/source3/rpc_client/cli_spoolss.c

    r414 r427  
    766766                                     uint32_t offered,
    767767                                     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);
    773778
    774779        status = rpccli_spoolss_GetPrinterData(cli, mem_ctx,
    775780                                               handle,
    776781                                               value_name,
    777                                                offered,
    778782                                               type,
    779783                                               data,
     784                                               offered,
    780785                                               &needed,
    781786                                               &werror);
     
    783788        if (W_ERROR_EQUAL(werror, WERR_MORE_DATA)) {
    784789                offered = needed;
     790                data = talloc_zero_array(mem_ctx, uint8_t, offered);
     791                W_ERROR_HAVE_NO_MEMORY(data);
    785792
    786793                status = rpccli_spoolss_GetPrinterData(cli, mem_ctx,
    787794                                                       handle,
    788795                                                       value_name,
    789                                                        offered,
    790796                                                       type,
    791797                                                       data,
     798                                                       offered,
    792799                                                       &needed,
    793800                                                       &werror);
    794801        }
     802
     803        *data_p = data;
     804        *needed_p = needed;
    795805
    796806        return werror;
  • vendor/current/source3/rpc_client/ndr.c

    r414 r427  
    184184        status = cli_do_rpc_ndr_recv(req, mem_ctx);
    185185
    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         }
    200186 fail:
    201187        TALLOC_FREE(frame);
  • vendor/current/source3/rpc_client/rpc_transport_np.c

    r414 r427  
    2929};
    3030
     31static 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
     50static 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
    3168static int rpc_transport_np_state_destructor(struct rpc_transport_np_state *s)
    3269{
    33         if (s->cli->fd == -1) {
     70        if (!rpc_np_is_connected(s)) {
    3471                DEBUG(10, ("socket was closed, no need to send close request.\n"));
    3572                return 0;
    3673        }
    37        
     74
     75        /* TODO: do not use a sync call with a destructor!!! */
    3876        if (!NT_STATUS_IS_OK(cli_close(s->cli, s->fnum))) {
    3977                DEBUG(1, ("rpc_transport_np_state_destructor: cli_close "
     
    4987
    5088struct rpc_np_write_state {
     89        struct rpc_transport_np_state *np_transport;
    5190        size_t size;
    5291        size_t written;
     
    64103        struct tevent_req *req, *subreq;
    65104        struct rpc_np_write_state *state;
     105        bool ok;
    66106
    67107        req = tevent_req_create(mem_ctx, &state, struct rpc_np_write_state);
     
    69109                return NULL;
    70110        }
     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;
    71119        state->size = size;
     120
    72121
    73122        subreq = cli_write_andx_send(mem_ctx, ev, np_transport->cli,
     
    93142        TALLOC_FREE(subreq);
    94143        if (!NT_STATUS_IS_OK(status)) {
     144                state->np_transport->cli = NULL;
    95145                tevent_req_nterror(req, status);
    96146                return;
     
    113163
    114164struct rpc_np_read_state {
     165        struct rpc_transport_np_state *np_transport;
    115166        uint8_t *data;
    116167        size_t size;
     
    129180        struct tevent_req *req, *subreq;
    130181        struct rpc_np_read_state *state;
     182        bool ok;
    131183
    132184        req = tevent_req_create(mem_ctx, &state, struct rpc_np_read_state);
     
    134186                return NULL;
    135187        }
     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;
    136196        state->data = data;
    137197        state->size = size;
     
    157217        NTSTATUS status;
    158218        uint8_t *rcvbuf;
     219
     220        /* We must free subreq in this function as there is
     221           a timer event attached to it. */
    159222
    160223        status = cli_read_andx_recv(subreq, &state->received, &rcvbuf);
     
    168231        if (!NT_STATUS_IS_OK(status)) {
    169232                TALLOC_FREE(subreq);
     233                state->np_transport->cli = NULL;
    170234                tevent_req_nterror(req, status);
    171235                return;
     
    174238        if (state->received > state->size) {
    175239                TALLOC_FREE(subreq);
     240                state->np_transport->cli = NULL;
    176241                tevent_req_nterror(req, NT_STATUS_INVALID_NETWORK_RESPONSE);
    177242                return;
    178243        }
    179244
     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
    180252        memcpy(state->data, rcvbuf, state->received);
     253        TALLOC_FREE(subreq);
    181254        tevent_req_done(req);
    182255}
     
    196269
    197270struct rpc_np_trans_state {
     271        struct rpc_transport_np_state *np_transport;
    198272        uint16_t setup[2];
     273        uint32_t max_rdata_len;
    199274        uint8_t *rdata;
    200275        uint32_t rdata_len;
     
    213288        struct tevent_req *req, *subreq;
    214289        struct rpc_np_trans_state *state;
     290        bool ok;
    215291
    216292        req = tevent_req_create(mem_ctx, &state, struct rpc_np_trans_state);
     
    218294                return NULL;
    219295        }
     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;
    220305
    221306        SSVAL(state->setup+0, 0, TRANSACT_DCERPCCMD);
     
    248333                                &state->rdata, &state->rdata_len);
    249334        TALLOC_FREE(subreq);
     335        if (NT_STATUS_EQUAL(status, NT_STATUS_BUFFER_TOO_SMALL)) {
     336                status = NT_STATUS_OK;
     337        }
    250338        if (!NT_STATUS_IS_OK(status)) {
     339                state->np_transport->cli = NULL;
    251340                tevent_req_nterror(req, status);
    252341                return;
    253342        }
     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
    254356        tevent_req_done(req);
    255357}
     
    284386        struct tevent_req *req, *subreq;
    285387        struct rpc_transport_np_init_state *state;
     388        bool ok;
    286389
    287390        req = tevent_req_create(mem_ctx, &state,
     
    289392        if (req == NULL) {
    290393                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);
    291400        }
    292401
     
    356465        state->transport->trans_send = rpc_np_trans_send;
    357466        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;
    358469
    359470        *presult = talloc_move(mem_ctx, &state->transport);
     
    403514        return state->cli;
    404515}
    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  
    420420}
    421421
     422static 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
     444static 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
     467static 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
    422485struct rpc_smbd_write_state {
    423         struct rpc_cli_transport *sub_transp;
     486        struct rpc_transport_smbd_state *transp;
    424487        ssize_t written;
    425488};
     
    436499        struct tevent_req *req, *subreq;
    437500        struct rpc_smbd_write_state *state;
     501        bool ok;
    438502
    439503        req = tevent_req_create(mem_ctx, &state, struct rpc_smbd_write_state);
     
    441505                return NULL;
    442506        }
    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;
    444515
    445516        subreq = transp->sub_transp->write_send(state, ev, data, size,
     
    469540        NTSTATUS status;
    470541
    471         status = state->sub_transp->write_recv(subreq, &state->written);
     542        status = state->transp->sub_transp->write_recv(subreq, &state->written);
    472543        TALLOC_FREE(subreq);
    473544        if (!NT_STATUS_IS_OK(status)) {
     545                rpc_smbd_disconnect(state->transp);
    474546                tevent_req_nterror(req, status);
    475547                return;
     
    492564
    493565struct rpc_smbd_read_state {
    494         struct rpc_cli_transport *sub_transp;
     566        struct rpc_transport_smbd_state *transp;
    495567        ssize_t received;
    496568};
     
    507579        struct tevent_req *req, *subreq;
    508580        struct rpc_smbd_read_state *state;
     581        bool ok;
    509582
    510583        req = tevent_req_create(mem_ctx, &state, struct rpc_smbd_read_state);
     
    512585                return NULL;
    513586        }
    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;
    515595
    516596        subreq = transp->sub_transp->read_send(state, ev, data, size,
     
    539619        NTSTATUS status;
    540620
    541         status = state->sub_transp->read_recv(subreq, &state->received);
     621        status = state->transp->sub_transp->read_recv(subreq, &state->received);
    542622        TALLOC_FREE(subreq);
    543623        if (!NT_STATUS_IS_OK(status)) {
     624                rpc_smbd_disconnect(state->transp);
    544625                tevent_req_nterror(req, status);
    545626                return;
     
    646727        state->transport->trans_send = NULL;
    647728        state->transport->trans_recv = NULL;
     729        state->transport->is_connected = rpc_smbd_is_connected;
     730        state->transport->set_timeout = rpc_smbd_set_timeout;
    648731
    649732        *presult = talloc_move(mem_ctx, &state->transport);
     
    683766        return status;
    684767}
    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  
    2828};
    2929
    30 static int rpc_transport_sock_state_destructor(struct rpc_transport_sock_state *s)
     30static void rpc_sock_disconnect(struct rpc_transport_sock_state *s)
    3131{
    3232        if (s->fd != -1) {
     
    3434                s->fd = -1;
    3535        }
     36}
     37
     38static int rpc_transport_sock_state_destructor(struct rpc_transport_sock_state *s)
     39{
     40        rpc_sock_disconnect(s);
    3641        return 0;
     42}
     43
     44static 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
     56static 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;
    3773}
    3874
     
    5995                return NULL;
    6096        }
    61         if (sock_transp->fd == -1) {
     97        if (!rpc_sock_is_connected(sock_transp)) {
    6298                tevent_req_nterror(req, NT_STATUS_CONNECTION_INVALID);
    6399                return tevent_req_post(req, ev);
     
    89125        int err;
    90126
     127        /* We must free subreq in this function as there is
     128          a timer event attached to it. */
     129
    91130        state->received = async_recv_recv(subreq, &err);
     131
    92132        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);
    97135                tevent_req_nterror(req, map_nt_error_from_unix(err));
    98136                return;
    99137        }
     138        TALLOC_FREE(subreq);
    100139        tevent_req_done(req);
    101140}
     
    136175                return NULL;
    137176        }
    138         if (sock_transp->fd == -1) {
     177        if (!rpc_sock_is_connected(sock_transp)) {
    139178                tevent_req_nterror(req, NT_STATUS_CONNECTION_INVALID);
    140179                return tevent_req_post(req, ev);
     
    166205        int err;
    167206
     207        /* We must free subreq in this function as there is
     208          a timer event attached to it. */
     209
    168210        state->sent = async_send_recv(subreq, &err);
     211
    169212        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);
    174215                tevent_req_nterror(req, map_nt_error_from_unix(err));
    175216                return;
    176217        }
     218        TALLOC_FREE(subreq);
    177219        tevent_req_done(req);
    178220}
     
    218260        result->read_send = rpc_sock_read_send;
    219261        result->read_recv = rpc_sock_read_recv;
     262        result->is_connected = rpc_sock_is_connected;
     263        result->set_timeout = rpc_sock_set_timeout;
    220264
    221265        *presult = result;
    222266        return NT_STATUS_OK;
    223267}
    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.