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: head/lib/libarchive/archive_entry_private.h 201096 2009-12-28 02:41:27Z kientzle $
26  */
27 
28 #ifndef ARCHIVE_ENTRY_PRIVATE_H_INCLUDED
29 #define ARCHIVE_ENTRY_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_acl_private.h"
36 #include "archive_string.h"
37 
38 struct ae_xattr {
39 	struct ae_xattr *next;
40 
41 	char	*name;
42 	void	*value;
43 	size_t	size;
44 };
45 
46 struct ae_sparse {
47 	struct ae_sparse *next;
48 
49 	int64_t	 offset;
50 	int64_t	 length;
51 };
52 
53 struct ae_digest {
54 	unsigned char md5[16];
55 	unsigned char rmd160[20];
56 	unsigned char sha1[20];
57 	unsigned char sha256[32];
58 	unsigned char sha384[48];
59 	unsigned char sha512[64];
60 };
61 
62 /*
63  * Description of an archive entry.
64  *
65  * Basically, this is a "struct stat" with a few text fields added in.
66  *
67  * TODO: Add "comment", "charset", and possibly other entries
68  * that are supported by "pax interchange" format.  However, GNU, ustar,
69  * cpio, and other variants don't support these features, so they're not an
70  * excruciatingly high priority right now.
71  *
72  * TODO: "pax interchange" format allows essentially arbitrary
73  * key/value attributes to be attached to any entry.  Supporting
74  * such extensions may make this library useful for special
75  * applications (e.g., a package manager could attach special
76  * package-management attributes to each entry).  There are tricky
77  * API issues involved, so this is not going to happen until
78  * there's a real demand for it.
79  *
80  * TODO: Design a good API for handling sparse files.
81  */
82 struct archive_entry {
83 	struct archive *archive;
84 
85 	/*
86 	 * Note that ae_stat.st_mode & AE_IFMT  can be  0!
87 	 *
88 	 * This occurs when the actual file type of the object is not
89 	 * in the archive.  For example, 'tar' archives store
90 	 * hardlinks without marking the type of the underlying
91 	 * object.
92 	 */
93 
94 	/*
95 	 * We have a "struct aest" for holding file metadata rather than just
96 	 * a "struct stat" because on some platforms the "struct stat" has
97 	 * fields which are too narrow to hold the range of possible values;
98 	 * we don't want to lose information if we read an archive and write
99 	 * out another (e.g., in "tar -cf new.tar @old.tar").
100 	 *
101 	 * The "stat" pointer points to some form of platform-specific struct
102 	 * stat; it is declared as a void * rather than a struct stat * as
103 	 * some platforms have multiple varieties of stat structures.
104 	 */
105 	void *stat;
106 	int  stat_valid; /* Set to 0 whenever a field in aest changes. */
107 
108 	struct aest {
109 		int64_t		aest_atime;
110 		uint32_t	aest_atime_nsec;
111 		int64_t		aest_ctime;
112 		uint32_t	aest_ctime_nsec;
113 		int64_t		aest_mtime;
114 		uint32_t	aest_mtime_nsec;
115 		int64_t		aest_birthtime;
116 		uint32_t	aest_birthtime_nsec;
117 		int64_t		aest_gid;
118 		int64_t		aest_ino;
119 		uint32_t	aest_nlink;
120 		uint64_t	aest_size;
121 		int64_t		aest_uid;
122 		/*
123 		 * Because converting between device codes and
124 		 * major/minor values is platform-specific and
125 		 * inherently a bit risky, we only do that conversion
126 		 * lazily.  That way, we will do a better job of
127 		 * preserving information in those cases where no
128 		 * conversion is actually required.
129 		 */
130 		int		aest_dev_is_broken_down;
131 		dev_t		aest_dev;
132 		dev_t		aest_devmajor;
133 		dev_t		aest_devminor;
134 		int		aest_rdev_is_broken_down;
135 		dev_t		aest_rdev;
136 		dev_t		aest_rdevmajor;
137 		dev_t		aest_rdevminor;
138 	} ae_stat;
139 
140 	int ae_set; /* bitmap of fields that are currently set */
141 #define	AE_SET_HARDLINK	1
142 #define	AE_SET_SYMLINK	2
143 #define	AE_SET_ATIME	4
144 #define	AE_SET_CTIME	8
145 #define	AE_SET_MTIME	16
146 #define	AE_SET_BIRTHTIME 32
147 #define	AE_SET_SIZE	64
148 #define	AE_SET_INO	128
149 #define	AE_SET_DEV	256
150 
151 	/*
152 	 * Use aes here so that we get transparent mbs<->wcs conversions.
153 	 */
154 	struct archive_mstring ae_fflags_text;	/* Text fflags per fflagstostr(3) */
155 	unsigned long ae_fflags_set;		/* Bitmap fflags */
156 	unsigned long ae_fflags_clear;
157 	struct archive_mstring ae_gname;		/* Name of owning group */
158 	struct archive_mstring ae_hardlink;	/* Name of target for hardlink */
159 	struct archive_mstring ae_pathname;	/* Name of entry */
160 	struct archive_mstring ae_symlink;		/* symlink contents */
161 	struct archive_mstring ae_uname;		/* Name of owner */
162 
163 	/* Not used within libarchive; useful for some clients. */
164 	struct archive_mstring ae_sourcepath;	/* Path this entry is sourced from. */
165 
166 #define AE_ENCRYPTION_NONE 0
167 #define AE_ENCRYPTION_DATA 1
168 #define AE_ENCRYPTION_METADATA 2
169 	char encryption;
170 
171 	void *mac_metadata;
172 	size_t mac_metadata_size;
173 
174 	/* Digest support. */
175 	struct ae_digest digest;
176 
177 	/* ACL support. */
178 	struct archive_acl    acl;
179 
180 	/* extattr support. */
181 	struct ae_xattr *xattr_head;
182 	struct ae_xattr *xattr_p;
183 
184 	/* sparse support. */
185 	struct ae_sparse *sparse_head;
186 	struct ae_sparse *sparse_tail;
187 	struct ae_sparse *sparse_p;
188 
189 	/* Miscellaneous. */
190 	char		 strmode[12];
191 
192 	/* Symlink type support */
193 	int ae_symlink_type;
194 };
195 
196 int
197 archive_entry_set_digest(struct archive_entry *entry, int type,
198     const unsigned char *digest);
199 
200 #endif /* ARCHIVE_ENTRY_PRIVATE_H_INCLUDED */
201