Browse Source

Add password support for read access

test_fixup
Vadim Lebedev 2 years ago
parent
commit
9bb3133f6e
5 changed files with 1307 additions and 124 deletions
  1. +7
    -4
      libarchive/Makefile
  2. +4
    -0
      libarchive/__init__.py
  3. +111
    -11
      libarchive/_libarchive.i
  4. +96
    -3
      libarchive/_libarchive.py
  5. +1089
    -106
      libarchive/_libarchive_wrap.c

+ 7
- 4
libarchive/Makefile View File

@@ -2,19 +2,22 @@ CFLAGS = -g
INCLUDE = -I/usr/include -I.
LIBS = -larchive

DEFINES = -DPyUnicode_AS_STRING=PyUnicode_AS_DATA
PYVER ?= 3.9

all: __libarchive.so

_libarchive_wrap.c: _libarchive.i
_libarchive_wrap.cxx: _libarchive.i
#swig -python -c++ -Wall -shadow _libarchive.i
swig -python -Wall -shadow _libarchive.i
swig -python -Wall -shadow _libarchive.i

_libarchive_wrap.o: _libarchive_wrap.c
${CC} -c ${CFLAGS} -fPIC ${INCLUDE} $$(python${PYVER}-config --cflags) _libarchive_wrap.c
echo ${CC} -c ${CFLAGS} -fPIC $$(python${PYVER}-config --cflags) _libarchive_wrap.c
${CC} -c ${CFLAGS} -fPIC $$(python${PYVER}-config --cflags) ${DEFINES} _libarchive_wrap.c
# ${CXX} -c ${CFLAGS} -fPIC $$(python${PYVER}-config --cflags) -DPyUnicode_AS_STRING=PyUnicode_AS_DATA _libarchive_wrap.cxx

__libarchive.so: _libarchive_wrap.o
${CC} _libarchive_wrap.o -shared $$(python${PYVER}-config --ldflags) -o __libarchive.so ${LIBS}

clean:
rm -f *.o *.so *.pyc
rm -f *.o *.so *.pyc

+ 4
- 0
libarchive/__init__.py View File

@@ -623,6 +623,10 @@ class Archive(object):
s.write(entry.pathname)
s.flush()

def add_passphrase(self, password):
'''Adds a password to the archive.'''
_libarchive.archive_read_add_passphrase(self._a, password)


