update changelog
[platform/upstream/acl.git] / examples / set-acl.c
1 /*
2   Copyright (C) 2009  Andreas Gruenbacher <agruen@suse.de>
3
4   This program is free software: you can redistribute it and/or modify it
5   under the terms of the GNU General Public License as published by
6   the Free Software Foundation, either version 2 of the License, or
7   (at your option) any later version.
8
9   This program is distributed in the hope that it will be useful,
10   but WITHOUT ANY WARRANTY; without even the implied warranty of
11   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12   GNU General Public License for more details.
13
14   You should have received a copy of the GNU General Public License
15   along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 #include <stdio.h>
19 #include <string.h>
20 #include <errno.h>
21 #include <libgen.h>
22 #include <sys/acl.h>
23
24 const char *progname;
25
26 int main(int argc, char *argv[])
27 {
28         acl_t acl;
29         int n, ret = 0;
30
31         progname = basename(argv[0]);
32
33         if (argc < 3) {
34                 printf("%s -- set access control list of files\n"
35                         "Usage: %s acl file ...\n",
36                         progname, progname);
37                 return 1;
38         }
39
40         acl = acl_from_text(argv[1]);
41         if (!acl) {
42                 fprintf(stderr, "%s: `%s': %s\n",
43                         progname, argv[1], strerror(errno));
44                 return 1;
45         }
46         if (acl_valid(acl) != 0) {
47                 fprintf(stderr, "%s: `%s': invalid/incomplete acl\n",
48                         progname, argv[1]);
49                 acl_free(acl);
50                 return 1;
51         }
52
53         for (n = 2; n < argc; n++) {
54                 if (acl_set_file(argv[n], ACL_TYPE_ACCESS, acl) != 0) {
55                         fprintf(stderr, "%s: setting acl of %s: %s\n",
56                                 progname, argv[n], strerror(errno));
57                         ret = 1;
58                 }
59         }
60
61         acl_free(acl);
62
63         return ret;
64 }