summaryrefslogtreecommitdiffstats
path: root/tools/gpgtar.h
blob: 74bfb56e81a77e947fe4d5535cc23df69d9ee8f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/* gpgtar.h - Global definitions for gpgtar
 * Copyright (C) 2010 Free Software Foundation, Inc.
 *
 * This file is part of GnuPG.
 *
 * GnuPG is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * GnuPG is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, see <https://www.gnu.org/licenses/>.
 */

#ifndef GPGTAR_H
#define GPGTAR_H

#include "../common/util.h"
#include "../common/strlist.h"


/* We keep all global options in the structure OPT.  */
EXTERN_UNLESS_MAIN_MODULE
struct
{
  int verbose;
  unsigned int debug_level;
  int quiet;
  int dry_run;
  const char *gpg_program;
  strlist_t gpg_arguments;
  const char *outfile;
  strlist_t recipients;
  const char *user;
  int symmetric;
  const char *filename;
  const char *directory;
} opt;


/* An info structure to avoid global variables.  */
struct tarinfo_s
{
  unsigned long long nblocks;     /* Count of processed blocks.  */
  unsigned long long headerblock; /* Number of current header block. */
};
typedef struct tarinfo_s *tarinfo_t;


/* The size of a tar record.  All IO is done in chunks of this size.
   Note that we don't care about blocking because this version of tar
   is not expected to be used directly on a tape drive in fact it is
   used in a pipeline with GPG and thus any blocking would be
   useless.  */
#define RECORDSIZE 512


/* Description of the USTAR header format.  */
struct ustar_raw_header
{
  char name[100];
  char mode[8];
  char uid[8];
  char gid[8];
  char size[12];
  char mtime[12];
  char checksum[8];
  char typeflag[1];
  char linkname[100];
  char magic[6];
  char version[2];
  char uname[32];
  char gname[32];
  char devmajor[8];
  char devminor[8];
  char prefix[155];
  char pad[12];
};


/* Filetypes as defined by USTAR.  */
typedef enum
  {
    TF_REGULAR,
    TF_HARDLINK,
    TF_SYMLINK,
    TF_CHARDEV,
    TF_BLOCKDEV,
    TF_DIRECTORY,
    TF_FIFO,
    TF_RESERVED,
    TF_UNKNOWN,    /* Needs to be treated as regular file.  */
    TF_NOTSUP      /* Not supported (used with --create).  */
  } typeflag_t;


/* The internal representation of a TAR header.  */
struct tar_header_s;
typedef struct tar_header_s *tar_header_t;
struct tar_header_s
{
  tar_header_t next;        /* Used to build a linked list of entries.  */

  unsigned long mode;       /* The file mode.  */
  unsigned long nlink;      /* Number of hard links.  */
  unsigned long uid;        /* The user id of the file.  */
  unsigned long gid;        /* The group id of the file.  */
  unsigned long long size;  /* The size of the file.  */
  unsigned long long mtime; /* Modification time since Epoch.  Note
                               that we don't use time_t here but a
                               type which is more likely to be larger
                               that 32 bit and thus allows tracking
                               times beyond 2106.  */
  typeflag_t typeflag;      /* The type of the file.  */


  unsigned long long nrecords; /* Number of data records.  */

  char name[1];             /* Filename (dynamically extended).  */
};


/*-- gpgtar.c --*/
gpg_error_t read_record (estream_t stream, void *record);
gpg_error_t write_record (estream_t stream, const void *record);

/*-- gpgtar-create.c --*/
gpg_error_t gpgtar_create (char **inpattern, int encrypt, int sign);

/*-- gpgtar-extract.c --*/
gpg_error_t gpgtar_extract (const char *filename, int decrypt);

/*-- gpgtar-list.c --*/
gpg_error_t gpgtar_list (const char *filename, int decrypt);
gpg_error_t gpgtar_read_header (estream_t stream, tarinfo_t info,
                                tar_header_t *r_header);
void gpgtar_print_header (tar_header_t header, estream_t out);


#endif /*GPGTAR_H*/