1228753Smm/*- 2228753Smm * Copyright (c) 2003-2007 Tim Kientzle 3228753Smm * All rights reserved. 4228753Smm * 5228753Smm * Redistribution and use in source and binary forms, with or without 6228753Smm * modification, are permitted provided that the following conditions 7228753Smm * are met: 8228753Smm * 1. Redistributions of source code must retain the above copyright 9228753Smm * notice, this list of conditions and the following disclaimer. 10228753Smm * 2. Redistributions in binary form must reproduce the above copyright 11228753Smm * notice, this list of conditions and the following disclaimer in the 12228753Smm * documentation and/or other materials provided with the distribution. 13228753Smm * 14228753Smm * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR 15228753Smm * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16228753Smm * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17228753Smm * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, 18228753Smm * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19228753Smm * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20228753Smm * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21228753Smm * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22228753Smm * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23228753Smm * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24228753Smm */ 25228753Smm 26228753Smm#include "archive_platform.h" 27228763Smm__FBSDID("$FreeBSD: releng/10.3/contrib/libarchive/libarchive/archive_entry_xattr.c 228763 2011-12-21 11:13:29Z mm $"); 28228753Smm 29228753Smm#ifdef HAVE_SYS_STAT_H 30228753Smm#include <sys/stat.h> 31228753Smm#endif 32228753Smm#ifdef HAVE_SYS_TYPES_H 33228753Smm#include <sys/types.h> 34228753Smm#endif 35228753Smm#ifdef HAVE_LIMITS_H 36228753Smm#include <limits.h> 37228753Smm#endif 38228753Smm#ifdef HAVE_LINUX_FS_H 39228753Smm#include <linux/fs.h> /* for Linux file flags */ 40228753Smm#endif 41228753Smm/* 42228753Smm * Some Linux distributions have both linux/ext2_fs.h and ext2fs/ext2_fs.h. 43228753Smm * As the include guards don't agree, the order of include is important. 44228753Smm */ 45228753Smm#ifdef HAVE_LINUX_EXT2_FS_H 46228753Smm#include <linux/ext2_fs.h> /* for Linux file flags */ 47228753Smm#endif 48228753Smm#if defined(HAVE_EXT2FS_EXT2_FS_H) && !defined(__CYGWIN__) 49228753Smm#include <ext2fs/ext2_fs.h> /* for Linux file flags */ 50228753Smm#endif 51228753Smm#include <stddef.h> 52228753Smm#include <stdio.h> 53228753Smm#ifdef HAVE_STDLIB_H 54228753Smm#include <stdlib.h> 55228753Smm#endif 56228753Smm#ifdef HAVE_STRING_H 57228753Smm#include <string.h> 58228753Smm#endif 59228753Smm#ifdef HAVE_WCHAR_H 60228753Smm#include <wchar.h> 61228753Smm#endif 62228753Smm 63228753Smm#include "archive.h" 64228753Smm#include "archive_entry.h" 65228753Smm#include "archive_private.h" 66228753Smm#include "archive_entry_private.h" 67228753Smm 68228753Smm/* 69228753Smm * extended attribute handling 70228753Smm */ 71228753Smm 72228753Smmvoid 73228753Smmarchive_entry_xattr_clear(struct archive_entry *entry) 74228753Smm{ 75228753Smm struct ae_xattr *xp; 76228753Smm 77228753Smm while (entry->xattr_head != NULL) { 78228753Smm xp = entry->xattr_head->next; 79228753Smm free(entry->xattr_head->name); 80228753Smm free(entry->xattr_head->value); 81228753Smm free(entry->xattr_head); 82228753Smm entry->xattr_head = xp; 83228753Smm } 84228753Smm 85228753Smm entry->xattr_head = NULL; 86228753Smm} 87228753Smm 88228753Smmvoid 89228753Smmarchive_entry_xattr_add_entry(struct archive_entry *entry, 90228753Smm const char *name, const void *value, size_t size) 91228753Smm{ 92228753Smm struct ae_xattr *xp; 93228753Smm 94228753Smm for (xp = entry->xattr_head; xp != NULL; xp = xp->next) 95228753Smm ; 96228753Smm 97228753Smm if ((xp = (struct ae_xattr *)malloc(sizeof(struct ae_xattr))) == NULL) 98228753Smm /* XXX Error XXX */ 99228753Smm return; 100228753Smm 101228753Smm xp->name = strdup(name); 102228753Smm if ((xp->value = malloc(size)) != NULL) { 103228753Smm memcpy(xp->value, value, size); 104228753Smm xp->size = size; 105228753Smm } else 106228753Smm xp->size = 0; 107228753Smm 108228753Smm xp->next = entry->xattr_head; 109228753Smm entry->xattr_head = xp; 110228753Smm} 111228753Smm 112228753Smm 113228753Smm/* 114228753Smm * returns number of the extended attribute entries 115228753Smm */ 116228753Smmint 117228753Smmarchive_entry_xattr_count(struct archive_entry *entry) 118228753Smm{ 119228753Smm struct ae_xattr *xp; 120228753Smm int count = 0; 121228753Smm 122228753Smm for (xp = entry->xattr_head; xp != NULL; xp = xp->next) 123228753Smm count++; 124228753Smm 125228753Smm return count; 126228753Smm} 127228753Smm 128228753Smmint 129228753Smmarchive_entry_xattr_reset(struct archive_entry * entry) 130228753Smm{ 131228753Smm entry->xattr_p = entry->xattr_head; 132228753Smm 133228753Smm return archive_entry_xattr_count(entry); 134228753Smm} 135228753Smm 136228753Smmint 137228753Smmarchive_entry_xattr_next(struct archive_entry * entry, 138228753Smm const char **name, const void **value, size_t *size) 139228753Smm{ 140228753Smm if (entry->xattr_p) { 141228753Smm *name = entry->xattr_p->name; 142228753Smm *value = entry->xattr_p->value; 143228753Smm *size = entry->xattr_p->size; 144228753Smm 145228753Smm entry->xattr_p = entry->xattr_p->next; 146228753Smm 147228753Smm return (ARCHIVE_OK); 148228753Smm } else { 149228753Smm *name = NULL; 150228753Smm *value = NULL; 151228753Smm *size = (size_t)0; 152228753Smm return (ARCHIVE_WARN); 153228753Smm } 154228753Smm} 155228753Smm 156228753Smm/* 157228753Smm * end of xattr handling 158228753Smm */ 159