Change interface of connect_to_agent

Add a boolean parameter to indicate whether pinentry environment
variables should be passed to the agent.

Setting this parameter to a non-zero value is equivalent to
calling the init_agent_environment function one the connection
with the agent is established.
This commit is contained in:
Damien Goutte-Gattat 2015-01-27 11:26:15 +01:00
parent 0d502338b0
commit fd83c5fa32
3 changed files with 18 additions and 18 deletions

View File

@ -104,14 +104,16 @@ get_agent_socket_name(void)
/*
* Establish a connection with a running GnuPG Agent.
*
* @param ctx A pointer to a assuan_context_t object that will be
* initialized by this function.
* @param ctx A pointer to a assuan_context_t object that will
* be initialized by this function.
* @param init_env If true, environment variables needed for pinentry
* will be passed to the agent.
*
* @return 0 if the connection was established, or a gpg_error_t
* error code.
*/
gpg_error_t
connect_to_agent(assuan_context_t *ctx)
connect_to_agent(assuan_context_t *ctx, int init_env)
{
char *socket_name;
gpg_error_t e;
@ -120,8 +122,10 @@ connect_to_agent(assuan_context_t *ctx)
return gcry_error(GPG_ERR_NO_AGENT);
if ( ! (e = assuan_new(ctx)) ) {
if ( ! (e = assuan_socket_connect(*ctx, socket_name, ASSUAN_INVALID_PID, 0)) )
e = gcry_error(GPG_ERR_NO_ERROR);
if ( ! (e = assuan_socket_connect(*ctx, socket_name, ASSUAN_INVALID_PID, 0)) ) {
if ( init_env && (e = init_agent_environment(*ctx)) )
assuan_release(*ctx);
}
else
assuan_release(*ctx);
}
@ -163,7 +167,7 @@ get_scd_socket_name(char **scd_socket_name)
assuan_context_t ctx;
gpg_error_t e;
if ( ! (e = connect_to_agent(&ctx)) ) {
if ( ! (e = connect_to_agent(&ctx, 0)) ) {
if ( ! (e = assuan_transact(ctx, "GETINFO scd_running",
NULL, NULL, NULL, NULL, NULL, NULL)) ) {

View File

@ -26,7 +26,7 @@ extern "C" {
#endif
gpg_error_t
connect_to_agent(assuan_context_t *);
connect_to_agent(assuan_context_t *, int);
gpg_error_t
connect_to_scdaemon(assuan_context_t *);

View File

@ -350,19 +350,15 @@ verify_pin(int admin)
char *line;
size_t len;
if ( ! (e = connect_to_agent(&ctx)) ) {
if ( ! (e = connect_to_agent(&ctx, 1)) ) {
if ( ! (e = init_agent_environment(ctx)) ) {
if ( ! (e = assuan_transact(ctx, "SCD GETATTR SERIALNO",
NULL, NULL, NULL, NULL, get_serial_cb, serial)) ) {
snprintf(command, sizeof(command), "SCD CHECKPIN %s%s",
serial, admin ? "[CHV3]" : "");
e = assuan_transact(ctx, command, NULL, NULL, NULL, NULL,
NULL, NULL);
}
if ( ! (e = assuan_transact(ctx, "SCD GETATTR SERIALNO",
NULL, NULL, NULL, NULL, get_serial_cb, serial)) ) {
snprintf(command, sizeof(command), "SCD CHECKPIN %s%s",
serial, admin ? "[CHV3]" : "");
e = assuan_transact(ctx, command, NULL, NULL, NULL, NULL,
NULL, NULL);
}
assuan_release(ctx);