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 .longName = "numeric",
44 .argInfo = POPT_ARG_NONE,
47 .descrip = "Don't resolve sids or masks to names"
52 .argInfo = POPT_ARG_INT,
55 .descrip = "Set debug level (0-100)"
58 .longName = "full_time_names",
60 .argInfo = POPT_ARG_NONE,
61 .arg = &full_time_names,
63 .descrip = "Use new style xattr names, which include CREATE_TIME"
68 .argInfo = POPT_ARG_STRING,
71 .descrip = "Delete an acl",
77 .argInfo = POPT_ARG_STRING,
80 .descrip = "Modify an acl",
86 .argInfo = POPT_ARG_STRING,
89 .descrip = "Add an acl",
95 .argInfo = POPT_ARG_STRING,
98 .descrip = "Set acls",
104 .argInfo = POPT_ARG_STRING,
107 .descrip = "Change ownership of a file",
108 .argDescrip = "USERNAME"
113 .argInfo = POPT_ARG_STRING,
116 .descrip = "Change group ownership of a file",
117 .argDescrip = "GROUPNAME"
122 .argInfo = POPT_ARG_STRING,
125 .descrip = "Get a specific acl attribute",
129 .longName = "stat_and_retry",
131 .argInfo = POPT_ARG_NONE,
132 .arg = &stat_and_retry,
134 .descrip = "After 'get' do 'stat' and another 'get'"
139 setbuf(stdout, NULL);
141 pc = poptGetContext("smbcacls", argc, argv, long_options, 0);
143 poptSetOtherOptionHelp(pc, "smb://server1/share1/filename");
145 while ((opt = poptGetNextOpt(pc)) != -1) {
148 the_acl = strdup(poptGetOptArg(pc));
153 the_acl = strdup(poptGetOptArg(pc));
154 mode = SMB_ACL_DELETE;
158 the_acl = strdup(poptGetOptArg(pc));
159 mode = SMB_ACL_MODIFY;
163 the_acl = strdup(poptGetOptArg(pc));
168 the_acl = strdup(poptGetOptArg(pc));
173 the_acl = strdup(poptGetOptArg(pc));
174 mode = SMB_ACL_CHOWN;
178 the_acl = strdup(poptGetOptArg(pc));
179 mode = SMB_ACL_CHGRP;
184 /* Make connection to server */
185 if(!poptPeekArg(pc)) {
186 poptPrintUsage(pc, stderr, 0);
190 strncpy(path, poptGetArg(pc), sizeof(path));
191 path[sizeof(path)-1] = '\0';
193 if (smbc_init(get_auth_data_fn, debug) != 0)
195 printf("Could not initialize smbc_ library\n");
199 if (full_time_names) {
200 SMBCCTX *context = smbc_set_context(NULL);
201 smbc_setOptionFullTimeNames(context, 1);
204 /* Perform requested action */
209 ret = smbc_listxattr(path, value, sizeof(value)-2);
212 printf("Could not get attribute list for [%s] %d: %s\n",
213 path, errno, strerror(errno));
218 * The list of attributes has a series of null-terminated strings.
219 * The list of strings terminates with an extra null byte, thus two in
220 * a row. Ensure that our buffer, which is conceivably shorter than
221 * the list of attributes, actually ends with two null bytes in a row.
223 value[sizeof(value) - 2] = '\0';
224 value[sizeof(value) - 1] = '\0';
225 printf("Supported attributes:\n");
226 for (p = value; *p; p += strlen(p) + 1)
239 the_acl = "system.*";
243 the_acl = "system.*+";
246 ret = smbc_getxattr(path, the_acl, value, sizeof(value));
249 printf("Could not get attributes for [%s] %d: %s\n",
250 path, errno, strerror(errno));
254 printf("Attributes for [%s] are:\n%s\n", path, value);
258 if (smbc_stat(path, &st) < 0)
266 } while (stat_and_retry >= 0);
270 flags = SMBC_XATTR_FLAG_CREATE;
271 debugstr = "add attributes";
275 flags = SMBC_XATTR_FLAG_REPLACE;
276 debugstr = "modify attributes";
280 snprintf(value, sizeof(value),
281 "system.nt_sec_desc.owner%s:%s",
282 numeric ? "" : "+", the_acl);
284 debugstr = "chown owner";
288 snprintf(value, sizeof(value),
289 "system.nt_sec_desc.group%s:%s",
290 numeric ? "" : "+", the_acl);
292 debugstr = "change group";
297 debugstr = "set attributes";
300 if ((p = strchr(the_acl, ':')) == NULL)
302 printf("Missing value. ACL must be name:value pair\n");
308 ret = smbc_setxattr(path, the_acl, p, strlen(p), flags);
311 printf("Could not %s for [%s] %d: %s\n",
312 debugstr, path, errno, strerror(errno));
318 ret = smbc_removexattr(path, the_acl);
321 printf("Could not remove attribute %s for [%s] %d:%s\n",
322 the_acl, path, errno, strerror(errno));
328 printf("operation not yet implemented\n");