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

« back to all changes in this revision

Viewing changes to tests/regression/subdomain/chown.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: chown.c 427 2007-03-08 00:09:47Z 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 <fcntl.h>
 
18
#include <string.h>
 
19
 
 
20
int main(int argc, char *argv[])
 
21
{
 
22
        uid_t uid;
 
23
 
 
24
        if (argc != 3) {
 
25
                fprintf(stderr, "usage: %s file username|uid\n",
 
26
                        argv[0]);
 
27
                return 1;
 
28
        }
 
29
 
 
30
        if (sscanf(argv[2], "%d", &uid) != 1) {
 
31
                fprintf(stderr, "FAIL: bad uid %s\n", argv[2]);
 
32
                return 1;
 
33
        }
 
34
        
 
35
        if (chown(argv[1], uid, -1) == -1) {
 
36
                fprintf(stderr, "FAIL: chown %s %d failed - %s\n",
 
37
                        argv[1], uid, strerror(errno));
 
38
                return 1;
 
39
        }
 
40
 
 
41
        printf("PASS\n");
 
42
 
 
43
        return 0;
 
44
}