Added support for saving requested attributes.
authorPekka Riikonen <priikone@silcnet.org>
Thu, 17 Oct 2002 13:43:54 +0000 (13:43 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Thu, 17 Oct 2002 13:43:54 +0000 (13:43 +0000)
CHANGES
TODO
apps/irssi/src/fe-common/silc/module-formats.c
apps/irssi/src/fe-common/silc/module-formats.h
apps/irssi/src/silc/core/client_ops.c
apps/irssi/src/silc/core/clientutil.c
apps/irssi/src/silc/core/silc-queries.c

diff --git a/CHANGES b/CHANGES
index 78a17aa7b581159362d25e76d9cbe88d9e7d8522..06f07772eb41d27e4428f5d9dd3c3c14dac07203 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,9 @@
+Thu Oct 17 16:40:39 EEST 2002  Pekka Riikonen <priikone@silcnet.org>
+
+       * Added support for saving the requested attributes in
+         WHOIS to directory.  Affected file is
+         irssi/src/silc/core/silc-queries.c.
+
 Wed Oct 16 17:40:56 EEST 2002  Pekka Riikonen <priikone@silcnet.org>
 
        * Added support for parsing VCard fields that do not have
diff --git a/TODO b/TODO
index 21087555f4effd90e49c271066d063dfb076b7bd..3d136272810916a6ea013d039ac8ddd966b9bb21 100644 (file)
--- a/TODO
+++ b/TODO
@@ -1,8 +1,6 @@
 TODO/bugs in Irssi SILC client
 ==============================
 
- o Add requested attributes public key/signature verifications.
-
  o Server password is not used at all.  It is not possible to automize
    the password authentication currently.  The silc_get_auth_method
    in irssi/src/silc/core/client_ops.c should find the connection's
index bdfcdcfc63cf0e935a92f5beb1d2a5b9caad085b..7e8a2315bea5aa2c166d1f852413aa518f7f8ae2 100644 (file)
@@ -177,6 +177,8 @@ FORMAT_REC fecommon_silc_formats[] = {
        { "attr_server_sign_verified", " Server's signature : verified successfully", 0 },
        { "attr_server_sign_failed",   " Server's signature : {hilight signature failed}", 0 },
        { "attr_extension",            " Extension          : $0", 1, { 0 } },
+       { "attr_save", "Would you like to save the attributes (y/n)?", 0 },
+       { "attr_saved", "Requested Attributes located in {hilight $0}", 1, { 0 } },
 
        { NULL, NULL, 0 }
 };
index c996e96e68999ab1d57aeb2b8bdb560964fce9d3..73d66a8e8f65e21f05f67cc317732506beb8107e 100644 (file)
@@ -91,9 +91,9 @@ enum {
   SILCTXT_PUBKEY_NO_MATCH,
   SILCTXT_PUBKEY_MAYBE_EXPIRED,
   SILCTXT_PUBKEY_MITM_ATTACK,
-  SILCTXT_GETKEY_NOKEY,
-  SILCTXT_GETKEY_VERIFIED,
-  SILCTXT_GETKEY_DISCARD,
+  SILCTXT_PUBKEY_NOKEY,
+  SILCTXT_PUBKEY_VERIFIED,
+  SILCTXT_PUBKEY_NOTVERIFIED,
 
   SILCTXT_FILL_4,
 
@@ -169,6 +169,8 @@ enum {
   SILCTXT_ATTR_SERVER_SIGN_VERIFIED,
   SILCTXT_ATTR_SERVER_SIGN_FAILED,
   SILCTXT_ATTR_EXTENSION,
+  SILCTXT_ATTR_SAVE,
+  SILCTXT_ATTR_SAVED,
 };
 
 extern FORMAT_REC fecommon_silc_formats[];
index 72014628313f596f96a0b2c262d3f384979c0036..c450af86070a08b350affacf2455fe6f2e7e19ec 100644 (file)
@@ -1044,10 +1044,11 @@ void silc_getkey_cb(bool success, void *context)
 
   if (success) {
     printformat_module("fe-common/silc", NULL, NULL,
-                      MSGLEVEL_CRAP, SILCTXT_GETKEY_VERIFIED, entity, name);
+                      MSGLEVEL_CRAP, SILCTXT_PUBKEY_VERIFIED, entity, name);
   } else {
     printformat_module("fe-common/silc", NULL, NULL,
-                      MSGLEVEL_CRAP, SILCTXT_GETKEY_DISCARD, entity, name);
+                      MSGLEVEL_CRAP, SILCTXT_PUBKEY_NOTVERIFIED,
+                      entity, name);
   }
 
   silc_free(getkey->fingerprint);
