From 40ca0022a7035ce5c3d715f36e0c70f310ea4c61 Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Tue, 23 Apr 2013 18:06:46 +0200 Subject: [PATCH] w32: Almost everywhere include winsock2.h before windows.h. -- This is required by newer mingw toolchain versions which demand that winsock2.h is included before windows.h. Now, due to the use of socket definitions in pth.h we need to include winsock2.h also in pth.h, now pth.h is often included after an include of windows.h and thus the compiler spits out a warning. To avoid that we include winsock2.h at all places the compiler complains about. --- agent/preset-passphrase.c | 23 +++-- agent/protect.c | 161 ++++++++++++++++--------------- autogen.sh | 2 +- common/estream.c | 3 + common/homedir.c | 39 ++++---- common/http.c | 3 + common/init.c | 7 +- common/iobuf.c | 69 ++++++------- common/sysutils.c | 27 +++--- common/ttyio.c | 43 +++++---- g10/exec.c | 21 ++-- g10/gpg.c | 193 +++++++++++++++++++------------------ g10/misc.c | 3 + g10/photoid.c | 7 +- jnlib/stringhelp.c | 75 +++++++------- jnlib/w32-gettext.c | 47 ++++----- jnlib/w32-reg.c | 39 ++++---- keyserver/gpgkeys_finger.c | 43 +++++---- keyserver/ksutil.c | 9 +- scd/apdu.c | 2 +- 20 files changed, 436 insertions(+), 380 deletions(-) diff --git a/agent/preset-passphrase.c b/agent/preset-passphrase.c index 72de91b7c..8f6018b7b 100644 --- a/agent/preset-passphrase.c +++ b/agent/preset-passphrase.c @@ -38,7 +38,10 @@ #include /* for setmode() */ #endif #ifdef HAVE_W32_SYSTEM -#include /* To initialize the sockets. fixme */ +# ifdef HAVE_WINSOCK2_H +# include +# endif +# include /* To initialize the sockets. fixme */ #endif #define JNLIB_NEED_LOG_LOGV @@ -49,14 +52,14 @@ #include "sysutils.h" -enum cmd_and_opt_values +enum cmd_and_opt_values { aNull = 0, oVerbose = 'v', oPassphrase = 'P', oPreset = 'c', oForget = 'f', - + oNoVerbose = 500, oHomedir, @@ -68,7 +71,7 @@ static const char *opt_homedir; static const char *opt_passphrase; static ARGPARSE_OPTS opts[] = { - + { 301, NULL, 0, N_("@Options:\n ") }, { oVerbose, "verbose", 0, "verbose" }, @@ -76,7 +79,7 @@ static ARGPARSE_OPTS opts[] = { { oPreset, "preset", 256, "preset passphrase"}, { oForget, "forget", 256, "forget passphrase"}, - { oHomedir, "homedir", 2, "@" }, + { oHomedir, "homedir", 2, "@" }, {0} }; @@ -94,14 +97,14 @@ my_strusage (int level) case 19: p = _("Please report bugs to <@EMAIL@>.\n"); break; case 1: - case 40: + case 40: p = _("Usage: gpg-preset-passphrase [options] KEYGRIP (-h for help)\n"); break; case 41: p = _("Syntax: gpg-preset-passphrase [options] KEYGRIP\n" "Password cache maintenance\n"); break; - + default: p = NULL; } return p; @@ -112,7 +115,7 @@ my_strusage (int level) /* Include the implementation of map_spwq_error. */ MAP_SPWQ_ERROR_IMPL - + static void preset_passphrase (const char *keygrip) @@ -210,7 +213,7 @@ main (int argc, char **argv) const char *keygrip = NULL; set_strusage (my_strusage); - log_set_prefix ("gpg-preset-passphrase", 1); + log_set_prefix ("gpg-preset-passphrase", 1); /* Make sure that our subsystems are ready. */ i18n_init (); @@ -231,7 +234,7 @@ main (int argc, char **argv) case oPreset: cmd = oPreset; break; case oForget: cmd = oForget; break; case oPassphrase: opt_passphrase = pargs.r.ret_str; break; - + default : pargs.err = 2; break; } } diff --git a/agent/protect.c b/agent/protect.c index d6c964121..d4d7e004d 100644 --- a/agent/protect.c +++ b/agent/protect.c @@ -28,6 +28,9 @@ #include #include #ifdef HAVE_W32_SYSTEM +# ifdef HAVE_WINSOCK2_H +# include +# endif # include #else # include @@ -83,7 +86,7 @@ calibrate_get_time (struct calibrate_time_s *data) &data->kernel_time, &data->user_time); #else struct tms tmp; - + times (&tmp); data->ticks = tmp.tms_utime; #endif @@ -94,12 +97,12 @@ static unsigned long calibrate_elapsed_time (struct calibrate_time_s *starttime) { struct calibrate_time_s stoptime; - + calibrate_get_time (&stoptime); #ifdef HAVE_W32_SYSTEM { unsigned long long t1, t2; - + t1 = (((unsigned long long)starttime->kernel_time.dwHighDateTime << 32) + starttime->kernel_time.dwLowDateTime); t1 += (((unsigned long long)starttime->user_time.dwHighDateTime << 32) @@ -136,7 +139,7 @@ calibrate_s2k_count_one (unsigned long count) /* Measure the time we need to do the hash operations and deduce an - S2K count which requires about 100ms of time. */ + S2K count which requires about 100ms of time. */ static unsigned long calibrate_s2k_count (void) { @@ -187,7 +190,7 @@ get_standard_s2k_count (void) /* Calculate the MIC for a private key S-Exp. SHA1HASH should point to a 20 byte buffer. This function is suitable for any algorithms. */ -static int +static int calculate_mic (const unsigned char *plainkey, unsigned char *sha1hash) { const unsigned char *hash_begin, *hash_end; @@ -200,16 +203,16 @@ calculate_mic (const unsigned char *plainkey, unsigned char *sha1hash) s++; n = snext (&s); if (!n) - return gpg_error (GPG_ERR_INV_SEXP); + return gpg_error (GPG_ERR_INV_SEXP); if (!smatch (&s, n, "private-key")) - return gpg_error (GPG_ERR_UNKNOWN_SEXP); + return gpg_error (GPG_ERR_UNKNOWN_SEXP); if (*s != '(') return gpg_error (GPG_ERR_UNKNOWN_SEXP); hash_begin = s; s++; n = snext (&s); if (!n) - return gpg_error (GPG_ERR_INV_SEXP); + return gpg_error (GPG_ERR_INV_SEXP); s += n; /* skip over the algorithm name */ while (*s == '(') @@ -217,18 +220,18 @@ calculate_mic (const unsigned char *plainkey, unsigned char *sha1hash) s++; n = snext (&s); if (!n) - return gpg_error (GPG_ERR_INV_SEXP); + return gpg_error (GPG_ERR_INV_SEXP); s += n; n = snext (&s); if (!n) - return gpg_error (GPG_ERR_INV_SEXP); + return gpg_error (GPG_ERR_INV_SEXP); s += n; if ( *s != ')' ) - return gpg_error (GPG_ERR_INV_SEXP); + return gpg_error (GPG_ERR_INV_SEXP); s++; } if (*s != ')') - return gpg_error (GPG_ERR_INV_SEXP); + return gpg_error (GPG_ERR_INV_SEXP); s++; hash_end = s; @@ -251,7 +254,7 @@ calculate_mic (const unsigned char *plainkey, unsigned char *sha1hash) (d #046129F..[some bytes not shown]..81#) (p #00e861b..[some bytes not shown]..f1#) (q #00f7a7c..[some bytes not shown]..61#) - (u #304559a..[some bytes not shown]..9b#) + (u #304559a..[some bytes not shown]..9b#) the returned block is the S-Expression: @@ -259,7 +262,7 @@ calculate_mic (const unsigned char *plainkey, unsigned char *sha1hash) */ static int -do_encryption (const unsigned char *protbegin, size_t protlen, +do_encryption (const unsigned char *protbegin, size_t protlen, const char *passphrase, const unsigned char *sha1hash, unsigned char **result, size_t *resultlen) { @@ -312,14 +315,14 @@ do_encryption (const unsigned char *protbegin, size_t protlen, { unsigned char *key; size_t keylen = PROT_CIPHER_KEYLEN; - + key = gcry_malloc_secure (keylen); if (!key) rc = out_of_core (); else { rc = hash_passphrase (passphrase, GCRY_MD_SHA1, - 3, iv+2*blklen, + 3, iv+2*blklen, get_standard_s2k_count (), key, keylen); if (!rc) rc = gcry_cipher_setkey (hd, key, keylen); @@ -339,7 +342,7 @@ do_encryption (const unsigned char *protbegin, size_t protlen, p += 20; *p++ = ')'; *p++ = ')'; - memcpy (p, iv+blklen, blklen); + memcpy (p, iv+blklen, blklen); p += blklen; assert ( p - outbuf == outlen); rc = gcry_cipher_encrypt (hd, outbuf, enclen, NULL, 0); @@ -357,7 +360,7 @@ do_encryption (const unsigned char *protbegin, size_t protlen, (protected openpgp-s2k3-sha1-aes-cbc ((sha1 salt no_of_iterations) 16byte_iv) encrypted_octet_string) - + in canoncical format of course. We use asprintf and %n modifier and dummy values as placeholders. */ { @@ -367,7 +370,7 @@ do_encryption (const unsigned char *protbegin, size_t protlen, p = xtryasprintf ("(9:protected%d:%s((4:sha18:%n_8bytes_%u:%s)%d:%n%*s)%d:%n%*s)", (int)strlen (modestr), modestr, - &saltpos, + &saltpos, (unsigned int)strlen (countbuf), countbuf, blklen, &ivpos, blklen, "", enclen, &encpos, enclen, ""); @@ -393,7 +396,7 @@ do_encryption (const unsigned char *protbegin, size_t protlen, /* Protect the key encoded in canonical format in PLAINKEY. We assume a valid S-Exp here. */ -int +int agent_protect (const unsigned char *plainkey, const char *passphrase, unsigned char **result, size_t *resultlen) { @@ -424,9 +427,9 @@ agent_protect (const unsigned char *plainkey, const char *passphrase, s++; n = snext (&s); if (!n) - return gpg_error (GPG_ERR_INV_SEXP); + return gpg_error (GPG_ERR_INV_SEXP); if (!smatch (&s, n, "private-key")) - return gpg_error (GPG_ERR_UNKNOWN_SEXP); + return gpg_error (GPG_ERR_UNKNOWN_SEXP); if (*s != '(') return gpg_error (GPG_ERR_UNKNOWN_SEXP); depth++; @@ -434,13 +437,13 @@ agent_protect (const unsigned char *plainkey, const char *passphrase, s++; n = snext (&s); if (!n) - return gpg_error (GPG_ERR_INV_SEXP); + return gpg_error (GPG_ERR_INV_SEXP); for (infidx=0; protect_info[infidx].algo && !smatch (&s, n, protect_info[infidx].algo); infidx++) ; if (!protect_info[infidx].algo) - return gpg_error (GPG_ERR_UNSUPPORTED_ALGORITHM); + return gpg_error (GPG_ERR_UNSUPPORTED_ALGORITHM); prot_begin = prot_end = NULL; for (i=0; (c=protect_info[infidx].parmlist[i]); i++) @@ -453,23 +456,23 @@ agent_protect (const unsigned char *plainkey, const char *passphrase, s++; n = snext (&s); if (!n) - return gpg_error (GPG_ERR_INV_SEXP); + return gpg_error (GPG_ERR_INV_SEXP); if (n != 1 || c != *s) - return gpg_error (GPG_ERR_INV_SEXP); + return gpg_error (GPG_ERR_INV_SEXP); s += n; n = snext (&s); if (!n) - return gpg_error (GPG_ERR_INV_SEXP); + return gpg_error (GPG_ERR_INV_SEXP); s +=n; /* skip value */ if (*s != ')') - return gpg_error (GPG_ERR_INV_SEXP); + return gpg_error (GPG_ERR_INV_SEXP); depth--; if (i == protect_info[infidx].prot_to) prot_end = s; s++; } if (*s != ')' || !prot_begin || !prot_end ) - return gpg_error (GPG_ERR_INV_SEXP); + return gpg_error (GPG_ERR_INV_SEXP); depth--; hash_end = s; s++; @@ -481,10 +484,10 @@ agent_protect (const unsigned char *plainkey, const char *passphrase, assert (!depth); real_end = s-1; - + /* Hash the stuff. Because the timestamp_exp won't get protected, we can't simply hash a continuous buffer but need to use several - md_writes. */ + md_writes. */ rc = gcry_md_open (&md, GCRY_MD_SHA1, 0 ); if (rc) return rc; @@ -537,8 +540,8 @@ agent_protect (const unsigned char *plainkey, const char *passphrase, /* Do the actual decryption and check the return list for consistency. */ static int -do_decryption (const unsigned char *protected, size_t protectedlen, - const char *passphrase, +do_decryption (const unsigned char *protected, size_t protectedlen, + const char *passphrase, const unsigned char *s2ksalt, unsigned long s2kcount, const unsigned char *iv, size_t ivlen, unsigned char **result) @@ -567,7 +570,7 @@ do_decryption (const unsigned char *protected, size_t protectedlen, { unsigned char *key; size_t keylen = PROT_CIPHER_KEYLEN; - + key = gcry_malloc_secure (keylen); if (!key) rc = out_of_core (); @@ -615,7 +618,7 @@ do_decryption (const unsigned char *protected, size_t protectedlen, calculation but then be removed. */ static int merge_lists (const unsigned char *protectedkey, - size_t replacepos, + size_t replacepos, const unsigned char *cleartext, unsigned char *sha1hash, unsigned char **result, size_t *resultlen, @@ -626,7 +629,7 @@ merge_lists (const unsigned char *protectedkey, const unsigned char *s; const unsigned char *startpos, *endpos; int i, rc; - + *result = NULL; *resultlen = 0; *cutoff = 0; @@ -689,7 +692,7 @@ merge_lists (const unsigned char *protectedkey, goto invalid_sexp; n = snext (&s); if (!smatch (&s, n, "sha1")) - goto invalid_sexp; + goto invalid_sexp; n = snext (&s); if (n != 20) goto invalid_sexp; @@ -702,7 +705,7 @@ merge_lists (const unsigned char *protectedkey, /* append the parameter list */ memcpy (p, startpos, endpos - startpos); p += endpos - startpos; - + /* Skip over the protected list element in the original list. */ s = protectedkey + replacepos; assert (*s == '('); @@ -740,7 +743,7 @@ merge_lists (const unsigned char *protectedkey, *cutoff = p - newlist; memcpy (p, startpos, endpos - startpos); p += endpos - startpos; - + /* ready */ *result = newlist; @@ -763,14 +766,14 @@ merge_lists (const unsigned char *protectedkey, /* Unprotect the key encoded in canonical format. We assume a valid S-Exp here. If a protected-at item is available, its value will be stored at protocted_at unless this is NULL. */ -int +int agent_unprotect (const unsigned char *protectedkey, const char *passphrase, - gnupg_isotime_t protected_at, + gnupg_isotime_t protected_at, unsigned char **result, size_t *resultlen) { int rc; const unsigned char *s; - const unsigned char *protect_list; + const unsigned char *protect_list; size_t n; int infidx, i; unsigned char sha1hash[20], sha1hash2[20]; @@ -792,21 +795,21 @@ agent_unprotect (const unsigned char *protectedkey, const char *passphrase, s++; n = snext (&s); if (!n) - return gpg_error (GPG_ERR_INV_SEXP); + return gpg_error (GPG_ERR_INV_SEXP); if (!smatch (&s, n, "protected-private-key")) - return gpg_error (GPG_ERR_UNKNOWN_SEXP); + return gpg_error (GPG_ERR_UNKNOWN_SEXP); if (*s != '(') return gpg_error (GPG_ERR_UNKNOWN_SEXP); s++; n = snext (&s); if (!n) - return gpg_error (GPG_ERR_INV_SEXP); + return gpg_error (GPG_ERR_INV_SEXP); for (infidx=0; protect_info[infidx].algo && !smatch (&s, n, protect_info[infidx].algo); infidx++) ; if (!protect_info[infidx].algo) - return gpg_error (GPG_ERR_UNSUPPORTED_ALGORITHM); + return gpg_error (GPG_ERR_UNSUPPORTED_ALGORITHM); /* See wether we have a protected-at timestamp. */ @@ -841,7 +844,7 @@ agent_unprotect (const unsigned char *protectedkey, const char *passphrase, /* Now find the list with the protected information. Here is an example for such a list: - (protected openpgp-s2k3-sha1-aes-cbc + (protected openpgp-s2k3-sha1-aes-cbc ((sha1 ) ) ) */ @@ -854,7 +857,7 @@ agent_unprotect (const unsigned char *protectedkey, const char *passphrase, s++; n = snext (&s); if (!n) - return gpg_error (GPG_ERR_INV_SEXP); + return gpg_error (GPG_ERR_INV_SEXP); if (smatch (&s, n, "protected")) break; s += n; @@ -866,7 +869,7 @@ agent_unprotect (const unsigned char *protectedkey, const char *passphrase, /* found */ n = snext (&s); if (!n) - return gpg_error (GPG_ERR_INV_SEXP); + return gpg_error (GPG_ERR_INV_SEXP); if (!smatch (&s, n, "openpgp-s2k3-sha1-" PROT_CIPHER_STRING "-cbc")) return gpg_error (GPG_ERR_UNSUPPORTED_PROTECTION); if (*s != '(' || s[1] != '(') @@ -874,7 +877,7 @@ agent_unprotect (const unsigned char *protectedkey, const char *passphrase, s += 2; n = snext (&s); if (!n) - return gpg_error (GPG_ERR_INV_SEXP); + return gpg_error (GPG_ERR_INV_SEXP); if (!smatch (&s, n, "sha1")) return gpg_error (GPG_ERR_UNSUPPORTED_PROTECTION); n = snext (&s); @@ -890,7 +893,7 @@ agent_unprotect (const unsigned char *protectedkey, const char *passphrase, is nothing we should worry about */ if (s[n] != ')' ) return gpg_error (GPG_ERR_INV_SEXP); - + /* Old versions of gpg-agent used the funny floating point number in a byte encoding as specified by OpenPGP. However this is not needed and thus we now store it as a plain unsigned integer. We @@ -920,8 +923,8 @@ agent_unprotect (const unsigned char *protectedkey, const char *passphrase, s++; n = snext (&s); if (!n) - return gpg_error (GPG_ERR_INV_SEXP); - + return gpg_error (GPG_ERR_INV_SEXP); + rc = do_decryption (s, n, passphrase, s2ksalt, s2kcount, iv, 16, @@ -995,7 +998,7 @@ agent_private_key_type (const unsigned char *privatekey) store this key in the caller provided buffer KEY. The caller must provide an HASHALGO, a valid S2KMODE (see rfc-2440) and depending on that mode an S2KSALT of 8 random bytes and an S2KCOUNT. - + Returns an error code on failure. */ static int hash_passphrase (const char *passphrase, int hashalgo, @@ -1015,7 +1018,7 @@ hash_passphrase (const char *passphrase, int hashalgo, return gpg_error (GPG_ERR_INV_VALUE); if ((s2kmode == 1 ||s2kmode == 3) && !s2ksalt) return gpg_error (GPG_ERR_INV_VALUE); - + rc = gcry_md_open (&md, hashalgo, GCRY_MD_FLAG_SECURE); if (rc) return rc; @@ -1049,7 +1052,7 @@ hash_passphrase (const char *passphrase, int hashalgo, } if (count < 8) gcry_md_write (md, s2ksalt, count); - else + else { gcry_md_write (md, s2ksalt, 8); count -= 8; @@ -1058,7 +1061,7 @@ hash_passphrase (const char *passphrase, int hashalgo, } else gcry_md_write (md, passphrase, pwlen); - + gcry_md_final (md); i = gcry_md_get_algo_dlen (hashalgo); if (i > keylen - used) @@ -1108,7 +1111,7 @@ make_shadow_info (const char *serialno, const char *idstring) S-expression is returned in an allocated buffer RESULT will point to. The input parameters are expected to be valid canonicalized S-expressions */ -int +int agent_shadow_key (const unsigned char *pubkey, const unsigned char *shadow_info, unsigned char **result) @@ -1130,16 +1133,16 @@ agent_shadow_key (const unsigned char *pubkey, s++; n = snext (&s); if (!n) - return gpg_error (GPG_ERR_INV_SEXP); + return gpg_error (GPG_ERR_INV_SEXP); if (!smatch (&s, n, "public-key")) - return gpg_error (GPG_ERR_UNKNOWN_SEXP); + return gpg_error (GPG_ERR_UNKNOWN_SEXP); if (*s != '(') return gpg_error (GPG_ERR_UNKNOWN_SEXP); depth++; s++; - n = snext (&s); + n = snext (&s); if (!n) - return gpg_error (GPG_ERR_INV_SEXP); + return gpg_error (GPG_ERR_INV_SEXP); s += n; /* skip over the algorithm name */ while (*s != ')') @@ -1149,15 +1152,15 @@ agent_shadow_key (const unsigned char *pubkey, depth++; s++; n = snext (&s); - if (!n) - return gpg_error (GPG_ERR_INV_SEXP); + if (!n) + return gpg_error (GPG_ERR_INV_SEXP); s += n; n = snext (&s); if (!n) - return gpg_error (GPG_ERR_INV_SEXP); + return gpg_error (GPG_ERR_INV_SEXP); s +=n; /* skip value */ if (*s != ')') - return gpg_error (GPG_ERR_INV_SEXP); + return gpg_error (GPG_ERR_INV_SEXP); depth--; s++; } @@ -1189,7 +1192,7 @@ agent_shadow_key (const unsigned char *pubkey, /* Parse a canonical encoded shadowed key and return a pointer to the inner list with the shadow_info */ -int +int agent_get_shadow_info (const unsigned char *shadowkey, unsigned char const **shadow_info) { @@ -1204,16 +1207,16 @@ agent_get_shadow_info (const unsigned char *shadowkey, s++; n = snext (&s); if (!n) - return gpg_error (GPG_ERR_INV_SEXP); + return gpg_error (GPG_ERR_INV_SEXP); if (!smatch (&s, n, "shadowed-private-key")) - return gpg_error (GPG_ERR_UNKNOWN_SEXP); + return gpg_error (GPG_ERR_UNKNOWN_SEXP); if (*s != '(') return gpg_error (GPG_ERR_UNKNOWN_SEXP); depth++; s++; - n = snext (&s); + n = snext (&s); if (!n) - return gpg_error (GPG_ERR_INV_SEXP); + return gpg_error (GPG_ERR_INV_SEXP); s += n; /* skip over the algorithm name */ for (;;) @@ -1225,24 +1228,24 @@ agent_get_shadow_info (const unsigned char *shadowkey, depth++; s++; n = snext (&s); - if (!n) - return gpg_error (GPG_ERR_INV_SEXP); + if (!n) + return gpg_error (GPG_ERR_INV_SEXP); if (smatch (&s, n, "shadowed")) break; s += n; n = snext (&s); if (!n) - return gpg_error (GPG_ERR_INV_SEXP); + return gpg_error (GPG_ERR_INV_SEXP); s +=n; /* skip value */ if (*s != ')') - return gpg_error (GPG_ERR_INV_SEXP); + return gpg_error (GPG_ERR_INV_SEXP); depth--; s++; } /* Found the shadowed list, S points to the protocol */ n = snext (&s); - if (!n) - return gpg_error (GPG_ERR_INV_SEXP); + if (!n) + return gpg_error (GPG_ERR_INV_SEXP); if (smatch (&s, n, "t1-v1")) { if (*s != '(') @@ -1262,7 +1265,7 @@ agent_get_shadow_info (const unsigned char *shadowkey, parameters addresses. If the serial number or the ID string is not required, NULL may be passed for them. */ gpg_error_t -parse_shadow_info (const unsigned char *shadow_info, +parse_shadow_info (const unsigned char *shadow_info, char **r_hexsn, char **r_idstr) { const unsigned char *s; @@ -1299,7 +1302,7 @@ parse_shadow_info (const unsigned char *shadow_info, } return gpg_error (GPG_ERR_INV_SEXP); } - + if (r_idstr) { *r_idstr = xtrymalloc (n+1); diff --git a/autogen.sh b/autogen.sh index 60017073e..b81a6b279 100755 --- a/autogen.sh +++ b/autogen.sh @@ -84,7 +84,7 @@ if test "$1" = "--build-w32"; then fi fi - ./configure --enable-maintainer-mode --prefix=${w32root} \ + $tsdir/configure --enable-maintainer-mode --prefix=${w32root} \ --host=${host} --build=${build} \ --enable-gpgtar \ --with-gpg-error-prefix=${w32root} \ diff --git a/common/estream.c b/common/estream.c index 3b6139eb2..9c781a0f1 100644 --- a/common/estream.c +++ b/common/estream.c @@ -79,6 +79,9 @@ #include #include #ifdef HAVE_W32_SYSTEM +# ifdef HAVE_WINSOCK2_H +# include +# endif # include #endif #ifdef HAVE_W32CE_SYSTEM diff --git a/common/homedir.c b/common/homedir.c index d0fc5c631..5adf46a62 100644 --- a/common/homedir.c +++ b/common/homedir.c @@ -23,6 +23,9 @@ #include #ifdef HAVE_W32_SYSTEM +# ifdef HAVE_WINSOCK2_H +# include +# endif #include #ifndef CSIDL_APPDATA #define CSIDL_APPDATA 0x001a @@ -97,7 +100,7 @@ standard_homedir (void) if (!dir) { char path[MAX_PATH]; - + /* It might be better to use LOCAL_APPDATA because this is defined as "non roaming" and thus more likely to be kept locally. For private keys this is desired. However, given @@ -105,13 +108,13 @@ standard_homedir (void) using a system roaming services might be better than to let them do it manually. A security conscious user will anyway use the registry entry to have better control. */ - if (w32_shgetfolderpath (NULL, CSIDL_APPDATA|CSIDL_FLAG_CREATE, - NULL, 0, path) >= 0) + if (w32_shgetfolderpath (NULL, CSIDL_APPDATA|CSIDL_FLAG_CREATE, + NULL, 0, path) >= 0) { char *tmp = xmalloc (strlen (path) + 6 +1); strcpy (stpcpy (tmp, path), "\\gnupg"); dir = tmp; - + /* Try to create the directory if it does not yet exists. */ if (access (dir, F_OK)) CreateDirectory (dir, NULL); @@ -137,7 +140,7 @@ default_homedir (void) if (!dir || !*dir) { static const char *saved_dir; - + if (!saved_dir) { if (!dir || !*dir) @@ -154,7 +157,7 @@ default_homedir (void) if (tmp) saved_dir = tmp; } - + if (!saved_dir) saved_dir = standard_homedir (); } @@ -191,7 +194,7 @@ w32_rootdir (void) else { log_debug ("bad filename `%s' returned for this process\n", dir); - *dir = 0; + *dir = 0; } } @@ -210,8 +213,8 @@ w32_commondir (void) { char path[MAX_PATH]; - if (w32_shgetfolderpath (NULL, CSIDL_COMMON_APPDATA, - NULL, 0, path) >= 0) + if (w32_shgetfolderpath (NULL, CSIDL_COMMON_APPDATA, + NULL, 0, path) >= 0) { char *tmp = xmalloc (strlen (path) + 4 +1); strcpy (stpcpy (tmp, path), "\\GNU"); @@ -226,7 +229,7 @@ w32_commondir (void) dir = xstrdup (w32_rootdir ()); } } - + return dir; } #endif /*HAVE_W32_SYSTEM*/ @@ -388,42 +391,42 @@ gnupg_module_name (int which) strcpy (stpcpy (name, s), s2); \ } \ return name; \ - } while (0) + } while (0) switch (which) { case GNUPG_MODULE_NAME_AGENT: #ifdef GNUPG_DEFAULT_AGENT return GNUPG_DEFAULT_AGENT; -#else +#else X(bindir, "gpg-agent"); #endif - + case GNUPG_MODULE_NAME_PINENTRY: #ifdef GNUPG_DEFAULT_PINENTRY return GNUPG_DEFAULT_PINENTRY; -#else +#else X(bindir, "pinentry"); #endif case GNUPG_MODULE_NAME_SCDAEMON: #ifdef GNUPG_DEFAULT_SCDAEMON return GNUPG_DEFAULT_SCDAEMON; -#else +#else X(libexecdir, "scdaemon"); #endif case GNUPG_MODULE_NAME_DIRMNGR: #ifdef GNUPG_DEFAULT_DIRMNGR return GNUPG_DEFAULT_DIRMNGR; -#else +#else X(bindir, "dirmngr"); #endif case GNUPG_MODULE_NAME_PROTECT_TOOL: #ifdef GNUPG_DEFAULT_PROTECT_TOOL return GNUPG_DEFAULT_PROTECT_TOOL; -#else +#else X(libexecdir, "gpg-protect-tool"); #endif @@ -442,7 +445,7 @@ gnupg_module_name (int which) case GNUPG_MODULE_NAME_GPGCONF: X(bindir, "gpgconf"); - default: + default: BUG (); } #undef X diff --git a/common/http.c b/common/http.c index 49859fa02..15d64c496 100644 --- a/common/http.c +++ b/common/http.c @@ -46,6 +46,9 @@ #include #ifdef HAVE_W32_SYSTEM +# ifdef HAVE_WINSOCK2_H +# include +# endif # include #else /*!HAVE_W32_SYSTEM*/ # include diff --git a/common/init.c b/common/init.c index 5425acee8..7be8af062 100644 --- a/common/init.c +++ b/common/init.c @@ -25,9 +25,12 @@ #endif #ifdef HAVE_W32_SYSTEM +# ifdef HAVE_WINSOCK2_H +# include +# endif #include #endif -#ifdef HAVE_PTH +#ifdef HAVE_PTH #include #endif @@ -46,7 +49,7 @@ void init_common_subsystems (void) { /* Try to auto set the character set. */ - set_native_charset (NULL); + set_native_charset (NULL); #ifdef HAVE_W32_SYSTEM /* For W32 we need to initialize the socket layer. This is because diff --git a/common/iobuf.c b/common/iobuf.c index 04b17ff17..1a84f3f41 100644 --- a/common/iobuf.c +++ b/common/iobuf.c @@ -30,6 +30,9 @@ #include #include #ifdef HAVE_W32_SYSTEM +# ifdef HAVE_WINSOCK2_H +# include +# endif # include #endif #ifdef __riscos__ @@ -43,7 +46,7 @@ /*-- Begin configurable part. --*/ -/* The size of the internal buffers. +/* The size of the internal buffers. NOTE: If you change this value you MUST also adjust the regression test "armored_key_8192" in armor.test! */ #define IOBUF_BUFFER_SIZE 8192 @@ -66,15 +69,15 @@ implementation. What we define here are 3 macros to make the appropriate calls: - my_fileno + my_fileno Is expanded to fileno(a) if using a stdion backend and to a if we are using the low-level backend. - my_fopen + my_fopen Is defined to fopen for the stdio backend and to direct_open if we are using the low-evel backend. - my_fopen_ro + my_fopen_ro Is defined to fopen for the stdio backend and to fd_cache_open if we are using the low-evel backend. @@ -117,7 +120,7 @@ typedef struct { fp_or_fd_t fp; /* Open file pointer or handle. */ - int keep_open; + int keep_open; int no_cache; int eof_seen; int print_only_name; /* Flags indicating that fname is not a real file. */ @@ -196,7 +199,7 @@ fd_cache_strcmp (const char *a, const char *b) #ifdef HAVE_DOSISH_SYSTEM for (; *a && *b; a++, b++) { - if (*a != *b && !((*a == '/' && *b == '\\') + if (*a != *b && !((*a == '/' && *b == '\\') || (*a == '\\' && *b == '/')) ) break; } @@ -353,7 +356,7 @@ direct_open (const char *fname, const char *mode) /* - * Instead of closing an FD we keep it open and cache it for later reuse + * Instead of closing an FD we keep it open and cache it for later reuse * Note that this caching strategy only works if the process does not chdir. */ static void @@ -477,13 +480,13 @@ file_filter (void *opaque, int control, iobuf_t chain, byte * buf, { assert (size); /* We need a buffer. */ if (feof (f)) - { + { /* On terminals you could easily read as many EOFs as you call fread() or fgetc() repeatly. Every call will block until you press CTRL-D. So we catch this case before we call fread() again. */ - rc = -1; - *ret_len = 0; + rc = -1; + *ret_len = 0; } else { @@ -891,7 +894,7 @@ block_filter (void *opaque, int control, iobuf_t chain, byte * buffer, /* log_debug("partial: ctx=%p c=%02x size=%u\n", a, c, a->size); */ } else - BUG (); + BUG (); } while (!rc && size && a->size) @@ -1506,7 +1509,7 @@ iobuf_ioctl (iobuf_t a, int cmd, int intval, void *ptrval) { /* keep system filepointer/descriptor open */ if (DBG_IOBUF) log_debug ("iobuf-%d.%d: ioctl `%s' keep=%d\n", - a ? a->no : -1, a ? a->subno : -1, + a ? a->no : -1, a ? a->subno : -1, a && a->desc ? a->desc : "?", intval); for (; a; a = a->chain) @@ -1543,7 +1546,7 @@ iobuf_ioctl (iobuf_t a, int cmd, int intval, void *ptrval) { /* disallow/allow caching */ if (DBG_IOBUF) log_debug ("iobuf-%d.%d: ioctl `%s' no_cache=%d\n", - a ? a->no : -1, a ? a->subno : -1, + a ? a->no : -1, a ? a->subno : -1, a && a->desc? a->desc : "?", intval); for (; a; a = a->chain) @@ -1663,7 +1666,7 @@ iobuf_push_filter2 (iobuf_t a, if (DBG_IOBUF) { - log_debug ("iobuf-%d.%d: push `%s'\n", a->no, a->subno, + log_debug ("iobuf-%d.%d: push `%s'\n", a->no, a->subno, a->desc?a->desc:"?"); print_chain (a); } @@ -2170,24 +2173,24 @@ iobuf_get_filelength (iobuf_t a, int *overflow) if (overflow) *overflow = 0; - - if ( a->directfp ) + + if ( a->directfp ) { FILE *fp = a->directfp; - + if ( !fstat(fileno(fp), &st) ) return st.st_size; log_error("fstat() failed: %s\n", strerror(errno) ); return 0; } - + /* Hmmm: file_filter may have already been removed */ for ( ; a; a = a->chain ) if ( !a->chain && a->filter == file_filter ) { file_filter_ctx_t *b = a->filter_ov; fp_or_fd_t fp = b->fp; - + #if defined(HAVE_W32_SYSTEM) && !defined(FILE_FILTER_USES_STDIO) ulong size; static int (* __stdcall get_file_size_ex) (void *handle, @@ -2197,7 +2200,7 @@ iobuf_get_filelength (iobuf_t a, int *overflow) if (!get_file_size_ex_initialized) { void *handle; - + handle = dlopen ("kernel32.dll", RTLD_LAZY); if (handle) { @@ -2207,21 +2210,21 @@ iobuf_get_filelength (iobuf_t a, int *overflow) } get_file_size_ex_initialized = 1; } - + if (get_file_size_ex) { /* This is a newer system with GetFileSizeEx; we use this then because it seem that GetFileSize won't return a proper error in case a file is larger than 4GB. */ LARGE_INTEGER exsize; - + if (get_file_size_ex (fp, &exsize)) { if (!exsize.u.HighPart) return exsize.u.LowPart; if (overflow) *overflow = 1; - return 0; + return 0; } } else @@ -2238,14 +2241,14 @@ iobuf_get_filelength (iobuf_t a, int *overflow) #endif break/*the for loop*/; } - + return 0; } /* Return the file descriptor of the underlying file or -1 if it is not available. */ -int +int iobuf_get_fd (iobuf_t a) { if (a->directfp) @@ -2518,7 +2521,7 @@ translate_file_handle (int fd, int for_write) # else { int x; - + (void)for_write; if (fd == 0) @@ -2551,13 +2554,13 @@ iobuf_skip_rest (iobuf_t a, unsigned long n, int partial) { for (;;) { - if (a->nofast || a->d.start >= a->d.len) + if (a->nofast || a->d.start >= a->d.len) { if (iobuf_readbyte (a) == -1) { break; } - } + } else { unsigned long count = a->d.len - a->d.start; @@ -2565,11 +2568,11 @@ iobuf_skip_rest (iobuf_t a, unsigned long n, int partial) a->d.start = a->d.len; } } - } + } else { unsigned long remaining = n; - while (remaining > 0) + while (remaining > 0) { if (a->nofast || a->d.start >= a->d.len) { @@ -2578,11 +2581,11 @@ iobuf_skip_rest (iobuf_t a, unsigned long n, int partial) break; } --remaining; - } - else + } + else { unsigned long count = a->d.len - a->d.start; - if (count > remaining) + if (count > remaining) { count = remaining; } diff --git a/common/sysutils.c b/common/sysutils.c index 8e0c75c1a..82bc81f56 100644 --- a/common/sysutils.c +++ b/common/sysutils.c @@ -43,10 +43,15 @@ # include #endif #ifdef HAVE_W32_SYSTEM -# define WINVER 0x0500 /* Required for AllowSetForegroundWindow. */ +# ifndef WINVER +# define WINVER 0x0500 /* Required for AllowSetForegroundWindow. */ +# endif +# ifdef HAVE_WINSOCK2_H +# include +# endif # include #endif -#ifdef HAVE_PTH +#ifdef HAVE_PTH # include #endif #include @@ -144,8 +149,8 @@ get_session_marker( size_t *rlen ) initialized = 1; /* Although this marker is guessable it is not easy to use * for a faked control packet because an attacker does not - * have enough control about the time the verification does - * take place. Of course, we can add just more random but + * have enough control about the time the verification does + * take place. Of course, we can add just more random but * than we need the random generator even for verification * tasks - which does not make sense. */ a = aa ^ (ulong)getpid(); @@ -260,7 +265,7 @@ gnupg_sleep (unsigned int seconds) the process will give up its timeslot. */ if (!seconds) { -# ifdef HAVE_W32_SYSTEM +# ifdef HAVE_W32_SYSTEM Sleep (0); # else sleep (0); @@ -269,7 +274,7 @@ gnupg_sleep (unsigned int seconds) pth_sleep (seconds); #else /* Fixme: make sure that a sleep won't wake up to early. */ -# ifdef HAVE_W32_SYSTEM +# ifdef HAVE_W32_SYSTEM Sleep (seconds*1000); # else sleep (seconds); @@ -291,7 +296,7 @@ translate_sys2libc_fd (gnupg_fd_t fd, int for_write) if (fd == GNUPG_INVALID_FD) return -1; - + /* Note that _open_osfhandle is currently defined to take and return a long. */ x = _open_osfhandle ((long)fd, for_write ? 1 : 0); @@ -414,7 +419,7 @@ gnupg_tmpfile (void) Must be called before we open any files! */ void gnupg_reopen_std (const char *pgmname) -{ +{ #if defined(HAVE_STAT) && !defined(HAVE_W32_SYSTEM) struct stat statbuf; int did_stdin = 0; @@ -429,7 +434,7 @@ gnupg_reopen_std (const char *pgmname) else did_stdin = 2; } - + if (fstat (STDOUT_FILENO, &statbuf) == -1 && errno == EBADF) { if (open ("/dev/null",O_WRONLY) == STDOUT_FILENO) @@ -478,13 +483,13 @@ gnupg_reopen_std (const char *pgmname) /* Hack required for Windows. */ -void +void gnupg_allow_set_foregound_window (pid_t pid) { if (!pid) log_info ("%s called with invalid pid %lu\n", "gnupg_allow_set_foregound_window", (unsigned long)pid); -#ifdef HAVE_W32_SYSTEM +#ifdef HAVE_W32_SYSTEM else if (!AllowSetForegroundWindow ((pid_t)pid == (pid_t)(-1)?ASFW_ANY:pid)) log_info ("AllowSetForegroundWindow(%lu) failed: %s\n", (unsigned long)pid, w32_strerror (-1)); diff --git a/common/ttyio.c b/common/ttyio.c index fc274070c..e70a205ba 100644 --- a/common/ttyio.c +++ b/common/ttyio.c @@ -25,23 +25,26 @@ #include #include #ifdef HAVE_TCGETATTR -#include +# include #else -#ifdef HAVE_TERMIO_H -/* simulate termios with termio */ -#include -#define termios termio -#define tcsetattr ioctl -#define TCSAFLUSH TCSETAF -#define tcgetattr(A,B) ioctl(A,TCGETA,B) -#define HAVE_TCGETATTR -#endif +# ifdef HAVE_TERMIO_H + /* Simulate termios with termio. */ +# include +# define termios termio +# define tcsetattr ioctl +# define TCSAFLUSH TCSETAF +# define tcgetattr(A,B) ioctl(A,TCGETA,B) +# define HAVE_TCGETATTR +# endif #endif #ifdef _WIN32 /* use the odd Win32 functions */ -#include -#ifdef HAVE_TCGETATTR -#error mingw32 and termios -#endif +# ifdef HAVE_WINSOCK2_H +# include +# endif +# include +# ifdef HAVE_TCGETATTR +# error mingw32 and termios +# endif #endif #include #include @@ -179,7 +182,7 @@ init_ttyfp(void) if (my_rl_init_stream) my_rl_init_stream (ttyfp); #endif - + #ifdef HAVE_TCGETATTR atexit( cleanup ); @@ -218,7 +221,7 @@ tty_printf( const char *fmt, ... ) va_start( arg_ptr, fmt ) ; #ifdef _WIN32 - { + { char *buf = NULL; int n; DWORD nwritten; @@ -226,7 +229,7 @@ tty_printf( const char *fmt, ... ) n = vasprintf(&buf, fmt, arg_ptr); if( !buf ) log_bug("vasprintf() failed\n"); - + if( !WriteConsoleA( con.out, buf, n, &nwritten, NULL ) ) log_fatal("WriteConsole failed: rc=%d", (int)GetLastError() ); if( n != nwritten ) @@ -265,7 +268,7 @@ tty_fprintf (FILE *fp, const char *fmt, ... ) va_start( arg_ptr, fmt ) ; #ifdef _WIN32 - { + { char *buf = NULL; int n; DWORD nwritten; @@ -273,7 +276,7 @@ tty_fprintf (FILE *fp, const char *fmt, ... ) n = vasprintf(&buf, fmt, arg_ptr); if( !buf ) log_bug("vasprintf() failed\n"); - + if( !WriteConsoleA( con.out, buf, n, &nwritten, NULL ) ) log_fatal("WriteConsole failed: rc=%d", (int)GetLastError() ); if( n != nwritten ) @@ -531,7 +534,7 @@ tty_get( const char *prompt ) { char *line; char *buf; - + if (!initialized) init_ttyfp(); diff --git a/g10/exec.c b/g10/exec.c index 6ab24793f..331c5ec2a 100644 --- a/g10/exec.c +++ b/g10/exec.c @@ -17,7 +17,7 @@ * along with this program; if not, see . */ -/* +/* FIXME: We should replace most code in this module by our spawn implementation from common/exechelp.c. */ @@ -33,7 +33,10 @@ #include #endif #ifdef HAVE_DOSISH_SYSTEM -#include +# ifdef HAVE_WINSOCK2_H +# include +# endif +# include #endif #include #include @@ -50,7 +53,7 @@ #include "exec.h" #ifdef NO_EXEC -int +int exec_write(struct exec_info **info,const char *program, const char *args_in,const char *name,int writeonly,int binary) { @@ -71,7 +74,7 @@ set_exec_path(const char *path) { return G10ERR_GENERAL; } /* This is a nicer system() for windows that waits for programs to return before returning control to the caller. I hate helpful computers. */ -static int +static int w32_system(const char *command) { PROCESS_INFORMATION pi; @@ -103,7 +106,7 @@ w32_system(const char *command) #endif /* Replaces current $PATH */ -int +int set_exec_path(const char *path) { char *p; @@ -126,7 +129,7 @@ set_exec_path(const char *path) } /* Makes a temp directory and filenames */ -static int +static int make_tempdir(struct exec_info *info) { char *tmp=opt.temp_dir,*namein=info->name,*nameout; @@ -208,7 +211,7 @@ make_tempdir(struct exec_info *info) /* Expands %i and %o in the args to the full temp files within the temp directory. */ -static int +static int expand_args(struct exec_info *info,const char *args_in) { const char *ch = args_in; @@ -297,7 +300,7 @@ expand_args(struct exec_info *info,const char *args_in) If there are args, but no tempfiles, then it's a fork/exec/pipe via shell -c. If there are tempfiles, then it's a system. */ -int +int exec_write(struct exec_info **info,const char *program, const char *args_in,const char *name,int writeonly,int binary) { @@ -599,7 +602,7 @@ exec_finish(struct exec_info *info) log_info(_("WARNING: unable to remove tempfile (%s) `%s': %s\n"), "in",info->tempfile_in,strerror(errno)); } - + if(info->tempfile_out) { if(unlink(info->tempfile_out)==-1) diff --git a/g10/gpg.c b/g10/gpg.c index b77309983..ffe964e6d 100644 --- a/g10/gpg.c +++ b/g10/gpg.c @@ -31,7 +31,10 @@ #endif #include #ifdef HAVE_W32_SYSTEM -#include +# ifdef HAVE_WINSOCK2_H +# include +# endif +# include #endif #define INCLUDED_BY_MAIN_MODULE 1 @@ -273,7 +276,7 @@ enum cmd_and_opt_values oS2KDigest, oS2KCipher, oS2KCount, - oSimpleSKChecksum, + oSimpleSKChecksum, oDisplayCharset, oNotDashEscaped, oEscapeFrom, @@ -302,7 +305,7 @@ enum cmd_and_opt_values oNoAllowNonSelfsignedUID, oAllowFreeformUID, oNoAllowFreeformUID, - oAllowSecretKeyImport, + oAllowSecretKeyImport, oEnableSpecialFilenames, oNoLiteral, oSetFilesize, @@ -392,7 +395,7 @@ static ARGPARSE_OPTS opts[] = { ARGPARSE_c (aListSecretKeys, "list-secret-keys", N_("list secret keys")), ARGPARSE_c (aKeygen, "gen-key", N_("generate a new key pair")), ARGPARSE_c (aGenRevoke, "gen-revoke",N_("generate a revocation certificate")), - ARGPARSE_c (aDeleteKeys,"delete-keys", + ARGPARSE_c (aDeleteKeys,"delete-keys", N_("remove keys from the public keyring")), ARGPARSE_c (aDeleteSecretKeys, "delete-secret-keys", N_("remove keys from the secret keyring")), @@ -405,9 +408,9 @@ static ARGPARSE_OPTS opts[] = { ARGPARSE_c (aExport, "export" , N_("export keys") ), ARGPARSE_c (aSendKeys, "send-keys" , N_("export keys to a key server") ), ARGPARSE_c (aRecvKeys, "recv-keys" , N_("import keys from a key server") ), - ARGPARSE_c (aSearchKeys, "search-keys" , + ARGPARSE_c (aSearchKeys, "search-keys" , N_("search for keys on a key server") ), - ARGPARSE_c (aRefreshKeys, "refresh-keys", + ARGPARSE_c (aRefreshKeys, "refresh-keys", N_("update all keys from a keyserver")), ARGPARSE_c (aLocateKeys, "locate-keys", "@"), ARGPARSE_c (aFetchKeys, "fetch-keys" , "@" ), @@ -596,7 +599,7 @@ static ARGPARSE_OPTS opts[] = { /* More hidden commands and options. */ ARGPARSE_c (aPrintMDs, "print-mds", "@"), /* old */ ARGPARSE_c (aListTrustDB, "list-trustdb", "@"), - /* Not yet used: + /* Not yet used: ARGPARSE_c (aListTrustPath, "list-trust-path", "@"), */ ARGPARSE_c (aDeleteSecretAndPublicKeys, "delete-secret-and-public-keys", "@"), @@ -620,8 +623,8 @@ static ARGPARSE_OPTS opts[] = { ARGPARSE_s_n (oNoArmor, "no-armour", "@"), ARGPARSE_s_n (oNoDefKeyring, "no-default-keyring", "@"), ARGPARSE_s_n (oNoGreeting, "no-greeting", "@"), - ARGPARSE_s_n (oNoOptions, "no-options", "@"), - ARGPARSE_s_s (oHomedir, "homedir", "@"), + ARGPARSE_s_n (oNoOptions, "no-options", "@"), + ARGPARSE_s_s (oHomedir, "homedir", "@"), ARGPARSE_s_n (oNoBatch, "no-batch", "@"), ARGPARSE_s_n (oWithColons, "with-colons", "@"), ARGPARSE_s_n (oWithKeyData,"with-key-data", "@"), @@ -732,8 +735,8 @@ static ARGPARSE_OPTS opts[] = { ARGPARSE_s_s (oKeyidFormat, "keyid-format", "@"), ARGPARSE_s_n (oExitOnStatusWriteError, "exit-on-status-write-error", "@"), ARGPARSE_s_i (oLimitCardInsertTries, "limit-card-insert-tries", "@"), - - ARGPARSE_s_n (oAllowMultisigVerification, + + ARGPARSE_s_n (oAllowMultisigVerification, "allow-multisig-verification", "@"), ARGPARSE_s_n (oEnableDSA2, "enable-dsa2", "@"), ARGPARSE_s_n (oDisableDSA2, "disable-dsa2", "@"), @@ -788,7 +791,7 @@ make_libversion (const char *libname, const char *(*getfnc)(const char*)) { const char *s; char *result; - + if (maybe_setuid) { gcry_control (GCRYCTL_INIT_SECMEM, 0, 0); /* Drop setuid. */ @@ -858,14 +861,14 @@ my_strusage( int level ) break; case 35: if( !ciphers ) - ciphers = build_list(_("Cipher: "), 'S', + ciphers = build_list(_("Cipher: "), 'S', openpgp_cipher_algo_name, openpgp_cipher_test_algo ); p = ciphers; break; case 36: if( !digests ) - digests = build_list(_("Hash: "), 'H', + digests = build_list(_("Hash: "), 'H', gcry_md_algo_name, openpgp_md_test_algo ); p = digests; @@ -961,7 +964,7 @@ static void set_opt_session_env (const char *name, const char *value) { gpg_error_t err; - + err = session_env_setenv (opt.session_env, name, value); if (err) log_fatal ("error setting session environment: %s\n", @@ -995,7 +998,7 @@ set_debug (const char *level) /* Unless the "guru" string has been used we don't want to allow hashing debugging. The rationale is that people tend to select the highest debug value and would then clutter their - disk with debug files which may reveal confidential data. */ + disk with debug files which may reveal confidential data. */ if (numok) opt.debug &= ~(DBG_HASHING_VALUE); } @@ -1019,17 +1022,17 @@ set_debug (const char *level) if (opt.debug) log_info ("enabled debug flags:%s%s%s%s%s%s%s%s%s%s%s%s%s\n", - (opt.debug & DBG_PACKET_VALUE )? " packet":"", - (opt.debug & DBG_MPI_VALUE )? " mpi":"", - (opt.debug & DBG_CIPHER_VALUE )? " cipher":"", - (opt.debug & DBG_FILTER_VALUE )? " filter":"", - (opt.debug & DBG_IOBUF_VALUE )? " iobuf":"", - (opt.debug & DBG_MEMORY_VALUE )? " memory":"", - (opt.debug & DBG_CACHE_VALUE )? " cache":"", - (opt.debug & DBG_MEMSTAT_VALUE)? " memstat":"", - (opt.debug & DBG_TRUST_VALUE )? " trust":"", - (opt.debug & DBG_HASHING_VALUE)? " hashing":"", - (opt.debug & DBG_EXTPROG_VALUE)? " extprog":"", + (opt.debug & DBG_PACKET_VALUE )? " packet":"", + (opt.debug & DBG_MPI_VALUE )? " mpi":"", + (opt.debug & DBG_CIPHER_VALUE )? " cipher":"", + (opt.debug & DBG_FILTER_VALUE )? " filter":"", + (opt.debug & DBG_IOBUF_VALUE )? " iobuf":"", + (opt.debug & DBG_MEMORY_VALUE )? " memory":"", + (opt.debug & DBG_CACHE_VALUE )? " cache":"", + (opt.debug & DBG_MEMSTAT_VALUE)? " memstat":"", + (opt.debug & DBG_TRUST_VALUE )? " trust":"", + (opt.debug & DBG_HASHING_VALUE)? " hashing":"", + (opt.debug & DBG_EXTPROG_VALUE)? " extprog":"", (opt.debug & DBG_CARD_IO_VALUE)? " cardio":"", (opt.debug & DBG_ASSUAN_VALUE )? " assuan":""); } @@ -1092,7 +1095,7 @@ open_info_file (const char *fname, int for_write, int binary) (void)for_write; (void)binary; return -1; -#else +#else int fd; if (binary) @@ -1118,7 +1121,7 @@ open_info_file (const char *fname, int for_write, int binary) if ( fd == -1) log_error ( for_write? _("can't create `%s': %s\n") : _("can't open `%s': %s\n"), fname, strerror(errno)); - + return fd; #endif } @@ -1559,7 +1562,7 @@ list_config(char *items) printf("\n"); any=1; } - + if(show_all || ascii_strcasecmp(name,"compress")==0) { printf("cfg:compress:"); @@ -1824,7 +1827,7 @@ get_default_configname (void) if (configname) { char *tok; - + xfree (configname); configname = NULL; @@ -1835,13 +1838,13 @@ get_default_configname (void) else break; } - + configname = make_filename (opt.homedir, name, NULL); } while (access (configname, R_OK)); xfree(name); - + if (! configname) configname = make_filename (opt.homedir, "gpg" EXTSEP_S "conf", NULL); if (! access (configname, R_OK)) @@ -2048,7 +2051,7 @@ main (int argc, char **argv) /* Initialize the secure memory. */ if (!gcry_control (GCRYCTL_INIT_SECMEM, 32768, 0)) - got_secmem = 1; + got_secmem = 1; #if defined(HAVE_GETUID) && defined(HAVE_GETEUID) /* There should be no way to get to this spot while still carrying setuid privs. Just in case, bomb out if we are. */ @@ -2065,7 +2068,7 @@ main (int argc, char **argv) malloc_hooks.free = gcry_free; assuan_set_malloc_hooks (&malloc_hooks); assuan_set_gpg_err_source (GPG_ERR_SOURCE_DEFAULT); - + /* Try for a version specific config file first */ default_configname = get_default_configname (); @@ -2125,55 +2128,55 @@ main (int argc, char **argv) { switch( pargs.r_opt ) { - case aCheckKeys: + case aCheckKeys: case aListConfig: case aGPGConfList: case aGPGConfTest: case aListPackets: - case aImport: - case aFastImport: - case aSendKeys: - case aRecvKeys: + case aImport: + case aFastImport: + case aSendKeys: + case aRecvKeys: case aSearchKeys: case aRefreshKeys: case aFetchKeys: - case aExport: + case aExport: #ifdef ENABLE_CARD_SUPPORT case aCardStatus: - case aCardEdit: + case aCardEdit: case aChangePIN: #endif /* ENABLE_CARD_SUPPORT*/ - case aListKeys: + case aListKeys: case aLocateKeys: - case aListSigs: - case aExportSecret: - case aExportSecretSub: + case aListSigs: + case aExportSecret: + case aExportSecretSub: case aSym: - case aClearsign: - case aGenRevoke: - case aDesigRevoke: - case aPrimegen: + case aClearsign: + case aGenRevoke: + case aDesigRevoke: + case aPrimegen: case aGenRandom: case aPrintMD: - case aPrintMDs: - case aListTrustDB: + case aPrintMDs: + case aListTrustDB: case aCheckTrustDB: - case aUpdateTrustDB: - case aFixTrustDB: - case aListTrustPath: - case aDeArmor: - case aEnArmor: - case aSign: - case aSignKey: + case aUpdateTrustDB: + case aFixTrustDB: + case aListTrustPath: + case aDeArmor: + case aEnArmor: + case aSign: + case aSignKey: case aLSignKey: - case aStore: - case aExportOwnerTrust: - case aImportOwnerTrust: + case aStore: + case aExportOwnerTrust: + case aImportOwnerTrust: case aRebuildKeydbCaches: set_cmd (&cmd, pargs.r_opt); break; - case aKeygen: + case aKeygen: case aEditKey: case aDeleteSecretKeys: case aDeleteSecretAndPublicKeys: @@ -2223,7 +2226,7 @@ main (int argc, char **argv) case oNoUseAgent: obsolete_option (configname, configlineno, "--no-use-agent"); break; - case oGpgAgentInfo: + case oGpgAgentInfo: obsolete_option (configname, configlineno, "--gpg-agent-info"); break; @@ -2286,12 +2289,12 @@ main (int argc, char **argv) case oNoArmor: opt.no_armor=1; opt.armor=0; break; case oNoDefKeyring: default_keyring = 0; break; case oNoGreeting: nogreeting = 1; break; - case oNoVerbose: + case oNoVerbose: opt.verbose = 0; gcry_control (GCRYCTL_SET_VERBOSITY, (int)opt.verbose); opt.list_sigs=0; break; - case oQuickRandom: + case oQuickRandom: gcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0); break; case oEmitVersion: opt.no_version=0; break; @@ -2321,12 +2324,12 @@ main (int argc, char **argv) case oWithColons: opt.with_colons=':'; break; case oWithSigCheck: opt.check_sigs = 1; /*FALLTHRU*/ - case oWithSigList: opt.list_sigs = 1; break; + case oWithSigList: opt.list_sigs = 1; break; case oSkipVerify: opt.skip_verify=1; break; - case oSkipHiddenRecipients: - case oNoSkipHiddenRecipients: + case oSkipHiddenRecipients: + case oNoSkipHiddenRecipients: /* Dummies for options to be used in 2.1. */ break; @@ -2574,7 +2577,7 @@ main (int argc, char **argv) case oCommandFile: opt.command_fd = open_info_file (pargs.r.ret_str, 0, 1); break; - case oCipherAlgo: + case oCipherAlgo: def_cipher_string = xstrdup(pargs.r.ret_str); break; case oDigestAlgo: @@ -2604,12 +2607,12 @@ main (int argc, char **argv) compress_algo_string = xstrdup(pargs.r.ret_str); } break; - case oCertDigestAlgo: + case oCertDigestAlgo: cert_digest_string = xstrdup(pargs.r.ret_str); break; - case oNoSecmemWarn: - gcry_control (GCRYCTL_DISABLE_SECMEM_WARN); + case oNoSecmemWarn: + gcry_control (GCRYCTL_DISABLE_SECMEM_WARN); break; case oRequireSecmem: require_secmem=1; break; @@ -2882,8 +2885,8 @@ main (int argc, char **argv) } break; - case oStrict: - case oNoStrict: + case oStrict: + case oNoStrict: /* Not used */ break; @@ -2908,8 +2911,8 @@ main (int argc, char **argv) opt.exit_on_status_write_error = 1; break; - case oLimitCardInsertTries: - opt.limit_card_insert_tries = pargs.r.ret_int; + case oLimitCardInsertTries: + opt.limit_card_insert_tries = pargs.r.ret_int; break; case oRequireCrossCert: opt.flags.require_cross_cert=1; break; @@ -2943,7 +2946,7 @@ main (int argc, char **argv) case oNoop: break; - default: + default: pargs.err = configfp? ARGPARSE_PRINT_WARNING:ARGPARSE_PRINT_ERROR; break; } @@ -3350,12 +3353,12 @@ main (int argc, char **argv) avoid adding the secret keyring for a couple of commands to avoid unneeded access in case the secrings are stored on a floppy. - + We always need to add the keyrings if we are running under SELinux, this is so that the rings are added to the list of secured files. */ - if( ALWAYS_ADD_KEYRINGS - || (cmd != aDeArmor && cmd != aEnArmor && cmd != aGPGConfTest) ) + if( ALWAYS_ADD_KEYRINGS + || (cmd != aDeArmor && cmd != aEnArmor && cmd != aGPGConfTest) ) { if (ALWAYS_ADD_KEYRINGS || (cmd != aCheckKeys && cmd != aListSigs && cmd != aListKeys @@ -3405,11 +3408,11 @@ main (int argc, char **argv) switch (cmd) { - case aStore: - case aSym: - case aSign: - case aSignSym: - case aClearsign: + case aStore: + case aSym: + case aSign: + case aSignSym: + case aClearsign: if (!opt.quiet && any_explicit_recipient) log_info (_("WARNING: recipients (-r) given " "without using public key encryption\n")); @@ -3579,7 +3582,7 @@ main (int argc, char **argv) log_error("decrypt_message failed: %s\n", g10_errstr(rc) ); } break; - + case aSignKey: if( argc != 1 ) wrong_args(_("--sign-key user-id")); @@ -3951,7 +3954,7 @@ main (int argc, char **argv) wrong_args("--import-ownertrust [file]"); import_ownertrust( argc? *argv:NULL ); break; - + case aRebuildKeydbCaches: if (argc) wrong_args ("--rebuild-keydb-caches"); @@ -4064,7 +4067,7 @@ g10_exit( int rc ) gcry_control (GCRYCTL_DUMP_SECMEM_STATS ); emergency_cleanup (); - + rc = rc? rc : log_get_errorcount(0)? 2 : g10_errors_seen? 1 : 0; exit (rc); } @@ -4158,12 +4161,12 @@ print_hashline( gcry_md_hd_t md, int algo, const char *fname ) { int i, n; const byte *p; - + if ( fname ) { for (p = fname; *p; p++ ) { if ( *p <= 32 || *p > 127 || *p == ':' || *p == '%' ) printf("%%%02X", *p ); - else + else putchar( *p ); } } @@ -4171,7 +4174,7 @@ print_hashline( gcry_md_hd_t md, int algo, const char *fname ) printf("%d:", algo ); p = gcry_md_read (md, algo); n = gcry_md_get_algo_dlen (algo); - for(i=0; i < n ; i++, p++ ) + for(i=0; i < n ; i++, p++ ) printf("%02X", *p ); putchar(':'); putchar('\n'); @@ -4229,7 +4232,7 @@ print_mds( const char *fname, int algo ) else { gcry_md_final (md); if ( opt.with_colons ) { - if ( algo ) + if ( algo ) print_hashline( md, algo, fname ); else { print_hashline( md, GCRY_MD_MD5, fname ); @@ -4328,7 +4331,7 @@ add_policy_url( const char *string, int which ) sl=add_to_strlist( &opt.sig_policy_url, string ); if(critical) - sl->flags |= 1; + sl->flags |= 1; } static void @@ -4361,5 +4364,5 @@ add_keyserver_url( const char *string, int which ) sl=add_to_strlist( &opt.sig_keyserver_url, string ); if(critical) - sl->flags |= 1; + sl->flags |= 1; } diff --git a/g10/misc.c b/g10/misc.c index 1a937f1a6..6e9b31ef9 100644 --- a/g10/misc.c +++ b/g10/misc.c @@ -40,6 +40,9 @@ #ifdef HAVE_W32_SYSTEM #include #include +#ifdef HAVE_WINSOCK2_H +# include +#endif #include #include #ifndef CSIDL_APPDATA diff --git a/g10/photoid.c b/g10/photoid.c index 37156f296..615837e2e 100644 --- a/g10/photoid.c +++ b/g10/photoid.c @@ -21,7 +21,10 @@ #include #include #include -#ifdef _WIN32 +#ifdef _WIN32 +# ifdef HAVE_WINSOCK2_H +# include +# endif # include # ifndef VER_PLATFORM_WIN32_WINDOWS # define VER_PLATFORM_WIN32_WINDOWS 1 @@ -121,7 +124,7 @@ generate_photo_id(PKT_public_key *pk,const char *photo_name) continue; } - + len=iobuf_get_filelength(file, &overflow); if(len>6144 || overflow) { diff --git a/jnlib/stringhelp.c b/jnlib/stringhelp.c index 3173ebc15..c43b120d6 100644 --- a/jnlib/stringhelp.c +++ b/jnlib/stringhelp.c @@ -30,6 +30,9 @@ #include #include #ifdef HAVE_W32_SYSTEM +# ifdef HAVE_WINSOCK2_H +# include +# endif # include #endif @@ -230,7 +233,7 @@ length_sans_trailing_chars (const unsigned char *line, size_t len, { const unsigned char *p, *mark; size_t n; - + for( mark=NULL, p=line, n=0; n < len; n++, p++ ) { if (strchr (trimchars, *p )) @@ -241,8 +244,8 @@ length_sans_trailing_chars (const unsigned char *line, size_t len, else mark = NULL; } - - if (mark) + + if (mark) return mark - line; return len; } @@ -355,16 +358,16 @@ do_make_filename (int xmode, const char *first_part, va_list arg_ptr) { const char *argv[32]; int argc; - size_t n; + size_t n; int skip = 1; char *home_buffer = NULL; - char *name, *home, *p; - - n = strlen (first_part) + 1; + char *name, *home, *p; + + n = strlen (first_part) + 1; argc = 0; - while ( (argv[argc] = va_arg (arg_ptr, const char *)) ) + while ( (argv[argc] = va_arg (arg_ptr, const char *)) ) { - n += strlen (argv[argc]) + 1; + n += strlen (argv[argc]) + 1; if (argc >= DIM (argv)-1) { if (xmode) @@ -372,11 +375,11 @@ do_make_filename (int xmode, const char *first_part, va_list arg_ptr) errno = EINVAL; return NULL; } - argc++; + argc++; } n++; - - home = NULL; + + home = NULL; if (*first_part == '~') { if (first_part[1] == '/' || !first_part[1]) @@ -386,13 +389,13 @@ do_make_filename (int xmode, const char *first_part, va_list arg_ptr) if (!home) home = home_buffer = get_pwdir (xmode, NULL); if (home && *home) - n += strlen (home); + n += strlen (home); } else { /* This is the "~username/" or "~username" case. */ char *user; - + if (xmode) user = jnlib_xstrdup (first_part+1); else @@ -405,7 +408,7 @@ do_make_filename (int xmode, const char *first_part, va_list arg_ptr) if (p) *p = 0; skip = 1 + strlen (user); - + home = home_buffer = get_pwdir (xmode, user); jnlib_free (user); if (home) @@ -426,7 +429,7 @@ do_make_filename (int xmode, const char *first_part, va_list arg_ptr) return NULL; } } - + if (home) p = stpcpy (stpcpy (name, home), first_part + skip); else @@ -481,9 +484,9 @@ int compare_filenames (const char *a, const char *b) { #ifdef HAVE_DRIVE_LETTERS - for ( ; *a && *b; a++, b++ ) + for ( ; *a && *b; a++, b++ ) { - if (*a != *b + if (*a != *b && (toupper (*(const unsigned char*)a) != toupper (*(const unsigned char*)b) ) && !((*a == '/' && *b == '\\') || (*a == '\\' && *b == '/'))) @@ -492,7 +495,7 @@ compare_filenames (const char *a, const char *b) if ((*a == '/' && *b == '\\') || (*a == '\\' && *b == '/')) return 0; else - return (toupper (*(const unsigned char*)a) + return (toupper (*(const unsigned char*)a) - toupper (*(const unsigned char*)b)); #else return strcmp(a,b); @@ -531,7 +534,7 @@ hextobyte (const char *s) /* Print a BUFFER to stream FP while replacing all control characters and the characters DELIM and DELIM2 with standard C escape sequences. Returns the number of characters printed. */ -size_t +size_t print_sanitized_buffer2 (FILE *fp, const void *buffer, size_t length, int delim, int delim2) { @@ -540,9 +543,9 @@ print_sanitized_buffer2 (FILE *fp, const void *buffer, size_t length, for (; length; length--, p++, count++) { - if (*p < 0x20 + if (*p < 0x20 || *p == 0x7f - || *p == delim + || *p == delim || *p == delim2 || ((delim || delim2) && *p=='\\')) { @@ -595,7 +598,7 @@ print_sanitized_buffer2 (FILE *fp, const void *buffer, size_t length, } /* Same as print_sanitized_buffer2 but with just one delimiter. */ -size_t +size_t print_sanitized_buffer (FILE *fp, const void *buffer, size_t length, int delim) { @@ -603,7 +606,7 @@ print_sanitized_buffer (FILE *fp, const void *buffer, size_t length, } -size_t +size_t print_sanitized_utf8_buffer (FILE *fp, const void *buffer, size_t length, int delim) { @@ -611,7 +614,7 @@ print_sanitized_utf8_buffer (FILE *fp, const void *buffer, size_t i; /* We can handle plain ascii simpler, so check for it first. */ - for (i=0; i < length; i++ ) + for (i=0; i < length; i++ ) { if ( (p[i] & 0x80) ) break; @@ -630,20 +633,20 @@ print_sanitized_utf8_buffer (FILE *fp, const void *buffer, } -size_t +size_t print_sanitized_string2 (FILE *fp, const char *string, int delim, int delim2) { return string? print_sanitized_buffer2 (fp, string, strlen (string), delim, delim2):0; } -size_t +size_t print_sanitized_string (FILE *fp, const char *string, int delim) { return string? print_sanitized_buffer (fp, string, strlen (string), delim):0; } -size_t +size_t print_sanitized_utf8_string (FILE *fp, const char *string, int delim) { return string? print_sanitized_utf8_buffer (fp, @@ -663,7 +666,7 @@ sanitize_buffer (const void *p_arg, size_t n, int delim) char *buffer, *d; /* First count length. */ - for (save_n = n, save_p = p, buflen=1 ; n; n--, p++ ) + for (save_n = n, save_p = p, buflen=1 ; n; n--, p++ ) { if ( *p < 0x20 || *p == 0x7f || *p == delim || (delim && *p=='\\')) { @@ -735,13 +738,13 @@ const char * w32_strerror (int ec) { static char strerr[256]; - + if (ec == -1) ec = (int)GetLastError (); FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM, NULL, ec, MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT), strerr, DIM (strerr)-1, NULL); - return strerr; + return strerr; } #endif /*HAVE_W32_SYSTEM*/ @@ -762,7 +765,7 @@ ascii_islower (int c) return c >= 'a' && c <= 'z'; } -int +int ascii_toupper (int c) { if (c >= 'a' && c <= 'z') @@ -770,7 +773,7 @@ ascii_toupper (int c) return c; } -int +int ascii_tolower (int c) { if (c >= 'A' && c <= 'Z') @@ -792,7 +795,7 @@ ascii_strcasecmp( const char *a, const char *b ) return *a == *b? 0 : (ascii_toupper (*a) - ascii_toupper (*b)); } -int +int ascii_strncasecmp (const char *a, const char *b, size_t n) { const unsigned char *p1 = (const unsigned char *)a; @@ -814,7 +817,7 @@ ascii_strncasecmp (const char *a, const char *b, size_t n) ++p2; } while (c1 == c2); - + return c1 - c2; } @@ -860,7 +863,7 @@ ascii_memcasemem (const void *haystack, size_t nhaystack, { const char *a = haystack; const char *b = a + nhaystack - nneedle; - + for (; a <= b; a++) { if ( !ascii_memcasecmp (a, needle, nneedle) ) diff --git a/jnlib/w32-gettext.c b/jnlib/w32-gettext.c index 834b2aa17..14cb1e1be 100644 --- a/jnlib/w32-gettext.c +++ b/jnlib/w32-gettext.c @@ -6,12 +6,12 @@ modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. - + This program 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 Lesser General Public License for more details. - + You should have received a copy of the GNU Lesser General Public License along with this program; if not, see . */ @@ -32,6 +32,9 @@ #include #include #include +#ifdef HAVE_WINSOCK2_H +# include +#endif #include #ifdef JNLIB_IN_JNLIB @@ -595,8 +598,8 @@ #ifndef SUBLANG_UZBEK_CYRILLIC #define SUBLANG_UZBEK_CYRILLIC 0x02 #endif - -/* Return an XPG style locale name + +/* Return an XPG style locale name language[_territory[.codeset]][@modifier]. Don't even bother determining the codeset; it's not useful in this context, because message catalogs are not specific to a single @@ -1034,7 +1037,7 @@ hash_string( const char *str_param ) { unsigned long int hval, g; const char *str = str_param; - + hval = 0; while (*str != '\0') { @@ -1158,7 +1161,7 @@ free_domain (struct loaded_domain *domain) jnlib_free (domain); } - + static struct loaded_domain * load_domain (const char *filename) { @@ -1169,7 +1172,7 @@ load_domain (const char *filename) struct loaded_domain *domain = NULL; size_t to_read; char *read_ptr; - + fp = fopen (filename, "rb"); if (!fp) return NULL; @@ -1225,7 +1228,7 @@ load_domain (const char *filename) domain->data = (char *) data; domain->data_native = (char *) data + size; domain->must_swap = data->magic != MAGIC; - + /* Fill in the information about the available tables. */ switch (SWAPIT (domain->must_swap, data->revision)) { @@ -1276,7 +1279,7 @@ utf8_to_wchar (const char *string, size_t length, size_t *retlen) return NULL; nbytes = (size_t)(n+1) * sizeof(*result); - if (nbytes / sizeof(*result) != (n+1)) + if (nbytes / sizeof(*result) != (n+1)) { errno = ENOMEM; return NULL; @@ -1465,17 +1468,17 @@ get_string (struct loaded_domain *domain, uint32_t idx, + SWAPIT(domain->must_swap, domain->trans_tab[idx].offset)); translen = SWAPIT(domain->must_swap, domain->trans_tab[idx].length); } - else if (!domain->mapped[idx]) + else if (!domain->mapped[idx]) { /* Not yet mapped. Map from utf-8 to native encoding now. */ const char *p_utf8; size_t plen_utf8, buflen; char *buf; - p_utf8 = (domain->data + p_utf8 = (domain->data + SWAPIT(domain->must_swap, domain->trans_tab[idx].offset)); plen_utf8 = SWAPIT(domain->must_swap, domain->trans_tab[idx].length); - + buf = utf8_to_native (p_utf8, plen_utf8, &buflen); if (!buf) { @@ -1487,7 +1490,7 @@ get_string (struct loaded_domain *domain, uint32_t idx, /* Copy into the DATA_NATIVE area. */ char *p_tmp; - p_tmp = (domain->data_native + p_tmp = (domain->data_native + SWAPIT(domain->must_swap, domain->trans_tab[idx].offset)); memcpy (p_tmp, buf, buflen); domain->mapped[idx] = buflen; @@ -1523,7 +1526,7 @@ get_string (struct loaded_domain *domain, uint32_t idx, } jnlib_free (buf); } - else if (domain->mapped[idx] == 1) + else if (domain->mapped[idx] == 1) { /* The translated string is in the overflow_space. */ for (os=domain->overflow_space; os; os = os->next) @@ -1540,8 +1543,8 @@ get_string (struct loaded_domain *domain, uint32_t idx, translen = 0; } } - else - { + else + { trans = (domain->data_native + SWAPIT(domain->must_swap, domain->trans_tab[idx].offset)); translen = domain->mapped[idx]; @@ -1559,7 +1562,7 @@ do_gettext (const char *msgid, const char *msgid2, unsigned long nplural) { struct loaded_domain *domain; uint32_t top, bottom, nstr; - + if (!(domain = the_domain)) goto not_found; @@ -1576,7 +1579,7 @@ do_gettext (const char *msgid, const char *msgid2, unsigned long nplural) { nstr--; if (nstr < domain->nstrings - && SWAPIT(domain->must_swap, + && SWAPIT(domain->must_swap, domain->orig_tab[nstr].length) >= len && !strcmp (msgid, (domain->data + SWAPIT(domain->must_swap, @@ -1599,7 +1602,7 @@ do_gettext (const char *msgid, const char *msgid2, unsigned long nplural) while (bottom < top) { int cmp_val; - + nstr = (bottom + top) / 2; cmp_val = strcmp (msgid, (domain->data + SWAPIT(domain->must_swap, @@ -1671,10 +1674,10 @@ gettext_select_utf8 (int value) int main (int argc, char **argv) { - const char atext1[] = + const char atext1[] = "Warning: You have entered an insecure passphrase.%%0A" "A passphrase should be at least %u character long."; - const char atext2[] = + const char atext2[] = "Warning: You have entered an insecure passphrase.%%0A" "A passphrase should be at least %u characters long."; @@ -1683,7 +1686,7 @@ main (int argc, char **argv) argc--; argv++; } - + bindtextdomain ("gnupg2", "c:/programme/gnu/gnupg/share/locale"); printf ("locale is `%s'\n", gettext_localename ()); diff --git a/jnlib/w32-reg.c b/jnlib/w32-reg.c index e6bd911c5..a6e239548 100644 --- a/jnlib/w32-reg.c +++ b/jnlib/w32-reg.c @@ -25,6 +25,9 @@ #include #include #include +#ifdef HAVE_WINSOCK2_H +# include +#endif #include #include "libjnlib-config.h" @@ -34,7 +37,7 @@ static HKEY get_root_key(const char *root) { HKEY root_key; - + if (!root) root_key = HKEY_CURRENT_USER; else if (!strcmp( root, "HKEY_CLASSES_ROOT" ) ) @@ -51,7 +54,7 @@ get_root_key(const char *root) root_key = HKEY_CURRENT_CONFIG; else return NULL; - + return root_key; } @@ -65,10 +68,10 @@ read_w32_registry_string (const char *root, const char *dir, const char *name) HKEY root_key, key_handle; DWORD n1, nbytes, type; char *result = NULL; - + if ( !(root_key = get_root_key(root) ) ) return NULL; - + if ( RegOpenKeyEx( root_key, dir, 0, KEY_READ, &key_handle ) ) { if (root) @@ -94,7 +97,7 @@ read_w32_registry_string (const char *root, const char *dir, const char *name) if (type == REG_EXPAND_SZ && strchr (result, '%')) { char *tmp; - + n1 += 1000; tmp = jnlib_malloc (n1+1); if (!tmp) @@ -111,7 +114,7 @@ read_w32_registry_string (const char *root, const char *dir, const char *name) if (nbytes && nbytes > n1) { /* Oops - truncated, better don't expand at all. */ - jnlib_free (tmp); + jnlib_free (tmp); goto leave; } tmp[nbytes] = 0; @@ -126,14 +129,14 @@ read_w32_registry_string (const char *root, const char *dir, const char *name) result = jnlib_malloc (strlen (tmp)+1); if (!result) result = tmp; - else + else { strcpy (result, tmp); jnlib_free (tmp); } } - else - { + else + { /* Error - don't expand. */ jnlib_free (tmp); } @@ -146,22 +149,22 @@ read_w32_registry_string (const char *root, const char *dir, const char *name) int -write_w32_registry_string (const char *root, const char *dir, +write_w32_registry_string (const char *root, const char *dir, const char *name, const char *value) { HKEY root_key, reg_key; - + if ( !(root_key = get_root_key(root) ) ) return -1; - - if ( RegOpenKeyEx( root_key, dir, 0, KEY_WRITE, ®_key ) + + if ( RegOpenKeyEx( root_key, dir, 0, KEY_WRITE, ®_key ) != ERROR_SUCCESS ) return -1; - - if ( RegSetValueEx (reg_key, name, 0, REG_SZ, (BYTE *)value, + + if ( RegSetValueEx (reg_key, name, 0, REG_SZ, (BYTE *)value, strlen( value ) ) != ERROR_SUCCESS ) { - if ( RegCreateKey( root_key, name, ®_key ) != ERROR_SUCCESS ) + if ( RegCreateKey( root_key, name, ®_key ) != ERROR_SUCCESS ) { RegCloseKey(reg_key); return -1; @@ -173,9 +176,9 @@ write_w32_registry_string (const char *root, const char *dir, return -1; } } - + RegCloseKey (reg_key); - + return 0; } diff --git a/keyserver/gpgkeys_finger.c b/keyserver/gpgkeys_finger.c index 721cb9acf..a599e4d2c 100644 --- a/keyserver/gpgkeys_finger.c +++ b/keyserver/gpgkeys_finger.c @@ -28,7 +28,10 @@ #endif #ifdef HAVE_W32_SYSTEM -#include +# ifdef HAVE_WINSOCK2_H +# include +# endif +# include #else #include #include @@ -79,9 +82,9 @@ connect_server (const char *server, unsigned short port) /* Win32 gethostbyname doesn't handle IP addresses internally, so we try inet_addr first on that platform only. */ - if ((l = inet_addr (server)) != INADDR_NONE) + if ((l = inet_addr (server)) != INADDR_NONE) memcpy (&addr.sin_addr, &l, sizeof l); - else if ((hp = gethostbyname (server))) + else if ((hp = gethostbyname (server))) { if (hp->h_addrtype != AF_INET) { @@ -107,14 +110,14 @@ connect_server (const char *server, unsigned short port) sock = socket (AF_INET, SOCK_STREAM, 0); if (sock == INVALID_SOCKET) { - fprintf (console, "gpgkeys: error creating socket: ec=%d\n", + fprintf (console, "gpgkeys: error creating socket: ec=%d\n", (int)WSAGetLastError ()); return -1; } if (connect (sock, (struct sockaddr *)&addr, sizeof addr)) { - fprintf (console, "gpgkeys: error connecting `%s': ec=%d\n", + fprintf (console, "gpgkeys: error connecting `%s': ec=%d\n", server, (int)WSAGetLastError ()); sock_close (sock); return -1; @@ -134,26 +137,26 @@ connect_server (const char *server, unsigned short port) server, strerror (errno)); return -1; } - + addr.sin_addr = *(struct in_addr*)host->h_addr; sock = socket (AF_INET, SOCK_STREAM, 0); if (sock == -1) { - fprintf (console, "gpgkeys: error creating socket: %s\n", + fprintf (console, "gpgkeys: error creating socket: %s\n", strerror (errno)); return -1; } - + if (connect (sock, (struct sockaddr *)&addr, sizeof addr) == -1) { - fprintf (console, "gpgkeys: error connecting `%s': %s\n", + fprintf (console, "gpgkeys: error connecting `%s': %s\n", server, strerror (errno)); close (sock); return -1; } #endif - + return sock; } @@ -163,11 +166,11 @@ write_server (int sock, const char *data, size_t length) int nleft; nleft = length; - while (nleft > 0) + while (nleft > 0) { int nwritten; - -#ifdef HAVE_W32_SYSTEM + +#ifdef HAVE_W32_SYSTEM nwritten = send (sock, data, nleft, 0); if ( nwritten == SOCKET_ERROR ) { @@ -184,7 +187,7 @@ write_server (int sock, const char *data, size_t length) if (errno == EAGAIN) { struct timeval tv; - + tv.tv_sec = 0; tv.tv_usec = 50000; select(0, NULL, NULL, NULL, &tv); @@ -197,7 +200,7 @@ write_server (int sock, const char *data, size_t length) nleft -=nwritten; data += nwritten; } - + return 0; } @@ -227,7 +230,7 @@ send_request (const char *request, int *r_sock) return KEYSERVER_GENERAL_ERROR; } *server++ = 0; - + sock = connect_server (server, 79); if (sock == -1) { @@ -272,7 +275,7 @@ get_key (char *getkey) sock_close (sock); return KEYSERVER_OK; } - + /* Hmmm, we use iobuf here only to cope with Windows socket peculiarities (we can't used fdopen). */ fp_read = iobuf_sockopen (sock , "r"); @@ -286,7 +289,7 @@ get_key (char *getkey) while ( iobuf_read_line ( fp_read, &line, &buflen, &maxlen)) { maxlen=1024; - + if(gotit) { print_nocr(output, (const char*)line); @@ -299,7 +302,7 @@ get_key (char *getkey) gotit=1; } } - + if(gotit) fprintf (output,"KEY 0x%s END\n", getkey); else @@ -316,7 +319,7 @@ get_key (char *getkey) } -static void +static void show_help (FILE *fp) { fprintf (fp,"-h, --help\thelp\n"); diff --git a/keyserver/ksutil.c b/keyserver/ksutil.c index cc46b92a9..7231d0a0a 100644 --- a/keyserver/ksutil.c +++ b/keyserver/ksutil.c @@ -36,7 +36,10 @@ #include #ifdef HAVE_W32_SYSTEM -#include +# ifdef HAVE_WINSOCK2_H +# include +# endif +# include #endif #ifdef HAVE_LIBCURL @@ -78,7 +81,7 @@ register_timeout(void) sigemptyset(&act.sa_mask); act.sa_flags=0; return sigaction(SIGALRM,&act,NULL); -#else +#else if(signal(SIGALRM,catch_alarm)==SIG_ERR) return -1; else @@ -597,7 +600,7 @@ ks_hextobyte (const char *s) /* Non localized version of toupper. */ -int +int ks_toupper (int c) { if (c >= 'a' && c <= 'z') diff --git a/scd/apdu.c b/scd/apdu.c index 4f40a6958..372932aee 100644 --- a/scd/apdu.c +++ b/scd/apdu.c @@ -82,7 +82,7 @@ #endif #if defined(__APPLE__) || defined(_WIN32) || defined(__CYGWIN__) -typedef unsinged int pcsc_dword_t; +typedef unsigned int pcsc_dword_t; #else typedef unsigned long pcsc_dword_t; #endif