static gpg_error_t cmd_getinfo (assuan_context_t ctx, char *line) { int rc = 0; if (!strcmp (line, "version")) { const char *s = VERSION; rc = assuan_send_data (ctx, s, strlen (s)); } else if (!strcmp (line, "pid")) { char numbuf[50]; snprintf (numbuf, sizeof numbuf, "%lu", (unsigned long)getpid ()); rc = assuan_send_data (ctx, numbuf, strlen (numbuf)); } else if (!strcmp (line, "agent-check")) { ctrl_t ctrl = assuan_get_pointer (ctx); rc = gpgsm_agent_send_nop (ctrl); } else if (!strncmp (line, "cmd_has_option", 14) && (line[14] == ' ' || line[14] == '\t' || !line[14])) { char *cmd, *cmdopt; line += 14; while (*line == ' ' || *line == '\t') line++; if (!*line) rc = gpg_error (GPG_ERR_MISSING_VALUE); else { cmd = line; while (*line && (*line != ' ' && *line != '\t')) line++; if (!*line) rc = gpg_error (GPG_ERR_MISSING_VALUE); else { *line++ = 0; while (*line == ' ' || *line == '\t') line++; if (!*line) rc = gpg_error (GPG_ERR_MISSING_VALUE); else { cmdopt = line; if (!command_has_option (cmd, cmdopt)) rc = gpg_error (GPG_ERR_GENERAL); } } } } else rc = set_error (GPG_ERR_ASS_PARAMETER, "unknown value for WHAT"); return rc; }
/* Fork and exec the protecttool, connect the file descriptor of INFILE to stdin, return a new stream in STATUSFILE, write the output to OUTFILE and the pid of the process in PID. Returns 0 on success or an error code. */ static gpg_error_t popen_protect_tool (ctrl_t ctrl, const char *pgmname, FILE *infile, FILE *outfile, FILE **statusfile, pid_t *pid) { const char *argv[22]; int i=0; /* Make sure that the agent is running so that the protect tool is able to ask for a passphrase. This has only an effect under W32 where the agent is started on demand; sending a NOP does not harm on other platforms. This is not really necessary anymore because the protect tool does this now by itself; it does not harm either. */ gpgsm_agent_send_nop (ctrl); argv[i++] = "--homedir"; argv[i++] = opt.homedir; argv[i++] = "--p12-import"; argv[i++] = "--store"; argv[i++] = "--no-fail-on-exist"; argv[i++] = "--enable-status-msg"; if (opt.fixed_passphrase) { argv[i++] = "--passphrase"; argv[i++] = opt.fixed_passphrase; } if (opt.agent_program) { argv[i++] = "--agent-program"; argv[i++] = opt.agent_program; } argv[i++] = "--", argv[i] = NULL; assert (i < sizeof argv); return gnupg_spawn_process (pgmname, argv, infile, outfile, setup_pinentry_env, (128 | 64), statusfile, pid); }