@@ -1565,7 +1566,7 @@ silc_command_reply(SilcClient client, SilcClientConnection conn,
        silc_free(pk);
       } else {
        printformat_module("fe-common/silc", server, NULL,
-                          MSGLEVEL_CRAP, SILCTXT_GETKEY_NOKEY);
+                          MSGLEVEL_CRAP, SILCTXT_PUBKEY_NOKEY);
       }
     }
     break;
index f660af3bff5bc2df25dd2ec4c3731626d8d49b78..5a0f3438375f7a564751e12359a440e38f5c47a9 100644 (file)
@@ -258,7 +258,7 @@ New pair of keys will be created.  Please, answer to following questions.\n\
 int silc_client_check_silc_dir()
 {
   char filename[256], file_public_key[256], file_private_key[256];
-  char servfilename[256], clientfilename[256];
+  char servfilename[256], clientfilename[256], friendsfilename[256];
   char *identifier;
   struct stat st;
   struct passwd *pw;
@@ -287,6 +287,8 @@ int silc_client_check_silc_dir()
           get_irssi_dir());
   snprintf(clientfilename, sizeof(clientfilename) - 1, "%s/clientkeys", 
           get_irssi_dir());
+  snprintf(friendsfilename, sizeof(friendsfilename) - 1, "%s/friends", 
+          get_irssi_dir());
 
   /*
    * Check ~/.silc directory
@@ -376,6 +378,28 @@ int silc_client_check_silc_dir()
     }
   }
   
+  /*
+   * Check ~./silc/friends directory
+   */
+  if ((stat(friendsfilename, &st)) == -1) {
+    /* If dir doesn't exist */
+    if (errno == ENOENT) {
+      if (pw->pw_uid == geteuid()) {
+       if ((mkdir(friendsfilename, 0755)) == -1) {
+         fprintf(stderr, "Couldn't create `%s' directory\n", friendsfilename);
+         return FALSE;
+       }
+      } else {
+       fprintf(stderr, "Couldn't create `%s' directory due to a wrong uid!\n",
+               friendsfilename);
+       return FALSE;
+      }
+    } else {
+      fprintf(stderr, "%s\n", strerror(errno));
+      return FALSE;
+    }
+  }
+  
   /*
    * Check Public and Private keys
    */
index a269ebf1f4a3b5e1a8d86fb1e1673188c4cd3b7b..033cb182de600881a1ece524428a08d836c28bfb 100644 (file)
@@ -33,6 +33,7 @@
 #include "fe-common/silc/module-formats.h"
 
 static void silc_query_attributes_print_final(bool success, void *context);
+static void silc_query_attributes_accept(const char *line, void *context);
 
 QUERY_REC *silc_query_create(const char *server_tag,
                             const char *nick, int automatic)
