r23620: Convert set_nt_acl to return NTSTATUS. Also fix the chown
[Samba/bb.git] / source3 / torture / cmd_vfs.c
blob1005d14e7972e34031398a531eafd3e3e9abeadc
1 /*
2 Unix SMB/CIFS implementation.
3 VFS module functions
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 2 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, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include "includes.h"
24 #include "vfstest.h"
26 static const char *null_string = "";
28 static NTSTATUS cmd_load_module(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, const char **argv)
30 int i;
32 if (argc < 2) {
33 printf("Usage: load <modules>\n");
34 return NT_STATUS_OK;
37 for (i=argc-1;i>0;i--) {
38 if (!vfs_init_custom(vfs->conn, argv[i])) {
39 DEBUG(0, ("load: (vfs_init_custom failed for %s)\n", argv[i]));
40 return NT_STATUS_UNSUCCESSFUL;
43 printf("load: ok\n");
44 return NT_STATUS_OK;
47 static NTSTATUS cmd_populate(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, const char **argv)
49 char c;
50 size_t size;
51 if (argc != 3) {
52 printf("Usage: populate <char> <size>\n");
53 return NT_STATUS_OK;
55 c = argv[1][0];
56 size = atoi(argv[2]);
57 vfs->data = TALLOC_ARRAY(mem_ctx, char, size);
58 if (vfs->data == NULL) {
59 printf("populate: error=-1 (not enough memory)");
60 return NT_STATUS_UNSUCCESSFUL;
62 memset(vfs->data, c, size);
63 vfs->data_size = size;
64 return NT_STATUS_OK;
67 static NTSTATUS cmd_show_data(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, const char **argv)
69 size_t offset;
70 size_t len;
71 if (argc != 1 && argc != 3) {
72 printf("Usage: showdata [<offset> <len>]\n");
73 return NT_STATUS_OK;
75 if (vfs->data == NULL || vfs->data_size == 0) {
76 printf("show_data: error=-1 (buffer empty)\n");
77 return NT_STATUS_UNSUCCESSFUL;
80 if (argc == 3) {
81 offset = atoi(argv[1]);
82 len = atoi(argv[2]);
83 } else {
84 offset = 0;
85 len = vfs->data_size;
87 if ((offset + len) > vfs->data_size) {
88 printf("show_data: error=-1 (not enough data in buffer)\n");
89 return NT_STATUS_UNSUCCESSFUL;
91 dump_data(0, (uint8 *)(vfs->data) + offset, len);
92 return NT_STATUS_OK;
95 static NTSTATUS cmd_connect(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, const char **argv)
97 SMB_VFS_CONNECT(vfs->conn, lp_servicename(SNUM(vfs->conn)), "vfstest");
98 return NT_STATUS_OK;
101 static NTSTATUS cmd_disconnect(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, const char **argv)
103 SMB_VFS_DISCONNECT(vfs->conn);
104 return NT_STATUS_OK;
107 static NTSTATUS cmd_disk_free(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, const char **argv)
109 SMB_BIG_UINT diskfree, bsize, dfree, dsize;
110 if (argc != 2) {
111 printf("Usage: disk_free <path>\n");
112 return NT_STATUS_OK;
115 diskfree = SMB_VFS_DISK_FREE(vfs->conn, argv[1], False, &bsize, &dfree, &dsize);
116 printf("disk_free: %lu, bsize = %lu, dfree = %lu, dsize = %lu\n",
117 (unsigned long)diskfree,
118 (unsigned long)bsize,
119 (unsigned long)dfree,
120 (unsigned long)dsize);
121 return NT_STATUS_OK;
125 static NTSTATUS cmd_opendir(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, const char **argv)
127 if (argc != 2) {
128 printf("Usage: opendir <fname>\n");
129 return NT_STATUS_OK;
132 vfs->currentdir = SMB_VFS_OPENDIR(vfs->conn, argv[1], NULL, 0);
133 if (vfs->currentdir == NULL) {
134 printf("opendir error=%d (%s)\n", errno, strerror(errno));
135 return NT_STATUS_UNSUCCESSFUL;
138 printf("opendir: ok\n");
139 return NT_STATUS_OK;
143 static NTSTATUS cmd_readdir(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, const char **argv)
145 SMB_STRUCT_DIRENT *dent;
147 if (vfs->currentdir == NULL) {
148 printf("readdir: error=-1 (no open directory)\n");
149 return NT_STATUS_UNSUCCESSFUL;
152 dent = SMB_VFS_READDIR(vfs->conn, vfs->currentdir);
153 if (dent == NULL) {
154 printf("readdir: NULL\n");
155 return NT_STATUS_OK;
158 printf("readdir: %s\n", dent->d_name);
159 return NT_STATUS_OK;
163 static NTSTATUS cmd_mkdir(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, const char **argv)
165 if (argc != 2) {
166 printf("Usage: mkdir <path>\n");
167 return NT_STATUS_OK;
170 if (SMB_VFS_MKDIR(vfs->conn, argv[1], 00755) == -1) {
171 printf("mkdir error=%d (%s)\n", errno, strerror(errno));
172 return NT_STATUS_UNSUCCESSFUL;
175 printf("mkdir: ok\n");
176 return NT_STATUS_OK;
180 static NTSTATUS cmd_closedir(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, const char **argv)
182 int ret;
184 if (vfs->currentdir == NULL) {
185 printf("closedir: failure (no directory open)\n");
186 return NT_STATUS_UNSUCCESSFUL;
189 ret = SMB_VFS_CLOSEDIR(vfs->conn, vfs->currentdir);
190 if (ret == -1) {
191 printf("closedir failure: %s\n", strerror(errno));
192 return NT_STATUS_UNSUCCESSFUL;
195 printf("closedir: ok\n");
196 vfs->currentdir = NULL;
197 return NT_STATUS_OK;
201 static NTSTATUS cmd_open(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, const char **argv)
203 int flags;
204 mode_t mode;
205 const char *flagstr;
206 files_struct *fsp;
208 mode = 00400;
210 if (argc < 3 || argc > 5) {
211 printf("Usage: open <filename> <flags> <mode>\n");
212 printf(" flags: O = O_RDONLY\n");
213 printf(" R = O_RDWR\n");
214 printf(" W = O_WRONLY\n");
215 printf(" C = O_CREAT\n");
216 printf(" E = O_EXCL\n");
217 printf(" T = O_TRUNC\n");
218 printf(" A = O_APPEND\n");
219 printf(" N = O_NONBLOCK/O_NDELAY\n");
220 #ifdef O_SYNC
221 printf(" S = O_SYNC\n");
222 #endif
223 #ifdef O_NOFOLLOW
224 printf(" F = O_NOFOLLOW\n");
225 #endif
226 printf(" mode: see open.2\n");
227 printf(" mode is ignored if C flag not present\n");
228 printf(" mode defaults to 00400\n");
229 return NT_STATUS_OK;
231 flags = 0;
232 flagstr = argv[2];
233 while (*flagstr) {
234 switch (*flagstr) {
235 case 'O':
236 flags |= O_RDONLY;
237 break;
238 case 'R':
239 flags |= O_RDWR;
240 break;
241 case 'W':
242 flags |= O_WRONLY;
243 break;
244 case 'C':
245 flags |= O_CREAT;
246 break;
247 case 'E':
248 flags |= O_EXCL;
249 break;
250 case 'T':
251 flags |= O_TRUNC;
252 break;
253 case 'A':
254 flags |= O_APPEND;
255 break;
256 case 'N':
257 flags |= O_NONBLOCK;
258 break;
259 #ifdef O_SYNC
260 case 'S':
261 flags |= O_SYNC;
262 break;
263 #endif
264 #ifdef O_NOFOLLOW
265 case 'F':
266 flags |= O_NOFOLLOW;
267 break;
268 #endif
269 default:
270 printf("open: error=-1 (invalid flag!)\n");
271 return NT_STATUS_UNSUCCESSFUL;
273 flagstr++;
275 if ((flags & O_CREAT) && argc == 4) {
276 if (sscanf(argv[3], "%o", &mode) == 0) {
277 printf("open: error=-1 (invalid mode!)\n");
278 return NT_STATUS_UNSUCCESSFUL;
282 fsp = SMB_MALLOC_P(struct files_struct);
283 fsp->fsp_name = SMB_STRDUP(argv[1]);
284 fsp->fh = SMB_MALLOC_P(struct fd_handle);
285 fsp->conn = vfs->conn;
287 fsp->fh->fd = SMB_VFS_OPEN(vfs->conn, argv[1], fsp, flags, mode);
288 if (fsp->fh->fd == -1) {
289 printf("open: error=%d (%s)\n", errno, strerror(errno));
290 SAFE_FREE(fsp->fh);
291 SAFE_FREE(fsp);
292 return NT_STATUS_UNSUCCESSFUL;
295 vfs->files[fsp->fh->fd] = fsp;
296 printf("open: fd=%d\n", fsp->fh->fd);
297 return NT_STATUS_OK;
301 static NTSTATUS cmd_pathfunc(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, const char **argv)
303 int ret = -1;
305 if (argc != 2) {
306 printf("Usage: %s <path>\n", argv[0]);
307 return NT_STATUS_OK;
310 if (strcmp("rmdir", argv[0]) == 0 ) {
311 ret = SMB_VFS_RMDIR(vfs->conn, argv[1]);
312 } else if (strcmp("unlink", argv[0]) == 0 ) {
313 ret = SMB_VFS_UNLINK(vfs->conn, argv[1]);
314 } else if (strcmp("chdir", argv[0]) == 0 ) {
315 ret = SMB_VFS_CHDIR(vfs->conn, argv[1]);
316 } else {
317 printf("%s: error=%d (invalid function name!)\n", argv[0], errno);
318 return NT_STATUS_UNSUCCESSFUL;
321 if (ret == -1) {
322 printf("%s: error=%d (%s)\n", argv[0], errno, strerror(errno));
323 return NT_STATUS_UNSUCCESSFUL;
326 printf("%s: ok\n", argv[0]);
327 return NT_STATUS_OK;
331 static NTSTATUS cmd_close(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, const char **argv)
333 int fd, ret;
335 if (argc != 2) {
336 printf("Usage: close <fd>\n");
337 return NT_STATUS_OK;
340 fd = atoi(argv[1]);
341 if (vfs->files[fd] == NULL) {
342 printf("close: error=-1 (invalid file descriptor)\n");
343 return NT_STATUS_OK;
346 ret = SMB_VFS_CLOSE(vfs->files[fd], fd);
347 if (ret == -1 )
348 printf("close: error=%d (%s)\n", errno, strerror(errno));
349 else
350 printf("close: ok\n");
352 SAFE_FREE(vfs->files[fd]->fsp_name);
353 SAFE_FREE(vfs->files[fd]->fh);
354 SAFE_FREE(vfs->files[fd]);
355 vfs->files[fd] = NULL;
356 return NT_STATUS_OK;
360 static NTSTATUS cmd_read(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, const char **argv)
362 int fd;
363 size_t size, rsize;
365 if (argc != 3) {
366 printf("Usage: read <fd> <size>\n");
367 return NT_STATUS_OK;
370 /* do some error checking on these */
371 fd = atoi(argv[1]);
372 size = atoi(argv[2]);
373 vfs->data = TALLOC_ARRAY(mem_ctx, char, size);
374 if (vfs->data == NULL) {
375 printf("read: error=-1 (not enough memory)");
376 return NT_STATUS_UNSUCCESSFUL;
378 vfs->data_size = size;
380 rsize = SMB_VFS_READ(vfs->files[fd], fd, vfs->data, size);
381 if (rsize == -1) {
382 printf("read: error=%d (%s)\n", errno, strerror(errno));
383 return NT_STATUS_UNSUCCESSFUL;
386 printf("read: ok\n");
387 return NT_STATUS_OK;
391 static NTSTATUS cmd_write(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, const char **argv)
393 int fd, size, wsize;
395 if (argc != 3) {
396 printf("Usage: write <fd> <size>\n");
397 return NT_STATUS_OK;
400 /* some error checking should go here */
401 fd = atoi(argv[1]);
402 size = atoi(argv[2]);
403 if (vfs->data == NULL) {
404 printf("write: error=-1 (buffer empty, please populate it before writing)");
405 return NT_STATUS_UNSUCCESSFUL;
408 if (vfs->data_size < size) {
409 printf("write: error=-1 (buffer too small, please put some more data in)");
410 return NT_STATUS_UNSUCCESSFUL;
413 wsize = SMB_VFS_WRITE(vfs->files[fd], fd, vfs->data, size);
415 if (wsize == -1) {
416 printf("write: error=%d (%s)\n", errno, strerror(errno));
417 return NT_STATUS_UNSUCCESSFUL;
420 printf("write: ok\n");
421 return NT_STATUS_OK;
425 static NTSTATUS cmd_lseek(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, const char **argv)
427 int fd, offset, whence;
428 SMB_OFF_T pos;
430 if (argc != 4) {
431 printf("Usage: lseek <fd> <offset> <whence>\n...where whence is 1 => SEEK_SET, 2 => SEEK_CUR, 3 => SEEK_END\n");
432 return NT_STATUS_OK;
435 fd = atoi(argv[1]);
436 offset = atoi(argv[2]);
437 whence = atoi(argv[3]);
438 switch (whence) {
439 case 1: whence = SEEK_SET; break;
440 case 2: whence = SEEK_CUR; break;
441 default: whence = SEEK_END;
444 pos = SMB_VFS_LSEEK(vfs->files[fd], fd, offset, whence);
445 if (pos == (SMB_OFF_T)-1) {
446 printf("lseek: error=%d (%s)\n", errno, strerror(errno));
447 return NT_STATUS_UNSUCCESSFUL;
450 printf("lseek: ok\n");
451 return NT_STATUS_OK;
455 static NTSTATUS cmd_rename(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, const char **argv)
457 int ret;
458 if (argc != 3) {
459 printf("Usage: rename <old> <new>\n");
460 return NT_STATUS_OK;
463 ret = SMB_VFS_RENAME(vfs->conn, argv[1], argv[2]);
464 if (ret == -1) {
465 printf("rename: error=%d (%s)\n", errno, strerror(errno));
466 return NT_STATUS_UNSUCCESSFUL;
469 printf("rename: ok\n");
470 return NT_STATUS_OK;
474 static NTSTATUS cmd_fsync(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, const char **argv)
476 int ret, fd;
477 if (argc != 2) {
478 printf("Usage: fsync <fd>\n");
479 return NT_STATUS_OK;
482 fd = atoi(argv[1]);
483 ret = SMB_VFS_FSYNC(vfs->files[fd], fd);
484 if (ret == -1) {
485 printf("fsync: error=%d (%s)\n", errno, strerror(errno));
486 return NT_STATUS_UNSUCCESSFUL;
489 printf("fsync: ok\n");
490 return NT_STATUS_OK;
494 static NTSTATUS cmd_stat(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, const char **argv)
496 int ret;
497 const char *user;
498 const char *group;
499 struct passwd *pwd = NULL;
500 struct group *grp = NULL;
501 SMB_STRUCT_STAT st;
503 if (argc != 2) {
504 printf("Usage: stat <fname>\n");
505 return NT_STATUS_OK;
508 ret = SMB_VFS_STAT(vfs->conn, argv[1], &st);
509 if (ret == -1) {
510 printf("stat: error=%d (%s)\n", errno, strerror(errno));
511 return NT_STATUS_UNSUCCESSFUL;
514 pwd = sys_getpwuid(st.st_uid);
515 if (pwd != NULL) user = pwd->pw_name;
516 else user = null_string;
517 grp = sys_getgrgid(st.st_gid);
518 if (grp != NULL) group = grp->gr_name;
519 else group = null_string;
521 printf("stat: ok\n");
522 printf(" File: %s", argv[1]);
523 if (S_ISREG(st.st_mode)) printf(" Regular File\n");
524 else if (S_ISDIR(st.st_mode)) printf(" Directory\n");
525 else if (S_ISCHR(st.st_mode)) printf(" Character Device\n");
526 else if (S_ISBLK(st.st_mode)) printf(" Block Device\n");
527 else if (S_ISFIFO(st.st_mode)) printf(" Fifo\n");
528 else if (S_ISLNK(st.st_mode)) printf(" Symbolic Link\n");
529 else if (S_ISSOCK(st.st_mode)) printf(" Socket\n");
530 printf(" Size: %10u", (unsigned int)st.st_size);
531 #ifdef HAVE_STAT_ST_BLOCKS
532 printf(" Blocks: %9u", (unsigned int)st.st_blocks);
533 #endif
534 #ifdef HAVE_STAT_ST_BLKSIZE
535 printf(" IO Block: %u\n", (unsigned int)st.st_blksize);
536 #endif
537 printf(" Device: 0x%10x", (unsigned int)st.st_dev);
538 printf(" Inode: %10u", (unsigned int)st.st_ino);
539 printf(" Links: %10u\n", (unsigned int)st.st_nlink);
540 printf(" Access: %05o", (st.st_mode) & 007777);
541 printf(" Uid: %5lu/%.16s Gid: %5lu/%.16s\n", (unsigned long)st.st_uid, user,
542 (unsigned long)st.st_gid, group);
543 printf(" Access: %s", ctime(&(st.st_atime)));
544 printf(" Modify: %s", ctime(&(st.st_mtime)));
545 printf(" Change: %s", ctime(&(st.st_ctime)));
547 return NT_STATUS_OK;
551 static NTSTATUS cmd_fstat(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, const char **argv)
553 int fd;
554 const char *user;
555 const char *group;
556 struct passwd *pwd = NULL;
557 struct group *grp = NULL;
558 SMB_STRUCT_STAT st;
560 if (argc != 2) {
561 printf("Usage: fstat <fd>\n");
562 return NT_STATUS_OK;
565 fd = atoi(argv[1]);
566 if (fd < 0 || fd > 1024) {
567 printf("fstat: error=%d (file descriptor out of range)\n", EBADF);
568 return NT_STATUS_OK;
571 if (vfs->files[fd] == NULL) {
572 printf("fstat: error=%d (invalid file descriptor)\n", EBADF);
573 return NT_STATUS_OK;
576 if (SMB_VFS_FSTAT(vfs->files[fd], fd, &st) == -1) {
577 printf("fstat: error=%d (%s)\n", errno, strerror(errno));
578 return NT_STATUS_UNSUCCESSFUL;
581 pwd = sys_getpwuid(st.st_uid);
582 if (pwd != NULL) user = pwd->pw_name;
583 else user = null_string;
584 grp = sys_getgrgid(st.st_gid);
585 if (grp != NULL) group = grp->gr_name;
586 else group = null_string;
588 printf("fstat: ok\n");
589 if (S_ISREG(st.st_mode)) printf(" Regular File\n");
590 else if (S_ISDIR(st.st_mode)) printf(" Directory\n");
591 else if (S_ISCHR(st.st_mode)) printf(" Character Device\n");
592 else if (S_ISBLK(st.st_mode)) printf(" Block Device\n");
593 else if (S_ISFIFO(st.st_mode)) printf(" Fifo\n");
594 else if (S_ISLNK(st.st_mode)) printf(" Symbolic Link\n");
595 else if (S_ISSOCK(st.st_mode)) printf(" Socket\n");
596 printf(" Size: %10u", (unsigned int)st.st_size);
597 #ifdef HAVE_STAT_ST_BLOCKS
598 printf(" Blocks: %9u", (unsigned int)st.st_blocks);
599 #endif
600 #ifdef HAVE_STAT_ST_BLKSIZE
601 printf(" IO Block: %u\n", (unsigned int)st.st_blksize);
602 #endif
603 printf(" Device: 0x%10x", (unsigned int)st.st_dev);
604 printf(" Inode: %10u", (unsigned int)st.st_ino);
605 printf(" Links: %10u\n", (unsigned int)st.st_nlink);
606 printf(" Access: %05o", (st.st_mode) & 007777);
607 printf(" Uid: %5lu/%.16s Gid: %5lu/%.16s\n", (unsigned long)st.st_uid, user,
608 (unsigned long)st.st_gid, group);
609 printf(" Access: %s", ctime(&(st.st_atime)));
610 printf(" Modify: %s", ctime(&(st.st_mtime)));
611 printf(" Change: %s", ctime(&(st.st_ctime)));
613 return NT_STATUS_OK;
617 static NTSTATUS cmd_lstat(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, const char **argv)
619 const char *user;
620 const char *group;
621 struct passwd *pwd = NULL;
622 struct group *grp = NULL;
623 SMB_STRUCT_STAT st;
625 if (argc != 2) {
626 printf("Usage: lstat <path>\n");
627 return NT_STATUS_OK;
630 if (SMB_VFS_LSTAT(vfs->conn, argv[1], &st) == -1) {
631 printf("lstat: error=%d (%s)\n", errno, strerror(errno));
632 return NT_STATUS_UNSUCCESSFUL;
635 pwd = sys_getpwuid(st.st_uid);
636 if (pwd != NULL) user = pwd->pw_name;
637 else user = null_string;
638 grp = sys_getgrgid(st.st_gid);
639 if (grp != NULL) group = grp->gr_name;
640 else group = null_string;
642 printf("lstat: ok\n");
643 if (S_ISREG(st.st_mode)) printf(" Regular File\n");
644 else if (S_ISDIR(st.st_mode)) printf(" Directory\n");
645 else if (S_ISCHR(st.st_mode)) printf(" Character Device\n");
646 else if (S_ISBLK(st.st_mode)) printf(" Block Device\n");
647 else if (S_ISFIFO(st.st_mode)) printf(" Fifo\n");
648 else if (S_ISLNK(st.st_mode)) printf(" Symbolic Link\n");
649 else if (S_ISSOCK(st.st_mode)) printf(" Socket\n");
650 printf(" Size: %10u", (unsigned int)st.st_size);
651 #ifdef HAVE_STAT_ST_BLOCKS
652 printf(" Blocks: %9u", (unsigned int)st.st_blocks);
653 #endif
654 #ifdef HAVE_STAT_ST_BLKSIZE
655 printf(" IO Block: %u\n", (unsigned int)st.st_blksize);
656 #endif
657 printf(" Device: 0x%10x", (unsigned int)st.st_dev);
658 printf(" Inode: %10u", (unsigned int)st.st_ino);
659 printf(" Links: %10u\n", (unsigned int)st.st_nlink);
660 printf(" Access: %05o", (st.st_mode) & 007777);
661 printf(" Uid: %5lu/%.16s Gid: %5lu/%.16s\n", (unsigned long)st.st_uid, user,
662 (unsigned long)st.st_gid, group);
663 printf(" Access: %s", ctime(&(st.st_atime)));
664 printf(" Modify: %s", ctime(&(st.st_mtime)));
665 printf(" Change: %s", ctime(&(st.st_ctime)));
667 return NT_STATUS_OK;
671 static NTSTATUS cmd_chmod(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, const char **argv)
673 mode_t mode;
674 if (argc != 3) {
675 printf("Usage: chmod <path> <mode>\n");
676 return NT_STATUS_OK;
679 mode = atoi(argv[2]);
680 if (SMB_VFS_CHMOD(vfs->conn, argv[1], mode) == -1) {
681 printf("chmod: error=%d (%s)\n", errno, strerror(errno));
682 return NT_STATUS_UNSUCCESSFUL;
685 printf("chmod: ok\n");
686 return NT_STATUS_OK;
690 static NTSTATUS cmd_fchmod(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, const char **argv)
692 int fd;
693 mode_t mode;
694 if (argc != 3) {
695 printf("Usage: fchmod <fd> <mode>\n");
696 return NT_STATUS_OK;
699 fd = atoi(argv[1]);
700 mode = atoi(argv[2]);
701 if (fd < 0 || fd > 1024) {
702 printf("fchmod: error=%d (file descriptor out of range)\n", EBADF);
703 return NT_STATUS_OK;
705 if (vfs->files[fd] == NULL) {
706 printf("fchmod: error=%d (invalid file descriptor)\n", EBADF);
707 return NT_STATUS_OK;
710 if (SMB_VFS_FCHMOD(vfs->files[fd], fd, mode) == -1) {
711 printf("fchmod: error=%d (%s)\n", errno, strerror(errno));
712 return NT_STATUS_UNSUCCESSFUL;
715 printf("fchmod: ok\n");
716 return NT_STATUS_OK;
720 static NTSTATUS cmd_chown(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, const char **argv)
722 uid_t uid;
723 gid_t gid;
724 if (argc != 4) {
725 printf("Usage: chown <path> <uid> <gid>\n");
726 return NT_STATUS_OK;
729 uid = atoi(argv[2]);
730 gid = atoi(argv[3]);
731 if (SMB_VFS_CHOWN(vfs->conn, argv[1], uid, gid) == -1) {
732 printf("chown: error=%d (%s)\n", errno, strerror(errno));
733 return NT_STATUS_UNSUCCESSFUL;
736 printf("chown: ok\n");
737 return NT_STATUS_OK;
741 static NTSTATUS cmd_fchown(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, const char **argv)
743 uid_t uid;
744 gid_t gid;
745 int fd;
746 if (argc != 4) {
747 printf("Usage: fchown <fd> <uid> <gid>\n");
748 return NT_STATUS_OK;
751 uid = atoi(argv[2]);
752 gid = atoi(argv[3]);
753 fd = atoi(argv[1]);
754 if (fd < 0 || fd > 1024) {
755 printf("fchown: faliure=%d (file descriptor out of range)\n", EBADF);
756 return NT_STATUS_OK;
758 if (vfs->files[fd] == NULL) {
759 printf("fchown: error=%d (invalid file descriptor)\n", EBADF);
760 return NT_STATUS_OK;
762 if (SMB_VFS_FCHOWN(vfs->files[fd], fd, uid, gid) == -1) {
763 printf("fchown error=%d (%s)\n", errno, strerror(errno));
764 return NT_STATUS_UNSUCCESSFUL;
767 printf("fchown: ok\n");
768 return NT_STATUS_OK;
772 static NTSTATUS cmd_getwd(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, const char **argv)
774 char buf[PATH_MAX];
775 if (SMB_VFS_GETWD(vfs->conn, buf) == NULL) {
776 printf("getwd: error=%d (%s)\n", errno, strerror(errno));
777 return NT_STATUS_UNSUCCESSFUL;
780 printf("getwd: %s\n", buf);
781 return NT_STATUS_OK;
784 static NTSTATUS cmd_utime(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, const char **argv)
786 struct timespec ts[2];
787 if (argc != 4) {
788 printf("Usage: utime <path> <access> <modify>\n");
789 return NT_STATUS_OK;
791 ts[0] = convert_time_t_to_timespec(atoi(argv[2]));
792 ts[1] = convert_time_t_to_timespec(atoi(argv[3]));
793 if (SMB_VFS_NTIMES(vfs->conn, argv[1], ts) != 0) {
794 printf("utime: error=%d (%s)\n", errno, strerror(errno));
795 return NT_STATUS_UNSUCCESSFUL;
798 printf("utime: ok\n");
799 return NT_STATUS_OK;
802 static NTSTATUS cmd_ftruncate(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, const char **argv)
804 int fd;
805 SMB_OFF_T off;
806 if (argc != 3) {
807 printf("Usage: ftruncate <fd> <length>\n");
808 return NT_STATUS_OK;
811 fd = atoi(argv[1]);
812 off = atoi(argv[2]);
813 if (fd < 0 || fd > 1024) {
814 printf("ftruncate: error=%d (file descriptor out of range)\n", EBADF);
815 return NT_STATUS_OK;
817 if (vfs->files[fd] == NULL) {
818 printf("ftruncate: error=%d (invalid file descriptor)\n", EBADF);
819 return NT_STATUS_OK;
822 if (SMB_VFS_FTRUNCATE(vfs->files[fd], fd, off) == -1) {
823 printf("ftruncate: error=%d (%s)\n", errno, strerror(errno));
824 return NT_STATUS_UNSUCCESSFUL;
827 printf("ftruncate: ok\n");
828 return NT_STATUS_OK;
831 static NTSTATUS cmd_lock(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, const char **argv)
833 BOOL ret;
834 int fd;
835 int op;
836 long offset;
837 long count;
838 int type;
839 const char *typestr;
841 if (argc != 6) {
842 printf("Usage: lock <fd> <op> <offset> <count> <type>\n");
843 printf(" ops: G = F_GETLK\n");
844 printf(" S = F_SETLK\n");
845 printf(" W = F_SETLKW\n");
846 printf(" type: R = F_RDLCK\n");
847 printf(" W = F_WRLCK\n");
848 printf(" U = F_UNLCK\n");
849 return NT_STATUS_OK;
852 if (sscanf(argv[1], "%d", &fd) == 0) {
853 printf("lock: error=-1 (error parsing fd)\n");
854 return NT_STATUS_UNSUCCESSFUL;
857 op = 0;
858 switch (*argv[2]) {
859 case 'G':
860 op = F_GETLK;
861 break;
862 case 'S':
863 op = F_SETLK;
864 break;
865 case 'W':
866 op = F_SETLKW;
867 break;
868 default:
869 printf("lock: error=-1 (invalid op flag!)\n");
870 return NT_STATUS_UNSUCCESSFUL;
873 if (sscanf(argv[3], "%ld", &offset) == 0) {
874 printf("lock: error=-1 (error parsing fd)\n");
875 return NT_STATUS_UNSUCCESSFUL;
878 if (sscanf(argv[4], "%ld", &count) == 0) {
879 printf("lock: error=-1 (error parsing fd)\n");
880 return NT_STATUS_UNSUCCESSFUL;
883 type = 0;
884 typestr = argv[5];
885 while(*typestr) {
886 switch (*typestr) {
887 case 'R':
888 type |= F_RDLCK;
889 break;
890 case 'W':
891 type |= F_WRLCK;
892 break;
893 case 'U':
894 type |= F_UNLCK;
895 break;
896 default:
897 printf("lock: error=-1 (invalid type flag!)\n");
898 return NT_STATUS_UNSUCCESSFUL;
900 typestr++;
903 printf("lock: debug lock(fd=%d, op=%d, offset=%ld, count=%ld, type=%d))\n", fd, op, offset, count, type);
905 if ((ret = SMB_VFS_LOCK(vfs->files[fd], fd, op, offset, count, type)) == False) {
906 printf("lock: error=%d (%s)\n", errno, strerror(errno));
907 return NT_STATUS_UNSUCCESSFUL;
910 printf("lock: ok\n");
911 return NT_STATUS_OK;
914 static NTSTATUS cmd_symlink(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, const char **argv)
916 if (argc != 3) {
917 printf("Usage: symlink <path> <link>\n");
918 return NT_STATUS_OK;
921 if (SMB_VFS_SYMLINK(vfs->conn, argv[1], argv[2]) == -1) {
922 printf("symlink: error=%d (%s)\n", errno, strerror(errno));
923 return NT_STATUS_UNSUCCESSFUL;
926 printf("symlink: ok\n");
927 return NT_STATUS_OK;
931 static NTSTATUS cmd_readlink(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, const char **argv)
933 char buffer[PATH_MAX];
934 int size;
936 if (argc != 2) {
937 printf("Usage: readlink <path>\n");
938 return NT_STATUS_OK;
941 if ((size = SMB_VFS_READLINK(vfs->conn, argv[1], buffer, PATH_MAX)) == -1) {
942 printf("readlink: error=%d (%s)\n", errno, strerror(errno));
943 return NT_STATUS_UNSUCCESSFUL;
946 buffer[size] = '\0';
947 printf("readlink: %s\n", buffer);
948 return NT_STATUS_OK;
952 static NTSTATUS cmd_link(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, const char **argv)
954 if (argc != 3) {
955 printf("Usage: link <path> <link>\n");
956 return NT_STATUS_OK;
959 if (SMB_VFS_LINK(vfs->conn, argv[1], argv[2]) == -1) {
960 printf("link: error=%d (%s)\n", errno, strerror(errno));
961 return NT_STATUS_UNSUCCESSFUL;
964 printf("link: ok\n");
965 return NT_STATUS_OK;
968 static NTSTATUS cmd_mknod(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, const char **argv)
970 mode_t mode;
971 unsigned int dev_val;
972 SMB_DEV_T dev;
974 if (argc != 4) {
975 printf("Usage: mknod <path> <mode> <dev>\n");
976 printf(" mode is octal\n");
977 printf(" dev is hex\n");
978 return NT_STATUS_OK;
981 if (sscanf(argv[2], "%o", &mode) == 0) {
982 printf("open: error=-1 (invalid mode!)\n");
983 return NT_STATUS_UNSUCCESSFUL;
986 if (sscanf(argv[3], "%x", &dev_val) == 0) {
987 printf("open: error=-1 (invalid dev!)\n");
988 return NT_STATUS_UNSUCCESSFUL;
990 dev = (SMB_DEV_T)dev_val;
992 if (SMB_VFS_MKNOD(vfs->conn, argv[1], mode, dev) == -1) {
993 printf("mknod: error=%d (%s)\n", errno, strerror(errno));
994 return NT_STATUS_UNSUCCESSFUL;
997 printf("mknod: ok\n");
998 return NT_STATUS_OK;
1001 static NTSTATUS cmd_realpath(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, const char **argv)
1003 char respath[PATH_MAX];
1005 if (argc != 2) {
1006 printf("Usage: realpath <path>\n");
1007 return NT_STATUS_OK;
1010 if (SMB_VFS_REALPATH(vfs->conn, argv[1], respath) == NULL) {
1011 printf("realpath: error=%d (%s)\n", errno, strerror(errno));
1012 return NT_STATUS_UNSUCCESSFUL;
1015 printf("realpath: ok\n");
1016 return NT_STATUS_OK;
1019 struct cmd_set vfs_commands[] = {
1021 { "VFS Commands" },
1023 { "load", cmd_load_module, "Load a module", "load <module.so>" },
1024 { "populate", cmd_populate, "Populate a data buffer", "populate <char> <size>" },
1025 { "showdata", cmd_show_data, "Show data currently in data buffer", "show_data [<offset> <len>]"},
1026 { "connect", cmd_connect, "VFS connect()", "connect" },
1027 { "disconnect", cmd_disconnect, "VFS disconnect()", "disconnect" },
1028 { "disk_free", cmd_disk_free, "VFS disk_free()", "disk_free <path>" },
1029 { "opendir", cmd_opendir, "VFS opendir()", "opendir <fname>" },
1030 { "readdir", cmd_readdir, "VFS readdir()", "readdir" },
1031 { "mkdir", cmd_mkdir, "VFS mkdir()", "mkdir <path>" },
1032 { "rmdir", cmd_pathfunc, "VFS rmdir()", "rmdir <path>" },
1033 { "closedir", cmd_closedir, "VFS closedir()", "closedir" },
1034 { "open", cmd_open, "VFS open()", "open <fname>" },
1035 { "close", cmd_close, "VFS close()", "close <fd>" },
1036 { "read", cmd_read, "VFS read()", "read <fd> <size>" },
1037 { "write", cmd_write, "VFS write()", "write <fd> <size>" },
1038 { "lseek", cmd_lseek, "VFS lseek()", "lseek <fd> <offset> <whence>" },
1039 { "rename", cmd_rename, "VFS rename()", "rename <old> <new>" },
1040 { "fsync", cmd_fsync, "VFS fsync()", "fsync <fd>" },
1041 { "stat", cmd_stat, "VFS stat()", "stat <fname>" },
1042 { "fstat", cmd_fstat, "VFS fstat()", "fstat <fd>" },
1043 { "lstat", cmd_lstat, "VFS lstat()", "lstat <fname>" },
1044 { "unlink", cmd_pathfunc, "VFS unlink()", "unlink <fname>" },
1045 { "chmod", cmd_chmod, "VFS chmod()", "chmod <path> <mode>" },
1046 { "fchmod", cmd_fchmod, "VFS fchmod()", "fchmod <fd> <mode>" },
1047 { "chown", cmd_chown, "VFS chown()", "chown <path> <uid> <gid>" },
1048 { "fchown", cmd_fchown, "VFS fchown()", "fchown <fd> <uid> <gid>" },
1049 { "chdir", cmd_pathfunc, "VFS chdir()", "chdir <path>" },
1050 { "getwd", cmd_getwd, "VFS getwd()", "getwd" },
1051 { "utime", cmd_utime, "VFS utime()", "utime <path> <access> <modify>" },
1052 { "ftruncate", cmd_ftruncate, "VFS ftruncate()", "ftruncate <fd> <length>" },
1053 { "lock", cmd_lock, "VFS lock()", "lock <f> <op> <offset> <count> <type>" },
1054 { "symlink", cmd_symlink, "VFS symlink()", "symlink <old> <new>" },
1055 { "readlink", cmd_readlink, "VFS readlink()", "readlink <path>" },
1056 { "link", cmd_link, "VFS link()", "link <oldpath> <newpath>" },
1057 { "mknod", cmd_mknod, "VFS mknod()", "mknod <path> <mode> <dev>" },
1058 { "realpath", cmd_realpath, "VFS realpath()", "realpath <path>" },
1059 { NULL }