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

« back to all changes in this revision

Viewing changes to tests/regression/subdomain/syscall_setdomainname.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
 
/* $Id: syscall_setdomainname.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 <string.h>
17
 
 
18
 
/* this implicitly tests getdomainname, too. */
19
 
 
20
 
#define RESET_DOMAIN_WHEN_DONE
21
 
 
22
 
#define BUFSIZE 4096
23
 
int main(int argc, char *argv[])
24
 
{
25
 
        char saved_domain[BUFSIZE];
26
 
        char new_domain[BUFSIZE];
27
 
        size_t len = sizeof(saved_domain);
28
 
        size_t newlen;
29
 
        int error = 0;
30
 
 
31
 
        if (argc != 2) {
32
 
                fprintf(stderr, "usage: %s domain\n",
33
 
                                argv[0]);
34
 
                return 1;
35
 
        }
36
 
 
37
 
        newlen = strlen(argv[1]);
38
 
        if (newlen <= 0 || newlen >= BUFSIZE) {
39
 
                fprintf(stderr, "FAIL: invalid domain '%s'\n",
40
 
                                argv[1]);
41
 
                return 1;
42
 
        }
43
 
        
44
 
        if (getdomainname(saved_domain, len) == -1) {
45
 
                fprintf(stderr, "FAIL: getdomainname failed - %s\n",
46
 
                        strerror(errno));
47
 
                return 1;
48
 
        }
49
 
        /* printf("old domainname is %s\n", saved_domain ? saved_domain : "NULL"); */
50
 
 
51
 
        if (setdomainname(argv[1], strlen(argv[1])) == -1) {
52
 
                fprintf(stderr, "FAIL: setdomainname failed - %s\n",
53
 
                        strerror(errno));
54
 
                return 1;
55
 
        }
56
 
 
57
 
        len = sizeof(new_domain);
58
 
        if (getdomainname(new_domain, len) == -1) {
59
 
                fprintf(stderr, "FAIL: getdomainname failed - %s\n",
60
 
                        strerror(errno));
61
 
                error = 1;
62
 
                goto cleanup;
63
 
        }
64
 
 
65
 
        if (strcmp(new_domain, argv[1]) != 0) {
66
 
                fprintf(stderr, "FAIL: attempted to set domainname to '%s', "
67
 
                                "but '%s' was the result\n",
68
 
                        argv[1],
69
 
                        new_domain);
70
 
                error = 1;
71
 
                goto cleanup;
72
 
        }
73
 
 
74
 
cleanup:
75
 
#ifdef RESET_DOMAIN_WHEN_DONE
76
 
        if (setdomainname(saved_domain, strlen(saved_domain)) == -1) {
77
 
                fprintf(stderr, "FAIL: setdomainname failed restting to old name - %s\n",
78
 
                        strerror(errno));
79
 
                error = 1;
80
 
        }
81
 
#endif /* RESET_DOMAIN_WHEN_DONE */
82
 
        
83
 
        if (error == 0)
84
 
                printf("PASS\n");
85
 
 
86
 
        return error;
87
 
}