1/* 2 * Copyright (c) 2007 Rob Braun 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 * 3. Neither the name of Rob Braun nor the names of his contributors 14 * may be used to endorse or promote products derived from this software 15 * without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 * POSSIBILITY OF SUCH DAMAGE. 28 */ 29/* 30 * 03-Apr-2005 31 * DRI: Rob Braun <bbraun@synack.net> 32 */ 33/* 34 * Portions Copyright 2006, Apple Computer, Inc. 35 * Christopher Ryan <ryanc@apple.com> 36 */ 37 38#include "arcmod.h" 39#include "archive.h" 40#include "stat.h" 41#include "data.h" 42#include "linuxattr.h" 43#include "fbsdattr.h" 44#include "darwinattr.h" 45#include "ext2.h" 46#include "xar.h" 47#include <string.h> 48 49struct arcmod xar_arcmods[] = { 50 { xar_stat_archive, xar_stat_extract }, /* must be first */ 51 { xar_linuxattr_archive, xar_linuxattr_extract }, 52 { xar_fbsdattr_archive, xar_fbsdattr_extract }, 53 { xar_darwinattr_archive, xar_darwinattr_extract }, 54 { xar_ext2attr_archive, xar_ext2attr_extract }, 55 { xar_data_archive, xar_data_extract }, 56 /* Add new modules here */ 57 { NULL, xar_set_perm }, 58 { NULL, xar_flags_extract } 59}; 60 61/* xar_arcmod_archive 62 * x: archive to add the file to 63 * f: node representing the file 64 * file: the filesystem path to the file 65 * Returns: 0 on success 66 * Summary: This is the entry point to actual file archival. 67 */ 68int32_t xar_arcmod_archive(xar_t x, xar_file_t f, const char *file, const char *buffer, size_t len) { 69 int i; 70 int32_t ret; 71 for(i = 0; i < (sizeof(xar_arcmods)/sizeof(struct arcmod)); i++) { 72 if( xar_arcmods[i].archive ) { 73 ret = xar_arcmods[i].archive(x, f, file, buffer, len); 74 if( ret < 0 ) { 75 return ret; 76 } 77 if( ret > 0 ) { 78 return 0; 79 } 80 } 81 } 82 return 0; 83} 84 85/* xar_arcmod_extract 86 * x: archive to extract the file from 87 * f: node representing the file 88 * file: the filesystem path to the target file 89 * Returns: 0 on success 90 * Summary: This is the entry point to actual file archival. 91 */ 92int32_t xar_arcmod_extract(xar_t x, xar_file_t f, const char *file, char *buffer, size_t len) { 93 int i; 94 int32_t ret; 95 for(i = 0; i < (sizeof(xar_arcmods)/sizeof(struct arcmod)); i++) { 96 if( xar_arcmods[i].extract ) { 97 ret = xar_arcmods[i].extract(x, f, file, buffer, len); 98 if( ret < 0 ) { 99 return ret; 100 } 101 if( ret > 0 ) { 102 return 0; 103 } 104 } 105 } 106 return 0; 107} 108 109 110int32_t xar_arcmod_verify(xar_t x, xar_file_t f){ 111 return xar_data_verify(x,f); 112} 113 114/* xar_check_prop 115 * x: xar archive 116 * name: name of property to check 117 * Description: If XAR_OPT_PROPINCLUDE is set at all, only properties 118 * specified for inclusion will be added. 119 * If XAR_OPT_PROPINCLUDE is not set, and XAR_OPT_PROPEXCLUDE is set, 120 * properies specified by XAR_OPT_PROPEXCLUDE will be omitted. 121 * Returns: 0 for not to include, 1 for include. 122 */ 123int32_t xar_check_prop(xar_t x, const char *name) { 124 xar_attr_t i; 125 char includeset = 0; 126 127 for(i = XAR(x)->attrs; i; i = XAR_ATTR(i)->next) { 128 if( strcmp(XAR_ATTR(i)->key, XAR_OPT_PROPINCLUDE) == 0 ) { 129 if( strcmp(XAR_ATTR(i)->value, name) == 0 ) 130 return 1; 131 includeset = 1; 132 } 133 } 134 135 if( includeset ) 136 return 0; 137 138 for(i = XAR(x)->attrs; i; i = XAR_ATTR(i)->next) { 139 if( strcmp(XAR_ATTR(i)->key, XAR_OPT_PROPEXCLUDE) == 0 ) { 140 if( strcmp(XAR_ATTR(i)->value, name) == 0 ) 141 return 0; 142 } 143 } 144 145 return 1; 146} 147