Ignore:
Timestamp:
Nov 24, 2016, 1:14:11 PM (9 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: update vendor to version 4.4.3

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vendor/current/source3/libsmb/clifile.c

    r746 r988  
    2727#include "trans2.h"
    2828#include "ntioctl.h"
     29#include "libcli/security/secdesc.h"
     30#include "../libcli/smb/smbXcli_base.h"
    2931
    3032/***********************************************************
     
    4951        buflen = talloc_get_size(buf);
    5052
    51         if (align_odd && ucs2 && (buflen % 2 == 0)) {
     53        if (ucs2 &&
     54            ((align_odd && (buflen % 2 == 0)) ||
     55             (!align_odd && (buflen % 2 == 1)))) {
    5256                /*
    5357                 * We're pushing into an SMB buffer, align odd
    5458                 */
    55                 buf = TALLOC_REALLOC_ARRAY(NULL, buf, uint8_t, buflen + 1);
     59                buf = talloc_realloc(NULL, buf, uint8_t, buflen + 1);
    5660                if (buf == NULL) {
    5761                        return NULL;
     
    6468                                   ucs2 ? CH_UTF16LE : CH_DOS,
    6569                                   str, str_len, &converted,
    66                                    &converted_size, true)) {
     70                                   &converted_size)) {
    6771                return NULL;
    6872        }
    6973
    70         buf = TALLOC_REALLOC_ARRAY(NULL, buf, uint8_t,
     74        buf = talloc_realloc(NULL, buf, uint8_t,
    7175                                   buflen + converted_size);
    7276        if (buf == NULL) {
     
    109113        buflen = talloc_get_size(buf);
    110114
    111         buf = TALLOC_REALLOC_ARRAY(NULL, buf, uint8_t,
     115        buf = talloc_realloc(NULL, buf, uint8_t,
    112116                                   buflen + 1 + num_bytes);
    113117        if (buf == NULL) {
     
    126130***********************************************************/
    127131
    128 static uint8_t *trans2_bytes_push_str(uint8_t *buf, bool ucs2,
    129                             const char *str, size_t str_len,
    130                             size_t *pconverted_size)
     132uint8_t *trans2_bytes_push_str(uint8_t *buf, bool ucs2,
     133                               const char *str, size_t str_len,
     134                               size_t *pconverted_size)
    131135{
    132136        return internal_bytes_push_str(buf, ucs2, str, str_len,
    133137                        false, pconverted_size);
     138}
     139
     140uint8_t *trans2_bytes_push_bytes(uint8_t *buf,
     141                                 const uint8_t *bytes, size_t num_bytes)
     142{
     143        size_t buflen;
     144
     145        if (buf == NULL) {
     146                return NULL;
     147        }
     148        buflen = talloc_get_size(buf);
     149
     150        buf = talloc_realloc(NULL, buf, uint8_t,
     151                             buflen + num_bytes);
     152        if (buf == NULL) {
     153                return NULL;
     154        }
     155        memcpy(&buf[buflen], bytes, num_bytes);
     156        return buf;
    134157}
    135158
     
    162185
    163186        /* Setup param array. */
    164         state->param = TALLOC_ZERO_ARRAY(state, uint8_t, 6);
     187        state->param = talloc_zero_array(state, uint8_t, 6);
    165188        if (tevent_req_nomem(state->param, req)) {
    166189                return tevent_req_post(req, ev);
     
    169192
    170193        state->param = trans2_bytes_push_str(
    171                 state->param, cli_ucs2(cli), path, strlen(path)+1, NULL);
     194                state->param, smbXcli_conn_use_unicode(cli->conn), path, strlen(path)+1, NULL);
    172195        if (tevent_req_nomem(state->param, req)) {
    173196                return tevent_req_post(req, ev);
     
    223246        NTSTATUS status = NT_STATUS_NO_MEMORY;
    224247
    225         if (cli_has_async_calls(cli)) {
     248        if (smbXcli_conn_has_async_calls(cli->conn)) {
    226249                /*
    227250                 * Can't use sync call while an async call is in flight
     
    230253                goto fail;
    231254        }
    232         ev = tevent_context_init(frame);
     255        ev = samba_tevent_context_init(frame);
    233256        if (ev == NULL) {
    234257                goto fail;
     
    259282
    260283static struct tevent_req *cli_posix_link_internal_send(TALLOC_CTX *mem_ctx,
    261                                         struct event_context *ev,
     284                                        struct tevent_context *ev,
    262285                                        struct cli_state *cli,
    263286                                        uint16_t level,
     
    280303        }
    281304        state->data = trans2_bytes_push_str(
    282                 state->data, cli_ucs2(cli), oldname, strlen(oldname)+1, NULL);
     305                state->data, smbXcli_conn_use_unicode(cli->conn), oldname, strlen(oldname)+1, NULL);
    283306
    284307        subreq = cli_setpathinfo_send(
     
    303326
    304327struct tevent_req *cli_posix_symlink_send(TALLOC_CTX *mem_ctx,
    305                                         struct event_context *ev,
     328                                        struct tevent_context *ev,
    306329                                        struct cli_state *cli,
    307330                                        const char *oldname,
     
    322345{
    323346        TALLOC_CTX *frame = talloc_stackframe();
    324         struct event_context *ev = NULL;
     347        struct tevent_context *ev = NULL;
    325348        struct tevent_req *req = NULL;
    326349        NTSTATUS status = NT_STATUS_OK;
    327350
    328         if (cli_has_async_calls(cli)) {
     351        if (smbXcli_conn_has_async_calls(cli->conn)) {
    329352                /*
    330353                 * Can't use sync call while an async call is in flight
     
    334357        }
    335358
    336         ev = event_context_init(frame);
     359        ev = samba_tevent_context_init(frame);
    337360        if (ev == NULL) {
    338361                status = NT_STATUS_NO_MEMORY;
     
    350373        }
    351374
    352         if (!tevent_req_poll(req, ev)) {
    353                 status = map_nt_error_from_unix(errno);
     375        if (!tevent_req_poll_ntstatus(req, ev, &status)) {
    354376                goto fail;
    355377        }
     
    374396
    375397struct tevent_req *cli_posix_readlink_send(TALLOC_CTX *mem_ctx,
    376                                         struct event_context *ev,
     398                                        struct tevent_context *ev,
    377399                                        struct cli_state *cli,
    378400                                        const char *fname,
     
    381403        struct tevent_req *req = NULL, *subreq = NULL;
    382404        struct readlink_state *state = NULL;
    383         uint32_t maxbytelen = (uint32_t)(cli_ucs2(cli) ? len*3 : len);
     405        uint32_t maxbytelen = (uint32_t)(smbXcli_conn_use_unicode(cli->conn) ? len*3 : len);
    384406
    385407        req = tevent_req_create(mem_ctx, &state, struct readlink_state);
     
    442464        /* The returned data is a pushed string, not raw data. */
    443465        if (!convert_string_talloc(state,
    444                                 cli_ucs2(cli) ? CH_UTF16LE : CH_DOS,
     466                                smbXcli_conn_use_unicode(cli->conn) ? CH_UTF16LE : CH_DOS,
    445467                                CH_UNIX,
    446468                                state->data,
    447469                                state->num_data,
    448470                                &converted,
    449                                 &converted_size,
    450                                 true)) {
     471                                &converted_size)) {
    451472                return NT_STATUS_NO_MEMORY;
    452473        }
     
    464485{
    465486        TALLOC_CTX *frame = talloc_stackframe();
    466         struct event_context *ev = NULL;
     487        struct tevent_context *ev = NULL;
    467488        struct tevent_req *req = NULL;
    468489        NTSTATUS status = NT_STATUS_OK;
    469490
    470         if (cli_has_async_calls(cli)) {
     491        if (smbXcli_conn_has_async_calls(cli->conn)) {
    471492                /*
    472493                 * Can't use sync call while an async call is in flight
     
    476497        }
    477498
    478         ev = event_context_init(frame);
     499        ev = samba_tevent_context_init(frame);
    479500        if (ev == NULL) {
    480501                status = NT_STATUS_NO_MEMORY;
     
    492513        }
    493514
    494         if (!tevent_req_poll(req, ev)) {
    495                 status = map_nt_error_from_unix(errno);
     515        if (!tevent_req_poll_ntstatus(req, ev, &status)) {
    496516                goto fail;
    497517        }
     
    509529
    510530struct tevent_req *cli_posix_hardlink_send(TALLOC_CTX *mem_ctx,
    511                                         struct event_context *ev,
     531                                        struct tevent_context *ev,
    512532                                        struct cli_state *cli,
    513533                                        const char *oldname,
     
    528548{
    529549        TALLOC_CTX *frame = talloc_stackframe();
    530         struct event_context *ev = NULL;
     550        struct tevent_context *ev = NULL;
    531551        struct tevent_req *req = NULL;
    532552        NTSTATUS status = NT_STATUS_OK;
    533553
    534         if (cli_has_async_calls(cli)) {
     554        if (smbXcli_conn_has_async_calls(cli->conn)) {
    535555                /*
    536556                 * Can't use sync call while an async call is in flight
     
    540560        }
    541561
    542         ev = event_context_init(frame);
     562        ev = samba_tevent_context_init(frame);
    543563        if (ev == NULL) {
    544564                status = NT_STATUS_NO_MEMORY;
     
    556576        }
    557577
    558         if (!tevent_req_poll(req, ev)) {
    559                 status = map_nt_error_from_unix(errno);
     578        if (!tevent_req_poll_ntstatus(req, ev, &status)) {
    560579                goto fail;
    561580        }
     
    569588
    570589/****************************************************************************
    571  Map standard UNIX permissions onto wire representations.
     590 Do a POSIX getacl - pathname based ACL get (UNIX extensions).
    572591****************************************************************************/
    573592
    574 uint32_t unix_perms_to_wire(mode_t perms)
    575 {
    576         unsigned int ret = 0;
    577 
    578         ret |= ((perms & S_IXOTH) ?  UNIX_X_OTH : 0);
    579         ret |= ((perms & S_IWOTH) ?  UNIX_W_OTH : 0);
    580         ret |= ((perms & S_IROTH) ?  UNIX_R_OTH : 0);
    581         ret |= ((perms & S_IXGRP) ?  UNIX_X_GRP : 0);
    582         ret |= ((perms & S_IWGRP) ?  UNIX_W_GRP : 0);
    583         ret |= ((perms & S_IRGRP) ?  UNIX_R_GRP : 0);
    584         ret |= ((perms & S_IXUSR) ?  UNIX_X_USR : 0);
    585         ret |= ((perms & S_IWUSR) ?  UNIX_W_USR : 0);
    586         ret |= ((perms & S_IRUSR) ?  UNIX_R_USR : 0);
    587 #ifdef S_ISVTX
    588         ret |= ((perms & S_ISVTX) ?  UNIX_STICKY : 0);
    589 #endif
    590 #ifdef S_ISGID
    591         ret |= ((perms & S_ISGID) ?  UNIX_SET_GID : 0);
    592 #endif
    593 #ifdef S_ISUID
    594         ret |= ((perms & S_ISUID) ?  UNIX_SET_UID : 0);
    595 #endif
    596         return ret;
    597 }
    598 
    599 /****************************************************************************
    600  Map wire permissions to standard UNIX.
    601 ****************************************************************************/
    602 
    603 mode_t wire_perms_to_unix(uint32_t perms)
    604 {
    605         mode_t ret = (mode_t)0;
    606 
    607         ret |= ((perms & UNIX_X_OTH) ? S_IXOTH : 0);
    608         ret |= ((perms & UNIX_W_OTH) ? S_IWOTH : 0);
    609         ret |= ((perms & UNIX_R_OTH) ? S_IROTH : 0);
    610         ret |= ((perms & UNIX_X_GRP) ? S_IXGRP : 0);
    611         ret |= ((perms & UNIX_W_GRP) ? S_IWGRP : 0);
    612         ret |= ((perms & UNIX_R_GRP) ? S_IRGRP : 0);
    613         ret |= ((perms & UNIX_X_USR) ? S_IXUSR : 0);
    614         ret |= ((perms & UNIX_W_USR) ? S_IWUSR : 0);
    615         ret |= ((perms & UNIX_R_USR) ? S_IRUSR : 0);
    616 #ifdef S_ISVTX
    617         ret |= ((perms & UNIX_STICKY) ? S_ISVTX : 0);
    618 #endif
    619 #ifdef S_ISGID
    620         ret |= ((perms & UNIX_SET_GID) ? S_ISGID : 0);
    621 #endif
    622 #ifdef S_ISUID
    623         ret |= ((perms & UNIX_SET_UID) ? S_ISUID : 0);
    624 #endif
    625         return ret;
    626 }
    627 
    628 /****************************************************************************
    629  Return the file type from the wire filetype for UNIX extensions.
    630 ****************************************************************************/
    631 
    632 static mode_t unix_filetype_from_wire(uint32_t wire_type)
    633 {
    634         switch (wire_type) {
    635                 case UNIX_TYPE_FILE:
    636                         return S_IFREG;
    637                 case UNIX_TYPE_DIR:
    638                         return S_IFDIR;
    639 #ifdef S_IFLNK
    640                 case UNIX_TYPE_SYMLINK:
    641                         return S_IFLNK;
    642 #endif
    643 #ifdef S_IFCHR
    644                 case UNIX_TYPE_CHARDEV:
    645                         return S_IFCHR;
    646 #endif
    647 #ifdef S_IFBLK
    648                 case UNIX_TYPE_BLKDEV:
    649                         return S_IFBLK;
    650 #endif
    651 #ifdef S_IFIFO
    652                 case UNIX_TYPE_FIFO:
    653                         return S_IFIFO;
    654 #endif
    655 #ifdef S_IFSOCK
    656                 case UNIX_TYPE_SOCKET:
    657                         return S_IFSOCK;
    658 #endif
    659                 default:
    660                         return (mode_t)0;
    661         }
    662 }
    663 
    664 /****************************************************************************
    665  Do a POSIX getfacl (UNIX extensions).
    666 ****************************************************************************/
    667 
    668 struct getfacl_state {
     593struct getacl_state {
    669594        uint32_t num_data;
    670595        uint8_t *data;
    671596};
    672597
    673 static void cli_posix_getfacl_done(struct tevent_req *subreq);
    674 
    675 struct tevent_req *cli_posix_getfacl_send(TALLOC_CTX *mem_ctx,
    676                                         struct event_context *ev,
     598static void cli_posix_getacl_done(struct tevent_req *subreq);
     599
     600struct tevent_req *cli_posix_getacl_send(TALLOC_CTX *mem_ctx,
     601                                        struct tevent_context *ev,
    677602                                        struct cli_state *cli,
    678603                                        const char *fname)
    679604{
    680605        struct tevent_req *req = NULL, *subreq = NULL;
    681         struct getfacl_state *state = NULL;
    682 
    683         req = tevent_req_create(mem_ctx, &state, struct getfacl_state);
     606        struct getacl_state *state = NULL;
     607
     608        req = tevent_req_create(mem_ctx, &state, struct getacl_state);
    684609        if (req == NULL) {
    685610                return NULL;
    686611        }
    687612        subreq = cli_qpathinfo_send(state, ev, cli, fname, SMB_QUERY_POSIX_ACL,
    688                                     0, cli->max_xmit);
     613                                    0, CLI_BUFFER_SIZE);
    689614        if (tevent_req_nomem(subreq, req)) {
    690615                return tevent_req_post(req, ev);
    691616        }
    692         tevent_req_set_callback(subreq, cli_posix_getfacl_done, req);
     617        tevent_req_set_callback(subreq, cli_posix_getacl_done, req);
    693618        return req;
    694619}
    695620
    696 static void cli_posix_getfacl_done(struct tevent_req *subreq)
     621static void cli_posix_getacl_done(struct tevent_req *subreq)
    697622{
    698623        struct tevent_req *req = tevent_req_callback_data(
    699624                subreq, struct tevent_req);
    700         struct getfacl_state *state = tevent_req_data(
    701                 req, struct getfacl_state);
     625        struct getacl_state *state = tevent_req_data(
     626                req, struct getacl_state);
    702627        NTSTATUS status;
    703628
     
    711636}
    712637
    713 NTSTATUS cli_posix_getfacl_recv(struct tevent_req *req,
     638NTSTATUS cli_posix_getacl_recv(struct tevent_req *req,
    714639                                TALLOC_CTX *mem_ctx,
    715640                                size_t *prb_size,
    716641                                char **retbuf)
    717642{
    718         struct getfacl_state *state = tevent_req_data(req, struct getfacl_state);
     643        struct getacl_state *state = tevent_req_data(req, struct getacl_state);
    719644        NTSTATUS status;
    720645
     
    727652}
    728653
    729 NTSTATUS cli_posix_getfacl(struct cli_state *cli,
     654NTSTATUS cli_posix_getacl(struct cli_state *cli,
    730655                        const char *fname,
    731656                        TALLOC_CTX *mem_ctx,
     
    734659{
    735660        TALLOC_CTX *frame = talloc_stackframe();
    736         struct event_context *ev = NULL;
     661        struct tevent_context *ev = NULL;
    737662        struct tevent_req *req = NULL;
    738663        NTSTATUS status = NT_STATUS_OK;
    739664
    740         if (cli_has_async_calls(cli)) {
     665        if (smbXcli_conn_has_async_calls(cli->conn)) {
    741666                /*
    742667                 * Can't use sync call while an async call is in flight
     
    746671        }
    747672
    748         ev = event_context_init(frame);
     673        ev = samba_tevent_context_init(frame);
    749674        if (ev == NULL) {
    750675                status = NT_STATUS_NO_MEMORY;
     
    752677        }
    753678
    754         req = cli_posix_getfacl_send(frame,
     679        req = cli_posix_getacl_send(frame,
    755680                                ev,
    756681                                cli,
     
    761686        }
    762687
    763         if (!tevent_req_poll(req, ev)) {
    764                 status = map_nt_error_from_unix(errno);
    765                 goto fail;
    766         }
    767 
    768         status = cli_posix_getfacl_recv(req, mem_ctx, prb_size, retbuf);
     688        if (!tevent_req_poll_ntstatus(req, ev, &status)) {
     689                goto fail;
     690        }
     691
     692        status = cli_posix_getacl_recv(req, mem_ctx, prb_size, retbuf);
     693
     694 fail:
     695        TALLOC_FREE(frame);
     696        return status;
     697}
     698
     699/****************************************************************************
     700 Do a POSIX setacl - pathname based ACL set (UNIX extensions).
     701****************************************************************************/
     702
     703struct setacl_state {
     704        uint8_t *data;
     705};
     706
     707static void cli_posix_setacl_done(struct tevent_req *subreq);
     708
     709struct tevent_req *cli_posix_setacl_send(TALLOC_CTX *mem_ctx,
     710                                        struct tevent_context *ev,
     711                                        struct cli_state *cli,
     712                                        const char *fname,
     713                                        const void *data,
     714                                        size_t num_data)
     715{
     716        struct tevent_req *req = NULL, *subreq = NULL;
     717        struct setacl_state *state = NULL;
     718
     719        req = tevent_req_create(mem_ctx, &state, struct setacl_state);
     720        if (req == NULL) {
     721                return NULL;
     722        }
     723        state->data = talloc_memdup(state, data, num_data);
     724        if (tevent_req_nomem(state->data, req)) {
     725                return tevent_req_post(req, ev);
     726        }
     727
     728        subreq = cli_setpathinfo_send(state,
     729                                ev,
     730                                cli,
     731                                SMB_SET_POSIX_ACL,
     732                                fname,
     733                                state->data,
     734                                num_data);
     735        if (tevent_req_nomem(subreq, req)) {
     736                return tevent_req_post(req, ev);
     737        }
     738        tevent_req_set_callback(subreq, cli_posix_setacl_done, req);
     739        return req;
     740}
     741
     742static void cli_posix_setacl_done(struct tevent_req *subreq)
     743{
     744        NTSTATUS status = cli_setpathinfo_recv(subreq);
     745        tevent_req_simple_finish_ntstatus(subreq, status);
     746}
     747
     748NTSTATUS cli_posix_setacl_recv(struct tevent_req *req)
     749{
     750        return tevent_req_simple_recv_ntstatus(req);
     751}
     752
     753NTSTATUS cli_posix_setacl(struct cli_state *cli,
     754                        const char *fname,
     755                        const void *acl_buf,
     756                        size_t acl_buf_size)
     757{
     758        TALLOC_CTX *frame = talloc_stackframe();
     759        struct tevent_context *ev = NULL;
     760        struct tevent_req *req = NULL;
     761        NTSTATUS status = NT_STATUS_OK;
     762
     763        if (smbXcli_conn_has_async_calls(cli->conn)) {
     764                /*
     765                 * Can't use sync call while an async call is in flight
     766                 */
     767                status = NT_STATUS_INVALID_PARAMETER;
     768                goto fail;
     769        }
     770
     771        ev = samba_tevent_context_init(frame);
     772        if (ev == NULL) {
     773                status = NT_STATUS_NO_MEMORY;
     774                goto fail;
     775        }
     776
     777        req = cli_posix_setacl_send(frame,
     778                                ev,
     779                                cli,
     780                                fname,
     781                                acl_buf,
     782                                acl_buf_size);
     783        if (req == NULL) {
     784                status = NT_STATUS_NO_MEMORY;
     785                goto fail;
     786        }
     787
     788        if (!tevent_req_poll_ntstatus(req, ev, &status)) {
     789                goto fail;
     790        }
     791
     792        status = cli_posix_setacl_recv(req);
    769793
    770794 fail:
     
    785809
    786810struct tevent_req *cli_posix_stat_send(TALLOC_CTX *mem_ctx,
    787                                         struct event_context *ev,
     811                                        struct tevent_context *ev,
    788812                                        struct cli_state *cli,
    789813                                        const char *fname)
     
    865889{
    866890        TALLOC_CTX *frame = talloc_stackframe();
    867         struct event_context *ev = NULL;
     891        struct tevent_context *ev = NULL;
    868892        struct tevent_req *req = NULL;
    869893        NTSTATUS status = NT_STATUS_OK;
    870894
    871         if (cli_has_async_calls(cli)) {
     895        if (smbXcli_conn_has_async_calls(cli->conn)) {
    872896                /*
    873897                 * Can't use sync call while an async call is in flight
     
    877901        }
    878902
    879         ev = event_context_init(frame);
     903        ev = samba_tevent_context_init(frame);
    880904        if (ev == NULL) {
    881905                status = NT_STATUS_NO_MEMORY;
     
    892916        }
    893917
    894         if (!tevent_req_poll(req, ev)) {
    895                 status = map_nt_error_from_unix(errno);
     918        if (!tevent_req_poll_ntstatus(req, ev, &status)) {
    896919                goto fail;
    897920        }
     
    915938
    916939static struct tevent_req *cli_posix_chown_chmod_internal_send(TALLOC_CTX *mem_ctx,
    917                                         struct event_context *ev,
     940                                        struct tevent_context *ev,
    918941                                        struct cli_state *cli,
    919942                                        const char *fname,
     
    958981
    959982struct tevent_req *cli_posix_chmod_send(TALLOC_CTX *mem_ctx,
    960                                         struct event_context *ev,
     983                                        struct tevent_context *ev,
    961984                                        struct cli_state *cli,
    962985                                        const char *fname,
     
    9781001{
    9791002        TALLOC_CTX *frame = talloc_stackframe();
    980         struct event_context *ev = NULL;
     1003        struct tevent_context *ev = NULL;
    9811004        struct tevent_req *req = NULL;
    9821005        NTSTATUS status = NT_STATUS_OK;
    9831006
    984         if (cli_has_async_calls(cli)) {
     1007        if (smbXcli_conn_has_async_calls(cli->conn)) {
    9851008                /*
    9861009                 * Can't use sync call while an async call is in flight
     
    9901013        }
    9911014
    992         ev = event_context_init(frame);
     1015        ev = samba_tevent_context_init(frame);
    9931016        if (ev == NULL) {
    9941017                status = NT_STATUS_NO_MEMORY;
     
    10061029        }
    10071030
    1008         if (!tevent_req_poll(req, ev)) {
    1009                 status = map_nt_error_from_unix(errno);
     1031        if (!tevent_req_poll_ntstatus(req, ev, &status)) {
    10101032                goto fail;
    10111033        }
     
    10231045
    10241046struct tevent_req *cli_posix_chown_send(TALLOC_CTX *mem_ctx,
    1025                                         struct event_context *ev,
     1047                                        struct tevent_context *ev,
    10261048                                        struct cli_state *cli,
    10271049                                        const char *fname,
     
    10471069{
    10481070        TALLOC_CTX *frame = talloc_stackframe();
    1049         struct event_context *ev = NULL;
     1071        struct tevent_context *ev = NULL;
    10501072        struct tevent_req *req = NULL;
    10511073        NTSTATUS status = NT_STATUS_OK;
    10521074
    1053         if (cli_has_async_calls(cli)) {
     1075        if (smbXcli_conn_has_async_calls(cli->conn)) {
    10541076                /*
    10551077                 * Can't use sync call while an async call is in flight
     
    10591081        }
    10601082
    1061         ev = event_context_init(frame);
     1083        ev = samba_tevent_context_init(frame);
    10621084        if (ev == NULL) {
    10631085                status = NT_STATUS_NO_MEMORY;
     
    10761098        }
    10771099
    1078         if (!tevent_req_poll(req, ev)) {
    1079                 status = map_nt_error_from_unix(errno);
     1100        if (!tevent_req_poll_ntstatus(req, ev, &status)) {
    10801101                goto fail;
    10811102        }
     
    10991120
    11001121struct tevent_req *cli_rename_send(TALLOC_CTX *mem_ctx,
    1101                                 struct event_context *ev,
     1122                                struct tevent_context *ev,
    11021123                                struct cli_state *cli,
    11031124                                const char *fname_src,
     
    11211142        }
    11221143        bytes[0] = 4;
    1123         bytes = smb_bytes_push_str(bytes, cli_ucs2(cli), fname_src,
     1144        bytes = smb_bytes_push_str(bytes, smbXcli_conn_use_unicode(cli->conn), fname_src,
    11241145                                   strlen(fname_src)+1, NULL);
    11251146        if (tevent_req_nomem(bytes, req)) {
     
    11271148        }
    11281149
    1129         bytes = TALLOC_REALLOC_ARRAY(state, bytes, uint8_t,
     1150        bytes = talloc_realloc(state, bytes, uint8_t,
    11301151                        talloc_get_size(bytes)+1);
    11311152        if (tevent_req_nomem(bytes, req)) {
     
    11341155
    11351156        bytes[talloc_get_size(bytes)-1] = 4;
    1136         bytes = smb_bytes_push_str(bytes, cli_ucs2(cli), fname_dst,
     1157        bytes = smb_bytes_push_str(bytes, smbXcli_conn_use_unicode(cli->conn), fname_dst,
    11371158                                   strlen(fname_dst)+1, NULL);
    11381159        if (tevent_req_nomem(bytes, req)) {
     
    11701191NTSTATUS cli_rename(struct cli_state *cli, const char *fname_src, const char *fname_dst)
    11711192{
    1172         TALLOC_CTX *frame = talloc_stackframe();
    1173         struct event_context *ev;
     1193        TALLOC_CTX *frame = NULL;
     1194        struct tevent_context *ev;
    11741195        struct tevent_req *req;
    11751196        NTSTATUS status = NT_STATUS_OK;
    11761197
    1177         if (cli_has_async_calls(cli)) {
     1198        if (smbXcli_conn_protocol(cli->conn) >= PROTOCOL_SMB2_02) {
     1199                return cli_smb2_rename(cli,
     1200                                        fname_src,
     1201                                        fname_dst);
     1202        }
     1203
     1204        frame = talloc_stackframe();
     1205
     1206        if (smbXcli_conn_has_async_calls(cli->conn)) {
    11781207                /*
    11791208                 * Can't use sync call while an async call is in flight
     
    11831212        }
    11841213
    1185         ev = event_context_init(frame);
     1214        ev = samba_tevent_context_init(frame);
    11861215        if (ev == NULL) {
    11871216                status = NT_STATUS_NO_MEMORY;
     
    11951224        }
    11961225
    1197         if (!tevent_req_poll(req, ev)) {
    1198                 status = map_nt_error_from_unix(errno);
     1226        if (!tevent_req_poll_ntstatus(req, ev, &status)) {
    11991227                goto fail;
    12001228        }
     
    12181246
    12191247static struct tevent_req *cli_ntrename_internal_send(TALLOC_CTX *mem_ctx,
    1220                                 struct event_context *ev,
     1248                                struct tevent_context *ev,
    12211249                                struct cli_state *cli,
    12221250                                const char *fname_src,
     
    12431271        }
    12441272        bytes[0] = 4;
    1245         bytes = smb_bytes_push_str(bytes, cli_ucs2(cli), fname_src,
     1273        bytes = smb_bytes_push_str(bytes, smbXcli_conn_use_unicode(cli->conn), fname_src,
    12461274                                   strlen(fname_src)+1, NULL);
    12471275        if (tevent_req_nomem(bytes, req)) {
     
    12491277        }
    12501278
    1251         bytes = TALLOC_REALLOC_ARRAY(state, bytes, uint8_t,
     1279        bytes = talloc_realloc(state, bytes, uint8_t,
    12521280                        talloc_get_size(bytes)+1);
    12531281        if (tevent_req_nomem(bytes, req)) {
     
    12561284
    12571285        bytes[talloc_get_size(bytes)-1] = 4;
    1258         bytes = smb_bytes_push_str(bytes, cli_ucs2(cli), fname_dst,
     1286        bytes = smb_bytes_push_str(bytes, smbXcli_conn_use_unicode(cli->conn), fname_dst,
    12591287                                   strlen(fname_dst)+1, NULL);
    12601288        if (tevent_req_nomem(bytes, req)) {
     
    12911319
    12921320struct tevent_req *cli_ntrename_send(TALLOC_CTX *mem_ctx,
    1293                                 struct event_context *ev,
     1321                                struct tevent_context *ev,
    12941322                                struct cli_state *cli,
    12951323                                const char *fname_src,
     
    13121340{
    13131341        TALLOC_CTX *frame = talloc_stackframe();
    1314         struct event_context *ev;
     1342        struct tevent_context *ev;
    13151343        struct tevent_req *req;
    13161344        NTSTATUS status = NT_STATUS_OK;
    13171345
    1318         if (cli_has_async_calls(cli)) {
     1346        if (smbXcli_conn_has_async_calls(cli->conn)) {
    13191347                /*
    13201348                 * Can't use sync call while an async call is in flight
     
    13241352        }
    13251353
    1326         ev = event_context_init(frame);
     1354        ev = samba_tevent_context_init(frame);
    13271355        if (ev == NULL) {
    13281356                status = NT_STATUS_NO_MEMORY;
     
    13361364        }
    13371365
    1338         if (!tevent_req_poll(req, ev)) {
    1339                 status = map_nt_error_from_unix(errno);
     1366        if (!tevent_req_poll_ntstatus(req, ev, &status)) {
    13401367                goto fail;
    13411368        }
     
    13531380
    13541381struct tevent_req *cli_nt_hardlink_send(TALLOC_CTX *mem_ctx,
    1355                                 struct event_context *ev,
     1382                                struct tevent_context *ev,
    13561383                                struct cli_state *cli,
    13571384                                const char *fname_src,
     
    13741401{
    13751402        TALLOC_CTX *frame = talloc_stackframe();
    1376         struct event_context *ev;
     1403        struct tevent_context *ev;
    13771404        struct tevent_req *req;
    13781405        NTSTATUS status = NT_STATUS_OK;
    13791406
    1380         if (cli_has_async_calls(cli)) {
     1407        if (smbXcli_conn_has_async_calls(cli->conn)) {
    13811408                /*
    13821409                 * Can't use sync call while an async call is in flight
     
    13861413        }
    13871414
    1388         ev = event_context_init(frame);
     1415        ev = samba_tevent_context_init(frame);
    13891416        if (ev == NULL) {
    13901417                status = NT_STATUS_NO_MEMORY;
     
    13981425        }
    13991426
    1400         if (!tevent_req_poll(req, ev)) {
    1401                 status = map_nt_error_from_unix(errno);
     1427        if (!tevent_req_poll_ntstatus(req, ev, &status)) {
    14021428                goto fail;
    14031429        }
     
    14211447
    14221448struct tevent_req *cli_unlink_send(TALLOC_CTX *mem_ctx,
    1423                                 struct event_context *ev,
     1449                                struct tevent_context *ev,
    14241450                                struct cli_state *cli,
    14251451                                const char *fname,
     
    14431469        }
    14441470        bytes[0] = 4;
    1445         bytes = smb_bytes_push_str(bytes, cli_ucs2(cli), fname,
     1471        bytes = smb_bytes_push_str(bytes, smbXcli_conn_use_unicode(cli->conn), fname,
    14461472                                   strlen(fname)+1, NULL);
    14471473
     
    14801506NTSTATUS cli_unlink(struct cli_state *cli, const char *fname, uint16_t mayhave_attrs)
    14811507{
    1482         TALLOC_CTX *frame = talloc_stackframe();
    1483         struct event_context *ev;
     1508        TALLOC_CTX *frame = NULL;
     1509        struct tevent_context *ev;
    14841510        struct tevent_req *req;
    14851511        NTSTATUS status = NT_STATUS_OK;
    14861512
    1487         if (cli_has_async_calls(cli)) {
     1513        if (smbXcli_conn_protocol(cli->conn) >= PROTOCOL_SMB2_02) {
     1514                return cli_smb2_unlink(cli, fname);
     1515        }
     1516
     1517        frame = talloc_stackframe();
     1518
     1519        if (smbXcli_conn_has_async_calls(cli->conn)) {
    14881520                /*
    14891521                 * Can't use sync call while an async call is in flight
     
    14931525        }
    14941526
    1495         ev = event_context_init(frame);
     1527        ev = samba_tevent_context_init(frame);
    14961528        if (ev == NULL) {
    14971529                status = NT_STATUS_NO_MEMORY;
     
    15051537        }
    15061538
    1507         if (!tevent_req_poll(req, ev)) {
    1508                 status = map_nt_error_from_unix(errno);
     1539        if (!tevent_req_poll_ntstatus(req, ev, &status)) {
    15091540                goto fail;
    15101541        }
     
    15281559
    15291560struct tevent_req *cli_mkdir_send(TALLOC_CTX *mem_ctx,
    1530                                   struct event_context *ev,
     1561                                  struct tevent_context *ev,
    15311562                                  struct cli_state *cli,
    15321563                                  const char *dname)
     
    15471578        }
    15481579        bytes[0] = 4;
    1549         bytes = smb_bytes_push_str(bytes, cli_ucs2(cli), dname,
     1580        bytes = smb_bytes_push_str(bytes, smbXcli_conn_use_unicode(cli->conn), dname,
    15501581                                   strlen(dname)+1, NULL);
    15511582
     
    15841615NTSTATUS cli_mkdir(struct cli_state *cli, const char *dname)
    15851616{
    1586         TALLOC_CTX *frame = talloc_stackframe();
    1587         struct event_context *ev;
     1617        TALLOC_CTX *frame = NULL;
     1618        struct tevent_context *ev;
    15881619        struct tevent_req *req;
    15891620        NTSTATUS status = NT_STATUS_OK;
    15901621
    1591         if (cli_has_async_calls(cli)) {
     1622        if (smbXcli_conn_protocol(cli->conn) >= PROTOCOL_SMB2_02) {
     1623                return cli_smb2_mkdir(cli, dname);
     1624        }
     1625
     1626        frame = talloc_stackframe();
     1627
     1628        if (smbXcli_conn_has_async_calls(cli->conn)) {
    15921629                /*
    15931630                 * Can't use sync call while an async call is in flight
     
    15971634        }
    15981635
    1599         ev = event_context_init(frame);
     1636        ev = samba_tevent_context_init(frame);
    16001637        if (ev == NULL) {
    16011638                status = NT_STATUS_NO_MEMORY;
     
    16091646        }
    16101647
    1611         if (!tevent_req_poll(req, ev)) {
    1612                 status = map_nt_error_from_unix(errno);
     1648        if (!tevent_req_poll_ntstatus(req, ev, &status)) {
    16131649                goto fail;
    16141650        }
     
    16321668
    16331669struct tevent_req *cli_rmdir_send(TALLOC_CTX *mem_ctx,
    1634                                   struct event_context *ev,
     1670                                  struct tevent_context *ev,
    16351671                                  struct cli_state *cli,
    16361672                                  const char *dname)
     
    16511687        }
    16521688        bytes[0] = 4;
    1653         bytes = smb_bytes_push_str(bytes, cli_ucs2(cli), dname,
     1689        bytes = smb_bytes_push_str(bytes, smbXcli_conn_use_unicode(cli->conn), dname,
    16541690                                   strlen(dname)+1, NULL);
    16551691
     
    16881724NTSTATUS cli_rmdir(struct cli_state *cli, const char *dname)
    16891725{
    1690         TALLOC_CTX *frame = talloc_stackframe();
    1691         struct event_context *ev;
     1726        TALLOC_CTX *frame = NULL;
     1727        struct tevent_context *ev;
    16921728        struct tevent_req *req;
    16931729        NTSTATUS status = NT_STATUS_OK;
    16941730
    1695         if (cli_has_async_calls(cli)) {
     1731        if (smbXcli_conn_protocol(cli->conn) >= PROTOCOL_SMB2_02) {
     1732                return cli_smb2_rmdir(cli, dname);
     1733        }
     1734
     1735        frame = talloc_stackframe();
     1736
     1737        if (smbXcli_conn_has_async_calls(cli->conn)) {
    16961738                /*
    16971739                 * Can't use sync call while an async call is in flight
     
    17011743        }
    17021744
    1703         ev = event_context_init(frame);
     1745        ev = samba_tevent_context_init(frame);
    17041746        if (ev == NULL) {
    17051747                status = NT_STATUS_NO_MEMORY;
     
    17131755        }
    17141756
    1715         if (!tevent_req_poll(req, ev)) {
    1716                 status = map_nt_error_from_unix(errno);
     1757        if (!tevent_req_poll_ntstatus(req, ev, &status)) {
    17171758                goto fail;
    17181759        }
     
    17431784
    17441785struct tevent_req *cli_nt_delete_on_close_send(TALLOC_CTX *mem_ctx,
    1745                                         struct event_context *ev,
     1786                                        struct tevent_context *ev,
    17461787                                        struct cli_state *cli,
    17471788                                        uint16_t fnum,
     
    17991840{
    18001841        TALLOC_CTX *frame = talloc_stackframe();
    1801         struct event_context *ev = NULL;
     1842        struct tevent_context *ev = NULL;
    18021843        struct tevent_req *req = NULL;
    18031844        NTSTATUS status = NT_STATUS_OK;
    18041845
    1805         if (cli_has_async_calls(cli)) {
     1846        if (smbXcli_conn_has_async_calls(cli->conn)) {
    18061847                /*
    18071848                 * Can't use sync call while an async call is in flight
     
    18111852        }
    18121853
    1813         ev = event_context_init(frame);
     1854        ev = samba_tevent_context_init(frame);
    18141855        if (ev == NULL) {
    18151856                status = NT_STATUS_NO_MEMORY;
     
    18271868        }
    18281869
    1829         if (!tevent_req_poll(req, ev)) {
    1830                 status = map_nt_error_from_unix(errno);
     1870        if (!tevent_req_poll_ntstatus(req, ev, &status)) {
    18311871                goto fail;
    18321872        }
     
    18391879}
    18401880
    1841 struct cli_ntcreate_state {
     1881struct cli_ntcreate1_state {
    18421882        uint16_t vwv[24];
    18431883        uint16_t fnum;
     1884        struct smb_create_returns cr;
     1885        struct tevent_req *subreq;
    18441886};
    18451887
    1846 static void cli_ntcreate_done(struct tevent_req *subreq);
    1847 
    1848 struct tevent_req *cli_ntcreate_send(TALLOC_CTX *mem_ctx,
    1849                                      struct event_context *ev,
    1850                                      struct cli_state *cli,
    1851                                      const char *fname,
    1852                                      uint32_t CreatFlags,
    1853                                      uint32_t DesiredAccess,
    1854                                      uint32_t FileAttributes,
    1855                                      uint32_t ShareAccess,
    1856                                      uint32_t CreateDisposition,
    1857                                      uint32_t CreateOptions,
    1858                                      uint8_t SecurityFlags)
     1888static void cli_ntcreate1_done(struct tevent_req *subreq);
     1889static bool cli_ntcreate1_cancel(struct tevent_req *req);
     1890
     1891static struct tevent_req *cli_ntcreate1_send(TALLOC_CTX *mem_ctx,
     1892                                             struct tevent_context *ev,
     1893                                             struct cli_state *cli,
     1894                                             const char *fname,
     1895                                             uint32_t CreatFlags,
     1896                                             uint32_t DesiredAccess,
     1897                                             uint32_t FileAttributes,
     1898                                             uint32_t ShareAccess,
     1899                                             uint32_t CreateDisposition,
     1900                                             uint32_t CreateOptions,
     1901                                             uint8_t SecurityFlags)
    18591902{
    18601903        struct tevent_req *req, *subreq;
    1861         struct cli_ntcreate_state *state;
     1904        struct cli_ntcreate1_state *state;
    18621905        uint16_t *vwv;
    18631906        uint8_t *bytes;
    18641907        size_t converted_len;
    18651908
    1866         req = tevent_req_create(mem_ctx, &state, struct cli_ntcreate_state);
     1909        req = tevent_req_create(mem_ctx, &state, struct cli_ntcreate1_state);
    18671910        if (req == NULL) {
    18681911                return NULL;
     
    18871930        SIVAL(vwv+15, 1, ShareAccess);
    18881931        SIVAL(vwv+17, 1, CreateDisposition);
    1889         SIVAL(vwv+19, 1, CreateOptions);
     1932        SIVAL(vwv+19, 1, CreateOptions |
     1933                (cli->backup_intent ? FILE_OPEN_FOR_BACKUP_INTENT : 0));
    18901934        SIVAL(vwv+21, 1, 0x02); /* ImpersonationLevel */
    18911935        SCVAL(vwv+23, 1, SecurityFlags);
    18921936
    18931937        bytes = talloc_array(state, uint8_t, 0);
    1894         bytes = smb_bytes_push_str(bytes, cli_ucs2(cli),
     1938        bytes = smb_bytes_push_str(bytes, smbXcli_conn_use_unicode(cli->conn),
    18951939                                   fname, strlen(fname)+1,
    18961940                                   &converted_len);
    18971941
    18981942        /* sigh. this copes with broken netapp filer behaviour */
    1899         bytes = smb_bytes_push_str(bytes, cli_ucs2(cli), "", 1, NULL);
     1943        bytes = smb_bytes_push_str(bytes, smbXcli_conn_use_unicode(cli->conn), "", 1, NULL);
    19001944
    19011945        if (tevent_req_nomem(bytes, req)) {
     
    19101954                return tevent_req_post(req, ev);
    19111955        }
     1956        tevent_req_set_callback(subreq, cli_ntcreate1_done, req);
     1957
     1958        state->subreq = subreq;
     1959        tevent_req_set_cancel_fn(req, cli_ntcreate1_cancel);
     1960
     1961        return req;
     1962}
     1963
     1964static void cli_ntcreate1_done(struct tevent_req *subreq)
     1965{
     1966        struct tevent_req *req = tevent_req_callback_data(
     1967                subreq, struct tevent_req);
     1968        struct cli_ntcreate1_state *state = tevent_req_data(
     1969                req, struct cli_ntcreate1_state);
     1970        uint8_t wct;
     1971        uint16_t *vwv;
     1972        uint32_t num_bytes;
     1973        uint8_t *bytes;
     1974        NTSTATUS status;
     1975
     1976        status = cli_smb_recv(subreq, state, NULL, 34, &wct, &vwv,
     1977                              &num_bytes, &bytes);
     1978        TALLOC_FREE(subreq);
     1979        if (tevent_req_nterror(req, status)) {
     1980                return;
     1981        }
     1982        state->cr.oplock_level = CVAL(vwv+2, 0);
     1983        state->fnum = SVAL(vwv+2, 1);
     1984        state->cr.create_action = IVAL(vwv+3, 1);
     1985        state->cr.creation_time = BVAL(vwv+5, 1);
     1986        state->cr.last_access_time = BVAL(vwv+9, 1);
     1987        state->cr.last_write_time = BVAL(vwv+13, 1);
     1988        state->cr.change_time   = BVAL(vwv+17, 1);
     1989        state->cr.file_attributes = IVAL(vwv+21, 1);
     1990        state->cr.allocation_size = BVAL(vwv+23, 1);
     1991        state->cr.end_of_file   = BVAL(vwv+27, 1);
     1992
     1993        tevent_req_done(req);
     1994}
     1995
     1996static bool cli_ntcreate1_cancel(struct tevent_req *req)
     1997{
     1998        struct cli_ntcreate1_state *state = tevent_req_data(
     1999                req, struct cli_ntcreate1_state);
     2000        return tevent_req_cancel(state->subreq);
     2001}
     2002
     2003static NTSTATUS cli_ntcreate1_recv(struct tevent_req *req,
     2004                                   uint16_t *pfnum,
     2005                                   struct smb_create_returns *cr)
     2006{
     2007        struct cli_ntcreate1_state *state = tevent_req_data(
     2008                req, struct cli_ntcreate1_state);
     2009        NTSTATUS status;
     2010
     2011        if (tevent_req_is_nterror(req, &status)) {
     2012                return status;
     2013        }
     2014        *pfnum = state->fnum;
     2015        if (cr != NULL) {
     2016                *cr = state->cr;
     2017        }
     2018        return NT_STATUS_OK;
     2019}
     2020
     2021struct cli_ntcreate_state {
     2022        NTSTATUS (*recv)(struct tevent_req *req, uint16_t *fnum,
     2023                         struct smb_create_returns *cr);
     2024        struct smb_create_returns cr;
     2025        uint16_t fnum;
     2026        struct tevent_req *subreq;
     2027};
     2028
     2029static void cli_ntcreate_done(struct tevent_req *subreq);
     2030static bool cli_ntcreate_cancel(struct tevent_req *req);
     2031
     2032struct tevent_req *cli_ntcreate_send(TALLOC_CTX *mem_ctx,
     2033                                     struct tevent_context *ev,
     2034                                     struct cli_state *cli,
     2035                                     const char *fname,
     2036                                     uint32_t create_flags,
     2037                                     uint32_t desired_access,
     2038                                     uint32_t file_attributes,
     2039                                     uint32_t share_access,
     2040                                     uint32_t create_disposition,
     2041                                     uint32_t create_options,
     2042                                     uint8_t security_flags)
     2043{
     2044        struct tevent_req *req, *subreq;
     2045        struct cli_ntcreate_state *state;
     2046
     2047        req = tevent_req_create(mem_ctx, &state, struct cli_ntcreate_state);
     2048        if (req == NULL) {
     2049                return NULL;
     2050        }
     2051
     2052        if (smbXcli_conn_protocol(cli->conn) >= PROTOCOL_SMB2_02) {
     2053                state->recv = cli_smb2_create_fnum_recv;
     2054
     2055                if (cli->use_oplocks) {
     2056                        create_flags |= REQUEST_OPLOCK|REQUEST_BATCH_OPLOCK;
     2057                }
     2058
     2059                subreq = cli_smb2_create_fnum_send(
     2060                        state, ev, cli, fname, create_flags, desired_access,
     2061                        file_attributes, share_access, create_disposition,
     2062                        create_options);
     2063        } else {
     2064                state->recv = cli_ntcreate1_recv;
     2065                subreq = cli_ntcreate1_send(
     2066                        state, ev, cli, fname, create_flags, desired_access,
     2067                        file_attributes, share_access, create_disposition,
     2068                        create_options, security_flags);
     2069        }
     2070        if (tevent_req_nomem(subreq, req)) {
     2071                return tevent_req_post(req, ev);
     2072        }
    19122073        tevent_req_set_callback(subreq, cli_ntcreate_done, req);
     2074
     2075        state->subreq = subreq;
     2076        tevent_req_set_cancel_fn(req, cli_ntcreate_cancel);
     2077
    19132078        return req;
    19142079}
     
    19202085        struct cli_ntcreate_state *state = tevent_req_data(
    19212086                req, struct cli_ntcreate_state);
    1922         uint8_t wct;
    1923         uint16_t *vwv;
    1924         uint32_t num_bytes;
    1925         uint8_t *bytes;
    1926         uint8_t *inbuf;
    19272087        NTSTATUS status;
    19282088
    1929         status = cli_smb_recv(subreq, state, &inbuf, 3, &wct, &vwv,
    1930                               &num_bytes, &bytes);
     2089        status = state->recv(subreq, &state->fnum, &state->cr);
    19312090        TALLOC_FREE(subreq);
    19322091        if (tevent_req_nterror(req, status)) {
    19332092                return;
    19342093        }
    1935         state->fnum = SVAL(vwv+2, 1);
    19362094        tevent_req_done(req);
    19372095}
    19382096
    1939 NTSTATUS cli_ntcreate_recv(struct tevent_req *req, uint16_t *pfnum)
     2097static bool cli_ntcreate_cancel(struct tevent_req *req)
     2098{
     2099        struct cli_ntcreate_state *state = tevent_req_data(
     2100                req, struct cli_ntcreate_state);
     2101        return tevent_req_cancel(state->subreq);
     2102}
     2103
     2104NTSTATUS cli_ntcreate_recv(struct tevent_req *req, uint16_t *fnum,
     2105                           struct smb_create_returns *cr)
    19402106{
    19412107        struct cli_ntcreate_state *state = tevent_req_data(
     
    19462112                return status;
    19472113        }
    1948         *pfnum = state->fnum;
     2114        if (fnum != NULL) {
     2115                *fnum = state->fnum;
     2116        }
     2117        if (cr != NULL) {
     2118                *cr = state->cr;
     2119        }
    19492120        return NT_STATUS_OK;
    19502121}
     
    19592130                      uint32_t CreateOptions,
    19602131                      uint8_t SecurityFlags,
    1961                       uint16_t *pfid)
     2132                      uint16_t *pfid,
     2133                      struct smb_create_returns *cr)
    19622134{
    19632135        TALLOC_CTX *frame = talloc_stackframe();
    1964         struct event_context *ev;
     2136        struct tevent_context *ev;
    19652137        struct tevent_req *req;
    1966         NTSTATUS status = NT_STATUS_OK;
    1967 
    1968         if (cli_has_async_calls(cli)) {
     2138        NTSTATUS status = NT_STATUS_NO_MEMORY;
     2139
     2140        if (smbXcli_conn_has_async_calls(cli->conn)) {
    19692141                /*
    19702142                 * Can't use sync call while an async call is in flight
     
    19742146        }
    19752147
    1976         ev = event_context_init(frame);
     2148        ev = samba_tevent_context_init(frame);
    19772149        if (ev == NULL) {
    1978                 status = NT_STATUS_NO_MEMORY;
    19792150                goto fail;
    19802151        }
     
    19852156                                SecurityFlags);
    19862157        if (req == NULL) {
    1987                 status = NT_STATUS_NO_MEMORY;
    1988                 goto fail;
    1989         }
    1990 
    1991         if (!tevent_req_poll(req, ev)) {
    1992                 status = map_nt_error_from_unix(errno);
    1993                 goto fail;
    1994         }
    1995 
    1996         status = cli_ntcreate_recv(req, pfid);
     2158                goto fail;
     2159        }
     2160
     2161        if (!tevent_req_poll_ntstatus(req, ev, &status)) {
     2162                goto fail;
     2163        }
     2164
     2165        status = cli_ntcreate_recv(req, pfid, cr);
     2166 fail:
     2167        TALLOC_FREE(frame);
     2168        return status;
     2169}
     2170
     2171struct cli_nttrans_create_state {
     2172        uint16_t fnum;
     2173        struct smb_create_returns cr;
     2174};
     2175
     2176static void cli_nttrans_create_done(struct tevent_req *subreq);
     2177
     2178struct tevent_req *cli_nttrans_create_send(TALLOC_CTX *mem_ctx,
     2179                                           struct tevent_context *ev,
     2180                                           struct cli_state *cli,
     2181                                           const char *fname,
     2182                                           uint32_t CreatFlags,
     2183                                           uint32_t DesiredAccess,
     2184                                           uint32_t FileAttributes,
     2185                                           uint32_t ShareAccess,
     2186                                           uint32_t CreateDisposition,
     2187                                           uint32_t CreateOptions,
     2188                                           uint8_t SecurityFlags,
     2189                                           struct security_descriptor *secdesc,
     2190                                           struct ea_struct *eas,
     2191                                           int num_eas)
     2192{
     2193        struct tevent_req *req, *subreq;
     2194        struct cli_nttrans_create_state *state;
     2195        uint8_t *param;
     2196        uint8_t *secdesc_buf;
     2197        size_t secdesc_len;
     2198        NTSTATUS status;
     2199        size_t converted_len;
     2200
     2201        req = tevent_req_create(mem_ctx,
     2202                                &state, struct cli_nttrans_create_state);
     2203        if (req == NULL) {
     2204                return NULL;
     2205        }
     2206
     2207        if (secdesc != NULL) {
     2208                status = marshall_sec_desc(talloc_tos(), secdesc,
     2209                                           &secdesc_buf, &secdesc_len);
     2210                if (tevent_req_nterror(req, status)) {
     2211                        DEBUG(10, ("marshall_sec_desc failed: %s\n",
     2212                                   nt_errstr(status)));
     2213                        return tevent_req_post(req, ev);
     2214                }
     2215        } else {
     2216                secdesc_buf = NULL;
     2217                secdesc_len = 0;
     2218        }
     2219
     2220        if (num_eas != 0) {
     2221                /*
     2222                 * TODO ;-)
     2223                 */
     2224                tevent_req_nterror(req, NT_STATUS_NOT_IMPLEMENTED);
     2225                return tevent_req_post(req, ev);
     2226        }
     2227
     2228        param = talloc_array(state, uint8_t, 53);
     2229        if (tevent_req_nomem(param, req)) {
     2230                return tevent_req_post(req, ev);
     2231        }
     2232
     2233        param = trans2_bytes_push_str(param, smbXcli_conn_use_unicode(cli->conn),
     2234                                      fname, strlen(fname),
     2235                                      &converted_len);
     2236        if (tevent_req_nomem(param, req)) {
     2237                return tevent_req_post(req, ev);
     2238        }
     2239
     2240        SIVAL(param, 0, CreatFlags);
     2241        SIVAL(param, 4, 0x0);   /* RootDirectoryFid */
     2242        SIVAL(param, 8, DesiredAccess);
     2243        SIVAL(param, 12, 0x0);  /* AllocationSize */
     2244        SIVAL(param, 16, 0x0);  /* AllocationSize */
     2245        SIVAL(param, 20, FileAttributes);
     2246        SIVAL(param, 24, ShareAccess);
     2247        SIVAL(param, 28, CreateDisposition);
     2248        SIVAL(param, 32, CreateOptions |
     2249                (cli->backup_intent ? FILE_OPEN_FOR_BACKUP_INTENT : 0));
     2250        SIVAL(param, 36, secdesc_len);
     2251        SIVAL(param, 40, 0);     /* EA length*/
     2252        SIVAL(param, 44, converted_len);
     2253        SIVAL(param, 48, 0x02); /* ImpersonationLevel */
     2254        SCVAL(param, 52, SecurityFlags);
     2255
     2256        subreq = cli_trans_send(state, ev, cli, SMBnttrans,
     2257                                NULL, -1, /* name, fid */
     2258                                NT_TRANSACT_CREATE, 0,
     2259                                NULL, 0, 0, /* setup */
     2260                                param, talloc_get_size(param), 128, /* param */
     2261                                secdesc_buf, secdesc_len, 0); /* data */
     2262        if (tevent_req_nomem(subreq, req)) {
     2263                return tevent_req_post(req, ev);
     2264        }
     2265        tevent_req_set_callback(subreq, cli_nttrans_create_done, req);
     2266        return req;
     2267}
     2268
     2269static void cli_nttrans_create_done(struct tevent_req *subreq)
     2270{
     2271        struct tevent_req *req = tevent_req_callback_data(
     2272                subreq, struct tevent_req);
     2273        struct cli_nttrans_create_state *state = tevent_req_data(
     2274                req, struct cli_nttrans_create_state);
     2275        uint8_t *param;
     2276        uint32_t num_param;
     2277        NTSTATUS status;
     2278
     2279        status = cli_trans_recv(subreq, talloc_tos(), NULL,
     2280                                NULL, 0, NULL, /* rsetup */
     2281                                &param, 69, &num_param,
     2282                                NULL, 0, NULL);
     2283        if (tevent_req_nterror(req, status)) {
     2284                return;
     2285        }
     2286        state->cr.oplock_level = CVAL(param, 0);
     2287        state->fnum = SVAL(param, 2);
     2288        state->cr.create_action = IVAL(param, 4);
     2289        state->cr.creation_time = BVAL(param, 12);
     2290        state->cr.last_access_time = BVAL(param, 20);
     2291        state->cr.last_write_time = BVAL(param, 28);
     2292        state->cr.change_time   = BVAL(param, 36);
     2293        state->cr.file_attributes = IVAL(param, 44);
     2294        state->cr.allocation_size = BVAL(param, 48);
     2295        state->cr.end_of_file   = BVAL(param, 56);
     2296
     2297        TALLOC_FREE(param);
     2298        tevent_req_done(req);
     2299}
     2300
     2301NTSTATUS cli_nttrans_create_recv(struct tevent_req *req,
     2302                        uint16_t *fnum,
     2303                        struct smb_create_returns *cr)
     2304{
     2305        struct cli_nttrans_create_state *state = tevent_req_data(
     2306                req, struct cli_nttrans_create_state);
     2307        NTSTATUS status;
     2308
     2309        if (tevent_req_is_nterror(req, &status)) {
     2310                return status;
     2311        }
     2312        *fnum = state->fnum;
     2313        if (cr != NULL) {
     2314                *cr = state->cr;
     2315        }
     2316        return NT_STATUS_OK;
     2317}
     2318
     2319NTSTATUS cli_nttrans_create(struct cli_state *cli,
     2320                            const char *fname,
     2321                            uint32_t CreatFlags,
     2322                            uint32_t DesiredAccess,
     2323                            uint32_t FileAttributes,
     2324                            uint32_t ShareAccess,
     2325                            uint32_t CreateDisposition,
     2326                            uint32_t CreateOptions,
     2327                            uint8_t SecurityFlags,
     2328                            struct security_descriptor *secdesc,
     2329                            struct ea_struct *eas,
     2330                            int num_eas,
     2331                            uint16_t *pfid,
     2332                            struct smb_create_returns *cr)
     2333{
     2334        TALLOC_CTX *frame = talloc_stackframe();
     2335        struct tevent_context *ev;
     2336        struct tevent_req *req;
     2337        NTSTATUS status = NT_STATUS_NO_MEMORY;
     2338
     2339        if (smbXcli_conn_has_async_calls(cli->conn)) {
     2340                /*
     2341                 * Can't use sync call while an async call is in flight
     2342                 */
     2343                status = NT_STATUS_INVALID_PARAMETER;
     2344                goto fail;
     2345        }
     2346        ev = samba_tevent_context_init(frame);
     2347        if (ev == NULL) {
     2348                goto fail;
     2349        }
     2350        req = cli_nttrans_create_send(frame, ev, cli, fname, CreatFlags,
     2351                                      DesiredAccess, FileAttributes,
     2352                                      ShareAccess, CreateDisposition,
     2353                                      CreateOptions, SecurityFlags,
     2354                                      secdesc, eas, num_eas);
     2355        if (req == NULL) {
     2356                goto fail;
     2357        }
     2358        if (!tevent_req_poll_ntstatus(req, ev, &status)) {
     2359                goto fail;
     2360        }
     2361        status = cli_nttrans_create_recv(req, pfid, cr);
    19972362 fail:
    19982363        TALLOC_FREE(frame);
     
    20052370****************************************************************************/
    20062371
    2007 struct cli_open_state {
    2008         struct tevent_context *ev;
    2009         struct cli_state *cli;
     2372struct cli_openx_state {
    20102373        const char *fname;
    20112374        uint16_t vwv[15];
    20122375        uint16_t fnum;
    2013         unsigned openfn;
    2014         unsigned dos_deny;
    2015         uint8_t additional_flags;
    20162376        struct iovec bytes;
    20172377};
    20182378
    2019 static void cli_open_done(struct tevent_req *subreq);
    2020 static void cli_open_ntcreate_done(struct tevent_req *subreq);
    2021 
    2022 struct tevent_req *cli_open_create(TALLOC_CTX *mem_ctx,
    2023                                    struct event_context *ev,
     2379static void cli_openx_done(struct tevent_req *subreq);
     2380
     2381struct tevent_req *cli_openx_create(TALLOC_CTX *mem_ctx,
     2382                                   struct tevent_context *ev,
    20242383                                   struct cli_state *cli, const char *fname,
    20252384                                   int flags, int share_mode,
     
    20272386{
    20282387        struct tevent_req *req, *subreq;
    2029         struct cli_open_state *state;
     2388        struct cli_openx_state *state;
     2389        unsigned openfn;
     2390        unsigned accessmode;
     2391        uint8_t additional_flags;
    20302392        uint8_t *bytes;
    20312393
    2032         req = tevent_req_create(mem_ctx, &state, struct cli_open_state);
     2394        req = tevent_req_create(mem_ctx, &state, struct cli_openx_state);
    20332395        if (req == NULL) {
    20342396                return NULL;
    20352397        }
    2036         state->ev = ev;
    2037         state->cli = cli;
    2038         state->fname = fname;
    2039 
     2398
     2399        openfn = 0;
    20402400        if (flags & O_CREAT) {
    2041                 state->openfn |= (1<<4);
     2401                openfn |= (1<<4);
    20422402        }
    20432403        if (!(flags & O_EXCL)) {
    20442404                if (flags & O_TRUNC)
    2045                         state->openfn |= (1<<1);
     2405                        openfn |= (1<<1);
    20462406                else
    2047                         state->openfn |= (1<<0);
    2048         }
    2049 
    2050         state->dos_deny = (share_mode<<4);
     2407                        openfn |= (1<<0);
     2408        }
     2409
     2410        accessmode = (share_mode<<4);
    20512411
    20522412        if ((flags & O_ACCMODE) == O_RDWR) {
    2053                 state->dos_deny |= 2;
     2413                accessmode |= 2;
    20542414        } else if ((flags & O_ACCMODE) == O_WRONLY) {
    2055                 state->dos_deny |= 1;
     2415                accessmode |= 1;
    20562416        }
    20572417
    20582418#if defined(O_SYNC)
    20592419        if ((flags & O_SYNC) == O_SYNC) {
    2060                 state->dos_deny |= (1<<14);
     2420                accessmode |= (1<<14);
    20612421        }
    20622422#endif /* O_SYNC */
    20632423
    20642424        if (share_mode == DENY_FCB) {
    2065                 state->dos_deny = 0xFF;
     2425                accessmode = 0xFF;
    20662426        }
    20672427
     
    20702430        SSVAL(state->vwv + 1, 0, 0);
    20712431        SSVAL(state->vwv + 2, 0, 0);  /* no additional info */
    2072         SSVAL(state->vwv + 3, 0, state->dos_deny);
     2432        SSVAL(state->vwv + 3, 0, accessmode);
    20732433        SSVAL(state->vwv + 4, 0, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
    20742434        SSVAL(state->vwv + 5, 0, 0);
    20752435        SIVAL(state->vwv + 6, 0, 0);
    2076         SSVAL(state->vwv + 8, 0, state->openfn);
     2436        SSVAL(state->vwv + 8, 0, openfn);
    20772437        SIVAL(state->vwv + 9, 0, 0);
    20782438        SIVAL(state->vwv + 11, 0, 0);
    20792439        SIVAL(state->vwv + 13, 0, 0);
    20802440
     2441        additional_flags = 0;
     2442
    20812443        if (cli->use_oplocks) {
    20822444                /* if using oplocks then ask for a batch oplock via
    20832445                   core and extended methods */
    2084                 state->additional_flags =
     2446                additional_flags =
    20852447                        FLAG_REQUEST_OPLOCK|FLAG_REQUEST_BATCH_OPLOCK;
    20862448                SSVAL(state->vwv+2, 0, SVAL(state->vwv+2, 0) | 6);
     
    20882450
    20892451        bytes = talloc_array(state, uint8_t, 0);
    2090         bytes = smb_bytes_push_str(bytes, cli_ucs2(cli), fname,
     2452        bytes = smb_bytes_push_str(bytes, smbXcli_conn_use_unicode(cli->conn), fname,
    20912453                                   strlen(fname)+1, NULL);
    20922454
     
    20982460        state->bytes.iov_len = talloc_get_size(bytes);
    20992461
    2100         subreq = cli_smb_req_create(state, ev, cli, SMBopenX,
    2101                                     state->additional_flags,
     2462        subreq = cli_smb_req_create(state, ev, cli, SMBopenX, additional_flags,
    21022463                                    15, state->vwv, 1, &state->bytes);
    21032464        if (subreq == NULL) {
     
    21052466                return NULL;
    21062467        }
    2107         tevent_req_set_callback(subreq, cli_open_done, req);
     2468        tevent_req_set_callback(subreq, cli_openx_done, req);
    21082469        *psmbreq = subreq;
    21092470        return req;
    21102471}
    21112472
    2112 struct tevent_req *cli_open_send(TALLOC_CTX *mem_ctx, struct event_context *ev,
     2473struct tevent_req *cli_openx_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev,
    21132474                                 struct cli_state *cli, const char *fname,
    21142475                                 int flags, int share_mode)
     
    21172478        NTSTATUS status;
    21182479
    2119         req = cli_open_create(mem_ctx, ev, cli, fname, flags, share_mode,
     2480        req = cli_openx_create(mem_ctx, ev, cli, fname, flags, share_mode,
    21202481                              &subreq);
    21212482        if (req == NULL) {
     
    21232484        }
    21242485
    2125         status = cli_smb_req_send(subreq);
     2486        status = smb1cli_req_chain_submit(&subreq, 1);
    21262487        if (tevent_req_nterror(req, status)) {
    21272488                return tevent_req_post(req, ev);
     
    21302491}
    21312492
    2132 static void cli_open_done(struct tevent_req *subreq)
     2493static void cli_openx_done(struct tevent_req *subreq)
    21332494{
    21342495        struct tevent_req *req = tevent_req_callback_data(
    21352496                subreq, struct tevent_req);
    2136         struct cli_open_state *state = tevent_req_data(
    2137                 req, struct cli_open_state);
     2497        struct cli_openx_state *state = tevent_req_data(
     2498                req, struct cli_openx_state);
    21382499        uint8_t wct;
    21392500        uint16_t *vwv;
    2140         uint8_t *inbuf;
    21412501        NTSTATUS status;
    2142         uint32_t access_mask, share_mode, create_disposition, create_options;
    2143 
    2144         status = cli_smb_recv(subreq, state, &inbuf, 3, &wct, &vwv, NULL,
     2502
     2503        status = cli_smb_recv(subreq, state, NULL, 3, &wct, &vwv, NULL,
    21452504                              NULL);
    2146         TALLOC_FREE(subreq);
    2147 
    2148         if (NT_STATUS_IS_OK(status)) {
    2149                 state->fnum = SVAL(vwv+2, 0);
    2150                 tevent_req_done(req);
    2151                 return;
    2152         }
    2153 
    2154         if (!NT_STATUS_EQUAL(status, NT_STATUS_NOT_SUPPORTED)) {
    2155                 tevent_req_nterror(req, status);
    2156                 return;
    2157         }
    2158 
    2159         /*
    2160          * For the new shiny OS/X Lion SMB server, try a ntcreate
    2161          * fallback.
    2162          */
    2163 
    2164         if (!map_open_params_to_ntcreate(state->fname, state->dos_deny,
    2165                                          state->openfn, &access_mask,
    2166                                          &share_mode, &create_disposition,
    2167                                          &create_options, NULL)) {
    2168                 tevent_req_nterror(req, NT_STATUS_NOT_SUPPORTED);
    2169                 return;
    2170         }
    2171 
    2172         subreq = cli_ntcreate_send(state, state->ev, state->cli,
    2173                                    state->fname, 0, access_mask,
    2174                                    0, share_mode, create_disposition,
    2175                                    create_options, 0);
    2176         if (tevent_req_nomem(subreq, req)) {
    2177                 return;
    2178         }
    2179         tevent_req_set_callback(subreq, cli_open_ntcreate_done, req);
    2180 }
    2181 
    2182 static void cli_open_ntcreate_done(struct tevent_req *subreq)
    2183 {
    2184         struct tevent_req *req = tevent_req_callback_data(
    2185                 subreq, struct tevent_req);
    2186         struct cli_open_state *state = tevent_req_data(
    2187                 req, struct cli_open_state);
    2188         NTSTATUS status;
    2189 
    2190         status = cli_ntcreate_recv(subreq, &state->fnum);
    21912505        TALLOC_FREE(subreq);
    21922506        if (tevent_req_nterror(req, status)) {
    21932507                return;
    21942508        }
     2509        state->fnum = SVAL(vwv+2, 0);
    21952510        tevent_req_done(req);
    21962511}
    21972512
    2198 NTSTATUS cli_open_recv(struct tevent_req *req, uint16_t *pfnum)
    2199 {
    2200         struct cli_open_state *state = tevent_req_data(
    2201                 req, struct cli_open_state);
     2513NTSTATUS cli_openx_recv(struct tevent_req *req, uint16_t *pfnum)
     2514{
     2515        struct cli_openx_state *state = tevent_req_data(
     2516                req, struct cli_openx_state);
    22022517        NTSTATUS status;
    22032518
     
    22092524}
    22102525
    2211 NTSTATUS cli_open(struct cli_state *cli, const char *fname, int flags,
     2526NTSTATUS cli_openx(struct cli_state *cli, const char *fname, int flags,
    22122527             int share_mode, uint16_t *pfnum)
    22132528{
    22142529        TALLOC_CTX *frame = talloc_stackframe();
    2215         struct event_context *ev;
     2530        struct tevent_context *ev;
    22162531        struct tevent_req *req;
    2217         NTSTATUS status = NT_STATUS_OK;
    2218 
    2219         if (cli_has_async_calls(cli)) {
     2532        NTSTATUS status = NT_STATUS_NO_MEMORY;
     2533
     2534        if (smbXcli_conn_has_async_calls(cli->conn)) {
    22202535                /*
    22212536                 * Can't use sync call while an async call is in flight
     
    22252540        }
    22262541
    2227         ev = event_context_init(frame);
     2542        ev = samba_tevent_context_init(frame);
    22282543        if (ev == NULL) {
    2229                 status = NT_STATUS_NO_MEMORY;
    2230                 goto fail;
    2231         }
    2232 
    2233         req = cli_open_send(frame, ev, cli, fname, flags, share_mode);
    2234         if (req == NULL) {
    2235                 status = NT_STATUS_NO_MEMORY;
    2236                 goto fail;
    2237         }
    2238 
    2239         if (!tevent_req_poll(req, ev)) {
    2240                 status = map_nt_error_from_unix(errno);
    2241                 goto fail;
    2242         }
    2243 
    2244         status = cli_open_recv(req, pfnum);
     2544                goto fail;
     2545        }
     2546
     2547        req = cli_openx_send(frame, ev, cli, fname, flags, share_mode);
     2548        if (req == NULL) {
     2549                goto fail;
     2550        }
     2551
     2552        if (!tevent_req_poll_ntstatus(req, ev, &status)) {
     2553                goto fail;
     2554        }
     2555
     2556        status = cli_openx_recv(req, pfnum);
    22452557 fail:
    22462558        TALLOC_FREE(frame);
    22472559        return status;
    22482560}
     2561/****************************************************************************
     2562 Synchronous wrapper function that does an NtCreateX open by preference
     2563 and falls back to openX if this fails.
     2564****************************************************************************/
     2565
     2566NTSTATUS cli_open(struct cli_state *cli, const char *fname, int flags,
     2567                        int share_mode_in, uint16_t *pfnum)
     2568{
     2569        NTSTATUS status;
     2570        unsigned int openfn = 0;
     2571        unsigned int dos_deny = 0;
     2572        uint32_t access_mask, share_mode, create_disposition, create_options;
     2573        struct smb_create_returns cr;
     2574
     2575        /* Do the initial mapping into OpenX parameters. */
     2576        if (flags & O_CREAT) {
     2577                openfn |= (1<<4);
     2578        }
     2579        if (!(flags & O_EXCL)) {
     2580                if (flags & O_TRUNC)
     2581                        openfn |= (1<<1);
     2582                else
     2583                        openfn |= (1<<0);
     2584        }
     2585
     2586        dos_deny = (share_mode_in<<4);
     2587
     2588        if ((flags & O_ACCMODE) == O_RDWR) {
     2589                dos_deny |= 2;
     2590        } else if ((flags & O_ACCMODE) == O_WRONLY) {
     2591                dos_deny |= 1;
     2592        }
     2593
     2594#if defined(O_SYNC)
     2595        if ((flags & O_SYNC) == O_SYNC) {
     2596                dos_deny |= (1<<14);
     2597        }
     2598#endif /* O_SYNC */
     2599
     2600        if (share_mode_in == DENY_FCB) {
     2601                dos_deny = 0xFF;
     2602        }
     2603
     2604#if 0
     2605        /* Hmmm. This is what I think the above code
     2606           should look like if it's using the constants
     2607           we #define. JRA. */
     2608
     2609        if (flags & O_CREAT) {
     2610                openfn |= OPENX_FILE_CREATE_IF_NOT_EXIST;
     2611        }
     2612        if (!(flags & O_EXCL)) {
     2613                if (flags & O_TRUNC)
     2614                        openfn |= OPENX_FILE_EXISTS_TRUNCATE;
     2615                else
     2616                        openfn |= OPENX_FILE_EXISTS_OPEN;
     2617        }
     2618
     2619        dos_deny = SET_DENY_MODE(share_mode_in);
     2620
     2621        if ((flags & O_ACCMODE) == O_RDWR) {
     2622                dos_deny |= DOS_OPEN_RDWR;
     2623        } else if ((flags & O_ACCMODE) == O_WRONLY) {
     2624                dos_deny |= DOS_OPEN_WRONLY;
     2625        }
     2626
     2627#if defined(O_SYNC)
     2628        if ((flags & O_SYNC) == O_SYNC) {
     2629                dos_deny |= FILE_SYNC_OPENMODE;
     2630        }
     2631#endif /* O_SYNC */
     2632
     2633        if (share_mode_in == DENY_FCB) {
     2634                dos_deny = 0xFF;
     2635        }
     2636#endif
     2637
     2638        if (!map_open_params_to_ntcreate(fname, dos_deny,
     2639                                        openfn, &access_mask,
     2640                                        &share_mode, &create_disposition,
     2641                                        &create_options, NULL)) {
     2642                goto try_openx;
     2643        }
     2644
     2645        status = cli_ntcreate(cli,
     2646                                fname,
     2647                                0,
     2648                                access_mask,
     2649                                0,
     2650                                share_mode,
     2651                                create_disposition,
     2652                                create_options,
     2653                                0,
     2654                                pfnum,
     2655                                &cr);
     2656
     2657        /* Try and cope will all varients of "we don't do this call"
     2658           and fall back to openX. */
     2659
     2660        if (NT_STATUS_EQUAL(status,NT_STATUS_NOT_IMPLEMENTED) ||
     2661                        NT_STATUS_EQUAL(status,NT_STATUS_INVALID_INFO_CLASS) ||
     2662                        NT_STATUS_EQUAL(status,NT_STATUS_PROCEDURE_NOT_FOUND) ||
     2663                        NT_STATUS_EQUAL(status,NT_STATUS_INVALID_LEVEL) ||
     2664                        NT_STATUS_EQUAL(status,NT_STATUS_INVALID_PARAMETER) ||
     2665                        NT_STATUS_EQUAL(status,NT_STATUS_INVALID_DEVICE_REQUEST) ||
     2666                        NT_STATUS_EQUAL(status,NT_STATUS_INVALID_DEVICE_STATE) ||
     2667                        NT_STATUS_EQUAL(status,NT_STATUS_CTL_FILE_NOT_SUPPORTED) ||
     2668                        NT_STATUS_EQUAL(status,NT_STATUS_UNSUCCESSFUL)) {
     2669                goto try_openx;
     2670        }
     2671
     2672        if (NT_STATUS_IS_OK(status) &&
     2673            (create_options & FILE_NON_DIRECTORY_FILE) &&
     2674            (cr.file_attributes & FILE_ATTRIBUTE_DIRECTORY))
     2675        {
     2676                /*
     2677                 * Some (broken) servers return a valid handle
     2678                 * for directories even if FILE_NON_DIRECTORY_FILE
     2679                 * is set. Just close the handle and set the
     2680                 * error explicitly to NT_STATUS_FILE_IS_A_DIRECTORY.
     2681                 */
     2682                status = cli_close(cli, *pfnum);
     2683                if (!NT_STATUS_IS_OK(status)) {
     2684                        return status;
     2685                }
     2686                status = NT_STATUS_FILE_IS_A_DIRECTORY;
     2687                /* Set this so libsmbclient can retrieve it. */
     2688                cli->raw_status = status;
     2689        }
     2690
     2691        return status;
     2692
     2693  try_openx:
     2694
     2695        return cli_openx(cli, fname, flags, share_mode_in, pfnum);
     2696}
    22492697
    22502698/****************************************************************************
     
    22592707
    22602708struct tevent_req *cli_close_create(TALLOC_CTX *mem_ctx,
    2261                                 struct event_context *ev,
     2709                                struct tevent_context *ev,
    22622710                                struct cli_state *cli,
    22632711                                uint16_t fnum,
     
    22872735
    22882736struct tevent_req *cli_close_send(TALLOC_CTX *mem_ctx,
    2289                                 struct event_context *ev,
     2737                                struct tevent_context *ev,
    22902738                                struct cli_state *cli,
    22912739                                uint16_t fnum)
     
    22992747        }
    23002748
    2301         status = cli_smb_req_send(subreq);
     2749        status = smb1cli_req_chain_submit(&subreq, 1);
    23022750        if (tevent_req_nterror(req, status)) {
    23032751                return tevent_req_post(req, ev);
     
    23272775NTSTATUS cli_close(struct cli_state *cli, uint16_t fnum)
    23282776{
    2329         TALLOC_CTX *frame = talloc_stackframe();
    2330         struct event_context *ev;
     2777        TALLOC_CTX *frame = NULL;
     2778        struct tevent_context *ev;
    23312779        struct tevent_req *req;
    23322780        NTSTATUS status = NT_STATUS_OK;
    23332781
    2334         if (cli_has_async_calls(cli)) {
     2782        if (smbXcli_conn_protocol(cli->conn) >= PROTOCOL_SMB2_02) {
     2783                return cli_smb2_close_fnum(cli, fnum);
     2784        }
     2785
     2786        frame = talloc_stackframe();
     2787
     2788        if (smbXcli_conn_has_async_calls(cli->conn)) {
    23352789                /*
    23362790                 * Can't use sync call while an async call is in flight
     
    23402794        }
    23412795
    2342         ev = event_context_init(frame);
     2796        ev = samba_tevent_context_init(frame);
    23432797        if (ev == NULL) {
    23442798                status = NT_STATUS_NO_MEMORY;
     
    23522806        }
    23532807
    2354         if (!tevent_req_poll(req, ev)) {
    2355                 status = map_nt_error_from_unix(errno);
     2808        if (!tevent_req_poll_ntstatus(req, ev, &status)) {
    23562809                goto fail;
    23572810        }
     
    23812834
    23822835struct tevent_req *cli_ftruncate_send(TALLOC_CTX *mem_ctx,
    2383                                         struct event_context *ev,
     2836                                        struct tevent_context *ev,
    23842837                                        struct cli_state *cli,
    23852838                                        uint16_t fnum,
     
    24382891{
    24392892        TALLOC_CTX *frame = talloc_stackframe();
    2440         struct event_context *ev = NULL;
     2893        struct tevent_context *ev = NULL;
    24412894        struct tevent_req *req = NULL;
    24422895        NTSTATUS status = NT_STATUS_OK;
    24432896
    2444         if (cli_has_async_calls(cli)) {
     2897        if (smbXcli_conn_has_async_calls(cli->conn)) {
    24452898                /*
    24462899                 * Can't use sync call while an async call is in flight
     
    24502903        }
    24512904
    2452         ev = event_context_init(frame);
     2905        ev = samba_tevent_context_init(frame);
    24532906        if (ev == NULL) {
    24542907                status = NT_STATUS_NO_MEMORY;
     
    24662919        }
    24672920
    2468         if (!tevent_req_poll(req, ev)) {
    2469                 status = map_nt_error_from_unix(errno);
     2921        if (!tevent_req_poll_ntstatus(req, ev, &status)) {
    24702922                goto fail;
    24712923        }
     
    24902942        uint8_t bytes[10];
    24912943        NTSTATUS status;
    2492         int saved_timeout;
     2944        unsigned int set_timeout = 0;
     2945        unsigned int saved_timeout = 0;
    24932946
    24942947        SCVAL(vwv + 0, 0, 0xff);
     
    25022955        SSVAL(vwv + 7, 0, 1);
    25032956
    2504         SSVAL(bytes, 0, cli->pid);
     2957        SSVAL(bytes, 0, cli_getpid(cli));
    25052958        SIVAL(bytes, 2, offset);
    25062959        SIVAL(bytes, 6, len);
    25072960
    2508         saved_timeout = cli->timeout;
    2509 
    25102961        if (timeout != 0) {
    2511                 cli->timeout = (timeout == -1)
    2512                         ? 0x7FFFFFFF : (timeout + 2*1000);
     2962                if (timeout == -1) {
     2963                        set_timeout = 0x7FFFFFFF;
     2964                } else {
     2965                        set_timeout = timeout + 2*1000;
     2966                }
     2967                saved_timeout = cli_set_timeout(cli, set_timeout);
    25132968        }
    25142969
     
    25162971                         10, bytes, NULL, 0, NULL, NULL, NULL, NULL);
    25172972
    2518         cli->timeout = saved_timeout;
     2973        if (saved_timeout != 0) {
     2974                cli_set_timeout(cli, saved_timeout);
     2975        }
    25192976
    25202977        return status;
     
    25262983****************************************************************************/
    25272984
    2528 bool cli_lock(struct cli_state *cli, uint16_t fnum,
     2985NTSTATUS cli_lock32(struct cli_state *cli, uint16_t fnum,
    25292986                  uint32_t offset, uint32_t len, int timeout,
    25302987                  enum brl_type lock_type)
     
    25342991        status = cli_locktype(cli, fnum, offset, len, timeout,
    25352992                              (lock_type == READ_LOCK? 1 : 0));
    2536         return NT_STATUS_IS_OK(status);
     2993        return status;
    25372994}
    25382995
     
    25493006
    25503007struct tevent_req *cli_unlock_send(TALLOC_CTX *mem_ctx,
    2551                                 struct event_context *ev,
     3008                                struct tevent_context *ev,
    25523009                                struct cli_state *cli,
    25533010                                uint16_t fnum,
     
    25723029        SSVAL(state->vwv+7, 0, 0);
    25733030
    2574         SSVAL(state->data, 0, cli->pid);
     3031        SSVAL(state->data, 0, cli_getpid(cli));
    25753032        SIVAL(state->data, 2, offset);
    25763033        SIVAL(state->data, 6, len);
     
    26103067{
    26113068        TALLOC_CTX *frame = talloc_stackframe();
    2612         struct event_context *ev;
     3069        struct tevent_context *ev;
    26133070        struct tevent_req *req;
    26143071        NTSTATUS status = NT_STATUS_OK;
    26153072
    2616         if (cli_has_async_calls(cli)) {
     3073        if (smbXcli_conn_has_async_calls(cli->conn)) {
    26173074                /*
    26183075                 * Can't use sync call while an async call is in flight
     
    26223079        }
    26233080
    2624         ev = event_context_init(frame);
     3081        ev = samba_tevent_context_init(frame);
    26253082        if (ev == NULL) {
    26263083                status = NT_STATUS_NO_MEMORY;
     
    26353092        }
    26363093
    2637         if (!tevent_req_poll(req, ev)) {
    2638                 status = map_nt_error_from_unix(errno);
     3094        if (!tevent_req_poll_ntstatus(req, ev, &status)) {
    26393095                goto fail;
    26403096        }
     
    26513107****************************************************************************/
    26523108
    2653 bool cli_lock64(struct cli_state *cli, uint16_t fnum,
    2654                 uint64_t offset, uint64_t len, int timeout,
    2655                 enum brl_type lock_type)
     3109NTSTATUS cli_lock64(struct cli_state *cli, uint16_t fnum,
     3110                    uint64_t offset, uint64_t len, int timeout,
     3111                    enum brl_type lock_type)
    26563112{
    26573113        uint16_t vwv[8];
    26583114        uint8_t bytes[20];
    2659         int saved_timeout = cli->timeout;
     3115        unsigned int set_timeout = 0;
     3116        unsigned int saved_timeout = 0;
    26603117        int ltype;
    26613118        NTSTATUS status;
    26623119
    2663         if (! (cli->capabilities & CAP_LARGE_FILES)) {
    2664                 return cli_lock(cli, fnum, offset, len, timeout, lock_type);
     3120        if (! (smb1cli_conn_capabilities(cli->conn) & CAP_LARGE_FILES)) {
     3121                return cli_lock32(cli, fnum, offset, len, timeout, lock_type);
    26653122        }
    26663123
     
    26783135        SSVAL(vwv + 7, 0, 1);
    26793136
    2680         SIVAL(bytes, 0, cli->pid);
     3137        SIVAL(bytes, 0, cli_getpid(cli));
    26813138        SOFF_T_R(bytes, 4, offset);
    26823139        SOFF_T_R(bytes, 12, len);
    26833140
    2684         saved_timeout = cli->timeout;
    2685 
    26863141        if (timeout != 0) {
    2687                 cli->timeout = (timeout == -1)
    2688                         ? 0x7FFFFFFF : (timeout + 2*1000);
     3142                if (timeout == -1) {
     3143                        set_timeout = 0x7FFFFFFF;
     3144                } else {
     3145                        set_timeout = timeout + 2*1000;
     3146                }
     3147                saved_timeout = cli_set_timeout(cli, set_timeout);
    26893148        }
    26903149
     
    26923151                         20, bytes, NULL, 0, NULL, NULL, NULL, NULL);
    26933152
    2694         cli->timeout = saved_timeout;
    2695 
    2696         return NT_STATUS_IS_OK(status);
     3153        if (saved_timeout != 0) {
     3154                cli_set_timeout(cli, saved_timeout);
     3155        }
     3156
     3157        return status;
    26973158}
    26983159
     
    27093170
    27103171struct tevent_req *cli_unlock64_send(TALLOC_CTX *mem_ctx,
    2711                                 struct event_context *ev,
     3172                                struct tevent_context *ev,
    27123173                                struct cli_state *cli,
    27133174                                uint16_t fnum,
     
    27323193        SSVAL(state->vwv+7, 0, 0);
    27333194
    2734         SIVAL(state->data, 0, cli->pid);
     3195        SIVAL(state->data, 0, cli_getpid(cli));
    27353196        SOFF_T_R(state->data, 4, offset);
    27363197        SOFF_T_R(state->data, 12, len);
     
    27703231{
    27713232        TALLOC_CTX *frame = talloc_stackframe();
    2772         struct event_context *ev;
     3233        struct tevent_context *ev;
    27733234        struct tevent_req *req;
    27743235        NTSTATUS status = NT_STATUS_OK;
    27753236
    2776         if (! (cli->capabilities & CAP_LARGE_FILES)) {
     3237        if (! (smb1cli_conn_capabilities(cli->conn) & CAP_LARGE_FILES)) {
    27773238                return cli_unlock(cli, fnum, offset, len);
    27783239        }
    27793240
    2780         if (cli_has_async_calls(cli)) {
     3241        if (smbXcli_conn_has_async_calls(cli->conn)) {
    27813242                /*
    27823243                 * Can't use sync call while an async call is in flight
     
    27863247        }
    27873248
    2788         ev = event_context_init(frame);
     3249        ev = samba_tevent_context_init(frame);
    27893250        if (ev == NULL) {
    27903251                status = NT_STATUS_NO_MEMORY;
     
    27993260        }
    28003261
    2801         if (!tevent_req_poll(req, ev)) {
    2802                 status = map_nt_error_from_unix(errno);
     3262        if (!tevent_req_poll_ntstatus(req, ev, &status)) {
    28033263                goto fail;
    28043264        }
     
    28293289
    28303290static struct tevent_req *cli_posix_lock_internal_send(TALLOC_CTX *mem_ctx,
    2831                                         struct event_context *ev,
     3291                                        struct tevent_context *ev,
    28323292                                        struct cli_state *cli,
    28333293                                        uint16_t fnum,
     
    28783338        }
    28793339
    2880         SIVAL(&state->data, POSIX_LOCK_PID_OFFSET, cli->pid);
     3340        SIVAL(&state->data, POSIX_LOCK_PID_OFFSET, cli_getpid(cli));
    28813341        SOFF_T(&state->data, POSIX_LOCK_START_OFFSET, offset);
    28823342        SOFF_T(&state->data, POSIX_LOCK_LEN_OFFSET, len);
     
    29123372
    29133373struct tevent_req *cli_posix_lock_send(TALLOC_CTX *mem_ctx,
    2914                                         struct event_context *ev,
     3374                                        struct tevent_context *ev,
    29153375                                        struct cli_state *cli,
    29163376                                        uint16_t fnum,
     
    29343394{
    29353395        TALLOC_CTX *frame = talloc_stackframe();
    2936         struct event_context *ev = NULL;
     3396        struct tevent_context *ev = NULL;
    29373397        struct tevent_req *req = NULL;
    29383398        NTSTATUS status = NT_STATUS_OK;
    29393399
    2940         if (cli_has_async_calls(cli)) {
     3400        if (smbXcli_conn_has_async_calls(cli->conn)) {
    29413401                /*
    29423402                 * Can't use sync call while an async call is in flight
     
    29513411        }
    29523412
    2953         ev = event_context_init(frame);
     3413        ev = samba_tevent_context_init(frame);
    29543414        if (ev == NULL) {
    29553415                status = NT_STATUS_NO_MEMORY;
     
    29703430        }
    29713431
    2972         if (!tevent_req_poll(req, ev)) {
    2973                 status = map_nt_error_from_unix(errno);
     3432        if (!tevent_req_poll_ntstatus(req, ev, &status)) {
    29743433                goto fail;
    29753434        }
     
    29873446
    29883447struct tevent_req *cli_posix_unlock_send(TALLOC_CTX *mem_ctx,
    2989                                         struct event_context *ev,
     3448                                        struct tevent_context *ev,
    29903449                                        struct cli_state *cli,
    29913450                                        uint16_t fnum,
     
    30053464{
    30063465        TALLOC_CTX *frame = talloc_stackframe();
    3007         struct event_context *ev = NULL;
     3466        struct tevent_context *ev = NULL;
    30083467        struct tevent_req *req = NULL;
    30093468        NTSTATUS status = NT_STATUS_OK;
    30103469
    3011         if (cli_has_async_calls(cli)) {
     3470        if (smbXcli_conn_has_async_calls(cli->conn)) {
    30123471                /*
    30133472                 * Can't use sync call while an async call is in flight
     
    30173476        }
    30183477
    3019         ev = event_context_init(frame);
     3478        ev = samba_tevent_context_init(frame);
    30203479        if (ev == NULL) {
    30213480                status = NT_STATUS_NO_MEMORY;
     
    30343493        }
    30353494
    3036         if (!tevent_req_poll(req, ev)) {
    3037                 status = map_nt_error_from_unix(errno);
     3495        if (!tevent_req_poll_ntstatus(req, ev, &status)) {
    30383496                goto fail;
    30393497        }
     
    30563514        int zone_offset;
    30573515        uint16_t attr;
    3058         SMB_OFF_T size;
     3516        off_t size;
    30593517        time_t change_time;
    30603518        time_t access_time;
     
    30633521
    30643522struct tevent_req *cli_getattrE_send(TALLOC_CTX *mem_ctx,
    3065                                 struct event_context *ev,
     3523                                struct tevent_context *ev,
    30663524                                struct cli_state *cli,
    30673525                                uint16_t fnum)
     
    30763534        }
    30773535
    3078         state->zone_offset = cli->serverzone;
     3536        state->zone_offset = smb1cli_conn_server_time_zone(cli->conn);
    30793537        SSVAL(state->vwv+0,0,fnum);
    30803538
     
    30963554        uint8_t wct;
    30973555        uint16_t *vwv = NULL;
    3098         uint8_t *inbuf;
    30993556        NTSTATUS status;
    31003557
    3101         status = cli_smb_recv(subreq, state, &inbuf, 11, &wct, &vwv,
     3558        status = cli_smb_recv(subreq, state, NULL, 11, &wct, &vwv,
    31023559                              NULL, NULL);
    31033560        TALLOC_FREE(subreq);
     
    31063563        }
    31073564
    3108         state->size = (SMB_OFF_T)IVAL(vwv+6,0);
     3565        state->size = (off_t)IVAL(vwv+6,0);
    31093566        state->attr = SVAL(vwv+10,0);
    31103567        state->change_time = make_unix_date2(vwv+0, state->zone_offset);
     
    31173574NTSTATUS cli_getattrE_recv(struct tevent_req *req,
    31183575                        uint16_t *attr,
    3119                         SMB_OFF_T *size,
     3576                        off_t *size,
    31203577                        time_t *change_time,
    31213578                        time_t *access_time,
     
    31503607                        uint16_t fnum,
    31513608                        uint16_t *attr,
    3152                         SMB_OFF_T *size,
     3609                        off_t *size,
    31533610                        time_t *change_time,
    31543611                        time_t *access_time,
    31553612                        time_t *write_time)
    31563613{
    3157         TALLOC_CTX *frame = talloc_stackframe();
    3158         struct event_context *ev = NULL;
     3614        TALLOC_CTX *frame = NULL;
     3615        struct tevent_context *ev = NULL;
    31593616        struct tevent_req *req = NULL;
    31603617        NTSTATUS status = NT_STATUS_OK;
    31613618
    3162         if (cli_has_async_calls(cli)) {
     3619        if (smbXcli_conn_protocol(cli->conn) >= PROTOCOL_SMB2_02) {
     3620                return cli_smb2_getattrE(cli,
     3621                                        fnum,
     3622                                        attr,
     3623                                        size,
     3624                                        change_time,
     3625                                        access_time,
     3626                                        write_time);
     3627        }
     3628
     3629        frame = talloc_stackframe();
     3630
     3631        if (smbXcli_conn_has_async_calls(cli->conn)) {
    31633632                /*
    31643633                 * Can't use sync call while an async call is in flight
     
    31683637        }
    31693638
    3170         ev = event_context_init(frame);
     3639        ev = samba_tevent_context_init(frame);
    31713640        if (ev == NULL) {
    31723641                status = NT_STATUS_NO_MEMORY;
     
    31803649        }
    31813650
    3182         if (!tevent_req_poll(req, ev)) {
    3183                 status = map_nt_error_from_unix(errno);
     3651        if (!tevent_req_poll_ntstatus(req, ev, &status)) {
    31843652                goto fail;
    31853653        }
     
    32063674        int zone_offset;
    32073675        uint16_t attr;
    3208         SMB_OFF_T size;
     3676        off_t size;
    32093677        time_t write_time;
    32103678};
    32113679
    32123680struct tevent_req *cli_getatr_send(TALLOC_CTX *mem_ctx,
    3213                                 struct event_context *ev,
     3681                                struct tevent_context *ev,
    32143682                                struct cli_state *cli,
    32153683                                const char *fname)
     
    32253693        }
    32263694
    3227         state->zone_offset = cli->serverzone;
     3695        state->zone_offset = smb1cli_conn_server_time_zone(cli->conn);
    32283696
    32293697        bytes = talloc_array(state, uint8_t, 1);
     
    32323700        }
    32333701        bytes[0] = 4;
    3234         bytes = smb_bytes_push_str(bytes, cli_ucs2(cli), fname,
     3702        bytes = smb_bytes_push_str(bytes, smbXcli_conn_use_unicode(cli->conn), fname,
    32353703                                   strlen(fname)+1, NULL);
    32363704
     
    32563724        uint8_t wct;
    32573725        uint16_t *vwv = NULL;
    3258         uint8_t *inbuf;
    32593726        NTSTATUS status;
    32603727
    3261         status = cli_smb_recv(subreq, state, &inbuf, 4, &wct, &vwv, NULL,
     3728        status = cli_smb_recv(subreq, state, NULL, 4, &wct, &vwv, NULL,
    32623729                              NULL);
    32633730        TALLOC_FREE(subreq);
     
    32673734
    32683735        state->attr = SVAL(vwv+0,0);
    3269         state->size = (SMB_OFF_T)IVAL(vwv+3,0);
     3736        state->size = (off_t)IVAL(vwv+3,0);
    32703737        state->write_time = make_unix_date3(vwv+1, state->zone_offset);
    32713738
     
    32753742NTSTATUS cli_getatr_recv(struct tevent_req *req,
    32763743                        uint16_t *attr,
    3277                         SMB_OFF_T *size,
     3744                        off_t *size,
    32783745                        time_t *write_time)
    32793746{
     
    33003767                        const char *fname,
    33013768                        uint16_t *attr,
    3302                         SMB_OFF_T *size,
     3769                        off_t *size,
    33033770                        time_t *write_time)
    33043771{
    3305         TALLOC_CTX *frame = talloc_stackframe();
    3306         struct event_context *ev = NULL;
     3772        TALLOC_CTX *frame = NULL;
     3773        struct tevent_context *ev = NULL;
    33073774        struct tevent_req *req = NULL;
    33083775        NTSTATUS status = NT_STATUS_OK;
    33093776
    3310         if (cli_has_async_calls(cli)) {
     3777        if (smbXcli_conn_protocol(cli->conn) >= PROTOCOL_SMB2_02) {
     3778                return cli_smb2_getatr(cli,
     3779                                        fname,
     3780                                        attr,
     3781                                        size,
     3782                                        write_time);
     3783        }
     3784
     3785        frame = talloc_stackframe();
     3786
     3787        if (smbXcli_conn_has_async_calls(cli->conn)) {
    33113788                /*
    33123789                 * Can't use sync call while an async call is in flight
     
    33163793        }
    33173794
    3318         ev = event_context_init(frame);
     3795        ev = samba_tevent_context_init(frame);
    33193796        if (ev == NULL) {
    33203797                status = NT_STATUS_NO_MEMORY;
     
    33283805        }
    33293806
    3330         if (!tevent_req_poll(req, ev)) {
    3331                 status = map_nt_error_from_unix(errno);
     3807        if (!tevent_req_poll_ntstatus(req, ev, &status)) {
    33323808                goto fail;
    33333809        }
     
    33543830
    33553831struct tevent_req *cli_setattrE_send(TALLOC_CTX *mem_ctx,
    3356                                 struct event_context *ev,
     3832                                struct tevent_context *ev,
    33573833                                struct cli_state *cli,
    33583834                                uint16_t fnum,
     
    33723848        SSVAL(state->vwv+0, 0, fnum);
    33733849        push_dos_date2((uint8_t *)&state->vwv[1], 0, change_time,
    3374                        cli->serverzone);
     3850                       smb1cli_conn_server_time_zone(cli->conn));
    33753851        push_dos_date2((uint8_t *)&state->vwv[3], 0, access_time,
    3376                        cli->serverzone);
     3852                       smb1cli_conn_server_time_zone(cli->conn));
    33773853        push_dos_date2((uint8_t *)&state->vwv[5], 0, write_time,
    3378                        cli->serverzone);
     3854                       smb1cli_conn_server_time_zone(cli->conn));
    33793855
    33803856        subreq = cli_smb_send(state, ev, cli, SMBsetattrE, additional_flags,
     
    34123888                        time_t write_time)
    34133889{
    3414         TALLOC_CTX *frame = talloc_stackframe();
    3415         struct event_context *ev = NULL;
     3890        TALLOC_CTX *frame = NULL;
     3891        struct tevent_context *ev = NULL;
    34163892        struct tevent_req *req = NULL;
    34173893        NTSTATUS status = NT_STATUS_OK;
    34183894
    3419         if (cli_has_async_calls(cli)) {
     3895        if (smbXcli_conn_protocol(cli->conn) >= PROTOCOL_SMB2_02) {
     3896                return cli_smb2_setattrE(cli,
     3897                                        fnum,
     3898                                        change_time,
     3899                                        access_time,
     3900                                        write_time);
     3901        }
     3902
     3903        frame = talloc_stackframe();
     3904
     3905        if (smbXcli_conn_has_async_calls(cli->conn)) {
    34203906                /*
    34213907                 * Can't use sync call while an async call is in flight
     
    34253911        }
    34263912
    3427         ev = event_context_init(frame);
     3913        ev = samba_tevent_context_init(frame);
    34283914        if (ev == NULL) {
    34293915                status = NT_STATUS_NO_MEMORY;
     
    34433929        }
    34443930
    3445         if (!tevent_req_poll(req, ev)) {
    3446                 status = map_nt_error_from_unix(errno);
     3931        if (!tevent_req_poll_ntstatus(req, ev, &status)) {
    34473932                goto fail;
    34483933        }
     
    34663951
    34673952struct tevent_req *cli_setatr_send(TALLOC_CTX *mem_ctx,
    3468                                 struct event_context *ev,
     3953                                struct tevent_context *ev,
    34693954                                struct cli_state *cli,
    34703955                                const char *fname,
     
    34833968
    34843969        SSVAL(state->vwv+0, 0, attr);
    3485         push_dos_date3((uint8_t *)&state->vwv[1], 0, mtime, cli->serverzone);
     3970        push_dos_date3((uint8_t *)&state->vwv[1], 0, mtime, smb1cli_conn_server_time_zone(cli->conn));
    34863971
    34873972        bytes = talloc_array(state, uint8_t, 1);
     
    34903975        }
    34913976        bytes[0] = 4;
    3492         bytes = smb_bytes_push_str(bytes, cli_ucs2(cli), fname,
     3977        bytes = smb_bytes_push_str(bytes, smbXcli_conn_use_unicode(cli->conn), fname,
    34933978                                   strlen(fname)+1, NULL);
    34943979        if (tevent_req_nomem(bytes, req)) {
    34953980                return tevent_req_post(req, ev);
    34963981        }
    3497         bytes = TALLOC_REALLOC_ARRAY(state, bytes, uint8_t,
     3982        bytes = talloc_realloc(state, bytes, uint8_t,
    34983983                        talloc_get_size(bytes)+1);
    34993984        if (tevent_req_nomem(bytes, req)) {
     
    35023987
    35033988        bytes[talloc_get_size(bytes)-1] = 4;
    3504         bytes = smb_bytes_push_str(bytes, cli_ucs2(cli), "",
     3989        bytes = smb_bytes_push_str(bytes, smbXcli_conn_use_unicode(cli->conn), "",
    35053990                                   1, NULL);
    35063991        if (tevent_req_nomem(bytes, req)) {
     
    35414026                time_t mtime)
    35424027{
    3543         TALLOC_CTX *frame = talloc_stackframe();
    3544         struct event_context *ev = NULL;
     4028        TALLOC_CTX *frame = NULL;
     4029        struct tevent_context *ev = NULL;
    35454030        struct tevent_req *req = NULL;
    35464031        NTSTATUS status = NT_STATUS_OK;
    35474032
    3548         if (cli_has_async_calls(cli)) {
     4033        if (smbXcli_conn_protocol(cli->conn) >= PROTOCOL_SMB2_02) {
     4034                return cli_smb2_setatr(cli,
     4035                                        fname,
     4036                                        attr,
     4037                                        mtime);
     4038        }
     4039
     4040        frame = talloc_stackframe();
     4041
     4042        if (smbXcli_conn_has_async_calls(cli->conn)) {
    35494043                /*
    35504044                 * Can't use sync call while an async call is in flight
     
    35544048        }
    35554049
    3556         ev = event_context_init(frame);
     4050        ev = samba_tevent_context_init(frame);
    35574051        if (ev == NULL) {
    35584052                status = NT_STATUS_NO_MEMORY;
     
    35664060        }
    35674061
    3568         if (!tevent_req_poll(req, ev)) {
    3569                 status = map_nt_error_from_unix(errno);
     4062        if (!tevent_req_poll_ntstatus(req, ev, &status)) {
    35704063                goto fail;
    35714064        }
     
    35894082
    35904083struct tevent_req *cli_chkpath_send(TALLOC_CTX *mem_ctx,
    3591                                   struct event_context *ev,
     4084                                  struct tevent_context *ev,
    35924085                                  struct cli_state *cli,
    35934086                                  const char *fname)
     
    36084101        }
    36094102        bytes[0] = 4;
    3610         bytes = smb_bytes_push_str(bytes, cli_ucs2(cli), fname,
     4103        bytes = smb_bytes_push_str(bytes, smbXcli_conn_use_unicode(cli->conn), fname,
    36114104                                   strlen(fname)+1, NULL);
    36124105
     
    36464139{
    36474140        TALLOC_CTX *frame = talloc_stackframe();
    3648         struct event_context *ev = NULL;
     4141        struct tevent_context *ev = NULL;
    36494142        struct tevent_req *req = NULL;
    36504143        char *path2 = NULL;
    36514144        NTSTATUS status = NT_STATUS_OK;
    36524145
    3653         if (cli_has_async_calls(cli)) {
     4146        if (smbXcli_conn_has_async_calls(cli->conn)) {
    36544147                /*
    36554148                 * Can't use sync call while an async call is in flight
     
    36734166        }
    36744167
    3675         ev = event_context_init(frame);
     4168        ev = samba_tevent_context_init(frame);
    36764169        if (ev == NULL) {
    36774170                status = NT_STATUS_NO_MEMORY;
     
    36854178        }
    36864179
    3687         if (!tevent_req_poll(req, ev)) {
    3688                 status = map_nt_error_from_unix(errno);
     4180        if (!tevent_req_poll_ntstatus(req, ev, &status)) {
    36894181                goto fail;
    36904182        }
     
    37104202
    37114203struct tevent_req *cli_dskattr_send(TALLOC_CTX *mem_ctx,
    3712                                   struct event_context *ev,
     4204                                  struct tevent_context *ev,
    37134205                                  struct cli_state *cli)
    37144206{
     
    37394231        uint8_t wct;
    37404232        uint16_t *vwv = NULL;
    3741         uint8_t *inbuf;
    37424233        NTSTATUS status;
    37434234
    3744         status = cli_smb_recv(subreq, state, &inbuf, 4, &wct, &vwv, NULL,
     4235        status = cli_smb_recv(subreq, state, NULL, 4, &wct, &vwv, NULL,
    37454236                              NULL);
    37464237        TALLOC_FREE(subreq);
     
    37714262NTSTATUS cli_dskattr(struct cli_state *cli, int *bsize, int *total, int *avail)
    37724263{
    3773         TALLOC_CTX *frame = talloc_stackframe();
    3774         struct event_context *ev = NULL;
     4264        TALLOC_CTX *frame = NULL;
     4265        struct tevent_context *ev = NULL;
    37754266        struct tevent_req *req = NULL;
    37764267        NTSTATUS status = NT_STATUS_OK;
    37774268
    3778         if (cli_has_async_calls(cli)) {
     4269        frame = talloc_stackframe();
     4270
     4271        if (smbXcli_conn_has_async_calls(cli->conn)) {
    37794272                /*
    37804273                 * Can't use sync call while an async call is in flight
     
    37844277        }
    37854278
    3786         ev = event_context_init(frame);
     4279        ev = samba_tevent_context_init(frame);
    37874280        if (ev == NULL) {
    37884281                status = NT_STATUS_NO_MEMORY;
     
    37964289        }
    37974290
    3798         if (!tevent_req_poll(req, ev)) {
    3799                 status = map_nt_error_from_unix(errno);
     4291        if (!tevent_req_poll_ntstatus(req, ev, &status)) {
    38004292                goto fail;
    38014293        }
     
    38064298        TALLOC_FREE(frame);
    38074299        return status;
     4300}
     4301
     4302NTSTATUS cli_disk_size(struct cli_state *cli, const char *path, uint64_t *bsize,
     4303                       uint64_t *total, uint64_t *avail)
     4304{
     4305        uint64_t sectors_per_block;
     4306        uint64_t bytes_per_sector;
     4307        int old_bsize, old_total, old_avail;
     4308        NTSTATUS status;
     4309
     4310        if (smbXcli_conn_protocol(cli->conn) >= PROTOCOL_SMB2_02) {
     4311                return cli_smb2_dskattr(cli, path, bsize, total, avail);
     4312        }
     4313
     4314        /*
     4315         * Try the trans2 disk full size info call first.
     4316         * We already use this in SMBC_fstatvfs_ctx().
     4317         * Ignore 'actual_available_units' as we only
     4318         * care about the quota for the caller.
     4319         */
     4320
     4321        status = cli_get_fs_full_size_info(cli,
     4322                        total,
     4323                        avail,
     4324                        NULL,
     4325                        &sectors_per_block,
     4326                        &bytes_per_sector);
     4327
     4328        /* Try and cope will all varients of "we don't do this call"
     4329           and fall back to cli_dskattr. */
     4330
     4331        if (NT_STATUS_EQUAL(status,NT_STATUS_NOT_IMPLEMENTED) ||
     4332                        NT_STATUS_EQUAL(status,NT_STATUS_NOT_SUPPORTED) ||
     4333                        NT_STATUS_EQUAL(status,NT_STATUS_INVALID_INFO_CLASS) ||
     4334                        NT_STATUS_EQUAL(status,NT_STATUS_PROCEDURE_NOT_FOUND) ||
     4335                        NT_STATUS_EQUAL(status,NT_STATUS_INVALID_LEVEL) ||
     4336                        NT_STATUS_EQUAL(status,NT_STATUS_INVALID_PARAMETER) ||
     4337                        NT_STATUS_EQUAL(status,NT_STATUS_INVALID_DEVICE_REQUEST) ||
     4338                        NT_STATUS_EQUAL(status,NT_STATUS_INVALID_DEVICE_STATE) ||
     4339                        NT_STATUS_EQUAL(status,NT_STATUS_CTL_FILE_NOT_SUPPORTED) ||
     4340                        NT_STATUS_EQUAL(status,NT_STATUS_UNSUCCESSFUL)) {
     4341                goto try_dskattr;
     4342        }
     4343
     4344        if (!NT_STATUS_IS_OK(status)) {
     4345                return status;
     4346        }
     4347
     4348        if (bsize) {
     4349                *bsize = sectors_per_block *
     4350                         bytes_per_sector;
     4351        }
     4352
     4353        return NT_STATUS_OK;
     4354
     4355  try_dskattr:
     4356
     4357        /* Old SMB1 core protocol fallback. */
     4358        status = cli_dskattr(cli, &old_bsize, &old_total, &old_avail);
     4359        if (!NT_STATUS_IS_OK(status)) {
     4360                return status;
     4361        }
     4362        if (bsize) {
     4363                *bsize = (uint64_t)old_bsize;
     4364        }
     4365        if (total) {
     4366                *total = (uint64_t)old_total;
     4367        }
     4368        if (avail) {
     4369                *avail = (uint64_t)old_avail;
     4370        }
     4371        return NT_STATUS_OK;
    38084372}
    38094373
     
    38214385
    38224386struct tevent_req *cli_ctemp_send(TALLOC_CTX *mem_ctx,
    3823                                 struct event_context *ev,
     4387                                struct tevent_context *ev,
    38244388                                struct cli_state *cli,
    38254389                                const char *path)
     
    38434407        }
    38444408        bytes[0] = 4;
    3845         bytes = smb_bytes_push_str(bytes, cli_ucs2(cli), path,
     4409        bytes = smb_bytes_push_str(bytes, smbXcli_conn_use_unicode(cli->conn), path,
    38464410                                   strlen(path)+1, NULL);
    38474411        if (tevent_req_nomem(bytes, req)) {
     
    38694433        uint32_t num_bytes = 0;
    38704434        uint8_t *bytes = NULL;
    3871         uint8_t *inbuf;
    3872 
    3873         status = cli_smb_recv(subreq, state, &inbuf, 1, &wcnt, &vwv,
     4435
     4436        status = cli_smb_recv(subreq, state, NULL, 1, &wcnt, &vwv,
    38744437                              &num_bytes, &bytes);
    38754438        TALLOC_FREE(subreq);
     
    39264489{
    39274490        TALLOC_CTX *frame = talloc_stackframe();
    3928         struct event_context *ev;
     4491        struct tevent_context *ev;
    39294492        struct tevent_req *req;
    39304493        NTSTATUS status = NT_STATUS_OK;
    39314494
    3932         if (cli_has_async_calls(cli)) {
     4495        if (smbXcli_conn_has_async_calls(cli->conn)) {
    39334496                /*
    39344497                 * Can't use sync call while an async call is in flight
     
    39384501        }
    39394502
    3940         ev = event_context_init(frame);
     4503        ev = samba_tevent_context_init(frame);
    39414504        if (ev == NULL) {
    39424505                status = NT_STATUS_NO_MEMORY;
     
    39504513        }
    39514514
    3952         if (!tevent_req_poll(req, ev)) {
    3953                 status = map_nt_error_from_unix(errno);
     4515        if (!tevent_req_poll_ntstatus(req, ev, &status)) {
    39544516                goto fail;
    39554517        }
     
    40034565        if (ea_namelen == 0 && ea_len == 0) {
    40044566                data_len = 4;
    4005                 data = (uint8_t *)SMB_MALLOC(data_len);
     4567                data = talloc_array(talloc_tos(),
     4568                                uint8_t,
     4569                                data_len);
    40064570                if (!data) {
    40074571                        return NT_STATUS_NO_MEMORY;
     
    40114575        } else {
    40124576                data_len = 4 + 4 + ea_namelen + 1 + ea_len;
    4013                 data = (uint8_t *)SMB_MALLOC(data_len);
     4577                data = talloc_array(talloc_tos(),
     4578                                uint8_t,
     4579                                data_len);
    40144580                if (!data) {
    40154581                        return NT_STATUS_NO_MEMORY;
     
    40284594                           setup, 1, 0,
    40294595                           param, param_len, 2,
    4030                            data,  data_len, cli->max_xmit,
     4596                           data,  data_len, CLI_BUFFER_SIZE,
    40314597                           NULL,
    40324598                           NULL, 0, NULL, /* rsetup */
    40334599                           NULL, 0, NULL, /* rparam */
    40344600                           NULL, 0, NULL); /* rdata */
    4035         SAFE_FREE(data);
     4601        talloc_free(data);
    40364602        return status;
    40374603}
     
    40474613        unsigned int param_len = 0;
    40484614        uint8_t *param;
    4049         size_t srclen = 2*(strlen(path)+1);
    4050         char *p;
    40514615        NTSTATUS status;
    4052 
    4053         param = SMB_MALLOC_ARRAY(uint8_t, 6+srclen+2);
     4616        TALLOC_CTX *frame = NULL;
     4617
     4618        if (smbXcli_conn_protocol(cli->conn) >= PROTOCOL_SMB2_02) {
     4619                return cli_smb2_set_ea_path(cli,
     4620                                        path,
     4621                                        ea_name,
     4622                                        ea_val,
     4623                                        ea_len);
     4624        }
     4625
     4626        frame = talloc_stackframe();
     4627
     4628        param = talloc_array(frame, uint8_t, 6);
    40544629        if (!param) {
    4055                 return NT_STATUS_NO_MEMORY;
    4056         }
    4057         memset(param, '\0', 6);
     4630                status = NT_STATUS_NO_MEMORY;
     4631                goto fail;
     4632        }
    40584633        SSVAL(param,0,SMB_INFO_SET_EA);
    4059         p = (char *)(&param[6]);
    4060 
    4061         p += clistr_push(cli, p, path, srclen, STR_TERMINATE);
    4062         param_len = PTR_DIFF(p, param);
     4634        SSVAL(param,2,0);
     4635        SSVAL(param,4,0);
     4636
     4637        param = trans2_bytes_push_str(param, smbXcli_conn_use_unicode(cli->conn),
     4638                                      path, strlen(path)+1,
     4639                                      NULL);
     4640        param_len = talloc_get_size(param);
    40634641
    40644642        status = cli_set_ea(cli, TRANSACT2_SETPATHINFO, param, param_len,
    40654643                            ea_name, ea_val, ea_len);
    4066         SAFE_FREE(param);
     4644
     4645  fail:
     4646
     4647        TALLOC_FREE(frame);
    40674648        return status;
    40684649}
     
    40774658{
    40784659        uint8_t param[6];
     4660
     4661        if (smbXcli_conn_protocol(cli->conn) >= PROTOCOL_SMB2_02) {
     4662                return cli_smb2_set_ea_fnum(cli,
     4663                                        fnum,
     4664                                        ea_name,
     4665                                        ea_val,
     4666                                        ea_len);
     4667        }
    40794668
    40804669        memset(param, 0, 6);
     
    41444733        }
    41454734
    4146         ea_list = TALLOC_ARRAY(ctx, struct ea_struct, num_eas);
     4735        ea_list = talloc_array(ctx, struct ea_struct, num_eas);
    41474736        if (!ea_list) {
    41484737                return false;
     
    41604749                ea->flags = CVAL(p,0);
    41614750                unix_ea_name[0] = '\0';
    4162                 pull_ascii_fstring(unix_ea_name, p + 4);
     4751                pull_ascii(unix_ea_name, p + 4, sizeof(unix_ea_name), rdata_len - PTR_DIFF(p+4, rdata), STR_TERMINATE);
    41634752                ea->name = talloc_strdup(ea_list, unix_ea_name);
    41644753                if (!ea->name) {
     
    42124801        subreq = cli_qpathinfo_send(state, ev, cli, fname,
    42134802                                    SMB_INFO_QUERY_ALL_EAS, 4,
    4214                                     cli->max_xmit);
     4803                                    CLI_BUFFER_SIZE);
    42154804        if (tevent_req_nomem(subreq, req)) {
    42164805                return tevent_req_post(req, ev);
     
    42594848                struct ea_struct **pea_list)
    42604849{
    4261         TALLOC_CTX *frame = talloc_stackframe();
    4262         struct event_context *ev = NULL;
     4850        TALLOC_CTX *frame = NULL;
     4851        struct tevent_context *ev = NULL;
    42634852        struct tevent_req *req = NULL;
    42644853        NTSTATUS status = NT_STATUS_NO_MEMORY;
    42654854
    4266         if (cli_has_async_calls(cli)) {
     4855        if (smbXcli_conn_protocol(cli->conn) >= PROTOCOL_SMB2_02) {
     4856                return cli_smb2_get_ea_list_path(cli,
     4857                                        path,
     4858                                        ctx,
     4859                                        pnum_eas,
     4860                                        pea_list);
     4861        }
     4862
     4863        frame = talloc_stackframe();
     4864
     4865        if (smbXcli_conn_has_async_calls(cli->conn)) {
    42674866                /*
    42684867                 * Can't use sync call while an async call is in flight
     
    42714870                goto fail;
    42724871        }
    4273         ev = event_context_init(frame);
     4872        ev = samba_tevent_context_init(frame);
    42744873        if (ev == NULL) {
    42754874                goto fail;
     
    43714970
    43724971static struct tevent_req *cli_posix_open_internal_send(TALLOC_CTX *mem_ctx,
    4373                                         struct event_context *ev,
     4972                                        struct tevent_context *ev,
    43744973                                        struct cli_state *cli,
    43754974                                        const char *fname,
     
    43984997        SSVAL(state->param, 0, SMB_POSIX_PATH_OPEN);
    43994998
    4400         state->param = trans2_bytes_push_str(state->param, cli_ucs2(cli), fname,
     4999        state->param = trans2_bytes_push_str(state->param, smbXcli_conn_use_unicode(cli->conn), fname,
    44015000                                   strlen(fname)+1, NULL);
    44025001
     
    44425041
    44435042struct tevent_req *cli_posix_open_send(TALLOC_CTX *mem_ctx,
    4444                                         struct event_context *ev,
     5043                                        struct tevent_context *ev,
    44455044                                        struct cli_state *cli,
    44465045                                        const char *fname,
     
    44735072
    44745073        TALLOC_CTX *frame = talloc_stackframe();
    4475         struct event_context *ev = NULL;
     5074        struct tevent_context *ev = NULL;
    44765075        struct tevent_req *req = NULL;
    44775076        NTSTATUS status = NT_STATUS_OK;
    44785077
    4479         if (cli_has_async_calls(cli)) {
     5078        if (smbXcli_conn_has_async_calls(cli->conn)) {
    44805079                /*
    44815080                 * Can't use sync call while an async call is in flight
     
    44855084        }
    44865085
    4487         ev = event_context_init(frame);
     5086        ev = samba_tevent_context_init(frame);
    44885087        if (ev == NULL) {
    44895088                status = NT_STATUS_NO_MEMORY;
     
    45025101        }
    45035102
    4504         if (!tevent_req_poll(req, ev)) {
    4505                 status = map_nt_error_from_unix(errno);
     5103        if (!tevent_req_poll_ntstatus(req, ev, &status)) {
    45065104                goto fail;
    45075105        }
     
    45155113
    45165114struct tevent_req *cli_posix_mkdir_send(TALLOC_CTX *mem_ctx,
    4517                                         struct event_context *ev,
     5115                                        struct tevent_context *ev,
    45185116                                        struct cli_state *cli,
    45195117                                        const char *fname,
     
    45325130{
    45335131        TALLOC_CTX *frame = talloc_stackframe();
    4534         struct event_context *ev = NULL;
     5132        struct tevent_context *ev = NULL;
    45355133        struct tevent_req *req = NULL;
    45365134        NTSTATUS status = NT_STATUS_OK;
    45375135
    4538         if (cli_has_async_calls(cli)) {
     5136        if (smbXcli_conn_has_async_calls(cli->conn)) {
    45395137                /*
    45405138                 * Can't use sync call while an async call is in flight
     
    45445142        }
    45455143
    4546         ev = event_context_init(frame);
     5144        ev = samba_tevent_context_init(frame);
    45475145        if (ev == NULL) {
    45485146                status = NT_STATUS_NO_MEMORY;
     
    45605158        }
    45615159
    4562         if (!tevent_req_poll(req, ev)) {
    4563                 status = map_nt_error_from_unix(errno);
     5160        if (!tevent_req_poll_ntstatus(req, ev, &status)) {
    45645161                goto fail;
    45655162        }
     
    45835180
    45845181static struct tevent_req *cli_posix_unlink_internal_send(TALLOC_CTX *mem_ctx,
    4585                                         struct event_context *ev,
     5182                                        struct tevent_context *ev,
    45865183                                        struct cli_state *cli,
    45875184                                        const char *fname,
     
    46185215
    46195216struct tevent_req *cli_posix_unlink_send(TALLOC_CTX *mem_ctx,
    4620                                         struct event_context *ev,
     5217                                        struct tevent_context *ev,
    46215218                                        struct cli_state *cli,
    46225219                                        const char *fname)
     
    46385235{
    46395236        TALLOC_CTX *frame = talloc_stackframe();
    4640         struct event_context *ev = NULL;
     5237        struct tevent_context *ev = NULL;
    46415238        struct tevent_req *req = NULL;
    46425239        NTSTATUS status = NT_STATUS_OK;
    46435240
    4644         if (cli_has_async_calls(cli)) {
     5241        if (smbXcli_conn_has_async_calls(cli->conn)) {
    46455242                /*
    46465243                 * Can't use sync call while an async call is in flight
     
    46505247        }
    46515248
    4652         ev = event_context_init(frame);
     5249        ev = samba_tevent_context_init(frame);
    46535250        if (ev == NULL) {
    46545251                status = NT_STATUS_NO_MEMORY;
     
    46655262        }
    46665263
    4667         if (!tevent_req_poll(req, ev)) {
    4668                 status = map_nt_error_from_unix(errno);
     5264        if (!tevent_req_poll_ntstatus(req, ev, &status)) {
    46695265                goto fail;
    46705266        }
     
    46825278
    46835279struct tevent_req *cli_posix_rmdir_send(TALLOC_CTX *mem_ctx,
    4684                                         struct event_context *ev,
     5280                                        struct tevent_context *ev,
    46855281                                        struct cli_state *cli,
    46865282                                        const char *fname)
     
    46995295{
    47005296        TALLOC_CTX *frame = talloc_stackframe();
    4701         struct event_context *ev = NULL;
     5297        struct tevent_context *ev = NULL;
    47025298        struct tevent_req *req = NULL;
    47035299        NTSTATUS status = NT_STATUS_OK;
    47045300
    4705         if (cli_has_async_calls(cli)) {
     5301        if (smbXcli_conn_has_async_calls(cli->conn)) {
    47065302                /*
    47075303                 * Can't use sync call while an async call is in flight
     
    47115307        }
    47125308
    4713         ev = event_context_init(frame);
     5309        ev = samba_tevent_context_init(frame);
    47145310        if (ev == NULL) {
    47155311                status = NT_STATUS_NO_MEMORY;
     
    47265322        }
    47275323
    4728         if (!tevent_req_poll(req, ev)) {
    4729                 status = map_nt_error_from_unix(errno);
     5324        if (!tevent_req_poll_ntstatus(req, ev, &status)) {
    47305325                goto fail;
    47315326        }
     
    47585353        struct tevent_req *req, *subreq;
    47595354        struct cli_notify_state *state;
     5355        unsigned old_timeout;
    47605356
    47615357        req = tevent_req_create(mem_ctx, &state, struct cli_notify_state);
     
    47675363        SSVAL(state->setup, 4, fnum);
    47685364        SSVAL(state->setup, 6, recursive);
     5365
     5366        /*
     5367         * Notifies should not time out
     5368         */
     5369        old_timeout = cli_set_timeout(cli, 0);
    47695370
    47705371        subreq = cli_trans_send(
     
    47875388                0);                     /* max returned data. */
    47885389
     5390        cli_set_timeout(cli, old_timeout);
     5391
    47895392        if (tevent_req_nomem(subreq, req)) {
    47905393                return tevent_req_post(req, ev);
     
    48175420
    48185421        while (num_params - ofs > 12) {
    4819                 uint32_t len = IVAL(params, ofs);
     5422                uint32_t next = IVAL(params, ofs);
    48205423                state->num_changes += 1;
    48215424
    4822                 if ((len == 0) || (ofs+len >= num_params)) {
     5425                if ((next == 0) || (ofs+next >= num_params)) {
    48235426                        break;
    48245427                }
    4825                 ofs += len;
     5428                ofs += next;
    48265429        }
    48275430
     
    48415444                char *name;
    48425445
    4843                 if ((next != 0) && (len+12 != next)) {
     5446                if (trans_oob(num_params, ofs + 12, len)) {
    48445447                        TALLOC_FREE(params);
    48455448                        tevent_req_nterror(
     
    48495452
    48505453                state->changes[i].action = IVAL(params, ofs+4);
    4851                 ret = clistr_pull_talloc(params, (char *)params, flags2,
     5454                ret = clistr_pull_talloc(state->changes, (char *)params, flags2,
    48525455                                         &name, params+ofs+12, len,
    48535456                                         STR_TERMINATE|STR_UNICODE);
     
    48825485}
    48835486
     5487NTSTATUS cli_notify(struct cli_state *cli, uint16_t fnum, uint32_t buffer_size,
     5488                    uint32_t completion_filter, bool recursive,
     5489                    TALLOC_CTX *mem_ctx, uint32_t *pnum_changes,
     5490                    struct notify_change **pchanges)
     5491{
     5492        TALLOC_CTX *frame = talloc_stackframe();
     5493        struct tevent_context *ev;
     5494        struct tevent_req *req;
     5495        NTSTATUS status = NT_STATUS_NO_MEMORY;
     5496
     5497        if (smbXcli_conn_has_async_calls(cli->conn)) {
     5498                /*
     5499                 * Can't use sync call while an async call is in flight
     5500                 */
     5501                status = NT_STATUS_INVALID_PARAMETER;
     5502                goto fail;
     5503        }
     5504        ev = samba_tevent_context_init(frame);
     5505        if (ev == NULL) {
     5506                goto fail;
     5507        }
     5508        req = cli_notify_send(ev, ev, cli, fnum, buffer_size,
     5509                              completion_filter, recursive);
     5510        if (req == NULL) {
     5511                goto fail;
     5512        }
     5513        if (!tevent_req_poll_ntstatus(req, ev, &status)) {
     5514                goto fail;
     5515        }
     5516        status = cli_notify_recv(req, mem_ctx, pnum_changes, pchanges);
     5517 fail:
     5518        TALLOC_FREE(frame);
     5519        return status;
     5520}
     5521
    48845522struct cli_qpathinfo_state {
    48855523        uint8_t *param;
     
    49155553        SSVAL(state->param, 0, level);
    49165554        state->param = trans2_bytes_push_str(
    4917                 state->param, cli_ucs2(cli), fname, strlen(fname)+1, NULL);
     5555                state->param, smbXcli_conn_use_unicode(cli->conn), fname, strlen(fname)+1, NULL);
    49185556        if (tevent_req_nomem(state->param, req)) {
    49195557                return tevent_req_post(req, ev);
     
    49915629{
    49925630        TALLOC_CTX *frame = talloc_stackframe();
    4993         struct event_context *ev;
     5631        struct tevent_context *ev;
    49945632        struct tevent_req *req;
    49955633        NTSTATUS status = NT_STATUS_NO_MEMORY;
    49965634
    4997         if (cli_has_async_calls(cli)) {
     5635        if (smbXcli_conn_has_async_calls(cli->conn)) {
    49985636                /*
    49995637                 * Can't use sync call while an async call is in flight
     
    50025640                goto fail;
    50035641        }
    5004         ev = event_context_init(frame);
     5642        ev = samba_tevent_context_init(frame);
    50055643        if (ev == NULL) {
    50065644                goto fail;
     
    50245662        uint8_t param[4];
    50255663        uint8_t *data;
     5664        uint16_t recv_flags2;
    50265665        uint32_t min_rdata;
    50275666        uint8_t *rdata;
     
    50835722        NTSTATUS status;
    50845723
    5085         status = cli_trans_recv(subreq, state, NULL, NULL, 0, NULL,
     5724        status = cli_trans_recv(subreq, state,
     5725                                &state->recv_flags2,
     5726                                NULL, 0, NULL,
    50865727                                NULL, 0, NULL,
    50875728                                &state->rdata, state->min_rdata,
     
    50945735
    50955736NTSTATUS cli_qfileinfo_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
     5737                            uint16_t *recv_flags2,
    50965738                            uint8_t **rdata, uint32_t *num_rdata)
    50975739{
     
    51025744        if (tevent_req_is_nterror(req, &status)) {
    51035745                return status;
     5746        }
     5747
     5748        if (recv_flags2 != NULL) {
     5749                *recv_flags2 = state->recv_flags2;
    51045750        }
    51055751        if (rdata != NULL) {
     
    51165762NTSTATUS cli_qfileinfo(TALLOC_CTX *mem_ctx, struct cli_state *cli,
    51175763                       uint16_t fnum, uint16_t level, uint32_t min_rdata,
    5118                        uint32_t max_rdata,
     5764                       uint32_t max_rdata, uint16_t *recv_flags2,
    51195765                       uint8_t **rdata, uint32_t *num_rdata)
    51205766{
    51215767        TALLOC_CTX *frame = talloc_stackframe();
    5122         struct event_context *ev;
     5768        struct tevent_context *ev;
    51235769        struct tevent_req *req;
    51245770        NTSTATUS status = NT_STATUS_NO_MEMORY;
    51255771
    5126         if (cli_has_async_calls(cli)) {
     5772        if (smbXcli_conn_has_async_calls(cli->conn)) {
    51275773                /*
    51285774                 * Can't use sync call while an async call is in flight
     
    51315777                goto fail;
    51325778        }
    5133         ev = event_context_init(frame);
     5779        ev = samba_tevent_context_init(frame);
    51345780        if (ev == NULL) {
    51355781                goto fail;
     
    51435789                goto fail;
    51445790        }
    5145         status = cli_qfileinfo_recv(req, mem_ctx, rdata, num_rdata);
     5791        status = cli_qfileinfo_recv(req, mem_ctx, recv_flags2, rdata, num_rdata);
    51465792 fail:
    51475793        TALLOC_FREE(frame);
     
    51565802
    51575803struct tevent_req *cli_flush_send(TALLOC_CTX *mem_ctx,
    5158                                   struct event_context *ev,
     5804                                  struct tevent_context *ev,
    51595805                                  struct cli_state *cli,
    51605806                                  uint16_t fnum)
     
    52005846{
    52015847        TALLOC_CTX *frame = talloc_stackframe();
    5202         struct event_context *ev;
     5848        struct tevent_context *ev;
    52035849        struct tevent_req *req;
    52045850        NTSTATUS status = NT_STATUS_NO_MEMORY;
    52055851
    5206         if (cli_has_async_calls(cli)) {
     5852        if (smbXcli_conn_has_async_calls(cli->conn)) {
    52075853                /*
    52085854                 * Can't use sync call while an async call is in flight
     
    52115857                goto fail;
    52125858        }
    5213         ev = event_context_init(frame);
     5859        ev = samba_tevent_context_init(frame);
    52145860        if (ev == NULL) {
    52155861                goto fail;
     
    52535899        }
    52545900        state->get_names = get_names;
    5255         ret_size = get_names ? cli->max_xmit : 16;
     5901        ret_size = get_names ? CLI_BUFFER_SIZE : 16;
    52565902
    52575903        SIVAL(state->setup + 0, 0, FSCTL_GET_SHADOW_COPY_DATA);
     
    53295975                        names, CH_UTF16LE, CH_UNIX,
    53305976                        src, 2 * sizeof(SHADOW_COPY_LABEL),
    5331                         &names[i], &converted_size, True);
     5977                        &names[i], &converted_size);
    53325978                if (!ret) {
    53335979                        TALLOC_FREE(names);
     
    53455991{
    53465992        TALLOC_CTX *frame = talloc_stackframe();
    5347         struct event_context *ev;
     5993        struct tevent_context *ev;
    53485994        struct tevent_req *req;
    53495995        NTSTATUS status = NT_STATUS_NO_MEMORY;
    53505996
    5351         if (cli_has_async_calls(cli)) {
     5997        if (smbXcli_conn_has_async_calls(cli->conn)) {
    53525998                /*
    53535999                 * Can't use sync call while an async call is in flight
     
    53566002                goto fail;
    53576003        }
    5358         ev = event_context_init(frame);
     6004        ev = samba_tevent_context_init(frame);
    53596005        if (ev == NULL) {
    53606006                goto fail;
Note: See TracChangeset for help on using the changeset viewer.