[BACK]Return to ssh-add.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / ssh

Diff for /src/usr.bin/ssh/ssh-add.c between version 1.6 and 1.7

version 1.6, 1999/10/17 20:39:11 version 1.7, 1999/10/27 23:35:32
Line 22 
Line 22 
 #include "authfd.h"  #include "authfd.h"
   
 void  void
 delete_file(const char *filename)  delete_file(AuthenticationConnection *ac, const char *filename)
 {  {
   RSA *key;    RSA *key;
   char *comment;    char *comment;
   AuthenticationConnection *ac;  
   
   key = RSA_new();    key = RSA_new();
   if (!load_public_key(filename, key, &comment))    if (!load_public_key(filename, key, &comment))
Line 35 
Line 34 
       return;        return;
     }      }
   
   /* Send the request to the authentication agent. */  
   ac = ssh_get_authentication_connection();  
   if (!ac)  
     {  
       fprintf(stderr,  
               "Could not open a connection to your authentication agent.\n");  
       RSA_free(key);  
       xfree(comment);  
       return;  
     }  
   if (ssh_remove_identity(ac, key))    if (ssh_remove_identity(ac, key))
     fprintf(stderr, "Identity removed: %s (%s)\n", filename, comment);      fprintf(stderr, "Identity removed: %s (%s)\n", filename, comment);
   else    else
     fprintf(stderr, "Could not remove identity: %s\n", filename);      fprintf(stderr, "Could not remove identity: %s\n", filename);
   RSA_free(key);    RSA_free(key);
   xfree(comment);    xfree(comment);
   ssh_close_authentication_connection(ac);  
 }  }
   
 void  void
 delete_all()  delete_all(AuthenticationConnection *ac)
 {  {
   AuthenticationConnection *ac;  
   
   /* Get a connection to the agent. */  
   ac = ssh_get_authentication_connection();  
   if (!ac)  
     {  
       fprintf(stderr,  
               "Could not open a connection to your authentication agent.\n");  
       return;  
     }  
   
   /* Send a request to remove all identities. */    /* Send a request to remove all identities. */
   if (ssh_remove_all_identities(ac))    if (ssh_remove_all_identities(ac))
     fprintf(stderr, "All identities removed.\n");      fprintf(stderr, "All identities removed.\n");
   else    else
     fprintf(stderr, "Failed to remove all identitities.\n");      fprintf(stderr, "Failed to remove all identitities.\n");
   
   /* Close the connection to the agent. */  
   ssh_close_authentication_connection(ac);  
 }  }
   
 void  void
 add_file(const char *filename)  add_file(AuthenticationConnection *ac, const char *filename)
 {  {
   RSA *key;    RSA *key;
   RSA *public_key;    RSA *public_key;
   AuthenticationConnection *ac;  
   char *saved_comment, *comment, *pass;    char *saved_comment, *comment, *pass;
   int first;    int first;
   
Line 131 
Line 104 
   
   xfree(saved_comment);    xfree(saved_comment);
   
   /* Send the key to the authentication agent. */  
   ac = ssh_get_authentication_connection();  
   if (!ac)  
     {  
       fprintf(stderr,  
               "Could not open a connection to your authentication agent.\n");  
       RSA_free(key);  
       xfree(comment);  
       return;  
     }  
   if (ssh_add_identity(ac, key, comment))    if (ssh_add_identity(ac, key, comment))
     fprintf(stderr, "Identity added: %s (%s)\n", filename, comment);      fprintf(stderr, "Identity added: %s (%s)\n", filename, comment);
   else    else
     fprintf(stderr, "Could not add identity: %s\n", filename);      fprintf(stderr, "Could not add identity: %s\n", filename);
   RSA_free(key);    RSA_free(key);
   xfree(comment);    xfree(comment);
   ssh_close_authentication_connection(ac);  
 }  }
   
 void  void
 list_identities()  list_identities(AuthenticationConnection *ac)
 {  {
   AuthenticationConnection *ac;  
   BIGNUM *e, *n;    BIGNUM *e, *n;
   int bits, status;    int bits, status;
   char *comment;    char *comment;
   int had_identities;    int had_identities;
   
   ac = ssh_get_authentication_connection();  
   if (!ac)  
     {  
       fprintf(stderr, "Could not connect to authentication server.\n");  
       return;  
     }  
   e = BN_new();    e = BN_new();
   n = BN_new();    n = BN_new();
   had_identities = 0;    had_identities = 0;
Line 189 
Line 144 
   BN_clear_free(n);    BN_clear_free(n);
   if (!had_identities)    if (!had_identities)
     printf("The agent has no identities.\n");      printf("The agent has no identities.\n");
   ssh_close_authentication_connection(ac);  
 }  }
   
 int  int
 main(int ac, char **av)  main(int argc, char **argv)
 {  {
     AuthenticationConnection *ac = NULL;
   struct passwd *pw;    struct passwd *pw;
   char buf[1024];    char buf[1024];
   int no_files = 1;    int no_files = 1;
Line 211 
Line 166 
     exit(1);      exit(1);
   }    }
   
   for (i = 1; i < ac; i++)    /* At first, get a connection to the authentication agent. */
     ac = ssh_get_authentication_connection();
     if (ac == NULL) {
       fprintf(stderr, "Could not open a connection to your authentication agent.\n");
       exit(1);
     }
   
     for (i = 1; i < argc; i++)
     {      {
       if (strcmp(av[i], "-l") == 0)        if (strcmp(argv[i], "-l") == 0)
         {          {
           list_identities();            list_identities(ac);
           no_files = 0; /* Don't default-add/delete if -l. */            no_files = 0; /* Don't default-add/delete if -l. */
           continue;            continue;
         }          }
       if (strcmp(av[i], "-d") == 0)        if (strcmp(argv[i], "-d") == 0)
         {          {
           deleting = 1;            deleting = 1;
           continue;            continue;
         }          }
       if (strcmp(av[i], "-D") == 0)        if (strcmp(argv[i], "-D") == 0)
         {          {
           delete_all();            delete_all(ac);
           no_files = 0;            no_files = 0;
           continue;            continue;
         }          }
       no_files = 0;        no_files = 0;
       if (deleting)        if (deleting)
         delete_file(av[i]);          delete_file(ac, argv[i]);
       else        else
         add_file(av[i]);          add_file(ac, argv[i]);
     }      }
   if (no_files)    if (no_files)
     {      {
Line 242 
Line 204 
       if (!pw)        if (!pw)
         {          {
           fprintf(stderr, "No user found with uid %d\n", (int)getuid());            fprintf(stderr, "No user found with uid %d\n", (int)getuid());
             ssh_close_authentication_connection(ac);
           exit(1);            exit(1);
         }          }
       snprintf(buf, sizeof buf, "%s/%s", pw->pw_dir, SSH_CLIENT_IDENTITY);        snprintf(buf, sizeof buf, "%s/%s", pw->pw_dir, SSH_CLIENT_IDENTITY);
       if (deleting)        if (deleting)
         delete_file(buf);          delete_file(ac, buf);
       else        else
         add_file(buf);          add_file(ac, buf);
     }      }
     ssh_close_authentication_connection(ac);
   exit(0);    exit(0);
 }  }

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.7