updates.
[silc.git] / apps / silcd / command.c
index d5fe84db3e5fbc6d819df439903eda74d36dac82..567a0f9228de8c0d11b75f8bd0bc32aeb0e4e286 100644 (file)
@@ -528,7 +528,7 @@ typedef struct {
   uint32 res_argc;
 } *SilcServerResolveContext;
 
-static char
+static bool
 silc_server_command_whois_check(SilcServerCommandContext cmd,
                                SilcClientEntry *clients,
                                uint32 clients_count)
@@ -538,6 +538,7 @@ silc_server_command_whois_check(SilcServerCommandContext cmd,
   SilcServerResolveContext resolve = NULL, r = NULL;
   uint32 resolve_count = 0;
   int i, k;
+  bool no_res = TRUE;
 
   for (i = 0; i < clients_count; i++) {
     entry = clients[i];
@@ -557,6 +558,7 @@ silc_server_command_whois_check(SilcServerCommandContext cmd,
                                  silc_server_command_destructor,
                                  silc_server_command_whois,
                                  silc_server_command_dup(cmd));
+      no_res = FALSE;
     } else {
       if (entry->data.status & SILC_IDLIST_STATUS_RESOLVING) {
        /* We've resolved this and it still is not ready.  We'll return
@@ -631,7 +633,7 @@ silc_server_command_whois_check(SilcServerCommandContext cmd,
                                          r->ident);
     silc_server_packet_send(server, r->router->connection,
                            SILC_PACKET_COMMAND, cmd->packet->flags,
-                           res_cmd->data, res_cmd->len, TRUE);
+                           res_cmd->data, res_cmd->len, FALSE);
 
     /* Reprocess this packet after received reply */
     silc_server_command_pending(server, SILC_COMMAND_WHOIS, 
@@ -647,13 +649,11 @@ silc_server_command_whois_check(SilcServerCommandContext cmd,
     silc_free(r->res_argv);
     silc_free(r->res_argv_lens);
     silc_free(r->res_argv_types);
+    no_res = FALSE;
   }
   silc_free(resolve);
 
-  if (resolve_count)
-    return FALSE;
-
-  return TRUE;
+  return no_res;
 }
 
 static void
@@ -678,6 +678,24 @@ silc_server_command_whois_send_reply(SilcServerCommandContext cmd,
     if (clients[i]->data.status & SILC_IDLIST_STATUS_REGISTERED)
       len++;
 
+  if (len == 0 && clients_count) {
+    entry = clients[0];
+    if (entry->nickname) {
+      silc_server_command_send_status_data(cmd, SILC_COMMAND_WHOIS,
+                                          SILC_STATUS_ERR_NO_SUCH_NICK,
+                                          3, entry->nickname, 
+                                          strlen(entry->nickname));
+    } else {
+      SilcBuffer idp = silc_id_payload_encode(entry->id, SILC_ID_CLIENT);
+      silc_server_command_send_status_data(cmd, SILC_COMMAND_WHOIS,
+                                          SILC_STATUS_ERR_NO_SUCH_CLIENT_ID,
+                                          2, idp->data, idp->len);
+      silc_buffer_free(idp);
+    }
+
+    return;
+  }
+
   status = SILC_STATUS_OK;
   if (len > 1)
     status = SILC_STATUS_LIST_START;
@@ -1473,7 +1491,7 @@ silc_server_command_identify_parse(SilcServerCommandContext cmd,
    then send WHOIS request to the server who owns the client. We use
    WHOIS because we want to get as much information as possible at once. */
 
-static char
+static bool
 silc_server_command_identify_check_client(SilcServerCommandContext cmd,
                                          SilcClientEntry *clients,
                                          uint32 clients_count)
@@ -1483,6 +1501,7 @@ silc_server_command_identify_check_client(SilcServerCommandContext cmd,
   SilcServerResolveContext resolve = NULL, r = NULL;
   uint32 resolve_count = 0;
   int i, k;
+  bool no_res = TRUE;
 
   for (i = 0; i < clients_count; i++) {
     entry = clients[i];
@@ -1502,6 +1521,7 @@ silc_server_command_identify_check_client(SilcServerCommandContext cmd,
                                  silc_server_command_destructor,
                                  silc_server_command_identify,
                                  silc_server_command_dup(cmd));
+      no_res = FALSE;
     } else {
       if (entry->data.status & SILC_IDLIST_STATUS_RESOLVING) {
        /* We've resolved this and it still is not ready.  We'll return
@@ -1576,7 +1596,7 @@ silc_server_command_identify_check_client(SilcServerCommandContext cmd,
                                          r->ident);
     silc_server_packet_send(server, r->router->connection,
                            SILC_PACKET_COMMAND, cmd->packet->flags,
-                           res_cmd->data, res_cmd->len, TRUE);
+                           res_cmd->data, res_cmd->len, FALSE);
 
     /* Reprocess this packet after received reply */
     silc_server_command_pending(server, SILC_COMMAND_WHOIS, 
@@ -1592,13 +1612,11 @@ silc_server_command_identify_check_client(SilcServerCommandContext cmd,
     silc_free(r->res_argv);
     silc_free(r->res_argv_lens);
     silc_free(r->res_argv_types);
+    no_res = FALSE;
   }
   silc_free(resolve);
 
-  if (resolve_count)
-    return FALSE;
-
-  return TRUE;
+  return no_res;
 }
 
 static void
@@ -1629,6 +1647,24 @@ silc_server_command_identify_send_reply(SilcServerCommandContext cmd,
       if (clients[i]->data.status & SILC_IDLIST_STATUS_REGISTERED)
        len++;
 
+    if (len == 0 && clients_count) {
+      entry = clients[0];
+      if (entry->nickname) {
+       silc_server_command_send_status_data(cmd, SILC_COMMAND_IDENTIFY,
+                                            SILC_STATUS_ERR_NO_SUCH_NICK,
+                                            3, entry->nickname, 
+                                            strlen(entry->nickname));
+      } else {
+       SilcBuffer idp = silc_id_payload_encode(entry->id, SILC_ID_CLIENT);
+       silc_server_command_send_status_data(cmd, SILC_COMMAND_IDENTIFY,
+                                            SILC_STATUS_ERR_NO_SUCH_CLIENT_ID,
+                                            2, idp->data, idp->len);
+       silc_buffer_free(idp);
+      }
+      
+      return;
+    }
+
     if (len > 1)
       status = SILC_STATUS_LIST_START;
 
@@ -1639,7 +1675,7 @@ silc_server_command_identify_send_reply(SilcServerCommandContext cmd,
        if (clients_count == 1) {
          SilcBuffer idp = silc_id_payload_encode(entry->id, SILC_ID_CLIENT);
          silc_server_command_send_status_data(cmd, SILC_COMMAND_IDENTIFY,
-                                       SILC_STATUS_ERR_NO_SUCH_CLIENT_ID,
+                                        SILC_STATUS_ERR_NO_SUCH_CLIENT_ID,
                                               2, idp->data, idp->len);
          silc_buffer_free(idp);
        }
@@ -3811,7 +3847,7 @@ SILC_SERVER_CMD_FUNC(cmode)
 
       /* Delete old cipher and allocate default one */
       silc_cipher_free(channel->channel_key);
-      if (!silc_cipher_alloc(cipher ? cipher : "aes-256-cbc"
+      if (!silc_cipher_alloc(cipher ? cipher : SILC_DEFAULT_CIPHER
                             &channel->channel_key)) {
        silc_server_command_send_status_reply(cmd, SILC_COMMAND_CMODE,
                                   SILC_STATUS_ERR_UNKNOWN_ALGORITHM);
@@ -3868,7 +3904,7 @@ SILC_SERVER_CMD_FUNC(cmode)
 
       /* Delete old hmac and allocate default one */
       silc_hmac_free(channel->hmac);
-      if (!silc_hmac_alloc(hmac ? hmac : "hmac-sha1-96", NULL, 
+      if (!silc_hmac_alloc(hmac ? hmac : SILC_DEFAULT_HMAC, NULL, 
                           &channel->hmac)) {
        silc_server_command_send_status_reply(cmd, SILC_COMMAND_CMODE,
                                       SILC_STATUS_ERR_UNKNOWN_ALGORITHM);
@@ -5114,18 +5150,24 @@ SILC_SERVER_CMD_FUNC(getkey)
     }
 
     /* The client is locally connected, just get the public key and
-       send it back. */
-    tmp = silc_pkcs_public_key_encode(client->data.public_key, &tmp_len);
-    pk = silc_buffer_alloc(4 + tmp_len);
-    silc_buffer_pull_tail(pk, SILC_BUFFER_END(pk));
-    silc_buffer_format(pk,
-                      SILC_STR_UI_SHORT(tmp_len),
-                      SILC_STR_UI_SHORT(SILC_SKE_PK_TYPE_SILC),
-                      SILC_STR_UI_XNSTRING(tmp, tmp_len),
-                      SILC_STR_END);
-    silc_free(tmp);
-    pkdata = pk->data;
-    pklen = pk->len;
+       send it back. If they key does not exist then do not send it, 
+       send just OK reply */
+    if (!client->data.public_key) {
+      pkdata = NULL;
+      pklen = 0;
+    } else {
+      tmp = silc_pkcs_public_key_encode(client->data.public_key, &tmp_len);
+      pk = silc_buffer_alloc(4 + tmp_len);
+      silc_buffer_pull_tail(pk, SILC_BUFFER_END(pk));
+      silc_buffer_format(pk,
+                        SILC_STR_UI_SHORT(tmp_len),
+                        SILC_STR_UI_SHORT(SILC_SKE_PK_TYPE_SILC),
+                        SILC_STR_UI_XNSTRING(tmp, tmp_len),
+                        SILC_STR_END);
+      silc_free(tmp);
+      pkdata = pk->data;
+      pklen = pk->len;
+    }
   } else if (id_type == SILC_ID_SERVER) {
     server_id = silc_id_payload_get_id(idp);
 
@@ -5183,7 +5225,7 @@ SILC_SERVER_CMD_FUNC(getkey)
       pk = silc_buffer_alloc(4 + tmp_len);
       silc_buffer_pull_tail(pk, SILC_BUFFER_END(pk));
       silc_buffer_format(pk,
-                      SILC_STR_UI_SHORT(tmp_len),
+                        SILC_STR_UI_SHORT(tmp_len),
                         SILC_STR_UI_SHORT(SILC_SKE_PK_TYPE_SILC),
                         SILC_STR_UI_XNSTRING(tmp, tmp_len),
                         SILC_STR_END);