~ubuntu-branches/ubuntu/raring/apparmor/raring

« back to all changes in this revision

Viewing changes to tests/stress/subdomain/change_hat.c

  • Committer: Bazaar Package Importer
  • Author(s): Kees Cook
  • Date: 2007-03-23 16:42:01 UTC
  • Revision ID: james.westby@ubuntu.com-20070323164201-jkax6f0oku087b7l
Tags: upstream-2.0.1+510.dfsg
ImportĀ upstreamĀ versionĀ 2.0.1+510.dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <unistd.h>
 
2
#include <sys/types.h>
 
3
#include <sys/stat.h>
 
4
#include <fcntl.h>
 
5
#include <errno.h>
 
6
#include <string.h>
 
7
#include <stdio.h>
 
8
#include <linux/unistd.h>
 
9
 
 
10
#include "sys/immunix.h"
 
11
 
 
12
#define SD_ID_MAGIC 0xdeadbeef
 
13
 
 
14
int main(int argc, char *argv[])
 
15
{
 
16
        int fd, error;
 
17
        char *hat_name;
 
18
        int hat_magic;
 
19
        char *o_file = "/bin/ls";
 
20
 
 
21
        while (1) {
 
22
        hat_name = "/subprofile/foo";
 
23
        hat_magic = SD_ID_MAGIC + 1;
 
24
        if (argc > 1)
 
25
                hat_name = argv[1];
 
26
 
 
27
        printf("before entering change_hat\n");
 
28
        error = change_hat(hat_name, hat_magic);
 
29
        printf("change_hat(%s, 0x%x): %s\n", hat_name, hat_magic,
 
30
                                                        strerror(errno));
 
31
 
 
32
        errno = 0;
 
33
        fd = open(o_file, O_RDONLY);
 
34
        printf("open(%s): %s\n", o_file, strerror(errno));
 
35
        if (fd != -1)
 
36
                close(fd);
 
37
        
 
38
        hat_name = NULL;
 
39
        printf("before leaving change_hat\n");
 
40
        errno = 0;
 
41
        error = change_hat(hat_name, hat_magic);
 
42
        printf("change_hat(%s, 0x%x): %s\n", "NULL", hat_magic,
 
43
                                                        strerror(errno));
 
44
 
 
45
        errno = 0;
 
46
        fd = open(o_file, O_RDONLY);
 
47
        printf("open(%s): %s\n", o_file, strerror(errno));
 
48
        if (fd != -1)
 
49
                close(fd);
 
50
        }
 
51
}