Skip to content

Commit

Permalink
Unix Pageant: support -D, to delete all keys.
Browse files Browse the repository at this point in the history
  • Loading branch information
sgtatham committed May 12, 2015
1 parent e533097 commit c6c23ed
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
36 changes: 36 additions & 0 deletions pageant.c
Original file line number Diff line number Diff line change
Expand Up @@ -1747,6 +1747,42 @@ int pageant_delete_key(struct pageant_pubkey *key, char **retstr)
return ret;
}

int pageant_delete_all_keys(char **retstr)
{
unsigned char request[5], *response;
int reqlen, resplen, success, ret;
void *vresponse;

PUT_32BIT(request, 1);
request[4] = SSH2_AGENTC_REMOVE_ALL_IDENTITIES;
reqlen = 5;
ret = agent_query(request, reqlen, &vresponse, &resplen, NULL, NULL);
assert(ret == 1);
response = vresponse;
success = (resplen >= 4 && response[4] == SSH_AGENT_SUCCESS);
sfree(response);
if (!success) {
*retstr = dupstr("Agent failed to delete SSH-2 keys");
return PAGEANT_ACTION_FAILURE;
}

PUT_32BIT(request, 1);
request[4] = SSH1_AGENTC_REMOVE_ALL_RSA_IDENTITIES;
reqlen = 5;
ret = agent_query(request, reqlen, &vresponse, &resplen, NULL, NULL);
assert(ret == 1);
response = vresponse;
success = (resplen >= 4 && response[4] == SSH_AGENT_SUCCESS);
sfree(response);
if (!success) {
*retstr = dupstr("Agent failed to delete SSH-1 keys");
return PAGEANT_ACTION_FAILURE;
}

*retstr = NULL;
return PAGEANT_ACTION_OK;
}

struct pageant_pubkey *pageant_pubkey_copy(struct pageant_pubkey *key)
{
struct pageant_pubkey *ret = snew(struct pageant_pubkey);
Expand Down
1 change: 1 addition & 0 deletions pageant.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,4 @@ typedef void (*pageant_key_enum_fn_t)(void *ctx,
int pageant_enum_keys(pageant_key_enum_fn_t callback, void *callback_ctx,
char **retstr);
int pageant_delete_key(struct pageant_pubkey *key, char **retstr);
int pageant_delete_all_keys(char **retstr);
7 changes: 5 additions & 2 deletions unix/uxpgnt.c
Original file line number Diff line number Diff line change
Expand Up @@ -593,8 +593,11 @@ void run_client(void)
}
break;
case KEYACT_CLIENT_DEL_ALL:
fprintf(stderr, "NYI\n");
errors = TRUE;
if (pageant_delete_all_keys(&retstr) == PAGEANT_ACTION_FAILURE) {
fprintf(stderr, "pageant: deleting all keys: %s\n", retstr);
sfree(retstr);
errors = TRUE;
}
break;
default:
assert(0 && "Invalid client action found");
Expand Down

0 comments on commit c6c23ed

Please sign in to comment.