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 /****************************************************************************
25 Call a remote api on an arbitrary pipe. takes param, data and setup buffers.
26 ****************************************************************************/
28 bool cli_api_pipe(struct cli_state *cli, const char *pipe_name,
29 uint16 *setup, uint32 setup_count, uint32 max_setup_count,
30 char *params, uint32 param_count, uint32 max_param_count,
31 char *data, uint32 data_count, uint32 max_data_count,
32 char **rparam, uint32 *rparam_count,
33 char **rdata, uint32 *rdata_count)
35 cli_send_trans(cli, SMBtrans,
38 setup, setup_count, max_setup_count,
39 params, param_count, max_param_count,
40 data, data_count, max_data_count);
42 return (cli_receive_trans(cli, SMBtrans,
43 rparam, (unsigned int *)rparam_count,
44 rdata, (unsigned int *)rdata_count));
47 /****************************************************************************
49 ****************************************************************************/
51 bool cli_api(struct cli_state *cli,
52 char *param, int prcnt, int mprcnt,
53 char *data, int drcnt, int mdrcnt,
54 char **rparam, unsigned int *rprcnt,
55 char **rdata, unsigned int *rdrcnt)
57 cli_send_trans(cli,SMBtrans,
58 PIPE_LANMAN, /* Name */
60 NULL,0,0, /* Setup, length, max */
61 param, prcnt, mprcnt, /* Params, length, max */
62 data, drcnt, mdrcnt /* Data, length, max */
65 return (cli_receive_trans(cli,SMBtrans,
70 /****************************************************************************
71 Perform a NetWkstaUserLogon.
72 ****************************************************************************/
74 bool cli_NetWkstaUserLogon(struct cli_state *cli,char *user, char *workstation)
79 unsigned int rdrcnt,rprcnt;
82 memset(param, 0, sizeof(param));
84 /* send a SMBtrans command with api NetWkstaUserLogon */
86 SSVAL(p,0,132); /* api number */
88 strlcpy(p,"OOWb54WrLh",sizeof(param)-PTR_DIFF(p,param));
89 p = skip_string(param,sizeof(param),p);
90 strlcpy(p,"WB21BWDWWDDDDDDDzzzD",sizeof(param)-PTR_DIFF(p,param));
91 p = skip_string(param,sizeof(param),p);
94 strlcpy(p,user,sizeof(param)-PTR_DIFF(p,param));
100 strlcpy(p, workstation,sizeof(param)-PTR_DIFF(p,param));
103 SSVAL(p, 0, CLI_BUFFER_SIZE);
105 SSVAL(p, 0, CLI_BUFFER_SIZE);
109 param, PTR_DIFF(p,param),1024, /* param, length, max */
110 NULL, 0, CLI_BUFFER_SIZE, /* data, length, max */
111 &rparam, &rprcnt, /* return params, return size */
112 &rdata, &rdrcnt /* return data, return size */
114 cli->rap_error = rparam? SVAL(rparam,0) : -1;
117 if (cli->rap_error == 0) {
118 DEBUG(4,("NetWkstaUserLogon success\n"));
119 cli->privileges = SVAL(p, 24);
120 /* The cli->eff_name field used to be set here
121 but it wasn't used anywhere else. */
123 DEBUG(1,("NetwkstaUserLogon gave error %d\n", cli->rap_error));
129 return (cli->rap_error == 0);
132 /****************************************************************************
133 Call a NetShareEnum - try and browse available connections on a host.
134 ****************************************************************************/
136 int cli_RNetShareEnum(struct cli_state *cli, void (*fn)(const char *, uint32, const char *, void *), void *state)
141 unsigned int rdrcnt,rprcnt;
145 /* now send a SMBtrans command with api RNetShareEnum */
147 SSVAL(p,0,0); /* api number */
149 strlcpy(p,"WrLeh",sizeof(param)-PTR_DIFF(p,param));
150 p = skip_string(param,sizeof(param),p);
151 strlcpy(p,"B13BWz",sizeof(param)-PTR_DIFF(p,param));
152 p = skip_string(param,sizeof(param),p);
155 * Win2k needs a *smaller* buffer than 0xFFFF here -
156 * it returns "out of server memory" with 0xFFFF !!! JRA.
162 param, PTR_DIFF(p,param), 1024, /* Param, length, maxlen */
163 NULL, 0, 0xFFE0, /* data, length, maxlen - Win2k needs a small buffer here too ! */
164 &rparam, &rprcnt, /* return params, length */
165 &rdata, &rdrcnt)) /* return data, length */
167 int res = rparam? SVAL(rparam,0) : -1;
169 if (res == 0 || res == ERRmoredata) {
170 int converter=SVAL(rparam,2);
172 char *rdata_end = rdata + rdrcnt;
174 count=SVAL(rparam,4);
177 for (i=0;i<count;i++,p+=20) {
185 TALLOC_CTX *frame = talloc_stackframe();
187 if (p + 20 > rdata_end) {
194 comment_offset = IVAL(p,16) & 0xFFFF;
195 if (comment_offset < 0 || comment_offset > (int)rdrcnt) {
199 cmnt = comment_offset?(rdata+comment_offset-converter):"";
201 /* Work out the comment length. */
202 for (p1 = cmnt, len = 0; *p1 &&
203 p1 < rdata_end; len++)
208 pull_string_talloc(frame,rdata,0,
209 &s1,sname,14,STR_ASCII);
210 pull_string_talloc(frame,rdata,0,
211 &s2,cmnt,len,STR_ASCII);
217 fn(s1, type, s2, state);
222 DEBUG(4,("NetShareEnum res=%d\n", res));
225 DEBUG(4,("NetShareEnum failed\n"));
234 /****************************************************************************
235 Call a NetServerEnum for the specified workgroup and servertype mask. This
236 function then calls the specified callback function for each name returned.
238 The callback function takes 4 arguments: the machine name, the server type,
239 the comment and a state pointer.
240 ****************************************************************************/
242 bool cli_NetServerEnum(struct cli_state *cli, char *workgroup, uint32 stype,
243 void (*fn)(const char *, uint32, const char *, void *),
248 char *rdata_end = NULL;
249 unsigned int rdrcnt,rprcnt;
254 uint32 func = RAP_NetServerEnum2;
255 char *last_entry = NULL;
260 errno = 0; /* reset */
263 * This may take more than one transaction, so we should loop until
264 * we no longer get a more data to process or we have all of the
268 /* send a SMBtrans command with api NetServerEnum */
270 SIVAL(p,0,func); /* api number */
272 /* Next time through we need to use the continue api */
273 func = RAP_NetServerEnum3;
276 strlcpy(p,"WrLehDOz", sizeof(param)-PTR_DIFF(p,param));
278 strlcpy(p,"WrLehDz", sizeof(param)-PTR_DIFF(p,param));
281 p = skip_string(param, sizeof(param), p);
282 strlcpy(p,"B16BBDz", sizeof(param)-PTR_DIFF(p,param));
284 p = skip_string(param, sizeof(param), p);
286 SSVAL(p,2,CLI_BUFFER_SIZE);
291 /* If we have more data, tell the server where
295 last_entry ? last_entry : workgroup,
296 sizeof(param) - PTR_DIFF(p,param) - 1,
297 STR_TERMINATE|STR_UPPER);
299 if (len == (size_t)-1) {
300 SAFE_FREE(last_entry);
306 param, PTR_DIFF(p,param), 8, /* params, length, max */
307 NULL, 0, CLI_BUFFER_SIZE, /* data, length, max */
308 &rparam, &rprcnt, /* return params, return size */
309 &rdata, &rdrcnt)) { /* return data, return size */
311 /* break out of the loop on error */
316 rdata_end = rdata + rdrcnt;
317 res = rparam ? SVAL(rparam,0) : -1;
319 if (res == 0 || res == ERRmoredata ||
320 (res != -1 && cli_errno(cli) == 0)) {
323 int converter=SVAL(rparam,2);
325 /* Get the number of items returned in this buffer */
326 count = SVAL(rparam, 4);
328 /* The next field contains the number of items left,
329 * including those returned in this buffer. So the
330 * first time through this should contain all of the
333 if (total_cnt == 0) {
334 total_cnt = SVAL(rparam, 6);
337 /* Keep track of how many we have read */
341 /* The last name in the previous NetServerEnum reply is
342 * sent back to server in the NetServerEnum3 request
343 * (last_entry). The next reply should repeat this entry
344 * as the first element. We have no proof that this is
345 * always true, but from traces that seems to be the
346 * behavior from Window Servers. So first lets do a lot
347 * of checking, just being paranoid. If the string
348 * matches then we already saw this entry so skip it.
350 * NOTE: sv1_name field must be null terminated and has
351 * a max size of 16 (NetBIOS Name).
353 if (last_entry && count && p &&
354 (strncmp(last_entry, p, 16) == 0)) {
355 count -= 1; /* Skip this entry */
356 return_cnt = -1; /* Not part of total, so don't count. */
357 p = rdata + 26; /* Skip the whole record */
360 for (i = 0; i < count; i++, p += 26) {
365 TALLOC_CTX *frame = talloc_stackframe();
367 if (p + 26 > rdata_end) {
373 comment_offset = (IVAL(p,22) & 0xFFFF)-converter;
374 cmnt = comment_offset?(rdata+comment_offset):"";
376 if (comment_offset < 0 || comment_offset > (int)rdrcnt) {
381 /* Work out the comment length. */
382 for (p1 = cmnt, len = 0; *p1 &&
383 p1 < rdata_end; len++)
389 stype = IVAL(p,18) & ~SV_TYPE_LOCAL_LIST_ONLY;
391 pull_string_talloc(frame,rdata,0,
392 &s1,sname,16,STR_ASCII);
393 pull_string_talloc(frame,rdata,0,
394 &s2,cmnt,len,STR_ASCII);
401 fn(s1, stype, s2, state);
405 /* We are done with the old last entry, so now we can free it */
407 SAFE_FREE(last_entry); /* This will set it to null */
410 /* We always make a copy of the last entry if we have one */
412 last_entry = smb_xstrdup(sname);
415 /* If we have more data, but no last entry then error out */
416 if (!last_entry && (res == ERRmoredata)) {
425 } while ((res == ERRmoredata) && (total_cnt > return_cnt));
429 SAFE_FREE(last_entry);
432 errno = cli_errno(cli);
435 /* this is a very special case, when the domain master for the
436 work group isn't part of the work group itself, there is something
442 return(return_cnt > 0);
445 /****************************************************************************
446 Send a SamOEMChangePassword command.
447 ****************************************************************************/
449 bool cli_oem_change_password(struct cli_state *cli, const char *user, const char *new_password,
450 const char *old_password)
453 unsigned char data[532];
455 unsigned char old_pw_hash[16];
456 unsigned char new_pw_hash[16];
457 unsigned int data_len;
458 unsigned int param_len = 0;
461 unsigned int rprcnt, rdrcnt;
463 if (strlen(user) >= sizeof(fstring)-1) {
464 DEBUG(0,("cli_oem_change_password: user name %s is too long.\n", user));
468 SSVAL(p,0,214); /* SamOEMChangePassword command. */
470 strlcpy(p, "zsT", sizeof(param)-PTR_DIFF(p,param));
471 p = skip_string(param,sizeof(param),p);
472 strlcpy(p, "B516B16", sizeof(param)-PTR_DIFF(p,param));
473 p = skip_string(param,sizeof(param),p);
474 strlcpy(p,user, sizeof(param)-PTR_DIFF(p,param));
475 p = skip_string(param,sizeof(param),p);
479 param_len = PTR_DIFF(p,param);
482 * Get the Lanman hash of the old password, we
483 * use this as the key to make_oem_passwd_hash().
485 E_deshash(old_password, old_pw_hash);
487 encode_pw_buffer(data, new_password, STR_ASCII);
489 #ifdef DEBUG_PASSWORD
490 DEBUG(100,("make_oem_passwd_hash\n"));
491 dump_data(100, data, 516);
493 SamOEMhash( (unsigned char *)data, (unsigned char *)old_pw_hash, 516);
496 * Now place the old password hash in the data.
498 E_deshash(new_password, new_pw_hash);
500 E_old_pw_hash( new_pw_hash, old_pw_hash, (uchar *)&data[516]);
504 if (cli_send_trans(cli,SMBtrans,
505 PIPE_LANMAN, /* name */
506 0,0, /* fid, flags */
507 NULL,0,0, /* setup, length, max */
508 param,param_len,2, /* param, length, max */
509 (char *)data,data_len,0 /* data, length, max */
511 DEBUG(0,("cli_oem_change_password: Failed to send password change for user %s\n",
516 if (!cli_receive_trans(cli,SMBtrans,
519 DEBUG(0,("cli_oem_change_password: Failed to recieve reply to password change for user %s\n",
525 cli->rap_error = SVAL(rparam,0);
531 return (cli->rap_error == 0);
534 /****************************************************************************
535 Send a qpathinfo call.
536 ****************************************************************************/
538 bool cli_qpathinfo(struct cli_state *cli,
546 unsigned int data_len = 0;
547 unsigned int param_len = 0;
548 unsigned int rparam_len, rdata_len;
549 uint16 setup = TRANSACT2_QPATHINFO;
551 char *rparam=NULL, *rdata=NULL;
554 time_t (*date_fn)(struct cli_state *, const void *);
556 size_t nlen = 2*(strlen(fname)+1);
558 param = SMB_MALLOC_ARRAY(char, 6+nlen+2);
564 SSVAL(p, 0, SMB_INFO_STANDARD);
566 p += clistr_push(cli, p, fname, nlen, STR_TERMINATE);
567 param_len = PTR_DIFF(p, param);
570 ret = (cli_send_trans(cli, SMBtrans2,
572 -1, 0, /* fid, flags */
573 &setup, 1, 0, /* setup, length, max */
574 param, param_len, 10, /* param, length, max */
575 NULL, data_len, cli->max_xmit /* data, length, max */
577 cli_receive_trans(cli, SMBtrans2,
578 &rparam, &rparam_len,
579 &rdata, &rdata_len));
580 if (!cli_is_dos_error(cli)) break;
582 /* we need to work around a Win95 bug - sometimes
583 it gives ERRSRV/ERRerror temprarily */
586 cli_dos_error(cli, &eclass, &ecode);
587 if (eclass != ERRSRV || ecode != ERRerror) break;
590 } while (count-- && ret==False);
593 if (!ret || !rdata || rdata_len < 22) {
598 date_fn = cli_make_unix_date;
600 date_fn = cli_make_unix_date2;
604 *change_time = date_fn(cli, rdata+0);
607 *access_time = date_fn(cli, rdata+4);
610 *write_time = date_fn(cli, rdata+8);
613 *size = IVAL(rdata, 12);
616 *mode = SVAL(rdata,l1_attrFile);
624 /****************************************************************************
625 Send a setpathinfo call.
626 ****************************************************************************/
628 bool cli_setpathinfo(struct cli_state *cli, const char *fname,
635 unsigned int data_len = 0;
636 unsigned int param_len = 0;
637 unsigned int rparam_len, rdata_len;
638 uint16 setup = TRANSACT2_SETPATHINFO;
641 char *rparam=NULL, *rdata=NULL;
645 size_t nlen = 2*(strlen(fname)+1);
647 param = SMB_MALLOC_ARRAY(char, 6+nlen+2);
651 memset(param, '\0', 6);
652 memset(data, 0, sizeof(data));
656 /* Add the information level */
657 SSVAL(p, 0, SMB_FILE_BASIC_INFORMATION);
662 /* Add the file name */
663 p += clistr_push(cli, p, fname, nlen, STR_TERMINATE);
665 param_len = PTR_DIFF(p, param);
670 * Add the create, last access, modification, and status change times
672 put_long_date(p, create_time);
675 put_long_date(p, access_time);
678 put_long_date(p, write_time);
681 put_long_date(p, change_time);
692 data_len = PTR_DIFF(p, data);
695 ret = (cli_send_trans(cli, SMBtrans2,
697 -1, 0, /* fid, flags */
698 &setup, 1, 0, /* setup, length, max */
699 param, param_len, 10, /* param, length, max */
700 data, data_len, cli->max_xmit /* data, length, max */
702 cli_receive_trans(cli, SMBtrans2,
703 &rparam, &rparam_len,
704 &rdata, &rdata_len));
705 if (!cli_is_dos_error(cli)) break;
707 /* we need to work around a Win95 bug - sometimes
708 it gives ERRSRV/ERRerror temprarily */
711 cli_dos_error(cli, &eclass, &ecode);
712 if (eclass != ERRSRV || ecode != ERRerror) break;
715 } while (count-- && ret==False);
727 /****************************************************************************
728 Send a qpathinfo call with the SMB_QUERY_FILE_ALL_INFO info level.
729 ****************************************************************************/
731 bool cli_qpathinfo2(struct cli_state *cli, const char *fname,
732 struct timespec *create_time,
733 struct timespec *access_time,
734 struct timespec *write_time,
735 struct timespec *change_time,
736 SMB_OFF_T *size, uint16 *mode,
739 unsigned int data_len = 0;
740 unsigned int param_len = 0;
741 uint16 setup = TRANSACT2_QPATHINFO;
743 char *rparam=NULL, *rdata=NULL;
745 size_t nlen = 2*(strlen(fname)+1);
747 param = SMB_MALLOC_ARRAY(char, 6+nlen+2);
752 memset(param, '\0', 6);
753 SSVAL(p, 0, SMB_QUERY_FILE_ALL_INFO);
755 p += clistr_push(cli, p, fname, nlen, STR_TERMINATE);
757 param_len = PTR_DIFF(p, param);
759 if (!cli_send_trans(cli, SMBtrans2,
761 -1, 0, /* fid, flags */
762 &setup, 1, 0, /* setup, length, max */
763 param, param_len, 10, /* param, length, max */
764 NULL, data_len, cli->max_xmit /* data, length, max */
771 if (!cli_receive_trans(cli, SMBtrans2,
773 &rdata, &data_len)) {
777 if (!rdata || data_len < 22) {
782 *create_time = interpret_long_date(rdata+0);
785 *access_time = interpret_long_date(rdata+8);
788 *write_time = interpret_long_date(rdata+16);
791 *change_time = interpret_long_date(rdata+24);
794 *mode = SVAL(rdata, 32);
797 *size = IVAL2_TO_SMB_BIG_UINT(rdata,48);
800 *ino = IVAL(rdata, 64);
808 /****************************************************************************
810 ****************************************************************************/
812 bool cli_qpathinfo_streams(struct cli_state *cli, const char *fname,
814 unsigned int *pnum_streams,
815 struct stream_struct **pstreams)
817 unsigned int data_len = 0;
818 unsigned int param_len = 0;
819 uint16 setup = TRANSACT2_QPATHINFO;
821 char *rparam=NULL, *rdata=NULL;
823 unsigned int num_streams;
824 struct stream_struct *streams;
826 size_t namelen = 2*(strlen(fname)+1);
828 param = SMB_MALLOC_ARRAY(char, 6+namelen+2);
834 SSVAL(p, 0, SMB_FILE_STREAM_INFORMATION);
836 p += clistr_push(cli, p, fname, namelen, STR_TERMINATE);
838 param_len = PTR_DIFF(p, param);
840 if (!cli_send_trans(cli, SMBtrans2,
842 -1, 0, /* fid, flags */
843 &setup, 1, 0, /* setup, len, max */
844 param, param_len, 10, /* param, len, max */
845 NULL, data_len, cli->max_xmit /* data, len, max */
850 if (!cli_receive_trans(cli, SMBtrans2,
852 &rdata, &data_len)) {
865 while ((data_len > ofs) && (data_len - ofs >= 24)) {
869 struct stream_struct *tmp;
872 tmp = TALLOC_REALLOC_ARRAY(mem_ctx, streams,
873 struct stream_struct,
881 nlen = IVAL(rdata, ofs + 0x04);
883 streams[num_streams].size = IVAL_TO_SMB_OFF_T(
885 streams[num_streams].alloc_size = IVAL_TO_SMB_OFF_T(
888 if (nlen > data_len - (ofs + 24)) {
893 * We need to null-terminate src, how do I do this with
894 * convert_string_talloc??
897 tmp_buf = TALLOC_ARRAY(streams, uint8_t, nlen+2);
898 if (tmp_buf == NULL) {
902 memcpy(tmp_buf, rdata+ofs+24, nlen);
906 size = convert_string_talloc(streams, CH_UTF16, CH_UNIX,
907 tmp_buf, nlen+2, &vstr,
909 TALLOC_FREE(tmp_buf);
914 streams[num_streams].name = (char *)vstr;
917 len = IVAL(rdata, ofs);
918 if (len > data_len - ofs) {
928 *pnum_streams = num_streams;
933 TALLOC_FREE(streams);
939 /****************************************************************************
940 Send a qfileinfo QUERY_FILE_NAME_INFO call.
941 ****************************************************************************/
943 bool cli_qfilename(struct cli_state *cli, int fnum, char *name, size_t namelen)
945 unsigned int data_len = 0;
946 unsigned int param_len = 0;
947 uint16 setup = TRANSACT2_QFILEINFO;
949 char *rparam=NULL, *rdata=NULL;
952 SSVAL(param, 0, fnum);
953 SSVAL(param, 2, SMB_QUERY_FILE_NAME_INFO);
955 if (!cli_send_trans(cli, SMBtrans2,
957 -1, 0, /* fid, flags */
958 &setup, 1, 0, /* setup, length, max */
959 param, param_len, 2, /* param, length, max */
960 NULL, data_len, cli->max_xmit /* data, length, max */
965 if (!cli_receive_trans(cli, SMBtrans2,
967 &rdata, &data_len)) {
971 if (!rdata || data_len < 4) {
975 clistr_pull(cli, name, rdata+4, namelen, IVAL(rdata, 0), STR_UNICODE);
980 /****************************************************************************
981 Send a qfileinfo call.
982 ****************************************************************************/
984 bool cli_qfileinfo(struct cli_state *cli, int fnum,
985 uint16 *mode, SMB_OFF_T *size,
986 struct timespec *create_time,
987 struct timespec *access_time,
988 struct timespec *write_time,
989 struct timespec *change_time,
992 unsigned int data_len = 0;
993 unsigned int param_len = 0;
994 uint16 setup = TRANSACT2_QFILEINFO;
996 char *rparam=NULL, *rdata=NULL;
998 /* if its a win95 server then fail this - win95 totally screws it
1000 if (cli->win95) return False;
1004 SSVAL(param, 0, fnum);
1005 SSVAL(param, 2, SMB_QUERY_FILE_ALL_INFO);
1007 if (!cli_send_trans(cli, SMBtrans2,
1009 -1, 0, /* fid, flags */
1010 &setup, 1, 0, /* setup, length, max */
1011 param, param_len, 2, /* param, length, max */
1012 NULL, data_len, cli->max_xmit /* data, length, max */
1017 if (!cli_receive_trans(cli, SMBtrans2,
1018 &rparam, ¶m_len,
1019 &rdata, &data_len)) {
1023 if (!rdata || data_len < 68) {
1028 *create_time = interpret_long_date(rdata+0);
1031 *access_time = interpret_long_date(rdata+8);
1034 *write_time = interpret_long_date(rdata+16);
1037 *change_time = interpret_long_date(rdata+24);
1040 *mode = SVAL(rdata, 32);
1043 *size = IVAL2_TO_SMB_BIG_UINT(rdata,48);
1046 *ino = IVAL(rdata, 64);
1054 /****************************************************************************
1055 Send a qpathinfo BASIC_INFO call.
1056 ****************************************************************************/
1058 bool cli_qpathinfo_basic( struct cli_state *cli, const char *name,
1059 SMB_STRUCT_STAT *sbuf, uint32 *attributes )
1061 unsigned int param_len = 0;
1062 unsigned int data_len = 0;
1063 uint16 setup = TRANSACT2_QPATHINFO;
1065 char *rparam=NULL, *rdata=NULL;
1070 TALLOC_CTX *frame = talloc_stackframe();
1072 path = talloc_strdup(frame, name);
1080 if ( path[len-1] == '\\' || path[len-1] == '/') {
1083 nlen = 2*(strlen(path)+1);
1085 param = TALLOC_ARRAY(frame,char,6+nlen+2);
1090 memset(param, '\0', 6);
1092 SSVAL(p, 0, SMB_QUERY_FILE_BASIC_INFO);
1094 p += clistr_push(cli, p, path, nlen, STR_TERMINATE);
1095 param_len = PTR_DIFF(p, param);
1098 if (!cli_send_trans(cli, SMBtrans2,
1100 -1, 0, /* fid, flags */
1101 &setup, 1, 0, /* setup, length, max */
1102 param, param_len, 2, /* param, length, max */
1103 NULL, 0, cli->max_xmit /* data, length, max */
1111 if (!cli_receive_trans(cli, SMBtrans2,
1112 &rparam, ¶m_len,
1113 &rdata, &data_len)) {
1117 if (data_len < 36) {
1123 set_atimespec(sbuf, interpret_long_date( rdata+8 )); /* Access time. */
1124 set_mtimespec(sbuf, interpret_long_date( rdata+16 )); /* Write time. */
1125 set_ctimespec(sbuf, interpret_long_date( rdata+24 )); /* Change time. */
1127 *attributes = IVAL( rdata, 32 );
1135 /****************************************************************************
1136 Send a qfileinfo call.
1137 ****************************************************************************/
1139 bool cli_qfileinfo_test(struct cli_state *cli, int fnum, int level, char **poutdata, uint32 *poutlen)
1141 unsigned int data_len = 0;
1142 unsigned int param_len = 0;
1143 uint16 setup = TRANSACT2_QFILEINFO;
1145 char *rparam=NULL, *rdata=NULL;
1150 /* if its a win95 server then fail this - win95 totally screws it
1157 SSVAL(param, 0, fnum);
1158 SSVAL(param, 2, level);
1160 if (!cli_send_trans(cli, SMBtrans2,
1162 -1, 0, /* fid, flags */
1163 &setup, 1, 0, /* setup, length, max */
1164 param, param_len, 2, /* param, length, max */
1165 NULL, data_len, cli->max_xmit /* data, length, max */
1170 if (!cli_receive_trans(cli, SMBtrans2,
1171 &rparam, ¶m_len,
1172 &rdata, &data_len)) {
1176 *poutdata = (char *)memdup(rdata, data_len);
1183 *poutlen = data_len;
1190 /****************************************************************************
1191 Send a qpathinfo SMB_QUERY_FILE_ALT_NAME_INFO call.
1192 ****************************************************************************/
1194 NTSTATUS cli_qpathinfo_alt_name(struct cli_state *cli, const char *fname, fstring alt_name)
1196 unsigned int data_len = 0;
1197 unsigned int param_len = 0;
1198 uint16 setup = TRANSACT2_QPATHINFO;
1200 char *rparam=NULL, *rdata=NULL;
1205 size_t nlen = 2*(strlen(fname)+1);
1207 param = SMB_MALLOC_ARRAY(char, 6+nlen+2);
1209 return NT_STATUS_NO_MEMORY;
1212 memset(param, '\0', 6);
1213 SSVAL(p, 0, SMB_QUERY_FILE_ALT_NAME_INFO);
1215 p += clistr_push(cli, p, fname, nlen, STR_TERMINATE);
1216 param_len = PTR_DIFF(p, param);
1219 ret = (cli_send_trans(cli, SMBtrans2,
1221 -1, 0, /* fid, flags */
1222 &setup, 1, 0, /* setup, length, max */
1223 param, param_len, 10, /* param, length, max */
1224 NULL, data_len, cli->max_xmit /* data, length, max */
1226 cli_receive_trans(cli, SMBtrans2,
1227 &rparam, ¶m_len,
1228 &rdata, &data_len));
1229 if (!ret && cli_is_dos_error(cli)) {
1230 /* we need to work around a Win95 bug - sometimes
1231 it gives ERRSRV/ERRerror temprarily */
1234 cli_dos_error(cli, &eclass, &ecode);
1235 if (eclass != ERRSRV || ecode != ERRerror) break;
1238 } while (count-- && ret==False);
1242 if (!ret || !rdata || data_len < 4) {
1243 return NT_STATUS_UNSUCCESSFUL;
1246 len = IVAL(rdata, 0);
1248 if (len > data_len - 4) {
1249 return NT_STATUS_INVALID_NETWORK_RESPONSE;
1252 clistr_pull(cli, alt_name, rdata+4, sizeof(fstring), len, STR_UNICODE);
1257 return NT_STATUS_OK;