~ubuntu-branches/ubuntu/wily/apparmor/wily

« back to all changes in this revision

Viewing changes to tests/regression/apparmor/xattrs.c

  • Committer: Bazaar Package Importer
  • Author(s): Kees Cook
  • Date: 2011-04-27 10:38:07 UTC
  • mfrom: (5.1.118 natty)
  • Revision ID: james.westby@ubuntu.com-20110427103807-ym3rhwys6o84ith0
Tags: 2.6.1-2
debian/copyright: clarify for some full organization names.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <sys/types.h>
 
2
 
 
3
/*
 
4
 *      Copyright (C) 2002-2005 Novell/SUSE
 
5
 *
 
6
 *      This program is free software; you can redistribute it and/or
 
7
 *      modify it under the terms of the GNU General Public License as
 
8
 *      published by the Free Software Foundation, version 2 of the
 
9
 *      License.
 
10
 */
 
11
#include <sys/xattr.h>
 
12
#include <stdio.h>
 
13
#include <errno.h>
 
14
#include <stdlib.h>
 
15
#include <string.h>
 
16
 
 
17
#define msgstring "hello"
 
18
#define msglen (strlen(msgstring)+1)
 
19
/*
 
20
 *NAME xattrs-write
 
21
 *DESCRIPTION this test does setxattr on a file
 
22
 *
 
23
 *argv[1] - file to test
 
24
 *argv[2] - xattr namespace to test
 
25
 *argv[3] - "read", "write", "remove"
 
26
 */
 
27
int main(int argc, char *argv[])
 
28
{
 
29
        ssize_t len;
 
30
        char name[256];
 
31
 
 
32
        if (argc != 4) {
 
33
                int i;
 
34
                fprintf(stderr, "usage: %s file xattr-name_space {read,write,remove}\n",
 
35
                        argv[0]);
 
36
                for (i=0; i < argc; i++) {
 
37
                        fprintf(stderr, "arg%d: %s\n", i, argv[i]);
 
38
                }
 
39
                return 1;
 
40
        }
 
41
        
 
42
        snprintf(name, sizeof(name), "%s.sdtest", argv[2]);
 
43
        if (strcmp(argv[3], "read") == 0) {
 
44
                char value[256];
 
45
                len = lgetxattr(argv[1], name, &value, 256);
 
46
                if (len == -1) {
 
47
                        fprintf(stderr, "FAIL: get of %s on %s.  %s\n", name,
 
48
                                argv[1], strerror(errno));
 
49
                        return 1;
 
50
                }
 
51
        } else if (strcmp(argv[3], "write") == 0) {
 
52
                len = lsetxattr(argv[1], name, msgstring, msglen, 0);
 
53
                if (len == -1) {
 
54
                        fprintf(stderr, "FAIL: set of %s on %s.  %s\n", name,
 
55
                                argv[1], strerror(errno));
 
56
                        return 1;
 
57
                }
 
58
        } else if (strcmp(argv[3], "remove") == 0) {
 
59
                len = lremovexattr(argv[1], name);
 
60
                if (len == -1) {
 
61
                        fprintf(stderr, "FAIL: remove of %s on %s.  %s\n",
 
62
                                name, argv[1], strerror(errno));
 
63
                        return 1;
 
64
                }
 
65
        } else {
 
66
                fprintf(stderr, "usage: %s invalid option %s is not one of {read, write, remove}\n", argv[0], argv[3]);
 
67
                return 1;
 
68
        }
 
69
 
 
70
        printf("PASS\n");
 
71
 
 
72
        return 0;
 
73
}