summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/gpgconf-comp.c28
-rw-r--r--tools/gpgconf.c21
-rw-r--r--tools/gpgconf.h28
-rw-r--r--tools/gpgtar-create.c8
-rw-r--r--tools/gpgtar-extract.c22
-rw-r--r--tools/gpgtar-list.c49
-rw-r--r--tools/gpgtar.c37
-rw-r--r--tools/gpgtar.h26
8 files changed, 146 insertions, 73 deletions
diff --git a/tools/gpgconf-comp.c b/tools/gpgconf-comp.c
index b10b146..79a7489 100644
--- a/tools/gpgconf-comp.c
+++ b/tools/gpgconf-comp.c
@@ -1066,34 +1066,6 @@ static gc_option_t gc_options_pinentry[] =
-/* Component system. Each component is a set of options that can be
- configured at the same time. If you change this, don't forget to
- update GC_COMPONENT below. */
-typedef enum
- {
- /* The classic GPG for OpenPGP. */
- GC_COMPONENT_GPG,
-
- /* The GPG Agent. */
- GC_COMPONENT_GPG_AGENT,
-
- /* The Smardcard Daemon. */
- GC_COMPONENT_SCDAEMON,
-
- /* GPG for S/MIME. */
- GC_COMPONENT_GPGSM,
-
- /* The LDAP Directory Manager for CRLs. */
- GC_COMPONENT_DIRMNGR,
-
- /* The external Pinentry. */
- GC_COMPONENT_PINENTRY,
-
- /* The number of components. */
- GC_COMPONENT_NR
- } gc_component_t;
-
-
/* The information associated with each component. */
static const struct
{
diff --git a/tools/gpgconf.c b/tools/gpgconf.c
index 59085d8..4cd0505 100644
--- a/tools/gpgconf.c
+++ b/tools/gpgconf.c
@@ -47,6 +47,7 @@ enum cmd_and_opt_values
oHomedir,
oBuilddir,
oStatusFD,
+ oShowSocket,
aListComponents,
aCheckPrograms,
@@ -108,6 +109,7 @@ static ARGPARSE_OPTS opts[] =
{ oBuilddir, "build-prefix", 2, "@" },
{ oNull, "null", 0, "@" },
{ oNoVerbose, "no-verbose", 0, "@"},
+ ARGPARSE_s_n (oShowSocket, "show-socket", "@"),
ARGPARSE_end(),
};
@@ -525,6 +527,7 @@ main (int argc, char **argv)
int no_more_options = 0;
enum cmd_and_opt_values cmd = 0;
estream_t outfp = NULL;
+ int show_socket = 0;
early_system_init ();
gnupg_reopen_std (GPGCONF_NAME);
@@ -558,6 +561,7 @@ main (int argc, char **argv)
case oStatusFD:
set_status_fd (translate_sys2libc_fd_int (pargs.r.ret_int, 1));
break;
+ case oShowSocket: show_socket = 1; break;
case aListDirs:
case aListComponents:
@@ -682,7 +686,22 @@ main (int argc, char **argv)
}
else if (cmd == aLaunch)
{
- if (gc_component_launch (idx))
+ err = gc_component_launch (idx);
+ if (show_socket)
+ {
+ char *names[2];
+
+ if (idx == GC_COMPONENT_GPG_AGENT)
+ names[0] = "agent-socket";
+ else if (idx == GC_COMPONENT_DIRMNGR)
+ names[0] = "dirmngr-socket";
+ else
+ names[0] = NULL;
+ names[1] = NULL;
+ get_outfp (&outfp);
+ list_dirs (outfp, names);
+ }
+ if (err)
gpgconf_failure (0);
}
else
diff --git a/tools/gpgconf.h b/tools/gpgconf.h
index 8a061ef..1922597 100644
--- a/tools/gpgconf.h
+++ b/tools/gpgconf.h
@@ -43,6 +43,34 @@ void gpgconf_failure (gpg_error_t err) GPGRT_ATTR_NORETURN;
/*-- gpgconf-comp.c --*/
+/* Component system. Each component is a set of options that can be
+ * configured at the same time. If you change this, don't forget to
+ * update GC_COMPONENT in gpgconf-comp.c. */
+typedef enum
+ {
+ /* The classic GPG for OpenPGP. */
+ GC_COMPONENT_GPG,
+
+ /* The GPG Agent. */
+ GC_COMPONENT_GPG_AGENT,
+
+ /* The Smardcard Daemon. */
+ GC_COMPONENT_SCDAEMON,
+
+ /* GPG for S/MIME. */
+ GC_COMPONENT_GPGSM,
+
+ /* The LDAP Directory Manager for CRLs. */
+ GC_COMPONENT_DIRMNGR,
+
+ /* The external Pinentry. */
+ GC_COMPONENT_PINENTRY,
+
+ /* The number of components. */
+ GC_COMPONENT_NR
+ } gc_component_t;
+
+
/* Initialize the components. */
void gc_components_init (void);
diff --git a/tools/gpgtar-create.c b/tools/gpgtar-create.c
index c622a66..a086016 100644
--- a/tools/gpgtar-create.c
+++ b/tools/gpgtar-create.c
@@ -762,6 +762,14 @@ gpgtar_create (char **inpattern, int encrypt, int sign)
memset (scanctrl, 0, sizeof *scanctrl);
scanctrl->flist_tail = &scanctrl->flist;
+ if (opt.directory && gnupg_chdir (opt.directory))
+ {
+ err = gpg_error_from_syserror ();
+ log_error ("chdir to '%s' failed: %s\n",
+ opt.directory, gpg_strerror (err));
+ return err;
+ }
+
while (!eof_seen)
{
char *pat, *p;
diff --git a/tools/gpgtar-extract.c b/tools/gpgtar-extract.c
index 8613d19..3da100c 100644
--- a/tools/gpgtar-extract.c
+++ b/tools/gpgtar-extract.c
@@ -36,7 +36,7 @@
static gpg_error_t
extract_regular (estream_t stream, const char *dirname,
- tar_header_t hdr)
+ tarinfo_t info, tar_header_t hdr)
{
gpg_error_t err;
char record[RECORDSIZE];
@@ -70,6 +70,7 @@ extract_regular (estream_t stream, const char *dirname,
err = read_record (stream, record);
if (err)
goto leave;
+ info->nblocks++;
n++;
if (n < hdr->nrecords || (hdr->size && !(hdr->size % RECORDSIZE)))
nbytes = RECORDSIZE;
@@ -163,7 +164,8 @@ extract_directory (const char *dirname, tar_header_t hdr)
static gpg_error_t
-extract (estream_t stream, const char *dirname, tar_header_t hdr)
+extract (estream_t stream, const char *dirname, tarinfo_t info,
+ tar_header_t hdr)
{
gpg_error_t err;
size_t n;
@@ -190,7 +192,7 @@ extract (estream_t stream, const char *dirname, tar_header_t hdr)
}
if (hdr->typeflag == TF_REGULAR || hdr->typeflag == TF_UNKNOWN)
- err = extract_regular (stream, dirname, hdr);
+ err = extract_regular (stream, dirname, info, hdr);
else if (hdr->typeflag == TF_DIRECTORY)
err = extract_directory (dirname, hdr);
else
@@ -200,7 +202,11 @@ extract (estream_t stream, const char *dirname, tar_header_t hdr)
log_info ("unsupported file type %d for '%s' - skipped\n",
(int)hdr->typeflag, hdr->name);
for (err = 0, n=0; !err && n < hdr->nrecords; n++)
- err = read_record (stream, record);
+ {
+ err = read_record (stream, record);
+ if (!err)
+ info->nblocks++;
+ }
}
return err;
}
@@ -282,6 +288,10 @@ gpgtar_extract (const char *filename, int decrypt)
tar_header_t header = NULL;
const char *dirprefix = NULL;
char *dirname = NULL;
+ struct tarinfo_s tarinfo_buffer;
+ tarinfo_t tarinfo = &tarinfo_buffer;
+
+ memset (&tarinfo_buffer, 0, sizeof tarinfo_buffer);
if (filename)
{
@@ -378,11 +388,11 @@ gpgtar_extract (const char *filename, int decrypt)
for (;;)
{
- err = gpgtar_read_header (stream, &header);
+ err = gpgtar_read_header (stream, tarinfo, &header);
if (err || header == NULL)
goto leave;
- err = extract (stream, dirname, header);
+ err = extract (stream, dirname, tarinfo, header);
if (err)
goto leave;
xfree (header);
diff --git a/tools/gpgtar-list.c b/tools/gpgtar-list.c
index 0e10be8..396e837 100644
--- a/tools/gpgtar-list.c
+++ b/tools/gpgtar-list.c
@@ -77,12 +77,15 @@ parse_xoctal (const void *data, size_t length, const char *filename)
static tar_header_t
-parse_header (const void *record, const char *filename)
+parse_header (const void *record, const char *filename, tarinfo_t info)
{
const struct ustar_raw_header *raw = record;
size_t n, namelen, prefixlen;
tar_header_t header;
int use_prefix;
+ int anyerror = 0;
+
+ info->headerblock = info->nblocks - 1;
use_prefix = (!memcmp (raw->magic, "ustar", 5)
&& (raw->magic[5] == ' ' || !raw->magic[5]));
@@ -91,27 +94,31 @@ parse_header (const void *record, const char *filename)
for (namelen=0; namelen < sizeof raw->name && raw->name[namelen]; namelen++)
;
if (namelen == sizeof raw->name)
- log_info ("%s: warning: name not terminated by a nul byte\n", filename);
+ {
+ log_info ("%s: warning: name not terminated by a nul\n", filename);
+ anyerror = 1;
+ }
for (n=namelen+1; n < sizeof raw->name; n++)
if (raw->name[n])
{
log_info ("%s: warning: garbage after name\n", filename);
+ anyerror = 1;
break;
}
-
if (use_prefix && raw->prefix[0])
{
for (prefixlen=0; (prefixlen < sizeof raw->prefix
&& raw->prefix[prefixlen]); prefixlen++)
;
if (prefixlen == sizeof raw->prefix)
- log_info ("%s: warning: prefix not terminated by a nul byte\n",
- filename);
+ log_info ("%s: warning: prefix not terminated by a nul (block %llu)\n",
+ filename, info->headerblock);
for (n=prefixlen+1; n < sizeof raw->prefix; n++)
if (raw->prefix[n])
{
log_info ("%s: warning: garbage after prefix\n", filename);
+ anyerror = 1;
break;
}
}
@@ -156,25 +163,32 @@ parse_header (const void *record, const char *filename)
default: header->typeflag = TF_UNKNOWN; break;
}
-
/* Compute the number of data records following this header. */
if (header->typeflag == TF_REGULAR || header->typeflag == TF_UNKNOWN)
header->nrecords = (header->size + RECORDSIZE-1)/RECORDSIZE;
else
header->nrecords = 0;
+ if (anyerror)
+ {
+ log_info ("%s: header block %llu is corrupt"
+ " (size=%llu type=%d nrec=%llu)\n",
+ filename, info->headerblock,
+ header->size, header->typeflag, header->nrecords);
+ /* log_printhex (record, RECORDSIZE, " "); */
+ }
return header;
}
-/* Read the next block, assming it is a tar header. Returns a header
+/* Read the next block, assuming it is a tar header. Returns a header
object on success in R_HEADER, or an error. If the stream is
consumed, R_HEADER is set to NULL. In case of an error an error
message has been printed. */
static gpg_error_t
-read_header (estream_t stream, tar_header_t *r_header)
+read_header (estream_t stream, tarinfo_t info, tar_header_t *r_header)
{
gpg_error_t err;
char record[RECORDSIZE];
@@ -183,6 +197,7 @@ read_header (estream_t stream, tar_header_t *r_header)
err = read_record (stream, record);
if (err)
return err;
+ info->nblocks++;
for (i=0; i < RECORDSIZE && !record[i]; i++)
;
@@ -193,6 +208,7 @@ read_header (estream_t stream, tar_header_t *r_header)
err = read_record (stream, record);
if (err)
return err;
+ info->nblocks++;
for (i=0; i < RECORDSIZE && !record[i]; i++)
;
@@ -207,7 +223,7 @@ read_header (estream_t stream, tar_header_t *r_header)
}
}
- *r_header = parse_header (record, es_fname_get (stream));
+ *r_header = parse_header (record, es_fname_get (stream), info);
return *r_header ? 0 : gpg_error_from_syserror ();
}
@@ -215,7 +231,7 @@ read_header (estream_t stream, tar_header_t *r_header)
/* Skip the data records according to HEADER. Prints an error message
on error and return -1. */
static int
-skip_data (estream_t stream, tar_header_t header)
+skip_data (estream_t stream, tarinfo_t info, tar_header_t header)
{
char record[RECORDSIZE];
unsigned long long n;
@@ -224,6 +240,7 @@ skip_data (estream_t stream, tar_header_t header)
{
if (read_record (stream, record))
return -1;
+ info->nblocks++;
}
return 0;
@@ -278,6 +295,10 @@ gpgtar_list (const char *filename, int decrypt)
estream_t stream;
estream_t cipher_stream = NULL;
tar_header_t header = NULL;
+ struct tarinfo_s tarinfo_buffer;
+ tarinfo_t tarinfo = &tarinfo_buffer;
+
+ memset (&tarinfo_buffer, 0, sizeof tarinfo_buffer);
if (filename)
{
@@ -339,13 +360,13 @@ gpgtar_list (const char *filename, int decrypt)
for (;;)
{
- err = read_header (stream, &header);
+ err = read_header (stream, tarinfo, &header);
if (err || header == NULL)
goto leave;
print_header (header, es_stdout);
- if (skip_data (stream, header))
+ if (skip_data (stream, tarinfo, header))
goto leave;
xfree (header);
header = NULL;
@@ -362,9 +383,9 @@ gpgtar_list (const char *filename, int decrypt)
}
gpg_error_t
-gpgtar_read_header (estream_t stream, tar_header_t *r_header)
+gpgtar_read_header (estream_t stream, tarinfo_t info, tar_header_t *r_header)
{
- return read_header (stream, r_header);
+ return read_header (stream, info, r_header);
}
void
diff --git a/tools/gpgtar.c b/tools/gpgtar.c
index 2757ab0..b33aa6d 100644
--- a/tools/gpgtar.c
+++ b/tools/gpgtar.c
@@ -112,7 +112,7 @@ static ARGPARSE_OPTS opts[] = {
ARGPARSE_group (302, N_("@\nTar options:\n ")),
ARGPARSE_s_s (oDirectory, "directory",
- N_("|DIRECTORY|extract files into DIRECTORY")),
+ N_("|DIRECTORY|change to DIRECTORY first")),
ARGPARSE_s_s (oFilesFrom, "files-from",
N_("|FILE|get names to create from FILE")),
ARGPARSE_s_n (oNull, "null", N_("-T reads null-terminated names")),
@@ -136,6 +136,14 @@ static ARGPARSE_OPTS tar_opts[] = {
};
+/* Global flags. */
+enum cmd_and_opt_values cmd = 0;
+int skip_crypto = 0;
+const char *files_from = NULL;
+int null_names = 0;
+
+
+
/* Print usage information and provide strings for help. */
static const char *
@@ -169,23 +177,25 @@ my_strusage( int level )
static void
set_cmd (enum cmd_and_opt_values *ret_cmd, enum cmd_and_opt_values new_cmd)
{
- enum cmd_and_opt_values cmd = *ret_cmd;
-
- if (!cmd || cmd == new_cmd)
- cmd = new_cmd;
- else if (cmd == aSign && new_cmd == aEncrypt)
- cmd = aSignEncrypt;
- else if (cmd == aEncrypt && new_cmd == aSign)
- cmd = aSignEncrypt;
+ enum cmd_and_opt_values c = *ret_cmd;
+
+ if (!c || c == new_cmd)
+ c = new_cmd;
+ else if (c == aSign && new_cmd == aEncrypt)
+ c = aSignEncrypt;
+ else if (c == aEncrypt && new_cmd == aSign)
+ c = aSignEncrypt;
else
{
log_error (_("conflicting commands\n"));
exit (2);
}
- *ret_cmd = cmd;
+ *ret_cmd = c;
}
+
+
/* Shell-like argument splitting.
For compatibility with gpg-zip we accept arguments for GnuPG and
@@ -287,14 +297,9 @@ shell_parse_argv (const char *s, int *r_argc, char ***r_argv)
gpgrt_annotate_leaked_object (*r_argv);
return 0;
}
-
-/* Global flags. */
-enum cmd_and_opt_values cmd = 0;
-int skip_crypto = 0;
-const char *files_from = NULL;
-int null_names = 0;
+
/* Command line parsing. */
static void
parse_arguments (ARGPARSE_ARGS *pargs, ARGPARSE_OPTS *popts)
diff --git a/tools/gpgtar.h b/tools/gpgtar.h
index 8cbe80b..e74a001 100644
--- a/tools/gpgtar.h
+++ b/tools/gpgtar.h
@@ -41,12 +41,21 @@ struct
} 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
+#define RECORDSIZE 512
/* Description of the USTAR header format. */
@@ -64,16 +73,16 @@ struct ustar_raw_header
char magic[6];
char version[2];
char uname[32];
- char gname[32];
- char devmajor[8];
+ char gname[32];
+ char devmajor[8];
char devminor[8];
- char prefix[155];
+ char prefix[155];
char pad[12];
};
/* Filetypes as defined by USTAR. */
-typedef enum
+typedef enum
{
TF_REGULAR,
TF_HARDLINK,
@@ -93,7 +102,7 @@ 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 iof entries. */
+ 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. */
@@ -106,7 +115,7 @@ struct tar_header_s
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. */
@@ -126,7 +135,8 @@ 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, tar_header_t *r_header);
+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);