2 Unix SMB/CIFS implementation.
4 Copyright (C) Andrew Tridgell 1994-1998
5 Copyright (C) Gerald (Jerry) Carter 2004
6 Copyright (C) James Peach 2007
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
24 /****************************************************************************
25 Call a remote api on an arbitrary pipe. takes param, data and setup buffers.
26 ****************************************************************************/
28 bool cli_api_pipe(struct cli_state
*cli
, const char *pipe_name
,
29 uint16
*setup
, uint32 setup_count
, uint32 max_setup_count
,
30 char *params
, uint32 param_count
, uint32 max_param_count
,
31 char *data
, uint32 data_count
, uint32 max_data_count
,
32 char **rparam
, uint32
*rparam_count
,
33 char **rdata
, uint32
*rdata_count
)
35 cli_send_trans(cli
, SMBtrans
,
38 setup
, setup_count
, max_setup_count
,
39 params
, param_count
, max_param_count
,
40 data
, data_count
, max_data_count
);
42 return (cli_receive_trans(cli
, SMBtrans
,
43 rparam
, (unsigned int *)rparam_count
,
44 rdata
, (unsigned int *)rdata_count
));
47 /****************************************************************************
49 ****************************************************************************/
51 bool cli_api(struct cli_state
*cli
,
52 char *param
, int prcnt
, int mprcnt
,
53 char *data
, int drcnt
, int mdrcnt
,
54 char **rparam
, unsigned int *rprcnt
,
55 char **rdata
, unsigned int *rdrcnt
)
57 cli_send_trans(cli
,SMBtrans
,
58 PIPE_LANMAN
, /* Name */
60 NULL
,0,0, /* Setup, length, max */
61 param
, prcnt
, mprcnt
, /* Params, length, max */
62 data
, drcnt
, mdrcnt
/* Data, length, max */
65 return (cli_receive_trans(cli
,SMBtrans
,
70 /****************************************************************************
71 Perform a NetWkstaUserLogon.
72 ****************************************************************************/
74 bool cli_NetWkstaUserLogon(struct cli_state
*cli
,char *user
, char *workstation
)
79 unsigned int rdrcnt
,rprcnt
;
82 memset(param
, 0, sizeof(param
));
84 /* send a SMBtrans command with api NetWkstaUserLogon */
86 SSVAL(p
,0,132); /* api number */
88 strlcpy(p
,"OOWb54WrLh",sizeof(param
)-PTR_DIFF(p
,param
));
89 p
= skip_string(param
,sizeof(param
),p
);
90 strlcpy(p
,"WB21BWDWWDDDDDDDzzzD",sizeof(param
)-PTR_DIFF(p
,param
));
91 p
= skip_string(param
,sizeof(param
),p
);
94 strlcpy(p
,user
,sizeof(param
)-PTR_DIFF(p
,param
));
100 strlcpy(p
, workstation
,sizeof(param
)-PTR_DIFF(p
,param
));
103 SSVAL(p
, 0, CLI_BUFFER_SIZE
);
105 SSVAL(p
, 0, CLI_BUFFER_SIZE
);
109 param
, PTR_DIFF(p
,param
),1024, /* param, length, max */
110 NULL
, 0, CLI_BUFFER_SIZE
, /* data, length, max */
111 &rparam
, &rprcnt
, /* return params, return size */
112 &rdata
, &rdrcnt
/* return data, return size */
114 cli
->rap_error
= rparam
? SVAL(rparam
,0) : -1;
117 if (cli
->rap_error
== 0) {
118 DEBUG(4,("NetWkstaUserLogon success\n"));
119 cli
->privileges
= SVAL(p
, 24);
120 /* The cli->eff_name field used to be set here
121 but it wasn't used anywhere else. */
123 DEBUG(1,("NetwkstaUserLogon gave error %d\n", cli
->rap_error
));
129 return (cli
->rap_error
== 0);
132 /****************************************************************************
133 Call a NetShareEnum - try and browse available connections on a host.
134 ****************************************************************************/
136 int cli_RNetShareEnum(struct cli_state
*cli
, void (*fn
)(const char *, uint32
, const char *, void *), void *state
)
141 unsigned int rdrcnt
,rprcnt
;
145 /* now send a SMBtrans command with api RNetShareEnum */
147 SSVAL(p
,0,0); /* api number */
149 strlcpy(p
,"WrLeh",sizeof(param
)-PTR_DIFF(p
,param
));
150 p
= skip_string(param
,sizeof(param
),p
);
151 strlcpy(p
,"B13BWz",sizeof(param
)-PTR_DIFF(p
,param
));
152 p
= skip_string(param
,sizeof(param
),p
);
155 * Win2k needs a *smaller* buffer than 0xFFFF here -
156 * it returns "out of server memory" with 0xFFFF !!! JRA.
162 param
, PTR_DIFF(p
,param
), 1024, /* Param, length, maxlen */
163 NULL
, 0, 0xFFE0, /* data, length, maxlen - Win2k needs a small buffer here too ! */
164 &rparam
, &rprcnt
, /* return params, length */
165 &rdata
, &rdrcnt
)) /* return data, length */
167 int res
= rparam
? SVAL(rparam
,0) : -1;
169 if (res
== 0 || res
== ERRmoredata
) {
170 int converter
=SVAL(rparam
,2);
172 char *rdata_end
= rdata
+ rdrcnt
;
174 count
=SVAL(rparam
,4);
177 for (i
=0;i
<count
;i
++,p
+=20) {
185 TALLOC_CTX
*frame
= talloc_stackframe();
187 if (p
+ 20 > rdata_end
) {
194 comment_offset
= IVAL(p
,16) & 0xFFFF;
195 if (comment_offset
< 0 || comment_offset
> (int)rdrcnt
) {
199 cmnt
= comment_offset
?(rdata
+comment_offset
-converter
):"";
201 /* Work out the comment length. */
202 for (p1
= cmnt
, len
= 0; *p1
&&
203 p1
< rdata_end
; len
++)
208 pull_string_talloc(frame
,rdata
,0,
209 &s1
,sname
,14,STR_ASCII
);
210 pull_string_talloc(frame
,rdata
,0,
211 &s2
,cmnt
,len
,STR_ASCII
);
217 fn(s1
, type
, s2
, state
);
222 DEBUG(4,("NetShareEnum res=%d\n", res
));
225 DEBUG(4,("NetShareEnum failed\n"));
234 /****************************************************************************
235 Call a NetServerEnum for the specified workgroup and servertype mask. This
236 function then calls the specified callback function for each name returned.
238 The callback function takes 4 arguments: the machine name, the server type,
239 the comment and a state pointer.
240 ****************************************************************************/
242 bool cli_NetServerEnum(struct cli_state
*cli
, char *workgroup
, uint32 stype
,
243 void (*fn
)(const char *, uint32
, const char *, void *),
248 char *rdata_end
= NULL
;
249 unsigned int rdrcnt
,rprcnt
;
254 uint32 func
= RAP_NetServerEnum2
;
255 char *last_entry
= NULL
;
260 errno
= 0; /* reset */
263 * This may take more than one transaction, so we should loop until
264 * we no longer get a more data to process or we have all of the
268 /* send a SMBtrans command with api NetServerEnum */
270 SIVAL(p
,0,func
); /* api number */
272 /* Next time through we need to use the continue api */
273 func
= RAP_NetServerEnum3
;
276 strlcpy(p
,"WrLehDOz", sizeof(param
)-PTR_DIFF(p
,param
));
278 strlcpy(p
,"WrLehDz", sizeof(param
)-PTR_DIFF(p
,param
));
281 p
= skip_string(param
, sizeof(param
), p
);
282 strlcpy(p
,"B16BBDz", sizeof(param
)-PTR_DIFF(p
,param
));
284 p
= skip_string(param
, sizeof(param
), p
);
286 SSVAL(p
,2,CLI_BUFFER_SIZE
);
291 /* If we have more data, tell the server where
295 last_entry
? last_entry
: workgroup
,
296 sizeof(param
) - PTR_DIFF(p
,param
) - 1,
297 STR_TERMINATE
|STR_UPPER
);
299 if (len
== (size_t)-1) {
305 param
, PTR_DIFF(p
,param
), 8, /* params, length, max */
306 NULL
, 0, CLI_BUFFER_SIZE
, /* data, length, max */
307 &rparam
, &rprcnt
, /* return params, return size */
308 &rdata
, &rdrcnt
)) { /* return data, return size */
310 /* break out of the loop on error */
315 rdata_end
= rdata
+ rdrcnt
;
316 res
= rparam
? SVAL(rparam
,0) : -1;
318 if (res
== 0 || res
== ERRmoredata
||
319 (res
!= -1 && cli_errno(cli
) == 0)) {
322 int converter
=SVAL(rparam
,2);
324 /* Get the number of items returned in this buffer */
325 count
= SVAL(rparam
, 4);
327 /* The next field contains the number of items left,
328 * including those returned in this buffer. So the
329 * first time through this should contain all of the
332 if (total_cnt
== 0) {
333 total_cnt
= SVAL(rparam
, 6);
336 /* Keep track of how many we have read */
340 /* The last name in the previous NetServerEnum reply is
341 * sent back to server in the NetServerEnum3 request
342 * (last_entry). The next reply should repeat this entry
343 * as the first element. We have no proof that this is
344 * always true, but from traces that seems to be the
345 * behavior from Window Servers. So first lets do a lot
346 * of checking, just being paranoid. If the string
347 * matches then we already saw this entry so skip it.
349 * NOTE: sv1_name field must be null terminated and has
350 * a max size of 16 (NetBIOS Name).
352 if (last_entry
&& count
&& p
&&
353 (strncmp(last_entry
, p
, 16) == 0)) {
354 count
-= 1; /* Skip this entry */
355 return_cnt
= -1; /* Not part of total, so don't count. */
356 p
= rdata
+ 26; /* Skip the whole record */
359 for (i
= 0; i
< count
; i
++, p
+= 26) {
364 TALLOC_CTX
*frame
= talloc_stackframe();
366 if (p
+ 26 > rdata_end
) {
372 comment_offset
= (IVAL(p
,22) & 0xFFFF)-converter
;
373 cmnt
= comment_offset
?(rdata
+comment_offset
):"";
375 if (comment_offset
< 0 || comment_offset
> (int)rdrcnt
) {
380 /* Work out the comment length. */
381 for (p1
= cmnt
, len
= 0; *p1
&&
382 p1
< rdata_end
; len
++)
388 stype
= IVAL(p
,18) & ~SV_TYPE_LOCAL_LIST_ONLY
;
390 pull_string_talloc(frame
,rdata
,0,
391 &s1
,sname
,16,STR_ASCII
);
392 pull_string_talloc(frame
,rdata
,0,
393 &s2
,cmnt
,len
,STR_ASCII
);
400 fn(s1
, stype
, s2
, state
);
404 /* We are done with the old last entry, so now we can free it */
406 SAFE_FREE(last_entry
); /* This will set it to null */
409 /* We always make a copy of the last entry if we have one */
411 last_entry
= smb_xstrdup(sname
);
414 /* If we have more data, but no last entry then error out */
415 if (!last_entry
&& (res
== ERRmoredata
)) {
424 } while ((res
== ERRmoredata
) && (total_cnt
> return_cnt
));
428 SAFE_FREE(last_entry
);
431 errno
= cli_errno(cli
);
434 /* this is a very special case, when the domain master for the
435 work group isn't part of the work group itself, there is something
441 return(return_cnt
> 0);
444 /****************************************************************************
445 Send a SamOEMChangePassword command.
446 ****************************************************************************/
448 bool cli_oem_change_password(struct cli_state
*cli
, const char *user
, const char *new_password
,
449 const char *old_password
)
452 unsigned char data
[532];
454 unsigned char old_pw_hash
[16];
455 unsigned char new_pw_hash
[16];
456 unsigned int data_len
;
457 unsigned int param_len
= 0;
460 unsigned int rprcnt
, rdrcnt
;
462 if (strlen(user
) >= sizeof(fstring
)-1) {
463 DEBUG(0,("cli_oem_change_password: user name %s is too long.\n", user
));
467 SSVAL(p
,0,214); /* SamOEMChangePassword command. */
469 strlcpy(p
, "zsT", sizeof(param
)-PTR_DIFF(p
,param
));
470 p
= skip_string(param
,sizeof(param
),p
);
471 strlcpy(p
, "B516B16", sizeof(param
)-PTR_DIFF(p
,param
));
472 p
= skip_string(param
,sizeof(param
),p
);
473 strlcpy(p
,user
, sizeof(param
)-PTR_DIFF(p
,param
));
474 p
= skip_string(param
,sizeof(param
),p
);
478 param_len
= PTR_DIFF(p
,param
);
481 * Get the Lanman hash of the old password, we
482 * use this as the key to make_oem_passwd_hash().
484 E_deshash(old_password
, old_pw_hash
);
486 encode_pw_buffer(data
, new_password
, STR_ASCII
);
488 #ifdef DEBUG_PASSWORD
489 DEBUG(100,("make_oem_passwd_hash\n"));
490 dump_data(100, data
, 516);
492 SamOEMhash( (unsigned char *)data
, (unsigned char *)old_pw_hash
, 516);
495 * Now place the old password hash in the data.
497 E_deshash(new_password
, new_pw_hash
);
499 E_old_pw_hash( new_pw_hash
, old_pw_hash
, (uchar
*)&data
[516]);
503 if (cli_send_trans(cli
,SMBtrans
,
504 PIPE_LANMAN
, /* name */
505 0,0, /* fid, flags */
506 NULL
,0,0, /* setup, length, max */
507 param
,param_len
,2, /* param, length, max */
508 (char *)data
,data_len
,0 /* data, length, max */
510 DEBUG(0,("cli_oem_change_password: Failed to send password change for user %s\n",
515 if (!cli_receive_trans(cli
,SMBtrans
,
518 DEBUG(0,("cli_oem_change_password: Failed to recieve reply to password change for user %s\n",
524 cli
->rap_error
= SVAL(rparam
,0);
530 return (cli
->rap_error
== 0);
533 /****************************************************************************
534 Send a qpathinfo call.
535 ****************************************************************************/
537 bool cli_qpathinfo(struct cli_state
*cli
,
545 unsigned int data_len
= 0;
546 unsigned int param_len
= 0;
547 unsigned int rparam_len
, rdata_len
;
548 uint16 setup
= TRANSACT2_QPATHINFO
;
550 char *rparam
=NULL
, *rdata
=NULL
;
553 time_t (*date_fn
)(struct cli_state
*, const void *);
555 size_t nlen
= 2*(strlen(fname
)+1);
557 param
= SMB_MALLOC_ARRAY(char, 6+nlen
+2);
563 SSVAL(p
, 0, SMB_INFO_STANDARD
);
565 p
+= clistr_push(cli
, p
, fname
, nlen
, STR_TERMINATE
);
566 param_len
= PTR_DIFF(p
, param
);
569 ret
= (cli_send_trans(cli
, SMBtrans2
,
571 -1, 0, /* fid, flags */
572 &setup
, 1, 0, /* setup, length, max */
573 param
, param_len
, 10, /* param, length, max */
574 NULL
, data_len
, cli
->max_xmit
/* data, length, max */
576 cli_receive_trans(cli
, SMBtrans2
,
577 &rparam
, &rparam_len
,
578 &rdata
, &rdata_len
));
579 if (!cli_is_dos_error(cli
)) break;
581 /* we need to work around a Win95 bug - sometimes
582 it gives ERRSRV/ERRerror temprarily */
585 cli_dos_error(cli
, &eclass
, &ecode
);
586 if (eclass
!= ERRSRV
|| ecode
!= ERRerror
) break;
589 } while (count
-- && ret
==False
);
592 if (!ret
|| !rdata
|| rdata_len
< 22) {
597 date_fn
= cli_make_unix_date
;
599 date_fn
= cli_make_unix_date2
;
603 *change_time
= date_fn(cli
, rdata
+0);
606 *access_time
= date_fn(cli
, rdata
+4);
609 *write_time
= date_fn(cli
, rdata
+8);
612 *size
= IVAL(rdata
, 12);
615 *mode
= SVAL(rdata
,l1_attrFile
);
623 /****************************************************************************
624 Send a setpathinfo call.
625 ****************************************************************************/
627 bool cli_setpathinfo(struct cli_state
*cli
, const char *fname
,
634 unsigned int data_len
= 0;
635 unsigned int param_len
= 0;
636 unsigned int rparam_len
, rdata_len
;
637 uint16 setup
= TRANSACT2_SETPATHINFO
;
640 char *rparam
=NULL
, *rdata
=NULL
;
644 size_t nlen
= 2*(strlen(fname
)+1);
646 param
= SMB_MALLOC_ARRAY(char, 6+nlen
+2);
650 memset(param
, '\0', 6);
651 memset(data
, 0, sizeof(data
));
655 /* Add the information level */
656 SSVAL(p
, 0, SMB_FILE_BASIC_INFORMATION
);
661 /* Add the file name */
662 p
+= clistr_push(cli
, p
, fname
, nlen
, STR_TERMINATE
);
664 param_len
= PTR_DIFF(p
, param
);
669 * Add the create, last access, modification, and status change times
671 put_long_date(p
, create_time
);
674 put_long_date(p
, access_time
);
677 put_long_date(p
, write_time
);
680 put_long_date(p
, change_time
);
691 data_len
= PTR_DIFF(p
, data
);
694 ret
= (cli_send_trans(cli
, SMBtrans2
,
696 -1, 0, /* fid, flags */
697 &setup
, 1, 0, /* setup, length, max */
698 param
, param_len
, 10, /* param, length, max */
699 data
, data_len
, cli
->max_xmit
/* data, length, max */
701 cli_receive_trans(cli
, SMBtrans2
,
702 &rparam
, &rparam_len
,
703 &rdata
, &rdata_len
));
704 if (!cli_is_dos_error(cli
)) break;
706 /* we need to work around a Win95 bug - sometimes
707 it gives ERRSRV/ERRerror temprarily */
710 cli_dos_error(cli
, &eclass
, &ecode
);
711 if (eclass
!= ERRSRV
|| ecode
!= ERRerror
) break;
714 } while (count
-- && ret
==False
);
726 /****************************************************************************
727 Send a qpathinfo call with the SMB_QUERY_FILE_ALL_INFO info level.
728 ****************************************************************************/
730 bool cli_qpathinfo2(struct cli_state
*cli
, const char *fname
,
731 struct timespec
*create_time
,
732 struct timespec
*access_time
,
733 struct timespec
*write_time
,
734 struct timespec
*change_time
,
735 SMB_OFF_T
*size
, uint16
*mode
,
738 unsigned int data_len
= 0;
739 unsigned int param_len
= 0;
740 uint16 setup
= TRANSACT2_QPATHINFO
;
742 char *rparam
=NULL
, *rdata
=NULL
;
744 size_t nlen
= 2*(strlen(fname
)+1);
746 param
= SMB_MALLOC_ARRAY(char, 6+nlen
+2);
751 memset(param
, '\0', 6);
752 SSVAL(p
, 0, SMB_QUERY_FILE_ALL_INFO
);
754 p
+= clistr_push(cli
, p
, fname
, nlen
, STR_TERMINATE
);
756 param_len
= PTR_DIFF(p
, param
);
758 if (!cli_send_trans(cli
, SMBtrans2
,
760 -1, 0, /* fid, flags */
761 &setup
, 1, 0, /* setup, length, max */
762 param
, param_len
, 10, /* param, length, max */
763 NULL
, data_len
, cli
->max_xmit
/* data, length, max */
770 if (!cli_receive_trans(cli
, SMBtrans2
,
772 &rdata
, &data_len
)) {
776 if (!rdata
|| data_len
< 22) {
781 *create_time
= interpret_long_date(rdata
+0);
784 *access_time
= interpret_long_date(rdata
+8);
787 *write_time
= interpret_long_date(rdata
+16);
790 *change_time
= interpret_long_date(rdata
+24);
793 *mode
= SVAL(rdata
, 32);
796 *size
= IVAL2_TO_SMB_BIG_UINT(rdata
,48);
799 *ino
= IVAL(rdata
, 64);
807 /****************************************************************************
808 Send a qfileinfo QUERY_FILE_NAME_INFO call.
809 ****************************************************************************/
811 bool cli_qfilename(struct cli_state
*cli
, int fnum
, char *name
, size_t namelen
)
813 unsigned int data_len
= 0;
814 unsigned int param_len
= 0;
815 uint16 setup
= TRANSACT2_QFILEINFO
;
817 char *rparam
=NULL
, *rdata
=NULL
;
820 SSVAL(param
, 0, fnum
);
821 SSVAL(param
, 2, SMB_QUERY_FILE_NAME_INFO
);
823 if (!cli_send_trans(cli
, SMBtrans2
,
825 -1, 0, /* fid, flags */
826 &setup
, 1, 0, /* setup, length, max */
827 param
, param_len
, 2, /* param, length, max */
828 NULL
, data_len
, cli
->max_xmit
/* data, length, max */
833 if (!cli_receive_trans(cli
, SMBtrans2
,
835 &rdata
, &data_len
)) {
839 if (!rdata
|| data_len
< 4) {
843 clistr_pull(cli
, name
, rdata
+4, namelen
, IVAL(rdata
, 0), STR_UNICODE
);
848 /****************************************************************************
849 Send a qfileinfo call.
850 ****************************************************************************/
852 bool cli_qfileinfo(struct cli_state
*cli
, int fnum
,
853 uint16
*mode
, SMB_OFF_T
*size
,
854 struct timespec
*create_time
,
855 struct timespec
*access_time
,
856 struct timespec
*write_time
,
857 struct timespec
*change_time
,
860 unsigned int data_len
= 0;
861 unsigned int param_len
= 0;
862 uint16 setup
= TRANSACT2_QFILEINFO
;
864 char *rparam
=NULL
, *rdata
=NULL
;
866 /* if its a win95 server then fail this - win95 totally screws it
868 if (cli
->win95
) return False
;
872 SSVAL(param
, 0, fnum
);
873 SSVAL(param
, 2, SMB_QUERY_FILE_ALL_INFO
);
875 if (!cli_send_trans(cli
, SMBtrans2
,
877 -1, 0, /* fid, flags */
878 &setup
, 1, 0, /* setup, length, max */
879 param
, param_len
, 2, /* param, length, max */
880 NULL
, data_len
, cli
->max_xmit
/* data, length, max */
885 if (!cli_receive_trans(cli
, SMBtrans2
,
887 &rdata
, &data_len
)) {
891 if (!rdata
|| data_len
< 68) {
896 *create_time
= interpret_long_date(rdata
+0);
899 *access_time
= interpret_long_date(rdata
+8);
902 *write_time
= interpret_long_date(rdata
+16);
905 *change_time
= interpret_long_date(rdata
+24);
908 *mode
= SVAL(rdata
, 32);
911 *size
= IVAL2_TO_SMB_BIG_UINT(rdata
,48);
914 *ino
= IVAL(rdata
, 64);
922 /****************************************************************************
923 Send a qpathinfo BASIC_INFO call.
924 ****************************************************************************/
926 bool cli_qpathinfo_basic( struct cli_state
*cli
, const char *name
,
927 SMB_STRUCT_STAT
*sbuf
, uint32
*attributes
)
929 unsigned int param_len
= 0;
930 unsigned int data_len
= 0;
931 uint16 setup
= TRANSACT2_QPATHINFO
;
933 char *rparam
=NULL
, *rdata
=NULL
;
938 TALLOC_CTX
*frame
= talloc_stackframe();
940 path
= talloc_strdup(frame
, name
);
948 if ( path
[len
-1] == '\\' || path
[len
-1] == '/') {
951 nlen
= 2*(strlen(path
)+1);
953 param
= TALLOC_ARRAY(frame
,char,6+nlen
+2);
958 memset(param
, '\0', 6);
960 SSVAL(p
, 0, SMB_QUERY_FILE_BASIC_INFO
);
962 p
+= clistr_push(cli
, p
, path
, nlen
, STR_TERMINATE
);
963 param_len
= PTR_DIFF(p
, param
);
966 if (!cli_send_trans(cli
, SMBtrans2
,
968 -1, 0, /* fid, flags */
969 &setup
, 1, 0, /* setup, length, max */
970 param
, param_len
, 2, /* param, length, max */
971 NULL
, 0, cli
->max_xmit
/* data, length, max */
979 if (!cli_receive_trans(cli
, SMBtrans2
,
981 &rdata
, &data_len
)) {
991 set_atimespec(sbuf
, interpret_long_date( rdata
+8 )); /* Access time. */
992 set_mtimespec(sbuf
, interpret_long_date( rdata
+16 )); /* Write time. */
993 set_ctimespec(sbuf
, interpret_long_date( rdata
+24 )); /* Change time. */
995 *attributes
= IVAL( rdata
, 32 );
1003 /****************************************************************************
1004 Send a qfileinfo call.
1005 ****************************************************************************/
1007 bool cli_qfileinfo_test(struct cli_state
*cli
, int fnum
, int level
, char **poutdata
, uint32
*poutlen
)
1009 unsigned int data_len
= 0;
1010 unsigned int param_len
= 0;
1011 uint16 setup
= TRANSACT2_QFILEINFO
;
1013 char *rparam
=NULL
, *rdata
=NULL
;
1018 /* if its a win95 server then fail this - win95 totally screws it
1025 SSVAL(param
, 0, fnum
);
1026 SSVAL(param
, 2, level
);
1028 if (!cli_send_trans(cli
, SMBtrans2
,
1030 -1, 0, /* fid, flags */
1031 &setup
, 1, 0, /* setup, length, max */
1032 param
, param_len
, 2, /* param, length, max */
1033 NULL
, data_len
, cli
->max_xmit
/* data, length, max */
1038 if (!cli_receive_trans(cli
, SMBtrans2
,
1039 &rparam
, ¶m_len
,
1040 &rdata
, &data_len
)) {
1044 *poutdata
= (char *)memdup(rdata
, data_len
);
1051 *poutlen
= data_len
;
1058 /****************************************************************************
1059 Send a qpathinfo SMB_QUERY_FILE_ALT_NAME_INFO call.
1060 ****************************************************************************/
1062 NTSTATUS
cli_qpathinfo_alt_name(struct cli_state
*cli
, const char *fname
, fstring alt_name
)
1064 unsigned int data_len
= 0;
1065 unsigned int param_len
= 0;
1066 uint16 setup
= TRANSACT2_QPATHINFO
;
1068 char *rparam
=NULL
, *rdata
=NULL
;
1073 size_t nlen
= 2*(strlen(fname
)+1);
1075 param
= SMB_MALLOC_ARRAY(char, 6+nlen
+2);
1077 return NT_STATUS_NO_MEMORY
;
1080 memset(param
, '\0', 6);
1081 SSVAL(p
, 0, SMB_QUERY_FILE_ALT_NAME_INFO
);
1083 p
+= clistr_push(cli
, p
, fname
, nlen
, STR_TERMINATE
);
1084 param_len
= PTR_DIFF(p
, param
);
1087 ret
= (cli_send_trans(cli
, SMBtrans2
,
1089 -1, 0, /* fid, flags */
1090 &setup
, 1, 0, /* setup, length, max */
1091 param
, param_len
, 10, /* param, length, max */
1092 NULL
, data_len
, cli
->max_xmit
/* data, length, max */
1094 cli_receive_trans(cli
, SMBtrans2
,
1095 &rparam
, ¶m_len
,
1096 &rdata
, &data_len
));
1097 if (!ret
&& cli_is_dos_error(cli
)) {
1098 /* we need to work around a Win95 bug - sometimes
1099 it gives ERRSRV/ERRerror temprarily */
1102 cli_dos_error(cli
, &eclass
, &ecode
);
1103 if (eclass
!= ERRSRV
|| ecode
!= ERRerror
) break;
1106 } while (count
-- && ret
==False
);
1110 if (!ret
|| !rdata
|| data_len
< 4) {
1111 return NT_STATUS_UNSUCCESSFUL
;
1114 len
= IVAL(rdata
, 0);
1116 if (len
> data_len
- 4) {
1117 return NT_STATUS_INVALID_NETWORK_RESPONSE
;
1120 clistr_pull(cli
, alt_name
, rdata
+4, sizeof(fstring
), len
, STR_UNICODE
);
1125 return NT_STATUS_OK
;