{
SilcServerCommandReplyContext cmd = (SilcServerCommandReplyContext)context;
SilcServer server = cmd->server;
+ SilcIDCacheEntry cache = NULL;
SilcCommandStatus status;
SilcChannelID *id;
SilcClientID *client_id = NULL;
unsigned char *id_string;
char *channel_name, *tmp;
unsigned int mode, created;
- SilcBuffer keyp, client_id_list, client_mode_list;
+ SilcBuffer keyp = NULL, client_id_list, client_mode_list;
COMMAND_CHECK_STATUS;
/* Get channel key */
tmp = silc_argument_get_arg_type(cmd->args, 7, &len);
- if (!tmp)
- goto out;
- keyp = silc_buffer_alloc(len);
- silc_buffer_pull_tail(keyp, SILC_BUFFER_END(keyp));
- silc_buffer_put(keyp, tmp, len);
+ if (tmp) {
+ keyp = silc_buffer_alloc(len);
+ silc_buffer_pull_tail(keyp, SILC_BUFFER_END(keyp));
+ silc_buffer_put(keyp, tmp, len);
+ }
id = silc_id_payload_parse_id(id_string, id_len);
if (!id)
silc_buffer_put(client_mode_list, tmp, len);
/* See whether we already have the channel. */
- entry = silc_idlist_find_channel_by_id(server->local_list, id, NULL);
+ entry = silc_idlist_find_channel_by_name(server->local_list,
+ channel_name, &cache);
if (!entry) {
/* Add new channel */
goto out;
}
} else {
- silc_free(id);
+ /* The entry exists. */
+ if (entry->id)
+ silc_free(entry->id);
+ entry->id = id;
+ cache->id = entry->id;
+
+ /* Remove the founder auth data if the mode is not set but we have
+ them in the entry */
+ if (!(mode & SILC_CHANNEL_MODE_FOUNDER_AUTH) && entry->founder_key) {
+ silc_pkcs_public_key_free(entry->founder_key);
+ if (entry->founder_passwd) {
+ silc_free(entry->founder_passwd);
+ entry->founder_passwd = NULL;
+ }
+ }
}
if (entry->hmac_name && hmac) {
entry->mode = mode;
/* Save channel key */
- silc_server_save_channel_key(server, keyp, entry);
- silc_buffer_free(keyp);
+ if (!(entry->mode & SILC_CHANNEL_MODE_PRIVKEY)) {
+ silc_server_save_channel_key(server, keyp, entry);
+ }
+ if (keyp)
+ silc_buffer_free(keyp);
/* Save the users to the channel */
silc_server_save_users_on_channel(server, cmd->sock, entry,