Ignore:
Timestamp:
Nov 14, 2012, 12:59:34 PM (13 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: update vendor to 3.6.0

Location:
vendor/current/source4/libcli
Files:
11 added
15 deleted
66 edited

Legend:

Unmodified
Added
Removed
  • vendor/current/source4/libcli/cliconnect.c

    r414 r740  
    3636                           struct resolve_context *resolve_ctx,
    3737                           struct smbcli_options *options,
    38                            struct smb_iconv_convenience *iconv_convenience,
    3938               const char *socket_options)
    4039{
     
    4746        if (sock == NULL) return false;
    4847       
    49         cli->transport = smbcli_transport_init(sock, cli, true, options,
    50                                                                                    iconv_convenience);
     48        cli->transport = smbcli_transport_init(sock, cli, true, options);
    5149        if (!cli->transport) {
    5250                return false;
     
    155153                                struct smbcli_options *options,
    156154                                struct smbcli_session_options *session_options,
    157                                 struct smb_iconv_convenience *iconv_convenience,
    158155                                struct gensec_settings *gensec_settings)
    159156{
     
    170167                                             options,
    171168                                             session_options,
    172                                                  iconv_convenience,
    173169                                                 gensec_settings);
    174170        if (!NT_STATUS_IS_OK(status)) {
     
    239235        char *p;
    240236
    241         *hostname = *sharename = NULL;
    242 
    243237        if (strncmp(unc_name, "\\\\", 2) &&
    244238            strncmp(unc_name, "//", 2)) {
    245239                return false;
    246240        }
     241
     242        *hostname = *sharename = NULL;
    247243
    248244        *hostname = talloc_strdup(mem_ctx, &unc_name[2]);
  • vendor/current/source4/libcli/clideltree.c

    r414 r740  
    4242        n = strdup(name);
    4343        n[strlen(n)-1] = 0;
    44         asprintf(&s, "%s%s", n, finfo->name);
     44        if (asprintf(&s, "%s%s", n, finfo->name) < 0) {
     45                free(n);
     46                return;
     47        }
    4548
    4649        if (finfo->attrib & FILE_ATTRIBUTE_READONLY) {
     
    5356        if (finfo->attrib & FILE_ATTRIBUTE_DIRECTORY) {
    5457                char *s2;
    55                 asprintf(&s2, "%s\\*", s);
     58                if (asprintf(&s2, "%s\\*", s) < 0) {
     59                        free(s);
     60                        free(n);
     61                        return;
     62                }
    5663                smbcli_unlink(dstate->tree, s2);
    5764                smbcli_list(dstate->tree, s2,
     
    110117        }
    111118
    112         asprintf(&mask, "%s\\*", dname);
     119        if (asprintf(&mask, "%s\\*", dname) < 0) {
     120                return -1;
     121        }
    113122        smbcli_unlink(dstate.tree, mask);
    114123        smbcli_list(dstate.tree, mask,
  • vendor/current/source4/libcli/clifile.c

    r414 r740  
    5656uint32_t unix_perms_to_wire(mode_t perms)
    5757{
    58         uint_t ret = 0;
     58        unsigned int ret = 0;
    5959
    6060        ret |= ((perms & S_IXOTH) ?  UNIX_X_OTH : 0);
     
    242242        open_parms.ntcreatex.level = RAW_OPEN_NTCREATEX;
    243243        open_parms.ntcreatex.in.flags = CreatFlags;
    244         open_parms.ntcreatex.in.root_fid = 0;
     244        open_parms.ntcreatex.in.root_fid.fnum = 0;
    245245        open_parms.ntcreatex.in.access_mask = DesiredAccess;
    246246        open_parms.ntcreatex.in.file_attr = FileAttributes;
     
    272272{
    273273        union smb_open open_parms;
    274         uint_t openfn=0;
    275         uint_t accessmode=0;
     274        unsigned int openfn=0;
     275        unsigned int accessmode=0;
    276276        TALLOC_CTX *mem_ctx;
    277277        NTSTATUS status;
  • vendor/current/source4/libcli/composite/composite.c

    r414 r740  
    2727#include "libcli/smb2/smb2.h"
    2828#include "libcli/composite/composite.h"
    29 #include "lib/messaging/irpc.h"
    30 #include "librpc/rpc/dcerpc.h"
    3129#include "../libcli/nbt/libnbt.h"
    3230
     
    164162}
    165163
    166 _PUBLIC_ void composite_continue_rpc(struct composite_context *ctx,
    167                                      struct rpc_request *new_req,
    168                                      void (*continuation)(struct rpc_request *),
    169                                      void *private_data)
    170 {
    171         if (composite_nomem(new_req, ctx)) return;
    172         new_req->async.callback = continuation;
    173         new_req->async.private_data = private_data;
    174 }
    175 
    176 _PUBLIC_ void composite_continue_irpc(struct composite_context *ctx,
    177                                       struct irpc_request *new_req,
    178                                       void (*continuation)(struct irpc_request *),
    179                                       void *private_data)
    180 {
    181         if (composite_nomem(new_req, ctx)) return;
    182         new_req->async.fn = continuation;
    183         new_req->async.private_data = private_data;
    184 }
    185 
    186164_PUBLIC_ void composite_continue_smb(struct composite_context *ctx,
    187165                                     struct smbcli_request *new_req,
  • vendor/current/source4/libcli/composite/composite.h

    r414 r740  
    6868};
    6969
    70 struct irpc_request;
    7170struct smbcli_request;
    7271struct smb2_request;
    73 struct rpc_request;
    7472struct nbt_name_request;
    7573
     
    8078                                 void (*continuation)(struct composite_context *),
    8179                                 void *private_data);
    82 void composite_continue_rpc(struct composite_context *ctx,
    83                                      struct rpc_request *new_req,
    84                                      void (*continuation)(struct rpc_request *),
    85                                      void *private_data);
    86 void composite_continue_irpc(struct composite_context *ctx,
    87                                       struct irpc_request *new_req,
    88                                       void (*continuation)(struct irpc_request *),
    89                                       void *private_data);
    9080void composite_continue_smb(struct composite_context *ctx,
    9181                                     struct smbcli_request *new_req,
  • vendor/current/source4/libcli/dgram/browse.c

    r414 r740  
    3939        TALLOC_CTX *tmp_ctx = talloc_new(dgmsock);
    4040
    41         ndr_err = ndr_push_struct_blob(&blob, tmp_ctx, dgmsock->iconv_convenience, request,
     41        ndr_err = ndr_push_struct_blob(&blob, tmp_ctx, request,
    4242                                      (ndr_push_flags_fn_t)ndr_push_nbt_browse_packet);
    4343        if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
     
    6767        struct socket_address *dest;
    6868
    69         ndr_err = ndr_push_struct_blob(&blob, tmp_ctx, dgmsock->iconv_convenience, reply,
     69        ndr_err = ndr_push_struct_blob(&blob, tmp_ctx, reply,
    7070                                      (ndr_push_flags_fn_t)ndr_push_nbt_browse_packet);
    7171        if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
     
    100100        enum ndr_err_code ndr_err;
    101101
    102         ndr_err = ndr_pull_struct_blob(&data, mem_ctx, dgmslot->dgmsock->iconv_convenience, pkt,
     102        ndr_err = ndr_pull_struct_blob(&data, mem_ctx, pkt,
    103103                                      (ndr_pull_flags_fn_t)ndr_pull_nbt_browse_packet);
    104104        if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
  • vendor/current/source4/libcli/dgram/dgramsocket.c

    r414 r740  
    6262        blob.length = nread;
    6363
    64         DEBUG(2,("Received dgram packet of length %d from %s:%d\n",
     64        DEBUG(5,("Received dgram packet of length %d from %s:%d\n",
    6565                 (int)blob.length, src->addr, src->port));
    6666
     
    7272
    7373        /* parse the request */
    74         ndr_err = ndr_pull_struct_blob(&blob, packet, dgmsock->iconv_convenience, packet,
     74        ndr_err = ndr_pull_struct_blob(&blob, packet, packet,
    7575                                      (ndr_pull_flags_fn_t)ndr_pull_nbt_dgram_packet);
    7676        if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
     
    158158*/
    159159struct nbt_dgram_socket *nbt_dgram_socket_init(TALLOC_CTX *mem_ctx,
    160                                               struct tevent_context *event_ctx,
    161                                               struct smb_iconv_convenience *iconv_convenience)
     160                                              struct tevent_context *event_ctx)
    162161{
    163162        struct nbt_dgram_socket *dgmsock;
     
    184183        dgmsock->incoming.handler = NULL;
    185184        dgmsock->mailslot_handlers = NULL;
    186         dgmsock->iconv_convenience = iconv_convenience;
    187185       
    188186        return dgmsock;
     
    227225        if (talloc_reference(req, dest) == NULL) goto failed;
    228226
    229         ndr_err = ndr_push_struct_blob(&req->encoded, req, dgmsock->iconv_convenience, packet,
     227        ndr_err = ndr_push_struct_blob(&req->encoded, req, packet,
    230228                                      (ndr_push_flags_fn_t)ndr_push_nbt_dgram_packet);
    231229        if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
  • vendor/current/source4/libcli/dgram/libdgram.h

    r414 r740  
    2020*/
    2121
    22 #include "../libcli/netlogon.h"
     22#include "../libcli/netlogon/netlogon.h"
    2323
    2424/*
     
    4141        struct socket_context *sock;
    4242        struct tevent_context *event_ctx;
    43         struct smb_iconv_convenience *iconv_convenience;
    4443
    4544        /* the fd event */
     
    9493                                    void *private_data);
    9594struct nbt_dgram_socket *nbt_dgram_socket_init(TALLOC_CTX *mem_ctx,
    96                                                struct tevent_context *event_ctx,
    97                                                struct smb_iconv_convenience *);
     95                                               struct tevent_context *event_ctx);
    9896
    9997const char *dgram_mailslot_name(struct nbt_dgram_packet *packet);
  • vendor/current/source4/libcli/dgram/mailslot.c

    r414 r740  
    130130                if (dgram_mailslot_find(dgmsock, name)) {
    131131                        talloc_free(name);
    132                         return NULL;
     132                        continue;
    133133                }
    134134                dgmslot = dgram_mailslot_listen(dgmsock, name, handler, private_data);
  • vendor/current/source4/libcli/dgram/netlogon.c

    r414 r740  
    4141        TALLOC_CTX *tmp_ctx = talloc_new(dgmsock);
    4242
    43         ndr_err = ndr_push_struct_blob(&blob, tmp_ctx,
    44                                        dgmsock->iconv_convenience,
    45                                        request,
     43        ndr_err = ndr_push_struct_blob(&blob, tmp_ctx, request,
    4644                                      (ndr_push_flags_fn_t)ndr_push_nbt_netlogon_packet);
    4745        if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
     
    7573        struct socket_address *dest;
    7674
    77         status = push_nbt_netlogon_response(&blob, tmp_ctx, dgmsock->iconv_convenience,
    78                                             reply);
     75        status = push_nbt_netlogon_response(&blob, tmp_ctx, reply);
    7976        if (!NT_STATUS_IS_OK(status)) {
    8077                return status;
     
    111108        enum ndr_err_code ndr_err;
    112109
    113         ndr_err = ndr_pull_struct_blob(&data, mem_ctx, dgmslot->dgmsock->iconv_convenience, netlogon,
    114                                       (ndr_pull_flags_fn_t)ndr_pull_nbt_netlogon_packet);
     110        ndr_err = ndr_pull_struct_blob(&data, mem_ctx, netlogon,
     111           (ndr_pull_flags_fn_t)ndr_pull_nbt_netlogon_packet);
    115112        if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
    116113                NTSTATUS status = ndr_map_error2ntstatus(ndr_err);
     
    136133        DATA_BLOB data = dgram_mailslot_data(dgram);
    137134       
    138         status = pull_nbt_netlogon_response(&data, mem_ctx, dgmslot->dgmsock->iconv_convenience, netlogon);
     135        status = pull_nbt_netlogon_response(&data, mem_ctx, netlogon);
    139136        if (!NT_STATUS_IS_OK(status)) {
    140137                return status;
  • vendor/current/source4/libcli/ldap/ldap_bind.c

    r414 r740  
    2323
    2424#include "includes.h"
    25 #include "libcli/ldap/ldap.h"
     25#include "libcli/ldap/libcli_ldap.h"
    2626#include "libcli/ldap/ldap_proto.h"
    2727#include "libcli/ldap/ldap_client.h"
     
    226226        status = gensec_client_start(conn, &conn->gensec,
    227227                                     conn->event.event_ctx,
    228                                      lp_gensec_settings(conn, lp_ctx));
     228                                     lpcfg_gensec_settings(conn, lp_ctx));
    229229        if (!NT_STATUS_IS_OK(status)) {
    230230                DEBUG(0, ("Failed to start GENSEC engine (%s)\n", nt_errstr(status)));
     
    353353                        goto failed;
    354354                }
    355                 talloc_steal(tmp_ctx, req);
     355                talloc_reparent(conn, tmp_ctx, req);
    356356
    357357                status = ldap_result_n(req, 0, &response);
  • vendor/current/source4/libcli/ldap/ldap_client.c

    r414 r740  
    2828#include "../lib/util/asn1.h"
    2929#include "../lib/util/dlinklist.h"
    30 #include "libcli/ldap/ldap.h"
     30#include "libcli/ldap/libcli_ldap.h"
    3131#include "libcli/ldap/ldap_proto.h"
    3232#include "libcli/ldap/ldap_client.h"
     
    339339                 * local host name as the target for gensec's
    340340                 * DIGEST-MD5 mechanism */
    341                 conn->host = talloc_asprintf(conn, "%s.%s", lp_netbios_name(conn->lp_ctx),  lp_realm(conn->lp_ctx));
     341                conn->host = talloc_asprintf(conn, "%s.%s",
     342                                             lpcfg_netbios_name(conn->lp_ctx),
     343                                             lpcfg_dnsdomain(conn->lp_ctx));
    342344                if (composite_nomem(conn->host, state->ctx)) {
    343345                        return result;
     
    374376               
    375377                ctx = socket_connect_multi_send(state, conn->host, 1, &conn->port,
    376                                                 lp_resolve_context(conn->lp_ctx), conn->event.event_ctx);
     378                                                lpcfg_resolve_context(conn->lp_ctx), conn->event.event_ctx);
    377379                if (ctx == NULL) goto failed;
    378380
     
    404406        if (conn->ldaps) {
    405407                struct socket_context *tls_socket;
    406                 struct socket_context *tmp_socket;
    407                 char *cafile = lp_tls_cafile(conn->sock, conn->lp_ctx);
     408                char *cafile = lpcfg_tls_cafile(conn->sock, conn->lp_ctx);
    408409
    409410                if (!cafile || !*cafile) {
     
    499500                conn->reconnect.max_retries = max_retries;
    500501                conn->reconnect.retries = 0;
    501                 conn->reconnect.previous = time(NULL);
     502                conn->reconnect.previous = time_mono(NULL);
    502503        }
    503504}
     
    507508{
    508509        NTSTATUS status;
    509         time_t now = time(NULL);
     510        time_t now = time_mono(NULL);
    510511
    511512        /* do we have set up reconnect ? */
     
    565566
    566567/*
    567   called on completion of a one-way ldap request
    568 */
    569 static void ldap_request_complete(struct tevent_context *ev, struct tevent_timer *te,
    570                                   struct timeval t, void *private_data)
     568  called on completion of a failed ldap request
     569*/
     570static void ldap_request_failed_complete(struct tevent_context *ev, struct tevent_timer *te,
     571                                      struct timeval t, void *private_data)
    571572{
    572573        struct ldap_request *req = talloc_get_type(private_data, struct ldap_request);
     
    577578
    578579/*
     580  called on completion of a one-way ldap request
     581*/
     582static void ldap_request_oneway_complete(void *private_data)
     583{
     584        struct ldap_request *req = talloc_get_type(private_data, struct ldap_request);
     585        if (req->state == LDAP_REQUEST_PENDING) {
     586                DLIST_REMOVE(req->conn->pending, req);
     587        }
     588        req->state = LDAP_REQUEST_DONE;
     589        if (req->async.fn) {
     590                req->async.fn(req);
     591        }
     592}
     593/*
    579594  send a ldap message - async interface
    580595*/
     
    584599        struct ldap_request *req;
    585600        NTSTATUS status = NT_STATUS_UNSUCCESSFUL;
     601        packet_send_callback_fn_t send_callback = NULL;
    586602
    587603        req = talloc_zero(conn, struct ldap_request);
     
    613629        }
    614630
    615         status = packet_send(conn->packet, req->data);
     631        if (req->type == LDAP_TAG_AbandonRequest ||
     632            req->type == LDAP_TAG_UnbindRequest) {
     633                send_callback = ldap_request_oneway_complete;
     634        }
     635
     636        status = packet_send_callback(conn->packet, req->data,
     637                                      send_callback, req);
    616638        if (!NT_STATUS_IS_OK(status)) {
    617639                goto failed;
    618         }
    619 
    620         /* some requests don't expect a reply, so don't add those to the
    621            pending queue */
    622         if (req->type == LDAP_TAG_AbandonRequest ||
    623             req->type == LDAP_TAG_UnbindRequest) {
    624                 req->status = NT_STATUS_OK;
    625                 req->state = LDAP_REQUEST_DONE;
    626                 /* we can't call the async callback now, as it isn't setup, so
    627                    call it as next event */
    628                 tevent_add_timer(conn->event.event_ctx, req, timeval_zero(),
    629                                  ldap_request_complete, req);
    630                 return req;
    631640        }
    632641
     
    645654        req->state = LDAP_REQUEST_ERROR;
    646655        tevent_add_timer(conn->event.event_ctx, req, timeval_zero(),
    647                          ldap_request_complete, req);
     656                         ldap_request_failed_complete, req);
    648657
    649658        return req;
  • vendor/current/source4/libcli/ldap/ldap_client.h

    r414 r740  
    2121
    2222
    23 #include "libcli/ldap/ldap.h"
     23#include "libcli/ldap/libcli_ldap.h"
    2424
    2525enum ldap_request_state { LDAP_REQUEST_SEND=1, LDAP_REQUEST_PENDING=2, LDAP_REQUEST_DONE=3, LDAP_REQUEST_ERROR=4 };
  • vendor/current/source4/libcli/ldap/ldap_controls.c

    r414 r740  
    2222#include "includes.h"
    2323#include "../lib/util/asn1.h"
    24 #include "libcli/ldap/ldap.h"
    25 #include "lib/ldb/include/ldb.h"
     24#include "libcli/ldap/libcli_ldap.h"
    2625#include "libcli/ldap/ldap_proto.h"
    2726#include "dsdb/samdb/samdb.h"
     
    215214        }
    216215
    217         if (!asn1_read_Integer(data, &(lsdfc->secinfo_flags))) {
     216        if (!asn1_read_Integer(data, (int *) &(lsdfc->secinfo_flags))) {
    218217                return false;
    219218        }
     
    249248        }
    250249
    251         if (!asn1_read_Integer(data, &(lsoc->search_options))) {
     250        if (!asn1_read_Integer(data, (int *) &(lsoc->search_options))) {
    252251                return false;
    253252        }
     
    424423
    425424        *out = lac;
    426 
    427         return true;
    428 }
    429 
    430 static bool decode_domain_scope_request(void *mem_ctx, DATA_BLOB in, void *_out)
    431 {
    432         if (in.length != 0) {
    433                 return false;
    434         }
    435 
    436         return true;
    437 }
    438 
    439 static bool decode_notification_request(void *mem_ctx, DATA_BLOB in, void *_out)
    440 {
    441         if (in.length != 0) {
    442                 return false;
    443         }
    444 
    445         return true;
    446 }
    447 
    448 static bool decode_show_deleted_request(void *mem_ctx, DATA_BLOB in, void *_out)
    449 {
    450         if (in.length != 0) {
    451                 return false;
    452         }
    453 
    454         return true;
    455 }
    456 
    457 static bool decode_show_recycled_request(void *mem_ctx, DATA_BLOB in, void *_out)
    458 {
    459         if (in.length != 0) {
    460                 return false;
    461         }
    462 
    463         return true;
    464 }
    465 
    466 static bool decode_show_deactivated_link_request(void *mem_ctx, DATA_BLOB in, void *_out)
    467 {
    468         if (in.length != 0) {
    469                 return false;
    470         }
    471 
    472         return true;
    473 }
    474 
    475 static bool decode_permissive_modify_request(void *mem_ctx, DATA_BLOB in, void *_out)
    476 {
    477         if (in.length != 0) {
    478                 return false;
    479         }
    480 
    481         return true;
    482 }
    483 
    484 static bool decode_manageDSAIT_request(void *mem_ctx, DATA_BLOB in, void *_out)
    485 {
    486         if (in.length != 0) {
    487                 return false;
    488         }
    489425
    490426        return true;
     
    947883        talloc_free(data);
    948884
    949         return true;
    950 }
    951 
    952 static bool encode_domain_scope_request(void *mem_ctx, void *in, DATA_BLOB *out)
    953 {
    954         if (in) {
    955                 return false;
    956         }
    957 
    958         *out = data_blob(NULL, 0);
    959         return true;
    960 }
    961 
    962 static bool encode_notification_request(void *mem_ctx, void *in, DATA_BLOB *out)
    963 {
    964         if (in) {
    965                 return false;
    966         }
    967 
    968         *out = data_blob(NULL, 0);
    969         return true;
    970 }
    971 
    972 static bool encode_show_deleted_request(void *mem_ctx, void *in, DATA_BLOB *out)
    973 {
    974         if (in) {
    975                 return false;
    976         }
    977 
    978         *out = data_blob(NULL, 0);
    979         return true;
    980 }
    981 
    982 static bool encode_show_recycled_request(void *mem_ctx, void *in, DATA_BLOB *out)
    983 {
    984         if (in) {
    985                 return false;
    986         }
    987 
    988         *out = data_blob(NULL, 0);
    989         return true;
    990 }
    991 
    992 static bool encode_show_deactivated_link_request(void *mem_ctx, void *in, DATA_BLOB *out)
    993 {
    994         if (in) {
    995                 return false;
    996         }
    997 
    998         *out = data_blob(NULL, 0);
    999         return true;
    1000 }
    1001 
    1002 static bool encode_permissive_modify_request(void *mem_ctx, void *in, DATA_BLOB *out)
    1003 {
    1004         if (in) {
    1005                 return false;
    1006         }
    1007 
    1008         *out = data_blob(NULL, 0);
    1009         return true;
    1010 }
    1011 
    1012 static bool encode_manageDSAIT_request(void *mem_ctx, void *in, DATA_BLOB *out)
    1013 {
    1014         if (in) {
    1015                 return false;
    1016         }
    1017 
    1018         *out = data_blob(NULL, 0);
    1019885        return true;
    1020886}
     
    12521118}
    12531119
     1120static bool encode_flag_request(void *mem_ctx, void *in, DATA_BLOB *out)
     1121{
     1122        if (in) {
     1123                return false;
     1124        }
     1125
     1126        *out = data_blob(NULL, 0);
     1127        return true;
     1128}
     1129
     1130static bool decode_flag_request(void *mem_ctx, DATA_BLOB in, void *_out)
     1131{
     1132        if (in.length != 0) {
     1133                return false;
     1134        }
     1135
     1136        return true;
     1137}
     1138
    12541139static const struct ldap_control_handler ldap_known_controls[] = {
    1255         { "1.2.840.113556.1.4.319", decode_paged_results_request, encode_paged_results_request },
    1256         { "1.2.840.113556.1.4.529", decode_extended_dn_request, encode_extended_dn_request },
    1257         { "1.2.840.113556.1.4.473", decode_server_sort_request, encode_server_sort_request },
    1258         { "1.2.840.113556.1.4.474", decode_server_sort_response, encode_server_sort_response },
    1259         { "1.2.840.113556.1.4.1504", decode_asq_control, encode_asq_control },
    1260         { "1.2.840.113556.1.4.841", decode_dirsync_request, encode_dirsync_request },
    1261         { "1.2.840.113556.1.4.528", decode_notification_request, encode_notification_request },
    1262         { "1.2.840.113556.1.4.417", decode_show_deleted_request, encode_show_deleted_request },
    1263         { "1.2.840.113556.1.4.2064", decode_show_recycled_request, encode_show_recycled_request },
    1264         { "1.2.840.113556.1.4.2065", decode_show_deactivated_link_request, encode_show_deactivated_link_request },
    1265         { "1.2.840.113556.1.4.1413", decode_permissive_modify_request, encode_permissive_modify_request },
    1266         { "1.2.840.113556.1.4.801", decode_sd_flags_request, encode_sd_flags_request },
    1267         { "1.2.840.113556.1.4.1339", decode_domain_scope_request, encode_domain_scope_request },
    1268         { "1.2.840.113556.1.4.1340", decode_search_options_request, encode_search_options_request },
    1269         { "2.16.840.1.113730.3.4.2", decode_manageDSAIT_request, encode_manageDSAIT_request },
    1270         { "2.16.840.1.113730.3.4.9", decode_vlv_request, encode_vlv_request },
    1271         { "2.16.840.1.113730.3.4.10", decode_vlv_response, encode_vlv_response },
     1140        { LDB_CONTROL_PAGED_RESULTS_OID, decode_paged_results_request, encode_paged_results_request },
     1141        { LDB_CONTROL_SD_FLAGS_OID, decode_sd_flags_request, encode_sd_flags_request },
     1142        { LDB_CONTROL_DOMAIN_SCOPE_OID, decode_flag_request, encode_flag_request },
     1143        { LDB_CONTROL_SEARCH_OPTIONS_OID, decode_search_options_request, encode_search_options_request },
     1144        { LDB_CONTROL_NOTIFICATION_OID, decode_flag_request, encode_flag_request },
     1145        { LDB_CONTROL_TREE_DELETE_OID, decode_flag_request, encode_flag_request },
     1146        { LDB_CONTROL_SHOW_DELETED_OID, decode_flag_request, encode_flag_request },
     1147        { LDB_CONTROL_SHOW_RECYCLED_OID, decode_flag_request, encode_flag_request },
     1148        { LDB_CONTROL_SHOW_DEACTIVATED_LINK_OID, decode_flag_request, encode_flag_request },
     1149        { LDB_CONTROL_EXTENDED_DN_OID, decode_extended_dn_request, encode_extended_dn_request },
     1150        { LDB_CONTROL_SERVER_SORT_OID, decode_server_sort_request, encode_server_sort_request },
     1151        { LDB_CONTROL_SORT_RESP_OID, decode_server_sort_response, encode_server_sort_response },
     1152        { LDB_CONTROL_ASQ_OID, decode_asq_control, encode_asq_control },
     1153        { LDB_CONTROL_DIRSYNC_OID, decode_dirsync_request, encode_dirsync_request },
     1154        { LDB_CONTROL_VLV_REQ_OID, decode_vlv_request, encode_vlv_request },
     1155        { LDB_CONTROL_VLV_RESP_OID, decode_vlv_response, encode_vlv_response },
     1156        { LDB_CONTROL_PERMISSIVE_MODIFY_OID, decode_flag_request, encode_flag_request },
     1157        { LDB_CONTROL_SERVER_LAZY_COMMIT, decode_flag_request, encode_flag_request },
     1158        { LDB_CONTROL_RODC_DCPROMO_OID, decode_flag_request, encode_flag_request },
     1159        { LDB_CONTROL_RELAX_OID, decode_flag_request, encode_flag_request },
     1160        { DSDB_OPENLDAP_DEREFERENCE_CONTROL, decode_openldap_dereference, encode_openldap_dereference },
     1161
    12721162/* DSDB_CONTROL_CURRENT_PARTITION_OID is internal only, and has no network representation */
    1273         { "1.3.6.1.4.1.7165.4.3.2", NULL, NULL },
     1163        { DSDB_CONTROL_CURRENT_PARTITION_OID, NULL, NULL },
     1164/* DSDB_CONTROL_REPLICATED_UPDATE_OID is internal only, and has no network representation */
     1165        { DSDB_CONTROL_REPLICATED_UPDATE_OID, NULL, NULL },
     1166/* DSDB_CONTROL_DN_STORAGE_FORMAT_OID is internal only, and has no network representation */
     1167        { DSDB_CONTROL_DN_STORAGE_FORMAT_OID, NULL, NULL },
     1168/* LDB_CONTROL_RECALCULATE_SD_OID is internal only, and has no network representation */
     1169        { LDB_CONTROL_RECALCULATE_SD_OID, NULL, NULL },
     1170/* LDB_CONTROL_REVEAL_INTERNALS is internal only, and has no network representation */
     1171        { LDB_CONTROL_REVEAL_INTERNALS, NULL, NULL },
     1172/* LDB_CONTROL_AS_SYSTEM_OID is internal only, and has no network representation */
     1173        { LDB_CONTROL_AS_SYSTEM_OID, NULL, NULL },
     1174/* DSDB_CONTROL_PASSWORD_CHANGE_STATUS_OID is internal only, and has no network representation */
     1175        { DSDB_CONTROL_PASSWORD_CHANGE_STATUS_OID, NULL, NULL },
     1176/* DSDB_CONTROL_PASSWORD_HASH_VALUES_OID is internal only, and has no network representation */
     1177        { DSDB_CONTROL_PASSWORD_HASH_VALUES_OID, NULL, NULL },
     1178/* DSDB_CONTROL_PASSWORD_CHANGE_OID is internal only, and has no network representation */
     1179        { DSDB_CONTROL_PASSWORD_CHANGE_OID, NULL, NULL },
     1180/* DSDB_CONTROL_APPLY_LINKS is internal only, and has no network representation */
     1181        { DSDB_CONTROL_APPLY_LINKS, NULL, NULL },
     1182/* DSDB_CONTROL_BYPASS_PASSWORD_HASH_OID is internal only, and has an empty network representation */
     1183        { DSDB_CONTROL_BYPASS_PASSWORD_HASH_OID, decode_flag_request, encode_flag_request },
     1184/* LDB_CONTROL_BYPASS_OPERATIONAL_OID is internal only, and has no network representation */
     1185        { LDB_CONTROL_BYPASS_OPERATIONAL_OID, NULL, NULL },
     1186/* DSDB_CONTROL_CHANGEREPLMETADATA_OID is internal only, and has no network representation */
     1187        { DSDB_CONTROL_CHANGEREPLMETADATA_OID, NULL, NULL },
     1188/* LDB_CONTROL_PROVISION_OID is internal only, and has no network representation */
     1189        { LDB_CONTROL_PROVISION_OID, NULL, NULL },
    12741190/* DSDB_EXTENDED_REPLICATED_OBJECTS_OID is internal only, and has no network representation */
    1275         { "1.3.6.1.4.1.7165.4.4.1", NULL, NULL },
    1276         { DSDB_OPENLDAP_DEREFERENCE_CONTROL, decode_openldap_dereference, encode_openldap_dereference},
     1191        { DSDB_EXTENDED_REPLICATED_OBJECTS_OID, NULL, NULL },
     1192/* DSDB_EXTENDED_SCHEMA_UPDATE_NOW_OID is internal only, and has no network representation */
     1193        { DSDB_EXTENDED_SCHEMA_UPDATE_NOW_OID, NULL, NULL },
     1194/* DSDB_EXTENDED_ALLOCATE_RID_POOL is internal only, and has no network representation */
     1195        { DSDB_EXTENDED_ALLOCATE_RID_POOL, NULL, NULL },
    12771196        { NULL, NULL, NULL }
    12781197};
  • vendor/current/source4/libcli/ldap/ldap_ildap.c

    r414 r740  
    2222
    2323#include "includes.h"
    24 #include "libcli/ldap/ldap.h"
     24#include "libcli/ldap/libcli_ldap.h"
    2525#include "libcli/ldap/ldap_client.h"
    2626
     
    7474
    7575        req = ldap_request_send(conn, msg);
    76         talloc_steal(msg, req);
     76        talloc_reparent(conn, msg, req);
    7777       
    7878        for (i=n=0;true;i++) {
  • vendor/current/source4/libcli/rap/rap.h

    r414 r740  
    1 /* 
     1/*
    22   Unix SMB/CIFS implementation.
    3    RAP operations
     3   RAP client
    44   Copyright (C) Volker Lendecke 2004
    5    
     5   Copyright (C) Tim Potter 2005
     6   Copyright (C) Jelmer Vernooij 2007
     7   Copyright (C) Guenther Deschner 2010
     8
    69   This program is free software; you can redistribute it and/or modify
    710   it under the terms of the GNU General Public License as published by
    811   the Free Software Foundation; either version 3 of the License, or
    912   (at your option) any later version.
    10    
     13
    1114   This program is distributed in the hope that it will be useful,
    1215   but WITHOUT ANY WARRANTY; without even the implied warranty of
    1316   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1417   GNU General Public License for more details.
    15    
     18
    1619   You should have received a copy of the GNU General Public License
    1720   along with this program.  If not, see <http://www.gnu.org/licenses/>.
    1821*/
    1922
    20 #define RAP_WshareEnum                          0
    21 #define RAP_WshareGetInfo                       1
    22 #define RAP_WshareSetInfo                       2
    23 #define RAP_WshareAdd                           3
    24 #define RAP_WshareDel                           4
    25 #define RAP_NetShareCheck                       5
    26 #define RAP_WsessionEnum                        6
    27 #define RAP_WsessionGetInfo                     7
    28 #define RAP_WsessionDel                         8
    29 #define RAP_WconnectionEnum                     9
    30 #define RAP_WfileEnum                           10
    31 #define RAP_WfileGetInfo                        11
    32 #define RAP_WfileClose                          12
    33 #define RAP_WserverGetInfo                      13
    34 #define RAP_WserverSetInfo                      14
    35 #define RAP_WserverDiskEnum                     15
    36 #define RAP_WserverAdminCommand                 16
    37 #define RAP_NetAuditOpen                        17
    38 #define RAP_WauditClear                         18
    39 #define RAP_NetErrorLogOpen                     19
    40 #define RAP_WerrorLogClear                      20
    41 #define RAP_NetCharDevEnum                      21
    42 #define RAP_NetCharDevGetInfo                   22
    43 #define RAP_WCharDevControl                     23
    44 #define RAP_NetCharDevQEnum                     24
    45 #define RAP_NetCharDevQGetInfo                  25
    46 #define RAP_WCharDevQSetInfo                    26
    47 #define RAP_WCharDevQPurge                      27
    48 #define RAP_WCharDevQPurgeSelf                  28
    49 #define RAP_WMessageNameEnum                    29
    50 #define RAP_WMessageNameGetInfo                 30
    51 #define RAP_WMessageNameAdd                     31
    52 #define RAP_WMessageNameDel                     32
    53 #define RAP_WMessageNameFwd                     33
    54 #define RAP_WMessageNameUnFwd                   34
    55 #define RAP_WMessageBufferSend                  35
    56 #define RAP_WMessageFileSend                    36
    57 #define RAP_WMessageLogFileSet                  37
    58 #define RAP_WMessageLogFileGet                  38
    59 #define RAP_WServiceEnum                        39
    60 #define RAP_WServiceInstall                     40
    61 #define RAP_WServiceControl                     41
    62 #define RAP_WAccessEnum                         42
    63 #define RAP_WAccessGetInfo                      43
    64 #define RAP_WAccessSetInfo                      44
    65 #define RAP_WAccessAdd                          45
    66 #define RAP_WAccessDel                          46
    67 #define RAP_WGroupEnum                          47
    68 #define RAP_WGroupAdd                           48
    69 #define RAP_WGroupDel                           49
    70 #define RAP_WGroupAddUser                       50
    71 #define RAP_WGroupDelUser                       51
    72 #define RAP_WGroupGetUsers                      52
    73 #define RAP_WUserEnum                           53
    74 #define RAP_WUserAdd                            54
    75 #define RAP_WUserDel                            55
    76 #define RAP_WUserGetInfo                        56
    77 #define RAP_WUserSetInfo                        57
    78 #define RAP_WUserPasswordSet                    58
    79 #define RAP_WUserGetGroups                      59
    80 #define RAP_WWkstaSetUID                        62
    81 #define RAP_WWkstaGetInfo                       63
    82 #define RAP_WWkstaSetInfo                       64
    83 #define RAP_WUseEnum                            65
    84 #define RAP_WUseAdd                             66
    85 #define RAP_WUseDel                             67
    86 #define RAP_WUseGetInfo                         68
    87 #define RAP_WPrintQEnum                         69
    88 #define RAP_WPrintQGetInfo                      70
    89 #define RAP_WPrintQSetInfo                      71
    90 #define RAP_WPrintQAdd                          72
    91 #define RAP_WPrintQDel                          73
    92 #define RAP_WPrintQPause                        74
    93 #define RAP_WPrintQContinue                     75
    94 #define RAP_WPrintJobEnum                       76
    95 #define RAP_WPrintJobGetInfo                    77
    96 #define RAP_WPrintJobSetInfo_OLD                78
    97 #define RAP_WPrintJobDel                        81
    98 #define RAP_WPrintJobPause                      82
    99 #define RAP_WPrintJobContinue                   83
    100 #define RAP_WPrintDestEnum                      84
    101 #define RAP_WPrintDestGetInfo                   85
    102 #define RAP_WPrintDestControl                   86
    103 #define RAP_WProfileSave                        87
    104 #define RAP_WProfileLoad                        88
    105 #define RAP_WStatisticsGet                      89
    106 #define RAP_WStatisticsClear                    90
    107 #define RAP_NetRemoteTOD                        91
    108 #define RAP_WNetBiosEnum                        92
    109 #define RAP_WNetBiosGetInfo                     93
    110 #define RAP_NetServerEnum                       94
    111 #define RAP_I_NetServerEnum                     95
    112 #define RAP_WServiceGetInfo                     96
    113 #define RAP_WPrintQPurge                        103
    114 #define RAP_NetServerEnum2                      104
    115 #define RAP_WAccessGetUserPerms                 105
    116 #define RAP_WGroupGetInfo                       106
    117 #define RAP_WGroupSetInfo                       107
    118 #define RAP_WGroupSetUsers                      108
    119 #define RAP_WUserSetGroups                      109
    120 #define RAP_WUserModalsGet                      110
    121 #define RAP_WUserModalsSet                      111
    122 #define RAP_WFileEnum2                          112
    123 #define RAP_WUserAdd2                           113
    124 #define RAP_WUserSetInfo2                       114
    125 #define RAP_WUserPasswordSet2                   115
    126 #define RAP_I_NetServerEnum2                    116
    127 #define RAP_WConfigGet2                         117
    128 #define RAP_WConfigGetAll2                      118
    129 #define RAP_WGetDCName                          119
    130 #define RAP_NetHandleGetInfo                    120
    131 #define RAP_NetHandleSetInfo                    121
    132 #define RAP_WStatisticsGet2                     122
    133 #define RAP_WBuildGetInfo                       123
    134 #define RAP_WFileGetInfo2                       124
    135 #define RAP_WFileClose2                         125
    136 #define RAP_WNetServerReqChallenge              126
    137 #define RAP_WNetServerAuthenticate              127
    138 #define RAP_WNetServerPasswordSet               128
    139 #define RAP_WNetAccountDeltas                   129
    140 #define RAP_WNetAccountSync                     130
    141 #define RAP_WUserEnum2                          131
    142 #define RAP_WWkstaUserLogon                     132
    143 #define RAP_WWkstaUserLogoff                    133
    144 #define RAP_WLogonEnum                          134
    145 #define RAP_WErrorLogRead                       135
    146 #define RAP_NetPathType                         136
    147 #define RAP_NetPathCanonicalize                 137
    148 #define RAP_NetPathCompare                      138
    149 #define RAP_NetNameValidate                     139
    150 #define RAP_NetNameCanonicalize                 140
    151 #define RAP_NetNameCompare                      141
    152 #define RAP_WAuditRead                          142
    153 #define RAP_WPrintDestAdd                       143
    154 #define RAP_WPrintDestSetInfo                   144
    155 #define RAP_WPrintDestDel                       145
    156 #define RAP_WUserValidate2                      146
    157 #define RAP_WPrintJobSetInfo                    147
    158 #define RAP_TI_NetServerDiskEnum                148
    159 #define RAP_TI_NetServerDiskGetInfo             149
    160 #define RAP_TI_FTVerifyMirror                   150
    161 #define RAP_TI_FTAbortVerify                    151
    162 #define RAP_TI_FTGetInfo                        152
    163 #define RAP_TI_FTSetInfo                        153
    164 #define RAP_TI_FTLockDisk                       154
    165 #define RAP_TI_FTFixError                       155
    166 #define RAP_TI_FTAbortFix                       156
    167 #define RAP_TI_FTDiagnoseError                  157
    168 #define RAP_TI_FTGetDriveStats                  158
    169 #define RAP_TI_FTErrorGetInfo                   160
    170 #define RAP_NetAccessCheck                      163
    171 #define RAP_NetAlertRaise                       164
    172 #define RAP_NetAlertStart                       165
    173 #define RAP_NetAlertStop                        166
    174 #define RAP_NetAuditWrite                       167
    175 #define RAP_NetIRemoteAPI                       168
    176 #define RAP_NetServiceStatus                    169
    177 #define RAP_NetServerRegister                   170
    178 #define RAP_NetServerDeregister                 171
    179 #define RAP_NetSessionEntryMake                 172
    180 #define RAP_NetSessionEntryClear                173
    181 #define RAP_NetSessionEntryGetInfo              174
    182 #define RAP_NetSessionEntrySetInfo              175
    183 #define RAP_NetConnectionEntryMake              176
    184 #define RAP_NetConnectionEntryClear             177
    185 #define RAP_NetConnectionEntrySetInfo           178
    186 #define RAP_NetConnectionEntryGetInfo           179
    187 #define RAP_NetFileEntryMake                    180
    188 #define RAP_NetFileEntryClear                   181
    189 #define RAP_NetFileEntrySetInfo                 182
    190 #define RAP_NetFileEntryGetInfo                 183
    191 #define RAP_AltSrvMessageBufferSend             184
    192 #define RAP_AltSrvMessageFileSend               185
    193 #define RAP_wI_NetRplWkstaEnum                  186
    194 #define RAP_wI_NetRplWkstaGetInfo               187
    195 #define RAP_wI_NetRplWkstaSetInfo               188
    196 #define RAP_wI_NetRplWkstaAdd                   189
    197 #define RAP_wI_NetRplWkstaDel                   190
    198 #define RAP_wI_NetRplProfileEnum                191
    199 #define RAP_wI_NetRplProfileGetInfo             192
    200 #define RAP_wI_NetRplProfileSetInfo             193
    201 #define RAP_wI_NetRplProfileAdd                 194
    202 #define RAP_wI_NetRplProfileDel                 195
    203 #define RAP_wI_NetRplProfileClone               196
    204 #define RAP_wI_NetRplBaseProfileEnum            197
    205 #define RAP_WIServerSetInfo                     201
    206 #define RAP_WPrintDriverEnum                    205
    207 #define RAP_WPrintQProcessorEnum                206
    208 #define RAP_WPrintPortEnum                      207
    209 #define RAP_WNetWriteUpdateLog                  208
    210 #define RAP_WNetAccountUpdate                   209
    211 #define RAP_WNetAccountConfirmUpdate            210
    212 #define RAP_WConfigSet                          211
    213 #define RAP_WAccountsReplicate                  212                     
    214 #define RAP_SamOEMChgPasswordUser2_P            214
    215 #define RAP_NetServerEnum3                      215
    216 #define RAP_WprintDriverGetInfo                 250
    217 #define RAP_WprintDriverSetInfo                 251
    218 #define RAP_WaliasAdd                           252
    219 #define RAP_WaliasDel                           253
    220 #define RAP_WaliasGetInfo                       254
    221 #define RAP_WaliasSetInfo                       255
    222 #define RAP_WaliasEnum                          256
    223 #define RAP_WuserGetLogonAsn                    257
    224 #define RAP_WuserSetLogonAsn                    258
    225 #define RAP_WuserGetAppSel                      259
    226 #define RAP_WuserSetAppSel                      260
    227 #define RAP_WappAdd                             261
    228 #define RAP_WappDel                             262
    229 #define RAP_WappGetInfo                         263
    230 #define RAP_WappSetInfo                         264
    231 #define RAP_WappEnum                            265
    232 #define RAP_WUserDCDBInit                       266
    233 #define RAP_WDASDAdd                            267
    234 #define RAP_WDASDDel                            268
    235 #define RAP_WDASDGetInfo                        269
    236 #define RAP_WDASDSetInfo                        270
    237 #define RAP_WDASDEnum                           271
    238 #define RAP_WDASDCheck                          272
    239 #define RAP_WDASDCtl                            273
    240 #define RAP_WuserRemoteLogonCheck               274
    241 #define RAP_WUserPasswordSet3                   275
    242 #define RAP_WCreateRIPLMachine                  276
    243 #define RAP_WDeleteRIPLMachine                  277
    244 #define RAP_WGetRIPLMachineInfo                 278
    245 #define RAP_WSetRIPLMachineInfo                 279
    246 #define RAP_WEnumRIPLMachine                    280
    247 #define RAP_I_ShareAdd                          281
    248 #define RAP_AliasEnum                           282
    249 #define RAP_WaccessApply                        283
    250 #define RAP_WPrt16Query                         284
    251 #define RAP_WPrt16Set                           285
    252 #define RAP_WUserDel100                         286
    253 #define RAP_WUserRemoteLogonCheck2              287
    254 #define RAP_WRemoteTODSet                       294
    255 #define RAP_WprintJobMoveAll                    295
    256 #define RAP_W16AppParmAdd                       296
    257 #define RAP_W16AppParmDel                       297
    258 #define RAP_W16AppParmGet                       298
    259 #define RAP_W16AppParmSet                       299
    260 #define RAP_W16RIPLMachineCreate                300
    261 #define RAP_W16RIPLMachineGetInfo               301
    262 #define RAP_W16RIPLMachineSetInfo               302
    263 #define RAP_W16RIPLMachineEnum                  303
    264 #define RAP_W16RIPLMachineListParmEnum          304
    265 #define RAP_W16RIPLMachClassGetInfo             305
    266 #define RAP_W16RIPLMachClassEnum                306
    267 #define RAP_W16RIPLMachClassCreate              307
    268 #define RAP_W16RIPLMachClassSetInfo             308
    269 #define RAP_W16RIPLMachClassDelete              309
    270 #define RAP_W16RIPLMachClassLPEnum              310
    271 #define RAP_W16RIPLMachineDelete                311
    272 #define RAP_W16WSLevelGetInfo                   312
    273 #define RAP_WserverNameAdd                      313
    274 #define RAP_WserverNameDel                      314
    275 #define RAP_WserverNameEnum                     315
    276 #define RAP_I_WDASDEnum                         316
    277 #define RAP_WDASDEnumTerminate                  317
    278 #define RAP_WDASDSetInfo2                       318
    279 #define MAX_API                                 318
     23#define RAP_GOTO(call) do { \
     24        NTSTATUS _status; \
     25        _status = call; \
     26        if (!NT_STATUS_IS_OK(_status)) { \
     27                result = _status; \
     28                goto done; \
     29        } \
     30} while (0)
    28031
    281 struct rap_shareenum_info_0 {
    282         char name[13];
     32#define RAP_RETURN(call) do { \
     33        NTSTATUS _status; \
     34        _status = call; \
     35        if (!NT_STATUS_IS_OK(_status)) { \
     36                return _status; \
     37        } \
     38} while (0)
     39
     40#define NDR_GOTO(call) do { \
     41        enum ndr_err_code _ndr_err; \
     42        _ndr_err = call; \
     43        if (!NDR_ERR_CODE_IS_SUCCESS(_ndr_err)) { \
     44                result = ndr_map_error2ntstatus(_ndr_err); \
     45                goto done; \
     46        } \
     47} while (0)
     48
     49#define NDR_RETURN(call) do { \
     50        enum ndr_err_code _ndr_err; \
     51        _ndr_err = call; \
     52        if (!NDR_ERR_CODE_IS_SUCCESS(_ndr_err)) { \
     53                return ndr_map_error2ntstatus(_ndr_err); \
     54        } \
     55} while (0)
     56
     57struct rap_call {
     58        uint16_t callno;
     59        char *paramdesc;
     60        const char *datadesc;
     61        const char *auxdatadesc;
     62
     63        uint16_t status;
     64        uint16_t convert;
     65
     66        uint16_t rcv_paramlen, rcv_datalen;
     67
     68        struct ndr_push *ndr_push_param;
     69        struct ndr_push *ndr_push_data;
     70        struct ndr_pull *ndr_pull_param;
     71        struct ndr_pull *ndr_pull_data;
    28372};
    28473
    285 struct rap_shareenum_info_1 {
    286         char name[13];
    287         char pad;
    288         uint16_t type;
    289         char *comment;
    290 };
     74#define RAPNDR_FLAGS (LIBNDR_FLAG_NOALIGN|LIBNDR_FLAG_STR_ASCII|LIBNDR_FLAG_STR_NULLTERM);
    29175
    292 union rap_shareenum_info {
    293         struct rap_shareenum_info_0 info0;
    294         struct rap_shareenum_info_1 info1;
    295 };
    296 
    297 struct rap_NetShareEnum {
    298         struct {
    299                 uint16_t level;
    300                 uint16_t bufsize;
    301         } in;
    302 
    303         struct {
    304                 uint16_t status;
    305                 uint16_t convert;
    306                 uint16_t count;
    307                 uint16_t available;
    308                 union rap_shareenum_info *info;
    309         } out;
    310 };
    311 
    312 struct rap_server_info_0 {
    313         char name[16];
    314 };
    315 
    316 struct rap_server_info_1 {
    317         char     name[16];
    318         uint8_t  version_major;
    319         uint8_t  version_minor;
    320         uint32_t servertype;
    321         char    *comment;
    322 };
    323 
    324 union rap_server_info {
    325         struct rap_server_info_0 info0;
    326         struct rap_server_info_1 info1;
    327 };
    328 
    329 struct rap_NetServerEnum2 {
    330         struct {
    331                 uint16_t level;
    332                 uint16_t bufsize;
    333                 uint32_t servertype;
    334                 const char *domain;
    335         } in;
    336 
    337         struct {
    338                 uint16_t status;
    339                 uint16_t convert;
    340                 uint16_t count;
    341                 uint16_t available;
    342                 union rap_server_info *info;
    343         } out;
    344 };
    345 
    346 struct rap_WserverGetInfo {
    347         struct {
    348                 uint16_t level;
    349                 uint16_t bufsize;
    350         } in;
    351 
    352         struct {
    353                 uint16_t status;
    354                 uint16_t convert;
    355                 uint16_t available;
    356                 union rap_server_info info;
    357         } out;
    358 };
     76#include "../librpc/gen_ndr/rap.h"
     77#include "libcli/rap/proto.h"
  • vendor/current/source4/libcli/raw/clisocket.c

    r414 r740  
    8181        state->socket_options = talloc_reference(state, socket_options);
    8282
     83        if (!host_addr) {
     84                host_addr = host_name;
     85        }
     86
    8387        ctx = socket_connect_multi_send(state, host_addr,
    8488                                        state->num_ports, state->ports,
  • vendor/current/source4/libcli/raw/clitransport.c

    r414 r740  
    7676                                               TALLOC_CTX *parent_ctx,
    7777                                               bool primary,
    78                                                struct smbcli_options *options,
    79                                                    struct smb_iconv_convenience *iconv_convenience)
     78                                               struct smbcli_options *options)
    8079{
    8180        struct smbcli_transport *transport;
     
    9291        transport->options = *options;
    9392        transport->negotiate.max_xmit = transport->options.max_xmit;
    94         transport->iconv_convenience = iconv_convenience;
    9593
    9694        /* setup the stream -> packet parser */
     
    173171        if (!NT_STATUS_IS_OK(status)) goto failed;
    174172       
    175         status = nbt_name_to_blob(tmp_ctx, transport->iconv_convenience, &calling_blob, calling);
     173        status = nbt_name_to_blob(tmp_ctx, &calling_blob, calling);
    176174        if (!NT_STATUS_IS_OK(status)) goto failed;
    177175
    178         status = nbt_name_to_blob(tmp_ctx, transport->iconv_convenience, &called_blob, called);
     176        status = nbt_name_to_blob(tmp_ctx, &called_blob, called);
    179177        if (!NT_STATUS_IS_OK(status)) goto failed;
    180178
  • vendor/current/source4/libcli/raw/clitree.c

    r414 r740  
    180180                                     struct smbcli_options *options,
    181181                                     struct smbcli_session_options *session_options,
    182                                          struct smb_iconv_convenience *iconv_convenience,
    183182                                         struct gensec_settings *gensec_settings)
    184183{
     
    206205        io.in.options = *options;
    207206        io.in.session_options = *session_options;
    208         io.in.iconv_convenience = iconv_convenience;
    209207       
    210208        status = smb_composite_connect(&io, parent_ctx, resolve_ctx, ev);
  • vendor/current/source4/libcli/raw/interfaces.h

    r414 r740  
    186186                struct {
    187187                        const char *path;
    188                         uint_t num_eas;
     188                        unsigned int num_eas;
    189189                        struct ea_struct *eas;                 
    190190                } in;
     
    489489                        uint32_t attrib;
    490490                        uint32_t ea_size;
    491                         uint_t num_eas;
     491                        unsigned int num_eas;
    492492                        struct ea_struct {
    493493                                uint8_t flags;
     
    517517                        uint32_t alignment_requirement;
    518518                        uint32_t reparse_tag;
    519                         uint_t num_streams;
     519                        unsigned int num_streams;
    520520                        struct stream_struct {
    521521                                uint64_t size;
     
    579579                struct {
    580580                        union smb_handle_or_path file;
    581                         uint_t num_names;
     581                        unsigned int num_names;
    582582                        struct ea_name {
    583583                                struct smb_wire_string name;
     
    586586
    587587                struct smb_ea_list {
    588                         uint_t num_eas;
     588                        unsigned int num_eas;
    589589                        struct ea_struct *eas;
    590590                } out;
     
    733733                } in;
    734734                struct stream_information {
    735                         uint_t num_streams;
     735                        unsigned int num_streams;
    736736                        struct stream_struct *streams;
    737737                } out;
     
    994994                struct {
    995995                        union smb_handle_or_path file;
    996                         uint_t num_eas;
     996                        unsigned int num_eas;
    997997                        struct ea_struct *eas;                 
    998998                } in;
     
    13571357        RAW_OPEN_NTTRANS_CREATE,
    13581358        RAW_OPEN_OPENX_READX,
     1359        RAW_OPEN_NTCREATEX_READX,
    13591360        RAW_OPEN_SMB2
    13601361};
     
    14011402                file = &op->openxreadx.out.file; \
    14021403                break; \
     1404        case RAW_OPEN_NTCREATEX_READX: \
     1405                file = &op->ntcreatexreadx.out.file; \
     1406                break; \
    14031407        case RAW_OPEN_SMB2: \
    14041408                file = &op->smb2.out.file; \
     
    14151419                struct {
    14161420                        uint32_t flags;
    1417                         uint32_t root_fid;
     1421                        union smb_handle root_fid;
    14181422                        uint32_t access_mask;
    14191423                        uint64_t alloc_size;
     
    14361440                        /* some optional parameters from the SMB2 varient */
    14371441                        bool query_maximal_access;
     1442
     1443                        /* private flags for internal use only */
     1444                        uint8_t private_flags;
    14381445                } in;
    14391446                struct {
     
    14711478                        uint32_t timeout;
    14721479                        const char *fname;
    1473                         uint_t num_eas;
     1480                        unsigned int num_eas;
    14741481                        struct ea_struct *eas;                 
    14751482                } in;
     
    16201627        } openxreadx;
    16211628
     1629        /* chained NTCreateX/ReadX interface */
     1630        struct {
     1631                enum smb_open_level level;
     1632                struct {
     1633                        uint32_t flags;
     1634                        union smb_handle root_fid;
     1635                        uint32_t access_mask;
     1636                        uint64_t alloc_size;
     1637                        uint32_t file_attr;
     1638                        uint32_t share_access;
     1639                        uint32_t open_disposition;
     1640                        uint32_t create_options;
     1641                        uint32_t impersonation;
     1642                        uint8_t  security_flags;
     1643                        /* NOTE: fname can also be a pointer to a
     1644                         uint64_t file_id if create_options has the
     1645                         NTCREATEX_OPTIONS_OPEN_BY_FILE_ID flag set */
     1646                        const char *fname;
     1647
     1648                        /* readx part */
     1649                        uint64_t offset;
     1650                        uint16_t mincnt;
     1651                        uint32_t maxcnt;
     1652                        uint16_t remaining;
     1653                } in;
     1654                struct {
     1655                        union smb_handle file;
     1656                        uint8_t oplock_level;
     1657                        uint32_t create_action;
     1658                        NTTIME create_time;
     1659                        NTTIME access_time;
     1660                        NTTIME write_time;
     1661                        NTTIME change_time;
     1662                        uint32_t attrib;
     1663                        uint64_t alloc_size;
     1664                        uint64_t size;
     1665                        uint16_t file_type;
     1666                        uint16_t ipc_state;
     1667                        uint8_t  is_directory;
     1668
     1669                        /* readx part */
     1670                        uint8_t *data;
     1671                        uint16_t remaining;
     1672                        uint16_t compaction_mode;
     1673                        uint16_t nread;
     1674                } out;
     1675        } ntcreatexreadx;
     1676
    16221677#define SMB2_CREATE_FLAG_REQUEST_OPLOCK           0x0100
    16231678#define SMB2_CREATE_FLAG_REQUEST_EXCLUSIVE_OPLOCK 0x0800
     
    19792034                        /* uint16_t buffer_code;  0x30 */
    19802035                        uint16_t lock_count;
    1981                         uint32_t reserved;
     2036                        uint32_t lock_sequence;
    19822037                        /* struct smb2_handle handle; */
    19832038                        struct smb2_lock_element {
     
    20362091                        union smb_handle file;
    20372092                        time_t write_time;
    2038 #define SMB2_CLOSE_FLAGS_FULL_INFORMATION (1<<0)
    20392093                        uint16_t flags; /* SMB2_CLOSE_FLAGS_* */
    20402094                } in;
     
    24332487
    24342488                        /* the ea names are only used for RAW_SEARCH_EA_LIST */
    2435                         uint_t num_names;
     2489                        unsigned int num_names;
    24362490                        struct ea_name *ea_names;
    24372491                } in;
     
    25172571
    25182572                        /* the ea names are only used for RAW_SEARCH_EA_LIST */
    2519                         uint_t num_names;
     2573                        unsigned int num_names;
    25202574                        struct ea_name *ea_names;
    25212575                } in;
  • vendor/current/source4/libcli/raw/libcliraw.h

    r414 r740  
    6464        int server_zone;
    6565        time_t server_time;
    66         uint_t readbraw_supported:1;
    67         uint_t writebraw_supported:1;
     66        unsigned int readbraw_supported:1;
     67        unsigned int writebraw_supported:1;
     68        unsigned int lockread_supported:1;
    6869
    6970        char *server_domain;
     
    9394*/
    9495struct smbcli_options {
    95         uint_t use_oplocks:1;
    96         uint_t use_level2_oplocks:1;
    97         uint_t use_spnego:1;
    98         uint_t unicode:1;
    99         uint_t ntstatus_support:1;
     96        unsigned int use_oplocks:1;
     97        unsigned int use_level2_oplocks:1;
     98        unsigned int use_spnego:1;
     99        unsigned int unicode:1;
     100        unsigned int ntstatus_support:1;
    100101        int max_protocol;
    101102        uint32_t max_xmit;
     
    122123        /* is a readbraw pending? we need to handle that case
    123124           specially on receiving packets */
    124         uint_t readbraw_pending:1;
     125        unsigned int readbraw_pending:1;
    125126       
    126127        /* an idle function - if this is defined then it will be
     
    130131                void (*func)(struct smbcli_transport *, void *);
    131132                void *private_data;
    132                 uint_t period;
     133                unsigned int period;
    133134        } idle;
    134135
     
    143144                              SOCKET_WRITE_ERROR,
    144145                              SOCKET_READ_BAD_SIG} socket_error;
    145                         uint_t nbt_error;
     146                        unsigned int nbt_error;
    146147                } e;
    147148        } error;
     
    164165        /* context of the stream -> packet parser */
    165166        struct packet_context *packet;
    166 
    167         /* iconv convenience */
    168         struct smb_iconv_convenience *iconv_convenience;
    169167};
    170168
     
    193191
    194192        struct smbcli_session_options {
    195                 uint_t lanman_auth:1;
    196                 uint_t ntlmv2_auth:1;
    197                 uint_t plaintext_auth:1;
     193                unsigned int lanman_auth:1;
     194                unsigned int ntlmv2_auth:1;
     195                unsigned int plaintext_auth:1;
    198196        } options;
    199197
     
    256254       
    257255        /* the sequence number of this packet - used for signing */
    258         uint_t seq_num;
     256        unsigned int seq_num;
    259257
    260258        /* list of ntcancel request for this requests */
     
    263261        /* set if this is a one-way request, meaning we are not
    264262           expecting a reply from the server. */
    265         uint_t one_way_request:1;
     263        unsigned int one_way_request:1;
    266264
    267265        /* set this when the request should only increment the signing
    268266           counter by one */
    269         uint_t sign_single_increment:1;
     267        unsigned int sign_single_increment:1;
    270268
    271269        /* the caller wants to do the signing check */
  • vendor/current/source4/libcli/raw/rawacl.c

    r414 r740  
    7878        nt.out.data.length = IVAL(nt.out.params.data, 0);
    7979
    80         ndr = ndr_pull_init_blob(&nt.out.data, mem_ctx, NULL);
     80        ndr = ndr_pull_init_blob(&nt.out.data, mem_ctx);
    8181        if (!ndr) {
    8282                return NT_STATUS_INVALID_PARAMETER;
     
    136136        nt.in.params.length = 8;
    137137
    138         ndr = ndr_push_init_ctx(NULL, NULL);
     138        ndr = ndr_push_init_ctx(NULL);
    139139        if (!ndr) return NULL;
    140140
  • vendor/current/source4/libcli/raw/raweas.c

    r414 r740  
    2727  reasonable assumption
    2828*/
    29 size_t ea_list_size(uint_t num_eas, struct ea_struct *eas)
    30 {
    31         uint_t total = 4;
     29size_t ea_list_size(unsigned int num_eas, struct ea_struct *eas)
     30{
     31        unsigned int total = 4;
    3232        int i;
    3333        for (i=0;i<num_eas;i++) {
     
    4040  work out how many bytes on the wire a ea name list will consume.
    4141*/
    42 static uint_t ea_name_list_size(uint_t num_names, struct ea_name *eas)
    43 {
    44         uint_t total = 4;
     42static unsigned int ea_name_list_size(unsigned int num_names, struct ea_name *eas)
     43{
     44        unsigned int total = 4;
    4545        int i;
    4646        for (i=0;i<num_names;i++) {
     
    5555  reasonable assumption
    5656*/
    57 size_t ea_list_size_chained(uint_t num_eas, struct ea_struct *eas, unsigned alignment)
    58 {
    59         uint_t total = 0;
     57size_t ea_list_size_chained(unsigned int num_eas, struct ea_struct *eas, unsigned alignment)
     58{
     59        unsigned int total = 0;
    6060        int i;
    6161        for (i=0;i<num_eas;i++) {
    62                 uint_t len = 8 + strlen(eas[i].name.s)+1 + eas[i].value.length;
     62                unsigned int len = 8 + strlen(eas[i].name.s)+1 + eas[i].value.length;
    6363                len = (len + (alignment-1)) & ~(alignment-1);
    6464                total += len;
     
    7171  of size ea_list_size()
    7272*/
    73 void ea_put_list(uint8_t *data, uint_t num_eas, struct ea_struct *eas)
     73void ea_put_list(uint8_t *data, unsigned int num_eas, struct ea_struct *eas)
    7474{
    7575        int i;
     
    8282
    8383        for (i=0;i<num_eas;i++) {
    84                 uint_t nlen = strlen(eas[i].name.s);
     84                unsigned int nlen = strlen(eas[i].name.s);
    8585                SCVAL(data, 0, eas[i].flags);
    8686                SCVAL(data, 1, nlen);
     
    9797  at least of size ea_list_size()
    9898*/
    99 void ea_put_list_chained(uint8_t *data, uint_t num_eas, struct ea_struct *eas,
     99void ea_put_list_chained(uint8_t *data, unsigned int num_eas, struct ea_struct *eas,
    100100                         unsigned alignment)
    101101{
     
    103103
    104104        for (i=0;i<num_eas;i++) {
    105                 uint_t nlen = strlen(eas[i].name.s);
     105                unsigned int nlen = strlen(eas[i].name.s);
    106106                uint32_t len = 8+nlen+1+eas[i].value.length;
    107                 uint_t pad = ((len + (alignment-1)) & ~(alignment-1)) - len;
     107                unsigned int pad = ((len + (alignment-1)) & ~(alignment-1)) - len;
    108108                if (i == num_eas-1) {
    109109                        SIVAL(data, 0, 0);
     
    125125  pull a ea_struct from a buffer. Return the number of bytes consumed
    126126*/
    127 uint_t ea_pull_struct(const DATA_BLOB *blob,
     127unsigned int ea_pull_struct(const DATA_BLOB *blob,
    128128                      TALLOC_CTX *mem_ctx,
    129129                      struct ea_struct *ea)
     
    165165NTSTATUS ea_pull_list(const DATA_BLOB *blob,
    166166                      TALLOC_CTX *mem_ctx,
    167                       uint_t *num_eas, struct ea_struct **eas)
     167                      unsigned int *num_eas, struct ea_struct **eas)
    168168{
    169169        int n;
     
    185185
    186186        while (ofs < ea_size) {
    187                 uint_t len;
     187                unsigned int len;
    188188                DATA_BLOB blob2;
    189189
     
    214214NTSTATUS ea_pull_list_chained(const DATA_BLOB *blob,
    215215                              TALLOC_CTX *mem_ctx,
    216                               uint_t *num_eas, struct ea_struct **eas)
     216                              unsigned int *num_eas, struct ea_struct **eas)
    217217{
    218218        int n;
     
    229229
    230230        while (ofs < blob->length) {
    231                 uint_t len;
     231                unsigned int len;
    232232                DATA_BLOB blob2;
    233233                uint32_t next_ofs = IVAL(blob->data, ofs);
     
    262262  pull a ea_name from a buffer. Return the number of bytes consumed
    263263*/
    264 static uint_t ea_pull_name(const DATA_BLOB *blob,
     264static unsigned int ea_pull_name(const DATA_BLOB *blob,
    265265                           TALLOC_CTX *mem_ctx,
    266266                           struct ea_name *ea)
     
    290290NTSTATUS ea_pull_name_list(const DATA_BLOB *blob,
    291291                           TALLOC_CTX *mem_ctx,
    292                            uint_t *num_names, struct ea_name **ea_names)
     292                           unsigned int *num_names, struct ea_name **ea_names)
    293293{
    294294        int n;
     
    310310
    311311        while (ofs < ea_size) {
    312                 uint_t len;
     312                unsigned int len;
    313313                DATA_BLOB blob2;
    314314
     
    338338*/
    339339bool ea_push_name_list(TALLOC_CTX *mem_ctx,
    340                        DATA_BLOB *data, uint_t num_names, struct ea_name *eas)
     340                       DATA_BLOB *data, unsigned int num_names, struct ea_name *eas)
    341341{
    342342        int i;
     
    355355
    356356        for (i=0;i<num_names;i++) {
    357                 uint_t nlen = strlen(eas[i].name.s);
     357                unsigned int nlen = strlen(eas[i].name.s);
    358358                SCVAL(data->data, off, nlen);
    359359                memcpy(data->data+off+1, eas[i].name.s, nlen+1);
  • vendor/current/source4/libcli/raw/rawfile.c

    r414 r740  
    349349        if (parms->ntcreatex.in.sec_desc) {
    350350                enum ndr_err_code ndr_err;
    351                 ndr_err = ndr_push_struct_blob(&sd_blob, mem_ctx, NULL,
     351                ndr_err = ndr_push_struct_blob(&sd_blob, mem_ctx,
    352352                                               parms->ntcreatex.in.sec_desc,
    353353                                               (ndr_push_flags_fn_t)ndr_push_security_descriptor);
     
    380380
    381381        SIVAL(params,  0, parms->ntcreatex.in.flags);
    382         SIVAL(params,  4, parms->ntcreatex.in.root_fid);
     382        SIVAL(params,  4, parms->ntcreatex.in.root_fid.fnum);
    383383        SIVAL(params,  8, parms->ntcreatex.in.access_mask);
    384384        SBVAL(params, 12, parms->ntcreatex.in.alloc_size);
     
    565565                SCVAL(req->out.vwv, VWV(2),0); /* padding */
    566566                SIVAL(req->out.vwv,  7, parms->ntcreatex.in.flags);
    567                 SIVAL(req->out.vwv, 11, parms->ntcreatex.in.root_fid);
     567                SIVAL(req->out.vwv, 11, parms->ntcreatex.in.root_fid.fnum);
    568568                SIVAL(req->out.vwv, 15, parms->ntcreatex.in.access_mask);
    569569                SBVAL(req->out.vwv, 19, parms->ntcreatex.in.alloc_size);
     
    617617                }
    618618                break;
     619
     620        case RAW_OPEN_NTCREATEX_READX:
     621                SETUP_REQUEST(SMBntcreateX, 24, 0);
     622                SSVAL(req->out.vwv, VWV(0),SMB_CHAIN_NONE);
     623                SSVAL(req->out.vwv, VWV(1),0);
     624                SCVAL(req->out.vwv, VWV(2),0); /* padding */
     625                SIVAL(req->out.vwv,  7, parms->ntcreatexreadx.in.flags);
     626                SIVAL(req->out.vwv, 11, parms->ntcreatexreadx.in.root_fid.fnum);
     627                SIVAL(req->out.vwv, 15, parms->ntcreatexreadx.in.access_mask);
     628                SBVAL(req->out.vwv, 19, parms->ntcreatexreadx.in.alloc_size);
     629                SIVAL(req->out.vwv, 27, parms->ntcreatexreadx.in.file_attr);
     630                SIVAL(req->out.vwv, 31, parms->ntcreatexreadx.in.share_access);
     631                SIVAL(req->out.vwv, 35, parms->ntcreatexreadx.in.open_disposition);
     632                SIVAL(req->out.vwv, 39, parms->ntcreatexreadx.in.create_options);
     633                SIVAL(req->out.vwv, 43, parms->ntcreatexreadx.in.impersonation);
     634                SCVAL(req->out.vwv, 47, parms->ntcreatexreadx.in.security_flags);
     635
     636                smbcli_req_append_string_len(req, parms->ntcreatexreadx.in.fname, STR_TERMINATE, &len);
     637                SSVAL(req->out.vwv, 5, len);
     638
     639                if (tree->session->transport->negotiate.capabilities & CAP_LARGE_FILES) {
     640                        bigoffset = true;
     641                }
     642
     643                smbcli_chained_request_setup(req, SMBreadX, bigoffset ? 12 : 10, 0);
     644
     645                SSVAL(req->out.vwv, VWV(0), SMB_CHAIN_NONE);
     646                SSVAL(req->out.vwv, VWV(1), 0);
     647                SSVAL(req->out.vwv, VWV(2), 0);
     648                SIVAL(req->out.vwv, VWV(3), parms->ntcreatexreadx.in.offset);
     649                SSVAL(req->out.vwv, VWV(5), parms->ntcreatexreadx.in.maxcnt & 0xFFFF);
     650                SSVAL(req->out.vwv, VWV(6), parms->ntcreatexreadx.in.mincnt);
     651                SIVAL(req->out.vwv, VWV(7), parms->ntcreatexreadx.in.maxcnt >> 16);
     652                SSVAL(req->out.vwv, VWV(9), parms->ntcreatexreadx.in.remaining);
     653                if (bigoffset) {
     654                        SIVAL(req->out.vwv, VWV(10),parms->ntcreatexreadx.in.offset>>32);
     655                }
     656                break;
     657
    619658        case RAW_OPEN_SMB2:
    620659                return NULL;
     
    754793                }
    755794                break;
     795
     796        case RAW_OPEN_NTCREATEX_READX:
     797                SMBCLI_CHECK_MIN_WCT(req, 34);
     798                parms->ntcreatexreadx.out.oplock_level =              CVAL(req->in.vwv, 4);
     799                parms->ntcreatexreadx.out.file.fnum =                 SVAL(req->in.vwv, 5);
     800                parms->ntcreatexreadx.out.create_action =             IVAL(req->in.vwv, 7);
     801                parms->ntcreatexreadx.out.create_time =   smbcli_pull_nttime(req->in.vwv, 11);
     802                parms->ntcreatexreadx.out.access_time =   smbcli_pull_nttime(req->in.vwv, 19);
     803                parms->ntcreatexreadx.out.write_time =    smbcli_pull_nttime(req->in.vwv, 27);
     804                parms->ntcreatexreadx.out.change_time =   smbcli_pull_nttime(req->in.vwv, 35);
     805                parms->ntcreatexreadx.out.attrib =                   IVAL(req->in.vwv, 43);
     806                parms->ntcreatexreadx.out.alloc_size =               BVAL(req->in.vwv, 47);
     807                parms->ntcreatexreadx.out.size =                     BVAL(req->in.vwv, 55);
     808                parms->ntcreatexreadx.out.file_type =                SVAL(req->in.vwv, 63);
     809                parms->ntcreatexreadx.out.ipc_state =                SVAL(req->in.vwv, 65);
     810                parms->ntcreatexreadx.out.is_directory =             CVAL(req->in.vwv, 67);
     811
     812                status = smbcli_chained_advance(req);
     813                if (!NT_STATUS_IS_OK(status)) {
     814                        return status;
     815                }
     816
     817                SMBCLI_CHECK_WCT(req, 12);
     818                parms->ntcreatexreadx.out.remaining       = SVAL(req->in.vwv, VWV(2));
     819                parms->ntcreatexreadx.out.compaction_mode = SVAL(req->in.vwv, VWV(3));
     820                parms->ntcreatexreadx.out.nread = SVAL(req->in.vwv, VWV(5));
     821                if (parms->ntcreatexreadx.out.nread >
     822                    MAX(parms->ntcreatexreadx.in.mincnt, parms->ntcreatexreadx.in.maxcnt) ||
     823                    !smbcli_raw_pull_data(&req->in.bufinfo, req->in.hdr + SVAL(req->in.vwv, VWV(6)),
     824                                          parms->ntcreatexreadx.out.nread,
     825                                          parms->ntcreatexreadx.out.data)) {
     826                        req->status = NT_STATUS_BUFFER_TOO_SMALL;
     827                }
     828                break;
     829
    756830        case RAW_OPEN_SMB2:
    757831                req->status = NT_STATUS_INTERNAL_ERROR;
     
    845919        case RAW_LOCK_LOCKX: {
    846920                struct smb_lock_entry *lockp;
    847                 uint_t lck_size = (parms->lockx.in.mode & LOCKING_ANDX_LARGE_FILES)? 20 : 10;
    848                 uint_t lock_count = parms->lockx.in.ulock_cnt + parms->lockx.in.lock_cnt;
     921                unsigned int lck_size = (parms->lockx.in.mode & LOCKING_ANDX_LARGE_FILES)? 20 : 10;
     922                unsigned int lock_count = parms->lockx.in.ulock_cnt + parms->lockx.in.lock_cnt;
    849923                int i;
    850924
  • vendor/current/source4/libcli/raw/rawfileinfo.c

    r414 r740  
    4848
    4949        while (blob.length - ofs >= 24) {
    50                 uint_t n = io->num_streams;
     50                unsigned int n = io->num_streams;
    5151                uint32_t nlen, len;
    5252                bool ret;
     
    254254                NT_STATUS_HAVE_NO_MEMORY(parms->query_secdesc.out.sd);
    255255
    256                 ndr_err = ndr_pull_struct_blob(blob, mem_ctx, NULL,
    257                                                parms->query_secdesc.out.sd,
    258                                                (ndr_pull_flags_fn_t)ndr_pull_security_descriptor);
     256                ndr_err = ndr_pull_struct_blob(blob, mem_ctx,
     257                        parms->query_secdesc.out.sd,
     258                        (ndr_pull_flags_fn_t)ndr_pull_security_descriptor);
    259259                if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
    260260                        return ndr_map_error2ntstatus(ndr_err);
  • vendor/current/source4/libcli/raw/rawfsinfo.c

    r414 r740  
    160160{
    161161        NTSTATUS status = NT_STATUS_OK;
    162         enum ndr_err_code ndr_err;
    163162        int i;
    164163
     
    216215                break;         
    217216
    218         case RAW_QFS_OBJECTID_INFORMATION:
     217        case RAW_QFS_OBJECTID_INFORMATION: {
     218                DATA_BLOB b2 = data_blob_const(blob.data, MIN(16, blob.length));
    219219                QFS_CHECK_SIZE(64);
    220                 ndr_err = ndr_pull_struct_blob(&blob, mem_ctx, NULL, &fsinfo->objectid_information.out.guid,
    221                                                (ndr_pull_flags_fn_t)ndr_pull_GUID);
    222                 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
    223                         status = ndr_map_error2ntstatus(ndr_err);
    224                 }
     220                status = GUID_from_ndr_blob(&b2, &fsinfo->objectid_information.out.guid);
     221                NT_STATUS_NOT_OK_RETURN(status);
    225222                for (i=0;i<6;i++) {
    226223                        fsinfo->objectid_information.out.unknown[i] = BVAL(blob.data, 16 + i*8);
    227224                }
    228225                break;
     226        }
    229227               
    230228        default:
  • vendor/current/source4/libcli/raw/rawnegotiate.c

    r414 r740  
    153153                        transport->negotiate.writebraw_supported = true;
    154154                }
     155
     156                if (transport->negotiate.capabilities & CAP_LOCK_AND_READ)
     157                        transport->negotiate.lockread_supported = true;
    155158        } else if (transport->negotiate.protocol >= PROTOCOL_LANMAN1) {
    156159                SMBCLI_CHECK_WCT(req, 13);
  • vendor/current/source4/libcli/raw/rawnotify.c

    r414 r740  
    7272        parms->nttrans.out.changes = NULL;
    7373        parms->nttrans.out.num_changes = 0;
    74        
     74
    7575        /* count them */
    7676        for (ofs=0; nt.out.params.length - ofs > 12; ) {
    7777                uint32_t next = IVAL(nt.out.params.data, ofs);
     78                if (next % 4 != 0)
     79                        return NT_STATUS_INVALID_NETWORK_RESPONSE;
    7880                parms->nttrans.out.num_changes++;
    7981                if (next == 0 ||
     
    156158         * but we want to keep it under oldreq->ntcancel
    157159         */
    158         if (!talloc_reference(oldreq, req)) {
    159                 talloc_free(req);
    160                 return NT_STATUS_NO_MEMORY;
    161         }
     160        req->do_not_free = true;
     161        talloc_steal(oldreq, req);
    162162
    163163        smbcli_request_send(req);
  • vendor/current/source4/libcli/raw/rawrequest.c

    r414 r740  
    120120*/
    121121struct smbcli_request *smbcli_request_setup_transport(struct smbcli_transport *transport,
    122                                                       uint8_t command, uint_t wct, uint_t buflen)
     122                                                      uint8_t command, unsigned int wct, unsigned int buflen)
    123123{
    124124        struct smbcli_request *req;
     
    168168*/
    169169struct smbcli_request *smbcli_request_setup_session(struct smbcli_session *session,
    170                                                     uint8_t command, uint_t wct, size_t buflen)
     170                                                    uint8_t command, unsigned int wct, size_t buflen)
    171171{
    172172        struct smbcli_request *req;
     
    191191struct smbcli_request *smbcli_request_setup(struct smbcli_tree *tree,
    192192                                            uint8_t command,
    193                                             uint_t wct, uint_t buflen)
     193                                            unsigned int wct, unsigned int buflen)
    194194{
    195195        struct smbcli_request *req;
     
    212212  point at the same offset into the packet as before this call
    213213*/
    214 static void smbcli_req_grow_allocation(struct smbcli_request *req, uint_t new_size)
     214static void smbcli_req_grow_allocation(struct smbcli_request *req, unsigned int new_size)
    215215{
    216216        int delta;
     
    253253  point at the same offset into the packet as before this call
    254254*/
    255 static void smbcli_req_grow_data(struct smbcli_request *req, uint_t new_size)
     255static void smbcli_req_grow_data(struct smbcli_request *req, unsigned int new_size)
    256256{
    257257        int delta;
     
    275275NTSTATUS smbcli_chained_request_setup(struct smbcli_request *req,
    276276                                      uint8_t command,
    277                                       uint_t wct, size_t buflen)
    278 {
    279         uint_t new_size = 1 + (wct*2) + 2 + buflen;
     277                                      unsigned int wct, size_t buflen)
     278{
     279        unsigned int new_size = 1 + (wct*2) + 2 + buflen;
    280280
    281281        SSVAL(req->out.vwv, VWV(0), command);
     
    372372  an oplock break
    373373*/
    374 bool smbcli_handle_oplock_break(struct smbcli_transport *transport, uint_t len, const uint8_t *hdr, const uint8_t *vwv)
     374bool smbcli_handle_oplock_break(struct smbcli_transport *transport, unsigned int len, const uint8_t *hdr, const uint8_t *vwv)
    375375{
    376376        /* we must be very fussy about what we consider an oplock break to avoid
     
    417417  return the number of bytes added to the packet
    418418*/
    419 size_t smbcli_req_append_string(struct smbcli_request *req, const char *str, uint_t flags)
     419size_t smbcli_req_append_string(struct smbcli_request *req, const char *str, unsigned int flags)
    420420{
    421421        size_t len;
     
    449449 placed in the packet as a separate field 
    450450*/
    451 size_t smbcli_req_append_string_len(struct smbcli_request *req, const char *str, uint_t flags, int *len)
     451size_t smbcli_req_append_string_len(struct smbcli_request *req, const char *str, unsigned int flags, int *len)
    452452{
    453453        int diff = 0;
     
    490490  if dest_len is -1 then no limit applies
    491491*/
    492 size_t smbcli_req_append_ascii4(struct smbcli_request *req, const char *str, uint_t flags)
     492size_t smbcli_req_append_ascii4(struct smbcli_request *req, const char *str, unsigned int flags)
    493493{
    494494        size_t size;
     
    556556*/
    557557static size_t smbcli_req_pull_ucs2(struct request_bufinfo *bufinfo, TALLOC_CTX *mem_ctx,
    558                                 char **dest, const uint8_t *src, int byte_len, uint_t flags)
     558                                char **dest, const uint8_t *src, int byte_len, unsigned int flags)
    559559{
    560560        int src_len, src_len2, alignment=0;
     
    610610*/
    611611size_t smbcli_req_pull_ascii(struct request_bufinfo *bufinfo, TALLOC_CTX *mem_ctx,
    612                              char **dest, const uint8_t *src, int byte_len, uint_t flags)
     612                             char **dest, const uint8_t *src, int byte_len, unsigned int flags)
    613613{
    614614        int src_len, src_len2;
     
    654654*/
    655655size_t smbcli_req_pull_string(struct request_bufinfo *bufinfo, TALLOC_CTX *mem_ctx,
    656                            char **dest, const uint8_t *src, int byte_len, uint_t flags)
     656                           char **dest, const uint8_t *src, int byte_len, unsigned int flags)
    657657{
    658658        if (!(flags & STR_ASCII) &&
     
    752752size_t smbcli_blob_pull_ucs2(TALLOC_CTX* mem_ctx,
    753753                             const DATA_BLOB *blob, const char **dest,
    754                              const uint8_t *src, int byte_len, uint_t flags)
     754                             const uint8_t *src, int byte_len, unsigned int flags)
    755755{
    756756        int src_len, src_len2, alignment=0;
     
    809809static size_t smbcli_blob_pull_ascii(TALLOC_CTX *mem_ctx,
    810810                                     const DATA_BLOB *blob, const char **dest,
    811                                      const uint8_t *src, int byte_len, uint_t flags)
     811                                     const uint8_t *src, int byte_len, unsigned int flags)
    812812{
    813813        int src_len, src_len2;
     
    861861                               struct smb_wire_string *dest,
    862862                               uint16_t len_offset, uint16_t str_offset,
    863                                uint_t flags)
     863                               unsigned int flags)
    864864{
    865865        int extra;
     
    928928                            const char **dest,
    929929                            uint16_t str_offset,
    930                             uint_t flags)
     930                            unsigned int flags)
    931931{
    932932        int extra = 0;
     
    962962size_t smbcli_blob_append_string(struct smbcli_session *session,
    963963                              TALLOC_CTX *mem_ctx, DATA_BLOB *blob,
    964                               const char *str, uint_t flags)
     964                              const char *str, unsigned int flags)
    965965{
    966966        size_t max_len;
     
    992992  bytes long
    993993 */
    994 enum ndr_err_code smbcli_pull_guid(void *base, uint16_t offset,
    995                                    struct GUID *guid)
     994NTSTATUS smbcli_pull_guid(void *base, uint16_t offset,
     995                          struct GUID *guid)
    996996{
    997997        DATA_BLOB blob;
    998         TALLOC_CTX *tmp_ctx = talloc_new(NULL);
    999         enum ndr_err_code ndr_err;
    1000998
    1001999        ZERO_STRUCTP(guid);
     
    10031001        blob.data       = offset + (uint8_t *)base;
    10041002        blob.length     = 16;
    1005         ndr_err = ndr_pull_struct_blob(&blob, tmp_ctx, NULL, guid,
    1006                                        (ndr_pull_flags_fn_t)ndr_pull_GUID);
    1007         talloc_free(tmp_ctx);
    1008         return ndr_err;
     1003
     1004        return GUID_from_ndr_blob(&blob, guid);
    10091005}
    10101006
     
    10121008  push a guid onto the wire. The buffer must hold 16 bytes
    10131009 */
    1014 enum ndr_err_code smbcli_push_guid(void *base, uint16_t offset,
    1015                                    const struct GUID *guid)
     1010NTSTATUS smbcli_push_guid(void *base, uint16_t offset, const struct GUID *guid)
    10161011{
    10171012        TALLOC_CTX *tmp_ctx = talloc_new(NULL);
    1018         enum ndr_err_code ndr_err;
     1013        NTSTATUS status;
    10191014        DATA_BLOB blob;
    1020         ndr_err = ndr_push_struct_blob(&blob, tmp_ctx, NULL,
    1021                                        guid, (ndr_push_flags_fn_t)ndr_push_GUID);
    1022         if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err) || blob.length != 16) {
     1015        status = GUID_to_ndr_blob(guid, tmp_ctx, &blob);
     1016        if (!NT_STATUS_IS_OK(status)) {
    10231017                talloc_free(tmp_ctx);
    1024                 return ndr_err;
     1018                return status;
    10251019        }
    10261020        memcpy(offset + (uint8_t *)base, blob.data, blob.length);
    10271021        talloc_free(tmp_ctx);
    1028         return ndr_err;
    1029 }
     1022        return NT_STATUS_OK;
     1023}
  • vendor/current/source4/libcli/raw/rawsearch.c

    r414 r740  
    334334                               const DATA_BLOB *blob,
    335335                               union smb_search_data *data,
    336                                uint_t *next_ofs,
    337                                uint_t str_flags)
    338 {
    339         uint_t len, blen;
     336                               unsigned int *next_ofs,
     337                               unsigned int str_flags)
     338{
     339        unsigned int len, blen;
    340340
    341341        if (blob->length < 4) {
     
    488488                               union smb_search_data *data)
    489489{
    490         uint_t len, ofs;
     490        unsigned int len, ofs;
    491491        uint32_t ea_size;
    492492        DATA_BLOB eablob;
     
    657657                case RAW_SEARCH_DATA_ID_FULL_DIRECTORY_INFO:
    658658                case RAW_SEARCH_DATA_ID_BOTH_DIRECTORY_INFO: {
    659                         uint_t str_flags = STR_UNICODE;
     659                        unsigned int str_flags = STR_UNICODE;
    660660                        if (!(tree->session->transport->negotiate.capabilities & CAP_UNICODE)) {
    661661                                str_flags = STR_ASCII;
     
    695695        for (i=0; i < count; i++) {
    696696                union smb_search_data search_data;
    697                 uint_t len;
     697                unsigned int len;
    698698
    699699                len = parse_trans2_search(tree, mem_ctx, level, flags, &blob2, &search_data);
  • vendor/current/source4/libcli/raw/rawsetfileinfo.c

    r414 r740  
    3434                                  DATA_BLOB *blob)
    3535{       
    36         uint_t len;
     36        unsigned int len;
    3737
    3838#define NEED_BLOB(n) do { \
     
    100100                enum ndr_err_code ndr_err;
    101101
    102                 ndr_err = ndr_push_struct_blob(blob, mem_ctx, NULL,
    103                                                parms->set_secdesc.in.sd,
     102                ndr_err = ndr_push_struct_blob(blob, mem_ctx, parms->set_secdesc.in.sd,
    104103                                               (ndr_push_flags_fn_t)ndr_push_security_descriptor);
    105104                if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
  • vendor/current/source4/libcli/raw/rawtrans.c

    r414 r740  
    3030*/
    3131static bool raw_trans_oob(struct smbcli_request *req,
    32                           uint_t offset, uint_t count)
     32                          unsigned int offset, unsigned int count)
    3333{
    3434        uint8_t *ptr;
  • vendor/current/source4/libcli/raw/request.h

    r414 r740  
    5959           into the raw buffer */
    6060        uint8_t *vwv;
    61         uint_t wct;
     61        unsigned int wct;
    6262       
    6363        /* the data buffer and size. data points into the raw buffer */
  • vendor/current/source4/libcli/raw/smb.h

    r414 r740  
    179179                                                 NTCREATEX_OPTIONS_SYNC_ALERT | \
    180180                                                 NTCREATEX_OPTIONS_ASYNC_ALERT | \
    181                                                  NTCREATEX_OPTIONS_OPFILTER | \
    182181                                                 0xFF000000)
    183182
    184183/*
    185  * We reuse some ignored flags for private use.
     184 * private_flags field in ntcreatex
    186185 * This values have different meaning for some ntvfs backends.
    187  *
    188  * TODO: use values that are ignore for sure...
    189186 */
    190 #define NTCREATEX_OPTIONS_PRIVATE_DENY_DOS      0x00010000
    191 #define NTCREATEX_OPTIONS_PRIVATE_DENY_FCB      0x00020000
    192 #define NTCREATEX_OPTIONS_PRIVATE_MASK          (NTCREATEX_OPTIONS_PRIVATE_DENY_DOS | \
    193                                                  NTCREATEX_OPTIONS_PRIVATE_DENY_FCB)
     187#define NTCREATEX_OPTIONS_PRIVATE_DENY_DOS      0x0001
     188#define NTCREATEX_OPTIONS_PRIVATE_DENY_FCB      0x0002
     189
    194190
    195191/* ntcreatex impersonation field */
     
    371367 
    372368
    373 /* Mapping of generic access rights for files to specific rights. */
    374 #define FILE_GENERIC_ALL (STANDARD_RIGHTS_REQUIRED_ACCESS| NT_ACCESS_SYNCHRONIZE_ACCESS|FILE_ALL_ACCESS)
    375 
    376 #define FILE_GENERIC_READ (STANDARD_RIGHTS_READ_ACCESS|FILE_READ_DATA|FILE_READ_ATTRIBUTES|\
    377                                                         FILE_READ_EA|NT_ACCESS_SYNCHRONIZE_ACCESS)
    378 
    379 #define FILE_GENERIC_WRITE (STANDARD_RIGHTS_WRITE_ACCESS|FILE_WRITE_DATA|FILE_WRITE_ATTRIBUTES|\
    380                             FILE_WRITE_EA|FILE_APPEND_DATA|NT_ACCESS_SYNCHRONIZE_ACCESS)
    381 
    382 #define FILE_GENERIC_EXECUTE (STANDARD_RIGHTS_EXECUTE_ACCESS|FILE_READ_ATTRIBUTES|\
    383                             FILE_EXECUTE|NT_ACCESS_SYNCHRONIZE_ACCESS)
    384 
    385 
    386369/* FileAttributes (search attributes) field */
    387370#define FILE_ATTRIBUTE_READONLY         0x0001
     
    465448        (FILE_NOTIFY_CHANGE_FILE_NAME|FILE_NOTIFY_CHANGE_DIR_NAME)
    466449
     450#define FILE_NOTIFY_CHANGE_ALL \
     451        (FILE_NOTIFY_CHANGE_FILE_NAME   | FILE_NOTIFY_CHANGE_DIR_NAME | \
     452         FILE_NOTIFY_CHANGE_ATTRIBUTES  | FILE_NOTIFY_CHANGE_SIZE | \
     453         FILE_NOTIFY_CHANGE_LAST_WRITE  | FILE_NOTIFY_CHANGE_LAST_ACCESS | \
     454         FILE_NOTIFY_CHANGE_CREATION    | FILE_NOTIFY_CHANGE_EA | \
     455         FILE_NOTIFY_CHANGE_SECURITY    | FILE_NOTIFY_CHANGE_STREAM_NAME | \
     456         FILE_NOTIFY_CHANGE_STREAM_SIZE | FILE_NOTIFY_CHANGE_STREAM_WRITE)
     457
    467458/* change notify action results */
    468459#define NOTIFY_ACTION_ADDED 1
     
    552543
    553544/* Lock types. */
     545#define LOCKING_ANDX_EXCLUSIVE_LOCK  0x00
    554546#define LOCKING_ANDX_SHARED_LOCK     0x01
    555547#define LOCKING_ANDX_OPLOCK_RELEASE  0x02
  • vendor/current/source4/libcli/raw/smb_signing.c

    r414 r740  
    133133}
    134134
    135 bool check_signed_incoming_message(struct smb_request_buffer *in, DATA_BLOB *mac_key, uint_t seq_num)
     135bool check_signed_incoming_message(struct smb_request_buffer *in, DATA_BLOB *mac_key, unsigned int seq_num)
    136136{
    137137        bool good;
  • vendor/current/source4/libcli/resolve/bcast.c

    r414 r740  
    102102{
    103103        struct interface *ifaces;
    104         load_interfaces(ctx, lp_interfaces(lp_ctx), &ifaces);
    105         return resolve_context_add_bcast_method(ctx, ifaces, lp_nbt_port(lp_ctx), lp_parm_int(lp_ctx, NULL, "nbt", "timeout", 1));
     104        load_interfaces(ctx, lpcfg_interfaces(lp_ctx), &ifaces);
     105        return resolve_context_add_bcast_method(ctx, ifaces, lpcfg_nbt_port(lp_ctx), lpcfg_parm_int(lp_ctx, NULL, "nbt", "timeout", 1));
    106106}
  • vendor/current/source4/libcli/resolve/dns_ex.c

    r414 r740  
    6868
    6969        kill(state->child, SIGTERM);
    70         close(state->child_fd);
    7170        if (waitpid(state->child, &status, WNOHANG) == 0) {
    7271                kill(state->child, SIGKILL);
     
    9493        bool do_srv = (state->flags & RESOLVE_NAME_FLAG_DNS_SRV);
    9594
     95        if (strchr(state->name.name, '.') && state->name.name[strlen(state->name.name)-1] != '.') {
     96                /* we are asking for a fully qualified name, but the
     97                   name doesn't end in a '.'. We need to prevent the
     98                   DNS library trying the search domains configured in
     99                   resolv.conf */
     100                state->name.name = talloc_strdup_append(discard_const_p(char, state->name.name),
     101                                                        ".");
     102        }
     103
    96104        /* this is the blocking call we are going to lots of trouble
    97105           to avoid in the parent */
     
    169177                if (do_srv) {
    170178                        /* we are only interested in SRV records */
    171                         if (rr->type != rk_ns_c_in) {
     179                        if (rr->type != rk_ns_t_srv) {
    172180                                continue;
    173181                        }
     
    209217                        }
    210218
    211                         /* we are only interested in SRV records */
     219                        /* we are only interested in A records */
    212220                        if (rr->type != rk_ns_t_a) {
    213221                                continue;
     
    370378                ret = -1;
    371379        }
    372         close(state->child_fd);
    373380        if (waitpid(state->child, &status, WNOHANG) == 0) {
    374381                kill(state->child, SIGKILL);
     
    499506                return c;
    500507        }
     508        tevent_fd_set_auto_close(state->fde);
    501509
    502510        state->child = fork();
  • vendor/current/source4/libcli/resolve/nbtlist.c

    r414 r740  
    164164        }
    165165
    166         state->nbtsock = nbt_name_socket_init(state, event_ctx,
    167                                               global_iconv_convenience);
     166        state->nbtsock = nbt_name_socket_init(state, event_ctx);
    168167        if (composite_nomem(state->nbtsock, c)) return c;
    169168
  • vendor/current/source4/libcli/resolve/resolve.c

    r414 r740  
    2828#include "lib/socket/socket.h"
    2929#include "../lib/util/dlinklist.h"
     30#include "lib/tsocket/tsocket.h"
     31#include "lib/util/util_net.h"
    3032
    3133struct resolve_state {
     
    138140struct composite_context *resolve_name_all_send(struct resolve_context *ctx,
    139141                                                TALLOC_CTX *mem_ctx,
    140                                                 uint32_t flags,
     142                                                uint32_t flags, /* RESOLVE_NAME_FLAG_* */
    141143                                                uint16_t port,
    142144                                                struct nbt_name *name,
     
    146148        struct resolve_state *state;
    147149
    148         if (ctx == NULL || event_ctx == NULL) {
     150        if (event_ctx == NULL) {
    149151                return NULL;
    150152        }
     
    222224}
    223225
     226struct composite_context *resolve_name_ex_send(struct resolve_context *ctx,
     227                                               TALLOC_CTX *mem_ctx,
     228                                               uint32_t flags, /* RESOLVE_NAME_FLAG_* */
     229                                               uint16_t port,
     230                                               struct nbt_name *name,
     231                                               struct tevent_context *event_ctx)
     232{
     233        return resolve_name_all_send(ctx, mem_ctx, flags, port, name, event_ctx);
     234}
     235
    224236struct composite_context *resolve_name_send(struct resolve_context *ctx,
    225237                                            TALLOC_CTX *mem_ctx,
     
    227239                                            struct tevent_context *event_ctx)
    228240{
    229         return resolve_name_all_send(ctx, mem_ctx, 0, 0, name, event_ctx);
     241        return resolve_name_ex_send(ctx, mem_ctx, 0, 0, name, event_ctx);
    230242}
    231243
     
    240252
    241253        if (NT_STATUS_IS_OK(status)) {
    242                 *reply_addr = talloc_steal(mem_ctx, addrs[0]->addr);
     254                struct tsocket_address *t_addr = socket_address_to_tsocket_address(addrs, addrs[0]);
     255                if (!t_addr) {
     256                        return NT_STATUS_NO_MEMORY;
     257                }
     258
     259                *reply_addr = tsocket_address_inet_addr_string(t_addr, mem_ctx);
    243260                talloc_free(addrs);
     261                if (!*reply_addr) {
     262                        return NT_STATUS_NO_MEMORY;
     263                }
    244264        }
    245265
     
    248268
    249269/*
     270  receive multiple responses from resolve_name_send()
     271 */
     272NTSTATUS resolve_name_multiple_recv(struct composite_context *c,
     273                                    TALLOC_CTX *mem_ctx,
     274                                    const char ***reply_addrs)
     275{
     276        NTSTATUS status;
     277        struct socket_address **addrs = NULL;
     278        int i;
     279
     280        status = resolve_name_all_recv(c, mem_ctx, &addrs, NULL);
     281        NT_STATUS_NOT_OK_RETURN(status);
     282
     283        /* count the addresses */
     284        for (i=0; addrs[i]; i++) ;
     285
     286        *reply_addrs = talloc_array(mem_ctx, const char *, i+1);
     287        NT_STATUS_HAVE_NO_MEMORY(*reply_addrs);
     288
     289        for (i=0; addrs[i]; i++) {
     290                struct tsocket_address *t_addr = socket_address_to_tsocket_address(addrs, addrs[i]);
     291                NT_STATUS_HAVE_NO_MEMORY(t_addr);
     292
     293                (*reply_addrs)[i] = tsocket_address_inet_addr_string(t_addr, *reply_addrs);
     294                NT_STATUS_HAVE_NO_MEMORY((*reply_addrs)[i]);
     295        }
     296        (*reply_addrs)[i] = NULL;
     297
     298        talloc_free(addrs);
     299
     300        return status;
     301}
     302
     303/*
    250304  general name resolution - sync call
    251305 */
     306NTSTATUS resolve_name_ex(struct resolve_context *ctx,
     307                         uint32_t flags, /* RESOLVE_NAME_FLAG_* */
     308                         uint16_t port,
     309                         struct nbt_name *name,
     310                         TALLOC_CTX *mem_ctx,
     311                         const char **reply_addr,
     312                         struct tevent_context *ev)
     313{
     314        struct composite_context *c = resolve_name_ex_send(ctx, mem_ctx, flags, port, name, ev);
     315        return resolve_name_recv(c, mem_ctx, reply_addr);
     316}
     317
     318
     319/*
     320  general name resolution - sync call
     321 */
    252322NTSTATUS resolve_name(struct resolve_context *ctx,
    253                           struct nbt_name *name,
    254                           TALLOC_CTX *mem_ctx,
    255                           const char **reply_addr,
    256                           struct tevent_context *ev)
    257 {
    258         struct composite_context *c = resolve_name_send(ctx, mem_ctx, name, ev);
    259         return resolve_name_recv(c, mem_ctx, reply_addr);
     323                      struct nbt_name *name,
     324                      TALLOC_CTX *mem_ctx,
     325                      const char **reply_addr,
     326                      struct tevent_context *ev)
     327{
     328        return resolve_name_ex(ctx, 0, 0, name, mem_ctx, reply_addr, ev);
    260329}
    261330
  • vendor/current/source4/libcli/resolve/resolve_lp.c

    r414 r740  
    2222#include "param/param.h"
    2323
    24 struct resolve_context *lp_resolve_context(struct loadparm_context *lp_ctx)
     24struct resolve_context *lpcfg_resolve_context(struct loadparm_context *lp_ctx)
    2525{
    26         const char **methods = lp_name_resolve_order(lp_ctx);
     26        const char **methods = lpcfg_name_resolve_order(lp_ctx);
    2727        int i;
    2828        struct resolve_context *ret = resolve_context_init(lp_ctx);
     
    3636                } else if (!strcmp(methods[i], "bcast")) {
    3737                        resolve_context_add_bcast_method_lp(ret, lp_ctx);
     38                } else if (!strcmp(methods[i], "file")) {
     39                        resolve_context_add_file_method_lp(ret, lp_ctx);
    3840                } else if (!strcmp(methods[i], "host")) {
    3941                        resolve_context_add_host_method(ret);
  • vendor/current/source4/libcli/resolve/testsuite.c

    r414 r740  
    2525#include "torture/torture.h"
    2626#include "system/network.h"
     27#include "lib/util/util_net.h"
    2728
    2829static bool test_async_resolve(struct torture_context *tctx)
     
    8283struct torture_suite *torture_local_resolve(TALLOC_CTX *mem_ctx)
    8384{
    84         struct torture_suite *suite = torture_suite_create(mem_ctx, "RESOLVE");
     85        struct torture_suite *suite = torture_suite_create(mem_ctx, "resolve");
    8586
    8687        torture_suite_add_simple_test(suite, "async", test_async_resolve);
  • vendor/current/source4/libcli/resolve/wins.c

    r414 r740  
    7878{
    7979        struct interface *ifaces;
    80         load_interfaces(ctx, lp_interfaces(lp_ctx), &ifaces);
    81         return resolve_context_add_wins_method(ctx, lp_wins_server_list(lp_ctx), ifaces, lp_nbt_port(lp_ctx), lp_parm_int(lp_ctx, NULL, "nbt", "timeout", 1));
     80        load_interfaces(ctx, lpcfg_interfaces(lp_ctx), &ifaces);
     81        return resolve_context_add_wins_method(ctx, lpcfg_wins_server_list(lp_ctx), ifaces, lpcfg_nbt_port(lp_ctx), lpcfg_parm_int(lp_ctx, NULL, "nbt", "timeout", 1));
    8282}
  • vendor/current/source4/libcli/security/tests/sddl.c

    r414 r740  
    7373        "D:(A;;CC;;;BA)(A;;RPWPCRCCDCLCLORCWOWDSDDTSW;;;SY)(A;;RPLCLORC;;;AU)",
    7474        "D:(A;;GA;;;SY)",
     75        "D:(A;;GA;;;RS)",
    7576        "D:(A;;RP;;;WD)(OA;;CR;1131f6aa-9c07-11d1-f79f-00c04fc2dcd2;;ED)(OA;;CR;1131f6ab-9c07-11d1-f79f-00c04fc2dcd2;;ED)(OA;;CR;1131f6ac-9c07-11d1-f79f-00c04fc2dcd2;;ED)(OA;;CR;1131f6aa-9c07-11d1-f79f-00c04fc2dcd2;;BA)(OA;;CR;1131f6ab-9c07-11d1-f79f-00c04fc2dcd2;;BA)(OA;;CR;1131f6ac-9c07-11d1-f79f-00c04fc2dcd2;;BA)(A;;RPLCLORC;;;AU)(A;;RPWPCRLCLOCCRCWDWOSW;;;DA)(A;CI;RPWPCRLCLOCCRCWDWOSDSW;;;BA)(A;;RPWPCRLCLOCCDCRCWDWOSDDTSW;;;SY)(A;CI;RPWPCRLCLOCCDCRCWDWOSDDTSW;;;EA)(A;CI;LC;;;RU)(OA;CIIO;RP;037088f8-0ae1-11d2-b422-00a0c968f939;bf967aba-0de6-11d0-a285-00aa003049e2;RU)(OA;CIIO;RP;59ba2f42-79a2-11d0-9020-00c04fc2d3cf;bf967aba-0de6-11d0-a285-00aa003049e2;RU)(OA;CIIO;RP;bc0ac240-79a9-11d0-9020-00c04fc2d4cf;bf967aba-0de6-11d0-a285-00aa003049e2;RU)(OA;CIIO;RP;4c164200-20c0-11d0-a768-00aa006e0529;bf967aba-0de6-11d0-a285-00aa003049e2;RU)(OA;CIIO;RP;5f202010-79a5-11d0-9020-00c04fc2d4cf;bf967aba-0de6-11d0-a285-00aa003049e2;RU)(OA;;RP;c7407360-20bf-11d0-a768-00aa006e0529;;RU)(OA;CIIO;RPLCLORC;;bf967a9c-0de6-11d0-a285-00aa003049e2;RU)(A;;RPRC;;;RU)(OA;CIIO;RPLCLORC;;bf967aba-0de6-11d0-a285-00aa003049e2;RU)(A;;LCRPLORC;;;ED)(OA;CIIO;RP;037088f8-0ae1-11d2-b422-00a0c968f939;4828CC14-1437-45bc-9B07-AD6F015E5F28;RU)(OA;CIIO;RP;59ba2f42-79a2-11d0-9020-00c04fc2d3cf;4828CC14-1437-45bc-9B07-AD6F015E5F28;RU)(OA;CIIO;RP;bc0ac240-79a9-11d0-9020-00c04fc2d4cf;4828CC14-1437-45bc-9B07-AD6F015E5F28;RU)(OA;CIIO;RP;4c164200-20c0-11d0-a768-00aa006e0529;4828CC14-1437-45bc-9B07-AD6F015E5F28;RU)(OA;CIIO;RP;5f202010-79a5-11d0-9020-00c04fc2d4cf;4828CC14-1437-45bc-9B07-AD6F015E5F28;RU)(OA;CIIO;RPLCLORC;;4828CC14-1437-45bc-9B07-AD6F015E5F28;RU)(OA;;RP;b8119fd0-04f6-4762-ab7a-4986c76b3f9a;;RU)(OA;;RP;b8119fd0-04f6-4762-ab7a-4986c76b3f9a;;AU)(OA;CIIO;RP;b7c69e6d-2cc7-11d2-854e-00a0c983f608;bf967aba-0de6-11d0-a285-00aa003049e2;ED)(OA;CIIO;RP;b7c69e6d-2cc7-11d2-854e-00a0c983f608;bf967a9c-0de6-11d0-a285-00aa003049e2;ED)(OA;CIIO;RP;b7c69e6d-2cc7-11d2-854e-00a0c983f608;bf967a86-0de6-11d0-a285-00aa003049e2;ED)(OA;;CR;1131f6ad-9c07-11d1-f79f-00c04fc2dcd2;;DD)(OA;;CR;1131f6ad-9c07-11d1-f79f-00c04fc2dcd2;;BA)(OA;;CR;e2a36dc9-ae17-47c3-b58b-be34c55ba633;;S-1-5-32-557)(OA;;CR;280f369c-67c7-438e-ae98-1d46f3c6f541;;AU)(OA;;CR;ccc2dc7d-a6ad-4a7a-8846-c04e3cc53501;;AU)(OA;;CR;05c74c5e-4deb-43b4-bd9f-86664c2a7fd5;;AU)S:(AU;SA;WDWOWP;;;WD)(AU;SA;CR;;;BA)(AU;SA;CR;;;DU)(OU;CISA;WP;f30e3bbe-9ff0-11d1-b603-0000f80367c1;bf967aa5-0de6-11d0-a285-00aa003049e2;WD)(OU;CISA;WP;f30e3bbf-9ff0-11d1-b603-0000f80367c1;bf967aa5-0de6-11d0-a285-00aa003049e2;WD)",
    7677        "D:(A;;RPLCLORC;;;DA)(A;;RPWPCRCCDCLCLORCWOWDSDDTSW;;;SY)(A;;RPLCLORC;;;AU)",
     
    9394struct torture_suite *torture_local_sddl(TALLOC_CTX *mem_ctx)
    9495{
    95         struct torture_suite *suite = torture_suite_create(mem_ctx, "SDDL");
     96        struct torture_suite *suite = torture_suite_create(mem_ctx, "sddl");
    9697        int i;
    9798
  • vendor/current/source4/libcli/smb2/cancel.c

    r414 r740  
    5454        SIVAL(c->out.hdr, SMB2_HDR_FLAGS,       0x00000002);
    5555        SSVAL(c->out.hdr, SMB2_HDR_CREDIT,      0x0030);
    56         SIVAL(c->out.hdr, SMB2_HDR_PID,         r->cancel.pending_id);
     56        SBVAL(c->out.hdr, SMB2_HDR_ASYNC_ID,    r->cancel.async_id);
    5757        SBVAL(c->out.hdr, SMB2_HDR_MESSAGE_ID,  c->seqnum);
    5858        if (r->session) {
  • vendor/current/source4/libcli/smb2/create.c

    r414 r740  
    132132                enum ndr_err_code ndr_err;
    133133                DATA_BLOB sd_blob;
    134                 ndr_err = ndr_push_struct_blob(&sd_blob, req, NULL,
    135                                                io->in.sec_desc,
     134                ndr_err = ndr_push_struct_blob(&sd_blob, req, io->in.sec_desc,
    136135                                               (ndr_push_flags_fn_t)ndr_push_security_descriptor);
    137136                if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
  • vendor/current/source4/libcli/smb2/find.c

    r414 r740  
    9696*/
    9797NTSTATUS smb2_find_level_recv(struct smb2_request *req, TALLOC_CTX *mem_ctx,
    98                               uint8_t level, uint_t *count,
     98                              uint8_t level, unsigned int *count,
    9999                              union smb_search_data **io)
    100100{
     
    103103        DATA_BLOB b;
    104104        enum smb_search_data_level smb_level;
    105         uint_t next_ofs=0;
     105        unsigned int next_ofs=0;
    106106
    107107        switch (level) {
     
    172172NTSTATUS smb2_find_level(struct smb2_tree *tree, TALLOC_CTX *mem_ctx,
    173173                         struct smb2_find *f,
    174                          uint_t *count, union smb_search_data **io)
     174                         unsigned int *count, union smb_search_data **io)
    175175{
    176176        struct smb2_request *req;
  • vendor/current/source4/libcli/smb2/lock.c

    r414 r740  
    4040
    4141        SSVAL(req->out.body, 0x02, io->in.lock_count);
    42         SIVAL(req->out.body, 0x04, io->in.reserved);
     42        SIVAL(req->out.body, 0x04, io->in.lock_sequence);
    4343        smb2_push_handle(req->out.body+0x08, &io->in.file.handle);
    4444
  • vendor/current/source4/libcli/smb2/negprot.c

    r414 r740  
    3535        struct smb2_request *req;
    3636        uint16_t size = 0x24 + io->in.dialect_count*2;
    37         enum ndr_err_code ndr_err;
    3837        int i;
     38        NTSTATUS status;
    3939
    4040        req = smb2_request_init(transport, SMB2_OP_NEGPROT, size, false, 0);
     
    4747        SSVAL(req->out.body, 0x06, io->in.reserved);
    4848        SIVAL(req->out.body, 0x08, io->in.capabilities);
    49         ndr_err = smbcli_push_guid(req->out.body, 0x0C, &io->in.client_guid);
    50         if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
     49        status = smbcli_push_guid(req->out.body, 0x0C, &io->in.client_guid);
     50        if (!NT_STATUS_IS_OK(status)) {
    5151                talloc_free(req);
    5252                return NULL;
     
    6969{
    7070        NTSTATUS status;
    71         enum ndr_err_code ndr_err;
    7271
    7372        if (!smb2_request_receive(req) ||
     
    8180        io->out.dialect_revision   = SVAL(req->in.body, 0x04);
    8281        io->out.reserved           = SVAL(req->in.body, 0x06);
    83         ndr_err = smbcli_pull_guid(req->in.body, 0x08, &io->in.client_guid);
    84         if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
     82        status = smbcli_pull_guid(req->in.body, 0x08, &io->in.client_guid);
     83        if (!NT_STATUS_IS_OK(status)) {
    8584                smb2_request_destroy(req);
    86                 return NT_STATUS_INTERNAL_ERROR;
     85                return status;
    8786        }
    8887        io->out.capabilities       = IVAL(req->in.body, 0x18);
  • vendor/current/source4/libcli/smb2/request.c

    r414 r740  
    176176
    177177        SBVAL(req->out.hdr,  SMB2_HDR_SESSION_ID, tree->session->uid);
     178        SIVAL(req->out.hdr,  SMB2_HDR_PID, tree->session->pid);
    178179        SIVAL(req->out.hdr,  SMB2_HDR_TID, tree->tid);
    179180        req->session = tree->session;
  • vendor/current/source4/libcli/smb2/session.c

    r414 r740  
    2727#include "auth/gensec/gensec.h"
    2828
     29#include <unistd.h>
     30
    2931/**
    3032  initialise a smb2_session structure
     
    4648                session->transport = talloc_reference(session, transport);
    4749        }
     50
     51        session->pid = getpid();
    4852
    4953        /* prepare a gensec context for later use */
  • vendor/current/source4/libcli/smb2/smb2.h

    r414 r740  
    104104                void (*func)(struct smb2_transport *, void *);
    105105                void *private_data;
    106                 uint_t period;
     106                unsigned int period;
    107107        } idle;
    108108
     
    146146        struct gensec_security *gensec;
    147147        uint64_t uid;
     148        uint32_t pid;
    148149        DATA_BLOB session_key;
    149150        bool signing_active;
     
    167168        /* each request is in one of 3 possible states */
    168169        enum smb2_request_state state;
    169        
     170
    170171        struct smb2_transport *transport;
    171172        struct smb2_session   *session;
     
    177178                bool do_cancel;
    178179                bool can_cancel;
    179                 uint32_t pending_id;
     180                uint64_t async_id;
    180181        } cancel;
    181182
     
    183184           or code detecting error. */
    184185        NTSTATUS status;
    185        
     186
    186187        struct smb2_request_buffer in;
    187188        struct smb2_request_buffer out;
  • vendor/current/source4/libcli/smb2/transport.c

    r414 r740  
    303303            NT_STATUS_EQUAL(req->status, STATUS_PENDING)) {
    304304                req->cancel.can_cancel = true;
    305                 req->cancel.pending_id = IVAL(hdr, SMB2_HDR_PID);
     305                req->cancel.async_id = BVAL(hdr, SMB2_HDR_ASYNC_ID);
    306306                for (i=0; i< req->cancel.do_cancel; i++) {
    307307                        smb2_cancel(req);
  • vendor/current/source4/libcli/smb2/util.c

    r414 r740  
    2626#include "libcli/smb2/smb2_calls.h"
    2727#include "libcli/smb_composite/smb_composite.h"
     28#include "librpc/gen_ndr/ndr_security.h"
    2829
    2930/*
     
    109110        NTSTATUS status;
    110111        uint32_t total_deleted = 0;
    111         uint_t count, i;
     112        unsigned int count, i;
    112113        union smb_search_data *list;
    113114        TALLOC_CTX *tmp_ctx = talloc_new(tree);
     
    221222        return total_deleted;
    222223}
     224
     225/*
     226  check if two SMB2 file handles are the same
     227*/
     228bool smb2_util_handle_equal(const struct smb2_handle h1,
     229                            const struct smb2_handle h2)
     230{
     231        return (h1.data[0] == h2.data[0]) && (h1.data[1] == h2.data[1]);
     232}
  • vendor/current/source4/libcli/smb_composite/appendacl.c

    r414 r740  
    255255       
    256256        state->io_open->ntcreatex.level               = RAW_OPEN_NTCREATEX;
    257         state->io_open->ntcreatex.in.root_fid = 0;
     257        state->io_open->ntcreatex.in.root_fid.fnum    = 0;
    258258        state->io_open->ntcreatex.in.flags            = 0;
    259259        state->io_open->ntcreatex.in.access_mask      = SEC_FLAG_MAXIMUM_ALLOWED;
  • vendor/current/source4/libcli/smb_composite/connect.c

    r414 r740  
    3131#include "librpc/gen_ndr/ndr_nbt.h"
    3232#include "param/param.h"
     33#include "lib/util/util_net.h"
    3334
    3435/* the stages of this call */
    35 enum connect_stage {CONNECT_RESOLVE,
    36                     CONNECT_SOCKET,
     36enum connect_stage {CONNECT_SOCKET,
    3737                    CONNECT_SESSION_REQUEST,
    3838                    CONNECT_NEGPROT,
     
    324324        /* the socket is up - we can initialise the smbcli transport layer */
    325325        state->transport = smbcli_transport_init(state->sock, state, true,
    326                                                  &io->in.options, io->in.iconv_convenience);
     326                                                 &io->in.options);
    327327        NT_STATUS_HAVE_NO_MEMORY(state->transport);
    328328
     
    363363
    364364/*
    365   called when name resolution is finished
    366 */
    367 static NTSTATUS connect_resolve(struct composite_context *c,
    368                                 struct smb_composite_connect *io)
    369 {
    370         struct connect_state *state = talloc_get_type(c->private_data, struct connect_state);
    371         NTSTATUS status;
    372         const char *address;
    373 
    374         status = resolve_name_recv(state->creq, state, &address);
    375         NT_STATUS_NOT_OK_RETURN(status);
    376 
    377         state->creq = smbcli_sock_connect_send(state, address,
    378                                                io->in.dest_ports,
    379                                                io->in.dest_host,
    380                                                NULL, c->event_ctx,
    381                                                   io->in.socket_options);
    382         NT_STATUS_HAVE_NO_MEMORY(state->creq);
    383 
    384         state->stage = CONNECT_SOCKET;
    385         state->creq->async.private_data = c;
    386         state->creq->async.fn = composite_handler;
    387 
    388         return NT_STATUS_OK;
    389 }
    390 
    391 
    392 /*
    393365  handle and dispatch state transitions
    394366*/
     
    398370
    399371        switch (state->stage) {
    400         case CONNECT_RESOLVE:
    401                 c->status = connect_resolve(c, state->io);
    402                 break;
    403372        case CONNECT_SOCKET:
    404373                c->status = connect_socket(c, state->io);
     
    462431        struct composite_context *c;
    463432        struct connect_state *state;
    464         struct nbt_name name;
    465433
    466434        c = talloc_zero(mem_ctx, struct composite_context);
     
    479447        c->private_data = state;
    480448
    481         state->stage = CONNECT_RESOLVE;
    482         make_nbt_name_server(&name, io->in.dest_host);
    483         state->creq = resolve_name_send(resolve_ctx, state, &name, c->event_ctx);
    484 
     449        state->creq = smbcli_sock_connect_send(state,
     450                                               NULL,
     451                                               io->in.dest_ports,
     452                                               io->in.dest_host,
     453                                               resolve_ctx, c->event_ctx,
     454                                               io->in.socket_options);
    485455        if (state->creq == NULL) goto failed;
     456
     457        state->stage = CONNECT_SOCKET;
    486458        state->creq->async.private_data = c;
    487459        state->creq->async.fn = composite_handler;
  • vendor/current/source4/libcli/smb_composite/fetchfile.c

    r414 r740  
    147147        state->connect->in.workgroup    = io->in.workgroup;
    148148        state->connect->in.gensec_settings = io->in.gensec_settings;
    149         state->connect->in.iconv_convenience = io->in.iconv_convenience;
    150149
    151150        state->connect->in.options      = io->in.options;
  • vendor/current/source4/libcli/smb_composite/fsinfo.c

    r414 r740  
    154154        state->connect->in.fallback_to_anonymous = false;
    155155        state->connect->in.workgroup    = io->in.workgroup;
    156         state->connect->in.iconv_convenience = io->in.iconv_convenience;
    157156        state->connect->in.gensec_settings = io->in.gensec_settings;
    158157
  • vendor/current/source4/libcli/smb_composite/smb_composite.h

    r414 r740  
    6161                struct smbcli_session_options session_options;
    6262                struct resolve_context *resolve_ctx;
    63                 struct smb_iconv_convenience *iconv_convenience;
    6463                struct gensec_settings *gensec_settings;
    6564        } in;
     
    105104                struct smbcli_options options;
    106105                struct smbcli_session_options session_options;
    107                 struct smb_iconv_convenience *iconv_convenience;
    108106                struct gensec_settings *gensec_settings;
    109107        } in;
     
    146144                const char *workgroup;
    147145                enum smb_fsinfo_level level;
    148                 struct smb_iconv_convenience *iconv_convenience;
    149146                struct gensec_settings *gensec_settings;
    150147        } in;
     
    182179                const char **hostnames;
    183180                const char **addresses;
    184                 int *ports;     /* Either NULL for lp_smb_ports() per
     181                int *ports;     /* Either NULL for lpcfg_smb_ports() per
    185182                                 * destination or a list of explicit ports */
    186183        } in;
  • vendor/current/source4/libcli/util/clilsa.c

    r414 r740  
    8080        lsa->ipc_tree->tid = tcon.tconx.out.tid;
    8181
    82         lsa->pipe = dcerpc_pipe_init(lsa, cli->transport->socket->event.ctx,
    83                                                                  cli->transport->iconv_convenience);
     82        lsa->pipe = dcerpc_pipe_init(lsa, cli->transport->socket->event.ctx);
    8483        if (lsa->pipe == NULL) {
    8584                talloc_free(lsa);
     
    120119        r.out.handle = &lsa->handle;
    121120
    122         status = dcerpc_lsa_OpenPolicy(lsa->pipe, lsa, &r);
    123         if (!NT_STATUS_IS_OK(status)) {
    124                 talloc_free(lsa);
    125                 return status;
     121        status = dcerpc_lsa_OpenPolicy_r(lsa->pipe->binding_handle, lsa, &r);
     122        if (!NT_STATUS_IS_OK(status)) {
     123                talloc_free(lsa);
     124                return status;
     125        }
     126
     127        if (!NT_STATUS_IS_OK(r.out.result)) {
     128                talloc_free(lsa);
     129                return r.out.result;
    126130        }
    127131
     
    151155        r.out.rights = rights;
    152156
    153         return dcerpc_lsa_EnumAccountRights(cli->lsa->pipe, mem_ctx, &r);
     157        status = dcerpc_lsa_EnumAccountRights_r(cli->lsa->pipe->binding_handle, mem_ctx, &r);
     158        if (!NT_STATUS_IS_OK(status)) {
     159                return status;
     160        }
     161
     162        return r.out.result;
    154163}
    155164
     
    235244        r.out.domains = &domains;
    236245
    237         status = dcerpc_lsa_LookupSids(cli->lsa->pipe, mem_ctx2, &r);
    238         if (!NT_STATUS_IS_OK(status)) {
    239                 talloc_free(mem_ctx2);
    240                 return status;
     246        status = dcerpc_lsa_LookupSids_r(cli->lsa->pipe->binding_handle, mem_ctx2, &r);
     247        if (!NT_STATUS_IS_OK(status)) {
     248                talloc_free(mem_ctx2);
     249                return status;
     250        }
     251        if (!NT_STATUS_IS_OK(r.out.result)) {
     252                talloc_free(mem_ctx2);
     253                return r.out.result;
    241254        }
    242255        if (names.count != 1) {
     
    292305        r.out.domains = &domains;
    293306
    294         status = dcerpc_lsa_LookupNames(cli->lsa->pipe, mem_ctx2, &r);
    295         if (!NT_STATUS_IS_OK(status)) {
    296                 talloc_free(mem_ctx2);
    297                 return status;
     307        status = dcerpc_lsa_LookupNames_r(cli->lsa->pipe->binding_handle, mem_ctx2, &r);
     308        if (!NT_STATUS_IS_OK(status)) {
     309                talloc_free(mem_ctx2);
     310                return status;
     311        }
     312        if (!NT_STATUS_IS_OK(r.out.result)) {
     313                talloc_free(mem_ctx2);
     314                return r.out.result;
    298315        }
    299316        if (sids.count != 1) {
     
    333350        r.in.rights = rights;
    334351
    335         return dcerpc_lsa_AddAccountRights(cli->lsa->pipe, mem_ctx, &r);
     352        status = dcerpc_lsa_AddAccountRights_r(cli->lsa->pipe->binding_handle, mem_ctx, &r);
     353        if (!NT_STATUS_IS_OK(status)) {
     354                return status;
     355        }
     356
     357        return r.out.result;
    336358}
    337359
     
    356378        r.in.rights = rights;
    357379
    358         return dcerpc_lsa_RemoveAccountRights(cli->lsa->pipe, mem_ctx, &r);
    359 }
     380        status = dcerpc_lsa_RemoveAccountRights_r(cli->lsa->pipe->binding_handle, mem_ctx, &r);
     381        if (!NT_STATUS_IS_OK(status)) {
     382                return status;
     383        }
     384
     385        return r.out.result;
     386}
  • vendor/current/source4/libcli/util/errormap.c

    r414 r740  
    2121
    2222#include "includes.h"
    23 #include "librpc/ndr/libndr.h"
    2423
    2524/* This map was extracted by the ERRMAPEXTRACT smbtorture command.
     
    180179*/
    181180        {ERRSRV,        ERRbadpw,       NT_STATUS_WRONG_PASSWORD},
     181        {ERRSRV,        ERRbaduid,      NT_STATUS_USER_SESSION_DELETED},
    182182        {ERRHRD,        ERRgeneral,     NT_STATUS_ILL_FORMED_PASSWORD},
    183183        {ERRHRD,        ERRgeneral,     NT_STATUS_PASSWORD_RESTRICTION},
     
    13221322#endif
    13231323#ifdef EDQUOT
    1324         { EDQUOT,       NT_STATUS_QUOTA_EXCEEDED },
     1324        { EDQUOT,       NT_STATUS_DISK_FULL }, /* Windows does NOT return NT_STATUS_QUOTA_EXCEEDED */
    13251325#endif
    13261326#ifdef ENOTEMPTY
     
    13831383}
    13841384
    1385 NTSTATUS ndr_map_error2ntstatus(enum ndr_err_code ndr_err)
     1385/* Convert a Unix error code to WERROR */
     1386WERROR unix_to_werror(int unix_error)
    13861387{
    1387         switch (ndr_err) {
    1388         case NDR_ERR_SUCCESS:
    1389                 return NT_STATUS_OK;
    1390         case NDR_ERR_BUFSIZE:
    1391                 return NT_STATUS_BUFFER_TOO_SMALL;
    1392         case NDR_ERR_TOKEN:
    1393                 return NT_STATUS_INTERNAL_ERROR;
    1394         case NDR_ERR_ALLOC:
    1395                 return NT_STATUS_NO_MEMORY;
    1396         case NDR_ERR_ARRAY_SIZE:
    1397                 return NT_STATUS_ARRAY_BOUNDS_EXCEEDED;
    1398         case NDR_ERR_INVALID_POINTER:
    1399                 return NT_STATUS_INVALID_PARAMETER_MIX;
    1400         case NDR_ERR_UNREAD_BYTES:
    1401                 return NT_STATUS_PORT_MESSAGE_TOO_LONG;
    1402         default:
    1403                 break;
    1404         }
    1405 
    1406         /* we should map all error codes to different status codes */
    1407         return NT_STATUS_INVALID_PARAMETER;
     1388        return ntstatus_to_werror(map_nt_error_from_unix(unix_error));
    14081389}
  • vendor/current/source4/libcli/util/nterr.c

    r414 r740  
    1 /* 
     1/*
    22 *  Unix SMB/CIFS implementation.
    33 *  RPC Pipe client / server routines
    44 *  Copyright (C) Luke Kenneth Casson Leighton 1997-2001.
    5  * 
     5 *
    66 *  This program is free software; you can redistribute it and/or modify
    77 *  it under the terms of the GNU General Public License as published by
    88 *  the Free Software Foundation; either version 3 of the License, or
    99 *  (at your option) any later version.
    10  * 
     10 *
    1111 *  This program is distributed in the hope that it will be useful,
    1212 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
    1313 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1414 *  GNU General Public License for more details.
    15  * 
     15 *
    1616 *  You should have received a copy of the GNU General Public License
    1717 *  along with this program; if not, see <http://www.gnu.org/licenses/>.
     
    2323#include "../libcli/ldap/ldap_errors.h"
    2424#undef strcasecmp
     25
     26#if !defined(N_)
     27#define N_(string) string
     28#endif
    2529
    2630typedef struct
     
    544548        { "NT_STATUS_FILE_IS_OFFLINE", NT_STATUS_FILE_IS_OFFLINE },
    545549        { "NT_STATUS_DS_NO_MORE_RIDS", NT_STATUS_DS_NO_MORE_RIDS },
    546         { "NT_STATUS_NO_MORE_ENTRIES", NT_STATUS_NO_MORE_ENTRIES },
     550        { "NT_STATUS_NOT_A_REPARSE_POINT", NT_STATUS_NOT_A_REPARSE_POINT },
     551        { "NT_STATUS_NO_MORE_ENTRIES", NT_STATUS_NO_MORE_ENTRIES },
    547552        { "NT_STATUS_RPC_PROTSEQ_NOT_SUPPORTED", NT_STATUS_RPC_PROTSEQ_NOT_SUPPORTED },
    548553        { "NT_STATUS_RPC_UNSUPPORTED_NAME_SYNTAX", NT_STATUS_RPC_UNSUPPORTED_NAME_SYNTAX },
     554        { "NT_STATUS_RPC_UNKNOWN_IF", NT_STATUS_RPC_UNKNOWN_IF },
     555        { "NT_STATUS_RPC_CALL_FAILED", NT_STATUS_RPC_CALL_FAILED },
     556        { "NT_STATUS_RPC_PROTOCOL_ERROR", NT_STATUS_RPC_PROTOCOL_ERROR },
     557        { "NT_STATUS_RPC_PROCNUM_OUT_OF_RANGE", NT_STATUS_RPC_PROCNUM_OUT_OF_RANGE },
     558        { "NT_STATUS_RPC_CANNOT_SUPPORT", NT_STATUS_RPC_CANNOT_SUPPORT },
     559        { "NT_STATUS_RPC_SEC_PKG_ERROR", NT_STATUS_RPC_SEC_PKG_ERROR },
     560        { "NT_STATUS_RPC_SS_CONTEXT_MISMATCH", NT_STATUS_RPC_SS_CONTEXT_MISMATCH },
     561        { "NT_STATUS_RPC_ENUM_VALUE_OUT_OF_RANGE", NT_STATUS_RPC_ENUM_VALUE_OUT_OF_RANGE },
     562        { "NT_STATUS_RPC_BAD_STUB_DATA", NT_STATUS_RPC_BAD_STUB_DATA },
     563        { "NT_STATUS_RPC_INVALID_PIPE_OBJECT", NT_STATUS_RPC_INVALID_PIPE_OBJECT },
     564        { "NT_STATUS_RPC_INVALID_PIPE_OPERATION", NT_STATUS_RPC_INVALID_PIPE_OPERATION },
     565        { "NT_STATUS_RPC_WRONG_PIPE_VERSION", NT_STATUS_RPC_WRONG_PIPE_VERSION },
     566        { "NT_STATUS_RPC_PIPE_CLOSED", NT_STATUS_RPC_PIPE_CLOSED },
     567        { "NT_STATUS_RPC_PIPE_DISCIPLINE_ERROR", NT_STATUS_RPC_PIPE_DISCIPLINE_ERROR },
     568        { "NT_STATUS_RPC_PIPE_EMPTY", NT_STATUS_RPC_PIPE_EMPTY },
    549569        { "NT_STATUS_CURRENT_DOMAIN_NOT_ALLOWED", NT_STATUS_CURRENT_DOMAIN_NOT_ALLOWED },
    550570        { "NT_STATUS_OBJECTID_NOT_FOUND", NT_STATUS_OBJECTID_NOT_FOUND },
    551571        { "NT_STATUS_DOWNGRADE_DETECTED", NT_STATUS_DOWNGRADE_DETECTED },
     572        { "NT_STATUS_NO_S4U_PROT_SUPPORT", NT_STATUS_NO_S4U_PROT_SUPPORT },
     573        { "NT_STATUS_CROSSREALM_DELEGATION_FAILURE", NT_STATUS_CROSSREALM_DELEGATION_FAILURE },
    552574        { "NT_STATUS_INVALID_LOCK_RANGE", NT_STATUS_INVALID_LOCK_RANGE },
    553575        { "NT_STATUS_ERROR_DS_OBJ_STRING_NAME_EXISTS", NT_STATUS_ERROR_DS_OBJ_STRING_NAME_EXISTS },
     
    722744};
    723745
     746/* These need sorting..... */
     747
    724748static const nt_err_code_struct nt_err_desc[] =
    725749{
    726         { "Success",                            NT_STATUS_OK },
    727         { "Undetermined error",                 NT_STATUS_UNSUCCESSFUL },
    728         { "Access denied",                      NT_STATUS_ACCESS_DENIED },
    729         { "Account locked out",                 NT_STATUS_ACCOUNT_LOCKED_OUT },
    730         { "Must change password",               NT_STATUS_PASSWORD_MUST_CHANGE },
    731         { "Password is too short",              NT_STATUS_PWD_TOO_SHORT },
    732         { "Password is too recent",             NT_STATUS_PWD_TOO_RECENT },
    733         { "Password history conflict",          NT_STATUS_PWD_HISTORY_CONFLICT },
    734         { "No logon servers",                   NT_STATUS_NO_LOGON_SERVERS },
    735         { "Improperly formed account name",     NT_STATUS_INVALID_ACCOUNT_NAME },
    736         { "User exists",                        NT_STATUS_USER_EXISTS },
    737         { "No such user",                       NT_STATUS_NO_SUCH_USER },
    738         { "Group exists",                       NT_STATUS_GROUP_EXISTS },
    739         { "No such group",                      NT_STATUS_NO_SUCH_GROUP },
    740         { "Member not in group",                NT_STATUS_MEMBER_NOT_IN_GROUP },
    741         { "Wrong Password",                     NT_STATUS_WRONG_PASSWORD },
    742         { "Ill formed password",                NT_STATUS_ILL_FORMED_PASSWORD },
    743         { "Password restriction",               NT_STATUS_PASSWORD_RESTRICTION },
    744         { "Logon failure",                      NT_STATUS_LOGON_FAILURE },
    745         { "Account restriction",                NT_STATUS_ACCOUNT_RESTRICTION },
    746         { "Invalid logon hours",                NT_STATUS_INVALID_LOGON_HOURS },
    747         { "Invalid workstation",                NT_STATUS_INVALID_WORKSTATION },
    748         { "Password expired",                   NT_STATUS_PASSWORD_EXPIRED },
    749         { "Account disabled",                   NT_STATUS_ACCOUNT_DISABLED },
    750         { "Unexpected information received",    NT_STATUS_INVALID_PARAMETER },
    751         { "Memory allocation error",            NT_STATUS_NO_MEMORY },
    752         { "No domain controllers located",      NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND },
    753         { "Account locked out",                 NT_STATUS_ACCOUNT_LOCKED_OUT },
    754         { "Named pipe not available",           NT_STATUS_PIPE_NOT_AVAILABLE },
    755         { "Not implemented",                    NT_STATUS_NOT_IMPLEMENTED },
    756         { "Invalid information class",          NT_STATUS_INVALID_INFO_CLASS },
    757         { "Information length mismatch",        NT_STATUS_INFO_LENGTH_MISMATCH },
    758         { "Access violation",                   NT_STATUS_ACCESS_VIOLATION },
    759         { "Invalid handle",                     NT_STATUS_INVALID_HANDLE },
    760         { "Invalid parameter",                  NT_STATUS_INVALID_PARAMETER },
    761         { "No memory",                          NT_STATUS_NO_MEMORY },
    762         { "Buffer too small",                   NT_STATUS_BUFFER_TOO_SMALL },
    763         { "Revision mismatch",                  NT_STATUS_REVISION_MISMATCH },
    764         { "No logon servers",                   NT_STATUS_NO_LOGON_SERVERS },
    765         { "No such logon session",              NT_STATUS_NO_SUCH_LOGON_SESSION },
    766         { "No such privilege",                  NT_STATUS_NO_SUCH_PRIVILEGE },
    767         { "Procedure not found",                NT_STATUS_PROCEDURE_NOT_FOUND },
    768         { "Server disabled",                    NT_STATUS_SERVER_DISABLED },
    769         { "Invalid pipe state",                 NT_STATUS_INVALID_PIPE_STATE },
    770         { "Named pipe busy",                    NT_STATUS_PIPE_BUSY },
    771         { "Illegal function",                   NT_STATUS_ILLEGAL_FUNCTION },
    772         { "Named pipe dicconnected",            NT_STATUS_PIPE_DISCONNECTED },
    773         { "Named pipe closing",                 NT_STATUS_PIPE_CLOSING },
    774         { "Remote host not listening",          NT_STATUS_REMOTE_NOT_LISTENING },
    775         { "Duplicate name on network",          NT_STATUS_DUPLICATE_NAME },
    776         { "Print queue is full",                NT_STATUS_PRINT_QUEUE_FULL },
    777         { "No print spool space available",     NT_STATUS_NO_SPOOL_SPACE },
    778         { "Too many names",                     NT_STATUS_TOO_MANY_NAMES },
    779         { "Too many sessions",                  NT_STATUS_TOO_MANY_SESSIONS },
    780         { "Invalid server state",               NT_STATUS_INVALID_SERVER_STATE },
    781         { "Invalid domain state",               NT_STATUS_INVALID_DOMAIN_STATE },
    782         { "Invalid domain role",                NT_STATUS_INVALID_DOMAIN_ROLE },
    783         { "No such domain",                     NT_STATUS_NO_SUCH_DOMAIN },
    784         { "Domain exists",                      NT_STATUS_DOMAIN_EXISTS },
    785         { "Domain limit exceeded",              NT_STATUS_DOMAIN_LIMIT_EXCEEDED },
    786         { "Bad logon session state",            NT_STATUS_BAD_LOGON_SESSION_STATE },
    787         { "Logon session collision",            NT_STATUS_LOGON_SESSION_COLLISION },
    788         { "Invalid logon type",                 NT_STATUS_INVALID_LOGON_TYPE },
    789         { "Cancelled",                          NT_STATUS_CANCELLED },
    790         { "Invalid computer name",              NT_STATUS_INVALID_COMPUTER_NAME },     
    791         { "Logon server conflict",              NT_STATUS_LOGON_SERVER_CONFLICT },
    792         { "Time difference at domain controller", NT_STATUS_TIME_DIFFERENCE_AT_DC },
    793         { "Pipe broken",                        NT_STATUS_PIPE_BROKEN },
    794         { "Registry corrupt",                   NT_STATUS_REGISTRY_CORRUPT },
    795         { "Too many secrets",                   NT_STATUS_TOO_MANY_SECRETS },
    796         { "Too many SIDs",                      NT_STATUS_TOO_MANY_SIDS },
    797         { "Lanmanager cross encryption required", NT_STATUS_LM_CROSS_ENCRYPTION_REQUIRED },
    798         { "Log file full",                      NT_STATUS_LOG_FILE_FULL },
    799         { "No trusted LSA secret",              NT_STATUS_NO_TRUST_LSA_SECRET },
    800         { "No trusted SAM account",             NT_STATUS_NO_TRUST_SAM_ACCOUNT },
    801         { "Trusted domain failure",             NT_STATUS_TRUSTED_DOMAIN_FAILURE },
    802         { "Trust relationship failure",         NT_STATUS_TRUSTED_RELATIONSHIP_FAILURE },
    803         { "Trust failure",                      NT_STATUS_TRUST_FAILURE },
    804         { "Netlogon service not started",       NT_STATUS_NETLOGON_NOT_STARTED },
    805         { "Account expired",                    NT_STATUS_ACCOUNT_EXPIRED },
    806         { "Network credential conflict",        NT_STATUS_NETWORK_CREDENTIAL_CONFLICT },
    807         { "Remote session limit",               NT_STATUS_REMOTE_SESSION_LIMIT },
    808         { "No logon interdomain trust account", NT_STATUS_NOLOGON_INTERDOMAIN_TRUST_ACCOUNT },
    809         { "No logon workstation trust account", NT_STATUS_NOLOGON_WORKSTATION_TRUST_ACCOUNT },
    810         { "No logon server trust account",      NT_STATUS_NOLOGON_SERVER_TRUST_ACCOUNT },
    811         { "Domain trust inconsistent",          NT_STATUS_DOMAIN_TRUST_INCONSISTENT },
    812         { "No user session key available",      NT_STATUS_NO_USER_SESSION_KEY },
    813         { "User session deleted",               NT_STATUS_USER_SESSION_DELETED },
    814         { "Insufficient server resources",      NT_STATUS_INSUFF_SERVER_RESOURCES },
    815         { "Insufficient logon information",     NT_STATUS_INSUFFICIENT_LOGON_INFO },
    816        
    817         { "License quota exceeded",             NT_STATUS_LICENSE_QUOTA_EXCEEDED },
     750        { N_("Success"),                                NT_STATUS_OK },
     751        { N_("Undetermined error"),             NT_STATUS_UNSUCCESSFUL },
     752        { N_("Access denied"),                  NT_STATUS_ACCESS_DENIED },
     753        { N_("Account locked out"),             NT_STATUS_ACCOUNT_LOCKED_OUT },
     754        { N_("Must change password"),           NT_STATUS_PASSWORD_MUST_CHANGE },
     755        { N_("Password is too short"),          NT_STATUS_PWD_TOO_SHORT },
     756        { N_("Password is too recent"),                 NT_STATUS_PWD_TOO_RECENT },
     757        { N_("Password history conflict"),              NT_STATUS_PWD_HISTORY_CONFLICT },
     758        { N_("No logon servers"),                       NT_STATUS_NO_LOGON_SERVERS },
     759        { N_("Improperly formed account name"),         NT_STATUS_INVALID_ACCOUNT_NAME },
     760        { N_("User exists"),                    NT_STATUS_USER_EXISTS },
     761        { N_("No such user"),                   NT_STATUS_NO_SUCH_USER },
     762        { N_("Group exists"),                   NT_STATUS_GROUP_EXISTS },
     763        { N_("No such group"),                  NT_STATUS_NO_SUCH_GROUP },
     764        { N_("Member not in group"),            NT_STATUS_MEMBER_NOT_IN_GROUP },
     765        { N_("Wrong Password"),                         NT_STATUS_WRONG_PASSWORD },
     766        { N_("Ill formed password"),            NT_STATUS_ILL_FORMED_PASSWORD },
     767        { N_("Password restriction"),           NT_STATUS_PASSWORD_RESTRICTION },
     768        { N_("Logon failure"),                  NT_STATUS_LOGON_FAILURE },
     769        { N_("Account restriction"),            NT_STATUS_ACCOUNT_RESTRICTION },
     770        { N_("Invalid logon hours"),            NT_STATUS_INVALID_LOGON_HOURS },
     771        { N_("Invalid workstation"),            NT_STATUS_INVALID_WORKSTATION },
     772        { N_("Password expired"),                       NT_STATUS_PASSWORD_EXPIRED },
     773        { N_("Account disabled"),                       NT_STATUS_ACCOUNT_DISABLED },
     774        { N_("Unexpected information received"),        NT_STATUS_INVALID_PARAMETER },
     775        { N_("Memory allocation error"),                NT_STATUS_NO_MEMORY },
     776        { N_("No domain controllers located"),  NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND },
     777        { N_("Account locked out"),             NT_STATUS_ACCOUNT_LOCKED_OUT },
     778        { N_("Named pipe not available"),               NT_STATUS_PIPE_NOT_AVAILABLE },
     779        { N_("Not implemented"),                        NT_STATUS_NOT_IMPLEMENTED },
     780        { N_("Invalid information class"),              NT_STATUS_INVALID_INFO_CLASS },
     781        { N_("Information length mismatch"),    NT_STATUS_INFO_LENGTH_MISMATCH },
     782        { N_("Access violation"),                       NT_STATUS_ACCESS_VIOLATION },
     783        { N_("Invalid handle"),                         NT_STATUS_INVALID_HANDLE },
     784        { N_("Invalid parameter"),                      NT_STATUS_INVALID_PARAMETER },
     785        { N_("No memory"),                              NT_STATUS_NO_MEMORY },
     786        { N_("Buffer too small"),                       NT_STATUS_BUFFER_TOO_SMALL },
     787        { N_("Revision mismatch"),                      NT_STATUS_REVISION_MISMATCH },
     788        { N_("No logon servers"),                       NT_STATUS_NO_LOGON_SERVERS },
     789        { N_("No such logon session"),          NT_STATUS_NO_SUCH_LOGON_SESSION },
     790        { N_("No such privilege"),                      NT_STATUS_NO_SUCH_PRIVILEGE },
     791        { N_("Procedure not found"),            NT_STATUS_PROCEDURE_NOT_FOUND },
     792        { N_("Server disabled"),                        NT_STATUS_SERVER_DISABLED },
     793        { N_("Invalid pipe state"),             NT_STATUS_INVALID_PIPE_STATE },
     794        { N_("Named pipe busy"),                        NT_STATUS_PIPE_BUSY },
     795        { N_("Illegal function"),                       NT_STATUS_ILLEGAL_FUNCTION },
     796        { N_("Named pipe disconnected"),                NT_STATUS_PIPE_DISCONNECTED },
     797        { N_("Named pipe closing"),             NT_STATUS_PIPE_CLOSING },
     798        { N_("Remote host not listening"),              NT_STATUS_REMOTE_NOT_LISTENING },
     799        { N_("Duplicate name on network"),              NT_STATUS_DUPLICATE_NAME },
     800        { N_("Print queue is full"),            NT_STATUS_PRINT_QUEUE_FULL },
     801        { N_("No print spool space available"),         NT_STATUS_NO_SPOOL_SPACE },
     802        { N_("The network name cannot be found"),   NT_STATUS_BAD_NETWORK_NAME },
     803        { N_("The connection was refused"),         NT_STATUS_CONNECTION_REFUSED },
     804        { N_("Too many names"),                         NT_STATUS_TOO_MANY_NAMES },
     805        { N_("Too many sessions"),                      NT_STATUS_TOO_MANY_SESSIONS },
     806        { N_("Invalid server state"),           NT_STATUS_INVALID_SERVER_STATE },
     807        { N_("Invalid domain state"),           NT_STATUS_INVALID_DOMAIN_STATE },
     808        { N_("Invalid domain role"),            NT_STATUS_INVALID_DOMAIN_ROLE },
     809        { N_("No such domain"),                         NT_STATUS_NO_SUCH_DOMAIN },
     810        { N_("Domain exists"),                  NT_STATUS_DOMAIN_EXISTS },
     811        { N_("Domain limit exceeded"),          NT_STATUS_DOMAIN_LIMIT_EXCEEDED },
     812        { N_("Bad logon session state"),                NT_STATUS_BAD_LOGON_SESSION_STATE },
     813        { N_("Logon session collision"),                NT_STATUS_LOGON_SESSION_COLLISION },
     814        { N_("Invalid logon type"),             NT_STATUS_INVALID_LOGON_TYPE },
     815        { N_("Cancelled"),                              NT_STATUS_CANCELLED },
     816        { N_("Invalid computer name"),          NT_STATUS_INVALID_COMPUTER_NAME },
     817        { N_("Logon server conflict"),          NT_STATUS_LOGON_SERVER_CONFLICT },
     818        { N_("Time difference at domain controller"), NT_STATUS_TIME_DIFFERENCE_AT_DC },
     819        { N_("Pipe broken"),                    NT_STATUS_PIPE_BROKEN },
     820        { N_("Registry corrupt"),                       NT_STATUS_REGISTRY_CORRUPT },
     821        { N_("Too many secrets"),                       NT_STATUS_TOO_MANY_SECRETS },
     822        { N_("Too many SIDs"),                  NT_STATUS_TOO_MANY_SIDS },
     823        { N_("Lanmanager cross encryption required"), NT_STATUS_LM_CROSS_ENCRYPTION_REQUIRED },
     824        { N_("Log file full"),                  NT_STATUS_LOG_FILE_FULL },
     825        { N_("No trusted LSA secret"),          NT_STATUS_NO_TRUST_LSA_SECRET },
     826        { N_("No trusted SAM account"),                 NT_STATUS_NO_TRUST_SAM_ACCOUNT },
     827        { N_("Trusted domain failure"),                 NT_STATUS_TRUSTED_DOMAIN_FAILURE },
     828        { N_("Trust relationship failure"),     NT_STATUS_TRUSTED_RELATIONSHIP_FAILURE },
     829        { N_("Trust failure"),                  NT_STATUS_TRUST_FAILURE },
     830        { N_("Netlogon service not started"),   NT_STATUS_NETLOGON_NOT_STARTED },
     831        { N_("Account expired"),                        NT_STATUS_ACCOUNT_EXPIRED },
     832        { N_("Network credential conflict"),    NT_STATUS_NETWORK_CREDENTIAL_CONFLICT },
     833        { N_("Remote session limit"),           NT_STATUS_REMOTE_SESSION_LIMIT },
     834        { N_("No logon interdomain trust account"), NT_STATUS_NOLOGON_INTERDOMAIN_TRUST_ACCOUNT },
     835        { N_("No logon workstation trust account"), NT_STATUS_NOLOGON_WORKSTATION_TRUST_ACCOUNT },
     836        { N_("No logon server trust account"),  NT_STATUS_NOLOGON_SERVER_TRUST_ACCOUNT },
     837        { N_("Domain trust inconsistent"),              NT_STATUS_DOMAIN_TRUST_INCONSISTENT },
     838        { N_("No user session key available"),  NT_STATUS_NO_USER_SESSION_KEY },
     839        { N_("User session deleted"),           NT_STATUS_USER_SESSION_DELETED },
     840        { N_("Insufficient server resources"),  NT_STATUS_INSUFF_SERVER_RESOURCES },
     841        { N_("Insufficient logon information"),         NT_STATUS_INSUFFICIENT_LOGON_INFO },
     842
     843        { N_("License quota exceeded"),                 NT_STATUS_LICENSE_QUOTA_EXCEEDED },
     844        { N_("No more files"),                  STATUS_NO_MORE_FILES },
    818845
    819846        { NULL, NT_STATUS(0) }
     
    821848
    822849/*****************************************************************************
    823  returns an NT error message.  not amazingly helpful, but better than a number.
     850 Returns an NT error message.  not amazingly helpful, but better than a number.
    824851 *****************************************************************************/
     852
    825853const char *nt_errstr(NTSTATUS nt_code)
    826854{
    827         static char msg[40];
    828         int idx = 0;
     855        static char msg[40];
     856        int idx = 0;
    829857
    830858        while (nt_errs[idx].nt_errstr != NULL) {
    831                 if (NT_STATUS_V(nt_errs[idx].nt_errcode) == 
    832                     NT_STATUS_V(nt_code)) {
    833                         return nt_errs[idx].nt_errstr;
     859                if (NT_STATUS_V(nt_errs[idx].nt_errcode) ==
     860                    NT_STATUS_V(nt_code)) {
     861                        return nt_errs[idx].nt_errstr;
    834862                }
    835863                idx++;
     
    843871        slprintf(msg, sizeof(msg), "NT code 0x%08x", NT_STATUS_V(nt_code));
    844872
    845         return msg;
     873        return msg;
    846874}
    847875
     
    849877 Print friendler version fo NT error code
    850878 ***********************************************************************/
     879
    851880const char *get_friendly_nt_error_msg(NTSTATUS nt_code)
    852881{
    853         int idx = 0;
     882        int idx = 0;
    854883
    855884        while (nt_err_desc[idx].nt_errstr != NULL) {
    856885                if (NT_STATUS_V(nt_err_desc[idx].nt_errcode) == NT_STATUS_V(nt_code)) {
    857                         return nt_err_desc[idx].nt_errstr;
     886                        return nt_err_desc[idx].nt_errstr;
    858887                }
    859888                idx++;
    860889        }
    861        
     890
    862891        /* fall back to NT_STATUS_XXX string */
     892
    863893        return nt_errstr(nt_code);
    864894}
    865895
    866896/*****************************************************************************
    867  returns an NT_STATUS constant as a string for inclusion in autogen C code
     897 Returns an NT_STATUS constant as a string for inclusion in autogen C code.
    868898 *****************************************************************************/
     899
    869900const char *get_nt_error_c_code(NTSTATUS nt_code)
    870901{
    871         static char out[40];
    872         int idx = 0;
     902        static char out[40];
     903        int idx = 0;
    873904
    874905        while (nt_errs[idx].nt_errstr != NULL) {
    875                 if (NT_STATUS_V(nt_errs[idx].nt_errcode) == 
    876                     NT_STATUS_V(nt_code)) {
    877                         return nt_errs[idx].nt_errstr;
     906                if (NT_STATUS_V(nt_errs[idx].nt_errcode) ==
     907                    NT_STATUS_V(nt_code)) {
     908                        return nt_errs[idx].nt_errstr;
    878909                }
    879910                idx++;
     
    882913        slprintf(out, sizeof(out), "NT_STATUS(0x%08x)", NT_STATUS_V(nt_code));
    883914
    884         return out;
     915        return out;
    885916}
    886917
    887918/*****************************************************************************
    888  returns the NT_STATUS constant matching the string supplied (as an NTSTATUS)
     919 Returns the NT_STATUS constant matching the string supplied (as an NTSTATUS)
    889920 *****************************************************************************/
     921
    890922NTSTATUS nt_status_string_to_code(const char *nt_status_str)
    891923{
    892         int idx = 0;
     924        int idx = 0;
    893925
    894926        while (nt_errs[idx].nt_errstr != NULL) {
    895927                if (strcasecmp(nt_errs[idx].nt_errstr, nt_status_str) == 0) {
    896                         return nt_errs[idx].nt_errcode;
     928                        return nt_errs[idx].nt_errcode;
    897929                }
    898930                idx++;
     
    900932        return NT_STATUS_UNSUCCESSFUL;
    901933}
     934
     935/**
     936 * Squash an NT_STATUS in line with security requirements.
     937 * In an attempt to avoid giving the whole game away when users
     938 * are authenticating, NT replaces both NT_STATUS_NO_SUCH_USER and
     939 * NT_STATUS_WRONG_PASSWORD with NT_STATUS_LOGON_FAILURE in certain situations
     940 * (session setups in particular).
     941 *
     942 * @param nt_status NTSTATUS input for squashing.
     943 * @return the 'squashed' nt_status
     944 **/
     945
     946NTSTATUS nt_status_squash(NTSTATUS nt_status)
     947{
     948        if NT_STATUS_IS_OK(nt_status) {
     949                return nt_status;
     950        } else if NT_STATUS_EQUAL(nt_status, NT_STATUS_NO_SUCH_USER) {
     951                /* Match WinXP and don't give the game away */
     952                return NT_STATUS_LOGON_FAILURE;
     953
     954        } else if NT_STATUS_EQUAL(nt_status, NT_STATUS_WRONG_PASSWORD) {
     955                /* Match WinXP and don't give the game away */
     956                return NT_STATUS_LOGON_FAILURE;
     957        } else {
     958                return nt_status;
     959        }
     960}
  • vendor/current/source4/libcli/util/pyerrors.h

    r414 r740  
    2525#define PyErr_FromNTSTATUS(status) Py_BuildValue("(i,s)", NT_STATUS_V(status), discard_const_p(char, get_friendly_nt_error_msg(status)))
    2626
     27#define PyErr_FromString(str) Py_BuildValue("(s)", discard_const_p(char, str))
     28
    2729#define PyErr_SetWERROR(err) \
    2830        PyErr_SetObject(PyExc_RuntimeError, PyErr_FromWERROR(err))
  • vendor/current/source4/libcli/wbclient/wbclient.c

    r414 r740  
    2121
    2222#include "includes.h"
     23#include <tevent.h>
    2324#include "libcli/wbclient/wbclient.h"
    24 
    25 /**
    26  * Get the server_id of the winbind task.
    27  *
    28  * \param[in] msg_ctx message context to use
    29  * \param[in] mem_ctx talloc context to use
    30  * \param[out] ids array of server_id structs containing the winbind id
    31  * \return NT_STATUS_OK on success, NT_STATUS_INTERNAL_ERROR on failure
    32  */
    33 static NTSTATUS get_server_id(struct messaging_context *msg_ctx,
    34                               TALLOC_CTX *mem_ctx, struct server_id **ids)
    35 {
    36         *ids = irpc_servers_byname(msg_ctx, mem_ctx, "winbind_server");
    37         if (*ids == NULL || (*ids)[0].id == 0) {
    38                 DEBUG(0, ("Geting the winbind server ID failed.\n"));
    39                 return NT_STATUS_INTERNAL_ERROR;
    40         }
    41         return NT_STATUS_OK;
    42 }
    4325
    4426/**
     
    5436{
    5537        struct wbc_context *ctx;
    56         NTSTATUS status;
    5738
    5839        ctx = talloc(mem_ctx, struct wbc_context);
    5940        if (ctx == NULL) return NULL;
    6041
    61         status = get_server_id(msg_ctx, mem_ctx, &ctx->ids);
    62         if (!NT_STATUS_IS_OK(status)) {
     42        ctx->event_ctx = event_ctx;
     43
     44        ctx->irpc_handle = irpc_binding_handle_by_name(ctx, msg_ctx,
     45                                                       "winbind_server",
     46                                                       &ndr_table_winbind);
     47        if (ctx->irpc_handle == NULL) {
    6348                talloc_free(ctx);
    6449                return NULL;
    6550        }
    66 
    67         ctx->msg_ctx = msg_ctx;
    68         ctx->event_ctx = event_ctx;
    6951
    7052        return ctx;
     
    7456        struct composite_context *ctx;
    7557        struct winbind_get_idmap *req;
    76         struct irpc_request *irpc_req;
    77         struct id_mapping *ids;
     58        struct id_map *ids;
    7859};
    7960
    80 static void sids_to_xids_recv_ids(struct irpc_request *req);
     61static void sids_to_xids_recv_ids(struct tevent_req *subreq);
    8162
    8263struct composite_context *wbc_sids_to_xids_send(struct wbc_context *wbc_ctx,
    8364                                                TALLOC_CTX *mem_ctx,
    8465                                                uint32_t count,
    85                                                 struct id_mapping *ids)
     66                                                struct id_map *ids)
    8667{
    8768        struct composite_context *ctx;
    8869        struct wbc_idmap_state *state;
     70        struct tevent_req *subreq;
    8971
    9072        DEBUG(5, ("wbc_sids_to_xids called\n"));
     
    10587        state->ctx = ctx;
    10688
    107         state->irpc_req = IRPC_CALL_SEND(wbc_ctx->msg_ctx, wbc_ctx->ids[0],
    108                                          winbind, WINBIND_GET_IDMAP, state->req,
    109                                          state);
    110         if (composite_nomem(state->irpc_req, ctx)) return ctx;
     89        subreq = dcerpc_winbind_get_idmap_r_send(state,
     90                                                 wbc_ctx->event_ctx,
     91                                                 wbc_ctx->irpc_handle,
     92                                                 state->req);
     93        if (composite_nomem(subreq, ctx)) return ctx;
    11194
    112         composite_continue_irpc(ctx, state->irpc_req, sids_to_xids_recv_ids,
    113                                 state);
     95        tevent_req_set_callback(subreq, sids_to_xids_recv_ids, state);
     96
    11497        return ctx;
    11598}
    11699
    117 static void sids_to_xids_recv_ids(struct irpc_request *req)
     100static void sids_to_xids_recv_ids(struct tevent_req *subreq)
    118101{
    119         struct wbc_idmap_state *state = talloc_get_type_abort(
    120                                                         req->async.private_data,
    121                                                         struct wbc_idmap_state);
     102        struct wbc_idmap_state *state =
     103                tevent_req_callback_data(subreq,
     104                struct wbc_idmap_state);
    122105
    123         state->ctx->status = irpc_call_recv(state->irpc_req);
     106        state->ctx->status = dcerpc_winbind_get_idmap_r_recv(subreq, state);
     107        TALLOC_FREE(subreq);
    124108        if (!composite_is_ok(state->ctx)) return;
    125109
     
    129113
    130114NTSTATUS wbc_sids_to_xids_recv(struct composite_context *ctx,
    131                                struct id_mapping **ids)
     115                               struct id_map **ids)
    132116{
    133117        NTSTATUS status = composite_wait(ctx);
     
    143127}
    144128
    145 static void xids_to_sids_recv_ids(struct irpc_request *req);
     129static void xids_to_sids_recv_ids(struct tevent_req *subreq);
    146130
    147131struct composite_context *wbc_xids_to_sids_send(struct wbc_context *wbc_ctx,
    148132                                                TALLOC_CTX *mem_ctx,
    149133                                                uint32_t count,
    150                                                 struct id_mapping *ids)
     134                                                struct id_map *ids)
    151135{
    152136        struct composite_context *ctx;
    153137        struct wbc_idmap_state *state;
     138        struct tevent_req *subreq;
    154139
    155140        DEBUG(5, ("wbc_xids_to_sids called\n"));
     
    170155        state->ctx = ctx;
    171156
    172         state->irpc_req = IRPC_CALL_SEND(wbc_ctx->msg_ctx, wbc_ctx->ids[0],
    173                                          winbind, WINBIND_GET_IDMAP, state->req,
    174                                          state);
    175         if (composite_nomem(state->irpc_req, ctx)) return ctx;
     157        subreq = dcerpc_winbind_get_idmap_r_send(state,
     158                                                 wbc_ctx->event_ctx,
     159                                                 wbc_ctx->irpc_handle,
     160                                                 state->req);
     161        if (composite_nomem(subreq, ctx)) return ctx;
    176162
    177         composite_continue_irpc(ctx, state->irpc_req, xids_to_sids_recv_ids,
    178                         state);
     163        tevent_req_set_callback(subreq, xids_to_sids_recv_ids, state);
    179164
    180165        return ctx;
    181166}
    182167
    183 static void xids_to_sids_recv_ids(struct irpc_request *req)
     168static void xids_to_sids_recv_ids(struct tevent_req *subreq)
    184169{
    185         struct wbc_idmap_state *state = talloc_get_type_abort(
    186                                                         req->async.private_data,
    187                                                         struct wbc_idmap_state);
     170        struct wbc_idmap_state *state =
     171                tevent_req_callback_data(subreq,
     172                struct wbc_idmap_state);
    188173
    189         state->ctx->status = irpc_call_recv(state->irpc_req);
     174        state->ctx->status = dcerpc_winbind_get_idmap_r_recv(subreq, state);
     175        TALLOC_FREE(subreq);
    190176        if (!composite_is_ok(state->ctx)) return;
    191177
     
    195181
    196182NTSTATUS wbc_xids_to_sids_recv(struct composite_context *ctx,
    197                                struct id_mapping **ids)
     183                               struct id_map **ids)
    198184{
    199185        NTSTATUS status = composite_wait(ctx);
  • vendor/current/source4/libcli/wbclient/wbclient.h

    r414 r740  
    2121#include "lib/messaging/irpc.h"
    2222#include "libcli/composite/composite.h"
    23 #include "librpc/gen_ndr/ndr_winbind.h"
     23#include "librpc/gen_ndr/ndr_winbind_c.h"
    2424
    2525struct wbc_context {
    26         struct messaging_context *msg_ctx;
    2726        struct tevent_context *event_ctx;
    28         struct server_id *ids;
     27        struct dcerpc_binding_handle *irpc_handle;
    2928};
    3029
     
    3635                                                TALLOC_CTX *mem_ctx,
    3736                                                uint32_t count,
    38                                                 struct id_mapping *ids);
     37                                                struct id_map *ids);
    3938
    4039NTSTATUS wbc_sids_to_xids_recv(struct composite_context *ctx,
    41                                struct id_mapping **ids);
     40                               struct id_map **ids);
    4241
    4342struct composite_context *wbc_xids_to_sids_send(struct wbc_context *wbc_ctx,
    4443                                                TALLOC_CTX *mem_ctx,
    4544                                                uint32_t count,
    46                                                 struct id_mapping *ids);
     45                                                struct id_map *ids);
    4746
    4847NTSTATUS wbc_xids_to_sids_recv(struct composite_context *ctx,
    49                                struct id_mapping **ids);
     48                               struct id_map **ids);
    5049
  • vendor/current/source4/libcli/wrepl/winsrepl.c

    r414 r740  
    55
    66   Copyright (C) Andrew Tridgell 2005
     7   Copyright (C) Stefan Metzmacher 2005-2010
    78   
    89   This program is free software; you can redistribute it and/or modify
     
    2324#include "lib/events/events.h"
    2425#include "../lib/util/dlinklist.h"
    25 #include "lib/socket/socket.h"
    2626#include "libcli/wrepl/winsrepl.h"
    2727#include "librpc/gen_ndr/ndr_winsrepl.h"
    2828#include "lib/stream/packet.h"
    29 #include "libcli/composite/composite.h"
    3029#include "system/network.h"
    3130#include "lib/socket/netif.h"
    3231#include "param/param.h"
    33 
    34 static struct wrepl_request *wrepl_request_finished(struct wrepl_request *req, NTSTATUS status);
    35 
    36 /*
    37   mark all pending requests as dead - called when a socket error happens
    38 */
    39 static void wrepl_socket_dead(struct wrepl_socket *wrepl_socket, NTSTATUS status)
    40 {
    41         wrepl_socket->dead = true;
    42 
    43         if (wrepl_socket->packet) {
    44                 packet_recv_disable(wrepl_socket->packet);
    45                 packet_set_fde(wrepl_socket->packet, NULL);
    46                 packet_set_socket(wrepl_socket->packet, NULL);
    47         }
    48 
    49         if (wrepl_socket->event.fde) {
    50                 talloc_free(wrepl_socket->event.fde);
    51                 wrepl_socket->event.fde = NULL;
    52         }
    53 
    54         if (wrepl_socket->sock) {
    55                 talloc_free(wrepl_socket->sock);
    56                 wrepl_socket->sock = NULL;
    57         }
    58 
    59         if (NT_STATUS_EQUAL(NT_STATUS_UNSUCCESSFUL, status)) {
    60                 status = NT_STATUS_UNEXPECTED_NETWORK_ERROR;
    61         }
    62         while (wrepl_socket->recv_queue) {
    63                 struct wrepl_request *req = wrepl_socket->recv_queue;
    64                 DLIST_REMOVE(wrepl_socket->recv_queue, req);
    65                 wrepl_request_finished(req, status);
    66         }
    67 
    68         talloc_set_destructor(wrepl_socket, NULL);
    69         if (wrepl_socket->free_skipped) {
    70                 talloc_free(wrepl_socket);
    71         }
    72 }
    73 
    74 static void wrepl_request_timeout_handler(struct tevent_context *ev, struct tevent_timer *te,
    75                                           struct timeval t, void *ptr)
    76 {
    77         struct wrepl_request *req = talloc_get_type(ptr, struct wrepl_request);
    78         wrepl_socket_dead(req->wrepl_socket, NT_STATUS_IO_TIMEOUT);
    79 }
    80 
    81 /*
    82   handle recv events
    83 */
    84 static NTSTATUS wrepl_finish_recv(void *private_data, DATA_BLOB packet_blob_in)
    85 {
    86         struct wrepl_socket *wrepl_socket = talloc_get_type(private_data, struct wrepl_socket);
    87         struct wrepl_request *req = wrepl_socket->recv_queue;
    88         DATA_BLOB blob;
    89         enum ndr_err_code ndr_err;
    90 
    91         if (!req) {
    92                 DEBUG(1,("Received unexpected WINS packet of length %u!\n",
    93                          (unsigned)packet_blob_in.length));
    94                 return NT_STATUS_INVALID_NETWORK_RESPONSE;
    95         }
    96 
    97         req->packet = talloc(req, struct wrepl_packet);
    98         NT_STATUS_HAVE_NO_MEMORY(req->packet);
    99 
    100         blob.data = packet_blob_in.data + 4;
    101         blob.length = packet_blob_in.length - 4;
    102        
    103         /* we have a full request - parse it */
    104         ndr_err = ndr_pull_struct_blob(&blob, req->packet, wrepl_socket->iconv_convenience, req->packet,
    105                                        (ndr_pull_flags_fn_t)ndr_pull_wrepl_packet);
    106         if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
    107                 NTSTATUS status = ndr_map_error2ntstatus(ndr_err);
    108                 wrepl_request_finished(req, status);
    109                 return NT_STATUS_OK;
    110         }
    111 
    112         if (DEBUGLVL(10)) {
    113                 DEBUG(10,("Received WINS packet of length %u\n",
    114                           (unsigned)packet_blob_in.length));
    115                 NDR_PRINT_DEBUG(wrepl_packet, req->packet);
    116         }
    117 
    118         wrepl_request_finished(req, NT_STATUS_OK);
    119         return NT_STATUS_OK;
    120 }
    121 
    122 /*
    123   handler for winrepl events
    124 */
    125 static void wrepl_handler(struct tevent_context *ev, struct tevent_fd *fde,
    126                           uint16_t flags, void *private_data)
    127 {
    128         struct wrepl_socket *wrepl_socket = talloc_get_type(private_data,
    129                                                             struct wrepl_socket);
    130         if (flags & EVENT_FD_READ) {
    131                 packet_recv(wrepl_socket->packet);
    132                 return;
    133         }
    134         if (flags & EVENT_FD_WRITE) {
    135                 packet_queue_run(wrepl_socket->packet);
    136         }
    137 }
    138 
    139 static void wrepl_error(void *private_data, NTSTATUS status)
    140 {
    141         struct wrepl_socket *wrepl_socket = talloc_get_type(private_data,
    142                                                             struct wrepl_socket);
    143         wrepl_socket_dead(wrepl_socket, status);
    144 }
    145 
    146 
    147 /*
    148   destroy a wrepl_socket destructor
    149 */
    150 static int wrepl_socket_destructor(struct wrepl_socket *sock)
    151 {
    152         if (sock->dead) {
    153                 sock->free_skipped = true;
    154                 return -1;
    155         }
    156         wrepl_socket_dead(sock, NT_STATUS_LOCAL_DISCONNECT);
    157         return 0;
     32#include "lib/util/tevent_ntstatus.h"
     33#include "lib/tsocket/tsocket.h"
     34#include "libcli/util/tstream.h"
     35
     36/*
     37  main context structure for the wins replication client library
     38*/
     39struct wrepl_socket {
     40        struct {
     41                struct tevent_context *ctx;
     42        } event;
     43
     44        /* the default timeout for requests, 0 means no timeout */
     45#define WREPL_SOCKET_REQUEST_TIMEOUT    (60)
     46        uint32_t request_timeout;
     47
     48        struct tevent_queue *request_queue;
     49
     50        struct tstream_context *stream;
     51};
     52
     53bool wrepl_socket_is_connected(struct wrepl_socket *wrepl_sock)
     54{
     55        if (!wrepl_sock) {
     56                return false;
     57        }
     58
     59        if (!wrepl_sock->stream) {
     60                return false;
     61        }
     62
     63        return true;
    15864}
    15965
     
    16268  operations will use that event context
    16369*/
    164 struct wrepl_socket *wrepl_socket_init(TALLOC_CTX *mem_ctx,
    165                                        struct tevent_context *event_ctx,
    166                                        struct smb_iconv_convenience *iconv_convenience)
     70struct wrepl_socket *wrepl_socket_init(TALLOC_CTX *mem_ctx,
     71                                       struct tevent_context *event_ctx)
    16772{
    16873        struct wrepl_socket *wrepl_socket;
    169         NTSTATUS status;
    17074
    17175        wrepl_socket = talloc_zero(mem_ctx, struct wrepl_socket);
    172         if (!wrepl_socket) return NULL;
     76        if (!wrepl_socket) {
     77                return NULL;
     78        }
    17379
    17480        wrepl_socket->event.ctx = event_ctx;
    175         if (!wrepl_socket->event.ctx) goto failed;
    176 
    177         wrepl_socket->iconv_convenience = iconv_convenience;
    178 
    179         status = socket_create("ip", SOCKET_TYPE_STREAM, &wrepl_socket->sock, 0);
    180         if (!NT_STATUS_IS_OK(status)) goto failed;
    181 
    182         talloc_steal(wrepl_socket, wrepl_socket->sock);
     81        if (!wrepl_socket->event.ctx) {
     82                goto failed;
     83        }
     84
     85        wrepl_socket->request_queue = tevent_queue_create(wrepl_socket,
     86                                                          "wrepl request queue");
     87        if (wrepl_socket->request_queue == NULL) {
     88                goto failed;
     89        }
    18390
    18491        wrepl_socket->request_timeout   = WREPL_SOCKET_REQUEST_TIMEOUT;
    185 
    186         talloc_set_destructor(wrepl_socket, wrepl_socket_destructor);
    18792
    18893        return wrepl_socket;
     
    196101  initialise a wrepl_socket from an already existing connection
    197102*/
    198 struct wrepl_socket *wrepl_socket_merge(TALLOC_CTX *mem_ctx,
    199                                         struct tevent_context *event_ctx,
    200                                         struct socket_context *sock,
    201                                         struct packet_context *pack)
    202 {
    203         struct wrepl_socket *wrepl_socket;
    204 
    205         wrepl_socket = talloc_zero(mem_ctx, struct wrepl_socket);
    206         if (wrepl_socket == NULL) goto failed;
    207 
    208         wrepl_socket->event.ctx = event_ctx;
    209         if (wrepl_socket->event.ctx == NULL) goto failed;
    210 
    211         wrepl_socket->sock = sock;
    212         talloc_steal(wrepl_socket, wrepl_socket->sock);
    213 
    214 
    215         wrepl_socket->request_timeout   = WREPL_SOCKET_REQUEST_TIMEOUT;
    216 
    217         wrepl_socket->event.fde = event_add_fd(wrepl_socket->event.ctx, wrepl_socket,
    218                                                socket_get_fd(wrepl_socket->sock),
    219                                                EVENT_FD_READ,
    220                                                wrepl_handler, wrepl_socket);
    221         if (wrepl_socket->event.fde == NULL) {
    222                 goto failed;
    223         }
    224 
    225         wrepl_socket->packet = pack;
    226         talloc_steal(wrepl_socket, wrepl_socket->packet);
    227         packet_set_private(wrepl_socket->packet, wrepl_socket);
    228         packet_set_socket(wrepl_socket->packet, wrepl_socket->sock);
    229         packet_set_callback(wrepl_socket->packet, wrepl_finish_recv);
    230         packet_set_full_request(wrepl_socket->packet, packet_full_request_u32);
    231         packet_set_error_handler(wrepl_socket->packet, wrepl_error);
    232         packet_set_event_context(wrepl_socket->packet, wrepl_socket->event.ctx);
    233         packet_set_fde(wrepl_socket->packet, wrepl_socket->event.fde);
    234         packet_set_serialise(wrepl_socket->packet);
    235 
    236         talloc_set_destructor(wrepl_socket, wrepl_socket_destructor);
    237        
    238         return wrepl_socket;
    239 
    240 failed:
    241         talloc_free(wrepl_socket);
    242         return NULL;
    243 }
    244 
    245 /*
    246   destroy a wrepl_request
    247 */
    248 static int wrepl_request_destructor(struct wrepl_request *req)
    249 {
    250         if (req->state == WREPL_REQUEST_RECV) {
    251                 DLIST_REMOVE(req->wrepl_socket->recv_queue, req);
    252         }
    253         req->state = WREPL_REQUEST_ERROR;
    254         return 0;
    255 }
    256 
    257 /*
    258   wait for a request to complete
    259 */
    260 static NTSTATUS wrepl_request_wait(struct wrepl_request *req)
    261 {
    262         NT_STATUS_HAVE_NO_MEMORY(req);
    263         while (req->state < WREPL_REQUEST_DONE) {
    264                 event_loop_once(req->wrepl_socket->event.ctx);
    265         }
    266         return req->status;
     103NTSTATUS wrepl_socket_donate_stream(struct wrepl_socket *wrepl_socket,
     104                                    struct tstream_context **stream)
     105{
     106        if (wrepl_socket->stream) {
     107                return NT_STATUS_CONNECTION_ACTIVE;
     108        }
     109
     110        wrepl_socket->stream = talloc_move(wrepl_socket, stream);
     111        return NT_STATUS_OK;
     112}
     113
     114/*
     115  initialise a wrepl_socket from an already existing connection
     116*/
     117NTSTATUS wrepl_socket_split_stream(struct wrepl_socket *wrepl_socket,
     118                                   TALLOC_CTX *mem_ctx,
     119                                   struct tstream_context **stream)
     120{
     121        size_t num_requests;
     122
     123        if (!wrepl_socket->stream) {
     124                return NT_STATUS_CONNECTION_INVALID;
     125        }
     126
     127        num_requests = tevent_queue_length(wrepl_socket->request_queue);
     128        if (num_requests > 0) {
     129                return NT_STATUS_CONNECTION_IN_USE;
     130        }
     131
     132        *stream = talloc_move(wrepl_socket, &wrepl_socket->stream);
     133        return NT_STATUS_OK;
     134}
     135
     136const char *wrepl_best_ip(struct loadparm_context *lp_ctx, const char *peer_ip)
     137{
     138        struct interface *ifaces;
     139        load_interfaces(lp_ctx, lpcfg_interfaces(lp_ctx), &ifaces);
     140        return iface_best_ip(ifaces, peer_ip);
    267141}
    268142
    269143struct wrepl_connect_state {
    270         struct composite_context *result;
    271         struct wrepl_socket *wrepl_socket;
    272         struct composite_context *creq;
     144        struct {
     145                struct wrepl_socket *wrepl_socket;
     146                struct tevent_context *ev;
     147        } caller;
     148        struct tsocket_address *local_address;
     149        struct tsocket_address *remote_address;
     150        struct tstream_context *stream;
    273151};
    274152
    275 /*
    276   handler for winrepl connection completion
    277 */
    278 static void wrepl_connect_handler(struct composite_context *creq)
    279 {
    280         struct wrepl_connect_state *state = talloc_get_type(creq->async.private_data,
     153static void wrepl_connect_trigger(struct tevent_req *req,
     154                                  void *private_date);
     155
     156struct tevent_req *wrepl_connect_send(TALLOC_CTX *mem_ctx,
     157                                      struct tevent_context *ev,
     158                                      struct wrepl_socket *wrepl_socket,
     159                                      const char *our_ip, const char *peer_ip)
     160{
     161        struct tevent_req *req;
     162        struct wrepl_connect_state *state;
     163        int ret;
     164        bool ok;
     165
     166        req = tevent_req_create(mem_ctx, &state,
     167                                struct wrepl_connect_state);
     168        if (req == NULL) {
     169                return NULL;
     170        }
     171
     172        state->caller.wrepl_socket = wrepl_socket;
     173        state->caller.ev = ev;
     174
     175        if (wrepl_socket->stream) {
     176                tevent_req_nterror(req, NT_STATUS_CONNECTION_ACTIVE);
     177                return tevent_req_post(req, ev);
     178        }
     179
     180        ret = tsocket_address_inet_from_strings(state, "ipv4",
     181                                                our_ip, 0,
     182                                                &state->local_address);
     183        if (ret != 0) {
     184                NTSTATUS status = map_nt_error_from_unix(errno);
     185                tevent_req_nterror(req, status);
     186                return tevent_req_post(req, ev);
     187        }
     188
     189        ret = tsocket_address_inet_from_strings(state, "ipv4",
     190                                                peer_ip, WINS_REPLICATION_PORT,
     191                                                &state->remote_address);
     192        if (ret != 0) {
     193                NTSTATUS status = map_nt_error_from_unix(errno);
     194                tevent_req_nterror(req, status);
     195                return tevent_req_post(req, ev);
     196        }
     197
     198        ok = tevent_queue_add(wrepl_socket->request_queue,
     199                              ev,
     200                              req,
     201                              wrepl_connect_trigger,
     202                              NULL);
     203        if (!ok) {
     204                tevent_req_nomem(NULL, req);
     205                return tevent_req_post(req, ev);
     206        }
     207
     208        if (wrepl_socket->request_timeout > 0) {
     209                struct timeval endtime;
     210                endtime = tevent_timeval_current_ofs(wrepl_socket->request_timeout, 0);
     211                ok = tevent_req_set_endtime(req, ev, endtime);
     212                if (!ok) {
     213                        return tevent_req_post(req, ev);
     214                }
     215        }
     216
     217        return req;
     218}
     219
     220static void wrepl_connect_done(struct tevent_req *subreq);
     221
     222static void wrepl_connect_trigger(struct tevent_req *req,
     223                                  void *private_date)
     224{
     225        struct wrepl_connect_state *state = tevent_req_data(req,
    281226                                            struct wrepl_connect_state);
    282         struct wrepl_socket *wrepl_socket = state->wrepl_socket;
    283         struct composite_context *result = state->result;
    284 
    285         result->status = socket_connect_recv(state->creq);
    286         if (!composite_is_ok(result)) return;
    287 
    288         wrepl_socket->event.fde = event_add_fd(wrepl_socket->event.ctx, wrepl_socket,
    289                                                socket_get_fd(wrepl_socket->sock),
    290                                                EVENT_FD_READ,
    291                                                wrepl_handler, wrepl_socket);
    292         if (composite_nomem(wrepl_socket->event.fde, result)) return;
    293 
    294         /* setup the stream -> packet parser */
    295         wrepl_socket->packet = packet_init(wrepl_socket);
    296         if (composite_nomem(wrepl_socket->packet, result)) return;
    297         packet_set_private(wrepl_socket->packet, wrepl_socket);
    298         packet_set_socket(wrepl_socket->packet, wrepl_socket->sock);
    299         packet_set_callback(wrepl_socket->packet, wrepl_finish_recv);
    300         packet_set_full_request(wrepl_socket->packet, packet_full_request_u32);
    301         packet_set_error_handler(wrepl_socket->packet, wrepl_error);
    302         packet_set_event_context(wrepl_socket->packet, wrepl_socket->event.ctx);
    303         packet_set_fde(wrepl_socket->packet, wrepl_socket->event.fde);
    304         packet_set_serialise(wrepl_socket->packet);
    305 
    306         composite_done(result);
    307 }
    308 
    309 const char *wrepl_best_ip(struct loadparm_context *lp_ctx, const char *peer_ip)
    310 {
    311         struct interface *ifaces;
    312         load_interfaces(lp_ctx, lp_interfaces(lp_ctx), &ifaces);
    313         return iface_best_ip(ifaces, peer_ip);
    314 }
    315 
    316 
    317 /*
    318   connect a wrepl_socket to a WINS server
    319 */
    320 struct composite_context *wrepl_connect_send(struct wrepl_socket *wrepl_socket,
    321                                              const char *our_ip, const char *peer_ip)
    322 {
    323         struct composite_context *result;
    324         struct wrepl_connect_state *state;
    325         struct socket_address *peer, *us;
    326 
    327         result = talloc_zero(wrepl_socket, struct composite_context);
    328         if (!result) return NULL;
    329 
    330         result->state           = COMPOSITE_STATE_IN_PROGRESS;
    331         result->event_ctx       = wrepl_socket->event.ctx;
    332 
    333         state = talloc_zero(result, struct wrepl_connect_state);
    334         if (composite_nomem(state, result)) return result;
    335         result->private_data    = state;
    336         state->result           = result;
    337         state->wrepl_socket     = wrepl_socket;
    338 
    339         us = socket_address_from_strings(state, wrepl_socket->sock->backend_name,
    340                                          our_ip, 0);
    341         if (composite_nomem(us, result)) return result;
    342 
    343         peer = socket_address_from_strings(state, wrepl_socket->sock->backend_name,
    344                                            peer_ip, WINS_REPLICATION_PORT);
    345         if (composite_nomem(peer, result)) return result;
    346 
    347         state->creq = socket_connect_send(wrepl_socket->sock, us, peer,
    348                                           0, wrepl_socket->event.ctx);
    349         composite_continue(result, state->creq, wrepl_connect_handler, state);
    350         return result;
     227        struct tevent_req *subreq;
     228
     229        subreq = tstream_inet_tcp_connect_send(state,
     230                                               state->caller.ev,
     231                                               state->local_address,
     232                                               state->remote_address);
     233        if (tevent_req_nomem(subreq, req)) {
     234                return;
     235        }
     236        tevent_req_set_callback(subreq, wrepl_connect_done, req);
     237
     238        return;
     239}
     240
     241static void wrepl_connect_done(struct tevent_req *subreq)
     242{
     243        struct tevent_req *req = tevent_req_callback_data(subreq,
     244                                 struct tevent_req);
     245        struct wrepl_connect_state *state = tevent_req_data(req,
     246                                            struct wrepl_connect_state);
     247        int ret;
     248        int sys_errno;
     249
     250        ret = tstream_inet_tcp_connect_recv(subreq, &sys_errno,
     251                                            state, &state->stream, NULL);
     252        if (ret != 0) {
     253                NTSTATUS status = map_nt_error_from_unix(sys_errno);
     254                tevent_req_nterror(req, status);
     255                return;
     256        }
     257
     258        tevent_req_done(req);
    351259}
    352260
     
    354262  connect a wrepl_socket to a WINS server - recv side
    355263*/
    356 NTSTATUS wrepl_connect_recv(struct composite_context *result)
    357 {
    358         struct wrepl_connect_state *state = talloc_get_type(result->private_data,
     264NTSTATUS wrepl_connect_recv(struct tevent_req *req)
     265{
     266        struct wrepl_connect_state *state = tevent_req_data(req,
    359267                                            struct wrepl_connect_state);
    360         struct wrepl_socket *wrepl_socket = state->wrepl_socket;
    361         NTSTATUS status = composite_wait(result);
    362 
    363         if (!NT_STATUS_IS_OK(status)) {
    364                 wrepl_socket_dead(wrepl_socket, status);
    365         }
    366 
    367         talloc_free(result);
    368         return status;
     268        struct wrepl_socket *wrepl_socket = state->caller.wrepl_socket;
     269        NTSTATUS status;
     270
     271        if (tevent_req_is_nterror(req, &status)) {
     272                tevent_req_received(req);
     273                return status;
     274        }
     275
     276        wrepl_socket->stream = talloc_move(wrepl_socket, &state->stream);
     277
     278        tevent_req_received(req);
     279        return NT_STATUS_OK;
    369280}
    370281
     
    375286                       const char *our_ip, const char *peer_ip)
    376287{
    377         struct composite_context *c_req = wrepl_connect_send(wrepl_socket, our_ip, peer_ip);
    378         return wrepl_connect_recv(c_req);
    379 }
    380 
    381 /*
    382    callback from wrepl_request_trigger()
    383 */
    384 static void wrepl_request_trigger_handler(struct tevent_context *ev, struct tevent_timer *te,
    385                                           struct timeval t, void *ptr)
    386 {
    387         struct wrepl_request *req = talloc_get_type(ptr, struct wrepl_request);
    388         if (req->async.fn) {
    389                 req->async.fn(req);
    390         }
    391 }
    392 
    393 /*
    394   trigger an immediate event on a wrepl_request
    395   the return value should only be used in wrepl_request_send()
    396   this is the only place where req->trigger is true
    397 */
    398 static struct wrepl_request *wrepl_request_finished(struct wrepl_request *req, NTSTATUS status)
    399 {
    400         struct tevent_timer *te;
    401 
    402         if (req->state == WREPL_REQUEST_RECV) {
    403                 DLIST_REMOVE(req->wrepl_socket->recv_queue, req);
    404         }
    405 
    406         if (!NT_STATUS_IS_OK(status)) {
    407                 req->state      = WREPL_REQUEST_ERROR;
    408         } else {
    409                 req->state      = WREPL_REQUEST_DONE;
    410         }
    411 
    412         req->status     = status;
    413 
    414         if (req->trigger) {
    415                 req->trigger = false;
    416                 /* a zero timeout means immediate */
    417                 te = event_add_timed(req->wrepl_socket->event.ctx,
    418                                      req, timeval_zero(),
    419                                      wrepl_request_trigger_handler, req);
    420                 if (!te) {
    421                         talloc_free(req);
    422                         return NULL;
    423                 }
    424                 return req;
    425         }
    426 
    427         if (req->async.fn) {
    428                 req->async.fn(req);
    429         }
    430         return NULL;
    431 }
    432 
    433 struct wrepl_send_ctrl_state {
     288        struct tevent_req *subreq;
     289        bool ok;
     290        NTSTATUS status;
     291
     292        subreq = wrepl_connect_send(wrepl_socket, wrepl_socket->event.ctx,
     293                                    wrepl_socket, our_ip, peer_ip);
     294        NT_STATUS_HAVE_NO_MEMORY(subreq);
     295
     296        ok = tevent_req_poll(subreq, wrepl_socket->event.ctx);
     297        if (!ok) {
     298                TALLOC_FREE(subreq);
     299                return NT_STATUS_INTERNAL_ERROR;
     300        }
     301
     302        status = wrepl_connect_recv(subreq);
     303        TALLOC_FREE(subreq);
     304        NT_STATUS_NOT_OK_RETURN(status);
     305
     306        return NT_STATUS_OK;
     307}
     308
     309struct wrepl_request_state {
     310        struct {
     311                struct wrepl_socket *wrepl_socket;
     312                struct tevent_context *ev;
     313        } caller;
    434314        struct wrepl_send_ctrl ctrl;
    435         struct wrepl_request *req;
    436         struct wrepl_socket *wrepl_sock;
     315        struct {
     316                struct wrepl_wrap wrap;
     317                DATA_BLOB blob;
     318                struct iovec iov;
     319        } req;
     320        bool one_way;
     321        struct {
     322                DATA_BLOB blob;
     323                struct wrepl_packet *packet;
     324        } rep;
    437325};
    438326
    439 static int wrepl_send_ctrl_destructor(struct wrepl_send_ctrl_state *s)
    440 {
    441         struct wrepl_request *req = s->wrepl_sock->recv_queue;
    442 
    443         /* check if the request is still in WREPL_STATE_RECV,
    444          * we need this here because the caller has may called
    445          * talloc_free(req) and wrepl_send_ctrl_state isn't
    446          * a talloc child of the request, so our s->req pointer
    447          * is maybe invalid!
    448          */
    449         for (; req; req = req->next) {
    450                 if (req == s->req) break;
    451         }
    452         if (!req) return 0;
    453 
    454         /* here, we need to make sure the async request handler is called
    455          * later in the next event_loop and now now
    456          */
    457         req->trigger = true;
    458         wrepl_request_finished(req, NT_STATUS_OK);
    459 
    460         if (s->ctrl.disconnect_after_send) {
    461                 wrepl_socket_dead(s->wrepl_sock, NT_STATUS_LOCAL_DISCONNECT);
    462         }
    463 
    464         return 0;
    465 }
    466 
    467 /*
    468   send a generic wins replication request
    469 */
    470 struct wrepl_request *wrepl_request_send(struct wrepl_socket *wrepl_socket,
    471                                          struct wrepl_packet *packet,
    472                                          struct wrepl_send_ctrl *ctrl)
    473 {
    474         struct wrepl_request *req;
    475         struct wrepl_wrap wrap;
    476         DATA_BLOB blob;
     327static void wrepl_request_trigger(struct tevent_req *req,
     328                                  void *private_data);
     329
     330struct tevent_req *wrepl_request_send(TALLOC_CTX *mem_ctx,
     331                                      struct tevent_context *ev,
     332                                      struct wrepl_socket *wrepl_socket,
     333                                      const struct wrepl_packet *packet,
     334                                      const struct wrepl_send_ctrl *ctrl)
     335{
     336        struct tevent_req *req;
     337        struct wrepl_request_state *state;
    477338        NTSTATUS status;
    478339        enum ndr_err_code ndr_err;
    479 
    480         req = talloc_zero(wrepl_socket, struct wrepl_request);
    481         if (!req) return NULL;
    482         req->wrepl_socket = wrepl_socket;
    483         req->state        = WREPL_REQUEST_RECV;
    484         req->trigger      = true;
    485 
    486         DLIST_ADD_END(wrepl_socket->recv_queue, req, struct wrepl_request *);
    487         talloc_set_destructor(req, wrepl_request_destructor);
    488 
    489         if (wrepl_socket->dead) {
    490                 return wrepl_request_finished(req, NT_STATUS_INVALID_CONNECTION);
    491         }
    492 
    493         wrap.packet = *packet;
    494         ndr_err = ndr_push_struct_blob(&blob, req, wrepl_socket->iconv_convenience, &wrap,
     340        bool ok;
     341
     342        if (wrepl_socket->event.ctx != ev) {
     343                /* TODO: remove wrepl_socket->event.ctx !!! */
     344                smb_panic("wrepl_associate_stop_send event context mismatch!");
     345                return NULL;
     346        }
     347
     348        req = tevent_req_create(mem_ctx, &state,
     349                                struct wrepl_request_state);
     350        if (req == NULL) {
     351                return NULL;
     352        }
     353
     354        state->caller.wrepl_socket = wrepl_socket;
     355        state->caller.ev = ev;
     356
     357        if (ctrl) {
     358                state->ctrl = *ctrl;
     359        }
     360
     361        if (wrepl_socket->stream == NULL) {
     362                tevent_req_nterror(req, NT_STATUS_INVALID_CONNECTION);
     363                return tevent_req_post(req, ev);
     364        }
     365
     366        state->req.wrap.packet = *packet;
     367        ndr_err = ndr_push_struct_blob(&state->req.blob, state,
     368                                       &state->req.wrap,
    495369                                       (ndr_push_flags_fn_t)ndr_push_wrepl_wrap);
    496370        if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
    497371                status = ndr_map_error2ntstatus(ndr_err);
    498                 return wrepl_request_finished(req, status);
     372                tevent_req_nterror(req, status);
     373                return tevent_req_post(req, ev);
     374        }
     375
     376        state->req.iov.iov_base = (char *) state->req.blob.data;
     377        state->req.iov.iov_len = state->req.blob.length;
     378
     379        ok = tevent_queue_add(wrepl_socket->request_queue,
     380                              ev,
     381                              req,
     382                              wrepl_request_trigger,
     383                              NULL);
     384        if (!ok) {
     385                tevent_req_nomem(NULL, req);
     386                return tevent_req_post(req, ev);
     387        }
     388
     389        if (wrepl_socket->request_timeout > 0) {
     390                struct timeval endtime;
     391                endtime = tevent_timeval_current_ofs(wrepl_socket->request_timeout, 0);
     392                ok = tevent_req_set_endtime(req, ev, endtime);
     393                if (!ok) {
     394                        return tevent_req_post(req, ev);
     395                }
     396        }
     397
     398        return req;
     399}
     400
     401static void wrepl_request_writev_done(struct tevent_req *subreq);
     402
     403static void wrepl_request_trigger(struct tevent_req *req,
     404                                  void *private_data)
     405{
     406        struct wrepl_request_state *state = tevent_req_data(req,
     407                                            struct wrepl_request_state);
     408        struct tevent_req *subreq;
     409
     410        if (state->caller.wrepl_socket->stream == NULL) {
     411                tevent_req_nterror(req, NT_STATUS_INVALID_CONNECTION);
     412                return;
    499413        }
    500414
    501415        if (DEBUGLVL(10)) {
    502                 DEBUG(10,("Sending WINS packet of length %u\n",
    503                           (unsigned)blob.length));
    504                 NDR_PRINT_DEBUG(wrepl_packet, &wrap.packet);
    505         }
    506 
    507         if (wrepl_socket->request_timeout > 0) {
    508                 req->te = event_add_timed(wrepl_socket->event.ctx, req,
    509                                           timeval_current_ofs(wrepl_socket->request_timeout, 0),
    510                                           wrepl_request_timeout_handler, req);
    511                 if (!req->te) return wrepl_request_finished(req, NT_STATUS_NO_MEMORY);
    512         }
    513 
    514         if (ctrl && (ctrl->send_only || ctrl->disconnect_after_send)) {
    515                 struct wrepl_send_ctrl_state *s = talloc(blob.data, struct wrepl_send_ctrl_state);
    516                 if (!s) return wrepl_request_finished(req, NT_STATUS_NO_MEMORY);
    517                 s->ctrl         = *ctrl;
    518                 s->req          = req;
    519                 s->wrepl_sock   = wrepl_socket;
    520                 talloc_set_destructor(s, wrepl_send_ctrl_destructor);
    521         }
    522 
    523         status = packet_send(wrepl_socket->packet, blob);
     416                DEBUG(10,("Sending WINS packet of length %u\n",
     417                          (unsigned)state->req.blob.length));
     418                NDR_PRINT_DEBUG(wrepl_packet, &state->req.wrap.packet);
     419        }
     420
     421        subreq = tstream_writev_send(state,
     422                                     state->caller.ev,
     423                                     state->caller.wrepl_socket->stream,
     424                                     &state->req.iov, 1);
     425        if (tevent_req_nomem(subreq, req)) {
     426                return;
     427        }
     428        tevent_req_set_callback(subreq, wrepl_request_writev_done, req);
     429}
     430
     431static void wrepl_request_disconnect_done(struct tevent_req *subreq);
     432static void wrepl_request_read_pdu_done(struct tevent_req *subreq);
     433
     434static void wrepl_request_writev_done(struct tevent_req *subreq)
     435{
     436        struct tevent_req *req = tevent_req_callback_data(subreq,
     437                                 struct tevent_req);
     438        struct wrepl_request_state *state = tevent_req_data(req,
     439                                            struct wrepl_request_state);
     440        int ret;
     441        int sys_errno;
     442
     443        ret = tstream_writev_recv(subreq, &sys_errno);
     444        TALLOC_FREE(subreq);
     445        if (ret == -1) {
     446                NTSTATUS status = map_nt_error_from_unix(sys_errno);
     447                TALLOC_FREE(state->caller.wrepl_socket->stream);
     448                tevent_req_nterror(req, status);
     449                return;
     450        }
     451
     452        if (state->caller.wrepl_socket->stream == NULL) {
     453                tevent_req_nterror(req, NT_STATUS_INVALID_CONNECTION);
     454                return;
     455        }
     456
     457        if (state->ctrl.disconnect_after_send) {
     458                subreq = tstream_disconnect_send(state,
     459                                                 state->caller.ev,
     460                                                 state->caller.wrepl_socket->stream);
     461                if (tevent_req_nomem(subreq, req)) {
     462                        return;
     463                }
     464                tevent_req_set_callback(subreq, wrepl_request_disconnect_done, req);
     465                return;
     466        }
     467
     468        if (state->ctrl.send_only) {
     469                tevent_req_done(req);
     470                return;
     471        }
     472
     473        subreq = tstream_read_pdu_blob_send(state,
     474                                            state->caller.ev,
     475                                            state->caller.wrepl_socket->stream,
     476                                            4, /* initial_read_size */
     477                                            packet_full_request_u32,
     478                                            NULL);
     479        if (tevent_req_nomem(subreq, req)) {
     480                return;
     481        }
     482        tevent_req_set_callback(subreq, wrepl_request_read_pdu_done, req);
     483}
     484
     485static void wrepl_request_disconnect_done(struct tevent_req *subreq)
     486{
     487        struct tevent_req *req = tevent_req_callback_data(subreq,
     488                                 struct tevent_req);
     489        struct wrepl_request_state *state = tevent_req_data(req,
     490                                            struct wrepl_request_state);
     491        int ret;
     492        int sys_errno;
     493
     494        ret = tstream_disconnect_recv(subreq, &sys_errno);
     495        TALLOC_FREE(subreq);
     496        if (ret == -1) {
     497                NTSTATUS status = map_nt_error_from_unix(sys_errno);
     498                TALLOC_FREE(state->caller.wrepl_socket->stream);
     499                tevent_req_nterror(req, status);
     500                return;
     501        }
     502
     503        DEBUG(10,("WINS connection disconnected\n"));
     504        TALLOC_FREE(state->caller.wrepl_socket->stream);
     505
     506        tevent_req_done(req);
     507}
     508
     509static void wrepl_request_read_pdu_done(struct tevent_req *subreq)
     510{
     511        struct tevent_req *req = tevent_req_callback_data(subreq,
     512                                 struct tevent_req);
     513        struct wrepl_request_state *state = tevent_req_data(req,
     514                                            struct wrepl_request_state);
     515        NTSTATUS status;
     516        DATA_BLOB blob;
     517        enum ndr_err_code ndr_err;
     518
     519        status = tstream_read_pdu_blob_recv(subreq, state, &state->rep.blob);
    524520        if (!NT_STATUS_IS_OK(status)) {
    525                 return wrepl_request_finished(req, status);
    526         }
    527 
    528         req->trigger = false;
    529         return req;
    530 }
    531 
    532 /*
    533   receive a generic WINS replication reply
    534 */
    535 NTSTATUS wrepl_request_recv(struct wrepl_request *req,
     521                TALLOC_FREE(state->caller.wrepl_socket->stream);
     522                tevent_req_nterror(req, status);
     523                return;
     524        }
     525
     526        state->rep.packet = talloc(state, struct wrepl_packet);
     527        if (tevent_req_nomem(state->rep.packet, req)) {
     528                return;
     529        }
     530
     531        blob.data = state->rep.blob.data + 4;
     532        blob.length = state->rep.blob.length - 4;
     533
     534        /* we have a full request - parse it */
     535        ndr_err = ndr_pull_struct_blob(&blob,
     536                                       state->rep.packet,
     537                                       state->rep.packet,
     538                                       (ndr_pull_flags_fn_t)ndr_pull_wrepl_packet);
     539        if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
     540                status = ndr_map_error2ntstatus(ndr_err);
     541                tevent_req_nterror(req, status);
     542                return;
     543        }
     544
     545        if (DEBUGLVL(10)) {
     546                DEBUG(10,("Received WINS packet of length %u\n",
     547                          (unsigned)state->rep.blob.length));
     548                NDR_PRINT_DEBUG(wrepl_packet, state->rep.packet);
     549        }
     550
     551        tevent_req_done(req);
     552}
     553
     554NTSTATUS wrepl_request_recv(struct tevent_req *req,
    536555                            TALLOC_CTX *mem_ctx,
    537556                            struct wrepl_packet **packet)
    538557{
    539         NTSTATUS status = wrepl_request_wait(req);
    540         if (NT_STATUS_IS_OK(status) && packet) {
    541                 *packet = talloc_steal(mem_ctx, req->packet);
    542         }
    543         talloc_free(req);
    544         return status;
     558        struct wrepl_request_state *state = tevent_req_data(req,
     559                                            struct wrepl_request_state);
     560        NTSTATUS status;
     561
     562        if (tevent_req_is_nterror(req, &status)) {
     563                TALLOC_FREE(state->caller.wrepl_socket->stream);
     564                tevent_req_received(req);
     565                return status;
     566        }
     567
     568        if (packet) {
     569                *packet = talloc_move(mem_ctx, &state->rep.packet);
     570        }
     571
     572        tevent_req_received(req);
     573        return NT_STATUS_OK;
    545574}
    546575
     
    550579NTSTATUS wrepl_request(struct wrepl_socket *wrepl_socket,
    551580                       TALLOC_CTX *mem_ctx,
    552                        struct wrepl_packet *req_packet,
     581                       const struct wrepl_packet *req_packet,
    553582                       struct wrepl_packet **reply_packet)
    554583{
    555         struct wrepl_request *req = wrepl_request_send(wrepl_socket, req_packet, NULL);
    556         return wrepl_request_recv(req, mem_ctx, reply_packet);
    557 }
    558 
    559 
    560 /*
    561   setup an association - send
    562 */
    563 struct wrepl_request *wrepl_associate_send(struct wrepl_socket *wrepl_socket,
    564                                            struct wrepl_associate *io)
    565 {
    566         struct wrepl_packet *packet;
    567         struct wrepl_request *req;
    568 
    569         packet = talloc_zero(wrepl_socket, struct wrepl_packet);
    570         if (packet == NULL) return NULL;
    571 
    572         packet->opcode                      = WREPL_OPCODE_BITS;
    573         packet->mess_type                   = WREPL_START_ASSOCIATION;
    574         packet->message.start.minor_version = 2;
    575         packet->message.start.major_version = 5;
     584        struct tevent_req *subreq;
     585        bool ok;
     586        NTSTATUS status;
     587
     588        subreq = wrepl_request_send(mem_ctx, wrepl_socket->event.ctx,
     589                                    wrepl_socket, req_packet, NULL);
     590        NT_STATUS_HAVE_NO_MEMORY(subreq);
     591
     592        ok = tevent_req_poll(subreq, wrepl_socket->event.ctx);
     593        if (!ok) {
     594                TALLOC_FREE(subreq);
     595                return NT_STATUS_INTERNAL_ERROR;
     596        }
     597
     598        status = wrepl_request_recv(subreq, mem_ctx, reply_packet);
     599        TALLOC_FREE(subreq);
     600        NT_STATUS_NOT_OK_RETURN(status);
     601
     602        return NT_STATUS_OK;
     603}
     604
     605
     606struct wrepl_associate_state {
     607        struct wrepl_packet packet;
     608        uint32_t assoc_ctx;
     609        uint16_t major_version;
     610};
     611
     612static void wrepl_associate_done(struct tevent_req *subreq);
     613
     614struct tevent_req *wrepl_associate_send(TALLOC_CTX *mem_ctx,
     615                                        struct tevent_context *ev,
     616                                        struct wrepl_socket *wrepl_socket,
     617                                        const struct wrepl_associate *io)
     618{
     619        struct tevent_req *req;
     620        struct wrepl_associate_state *state;
     621        struct tevent_req *subreq;
     622
     623        if (wrepl_socket->event.ctx != ev) {
     624                /* TODO: remove wrepl_socket->event.ctx !!! */
     625                smb_panic("wrepl_associate_send event context mismatch!");
     626                return NULL;
     627        }
     628
     629        req = tevent_req_create(mem_ctx, &state,
     630                                struct wrepl_associate_state);
     631        if (req == NULL) {
     632                return NULL;
     633        };
     634
     635        state->packet.opcode                            = WREPL_OPCODE_BITS;
     636        state->packet.mess_type                         = WREPL_START_ASSOCIATION;
     637        state->packet.message.start.minor_version       = 2;
     638        state->packet.message.start.major_version       = 5;
    576639
    577640        /*
     
    583646         * and that would break nt4 <-> samba replication
    584647         */
    585         packet->padding = data_blob_talloc(packet, NULL, 21);
    586         if (packet->padding.data == NULL) {
    587                 talloc_free(packet);
    588                 return NULL;
    589         }
    590         memset(packet->padding.data, 0, packet->padding.length);
    591 
    592         req = wrepl_request_send(wrepl_socket, packet, NULL);
    593 
    594         talloc_free(packet);
    595 
    596         return req;     
     648        state->packet.padding   = data_blob_talloc(state, NULL, 21);
     649        if (tevent_req_nomem(state->packet.padding.data, req)) {
     650                return tevent_req_post(req, ev);
     651        }
     652        memset(state->packet.padding.data, 0, state->packet.padding.length);
     653
     654        subreq = wrepl_request_send(state, ev, wrepl_socket, &state->packet, NULL);
     655        if (tevent_req_nomem(subreq, req)) {
     656                return tevent_req_post(req, ev);
     657        }
     658        tevent_req_set_callback(subreq, wrepl_associate_done, req);
     659
     660        return req;
     661}
     662
     663static void wrepl_associate_done(struct tevent_req *subreq)
     664{
     665        struct tevent_req *req = tevent_req_callback_data(subreq,
     666                                 struct tevent_req);
     667        struct wrepl_associate_state *state = tevent_req_data(req,
     668                                              struct wrepl_associate_state);
     669        NTSTATUS status;
     670        struct wrepl_packet *packet;
     671
     672        status = wrepl_request_recv(subreq, state, &packet);
     673        TALLOC_FREE(subreq);
     674        if (!NT_STATUS_IS_OK(status)) {
     675                tevent_req_nterror(req, status);
     676                return;
     677        }
     678
     679        if (packet->mess_type != WREPL_START_ASSOCIATION_REPLY) {
     680                tevent_req_nterror(req, NT_STATUS_INVALID_NETWORK_RESPONSE);
     681                return;
     682        }
     683
     684        state->assoc_ctx = packet->message.start_reply.assoc_ctx;
     685        state->major_version = packet->message.start_reply.major_version;
     686
     687        tevent_req_done(req);
    597688}
    598689
     
    600691  setup an association - recv
    601692*/
    602 NTSTATUS wrepl_associate_recv(struct wrepl_request *req,
     693NTSTATUS wrepl_associate_recv(struct tevent_req *req,
    603694                              struct wrepl_associate *io)
    604695{
    605         struct wrepl_packet *packet=NULL;
    606         NTSTATUS status;
    607         status = wrepl_request_recv(req, req->wrepl_socket, &packet);
    608         NT_STATUS_NOT_OK_RETURN(status);
    609         if (packet->mess_type != WREPL_START_ASSOCIATION_REPLY) {
    610                 status = NT_STATUS_UNEXPECTED_NETWORK_ERROR;
    611         }
    612         if (NT_STATUS_IS_OK(status)) {
    613                 io->out.assoc_ctx = packet->message.start_reply.assoc_ctx;
    614                 io->out.major_version = packet->message.start_reply.major_version;
    615         }
    616         talloc_free(packet);
    617         return status;
     696        struct wrepl_associate_state *state = tevent_req_data(req,
     697                                              struct wrepl_associate_state);
     698        NTSTATUS status;
     699
     700        if (tevent_req_is_nterror(req, &status)) {
     701                tevent_req_received(req);
     702                return status;
     703        }
     704
     705        io->out.assoc_ctx = state->assoc_ctx;
     706        io->out.major_version = state->major_version;
     707
     708        tevent_req_received(req);
     709        return NT_STATUS_OK;
    618710}
    619711
     
    624716                         struct wrepl_associate *io)
    625717{
    626         struct wrepl_request *req = wrepl_associate_send(wrepl_socket, io);
    627         return wrepl_associate_recv(req, io);
    628 }
    629 
    630 
    631 /*
    632   stop an association - send
    633 */
    634 struct wrepl_request *wrepl_associate_stop_send(struct wrepl_socket *wrepl_socket,
    635                                                 struct wrepl_associate_stop *io)
    636 {
    637         struct wrepl_packet *packet;
    638         struct wrepl_request *req;
     718        struct tevent_req *subreq;
     719        bool ok;
     720        NTSTATUS status;
     721
     722        subreq = wrepl_associate_send(wrepl_socket, wrepl_socket->event.ctx,
     723                                      wrepl_socket, io);
     724        NT_STATUS_HAVE_NO_MEMORY(subreq);
     725
     726        ok = tevent_req_poll(subreq, wrepl_socket->event.ctx);
     727        if (!ok) {
     728                TALLOC_FREE(subreq);
     729                return NT_STATUS_INTERNAL_ERROR;
     730        }
     731
     732        status = wrepl_associate_recv(subreq, io);
     733        TALLOC_FREE(subreq);
     734        NT_STATUS_NOT_OK_RETURN(status);
     735
     736        return NT_STATUS_OK;
     737}
     738
     739struct wrepl_associate_stop_state {
     740        struct wrepl_packet packet;
    639741        struct wrepl_send_ctrl ctrl;
    640 
    641         packet = talloc_zero(wrepl_socket, struct wrepl_packet);
    642         if (packet == NULL) return NULL;
    643 
    644         packet->opcode                  = WREPL_OPCODE_BITS;
    645         packet->assoc_ctx               = io->in.assoc_ctx;
    646         packet->mess_type               = WREPL_STOP_ASSOCIATION;
    647         packet->message.stop.reason     = io->in.reason;
    648 
    649         ZERO_STRUCT(ctrl);
     742};
     743
     744static void wrepl_associate_stop_done(struct tevent_req *subreq);
     745
     746struct tevent_req *wrepl_associate_stop_send(TALLOC_CTX *mem_ctx,
     747                                             struct tevent_context *ev,
     748                                             struct wrepl_socket *wrepl_socket,
     749                                             const struct wrepl_associate_stop *io)
     750{
     751        struct tevent_req *req;
     752        struct wrepl_associate_stop_state *state;
     753        struct tevent_req *subreq;
     754
     755        if (wrepl_socket->event.ctx != ev) {
     756                /* TODO: remove wrepl_socket->event.ctx !!! */
     757                smb_panic("wrepl_associate_stop_send event context mismatch!");
     758                return NULL;
     759        }
     760
     761        req = tevent_req_create(mem_ctx, &state,
     762                                struct wrepl_associate_stop_state);
     763        if (req == NULL) {
     764                return NULL;
     765        };
     766
     767        state->packet.opcode                    = WREPL_OPCODE_BITS;
     768        state->packet.assoc_ctx                 = io->in.assoc_ctx;
     769        state->packet.mess_type                 = WREPL_STOP_ASSOCIATION;
     770        state->packet.message.stop.reason       = io->in.reason;
     771
    650772        if (io->in.reason == 0) {
    651                 ctrl.send_only                  = true;
    652                 ctrl.disconnect_after_send      = true;
    653         }
    654 
    655         req = wrepl_request_send(wrepl_socket, packet, &ctrl);
    656 
    657         talloc_free(packet);
    658 
    659         return req;     
     773                state->ctrl.send_only                   = true;
     774                state->ctrl.disconnect_after_send       = true;
     775        }
     776
     777        subreq = wrepl_request_send(state, ev, wrepl_socket, &state->packet, &state->ctrl);
     778        if (tevent_req_nomem(subreq, req)) {
     779                return tevent_req_post(req, ev);
     780        }
     781        tevent_req_set_callback(subreq, wrepl_associate_stop_done, req);
     782
     783        return req;
     784}
     785
     786static void wrepl_associate_stop_done(struct tevent_req *subreq)
     787{
     788        struct tevent_req *req = tevent_req_callback_data(subreq,
     789                                 struct tevent_req);
     790        struct wrepl_associate_stop_state *state = tevent_req_data(req,
     791                                                   struct wrepl_associate_stop_state);
     792        NTSTATUS status;
     793
     794        /* currently we don't care about a possible response */
     795        status = wrepl_request_recv(subreq, state, NULL);
     796        TALLOC_FREE(subreq);
     797        if (!NT_STATUS_IS_OK(status)) {
     798                tevent_req_nterror(req, status);
     799                return;
     800        }
     801
     802        tevent_req_done(req);
    660803}
    661804
     
    663806  stop an association - recv
    664807*/
    665 NTSTATUS wrepl_associate_stop_recv(struct wrepl_request *req,
     808NTSTATUS wrepl_associate_stop_recv(struct tevent_req *req,
    666809                                   struct wrepl_associate_stop *io)
    667810{
    668         struct wrepl_packet *packet=NULL;
    669         NTSTATUS status;
    670         status = wrepl_request_recv(req, req->wrepl_socket, &packet);
    671         NT_STATUS_NOT_OK_RETURN(status);
    672         talloc_free(packet);
    673         return status;
     811        NTSTATUS status;
     812
     813        if (tevent_req_is_nterror(req, &status)) {
     814                tevent_req_received(req);
     815                return status;
     816        }
     817
     818        tevent_req_received(req);
     819        return NT_STATUS_OK;
    674820}
    675821
     
    680826                              struct wrepl_associate_stop *io)
    681827{
    682         struct wrepl_request *req = wrepl_associate_stop_send(wrepl_socket, io);
    683         return wrepl_associate_stop_recv(req, io);
    684 }
    685 
    686 /*
    687   fetch the partner tables - send
    688 */
    689 struct wrepl_request *wrepl_pull_table_send(struct wrepl_socket *wrepl_socket,
    690                                             struct wrepl_pull_table *io)
    691 {
     828        struct tevent_req *subreq;
     829        bool ok;
     830        NTSTATUS status;
     831
     832        subreq = wrepl_associate_stop_send(wrepl_socket, wrepl_socket->event.ctx,
     833                                           wrepl_socket, io);
     834        NT_STATUS_HAVE_NO_MEMORY(subreq);
     835
     836        ok = tevent_req_poll(subreq, wrepl_socket->event.ctx);
     837        if (!ok) {
     838                TALLOC_FREE(subreq);
     839                return NT_STATUS_INTERNAL_ERROR;
     840        }
     841
     842        status = wrepl_associate_stop_recv(subreq, io);
     843        TALLOC_FREE(subreq);
     844        NT_STATUS_NOT_OK_RETURN(status);
     845
     846        return NT_STATUS_OK;
     847}
     848
     849struct wrepl_pull_table_state {
     850        struct wrepl_packet packet;
     851        uint32_t num_partners;
     852        struct wrepl_wins_owner *partners;
     853};
     854
     855static void wrepl_pull_table_done(struct tevent_req *subreq);
     856
     857struct tevent_req *wrepl_pull_table_send(TALLOC_CTX *mem_ctx,
     858                                         struct tevent_context *ev,
     859                                         struct wrepl_socket *wrepl_socket,
     860                                         const struct wrepl_pull_table *io)
     861{
     862        struct tevent_req *req;
     863        struct wrepl_pull_table_state *state;
     864        struct tevent_req *subreq;
     865
     866        if (wrepl_socket->event.ctx != ev) {
     867                /* TODO: remove wrepl_socket->event.ctx !!! */
     868                smb_panic("wrepl_pull_table_send event context mismatch!");
     869                return NULL;
     870        }
     871
     872        req = tevent_req_create(mem_ctx, &state,
     873                                struct wrepl_pull_table_state);
     874        if (req == NULL) {
     875                return NULL;
     876        };
     877
     878        state->packet.opcode                            = WREPL_OPCODE_BITS;
     879        state->packet.assoc_ctx                         = io->in.assoc_ctx;
     880        state->packet.mess_type                         = WREPL_REPLICATION;
     881        state->packet.message.replication.command       = WREPL_REPL_TABLE_QUERY;
     882
     883        subreq = wrepl_request_send(state, ev, wrepl_socket, &state->packet, NULL);
     884        if (tevent_req_nomem(subreq, req)) {
     885                return tevent_req_post(req, ev);
     886        }
     887        tevent_req_set_callback(subreq, wrepl_pull_table_done, req);
     888
     889        return req;
     890}
     891
     892static void wrepl_pull_table_done(struct tevent_req *subreq)
     893{
     894        struct tevent_req *req = tevent_req_callback_data(subreq,
     895                                 struct tevent_req);
     896        struct wrepl_pull_table_state *state = tevent_req_data(req,
     897                                               struct wrepl_pull_table_state);
     898        NTSTATUS status;
    692899        struct wrepl_packet *packet;
    693         struct wrepl_request *req;
    694 
    695         packet = talloc_zero(wrepl_socket, struct wrepl_packet);
    696         if (packet == NULL) return NULL;
    697 
    698         packet->opcode                      = WREPL_OPCODE_BITS;
    699         packet->assoc_ctx                   = io->in.assoc_ctx;
    700         packet->mess_type                   = WREPL_REPLICATION;
    701         packet->message.replication.command = WREPL_REPL_TABLE_QUERY;
    702 
    703         req = wrepl_request_send(wrepl_socket, packet, NULL);
    704 
    705         talloc_free(packet);
    706 
    707         return req;     
    708 }
    709 
     900        struct wrepl_table *table;
     901
     902        status = wrepl_request_recv(subreq, state, &packet);
     903        TALLOC_FREE(subreq);
     904        if (!NT_STATUS_IS_OK(status)) {
     905                tevent_req_nterror(req, status);
     906                return;
     907        }
     908
     909        if (packet->mess_type != WREPL_REPLICATION) {
     910                tevent_req_nterror(req, NT_STATUS_NETWORK_ACCESS_DENIED);
     911                return;
     912        }
     913
     914        if (packet->message.replication.command != WREPL_REPL_TABLE_REPLY) {
     915                tevent_req_nterror(req, NT_STATUS_INVALID_NETWORK_RESPONSE);
     916                return;
     917        }
     918
     919        table = &packet->message.replication.info.table;
     920
     921        state->num_partners = table->partner_count;
     922        state->partners = talloc_move(state, &table->partners);
     923
     924        tevent_req_done(req);
     925}
    710926
    711927/*
    712928  fetch the partner tables - recv
    713929*/
    714 NTSTATUS wrepl_pull_table_recv(struct wrepl_request *req,
     930NTSTATUS wrepl_pull_table_recv(struct tevent_req *req,
    715931                               TALLOC_CTX *mem_ctx,
    716932                               struct wrepl_pull_table *io)
    717933{
    718         struct wrepl_packet *packet=NULL;
    719         NTSTATUS status;
    720         struct wrepl_table *table;
    721         int i;
    722 
    723         status = wrepl_request_recv(req, req->wrepl_socket, &packet);
    724         NT_STATUS_NOT_OK_RETURN(status);
    725         if (packet->mess_type != WREPL_REPLICATION) {
    726                 status = NT_STATUS_NETWORK_ACCESS_DENIED;
    727         } else if (packet->message.replication.command != WREPL_REPL_TABLE_REPLY) {
    728                 status = NT_STATUS_UNEXPECTED_NETWORK_ERROR;
    729         }
    730         if (!NT_STATUS_IS_OK(status)) goto failed;
    731 
    732         table = &packet->message.replication.info.table;
    733         io->out.num_partners = table->partner_count;
    734         io->out.partners = talloc_steal(mem_ctx, table->partners);
    735         for (i=0;i<io->out.num_partners;i++) {
    736                 talloc_steal(io->out.partners, io->out.partners[i].address);
    737         }
    738 
    739 failed:
    740         talloc_free(packet);
    741         return status;
    742 }
    743 
     934        struct wrepl_pull_table_state *state = tevent_req_data(req,
     935                                               struct wrepl_pull_table_state);
     936        NTSTATUS status;
     937
     938        if (tevent_req_is_nterror(req, &status)) {
     939                tevent_req_received(req);
     940                return status;
     941        }
     942
     943        io->out.num_partners = state->num_partners;
     944        io->out.partners = talloc_move(mem_ctx, &state->partners);
     945
     946        tevent_req_received(req);
     947        return NT_STATUS_OK;
     948}
    744949
    745950/*
     
    750955                          struct wrepl_pull_table *io)
    751956{
    752         struct wrepl_request *req = wrepl_pull_table_send(wrepl_socket, io);
    753         return wrepl_pull_table_recv(req, mem_ctx, io);
    754 }
    755 
    756 
    757 /*
    758   fetch the names for a WINS partner - send
    759 */
    760 struct wrepl_request *wrepl_pull_names_send(struct wrepl_socket *wrepl_socket,
    761                                             struct wrepl_pull_names *io)
    762 {
     957        struct tevent_req *subreq;
     958        bool ok;
     959        NTSTATUS status;
     960
     961        subreq = wrepl_pull_table_send(mem_ctx, wrepl_socket->event.ctx,
     962                                       wrepl_socket, io);
     963        NT_STATUS_HAVE_NO_MEMORY(subreq);
     964
     965        ok = tevent_req_poll(subreq, wrepl_socket->event.ctx);
     966        if (!ok) {
     967                TALLOC_FREE(subreq);
     968                return NT_STATUS_INTERNAL_ERROR;
     969        }
     970
     971        status = wrepl_pull_table_recv(subreq, mem_ctx, io);
     972        TALLOC_FREE(subreq);
     973        NT_STATUS_NOT_OK_RETURN(status);
     974
     975        return NT_STATUS_OK;
     976}
     977
     978
     979struct wrepl_pull_names_state {
     980        struct {
     981                const struct wrepl_pull_names *io;
     982        } caller;
     983        struct wrepl_packet packet;
     984        uint32_t num_names;
     985        struct wrepl_name *names;
     986};
     987
     988static void wrepl_pull_names_done(struct tevent_req *subreq);
     989
     990struct tevent_req *wrepl_pull_names_send(TALLOC_CTX *mem_ctx,
     991                                         struct tevent_context *ev,
     992                                         struct wrepl_socket *wrepl_socket,
     993                                         const struct wrepl_pull_names *io)
     994{
     995        struct tevent_req *req;
     996        struct wrepl_pull_names_state *state;
     997        struct tevent_req *subreq;
     998
     999        if (wrepl_socket->event.ctx != ev) {
     1000                /* TODO: remove wrepl_socket->event.ctx !!! */
     1001                smb_panic("wrepl_pull_names_send event context mismatch!");
     1002                return NULL;
     1003        }
     1004
     1005        req = tevent_req_create(mem_ctx, &state,
     1006                                struct wrepl_pull_names_state);
     1007        if (req == NULL) {
     1008                return NULL;
     1009        };
     1010        state->caller.io = io;
     1011
     1012        state->packet.opcode                            = WREPL_OPCODE_BITS;
     1013        state->packet.assoc_ctx                         = io->in.assoc_ctx;
     1014        state->packet.mess_type                         = WREPL_REPLICATION;
     1015        state->packet.message.replication.command       = WREPL_REPL_SEND_REQUEST;
     1016        state->packet.message.replication.info.owner    = io->in.partner;
     1017
     1018        subreq = wrepl_request_send(state, ev, wrepl_socket, &state->packet, NULL);
     1019        if (tevent_req_nomem(subreq, req)) {
     1020                return tevent_req_post(req, ev);
     1021        }
     1022        tevent_req_set_callback(subreq, wrepl_pull_names_done, req);
     1023
     1024        return req;
     1025}
     1026
     1027static void wrepl_pull_names_done(struct tevent_req *subreq)
     1028{
     1029        struct tevent_req *req = tevent_req_callback_data(subreq,
     1030                                 struct tevent_req);
     1031        struct wrepl_pull_names_state *state = tevent_req_data(req,
     1032                                               struct wrepl_pull_names_state);
     1033        NTSTATUS status;
    7631034        struct wrepl_packet *packet;
    764         struct wrepl_request *req;
    765 
    766         packet = talloc_zero(wrepl_socket, struct wrepl_packet);
    767         if (packet == NULL) return NULL;
    768 
    769         packet->opcode                         = WREPL_OPCODE_BITS;
    770         packet->assoc_ctx                      = io->in.assoc_ctx;
    771         packet->mess_type                      = WREPL_REPLICATION;
    772         packet->message.replication.command    = WREPL_REPL_SEND_REQUEST;
    773         packet->message.replication.info.owner = io->in.partner;
    774 
    775         req = wrepl_request_send(wrepl_socket, packet, NULL);
    776 
    777         talloc_free(packet);
    778 
    779         return req;     
    780 }
    781 
    782 /*
    783   fetch the names for a WINS partner - recv
    784 */
    785 NTSTATUS wrepl_pull_names_recv(struct wrepl_request *req,
    786                                TALLOC_CTX *mem_ctx,
    787                                struct wrepl_pull_names *io)
    788 {
    789         struct wrepl_packet *packet=NULL;
    790         NTSTATUS status;
    791         int i;
    792 
    793         status = wrepl_request_recv(req, req->wrepl_socket, &packet);
    794         NT_STATUS_NOT_OK_RETURN(status);
    795         if (packet->mess_type != WREPL_REPLICATION ||
    796             packet->message.replication.command != WREPL_REPL_SEND_REPLY) {
    797                 status = NT_STATUS_UNEXPECTED_NETWORK_ERROR;
    798         }
    799         if (!NT_STATUS_IS_OK(status)) goto failed;
    800 
    801         io->out.num_names = packet->message.replication.info.reply.num_names;
    802 
    803         io->out.names = talloc_array(packet, struct wrepl_name, io->out.num_names);
    804         if (io->out.names == NULL) goto nomem;
     1035        uint32_t i;
     1036
     1037        status = wrepl_request_recv(subreq, state, &packet);
     1038        TALLOC_FREE(subreq);
     1039        if (!NT_STATUS_IS_OK(status)) {
     1040                tevent_req_nterror(req, status);
     1041                return;
     1042        }
     1043
     1044        if (packet->mess_type != WREPL_REPLICATION) {
     1045                tevent_req_nterror(req, NT_STATUS_NETWORK_ACCESS_DENIED);
     1046                return;
     1047        }
     1048
     1049        if (packet->message.replication.command != WREPL_REPL_SEND_REPLY) {
     1050                tevent_req_nterror(req, NT_STATUS_INVALID_NETWORK_RESPONSE);
     1051                return;
     1052        }
     1053
     1054        state->num_names = packet->message.replication.info.reply.num_names;
     1055
     1056        state->names = talloc_array(state, struct wrepl_name, state->num_names);
     1057        if (tevent_req_nomem(state->names, req)) {
     1058                return;
     1059        }
    8051060
    8061061        /* convert the list of names and addresses to a sane format */
    807         for (i=0;i<io->out.num_names;i++) {
     1062        for (i=0; i < state->num_names; i++) {
    8081063                struct wrepl_wins_name *wname = &packet->message.replication.info.reply.names[i];
    809                 struct wrepl_name *name = &io->out.names[i];
     1064                struct wrepl_name *name = &state->names[i];
    8101065
    8111066                name->name      = *wname->name;
    812                 talloc_steal(io->out.names, wname->name);
     1067                talloc_steal(state->names, wname->name);
    8131068                name->type      = WREPL_NAME_TYPE(wname->flags);
    8141069                name->state     = WREPL_NAME_STATE(wname->flags);
     
    8171072                name->raw_flags = wname->flags;
    8181073                name->version_id= wname->id;
    819                 name->owner     = talloc_strdup(io->out.names, io->in.partner.address);
    820                 if (name->owner == NULL) goto nomem;
     1074                name->owner     = talloc_strdup(state->names,
     1075                                                state->caller.io->in.partner.address);
     1076                if (tevent_req_nomem(name->owner, req)) {
     1077                        return;
     1078                }
    8211079
    8221080                /* trying to save 1 or 2 bytes on the wire isn't a good idea */
    8231081                if (wname->flags & 2) {
    824                         int j;
     1082                        uint32_t j;
    8251083
    8261084                        name->num_addresses = wname->addresses.addresses.num_ips;
    827                         name->addresses = talloc_array(io->out.names,
    828                                                        struct wrepl_address, 
     1085                        name->addresses = talloc_array(state->names,
     1086                                                       struct wrepl_address,
    8291087                                                       name->num_addresses);
    830                         if (name->addresses == NULL) goto nomem;
     1088                        if (tevent_req_nomem(name->addresses, req)) {
     1089                                return;
     1090                        }
     1091
    8311092                        for (j=0;j<name->num_addresses;j++) {
    832                                 name->addresses[j].owner = 
    833                                         talloc_steal(name->addresses,
    834                                                      wname->addresses.addresses.ips[j].owner);
     1093                                name->addresses[j].owner =
     1094                                        talloc_move(name->addresses,
     1095                                                    &wname->addresses.addresses.ips[j].owner);
    8351096                                name->addresses[j].address =
    836                                         talloc_steal(name->addresses,
    837                                                      wname->addresses.addresses.ips[j].ip);
     1097                                        talloc_move(name->addresses,
     1098                                                    &wname->addresses.addresses.ips[j].ip);
    8381099                        }
    8391100                } else {
    8401101                        name->num_addresses = 1;
    841                         name->addresses = talloc(io->out.names, struct wrepl_address);
    842                         if (name->addresses == NULL) goto nomem;
    843                         name->addresses[0].owner = talloc_strdup(name->addresses,io->in.partner.address);
    844                         if (name->addresses[0].owner == NULL) goto nomem;
    845                         name->addresses[0].address = talloc_steal(name->addresses,
    846                                                                   wname->addresses.ip);
     1102                        name->addresses = talloc_array(state->names,
     1103                                                       struct wrepl_address,
     1104                                                       name->num_addresses);
     1105                        if (tevent_req_nomem(name->addresses, req)) {
     1106                                return;
     1107                        }
     1108
     1109                        name->addresses[0].owner = talloc_strdup(name->addresses, name->owner);
     1110                        if (tevent_req_nomem(name->addresses[0].owner, req)) {
     1111                                return;
     1112                        }
     1113                        name->addresses[0].address = talloc_move(name->addresses,
     1114                                                                 &wname->addresses.ip);
    8471115                }
    8481116        }
    8491117
    850         talloc_steal(mem_ctx, io->out.names);
    851         talloc_free(packet);
    852         return NT_STATUS_OK;
    853 nomem:
    854         status = NT_STATUS_NO_MEMORY;
    855 failed:
    856         talloc_free(packet);
    857         return status;
     1118        tevent_req_done(req);
     1119}
     1120
     1121/*
     1122  fetch the names for a WINS partner - recv
     1123*/
     1124NTSTATUS wrepl_pull_names_recv(struct tevent_req *req,
     1125                               TALLOC_CTX *mem_ctx,
     1126                               struct wrepl_pull_names *io)
     1127{
     1128        struct wrepl_pull_names_state *state = tevent_req_data(req,
     1129                                               struct wrepl_pull_names_state);
     1130        NTSTATUS status;
     1131
     1132        if (tevent_req_is_nterror(req, &status)) {
     1133                tevent_req_received(req);
     1134                return status;
     1135        }
     1136
     1137        io->out.num_names = state->num_names;
     1138        io->out.names = talloc_move(mem_ctx, &state->names);
     1139
     1140        tevent_req_received(req);
     1141        return NT_STATUS_OK;
    8581142}
    8591143
     
    8671151                          struct wrepl_pull_names *io)
    8681152{
    869         struct wrepl_request *req = wrepl_pull_names_send(wrepl_socket, io);
    870         return wrepl_pull_names_recv(req, mem_ctx, io);
    871 }
     1153        struct tevent_req *subreq;
     1154        bool ok;
     1155        NTSTATUS status;
     1156
     1157        subreq = wrepl_pull_names_send(mem_ctx, wrepl_socket->event.ctx,
     1158                                       wrepl_socket, io);
     1159        NT_STATUS_HAVE_NO_MEMORY(subreq);
     1160
     1161        ok = tevent_req_poll(subreq, wrepl_socket->event.ctx);
     1162        if (!ok) {
     1163                TALLOC_FREE(subreq);
     1164                return NT_STATUS_INTERNAL_ERROR;
     1165        }
     1166
     1167        status = wrepl_pull_names_recv(subreq, mem_ctx, io);
     1168        TALLOC_FREE(subreq);
     1169        NT_STATUS_NOT_OK_RETURN(status);
     1170
     1171        return NT_STATUS_OK;
     1172}
  • vendor/current/source4/libcli/wrepl/winsrepl.h

    r414 r740  
    55
    66   Copyright (C) Andrew Tridgell 2005
     7   Copyright (C) Stefan Metzmacher 2005-2010
    78
    89   This program is free software; you can redistribute it and/or modify
     
    2324#include "librpc/gen_ndr/winsrepl.h"
    2425
    25 /*
    26   main context structure for the wins replication client library
    27 */
    28 struct wrepl_socket {
    29         struct socket_context *sock;
    30         struct packet_context *packet;
    31 
    32         struct {
    33                 struct tevent_context *ctx;
    34                 struct tevent_fd *fde;
    35         } event;
    36 
    37         /* a queue of replies waiting to be received */
    38         struct wrepl_request *recv_queue;
    39 
    40         /* the default timeout for requests, 0 means no timeout */
    41 #define WREPL_SOCKET_REQUEST_TIMEOUT    (60)
    42         uint32_t request_timeout;
    43 
    44         /* counter for request timeouts, after 2 timeouts the socket is marked as dead */
    45         uint32_t timeout_count;
    46 
    47         /* remember is the socket is dead */
    48         bool dead;
    49 
    50         /* remember if we need to free the wrepl_socket at the end of wrepl_socket_dead() */
    51         bool free_skipped;
    52 
    53         struct smb_iconv_convenience *iconv_convenience;
    54 };
     26struct wrepl_request;
     27struct wrepl_socket;
    5528
    5629struct wrepl_send_ctrl {
     
    5831        bool disconnect_after_send;
    5932};
    60 
    61 enum wrepl_request_state {
    62         WREPL_REQUEST_INIT  = 0,
    63         WREPL_REQUEST_RECV  = 1,
    64         WREPL_REQUEST_DONE  = 2,
    65         WREPL_REQUEST_ERROR = 3
    66 };
    67 
    68 /*
    69   a WINS replication request
    70 */
    71 struct wrepl_request {
    72         struct wrepl_request *next, *prev;
    73         struct wrepl_socket *wrepl_socket;
    74 
    75         enum wrepl_request_state state;
    76         bool trigger;
    77         NTSTATUS status;
    78 
    79         struct tevent_timer *te;
    80 
    81         struct wrepl_packet *packet;
    82 
    83         struct {
    84                 void (*fn)(struct wrepl_request *);
    85                 void *private_data;
    86         } async;
    87 };
    88 
    8933
    9034/*
     
    13074         (is_static ? WREPL_FLAGS_IS_STATIC : 0))
    13175
     76struct wrepl_address {
     77        const char *owner;
     78        const char *address;
     79};
     80
     81struct wrepl_name {
     82        struct nbt_name name;
     83        enum wrepl_name_type type;
     84        enum wrepl_name_state state;
     85        enum wrepl_name_node node;
     86        bool is_static;
     87        uint32_t raw_flags;
     88        uint64_t version_id;
     89        const char *owner;
     90        uint32_t num_addresses;
     91        struct wrepl_address *addresses;
     92};
     93
    13294/*
    13395  a full pull replication
     
    140102        struct {
    141103                uint32_t num_names;
    142                 struct wrepl_name {
    143                         struct nbt_name name;
    144                         enum wrepl_name_type type;
    145                         enum wrepl_name_state state;
    146                         enum wrepl_name_node node;
    147                         bool is_static;
    148                         uint32_t raw_flags;
    149                         uint64_t version_id;
    150                         const char *owner;
    151                         uint32_t num_addresses;
    152                         struct wrepl_address {
    153                                 const char *owner;
    154                                 const char *address;
    155                         } *addresses;
    156                 } *names;
     104                struct wrepl_name *names;
    157105        } out;
    158106};
    159107
    160 struct resolve_context;
     108struct tstream_context;
    161109
    162110#include "libcli/wrepl/winsrepl_proto.h"
Note: See TracChangeset for help on using the changeset viewer.