diff options
author | Werner Koch <[email protected]> | 2020-09-01 18:43:57 +0000 |
---|---|---|
committer | Werner Koch <[email protected]> | 2020-09-01 18:43:57 +0000 |
commit | 2cd8bae23d7382588cf096df3eed83e02331a2bf (patch) | |
tree | 33d1132e0e52cd80ddfd9d9b624676cc25a8f491 /common/asshelp.c | |
parent | sm: Fix a bug in the rfc2253 parser (diff) | |
download | gnupg-2cd8bae23d7382588cf096df3eed83e02331a2bf.tar.gz gnupg-2cd8bae23d7382588cf096df3eed83e02331a2bf.zip |
Use only one copy of the warn_server_mismatch function.
* common/asshelp.c (warn_server_version_mismatch): New. Actually a
slightly modified version of warn_version_mismatch found in other
modules.
* common/status.c (gnupg_status_strings): New.
* g10/cpr.c (write_status_strings2): New.
* g10/call-agent.c (warn_version_mismatch): Use the new unified
warn_server_version_mismatch function.
* g10/call-dirmngr.c (warn_version_mismatch): Ditto.
* g10/call-keyboxd.c (warn_version_mismatch): Ditto.
* sm/call-agent.c (warn_version_mismatch): Ditto.
* sm/call-dirmngr.c (warn_version_mismatch): Ditto.
* tools/card-call-scd.c (warn_version_mismatch): Ditto.
Signed-off-by: Werner Koch <[email protected]>
Diffstat (limited to 'common/asshelp.c')
-rw-r--r-- | common/asshelp.c | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/common/asshelp.c b/common/asshelp.c index fe49aa83a..0d903fd5f 100644 --- a/common/asshelp.c +++ b/common/asshelp.c @@ -696,3 +696,57 @@ get_assuan_server_version (assuan_context_t ctx, int mode, char **r_version) } return err; } + + +/* Print a warning if the server's version number is less than our + * version number. Returns an error code on a connection problem. + * CTX is the Assuan context, SERVERNAME is the name of teh server, + * STATUS_FUNC and STATUS_FUNC_DATA is a callback to emit status + * messages. If PRINT_HINTS is set additional hints are printed. For + * MODE see get_assuan_server_version. */ +gpg_error_t +warn_server_version_mismatch (assuan_context_t ctx, + const char *servername, int mode, + gpg_error_t (*status_func)(ctrl_t ctrl, + int status_no, + ...), + void *status_func_ctrl, + int print_hints) +{ + gpg_error_t err; + char *serverversion; + const char *myversion = gpgrt_strusage (13); + + err = get_assuan_server_version (ctx, mode, &serverversion); + if (err) + log_log (gpg_err_code (err) == GPG_ERR_NOT_SUPPORTED? + GPGRT_LOGLVL_INFO : GPGRT_LOGLVL_ERROR, + _("error getting version from '%s': %s\n"), + servername, gpg_strerror (err)); + else if (compare_version_strings (serverversion, myversion) < 0) + { + char *warn; + + warn = xtryasprintf (_("server '%s' is older than us (%s < %s)"), + servername, serverversion, myversion); + if (!warn) + err = gpg_error_from_syserror (); + else + { + log_info (_("WARNING: %s\n"), warn); + if (print_hints) + { + log_info (_("Note: Outdated servers may lack important" + " security fixes.\n")); + log_info (_("Note: Use the command \"%s\" to restart them.\n"), + "gpgconf --kill all"); + } + if (status_func) + status_func (status_func_ctrl, STATUS_WARNING, + "server_version_mismatch 0", warn, NULL); + xfree (warn); + } + } + xfree (serverversion); + return err; +} |