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: src/
Date: Sun, 27 Nov 2011 00:26:42
Message-Id: 43c2929f6a7e29a32cc812f3974857fc08544dd7.blueness@gentoo
1 commit: 43c2929f6a7e29a32cc812f3974857fc08544dd7
2 Author: Anthony G. Basile <blueness <AT> gentoo <DOT> org>
3 AuthorDate: Sun Nov 27 00:26:27 2011 +0000
4 Commit: Anthony G. Basile <blueness <AT> gentoo <DOT> org>
5 CommitDate: Sun Nov 27 00:26:27 2011 +0000
6 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=43c2929f
7
8 src/paxctl-ng.c: build with/without xattr support
9
10 ---
11 src/paxctl-ng.c | 28 +++++++++++++++++++++++++---
12 1 files changed, 25 insertions(+), 3 deletions(-)
13
14 diff --git a/src/paxctl-ng.c b/src/paxctl-ng.c
15 index 5527e40..427281b 100644
16 --- a/src/paxctl-ng.c
17 +++ b/src/paxctl-ng.c
18 @@ -24,7 +24,10 @@
19 #include <libgen.h>
20
21 #include <gelf.h>
22 +
23 +#ifdef XATTR
24 #include <attr/xattr.h>
25 +#endif
26
27 #include <sys/types.h>
28 #include <sys/stat.h>
29 @@ -33,15 +36,16 @@
30
31 #include <config.h>
32
33 -
34 +#ifdef XATTR
35 #define PAX_NAMESPACE "user.pax"
36 -#define BUF_SIZE 8
37 -#define FILE_NAME_SIZE 32768
38
39 #define CREATE_XT_FLAGS_SECURE 1
40 #define CREATE_XT_FLAGS_DEFAULT 2
41 #define COPY_PT_TO_XT_FLAGS 3
42 #define COPY_XT_TO_PT_FLAGS 4
43 +#endif
44 +
45 +#define BUF_SIZE 8
46
47 void
48 print_help_exit(char *v)
49 @@ -53,7 +57,9 @@ print_help_exit(char *v)
50 "Program Name : %s\n"
51 "Description : Get or set pax flags on an ELF object\n\n"
52 "Usage : %s -PpEeMmRrXxSsv ELF | -Zv ELF | -zv ELF\n"
53 +#ifdef XATTR
54 " : %s -Cv ELF | -cv ELF | Fv ELF | -fv ELF\n"
55 +#endif
56 " : %s -v ELF | -h\n\n"
57 "Options : -P enable PAGEEXEC\t-p disable PAGEEXEC\n"
58 " : -S enable SEGMEXEC\t-s disable SEGMEXEC\n"
59 @@ -62,10 +68,12 @@ print_help_exit(char *v)
60 " : -R enable RANDMMAP\t-r disable RANDMMAP\n"
61 " : -X enable RANDEXEC\t-x disable RANDEXEC\n"
62 " : -Z most secure settings\t-z all default settings\n"
63 +#ifdef XATTR
64 " : -C create XT_PAX with most secure setting\n"
65 " : -c create XT_PAX all default settings\n"
66 " : -F copy PT_PAX to XT_PAX\n"
67 " : -f copy XT_PAX to PT_PAX\n"
68 +#endif
69 " : -v view the flags, along with any accompanying operation\n"
70 " : -h print out this help\n\n"
71 "Note : If both enabling and disabling flags are set, the default - is used\n\n",
72 @@ -154,6 +162,7 @@ parse_cmd_args(int argc, char *argv[], uint16_t *pax_flags, int *view_flags, int
73 PF_RANDMMAP | PF_NORANDMMAP | PF_RANDEXEC | PF_NORANDEXEC;
74 solitaire += 1;
75 break;
76 +#ifdef XATTR
77 case 'C':
78 solitaire += 1;
79 *cp_flags = CREATE_XT_FLAGS_SECURE;
80 @@ -170,6 +179,7 @@ parse_cmd_args(int argc, char *argv[], uint16_t *pax_flags, int *view_flags, int
81 solitaire += 1;
82 *cp_flags = COPY_XT_TO_PT_FLAGS;
83 break;
84 +#endif
85 case 'v':
86 *view_flags = 1;
87 break;
88 @@ -243,6 +253,7 @@ get_pt_flags(int fd)
89 }
90
91
92 +#ifdef XATTR
93 uint16_t
94 get_xt_flags(int fd)
95 {
96 @@ -251,6 +262,7 @@ get_xt_flags(int fd)
97 fgetxattr(fd, PAX_NAMESPACE, &xt_flags, sizeof(uint16_t));
98 return xt_flags;
99 }
100 +#endif
101
102
103 void
104 @@ -292,6 +304,7 @@ print_flags(int fd)
105 printf("\tPT_PAX: %s\n", buf);
106 }
107
108 +#ifdef XATTR
109 flags = get_xt_flags(fd);
110 if( flags == UINT16_MAX )
111 printf("\tXT_PAX: not found\n");
112 @@ -301,6 +314,7 @@ print_flags(int fd)
113 bin2string(flags, buf);
114 printf("\tXT_PAX: %s\n", buf);
115 }
116 +#endif
117 }
118
119
120 @@ -467,11 +481,13 @@ set_pt_flags(int fd, uint16_t pt_flags)
121 }
122
123
124 +#ifdef XATTR
125 void
126 set_xt_flags(int fd, uint16_t xt_flags)
127 {
128 fsetxattr(fd, PAX_NAMESPACE, &xt_flags, sizeof(uint16_t), XATTR_REPLACE);
129 }
130 +#endif
131
132
133 void
134 @@ -488,14 +504,17 @@ set_flags(int fd, uint16_t *pax_flags, int rdwr_pt_pax)
135 set_pt_flags(fd, flags);
136 }
137
138 +#ifdef XATTR
139 flags = get_xt_flags(fd);
140 if( flags == UINT16_MAX )
141 flags = PF_NOEMUTRAMP | PF_NORANDEXEC;
142 flags = update_flags( flags, *pax_flags);
143 set_xt_flags(fd, flags);
144 +#endif
145 }
146
147
148 +#ifdef XATTR
149 void
150 create_xt_flags(fd, cp_flags)
151 {
152 @@ -526,6 +545,7 @@ copy_xt_flags(fd, cp_flags)
153 set_pt_flags(fd, flags);
154 }
155 }
156 +#endif
157
158
159 int
160 @@ -553,11 +573,13 @@ main( int argc, char *argv[])
161 }
162 }
163
164 +#ifdef XATTR
165 if(cp_flags == CREATE_XT_FLAGS_SECURE || cp_flags == CREATE_XT_FLAGS_DEFAULT)
166 create_xt_flags(fd, cp_flags);
167
168 if(cp_flags == COPY_PT_TO_XT_FLAGS || (cp_flags == COPY_XT_TO_PT_FLAGS && rdwr_pt_pax))
169 copy_xt_flags(fd, cp_flags);
170 +#endif
171
172 if(pax_flags != 1)
173 set_flags(fd, &pax_flags, rdwr_pt_pax);