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"
25 /****************************************************************************
27 ****************************************************************************/
29 bool cli_api(struct cli_state *cli,
30 char *param, int prcnt, int mprcnt,
31 char *data, int drcnt, int mdrcnt,
32 char **rparam, unsigned int *rprcnt,
33 char **rdata, unsigned int *rdrcnt)
35 cli_send_trans(cli,SMBtrans,
36 PIPE_LANMAN, /* Name */
38 NULL,0,0, /* Setup, length, max */
39 param, prcnt, mprcnt, /* Params, length, max */
40 data, drcnt, mdrcnt /* Data, length, max */
43 return (cli_receive_trans(cli,SMBtrans,
48 /****************************************************************************
49 Perform a NetWkstaUserLogon.
50 ****************************************************************************/
52 bool cli_NetWkstaUserLogon(struct cli_state *cli,char *user, char *workstation)
57 unsigned int rdrcnt,rprcnt;
60 memset(param, 0, sizeof(param));
62 /* send a SMBtrans command with api NetWkstaUserLogon */
64 SSVAL(p,0,132); /* api number */
66 strlcpy(p,"OOWb54WrLh",sizeof(param)-PTR_DIFF(p,param));
67 p = skip_string(param,sizeof(param),p);
68 strlcpy(p,"WB21BWDWWDDDDDDDzzzD",sizeof(param)-PTR_DIFF(p,param));
69 p = skip_string(param,sizeof(param),p);
72 strlcpy(p,user,sizeof(param)-PTR_DIFF(p,param));
78 strlcpy(p, workstation,sizeof(param)-PTR_DIFF(p,param));
81 SSVAL(p, 0, CLI_BUFFER_SIZE);
83 SSVAL(p, 0, CLI_BUFFER_SIZE);
87 param, PTR_DIFF(p,param),1024, /* param, length, max */
88 NULL, 0, CLI_BUFFER_SIZE, /* data, length, max */
89 &rparam, &rprcnt, /* return params, return size */
90 &rdata, &rdrcnt /* return data, return size */
92 cli->rap_error = rparam? SVAL(rparam,0) : -1;
95 if (cli->rap_error == 0) {
96 DEBUG(4,("NetWkstaUserLogon success\n"));
97 cli->privileges = SVAL(p, 24);
98 /* The cli->eff_name field used to be set here
99 but it wasn't used anywhere else. */
101 DEBUG(1,("NetwkstaUserLogon gave error %d\n", cli->rap_error));
107 return (cli->rap_error == 0);
110 /****************************************************************************
111 Call a NetShareEnum - try and browse available connections on a host.
112 ****************************************************************************/
114 int cli_RNetShareEnum(struct cli_state *cli, void (*fn)(const char *, uint32, const char *, void *), void *state)
119 unsigned int rdrcnt,rprcnt;
123 /* now send a SMBtrans command with api RNetShareEnum */
125 SSVAL(p,0,0); /* api number */
127 strlcpy(p,"WrLeh",sizeof(param)-PTR_DIFF(p,param));
128 p = skip_string(param,sizeof(param),p);
129 strlcpy(p,"B13BWz",sizeof(param)-PTR_DIFF(p,param));
130 p = skip_string(param,sizeof(param),p);
133 * Win2k needs a *smaller* buffer than 0xFFFF here -
134 * it returns "out of server memory" with 0xFFFF !!! JRA.
140 param, PTR_DIFF(p,param), 1024, /* Param, length, maxlen */
141 NULL, 0, 0xFFE0, /* data, length, maxlen - Win2k needs a small buffer here too ! */
142 &rparam, &rprcnt, /* return params, length */
143 &rdata, &rdrcnt)) /* return data, length */
145 int res = rparam? SVAL(rparam,0) : -1;
147 if (res == 0 || res == ERRmoredata) {
148 int converter=SVAL(rparam,2);
150 char *rdata_end = rdata + rdrcnt;
152 count=SVAL(rparam,4);
155 for (i=0;i<count;i++,p+=20) {
163 TALLOC_CTX *frame = talloc_stackframe();
165 if (p + 20 > rdata_end) {
172 comment_offset = (IVAL(p,16) & 0xFFFF) - converter;
173 if (comment_offset < 0 ||
174 comment_offset > (int)rdrcnt) {
178 cmnt = comment_offset?(rdata+comment_offset):"";
180 /* Work out the comment length. */
181 for (p1 = cmnt, len = 0; *p1 &&
182 p1 < rdata_end; len++)
187 pull_string_talloc(frame,rdata,0,
188 &s1,sname,14,STR_ASCII);
189 pull_string_talloc(frame,rdata,0,
190 &s2,cmnt,len,STR_ASCII);
196 fn(s1, type, s2, state);
201 DEBUG(4,("NetShareEnum res=%d\n", res));
204 DEBUG(4,("NetShareEnum failed\n"));
213 /****************************************************************************
214 Call a NetServerEnum for the specified workgroup and servertype mask. This
215 function then calls the specified callback function for each name returned.
217 The callback function takes 4 arguments: the machine name, the server type,
218 the comment and a state pointer.
219 ****************************************************************************/
221 bool cli_NetServerEnum(struct cli_state *cli, char *workgroup, uint32 stype,
222 void (*fn)(const char *, uint32, const char *, void *),
227 char *rdata_end = NULL;
228 unsigned int rdrcnt,rprcnt;
233 uint32 func = RAP_NetServerEnum2;
234 char *last_entry = NULL;
239 errno = 0; /* reset */
242 * This may take more than one transaction, so we should loop until
243 * we no longer get a more data to process or we have all of the
247 /* send a SMBtrans command with api NetServerEnum */
249 SIVAL(p,0,func); /* api number */
251 /* Next time through we need to use the continue api */
252 func = RAP_NetServerEnum3;
255 strlcpy(p,"WrLehDOz", sizeof(param)-PTR_DIFF(p,param));
257 strlcpy(p,"WrLehDz", sizeof(param)-PTR_DIFF(p,param));
260 p = skip_string(param, sizeof(param), p);
261 strlcpy(p,"B16BBDz", sizeof(param)-PTR_DIFF(p,param));
263 p = skip_string(param, sizeof(param), p);
265 SSVAL(p,2,CLI_BUFFER_SIZE);
270 /* If we have more data, tell the server where
274 last_entry ? last_entry : workgroup,
275 sizeof(param) - PTR_DIFF(p,param) - 1,
276 STR_TERMINATE|STR_UPPER);
278 if (len == (size_t)-1) {
279 SAFE_FREE(last_entry);
285 param, PTR_DIFF(p,param), 8, /* params, length, max */
286 NULL, 0, CLI_BUFFER_SIZE, /* data, length, max */
287 &rparam, &rprcnt, /* return params, return size */
288 &rdata, &rdrcnt)) { /* return data, return size */
290 /* break out of the loop on error */
295 rdata_end = rdata + rdrcnt;
296 res = rparam ? SVAL(rparam,0) : -1;
298 if (res == 0 || res == ERRmoredata ||
299 (res != -1 && cli_errno(cli) == 0)) {
302 int converter=SVAL(rparam,2);
304 /* Get the number of items returned in this buffer */
305 count = SVAL(rparam, 4);
307 /* The next field contains the number of items left,
308 * including those returned in this buffer. So the
309 * first time through this should contain all of the
312 if (total_cnt == 0) {
313 total_cnt = SVAL(rparam, 6);
316 /* Keep track of how many we have read */
320 /* The last name in the previous NetServerEnum reply is
321 * sent back to server in the NetServerEnum3 request
322 * (last_entry). The next reply should repeat this entry
323 * as the first element. We have no proof that this is
324 * always true, but from traces that seems to be the
325 * behavior from Window Servers. So first lets do a lot
326 * of checking, just being paranoid. If the string
327 * matches then we already saw this entry so skip it.
329 * NOTE: sv1_name field must be null terminated and has
330 * a max size of 16 (NetBIOS Name).
332 if (last_entry && count && p &&
333 (strncmp(last_entry, p, 16) == 0)) {
334 count -= 1; /* Skip this entry */
335 return_cnt = -1; /* Not part of total, so don't count. */
336 p = rdata + 26; /* Skip the whole record */
339 for (i = 0; i < count; i++, p += 26) {
344 TALLOC_CTX *frame = talloc_stackframe();
346 if (p + 26 > rdata_end) {
352 comment_offset = (IVAL(p,22) & 0xFFFF)-converter;
353 cmnt = comment_offset?(rdata+comment_offset):"";
355 if (comment_offset < 0 || comment_offset > (int)rdrcnt) {
360 /* Work out the comment length. */
361 for (p1 = cmnt, len = 0; *p1 &&
362 p1 < rdata_end; len++)
368 stype = IVAL(p,18) & ~SV_TYPE_LOCAL_LIST_ONLY;
370 pull_string_talloc(frame,rdata,0,
371 &s1,sname,16,STR_ASCII);
372 pull_string_talloc(frame,rdata,0,
373 &s2,cmnt,len,STR_ASCII);
380 fn(s1, stype, s2, state);
384 /* We are done with the old last entry, so now we can free it */
386 SAFE_FREE(last_entry); /* This will set it to null */
389 /* We always make a copy of the last entry if we have one */
391 last_entry = smb_xstrdup(sname);
394 /* If we have more data, but no last entry then error out */
395 if (!last_entry && (res == ERRmoredata)) {
404 } while ((res == ERRmoredata) && (total_cnt > return_cnt));
408 SAFE_FREE(last_entry);
411 errno = cli_errno(cli);
414 /* this is a very special case, when the domain master for the
415 work group isn't part of the work group itself, there is something
421 return(return_cnt > 0);
424 /****************************************************************************
425 Send a SamOEMChangePassword command.
426 ****************************************************************************/
428 bool cli_oem_change_password(struct cli_state *cli, const char *user, const char *new_password,
429 const char *old_password)
432 unsigned char data[532];
434 unsigned char old_pw_hash[16];
435 unsigned char new_pw_hash[16];
436 unsigned int data_len;
437 unsigned int param_len = 0;
440 unsigned int rprcnt, rdrcnt;
442 if (strlen(user) >= sizeof(fstring)-1) {
443 DEBUG(0,("cli_oem_change_password: user name %s is too long.\n", user));
447 SSVAL(p,0,214); /* SamOEMChangePassword command. */
449 strlcpy(p, "zsT", sizeof(param)-PTR_DIFF(p,param));
450 p = skip_string(param,sizeof(param),p);
451 strlcpy(p, "B516B16", sizeof(param)-PTR_DIFF(p,param));
452 p = skip_string(param,sizeof(param),p);
453 strlcpy(p,user, sizeof(param)-PTR_DIFF(p,param));
454 p = skip_string(param,sizeof(param),p);
458 param_len = PTR_DIFF(p,param);
461 * Get the Lanman hash of the old password, we
462 * use this as the key to make_oem_passwd_hash().
464 E_deshash(old_password, old_pw_hash);
466 encode_pw_buffer(data, new_password, STR_ASCII);
468 #ifdef DEBUG_PASSWORD
469 DEBUG(100,("make_oem_passwd_hash\n"));
470 dump_data(100, data, 516);
472 arcfour_crypt( (unsigned char *)data, (unsigned char *)old_pw_hash, 516);
475 * Now place the old password hash in the data.
477 E_deshash(new_password, new_pw_hash);
479 E_old_pw_hash( new_pw_hash, old_pw_hash, (uchar *)&data[516]);
483 if (cli_send_trans(cli,SMBtrans,
484 PIPE_LANMAN, /* name */
485 0,0, /* fid, flags */
486 NULL,0,0, /* setup, length, max */
487 param,param_len,2, /* param, length, max */
488 (char *)data,data_len,0 /* data, length, max */
490 DEBUG(0,("cli_oem_change_password: Failed to send password change for user %s\n",
495 if (!cli_receive_trans(cli,SMBtrans,
498 DEBUG(0,("cli_oem_change_password: Failed to recieve reply to password change for user %s\n",
504 cli->rap_error = SVAL(rparam,0);
510 return (cli->rap_error == 0);
513 /****************************************************************************
514 Send a qpathinfo call.
515 ****************************************************************************/
517 bool cli_qpathinfo(struct cli_state *cli,
525 unsigned int data_len = 0;
526 unsigned int param_len = 0;
527 unsigned int rparam_len, rdata_len;
528 uint16 setup = TRANSACT2_QPATHINFO;
530 char *rparam=NULL, *rdata=NULL;
533 time_t (*date_fn)(struct cli_state *, const void *);
535 size_t nlen = 2*(strlen(fname)+1);
537 param = SMB_MALLOC_ARRAY(char, 6+nlen+2);
543 SSVAL(p, 0, SMB_INFO_STANDARD);
545 p += clistr_push(cli, p, fname, nlen, STR_TERMINATE);
546 param_len = PTR_DIFF(p, param);
549 ret = (cli_send_trans(cli, SMBtrans2,
551 -1, 0, /* fid, flags */
552 &setup, 1, 0, /* setup, length, max */
553 param, param_len, 10, /* param, length, max */
554 NULL, data_len, cli->max_xmit /* data, length, max */
556 cli_receive_trans(cli, SMBtrans2,
557 &rparam, &rparam_len,
558 &rdata, &rdata_len));
559 if (!cli_is_dos_error(cli)) break;
561 /* we need to work around a Win95 bug - sometimes
562 it gives ERRSRV/ERRerror temprarily */
565 cli_dos_error(cli, &eclass, &ecode);
566 if (eclass != ERRSRV || ecode != ERRerror) break;
569 } while (count-- && ret==False);
572 if (!ret || !rdata || rdata_len < 22) {
577 date_fn = cli_make_unix_date;
579 date_fn = cli_make_unix_date2;
583 *change_time = date_fn(cli, rdata+0);
586 *access_time = date_fn(cli, rdata+4);
589 *write_time = date_fn(cli, rdata+8);
592 *size = IVAL(rdata, 12);
595 *mode = SVAL(rdata,l1_attrFile);
603 /****************************************************************************
604 Send a setpathinfo call.
605 ****************************************************************************/
607 bool cli_setpathinfo(struct cli_state *cli, const char *fname,
614 unsigned int data_len = 0;
615 unsigned int param_len = 0;
616 unsigned int rparam_len, rdata_len;
617 uint16 setup = TRANSACT2_SETPATHINFO;
620 char *rparam=NULL, *rdata=NULL;
624 size_t nlen = 2*(strlen(fname)+1);
626 param = SMB_MALLOC_ARRAY(char, 6+nlen+2);
630 memset(param, '\0', 6);
631 memset(data, 0, sizeof(data));
635 /* Add the information level */
636 SSVAL(p, 0, SMB_FILE_BASIC_INFORMATION);
641 /* Add the file name */
642 p += clistr_push(cli, p, fname, nlen, STR_TERMINATE);
644 param_len = PTR_DIFF(p, param);
649 * Add the create, last access, modification, and status change times
651 put_long_date(p, create_time);
654 put_long_date(p, access_time);
657 put_long_date(p, write_time);
660 put_long_date(p, change_time);
671 data_len = PTR_DIFF(p, data);
674 ret = (cli_send_trans(cli, SMBtrans2,
676 -1, 0, /* fid, flags */
677 &setup, 1, 0, /* setup, length, max */
678 param, param_len, 10, /* param, length, max */
679 data, data_len, cli->max_xmit /* data, length, max */
681 cli_receive_trans(cli, SMBtrans2,
682 &rparam, &rparam_len,
683 &rdata, &rdata_len));
684 if (!cli_is_dos_error(cli)) break;
686 /* we need to work around a Win95 bug - sometimes
687 it gives ERRSRV/ERRerror temprarily */
690 cli_dos_error(cli, &eclass, &ecode);
691 if (eclass != ERRSRV || ecode != ERRerror) break;
694 } while (count-- && ret==False);
706 /****************************************************************************
707 Send a qpathinfo call with the SMB_QUERY_FILE_ALL_INFO info level.
708 ****************************************************************************/
710 bool cli_qpathinfo2(struct cli_state *cli, const char *fname,
711 struct timespec *create_time,
712 struct timespec *access_time,
713 struct timespec *write_time,
714 struct timespec *change_time,
715 SMB_OFF_T *size, uint16 *mode,
718 unsigned int data_len = 0;
719 unsigned int param_len = 0;
720 uint16 setup = TRANSACT2_QPATHINFO;
722 char *rparam=NULL, *rdata=NULL;
724 size_t nlen = 2*(strlen(fname)+1);
726 param = SMB_MALLOC_ARRAY(char, 6+nlen+2);
731 memset(param, '\0', 6);
732 SSVAL(p, 0, SMB_QUERY_FILE_ALL_INFO);
734 p += clistr_push(cli, p, fname, nlen, STR_TERMINATE);
736 param_len = PTR_DIFF(p, param);
738 if (!cli_send_trans(cli, SMBtrans2,
740 -1, 0, /* fid, flags */
741 &setup, 1, 0, /* setup, length, max */
742 param, param_len, 10, /* param, length, max */
743 NULL, data_len, cli->max_xmit /* data, length, max */
750 if (!cli_receive_trans(cli, SMBtrans2,
752 &rdata, &data_len)) {
756 if (!rdata || data_len < 22) {
761 *create_time = interpret_long_date(rdata+0);
764 *access_time = interpret_long_date(rdata+8);
767 *write_time = interpret_long_date(rdata+16);
770 *change_time = interpret_long_date(rdata+24);
773 *mode = SVAL(rdata, 32);
776 *size = IVAL2_TO_SMB_BIG_UINT(rdata,48);
779 *ino = IVAL(rdata, 64);
787 /****************************************************************************
789 ****************************************************************************/
791 bool cli_qpathinfo_streams(struct cli_state *cli, const char *fname,
793 unsigned int *pnum_streams,
794 struct stream_struct **pstreams)
796 unsigned int data_len = 0;
797 unsigned int param_len = 0;
798 uint16 setup = TRANSACT2_QPATHINFO;
800 char *rparam=NULL, *rdata=NULL;
802 unsigned int num_streams;
803 struct stream_struct *streams;
805 size_t namelen = 2*(strlen(fname)+1);
807 param = SMB_MALLOC_ARRAY(char, 6+namelen+2);
813 SSVAL(p, 0, SMB_FILE_STREAM_INFORMATION);
815 p += clistr_push(cli, p, fname, namelen, STR_TERMINATE);
817 param_len = PTR_DIFF(p, param);
819 if (!cli_send_trans(cli, SMBtrans2,
821 -1, 0, /* fid, flags */
822 &setup, 1, 0, /* setup, len, max */
823 param, param_len, 10, /* param, len, max */
824 NULL, data_len, cli->max_xmit /* data, len, max */
829 if (!cli_receive_trans(cli, SMBtrans2,
831 &rdata, &data_len)) {
844 while ((data_len > ofs) && (data_len - ofs >= 24)) {
848 struct stream_struct *tmp;
851 tmp = TALLOC_REALLOC_ARRAY(mem_ctx, streams,
852 struct stream_struct,
860 nlen = IVAL(rdata, ofs + 0x04);
862 streams[num_streams].size = IVAL_TO_SMB_OFF_T(
864 streams[num_streams].alloc_size = IVAL_TO_SMB_OFF_T(
867 if (nlen > data_len - (ofs + 24)) {
872 * We need to null-terminate src, how do I do this with
873 * convert_string_talloc??
876 tmp_buf = TALLOC_ARRAY(streams, uint8_t, nlen+2);
877 if (tmp_buf == NULL) {
881 memcpy(tmp_buf, rdata+ofs+24, nlen);
885 if (!convert_string_talloc(streams, CH_UTF16, CH_UNIX, tmp_buf,
886 nlen+2, &vstr, &size, false))
888 TALLOC_FREE(tmp_buf);
892 TALLOC_FREE(tmp_buf);
893 streams[num_streams].name = (char *)vstr;
896 len = IVAL(rdata, ofs);
897 if (len > data_len - ofs) {
907 *pnum_streams = num_streams;
912 TALLOC_FREE(streams);
918 /****************************************************************************
919 Send a qfileinfo QUERY_FILE_NAME_INFO call.
920 ****************************************************************************/
922 bool cli_qfilename(struct cli_state *cli, uint16_t fnum, char *name, size_t namelen)
924 unsigned int data_len = 0;
925 unsigned int param_len = 0;
926 uint16 setup = TRANSACT2_QFILEINFO;
928 char *rparam=NULL, *rdata=NULL;
931 SSVAL(param, 0, fnum);
932 SSVAL(param, 2, SMB_QUERY_FILE_NAME_INFO);
934 if (!cli_send_trans(cli, SMBtrans2,
936 -1, 0, /* fid, flags */
937 &setup, 1, 0, /* setup, length, max */
938 param, param_len, 2, /* param, length, max */
939 NULL, data_len, cli->max_xmit /* data, length, max */
944 if (!cli_receive_trans(cli, SMBtrans2,
946 &rdata, &data_len)) {
950 if (!rdata || data_len < 4) {
956 clistr_pull(cli->inbuf, name, rdata+4, namelen, IVAL(rdata, 0),
965 /****************************************************************************
966 Send a qfileinfo call.
967 ****************************************************************************/
969 bool cli_qfileinfo(struct cli_state *cli, uint16_t fnum,
970 uint16 *mode, SMB_OFF_T *size,
971 struct timespec *create_time,
972 struct timespec *access_time,
973 struct timespec *write_time,
974 struct timespec *change_time,
977 unsigned int data_len = 0;
978 unsigned int param_len = 0;
981 uint8_t *rparam=NULL, *rdata=NULL;
984 /* if its a win95 server then fail this - win95 totally screws it
986 if (cli->win95) return False;
990 SSVAL(param, 0, fnum);
991 SSVAL(param, 2, SMB_QUERY_FILE_ALL_INFO);
993 SSVAL(&setup, 0, TRANSACT2_QFILEINFO);
995 status = cli_trans(talloc_tos(), cli, SMBtrans2,
996 NULL, -1, 0, 0, /* name, fid, function, flags */
997 &setup, 1, 0, /* setup, length, max */
998 param, param_len, 2, /* param, length, max */
999 NULL, 0, MIN(cli->max_xmit, 0xffff), /* data, length, max */
1000 NULL, NULL, /* rsetup, length */
1001 &rparam, ¶m_len, /* rparam, length */
1004 if (!NT_STATUS_IS_OK(status)) {
1008 if (!rdata || data_len < 68) {
1013 *create_time = interpret_long_date((char *)rdata+0);
1016 *access_time = interpret_long_date((char *)rdata+8);
1019 *write_time = interpret_long_date((char *)rdata+16);
1022 *change_time = interpret_long_date((char *)rdata+24);
1025 *mode = SVAL(rdata, 32);
1028 *size = IVAL2_TO_SMB_BIG_UINT(rdata,48);
1031 *ino = IVAL(rdata, 64);
1035 TALLOC_FREE(rparam);
1039 /****************************************************************************
1040 Send a qpathinfo BASIC_INFO call.
1041 ****************************************************************************/
1043 bool cli_qpathinfo_basic( struct cli_state *cli, const char *name,
1044 SMB_STRUCT_STAT *sbuf, uint32 *attributes )
1046 unsigned int param_len = 0;
1047 unsigned int data_len = 0;
1048 uint16 setup = TRANSACT2_QPATHINFO;
1050 char *rparam=NULL, *rdata=NULL;
1055 TALLOC_CTX *frame = talloc_stackframe();
1057 path = talloc_strdup(frame, name);
1065 if ( path[len-1] == '\\' || path[len-1] == '/') {
1068 nlen = 2*(strlen(path)+1);
1070 param = TALLOC_ARRAY(frame,char,6+nlen+2);
1075 memset(param, '\0', 6);
1077 SSVAL(p, 0, SMB_QUERY_FILE_BASIC_INFO);
1079 p += clistr_push(cli, p, path, nlen, STR_TERMINATE);
1080 param_len = PTR_DIFF(p, param);
1083 if (!cli_send_trans(cli, SMBtrans2,
1085 -1, 0, /* fid, flags */
1086 &setup, 1, 0, /* setup, length, max */
1087 param, param_len, 2, /* param, length, max */
1088 NULL, 0, cli->max_xmit /* data, length, max */
1096 if (!cli_receive_trans(cli, SMBtrans2,
1097 &rparam, ¶m_len,
1098 &rdata, &data_len)) {
1102 if (data_len < 36) {
1108 set_atimespec(sbuf, interpret_long_date( rdata+8 )); /* Access time. */
1109 set_mtimespec(sbuf, interpret_long_date( rdata+16 )); /* Write time. */
1110 set_ctimespec(sbuf, interpret_long_date( rdata+24 )); /* Change time. */
1112 *attributes = IVAL( rdata, 32 );
1120 /****************************************************************************
1121 Send a qfileinfo call.
1122 ****************************************************************************/
1124 bool cli_qfileinfo_test(struct cli_state *cli, uint16_t fnum, int level, char **poutdata, uint32 *poutlen)
1126 unsigned int data_len = 0;
1127 unsigned int param_len = 0;
1128 uint16 setup = TRANSACT2_QFILEINFO;
1130 char *rparam=NULL, *rdata=NULL;
1135 /* if its a win95 server then fail this - win95 totally screws it
1142 SSVAL(param, 0, fnum);
1143 SSVAL(param, 2, level);
1145 if (!cli_send_trans(cli, SMBtrans2,
1147 -1, 0, /* fid, flags */
1148 &setup, 1, 0, /* setup, length, max */
1149 param, param_len, 2, /* param, length, max */
1150 NULL, data_len, cli->max_xmit /* data, length, max */
1155 if (!cli_receive_trans(cli, SMBtrans2,
1156 &rparam, ¶m_len,
1157 &rdata, &data_len)) {
1161 *poutdata = (char *)memdup(rdata, data_len);
1168 *poutlen = data_len;
1175 /****************************************************************************
1176 Send a qpathinfo SMB_QUERY_FILE_ALT_NAME_INFO call.
1177 ****************************************************************************/
1179 NTSTATUS cli_qpathinfo_alt_name(struct cli_state *cli, const char *fname, fstring alt_name)
1181 unsigned int data_len = 0;
1182 unsigned int param_len = 0;
1183 uint16 setup = TRANSACT2_QPATHINFO;
1185 char *rparam=NULL, *rdata=NULL;
1190 size_t nlen = 2*(strlen(fname)+1);
1192 param = SMB_MALLOC_ARRAY(char, 6+nlen+2);
1194 return NT_STATUS_NO_MEMORY;
1197 memset(param, '\0', 6);
1198 SSVAL(p, 0, SMB_QUERY_FILE_ALT_NAME_INFO);
1200 p += clistr_push(cli, p, fname, nlen, STR_TERMINATE);
1201 param_len = PTR_DIFF(p, param);
1204 ret = (cli_send_trans(cli, SMBtrans2,
1206 -1, 0, /* fid, flags */
1207 &setup, 1, 0, /* setup, length, max */
1208 param, param_len, 10, /* param, length, max */
1209 NULL, data_len, cli->max_xmit /* data, length, max */
1211 cli_receive_trans(cli, SMBtrans2,
1212 &rparam, ¶m_len,
1213 &rdata, &data_len));
1214 if (!ret && cli_is_dos_error(cli)) {
1215 /* we need to work around a Win95 bug - sometimes
1216 it gives ERRSRV/ERRerror temprarily */
1219 cli_dos_error(cli, &eclass, &ecode);
1220 if (eclass != ERRSRV || ecode != ERRerror) break;
1223 } while (count-- && ret==False);
1227 if (!ret || !rdata || data_len < 4) {
1228 return NT_STATUS_UNSUCCESSFUL;
1231 len = IVAL(rdata, 0);
1233 if (len > data_len - 4) {
1234 return NT_STATUS_INVALID_NETWORK_RESPONSE;
1237 clistr_pull(cli->inbuf, alt_name, rdata+4, sizeof(fstring), len,
1243 return NT_STATUS_OK;