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

« back to all changes in this revision

Viewing changes to libnfs4acl/acl_nfs4_get_who.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
/*
 
2
 *  NFSv4 ACL Code
 
3
 *  Read the who value from the ace and return its type and optionally
 
4
 *  its value.
 
5
 *
 
6
 *  Ace is a reference to the ace to extract the who value from.
 
7
 *  Type is a reference where the value of the whotype will be stored.
 
8
 *  Who is a double reference that should either be passed as NULL
 
9
 *  (and thus no who string will be returned) or as a pointer to a
 
10
 *  char* where the who string will be allocated. This string must be
 
11
 *  freed by the caller.
 
12
 *
 
13
 *  Copyright (c) 2002, 2003, 2006 The Regents of the University of Michigan.
 
14
 *  All rights reserved.
 
15
 *
 
16
 *  Nathaniel Gallaher <ngallahe@umich.edu>
 
17
 *
 
18
 *  Redistribution and use in source and binary forms, with or without
 
19
 *  modification, are permitted provided that the following conditions
 
20
 *  are met:
 
21
 *
 
22
 *  1. Redistributions of source code must retain the above copyright
 
23
 *     notice, this list of conditions and the following disclaimer.
 
24
 *  2. Redistributions in binary form must reproduce the above copyright
 
25
 *     notice, this list of conditions and the following disclaimer in the
 
26
 *     documentation and/or other materials provided with the distribution.
 
27
 *  3. Neither the name of the University nor the names of its
 
28
 *     contributors may be used to endorse or promote products derived
 
29
 *     from this software without specific prior written permission.
 
30
 *
 
31
 *  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
 
32
 *  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 
33
 *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 
34
 *  DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 
35
 *  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 
36
 *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 
37
 *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
 
38
 *  BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 
39
 *  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 
40
 *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 
41
 *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
42
 */
 
43
 
 
44
#include "libacl_nfs4.h"
 
45
 
 
46
int acl_nfs4_get_who(struct nfs4_ace* ace, int* type, char** who)
 
47
{
 
48
        int itype;
 
49
        char* iwho = NULL;
 
50
        int wholen;
 
51
 
 
52
        if (ace == NULL || ace->who == NULL)
 
53
                goto inval_failed;
 
54
 
 
55
        itype = acl_nfs4_get_whotype(ace->who);
 
56
        if (type != NULL) {
 
57
                *type = itype;
 
58
        }
 
59
 
 
60
        if(who == NULL)
 
61
                return 0;
 
62
 
 
63
        switch(itype) {
 
64
                case NFS4_ACL_WHO_NAMED:
 
65
                        iwho = ace->who;
 
66
                        break;
 
67
                case NFS4_ACL_WHO_OWNER:
 
68
                        iwho = NFS4_ACL_WHO_OWNER_STRING;
 
69
                        break;
 
70
                case NFS4_ACL_WHO_GROUP:
 
71
                        iwho = NFS4_ACL_WHO_GROUP_STRING;
 
72
                        break;
 
73
                case NFS4_ACL_WHO_EVERYONE:
 
74
                        iwho = NFS4_ACL_WHO_EVERYONE_STRING;
 
75
                        break;
 
76
                default:
 
77
                        goto inval_failed;
 
78
        }
 
79
 
 
80
        wholen = strlen(iwho);
 
81
        if (wholen < 0)
 
82
                goto inval_failed;
 
83
 
 
84
        (*who) = (char *)malloc(sizeof(char) * (wholen + 1));
 
85
        if ((*who) == NULL) {
 
86
                errno = ENOMEM;
 
87
                goto failed;
 
88
        }
 
89
        strcpy((*who), iwho);
 
90
 
 
91
        return 0;
 
92
 
 
93
inval_failed:
 
94
        errno = EINVAL;
 
95
failed:
 
96
        return -1;
 
97
}
 
98