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 strncpy(path
, poptGetArg(pc
), sizeof(path
));
143 path
[sizeof(path
)-1] = '\0';
145 if (smbc_init(get_auth_data_fn
, debug
) != 0)
147 printf("Could not initialize smbc_ library\n");
151 if (full_time_names
) {
152 SMBCCTX
*context
= smbc_set_context(NULL
);
153 smbc_setOptionFullTimeNames(context
, 1);
156 /* Perform requested action */
161 ret
= smbc_listxattr(path
, value
, sizeof(value
)-2);
164 printf("Could not get attribute list for [%s] %d: %s\n",
165 path
, errno
, strerror(errno
));
170 * The list of attributes has a series of null-terminated strings.
171 * The list of strings terminates with an extra null byte, thus two in
172 * a row. Ensure that our buffer, which is conceivably shorter than
173 * the list of attributes, actually ends with two null bytes in a row.
175 value
[sizeof(value
) - 2] = '\0';
176 value
[sizeof(value
) - 1] = '\0';
177 printf("Supported attributes:\n");
178 for (p
= value
; *p
; p
+= strlen(p
) + 1)
191 the_acl
= "system.*";
195 the_acl
= "system.*+";
198 ret
= smbc_getxattr(path
, the_acl
, value
, sizeof(value
));
201 printf("Could not get attributes for [%s] %d: %s\n",
202 path
, errno
, strerror(errno
));
206 printf("Attributes for [%s] are:\n%s\n", path
, value
);
210 if (smbc_stat(path
, &st
) < 0)
218 } while (stat_and_retry
>= 0);
222 flags
= SMBC_XATTR_FLAG_CREATE
;
223 debugstr
= "add attributes";
227 flags
= SMBC_XATTR_FLAG_REPLACE
;
228 debugstr
= "modify attributes";
232 snprintf(value
, sizeof(value
),
233 "system.nt_sec_desc.owner%s:%s",
234 numeric
? "" : "+", the_acl
);
236 debugstr
= "chown owner";
240 snprintf(value
, sizeof(value
),
241 "system.nt_sec_desc.group%s:%s",
242 numeric
? "" : "+", the_acl
);
244 debugstr
= "change group";
249 debugstr
= "set attributes";
252 if ((p
= strchr(the_acl
, ':')) == NULL
)
254 printf("Missing value. ACL must be name:value pair\n");
260 ret
= smbc_setxattr(path
, the_acl
, p
, strlen(p
), flags
);
263 printf("Could not %s for [%s] %d: %s\n",
264 debugstr
, path
, errno
, strerror(errno
));
270 ret
= smbc_removexattr(path
, the_acl
);
273 printf("Could not remove attribute %s for [%s] %d:%s\n",
274 the_acl
, path
, errno
, strerror(errno
));
280 printf("operation not yet implemented\n");