mirror of
git://git.gnupg.org/gnupg.git
synced 2025-01-03 12:11:33 +01:00
common: Replace macro based function calls by using DEFAULT_ERRSOURCE.
* common/dns-cert.h (get_dns_cert): Remove macro. * common/dns-cert.c (_get_dns_cert): Rename to get_dns_cert. Replace arg ERRSOURCE by global DEFAULT_ERRSOURCE. * common/http.h (http_parse_uri, http_raw_connect, http_open) (http_open_document, http_wait_response): Remove macros. * common/http.c (_http_parse_uri, _http_raw_connect, _http_open) (_http_open_document, _http_wait_response): Remove underscore from symbols. Replace args ERRSOURCE by global DEFAULT_ERRSOURCE. * common/ssh-utils.h (ssh_get_fingerprint) (ssh_get_fingerprint_string): Remove macros. * common/ssh-utils.h (_ssh_get_fingerprint) (_ssh_get_fingerprint_string): Remove underscore from symbols. Replace args ERRSOURCE by global DEFAULT_ERRSOURCE. * common/tlv.h (parse_ber_header, parse_sexp): Remove macros. * common/tlv.c: Include util.h. (_parse_ber_header, _parse_sexp): Remove underscore from symbols. Replace args ERRSOURCE by global DEFAULT_ERRSOURCE.
This commit is contained in:
parent
115a6ed55d
commit
13ec74481c
@ -71,9 +71,8 @@
|
|||||||
first CERT found with a supported type; it is expected that only
|
first CERT found with a supported type; it is expected that only
|
||||||
one CERT record is used. */
|
one CERT record is used. */
|
||||||
gpg_error_t
|
gpg_error_t
|
||||||
_get_dns_cert (const char *name, estream_t *r_key,
|
get_dns_cert (const char *name, estream_t *r_key,
|
||||||
unsigned char **r_fpr, size_t *r_fprlen, char **r_url,
|
unsigned char **r_fpr, size_t *r_fprlen, char **r_url)
|
||||||
gpg_err_source_t errsource)
|
|
||||||
{
|
{
|
||||||
#ifdef USE_DNS_CERT
|
#ifdef USE_DNS_CERT
|
||||||
#ifdef USE_ADNS
|
#ifdef USE_ADNS
|
||||||
@ -90,7 +89,7 @@ _get_dns_cert (const char *name, estream_t *r_key,
|
|||||||
|
|
||||||
if (adns_init (&state, adns_if_noerrprint, NULL))
|
if (adns_init (&state, adns_if_noerrprint, NULL))
|
||||||
{
|
{
|
||||||
err = gpg_err_make (errsource, gpg_err_code_from_syserror ());
|
err = gpg_err_make (default_errsource, gpg_err_code_from_syserror ());
|
||||||
log_error ("error initializing adns: %s\n", strerror (errno));
|
log_error ("error initializing adns: %s\n", strerror (errno));
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
@ -98,7 +97,7 @@ _get_dns_cert (const char *name, estream_t *r_key,
|
|||||||
if (adns_synchronous (state, name, (adns_r_unknown | my_adns_r_cert),
|
if (adns_synchronous (state, name, (adns_r_unknown | my_adns_r_cert),
|
||||||
adns_qf_quoteok_query, &answer))
|
adns_qf_quoteok_query, &answer))
|
||||||
{
|
{
|
||||||
err = gpg_err_make (errsource, gpg_err_code_from_syserror ());
|
err = gpg_err_make (default_errsource, gpg_err_code_from_syserror ());
|
||||||
/* log_error ("DNS query failed: %s\n", strerror (errno)); */
|
/* log_error ("DNS query failed: %s\n", strerror (errno)); */
|
||||||
adns_finish (state);
|
adns_finish (state);
|
||||||
return err;
|
return err;
|
||||||
@ -108,11 +107,11 @@ _get_dns_cert (const char *name, estream_t *r_key,
|
|||||||
/* log_error ("DNS query returned an error: %s (%s)\n", */
|
/* log_error ("DNS query returned an error: %s (%s)\n", */
|
||||||
/* adns_strerror (answer->status), */
|
/* adns_strerror (answer->status), */
|
||||||
/* adns_errabbrev (answer->status)); */
|
/* adns_errabbrev (answer->status)); */
|
||||||
err = gpg_err_make (errsource, GPG_ERR_NOT_FOUND);
|
err = gpg_err_make (default_errsource, GPG_ERR_NOT_FOUND);
|
||||||
goto leave;
|
goto leave;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = gpg_err_make (errsource, GPG_ERR_NOT_FOUND);
|
err = gpg_err_make (default_errsource, GPG_ERR_NOT_FOUND);
|
||||||
for (count = 0; count < answer->nrrs; count++)
|
for (count = 0; count < answer->nrrs; count++)
|
||||||
{
|
{
|
||||||
int datalen = answer->rrs.byteblock[count].len;
|
int datalen = answer->rrs.byteblock[count].len;
|
||||||
@ -132,7 +131,8 @@ _get_dns_cert (const char *name, estream_t *r_key,
|
|||||||
thus we do the same. */
|
thus we do the same. */
|
||||||
*r_key = es_fopenmem_init (0, "rwb", data, datalen);
|
*r_key = es_fopenmem_init (0, "rwb", data, datalen);
|
||||||
if (!*r_key)
|
if (!*r_key)
|
||||||
err = gpg_err_make (errsource, gpg_err_code_from_syserror ());
|
err = gpg_err_make (default_errsource,
|
||||||
|
gpg_err_code_from_syserror ());
|
||||||
else
|
else
|
||||||
err = 0;
|
err = 0;
|
||||||
goto leave;
|
goto leave;
|
||||||
@ -149,7 +149,8 @@ _get_dns_cert (const char *name, estream_t *r_key,
|
|||||||
*r_fpr = xtrymalloc (*r_fprlen);
|
*r_fpr = xtrymalloc (*r_fprlen);
|
||||||
if (!*r_fpr)
|
if (!*r_fpr)
|
||||||
{
|
{
|
||||||
err = gpg_err_make (errsource, gpg_err_code_from_syserror ());
|
err = gpg_err_make (default_errsource,
|
||||||
|
gpg_err_code_from_syserror ());
|
||||||
goto leave;
|
goto leave;
|
||||||
}
|
}
|
||||||
memcpy (*r_fpr, data + 1, *r_fprlen);
|
memcpy (*r_fpr, data + 1, *r_fprlen);
|
||||||
@ -162,7 +163,8 @@ _get_dns_cert (const char *name, estream_t *r_key,
|
|||||||
*url = xtrymalloc (datalen - (*r_fprlen + 1) + 1);
|
*url = xtrymalloc (datalen - (*r_fprlen + 1) + 1);
|
||||||
if (!*r_url)
|
if (!*r_url)
|
||||||
{
|
{
|
||||||
err = gpg_err_make (errsource, gpg_err_code_from_syserror ());
|
err = gpg_err_make (default_errsource,
|
||||||
|
gpg_err_code_from_syserror ());
|
||||||
xfree (*r_fpr);
|
xfree (*r_fpr);
|
||||||
*r_fpr = NULL;
|
*r_fpr = NULL;
|
||||||
goto leave;
|
goto leave;
|
||||||
@ -198,9 +200,9 @@ _get_dns_cert (const char *name, estream_t *r_key,
|
|||||||
/* Allocate a 64k buffer which is the limit for an DNS response. */
|
/* Allocate a 64k buffer which is the limit for an DNS response. */
|
||||||
answer = xtrymalloc (65536);
|
answer = xtrymalloc (65536);
|
||||||
if (!answer)
|
if (!answer)
|
||||||
return gpg_err_make (errsource, gpg_err_code_from_syserror ());
|
return gpg_err_make (default_errsource, gpg_err_code_from_syserror ());
|
||||||
|
|
||||||
err = gpg_err_make (errsource, GPG_ERR_NOT_FOUND);
|
err = gpg_err_make (default_errsource, GPG_ERR_NOT_FOUND);
|
||||||
|
|
||||||
r = res_query (name, C_IN, T_CERT, answer, 65536);
|
r = res_query (name, C_IN, T_CERT, answer, 65536);
|
||||||
/* Not too big, not too small, no errors and at least 1 answer. */
|
/* Not too big, not too small, no errors and at least 1 answer. */
|
||||||
@ -220,7 +222,7 @@ _get_dns_cert (const char *name, estream_t *r_key,
|
|||||||
rc = dn_skipname (pt, emsg);
|
rc = dn_skipname (pt, emsg);
|
||||||
if (rc == -1)
|
if (rc == -1)
|
||||||
{
|
{
|
||||||
err = gpg_err_make (errsource, GPG_ERR_INV_OBJ);
|
err = gpg_err_make (default_errsource, GPG_ERR_INV_OBJ);
|
||||||
goto leave;
|
goto leave;
|
||||||
}
|
}
|
||||||
pt += rc + QFIXEDSZ;
|
pt += rc + QFIXEDSZ;
|
||||||
@ -238,7 +240,7 @@ _get_dns_cert (const char *name, estream_t *r_key,
|
|||||||
rc = dn_skipname (pt, emsg); /* the name we just queried for */
|
rc = dn_skipname (pt, emsg); /* the name we just queried for */
|
||||||
if (rc == -1)
|
if (rc == -1)
|
||||||
{
|
{
|
||||||
err = gpg_err_make (errsource, GPG_ERR_INV_OBJ);
|
err = gpg_err_make (default_errsource, GPG_ERR_INV_OBJ);
|
||||||
goto leave;
|
goto leave;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -289,7 +291,8 @@ _get_dns_cert (const char *name, estream_t *r_key,
|
|||||||
/* PGP type */
|
/* PGP type */
|
||||||
*r_key = es_fopenmem_init (0, "rwb", pt, dlen);
|
*r_key = es_fopenmem_init (0, "rwb", pt, dlen);
|
||||||
if (!*r_key)
|
if (!*r_key)
|
||||||
err = gpg_err_make (errsource, gpg_err_code_from_syserror ());
|
err = gpg_err_make (default_errsource,
|
||||||
|
gpg_err_code_from_syserror ());
|
||||||
else
|
else
|
||||||
err = 0;
|
err = 0;
|
||||||
goto leave;
|
goto leave;
|
||||||
@ -304,7 +307,7 @@ _get_dns_cert (const char *name, estream_t *r_key,
|
|||||||
*r_fpr = xtrymalloc (*r_fprlen);
|
*r_fpr = xtrymalloc (*r_fprlen);
|
||||||
if (!*r_fpr)
|
if (!*r_fpr)
|
||||||
{
|
{
|
||||||
err = gpg_err_make (errsource,
|
err = gpg_err_make (default_errsource,
|
||||||
gpg_err_code_from_syserror ());
|
gpg_err_code_from_syserror ());
|
||||||
goto leave;
|
goto leave;
|
||||||
}
|
}
|
||||||
@ -318,7 +321,7 @@ _get_dns_cert (const char *name, estream_t *r_key,
|
|||||||
*r_url = xtrymalloc (dlen - (*r_fprlen + 1) + 1);
|
*r_url = xtrymalloc (dlen - (*r_fprlen + 1) + 1);
|
||||||
if (!*r_fpr)
|
if (!*r_fpr)
|
||||||
{
|
{
|
||||||
err = gpg_err_make (errsource,
|
err = gpg_err_make (default_errsource,
|
||||||
gpg_err_code_from_syserror ());
|
gpg_err_code_from_syserror ());
|
||||||
xfree (*r_fpr);
|
xfree (*r_fpr);
|
||||||
*r_fpr = NULL;
|
*r_fpr = NULL;
|
||||||
@ -351,6 +354,6 @@ _get_dns_cert (const char *name, estream_t *r_key,
|
|||||||
(void)r_fprlen;
|
(void)r_fprlen;
|
||||||
(void)r_url;
|
(void)r_url;
|
||||||
|
|
||||||
return gpg_err_make (errsource, GPG_ERR_NOT_SUPPORTED);
|
return gpg_err_make (default_errsource, GPG_ERR_NOT_SUPPORTED);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -19,12 +19,9 @@
|
|||||||
#ifndef GNUPG_COMMON_DNS_CERT_H
|
#ifndef GNUPG_COMMON_DNS_CERT_H
|
||||||
#define GNUPG_COMMON_DNS_CERT_H
|
#define GNUPG_COMMON_DNS_CERT_H
|
||||||
|
|
||||||
gpg_error_t _get_dns_cert (const char *name, estream_t *r_key,
|
gpg_error_t get_dns_cert (const char *name, estream_t *r_key,
|
||||||
unsigned char **r_fpr, size_t *r_fprlen,
|
unsigned char **r_fpr, size_t *r_fprlen,
|
||||||
char **r_url,
|
char **r_url);
|
||||||
gpg_err_source_t errsource);
|
|
||||||
#define get_dns_cert(a,b,c,d,e) \
|
|
||||||
_get_dns_cert ((a),(b),(c),(d),(e), GPG_ERR_SOURCE_DEFAULT);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
104
common/http.c
104
common/http.c
@ -155,8 +155,7 @@ static int insert_escapes (char *buffer, const char *string,
|
|||||||
const char *special);
|
const char *special);
|
||||||
static uri_tuple_t parse_tuple (char *string);
|
static uri_tuple_t parse_tuple (char *string);
|
||||||
static gpg_error_t send_request (http_t hd, const char *auth,const char *proxy,
|
static gpg_error_t send_request (http_t hd, const char *auth,const char *proxy,
|
||||||
const char *srvtag,strlist_t headers,
|
const char *srvtag,strlist_t headers);
|
||||||
gpg_err_source_t errsource);
|
|
||||||
static char *build_rel_path (parsed_uri_t uri);
|
static char *build_rel_path (parsed_uri_t uri);
|
||||||
static gpg_error_t parse_response (http_t hd);
|
static gpg_error_t parse_response (http_t hd);
|
||||||
|
|
||||||
@ -428,10 +427,9 @@ http_register_tls_callback ( gpg_error_t (*cb) (http_t, void *, int) )
|
|||||||
pointer for completing the the request and to wait for the
|
pointer for completing the the request and to wait for the
|
||||||
response. */
|
response. */
|
||||||
gpg_error_t
|
gpg_error_t
|
||||||
_http_open (http_t *r_hd, http_req_t reqtype, const char *url,
|
http_open (http_t *r_hd, http_req_t reqtype, const char *url,
|
||||||
const char *auth, unsigned int flags, const char *proxy,
|
const char *auth, unsigned int flags, const char *proxy,
|
||||||
void *tls_context, const char *srvtag, strlist_t headers,
|
void *tls_context, const char *srvtag, strlist_t headers)
|
||||||
gpg_err_source_t errsource)
|
|
||||||
{
|
{
|
||||||
gpg_error_t err;
|
gpg_error_t err;
|
||||||
http_t hd;
|
http_t hd;
|
||||||
@ -439,7 +437,7 @@ _http_open (http_t *r_hd, http_req_t reqtype, const char *url,
|
|||||||
*r_hd = NULL;
|
*r_hd = NULL;
|
||||||
|
|
||||||
if (!(reqtype == HTTP_REQ_GET || reqtype == HTTP_REQ_POST))
|
if (!(reqtype == HTTP_REQ_GET || reqtype == HTTP_REQ_POST))
|
||||||
return gpg_err_make (errsource, GPG_ERR_INV_ARG);
|
return gpg_err_make (default_errsource, GPG_ERR_INV_ARG);
|
||||||
|
|
||||||
/* Create the handle. */
|
/* Create the handle. */
|
||||||
hd = xtrycalloc (1, sizeof *hd);
|
hd = xtrycalloc (1, sizeof *hd);
|
||||||
@ -449,9 +447,9 @@ _http_open (http_t *r_hd, http_req_t reqtype, const char *url,
|
|||||||
hd->flags = flags;
|
hd->flags = flags;
|
||||||
hd->tls_context = tls_context;
|
hd->tls_context = tls_context;
|
||||||
|
|
||||||
err = _http_parse_uri (&hd->uri, url, 0, errsource);
|
err = http_parse_uri (&hd->uri, url, 0);
|
||||||
if (!err)
|
if (!err)
|
||||||
err = send_request (hd, auth, proxy, srvtag, headers, errsource);
|
err = send_request (hd, auth, proxy, srvtag, headers);
|
||||||
|
|
||||||
if (err)
|
if (err)
|
||||||
{
|
{
|
||||||
@ -472,9 +470,8 @@ _http_open (http_t *r_hd, http_req_t reqtype, const char *url,
|
|||||||
this http abstraction layer. This has the advantage of providing
|
this http abstraction layer. This has the advantage of providing
|
||||||
service tags and an estream interface. */
|
service tags and an estream interface. */
|
||||||
gpg_error_t
|
gpg_error_t
|
||||||
_http_raw_connect (http_t *r_hd, const char *server, unsigned short port,
|
http_raw_connect (http_t *r_hd, const char *server, unsigned short port,
|
||||||
unsigned int flags, const char *srvtag,
|
unsigned int flags, const char *srvtag)
|
||||||
gpg_err_source_t errsource)
|
|
||||||
{
|
{
|
||||||
gpg_error_t err = 0;
|
gpg_error_t err = 0;
|
||||||
int sock;
|
int sock;
|
||||||
@ -495,15 +492,16 @@ _http_raw_connect (http_t *r_hd, const char *server, unsigned short port,
|
|||||||
sock = connect_server (server, port, hd->flags, srvtag, &hnf);
|
sock = connect_server (server, port, hd->flags, srvtag, &hnf);
|
||||||
if (sock == -1)
|
if (sock == -1)
|
||||||
{
|
{
|
||||||
err = gpg_err_make (errsource, (hnf? GPG_ERR_UNKNOWN_HOST
|
err = gpg_err_make (default_errsource,
|
||||||
:gpg_err_code_from_syserror ()));
|
(hnf? GPG_ERR_UNKNOWN_HOST
|
||||||
|
: gpg_err_code_from_syserror ()));
|
||||||
xfree (hd);
|
xfree (hd);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
hd->sock = my_socket_new (sock);
|
hd->sock = my_socket_new (sock);
|
||||||
if (!hd->sock)
|
if (!hd->sock)
|
||||||
{
|
{
|
||||||
err = gpg_err_make (errsource, gpg_err_code_from_syserror ());
|
err = gpg_err_make (default_errsource, gpg_err_code_from_syserror ());
|
||||||
xfree (hd);
|
xfree (hd);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
@ -512,14 +510,14 @@ _http_raw_connect (http_t *r_hd, const char *server, unsigned short port,
|
|||||||
cookie = xtrycalloc (1, sizeof *cookie);
|
cookie = xtrycalloc (1, sizeof *cookie);
|
||||||
if (!cookie)
|
if (!cookie)
|
||||||
{
|
{
|
||||||
err = gpg_err_make (errsource, gpg_err_code_from_syserror ());
|
err = gpg_err_make (default_errsource, gpg_err_code_from_syserror ());
|
||||||
goto leave;
|
goto leave;
|
||||||
}
|
}
|
||||||
cookie->sock = my_socket_ref (hd->sock);
|
cookie->sock = my_socket_ref (hd->sock);
|
||||||
hd->fp_write = es_fopencookie (cookie, "w", cookie_functions);
|
hd->fp_write = es_fopencookie (cookie, "w", cookie_functions);
|
||||||
if (!hd->fp_write)
|
if (!hd->fp_write)
|
||||||
{
|
{
|
||||||
err = gpg_err_make (errsource, gpg_err_code_from_syserror ());
|
err = gpg_err_make (default_errsource, gpg_err_code_from_syserror ());
|
||||||
my_socket_unref (cookie->sock);
|
my_socket_unref (cookie->sock);
|
||||||
xfree (cookie);
|
xfree (cookie);
|
||||||
goto leave;
|
goto leave;
|
||||||
@ -529,14 +527,14 @@ _http_raw_connect (http_t *r_hd, const char *server, unsigned short port,
|
|||||||
cookie = xtrycalloc (1, sizeof *cookie);
|
cookie = xtrycalloc (1, sizeof *cookie);
|
||||||
if (!cookie)
|
if (!cookie)
|
||||||
{
|
{
|
||||||
err = gpg_err_make (errsource, gpg_err_code_from_syserror ());
|
err = gpg_err_make (default_errsource, gpg_err_code_from_syserror ());
|
||||||
goto leave;
|
goto leave;
|
||||||
}
|
}
|
||||||
cookie->sock = my_socket_ref (hd->sock);
|
cookie->sock = my_socket_ref (hd->sock);
|
||||||
hd->fp_read = es_fopencookie (cookie, "r", cookie_functions);
|
hd->fp_read = es_fopencookie (cookie, "r", cookie_functions);
|
||||||
if (!hd->fp_read)
|
if (!hd->fp_read)
|
||||||
{
|
{
|
||||||
err = gpg_err_make (errsource, gpg_err_code_from_syserror ());
|
err = gpg_err_make (default_errsource, gpg_err_code_from_syserror ());
|
||||||
my_socket_unref (cookie->sock);
|
my_socket_unref (cookie->sock);
|
||||||
xfree (cookie);
|
xfree (cookie);
|
||||||
goto leave;
|
goto leave;
|
||||||
@ -582,7 +580,7 @@ http_start_data (http_t hd)
|
|||||||
|
|
||||||
|
|
||||||
gpg_error_t
|
gpg_error_t
|
||||||
_http_wait_response (http_t hd, gpg_err_source_t errsource)
|
http_wait_response (http_t hd)
|
||||||
{
|
{
|
||||||
gpg_error_t err;
|
gpg_error_t err;
|
||||||
cookie_t cookie;
|
cookie_t cookie;
|
||||||
@ -594,7 +592,7 @@ _http_wait_response (http_t hd, gpg_err_source_t errsource)
|
|||||||
object keeps the actual system socket open. */
|
object keeps the actual system socket open. */
|
||||||
cookie = hd->write_cookie;
|
cookie = hd->write_cookie;
|
||||||
if (!cookie)
|
if (!cookie)
|
||||||
return gpg_err_make (errsource, GPG_ERR_INTERNAL);
|
return gpg_err_make (default_errsource, GPG_ERR_INTERNAL);
|
||||||
|
|
||||||
es_fclose (hd->fp_write);
|
es_fclose (hd->fp_write);
|
||||||
hd->fp_write = NULL;
|
hd->fp_write = NULL;
|
||||||
@ -611,7 +609,7 @@ _http_wait_response (http_t hd, gpg_err_source_t errsource)
|
|||||||
/* Create a new cookie and a stream for reading. */
|
/* Create a new cookie and a stream for reading. */
|
||||||
cookie = xtrycalloc (1, sizeof *cookie);
|
cookie = xtrycalloc (1, sizeof *cookie);
|
||||||
if (!cookie)
|
if (!cookie)
|
||||||
return gpg_err_make (errsource, gpg_err_code_from_syserror ());
|
return gpg_err_make (default_errsource, gpg_err_code_from_syserror ());
|
||||||
cookie->sock = my_socket_ref (hd->sock);
|
cookie->sock = my_socket_ref (hd->sock);
|
||||||
if (hd->uri->use_tls)
|
if (hd->uri->use_tls)
|
||||||
cookie->tls_session = hd->tls_context;
|
cookie->tls_session = hd->tls_context;
|
||||||
@ -620,7 +618,7 @@ _http_wait_response (http_t hd, gpg_err_source_t errsource)
|
|||||||
hd->fp_read = es_fopencookie (cookie, "r", cookie_functions);
|
hd->fp_read = es_fopencookie (cookie, "r", cookie_functions);
|
||||||
if (!hd->fp_read)
|
if (!hd->fp_read)
|
||||||
{
|
{
|
||||||
err = gpg_err_make (errsource, gpg_err_code_from_syserror ());
|
err = gpg_err_make (default_errsource, gpg_err_code_from_syserror ());
|
||||||
my_socket_unref (cookie->sock);
|
my_socket_unref (cookie->sock);
|
||||||
xfree (cookie);
|
xfree (cookie);
|
||||||
hd->read_cookie = NULL;
|
hd->read_cookie = NULL;
|
||||||
@ -641,19 +639,18 @@ _http_wait_response (http_t hd, gpg_err_source_t errsource)
|
|||||||
be used as an HTTP proxy and any enabled $http_proxy gets
|
be used as an HTTP proxy and any enabled $http_proxy gets
|
||||||
ignored. */
|
ignored. */
|
||||||
gpg_error_t
|
gpg_error_t
|
||||||
_http_open_document (http_t *r_hd, const char *document,
|
http_open_document (http_t *r_hd, const char *document,
|
||||||
const char *auth, unsigned int flags, const char *proxy,
|
const char *auth, unsigned int flags, const char *proxy,
|
||||||
void *tls_context, const char *srvtag, strlist_t headers,
|
void *tls_context, const char *srvtag, strlist_t headers)
|
||||||
gpg_err_source_t errsource)
|
|
||||||
{
|
{
|
||||||
gpg_error_t err;
|
gpg_error_t err;
|
||||||
|
|
||||||
err = _http_open (r_hd, HTTP_REQ_GET, document, auth, flags,
|
err = http_open (r_hd, HTTP_REQ_GET, document, auth, flags,
|
||||||
proxy, tls_context, srvtag, headers, errsource);
|
proxy, tls_context, srvtag, headers);
|
||||||
if (err)
|
if (err)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
err = _http_wait_response (*r_hd, errsource);
|
err = http_wait_response (*r_hd);
|
||||||
if (err)
|
if (err)
|
||||||
http_close (*r_hd, 0);
|
http_close (*r_hd, 0);
|
||||||
|
|
||||||
@ -719,14 +716,14 @@ http_get_status_code (http_t hd)
|
|||||||
* the URL in the same way it would do for an HTTP style URI.
|
* the URL in the same way it would do for an HTTP style URI.
|
||||||
*/
|
*/
|
||||||
gpg_error_t
|
gpg_error_t
|
||||||
_http_parse_uri (parsed_uri_t *ret_uri, const char *uri,
|
http_parse_uri (parsed_uri_t *ret_uri, const char *uri,
|
||||||
int no_scheme_check, gpg_err_source_t errsource)
|
int no_scheme_check)
|
||||||
{
|
{
|
||||||
gpg_err_code_t ec;
|
gpg_err_code_t ec;
|
||||||
|
|
||||||
*ret_uri = xtrycalloc (1, sizeof **ret_uri + strlen (uri));
|
*ret_uri = xtrycalloc (1, sizeof **ret_uri + strlen (uri));
|
||||||
if (!*ret_uri)
|
if (!*ret_uri)
|
||||||
return gpg_err_make (errsource, gpg_err_code_from_syserror ());
|
return gpg_err_make (default_errsource, gpg_err_code_from_syserror ());
|
||||||
strcpy ((*ret_uri)->buffer, uri);
|
strcpy ((*ret_uri)->buffer, uri);
|
||||||
ec = do_parse_uri (*ret_uri, 0, no_scheme_check);
|
ec = do_parse_uri (*ret_uri, 0, no_scheme_check);
|
||||||
if (ec)
|
if (ec)
|
||||||
@ -734,7 +731,7 @@ _http_parse_uri (parsed_uri_t *ret_uri, const char *uri,
|
|||||||
xfree (*ret_uri);
|
xfree (*ret_uri);
|
||||||
*ret_uri = NULL;
|
*ret_uri = NULL;
|
||||||
}
|
}
|
||||||
return gpg_err_make (errsource, ec);
|
return gpg_err_make (default_errsource, ec);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -1075,8 +1072,7 @@ parse_tuple (char *string)
|
|||||||
*/
|
*/
|
||||||
static gpg_error_t
|
static gpg_error_t
|
||||||
send_request (http_t hd, const char *auth,
|
send_request (http_t hd, const char *auth,
|
||||||
const char *proxy, const char *srvtag, strlist_t headers,
|
const char *proxy, const char *srvtag, strlist_t headers)
|
||||||
gpg_err_source_t errsource)
|
|
||||||
{
|
{
|
||||||
gnutls_session_t tls_session;
|
gnutls_session_t tls_session;
|
||||||
gpg_error_t err;
|
gpg_error_t err;
|
||||||
@ -1093,7 +1089,7 @@ send_request (http_t hd, const char *auth,
|
|||||||
if (hd->uri->use_tls && !tls_session)
|
if (hd->uri->use_tls && !tls_session)
|
||||||
{
|
{
|
||||||
log_error ("TLS requested but no GNUTLS context provided\n");
|
log_error ("TLS requested but no GNUTLS context provided\n");
|
||||||
return gpg_err_make (errsource, GPG_ERR_INTERNAL);
|
return gpg_err_make (default_errsource, GPG_ERR_INTERNAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
server = *hd->uri->host ? hd->uri->host : "localhost";
|
server = *hd->uri->host ? hd->uri->host : "localhost";
|
||||||
@ -1110,12 +1106,12 @@ send_request (http_t hd, const char *auth,
|
|||||||
if (proxy)
|
if (proxy)
|
||||||
http_proxy = proxy;
|
http_proxy = proxy;
|
||||||
|
|
||||||
err = _http_parse_uri (&uri, http_proxy, 0, errsource);
|
err = http_parse_uri (&uri, http_proxy, 0);
|
||||||
if (err)
|
if (err)
|
||||||
{
|
{
|
||||||
log_error ("invalid HTTP proxy (%s): %s\n",
|
log_error ("invalid HTTP proxy (%s): %s\n",
|
||||||
http_proxy, gpg_strerror (err));
|
http_proxy, gpg_strerror (err));
|
||||||
return gpg_err_make (errsource, GPG_ERR_CONFIGURATION);
|
return gpg_err_make (default_errsource, GPG_ERR_CONFIGURATION);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (uri->auth)
|
if (uri->auth)
|
||||||
@ -1126,7 +1122,8 @@ send_request (http_t hd, const char *auth,
|
|||||||
uri->auth, strlen(uri->auth));
|
uri->auth, strlen(uri->auth));
|
||||||
if (!proxy_authstr)
|
if (!proxy_authstr)
|
||||||
{
|
{
|
||||||
err = gpg_err_make (errsource, gpg_err_code_from_syserror ());
|
err = gpg_err_make (default_errsource,
|
||||||
|
gpg_err_code_from_syserror ());
|
||||||
http_release_parsed_uri (uri);
|
http_release_parsed_uri (uri);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
@ -1148,14 +1145,15 @@ send_request (http_t hd, const char *auth,
|
|||||||
if (sock == -1)
|
if (sock == -1)
|
||||||
{
|
{
|
||||||
xfree (proxy_authstr);
|
xfree (proxy_authstr);
|
||||||
return gpg_err_make (errsource, (hnf? GPG_ERR_UNKNOWN_HOST
|
return gpg_err_make (default_errsource,
|
||||||
: gpg_err_code_from_syserror ()));
|
(hnf? GPG_ERR_UNKNOWN_HOST
|
||||||
|
: gpg_err_code_from_syserror ()));
|
||||||
}
|
}
|
||||||
hd->sock = my_socket_new (sock);
|
hd->sock = my_socket_new (sock);
|
||||||
if (!hd->sock)
|
if (!hd->sock)
|
||||||
{
|
{
|
||||||
xfree (proxy_authstr);
|
xfree (proxy_authstr);
|
||||||
return gpg_err_make (errsource, gpg_err_code_from_syserror ());
|
return gpg_err_make (default_errsource, gpg_err_code_from_syserror ());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1177,7 +1175,7 @@ send_request (http_t hd, const char *auth,
|
|||||||
{
|
{
|
||||||
log_info ("TLS handshake failed: %s\n", gnutls_strerror (rc));
|
log_info ("TLS handshake failed: %s\n", gnutls_strerror (rc));
|
||||||
xfree (proxy_authstr);
|
xfree (proxy_authstr);
|
||||||
return gpg_err_make (errsource, GPG_ERR_NETWORK);
|
return gpg_err_make (default_errsource, GPG_ERR_NETWORK);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tls_callback)
|
if (tls_callback)
|
||||||
@ -1204,7 +1202,7 @@ send_request (http_t hd, const char *auth,
|
|||||||
if (!myauth)
|
if (!myauth)
|
||||||
{
|
{
|
||||||
xfree (proxy_authstr);
|
xfree (proxy_authstr);
|
||||||
return gpg_err_make (errsource, gpg_err_code_from_syserror ());
|
return gpg_err_make (default_errsource, gpg_err_code_from_syserror ());
|
||||||
}
|
}
|
||||||
remove_escapes (myauth);
|
remove_escapes (myauth);
|
||||||
}
|
}
|
||||||
@ -1222,13 +1220,14 @@ send_request (http_t hd, const char *auth,
|
|||||||
if (!authstr)
|
if (!authstr)
|
||||||
{
|
{
|
||||||
xfree (proxy_authstr);
|
xfree (proxy_authstr);
|
||||||
return gpg_err_make (errsource, gpg_err_code_from_syserror ());
|
return gpg_err_make (default_errsource,
|
||||||
|
gpg_err_code_from_syserror ());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
p = build_rel_path (hd->uri);
|
p = build_rel_path (hd->uri);
|
||||||
if (!p)
|
if (!p)
|
||||||
return gpg_err_make (errsource, gpg_err_code_from_syserror ());
|
return gpg_err_make (default_errsource, gpg_err_code_from_syserror ());
|
||||||
|
|
||||||
if (http_proxy && *http_proxy)
|
if (http_proxy && *http_proxy)
|
||||||
{
|
{
|
||||||
@ -1261,7 +1260,7 @@ send_request (http_t hd, const char *auth,
|
|||||||
xfree (p);
|
xfree (p);
|
||||||
if (!request)
|
if (!request)
|
||||||
{
|
{
|
||||||
err = gpg_err_make (errsource, gpg_err_code_from_syserror ());
|
err = gpg_err_make (default_errsource, gpg_err_code_from_syserror ());
|
||||||
xfree (authstr);
|
xfree (authstr);
|
||||||
xfree (proxy_authstr);
|
xfree (proxy_authstr);
|
||||||
return err;
|
return err;
|
||||||
@ -1276,7 +1275,7 @@ send_request (http_t hd, const char *auth,
|
|||||||
cookie = xtrycalloc (1, sizeof *cookie);
|
cookie = xtrycalloc (1, sizeof *cookie);
|
||||||
if (!cookie)
|
if (!cookie)
|
||||||
{
|
{
|
||||||
err = gpg_err_make (errsource, gpg_err_code_from_syserror ());
|
err = gpg_err_make (default_errsource, gpg_err_code_from_syserror ());
|
||||||
goto leave;
|
goto leave;
|
||||||
}
|
}
|
||||||
cookie->sock = my_socket_ref (hd->sock);
|
cookie->sock = my_socket_ref (hd->sock);
|
||||||
@ -1287,13 +1286,13 @@ send_request (http_t hd, const char *auth,
|
|||||||
hd->fp_write = es_fopencookie (cookie, "w", cookie_functions);
|
hd->fp_write = es_fopencookie (cookie, "w", cookie_functions);
|
||||||
if (!hd->fp_write)
|
if (!hd->fp_write)
|
||||||
{
|
{
|
||||||
err = gpg_err_make (errsource, gpg_err_code_from_syserror ());
|
err = gpg_err_make (default_errsource, gpg_err_code_from_syserror ());
|
||||||
my_socket_unref (cookie->sock);
|
my_socket_unref (cookie->sock);
|
||||||
xfree (cookie);
|
xfree (cookie);
|
||||||
hd->write_cookie = NULL;
|
hd->write_cookie = NULL;
|
||||||
}
|
}
|
||||||
else if (es_fputs (request, hd->fp_write) || es_fflush (hd->fp_write))
|
else if (es_fputs (request, hd->fp_write) || es_fflush (hd->fp_write))
|
||||||
err = gpg_err_make (errsource, gpg_err_code_from_syserror ());
|
err = gpg_err_make (default_errsource, gpg_err_code_from_syserror ());
|
||||||
else
|
else
|
||||||
err = 0;
|
err = 0;
|
||||||
|
|
||||||
@ -1304,7 +1303,8 @@ send_request (http_t hd, const char *auth,
|
|||||||
if ((es_fputs (headers->d, hd->fp_write) || es_fflush (hd->fp_write))
|
if ((es_fputs (headers->d, hd->fp_write) || es_fflush (hd->fp_write))
|
||||||
|| (es_fputs("\r\n",hd->fp_write) || es_fflush(hd->fp_write)))
|
|| (es_fputs("\r\n",hd->fp_write) || es_fflush(hd->fp_write)))
|
||||||
{
|
{
|
||||||
err = gpg_err_make (errsource, gpg_err_code_from_syserror ());
|
err = gpg_err_make (default_errsource,
|
||||||
|
gpg_err_code_from_syserror ());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -74,51 +74,38 @@ typedef struct http_context_s *http_t;
|
|||||||
|
|
||||||
void http_register_tls_callback (gpg_error_t (*cb) (http_t, void *, int));
|
void http_register_tls_callback (gpg_error_t (*cb) (http_t, void *, int));
|
||||||
|
|
||||||
gpg_error_t _http_parse_uri (parsed_uri_t *ret_uri, const char *uri,
|
gpg_error_t http_parse_uri (parsed_uri_t *ret_uri, const char *uri,
|
||||||
int no_scheme_check, gpg_err_source_t errsource);
|
int no_scheme_check);
|
||||||
#define http_parse_uri(a,b,c) \
|
|
||||||
_http_parse_uri ((a), (b), (c), GPG_ERR_SOURCE_DEFAULT)
|
|
||||||
|
|
||||||
void http_release_parsed_uri (parsed_uri_t uri);
|
void http_release_parsed_uri (parsed_uri_t uri);
|
||||||
|
|
||||||
gpg_error_t _http_raw_connect (http_t *r_hd,
|
gpg_error_t http_raw_connect (http_t *r_hd,
|
||||||
const char *server, unsigned short port,
|
const char *server, unsigned short port,
|
||||||
unsigned int flags, const char *srvtag,
|
unsigned int flags, const char *srvtag);
|
||||||
gpg_err_source_t errsource);
|
|
||||||
#define http_raw_connect(a,b,c,d,e) \
|
|
||||||
_http_raw_connect ((a),(b),(c),(d),(e), GPG_ERR_SOURCE_DEFAULT)
|
|
||||||
|
|
||||||
gpg_error_t _http_open (http_t *r_hd, http_req_t reqtype,
|
gpg_error_t http_open (http_t *r_hd, http_req_t reqtype,
|
||||||
const char *url,
|
const char *url,
|
||||||
const char *auth,
|
const char *auth,
|
||||||
unsigned int flags,
|
unsigned int flags,
|
||||||
const char *proxy,
|
const char *proxy,
|
||||||
void *tls_context,
|
void *tls_context,
|
||||||
const char *srvtag,
|
const char *srvtag,
|
||||||
strlist_t headers,
|
strlist_t headers);
|
||||||
gpg_err_source_t errsource);
|
|
||||||
#define http_open(a,b,c,d,e,f,g,h,i) \
|
|
||||||
_http_open ((a),(b),(c),(d),(e),(f),(g),(h),(i), GPG_ERR_SOURCE_DEFAULT)
|
|
||||||
|
|
||||||
void http_start_data (http_t hd);
|
void http_start_data (http_t hd);
|
||||||
|
|
||||||
gpg_error_t _http_wait_response (http_t hd, gpg_err_source_t errsource);
|
gpg_error_t http_wait_response (http_t hd);
|
||||||
#define http_wait_response(a) \
|
|
||||||
_http_wait_response ((a), GPG_ERR_SOURCE_DEFAULT)
|
|
||||||
|
|
||||||
void http_close (http_t hd, int keep_read_stream);
|
void http_close (http_t hd, int keep_read_stream);
|
||||||
|
|
||||||
gpg_error_t _http_open_document (http_t *r_hd,
|
gpg_error_t http_open_document (http_t *r_hd,
|
||||||
const char *document,
|
const char *document,
|
||||||
const char *auth,
|
const char *auth,
|
||||||
unsigned int flags,
|
unsigned int flags,
|
||||||
const char *proxy,
|
const char *proxy,
|
||||||
void *tls_context,
|
void *tls_context,
|
||||||
const char *srvtag,
|
const char *srvtag,
|
||||||
strlist_t headers,
|
strlist_t headers);
|
||||||
gpg_err_source_t errsource);
|
|
||||||
#define http_open_document(a,b,c,d,e,f,g,h) \
|
|
||||||
_http_open_document ((a),(b),(c),(d),(e),(f),(g),(h), GPG_ERR_SOURCE_DEFAULT)
|
|
||||||
|
|
||||||
estream_t http_get_read_ptr (http_t hd);
|
estream_t http_get_read_ptr (http_t hd);
|
||||||
estream_t http_get_write_ptr (http_t hd);
|
estream_t http_get_write_ptr (http_t hd);
|
||||||
|
@ -31,11 +31,9 @@
|
|||||||
/* Return the Secure Shell type fingerprint for KEY. The length of
|
/* Return the Secure Shell type fingerprint for KEY. The length of
|
||||||
the fingerprint is returned at R_LEN and the fingerprint itself at
|
the fingerprint is returned at R_LEN and the fingerprint itself at
|
||||||
R_FPR. In case of a error code is returned and NULL stored at
|
R_FPR. In case of a error code is returned and NULL stored at
|
||||||
R_FPR. This function is usually called via the ssh_get_fingerprint
|
R_FPR. */
|
||||||
macro which makes sure to use the correct value for ERRSOURCE. */
|
|
||||||
static gpg_error_t
|
static gpg_error_t
|
||||||
get_fingerprint (gcry_sexp_t key, void **r_fpr, size_t *r_len,
|
get_fingerprint (gcry_sexp_t key, void **r_fpr, size_t *r_len, int as_string)
|
||||||
gpg_err_source_t errsource, int as_string)
|
|
||||||
{
|
{
|
||||||
gpg_error_t err;
|
gpg_error_t err;
|
||||||
gcry_sexp_t list = NULL;
|
gcry_sexp_t list = NULL;
|
||||||
@ -59,7 +57,7 @@ get_fingerprint (gcry_sexp_t key, void **r_fpr, size_t *r_len,
|
|||||||
list = gcry_sexp_find_token (key, "shadowed-private-key", 0);
|
list = gcry_sexp_find_token (key, "shadowed-private-key", 0);
|
||||||
if (!list)
|
if (!list)
|
||||||
{
|
{
|
||||||
err = gpg_err_make (errsource, GPG_ERR_UNKNOWN_SEXP);
|
err = gpg_err_make (default_errsource, GPG_ERR_UNKNOWN_SEXP);
|
||||||
goto leave;
|
goto leave;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,7 +69,7 @@ get_fingerprint (gcry_sexp_t key, void **r_fpr, size_t *r_len,
|
|||||||
name = gcry_sexp_nth_string (list, 0);
|
name = gcry_sexp_nth_string (list, 0);
|
||||||
if (!name)
|
if (!name)
|
||||||
{
|
{
|
||||||
err = gpg_err_make (errsource, GPG_ERR_INV_SEXP);
|
err = gpg_err_make (default_errsource, GPG_ERR_INV_SEXP);
|
||||||
goto leave;
|
goto leave;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,7 +89,7 @@ get_fingerprint (gcry_sexp_t key, void **r_fpr, size_t *r_len,
|
|||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
elems = "";
|
elems = "";
|
||||||
err = gpg_err_make (errsource, GPG_ERR_PUBKEY_ALGO);
|
err = gpg_err_make (default_errsource, GPG_ERR_PUBKEY_ALGO);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (err)
|
if (err)
|
||||||
@ -106,7 +104,7 @@ get_fingerprint (gcry_sexp_t key, void **r_fpr, size_t *r_len,
|
|||||||
l2 = gcry_sexp_find_token (list, s, 1);
|
l2 = gcry_sexp_find_token (list, s, 1);
|
||||||
if (!l2)
|
if (!l2)
|
||||||
{
|
{
|
||||||
err = gpg_err_make (errsource, GPG_ERR_INV_SEXP);
|
err = gpg_err_make (default_errsource, GPG_ERR_INV_SEXP);
|
||||||
goto leave;
|
goto leave;
|
||||||
}
|
}
|
||||||
a = gcry_sexp_nth_mpi (l2, 1, GCRYMPI_FMT_USG);
|
a = gcry_sexp_nth_mpi (l2, 1, GCRYMPI_FMT_USG);
|
||||||
@ -114,7 +112,7 @@ get_fingerprint (gcry_sexp_t key, void **r_fpr, size_t *r_len,
|
|||||||
l2 = NULL;
|
l2 = NULL;
|
||||||
if (!a)
|
if (!a)
|
||||||
{
|
{
|
||||||
err = gpg_err_make (errsource, GPG_ERR_INV_SEXP);
|
err = gpg_err_make (default_errsource, GPG_ERR_INV_SEXP);
|
||||||
goto leave;
|
goto leave;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -129,7 +127,7 @@ get_fingerprint (gcry_sexp_t key, void **r_fpr, size_t *r_len,
|
|||||||
*r_fpr = gcry_malloc (as_string? 61:20);
|
*r_fpr = gcry_malloc (as_string? 61:20);
|
||||||
if (!*r_fpr)
|
if (!*r_fpr)
|
||||||
{
|
{
|
||||||
err = gpg_err_make (errsource, gpg_err_code_from_syserror ());
|
err = gpg_err_make (default_errsource, gpg_err_code_from_syserror ());
|
||||||
goto leave;
|
goto leave;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -157,31 +155,25 @@ get_fingerprint (gcry_sexp_t key, void **r_fpr, size_t *r_len,
|
|||||||
/* Return the Secure Shell type fingerprint for KEY. The length of
|
/* Return the Secure Shell type fingerprint for KEY. The length of
|
||||||
the fingerprint is returned at R_LEN and the fingerprint itself at
|
the fingerprint is returned at R_LEN and the fingerprint itself at
|
||||||
R_FPR. In case of an error an error code is returned and NULL
|
R_FPR. In case of an error an error code is returned and NULL
|
||||||
stored at R_FPR. This function is usually called via the
|
stored at R_FPR. */
|
||||||
ssh_get_fingerprint macro which makes sure to use the correct value
|
|
||||||
for ERRSOURCE. */
|
|
||||||
gpg_error_t
|
gpg_error_t
|
||||||
_ssh_get_fingerprint (gcry_sexp_t key, void **r_fpr, size_t *r_len,
|
ssh_get_fingerprint (gcry_sexp_t key, void **r_fpr, size_t *r_len)
|
||||||
gpg_err_source_t errsource)
|
|
||||||
{
|
{
|
||||||
return get_fingerprint (key, r_fpr, r_len, errsource, 0);
|
return get_fingerprint (key, r_fpr, r_len, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Return the Secure Shell type fingerprint for KEY as a string. The
|
/* Return the Secure Shell type fingerprint for KEY as a string. The
|
||||||
fingerprint is mallcoed and stored at R_FPRSTR. In case of an
|
fingerprint is mallcoed and stored at R_FPRSTR. In case of an
|
||||||
error an error code is returned and NULL stored at R_FPRSTR. This
|
error an error code is returned and NULL stored at R_FPRSTR. */
|
||||||
function is usually called via the ssh_get_fingerprint_string macro
|
|
||||||
which makes sure to use the correct value for ERRSOURCE. */
|
|
||||||
gpg_error_t
|
gpg_error_t
|
||||||
_ssh_get_fingerprint_string (gcry_sexp_t key, char **r_fprstr,
|
ssh_get_fingerprint_string (gcry_sexp_t key, char **r_fprstr)
|
||||||
gpg_err_source_t errsource)
|
|
||||||
{
|
{
|
||||||
gpg_error_t err;
|
gpg_error_t err;
|
||||||
size_t dummy;
|
size_t dummy;
|
||||||
void *string;
|
void *string;
|
||||||
|
|
||||||
err = get_fingerprint (key, &string, &dummy, errsource, 1);
|
err = get_fingerprint (key, &string, &dummy, 1);
|
||||||
*r_fprstr = string;
|
*r_fprstr = string;
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
@ -21,16 +21,9 @@
|
|||||||
#define GNUPG_COMMON_SSH_UTILS_H
|
#define GNUPG_COMMON_SSH_UTILS_H
|
||||||
|
|
||||||
|
|
||||||
gpg_error_t _ssh_get_fingerprint (gcry_sexp_t key, void **r_fpr, size_t *r_len,
|
gpg_error_t ssh_get_fingerprint (gcry_sexp_t key, void **r_fpr, size_t *r_len);
|
||||||
gpg_err_source_t errsource);
|
|
||||||
#define ssh_get_fingerprint(a,b,c) \
|
|
||||||
_ssh_get_fingerprint ((a), (b), (c), GPG_ERR_SOURCE_DEFAULT)
|
|
||||||
|
|
||||||
gpg_error_t _ssh_get_fingerprint_string (gcry_sexp_t key, char **r_fprstr,
|
|
||||||
gpg_err_source_t errsource);
|
|
||||||
#define ssh_get_fingerprint_string(a,b) \
|
|
||||||
_ssh_get_fingerprint_string ((a), (b), GPG_ERR_SOURCE_DEFAULT)
|
|
||||||
|
|
||||||
|
gpg_error_t ssh_get_fingerprint_string (gcry_sexp_t key, char **r_fprstr);
|
||||||
|
|
||||||
|
|
||||||
#endif /*GNUPG_COMMON_SSH_UTILS_H*/
|
#endif /*GNUPG_COMMON_SSH_UTILS_H*/
|
||||||
|
35
common/tlv.c
35
common/tlv.c
@ -34,6 +34,7 @@ typedef int gpg_error_t;
|
|||||||
#include <gpg-error.h>
|
#include <gpg-error.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "util.h"
|
||||||
#include "tlv.h"
|
#include "tlv.h"
|
||||||
|
|
||||||
static const unsigned char *
|
static const unsigned char *
|
||||||
@ -151,11 +152,10 @@ find_tlv_unchecked (const unsigned char *buffer, size_t length,
|
|||||||
and the length part from the TLV triplet. Update BUFFER and SIZE
|
and the length part from the TLV triplet. Update BUFFER and SIZE
|
||||||
on success. */
|
on success. */
|
||||||
gpg_error_t
|
gpg_error_t
|
||||||
_parse_ber_header (unsigned char const **buffer, size_t *size,
|
parse_ber_header (unsigned char const **buffer, size_t *size,
|
||||||
int *r_class, int *r_tag,
|
int *r_class, int *r_tag,
|
||||||
int *r_constructed, int *r_ndef,
|
int *r_constructed, int *r_ndef,
|
||||||
size_t *r_length, size_t *r_nhdr,
|
size_t *r_length, size_t *r_nhdr)
|
||||||
gpg_err_source_t errsource)
|
|
||||||
{
|
{
|
||||||
int c;
|
int c;
|
||||||
unsigned long tag;
|
unsigned long tag;
|
||||||
@ -168,7 +168,7 @@ _parse_ber_header (unsigned char const **buffer, size_t *size,
|
|||||||
|
|
||||||
/* Get the tag. */
|
/* Get the tag. */
|
||||||
if (!length)
|
if (!length)
|
||||||
return gpg_err_make (errsource, GPG_ERR_EOF);
|
return gpg_err_make (default_errsource, GPG_ERR_EOF);
|
||||||
c = *buf++; length--; ++*r_nhdr;
|
c = *buf++; length--; ++*r_nhdr;
|
||||||
|
|
||||||
*r_class = (c & 0xc0) >> 6;
|
*r_class = (c & 0xc0) >> 6;
|
||||||
@ -182,7 +182,7 @@ _parse_ber_header (unsigned char const **buffer, size_t *size,
|
|||||||
{
|
{
|
||||||
tag <<= 7;
|
tag <<= 7;
|
||||||
if (!length)
|
if (!length)
|
||||||
return gpg_err_make (errsource, GPG_ERR_EOF);
|
return gpg_err_make (default_errsource, GPG_ERR_EOF);
|
||||||
c = *buf++; length--; ++*r_nhdr;
|
c = *buf++; length--; ++*r_nhdr;
|
||||||
tag |= c & 0x7f;
|
tag |= c & 0x7f;
|
||||||
|
|
||||||
@ -193,7 +193,7 @@ _parse_ber_header (unsigned char const **buffer, size_t *size,
|
|||||||
|
|
||||||
/* Get the length. */
|
/* Get the length. */
|
||||||
if (!length)
|
if (!length)
|
||||||
return gpg_err_make (errsource, GPG_ERR_EOF);
|
return gpg_err_make (default_errsource, GPG_ERR_EOF);
|
||||||
c = *buf++; length--; ++*r_nhdr;
|
c = *buf++; length--; ++*r_nhdr;
|
||||||
|
|
||||||
if ( !(c & 0x80) )
|
if ( !(c & 0x80) )
|
||||||
@ -201,20 +201,20 @@ _parse_ber_header (unsigned char const **buffer, size_t *size,
|
|||||||
else if (c == 0x80)
|
else if (c == 0x80)
|
||||||
*r_ndef = 1;
|
*r_ndef = 1;
|
||||||
else if (c == 0xff)
|
else if (c == 0xff)
|
||||||
return gpg_err_make (errsource, GPG_ERR_BAD_BER);
|
return gpg_err_make (default_errsource, GPG_ERR_BAD_BER);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
unsigned long len = 0;
|
unsigned long len = 0;
|
||||||
int count = c & 0x7f;
|
int count = c & 0x7f;
|
||||||
|
|
||||||
if (count > sizeof (len) || count > sizeof (size_t))
|
if (count > sizeof (len) || count > sizeof (size_t))
|
||||||
return gpg_err_make (errsource, GPG_ERR_BAD_BER);
|
return gpg_err_make (default_errsource, GPG_ERR_BAD_BER);
|
||||||
|
|
||||||
for (; count; count--)
|
for (; count; count--)
|
||||||
{
|
{
|
||||||
len <<= 8;
|
len <<= 8;
|
||||||
if (!length)
|
if (!length)
|
||||||
return gpg_err_make (errsource, GPG_ERR_EOF);
|
return gpg_err_make (default_errsource, GPG_ERR_EOF);
|
||||||
c = *buf++; length--; ++*r_nhdr;
|
c = *buf++; length--; ++*r_nhdr;
|
||||||
len |= c & 0xff;
|
len |= c & 0xff;
|
||||||
}
|
}
|
||||||
@ -255,9 +255,8 @@ _parse_ber_header (unsigned char const **buffer, size_t *size,
|
|||||||
handle_error ();
|
handle_error ();
|
||||||
*/
|
*/
|
||||||
gpg_error_t
|
gpg_error_t
|
||||||
_parse_sexp (unsigned char const **buf, size_t *buflen,
|
parse_sexp (unsigned char const **buf, size_t *buflen,
|
||||||
int *depth, unsigned char const **tok, size_t *toklen,
|
int *depth, unsigned char const **tok, size_t *toklen)
|
||||||
gpg_err_source_t errsource)
|
|
||||||
{
|
{
|
||||||
const unsigned char *s;
|
const unsigned char *s;
|
||||||
size_t n, vlen;
|
size_t n, vlen;
|
||||||
@ -267,7 +266,7 @@ _parse_sexp (unsigned char const **buf, size_t *buflen,
|
|||||||
*tok = NULL;
|
*tok = NULL;
|
||||||
*toklen = 0;
|
*toklen = 0;
|
||||||
if (!n)
|
if (!n)
|
||||||
return *depth ? gpg_err_make (errsource, GPG_ERR_INV_SEXP) : 0;
|
return *depth ? gpg_err_make (default_errsource, GPG_ERR_INV_SEXP) : 0;
|
||||||
if (*s == '(')
|
if (*s == '(')
|
||||||
{
|
{
|
||||||
s++; n--;
|
s++; n--;
|
||||||
@ -279,7 +278,7 @@ _parse_sexp (unsigned char const **buf, size_t *buflen,
|
|||||||
if (*s == ')')
|
if (*s == ')')
|
||||||
{
|
{
|
||||||
if (!*depth)
|
if (!*depth)
|
||||||
return gpg_err_make (errsource, GPG_ERR_INV_SEXP);
|
return gpg_err_make (default_errsource, GPG_ERR_INV_SEXP);
|
||||||
*toklen = 1;
|
*toklen = 1;
|
||||||
s++; n--;
|
s++; n--;
|
||||||
(*depth)--;
|
(*depth)--;
|
||||||
@ -290,10 +289,10 @@ _parse_sexp (unsigned char const **buf, size_t *buflen,
|
|||||||
for (vlen=0; n && *s && *s != ':' && (*s >= '0' && *s <= '9'); s++, n--)
|
for (vlen=0; n && *s && *s != ':' && (*s >= '0' && *s <= '9'); s++, n--)
|
||||||
vlen = vlen*10 + (*s - '0');
|
vlen = vlen*10 + (*s - '0');
|
||||||
if (!n || *s != ':')
|
if (!n || *s != ':')
|
||||||
return gpg_err_make (errsource, GPG_ERR_INV_SEXP);
|
return gpg_err_make (default_errsource, GPG_ERR_INV_SEXP);
|
||||||
s++; n--;
|
s++; n--;
|
||||||
if (vlen > n)
|
if (vlen > n)
|
||||||
return gpg_err_make (errsource, GPG_ERR_INV_SEXP);
|
return gpg_err_make (default_errsource, GPG_ERR_INV_SEXP);
|
||||||
*tok = s;
|
*tok = s;
|
||||||
*toklen = vlen;
|
*toklen = vlen;
|
||||||
s += vlen;
|
s += vlen;
|
||||||
|
15
common/tlv.h
15
common/tlv.h
@ -80,14 +80,10 @@ const unsigned char *find_tlv_unchecked (const unsigned char *buffer,
|
|||||||
/* ASN.1 BER parser: Parse BUFFER of length SIZE and return the tag
|
/* ASN.1 BER parser: Parse BUFFER of length SIZE and return the tag
|
||||||
and the length part from the TLV triplet. Update BUFFER and SIZE
|
and the length part from the TLV triplet. Update BUFFER and SIZE
|
||||||
on success. */
|
on success. */
|
||||||
gpg_error_t _parse_ber_header (unsigned char const **buffer, size_t *size,
|
gpg_error_t parse_ber_header (unsigned char const **buffer, size_t *size,
|
||||||
int *r_class, int *r_tag,
|
int *r_class, int *r_tag,
|
||||||
int *r_constructed,
|
int *r_constructed,
|
||||||
int *r_ndef, size_t *r_length, size_t *r_nhdr,
|
int *r_ndef, size_t *r_length, size_t *r_nhdr);
|
||||||
gpg_err_source_t errsource);
|
|
||||||
#define parse_ber_header(a,b,c,d,e,f,g,h) \
|
|
||||||
_parse_ber_header ((a),(b),(c),(d),(e),(f),(g),(h),\
|
|
||||||
GPG_ERR_SOURCE_DEFAULT)
|
|
||||||
|
|
||||||
|
|
||||||
/* Return the next token of an canonical encoded S-expression. BUF
|
/* Return the next token of an canonical encoded S-expression. BUF
|
||||||
@ -102,11 +98,8 @@ gpg_error_t _parse_ber_header (unsigned char const **buffer, size_t *size,
|
|||||||
reflect on return the actual depth of the tree. To detect the end
|
reflect on return the actual depth of the tree. To detect the end
|
||||||
of the S-expression it is advisable to check DEPTH after a
|
of the S-expression it is advisable to check DEPTH after a
|
||||||
successful return. */
|
successful return. */
|
||||||
gpg_error_t _parse_sexp (unsigned char const **buf, size_t *buflen,
|
gpg_error_t parse_sexp (unsigned char const **buf, size_t *buflen,
|
||||||
int *depth, unsigned char const **tok, size_t *toklen,
|
int *depth, unsigned char const **tok, size_t *toklen);
|
||||||
gpg_err_source_t errsource);
|
|
||||||
#define parse_sexp(a,b,c,d,e) \
|
|
||||||
_parse_sexp ((a),(b),(c),(d),(e), GPG_ERR_SOURCE_DEFAULT)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user