├── .gitignore ├── Android.mk ├── Application.mk ├── COPYING ├── COPYING.GPL ├── COPYING.LGPL ├── README.md ├── README_zh.md ├── boot.c ├── boot.h ├── build.sh ├── bxxt.c ├── bxxt.h ├── cpio.c ├── cpio.h ├── docker └── Dockerfile ├── dtcc.c ├── dtcc.h ├── jni ├── Android.mk └── Application.mk ├── libarchive ├── COPYING ├── archive_acl.c ├── archive_blake2s_ref.c ├── archive_blake2sp_ref.c ├── archive_check_magic.c ├── archive_cmdline.c ├── archive_cryptor.c ├── archive_digest.c ├── archive_disk_acl_darwin.c ├── archive_disk_acl_freebsd.c ├── archive_disk_acl_linux.c ├── archive_disk_acl_sunos.c ├── archive_entry.c ├── archive_entry_copy_bhfi.c ├── archive_entry_copy_stat.c ├── archive_entry_link_resolver.c ├── archive_entry_sparse.c ├── archive_entry_stat.c ├── archive_entry_strmode.c ├── archive_entry_xattr.c ├── archive_getdate.c ├── archive_hmac.c ├── archive_match.c ├── archive_options.c ├── archive_pack_dev.c ├── archive_pathmatch.c ├── archive_ppmd7.c ├── archive_ppmd8.c ├── archive_random.c ├── archive_rb.c ├── archive_read.c ├── archive_read_add_passphrase.c ├── archive_read_append_filter.c ├── archive_read_data_into_fd.c ├── archive_read_disk_entry_from_file.c ├── archive_read_disk_posix.c ├── archive_read_disk_set_standard_lookup.c ├── archive_read_disk_windows.c ├── archive_read_extract.c ├── archive_read_extract2.c ├── archive_read_open_fd.c ├── archive_read_open_file.c ├── archive_read_open_filename.c ├── archive_read_open_memory.c ├── archive_read_set_format.c ├── archive_read_set_options.c ├── archive_read_support_filter_all.c ├── archive_read_support_filter_bzip2.c ├── archive_read_support_filter_compress.c ├── archive_read_support_filter_grzip.c ├── archive_read_support_filter_gzip.c ├── archive_read_support_filter_lrzip.c ├── archive_read_support_filter_lz4.c ├── archive_read_support_filter_lzop.c ├── archive_read_support_filter_none.c ├── archive_read_support_filter_program.c ├── archive_read_support_filter_rpm.c ├── archive_read_support_filter_uu.c ├── archive_read_support_filter_xz.c ├── archive_read_support_filter_zstd.c ├── archive_read_support_format_7zip.c ├── archive_read_support_format_all.c ├── archive_read_support_format_ar.c ├── archive_read_support_format_by_code.c ├── archive_read_support_format_cab.c ├── archive_read_support_format_cpio.c ├── archive_read_support_format_empty.c ├── archive_read_support_format_iso9660.c ├── archive_read_support_format_lha.c ├── archive_read_support_format_mtree.c ├── archive_read_support_format_rar.c ├── archive_read_support_format_rar5.c ├── archive_read_support_format_raw.c ├── archive_read_support_format_tar.c ├── archive_read_support_format_warc.c ├── archive_read_support_format_xar.c ├── archive_read_support_format_zip.c ├── archive_string.c ├── archive_string_sprintf.c ├── archive_util.c ├── archive_version_details.c ├── archive_virtual.c ├── archive_windows.c ├── archive_write.c ├── archive_write_add_filter.c ├── archive_write_add_filter_b64encode.c ├── archive_write_add_filter_by_name.c ├── archive_write_add_filter_bzip2.c ├── archive_write_add_filter_compress.c ├── archive_write_add_filter_grzip.c ├── archive_write_add_filter_gzip.c ├── archive_write_add_filter_lrzip.c ├── archive_write_add_filter_lz4.c ├── archive_write_add_filter_lzop.c ├── archive_write_add_filter_none.c ├── archive_write_add_filter_program.c ├── archive_write_add_filter_uuencode.c ├── archive_write_add_filter_xz.c ├── archive_write_add_filter_zstd.c ├── archive_write_disk_posix.c ├── archive_write_disk_set_standard_lookup.c ├── archive_write_disk_windows.c ├── archive_write_open_fd.c ├── archive_write_open_file.c ├── archive_write_open_filename.c ├── archive_write_open_memory.c ├── archive_write_set_format.c ├── archive_write_set_format_7zip.c ├── archive_write_set_format_ar.c ├── archive_write_set_format_by_name.c ├── archive_write_set_format_cpio.c ├── archive_write_set_format_cpio_newc.c ├── archive_write_set_format_filter_by_ext.c ├── archive_write_set_format_gnutar.c ├── archive_write_set_format_iso9660.c ├── archive_write_set_format_mtree.c ├── archive_write_set_format_pax.c ├── archive_write_set_format_raw.c ├── archive_write_set_format_shar.c ├── archive_write_set_format_ustar.c ├── archive_write_set_format_v7tar.c ├── archive_write_set_format_warc.c ├── archive_write_set_format_xar.c ├── archive_write_set_format_zip.c ├── archive_write_set_options.c ├── archive_write_set_passphrase.c ├── filter_fork_posix.c ├── filter_fork_windows.c ├── include │ ├── android │ │ ├── android_lf.h │ │ └── config.h │ ├── archive.h │ ├── archive_acl_private.h │ ├── archive_blake2.h │ ├── archive_blake2_impl.h │ ├── archive_cmdline_private.h │ ├── archive_crc32.h │ ├── archive_cryptor_private.h │ ├── archive_digest_private.h │ ├── archive_endian.h │ ├── archive_entry.h │ ├── archive_entry_locale.h │ ├── archive_entry_private.h │ ├── archive_getdate.h │ ├── archive_hmac_private.h │ ├── archive_openssl_evp_private.h │ ├── archive_openssl_hmac_private.h │ ├── archive_options_private.h │ ├── archive_pack_dev.h │ ├── archive_pathmatch.h │ ├── archive_platform.h │ ├── archive_platform_acl.h │ ├── archive_platform_xattr.h │ ├── archive_ppmd7_private.h │ ├── archive_ppmd8_private.h │ ├── archive_ppmd_private.h │ ├── archive_private.h │ ├── archive_random_private.h │ ├── archive_rb.h │ ├── archive_read_disk_private.h │ ├── archive_read_private.h │ ├── archive_string.h │ ├── archive_string_composition.h │ ├── archive_windows.h │ ├── archive_write_disk_private.h │ ├── archive_write_private.h │ ├── archive_write_set_format_private.h │ ├── archive_xxhash.h │ ├── config_freebsd.h │ ├── fe │ │ ├── err.h │ │ ├── lafe_platform.h │ │ ├── line_reader.h │ │ └── passphrase.h │ └── filter_fork.h └── xxhash.c ├── libdtc ├── GPL ├── checks.c ├── data.c ├── dtc-lexer.c ├── dtc-parser.c ├── dtc-parser.h ├── dtc.c ├── dtc.h ├── fdt.h ├── fdtdump.c ├── fdtget.c ├── fdtoverlay.c ├── fdtput.c ├── flattree.c ├── fstree.c ├── libfdt.h ├── libfdt_env.h ├── livetree.c ├── srcpos.c ├── srcpos.h ├── treesource.c ├── util.c ├── util.h └── version.h ├── libsepol ├── COPYING ├── assertion.c ├── av_permissions.h ├── avrule_block.c ├── avtab.c ├── boolean_internal.h ├── boolean_record.c ├── booleans.c ├── conditional.c ├── constraint.c ├── context.c ├── context.h ├── context_internal.h ├── context_record.c ├── debug.c ├── debug.h ├── deprecated_funcs.c ├── dso.h ├── ebitmap.c ├── expand.c ├── handle.c ├── handle.h ├── hashtab.c ├── hierarchy.c ├── ibendport_internal.h ├── ibendport_record.c ├── ibendports.c ├── ibpkey_internal.h ├── ibpkey_record.c ├── ibpkeys.c ├── iface_internal.h ├── iface_record.c ├── include │ ├── cil │ │ ├── android.h │ │ ├── cil.h │ │ └── cil_write_ast.h │ └── sepol │ │ ├── boolean_record.h │ │ ├── booleans.h │ │ ├── compat.h │ │ ├── context.h │ │ ├── context_record.h │ │ ├── debug.h │ │ ├── errcodes.h │ │ ├── handle.h │ │ ├── ibendport_record.h │ │ ├── ibendports.h │ │ ├── ibpkey_record.h │ │ ├── ibpkeys.h │ │ ├── iface_record.h │ │ ├── interfaces.h │ │ ├── kernel_to_cil.h │ │ ├── kernel_to_conf.h │ │ ├── module.h │ │ ├── module_to_cil.h │ │ ├── node_record.h │ │ ├── nodes.h │ │ ├── policydb.h │ │ ├── policydb │ │ ├── avrule_block.h │ │ ├── avtab.h │ │ ├── conditional.h │ │ ├── constraint.h │ │ ├── context.h │ │ ├── ebitmap.h │ │ ├── expand.h │ │ ├── flask.h │ │ ├── flask_types.h │ │ ├── hashtab.h │ │ ├── hierarchy.h │ │ ├── link.h │ │ ├── mls_types.h │ │ ├── module.h │ │ ├── polcaps.h │ │ ├── policydb.h │ │ ├── services.h │ │ ├── sidtab.h │ │ ├── symtab.h │ │ └── util.h │ │ ├── port_record.h │ │ ├── ports.h │ │ ├── roles.h │ │ ├── sepol.h │ │ ├── user_record.h │ │ └── users.h ├── interfaces.c ├── kernel_to_cil.c ├── kernel_to_common.c ├── kernel_to_common.h ├── kernel_to_conf.c ├── link.c ├── mls.c ├── mls.h ├── module.c ├── module_internal.h ├── module_to_cil.c ├── node_internal.h ├── node_record.c ├── nodes.c ├── optimize.c ├── polcaps.c ├── policydb.c ├── policydb_convert.c ├── policydb_internal.h ├── policydb_public.c ├── port_internal.h ├── port_record.c ├── ports.c ├── private.h ├── roles.c ├── services.c ├── sidtab.c ├── symtab.c ├── user_internal.h ├── user_record.c ├── users.c ├── util.c └── write.c ├── patch.c ├── prop.c ├── prop.h ├── sepol.c ├── sepol.h ├── sha1.c ├── sha1.h ├── util.c ├── util.h └── zlib ├── LICENSE ├── README ├── adler32.c ├── compress.c ├── crc32.c ├── crc32.h ├── deflate.c ├── deflate.h ├── gzclose.c ├── gzguts.h ├── gzlib.c ├── gzread.c ├── gzwrite.c ├── infback.c ├── inffast.c ├── inffast.h ├── inffixed.h ├── inflate.c ├── inflate.h ├── inftrees.c ├── inftrees.h ├── trees.c ├── trees.h ├── uncompr.c ├── zconf.h ├── zlib.h ├── zutil.c └── zutil.h /.gitignore: -------------------------------------------------------------------------------- 1 | obj/ 2 | libs/ 3 | out/ 4 | -------------------------------------------------------------------------------- /Application.mk: -------------------------------------------------------------------------------- 1 | # Copyright 2019 rev1si0n 2 | APP_BUILD_SCRIPT := Android.mk 3 | APP_PLATFORM := android-23 4 | APP_ABI := armeabi-v7a arm64-v8a x86 x86_64 5 | APP_STRIP_MODE := --strip-all 6 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | This package contains files under two licences - 2 | the GNU General Public License and the GNU Lesser General Public License. 3 | 4 | See COPYING.GPL and COPYING.LGPL respectively for the full text of 5 | these licences. All files distributed with this package indicate the 6 | appropriate license to use with that file. 7 | -------------------------------------------------------------------------------- /build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | pushd $(pwd) 3 | cd docker/ 4 | docker build -t android-ndk-r20 . 5 | 6 | popd 7 | docker run -it -v $(pwd):/src android-ndk-r20 \ 8 | /opt/android-ndk-r20/build/ndk-build -j8 9 | echo "Done! checkout libs/" 10 | -------------------------------------------------------------------------------- /bxxt.c: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright rev1si0n . 2019. 3 | * 4 | * This file is part of bxxt. 5 | * 6 | * bxxt is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | 11 | * bxxt is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | 16 | * You should have received a copy of the GNU General Public License 17 | * along with bxxt. If not, see . 18 | */ 19 | #include "util.h" 20 | #include "boot.h" 21 | #include "cpio.h" 22 | 23 | int main(int argc, char **argv) { 24 | umask(022); 25 | if (argc > 2 && strcmp(argv[1], "boot") == 0) { 26 | log1(-256, "bxxt 1.0, Copyright rev1si0n , 2019.") 27 | } 28 | 29 | if (argc > 2 && strcmp(argv[1], "boot") == 0) 30 | return boot_main(argc - 1, argv + 1); 31 | else if (argc > 2 && strcmp(argv[1], "sepol") == 0) 32 | return sepol_main(argc - 1, argv + 1); 33 | else if (argc == 3 && strcmp(argv[1], "setdebuggable") == 0) 34 | return setdebuggable_main(argc - 1, argv + 1); 35 | else if (argc == 4 && strcmp(argv[1], "setprop") == 0) 36 | return setprop_main(argc - 1, argv + 1); 37 | else if (argc > 2 && strcmp(argv[1], "patch") == 0) 38 | return patch_main(argc - 1, argv + 1); 39 | return 1; 40 | } 41 | -------------------------------------------------------------------------------- /bxxt.h: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright rev1si0n . 2019. 3 | * 4 | * This file is part of bxxt. 5 | * 6 | * bxxt is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | 11 | * bxxt is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | 16 | * You should have received a copy of the GNU General Public License 17 | * along with bxxt. If not, see . 18 | */ 19 | #ifndef _BXXT_BXXT_H_ 20 | #define _BXXT_BXXT_H_ 21 | 22 | // from libarchive 23 | #define BXXT_SUCCESS (0) 24 | #define BXXT_FAILED (-25) 25 | #define BXXT_FATAL (-30) 26 | #endif 27 | -------------------------------------------------------------------------------- /cpio.h: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright rev1si0n . 2019. 3 | * 4 | * This file is part of bxxt. 5 | * 6 | * bxxt is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | 11 | * bxxt is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | 16 | * You should have received a copy of the GNU General Public License 17 | * along with bxxt. If not, see . 18 | */ 19 | #ifndef _BXXT_CPIO_H_ 20 | #define _BXXT_CPIO_H_ 21 | 22 | #include 23 | #include 24 | 25 | #include "util.h" 26 | #include "bxxt.h" 27 | 28 | #define CPIO_DIR_NOT_EXIST -2 29 | #define CPIO_MAX_SIZE 64*1024*1024 //64MB 30 | 31 | 32 | typedef struct bxxt_cpio_archive { 33 | char path[PATH_MAX]; 34 | uint32_t archive_size_gussed; 35 | 36 | struct archive *r; 37 | struct archive *w; 38 | 39 | struct archive *d_r; // disk reader 40 | struct archive *d_w; // disk writer 41 | 42 | uint32_t inode; 43 | int flags; 44 | } bxxt_cpio_t; 45 | 46 | 47 | static bxxt_cpio_t* bxxt_cpio_archive_new(); 48 | static void bxxt_cpio_archive_free(bxxt_cpio_t* cp); 49 | static int bxxt_cpio_archive_read_entry(bxxt_cpio_t* cp, struct archive_entry *e); 50 | 51 | static int bxxt_cpio_archive_write(bxxt_cpio_t* cp, char* d_name, 52 | char* a_name); 53 | int bxxt_cpio_archive_in(bxxt_buffer_t* bb, const char* path); 54 | static void bxxt_cpio_archive_guess_buffer_size(char*path, void *_cp); 55 | static void bxxt_cpio_archive_add_file(char *path, void *_cp); 56 | int bxxt_cpio_archive_out(const char* path, bxxt_buffer_t** _bb); 57 | static void bxxt_tree_walk(const char *name, void (*fn)(char *path, void* arg), void *arg); 58 | #endif -------------------------------------------------------------------------------- /docker/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM debian:stretch-slim 2 | 3 | ENV ANDROID_NDK_ROOT=/opt/android-ndk-r20 4 | ENV NDK_DOWNLOAD_URL=https://dl.google.com/android/repository/android-ndk-r20-linux-x86_64.zip 5 | RUN cd /tmp \ 6 | && apt update \ 7 | && apt upgrade -y \ 8 | && apt install -y wget curl unzip make file \ 9 | && wget ${NDK_DOWNLOAD_URL} -O ndk.zip \ 10 | && unzip -q ndk.zip -d /opt \ 11 | && rm ndk.zip 12 | WORKDIR /src 13 | CMD bash 14 | -------------------------------------------------------------------------------- /dtcc.c: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright rev1si0n . 2019. 3 | * 4 | * This file is part of bxxt. 5 | * 6 | * bxxt is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | 11 | * bxxt is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | 16 | * You should have received a copy of the GNU General Public License 17 | * along with bxxt. If not, see . 18 | */ 19 | #include 20 | #include 21 | 22 | extern void* dt_to_mem(struct dt_info *dti, int version, uint32_t* size); 23 | extern struct dt_info* dt_from_mem(void* ptr, size_t size); 24 | 25 | #include "bxxt.h" 26 | #include "util.h" 27 | #include "dtcc.h" 28 | 29 | int quiet = 0xff; 30 | int reservenum = 0x00; 31 | int annotate = 0x00; 32 | 33 | int phandle_format = PHANDLE_EPAPR; 34 | 35 | int minsize = 0x00; 36 | int padsize = 0x00; 37 | int alignsize = 0x00; 38 | 39 | 40 | int bxxt_dtcc_dtb_to_source(void* ptr, size_t size, char *fname) { 41 | FILE* out; 42 | bxxt_buffer_t* dtb; 43 | struct dt_info* dti; 44 | out = fopen(fname, "wb"); 45 | 46 | if (out == NULL) 47 | return BXXT_FAILED; 48 | 49 | dtb = bxxt_buffer_create_from_data(ptr, size); 50 | 51 | dti = dt_from_mem(dtb->ptr, dtb->size); 52 | // see https://source.android.com/devices/architecture/dto/compile 53 | generate_label_tree(dti, "__symbols__", true); 54 | 55 | dt_to_source(out, dti); 56 | free(dti); 57 | 58 | bxxt_buffer_free(dtb); 59 | return BXXT_SUCCESS; 60 | } 61 | 62 | bxxt_buffer_t* bxxt_dtcc_dtb_from_source(char *fname) { 63 | struct dt_info* dti; 64 | bxxt_buffer_t* data; 65 | uint32_t size = 0; 66 | void* p; 67 | 68 | dti = dt_from_source(fname); 69 | // see https://source.android.com/devices/architecture/dto/compile 70 | generate_label_tree(dti, "__symbols__", true); 71 | 72 | p = dt_to_mem(dti, DEFAULT_FDT_VERSION, &size); 73 | data = bxxt_buffer_create_from_data(p, size); 74 | 75 | free(p); 76 | free(dti); 77 | 78 | return data; 79 | } -------------------------------------------------------------------------------- /dtcc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright rev1si0n . 2019. 3 | * 4 | * This file is part of bxxt. 5 | * 6 | * bxxt is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | 11 | * bxxt is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | 16 | * You should have received a copy of the GNU General Public License 17 | * along with bxxt. If not, see . 18 | */ 19 | #ifndef _BXXT_DTCC_H_ 20 | #define _BXXT_DTCC_H_ 21 | #include 22 | #include "util.h" 23 | 24 | int bxxt_dtcc_dtb_to_source(void*, size_t, char *); 25 | bxxt_buffer_t* bxxt_dtcc_dtb_from_source(char *); 26 | #endif 27 | -------------------------------------------------------------------------------- /jni/Application.mk: -------------------------------------------------------------------------------- 1 | # Copyright 2019 rev1si0n 2 | APP_BUILD_SCRIPT := Android.mk 3 | APP_PLATFORM := android-23 4 | APP_ABI := armeabi-v7a arm64-v8a x86 x86_64 5 | APP_STRIP_MODE := --strip-all 6 | -------------------------------------------------------------------------------- /libarchive/COPYING: -------------------------------------------------------------------------------- 1 | The libarchive distribution as a whole is Copyright by Tim Kientzle 2 | and is subject to the copyright notice reproduced at the bottom of 3 | this file. 4 | 5 | Each individual file in this distribution should have a clear 6 | copyright/licensing statement at the beginning of the file. If any do 7 | not, please let me know and I will rectify it. The following is 8 | intended to summarize the copyright status of the individual files; 9 | the actual statements in the files are controlling. 10 | 11 | * Except as listed below, all C sources (including .c and .h files) 12 | and documentation files are subject to the copyright notice reproduced 13 | at the bottom of this file. 14 | 15 | * The following source files are also subject in whole or in part to 16 | a 3-clause UC Regents copyright; please read the individual source 17 | files for details: 18 | libarchive/archive_read_support_filter_compress.c 19 | libarchive/archive_write_add_filter_compress.c 20 | libarchive/mtree.5 21 | 22 | * The following source files are in the public domain: 23 | libarchive/archive_getdate.c 24 | 25 | * The following source files are triple-licensed with the ability to choose 26 | from CC0 1.0 Universal, OpenSSL or Apache 2.0 licenses: 27 | libarchive/archive_blake2.h 28 | libarchive/archive_blake2_impl.h 29 | libarchive/archive_blake2s_ref.c 30 | libarchive/archive_blake2sp_ref.c 31 | 32 | * The build files---including Makefiles, configure scripts, 33 | and auxiliary scripts used as part of the compile process---have 34 | widely varying licensing terms. Please check individual files before 35 | distributing them to see if those restrictions apply to you. 36 | 37 | I intend for all new source code to use the license below and hope over 38 | time to replace code with other licenses with new implementations that 39 | do use the license below. The varying licensing of the build scripts 40 | seems to be an unavoidable mess. 41 | 42 | 43 | Copyright (c) 2003-2018 44 | All rights reserved. 45 | 46 | Redistribution and use in source and binary forms, with or without 47 | modification, are permitted provided that the following conditions 48 | are met: 49 | 1. Redistributions of source code must retain the above copyright 50 | notice, this list of conditions and the following disclaimer 51 | in this position and unchanged. 52 | 2. Redistributions in binary form must reproduce the above copyright 53 | notice, this list of conditions and the following disclaimer in the 54 | documentation and/or other materials provided with the distribution. 55 | 56 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR 57 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 58 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 59 | IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, 60 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 61 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 62 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 63 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 64 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 65 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 66 | -------------------------------------------------------------------------------- /libarchive/archive_entry_copy_bhfi.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2003-2007 Tim Kientzle 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, 18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #include "archive_platform.h" 27 | __FBSDID("$FreeBSD$"); 28 | 29 | #include "archive_private.h" 30 | #include "archive_entry.h" 31 | 32 | #if defined(_WIN32) && !defined(__CYGWIN__) 33 | 34 | #define EPOC_TIME ARCHIVE_LITERAL_ULL(116444736000000000) 35 | 36 | __inline static void 37 | fileTimeToUtc(const FILETIME *filetime, time_t *t, long *ns) 38 | { 39 | ULARGE_INTEGER utc; 40 | 41 | utc.HighPart = filetime->dwHighDateTime; 42 | utc.LowPart = filetime->dwLowDateTime; 43 | if (utc.QuadPart >= EPOC_TIME) { 44 | utc.QuadPart -= EPOC_TIME; 45 | *t = (time_t)(utc.QuadPart / 10000000); /* milli seconds base */ 46 | *ns = (long)(utc.QuadPart % 10000000) * 100;/* nano seconds base */ 47 | } else { 48 | *t = 0; 49 | *ns = 0; 50 | } 51 | } 52 | 53 | void 54 | archive_entry_copy_bhfi(struct archive_entry *entry, 55 | BY_HANDLE_FILE_INFORMATION *bhfi) 56 | { 57 | time_t secs; 58 | long nsecs; 59 | 60 | fileTimeToUtc(&bhfi->ftLastAccessTime, &secs, &nsecs); 61 | archive_entry_set_atime(entry, secs, nsecs); 62 | fileTimeToUtc(&bhfi->ftLastWriteTime, &secs, &nsecs); 63 | archive_entry_set_mtime(entry, secs, nsecs); 64 | fileTimeToUtc(&bhfi->ftCreationTime, &secs, &nsecs); 65 | archive_entry_set_birthtime(entry, secs, nsecs); 66 | archive_entry_set_ctime(entry, secs, nsecs); 67 | archive_entry_set_dev(entry, bhfi->dwVolumeSerialNumber); 68 | archive_entry_set_ino64(entry, (((int64_t)bhfi->nFileIndexHigh) << 32) 69 | + bhfi->nFileIndexLow); 70 | archive_entry_set_nlink(entry, bhfi->nNumberOfLinks); 71 | archive_entry_set_size(entry, (((int64_t)bhfi->nFileSizeHigh) << 32) 72 | + bhfi->nFileSizeLow); 73 | /* archive_entry_set_mode(entry, st->st_mode); */ 74 | } 75 | #endif 76 | -------------------------------------------------------------------------------- /libarchive/archive_entry_strmode.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2003-2007 Tim Kientzle 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, 18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #include "archive_platform.h" 27 | __FBSDID("$FreeBSD: src/lib/libarchive/archive_entry_strmode.c,v 1.4 2008/06/15 05:14:01 kientzle Exp $"); 28 | 29 | #ifdef HAVE_SYS_STAT_H 30 | #include 31 | #endif 32 | #ifdef HAVE_STRING_H 33 | #include 34 | #endif 35 | 36 | #include "archive_entry.h" 37 | #include "archive_entry_private.h" 38 | 39 | const char * 40 | archive_entry_strmode(struct archive_entry *entry) 41 | { 42 | static const mode_t permbits[] = 43 | { 0400, 0200, 0100, 0040, 0020, 0010, 0004, 0002, 0001 }; 44 | char *bp = entry->strmode; 45 | mode_t mode; 46 | int i; 47 | 48 | /* Fill in a default string, then selectively override. */ 49 | strcpy(bp, "?rwxrwxrwx "); 50 | 51 | mode = archive_entry_mode(entry); 52 | switch (archive_entry_filetype(entry)) { 53 | case AE_IFREG: bp[0] = '-'; break; 54 | case AE_IFBLK: bp[0] = 'b'; break; 55 | case AE_IFCHR: bp[0] = 'c'; break; 56 | case AE_IFDIR: bp[0] = 'd'; break; 57 | case AE_IFLNK: bp[0] = 'l'; break; 58 | case AE_IFSOCK: bp[0] = 's'; break; 59 | case AE_IFIFO: bp[0] = 'p'; break; 60 | default: 61 | if (archive_entry_hardlink(entry) != NULL) { 62 | bp[0] = 'h'; 63 | break; 64 | } 65 | } 66 | 67 | for (i = 0; i < 9; i++) 68 | if (!(mode & permbits[i])) 69 | bp[i+1] = '-'; 70 | 71 | if (mode & S_ISUID) { 72 | if (mode & 0100) bp[3] = 's'; 73 | else bp[3] = 'S'; 74 | } 75 | if (mode & S_ISGID) { 76 | if (mode & 0010) bp[6] = 's'; 77 | else bp[6] = 'S'; 78 | } 79 | if (mode & S_ISVTX) { 80 | if (mode & 0001) bp[9] = 't'; 81 | else bp[9] = 'T'; 82 | } 83 | if (archive_entry_acl_types(entry) != 0) 84 | bp[10] = '+'; 85 | 86 | return (bp); 87 | } 88 | -------------------------------------------------------------------------------- /libarchive/archive_read_extract.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2003-2007 Tim Kientzle 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, 18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #include "archive_platform.h" 27 | __FBSDID("$FreeBSD: src/lib/libarchive/archive_read_extract.c,v 1.61 2008/05/26 17:00:22 kientzle Exp $"); 28 | 29 | #ifdef HAVE_ERRNO_H 30 | #include 31 | #endif 32 | 33 | #include "archive.h" 34 | #include "archive_entry.h" 35 | #include "archive_private.h" 36 | #include "archive_read_private.h" 37 | 38 | int 39 | archive_read_extract(struct archive *_a, struct archive_entry *entry, int flags) 40 | { 41 | struct archive_read_extract *extract; 42 | struct archive_read * a = (struct archive_read *)_a; 43 | 44 | extract = __archive_read_get_extract(a); 45 | if (extract == NULL) 46 | return (ARCHIVE_FATAL); 47 | 48 | /* If we haven't initialized the archive_write_disk object, do it now. */ 49 | if (extract->ad == NULL) { 50 | extract->ad = archive_write_disk_new(); 51 | if (extract->ad == NULL) { 52 | archive_set_error(&a->archive, ENOMEM, "Can't extract"); 53 | return (ARCHIVE_FATAL); 54 | } 55 | archive_write_disk_set_standard_lookup(extract->ad); 56 | } 57 | 58 | archive_write_disk_set_options(extract->ad, flags); 59 | return (archive_read_extract2(&a->archive, entry, extract->ad)); 60 | } 61 | -------------------------------------------------------------------------------- /libarchive/archive_read_support_filter_none.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2003-2007 Tim Kientzle 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, 18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #include "archive_platform.h" 27 | __FBSDID("$FreeBSD$"); 28 | 29 | #include "archive.h" 30 | #include "archive_private.h" 31 | 32 | #if ARCHIVE_VERSION_NUMBER < 4000000 33 | /* Deprecated; remove in libarchive 4.0 */ 34 | int 35 | archive_read_support_compression_none(struct archive *a) 36 | { 37 | return archive_read_support_filter_none(a); 38 | } 39 | #endif 40 | 41 | /* 42 | * Uncompressed streams are handled implicitly by the read core, 43 | * so this is now a no-op. 44 | */ 45 | int 46 | archive_read_support_filter_none(struct archive *a) 47 | { 48 | archive_check_magic(a, ARCHIVE_READ_MAGIC, 49 | ARCHIVE_STATE_NEW, "archive_read_support_filter_none"); 50 | 51 | return (ARCHIVE_OK); 52 | } 53 | -------------------------------------------------------------------------------- /libarchive/archive_read_support_format_by_code.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2003-2011 Tim Kientzle 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, 18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #include "archive_platform.h" 27 | __FBSDID("$FreeBSD$"); 28 | 29 | #include "archive.h" 30 | #include "archive_private.h" 31 | 32 | int 33 | archive_read_support_format_by_code(struct archive *a, int format_code) 34 | { 35 | archive_check_magic(a, ARCHIVE_READ_MAGIC, 36 | ARCHIVE_STATE_NEW, "archive_read_support_format_by_code"); 37 | 38 | switch (format_code & ARCHIVE_FORMAT_BASE_MASK) { 39 | case ARCHIVE_FORMAT_7ZIP: 40 | return archive_read_support_format_7zip(a); 41 | break; 42 | case ARCHIVE_FORMAT_AR: 43 | return archive_read_support_format_ar(a); 44 | break; 45 | case ARCHIVE_FORMAT_CAB: 46 | return archive_read_support_format_cab(a); 47 | break; 48 | case ARCHIVE_FORMAT_CPIO: 49 | return archive_read_support_format_cpio(a); 50 | break; 51 | case ARCHIVE_FORMAT_ISO9660: 52 | return archive_read_support_format_iso9660(a); 53 | break; 54 | case ARCHIVE_FORMAT_LHA: 55 | return archive_read_support_format_lha(a); 56 | break; 57 | case ARCHIVE_FORMAT_MTREE: 58 | return archive_read_support_format_mtree(a); 59 | break; 60 | case ARCHIVE_FORMAT_RAR: 61 | return archive_read_support_format_rar(a); 62 | break; 63 | case ARCHIVE_FORMAT_RAR_V5: 64 | return archive_read_support_format_rar5(a); 65 | break; 66 | case ARCHIVE_FORMAT_TAR: 67 | return archive_read_support_format_tar(a); 68 | break; 69 | case ARCHIVE_FORMAT_XAR: 70 | return archive_read_support_format_xar(a); 71 | break; 72 | case ARCHIVE_FORMAT_ZIP: 73 | return archive_read_support_format_zip(a); 74 | break; 75 | } 76 | return (ARCHIVE_FATAL); 77 | } 78 | -------------------------------------------------------------------------------- /libarchive/archive_read_support_format_empty.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2003-2007 Tim Kientzle 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, 18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #include "archive_platform.h" 27 | __FBSDID("$FreeBSD: head/lib/libarchive/archive_read_support_format_empty.c 191524 2009-04-26 18:24:14Z kientzle $"); 28 | 29 | #include "archive.h" 30 | #include "archive_entry.h" 31 | #include "archive_private.h" 32 | #include "archive_read_private.h" 33 | 34 | static int archive_read_format_empty_bid(struct archive_read *, int); 35 | static int archive_read_format_empty_read_data(struct archive_read *, 36 | const void **, size_t *, int64_t *); 37 | static int archive_read_format_empty_read_header(struct archive_read *, 38 | struct archive_entry *); 39 | int 40 | archive_read_support_format_empty(struct archive *_a) 41 | { 42 | struct archive_read *a = (struct archive_read *)_a; 43 | int r; 44 | 45 | archive_check_magic(_a, ARCHIVE_READ_MAGIC, 46 | ARCHIVE_STATE_NEW, "archive_read_support_format_empty"); 47 | 48 | r = __archive_read_register_format(a, 49 | NULL, 50 | NULL, 51 | archive_read_format_empty_bid, 52 | NULL, 53 | archive_read_format_empty_read_header, 54 | archive_read_format_empty_read_data, 55 | NULL, 56 | NULL, 57 | NULL, 58 | NULL, 59 | NULL); 60 | 61 | return (r); 62 | } 63 | 64 | 65 | static int 66 | archive_read_format_empty_bid(struct archive_read *a, int best_bid) 67 | { 68 | if (best_bid < 1 && __archive_read_ahead(a, 1, NULL) == NULL) 69 | return (1); 70 | return (-1); 71 | } 72 | 73 | static int 74 | archive_read_format_empty_read_header(struct archive_read *a, 75 | struct archive_entry *entry) 76 | { 77 | (void)a; /* UNUSED */ 78 | (void)entry; /* UNUSED */ 79 | 80 | a->archive.archive_format = ARCHIVE_FORMAT_EMPTY; 81 | a->archive.archive_format_name = "Empty file"; 82 | 83 | return (ARCHIVE_EOF); 84 | } 85 | 86 | static int 87 | archive_read_format_empty_read_data(struct archive_read *a, 88 | const void **buff, size_t *size, int64_t *offset) 89 | { 90 | (void)a; /* UNUSED */ 91 | (void)buff; /* UNUSED */ 92 | (void)size; /* UNUSED */ 93 | (void)offset; /* UNUSED */ 94 | 95 | return (ARCHIVE_EOF); 96 | } 97 | -------------------------------------------------------------------------------- /libarchive/archive_write_add_filter.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2012 Ondrej Holy 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, 18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #include "archive_platform.h" 27 | __FBSDID("$FreeBSD$"); 28 | 29 | #ifdef HAVE_SYS_TYPES_H 30 | #include 31 | #endif 32 | 33 | #ifdef HAVE_ERRNO_H 34 | #include 35 | #endif 36 | 37 | #include "archive.h" 38 | #include "archive_private.h" 39 | 40 | /* A table that maps filter codes to functions. */ 41 | static const 42 | struct { int code; int (*setter)(struct archive *); } codes[] = 43 | { 44 | { ARCHIVE_FILTER_NONE, archive_write_add_filter_none }, 45 | { ARCHIVE_FILTER_GZIP, archive_write_add_filter_gzip }, 46 | { ARCHIVE_FILTER_BZIP2, archive_write_add_filter_bzip2 }, 47 | { ARCHIVE_FILTER_COMPRESS, archive_write_add_filter_compress }, 48 | { ARCHIVE_FILTER_GRZIP, archive_write_add_filter_grzip }, 49 | { ARCHIVE_FILTER_LRZIP, archive_write_add_filter_lrzip }, 50 | { ARCHIVE_FILTER_LZ4, archive_write_add_filter_lz4 }, 51 | { ARCHIVE_FILTER_LZIP, archive_write_add_filter_lzip }, 52 | { ARCHIVE_FILTER_LZMA, archive_write_add_filter_lzma }, 53 | { ARCHIVE_FILTER_LZOP, archive_write_add_filter_lzip }, 54 | { ARCHIVE_FILTER_UU, archive_write_add_filter_uuencode }, 55 | { ARCHIVE_FILTER_XZ, archive_write_add_filter_xz }, 56 | { ARCHIVE_FILTER_ZSTD, archive_write_add_filter_zstd }, 57 | { -1, NULL } 58 | }; 59 | 60 | int 61 | archive_write_add_filter(struct archive *a, int code) 62 | { 63 | int i; 64 | 65 | for (i = 0; codes[i].code != -1; i++) { 66 | if (code == codes[i].code) 67 | return ((codes[i].setter)(a)); 68 | } 69 | 70 | archive_set_error(a, EINVAL, "No such filter"); 71 | return (ARCHIVE_FATAL); 72 | } 73 | -------------------------------------------------------------------------------- /libarchive/archive_write_add_filter_by_name.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2003-2007 Tim Kientzle 3 | * Copyright (c) 2012 Michihiro NAKAJIMA 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR 16 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 | * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, 19 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #include "archive_platform.h" 28 | __FBSDID("$FreeBSD$"); 29 | 30 | #ifdef HAVE_SYS_TYPES_H 31 | #include 32 | #endif 33 | 34 | #ifdef HAVE_ERRNO_H 35 | #include 36 | #endif 37 | #ifdef HAVE_STRING_H 38 | #include 39 | #endif 40 | 41 | #include "archive.h" 42 | #include "archive_private.h" 43 | 44 | /* A table that maps names to functions. */ 45 | static const 46 | struct { const char *name; int (*setter)(struct archive *); } names[] = 47 | { 48 | { "b64encode", archive_write_add_filter_b64encode }, 49 | { "bzip2", archive_write_add_filter_bzip2 }, 50 | { "compress", archive_write_add_filter_compress }, 51 | { "grzip", archive_write_add_filter_grzip }, 52 | { "gzip", archive_write_add_filter_gzip }, 53 | { "lrzip", archive_write_add_filter_lrzip }, 54 | { "lz4", archive_write_add_filter_lz4 }, 55 | { "lzip", archive_write_add_filter_lzip }, 56 | { "lzma", archive_write_add_filter_lzma }, 57 | { "lzop", archive_write_add_filter_lzop }, 58 | { "uuencode", archive_write_add_filter_uuencode }, 59 | { "xz", archive_write_add_filter_xz }, 60 | { "zstd", archive_write_add_filter_zstd }, 61 | { NULL, NULL } 62 | }; 63 | 64 | int 65 | archive_write_add_filter_by_name(struct archive *a, const char *name) 66 | { 67 | int i; 68 | 69 | for (i = 0; names[i].name != NULL; i++) { 70 | if (strcmp(name, names[i].name) == 0) 71 | return ((names[i].setter)(a)); 72 | } 73 | 74 | archive_set_error(a, EINVAL, "No such filter '%s'", name); 75 | a->state = ARCHIVE_STATE_FATAL; 76 | return (ARCHIVE_FATAL); 77 | } 78 | -------------------------------------------------------------------------------- /libarchive/archive_write_add_filter_none.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2003-2010 Tim Kientzle 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, 18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #include "archive_platform.h" 27 | __FBSDID("$FreeBSD: head/lib/libarchive/archive_write_set_compression_none.c 201080 2009-12-28 02:03:54Z kientzle $"); 28 | 29 | #include "archive.h" 30 | 31 | int 32 | archive_write_set_compression_none(struct archive *a) 33 | { 34 | (void)a; /* UNUSED */ 35 | return (ARCHIVE_OK); 36 | } 37 | 38 | int 39 | archive_write_add_filter_none(struct archive *a) 40 | { 41 | (void)a; /* UNUSED */ 42 | return (ARCHIVE_OK); 43 | } 44 | -------------------------------------------------------------------------------- /libarchive/archive_write_open_file.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2003-2007 Tim Kientzle 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, 18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #include "archive_platform.h" 27 | __FBSDID("$FreeBSD: src/lib/libarchive/archive_write_open_file.c,v 1.19 2007/01/09 08:05:56 kientzle Exp $"); 28 | 29 | #ifdef HAVE_SYS_STAT_H 30 | #include 31 | #endif 32 | #ifdef HAVE_ERRNO_H 33 | #include 34 | #endif 35 | #ifdef HAVE_FCNTL_H 36 | #include 37 | #endif 38 | #ifdef HAVE_STDLIB_H 39 | #include 40 | #endif 41 | #ifdef HAVE_STRING_H 42 | #include 43 | #endif 44 | #ifdef HAVE_UNISTD_H 45 | #include 46 | #endif 47 | 48 | #include "archive.h" 49 | 50 | struct write_FILE_data { 51 | FILE *f; 52 | }; 53 | 54 | static int file_close(struct archive *, void *); 55 | static int file_open(struct archive *, void *); 56 | static ssize_t file_write(struct archive *, void *, const void *buff, size_t); 57 | 58 | int 59 | archive_write_open_FILE(struct archive *a, FILE *f) 60 | { 61 | struct write_FILE_data *mine; 62 | 63 | mine = (struct write_FILE_data *)malloc(sizeof(*mine)); 64 | if (mine == NULL) { 65 | archive_set_error(a, ENOMEM, "No memory"); 66 | return (ARCHIVE_FATAL); 67 | } 68 | mine->f = f; 69 | return (archive_write_open(a, mine, 70 | file_open, file_write, file_close)); 71 | } 72 | 73 | static int 74 | file_open(struct archive *a, void *client_data) 75 | { 76 | (void)a; /* UNUSED */ 77 | (void)client_data; /* UNUSED */ 78 | 79 | return (ARCHIVE_OK); 80 | } 81 | 82 | static ssize_t 83 | file_write(struct archive *a, void *client_data, const void *buff, size_t length) 84 | { 85 | struct write_FILE_data *mine; 86 | size_t bytesWritten; 87 | 88 | mine = client_data; 89 | for (;;) { 90 | bytesWritten = fwrite(buff, 1, length, mine->f); 91 | if (bytesWritten <= 0) { 92 | if (errno == EINTR) 93 | continue; 94 | archive_set_error(a, errno, "Write error"); 95 | return (-1); 96 | } 97 | return (bytesWritten); 98 | } 99 | } 100 | 101 | static int 102 | file_close(struct archive *a, void *client_data) 103 | { 104 | struct write_FILE_data *mine = client_data; 105 | 106 | (void)a; /* UNUSED */ 107 | free(mine); 108 | return (ARCHIVE_OK); 109 | } 110 | -------------------------------------------------------------------------------- /libarchive/archive_write_set_passphrase.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2014 Michihiro NAKAJIMA 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, 18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #include "archive_platform.h" 27 | __FBSDID("$FreeBSD$"); 28 | 29 | #ifdef HAVE_ERRNO_H 30 | #include 31 | #endif 32 | #include "archive_write_private.h" 33 | 34 | int 35 | archive_write_set_passphrase(struct archive *_a, const char *p) 36 | { 37 | struct archive_write *a = (struct archive_write *)_a; 38 | 39 | archive_check_magic(_a, ARCHIVE_WRITE_MAGIC, ARCHIVE_STATE_NEW, 40 | "archive_write_set_passphrase"); 41 | 42 | if (p == NULL || p[0] == '\0') { 43 | archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, 44 | "Empty passphrase is unacceptable"); 45 | return (ARCHIVE_FAILED); 46 | } 47 | free(a->passphrase); 48 | a->passphrase = strdup(p); 49 | if (a->passphrase == NULL) { 50 | archive_set_error(&a->archive, ENOMEM, 51 | "Can't allocate data for passphrase"); 52 | return (ARCHIVE_FATAL); 53 | } 54 | return (ARCHIVE_OK); 55 | } 56 | 57 | 58 | int 59 | archive_write_set_passphrase_callback(struct archive *_a, void *client_data, 60 | archive_passphrase_callback *cb) 61 | { 62 | struct archive_write *a = (struct archive_write *)_a; 63 | 64 | archive_check_magic(_a, ARCHIVE_WRITE_MAGIC, ARCHIVE_STATE_NEW, 65 | "archive_write_set_passphrase_callback"); 66 | 67 | a->passphrase_callback = cb; 68 | a->passphrase_client_data = client_data; 69 | return (ARCHIVE_OK); 70 | } 71 | 72 | 73 | const char * 74 | __archive_write_get_passphrase(struct archive_write *a) 75 | { 76 | 77 | if (a->passphrase != NULL) 78 | return (a->passphrase); 79 | 80 | if (a->passphrase_callback != NULL) { 81 | const char *p; 82 | p = a->passphrase_callback(&a->archive, 83 | a->passphrase_client_data); 84 | if (p != NULL) { 85 | a->passphrase = strdup(p); 86 | if (a->passphrase == NULL) { 87 | archive_set_error(&a->archive, ENOMEM, 88 | "Can't allocate data for passphrase"); 89 | return (NULL); 90 | } 91 | return (a->passphrase); 92 | } 93 | } 94 | return (NULL); 95 | } 96 | -------------------------------------------------------------------------------- /libarchive/include/android/android_lf.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Macros for file64 functions 3 | * 4 | * Android does not support the macro _FILE_OFFSET_BITS=64 5 | * As of android-21 it does however support many file64 functions 6 | */ 7 | 8 | #ifndef ARCHIVE_ANDROID_LF_H_INCLUDED 9 | #define ARCHIVE_ANDROID_LF_H_INCLUDED 10 | 11 | #if __ANDROID_API__ > 20 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | //dirent.h 22 | #define readdir_r readdir64_r 23 | #define readdir readdir64 24 | #define dirent dirent64 25 | //fcntl.h 26 | #define openat openat64 27 | #define open open64 28 | #define mkstemp mkstemp64 29 | //unistd.h 30 | #define lseek lseek64 31 | #define ftruncate ftruncate64 32 | //sys/stat.h 33 | #define fstatat fstatat64 34 | #define fstat fstat64 35 | #define lstat lstat64 36 | #define stat stat64 37 | //sys/statvfs.h 38 | #define fstatvfs fstatvfs64 39 | #define statvfs statvfs64 40 | //sys/types.h 41 | #define off_t off64_t 42 | //sys/vfs.h 43 | #define fstatfs fstatfs64 44 | #define statfs statfs64 45 | #endif 46 | 47 | #endif /* ARCHIVE_ANDROID_LF_H_INCLUDED */ 48 | -------------------------------------------------------------------------------- /libarchive/include/archive_acl_private.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2003-2010 Tim Kientzle 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, 18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | * 25 | * $FreeBSD$ 26 | */ 27 | 28 | #ifndef ARCHIVE_ACL_PRIVATE_H_INCLUDED 29 | #define ARCHIVE_ACL_PRIVATE_H_INCLUDED 30 | 31 | #ifndef __LIBARCHIVE_BUILD 32 | #error This header is only to be used internally to libarchive. 33 | #endif 34 | 35 | #include "archive_string.h" 36 | 37 | struct archive_acl_entry { 38 | struct archive_acl_entry *next; 39 | int type; /* E.g., access or default */ 40 | int tag; /* E.g., user/group/other/mask */ 41 | int permset; /* r/w/x bits */ 42 | int id; /* uid/gid for user/group */ 43 | struct archive_mstring name; /* uname/gname */ 44 | }; 45 | 46 | struct archive_acl { 47 | mode_t mode; 48 | struct archive_acl_entry *acl_head; 49 | struct archive_acl_entry *acl_p; 50 | int acl_state; /* See acl_next for details. */ 51 | wchar_t *acl_text_w; 52 | char *acl_text; 53 | int acl_types; 54 | }; 55 | 56 | void archive_acl_clear(struct archive_acl *); 57 | void archive_acl_copy(struct archive_acl *, struct archive_acl *); 58 | int archive_acl_count(struct archive_acl *, int); 59 | int archive_acl_types(struct archive_acl *); 60 | int archive_acl_reset(struct archive_acl *, int); 61 | int archive_acl_next(struct archive *, struct archive_acl *, int, 62 | int *, int *, int *, int *, const char **); 63 | 64 | int archive_acl_add_entry(struct archive_acl *, int, int, int, int, const char *); 65 | int archive_acl_add_entry_w_len(struct archive_acl *, 66 | int, int, int, int, const wchar_t *, size_t); 67 | int archive_acl_add_entry_len(struct archive_acl *, 68 | int, int, int, int, const char *, size_t); 69 | 70 | wchar_t *archive_acl_to_text_w(struct archive_acl *, ssize_t *, int, 71 | struct archive *); 72 | char *archive_acl_to_text_l(struct archive_acl *, ssize_t *, int, 73 | struct archive_string_conv *); 74 | 75 | /* 76 | * ACL text parser. 77 | */ 78 | int archive_acl_from_text_w(struct archive_acl *, const wchar_t * /* wtext */, 79 | int /* type */); 80 | int archive_acl_from_text_l(struct archive_acl *, const char * /* text */, 81 | int /* type */, struct archive_string_conv *); 82 | 83 | #endif /* ARCHIVE_ENTRY_PRIVATE_H_INCLUDED */ 84 | -------------------------------------------------------------------------------- /libarchive/include/archive_cmdline_private.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2012 Michihiro NAKAJIMA 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, 18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | * 25 | * $FreeBSD$ 26 | */ 27 | 28 | #ifndef ARCHIVE_CMDLINE_PRIVATE_H 29 | #define ARCHIVE_CMDLINE_PRIVATE_H 30 | 31 | #ifndef __LIBARCHIVE_BUILD 32 | #ifndef __LIBARCHIVE_TEST 33 | #error This header is only to be used internally to libarchive. 34 | #endif 35 | #endif 36 | 37 | struct archive_cmdline { 38 | char *path; 39 | char **argv; 40 | int argc; 41 | }; 42 | 43 | struct archive_cmdline *__archive_cmdline_allocate(void); 44 | int __archive_cmdline_parse(struct archive_cmdline *, const char *); 45 | int __archive_cmdline_free(struct archive_cmdline *); 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /libarchive/include/archive_crc32.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2009 Joerg Sonnenberger 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, 18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | * 25 | * $FreeBSD: head/lib/libarchive/archive_crc32.h 201102 2009-12-28 03:11:36Z kientzle $ 26 | */ 27 | 28 | #ifndef ARCHIVE_CRC32_H 29 | #define ARCHIVE_CRC32_H 30 | 31 | #ifndef __LIBARCHIVE_BUILD 32 | #error This header is only to be used internally to libarchive. 33 | #endif 34 | 35 | /* 36 | * When zlib is unavailable, we should still be able to validate 37 | * uncompressed zip archives. That requires us to be able to compute 38 | * the CRC32 check value. This is a drop-in compatible replacement 39 | * for crc32() from zlib. It's slower than the zlib implementation, 40 | * but still pretty fast: This runs about 300MB/s on my 3GHz P4 41 | * compared to about 800MB/s for the zlib implementation. 42 | */ 43 | static unsigned long 44 | crc32(unsigned long crc, const void *_p, size_t len) 45 | { 46 | unsigned long crc2, b, i; 47 | const unsigned char *p = _p; 48 | static volatile int crc_tbl_inited = 0; 49 | static unsigned long crc_tbl[256]; 50 | 51 | if (!crc_tbl_inited) { 52 | for (b = 0; b < 256; ++b) { 53 | crc2 = b; 54 | for (i = 8; i > 0; --i) { 55 | if (crc2 & 1) 56 | crc2 = (crc2 >> 1) ^ 0xedb88320UL; 57 | else 58 | crc2 = (crc2 >> 1); 59 | } 60 | crc_tbl[b] = crc2; 61 | } 62 | crc_tbl_inited = 1; 63 | } 64 | 65 | crc = crc ^ 0xffffffffUL; 66 | /* A use of this loop is about 20% - 30% faster than 67 | * no use version in any optimization option of gcc. */ 68 | for (;len >= 8; len -= 8) { 69 | crc = crc_tbl[(crc ^ *p++) & 0xff] ^ (crc >> 8); 70 | crc = crc_tbl[(crc ^ *p++) & 0xff] ^ (crc >> 8); 71 | crc = crc_tbl[(crc ^ *p++) & 0xff] ^ (crc >> 8); 72 | crc = crc_tbl[(crc ^ *p++) & 0xff] ^ (crc >> 8); 73 | crc = crc_tbl[(crc ^ *p++) & 0xff] ^ (crc >> 8); 74 | crc = crc_tbl[(crc ^ *p++) & 0xff] ^ (crc >> 8); 75 | crc = crc_tbl[(crc ^ *p++) & 0xff] ^ (crc >> 8); 76 | crc = crc_tbl[(crc ^ *p++) & 0xff] ^ (crc >> 8); 77 | } 78 | while (len--) 79 | crc = crc_tbl[(crc ^ *p++) & 0xff] ^ (crc >> 8); 80 | return (crc ^ 0xffffffffUL); 81 | } 82 | 83 | #endif 84 | -------------------------------------------------------------------------------- /libarchive/include/archive_getdate.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2003-2015 Tim Kientzle 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, 18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | * 25 | * $FreeBSD$ 26 | */ 27 | 28 | #ifndef ARCHIVE_GETDATE_H_INCLUDED 29 | #define ARCHIVE_GETDATE_H_INCLUDED 30 | 31 | #ifndef __LIBARCHIVE_BUILD 32 | #error This header is only to be used internally to libarchive. 33 | #endif 34 | 35 | #include 36 | 37 | time_t __archive_get_date(time_t now, const char *); 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /libarchive/include/archive_openssl_evp_private.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2003-2007 Tim Kientzle 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, 18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #ifndef ARCHIVE_OPENSSL_EVP_PRIVATE_H_INCLUDED 27 | #define ARCHIVE_OPENSSL_EVP_PRIVATE_H_INCLUDED 28 | 29 | #ifndef __LIBARCHIVE_BUILD 30 | #error This header is only to be used internally to libarchive. 31 | #endif 32 | 33 | #include 34 | #include 35 | 36 | #if OPENSSL_VERSION_NUMBER < 0x10100000L 37 | #include /* malloc, free */ 38 | #include /* memset */ 39 | static inline EVP_MD_CTX *EVP_MD_CTX_new(void) 40 | { 41 | EVP_MD_CTX *ctx = (EVP_MD_CTX *)calloc(1, sizeof(EVP_MD_CTX)); 42 | return ctx; 43 | } 44 | 45 | static inline void EVP_MD_CTX_free(EVP_MD_CTX *ctx) 46 | { 47 | EVP_MD_CTX_cleanup(ctx); 48 | memset(ctx, 0, sizeof(*ctx)); 49 | free(ctx); 50 | } 51 | #endif 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /libarchive/include/archive_openssl_hmac_private.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2003-2007 Tim Kientzle 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, 18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #ifndef ARCHIVE_OPENSSL_HMAC_PRIVATE_H_INCLUDED 27 | #define ARCHIVE_OPENSSL_HMAC_PRIVATE_H_INCLUDED 28 | 29 | #ifndef __LIBARCHIVE_BUILD 30 | #error This header is only to be used internally to libarchive. 31 | #endif 32 | 33 | #include 34 | #include 35 | 36 | #if OPENSSL_VERSION_NUMBER < 0x10100000L || \ 37 | (defined(LIBRESSL_VERSION_NUMBER) && LIBRESSL_VERSION_NUMBER < 0x20700000L) 38 | #include /* malloc, free */ 39 | #include /* memset */ 40 | static inline HMAC_CTX *HMAC_CTX_new(void) 41 | { 42 | HMAC_CTX *ctx = (HMAC_CTX *)calloc(1, sizeof(HMAC_CTX)); 43 | return ctx; 44 | } 45 | 46 | static inline void HMAC_CTX_free(HMAC_CTX *ctx) 47 | { 48 | HMAC_CTX_cleanup(ctx); 49 | memset(ctx, 0, sizeof(*ctx)); 50 | free(ctx); 51 | } 52 | #endif 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /libarchive/include/archive_options_private.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2011 Tim Kientzle 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, 18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #ifndef ARCHIVE_OPTIONS_PRIVATE_H_INCLUDED 27 | #define ARCHIVE_OPTIONS_PRIVATE_H_INCLUDED 28 | 29 | #include "archive_platform.h" 30 | __FBSDID("$FreeBSD$"); 31 | 32 | #include "archive_private.h" 33 | 34 | typedef int (*option_handler)(struct archive *a, 35 | const char *mod, const char *opt, const char *val); 36 | 37 | int 38 | _archive_set_option(struct archive *a, 39 | const char *mod, const char *opt, const char *val, 40 | int magic, const char *fn, option_handler use_option); 41 | 42 | int 43 | _archive_set_options(struct archive *a, const char *options, 44 | int magic, const char *fn, option_handler use_option); 45 | 46 | int 47 | _archive_set_either_option(struct archive *a, 48 | const char *m, const char *o, const char *v, 49 | option_handler use_format_option, option_handler use_filter_option); 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /libarchive/include/archive_pack_dev.h: -------------------------------------------------------------------------------- 1 | /* $NetBSD: pack_dev.h,v 1.8 2013/06/14 16:28:20 tsutsui Exp $ */ 2 | 3 | /*- 4 | * Copyright (c) 1998, 2001 The NetBSD Foundation, Inc. 5 | * All rights reserved. 6 | * 7 | * This code is derived from software contributed to The NetBSD Foundation 8 | * by Charles M. Hannum. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | /* Originally from NetBSD's mknod(8) source. */ 33 | 34 | #ifndef ARCHIVE_PACK_DEV_H 35 | #define ARCHIVE_PACK_DEV_H 36 | 37 | typedef dev_t pack_t(int, unsigned long [], const char **); 38 | 39 | pack_t *pack_find(const char *); 40 | pack_t pack_native; 41 | 42 | #define major_netbsd(x) ((int32_t)((((x) & 0x000fff00) >> 8))) 43 | #define minor_netbsd(x) ((int32_t)((((x) & 0xfff00000) >> 12) | \ 44 | (((x) & 0x000000ff) >> 0))) 45 | #define makedev_netbsd(x,y) ((dev_t)((((x) << 8) & 0x000fff00) | \ 46 | (((y) << 12) & 0xfff00000) | \ 47 | (((y) << 0) & 0x000000ff))) 48 | 49 | #endif /* ARCHIVE_PACK_DEV_H */ 50 | -------------------------------------------------------------------------------- /libarchive/include/archive_pathmatch.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2003-2007 Tim Kientzle 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer 10 | * in this position and unchanged. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR 16 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 | * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, 19 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | * 26 | * $FreeBSD$ 27 | */ 28 | 29 | #ifndef ARCHIVE_PATHMATCH_H 30 | #define ARCHIVE_PATHMATCH_H 31 | 32 | #ifndef __LIBARCHIVE_BUILD 33 | #ifndef __LIBARCHIVE_TEST 34 | #error This header is only to be used internally to libarchive. 35 | #endif 36 | #endif 37 | 38 | /* Don't anchor at beginning unless the pattern starts with "^" */ 39 | #define PATHMATCH_NO_ANCHOR_START 1 40 | /* Don't anchor at end unless the pattern ends with "$" */ 41 | #define PATHMATCH_NO_ANCHOR_END 2 42 | 43 | /* Note that "^" and "$" are not special unless you set the corresponding 44 | * flag above. */ 45 | 46 | int __archive_pathmatch(const char *p, const char *s, int flags); 47 | int __archive_pathmatch_w(const wchar_t *p, const wchar_t *s, int flags); 48 | 49 | #define archive_pathmatch(p, s, f) __archive_pathmatch(p, s, f) 50 | #define archive_pathmatch_w(p, s, f) __archive_pathmatch_w(p, s, f) 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /libarchive/include/archive_platform_acl.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2017 Martin Matuska 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, 18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | * 25 | * $FreeBSD$ 26 | */ 27 | 28 | /* !!ONLY FOR USE INTERNALLY TO LIBARCHIVE!! */ 29 | 30 | #ifndef ARCHIVE_PLATFORM_ACL_H_INCLUDED 31 | #define ARCHIVE_PLATFORM_ACL_H_INCLUDED 32 | 33 | #ifndef __LIBARCHIVE_BUILD 34 | #ifndef __LIBARCHIVE_TEST_COMMON 35 | #error This header is only to be used internally to libarchive. 36 | #endif 37 | #endif 38 | 39 | /* 40 | * Determine what ACL types are supported 41 | */ 42 | #if ARCHIVE_ACL_FREEBSD || ARCHIVE_ACL_SUNOS || ARCHIVE_ACL_LIBACL 43 | #define ARCHIVE_ACL_POSIX1E 1 44 | #endif 45 | 46 | #if ARCHIVE_ACL_FREEBSD_NFS4 || ARCHIVE_ACL_SUNOS_NFS4 || \ 47 | ARCHIVE_ACL_DARWIN || ARCHIVE_ACL_LIBRICHACL 48 | #define ARCHIVE_ACL_NFS4 1 49 | #endif 50 | 51 | #if ARCHIVE_ACL_POSIX1E || ARCHIVE_ACL_NFS4 52 | #define ARCHIVE_ACL_SUPPORT 1 53 | #endif 54 | 55 | #endif /* ARCHIVE_PLATFORM_ACL_H_INCLUDED */ 56 | -------------------------------------------------------------------------------- /libarchive/include/archive_platform_xattr.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2017 Martin Matuska 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, 18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | * 25 | * $FreeBSD$ 26 | */ 27 | 28 | /* !!ONLY FOR USE INTERNALLY TO LIBARCHIVE!! */ 29 | 30 | #ifndef ARCHIVE_PLATFORM_XATTR_H_INCLUDED 31 | #define ARCHIVE_PLATFORM_XATTR_H_INCLUDED 32 | 33 | #ifndef __LIBARCHIVE_BUILD 34 | #ifndef __LIBARCHIVE_TEST_COMMON 35 | #error This header is only to be used internally to libarchive. 36 | #endif 37 | #endif 38 | 39 | /* 40 | * Determine if we support extended attributes 41 | */ 42 | #if ARCHIVE_XATTR_LINUX || ARCHIVE_XATTR_DARWIN || ARCHIVE_XATTR_FREEBSD || \ 43 | ARCHIVE_XATTR_AIX 44 | #define ARCHIVE_XATTR_SUPPORT 1 45 | #endif 46 | 47 | #endif /* ARCHIVE_PLATFORM_XATTR_H_INCLUDED */ 48 | -------------------------------------------------------------------------------- /libarchive/include/archive_ppmd7_private.h: -------------------------------------------------------------------------------- 1 | /* Ppmd7.h -- PPMdH compression codec 2 | 2010-03-12 : Igor Pavlov : Public domain 3 | This code is based on PPMd var.H (2001): Dmitry Shkarin : Public domain */ 4 | 5 | /* This code supports virtual RangeDecoder and includes the implementation 6 | of RangeCoder from 7z, instead of RangeCoder from original PPMd var.H. 7 | If you need the compatibility with original PPMd var.H, you can use external RangeDecoder */ 8 | 9 | #ifndef ARCHIVE_PPMD7_PRIVATE_H_INCLUDED 10 | #define ARCHIVE_PPMD7_PRIVATE_H_INCLUDED 11 | 12 | #ifndef __LIBARCHIVE_BUILD 13 | #error This header is only to be used internally to libarchive. 14 | #endif 15 | 16 | #include "archive_ppmd_private.h" 17 | 18 | #define PPMD7_MIN_ORDER 2 19 | #define PPMD7_MAX_ORDER 64 20 | 21 | #define PPMD7_MIN_MEM_SIZE (1 << 11) 22 | #define PPMD7_MAX_MEM_SIZE (0xFFFFFFFFu - 12 * 3) 23 | 24 | struct CPpmd7_Context_; 25 | 26 | typedef 27 | #ifdef PPMD_32BIT 28 | struct CPpmd7_Context_ * 29 | #else 30 | UInt32 31 | #endif 32 | CPpmd7_Context_Ref; 33 | 34 | typedef struct CPpmd7_Context_ 35 | { 36 | UInt16 NumStats; 37 | UInt16 SummFreq; 38 | CPpmd_State_Ref Stats; 39 | CPpmd7_Context_Ref Suffix; 40 | } CPpmd7_Context; 41 | 42 | #define Ppmd7Context_OneState(p) ((CPpmd_State *)&(p)->SummFreq) 43 | 44 | typedef struct 45 | { 46 | CPpmd7_Context *MinContext, *MaxContext; 47 | CPpmd_State *FoundState; 48 | unsigned OrderFall, InitEsc, PrevSuccess, MaxOrder, HiBitsFlag; 49 | Int32 RunLength, InitRL; /* must be 32-bit at least */ 50 | 51 | UInt32 Size; 52 | UInt32 GlueCount; 53 | Byte *Base, *LoUnit, *HiUnit, *Text, *UnitsStart; 54 | UInt32 AlignOffset; 55 | 56 | Byte Indx2Units[PPMD_NUM_INDEXES]; 57 | Byte Units2Indx[128]; 58 | CPpmd_Void_Ref FreeList[PPMD_NUM_INDEXES]; 59 | Byte NS2Indx[256], NS2BSIndx[256], HB2Flag[256]; 60 | CPpmd_See DummySee, See[25][16]; 61 | UInt16 BinSumm[128][64]; 62 | } CPpmd7; 63 | 64 | /* ---------- Decode ---------- */ 65 | 66 | typedef struct 67 | { 68 | UInt32 (*GetThreshold)(void *p, UInt32 total); 69 | void (*Decode)(void *p, UInt32 start, UInt32 size); 70 | UInt32 (*DecodeBit)(void *p, UInt32 size0); 71 | } IPpmd7_RangeDec; 72 | 73 | typedef struct 74 | { 75 | IPpmd7_RangeDec p; 76 | UInt32 Range; 77 | UInt32 Code; 78 | UInt32 Low; 79 | UInt32 Bottom; 80 | IByteIn *Stream; 81 | } CPpmd7z_RangeDec; 82 | 83 | /* ---------- Encode ---------- */ 84 | 85 | typedef struct 86 | { 87 | UInt64 Low; 88 | UInt32 Range; 89 | Byte Cache; 90 | UInt64 CacheSize; 91 | IByteOut *Stream; 92 | } CPpmd7z_RangeEnc; 93 | 94 | typedef struct 95 | { 96 | /* Base Functions */ 97 | void (*Ppmd7_Construct)(CPpmd7 *p); 98 | Bool (*Ppmd7_Alloc)(CPpmd7 *p, UInt32 size); 99 | void (*Ppmd7_Free)(CPpmd7 *p); 100 | void (*Ppmd7_Init)(CPpmd7 *p, unsigned maxOrder); 101 | #define Ppmd7_WasAllocated(p) ((p)->Base != NULL) 102 | 103 | /* Decode Functions */ 104 | void (*Ppmd7z_RangeDec_CreateVTable)(CPpmd7z_RangeDec *p); 105 | void (*PpmdRAR_RangeDec_CreateVTable)(CPpmd7z_RangeDec *p); 106 | Bool (*Ppmd7z_RangeDec_Init)(CPpmd7z_RangeDec *p); 107 | Bool (*PpmdRAR_RangeDec_Init)(CPpmd7z_RangeDec *p); 108 | #define Ppmd7z_RangeDec_IsFinishedOK(p) ((p)->Code == 0) 109 | int (*Ppmd7_DecodeSymbol)(CPpmd7 *p, IPpmd7_RangeDec *rc); 110 | 111 | /* Encode Functions */ 112 | void (*Ppmd7z_RangeEnc_Init)(CPpmd7z_RangeEnc *p); 113 | void (*Ppmd7z_RangeEnc_FlushData)(CPpmd7z_RangeEnc *p); 114 | 115 | void (*Ppmd7_EncodeSymbol)(CPpmd7 *p, CPpmd7z_RangeEnc *rc, int symbol); 116 | } IPpmd7; 117 | 118 | extern const IPpmd7 __archive_ppmd7_functions; 119 | #endif 120 | -------------------------------------------------------------------------------- /libarchive/include/archive_random_private.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2014 Michihiro NAKAJIMA 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, 18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #ifndef ARCHIVE_RANDOM_PRIVATE_H_INCLUDED 27 | #define ARCHIVE_RANDOM_PRIVATE_H_INCLUDED 28 | 29 | #ifndef __LIBARCHIVE_BUILD 30 | #error This header is only to be used internally to libarchive. 31 | #endif 32 | 33 | /* Random number generator. */ 34 | int archive_random(void *buf, size_t nbytes); 35 | 36 | #endif /* ARCHIVE_RANDOM_PRIVATE_H_INCLUDED */ 37 | -------------------------------------------------------------------------------- /libarchive/include/archive_write_disk_private.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2003-2007 Tim Kientzle 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer 10 | * in this position and unchanged. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR 16 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 | * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, 19 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | * 26 | * $FreeBSD: head/lib/libarchive/archive_write_disk_private.h 201086 2009-12-28 02:17:53Z kientzle $ 27 | */ 28 | 29 | #ifndef ARCHIVE_WRITE_DISK_PRIVATE_H_INCLUDED 30 | #define ARCHIVE_WRITE_DISK_PRIVATE_H_INCLUDED 31 | 32 | #ifndef __LIBARCHIVE_BUILD 33 | #error This header is only to be used internally to libarchive. 34 | #endif 35 | 36 | #include "archive_platform_acl.h" 37 | #include "archive_acl_private.h" 38 | #include "archive_entry.h" 39 | 40 | struct archive_write_disk; 41 | 42 | int archive_write_disk_set_acls(struct archive *, int, const char *, 43 | struct archive_acl *, __LA_MODE_T); 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /libarchive/include/archive_write_set_format_private.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2020 Martin Matuska 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, 18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | * 25 | * $FreeBSD$ 26 | */ 27 | 28 | #ifndef ARCHIVE_WRITE_SET_FORMAT_PRIVATE_H_INCLUDED 29 | #define ARCHIVE_WRITE_SET_FORMAT_PRIVATE_H_INCLUDED 30 | 31 | #ifndef __LIBARCHIVE_BUILD 32 | #ifndef __LIBARCHIVE_TEST 33 | #error This header is only to be used internally to libarchive. 34 | #endif 35 | #endif 36 | 37 | #include "archive.h" 38 | #include "archive_entry.h" 39 | 40 | void __archive_write_entry_filetype_unsupported(struct archive *a, 41 | struct archive_entry *entry, const char *format); 42 | #endif 43 | -------------------------------------------------------------------------------- /libarchive/include/archive_xxhash.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2014 Michihiro NAKAJIMA 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, 18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | * 25 | */ 26 | 27 | #ifndef ARCHIVE_XXHASH_H_INCLUDED 28 | #define ARCHIVE_XXHASH_H_INCLUDED 29 | 30 | #ifndef __LIBARCHIVE_BUILD 31 | #error This header is only to be used internally to libarchive. 32 | #endif 33 | 34 | 35 | typedef enum { XXH_OK=0, XXH_ERROR } XXH_errorcode; 36 | 37 | struct archive_xxhash { 38 | unsigned int (*XXH32)(const void* input, unsigned int len, 39 | unsigned int seed); 40 | void* (*XXH32_init)(unsigned int seed); 41 | XXH_errorcode (*XXH32_update)(void* state, const void* input, 42 | unsigned int len); 43 | unsigned int (*XXH32_digest)(void* state); 44 | }; 45 | 46 | extern const struct archive_xxhash __archive_xxhash; 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /libarchive/include/fe/err.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2009 Joerg Sonnenberger 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, 18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #ifndef LAFE_ERR_H 27 | #define LAFE_ERR_H 28 | 29 | #if defined(__GNUC__) && (__GNUC__ > 2 || \ 30 | (__GNUC__ == 2 && __GNUC_MINOR__ >= 5)) 31 | #define __LA_DEAD __attribute__((__noreturn__)) 32 | #else 33 | #define __LA_DEAD 34 | #endif 35 | 36 | #if defined(__GNUC__) && (__GNUC__ > 2 || \ 37 | (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)) 38 | # ifdef __MINGW_PRINTF_FORMAT 39 | # define __LA_PRINTF_FORMAT __MINGW_PRINTF_FORMAT 40 | # else 41 | # define __LA_PRINTF_FORMAT __printf__ 42 | # endif 43 | # define __LA_PRINTFLIKE(f,a) __attribute__((__format__(__LA_PRINTF_FORMAT, f, a))) 44 | #else 45 | # define __LA_PRINTFLIKE(f,a) 46 | #endif 47 | 48 | void lafe_warnc(int code, const char *fmt, ...) __LA_PRINTFLIKE(2, 3); 49 | void lafe_errc(int eval, int code, const char *fmt, ...) __LA_DEAD 50 | __LA_PRINTFLIKE(3, 4); 51 | 52 | const char * lafe_getprogname(void); 53 | void lafe_setprogname(const char *name, const char *defaultname); 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /libarchive/include/fe/lafe_platform.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2003-2007 Tim Kientzle 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, 18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | * 25 | * $FreeBSD: src/usr.bin/cpio/cpio_platform.h,v 1.2 2008/12/06 07:15:42 kientzle Exp $ 26 | */ 27 | 28 | /* 29 | * This header is the first thing included in any of the libarchive_fe 30 | * source files. As far as possible, platform-specific issues should 31 | * be dealt with here and not within individual source files. 32 | */ 33 | 34 | #ifndef LAFE_PLATFORM_H_INCLUDED 35 | #define LAFE_PLATFORM_H_INCLUDED 36 | 37 | #if defined(PLATFORM_CONFIG_H) 38 | /* Use hand-built config.h in environments that need it. */ 39 | #include PLATFORM_CONFIG_H 40 | #else 41 | /* Read config.h or die trying. */ 42 | #include "config.h" 43 | #endif 44 | 45 | /* Get a real definition for __FBSDID if we can */ 46 | #if HAVE_SYS_CDEFS_H 47 | #include 48 | #endif 49 | 50 | /* If not, define it so as to avoid dangling semicolons. */ 51 | #ifndef __FBSDID 52 | #define __FBSDID(a) struct _undefined_hack 53 | #endif 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /libarchive/include/fe/line_reader.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2009 Joerg Sonnenberger 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, 18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #ifndef LAFE_LINE_READER_H 27 | #define LAFE_LINE_READER_H 28 | 29 | struct lafe_line_reader; 30 | 31 | struct lafe_line_reader *lafe_line_reader(const char *, int nullSeparator); 32 | const char *lafe_line_reader_next(struct lafe_line_reader *); 33 | void lafe_line_reader_free(struct lafe_line_reader *); 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /libarchive/include/fe/passphrase.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2014 Michihiro NAKAJIMA 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, 18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #ifndef LAFE_PASSPHRASE_H 27 | #define LAFE_PASSPHRASE_H 28 | 29 | char *lafe_readpassphrase(const char *prompt, char *buf, size_t bufsiz); 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /libarchive/include/filter_fork.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2007 Joerg Sonnenberger 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 | * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, 18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | * 25 | * $FreeBSD: head/lib/libarchive/filter_fork.h 201087 2009-12-28 02:18:26Z kientzle $ 26 | */ 27 | 28 | #ifndef FILTER_FORK_H 29 | #define FILTER_FORK_H 30 | 31 | #ifndef __LIBARCHIVE_BUILD 32 | #error This header is only to be used internally to libarchive. 33 | #endif 34 | 35 | int 36 | __archive_create_child(const char *cmd, int *child_stdin, int *child_stdout, 37 | #if defined(_WIN32) && !defined(__CYGWIN__) 38 | HANDLE *out_child); 39 | #else 40 | pid_t *out_child); 41 | #endif 42 | 43 | void 44 | __archive_check_child(int in, int out); 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /libdtc/fstree.c: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright David Gibson , IBM Corporation. 2005. 3 | * 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License as 7 | * published by the Free Software Foundation; either version 2 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 18 | * USA 19 | */ 20 | 21 | #include "dtc.h" 22 | 23 | #include 24 | #include 25 | 26 | static struct node *read_fstree(const char *dirname) 27 | { 28 | DIR *d; 29 | struct dirent *de; 30 | struct stat st; 31 | struct node *tree; 32 | 33 | d = opendir(dirname); 34 | if (!d) 35 | die("Couldn't opendir() \"%s\": %s\n", dirname, strerror(errno)); 36 | 37 | tree = build_node(NULL, NULL); 38 | 39 | while ((de = readdir(d)) != NULL) { 40 | char *tmpname; 41 | 42 | if (streq(de->d_name, ".") 43 | || streq(de->d_name, "..")) 44 | continue; 45 | 46 | tmpname = join_path(dirname, de->d_name); 47 | 48 | if (lstat(tmpname, &st) < 0) 49 | die("stat(%s): %s\n", tmpname, strerror(errno)); 50 | 51 | if (S_ISREG(st.st_mode)) { 52 | struct property *prop; 53 | FILE *pfile; 54 | 55 | pfile = fopen(tmpname, "rb"); 56 | if (! pfile) { 57 | fprintf(stderr, 58 | "WARNING: Cannot open %s: %s\n", 59 | tmpname, strerror(errno)); 60 | } else { 61 | prop = build_property(xstrdup(de->d_name), 62 | data_copy_file(pfile, 63 | st.st_size)); 64 | add_property(tree, prop); 65 | fclose(pfile); 66 | } 67 | } else if (S_ISDIR(st.st_mode)) { 68 | struct node *newchild; 69 | 70 | newchild = read_fstree(tmpname); 71 | newchild = name_node(newchild, xstrdup(de->d_name)); 72 | add_child(tree, newchild); 73 | } 74 | 75 | free(tmpname); 76 | } 77 | 78 | closedir(d); 79 | return tree; 80 | } 81 | 82 | struct dt_info *dt_from_fs(const char *dirname) 83 | { 84 | struct node *tree; 85 | 86 | tree = read_fstree(dirname); 87 | tree = name_node(tree, ""); 88 | 89 | return build_dt_info(DTSF_V1, NULL, tree, guess_boot_cpuid(tree)); 90 | } 91 | -------------------------------------------------------------------------------- /libdtc/version.h: -------------------------------------------------------------------------------- 1 | #define DTC_VERSION "DTC 1.4.4" 2 | -------------------------------------------------------------------------------- /libsepol/av_permissions.h: -------------------------------------------------------------------------------- 1 | /* Used by security_compute_av. */ 2 | #define PROCESS__TRANSITION 0x00000002UL 3 | #define PROCESS__DYNTRANSITION 0x00800000UL 4 | -------------------------------------------------------------------------------- /libsepol/boolean_internal.h: -------------------------------------------------------------------------------- 1 | #ifndef _SEPOL_BOOLEAN_INTERNAL_H_ 2 | #define _SEPOL_BOOLEAN_INTERNAL_H_ 3 | 4 | #include 5 | #include 6 | #include "dso.h" 7 | 8 | hidden_proto(sepol_bool_key_create) 9 | hidden_proto(sepol_bool_key_unpack) 10 | hidden_proto(sepol_bool_get_name) 11 | hidden_proto(sepol_bool_set_name) 12 | hidden_proto(sepol_bool_get_value) 13 | hidden_proto(sepol_bool_set_value) 14 | hidden_proto(sepol_bool_create) 15 | hidden_proto(sepol_bool_free) 16 | #endif 17 | -------------------------------------------------------------------------------- /libsepol/constraint.c: -------------------------------------------------------------------------------- 1 | /* Authors: Jason Tang 2 | * 3 | * Copyright (C) 2005 Tresys Technology, LLC 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #include 26 | #include 27 | 28 | int constraint_expr_init(constraint_expr_t * expr) 29 | { 30 | memset(expr, 0, sizeof(*expr)); 31 | ebitmap_init(&expr->names); 32 | if ((expr->type_names = malloc(sizeof(*expr->type_names))) == NULL) { 33 | return -1; 34 | } 35 | type_set_init(expr->type_names); 36 | return 0; 37 | } 38 | 39 | void constraint_expr_destroy(constraint_expr_t * expr) 40 | { 41 | if (expr != NULL) { 42 | ebitmap_destroy(&expr->names); 43 | type_set_destroy(expr->type_names); 44 | free(expr->type_names); 45 | free(expr); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /libsepol/context.h: -------------------------------------------------------------------------------- 1 | #ifndef _SEPOL_INTERNAL_CONTEXT_H_ 2 | #define _SEPOL_INTERNAL_CONTEXT_H_ 3 | 4 | #include 5 | #include "context_internal.h" 6 | #include 7 | #include 8 | #include 9 | 10 | /* Create a context structure from high level representation */ 11 | extern int context_from_record(sepol_handle_t * handle, 12 | const policydb_t * policydb, 13 | context_struct_t ** cptr, 14 | const sepol_context_t * data); 15 | 16 | extern int context_to_record(sepol_handle_t * handle, 17 | const policydb_t * policydb, 18 | const context_struct_t * context, 19 | sepol_context_t ** record); 20 | 21 | /* Create a context structure from string representation */ 22 | extern int context_from_string(sepol_handle_t * handle, 23 | const policydb_t * policydb, 24 | context_struct_t ** cptr, 25 | const char *con_str, size_t con_str_len); 26 | 27 | /* Check if the provided context is valid for this policy */ 28 | extern int context_is_valid(const policydb_t * policydb, 29 | const context_struct_t * context); 30 | 31 | /* Extract the context as string */ 32 | extern int context_to_string(sepol_handle_t * handle, 33 | const policydb_t * policydb, 34 | const context_struct_t * context, 35 | char **result, size_t * result_len); 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /libsepol/context_internal.h: -------------------------------------------------------------------------------- 1 | #ifndef _SEPOL_CONTEXT_INTERNAL_H_ 2 | #define _SEPOL_CONTEXT_INTERNAL_H_ 3 | 4 | #include 5 | #include "dso.h" 6 | 7 | hidden_proto(sepol_context_clone) 8 | hidden_proto(sepol_context_create) 9 | hidden_proto(sepol_context_free) 10 | hidden_proto(sepol_context_from_string) 11 | hidden_proto(sepol_context_get_mls) 12 | hidden_proto(sepol_context_get_role) 13 | hidden_proto(sepol_context_get_type) 14 | hidden_proto(sepol_context_get_user) 15 | hidden_proto(sepol_context_set_mls) 16 | hidden_proto(sepol_context_set_role) 17 | hidden_proto(sepol_context_set_type) 18 | hidden_proto(sepol_context_set_user) 19 | #endif 20 | -------------------------------------------------------------------------------- /libsepol/debug.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "handle.h" 5 | #include "debug.h" 6 | 7 | /* Deprecated */ 8 | struct sepol_handle sepol_compat_handle = { 9 | .msg_callback = sepol_msg_default_handler, 10 | .msg_callback_arg = NULL, 11 | }; 12 | 13 | void sepol_debug(int on) 14 | { 15 | sepol_compat_handle.msg_callback = (on) ? 16 | sepol_msg_default_handler : NULL; 17 | } 18 | 19 | /* End deprecated */ 20 | 21 | int sepol_msg_get_level(sepol_handle_t * handle) 22 | { 23 | return handle->msg_level; 24 | } 25 | 26 | hidden_def(sepol_msg_get_level) 27 | 28 | const char *sepol_msg_get_channel(sepol_handle_t * handle) 29 | { 30 | return handle->msg_channel; 31 | } 32 | 33 | hidden_def(sepol_msg_get_channel) 34 | 35 | const char *sepol_msg_get_fname(sepol_handle_t * handle) 36 | { 37 | return handle->msg_fname; 38 | } 39 | 40 | hidden_def(sepol_msg_get_fname) 41 | #ifdef __GNUC__ 42 | __attribute__ ((format(printf, 3, 4))) 43 | #endif 44 | void hidden sepol_msg_default_handler(void *varg __attribute__ ((unused)), 45 | sepol_handle_t * handle, 46 | const char *fmt, ...) 47 | { 48 | 49 | FILE *stream = NULL; 50 | 51 | switch (sepol_msg_get_level(handle)) { 52 | 53 | case SEPOL_MSG_ERR: 54 | case SEPOL_MSG_WARN: 55 | stream = stderr; 56 | break; 57 | case SEPOL_MSG_INFO: 58 | default: 59 | stream = stdout; 60 | break; 61 | } 62 | 63 | fprintf(stream, "%s.%s: ", 64 | sepol_msg_get_channel(handle), sepol_msg_get_fname(handle)); 65 | 66 | va_list ap; 67 | va_start(ap, fmt); 68 | vfprintf(stream, fmt, ap); 69 | va_end(ap); 70 | 71 | fprintf(stream, "\n"); 72 | } 73 | 74 | extern void sepol_msg_set_callback(sepol_handle_t * handle, 75 | #ifdef __GNUC__ 76 | __attribute__ ((format(printf, 3, 4))) 77 | #endif 78 | void (*msg_callback) (void *varg, 79 | sepol_handle_t * 80 | handle, 81 | const char *fmt, ...), 82 | void *msg_callback_arg) 83 | { 84 | 85 | handle->msg_callback = msg_callback; 86 | handle->msg_callback_arg = msg_callback_arg; 87 | } 88 | -------------------------------------------------------------------------------- /libsepol/debug.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2006 Tresys Technology, LLC 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | 19 | #ifndef _SEPOL_INTERNAL_DEBUG_H_ 20 | #define _SEPOL_INTERNAL_DEBUG_H_ 21 | 22 | #include 23 | #include 24 | #include "dso.h" 25 | #include "handle.h" 26 | 27 | #define STATUS_SUCCESS 0 28 | #define STATUS_ERR -1 29 | #define STATUS_NODATA 1 30 | 31 | /* FIXME: this needs to become a real function. Declaring variables 32 | * in a macro is _evil_ as it can shadow other variables in local scope. 33 | * The variable h has been renamed to _sepol_h to reduce this chance, but 34 | * it is still wrong. 35 | */ 36 | #define msg_write(handle_arg, level_arg, \ 37 | channel_arg, func_arg, ...) do { \ 38 | sepol_handle_t *_sepol_h = (handle_arg) ?: &sepol_compat_handle; \ 39 | if (_sepol_h->msg_callback) { \ 40 | _sepol_h->msg_fname = func_arg; \ 41 | _sepol_h->msg_channel = channel_arg; \ 42 | _sepol_h->msg_level = level_arg; \ 43 | \ 44 | _sepol_h->msg_callback( \ 45 | _sepol_h->msg_callback_arg, \ 46 | _sepol_h, __VA_ARGS__); \ 47 | } \ 48 | } while(0) 49 | 50 | #define ERR(handle, ...) \ 51 | msg_write(handle, SEPOL_MSG_ERR, "libsepol", \ 52 | __FUNCTION__, __VA_ARGS__) 53 | 54 | #define INFO(handle, ...) \ 55 | msg_write(handle, SEPOL_MSG_INFO, "libsepol", \ 56 | __FUNCTION__, __VA_ARGS__) 57 | 58 | #define WARN(handle, ...) \ 59 | msg_write(handle, SEPOL_MSG_WARN, "libsepol", \ 60 | __FUNCTION__, __VA_ARGS__) 61 | 62 | #ifdef __GNUC__ 63 | __attribute__ ((format(printf, 3, 4))) 64 | #endif 65 | extern void hidden sepol_msg_default_handler(void *varg, 66 | sepol_handle_t * msg, 67 | const char *fmt, ...); 68 | 69 | extern struct sepol_handle sepol_compat_handle; 70 | 71 | hidden_proto(sepol_msg_get_channel) 72 | hidden_proto(sepol_msg_get_fname) 73 | hidden_proto(sepol_msg_get_level) 74 | #endif 75 | -------------------------------------------------------------------------------- /libsepol/deprecated_funcs.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "debug.h" 3 | 4 | /* 5 | * Need to keep these stubs for the libsepol interfaces exported in 6 | * libsepol.map.in, as they are part of the shared library ABI. 7 | */ 8 | 9 | static const char *msg = "Deprecated interface"; 10 | 11 | /* 12 | * These two functions are deprecated and referenced in: 13 | * include/libsepol/users.h 14 | */ 15 | int sepol_genusers(void *data __attribute((unused)), 16 | size_t len __attribute((unused)), 17 | const char *usersdir __attribute((unused)), 18 | void **newdata __attribute((unused)), 19 | size_t *newlen __attribute((unused))) 20 | { 21 | WARN(NULL, "%s", msg); 22 | return -1; 23 | } 24 | 25 | void sepol_set_delusers(int on __attribute((unused))) 26 | { 27 | WARN(NULL, "%s", msg); 28 | } 29 | 30 | /* 31 | * These two functions are deprecated and referenced in: 32 | * include/libsepol/booleans.h 33 | */ 34 | int sepol_genbools(void *data __attribute((unused)), 35 | size_t len __attribute((unused)), 36 | const char *booleans __attribute((unused))) 37 | { 38 | WARN(NULL, "%s", msg); 39 | return -1; 40 | } 41 | 42 | int sepol_genbools_array(void *data __attribute((unused)), 43 | size_t len __attribute((unused)), 44 | char **names __attribute((unused)), 45 | int *values __attribute((unused)), 46 | int nel __attribute((unused))) 47 | { 48 | WARN(NULL, "%s", msg); 49 | return -1; 50 | } 51 | -------------------------------------------------------------------------------- /libsepol/dso.h: -------------------------------------------------------------------------------- 1 | #ifndef _SEPOL_DSO_H 2 | #define _SEPOL_DSO_H 1 3 | 4 | #if !defined(SHARED) || defined(ANDROID) 5 | #define DISABLE_SYMVER 1 6 | #endif 7 | 8 | #ifdef SHARED 9 | # define hidden __attribute__ ((visibility ("hidden"))) 10 | # define hidden_proto(fct) __hidden_proto (fct, fct##_internal) 11 | # define __hidden_proto(fct, internal) \ 12 | extern __typeof (fct) internal; \ 13 | extern __typeof (fct) fct __asm (#internal) hidden; 14 | # if defined(__alpha__) || defined(__mips__) 15 | # define hidden_def(fct) \ 16 | asm (".globl " #fct "\n" #fct " = " #fct "_internal"); 17 | # else 18 | # define hidden_def(fct) \ 19 | asm (".globl " #fct "\n.set " #fct ", " #fct "_internal"); 20 | #endif 21 | #else 22 | # define hidden 23 | # define hidden_proto(fct) 24 | # define hidden_def(fct) 25 | #endif 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /libsepol/handle.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "handle.h" 4 | #include "debug.h" 5 | 6 | sepol_handle_t *sepol_handle_create(void) 7 | { 8 | 9 | sepol_handle_t *sh = malloc(sizeof(sepol_handle_t)); 10 | if (sh == NULL) 11 | return NULL; 12 | 13 | /* Set callback */ 14 | sh->msg_callback = sepol_msg_default_handler; 15 | sh->msg_callback_arg = NULL; 16 | 17 | /* by default do not disable dontaudits */ 18 | sh->disable_dontaudit = 0; 19 | sh->expand_consume_base = 0; 20 | 21 | /* by default needless unused branch of tunables would be discarded */ 22 | sh->preserve_tunables = 0; 23 | 24 | return sh; 25 | } 26 | 27 | int sepol_get_preserve_tunables(sepol_handle_t *sh) 28 | { 29 | assert(sh != NULL); 30 | return sh->preserve_tunables; 31 | } 32 | 33 | void sepol_set_preserve_tunables(sepol_handle_t * sh, int preserve_tunables) 34 | { 35 | assert(sh !=NULL); 36 | sh->preserve_tunables = preserve_tunables; 37 | } 38 | 39 | int sepol_get_disable_dontaudit(sepol_handle_t *sh) 40 | { 41 | assert(sh !=NULL); 42 | return sh->disable_dontaudit; 43 | } 44 | 45 | void sepol_set_disable_dontaudit(sepol_handle_t * sh, int disable_dontaudit) 46 | { 47 | assert(sh !=NULL); 48 | sh->disable_dontaudit = disable_dontaudit; 49 | } 50 | 51 | void sepol_set_expand_consume_base(sepol_handle_t *sh, int consume_base) 52 | { 53 | assert(sh != NULL); 54 | sh->expand_consume_base = consume_base; 55 | } 56 | 57 | void sepol_handle_destroy(sepol_handle_t * sh) 58 | { 59 | free(sh); 60 | } 61 | -------------------------------------------------------------------------------- /libsepol/handle.h: -------------------------------------------------------------------------------- 1 | #ifndef _SEPOL_INTERNAL_HANDLE_H_ 2 | #define _SEPOL_INTERNAL_HANDLE_H_ 3 | 4 | #include 5 | 6 | struct sepol_handle { 7 | /* Error handling */ 8 | int msg_level; 9 | const char *msg_channel; 10 | const char *msg_fname; 11 | #ifdef __GNUC__ 12 | __attribute__ ((format(printf, 3, 4))) 13 | #endif 14 | void (*msg_callback) (void *varg, 15 | sepol_handle_t * handle, const char *fmt, ...); 16 | void *msg_callback_arg; 17 | 18 | int disable_dontaudit; 19 | int expand_consume_base; 20 | int preserve_tunables; 21 | }; 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /libsepol/ibendport_internal.h: -------------------------------------------------------------------------------- 1 | #ifndef _SEPOL_IBENDPORT_INTERNAL_H_ 2 | #define _SEPOL_IBENDPORT_INTERNAL_H_ 3 | 4 | #include 5 | #include 6 | #include "dso.h" 7 | 8 | hidden_proto(sepol_ibendport_create) 9 | hidden_proto(sepol_ibendport_free) 10 | hidden_proto(sepol_ibendport_get_con) 11 | hidden_proto(sepol_ibendport_get_port) 12 | hidden_proto(sepol_ibendport_key_create) 13 | hidden_proto(sepol_ibendport_key_unpack) 14 | hidden_proto(sepol_ibendport_set_con) 15 | hidden_proto(sepol_ibendport_set_port) 16 | hidden_proto(sepol_ibendport_get_ibdev_name) 17 | hidden_proto(sepol_ibendport_set_ibdev_name) 18 | #endif 19 | -------------------------------------------------------------------------------- /libsepol/ibpkey_internal.h: -------------------------------------------------------------------------------- 1 | #ifndef _SEPOL_IBPKEY_INTERNAL_H_ 2 | #define _SEPOL_IBPKEY_INTERNAL_H_ 3 | 4 | #include 5 | #include 6 | #include "dso.h" 7 | 8 | hidden_proto(sepol_ibpkey_create) 9 | hidden_proto(sepol_ibpkey_free) 10 | hidden_proto(sepol_ibpkey_get_con) 11 | hidden_proto(sepol_ibpkey_get_high) 12 | hidden_proto(sepol_ibpkey_get_low) 13 | hidden_proto(sepol_ibpkey_key_create) 14 | hidden_proto(sepol_ibpkey_key_unpack) 15 | hidden_proto(sepol_ibpkey_set_con) 16 | hidden_proto(sepol_ibpkey_set_range) 17 | hidden_proto(sepol_ibpkey_get_subnet_prefix) 18 | hidden_proto(sepol_ibpkey_get_subnet_prefix_bytes) 19 | hidden_proto(sepol_ibpkey_set_subnet_prefix) 20 | hidden_proto(sepol_ibpkey_set_subnet_prefix_bytes) 21 | #endif 22 | -------------------------------------------------------------------------------- /libsepol/iface_internal.h: -------------------------------------------------------------------------------- 1 | #ifndef _SEPOL_IFACE_INTERNAL_H_ 2 | #define _SEPOL_IFACE_INTERNAL_H_ 3 | 4 | #include 5 | #include 6 | #include "dso.h" 7 | 8 | hidden_proto(sepol_iface_create) 9 | hidden_proto(sepol_iface_free) 10 | hidden_proto(sepol_iface_get_ifcon) 11 | hidden_proto(sepol_iface_get_msgcon) 12 | hidden_proto(sepol_iface_get_name) 13 | hidden_proto(sepol_iface_key_create) 14 | hidden_proto(sepol_iface_key_unpack) 15 | hidden_proto(sepol_iface_set_ifcon) 16 | hidden_proto(sepol_iface_set_msgcon) 17 | hidden_proto(sepol_iface_set_name) 18 | #endif 19 | -------------------------------------------------------------------------------- /libsepol/include/cil/android.h: -------------------------------------------------------------------------------- 1 | #ifndef _SEPOL_ANDROID_H_ 2 | #define _SEPOL_ANDROID_H_ 3 | #include 4 | 5 | #define PLAT_VERS "curr" 6 | #define PLAT_ID "p" 7 | #define NON_PLAT_ID "n" 8 | 9 | /* 10 | * cil_android_attrib_mapping - extract attributizable elements of the policy in 11 | * srcdb and create the mapping file necessary to link the platform and 12 | * non-platform policy files after non-platform policy attributization. 13 | * mdb - uninitialized cil_db reference to the resulting policy. Caller 14 | * responsibility to destroy. 15 | * srcdb - initialized and parsed cil_db reference to source public policy. 16 | * num - the version string to append types when converted to attributes. 17 | * returns SEPOL_OK if successful, otherwise passes on the encountered error. 18 | */ 19 | int cil_android_attrib_mapping(struct cil_db **mdb, struct cil_db *srcdb, const char *num); 20 | 21 | /* 22 | * cil_android_attributize - extract attributizable elements of the policy in 23 | * srcdb and convert all usage of those elements in tgtdb to versioned attributes. 24 | * Keep the attributes and type definitions so that tgtdb policy is more robust 25 | * against future changes to the public policy. 26 | * tgtdb - initialized and parsed cil_db reference to modify. 27 | * srcdb - initialized and parsed cil_db reference to source public policy 28 | * from which to extract attributizable elements. 29 | * num - the version string to append types when converted to attributes. 30 | * returns SEPOL_OK if successful, otherwise passes on the encountered error. 31 | */ 32 | int cil_android_attributize(struct cil_db *tgtdb, struct cil_db *srcdb, const char *num); 33 | 34 | #endif /* _SEPOL_ANDROID_H_ */ 35 | -------------------------------------------------------------------------------- /libsepol/include/cil/cil.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011 Tresys Technology, LLC. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * 1. Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY TRESYS TECHNOLOGY, LLC ``AS IS'' AND ANY EXPRESS 15 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 16 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 17 | * EVENT SHALL TRESYS TECHNOLOGY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 18 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 19 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 21 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 22 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 23 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | * 25 | * The views and conclusions contained in the software and documentation are those 26 | * of the authors and should not be interpreted as representing official policies, 27 | * either expressed or implied, of Tresys Technology, LLC. 28 | */ 29 | 30 | #ifndef CIL_H_ 31 | #define CIL_H_ 32 | 33 | #include 34 | 35 | #ifdef __cplusplus 36 | extern "C" { 37 | #endif 38 | 39 | struct cil_db; 40 | typedef struct cil_db cil_db_t; 41 | 42 | extern void cil_db_init(cil_db_t **db); 43 | extern void cil_db_destroy(cil_db_t **db); 44 | 45 | extern int cil_add_file(cil_db_t *db, char *name, char *data, size_t size); 46 | 47 | extern int cil_compile(cil_db_t *db); 48 | extern int cil_build_policydb(cil_db_t *db, sepol_policydb_t **sepol_db); 49 | extern int cil_userprefixes_to_string(cil_db_t *db, char **out, size_t *size); 50 | extern int cil_selinuxusers_to_string(cil_db_t *db, char **out, size_t *size); 51 | extern int cil_filecons_to_string(cil_db_t *db, char **out, size_t *size); 52 | extern void cil_set_disable_dontaudit(cil_db_t *db, int disable_dontaudit); 53 | extern void cil_set_multiple_decls(cil_db_t *db, int multiple_decls); 54 | extern void cil_set_disable_neverallow(cil_db_t *db, int disable_neverallow); 55 | extern void cil_set_preserve_tunables(cil_db_t *db, int preserve_tunables); 56 | extern int cil_set_handle_unknown(cil_db_t *db, int handle_unknown); 57 | extern void cil_set_mls(cil_db_t *db, int mls); 58 | extern void cil_set_attrs_expand_generated(struct cil_db *db, int attrs_expand_generated); 59 | extern void cil_set_attrs_expand_size(struct cil_db *db, unsigned attrs_expand_size); 60 | extern void cil_set_target_platform(cil_db_t *db, int target_platform); 61 | extern void cil_set_policy_version(cil_db_t *db, int policy_version); 62 | extern void cil_write_policy_conf(FILE *out, struct cil_db *db); 63 | 64 | enum cil_log_level { 65 | CIL_ERR = 1, 66 | CIL_WARN, 67 | CIL_INFO 68 | }; 69 | extern void cil_set_log_level(enum cil_log_level lvl); 70 | extern void cil_set_log_handler(void (*handler)(int lvl, char *msg)); 71 | 72 | #ifdef __GNUC__ 73 | __attribute__ ((format(printf, 2, 3))) 74 | #endif 75 | extern void cil_log(enum cil_log_level lvl, const char *msg, ...); 76 | 77 | extern void cil_set_malloc_error_handler(void (*handler)(void)); 78 | 79 | #ifdef __cplusplus 80 | } 81 | #endif 82 | #endif 83 | -------------------------------------------------------------------------------- /libsepol/include/cil/cil_write_ast.h: -------------------------------------------------------------------------------- 1 | #ifndef CIL_WRITE_H_ 2 | #define CIL_WRITE_H_ 3 | 4 | #include 5 | 6 | int cil_write_ast(struct cil_db *db, const char* path); 7 | #endif /* CIL_WRITE_H_ */ 8 | -------------------------------------------------------------------------------- /libsepol/include/sepol/boolean_record.h: -------------------------------------------------------------------------------- 1 | #ifndef _SEPOL_BOOLEAN_RECORD_H_ 2 | #define _SEPOL_BOOLEAN_RECORD_H_ 3 | 4 | #include 5 | #include 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | 11 | struct sepol_bool; 12 | struct sepol_bool_key; 13 | typedef struct sepol_bool sepol_bool_t; 14 | typedef struct sepol_bool_key sepol_bool_key_t; 15 | 16 | /* Key */ 17 | extern int sepol_bool_key_create(sepol_handle_t * handle, 18 | const char *name, sepol_bool_key_t ** key); 19 | 20 | extern void sepol_bool_key_unpack(const sepol_bool_key_t * key, 21 | const char **name); 22 | 23 | extern int sepol_bool_key_extract(sepol_handle_t * handle, 24 | const sepol_bool_t * boolean, 25 | sepol_bool_key_t ** key_ptr); 26 | 27 | extern void sepol_bool_key_free(sepol_bool_key_t * key); 28 | 29 | extern int sepol_bool_compare(const sepol_bool_t * boolean, 30 | const sepol_bool_key_t * key); 31 | 32 | extern int sepol_bool_compare2(const sepol_bool_t * boolean, 33 | const sepol_bool_t * boolean2); 34 | 35 | /* Name */ 36 | extern const char *sepol_bool_get_name(const sepol_bool_t * boolean); 37 | 38 | extern int sepol_bool_set_name(sepol_handle_t * handle, 39 | sepol_bool_t * boolean, const char *name); 40 | 41 | /* Value */ 42 | extern int sepol_bool_get_value(const sepol_bool_t * boolean); 43 | 44 | extern void sepol_bool_set_value(sepol_bool_t * boolean, int value); 45 | 46 | /* Create/Clone/Destroy */ 47 | extern int sepol_bool_create(sepol_handle_t * handle, sepol_bool_t ** bool_ptr); 48 | 49 | extern int sepol_bool_clone(sepol_handle_t * handle, 50 | const sepol_bool_t * boolean, 51 | sepol_bool_t ** bool_ptr); 52 | 53 | extern void sepol_bool_free(sepol_bool_t * boolean); 54 | 55 | #ifdef __cplusplus 56 | } 57 | #endif 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /libsepol/include/sepol/booleans.h: -------------------------------------------------------------------------------- 1 | #ifndef _SEPOL_BOOLEANS_H_ 2 | #define _SEPOL_BOOLEANS_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /* These two functions are deprecated. See src/deprecated_funcs.c */ 14 | extern int sepol_genbools(void *data, size_t len, const char *boolpath); 15 | extern int sepol_genbools_array(void *data, size_t len, 16 | char **names, int *values, int nel); 17 | 18 | /* Set the specified boolean */ 19 | extern int sepol_bool_set(sepol_handle_t * handle, 20 | sepol_policydb_t * policydb, 21 | const sepol_bool_key_t * key, 22 | const sepol_bool_t * data); 23 | 24 | /* Return the number of booleans */ 25 | extern int sepol_bool_count(sepol_handle_t * handle, 26 | const sepol_policydb_t * p, unsigned int *response); 27 | 28 | /* Check if the specified boolean exists */ 29 | extern int sepol_bool_exists(sepol_handle_t * handle, 30 | const sepol_policydb_t * policydb, 31 | const sepol_bool_key_t * key, int *response); 32 | 33 | /* Query a boolean - returns the boolean, or NULL if not found */ 34 | extern int sepol_bool_query(sepol_handle_t * handle, 35 | const sepol_policydb_t * p, 36 | const sepol_bool_key_t * key, 37 | sepol_bool_t ** response); 38 | 39 | /* Iterate the booleans 40 | * The handler may return: 41 | * -1 to signal an error condition, 42 | * 1 to signal successful exit 43 | * 0 to signal continue */ 44 | 45 | extern int sepol_bool_iterate(sepol_handle_t * handle, 46 | const sepol_policydb_t * policydb, 47 | int (*fn) (const sepol_bool_t * boolean, 48 | void *fn_arg), void *arg); 49 | 50 | #ifdef __cplusplus 51 | } 52 | #endif 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /libsepol/include/sepol/compat.h: -------------------------------------------------------------------------------- 1 | /* 2 | * extended permissions compatibility. Make ToT Android kernels compatible 3 | * with Android M releases 4 | */ 5 | #define AVTAB_OPTYPE_ALLOWED 0x1000 6 | #define AVTAB_OPTYPE_AUDITALLOW 0x2000 7 | #define AVTAB_OPTYPE_DONTAUDIT 0x4000 8 | #define AVTAB_OPTYPE (AVTAB_OPTYPE_ALLOWED | \ 9 | AVTAB_OPTYPE_AUDITALLOW | \ 10 | AVTAB_OPTYPE_DONTAUDIT) 11 | #define AVTAB_XPERMS_OPTYPE 4 12 | 13 | #define avtab_xperms_to_optype(x) (x << AVTAB_XPERMS_OPTYPE) 14 | #define avtab_optype_to_xperms(x) (x >> AVTAB_XPERMS_OPTYPE) 15 | 16 | extern unsigned int avtab_android_m_compat; 17 | -------------------------------------------------------------------------------- /libsepol/include/sepol/context.h: -------------------------------------------------------------------------------- 1 | #ifndef _SEPOL_CONTEXT_H_ 2 | #define _SEPOL_CONTEXT_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | 12 | /* -- Deprecated -- */ 13 | 14 | extern int sepol_check_context(const char *context); 15 | 16 | /* -- End deprecated -- */ 17 | 18 | extern int sepol_context_check(sepol_handle_t * handle, 19 | const sepol_policydb_t * policydb, 20 | const sepol_context_t * context); 21 | 22 | extern int sepol_mls_contains(sepol_handle_t * handle, 23 | const sepol_policydb_t * policydb, 24 | const char *mls1, 25 | const char *mls2, int *response); 26 | 27 | extern int sepol_mls_check(sepol_handle_t * handle, 28 | const sepol_policydb_t * policydb, const char *mls); 29 | 30 | #ifdef __cplusplus 31 | } 32 | #endif 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /libsepol/include/sepol/context_record.h: -------------------------------------------------------------------------------- 1 | #ifndef _SEPOL_CONTEXT_RECORD_H_ 2 | #define _SEPOL_CONTEXT_RECORD_H_ 3 | 4 | #include 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | struct sepol_context; 11 | typedef struct sepol_context sepol_context_t; 12 | 13 | /* We don't need a key, because the context is never stored 14 | * in a data collection by itself */ 15 | 16 | /* User */ 17 | extern const char *sepol_context_get_user(const sepol_context_t * con); 18 | 19 | extern int sepol_context_set_user(sepol_handle_t * handle, 20 | sepol_context_t * con, const char *user); 21 | 22 | /* Role */ 23 | extern const char *sepol_context_get_role(const sepol_context_t * con); 24 | 25 | extern int sepol_context_set_role(sepol_handle_t * handle, 26 | sepol_context_t * con, const char *role); 27 | 28 | /* Type */ 29 | extern const char *sepol_context_get_type(const sepol_context_t * con); 30 | 31 | extern int sepol_context_set_type(sepol_handle_t * handle, 32 | sepol_context_t * con, const char *type); 33 | 34 | /* MLS */ 35 | extern const char *sepol_context_get_mls(const sepol_context_t * con); 36 | 37 | extern int sepol_context_set_mls(sepol_handle_t * handle, 38 | sepol_context_t * con, const char *mls_range); 39 | 40 | /* Create/Clone/Destroy */ 41 | extern int sepol_context_create(sepol_handle_t * handle, 42 | sepol_context_t ** con_ptr); 43 | 44 | extern int sepol_context_clone(sepol_handle_t * handle, 45 | const sepol_context_t * con, 46 | sepol_context_t ** con_ptr); 47 | 48 | extern void sepol_context_free(sepol_context_t * con); 49 | 50 | /* Parse to/from string */ 51 | extern int sepol_context_from_string(sepol_handle_t * handle, 52 | const char *str, sepol_context_t ** con); 53 | 54 | extern int sepol_context_to_string(sepol_handle_t * handle, 55 | const sepol_context_t * con, char **str_ptr); 56 | 57 | #ifdef __cplusplus 58 | } 59 | #endif 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /libsepol/include/sepol/debug.h: -------------------------------------------------------------------------------- 1 | #ifndef _SEPOL_DEBUG_H_ 2 | #define _SEPOL_DEBUG_H_ 3 | 4 | #include 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | /* Deprecated */ 11 | extern void sepol_debug(int on); 12 | /* End deprecated */ 13 | 14 | #define SEPOL_MSG_ERR 1 15 | #define SEPOL_MSG_WARN 2 16 | #define SEPOL_MSG_INFO 3 17 | 18 | extern int sepol_msg_get_level(sepol_handle_t * handle); 19 | 20 | extern const char *sepol_msg_get_channel(sepol_handle_t * handle); 21 | 22 | extern const char *sepol_msg_get_fname(sepol_handle_t * handle); 23 | 24 | /* Set the messaging callback. 25 | * By the default, the callback will print 26 | * the message on standard output, in a 27 | * particular format. Passing NULL here 28 | * indicates that messaging should be suppressed */ 29 | extern void sepol_msg_set_callback(sepol_handle_t * handle, 30 | #ifdef __GNUC__ 31 | __attribute__ ((format(printf, 3, 4))) 32 | #endif 33 | void (*msg_callback) (void *varg, 34 | sepol_handle_t * 35 | handle, 36 | const char *fmt, ...), 37 | void *msg_callback_arg); 38 | 39 | #ifdef __cplusplus 40 | } 41 | #endif 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /libsepol/include/sepol/errcodes.h: -------------------------------------------------------------------------------- 1 | /* Author: Karl MacMillan */ 2 | 3 | #ifndef __sepol_errno_h__ 4 | #define __sepol_errno_h__ 5 | 6 | #include 7 | 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | 12 | #define SEPOL_OK 0 13 | 14 | /* These first error codes are defined for compatibility with 15 | * previous version of libsepol. In the future, custom error 16 | * codes that don't map to system error codes should be defined 17 | * outside of the range of system error codes. 18 | */ 19 | #define SEPOL_ERR -1 20 | #define SEPOL_ENOTSUP -2 /* feature not supported in module language */ 21 | #define SEPOL_EREQ -3 /* requirements not met */ 22 | 23 | /* Error codes that map to system error codes */ 24 | #define SEPOL_ENOMEM -ENOMEM 25 | #define SEPOL_ERANGE -ERANGE 26 | #define SEPOL_EEXIST -EEXIST 27 | #define SEPOL_ENOENT -ENOENT 28 | 29 | #ifdef __cplusplus 30 | } 31 | #endif 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /libsepol/include/sepol/handle.h: -------------------------------------------------------------------------------- 1 | #ifndef _SEPOL_HANDLE_H_ 2 | #define _SEPOL_HANDLE_H_ 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | struct sepol_handle; 9 | typedef struct sepol_handle sepol_handle_t; 10 | 11 | /* Create and return a sepol handle. */ 12 | sepol_handle_t *sepol_handle_create(void); 13 | 14 | /* Get whether or not dontaudits will be disabled, same values as 15 | * specified by set_disable_dontaudit. This value reflects the state 16 | * your system will be set to upon commit, not necessarily its 17 | * current state.*/ 18 | int sepol_get_disable_dontaudit(sepol_handle_t * sh); 19 | 20 | /* Set whether or not to disable dontaudits, 0 is default and does 21 | * not disable dontaudits, 1 disables them */ 22 | void sepol_set_disable_dontaudit(sepol_handle_t * sh, int disable_dontaudit); 23 | 24 | /* Set whether module_expand() should consume the base policy passed in. 25 | * This should reduce the amount of memory required to expand the policy. */ 26 | void sepol_set_expand_consume_base(sepol_handle_t * sh, int consume_base); 27 | 28 | /* Destroy a sepol handle. */ 29 | void sepol_handle_destroy(sepol_handle_t *); 30 | 31 | /* Get whether or not needless unused branch of tunables would be preserved */ 32 | int sepol_get_preserve_tunables(sepol_handle_t * sh); 33 | 34 | /* Set whether or not to preserve the needless unused branch of tunables, 35 | * 0 is default and discard such branch, 1 preserves them */ 36 | void sepol_set_preserve_tunables(sepol_handle_t * sh, int preserve_tunables); 37 | 38 | #ifdef __cplusplus 39 | } 40 | #endif 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /libsepol/include/sepol/ibendport_record.h: -------------------------------------------------------------------------------- 1 | #ifndef _SEPOL_IBENDPORT_RECORD_H_ 2 | #define _SEPOL_IBENDPORT_RECORD_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | 12 | struct sepol_ibendport; 13 | struct sepol_ibendport_key; 14 | typedef struct sepol_ibendport sepol_ibendport_t; 15 | typedef struct sepol_ibendport_key sepol_ibendport_key_t; 16 | 17 | extern int sepol_ibendport_compare(const sepol_ibendport_t *ibendport, 18 | const sepol_ibendport_key_t *key); 19 | 20 | extern int sepol_ibendport_compare2(const sepol_ibendport_t *ibendport, 21 | const sepol_ibendport_t *ibendport2); 22 | 23 | extern int sepol_ibendport_key_create(sepol_handle_t *handle, 24 | const char *ibdev_name, 25 | int port, 26 | sepol_ibendport_key_t **key_ptr); 27 | 28 | extern void sepol_ibendport_key_unpack(const sepol_ibendport_key_t *key, 29 | const char **ibdev_name, 30 | int *port); 31 | 32 | extern int sepol_ibendport_alloc_ibdev_name(sepol_handle_t *handle, 33 | char **ibdev_name); 34 | 35 | extern int sepol_ibendport_key_extract(sepol_handle_t *handle, 36 | const sepol_ibendport_t *ibendport, 37 | sepol_ibendport_key_t **key_ptr); 38 | 39 | extern void sepol_ibendport_key_free(sepol_ibendport_key_t *key); 40 | 41 | extern void sepol_ibendport_set_port(sepol_ibendport_t *ibendport, int port); 42 | 43 | extern int sepol_ibendport_get_port(const sepol_ibendport_t *ibendport); 44 | 45 | extern int sepol_ibendport_get_ibdev_name(sepol_handle_t *handle, 46 | const sepol_ibendport_t *ibendport, 47 | char **ibdev_name); 48 | 49 | extern int sepol_ibendport_set_ibdev_name(sepol_handle_t *handle, 50 | sepol_ibendport_t *ibendport, 51 | const char *ibdev_name); 52 | 53 | extern sepol_context_t *sepol_ibendport_get_con(const sepol_ibendport_t *ibendport); 54 | 55 | extern int sepol_ibendport_set_con(sepol_handle_t *handle, 56 | sepol_ibendport_t *ibendport, 57 | sepol_context_t *con); 58 | 59 | extern int sepol_ibendport_create(sepol_handle_t *handle, 60 | sepol_ibendport_t **ibendport_ptr); 61 | 62 | extern int sepol_ibendport_clone(sepol_handle_t *handle, 63 | const sepol_ibendport_t *ibendport, 64 | sepol_ibendport_t **ibendport_ptr); 65 | 66 | extern void sepol_ibendport_free(sepol_ibendport_t *ibendport); 67 | 68 | #ifdef __cplusplus 69 | } 70 | #endif 71 | 72 | #endif 73 | -------------------------------------------------------------------------------- /libsepol/include/sepol/ibendports.h: -------------------------------------------------------------------------------- 1 | #ifndef _SEPOL_IBENDPORTS_H_ 2 | #define _SEPOL_IBENDPORTS_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | 12 | /* Return the number of ibendports */ 13 | extern int sepol_ibendport_count(sepol_handle_t *handle, 14 | const sepol_policydb_t *p, 15 | unsigned int *response); 16 | 17 | /* Check if a ibendport exists */ 18 | extern int sepol_ibendport_exists(sepol_handle_t *handle, 19 | const sepol_policydb_t *policydb, 20 | const sepol_ibendport_key_t *key, int *response); 21 | 22 | /* Query a ibendport - returns the ibendport, or NULL if not found */ 23 | extern int sepol_ibendport_query(sepol_handle_t *handle, 24 | const sepol_policydb_t *policydb, 25 | const sepol_ibendport_key_t *key, 26 | sepol_ibendport_t **response); 27 | 28 | /* Modify a ibendport, or add it, if the key is not found */ 29 | extern int sepol_ibendport_modify(sepol_handle_t *handle, 30 | sepol_policydb_t *policydb, 31 | const sepol_ibendport_key_t *key, 32 | const sepol_ibendport_t *data); 33 | 34 | /* Iterate the ibendports 35 | * The handler may return: 36 | * -1 to signal an error condition, 37 | * 1 to signal successful exit 38 | * 0 to signal continue 39 | */ 40 | extern int sepol_ibendport_iterate(sepol_handle_t *handle, 41 | const sepol_policydb_t *policydb, 42 | int (*fn)(const sepol_ibendport_t *ibendport, 43 | void *fn_arg), void *arg); 44 | 45 | 46 | #ifdef __cplusplus 47 | } 48 | #endif 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /libsepol/include/sepol/ibpkey_record.h: -------------------------------------------------------------------------------- 1 | #ifndef _SEPOL_IBPKEY_RECORD_H_ 2 | #define _SEPOL_IBPKEY_RECORD_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #define INET6_ADDRLEN 16 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | struct sepol_ibpkey; 16 | struct sepol_ibpkey_key; 17 | typedef struct sepol_ibpkey sepol_ibpkey_t; 18 | typedef struct sepol_ibpkey_key sepol_ibpkey_key_t; 19 | 20 | extern int sepol_ibpkey_compare(const sepol_ibpkey_t *ibpkey, 21 | const sepol_ibpkey_key_t *key); 22 | 23 | extern int sepol_ibpkey_compare2(const sepol_ibpkey_t *ibpkey, 24 | const sepol_ibpkey_t *ibpkey2); 25 | 26 | extern int sepol_ibpkey_key_create(sepol_handle_t *handle, 27 | const char *subnet_prefix, 28 | int low, int high, 29 | sepol_ibpkey_key_t **key_ptr); 30 | 31 | extern void sepol_ibpkey_key_unpack(const sepol_ibpkey_key_t *key, 32 | uint64_t *subnet_prefix, 33 | int *low, int *high); 34 | 35 | extern int sepol_ibpkey_key_extract(sepol_handle_t *handle, 36 | const sepol_ibpkey_t *ibpkey, 37 | sepol_ibpkey_key_t **key_ptr); 38 | 39 | extern void sepol_ibpkey_key_free(sepol_ibpkey_key_t *key); 40 | 41 | extern int sepol_ibpkey_get_low(const sepol_ibpkey_t *ibpkey); 42 | 43 | extern int sepol_ibpkey_get_high(const sepol_ibpkey_t *ibpkey); 44 | 45 | extern void sepol_ibpkey_set_pkey(sepol_ibpkey_t *ibpkey, int pkey_num); 46 | 47 | extern void sepol_ibpkey_set_range(sepol_ibpkey_t *ibpkey, int low, int high); 48 | 49 | extern int sepol_ibpkey_get_subnet_prefix(sepol_handle_t *handle, 50 | const sepol_ibpkey_t *ibpkey, 51 | char **subnet_prefix); 52 | 53 | extern uint64_t sepol_ibpkey_get_subnet_prefix_bytes(const sepol_ibpkey_t *ibpkey); 54 | 55 | extern int sepol_ibpkey_set_subnet_prefix(sepol_handle_t *handle, 56 | sepol_ibpkey_t *ibpkey, 57 | const char *subnet_prefix); 58 | 59 | extern void sepol_ibpkey_set_subnet_prefix_bytes(sepol_ibpkey_t *ibpkey, 60 | uint64_t subnet_prefix); 61 | 62 | extern sepol_context_t *sepol_ibpkey_get_con(const sepol_ibpkey_t *ibpkey); 63 | 64 | extern int sepol_ibpkey_set_con(sepol_handle_t *handle, 65 | sepol_ibpkey_t *ibpkey, sepol_context_t *con); 66 | 67 | extern int sepol_ibpkey_create(sepol_handle_t *handle, sepol_ibpkey_t **ibpkey_ptr); 68 | 69 | extern int sepol_ibpkey_clone(sepol_handle_t *handle, 70 | const sepol_ibpkey_t *ibpkey, 71 | sepol_ibpkey_t **ibpkey_ptr); 72 | 73 | extern void sepol_ibpkey_free(sepol_ibpkey_t *ibpkey); 74 | 75 | 76 | #ifdef __cplusplus 77 | } 78 | #endif 79 | 80 | #endif 81 | -------------------------------------------------------------------------------- /libsepol/include/sepol/ibpkeys.h: -------------------------------------------------------------------------------- 1 | #ifndef _SEPOL_IBPKEYS_H_ 2 | #define _SEPOL_IBPKEYS_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /* Return the number of ibpkeys */ 14 | extern int sepol_ibpkey_count(sepol_handle_t *handle, 15 | const sepol_policydb_t *p, unsigned int *response); 16 | 17 | /* Check if a ibpkey exists */ 18 | extern int sepol_ibpkey_exists(sepol_handle_t *handle, 19 | const sepol_policydb_t *policydb, 20 | const sepol_ibpkey_key_t *key, int *response); 21 | 22 | /* Query a ibpkey - returns the ibpkey, or NULL if not found */ 23 | extern int sepol_ibpkey_query(sepol_handle_t *handle, 24 | const sepol_policydb_t *policydb, 25 | const sepol_ibpkey_key_t *key, 26 | sepol_ibpkey_t **response); 27 | 28 | /* Modify a ibpkey, or add it, if the key is not found */ 29 | extern int sepol_ibpkey_modify(sepol_handle_t *handle, 30 | sepol_policydb_t *policydb, 31 | const sepol_ibpkey_key_t *key, 32 | const sepol_ibpkey_t *data); 33 | 34 | /* Iterate the ibpkeys 35 | * The handler may return: 36 | * -1 to signal an error condition, 37 | * 1 to signal successful exit 38 | * 0 to signal continue 39 | */ 40 | extern int sepol_ibpkey_iterate(sepol_handle_t *handle, 41 | const sepol_policydb_t *policydb, 42 | int (*fn)(const sepol_ibpkey_t *ibpkey, 43 | void *fn_arg), void *arg); 44 | 45 | 46 | #ifdef __cplusplus 47 | } 48 | #endif 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /libsepol/include/sepol/iface_record.h: -------------------------------------------------------------------------------- 1 | #ifndef _SEPOL_IFACE_RECORD_H_ 2 | #define _SEPOL_IFACE_RECORD_H_ 3 | 4 | #include 5 | #include 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | 11 | struct sepol_iface; 12 | struct sepol_iface_key; 13 | typedef struct sepol_iface sepol_iface_t; 14 | typedef struct sepol_iface_key sepol_iface_key_t; 15 | 16 | /* Key */ 17 | extern int sepol_iface_compare(const sepol_iface_t * iface, 18 | const sepol_iface_key_t * key); 19 | 20 | extern int sepol_iface_compare2(const sepol_iface_t * iface, 21 | const sepol_iface_t * iface2); 22 | 23 | extern void sepol_iface_key_unpack(const sepol_iface_key_t * key, 24 | const char **name); 25 | 26 | extern int sepol_iface_key_create(sepol_handle_t * handle, 27 | const char *name, 28 | sepol_iface_key_t ** key_ptr); 29 | 30 | extern int sepol_iface_key_extract(sepol_handle_t * handle, 31 | const sepol_iface_t * iface, 32 | sepol_iface_key_t ** key_ptr); 33 | 34 | extern void sepol_iface_key_free(sepol_iface_key_t * key); 35 | 36 | /* Name */ 37 | extern const char *sepol_iface_get_name(const sepol_iface_t * iface); 38 | 39 | extern int sepol_iface_set_name(sepol_handle_t * handle, 40 | sepol_iface_t * iface, const char *name); 41 | 42 | /* Context */ 43 | extern sepol_context_t *sepol_iface_get_ifcon(const sepol_iface_t * iface); 44 | 45 | extern int sepol_iface_set_ifcon(sepol_handle_t * handle, 46 | sepol_iface_t * iface, sepol_context_t * con); 47 | 48 | extern sepol_context_t *sepol_iface_get_msgcon(const sepol_iface_t * iface); 49 | 50 | extern int sepol_iface_set_msgcon(sepol_handle_t * handle, 51 | sepol_iface_t * iface, sepol_context_t * con); 52 | 53 | /* Create/Clone/Destroy */ 54 | extern int sepol_iface_create(sepol_handle_t * handle, 55 | sepol_iface_t ** iface_ptr); 56 | 57 | extern int sepol_iface_clone(sepol_handle_t * handle, 58 | const sepol_iface_t * iface, 59 | sepol_iface_t ** iface_ptr); 60 | 61 | extern void sepol_iface_free(sepol_iface_t * iface); 62 | 63 | #ifdef __cplusplus 64 | } 65 | #endif 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /libsepol/include/sepol/interfaces.h: -------------------------------------------------------------------------------- 1 | #ifndef __SEPOL_INTERFACES_H_ 2 | #define __SEPOL_INTERFACES_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | 12 | /* Return the number of interfaces */ 13 | extern int sepol_iface_count(sepol_handle_t * handle, 14 | const sepol_policydb_t * policydb, 15 | unsigned int *response); 16 | 17 | /* Check if an interface exists */ 18 | extern int sepol_iface_exists(sepol_handle_t * handle, 19 | const sepol_policydb_t * policydb, 20 | const sepol_iface_key_t * key, int *response); 21 | 22 | /* Query an interface - returns the interface, 23 | * or NULL if not found */ 24 | extern int sepol_iface_query(sepol_handle_t * handle, 25 | const sepol_policydb_t * policydb, 26 | const sepol_iface_key_t * key, 27 | sepol_iface_t ** response); 28 | 29 | /* Modify an interface, or add it, if the key 30 | * is not found */ 31 | extern int sepol_iface_modify(sepol_handle_t * handle, 32 | sepol_policydb_t * policydb, 33 | const sepol_iface_key_t * key, 34 | const sepol_iface_t * data); 35 | 36 | /* Iterate the interfaces 37 | * The handler may return: 38 | * -1 to signal an error condition, 39 | * 1 to signal successful exit 40 | * 0 to signal continue */ 41 | 42 | extern int sepol_iface_iterate(sepol_handle_t * handle, 43 | const sepol_policydb_t * policydb, 44 | int (*fn) (const sepol_iface_t * iface, 45 | void *fn_arg), void *arg); 46 | 47 | #ifdef __cplusplus 48 | } 49 | #endif 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /libsepol/include/sepol/kernel_to_cil.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | int sepol_kernel_policydb_to_cil(FILE *fp, struct policydb *pdb); 6 | -------------------------------------------------------------------------------- /libsepol/include/sepol/kernel_to_conf.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | int sepol_kernel_policydb_to_conf(FILE *fp, struct policydb *pdb); 6 | -------------------------------------------------------------------------------- /libsepol/include/sepol/module.h: -------------------------------------------------------------------------------- 1 | #ifndef _SEPOL_MODULE_H_ 2 | #define _SEPOL_MODULE_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | #include 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | struct sepol_module_package; 16 | typedef struct sepol_module_package sepol_module_package_t; 17 | 18 | /* Module package public interfaces. */ 19 | 20 | extern int sepol_module_package_create(sepol_module_package_t ** p); 21 | 22 | extern void sepol_module_package_free(sepol_module_package_t * p); 23 | 24 | extern char *sepol_module_package_get_file_contexts(sepol_module_package_t * p); 25 | 26 | extern size_t sepol_module_package_get_file_contexts_len(sepol_module_package_t 27 | * p); 28 | 29 | extern int sepol_module_package_set_file_contexts(sepol_module_package_t * p, 30 | char *data, size_t len); 31 | 32 | extern char *sepol_module_package_get_seusers(sepol_module_package_t * p); 33 | 34 | extern size_t sepol_module_package_get_seusers_len(sepol_module_package_t * p); 35 | 36 | extern int sepol_module_package_set_seusers(sepol_module_package_t * p, 37 | char *data, size_t len); 38 | 39 | extern char *sepol_module_package_get_user_extra(sepol_module_package_t * p); 40 | 41 | extern size_t sepol_module_package_get_user_extra_len(sepol_module_package_t * 42 | p); 43 | 44 | extern int sepol_module_package_set_user_extra(sepol_module_package_t * p, 45 | char *data, size_t len); 46 | 47 | extern char *sepol_module_package_get_netfilter_contexts(sepol_module_package_t 48 | * p); 49 | 50 | extern size_t 51 | sepol_module_package_get_netfilter_contexts_len(sepol_module_package_t * p); 52 | 53 | extern int sepol_module_package_set_netfilter_contexts(sepol_module_package_t * 54 | p, char *data, 55 | size_t len); 56 | 57 | extern sepol_policydb_t *sepol_module_package_get_policy(sepol_module_package_t 58 | * p); 59 | 60 | extern int sepol_link_packages(sepol_handle_t * handle, 61 | sepol_module_package_t * base, 62 | sepol_module_package_t ** modules, 63 | int num_modules, int verbose); 64 | 65 | extern int sepol_module_package_read(sepol_module_package_t * mod, 66 | struct sepol_policy_file *file, 67 | int verbose); 68 | 69 | extern int sepol_module_package_info(struct sepol_policy_file *file, 70 | int *type, char **name, char **version); 71 | 72 | extern int sepol_module_package_write(sepol_module_package_t * p, 73 | struct sepol_policy_file *file); 74 | 75 | /* Module linking/expanding public interfaces. */ 76 | 77 | extern int sepol_link_modules(sepol_handle_t * handle, 78 | sepol_policydb_t * base, 79 | sepol_policydb_t ** modules, 80 | size_t len, int verbose); 81 | 82 | extern int sepol_expand_module(sepol_handle_t * handle, 83 | sepol_policydb_t * base, 84 | sepol_policydb_t * out, int verbose, int check); 85 | 86 | #ifdef __cplusplus 87 | } 88 | #endif 89 | 90 | #endif 91 | -------------------------------------------------------------------------------- /libsepol/include/sepol/module_to_cil.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | 6 | int sepol_module_policydb_to_cil(FILE *fp, struct policydb *pdb, int linked); 7 | int sepol_module_package_to_cil(FILE *fp, struct sepol_module_package *mod_pkg); 8 | int sepol_ppfile_to_module_package(FILE *fp, struct sepol_module_package **mod_pkg); 9 | -------------------------------------------------------------------------------- /libsepol/include/sepol/node_record.h: -------------------------------------------------------------------------------- 1 | #ifndef _SEPOL_NODE_RECORD_H_ 2 | #define _SEPOL_NODE_RECORD_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | 12 | struct sepol_node; 13 | struct sepol_node_key; 14 | typedef struct sepol_node sepol_node_t; 15 | typedef struct sepol_node_key sepol_node_key_t; 16 | 17 | #define SEPOL_PROTO_IP4 0 18 | #define SEPOL_PROTO_IP6 1 19 | 20 | /* Key */ 21 | extern int sepol_node_compare(const sepol_node_t * node, 22 | const sepol_node_key_t * key); 23 | 24 | extern int sepol_node_compare2(const sepol_node_t * node, 25 | const sepol_node_t * node2); 26 | 27 | extern int sepol_node_key_create(sepol_handle_t * handle, 28 | const char *addr, 29 | const char *mask, 30 | int proto, sepol_node_key_t ** key_ptr); 31 | 32 | extern void sepol_node_key_unpack(const sepol_node_key_t * key, 33 | const char **addr, 34 | const char **mask, int *proto); 35 | 36 | extern int sepol_node_key_extract(sepol_handle_t * handle, 37 | const sepol_node_t * node, 38 | sepol_node_key_t ** key_ptr); 39 | 40 | extern void sepol_node_key_free(sepol_node_key_t * key); 41 | 42 | /* Address */ 43 | extern int sepol_node_get_addr(sepol_handle_t * handle, 44 | const sepol_node_t * node, char **addr); 45 | 46 | extern int sepol_node_get_addr_bytes(sepol_handle_t * handle, 47 | const sepol_node_t * node, 48 | char **addr, size_t * addr_sz); 49 | 50 | extern int sepol_node_set_addr(sepol_handle_t * handle, 51 | sepol_node_t * node, 52 | int proto, const char *addr); 53 | 54 | extern int sepol_node_set_addr_bytes(sepol_handle_t * handle, 55 | sepol_node_t * node, 56 | const char *addr, size_t addr_sz); 57 | 58 | /* Netmask */ 59 | extern int sepol_node_get_mask(sepol_handle_t * handle, 60 | const sepol_node_t * node, char **mask); 61 | 62 | extern int sepol_node_get_mask_bytes(sepol_handle_t * handle, 63 | const sepol_node_t * node, 64 | char **mask, size_t * mask_sz); 65 | 66 | extern int sepol_node_set_mask(sepol_handle_t * handle, 67 | sepol_node_t * node, 68 | int proto, const char *mask); 69 | 70 | extern int sepol_node_set_mask_bytes(sepol_handle_t * handle, 71 | sepol_node_t * node, 72 | const char *mask, size_t mask_sz); 73 | 74 | /* Protocol */ 75 | extern int sepol_node_get_proto(const sepol_node_t * node); 76 | 77 | extern void sepol_node_set_proto(sepol_node_t * node, int proto); 78 | 79 | extern const char *sepol_node_get_proto_str(int proto); 80 | 81 | /* Context */ 82 | extern sepol_context_t *sepol_node_get_con(const sepol_node_t * node); 83 | 84 | extern int sepol_node_set_con(sepol_handle_t * handle, 85 | sepol_node_t * node, sepol_context_t * con); 86 | 87 | /* Create/Clone/Destroy */ 88 | extern int sepol_node_create(sepol_handle_t * handle, sepol_node_t ** node_ptr); 89 | 90 | extern int sepol_node_clone(sepol_handle_t * handle, 91 | const sepol_node_t * node, 92 | sepol_node_t ** node_ptr); 93 | 94 | extern void sepol_node_free(sepol_node_t * node); 95 | 96 | #ifdef __cplusplus 97 | } 98 | #endif 99 | 100 | #endif 101 | -------------------------------------------------------------------------------- /libsepol/include/sepol/nodes.h: -------------------------------------------------------------------------------- 1 | #ifndef _SEPOL_NODES_H_ 2 | #define _SEPOL_NODES_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | 12 | /* Return the number of nodes */ 13 | extern int sepol_node_count(sepol_handle_t * handle, 14 | const sepol_policydb_t * p, unsigned int *response); 15 | 16 | /* Check if a node exists */ 17 | extern int sepol_node_exists(sepol_handle_t * handle, 18 | const sepol_policydb_t * policydb, 19 | const sepol_node_key_t * key, int *response); 20 | 21 | /* Query a node - returns the node, or NULL if not found */ 22 | extern int sepol_node_query(sepol_handle_t * handle, 23 | const sepol_policydb_t * policydb, 24 | const sepol_node_key_t * key, 25 | sepol_node_t ** response); 26 | 27 | /* Modify a node, or add it, if the key is not found */ 28 | extern int sepol_node_modify(sepol_handle_t * handle, 29 | sepol_policydb_t * policydb, 30 | const sepol_node_key_t * key, 31 | const sepol_node_t * data); 32 | 33 | /* Iterate the nodes 34 | * The handler may return: 35 | * -1 to signal an error condition, 36 | * 1 to signal successful exit 37 | * 0 to signal continue */ 38 | 39 | extern int sepol_node_iterate(sepol_handle_t * handle, 40 | const sepol_policydb_t * policydb, 41 | int (*fn) (const sepol_node_t * node, 42 | void *fn_arg), void *arg); 43 | 44 | #ifdef __cplusplus 45 | } 46 | #endif 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /libsepol/include/sepol/policydb/avrule_block.h: -------------------------------------------------------------------------------- 1 | /* Authors: Jason Tang 2 | * 3 | * Copyright (C) 2005 Tresys Technology, LLC 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef _SEPOL_AVRULE_BLOCK_H_ 21 | #define _SEPOL_AVRULE_BLOCK_H_ 22 | 23 | #include 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | extern avrule_block_t *avrule_block_create(void); 30 | extern void avrule_block_destroy(avrule_block_t * x); 31 | extern avrule_decl_t *avrule_decl_create(uint32_t decl_id); 32 | extern void avrule_decl_destroy(avrule_decl_t * x); 33 | extern void avrule_block_list_destroy(avrule_block_t * x); 34 | extern avrule_decl_t *get_avrule_decl(policydb_t * p, uint32_t decl_id); 35 | extern cond_list_t *get_decl_cond_list(policydb_t * p, 36 | avrule_decl_t * decl, 37 | cond_list_t * cond); 38 | extern int is_id_enabled(char *id, policydb_t * p, int symbol_table); 39 | extern int is_perm_enabled(char *class_id, char *perm_id, policydb_t * p); 40 | 41 | #ifdef __cplusplus 42 | } 43 | #endif 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /libsepol/include/sepol/policydb/constraint.h: -------------------------------------------------------------------------------- 1 | /* Author : Stephen Smalley, */ 2 | 3 | /* FLASK */ 4 | 5 | /* 6 | * A constraint is a condition that must be satisfied in 7 | * order for one or more permissions to be granted. 8 | * Constraints are used to impose additional restrictions 9 | * beyond the type-based rules in `te' or the role-based 10 | * transition rules in `rbac'. Constraints are typically 11 | * used to prevent a process from transitioning to a new user 12 | * identity or role unless it is in a privileged type. 13 | * Constraints are likewise typically used to prevent a 14 | * process from labeling an object with a different user 15 | * identity. 16 | */ 17 | 18 | #ifndef _SEPOL_POLICYDB_CONSTRAINT_H_ 19 | #define _SEPOL_POLICYDB_CONSTRAINT_H_ 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | #define CEXPR_MAXDEPTH 5 30 | 31 | struct type_set; 32 | 33 | typedef struct constraint_expr { 34 | #define CEXPR_NOT 1 /* not expr */ 35 | #define CEXPR_AND 2 /* expr and expr */ 36 | #define CEXPR_OR 3 /* expr or expr */ 37 | #define CEXPR_ATTR 4 /* attr op attr */ 38 | #define CEXPR_NAMES 5 /* attr op names */ 39 | uint32_t expr_type; /* expression type */ 40 | 41 | #define CEXPR_USER 1 /* user */ 42 | #define CEXPR_ROLE 2 /* role */ 43 | #define CEXPR_TYPE 4 /* type */ 44 | #define CEXPR_TARGET 8 /* target if set, source otherwise */ 45 | #define CEXPR_XTARGET 16 /* special 3rd target for validatetrans rule */ 46 | #define CEXPR_L1L2 32 /* low level 1 vs. low level 2 */ 47 | #define CEXPR_L1H2 64 /* low level 1 vs. high level 2 */ 48 | #define CEXPR_H1L2 128 /* high level 1 vs. low level 2 */ 49 | #define CEXPR_H1H2 256 /* high level 1 vs. high level 2 */ 50 | #define CEXPR_L1H1 512 /* low level 1 vs. high level 1 */ 51 | #define CEXPR_L2H2 1024 /* low level 2 vs. high level 2 */ 52 | uint32_t attr; /* attribute */ 53 | 54 | #define CEXPR_EQ 1 /* == or eq */ 55 | #define CEXPR_NEQ 2 /* != */ 56 | #define CEXPR_DOM 3 /* dom */ 57 | #define CEXPR_DOMBY 4 /* domby */ 58 | #define CEXPR_INCOMP 5 /* incomp */ 59 | uint32_t op; /* operator */ 60 | 61 | ebitmap_t names; /* names */ 62 | struct type_set *type_names; 63 | 64 | struct constraint_expr *next; /* next expression */ 65 | } constraint_expr_t; 66 | 67 | typedef struct constraint_node { 68 | sepol_access_vector_t permissions; /* constrained permissions */ 69 | constraint_expr_t *expr; /* constraint on permissions */ 70 | struct constraint_node *next; /* next constraint */ 71 | } constraint_node_t; 72 | 73 | struct policydb; 74 | 75 | extern int constraint_expr_init(constraint_expr_t * expr); 76 | extern void constraint_expr_destroy(constraint_expr_t * expr); 77 | 78 | #ifdef __cplusplus 79 | } 80 | #endif 81 | 82 | #endif /* _CONSTRAINT_H_ */ 83 | 84 | /* FLASK */ 85 | -------------------------------------------------------------------------------- /libsepol/include/sepol/policydb/flask_types.h: -------------------------------------------------------------------------------- 1 | /* -*- linux-c -*- */ 2 | 3 | /* 4 | * Author : Stephen Smalley, 5 | */ 6 | 7 | #ifndef _SEPOL_POLICYDB_FLASK_TYPES_H_ 8 | #define _SEPOL_POLICYDB_FLASK_TYPES_H_ 9 | 10 | /* 11 | * The basic Flask types and constants. 12 | */ 13 | 14 | #include 15 | #include 16 | 17 | #ifdef __cplusplus 18 | extern "C" { 19 | #endif 20 | 21 | /* 22 | * A security context is a set of security attributes 23 | * associated with each subject and object controlled 24 | * by the security policy. The security context type 25 | * is defined as a variable-length string that can be 26 | * interpreted by any application or user with an 27 | * understanding of the security policy. 28 | */ 29 | typedef char *sepol_security_context_t; 30 | 31 | /* 32 | * An access vector (AV) is a collection of related permissions 33 | * for a pair of SIDs. The bits within an access vector 34 | * are interpreted differently depending on the class of 35 | * the object. The access vector interpretations are specified 36 | * in flask/access_vectors, and the corresponding constants 37 | * for permissions are defined in the automatically generated 38 | * header file av_permissions.h. 39 | */ 40 | typedef uint32_t sepol_access_vector_t; 41 | 42 | /* 43 | * Each object class is identified by a fixed-size value. 44 | * The set of security classes is specified in flask/security_classes, 45 | * with the corresponding constants defined in the automatically 46 | * generated header file flask.h. 47 | */ 48 | typedef uint16_t sepol_security_class_t; 49 | #define SEPOL_SECCLASS_NULL 0x0000 /* no class */ 50 | 51 | #define SELINUX_MAGIC 0xf97cff8c 52 | #define SELINUX_MOD_MAGIC 0xf97cff8d 53 | 54 | typedef uint32_t sepol_security_id_t; 55 | #define SEPOL_SECSID_NULL 0 56 | 57 | struct sepol_av_decision { 58 | sepol_access_vector_t allowed; 59 | sepol_access_vector_t decided; 60 | sepol_access_vector_t auditallow; 61 | sepol_access_vector_t auditdeny; 62 | uint32_t seqno; 63 | }; 64 | 65 | #ifdef __cplusplus 66 | } 67 | #endif 68 | 69 | #endif 70 | -------------------------------------------------------------------------------- /libsepol/include/sepol/policydb/hierarchy.h: -------------------------------------------------------------------------------- 1 | /* Authors: Jason Tang 2 | * Joshua Brindle 3 | * Karl MacMillan 4 | * 5 | * A set of utility functions that aid policy decision when dealing 6 | * with hierarchal items. 7 | * 8 | * Copyright (C) 2005 Tresys Technology, LLC 9 | * 10 | * This library is free software; you can redistribute it and/or 11 | * modify it under the terms of the GNU Lesser General Public 12 | * License as published by the Free Software Foundation; either 13 | * version 2.1 of the License, or (at your option) any later version. 14 | * 15 | * This library is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | * Lesser General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU Lesser General Public 21 | * License along with this library; if not, write to the Free Software 22 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 23 | */ 24 | 25 | #ifndef _SEPOL_POLICYDB_HIERARCHY_H_ 26 | #define _SEPOL_POLICYDB_HIERARCHY_H_ 27 | 28 | #include 29 | #include 30 | 31 | #ifdef __cplusplus 32 | extern "C" { 33 | #endif 34 | 35 | extern int hierarchy_add_bounds(sepol_handle_t *handle, policydb_t *p); 36 | 37 | extern void bounds_destroy_bad(avtab_ptr_t cur); 38 | extern int bounds_check_type(sepol_handle_t *handle, policydb_t *p, uint32_t child, 39 | uint32_t parent, avtab_ptr_t *bad, int *numbad); 40 | 41 | extern int bounds_check_users(sepol_handle_t *handle, policydb_t *p); 42 | extern int bounds_check_roles(sepol_handle_t *handle, policydb_t *p); 43 | extern int bounds_check_types(sepol_handle_t *handle, policydb_t *p); 44 | 45 | extern int hierarchy_check_constraints(sepol_handle_t * handle, policydb_t * p); 46 | 47 | #ifdef __cplusplus 48 | } 49 | #endif 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /libsepol/include/sepol/policydb/link.h: -------------------------------------------------------------------------------- 1 | /* Authors: Jason Tang 2 | * Joshua Brindle 3 | * Karl MacMillan 4 | */ 5 | 6 | #ifndef _SEPOL_POLICYDB_LINK_H 7 | #define _SEPOL_POLICYDB_LINK_H 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | 14 | #include 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | extern int link_modules(sepol_handle_t * handle, 21 | policydb_t * b, policydb_t ** mods, int len, 22 | int verbose); 23 | 24 | #ifdef __cplusplus 25 | } 26 | #endif 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /libsepol/include/sepol/policydb/module.h: -------------------------------------------------------------------------------- 1 | /* Author: Karl MacMillan 2 | * 3 | * Copyright (C) 2004-2005 Tresys Technology, LLC 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef _SEPOL_POLICYDB_MODULE_H_ 21 | #define _SEPOL_POLICYDB_MODULE_H_ 22 | 23 | #include 24 | #include 25 | 26 | #include 27 | 28 | #include 29 | #include 30 | 31 | #define SEPOL_MODULE_PACKAGE_MAGIC 0xf97cff8f 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | struct sepol_module_package { 38 | sepol_policydb_t *policy; 39 | uint32_t version; 40 | char *file_contexts; 41 | size_t file_contexts_len; 42 | char *seusers; 43 | size_t seusers_len; 44 | char *user_extra; 45 | size_t user_extra_len; 46 | char *netfilter_contexts; 47 | size_t netfilter_contexts_len; 48 | }; 49 | 50 | extern int sepol_module_package_init(sepol_module_package_t * p); 51 | 52 | #ifdef __cplusplus 53 | } 54 | #endif 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /libsepol/include/sepol/policydb/polcaps.h: -------------------------------------------------------------------------------- 1 | #ifndef _SEPOL_POLICYDB_POLCAPS_H_ 2 | #define _SEPOL_POLICYDB_POLCAPS_H_ 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | /* Policy capabilities */ 9 | enum { 10 | POLICYDB_CAPABILITY_NETPEER, 11 | POLICYDB_CAPABILITY_OPENPERM, 12 | POLICYDB_CAPABILITY_EXTSOCKCLASS, 13 | POLICYDB_CAPABILITY_ALWAYSNETWORK, 14 | POLICYDB_CAPABILITY_CGROUPSECLABEL, 15 | POLICYDB_CAPABILITY_NNP_NOSUID_TRANSITION, 16 | POLICYDB_CAPABILITY_GENFS_SECLABEL_SYMLINKS, 17 | __POLICYDB_CAPABILITY_MAX 18 | }; 19 | #define POLICYDB_CAPABILITY_MAX (__POLICYDB_CAPABILITY_MAX - 1) 20 | 21 | /* Convert a capability name to number. */ 22 | extern int sepol_polcap_getnum(const char *name); 23 | 24 | /* Convert a capability number to name. */ 25 | extern const char *sepol_polcap_getname(unsigned int capnum); 26 | 27 | #ifdef __cplusplus 28 | } 29 | #endif 30 | 31 | #endif /* _SEPOL_POLICYDB_POLCAPS_H_ */ 32 | -------------------------------------------------------------------------------- /libsepol/include/sepol/policydb/sidtab.h: -------------------------------------------------------------------------------- 1 | /* Author : Stephen Smalley, */ 2 | 3 | /* FLASK */ 4 | 5 | /* 6 | * A security identifier table (sidtab) is a hash table 7 | * of security context structures indexed by SID value. 8 | */ 9 | 10 | #ifndef _SEPOL_POLICYDB_SIDTAB_H_ 11 | #define _SEPOL_POLICYDB_SIDTAB_H_ 12 | 13 | #include 14 | 15 | #ifdef __cplusplus 16 | extern "C" { 17 | #endif 18 | 19 | typedef struct sidtab_node { 20 | sepol_security_id_t sid; /* security identifier */ 21 | context_struct_t context; /* security context structure */ 22 | struct sidtab_node *next; 23 | } sidtab_node_t; 24 | 25 | typedef struct sidtab_node *sidtab_ptr_t; 26 | 27 | #define SIDTAB_HASH_BITS 7 28 | #define SIDTAB_HASH_BUCKETS (1 << SIDTAB_HASH_BITS) 29 | #define SIDTAB_HASH_MASK (SIDTAB_HASH_BUCKETS-1) 30 | 31 | #define SIDTAB_SIZE SIDTAB_HASH_BUCKETS 32 | 33 | typedef struct { 34 | sidtab_ptr_t *htable; 35 | unsigned int nel; /* number of elements */ 36 | unsigned int next_sid; /* next SID to allocate */ 37 | unsigned char shutdown; 38 | } sidtab_t; 39 | 40 | extern int sepol_sidtab_init(sidtab_t * s); 41 | 42 | extern int sepol_sidtab_insert(sidtab_t * s, 43 | sepol_security_id_t sid, 44 | context_struct_t * context); 45 | 46 | extern context_struct_t *sepol_sidtab_search(sidtab_t * s, 47 | sepol_security_id_t sid); 48 | 49 | extern int sepol_sidtab_map(sidtab_t * s, 50 | int (*apply) (sepol_security_id_t sid, 51 | context_struct_t * context, 52 | void *args), void *args); 53 | 54 | extern void sepol_sidtab_map_remove_on_error(sidtab_t * s, 55 | int (*apply) (sepol_security_id_t 56 | s, 57 | context_struct_t * 58 | context, void *args), 59 | void *args); 60 | 61 | extern int sepol_sidtab_context_to_sid(sidtab_t * s, /* IN */ 62 | context_struct_t * context, /* IN */ 63 | sepol_security_id_t * sid); /* OUT */ 64 | 65 | extern void sepol_sidtab_hash_eval(sidtab_t * h, char *tag); 66 | 67 | extern void sepol_sidtab_destroy(sidtab_t * s); 68 | 69 | extern void sepol_sidtab_set(sidtab_t * dst, sidtab_t * src); 70 | 71 | extern void sepol_sidtab_shutdown(sidtab_t * s); 72 | 73 | #ifdef __cplusplus 74 | } 75 | #endif 76 | 77 | #endif /* _SIDTAB_H_ */ 78 | 79 | /* FLASK */ 80 | -------------------------------------------------------------------------------- /libsepol/include/sepol/policydb/symtab.h: -------------------------------------------------------------------------------- 1 | 2 | /* Author : Stephen Smalley, */ 3 | 4 | /* FLASK */ 5 | 6 | /* 7 | * A symbol table (symtab) maintains associations between symbol 8 | * strings and datum values. The type of the datum values 9 | * is arbitrary. The symbol table type is implemented 10 | * using the hash table type (hashtab). 11 | */ 12 | 13 | #ifndef _SEPOL_POLICYDB_SYMTAB_H_ 14 | #define _SEPOL_POLICYDB_SYMTAB_H_ 15 | 16 | #include 17 | 18 | #ifdef __cplusplus 19 | extern "C" { 20 | #endif 21 | 22 | /* The symtab_datum struct stores the common information for 23 | * all symtab datums. It should the first element in every 24 | * struct that will be used in a symtab to allow the specific 25 | * datum types to be freely cast to this type. 26 | * 27 | * The values start at 1 - 0 is never a valid value. 28 | */ 29 | typedef struct symtab_datum { 30 | uint32_t value; 31 | } symtab_datum_t; 32 | 33 | typedef struct { 34 | hashtab_t table; /* hash table (keyed on a string) */ 35 | uint32_t nprim; /* number of primary names in table */ 36 | } symtab_t; 37 | 38 | extern int symtab_init(symtab_t *, unsigned int size); 39 | extern void symtab_destroy(symtab_t *); 40 | 41 | #ifdef __cplusplus 42 | } 43 | #endif 44 | 45 | #endif /* _SYMTAB_H_ */ 46 | 47 | /* FLASK */ 48 | -------------------------------------------------------------------------------- /libsepol/include/sepol/policydb/util.h: -------------------------------------------------------------------------------- 1 | /* Authors: Karl MacMillan 2 | * 3 | * A set of utility functions that aid policy decision when dealing 4 | * with hierarchal namespaces. 5 | * 6 | * Copyright (C) 2006 Tresys Technology, LLC 7 | * 8 | * This library is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public 10 | * License as published by the Free Software Foundation; either 11 | * version 2.1 of the License, or (at your option) any later version. 12 | * 13 | * This library is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | * Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public 19 | * License along with this library; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | */ 22 | 23 | #ifndef __SEPOL_UTIL_H__ 24 | #define __SEPOL_UTIL_H__ 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | extern int add_i_to_a(uint32_t i, uint32_t * cnt, uint32_t ** a); 31 | 32 | extern char *sepol_av_to_string(policydb_t * policydbp, uint32_t tclass, 33 | sepol_access_vector_t av); 34 | 35 | char *sepol_extended_perms_to_string(avtab_extended_perms_t *xperms); 36 | 37 | /* 38 | * The tokenize function may be used to 39 | * replace sscanf 40 | */ 41 | extern int tokenize(char *line_buf, char delim, int num_args, ...); 42 | 43 | #ifdef __cplusplus 44 | } 45 | #endif 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /libsepol/include/sepol/port_record.h: -------------------------------------------------------------------------------- 1 | #ifndef _SEPOL_PORT_RECORD_H_ 2 | #define _SEPOL_PORT_RECORD_H_ 3 | 4 | #include 5 | #include 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | 11 | struct sepol_port; 12 | struct sepol_port_key; 13 | typedef struct sepol_port sepol_port_t; 14 | typedef struct sepol_port_key sepol_port_key_t; 15 | 16 | #define SEPOL_PROTO_UDP 0 17 | #define SEPOL_PROTO_TCP 1 18 | #define SEPOL_PROTO_DCCP 2 19 | #define SEPOL_PROTO_SCTP 3 20 | 21 | /* Key */ 22 | extern int sepol_port_compare(const sepol_port_t * port, 23 | const sepol_port_key_t * key); 24 | 25 | extern int sepol_port_compare2(const sepol_port_t * port, 26 | const sepol_port_t * port2); 27 | 28 | extern int sepol_port_key_create(sepol_handle_t * handle, 29 | int low, int high, int proto, 30 | sepol_port_key_t ** key_ptr); 31 | 32 | extern void sepol_port_key_unpack(const sepol_port_key_t * key, 33 | int *low, int *high, int *proto); 34 | 35 | extern int sepol_port_key_extract(sepol_handle_t * handle, 36 | const sepol_port_t * port, 37 | sepol_port_key_t ** key_ptr); 38 | 39 | extern void sepol_port_key_free(sepol_port_key_t * key); 40 | 41 | /* Protocol */ 42 | extern int sepol_port_get_proto(const sepol_port_t * port); 43 | 44 | extern void sepol_port_set_proto(sepol_port_t * port, int proto); 45 | 46 | extern const char *sepol_port_get_proto_str(int proto); 47 | 48 | /* Port */ 49 | extern int sepol_port_get_low(const sepol_port_t * port); 50 | 51 | extern int sepol_port_get_high(const sepol_port_t * port); 52 | 53 | extern void sepol_port_set_port(sepol_port_t * port, int port_num); 54 | 55 | extern void sepol_port_set_range(sepol_port_t * port, int low, int high); 56 | 57 | /* Context */ 58 | extern sepol_context_t *sepol_port_get_con(const sepol_port_t * port); 59 | 60 | extern int sepol_port_set_con(sepol_handle_t * handle, 61 | sepol_port_t * port, sepol_context_t * con); 62 | 63 | /* Create/Clone/Destroy */ 64 | extern int sepol_port_create(sepol_handle_t * handle, sepol_port_t ** port_ptr); 65 | 66 | extern int sepol_port_clone(sepol_handle_t * handle, 67 | const sepol_port_t * port, 68 | sepol_port_t ** port_ptr); 69 | 70 | extern void sepol_port_free(sepol_port_t * port); 71 | 72 | #ifdef __cplusplus 73 | } 74 | #endif 75 | 76 | #endif 77 | -------------------------------------------------------------------------------- /libsepol/include/sepol/ports.h: -------------------------------------------------------------------------------- 1 | #ifndef _SEPOL_PORTS_H_ 2 | #define _SEPOL_PORTS_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | 12 | /* Return the number of ports */ 13 | extern int sepol_port_count(sepol_handle_t * handle, 14 | const sepol_policydb_t * p, unsigned int *response); 15 | 16 | /* Check if a port exists */ 17 | extern int sepol_port_exists(sepol_handle_t * handle, 18 | const sepol_policydb_t * policydb, 19 | const sepol_port_key_t * key, int *response); 20 | 21 | /* Query a port - returns the port, or NULL if not found */ 22 | extern int sepol_port_query(sepol_handle_t * handle, 23 | const sepol_policydb_t * policydb, 24 | const sepol_port_key_t * key, 25 | sepol_port_t ** response); 26 | 27 | /* Modify a port, or add it, if the key is not found */ 28 | extern int sepol_port_modify(sepol_handle_t * handle, 29 | sepol_policydb_t * policydb, 30 | const sepol_port_key_t * key, 31 | const sepol_port_t * data); 32 | 33 | /* Iterate the ports 34 | * The handler may return: 35 | * -1 to signal an error condition, 36 | * 1 to signal successful exit 37 | * 0 to signal continue */ 38 | 39 | extern int sepol_port_iterate(sepol_handle_t * handle, 40 | const sepol_policydb_t * policydb, 41 | int (*fn) (const sepol_port_t * port, 42 | void *fn_arg), void *arg); 43 | 44 | #ifdef __cplusplus 45 | } 46 | #endif 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /libsepol/include/sepol/roles.h: -------------------------------------------------------------------------------- 1 | #ifndef _SEPOL_ROLES_H_ 2 | #define _SEPOL_ROLES_H_ 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | extern int sepol_role_exists(const sepol_policydb_t * policydb, 9 | const char *role, int *response); 10 | 11 | extern int sepol_role_list(const sepol_policydb_t * policydb, 12 | char ***roles, unsigned int *nroles); 13 | 14 | #ifdef __cplusplus 15 | } 16 | #endif 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /libsepol/include/sepol/sepol.h: -------------------------------------------------------------------------------- 1 | #ifndef _SEPOL_H_ 2 | #define _SEPOL_H_ 3 | 4 | #include 5 | #include 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | /* Set internal policydb from a file for subsequent service calls. */ 34 | extern int sepol_set_policydb_from_file(FILE * fp); 35 | 36 | #ifdef __cplusplus 37 | } 38 | #endif 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /libsepol/include/sepol/user_record.h: -------------------------------------------------------------------------------- 1 | #ifndef _SEPOL_USER_RECORD_H_ 2 | #define _SEPOL_USER_RECORD_H_ 3 | 4 | #include 5 | #include 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | 11 | struct sepol_user; 12 | struct sepol_user_key; 13 | typedef struct sepol_user sepol_user_t; 14 | typedef struct sepol_user_key sepol_user_key_t; 15 | 16 | /* Key */ 17 | extern int sepol_user_key_create(sepol_handle_t * handle, 18 | const char *name, sepol_user_key_t ** key); 19 | 20 | extern void sepol_user_key_unpack(const sepol_user_key_t * key, 21 | const char **name); 22 | 23 | extern int sepol_user_key_extract(sepol_handle_t * handle, 24 | const sepol_user_t * user, 25 | sepol_user_key_t ** key_ptr); 26 | 27 | extern void sepol_user_key_free(sepol_user_key_t * key); 28 | 29 | extern int sepol_user_compare(const sepol_user_t * user, 30 | const sepol_user_key_t * key); 31 | 32 | extern int sepol_user_compare2(const sepol_user_t * user, 33 | const sepol_user_t * user2); 34 | 35 | /* Name */ 36 | extern const char *sepol_user_get_name(const sepol_user_t * user); 37 | 38 | extern int sepol_user_set_name(sepol_handle_t * handle, 39 | sepol_user_t * user, const char *name); 40 | 41 | /* MLS */ 42 | extern const char *sepol_user_get_mlslevel(const sepol_user_t * user); 43 | 44 | extern int sepol_user_set_mlslevel(sepol_handle_t * handle, 45 | sepol_user_t * user, const char *mls_level); 46 | 47 | extern const char *sepol_user_get_mlsrange(const sepol_user_t * user); 48 | 49 | extern int sepol_user_set_mlsrange(sepol_handle_t * handle, 50 | sepol_user_t * user, const char *mls_range); 51 | 52 | /* Role management */ 53 | extern int sepol_user_get_num_roles(const sepol_user_t * user); 54 | 55 | extern int sepol_user_add_role(sepol_handle_t * handle, 56 | sepol_user_t * user, const char *role); 57 | 58 | extern void sepol_user_del_role(sepol_user_t * user, const char *role); 59 | 60 | extern int sepol_user_has_role(const sepol_user_t * user, const char *role); 61 | 62 | extern int sepol_user_get_roles(sepol_handle_t * handle, 63 | const sepol_user_t * user, 64 | const char ***roles_arr, 65 | unsigned int *num_roles); 66 | 67 | extern int sepol_user_set_roles(sepol_handle_t * handle, 68 | sepol_user_t * user, 69 | const char **roles_arr, unsigned int num_roles); 70 | 71 | /* Create/Clone/Destroy */ 72 | extern int sepol_user_create(sepol_handle_t * handle, sepol_user_t ** user_ptr); 73 | 74 | extern int sepol_user_clone(sepol_handle_t * handle, 75 | const sepol_user_t * user, 76 | sepol_user_t ** user_ptr); 77 | 78 | extern void sepol_user_free(sepol_user_t * user); 79 | 80 | #ifdef __cplusplus 81 | } 82 | #endif 83 | 84 | #endif 85 | -------------------------------------------------------------------------------- /libsepol/include/sepol/users.h: -------------------------------------------------------------------------------- 1 | #ifndef _SEPOL_USERS_H_ 2 | #define _SEPOL_USERS_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /* These two functions are deprecated. See src/deprecated_funcs.c */ 14 | extern int sepol_genusers(void *data, size_t len, 15 | const char *usersdir, 16 | void **newdata, size_t * newlen); 17 | extern void sepol_set_delusers(int on); 18 | 19 | /* Modify the user, or add it, if the key is not found */ 20 | extern int sepol_user_modify(sepol_handle_t * handle, 21 | sepol_policydb_t * policydb, 22 | const sepol_user_key_t * key, 23 | const sepol_user_t * data); 24 | 25 | /* Return the number of users */ 26 | extern int sepol_user_count(sepol_handle_t * handle, 27 | const sepol_policydb_t * p, unsigned int *response); 28 | 29 | /* Check if the specified user exists */ 30 | extern int sepol_user_exists(sepol_handle_t * handle, 31 | const sepol_policydb_t * policydb, 32 | const sepol_user_key_t * key, int *response); 33 | 34 | /* Query a user - returns the user or NULL if not found */ 35 | extern int sepol_user_query(sepol_handle_t * handle, 36 | const sepol_policydb_t * p, 37 | const sepol_user_key_t * key, 38 | sepol_user_t ** response); 39 | 40 | /* Iterate the users 41 | * The handler may return: 42 | * -1 to signal an error condition, 43 | * 1 to signal successful exit 44 | * 0 to signal continue */ 45 | extern int sepol_user_iterate(sepol_handle_t * handle, 46 | const sepol_policydb_t * policydb, 47 | int (*fn) (const sepol_user_t * user, 48 | void *fn_arg), void *arg); 49 | 50 | #ifdef __cplusplus 51 | } 52 | #endif 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /libsepol/kernel_to_common.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include 6 | #include 7 | 8 | 9 | #define STACK_SIZE 16 10 | #define DEFAULT_LEVEL "systemlow" 11 | #define DEFAULT_OBJECT "object_r" 12 | 13 | // initial sid names aren't actually stored in the pp files, need to a have 14 | // a mapping, taken from the linux kernel 15 | static const char * const selinux_sid_to_str[] = { 16 | "null", 17 | "kernel", 18 | "security", 19 | "unlabeled", 20 | "fs", 21 | "file", 22 | "file_labels", 23 | "init", 24 | "any_socket", 25 | "port", 26 | "netif", 27 | "netmsg", 28 | "node", 29 | "igmp_packet", 30 | "icmp_socket", 31 | "tcp_socket", 32 | "sysctl_modprobe", 33 | "sysctl", 34 | "sysctl_fs", 35 | "sysctl_kernel", 36 | "sysctl_net", 37 | "sysctl_net_unix", 38 | "sysctl_vm", 39 | "sysctl_dev", 40 | "kmod", 41 | "policy", 42 | "scmp_packet", 43 | "devnull", 44 | }; 45 | 46 | #define SELINUX_SID_SZ (sizeof(selinux_sid_to_str)/sizeof(selinux_sid_to_str[0])) 47 | 48 | static const char * const xen_sid_to_str[] = { 49 | "null", 50 | "xen", 51 | "dom0", 52 | "domio", 53 | "domxen", 54 | "unlabeled", 55 | "security", 56 | "ioport", 57 | "iomem", 58 | "irq", 59 | "device", 60 | "domU", 61 | "domDM", 62 | }; 63 | 64 | #define XEN_SID_SZ (sizeof(xen_sid_to_str)/sizeof(xen_sid_to_str[0])) 65 | 66 | static const uint32_t avtab_flavors[] = { 67 | AVTAB_ALLOWED, 68 | AVTAB_AUDITALLOW, 69 | AVTAB_AUDITDENY, 70 | AVTAB_XPERMS_ALLOWED, 71 | AVTAB_XPERMS_AUDITALLOW, 72 | AVTAB_XPERMS_DONTAUDIT, 73 | AVTAB_TRANSITION, 74 | AVTAB_MEMBER, 75 | AVTAB_CHANGE, 76 | }; 77 | 78 | #define AVTAB_FLAVORS_SZ (sizeof(avtab_flavors)/sizeof(avtab_flavors[0])) 79 | 80 | struct strs { 81 | char **list; 82 | unsigned num; 83 | size_t size; 84 | }; 85 | 86 | __attribute__ ((format(printf, 1, 2))) 87 | void sepol_log_err(const char *fmt, ...); 88 | void sepol_indent(FILE *out, int indent); 89 | __attribute__ ((format(printf, 2, 3))) 90 | void sepol_printf(FILE *out, const char *fmt, ...); 91 | 92 | __attribute__ ((format(printf, 1, 3))) 93 | char *create_str(const char *fmt, int num, ...); 94 | 95 | int strs_init(struct strs **strs, size_t size); 96 | void strs_destroy(struct strs **strs); 97 | void strs_free_all(struct strs *strs); 98 | int strs_add(struct strs *strs, char *s); 99 | __attribute__ ((format(printf, 2, 4))) 100 | int strs_create_and_add(struct strs *strs, const char *fmt, int num, ...); 101 | char *strs_remove_last(struct strs *strs); 102 | int strs_add_at_index(struct strs *strs, char *s, unsigned index); 103 | char *strs_read_at_index(struct strs *strs, unsigned index); 104 | void strs_sort(struct strs *strs); 105 | unsigned strs_num_items(struct strs *strs); 106 | size_t strs_len_items(struct strs *strs); 107 | char *strs_to_str(struct strs *strs); 108 | void strs_write_each(struct strs *strs, FILE *out); 109 | void strs_write_each_indented(struct strs *strs, FILE *out, int indent); 110 | int hashtab_ordered_to_strs(char *key, void *data, void *args); 111 | int ebitmap_to_strs(struct ebitmap *map, struct strs *strs, char **val_to_name); 112 | char *ebitmap_to_str(struct ebitmap *map, char **val_to_name, int sort); 113 | 114 | int strs_stack_init(struct strs **stack); 115 | void strs_stack_destroy(struct strs **stack); 116 | int strs_stack_push(struct strs *stack, char *s); 117 | char *strs_stack_pop(struct strs *stack); 118 | int strs_stack_empty(struct strs *stack); 119 | 120 | int sort_ocontexts(struct policydb *pdb); 121 | -------------------------------------------------------------------------------- /libsepol/mls.h: -------------------------------------------------------------------------------- 1 | /* Author: Stephen Smalley, 2 | * Updated: Trusted Computer Solutions, Inc. 3 | * 4 | * Support for enhanced MLS infrastructure. 5 | * 6 | * Copyright (C) 2004-2005 Trusted Computer Solutions, Inc. 7 | * 8 | * This library is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public 10 | * License as published by the Free Software Foundation; either 11 | * version 2.1 of the License, or (at your option) any later version. 12 | * 13 | * This library is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | * Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public 19 | * License along with this library; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | */ 22 | 23 | #ifndef _SEPOL_MLS_INTERNAL_H_ 24 | #define _SEPOL_MLS_INTERNAL_H_ 25 | 26 | #include "policydb_internal.h" 27 | #include 28 | #include "handle.h" 29 | 30 | extern int mls_from_string(sepol_handle_t * handle, 31 | const policydb_t * policydb, 32 | const char *str, context_struct_t * mls); 33 | 34 | extern int mls_to_string(sepol_handle_t * handle, 35 | const policydb_t * policydb, 36 | const context_struct_t * mls, char **str); 37 | 38 | /* Deprecated */ 39 | extern int mls_compute_context_len(const policydb_t * policydb, 40 | const context_struct_t * context); 41 | 42 | /* Deprecated */ 43 | extern void mls_sid_to_context(const policydb_t * policydb, 44 | const context_struct_t * context, 45 | char **scontext); 46 | 47 | /* Deprecated */ 48 | extern int mls_context_to_sid(const policydb_t * policydb, 49 | char oldc, 50 | char **scontext, context_struct_t * context); 51 | 52 | extern int mls_context_isvalid(const policydb_t * p, 53 | const context_struct_t * c); 54 | 55 | extern int mls_convert_context(policydb_t * oldp, 56 | policydb_t * newp, context_struct_t * context); 57 | 58 | extern int mls_compute_sid(policydb_t * policydb, 59 | context_struct_t * scontext, 60 | context_struct_t * tcontext, 61 | sepol_security_class_t tclass, 62 | uint32_t specified, context_struct_t * newcontext); 63 | 64 | extern int mls_setup_user_range(context_struct_t * fromcon, user_datum_t * user, 65 | context_struct_t * usercon, int mls); 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /libsepol/module_internal.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include "dso.h" 3 | 4 | hidden_proto(sepol_module_package_create) 5 | hidden_proto(sepol_module_package_free) 6 | -------------------------------------------------------------------------------- /libsepol/node_internal.h: -------------------------------------------------------------------------------- 1 | #ifndef _SEPOL_NODE_INTERNAL_H_ 2 | #define _SEPOL_NODE_INTERNAL_H_ 3 | 4 | #include 5 | #include 6 | #include "dso.h" 7 | 8 | hidden_proto(sepol_node_create) 9 | hidden_proto(sepol_node_key_free) 10 | hidden_proto(sepol_node_free) 11 | hidden_proto(sepol_node_get_con) 12 | hidden_proto(sepol_node_get_addr) 13 | hidden_proto(sepol_node_get_addr_bytes) 14 | hidden_proto(sepol_node_get_mask) 15 | hidden_proto(sepol_node_get_mask_bytes) 16 | hidden_proto(sepol_node_get_proto) 17 | hidden_proto(sepol_node_get_proto_str) 18 | hidden_proto(sepol_node_key_create) 19 | hidden_proto(sepol_node_key_unpack) 20 | hidden_proto(sepol_node_set_con) 21 | hidden_proto(sepol_node_set_addr) 22 | hidden_proto(sepol_node_set_addr_bytes) 23 | hidden_proto(sepol_node_set_mask) 24 | hidden_proto(sepol_node_set_mask_bytes) 25 | hidden_proto(sepol_node_set_proto) 26 | #endif 27 | -------------------------------------------------------------------------------- /libsepol/polcaps.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Policy capability support functions 3 | */ 4 | 5 | #include 6 | #include 7 | 8 | static const char *polcap_names[] = { 9 | "network_peer_controls", /* POLICYDB_CAPABILITY_NETPEER */ 10 | "open_perms", /* POLICYDB_CAPABILITY_OPENPERM */ 11 | "extended_socket_class", /* POLICYDB_CAPABILITY_EXTSOCKCLASS */ 12 | "always_check_network", /* POLICYDB_CAPABILITY_ALWAYSNETWORK */ 13 | "cgroup_seclabel", /* POLICYDB_CAPABILITY_SECLABEL */ 14 | "nnp_nosuid_transition", /* POLICYDB_CAPABILITY_NNP_NOSUID_TRANSITION */ 15 | "genfs_seclabel_symlinks", /* POLICYDB_CAPABILITY_GENFS_SECLABEL_SYMLINKS */ 16 | NULL 17 | }; 18 | 19 | int sepol_polcap_getnum(const char *name) 20 | { 21 | int capnum; 22 | 23 | for (capnum = 0; capnum <= POLICYDB_CAPABILITY_MAX; capnum++) { 24 | if (polcap_names[capnum] == NULL) 25 | continue; 26 | if (strcasecmp(polcap_names[capnum], name) == 0) 27 | return capnum; 28 | } 29 | return -1; 30 | } 31 | 32 | const char *sepol_polcap_getname(unsigned int capnum) 33 | { 34 | if (capnum > POLICYDB_CAPABILITY_MAX) 35 | return NULL; 36 | 37 | return polcap_names[capnum]; 38 | } 39 | -------------------------------------------------------------------------------- /libsepol/policydb_convert.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "private.h" 4 | #include "debug.h" 5 | 6 | #include 7 | 8 | /* Construct a policydb from the supplied (data, len) pair */ 9 | 10 | int policydb_from_image(sepol_handle_t * handle, 11 | void *data, size_t len, policydb_t * policydb) 12 | { 13 | 14 | policy_file_t pf; 15 | 16 | policy_file_init(&pf); 17 | pf.type = PF_USE_MEMORY; 18 | pf.data = data; 19 | pf.len = len; 20 | pf.handle = handle; 21 | 22 | if (policydb_read(policydb, &pf, 0)) { 23 | policydb_destroy(policydb); 24 | ERR(handle, "policy image is invalid"); 25 | errno = EINVAL; 26 | return STATUS_ERR; 27 | } 28 | 29 | return STATUS_SUCCESS; 30 | } 31 | 32 | /* Write a policydb to a memory region, and return the (data, len) pair. */ 33 | 34 | int policydb_to_image(sepol_handle_t * handle, 35 | policydb_t * policydb, void **newdata, size_t * newlen) 36 | { 37 | 38 | void *tmp_data = NULL; 39 | size_t tmp_len; 40 | policy_file_t pf; 41 | struct policydb tmp_policydb; 42 | 43 | /* Compute the length for the new policy image. */ 44 | policy_file_init(&pf); 45 | pf.type = PF_LEN; 46 | pf.handle = handle; 47 | if (policydb_write(policydb, &pf)) { 48 | ERR(handle, "could not compute policy length"); 49 | errno = EINVAL; 50 | goto err; 51 | } 52 | 53 | /* Allocate the new policy image. */ 54 | pf.type = PF_USE_MEMORY; 55 | pf.data = malloc(pf.len); 56 | if (!pf.data) { 57 | ERR(handle, "out of memory"); 58 | goto err; 59 | } 60 | 61 | /* Need to save len and data prior to modification by policydb_write. */ 62 | tmp_len = pf.len; 63 | tmp_data = pf.data; 64 | 65 | /* Write out the new policy image. */ 66 | if (policydb_write(policydb, &pf)) { 67 | ERR(handle, "could not write policy"); 68 | errno = EINVAL; 69 | goto err; 70 | } 71 | 72 | /* Verify the new policy image. */ 73 | pf.type = PF_USE_MEMORY; 74 | pf.data = tmp_data; 75 | pf.len = tmp_len; 76 | if (policydb_init(&tmp_policydb)) { 77 | ERR(handle, "Out of memory"); 78 | errno = ENOMEM; 79 | goto err; 80 | } 81 | if (policydb_read(&tmp_policydb, &pf, 0)) { 82 | ERR(handle, "new policy image is invalid"); 83 | errno = EINVAL; 84 | goto err; 85 | } 86 | policydb_destroy(&tmp_policydb); 87 | 88 | /* Update (newdata, newlen) */ 89 | *newdata = tmp_data; 90 | *newlen = tmp_len; 91 | 92 | /* Recover */ 93 | return STATUS_SUCCESS; 94 | 95 | err: 96 | ERR(handle, "could not create policy image"); 97 | 98 | /* Recover */ 99 | free(tmp_data); 100 | return STATUS_ERR; 101 | } 102 | -------------------------------------------------------------------------------- /libsepol/policydb_internal.h: -------------------------------------------------------------------------------- 1 | #ifndef _SEPOL_POLICYDB_INTERNAL_H_ 2 | #define _SEPOL_POLICYDB_INTERNAL_H_ 3 | 4 | #include 5 | #include "dso.h" 6 | 7 | hidden_proto(sepol_policydb_create) 8 | hidden_proto(sepol_policydb_free) 9 | extern const char *policydb_target_strings[]; 10 | #endif 11 | -------------------------------------------------------------------------------- /libsepol/port_internal.h: -------------------------------------------------------------------------------- 1 | #ifndef _SEPOL_PORT_INTERNAL_H_ 2 | #define _SEPOL_PORT_INTERNAL_H_ 3 | 4 | #include 5 | #include 6 | #include "dso.h" 7 | 8 | hidden_proto(sepol_port_create) 9 | hidden_proto(sepol_port_free) 10 | hidden_proto(sepol_port_get_con) 11 | hidden_proto(sepol_port_get_high) 12 | hidden_proto(sepol_port_get_low) 13 | hidden_proto(sepol_port_get_proto) 14 | hidden_proto(sepol_port_get_proto_str) 15 | hidden_proto(sepol_port_key_create) 16 | hidden_proto(sepol_port_key_unpack) 17 | hidden_proto(sepol_port_set_con) 18 | hidden_proto(sepol_port_set_proto) 19 | hidden_proto(sepol_port_set_range) 20 | #endif 21 | -------------------------------------------------------------------------------- /libsepol/private.h: -------------------------------------------------------------------------------- 1 | /* Private definitions for libsepol. */ 2 | 3 | /* Endian conversion for reading and writing binary policies */ 4 | 5 | #include 6 | 7 | 8 | #ifdef __APPLE__ 9 | #include 10 | #include 11 | #else 12 | #include 13 | #include 14 | #endif 15 | 16 | #include 17 | #include 18 | 19 | #ifdef __APPLE__ 20 | #define __BYTE_ORDER BYTE_ORDER 21 | #define __LITTLE_ENDIAN LITTLE_ENDIAN 22 | #endif 23 | 24 | #if __BYTE_ORDER == __LITTLE_ENDIAN 25 | #define cpu_to_le16(x) (x) 26 | #define le16_to_cpu(x) (x) 27 | #define cpu_to_le32(x) (x) 28 | #define le32_to_cpu(x) (x) 29 | #define cpu_to_le64(x) (x) 30 | #define le64_to_cpu(x) (x) 31 | #else 32 | #define cpu_to_le16(x) bswap_16(x) 33 | #define le16_to_cpu(x) bswap_16(x) 34 | #define cpu_to_le32(x) bswap_32(x) 35 | #define le32_to_cpu(x) bswap_32(x) 36 | #define cpu_to_le64(x) bswap_64(x) 37 | #define le64_to_cpu(x) bswap_64(x) 38 | #endif 39 | 40 | #undef min 41 | #define min(a,b) (((a) < (b)) ? (a) : (b)) 42 | 43 | #undef max 44 | #define max(a,b) ((a) >= (b) ? (a) : (b)) 45 | 46 | #define ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0])) 47 | 48 | #define is_saturated(x) (x == (typeof(x))-1) 49 | #define zero_or_saturated(x) ((x == 0) || is_saturated(x)) 50 | 51 | /* Policy compatibility information. */ 52 | struct policydb_compat_info { 53 | unsigned int type; 54 | unsigned int version; 55 | unsigned int sym_num; 56 | unsigned int ocon_num; 57 | unsigned int target_platform; 58 | }; 59 | 60 | extern struct policydb_compat_info *policydb_lookup_compat(unsigned int version, 61 | unsigned int type, 62 | unsigned int target_platform); 63 | 64 | /* Reading from a policy "file". */ 65 | extern int next_entry(void *buf, struct policy_file *fp, size_t bytes) hidden; 66 | extern size_t put_entry(const void *ptr, size_t size, size_t n, 67 | struct policy_file *fp) hidden; 68 | extern int str_read(char **strp, struct policy_file *fp, size_t len) hidden; 69 | -------------------------------------------------------------------------------- /libsepol/roles.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include 5 | #include 6 | 7 | #include "debug.h" 8 | #include "handle.h" 9 | 10 | /* Check if a role exists */ 11 | int sepol_role_exists(sepol_handle_t * handle __attribute__ ((unused)), 12 | sepol_policydb_t * p, const char *role, int *response) 13 | { 14 | 15 | policydb_t *policydb = &p->p; 16 | *response = (hashtab_search(policydb->p_roles.table, role) != NULL); 17 | 18 | return STATUS_SUCCESS; 19 | } 20 | 21 | /* Fill an array with all valid roles */ 22 | int sepol_role_list(sepol_handle_t * handle, 23 | sepol_policydb_t * p, char ***roles, unsigned int *nroles) 24 | { 25 | 26 | policydb_t *policydb = &p->p; 27 | unsigned int tmp_nroles = policydb->p_roles.nprim; 28 | char **tmp_roles = (char **)malloc(tmp_nroles * sizeof(char *)); 29 | char **ptr; 30 | unsigned int i; 31 | if (!tmp_roles) 32 | goto omem; 33 | 34 | for (i = 0; i < tmp_nroles; i++) { 35 | tmp_roles[i] = strdup(policydb->p_role_val_to_name[i]); 36 | if (!tmp_roles[i]) 37 | goto omem; 38 | } 39 | 40 | *nroles = tmp_nroles; 41 | *roles = tmp_roles; 42 | 43 | return STATUS_SUCCESS; 44 | 45 | omem: 46 | ERR(handle, "out of memory, could not list roles"); 47 | 48 | ptr = tmp_roles; 49 | while (ptr && *ptr) 50 | free(*ptr++); 51 | free(tmp_roles); 52 | return STATUS_ERR; 53 | } 54 | -------------------------------------------------------------------------------- /libsepol/symtab.c: -------------------------------------------------------------------------------- 1 | 2 | /* Author : Stephen Smalley, */ 3 | 4 | /* FLASK */ 5 | 6 | /* 7 | * Implementation of the symbol table type. 8 | */ 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | static unsigned int symhash(hashtab_t h, const_hashtab_key_t key) 15 | { 16 | const char *p, *keyp; 17 | size_t size; 18 | unsigned int val; 19 | 20 | val = 0; 21 | keyp = (const char *)key; 22 | size = strlen(keyp); 23 | for (p = keyp; ((size_t) (p - keyp)) < size; p++) 24 | val = 25 | (val << 4 | (val >> (8 * sizeof(unsigned int) - 4))) ^ (*p); 26 | return val & (h->size - 1); 27 | } 28 | 29 | static int symcmp(hashtab_t h 30 | __attribute__ ((unused)), const_hashtab_key_t key1, 31 | const_hashtab_key_t key2) 32 | { 33 | return strcmp(key1, key2); 34 | } 35 | 36 | int symtab_init(symtab_t * s, unsigned int size) 37 | { 38 | s->table = hashtab_create(symhash, symcmp, size); 39 | if (!s->table) 40 | return -1; 41 | s->nprim = 0; 42 | return 0; 43 | } 44 | 45 | void symtab_destroy(symtab_t * s) 46 | { 47 | if (!s) 48 | return; 49 | if (s->table) 50 | hashtab_destroy(s->table); 51 | return; 52 | } 53 | /* FLASK */ 54 | -------------------------------------------------------------------------------- /libsepol/user_internal.h: -------------------------------------------------------------------------------- 1 | #ifndef _SEPOL_USER_INTERNAL_H_ 2 | #define _SEPOL_USER_INTERNAL_H_ 3 | 4 | #include 5 | #include 6 | #include "dso.h" 7 | 8 | hidden_proto(sepol_user_add_role) 9 | hidden_proto(sepol_user_create) 10 | hidden_proto(sepol_user_free) 11 | hidden_proto(sepol_user_get_mlslevel) 12 | hidden_proto(sepol_user_get_mlsrange) 13 | hidden_proto(sepol_user_get_roles) 14 | hidden_proto(sepol_user_has_role) 15 | hidden_proto(sepol_user_key_create) 16 | hidden_proto(sepol_user_key_unpack) 17 | hidden_proto(sepol_user_set_mlslevel) 18 | hidden_proto(sepol_user_set_mlsrange) 19 | hidden_proto(sepol_user_set_name) 20 | #endif 21 | -------------------------------------------------------------------------------- /patch.c: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright rev1si0n . 2019. 3 | * 4 | * This file is part of bxxt. 5 | * 6 | * bxxt is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | 11 | * bxxt is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | 16 | * You should have received a copy of the GNU General Public License 17 | * along with bxxt. If not, see . 18 | */ 19 | #include 20 | 21 | #include "bxxt.h" 22 | #include "util.h" 23 | 24 | 25 | int patch(uint64_t offset, uint64_t repl, 26 | uint64_t size, char* fname) { 27 | bxxt_file_t *file = NULL; 28 | char fmt[512] = {0}, msg[512]; 29 | 30 | uint64_t n = 0; 31 | uint8_t *ptr; 32 | 33 | repl = bswap_64(repl); 34 | 35 | if (size > sizeof(uint64_t)) { 36 | log1(-1, "patch size must <= %x bytes", (int)sizeof(uint64_t)); 37 | goto error; 38 | } 39 | 40 | file = bxxt_file_new(fname, O_WRONLY, 0644); 41 | if (bxxt_file_open(file) != 0) { 42 | log1(-1, "failed open file %s to patch", fname); 43 | goto error; 44 | } 45 | 46 | if (lseek(file->fd, offset, SEEK_SET) != offset) { 47 | log1(-1, "cant't seek to offset %" PRIx64, offset); 48 | goto error; 49 | } 50 | 51 | ptr = ((uint8_t*)&repl) + (sizeof(uint64_t) - size); 52 | memcpy(&n, ptr, size); 53 | 54 | n = bswap_64(n) >> ((sizeof(uint64_t) - size)*8); 55 | sprintf(fmt, "patch offset %%08" PRIx64 " to %%0%u" PRIx64, 56 | (uint8_t)size*2); 57 | sprintf(msg, fmt, offset, n); 58 | log1(1, "%s", msg) 59 | 60 | write(file->fd, ptr, (size_t)size); 61 | 62 | bxxt_file_close(file); 63 | return BXXT_SUCCESS; 64 | 65 | error: 66 | log1(-1, "failed"); 67 | bxxt_file_close(file); 68 | return BXXT_FAILED; 69 | } 70 | 71 | int patch_main(int argc, char **argv) { 72 | uint64_t offset = 0, repl = 0, size = 0; 73 | if (argc == 3 && sscanf(argv[1], "@%" PRIX64 ":%" PRIX64 "=%" PRIX64, 74 | &offset, &size, &repl) == 3) 75 | return patch(offset, repl, size, argv[2]); 76 | return BXXT_FAILED; 77 | } -------------------------------------------------------------------------------- /prop.h: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright rev1si0n . 2019. 3 | * 4 | * This file is part of bxxt. 5 | * 6 | * bxxt is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | 11 | * bxxt is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | 16 | * You should have received a copy of the GNU General Public License 17 | * along with bxxt. If not, see . 18 | */ 19 | #ifndef _BXXT_DTCC_H_ 20 | #define _BXXT_DTCC_H_ 21 | #include 22 | 23 | #include 24 | #include 25 | #define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_ 26 | #include 27 | 28 | #include "bxxt.h" 29 | #include "util.h" 30 | 31 | struct _prinfo { 32 | unsigned volatile serial; 33 | char value[PROP_VALUE_MAX]; 34 | char name[0]; 35 | }; 36 | 37 | struct bxxt_mapinfo { 38 | char file[PATH_MAX]; 39 | uint64_t start; 40 | uint64_t end; 41 | }; 42 | 43 | int bxxt_scan_maps_by_offset_callback(void* offset, 44 | struct bxxt_mapinfo* bm); 45 | int bxxt_scan_maps_by_callback(pid_t pid, void* args, 46 | int (*callback)(void*, struct bxxt_mapinfo*), 47 | struct bxxt_mapinfo *bm); 48 | int bxxt_prop_set(char* name, char* value); 49 | pid_t bxxt_get_pid_by_cmdline(char* name); 50 | int bxxt_do_setdebuggable(char* value); 51 | #endif 52 | -------------------------------------------------------------------------------- /sepol.h: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright rev1si0n . 2019. 3 | * 4 | * This file is part of bxxt. 5 | * 6 | * bxxt is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | 11 | * bxxt is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | 16 | * You should have received a copy of the GNU General Public License 17 | * along with bxxt. If not, see . 18 | */ 19 | #ifndef _BXXT_SEPOL_H_ 20 | #define _BXXT_SEPOL_H_ 21 | 22 | #include "bxxt.h" 23 | 24 | #ifdef DEBUG 25 | #include 26 | #include 27 | #endif 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | 35 | #ifndef _SEPOL_INTERNAL_DEBUG_H_ 36 | 37 | #define STATUS_SUCCESS 0 38 | #define STATUS_NODATA 1 39 | #define STATUS_ERR -1 40 | 41 | #endif 42 | 43 | #include "util.h" 44 | 45 | typedef struct bxxt_sepoldb { 46 | // i don't know how to free memory allocated by create domain 47 | // pdb destory seems not release them, 48 | // so we allocate it ourself with a block memory 49 | bxxt_buffer_t *mm_pool; 50 | 51 | policydb_t pdb; 52 | } bxxt_sepoldb_t; 53 | 54 | static int bxxt_sepol_save_policy_file(bxxt_sepoldb_t* bpb, char* file); 55 | static int bxxt_sepol_load_policy_file(bxxt_sepoldb_t* bpb, char* file); 56 | 57 | static int bxxt_sepol_reload_kernel_policy(bxxt_sepoldb_t* bpb); 58 | static void bxxt_sepol_reload_kernel_policy_from_file(char* file); 59 | 60 | static int bxxt_sepol_allow_ext(bxxt_sepoldb_t* bpb, char* src, char* tgt, 61 | char* cls, char* perm, bool disallow); 62 | static int bxxt_sepol_create_domain(bxxt_sepoldb_t* bpb, char* domain); 63 | 64 | static int bxxt_sepol_execute_stmt(bxxt_sepoldb_t* bpb, char* stmt); 65 | static int bxxt_sepol_set_permissive(bxxt_sepoldb_t* bpb, char* domain, bool permissive); 66 | 67 | static bxxt_sepoldb_t* bxxt_sepol_new(); 68 | static void bxxt_sepol_free(bxxt_sepoldb_t* bpb); 69 | 70 | int sepol_main(int argc, char **argv); 71 | int sepol_rtexec(char* stmt); 72 | #endif 73 | -------------------------------------------------------------------------------- /sha1.h: -------------------------------------------------------------------------------- 1 | #ifndef SHA1_H 2 | #define SHA1_H 3 | 4 | /* 5 | SHA-1 in C 6 | By Steve Reid 7 | 100% Public Domain 8 | */ 9 | 10 | #include "stdint.h" 11 | 12 | typedef struct 13 | { 14 | uint32_t state[5]; 15 | uint32_t count[2]; 16 | unsigned char buffer[64]; 17 | } SHA1_CTX; 18 | 19 | void SHA1Transform( 20 | uint32_t state[5], 21 | const unsigned char buffer[64] 22 | ); 23 | 24 | void SHA1Init( 25 | SHA1_CTX * context 26 | ); 27 | 28 | void SHA1Update( 29 | SHA1_CTX * context, 30 | const unsigned char *data, 31 | uint32_t len 32 | ); 33 | 34 | void SHA1Final( 35 | unsigned char digest[20], 36 | SHA1_CTX * context 37 | ); 38 | 39 | void SHA1( 40 | char *hash_out, 41 | const char *str, 42 | int len); 43 | 44 | #endif /* SHA1_H */ 45 | -------------------------------------------------------------------------------- /util.h: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright rev1si0n . 2019. 3 | * 4 | * This file is part of bxxt. 5 | * 6 | * bxxt is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | 11 | * bxxt is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | 16 | * You should have received a copy of the GNU General Public License 17 | * along with bxxt. If not, see . 18 | */ 19 | #ifndef _BXXT_UTIL_H_ 20 | #define _BXXT_UTIL_H_ 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #include 28 | 29 | #include 30 | #include 31 | 32 | #include 33 | #include 34 | 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | 41 | #include 42 | #include 43 | 44 | typedef void (*buffer_free_callback)(void*); 45 | typedef void (*buffer_resize_callback)(void*, int); 46 | 47 | 48 | struct bxxt_buffer { 49 | buffer_free_callback free; 50 | buffer_resize_callback resize; 51 | 52 | size_t size; 53 | void* ptr; 54 | }; 55 | 56 | struct bxxt_file { 57 | struct stat stat; 58 | int fd; 59 | 60 | char name[PATH_MAX]; 61 | uint32_t o_flags; 62 | 63 | mode_t mode; 64 | size_t size; 65 | 66 | uint8_t mm; 67 | uint32_t mm_flags; 68 | uint32_t mm_prot; 69 | void* ptr; 70 | }; 71 | 72 | #define log1(level, fmt, ...) \ 73 | {\ 74 | if (level <= BXXT_LOGLEVEL) { \ 75 | fprintf(stderr, "bxxt \033[1;3%cm[%c]\033[0m " fmt "\n", (level < 0)?'1': '2', \ 76 | (level < 0)?'!': ((level <= 2)?'-': ((level <= 4)?'+': '*')), \ 77 | ##__VA_ARGS__); \ 78 | }\ 79 | } 80 | 81 | typedef struct bxxt_buffer bxxt_buffer_t; 82 | typedef struct bxxt_file bxxt_file_t; 83 | 84 | 85 | uint32_t bxxt_convert_to_little32(uint32_t n); 86 | uint64_t bxxt_convert_to_little64(uint64_t n); 87 | 88 | bxxt_file_t* bxxt_file_new(char* file, uint32_t o_flags, uint32_t mode); 89 | bxxt_file_t* bxxt_file_new_mm(char* file, uint32_t o_flags, uint32_t mode, 90 | uint32_t mm_flags, uint32_t mm_mode); 91 | 92 | int bxxt_file_open(bxxt_file_t* file); 93 | void bxxt_file_close_no_free(bxxt_file_t* file); 94 | void bxxt_file_close(bxxt_file_t* file); 95 | 96 | bxxt_buffer_t* bxxt_buffer_create(size_t size); 97 | bxxt_buffer_t* bxxt_buffer_create_from_data(const void* data, size_t size); 98 | void bxxt_buffer_resize(bxxt_buffer_t* buffer, int adj_size); 99 | size_t bxxt_buffer_concat_from_data(bxxt_buffer_t* buffer, const void* data, size_t size); 100 | size_t bxxt_buffer_align(bxxt_buffer_t* buffer, size_t page_size); 101 | void bxxt_buffer_free(bxxt_buffer_t* buffer); 102 | 103 | void* bxxt_malloc(size_t size); 104 | void bxxt_free(void* ptr); 105 | #endif -------------------------------------------------------------------------------- /zlib/LICENSE: -------------------------------------------------------------------------------- 1 | see https://zlib.net/zlib_license.html 2 | -------------------------------------------------------------------------------- /zlib/compress.c: -------------------------------------------------------------------------------- 1 | /* compress.c -- compress a memory buffer 2 | * Copyright (C) 1995-2005 Jean-loup Gailly. 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* @(#) $Id$ */ 7 | 8 | #define ZLIB_INTERNAL 9 | #include "zlib.h" 10 | 11 | /* =========================================================================== 12 | Compresses the source buffer into the destination buffer. The level 13 | parameter has the same meaning as in deflateInit. sourceLen is the byte 14 | length of the source buffer. Upon entry, destLen is the total size of the 15 | destination buffer, which must be at least 0.1% larger than sourceLen plus 16 | 12 bytes. Upon exit, destLen is the actual size of the compressed buffer. 17 | 18 | compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough 19 | memory, Z_BUF_ERROR if there was not enough room in the output buffer, 20 | Z_STREAM_ERROR if the level parameter is invalid. 21 | */ 22 | int ZEXPORT compress2 (dest, destLen, source, sourceLen, level) 23 | Bytef *dest; 24 | uLongf *destLen; 25 | const Bytef *source; 26 | uLong sourceLen; 27 | int level; 28 | { 29 | z_stream stream; 30 | int err; 31 | 32 | stream.next_in = (z_const Bytef *)source; 33 | stream.avail_in = (uInt)sourceLen; 34 | #ifdef MAXSEG_64K 35 | /* Check for source > 64K on 16-bit machine: */ 36 | if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR; 37 | #endif 38 | stream.next_out = dest; 39 | stream.avail_out = (uInt)*destLen; 40 | if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR; 41 | 42 | stream.zalloc = (alloc_func)0; 43 | stream.zfree = (free_func)0; 44 | stream.opaque = (voidpf)0; 45 | 46 | err = deflateInit(&stream, level); 47 | if (err != Z_OK) return err; 48 | 49 | err = deflate(&stream, Z_FINISH); 50 | if (err != Z_STREAM_END) { 51 | deflateEnd(&stream); 52 | return err == Z_OK ? Z_BUF_ERROR : err; 53 | } 54 | *destLen = stream.total_out; 55 | 56 | err = deflateEnd(&stream); 57 | return err; 58 | } 59 | 60 | /* =========================================================================== 61 | */ 62 | int ZEXPORT compress (dest, destLen, source, sourceLen) 63 | Bytef *dest; 64 | uLongf *destLen; 65 | const Bytef *source; 66 | uLong sourceLen; 67 | { 68 | return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION); 69 | } 70 | 71 | /* =========================================================================== 72 | If the default memLevel or windowBits for deflateInit() is changed, then 73 | this function needs to be updated. 74 | */ 75 | uLong ZEXPORT compressBound (sourceLen) 76 | uLong sourceLen; 77 | { 78 | return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + 79 | (sourceLen >> 25) + 13; 80 | } 81 | -------------------------------------------------------------------------------- /zlib/gzclose.c: -------------------------------------------------------------------------------- 1 | /* gzclose.c -- zlib gzclose() function 2 | * Copyright (C) 2004, 2010 Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | #include "gzguts.h" 7 | 8 | /* gzclose() is in a separate file so that it is linked in only if it is used. 9 | That way the other gzclose functions can be used instead to avoid linking in 10 | unneeded compression or decompression routines. */ 11 | int ZEXPORT gzclose(file) 12 | gzFile file; 13 | { 14 | #ifndef NO_GZCOMPRESS 15 | gz_statep state; 16 | 17 | if (file == NULL) 18 | return Z_STREAM_ERROR; 19 | state = (gz_statep)file; 20 | 21 | return state->mode == GZ_READ ? gzclose_r(file) : gzclose_w(file); 22 | #else 23 | return gzclose_r(file); 24 | #endif 25 | } 26 | -------------------------------------------------------------------------------- /zlib/inffast.h: -------------------------------------------------------------------------------- 1 | /* inffast.h -- header to use inffast.c 2 | * Copyright (C) 1995-2003, 2010 Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* WARNING: this file should *not* be used by applications. It is 7 | part of the implementation of the compression library and is 8 | subject to change. Applications should only use zlib.h. 9 | */ 10 | 11 | void ZLIB_INTERNAL inflate_fast OF((z_streamp strm, unsigned start)); 12 | -------------------------------------------------------------------------------- /zlib/inftrees.h: -------------------------------------------------------------------------------- 1 | /* inftrees.h -- header to use inftrees.c 2 | * Copyright (C) 1995-2005, 2010 Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* WARNING: this file should *not* be used by applications. It is 7 | part of the implementation of the compression library and is 8 | subject to change. Applications should only use zlib.h. 9 | */ 10 | 11 | /* Structure for decoding tables. Each entry provides either the 12 | information needed to do the operation requested by the code that 13 | indexed that table entry, or it provides a pointer to another 14 | table that indexes more bits of the code. op indicates whether 15 | the entry is a pointer to another table, a literal, a length or 16 | distance, an end-of-block, or an invalid code. For a table 17 | pointer, the low four bits of op is the number of index bits of 18 | that table. For a length or distance, the low four bits of op 19 | is the number of extra bits to get after the code. bits is 20 | the number of bits in this code or part of the code to drop off 21 | of the bit buffer. val is the actual byte to output in the case 22 | of a literal, the base length or distance, or the offset from 23 | the current table to the next table. Each entry is four bytes. */ 24 | typedef struct { 25 | unsigned char op; /* operation, extra bits, table bits */ 26 | unsigned char bits; /* bits in this part of the code */ 27 | unsigned short val; /* offset in table or code value */ 28 | } code; 29 | 30 | /* op values as set by inflate_table(): 31 | 00000000 - literal 32 | 0000tttt - table link, tttt != 0 is the number of table index bits 33 | 0001eeee - length or distance, eeee is the number of extra bits 34 | 01100000 - end of block 35 | 01000000 - invalid code 36 | */ 37 | 38 | /* Maximum size of the dynamic table. The maximum number of code structures is 39 | 1444, which is the sum of 852 for literal/length codes and 592 for distance 40 | codes. These values were found by exhaustive searches using the program 41 | examples/enough.c found in the zlib distribtution. The arguments to that 42 | program are the number of symbols, the initial root table size, and the 43 | maximum bit length of a code. "enough 286 9 15" for literal/length codes 44 | returns returns 852, and "enough 30 6 15" for distance codes returns 592. 45 | The initial root table size (9 or 6) is found in the fifth argument of the 46 | inflate_table() calls in inflate.c and infback.c. If the root table size is 47 | changed, then these maximum sizes would be need to be recalculated and 48 | updated. */ 49 | #define ENOUGH_LENS 852 50 | #define ENOUGH_DISTS 592 51 | #define ENOUGH (ENOUGH_LENS+ENOUGH_DISTS) 52 | 53 | /* Type of code to build for inflate_table() */ 54 | typedef enum { 55 | CODES, 56 | LENS, 57 | DISTS 58 | } codetype; 59 | 60 | int ZLIB_INTERNAL inflate_table OF((codetype type, unsigned short FAR *lens, 61 | unsigned codes, code FAR * FAR *table, 62 | unsigned FAR *bits, unsigned short FAR *work)); 63 | -------------------------------------------------------------------------------- /zlib/uncompr.c: -------------------------------------------------------------------------------- 1 | /* uncompr.c -- decompress a memory buffer 2 | * Copyright (C) 1995-2003, 2010 Jean-loup Gailly. 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* @(#) $Id$ */ 7 | 8 | #define ZLIB_INTERNAL 9 | #include "zlib.h" 10 | 11 | /* =========================================================================== 12 | Decompresses the source buffer into the destination buffer. sourceLen is 13 | the byte length of the source buffer. Upon entry, destLen is the total 14 | size of the destination buffer, which must be large enough to hold the 15 | entire uncompressed data. (The size of the uncompressed data must have 16 | been saved previously by the compressor and transmitted to the decompressor 17 | by some mechanism outside the scope of this compression library.) 18 | Upon exit, destLen is the actual size of the compressed buffer. 19 | 20 | uncompress returns Z_OK if success, Z_MEM_ERROR if there was not 21 | enough memory, Z_BUF_ERROR if there was not enough room in the output 22 | buffer, or Z_DATA_ERROR if the input data was corrupted. 23 | */ 24 | int ZEXPORT uncompress (dest, destLen, source, sourceLen) 25 | Bytef *dest; 26 | uLongf *destLen; 27 | const Bytef *source; 28 | uLong sourceLen; 29 | { 30 | z_stream stream; 31 | int err; 32 | 33 | stream.next_in = (z_const Bytef *)source; 34 | stream.avail_in = (uInt)sourceLen; 35 | /* Check for source > 64K on 16-bit machine: */ 36 | if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR; 37 | 38 | stream.next_out = dest; 39 | stream.avail_out = (uInt)*destLen; 40 | if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR; 41 | 42 | stream.zalloc = (alloc_func)0; 43 | stream.zfree = (free_func)0; 44 | 45 | err = inflateInit(&stream); 46 | if (err != Z_OK) return err; 47 | 48 | err = inflate(&stream, Z_FINISH); 49 | if (err != Z_STREAM_END) { 50 | inflateEnd(&stream); 51 | if (err == Z_NEED_DICT || (err == Z_BUF_ERROR && stream.avail_in == 0)) 52 | return Z_DATA_ERROR; 53 | return err; 54 | } 55 | *destLen = stream.total_out; 56 | 57 | err = inflateEnd(&stream); 58 | return err; 59 | } 60 | --------------------------------------------------------------------------------