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 uint32_t ssf_flags(void)
35 return lp_posix_pathnames() ? SMB_FILENAME_POSIX_PATH
: 0;
38 static NTSTATUS
cmd_load_module(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
43 printf("Usage: load <modules>\n");
47 for (i
=argc
-1;i
>0;i
--) {
48 if (!vfs_init_custom(vfs
->conn
, argv
[i
])) {
49 DEBUG(0, ("load: (vfs_init_custom failed for %s)\n", argv
[i
]));
50 return NT_STATUS_UNSUCCESSFUL
;
57 static NTSTATUS
cmd_populate(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
62 printf("Usage: populate <char> <size>\n");
67 vfs
->data
= talloc_array(mem_ctx
, char, size
);
68 if (vfs
->data
== NULL
) {
69 printf("populate: error=-1 (not enough memory)");
70 return NT_STATUS_UNSUCCESSFUL
;
72 memset(vfs
->data
, c
, size
);
73 vfs
->data_size
= size
;
77 static NTSTATUS
cmd_show_data(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
81 if (argc
!= 1 && argc
!= 3) {
82 printf("Usage: showdata [<offset> <len>]\n");
85 if (vfs
->data
== NULL
|| vfs
->data_size
== 0) {
86 printf("show_data: error=-1 (buffer empty)\n");
87 return NT_STATUS_UNSUCCESSFUL
;
91 offset
= atoi(argv
[1]);
97 if ((offset
+ len
) > vfs
->data_size
) {
98 printf("show_data: error=-1 (not enough data in buffer)\n");
99 return NT_STATUS_UNSUCCESSFUL
;
101 dump_data(0, (uint8_t *)(vfs
->data
) + offset
, len
);
105 static NTSTATUS
cmd_connect(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
107 SMB_VFS_CONNECT(vfs
->conn
, lp_servicename(talloc_tos(), SNUM(vfs
->conn
)), "vfstest");
111 static NTSTATUS
cmd_disconnect(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
113 SMB_VFS_DISCONNECT(vfs
->conn
);
117 static NTSTATUS
cmd_disk_free(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
119 uint64_t diskfree
, bsize
, dfree
, dsize
;
121 printf("Usage: disk_free <path>\n");
125 diskfree
= SMB_VFS_DISK_FREE(vfs
->conn
, argv
[1], &bsize
, &dfree
, &dsize
);
126 printf("disk_free: %lu, bsize = %lu, dfree = %lu, dsize = %lu\n",
127 (unsigned long)diskfree
,
128 (unsigned long)bsize
,
129 (unsigned long)dfree
,
130 (unsigned long)dsize
);
135 static NTSTATUS
cmd_opendir(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
137 struct smb_filename
*smb_fname
= NULL
;
140 printf("Usage: opendir <fname>\n");
144 smb_fname
= synthetic_smb_fname(talloc_tos(),
149 if (smb_fname
== NULL
) {
150 return NT_STATUS_NO_MEMORY
;
153 vfs
->currentdir
= SMB_VFS_OPENDIR(vfs
->conn
, smb_fname
, NULL
, 0);
154 if (vfs
->currentdir
== NULL
) {
155 printf("opendir error=%d (%s)\n", errno
, strerror(errno
));
156 TALLOC_FREE(smb_fname
);
157 return NT_STATUS_UNSUCCESSFUL
;
160 TALLOC_FREE(smb_fname
);
161 printf("opendir: ok\n");
166 static NTSTATUS
cmd_readdir(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
169 struct dirent
*dent
= NULL
;
171 if (vfs
->currentdir
== NULL
) {
172 printf("readdir: error=-1 (no open directory)\n");
173 return NT_STATUS_UNSUCCESSFUL
;
176 dent
= SMB_VFS_READDIR(vfs
->conn
, vfs
->currentdir
, &st
);
178 printf("readdir: NULL\n");
182 printf("readdir: %s\n", dent
->d_name
);
183 if (VALID_STAT(st
)) {
185 printf(" stat available");
186 if (S_ISREG(st
.st_ex_mode
)) printf(" Regular File\n");
187 else if (S_ISDIR(st
.st_ex_mode
)) printf(" Directory\n");
188 else if (S_ISCHR(st
.st_ex_mode
)) printf(" Character Device\n");
189 else if (S_ISBLK(st
.st_ex_mode
)) printf(" Block Device\n");
190 else if (S_ISFIFO(st
.st_ex_mode
)) printf(" Fifo\n");
191 else if (S_ISLNK(st
.st_ex_mode
)) printf(" Symbolic Link\n");
192 else if (S_ISSOCK(st
.st_ex_mode
)) printf(" Socket\n");
193 printf(" Size: %10u", (unsigned int)st
.st_ex_size
);
194 #ifdef HAVE_STAT_ST_BLOCKS
195 printf(" Blocks: %9u", (unsigned int)st
.st_ex_blocks
);
197 #ifdef HAVE_STAT_ST_BLKSIZE
198 printf(" IO Block: %u\n", (unsigned int)st
.st_ex_blksize
);
200 printf(" Device: 0x%10x", (unsigned int)st
.st_ex_dev
);
201 printf(" Inode: %10u", (unsigned int)st
.st_ex_ino
);
202 printf(" Links: %10u\n", (unsigned int)st
.st_ex_nlink
);
203 printf(" Access: %05o", (int)((st
.st_ex_mode
) & 007777));
204 printf(" Uid: %5lu Gid: %5lu\n",
205 (unsigned long)st
.st_ex_uid
,
206 (unsigned long)st
.st_ex_gid
);
207 tmp_time
= convert_timespec_to_time_t(st
.st_ex_atime
);
208 printf(" Access: %s", ctime(&tmp_time
));
209 tmp_time
= convert_timespec_to_time_t(st
.st_ex_mtime
);
210 printf(" Modify: %s", ctime(&tmp_time
));
211 tmp_time
= convert_timespec_to_time_t(st
.st_ex_ctime
);
212 printf(" Change: %s", ctime(&tmp_time
));
219 static NTSTATUS
cmd_mkdir(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
221 struct smb_filename
*smb_fname
= NULL
;
224 printf("Usage: mkdir <path>\n");
228 smb_fname
= synthetic_smb_fname(talloc_tos(),
234 if (smb_fname
== NULL
) {
235 return NT_STATUS_NO_MEMORY
;
238 if (SMB_VFS_MKDIR(vfs
->conn
, smb_fname
, 00755) == -1) {
239 printf("mkdir error=%d (%s)\n", errno
, strerror(errno
));
240 return NT_STATUS_UNSUCCESSFUL
;
243 printf("mkdir: ok\n");
248 static NTSTATUS
cmd_closedir(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
252 if (vfs
->currentdir
== NULL
) {
253 printf("closedir: failure (no directory open)\n");
254 return NT_STATUS_UNSUCCESSFUL
;
257 ret
= SMB_VFS_CLOSEDIR(vfs
->conn
, vfs
->currentdir
);
259 printf("closedir failure: %s\n", strerror(errno
));
260 return NT_STATUS_UNSUCCESSFUL
;
263 printf("closedir: ok\n");
264 vfs
->currentdir
= NULL
;
269 static NTSTATUS
cmd_open(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
275 struct smb_filename
*smb_fname
= NULL
;
281 if (argc
< 3 || argc
> 5) {
282 printf("Usage: open <filename> <flags> <mode>\n");
283 printf(" flags: O = O_RDONLY\n");
284 printf(" R = O_RDWR\n");
285 printf(" W = O_WRONLY\n");
286 printf(" C = O_CREAT\n");
287 printf(" E = O_EXCL\n");
288 printf(" T = O_TRUNC\n");
289 printf(" A = O_APPEND\n");
290 printf(" N = O_NONBLOCK/O_NDELAY\n");
292 printf(" S = O_SYNC\n");
295 printf(" F = O_NOFOLLOW\n");
297 printf(" mode: see open.2\n");
298 printf(" mode is ignored if C flag not present\n");
299 printf(" mode defaults to 00400\n");
341 printf("open: error=-1 (invalid flag!)\n");
342 return NT_STATUS_UNSUCCESSFUL
;
346 if ((flags
& O_CREAT
) && argc
== 4) {
347 if (sscanf(argv
[3], "%ho", (unsigned short *)&mode
) == 0) {
348 printf("open: error=-1 (invalid mode!)\n");
349 return NT_STATUS_UNSUCCESSFUL
;
353 fsp
= talloc_zero(vfs
, struct files_struct
);
355 return NT_STATUS_NO_MEMORY
;
357 fsp
->fh
= talloc_zero(fsp
, struct fd_handle
);
358 if (fsp
->fh
== NULL
) {
360 return NT_STATUS_NO_MEMORY
;
362 fsp
->conn
= vfs
->conn
;
364 smb_fname
= synthetic_smb_fname_split(NULL
,
366 lp_posix_pathnames());
367 if (smb_fname
== NULL
) {
369 return NT_STATUS_NO_MEMORY
;
372 fsp
->fsp_name
= smb_fname
;
374 fsp
->fh
->fd
= SMB_VFS_OPEN(vfs
->conn
, smb_fname
, fsp
, flags
, mode
);
375 if (fsp
->fh
->fd
== -1) {
376 printf("open: error=%d (%s)\n", errno
, strerror(errno
));
378 TALLOC_FREE(smb_fname
);
379 return NT_STATUS_UNSUCCESSFUL
;
382 status
= NT_STATUS_OK
;
383 ret
= SMB_VFS_FSTAT(fsp
, &smb_fname
->st
);
385 /* If we have an fd, this stat should succeed. */
386 DEBUG(0,("Error doing fstat on open file %s "
388 smb_fname_str_dbg(smb_fname
),
390 status
= map_nt_error_from_unix(errno
);
391 } else if (S_ISDIR(smb_fname
->st
.st_ex_mode
)) {
393 status
= NT_STATUS_FILE_IS_A_DIRECTORY
;
396 if (!NT_STATUS_IS_OK(status
)) {
399 TALLOC_FREE(smb_fname
);
403 fsp
->file_id
= vfs_file_id_from_sbuf(vfs
->conn
, &smb_fname
->st
);
404 fsp
->vuid
= UID_FIELD_INVALID
;
406 fsp
->can_lock
= True
;
407 fsp
->can_read
= True
;
409 CAN_WRITE(vfs
->conn
);
410 fsp
->print_file
= NULL
;
411 fsp
->modified
= False
;
412 fsp
->sent_oplock_break
= NO_BREAK_SENT
;
413 fsp
->is_directory
= False
;
415 vfs
->files
[fsp
->fh
->fd
] = fsp
;
416 printf("open: fd=%d\n", fsp
->fh
->fd
);
421 static NTSTATUS
cmd_pathfunc(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
423 struct smb_filename
*smb_fname
= NULL
;
427 printf("Usage: %s <path>\n", argv
[0]);
431 smb_fname
= synthetic_smb_fname(talloc_tos(),
437 if (smb_fname
== NULL
) {
438 return NT_STATUS_NO_MEMORY
;
441 if (strcmp("rmdir", argv
[0]) == 0 ) {
442 ret
= SMB_VFS_RMDIR(vfs
->conn
, smb_fname
);
443 TALLOC_FREE(smb_fname
);
444 } else if (strcmp("unlink", argv
[0]) == 0 ) {
445 TALLOC_FREE(smb_fname
);
446 /* unlink can be a stream:name */
447 smb_fname
= synthetic_smb_fname_split(talloc_tos(),
449 lp_posix_pathnames());
450 if (smb_fname
== NULL
) {
451 return NT_STATUS_NO_MEMORY
;
453 ret
= SMB_VFS_UNLINK(vfs
->conn
, smb_fname
);
454 TALLOC_FREE(smb_fname
);
455 } else if (strcmp("chdir", argv
[0]) == 0 ) {
456 ret
= SMB_VFS_CHDIR(vfs
->conn
, argv
[1]);
458 printf("%s: error=%d (invalid function name!)\n", argv
[0], errno
);
459 return NT_STATUS_UNSUCCESSFUL
;
463 printf("%s: error=%d (%s)\n", argv
[0], errno
, strerror(errno
));
464 return NT_STATUS_UNSUCCESSFUL
;
467 printf("%s: ok\n", argv
[0]);
472 static NTSTATUS
cmd_close(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
477 printf("Usage: close <fd>\n");
482 if (vfs
->files
[fd
] == NULL
) {
483 printf("close: error=-1 (invalid file descriptor)\n");
487 ret
= SMB_VFS_CLOSE(vfs
->files
[fd
]);
489 printf("close: error=%d (%s)\n", errno
, strerror(errno
));
491 printf("close: ok\n");
493 TALLOC_FREE(vfs
->files
[fd
]);
494 vfs
->files
[fd
] = NULL
;
499 static NTSTATUS
cmd_read(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
505 printf("Usage: read <fd> <size>\n");
509 /* do some error checking on these */
511 size
= atoi(argv
[2]);
512 vfs
->data
= talloc_array(mem_ctx
, char, size
);
513 if (vfs
->data
== NULL
) {
514 printf("read: error=-1 (not enough memory)");
515 return NT_STATUS_UNSUCCESSFUL
;
517 vfs
->data_size
= size
;
519 rsize
= SMB_VFS_READ(vfs
->files
[fd
], vfs
->data
, size
);
521 printf("read: error=%d (%s)\n", errno
, strerror(errno
));
522 return NT_STATUS_UNSUCCESSFUL
;
525 printf("read: ok\n");
530 static NTSTATUS
cmd_write(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
535 printf("Usage: write <fd> <size>\n");
539 /* some error checking should go here */
541 size
= atoi(argv
[2]);
542 if (vfs
->data
== NULL
) {
543 printf("write: error=-1 (buffer empty, please populate it before writing)");
544 return NT_STATUS_UNSUCCESSFUL
;
547 if (vfs
->data_size
< size
) {
548 printf("write: error=-1 (buffer too small, please put some more data in)");
549 return NT_STATUS_UNSUCCESSFUL
;
552 wsize
= SMB_VFS_WRITE(vfs
->files
[fd
], vfs
->data
, size
);
555 printf("write: error=%d (%s)\n", errno
, strerror(errno
));
556 return NT_STATUS_UNSUCCESSFUL
;
559 printf("write: ok\n");
564 static NTSTATUS
cmd_lseek(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
566 int fd
, offset
, whence
;
570 printf("Usage: lseek <fd> <offset> <whence>\n...where whence is 1 => SEEK_SET, 2 => SEEK_CUR, 3 => SEEK_END\n");
575 offset
= atoi(argv
[2]);
576 whence
= atoi(argv
[3]);
578 case 1: whence
= SEEK_SET
; break;
579 case 2: whence
= SEEK_CUR
; break;
580 default: whence
= SEEK_END
;
583 pos
= SMB_VFS_LSEEK(vfs
->files
[fd
], offset
, whence
);
584 if (pos
== (off_t
)-1) {
585 printf("lseek: error=%d (%s)\n", errno
, strerror(errno
));
586 return NT_STATUS_UNSUCCESSFUL
;
589 printf("lseek: ok\n");
594 static NTSTATUS
cmd_rename(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
597 struct smb_filename
*smb_fname_src
= NULL
;
598 struct smb_filename
*smb_fname_dst
= NULL
;
601 printf("Usage: rename <old> <new>\n");
605 smb_fname_src
= synthetic_smb_fname_split(mem_ctx
,
607 lp_posix_pathnames());
608 if (smb_fname_src
== NULL
) {
609 return NT_STATUS_NO_MEMORY
;
612 smb_fname_dst
= synthetic_smb_fname_split(mem_ctx
,
614 lp_posix_pathnames());
615 if (smb_fname_dst
== NULL
) {
616 TALLOC_FREE(smb_fname_src
);
617 return NT_STATUS_NO_MEMORY
;
620 ret
= SMB_VFS_RENAME(vfs
->conn
, smb_fname_src
, smb_fname_dst
);
621 TALLOC_FREE(smb_fname_src
);
622 TALLOC_FREE(smb_fname_dst
);
624 printf("rename: error=%d (%s)\n", errno
, strerror(errno
));
625 return NT_STATUS_UNSUCCESSFUL
;
628 printf("rename: ok\n");
633 static NTSTATUS
cmd_fsync(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
637 printf("Usage: fsync <fd>\n");
642 ret
= SMB_VFS_FSYNC(vfs
->files
[fd
]);
644 printf("fsync: error=%d (%s)\n", errno
, strerror(errno
));
645 return NT_STATUS_UNSUCCESSFUL
;
648 printf("fsync: ok\n");
653 static NTSTATUS
cmd_stat(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
658 struct passwd
*pwd
= NULL
;
659 struct group
*grp
= NULL
;
660 struct smb_filename
*smb_fname
= NULL
;
665 printf("Usage: stat <fname>\n");
669 smb_fname
= synthetic_smb_fname_split(mem_ctx
,
671 lp_posix_pathnames());
672 if (smb_fname
== NULL
) {
673 return NT_STATUS_NO_MEMORY
;
676 ret
= SMB_VFS_STAT(vfs
->conn
, smb_fname
);
678 printf("stat: error=%d (%s)\n", errno
, strerror(errno
));
679 TALLOC_FREE(smb_fname
);
680 return NT_STATUS_UNSUCCESSFUL
;
683 TALLOC_FREE(smb_fname
);
685 pwd
= getpwuid(st
.st_ex_uid
);
686 if (pwd
!= NULL
) user
= pwd
->pw_name
;
687 else user
= null_string
;
688 grp
= getgrgid(st
.st_ex_gid
);
689 if (grp
!= NULL
) group
= grp
->gr_name
;
690 else group
= null_string
;
692 printf("stat: ok\n");
693 printf(" File: %s", argv
[1]);
694 if (S_ISREG(st
.st_ex_mode
)) printf(" Regular File\n");
695 else if (S_ISDIR(st
.st_ex_mode
)) printf(" Directory\n");
696 else if (S_ISCHR(st
.st_ex_mode
)) printf(" Character Device\n");
697 else if (S_ISBLK(st
.st_ex_mode
)) printf(" Block Device\n");
698 else if (S_ISFIFO(st
.st_ex_mode
)) printf(" Fifo\n");
699 else if (S_ISLNK(st
.st_ex_mode
)) printf(" Symbolic Link\n");
700 else if (S_ISSOCK(st
.st_ex_mode
)) printf(" Socket\n");
701 printf(" Size: %10u", (unsigned int)st
.st_ex_size
);
702 #ifdef HAVE_STAT_ST_BLOCKS
703 printf(" Blocks: %9u", (unsigned int)st
.st_ex_blocks
);
705 #ifdef HAVE_STAT_ST_BLKSIZE
706 printf(" IO Block: %u\n", (unsigned int)st
.st_ex_blksize
);
708 printf(" Device: 0x%10x", (unsigned int)st
.st_ex_dev
);
709 printf(" Inode: %10u", (unsigned int)st
.st_ex_ino
);
710 printf(" Links: %10u\n", (unsigned int)st
.st_ex_nlink
);
711 printf(" Access: %05o", (int)((st
.st_ex_mode
) & 007777));
712 printf(" Uid: %5lu/%.16s Gid: %5lu/%.16s\n", (unsigned long)st
.st_ex_uid
, user
,
713 (unsigned long)st
.st_ex_gid
, group
);
714 tmp_time
= convert_timespec_to_time_t(st
.st_ex_atime
);
715 printf(" Access: %s", ctime(&tmp_time
));
716 tmp_time
= convert_timespec_to_time_t(st
.st_ex_mtime
);
717 printf(" Modify: %s", ctime(&tmp_time
));
718 tmp_time
= convert_timespec_to_time_t(st
.st_ex_ctime
);
719 printf(" Change: %s", ctime(&tmp_time
));
725 static NTSTATUS
cmd_fstat(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
730 struct passwd
*pwd
= NULL
;
731 struct group
*grp
= NULL
;
736 printf("Usage: fstat <fd>\n");
741 if (fd
< 0 || fd
>= 1024) {
742 printf("fstat: error=%d (file descriptor out of range)\n", EBADF
);
746 if (vfs
->files
[fd
] == NULL
) {
747 printf("fstat: error=%d (invalid file descriptor)\n", EBADF
);
751 if (SMB_VFS_FSTAT(vfs
->files
[fd
], &st
) == -1) {
752 printf("fstat: error=%d (%s)\n", errno
, strerror(errno
));
753 return NT_STATUS_UNSUCCESSFUL
;
756 pwd
= getpwuid(st
.st_ex_uid
);
757 if (pwd
!= NULL
) user
= pwd
->pw_name
;
758 else user
= null_string
;
759 grp
= getgrgid(st
.st_ex_gid
);
760 if (grp
!= NULL
) group
= grp
->gr_name
;
761 else group
= null_string
;
763 printf("fstat: ok\n");
764 if (S_ISREG(st
.st_ex_mode
)) printf(" Regular File\n");
765 else if (S_ISDIR(st
.st_ex_mode
)) printf(" Directory\n");
766 else if (S_ISCHR(st
.st_ex_mode
)) printf(" Character Device\n");
767 else if (S_ISBLK(st
.st_ex_mode
)) printf(" Block Device\n");
768 else if (S_ISFIFO(st
.st_ex_mode
)) printf(" Fifo\n");
769 else if (S_ISLNK(st
.st_ex_mode
)) printf(" Symbolic Link\n");
770 else if (S_ISSOCK(st
.st_ex_mode
)) printf(" Socket\n");
771 printf(" Size: %10u", (unsigned int)st
.st_ex_size
);
772 #ifdef HAVE_STAT_ST_BLOCKS
773 printf(" Blocks: %9u", (unsigned int)st
.st_ex_blocks
);
775 #ifdef HAVE_STAT_ST_BLKSIZE
776 printf(" IO Block: %u\n", (unsigned int)st
.st_ex_blksize
);
778 printf(" Device: 0x%10x", (unsigned int)st
.st_ex_dev
);
779 printf(" Inode: %10u", (unsigned int)st
.st_ex_ino
);
780 printf(" Links: %10u\n", (unsigned int)st
.st_ex_nlink
);
781 printf(" Access: %05o", (int)((st
.st_ex_mode
) & 007777));
782 printf(" Uid: %5lu/%.16s Gid: %5lu/%.16s\n", (unsigned long)st
.st_ex_uid
, user
,
783 (unsigned long)st
.st_ex_gid
, group
);
784 tmp_time
= convert_timespec_to_time_t(st
.st_ex_atime
);
785 printf(" Access: %s", ctime(&tmp_time
));
786 tmp_time
= convert_timespec_to_time_t(st
.st_ex_mtime
);
787 printf(" Modify: %s", ctime(&tmp_time
));
788 tmp_time
= convert_timespec_to_time_t(st
.st_ex_ctime
);
789 printf(" Change: %s", ctime(&tmp_time
));
795 static NTSTATUS
cmd_lstat(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
799 struct passwd
*pwd
= NULL
;
800 struct group
*grp
= NULL
;
801 struct smb_filename
*smb_fname
= NULL
;
806 printf("Usage: lstat <path>\n");
810 smb_fname
= synthetic_smb_fname_split(mem_ctx
,
812 lp_posix_pathnames());
813 if (smb_fname
== NULL
) {
814 return NT_STATUS_NO_MEMORY
;
817 if (SMB_VFS_LSTAT(vfs
->conn
, smb_fname
) == -1) {
818 printf("lstat: error=%d (%s)\n", errno
, strerror(errno
));
819 TALLOC_FREE(smb_fname
);
820 return NT_STATUS_UNSUCCESSFUL
;
823 TALLOC_FREE(smb_fname
);
825 pwd
= getpwuid(st
.st_ex_uid
);
826 if (pwd
!= NULL
) user
= pwd
->pw_name
;
827 else user
= null_string
;
828 grp
= getgrgid(st
.st_ex_gid
);
829 if (grp
!= NULL
) group
= grp
->gr_name
;
830 else group
= null_string
;
832 printf("lstat: ok\n");
833 if (S_ISREG(st
.st_ex_mode
)) printf(" Regular File\n");
834 else if (S_ISDIR(st
.st_ex_mode
)) printf(" Directory\n");
835 else if (S_ISCHR(st
.st_ex_mode
)) printf(" Character Device\n");
836 else if (S_ISBLK(st
.st_ex_mode
)) printf(" Block Device\n");
837 else if (S_ISFIFO(st
.st_ex_mode
)) printf(" Fifo\n");
838 else if (S_ISLNK(st
.st_ex_mode
)) printf(" Symbolic Link\n");
839 else if (S_ISSOCK(st
.st_ex_mode
)) printf(" Socket\n");
840 printf(" Size: %10u", (unsigned int)st
.st_ex_size
);
841 #ifdef HAVE_STAT_ST_BLOCKS
842 printf(" Blocks: %9u", (unsigned int)st
.st_ex_blocks
);
844 #ifdef HAVE_STAT_ST_BLKSIZE
845 printf(" IO Block: %u\n", (unsigned int)st
.st_ex_blksize
);
847 printf(" Device: 0x%10x", (unsigned int)st
.st_ex_dev
);
848 printf(" Inode: %10u", (unsigned int)st
.st_ex_ino
);
849 printf(" Links: %10u\n", (unsigned int)st
.st_ex_nlink
);
850 printf(" Access: %05o", (int)((st
.st_ex_mode
) & 007777));
851 printf(" Uid: %5lu/%.16s Gid: %5lu/%.16s\n", (unsigned long)st
.st_ex_uid
, user
,
852 (unsigned long)st
.st_ex_gid
, group
);
853 tmp_time
= convert_timespec_to_time_t(st
.st_ex_atime
);
854 printf(" Access: %s", ctime(&tmp_time
));
855 tmp_time
= convert_timespec_to_time_t(st
.st_ex_mtime
);
856 printf(" Modify: %s", ctime(&tmp_time
));
857 tmp_time
= convert_timespec_to_time_t(st
.st_ex_ctime
);
858 printf(" Change: %s", ctime(&tmp_time
));
864 static NTSTATUS
cmd_chmod(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
866 struct smb_filename
*smb_fname
= NULL
;
869 printf("Usage: chmod <path> <mode>\n");
873 mode
= atoi(argv
[2]);
875 smb_fname
= synthetic_smb_fname(talloc_tos(),
880 if (smb_fname
== NULL
) {
881 return NT_STATUS_NO_MEMORY
;
884 if (SMB_VFS_CHMOD(vfs
->conn
, smb_fname
, mode
) == -1) {
885 printf("chmod: error=%d (%s)\n", errno
, strerror(errno
));
886 return NT_STATUS_UNSUCCESSFUL
;
889 printf("chmod: ok\n");
894 static NTSTATUS
cmd_fchmod(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
899 printf("Usage: fchmod <fd> <mode>\n");
904 mode
= atoi(argv
[2]);
905 if (fd
< 0 || fd
>= 1024) {
906 printf("fchmod: error=%d (file descriptor out of range)\n", EBADF
);
909 if (vfs
->files
[fd
] == NULL
) {
910 printf("fchmod: error=%d (invalid file descriptor)\n", EBADF
);
914 if (SMB_VFS_FCHMOD(vfs
->files
[fd
], mode
) == -1) {
915 printf("fchmod: error=%d (%s)\n", errno
, strerror(errno
));
916 return NT_STATUS_UNSUCCESSFUL
;
919 printf("fchmod: ok\n");
924 static NTSTATUS
cmd_chmod_acl(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
926 struct smb_filename
*smb_fname
= NULL
;
929 printf("Usage: chmod_acl <path> <mode>\n");
933 mode
= atoi(argv
[2]);
935 smb_fname
= synthetic_smb_fname(talloc_tos(),
940 if (smb_fname
== NULL
) {
941 return NT_STATUS_NO_MEMORY
;
944 if (SMB_VFS_CHMOD_ACL(vfs
->conn
, smb_fname
, mode
) == -1) {
945 printf("chmod_acl: error=%d (%s)\n", errno
, strerror(errno
));
946 return NT_STATUS_UNSUCCESSFUL
;
949 printf("chmod_acl: ok\n");
954 static NTSTATUS
cmd_fchmod_acl(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
959 printf("Usage: fchmod_acl <fd> <mode>\n");
964 mode
= atoi(argv
[2]);
965 if (fd
< 0 || fd
>= 1024) {
966 printf("fchmod_acl: error=%d (file descriptor out of range)\n", EBADF
);
969 if (vfs
->files
[fd
] == NULL
) {
970 printf("fchmod_acl: error=%d (invalid file descriptor)\n", EBADF
);
974 if (SMB_VFS_FCHMOD_ACL(vfs
->files
[fd
], mode
) == -1) {
975 printf("fchmod_acl: error=%d (%s)\n", errno
, strerror(errno
));
976 return NT_STATUS_UNSUCCESSFUL
;
979 printf("fchmod_acl: ok\n");
984 static NTSTATUS
cmd_chown(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
986 struct smb_filename
*smb_fname
= NULL
;
990 printf("Usage: chown <path> <uid> <gid>\n");
997 smb_fname
= synthetic_smb_fname(talloc_tos(),
1002 if (smb_fname
== NULL
) {
1003 return NT_STATUS_NO_MEMORY
;
1006 if (SMB_VFS_CHOWN(vfs
->conn
, smb_fname
, uid
, gid
) == -1) {
1007 printf("chown: error=%d (%s)\n", errno
, strerror(errno
));
1008 return NT_STATUS_UNSUCCESSFUL
;
1011 printf("chown: ok\n");
1012 return NT_STATUS_OK
;
1016 static NTSTATUS
cmd_fchown(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
1022 printf("Usage: fchown <fd> <uid> <gid>\n");
1023 return NT_STATUS_OK
;
1026 uid
= atoi(argv
[2]);
1027 gid
= atoi(argv
[3]);
1029 if (fd
< 0 || fd
>= 1024) {
1030 printf("fchown: faliure=%d (file descriptor out of range)\n", EBADF
);
1031 return NT_STATUS_OK
;
1033 if (vfs
->files
[fd
] == NULL
) {
1034 printf("fchown: error=%d (invalid file descriptor)\n", EBADF
);
1035 return NT_STATUS_OK
;
1037 if (SMB_VFS_FCHOWN(vfs
->files
[fd
], uid
, gid
) == -1) {
1038 printf("fchown error=%d (%s)\n", errno
, strerror(errno
));
1039 return NT_STATUS_UNSUCCESSFUL
;
1042 printf("fchown: ok\n");
1043 return NT_STATUS_OK
;
1047 static NTSTATUS
cmd_getwd(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
1049 char *buf
= SMB_VFS_GETWD(vfs
->conn
);
1051 printf("getwd: error=%d (%s)\n", errno
, strerror(errno
));
1052 return NT_STATUS_UNSUCCESSFUL
;
1055 printf("getwd: %s\n", buf
);
1057 return NT_STATUS_OK
;
1060 static NTSTATUS
cmd_utime(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
1062 struct smb_file_time ft
;
1063 struct smb_filename
*smb_fname
= NULL
;
1066 printf("Usage: utime <path> <access> <modify>\n");
1067 return NT_STATUS_OK
;
1072 ft
.atime
= convert_time_t_to_timespec(atoi(argv
[2]));
1073 ft
.mtime
= convert_time_t_to_timespec(atoi(argv
[3]));
1075 smb_fname
= synthetic_smb_fname_split(mem_ctx
,
1077 lp_posix_pathnames());
1078 if (smb_fname
== NULL
) {
1079 return NT_STATUS_NO_MEMORY
;
1082 if (SMB_VFS_NTIMES(vfs
->conn
, smb_fname
, &ft
) != 0) {
1083 printf("utime: error=%d (%s)\n", errno
, strerror(errno
));
1084 TALLOC_FREE(smb_fname
);
1085 return NT_STATUS_UNSUCCESSFUL
;
1088 TALLOC_FREE(smb_fname
);
1089 printf("utime: ok\n");
1090 return NT_STATUS_OK
;
1093 static NTSTATUS
cmd_ftruncate(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
1098 printf("Usage: ftruncate <fd> <length>\n");
1099 return NT_STATUS_OK
;
1103 off
= atoi(argv
[2]);
1104 if (fd
< 0 || fd
>= 1024) {
1105 printf("ftruncate: error=%d (file descriptor out of range)\n", EBADF
);
1106 return NT_STATUS_OK
;
1108 if (vfs
->files
[fd
] == NULL
) {
1109 printf("ftruncate: error=%d (invalid file descriptor)\n", EBADF
);
1110 return NT_STATUS_OK
;
1113 if (SMB_VFS_FTRUNCATE(vfs
->files
[fd
], off
) == -1) {
1114 printf("ftruncate: error=%d (%s)\n", errno
, strerror(errno
));
1115 return NT_STATUS_UNSUCCESSFUL
;
1118 printf("ftruncate: ok\n");
1119 return NT_STATUS_OK
;
1122 static NTSTATUS
cmd_lock(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
1129 const char *typestr
;
1132 printf("Usage: lock <fd> <op> <offset> <count> <type>\n");
1133 printf(" ops: G = F_GETLK\n");
1134 printf(" S = F_SETLK\n");
1135 printf(" W = F_SETLKW\n");
1136 printf(" type: R = F_RDLCK\n");
1137 printf(" W = F_WRLCK\n");
1138 printf(" U = F_UNLCK\n");
1139 return NT_STATUS_OK
;
1142 if (sscanf(argv
[1], "%d", &fd
) == 0) {
1143 printf("lock: error=-1 (error parsing fd)\n");
1144 return NT_STATUS_UNSUCCESSFUL
;
1159 printf("lock: error=-1 (invalid op flag!)\n");
1160 return NT_STATUS_UNSUCCESSFUL
;
1163 if (sscanf(argv
[3], "%ld", &offset
) == 0) {
1164 printf("lock: error=-1 (error parsing fd)\n");
1165 return NT_STATUS_UNSUCCESSFUL
;
1168 if (sscanf(argv
[4], "%ld", &count
) == 0) {
1169 printf("lock: error=-1 (error parsing fd)\n");
1170 return NT_STATUS_UNSUCCESSFUL
;
1187 printf("lock: error=-1 (invalid type flag!)\n");
1188 return NT_STATUS_UNSUCCESSFUL
;
1193 printf("lock: debug lock(fd=%d, op=%d, offset=%ld, count=%ld, type=%d))\n", fd
, op
, offset
, count
, type
);
1195 if (SMB_VFS_LOCK(vfs
->files
[fd
], op
, offset
, count
, type
) == False
) {
1196 printf("lock: error=%d (%s)\n", errno
, strerror(errno
));
1197 return NT_STATUS_UNSUCCESSFUL
;
1200 printf("lock: ok\n");
1201 return NT_STATUS_OK
;
1204 static NTSTATUS
cmd_symlink(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
1207 printf("Usage: symlink <path> <link>\n");
1208 return NT_STATUS_OK
;
1211 if (SMB_VFS_SYMLINK(vfs
->conn
, argv
[1], argv
[2]) == -1) {
1212 printf("symlink: error=%d (%s)\n", errno
, strerror(errno
));
1213 return NT_STATUS_UNSUCCESSFUL
;
1216 printf("symlink: ok\n");
1217 return NT_STATUS_OK
;
1221 static NTSTATUS
cmd_readlink(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
1223 char buffer
[PATH_MAX
];
1227 printf("Usage: readlink <path>\n");
1228 return NT_STATUS_OK
;
1231 if ((size
= SMB_VFS_READLINK(vfs
->conn
, argv
[1], buffer
, PATH_MAX
)) == -1) {
1232 printf("readlink: error=%d (%s)\n", errno
, strerror(errno
));
1233 return NT_STATUS_UNSUCCESSFUL
;
1236 buffer
[size
] = '\0';
1237 printf("readlink: %s\n", buffer
);
1238 return NT_STATUS_OK
;
1242 static NTSTATUS
cmd_link(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
1245 printf("Usage: link <path> <link>\n");
1246 return NT_STATUS_OK
;
1249 if (SMB_VFS_LINK(vfs
->conn
, argv
[1], argv
[2]) == -1) {
1250 printf("link: error=%d (%s)\n", errno
, strerror(errno
));
1251 return NT_STATUS_UNSUCCESSFUL
;
1254 printf("link: ok\n");
1255 return NT_STATUS_OK
;
1258 static NTSTATUS
cmd_mknod(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
1261 unsigned int dev_val
;
1263 struct smb_filename
*smb_fname
= NULL
;
1266 printf("Usage: mknod <path> <mode> <dev>\n");
1267 printf(" mode is octal\n");
1268 printf(" dev is hex\n");
1269 return NT_STATUS_OK
;
1272 if (sscanf(argv
[2], "%ho", (unsigned short *)&mode
) == 0) {
1273 printf("open: error=-1 (invalid mode!)\n");
1274 return NT_STATUS_UNSUCCESSFUL
;
1277 if (sscanf(argv
[3], "%x", &dev_val
) == 0) {
1278 printf("open: error=-1 (invalid dev!)\n");
1279 return NT_STATUS_UNSUCCESSFUL
;
1281 dev
= (SMB_DEV_T
)dev_val
;
1283 smb_fname
= synthetic_smb_fname_split(mem_ctx
,
1285 lp_posix_pathnames());
1286 if (smb_fname
== NULL
) {
1287 return NT_STATUS_NO_MEMORY
;
1289 if (SMB_VFS_MKNOD(vfs
->conn
, smb_fname
, mode
, dev
) == -1) {
1290 printf("mknod: error=%d (%s)\n", errno
, strerror(errno
));
1291 return NT_STATUS_UNSUCCESSFUL
;
1294 printf("mknod: ok\n");
1295 return NT_STATUS_OK
;
1298 static NTSTATUS
cmd_realpath(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
1301 printf("Usage: realpath <path>\n");
1302 return NT_STATUS_OK
;
1305 if (SMB_VFS_REALPATH(vfs
->conn
, argv
[1]) == NULL
) {
1306 printf("realpath: error=%d (%s)\n", errno
, strerror(errno
));
1307 return NT_STATUS_UNSUCCESSFUL
;
1310 printf("realpath: ok\n");
1311 return NT_STATUS_OK
;
1314 static NTSTATUS
cmd_getxattr(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
,
1315 int argc
, const char **argv
)
1319 struct smb_filename
*smb_fname
= NULL
;
1322 printf("Usage: getxattr <path> <xattr>\n");
1323 return NT_STATUS_OK
;
1328 smb_fname
= synthetic_smb_fname_split(mem_ctx
,
1330 lp_posix_pathnames());
1331 if (smb_fname
== NULL
) {
1332 return NT_STATUS_NO_MEMORY
;
1334 ret
= SMB_VFS_GETXATTR(vfs
->conn
, smb_fname
, argv
[2], buf
,
1335 talloc_get_size(buf
));
1338 printf("getxattr returned (%s)\n", strerror(err
));
1339 return map_nt_error_from_unix(err
);
1341 buf
= talloc_array(mem_ctx
, uint8_t, ret
);
1343 return NT_STATUS_NO_MEMORY
;
1345 ret
= SMB_VFS_GETXATTR(vfs
->conn
, smb_fname
, argv
[2], buf
,
1346 talloc_get_size(buf
));
1349 printf("getxattr returned (%s)\n", strerror(err
));
1350 return map_nt_error_from_unix(err
);
1352 dump_data_file(buf
, talloc_get_size(buf
), false, stdout
);
1353 return NT_STATUS_OK
;
1356 static NTSTATUS
cmd_listxattr(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
,
1357 int argc
, const char **argv
)
1361 struct smb_filename
*smb_fname
= NULL
;
1364 printf("Usage: listxattr <path>\n");
1365 return NT_STATUS_OK
;
1370 smb_fname
= synthetic_smb_fname_split(mem_ctx
,
1372 lp_posix_pathnames());
1373 if (smb_fname
== NULL
) {
1374 return NT_STATUS_NO_MEMORY
;
1376 ret
= SMB_VFS_LISTXATTR(vfs
->conn
, smb_fname
,
1377 buf
, talloc_get_size(buf
));
1380 printf("listxattr returned (%s)\n", strerror(err
));
1381 return map_nt_error_from_unix(err
);
1383 buf
= talloc_array(mem_ctx
, char, ret
);
1385 return NT_STATUS_NO_MEMORY
;
1387 ret
= SMB_VFS_LISTXATTR(vfs
->conn
, smb_fname
,
1388 buf
, talloc_get_size(buf
));
1391 printf("listxattr returned (%s)\n", strerror(err
));
1392 return map_nt_error_from_unix(err
);
1395 return NT_STATUS_OK
;
1397 if (buf
[ret
-1] != '\0') {
1398 printf("listxattr returned non 0-terminated strings\n");
1399 return NT_STATUS_INTERNAL_ERROR
;
1403 while (p
< buf
+ret
) {
1408 return NT_STATUS_OK
;
1411 static NTSTATUS
cmd_setxattr(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
,
1412 int argc
, const char **argv
)
1416 struct smb_filename
*smb_fname
= NULL
;
1418 if ((argc
< 4) || (argc
> 5)) {
1419 printf("Usage: setxattr <path> <xattr> <value> [flags]\n");
1420 return NT_STATUS_OK
;
1424 flags
= atoi(argv
[4]);
1427 smb_fname
= synthetic_smb_fname_split(mem_ctx
,
1429 lp_posix_pathnames());
1430 if (smb_fname
== NULL
) {
1431 return NT_STATUS_NO_MEMORY
;
1433 ret
= SMB_VFS_SETXATTR(vfs
->conn
, smb_fname
, argv
[2],
1434 argv
[3], strlen(argv
[3]), flags
);
1437 printf("setxattr returned (%s)\n", strerror(err
));
1438 return map_nt_error_from_unix(err
);
1440 return NT_STATUS_OK
;
1443 static NTSTATUS
cmd_removexattr(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
,
1444 int argc
, const char **argv
)
1447 struct smb_filename
*smb_fname
= NULL
;
1450 printf("Usage: removexattr <path> <xattr>\n");
1451 return NT_STATUS_OK
;
1454 smb_fname
= synthetic_smb_fname(talloc_tos(),
1460 if (smb_fname
== NULL
) {
1461 return NT_STATUS_NO_MEMORY
;
1464 ret
= SMB_VFS_REMOVEXATTR(vfs
->conn
, smb_fname
, argv
[2]);
1467 printf("removexattr returned (%s)\n", strerror(err
));
1468 return map_nt_error_from_unix(err
);
1470 return NT_STATUS_OK
;
1473 static NTSTATUS
cmd_fget_nt_acl(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
,
1474 int argc
, const char **argv
)
1478 struct security_descriptor
*sd
;
1481 printf("Usage: fget_nt_acl <fd>\n");
1482 return NT_STATUS_OK
;
1486 if (fd
< 0 || fd
>= 1024) {
1487 printf("fget_nt_acl: error=%d (file descriptor out of range)\n", EBADF
);
1488 return NT_STATUS_OK
;
1490 if (vfs
->files
[fd
] == NULL
) {
1491 printf("fget_nt_acl: error=%d (invalid file descriptor)\n", EBADF
);
1492 return NT_STATUS_OK
;
1495 status
= SMB_VFS_FGET_NT_ACL(vfs
->files
[fd
],
1496 SECINFO_OWNER
| SECINFO_GROUP
| SECINFO_DACL
,
1498 if (!NT_STATUS_IS_OK(status
)) {
1499 printf("fget_nt_acl returned (%s)\n", nt_errstr(status
));
1502 printf("%s\n", sddl_encode(talloc_tos(), sd
, get_global_sam_sid()));
1504 return NT_STATUS_OK
;
1507 static NTSTATUS
cmd_get_nt_acl(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
,
1508 int argc
, const char **argv
)
1511 struct security_descriptor
*sd
;
1512 struct smb_filename
*smb_fname
= NULL
;
1515 printf("Usage: get_nt_acl <path>\n");
1516 return NT_STATUS_OK
;
1519 smb_fname
= synthetic_smb_fname(talloc_tos(),
1525 if (smb_fname
== NULL
) {
1526 return NT_STATUS_NO_MEMORY
;
1529 status
= SMB_VFS_GET_NT_ACL(vfs
->conn
, smb_fname
,
1530 SECINFO_OWNER
| SECINFO_GROUP
| SECINFO_DACL
,
1532 if (!NT_STATUS_IS_OK(status
)) {
1533 printf("get_nt_acl returned (%s)\n", nt_errstr(status
));
1536 printf("%s\n", sddl_encode(talloc_tos(), sd
, get_global_sam_sid()));
1538 return NT_STATUS_OK
;
1541 static NTSTATUS
cmd_fset_nt_acl(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
,
1542 int argc
, const char **argv
)
1546 struct security_descriptor
*sd
;
1549 printf("Usage: fset_nt_acl <fd> <sddl>\n");
1550 return NT_STATUS_OK
;
1554 if (fd
< 0 || fd
>= 1024) {
1555 printf("fset_nt_acl: error=%d (file descriptor out of range)\n", EBADF
);
1556 return NT_STATUS_OK
;
1558 if (vfs
->files
[fd
] == NULL
) {
1559 printf("fset_nt_acl: error=%d (invalid file descriptor)\n", EBADF
);
1560 return NT_STATUS_OK
;
1563 sd
= sddl_decode(talloc_tos(), argv
[2], get_global_sam_sid());
1565 printf("sddl_decode failed to parse %s as SDDL\n", argv
[2]);
1566 return NT_STATUS_INVALID_PARAMETER
;
1569 status
= SMB_VFS_FSET_NT_ACL(vfs
->files
[fd
], SECINFO_OWNER
| SECINFO_GROUP
| SECINFO_DACL
, sd
);
1570 if (!NT_STATUS_IS_OK(status
)) {
1571 printf("fset_nt_acl returned (%s)\n", nt_errstr(status
));
1575 return NT_STATUS_OK
;
1578 static NTSTATUS
cmd_set_nt_acl(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
1584 struct smb_filename
*smb_fname
= NULL
;
1586 struct security_descriptor
*sd
= NULL
;
1589 printf("Usage: set_nt_acl <file> <sddl>\n");
1590 return NT_STATUS_OK
;
1595 fsp
= talloc_zero(vfs
, struct files_struct
);
1597 return NT_STATUS_NO_MEMORY
;
1599 fsp
->fh
= talloc_zero(fsp
, struct fd_handle
);
1600 if (fsp
->fh
== NULL
) {
1602 return NT_STATUS_NO_MEMORY
;
1604 fsp
->conn
= vfs
->conn
;
1606 smb_fname
= synthetic_smb_fname_split(NULL
,
1608 lp_posix_pathnames());
1609 if (smb_fname
== NULL
) {
1611 return NT_STATUS_NO_MEMORY
;
1614 fsp
->fsp_name
= smb_fname
;
1617 flags
= O_RDONLY
|O_DIRECTORY
;
1619 /* POSIX allows us to open a directory with O_RDONLY. */
1623 fsp
->fh
->fd
= SMB_VFS_OPEN(vfs
->conn
, smb_fname
, fsp
, O_RDWR
, mode
);
1624 if (fsp
->fh
->fd
== -1 && errno
== EISDIR
) {
1625 fsp
->fh
->fd
= SMB_VFS_OPEN(vfs
->conn
, smb_fname
, fsp
, flags
, mode
);
1627 if (fsp
->fh
->fd
== -1) {
1628 printf("open: error=%d (%s)\n", errno
, strerror(errno
));
1630 TALLOC_FREE(smb_fname
);
1631 return NT_STATUS_UNSUCCESSFUL
;
1634 status
= NT_STATUS_OK
;
1635 ret
= SMB_VFS_FSTAT(fsp
, &smb_fname
->st
);
1637 /* If we have an fd, this stat should succeed. */
1638 DEBUG(0,("Error doing fstat on open file %s "
1640 smb_fname_str_dbg(smb_fname
),
1642 status
= map_nt_error_from_unix(errno
);
1645 if (!NT_STATUS_IS_OK(status
)) {
1649 fsp
->file_id
= vfs_file_id_from_sbuf(vfs
->conn
, &smb_fname
->st
);
1650 fsp
->vuid
= UID_FIELD_INVALID
;
1652 fsp
->can_lock
= True
;
1653 fsp
->can_read
= True
;
1654 fsp
->can_write
= True
;
1655 fsp
->print_file
= NULL
;
1656 fsp
->modified
= False
;
1657 fsp
->sent_oplock_break
= NO_BREAK_SENT
;
1658 fsp
->is_directory
= S_ISDIR(smb_fname
->st
.st_ex_mode
);
1661 sd
= sddl_decode(talloc_tos(), argv
[2], get_global_sam_sid());
1663 printf("sddl_decode failed to parse %s as SDDL\n", argv
[2]);
1664 status
= NT_STATUS_INVALID_PARAMETER
;
1668 status
= SMB_VFS_FSET_NT_ACL(fsp
, SECINFO_OWNER
| SECINFO_GROUP
| SECINFO_DACL
, sd
);
1669 if (!NT_STATUS_IS_OK(status
)) {
1670 printf("fset_nt_acl returned (%s)\n", nt_errstr(status
));
1676 ret
= SMB_VFS_CLOSE(fsp
);
1678 printf("close: error=%d (%s)\n", errno
, strerror(errno
));
1687 static NTSTATUS
cmd_sys_acl_get_fd(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
,
1688 int argc
, const char **argv
)
1695 printf("Usage: sys_acl_get_fd <fd>\n");
1696 return NT_STATUS_OK
;
1700 if (fd
< 0 || fd
>= 1024) {
1701 printf("sys_acl_get_fd: error=%d (file descriptor out of range)\n", EBADF
);
1702 return NT_STATUS_OK
;
1704 if (vfs
->files
[fd
] == NULL
) {
1705 printf("sys_acl_get_fd: error=%d (invalid file descriptor)\n", EBADF
);
1706 return NT_STATUS_OK
;
1709 acl
= SMB_VFS_SYS_ACL_GET_FD(vfs
->files
[fd
], talloc_tos());
1711 printf("sys_acl_get_fd failed (%s)\n", strerror(errno
));
1712 return NT_STATUS_UNSUCCESSFUL
;
1714 acl_text
= sys_acl_to_text(acl
, NULL
);
1715 printf("%s", acl_text
);
1717 SAFE_FREE(acl_text
);
1718 return NT_STATUS_OK
;
1721 static NTSTATUS
cmd_sys_acl_get_file(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
,
1722 int argc
, const char **argv
)
1727 struct smb_filename
*smb_fname
= NULL
;
1730 printf("Usage: sys_acl_get_file <path> <type>\n");
1731 return NT_STATUS_OK
;
1734 smb_fname
= synthetic_smb_fname_split(talloc_tos(),
1736 lp_posix_pathnames());
1737 if (smb_fname
== NULL
) {
1738 return NT_STATUS_NO_MEMORY
;
1740 type
= atoi(argv
[2]);
1741 acl
= SMB_VFS_SYS_ACL_GET_FILE(vfs
->conn
, smb_fname
,
1742 type
, talloc_tos());
1744 printf("sys_acl_get_file failed (%s)\n", strerror(errno
));
1745 return NT_STATUS_UNSUCCESSFUL
;
1747 acl_text
= sys_acl_to_text(acl
, NULL
);
1748 printf("%s", acl_text
);
1750 SAFE_FREE(acl_text
);
1751 return NT_STATUS_OK
;
1754 static NTSTATUS
cmd_sys_acl_blob_get_file(struct vfs_state
*vfs
,
1755 TALLOC_CTX
*mem_ctx
,
1756 int argc
, const char **argv
)
1762 struct smb_filename
*smb_fname
= NULL
;
1765 printf("Usage: sys_acl_get_file <path>\n");
1766 return NT_STATUS_OK
;
1769 smb_fname
= synthetic_smb_fname_split(talloc_tos(),
1771 lp_posix_pathnames());
1772 if (smb_fname
== NULL
) {
1773 return NT_STATUS_NO_MEMORY
;
1775 ret
= SMB_VFS_SYS_ACL_BLOB_GET_FILE(vfs
->conn
, smb_fname
, talloc_tos(),
1776 &description
, &blob
);
1778 printf("sys_acl_blob_get_file failed (%s)\n", strerror(errno
));
1779 return map_nt_error_from_unix(errno
);
1781 printf("Description: %s\n", description
);
1782 for (i
= 0; i
< blob
.length
; i
++) {
1783 printf("%.2x ", blob
.data
[i
]);
1787 return NT_STATUS_OK
;
1790 static NTSTATUS
cmd_sys_acl_blob_get_fd(struct vfs_state
*vfs
,
1791 TALLOC_CTX
*mem_ctx
,
1792 int argc
, const char **argv
)
1801 printf("Usage: sys_acl_blob_get_fd <fd>\n");
1802 return NT_STATUS_OK
;
1806 if (fd
< 0 || fd
>= 1024) {
1807 printf("sys_acl_blob_get_fd: error=%d "
1808 "(file descriptor out of range)\n", EBADF
);
1809 return NT_STATUS_OK
;
1811 if (vfs
->files
[fd
] == NULL
) {
1812 printf("sys_acl_blob_get_fd: error=%d "
1813 "(invalid file descriptor)\n", EBADF
);
1814 return NT_STATUS_OK
;
1817 ret
= SMB_VFS_SYS_ACL_BLOB_GET_FD(vfs
->files
[fd
], talloc_tos(),
1818 &description
, &blob
);
1820 printf("sys_acl_blob_get_fd failed (%s)\n", strerror(errno
));
1821 return map_nt_error_from_unix(errno
);
1823 printf("Description: %s\n", description
);
1824 for (i
= 0; i
< blob
.length
; i
++) {
1825 printf("%.2x ", blob
.data
[i
]);
1829 return NT_STATUS_OK
;
1834 static NTSTATUS
cmd_sys_acl_delete_def_file(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
,
1835 int argc
, const char **argv
)
1838 struct smb_filename
*smb_fname
= NULL
;
1841 printf("Usage: sys_acl_delete_def_file <path>\n");
1842 return NT_STATUS_OK
;
1845 smb_fname
= synthetic_smb_fname(talloc_tos(),
1851 if (smb_fname
== NULL
) {
1852 return NT_STATUS_NO_MEMORY
;
1854 ret
= SMB_VFS_SYS_ACL_DELETE_DEF_FILE(vfs
->conn
, smb_fname
);
1856 printf("sys_acl_delete_def_file failed (%s)\n", strerror(errno
));
1857 TALLOC_FREE(smb_fname
);
1858 return NT_STATUS_UNSUCCESSFUL
;
1860 TALLOC_FREE(smb_fname
);
1861 return NT_STATUS_OK
;
1864 /* Afaik translate name was first introduced with vfs_catia, to be able
1865 to translate unix file/dir-names, containing invalid windows characters,
1866 to valid windows names.
1867 The used translation direction is always unix --> windows
1869 static NTSTATUS
cmd_translate_name(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
,
1870 int argc
, const char **argv
)
1873 struct dirent
*dent
= NULL
;
1876 char *translated
= NULL
;
1877 struct smb_filename
*smb_fname
= NULL
;
1881 DEBUG(0, ("Usage: translate_name unix_filename\n"));
1882 return NT_STATUS_UNSUCCESSFUL
;
1885 smb_fname
= synthetic_smb_fname(talloc_tos(),
1890 if (smb_fname
== NULL
) {
1891 return NT_STATUS_NO_MEMORY
;
1894 vfs
->currentdir
= SMB_VFS_OPENDIR(vfs
->conn
, smb_fname
, NULL
, 0);
1895 if (vfs
->currentdir
== NULL
) {
1896 DEBUG(0, ("cmd_translate_name: opendir error=%d (%s)\n",
1897 errno
, strerror(errno
)));
1898 TALLOC_FREE(smb_fname
);
1899 return NT_STATUS_UNSUCCESSFUL
;
1903 dent
= SMB_VFS_READDIR(vfs
->conn
, vfs
->currentdir
, &st
);
1907 if (strcmp (dent
->d_name
, argv
[1]) == 0) {
1914 DEBUG(0, ("cmd_translate_name: file '%s' not found.\n",
1916 status
= NT_STATUS_UNSUCCESSFUL
;
1919 status
= SMB_VFS_TRANSLATE_NAME(vfs
->conn
, dent
->d_name
,
1920 vfs_translate_to_windows
,
1921 talloc_tos(), &translated
);
1922 if (NT_STATUS_EQUAL(status
, NT_STATUS_NONE_MAPPED
)) {
1923 DEBUG(0, ("cmd_translate_name: file '%s' cannot be "
1924 "translated\n", argv
[1]));
1925 TALLOC_FREE(translated
);
1928 /* translation success. But that could also mean
1929 that translating "aaa" to "aaa" was successful :-(
1931 DEBUG(0, ("cmd_translate_name: file '%s' --> '%s'\n",
1932 argv
[1], translated
));
1934 TALLOC_FREE(smb_fname
);
1935 TALLOC_FREE(translated
);
1938 TALLOC_FREE(smb_fname
);
1939 ret
= SMB_VFS_CLOSEDIR(vfs
->conn
, vfs
->currentdir
);
1941 DEBUG(0, ("cmd_translate_name: closedir failure: %s\n",
1943 return NT_STATUS_UNSUCCESSFUL
;
1946 vfs
->currentdir
= NULL
;
1951 struct cmd_set vfs_commands
[] = {
1955 { "load", cmd_load_module
, "Load a module", "load <module.so>" },
1956 { "populate", cmd_populate
, "Populate a data buffer", "populate <char> <size>" },
1957 { "showdata", cmd_show_data
, "Show data currently in data buffer", "show_data [<offset> <len>]"},
1958 { "connect", cmd_connect
, "VFS connect()", "connect" },
1959 { "disconnect", cmd_disconnect
, "VFS disconnect()", "disconnect" },
1960 { "disk_free", cmd_disk_free
, "VFS disk_free()", "disk_free <path>" },
1961 { "opendir", cmd_opendir
, "VFS opendir()", "opendir <fname>" },
1962 { "readdir", cmd_readdir
, "VFS readdir()", "readdir" },
1963 { "mkdir", cmd_mkdir
, "VFS mkdir()", "mkdir <path>" },
1964 { "rmdir", cmd_pathfunc
, "VFS rmdir()", "rmdir <path>" },
1965 { "closedir", cmd_closedir
, "VFS closedir()", "closedir" },
1966 { "open", cmd_open
, "VFS open()", "open <fname> <flags> <mode>" },
1967 { "close", cmd_close
, "VFS close()", "close <fd>" },
1968 { "read", cmd_read
, "VFS read()", "read <fd> <size>" },
1969 { "write", cmd_write
, "VFS write()", "write <fd> <size>" },
1970 { "lseek", cmd_lseek
, "VFS lseek()", "lseek <fd> <offset> <whence>" },
1971 { "rename", cmd_rename
, "VFS rename()", "rename <old> <new>" },
1972 { "fsync", cmd_fsync
, "VFS fsync()", "fsync <fd>" },
1973 { "stat", cmd_stat
, "VFS stat()", "stat <fname>" },
1974 { "fstat", cmd_fstat
, "VFS fstat()", "fstat <fd>" },
1975 { "lstat", cmd_lstat
, "VFS lstat()", "lstat <fname>" },
1976 { "unlink", cmd_pathfunc
, "VFS unlink()", "unlink <fname>" },
1977 { "chmod", cmd_chmod
, "VFS chmod()", "chmod <path> <mode>" },
1978 { "fchmod", cmd_fchmod
, "VFS fchmod()", "fchmod <fd> <mode>" },
1979 { "chown", cmd_chown
, "VFS chown()", "chown <path> <uid> <gid>" },
1980 { "fchown", cmd_fchown
, "VFS fchown()", "fchown <fd> <uid> <gid>" },
1981 { "chdir", cmd_pathfunc
, "VFS chdir()", "chdir <path>" },
1982 { "getwd", cmd_getwd
, "VFS getwd()", "getwd" },
1983 { "utime", cmd_utime
, "VFS utime()", "utime <path> <access> <modify>" },
1984 { "ftruncate", cmd_ftruncate
, "VFS ftruncate()", "ftruncate <fd> <length>" },
1985 { "lock", cmd_lock
, "VFS lock()", "lock <f> <op> <offset> <count> <type>" },
1986 { "symlink", cmd_symlink
, "VFS symlink()", "symlink <old> <new>" },
1987 { "readlink", cmd_readlink
, "VFS readlink()", "readlink <path>" },
1988 { "link", cmd_link
, "VFS link()", "link <oldpath> <newpath>" },
1989 { "mknod", cmd_mknod
, "VFS mknod()", "mknod <path> <mode> <dev>" },
1990 { "realpath", cmd_realpath
, "VFS realpath()", "realpath <path>" },
1991 { "getxattr", cmd_getxattr
, "VFS getxattr()",
1992 "getxattr <path> <name>" },
1993 { "listxattr", cmd_listxattr
, "VFS listxattr()",
1994 "listxattr <path>" },
1995 { "setxattr", cmd_setxattr
, "VFS setxattr()",
1996 "setxattr <path> <name> <value> [<flags>]" },
1997 { "removexattr", cmd_removexattr
, "VFS removexattr()",
1998 "removexattr <path> <name>\n" },
1999 { "fget_nt_acl", cmd_fget_nt_acl
, "VFS fget_nt_acl()",
2000 "fget_nt_acl <fd>\n" },
2001 { "get_nt_acl", cmd_get_nt_acl
, "VFS get_nt_acl()",
2002 "get_nt_acl <path>\n" },
2003 { "fset_nt_acl", cmd_fset_nt_acl
, "VFS fset_nt_acl()",
2004 "fset_nt_acl <fd>\n" },
2005 { "set_nt_acl", cmd_set_nt_acl
, "VFS open() and fset_nt_acl()",
2006 "set_nt_acl <file>\n" },
2007 { "fchmod_acl", cmd_fchmod_acl
, "VFS fchmod_acl()", "fchmod_acl <fd> <mode>" },
2008 { "chmod_acl", cmd_chmod_acl
, "VFS chmod_acl()", "chmod_acl <path> <mode>" },
2009 { "sys_acl_get_file", cmd_sys_acl_get_file
, "VFS sys_acl_get_file()", "sys_acl_get_file <path>" },
2010 { "sys_acl_get_fd", cmd_sys_acl_get_fd
, "VFS sys_acl_get_fd()", "sys_acl_get_fd <fd>" },
2011 { "sys_acl_blob_get_file", cmd_sys_acl_blob_get_file
,
2012 "VFS sys_acl_blob_get_file()", "sys_acl_blob_get_file <path>" },
2013 { "sys_acl_blob_get_fd", cmd_sys_acl_blob_get_fd
,
2014 "VFS sys_acl_blob_get_fd()", "sys_acl_blob_get_fd <path>" },
2015 { "sys_acl_delete_def_file", cmd_sys_acl_delete_def_file
, "VFS sys_acl_delete_def_file()", "sys_acl_delete_def_file <path>" },
2018 { "test_chain", cmd_test_chain
, "test chain code",
2020 { "translate_name", cmd_translate_name
, "VFS translate_name()", "translate_name unix_filename" },