From 19aff105aad2d4b2689e2a0e955c77a93e12857f Mon Sep 17 00:00:00 2001 From: Richard Sharpe Date: Wed, 12 Nov 2003 21:46:39 +0000 Subject: Add testacl.c ... from Derrell Lipman. (This used to be commit af42af75a45d6e6538009694704e11eb83c88457) --- examples/libsmbclient/testacl.c | 280 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 280 insertions(+) create mode 100644 examples/libsmbclient/testacl.c (limited to 'examples/libsmbclient/testacl.c') diff --git a/examples/libsmbclient/testacl.c b/examples/libsmbclient/testacl.c new file mode 100644 index 0000000000..47668f7c9c --- /dev/null +++ b/examples/libsmbclient/testacl.c @@ -0,0 +1,280 @@ +#include +#include +#include +#include +#include "libsmbclient.h" + +enum acl_mode +{ + SMB_ACL_GET, + SMB_ACL_SET, + SMB_ACL_DELETE, + SMB_ACL_MODIFY, + SMB_ACL_ADD, + SMB_ACL_CHOWN, + SMB_ACL_CHGRP +}; + +static void +get_auth_data_fn(const char * pServer, + const char * pShare, + char * pWorkgroup, + int maxLenWorkgroup, + char * pUsername, + int maxLenUsername, + char * pPassword, + int maxLenPassword) + +{ + char temp[128]; + + fprintf(stdout, "Workgroup: [%s] ", pWorkgroup); + fgets(temp, sizeof(temp), stdin); + + if (temp[strlen(temp) - 1] == '\n') /* A new line? */ + { + temp[strlen(temp) - 1] = '\0'; + } + + if (temp[0] != '\0') + { + strncpy(pWorkgroup, temp, maxLenWorkgroup - 1); + } + + fprintf(stdout, "Username: [%s] ", pUsername); + fgets(temp, sizeof(temp), stdin); + + if (temp[strlen(temp) - 1] == '\n') /* A new line? */ + { + temp[strlen(temp) - 1] = '\0'; + } + + if (temp[0] != '\0') + { + strncpy(pUsername, temp, maxLenUsername - 1); + } + + fprintf(stdout, "Password: "); + fgets(temp, sizeof(temp), stdin); + + if (temp[strlen(temp) - 1] == '\n') /* A new line? */ + { + temp[strlen(temp) - 1] = '\0'; + } + + if (temp[0] != '\0') + { + strncpy(pPassword, temp, maxLenPassword - 1); + } +} + + +int main(int argc, const char *argv[]) +{ + int opt; + int flags; + int debug = 0; + int numeric = 0; + enum acl_mode mode = SMB_ACL_GET; + static char *the_acl = NULL; + int ret; + char *p; + char *debugstr; + char path[1024]; + char value[1024]; + poptContext pc; + struct poptOption long_options[] = + { + POPT_AUTOHELP + { + "numeric", 'n', POPT_ARG_NONE, &numeric, + 1, "Don't resolve sids or masks to names" + }, + { + "debug", 'd', POPT_ARG_INT, &debug, + 0, "Set debug level (0-100)" + }, + { + "delete", 'D', POPT_ARG_STRING, NULL, + 'D', "Delete an acl", "ACL" + }, + { + "modify", 'M', POPT_ARG_STRING, NULL, + 'M', "Modify an acl", "ACL" + }, + { + "add", 'a', POPT_ARG_STRING, NULL, + 'a', "Add an acl", "ACL" + }, + { + "set", 'S', POPT_ARG_STRING, NULL, + 'S', "Set acls", "ACLS" + }, + { + "chown", 'C', POPT_ARG_STRING, NULL, + 'C', "Change ownership of a file", "USERNAME" + }, + { + "chgrp", 'G', POPT_ARG_STRING, NULL, + 'G', "Change group ownership of a file", "GROUPNAME" + }, + { + "get", 'g', POPT_ARG_STRING, NULL, + 'g', "Get a specific acl attribute", "ACL" + }, + { + NULL + } + }; + + setbuf(stdout, NULL); + + pc = poptGetContext("smbcacls", argc, argv, long_options, 0); + + poptSetOtherOptionHelp(pc, "smb://server1/share1/filename"); + + while ((opt = poptGetNextOpt(pc)) != -1) { + switch (opt) { + case 'S': + the_acl = strdup(poptGetOptArg(pc)); + mode = SMB_ACL_SET; + break; + + case 'D': + the_acl = strdup(poptGetOptArg(pc)); + mode = SMB_ACL_DELETE; + break; + + case 'M': + the_acl = strdup(poptGetOptArg(pc)); + mode = SMB_ACL_MODIFY; + break; + + case 'a': + the_acl = strdup(poptGetOptArg(pc)); + mode = SMB_ACL_ADD; + break; + + case 'g': + the_acl = strdup(poptGetOptArg(pc)); + mode = SMB_ACL_GET; + break; + + case 'C': + the_acl = strdup(poptGetOptArg(pc)); + mode = SMB_ACL_CHOWN; + break; + + case 'G': + the_acl = strdup(poptGetOptArg(pc)); + mode = SMB_ACL_CHGRP; + break; + } + } + + /* Make connection to server */ + if(!poptPeekArg(pc)) { + poptPrintUsage(pc, stderr, 0); + return 1; + } + + strcpy(path, poptGetArg(pc)); + + if (smbc_init(get_auth_data_fn, debug) != 0) + { + printf("Could not initialize smbc_ library\n"); + return 1; + } + + /* Perform requested action */ + + switch(mode) + { + case SMB_ACL_GET: + if (the_acl == NULL) + { + if (numeric) + { + the_acl = "system.nt_sec_desc.*"; + } + else + { + the_acl = "system.nt_sec_desc.*+"; + } + } + ret = smbc_getxattr(path, the_acl, value, sizeof(value)); + if (ret < 0) + { + printf("Could not get attributes for [%s] %d: %s\n", + path, errno, strerror(errno)); + return 1; + } + + printf("Attributes for [%s] are:\n%s\n", path, value); + break; + + case SMB_ACL_ADD: + flags = SMBC_XATTR_FLAG_CREATE; + debugstr = "add attributes"; + goto do_set; + + case SMB_ACL_MODIFY: + flags = SMBC_XATTR_FLAG_REPLACE; + debugstr = "modify attributes"; + goto do_set; + + case SMB_ACL_CHOWN: + snprintf(value, sizeof(value), + "system.nt_sec_desc.owner%s:%s", + numeric ? "" : "+", the_acl); + the_acl = value; + debugstr = "chown owner"; + goto do_set; + + case SMB_ACL_CHGRP: + snprintf(value, sizeof(value), + "system.nt_sec_desc.group%s:%s", + numeric ? "" : "+", the_acl); + the_acl = value; + debugstr = "change group"; + goto do_set; + + case SMB_ACL_SET: + flags = 0; + debugstr = "set attributes"; + + do_set: + if ((p = strchr(the_acl, ':')) == NULL) + { + printf("Missing value. ACL must be name:value pair\n"); + return 1; + } + + *p++ = '\0'; + + ret = smbc_setxattr(path, the_acl, p, strlen(p), flags); + if (ret < 0) + { + printf("Could not %s for [%s] %d: %s\n", + debugstr, path, errno, strerror(errno)); + return 1; + } + break; + + case SMB_ACL_DELETE: + ret = smbc_removexattr(path, the_acl); + if (ret < 0) + { + printf("Could not remove attribute %s for [%s] %d:%s\n", + the_acl, path, errno, strerror(errno)); + return 1; + } + break; + + default: + printf("operation not yet implemented\n"); + break; + } + + return 0; +} -- cgit From 9840db418bad5a39edc4a32a1786f5e2d2c9dff8 Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Thu, 31 Mar 2005 05:06:04 +0000 Subject: r6149: Fixes bugs #2498 and 2484. 1. using smbc_getxattr() et al, one may now request all access control entities in the ACL without getting all other NT attributes. 2. added the ability to exclude specified attributes from the result set provided by smbc_getxattr() et al, when requesting all attributes, all NT attributes, or all DOS attributes. 3. eliminated all compiler warnings, including when --enable-developer compiler flags are in use. removed -Wcast-qual flag from list, as that is specifically to force warnings in the case of casting away qualifiers. Note: In the process of eliminating compiler warnings, a few nasties were discovered. In the file libads/sasl.c, PRIVATE kerberos interfaces are being used; and in libsmb/clikrb5.c, both PRIAVE and DEPRECATED kerberos interfaces are being used. Someone who knows kerberos should look at these and determine if there is an alternate method of accomplishing the task. (This used to be commit 994694f7f26da5099f071e1381271a70407f33bb) --- examples/libsmbclient/testacl.c | 54 +---------------------------------------- 1 file changed, 1 insertion(+), 53 deletions(-) (limited to 'examples/libsmbclient/testacl.c') diff --git a/examples/libsmbclient/testacl.c b/examples/libsmbclient/testacl.c index 47668f7c9c..ce5694b331 100644 --- a/examples/libsmbclient/testacl.c +++ b/examples/libsmbclient/testacl.c @@ -3,6 +3,7 @@ #include #include #include "libsmbclient.h" +#include "get_auth_data_fn.h" enum acl_mode { @@ -15,59 +16,6 @@ enum acl_mode SMB_ACL_CHGRP }; -static void -get_auth_data_fn(const char * pServer, - const char * pShare, - char * pWorkgroup, - int maxLenWorkgroup, - char * pUsername, - int maxLenUsername, - char * pPassword, - int maxLenPassword) - -{ - char temp[128]; - - fprintf(stdout, "Workgroup: [%s] ", pWorkgroup); - fgets(temp, sizeof(temp), stdin); - - if (temp[strlen(temp) - 1] == '\n') /* A new line? */ - { - temp[strlen(temp) - 1] = '\0'; - } - - if (temp[0] != '\0') - { - strncpy(pWorkgroup, temp, maxLenWorkgroup - 1); - } - - fprintf(stdout, "Username: [%s] ", pUsername); - fgets(temp, sizeof(temp), stdin); - - if (temp[strlen(temp) - 1] == '\n') /* A new line? */ - { - temp[strlen(temp) - 1] = '\0'; - } - - if (temp[0] != '\0') - { - strncpy(pUsername, temp, maxLenUsername - 1); - } - - fprintf(stdout, "Password: "); - fgets(temp, sizeof(temp), stdin); - - if (temp[strlen(temp) - 1] == '\n') /* A new line? */ - { - temp[strlen(temp) - 1] = '\0'; - } - - if (temp[0] != '\0') - { - strncpy(pPassword, temp, maxLenPassword - 1); - } -} - int main(int argc, const char *argv[]) { -- cgit From 5e44fc4cd47108245c567b9e676a5d8c09787d96 Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Sat, 2 Sep 2006 21:47:56 +0000 Subject: r18009: Fixes bug 4026. This completes the work Jeremy began last week, disambiguating the meaning of c_time. (In POSIX terminology, c_time means "status Change time", not "create time".) All uses of c_time, a_time and m_time have now been replaced with change_time, access_time, and write_time, and when creation time is intended, create_time is used. Additionally, the capability of setting and retrieving the create time have been added to the smbc_setxattr() and smbc_getxattr() functions. An example of setting all four times can be seen with the program examples/libsmbclient/testacl with the following command line similar to: testacl -f -S "system.*:CREATE_TIME:1000000000,ACCESS_TIME:1000000060,WRITE_TIME:1000000120,CHANGE_TIME:1000000180" 'smb://server/share/testfile.txt' The -f option turns on the new mode which uses full time names in the attribute specification (e.g. ACCESS_TIME vs A_TIME). (This used to be commit 8e119b64f1d92026dda855d904be09912a40601c) --- examples/libsmbclient/testacl.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'examples/libsmbclient/testacl.c') diff --git a/examples/libsmbclient/testacl.c b/examples/libsmbclient/testacl.c index ce5694b331..4d327b39a7 100644 --- a/examples/libsmbclient/testacl.c +++ b/examples/libsmbclient/testacl.c @@ -23,6 +23,7 @@ int main(int argc, const char *argv[]) int flags; int debug = 0; int numeric = 0; + int full_time_names = 0; enum acl_mode mode = SMB_ACL_GET; static char *the_acl = NULL; int ret; @@ -42,6 +43,11 @@ int main(int argc, const char *argv[]) "debug", 'd', POPT_ARG_INT, &debug, 0, "Set debug level (0-100)" }, + { + "full_time_names", 'f', POPT_ARG_NONE, &full_time_names, + 1, + "Use new style xattr names, which include CREATE_TIME" + }, { "delete", 'D', POPT_ARG_STRING, NULL, 'D', "Delete an acl", "ACL" @@ -133,6 +139,11 @@ int main(int argc, const char *argv[]) printf("Could not initialize smbc_ library\n"); return 1; } + + if (full_time_names) { + SMBCCTX *context = smbc_set_context(NULL); + smbc_option_set(context, "full_time_names", 1); + } /* Perform requested action */ @@ -143,11 +154,11 @@ int main(int argc, const char *argv[]) { if (numeric) { - the_acl = "system.nt_sec_desc.*"; + the_acl = "system.*"; } else { - the_acl = "system.nt_sec_desc.*+"; + the_acl = "system.*+"; } } ret = smbc_getxattr(path, the_acl, value, sizeof(value)); -- cgit From 011e89c85868ec8f16e475a560a0e5bd41995920 Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Sun, 13 Jan 2008 17:10:06 -0500 Subject: Fix smbc_listxattr() and friends (bug #5189) When the capability of using full names for DOS attributes was added, a bug was introduced which caused the wrong number of bytes to be returned. This patch to smbc_listxattr_ctx() fixes the problem. Thanks to Jack Schmidt for this patch. Derrell (This used to be commit 913c335d21c503d32b35bf65da7b2bddf0473875) --- examples/libsmbclient/testacl.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'examples/libsmbclient/testacl.c') diff --git a/examples/libsmbclient/testacl.c b/examples/libsmbclient/testacl.c index 4d327b39a7..51cc90f101 100644 --- a/examples/libsmbclient/testacl.c +++ b/examples/libsmbclient/testacl.c @@ -7,6 +7,7 @@ enum acl_mode { + SMB_ACL_LIST, SMB_ACL_GET, SMB_ACL_SET, SMB_ACL_DELETE, @@ -24,7 +25,7 @@ int main(int argc, const char *argv[]) int debug = 0; int numeric = 0; int full_time_names = 0; - enum acl_mode mode = SMB_ACL_GET; + enum acl_mode mode = SMB_ACL_LIST; static char *the_acl = NULL; int ret; char *p; @@ -149,6 +150,30 @@ int main(int argc, const char *argv[]) switch(mode) { + case SMB_ACL_LIST: + ret = smbc_listxattr(path, value, sizeof(value)-2); + if (ret < 0) + { + printf("Could not get attribute list for [%s] %d: %s\n", + path, errno, strerror(errno)); + return 1; + } + + /* + * The list of attributes has a series of null-terminated strings. + * The list of strings terminates with an extra null byte, thus two in + * a row. Ensure that our buffer, which is conceivably shorter than + * the list of attributes, actually ends with two null bytes in a row. + */ + value[sizeof(value) - 2] = '\0'; + value[sizeof(value) - 1] = '\0'; + printf("Supported attributes:\n"); + for (p = value; *p; p += strlen(p) + 1) + { + printf("\t%s\n", p); + } + break; + case SMB_ACL_GET: if (the_acl == NULL) { -- cgit From 8a05c0a8843c001bdb4ac31e9ea382dd89716b55 Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Sun, 2 Mar 2008 16:21:48 -0500 Subject: Remove use of deprecated function (This used to be commit 93580bce833453ba512ee436d6dfdbdcd2c53777) --- examples/libsmbclient/testacl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples/libsmbclient/testacl.c') diff --git a/examples/libsmbclient/testacl.c b/examples/libsmbclient/testacl.c index 51cc90f101..00e1c2c9da 100644 --- a/examples/libsmbclient/testacl.c +++ b/examples/libsmbclient/testacl.c @@ -143,7 +143,7 @@ int main(int argc, const char *argv[]) if (full_time_names) { SMBCCTX *context = smbc_set_context(NULL); - smbc_option_set(context, "full_time_names", 1); + smbc_setOptionFullTimeNames(context, 1); } /* Perform requested action */ -- cgit From 3e20aeb18e418a5a1a7821fd8c3f0d0bc5169489 Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Fri, 30 May 2008 10:38:35 -0400 Subject: Working on bug #5475 - Add code to test whether smbc_stat() munges future smbc_getxattr() results. Derrell (This used to be commit 5f6b301f92e9e9d5ee1dab9ef8eca2cc77e12941) --- examples/libsmbclient/testacl.c | 48 +++++++++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 14 deletions(-) (limited to 'examples/libsmbclient/testacl.c') diff --git a/examples/libsmbclient/testacl.c b/examples/libsmbclient/testacl.c index 00e1c2c9da..a57dd4a499 100644 --- a/examples/libsmbclient/testacl.c +++ b/examples/libsmbclient/testacl.c @@ -24,6 +24,7 @@ int main(int argc, const char *argv[]) int flags; int debug = 0; int numeric = 0; + int stat_and_retry = 0; int full_time_names = 0; enum acl_mode mode = SMB_ACL_LIST; static char *the_acl = NULL; @@ -33,6 +34,7 @@ int main(int argc, const char *argv[]) char path[1024]; char value[1024]; poptContext pc; + struct stat st; struct poptOption long_options[] = { POPT_AUTOHELP @@ -77,6 +79,10 @@ int main(int argc, const char *argv[]) "get", 'g', POPT_ARG_STRING, NULL, 'g', "Get a specific acl attribute", "ACL" }, + { + "stat_and_retry", 'R', POPT_ARG_NONE, &stat_and_retry, + 1, "After 'get' do 'stat' and another 'get'" + }, { NULL } @@ -175,26 +181,40 @@ int main(int argc, const char *argv[]) break; case SMB_ACL_GET: - if (the_acl == NULL) + do { - if (numeric) + if (the_acl == NULL) { - the_acl = "system.*"; + if (numeric) + { + the_acl = "system.*"; + } + else + { + the_acl = "system.*+"; + } } - else + ret = smbc_getxattr(path, the_acl, value, sizeof(value)); + if (ret < 0) { - the_acl = "system.*+"; + printf("Could not get attributes for [%s] %d: %s\n", + path, errno, strerror(errno)); + return 1; } - } - ret = smbc_getxattr(path, the_acl, value, sizeof(value)); - if (ret < 0) - { - printf("Could not get attributes for [%s] %d: %s\n", - path, errno, strerror(errno)); - return 1; - } - printf("Attributes for [%s] are:\n%s\n", path, value); + printf("Attributes for [%s] are:\n%s\n", path, value); + + if (stat_and_retry) + { + if (smbc_stat(path, &st) < 0) + { + perror("smbc_stat"); + return 1; + } + } + + --stat_and_retry; + } while (stat_and_retry >= 0); break; case SMB_ACL_ADD: -- cgit