5 #include "libsmbclient.h"
6 #include "get_auth_data_fn.h"
21 int main(int argc, const char *argv[])
27 int stat_and_retry = 0;
28 int full_time_names = 0;
29 enum acl_mode mode = SMB_ACL_LIST;
30 static const char *the_acl = NULL;
38 struct poptOption long_options[] =
42 "numeric", 'n', POPT_ARG_NONE, &numeric,
43 1, "Don't resolve sids or masks to names"
46 "debug", 'd', POPT_ARG_INT, &debug,
47 0, "Set debug level (0-100)"
50 "full_time_names", 'f', POPT_ARG_NONE, &full_time_names,
52 "Use new style xattr names, which include CREATE_TIME"
55 "delete", 'D', POPT_ARG_STRING, NULL,
56 'D', "Delete an acl", "ACL"
59 "modify", 'M', POPT_ARG_STRING, NULL,
60 'M', "Modify an acl", "ACL"
63 "add", 'a', POPT_ARG_STRING, NULL,
64 'a', "Add an acl", "ACL"
67 "set", 'S', POPT_ARG_STRING, NULL,
68 'S', "Set acls", "ACLS"
71 "chown", 'C', POPT_ARG_STRING, NULL,
72 'C', "Change ownership of a file", "USERNAME"
75 "chgrp", 'G', POPT_ARG_STRING, NULL,
76 'G', "Change group ownership of a file", "GROUPNAME"
79 "get", 'g', POPT_ARG_STRING, NULL,
80 'g', "Get a specific acl attribute", "ACL"
83 "stat_and_retry", 'R', POPT_ARG_NONE, &stat_and_retry,
84 1, "After 'get' do 'stat' and another 'get'"
93 pc = poptGetContext("smbcacls", argc, argv, long_options, 0);
95 poptSetOtherOptionHelp(pc, "smb://server1/share1/filename");
97 while ((opt = poptGetNextOpt(pc)) != -1) {
100 the_acl = strdup(poptGetOptArg(pc));
105 the_acl = strdup(poptGetOptArg(pc));
106 mode = SMB_ACL_DELETE;
110 the_acl = strdup(poptGetOptArg(pc));
111 mode = SMB_ACL_MODIFY;
115 the_acl = strdup(poptGetOptArg(pc));
120 the_acl = strdup(poptGetOptArg(pc));
125 the_acl = strdup(poptGetOptArg(pc));
126 mode = SMB_ACL_CHOWN;
130 the_acl = strdup(poptGetOptArg(pc));
131 mode = SMB_ACL_CHGRP;
136 /* Make connection to server */
137 if(!poptPeekArg(pc)) {
138 poptPrintUsage(pc, stderr, 0);
142 strcpy(path, poptGetArg(pc));
144 if (smbc_init(get_auth_data_fn, debug) != 0)
146 printf("Could not initialize smbc_ library\n");
150 if (full_time_names) {
151 SMBCCTX *context = smbc_set_context(NULL);
152 smbc_setOptionFullTimeNames(context, 1);
155 /* Perform requested action */
160 ret = smbc_listxattr(path, value, sizeof(value)-2);
163 printf("Could not get attribute list for [%s] %d: %s\n",
164 path, errno, strerror(errno));
169 * The list of attributes has a series of null-terminated strings.
170 * The list of strings terminates with an extra null byte, thus two in
171 * a row. Ensure that our buffer, which is conceivably shorter than
172 * the list of attributes, actually ends with two null bytes in a row.
174 value[sizeof(value) - 2] = '\0';
175 value[sizeof(value) - 1] = '\0';
176 printf("Supported attributes:\n");
177 for (p = value; *p; p += strlen(p) + 1)
190 the_acl = "system.*";
194 the_acl = "system.*+";
197 ret = smbc_getxattr(path, the_acl, value, sizeof(value));
200 printf("Could not get attributes for [%s] %d: %s\n",
201 path, errno, strerror(errno));
205 printf("Attributes for [%s] are:\n%s\n", path, value);
209 if (smbc_stat(path, &st) < 0)
217 } while (stat_and_retry >= 0);
221 flags = SMBC_XATTR_FLAG_CREATE;
222 debugstr = "add attributes";
226 flags = SMBC_XATTR_FLAG_REPLACE;
227 debugstr = "modify attributes";
231 snprintf(value, sizeof(value),
232 "system.nt_sec_desc.owner%s:%s",
233 numeric ? "" : "+", the_acl);
235 debugstr = "chown owner";
239 snprintf(value, sizeof(value),
240 "system.nt_sec_desc.group%s:%s",
241 numeric ? "" : "+", the_acl);
243 debugstr = "change group";
248 debugstr = "set attributes";
251 if ((p = strchr(the_acl, ':')) == NULL)
253 printf("Missing value. ACL must be name:value pair\n");
259 ret = smbc_setxattr(path, the_acl, p, strlen(p), flags);
262 printf("Could not %s for [%s] %d: %s\n",
263 debugstr, path, errno, strerror(errno));
269 ret = smbc_removexattr(path, the_acl);
272 printf("Could not remove attribute %s for [%s] %d:%s\n",
273 the_acl, path, errno, strerror(errno));
279 printf("operation not yet implemented\n");