2 Unix SMB/CIFS implementation.
5 Copyright (C) Simo Sorce 2002
6 Copyright (C) Eric Lorimer 2002
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 "smbd/smbd.h"
24 #include "system/passwd.h"
25 #include "system/filesys.h"
27 #include "../lib/util/util_pw.h"
28 #include "libcli/security/security.h"
29 #include "passdb/machine_sid.h"
31 static const char *null_string
= "";
33 static NTSTATUS
cmd_load_module(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
38 printf("Usage: load <modules>\n");
42 for (i
=argc
-1;i
>0;i
--) {
43 if (!vfs_init_custom(vfs
->conn
, argv
[i
])) {
44 DEBUG(0, ("load: (vfs_init_custom failed for %s)\n", argv
[i
]));
45 return NT_STATUS_UNSUCCESSFUL
;
52 static NTSTATUS
cmd_populate(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
57 printf("Usage: populate <char> <size>\n");
62 vfs
->data
= talloc_array(mem_ctx
, char, size
);
63 if (vfs
->data
== NULL
) {
64 printf("populate: error=-1 (not enough memory)");
65 return NT_STATUS_UNSUCCESSFUL
;
67 memset(vfs
->data
, c
, size
);
68 vfs
->data_size
= size
;
72 static NTSTATUS
cmd_show_data(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
76 if (argc
!= 1 && argc
!= 3) {
77 printf("Usage: showdata [<offset> <len>]\n");
80 if (vfs
->data
== NULL
|| vfs
->data_size
== 0) {
81 printf("show_data: error=-1 (buffer empty)\n");
82 return NT_STATUS_UNSUCCESSFUL
;
86 offset
= atoi(argv
[1]);
92 if ((offset
+ len
) > vfs
->data_size
) {
93 printf("show_data: error=-1 (not enough data in buffer)\n");
94 return NT_STATUS_UNSUCCESSFUL
;
96 dump_data(0, (uint8
*)(vfs
->data
) + offset
, len
);
100 static NTSTATUS
cmd_connect(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
102 SMB_VFS_CONNECT(vfs
->conn
, lp_servicename(talloc_tos(), SNUM(vfs
->conn
)), "vfstest");
106 static NTSTATUS
cmd_disconnect(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
108 SMB_VFS_DISCONNECT(vfs
->conn
);
112 static NTSTATUS
cmd_disk_free(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
114 uint64_t diskfree
, bsize
, dfree
, dsize
;
116 printf("Usage: disk_free <path>\n");
120 diskfree
= SMB_VFS_DISK_FREE(vfs
->conn
, argv
[1], False
, &bsize
, &dfree
, &dsize
);
121 printf("disk_free: %lu, bsize = %lu, dfree = %lu, dsize = %lu\n",
122 (unsigned long)diskfree
,
123 (unsigned long)bsize
,
124 (unsigned long)dfree
,
125 (unsigned long)dsize
);
130 static NTSTATUS
cmd_opendir(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
133 printf("Usage: opendir <fname>\n");
137 vfs
->currentdir
= SMB_VFS_OPENDIR(vfs
->conn
, argv
[1], NULL
, 0);
138 if (vfs
->currentdir
== NULL
) {
139 printf("opendir error=%d (%s)\n", errno
, strerror(errno
));
140 return NT_STATUS_UNSUCCESSFUL
;
143 printf("opendir: ok\n");
148 static NTSTATUS
cmd_readdir(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
151 struct dirent
*dent
= NULL
;
153 if (vfs
->currentdir
== NULL
) {
154 printf("readdir: error=-1 (no open directory)\n");
155 return NT_STATUS_UNSUCCESSFUL
;
158 dent
= SMB_VFS_READDIR(vfs
->conn
, vfs
->currentdir
, &st
);
160 printf("readdir: NULL\n");
164 printf("readdir: %s\n", dent
->d_name
);
165 if (VALID_STAT(st
)) {
167 printf(" stat available");
168 if (S_ISREG(st
.st_ex_mode
)) printf(" Regular File\n");
169 else if (S_ISDIR(st
.st_ex_mode
)) printf(" Directory\n");
170 else if (S_ISCHR(st
.st_ex_mode
)) printf(" Character Device\n");
171 else if (S_ISBLK(st
.st_ex_mode
)) printf(" Block Device\n");
172 else if (S_ISFIFO(st
.st_ex_mode
)) printf(" Fifo\n");
173 else if (S_ISLNK(st
.st_ex_mode
)) printf(" Symbolic Link\n");
174 else if (S_ISSOCK(st
.st_ex_mode
)) printf(" Socket\n");
175 printf(" Size: %10u", (unsigned int)st
.st_ex_size
);
176 #ifdef HAVE_STAT_ST_BLOCKS
177 printf(" Blocks: %9u", (unsigned int)st
.st_ex_blocks
);
179 #ifdef HAVE_STAT_ST_BLKSIZE
180 printf(" IO Block: %u\n", (unsigned int)st
.st_ex_blksize
);
182 printf(" Device: 0x%10x", (unsigned int)st
.st_ex_dev
);
183 printf(" Inode: %10u", (unsigned int)st
.st_ex_ino
);
184 printf(" Links: %10u\n", (unsigned int)st
.st_ex_nlink
);
185 printf(" Access: %05o", (int)((st
.st_ex_mode
) & 007777));
186 printf(" Uid: %5lu Gid: %5lu\n",
187 (unsigned long)st
.st_ex_uid
,
188 (unsigned long)st
.st_ex_gid
);
189 tmp_time
= convert_timespec_to_time_t(st
.st_ex_atime
);
190 printf(" Access: %s", ctime(&tmp_time
));
191 tmp_time
= convert_timespec_to_time_t(st
.st_ex_mtime
);
192 printf(" Modify: %s", ctime(&tmp_time
));
193 tmp_time
= convert_timespec_to_time_t(st
.st_ex_ctime
);
194 printf(" Change: %s", ctime(&tmp_time
));
201 static NTSTATUS
cmd_mkdir(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
204 printf("Usage: mkdir <path>\n");
208 if (SMB_VFS_MKDIR(vfs
->conn
, argv
[1], 00755) == -1) {
209 printf("mkdir error=%d (%s)\n", errno
, strerror(errno
));
210 return NT_STATUS_UNSUCCESSFUL
;
213 printf("mkdir: ok\n");
218 static NTSTATUS
cmd_closedir(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
222 if (vfs
->currentdir
== NULL
) {
223 printf("closedir: failure (no directory open)\n");
224 return NT_STATUS_UNSUCCESSFUL
;
227 ret
= SMB_VFS_CLOSEDIR(vfs
->conn
, vfs
->currentdir
);
229 printf("closedir failure: %s\n", strerror(errno
));
230 return NT_STATUS_UNSUCCESSFUL
;
233 printf("closedir: ok\n");
234 vfs
->currentdir
= NULL
;
239 static NTSTATUS
cmd_open(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
245 struct smb_filename
*smb_fname
= NULL
;
251 if (argc
< 3 || argc
> 5) {
252 printf("Usage: open <filename> <flags> <mode>\n");
253 printf(" flags: O = O_RDONLY\n");
254 printf(" R = O_RDWR\n");
255 printf(" W = O_WRONLY\n");
256 printf(" C = O_CREAT\n");
257 printf(" E = O_EXCL\n");
258 printf(" T = O_TRUNC\n");
259 printf(" A = O_APPEND\n");
260 printf(" N = O_NONBLOCK/O_NDELAY\n");
262 printf(" S = O_SYNC\n");
265 printf(" F = O_NOFOLLOW\n");
267 printf(" mode: see open.2\n");
268 printf(" mode is ignored if C flag not present\n");
269 printf(" mode defaults to 00400\n");
311 printf("open: error=-1 (invalid flag!)\n");
312 return NT_STATUS_UNSUCCESSFUL
;
316 if ((flags
& O_CREAT
) && argc
== 4) {
317 if (sscanf(argv
[3], "%ho", (unsigned short *)&mode
) == 0) {
318 printf("open: error=-1 (invalid mode!)\n");
319 return NT_STATUS_UNSUCCESSFUL
;
323 fsp
= talloc_zero(vfs
, struct files_struct
);
325 return NT_STATUS_NO_MEMORY
;
327 fsp
->fh
= talloc_zero(fsp
, struct fd_handle
);
328 if (fsp
->fh
== NULL
) {
330 return NT_STATUS_NO_MEMORY
;
332 fsp
->conn
= vfs
->conn
;
334 smb_fname
= synthetic_smb_fname_split(NULL
, argv
[1], NULL
);
335 if (smb_fname
== NULL
) {
337 return NT_STATUS_NO_MEMORY
;
340 fsp
->fsp_name
= smb_fname
;
342 fsp
->fh
->fd
= SMB_VFS_OPEN(vfs
->conn
, smb_fname
, fsp
, flags
, mode
);
343 if (fsp
->fh
->fd
== -1) {
344 printf("open: error=%d (%s)\n", errno
, strerror(errno
));
346 TALLOC_FREE(smb_fname
);
347 return NT_STATUS_UNSUCCESSFUL
;
350 ret
= SMB_VFS_FSTAT(fsp
, &smb_fname
->st
);
352 /* If we have an fd, this stat should succeed. */
353 DEBUG(0,("Error doing fstat on open file %s "
355 smb_fname_str_dbg(smb_fname
),
357 status
= map_nt_error_from_unix(errno
);
358 } else if (S_ISDIR(smb_fname
->st
.st_ex_mode
)) {
360 status
= NT_STATUS_FILE_IS_A_DIRECTORY
;
363 if (!NT_STATUS_IS_OK(status
)) {
366 TALLOC_FREE(smb_fname
);
370 fsp
->file_id
= vfs_file_id_from_sbuf(vfs
->conn
, &smb_fname
->st
);
371 fsp
->vuid
= UID_FIELD_INVALID
;
373 fsp
->can_lock
= True
;
374 fsp
->can_read
= True
;
376 CAN_WRITE(vfs
->conn
);
377 fsp
->print_file
= NULL
;
378 fsp
->modified
= False
;
379 fsp
->sent_oplock_break
= NO_BREAK_SENT
;
380 fsp
->is_directory
= False
;
382 vfs
->files
[fsp
->fh
->fd
] = fsp
;
383 printf("open: fd=%d\n", fsp
->fh
->fd
);
388 static NTSTATUS
cmd_pathfunc(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
393 printf("Usage: %s <path>\n", argv
[0]);
397 if (strcmp("rmdir", argv
[0]) == 0 ) {
398 ret
= SMB_VFS_RMDIR(vfs
->conn
, argv
[1]);
399 } else if (strcmp("unlink", argv
[0]) == 0 ) {
400 struct smb_filename
*smb_fname
;
402 smb_fname
= synthetic_smb_fname_split(mem_ctx
, argv
[1], NULL
);
403 if (smb_fname
== NULL
) {
404 return NT_STATUS_NO_MEMORY
;
407 ret
= SMB_VFS_UNLINK(vfs
->conn
, smb_fname
);
408 TALLOC_FREE(smb_fname
);
409 } else if (strcmp("chdir", argv
[0]) == 0 ) {
410 ret
= SMB_VFS_CHDIR(vfs
->conn
, argv
[1]);
412 printf("%s: error=%d (invalid function name!)\n", argv
[0], errno
);
413 return NT_STATUS_UNSUCCESSFUL
;
417 printf("%s: error=%d (%s)\n", argv
[0], errno
, strerror(errno
));
418 return NT_STATUS_UNSUCCESSFUL
;
421 printf("%s: ok\n", argv
[0]);
426 static NTSTATUS
cmd_close(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
431 printf("Usage: close <fd>\n");
436 if (vfs
->files
[fd
] == NULL
) {
437 printf("close: error=-1 (invalid file descriptor)\n");
441 ret
= SMB_VFS_CLOSE(vfs
->files
[fd
]);
443 printf("close: error=%d (%s)\n", errno
, strerror(errno
));
445 printf("close: ok\n");
447 TALLOC_FREE(vfs
->files
[fd
]);
448 vfs
->files
[fd
] = NULL
;
453 static NTSTATUS
cmd_read(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
459 printf("Usage: read <fd> <size>\n");
463 /* do some error checking on these */
465 size
= atoi(argv
[2]);
466 vfs
->data
= talloc_array(mem_ctx
, char, size
);
467 if (vfs
->data
== NULL
) {
468 printf("read: error=-1 (not enough memory)");
469 return NT_STATUS_UNSUCCESSFUL
;
471 vfs
->data_size
= size
;
473 rsize
= SMB_VFS_READ(vfs
->files
[fd
], vfs
->data
, size
);
475 printf("read: error=%d (%s)\n", errno
, strerror(errno
));
476 return NT_STATUS_UNSUCCESSFUL
;
479 printf("read: ok\n");
484 static NTSTATUS
cmd_write(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
489 printf("Usage: write <fd> <size>\n");
493 /* some error checking should go here */
495 size
= atoi(argv
[2]);
496 if (vfs
->data
== NULL
) {
497 printf("write: error=-1 (buffer empty, please populate it before writing)");
498 return NT_STATUS_UNSUCCESSFUL
;
501 if (vfs
->data_size
< size
) {
502 printf("write: error=-1 (buffer too small, please put some more data in)");
503 return NT_STATUS_UNSUCCESSFUL
;
506 wsize
= SMB_VFS_WRITE(vfs
->files
[fd
], vfs
->data
, size
);
509 printf("write: error=%d (%s)\n", errno
, strerror(errno
));
510 return NT_STATUS_UNSUCCESSFUL
;
513 printf("write: ok\n");
518 static NTSTATUS
cmd_lseek(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
520 int fd
, offset
, whence
;
524 printf("Usage: lseek <fd> <offset> <whence>\n...where whence is 1 => SEEK_SET, 2 => SEEK_CUR, 3 => SEEK_END\n");
529 offset
= atoi(argv
[2]);
530 whence
= atoi(argv
[3]);
532 case 1: whence
= SEEK_SET
; break;
533 case 2: whence
= SEEK_CUR
; break;
534 default: whence
= SEEK_END
;
537 pos
= SMB_VFS_LSEEK(vfs
->files
[fd
], offset
, whence
);
538 if (pos
== (off_t
)-1) {
539 printf("lseek: error=%d (%s)\n", errno
, strerror(errno
));
540 return NT_STATUS_UNSUCCESSFUL
;
543 printf("lseek: ok\n");
548 static NTSTATUS
cmd_rename(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
551 struct smb_filename
*smb_fname_src
= NULL
;
552 struct smb_filename
*smb_fname_dst
= NULL
;
555 printf("Usage: rename <old> <new>\n");
559 smb_fname_src
= synthetic_smb_fname_split(mem_ctx
, argv
[1], NULL
);
560 if (smb_fname_src
== NULL
) {
561 return NT_STATUS_NO_MEMORY
;
564 smb_fname_dst
= synthetic_smb_fname_split(mem_ctx
, argv
[2], NULL
);
565 if (smb_fname_dst
== NULL
) {
566 TALLOC_FREE(smb_fname_src
);
567 return NT_STATUS_NO_MEMORY
;
570 ret
= SMB_VFS_RENAME(vfs
->conn
, smb_fname_src
, smb_fname_dst
);
571 TALLOC_FREE(smb_fname_src
);
572 TALLOC_FREE(smb_fname_dst
);
574 printf("rename: error=%d (%s)\n", errno
, strerror(errno
));
575 return NT_STATUS_UNSUCCESSFUL
;
578 printf("rename: ok\n");
583 static NTSTATUS
cmd_fsync(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
587 printf("Usage: fsync <fd>\n");
592 ret
= SMB_VFS_FSYNC(vfs
->files
[fd
]);
594 printf("fsync: error=%d (%s)\n", errno
, strerror(errno
));
595 return NT_STATUS_UNSUCCESSFUL
;
598 printf("fsync: ok\n");
603 static NTSTATUS
cmd_stat(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
608 struct passwd
*pwd
= NULL
;
609 struct group
*grp
= NULL
;
610 struct smb_filename
*smb_fname
= NULL
;
615 printf("Usage: stat <fname>\n");
619 smb_fname
= synthetic_smb_fname_split(mem_ctx
, argv
[1], NULL
);
620 if (smb_fname
== NULL
) {
621 return NT_STATUS_NO_MEMORY
;
624 ret
= SMB_VFS_STAT(vfs
->conn
, smb_fname
);
626 printf("stat: error=%d (%s)\n", errno
, strerror(errno
));
627 TALLOC_FREE(smb_fname
);
628 return NT_STATUS_UNSUCCESSFUL
;
631 TALLOC_FREE(smb_fname
);
633 pwd
= getpwuid(st
.st_ex_uid
);
634 if (pwd
!= NULL
) user
= pwd
->pw_name
;
635 else user
= null_string
;
636 grp
= getgrgid(st
.st_ex_gid
);
637 if (grp
!= NULL
) group
= grp
->gr_name
;
638 else group
= null_string
;
640 printf("stat: ok\n");
641 printf(" File: %s", argv
[1]);
642 if (S_ISREG(st
.st_ex_mode
)) printf(" Regular File\n");
643 else if (S_ISDIR(st
.st_ex_mode
)) printf(" Directory\n");
644 else if (S_ISCHR(st
.st_ex_mode
)) printf(" Character Device\n");
645 else if (S_ISBLK(st
.st_ex_mode
)) printf(" Block Device\n");
646 else if (S_ISFIFO(st
.st_ex_mode
)) printf(" Fifo\n");
647 else if (S_ISLNK(st
.st_ex_mode
)) printf(" Symbolic Link\n");
648 else if (S_ISSOCK(st
.st_ex_mode
)) printf(" Socket\n");
649 printf(" Size: %10u", (unsigned int)st
.st_ex_size
);
650 #ifdef HAVE_STAT_ST_BLOCKS
651 printf(" Blocks: %9u", (unsigned int)st
.st_ex_blocks
);
653 #ifdef HAVE_STAT_ST_BLKSIZE
654 printf(" IO Block: %u\n", (unsigned int)st
.st_ex_blksize
);
656 printf(" Device: 0x%10x", (unsigned int)st
.st_ex_dev
);
657 printf(" Inode: %10u", (unsigned int)st
.st_ex_ino
);
658 printf(" Links: %10u\n", (unsigned int)st
.st_ex_nlink
);
659 printf(" Access: %05o", (int)((st
.st_ex_mode
) & 007777));
660 printf(" Uid: %5lu/%.16s Gid: %5lu/%.16s\n", (unsigned long)st
.st_ex_uid
, user
,
661 (unsigned long)st
.st_ex_gid
, group
);
662 tmp_time
= convert_timespec_to_time_t(st
.st_ex_atime
);
663 printf(" Access: %s", ctime(&tmp_time
));
664 tmp_time
= convert_timespec_to_time_t(st
.st_ex_mtime
);
665 printf(" Modify: %s", ctime(&tmp_time
));
666 tmp_time
= convert_timespec_to_time_t(st
.st_ex_ctime
);
667 printf(" Change: %s", ctime(&tmp_time
));
673 static NTSTATUS
cmd_fstat(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
678 struct passwd
*pwd
= NULL
;
679 struct group
*grp
= NULL
;
684 printf("Usage: fstat <fd>\n");
689 if (fd
< 0 || fd
>= 1024) {
690 printf("fstat: error=%d (file descriptor out of range)\n", EBADF
);
694 if (vfs
->files
[fd
] == NULL
) {
695 printf("fstat: error=%d (invalid file descriptor)\n", EBADF
);
699 if (SMB_VFS_FSTAT(vfs
->files
[fd
], &st
) == -1) {
700 printf("fstat: error=%d (%s)\n", errno
, strerror(errno
));
701 return NT_STATUS_UNSUCCESSFUL
;
704 pwd
= getpwuid(st
.st_ex_uid
);
705 if (pwd
!= NULL
) user
= pwd
->pw_name
;
706 else user
= null_string
;
707 grp
= getgrgid(st
.st_ex_gid
);
708 if (grp
!= NULL
) group
= grp
->gr_name
;
709 else group
= null_string
;
711 printf("fstat: ok\n");
712 if (S_ISREG(st
.st_ex_mode
)) printf(" Regular File\n");
713 else if (S_ISDIR(st
.st_ex_mode
)) printf(" Directory\n");
714 else if (S_ISCHR(st
.st_ex_mode
)) printf(" Character Device\n");
715 else if (S_ISBLK(st
.st_ex_mode
)) printf(" Block Device\n");
716 else if (S_ISFIFO(st
.st_ex_mode
)) printf(" Fifo\n");
717 else if (S_ISLNK(st
.st_ex_mode
)) printf(" Symbolic Link\n");
718 else if (S_ISSOCK(st
.st_ex_mode
)) printf(" Socket\n");
719 printf(" Size: %10u", (unsigned int)st
.st_ex_size
);
720 #ifdef HAVE_STAT_ST_BLOCKS
721 printf(" Blocks: %9u", (unsigned int)st
.st_ex_blocks
);
723 #ifdef HAVE_STAT_ST_BLKSIZE
724 printf(" IO Block: %u\n", (unsigned int)st
.st_ex_blksize
);
726 printf(" Device: 0x%10x", (unsigned int)st
.st_ex_dev
);
727 printf(" Inode: %10u", (unsigned int)st
.st_ex_ino
);
728 printf(" Links: %10u\n", (unsigned int)st
.st_ex_nlink
);
729 printf(" Access: %05o", (int)((st
.st_ex_mode
) & 007777));
730 printf(" Uid: %5lu/%.16s Gid: %5lu/%.16s\n", (unsigned long)st
.st_ex_uid
, user
,
731 (unsigned long)st
.st_ex_gid
, group
);
732 tmp_time
= convert_timespec_to_time_t(st
.st_ex_atime
);
733 printf(" Access: %s", ctime(&tmp_time
));
734 tmp_time
= convert_timespec_to_time_t(st
.st_ex_mtime
);
735 printf(" Modify: %s", ctime(&tmp_time
));
736 tmp_time
= convert_timespec_to_time_t(st
.st_ex_ctime
);
737 printf(" Change: %s", ctime(&tmp_time
));
743 static NTSTATUS
cmd_lstat(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
747 struct passwd
*pwd
= NULL
;
748 struct group
*grp
= NULL
;
749 struct smb_filename
*smb_fname
= NULL
;
754 printf("Usage: lstat <path>\n");
758 smb_fname
= synthetic_smb_fname_split(mem_ctx
, argv
[1], NULL
);
759 if (smb_fname
== NULL
) {
760 return NT_STATUS_NO_MEMORY
;
763 if (SMB_VFS_LSTAT(vfs
->conn
, smb_fname
) == -1) {
764 printf("lstat: error=%d (%s)\n", errno
, strerror(errno
));
765 TALLOC_FREE(smb_fname
);
766 return NT_STATUS_UNSUCCESSFUL
;
769 TALLOC_FREE(smb_fname
);
771 pwd
= getpwuid(st
.st_ex_uid
);
772 if (pwd
!= NULL
) user
= pwd
->pw_name
;
773 else user
= null_string
;
774 grp
= getgrgid(st
.st_ex_gid
);
775 if (grp
!= NULL
) group
= grp
->gr_name
;
776 else group
= null_string
;
778 printf("lstat: ok\n");
779 if (S_ISREG(st
.st_ex_mode
)) printf(" Regular File\n");
780 else if (S_ISDIR(st
.st_ex_mode
)) printf(" Directory\n");
781 else if (S_ISCHR(st
.st_ex_mode
)) printf(" Character Device\n");
782 else if (S_ISBLK(st
.st_ex_mode
)) printf(" Block Device\n");
783 else if (S_ISFIFO(st
.st_ex_mode
)) printf(" Fifo\n");
784 else if (S_ISLNK(st
.st_ex_mode
)) printf(" Symbolic Link\n");
785 else if (S_ISSOCK(st
.st_ex_mode
)) printf(" Socket\n");
786 printf(" Size: %10u", (unsigned int)st
.st_ex_size
);
787 #ifdef HAVE_STAT_ST_BLOCKS
788 printf(" Blocks: %9u", (unsigned int)st
.st_ex_blocks
);
790 #ifdef HAVE_STAT_ST_BLKSIZE
791 printf(" IO Block: %u\n", (unsigned int)st
.st_ex_blksize
);
793 printf(" Device: 0x%10x", (unsigned int)st
.st_ex_dev
);
794 printf(" Inode: %10u", (unsigned int)st
.st_ex_ino
);
795 printf(" Links: %10u\n", (unsigned int)st
.st_ex_nlink
);
796 printf(" Access: %05o", (int)((st
.st_ex_mode
) & 007777));
797 printf(" Uid: %5lu/%.16s Gid: %5lu/%.16s\n", (unsigned long)st
.st_ex_uid
, user
,
798 (unsigned long)st
.st_ex_gid
, group
);
799 tmp_time
= convert_timespec_to_time_t(st
.st_ex_atime
);
800 printf(" Access: %s", ctime(&tmp_time
));
801 tmp_time
= convert_timespec_to_time_t(st
.st_ex_mtime
);
802 printf(" Modify: %s", ctime(&tmp_time
));
803 tmp_time
= convert_timespec_to_time_t(st
.st_ex_ctime
);
804 printf(" Change: %s", ctime(&tmp_time
));
810 static NTSTATUS
cmd_chmod(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
814 printf("Usage: chmod <path> <mode>\n");
818 mode
= atoi(argv
[2]);
819 if (SMB_VFS_CHMOD(vfs
->conn
, argv
[1], mode
) == -1) {
820 printf("chmod: error=%d (%s)\n", errno
, strerror(errno
));
821 return NT_STATUS_UNSUCCESSFUL
;
824 printf("chmod: ok\n");
829 static NTSTATUS
cmd_fchmod(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
834 printf("Usage: fchmod <fd> <mode>\n");
839 mode
= atoi(argv
[2]);
840 if (fd
< 0 || fd
>= 1024) {
841 printf("fchmod: error=%d (file descriptor out of range)\n", EBADF
);
844 if (vfs
->files
[fd
] == NULL
) {
845 printf("fchmod: error=%d (invalid file descriptor)\n", EBADF
);
849 if (SMB_VFS_FCHMOD(vfs
->files
[fd
], mode
) == -1) {
850 printf("fchmod: error=%d (%s)\n", errno
, strerror(errno
));
851 return NT_STATUS_UNSUCCESSFUL
;
854 printf("fchmod: ok\n");
859 static NTSTATUS
cmd_chmod_acl(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
863 printf("Usage: chmod_acl <path> <mode>\n");
867 mode
= atoi(argv
[2]);
868 if (SMB_VFS_CHMOD_ACL(vfs
->conn
, argv
[1], mode
) == -1) {
869 printf("chmod_acl: error=%d (%s)\n", errno
, strerror(errno
));
870 return NT_STATUS_UNSUCCESSFUL
;
873 printf("chmod_acl: ok\n");
878 static NTSTATUS
cmd_fchmod_acl(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
883 printf("Usage: fchmod_acl <fd> <mode>\n");
888 mode
= atoi(argv
[2]);
889 if (fd
< 0 || fd
>= 1024) {
890 printf("fchmod_acl: error=%d (file descriptor out of range)\n", EBADF
);
893 if (vfs
->files
[fd
] == NULL
) {
894 printf("fchmod_acl: error=%d (invalid file descriptor)\n", EBADF
);
898 if (SMB_VFS_FCHMOD_ACL(vfs
->files
[fd
], mode
) == -1) {
899 printf("fchmod_acl: error=%d (%s)\n", errno
, strerror(errno
));
900 return NT_STATUS_UNSUCCESSFUL
;
903 printf("fchmod_acl: ok\n");
908 static NTSTATUS
cmd_chown(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
913 printf("Usage: chown <path> <uid> <gid>\n");
919 if (SMB_VFS_CHOWN(vfs
->conn
, argv
[1], uid
, gid
) == -1) {
920 printf("chown: error=%d (%s)\n", errno
, strerror(errno
));
921 return NT_STATUS_UNSUCCESSFUL
;
924 printf("chown: ok\n");
929 static NTSTATUS
cmd_fchown(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
935 printf("Usage: fchown <fd> <uid> <gid>\n");
942 if (fd
< 0 || fd
>= 1024) {
943 printf("fchown: faliure=%d (file descriptor out of range)\n", EBADF
);
946 if (vfs
->files
[fd
] == NULL
) {
947 printf("fchown: error=%d (invalid file descriptor)\n", EBADF
);
950 if (SMB_VFS_FCHOWN(vfs
->files
[fd
], uid
, gid
) == -1) {
951 printf("fchown error=%d (%s)\n", errno
, strerror(errno
));
952 return NT_STATUS_UNSUCCESSFUL
;
955 printf("fchown: ok\n");
960 static NTSTATUS
cmd_getwd(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
962 char *buf
= SMB_VFS_GETWD(vfs
->conn
);
964 printf("getwd: error=%d (%s)\n", errno
, strerror(errno
));
965 return NT_STATUS_UNSUCCESSFUL
;
968 printf("getwd: %s\n", buf
);
973 static NTSTATUS
cmd_utime(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
975 struct smb_file_time ft
;
976 struct smb_filename
*smb_fname
= NULL
;
979 printf("Usage: utime <path> <access> <modify>\n");
985 ft
.atime
= convert_time_t_to_timespec(atoi(argv
[2]));
986 ft
.mtime
= convert_time_t_to_timespec(atoi(argv
[3]));
988 smb_fname
= synthetic_smb_fname_split(mem_ctx
, argv
[1], NULL
);
989 if (smb_fname
== NULL
) {
990 return NT_STATUS_NO_MEMORY
;
993 if (SMB_VFS_NTIMES(vfs
->conn
, smb_fname
, &ft
) != 0) {
994 printf("utime: error=%d (%s)\n", errno
, strerror(errno
));
995 TALLOC_FREE(smb_fname
);
996 return NT_STATUS_UNSUCCESSFUL
;
999 TALLOC_FREE(smb_fname
);
1000 printf("utime: ok\n");
1001 return NT_STATUS_OK
;
1004 static NTSTATUS
cmd_ftruncate(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
1009 printf("Usage: ftruncate <fd> <length>\n");
1010 return NT_STATUS_OK
;
1014 off
= atoi(argv
[2]);
1015 if (fd
< 0 || fd
>= 1024) {
1016 printf("ftruncate: error=%d (file descriptor out of range)\n", EBADF
);
1017 return NT_STATUS_OK
;
1019 if (vfs
->files
[fd
] == NULL
) {
1020 printf("ftruncate: error=%d (invalid file descriptor)\n", EBADF
);
1021 return NT_STATUS_OK
;
1024 if (SMB_VFS_FTRUNCATE(vfs
->files
[fd
], off
) == -1) {
1025 printf("ftruncate: error=%d (%s)\n", errno
, strerror(errno
));
1026 return NT_STATUS_UNSUCCESSFUL
;
1029 printf("ftruncate: ok\n");
1030 return NT_STATUS_OK
;
1033 static NTSTATUS
cmd_lock(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
1040 const char *typestr
;
1043 printf("Usage: lock <fd> <op> <offset> <count> <type>\n");
1044 printf(" ops: G = F_GETLK\n");
1045 printf(" S = F_SETLK\n");
1046 printf(" W = F_SETLKW\n");
1047 printf(" type: R = F_RDLCK\n");
1048 printf(" W = F_WRLCK\n");
1049 printf(" U = F_UNLCK\n");
1050 return NT_STATUS_OK
;
1053 if (sscanf(argv
[1], "%d", &fd
) == 0) {
1054 printf("lock: error=-1 (error parsing fd)\n");
1055 return NT_STATUS_UNSUCCESSFUL
;
1070 printf("lock: error=-1 (invalid op flag!)\n");
1071 return NT_STATUS_UNSUCCESSFUL
;
1074 if (sscanf(argv
[3], "%ld", &offset
) == 0) {
1075 printf("lock: error=-1 (error parsing fd)\n");
1076 return NT_STATUS_UNSUCCESSFUL
;
1079 if (sscanf(argv
[4], "%ld", &count
) == 0) {
1080 printf("lock: error=-1 (error parsing fd)\n");
1081 return NT_STATUS_UNSUCCESSFUL
;
1098 printf("lock: error=-1 (invalid type flag!)\n");
1099 return NT_STATUS_UNSUCCESSFUL
;
1104 printf("lock: debug lock(fd=%d, op=%d, offset=%ld, count=%ld, type=%d))\n", fd
, op
, offset
, count
, type
);
1106 if (SMB_VFS_LOCK(vfs
->files
[fd
], op
, offset
, count
, type
) == False
) {
1107 printf("lock: error=%d (%s)\n", errno
, strerror(errno
));
1108 return NT_STATUS_UNSUCCESSFUL
;
1111 printf("lock: ok\n");
1112 return NT_STATUS_OK
;
1115 static NTSTATUS
cmd_symlink(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
1118 printf("Usage: symlink <path> <link>\n");
1119 return NT_STATUS_OK
;
1122 if (SMB_VFS_SYMLINK(vfs
->conn
, argv
[1], argv
[2]) == -1) {
1123 printf("symlink: error=%d (%s)\n", errno
, strerror(errno
));
1124 return NT_STATUS_UNSUCCESSFUL
;
1127 printf("symlink: ok\n");
1128 return NT_STATUS_OK
;
1132 static NTSTATUS
cmd_readlink(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
1134 char buffer
[PATH_MAX
];
1138 printf("Usage: readlink <path>\n");
1139 return NT_STATUS_OK
;
1142 if ((size
= SMB_VFS_READLINK(vfs
->conn
, argv
[1], buffer
, PATH_MAX
)) == -1) {
1143 printf("readlink: error=%d (%s)\n", errno
, strerror(errno
));
1144 return NT_STATUS_UNSUCCESSFUL
;
1147 buffer
[size
] = '\0';
1148 printf("readlink: %s\n", buffer
);
1149 return NT_STATUS_OK
;
1153 static NTSTATUS
cmd_link(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
1156 printf("Usage: link <path> <link>\n");
1157 return NT_STATUS_OK
;
1160 if (SMB_VFS_LINK(vfs
->conn
, argv
[1], argv
[2]) == -1) {
1161 printf("link: error=%d (%s)\n", errno
, strerror(errno
));
1162 return NT_STATUS_UNSUCCESSFUL
;
1165 printf("link: ok\n");
1166 return NT_STATUS_OK
;
1169 static NTSTATUS
cmd_mknod(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
1172 unsigned int dev_val
;
1176 printf("Usage: mknod <path> <mode> <dev>\n");
1177 printf(" mode is octal\n");
1178 printf(" dev is hex\n");
1179 return NT_STATUS_OK
;
1182 if (sscanf(argv
[2], "%ho", (unsigned short *)&mode
) == 0) {
1183 printf("open: error=-1 (invalid mode!)\n");
1184 return NT_STATUS_UNSUCCESSFUL
;
1187 if (sscanf(argv
[3], "%x", &dev_val
) == 0) {
1188 printf("open: error=-1 (invalid dev!)\n");
1189 return NT_STATUS_UNSUCCESSFUL
;
1191 dev
= (SMB_DEV_T
)dev_val
;
1193 if (SMB_VFS_MKNOD(vfs
->conn
, argv
[1], mode
, dev
) == -1) {
1194 printf("mknod: error=%d (%s)\n", errno
, strerror(errno
));
1195 return NT_STATUS_UNSUCCESSFUL
;
1198 printf("mknod: ok\n");
1199 return NT_STATUS_OK
;
1202 static NTSTATUS
cmd_realpath(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
1205 printf("Usage: realpath <path>\n");
1206 return NT_STATUS_OK
;
1209 if (SMB_VFS_REALPATH(vfs
->conn
, argv
[1]) == NULL
) {
1210 printf("realpath: error=%d (%s)\n", errno
, strerror(errno
));
1211 return NT_STATUS_UNSUCCESSFUL
;
1214 printf("realpath: ok\n");
1215 return NT_STATUS_OK
;
1218 static NTSTATUS
cmd_getxattr(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
,
1219 int argc
, const char **argv
)
1225 printf("Usage: getxattr <path> <xattr>\n");
1226 return NT_STATUS_OK
;
1231 ret
= SMB_VFS_GETXATTR(vfs
->conn
, argv
[1], argv
[2], buf
,
1232 talloc_get_size(buf
));
1235 printf("getxattr returned (%s)\n", strerror(err
));
1236 return map_nt_error_from_unix(err
);
1238 buf
= talloc_array(mem_ctx
, uint8_t, ret
);
1240 return NT_STATUS_NO_MEMORY
;
1242 ret
= SMB_VFS_GETXATTR(vfs
->conn
, argv
[1], argv
[2], buf
,
1243 talloc_get_size(buf
));
1246 printf("getxattr returned (%s)\n", strerror(err
));
1247 return map_nt_error_from_unix(err
);
1249 dump_data_file(buf
, talloc_get_size(buf
), false, stdout
);
1250 return NT_STATUS_OK
;
1253 static NTSTATUS
cmd_listxattr(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
,
1254 int argc
, const char **argv
)
1260 printf("Usage: listxattr <path>\n");
1261 return NT_STATUS_OK
;
1266 ret
= SMB_VFS_LISTXATTR(vfs
->conn
, argv
[1], buf
, talloc_get_size(buf
));
1269 printf("listxattr returned (%s)\n", strerror(err
));
1270 return map_nt_error_from_unix(err
);
1272 buf
= talloc_array(mem_ctx
, char, ret
);
1274 return NT_STATUS_NO_MEMORY
;
1276 ret
= SMB_VFS_LISTXATTR(vfs
->conn
, argv
[1], buf
, talloc_get_size(buf
));
1279 printf("listxattr returned (%s)\n", strerror(err
));
1280 return map_nt_error_from_unix(err
);
1283 return NT_STATUS_OK
;
1285 if (buf
[ret
-1] != '\0') {
1286 printf("listxattr returned non 0-terminated strings\n");
1287 return NT_STATUS_INTERNAL_ERROR
;
1291 while (p
< buf
+ret
) {
1296 return NT_STATUS_OK
;
1299 static NTSTATUS
cmd_setxattr(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
,
1300 int argc
, const char **argv
)
1305 if ((argc
< 4) || (argc
> 5)) {
1306 printf("Usage: setxattr <path> <xattr> <value> [flags]\n");
1307 return NT_STATUS_OK
;
1311 flags
= atoi(argv
[4]);
1314 ret
= SMB_VFS_SETXATTR(vfs
->conn
, argv
[1], argv
[2],
1315 argv
[3], strlen(argv
[3]), flags
);
1318 printf("setxattr returned (%s)\n", strerror(err
));
1319 return map_nt_error_from_unix(err
);
1321 return NT_STATUS_OK
;
1324 static NTSTATUS
cmd_removexattr(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
,
1325 int argc
, const char **argv
)
1330 printf("Usage: removexattr <path> <xattr>\n");
1331 return NT_STATUS_OK
;
1334 ret
= SMB_VFS_REMOVEXATTR(vfs
->conn
, argv
[1], argv
[2]);
1337 printf("removexattr returned (%s)\n", strerror(err
));
1338 return map_nt_error_from_unix(err
);
1340 return NT_STATUS_OK
;
1343 static NTSTATUS
cmd_fget_nt_acl(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
,
1344 int argc
, const char **argv
)
1348 struct security_descriptor
*sd
;
1351 printf("Usage: fget_nt_acl <fd>\n");
1352 return NT_STATUS_OK
;
1356 if (fd
< 0 || fd
>= 1024) {
1357 printf("fget_nt_acl: error=%d (file descriptor out of range)\n", EBADF
);
1358 return NT_STATUS_OK
;
1360 if (vfs
->files
[fd
] == NULL
) {
1361 printf("fget_nt_acl: error=%d (invalid file descriptor)\n", EBADF
);
1362 return NT_STATUS_OK
;
1365 status
= SMB_VFS_FGET_NT_ACL(vfs
->files
[fd
],
1366 SECINFO_OWNER
| SECINFO_GROUP
| SECINFO_DACL
,
1368 if (!NT_STATUS_IS_OK(status
)) {
1369 printf("fget_nt_acl returned (%s)\n", nt_errstr(status
));
1372 printf("%s\n", sddl_encode(talloc_tos(), sd
, get_global_sam_sid()));
1374 return NT_STATUS_OK
;
1377 static NTSTATUS
cmd_get_nt_acl(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
,
1378 int argc
, const char **argv
)
1381 struct security_descriptor
*sd
;
1384 printf("Usage: get_nt_acl <path>\n");
1385 return NT_STATUS_OK
;
1388 status
= SMB_VFS_GET_NT_ACL(vfs
->conn
, argv
[1],
1389 SECINFO_OWNER
| SECINFO_GROUP
| SECINFO_DACL
,
1391 if (!NT_STATUS_IS_OK(status
)) {
1392 printf("get_nt_acl returned (%s)\n", nt_errstr(status
));
1395 printf("%s\n", sddl_encode(talloc_tos(), sd
, get_global_sam_sid()));
1397 return NT_STATUS_OK
;
1400 static NTSTATUS
cmd_fset_nt_acl(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
,
1401 int argc
, const char **argv
)
1405 struct security_descriptor
*sd
;
1408 printf("Usage: fset_nt_acl <fd> <sddl>\n");
1409 return NT_STATUS_OK
;
1413 if (fd
< 0 || fd
>= 1024) {
1414 printf("fset_nt_acl: error=%d (file descriptor out of range)\n", EBADF
);
1415 return NT_STATUS_OK
;
1417 if (vfs
->files
[fd
] == NULL
) {
1418 printf("fset_nt_acl: error=%d (invalid file descriptor)\n", EBADF
);
1419 return NT_STATUS_OK
;
1422 sd
= sddl_decode(talloc_tos(), argv
[2], get_global_sam_sid());
1424 printf("sddl_decode failed to parse %s as SDDL\n", argv
[2]);
1425 return NT_STATUS_INVALID_PARAMETER
;
1428 status
= SMB_VFS_FSET_NT_ACL(vfs
->files
[fd
], SECINFO_OWNER
| SECINFO_GROUP
| SECINFO_DACL
, sd
);
1429 if (!NT_STATUS_IS_OK(status
)) {
1430 printf("fset_nt_acl returned (%s)\n", nt_errstr(status
));
1434 return NT_STATUS_OK
;
1437 static NTSTATUS
cmd_set_nt_acl(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
1443 struct smb_filename
*smb_fname
= NULL
;
1445 struct security_descriptor
*sd
= NULL
;
1448 printf("Usage: set_nt_acl <file> <sddl>\n");
1449 return NT_STATUS_OK
;
1454 fsp
= talloc_zero(vfs
, struct files_struct
);
1456 return NT_STATUS_NO_MEMORY
;
1458 fsp
->fh
= talloc_zero(fsp
, struct fd_handle
);
1459 if (fsp
->fh
== NULL
) {
1461 return NT_STATUS_NO_MEMORY
;
1463 fsp
->conn
= vfs
->conn
;
1465 smb_fname
= synthetic_smb_fname_split(NULL
, argv
[1], NULL
);
1466 if (smb_fname
== NULL
) {
1468 return NT_STATUS_NO_MEMORY
;
1471 fsp
->fsp_name
= smb_fname
;
1474 flags
= O_RDONLY
|O_DIRECTORY
;
1476 /* POSIX allows us to open a directory with O_RDONLY. */
1480 fsp
->fh
->fd
= SMB_VFS_OPEN(vfs
->conn
, smb_fname
, fsp
, O_RDWR
, mode
);
1481 if (fsp
->fh
->fd
== -1 && errno
== EISDIR
) {
1482 fsp
->fh
->fd
= SMB_VFS_OPEN(vfs
->conn
, smb_fname
, fsp
, flags
, mode
);
1484 if (fsp
->fh
->fd
== -1) {
1485 printf("open: error=%d (%s)\n", errno
, strerror(errno
));
1487 TALLOC_FREE(smb_fname
);
1488 return NT_STATUS_UNSUCCESSFUL
;
1491 ret
= SMB_VFS_FSTAT(fsp
, &smb_fname
->st
);
1493 /* If we have an fd, this stat should succeed. */
1494 DEBUG(0,("Error doing fstat on open file %s "
1496 smb_fname_str_dbg(smb_fname
),
1498 status
= map_nt_error_from_unix(errno
);
1501 if (!NT_STATUS_IS_OK(status
)) {
1505 fsp
->file_id
= vfs_file_id_from_sbuf(vfs
->conn
, &smb_fname
->st
);
1506 fsp
->vuid
= UID_FIELD_INVALID
;
1508 fsp
->can_lock
= True
;
1509 fsp
->can_read
= True
;
1510 fsp
->can_write
= True
;
1511 fsp
->print_file
= NULL
;
1512 fsp
->modified
= False
;
1513 fsp
->sent_oplock_break
= NO_BREAK_SENT
;
1514 fsp
->is_directory
= S_ISDIR(smb_fname
->st
.st_ex_mode
);
1517 sd
= sddl_decode(talloc_tos(), argv
[2], get_global_sam_sid());
1519 printf("sddl_decode failed to parse %s as SDDL\n", argv
[2]);
1520 status
= NT_STATUS_INVALID_PARAMETER
;
1524 status
= SMB_VFS_FSET_NT_ACL(fsp
, SECINFO_OWNER
| SECINFO_GROUP
| SECINFO_DACL
, sd
);
1525 if (!NT_STATUS_IS_OK(status
)) {
1526 printf("fset_nt_acl returned (%s)\n", nt_errstr(status
));
1532 ret
= SMB_VFS_CLOSE(fsp
);
1534 printf("close: error=%d (%s)\n", errno
, strerror(errno
));
1543 static NTSTATUS
cmd_sys_acl_get_fd(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
,
1544 int argc
, const char **argv
)
1552 printf("Usage: sys_acl_get_fd <fd>\n");
1553 return NT_STATUS_OK
;
1557 if (fd
< 0 || fd
>= 1024) {
1558 printf("sys_acl_get_fd: error=%d (file descriptor out of range)\n", EBADF
);
1559 return NT_STATUS_OK
;
1561 if (vfs
->files
[fd
] == NULL
) {
1562 printf("sys_acl_get_fd: error=%d (invalid file descriptor)\n", EBADF
);
1563 return NT_STATUS_OK
;
1566 acl
= SMB_VFS_SYS_ACL_GET_FD(vfs
->files
[fd
], talloc_tos());
1568 printf("sys_acl_get_fd failed (%s)\n", strerror(errno
));
1571 acl_text
= sys_acl_to_text(acl
, NULL
);
1572 printf("%s", acl_text
);
1574 SAFE_FREE(acl_text
);
1575 return NT_STATUS_OK
;
1578 static NTSTATUS
cmd_sys_acl_get_file(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
,
1579 int argc
, const char **argv
)
1586 printf("Usage: sys_acl_get_file <path> <type>\n");
1587 return NT_STATUS_OK
;
1590 type
= atoi(argv
[2]);
1591 acl
= SMB_VFS_SYS_ACL_GET_FILE(vfs
->conn
, argv
[1], type
, talloc_tos());
1593 printf("sys_acl_get_file failed (%s)\n", strerror(errno
));
1596 acl_text
= sys_acl_to_text(acl
, NULL
);
1597 printf("%s", acl_text
);
1599 SAFE_FREE(acl_text
);
1600 return NT_STATUS_OK
;
1603 static NTSTATUS
cmd_sys_acl_blob_get_file(struct vfs_state
*vfs
,
1604 TALLOC_CTX
*mem_ctx
,
1605 int argc
, const char **argv
)
1613 printf("Usage: sys_acl_get_file <path>\n");
1614 return NT_STATUS_OK
;
1617 ret
= SMB_VFS_SYS_ACL_BLOB_GET_FILE(vfs
->conn
, argv
[1], talloc_tos(),
1618 &description
, &blob
);
1620 printf("sys_acl_blob_get_file failed (%s)\n", strerror(errno
));
1621 return map_nt_error_from_unix(errno
);
1623 printf("Description: %s\n", description
);
1624 for (i
= 0; i
< blob
.length
; i
++) {
1625 printf("%.2x ", blob
.data
[i
]);
1629 return NT_STATUS_OK
;
1632 static NTSTATUS
cmd_sys_acl_blob_get_fd(struct vfs_state
*vfs
,
1633 TALLOC_CTX
*mem_ctx
,
1634 int argc
, const char **argv
)
1643 printf("Usage: sys_acl_blob_get_fd <fd>\n");
1644 return NT_STATUS_OK
;
1648 if (fd
< 0 || fd
>= 1024) {
1649 printf("sys_acl_blob_get_fd: error=%d "
1650 "(file descriptor out of range)\n", EBADF
);
1651 return NT_STATUS_OK
;
1653 if (vfs
->files
[fd
] == NULL
) {
1654 printf("sys_acl_blob_get_fd: error=%d "
1655 "(invalid file descriptor)\n", EBADF
);
1656 return NT_STATUS_OK
;
1659 ret
= SMB_VFS_SYS_ACL_BLOB_GET_FD(vfs
->files
[fd
], talloc_tos(),
1660 &description
, &blob
);
1662 printf("sys_acl_blob_get_fd failed (%s)\n", strerror(errno
));
1663 return map_nt_error_from_unix(errno
);
1665 printf("Description: %s\n", description
);
1666 for (i
= 0; i
< blob
.length
; i
++) {
1667 printf("%.2x ", blob
.data
[i
]);
1671 return NT_STATUS_OK
;
1676 static NTSTATUS
cmd_sys_acl_delete_def_file(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
,
1677 int argc
, const char **argv
)
1682 printf("Usage: sys_acl_delete_def_file <path>\n");
1683 return NT_STATUS_OK
;
1686 ret
= SMB_VFS_SYS_ACL_DELETE_DEF_FILE(vfs
->conn
, argv
[1]);
1688 printf("sys_acl_delete_def_file failed (%s)\n", strerror(errno
));
1689 return NT_STATUS_UNSUCCESSFUL
;
1691 return NT_STATUS_OK
;
1694 /* Afaik translate name was first introduced with vfs_catia, to be able
1695 to translate unix file/dir-names, containing invalid windows characters,
1696 to valid windows names.
1697 The used translation direction is always unix --> windows
1699 static NTSTATUS
cmd_translate_name(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
,
1700 int argc
, const char **argv
)
1703 struct dirent
*dent
= NULL
;
1706 char *translated
= NULL
;
1710 DEBUG(0, ("Usage: translate_name unix_filename\n"));
1711 return NT_STATUS_UNSUCCESSFUL
;
1714 vfs
->currentdir
= SMB_VFS_OPENDIR(vfs
->conn
, ".", NULL
, 0);
1715 if (vfs
->currentdir
== NULL
) {
1716 DEBUG(0, ("cmd_translate_name: opendir error=%d (%s)\n",
1717 errno
, strerror(errno
)));
1718 return NT_STATUS_UNSUCCESSFUL
;
1722 dent
= SMB_VFS_READDIR(vfs
->conn
, vfs
->currentdir
, &st
);
1726 if (strcmp (dent
->d_name
, argv
[1]) == 0) {
1733 DEBUG(0, ("cmd_translate_name: file '%s' not found.\n",
1735 status
= NT_STATUS_UNSUCCESSFUL
;
1738 status
= SMB_VFS_TRANSLATE_NAME(vfs
->conn
, dent
->d_name
,
1739 vfs_translate_to_windows
,
1740 talloc_tos(), &translated
);
1741 if (NT_STATUS_EQUAL(status
, NT_STATUS_NONE_MAPPED
)) {
1742 DEBUG(0, ("cmd_translate_name: file '%s' cannot be "
1743 "translated\n", argv
[1]));
1744 TALLOC_FREE(translated
);
1747 /* translation success. But that could also mean
1748 that translating "aaa" to "aaa" was successful :-(
1750 DEBUG(0, ("cmd_translate_name: file '%s' --> '%s'\n",
1751 argv
[1], translated
));
1753 TALLOC_FREE(translated
);
1756 ret
= SMB_VFS_CLOSEDIR(vfs
->conn
, vfs
->currentdir
);
1758 DEBUG(0, ("cmd_translate_name: closedir failure: %s\n",
1760 return NT_STATUS_UNSUCCESSFUL
;
1763 vfs
->currentdir
= NULL
;
1768 struct cmd_set vfs_commands
[] = {
1772 { "load", cmd_load_module
, "Load a module", "load <module.so>" },
1773 { "populate", cmd_populate
, "Populate a data buffer", "populate <char> <size>" },
1774 { "showdata", cmd_show_data
, "Show data currently in data buffer", "show_data [<offset> <len>]"},
1775 { "connect", cmd_connect
, "VFS connect()", "connect" },
1776 { "disconnect", cmd_disconnect
, "VFS disconnect()", "disconnect" },
1777 { "disk_free", cmd_disk_free
, "VFS disk_free()", "disk_free <path>" },
1778 { "opendir", cmd_opendir
, "VFS opendir()", "opendir <fname>" },
1779 { "readdir", cmd_readdir
, "VFS readdir()", "readdir" },
1780 { "mkdir", cmd_mkdir
, "VFS mkdir()", "mkdir <path>" },
1781 { "rmdir", cmd_pathfunc
, "VFS rmdir()", "rmdir <path>" },
1782 { "closedir", cmd_closedir
, "VFS closedir()", "closedir" },
1783 { "open", cmd_open
, "VFS open()", "open <fname>" },
1784 { "close", cmd_close
, "VFS close()", "close <fd>" },
1785 { "read", cmd_read
, "VFS read()", "read <fd> <size>" },
1786 { "write", cmd_write
, "VFS write()", "write <fd> <size>" },
1787 { "lseek", cmd_lseek
, "VFS lseek()", "lseek <fd> <offset> <whence>" },
1788 { "rename", cmd_rename
, "VFS rename()", "rename <old> <new>" },
1789 { "fsync", cmd_fsync
, "VFS fsync()", "fsync <fd>" },
1790 { "stat", cmd_stat
, "VFS stat()", "stat <fname>" },
1791 { "fstat", cmd_fstat
, "VFS fstat()", "fstat <fd>" },
1792 { "lstat", cmd_lstat
, "VFS lstat()", "lstat <fname>" },
1793 { "unlink", cmd_pathfunc
, "VFS unlink()", "unlink <fname>" },
1794 { "chmod", cmd_chmod
, "VFS chmod()", "chmod <path> <mode>" },
1795 { "fchmod", cmd_fchmod
, "VFS fchmod()", "fchmod <fd> <mode>" },
1796 { "chown", cmd_chown
, "VFS chown()", "chown <path> <uid> <gid>" },
1797 { "fchown", cmd_fchown
, "VFS fchown()", "fchown <fd> <uid> <gid>" },
1798 { "chdir", cmd_pathfunc
, "VFS chdir()", "chdir <path>" },
1799 { "getwd", cmd_getwd
, "VFS getwd()", "getwd" },
1800 { "utime", cmd_utime
, "VFS utime()", "utime <path> <access> <modify>" },
1801 { "ftruncate", cmd_ftruncate
, "VFS ftruncate()", "ftruncate <fd> <length>" },
1802 { "lock", cmd_lock
, "VFS lock()", "lock <f> <op> <offset> <count> <type>" },
1803 { "symlink", cmd_symlink
, "VFS symlink()", "symlink <old> <new>" },
1804 { "readlink", cmd_readlink
, "VFS readlink()", "readlink <path>" },
1805 { "link", cmd_link
, "VFS link()", "link <oldpath> <newpath>" },
1806 { "mknod", cmd_mknod
, "VFS mknod()", "mknod <path> <mode> <dev>" },
1807 { "realpath", cmd_realpath
, "VFS realpath()", "realpath <path>" },
1808 { "getxattr", cmd_getxattr
, "VFS getxattr()",
1809 "getxattr <path> <name>" },
1810 { "listxattr", cmd_listxattr
, "VFS listxattr()",
1811 "listxattr <path>" },
1812 { "setxattr", cmd_setxattr
, "VFS setxattr()",
1813 "setxattr <path> <name> <value> [<flags>]" },
1814 { "removexattr", cmd_removexattr
, "VFS removexattr()",
1815 "removexattr <path> <name>\n" },
1816 { "fget_nt_acl", cmd_fget_nt_acl
, "VFS fget_nt_acl()",
1817 "fget_nt_acl <fd>\n" },
1818 { "get_nt_acl", cmd_get_nt_acl
, "VFS get_nt_acl()",
1819 "get_nt_acl <path>\n" },
1820 { "fset_nt_acl", cmd_fset_nt_acl
, "VFS fset_nt_acl()",
1821 "fset_nt_acl <fd>\n" },
1822 { "set_nt_acl", cmd_set_nt_acl
, "VFS open() and fset_nt_acl()",
1823 "set_nt_acl <file>\n" },
1824 { "fchmod_acl", cmd_fchmod_acl
, "VFS fchmod_acl()", "fchmod_acl <fd> <mode>" },
1825 { "chmod_acl", cmd_chmod_acl
, "VFS chmod_acl()", "chmod_acl <path> <mode>" },
1826 { "sys_acl_get_file", cmd_sys_acl_get_file
, "VFS sys_acl_get_file()", "sys_acl_get_file <path>" },
1827 { "sys_acl_get_fd", cmd_sys_acl_get_fd
, "VFS sys_acl_get_fd()", "sys_acl_get_fd <fd>" },
1828 { "sys_acl_blob_get_file", cmd_sys_acl_blob_get_file
,
1829 "VFS sys_acl_blob_get_file()", "sys_acl_blob_get_file <path>" },
1830 { "sys_acl_blob_get_fd", cmd_sys_acl_blob_get_fd
,
1831 "VFS sys_acl_blob_get_fd()", "sys_acl_blob_get_fd <path>" },
1832 { "sys_acl_delete_def_file", cmd_sys_acl_delete_def_file
, "VFS sys_acl_delete_def_file()", "sys_acl_delete_def_file <path>" },
1835 { "test_chain", cmd_test_chain
, "test chain code",
1837 { "translate_name", cmd_translate_name
, "VFS translate_name()", "translate_name unix_filename" },