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

« back to all changes in this revision

Viewing changes to tests/regression/subdomain/env_check.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: env_check.c 427 2007-03-08 00:09:47Z steve-beattie $ */
2
 
 
3
 
/*      Copyright (C) 2002-2006 Novell/SUSE
4
 
 *
5
 
 *      This program is free software; you can redistribute it and/or
6
 
 *      modify it under the terms of the GNU General Public License as
7
 
 *      published by the Free Software Foundation, version 2 of the
8
 
 *      License.
9
 
 */
10
 
 
11
 
#define _GNU_SOURCE
12
 
#include <stdio.h>
13
 
#include <stdlib.h>
14
 
#include <string.h>
15
 
#include <unistd.h>
16
 
#include <errno.h>
17
 
 
18
 
int main(int argc, char *argv[])
19
 
{
20
 
        char *var, *val, *p, *envval;
21
 
 
22
 
        if (argc < 2 || !(p = strchr(argv[1], '='))) {
23
 
                fprintf(stderr, "Usage: %s VAR=value\n", argv[0]);
24
 
                return 1;
25
 
        }
26
 
 
27
 
        var = strndup(argv[1], p - argv[1]);
28
 
        val = strdup(p + 1);
29
 
 
30
 
        envval = getenv(var);
31
 
        if (!envval) {
32
 
                fprintf(stderr, "FAIL: environment variable not found\n");
33
 
                return 1;
34
 
        }
35
 
 
36
 
        if (strcmp(envval, val) != 0) {
37
 
                fprintf(stderr, "FAIL: environment variable differs: expected '%s', found '%s'\n",
38
 
                        val, envval);
39
 
                return 1;
40
 
        }
41
 
        return 0;
42
 
}