1 /* gpgtar.h - Global definitions for gpgtar
2  * Copyright (C) 2010 Free Software Foundation, Inc.
3  *
4  * This file is part of GnuPG.
5  *
6  * GnuPG 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  * GnuPG 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 this program; if not, see <https://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef GPGTAR_H
21 #define GPGTAR_H
22 
23 #include "../common/util.h"
24 #include "../common/strlist.h"
25 
26 
27 /* We keep all global options in the structure OPT.  */
28 EXTERN_UNLESS_MAIN_MODULE
29 struct
30 {
31   int verbose;
32   unsigned int debug_level;
33   int quiet;
34   int dry_run;
35   int utf8strings;
36   const char *gpg_program;
37   strlist_t gpg_arguments;
38   const char *outfile;
39   strlist_t recipients;
40   const char *user;
41   int symmetric;
42   const char *filename;
43   const char *directory;
44 } opt;
45 
46 
47 /* An info structure to avoid global variables.  */
48 struct tarinfo_s
49 {
50   unsigned long long nblocks;     /* Count of processed blocks.  */
51   unsigned long long headerblock; /* Number of current header block. */
52 };
53 typedef struct tarinfo_s *tarinfo_t;
54 
55 
56 /* The size of a tar record.  All IO is done in chunks of this size.
57    Note that we don't care about blocking because this version of tar
58    is not expected to be used directly on a tape drive in fact it is
59    used in a pipeline with GPG and thus any blocking would be
60    useless.  */
61 #define RECORDSIZE 512
62 
63 
64 /* Description of the USTAR header format.  */
65 struct ustar_raw_header
66 {
67   char name[100];
68   char mode[8];
69   char uid[8];
70   char gid[8];
71   char size[12];
72   char mtime[12];
73   char checksum[8];
74   char typeflag[1];
75   char linkname[100];
76   char magic[6];
77   char version[2];
78   char uname[32];
79   char gname[32];
80   char devmajor[8];
81   char devminor[8];
82   char prefix[155];
83   char pad[12];
84 };
85 
86 
87 /* Filetypes as defined by USTAR.  */
88 typedef enum
89   {
90     TF_REGULAR,
91     TF_HARDLINK,
92     TF_SYMLINK,
93     TF_CHARDEV,
94     TF_BLOCKDEV,
95     TF_DIRECTORY,
96     TF_FIFO,
97     TF_RESERVED,
98     TF_UNKNOWN,    /* Needs to be treated as regular file.  */
99     TF_NOTSUP      /* Not supported (used with --create).  */
100   } typeflag_t;
101 
102 
103 /* The internal representation of a TAR header.  */
104 struct tar_header_s;
105 typedef struct tar_header_s *tar_header_t;
106 struct tar_header_s
107 {
108   tar_header_t next;        /* Used to build a linked list of entries.  */
109 
110   unsigned long mode;       /* The file mode.  */
111   unsigned long nlink;      /* Number of hard links.  */
112   unsigned long uid;        /* The user id of the file.  */
113   unsigned long gid;        /* The group id of the file.  */
114   unsigned long long size;  /* The size of the file.  */
115   unsigned long long mtime; /* Modification time since Epoch.  Note
116                                that we don't use time_t here but a
117                                type which is more likely to be larger
118                                that 32 bit and thus allows tracking
119                                times beyond 2106.  */
120   typeflag_t typeflag;      /* The type of the file.  */
121 
122 
123   unsigned long long nrecords; /* Number of data records.  */
124 
125   char name[1];             /* Filename (UTF-8, dynamically extended).  */
126 };
127 
128 
129 /*-- gpgtar.c --*/
130 gpg_error_t read_record (estream_t stream, void *record);
131 gpg_error_t write_record (estream_t stream, const void *record);
132 
133 /*-- gpgtar-create.c --*/
134 gpg_error_t gpgtar_create (char **inpattern, const char *files_from,
135                            int null_names, int encrypt, int sign);
136 
137 /*-- gpgtar-extract.c --*/
138 gpg_error_t gpgtar_extract (const char *filename, int decrypt);
139 
140 /*-- gpgtar-list.c --*/
141 gpg_error_t gpgtar_list (const char *filename, int decrypt);
142 gpg_error_t gpgtar_read_header (estream_t stream, tarinfo_t info,
143                                 tar_header_t *r_header);
144 void gpgtar_print_header (tar_header_t header, estream_t out);
145 
146 
147 #endif /*GPGTAR_H*/
148