s3:libsmb: Plumb cli_smb2_qpathinfo2() inside cli_qpathinfo2().
[bbaumbach/samba-autobuild/.git] / source3 / libsmb / clirap.c
index 4c5e338606f9f2b8c9a7d120ec2bc82c2b46239c..41608dd73284d2d8eb268c98a505992516082d7f 100644 (file)
 */
 
 #include "includes.h"
-
-/****************************************************************************
- Call a remote api on an arbitrary pipe.  takes param, data and setup buffers.
-****************************************************************************/
-
-bool cli_api_pipe(struct cli_state *cli, const char *pipe_name,
-                  uint16 *setup, uint32 setup_count, uint32 max_setup_count,
-                  char *params, uint32 param_count, uint32 max_param_count,
-                  char *data, uint32 data_count, uint32 max_data_count,
-                  char **rparam, uint32 *rparam_count,
-                  char **rdata, uint32 *rdata_count)
-{
-       cli_send_trans(cli, SMBtrans,
-                 pipe_name,
-                 0,0,                         /* fid, flags */
-                 setup, setup_count, max_setup_count,
-                 params, param_count, max_param_count,
-                 data, data_count, max_data_count);
-
-       return (cli_receive_trans(cli, SMBtrans,
-                            rparam, (unsigned int *)rparam_count,
-                            rdata, (unsigned int *)rdata_count));
-}
+#include "../libcli/auth/libcli_auth.h"
+#include "../librpc/gen_ndr/rap.h"
+#include "../lib/crypto/arcfour.h"
+#include "../lib/util/tevent_ntstatus.h"
+#include "async_smb.h"
+#include "libsmb/libsmb.h"
+#include "libsmb/clirap.h"
+#include "trans2.h"
+#include "../libcli/smb/smbXcli_base.h"
+
+#define PIPE_LANMAN   "\\PIPE\\LANMAN"
 
 /****************************************************************************
  Call a remote api
@@ -54,17 +42,54 @@ bool cli_api(struct cli_state *cli,
             char **rparam, unsigned int *rprcnt,
             char **rdata, unsigned int *rdrcnt)
 {
-       cli_send_trans(cli,SMBtrans,
-                 PIPE_LANMAN,             /* Name */
-                 0,0,                     /* fid, flags */
-                 NULL,0,0,                /* Setup, length, max */
-                 param, prcnt, mprcnt,    /* Params, length, max */
-                 data, drcnt, mdrcnt      /* Data, length, max */
-                );
-
-       return (cli_receive_trans(cli,SMBtrans,
-                            rparam, rprcnt,
-                            rdata, rdrcnt));
+       NTSTATUS status;
+
+       uint8_t *my_rparam, *my_rdata;
+       uint32_t num_my_rparam, num_my_rdata;
+
+       status = cli_trans(talloc_tos(), cli, SMBtrans,
+                          PIPE_LANMAN, 0, /* name, fid */
+                          0, 0,           /* function, flags */
+                          NULL, 0, 0,     /* setup */
+                          (uint8_t *)param, prcnt, mprcnt, /* Params, length, max */
+                          (uint8_t *)data, drcnt, mdrcnt,  /* Data, length, max */
+                          NULL,                 /* recv_flags2 */
+                          NULL, 0, NULL,        /* rsetup */
+                          &my_rparam, 0, &num_my_rparam,
+                          &my_rdata, 0, &num_my_rdata);
+       if (!NT_STATUS_IS_OK(status)) {
+               return false;
+       }
+
+       /*
+        * I know this memcpy massively hurts, but there are just tons
+        * of callers of cli_api that eventually need changing to
+        * talloc
+        */
+
+       *rparam = (char *)memdup(my_rparam, num_my_rparam);
+       if (*rparam == NULL) {
+               goto fail;
+       }
+       *rprcnt = num_my_rparam;
+       TALLOC_FREE(my_rparam);
+
+       *rdata = (char *)memdup(my_rdata, num_my_rdata);
+       if (*rdata == NULL) {
+               goto fail;
+       }
+       *rdrcnt = num_my_rdata;
+       TALLOC_FREE(my_rdata);
+
+       return true;
+fail:
+       TALLOC_FREE(my_rdata);
+       TALLOC_FREE(my_rparam);
+       *rparam = NULL;
+       *rprcnt = 0;
+       *rdata = NULL;
+       *rdrcnt = 0;
+       return false;
 }
 
 /****************************************************************************
@@ -92,13 +117,17 @@ bool cli_NetWkstaUserLogon(struct cli_state *cli,char *user, char *workstation)
        SSVAL(p,0,1);
        p += 2;
        strlcpy(p,user,sizeof(param)-PTR_DIFF(p,param));
-       strupper_m(p);
+       if (!strupper_m(p)) {
+               return false;
+       }
        p += 21;
        p++;
        p += 15;
        p++;
        strlcpy(p, workstation,sizeof(param)-PTR_DIFF(p,param));
-       strupper_m(p);
+       if (!strupper_m(p)) {
+               return false;
+       }
        p += 16;
        SSVAL(p, 0, CLI_BUFFER_SIZE);
        p += 2;
@@ -116,7 +145,10 @@ bool cli_NetWkstaUserLogon(struct cli_state *cli,char *user, char *workstation)
 
                if (cli->rap_error == 0) {
                        DEBUG(4,("NetWkstaUserLogon success\n"));
-                       cli->privileges = SVAL(p, 24);
+                       /*
+                        * The cli->privileges = SVAL(p, 24); field was set here
+                        * but it was not use anywhere else.
+                        */
                        /* The cli->eff_name field used to be set here
                           but it wasn't used anywhere else. */
                } else {
@@ -191,12 +223,13 @@ int cli_RNetShareEnum(struct cli_state *cli, void (*fn)(const char *, uint32, co
 
                                        sname = p;
                                        type = SVAL(p,14);
-                                       comment_offset = IVAL(p,16) & 0xFFFF;
-                                       if (comment_offset < 0 || comment_offset > (int)rdrcnt) {
+                                       comment_offset = (IVAL(p,16) & 0xFFFF) - converter;
+                                       if (comment_offset < 0 ||
+                                                       comment_offset > (int)rdrcnt) {
                                                TALLOC_FREE(frame);
                                                break;
                                        }
-                                       cmnt = comment_offset?(rdata+comment_offset-converter):"";
+                                       cmnt = comment_offset?(rdata+comment_offset):"";
 
                                        /* Work out the comment length. */
                                        for (p1 = cmnt, len = 0; *p1 &&
@@ -269,11 +302,9 @@ bool cli_NetServerEnum(struct cli_state *cli, char *workgroup, uint32 stype,
                p = param;
                SIVAL(p,0,func); /* api number */
                p += 2;
-               /* Next time through we need to use the continue api */
-               func = RAP_NetServerEnum3;
 
-               if (last_entry) {
-                       strlcpy(p,"WrLehDOz", sizeof(param)-PTR_DIFF(p,param));
+               if (func == RAP_NetServerEnum3) {
+                       strlcpy(p,"WrLehDzz", sizeof(param)-PTR_DIFF(p,param));
                } else {
                        strlcpy(p,"WrLehDz", sizeof(param)-PTR_DIFF(p,param));
                }
@@ -292,7 +323,7 @@ bool cli_NetServerEnum(struct cli_state *cli, char *workgroup, uint32 stype,
                 * to continue from.
                 */
                len = push_ascii(p,
-                               last_entry ? last_entry : workgroup,
+                               workgroup,
                                sizeof(param) - PTR_DIFF(p,param) - 1,
                                STR_TERMINATE|STR_UPPER);
 
@@ -302,6 +333,22 @@ bool cli_NetServerEnum(struct cli_state *cli, char *workgroup, uint32 stype,
                }
                p += len;
 
+               if (func == RAP_NetServerEnum3) {
+                       len = push_ascii(p,
+                                       last_entry ? last_entry : "",
+                                       sizeof(param) - PTR_DIFF(p,param) - 1,
+                                       STR_TERMINATE);
+
+                       if (len == (size_t)-1) {
+                               SAFE_FREE(last_entry);
+                               return false;
+                       }
+                       p += len;
+               }
+
+               /* Next time through we need to use the continue api */
+               func = RAP_NetServerEnum3;
+
                if (!cli_api(cli,
                        param, PTR_DIFF(p,param), 8, /* params, length, max */
                        NULL, 0, CLI_BUFFER_SIZE, /* data, length, max */
@@ -363,6 +410,7 @@ bool cli_NetServerEnum(struct cli_state *cli, char *workgroup, uint32 stype,
                                const char *p1;
                                char *s1, *s2;
                                TALLOC_CTX *frame = talloc_stackframe();
+                               uint32_t entry_stype;
 
                                if (p + 26 > rdata_end) {
                                        TALLOC_FREE(frame);
@@ -373,7 +421,7 @@ bool cli_NetServerEnum(struct cli_state *cli, char *workgroup, uint32 stype,
                                comment_offset = (IVAL(p,22) & 0xFFFF)-converter;
                                cmnt = comment_offset?(rdata+comment_offset):"";
 
-                               if (comment_offset < 0 || comment_offset > (int)rdrcnt) {
+                               if (comment_offset < 0 || comment_offset >= (int)rdrcnt) {
                                        TALLOC_FREE(frame);
                                        continue;
                                }
@@ -386,7 +434,7 @@ bool cli_NetServerEnum(struct cli_state *cli, char *workgroup, uint32 stype,
                                        len++;
                                }
 
-                               stype = IVAL(p,18) & ~SV_TYPE_LOCAL_LIST_ONLY;
+                               entry_stype = IVAL(p,18) & ~SV_TYPE_LOCAL_LIST_ONLY;
 
                                pull_string_talloc(frame,rdata,0,
                                        &s1,sname,16,STR_ASCII);
@@ -398,7 +446,7 @@ bool cli_NetServerEnum(struct cli_state *cli, char *workgroup, uint32 stype,
                                        continue;
                                }
 
-                               fn(s1, stype, s2, state);
+                               fn(s1, entry_stype, s2, state);
                                TALLOC_FREE(frame);
                        }
 
@@ -490,7 +538,7 @@ bool cli_oem_change_password(struct cli_state *cli, const char *user, const char
        DEBUG(100,("make_oem_passwd_hash\n"));
        dump_data(100, data, 516);
 #endif
-       SamOEMhash( (unsigned char *)data, (unsigned char *)old_pw_hash, 516);
+       arcfour_crypt( (unsigned char *)data, (unsigned char *)old_pw_hash, 516);
 
        /*
         * Now place the old password hash in the data.
@@ -501,26 +549,16 @@ bool cli_oem_change_password(struct cli_state *cli, const char *user, const char
 
        data_len = 532;
 
-       if (cli_send_trans(cli,SMBtrans,
-                    PIPE_LANMAN,                          /* name */
-                    0,0,                                  /* fid, flags */
-                    NULL,0,0,                             /* setup, length, max */
-                    param,param_len,2,                    /* param, length, max */
-                    (char *)data,data_len,0                       /* data, length, max */
-                   ) == False) {
+       if (!cli_api(cli,
+                    param, param_len, 4,               /* param, length, max */
+                    (char *)data, data_len, 0,         /* data, length, max */
+                    &rparam, &rprcnt,
+                    &rdata, &rdrcnt)) {
                DEBUG(0,("cli_oem_change_password: Failed to send password change for user %s\n",
                        user ));
                return False;
        }
 
-       if (!cli_receive_trans(cli,SMBtrans,
-                       &rparam, &rprcnt,
-                       &rdata, &rdrcnt)) {
-               DEBUG(0,("cli_oem_change_password: Failed to recieve reply to password change for user %s\n",
-                       user ));
-               return False;
-       }
-
        if (rparam) {
                cli->rap_error = SVAL(rparam,0);
        }
@@ -535,134 +573,147 @@ bool cli_oem_change_password(struct cli_state *cli, const char *user, const char
  Send a qpathinfo call.
 ****************************************************************************/
 
-bool cli_qpathinfo(struct cli_state *cli,
-                       const char *fname,
-                       time_t *change_time,
-                       time_t *access_time,
-                       time_t *write_time,
-                       SMB_OFF_T *size,
-                       uint16 *mode)
+struct cli_qpathinfo1_state {
+       struct cli_state *cli;
+       uint32_t num_data;
+       uint8_t *data;
+};
+
+static void cli_qpathinfo1_done(struct tevent_req *subreq);
+
+struct tevent_req *cli_qpathinfo1_send(TALLOC_CTX *mem_ctx,
+                                      struct tevent_context *ev,
+                                      struct cli_state *cli,
+                                      const char *fname)
 {
-       unsigned int data_len = 0;
-       unsigned int param_len = 0;
-       unsigned int rparam_len, rdata_len;
-       uint16 setup = TRANSACT2_QPATHINFO;
-       char *param;
-       char *rparam=NULL, *rdata=NULL;
-       int count=8;
-       bool ret;
-       time_t (*date_fn)(struct cli_state *, const void *);
-       char *p;
-       size_t nlen = 2*(strlen(fname)+1);
+       struct tevent_req *req = NULL, *subreq = NULL;
+       struct cli_qpathinfo1_state *state = NULL;
 
-       param = SMB_MALLOC_ARRAY(char, 6+nlen+2);
-       if (!param) {
-               return false;
+       req = tevent_req_create(mem_ctx, &state, struct cli_qpathinfo1_state);
+       if (req == NULL) {
+               return NULL;
        }
-       p = param;
-       memset(p, '\0', 6);
-       SSVAL(p, 0, SMB_INFO_STANDARD);
-       p += 6;
-       p += clistr_push(cli, p, fname, nlen, STR_TERMINATE);
-       param_len = PTR_DIFF(p, param);
+       state->cli = cli;
+       subreq = cli_qpathinfo_send(state, ev, cli, fname, SMB_INFO_STANDARD,
+                                   22, CLI_BUFFER_SIZE);
+       if (tevent_req_nomem(subreq, req)) {
+               return tevent_req_post(req, ev);
+       }
+       tevent_req_set_callback(subreq, cli_qpathinfo1_done, req);
+       return req;
+}
 
-       do {
-               ret = (cli_send_trans(cli, SMBtrans2,
-                                     NULL,           /* Name */
-                                     -1, 0,          /* fid, flags */
-                                     &setup, 1, 0,   /* setup, length, max */
-                                     param, param_len, 10, /* param, length, max */
-                                     NULL, data_len, cli->max_xmit /* data, length, max */
-                                     ) &&
-                      cli_receive_trans(cli, SMBtrans2,
-                                        &rparam, &rparam_len,
-                                        &rdata, &rdata_len));
-               if (!cli_is_dos_error(cli)) break;
-               if (!ret) {
-                       /* we need to work around a Win95 bug - sometimes
-                          it gives ERRSRV/ERRerror temprarily */
-                       uint8 eclass;
-                       uint32 ecode;
-                       cli_dos_error(cli, &eclass, &ecode);
-                       if (eclass != ERRSRV || ecode != ERRerror) break;
-                       smb_msleep(100);
-               }
-       } while (count-- && ret==False);
+static void cli_qpathinfo1_done(struct tevent_req *subreq)
+{
+       struct tevent_req *req = tevent_req_callback_data(
+               subreq, struct tevent_req);
+       struct cli_qpathinfo1_state *state = tevent_req_data(
+               req, struct cli_qpathinfo1_state);
+       NTSTATUS status;
+
+       status = cli_qpathinfo_recv(subreq, state, &state->data,
+                                   &state->num_data);
+       TALLOC_FREE(subreq);
+       if (!NT_STATUS_IS_OK(status)) {
+               tevent_req_nterror(req, status);
+               return;
+       }
+       tevent_req_done(req);
+}
 
-       SAFE_FREE(param);
-       if (!ret || !rdata || rdata_len < 22) {
-               return False;
+NTSTATUS cli_qpathinfo1_recv(struct tevent_req *req,
+                            time_t *change_time,
+                            time_t *access_time,
+                            time_t *write_time,
+                            off_t *size,
+                            uint16 *mode)
+{
+       struct cli_qpathinfo1_state *state = tevent_req_data(
+               req, struct cli_qpathinfo1_state);
+       NTSTATUS status;
+
+       time_t (*date_fn)(const void *buf, int serverzone);
+
+       if (tevent_req_is_nterror(req, &status)) {
+               return status;
        }
 
-       if (cli->win95) {
-               date_fn = cli_make_unix_date;
+       if (state->cli->win95) {
+               date_fn = make_unix_date;
        } else {
-               date_fn = cli_make_unix_date2;
+               date_fn = make_unix_date2;
        }
 
        if (change_time) {
-               *change_time = date_fn(cli, rdata+0);
+               *change_time = date_fn(state->data+0, smb1cli_conn_server_time_zone(state->cli->conn));
        }
        if (access_time) {
-               *access_time = date_fn(cli, rdata+4);
+               *access_time = date_fn(state->data+4, smb1cli_conn_server_time_zone(state->cli->conn));
        }
        if (write_time) {
-               *write_time = date_fn(cli, rdata+8);
+               *write_time = date_fn(state->data+8, smb1cli_conn_server_time_zone(state->cli->conn));
        }
        if (size) {
-               *size = IVAL(rdata, 12);
+               *size = IVAL(state->data, 12);
        }
        if (mode) {
-               *mode = SVAL(rdata,l1_attrFile);
+               *mode = SVAL(state->data, l1_attrFile);
        }
+       return NT_STATUS_OK;
+}
 
-       SAFE_FREE(rdata);
-       SAFE_FREE(rparam);
-       return True;
+NTSTATUS cli_qpathinfo1(struct cli_state *cli,
+                       const char *fname,
+                       time_t *change_time,
+                       time_t *access_time,
+                       time_t *write_time,
+                       off_t *size,
+                       uint16 *mode)
+{
+       TALLOC_CTX *frame = talloc_stackframe();
+       struct tevent_context *ev;
+       struct tevent_req *req;
+       NTSTATUS status = NT_STATUS_NO_MEMORY;
+
+       if (smbXcli_conn_has_async_calls(cli->conn)) {
+               /*
+                * Can't use sync call while an async call is in flight
+                */
+               status = NT_STATUS_INVALID_PARAMETER;
+               goto fail;
+       }
+       ev = samba_tevent_context_init(frame);
+       if (ev == NULL) {
+               goto fail;
+       }
+       req = cli_qpathinfo1_send(frame, ev, cli, fname);
+       if (req == NULL) {
+               goto fail;
+       }
+       if (!tevent_req_poll_ntstatus(req, ev, &status)) {
+               goto fail;
+       }
+       status = cli_qpathinfo1_recv(req, change_time, access_time,
+                                    write_time, size, mode);
+ fail:
+       TALLOC_FREE(frame);
+       return status;
 }
 
 /****************************************************************************
  Send a setpathinfo call.
 ****************************************************************************/
 
-bool cli_setpathinfo(struct cli_state *cli, const char *fname,
-                     time_t create_time,
-                     time_t access_time,
-                     time_t write_time,
-                     time_t change_time,
-                     uint16 mode)
+NTSTATUS cli_setpathinfo_basic(struct cli_state *cli, const char *fname,
+                              time_t create_time,
+                              time_t access_time,
+                              time_t write_time,
+                              time_t change_time,
+                              uint16 mode)
 {
        unsigned int data_len = 0;
-       unsigned int param_len = 0;
-       unsigned int rparam_len, rdata_len;
-       uint16 setup = TRANSACT2_SETPATHINFO;
-       char *param;
        char data[40];
-       char *rparam=NULL, *rdata=NULL;
-       int count=8;
-       bool ret;
        char *p;
-       size_t nlen = 2*(strlen(fname)+1);
-
-       param = SMB_MALLOC_ARRAY(char, 6+nlen+2);
-       if (!param) {
-               return false;
-       }
-       memset(param, '\0', 6);
-       memset(data, 0, sizeof(data));
-
-        p = param;
-
-        /* Add the information level */
-       SSVAL(p, 0, SMB_FILE_BASIC_INFORMATION);
-
-        /* Skip reserved */
-       p += 6;
-
-        /* Add the file name */
-       p += clistr_push(cli, p, fname, nlen, STR_TERMINATE);
-
-       param_len = PTR_DIFF(p, param);
 
         p = data;
 
@@ -691,172 +742,267 @@ bool cli_setpathinfo(struct cli_state *cli, const char *fname,
 
         data_len = PTR_DIFF(p, data);
 
-       do {
-               ret = (cli_send_trans(cli, SMBtrans2,
-                                     NULL,           /* Name */
-                                     -1, 0,          /* fid, flags */
-                                     &setup, 1, 0,   /* setup, length, max */
-                                     param, param_len, 10, /* param, length, max */
-                                     data, data_len, cli->max_xmit /* data, length, max */
-                                     ) &&
-                      cli_receive_trans(cli, SMBtrans2,
-                                        &rparam, &rparam_len,
-                                        &rdata, &rdata_len));
-               if (!cli_is_dos_error(cli)) break;
-               if (!ret) {
-                       /* we need to work around a Win95 bug - sometimes
-                          it gives ERRSRV/ERRerror temprarily */
-                       uint8 eclass;
-                       uint32 ecode;
-                       cli_dos_error(cli, &eclass, &ecode);
-                       if (eclass != ERRSRV || ecode != ERRerror) break;
-                       smb_msleep(100);
-               }
-       } while (count-- && ret==False);
-
-       SAFE_FREE(param);
-       if (!ret) {
-               return False;
-       }
-
-       SAFE_FREE(rdata);
-       SAFE_FREE(rparam);
-       return True;
+       return cli_setpathinfo(cli, SMB_FILE_BASIC_INFORMATION, fname,
+                              (uint8_t *)data, data_len);
 }
 
 /****************************************************************************
  Send a qpathinfo call with the SMB_QUERY_FILE_ALL_INFO info level.
 ****************************************************************************/
 
-bool cli_qpathinfo2(struct cli_state *cli, const char *fname,
-                   struct timespec *create_time,
-                    struct timespec *access_time,
-                    struct timespec *write_time,
-                   struct timespec *change_time,
-                    SMB_OFF_T *size, uint16 *mode,
-                   SMB_INO_T *ino)
+struct cli_qpathinfo2_state {
+       uint32_t num_data;
+       uint8_t *data;
+};
+
+static void cli_qpathinfo2_done(struct tevent_req *subreq);
+
+struct tevent_req *cli_qpathinfo2_send(TALLOC_CTX *mem_ctx,
+                                      struct tevent_context *ev,
+                                      struct cli_state *cli,
+                                      const char *fname)
 {
-       unsigned int data_len = 0;
-       unsigned int param_len = 0;
-       uint16 setup = TRANSACT2_QPATHINFO;
-       char *param;
-       char *rparam=NULL, *rdata=NULL;
-       char *p;
-       size_t nlen = 2*(strlen(fname)+1);
+       struct tevent_req *req = NULL, *subreq = NULL;
+       struct cli_qpathinfo2_state *state = NULL;
 
-       param = SMB_MALLOC_ARRAY(char, 6+nlen+2);
-       if (!param) {
-               return false;
+       req = tevent_req_create(mem_ctx, &state, struct cli_qpathinfo2_state);
+       if (req == NULL) {
+               return NULL;
        }
-       p = param;
-       memset(param, '\0', 6);
-       SSVAL(p, 0, SMB_QUERY_FILE_ALL_INFO);
-       p += 6;
-       p += clistr_push(cli, p, fname, nlen, STR_TERMINATE);
-
-       param_len = PTR_DIFF(p, param);
-
-       if (!cli_send_trans(cli, SMBtrans2,
-                            NULL,                         /* name */
-                            -1, 0,                        /* fid, flags */
-                            &setup, 1, 0,                 /* setup, length, max */
-                            param, param_len, 10,         /* param, length, max */
-                            NULL, data_len, cli->max_xmit /* data, length, max */
-                           )) {
-               SAFE_FREE(param);
-               return False;
+       subreq = cli_qpathinfo_send(state, ev, cli, fname,
+                                   SMB_QUERY_FILE_ALL_INFO,
+                                   68, CLI_BUFFER_SIZE);
+       if (tevent_req_nomem(subreq, req)) {
+               return tevent_req_post(req, ev);
        }
+       tevent_req_set_callback(subreq, cli_qpathinfo2_done, req);
+       return req;
+}
 
-       SAFE_FREE(param);
-       if (!cli_receive_trans(cli, SMBtrans2,
-                               &rparam, &param_len,
-                               &rdata, &data_len)) {
-               return False;
+static void cli_qpathinfo2_done(struct tevent_req *subreq)
+{
+       struct tevent_req *req = tevent_req_callback_data(
+               subreq, struct tevent_req);
+       struct cli_qpathinfo2_state *state = tevent_req_data(
+               req, struct cli_qpathinfo2_state);
+       NTSTATUS status;
+
+       status = cli_qpathinfo_recv(subreq, state, &state->data,
+                                   &state->num_data);
+       TALLOC_FREE(subreq);
+       if (!NT_STATUS_IS_OK(status)) {
+               tevent_req_nterror(req, status);
+               return;
        }
+       tevent_req_done(req);
+}
 
-       if (!rdata || data_len < 22) {
-               return False;
+NTSTATUS cli_qpathinfo2_recv(struct tevent_req *req,
+                            struct timespec *create_time,
+                            struct timespec *access_time,
+                            struct timespec *write_time,
+                            struct timespec *change_time,
+                            off_t *size, uint16 *mode,
+                            SMB_INO_T *ino)
+{
+       struct cli_qpathinfo2_state *state = tevent_req_data(
+               req, struct cli_qpathinfo2_state);
+       NTSTATUS status;
+
+       if (tevent_req_is_nterror(req, &status)) {
+               return status;
        }
 
        if (create_time) {
-                *create_time = interpret_long_date(rdata+0);
+                *create_time = interpret_long_date((char *)state->data+0);
        }
        if (access_time) {
-               *access_time = interpret_long_date(rdata+8);
+               *access_time = interpret_long_date((char *)state->data+8);
        }
        if (write_time) {
-               *write_time = interpret_long_date(rdata+16);
+               *write_time = interpret_long_date((char *)state->data+16);
        }
        if (change_time) {
-               *change_time = interpret_long_date(rdata+24);
+               *change_time = interpret_long_date((char *)state->data+24);
        }
        if (mode) {
-               *mode = SVAL(rdata, 32);
+               *mode = SVAL(state->data, 32);
        }
        if (size) {
-                *size = IVAL2_TO_SMB_BIG_UINT(rdata,48);
+                *size = IVAL2_TO_SMB_BIG_UINT(state->data,48);
        }
        if (ino) {
-               *ino = IVAL(rdata, 64);
+               *ino = IVAL(state->data, 64);
        }
+       return NT_STATUS_OK;
+}
 
-       SAFE_FREE(rdata);
-       SAFE_FREE(rparam);
-       return True;
+NTSTATUS cli_qpathinfo2(struct cli_state *cli, const char *fname,
+                       struct timespec *create_time,
+                       struct timespec *access_time,
+                       struct timespec *write_time,
+                       struct timespec *change_time,
+                       off_t *size, uint16 *mode,
+                       SMB_INO_T *ino)
+{
+       TALLOC_CTX *frame = NULL;
+       struct tevent_context *ev;
+       struct tevent_req *req;
+       NTSTATUS status = NT_STATUS_NO_MEMORY;
+
+       if (smbXcli_conn_protocol(cli->conn) >= PROTOCOL_SMB2_02) {
+               return cli_smb2_qpathinfo2(cli,
+                                       fname,
+                                       create_time,
+                                       access_time,
+                                       write_time,
+                                       change_time,
+                                       size,
+                                       mode,
+                                       ino);
+       }
+
+       frame = talloc_stackframe();
+
+       if (smbXcli_conn_has_async_calls(cli->conn)) {
+               /*
+                * Can't use sync call while an async call is in flight
+                */
+               status = NT_STATUS_INVALID_PARAMETER;
+               goto fail;
+       }
+       ev = samba_tevent_context_init(frame);
+       if (ev == NULL) {
+               goto fail;
+       }
+       req = cli_qpathinfo2_send(frame, ev, cli, fname);
+       if (req == NULL) {
+               goto fail;
+       }
+       if (!tevent_req_poll_ntstatus(req, ev, &status)) {
+               goto fail;
+       }
+       status = cli_qpathinfo2_recv(req, create_time, access_time,
+                                    write_time, change_time, size, mode, ino);
+ fail:
+       TALLOC_FREE(frame);
+       return status;
 }
 
 /****************************************************************************
  Get the stream info
 ****************************************************************************/
 
-bool cli_qpathinfo_streams(struct cli_state *cli, const char *fname,
-                          TALLOC_CTX *mem_ctx,
-                          unsigned int *pnum_streams,
-                          struct stream_struct **pstreams)
+struct cli_qpathinfo_streams_state {
+       uint32_t num_data;
+       uint8_t *data;
+};
+
+static void cli_qpathinfo_streams_done(struct tevent_req *subreq);
+
+struct tevent_req *cli_qpathinfo_streams_send(TALLOC_CTX *mem_ctx,
+                                             struct tevent_context *ev,
+                                             struct cli_state *cli,
+                                             const char *fname)
 {
-       unsigned int data_len = 0;
-       unsigned int param_len = 0;
-       uint16 setup = TRANSACT2_QPATHINFO;
-       char *param;
-       char *rparam=NULL, *rdata=NULL;
-       char *p;
-       unsigned int num_streams;
-       struct stream_struct *streams;
-       unsigned int ofs;
-       size_t namelen = 2*(strlen(fname)+1);
+       struct tevent_req *req = NULL, *subreq = NULL;
+       struct cli_qpathinfo_streams_state *state = NULL;
 
-       param = SMB_MALLOC_ARRAY(char, 6+namelen+2);
-       if (param == NULL) {
-               return false;
+       req = tevent_req_create(mem_ctx, &state,
+                               struct cli_qpathinfo_streams_state);
+       if (req == NULL) {
+               return NULL;
        }
-       p = param;
-       memset(p, 0, 6);
-       SSVAL(p, 0, SMB_FILE_STREAM_INFORMATION);
-       p += 6;
-       p += clistr_push(cli, p, fname, namelen, STR_TERMINATE);
-
-       param_len = PTR_DIFF(p, param);
-
-       if (!cli_send_trans(cli, SMBtrans2,
-                            NULL,                     /* name */
-                            -1, 0,                    /* fid, flags */
-                            &setup, 1, 0,             /* setup, len, max */
-                            param, param_len, 10,     /* param, len, max */
-                            NULL, data_len, cli->max_xmit /* data, len, max */
-                           )) {
-               return false;
+       subreq = cli_qpathinfo_send(state, ev, cli, fname,
+                                   SMB_FILE_STREAM_INFORMATION,
+                                   0, CLI_BUFFER_SIZE);
+       if (tevent_req_nomem(subreq, req)) {
+               return tevent_req_post(req, ev);
        }
+       tevent_req_set_callback(subreq, cli_qpathinfo_streams_done, req);
+       return req;
+}
 
-       if (!cli_receive_trans(cli, SMBtrans2,
-                               &rparam, &param_len,
-                               &rdata, &data_len)) {
-               return false;
+static void cli_qpathinfo_streams_done(struct tevent_req *subreq)
+{
+       struct tevent_req *req = tevent_req_callback_data(
+               subreq, struct tevent_req);
+       struct cli_qpathinfo_streams_state *state = tevent_req_data(
+               req, struct cli_qpathinfo_streams_state);
+       NTSTATUS status;
+
+       status = cli_qpathinfo_recv(subreq, state, &state->data,
+                                   &state->num_data);
+       TALLOC_FREE(subreq);
+       if (!NT_STATUS_IS_OK(status)) {
+               tevent_req_nterror(req, status);
+               return;
        }
+       tevent_req_done(req);
+}
 
-       if (!rdata) {
-               SAFE_FREE(rparam);
-               return false;
+NTSTATUS cli_qpathinfo_streams_recv(struct tevent_req *req,
+                                   TALLOC_CTX *mem_ctx,
+                                   unsigned int *pnum_streams,
+                                   struct stream_struct **pstreams)
+{
+       struct cli_qpathinfo_streams_state *state = tevent_req_data(
+                req, struct cli_qpathinfo_streams_state);
+        NTSTATUS status;
+
+       if (tevent_req_is_nterror(req, &status)) {
+               return status;
        }
+       if (!parse_streams_blob(mem_ctx, state->data, state->num_data,
+                               pnum_streams, pstreams)) {
+               return NT_STATUS_INVALID_NETWORK_RESPONSE;
+       }
+       return NT_STATUS_OK;
+}
+
+NTSTATUS cli_qpathinfo_streams(struct cli_state *cli, const char *fname,
+                              TALLOC_CTX *mem_ctx,
+                              unsigned int *pnum_streams,
+                              struct stream_struct **pstreams)
+{
+       TALLOC_CTX *frame = talloc_stackframe();
+       struct tevent_context *ev;
+       struct tevent_req *req;
+       NTSTATUS status = NT_STATUS_NO_MEMORY;
+
+       if (smbXcli_conn_has_async_calls(cli->conn)) {
+               /*
+                * Can't use sync call while an async call is in flight
+                */
+               status = NT_STATUS_INVALID_PARAMETER;
+               goto fail;
+       }
+       ev = samba_tevent_context_init(frame);
+       if (ev == NULL) {
+               goto fail;
+       }
+       req = cli_qpathinfo_streams_send(frame, ev, cli, fname);
+       if (req == NULL) {
+               goto fail;
+       }
+       if (!tevent_req_poll_ntstatus(req, ev, &status)) {
+               goto fail;
+       }
+       status = cli_qpathinfo_streams_recv(req, mem_ctx, pnum_streams,
+                                           pstreams);
+ fail:
+       TALLOC_FREE(frame);
+       return status;
+}
+
+bool parse_streams_blob(TALLOC_CTX *mem_ctx, const uint8_t *rdata,
+                              size_t data_len,
+                              unsigned int *pnum_streams,
+                              struct stream_struct **pstreams)
+{
+       unsigned int num_streams;
+       struct stream_struct *streams;
+       unsigned int ofs;
 
        num_streams = 0;
        streams = NULL;
@@ -864,12 +1010,12 @@ bool cli_qpathinfo_streams(struct cli_state *cli, const char *fname,
 
        while ((data_len > ofs) && (data_len - ofs >= 24)) {
                uint32_t nlen, len;
-               ssize_t size;
+               size_t size;
                void *vstr;
                struct stream_struct *tmp;
                uint8_t *tmp_buf;
 
-               tmp = TALLOC_REALLOC_ARRAY(mem_ctx, streams,
+               tmp = talloc_realloc(mem_ctx, streams,
                                           struct stream_struct,
                                           num_streams+1);
 
@@ -894,7 +1040,7 @@ bool cli_qpathinfo_streams(struct cli_state *cli, const char *fname,
                 * convert_string_talloc??
                 */
 
-               tmp_buf = TALLOC_ARRAY(streams, uint8_t, nlen+2);
+               tmp_buf = talloc_array(streams, uint8_t, nlen+2);
                if (tmp_buf == NULL) {
                        goto fail;
                }
@@ -903,14 +1049,14 @@ bool cli_qpathinfo_streams(struct cli_state *cli, const char *fname,
                tmp_buf[nlen] = 0;
                tmp_buf[nlen+1] = 0;
 
-               size = convert_string_talloc(streams, CH_UTF16, CH_UNIX,
-                                            tmp_buf, nlen+2, &vstr,
-                                            false);
-               TALLOC_FREE(tmp_buf);
-
-               if (size == -1) {
+               if (!convert_string_talloc(streams, CH_UTF16, CH_UNIX, tmp_buf,
+                                          nlen+2, &vstr, &size))
+               {
+                       TALLOC_FREE(tmp_buf);
                        goto fail;
                }
+
+               TALLOC_FREE(tmp_buf);
                streams[num_streams].name = (char *)vstr;
                num_streams++;
 
@@ -922,17 +1068,12 @@ bool cli_qpathinfo_streams(struct cli_state *cli, const char *fname,
                ofs += len;
        }
 
-       SAFE_FREE(rdata);
-       SAFE_FREE(rparam);
-
        *pnum_streams = num_streams;
        *pstreams = streams;
        return true;
 
  fail:
        TALLOC_FREE(streams);
-       SAFE_FREE(rdata);
-       SAFE_FREE(rparam);
        return false;
 }
 
@@ -940,101 +1081,90 @@ bool cli_qpathinfo_streams(struct cli_state *cli, const char *fname,
  Send a qfileinfo QUERY_FILE_NAME_INFO call.
 ****************************************************************************/
 
-bool cli_qfilename(struct cli_state *cli, int fnum, char *name, size_t namelen)
+NTSTATUS cli_qfilename(struct cli_state *cli, uint16_t fnum,
+                      TALLOC_CTX *mem_ctx, char **_name)
 {
-       unsigned int data_len = 0;
-       unsigned int param_len = 0;
-       uint16 setup = TRANSACT2_QFILEINFO;
-       char param[4];
-       char *rparam=NULL, *rdata=NULL;
-
-       param_len = 4;
-       SSVAL(param, 0, fnum);
-       SSVAL(param, 2, SMB_QUERY_FILE_NAME_INFO);
-
-       if (!cli_send_trans(cli, SMBtrans2,
-                            NULL,                         /* name */
-                            -1, 0,                        /* fid, flags */
-                            &setup, 1, 0,                 /* setup, length, max */
-                            param, param_len, 2,          /* param, length, max */
-                            NULL, data_len, cli->max_xmit /* data, length, max */
-                           )) {
-               return False;
+       uint16_t recv_flags2;
+       uint8_t *rdata;
+       uint32_t num_rdata;
+       NTSTATUS status;
+       char *name = NULL;
+       uint32_t namelen;
+
+       status = cli_qfileinfo(talloc_tos(), cli, fnum,
+                              SMB_QUERY_FILE_NAME_INFO,
+                              4, CLI_BUFFER_SIZE, &recv_flags2,
+                              &rdata, &num_rdata);
+       if (!NT_STATUS_IS_OK(status)) {
+               return status;
        }
 
-       if (!cli_receive_trans(cli, SMBtrans2,
-                               &rparam, &param_len,
-                               &rdata, &data_len)) {
-               return False;
+       namelen = IVAL(rdata, 0);
+       if (namelen > (num_rdata - 4)) {
+               TALLOC_FREE(rdata);
+               return NT_STATUS_INVALID_NETWORK_RESPONSE;
        }
 
-       if (!rdata || data_len < 4) {
-               return False;
+       clistr_pull_talloc(mem_ctx,
+                          (const char *)rdata,
+                          recv_flags2,
+                          &name,
+                          rdata + 4,
+                          namelen,
+                          STR_UNICODE);
+       if (name == NULL) {
+               status = map_nt_error_from_unix(errno);
+               TALLOC_FREE(rdata);
+               return status;
        }
 
-       clistr_pull(cli, name, rdata+4, namelen, IVAL(rdata, 0), STR_UNICODE);
-
-       return True;
+       *_name = name;
+       TALLOC_FREE(rdata);
+       return NT_STATUS_OK;
 }
 
 /****************************************************************************
  Send a qfileinfo call.
 ****************************************************************************/
 
-bool cli_qfileinfo(struct cli_state *cli, int fnum,
-                  uint16 *mode, SMB_OFF_T *size,
-                  struct timespec *create_time,
-                   struct timespec *access_time,
-                   struct timespec *write_time,
-                  struct timespec *change_time,
-                   SMB_INO_T *ino)
+NTSTATUS cli_qfileinfo_basic(struct cli_state *cli, uint16_t fnum,
+                            uint16 *mode, off_t *size,
+                            struct timespec *create_time,
+                            struct timespec *access_time,
+                            struct timespec *write_time,
+                            struct timespec *change_time,
+                            SMB_INO_T *ino)
 {
-       unsigned int data_len = 0;
-       unsigned int param_len = 0;
-       uint16 setup = TRANSACT2_QFILEINFO;
-       char param[4];
-       char *rparam=NULL, *rdata=NULL;
+       uint8_t *rdata;
+       uint32_t num_rdata;
+       NTSTATUS status;
 
        /* if its a win95 server then fail this - win95 totally screws it
           up */
-       if (cli->win95) return False;
-
-       param_len = 4;
-
-       SSVAL(param, 0, fnum);
-       SSVAL(param, 2, SMB_QUERY_FILE_ALL_INFO);
-
-       if (!cli_send_trans(cli, SMBtrans2,
-                            NULL,                         /* name */
-                            -1, 0,                        /* fid, flags */
-                            &setup, 1, 0,                 /* setup, length, max */
-                            param, param_len, 2,          /* param, length, max */
-                            NULL, data_len, cli->max_xmit /* data, length, max */
-                           )) {
-               return False;
-       }
-
-       if (!cli_receive_trans(cli, SMBtrans2,
-                               &rparam, &param_len,
-                               &rdata, &data_len)) {
-               return False;
+       if (cli->win95) {
+               return NT_STATUS_NOT_SUPPORTED;
        }
 
-       if (!rdata || data_len < 68) {
-               return False;
+       status = cli_qfileinfo(talloc_tos(), cli, fnum,
+                              SMB_QUERY_FILE_ALL_INFO,
+                              68, CLI_BUFFER_SIZE,
+                              NULL,
+                              &rdata, &num_rdata);
+       if (!NT_STATUS_IS_OK(status)) {
+               return status;
        }
 
        if (create_time) {
-               *create_time = interpret_long_date(rdata+0);
+               *create_time = interpret_long_date((char *)rdata+0);
        }
        if (access_time) {
-               *access_time = interpret_long_date(rdata+8);
+               *access_time = interpret_long_date((char *)rdata+8);
        }
        if (write_time) {
-               *write_time = interpret_long_date(rdata+16);
+               *write_time = interpret_long_date((char *)rdata+16);
        }
        if (change_time) {
-               *change_time = interpret_long_date(rdata+24);
+               *change_time = interpret_long_date((char *)rdata+24);
        }
        if (mode) {
                *mode = SVAL(rdata, 32);
@@ -1046,145 +1176,110 @@ bool cli_qfileinfo(struct cli_state *cli, int fnum,
                *ino = IVAL(rdata, 64);
        }
 
-       SAFE_FREE(rdata);
-       SAFE_FREE(rparam);
-       return True;
+       TALLOC_FREE(rdata);
+       return NT_STATUS_OK;
 }
 
 /****************************************************************************
  Send a qpathinfo BASIC_INFO call.
 ****************************************************************************/
 
-bool cli_qpathinfo_basic( struct cli_state *cli, const char *name,
-                          SMB_STRUCT_STAT *sbuf, uint32 *attributes )
-{
-       unsigned int param_len = 0;
-       unsigned int data_len = 0;
-       uint16 setup = TRANSACT2_QPATHINFO;
-       char *param;
-       char *rparam=NULL, *rdata=NULL;
-       char *p;
-       char *path;
-       int len;
-       size_t nlen;
-       TALLOC_CTX *frame = talloc_stackframe();
+struct cli_qpathinfo_basic_state {
+       uint32_t num_data;
+       uint8_t *data;
+};
 
-       path = talloc_strdup(frame, name);
-       if (!path) {
-               TALLOC_FREE(frame);
-               return false;
-       }
-       /* cleanup */
+static void cli_qpathinfo_basic_done(struct tevent_req *subreq);
 
-       len = strlen(path);
-       if ( path[len-1] == '\\' || path[len-1] == '/') {
-               path[len-1] = '\0';
-       }
-       nlen = 2*(strlen(path)+1);
+struct tevent_req *cli_qpathinfo_basic_send(TALLOC_CTX *mem_ctx,
+                                           struct tevent_context *ev,
+                                           struct cli_state *cli,
+                                           const char *fname)
+{
+       struct tevent_req *req = NULL, *subreq = NULL;
+       struct cli_qpathinfo_basic_state *state = NULL;
 
-       param = TALLOC_ARRAY(frame,char,6+nlen+2);
-       if (!param) {
-               return false;
+       req = tevent_req_create(mem_ctx, &state,
+                               struct cli_qpathinfo_basic_state);
+       if (req == NULL) {
+               return NULL;
        }
-       p = param;
-       memset(param, '\0', 6);
-
-       SSVAL(p, 0, SMB_QUERY_FILE_BASIC_INFO);
-       p += 6;
-       p += clistr_push(cli, p, path, nlen, STR_TERMINATE);
-       param_len = PTR_DIFF(p, param);
-
-
-       if (!cli_send_trans(cli, SMBtrans2,
-                       NULL,                        /* name */
-                       -1, 0,                       /* fid, flags */
-                       &setup, 1, 0,                /* setup, length, max */
-                       param, param_len, 2,         /* param, length, max */
-                       NULL,  0, cli->max_xmit      /* data, length, max */
-                       )) {
-               TALLOC_FREE(frame);
-               return False;
-       }
-
-       TALLOC_FREE(frame);
-
-       if (!cli_receive_trans(cli, SMBtrans2,
-               &rparam, &param_len,
-               &rdata, &data_len)) {
-                       return False;
+       subreq = cli_qpathinfo_send(state, ev, cli, fname,
+                                   SMB_QUERY_FILE_BASIC_INFO,
+                                   36, CLI_BUFFER_SIZE);
+       if (tevent_req_nomem(subreq, req)) {
+               return tevent_req_post(req, ev);
        }
+       tevent_req_set_callback(subreq, cli_qpathinfo_basic_done, req);
+       return req;
+}
 
-       if (data_len < 36) {
-               SAFE_FREE(rdata);
-               SAFE_FREE(rparam);
-               return False;
+static void cli_qpathinfo_basic_done(struct tevent_req *subreq)
+{
+       struct tevent_req *req = tevent_req_callback_data(
+               subreq, struct tevent_req);
+       struct cli_qpathinfo_basic_state *state = tevent_req_data(
+               req, struct cli_qpathinfo_basic_state);
+       NTSTATUS status;
+
+       status = cli_qpathinfo_recv(subreq, state, &state->data,
+                                   &state->num_data);
+       TALLOC_FREE(subreq);
+       if (!NT_STATUS_IS_OK(status)) {
+               tevent_req_nterror(req, status);
+               return;
        }
-
-       set_atimespec(sbuf, interpret_long_date( rdata+8 )); /* Access time. */
-       set_mtimespec(sbuf, interpret_long_date( rdata+16 )); /* Write time. */
-       set_ctimespec(sbuf, interpret_long_date( rdata+24 )); /* Change time. */
-
-       *attributes = IVAL( rdata, 32 );
-
-       SAFE_FREE(rparam);
-       SAFE_FREE(rdata);
-
-       return True;
+       tevent_req_done(req);
 }
 
-/****************************************************************************
- Send a qfileinfo call.
-****************************************************************************/
-
-bool cli_qfileinfo_test(struct cli_state *cli, int fnum, int level, char **poutdata, uint32 *poutlen)
+NTSTATUS cli_qpathinfo_basic_recv(struct tevent_req *req,
+                                 SMB_STRUCT_STAT *sbuf, uint32 *attributes)
 {
-       unsigned int data_len = 0;
-       unsigned int param_len = 0;
-       uint16 setup = TRANSACT2_QFILEINFO;
-       char param[4];
-       char *rparam=NULL, *rdata=NULL;
-
-       *poutdata = NULL;
-       *poutlen = 0;
+       struct cli_qpathinfo_basic_state *state = tevent_req_data(
+               req, struct cli_qpathinfo_basic_state);
+       NTSTATUS status;
 
-       /* if its a win95 server then fail this - win95 totally screws it
-          up */
-       if (cli->win95)
-               return False;
+       if (tevent_req_is_nterror(req, &status)) {
+               return status;
+       }
 
-       param_len = 4;
+       sbuf->st_ex_atime = interpret_long_date((char *)state->data+8);
+       sbuf->st_ex_mtime = interpret_long_date((char *)state->data+16);
+       sbuf->st_ex_ctime = interpret_long_date((char *)state->data+24);
+       *attributes = IVAL(state->data, 32);
+       return NT_STATUS_OK;
+}
 
-       SSVAL(param, 0, fnum);
-       SSVAL(param, 2, level);
+NTSTATUS cli_qpathinfo_basic(struct cli_state *cli, const char *name,
+                            SMB_STRUCT_STAT *sbuf, uint32 *attributes)
+{
+       TALLOC_CTX *frame = talloc_stackframe();
+       struct tevent_context *ev;
+       struct tevent_req *req;
+       NTSTATUS status = NT_STATUS_NO_MEMORY;
 
-       if (!cli_send_trans(cli, SMBtrans2,
-                            NULL,                           /* name */
-                            -1, 0,                          /* fid, flags */
-                            &setup, 1, 0,                   /* setup, length, max */
-                            param, param_len, 2,            /* param, length, max */
-                            NULL, data_len, cli->max_xmit   /* data, length, max */
-                           )) {
-               return False;
+       if (smbXcli_conn_has_async_calls(cli->conn)) {
+               /*
+                * Can't use sync call while an async call is in flight
+                */
+               status = NT_STATUS_INVALID_PARAMETER;
+               goto fail;
        }
-
-       if (!cli_receive_trans(cli, SMBtrans2,
-                               &rparam, &param_len,
-                               &rdata, &data_len)) {
-               return False;
+       ev = samba_tevent_context_init(frame);
+       if (ev == NULL) {
+               goto fail;
        }
-
-       *poutdata = (char *)memdup(rdata, data_len);
-       if (!*poutdata) {
-               SAFE_FREE(rdata);
-               SAFE_FREE(rparam);
-               return False;
+       req = cli_qpathinfo_basic_send(frame, ev, cli, name);
+       if (req == NULL) {
+               goto fail;
        }
-
-       *poutlen = data_len;
-
-       SAFE_FREE(rdata);
-       SAFE_FREE(rparam);
-       return True;
+       if (!tevent_req_poll_ntstatus(req, ev, &status)) {
+               goto fail;
+       }
+       status = cli_qpathinfo_basic_recv(req, sbuf, attributes);
+ fail:
+       TALLOC_FREE(frame);
+       return status;
 }
 
 /****************************************************************************
@@ -1193,66 +1288,40 @@ bool cli_qfileinfo_test(struct cli_state *cli, int fnum, int level, char **poutd
 
 NTSTATUS cli_qpathinfo_alt_name(struct cli_state *cli, const char *fname, fstring alt_name)
 {
-       unsigned int data_len = 0;
-       unsigned int param_len = 0;
-       uint16 setup = TRANSACT2_QPATHINFO;
-       char *param;
-       char *rparam=NULL, *rdata=NULL;
-       int count=8;
-       char *p;
-       bool ret;
+       uint8_t *rdata;
+       uint32_t num_rdata;
        unsigned int len;
-       size_t nlen = 2*(strlen(fname)+1);
-
-       param = SMB_MALLOC_ARRAY(char, 6+nlen+2);
-       if (!param) {
-               return NT_STATUS_NO_MEMORY;
-       }
-       p = param;
-       memset(param, '\0', 6);
-       SSVAL(p, 0, SMB_QUERY_FILE_ALT_NAME_INFO);
-       p += 6;
-       p += clistr_push(cli, p, fname, nlen, STR_TERMINATE);
-       param_len = PTR_DIFF(p, param);
-
-       do {
-               ret = (cli_send_trans(cli, SMBtrans2,
-                                     NULL,           /* Name */
-                                     -1, 0,          /* fid, flags */
-                                     &setup, 1, 0,   /* setup, length, max */
-                                     param, param_len, 10, /* param, length, max */
-                                     NULL, data_len, cli->max_xmit /* data, length, max */
-                                     ) &&
-                      cli_receive_trans(cli, SMBtrans2,
-                                        &rparam, &param_len,
-                                        &rdata, &data_len));
-               if (!ret && cli_is_dos_error(cli)) {
-                       /* we need to work around a Win95 bug - sometimes
-                          it gives ERRSRV/ERRerror temprarily */
-                       uint8 eclass;
-                       uint32 ecode;
-                       cli_dos_error(cli, &eclass, &ecode);
-                       if (eclass != ERRSRV || ecode != ERRerror) break;
-                       smb_msleep(100);
-               }
-       } while (count-- && ret==False);
-
-       SAFE_FREE(param);
-
-       if (!ret || !rdata || data_len < 4) {
-               return NT_STATUS_UNSUCCESSFUL;
+       char *converted = NULL;
+       size_t converted_size = 0;
+       NTSTATUS status;
+
+       status = cli_qpathinfo(talloc_tos(), cli, fname,
+                              SMB_QUERY_FILE_ALT_NAME_INFO,
+                              4, CLI_BUFFER_SIZE, &rdata, &num_rdata);
+       if (!NT_STATUS_IS_OK(status)) {
+               return status;
        }
 
        len = IVAL(rdata, 0);
 
-       if (len > data_len - 4) {
+       if (len > num_rdata - 4) {
                return NT_STATUS_INVALID_NETWORK_RESPONSE;
        }
 
-       clistr_pull(cli, alt_name, rdata+4, sizeof(fstring), len, STR_UNICODE);
+       /* The returned data is a pushed string, not raw data. */
+       if (!convert_string_talloc(talloc_tos(),
+                                  smbXcli_conn_use_unicode(cli->conn) ? CH_UTF16LE : CH_DOS,
+                                  CH_UNIX,
+                                  rdata + 4,
+                                  len,
+                                  &converted,
+                                  &converted_size)) {
+               return NT_STATUS_NO_MEMORY;
+       }
+       fstrcpy(alt_name, converted);
 
-       SAFE_FREE(rdata);
-       SAFE_FREE(rparam);
+       TALLOC_FREE(converted);
+       TALLOC_FREE(rdata);
 
        return NT_STATUS_OK;
 }