5 #include "libsmbclient.h"
6 #include "get_auth_data_fn.h"
21 int main(int argc
, const char *argv
[])
27 int full_time_names
= 0;
28 enum acl_mode mode
= SMB_ACL_LIST
;
29 static char *the_acl
= NULL
;
36 struct poptOption long_options
[] =
40 "numeric", 'n', POPT_ARG_NONE
, &numeric
,
41 1, "Don't resolve sids or masks to names"
44 "debug", 'd', POPT_ARG_INT
, &debug
,
45 0, "Set debug level (0-100)"
48 "full_time_names", 'f', POPT_ARG_NONE
, &full_time_names
,
50 "Use new style xattr names, which include CREATE_TIME"
53 "delete", 'D', POPT_ARG_STRING
, NULL
,
54 'D', "Delete an acl", "ACL"
57 "modify", 'M', POPT_ARG_STRING
, NULL
,
58 'M', "Modify an acl", "ACL"
61 "add", 'a', POPT_ARG_STRING
, NULL
,
62 'a', "Add an acl", "ACL"
65 "set", 'S', POPT_ARG_STRING
, NULL
,
66 'S', "Set acls", "ACLS"
69 "chown", 'C', POPT_ARG_STRING
, NULL
,
70 'C', "Change ownership of a file", "USERNAME"
73 "chgrp", 'G', POPT_ARG_STRING
, NULL
,
74 'G', "Change group ownership of a file", "GROUPNAME"
77 "get", 'g', POPT_ARG_STRING
, NULL
,
78 'g', "Get a specific acl attribute", "ACL"
87 pc
= poptGetContext("smbcacls", argc
, argv
, long_options
, 0);
89 poptSetOtherOptionHelp(pc
, "smb://server1/share1/filename");
91 while ((opt
= poptGetNextOpt(pc
)) != -1) {
94 the_acl
= strdup(poptGetOptArg(pc
));
99 the_acl
= strdup(poptGetOptArg(pc
));
100 mode
= SMB_ACL_DELETE
;
104 the_acl
= strdup(poptGetOptArg(pc
));
105 mode
= SMB_ACL_MODIFY
;
109 the_acl
= strdup(poptGetOptArg(pc
));
114 the_acl
= strdup(poptGetOptArg(pc
));
119 the_acl
= strdup(poptGetOptArg(pc
));
120 mode
= SMB_ACL_CHOWN
;
124 the_acl
= strdup(poptGetOptArg(pc
));
125 mode
= SMB_ACL_CHGRP
;
130 /* Make connection to server */
131 if(!poptPeekArg(pc
)) {
132 poptPrintUsage(pc
, stderr
, 0);
136 strcpy(path
, poptGetArg(pc
));
138 if (smbc_init(get_auth_data_fn
, debug
) != 0)
140 printf("Could not initialize smbc_ library\n");
144 if (full_time_names
) {
145 SMBCCTX
*context
= smbc_set_context(NULL
);
146 smbc_option_set(context
, "full_time_names", 1);
149 /* Perform requested action */
154 ret
= smbc_listxattr(path
, value
, sizeof(value
)-2);
157 printf("Could not get attribute list for [%s] %d: %s\n",
158 path
, errno
, strerror(errno
));
163 * The list of attributes has a series of null-terminated strings.
164 * The list of strings terminates with an extra null byte, thus two in
165 * a row. Ensure that our buffer, which is conceivably shorter than
166 * the list of attributes, actually ends with two null bytes in a row.
168 value
[sizeof(value
) - 2] = '\0';
169 value
[sizeof(value
) - 1] = '\0';
170 printf("Supported attributes:\n");
171 for (p
= value
; *p
; p
+= strlen(p
) + 1)
182 the_acl
= "system.*";
186 the_acl
= "system.*+";
189 ret
= smbc_getxattr(path
, the_acl
, value
, sizeof(value
));
192 printf("Could not get attributes for [%s] %d: %s\n",
193 path
, errno
, strerror(errno
));
197 printf("Attributes for [%s] are:\n%s\n", path
, value
);
201 flags
= SMBC_XATTR_FLAG_CREATE
;
202 debugstr
= "add attributes";
206 flags
= SMBC_XATTR_FLAG_REPLACE
;
207 debugstr
= "modify attributes";
211 snprintf(value
, sizeof(value
),
212 "system.nt_sec_desc.owner%s:%s",
213 numeric
? "" : "+", the_acl
);
215 debugstr
= "chown owner";
219 snprintf(value
, sizeof(value
),
220 "system.nt_sec_desc.group%s:%s",
221 numeric
? "" : "+", the_acl
);
223 debugstr
= "change group";
228 debugstr
= "set attributes";
231 if ((p
= strchr(the_acl
, ':')) == NULL
)
233 printf("Missing value. ACL must be name:value pair\n");
239 ret
= smbc_setxattr(path
, the_acl
, p
, strlen(p
), flags
);
242 printf("Could not %s for [%s] %d: %s\n",
243 debugstr
, path
, errno
, strerror(errno
));
249 ret
= smbc_removexattr(path
, the_acl
);
252 printf("Could not remove attribute %s for [%s] %d:%s\n",
253 the_acl
, path
, errno
, strerror(errno
));
259 printf("operation not yet implemented\n");