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/>.
24 /****************************************************************************
26 ****************************************************************************/
28 bool cli_api(struct cli_state *cli,
29 char *param, int prcnt, int mprcnt,
30 char *data, int drcnt, int mdrcnt,
31 char **rparam, unsigned int *rprcnt,
32 char **rdata, unsigned int *rdrcnt)
34 cli_send_trans(cli,SMBtrans,
35 PIPE_LANMAN, /* Name */
37 NULL,0,0, /* Setup, length, max */
38 param, prcnt, mprcnt, /* Params, length, max */
39 data, drcnt, mdrcnt /* Data, length, max */
42 return (cli_receive_trans(cli,SMBtrans,
47 /****************************************************************************
48 Perform a NetWkstaUserLogon.
49 ****************************************************************************/
51 bool cli_NetWkstaUserLogon(struct cli_state *cli,char *user, char *workstation)
56 unsigned int rdrcnt,rprcnt;
59 memset(param, 0, sizeof(param));
61 /* send a SMBtrans command with api NetWkstaUserLogon */
63 SSVAL(p,0,132); /* api number */
65 strlcpy(p,"OOWb54WrLh",sizeof(param)-PTR_DIFF(p,param));
66 p = skip_string(param,sizeof(param),p);
67 strlcpy(p,"WB21BWDWWDDDDDDDzzzD",sizeof(param)-PTR_DIFF(p,param));
68 p = skip_string(param,sizeof(param),p);
71 strlcpy(p,user,sizeof(param)-PTR_DIFF(p,param));
77 strlcpy(p, workstation,sizeof(param)-PTR_DIFF(p,param));
80 SSVAL(p, 0, CLI_BUFFER_SIZE);
82 SSVAL(p, 0, CLI_BUFFER_SIZE);
86 param, PTR_DIFF(p,param),1024, /* param, length, max */
87 NULL, 0, CLI_BUFFER_SIZE, /* data, length, max */
88 &rparam, &rprcnt, /* return params, return size */
89 &rdata, &rdrcnt /* return data, return size */
91 cli->rap_error = rparam? SVAL(rparam,0) : -1;
94 if (cli->rap_error == 0) {
95 DEBUG(4,("NetWkstaUserLogon success\n"));
96 cli->privileges = SVAL(p, 24);
97 /* The cli->eff_name field used to be set here
98 but it wasn't used anywhere else. */
100 DEBUG(1,("NetwkstaUserLogon gave error %d\n", cli->rap_error));
106 return (cli->rap_error == 0);
109 /****************************************************************************
110 Call a NetShareEnum - try and browse available connections on a host.
111 ****************************************************************************/
113 int cli_RNetShareEnum(struct cli_state *cli, void (*fn)(const char *, uint32, const char *, void *), void *state)
118 unsigned int rdrcnt,rprcnt;
122 /* now send a SMBtrans command with api RNetShareEnum */
124 SSVAL(p,0,0); /* api number */
126 strlcpy(p,"WrLeh",sizeof(param)-PTR_DIFF(p,param));
127 p = skip_string(param,sizeof(param),p);
128 strlcpy(p,"B13BWz",sizeof(param)-PTR_DIFF(p,param));
129 p = skip_string(param,sizeof(param),p);
132 * Win2k needs a *smaller* buffer than 0xFFFF here -
133 * it returns "out of server memory" with 0xFFFF !!! JRA.
139 param, PTR_DIFF(p,param), 1024, /* Param, length, maxlen */
140 NULL, 0, 0xFFE0, /* data, length, maxlen - Win2k needs a small buffer here too ! */
141 &rparam, &rprcnt, /* return params, length */
142 &rdata, &rdrcnt)) /* return data, length */
144 int res = rparam? SVAL(rparam,0) : -1;
146 if (res == 0 || res == ERRmoredata) {
147 int converter=SVAL(rparam,2);
149 char *rdata_end = rdata + rdrcnt;
151 count=SVAL(rparam,4);
154 for (i=0;i<count;i++,p+=20) {
162 TALLOC_CTX *frame = talloc_stackframe();
164 if (p + 20 > rdata_end) {
171 comment_offset = (IVAL(p,16) & 0xFFFF) - converter;
172 if (comment_offset < 0 ||
173 comment_offset > (int)rdrcnt) {
177 cmnt = comment_offset?(rdata+comment_offset):"";
179 /* Work out the comment length. */
180 for (p1 = cmnt, len = 0; *p1 &&
181 p1 < rdata_end; len++)
186 pull_string_talloc(frame,rdata,0,
187 &s1,sname,14,STR_ASCII);
188 pull_string_talloc(frame,rdata,0,
189 &s2,cmnt,len,STR_ASCII);
195 fn(s1, type, s2, state);
200 DEBUG(4,("NetShareEnum res=%d\n", res));
203 DEBUG(4,("NetShareEnum failed\n"));
212 /****************************************************************************
213 Call a NetServerEnum for the specified workgroup and servertype mask. This
214 function then calls the specified callback function for each name returned.
216 The callback function takes 4 arguments: the machine name, the server type,
217 the comment and a state pointer.
218 ****************************************************************************/
220 bool cli_NetServerEnum(struct cli_state *cli, char *workgroup, uint32 stype,
221 void (*fn)(const char *, uint32, const char *, void *),
226 char *rdata_end = NULL;
227 unsigned int rdrcnt,rprcnt;
232 uint32 func = RAP_NetServerEnum2;
233 char *last_entry = NULL;
238 errno = 0; /* reset */
241 * This may take more than one transaction, so we should loop until
242 * we no longer get a more data to process or we have all of the
246 /* send a SMBtrans command with api NetServerEnum */
248 SIVAL(p,0,func); /* api number */
250 /* Next time through we need to use the continue api */
251 func = RAP_NetServerEnum3;
254 strlcpy(p,"WrLehDOz", 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
273 last_entry ? last_entry : workgroup,
274 sizeof(param) - PTR_DIFF(p,param) - 1,
275 STR_TERMINATE|STR_UPPER);
277 if (len == (size_t)-1) {
278 SAFE_FREE(last_entry);
284 param, PTR_DIFF(p,param), 8, /* params, length, max */
285 NULL, 0, CLI_BUFFER_SIZE, /* data, length, max */
286 &rparam, &rprcnt, /* return params, return size */
287 &rdata, &rdrcnt)) { /* return data, return size */
289 /* break out of the loop on error */
294 rdata_end = rdata + rdrcnt;
295 res = rparam ? SVAL(rparam,0) : -1;
297 if (res == 0 || res == ERRmoredata ||
298 (res != -1 && cli_errno(cli) == 0)) {
301 int converter=SVAL(rparam,2);
303 /* Get the number of items returned in this buffer */
304 count = SVAL(rparam, 4);
306 /* The next field contains the number of items left,
307 * including those returned in this buffer. So the
308 * first time through this should contain all of the
311 if (total_cnt == 0) {
312 total_cnt = SVAL(rparam, 6);
315 /* Keep track of how many we have read */
319 /* The last name in the previous NetServerEnum reply is
320 * sent back to server in the NetServerEnum3 request
321 * (last_entry). The next reply should repeat this entry
322 * as the first element. We have no proof that this is
323 * always true, but from traces that seems to be the
324 * behavior from Window Servers. So first lets do a lot
325 * of checking, just being paranoid. If the string
326 * matches then we already saw this entry so skip it.
328 * NOTE: sv1_name field must be null terminated and has
329 * a max size of 16 (NetBIOS Name).
331 if (last_entry && count && p &&
332 (strncmp(last_entry, p, 16) == 0)) {
333 count -= 1; /* Skip this entry */
334 return_cnt = -1; /* Not part of total, so don't count. */
335 p = rdata + 26; /* Skip the whole record */
338 for (i = 0; i < count; i++, p += 26) {
343 TALLOC_CTX *frame = talloc_stackframe();
345 if (p + 26 > rdata_end) {
351 comment_offset = (IVAL(p,22) & 0xFFFF)-converter;
352 cmnt = comment_offset?(rdata+comment_offset):"";
354 if (comment_offset < 0 || comment_offset > (int)rdrcnt) {
359 /* Work out the comment length. */
360 for (p1 = cmnt, len = 0; *p1 &&
361 p1 < rdata_end; len++)
367 stype = IVAL(p,18) & ~SV_TYPE_LOCAL_LIST_ONLY;
369 pull_string_talloc(frame,rdata,0,
370 &s1,sname,16,STR_ASCII);
371 pull_string_talloc(frame,rdata,0,
372 &s2,cmnt,len,STR_ASCII);
379 fn(s1, stype, s2, state);
383 /* We are done with the old last entry, so now we can free it */
385 SAFE_FREE(last_entry); /* This will set it to null */
388 /* We always make a copy of the last entry if we have one */
390 last_entry = smb_xstrdup(sname);
393 /* If we have more data, but no last entry then error out */
394 if (!last_entry && (res == ERRmoredata)) {
403 } while ((res == ERRmoredata) && (total_cnt > return_cnt));
407 SAFE_FREE(last_entry);
410 errno = cli_errno(cli);
413 /* this is a very special case, when the domain master for the
414 work group isn't part of the work group itself, there is something
420 return(return_cnt > 0);
423 /****************************************************************************
424 Send a SamOEMChangePassword command.
425 ****************************************************************************/
427 bool cli_oem_change_password(struct cli_state *cli, const char *user, const char *new_password,
428 const char *old_password)
431 unsigned char data[532];
433 unsigned char old_pw_hash[16];
434 unsigned char new_pw_hash[16];
435 unsigned int data_len;
436 unsigned int param_len = 0;
439 unsigned int rprcnt, rdrcnt;
441 if (strlen(user) >= sizeof(fstring)-1) {
442 DEBUG(0,("cli_oem_change_password: user name %s is too long.\n", user));
446 SSVAL(p,0,214); /* SamOEMChangePassword command. */
448 strlcpy(p, "zsT", sizeof(param)-PTR_DIFF(p,param));
449 p = skip_string(param,sizeof(param),p);
450 strlcpy(p, "B516B16", sizeof(param)-PTR_DIFF(p,param));
451 p = skip_string(param,sizeof(param),p);
452 strlcpy(p,user, sizeof(param)-PTR_DIFF(p,param));
453 p = skip_string(param,sizeof(param),p);
457 param_len = PTR_DIFF(p,param);
460 * Get the Lanman hash of the old password, we
461 * use this as the key to make_oem_passwd_hash().
463 E_deshash(old_password, old_pw_hash);
465 encode_pw_buffer(data, new_password, STR_ASCII);
467 #ifdef DEBUG_PASSWORD
468 DEBUG(100,("make_oem_passwd_hash\n"));
469 dump_data(100, data, 516);
471 SamOEMhash( (unsigned char *)data, (unsigned char *)old_pw_hash, 516);
474 * Now place the old password hash in the data.
476 E_deshash(new_password, new_pw_hash);
478 E_old_pw_hash( new_pw_hash, old_pw_hash, (uchar *)&data[516]);
482 if (cli_send_trans(cli,SMBtrans,
483 PIPE_LANMAN, /* name */
484 0,0, /* fid, flags */
485 NULL,0,0, /* setup, length, max */
486 param,param_len,2, /* param, length, max */
487 (char *)data,data_len,0 /* data, length, max */
489 DEBUG(0,("cli_oem_change_password: Failed to send password change for user %s\n",
494 if (!cli_receive_trans(cli,SMBtrans,
497 DEBUG(0,("cli_oem_change_password: Failed to recieve reply to password change for user %s\n",
503 cli->rap_error = SVAL(rparam,0);
509 return (cli->rap_error == 0);
512 /****************************************************************************
513 Send a qpathinfo call.
514 ****************************************************************************/
516 bool cli_qpathinfo(struct cli_state *cli,
524 unsigned int data_len = 0;
525 unsigned int param_len = 0;
526 unsigned int rparam_len, rdata_len;
527 uint16 setup = TRANSACT2_QPATHINFO;
529 char *rparam=NULL, *rdata=NULL;
532 time_t (*date_fn)(struct cli_state *, const void *);
534 size_t nlen = 2*(strlen(fname)+1);
536 param = SMB_MALLOC_ARRAY(char, 6+nlen+2);
542 SSVAL(p, 0, SMB_INFO_STANDARD);
544 p += clistr_push(cli, p, fname, nlen, STR_TERMINATE);
545 param_len = PTR_DIFF(p, param);
548 ret = (cli_send_trans(cli, SMBtrans2,
550 -1, 0, /* fid, flags */
551 &setup, 1, 0, /* setup, length, max */
552 param, param_len, 10, /* param, length, max */
553 NULL, data_len, cli->max_xmit /* data, length, max */
555 cli_receive_trans(cli, SMBtrans2,
556 &rparam, &rparam_len,
557 &rdata, &rdata_len));
558 if (!cli_is_dos_error(cli)) break;
560 /* we need to work around a Win95 bug - sometimes
561 it gives ERRSRV/ERRerror temprarily */
564 cli_dos_error(cli, &eclass, &ecode);
565 if (eclass != ERRSRV || ecode != ERRerror) break;
568 } while (count-- && ret==False);
571 if (!ret || !rdata || rdata_len < 22) {
576 date_fn = cli_make_unix_date;
578 date_fn = cli_make_unix_date2;
582 *change_time = date_fn(cli, rdata+0);
585 *access_time = date_fn(cli, rdata+4);
588 *write_time = date_fn(cli, rdata+8);
591 *size = IVAL(rdata, 12);
594 *mode = SVAL(rdata,l1_attrFile);
602 /****************************************************************************
603 Send a setpathinfo call.
604 ****************************************************************************/
606 bool cli_setpathinfo(struct cli_state *cli, const char *fname,
613 unsigned int data_len = 0;
614 unsigned int param_len = 0;
615 unsigned int rparam_len, rdata_len;
616 uint16 setup = TRANSACT2_SETPATHINFO;
619 char *rparam=NULL, *rdata=NULL;
623 size_t nlen = 2*(strlen(fname)+1);
625 param = SMB_MALLOC_ARRAY(char, 6+nlen+2);
629 memset(param, '\0', 6);
630 memset(data, 0, sizeof(data));
634 /* Add the information level */
635 SSVAL(p, 0, SMB_FILE_BASIC_INFORMATION);
640 /* Add the file name */
641 p += clistr_push(cli, p, fname, nlen, STR_TERMINATE);
643 param_len = PTR_DIFF(p, param);
648 * Add the create, last access, modification, and status change times
650 put_long_date(p, create_time);
653 put_long_date(p, access_time);
656 put_long_date(p, write_time);
659 put_long_date(p, change_time);
670 data_len = PTR_DIFF(p, data);
673 ret = (cli_send_trans(cli, SMBtrans2,
675 -1, 0, /* fid, flags */
676 &setup, 1, 0, /* setup, length, max */
677 param, param_len, 10, /* param, length, max */
678 data, data_len, cli->max_xmit /* data, length, max */
680 cli_receive_trans(cli, SMBtrans2,
681 &rparam, &rparam_len,
682 &rdata, &rdata_len));
683 if (!cli_is_dos_error(cli)) break;
685 /* we need to work around a Win95 bug - sometimes
686 it gives ERRSRV/ERRerror temprarily */
689 cli_dos_error(cli, &eclass, &ecode);
690 if (eclass != ERRSRV || ecode != ERRerror) break;
693 } while (count-- && ret==False);
705 /****************************************************************************
706 Send a qpathinfo call with the SMB_QUERY_FILE_ALL_INFO info level.
707 ****************************************************************************/
709 bool cli_qpathinfo2(struct cli_state *cli, const char *fname,
710 struct timespec *create_time,
711 struct timespec *access_time,
712 struct timespec *write_time,
713 struct timespec *change_time,
714 SMB_OFF_T *size, uint16 *mode,
717 unsigned int data_len = 0;
718 unsigned int param_len = 0;
719 uint16 setup = TRANSACT2_QPATHINFO;
721 char *rparam=NULL, *rdata=NULL;
723 size_t nlen = 2*(strlen(fname)+1);
725 param = SMB_MALLOC_ARRAY(char, 6+nlen+2);
730 memset(param, '\0', 6);
731 SSVAL(p, 0, SMB_QUERY_FILE_ALL_INFO);
733 p += clistr_push(cli, p, fname, nlen, STR_TERMINATE);
735 param_len = PTR_DIFF(p, param);
737 if (!cli_send_trans(cli, SMBtrans2,
739 -1, 0, /* fid, flags */
740 &setup, 1, 0, /* setup, length, max */
741 param, param_len, 10, /* param, length, max */
742 NULL, data_len, cli->max_xmit /* data, length, max */
749 if (!cli_receive_trans(cli, SMBtrans2,
751 &rdata, &data_len)) {
755 if (!rdata || data_len < 22) {
760 *create_time = interpret_long_date(rdata+0);
763 *access_time = interpret_long_date(rdata+8);
766 *write_time = interpret_long_date(rdata+16);
769 *change_time = interpret_long_date(rdata+24);
772 *mode = SVAL(rdata, 32);
775 *size = IVAL2_TO_SMB_BIG_UINT(rdata,48);
778 *ino = IVAL(rdata, 64);
786 /****************************************************************************
788 ****************************************************************************/
790 bool cli_qpathinfo_streams(struct cli_state *cli, const char *fname,
792 unsigned int *pnum_streams,
793 struct stream_struct **pstreams)
795 unsigned int data_len = 0;
796 unsigned int param_len = 0;
797 uint16 setup = TRANSACT2_QPATHINFO;
799 char *rparam=NULL, *rdata=NULL;
801 unsigned int num_streams;
802 struct stream_struct *streams;
804 size_t namelen = 2*(strlen(fname)+1);
806 param = SMB_MALLOC_ARRAY(char, 6+namelen+2);
812 SSVAL(p, 0, SMB_FILE_STREAM_INFORMATION);
814 p += clistr_push(cli, p, fname, namelen, STR_TERMINATE);
816 param_len = PTR_DIFF(p, param);
818 if (!cli_send_trans(cli, SMBtrans2,
820 -1, 0, /* fid, flags */
821 &setup, 1, 0, /* setup, len, max */
822 param, param_len, 10, /* param, len, max */
823 NULL, data_len, cli->max_xmit /* data, len, max */
828 if (!cli_receive_trans(cli, SMBtrans2,
830 &rdata, &data_len)) {
843 while ((data_len > ofs) && (data_len - ofs >= 24)) {
847 struct stream_struct *tmp;
850 tmp = TALLOC_REALLOC_ARRAY(mem_ctx, streams,
851 struct stream_struct,
859 nlen = IVAL(rdata, ofs + 0x04);
861 streams[num_streams].size = IVAL_TO_SMB_OFF_T(
863 streams[num_streams].alloc_size = IVAL_TO_SMB_OFF_T(
866 if (nlen > data_len - (ofs + 24)) {
871 * We need to null-terminate src, how do I do this with
872 * convert_string_talloc??
875 tmp_buf = TALLOC_ARRAY(streams, uint8_t, nlen+2);
876 if (tmp_buf == NULL) {
880 memcpy(tmp_buf, rdata+ofs+24, nlen);
884 if (!convert_string_talloc(streams, CH_UTF16, CH_UNIX, tmp_buf,
885 nlen+2, &vstr, &size, false))
887 TALLOC_FREE(tmp_buf);
891 TALLOC_FREE(tmp_buf);
892 streams[num_streams].name = (char *)vstr;
895 len = IVAL(rdata, ofs);
896 if (len > data_len - ofs) {
906 *pnum_streams = num_streams;
911 TALLOC_FREE(streams);
917 /****************************************************************************
918 Send a qfileinfo QUERY_FILE_NAME_INFO call.
919 ****************************************************************************/
921 bool cli_qfilename(struct cli_state *cli, int fnum, char *name, size_t namelen)
923 unsigned int data_len = 0;
924 unsigned int param_len = 0;
925 uint16 setup = TRANSACT2_QFILEINFO;
927 char *rparam=NULL, *rdata=NULL;
930 SSVAL(param, 0, fnum);
931 SSVAL(param, 2, SMB_QUERY_FILE_NAME_INFO);
933 if (!cli_send_trans(cli, SMBtrans2,
935 -1, 0, /* fid, flags */
936 &setup, 1, 0, /* setup, length, max */
937 param, param_len, 2, /* param, length, max */
938 NULL, data_len, cli->max_xmit /* data, length, max */
943 if (!cli_receive_trans(cli, SMBtrans2,
945 &rdata, &data_len)) {
949 if (!rdata || data_len < 4) {
955 clistr_pull(cli->inbuf, name, rdata+4, namelen, IVAL(rdata, 0),
964 /****************************************************************************
965 Send a qfileinfo call.
966 ****************************************************************************/
968 bool cli_qfileinfo(struct cli_state *cli, int fnum,
969 uint16 *mode, SMB_OFF_T *size,
970 struct timespec *create_time,
971 struct timespec *access_time,
972 struct timespec *write_time,
973 struct timespec *change_time,
976 unsigned int data_len = 0;
977 unsigned int param_len = 0;
980 uint8_t *rparam=NULL, *rdata=NULL;
983 /* if its a win95 server then fail this - win95 totally screws it
985 if (cli->win95) return False;
989 SSVAL(param, 0, fnum);
990 SSVAL(param, 2, SMB_QUERY_FILE_ALL_INFO);
992 SSVAL(&setup, 0, TRANSACT2_QFILEINFO);
994 status = cli_trans(talloc_tos(), cli, SMBtrans2,
995 NULL, -1, 0, 0, /* name, fid, function, flags */
996 &setup, 1, 0, /* setup, length, max */
997 param, param_len, 2, /* param, length, max */
998 NULL, 0, MIN(cli->max_xmit, 0xffff), /* data, length, max */
999 NULL, NULL, /* rsetup, length */
1000 &rparam, ¶m_len, /* rparam, length */
1003 if (!NT_STATUS_IS_OK(status)) {
1007 if (!rdata || data_len < 68) {
1012 *create_time = interpret_long_date((char *)rdata+0);
1015 *access_time = interpret_long_date((char *)rdata+8);
1018 *write_time = interpret_long_date((char *)rdata+16);
1021 *change_time = interpret_long_date((char *)rdata+24);
1024 *mode = SVAL(rdata, 32);
1027 *size = IVAL2_TO_SMB_BIG_UINT(rdata,48);
1030 *ino = IVAL(rdata, 64);
1034 TALLOC_FREE(rparam);
1038 /****************************************************************************
1039 Send a qpathinfo BASIC_INFO call.
1040 ****************************************************************************/
1042 bool cli_qpathinfo_basic( struct cli_state *cli, const char *name,
1043 SMB_STRUCT_STAT *sbuf, uint32 *attributes )
1045 unsigned int param_len = 0;
1046 unsigned int data_len = 0;
1047 uint16 setup = TRANSACT2_QPATHINFO;
1049 char *rparam=NULL, *rdata=NULL;
1054 TALLOC_CTX *frame = talloc_stackframe();
1056 path = talloc_strdup(frame, name);
1064 if ( path[len-1] == '\\' || path[len-1] == '/') {
1067 nlen = 2*(strlen(path)+1);
1069 param = TALLOC_ARRAY(frame,char,6+nlen+2);
1074 memset(param, '\0', 6);
1076 SSVAL(p, 0, SMB_QUERY_FILE_BASIC_INFO);
1078 p += clistr_push(cli, p, path, nlen, STR_TERMINATE);
1079 param_len = PTR_DIFF(p, param);
1082 if (!cli_send_trans(cli, SMBtrans2,
1084 -1, 0, /* fid, flags */
1085 &setup, 1, 0, /* setup, length, max */
1086 param, param_len, 2, /* param, length, max */
1087 NULL, 0, cli->max_xmit /* data, length, max */
1095 if (!cli_receive_trans(cli, SMBtrans2,
1096 &rparam, ¶m_len,
1097 &rdata, &data_len)) {
1101 if (data_len < 36) {
1107 set_atimespec(sbuf, interpret_long_date( rdata+8 )); /* Access time. */
1108 set_mtimespec(sbuf, interpret_long_date( rdata+16 )); /* Write time. */
1109 set_ctimespec(sbuf, interpret_long_date( rdata+24 )); /* Change time. */
1111 *attributes = IVAL( rdata, 32 );
1119 /****************************************************************************
1120 Send a qfileinfo call.
1121 ****************************************************************************/
1123 bool cli_qfileinfo_test(struct cli_state *cli, int fnum, int level, char **poutdata, uint32 *poutlen)
1125 unsigned int data_len = 0;
1126 unsigned int param_len = 0;
1127 uint16 setup = TRANSACT2_QFILEINFO;
1129 char *rparam=NULL, *rdata=NULL;
1134 /* if its a win95 server then fail this - win95 totally screws it
1141 SSVAL(param, 0, fnum);
1142 SSVAL(param, 2, level);
1144 if (!cli_send_trans(cli, SMBtrans2,
1146 -1, 0, /* fid, flags */
1147 &setup, 1, 0, /* setup, length, max */
1148 param, param_len, 2, /* param, length, max */
1149 NULL, data_len, cli->max_xmit /* data, length, max */
1154 if (!cli_receive_trans(cli, SMBtrans2,
1155 &rparam, ¶m_len,
1156 &rdata, &data_len)) {
1160 *poutdata = (char *)memdup(rdata, data_len);
1167 *poutlen = data_len;
1174 /****************************************************************************
1175 Send a qpathinfo SMB_QUERY_FILE_ALT_NAME_INFO call.
1176 ****************************************************************************/
1178 NTSTATUS cli_qpathinfo_alt_name(struct cli_state *cli, const char *fname, fstring alt_name)
1180 unsigned int data_len = 0;
1181 unsigned int param_len = 0;
1182 uint16 setup = TRANSACT2_QPATHINFO;
1184 char *rparam=NULL, *rdata=NULL;
1189 size_t nlen = 2*(strlen(fname)+1);
1191 param = SMB_MALLOC_ARRAY(char, 6+nlen+2);
1193 return NT_STATUS_NO_MEMORY;
1196 memset(param, '\0', 6);
1197 SSVAL(p, 0, SMB_QUERY_FILE_ALT_NAME_INFO);
1199 p += clistr_push(cli, p, fname, nlen, STR_TERMINATE);
1200 param_len = PTR_DIFF(p, param);
1203 ret = (cli_send_trans(cli, SMBtrans2,
1205 -1, 0, /* fid, flags */
1206 &setup, 1, 0, /* setup, length, max */
1207 param, param_len, 10, /* param, length, max */
1208 NULL, data_len, cli->max_xmit /* data, length, max */
1210 cli_receive_trans(cli, SMBtrans2,
1211 &rparam, ¶m_len,
1212 &rdata, &data_len));
1213 if (!ret && cli_is_dos_error(cli)) {
1214 /* we need to work around a Win95 bug - sometimes
1215 it gives ERRSRV/ERRerror temprarily */
1218 cli_dos_error(cli, &eclass, &ecode);
1219 if (eclass != ERRSRV || ecode != ERRerror) break;
1222 } while (count-- && ret==False);
1226 if (!ret || !rdata || data_len < 4) {
1227 return NT_STATUS_UNSUCCESSFUL;
1230 len = IVAL(rdata, 0);
1232 if (len > data_len - 4) {
1233 return NT_STATUS_INVALID_NETWORK_RESPONSE;
1236 clistr_pull(cli->inbuf, alt_name, rdata+4, sizeof(fstring), len,
1242 return NT_STATUS_OK;