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) - converter
;
195 if (comment_offset
< 0 ||
196 comment_offset
> (int)rdrcnt
) {
200 cmnt
= comment_offset
?(rdata
+comment_offset
):"";
202 /* Work out the comment length. */
203 for (p1
= cmnt
, len
= 0; *p1
&&
204 p1
< rdata_end
; len
++)
209 pull_string_talloc(frame
,rdata
,0,
210 &s1
,sname
,14,STR_ASCII
);
211 pull_string_talloc(frame
,rdata
,0,
212 &s2
,cmnt
,len
,STR_ASCII
);
218 fn(s1
, type
, s2
, state
);
223 DEBUG(4,("NetShareEnum res=%d\n", res
));
226 DEBUG(4,("NetShareEnum failed\n"));
235 /****************************************************************************
236 Call a NetServerEnum for the specified workgroup and servertype mask. This
237 function then calls the specified callback function for each name returned.
239 The callback function takes 4 arguments: the machine name, the server type,
240 the comment and a state pointer.
241 ****************************************************************************/
243 bool cli_NetServerEnum(struct cli_state
*cli
, char *workgroup
, uint32 stype
,
244 void (*fn
)(const char *, uint32
, const char *, void *),
249 char *rdata_end
= NULL
;
250 unsigned int rdrcnt
,rprcnt
;
255 uint32 func
= RAP_NetServerEnum2
;
256 char *last_entry
= NULL
;
261 errno
= 0; /* reset */
264 * This may take more than one transaction, so we should loop until
265 * we no longer get a more data to process or we have all of the
269 /* send a SMBtrans command with api NetServerEnum */
271 SIVAL(p
,0,func
); /* api number */
274 if (func
== RAP_NetServerEnum3
) {
275 strlcpy(p
,"WrLehDzz", sizeof(param
)-PTR_DIFF(p
,param
));
277 strlcpy(p
,"WrLehDz", sizeof(param
)-PTR_DIFF(p
,param
));
280 p
= skip_string(param
, sizeof(param
), p
);
281 strlcpy(p
,"B16BBDz", sizeof(param
)-PTR_DIFF(p
,param
));
283 p
= skip_string(param
, sizeof(param
), p
);
285 SSVAL(p
,2,CLI_BUFFER_SIZE
);
290 /* If we have more data, tell the server where
295 sizeof(param
) - PTR_DIFF(p
,param
) - 1,
296 STR_TERMINATE
|STR_UPPER
);
298 if (len
== (size_t)-1) {
299 SAFE_FREE(last_entry
);
304 if (func
== RAP_NetServerEnum3
) {
306 last_entry
? last_entry
: "",
307 sizeof(param
) - PTR_DIFF(p
,param
) - 1,
310 if (len
== (size_t)-1) {
311 SAFE_FREE(last_entry
);
317 /* Next time through we need to use the continue api */
318 func
= RAP_NetServerEnum3
;
321 param
, PTR_DIFF(p
,param
), 8, /* params, length, max */
322 NULL
, 0, CLI_BUFFER_SIZE
, /* data, length, max */
323 &rparam
, &rprcnt
, /* return params, return size */
324 &rdata
, &rdrcnt
)) { /* return data, return size */
326 /* break out of the loop on error */
331 rdata_end
= rdata
+ rdrcnt
;
332 res
= rparam
? SVAL(rparam
,0) : -1;
334 if (res
== 0 || res
== ERRmoredata
||
335 (res
!= -1 && cli_errno(cli
) == 0)) {
338 int converter
=SVAL(rparam
,2);
340 /* Get the number of items returned in this buffer */
341 count
= SVAL(rparam
, 4);
343 /* The next field contains the number of items left,
344 * including those returned in this buffer. So the
345 * first time through this should contain all of the
348 if (total_cnt
== 0) {
349 total_cnt
= SVAL(rparam
, 6);
352 /* Keep track of how many we have read */
356 /* The last name in the previous NetServerEnum reply is
357 * sent back to server in the NetServerEnum3 request
358 * (last_entry). The next reply should repeat this entry
359 * as the first element. We have no proof that this is
360 * always true, but from traces that seems to be the
361 * behavior from Window Servers. So first lets do a lot
362 * of checking, just being paranoid. If the string
363 * matches then we already saw this entry so skip it.
365 * NOTE: sv1_name field must be null terminated and has
366 * a max size of 16 (NetBIOS Name).
368 if (last_entry
&& count
&& p
&&
369 (strncmp(last_entry
, p
, 16) == 0)) {
370 count
-= 1; /* Skip this entry */
371 return_cnt
= -1; /* Not part of total, so don't count. */
372 p
= rdata
+ 26; /* Skip the whole record */
375 for (i
= 0; i
< count
; i
++, p
+= 26) {
380 TALLOC_CTX
*frame
= talloc_stackframe();
381 uint32_t entry_stype
;
383 if (p
+ 26 > rdata_end
) {
389 comment_offset
= (IVAL(p
,22) & 0xFFFF)-converter
;
390 cmnt
= comment_offset
?(rdata
+comment_offset
):"";
392 if (comment_offset
< 0 || comment_offset
> (int)rdrcnt
) {
397 /* Work out the comment length. */
398 for (p1
= cmnt
, len
= 0; *p1
&&
399 p1
< rdata_end
; len
++)
405 entry_stype
= IVAL(p
,18) & ~SV_TYPE_LOCAL_LIST_ONLY
;
407 pull_string_talloc(frame
,rdata
,0,
408 &s1
,sname
,16,STR_ASCII
);
409 pull_string_talloc(frame
,rdata
,0,
410 &s2
,cmnt
,len
,STR_ASCII
);
417 fn(s1
, entry_stype
, s2
, state
);
421 /* We are done with the old last entry, so now we can free it */
423 SAFE_FREE(last_entry
); /* This will set it to null */
426 /* We always make a copy of the last entry if we have one */
428 last_entry
= smb_xstrdup(sname
);
431 /* If we have more data, but no last entry then error out */
432 if (!last_entry
&& (res
== ERRmoredata
)) {
441 } while ((res
== ERRmoredata
) && (total_cnt
> return_cnt
));
445 SAFE_FREE(last_entry
);
448 errno
= cli_errno(cli
);
451 /* this is a very special case, when the domain master for the
452 work group isn't part of the work group itself, there is something
458 return(return_cnt
> 0);
461 /****************************************************************************
462 Send a SamOEMChangePassword command.
463 ****************************************************************************/
465 bool cli_oem_change_password(struct cli_state
*cli
, const char *user
, const char *new_password
,
466 const char *old_password
)
469 unsigned char data
[532];
471 unsigned char old_pw_hash
[16];
472 unsigned char new_pw_hash
[16];
473 unsigned int data_len
;
474 unsigned int param_len
= 0;
477 unsigned int rprcnt
, rdrcnt
;
479 if (strlen(user
) >= sizeof(fstring
)-1) {
480 DEBUG(0,("cli_oem_change_password: user name %s is too long.\n", user
));
484 SSVAL(p
,0,214); /* SamOEMChangePassword command. */
486 strlcpy(p
, "zsT", sizeof(param
)-PTR_DIFF(p
,param
));
487 p
= skip_string(param
,sizeof(param
),p
);
488 strlcpy(p
, "B516B16", sizeof(param
)-PTR_DIFF(p
,param
));
489 p
= skip_string(param
,sizeof(param
),p
);
490 strlcpy(p
,user
, sizeof(param
)-PTR_DIFF(p
,param
));
491 p
= skip_string(param
,sizeof(param
),p
);
495 param_len
= PTR_DIFF(p
,param
);
498 * Get the Lanman hash of the old password, we
499 * use this as the key to make_oem_passwd_hash().
501 E_deshash(old_password
, old_pw_hash
);
503 encode_pw_buffer(data
, new_password
, STR_ASCII
);
505 #ifdef DEBUG_PASSWORD
506 DEBUG(100,("make_oem_passwd_hash\n"));
507 dump_data(100, data
, 516);
509 SamOEMhash( (unsigned char *)data
, (unsigned char *)old_pw_hash
, 516);
512 * Now place the old password hash in the data.
514 E_deshash(new_password
, new_pw_hash
);
516 E_old_pw_hash( new_pw_hash
, old_pw_hash
, (uchar
*)&data
[516]);
520 if (cli_send_trans(cli
,SMBtrans
,
521 PIPE_LANMAN
, /* name */
522 0,0, /* fid, flags */
523 NULL
,0,0, /* setup, length, max */
524 param
,param_len
,2, /* param, length, max */
525 (char *)data
,data_len
,0 /* data, length, max */
527 DEBUG(0,("cli_oem_change_password: Failed to send password change for user %s\n",
532 if (!cli_receive_trans(cli
,SMBtrans
,
535 DEBUG(0,("cli_oem_change_password: Failed to recieve reply to password change for user %s\n",
541 cli
->rap_error
= SVAL(rparam
,0);
547 return (cli
->rap_error
== 0);
550 /****************************************************************************
551 Send a qpathinfo call.
552 ****************************************************************************/
554 bool cli_qpathinfo(struct cli_state
*cli
,
562 unsigned int data_len
= 0;
563 unsigned int param_len
= 0;
564 unsigned int rparam_len
, rdata_len
;
565 uint16 setup
= TRANSACT2_QPATHINFO
;
567 char *rparam
=NULL
, *rdata
=NULL
;
570 time_t (*date_fn
)(struct cli_state
*, const void *);
572 size_t nlen
= 2*(strlen(fname
)+1);
574 param
= SMB_MALLOC_ARRAY(char, 6+nlen
+2);
580 SSVAL(p
, 0, SMB_INFO_STANDARD
);
582 p
+= clistr_push(cli
, p
, fname
, nlen
, STR_TERMINATE
);
583 param_len
= PTR_DIFF(p
, param
);
586 ret
= (cli_send_trans(cli
, SMBtrans2
,
588 -1, 0, /* fid, flags */
589 &setup
, 1, 0, /* setup, length, max */
590 param
, param_len
, 10, /* param, length, max */
591 NULL
, data_len
, cli
->max_xmit
/* data, length, max */
593 cli_receive_trans(cli
, SMBtrans2
,
594 &rparam
, &rparam_len
,
595 &rdata
, &rdata_len
));
596 if (!cli_is_dos_error(cli
)) break;
598 /* we need to work around a Win95 bug - sometimes
599 it gives ERRSRV/ERRerror temprarily */
602 cli_dos_error(cli
, &eclass
, &ecode
);
603 if (eclass
!= ERRSRV
|| ecode
!= ERRerror
) break;
606 } while (count
-- && ret
==False
);
609 if (!ret
|| !rdata
|| rdata_len
< 22) {
614 date_fn
= cli_make_unix_date
;
616 date_fn
= cli_make_unix_date2
;
620 *change_time
= date_fn(cli
, rdata
+0);
623 *access_time
= date_fn(cli
, rdata
+4);
626 *write_time
= date_fn(cli
, rdata
+8);
629 *size
= IVAL(rdata
, 12);
632 *mode
= SVAL(rdata
,l1_attrFile
);
640 /****************************************************************************
641 Send a setpathinfo call.
642 ****************************************************************************/
644 bool cli_setpathinfo(struct cli_state
*cli
, const char *fname
,
651 unsigned int data_len
= 0;
652 unsigned int param_len
= 0;
653 unsigned int rparam_len
, rdata_len
;
654 uint16 setup
= TRANSACT2_SETPATHINFO
;
657 char *rparam
=NULL
, *rdata
=NULL
;
661 size_t nlen
= 2*(strlen(fname
)+1);
663 param
= SMB_MALLOC_ARRAY(char, 6+nlen
+2);
667 memset(param
, '\0', 6);
668 memset(data
, 0, sizeof(data
));
672 /* Add the information level */
673 SSVAL(p
, 0, SMB_FILE_BASIC_INFORMATION
);
678 /* Add the file name */
679 p
+= clistr_push(cli
, p
, fname
, nlen
, STR_TERMINATE
);
681 param_len
= PTR_DIFF(p
, param
);
686 * Add the create, last access, modification, and status change times
688 put_long_date(p
, create_time
);
691 put_long_date(p
, access_time
);
694 put_long_date(p
, write_time
);
697 put_long_date(p
, change_time
);
708 data_len
= PTR_DIFF(p
, data
);
711 ret
= (cli_send_trans(cli
, SMBtrans2
,
713 -1, 0, /* fid, flags */
714 &setup
, 1, 0, /* setup, length, max */
715 param
, param_len
, 10, /* param, length, max */
716 data
, data_len
, cli
->max_xmit
/* data, length, max */
718 cli_receive_trans(cli
, SMBtrans2
,
719 &rparam
, &rparam_len
,
720 &rdata
, &rdata_len
));
721 if (!cli_is_dos_error(cli
)) break;
723 /* we need to work around a Win95 bug - sometimes
724 it gives ERRSRV/ERRerror temprarily */
727 cli_dos_error(cli
, &eclass
, &ecode
);
728 if (eclass
!= ERRSRV
|| ecode
!= ERRerror
) break;
731 } while (count
-- && ret
==False
);
743 /****************************************************************************
744 Send a qpathinfo call with the SMB_QUERY_FILE_ALL_INFO info level.
745 ****************************************************************************/
747 bool cli_qpathinfo2(struct cli_state
*cli
, const char *fname
,
748 struct timespec
*create_time
,
749 struct timespec
*access_time
,
750 struct timespec
*write_time
,
751 struct timespec
*change_time
,
752 SMB_OFF_T
*size
, uint16
*mode
,
755 unsigned int data_len
= 0;
756 unsigned int param_len
= 0;
757 uint16 setup
= TRANSACT2_QPATHINFO
;
759 char *rparam
=NULL
, *rdata
=NULL
;
761 size_t nlen
= 2*(strlen(fname
)+1);
763 param
= SMB_MALLOC_ARRAY(char, 6+nlen
+2);
768 memset(param
, '\0', 6);
769 SSVAL(p
, 0, SMB_QUERY_FILE_ALL_INFO
);
771 p
+= clistr_push(cli
, p
, fname
, nlen
, STR_TERMINATE
);
773 param_len
= PTR_DIFF(p
, param
);
775 if (!cli_send_trans(cli
, SMBtrans2
,
777 -1, 0, /* fid, flags */
778 &setup
, 1, 0, /* setup, length, max */
779 param
, param_len
, 10, /* param, length, max */
780 NULL
, data_len
, cli
->max_xmit
/* data, length, max */
787 if (!cli_receive_trans(cli
, SMBtrans2
,
789 &rdata
, &data_len
)) {
793 if (!rdata
|| data_len
< 22) {
798 *create_time
= interpret_long_date(rdata
+0);
801 *access_time
= interpret_long_date(rdata
+8);
804 *write_time
= interpret_long_date(rdata
+16);
807 *change_time
= interpret_long_date(rdata
+24);
810 *mode
= SVAL(rdata
, 32);
813 *size
= IVAL2_TO_SMB_BIG_UINT(rdata
,48);
816 *ino
= IVAL(rdata
, 64);
824 /****************************************************************************
826 ****************************************************************************/
828 bool cli_qpathinfo_streams(struct cli_state
*cli
, const char *fname
,
830 unsigned int *pnum_streams
,
831 struct stream_struct
**pstreams
)
833 unsigned int data_len
= 0;
834 unsigned int param_len
= 0;
835 uint16 setup
= TRANSACT2_QPATHINFO
;
837 char *rparam
=NULL
, *rdata
=NULL
;
839 unsigned int num_streams
;
840 struct stream_struct
*streams
;
842 size_t namelen
= 2*(strlen(fname
)+1);
844 param
= SMB_MALLOC_ARRAY(char, 6+namelen
+2);
850 SSVAL(p
, 0, SMB_FILE_STREAM_INFORMATION
);
852 p
+= clistr_push(cli
, p
, fname
, namelen
, STR_TERMINATE
);
854 param_len
= PTR_DIFF(p
, param
);
856 if (!cli_send_trans(cli
, SMBtrans2
,
858 -1, 0, /* fid, flags */
859 &setup
, 1, 0, /* setup, len, max */
860 param
, param_len
, 10, /* param, len, max */
861 NULL
, data_len
, cli
->max_xmit
/* data, len, max */
866 if (!cli_receive_trans(cli
, SMBtrans2
,
868 &rdata
, &data_len
)) {
881 while ((data_len
> ofs
) && (data_len
- ofs
>= 24)) {
885 struct stream_struct
*tmp
;
888 tmp
= TALLOC_REALLOC_ARRAY(mem_ctx
, streams
,
889 struct stream_struct
,
897 nlen
= IVAL(rdata
, ofs
+ 0x04);
899 streams
[num_streams
].size
= IVAL_TO_SMB_OFF_T(
901 streams
[num_streams
].alloc_size
= IVAL_TO_SMB_OFF_T(
904 if (nlen
> data_len
- (ofs
+ 24)) {
909 * We need to null-terminate src, how do I do this with
910 * convert_string_talloc??
913 tmp_buf
= TALLOC_ARRAY(streams
, uint8_t, nlen
+2);
914 if (tmp_buf
== NULL
) {
918 memcpy(tmp_buf
, rdata
+ofs
+24, nlen
);
922 if (!convert_string_talloc(streams
, CH_UTF16
, CH_UNIX
, tmp_buf
,
923 nlen
+2, &vstr
, &size
, false))
925 TALLOC_FREE(tmp_buf
);
929 TALLOC_FREE(tmp_buf
);
930 streams
[num_streams
].name
= (char *)vstr
;
933 len
= IVAL(rdata
, ofs
);
934 if (len
> data_len
- ofs
) {
944 *pnum_streams
= num_streams
;
949 TALLOC_FREE(streams
);
955 /****************************************************************************
956 Send a qfileinfo QUERY_FILE_NAME_INFO call.
957 ****************************************************************************/
959 bool cli_qfilename(struct cli_state
*cli
, int fnum
, char *name
, size_t namelen
)
961 unsigned int data_len
= 0;
962 unsigned int param_len
= 0;
963 uint16 setup
= TRANSACT2_QFILEINFO
;
965 char *rparam
=NULL
, *rdata
=NULL
;
968 SSVAL(param
, 0, fnum
);
969 SSVAL(param
, 2, SMB_QUERY_FILE_NAME_INFO
);
971 if (!cli_send_trans(cli
, SMBtrans2
,
973 -1, 0, /* fid, flags */
974 &setup
, 1, 0, /* setup, length, max */
975 param
, param_len
, 2, /* param, length, max */
976 NULL
, data_len
, cli
->max_xmit
/* data, length, max */
981 if (!cli_receive_trans(cli
, SMBtrans2
,
983 &rdata
, &data_len
)) {
987 if (!rdata
|| data_len
< 4) {
991 clistr_pull(cli
, name
, rdata
+4, namelen
, IVAL(rdata
, 0), STR_UNICODE
);
996 /****************************************************************************
997 Send a qfileinfo call.
998 ****************************************************************************/
1000 bool cli_qfileinfo(struct cli_state
*cli
, int fnum
,
1001 uint16
*mode
, SMB_OFF_T
*size
,
1002 struct timespec
*create_time
,
1003 struct timespec
*access_time
,
1004 struct timespec
*write_time
,
1005 struct timespec
*change_time
,
1008 unsigned int data_len
= 0;
1009 unsigned int param_len
= 0;
1010 uint16 setup
= TRANSACT2_QFILEINFO
;
1012 char *rparam
=NULL
, *rdata
=NULL
;
1014 /* if its a win95 server then fail this - win95 totally screws it
1016 if (cli
->win95
) return False
;
1020 SSVAL(param
, 0, fnum
);
1021 SSVAL(param
, 2, SMB_QUERY_FILE_ALL_INFO
);
1023 if (!cli_send_trans(cli
, SMBtrans2
,
1025 -1, 0, /* fid, flags */
1026 &setup
, 1, 0, /* setup, length, max */
1027 param
, param_len
, 2, /* param, length, max */
1028 NULL
, data_len
, cli
->max_xmit
/* data, length, max */
1033 if (!cli_receive_trans(cli
, SMBtrans2
,
1034 &rparam
, ¶m_len
,
1035 &rdata
, &data_len
)) {
1039 if (!rdata
|| data_len
< 68) {
1044 *create_time
= interpret_long_date(rdata
+0);
1047 *access_time
= interpret_long_date(rdata
+8);
1050 *write_time
= interpret_long_date(rdata
+16);
1053 *change_time
= interpret_long_date(rdata
+24);
1056 *mode
= SVAL(rdata
, 32);
1059 *size
= IVAL2_TO_SMB_BIG_UINT(rdata
,48);
1062 *ino
= IVAL(rdata
, 64);
1070 /****************************************************************************
1071 Send a qpathinfo BASIC_INFO call.
1072 ****************************************************************************/
1074 bool cli_qpathinfo_basic( struct cli_state
*cli
, const char *name
,
1075 SMB_STRUCT_STAT
*sbuf
, uint32
*attributes
)
1077 unsigned int param_len
= 0;
1078 unsigned int data_len
= 0;
1079 uint16 setup
= TRANSACT2_QPATHINFO
;
1081 char *rparam
=NULL
, *rdata
=NULL
;
1086 TALLOC_CTX
*frame
= talloc_stackframe();
1088 path
= talloc_strdup(frame
, name
);
1096 if ( path
[len
-1] == '\\' || path
[len
-1] == '/') {
1099 nlen
= 2*(strlen(path
)+1);
1101 param
= TALLOC_ARRAY(frame
,char,6+nlen
+2);
1106 memset(param
, '\0', 6);
1108 SSVAL(p
, 0, SMB_QUERY_FILE_BASIC_INFO
);
1110 p
+= clistr_push(cli
, p
, path
, nlen
, STR_TERMINATE
);
1111 param_len
= PTR_DIFF(p
, param
);
1114 if (!cli_send_trans(cli
, SMBtrans2
,
1116 -1, 0, /* fid, flags */
1117 &setup
, 1, 0, /* setup, length, max */
1118 param
, param_len
, 2, /* param, length, max */
1119 NULL
, 0, cli
->max_xmit
/* data, length, max */
1127 if (!cli_receive_trans(cli
, SMBtrans2
,
1128 &rparam
, ¶m_len
,
1129 &rdata
, &data_len
)) {
1133 if (data_len
< 36) {
1139 set_atimespec(sbuf
, interpret_long_date( rdata
+8 )); /* Access time. */
1140 set_mtimespec(sbuf
, interpret_long_date( rdata
+16 )); /* Write time. */
1141 set_ctimespec(sbuf
, interpret_long_date( rdata
+24 )); /* Change time. */
1143 *attributes
= IVAL( rdata
, 32 );
1151 /****************************************************************************
1152 Send a qfileinfo call.
1153 ****************************************************************************/
1155 bool cli_qfileinfo_test(struct cli_state
*cli
, int fnum
, int level
, char **poutdata
, uint32
*poutlen
)
1157 unsigned int data_len
= 0;
1158 unsigned int param_len
= 0;
1159 uint16 setup
= TRANSACT2_QFILEINFO
;
1161 char *rparam
=NULL
, *rdata
=NULL
;
1166 /* if its a win95 server then fail this - win95 totally screws it
1173 SSVAL(param
, 0, fnum
);
1174 SSVAL(param
, 2, level
);
1176 if (!cli_send_trans(cli
, SMBtrans2
,
1178 -1, 0, /* fid, flags */
1179 &setup
, 1, 0, /* setup, length, max */
1180 param
, param_len
, 2, /* param, length, max */
1181 NULL
, data_len
, cli
->max_xmit
/* data, length, max */
1186 if (!cli_receive_trans(cli
, SMBtrans2
,
1187 &rparam
, ¶m_len
,
1188 &rdata
, &data_len
)) {
1192 *poutdata
= (char *)memdup(rdata
, data_len
);
1199 *poutlen
= data_len
;
1206 /****************************************************************************
1207 Send a qpathinfo SMB_QUERY_FILE_ALT_NAME_INFO call.
1208 ****************************************************************************/
1210 NTSTATUS
cli_qpathinfo_alt_name(struct cli_state
*cli
, const char *fname
, fstring alt_name
)
1212 unsigned int data_len
= 0;
1213 unsigned int param_len
= 0;
1214 uint16 setup
= TRANSACT2_QPATHINFO
;
1216 char *rparam
=NULL
, *rdata
=NULL
;
1221 size_t nlen
= 2*(strlen(fname
)+1);
1223 param
= SMB_MALLOC_ARRAY(char, 6+nlen
+2);
1225 return NT_STATUS_NO_MEMORY
;
1228 memset(param
, '\0', 6);
1229 SSVAL(p
, 0, SMB_QUERY_FILE_ALT_NAME_INFO
);
1231 p
+= clistr_push(cli
, p
, fname
, nlen
, STR_TERMINATE
);
1232 param_len
= PTR_DIFF(p
, param
);
1235 ret
= (cli_send_trans(cli
, SMBtrans2
,
1237 -1, 0, /* fid, flags */
1238 &setup
, 1, 0, /* setup, length, max */
1239 param
, param_len
, 10, /* param, length, max */
1240 NULL
, data_len
, cli
->max_xmit
/* data, length, max */
1242 cli_receive_trans(cli
, SMBtrans2
,
1243 &rparam
, ¶m_len
,
1244 &rdata
, &data_len
));
1245 if (!ret
&& cli_is_dos_error(cli
)) {
1246 /* we need to work around a Win95 bug - sometimes
1247 it gives ERRSRV/ERRerror temprarily */
1250 cli_dos_error(cli
, &eclass
, &ecode
);
1251 if (eclass
!= ERRSRV
|| ecode
!= ERRerror
) break;
1254 } while (count
-- && ret
==False
);
1258 if (!ret
|| !rdata
|| data_len
< 4) {
1259 return NT_STATUS_UNSUCCESSFUL
;
1262 len
= IVAL(rdata
, 0);
1264 if (len
> data_len
- 4) {
1265 return NT_STATUS_INVALID_NETWORK_RESPONSE
;
1268 clistr_pull(cli
, alt_name
, rdata
+4, sizeof(fstring
), len
, STR_UNICODE
);
1273 return NT_STATUS_OK
;