- /*
- * Process the command line and add keys as listed on it.
- * If we already determined that we need to spawn a program from above we
- * need to ignore the first two arguments. [DBW]
- */
- {
- char *p;
- int inquotes = 0;
- p = cmdline;
- while (*p) {
- while (*p && isspace(*p))
- p++;
- if (*p && !isspace(*p)) {
- char *q = p, *pp = p;
- while (*p && (inquotes || !isspace(*p))) {
- if (*p == '"') {
- inquotes = !inquotes;
- p++;
- continue;
- }
- *pp++ = *p++;
- }
- if (*pp) {
- if (*p)
- p++;
- *pp++ = '\0';
- }
- if (!strcmp(q, "-c")) {
- /*
- * If we see `-c', then the rest of the
- * command line should be treated as a
- * command to be spawned.
- */
- while (*p && isspace(*p))
- p++;
- command = p;
- break;
- } else {
- add_keyfile(q);
- added_keys = TRUE;
- }
+ agent_query_synchronous(request, reqlen, &vresponse, &resplen);
+ response = vresponse;
+ if (resplen < 5 || response[4] != SSH_AGENT_SUCCESS) {
+ *retstr = dupstr("The already running Pageant "
+ "refused to add the key.");
+ freersakey(rkey);
+ sfree(rkey);
+ sfree(request);
+ sfree(response);
+ return PAGEANT_ACTION_FAILURE;
+ }
+ freersakey(rkey);
+ sfree(rkey);
+ sfree(request);
+ sfree(response);
+ } else {
+ if (!pageant_add_ssh1_key(rkey)) {
+ freersakey(rkey);
+ sfree(rkey); /* already present, don't waste RAM */
+ }
+ }
+ } else {
+ if (!pageant_local) {
+ unsigned char *request, *response;
+ void *vresponse;
+ int reqlen, alglen, clen, keybloblen, resplen;
+ alglen = strlen(skey->alg->name);
+ clen = strlen(skey->comment);
+
+ keybloblen = skey->alg->openssh_fmtkey(skey->data, NULL, 0);
+
+ reqlen = 4 + 1 + /* length, message type */
+ 4 + alglen + /* algorithm name */
+ keybloblen + /* key data */
+ 4 + clen /* comment */
+ ;
+
+ request = snewn(reqlen, unsigned char);
+
+ request[4] = SSH2_AGENTC_ADD_IDENTITY;
+ reqlen = 5;
+ PUT_32BIT(request + reqlen, alglen);
+ reqlen += 4;
+ memcpy(request + reqlen, skey->alg->name, alglen);
+ reqlen += alglen;
+ reqlen += skey->alg->openssh_fmtkey(skey->data,
+ request + reqlen,
+ keybloblen);
+ PUT_32BIT(request + reqlen, clen);
+ memcpy(request + reqlen + 4, skey->comment, clen);
+ reqlen += clen + 4;
+ PUT_32BIT(request, reqlen - 4);
+
+ agent_query_synchronous(request, reqlen, &vresponse, &resplen);
+ response = vresponse;
+ if (resplen < 5 || response[4] != SSH_AGENT_SUCCESS) {
+ *retstr = dupstr("The already running Pageant "
+ "refused to add the key.");
+ sfree(request);
+ sfree(response);
+ return PAGEANT_ACTION_FAILURE;
+ }
+
+ sfree(request);
+ sfree(response);
+ } else {
+ if (!pageant_add_ssh2_key(skey)) {
+ skey->alg->freekey(skey->data);
+ sfree(skey); /* already present, don't waste RAM */