summaryrefslogtreecommitdiff
path: root/source3/torture
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2002-09-20 16:59:48 +0000
committerJelmer Vernooij <jelmer@samba.org>2002-09-20 16:59:48 +0000
commit696fedc7ad26222c94d0ecfda4aa3fa5be2377ca (patch)
tree057c541afd30003e762c0242448ce1ac68312456 /source3/torture
parent3c1c9ac22825c2ca1ce3f7fca10047df3ebda8e5 (diff)
downloadsamba-696fedc7ad26222c94d0ecfda4aa3fa5be2377ca.tar.gz
samba-696fedc7ad26222c94d0ecfda4aa3fa5be2377ca.tar.bz2
samba-696fedc7ad26222c94d0ecfda4aa3fa5be2377ca.zip
Add framework for samtest commands
(This used to be commit f1021cbc557bfa0078e932a8268c5c9adcae0ae8)
Diffstat (limited to 'source3/torture')
-rw-r--r--source3/torture/cmd_sam.c985
-rw-r--r--source3/torture/samtest.c12
2 files changed, 117 insertions, 880 deletions
diff --git a/source3/torture/cmd_sam.c b/source3/torture/cmd_sam.c
index d276d52fe6..a2835ed69a 100644
--- a/source3/torture/cmd_sam.c
+++ b/source3/torture/cmd_sam.c
@@ -22,6 +22,26 @@
#include "includes.h"
#include "samtest.h"
+#if 0
+static struct cmd_popt_user_opts [] = {
+ { NULL, 0, POPT_ARG_CALLBACK, cmd_parse_user_opts },
+ {"username", 'u', POPT_ARG_STRING, NULL, 1, "Username to use"},
+};
+
+static void cmd_parse_user_opts(poptContext con,
+ enum poptCallbackReason reason,
+ const struct poptOption *opt,
+ const char *arg, const void *data)
+{
+ SAM_ACCOUNT_HANDLE *account = (SAM_ACCOUNT_HANDLE *)data;
+ switch(opt->val) {
+ case 'u':
+ sam_set_account_username(account, arg);
+ break;
+ }
+}
+#endif
+
static NTSTATUS cmd_load_module(struct sam_context *c, TALLOC_CTX *mem_ctx, int argc, char **argv)
{
char *plugin_arg[2];
@@ -42,961 +62,172 @@ static NTSTATUS cmd_load_module(struct sam_context *c, TALLOC_CTX *mem_ctx, int
return NT_STATUS_OK;
}
-#if 0
-static NTSTATUS cmd_populate(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, char **argv)
-{
- char c;
- size_t size;
- if (argc != 3) {
- printf("Usage: populate <char> <size>\n");
- return NT_STATUS_OK;
- }
- c = argv[1][0];
- size = atoi(argv[2]);
- vfs->data = (char *)talloc(mem_ctx, size);
- if (vfs->data == NULL) {
- printf("populate: error=-1 (not enough memory)");
- return NT_STATUS_UNSUCCESSFUL;
- }
- memset(vfs->data, c, size);
- vfs->data_size = size;
- return NT_STATUS_OK;
-}
-
-static NTSTATUS cmd_show_data(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, char **argv)
-{
- size_t offset;
- size_t len;
- if (argc != 1 && argc != 3) {
- printf("Usage: showdata [<offset> <len>]\n");
- return NT_STATUS_OK;
- }
- if (vfs->data == NULL || vfs->data_size == 0) {
- printf("show_data: error=-1 (buffer empty)\n");
- return NT_STATUS_UNSUCCESSFUL;
- }
-
- if (argc == 3) {
- offset = atoi(argv[1]);
- len = atoi(argv[2]);
- } else {
- offset = 0;
- len = vfs->data_size;
- }
- if ((offset + len) > vfs->data_size) {
- printf("show_data: error=-1 (not enough data in buffer)\n");
- return NT_STATUS_UNSUCCESSFUL;
- }
- dump_data(0, (char *)(vfs->data) + offset, len);
- return NT_STATUS_OK;
-}
-
-static NTSTATUS cmd_connect(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, char **argv)
-{
- vfs->conn->vfs_ops.connect(vfs->conn, lp_servicename(vfs->conn->service), "vfstest");
- return NT_STATUS_OK;
-}
-
-static NTSTATUS cmd_disconnect(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, char **argv)
-{
- vfs->conn->vfs_ops.disconnect(vfs->conn);
- return NT_STATUS_OK;
-}
-
-static NTSTATUS cmd_disk_free(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, char **argv)
-{
- SMB_BIG_UINT diskfree, bsize, dfree, dsize;
- if (argc != 2) {
- printf("Usage: disk_free <path>\n");
- return NT_STATUS_OK;
- }
-
- diskfree = vfs->conn->vfs_ops.disk_free(vfs->conn, argv[1], False, &bsize, &dfree, &dsize);
- printf("disk_free: %ld, bsize = %ld, dfree = %ld, dsize = %ld\n", diskfree, bsize, dfree, dsize);
- return NT_STATUS_OK;
-}
-
-
-static NTSTATUS cmd_opendir(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, char **argv)
-{
- if (argc != 2) {
- printf("Usage: opendir <fname>\n");
- return NT_STATUS_OK;
- }
-
- vfs->currentdir = vfs->conn->vfs_ops.opendir(vfs->conn, argv[1]);
- if (vfs->currentdir == NULL) {
- printf("opendir error=%d (%s)\n", errno, strerror(errno));
- return NT_STATUS_UNSUCCESSFUL;
- }
-
- printf("opendir: ok\n");
- return NT_STATUS_OK;
-}
-
-
-static NTSTATUS cmd_readdir(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, char **argv)
-{
- struct dirent *dent;
-
- if (vfs->currentdir == NULL) {
- printf("readdir: error=-1 (no open directory)\n");
- return NT_STATUS_UNSUCCESSFUL;
- }
-
- dent = vfs->conn->vfs_ops.readdir(vfs->conn, vfs->currentdir);
- if (dent == NULL) {
- printf("readdir: NULL\n");
- return NT_STATUS_OK;
- }
-
- printf("readdir: %s\n", dent->d_name);
- return NT_STATUS_OK;
-}
-
-
-static NTSTATUS cmd_mkdir(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, char **argv)
+static NTSTATUS cmd_get_sec_desc(struct sam_context *c, TALLOC_CTX *mem_ctx, int argc, char **argv)
{
- if (argc != 2) {
- printf("Usage: mkdir <path>\n");
- return NT_STATUS_OK;
- }
-
- if (vfs->conn->vfs_ops.mkdir(vfs->conn, argv[1], 00755) == -1) {
- printf("mkdir error=%d (%s)\n", errno, strerror(errno));
- return NT_STATUS_UNSUCCESSFUL;
- }
-
- printf("mkdir: ok\n");
- return NT_STATUS_OK;
+ return NT_STATUS_NOT_IMPLEMENTED;
}
-
-static NTSTATUS cmd_closedir(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, char **argv)
+static NTSTATUS cmd_set_sec_desc(struct sam_context *c, TALLOC_CTX *mem_ctx, int argc, char **argv)
{
- int ret;
-
- if (vfs->currentdir == NULL) {
- printf("closedir: failure (no directory open)\n");
- return NT_STATUS_UNSUCCESSFUL;
- }
-
- ret = vfs->conn->vfs_ops.closedir(vfs->conn, vfs->currentdir);
- if (ret == -1) {
- printf("closedir failure: %s\n", strerror(errno));
- return NT_STATUS_UNSUCCESSFUL;
- }
-
- printf("closedir: ok\n");
- vfs->currentdir = NULL;
- return NT_STATUS_OK;
+ return NT_STATUS_NOT_IMPLEMENTED;
}
-
-static NTSTATUS cmd_open(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, char **argv)
+static NTSTATUS cmd_lookup_sid(struct sam_context *c, TALLOC_CTX *mem_ctx, int argc, char **argv)
{
- int flags, fd;
- mode_t mode;
- char *flagstr;
-
- mode = 00400;
-
- if (argc < 3 || argc > 5) {
- printf("Usage: open <filename> <flags> <mode>\n");
- printf(" flags: O = O_RDONLY\n");
- printf(" R = O_RDWR\n");
- printf(" W = O_WRONLY\n");
- printf(" C = O_CREAT\n");
- printf(" E = O_EXCL\n");
- printf(" T = O_TRUNC\n");
- printf(" A = O_APPEND\n");
- printf(" N = O_NONBLOCK/O_NDELAY\n");
-#ifdef O_SYNC
- printf(" S = O_SYNC\n");
-#endif
-#ifdef O_NOFOLLOW
- printf(" F = O_NOFOLLOW\n");
-#endif
- printf(" mode: see open.2\n");
- printf(" mode is ignored if C flag not present\n");
- printf(" mode defaults to 00400\n");
- return NT_STATUS_OK;
- }
- flags = 0;
- flagstr = argv[2];
- while (*flagstr) {
- switch (*flagstr) {
- case 'O':
- flags |= O_RDONLY;
- break;
- case 'R':
- flags |= O_RDWR;
- break;
- case 'W':
- flags |= O_WRONLY;
- break;
- case 'C':
- flags |= O_CREAT;
- break;
- case 'E':
- flags |= O_EXCL;
- break;
- case 'T':
- flags |= O_TRUNC;
- break;
- case 'A':
- flags |= O_APPEND;
- break;
- case 'N':
- flags |= O_NONBLOCK;
- break;
-#ifdef O_SYNC
- case 'S':
- flags |= O_SYNC;
- break;
-#endif
-#ifdef O_NOFOLLOW
- case 'F':
- flags |= O_NOFOLLOW;
- break;
-#endif
- default:
- printf("open: error=-1 (invalid flag!)\n");
- return NT_STATUS_UNSUCCESSFUL;
- }
- flagstr++;
- }
- if ((flags & O_CREAT) && argc == 4) {
- if (sscanf(argv[3], "%o", &mode) == 0) {
- printf("open: error=-1 (invalid mode!)\n");
- return NT_STATUS_UNSUCCESSFUL;
- }
- }
-
- fd = vfs->conn->vfs_ops.open(vfs->conn, argv[1], flags, mode);
- if (fd == -1) {
- printf("open: error=%d (%s)\n", errno, strerror(errno));
- return NT_STATUS_UNSUCCESSFUL;
- }
-
- vfs->files[fd] = (struct files_struct *)malloc(sizeof(struct files_struct));
- vfs->files[fd]->fsp_name = strdup(argv[1]);
- vfs->files[fd]->fd = fd;
- vfs->files[fd]->conn = vfs->conn;
- printf("open: fd=%d\n", fd);
- return NT_STATUS_OK;
+ return NT_STATUS_NOT_IMPLEMENTED;
}
-
-static NTSTATUS cmd_pathfunc(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, char **argv)
+static NTSTATUS cmd_lookup_name(struct sam_context *c, TALLOC_CTX *mem_ctx, int argc, char **argv)
{
- int ret = -1;
-
- if (argc != 2) {
- printf("Usage: %s <path>\n", argv[0]);
- return NT_STATUS_OK;
- }
-
- if (strcmp("rmdir", argv[0]) == 0 ) {
- ret = vfs->conn->vfs_ops.rmdir(vfs->conn, argv[1]);
- } else if (strcmp("unlink", argv[0]) == 0 ) {
- ret = vfs->conn->vfs_ops.unlink(vfs->conn, argv[1]);
- } else if (strcmp("chdir", argv[0]) == 0 ) {
- ret = vfs->conn->vfs_ops.chdir(vfs->conn, argv[1]);
- } else {
- printf("%s: error=%d (invalid function name!)\n", argv[0], errno);
- return NT_STATUS_UNSUCCESSFUL;
- }
-
- if (ret == -1) {
- printf("%s: error=%d (%s)\n", argv[0], errno, strerror(errno));
- return NT_STATUS_UNSUCCESSFUL;
- }
-
- printf("%s: ok\n", argv[0]);
- return NT_STATUS_OK;
+ return NT_STATUS_NOT_IMPLEMENTED;
}
-
-static NTSTATUS cmd_close(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, char **argv)
+static NTSTATUS cmd_lookup_account(struct sam_context *c, TALLOC_CTX *mem_ctx, int argc, char **argv)
{
- int fd, ret;
-
- if (argc != 2) {
- printf("Usage: close <fd>\n");
- return NT_STATUS_OK;
- }
-
- fd = atoi(argv[1]);
- if (vfs->files[fd] == NULL) {
- printf("close: error=-1 (invalid file descriptor)\n");
- return NT_STATUS_OK;
- }
-
- ret = vfs->conn->vfs_ops.close(vfs->files[fd], fd);
- if (ret == -1 )
- printf("close: error=%d (%s)\n", errno, strerror(errno));
- else
- printf("close: ok\n");
-
- SAFE_FREE(vfs->files[fd]->fsp_name);
- SAFE_FREE(vfs->files[fd]);
- vfs->files[fd] = NULL;
- return NT_STATUS_OK;
+ return NT_STATUS_NOT_IMPLEMENTED;
}
-
-static NTSTATUS cmd_read(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, char **argv)
+static NTSTATUS cmd_lookup_group(struct sam_context *c, TALLOC_CTX *mem_ctx, int argc, char **argv)
{
- int fd;
- size_t size, rsize;
-
- if (argc != 3) {
- printf("Usage: read <fd> <size>\n");
- return NT_STATUS_OK;
- }
-
- /* do some error checking on these */
- fd = atoi(argv[1]);
- size = atoi(argv[2]);
- vfs->data = (char *)talloc(mem_ctx, size);
- if (vfs->data == NULL) {
- printf("read: error=-1 (not enough memory)");
- return NT_STATUS_UNSUCCESSFUL;
- }
- vfs->data_size = size;
-
- rsize = vfs->conn->vfs_ops.read(vfs->files[fd], fd, vfs->data, size);
- if (rsize == -1) {
- printf("read: error=%d (%s)\n", errno, strerror(errno));
- return NT_STATUS_UNSUCCESSFUL;
- }
-
- printf("read: ok\n");
- return NT_STATUS_OK;
+ return NT_STATUS_NOT_IMPLEMENTED;
}
-
-static NTSTATUS cmd_write(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, char **argv)
+static NTSTATUS cmd_update_domain(struct sam_context *c, TALLOC_CTX *mem_ctx, int argc, char **argv)
{
- int fd, size, wsize;
-
- if (argc != 3) {
- printf("Usage: write <fd> <size>\n");
- return NT_STATUS_OK;
- }
-
- /* some error checking should go here */
- fd = atoi(argv[1]);
- size = atoi(argv[2]);
- if (vfs->data == NULL) {
- printf("write: error=-1 (buffer empty, please populate it before writing)");
- return NT_STATUS_UNSUCCESSFUL;
- }
-
- if (vfs->data_size < size) {
- printf("write: error=-1 (buffer too small, please put some more data in)");
- return NT_STATUS_UNSUCCESSFUL;
- }
-
- wsize = vfs->conn->vfs_ops.write(vfs->files[fd], fd, vfs->data, size);
-
- if (wsize == -1) {
- printf("write: error=%d (%s)\n", errno, strerror(errno));
- return NT_STATUS_UNSUCCESSFUL;
- }
-
- printf("write: ok\n");
- return NT_STATUS_OK;
+ return NT_STATUS_NOT_IMPLEMENTED;
}
-
-static NTSTATUS cmd_lseek(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, char **argv)
+static NTSTATUS cmd_show_domain(struct sam_context *c, TALLOC_CTX *mem_ctx, int argc, char **argv)
{
- int fd, offset, whence;
- SMB_OFF_T pos;
-
- if (argc != 4) {
- printf("Usage: lseek <fd> <offset> <whence>\n...where whence is 1 => SEEK_SET, 2 => SEEK_CUR, 3 => SEEK_END\n");
- return NT_STATUS_OK;
- }
-
- fd = atoi(argv[1]);
- offset = atoi(argv[2]);
- whence = atoi(argv[3]);
- switch (whence) {
- case 1: whence = SEEK_SET; break;
- case 2: whence = SEEK_CUR; break;
- default: whence = SEEK_END;
- }
-
- pos = vfs->conn->vfs_ops.lseek(vfs->files[fd], fd, offset, whence);
- if (pos == (SMB_OFF_T)-1) {
- printf("lseek: error=%d (%s)\n", errno, strerror(errno));
- return NT_STATUS_UNSUCCESSFUL;
- }
-
- printf("lseek: ok\n");
- return NT_STATUS_OK;
+ return NT_STATUS_NOT_IMPLEMENTED;
}
-
-static NTSTATUS cmd_rename(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, char **argv)
+static NTSTATUS cmd_create_account(struct sam_context *c, TALLOC_CTX *mem_ctx, int argc, char **argv)
{
- int ret;
- if (argc != 3) {
- printf("Usage: rename <old> <new>\n");
- return NT_STATUS_OK;
- }
-
- ret = vfs->conn->vfs_ops.rename(vfs->conn, argv[1], argv[2]);
- if (ret == -1) {
- printf("rename: error=%d (%s)\n", errno, strerror(errno));
- return NT_STATUS_UNSUCCESSFUL;
- }
-
- printf("rename: ok\n");
- return NT_STATUS_OK;
+ return NT_STATUS_NOT_IMPLEMENTED;
}
-
-static NTSTATUS cmd_fsync(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, char **argv)
+static NTSTATUS cmd_update_account(struct sam_context *c, TALLOC_CTX *mem_ctx, int argc, char **argv)
{
- int ret, fd;
- if (argc != 2) {
- printf("Usage: fsync <fd>\n");
- return NT_STATUS_OK;
- }
-
- fd = atoi(argv[1]);
- ret = vfs->conn->vfs_ops.fsync(vfs->files[fd], fd);
- if (ret == -1) {
- printf("fsync: error=%d (%s)\n", errno, strerror(errno));
- return NT_STATUS_UNSUCCESSFUL;
- }
-
- printf("fsync: ok\n");
- return NT_STATUS_OK;
+ return NT_STATUS_NOT_IMPLEMENTED;
}
-
-static NTSTATUS cmd_stat(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, char **argv)
+static NTSTATUS cmd_delete_account(struct sam_context *c, TALLOC_CTX *mem_ctx, int argc, char **argv)
{
- int ret;
- char *user;
- char *group;
- struct passwd *pwd;
- struct group *grp;
- SMB_STRUCT_STAT st;
-
- if (argc != 2) {
- printf("Usage: stat <fname>\n");
- return NT_STATUS_OK;
- }
-
- ret = vfs->conn->vfs_ops.stat(vfs->conn, argv[1], &st);
- if (ret == -1) {
- printf("stat: error=%d (%s)\n", errno, strerror(errno));
- return NT_STATUS_UNSUCCESSFUL;
- }
-
- pwd = sys_getpwuid(st.st_uid);
- if (pwd != NULL) user = strdup(pwd->pw_name);
- else user = null_string;
- grp = sys_getgrgid(st.st_gid);
- if (grp != NULL) group = strdup(grp->gr_name);
- else group = null_string;
-
- printf("stat: ok\n");
- printf(" File: %s", argv[1]);
- if (S_ISREG(st.st_mode)) printf(" Regular File\n");
- else if (S_ISDIR(st.st_mode)) printf(" Directory\n");
- else if (S_ISCHR(st.st_mode)) printf(" Character Device\n");
- else if (S_ISBLK(st.st_mode)) printf(" Block Device\n");
- else if (S_ISFIFO(st.st_mode)) printf(" Fifo\n");
- else if (S_ISLNK(st.st_mode)) printf(" Symbolic Link\n");
- else if (S_ISSOCK(st.st_mode)) printf(" Socket\n");
- printf(" Size: %10d", st.st_size);
- printf(" Blocks: %9d", st.st_blocks);
- printf(" IO Block: %d\n", st.st_blksize);
- printf(" Device: 0x%10x", st.st_dev);
- printf(" Inode: %10d", st.st_ino);
- printf(" Links: %10d\n", st.st_nlink);
- printf(" Access: %05o", (st.st_mode) & 007777);
- printf(" Uid: %5d/%.16s Gid: %5d/%.16s\n", st.st_uid, user, st.st_gid, group);
- printf(" Access: %s", ctime(&(st.st_atime)));
- printf(" Modify: %s", ctime(&(st.st_mtime)));
- printf(" Change: %s", ctime(&(st.st_ctime)));
- if (user != null_string) SAFE_FREE(user);
- if (group!= null_string) SAFE_FREE(group);
- return NT_STATUS_OK;
+ return NT_STATUS_NOT_IMPLEMENTED;
}
-
-static NTSTATUS cmd_fstat(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, char **argv)
+static NTSTATUS cmd_enum_accounts(struct sam_context *c, TALLOC_CTX *mem_ctx, int argc, char **argv)
{
- int fd;
- char *user;
- char *group;
- struct passwd *pwd;
- struct group *grp;
- SMB_STRUCT_STAT st;
-
- if (argc != 2) {
- printf("Usage: fstat <fd>\n");
- return NT_STATUS_OK;
- }
-
- fd = atoi(argv[1]);
- if (fd < 0 || fd > 1024) {
- printf("fstat: error=%d (file descriptor out of range)\n", EBADF);
- return NT_STATUS_OK;
- }
-
- if (vfs->files[fd] == NULL) {
- printf("fstat: error=%d (invalid file descriptor)\n", EBADF);
- return NT_STATUS_OK;
- }
-
- if (vfs->conn->vfs_ops.fstat(vfs->files[fd], fd, &st) == -1) {
- printf("fstat: error=%d (%s)\n", errno, strerror(errno));
- return NT_STATUS_UNSUCCESSFUL;
- }
-
- pwd = sys_getpwuid(st.st_uid);
- if (pwd != NULL) user = strdup(pwd->pw_name);
- else user = null_string;
- grp = sys_getgrgid(st.st_gid);
- if (grp != NULL) group = strdup(grp->gr_name);
- else group = null_string;
-
- printf("fstat: ok\n");
- if (S_ISREG(st.st_mode)) printf(" Regular File\n");
- else if (S_ISDIR(st.st_mode)) printf(" Directory\n");
- else if (S_ISCHR(st.st_mode)) printf(" Character Device\n");
- else if (S_ISBLK(st.st_mode)) printf(" Block Device\n");
- else if (S_ISFIFO(st.st_mode)) printf(" Fifo\n");
- else if (S_ISLNK(st.st_mode)) printf(" Symbolic Link\n");
- else if (S_ISSOCK(st.st_mode)) printf(" Socket\n");
- printf(" Size: %10d", st.st_size);
- printf(" Blocks: %9d", st.st_blocks);
- printf(" IO Block: %d\n", st.st_blksize);
- printf(" Device: 0x%10x", st.st_dev);
- printf(" Inode: %10d", st.st_ino);
- printf(" Links: %10d\n", st.st_nlink);
- printf(" Access: %05o", (st.st_mode) & 007777);
- printf(" Uid: %5d/%.16s Gid: %5d/%.16s\n", st.st_uid, user, st.st_gid, group);
- printf(" Access: %s", ctime(&(st.st_atime)));
- printf(" Modify: %s", ctime(&(st.st_mtime)));
- printf(" Change: %s", ctime(&(st.st_ctime)));
- if (user != null_string) SAFE_FREE(user);
- if (group!= null_string) SAFE_FREE(group);
- return NT_STATUS_OK;
+ return NT_STATUS_NOT_IMPLEMENTED;
}
-
-static NTSTATUS cmd_lstat(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, char **argv)
+static NTSTATUS cmd_lookup_account_sid(struct sam_context *c, TALLOC_CTX *mem_ctx, int argc, char **argv)
{
- char *user;
- char *group;
- struct passwd *pwd;
- struct group *grp;
- SMB_STRUCT_STAT st;
-
- if (argc != 2) {
- printf("Usage: lstat <path>\n");
- return NT_STATUS_OK;
- }
-
- if (vfs->conn->vfs_ops.lstat(vfs->conn, argv[1], &st) == -1) {
- printf("lstat: error=%d (%s)\n", errno, strerror(errno));
- return NT_STATUS_UNSUCCESSFUL;
- }
-
- pwd = sys_getpwuid(st.st_uid);
- if (pwd != NULL) user = strdup(pwd->pw_name);
- else user = null_string;
- grp = sys_getgrgid(st.st_gid);
- if (grp != NULL) group = strdup(grp->gr_name);
- else group = null_string;
-
- printf("lstat: ok\n");
- if (S_ISREG(st.st_mode)) printf(" Regular File\n");
- else if (S_ISDIR(st.st_mode)) printf(" Directory\n");
- else if (S_ISCHR(st.st_mode)) printf(" Character Device\n");
- else if (S_ISBLK(st.st_mode)) printf(" Block Device\n");
- else if (S_ISFIFO(st.st_mode)) printf(" Fifo\n");
- else if (S_ISLNK(st.st_mode)) printf(" Symbolic Link\n");
- else if (S_ISSOCK(st.st_mode)) printf(" Socket\n");
- printf(" Size: %10d", st.st_size);
- printf(" Blocks: %9d", st.st_blocks);
- printf(" IO Block: %d\n", st.st_blksize);
- printf(" Device: 0x%10x", st.st_dev);
- printf(" Inode: %10d", st.st_ino);
- printf(" Links: %10d\n", st.st_nlink);
- printf(" Access: %05o", (st.st_mode) & 007777);
- printf(" Uid: %5d/%.16s Gid: %5d/%.16s\n", st.st_uid, user, st.st_gid, group);
- printf(" Access: %s", ctime(&(st.st_atime)));
- printf(" Modify: %s", ctime(&(st.st_mtime)));
- printf(" Change: %s", ctime(&(st.st_ctime)));
- if (user != null_string) SAFE_FREE(user);
- if (group!= null_string) SAFE_FREE(group);
- return NT_STATUS_OK;
+ return NT_STATUS_NOT_IMPLEMENTED;
}
-
-static NTSTATUS cmd_chmod(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, char **argv)
+static NTSTATUS cmd_lookup_account_name(struct sam_context *c, TALLOC_CTX *mem_ctx, int argc, char **argv)
{
- mode_t mode;
- if (argc != 3) {
- printf("Usage: chmod <path> <mode>\n");
- return NT_STATUS_OK;
- }
-
- mode = atoi(argv[2]);
- if (vfs->conn->vfs_ops.chmod(vfs->conn, argv[1], mode) == -1) {
- printf("chmod: error=%d (%s)\n", errno, strerror(errno));
- return NT_STATUS_UNSUCCESSFUL;
- }
-
- printf("chmod: ok\n");
- return NT_STATUS_OK;
+ return NT_STATUS_NOT_IMPLEMENTED;
}
-
-static NTSTATUS cmd_fchmod(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, char **argv)
+static NTSTATUS cmd_create_group(struct sam_context *c, TALLOC_CTX *mem_ctx, int argc, char **argv)
{
- int fd;
- mode_t mode;
- if (argc != 3) {
- printf("Usage: fchmod <fd> <mode>\n");
- return NT_STATUS_OK;
- }
-
- fd = atoi(argv[1]);
- mode = atoi(argv[2]);
- if (fd < 0 || fd > 1024) {
- printf("fchmod: error=%d (file descriptor out of range)\n", EBADF);
- return NT_STATUS_OK;
- }
- if (vfs->files[fd] == NULL) {
- printf("fchmod: error=%d (invalid file descriptor)\n", EBADF);
- return NT_STATUS_OK;
- }
-
- if (vfs->conn->vfs_ops.fchmod(vfs->files[fd], fd, mode) == -1) {
- printf("fchmod: error=%d (%s)\n", errno, strerror(errno));
- return NT_STATUS_UNSUCCESSFUL;
- }
-
- printf("fchmod: ok\n");
- return NT_STATUS_OK;
+ return NT_STATUS_NOT_IMPLEMENTED;
}
-
-static NTSTATUS cmd_chown(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, char **argv)
+static NTSTATUS cmd_update_group(struct sam_context *c, TALLOC_CTX *mem_ctx, int argc, char **argv)
{
- uid_t uid;
- gid_t gid;
- if (argc != 4) {
- printf("Usage: chown <path> <uid> <gid>\n");
- return NT_STATUS_OK;
- }
-
- uid = atoi(argv[2]);
- gid = atoi(argv[3]);
- if (vfs->conn->vfs_ops.chown(vfs->conn, argv[1], uid, gid) == -1) {
- printf("chown: error=%d (%s)\n", errno, strerror(errno));
- return NT_STATUS_UNSUCCESSFUL;
- }
-
- printf("chown: ok\n");
- return NT_STATUS_OK;
+ return NT_STATUS_NOT_IMPLEMENTED;
}
-
-static NTSTATUS cmd_fchown(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, char **argv)
+static NTSTATUS cmd_delete_group(struct sam_context *c, TALLOC_CTX *mem_ctx, int argc, char **argv)
{
- uid_t uid;
- gid_t gid;
- int fd;
- if (argc != 4) {
- printf("Usage: fchown <fd> <uid> <gid>\n");
- return NT_STATUS_OK;
- }
-
- uid = atoi(argv[2]);
- gid = atoi(argv[3]);
- fd = atoi(argv[1]);
- if (fd < 0 || fd > 1024) {
- printf("fchown: faliure=%d (file descriptor out of range)\n", EBADF);
- return NT_STATUS_OK;
- }
- if (vfs->files[fd] == NULL) {
- printf("fchown: error=%d (invalid file descriptor)\n", EBADF);
- return NT_STATUS_OK;
- }
- if (vfs->conn->vfs_ops.fchown(vfs->files[fd], fd, uid, gid) == -1) {
- printf("fchown error=%d (%s)\n", errno, strerror(errno));
- return NT_STATUS_UNSUCCESSFUL;
- }
-
- printf("fchown: ok\n");
- return NT_STATUS_OK;
+ return NT_STATUS_NOT_IMPLEMENTED;
}
-
-static NTSTATUS cmd_getwd(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, char **argv)
+static NTSTATUS cmd_enum_groups(struct sam_context *c, TALLOC_CTX *mem_ctx, int argc, char **argv)
{
- char buf[PATH_MAX];
- if (vfs->conn->vfs_ops.getwd(vfs->conn, buf) == NULL) {
- printf("getwd: error=%d (%s)\n", errno, strerror(errno));
- return NT_STATUS_UNSUCCESSFUL;
- }
-
- printf("getwd: %s\n", buf);
- return NT_STATUS_OK;
+ return NT_STATUS_NOT_IMPLEMENTED;
}
-static NTSTATUS cmd_utime(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, char **argv)
+static NTSTATUS cmd_lookup_group_sid(struct sam_context *c, TALLOC_CTX *mem_ctx, int argc, char **argv)
{
- struct utimbuf times;
- if (argc != 4) {
- printf("Usage: utime <path> <access> <modify>\n");
- return NT_STATUS_OK;
- }
- times.actime = atoi(argv[2]);
- times.modtime = atoi(argv[3]);
- if (vfs->conn->vfs_ops.utime(vfs->conn, argv[1], &times) != 0) {
- printf("utime: error=%d (%s)\n", errno, strerror(errno));
- return NT_STATUS_UNSUCCESSFUL;
- }
-
- printf("utime: ok\n");
- return NT_STATUS_OK;
+ return NT_STATUS_NOT_IMPLEMENTED;
}
-static NTSTATUS cmd_ftruncate(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, char **argv)
+static NTSTATUS cmd_lookup_group_name(struct sam_context *c, TALLOC_CTX *mem_ctx, int argc, char **argv)
{
- int fd;
- SMB_OFF_T off;
- if (argc != 3) {
- printf("Usage: ftruncate <fd> <length>\n");
- return NT_STATUS_OK;
- }
-
- fd = atoi(argv[1]);
- off = atoi(argv[2]);
- if (fd < 0 || fd > 1024) {
- printf("ftruncate: error=%d (file descriptor out of range)\n", EBADF);
- return NT_STATUS_OK;
- }
- if (vfs->files[fd] == NULL) {
- printf("ftruncate: error=%d (invalid file descriptor)\n", EBADF);
- return NT_STATUS_OK;
- }
-
- if (vfs->conn->vfs_ops.ftruncate(vfs->files[fd], fd, off) == -1) {
- printf("ftruncate: error=%d (%s)\n", errno, strerror(errno));
- return NT_STATUS_UNSUCCESSFUL;
- }
-
- printf("ftruncate: ok\n");
- return NT_STATUS_OK;
+ return NT_STATUS_NOT_IMPLEMENTED;
}
-static NTSTATUS cmd_lock(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, char **argv)
+static NTSTATUS cmd_group_add_member(struct sam_context *c, TALLOC_CTX *mem_ctx, int argc, char **argv)
{
- BOOL ret;
- int fd;
- int op;
- long offset;
- long count;
- int type;
- char *typestr;
-
- if (argc != 6) {
- printf("Usage: lock <fd> <op> <offset> <count> <type>\n");
- printf(" ops: G = F_GETLK\n");
- printf(" S = F_SETLK\n");
- printf(" W = F_SETLKW\n");
- printf(" type: R = F_RDLCK\n");
- printf(" W = F_WRLCK\n");
- printf(" U = F_UNLCK\n");
- return NT_STATUS_OK;
- }
-
- if (sscanf(argv[1], "%d", &fd) == 0) {
- printf("lock: error=-1 (error parsing fd)\n");
- return NT_STATUS_UNSUCCESSFUL;
- }
-
- op = 0;
- switch (*argv[2]) {
- case 'G':
- op = F_GETLK;
- break;
- case 'S':
- op = F_SETLK;
- break;
- case 'W':
- op = F_SETLKW;
- break;
- default:
- printf("lock: error=-1 (invalid op flag!)\n");
- return NT_STATUS_UNSUCCESSFUL;
- }
-
- if (sscanf(argv[3], "%ld", &offset) == 0) {
- printf("lock: error=-1 (error parsing fd)\n");
- return NT_STATUS_UNSUCCESSFUL;
- }
-
- if (sscanf(argv[4], "%ld", &count) == 0) {
- printf("lock: error=-1 (error parsing fd)\n");
- return NT_STATUS_UNSUCCESSFUL;
- }
-
- type = 0;
- typestr = argv[5];
- while(*typestr) {
- switch (*typestr) {
- case 'R':
- type |= F_RDLCK;
- break;
- case 'W':
- type |= F_WRLCK;
- break;
- case 'U':
- type |= F_UNLCK;
- break;
- default:
- printf("lock: error=-1 (invalid type flag!)\n");
- return NT_STATUS_UNSUCCESSFUL;
- }
- typestr++;
- }
-
- printf("lock: debug lock(fd=%d, op=%d, offset=%ld, count=%ld, type=%d))\n", fd, op, offset, count, type);
-
- if ((ret = vfs->conn->vfs_ops.lock(vfs->files[fd], fd, op, offset, count, type)) == False) {
- printf("lock: error=%d (%s)\n", errno, strerror(errno));
- return NT_STATUS_UNSUCCESSFUL;
- }
-
- printf("lock: ok\n");
- return NT_STATUS_OK;
+ return NT_STATUS_NOT_IMPLEMENTED;
}
-static NTSTATUS cmd_symlink(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, char **argv)
+static NTSTATUS cmd_group_del_member(struct sam_context *c, TALLOC_CTX *mem_ctx, int argc, char **argv)
{
- if (argc != 3) {
- printf("Usage: symlink <path> <link>\n");
- return NT_STATUS_OK;
- }
-
- if (vfs->conn->vfs_ops.symlink(vfs->conn, argv[1], argv[2]) == -1) {
- printf("symlink: error=%d (%s)\n", errno, strerror(errno));
- return NT_STATUS_UNSUCCESSFUL;
- }
-
- printf("symlink: ok\n");
- return NT_STATUS_OK;
+ return NT_STATUS_NOT_IMPLEMENTED;
}
-static NTSTATUS cmd_readlink(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, char **argv)
+static NTSTATUS cmd_group_enum(struct sam_context *c, TALLOC_CTX *mem_ctx, int argc, char **argv)
{
- char buffer[PATH_MAX];
- int size;
-
- if (argc != 2) {
- printf("Usage: readlink <path>\n");
- return NT_STATUS_OK;
- }
-
- if ((size = vfs->conn->vfs_ops.readlink(vfs->conn, argv[1], buffer, PATH_MAX)) == -1) {
- printf("readlink: error=%d (%s)\n", errno, strerror(errno));
- return NT_STATUS_UNSUCCESSFUL;
- }
-
- buffer[size] = '\0';
- printf("readlink: %s\n", buffer);
- return NT_STATUS_OK;
+ return NT_STATUS_NOT_IMPLEMENTED;
}
-static NTSTATUS cmd_link(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, char **argv)
+static NTSTATUS cmd_get_sid_groups(struct sam_context *c, TALLOC_CTX *mem_ctx, int argc, char **argv)
{
- if (argc != 3) {
- printf("Usage: link <path> <link>\n");
- return NT_STATUS_OK;
- }
-
- if (vfs->conn->vfs_ops.link(vfs->conn, argv[1], argv[2]) == -1) {
- printf("link: error=%d (%s)\n", errno, strerror(errno));
- return NT_STATUS_UNSUCCESSFUL;
- }
-
- printf("link: ok\n");
- return NT_STATUS_OK;
-}
-
-static NTSTATUS cmd_mknod(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, char **argv)
-{
- mode_t mode;
- SMB_DEV_T dev;
-
- if (argc != 4) {
- printf("Usage: mknod <path> <mode> <dev>\n");
- printf(" mode is octal\n");
- printf(" dev is hex\n");
- return NT_STATUS_OK;
- }
-
- if (sscanf(argv[2], "%o", &mode) == 0) {
- printf("open: error=-1 (invalid mode!)\n");
- return NT_STATUS_UNSUCCESSFUL;
- }
-
- if (sscanf(argv[3], "%x", &dev) == 0) {
- printf("open: error=-1 (invalid dev!)\n");
- return NT_STATUS_UNSUCCESSFUL;
- }
-
- if (vfs->conn->vfs_ops.mknod(vfs->conn, argv[1], mode, dev) == -1) {
- printf("mknod: error=%d (%s)\n", errno, strerror(errno));
- return NT_STATUS_UNSUCCESSFUL;
- }
-
- printf("mknod: ok\n");
- return NT_STATUS_OK;
+ return NT_STATUS_NOT_IMPLEMENTED;
}
-static NTSTATUS cmd_realpath(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, char **argv)
-{
- char respath[PATH_MAX];
-
- if (argc != 2) {
- printf("Usage: realpath <path>\n");
- return NT_STATUS_OK;
- }
+struct cmd_set sam_general_commands[] = {
- if (vfs->conn->vfs_ops.realpath(vfs->conn, argv[1], respath) == NULL) {
- printf("realpath: error=%d (%s)\n", errno, strerror(errno));
- return NT_STATUS_UNSUCCESSFUL;
- }
+ { "General SAM Commands" },
- printf("realpath: ok\n");
- return NT_STATUS_OK;
-}
-
-#endif
+ { "load", cmd_load_module, "Load a module", "load <module.so>" },
+ { "get_sec_desc", cmd_get_sec_desc, "Get security descriptor info", "get_sec_desc <access-token> <sid>" },
+ { "set_sec_desc", cmd_set_sec_desc, "Set security descriptor info", "set_sec_desc <access-token> <sid>" },
+ { "lookup_sid", cmd_lookup_sid, "Lookup type of specified SID", "lookup_sid <sid>" },
+ { "lookup_name", cmd_lookup_name, "Lookup type of specified name", "lookup_name <sid>" },
+ { NULL }
+};
-struct cmd_set sam_commands[] = {
+struct cmd_set sam_domain_commands[] = {
+ { "Domain Commands" },
+ { "update_domain", cmd_update_domain, "Update domain information", "update_domain [domain-options] domain-name | domain-sid" },
+ { "show_domain", cmd_show_domain, "Show domain information", "show_domain domain-sid | domain-name" },
+ { NULL }
+};
- { "SAM Commands" },
+struct cmd_set sam_account_commands[] = {
+ { "Account Commands" },
+ { "create_account", cmd_create_account, "Create a new account with specified properties", "create_account [account-options]" },
+ { "update_account", cmd_update_account, "Update an existing account", "update_account [account-options] account-sid | account-name" },
+ { "delete_account", cmd_delete_account, "Delete an account", "delete_account account-sid | account-name" },
+ { "enum_accounts", cmd_enum_accounts, "Enumerate all accounts", "enum_accounts <token> <acct-ctrl>" },
+ { "lookup_account", cmd_lookup_account, "Lookup an account by either sid or name", "lookup_account account-sid | account-name" },
+ { "lookup_account_sid", cmd_lookup_account_sid, "Lookup an account by sid", "lookup_account_sid account-sid" },
+ { "lookup_account_name", cmd_lookup_account_name, "Lookup an account by name", "lookup_account_name account-name" },
+ { NULL }
+};
- { "load", cmd_load_module, "Load a module", "load <module.so>" },
+struct cmd_set sam_group_commands[] = {
+ { "Group Commands" },
+ { "create_group", cmd_create_group, "Create a new group", "create_group [group-opts]" },
+ { "update_group", cmd_update_group, "Update an existing group", "update_group [group-opts] group-name | group-sid" },
+ { "delete_group", cmd_delete_group, "Delete an existing group", "delete_group group-name | group-sid" },
+ { "enum_groups", cmd_enum_groups, "Enumerate all groups", "enum_groups <token> <group-ctrl>" },
+ { "lookup_group", cmd_lookup_group, "Lookup a group by SID or name", "lookup_group group-sid | group-name" },
+ { "lookup_group_sid", cmd_lookup_group_sid, "Lookup a group by SID", "lookup_group_sid <sid>" },
+ { "lookup_group_name", cmd_lookup_group_name, "Lookup a group by name", "lookup_group_name <name>" },
+ { "group_add_member", cmd_group_add_member, "Add group member to group", "group_add_member <group-name | group-sid> <member-name | member-sid>" },
+ { "group_del_member", cmd_group_del_member, "Delete group member from group", "group_del_member <group-name | group-sid> <member-name | member-sid>" },
+ { "group_enum", cmd_group_enum, "Enumerate all members of specified group", "group_enum group-sid | group-name" },
+
+ { "get_sid_groups", cmd_get_sid_groups, "Get a list of groups specified sid is a member of", "group_enum <group-sid | group-name>" },
{ NULL }
};
diff --git a/source3/torture/samtest.c b/source3/torture/samtest.c
index 3ac65ef0df..0275e0f002 100644
--- a/source3/torture/samtest.c
+++ b/source3/torture/samtest.c
@@ -100,7 +100,7 @@ static NTSTATUS cmd_help(struct sam_context *sam, TALLOC_CTX *mem_ctx,
while(tmp_set->name) {
- printf("%15s\t\t%s\n", tmp_set->name,
+ printf("%20s\t%s\n", tmp_set->name,
tmp_set->description ? tmp_set->description:
"");
@@ -157,10 +157,16 @@ static struct cmd_set separator_command[] = {
/*extern struct cmd_set sam_commands[];*/
-extern struct cmd_set sam_commands[];
+extern struct cmd_set sam_general_commands[];
+extern struct cmd_set sam_domain_commands[];
+extern struct cmd_set sam_account_commands[];
+extern struct cmd_set sam_group_commands[];
static struct cmd_set *samtest_command_list[] = {
samtest_commands,
- sam_commands,
+ sam_general_commands,
+ sam_domain_commands,
+ sam_account_commands,
+ sam_group_commands,
NULL
};