Gentoo Archives: gentoo-commits

From: "Chris PeBenito (pebenito)" <pebenito@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] gentoo-x86 commit in sys-libs/libsemanage/files: libsemanage-2.0.33-bzip.diff
Date: Mon, 24 Aug 2009 18:36:18
Message-Id: E1MfeOu-00056h-OO@stork.gentoo.org
1 pebenito 09/08/24 18:36:16
2
3 Added: libsemanage-2.0.33-bzip.diff
4 Log:
5 sys-libs/libsemanage: Add patch to make bzip2 compression configurable.
6 (Portage version: 2.2_rc38/cvs/Linux x86_64)
7
8 Revision Changes Path
9 1.1 sys-libs/libsemanage/files/libsemanage-2.0.33-bzip.diff
10
11 file : http://sources.gentoo.org/viewcvs.py/gentoo-x86/sys-libs/libsemanage/files/libsemanage-2.0.33-bzip.diff?rev=1.1&view=markup
12 plain: http://sources.gentoo.org/viewcvs.py/gentoo-x86/sys-libs/libsemanage/files/libsemanage-2.0.33-bzip.diff?rev=1.1&content-type=text/plain
13
14 Index: libsemanage-2.0.33-bzip.diff
15 ===================================================================
16 diff -purN libsemanage-2.0.33.orig/src/conf-parse.y libsemanage-2.0.33/src/conf-parse.y
17 --- libsemanage-2.0.33.orig/src/conf-parse.y 2009-07-30 22:14:16.000000000 -0400
18 +++ libsemanage-2.0.33/src/conf-parse.y 2009-08-24 14:17:59.255304232 -0400
19 @@ -58,6 +58,7 @@ static int parse_errors;
20
21 %token MODULE_STORE VERSION EXPAND_CHECK FILE_MODE SAVE_PREVIOUS SAVE_LINKED
22 %token LOAD_POLICY_START SETFILES_START DISABLE_GENHOMEDIRCON HANDLE_UNKNOWN
23 +%token BZIP_BLOCKSIZE BZIP_SMALL
24 %token VERIFY_MOD_START VERIFY_LINKED_START VERIFY_KERNEL_START BLOCK_END
25 %token PROG_PATH PROG_ARGS
26 %token <s> ARG
27 @@ -82,6 +83,8 @@ single_opt: module_store
28 | save_linked
29 | disable_genhomedircon
30 | handle_unknown
31 + | bzip_blocksize
32 + | bzip_small
33 ;
34
35 module_store: MODULE_STORE '=' ARG {
36 @@ -163,6 +166,26 @@ handle_unknown: HANDLE_UNKNOWN '=' ARG {
37 free($3);
38 }
39
40 +bzip_blocksize: BZIP_BLOCKSIZE '=' ARG {
41 + int blocksize = atoi($3);
42 + free($3);
43 + if (blocksize > 9)
44 + yyerror("bzip-blocksize can only be in the range 0-9");
45 + else
46 + current_conf->bzip_blocksize = blocksize;
47 +}
48 +
49 +bzip_small: BZIP_SMALL '=' ARG {
50 + if (strcasecmp($3, "false") == 0) {
51 + current_conf->bzip_small = 0;
52 + } else if (strcasecmp($3, "true") == 0) {
53 + current_conf->bzip_small = 1;
54 + } else {
55 + yyerror("bzip-small can only be 'true' or 'false'");
56 + }
57 + free($3);
58 +}
59 +
60 command_block:
61 command_start external_opts BLOCK_END {
62 if (new_external->path == NULL) {
63 @@ -230,6 +253,8 @@ static int semanage_conf_init(semanage_c
64 conf->expand_check = 1;
65 conf->handle_unknown = -1;
66 conf->file_mode = 0644;
67 + conf->bzip_blocksize = 9;
68 + conf->bzip_small = 0;
69
70 conf->save_previous = 0;
71 conf->save_linked = 0;
72 diff -purN libsemanage-2.0.33.orig/src/conf-scan.l libsemanage-2.0.33/src/conf-scan.l
73 --- libsemanage-2.0.33.orig/src/conf-scan.l 2009-07-30 22:14:16.000000000 -0400
74 +++ libsemanage-2.0.33/src/conf-scan.l 2009-08-24 14:17:59.255304232 -0400
75 @@ -47,6 +47,8 @@ save-previous return SAVE_PREVIOUS;
76 save-linked return SAVE_LINKED;
77 disable-genhomedircon return DISABLE_GENHOMEDIRCON;
78 handle-unknown return HANDLE_UNKNOWN;
79 +bzip-blocksize return BZIP_BLOCKSIZE;
80 +bzip-small return BZIP_SMALL;
81 "[load_policy]" return LOAD_POLICY_START;
82 "[setfiles]" return SETFILES_START;
83 "[verify module]" return VERIFY_MOD_START;
84 diff -purN libsemanage-2.0.33.orig/src/direct_api.c libsemanage-2.0.33/src/direct_api.c
85 --- libsemanage-2.0.33.orig/src/direct_api.c 2009-07-30 22:14:16.000000000 -0400
86 +++ libsemanage-2.0.33/src/direct_api.c 2009-08-24 14:18:16.895213296 -0400
87 @@ -401,7 +401,9 @@ static int parse_base_headers(semanage_h
88
89 /* bzip() a data to a file, returning the total number of compressed bytes
90 * in the file. Returns -1 if file could not be compressed. */
91 -static ssize_t bzip(const char *filename, char *data, size_t num_bytes) {
92 +static ssize_t bzip(semanage_handle_t *sh, const char *filename, char *data,
93 + size_t num_bytes)
94 +{
95 BZFILE* b;
96 size_t size = 1<<16;
97 int bzerror;
98 @@ -413,7 +415,16 @@ static ssize_t bzip(const char *filename
99 return -1;
100 }
101
102 - b = BZ2_bzWriteOpen( &bzerror, f, 9, 0, 0);
103 + if (!sh->conf->bzip_blocksize) {
104 + if (fwrite(data, 1, num_bytes, f) < num_bytes) {
105 + fclose(f);
106 + return -1;
107 + }
108 + fclose(f);
109 + return num_bytes;
110 + }
111 +
112 + b = BZ2_bzWriteOpen( &bzerror, f, sh->conf->bzip_blocksize, 0, 0);
113 if (bzerror != BZ_OK) {
114 BZ2_bzWriteClose ( &bzerror, b, 1, 0, 0 );
115 return -1;
116 @@ -441,17 +452,29 @@ static ssize_t bzip(const char *filename
117 return total;
118 }
119
120 +#define BZ2_MAGICSTR "BZh"
121 +#define BZ2_MAGICLEN (sizeof(BZ2_MAGICSTR)-1)
122 +
123 /* bunzip() a file to '*data', returning the total number of uncompressed bytes
124 * in the file. Returns -1 if file could not be decompressed. */
125 -ssize_t bunzip(FILE *f, char **data) {
126 +ssize_t bunzip(semanage_handle_t *sh, FILE *f, char **data)
127 +{
128 BZFILE* b;
129 size_t nBuf;
130 char buf[1<<18];
131 size_t size = sizeof(buf);
132 int bzerror;
133 size_t total=0;
134 +
135 + if (!sh->conf->bzip_blocksize) {
136 + bzerror = fread(buf, 1, BZ2_MAGICLEN, f);
137 + rewind(f);
138 + if ((bzerror != BZ2_MAGICLEN) || memcmp(buf, BZ2_MAGICSTR, BZ2_MAGICLEN))
139 + return -1;
140 + /* fall through */
141 + }
142
143 - b = BZ2_bzReadOpen ( &bzerror, f, 0, 0, NULL, 0 );
144 + b = BZ2_bzReadOpen ( &bzerror, f, 0, sh->conf->bzip_small, NULL, 0 );
145 if ( bzerror != BZ_OK ) {
146 BZ2_bzReadClose ( &bzerror, b );
147 return -1;
148 @@ -486,11 +509,12 @@ ssize_t bunzip(FILE *f, char **data) {
149 * the file into '*data'.
150 * Returns the total number of bytes in memory .
151 * Returns -1 if file could not be opened or mapped. */
152 -static ssize_t map_file(int fd, char **data, int *compressed)
153 +static ssize_t map_file(semanage_handle_t *sh, int fd, char **data,
154 + int *compressed)
155 {
156 ssize_t size = -1;
157 char *uncompress;
158 - if ((size = bunzip(fdopen(fd, "r"), &uncompress)) > 0) {
159 + if ((size = bunzip(sh, fdopen(fd, "r"), &uncompress)) > 0) {
160 *data = mmap(0, size, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, 0, 0);
161 if (*data == MAP_FAILED) {
162 free(uncompress);
163 @@ -997,7 +1021,7 @@ static int semanage_direct_install(seman
164 &filename)) != 0) {
165 goto cleanup;
166 }
167 - if (bzip(filename, data, data_len) <= 0) {
168 + if (bzip(sh, filename, data, data_len) <= 0) {
169 ERR(sh, "Error while writing to %s.", filename);
170 retval = -3;
171 goto cleanup;
172 @@ -1029,7 +1053,7 @@ static int semanage_direct_install_file(
173 return -1;
174 }
175
176 - if ((data_len = map_file(in_fd, &data, &compressed)) <= 0) {
177 + if ((data_len = map_file(sh, in_fd, &data, &compressed)) <= 0) {
178 goto cleanup;
179 }
180
181 @@ -1127,7 +1151,7 @@ static int semanage_direct_upgrade(seman
182 data, data_len,
183 &filename);
184 if (retval == 0) {
185 - if (bzip(filename, data, data_len) <= 0) {
186 + if (bzip(sh, filename, data, data_len) <= 0) {
187 ERR(sh, "Error while writing to %s.", filename);
188 retval = -3;
189 }
190 @@ -1155,7 +1179,7 @@ static int semanage_direct_upgrade_file(
191 return -1;
192 }
193
194 - if ((data_len = map_file(in_fd, &data, &compressed)) <= 0) {
195 + if ((data_len = map_file(sh, in_fd, &data, &compressed)) <= 0) {
196 goto cleanup;
197 }
198
199 @@ -1197,7 +1221,7 @@ static int semanage_direct_install_base(
200 if ((filename = semanage_path(SEMANAGE_TMP, SEMANAGE_BASE)) == NULL) {
201 goto cleanup;
202 }
203 - if (bzip(filename, base_data, data_len) <= 0) {
204 + if (bzip(sh, filename, base_data, data_len) <= 0) {
205 ERR(sh, "Error while writing to %s.", filename);
206 retval = -3;
207 goto cleanup;
208 @@ -1225,7 +1249,7 @@ static int semanage_direct_install_base_
209 return -1;
210 }
211
212 - if ((data_len = map_file(in_fd, &data, &compressed)) <= 0) {
213 + if ((data_len = map_file(sh, in_fd, &data, &compressed)) <= 0) {
214 goto cleanup;
215 }
216
217 @@ -1347,7 +1371,7 @@ static int semanage_direct_list(semanage
218 ssize_t size;
219 char *data = NULL;
220
221 - if ((size = bunzip(fp, &data)) > 0) {
222 + if ((size = bunzip(sh, fp, &data)) > 0) {
223 fclose(fp);
224 fp = fmemopen(data, size, "rb");
225 if (!fp) {
226 diff -purN libsemanage-2.0.33.orig/src/direct_api.h libsemanage-2.0.33/src/direct_api.h
227 --- libsemanage-2.0.33.orig/src/direct_api.h 2009-07-30 22:14:16.000000000 -0400
228 +++ libsemanage-2.0.33/src/direct_api.h 2009-08-24 14:17:59.271293736 -0400
229 @@ -41,6 +41,6 @@ int semanage_direct_mls_enabled(struct s
230
231 #include <stdio.h>
232 #include <unistd.h>
233 -ssize_t bunzip(FILE *f, char **data);
234 +ssize_t bunzip(struct semanage_handle *sh, FILE *f, char **data);
235
236 #endif
237 diff -purN libsemanage-2.0.33.orig/src/semanage_conf.h libsemanage-2.0.33/src/semanage_conf.h
238 --- libsemanage-2.0.33.orig/src/semanage_conf.h 2009-07-30 22:14:16.000000000 -0400
239 +++ libsemanage-2.0.33/src/semanage_conf.h 2009-08-24 14:17:59.279293237 -0400
240 @@ -40,6 +40,8 @@ typedef struct semanage_conf {
241 int disable_genhomedircon;
242 int handle_unknown;
243 mode_t file_mode;
244 + int bzip_blocksize;
245 + int bzip_small;
246 struct external_prog *load_policy;
247 struct external_prog *setfiles;
248 struct external_prog *mod_prog, *linked_prog, *kernel_prog;
249 diff -purN libsemanage-2.0.33.orig/src/semanage_store.c libsemanage-2.0.33/src/semanage_store.c
250 --- libsemanage-2.0.33.orig/src/semanage_store.c 2009-07-30 22:14:16.000000000 -0400
251 +++ libsemanage-2.0.33/src/semanage_store.c 2009-08-24 14:17:59.283234006 -0400
252 @@ -1529,7 +1529,7 @@ static int semanage_load_module(semanage
253 ssize_t size;
254 char *data = NULL;
255
256 - if ((size = bunzip(fp, &data)) > 0) {
257 + if ((size = bunzip(sh, fp, &data)) > 0) {
258 fclose(fp);
259 fp = fmemopen(data, size, "rb");
260 if (!fp) {