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

« back to all changes in this revision

Viewing changes to tests/regression/apparmor/fchgrp.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
/*
 
2
 *      Copyright (C) 2002-2007 Novell/SUSE
 
3
 *
 
4
 *      This program is free software; you can redistribute it and/or
 
5
 *      modify it under the terms of the GNU General Public License as
 
6
 *      published by the Free Software Foundation, version 2 of the
 
7
 *      License.
 
8
 */
 
9
 
 
10
#include <stdio.h>
 
11
#include <unistd.h>
 
12
#include <errno.h>
 
13
#include <sys/types.h>
 
14
#include <sys/stat.h>
 
15
#include <fcntl.h>
 
16
#include <string.h>
 
17
 
 
18
int main(int argc, char *argv[])
 
19
{
 
20
        gid_t gid;
 
21
        int fd;
 
22
 
 
23
        if (argc != 3) {
 
24
                fprintf(stderr, "usage: %s file groupname|gid\n",
 
25
                        argv[0]);
 
26
                return 1;
 
27
        }
 
28
 
 
29
 
 
30
        if (sscanf(argv[2], "%d", &gid) != 1) {
 
31
                fprintf(stderr, "FAIL: bad gid %s\n", argv[2]);
 
32
                return 1;
 
33
        }
 
34
        
 
35
        fd = open(argv[1], O_RDONLY);
 
36
        if (fd == -1) {
 
37
                fprintf(stderr, "FAIL: open %s failed - %s\n",
 
38
                        argv[1], strerror(errno));
 
39
                perror("FAIL: open");
 
40
                return 1;
 
41
        }
 
42
 
 
43
        if (fchown(fd, -1, gid) == -1) {
 
44
                fprintf(stderr, "FAIL: fchgrp %s %d failed - %s\n",
 
45
                        argv[1], gid, strerror(errno));
 
46
                return 1;
 
47
        }
 
48
 
 
49
        printf("PASS\n");
 
50
 
 
51
        return 0;
 
52
}