ssh-add.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
* All rights reserved
* Adds an identity to the authentication server, or removes an identity.
*
* As far as I am concerned, the code I have written for this software
* can be used freely for any purpose. Any derived versions of this
* software must be clearly marked as such, and if the derived work is
* incompatible with the protocol description in the RFC file, it must be
* called by a name other than "ssh" or "Secure Shell".
*
* SSH2 implementation,
* Copyright (c) 2000, 2001 Markus Friedl. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "includes.h"
#pragma ident "%Z%%M% %I% %E% SMI"
#include "ssh.h"
#include "rsa.h"
#include "log.h"
#include "xmalloc.h"
#include "key.h"
#include "authfd.h"
#include "authfile.h"
#include "pathnames.h"
#include "readpass.h"
#include "misc.h"
#ifdef HAVE___PROGNAME
extern char *__progname;
#else
char *__progname;
#endif
/* argv0 */
extern char *__progname;
/* Default files to add */
static char *default_files[] = {
};
/* Default lifetime (0 == forever) */
static int lifetime = 0;
/* we keep a cache of one passphrases */
static void
clear_pass(void)
{
if (pass) {
}
}
static int
{
int ret = -1;
return -1;
}
ret = 0;
} else
filename);
return ret;
}
/* Send a request to remove all identities. */
static int
{
int ret = -1;
ret = 0;
/* ignore error-code for ssh2 */
if (ret == 0)
else
return ret;
}
static int
{
char msg[1024];
int ret = -1;
return -1;
}
/* At first, try empty passphrase */
/* try last */
/* clear passphrase since it did not work */
clear_pass();
for (;;) {
clear_pass();
return -1;
}
break;
clear_pass();
sizeof msg);
}
}
ret = 0;
if (lifetime != 0)
ret = 0;
} else {
filename);
}
return ret;
}
#ifdef SMARTCARD
static int
{
char *pin;
return -1;
return 0;
} else {
return -1;
}
}
#endif /* SMARTCARD */
static int
{
int had_identities = 0;
int version;
had_identities = 1;
if (do_fp) {
printf("%d %s %s (%s)\n",
} else {
gettext("key_write failed"));
}
}
}
if (!had_identities) {
return -1;
}
return 0;
}
static int
{
if (lock) {
passok = 0;
}
}
if (lock)
else
ret = 0;
} else {
if (lock)
else
}
return (ret);
}
static int
{
if (deleting) {
return -1;
} else {
return -1;
}
return 0;
}
static void
usage(void)
{
gettext( "Usage: %s [options]\n"
"Options:\n"
" -l List fingerprints of all identities.\n"
" -L List public key parameters of all identities.\n"
" -d Delete identity.\n"
" -D Delete all identities.\n"
" -x Lock agent.\n"
" -X Unlock agent.\n"
" -t life Set lifetime (seconds) when adding identities.\n"
#ifdef SMARTCARD
" -s reader Add key in smartcard reader.\n"
" -e reader Remove key in smartcard reader.\n"
#endif /* SMARTCARD */
), __progname);
}
int
{
extern char *optarg;
extern int optind;
#ifdef SMARTCARD
char *sc_reader_id = NULL;
#endif /* SMARTCARD */
init_rng();
seed_rng();
/* At first, get a connection to the authentication agent. */
"to your authentication agent.\n"));
exit(2);
}
switch (ch) {
case 'l':
case 'L':
ret = 1;
goto done;
break;
case 'x':
case 'X':
ret = 1;
goto done;
break;
case 'd':
deleting = 1;
break;
case 'D':
ret = 1;
goto done;
break;
#ifdef SMARTCARD
case 's':
break;
case 'e':
deleting = 1;
break;
#endif /* SMARTCARD */
case 't':
ret = 1;
goto done;
}
break;
default:
usage();
ret = 1;
goto done;
}
}
#ifdef SMARTCARD
if (sc_reader_id != NULL) {
ret = 1;
goto done;
}
#endif /* SMARTCARD */
if (argc == 0) {
char buf[MAXPATHLEN];
int count = 0;
ret = 1;
goto done;
}
for(i = 0; default_files[i]; i++) {
default_files[i]);
continue;
ret = 1;
else
count++;
}
if (count == 0)
ret = 1;
} else {
for(i = 0; i < argc; i++) {
ret = 1;
}
}
clear_pass();
done:
return ret;
}