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"
25 /****************************************************************************
27 ****************************************************************************/
29 bool cli_api(struct cli_state
*cli
,
30 char *param
, int prcnt
, int mprcnt
,
31 char *data
, int drcnt
, int mdrcnt
,
32 char **rparam
, unsigned int *rprcnt
,
33 char **rdata
, unsigned int *rdrcnt
)
35 cli_send_trans(cli
,SMBtrans
,
36 PIPE_LANMAN
, /* Name */
38 NULL
,0,0, /* Setup, length, max */
39 param
, prcnt
, mprcnt
, /* Params, length, max */
40 data
, drcnt
, mdrcnt
/* Data, length, max */
43 return (cli_receive_trans(cli
,SMBtrans
,
48 /****************************************************************************
49 Perform a NetWkstaUserLogon.
50 ****************************************************************************/
52 bool cli_NetWkstaUserLogon(struct cli_state
*cli
,char *user
, char *workstation
)
57 unsigned int rdrcnt
,rprcnt
;
60 memset(param
, 0, sizeof(param
));
62 /* send a SMBtrans command with api NetWkstaUserLogon */
64 SSVAL(p
,0,132); /* api number */
66 strlcpy(p
,"OOWb54WrLh",sizeof(param
)-PTR_DIFF(p
,param
));
67 p
= skip_string(param
,sizeof(param
),p
);
68 strlcpy(p
,"WB21BWDWWDDDDDDDzzzD",sizeof(param
)-PTR_DIFF(p
,param
));
69 p
= skip_string(param
,sizeof(param
),p
);
72 strlcpy(p
,user
,sizeof(param
)-PTR_DIFF(p
,param
));
78 strlcpy(p
, workstation
,sizeof(param
)-PTR_DIFF(p
,param
));
81 SSVAL(p
, 0, CLI_BUFFER_SIZE
);
83 SSVAL(p
, 0, CLI_BUFFER_SIZE
);
87 param
, PTR_DIFF(p
,param
),1024, /* param, length, max */
88 NULL
, 0, CLI_BUFFER_SIZE
, /* data, length, max */
89 &rparam
, &rprcnt
, /* return params, return size */
90 &rdata
, &rdrcnt
/* return data, return size */
92 cli
->rap_error
= rparam
? SVAL(rparam
,0) : -1;
95 if (cli
->rap_error
== 0) {
96 DEBUG(4,("NetWkstaUserLogon success\n"));
97 cli
->privileges
= SVAL(p
, 24);
98 /* The cli->eff_name field used to be set here
99 but it wasn't used anywhere else. */
101 DEBUG(1,("NetwkstaUserLogon gave error %d\n", cli
->rap_error
));
107 return (cli
->rap_error
== 0);
110 /****************************************************************************
111 Call a NetShareEnum - try and browse available connections on a host.
112 ****************************************************************************/
114 int cli_RNetShareEnum(struct cli_state
*cli
, void (*fn
)(const char *, uint32
, const char *, void *), void *state
)
119 unsigned int rdrcnt
,rprcnt
;
123 /* now send a SMBtrans command with api RNetShareEnum */
125 SSVAL(p
,0,0); /* api number */
127 strlcpy(p
,"WrLeh",sizeof(param
)-PTR_DIFF(p
,param
));
128 p
= skip_string(param
,sizeof(param
),p
);
129 strlcpy(p
,"B13BWz",sizeof(param
)-PTR_DIFF(p
,param
));
130 p
= skip_string(param
,sizeof(param
),p
);
133 * Win2k needs a *smaller* buffer than 0xFFFF here -
134 * it returns "out of server memory" with 0xFFFF !!! JRA.
140 param
, PTR_DIFF(p
,param
), 1024, /* Param, length, maxlen */
141 NULL
, 0, 0xFFE0, /* data, length, maxlen - Win2k needs a small buffer here too ! */
142 &rparam
, &rprcnt
, /* return params, length */
143 &rdata
, &rdrcnt
)) /* return data, length */
145 int res
= rparam
? SVAL(rparam
,0) : -1;
147 if (res
== 0 || res
== ERRmoredata
) {
148 int converter
=SVAL(rparam
,2);
150 char *rdata_end
= rdata
+ rdrcnt
;
152 count
=SVAL(rparam
,4);
155 for (i
=0;i
<count
;i
++,p
+=20) {
163 TALLOC_CTX
*frame
= talloc_stackframe();
165 if (p
+ 20 > rdata_end
) {
172 comment_offset
= (IVAL(p
,16) & 0xFFFF) - converter
;
173 if (comment_offset
< 0 ||
174 comment_offset
> (int)rdrcnt
) {
178 cmnt
= comment_offset
?(rdata
+comment_offset
):"";
180 /* Work out the comment length. */
181 for (p1
= cmnt
, len
= 0; *p1
&&
182 p1
< rdata_end
; len
++)
187 pull_string_talloc(frame
,rdata
,0,
188 &s1
,sname
,14,STR_ASCII
);
189 pull_string_talloc(frame
,rdata
,0,
190 &s2
,cmnt
,len
,STR_ASCII
);
196 fn(s1
, type
, s2
, state
);
201 DEBUG(4,("NetShareEnum res=%d\n", res
));
204 DEBUG(4,("NetShareEnum failed\n"));
213 /****************************************************************************
214 Call a NetServerEnum for the specified workgroup and servertype mask. This
215 function then calls the specified callback function for each name returned.
217 The callback function takes 4 arguments: the machine name, the server type,
218 the comment and a state pointer.
219 ****************************************************************************/
221 bool cli_NetServerEnum(struct cli_state
*cli
, char *workgroup
, uint32 stype
,
222 void (*fn
)(const char *, uint32
, const char *, void *),
227 char *rdata_end
= NULL
;
228 unsigned int rdrcnt
,rprcnt
;
233 uint32 func
= RAP_NetServerEnum2
;
234 char *last_entry
= NULL
;
239 errno
= 0; /* reset */
242 * This may take more than one transaction, so we should loop until
243 * we no longer get a more data to process or we have all of the
247 /* send a SMBtrans command with api NetServerEnum */
249 SIVAL(p
,0,func
); /* api number */
252 if (func
== RAP_NetServerEnum3
) {
253 strlcpy(p
,"WrLehDzz", sizeof(param
)-PTR_DIFF(p
,param
));
255 strlcpy(p
,"WrLehDz", sizeof(param
)-PTR_DIFF(p
,param
));
258 p
= skip_string(param
, sizeof(param
), p
);
259 strlcpy(p
,"B16BBDz", sizeof(param
)-PTR_DIFF(p
,param
));
261 p
= skip_string(param
, sizeof(param
), p
);
263 SSVAL(p
,2,CLI_BUFFER_SIZE
);
268 /* If we have more data, tell the server where
273 sizeof(param
) - PTR_DIFF(p
,param
) - 1,
274 STR_TERMINATE
|STR_UPPER
);
276 if (len
== (size_t)-1) {
277 SAFE_FREE(last_entry
);
282 if (func
== RAP_NetServerEnum3
) {
284 last_entry
? last_entry
: "",
285 sizeof(param
) - PTR_DIFF(p
,param
) - 1,
288 if (len
== (size_t)-1) {
289 SAFE_FREE(last_entry
);
295 /* Next time through we need to use the continue api */
296 func
= RAP_NetServerEnum3
;
299 param
, PTR_DIFF(p
,param
), 8, /* params, length, max */
300 NULL
, 0, CLI_BUFFER_SIZE
, /* data, length, max */
301 &rparam
, &rprcnt
, /* return params, return size */
302 &rdata
, &rdrcnt
)) { /* return data, return size */
304 /* break out of the loop on error */
309 rdata_end
= rdata
+ rdrcnt
;
310 res
= rparam
? SVAL(rparam
,0) : -1;
312 if (res
== 0 || res
== ERRmoredata
||
313 (res
!= -1 && cli_errno(cli
) == 0)) {
316 int converter
=SVAL(rparam
,2);
318 /* Get the number of items returned in this buffer */
319 count
= SVAL(rparam
, 4);
321 /* The next field contains the number of items left,
322 * including those returned in this buffer. So the
323 * first time through this should contain all of the
326 if (total_cnt
== 0) {
327 total_cnt
= SVAL(rparam
, 6);
330 /* Keep track of how many we have read */
334 /* The last name in the previous NetServerEnum reply is
335 * sent back to server in the NetServerEnum3 request
336 * (last_entry). The next reply should repeat this entry
337 * as the first element. We have no proof that this is
338 * always true, but from traces that seems to be the
339 * behavior from Window Servers. So first lets do a lot
340 * of checking, just being paranoid. If the string
341 * matches then we already saw this entry so skip it.
343 * NOTE: sv1_name field must be null terminated and has
344 * a max size of 16 (NetBIOS Name).
346 if (last_entry
&& count
&& p
&&
347 (strncmp(last_entry
, p
, 16) == 0)) {
348 count
-= 1; /* Skip this entry */
349 return_cnt
= -1; /* Not part of total, so don't count. */
350 p
= rdata
+ 26; /* Skip the whole record */
353 for (i
= 0; i
< count
; i
++, p
+= 26) {
358 TALLOC_CTX
*frame
= talloc_stackframe();
359 uint32_t entry_stype
;
361 if (p
+ 26 > rdata_end
) {
367 comment_offset
= (IVAL(p
,22) & 0xFFFF)-converter
;
368 cmnt
= comment_offset
?(rdata
+comment_offset
):"";
370 if (comment_offset
< 0 || comment_offset
>= (int)rdrcnt
) {
375 /* Work out the comment length. */
376 for (p1
= cmnt
, len
= 0; *p1
&&
377 p1
< rdata_end
; len
++)
383 entry_stype
= IVAL(p
,18) & ~SV_TYPE_LOCAL_LIST_ONLY
;
385 pull_string_talloc(frame
,rdata
,0,
386 &s1
,sname
,16,STR_ASCII
);
387 pull_string_talloc(frame
,rdata
,0,
388 &s2
,cmnt
,len
,STR_ASCII
);
395 fn(s1
, entry_stype
, s2
, state
);
399 /* We are done with the old last entry, so now we can free it */
401 SAFE_FREE(last_entry
); /* This will set it to null */
404 /* We always make a copy of the last entry if we have one */
406 last_entry
= smb_xstrdup(sname
);
409 /* If we have more data, but no last entry then error out */
410 if (!last_entry
&& (res
== ERRmoredata
)) {
419 } while ((res
== ERRmoredata
) && (total_cnt
> return_cnt
));
423 SAFE_FREE(last_entry
);
426 errno
= cli_errno(cli
);
429 /* this is a very special case, when the domain master for the
430 work group isn't part of the work group itself, there is something
436 return(return_cnt
> 0);
439 /****************************************************************************
440 Send a SamOEMChangePassword command.
441 ****************************************************************************/
443 bool cli_oem_change_password(struct cli_state
*cli
, const char *user
, const char *new_password
,
444 const char *old_password
)
447 unsigned char data
[532];
449 unsigned char old_pw_hash
[16];
450 unsigned char new_pw_hash
[16];
451 unsigned int data_len
;
452 unsigned int param_len
= 0;
455 unsigned int rprcnt
, rdrcnt
;
457 if (strlen(user
) >= sizeof(fstring
)-1) {
458 DEBUG(0,("cli_oem_change_password: user name %s is too long.\n", user
));
462 SSVAL(p
,0,214); /* SamOEMChangePassword command. */
464 strlcpy(p
, "zsT", sizeof(param
)-PTR_DIFF(p
,param
));
465 p
= skip_string(param
,sizeof(param
),p
);
466 strlcpy(p
, "B516B16", sizeof(param
)-PTR_DIFF(p
,param
));
467 p
= skip_string(param
,sizeof(param
),p
);
468 strlcpy(p
,user
, sizeof(param
)-PTR_DIFF(p
,param
));
469 p
= skip_string(param
,sizeof(param
),p
);
473 param_len
= PTR_DIFF(p
,param
);
476 * Get the Lanman hash of the old password, we
477 * use this as the key to make_oem_passwd_hash().
479 E_deshash(old_password
, old_pw_hash
);
481 encode_pw_buffer(data
, new_password
, STR_ASCII
);
483 #ifdef DEBUG_PASSWORD
484 DEBUG(100,("make_oem_passwd_hash\n"));
485 dump_data(100, data
, 516);
487 arcfour_crypt( (unsigned char *)data
, (unsigned char *)old_pw_hash
, 516);
490 * Now place the old password hash in the data.
492 E_deshash(new_password
, new_pw_hash
);
494 E_old_pw_hash( new_pw_hash
, old_pw_hash
, (uchar
*)&data
[516]);
498 if (cli_send_trans(cli
,SMBtrans
,
499 PIPE_LANMAN
, /* name */
500 0,0, /* fid, flags */
501 NULL
,0,0, /* setup, length, max */
502 param
,param_len
,2, /* param, length, max */
503 (char *)data
,data_len
,0 /* data, length, max */
505 DEBUG(0,("cli_oem_change_password: Failed to send password change for user %s\n",
510 if (!cli_receive_trans(cli
,SMBtrans
,
513 DEBUG(0,("cli_oem_change_password: Failed to recieve reply to password change for user %s\n",
519 cli
->rap_error
= SVAL(rparam
,0);
525 return (cli
->rap_error
== 0);
528 /****************************************************************************
529 Send a qpathinfo call.
530 ****************************************************************************/
532 bool cli_qpathinfo(struct cli_state
*cli
,
540 unsigned int data_len
= 0;
541 unsigned int param_len
= 0;
542 unsigned int rparam_len
, rdata_len
;
543 uint16 setup
= TRANSACT2_QPATHINFO
;
545 char *rparam
=NULL
, *rdata
=NULL
;
548 time_t (*date_fn
)(struct cli_state
*, const void *);
550 size_t nlen
= 2*(strlen(fname
)+1);
552 param
= SMB_MALLOC_ARRAY(char, 6+nlen
+2);
558 SSVAL(p
, 0, SMB_INFO_STANDARD
);
560 p
+= clistr_push(cli
, p
, fname
, nlen
, STR_TERMINATE
);
561 param_len
= PTR_DIFF(p
, param
);
564 ret
= (cli_send_trans(cli
, SMBtrans2
,
566 -1, 0, /* fid, flags */
567 &setup
, 1, 0, /* setup, length, max */
568 param
, param_len
, 10, /* param, length, max */
569 NULL
, data_len
, cli
->max_xmit
/* data, length, max */
571 cli_receive_trans(cli
, SMBtrans2
,
572 &rparam
, &rparam_len
,
573 &rdata
, &rdata_len
));
574 if (!cli_is_dos_error(cli
)) break;
576 /* we need to work around a Win95 bug - sometimes
577 it gives ERRSRV/ERRerror temprarily */
580 cli_dos_error(cli
, &eclass
, &ecode
);
581 if (eclass
!= ERRSRV
|| ecode
!= ERRerror
) break;
584 } while (count
-- && ret
==False
);
587 if (!ret
|| !rdata
|| rdata_len
< 22) {
592 date_fn
= cli_make_unix_date
;
594 date_fn
= cli_make_unix_date2
;
598 *change_time
= date_fn(cli
, rdata
+0);
601 *access_time
= date_fn(cli
, rdata
+4);
604 *write_time
= date_fn(cli
, rdata
+8);
607 *size
= IVAL(rdata
, 12);
610 *mode
= SVAL(rdata
,l1_attrFile
);
618 /****************************************************************************
619 Send a setpathinfo call.
620 ****************************************************************************/
622 bool cli_setpathinfo(struct cli_state
*cli
, const char *fname
,
629 unsigned int data_len
= 0;
630 unsigned int param_len
= 0;
631 unsigned int rparam_len
, rdata_len
;
632 uint16 setup
= TRANSACT2_SETPATHINFO
;
635 char *rparam
=NULL
, *rdata
=NULL
;
639 size_t nlen
= 2*(strlen(fname
)+1);
641 param
= SMB_MALLOC_ARRAY(char, 6+nlen
+2);
645 memset(param
, '\0', 6);
646 memset(data
, 0, sizeof(data
));
650 /* Add the information level */
651 SSVAL(p
, 0, SMB_FILE_BASIC_INFORMATION
);
656 /* Add the file name */
657 p
+= clistr_push(cli
, p
, fname
, nlen
, STR_TERMINATE
);
659 param_len
= PTR_DIFF(p
, param
);
664 * Add the create, last access, modification, and status change times
666 put_long_date(p
, create_time
);
669 put_long_date(p
, access_time
);
672 put_long_date(p
, write_time
);
675 put_long_date(p
, change_time
);
686 data_len
= PTR_DIFF(p
, data
);
689 ret
= (cli_send_trans(cli
, SMBtrans2
,
691 -1, 0, /* fid, flags */
692 &setup
, 1, 0, /* setup, length, max */
693 param
, param_len
, 10, /* param, length, max */
694 data
, data_len
, cli
->max_xmit
/* data, length, max */
696 cli_receive_trans(cli
, SMBtrans2
,
697 &rparam
, &rparam_len
,
698 &rdata
, &rdata_len
));
699 if (!cli_is_dos_error(cli
)) break;
701 /* we need to work around a Win95 bug - sometimes
702 it gives ERRSRV/ERRerror temprarily */
705 cli_dos_error(cli
, &eclass
, &ecode
);
706 if (eclass
!= ERRSRV
|| ecode
!= ERRerror
) break;
709 } while (count
-- && ret
==False
);
721 /****************************************************************************
722 Send a qpathinfo call with the SMB_QUERY_FILE_ALL_INFO info level.
723 ****************************************************************************/
725 bool cli_qpathinfo2(struct cli_state
*cli
, const char *fname
,
726 struct timespec
*create_time
,
727 struct timespec
*access_time
,
728 struct timespec
*write_time
,
729 struct timespec
*change_time
,
730 SMB_OFF_T
*size
, uint16
*mode
,
733 unsigned int data_len
= 0;
734 unsigned int param_len
= 0;
735 uint16 setup
= TRANSACT2_QPATHINFO
;
737 char *rparam
=NULL
, *rdata
=NULL
;
739 size_t nlen
= 2*(strlen(fname
)+1);
741 param
= SMB_MALLOC_ARRAY(char, 6+nlen
+2);
746 memset(param
, '\0', 6);
747 SSVAL(p
, 0, SMB_QUERY_FILE_ALL_INFO
);
749 p
+= clistr_push(cli
, p
, fname
, nlen
, STR_TERMINATE
);
751 param_len
= PTR_DIFF(p
, param
);
753 if (!cli_send_trans(cli
, SMBtrans2
,
755 -1, 0, /* fid, flags */
756 &setup
, 1, 0, /* setup, length, max */
757 param
, param_len
, 10, /* param, length, max */
758 NULL
, data_len
, cli
->max_xmit
/* data, length, max */
765 if (!cli_receive_trans(cli
, SMBtrans2
,
767 &rdata
, &data_len
)) {
771 if (!rdata
|| data_len
< 22) {
776 *create_time
= interpret_long_date(rdata
+0);
779 *access_time
= interpret_long_date(rdata
+8);
782 *write_time
= interpret_long_date(rdata
+16);
785 *change_time
= interpret_long_date(rdata
+24);
788 *mode
= SVAL(rdata
, 32);
791 *size
= IVAL2_TO_SMB_BIG_UINT(rdata
,48);
794 *ino
= IVAL(rdata
, 64);
802 /****************************************************************************
804 ****************************************************************************/
806 bool cli_qpathinfo_streams(struct cli_state
*cli
, const char *fname
,
808 unsigned int *pnum_streams
,
809 struct stream_struct
**pstreams
)
811 unsigned int data_len
= 0;
812 unsigned int param_len
= 0;
813 uint16 setup
= TRANSACT2_QPATHINFO
;
815 char *rparam
=NULL
, *rdata
=NULL
;
817 unsigned int num_streams
;
818 struct stream_struct
*streams
;
820 size_t namelen
= 2*(strlen(fname
)+1);
822 param
= SMB_MALLOC_ARRAY(char, 6+namelen
+2);
828 SSVAL(p
, 0, SMB_FILE_STREAM_INFORMATION
);
830 p
+= clistr_push(cli
, p
, fname
, namelen
, STR_TERMINATE
);
832 param_len
= PTR_DIFF(p
, param
);
834 if (!cli_send_trans(cli
, SMBtrans2
,
836 -1, 0, /* fid, flags */
837 &setup
, 1, 0, /* setup, len, max */
838 param
, param_len
, 10, /* param, len, max */
839 NULL
, data_len
, cli
->max_xmit
/* data, len, max */
844 if (!cli_receive_trans(cli
, SMBtrans2
,
846 &rdata
, &data_len
)) {
859 while ((data_len
> ofs
) && (data_len
- ofs
>= 24)) {
863 struct stream_struct
*tmp
;
866 tmp
= TALLOC_REALLOC_ARRAY(mem_ctx
, streams
,
867 struct stream_struct
,
875 nlen
= IVAL(rdata
, ofs
+ 0x04);
877 streams
[num_streams
].size
= IVAL_TO_SMB_OFF_T(
879 streams
[num_streams
].alloc_size
= IVAL_TO_SMB_OFF_T(
882 if (nlen
> data_len
- (ofs
+ 24)) {
887 * We need to null-terminate src, how do I do this with
888 * convert_string_talloc??
891 tmp_buf
= TALLOC_ARRAY(streams
, uint8_t, nlen
+2);
892 if (tmp_buf
== NULL
) {
896 memcpy(tmp_buf
, rdata
+ofs
+24, nlen
);
900 if (!convert_string_talloc(streams
, CH_UTF16
, CH_UNIX
, tmp_buf
,
901 nlen
+2, &vstr
, &size
, false))
903 TALLOC_FREE(tmp_buf
);
907 TALLOC_FREE(tmp_buf
);
908 streams
[num_streams
].name
= (char *)vstr
;
911 len
= IVAL(rdata
, ofs
);
912 if (len
> data_len
- ofs
) {
922 *pnum_streams
= num_streams
;
927 TALLOC_FREE(streams
);
933 /****************************************************************************
934 Send a qfileinfo QUERY_FILE_NAME_INFO call.
935 ****************************************************************************/
937 bool cli_qfilename(struct cli_state
*cli
, uint16_t fnum
, char *name
, size_t namelen
)
939 unsigned int data_len
= 0;
940 unsigned int param_len
= 0;
941 uint16 setup
= TRANSACT2_QFILEINFO
;
943 char *rparam
=NULL
, *rdata
=NULL
;
946 SSVAL(param
, 0, fnum
);
947 SSVAL(param
, 2, SMB_QUERY_FILE_NAME_INFO
);
949 if (!cli_send_trans(cli
, SMBtrans2
,
951 -1, 0, /* fid, flags */
952 &setup
, 1, 0, /* setup, length, max */
953 param
, param_len
, 2, /* param, length, max */
954 NULL
, data_len
, cli
->max_xmit
/* data, length, max */
959 if (!cli_receive_trans(cli
, SMBtrans2
,
961 &rdata
, &data_len
)) {
965 if (!rdata
|| data_len
< 4) {
971 clistr_pull(cli
->inbuf
, name
, rdata
+4, namelen
, IVAL(rdata
, 0),
980 /****************************************************************************
981 Send a qfileinfo call.
982 ****************************************************************************/
984 bool cli_qfileinfo(struct cli_state
*cli
, uint16_t fnum
,
985 uint16
*mode
, SMB_OFF_T
*size
,
986 struct timespec
*create_time
,
987 struct timespec
*access_time
,
988 struct timespec
*write_time
,
989 struct timespec
*change_time
,
992 uint32_t data_len
= 0;
998 /* if its a win95 server then fail this - win95 totally screws it
1000 if (cli
->win95
) return False
;
1002 SSVAL(param
, 0, fnum
);
1003 SSVAL(param
, 2, SMB_QUERY_FILE_ALL_INFO
);
1005 SSVAL(&setup
, 0, TRANSACT2_QFILEINFO
);
1007 status
= cli_trans(talloc_tos(), cli
, SMBtrans2
,
1008 NULL
, -1, 0, 0, /* name, fid, function, flags */
1009 &setup
, 1, 0, /* setup, length, max */
1010 param
, 4, 2, /* param, length, max */
1011 NULL
, 0, MIN(cli
->max_xmit
, 0xffff), /* data, length, max */
1012 NULL
, 0, NULL
, /* rsetup, length */
1013 NULL
, 0, NULL
, /* rparam, length */
1014 &rdata
, 68, &data_len
);
1016 if (!NT_STATUS_IS_OK(status
)) {
1021 *create_time
= interpret_long_date((char *)rdata
+0);
1024 *access_time
= interpret_long_date((char *)rdata
+8);
1027 *write_time
= interpret_long_date((char *)rdata
+16);
1030 *change_time
= interpret_long_date((char *)rdata
+24);
1033 *mode
= SVAL(rdata
, 32);
1036 *size
= IVAL2_TO_SMB_BIG_UINT(rdata
,48);
1039 *ino
= IVAL(rdata
, 64);
1046 /****************************************************************************
1047 Send a qpathinfo BASIC_INFO call.
1048 ****************************************************************************/
1050 bool cli_qpathinfo_basic( struct cli_state
*cli
, const char *name
,
1051 SMB_STRUCT_STAT
*sbuf
, uint32
*attributes
)
1053 unsigned int param_len
= 0;
1054 unsigned int data_len
= 0;
1055 uint16 setup
= TRANSACT2_QPATHINFO
;
1057 char *rparam
=NULL
, *rdata
=NULL
;
1062 TALLOC_CTX
*frame
= talloc_stackframe();
1064 path
= talloc_strdup(frame
, name
);
1072 if ( path
[len
-1] == '\\' || path
[len
-1] == '/') {
1075 nlen
= 2*(strlen(path
)+1);
1077 param
= TALLOC_ARRAY(frame
,char,6+nlen
+2);
1082 memset(param
, '\0', 6);
1084 SSVAL(p
, 0, SMB_QUERY_FILE_BASIC_INFO
);
1086 p
+= clistr_push(cli
, p
, path
, nlen
, STR_TERMINATE
);
1087 param_len
= PTR_DIFF(p
, param
);
1090 if (!cli_send_trans(cli
, SMBtrans2
,
1092 -1, 0, /* fid, flags */
1093 &setup
, 1, 0, /* setup, length, max */
1094 param
, param_len
, 2, /* param, length, max */
1095 NULL
, 0, cli
->max_xmit
/* data, length, max */
1103 if (!cli_receive_trans(cli
, SMBtrans2
,
1104 &rparam
, ¶m_len
,
1105 &rdata
, &data_len
)) {
1109 if (data_len
< 36) {
1115 sbuf
->st_ex_atime
= interpret_long_date( rdata
+8 ); /* Access time. */
1116 sbuf
->st_ex_mtime
= interpret_long_date( rdata
+16 ); /* Write time. */
1117 sbuf
->st_ex_ctime
= interpret_long_date( rdata
+24 ); /* Change time. */
1119 *attributes
= IVAL( rdata
, 32 );
1127 /****************************************************************************
1128 Send a qfileinfo call.
1129 ****************************************************************************/
1131 bool cli_qfileinfo_test(struct cli_state
*cli
, uint16_t fnum
, int level
, char **poutdata
, uint32
*poutlen
)
1133 unsigned int data_len
= 0;
1134 unsigned int param_len
= 0;
1135 uint16 setup
= TRANSACT2_QFILEINFO
;
1137 char *rparam
=NULL
, *rdata
=NULL
;
1142 /* if its a win95 server then fail this - win95 totally screws it
1149 SSVAL(param
, 0, fnum
);
1150 SSVAL(param
, 2, level
);
1152 if (!cli_send_trans(cli
, SMBtrans2
,
1154 -1, 0, /* fid, flags */
1155 &setup
, 1, 0, /* setup, length, max */
1156 param
, param_len
, 2, /* param, length, max */
1157 NULL
, data_len
, cli
->max_xmit
/* data, length, max */
1162 if (!cli_receive_trans(cli
, SMBtrans2
,
1163 &rparam
, ¶m_len
,
1164 &rdata
, &data_len
)) {
1168 *poutdata
= (char *)memdup(rdata
, data_len
);
1175 *poutlen
= data_len
;
1182 /****************************************************************************
1183 Send a qpathinfo SMB_QUERY_FILE_ALT_NAME_INFO call.
1184 ****************************************************************************/
1186 NTSTATUS
cli_qpathinfo_alt_name(struct cli_state
*cli
, const char *fname
, fstring alt_name
)
1188 unsigned int data_len
= 0;
1189 unsigned int param_len
= 0;
1190 uint16 setup
= TRANSACT2_QPATHINFO
;
1192 char *rparam
=NULL
, *rdata
=NULL
;
1197 size_t nlen
= 2*(strlen(fname
)+1);
1199 param
= SMB_MALLOC_ARRAY(char, 6+nlen
+2);
1201 return NT_STATUS_NO_MEMORY
;
1204 memset(param
, '\0', 6);
1205 SSVAL(p
, 0, SMB_QUERY_FILE_ALT_NAME_INFO
);
1207 p
+= clistr_push(cli
, p
, fname
, nlen
, STR_TERMINATE
);
1208 param_len
= PTR_DIFF(p
, param
);
1211 ret
= (cli_send_trans(cli
, SMBtrans2
,
1213 -1, 0, /* fid, flags */
1214 &setup
, 1, 0, /* setup, length, max */
1215 param
, param_len
, 10, /* param, length, max */
1216 NULL
, data_len
, cli
->max_xmit
/* data, length, max */
1218 cli_receive_trans(cli
, SMBtrans2
,
1219 &rparam
, ¶m_len
,
1220 &rdata
, &data_len
));
1221 if (!ret
&& cli_is_dos_error(cli
)) {
1222 /* we need to work around a Win95 bug - sometimes
1223 it gives ERRSRV/ERRerror temprarily */
1226 cli_dos_error(cli
, &eclass
, &ecode
);
1227 if (eclass
!= ERRSRV
|| ecode
!= ERRerror
) break;
1230 } while (count
-- && ret
==False
);
1234 if (!ret
|| !rdata
|| data_len
< 4) {
1235 return NT_STATUS_UNSUCCESSFUL
;
1238 len
= IVAL(rdata
, 0);
1240 if (len
> data_len
- 4) {
1241 return NT_STATUS_INVALID_NETWORK_RESPONSE
;
1244 clistr_pull(cli
->inbuf
, alt_name
, rdata
+4, sizeof(fstring
), len
,
1250 return NT_STATUS_OK
;