class SeekableArchive(Archive):
'''A class that provides random-access to archive entries. It does this by using one


+ 111
- 11
libarchive/_libarchive.i View File

@@ -153,8 +153,8 @@ extern int archive_read_free(struct archive *);
extern int archive_read_open_filename(struct archive *,
const char *_filename, size_t _block_size);
extern int archive_read_open_memory(struct archive *,
void * buff, size_t size);
extern int archive_read_open_memory2(struct archive *a, void *buff,
const void * buff, size_t size);
extern int archive_read_open_memory2(struct archive *a, void const *buff,
size_t size, size_t read_size);
extern int archive_read_open_fd(struct archive *, int _fd,
size_t _block_size);
@@ -169,39 +169,107 @@ extern int archive_read_next_header2(struct archive *,
extern const struct stat *archive_entry_stat(struct archive_entry *);
extern __LA_INT64_T archive_read_header_position(struct archive *);

/*
* Set read options.
*/
/* Apply option to the format only. */
extern int archive_read_set_format_option(struct archive *_a,
const char *m, const char *o,
const char *v);
/* Apply option to the filter only. */
extern int archive_read_set_filter_option(struct archive *_a,
const char *m, const char *o,
const char *v);
/* Apply option to both the format and the filter. */
extern int archive_read_set_option(struct archive *_a,
const char *m, const char *o,
const char *v);
/* Apply option string to both the format and the filter. */
extern int archive_read_set_options(struct archive *_a,
const char *opts);

/*
* Add a decryption passphrase.
*/
extern int archive_read_add_passphrase(struct archive *, const char *);
/* data */
extern int archive_read_data_skip(struct archive *);
extern int archive_read_data_into_fd(struct archive *, int fd);

/* FILTERS */
#if ARCHIVE_VERSION_NUMBER < 4000000
extern int archive_read_support_compression_all(struct archive *);
extern int archive_read_support_compression_bzip2(struct archive *);
extern int archive_read_support_compression_compress(struct archive *);
extern int archive_read_support_compression_gzip(struct archive *);
extern int archive_read_support_compression_lzip(struct archive *);
extern int archive_read_support_compression_lzma(struct archive *);
extern int archive_read_support_compression_none(struct archive *);
extern int archive_read_support_compression_program(struct archive *, const char *command);
extern int archive_read_support_compression_program_signature
(struct archive *, const char *,
const void * /* match */, size_t);

extern int archive_read_support_compression_rpm(struct archive *);
extern int archive_read_support_compression_uu(struct archive *);
extern int archive_read_support_compression_xz(struct archive *);
#endif

extern int archive_read_support_filter_all(struct archive *);
extern int archive_read_support_filter_bzip2(struct archive *);
extern int archive_read_support_filter_compress(struct archive *);
extern int archive_read_support_filter_gzip(struct archive *);
extern int archive_read_support_filter_grzip(struct archive *);
extern int archive_read_support_filter_lrzip(struct archive *);
extern int archive_read_support_filter_lz4(struct archive *);
extern int archive_read_support_filter_lzip(struct archive *);
extern int archive_read_support_filter_lzma(struct archive *);
extern int archive_read_support_filter_lzop(struct archive *);
extern int archive_read_support_filter_none(struct archive *);
extern int archive_read_support_filter_program(struct archive *,
const char *command);
extern int archive_read_support_filter_program_signature
(struct archive *, const char * /* cmd */,
const void * /* match */, size_t);
extern int archive_read_support_filter_rpm(struct archive *);
extern int archive_read_support_filter_uu(struct archive *);
extern int archive_read_support_filter_xz(struct archive *);

/* FORMATS */
extern int archive_read_support_format_all(struct archive *);
extern int archive_read_support_format_7zip(struct archive *);
extern int archive_read_support_format_all(struct archive *);
extern int archive_read_support_format_ar(struct archive *);
extern int archive_read_support_format_by_code(struct archive *, int);
extern int archive_read_support_format_cab(struct archive *);
extern int archive_read_support_format_cpio(struct archive *);
extern int archive_read_support_format_empty(struct archive *);
extern int archive_read_support_format_gnutar(struct archive *);
extern int archive_read_support_format_iso9660(struct archive *);
extern int archive_read_support_format_lha(struct archive *);
/*extern int archive_read_support_format_mtree(struct archive *);*/
/* extern int archive_read_support_format_mtree(struct archive *); */
extern int archive_read_support_format_rar(struct archive *);
extern int archive_read_support_format_raw(struct archive *);
extern int archive_read_support_format_tar(struct archive *);
extern int archive_read_support_format_warc(struct archive *);
extern int archive_read_support_format_xar(struct archive *);
/* archive_read_support_format_zip() enables both streamable and seekable
* zip readers. */
extern int archive_read_support_format_zip(struct archive *);
/*extern int archive_read_support_format_by_code(struct archive *, int);*/
/* Reads Zip archives as stream from beginning to end. Doesn't
* correctly handle SFX ZIP files or ZIP archives that have been modified
* in-place. */
extern int archive_read_support_format_zip_streamable(struct archive *);
/* Reads starting from central directory; requires seekable input. */
extern int archive_read_support_format_zip_seekable(struct archive *);

/* Functions to manually set the format and filters to be used. This is
* useful to bypass the bidding process when the format and filters to use
* is known in advance.
*/
extern int archive_read_set_format(struct archive *, int);
extern int archive_read_append_filter(struct archive *, int);
extern int archive_read_append_filter_program(struct archive *,
const char *);
extern int archive_read_append_filter_program_signature
(struct archive *, const char *, const void * /* match */, size_t);

/* ARCHIVE WRITING */
extern struct archive *archive_write_new(void);
@@ -282,8 +350,8 @@ extern void archive_entry_set_link(struct archive_entry *, const char *);
//extern int archive_entry_symlink_type(struct archive_entry *);
extern const wchar_t *archive_entry_symlink_w(struct archive_entry *);

//__LA_DECL void archive_entry_copy_link(struct archive_entry *, const char *);
//__LA_DECL void archive_entry_copy_link_w(struct archive_entry *, const wchar_t *);
//extern void archive_entry_copy_link(struct archive_entry *, const char *);
//extern void archive_entry_copy_link_w(struct archive_entry *, const wchar_t *);

/* The names for symlink modes here correspond to an old BSD
* command-line argument convention: -L, -P, -H */
@@ -318,8 +386,8 @@ extern const char *archive_error_string(struct archive *);


/* CONSTANTS */
#define ARCHIVE_VERSION_NUMBER 3005003
#define ARCHIVE_VERSION_STRING "libarchive 3.5.2"
#define ARCHIVE_VERSION_NUMBER 3002002
#define ARCHIVE_VERSION_STRING "libarchive 3.2.2"
#define ARCHIVE_EOF 1 /* Found end of archive. */
#define ARCHIVE_OK 0 /* Operation was successful. */
#define ARCHIVE_RETRY (-10) /* Retry might succeed. */
@@ -337,6 +405,10 @@ extern const char *archive_error_string(struct archive *);
#define ARCHIVE_FILTER_UU 7
#define ARCHIVE_FILTER_RPM 8
#define ARCHIVE_FILTER_LZIP 9
#define ARCHIVE_FILTER_LRZIP 10
#define ARCHIVE_FILTER_LZOP 11
#define ARCHIVE_FILTER_GRZIP 12
#define ARCHIVE_FILTER_LZ4 13

#define ARCHIVE_FORMAT_BASE_MASK 0xff0000
#define ARCHIVE_FORMAT_CPIO 0x10000
@@ -368,21 +440,49 @@ extern const char *archive_error_string(struct archive *);
#define ARCHIVE_FORMAT_CAB 0xC0000
#define ARCHIVE_FORMAT_RAR 0xD0000
#define ARCHIVE_FORMAT_7ZIP 0xE0000
#define ARCHIVE_FORMAT_WARC 0xF0000

/* Default: Do not try to set owner/group. */
#define ARCHIVE_EXTRACT_OWNER (0x0001)
/* Default: Do obey umask, do not restore SUID/SGID/SVTX bits. */
#define ARCHIVE_EXTRACT_PERM (0x0002)
/* Default: Do not restore mtime/atime. */
#define ARCHIVE_EXTRACT_TIME (0x0004)
/* Default: Replace existing files. */
#define ARCHIVE_EXTRACT_NO_OVERWRITE (0x0008)
/* Default: Try create first, unlink only if create fails with EEXIST. */
#define ARCHIVE_EXTRACT_UNLINK (0x0010)
/* Default: Do not restore ACLs. */
#define ARCHIVE_EXTRACT_ACL (0x0020)
/* Default: Do not restore fflags. */
#define ARCHIVE_EXTRACT_FFLAGS (0x0040)
/* Default: Do not restore xattrs. */
#define ARCHIVE_EXTRACT_XATTR (0x0080)
/* Default: Do not try to guard against extracts redirected by symlinks. */
/* Note: With ARCHIVE_EXTRACT_UNLINK, will remove any intermediate symlink. */
#define ARCHIVE_EXTRACT_SECURE_SYMLINKS (0x0100)
/* Default: Do not reject entries with '..' as path elements. */
#define ARCHIVE_EXTRACT_SECURE_NODOTDOT (0x0200)
/* Default: Create parent directories as needed. */
#define ARCHIVE_EXTRACT_NO_AUTODIR (0x0400)
/* Default: Overwrite files, even if one on disk is newer. */
#define ARCHIVE_EXTRACT_NO_OVERWRITE_NEWER (0x0800)
/* Detect blocks of 0 and write holes instead. */
#define ARCHIVE_EXTRACT_SPARSE (0x1000)
/* Default: Do not restore Mac extended metadata. */
/* This has no effect except on Mac OS. */
#define ARCHIVE_EXTRACT_MAC_METADATA (0x2000)
/* Default: Use HFS+ compression if it was compressed. */
/* This has no effect except on Mac OS v10.6 or later. */
#define ARCHIVE_EXTRACT_NO_HFS_COMPRESSION (0x4000)
/* Default: Do not use HFS+ compression if it was not compressed. */
/* This has no effect except on Mac OS v10.6 or later. */
#define ARCHIVE_EXTRACT_HFS_COMPRESSION_FORCED (0x8000)
/* Default: Do not reject entries with absolute paths */
#define ARCHIVE_EXTRACT_SECURE_NOABSOLUTEPATHS (0x10000)
/* Default: Do not clear no-change flags when unlinking object */
#define ARCHIVE_EXTRACT_CLEAR_NOCHANGE_FFLAGS (0x20000)


%inline %{
PyObject *archive_read_data_into_str(struct archive *archive, int len) {


+ 96
- 3
libarchive/_libarchive.py View File

@@ -95,12 +95,63 @@ def archive_entry_stat(arg1):
def archive_read_header_position(arg1):
return __libarchive.archive_read_header_position(arg1)

def archive_read_set_format_option(_a, m, o, v):
return __libarchive.archive_read_set_format_option(_a, m, o, v)

def archive_read_set_filter_option(_a, m, o, v):
return __libarchive.archive_read_set_filter_option(_a, m, o, v)

def archive_read_set_option(_a, m, o, v):
return __libarchive.archive_read_set_option(_a, m, o, v)

def archive_read_set_options(_a, opts):
return __libarchive.archive_read_set_options(_a, opts)

def archive_read_add_passphrase(arg1, arg2):
return __libarchive.archive_read_add_passphrase(arg1, arg2)

def archive_read_data_skip(arg1):
return __libarchive.archive_read_data_skip(arg1)

def archive_read_data_into_fd(arg1, fd):
return __libarchive.archive_read_data_into_fd(arg1, fd)

def archive_read_support_compression_all(arg1):
return __libarchive.archive_read_support_compression_all(arg1)

def archive_read_support_compression_bzip2(arg1):
return __libarchive.archive_read_support_compression_bzip2(arg1)

def archive_read_support_compression_compress(arg1):
return __libarchive.archive_read_support_compression_compress(arg1)

def archive_read_support_compression_gzip(arg1):
return __libarchive.archive_read_support_compression_gzip(arg1)

def archive_read_support_compression_lzip(arg1):
return __libarchive.archive_read_support_compression_lzip(arg1)

def archive_read_support_compression_lzma(arg1):
return __libarchive.archive_read_support_compression_lzma(arg1)

def archive_read_support_compression_none(arg1):
return __libarchive.archive_read_support_compression_none(arg1)

def archive_read_support_compression_program(arg1, command):
return __libarchive.archive_read_support_compression_program(arg1, command)

def archive_read_support_compression_program_signature(arg1, arg2, arg3, arg4):
return __libarchive.archive_read_support_compression_program_signature(arg1, arg2, arg3, arg4)

def archive_read_support_compression_rpm(arg1):
return __libarchive.archive_read_support_compression_rpm(arg1)

def archive_read_support_compression_uu(arg1):
return __libarchive.archive_read_support_compression_uu(arg1)

def archive_read_support_compression_xz(arg1):
return __libarchive.archive_read_support_compression_xz(arg1)

def archive_read_support_filter_all(arg1):
return __libarchive.archive_read_support_filter_all(arg1)

@@ -113,15 +164,33 @@ def archive_read_support_filter_compress(arg1):
def archive_read_support_filter_gzip(arg1):
return __libarchive.archive_read_support_filter_gzip(arg1)

def archive_read_support_filter_grzip(arg1):
return __libarchive.archive_read_support_filter_grzip(arg1)

def archive_read_support_filter_lrzip(arg1):
return __libarchive.archive_read_support_filter_lrzip(arg1)

def archive_read_support_filter_lz4(arg1):
return __libarchive.archive_read_support_filter_lz4(arg1)

def archive_read_support_filter_lzip(arg1):
return __libarchive.archive_read_support_filter_lzip(arg1)

def archive_read_support_filter_lzma(arg1):
return __libarchive.archive_read_support_filter_lzma(arg1)

def archive_read_support_filter_lzop(arg1):
return __libarchive.archive_read_support_filter_lzop(arg1)

def archive_read_support_filter_none(arg1):
return __libarchive.archive_read_support_filter_none(arg1)

def archive_read_support_filter_program(arg1, command):
return __libarchive.archive_read_support_filter_program(arg1, command)

def archive_read_support_filter_program_signature(arg1, arg2, arg3, arg4):
return __libarchive.archive_read_support_filter_program_signature(arg1, arg2, arg3, arg4)

def archive_read_support_filter_rpm(arg1):
return __libarchive.archive_read_support_filter_rpm(arg1)

@@ -131,15 +200,18 @@ def archive_read_support_filter_uu(arg1):
def archive_read_support_filter_xz(arg1):
return __libarchive.archive_read_support_filter_xz(arg1)

def archive_read_support_format_all(arg1):
return __libarchive.archive_read_support_format_all(arg1)

def archive_read_support_format_7zip(arg1):
return __libarchive.archive_read_support_format_7zip(arg1)

def archive_read_support_format_all(arg1):
return __libarchive.archive_read_support_format_all(arg1)

def archive_read_support_format_ar(arg1):
return __libarchive.archive_read_support_format_ar(arg1)

def archive_read_support_format_by_code(arg1, arg2):
return __libarchive.archive_read_support_format_by_code(arg1, arg2)

def archive_read_support_format_cab(arg1):
return __libarchive.archive_read_support_format_cab(arg1)

@@ -167,12 +239,33 @@ def archive_read_support_format_raw(arg1):
def archive_read_support_format_tar(arg1):
return __libarchive.archive_read_support_format_tar(arg1)

def archive_read_support_format_warc(arg1):
return __libarchive.archive_read_support_format_warc(arg1)

def archive_read_support_format_xar(arg1):
return __libarchive.archive_read_support_format_xar(arg1)

def archive_read_support_format_zip(arg1):
return __libarchive.archive_read_support_format_zip(arg1)

def archive_read_support_format_zip_streamable(arg1):
return __libarchive.archive_read_support_format_zip_streamable(arg1)

def archive_read_support_format_zip_seekable(arg1):
return __libarchive.archive_read_support_format_zip_seekable(arg1)

def archive_read_set_format(arg1, arg2):
return __libarchive.archive_read_set_format(arg1, arg2)

def archive_read_append_filter(arg1, arg2):
return __libarchive.archive_read_append_filter(arg1, arg2)

def archive_read_append_filter_program(arg1, arg2):
return __libarchive.archive_read_append_filter_program(arg1, arg2)

def archive_read_append_filter_program_signature(arg1, arg2, arg3, arg4):
return __libarchive.archive_read_append_filter_program_signature(arg1, arg2, arg3, arg4)

def archive_write_new():
return __libarchive.archive_write_new()



+ 1089
- 106
libarchive/_libarchive_wrap.c
File diff suppressed because it is too large
View File


Loading…
Cancel
Save