mirror of
git://git.gnupg.org/gnupg.git
synced 2024-12-22 10:19:57 +01:00
Use has_leading_keyword in the assuan callbacks.
* agent/call-pinentry.c (inq_quality): Use has_leading_keyword. * agent/call-scd.c (inq_needpin, inq_writekey_parms): Ditto. * g10/call-agent.c (inq_writecert_parms, keyinfo_status_cb): Ditto. (inq_genkey_parms, inq_ciphertext_cb, inq_import_key_parms): Ditto. * g10/call-dirmngr.c (ks_put_inq_cb): Ditto. * sm/call-agent.c (default_inq_cb, inq_ciphertext_cb): Ditto. (inq_genkey_parms, istrusted_status_cb, learn_status_cb): Ditto. (keyinfo_status_cb, inq_import_key_parms): Ditto. * sm/call-dirmngr.c (inq_certificate, isvalid_status_cb): Ditto. (lookup_status_cb, run_command_inq_cb, run_command_status_cb): Ditto.
This commit is contained in:
parent
c6b8f05517
commit
585d5c62ee
@ -596,18 +596,15 @@ static gpg_error_t
|
||||
inq_quality (void *opaque, const char *line)
|
||||
{
|
||||
assuan_context_t ctx = opaque;
|
||||
const char *s;
|
||||
char *pin;
|
||||
int rc;
|
||||
int percent;
|
||||
char numbuf[20];
|
||||
|
||||
if (!strncmp (line, "QUALITY", 7) && (line[7] == ' ' || !line[7]))
|
||||
if ((s = has_leading_keyword (line, "QUALITY")))
|
||||
{
|
||||
line += 7;
|
||||
while (*line == ' ')
|
||||
line++;
|
||||
|
||||
pin = unescape_passphrase_string (line);
|
||||
pin = unescape_passphrase_string (s);
|
||||
if (!pin)
|
||||
rc = gpg_error_from_syserror ();
|
||||
else
|
||||
|
@ -701,17 +701,15 @@ static gpg_error_t
|
||||
inq_needpin (void *opaque, const char *line)
|
||||
{
|
||||
struct inq_needpin_s *parm = opaque;
|
||||
const char *s;
|
||||
char *pin;
|
||||
size_t pinlen;
|
||||
int rc;
|
||||
|
||||
parm->any_inq_seen = 1;
|
||||
if (!strncmp (line, "NEEDPIN", 7) && (line[7] == ' ' || !line[7]))
|
||||
if ((s = has_leading_keyword (line, "NEEDPIN")))
|
||||
{
|
||||
line += 7;
|
||||
while (*line == ' ')
|
||||
line++;
|
||||
|
||||
line = s;
|
||||
pinlen = 90;
|
||||
pin = gcry_malloc_secure (pinlen);
|
||||
if (!pin)
|
||||
@ -722,17 +720,11 @@ inq_needpin (void *opaque, const char *line)
|
||||
rc = assuan_send_data (parm->ctx, pin, pinlen);
|
||||
xfree (pin);
|
||||
}
|
||||
else if (!strncmp (line, "POPUPPINPADPROMPT", 17)
|
||||
&& (line[17] == ' ' || !line[17]))
|
||||
else if ((s = has_leading_keyword (line, "POPUPPINPADPROMPT")))
|
||||
{
|
||||
line += 17;
|
||||
while (*line == ' ')
|
||||
line++;
|
||||
|
||||
rc = parm->getpin_cb (parm->getpin_cb_arg, line, NULL, 1);
|
||||
rc = parm->getpin_cb (parm->getpin_cb_arg, s, NULL, 1);
|
||||
}
|
||||
else if (!strncmp (line, "DISMISSPINPADPROMPT", 19)
|
||||
&& (line[19] == ' ' || !line[19]))
|
||||
else if ((s = has_leading_keyword (line, "DISMISSPINPADPROMPT")))
|
||||
{
|
||||
rc = parm->getpin_cb (parm->getpin_cb_arg, "", NULL, 0);
|
||||
}
|
||||
@ -1069,7 +1061,7 @@ inq_writekey_parms (void *opaque, const char *line)
|
||||
{
|
||||
struct writekey_parm_s *parm = opaque;
|
||||
|
||||
if (!strncmp (line, "KEYDATA", 7) && (line[7]==' '||!line[7]))
|
||||
if (has_leading_keyword (line, "KEYDATA"))
|
||||
return assuan_send_data (parm->ctx, parm->keydata, parm->keydatalen);
|
||||
else
|
||||
return inq_needpin (opaque, line);
|
||||
|
@ -725,7 +725,7 @@ inq_writecert_parms (void *opaque, const char *line)
|
||||
int rc;
|
||||
struct writecert_parm_s *parm = opaque;
|
||||
|
||||
if (!strncmp (line, "CERTDATA", 8) && (line[8]==' '||!line[8]))
|
||||
if (has_leading_keyword (line, "CERTDATA"))
|
||||
{
|
||||
rc = assuan_send_data (parm->dflt->ctx,
|
||||
parm->certdata, parm->certdatalen);
|
||||
@ -778,7 +778,7 @@ inq_writekey_parms (void *opaque, const char *line)
|
||||
int rc;
|
||||
struct writekey_parm_s *parm = opaque;
|
||||
|
||||
if (!strncmp (line, "KEYDATA", 7) && (line[7]==' '||!line[7]))
|
||||
if (has_leading_keyword (line, "KEYDATA"))
|
||||
{
|
||||
rc = assuan_send_data (parm->dflt->ctx, parm->keydata, parm->keydatalen);
|
||||
}
|
||||
@ -1471,9 +1471,9 @@ keyinfo_status_cb (void *opaque, const char *line)
|
||||
char **serialno = opaque;
|
||||
const char *s, *s2;
|
||||
|
||||
if (!strncmp (line, "KEYINFO ", 8) && !*serialno)
|
||||
if ((s = has_leading_keyword (line, "KEYINFO ")) && !*serialno)
|
||||
{
|
||||
s = strchr (line+8, ' ');
|
||||
s = strchr (s, ' ');
|
||||
if (s && s[1] == 'T' && s[2] == ' ' && s[3])
|
||||
{
|
||||
s += 3;
|
||||
@ -1575,7 +1575,7 @@ inq_genkey_parms (void *opaque, const char *line)
|
||||
struct genkey_parm_s *parm = opaque;
|
||||
gpg_error_t err;
|
||||
|
||||
if (!strncmp (line, "KEYPARAM", 8) && (line[8]==' '||!line[8]))
|
||||
if (has_leading_keyword (line, "KEYPARAM"))
|
||||
{
|
||||
err = assuan_send_data (parm->dflt->ctx,
|
||||
parm->keyparms, strlen (parm->keyparms));
|
||||
@ -1802,7 +1802,7 @@ inq_ciphertext_cb (void *opaque, const char *line)
|
||||
struct cipher_parm_s *parm = opaque;
|
||||
int rc;
|
||||
|
||||
if (!strncmp (line, "CIPHERTEXT", 10) && (line[10]==' '||!line[10]))
|
||||
if (has_leading_keyword (line, "CIPHERTEXT"))
|
||||
{
|
||||
assuan_begin_confidential (parm->ctx);
|
||||
rc = assuan_send_data (parm->dflt->ctx,
|
||||
@ -1984,7 +1984,7 @@ inq_import_key_parms (void *opaque, const char *line)
|
||||
struct import_key_parm_s *parm = opaque;
|
||||
gpg_error_t err;
|
||||
|
||||
if (!strncmp (line, "KEYDATA", 7) && (line[7]==' '||!line[7]))
|
||||
if (has_leading_keyword (line, "KEYDATA"))
|
||||
{
|
||||
err = assuan_send_data (parm->dflt->ctx, parm->key, parm->keylen);
|
||||
}
|
||||
|
@ -515,12 +515,12 @@ ks_put_inq_cb (void *opaque, const char *line)
|
||||
struct ks_put_parm_s *parm = opaque;
|
||||
gpg_error_t err = 0;
|
||||
|
||||
if (!strncmp (line, "KEYBLOCK", 8) && (line[8] == ' ' || !line[8]))
|
||||
if (has_leading_keyword (line, "KEYBLOCK"))
|
||||
{
|
||||
if (parm->data)
|
||||
err = assuan_send_data (parm->ctx, parm->data, parm->datalen);
|
||||
}
|
||||
else if (!strncmp (line, "KEYBLOCK_INFO", 13) && (line[13]==' ' || !line[13]))
|
||||
else if (has_leading_keyword (line, "KEYBLOCK_INFO"))
|
||||
{
|
||||
kbnode_t node;
|
||||
estream_t fp;
|
||||
|
@ -138,7 +138,7 @@ default_inq_cb (void *opaque, const char *line)
|
||||
gpg_error_t err;
|
||||
ctrl_t ctrl = opaque;
|
||||
|
||||
if (!strncmp (line, "PINENTRY_LAUNCHED", 17) && (line[17]==' '||!line[17]))
|
||||
if (has_leading_keyword (line, "PINENTRY_LAUNCHED"))
|
||||
{
|
||||
err = gpgsm_proxy_pinentry_notify (ctrl, line);
|
||||
if (err)
|
||||
@ -315,7 +315,7 @@ inq_ciphertext_cb (void *opaque, const char *line)
|
||||
struct cipher_parm_s *parm = opaque;
|
||||
int rc;
|
||||
|
||||
if (!strncmp (line, "CIPHERTEXT", 10) && (line[10]==' '||!line[10]))
|
||||
if (has_leading_keyword (line, "CIPHERTEXT"))
|
||||
{
|
||||
assuan_begin_confidential (parm->ctx);
|
||||
rc = assuan_send_data (parm->ctx, parm->ciphertext, parm->ciphertextlen);
|
||||
@ -437,7 +437,7 @@ inq_genkey_parms (void *opaque, const char *line)
|
||||
struct genkey_parm_s *parm = opaque;
|
||||
int rc;
|
||||
|
||||
if (!strncmp (line, "KEYPARAM", 8) && (line[8]==' '||!line[8]))
|
||||
if (has_leading_keyword (line, "KEYPARAM"))
|
||||
{
|
||||
rc = assuan_send_data (parm->ctx, parm->sexp, parm->sexplen);
|
||||
}
|
||||
@ -693,14 +693,14 @@ static gpg_error_t
|
||||
istrusted_status_cb (void *opaque, const char *line)
|
||||
{
|
||||
struct rootca_flags_s *flags = opaque;
|
||||
const char *s;
|
||||
|
||||
if (!strncmp (line, "TRUSTLISTFLAG", 13) && (line[13]==' ' || !line[13]))
|
||||
if ((s = has_leading_keyword (line, "TRUSTLISTFLAG")))
|
||||
{
|
||||
for (line += 13; *line == ' '; line++)
|
||||
;
|
||||
if (!strncmp (line, "relax", 5) && (line[5] == ' ' || !line[5]))
|
||||
line = s;
|
||||
if (has_leading_keyword (line, "relax"))
|
||||
flags->relax = 1;
|
||||
else if (!strncmp (line, "cm", 2) && (line[2] == ' ' || !line[2]))
|
||||
else if (has_leading_keyword (line, "cm"))
|
||||
flags->chain_model = 1;
|
||||
}
|
||||
return 0;
|
||||
@ -824,14 +824,14 @@ static gpg_error_t
|
||||
learn_status_cb (void *opaque, const char *line)
|
||||
{
|
||||
struct learn_parm_s *parm = opaque;
|
||||
const char *s;
|
||||
|
||||
/* Pass progress data to the caller. */
|
||||
if (!strncmp (line, "PROGRESS", 8) && (line[8]==' ' || !line[8]))
|
||||
if ((s = has_leading_keyword (line, "PROGRESS")))
|
||||
{
|
||||
line = s;
|
||||
if (parm->ctrl)
|
||||
{
|
||||
for (line += 8; *line == ' '; line++)
|
||||
;
|
||||
if (gpgsm_status (parm->ctrl, STATUS_PROGRESS, line))
|
||||
return gpg_error (GPG_ERR_ASS_CANCELED);
|
||||
}
|
||||
@ -1017,9 +1017,9 @@ keyinfo_status_cb (void *opaque, const char *line)
|
||||
char **serialno = opaque;
|
||||
const char *s, *s2;
|
||||
|
||||
if (!strncmp (line, "KEYINFO ", 8) && !*serialno)
|
||||
if ((s = has_leading_keyword (line, "KEYINFO")) && !*serialno)
|
||||
{
|
||||
s = strchr (line+8, ' ');
|
||||
s = strchr (s, ' ');
|
||||
if (s && s[1] == 'T' && s[2] == ' ' && s[3])
|
||||
{
|
||||
s += 3;
|
||||
@ -1172,7 +1172,7 @@ inq_import_key_parms (void *opaque, const char *line)
|
||||
struct import_key_parm_s *parm = opaque;
|
||||
gpg_error_t err;
|
||||
|
||||
if (!strncmp (line, "KEYDATA", 7) && (line[7]==' '||!line[7]))
|
||||
if (has_leading_keyword (line, "KEYDATA"))
|
||||
{
|
||||
assuan_begin_confidential (parm->ctx);
|
||||
err = assuan_send_data (parm->ctx, parm->key, parm->keylen);
|
||||
|
@ -282,47 +282,40 @@ static gpg_error_t
|
||||
inq_certificate (void *opaque, const char *line)
|
||||
{
|
||||
struct inq_certificate_parm_s *parm = opaque;
|
||||
const char *s;
|
||||
int rc;
|
||||
size_t n;
|
||||
const unsigned char *der;
|
||||
size_t derlen;
|
||||
int issuer_mode = 0;
|
||||
ksba_sexp_t ski = NULL;
|
||||
|
||||
if (!strncmp (line, "SENDCERT", 8) && (line[8] == ' ' || !line[8]))
|
||||
if ((s = has_leading_keyword (line, "SENDCERT")))
|
||||
{
|
||||
line += 8;
|
||||
line = s;
|
||||
}
|
||||
else if (!strncmp (line, "SENDCERT_SKI", 12) && (line[12]==' ' || !line[12]))
|
||||
else if ((s = has_leading_keyword (line, "SENDCERT_SKI")))
|
||||
{
|
||||
size_t n;
|
||||
|
||||
/* Send a certificate where a sourceKeyIdentifier is included. */
|
||||
line += 12;
|
||||
while (*line == ' ')
|
||||
line++;
|
||||
line = s;
|
||||
ski = make_simple_sexp_from_hexstr (line, &n);
|
||||
line += n;
|
||||
while (*line == ' ')
|
||||
line++;
|
||||
}
|
||||
else if (!strncmp (line, "SENDISSUERCERT", 14)
|
||||
&& (line[14] == ' ' || !line[14]))
|
||||
else if ((s = has_leading_keyword (line, "SENDISSUERCERT")))
|
||||
{
|
||||
line += 14;
|
||||
line = s;
|
||||
issuer_mode = 1;
|
||||
}
|
||||
else if (!strncmp (line, "ISTRUSTED", 9) && (line[9]==' ' || !line[9]))
|
||||
else if ((s = has_leading_keyword (line, "ISTRUSTED")))
|
||||
{
|
||||
/* The server is asking us whether the certificate is a trusted
|
||||
root certificate. */
|
||||
const char *s;
|
||||
size_t n;
|
||||
char fpr[41];
|
||||
struct rootca_flags_s rootca_flags;
|
||||
|
||||
line += 9;
|
||||
while (*line == ' ')
|
||||
line++;
|
||||
line = s;
|
||||
|
||||
for (s=line,n=0; hexdigitp (s); s++, n++)
|
||||
;
|
||||
@ -410,22 +403,21 @@ static gpg_error_t
|
||||
isvalid_status_cb (void *opaque, const char *line)
|
||||
{
|
||||
struct isvalid_status_parm_s *parm = opaque;
|
||||
const char *s;
|
||||
|
||||
if (!strncmp (line, "PROGRESS", 8) && (line[8]==' ' || !line[8]))
|
||||
if ((s = has_leading_keyword (line, "PROGRESS")))
|
||||
{
|
||||
if (parm->ctrl)
|
||||
{
|
||||
for (line += 8; *line == ' '; line++)
|
||||
;
|
||||
line = s;
|
||||
if (gpgsm_status (parm->ctrl, STATUS_PROGRESS, line))
|
||||
return gpg_error (GPG_ERR_ASS_CANCELED);
|
||||
}
|
||||
}
|
||||
else if (!strncmp (line, "ONLY_VALID_IF_CERT_VALID", 24)
|
||||
&& (line[24]==' ' || !line[24]))
|
||||
else if ((s = has_leading_keyword (line, "ONLY_VALID_IF_CERT_VALID")))
|
||||
{
|
||||
parm->seen++;
|
||||
if (!line[24] || !unhexify_fpr (line+25, parm->fpr))
|
||||
if (!*s || !unhexify_fpr (s, parm->fpr))
|
||||
parm->seen++; /* Bumb it to indicate an error. */
|
||||
}
|
||||
return 0;
|
||||
@ -693,23 +685,22 @@ static gpg_error_t
|
||||
lookup_status_cb (void *opaque, const char *line)
|
||||
{
|
||||
struct lookup_parm_s *parm = opaque;
|
||||
const char *s;
|
||||
|
||||
if (!strncmp (line, "PROGRESS", 8) && (line[8]==' ' || !line[8]))
|
||||
if ((s = has_leading_keyword (line, "PROGRESS")))
|
||||
{
|
||||
if (parm->ctrl)
|
||||
{
|
||||
for (line += 8; *line == ' '; line++)
|
||||
;
|
||||
line = s;
|
||||
if (gpgsm_status (parm->ctrl, STATUS_PROGRESS, line))
|
||||
return gpg_error (GPG_ERR_ASS_CANCELED);
|
||||
}
|
||||
}
|
||||
else if (!strncmp (line, "TRUNCATED", 9) && (line[9]==' ' || !line[9]))
|
||||
else if ((s = has_leading_keyword (line, "TRUNCATED")))
|
||||
{
|
||||
if (parm->ctrl)
|
||||
{
|
||||
for (line +=9; *line == ' '; line++)
|
||||
;
|
||||
line = s;
|
||||
gpgsm_status (parm->ctrl, STATUS_TRUNCATED, line);
|
||||
}
|
||||
}
|
||||
@ -878,16 +869,17 @@ static gpg_error_t
|
||||
run_command_inq_cb (void *opaque, const char *line)
|
||||
{
|
||||
struct run_command_parm_s *parm = opaque;
|
||||
const char *s;
|
||||
int rc = 0;
|
||||
|
||||
if ( !strncmp (line, "SENDCERT", 8) && (line[8] == ' ' || !line[8]) )
|
||||
if ((s = has_leading_keyword (line, "SENDCERT")))
|
||||
{ /* send the given certificate */
|
||||
int err;
|
||||
ksba_cert_t cert;
|
||||
const unsigned char *der;
|
||||
size_t derlen;
|
||||
|
||||
line += 8;
|
||||
line = s;
|
||||
if (!*line)
|
||||
return gpg_error (GPG_ERR_ASS_PARAMETER);
|
||||
|
||||
@ -907,9 +899,9 @@ run_command_inq_cb (void *opaque, const char *line)
|
||||
ksba_cert_release (cert);
|
||||
}
|
||||
}
|
||||
else if ( !strncmp (line, "PRINTINFO", 9) && (line[9] == ' ' || !line[9]) )
|
||||
else if ((s = has_leading_keyword (line, "PRINTINFO")))
|
||||
{ /* Simply show the message given in the argument. */
|
||||
line += 9;
|
||||
line = s;
|
||||
log_info ("dirmngr: %s\n", line);
|
||||
}
|
||||
else
|
||||
@ -925,17 +917,17 @@ static gpg_error_t
|
||||
run_command_status_cb (void *opaque, const char *line)
|
||||
{
|
||||
ctrl_t ctrl = opaque;
|
||||
const char *s;
|
||||
|
||||
if (opt.verbose)
|
||||
{
|
||||
log_info ("dirmngr status: %s\n", line);
|
||||
}
|
||||
if (!strncmp (line, "PROGRESS", 8) && (line[8]==' ' || !line[8]))
|
||||
if ((s = has_leading_keyword (line, "PROGRESS")))
|
||||
{
|
||||
if (ctrl)
|
||||
{
|
||||
for (line += 8; *line == ' '; line++)
|
||||
;
|
||||
line = s;
|
||||
if (gpgsm_status (ctrl, STATUS_PROGRESS, line))
|
||||
return gpg_error (GPG_ERR_ASS_CANCELED);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user