5 #include "libsmbclient.h"
19 get_auth_data_fn(const char * pServer
,
31 fprintf(stdout
, "Workgroup: [%s] ", pWorkgroup
);
32 fgets(temp
, sizeof(temp
), stdin
);
34 if (temp
[strlen(temp
) - 1] == '\n') /* A new line? */
36 temp
[strlen(temp
) - 1] = '\0';
41 strncpy(pWorkgroup
, temp
, maxLenWorkgroup
- 1);
44 fprintf(stdout
, "Username: [%s] ", pUsername
);
45 fgets(temp
, sizeof(temp
), stdin
);
47 if (temp
[strlen(temp
) - 1] == '\n') /* A new line? */
49 temp
[strlen(temp
) - 1] = '\0';
54 strncpy(pUsername
, temp
, maxLenUsername
- 1);
57 fprintf(stdout
, "Password: ");
58 fgets(temp
, sizeof(temp
), stdin
);
60 if (temp
[strlen(temp
) - 1] == '\n') /* A new line? */
62 temp
[strlen(temp
) - 1] = '\0';
67 strncpy(pPassword
, temp
, maxLenPassword
- 1);
72 int main(int argc
, const char *argv
[])
78 enum acl_mode mode
= SMB_ACL_GET
;
79 static char *the_acl
= NULL
;
86 struct poptOption long_options
[] =
90 "numeric", 'n', POPT_ARG_NONE
, &numeric
,
91 1, "Don't resolve sids or masks to names"
94 "debug", 'd', POPT_ARG_INT
, &debug
,
95 0, "Set debug level (0-100)"
98 "delete", 'D', POPT_ARG_STRING
, NULL
,
99 'D', "Delete an acl", "ACL"
102 "modify", 'M', POPT_ARG_STRING
, NULL
,
103 'M', "Modify an acl", "ACL"
106 "add", 'a', POPT_ARG_STRING
, NULL
,
107 'a', "Add an acl", "ACL"
110 "set", 'S', POPT_ARG_STRING
, NULL
,
111 'S', "Set acls", "ACLS"
114 "chown", 'C', POPT_ARG_STRING
, NULL
,
115 'C', "Change ownership of a file", "USERNAME"
118 "chgrp", 'G', POPT_ARG_STRING
, NULL
,
119 'G', "Change group ownership of a file", "GROUPNAME"
122 "get", 'g', POPT_ARG_STRING
, NULL
,
123 'g', "Get a specific acl attribute", "ACL"
130 setbuf(stdout
, NULL
);
132 pc
= poptGetContext("smbcacls", argc
, argv
, long_options
, 0);
134 poptSetOtherOptionHelp(pc
, "smb://server1/share1/filename");
136 while ((opt
= poptGetNextOpt(pc
)) != -1) {
139 the_acl
= strdup(poptGetOptArg(pc
));
144 the_acl
= strdup(poptGetOptArg(pc
));
145 mode
= SMB_ACL_DELETE
;
149 the_acl
= strdup(poptGetOptArg(pc
));
150 mode
= SMB_ACL_MODIFY
;
154 the_acl
= strdup(poptGetOptArg(pc
));
159 the_acl
= strdup(poptGetOptArg(pc
));
164 the_acl
= strdup(poptGetOptArg(pc
));
165 mode
= SMB_ACL_CHOWN
;
169 the_acl
= strdup(poptGetOptArg(pc
));
170 mode
= SMB_ACL_CHGRP
;
175 /* Make connection to server */
176 if(!poptPeekArg(pc
)) {
177 poptPrintUsage(pc
, stderr
, 0);
181 strcpy(path
, poptGetArg(pc
));
183 if (smbc_init(get_auth_data_fn
, debug
) != 0)
185 printf("Could not initialize smbc_ library\n");
189 /* Perform requested action */
198 the_acl
= "system.nt_sec_desc.*";
202 the_acl
= "system.nt_sec_desc.*+";
205 ret
= smbc_getxattr(path
, the_acl
, value
, sizeof(value
));
208 printf("Could not get attributes for [%s] %d: %s\n",
209 path
, errno
, strerror(errno
));
213 printf("Attributes for [%s] are:\n%s\n", path
, value
);
217 flags
= SMBC_XATTR_FLAG_CREATE
;
218 debugstr
= "add attributes";
222 flags
= SMBC_XATTR_FLAG_REPLACE
;
223 debugstr
= "modify attributes";
227 snprintf(value
, sizeof(value
),
228 "system.nt_sec_desc.owner%s:%s",
229 numeric
? "" : "+", the_acl
);
231 debugstr
= "chown owner";
235 snprintf(value
, sizeof(value
),
236 "system.nt_sec_desc.group%s:%s",
237 numeric
? "" : "+", the_acl
);
239 debugstr
= "change group";
244 debugstr
= "set attributes";
247 if ((p
= strchr(the_acl
, ':')) == NULL
)
249 printf("Missing value. ACL must be name:value pair\n");
255 ret
= smbc_setxattr(path
, the_acl
, p
, strlen(p
), flags
);
258 printf("Could not %s for [%s] %d: %s\n",
259 debugstr
, path
, errno
, strerror(errno
));
265 ret
= smbc_removexattr(path
, the_acl
);
268 printf("Could not remove attribute %s for [%s] %d:%s\n",
269 the_acl
, path
, errno
, strerror(errno
));
275 printf("operation not yet implemented\n");