public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Kohei KaiGai <kaigai@ak.jp.nec.com>
To: morgan@kernel.org
Cc: akpm@osdl.org, serue@us.ibm.com, jmorris@namei.org,
	linux-kernel@vger.kernel.org,
	linux-security-module@vger.kernel.org
Subject: [PATCH 3/3] exporting capability code/name pairs (try 2nd)
Date: Fri, 25 Jan 2008 14:18:40 +0900	[thread overview]
Message-ID: <47997130.6010202@ak.jp.nec.com> (raw)

We can apply this patch to libcap.

This patch enables setcap command to print the list
of capabilities running kernel supported, if the kernel
exports capability code/name pairs.
It is useful to confirm the name of capability when setting.

Thanks,
----
Signed-off-by: KaiGai Kohei <kaigai@ak.jp.nec.com>

diff --git a/progs/setcap.c b/progs/setcap.c
index dc13c06..1b9ed45 100644
--- a/progs/setcap.c
+++ b/progs/setcap.c
@@ -4,6 +4,7 @@
  * This sets the capabilities of a given file.
  */

+#include <dirent.h>
 #include <errno.h>
 #include <stdio.h>
 #include <string.h>
@@ -13,10 +14,34 @@

 static void usage(void)
 {
+    DIR *dirp;
+
     fprintf(stderr,
 	    "usage: setcap [-q] (-r|-|<caps>) <filename> "
 	    "[ ... (-r|-|<capsN>) <filenameN> ]\n"
 	);
+
+    dirp = opendir("/sys/kernel/capability");
+    if (dirp) {
+	struct dirent *dent;
+	int len, width = 99999;
+
+	fprintf(stderr,
+		"\nsupported capabilities:");
+	while ((dent = readdir(dirp)) != NULL) {
+	    if (!!strncmp("cap_", dent->d_name, 4))
+		continue;
+	    len = strlen(dent->d_name);
+	    if (width + len > 72) {
+		fprintf(stderr, "\n\t");
+		width = 8;
+	    }
+	    fprintf(stderr, "%s ", dent->d_name);
+	    width += len;
+	}
+	fputc('\n', stderr);
+	closedir(dirp);
+    }
     exit(1);
 }


-- 
OSS Platform Development Division, NEC
KaiGai Kohei <kaigai@ak.jp.nec.com>

                 reply	other threads:[~2008-01-25  5:19 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=47997130.6010202@ak.jp.nec.com \
    --to=kaigai@ak.jp.nec.com \
    --cc=akpm@osdl.org \
    --cc=jmorris@namei.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=morgan@kernel.org \
    --cc=serue@us.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox