summaryrefslogtreecommitdiff
path: root/progs/old/getcap.c
blob: 8a7102dbf8b35dcaa3f71ee393fb1385f2e1af2d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
 * $Id: getcap.c,v 1.1.1.1 1999/04/17 22:16:31 morgan Exp $
 *
 * Copyright (c) 1997 Andrew G. Morgan  <morgan@parc.power.net>
 *
 * This displays the capabilities of a given file.
 */

#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <sys/capability.h>

static void usage(void)
{
    fprintf(stderr,
	    "usage: getcap <filename> [<filename> ...]\n"
	    "\n"
	    "\tdisplays the capabilities on the queried file(s).\n"
	);
    exit(1);
}

int main(int argc, char **argv)
{
    char *result=NULL;

    if (argc < 2) {
	usage();
    }

    for ( ++argv; --argc > 0; ++argv ) {
	ssize_t length;
	cap_t cap_d;

	cap_d = cap_get_file(argv[0]);

	if (cap_d == NULL) {
	    fprintf(stderr,
		    "Failed to get capabilities for file `%s'\n"
		    " (%s)\n", argv[0], strerror(errno));
	    continue;
	}

	result = cap_to_text(cap_d, &length);

	fprintf(stderr, "Capabilities for `%s':\n%s\n", *argv, result);
    }

    return 0;
}

/*
 * $Log: getcap.c,v $
 * Revision 1.1.1.1  1999/04/17 22:16:31  morgan
 * release 1.0 of libcap
 *
 * Revision 1.3  1997/05/04 05:34:32  morgan
 * non void main
 *
 * Revision 1.2  1997/04/28 01:01:20  morgan
 * update to allow more than one argument file
 *
 * Revision 1.1  1997/04/21 04:34:04  morgan
 * Initial revision
 *
 */