~ubuntu-branches/ubuntu/vivid/nfs4-acl-tools/vivid-proposed

« back to all changes in this revision

Viewing changes to nfs4_getfacl/nfs4_getfacl.c

  • Committer: Bazaar Package Importer
  • Author(s): Timo Aaltonen
  • Date: 2009-05-12 13:53:04 UTC
  • Revision ID: james.westby@ubuntu.com-20090512135304-b4hyk0en3a0v8r3p
Tags: upstream-0.3.3
ImportĀ upstreamĀ versionĀ 0.3.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*  Copyright (c) 2002, 2003, 2006 The Regents of the University of Michigan.
 
2
 *  All rights reserved.
 
3
 *
 
4
 *  Andy Adamson <andros@citi.umich.edu>
 
5
 *  David M. Richter <richterd@citi.umich.edu>
 
6
 *  Alexis Mackenzie <allamack@citi.umich.edu>
 
7
 *  Alex Soule <soule@umich.edu>
 
8
 *
 
9
 *  Redistribution and use in source and binary forms, with or without
 
10
 *  modification, are permitted provided that the following conditions
 
11
 *  are met:
 
12
 *
 
13
 *  1. Redistributions of source code must retain the above copyright
 
14
 *     notice, this list of conditions and the following disclaimer.
 
15
 *  2. Redistributions in binary form must reproduce the above copyright
 
16
 *     notice, this list of conditions and the following disclaimer in the
 
17
 *     documentation and/or other materials provided with the distribution.
 
18
 *  3. Neither the name of the University nor the names of its
 
19
 *     contributors may be used to endorse or promote products derived
 
20
 *     from this software without specific prior written permission.
 
21
 *
 
22
 *  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
 
23
 *  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 
24
 *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 
25
 *  DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 
26
 *  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 
27
 *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 
28
 *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
 
29
 *  BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 
30
 *  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 
31
 *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 
32
 *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
33
 */
 
34
 
 
35
 
 
36
#include <stdio.h>
 
37
#include <errno.h>
 
38
#include <string.h>
 
39
#include <sys/types.h>
 
40
#include <libgen.h>
 
41
#include "libacl_nfs4.h"
 
42
 
 
43
static void usage(int);
 
44
static void more_help();
 
45
static char *execname;
 
46
 
 
47
int main(int argc, char **argv)
 
48
{
 
49
        struct nfs4_acl *acl;
 
50
        int res = 1;
 
51
        
 
52
        execname = basename(argv[0]);
 
53
 
 
54
        if (argc < 2) {
 
55
                fprintf(stderr, "%s: you must specify a path.\n", execname);
 
56
                usage(0);
 
57
                goto out;
 
58
        } else if (argc > 2) {
 
59
                fprintf(stderr, "%s: currently, you may only specify a single path.\n", execname);
 
60
                usage(0);
 
61
                goto out;
 
62
        } else if (!strcmp(argv[1], "-?") || !strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")) {
 
63
                usage(1);
 
64
                res = 0;
 
65
                goto out;
 
66
        } else if (!strcmp(argv[1], "-H") || !strcmp(argv[1], "--more-help")) {
 
67
                more_help();
 
68
                res = 0;
 
69
                goto out;
 
70
        }
 
71
        acl = nfs4_acl_for_path(argv[1]);
 
72
        if (acl != NULL) {
 
73
                nfs4_print_acl(stdout, acl);
 
74
                res = 0;
 
75
        }
 
76
out:
 
77
        return res;
 
78
}
 
79
 
 
80
static void usage(int label)
 
81
{
 
82
        if (label)
 
83
                fprintf(stderr, "%s %s -- get NFSv4 file or directory access control lists.\n", execname, VERSION);
 
84
        fprintf(stderr, "Usage: %s file\n  -H, --more-help\tdisplay ACL format information\n  -?, -h, --help\tdisplay this help text\n", execname);
 
85
}
 
86
 
 
87
static void more_help()
 
88
{
 
89
        const char *info = \
 
90
        "%s %s -- get NFSv4 file or directory access control lists.\n\n"
 
91
        "An NFSv4 ACL consists of one or more NFSv4 ACEs, each delimited by commas or whitespace.\n"
 
92
        "An NFSv4 ACE is written as a colon-delimited, 4-field string in the following format:\n"
 
93
        "\n"
 
94
        "    <type>:<flags>:<principal>:<permissions>\n"
 
95
        "\n"
 
96
        "    * <type> - one of:\n"
 
97
        "        'A'  allow\n"
 
98
        "        'D'  deny\n"
 
99
        "        'U'  audit\n"
 
100
        "        'L'  alarm\n"
 
101
        "\n"
 
102
        "    * <flags> - zero or more (depending on <type>) of:\n"
 
103
        "        'f'  file-inherit\n"
 
104
        "        'd'  directory-inherit\n"
 
105
        "        'p'  no-propagate-inherit\n"
 
106
        "        'i'  inherit-only\n"
 
107
        "        'S'  successful-access\n"
 
108
        "        'F'  failed-access\n"
 
109
        "        'g'  group (denotes that <principal> is a group)\n"
 
110
        "\n"
 
111
        "    * <principal> - named user or group, or one of: \"OWNER@\", \"GROUP@\", \"EVERYONE@\"\n"
 
112
        "\n"
 
113
        "    * <permissions> - one or more of:\n"
 
114
        "        'r'  read-data / list-directory \n"
 
115
        "        'w'  write-data / create-file \n"
 
116
        "        'a'  append-data / create-subdirectory \n"
 
117
        "        'x'  execute \n"
 
118
        "        'd'  delete\n"
 
119
        "        'D'  delete-child (directories only)\n"
 
120
        "        't'  read-attrs\n"
 
121
        "        'T'  write-attrs\n"
 
122
        "        'n'  read-named-attrs\n"
 
123
        "        'N'  write-named-attrs\n"
 
124
        "        'c'  read-ACL\n"
 
125
        "        'C'  write-ACL\n"
 
126
        "        'o'  write-owner\n"
 
127
        "        'y'  synchronize\n"
 
128
        "\n"
 
129
        "For more information and examples, please refer to the nfs4_acl(5) manpage.\n";
 
130
 
 
131
        printf(info, execname, VERSION); 
 
132
}