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();
367 uint32_t entry_stype
;
369 if (p
+ 26 > rdata_end
) {
375 comment_offset
= (IVAL(p
,22) & 0xFFFF)-converter
;
376 cmnt
= comment_offset
?(rdata
+comment_offset
):"";
378 if (comment_offset
< 0 || comment_offset
> (int)rdrcnt
) {
383 /* Work out the comment length. */
384 for (p1
= cmnt
, len
= 0; *p1
&&
385 p1
< rdata_end
; len
++)
391 entry_stype
= IVAL(p
,18) & ~SV_TYPE_LOCAL_LIST_ONLY
;
393 pull_string_talloc(frame
,rdata
,0,
394 &s1
,sname
,16,STR_ASCII
);
395 pull_string_talloc(frame
,rdata
,0,
396 &s2
,cmnt
,len
,STR_ASCII
);
403 fn(s1
, entry_stype
, s2
, state
);
407 /* We are done with the old last entry, so now we can free it */
409 SAFE_FREE(last_entry
); /* This will set it to null */
412 /* We always make a copy of the last entry if we have one */
414 last_entry
= smb_xstrdup(sname
);
417 /* If we have more data, but no last entry then error out */
418 if (!last_entry
&& (res
== ERRmoredata
)) {
427 } while ((res
== ERRmoredata
) && (total_cnt
> return_cnt
));
431 SAFE_FREE(last_entry
);
434 errno
= cli_errno(cli
);
437 /* this is a very special case, when the domain master for the
438 work group isn't part of the work group itself, there is something
444 return(return_cnt
> 0);
447 /****************************************************************************
448 Send a SamOEMChangePassword command.
449 ****************************************************************************/
451 bool cli_oem_change_password(struct cli_state
*cli
, const char *user
, const char *new_password
,
452 const char *old_password
)
455 unsigned char data
[532];
457 unsigned char old_pw_hash
[16];
458 unsigned char new_pw_hash
[16];
459 unsigned int data_len
;
460 unsigned int param_len
= 0;
463 unsigned int rprcnt
, rdrcnt
;
465 if (strlen(user
) >= sizeof(fstring
)-1) {
466 DEBUG(0,("cli_oem_change_password: user name %s is too long.\n", user
));
470 SSVAL(p
,0,214); /* SamOEMChangePassword command. */
472 strlcpy(p
, "zsT", sizeof(param
)-PTR_DIFF(p
,param
));
473 p
= skip_string(param
,sizeof(param
),p
);
474 strlcpy(p
, "B516B16", sizeof(param
)-PTR_DIFF(p
,param
));
475 p
= skip_string(param
,sizeof(param
),p
);
476 strlcpy(p
,user
, sizeof(param
)-PTR_DIFF(p
,param
));
477 p
= skip_string(param
,sizeof(param
),p
);
481 param_len
= PTR_DIFF(p
,param
);
484 * Get the Lanman hash of the old password, we
485 * use this as the key to make_oem_passwd_hash().
487 E_deshash(old_password
, old_pw_hash
);
489 encode_pw_buffer(data
, new_password
, STR_ASCII
);
491 #ifdef DEBUG_PASSWORD
492 DEBUG(100,("make_oem_passwd_hash\n"));
493 dump_data(100, data
, 516);
495 SamOEMhash( (unsigned char *)data
, (unsigned char *)old_pw_hash
, 516);
498 * Now place the old password hash in the data.
500 E_deshash(new_password
, new_pw_hash
);
502 E_old_pw_hash( new_pw_hash
, old_pw_hash
, (uchar
*)&data
[516]);
506 if (cli_send_trans(cli
,SMBtrans
,
507 PIPE_LANMAN
, /* name */
508 0,0, /* fid, flags */
509 NULL
,0,0, /* setup, length, max */
510 param
,param_len
,2, /* param, length, max */
511 (char *)data
,data_len
,0 /* data, length, max */
513 DEBUG(0,("cli_oem_change_password: Failed to send password change for user %s\n",
518 if (!cli_receive_trans(cli
,SMBtrans
,
521 DEBUG(0,("cli_oem_change_password: Failed to recieve reply to password change for user %s\n",
527 cli
->rap_error
= SVAL(rparam
,0);
533 return (cli
->rap_error
== 0);
536 /****************************************************************************
537 Send a qpathinfo call.
538 ****************************************************************************/
540 bool cli_qpathinfo(struct cli_state
*cli
,
548 unsigned int data_len
= 0;
549 unsigned int param_len
= 0;
550 unsigned int rparam_len
, rdata_len
;
551 uint16 setup
= TRANSACT2_QPATHINFO
;
553 char *rparam
=NULL
, *rdata
=NULL
;
556 time_t (*date_fn
)(struct cli_state
*, const void *);
558 size_t nlen
= 2*(strlen(fname
)+1);
560 param
= SMB_MALLOC_ARRAY(char, 6+nlen
+2);
566 SSVAL(p
, 0, SMB_INFO_STANDARD
);
568 p
+= clistr_push(cli
, p
, fname
, nlen
, STR_TERMINATE
);
569 param_len
= PTR_DIFF(p
, param
);
572 ret
= (cli_send_trans(cli
, SMBtrans2
,
574 -1, 0, /* fid, flags */
575 &setup
, 1, 0, /* setup, length, max */
576 param
, param_len
, 10, /* param, length, max */
577 NULL
, data_len
, cli
->max_xmit
/* data, length, max */
579 cli_receive_trans(cli
, SMBtrans2
,
580 &rparam
, &rparam_len
,
581 &rdata
, &rdata_len
));
582 if (!cli_is_dos_error(cli
)) break;
584 /* we need to work around a Win95 bug - sometimes
585 it gives ERRSRV/ERRerror temprarily */
588 cli_dos_error(cli
, &eclass
, &ecode
);
589 if (eclass
!= ERRSRV
|| ecode
!= ERRerror
) break;
592 } while (count
-- && ret
==False
);
595 if (!ret
|| !rdata
|| rdata_len
< 22) {
600 date_fn
= cli_make_unix_date
;
602 date_fn
= cli_make_unix_date2
;
606 *change_time
= date_fn(cli
, rdata
+0);
609 *access_time
= date_fn(cli
, rdata
+4);
612 *write_time
= date_fn(cli
, rdata
+8);
615 *size
= IVAL(rdata
, 12);
618 *mode
= SVAL(rdata
,l1_attrFile
);
626 /****************************************************************************
627 Send a setpathinfo call.
628 ****************************************************************************/
630 bool cli_setpathinfo(struct cli_state
*cli
, const char *fname
,
637 unsigned int data_len
= 0;
638 unsigned int param_len
= 0;
639 unsigned int rparam_len
, rdata_len
;
640 uint16 setup
= TRANSACT2_SETPATHINFO
;
643 char *rparam
=NULL
, *rdata
=NULL
;
647 size_t nlen
= 2*(strlen(fname
)+1);
649 param
= SMB_MALLOC_ARRAY(char, 6+nlen
+2);
653 memset(param
, '\0', 6);
654 memset(data
, 0, sizeof(data
));
658 /* Add the information level */
659 SSVAL(p
, 0, SMB_FILE_BASIC_INFORMATION
);
664 /* Add the file name */
665 p
+= clistr_push(cli
, p
, fname
, nlen
, STR_TERMINATE
);
667 param_len
= PTR_DIFF(p
, param
);
672 * Add the create, last access, modification, and status change times
674 put_long_date(p
, create_time
);
677 put_long_date(p
, access_time
);
680 put_long_date(p
, write_time
);
683 put_long_date(p
, change_time
);
694 data_len
= PTR_DIFF(p
, data
);
697 ret
= (cli_send_trans(cli
, SMBtrans2
,
699 -1, 0, /* fid, flags */
700 &setup
, 1, 0, /* setup, length, max */
701 param
, param_len
, 10, /* param, length, max */
702 data
, data_len
, cli
->max_xmit
/* data, length, max */
704 cli_receive_trans(cli
, SMBtrans2
,
705 &rparam
, &rparam_len
,
706 &rdata
, &rdata_len
));
707 if (!cli_is_dos_error(cli
)) break;
709 /* we need to work around a Win95 bug - sometimes
710 it gives ERRSRV/ERRerror temprarily */
713 cli_dos_error(cli
, &eclass
, &ecode
);
714 if (eclass
!= ERRSRV
|| ecode
!= ERRerror
) break;
717 } while (count
-- && ret
==False
);
729 /****************************************************************************
730 Send a qpathinfo call with the SMB_QUERY_FILE_ALL_INFO info level.
731 ****************************************************************************/
733 bool cli_qpathinfo2(struct cli_state
*cli
, const char *fname
,
734 struct timespec
*create_time
,
735 struct timespec
*access_time
,
736 struct timespec
*write_time
,
737 struct timespec
*change_time
,
738 SMB_OFF_T
*size
, uint16
*mode
,
741 unsigned int data_len
= 0;
742 unsigned int param_len
= 0;
743 uint16 setup
= TRANSACT2_QPATHINFO
;
745 char *rparam
=NULL
, *rdata
=NULL
;
747 size_t nlen
= 2*(strlen(fname
)+1);
749 param
= SMB_MALLOC_ARRAY(char, 6+nlen
+2);
754 memset(param
, '\0', 6);
755 SSVAL(p
, 0, SMB_QUERY_FILE_ALL_INFO
);
757 p
+= clistr_push(cli
, p
, fname
, nlen
, STR_TERMINATE
);
759 param_len
= PTR_DIFF(p
, param
);
761 if (!cli_send_trans(cli
, SMBtrans2
,
763 -1, 0, /* fid, flags */
764 &setup
, 1, 0, /* setup, length, max */
765 param
, param_len
, 10, /* param, length, max */
766 NULL
, data_len
, cli
->max_xmit
/* data, length, max */
773 if (!cli_receive_trans(cli
, SMBtrans2
,
775 &rdata
, &data_len
)) {
779 if (!rdata
|| data_len
< 22) {
784 *create_time
= interpret_long_date(rdata
+0);
787 *access_time
= interpret_long_date(rdata
+8);
790 *write_time
= interpret_long_date(rdata
+16);
793 *change_time
= interpret_long_date(rdata
+24);
796 *mode
= SVAL(rdata
, 32);
799 *size
= IVAL2_TO_SMB_BIG_UINT(rdata
,48);
802 *ino
= IVAL(rdata
, 64);
810 /****************************************************************************
812 ****************************************************************************/
814 bool cli_qpathinfo_streams(struct cli_state
*cli
, const char *fname
,
816 unsigned int *pnum_streams
,
817 struct stream_struct
**pstreams
)
819 unsigned int data_len
= 0;
820 unsigned int param_len
= 0;
821 uint16 setup
= TRANSACT2_QPATHINFO
;
823 char *rparam
=NULL
, *rdata
=NULL
;
825 unsigned int num_streams
;
826 struct stream_struct
*streams
;
828 size_t namelen
= 2*(strlen(fname
)+1);
830 param
= SMB_MALLOC_ARRAY(char, 6+namelen
+2);
836 SSVAL(p
, 0, SMB_FILE_STREAM_INFORMATION
);
838 p
+= clistr_push(cli
, p
, fname
, namelen
, STR_TERMINATE
);
840 param_len
= PTR_DIFF(p
, param
);
842 if (!cli_send_trans(cli
, SMBtrans2
,
844 -1, 0, /* fid, flags */
845 &setup
, 1, 0, /* setup, len, max */
846 param
, param_len
, 10, /* param, len, max */
847 NULL
, data_len
, cli
->max_xmit
/* data, len, max */
852 if (!cli_receive_trans(cli
, SMBtrans2
,
854 &rdata
, &data_len
)) {
867 while ((data_len
> ofs
) && (data_len
- ofs
>= 24)) {
871 struct stream_struct
*tmp
;
874 tmp
= TALLOC_REALLOC_ARRAY(mem_ctx
, streams
,
875 struct stream_struct
,
883 nlen
= IVAL(rdata
, ofs
+ 0x04);
885 streams
[num_streams
].size
= IVAL_TO_SMB_OFF_T(
887 streams
[num_streams
].alloc_size
= IVAL_TO_SMB_OFF_T(
890 if (nlen
> data_len
- (ofs
+ 24)) {
895 * We need to null-terminate src, how do I do this with
896 * convert_string_talloc??
899 tmp_buf
= TALLOC_ARRAY(streams
, uint8_t, nlen
+2);
900 if (tmp_buf
== NULL
) {
904 memcpy(tmp_buf
, rdata
+ofs
+24, nlen
);
908 if (!convert_string_talloc(streams
, CH_UTF16
, CH_UNIX
, tmp_buf
,
909 nlen
+2, &vstr
, &size
, false))
911 TALLOC_FREE(tmp_buf
);
915 TALLOC_FREE(tmp_buf
);
916 streams
[num_streams
].name
= (char *)vstr
;
919 len
= IVAL(rdata
, ofs
);
920 if (len
> data_len
- ofs
) {
930 *pnum_streams
= num_streams
;
935 TALLOC_FREE(streams
);
941 /****************************************************************************
942 Send a qfileinfo QUERY_FILE_NAME_INFO call.
943 ****************************************************************************/
945 bool cli_qfilename(struct cli_state
*cli
, int fnum
, char *name
, size_t namelen
)
947 unsigned int data_len
= 0;
948 unsigned int param_len
= 0;
949 uint16 setup
= TRANSACT2_QFILEINFO
;
951 char *rparam
=NULL
, *rdata
=NULL
;
954 SSVAL(param
, 0, fnum
);
955 SSVAL(param
, 2, SMB_QUERY_FILE_NAME_INFO
);
957 if (!cli_send_trans(cli
, SMBtrans2
,
959 -1, 0, /* fid, flags */
960 &setup
, 1, 0, /* setup, length, max */
961 param
, param_len
, 2, /* param, length, max */
962 NULL
, data_len
, cli
->max_xmit
/* data, length, max */
967 if (!cli_receive_trans(cli
, SMBtrans2
,
969 &rdata
, &data_len
)) {
973 if (!rdata
|| data_len
< 4) {
977 clistr_pull(cli
, name
, rdata
+4, namelen
, IVAL(rdata
, 0), STR_UNICODE
);
982 /****************************************************************************
983 Send a qfileinfo call.
984 ****************************************************************************/
986 bool cli_qfileinfo(struct cli_state
*cli
, int fnum
,
987 uint16
*mode
, SMB_OFF_T
*size
,
988 struct timespec
*create_time
,
989 struct timespec
*access_time
,
990 struct timespec
*write_time
,
991 struct timespec
*change_time
,
994 unsigned int data_len
= 0;
995 unsigned int param_len
= 0;
996 uint16 setup
= TRANSACT2_QFILEINFO
;
998 char *rparam
=NULL
, *rdata
=NULL
;
1000 /* if its a win95 server then fail this - win95 totally screws it
1002 if (cli
->win95
) return False
;
1006 SSVAL(param
, 0, fnum
);
1007 SSVAL(param
, 2, SMB_QUERY_FILE_ALL_INFO
);
1009 if (!cli_send_trans(cli
, SMBtrans2
,
1011 -1, 0, /* fid, flags */
1012 &setup
, 1, 0, /* setup, length, max */
1013 param
, param_len
, 2, /* param, length, max */
1014 NULL
, data_len
, cli
->max_xmit
/* data, length, max */
1019 if (!cli_receive_trans(cli
, SMBtrans2
,
1020 &rparam
, ¶m_len
,
1021 &rdata
, &data_len
)) {
1025 if (!rdata
|| data_len
< 68) {
1030 *create_time
= interpret_long_date(rdata
+0);
1033 *access_time
= interpret_long_date(rdata
+8);
1036 *write_time
= interpret_long_date(rdata
+16);
1039 *change_time
= interpret_long_date(rdata
+24);
1042 *mode
= SVAL(rdata
, 32);
1045 *size
= IVAL2_TO_SMB_BIG_UINT(rdata
,48);
1048 *ino
= IVAL(rdata
, 64);
1056 /****************************************************************************
1057 Send a qpathinfo BASIC_INFO call.
1058 ****************************************************************************/
1060 bool cli_qpathinfo_basic( struct cli_state
*cli
, const char *name
,
1061 SMB_STRUCT_STAT
*sbuf
, uint32
*attributes
)
1063 unsigned int param_len
= 0;
1064 unsigned int data_len
= 0;
1065 uint16 setup
= TRANSACT2_QPATHINFO
;
1067 char *rparam
=NULL
, *rdata
=NULL
;
1072 TALLOC_CTX
*frame
= talloc_stackframe();
1074 path
= talloc_strdup(frame
, name
);
1082 if ( path
[len
-1] == '\\' || path
[len
-1] == '/') {
1085 nlen
= 2*(strlen(path
)+1);
1087 param
= TALLOC_ARRAY(frame
,char,6+nlen
+2);
1092 memset(param
, '\0', 6);
1094 SSVAL(p
, 0, SMB_QUERY_FILE_BASIC_INFO
);
1096 p
+= clistr_push(cli
, p
, path
, nlen
, STR_TERMINATE
);
1097 param_len
= PTR_DIFF(p
, param
);
1100 if (!cli_send_trans(cli
, SMBtrans2
,
1102 -1, 0, /* fid, flags */
1103 &setup
, 1, 0, /* setup, length, max */
1104 param
, param_len
, 2, /* param, length, max */
1105 NULL
, 0, cli
->max_xmit
/* data, length, max */
1113 if (!cli_receive_trans(cli
, SMBtrans2
,
1114 &rparam
, ¶m_len
,
1115 &rdata
, &data_len
)) {
1119 if (data_len
< 36) {
1125 set_atimespec(sbuf
, interpret_long_date( rdata
+8 )); /* Access time. */
1126 set_mtimespec(sbuf
, interpret_long_date( rdata
+16 )); /* Write time. */
1127 set_ctimespec(sbuf
, interpret_long_date( rdata
+24 )); /* Change time. */
1129 *attributes
= IVAL( rdata
, 32 );
1137 /****************************************************************************
1138 Send a qfileinfo call.
1139 ****************************************************************************/
1141 bool cli_qfileinfo_test(struct cli_state
*cli
, int fnum
, int level
, char **poutdata
, uint32
*poutlen
)
1143 unsigned int data_len
= 0;
1144 unsigned int param_len
= 0;
1145 uint16 setup
= TRANSACT2_QFILEINFO
;
1147 char *rparam
=NULL
, *rdata
=NULL
;
1152 /* if its a win95 server then fail this - win95 totally screws it
1159 SSVAL(param
, 0, fnum
);
1160 SSVAL(param
, 2, level
);
1162 if (!cli_send_trans(cli
, SMBtrans2
,
1164 -1, 0, /* fid, flags */
1165 &setup
, 1, 0, /* setup, length, max */
1166 param
, param_len
, 2, /* param, length, max */
1167 NULL
, data_len
, cli
->max_xmit
/* data, length, max */
1172 if (!cli_receive_trans(cli
, SMBtrans2
,
1173 &rparam
, ¶m_len
,
1174 &rdata
, &data_len
)) {
1178 *poutdata
= (char *)memdup(rdata
, data_len
);
1185 *poutlen
= data_len
;
1192 /****************************************************************************
1193 Send a qpathinfo SMB_QUERY_FILE_ALT_NAME_INFO call.
1194 ****************************************************************************/
1196 NTSTATUS
cli_qpathinfo_alt_name(struct cli_state
*cli
, const char *fname
, fstring alt_name
)
1198 unsigned int data_len
= 0;
1199 unsigned int param_len
= 0;
1200 uint16 setup
= TRANSACT2_QPATHINFO
;
1202 char *rparam
=NULL
, *rdata
=NULL
;
1207 size_t nlen
= 2*(strlen(fname
)+1);
1209 param
= SMB_MALLOC_ARRAY(char, 6+nlen
+2);
1211 return NT_STATUS_NO_MEMORY
;
1214 memset(param
, '\0', 6);
1215 SSVAL(p
, 0, SMB_QUERY_FILE_ALT_NAME_INFO
);
1217 p
+= clistr_push(cli
, p
, fname
, nlen
, STR_TERMINATE
);
1218 param_len
= PTR_DIFF(p
, param
);
1221 ret
= (cli_send_trans(cli
, SMBtrans2
,
1223 -1, 0, /* fid, flags */
1224 &setup
, 1, 0, /* setup, length, max */
1225 param
, param_len
, 10, /* param, length, max */
1226 NULL
, data_len
, cli
->max_xmit
/* data, length, max */
1228 cli_receive_trans(cli
, SMBtrans2
,
1229 &rparam
, ¶m_len
,
1230 &rdata
, &data_len
));
1231 if (!ret
&& cli_is_dos_error(cli
)) {
1232 /* we need to work around a Win95 bug - sometimes
1233 it gives ERRSRV/ERRerror temprarily */
1236 cli_dos_error(cli
, &eclass
, &ecode
);
1237 if (eclass
!= ERRSRV
|| ecode
!= ERRerror
) break;
1240 } while (count
-- && ret
==False
);
1244 if (!ret
|| !rdata
|| data_len
< 4) {
1245 return NT_STATUS_UNSUCCESSFUL
;
1248 len
= IVAL(rdata
, 0);
1250 if (len
> data_len
- 4) {
1251 return NT_STATUS_INVALID_NETWORK_RESPONSE
;
1254 clistr_pull(cli
, alt_name
, rdata
+4, sizeof(fstring
), len
, STR_UNICODE
);
1259 return NT_STATUS_OK
;