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 */
273 /* Next time through we need to use the continue api */
274 func
= RAP_NetServerEnum3
;
277 strlcpy(p
,"WrLehDOz", sizeof(param
)-PTR_DIFF(p
,param
));
279 strlcpy(p
,"WrLehDz", sizeof(param
)-PTR_DIFF(p
,param
));
282 p
= skip_string(param
, sizeof(param
), p
);
283 strlcpy(p
,"B16BBDz", sizeof(param
)-PTR_DIFF(p
,param
));
285 p
= skip_string(param
, sizeof(param
), p
);
287 SSVAL(p
,2,CLI_BUFFER_SIZE
);
292 /* If we have more data, tell the server where
296 last_entry
? last_entry
: workgroup
,
297 sizeof(param
) - PTR_DIFF(p
,param
) - 1,
298 STR_TERMINATE
|STR_UPPER
);
300 if (len
== (size_t)-1) {
301 SAFE_FREE(last_entry
);
307 param
, PTR_DIFF(p
,param
), 8, /* params, length, max */
308 NULL
, 0, CLI_BUFFER_SIZE
, /* data, length, max */
309 &rparam
, &rprcnt
, /* return params, return size */
310 &rdata
, &rdrcnt
)) { /* return data, return size */
312 /* break out of the loop on error */
317 rdata_end
= rdata
+ rdrcnt
;
318 res
= rparam
? SVAL(rparam
,0) : -1;
320 if (res
== 0 || res
== ERRmoredata
||
321 (res
!= -1 && cli_errno(cli
) == 0)) {
324 int converter
=SVAL(rparam
,2);
326 /* Get the number of items returned in this buffer */
327 count
= SVAL(rparam
, 4);
329 /* The next field contains the number of items left,
330 * including those returned in this buffer. So the
331 * first time through this should contain all of the
334 if (total_cnt
== 0) {
335 total_cnt
= SVAL(rparam
, 6);
338 /* Keep track of how many we have read */
342 /* The last name in the previous NetServerEnum reply is
343 * sent back to server in the NetServerEnum3 request
344 * (last_entry). The next reply should repeat this entry
345 * as the first element. We have no proof that this is
346 * always true, but from traces that seems to be the
347 * behavior from Window Servers. So first lets do a lot
348 * of checking, just being paranoid. If the string
349 * matches then we already saw this entry so skip it.
351 * NOTE: sv1_name field must be null terminated and has
352 * a max size of 16 (NetBIOS Name).
354 if (last_entry
&& count
&& p
&&
355 (strncmp(last_entry
, p
, 16) == 0)) {
356 count
-= 1; /* Skip this entry */
357 return_cnt
= -1; /* Not part of total, so don't count. */
358 p
= rdata
+ 26; /* Skip the whole record */
361 for (i
= 0; i
< count
; i
++, p
+= 26) {
366 TALLOC_CTX
*frame
= talloc_stackframe();
368 if (p
+ 26 > rdata_end
) {
374 comment_offset
= (IVAL(p
,22) & 0xFFFF)-converter
;
375 cmnt
= comment_offset
?(rdata
+comment_offset
):"";
377 if (comment_offset
< 0 || comment_offset
> (int)rdrcnt
) {
382 /* Work out the comment length. */
383 for (p1
= cmnt
, len
= 0; *p1
&&
384 p1
< rdata_end
; len
++)
390 stype
= IVAL(p
,18) & ~SV_TYPE_LOCAL_LIST_ONLY
;
392 pull_string_talloc(frame
,rdata
,0,
393 &s1
,sname
,16,STR_ASCII
);
394 pull_string_talloc(frame
,rdata
,0,
395 &s2
,cmnt
,len
,STR_ASCII
);
402 fn(s1
, stype
, s2
, state
);
406 /* We are done with the old last entry, so now we can free it */
408 SAFE_FREE(last_entry
); /* This will set it to null */
411 /* We always make a copy of the last entry if we have one */
413 last_entry
= smb_xstrdup(sname
);
416 /* If we have more data, but no last entry then error out */
417 if (!last_entry
&& (res
== ERRmoredata
)) {
426 } while ((res
== ERRmoredata
) && (total_cnt
> return_cnt
));
430 SAFE_FREE(last_entry
);
433 errno
= cli_errno(cli
);
436 /* this is a very special case, when the domain master for the
437 work group isn't part of the work group itself, there is something
443 return(return_cnt
> 0);
446 /****************************************************************************
447 Send a SamOEMChangePassword command.
448 ****************************************************************************/
450 bool cli_oem_change_password(struct cli_state
*cli
, const char *user
, const char *new_password
,
451 const char *old_password
)
454 unsigned char data
[532];
456 unsigned char old_pw_hash
[16];
457 unsigned char new_pw_hash
[16];
458 unsigned int data_len
;
459 unsigned int param_len
= 0;
462 unsigned int rprcnt
, rdrcnt
;
464 if (strlen(user
) >= sizeof(fstring
)-1) {
465 DEBUG(0,("cli_oem_change_password: user name %s is too long.\n", user
));
469 SSVAL(p
,0,214); /* SamOEMChangePassword command. */
471 strlcpy(p
, "zsT", sizeof(param
)-PTR_DIFF(p
,param
));
472 p
= skip_string(param
,sizeof(param
),p
);
473 strlcpy(p
, "B516B16", sizeof(param
)-PTR_DIFF(p
,param
));
474 p
= skip_string(param
,sizeof(param
),p
);
475 strlcpy(p
,user
, sizeof(param
)-PTR_DIFF(p
,param
));
476 p
= skip_string(param
,sizeof(param
),p
);
480 param_len
= PTR_DIFF(p
,param
);
483 * Get the Lanman hash of the old password, we
484 * use this as the key to make_oem_passwd_hash().
486 E_deshash(old_password
, old_pw_hash
);
488 encode_pw_buffer(data
, new_password
, STR_ASCII
);
490 #ifdef DEBUG_PASSWORD
491 DEBUG(100,("make_oem_passwd_hash\n"));
492 dump_data(100, data
, 516);
494 SamOEMhash( (unsigned char *)data
, (unsigned char *)old_pw_hash
, 516);
497 * Now place the old password hash in the data.
499 E_deshash(new_password
, new_pw_hash
);
501 E_old_pw_hash( new_pw_hash
, old_pw_hash
, (uchar
*)&data
[516]);
505 if (cli_send_trans(cli
,SMBtrans
,
506 PIPE_LANMAN
, /* name */
507 0,0, /* fid, flags */
508 NULL
,0,0, /* setup, length, max */
509 param
,param_len
,2, /* param, length, max */
510 (char *)data
,data_len
,0 /* data, length, max */
512 DEBUG(0,("cli_oem_change_password: Failed to send password change for user %s\n",
517 if (!cli_receive_trans(cli
,SMBtrans
,
520 DEBUG(0,("cli_oem_change_password: Failed to recieve reply to password change for user %s\n",
526 cli
->rap_error
= SVAL(rparam
,0);
532 return (cli
->rap_error
== 0);
535 /****************************************************************************
536 Send a qpathinfo call.
537 ****************************************************************************/
539 bool cli_qpathinfo(struct cli_state
*cli
,
547 unsigned int data_len
= 0;
548 unsigned int param_len
= 0;
549 unsigned int rparam_len
, rdata_len
;
550 uint16 setup
= TRANSACT2_QPATHINFO
;
552 char *rparam
=NULL
, *rdata
=NULL
;
555 time_t (*date_fn
)(struct cli_state
*, const void *);
557 size_t nlen
= 2*(strlen(fname
)+1);
559 param
= SMB_MALLOC_ARRAY(char, 6+nlen
+2);
565 SSVAL(p
, 0, SMB_INFO_STANDARD
);
567 p
+= clistr_push(cli
, p
, fname
, nlen
, STR_TERMINATE
);
568 param_len
= PTR_DIFF(p
, param
);
571 ret
= (cli_send_trans(cli
, SMBtrans2
,
573 -1, 0, /* fid, flags */
574 &setup
, 1, 0, /* setup, length, max */
575 param
, param_len
, 10, /* param, length, max */
576 NULL
, data_len
, cli
->max_xmit
/* data, length, max */
578 cli_receive_trans(cli
, SMBtrans2
,
579 &rparam
, &rparam_len
,
580 &rdata
, &rdata_len
));
581 if (!cli_is_dos_error(cli
)) break;
583 /* we need to work around a Win95 bug - sometimes
584 it gives ERRSRV/ERRerror temprarily */
587 cli_dos_error(cli
, &eclass
, &ecode
);
588 if (eclass
!= ERRSRV
|| ecode
!= ERRerror
) break;
591 } while (count
-- && ret
==False
);
594 if (!ret
|| !rdata
|| rdata_len
< 22) {
599 date_fn
= cli_make_unix_date
;
601 date_fn
= cli_make_unix_date2
;
605 *change_time
= date_fn(cli
, rdata
+0);
608 *access_time
= date_fn(cli
, rdata
+4);
611 *write_time
= date_fn(cli
, rdata
+8);
614 *size
= IVAL(rdata
, 12);
617 *mode
= SVAL(rdata
,l1_attrFile
);
625 /****************************************************************************
626 Send a setpathinfo call.
627 ****************************************************************************/
629 bool cli_setpathinfo(struct cli_state
*cli
, const char *fname
,
636 unsigned int data_len
= 0;
637 unsigned int param_len
= 0;
638 unsigned int rparam_len
, rdata_len
;
639 uint16 setup
= TRANSACT2_SETPATHINFO
;
642 char *rparam
=NULL
, *rdata
=NULL
;
646 size_t nlen
= 2*(strlen(fname
)+1);
648 param
= SMB_MALLOC_ARRAY(char, 6+nlen
+2);
652 memset(param
, '\0', 6);
653 memset(data
, 0, sizeof(data
));
657 /* Add the information level */
658 SSVAL(p
, 0, SMB_FILE_BASIC_INFORMATION
);
663 /* Add the file name */
664 p
+= clistr_push(cli
, p
, fname
, nlen
, STR_TERMINATE
);
666 param_len
= PTR_DIFF(p
, param
);
671 * Add the create, last access, modification, and status change times
673 put_long_date(p
, create_time
);
676 put_long_date(p
, access_time
);
679 put_long_date(p
, write_time
);
682 put_long_date(p
, change_time
);
693 data_len
= PTR_DIFF(p
, data
);
696 ret
= (cli_send_trans(cli
, SMBtrans2
,
698 -1, 0, /* fid, flags */
699 &setup
, 1, 0, /* setup, length, max */
700 param
, param_len
, 10, /* param, length, max */
701 data
, data_len
, cli
->max_xmit
/* data, length, max */
703 cli_receive_trans(cli
, SMBtrans2
,
704 &rparam
, &rparam_len
,
705 &rdata
, &rdata_len
));
706 if (!cli_is_dos_error(cli
)) break;
708 /* we need to work around a Win95 bug - sometimes
709 it gives ERRSRV/ERRerror temprarily */
712 cli_dos_error(cli
, &eclass
, &ecode
);
713 if (eclass
!= ERRSRV
|| ecode
!= ERRerror
) break;
716 } while (count
-- && ret
==False
);
728 /****************************************************************************
729 Send a qpathinfo call with the SMB_QUERY_FILE_ALL_INFO info level.
730 ****************************************************************************/
732 bool cli_qpathinfo2(struct cli_state
*cli
, const char *fname
,
733 struct timespec
*create_time
,
734 struct timespec
*access_time
,
735 struct timespec
*write_time
,
736 struct timespec
*change_time
,
737 SMB_OFF_T
*size
, uint16
*mode
,
740 unsigned int data_len
= 0;
741 unsigned int param_len
= 0;
742 uint16 setup
= TRANSACT2_QPATHINFO
;
744 char *rparam
=NULL
, *rdata
=NULL
;
746 size_t nlen
= 2*(strlen(fname
)+1);
748 param
= SMB_MALLOC_ARRAY(char, 6+nlen
+2);
753 memset(param
, '\0', 6);
754 SSVAL(p
, 0, SMB_QUERY_FILE_ALL_INFO
);
756 p
+= clistr_push(cli
, p
, fname
, nlen
, STR_TERMINATE
);
758 param_len
= PTR_DIFF(p
, param
);
760 if (!cli_send_trans(cli
, SMBtrans2
,
762 -1, 0, /* fid, flags */
763 &setup
, 1, 0, /* setup, length, max */
764 param
, param_len
, 10, /* param, length, max */
765 NULL
, data_len
, cli
->max_xmit
/* data, length, max */
772 if (!cli_receive_trans(cli
, SMBtrans2
,
774 &rdata
, &data_len
)) {
778 if (!rdata
|| data_len
< 22) {
783 *create_time
= interpret_long_date(rdata
+0);
786 *access_time
= interpret_long_date(rdata
+8);
789 *write_time
= interpret_long_date(rdata
+16);
792 *change_time
= interpret_long_date(rdata
+24);
795 *mode
= SVAL(rdata
, 32);
798 *size
= IVAL2_TO_SMB_BIG_UINT(rdata
,48);
801 *ino
= IVAL(rdata
, 64);
809 /****************************************************************************
811 ****************************************************************************/
813 bool cli_qpathinfo_streams(struct cli_state
*cli
, const char *fname
,
815 unsigned int *pnum_streams
,
816 struct stream_struct
**pstreams
)
818 unsigned int data_len
= 0;
819 unsigned int param_len
= 0;
820 uint16 setup
= TRANSACT2_QPATHINFO
;
822 char *rparam
=NULL
, *rdata
=NULL
;
824 unsigned int num_streams
;
825 struct stream_struct
*streams
;
827 size_t namelen
= 2*(strlen(fname
)+1);
829 param
= SMB_MALLOC_ARRAY(char, 6+namelen
+2);
835 SSVAL(p
, 0, SMB_FILE_STREAM_INFORMATION
);
837 p
+= clistr_push(cli
, p
, fname
, namelen
, STR_TERMINATE
);
839 param_len
= PTR_DIFF(p
, param
);
841 if (!cli_send_trans(cli
, SMBtrans2
,
843 -1, 0, /* fid, flags */
844 &setup
, 1, 0, /* setup, len, max */
845 param
, param_len
, 10, /* param, len, max */
846 NULL
, data_len
, cli
->max_xmit
/* data, len, max */
851 if (!cli_receive_trans(cli
, SMBtrans2
,
853 &rdata
, &data_len
)) {
866 while ((data_len
> ofs
) && (data_len
- ofs
>= 24)) {
870 struct stream_struct
*tmp
;
873 tmp
= TALLOC_REALLOC_ARRAY(mem_ctx
, streams
,
874 struct stream_struct
,
882 nlen
= IVAL(rdata
, ofs
+ 0x04);
884 streams
[num_streams
].size
= IVAL_TO_SMB_OFF_T(
886 streams
[num_streams
].alloc_size
= IVAL_TO_SMB_OFF_T(
889 if (nlen
> data_len
- (ofs
+ 24)) {
894 * We need to null-terminate src, how do I do this with
895 * convert_string_talloc??
898 tmp_buf
= TALLOC_ARRAY(streams
, uint8_t, nlen
+2);
899 if (tmp_buf
== NULL
) {
903 memcpy(tmp_buf
, rdata
+ofs
+24, nlen
);
907 if (!convert_string_talloc(streams
, CH_UTF16
, CH_UNIX
, tmp_buf
,
908 nlen
+2, &vstr
, &size
, false))
910 TALLOC_FREE(tmp_buf
);
914 TALLOC_FREE(tmp_buf
);
915 streams
[num_streams
].name
= (char *)vstr
;
918 len
= IVAL(rdata
, ofs
);
919 if (len
> data_len
- ofs
) {
929 *pnum_streams
= num_streams
;
934 TALLOC_FREE(streams
);
940 /****************************************************************************
941 Send a qfileinfo QUERY_FILE_NAME_INFO call.
942 ****************************************************************************/
944 bool cli_qfilename(struct cli_state
*cli
, int fnum
, char *name
, size_t namelen
)
946 unsigned int data_len
= 0;
947 unsigned int param_len
= 0;
948 uint16 setup
= TRANSACT2_QFILEINFO
;
950 char *rparam
=NULL
, *rdata
=NULL
;
953 SSVAL(param
, 0, fnum
);
954 SSVAL(param
, 2, SMB_QUERY_FILE_NAME_INFO
);
956 if (!cli_send_trans(cli
, SMBtrans2
,
958 -1, 0, /* fid, flags */
959 &setup
, 1, 0, /* setup, length, max */
960 param
, param_len
, 2, /* param, length, max */
961 NULL
, data_len
, cli
->max_xmit
/* data, length, max */
966 if (!cli_receive_trans(cli
, SMBtrans2
,
968 &rdata
, &data_len
)) {
972 if (!rdata
|| data_len
< 4) {
976 clistr_pull(cli
, name
, rdata
+4, namelen
, IVAL(rdata
, 0), STR_UNICODE
);
981 /****************************************************************************
982 Send a qfileinfo call.
983 ****************************************************************************/
985 bool cli_qfileinfo(struct cli_state
*cli
, int fnum
,
986 uint16
*mode
, SMB_OFF_T
*size
,
987 struct timespec
*create_time
,
988 struct timespec
*access_time
,
989 struct timespec
*write_time
,
990 struct timespec
*change_time
,
993 unsigned int data_len
= 0;
994 unsigned int param_len
= 0;
995 uint16 setup
= TRANSACT2_QFILEINFO
;
997 char *rparam
=NULL
, *rdata
=NULL
;
999 /* if its a win95 server then fail this - win95 totally screws it
1001 if (cli
->win95
) return False
;
1005 SSVAL(param
, 0, fnum
);
1006 SSVAL(param
, 2, SMB_QUERY_FILE_ALL_INFO
);
1008 if (!cli_send_trans(cli
, SMBtrans2
,
1010 -1, 0, /* fid, flags */
1011 &setup
, 1, 0, /* setup, length, max */
1012 param
, param_len
, 2, /* param, length, max */
1013 NULL
, data_len
, cli
->max_xmit
/* data, length, max */
1018 if (!cli_receive_trans(cli
, SMBtrans2
,
1019 &rparam
, ¶m_len
,
1020 &rdata
, &data_len
)) {
1024 if (!rdata
|| data_len
< 68) {
1029 *create_time
= interpret_long_date(rdata
+0);
1032 *access_time
= interpret_long_date(rdata
+8);
1035 *write_time
= interpret_long_date(rdata
+16);
1038 *change_time
= interpret_long_date(rdata
+24);
1041 *mode
= SVAL(rdata
, 32);
1044 *size
= IVAL2_TO_SMB_BIG_UINT(rdata
,48);
1047 *ino
= IVAL(rdata
, 64);
1055 /****************************************************************************
1056 Send a qpathinfo BASIC_INFO call.
1057 ****************************************************************************/
1059 bool cli_qpathinfo_basic( struct cli_state
*cli
, const char *name
,
1060 SMB_STRUCT_STAT
*sbuf
, uint32
*attributes
)
1062 unsigned int param_len
= 0;
1063 unsigned int data_len
= 0;
1064 uint16 setup
= TRANSACT2_QPATHINFO
;
1066 char *rparam
=NULL
, *rdata
=NULL
;
1071 TALLOC_CTX
*frame
= talloc_stackframe();
1073 path
= talloc_strdup(frame
, name
);
1081 if ( path
[len
-1] == '\\' || path
[len
-1] == '/') {
1084 nlen
= 2*(strlen(path
)+1);
1086 param
= TALLOC_ARRAY(frame
,char,6+nlen
+2);
1091 memset(param
, '\0', 6);
1093 SSVAL(p
, 0, SMB_QUERY_FILE_BASIC_INFO
);
1095 p
+= clistr_push(cli
, p
, path
, nlen
, STR_TERMINATE
);
1096 param_len
= PTR_DIFF(p
, param
);
1099 if (!cli_send_trans(cli
, SMBtrans2
,
1101 -1, 0, /* fid, flags */
1102 &setup
, 1, 0, /* setup, length, max */
1103 param
, param_len
, 2, /* param, length, max */
1104 NULL
, 0, cli
->max_xmit
/* data, length, max */
1112 if (!cli_receive_trans(cli
, SMBtrans2
,
1113 &rparam
, ¶m_len
,
1114 &rdata
, &data_len
)) {
1118 if (data_len
< 36) {
1124 set_atimespec(sbuf
, interpret_long_date( rdata
+8 )); /* Access time. */
1125 set_mtimespec(sbuf
, interpret_long_date( rdata
+16 )); /* Write time. */
1126 set_ctimespec(sbuf
, interpret_long_date( rdata
+24 )); /* Change time. */
1128 *attributes
= IVAL( rdata
, 32 );
1136 /****************************************************************************
1137 Send a qfileinfo call.
1138 ****************************************************************************/
1140 bool cli_qfileinfo_test(struct cli_state
*cli
, int fnum
, int level
, char **poutdata
, uint32
*poutlen
)
1142 unsigned int data_len
= 0;
1143 unsigned int param_len
= 0;
1144 uint16 setup
= TRANSACT2_QFILEINFO
;
1146 char *rparam
=NULL
, *rdata
=NULL
;
1151 /* if its a win95 server then fail this - win95 totally screws it
1158 SSVAL(param
, 0, fnum
);
1159 SSVAL(param
, 2, level
);
1161 if (!cli_send_trans(cli
, SMBtrans2
,
1163 -1, 0, /* fid, flags */
1164 &setup
, 1, 0, /* setup, length, max */
1165 param
, param_len
, 2, /* param, length, max */
1166 NULL
, data_len
, cli
->max_xmit
/* data, length, max */
1171 if (!cli_receive_trans(cli
, SMBtrans2
,
1172 &rparam
, ¶m_len
,
1173 &rdata
, &data_len
)) {
1177 *poutdata
= (char *)memdup(rdata
, data_len
);
1184 *poutlen
= data_len
;
1191 /****************************************************************************
1192 Send a qpathinfo SMB_QUERY_FILE_ALT_NAME_INFO call.
1193 ****************************************************************************/
1195 NTSTATUS
cli_qpathinfo_alt_name(struct cli_state
*cli
, const char *fname
, fstring alt_name
)
1197 unsigned int data_len
= 0;
1198 unsigned int param_len
= 0;
1199 uint16 setup
= TRANSACT2_QPATHINFO
;
1201 char *rparam
=NULL
, *rdata
=NULL
;
1206 size_t nlen
= 2*(strlen(fname
)+1);
1208 param
= SMB_MALLOC_ARRAY(char, 6+nlen
+2);
1210 return NT_STATUS_NO_MEMORY
;
1213 memset(param
, '\0', 6);
1214 SSVAL(p
, 0, SMB_QUERY_FILE_ALT_NAME_INFO
);
1216 p
+= clistr_push(cli
, p
, fname
, nlen
, STR_TERMINATE
);
1217 param_len
= PTR_DIFF(p
, param
);
1220 ret
= (cli_send_trans(cli
, SMBtrans2
,
1222 -1, 0, /* fid, flags */
1223 &setup
, 1, 0, /* setup, length, max */
1224 param
, param_len
, 10, /* param, length, max */
1225 NULL
, data_len
, cli
->max_xmit
/* data, length, max */
1227 cli_receive_trans(cli
, SMBtrans2
,
1228 &rparam
, ¶m_len
,
1229 &rdata
, &data_len
));
1230 if (!ret
&& cli_is_dos_error(cli
)) {
1231 /* we need to work around a Win95 bug - sometimes
1232 it gives ERRSRV/ERRerror temprarily */
1235 cli_dos_error(cli
, &eclass
, &ecode
);
1236 if (eclass
!= ERRSRV
|| ecode
!= ERRerror
) break;
1239 } while (count
-- && ret
==False
);
1243 if (!ret
|| !rdata
|| data_len
< 4) {
1244 return NT_STATUS_UNSUCCESSFUL
;
1247 len
= IVAL(rdata
, 0);
1249 if (len
> data_len
- 4) {
1250 return NT_STATUS_INVALID_NETWORK_RESPONSE
;
1253 clistr_pull(cli
, alt_name
, rdata
+4, sizeof(fstring
), len
, STR_UNICODE
);
1258 return NT_STATUS_OK
;