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 /****************************************************************************
26 ****************************************************************************/
28 bool cli_api(struct cli_state
*cli
,
29 char *param
, int prcnt
, int mprcnt
,
30 char *data
, int drcnt
, int mdrcnt
,
31 char **rparam
, unsigned int *rprcnt
,
32 char **rdata
, unsigned int *rdrcnt
)
34 cli_send_trans(cli
,SMBtrans
,
35 PIPE_LANMAN
, /* Name */
37 NULL
,0,0, /* Setup, length, max */
38 param
, prcnt
, mprcnt
, /* Params, length, max */
39 data
, drcnt
, mdrcnt
/* Data, length, max */
42 return (cli_receive_trans(cli
,SMBtrans
,
47 /****************************************************************************
48 Perform a NetWkstaUserLogon.
49 ****************************************************************************/
51 bool cli_NetWkstaUserLogon(struct cli_state
*cli
,char *user
, char *workstation
)
56 unsigned int rdrcnt
,rprcnt
;
59 memset(param
, 0, sizeof(param
));
61 /* send a SMBtrans command with api NetWkstaUserLogon */
63 SSVAL(p
,0,132); /* api number */
65 strlcpy(p
,"OOWb54WrLh",sizeof(param
)-PTR_DIFF(p
,param
));
66 p
= skip_string(param
,sizeof(param
),p
);
67 strlcpy(p
,"WB21BWDWWDDDDDDDzzzD",sizeof(param
)-PTR_DIFF(p
,param
));
68 p
= skip_string(param
,sizeof(param
),p
);
71 strlcpy(p
,user
,sizeof(param
)-PTR_DIFF(p
,param
));
77 strlcpy(p
, workstation
,sizeof(param
)-PTR_DIFF(p
,param
));
80 SSVAL(p
, 0, CLI_BUFFER_SIZE
);
82 SSVAL(p
, 0, CLI_BUFFER_SIZE
);
86 param
, PTR_DIFF(p
,param
),1024, /* param, length, max */
87 NULL
, 0, CLI_BUFFER_SIZE
, /* data, length, max */
88 &rparam
, &rprcnt
, /* return params, return size */
89 &rdata
, &rdrcnt
/* return data, return size */
91 cli
->rap_error
= rparam
? SVAL(rparam
,0) : -1;
94 if (cli
->rap_error
== 0) {
95 DEBUG(4,("NetWkstaUserLogon success\n"));
96 cli
->privileges
= SVAL(p
, 24);
97 /* The cli->eff_name field used to be set here
98 but it wasn't used anywhere else. */
100 DEBUG(1,("NetwkstaUserLogon gave error %d\n", cli
->rap_error
));
106 return (cli
->rap_error
== 0);
109 /****************************************************************************
110 Call a NetShareEnum - try and browse available connections on a host.
111 ****************************************************************************/
113 int cli_RNetShareEnum(struct cli_state
*cli
, void (*fn
)(const char *, uint32
, const char *, void *), void *state
)
118 unsigned int rdrcnt
,rprcnt
;
122 /* now send a SMBtrans command with api RNetShareEnum */
124 SSVAL(p
,0,0); /* api number */
126 strlcpy(p
,"WrLeh",sizeof(param
)-PTR_DIFF(p
,param
));
127 p
= skip_string(param
,sizeof(param
),p
);
128 strlcpy(p
,"B13BWz",sizeof(param
)-PTR_DIFF(p
,param
));
129 p
= skip_string(param
,sizeof(param
),p
);
132 * Win2k needs a *smaller* buffer than 0xFFFF here -
133 * it returns "out of server memory" with 0xFFFF !!! JRA.
139 param
, PTR_DIFF(p
,param
), 1024, /* Param, length, maxlen */
140 NULL
, 0, 0xFFE0, /* data, length, maxlen - Win2k needs a small buffer here too ! */
141 &rparam
, &rprcnt
, /* return params, length */
142 &rdata
, &rdrcnt
)) /* return data, length */
144 int res
= rparam
? SVAL(rparam
,0) : -1;
146 if (res
== 0 || res
== ERRmoredata
) {
147 int converter
=SVAL(rparam
,2);
149 char *rdata_end
= rdata
+ rdrcnt
;
151 count
=SVAL(rparam
,4);
154 for (i
=0;i
<count
;i
++,p
+=20) {
162 TALLOC_CTX
*frame
= talloc_stackframe();
164 if (p
+ 20 > rdata_end
) {
171 comment_offset
= (IVAL(p
,16) & 0xFFFF) - converter
;
172 if (comment_offset
< 0 ||
173 comment_offset
> (int)rdrcnt
) {
177 cmnt
= comment_offset
?(rdata
+comment_offset
):"";
179 /* Work out the comment length. */
180 for (p1
= cmnt
, len
= 0; *p1
&&
181 p1
< rdata_end
; len
++)
186 pull_string_talloc(frame
,rdata
,0,
187 &s1
,sname
,14,STR_ASCII
);
188 pull_string_talloc(frame
,rdata
,0,
189 &s2
,cmnt
,len
,STR_ASCII
);
195 fn(s1
, type
, s2
, state
);
200 DEBUG(4,("NetShareEnum res=%d\n", res
));
203 DEBUG(4,("NetShareEnum failed\n"));
212 /****************************************************************************
213 Call a NetServerEnum for the specified workgroup and servertype mask. This
214 function then calls the specified callback function for each name returned.
216 The callback function takes 4 arguments: the machine name, the server type,
217 the comment and a state pointer.
218 ****************************************************************************/
220 bool cli_NetServerEnum(struct cli_state
*cli
, char *workgroup
, uint32 stype
,
221 void (*fn
)(const char *, uint32
, const char *, void *),
226 char *rdata_end
= NULL
;
227 unsigned int rdrcnt
,rprcnt
;
232 uint32 func
= RAP_NetServerEnum2
;
233 char *last_entry
= NULL
;
238 errno
= 0; /* reset */
241 * This may take more than one transaction, so we should loop until
242 * we no longer get a more data to process or we have all of the
246 /* send a SMBtrans command with api NetServerEnum */
248 SIVAL(p
,0,func
); /* api number */
251 if (func
== RAP_NetServerEnum3
) {
252 strlcpy(p
,"WrLehDzz", sizeof(param
)-PTR_DIFF(p
,param
));
254 strlcpy(p
,"WrLehDz", sizeof(param
)-PTR_DIFF(p
,param
));
257 p
= skip_string(param
, sizeof(param
), p
);
258 strlcpy(p
,"B16BBDz", sizeof(param
)-PTR_DIFF(p
,param
));
260 p
= skip_string(param
, sizeof(param
), p
);
262 SSVAL(p
,2,CLI_BUFFER_SIZE
);
267 /* If we have more data, tell the server where
272 sizeof(param
) - PTR_DIFF(p
,param
) - 1,
273 STR_TERMINATE
|STR_UPPER
);
275 if (len
== (size_t)-1) {
276 SAFE_FREE(last_entry
);
281 if (func
== RAP_NetServerEnum3
) {
283 last_entry
? last_entry
: "",
284 sizeof(param
) - PTR_DIFF(p
,param
) - 1,
287 if (len
== (size_t)-1) {
288 SAFE_FREE(last_entry
);
294 /* Next time through we need to use the continue api */
295 func
= RAP_NetServerEnum3
;
298 param
, PTR_DIFF(p
,param
), 8, /* params, length, max */
299 NULL
, 0, CLI_BUFFER_SIZE
, /* data, length, max */
300 &rparam
, &rprcnt
, /* return params, return size */
301 &rdata
, &rdrcnt
)) { /* return data, return size */
303 /* break out of the loop on error */
308 rdata_end
= rdata
+ rdrcnt
;
309 res
= rparam
? SVAL(rparam
,0) : -1;
311 if (res
== 0 || res
== ERRmoredata
||
312 (res
!= -1 && cli_errno(cli
) == 0)) {
315 int converter
=SVAL(rparam
,2);
317 /* Get the number of items returned in this buffer */
318 count
= SVAL(rparam
, 4);
320 /* The next field contains the number of items left,
321 * including those returned in this buffer. So the
322 * first time through this should contain all of the
325 if (total_cnt
== 0) {
326 total_cnt
= SVAL(rparam
, 6);
329 /* Keep track of how many we have read */
333 /* The last name in the previous NetServerEnum reply is
334 * sent back to server in the NetServerEnum3 request
335 * (last_entry). The next reply should repeat this entry
336 * as the first element. We have no proof that this is
337 * always true, but from traces that seems to be the
338 * behavior from Window Servers. So first lets do a lot
339 * of checking, just being paranoid. If the string
340 * matches then we already saw this entry so skip it.
342 * NOTE: sv1_name field must be null terminated and has
343 * a max size of 16 (NetBIOS Name).
345 if (last_entry
&& count
&& p
&&
346 (strncmp(last_entry
, p
, 16) == 0)) {
347 count
-= 1; /* Skip this entry */
348 return_cnt
= -1; /* Not part of total, so don't count. */
349 p
= rdata
+ 26; /* Skip the whole record */
352 for (i
= 0; i
< count
; i
++, p
+= 26) {
357 TALLOC_CTX
*frame
= talloc_stackframe();
358 uint32_t entry_stype
;
360 if (p
+ 26 > rdata_end
) {
366 comment_offset
= (IVAL(p
,22) & 0xFFFF)-converter
;
367 cmnt
= comment_offset
?(rdata
+comment_offset
):"";
369 if (comment_offset
< 0 || comment_offset
> (int)rdrcnt
) {
374 /* Work out the comment length. */
375 for (p1
= cmnt
, len
= 0; *p1
&&
376 p1
< rdata_end
; len
++)
382 entry_stype
= IVAL(p
,18) & ~SV_TYPE_LOCAL_LIST_ONLY
;
384 pull_string_talloc(frame
,rdata
,0,
385 &s1
,sname
,16,STR_ASCII
);
386 pull_string_talloc(frame
,rdata
,0,
387 &s2
,cmnt
,len
,STR_ASCII
);
394 fn(s1
, entry_stype
, s2
, state
);
398 /* We are done with the old last entry, so now we can free it */
400 SAFE_FREE(last_entry
); /* This will set it to null */
403 /* We always make a copy of the last entry if we have one */
405 last_entry
= smb_xstrdup(sname
);
408 /* If we have more data, but no last entry then error out */
409 if (!last_entry
&& (res
== ERRmoredata
)) {
418 } while ((res
== ERRmoredata
) && (total_cnt
> return_cnt
));
422 SAFE_FREE(last_entry
);
425 errno
= cli_errno(cli
);
428 /* this is a very special case, when the domain master for the
429 work group isn't part of the work group itself, there is something
435 return(return_cnt
> 0);
438 /****************************************************************************
439 Send a SamOEMChangePassword command.
440 ****************************************************************************/
442 bool cli_oem_change_password(struct cli_state
*cli
, const char *user
, const char *new_password
,
443 const char *old_password
)
446 unsigned char data
[532];
448 unsigned char old_pw_hash
[16];
449 unsigned char new_pw_hash
[16];
450 unsigned int data_len
;
451 unsigned int param_len
= 0;
454 unsigned int rprcnt
, rdrcnt
;
456 if (strlen(user
) >= sizeof(fstring
)-1) {
457 DEBUG(0,("cli_oem_change_password: user name %s is too long.\n", user
));
461 SSVAL(p
,0,214); /* SamOEMChangePassword command. */
463 strlcpy(p
, "zsT", sizeof(param
)-PTR_DIFF(p
,param
));
464 p
= skip_string(param
,sizeof(param
),p
);
465 strlcpy(p
, "B516B16", sizeof(param
)-PTR_DIFF(p
,param
));
466 p
= skip_string(param
,sizeof(param
),p
);
467 strlcpy(p
,user
, sizeof(param
)-PTR_DIFF(p
,param
));
468 p
= skip_string(param
,sizeof(param
),p
);
472 param_len
= PTR_DIFF(p
,param
);
475 * Get the Lanman hash of the old password, we
476 * use this as the key to make_oem_passwd_hash().
478 E_deshash(old_password
, old_pw_hash
);
480 encode_pw_buffer(data
, new_password
, STR_ASCII
);
482 #ifdef DEBUG_PASSWORD
483 DEBUG(100,("make_oem_passwd_hash\n"));
484 dump_data(100, data
, 516);
486 SamOEMhash( (unsigned char *)data
, (unsigned char *)old_pw_hash
, 516);
489 * Now place the old password hash in the data.
491 E_deshash(new_password
, new_pw_hash
);
493 E_old_pw_hash( new_pw_hash
, old_pw_hash
, (uchar
*)&data
[516]);
497 if (cli_send_trans(cli
,SMBtrans
,
498 PIPE_LANMAN
, /* name */
499 0,0, /* fid, flags */
500 NULL
,0,0, /* setup, length, max */
501 param
,param_len
,2, /* param, length, max */
502 (char *)data
,data_len
,0 /* data, length, max */
504 DEBUG(0,("cli_oem_change_password: Failed to send password change for user %s\n",
509 if (!cli_receive_trans(cli
,SMBtrans
,
512 DEBUG(0,("cli_oem_change_password: Failed to recieve reply to password change for user %s\n",
518 cli
->rap_error
= SVAL(rparam
,0);
524 return (cli
->rap_error
== 0);
527 /****************************************************************************
528 Send a qpathinfo call.
529 ****************************************************************************/
531 bool cli_qpathinfo(struct cli_state
*cli
,
539 unsigned int data_len
= 0;
540 unsigned int param_len
= 0;
541 unsigned int rparam_len
, rdata_len
;
542 uint16 setup
= TRANSACT2_QPATHINFO
;
544 char *rparam
=NULL
, *rdata
=NULL
;
547 time_t (*date_fn
)(struct cli_state
*, const void *);
549 size_t nlen
= 2*(strlen(fname
)+1);
551 param
= SMB_MALLOC_ARRAY(char, 6+nlen
+2);
557 SSVAL(p
, 0, SMB_INFO_STANDARD
);
559 p
+= clistr_push(cli
, p
, fname
, nlen
, STR_TERMINATE
);
560 param_len
= PTR_DIFF(p
, param
);
563 ret
= (cli_send_trans(cli
, SMBtrans2
,
565 -1, 0, /* fid, flags */
566 &setup
, 1, 0, /* setup, length, max */
567 param
, param_len
, 10, /* param, length, max */
568 NULL
, data_len
, cli
->max_xmit
/* data, length, max */
570 cli_receive_trans(cli
, SMBtrans2
,
571 &rparam
, &rparam_len
,
572 &rdata
, &rdata_len
));
573 if (!cli_is_dos_error(cli
)) break;
575 /* we need to work around a Win95 bug - sometimes
576 it gives ERRSRV/ERRerror temprarily */
579 cli_dos_error(cli
, &eclass
, &ecode
);
580 if (eclass
!= ERRSRV
|| ecode
!= ERRerror
) break;
583 } while (count
-- && ret
==False
);
586 if (!ret
|| !rdata
|| rdata_len
< 22) {
591 date_fn
= cli_make_unix_date
;
593 date_fn
= cli_make_unix_date2
;
597 *change_time
= date_fn(cli
, rdata
+0);
600 *access_time
= date_fn(cli
, rdata
+4);
603 *write_time
= date_fn(cli
, rdata
+8);
606 *size
= IVAL(rdata
, 12);
609 *mode
= SVAL(rdata
,l1_attrFile
);
617 /****************************************************************************
618 Send a setpathinfo call.
619 ****************************************************************************/
621 bool cli_setpathinfo(struct cli_state
*cli
, const char *fname
,
628 unsigned int data_len
= 0;
629 unsigned int param_len
= 0;
630 unsigned int rparam_len
, rdata_len
;
631 uint16 setup
= TRANSACT2_SETPATHINFO
;
634 char *rparam
=NULL
, *rdata
=NULL
;
638 size_t nlen
= 2*(strlen(fname
)+1);
640 param
= SMB_MALLOC_ARRAY(char, 6+nlen
+2);
644 memset(param
, '\0', 6);
645 memset(data
, 0, sizeof(data
));
649 /* Add the information level */
650 SSVAL(p
, 0, SMB_FILE_BASIC_INFORMATION
);
655 /* Add the file name */
656 p
+= clistr_push(cli
, p
, fname
, nlen
, STR_TERMINATE
);
658 param_len
= PTR_DIFF(p
, param
);
663 * Add the create, last access, modification, and status change times
665 put_long_date(p
, create_time
);
668 put_long_date(p
, access_time
);
671 put_long_date(p
, write_time
);
674 put_long_date(p
, change_time
);
685 data_len
= PTR_DIFF(p
, data
);
688 ret
= (cli_send_trans(cli
, SMBtrans2
,
690 -1, 0, /* fid, flags */
691 &setup
, 1, 0, /* setup, length, max */
692 param
, param_len
, 10, /* param, length, max */
693 data
, data_len
, cli
->max_xmit
/* data, length, max */
695 cli_receive_trans(cli
, SMBtrans2
,
696 &rparam
, &rparam_len
,
697 &rdata
, &rdata_len
));
698 if (!cli_is_dos_error(cli
)) break;
700 /* we need to work around a Win95 bug - sometimes
701 it gives ERRSRV/ERRerror temprarily */
704 cli_dos_error(cli
, &eclass
, &ecode
);
705 if (eclass
!= ERRSRV
|| ecode
!= ERRerror
) break;
708 } while (count
-- && ret
==False
);
720 /****************************************************************************
721 Send a qpathinfo call with the SMB_QUERY_FILE_ALL_INFO info level.
722 ****************************************************************************/
724 bool cli_qpathinfo2(struct cli_state
*cli
, const char *fname
,
725 struct timespec
*create_time
,
726 struct timespec
*access_time
,
727 struct timespec
*write_time
,
728 struct timespec
*change_time
,
729 SMB_OFF_T
*size
, uint16
*mode
,
732 unsigned int data_len
= 0;
733 unsigned int param_len
= 0;
734 uint16 setup
= TRANSACT2_QPATHINFO
;
736 char *rparam
=NULL
, *rdata
=NULL
;
738 size_t nlen
= 2*(strlen(fname
)+1);
740 param
= SMB_MALLOC_ARRAY(char, 6+nlen
+2);
745 memset(param
, '\0', 6);
746 SSVAL(p
, 0, SMB_QUERY_FILE_ALL_INFO
);
748 p
+= clistr_push(cli
, p
, fname
, nlen
, STR_TERMINATE
);
750 param_len
= PTR_DIFF(p
, param
);
752 if (!cli_send_trans(cli
, SMBtrans2
,
754 -1, 0, /* fid, flags */
755 &setup
, 1, 0, /* setup, length, max */
756 param
, param_len
, 10, /* param, length, max */
757 NULL
, data_len
, cli
->max_xmit
/* data, length, max */
764 if (!cli_receive_trans(cli
, SMBtrans2
,
766 &rdata
, &data_len
)) {
770 if (!rdata
|| data_len
< 22) {
775 *create_time
= interpret_long_date(rdata
+0);
778 *access_time
= interpret_long_date(rdata
+8);
781 *write_time
= interpret_long_date(rdata
+16);
784 *change_time
= interpret_long_date(rdata
+24);
787 *mode
= SVAL(rdata
, 32);
790 *size
= IVAL2_TO_SMB_BIG_UINT(rdata
,48);
793 *ino
= IVAL(rdata
, 64);
801 /****************************************************************************
803 ****************************************************************************/
805 bool cli_qpathinfo_streams(struct cli_state
*cli
, const char *fname
,
807 unsigned int *pnum_streams
,
808 struct stream_struct
**pstreams
)
810 unsigned int data_len
= 0;
811 unsigned int param_len
= 0;
812 uint16 setup
= TRANSACT2_QPATHINFO
;
814 char *rparam
=NULL
, *rdata
=NULL
;
816 unsigned int num_streams
;
817 struct stream_struct
*streams
;
819 size_t namelen
= 2*(strlen(fname
)+1);
821 param
= SMB_MALLOC_ARRAY(char, 6+namelen
+2);
827 SSVAL(p
, 0, SMB_FILE_STREAM_INFORMATION
);
829 p
+= clistr_push(cli
, p
, fname
, namelen
, STR_TERMINATE
);
831 param_len
= PTR_DIFF(p
, param
);
833 if (!cli_send_trans(cli
, SMBtrans2
,
835 -1, 0, /* fid, flags */
836 &setup
, 1, 0, /* setup, len, max */
837 param
, param_len
, 10, /* param, len, max */
838 NULL
, data_len
, cli
->max_xmit
/* data, len, max */
843 if (!cli_receive_trans(cli
, SMBtrans2
,
845 &rdata
, &data_len
)) {
858 while ((data_len
> ofs
) && (data_len
- ofs
>= 24)) {
862 struct stream_struct
*tmp
;
865 tmp
= TALLOC_REALLOC_ARRAY(mem_ctx
, streams
,
866 struct stream_struct
,
874 nlen
= IVAL(rdata
, ofs
+ 0x04);
876 streams
[num_streams
].size
= IVAL_TO_SMB_OFF_T(
878 streams
[num_streams
].alloc_size
= IVAL_TO_SMB_OFF_T(
881 if (nlen
> data_len
- (ofs
+ 24)) {
886 * We need to null-terminate src, how do I do this with
887 * convert_string_talloc??
890 tmp_buf
= TALLOC_ARRAY(streams
, uint8_t, nlen
+2);
891 if (tmp_buf
== NULL
) {
895 memcpy(tmp_buf
, rdata
+ofs
+24, nlen
);
899 if (!convert_string_talloc(streams
, CH_UTF16
, CH_UNIX
, tmp_buf
,
900 nlen
+2, &vstr
, &size
, false))
902 TALLOC_FREE(tmp_buf
);
906 TALLOC_FREE(tmp_buf
);
907 streams
[num_streams
].name
= (char *)vstr
;
910 len
= IVAL(rdata
, ofs
);
911 if (len
> data_len
- ofs
) {
921 *pnum_streams
= num_streams
;
926 TALLOC_FREE(streams
);
932 /****************************************************************************
933 Send a qfileinfo QUERY_FILE_NAME_INFO call.
934 ****************************************************************************/
936 bool cli_qfilename(struct cli_state
*cli
, int fnum
, char *name
, size_t namelen
)
938 unsigned int data_len
= 0;
939 unsigned int param_len
= 0;
940 uint16 setup
= TRANSACT2_QFILEINFO
;
942 char *rparam
=NULL
, *rdata
=NULL
;
945 SSVAL(param
, 0, fnum
);
946 SSVAL(param
, 2, SMB_QUERY_FILE_NAME_INFO
);
948 if (!cli_send_trans(cli
, SMBtrans2
,
950 -1, 0, /* fid, flags */
951 &setup
, 1, 0, /* setup, length, max */
952 param
, param_len
, 2, /* param, length, max */
953 NULL
, data_len
, cli
->max_xmit
/* data, length, max */
958 if (!cli_receive_trans(cli
, SMBtrans2
,
960 &rdata
, &data_len
)) {
964 if (!rdata
|| data_len
< 4) {
970 clistr_pull(cli
->inbuf
, name
, rdata
+4, namelen
, IVAL(rdata
, 0),
979 /****************************************************************************
980 Send a qfileinfo call.
981 ****************************************************************************/
983 bool cli_qfileinfo(struct cli_state
*cli
, int fnum
,
984 uint16
*mode
, SMB_OFF_T
*size
,
985 struct timespec
*create_time
,
986 struct timespec
*access_time
,
987 struct timespec
*write_time
,
988 struct timespec
*change_time
,
991 unsigned int data_len
= 0;
992 unsigned int param_len
= 0;
995 uint8_t *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 SSVAL(&setup
, 0, TRANSACT2_QFILEINFO
);
1009 status
= cli_trans(talloc_tos(), cli
, SMBtrans2
,
1010 NULL
, -1, 0, 0, /* name, fid, function, flags */
1011 &setup
, 1, 0, /* setup, length, max */
1012 param
, param_len
, 2, /* param, length, max */
1013 NULL
, 0, MIN(cli
->max_xmit
, 0xffff), /* data, length, max */
1014 NULL
, NULL
, /* rsetup, length */
1015 &rparam
, ¶m_len
, /* rparam, length */
1018 if (!NT_STATUS_IS_OK(status
)) {
1022 if (!rdata
|| data_len
< 68) {
1027 *create_time
= interpret_long_date((char *)rdata
+0);
1030 *access_time
= interpret_long_date((char *)rdata
+8);
1033 *write_time
= interpret_long_date((char *)rdata
+16);
1036 *change_time
= interpret_long_date((char *)rdata
+24);
1039 *mode
= SVAL(rdata
, 32);
1042 *size
= IVAL2_TO_SMB_BIG_UINT(rdata
,48);
1045 *ino
= IVAL(rdata
, 64);
1049 TALLOC_FREE(rparam
);
1053 /****************************************************************************
1054 Send a qpathinfo BASIC_INFO call.
1055 ****************************************************************************/
1057 bool cli_qpathinfo_basic( struct cli_state
*cli
, const char *name
,
1058 SMB_STRUCT_STAT
*sbuf
, uint32
*attributes
)
1060 unsigned int param_len
= 0;
1061 unsigned int data_len
= 0;
1062 uint16 setup
= TRANSACT2_QPATHINFO
;
1064 char *rparam
=NULL
, *rdata
=NULL
;
1069 TALLOC_CTX
*frame
= talloc_stackframe();
1071 path
= talloc_strdup(frame
, name
);
1079 if ( path
[len
-1] == '\\' || path
[len
-1] == '/') {
1082 nlen
= 2*(strlen(path
)+1);
1084 param
= TALLOC_ARRAY(frame
,char,6+nlen
+2);
1089 memset(param
, '\0', 6);
1091 SSVAL(p
, 0, SMB_QUERY_FILE_BASIC_INFO
);
1093 p
+= clistr_push(cli
, p
, path
, nlen
, STR_TERMINATE
);
1094 param_len
= PTR_DIFF(p
, param
);
1097 if (!cli_send_trans(cli
, SMBtrans2
,
1099 -1, 0, /* fid, flags */
1100 &setup
, 1, 0, /* setup, length, max */
1101 param
, param_len
, 2, /* param, length, max */
1102 NULL
, 0, cli
->max_xmit
/* data, length, max */
1110 if (!cli_receive_trans(cli
, SMBtrans2
,
1111 &rparam
, ¶m_len
,
1112 &rdata
, &data_len
)) {
1116 if (data_len
< 36) {
1122 set_atimespec(sbuf
, interpret_long_date( rdata
+8 )); /* Access time. */
1123 set_mtimespec(sbuf
, interpret_long_date( rdata
+16 )); /* Write time. */
1124 set_ctimespec(sbuf
, interpret_long_date( rdata
+24 )); /* Change time. */
1126 *attributes
= IVAL( rdata
, 32 );
1134 /****************************************************************************
1135 Send a qfileinfo call.
1136 ****************************************************************************/
1138 bool cli_qfileinfo_test(struct cli_state
*cli
, int fnum
, int level
, char **poutdata
, uint32
*poutlen
)
1140 unsigned int data_len
= 0;
1141 unsigned int param_len
= 0;
1142 uint16 setup
= TRANSACT2_QFILEINFO
;
1144 char *rparam
=NULL
, *rdata
=NULL
;
1149 /* if its a win95 server then fail this - win95 totally screws it
1156 SSVAL(param
, 0, fnum
);
1157 SSVAL(param
, 2, level
);
1159 if (!cli_send_trans(cli
, SMBtrans2
,
1161 -1, 0, /* fid, flags */
1162 &setup
, 1, 0, /* setup, length, max */
1163 param
, param_len
, 2, /* param, length, max */
1164 NULL
, data_len
, cli
->max_xmit
/* data, length, max */
1169 if (!cli_receive_trans(cli
, SMBtrans2
,
1170 &rparam
, ¶m_len
,
1171 &rdata
, &data_len
)) {
1175 *poutdata
= (char *)memdup(rdata
, data_len
);
1182 *poutlen
= data_len
;
1189 /****************************************************************************
1190 Send a qpathinfo SMB_QUERY_FILE_ALT_NAME_INFO call.
1191 ****************************************************************************/
1193 NTSTATUS
cli_qpathinfo_alt_name(struct cli_state
*cli
, const char *fname
, fstring alt_name
)
1195 unsigned int data_len
= 0;
1196 unsigned int param_len
= 0;
1197 uint16 setup
= TRANSACT2_QPATHINFO
;
1199 char *rparam
=NULL
, *rdata
=NULL
;
1204 size_t nlen
= 2*(strlen(fname
)+1);
1206 param
= SMB_MALLOC_ARRAY(char, 6+nlen
+2);
1208 return NT_STATUS_NO_MEMORY
;
1211 memset(param
, '\0', 6);
1212 SSVAL(p
, 0, SMB_QUERY_FILE_ALT_NAME_INFO
);
1214 p
+= clistr_push(cli
, p
, fname
, nlen
, STR_TERMINATE
);
1215 param_len
= PTR_DIFF(p
, param
);
1218 ret
= (cli_send_trans(cli
, SMBtrans2
,
1220 -1, 0, /* fid, flags */
1221 &setup
, 1, 0, /* setup, length, max */
1222 param
, param_len
, 10, /* param, length, max */
1223 NULL
, data_len
, cli
->max_xmit
/* data, length, max */
1225 cli_receive_trans(cli
, SMBtrans2
,
1226 &rparam
, ¶m_len
,
1227 &rdata
, &data_len
));
1228 if (!ret
&& cli_is_dos_error(cli
)) {
1229 /* we need to work around a Win95 bug - sometimes
1230 it gives ERRSRV/ERRerror temprarily */
1233 cli_dos_error(cli
, &eclass
, &ecode
);
1234 if (eclass
!= ERRSRV
|| ecode
!= ERRerror
) break;
1237 } while (count
-- && ret
==False
);
1241 if (!ret
|| !rdata
|| data_len
< 4) {
1242 return NT_STATUS_UNSUCCESSFUL
;
1245 len
= IVAL(rdata
, 0);
1247 if (len
> data_len
- 4) {
1248 return NT_STATUS_INVALID_NETWORK_RESPONSE
;
1251 clistr_pull(cli
->inbuf
, alt_name
, rdata
+4, sizeof(fstring
), len
,
1257 return NT_STATUS_OK
;