5 #include "libsmbclient.h"
6 #include "get_auth_data_fn.h"
20 int main(int argc, const char *argv[])
26 enum acl_mode mode = SMB_ACL_GET;
27 static char *the_acl = NULL;
34 struct poptOption long_options[] =
38 "numeric", 'n', POPT_ARG_NONE, &numeric,
39 1, "Don't resolve sids or masks to names"
42 "debug", 'd', POPT_ARG_INT, &debug,
43 0, "Set debug level (0-100)"
46 "delete", 'D', POPT_ARG_STRING, NULL,
47 'D', "Delete an acl", "ACL"
50 "modify", 'M', POPT_ARG_STRING, NULL,
51 'M', "Modify an acl", "ACL"
54 "add", 'a', POPT_ARG_STRING, NULL,
55 'a', "Add an acl", "ACL"
58 "set", 'S', POPT_ARG_STRING, NULL,
59 'S', "Set acls", "ACLS"
62 "chown", 'C', POPT_ARG_STRING, NULL,
63 'C', "Change ownership of a file", "USERNAME"
66 "chgrp", 'G', POPT_ARG_STRING, NULL,
67 'G', "Change group ownership of a file", "GROUPNAME"
70 "get", 'g', POPT_ARG_STRING, NULL,
71 'g', "Get a specific acl attribute", "ACL"
80 pc = poptGetContext("smbcacls", argc, argv, long_options, 0);
82 poptSetOtherOptionHelp(pc, "smb://server1/share1/filename");
84 while ((opt = poptGetNextOpt(pc)) != -1) {
87 the_acl = strdup(poptGetOptArg(pc));
92 the_acl = strdup(poptGetOptArg(pc));
93 mode = SMB_ACL_DELETE;
97 the_acl = strdup(poptGetOptArg(pc));
98 mode = SMB_ACL_MODIFY;
102 the_acl = strdup(poptGetOptArg(pc));
107 the_acl = strdup(poptGetOptArg(pc));
112 the_acl = strdup(poptGetOptArg(pc));
113 mode = SMB_ACL_CHOWN;
117 the_acl = strdup(poptGetOptArg(pc));
118 mode = SMB_ACL_CHGRP;
123 /* Make connection to server */
124 if(!poptPeekArg(pc)) {
125 poptPrintUsage(pc, stderr, 0);
129 strcpy(path, poptGetArg(pc));
131 if (smbc_init(get_auth_data_fn, debug) != 0)
133 printf("Could not initialize smbc_ library\n");
137 /* Perform requested action */
146 the_acl = "system.nt_sec_desc.*";
150 the_acl = "system.nt_sec_desc.*+";
153 ret = smbc_getxattr(path, the_acl, value, sizeof(value));
156 printf("Could not get attributes for [%s] %d: %s\n",
157 path, errno, strerror(errno));
161 printf("Attributes for [%s] are:\n%s\n", path, value);
165 flags = SMBC_XATTR_FLAG_CREATE;
166 debugstr = "add attributes";
170 flags = SMBC_XATTR_FLAG_REPLACE;
171 debugstr = "modify attributes";
175 snprintf(value, sizeof(value),
176 "system.nt_sec_desc.owner%s:%s",
177 numeric ? "" : "+", the_acl);
179 debugstr = "chown owner";
183 snprintf(value, sizeof(value),
184 "system.nt_sec_desc.group%s:%s",
185 numeric ? "" : "+", the_acl);
187 debugstr = "change group";
192 debugstr = "set attributes";
195 if ((p = strchr(the_acl, ':')) == NULL)
197 printf("Missing value. ACL must be name:value pair\n");
203 ret = smbc_setxattr(path, the_acl, p, strlen(p), flags);
206 printf("Could not %s for [%s] %d: %s\n",
207 debugstr, path, errno, strerror(errno));
213 ret = smbc_removexattr(path, the_acl);
216 printf("Could not remove attribute %s for [%s] %d:%s\n",
217 the_acl, path, errno, strerror(errno));
223 printf("operation not yet implemented\n");