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"
29 static const char *null_string
= "";
31 static NTSTATUS
cmd_load_module(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
36 printf("Usage: load <modules>\n");
40 for (i
=argc
-1;i
>0;i
--) {
41 if (!vfs_init_custom(vfs
->conn
, argv
[i
])) {
42 DEBUG(0, ("load: (vfs_init_custom failed for %s)\n", argv
[i
]));
43 return NT_STATUS_UNSUCCESSFUL
;
50 static NTSTATUS
cmd_populate(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
55 printf("Usage: populate <char> <size>\n");
60 vfs
->data
= talloc_array(mem_ctx
, char, size
);
61 if (vfs
->data
== NULL
) {
62 printf("populate: error=-1 (not enough memory)");
63 return NT_STATUS_UNSUCCESSFUL
;
65 memset(vfs
->data
, c
, size
);
66 vfs
->data_size
= size
;
70 static NTSTATUS
cmd_show_data(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
74 if (argc
!= 1 && argc
!= 3) {
75 printf("Usage: showdata [<offset> <len>]\n");
78 if (vfs
->data
== NULL
|| vfs
->data_size
== 0) {
79 printf("show_data: error=-1 (buffer empty)\n");
80 return NT_STATUS_UNSUCCESSFUL
;
84 offset
= atoi(argv
[1]);
90 if ((offset
+ len
) > vfs
->data_size
) {
91 printf("show_data: error=-1 (not enough data in buffer)\n");
92 return NT_STATUS_UNSUCCESSFUL
;
94 dump_data(0, (uint8
*)(vfs
->data
) + offset
, len
);
98 static NTSTATUS
cmd_connect(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
100 SMB_VFS_CONNECT(vfs
->conn
, lp_servicename(SNUM(vfs
->conn
)), "vfstest");
104 static NTSTATUS
cmd_disconnect(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
106 SMB_VFS_DISCONNECT(vfs
->conn
);
110 static NTSTATUS
cmd_disk_free(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
112 uint64_t diskfree
, bsize
, dfree
, dsize
;
114 printf("Usage: disk_free <path>\n");
118 diskfree
= SMB_VFS_DISK_FREE(vfs
->conn
, argv
[1], False
, &bsize
, &dfree
, &dsize
);
119 printf("disk_free: %lu, bsize = %lu, dfree = %lu, dsize = %lu\n",
120 (unsigned long)diskfree
,
121 (unsigned long)bsize
,
122 (unsigned long)dfree
,
123 (unsigned long)dsize
);
128 static NTSTATUS
cmd_opendir(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
131 printf("Usage: opendir <fname>\n");
135 vfs
->currentdir
= SMB_VFS_OPENDIR(vfs
->conn
, argv
[1], NULL
, 0);
136 if (vfs
->currentdir
== NULL
) {
137 printf("opendir error=%d (%s)\n", errno
, strerror(errno
));
138 return NT_STATUS_UNSUCCESSFUL
;
141 printf("opendir: ok\n");
146 static NTSTATUS
cmd_readdir(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
149 SMB_STRUCT_DIRENT
*dent
= NULL
;
151 if (vfs
->currentdir
== NULL
) {
152 printf("readdir: error=-1 (no open directory)\n");
153 return NT_STATUS_UNSUCCESSFUL
;
156 dent
= SMB_VFS_READDIR(vfs
->conn
, vfs
->currentdir
, &st
);
158 printf("readdir: NULL\n");
162 printf("readdir: %s\n", dent
->d_name
);
163 if (VALID_STAT(st
)) {
165 printf(" stat available");
166 if (S_ISREG(st
.st_ex_mode
)) printf(" Regular File\n");
167 else if (S_ISDIR(st
.st_ex_mode
)) printf(" Directory\n");
168 else if (S_ISCHR(st
.st_ex_mode
)) printf(" Character Device\n");
169 else if (S_ISBLK(st
.st_ex_mode
)) printf(" Block Device\n");
170 else if (S_ISFIFO(st
.st_ex_mode
)) printf(" Fifo\n");
171 else if (S_ISLNK(st
.st_ex_mode
)) printf(" Symbolic Link\n");
172 else if (S_ISSOCK(st
.st_ex_mode
)) printf(" Socket\n");
173 printf(" Size: %10u", (unsigned int)st
.st_ex_size
);
174 #ifdef HAVE_STAT_ST_BLOCKS
175 printf(" Blocks: %9u", (unsigned int)st
.st_ex_blocks
);
177 #ifdef HAVE_STAT_ST_BLKSIZE
178 printf(" IO Block: %u\n", (unsigned int)st
.st_ex_blksize
);
180 printf(" Device: 0x%10x", (unsigned int)st
.st_ex_dev
);
181 printf(" Inode: %10u", (unsigned int)st
.st_ex_ino
);
182 printf(" Links: %10u\n", (unsigned int)st
.st_ex_nlink
);
183 printf(" Access: %05o", (int)((st
.st_ex_mode
) & 007777));
184 printf(" Uid: %5lu Gid: %5lu\n",
185 (unsigned long)st
.st_ex_uid
,
186 (unsigned long)st
.st_ex_gid
);
187 tmp_time
= convert_timespec_to_time_t(st
.st_ex_atime
);
188 printf(" Access: %s", ctime(&tmp_time
));
189 tmp_time
= convert_timespec_to_time_t(st
.st_ex_mtime
);
190 printf(" Modify: %s", ctime(&tmp_time
));
191 tmp_time
= convert_timespec_to_time_t(st
.st_ex_ctime
);
192 printf(" Change: %s", ctime(&tmp_time
));
199 static NTSTATUS
cmd_mkdir(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
202 printf("Usage: mkdir <path>\n");
206 if (SMB_VFS_MKDIR(vfs
->conn
, argv
[1], 00755) == -1) {
207 printf("mkdir error=%d (%s)\n", errno
, strerror(errno
));
208 return NT_STATUS_UNSUCCESSFUL
;
211 printf("mkdir: ok\n");
216 static NTSTATUS
cmd_closedir(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
220 if (vfs
->currentdir
== NULL
) {
221 printf("closedir: failure (no directory open)\n");
222 return NT_STATUS_UNSUCCESSFUL
;
225 ret
= SMB_VFS_CLOSEDIR(vfs
->conn
, vfs
->currentdir
);
227 printf("closedir failure: %s\n", strerror(errno
));
228 return NT_STATUS_UNSUCCESSFUL
;
231 printf("closedir: ok\n");
232 vfs
->currentdir
= NULL
;
237 static NTSTATUS
cmd_open(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
243 struct smb_filename
*smb_fname
= NULL
;
248 if (argc
< 3 || argc
> 5) {
249 printf("Usage: open <filename> <flags> <mode>\n");
250 printf(" flags: O = O_RDONLY\n");
251 printf(" R = O_RDWR\n");
252 printf(" W = O_WRONLY\n");
253 printf(" C = O_CREAT\n");
254 printf(" E = O_EXCL\n");
255 printf(" T = O_TRUNC\n");
256 printf(" A = O_APPEND\n");
257 printf(" N = O_NONBLOCK/O_NDELAY\n");
259 printf(" S = O_SYNC\n");
262 printf(" F = O_NOFOLLOW\n");
264 printf(" mode: see open.2\n");
265 printf(" mode is ignored if C flag not present\n");
266 printf(" mode defaults to 00400\n");
308 printf("open: error=-1 (invalid flag!)\n");
309 return NT_STATUS_UNSUCCESSFUL
;
313 if ((flags
& O_CREAT
) && argc
== 4) {
314 if (sscanf(argv
[3], "%ho", (unsigned short *)&mode
) == 0) {
315 printf("open: error=-1 (invalid mode!)\n");
316 return NT_STATUS_UNSUCCESSFUL
;
320 fsp
= SMB_MALLOC_P(struct files_struct
);
322 return NT_STATUS_NO_MEMORY
;
324 fsp
->fh
= SMB_MALLOC_P(struct fd_handle
);
325 if (fsp
->fh
== NULL
) {
326 SAFE_FREE(fsp
->fsp_name
);
328 return NT_STATUS_NO_MEMORY
;
330 fsp
->conn
= vfs
->conn
;
332 status
= create_synthetic_smb_fname_split(mem_ctx
, argv
[1], NULL
,
334 if (!NT_STATUS_IS_OK(status
)) {
339 fsp
->fsp_name
= smb_fname
;
341 fsp
->fh
->fd
= SMB_VFS_OPEN(vfs
->conn
, smb_fname
, fsp
, flags
, mode
);
342 if (fsp
->fh
->fd
== -1) {
343 printf("open: error=%d (%s)\n", errno
, strerror(errno
));
346 TALLOC_FREE(smb_fname
);
347 return NT_STATUS_UNSUCCESSFUL
;
350 vfs
->files
[fsp
->fh
->fd
] = fsp
;
351 printf("open: fd=%d\n", fsp
->fh
->fd
);
356 static NTSTATUS
cmd_pathfunc(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
361 printf("Usage: %s <path>\n", argv
[0]);
365 if (strcmp("rmdir", argv
[0]) == 0 ) {
366 ret
= SMB_VFS_RMDIR(vfs
->conn
, argv
[1]);
367 } else if (strcmp("unlink", argv
[0]) == 0 ) {
368 struct smb_filename
*smb_fname
= NULL
;
371 status
= create_synthetic_smb_fname_split(mem_ctx
, argv
[1],
373 if (!NT_STATUS_IS_OK(status
)) {
377 ret
= SMB_VFS_UNLINK(vfs
->conn
, smb_fname
);
378 TALLOC_FREE(smb_fname
);
379 } else if (strcmp("chdir", argv
[0]) == 0 ) {
380 ret
= SMB_VFS_CHDIR(vfs
->conn
, argv
[1]);
382 printf("%s: error=%d (invalid function name!)\n", argv
[0], errno
);
383 return NT_STATUS_UNSUCCESSFUL
;
387 printf("%s: error=%d (%s)\n", argv
[0], errno
, strerror(errno
));
388 return NT_STATUS_UNSUCCESSFUL
;
391 printf("%s: ok\n", argv
[0]);
396 static NTSTATUS
cmd_close(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
401 printf("Usage: close <fd>\n");
406 if (vfs
->files
[fd
] == NULL
) {
407 printf("close: error=-1 (invalid file descriptor)\n");
411 ret
= SMB_VFS_CLOSE(vfs
->files
[fd
]);
413 printf("close: error=%d (%s)\n", errno
, strerror(errno
));
415 printf("close: ok\n");
417 TALLOC_FREE(vfs
->files
[fd
]->fsp_name
);
418 SAFE_FREE(vfs
->files
[fd
]->fh
);
419 SAFE_FREE(vfs
->files
[fd
]);
420 vfs
->files
[fd
] = NULL
;
425 static NTSTATUS
cmd_read(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
431 printf("Usage: read <fd> <size>\n");
435 /* do some error checking on these */
437 size
= atoi(argv
[2]);
438 vfs
->data
= talloc_array(mem_ctx
, char, size
);
439 if (vfs
->data
== NULL
) {
440 printf("read: error=-1 (not enough memory)");
441 return NT_STATUS_UNSUCCESSFUL
;
443 vfs
->data_size
= size
;
445 rsize
= SMB_VFS_READ(vfs
->files
[fd
], vfs
->data
, size
);
447 printf("read: error=%d (%s)\n", errno
, strerror(errno
));
448 return NT_STATUS_UNSUCCESSFUL
;
451 printf("read: ok\n");
456 static NTSTATUS
cmd_write(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
461 printf("Usage: write <fd> <size>\n");
465 /* some error checking should go here */
467 size
= atoi(argv
[2]);
468 if (vfs
->data
== NULL
) {
469 printf("write: error=-1 (buffer empty, please populate it before writing)");
470 return NT_STATUS_UNSUCCESSFUL
;
473 if (vfs
->data_size
< size
) {
474 printf("write: error=-1 (buffer too small, please put some more data in)");
475 return NT_STATUS_UNSUCCESSFUL
;
478 wsize
= SMB_VFS_WRITE(vfs
->files
[fd
], vfs
->data
, size
);
481 printf("write: error=%d (%s)\n", errno
, strerror(errno
));
482 return NT_STATUS_UNSUCCESSFUL
;
485 printf("write: ok\n");
490 static NTSTATUS
cmd_lseek(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
492 int fd
, offset
, whence
;
496 printf("Usage: lseek <fd> <offset> <whence>\n...where whence is 1 => SEEK_SET, 2 => SEEK_CUR, 3 => SEEK_END\n");
501 offset
= atoi(argv
[2]);
502 whence
= atoi(argv
[3]);
504 case 1: whence
= SEEK_SET
; break;
505 case 2: whence
= SEEK_CUR
; break;
506 default: whence
= SEEK_END
;
509 pos
= SMB_VFS_LSEEK(vfs
->files
[fd
], offset
, whence
);
510 if (pos
== (SMB_OFF_T
)-1) {
511 printf("lseek: error=%d (%s)\n", errno
, strerror(errno
));
512 return NT_STATUS_UNSUCCESSFUL
;
515 printf("lseek: ok\n");
520 static NTSTATUS
cmd_rename(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
523 struct smb_filename
*smb_fname_src
= NULL
;
524 struct smb_filename
*smb_fname_dst
= NULL
;
528 printf("Usage: rename <old> <new>\n");
532 status
= create_synthetic_smb_fname_split(mem_ctx
, argv
[1], NULL
,
534 if (!NT_STATUS_IS_OK(status
)) {
538 status
= create_synthetic_smb_fname_split(mem_ctx
, argv
[2], NULL
,
540 if (!NT_STATUS_IS_OK(status
)) {
541 TALLOC_FREE(smb_fname_src
);
545 ret
= SMB_VFS_RENAME(vfs
->conn
, smb_fname_src
, smb_fname_dst
);
546 TALLOC_FREE(smb_fname_src
);
547 TALLOC_FREE(smb_fname_dst
);
549 printf("rename: error=%d (%s)\n", errno
, strerror(errno
));
550 return NT_STATUS_UNSUCCESSFUL
;
553 printf("rename: ok\n");
558 static NTSTATUS
cmd_fsync(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
562 printf("Usage: fsync <fd>\n");
567 ret
= SMB_VFS_FSYNC(vfs
->files
[fd
]);
569 printf("fsync: error=%d (%s)\n", errno
, strerror(errno
));
570 return NT_STATUS_UNSUCCESSFUL
;
573 printf("fsync: ok\n");
578 static NTSTATUS
cmd_stat(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
583 struct passwd
*pwd
= NULL
;
584 struct group
*grp
= NULL
;
585 struct smb_filename
*smb_fname
= NULL
;
591 printf("Usage: stat <fname>\n");
595 status
= create_synthetic_smb_fname_split(mem_ctx
, argv
[1], NULL
,
597 if (!NT_STATUS_IS_OK(status
)) {
601 ret
= SMB_VFS_STAT(vfs
->conn
, smb_fname
);
603 printf("stat: error=%d (%s)\n", errno
, strerror(errno
));
604 TALLOC_FREE(smb_fname
);
605 return NT_STATUS_UNSUCCESSFUL
;
608 TALLOC_FREE(smb_fname
);
610 pwd
= sys_getpwuid(st
.st_ex_uid
);
611 if (pwd
!= NULL
) user
= pwd
->pw_name
;
612 else user
= null_string
;
613 grp
= sys_getgrgid(st
.st_ex_gid
);
614 if (grp
!= NULL
) group
= grp
->gr_name
;
615 else group
= null_string
;
617 printf("stat: ok\n");
618 printf(" File: %s", argv
[1]);
619 if (S_ISREG(st
.st_ex_mode
)) printf(" Regular File\n");
620 else if (S_ISDIR(st
.st_ex_mode
)) printf(" Directory\n");
621 else if (S_ISCHR(st
.st_ex_mode
)) printf(" Character Device\n");
622 else if (S_ISBLK(st
.st_ex_mode
)) printf(" Block Device\n");
623 else if (S_ISFIFO(st
.st_ex_mode
)) printf(" Fifo\n");
624 else if (S_ISLNK(st
.st_ex_mode
)) printf(" Symbolic Link\n");
625 else if (S_ISSOCK(st
.st_ex_mode
)) printf(" Socket\n");
626 printf(" Size: %10u", (unsigned int)st
.st_ex_size
);
627 #ifdef HAVE_STAT_ST_BLOCKS
628 printf(" Blocks: %9u", (unsigned int)st
.st_ex_blocks
);
630 #ifdef HAVE_STAT_ST_BLKSIZE
631 printf(" IO Block: %u\n", (unsigned int)st
.st_ex_blksize
);
633 printf(" Device: 0x%10x", (unsigned int)st
.st_ex_dev
);
634 printf(" Inode: %10u", (unsigned int)st
.st_ex_ino
);
635 printf(" Links: %10u\n", (unsigned int)st
.st_ex_nlink
);
636 printf(" Access: %05o", (int)((st
.st_ex_mode
) & 007777));
637 printf(" Uid: %5lu/%.16s Gid: %5lu/%.16s\n", (unsigned long)st
.st_ex_uid
, user
,
638 (unsigned long)st
.st_ex_gid
, group
);
639 tmp_time
= convert_timespec_to_time_t(st
.st_ex_atime
);
640 printf(" Access: %s", ctime(&tmp_time
));
641 tmp_time
= convert_timespec_to_time_t(st
.st_ex_mtime
);
642 printf(" Modify: %s", ctime(&tmp_time
));
643 tmp_time
= convert_timespec_to_time_t(st
.st_ex_ctime
);
644 printf(" Change: %s", ctime(&tmp_time
));
650 static NTSTATUS
cmd_fstat(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
655 struct passwd
*pwd
= NULL
;
656 struct group
*grp
= NULL
;
661 printf("Usage: fstat <fd>\n");
666 if (fd
< 0 || fd
>= 1024) {
667 printf("fstat: error=%d (file descriptor out of range)\n", EBADF
);
671 if (vfs
->files
[fd
] == NULL
) {
672 printf("fstat: error=%d (invalid file descriptor)\n", EBADF
);
676 if (SMB_VFS_FSTAT(vfs
->files
[fd
], &st
) == -1) {
677 printf("fstat: error=%d (%s)\n", errno
, strerror(errno
));
678 return NT_STATUS_UNSUCCESSFUL
;
681 pwd
= sys_getpwuid(st
.st_ex_uid
);
682 if (pwd
!= NULL
) user
= pwd
->pw_name
;
683 else user
= null_string
;
684 grp
= sys_getgrgid(st
.st_ex_gid
);
685 if (grp
!= NULL
) group
= grp
->gr_name
;
686 else group
= null_string
;
688 printf("fstat: ok\n");
689 if (S_ISREG(st
.st_ex_mode
)) printf(" Regular File\n");
690 else if (S_ISDIR(st
.st_ex_mode
)) printf(" Directory\n");
691 else if (S_ISCHR(st
.st_ex_mode
)) printf(" Character Device\n");
692 else if (S_ISBLK(st
.st_ex_mode
)) printf(" Block Device\n");
693 else if (S_ISFIFO(st
.st_ex_mode
)) printf(" Fifo\n");
694 else if (S_ISLNK(st
.st_ex_mode
)) printf(" Symbolic Link\n");
695 else if (S_ISSOCK(st
.st_ex_mode
)) printf(" Socket\n");
696 printf(" Size: %10u", (unsigned int)st
.st_ex_size
);
697 #ifdef HAVE_STAT_ST_BLOCKS
698 printf(" Blocks: %9u", (unsigned int)st
.st_ex_blocks
);
700 #ifdef HAVE_STAT_ST_BLKSIZE
701 printf(" IO Block: %u\n", (unsigned int)st
.st_ex_blksize
);
703 printf(" Device: 0x%10x", (unsigned int)st
.st_ex_dev
);
704 printf(" Inode: %10u", (unsigned int)st
.st_ex_ino
);
705 printf(" Links: %10u\n", (unsigned int)st
.st_ex_nlink
);
706 printf(" Access: %05o", (int)((st
.st_ex_mode
) & 007777));
707 printf(" Uid: %5lu/%.16s Gid: %5lu/%.16s\n", (unsigned long)st
.st_ex_uid
, user
,
708 (unsigned long)st
.st_ex_gid
, group
);
709 tmp_time
= convert_timespec_to_time_t(st
.st_ex_atime
);
710 printf(" Access: %s", ctime(&tmp_time
));
711 tmp_time
= convert_timespec_to_time_t(st
.st_ex_mtime
);
712 printf(" Modify: %s", ctime(&tmp_time
));
713 tmp_time
= convert_timespec_to_time_t(st
.st_ex_ctime
);
714 printf(" Change: %s", ctime(&tmp_time
));
720 static NTSTATUS
cmd_lstat(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
724 struct passwd
*pwd
= NULL
;
725 struct group
*grp
= NULL
;
726 struct smb_filename
*smb_fname
= NULL
;
732 printf("Usage: lstat <path>\n");
736 status
= create_synthetic_smb_fname_split(mem_ctx
, argv
[1], NULL
,
738 if (!NT_STATUS_IS_OK(status
)) {
742 if (SMB_VFS_LSTAT(vfs
->conn
, smb_fname
) == -1) {
743 printf("lstat: error=%d (%s)\n", errno
, strerror(errno
));
744 TALLOC_FREE(smb_fname
);
745 return NT_STATUS_UNSUCCESSFUL
;
748 TALLOC_FREE(smb_fname
);
750 pwd
= sys_getpwuid(st
.st_ex_uid
);
751 if (pwd
!= NULL
) user
= pwd
->pw_name
;
752 else user
= null_string
;
753 grp
= sys_getgrgid(st
.st_ex_gid
);
754 if (grp
!= NULL
) group
= grp
->gr_name
;
755 else group
= null_string
;
757 printf("lstat: ok\n");
758 if (S_ISREG(st
.st_ex_mode
)) printf(" Regular File\n");
759 else if (S_ISDIR(st
.st_ex_mode
)) printf(" Directory\n");
760 else if (S_ISCHR(st
.st_ex_mode
)) printf(" Character Device\n");
761 else if (S_ISBLK(st
.st_ex_mode
)) printf(" Block Device\n");
762 else if (S_ISFIFO(st
.st_ex_mode
)) printf(" Fifo\n");
763 else if (S_ISLNK(st
.st_ex_mode
)) printf(" Symbolic Link\n");
764 else if (S_ISSOCK(st
.st_ex_mode
)) printf(" Socket\n");
765 printf(" Size: %10u", (unsigned int)st
.st_ex_size
);
766 #ifdef HAVE_STAT_ST_BLOCKS
767 printf(" Blocks: %9u", (unsigned int)st
.st_ex_blocks
);
769 #ifdef HAVE_STAT_ST_BLKSIZE
770 printf(" IO Block: %u\n", (unsigned int)st
.st_ex_blksize
);
772 printf(" Device: 0x%10x", (unsigned int)st
.st_ex_dev
);
773 printf(" Inode: %10u", (unsigned int)st
.st_ex_ino
);
774 printf(" Links: %10u\n", (unsigned int)st
.st_ex_nlink
);
775 printf(" Access: %05o", (int)((st
.st_ex_mode
) & 007777));
776 printf(" Uid: %5lu/%.16s Gid: %5lu/%.16s\n", (unsigned long)st
.st_ex_uid
, user
,
777 (unsigned long)st
.st_ex_gid
, group
);
778 tmp_time
= convert_timespec_to_time_t(st
.st_ex_atime
);
779 printf(" Access: %s", ctime(&tmp_time
));
780 tmp_time
= convert_timespec_to_time_t(st
.st_ex_mtime
);
781 printf(" Modify: %s", ctime(&tmp_time
));
782 tmp_time
= convert_timespec_to_time_t(st
.st_ex_ctime
);
783 printf(" Change: %s", ctime(&tmp_time
));
789 static NTSTATUS
cmd_chmod(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
793 printf("Usage: chmod <path> <mode>\n");
797 mode
= atoi(argv
[2]);
798 if (SMB_VFS_CHMOD(vfs
->conn
, argv
[1], mode
) == -1) {
799 printf("chmod: error=%d (%s)\n", errno
, strerror(errno
));
800 return NT_STATUS_UNSUCCESSFUL
;
803 printf("chmod: ok\n");
808 static NTSTATUS
cmd_fchmod(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
813 printf("Usage: fchmod <fd> <mode>\n");
818 mode
= atoi(argv
[2]);
819 if (fd
< 0 || fd
>= 1024) {
820 printf("fchmod: error=%d (file descriptor out of range)\n", EBADF
);
823 if (vfs
->files
[fd
] == NULL
) {
824 printf("fchmod: error=%d (invalid file descriptor)\n", EBADF
);
828 if (SMB_VFS_FCHMOD(vfs
->files
[fd
], mode
) == -1) {
829 printf("fchmod: error=%d (%s)\n", errno
, strerror(errno
));
830 return NT_STATUS_UNSUCCESSFUL
;
833 printf("fchmod: ok\n");
838 static NTSTATUS
cmd_chown(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
843 printf("Usage: chown <path> <uid> <gid>\n");
849 if (SMB_VFS_CHOWN(vfs
->conn
, argv
[1], uid
, gid
) == -1) {
850 printf("chown: error=%d (%s)\n", errno
, strerror(errno
));
851 return NT_STATUS_UNSUCCESSFUL
;
854 printf("chown: ok\n");
859 static NTSTATUS
cmd_fchown(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
865 printf("Usage: fchown <fd> <uid> <gid>\n");
872 if (fd
< 0 || fd
>= 1024) {
873 printf("fchown: faliure=%d (file descriptor out of range)\n", EBADF
);
876 if (vfs
->files
[fd
] == NULL
) {
877 printf("fchown: error=%d (invalid file descriptor)\n", EBADF
);
880 if (SMB_VFS_FCHOWN(vfs
->files
[fd
], uid
, gid
) == -1) {
881 printf("fchown error=%d (%s)\n", errno
, strerror(errno
));
882 return NT_STATUS_UNSUCCESSFUL
;
885 printf("fchown: ok\n");
890 static NTSTATUS
cmd_getwd(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
892 char *buf
= SMB_VFS_GETWD(vfs
->conn
);
894 printf("getwd: error=%d (%s)\n", errno
, strerror(errno
));
895 return NT_STATUS_UNSUCCESSFUL
;
898 printf("getwd: %s\n", buf
);
903 static NTSTATUS
cmd_utime(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
905 struct smb_file_time ft
;
906 struct smb_filename
*smb_fname
= NULL
;
910 printf("Usage: utime <path> <access> <modify>\n");
916 ft
.atime
= convert_time_t_to_timespec(atoi(argv
[2]));
917 ft
.mtime
= convert_time_t_to_timespec(atoi(argv
[3]));
919 status
= create_synthetic_smb_fname_split(mem_ctx
, argv
[1],
921 if (!NT_STATUS_IS_OK(status
)) {
925 if (SMB_VFS_NTIMES(vfs
->conn
, smb_fname
, &ft
) != 0) {
926 printf("utime: error=%d (%s)\n", errno
, strerror(errno
));
927 TALLOC_FREE(smb_fname
);
928 return NT_STATUS_UNSUCCESSFUL
;
931 TALLOC_FREE(smb_fname
);
932 printf("utime: ok\n");
936 static NTSTATUS
cmd_ftruncate(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
941 printf("Usage: ftruncate <fd> <length>\n");
947 if (fd
< 0 || fd
>= 1024) {
948 printf("ftruncate: error=%d (file descriptor out of range)\n", EBADF
);
951 if (vfs
->files
[fd
] == NULL
) {
952 printf("ftruncate: error=%d (invalid file descriptor)\n", EBADF
);
956 if (SMB_VFS_FTRUNCATE(vfs
->files
[fd
], off
) == -1) {
957 printf("ftruncate: error=%d (%s)\n", errno
, strerror(errno
));
958 return NT_STATUS_UNSUCCESSFUL
;
961 printf("ftruncate: ok\n");
965 static NTSTATUS
cmd_lock(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
975 printf("Usage: lock <fd> <op> <offset> <count> <type>\n");
976 printf(" ops: G = F_GETLK\n");
977 printf(" S = F_SETLK\n");
978 printf(" W = F_SETLKW\n");
979 printf(" type: R = F_RDLCK\n");
980 printf(" W = F_WRLCK\n");
981 printf(" U = F_UNLCK\n");
985 if (sscanf(argv
[1], "%d", &fd
) == 0) {
986 printf("lock: error=-1 (error parsing fd)\n");
987 return NT_STATUS_UNSUCCESSFUL
;
1002 printf("lock: error=-1 (invalid op flag!)\n");
1003 return NT_STATUS_UNSUCCESSFUL
;
1006 if (sscanf(argv
[3], "%ld", &offset
) == 0) {
1007 printf("lock: error=-1 (error parsing fd)\n");
1008 return NT_STATUS_UNSUCCESSFUL
;
1011 if (sscanf(argv
[4], "%ld", &count
) == 0) {
1012 printf("lock: error=-1 (error parsing fd)\n");
1013 return NT_STATUS_UNSUCCESSFUL
;
1030 printf("lock: error=-1 (invalid type flag!)\n");
1031 return NT_STATUS_UNSUCCESSFUL
;
1036 printf("lock: debug lock(fd=%d, op=%d, offset=%ld, count=%ld, type=%d))\n", fd
, op
, offset
, count
, type
);
1038 if (SMB_VFS_LOCK(vfs
->files
[fd
], op
, offset
, count
, type
) == False
) {
1039 printf("lock: error=%d (%s)\n", errno
, strerror(errno
));
1040 return NT_STATUS_UNSUCCESSFUL
;
1043 printf("lock: ok\n");
1044 return NT_STATUS_OK
;
1047 static NTSTATUS
cmd_symlink(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
1050 printf("Usage: symlink <path> <link>\n");
1051 return NT_STATUS_OK
;
1054 if (SMB_VFS_SYMLINK(vfs
->conn
, argv
[1], argv
[2]) == -1) {
1055 printf("symlink: error=%d (%s)\n", errno
, strerror(errno
));
1056 return NT_STATUS_UNSUCCESSFUL
;
1059 printf("symlink: ok\n");
1060 return NT_STATUS_OK
;
1064 static NTSTATUS
cmd_readlink(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
1066 char buffer
[PATH_MAX
];
1070 printf("Usage: readlink <path>\n");
1071 return NT_STATUS_OK
;
1074 if ((size
= SMB_VFS_READLINK(vfs
->conn
, argv
[1], buffer
, PATH_MAX
)) == -1) {
1075 printf("readlink: error=%d (%s)\n", errno
, strerror(errno
));
1076 return NT_STATUS_UNSUCCESSFUL
;
1079 buffer
[size
] = '\0';
1080 printf("readlink: %s\n", buffer
);
1081 return NT_STATUS_OK
;
1085 static NTSTATUS
cmd_link(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
1088 printf("Usage: link <path> <link>\n");
1089 return NT_STATUS_OK
;
1092 if (SMB_VFS_LINK(vfs
->conn
, argv
[1], argv
[2]) == -1) {
1093 printf("link: error=%d (%s)\n", errno
, strerror(errno
));
1094 return NT_STATUS_UNSUCCESSFUL
;
1097 printf("link: ok\n");
1098 return NT_STATUS_OK
;
1101 static NTSTATUS
cmd_mknod(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
1104 unsigned int dev_val
;
1108 printf("Usage: mknod <path> <mode> <dev>\n");
1109 printf(" mode is octal\n");
1110 printf(" dev is hex\n");
1111 return NT_STATUS_OK
;
1114 if (sscanf(argv
[2], "%ho", (unsigned short *)&mode
) == 0) {
1115 printf("open: error=-1 (invalid mode!)\n");
1116 return NT_STATUS_UNSUCCESSFUL
;
1119 if (sscanf(argv
[3], "%x", &dev_val
) == 0) {
1120 printf("open: error=-1 (invalid dev!)\n");
1121 return NT_STATUS_UNSUCCESSFUL
;
1123 dev
= (SMB_DEV_T
)dev_val
;
1125 if (SMB_VFS_MKNOD(vfs
->conn
, argv
[1], mode
, dev
) == -1) {
1126 printf("mknod: error=%d (%s)\n", errno
, strerror(errno
));
1127 return NT_STATUS_UNSUCCESSFUL
;
1130 printf("mknod: ok\n");
1131 return NT_STATUS_OK
;
1134 static NTSTATUS
cmd_realpath(struct vfs_state
*vfs
, TALLOC_CTX
*mem_ctx
, int argc
, const char **argv
)
1137 printf("Usage: realpath <path>\n");
1138 return NT_STATUS_OK
;
1141 if (SMB_VFS_REALPATH(vfs
->conn
, argv
[1]) == NULL
) {
1142 printf("realpath: error=%d (%s)\n", errno
, strerror(errno
));
1143 return NT_STATUS_UNSUCCESSFUL
;
1146 printf("realpath: ok\n");
1147 return NT_STATUS_OK
;
1150 struct cmd_set vfs_commands
[] = {
1154 { "load", cmd_load_module
, "Load a module", "load <module.so>" },
1155 { "populate", cmd_populate
, "Populate a data buffer", "populate <char> <size>" },
1156 { "showdata", cmd_show_data
, "Show data currently in data buffer", "show_data [<offset> <len>]"},
1157 { "connect", cmd_connect
, "VFS connect()", "connect" },
1158 { "disconnect", cmd_disconnect
, "VFS disconnect()", "disconnect" },
1159 { "disk_free", cmd_disk_free
, "VFS disk_free()", "disk_free <path>" },
1160 { "opendir", cmd_opendir
, "VFS opendir()", "opendir <fname>" },
1161 { "readdir", cmd_readdir
, "VFS readdir()", "readdir" },
1162 { "mkdir", cmd_mkdir
, "VFS mkdir()", "mkdir <path>" },
1163 { "rmdir", cmd_pathfunc
, "VFS rmdir()", "rmdir <path>" },
1164 { "closedir", cmd_closedir
, "VFS closedir()", "closedir" },
1165 { "open", cmd_open
, "VFS open()", "open <fname>" },
1166 { "close", cmd_close
, "VFS close()", "close <fd>" },
1167 { "read", cmd_read
, "VFS read()", "read <fd> <size>" },
1168 { "write", cmd_write
, "VFS write()", "write <fd> <size>" },
1169 { "lseek", cmd_lseek
, "VFS lseek()", "lseek <fd> <offset> <whence>" },
1170 { "rename", cmd_rename
, "VFS rename()", "rename <old> <new>" },
1171 { "fsync", cmd_fsync
, "VFS fsync()", "fsync <fd>" },
1172 { "stat", cmd_stat
, "VFS stat()", "stat <fname>" },
1173 { "fstat", cmd_fstat
, "VFS fstat()", "fstat <fd>" },
1174 { "lstat", cmd_lstat
, "VFS lstat()", "lstat <fname>" },
1175 { "unlink", cmd_pathfunc
, "VFS unlink()", "unlink <fname>" },
1176 { "chmod", cmd_chmod
, "VFS chmod()", "chmod <path> <mode>" },
1177 { "fchmod", cmd_fchmod
, "VFS fchmod()", "fchmod <fd> <mode>" },
1178 { "chown", cmd_chown
, "VFS chown()", "chown <path> <uid> <gid>" },
1179 { "fchown", cmd_fchown
, "VFS fchown()", "fchown <fd> <uid> <gid>" },
1180 { "chdir", cmd_pathfunc
, "VFS chdir()", "chdir <path>" },
1181 { "getwd", cmd_getwd
, "VFS getwd()", "getwd" },
1182 { "utime", cmd_utime
, "VFS utime()", "utime <path> <access> <modify>" },
1183 { "ftruncate", cmd_ftruncate
, "VFS ftruncate()", "ftruncate <fd> <length>" },
1184 { "lock", cmd_lock
, "VFS lock()", "lock <f> <op> <offset> <count> <type>" },
1185 { "symlink", cmd_symlink
, "VFS symlink()", "symlink <old> <new>" },
1186 { "readlink", cmd_readlink
, "VFS readlink()", "readlink <path>" },
1187 { "link", cmd_link
, "VFS link()", "link <oldpath> <newpath>" },
1188 { "mknod", cmd_mknod
, "VFS mknod()", "mknod <path> <mode> <dev>" },
1189 { "realpath", cmd_realpath
, "VFS realpath()", "realpath <path>" },