r9661: fallback to cn attribubte if displayName is not available
[Samba.git] / source / utils / smbcacls.c
blob00000b5cfbe51095d40fc09daad94c08a6029378
1 /*
2 Unix SMB/CIFS implementation.
3 ACL get/set utility
5 Copyright (C) Andrew Tridgell 2000
6 Copyright (C) Tim Potter 2000
7 Copyright (C) Jeremy Allison 2000
8 Copyright (C) Jelmer Vernooij 2003
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 #include "includes.h"
27 static pstring owner_username;
28 static fstring server;
29 static int test_args = False;
30 static TALLOC_CTX *ctx;
32 #define CREATE_ACCESS_READ READ_CONTROL_ACCESS
34 /* numeric is set when the user wants numeric SIDs and ACEs rather
35 than going via LSA calls to resolve them */
36 static BOOL numeric = False;
38 enum acl_mode {SMB_ACL_SET, SMB_ACL_DELETE, SMB_ACL_MODIFY, SMB_ACL_ADD };
39 enum chown_mode {REQUEST_NONE, REQUEST_CHOWN, REQUEST_CHGRP};
40 enum exit_values {EXIT_OK, EXIT_FAILED, EXIT_PARSE_ERROR};
42 struct perm_value {
43 const char *perm;
44 uint32 mask;
47 /* These values discovered by inspection */
49 static const struct perm_value special_values[] = {
50 { "R", 0x00120089 },
51 { "W", 0x00120116 },
52 { "X", 0x001200a0 },
53 { "D", 0x00010000 },
54 { "P", 0x00040000 },
55 { "O", 0x00080000 },
56 { NULL, 0 },
59 static const struct perm_value standard_values[] = {
60 { "READ", 0x001200a9 },
61 { "CHANGE", 0x001301bf },
62 { "FULL", 0x001f01ff },
63 { NULL, 0 },
66 static struct cli_state *global_hack_cli;
67 static POLICY_HND pol;
68 static BOOL got_policy_hnd;
70 static struct cli_state *connect_one(const char *share);
72 /* Open cli connection and policy handle */
74 static BOOL cacls_open_policy_hnd(void)
76 /* Initialise cli LSA connection */
78 if (!global_hack_cli) {
79 global_hack_cli = connect_one("IPC$");
80 if (!cli_nt_session_open (global_hack_cli, PI_LSARPC)) {
81 return False;
85 /* Open policy handle */
87 if (!got_policy_hnd) {
89 /* Some systems don't support SEC_RIGHTS_MAXIMUM_ALLOWED,
90 but NT sends 0x2000000 so we might as well do it too. */
92 if (!NT_STATUS_IS_OK(cli_lsa_open_policy(global_hack_cli, global_hack_cli->mem_ctx, True,
93 GENERIC_EXECUTE_ACCESS, &pol))) {
94 return False;
97 got_policy_hnd = True;
100 return True;
103 /* convert a SID to a string, either numeric or username/group */
104 static void SidToString(fstring str, DOM_SID *sid)
106 char **domains = NULL;
107 char **names = NULL;
108 uint32 *types = NULL;
110 sid_to_string(str, sid);
112 if (numeric) return;
114 /* Ask LSA to convert the sid to a name */
116 if (!cacls_open_policy_hnd() ||
117 !NT_STATUS_IS_OK(cli_lsa_lookup_sids(global_hack_cli, global_hack_cli->mem_ctx,
118 &pol, 1, sid, &domains,
119 &names, &types)) ||
120 !domains || !domains[0] || !names || !names[0]) {
121 return;
124 /* Converted OK */
126 slprintf(str, sizeof(fstring) - 1, "%s%s%s",
127 domains[0], lp_winbind_separator(),
128 names[0]);
132 /* convert a string to a SID, either numeric or username/group */
133 static BOOL StringToSid(DOM_SID *sid, const char *str)
135 uint32 *types = NULL;
136 DOM_SID *sids = NULL;
137 BOOL result = True;
139 if (strncmp(str, "S-", 2) == 0) {
140 return string_to_sid(sid, str);
143 if (!cacls_open_policy_hnd() ||
144 !NT_STATUS_IS_OK(cli_lsa_lookup_names(global_hack_cli, global_hack_cli->mem_ctx,
145 &pol, 1, &str, &sids,
146 &types))) {
147 result = False;
148 goto done;
151 sid_copy(sid, &sids[0]);
152 done:
154 return result;
158 /* print an ACE on a FILE, using either numeric or ascii representation */
159 static void print_ace(FILE *f, SEC_ACE *ace)
161 const struct perm_value *v;
162 fstring sidstr;
163 int do_print = 0;
164 uint32 got_mask;
166 SidToString(sidstr, &ace->trustee);
168 fprintf(f, "%s:", sidstr);
170 if (numeric) {
171 fprintf(f, "%d/%d/0x%08x",
172 ace->type, ace->flags, ace->info.mask);
173 return;
176 /* Ace type */
178 if (ace->type == SEC_ACE_TYPE_ACCESS_ALLOWED) {
179 fprintf(f, "ALLOWED");
180 } else if (ace->type == SEC_ACE_TYPE_ACCESS_DENIED) {
181 fprintf(f, "DENIED");
182 } else {
183 fprintf(f, "%d", ace->type);
186 /* Not sure what flags can be set in a file ACL */
188 fprintf(f, "/%d/", ace->flags);
190 /* Standard permissions */
192 for (v = standard_values; v->perm; v++) {
193 if (ace->info.mask == v->mask) {
194 fprintf(f, "%s", v->perm);
195 return;
199 /* Special permissions. Print out a hex value if we have
200 leftover bits in the mask. */
202 got_mask = ace->info.mask;
204 again:
205 for (v = special_values; v->perm; v++) {
206 if ((ace->info.mask & v->mask) == v->mask) {
207 if (do_print) {
208 fprintf(f, "%s", v->perm);
210 got_mask &= ~v->mask;
214 if (!do_print) {
215 if (got_mask != 0) {
216 fprintf(f, "0x%08x", ace->info.mask);
217 } else {
218 do_print = 1;
219 goto again;
225 /* parse an ACE in the same format as print_ace() */
226 static BOOL parse_ace(SEC_ACE *ace, char *str)
228 char *p;
229 const char *cp;
230 fstring tok;
231 unsigned atype, aflags, amask;
232 DOM_SID sid;
233 SEC_ACCESS mask;
234 const struct perm_value *v;
236 ZERO_STRUCTP(ace);
237 p = strchr_m(str,':');
238 if (!p) return False;
239 *p = '\0';
240 p++;
241 /* Try to parse numeric form */
243 if (sscanf(p, "%i/%i/%i", &atype, &aflags, &amask) == 3 &&
244 StringToSid(&sid, str)) {
245 goto done;
248 /* Try to parse text form */
250 if (!StringToSid(&sid, str)) {
251 return False;
254 cp = p;
255 if (!next_token(&cp, tok, "/", sizeof(fstring))) {
256 return False;
259 if (strncmp(tok, "ALLOWED", strlen("ALLOWED")) == 0) {
260 atype = SEC_ACE_TYPE_ACCESS_ALLOWED;
261 } else if (strncmp(tok, "DENIED", strlen("DENIED")) == 0) {
262 atype = SEC_ACE_TYPE_ACCESS_DENIED;
263 } else {
264 return False;
267 /* Only numeric form accepted for flags at present */
269 if (!(next_token(&cp, tok, "/", sizeof(fstring)) &&
270 sscanf(tok, "%i", &aflags))) {
271 return False;
274 if (!next_token(&cp, tok, "/", sizeof(fstring))) {
275 return False;
278 if (strncmp(tok, "0x", 2) == 0) {
279 if (sscanf(tok, "%i", &amask) != 1) {
280 return False;
282 goto done;
285 for (v = standard_values; v->perm; v++) {
286 if (strcmp(tok, v->perm) == 0) {
287 amask = v->mask;
288 goto done;
292 p = tok;
294 while(*p) {
295 BOOL found = False;
297 for (v = special_values; v->perm; v++) {
298 if (v->perm[0] == *p) {
299 amask |= v->mask;
300 found = True;
304 if (!found) return False;
305 p++;
308 if (*p) {
309 return False;
312 done:
313 mask.mask = amask;
314 init_sec_ace(ace, &sid, atype, mask, aflags);
315 return True;
318 /* add an ACE to a list of ACEs in a SEC_ACL */
319 static BOOL add_ace(SEC_ACL **the_acl, SEC_ACE *ace)
321 SEC_ACL *new_ace;
322 SEC_ACE *aces;
323 if (! *the_acl) {
324 (*the_acl) = make_sec_acl(ctx, 3, 1, ace);
325 return True;
328 aces = SMB_CALLOC_ARRAY(SEC_ACE, 1+(*the_acl)->num_aces);
329 memcpy(aces, (*the_acl)->ace, (*the_acl)->num_aces * sizeof(SEC_ACE));
330 memcpy(aces+(*the_acl)->num_aces, ace, sizeof(SEC_ACE));
331 new_ace = make_sec_acl(ctx,(*the_acl)->revision,1+(*the_acl)->num_aces, aces);
332 SAFE_FREE(aces);
333 (*the_acl) = new_ace;
334 return True;
337 /* parse a ascii version of a security descriptor */
338 static SEC_DESC *sec_desc_parse(char *str)
340 const char *p = str;
341 fstring tok;
342 SEC_DESC *ret;
343 size_t sd_size;
344 DOM_SID *grp_sid=NULL, *owner_sid=NULL;
345 SEC_ACL *dacl=NULL;
346 int revision=1;
348 while (next_token(&p, tok, "\t,\r\n", sizeof(tok))) {
350 if (strncmp(tok,"REVISION:", 9) == 0) {
351 revision = strtol(tok+9, NULL, 16);
352 continue;
355 if (strncmp(tok,"OWNER:", 6) == 0) {
356 owner_sid = SMB_CALLOC_ARRAY(DOM_SID, 1);
357 if (!owner_sid ||
358 !StringToSid(owner_sid, tok+6)) {
359 printf("Failed to parse owner sid\n");
360 return NULL;
362 continue;
365 if (strncmp(tok,"GROUP:", 6) == 0) {
366 grp_sid = SMB_CALLOC_ARRAY(DOM_SID, 1);
367 if (!grp_sid ||
368 !StringToSid(grp_sid, tok+6)) {
369 printf("Failed to parse group sid\n");
370 return NULL;
372 continue;
375 if (strncmp(tok,"ACL:", 4) == 0) {
376 SEC_ACE ace;
377 if (!parse_ace(&ace, tok+4)) {
378 printf("Failed to parse ACL %s\n", tok);
379 return NULL;
381 if(!add_ace(&dacl, &ace)) {
382 printf("Failed to add ACL %s\n", tok);
383 return NULL;
385 continue;
388 printf("Failed to parse security descriptor\n");
389 return NULL;
392 ret = make_sec_desc(ctx,revision, SEC_DESC_SELF_RELATIVE, owner_sid, grp_sid,
393 NULL, dacl, &sd_size);
395 SAFE_FREE(grp_sid);
396 SAFE_FREE(owner_sid);
398 return ret;
402 /* print a ascii version of a security descriptor on a FILE handle */
403 static void sec_desc_print(FILE *f, SEC_DESC *sd)
405 fstring sidstr;
406 uint32 i;
408 fprintf(f, "REVISION:%d\n", sd->revision);
410 /* Print owner and group sid */
412 if (sd->owner_sid) {
413 SidToString(sidstr, sd->owner_sid);
414 } else {
415 fstrcpy(sidstr, "");
418 fprintf(f, "OWNER:%s\n", sidstr);
420 if (sd->grp_sid) {
421 SidToString(sidstr, sd->grp_sid);
422 } else {
423 fstrcpy(sidstr, "");
426 fprintf(f, "GROUP:%s\n", sidstr);
428 /* Print aces */
429 for (i = 0; sd->dacl && i < sd->dacl->num_aces; i++) {
430 SEC_ACE *ace = &sd->dacl->ace[i];
431 fprintf(f, "ACL:");
432 print_ace(f, ace);
433 fprintf(f, "\n");
438 /*****************************************************
439 dump the acls for a file
440 *******************************************************/
441 static int cacl_dump(struct cli_state *cli, char *filename)
443 int result = EXIT_FAILED;
444 int fnum = -1;
445 SEC_DESC *sd;
447 if (test_args)
448 return EXIT_OK;
450 fnum = cli_nt_create(cli, filename, CREATE_ACCESS_READ);
452 if (fnum == -1) {
453 printf("Failed to open %s: %s\n", filename, cli_errstr(cli));
454 goto done;
457 sd = cli_query_secdesc(cli, fnum, ctx);
459 if (!sd) {
460 printf("ERROR: secdesc query failed: %s\n", cli_errstr(cli));
461 goto done;
464 sec_desc_print(stdout, sd);
466 result = EXIT_OK;
468 done:
469 if (fnum != -1)
470 cli_close(cli, fnum);
472 return result;
475 /*****************************************************
476 Change the ownership or group ownership of a file. Just
477 because the NT docs say this can't be done :-). JRA.
478 *******************************************************/
480 static int owner_set(struct cli_state *cli, enum chown_mode change_mode,
481 char *filename, char *new_username)
483 int fnum;
484 DOM_SID sid;
485 SEC_DESC *sd, *old;
486 size_t sd_size;
488 fnum = cli_nt_create(cli, filename, CREATE_ACCESS_READ);
490 if (fnum == -1) {
491 printf("Failed to open %s: %s\n", filename, cli_errstr(cli));
492 return EXIT_FAILED;
495 if (!StringToSid(&sid, new_username))
496 return EXIT_PARSE_ERROR;
498 old = cli_query_secdesc(cli, fnum, ctx);
500 cli_close(cli, fnum);
502 if (!old) {
503 printf("owner_set: Failed to query old descriptor\n");
504 return EXIT_FAILED;
507 sd = make_sec_desc(ctx,old->revision, old->type,
508 (change_mode == REQUEST_CHOWN) ? &sid : NULL,
509 (change_mode == REQUEST_CHGRP) ? &sid : NULL,
510 NULL, NULL, &sd_size);
512 fnum = cli_nt_create(cli, filename, WRITE_OWNER_ACCESS);
514 if (fnum == -1) {
515 printf("Failed to open %s: %s\n", filename, cli_errstr(cli));
516 return EXIT_FAILED;
519 if (!cli_set_secdesc(cli, fnum, sd)) {
520 printf("ERROR: secdesc set failed: %s\n", cli_errstr(cli));
523 cli_close(cli, fnum);
525 return EXIT_OK;
529 /* The MSDN is contradictory over the ordering of ACE entries in an ACL.
530 However NT4 gives a "The information may have been modified by a
531 computer running Windows NT 5.0" if denied ACEs do not appear before
532 allowed ACEs. */
534 static int ace_compare(SEC_ACE *ace1, SEC_ACE *ace2)
536 if (sec_ace_equal(ace1, ace2))
537 return 0;
539 if (ace1->type != ace2->type)
540 return ace2->type - ace1->type;
542 if (sid_compare(&ace1->trustee, &ace2->trustee))
543 return sid_compare(&ace1->trustee, &ace2->trustee);
545 if (ace1->flags != ace2->flags)
546 return ace1->flags - ace2->flags;
548 if (ace1->info.mask != ace2->info.mask)
549 return ace1->info.mask - ace2->info.mask;
551 if (ace1->size != ace2->size)
552 return ace1->size - ace2->size;
554 return memcmp(ace1, ace2, sizeof(SEC_ACE));
557 static void sort_acl(SEC_ACL *the_acl)
559 uint32 i;
560 if (!the_acl) return;
562 qsort(the_acl->ace, the_acl->num_aces, sizeof(the_acl->ace[0]), QSORT_CAST ace_compare);
564 for (i=1;i<the_acl->num_aces;) {
565 if (sec_ace_equal(&the_acl->ace[i-1], &the_acl->ace[i])) {
566 int j;
567 for (j=i; j<the_acl->num_aces-1; j++) {
568 the_acl->ace[j] = the_acl->ace[j+1];
570 the_acl->num_aces--;
571 } else {
572 i++;
577 /*****************************************************
578 set the ACLs on a file given an ascii description
579 *******************************************************/
580 static int cacl_set(struct cli_state *cli, char *filename,
581 char *the_acl, enum acl_mode mode)
583 int fnum;
584 SEC_DESC *sd, *old;
585 uint32 i, j;
586 size_t sd_size;
587 int result = EXIT_OK;
589 sd = sec_desc_parse(the_acl);
591 if (!sd) return EXIT_PARSE_ERROR;
592 if (test_args) return EXIT_OK;
594 /* The desired access below is the only one I could find that works
595 with NT4, W2KP and Samba */
597 fnum = cli_nt_create(cli, filename, CREATE_ACCESS_READ);
599 if (fnum == -1) {
600 printf("cacl_set failed to open %s: %s\n", filename, cli_errstr(cli));
601 return EXIT_FAILED;
604 old = cli_query_secdesc(cli, fnum, ctx);
606 if (!old) {
607 printf("calc_set: Failed to query old descriptor\n");
608 return EXIT_FAILED;
611 cli_close(cli, fnum);
613 /* the logic here is rather more complex than I would like */
614 switch (mode) {
615 case SMB_ACL_DELETE:
616 for (i=0;sd->dacl && i<sd->dacl->num_aces;i++) {
617 BOOL found = False;
619 for (j=0;old->dacl && j<old->dacl->num_aces;j++) {
620 if (sec_ace_equal(&sd->dacl->ace[i],
621 &old->dacl->ace[j])) {
622 uint32 k;
623 for (k=j; k<old->dacl->num_aces-1;k++) {
624 old->dacl->ace[k] = old->dacl->ace[k+1];
626 old->dacl->num_aces--;
627 found = True;
628 break;
632 if (!found) {
633 printf("ACL for ACE:");
634 print_ace(stdout, &sd->dacl->ace[i]);
635 printf(" not found\n");
638 break;
640 case SMB_ACL_MODIFY:
641 for (i=0;sd->dacl && i<sd->dacl->num_aces;i++) {
642 BOOL found = False;
644 for (j=0;old->dacl && j<old->dacl->num_aces;j++) {
645 if (sid_equal(&sd->dacl->ace[i].trustee,
646 &old->dacl->ace[j].trustee)) {
647 old->dacl->ace[j] = sd->dacl->ace[i];
648 found = True;
652 if (!found) {
653 fstring str;
655 SidToString(str, &sd->dacl->ace[i].trustee);
656 printf("ACL for SID %s not found\n", str);
660 if (sd->owner_sid) {
661 old->owner_sid = sd->owner_sid;
664 if (sd->grp_sid) {
665 old->grp_sid = sd->grp_sid;
668 break;
670 case SMB_ACL_ADD:
671 for (i=0;sd->dacl && i<sd->dacl->num_aces;i++) {
672 add_ace(&old->dacl, &sd->dacl->ace[i]);
674 break;
676 case SMB_ACL_SET:
677 old = sd;
678 break;
681 /* Denied ACE entries must come before allowed ones */
682 sort_acl(old->dacl);
684 /* Create new security descriptor and set it */
685 sd = make_sec_desc(ctx,old->revision, old->type, old->owner_sid, old->grp_sid,
686 NULL, old->dacl, &sd_size);
688 fnum = cli_nt_create(cli, filename, WRITE_DAC_ACCESS);
690 if (fnum == -1) {
691 printf("cacl_set failed to open %s: %s\n", filename, cli_errstr(cli));
692 return EXIT_FAILED;
695 if (!cli_set_secdesc(cli, fnum, sd)) {
696 printf("ERROR: secdesc set failed: %s\n", cli_errstr(cli));
697 result = EXIT_FAILED;
700 /* Clean up */
702 cli_close(cli, fnum);
704 return result;
708 /*****************************************************
709 return a connection to a server
710 *******************************************************/
711 static struct cli_state *connect_one(const char *share)
713 struct cli_state *c;
714 struct in_addr ip;
715 NTSTATUS nt_status;
716 zero_ip(&ip);
718 if (!cmdline_auth_info.got_pass) {
719 char *pass = getpass("Password: ");
720 if (pass) {
721 pstrcpy(cmdline_auth_info.password, pass);
722 cmdline_auth_info.got_pass = True;
726 if (NT_STATUS_IS_OK(nt_status = cli_full_connection(&c, global_myname(), server,
727 &ip, 0,
728 share, "?????",
729 cmdline_auth_info.username, lp_workgroup(),
730 cmdline_auth_info.password, 0,
731 cmdline_auth_info.signing_state, NULL))) {
732 return c;
733 } else {
734 DEBUG(0,("cli_full_connection failed! (%s)\n", nt_errstr(nt_status)));
735 return NULL;
739 /****************************************************************************
740 main program
741 ****************************************************************************/
742 int main(int argc, const char *argv[])
744 char *share;
745 int opt;
746 enum acl_mode mode = SMB_ACL_SET;
747 static char *the_acl = NULL;
748 enum chown_mode change_mode = REQUEST_NONE;
749 int result;
750 fstring path;
751 pstring filename;
752 poptContext pc;
753 struct poptOption long_options[] = {
754 POPT_AUTOHELP
755 { "delete", 'D', POPT_ARG_STRING, NULL, 'D', "Delete an acl", "ACL" },
756 { "modify", 'M', POPT_ARG_STRING, NULL, 'M', "Modify an acl", "ACL" },
757 { "add", 'a', POPT_ARG_STRING, NULL, 'a', "Add an acl", "ACL" },
758 { "set", 'S', POPT_ARG_STRING, NULL, 'S', "Set acls", "ACLS" },
759 { "chown", 'C', POPT_ARG_STRING, NULL, 'C', "Change ownership of a file", "USERNAME" },
760 { "chgrp", 'G', POPT_ARG_STRING, NULL, 'G', "Change group ownership of a file", "GROUPNAME" },
761 { "numeric", 0, POPT_ARG_NONE, &numeric, True, "Don't resolve sids or masks to names" },
762 { "test-args", 't', POPT_ARG_NONE, &test_args, True, "Test arguments"},
763 POPT_COMMON_SAMBA
764 POPT_COMMON_CREDENTIALS
765 { NULL }
768 struct cli_state *cli;
770 ctx=talloc_init("main");
772 /* set default debug level to 1 regardless of what smb.conf sets */
773 setup_logging( "smbcacls", True );
774 DEBUGLEVEL_CLASS[DBGC_ALL] = 1;
775 dbf = x_stderr;
776 x_setbuf( x_stderr, NULL );
778 setlinebuf(stdout);
780 lp_load(dyn_CONFIGFILE,True,False,False);
781 load_interfaces();
783 pc = poptGetContext("smbcacls", argc, argv, long_options, 0);
785 poptSetOtherOptionHelp(pc, "//server1/share1 filename");
787 while ((opt = poptGetNextOpt(pc)) != -1) {
788 switch (opt) {
789 case 'S':
790 the_acl = smb_xstrdup(poptGetOptArg(pc));
791 mode = SMB_ACL_SET;
792 break;
794 case 'D':
795 the_acl = smb_xstrdup(poptGetOptArg(pc));
796 mode = SMB_ACL_DELETE;
797 break;
799 case 'M':
800 the_acl = smb_xstrdup(poptGetOptArg(pc));
801 mode = SMB_ACL_MODIFY;
802 break;
804 case 'a':
805 the_acl = smb_xstrdup(poptGetOptArg(pc));
806 mode = SMB_ACL_ADD;
807 break;
809 case 'C':
810 pstrcpy(owner_username,poptGetOptArg(pc));
811 change_mode = REQUEST_CHOWN;
812 break;
814 case 'G':
815 pstrcpy(owner_username,poptGetOptArg(pc));
816 change_mode = REQUEST_CHGRP;
817 break;
821 /* Make connection to server */
822 if(!poptPeekArg(pc)) {
823 poptPrintUsage(pc, stderr, 0);
824 return -1;
827 fstrcpy(path, poptGetArg(pc));
829 if(!poptPeekArg(pc)) {
830 poptPrintUsage(pc, stderr, 0);
831 return -1;
834 pstrcpy(filename, poptGetArg(pc));
836 all_string_sub(path,"/","\\",0);
838 fstrcpy(server,path+2);
839 share = strchr_m(server,'\\');
840 if (!share) {
841 share = strchr_m(server,'/');
842 if (!share) {
843 printf("Invalid argument: %s\n", share);
844 return -1;
848 *share = 0;
849 share++;
851 if (!test_args) {
852 cli = connect_one(share);
853 if (!cli) {
854 talloc_destroy(ctx);
855 exit(EXIT_FAILED);
857 } else {
858 exit(0);
861 all_string_sub(filename, "/", "\\", 0);
862 if (filename[0] != '\\') {
863 pstring s;
864 s[0] = '\\';
865 safe_strcpy(&s[1], filename, sizeof(pstring)-2);
866 pstrcpy(filename, s);
869 /* Perform requested action */
871 if (change_mode != REQUEST_NONE) {
872 result = owner_set(cli, change_mode, filename, owner_username);
873 } else if (the_acl) {
874 result = cacl_set(cli, filename, the_acl, mode);
875 } else {
876 result = cacl_dump(cli, filename);
879 talloc_destroy(ctx);
881 return result;