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 */
251 /* Next time through we need to use the continue api */
252 func
= RAP_NetServerEnum3
;
255 strlcpy(p
,"WrLehDOz", 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
274 last_entry
? last_entry
: workgroup
,
275 sizeof(param
) - PTR_DIFF(p
,param
) - 1,
276 STR_TERMINATE
|STR_UPPER
);
278 if (len
== (size_t)-1) {
279 SAFE_FREE(last_entry
);
285 param
, PTR_DIFF(p
,param
), 8, /* params, length, max */
286 NULL
, 0, CLI_BUFFER_SIZE
, /* data, length, max */
287 &rparam
, &rprcnt
, /* return params, return size */
288 &rdata
, &rdrcnt
)) { /* return data, return size */
290 /* break out of the loop on error */
295 rdata_end
= rdata
+ rdrcnt
;
296 res
= rparam
? SVAL(rparam
,0) : -1;
298 if (res
== 0 || res
== ERRmoredata
||
299 (res
!= -1 && cli_errno(cli
) == 0)) {
302 int converter
=SVAL(rparam
,2);
304 /* Get the number of items returned in this buffer */
305 count
= SVAL(rparam
, 4);
307 /* The next field contains the number of items left,
308 * including those returned in this buffer. So the
309 * first time through this should contain all of the
312 if (total_cnt
== 0) {
313 total_cnt
= SVAL(rparam
, 6);
316 /* Keep track of how many we have read */
320 /* The last name in the previous NetServerEnum reply is
321 * sent back to server in the NetServerEnum3 request
322 * (last_entry). The next reply should repeat this entry
323 * as the first element. We have no proof that this is
324 * always true, but from traces that seems to be the
325 * behavior from Window Servers. So first lets do a lot
326 * of checking, just being paranoid. If the string
327 * matches then we already saw this entry so skip it.
329 * NOTE: sv1_name field must be null terminated and has
330 * a max size of 16 (NetBIOS Name).
332 if (last_entry
&& count
&& p
&&
333 (strncmp(last_entry
, p
, 16) == 0)) {
334 count
-= 1; /* Skip this entry */
335 return_cnt
= -1; /* Not part of total, so don't count. */
336 p
= rdata
+ 26; /* Skip the whole record */
339 for (i
= 0; i
< count
; i
++, p
+= 26) {
344 TALLOC_CTX
*frame
= talloc_stackframe();
345 uint32_t entry_stype
;
347 if (p
+ 26 > rdata_end
) {
353 comment_offset
= (IVAL(p
,22) & 0xFFFF)-converter
;
354 cmnt
= comment_offset
?(rdata
+comment_offset
):"";
356 if (comment_offset
< 0 || comment_offset
> (int)rdrcnt
) {
361 /* Work out the comment length. */
362 for (p1
= cmnt
, len
= 0; *p1
&&
363 p1
< rdata_end
; len
++)
369 entry_stype
= IVAL(p
,18) & ~SV_TYPE_LOCAL_LIST_ONLY
;
371 pull_string_talloc(frame
,rdata
,0,
372 &s1
,sname
,16,STR_ASCII
);
373 pull_string_talloc(frame
,rdata
,0,
374 &s2
,cmnt
,len
,STR_ASCII
);
381 fn(s1
, entry_stype
, s2
, state
);
385 /* We are done with the old last entry, so now we can free it */
387 SAFE_FREE(last_entry
); /* This will set it to null */
390 /* We always make a copy of the last entry if we have one */
392 last_entry
= smb_xstrdup(sname
);
395 /* If we have more data, but no last entry then error out */
396 if (!last_entry
&& (res
== ERRmoredata
)) {
405 } while ((res
== ERRmoredata
) && (total_cnt
> return_cnt
));
409 SAFE_FREE(last_entry
);
412 errno
= cli_errno(cli
);
415 /* this is a very special case, when the domain master for the
416 work group isn't part of the work group itself, there is something
422 return(return_cnt
> 0);
425 /****************************************************************************
426 Send a SamOEMChangePassword command.
427 ****************************************************************************/
429 bool cli_oem_change_password(struct cli_state
*cli
, const char *user
, const char *new_password
,
430 const char *old_password
)
433 unsigned char data
[532];
435 unsigned char old_pw_hash
[16];
436 unsigned char new_pw_hash
[16];
437 unsigned int data_len
;
438 unsigned int param_len
= 0;
441 unsigned int rprcnt
, rdrcnt
;
443 if (strlen(user
) >= sizeof(fstring
)-1) {
444 DEBUG(0,("cli_oem_change_password: user name %s is too long.\n", user
));
448 SSVAL(p
,0,214); /* SamOEMChangePassword command. */
450 strlcpy(p
, "zsT", sizeof(param
)-PTR_DIFF(p
,param
));
451 p
= skip_string(param
,sizeof(param
),p
);
452 strlcpy(p
, "B516B16", sizeof(param
)-PTR_DIFF(p
,param
));
453 p
= skip_string(param
,sizeof(param
),p
);
454 strlcpy(p
,user
, sizeof(param
)-PTR_DIFF(p
,param
));
455 p
= skip_string(param
,sizeof(param
),p
);
459 param_len
= PTR_DIFF(p
,param
);
462 * Get the Lanman hash of the old password, we
463 * use this as the key to make_oem_passwd_hash().
465 E_deshash(old_password
, old_pw_hash
);
467 encode_pw_buffer(data
, new_password
, STR_ASCII
);
469 #ifdef DEBUG_PASSWORD
470 DEBUG(100,("make_oem_passwd_hash\n"));
471 dump_data(100, data
, 516);
473 arcfour_crypt( (unsigned char *)data
, (unsigned char *)old_pw_hash
, 516);
476 * Now place the old password hash in the data.
478 E_deshash(new_password
, new_pw_hash
);
480 E_old_pw_hash( new_pw_hash
, old_pw_hash
, (uchar
*)&data
[516]);
484 if (cli_send_trans(cli
,SMBtrans
,
485 PIPE_LANMAN
, /* name */
486 0,0, /* fid, flags */
487 NULL
,0,0, /* setup, length, max */
488 param
,param_len
,2, /* param, length, max */
489 (char *)data
,data_len
,0 /* data, length, max */
491 DEBUG(0,("cli_oem_change_password: Failed to send password change for user %s\n",
496 if (!cli_receive_trans(cli
,SMBtrans
,
499 DEBUG(0,("cli_oem_change_password: Failed to recieve reply to password change for user %s\n",
505 cli
->rap_error
= SVAL(rparam
,0);
511 return (cli
->rap_error
== 0);
514 /****************************************************************************
515 Send a qpathinfo call.
516 ****************************************************************************/
518 bool cli_qpathinfo(struct cli_state
*cli
,
526 unsigned int data_len
= 0;
527 unsigned int param_len
= 0;
528 unsigned int rparam_len
, rdata_len
;
529 uint16 setup
= TRANSACT2_QPATHINFO
;
531 char *rparam
=NULL
, *rdata
=NULL
;
534 time_t (*date_fn
)(struct cli_state
*, const void *);
536 size_t nlen
= 2*(strlen(fname
)+1);
538 param
= SMB_MALLOC_ARRAY(char, 6+nlen
+2);
544 SSVAL(p
, 0, SMB_INFO_STANDARD
);
546 p
+= clistr_push(cli
, p
, fname
, nlen
, STR_TERMINATE
);
547 param_len
= PTR_DIFF(p
, param
);
550 ret
= (cli_send_trans(cli
, SMBtrans2
,
552 -1, 0, /* fid, flags */
553 &setup
, 1, 0, /* setup, length, max */
554 param
, param_len
, 10, /* param, length, max */
555 NULL
, data_len
, cli
->max_xmit
/* data, length, max */
557 cli_receive_trans(cli
, SMBtrans2
,
558 &rparam
, &rparam_len
,
559 &rdata
, &rdata_len
));
560 if (!cli_is_dos_error(cli
)) break;
562 /* we need to work around a Win95 bug - sometimes
563 it gives ERRSRV/ERRerror temprarily */
566 cli_dos_error(cli
, &eclass
, &ecode
);
567 if (eclass
!= ERRSRV
|| ecode
!= ERRerror
) break;
570 } while (count
-- && ret
==False
);
573 if (!ret
|| !rdata
|| rdata_len
< 22) {
578 date_fn
= cli_make_unix_date
;
580 date_fn
= cli_make_unix_date2
;
584 *change_time
= date_fn(cli
, rdata
+0);
587 *access_time
= date_fn(cli
, rdata
+4);
590 *write_time
= date_fn(cli
, rdata
+8);
593 *size
= IVAL(rdata
, 12);
596 *mode
= SVAL(rdata
,l1_attrFile
);
604 /****************************************************************************
605 Send a setpathinfo call.
606 ****************************************************************************/
608 bool cli_setpathinfo(struct cli_state
*cli
, const char *fname
,
615 unsigned int data_len
= 0;
616 unsigned int param_len
= 0;
617 unsigned int rparam_len
, rdata_len
;
618 uint16 setup
= TRANSACT2_SETPATHINFO
;
621 char *rparam
=NULL
, *rdata
=NULL
;
625 size_t nlen
= 2*(strlen(fname
)+1);
627 param
= SMB_MALLOC_ARRAY(char, 6+nlen
+2);
631 memset(param
, '\0', 6);
632 memset(data
, 0, sizeof(data
));
636 /* Add the information level */
637 SSVAL(p
, 0, SMB_FILE_BASIC_INFORMATION
);
642 /* Add the file name */
643 p
+= clistr_push(cli
, p
, fname
, nlen
, STR_TERMINATE
);
645 param_len
= PTR_DIFF(p
, param
);
650 * Add the create, last access, modification, and status change times
652 put_long_date(p
, create_time
);
655 put_long_date(p
, access_time
);
658 put_long_date(p
, write_time
);
661 put_long_date(p
, change_time
);
672 data_len
= PTR_DIFF(p
, data
);
675 ret
= (cli_send_trans(cli
, SMBtrans2
,
677 -1, 0, /* fid, flags */
678 &setup
, 1, 0, /* setup, length, max */
679 param
, param_len
, 10, /* param, length, max */
680 data
, data_len
, cli
->max_xmit
/* data, length, max */
682 cli_receive_trans(cli
, SMBtrans2
,
683 &rparam
, &rparam_len
,
684 &rdata
, &rdata_len
));
685 if (!cli_is_dos_error(cli
)) break;
687 /* we need to work around a Win95 bug - sometimes
688 it gives ERRSRV/ERRerror temprarily */
691 cli_dos_error(cli
, &eclass
, &ecode
);
692 if (eclass
!= ERRSRV
|| ecode
!= ERRerror
) break;
695 } while (count
-- && ret
==False
);
707 /****************************************************************************
708 Send a qpathinfo call with the SMB_QUERY_FILE_ALL_INFO info level.
709 ****************************************************************************/
711 bool cli_qpathinfo2(struct cli_state
*cli
, const char *fname
,
712 struct timespec
*create_time
,
713 struct timespec
*access_time
,
714 struct timespec
*write_time
,
715 struct timespec
*change_time
,
716 SMB_OFF_T
*size
, uint16
*mode
,
719 unsigned int data_len
= 0;
720 unsigned int param_len
= 0;
721 uint16 setup
= TRANSACT2_QPATHINFO
;
723 char *rparam
=NULL
, *rdata
=NULL
;
725 size_t nlen
= 2*(strlen(fname
)+1);
727 param
= SMB_MALLOC_ARRAY(char, 6+nlen
+2);
732 memset(param
, '\0', 6);
733 SSVAL(p
, 0, SMB_QUERY_FILE_ALL_INFO
);
735 p
+= clistr_push(cli
, p
, fname
, nlen
, STR_TERMINATE
);
737 param_len
= PTR_DIFF(p
, param
);
739 if (!cli_send_trans(cli
, SMBtrans2
,
741 -1, 0, /* fid, flags */
742 &setup
, 1, 0, /* setup, length, max */
743 param
, param_len
, 10, /* param, length, max */
744 NULL
, data_len
, cli
->max_xmit
/* data, length, max */
751 if (!cli_receive_trans(cli
, SMBtrans2
,
753 &rdata
, &data_len
)) {
757 if (!rdata
|| data_len
< 22) {
762 *create_time
= interpret_long_date(rdata
+0);
765 *access_time
= interpret_long_date(rdata
+8);
768 *write_time
= interpret_long_date(rdata
+16);
771 *change_time
= interpret_long_date(rdata
+24);
774 *mode
= SVAL(rdata
, 32);
777 *size
= IVAL2_TO_SMB_BIG_UINT(rdata
,48);
780 *ino
= IVAL(rdata
, 64);
788 /****************************************************************************
790 ****************************************************************************/
792 bool cli_qpathinfo_streams(struct cli_state
*cli
, const char *fname
,
794 unsigned int *pnum_streams
,
795 struct stream_struct
**pstreams
)
797 unsigned int data_len
= 0;
798 unsigned int param_len
= 0;
799 uint16 setup
= TRANSACT2_QPATHINFO
;
801 char *rparam
=NULL
, *rdata
=NULL
;
803 unsigned int num_streams
;
804 struct stream_struct
*streams
;
806 size_t namelen
= 2*(strlen(fname
)+1);
808 param
= SMB_MALLOC_ARRAY(char, 6+namelen
+2);
814 SSVAL(p
, 0, SMB_FILE_STREAM_INFORMATION
);
816 p
+= clistr_push(cli
, p
, fname
, namelen
, STR_TERMINATE
);
818 param_len
= PTR_DIFF(p
, param
);
820 if (!cli_send_trans(cli
, SMBtrans2
,
822 -1, 0, /* fid, flags */
823 &setup
, 1, 0, /* setup, len, max */
824 param
, param_len
, 10, /* param, len, max */
825 NULL
, data_len
, cli
->max_xmit
/* data, len, max */
830 if (!cli_receive_trans(cli
, SMBtrans2
,
832 &rdata
, &data_len
)) {
845 while ((data_len
> ofs
) && (data_len
- ofs
>= 24)) {
849 struct stream_struct
*tmp
;
852 tmp
= TALLOC_REALLOC_ARRAY(mem_ctx
, streams
,
853 struct stream_struct
,
861 nlen
= IVAL(rdata
, ofs
+ 0x04);
863 streams
[num_streams
].size
= IVAL_TO_SMB_OFF_T(
865 streams
[num_streams
].alloc_size
= IVAL_TO_SMB_OFF_T(
868 if (nlen
> data_len
- (ofs
+ 24)) {
873 * We need to null-terminate src, how do I do this with
874 * convert_string_talloc??
877 tmp_buf
= TALLOC_ARRAY(streams
, uint8_t, nlen
+2);
878 if (tmp_buf
== NULL
) {
882 memcpy(tmp_buf
, rdata
+ofs
+24, nlen
);
886 if (!convert_string_talloc(streams
, CH_UTF16
, CH_UNIX
, tmp_buf
,
887 nlen
+2, &vstr
, &size
, false))
889 TALLOC_FREE(tmp_buf
);
893 TALLOC_FREE(tmp_buf
);
894 streams
[num_streams
].name
= (char *)vstr
;
897 len
= IVAL(rdata
, ofs
);
898 if (len
> data_len
- ofs
) {
908 *pnum_streams
= num_streams
;
913 TALLOC_FREE(streams
);
919 /****************************************************************************
920 Send a qfileinfo QUERY_FILE_NAME_INFO call.
921 ****************************************************************************/
923 bool cli_qfilename(struct cli_state
*cli
, uint16_t fnum
, char *name
, size_t namelen
)
925 unsigned int data_len
= 0;
926 unsigned int param_len
= 0;
927 uint16 setup
= TRANSACT2_QFILEINFO
;
929 char *rparam
=NULL
, *rdata
=NULL
;
932 SSVAL(param
, 0, fnum
);
933 SSVAL(param
, 2, SMB_QUERY_FILE_NAME_INFO
);
935 if (!cli_send_trans(cli
, SMBtrans2
,
937 -1, 0, /* fid, flags */
938 &setup
, 1, 0, /* setup, length, max */
939 param
, param_len
, 2, /* param, length, max */
940 NULL
, data_len
, cli
->max_xmit
/* data, length, max */
945 if (!cli_receive_trans(cli
, SMBtrans2
,
947 &rdata
, &data_len
)) {
951 if (!rdata
|| data_len
< 4) {
957 clistr_pull(cli
->inbuf
, name
, rdata
+4, namelen
, IVAL(rdata
, 0),
966 /****************************************************************************
967 Send a qfileinfo call.
968 ****************************************************************************/
970 bool cli_qfileinfo(struct cli_state
*cli
, uint16_t fnum
,
971 uint16
*mode
, SMB_OFF_T
*size
,
972 struct timespec
*create_time
,
973 struct timespec
*access_time
,
974 struct timespec
*write_time
,
975 struct timespec
*change_time
,
978 uint32_t data_len
= 0;
984 /* if its a win95 server then fail this - win95 totally screws it
986 if (cli
->win95
) return False
;
988 SSVAL(param
, 0, fnum
);
989 SSVAL(param
, 2, SMB_QUERY_FILE_ALL_INFO
);
991 SSVAL(&setup
, 0, TRANSACT2_QFILEINFO
);
993 status
= cli_trans(talloc_tos(), cli
, SMBtrans2
,
994 NULL
, -1, 0, 0, /* name, fid, function, flags */
995 &setup
, 1, 0, /* setup, length, max */
996 param
, 4, 2, /* param, length, max */
997 NULL
, 0, MIN(cli
->max_xmit
, 0xffff), /* data, length, max */
998 NULL
, 0, NULL
, /* rsetup, length */
999 NULL
, 0, NULL
, /* rparam, length */
1000 &rdata
, 68, &data_len
);
1002 if (!NT_STATUS_IS_OK(status
)) {
1007 *create_time
= interpret_long_date((char *)rdata
+0);
1010 *access_time
= interpret_long_date((char *)rdata
+8);
1013 *write_time
= interpret_long_date((char *)rdata
+16);
1016 *change_time
= interpret_long_date((char *)rdata
+24);
1019 *mode
= SVAL(rdata
, 32);
1022 *size
= IVAL2_TO_SMB_BIG_UINT(rdata
,48);
1025 *ino
= IVAL(rdata
, 64);
1032 /****************************************************************************
1033 Send a qpathinfo BASIC_INFO call.
1034 ****************************************************************************/
1036 bool cli_qpathinfo_basic( struct cli_state
*cli
, const char *name
,
1037 SMB_STRUCT_STAT
*sbuf
, uint32
*attributes
)
1039 unsigned int param_len
= 0;
1040 unsigned int data_len
= 0;
1041 uint16 setup
= TRANSACT2_QPATHINFO
;
1043 char *rparam
=NULL
, *rdata
=NULL
;
1048 TALLOC_CTX
*frame
= talloc_stackframe();
1050 path
= talloc_strdup(frame
, name
);
1058 if ( path
[len
-1] == '\\' || path
[len
-1] == '/') {
1061 nlen
= 2*(strlen(path
)+1);
1063 param
= TALLOC_ARRAY(frame
,char,6+nlen
+2);
1068 memset(param
, '\0', 6);
1070 SSVAL(p
, 0, SMB_QUERY_FILE_BASIC_INFO
);
1072 p
+= clistr_push(cli
, p
, path
, nlen
, STR_TERMINATE
);
1073 param_len
= PTR_DIFF(p
, param
);
1076 if (!cli_send_trans(cli
, SMBtrans2
,
1078 -1, 0, /* fid, flags */
1079 &setup
, 1, 0, /* setup, length, max */
1080 param
, param_len
, 2, /* param, length, max */
1081 NULL
, 0, cli
->max_xmit
/* data, length, max */
1089 if (!cli_receive_trans(cli
, SMBtrans2
,
1090 &rparam
, ¶m_len
,
1091 &rdata
, &data_len
)) {
1095 if (data_len
< 36) {
1101 sbuf
->st_ex_atime
= interpret_long_date( rdata
+8 ); /* Access time. */
1102 sbuf
->st_ex_mtime
= interpret_long_date( rdata
+16 ); /* Write time. */
1103 sbuf
->st_ex_ctime
= interpret_long_date( rdata
+24 ); /* Change time. */
1105 *attributes
= IVAL( rdata
, 32 );
1113 /****************************************************************************
1114 Send a qfileinfo call.
1115 ****************************************************************************/
1117 bool cli_qfileinfo_test(struct cli_state
*cli
, uint16_t fnum
, int level
, char **poutdata
, uint32
*poutlen
)
1119 unsigned int data_len
= 0;
1120 unsigned int param_len
= 0;
1121 uint16 setup
= TRANSACT2_QFILEINFO
;
1123 char *rparam
=NULL
, *rdata
=NULL
;
1128 /* if its a win95 server then fail this - win95 totally screws it
1135 SSVAL(param
, 0, fnum
);
1136 SSVAL(param
, 2, level
);
1138 if (!cli_send_trans(cli
, SMBtrans2
,
1140 -1, 0, /* fid, flags */
1141 &setup
, 1, 0, /* setup, length, max */
1142 param
, param_len
, 2, /* param, length, max */
1143 NULL
, data_len
, cli
->max_xmit
/* data, length, max */
1148 if (!cli_receive_trans(cli
, SMBtrans2
,
1149 &rparam
, ¶m_len
,
1150 &rdata
, &data_len
)) {
1154 *poutdata
= (char *)memdup(rdata
, data_len
);
1161 *poutlen
= data_len
;
1168 /****************************************************************************
1169 Send a qpathinfo SMB_QUERY_FILE_ALT_NAME_INFO call.
1170 ****************************************************************************/
1172 NTSTATUS
cli_qpathinfo_alt_name(struct cli_state
*cli
, const char *fname
, fstring alt_name
)
1174 unsigned int data_len
= 0;
1175 unsigned int param_len
= 0;
1176 uint16 setup
= TRANSACT2_QPATHINFO
;
1178 char *rparam
=NULL
, *rdata
=NULL
;
1183 size_t nlen
= 2*(strlen(fname
)+1);
1185 param
= SMB_MALLOC_ARRAY(char, 6+nlen
+2);
1187 return NT_STATUS_NO_MEMORY
;
1190 memset(param
, '\0', 6);
1191 SSVAL(p
, 0, SMB_QUERY_FILE_ALT_NAME_INFO
);
1193 p
+= clistr_push(cli
, p
, fname
, nlen
, STR_TERMINATE
);
1194 param_len
= PTR_DIFF(p
, param
);
1197 ret
= (cli_send_trans(cli
, SMBtrans2
,
1199 -1, 0, /* fid, flags */
1200 &setup
, 1, 0, /* setup, length, max */
1201 param
, param_len
, 10, /* param, length, max */
1202 NULL
, data_len
, cli
->max_xmit
/* data, length, max */
1204 cli_receive_trans(cli
, SMBtrans2
,
1205 &rparam
, ¶m_len
,
1206 &rdata
, &data_len
));
1207 if (!ret
&& cli_is_dos_error(cli
)) {
1208 /* we need to work around a Win95 bug - sometimes
1209 it gives ERRSRV/ERRerror temprarily */
1212 cli_dos_error(cli
, &eclass
, &ecode
);
1213 if (eclass
!= ERRSRV
|| ecode
!= ERRerror
) break;
1216 } while (count
-- && ret
==False
);
1220 if (!ret
|| !rdata
|| data_len
< 4) {
1221 return NT_STATUS_UNSUCCESSFUL
;
1224 len
= IVAL(rdata
, 0);
1226 if (len
> data_len
- 4) {
1227 return NT_STATUS_INVALID_NETWORK_RESPONSE
;
1230 clistr_pull(cli
->inbuf
, alt_name
, rdata
+4, sizeof(fstring
), len
,
1236 return NT_STATUS_OK
;