2 Unix SMB/CIFS implementation.
4 Copyright (C) Andrew Tridgell 1994-1998
5 Copyright (C) Gerald (Jerry) Carter 2004
6 Copyright (C) James Peach 2007
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "../libcli/auth/libcli_auth.h"
24 #include "../librpc/gen_ndr/rap.h"
26 /****************************************************************************
28 ****************************************************************************/
30 bool cli_api(struct cli_state *cli,
31 char *param, int prcnt, int mprcnt,
32 char *data, int drcnt, int mdrcnt,
33 char **rparam, unsigned int *rprcnt,
34 char **rdata, unsigned int *rdrcnt)
36 cli_send_trans(cli,SMBtrans,
37 PIPE_LANMAN, /* Name */
39 NULL,0,0, /* Setup, length, max */
40 param, prcnt, mprcnt, /* Params, length, max */
41 data, drcnt, mdrcnt /* Data, length, max */
44 return (cli_receive_trans(cli,SMBtrans,
49 /****************************************************************************
50 Perform a NetWkstaUserLogon.
51 ****************************************************************************/
53 bool cli_NetWkstaUserLogon(struct cli_state *cli,char *user, char *workstation)
58 unsigned int rdrcnt,rprcnt;
61 memset(param, 0, sizeof(param));
63 /* send a SMBtrans command with api NetWkstaUserLogon */
65 SSVAL(p,0,132); /* api number */
67 strlcpy(p,"OOWb54WrLh",sizeof(param)-PTR_DIFF(p,param));
68 p = skip_string(param,sizeof(param),p);
69 strlcpy(p,"WB21BWDWWDDDDDDDzzzD",sizeof(param)-PTR_DIFF(p,param));
70 p = skip_string(param,sizeof(param),p);
73 strlcpy(p,user,sizeof(param)-PTR_DIFF(p,param));
79 strlcpy(p, workstation,sizeof(param)-PTR_DIFF(p,param));
82 SSVAL(p, 0, CLI_BUFFER_SIZE);
84 SSVAL(p, 0, CLI_BUFFER_SIZE);
88 param, PTR_DIFF(p,param),1024, /* param, length, max */
89 NULL, 0, CLI_BUFFER_SIZE, /* data, length, max */
90 &rparam, &rprcnt, /* return params, return size */
91 &rdata, &rdrcnt /* return data, return size */
93 cli->rap_error = rparam? SVAL(rparam,0) : -1;
96 if (cli->rap_error == 0) {
97 DEBUG(4,("NetWkstaUserLogon success\n"));
98 cli->privileges = SVAL(p, 24);
99 /* The cli->eff_name field used to be set here
100 but it wasn't used anywhere else. */
102 DEBUG(1,("NetwkstaUserLogon gave error %d\n", cli->rap_error));
108 return (cli->rap_error == 0);
111 /****************************************************************************
112 Call a NetShareEnum - try and browse available connections on a host.
113 ****************************************************************************/
115 int cli_RNetShareEnum(struct cli_state *cli, void (*fn)(const char *, uint32, const char *, void *), void *state)
120 unsigned int rdrcnt,rprcnt;
124 /* now send a SMBtrans command with api RNetShareEnum */
126 SSVAL(p,0,0); /* api number */
128 strlcpy(p,"WrLeh",sizeof(param)-PTR_DIFF(p,param));
129 p = skip_string(param,sizeof(param),p);
130 strlcpy(p,"B13BWz",sizeof(param)-PTR_DIFF(p,param));
131 p = skip_string(param,sizeof(param),p);
134 * Win2k needs a *smaller* buffer than 0xFFFF here -
135 * it returns "out of server memory" with 0xFFFF !!! JRA.
141 param, PTR_DIFF(p,param), 1024, /* Param, length, maxlen */
142 NULL, 0, 0xFFE0, /* data, length, maxlen - Win2k needs a small buffer here too ! */
143 &rparam, &rprcnt, /* return params, length */
144 &rdata, &rdrcnt)) /* return data, length */
146 int res = rparam? SVAL(rparam,0) : -1;
148 if (res == 0 || res == ERRmoredata) {
149 int converter=SVAL(rparam,2);
151 char *rdata_end = rdata + rdrcnt;
153 count=SVAL(rparam,4);
156 for (i=0;i<count;i++,p+=20) {
164 TALLOC_CTX *frame = talloc_stackframe();
166 if (p + 20 > rdata_end) {
173 comment_offset = (IVAL(p,16) & 0xFFFF) - converter;
174 if (comment_offset < 0 ||
175 comment_offset > (int)rdrcnt) {
179 cmnt = comment_offset?(rdata+comment_offset):"";
181 /* Work out the comment length. */
182 for (p1 = cmnt, len = 0; *p1 &&
183 p1 < rdata_end; len++)
188 pull_string_talloc(frame,rdata,0,
189 &s1,sname,14,STR_ASCII);
190 pull_string_talloc(frame,rdata,0,
191 &s2,cmnt,len,STR_ASCII);
197 fn(s1, type, s2, state);
202 DEBUG(4,("NetShareEnum res=%d\n", res));
205 DEBUG(4,("NetShareEnum failed\n"));
214 /****************************************************************************
215 Call a NetServerEnum for the specified workgroup and servertype mask. This
216 function then calls the specified callback function for each name returned.
218 The callback function takes 4 arguments: the machine name, the server type,
219 the comment and a state pointer.
220 ****************************************************************************/
222 bool cli_NetServerEnum(struct cli_state *cli, char *workgroup, uint32 stype,
223 void (*fn)(const char *, uint32, const char *, void *),
228 char *rdata_end = NULL;
229 unsigned int rdrcnt,rprcnt;
234 uint32 func = RAP_NetServerEnum2;
235 char *last_entry = NULL;
240 errno = 0; /* reset */
243 * This may take more than one transaction, so we should loop until
244 * we no longer get a more data to process or we have all of the
248 /* send a SMBtrans command with api NetServerEnum */
250 SIVAL(p,0,func); /* api number */
253 if (func == RAP_NetServerEnum3) {
254 strlcpy(p,"WrLehDzz", sizeof(param)-PTR_DIFF(p,param));
256 strlcpy(p,"WrLehDz", sizeof(param)-PTR_DIFF(p,param));
259 p = skip_string(param, sizeof(param), p);
260 strlcpy(p,"B16BBDz", sizeof(param)-PTR_DIFF(p,param));
262 p = skip_string(param, sizeof(param), p);
264 SSVAL(p,2,CLI_BUFFER_SIZE);
269 /* If we have more data, tell the server where
274 sizeof(param) - PTR_DIFF(p,param) - 1,
275 STR_TERMINATE|STR_UPPER);
277 if (len == (size_t)-1) {
278 SAFE_FREE(last_entry);
283 if (func == RAP_NetServerEnum3) {
285 last_entry ? last_entry : "",
286 sizeof(param) - PTR_DIFF(p,param) - 1,
289 if (len == (size_t)-1) {
290 SAFE_FREE(last_entry);
296 /* Next time through we need to use the continue api */
297 func = RAP_NetServerEnum3;
300 param, PTR_DIFF(p,param), 8, /* params, length, max */
301 NULL, 0, CLI_BUFFER_SIZE, /* data, length, max */
302 &rparam, &rprcnt, /* return params, return size */
303 &rdata, &rdrcnt)) { /* return data, return size */
305 /* break out of the loop on error */
310 rdata_end = rdata + rdrcnt;
311 res = rparam ? SVAL(rparam,0) : -1;
313 if (res == 0 || res == ERRmoredata ||
314 (res != -1 && cli_errno(cli) == 0)) {
317 int converter=SVAL(rparam,2);
319 /* Get the number of items returned in this buffer */
320 count = SVAL(rparam, 4);
322 /* The next field contains the number of items left,
323 * including those returned in this buffer. So the
324 * first time through this should contain all of the
327 if (total_cnt == 0) {
328 total_cnt = SVAL(rparam, 6);
331 /* Keep track of how many we have read */
335 /* The last name in the previous NetServerEnum reply is
336 * sent back to server in the NetServerEnum3 request
337 * (last_entry). The next reply should repeat this entry
338 * as the first element. We have no proof that this is
339 * always true, but from traces that seems to be the
340 * behavior from Window Servers. So first lets do a lot
341 * of checking, just being paranoid. If the string
342 * matches then we already saw this entry so skip it.
344 * NOTE: sv1_name field must be null terminated and has
345 * a max size of 16 (NetBIOS Name).
347 if (last_entry && count && p &&
348 (strncmp(last_entry, p, 16) == 0)) {
349 count -= 1; /* Skip this entry */
350 return_cnt = -1; /* Not part of total, so don't count. */
351 p = rdata + 26; /* Skip the whole record */
354 for (i = 0; i < count; i++, p += 26) {
359 TALLOC_CTX *frame = talloc_stackframe();
360 uint32_t entry_stype;
362 if (p + 26 > rdata_end) {
368 comment_offset = (IVAL(p,22) & 0xFFFF)-converter;
369 cmnt = comment_offset?(rdata+comment_offset):"";
371 if (comment_offset < 0 || comment_offset >= (int)rdrcnt) {
376 /* Work out the comment length. */
377 for (p1 = cmnt, len = 0; *p1 &&
378 p1 < rdata_end; len++)
384 entry_stype = IVAL(p,18) & ~SV_TYPE_LOCAL_LIST_ONLY;
386 pull_string_talloc(frame,rdata,0,
387 &s1,sname,16,STR_ASCII);
388 pull_string_talloc(frame,rdata,0,
389 &s2,cmnt,len,STR_ASCII);
396 fn(s1, entry_stype, s2, state);
400 /* We are done with the old last entry, so now we can free it */
402 SAFE_FREE(last_entry); /* This will set it to null */
405 /* We always make a copy of the last entry if we have one */
407 last_entry = smb_xstrdup(sname);
410 /* If we have more data, but no last entry then error out */
411 if (!last_entry && (res == ERRmoredata)) {
420 } while ((res == ERRmoredata) && (total_cnt > return_cnt));
424 SAFE_FREE(last_entry);
427 errno = cli_errno(cli);
430 /* this is a very special case, when the domain master for the
431 work group isn't part of the work group itself, there is something
437 return(return_cnt > 0);
440 /****************************************************************************
441 Send a SamOEMChangePassword command.
442 ****************************************************************************/
444 bool cli_oem_change_password(struct cli_state *cli, const char *user, const char *new_password,
445 const char *old_password)
448 unsigned char data[532];
450 unsigned char old_pw_hash[16];
451 unsigned char new_pw_hash[16];
452 unsigned int data_len;
453 unsigned int param_len = 0;
456 unsigned int rprcnt, rdrcnt;
458 if (strlen(user) >= sizeof(fstring)-1) {
459 DEBUG(0,("cli_oem_change_password: user name %s is too long.\n", user));
463 SSVAL(p,0,214); /* SamOEMChangePassword command. */
465 strlcpy(p, "zsT", sizeof(param)-PTR_DIFF(p,param));
466 p = skip_string(param,sizeof(param),p);
467 strlcpy(p, "B516B16", sizeof(param)-PTR_DIFF(p,param));
468 p = skip_string(param,sizeof(param),p);
469 strlcpy(p,user, sizeof(param)-PTR_DIFF(p,param));
470 p = skip_string(param,sizeof(param),p);
474 param_len = PTR_DIFF(p,param);
477 * Get the Lanman hash of the old password, we
478 * use this as the key to make_oem_passwd_hash().
480 E_deshash(old_password, old_pw_hash);
482 encode_pw_buffer(data, new_password, STR_ASCII);
484 #ifdef DEBUG_PASSWORD
485 DEBUG(100,("make_oem_passwd_hash\n"));
486 dump_data(100, data, 516);
488 arcfour_crypt( (unsigned char *)data, (unsigned char *)old_pw_hash, 516);
491 * Now place the old password hash in the data.
493 E_deshash(new_password, new_pw_hash);
495 E_old_pw_hash( new_pw_hash, old_pw_hash, (uchar *)&data[516]);
499 if (cli_send_trans(cli,SMBtrans,
500 PIPE_LANMAN, /* name */
501 0,0, /* fid, flags */
502 NULL,0,0, /* setup, length, max */
503 param,param_len,2, /* param, length, max */
504 (char *)data,data_len,0 /* data, length, max */
506 DEBUG(0,("cli_oem_change_password: Failed to send password change for user %s\n",
511 if (!cli_receive_trans(cli,SMBtrans,
514 DEBUG(0,("cli_oem_change_password: Failed to recieve reply to password change for user %s\n",
520 cli->rap_error = SVAL(rparam,0);
526 return (cli->rap_error == 0);
529 /****************************************************************************
530 Send a qpathinfo call.
531 ****************************************************************************/
533 bool cli_qpathinfo(struct cli_state *cli,
541 unsigned int data_len = 0;
542 unsigned int param_len = 0;
543 unsigned int rparam_len, rdata_len;
544 uint16 setup = TRANSACT2_QPATHINFO;
546 char *rparam=NULL, *rdata=NULL;
549 time_t (*date_fn)(struct cli_state *, const void *);
551 size_t nlen = 2*(strlen(fname)+1);
553 param = SMB_MALLOC_ARRAY(char, 6+nlen+2);
559 SSVAL(p, 0, SMB_INFO_STANDARD);
561 p += clistr_push(cli, p, fname, nlen, STR_TERMINATE);
562 param_len = PTR_DIFF(p, param);
565 ret = (cli_send_trans(cli, SMBtrans2,
567 -1, 0, /* fid, flags */
568 &setup, 1, 0, /* setup, length, max */
569 param, param_len, 10, /* param, length, max */
570 NULL, data_len, cli->max_xmit /* data, length, max */
572 cli_receive_trans(cli, SMBtrans2,
573 &rparam, &rparam_len,
574 &rdata, &rdata_len));
575 if (!cli_is_dos_error(cli)) break;
577 /* we need to work around a Win95 bug - sometimes
578 it gives ERRSRV/ERRerror temprarily */
581 cli_dos_error(cli, &eclass, &ecode);
582 if (eclass != ERRSRV || ecode != ERRerror) break;
585 } while (count-- && ret==False);
588 if (!ret || !rdata || rdata_len < 22) {
593 date_fn = cli_make_unix_date;
595 date_fn = cli_make_unix_date2;
599 *change_time = date_fn(cli, rdata+0);
602 *access_time = date_fn(cli, rdata+4);
605 *write_time = date_fn(cli, rdata+8);
608 *size = IVAL(rdata, 12);
611 *mode = SVAL(rdata,l1_attrFile);
619 /****************************************************************************
620 Send a setpathinfo call.
621 ****************************************************************************/
623 bool cli_setpathinfo(struct cli_state *cli, const char *fname,
630 unsigned int data_len = 0;
631 unsigned int param_len = 0;
632 unsigned int rparam_len, rdata_len;
633 uint16 setup = TRANSACT2_SETPATHINFO;
636 char *rparam=NULL, *rdata=NULL;
640 size_t nlen = 2*(strlen(fname)+1);
642 param = SMB_MALLOC_ARRAY(char, 6+nlen+2);
646 memset(param, '\0', 6);
647 memset(data, 0, sizeof(data));
651 /* Add the information level */
652 SSVAL(p, 0, SMB_FILE_BASIC_INFORMATION);
657 /* Add the file name */
658 p += clistr_push(cli, p, fname, nlen, STR_TERMINATE);
660 param_len = PTR_DIFF(p, param);
665 * Add the create, last access, modification, and status change times
667 put_long_date(p, create_time);
670 put_long_date(p, access_time);
673 put_long_date(p, write_time);
676 put_long_date(p, change_time);
687 data_len = PTR_DIFF(p, data);
690 ret = (cli_send_trans(cli, SMBtrans2,
692 -1, 0, /* fid, flags */
693 &setup, 1, 0, /* setup, length, max */
694 param, param_len, 10, /* param, length, max */
695 data, data_len, cli->max_xmit /* data, length, max */
697 cli_receive_trans(cli, SMBtrans2,
698 &rparam, &rparam_len,
699 &rdata, &rdata_len));
700 if (!cli_is_dos_error(cli)) break;
702 /* we need to work around a Win95 bug - sometimes
703 it gives ERRSRV/ERRerror temprarily */
706 cli_dos_error(cli, &eclass, &ecode);
707 if (eclass != ERRSRV || ecode != ERRerror) break;
710 } while (count-- && ret==False);
722 /****************************************************************************
723 Send a qpathinfo call with the SMB_QUERY_FILE_ALL_INFO info level.
724 ****************************************************************************/
726 bool cli_qpathinfo2(struct cli_state *cli, const char *fname,
727 struct timespec *create_time,
728 struct timespec *access_time,
729 struct timespec *write_time,
730 struct timespec *change_time,
731 SMB_OFF_T *size, uint16 *mode,
734 unsigned int data_len = 0;
735 unsigned int param_len = 0;
736 uint16 setup = TRANSACT2_QPATHINFO;
738 char *rparam=NULL, *rdata=NULL;
740 size_t nlen = 2*(strlen(fname)+1);
742 param = SMB_MALLOC_ARRAY(char, 6+nlen+2);
747 memset(param, '\0', 6);
748 SSVAL(p, 0, SMB_QUERY_FILE_ALL_INFO);
750 p += clistr_push(cli, p, fname, nlen, STR_TERMINATE);
752 param_len = PTR_DIFF(p, param);
754 if (!cli_send_trans(cli, SMBtrans2,
756 -1, 0, /* fid, flags */
757 &setup, 1, 0, /* setup, length, max */
758 param, param_len, 10, /* param, length, max */
759 NULL, data_len, cli->max_xmit /* data, length, max */
766 if (!cli_receive_trans(cli, SMBtrans2,
768 &rdata, &data_len)) {
772 if (!rdata || data_len < 22) {
777 *create_time = interpret_long_date(rdata+0);
780 *access_time = interpret_long_date(rdata+8);
783 *write_time = interpret_long_date(rdata+16);
786 *change_time = interpret_long_date(rdata+24);
789 *mode = SVAL(rdata, 32);
792 *size = IVAL2_TO_SMB_BIG_UINT(rdata,48);
795 *ino = IVAL(rdata, 64);
803 /****************************************************************************
805 ****************************************************************************/
807 bool cli_qpathinfo_streams(struct cli_state *cli, const char *fname,
809 unsigned int *pnum_streams,
810 struct stream_struct **pstreams)
812 unsigned int data_len = 0;
813 unsigned int param_len = 0;
814 uint16 setup = TRANSACT2_QPATHINFO;
816 char *rparam=NULL, *rdata=NULL;
818 unsigned int num_streams;
819 struct stream_struct *streams;
821 size_t namelen = 2*(strlen(fname)+1);
823 param = SMB_MALLOC_ARRAY(char, 6+namelen+2);
829 SSVAL(p, 0, SMB_FILE_STREAM_INFORMATION);
831 p += clistr_push(cli, p, fname, namelen, STR_TERMINATE);
833 param_len = PTR_DIFF(p, param);
835 if (!cli_send_trans(cli, SMBtrans2,
837 -1, 0, /* fid, flags */
838 &setup, 1, 0, /* setup, len, max */
839 param, param_len, 10, /* param, len, max */
840 NULL, data_len, cli->max_xmit /* data, len, max */
845 if (!cli_receive_trans(cli, SMBtrans2,
847 &rdata, &data_len)) {
860 while ((data_len > ofs) && (data_len - ofs >= 24)) {
864 struct stream_struct *tmp;
867 tmp = TALLOC_REALLOC_ARRAY(mem_ctx, streams,
868 struct stream_struct,
876 nlen = IVAL(rdata, ofs + 0x04);
878 streams[num_streams].size = IVAL_TO_SMB_OFF_T(
880 streams[num_streams].alloc_size = IVAL_TO_SMB_OFF_T(
883 if (nlen > data_len - (ofs + 24)) {
888 * We need to null-terminate src, how do I do this with
889 * convert_string_talloc??
892 tmp_buf = TALLOC_ARRAY(streams, uint8_t, nlen+2);
893 if (tmp_buf == NULL) {
897 memcpy(tmp_buf, rdata+ofs+24, nlen);
901 if (!convert_string_talloc(streams, CH_UTF16, CH_UNIX, tmp_buf,
902 nlen+2, &vstr, &size, false))
904 TALLOC_FREE(tmp_buf);
908 TALLOC_FREE(tmp_buf);
909 streams[num_streams].name = (char *)vstr;
912 len = IVAL(rdata, ofs);
913 if (len > data_len - ofs) {
923 *pnum_streams = num_streams;
928 TALLOC_FREE(streams);
934 /****************************************************************************
935 Send a qfileinfo QUERY_FILE_NAME_INFO call.
936 ****************************************************************************/
938 bool cli_qfilename(struct cli_state *cli, uint16_t fnum, char *name, size_t namelen)
940 unsigned int data_len = 0;
941 unsigned int param_len = 0;
942 uint16 setup = TRANSACT2_QFILEINFO;
944 char *rparam=NULL, *rdata=NULL;
947 SSVAL(param, 0, fnum);
948 SSVAL(param, 2, SMB_QUERY_FILE_NAME_INFO);
950 if (!cli_send_trans(cli, SMBtrans2,
952 -1, 0, /* fid, flags */
953 &setup, 1, 0, /* setup, length, max */
954 param, param_len, 2, /* param, length, max */
955 NULL, data_len, cli->max_xmit /* data, length, max */
960 if (!cli_receive_trans(cli, SMBtrans2,
962 &rdata, &data_len)) {
966 if (!rdata || data_len < 4) {
972 clistr_pull(cli->inbuf, name, rdata+4, namelen, IVAL(rdata, 0),
981 /****************************************************************************
982 Send a qfileinfo call.
983 ****************************************************************************/
985 bool cli_qfileinfo(struct cli_state *cli, uint16_t fnum,
986 uint16 *mode, SMB_OFF_T *size,
987 struct timespec *create_time,
988 struct timespec *access_time,
989 struct timespec *write_time,
990 struct timespec *change_time,
993 uint32_t data_len = 0;
999 /* if its a win95 server then fail this - win95 totally screws it
1001 if (cli->win95) return False;
1003 SSVAL(param, 0, fnum);
1004 SSVAL(param, 2, SMB_QUERY_FILE_ALL_INFO);
1006 SSVAL(&setup, 0, TRANSACT2_QFILEINFO);
1008 status = cli_trans(talloc_tos(), cli, SMBtrans2,
1009 NULL, -1, 0, 0, /* name, fid, function, flags */
1010 &setup, 1, 0, /* setup, length, max */
1011 param, 4, 2, /* param, length, max */
1012 NULL, 0, MIN(cli->max_xmit, 0xffff), /* data, length, max */
1013 NULL, 0, NULL, /* rsetup, length */
1014 NULL, 0, NULL, /* rparam, length */
1015 &rdata, 68, &data_len);
1017 if (!NT_STATUS_IS_OK(status)) {
1022 *create_time = interpret_long_date((char *)rdata+0);
1025 *access_time = interpret_long_date((char *)rdata+8);
1028 *write_time = interpret_long_date((char *)rdata+16);
1031 *change_time = interpret_long_date((char *)rdata+24);
1034 *mode = SVAL(rdata, 32);
1037 *size = IVAL2_TO_SMB_BIG_UINT(rdata,48);
1040 *ino = IVAL(rdata, 64);
1047 /****************************************************************************
1048 Send a qpathinfo BASIC_INFO call.
1049 ****************************************************************************/
1051 NTSTATUS cli_qpathinfo_basic(struct cli_state *cli, const char *name,
1052 SMB_STRUCT_STAT *sbuf, uint32 *attributes)
1054 unsigned int param_len = 0;
1057 uint8_t *param, *rdata;
1062 TALLOC_CTX *frame = talloc_stackframe();
1065 path = talloc_strdup(frame, name);
1068 return NT_STATUS_NO_MEMORY;
1073 if ( path[len-1] == '\\' || path[len-1] == '/') {
1076 nlen = 2*(strlen(path)+1);
1078 param = TALLOC_ARRAY(frame, uint8_t, 6+nlen+2);
1081 return NT_STATUS_NO_MEMORY;
1084 memset(param, '\0', 6);
1086 SSVAL(setup, 0, TRANSACT2_QPATHINFO);
1087 SSVAL(p, 0, SMB_QUERY_FILE_BASIC_INFO);
1089 p += clistr_push(cli, p, path, nlen, STR_TERMINATE);
1090 param_len = PTR_DIFF(p, param);
1092 status = cli_trans(talloc_tos(), cli, SMBtrans2, NULL, -1, 0, 0,
1094 param, param_len, 2,
1095 NULL, 0, cli->max_xmit,
1098 &rdata, 36, &rdata_len);
1099 if (!NT_STATUS_IS_OK(status)) {
1104 sbuf->st_ex_atime = interpret_long_date((char *)rdata+8);
1105 sbuf->st_ex_mtime = interpret_long_date((char *)rdata+16);
1106 sbuf->st_ex_ctime = interpret_long_date((char *)rdata+24);
1108 *attributes = IVAL( rdata, 32 );
1112 return NT_STATUS_OK;
1115 /****************************************************************************
1116 Send a qfileinfo call.
1117 ****************************************************************************/
1119 bool cli_qfileinfo_test(struct cli_state *cli, uint16_t fnum, int level, char **poutdata, uint32 *poutlen)
1121 unsigned int data_len = 0;
1122 unsigned int param_len = 0;
1123 uint16 setup = TRANSACT2_QFILEINFO;
1125 char *rparam=NULL, *rdata=NULL;
1130 /* if its a win95 server then fail this - win95 totally screws it
1137 SSVAL(param, 0, fnum);
1138 SSVAL(param, 2, level);
1140 if (!cli_send_trans(cli, SMBtrans2,
1142 -1, 0, /* fid, flags */
1143 &setup, 1, 0, /* setup, length, max */
1144 param, param_len, 2, /* param, length, max */
1145 NULL, data_len, cli->max_xmit /* data, length, max */
1150 if (!cli_receive_trans(cli, SMBtrans2,
1151 &rparam, ¶m_len,
1152 &rdata, &data_len)) {
1156 *poutdata = (char *)memdup(rdata, data_len);
1163 *poutlen = data_len;
1170 /****************************************************************************
1171 Send a qpathinfo SMB_QUERY_FILE_ALT_NAME_INFO call.
1172 ****************************************************************************/
1174 NTSTATUS cli_qpathinfo_alt_name(struct cli_state *cli, const char *fname, fstring alt_name)
1176 unsigned int data_len = 0;
1177 unsigned int param_len = 0;
1178 uint16 setup = TRANSACT2_QPATHINFO;
1180 char *rparam=NULL, *rdata=NULL;
1185 size_t nlen = 2*(strlen(fname)+1);
1187 param = SMB_MALLOC_ARRAY(char, 6+nlen+2);
1189 return NT_STATUS_NO_MEMORY;
1192 memset(param, '\0', 6);
1193 SSVAL(p, 0, SMB_QUERY_FILE_ALT_NAME_INFO);
1195 p += clistr_push(cli, p, fname, nlen, STR_TERMINATE);
1196 param_len = PTR_DIFF(p, param);
1199 ret = (cli_send_trans(cli, SMBtrans2,
1201 -1, 0, /* fid, flags */
1202 &setup, 1, 0, /* setup, length, max */
1203 param, param_len, 10, /* param, length, max */
1204 NULL, data_len, cli->max_xmit /* data, length, max */
1206 cli_receive_trans(cli, SMBtrans2,
1207 &rparam, ¶m_len,
1208 &rdata, &data_len));
1209 if (!ret && cli_is_dos_error(cli)) {
1210 /* we need to work around a Win95 bug - sometimes
1211 it gives ERRSRV/ERRerror temprarily */
1214 cli_dos_error(cli, &eclass, &ecode);
1215 if (eclass != ERRSRV || ecode != ERRerror) break;
1218 } while (count-- && ret==False);
1222 if (!ret || !rdata || data_len < 4) {
1223 return NT_STATUS_UNSUCCESSFUL;
1226 len = IVAL(rdata, 0);
1228 if (len > data_len - 4) {
1229 return NT_STATUS_INVALID_NETWORK_RESPONSE;
1232 clistr_pull(cli->inbuf, alt_name, rdata+4, sizeof(fstring), len,
1238 return NT_STATUS_OK;