3 * Copyright (C) 2012 Simone Piccardi
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or (at
8 * your option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 /****************************************************************
21 * Program mygetfacl.c:
22 * A simple program that get a file acl
24 * Author: Simone Piccardi
27 ****************************************************************/
29 * Include needed headers
31 #include <sys/types.h> /* primitive system data types */
32 #include <stdlib.h> /* C standard library */
33 #include <unistd.h> /* unix standard library */
34 #include <stdio.h> /* standard I/O library */
35 #include <sys/acl.h> /* acl library (use -l acl) */
36 #include <errno.h> /* acl library (use -l acl) */
39 /* pass -D DEBUG to gcc to enable debug printing */
43 #define debug(fmt, arg...)
49 /* Help printing routine */
52 int main(int argc, char *argv[])
55 * Variables definition
62 * Input section: decode command line parameters
65 opterr = 0; /* don't want writing to stderr */
66 while ( (i = getopt(argc, argv, "h")) != -1) {
71 case 'h': /* help option */
72 printf("Wrong -h option use\n");
76 case '?': /* unrecognized options */
77 printf("Unrecognized options -%c\n",optopt);
79 default: /* should not reached */
83 /* must have an argument */
84 if ((argc - optind) != 1) {
85 printf("Wrong number of arguments %d\n", argc - optind);
90 acl = acl_get_file(argv[1], ACL_TYPE_ACCESS);
92 printf("error on getting ACL for file %s\n", argv[1]);
96 buffer = acl_to_text(acl, &size);
98 perror("cannot convert acl");
101 printf("ACL for file '%s':\n%s\n", argv[1], buffer);
109 * routine to print usage info and exit
112 printf("Program mymount: \n");
114 printf("mygetfacl [-h] file\n");
115 printf(" -h print this help\n");