summaryrefslogtreecommitdiff
path: root/source3/utils
diff options
context:
space:
mode:
authorRalph Boehme <slow@samba.org>2019-07-11 16:23:53 +0200
committerJeremy Allison <jra@samba.org>2019-07-12 22:59:58 +0000
commit36b48aa783743c86da21f8a896eac0f774fed27a (patch)
treeddb0ab5eaa13650bee6f9c3d0d5e6a01ecc127ab /source3/utils
parentbb37a88e63660f885121703419f183f9c3e85827 (diff)
downloadsamba-36b48aa783743c86da21f8a896eac0f774fed27a.tar.gz
s3:net: add 'net vfs getntacl' command
Signed-off-by: Ralph Boehme <slow@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org> Autobuild-User(master): Jeremy Allison <jra@samba.org> Autobuild-Date(master): Fri Jul 12 22:59:58 UTC 2019 on sn-devel-184
Diffstat (limited to 'source3/utils')
-rw-r--r--source3/utils/net_vfs.c111
-rw-r--r--source3/utils/wscript_build1
2 files changed, 112 insertions, 0 deletions
diff --git a/source3/utils/net_vfs.c b/source3/utils/net_vfs.c
index 041f98f7a82..e793daa8b9b 100644
--- a/source3/utils/net_vfs.c
+++ b/source3/utils/net_vfs.c
@@ -30,6 +30,8 @@
#include "smbd/proto.h"
#include "locking/proto.h"
#include "auth.h"
+#include "client.h"
+#include "util_sd.h"
#include "lib/adouble.h"
#include "lib/string_replace.h"
#include "utils/net.h"
@@ -50,6 +52,13 @@ static void net_vfs_usage(void)
"net vfs [OPTIONS] <share> ....\n");
}
+static void net_vfs_getntacl_usage(void)
+{
+ fprintf(stderr,
+ "Usage:\n"
+ "net vfs getntacl <share> <path>\n");
+}
+
static void net_vfs_stream_to_appledouble_usage(void)
{
fprintf(stderr,
@@ -188,6 +197,101 @@ done:
return rc;
}
+static int net_vfs_get_ntacl(struct net_context *net,
+ int argc,
+ const char **argv)
+{
+ const char *path = NULL;
+ struct smb_filename *smb_fname = NULL;
+ files_struct *fsp = NULL;
+ struct security_descriptor *sd = NULL;
+ NTSTATUS status;
+ int ret;
+ int rc = 1;
+
+ if (argc < 2 || net->display_usage) {
+ net_vfs_getntacl_usage();
+ goto done;
+ }
+
+ ret = net_vfs_init(net, argc, argv);
+ if (ret != 0) {
+ goto done;
+ }
+
+ path = argv[1];
+ smb_fname = synthetic_smb_fname(state.mem_ctx, path, NULL, NULL, 0);
+ if (smb_fname == NULL) {
+ goto done;
+ }
+
+ ret = SMB_VFS_STAT(state.conn_tos->conn, smb_fname);
+ if (ret != 0) {
+ fprintf(stderr, "stat [%s] failed: %s\n",
+ smb_fname_str_dbg(smb_fname), strerror(errno));
+ goto done;
+ }
+
+ status = SMB_VFS_CREATE_FILE(
+ state.conn_tos->conn,
+ NULL, /* req */
+ 0, /* root_dir_fid */
+ smb_fname,
+ FILE_READ_ATTRIBUTES|READ_CONTROL_ACCESS,
+ FILE_SHARE_READ|FILE_SHARE_WRITE,
+ FILE_OPEN,
+ 0, /* create_options */
+ 0, /* file_attributes */
+ INTERNAL_OPEN_ONLY, /* oplock_request */
+ NULL, /* lease */
+ 0, /* allocation_size */
+ 0, /* private_flags */
+ NULL, /* sd */
+ NULL, /* ea_list */
+ &fsp,
+ NULL, /* info */
+ NULL, NULL); /* create context */
+ if (!NT_STATUS_IS_OK(status)) {
+ DBG_ERR("SMB_VFS_CREATE_FILE [%s] failed: %s\n",
+ smb_fname_str_dbg(smb_fname), nt_errstr(status));
+ goto done;
+ }
+
+ status = SMB_VFS_FGET_NT_ACL(fsp,
+ SECINFO_OWNER|SECINFO_GROUP|SECINFO_DACL,
+ fsp,
+ &sd);
+ if (!NT_STATUS_IS_OK(status)) {
+ DBG_ERR("SMB_VFS_FGET_NT_ACL [%s] failed: %s\n",
+ smb_fname_str_dbg(smb_fname), nt_errstr(status));
+ goto done;
+ }
+
+ status = close_file(NULL, fsp, NORMAL_CLOSE);
+ if (!NT_STATUS_IS_OK(status)) {
+ DBG_ERR("close_file [%s] failed: %s\n",
+ smb_fname_str_dbg(smb_fname),
+ nt_errstr(status));
+ goto done;
+ }
+ fsp = NULL;
+
+ sec_desc_print(NULL, stdout, sd, true);
+
+ rc = 0;
+done:
+ if (fsp != NULL) {
+ status = close_file(NULL, fsp, NORMAL_CLOSE);
+ if (!NT_STATUS_IS_OK(status)) {
+ DBG_ERR("close_file [%s] failed: %s\n",
+ smb_fname_str_dbg(smb_fname),
+ nt_errstr(status));
+ rc = 1;
+ }
+ }
+ return rc;
+}
+
static bool do_unfruit(const char *path)
{
struct smb_filename *smb_fname = NULL;
@@ -324,6 +428,13 @@ done:
static struct functable func[] = {
{
+ "getntacl",
+ net_vfs_get_ntacl,
+ NET_TRANSPORT_LOCAL,
+ N_("Display security descriptor of a file or directory"),
+ N_("net vfs getntacl <share> <path> [<path> ...]")
+ },
+ {
NET_VFS_CMD_STREAM_TO_ADOUBLE,
net_vfs_stream_to_appledouble,
NET_TRANSPORT_LOCAL,
diff --git a/source3/utils/wscript_build b/source3/utils/wscript_build
index 8393ab92b88..b6ff3697ca0 100644
--- a/source3/utils/wscript_build
+++ b/source3/utils/wscript_build
@@ -229,6 +229,7 @@ bld.SAMBA3_BINARY('net',
../registry/reg_format.c
../registry/reg_import.c
net_registry_util.c
+ ../lib/util_sd.c
net_help_common.c''',
deps='''
talloc