-
- case SILC_COMMAND_NICK:
- {
- SilcClientEntry client = va_arg(vp, SilcClientEntry);
- char *old;
-
- if (!success)
- return;
-
- old = g_strdup(server->nick);
- server_change_nick(SERVER(server), client->nickname);
- nicklist_rename_unique(SERVER(server),
- server->conn->local_entry, server->nick,
- client, client->nickname);
-
- signal_emit("message own_nick", 4, server, server->nick, old, "");
- g_free(old);
- break;
- }
-
- case SILC_COMMAND_LIST:
- {
- char *topic, *name;
- int usercount;
- unsigned char buf[256], tmp[16];
- int i, len;
-
- if (!success)
- return;
-
- /* XXX should use irssi routines */
-
- (void)va_arg(vp, SilcChannelEntry);
- name = va_arg(vp, char *);
- topic = va_arg(vp, char *);
- usercount = va_arg(vp, int);
-
- if (status == SILC_STATUS_LIST_START ||
- status == SILC_STATUS_OK)
- silc_say(client, conn,
- " Channel Users Topic");
-
- memset(buf, 0, sizeof(buf));
- strncat(buf, " ", 2);
- len = strlen(name);
- strncat(buf, name, len > 40 ? 40 : len);
- if (len < 40)
- for (i = 0; i < 40 - len; i++)
- strcat(buf, " ");
- strcat(buf, " ");
-
- memset(tmp, 0, sizeof(tmp));
- if (usercount) {
- snprintf(tmp, sizeof(tmp), "%d", usercount);
- strcat(buf, tmp);
- }
- len = strlen(tmp);
- if (len < 10)
- for (i = 0; i < 10 - len; i++)
- strcat(buf, " ");
- strcat(buf, " ");
-
- if (topic) {
- len = strlen(topic);
- strncat(buf, topic, len);
- }
-
- silc_say(client, conn, "%s", buf);
- }
- break;
-
- case SILC_COMMAND_UMODE:
- {
- uint32 mode;
-
- if (!success)
- return;
-
- mode = va_arg(vp, uint32);
-
- /* XXX todo */
- }
- break;
-
- case SILC_COMMAND_OPER:
-#if 0
- if (status == SILC_STATUS_OK) {
- conn->local_entry->mode |= SILC_UMODE_SERVER_OPERATOR;
- if (app->screen->bottom_line->umode)
- silc_free(app->screen->bottom_line->umode);
- app->screen->bottom_line->umode = strdup("Server Operator");;
- silc_screen_print_bottom_line(app->screen, 0);
- }
-#endif
- break;
-
- case SILC_COMMAND_SILCOPER:
-#if 0
- if (status == SILC_STATUS_OK) {
- conn->local_entry->mode |= SILC_UMODE_ROUTER_OPERATOR;
- if (app->screen->bottom_line->umode)
- silc_free(app->screen->bottom_line->umode);
- app->screen->bottom_line->umode = strdup("SILC Operator");;
- silc_screen_print_bottom_line(app->screen, 0);
- }
-#endif
- break;
-
- case SILC_COMMAND_USERS:
- {
- SilcChannelEntry channel;
- SilcChannelUser chu;
- int line_len;
- char *line;
-
- if (!success)
- return;
-
- channel = va_arg(vp, SilcChannelEntry);
-
- /* There are two ways to do this, either parse the list (that
- the command_reply sends (just take it with va_arg()) or just
- traverse the channel's client list. I'll do the latter. See
- JOIN command reply for example for the list. */
-
- silc_say(client, conn, "Users on %s", channel->channel_name);
-
- line = silc_calloc(1024, sizeof(*line));
- line_len = 1024;
- silc_list_start(channel->clients);
- while ((chu = silc_list_get(channel->clients)) != SILC_LIST_END) {
- SilcClientEntry e = chu->client;
- int i, len1;
- char *m, tmp[80];
-
- memset(line, 0, line_len);
-
- if (strlen(e->nickname) + strlen(e->server) + 100 > line_len) {
- silc_free(line);
- line_len += strlen(e->nickname) + strlen(e->server) + 100;
- line = silc_calloc(line_len, sizeof(*line));
- }
-
- memset(tmp, 0, sizeof(tmp));
- m = silc_client_chumode_char(chu->mode);
-
- strncat(line, " ", 1);
- strncat(line, e->nickname, strlen(e->nickname));
- strncat(line, e->server ? "@" : "", 1);
-
- len1 = 0;
- if (e->server)
- len1 = strlen(e->server);
- strncat(line, e->server ? e->server : "", len1 > 30 ? 30 : len1);
-
- len1 = strlen(line);
- if (len1 >= 30) {
- memset(&line[29], 0, len1 - 29);
- } else {
- for (i = 0; i < 30 - len1 - 1; i++)
- strcat(line, " ");
- }
-
- if (e->mode & SILC_UMODE_GONE)
- strcat(line, " G");
- else
- strcat(line, " H");
- strcat(tmp, m ? m : "");
- strncat(line, tmp, strlen(tmp));
-
- if (strlen(tmp) < 5)
- for (i = 0; i < 5 - strlen(tmp); i++)
- strcat(line, " ");
-
- strcat(line, e->username ? e->username : "");
-
- silc_say(client, conn, "%s", line);
-
- if (m)
- silc_free(m);
- }
-
- silc_free(line);
- }
- break;
-
- case SILC_COMMAND_BAN:
- {
- SilcChannelEntry channel;
- char *ban_list;
-
- if (!success)
- return;
-
- /* XXX should use irssi routines */
-
- channel = va_arg(vp, SilcChannelEntry);
- ban_list = va_arg(vp, char *);
-
- if (ban_list)
- silc_say(client, conn, "%s ban list: %s", channel->channel_name,
- ban_list);
- else
- silc_say(client, conn, "%s ban list not set", channel->channel_name);
- }
- break;
-
- case SILC_COMMAND_GETKEY:
- {
- SilcIdType id_type;
- void *entry;
- SilcPublicKey public_key;
- unsigned char *pk;
- uint32 pk_len;
-
- id_type = va_arg(vp, uint32);
- entry = va_arg(vp, void *);
- public_key = va_arg(vp, SilcPublicKey);
-
- pk = silc_pkcs_public_key_encode(public_key, &pk_len);
-
- if (id_type == SILC_ID_CLIENT) {
- silc_verify_public_key_internal(client, conn, SILC_SOCKET_TYPE_CLIENT,
- pk, pk_len, SILC_SKE_PK_TYPE_SILC,
- NULL, NULL);
- }
-
- silc_free(pk);
- }
-
- case SILC_COMMAND_TOPIC:
- {
- SilcChannelEntry channel;
- char *topic;
-
- if (!success)
- return;
-
- channel = va_arg(vp, SilcChannelEntry);
- topic = va_arg(vp, char *);
-
- /* XXX should use irssi routines */
-
- if (topic)
- silc_say(client, conn,
- "Topic on channel %s: %s", channel->channel_name,
- topic);
- }
- break;
- }
-
- va_end(vp);
-}
-
-/* Internal routine to verify public key. If the `completion' is provided
- it will be called to indicate whether public was verified or not. */
-
-typedef struct {
- SilcClient client;
- SilcClientConnection conn;
- char *filename;
- char *entity;
- unsigned char *pk;
- uint32 pk_len;
- SilcSKEPKType pk_type;
- SilcVerifyPublicKey completion;
- void *context;
-} *PublicKeyVerify;
-
-static void verify_public_key_completion(const char *line, void *context)
-{
- PublicKeyVerify verify = (PublicKeyVerify)context;
-
- if (line[0] == 'Y' || line[0] == 'y') {
- /* Call the completion */
- if (verify->completion)
- verify->completion(TRUE, verify->context);
-
- /* Save the key for future checking */
- silc_pkcs_save_public_key_data(verify->filename, verify->pk,
- verify->pk_len, SILC_PKCS_FILE_PEM);
- } else {
- /* Call the completion */
- if (verify->completion)
- verify->completion(FALSE, verify->context);
-
- silc_say(verify->client,
- verify->conn, "Will not accept the %s key", verify->entity);
- }
-
- silc_free(verify->filename);
- silc_free(verify->entity);
- silc_free(verify);
-}
-
-static void
-silc_verify_public_key_internal(SilcClient client, SilcClientConnection conn,
- SilcSocketType conn_type, unsigned char *pk,
- uint32 pk_len, SilcSKEPKType pk_type,
- SilcVerifyPublicKey completion, void *context)
-{
- int i;
- char file[256], filename[256], *fingerprint;
- struct passwd *pw;
- struct stat st;
- char *entity = ((conn_type == SILC_SOCKET_TYPE_SERVER ||
- conn_type == SILC_SOCKET_TYPE_ROUTER) ?
- "server" : "client");
- PublicKeyVerify verify;
-
- if (pk_type != SILC_SKE_PK_TYPE_SILC) {
- silc_say(client, conn, "We don't support %s public key type %d",
- entity, pk_type);
- if (completion)
- completion(FALSE, context);
- return;
- }
-
- pw = getpwuid(getuid());
- if (!pw) {
- if (completion)
- completion(FALSE, context);
- return;
- }
-
- memset(filename, 0, sizeof(filename));
- memset(file, 0, sizeof(file));
-
- if (conn_type == SILC_SOCKET_TYPE_SERVER ||
- conn_type == SILC_SOCKET_TYPE_ROUTER) {
- snprintf(file, sizeof(file) - 1, "%skey_%s_%d.pub", entity,
- conn->sock->hostname, conn->sock->port);
- snprintf(filename, sizeof(filename) - 1, "%s/.silc/%skeys/%s",
- pw->pw_dir, entity, file);
- } else {
- /* Replace all whitespaces with `_'. */
- fingerprint = silc_hash_fingerprint(NULL, pk, pk_len);
- for (i = 0; i < strlen(fingerprint); i++)
- if (fingerprint[i] == ' ')
- fingerprint[i] = '_';
-
- snprintf(file, sizeof(file) - 1, "%skey_%s.pub", entity, fingerprint);
- snprintf(filename, sizeof(filename) - 1, "%s/.silc/%skeys/%s",
- pw->pw_dir, entity, file);
- silc_free(fingerprint);
- }
-
- /* Take fingerprint of the public key */
- fingerprint = silc_hash_fingerprint(NULL, pk, pk_len);
-
- verify = silc_calloc(1, sizeof(*verify));
- verify->client = client;
- verify->conn = conn;
- verify->filename = strdup(filename);
- verify->entity = strdup(entity);
- verify->pk = pk;
- verify->pk_len = pk_len;
- verify->pk_type = pk_type;
- verify->completion = completion;
- verify->context = context;
-
- /* Check whether this key already exists */
- if (stat(filename, &st) < 0) {
- /* Key does not exist, ask user to verify the key and save it */
-
- silc_say(client, conn, "Received %s public key", entity);
- silc_say(client, conn, "Fingerprint for the %s key is", entity);
- silc_say(client, conn, "%s", fingerprint);
-
- keyboard_entry_redirect((SIGNAL_FUNC)verify_public_key_completion,
- "Would you like to accept the key (y/n)? ", 0,
- verify);
- silc_free(fingerprint);
- return;