Package: libcap2 / 1:2.24-8

0002-setcap-error-message.patch Patch series | 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
From: Zhi Li <lizhi1215@gmail.com>
Date: Wed, 20 Jul 2011 09:35:48 +0800
Subject: refine setcap output on errors (Closes: #633075)

The error message of setcap is a little confused. From the error message it is
hard to detect what is wrong. I removed the last 'usage' function call,
because at that code point the 'usage' can not provide any useful information.
Instead, I added a function 'mystrerror' which shall provide more information.

Last-Update: 2014-07-26

diff -Naurp libcap2.orig/progs/setcap.c libcap2/progs/setcap.c
--- libcap2.orig/progs/setcap.c
+++ libcap2/progs/setcap.c
@@ -22,6 +22,25 @@ static void usage(void)
     exit(1);
 }
 
+static const char * mystrerror(int n)
+{
+  struct my_error {
+    int num;
+    const char *desp;
+  }db[] = {
+    { EINVAL, "The value of the capability argument is not permitted for a file. Or the file is not a regular (non-symlink) file" },
+    { ENODATA, "Are you removing capabilities from a file? That file does not have any capability."},
+    {0, ""}
+  };
+
+  struct my_error *p = &db[0];
+  while (p->num) {
+    if ( n == p->num ) return p->desp;
+    p++;
+  }
+  return "";
+}
+
 #define MAXCAP  2048
 
 static int read_caps(int quiet, const char *filename, char *buffer)
@@ -195,7 +214,8 @@ int main(int argc, char **argv)
 			"Failed to set capabilities on file `%s' (%s)\n",
 			argv[0], strerror(errno));
 		if (!explained) {
-		    usage();
+			fprintf(stderr, "%s\n", mystrerror(errno));
+			exit(1);
 		}
 	    }
 	}