File: getcap.c

package info (click to toggle)
libcap 1.92-1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 312 kB
  • ctags: 172
  • sloc: ansic: 1,294; makefile: 152; sh: 5
file content (63 lines) | stat: -rw-r--r-- 1,310 bytes parent folder | download
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
/*
 * $Id: getcap.c,v 1.1.2.2 1999/05/01 23:26:31 morgan Exp $
 *
 * Copyright (c) 1997 Andrew G. Morgan  <morgan@ftp.kernel.org>
 *
 * 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': %s\n", *argv, result);
    }

    return 0;
}

/*
 * $Log: getcap.c,v $
 * Revision 1.1.2.2  1999/05/01 23:26:31  morgan
 * added list of things to ignore in this directory
 * altered command line syntax of sucap and also made it work (sometimes)
 * getcap output is now one line per file
 *
 * Revision 1.1.2.1  1999/04/23 05:00:31  morgan
 * resurecting from the dead for kernels with fcap support
 *
 */