@@ -514,6 +515,7 @@ void silc_query_attributes_default(SilcClient client,
 }
 
 typedef struct {
+  SilcClient client;
   SILC_SERVER_REC *server;
   char *name;
   SilcAttributeObjPk userpk;
@@ -544,6 +546,7 @@ void silc_query_attributes_print(SILC_SERVER_REC *server,
   verify = silc_calloc(1, sizeof(*verify));
   if (!verify)
     return;
+  verify->client = client;
   verify->server = server;
   verify->name = strdup(client_entry->nickname);
 
@@ -847,21 +850,150 @@ void silc_query_attributes_print(SILC_SERVER_REC *server,
 static void silc_query_attributes_print_final(bool success, void *context)
 {
   AttrVerify verify = context;
+  SilcClient client = verify->client;
   SILC_SERVER_REC *server = verify->server;
+  char *format = NULL;
+  unsigned char filename[256], *fingerprint = NULL, *tmp;
+  struct stat st;
+  int i;
 
   if (success) {
     printformat_module("fe-common/silc", NULL, NULL,
-                      MSGLEVEL_CRAP, SILCTXT_GETKEY_VERIFIED, "user",
+                      MSGLEVEL_CRAP, SILCTXT_PUBKEY_VERIFIED, "user",
                       verify->name);
   } else {
     printformat_module("fe-common/silc", NULL, NULL,
-                      MSGLEVEL_CRAP, SILCTXT_GETKEY_DISCARD, "user",
+                      MSGLEVEL_CRAP, SILCTXT_PUBKEY_NOTVERIFIED, "user",
                       verify->name);
   }
 
   printformat_module("fe-common/silc", server, NULL,
                     MSGLEVEL_CRAP, SILCTXT_ATTR_FOOTER);
 
+  /* Replace all whitespaces with `_'. */
+  fingerprint = silc_hash_fingerprint(client->sha1hash,
+                                     verify->userpk.data,
+                                     verify->userpk.data_len);
+  for (i = 0; i < strlen(fingerprint); i++)
+    if (fingerprint[i] == ' ')
+      fingerprint[i] = '_';
+  
+  /* Filename for dir */
+  tmp = fingerprint + strlen(fingerprint) - 9;
+  snprintf(filename, sizeof(filename) - 1, "%s/friends/%s", 
+          get_irssi_dir(), tmp);
+  silc_free(fingerprint);
+
+  if ((stat(filename, &st)) == -1) {
+    /* Ask to accept save requested attributes */
+    format = format_get_text("fe-common/silc", NULL, NULL, NULL,
+                            SILCTXT_ATTR_SAVE);
+    keyboard_entry_redirect((SIGNAL_FUNC)silc_query_attributes_accept,
+                           format, 0, verify);
+  } else {
+    /* Save new data to existing directory */
+    silc_query_attributes_accept("Y", verify);
+  }
+
+  g_free(format);
+}
+
+static void silc_query_attributes_accept(const char *line, void *context)
+{
+  AttrVerify verify = context;
+  SilcClient client = verify->client;
+  SILC_SERVER_REC *server = verify->server;
+  struct stat st;
+  struct passwd *pw;
+  unsigned char filename[256], filename2[256], *fingerprint = NULL, *tmp;
+  SilcUInt32 len;
+  int i;
+
+  if (line[0] == 'Y' || line[0] == 'y') {
+    /* Save the attributes */
+    memset(filename, 0, sizeof(filename));
+    memset(filename2, 0, sizeof(filename2));
+
+    pw = getpwuid(getuid());
+    if (!pw)
+      goto out;
+
+    /* Replace all whitespaces with `_'. */
+    fingerprint = silc_hash_fingerprint(client->sha1hash,
+                                       verify->userpk.data,
+                                       verify->userpk.data_len);
+    for (i = 0; i < strlen(fingerprint); i++)
+      if (fingerprint[i] == ' ')
+       fingerprint[i] = '_';
+
+    /* Filename for dir */
+    tmp = fingerprint + strlen(fingerprint) - 9;
+    snprintf(filename, sizeof(filename) - 1, "%s/friends/%s", 
+            get_irssi_dir(), tmp);
+
+    /* Create dir if it doesn't exist */
+    if ((stat(filename, &st)) == -1) {
+      /* If dir doesn't exist */
+      if (errno == ENOENT) {
+       if (pw->pw_uid == geteuid()) {
+         if ((mkdir(filename, 0755)) == -1) {
+           silc_say_error("Couldn't create `%s' directory",
+                          filename);
+           goto out;
+         }
+       } else {
+         silc_say_error("Couldn't create `%s' directory due to a "
+                        "wrong uid!", filename);
+         goto out;
+       }
+      } else {
+       silc_say_error("%s", strerror(errno));
+       goto out;
+      }
+    }
+
+    /* Save the stuff to the directory */
+
+    /* Save VCard */
+    snprintf(filename2, sizeof(filename2) - 1, "%s/vcard", filename);
+    if (verify->vcard.full_name) {
+      tmp = silc_vcard_encode(&verify->vcard, &len);
+      silc_file_writefile(filename2, tmp, len);
+      silc_free(tmp);
+    }
+
+    /* Save public key */
+    memset(filename2, 0, sizeof(filename2));
+    snprintf(filename2, sizeof(filename2) - 1, "%s/clientkey_%s.pub",
+            filename, fingerprint);
+    silc_pkcs_save_public_key_data(filename2, verify->userpk.data,
+                                  verify->userpk.data_len,
+                                  SILC_PKCS_FILE_PEM);
+
+    /* Save extension data */
+    if (verify->extension.mime) {
+      memset(filename2, 0, sizeof(filename2));
+      snprintf(filename2, sizeof(filename2) - 1, "%s/extension.mime",
+              filename);
+      silc_file_writefile(filename2, verify->extension.mime,
+                         verify->extension.mime_len);
+    }
+
+    /* Save MIME message data */
+    if (verify->extension.mime) {
+      memset(filename2, 0, sizeof(filename2));
+      snprintf(filename2, sizeof(filename2) - 1, "%s/status_message.mime",
+              filename);
+      silc_file_writefile(filename2, verify->message.mime,
+                         verify->message.mime_len);
+    }
+
+    printformat_module("fe-common/silc", server, NULL,
+                      MSGLEVEL_CRAP, SILCTXT_ATTR_SAVED, filename);
+  }
+
+ out:
+  silc_free(fingerprint);
   silc_free(verify->name);
   silc_vcard_free(&verify->vcard);
   silc_free(verify);