2 Unix SMB/CIFS implementation.
4 Copyright (C) Andrew Tridgell 1994-1998
5 Copyright (C) Jeremy Allison 2001-2002
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 /****************************************************************************
25 Hard/Symlink a file (UNIX extensions).
26 Creates new name (sym)linked to oldname.
27 ****************************************************************************/
29 static BOOL
cli_link_internal(struct cli_state
*cli
, const char *oldname
, const char *newname
, BOOL hard_link
)
31 unsigned int data_len
= 0;
32 unsigned int param_len
= 0;
33 uint16 setup
= TRANSACT2_SETPATHINFO
;
34 char param
[sizeof(pstring
)+6];
36 char *rparam
=NULL
, *rdata
=NULL
;
38 size_t oldlen
= 2*(strlen(oldname
)+1);
39 size_t newlen
= 2*(strlen(newname
)+1);
41 memset(param
, 0, sizeof(param
));
42 SSVAL(param
,0,hard_link
? SMB_SET_FILE_UNIX_HLINK
: SMB_SET_FILE_UNIX_LINK
);
45 p
+= clistr_push(cli
, p
, newname
, MIN(newlen
, sizeof(param
)-6), STR_TERMINATE
);
46 param_len
= PTR_DIFF(p
, param
);
49 p
+= clistr_push(cli
, p
, oldname
, MIN(oldlen
,sizeof(data
)), STR_TERMINATE
);
50 data_len
= PTR_DIFF(p
, data
);
52 if (!cli_send_trans(cli
, SMBtrans2
,
54 -1, 0, /* fid, flags */
55 &setup
, 1, 0, /* setup, length, max */
56 param
, param_len
, 2, /* param, length, max */
57 (char *)&data
, data_len
, cli
->max_xmit
/* data, length, max */
62 if (!cli_receive_trans(cli
, SMBtrans2
,
74 /****************************************************************************
75 Map standard UNIX permissions onto wire representations.
76 ****************************************************************************/
78 uint32
unix_perms_to_wire(mode_t perms
)
82 ret
|= ((perms
& S_IXOTH
) ? UNIX_X_OTH
: 0);
83 ret
|= ((perms
& S_IWOTH
) ? UNIX_W_OTH
: 0);
84 ret
|= ((perms
& S_IROTH
) ? UNIX_R_OTH
: 0);
85 ret
|= ((perms
& S_IXGRP
) ? UNIX_X_GRP
: 0);
86 ret
|= ((perms
& S_IWGRP
) ? UNIX_W_GRP
: 0);
87 ret
|= ((perms
& S_IRGRP
) ? UNIX_R_GRP
: 0);
88 ret
|= ((perms
& S_IXUSR
) ? UNIX_X_USR
: 0);
89 ret
|= ((perms
& S_IWUSR
) ? UNIX_W_USR
: 0);
90 ret
|= ((perms
& S_IRUSR
) ? UNIX_R_USR
: 0);
92 ret
|= ((perms
& S_ISVTX
) ? UNIX_STICKY
: 0);
95 ret
|= ((perms
& S_ISGID
) ? UNIX_SET_GID
: 0);
98 ret
|= ((perms
& S_ISUID
) ? UNIX_SET_UID
: 0);
103 /****************************************************************************
104 Map wire permissions to standard UNIX.
105 ****************************************************************************/
107 mode_t
wire_perms_to_unix(uint32 perms
)
109 mode_t ret
= (mode_t
)0;
111 ret
|= ((perms
& UNIX_X_OTH
) ? S_IXOTH
: 0);
112 ret
|= ((perms
& UNIX_W_OTH
) ? S_IWOTH
: 0);
113 ret
|= ((perms
& UNIX_R_OTH
) ? S_IROTH
: 0);
114 ret
|= ((perms
& UNIX_X_GRP
) ? S_IXGRP
: 0);
115 ret
|= ((perms
& UNIX_W_GRP
) ? S_IWGRP
: 0);
116 ret
|= ((perms
& UNIX_R_GRP
) ? S_IRGRP
: 0);
117 ret
|= ((perms
& UNIX_X_USR
) ? S_IXUSR
: 0);
118 ret
|= ((perms
& UNIX_W_USR
) ? S_IWUSR
: 0);
119 ret
|= ((perms
& UNIX_R_USR
) ? S_IRUSR
: 0);
121 ret
|= ((perms
& UNIX_STICKY
) ? S_ISVTX
: 0);
124 ret
|= ((perms
& UNIX_SET_GID
) ? S_ISGID
: 0);
127 ret
|= ((perms
& UNIX_SET_UID
) ? S_ISUID
: 0);
132 /****************************************************************************
133 Return the file type from the wire filetype for UNIX extensions.
134 ****************************************************************************/
136 static mode_t
unix_filetype_from_wire(uint32 wire_type
)
144 case UNIX_TYPE_SYMLINK
:
148 case UNIX_TYPE_CHARDEV
:
152 case UNIX_TYPE_BLKDEV
:
160 case UNIX_TYPE_SOCKET
:
168 /****************************************************************************
169 Do a POSIX getfacl (UNIX extensions).
170 ****************************************************************************/
172 BOOL
cli_unix_getfacl(struct cli_state
*cli
, const char *name
, size_t *prb_size
, char **retbuf
)
174 unsigned int param_len
= 0;
175 unsigned int data_len
= 0;
176 uint16 setup
= TRANSACT2_QPATHINFO
;
177 char param
[sizeof(pstring
)+6];
178 char *rparam
=NULL
, *rdata
=NULL
;
183 SSVAL(p
, 0, SMB_QUERY_POSIX_ACL
);
185 p
+= clistr_push(cli
, p
, name
, sizeof(pstring
)-6, STR_TERMINATE
);
186 param_len
= PTR_DIFF(p
, param
);
188 if (!cli_send_trans(cli
, SMBtrans2
,
190 -1, 0, /* fid, flags */
191 &setup
, 1, 0, /* setup, length, max */
192 param
, param_len
, 2, /* param, length, max */
193 NULL
, 0, cli
->max_xmit
/* data, length, max */
198 if (!cli_receive_trans(cli
, SMBtrans2
,
200 &rdata
, &data_len
)) {
212 *prb_size
= (size_t)data_len
;
217 /****************************************************************************
218 Stat a file (UNIX extensions).
219 ****************************************************************************/
221 BOOL
cli_unix_stat(struct cli_state
*cli
, const char *name
, SMB_STRUCT_STAT
*sbuf
)
223 unsigned int param_len
= 0;
224 unsigned int data_len
= 0;
225 uint16 setup
= TRANSACT2_QPATHINFO
;
226 char param
[sizeof(pstring
)+6];
227 char *rparam
=NULL
, *rdata
=NULL
;
234 SSVAL(p
, 0, SMB_QUERY_FILE_UNIX_BASIC
);
236 p
+= clistr_push(cli
, p
, name
, sizeof(pstring
)-6, STR_TERMINATE
);
237 param_len
= PTR_DIFF(p
, param
);
239 if (!cli_send_trans(cli
, SMBtrans2
,
241 -1, 0, /* fid, flags */
242 &setup
, 1, 0, /* setup, length, max */
243 param
, param_len
, 2, /* param, length, max */
244 NULL
, 0, cli
->max_xmit
/* data, length, max */
249 if (!cli_receive_trans(cli
, SMBtrans2
,
251 &rdata
, &data_len
)) {
261 sbuf
->st_size
= IVAL2_TO_SMB_BIG_UINT(rdata
,0); /* total size, in bytes */
262 sbuf
->st_blocks
= IVAL2_TO_SMB_BIG_UINT(rdata
,8); /* number of blocks allocated */
263 #if defined (HAVE_STAT_ST_BLOCKS) && defined(STAT_ST_BLOCKSIZE)
264 sbuf
->st_blocks
/= STAT_ST_BLOCKSIZE
;
266 /* assume 512 byte blocks */
267 sbuf
->st_blocks
/= 512;
269 set_ctimespec(sbuf
, interpret_long_date(rdata
+ 16)); /* time of last change */
270 set_atimespec(sbuf
, interpret_long_date(rdata
+ 24)); /* time of last access */
271 set_mtimespec(sbuf
, interpret_long_date(rdata
+ 32)); /* time of last modification */
273 sbuf
->st_uid
= (uid_t
) IVAL(rdata
,40); /* user ID of owner */
274 sbuf
->st_gid
= (gid_t
) IVAL(rdata
,48); /* group ID of owner */
275 sbuf
->st_mode
|= unix_filetype_from_wire(IVAL(rdata
, 56));
276 #if defined(HAVE_MAKEDEV)
278 uint32 dev_major
= IVAL(rdata
,60);
279 uint32 dev_minor
= IVAL(rdata
,68);
280 sbuf
->st_rdev
= makedev(dev_major
, dev_minor
);
283 sbuf
->st_ino
= (SMB_INO_T
)IVAL2_TO_SMB_BIG_UINT(rdata
,76); /* inode */
284 sbuf
->st_mode
|= wire_perms_to_unix(IVAL(rdata
,84)); /* protection */
285 sbuf
->st_nlink
= IVAL(rdata
,92); /* number of hard links */
293 /****************************************************************************
294 Symlink a file (UNIX extensions).
295 ****************************************************************************/
297 BOOL
cli_unix_symlink(struct cli_state
*cli
, const char *oldname
, const char *newname
)
299 return cli_link_internal(cli
, oldname
, newname
, False
);
302 /****************************************************************************
303 Hard a file (UNIX extensions).
304 ****************************************************************************/
306 BOOL
cli_unix_hardlink(struct cli_state
*cli
, const char *oldname
, const char *newname
)
308 return cli_link_internal(cli
, oldname
, newname
, True
);
311 /****************************************************************************
312 Chmod or chown a file internal (UNIX extensions).
313 ****************************************************************************/
315 static BOOL
cli_unix_chmod_chown_internal(struct cli_state
*cli
, const char *fname
, uint32 mode
, uint32 uid
, uint32 gid
)
317 unsigned int data_len
= 0;
318 unsigned int param_len
= 0;
319 uint16 setup
= TRANSACT2_SETPATHINFO
;
320 char param
[sizeof(pstring
)+6];
322 char *rparam
=NULL
, *rdata
=NULL
;
325 memset(param
, 0, sizeof(param
));
326 memset(data
, 0, sizeof(data
));
327 SSVAL(param
,0,SMB_SET_FILE_UNIX_BASIC
);
330 p
+= clistr_push(cli
, p
, fname
, -1, STR_TERMINATE
);
331 param_len
= PTR_DIFF(p
, param
);
339 if (!cli_send_trans(cli
, SMBtrans2
,
341 -1, 0, /* fid, flags */
342 &setup
, 1, 0, /* setup, length, max */
343 param
, param_len
, 2, /* param, length, max */
344 (char *)&data
, data_len
, cli
->max_xmit
/* data, length, max */
349 if (!cli_receive_trans(cli
, SMBtrans2
,
351 &rdata
, &data_len
)) {
361 /****************************************************************************
362 chmod a file (UNIX extensions).
363 ****************************************************************************/
365 BOOL
cli_unix_chmod(struct cli_state
*cli
, const char *fname
, mode_t mode
)
367 return cli_unix_chmod_chown_internal(cli
, fname
,
368 unix_perms_to_wire(mode
), SMB_UID_NO_CHANGE
, SMB_GID_NO_CHANGE
);
371 /****************************************************************************
372 chown a file (UNIX extensions).
373 ****************************************************************************/
375 BOOL
cli_unix_chown(struct cli_state
*cli
, const char *fname
, uid_t uid
, gid_t gid
)
377 return cli_unix_chmod_chown_internal(cli
, fname
, SMB_MODE_NO_CHANGE
, (uint32
)uid
, (uint32
)gid
);
380 /****************************************************************************
382 ****************************************************************************/
384 BOOL
cli_rename(struct cli_state
*cli
, const char *fname_src
, const char *fname_dst
)
388 memset(cli
->outbuf
,'\0',smb_size
);
389 memset(cli
->inbuf
,'\0',smb_size
);
391 set_message(cli
->outbuf
,1, 0, True
);
393 SCVAL(cli
->outbuf
,smb_com
,SMBmv
);
394 SSVAL(cli
->outbuf
,smb_tid
,cli
->cnum
);
395 cli_setup_packet(cli
);
397 SSVAL(cli
->outbuf
,smb_vwv0
,aSYSTEM
| aHIDDEN
| aDIR
);
399 p
= smb_buf(cli
->outbuf
);
401 p
+= clistr_push(cli
, p
, fname_src
, -1, STR_TERMINATE
);
403 p
+= clistr_push(cli
, p
, fname_dst
, -1, STR_TERMINATE
);
405 cli_setup_bcc(cli
, p
);
408 if (!cli_receive_smb(cli
))
411 if (cli_is_error(cli
))
417 /****************************************************************************
419 ****************************************************************************/
421 BOOL
cli_ntrename(struct cli_state
*cli
, const char *fname_src
, const char *fname_dst
)
425 memset(cli
->outbuf
,'\0',smb_size
);
426 memset(cli
->inbuf
,'\0',smb_size
);
428 set_message(cli
->outbuf
, 4, 0, True
);
430 SCVAL(cli
->outbuf
,smb_com
,SMBntrename
);
431 SSVAL(cli
->outbuf
,smb_tid
,cli
->cnum
);
432 cli_setup_packet(cli
);
434 SSVAL(cli
->outbuf
,smb_vwv0
,aSYSTEM
| aHIDDEN
| aDIR
);
435 SSVAL(cli
->outbuf
,smb_vwv1
, RENAME_FLAG_RENAME
);
437 p
= smb_buf(cli
->outbuf
);
439 p
+= clistr_push(cli
, p
, fname_src
, -1, STR_TERMINATE
);
441 p
+= clistr_push(cli
, p
, fname_dst
, -1, STR_TERMINATE
);
443 cli_setup_bcc(cli
, p
);
446 if (!cli_receive_smb(cli
))
449 if (cli_is_error(cli
))
455 /****************************************************************************
457 ****************************************************************************/
459 BOOL
cli_nt_hardlink(struct cli_state
*cli
, const char *fname_src
, const char *fname_dst
)
463 memset(cli
->outbuf
,'\0',smb_size
);
464 memset(cli
->inbuf
,'\0',smb_size
);
466 set_message(cli
->outbuf
, 4, 0, True
);
468 SCVAL(cli
->outbuf
,smb_com
,SMBntrename
);
469 SSVAL(cli
->outbuf
,smb_tid
,cli
->cnum
);
470 cli_setup_packet(cli
);
472 SSVAL(cli
->outbuf
,smb_vwv0
,aSYSTEM
| aHIDDEN
| aDIR
);
473 SSVAL(cli
->outbuf
,smb_vwv1
, RENAME_FLAG_HARD_LINK
);
475 p
= smb_buf(cli
->outbuf
);
477 p
+= clistr_push(cli
, p
, fname_src
, -1, STR_TERMINATE
);
479 p
+= clistr_push(cli
, p
, fname_dst
, -1, STR_TERMINATE
);
481 cli_setup_bcc(cli
, p
);
484 if (!cli_receive_smb(cli
))
487 if (cli_is_error(cli
))
493 /****************************************************************************
495 ****************************************************************************/
497 BOOL
cli_unlink_full(struct cli_state
*cli
, const char *fname
, uint16 attrs
)
501 memset(cli
->outbuf
,'\0',smb_size
);
502 memset(cli
->inbuf
,'\0',smb_size
);
504 set_message(cli
->outbuf
,1, 0,True
);
506 SCVAL(cli
->outbuf
,smb_com
,SMBunlink
);
507 SSVAL(cli
->outbuf
,smb_tid
,cli
->cnum
);
508 cli_setup_packet(cli
);
510 SSVAL(cli
->outbuf
,smb_vwv0
, attrs
);
512 p
= smb_buf(cli
->outbuf
);
514 p
+= clistr_push(cli
, p
, fname
, -1, STR_TERMINATE
);
516 cli_setup_bcc(cli
, p
);
518 if (!cli_receive_smb(cli
)) {
522 if (cli_is_error(cli
)) {
529 /****************************************************************************
531 ****************************************************************************/
533 BOOL
cli_unlink(struct cli_state
*cli
, const char *fname
)
535 return cli_unlink_full(cli
, fname
, aSYSTEM
| aHIDDEN
);
538 /****************************************************************************
540 ****************************************************************************/
542 BOOL
cli_mkdir(struct cli_state
*cli
, const char *dname
)
546 memset(cli
->outbuf
,'\0',smb_size
);
547 memset(cli
->inbuf
,'\0',smb_size
);
549 set_message(cli
->outbuf
,0, 0,True
);
551 SCVAL(cli
->outbuf
,smb_com
,SMBmkdir
);
552 SSVAL(cli
->outbuf
,smb_tid
,cli
->cnum
);
553 cli_setup_packet(cli
);
555 p
= smb_buf(cli
->outbuf
);
557 p
+= clistr_push(cli
, p
, dname
, -1, STR_TERMINATE
);
559 cli_setup_bcc(cli
, p
);
562 if (!cli_receive_smb(cli
)) {
566 if (cli_is_error(cli
)) {
573 /****************************************************************************
575 ****************************************************************************/
577 BOOL
cli_rmdir(struct cli_state
*cli
, const char *dname
)
581 memset(cli
->outbuf
,'\0',smb_size
);
582 memset(cli
->inbuf
,'\0',smb_size
);
584 set_message(cli
->outbuf
,0, 0, True
);
586 SCVAL(cli
->outbuf
,smb_com
,SMBrmdir
);
587 SSVAL(cli
->outbuf
,smb_tid
,cli
->cnum
);
588 cli_setup_packet(cli
);
590 p
= smb_buf(cli
->outbuf
);
592 p
+= clistr_push(cli
, p
, dname
, -1, STR_TERMINATE
);
594 cli_setup_bcc(cli
, p
);
597 if (!cli_receive_smb(cli
)) {
601 if (cli_is_error(cli
)) {
608 /****************************************************************************
609 Set or clear the delete on close flag.
610 ****************************************************************************/
612 int cli_nt_delete_on_close(struct cli_state
*cli
, int fnum
, BOOL flag
)
614 unsigned int data_len
= 1;
615 unsigned int param_len
= 6;
616 uint16 setup
= TRANSACT2_SETFILEINFO
;
619 char *rparam
=NULL
, *rdata
=NULL
;
621 memset(param
, 0, param_len
);
623 SSVAL(param
,2,SMB_SET_FILE_DISPOSITION_INFO
);
627 if (!cli_send_trans(cli
, SMBtrans2
,
629 -1, 0, /* fid, flags */
630 &setup
, 1, 0, /* setup, length, max */
631 param
, param_len
, 2, /* param, length, max */
632 (char *)&data
, data_len
, cli
->max_xmit
/* data, length, max */
637 if (!cli_receive_trans(cli
, SMBtrans2
,
639 &rdata
, &data_len
)) {
649 /****************************************************************************
650 Open a file - exposing the full horror of the NT API :-).
652 ****************************************************************************/
654 int cli_nt_create_full(struct cli_state
*cli
, const char *fname
,
655 uint32 CreatFlags
, uint32 DesiredAccess
,
656 uint32 FileAttributes
, uint32 ShareAccess
,
657 uint32 CreateDisposition
, uint32 CreateOptions
,
663 memset(cli
->outbuf
,'\0',smb_size
);
664 memset(cli
->inbuf
,'\0',smb_size
);
666 set_message(cli
->outbuf
,24,0,True
);
668 SCVAL(cli
->outbuf
,smb_com
,SMBntcreateX
);
669 SSVAL(cli
->outbuf
,smb_tid
,cli
->cnum
);
670 cli_setup_packet(cli
);
672 SSVAL(cli
->outbuf
,smb_vwv0
,0xFF);
673 if (cli
->use_oplocks
)
674 CreatFlags
|= (REQUEST_OPLOCK
|REQUEST_BATCH_OPLOCK
);
676 SIVAL(cli
->outbuf
,smb_ntcreate_Flags
, CreatFlags
);
677 SIVAL(cli
->outbuf
,smb_ntcreate_RootDirectoryFid
, 0x0);
678 SIVAL(cli
->outbuf
,smb_ntcreate_DesiredAccess
, DesiredAccess
);
679 SIVAL(cli
->outbuf
,smb_ntcreate_FileAttributes
, FileAttributes
);
680 SIVAL(cli
->outbuf
,smb_ntcreate_ShareAccess
, ShareAccess
);
681 SIVAL(cli
->outbuf
,smb_ntcreate_CreateDisposition
, CreateDisposition
);
682 SIVAL(cli
->outbuf
,smb_ntcreate_CreateOptions
, CreateOptions
);
683 SIVAL(cli
->outbuf
,smb_ntcreate_ImpersonationLevel
, 0x02);
684 SCVAL(cli
->outbuf
,smb_ntcreate_SecurityFlags
, SecuityFlags
);
686 p
= smb_buf(cli
->outbuf
);
687 /* this alignment and termination is critical for netapp filers. Don't change */
688 p
+= clistr_align_out(cli
, p
, 0);
689 len
= clistr_push(cli
, p
, fname
, -1, 0);
691 SSVAL(cli
->outbuf
,smb_ntcreate_NameLength
, len
);
692 /* sigh. this copes with broken netapp filer behaviour */
693 p
+= clistr_push(cli
, p
, "", -1, STR_TERMINATE
);
695 cli_setup_bcc(cli
, p
);
698 if (!cli_receive_smb(cli
)) {
702 if (cli_is_error(cli
)) {
706 return SVAL(cli
->inbuf
,smb_vwv2
+ 1);
709 /****************************************************************************
711 ****************************************************************************/
713 int cli_nt_create(struct cli_state
*cli
, const char *fname
, uint32 DesiredAccess
)
715 return cli_nt_create_full(cli
, fname
, 0, DesiredAccess
, 0,
716 FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_OPEN
, 0x0, 0x0);
719 /****************************************************************************
721 WARNING: if you open with O_WRONLY then getattrE won't work!
722 ****************************************************************************/
724 int cli_open(struct cli_state
*cli
, const char *fname
, int flags
, int share_mode
)
728 unsigned accessmode
=0;
732 if (!(flags
& O_EXCL
)) {
739 accessmode
= (share_mode
<<4);
741 if ((flags
& O_ACCMODE
) == O_RDWR
) {
743 } else if ((flags
& O_ACCMODE
) == O_WRONLY
) {
748 if ((flags
& O_SYNC
) == O_SYNC
) {
749 accessmode
|= (1<<14);
753 if (share_mode
== DENY_FCB
) {
757 memset(cli
->outbuf
,'\0',smb_size
);
758 memset(cli
->inbuf
,'\0',smb_size
);
760 set_message(cli
->outbuf
,15,0,True
);
762 SCVAL(cli
->outbuf
,smb_com
,SMBopenX
);
763 SSVAL(cli
->outbuf
,smb_tid
,cli
->cnum
);
764 cli_setup_packet(cli
);
766 SSVAL(cli
->outbuf
,smb_vwv0
,0xFF);
767 SSVAL(cli
->outbuf
,smb_vwv2
,0); /* no additional info */
768 SSVAL(cli
->outbuf
,smb_vwv3
,accessmode
);
769 SSVAL(cli
->outbuf
,smb_vwv4
,aSYSTEM
| aHIDDEN
);
770 SSVAL(cli
->outbuf
,smb_vwv5
,0);
771 SSVAL(cli
->outbuf
,smb_vwv8
,openfn
);
773 if (cli
->use_oplocks
) {
774 /* if using oplocks then ask for a batch oplock via
775 core and extended methods */
776 SCVAL(cli
->outbuf
,smb_flg
, CVAL(cli
->outbuf
,smb_flg
)|
777 FLAG_REQUEST_OPLOCK
|FLAG_REQUEST_BATCH_OPLOCK
);
778 SSVAL(cli
->outbuf
,smb_vwv2
,SVAL(cli
->outbuf
,smb_vwv2
) | 6);
781 p
= smb_buf(cli
->outbuf
);
782 p
+= clistr_push(cli
, p
, fname
, -1, STR_TERMINATE
);
784 cli_setup_bcc(cli
, p
);
787 if (!cli_receive_smb(cli
)) {
791 if (cli_is_error(cli
)) {
795 return SVAL(cli
->inbuf
,smb_vwv2
);
798 /****************************************************************************
800 ****************************************************************************/
802 BOOL
cli_close(struct cli_state
*cli
, int fnum
)
804 memset(cli
->outbuf
,'\0',smb_size
);
805 memset(cli
->inbuf
,'\0',smb_size
);
807 set_message(cli
->outbuf
,3,0,True
);
809 SCVAL(cli
->outbuf
,smb_com
,SMBclose
);
810 SSVAL(cli
->outbuf
,smb_tid
,cli
->cnum
);
811 cli_setup_packet(cli
);
813 SSVAL(cli
->outbuf
,smb_vwv0
,fnum
);
814 SIVALS(cli
->outbuf
,smb_vwv1
,-1);
817 if (!cli_receive_smb(cli
)) {
821 return !cli_is_error(cli
);
825 /****************************************************************************
826 send a lock with a specified locktype
827 this is used for testing LOCKING_ANDX_CANCEL_LOCK
828 ****************************************************************************/
830 NTSTATUS
cli_locktype(struct cli_state
*cli
, int fnum
,
831 uint32 offset
, uint32 len
, int timeout
, unsigned char locktype
)
834 int saved_timeout
= cli
->timeout
;
836 memset(cli
->outbuf
,'\0',smb_size
);
837 memset(cli
->inbuf
,'\0', smb_size
);
839 set_message(cli
->outbuf
,8,0,True
);
841 SCVAL(cli
->outbuf
,smb_com
,SMBlockingX
);
842 SSVAL(cli
->outbuf
,smb_tid
,cli
->cnum
);
843 cli_setup_packet(cli
);
845 SCVAL(cli
->outbuf
,smb_vwv0
,0xFF);
846 SSVAL(cli
->outbuf
,smb_vwv2
,fnum
);
847 SCVAL(cli
->outbuf
,smb_vwv3
,locktype
);
848 SIVALS(cli
->outbuf
, smb_vwv4
, timeout
);
849 SSVAL(cli
->outbuf
,smb_vwv6
,0);
850 SSVAL(cli
->outbuf
,smb_vwv7
,1);
852 p
= smb_buf(cli
->outbuf
);
853 SSVAL(p
, 0, cli
->pid
);
859 cli_setup_bcc(cli
, p
);
864 cli
->timeout
= (timeout
== -1) ? 0x7FFFFFFF : (timeout
+ 2*1000);
867 if (!cli_receive_smb(cli
)) {
868 cli
->timeout
= saved_timeout
;
869 return NT_STATUS_UNSUCCESSFUL
;
872 cli
->timeout
= saved_timeout
;
874 return cli_nt_error(cli
);
877 /****************************************************************************
879 note that timeout is in units of 2 milliseconds
880 ****************************************************************************/
882 BOOL
cli_lock(struct cli_state
*cli
, int fnum
,
883 uint32 offset
, uint32 len
, int timeout
, enum brl_type lock_type
)
886 int saved_timeout
= cli
->timeout
;
888 memset(cli
->outbuf
,'\0',smb_size
);
889 memset(cli
->inbuf
,'\0', smb_size
);
891 set_message(cli
->outbuf
,8,0,True
);
893 SCVAL(cli
->outbuf
,smb_com
,SMBlockingX
);
894 SSVAL(cli
->outbuf
,smb_tid
,cli
->cnum
);
895 cli_setup_packet(cli
);
897 SCVAL(cli
->outbuf
,smb_vwv0
,0xFF);
898 SSVAL(cli
->outbuf
,smb_vwv2
,fnum
);
899 SCVAL(cli
->outbuf
,smb_vwv3
,(lock_type
== READ_LOCK
? 1 : 0));
900 SIVALS(cli
->outbuf
, smb_vwv4
, timeout
);
901 SSVAL(cli
->outbuf
,smb_vwv6
,0);
902 SSVAL(cli
->outbuf
,smb_vwv7
,1);
904 p
= smb_buf(cli
->outbuf
);
905 SSVAL(p
, 0, cli
->pid
);
911 cli_setup_bcc(cli
, p
);
916 cli
->timeout
= (timeout
== -1) ? 0x7FFFFFFF : (timeout
*2 + 5*1000);
919 if (!cli_receive_smb(cli
)) {
920 cli
->timeout
= saved_timeout
;
924 cli
->timeout
= saved_timeout
;
926 if (cli_is_error(cli
)) {
933 /****************************************************************************
935 ****************************************************************************/
937 BOOL
cli_unlock(struct cli_state
*cli
, int fnum
, uint32 offset
, uint32 len
)
941 memset(cli
->outbuf
,'\0',smb_size
);
942 memset(cli
->inbuf
,'\0',smb_size
);
944 set_message(cli
->outbuf
,8,0,True
);
946 SCVAL(cli
->outbuf
,smb_com
,SMBlockingX
);
947 SSVAL(cli
->outbuf
,smb_tid
,cli
->cnum
);
948 cli_setup_packet(cli
);
950 SCVAL(cli
->outbuf
,smb_vwv0
,0xFF);
951 SSVAL(cli
->outbuf
,smb_vwv2
,fnum
);
952 SCVAL(cli
->outbuf
,smb_vwv3
,0);
953 SIVALS(cli
->outbuf
, smb_vwv4
, 0);
954 SSVAL(cli
->outbuf
,smb_vwv6
,1);
955 SSVAL(cli
->outbuf
,smb_vwv7
,0);
957 p
= smb_buf(cli
->outbuf
);
958 SSVAL(p
, 0, cli
->pid
);
962 cli_setup_bcc(cli
, p
);
964 if (!cli_receive_smb(cli
)) {
968 if (cli_is_error(cli
)) {
975 /****************************************************************************
976 Lock a file with 64 bit offsets.
977 ****************************************************************************/
979 BOOL
cli_lock64(struct cli_state
*cli
, int fnum
,
980 SMB_BIG_UINT offset
, SMB_BIG_UINT len
, int timeout
, enum brl_type lock_type
)
983 int saved_timeout
= cli
->timeout
;
986 if (! (cli
->capabilities
& CAP_LARGE_FILES
)) {
987 return cli_lock(cli
, fnum
, offset
, len
, timeout
, lock_type
);
990 ltype
= (lock_type
== READ_LOCK
? 1 : 0);
991 ltype
|= LOCKING_ANDX_LARGE_FILES
;
993 memset(cli
->outbuf
,'\0',smb_size
);
994 memset(cli
->inbuf
,'\0', smb_size
);
996 set_message(cli
->outbuf
,8,0,True
);
998 SCVAL(cli
->outbuf
,smb_com
,SMBlockingX
);
999 SSVAL(cli
->outbuf
,smb_tid
,cli
->cnum
);
1000 cli_setup_packet(cli
);
1002 SCVAL(cli
->outbuf
,smb_vwv0
,0xFF);
1003 SSVAL(cli
->outbuf
,smb_vwv2
,fnum
);
1004 SCVAL(cli
->outbuf
,smb_vwv3
,ltype
);
1005 SIVALS(cli
->outbuf
, smb_vwv4
, timeout
);
1006 SSVAL(cli
->outbuf
,smb_vwv6
,0);
1007 SSVAL(cli
->outbuf
,smb_vwv7
,1);
1009 p
= smb_buf(cli
->outbuf
);
1010 SIVAL(p
, 0, cli
->pid
);
1011 SOFF_T_R(p
, 4, offset
);
1012 SOFF_T_R(p
, 12, len
);
1015 cli_setup_bcc(cli
, p
);
1019 cli
->timeout
= (timeout
== -1) ? 0x7FFFFFFF : (timeout
+ 5*1000);
1022 if (!cli_receive_smb(cli
)) {
1023 cli
->timeout
= saved_timeout
;
1027 cli
->timeout
= saved_timeout
;
1029 if (cli_is_error(cli
)) {
1036 /****************************************************************************
1037 Unlock a file with 64 bit offsets.
1038 ****************************************************************************/
1040 BOOL
cli_unlock64(struct cli_state
*cli
, int fnum
, SMB_BIG_UINT offset
, SMB_BIG_UINT len
)
1044 if (! (cli
->capabilities
& CAP_LARGE_FILES
)) {
1045 return cli_unlock(cli
, fnum
, offset
, len
);
1048 memset(cli
->outbuf
,'\0',smb_size
);
1049 memset(cli
->inbuf
,'\0',smb_size
);
1051 set_message(cli
->outbuf
,8,0,True
);
1053 SCVAL(cli
->outbuf
,smb_com
,SMBlockingX
);
1054 SSVAL(cli
->outbuf
,smb_tid
,cli
->cnum
);
1055 cli_setup_packet(cli
);
1057 SCVAL(cli
->outbuf
,smb_vwv0
,0xFF);
1058 SSVAL(cli
->outbuf
,smb_vwv2
,fnum
);
1059 SCVAL(cli
->outbuf
,smb_vwv3
,LOCKING_ANDX_LARGE_FILES
);
1060 SIVALS(cli
->outbuf
, smb_vwv4
, 0);
1061 SSVAL(cli
->outbuf
,smb_vwv6
,1);
1062 SSVAL(cli
->outbuf
,smb_vwv7
,0);
1064 p
= smb_buf(cli
->outbuf
);
1065 SIVAL(p
, 0, cli
->pid
);
1066 SOFF_T_R(p
, 4, offset
);
1067 SOFF_T_R(p
, 12, len
);
1069 cli_setup_bcc(cli
, p
);
1071 if (!cli_receive_smb(cli
)) {
1075 if (cli_is_error(cli
)) {
1082 /****************************************************************************
1083 Get/unlock a POSIX lock on a file - internal function.
1084 ****************************************************************************/
1086 static BOOL
cli_posix_lock_internal(struct cli_state
*cli
, int fnum
,
1087 SMB_BIG_UINT offset
, SMB_BIG_UINT len
, BOOL wait_lock
, enum brl_type lock_type
)
1089 unsigned int param_len
= 4;
1090 unsigned int data_len
= POSIX_LOCK_DATA_SIZE
;
1091 uint16 setup
= TRANSACT2_SETFILEINFO
;
1093 unsigned char data
[POSIX_LOCK_DATA_SIZE
];
1094 char *rparam
=NULL
, *rdata
=NULL
;
1095 int saved_timeout
= cli
->timeout
;
1097 SSVAL(param
,0,fnum
);
1098 SSVAL(param
,2,SMB_SET_POSIX_LOCK
);
1100 switch (lock_type
) {
1102 SSVAL(data
, POSIX_LOCK_TYPE_OFFSET
, POSIX_LOCK_TYPE_READ
);
1105 SSVAL(data
, POSIX_LOCK_TYPE_OFFSET
, POSIX_LOCK_TYPE_WRITE
);
1108 SSVAL(data
, POSIX_LOCK_TYPE_OFFSET
, POSIX_LOCK_TYPE_UNLOCK
);
1115 SSVAL(data
, POSIX_LOCK_FLAGS_OFFSET
, POSIX_LOCK_FLAG_WAIT
);
1116 cli
->timeout
= 0x7FFFFFFF;
1118 SSVAL(data
, POSIX_LOCK_FLAGS_OFFSET
, POSIX_LOCK_FLAG_NOWAIT
);
1121 SIVAL(data
, POSIX_LOCK_PID_OFFSET
, cli
->pid
);
1122 SOFF_T(data
, POSIX_LOCK_START_OFFSET
, offset
);
1123 SOFF_T(data
, POSIX_LOCK_LEN_OFFSET
, len
);
1125 if (!cli_send_trans(cli
, SMBtrans2
,
1127 -1, 0, /* fid, flags */
1128 &setup
, 1, 0, /* setup, length, max */
1129 param
, param_len
, 2, /* param, length, max */
1130 (char *)&data
, data_len
, cli
->max_xmit
/* data, length, max */
1132 cli
->timeout
= saved_timeout
;
1136 if (!cli_receive_trans(cli
, SMBtrans2
,
1137 &rparam
, ¶m_len
,
1138 &rdata
, &data_len
)) {
1139 cli
->timeout
= saved_timeout
;
1145 cli
->timeout
= saved_timeout
;
1153 /****************************************************************************
1155 ****************************************************************************/
1157 BOOL
cli_posix_lock(struct cli_state
*cli
, int fnum
,
1158 SMB_BIG_UINT offset
, SMB_BIG_UINT len
,
1159 BOOL wait_lock
, enum brl_type lock_type
)
1161 if (lock_type
!= READ_LOCK
&& lock_type
!= WRITE_LOCK
) {
1164 return cli_posix_lock_internal(cli
, fnum
, offset
, len
, wait_lock
, lock_type
);
1167 /****************************************************************************
1168 POSIX Unlock a file.
1169 ****************************************************************************/
1171 BOOL
cli_posix_unlock(struct cli_state
*cli
, int fnum
, SMB_BIG_UINT offset
, SMB_BIG_UINT len
)
1173 return cli_posix_lock_internal(cli
, fnum
, offset
, len
, False
, UNLOCK_LOCK
);
1176 /****************************************************************************
1177 POSIX Get any lock covering a file.
1178 ****************************************************************************/
1180 BOOL
cli_posix_getlock(struct cli_state
*cli
, int fnum
, SMB_BIG_UINT
*poffset
, SMB_BIG_UINT
*plen
)
1185 /****************************************************************************
1186 Do a SMBgetattrE call.
1187 ****************************************************************************/
1189 BOOL
cli_getattrE(struct cli_state
*cli
, int fd
,
1190 uint16
*attr
, SMB_OFF_T
*size
,
1191 time_t *change_time
,
1192 time_t *access_time
,
1195 memset(cli
->outbuf
,'\0',smb_size
);
1196 memset(cli
->inbuf
,'\0',smb_size
);
1198 set_message(cli
->outbuf
,1,0,True
);
1200 SCVAL(cli
->outbuf
,smb_com
,SMBgetattrE
);
1201 SSVAL(cli
->outbuf
,smb_tid
,cli
->cnum
);
1202 cli_setup_packet(cli
);
1204 SSVAL(cli
->outbuf
,smb_vwv0
,fd
);
1207 if (!cli_receive_smb(cli
)) {
1211 if (cli_is_error(cli
)) {
1216 *size
= IVAL(cli
->inbuf
, smb_vwv6
);
1220 *attr
= SVAL(cli
->inbuf
,smb_vwv10
);
1224 *change_time
= cli_make_unix_date2(cli
, cli
->inbuf
+smb_vwv0
);
1228 *access_time
= cli_make_unix_date2(cli
, cli
->inbuf
+smb_vwv2
);
1232 *write_time
= cli_make_unix_date2(cli
, cli
->inbuf
+smb_vwv4
);
1238 /****************************************************************************
1240 ****************************************************************************/
1242 BOOL
cli_getatr(struct cli_state
*cli
, const char *fname
,
1243 uint16
*attr
, SMB_OFF_T
*size
, time_t *write_time
)
1247 memset(cli
->outbuf
,'\0',smb_size
);
1248 memset(cli
->inbuf
,'\0',smb_size
);
1250 set_message(cli
->outbuf
,0,0,True
);
1252 SCVAL(cli
->outbuf
,smb_com
,SMBgetatr
);
1253 SSVAL(cli
->outbuf
,smb_tid
,cli
->cnum
);
1254 cli_setup_packet(cli
);
1256 p
= smb_buf(cli
->outbuf
);
1258 p
+= clistr_push(cli
, p
, fname
, -1, STR_TERMINATE
);
1260 cli_setup_bcc(cli
, p
);
1263 if (!cli_receive_smb(cli
)) {
1267 if (cli_is_error(cli
)) {
1272 *size
= IVAL(cli
->inbuf
, smb_vwv3
);
1276 *write_time
= cli_make_unix_date3(cli
, cli
->inbuf
+smb_vwv1
);
1280 *attr
= SVAL(cli
->inbuf
,smb_vwv0
);
1287 /****************************************************************************
1288 Do a SMBsetattrE call.
1289 ****************************************************************************/
1291 BOOL
cli_setattrE(struct cli_state
*cli
, int fd
,
1299 memset(cli
->outbuf
,'\0',smb_size
);
1300 memset(cli
->inbuf
,'\0',smb_size
);
1302 set_message(cli
->outbuf
,7,0,True
);
1304 SCVAL(cli
->outbuf
,smb_com
,SMBsetattrE
);
1305 SSVAL(cli
->outbuf
,smb_tid
,cli
->cnum
);
1306 cli_setup_packet(cli
);
1308 SSVAL(cli
->outbuf
,smb_vwv0
, fd
);
1309 cli_put_dos_date2(cli
, cli
->outbuf
,smb_vwv1
, change_time
);
1310 cli_put_dos_date2(cli
, cli
->outbuf
,smb_vwv3
, access_time
);
1311 cli_put_dos_date2(cli
, cli
->outbuf
,smb_vwv5
, write_time
);
1313 p
= smb_buf(cli
->outbuf
);
1316 cli_setup_bcc(cli
, p
);
1319 if (!cli_receive_smb(cli
)) {
1323 if (cli_is_error(cli
)) {
1330 /****************************************************************************
1331 Do a SMBsetatr call.
1332 ****************************************************************************/
1334 BOOL
cli_setatr(struct cli_state
*cli
, const char *fname
, uint16 attr
, time_t t
)
1338 memset(cli
->outbuf
,'\0',smb_size
);
1339 memset(cli
->inbuf
,'\0',smb_size
);
1341 set_message(cli
->outbuf
,8,0,True
);
1343 SCVAL(cli
->outbuf
,smb_com
,SMBsetatr
);
1344 SSVAL(cli
->outbuf
,smb_tid
,cli
->cnum
);
1345 cli_setup_packet(cli
);
1347 SSVAL(cli
->outbuf
,smb_vwv0
, attr
);
1348 cli_put_dos_date3(cli
, cli
->outbuf
,smb_vwv1
, t
);
1350 p
= smb_buf(cli
->outbuf
);
1352 p
+= clistr_push(cli
, p
, fname
, -1, STR_TERMINATE
);
1355 cli_setup_bcc(cli
, p
);
1358 if (!cli_receive_smb(cli
)) {
1362 if (cli_is_error(cli
)) {
1369 /****************************************************************************
1370 Check for existance of a dir.
1371 ****************************************************************************/
1372 BOOL
cli_chkpath(struct cli_state
*cli
, const char *path
)
1377 pstrcpy(path2
,path
);
1378 trim_char(path2
,'\0','\\');
1382 memset(cli
->outbuf
,'\0',smb_size
);
1383 set_message(cli
->outbuf
,0,0,True
);
1384 SCVAL(cli
->outbuf
,smb_com
,SMBcheckpath
);
1385 SSVAL(cli
->outbuf
,smb_tid
,cli
->cnum
);
1386 cli_setup_packet(cli
);
1387 p
= smb_buf(cli
->outbuf
);
1389 p
+= clistr_push(cli
, p
, path2
, -1, STR_TERMINATE
);
1391 cli_setup_bcc(cli
, p
);
1394 if (!cli_receive_smb(cli
)) {
1398 if (cli_is_error(cli
)) return False
;
1403 /****************************************************************************
1405 ****************************************************************************/
1407 BOOL
cli_dskattr(struct cli_state
*cli
, int *bsize
, int *total
, int *avail
)
1409 memset(cli
->outbuf
,'\0',smb_size
);
1410 set_message(cli
->outbuf
,0,0,True
);
1411 SCVAL(cli
->outbuf
,smb_com
,SMBdskattr
);
1412 SSVAL(cli
->outbuf
,smb_tid
,cli
->cnum
);
1413 cli_setup_packet(cli
);
1416 if (!cli_receive_smb(cli
)) {
1420 *bsize
= SVAL(cli
->inbuf
,smb_vwv1
)*SVAL(cli
->inbuf
,smb_vwv2
);
1421 *total
= SVAL(cli
->inbuf
,smb_vwv0
);
1422 *avail
= SVAL(cli
->inbuf
,smb_vwv3
);
1427 /****************************************************************************
1428 Create and open a temporary file.
1429 ****************************************************************************/
1431 int cli_ctemp(struct cli_state
*cli
, const char *path
, char **tmp_path
)
1436 memset(cli
->outbuf
,'\0',smb_size
);
1437 memset(cli
->inbuf
,'\0',smb_size
);
1439 set_message(cli
->outbuf
,3,0,True
);
1441 SCVAL(cli
->outbuf
,smb_com
,SMBctemp
);
1442 SSVAL(cli
->outbuf
,smb_tid
,cli
->cnum
);
1443 cli_setup_packet(cli
);
1445 SSVAL(cli
->outbuf
,smb_vwv0
,0);
1446 SIVALS(cli
->outbuf
,smb_vwv1
,-1);
1448 p
= smb_buf(cli
->outbuf
);
1450 p
+= clistr_push(cli
, p
, path
, -1, STR_TERMINATE
);
1452 cli_setup_bcc(cli
, p
);
1455 if (!cli_receive_smb(cli
)) {
1459 if (cli_is_error(cli
)) {
1463 /* despite the spec, the result has a -1, followed by
1464 length, followed by name */
1465 p
= smb_buf(cli
->inbuf
);
1467 len
= smb_buflen(cli
->inbuf
) - 4;
1468 if (len
<= 0) return -1;
1472 clistr_pull(cli
, path2
, p
,
1473 sizeof(path2
), len
, STR_ASCII
);
1474 *tmp_path
= SMB_STRDUP(path2
);
1477 return SVAL(cli
->inbuf
,smb_vwv0
);
1482 send a raw ioctl - used by the torture code
1484 NTSTATUS
cli_raw_ioctl(struct cli_state
*cli
, int fnum
, uint32 code
, DATA_BLOB
*blob
)
1486 memset(cli
->outbuf
,'\0',smb_size
);
1487 memset(cli
->inbuf
,'\0',smb_size
);
1489 set_message(cli
->outbuf
, 3, 0, True
);
1490 SCVAL(cli
->outbuf
,smb_com
,SMBioctl
);
1491 cli_setup_packet(cli
);
1493 SSVAL(cli
->outbuf
, smb_vwv0
, fnum
);
1494 SSVAL(cli
->outbuf
, smb_vwv1
, code
>>16);
1495 SSVAL(cli
->outbuf
, smb_vwv2
, (code
&0xFFFF));
1498 if (!cli_receive_smb(cli
)) {
1499 return NT_STATUS_UNEXPECTED_NETWORK_ERROR
;
1502 if (cli_is_error(cli
)) {
1503 return cli_nt_error(cli
);
1506 *blob
= data_blob(NULL
, 0);
1508 return NT_STATUS_OK
;
1511 /*********************************************************
1512 Set an extended attribute utility fn.
1513 *********************************************************/
1515 static BOOL
cli_set_ea(struct cli_state
*cli
, uint16 setup
, char *param
, unsigned int param_len
,
1516 const char *ea_name
, const char *ea_val
, size_t ea_len
)
1518 unsigned int data_len
= 0;
1520 char *rparam
=NULL
, *rdata
=NULL
;
1522 size_t ea_namelen
= strlen(ea_name
);
1524 if (ea_namelen
== 0 && ea_len
== 0) {
1526 data
= (char *)SMB_MALLOC(data_len
);
1531 SIVAL(p
,0,data_len
);
1533 data_len
= 4 + 4 + ea_namelen
+ 1 + ea_len
;
1534 data
= (char *)SMB_MALLOC(data_len
);
1539 SIVAL(p
,0,data_len
);
1541 SCVAL(p
, 0, 0); /* EA flags. */
1542 SCVAL(p
, 1, ea_namelen
);
1543 SSVAL(p
, 2, ea_len
);
1544 memcpy(p
+4, ea_name
, ea_namelen
+1); /* Copy in the name. */
1545 memcpy(p
+4+ea_namelen
+1, ea_val
, ea_len
);
1548 if (!cli_send_trans(cli
, SMBtrans2
,
1550 -1, 0, /* fid, flags */
1551 &setup
, 1, 0, /* setup, length, max */
1552 param
, param_len
, 2, /* param, length, max */
1553 data
, data_len
, cli
->max_xmit
/* data, length, max */
1558 if (!cli_receive_trans(cli
, SMBtrans2
,
1559 &rparam
, ¶m_len
,
1560 &rdata
, &data_len
)) {
1571 /*********************************************************
1572 Set an extended attribute on a pathname.
1573 *********************************************************/
1575 BOOL
cli_set_ea_path(struct cli_state
*cli
, const char *path
, const char *ea_name
, const char *ea_val
, size_t ea_len
)
1577 uint16 setup
= TRANSACT2_SETPATHINFO
;
1578 unsigned int param_len
= 0;
1579 char param
[sizeof(pstring
)+6];
1580 size_t srclen
= 2*(strlen(path
)+1);
1583 memset(param
, 0, sizeof(param
));
1584 SSVAL(param
,0,SMB_INFO_SET_EA
);
1587 p
+= clistr_push(cli
, p
, path
, MIN(srclen
, sizeof(param
)-6), STR_TERMINATE
);
1588 param_len
= PTR_DIFF(p
, param
);
1590 return cli_set_ea(cli
, setup
, param
, param_len
, ea_name
, ea_val
, ea_len
);
1593 /*********************************************************
1594 Set an extended attribute on an fnum.
1595 *********************************************************/
1597 BOOL
cli_set_ea_fnum(struct cli_state
*cli
, int fnum
, const char *ea_name
, const char *ea_val
, size_t ea_len
)
1600 uint16 setup
= TRANSACT2_SETFILEINFO
;
1602 memset(param
, 0, 6);
1603 SSVAL(param
,0,fnum
);
1604 SSVAL(param
,2,SMB_INFO_SET_EA
);
1606 return cli_set_ea(cli
, setup
, param
, 6, ea_name
, ea_val
, ea_len
);
1609 /*********************************************************
1610 Get an extended attribute list tility fn.
1611 *********************************************************/
1613 static BOOL
cli_get_ea_list(struct cli_state
*cli
,
1614 uint16 setup
, char *param
, unsigned int param_len
,
1617 struct ea_struct
**pea_list
)
1619 unsigned int data_len
= 0;
1620 unsigned int rparam_len
, rdata_len
;
1621 char *rparam
=NULL
, *rdata
=NULL
;
1626 struct ea_struct
*ea_list
;
1633 if (!cli_send_trans(cli
, SMBtrans2
,
1635 -1, 0, /* fid, flags */
1636 &setup
, 1, 0, /* setup, length, max */
1637 param
, param_len
, 10, /* param, length, max */
1638 NULL
, data_len
, cli
->max_xmit
/* data, length, max */
1643 if (!cli_receive_trans(cli
, SMBtrans2
,
1644 &rparam
, &rparam_len
,
1645 &rdata
, &rdata_len
)) {
1649 if (!rdata
|| rdata_len
< 4) {
1653 ea_size
= (size_t)IVAL(rdata
,0);
1654 if (ea_size
> rdata_len
) {
1659 /* No EA's present. */
1667 /* Validate the EA list and count it. */
1668 for (num_eas
= 0; ea_size
>= 4; num_eas
++) {
1669 unsigned int ea_namelen
= CVAL(p
,1);
1670 unsigned int ea_valuelen
= SVAL(p
,2);
1671 if (ea_namelen
== 0) {
1674 if (4 + ea_namelen
+ 1 + ea_valuelen
> ea_size
) {
1677 ea_size
-= 4 + ea_namelen
+ 1 + ea_valuelen
;
1678 p
+= 4 + ea_namelen
+ 1 + ea_valuelen
;
1686 *pnum_eas
= num_eas
;
1688 /* Caller only wants number of EA's. */
1693 ea_list
= TALLOC_ARRAY(ctx
, struct ea_struct
, num_eas
);
1698 ea_size
= (size_t)IVAL(rdata
,0);
1701 for (num_eas
= 0; num_eas
< *pnum_eas
; num_eas
++ ) {
1702 struct ea_struct
*ea
= &ea_list
[num_eas
];
1703 fstring unix_ea_name
;
1704 unsigned int ea_namelen
= CVAL(p
,1);
1705 unsigned int ea_valuelen
= SVAL(p
,2);
1707 ea
->flags
= CVAL(p
,0);
1708 unix_ea_name
[0] = '\0';
1709 pull_ascii_fstring(unix_ea_name
, p
+ 4);
1710 ea
->name
= talloc_strdup(ctx
, unix_ea_name
);
1711 /* Ensure the value is null terminated (in case it's a string). */
1712 ea
->value
= data_blob_talloc(ctx
, NULL
, ea_valuelen
+ 1);
1713 if (!ea
->value
.data
) {
1717 memcpy(ea
->value
.data
, p
+4+ea_namelen
+1, ea_valuelen
);
1719 ea
->value
.data
[ea_valuelen
] = 0;
1721 p
+= 4 + ea_namelen
+ 1 + ea_valuelen
;
1724 *pea_list
= ea_list
;
1734 /*********************************************************
1735 Get an extended attribute list from a pathname.
1736 *********************************************************/
1738 BOOL
cli_get_ea_list_path(struct cli_state
*cli
, const char *path
,
1741 struct ea_struct
**pea_list
)
1743 uint16 setup
= TRANSACT2_QPATHINFO
;
1744 unsigned int param_len
= 0;
1745 char param
[sizeof(pstring
)+6];
1750 SSVAL(p
, 0, SMB_INFO_QUERY_ALL_EAS
);
1752 p
+= clistr_push(cli
, p
, path
, sizeof(pstring
)-6, STR_TERMINATE
);
1753 param_len
= PTR_DIFF(p
, param
);
1755 return cli_get_ea_list(cli
, setup
, param
, param_len
, ctx
, pnum_eas
, pea_list
);
1758 /*********************************************************
1759 Get an extended attribute list from an fnum.
1760 *********************************************************/
1762 BOOL
cli_get_ea_list_fnum(struct cli_state
*cli
, int fnum
,
1765 struct ea_struct
**pea_list
)
1767 uint16 setup
= TRANSACT2_QFILEINFO
;
1770 memset(param
, 0, 6);
1771 SSVAL(param
,0,fnum
);
1772 SSVAL(param
,2,SMB_INFO_SET_EA
);
1774 return cli_get_ea_list(cli
, setup
, param
, 6, ctx
, pnum_eas
, pea_list
);