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

« back to all changes in this revision

Viewing changes to tests/regression/subdomain/changehat_twice.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
/* $Id: changehat_twice.c 61 2006-05-19 18:32:14Z steve-beattie $ */
 
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
 
 
12
#include <stdio.h>
 
13
#include <unistd.h>
 
14
#include <errno.h>
 
15
#include <sys/types.h>
 
16
#include <sys/stat.h>
 
17
#include <sys/wait.h>
 
18
#include <fcntl.h>
 
19
#include <string.h>
 
20
#include <stdlib.h>
 
21
#include <linux/unistd.h>
 
22
 
 
23
#include "changehat.h"
 
24
 
 
25
int main(int argc, char *argv[])
 
26
{
 
27
        int rc, magic;
 
28
 
 
29
        if (argc != 5){
 
30
                fprintf(stderr, "usage: %s profile1 profile2 goodmagic|badmagic file\n",
 
31
                        argv[0]);
 
32
                return 1;
 
33
        }
 
34
 
 
35
        /* change hat if hatname != nochange */
 
36
        if (strcmp(argv[1], "nochange") != 0){
 
37
                rc = change_hat(argv[1], SD_ID_MAGIC+1);
 
38
                if (rc == -1){
 
39
                        fprintf(stderr, "FAIL: changehat %s failed - %s\n",
 
40
                                argv[1], strerror(errno));
 
41
                        exit(1);
 
42
                }
 
43
        }
 
44
 
 
45
        magic=SD_ID_MAGIC+1;
 
46
        if (strcmp(argv[3], "badmagic") == 0){
 
47
                magic^=0xdeadbeef;
 
48
        }
 
49
 
 
50
        if (strcmp(argv[1], "nochange") != 0){
 
51
                rc = change_hat(argv[2], magic);
 
52
                if (rc == -1){
 
53
                        fprintf(stderr, "FAIL: changehat %s failed - %s\n",
 
54
                                argv[1], strerror(errno));
 
55
                        exit(1);
 
56
                }
 
57
        }
 
58
 
 
59
        rc = do_open(argv[4]);
 
60
        if (rc != 0)
 
61
                return rc;
 
62
 
 
63
        printf("PASS\n");
 
64
        return 0;
 
65
}