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

« back to all changes in this revision

Viewing changes to tests/regression/subdomain/changehat.h

  • 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
 
/* $Id: changehat.h 61 2006-05-19 18:32:14Z steve-beattie $ */
2
 
 
3
 
 
4
 
/* #define CHANGEHAT_NOT_IN_GLIB */
5
 
 
6
 
#define SD_ID_MAGIC     0x8c235e38
7
 
 
8
 
#ifdef CHANGEHAT_NOT_IN_LIBRARY
9
 
#  ifdef CHANGEHAT_2_4_KERNEL
10
 
 
11
 
struct sd_hat {
12
 
        char *hat_name;
13
 
        unsigned int hat_magic;
14
 
};
15
 
 
16
 
#define __NR_security   223 
17
 
#define SD_CHANGE_HAT   10
18
 
 
19
 
_syscall3(int, security, unsigned int, id, unsigned int, call, unsigned long *, args);
20
 
 
21
 
int change_hat (char * subprofile, unsigned int token)
22
 
{
23
 
        struct sd_hat hat;
24
 
        unsigned int id = SD_ID_MAGIC;
25
 
 
26
 
        hat.hat_name=subprofile;
27
 
        hat.hat_magic = token;
28
 
 
29
 
        return security(id, SD_CHANGE_HAT, (unsigned long*)&hat);
30
 
}
31
 
 
32
 
#  else
33
 
#    ifdef CHANGEHAT_2_2_KERNEL
34
 
#define __NR_change_hat 230
35
 
 
36
 
_syscall2(int, change_hat, char *, subdomain, unsigned int, magic_token);
37
 
 
38
 
#    endif /* CHANGEHAT_2_2_KERNEL */
39
 
#  endif /* CHANGEHAT_2_4_KERNEL */
40
 
 
41
 
#else /* !CHANGEHAT_NOT_IN_LIBRARY */
42
 
#ifdef USE_COMPAT_IMMUNIX_H
43
 
#include <sys/immunix.h>
44
 
#else
45
 
#include <sys/apparmor.h>
46
 
#endif /* USE_COMPAT_IMMUNIX_H */
47
 
#endif /* CHANGEHAT_NOT_IN_LIBRARY */
48
 
 
49
 
#include <fcntl.h>
50
 
#include <string.h>
51
 
 
52
 
inline int do_open (char * file)
53
 
{
54
 
        int fd, rc;
55
 
        char buf[128];
56
 
        const char *data="hello world";
57
 
 
58
 
        fd=open(file, O_RDWR, 0);
59
 
        if (fd == -1){
60
 
                fprintf(stderr, "FAIL: open %s failed - %s\n",
61
 
                        file,
62
 
                        strerror(errno));
63
 
                return 1;
64
 
        }
65
 
 
66
 
        rc=write(fd, data, strlen(data));
67
 
 
68
 
        if (rc != strlen(data)){
69
 
                fprintf(stderr, "FAIL: write failed - %s\n",
70
 
                        strerror(errno));
71
 
                return 1;
72
 
        }
73
 
 
74
 
        (void)lseek(fd, 0, SEEK_SET);
75
 
        rc=read(fd, buf, sizeof(buf));
76
 
 
77
 
        if (rc != strlen(data)){
78
 
                fprintf(stderr, "FAIL: read failed - %s\n",
79
 
                        strerror(errno));
80
 
                return 1;
81
 
        }
82
 
 
83
 
        if (memcmp(buf, data, strlen(data)) != 0){
84
 
                fprintf(stderr, "FAIL: comparison failed - %s\n",
85
 
                        strerror(errno));
86
 
                return 1;
87
 
        }
88
 
 
89
 
        close(fd);
90
 
 
91
 
        return 0;
92
 
}