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

« back to all changes in this revision

Viewing changes to libnfs4acl/nfs4_acl_spec_from_file.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) 2006 The Regents of the University of Michigan.
 
2
 *  All rights reserved.
 
3
 *
 
4
 *  David M. Richter <richterd@citi.umich.edu>
 
5
 *
 
6
 *  Redistribution and use in source and binary forms, with or without
 
7
 *  modification, are permitted provided that the following conditions
 
8
 *  are met:
 
9
 *
 
10
 *  1. Redistributions of source code must retain the above copyright
 
11
 *     notice, this list of conditions and the following disclaimer.
 
12
 *  2. Redistributions in binary form must reproduce the above copyright
 
13
 *     notice, this list of conditions and the following disclaimer in the
 
14
 *     documentation and/or other materials provided with the distribution.
 
15
 *  3. Neither the name of the University nor the names of its
 
16
 *     contributors may be used to endorse or promote products derived
 
17
 *     from this software without specific prior written permission.
 
18
 *
 
19
 *  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
 
20
 *  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 
21
 *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 
22
 *  DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 
23
 *  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 
24
 *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 
25
 *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
 
26
 *  BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 
27
 *  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 
28
 *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 
29
 *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
30
 */
 
31
 
 
32
#include <stdio.h>
 
33
#include <string.h>
 
34
#include "libacl_nfs4.h"
 
35
 
 
36
 
 
37
char * nfs4_acl_spec_from_file(FILE *f)
 
38
{
 
39
        char ace_buf[NFS4_MAX_ACESIZE];
 
40
        char *acl_spec, *c;
 
41
        int consumed = 0;
 
42
 
 
43
        if (!f)
 
44
                return NULL;
 
45
 
 
46
        acl_spec = calloc(1, NFS4_MAX_ACLSIZE);
 
47
        if (!acl_spec)
 
48
                return NULL;
 
49
 
 
50
        while (fgets(ace_buf, NFS4_MAX_ACESIZE, f) != NULL) {
 
51
                if ((c = strchr(ace_buf, '#')) != NULL)
 
52
                        *c = '\0';
 
53
                consumed += strlen(ace_buf);
 
54
                if (consumed > NFS4_MAX_ACLSIZE) {
 
55
                        fprintf(stderr, "ERROR: maximum ACL buffer size exceeded (%d > %d).\n",
 
56
                                        NFS4_MAX_ACLSIZE, consumed);
 
57
                        free(acl_spec);
 
58
                        return NULL;
 
59
                }
 
60
                strncat(acl_spec, ace_buf, NFS4_MAX_ACESIZE);
 
61
 
 
62
        }
 
63
 
 
64
        return acl_spec;
 
65
}