Gentoo Archives: gentoo-commits

From: "Anthony G. Basile" <blueness@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/elfix:master commit in: poc/
Date: Tue, 27 Sep 2011 21:46:48
Message-Id: 7cbdcd63cf17ff66b72db3de744475869e8e6285.blueness@gentoo
1 commit: 7cbdcd63cf17ff66b72db3de744475869e8e6285
2 Author: Anthony G. Basile <blueness <AT> gentoo <DOT> org>
3 AuthorDate: Tue Sep 27 21:46:34 2011 +0000
4 Commit: Anthony G. Basile <blueness <AT> gentoo <DOT> org>
5 CommitDate: Tue Sep 27 21:46:34 2011 +0000
6 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=7cbdcd63
7
8 poc/paxctl-xattr.c: removed unnecesary listing of all xattrs
9
10 ---
11 poc/paxctl-xattr.c | 79 +++++++++++++++++++--------------------------------
12 1 files changed, 30 insertions(+), 49 deletions(-)
13
14 diff --git a/poc/paxctl-xattr.c b/poc/paxctl-xattr.c
15 index eb97166..5040f80 100644
16 --- a/poc/paxctl-xattr.c
17 +++ b/poc/paxctl-xattr.c
18 @@ -25,7 +25,7 @@
19 #include <libgen.h>
20
21 #include <gelf.h>
22 -#include <sys/xattr.h>
23 +#include <attr/xattr.h>
24
25 #include <sys/types.h>
26 #include <sys/stat.h>
27 @@ -160,84 +160,65 @@ void
28 print_flags(int fd)
29 {
30 char xt_buf[BUF_SIZE];
31 -
32 - static ssize_t xsize = 1024;
33 - static char *xattrs = NULL;
34 - ssize_t i, xret = -1;
35 + uint16_t xt_flags;
36
37 static ssize_t vsize = 1024;
38 static char *value = NULL;
39 - ssize_t vret = -1;
40 + ssize_t i, vret = -1;
41
42 memset(xt_buf, 0, BUF_SIZE);
43 - xattrs = malloc(xsize);
44 value = malloc(vsize);
45
46 //If at first we don't succeed, grow buffer size
47 - while(((xret = flistxattr(fd, xattrs, xsize)) == -1) && (errno == ERANGE))
48 + while(((vret = fgetxattr(fd, PAX_NAMESPACE, value, vsize)) == -1) && (errno == ERANGE))
49 {
50 - xsize <<= 1;
51 - xattrs = realloc(xattrs, xsize);
52 + vsize <<= 1;
53 + value = realloc(value, vsize);
54 }
55
56 - if(errno == ENOTSUP)
57 + if(errno == ENOATTR)
58 {
59 - printf("XT_PAX: not found without Extended Attribute Support\n");
60 + printf("XT_PAX: not found or permission denied\n");
61 return;
62 }
63
64 - for(i = 0; i < xret; i += strlen(&xattrs[i]) + 1)
65 + if(errno == ENOTSUP)
66 {
67 + printf("XT_PAX: extended attribute not supported\n");
68 + return;
69 + }
70
71 - if(strcmp(&xattrs[i], PAX_NAMESPACE) == 0)
72 - {
73 - printf("here\n");
74 -
75 - while(((vret = fgetxattr(fd, &xattrs[i], value, vsize)) == -1) && (errno == ERANGE))
76 - {
77 - xsize <<= 1;
78 - xattrs = realloc(xattrs, xsize);
79 - }
80 -
81 - /*
82 - valueLen = getxattr(argv[j], &xattrs[ns], value, XATTR_SIZE);
83 - if (valueLen == -1) {
84 - printf("couldn't get value");
85 - } else {
86 - for (k = 0; k < valueLen; k++)
87 - printf("%02x ", (unsigned int) value[k]);
88 - }
89 + xt_flags = (uint16_t)value[0];
90 + xt_flags = xt_flags << 8 + value[1];
91
92 - xt_buf[0] = xt_flags & PF_PAGEEXEC ? 'P' :
93 - xt_flags & PF_NOPAGEEXEC ? 'p' : '-' ;
94 + xt_buf[0] = xt_flags & PF_PAGEEXEC ? 'P' :
95 + xt_flags & PF_NOPAGEEXEC ? 'p' : '-' ;
96
97 - xt_buf[1] = xt_flags & PF_SEGMEXEC ? 'S' :
98 - xt_flags & PF_NOSEGMEXEC ? 's' : '-';
99 + xt_buf[1] = xt_flags & PF_SEGMEXEC ? 'S' :
100 + xt_flags & PF_NOSEGMEXEC ? 's' : '-';
101
102 - xt_buf[2] = xt_flags & PF_MPROTECT ? 'M' :
103 - xt_flags & PF_NOMPROTECT ? 'm' : '-';
104 + xt_buf[2] = xt_flags & PF_MPROTECT ? 'M' :
105 + xt_flags & PF_NOMPROTECT ? 'm' : '-';
106
107 - xt_buf[3] = xt_flags & PF_EMUTRAMP ? 'E' :
108 - xt_flags & PF_NOEMUTRAMP ? 'e' : '-';
109 + xt_buf[3] = xt_flags & PF_EMUTRAMP ? 'E' :
110 + xt_flags & PF_NOEMUTRAMP ? 'e' : '-';
111
112 - xt_buf[4] = xt_flags & PF_RANDMMAP ? 'R' :
113 - xt_flags & PF_NORANDMMAP ? 'r' : '-';
114 + xt_buf[4] = xt_flags & PF_RANDMMAP ? 'R' :
115 + xt_flags & PF_NORANDMMAP ? 'r' : '-';
116
117 - xt_buf[5] = xt_flags & PF_RANDEXEC ? 'X' :
118 - xt_flags & PF_NORANDEXEC ? 'x' : '-';
119 + xt_buf[5] = xt_flags & PF_RANDEXEC ? 'X' :
120 + xt_flags & PF_NORANDEXEC ? 'x' : '-';
121
122 - printf("XT_PAX: %s\n", xt_buf);
123 - */
124 - }
125 - }
126 + printf("XT_PAX: %s\n", xt_buf);
127 }
128
129
130 void
131 set_flags(int fd, int *pax_flags)
132 {
133 - char xt_buf[BUF_SIZE];
134 - memset(xt_buf, 0, BUF_SIZE);
135 + uint16_t xt_flags;
136 +
137 + //int fsetxattr(int fd, const char *name, const void *value, size_t size, int flags);
138
139 /*
140 if( / DOME xattrs is supported / )