5 #include "libsmbclient.h"
6 #include "get_auth_data_fn.h"
20 int main(int argc
, const char *argv
[])
26 int full_time_names
= 0;
27 enum acl_mode mode
= SMB_ACL_GET
;
28 static char *the_acl
= NULL
;
35 struct poptOption long_options
[] =
39 "numeric", 'n', POPT_ARG_NONE
, &numeric
,
40 1, "Don't resolve sids or masks to names"
43 "debug", 'd', POPT_ARG_INT
, &debug
,
44 0, "Set debug level (0-100)"
47 "full_time_names", 'f', POPT_ARG_NONE
, &full_time_names
,
49 "Use new style xattr names, which include CREATE_TIME"
52 "delete", 'D', POPT_ARG_STRING
, NULL
,
53 'D', "Delete an acl", "ACL"
56 "modify", 'M', POPT_ARG_STRING
, NULL
,
57 'M', "Modify an acl", "ACL"
60 "add", 'a', POPT_ARG_STRING
, NULL
,
61 'a', "Add an acl", "ACL"
64 "set", 'S', POPT_ARG_STRING
, NULL
,
65 'S', "Set acls", "ACLS"
68 "chown", 'C', POPT_ARG_STRING
, NULL
,
69 'C', "Change ownership of a file", "USERNAME"
72 "chgrp", 'G', POPT_ARG_STRING
, NULL
,
73 'G', "Change group ownership of a file", "GROUPNAME"
76 "get", 'g', POPT_ARG_STRING
, NULL
,
77 'g', "Get a specific acl attribute", "ACL"
86 pc
= poptGetContext("smbcacls", argc
, argv
, long_options
, 0);
88 poptSetOtherOptionHelp(pc
, "smb://server1/share1/filename");
90 while ((opt
= poptGetNextOpt(pc
)) != -1) {
93 the_acl
= strdup(poptGetOptArg(pc
));
98 the_acl
= strdup(poptGetOptArg(pc
));
99 mode
= SMB_ACL_DELETE
;
103 the_acl
= strdup(poptGetOptArg(pc
));
104 mode
= SMB_ACL_MODIFY
;
108 the_acl
= strdup(poptGetOptArg(pc
));
113 the_acl
= strdup(poptGetOptArg(pc
));
118 the_acl
= strdup(poptGetOptArg(pc
));
119 mode
= SMB_ACL_CHOWN
;
123 the_acl
= strdup(poptGetOptArg(pc
));
124 mode
= SMB_ACL_CHGRP
;
129 /* Make connection to server */
130 if(!poptPeekArg(pc
)) {
131 poptPrintUsage(pc
, stderr
, 0);
135 strcpy(path
, poptGetArg(pc
));
137 if (smbc_init(get_auth_data_fn
, debug
) != 0)
139 printf("Could not initialize smbc_ library\n");
143 if (full_time_names
) {
144 SMBCCTX
*context
= smbc_set_context(NULL
);
145 smbc_option_set(context
, "full_time_names", 1);
148 /* Perform requested action */
157 the_acl
= "system.*";
161 the_acl
= "system.*+";
164 ret
= smbc_getxattr(path
, the_acl
, value
, sizeof(value
));
167 printf("Could not get attributes for [%s] %d: %s\n",
168 path
, errno
, strerror(errno
));
172 printf("Attributes for [%s] are:\n%s\n", path
, value
);
176 flags
= SMBC_XATTR_FLAG_CREATE
;
177 debugstr
= "add attributes";
181 flags
= SMBC_XATTR_FLAG_REPLACE
;
182 debugstr
= "modify attributes";
186 snprintf(value
, sizeof(value
),
187 "system.nt_sec_desc.owner%s:%s",
188 numeric
? "" : "+", the_acl
);
190 debugstr
= "chown owner";
194 snprintf(value
, sizeof(value
),
195 "system.nt_sec_desc.group%s:%s",
196 numeric
? "" : "+", the_acl
);
198 debugstr
= "change group";
203 debugstr
= "set attributes";
206 if ((p
= strchr(the_acl
, ':')) == NULL
)
208 printf("Missing value. ACL must be name:value pair\n");
214 ret
= smbc_setxattr(path
, the_acl
, p
, strlen(p
), flags
);
217 printf("Could not %s for [%s] %d: %s\n",
218 debugstr
, path
, errno
, strerror(errno
));
224 ret
= smbc_removexattr(path
, the_acl
);
227 printf("Could not remove attribute %s for [%s] %d:%s\n",
228 the_acl
, path
, errno
, strerror(errno
));
234 printf("operation not yet implemented\n");