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/>.
23 #include "../libcli/auth/libcli_auth.h"
24 #include "../librpc/gen_ndr/rap.h"
25 #include "../lib/crypto/arcfour.h"
27 /****************************************************************************
29 ****************************************************************************/
31 bool cli_api(struct cli_state
*cli
,
32 char *param
, int prcnt
, int mprcnt
,
33 char *data
, int drcnt
, int mdrcnt
,
34 char **rparam
, unsigned int *rprcnt
,
35 char **rdata
, unsigned int *rdrcnt
)
37 cli_send_trans(cli
,SMBtrans
,
38 PIPE_LANMAN
, /* Name */
40 NULL
,0,0, /* Setup, length, max */
41 param
, prcnt
, mprcnt
, /* Params, length, max */
42 data
, drcnt
, mdrcnt
/* Data, length, max */
45 return (cli_receive_trans(cli
,SMBtrans
,
50 /****************************************************************************
51 Perform a NetWkstaUserLogon.
52 ****************************************************************************/
54 bool cli_NetWkstaUserLogon(struct cli_state
*cli
,char *user
, char *workstation
)
59 unsigned int rdrcnt
,rprcnt
;
62 memset(param
, 0, sizeof(param
));
64 /* send a SMBtrans command with api NetWkstaUserLogon */
66 SSVAL(p
,0,132); /* api number */
68 strlcpy(p
,"OOWb54WrLh",sizeof(param
)-PTR_DIFF(p
,param
));
69 p
= skip_string(param
,sizeof(param
),p
);
70 strlcpy(p
,"WB21BWDWWDDDDDDDzzzD",sizeof(param
)-PTR_DIFF(p
,param
));
71 p
= skip_string(param
,sizeof(param
),p
);
74 strlcpy(p
,user
,sizeof(param
)-PTR_DIFF(p
,param
));
80 strlcpy(p
, workstation
,sizeof(param
)-PTR_DIFF(p
,param
));
83 SSVAL(p
, 0, CLI_BUFFER_SIZE
);
85 SSVAL(p
, 0, CLI_BUFFER_SIZE
);
89 param
, PTR_DIFF(p
,param
),1024, /* param, length, max */
90 NULL
, 0, CLI_BUFFER_SIZE
, /* data, length, max */
91 &rparam
, &rprcnt
, /* return params, return size */
92 &rdata
, &rdrcnt
/* return data, return size */
94 cli
->rap_error
= rparam
? SVAL(rparam
,0) : -1;
97 if (cli
->rap_error
== 0) {
98 DEBUG(4,("NetWkstaUserLogon success\n"));
99 cli
->privileges
= SVAL(p
, 24);
100 /* The cli->eff_name field used to be set here
101 but it wasn't used anywhere else. */
103 DEBUG(1,("NetwkstaUserLogon gave error %d\n", cli
->rap_error
));
109 return (cli
->rap_error
== 0);
112 /****************************************************************************
113 Call a NetShareEnum - try and browse available connections on a host.
114 ****************************************************************************/
116 int cli_RNetShareEnum(struct cli_state
*cli
, void (*fn
)(const char *, uint32
, const char *, void *), void *state
)
121 unsigned int rdrcnt
,rprcnt
;
125 /* now send a SMBtrans command with api RNetShareEnum */
127 SSVAL(p
,0,0); /* api number */
129 strlcpy(p
,"WrLeh",sizeof(param
)-PTR_DIFF(p
,param
));
130 p
= skip_string(param
,sizeof(param
),p
);
131 strlcpy(p
,"B13BWz",sizeof(param
)-PTR_DIFF(p
,param
));
132 p
= skip_string(param
,sizeof(param
),p
);
135 * Win2k needs a *smaller* buffer than 0xFFFF here -
136 * it returns "out of server memory" with 0xFFFF !!! JRA.
142 param
, PTR_DIFF(p
,param
), 1024, /* Param, length, maxlen */
143 NULL
, 0, 0xFFE0, /* data, length, maxlen - Win2k needs a small buffer here too ! */
144 &rparam
, &rprcnt
, /* return params, length */
145 &rdata
, &rdrcnt
)) /* return data, length */
147 int res
= rparam
? SVAL(rparam
,0) : -1;
149 if (res
== 0 || res
== ERRmoredata
) {
150 int converter
=SVAL(rparam
,2);
152 char *rdata_end
= rdata
+ rdrcnt
;
154 count
=SVAL(rparam
,4);
157 for (i
=0;i
<count
;i
++,p
+=20) {
165 TALLOC_CTX
*frame
= talloc_stackframe();
167 if (p
+ 20 > rdata_end
) {
174 comment_offset
= (IVAL(p
,16) & 0xFFFF) - converter
;
175 if (comment_offset
< 0 ||
176 comment_offset
> (int)rdrcnt
) {
180 cmnt
= comment_offset
?(rdata
+comment_offset
):"";
182 /* Work out the comment length. */
183 for (p1
= cmnt
, len
= 0; *p1
&&
184 p1
< rdata_end
; len
++)
189 pull_string_talloc(frame
,rdata
,0,
190 &s1
,sname
,14,STR_ASCII
);
191 pull_string_talloc(frame
,rdata
,0,
192 &s2
,cmnt
,len
,STR_ASCII
);
198 fn(s1
, type
, s2
, state
);
203 DEBUG(4,("NetShareEnum res=%d\n", res
));
206 DEBUG(4,("NetShareEnum failed\n"));
215 /****************************************************************************
216 Call a NetServerEnum for the specified workgroup and servertype mask. This
217 function then calls the specified callback function for each name returned.
219 The callback function takes 4 arguments: the machine name, the server type,
220 the comment and a state pointer.
221 ****************************************************************************/
223 bool cli_NetServerEnum(struct cli_state
*cli
, char *workgroup
, uint32 stype
,
224 void (*fn
)(const char *, uint32
, const char *, void *),
229 char *rdata_end
= NULL
;
230 unsigned int rdrcnt
,rprcnt
;
235 uint32 func
= RAP_NetServerEnum2
;
236 char *last_entry
= NULL
;
241 errno
= 0; /* reset */
244 * This may take more than one transaction, so we should loop until
245 * we no longer get a more data to process or we have all of the
249 /* send a SMBtrans command with api NetServerEnum */
251 SIVAL(p
,0,func
); /* api number */
254 if (func
== RAP_NetServerEnum3
) {
255 strlcpy(p
,"WrLehDzz", sizeof(param
)-PTR_DIFF(p
,param
));
257 strlcpy(p
,"WrLehDz", sizeof(param
)-PTR_DIFF(p
,param
));
260 p
= skip_string(param
, sizeof(param
), p
);
261 strlcpy(p
,"B16BBDz", sizeof(param
)-PTR_DIFF(p
,param
));
263 p
= skip_string(param
, sizeof(param
), p
);
265 SSVAL(p
,2,CLI_BUFFER_SIZE
);
270 /* If we have more data, tell the server where
275 sizeof(param
) - PTR_DIFF(p
,param
) - 1,
276 STR_TERMINATE
|STR_UPPER
);
278 if (len
== (size_t)-1) {
279 SAFE_FREE(last_entry
);
284 if (func
== RAP_NetServerEnum3
) {
286 last_entry
? last_entry
: "",
287 sizeof(param
) - PTR_DIFF(p
,param
) - 1,
290 if (len
== (size_t)-1) {
291 SAFE_FREE(last_entry
);
297 /* Next time through we need to use the continue api */
298 func
= RAP_NetServerEnum3
;
301 param
, PTR_DIFF(p
,param
), 8, /* params, length, max */
302 NULL
, 0, CLI_BUFFER_SIZE
, /* data, length, max */
303 &rparam
, &rprcnt
, /* return params, return size */
304 &rdata
, &rdrcnt
)) { /* return data, return size */
306 /* break out of the loop on error */
311 rdata_end
= rdata
+ rdrcnt
;
312 res
= rparam
? SVAL(rparam
,0) : -1;
314 if (res
== 0 || res
== ERRmoredata
||
315 (res
!= -1 && cli_errno(cli
) == 0)) {
318 int converter
=SVAL(rparam
,2);
320 /* Get the number of items returned in this buffer */
321 count
= SVAL(rparam
, 4);
323 /* The next field contains the number of items left,
324 * including those returned in this buffer. So the
325 * first time through this should contain all of the
328 if (total_cnt
== 0) {
329 total_cnt
= SVAL(rparam
, 6);
332 /* Keep track of how many we have read */
336 /* The last name in the previous NetServerEnum reply is
337 * sent back to server in the NetServerEnum3 request
338 * (last_entry). The next reply should repeat this entry
339 * as the first element. We have no proof that this is
340 * always true, but from traces that seems to be the
341 * behavior from Window Servers. So first lets do a lot
342 * of checking, just being paranoid. If the string
343 * matches then we already saw this entry so skip it.
345 * NOTE: sv1_name field must be null terminated and has
346 * a max size of 16 (NetBIOS Name).
348 if (last_entry
&& count
&& p
&&
349 (strncmp(last_entry
, p
, 16) == 0)) {
350 count
-= 1; /* Skip this entry */
351 return_cnt
= -1; /* Not part of total, so don't count. */
352 p
= rdata
+ 26; /* Skip the whole record */
355 for (i
= 0; i
< count
; i
++, p
+= 26) {
360 TALLOC_CTX
*frame
= talloc_stackframe();
361 uint32_t entry_stype
;
363 if (p
+ 26 > rdata_end
) {
369 comment_offset
= (IVAL(p
,22) & 0xFFFF)-converter
;
370 cmnt
= comment_offset
?(rdata
+comment_offset
):"";
372 if (comment_offset
< 0 || comment_offset
>= (int)rdrcnt
) {
377 /* Work out the comment length. */
378 for (p1
= cmnt
, len
= 0; *p1
&&
379 p1
< rdata_end
; len
++)
385 entry_stype
= IVAL(p
,18) & ~SV_TYPE_LOCAL_LIST_ONLY
;
387 pull_string_talloc(frame
,rdata
,0,
388 &s1
,sname
,16,STR_ASCII
);
389 pull_string_talloc(frame
,rdata
,0,
390 &s2
,cmnt
,len
,STR_ASCII
);
397 fn(s1
, entry_stype
, s2
, state
);
401 /* We are done with the old last entry, so now we can free it */
403 SAFE_FREE(last_entry
); /* This will set it to null */
406 /* We always make a copy of the last entry if we have one */
408 last_entry
= smb_xstrdup(sname
);
411 /* If we have more data, but no last entry then error out */
412 if (!last_entry
&& (res
== ERRmoredata
)) {
421 } while ((res
== ERRmoredata
) && (total_cnt
> return_cnt
));
425 SAFE_FREE(last_entry
);
428 errno
= cli_errno(cli
);
431 /* this is a very special case, when the domain master for the
432 work group isn't part of the work group itself, there is something
438 return(return_cnt
> 0);
441 /****************************************************************************
442 Send a SamOEMChangePassword command.
443 ****************************************************************************/
445 bool cli_oem_change_password(struct cli_state
*cli
, const char *user
, const char *new_password
,
446 const char *old_password
)
449 unsigned char data
[532];
451 unsigned char old_pw_hash
[16];
452 unsigned char new_pw_hash
[16];
453 unsigned int data_len
;
454 unsigned int param_len
= 0;
457 unsigned int rprcnt
, rdrcnt
;
459 if (strlen(user
) >= sizeof(fstring
)-1) {
460 DEBUG(0,("cli_oem_change_password: user name %s is too long.\n", user
));
464 SSVAL(p
,0,214); /* SamOEMChangePassword command. */
466 strlcpy(p
, "zsT", sizeof(param
)-PTR_DIFF(p
,param
));
467 p
= skip_string(param
,sizeof(param
),p
);
468 strlcpy(p
, "B516B16", sizeof(param
)-PTR_DIFF(p
,param
));
469 p
= skip_string(param
,sizeof(param
),p
);
470 strlcpy(p
,user
, sizeof(param
)-PTR_DIFF(p
,param
));
471 p
= skip_string(param
,sizeof(param
),p
);
475 param_len
= PTR_DIFF(p
,param
);
478 * Get the Lanman hash of the old password, we
479 * use this as the key to make_oem_passwd_hash().
481 E_deshash(old_password
, old_pw_hash
);
483 encode_pw_buffer(data
, new_password
, STR_ASCII
);
485 #ifdef DEBUG_PASSWORD
486 DEBUG(100,("make_oem_passwd_hash\n"));
487 dump_data(100, data
, 516);
489 arcfour_crypt( (unsigned char *)data
, (unsigned char *)old_pw_hash
, 516);
492 * Now place the old password hash in the data.
494 E_deshash(new_password
, new_pw_hash
);
496 E_old_pw_hash( new_pw_hash
, old_pw_hash
, (uchar
*)&data
[516]);
500 if (cli_send_trans(cli
,SMBtrans
,
501 PIPE_LANMAN
, /* name */
502 0,0, /* fid, flags */
503 NULL
,0,0, /* setup, length, max */
504 param
,param_len
,4, /* param, length, max */
505 (char *)data
,data_len
,0 /* data, length, max */
507 DEBUG(0,("cli_oem_change_password: Failed to send password change for user %s\n",
512 if (!cli_receive_trans(cli
,SMBtrans
,
515 DEBUG(0,("cli_oem_change_password: Failed to recieve reply to password change for user %s\n",
521 cli
->rap_error
= SVAL(rparam
,0);
527 return (cli
->rap_error
== 0);
530 /****************************************************************************
531 Send a qpathinfo call.
532 ****************************************************************************/
534 bool cli_qpathinfo(struct cli_state
*cli
,
542 unsigned int data_len
= 0;
543 unsigned int param_len
= 0;
544 unsigned int rparam_len
, rdata_len
;
545 uint16 setup
= TRANSACT2_QPATHINFO
;
547 char *rparam
=NULL
, *rdata
=NULL
;
550 time_t (*date_fn
)(struct cli_state
*, const void *);
552 size_t nlen
= 2*(strlen(fname
)+1);
554 param
= SMB_MALLOC_ARRAY(char, 6+nlen
+2);
560 SSVAL(p
, 0, SMB_INFO_STANDARD
);
562 p
+= clistr_push(cli
, p
, fname
, nlen
, STR_TERMINATE
);
563 param_len
= PTR_DIFF(p
, param
);
566 ret
= (cli_send_trans(cli
, SMBtrans2
,
568 -1, 0, /* fid, flags */
569 &setup
, 1, 0, /* setup, length, max */
570 param
, param_len
, 10, /* param, length, max */
571 NULL
, data_len
, cli
->max_xmit
/* data, length, max */
573 cli_receive_trans(cli
, SMBtrans2
,
574 &rparam
, &rparam_len
,
575 &rdata
, &rdata_len
));
576 if (!cli_is_dos_error(cli
)) break;
578 /* we need to work around a Win95 bug - sometimes
579 it gives ERRSRV/ERRerror temprarily */
582 cli_dos_error(cli
, &eclass
, &ecode
);
583 if (eclass
!= ERRSRV
|| ecode
!= ERRerror
) break;
586 } while (count
-- && ret
==False
);
589 if (!ret
|| !rdata
|| rdata_len
< 22) {
594 date_fn
= cli_make_unix_date
;
596 date_fn
= cli_make_unix_date2
;
600 *change_time
= date_fn(cli
, rdata
+0);
603 *access_time
= date_fn(cli
, rdata
+4);
606 *write_time
= date_fn(cli
, rdata
+8);
609 *size
= IVAL(rdata
, 12);
612 *mode
= SVAL(rdata
,l1_attrFile
);
620 /****************************************************************************
621 Send a setpathinfo call.
622 ****************************************************************************/
624 bool cli_setpathinfo(struct cli_state
*cli
, const char *fname
,
631 unsigned int data_len
= 0;
632 unsigned int param_len
= 0;
633 unsigned int rparam_len
, rdata_len
;
634 uint16 setup
= TRANSACT2_SETPATHINFO
;
637 char *rparam
=NULL
, *rdata
=NULL
;
641 size_t nlen
= 2*(strlen(fname
)+1);
643 param
= SMB_MALLOC_ARRAY(char, 6+nlen
+2);
647 memset(param
, '\0', 6);
648 memset(data
, 0, sizeof(data
));
652 /* Add the information level */
653 SSVAL(p
, 0, SMB_FILE_BASIC_INFORMATION
);
658 /* Add the file name */
659 p
+= clistr_push(cli
, p
, fname
, nlen
, STR_TERMINATE
);
661 param_len
= PTR_DIFF(p
, param
);
666 * Add the create, last access, modification, and status change times
668 put_long_date(p
, create_time
);
671 put_long_date(p
, access_time
);
674 put_long_date(p
, write_time
);
677 put_long_date(p
, change_time
);
688 data_len
= PTR_DIFF(p
, data
);
691 ret
= (cli_send_trans(cli
, SMBtrans2
,
693 -1, 0, /* fid, flags */
694 &setup
, 1, 0, /* setup, length, max */
695 param
, param_len
, 10, /* param, length, max */
696 data
, data_len
, cli
->max_xmit
/* data, length, max */
698 cli_receive_trans(cli
, SMBtrans2
,
699 &rparam
, &rparam_len
,
700 &rdata
, &rdata_len
));
701 if (!cli_is_dos_error(cli
)) break;
703 /* we need to work around a Win95 bug - sometimes
704 it gives ERRSRV/ERRerror temprarily */
707 cli_dos_error(cli
, &eclass
, &ecode
);
708 if (eclass
!= ERRSRV
|| ecode
!= ERRerror
) break;
711 } while (count
-- && ret
==False
);
723 /****************************************************************************
724 Send a qpathinfo call with the SMB_QUERY_FILE_ALL_INFO info level.
725 ****************************************************************************/
727 bool cli_qpathinfo2(struct cli_state
*cli
, const char *fname
,
728 struct timespec
*create_time
,
729 struct timespec
*access_time
,
730 struct timespec
*write_time
,
731 struct timespec
*change_time
,
732 SMB_OFF_T
*size
, uint16
*mode
,
735 unsigned int data_len
= 0;
736 unsigned int param_len
= 0;
737 uint16 setup
= TRANSACT2_QPATHINFO
;
739 char *rparam
=NULL
, *rdata
=NULL
;
741 size_t nlen
= 2*(strlen(fname
)+1);
743 param
= SMB_MALLOC_ARRAY(char, 6+nlen
+2);
748 memset(param
, '\0', 6);
749 SSVAL(p
, 0, SMB_QUERY_FILE_ALL_INFO
);
751 p
+= clistr_push(cli
, p
, fname
, nlen
, STR_TERMINATE
);
753 param_len
= PTR_DIFF(p
, param
);
755 if (!cli_send_trans(cli
, SMBtrans2
,
757 -1, 0, /* fid, flags */
758 &setup
, 1, 0, /* setup, length, max */
759 param
, param_len
, 10, /* param, length, max */
760 NULL
, data_len
, cli
->max_xmit
/* data, length, max */
767 if (!cli_receive_trans(cli
, SMBtrans2
,
769 &rdata
, &data_len
)) {
773 if (!rdata
|| data_len
< 22) {
778 *create_time
= interpret_long_date(rdata
+0);
781 *access_time
= interpret_long_date(rdata
+8);
784 *write_time
= interpret_long_date(rdata
+16);
787 *change_time
= interpret_long_date(rdata
+24);
790 *mode
= SVAL(rdata
, 32);
793 *size
= IVAL2_TO_SMB_BIG_UINT(rdata
,48);
796 *ino
= IVAL(rdata
, 64);
804 /****************************************************************************
806 ****************************************************************************/
808 bool cli_qpathinfo_streams(struct cli_state
*cli
, const char *fname
,
810 unsigned int *pnum_streams
,
811 struct stream_struct
**pstreams
)
813 unsigned int data_len
= 0;
814 unsigned int param_len
= 0;
815 uint16 setup
= TRANSACT2_QPATHINFO
;
817 char *rparam
=NULL
, *rdata
=NULL
;
819 unsigned int num_streams
;
820 struct stream_struct
*streams
;
822 size_t namelen
= 2*(strlen(fname
)+1);
824 param
= SMB_MALLOC_ARRAY(char, 6+namelen
+2);
830 SSVAL(p
, 0, SMB_FILE_STREAM_INFORMATION
);
832 p
+= clistr_push(cli
, p
, fname
, namelen
, STR_TERMINATE
);
834 param_len
= PTR_DIFF(p
, param
);
836 if (!cli_send_trans(cli
, SMBtrans2
,
838 -1, 0, /* fid, flags */
839 &setup
, 1, 0, /* setup, len, max */
840 param
, param_len
, 10, /* param, len, max */
841 NULL
, data_len
, cli
->max_xmit
/* data, len, max */
846 if (!cli_receive_trans(cli
, SMBtrans2
,
848 &rdata
, &data_len
)) {
861 while ((data_len
> ofs
) && (data_len
- ofs
>= 24)) {
865 struct stream_struct
*tmp
;
868 tmp
= TALLOC_REALLOC_ARRAY(mem_ctx
, streams
,
869 struct stream_struct
,
877 nlen
= IVAL(rdata
, ofs
+ 0x04);
879 streams
[num_streams
].size
= IVAL_TO_SMB_OFF_T(
881 streams
[num_streams
].alloc_size
= IVAL_TO_SMB_OFF_T(
884 if (nlen
> data_len
- (ofs
+ 24)) {
889 * We need to null-terminate src, how do I do this with
890 * convert_string_talloc??
893 tmp_buf
= TALLOC_ARRAY(streams
, uint8_t, nlen
+2);
894 if (tmp_buf
== NULL
) {
898 memcpy(tmp_buf
, rdata
+ofs
+24, nlen
);
902 if (!convert_string_talloc(streams
, CH_UTF16
, CH_UNIX
, tmp_buf
,
903 nlen
+2, &vstr
, &size
, false))
905 TALLOC_FREE(tmp_buf
);
909 TALLOC_FREE(tmp_buf
);
910 streams
[num_streams
].name
= (char *)vstr
;
913 len
= IVAL(rdata
, ofs
);
914 if (len
> data_len
- ofs
) {
924 *pnum_streams
= num_streams
;
929 TALLOC_FREE(streams
);
935 /****************************************************************************
936 Send a qfileinfo QUERY_FILE_NAME_INFO call.
937 ****************************************************************************/
939 bool cli_qfilename(struct cli_state
*cli
, uint16_t fnum
, char *name
, size_t namelen
)
941 unsigned int data_len
= 0;
942 unsigned int param_len
= 0;
943 uint16 setup
= TRANSACT2_QFILEINFO
;
945 char *rparam
=NULL
, *rdata
=NULL
;
948 SSVAL(param
, 0, fnum
);
949 SSVAL(param
, 2, SMB_QUERY_FILE_NAME_INFO
);
951 if (!cli_send_trans(cli
, SMBtrans2
,
953 -1, 0, /* fid, flags */
954 &setup
, 1, 0, /* setup, length, max */
955 param
, param_len
, 2, /* param, length, max */
956 NULL
, data_len
, cli
->max_xmit
/* data, length, max */
961 if (!cli_receive_trans(cli
, SMBtrans2
,
963 &rdata
, &data_len
)) {
967 if (!rdata
|| data_len
< 4) {
973 clistr_pull(cli
->inbuf
, name
, rdata
+4, namelen
, IVAL(rdata
, 0),
982 /****************************************************************************
983 Send a qfileinfo call.
984 ****************************************************************************/
986 bool cli_qfileinfo(struct cli_state
*cli
, uint16_t 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 uint32_t data_len
= 0;
1000 /* if its a win95 server then fail this - win95 totally screws it
1002 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
, 4, 2, /* param, length, max */
1013 NULL
, 0, MIN(cli
->max_xmit
, 0xffff), /* data, length, max */
1014 NULL
, 0, NULL
, /* rsetup, length */
1015 NULL
, 0, NULL
, /* rparam, length */
1016 &rdata
, 68, &data_len
);
1018 if (!NT_STATUS_IS_OK(status
)) {
1023 *create_time
= interpret_long_date((char *)rdata
+0);
1026 *access_time
= interpret_long_date((char *)rdata
+8);
1029 *write_time
= interpret_long_date((char *)rdata
+16);
1032 *change_time
= interpret_long_date((char *)rdata
+24);
1035 *mode
= SVAL(rdata
, 32);
1038 *size
= IVAL2_TO_SMB_BIG_UINT(rdata
,48);
1041 *ino
= IVAL(rdata
, 64);
1048 /****************************************************************************
1049 Send a qpathinfo BASIC_INFO call.
1050 ****************************************************************************/
1052 NTSTATUS
cli_qpathinfo_basic(struct cli_state
*cli
, const char *name
,
1053 SMB_STRUCT_STAT
*sbuf
, uint32
*attributes
)
1055 unsigned int param_len
= 0;
1058 uint8_t *param
, *rdata
;
1063 TALLOC_CTX
*frame
= talloc_stackframe();
1066 path
= talloc_strdup(frame
, name
);
1069 return NT_STATUS_NO_MEMORY
;
1074 if ( path
[len
-1] == '\\' || path
[len
-1] == '/') {
1077 nlen
= 2*(strlen(path
)+1);
1079 param
= TALLOC_ARRAY(frame
, uint8_t, 6+nlen
+2);
1082 return NT_STATUS_NO_MEMORY
;
1085 memset(param
, '\0', 6);
1087 SSVAL(setup
, 0, TRANSACT2_QPATHINFO
);
1088 SSVAL(p
, 0, SMB_QUERY_FILE_BASIC_INFO
);
1090 p
+= clistr_push(cli
, p
, path
, nlen
, STR_TERMINATE
);
1091 param_len
= PTR_DIFF(p
, param
);
1093 status
= cli_trans(talloc_tos(), cli
, SMBtrans2
, NULL
, -1, 0, 0,
1095 param
, param_len
, 2,
1096 NULL
, 0, cli
->max_xmit
,
1099 &rdata
, 36, &rdata_len
);
1100 if (!NT_STATUS_IS_OK(status
)) {
1105 sbuf
->st_ex_atime
= interpret_long_date((char *)rdata
+8);
1106 sbuf
->st_ex_mtime
= interpret_long_date((char *)rdata
+16);
1107 sbuf
->st_ex_ctime
= interpret_long_date((char *)rdata
+24);
1109 *attributes
= IVAL( rdata
, 32 );
1113 return NT_STATUS_OK
;
1116 /****************************************************************************
1117 Send a qfileinfo call.
1118 ****************************************************************************/
1120 bool cli_qfileinfo_test(struct cli_state
*cli
, uint16_t fnum
, int level
, char **poutdata
, uint32
*poutlen
)
1122 unsigned int data_len
= 0;
1123 unsigned int param_len
= 0;
1124 uint16 setup
= TRANSACT2_QFILEINFO
;
1126 char *rparam
=NULL
, *rdata
=NULL
;
1131 /* if its a win95 server then fail this - win95 totally screws it
1138 SSVAL(param
, 0, fnum
);
1139 SSVAL(param
, 2, level
);
1141 if (!cli_send_trans(cli
, SMBtrans2
,
1143 -1, 0, /* fid, flags */
1144 &setup
, 1, 0, /* setup, length, max */
1145 param
, param_len
, 2, /* param, length, max */
1146 NULL
, data_len
, cli
->max_xmit
/* data, length, max */
1151 if (!cli_receive_trans(cli
, SMBtrans2
,
1152 &rparam
, ¶m_len
,
1153 &rdata
, &data_len
)) {
1157 *poutdata
= (char *)memdup(rdata
, data_len
);
1164 *poutlen
= data_len
;
1171 /****************************************************************************
1172 Send a qpathinfo SMB_QUERY_FILE_ALT_NAME_INFO call.
1173 ****************************************************************************/
1175 NTSTATUS
cli_qpathinfo_alt_name(struct cli_state
*cli
, const char *fname
, fstring alt_name
)
1177 unsigned int data_len
= 0;
1178 unsigned int param_len
= 0;
1179 uint16 setup
= TRANSACT2_QPATHINFO
;
1181 char *rparam
=NULL
, *rdata
=NULL
;
1186 size_t nlen
= 2*(strlen(fname
)+1);
1188 param
= SMB_MALLOC_ARRAY(char, 6+nlen
+2);
1190 return NT_STATUS_NO_MEMORY
;
1193 memset(param
, '\0', 6);
1194 SSVAL(p
, 0, SMB_QUERY_FILE_ALT_NAME_INFO
);
1196 p
+= clistr_push(cli
, p
, fname
, nlen
, STR_TERMINATE
);
1197 param_len
= PTR_DIFF(p
, param
);
1200 ret
= (cli_send_trans(cli
, SMBtrans2
,
1202 -1, 0, /* fid, flags */
1203 &setup
, 1, 0, /* setup, length, max */
1204 param
, param_len
, 10, /* param, length, max */
1205 NULL
, data_len
, cli
->max_xmit
/* data, length, max */
1207 cli_receive_trans(cli
, SMBtrans2
,
1208 &rparam
, ¶m_len
,
1209 &rdata
, &data_len
));
1210 if (!ret
&& cli_is_dos_error(cli
)) {
1211 /* we need to work around a Win95 bug - sometimes
1212 it gives ERRSRV/ERRerror temprarily */
1215 cli_dos_error(cli
, &eclass
, &ecode
);
1216 if (eclass
!= ERRSRV
|| ecode
!= ERRerror
) break;
1219 } while (count
-- && ret
==False
);
1223 if (!ret
|| !rdata
|| data_len
< 4) {
1224 return NT_STATUS_UNSUCCESSFUL
;
1227 len
= IVAL(rdata
, 0);
1229 if (len
> data_len
- 4) {
1230 return NT_STATUS_INVALID_NETWORK_RESPONSE
;
1233 clistr_pull(cli
->inbuf
, alt_name
, rdata
+4, sizeof(fstring
), len
,
1239 return NT_STATUS_OK
;