Gentoo Archives: gentoo-commits

From: Aric Belsito <lluixhi@×××××.com>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/musl:master commit in: app-arch/p7zip/, app-arch/p7zip/files/
Date: Fri, 28 Oct 2016 18:59:05
Message-Id: 1477681012.64f767341486d1c86c0ed4f2a55ed35e16f421de.lluixhi@gentoo
1 commit: 64f767341486d1c86c0ed4f2a55ed35e16f421de
2 Author: Aric Belsito <lluixhi <AT> gmail <DOT> com>
3 AuthorDate: Fri Oct 28 18:56:52 2016 +0000
4 Commit: Aric Belsito <lluixhi <AT> gmail <DOT> com>
5 CommitDate: Fri Oct 28 18:56:52 2016 +0000
6 URL: https://gitweb.gentoo.org/proj/musl.git/commit/?id=64f76734
7
8 app-arch/p7zip: Add stable version.
9
10 Gentoo-Bug: 581010
11
12 app-arch/p7zip/Manifest | 1 +
13 app-arch/p7zip/files/9.04-makefile.patch | 19 ++
14 .../p7zip/files/p7zip-9.20.1-CVE-2015-1038.patch | 315 +++++++++++++++++++++
15 app-arch/p7zip/files/p7zip-9.20.1-QA.patch | 17 ++
16 app-arch/p7zip/files/p7zip-9.20.1-execstack.patch | 24 ++
17 .../p7zip/files/p7zip-CVE-2015-1038-musl.patch | 14 +
18 app-arch/p7zip/metadata.xml | 14 +
19 app-arch/p7zip/p7zip-9.20.1-r5.ebuild | 156 ++++++++++
20 8 files changed, 560 insertions(+)
21
22 diff --git a/app-arch/p7zip/Manifest b/app-arch/p7zip/Manifest
23 new file mode 100644
24 index 0000000..f34836c
25 --- /dev/null
26 +++ b/app-arch/p7zip/Manifest
27 @@ -0,0 +1 @@
28 +DIST p7zip_9.20.1_src_all.tar.bz2 3835235 SHA256 49557e7ffca08100f9fc687f4dfc5aea703ca207640c76d9dee7b66f03cb4782 SHA512 7bb8a276aaefc4a83364e45633c48527de44c6b1205344f3356db570582f30f81d82a94938c99a7ad193587b584cc1c03219c28249de40018bdaee6c3b2a022a WHIRLPOOL cb20f37d3f796931a9b330728aa7148afe98bbf8a49bb91bfd80e4667c16416206b23bf34298e9ec37825e8b43f92a5710f0cea1f974296d5c17aa2c7b0931f3
29
30 diff --git a/app-arch/p7zip/files/9.04-makefile.patch b/app-arch/p7zip/files/9.04-makefile.patch
31 new file mode 100644
32 index 0000000..93a99cc
33 --- /dev/null
34 +++ b/app-arch/p7zip/files/9.04-makefile.patch
35 @@ -0,0 +1,19 @@
36 +--- p7zip_9.04/CPP/7zip/Bundles/Format7zFree/makefile.orig 2010-01-04 13:58:54.527887746 +0100
37 ++++ p7zip_9.04/CPP/7zip/Bundles/Format7zFree/makefile 2010-01-04 13:59:10.290868343 +0100
38 +@@ -247,8 +247,6 @@
39 + MyAes.o \
40 + Pbkdf2HmacSha1.o \
41 + RandGen.o \
42 +- Rar20Crypto.o \
43 +- RarAes.o \
44 + Sha1.o \
45 + WzAes.o \
46 + ZipCrypto.o \
47 +@@ -298,7 +296,6 @@
48 + $(HFS_OBJS) \
49 + $(ISO_OBJS) \
50 + $(NSIS_OBJS) \
51 +- $(RAR_OBJS) \
52 + $(TAR_OBJS) \
53 + $(UDF_OBJS) \
54 + $(WIM_OBJS) \
55
56 diff --git a/app-arch/p7zip/files/p7zip-9.20.1-CVE-2015-1038.patch b/app-arch/p7zip/files/p7zip-9.20.1-CVE-2015-1038.patch
57 new file mode 100644
58 index 0000000..09dd0f2
59 --- /dev/null
60 +++ b/app-arch/p7zip/files/p7zip-9.20.1-CVE-2015-1038.patch
61 @@ -0,0 +1,315 @@
62 +Author: Ben Hutchings <ben@××××××××××××.uk>
63 +Date: Tue, 19 May 2015 02:38:40 +0100
64 +Description: Delay creation of symlinks to prevent arbitrary file writes (CVE-2015-1038)
65 +Bug: http://sourceforge.net/p/p7zip/bugs/147/
66 +Bug-Debian: https://bugs.debian.org/774660
67 +
68 +Alexander Cherepanov discovered that 7zip is susceptible to a
69 +directory traversal vulnerability. While extracting an archive, it
70 +will extract symlinks and then follow them if they are referenced in
71 +further entries. This can be exploited by a rogue archive to write
72 +files outside the current directory.
73 +
74 +We have to create placeholder files (which we already do) and delay
75 +creating symlinks until the end of extraction.
76 +
77 +Due to the possibility of anti-items (deletions) in the archive, it is
78 +possible for placeholders to be deleted and replaced before we create
79 +the symlinks. It's not clear that this can be used for mischief, but
80 +GNU tar guards against similar problems by checking that the placeholder
81 +still exists and is the same inode. XXX It also checks 'birth time' but
82 +this isn't portable. We can probably get away with comparing ctime
83 +since we don't support hard links.
84 +
85 +--- a/CPP/7zip/UI/Agent/Agent.cpp
86 ++++ b/CPP/7zip/UI/Agent/Agent.cpp
87 +@@ -424,6 +424,8 @@ STDMETHODIMP CAgentFolder::Extract(const
88 + CMyComPtr<IArchiveExtractCallback> extractCallback = extractCallbackSpec;
89 + UStringVector pathParts;
90 + CProxyFolder *currentProxyFolder = _proxyFolderItem;
91 ++ HRESULT res;
92 ++
93 + while (currentProxyFolder->Parent)
94 + {
95 + pathParts.Insert(0, currentProxyFolder->Name);
96 +@@ -445,8 +447,11 @@ STDMETHODIMP CAgentFolder::Extract(const
97 + (UInt64)(Int64)-1);
98 + CUIntVector realIndices;
99 + GetRealIndices(indices, numItems, realIndices);
100 +- return _agentSpec->GetArchive()->Extract(&realIndices.Front(),
101 ++ res = _agentSpec->GetArchive()->Extract(&realIndices.Front(),
102 + realIndices.Size(), testMode, extractCallback);
103 ++ if (res == S_OK && !extractCallbackSpec->CreateSymLinks())
104 ++ res = E_FAIL;
105 ++ return res;
106 + COM_TRY_END
107 + }
108 +
109 +--- a/CPP/7zip/UI/Agent/ArchiveFolder.cpp
110 ++++ b/CPP/7zip/UI/Agent/ArchiveFolder.cpp
111 +@@ -20,6 +20,8 @@ STDMETHODIMP CAgentFolder::CopyTo(const
112 + CMyComPtr<IArchiveExtractCallback> extractCallback = extractCallbackSpec;
113 + UStringVector pathParts;
114 + CProxyFolder *currentProxyFolder = _proxyFolderItem;
115 ++ HRESULT res;
116 ++
117 + while (currentProxyFolder->Parent)
118 + {
119 + pathParts.Insert(0, currentProxyFolder->Name);
120 +@@ -46,8 +48,11 @@ STDMETHODIMP CAgentFolder::CopyTo(const
121 + (UInt64)(Int64)-1);
122 + CUIntVector realIndices;
123 + GetRealIndices(indices, numItems, realIndices);
124 +- return _agentSpec->GetArchive()->Extract(&realIndices.Front(),
125 ++ res = _agentSpec->GetArchive()->Extract(&realIndices.Front(),
126 + realIndices.Size(), BoolToInt(false), extractCallback);
127 ++ if (res == S_OK && !extractCallbackSpec->CreateSymLinks())
128 ++ res = E_FAIL;
129 ++ return res;
130 + COM_TRY_END
131 + }
132 +
133 +--- a/CPP/7zip/UI/Client7z/Client7z.cpp
134 ++++ b/CPP/7zip/UI/Client7z/Client7z.cpp
135 +@@ -197,8 +197,11 @@ private:
136 + COutFileStream *_outFileStreamSpec;
137 + CMyComPtr<ISequentialOutStream> _outFileStream;
138 +
139 ++ CObjectVector<NWindows::NFile::NDirectory::CDelayedSymLink> _delayedSymLinks;
140 ++
141 + public:
142 + void Init(IInArchive *archiveHandler, const UString &directoryPath);
143 ++ bool CreateSymLinks();
144 +
145 + UInt64 NumErrors;
146 + bool PasswordIsDefined;
147 +@@ -392,11 +395,22 @@ STDMETHODIMP CArchiveExtractCallback::Se
148 + }
149 + _outFileStream.Release();
150 + if (_extractMode && _processedFileInfo.AttribDefined)
151 +- NFile::NDirectory::MySetFileAttributes(_diskFilePath, _processedFileInfo.Attrib);
152 ++ NFile::NDirectory::MySetFileAttributes(_diskFilePath, _processedFileInfo.Attrib, &_delayedSymLinks);
153 + PrintNewLine();
154 + return S_OK;
155 + }
156 +
157 ++bool CArchiveExtractCallback::CreateSymLinks()
158 ++{
159 ++ bool success = true;
160 ++
161 ++ for (int i = 0; i != _delayedSymLinks.Size(); ++i)
162 ++ success &= _delayedSymLinks[i].Create();
163 ++
164 ++ _delayedSymLinks.Clear();
165 ++
166 ++ return success;
167 ++}
168 +
169 + STDMETHODIMP CArchiveExtractCallback::CryptoGetTextPassword(BSTR *password)
170 + {
171 +--- a/CPP/7zip/UI/Common/ArchiveExtractCallback.cpp
172 ++++ b/CPP/7zip/UI/Common/ArchiveExtractCallback.cpp
173 +@@ -453,12 +453,24 @@ STDMETHODIMP CArchiveExtractCallback::Se
174 + NumFiles++;
175 +
176 + if (_extractMode && _fi.AttribDefined)
177 +- NFile::NDirectory::MySetFileAttributes(_diskFilePath, _fi.Attrib);
178 ++ NFile::NDirectory::MySetFileAttributes(_diskFilePath, _fi.Attrib, &_delayedSymLinks);
179 + RINOK(_extractCallback2->SetOperationResult(operationResult, _encrypted));
180 + return S_OK;
181 + COM_TRY_END
182 + }
183 +
184 ++bool CArchiveExtractCallback::CreateSymLinks()
185 ++{
186 ++ bool success = true;
187 ++
188 ++ for (int i = 0; i != _delayedSymLinks.Size(); ++i)
189 ++ success &= _delayedSymLinks[i].Create();
190 ++
191 ++ _delayedSymLinks.Clear();
192 ++
193 ++ return success;
194 ++}
195 ++
196 + /*
197 + STDMETHODIMP CArchiveExtractCallback::GetInStream(
198 + const wchar_t *name, ISequentialInStream **inStream)
199 +--- a/CPP/7zip/UI/Common/ArchiveExtractCallback.h
200 ++++ b/CPP/7zip/UI/Common/ArchiveExtractCallback.h
201 +@@ -6,6 +6,8 @@
202 + #include "Common/MyCom.h"
203 + #include "Common/Wildcard.h"
204 +
205 ++#include "Windows/FileDir.h"
206 ++
207 + #include "../../IPassword.h"
208 +
209 + #include "../../Common/FileStreams.h"
210 +@@ -83,6 +85,8 @@ class CArchiveExtractCallback:
211 + UInt64 _packTotal;
212 + UInt64 _unpTotal;
213 +
214 ++ CObjectVector<NWindows::NFile::NDirectory::CDelayedSymLink> _delayedSymLinks;
215 ++
216 + void CreateComplexDirectory(const UStringVector &dirPathParts, UString &fullPath);
217 + HRESULT GetTime(int index, PROPID propID, FILETIME &filetime, bool &filetimeIsDefined);
218 + HRESULT GetUnpackSize();
219 +@@ -138,6 +142,7 @@ public:
220 + const UStringVector &removePathParts,
221 + UInt64 packSize);
222 +
223 ++ bool CreateSymLinks();
224 + };
225 +
226 + #endif
227 +--- a/CPP/7zip/UI/Common/Extract.cpp
228 ++++ b/CPP/7zip/UI/Common/Extract.cpp
229 +@@ -96,6 +96,9 @@ static HRESULT DecompressArchive(
230 + else
231 + result = archive->Extract(&realIndices.Front(), realIndices.Size(), testMode, extractCallbackSpec);
232 +
233 ++ if (result == S_OK && !extractCallbackSpec->CreateSymLinks())
234 ++ result = E_FAIL;
235 ++
236 + return callback->ExtractResult(result);
237 + }
238 +
239 +--- a/CPP/Windows/FileDir.cpp
240 ++++ b/CPP/Windows/FileDir.cpp
241 +@@ -453,9 +453,10 @@ bool SetDirTime(LPCWSTR fileName, const
242 + }
243 +
244 + #ifndef _UNICODE
245 +-bool MySetFileAttributes(LPCWSTR fileName, DWORD fileAttributes)
246 ++bool MySetFileAttributes(LPCWSTR fileName, DWORD fileAttributes,
247 ++ CObjectVector<CDelayedSymLink> *delayedSymLinks)
248 + {
249 +- return MySetFileAttributes(UnicodeStringToMultiByte(fileName, CP_ACP), fileAttributes);
250 ++ return MySetFileAttributes(UnicodeStringToMultiByte(fileName, CP_ACP), fileAttributes, delayedSymLinks);
251 + }
252 +
253 + bool MyRemoveDirectory(LPCWSTR pathName)
254 +@@ -488,7 +489,8 @@ static int convert_to_symlink(const char
255 + return -1;
256 + }
257 +
258 +-bool MySetFileAttributes(LPCTSTR fileName, DWORD fileAttributes)
259 ++bool MySetFileAttributes(LPCTSTR fileName, DWORD fileAttributes,
260 ++ CObjectVector<CDelayedSymLink> *delayedSymLinks)
261 + {
262 + if (!fileName) {
263 + SetLastError(ERROR_PATH_NOT_FOUND);
264 +@@ -520,7 +522,9 @@ bool MySetFileAttributes(LPCTSTR fileNam
265 + stat_info.st_mode = fileAttributes >> 16;
266 + #ifdef ENV_HAVE_LSTAT
267 + if (S_ISLNK(stat_info.st_mode)) {
268 +- if ( convert_to_symlink(name) != 0) {
269 ++ if (delayedSymLinks)
270 ++ delayedSymLinks->Add(CDelayedSymLink(name));
271 ++ else if ( convert_to_symlink(name) != 0) {
272 + TRACEN((printf("MySetFileAttributes(%s,%d) : false-3\n",name,fileAttributes)))
273 + return false;
274 + }
275 +@@ -924,4 +928,41 @@ bool CTempDirectory::Create(LPCTSTR pref
276 + }
277 +
278 +
279 ++#ifdef ENV_UNIX
280 ++
281 ++CDelayedSymLink::CDelayedSymLink(LPCSTR source)
282 ++ : _source(source)
283 ++{
284 ++ struct stat st;
285 ++
286 ++ if (lstat(_source, &st) == 0) {
287 ++ _dev = st.st_dev;
288 ++ _ino = st.st_ino;
289 ++ } else {
290 ++ _dev = 0;
291 ++ }
292 ++}
293 ++
294 ++bool CDelayedSymLink::Create()
295 ++{
296 ++ struct stat st;
297 ++
298 ++ if (_dev == 0) {
299 ++ errno = EPERM;
300 ++ return false;
301 ++ }
302 ++ if (lstat(_source, &st) != 0)
303 ++ return false;
304 ++ if (_dev != st.st_dev || _ino != st.st_ino) {
305 ++ // Placeholder file has been overwritten or moved by another
306 ++ // symbolic link creation
307 ++ errno = EPERM;
308 ++ return false;
309 ++ }
310 ++
311 ++ return convert_to_symlink(_source) == 0;
312 ++}
313 ++
314 ++#endif // ENV_UNIX
315 ++
316 + }}}
317 +--- a/CPP/Windows/FileDir.h
318 ++++ b/CPP/Windows/FileDir.h
319 +@@ -4,6 +4,7 @@
320 + #define __WINDOWS_FILEDIR_H
321 +
322 + #include "../Common/MyString.h"
323 ++#include "../Common/MyVector.h"
324 + #include "Defs.h"
325 +
326 + /* GetFullPathName for 7zAES.cpp */
327 +@@ -13,11 +14,15 @@ namespace NWindows {
328 + namespace NFile {
329 + namespace NDirectory {
330 +
331 ++class CDelayedSymLink;
332 ++
333 + bool SetDirTime(LPCWSTR fileName, const FILETIME *creationTime, const FILETIME *lastAccessTime, const FILETIME *lastWriteTime);
334 +
335 +-bool MySetFileAttributes(LPCTSTR fileName, DWORD fileAttributes);
336 ++bool MySetFileAttributes(LPCTSTR fileName, DWORD fileAttributes,
337 ++ CObjectVector<CDelayedSymLink> *delayedSymLinks = 0);
338 + #ifndef _UNICODE
339 +-bool MySetFileAttributes(LPCWSTR fileName, DWORD fileAttributes);
340 ++bool MySetFileAttributes(LPCWSTR fileName, DWORD fileAttributes,
341 ++ CObjectVector<CDelayedSymLink> *delayedSymLinks = 0);
342 + #endif
343 +
344 + bool MyMoveFile(LPCTSTR existFileName, LPCTSTR newFileName);
345 +@@ -80,6 +85,31 @@ public:
346 + bool Remove();
347 + };
348 +
349 ++// Symbolic links must be created last so that they can't be used to
350 ++// create or overwrite files above the extraction directory.
351 ++class CDelayedSymLink
352 ++{
353 ++#ifdef ENV_UNIX
354 ++ // Where the symlink should be created. The target is specified in
355 ++ // the placeholder file.
356 ++ AString _source;
357 ++
358 ++ // Device and inode of the placeholder file. Before creating the
359 ++ // symlink, we must check that these haven't been changed by creation
360 ++ // of another symlink.
361 ++ dev_t _dev;
362 ++ ino_t _ino;
363 ++
364 ++public:
365 ++ explicit CDelayedSymLink(LPCSTR source);
366 ++ bool Create();
367 ++#else // !ENV_UNIX
368 ++public:
369 ++ CDelayedSymLink(LPCSTR source) {}
370 ++ bool Create() { return true; }
371 ++#endif // ENV_UNIX
372 ++};
373 ++
374 + #ifdef _UNICODE
375 + typedef CTempFile CTempFileW;
376 + #endif
377
378 diff --git a/app-arch/p7zip/files/p7zip-9.20.1-QA.patch b/app-arch/p7zip/files/p7zip-9.20.1-QA.patch
379 new file mode 100644
380 index 0000000..8845aca
381 --- /dev/null
382 +++ b/app-arch/p7zip/files/p7zip-9.20.1-QA.patch
383 @@ -0,0 +1,17 @@
384 +From: Julian Ospald <hasufell@g.o>
385 +Date: Thu Jun 7 14:31:12 UTC 2012
386 +Subject: fix QA warnings
387 +
388 +https://sourceforge.net/tracker/?func=detail&atid=660493&aid=3532590&group_id=111810
389 +
390 +--- CPP/7zip/Archive/NtfsHandler.cpp
391 ++++ CPP/7zip/Archive/NtfsHandler.cpp
392 +@@ -1280,7 +1280,7 @@
393 + if (recSizeLog < Header.SectorSizeLog)
394 + return false;
395 + numSectorsInRec = 1 << (recSizeLog - Header.SectorSizeLog);
396 +- if (!mftRec.Parse(ByteBuf, Header.SectorSizeLog, numSectorsInRec, NULL, 0))
397 ++ if (!mftRec.Parse(ByteBuf, Header.SectorSizeLog, numSectorsInRec, 0, NULL))
398 + return S_FALSE;
399 + if (!mftRec.IsFILE())
400 + return S_FALSE;
401
402 diff --git a/app-arch/p7zip/files/p7zip-9.20.1-execstack.patch b/app-arch/p7zip/files/p7zip-9.20.1-execstack.patch
403 new file mode 100644
404 index 0000000..e8259c7
405 --- /dev/null
406 +++ b/app-arch/p7zip/files/p7zip-9.20.1-execstack.patch
407 @@ -0,0 +1,24 @@
408 +diff -Naupr p7zip_9.20.1.orig/Asm/x64/7zCrcT8U.asm p7zip_9.20.1/Asm/x64/7zCrcT8U.asm
409 +--- p7zip_9.20.1.orig/Asm/x64/7zCrcT8U.asm 2008-08-14 11:18:07.000000000 +0200
410 ++++ p7zip_9.20.1/Asm/x64/7zCrcT8U.asm 2011-07-26 17:43:57.727910278 +0200
411 +@@ -101,3 +101,8 @@ _CrcUpdateT8:
412 + ret
413 +
414 + end
415 ++
416 ++%ifidn __OUTPUT_FORMAT__,elf
417 ++section .note.GNU-stack noalloc noexec nowrite progbits
418 ++%endif
419 ++
420 +diff -Naupr p7zip_9.20.1.orig/Asm/x86/7zCrcT8U.asm p7zip_9.20.1/Asm/x86/7zCrcT8U.asm
421 +--- p7zip_9.20.1.orig/Asm/x86/7zCrcT8U.asm 2009-07-14 12:44:15.000000000 +0200
422 ++++ p7zip_9.20.1/Asm/x86/7zCrcT8U.asm 2011-07-26 17:44:23.938864508 +0200
423 +@@ -99,3 +99,8 @@ _CrcUpdateT8:
424 +
425 +
426 + ; end
427 ++
428 ++%ifidn __OUTPUT_FORMAT__,elf
429 ++section .note.GNU-stack noalloc noexec nowrite progbits
430 ++%endif
431 ++
432
433 diff --git a/app-arch/p7zip/files/p7zip-CVE-2015-1038-musl.patch b/app-arch/p7zip/files/p7zip-CVE-2015-1038-musl.patch
434 new file mode 100644
435 index 0000000..9837758
436 --- /dev/null
437 +++ b/app-arch/p7zip/files/p7zip-CVE-2015-1038-musl.patch
438 @@ -0,0 +1,14 @@
439 +diff -Naurw p7zip_15.09.orig/CPP/Windows/FileDir.h p7zip_15.09/CPP/Windows/FileDir.h
440 +--- p7zip_15.09.orig/CPP/Windows/FileDir.h 2015-10-28 12:10:52.776688264 -0700
441 ++++ p7zip_15.09/CPP/Windows/FileDir.h 2015-10-28 12:11:27.813355975 -0700
442 +@@ -3,6 +3,10 @@
443 + #ifndef __WINDOWS_FILE_DIR_H
444 + #define __WINDOWS_FILE_DIR_H
445 +
446 ++#ifdef ENV_UNIX
447 ++#include <sys/types.h>
448 ++#endif
449 ++
450 + #include "../Common/MyString.h"
451 + #include "../Common/MyVector.h"
452 +
453
454 diff --git a/app-arch/p7zip/metadata.xml b/app-arch/p7zip/metadata.xml
455 new file mode 100644
456 index 0000000..686e063
457 --- /dev/null
458 +++ b/app-arch/p7zip/metadata.xml
459 @@ -0,0 +1,14 @@
460 +<?xml version="1.0" encoding="UTF-8"?>
461 +<!DOCTYPE pkgmetadata SYSTEM "http://www.gentoo.org/dtd/metadata.dtd">
462 +<pkgmetadata>
463 + <maintainer type="person">
464 + <email>prometheanfire@g.o</email>
465 + <description>maintainer</description>
466 + </maintainer>
467 + <use>
468 + <flag name="rar">Enable support for non-free rar decoder</flag>
469 + </use>
470 + <upstream>
471 + <remote-id type="sourceforge">p7zip</remote-id>
472 + </upstream>
473 +</pkgmetadata>
474
475 diff --git a/app-arch/p7zip/p7zip-9.20.1-r5.ebuild b/app-arch/p7zip/p7zip-9.20.1-r5.ebuild
476 new file mode 100644
477 index 0000000..c399922
478 --- /dev/null
479 +++ b/app-arch/p7zip/p7zip-9.20.1-r5.ebuild
480 @@ -0,0 +1,156 @@
481 +# Copyright 1999-2015 Gentoo Foundation
482 +# Distributed under the terms of the GNU General Public License v2
483 +# $Id$
484 +
485 +EAPI=4
486 +
487 +WX_GTK_VER="2.8"
488 +
489 +inherit eutils multilib toolchain-funcs wxwidgets
490 +
491 +DESCRIPTION="Port of 7-Zip archiver for Unix"
492 +HOMEPAGE="http://p7zip.sourceforge.net/"
493 +SRC_URI="mirror://sourceforge/${PN}/${PN}_${PV}_src_all.tar.bz2"
494 +
495 +LICENSE="LGPL-2.1 rar? ( unRAR )"
496 +SLOT="0"
497 +KEYWORDS="alpha amd64 ~arm hppa ia64 ppc ppc64 ~s390 sparc x86 ~x86-fbsd ~x86-freebsd ~x86-interix ~amd64-linux ~x86-linux ~ppc-macos ~x64-macos ~x86-macos ~sparc-solaris"
498 +IUSE="doc kde rar +pch static wxwidgets"
499 +
500 +REQUIRED_USE="kde? ( wxwidgets )"
501 +
502 +RDEPEND="
503 + kde? ( x11-libs/wxGTK:2.8[X,-odbc] kde-base/kdelibs )
504 + wxwidgets? ( x11-libs/wxGTK:2.8[X,-odbc] )"
505 +DEPEND="${RDEPEND}
506 + amd64? ( dev-lang/yasm )
507 + x86? ( dev-lang/nasm )"
508 +
509 +S=${WORKDIR}/${PN}_${PV}
510 +
511 +src_prepare() {
512 + epatch \
513 + "${FILESDIR}"/${P}-execstack.patch \
514 + "${FILESDIR}"/${P}-QA.patch \
515 + "${FILESDIR}"/${P}-CVE-2015-1038.patch \
516 + "${FILESDIR}"/${PN}-CVE-2015-1038-musl.patch
517 +
518 + if ! use pch; then
519 + sed "s:PRE_COMPILED_HEADER=StdAfx.h.gch:PRE_COMPILED_HEADER=:g" -i makefile.* || die
520 + fi
521 +
522 + sed \
523 + -e 's:-m32 ::g' \
524 + -e 's:-m64 ::g' \
525 + -e 's:-O::g' \
526 + -e 's:-pipe::g' \
527 + -e "/^CC/s:\$(ALLFLAGS):${CFLAGS} \$(ALLFLAGS):g" \
528 + -e "/^CXX/s:\$(ALLFLAGS):${CXXFLAGS} \$(ALLFLAGS):g" \
529 + -i makefile* || die
530 +
531 + # remove non-free RAR codec
532 + if use rar; then
533 + ewarn "Enabling nonfree RAR decompressor"
534 + else
535 + sed -e '/Rar/d' -i makefile* || die
536 + rm -rf CPP/7zip/Compress/Rar || die
537 + epatch "${FILESDIR}"/9.04-makefile.patch
538 + fi
539 +
540 + sed -i \
541 + -e "/^CXX=/s:g++:$(tc-getCXX):" \
542 + -e "/^CC=/s:gcc:$(tc-getCC):" \
543 + -e '/ALLFLAGS/s:-s ::' \
544 + makefile* || die "changing makefiles"
545 +
546 + if use amd64; then
547 + cp -f makefile.linux_amd64_asm makefile.machine || die
548 + elif use x86; then
549 + cp -f makefile.linux_x86_asm_gcc_4.X makefile.machine || die
550 + elif [[ ${CHOST} == *-darwin* ]] ; then
551 + # Mac OS X needs this special makefile, because it has a non-GNU linker
552 + [[ ${CHOST} == *64-* ]] \
553 + && cp -f makefile.macosx_64bits makefile.machine \
554 + || cp -f makefile.macosx_32bits makefile.machine
555 + # bundles have extension .bundle but don't die because USE=-rar
556 + # removes the Rar directory
557 + sed -i -e '/strcpy(name/s/\.so/.bundle/' \
558 + CPP/Windows/DLL.cpp || die
559 + sed -i -e '/^PROG=/s/\.so/.bundle/' \
560 + CPP/7zip/Bundles/Format7zFree/makefile \
561 + $(use rar && echo CPP/7zip/Compress/Rar/makefile) || die
562 + elif use x86-fbsd; then
563 + # FreeBSD needs this special makefile, because it hasn't -ldl
564 + sed -e 's/-lc_r/-pthread/' makefile.freebsd > makefile.machine
565 + fi
566 +
567 + if use static; then
568 + sed -i -e '/^LOCAL_LIBS=/s/LOCAL_LIBS=/&-static /' makefile.machine || die
569 + fi
570 +
571 + if use kde || use wxwidgets; then
572 + einfo "Preparing dependency list"
573 + emake depend
574 + fi
575 +}
576 +
577 +src_compile() {
578 + emake all3
579 + if use kde || use wxwidgets; then
580 + emake -- 7zG
581 + emake -- 7zFM
582 + fi
583 +}
584 +
585 +src_test() {
586 + emake test test_7z test_7zr
587 +}
588 +
589 +src_install() {
590 + # this wrappers can not be symlinks, p7zip should be called with full path
591 + make_wrapper 7zr "/usr/$(get_libdir)/${PN}/7zr"
592 + make_wrapper 7za "/usr/$(get_libdir)/${PN}/7za"
593 + make_wrapper 7z "/usr/$(get_libdir)/${PN}/7z"
594 +
595 + if use kde || use wxwidgets; then
596 + make_wrapper 7zG "/usr/$(get_libdir)/${PN}/7zG"
597 + make_wrapper 7zFM "/usr/$(get_libdir)/${PN}/7zFM"
598 +
599 + make_desktop_entry 7zFM "${PN} FM" ${PN} "GTK;Utility;Archiving;Compression"
600 +
601 + dobin GUI/p7zipForFilemanager
602 + exeinto /usr/$(get_libdir)/${PN}
603 + doexe bin/7z{G,FM}
604 +
605 + insinto /usr/$(get_libdir)/${PN}
606 + doins -r GUI/{Lang,help}
607 +
608 + insinto /usr/share/icons/hicolor/16x16/apps/
609 + newins GUI/p7zip_16_ok.png p7zip.png
610 +
611 + if use kde; then
612 + rm GUI/kde4/p7zip_compress.desktop || die
613 + insinto /usr/share/kde4/services/ServiceMenus
614 + doins GUI/kde4/*.desktop
615 + fi
616 + fi
617 +
618 + dobin contrib/gzip-like_CLI_wrapper_for_7z/p7zip
619 + doman contrib/gzip-like_CLI_wrapper_for_7z/man1/p7zip.1
620 +
621 + exeinto /usr/$(get_libdir)/${PN}
622 + doexe bin/7z bin/7za bin/7zr bin/7zCon.sfx
623 + doexe bin/*$(get_modname)
624 + if use rar; then
625 + exeinto /usr/$(get_libdir)/${PN}/Codecs/
626 + doexe bin/Codecs/*$(get_modname)
627 + fi
628 +
629 + doman man1/7z.1 man1/7za.1 man1/7zr.1
630 + dodoc ChangeLog README TODO
631 +
632 + if use doc; then
633 + dodoc DOCS/*.txt
634 + dohtml -r DOCS/MANUAL/*
635 + fi
636 +}