char info_string[256];
memset(info_string, 0, sizeof(info_string));
- snprintf(info_string, sizeof(info_string),
- "location: %s server: %s admin: %s <%s>",
- server->config->server_info->location,
- server->config->server_info->server_type,
- server->config->server_info->admin,
- server->config->server_info->email);
+ silc_snprintf(info_string, sizeof(info_string),
+ "location: %s server: %s admin: %s <%s> version: %s",
+ server->config->server_info->location,
+ server->config->server_info->server_type,
+ server->config->server_info->admin,
+ server->config->server_info->email,
+ silc_dist_version);
server_info = info_string;
entry = server->id_entry;
SilcServer server = cmd->server;
SilcClientEntry client = silc_packet_get_context(cmd->sock);
unsigned char *tmp_mask, m[4];
- SilcUInt32 mask = 0;
+ SilcUInt32 mask = 0, tmp_len;
SilcUInt16 ident = silc_command_get_ident(cmd->payload);
SilcBool set_mask = FALSE;
SILC_SERVER_COMMAND_CHECK(SILC_COMMAND_UMODE, cmd, 1, 2);
/* Get the client's mode mask */
- tmp_mask = silc_argument_get_arg_type(cmd->args, 2, NULL);
- if (tmp_mask) {
+ tmp_mask = silc_argument_get_arg_type(cmd->args, 2, &tmp_len);
+ if (tmp_mask && tmp_len == 4) {
SILC_GET32_MSB(mask, tmp_mask);
set_mask = TRUE;
}
/* Get the channel mode mask */
tmp_mask = silc_argument_get_arg_type(cmd->args, 2, &tmp_len);
- if (tmp_mask) {
+ if (tmp_mask && tmp_len == 4) {
SILC_GET32_MSB(mode_mask, tmp_mask);
set_mask = TRUE;
}
if (server->router_conn && server->router_conn->sock == stream &&
!server->router && server->standalone) {
+ if (idata->sconn && idata->sconn->callback)
+ (*idata->sconn->callback)(server, NULL, idata->sconn->callback_context);
silc_server_create_connections(server);
silc_server_free_sock_user_data(server, stream, NULL);
} else {
server->backup_closed = TRUE;
}
+ if (idata->sconn && idata->sconn->callback)
+ (*idata->sconn->callback)(server, NULL, idata->sconn->callback_context);
silc_server_free_sock_user_data(server, stream, NULL);
}
server->backup_closed = TRUE;
}
+ if (idata->sconn && idata->sconn->callback)
+ (*idata->sconn->callback)(server, NULL, idata->sconn->callback_context);
silc_server_free_sock_user_data(server, stream, NULL);
}
sconn->no_conf = dynamic;
sconn->server = server;
- SILC_LOG_DEBUG(("Created connection %p", sconn));
+ SILC_LOG_DEBUG(("Created connection %p to %s:%d", sconn,
+ remote_host, port));
silc_schedule_task_add_timeout(server->schedule, silc_server_connect_router,
sconn, 0, 0);
if (success == FALSE) {
/* Authentication failed */
- /* XXX retry connecting */
+
+ /* Try reconnecting if configuration wants it */
+ if (!sconn->no_reconnect) {
+ silc_schedule_task_add_timeout(server->schedule,
+ silc_server_connect_to_router_retry,
+ sconn, 1, 0);
+ silc_dlist_del(server->conns, sconn);
+ return;
+ }
if (sconn->callback)
(*sconn->callback)(server, NULL, sconn->callback_context);
SILC_ID_SERVER),
NULL, sconn->sock);
if (!id_entry) {
+ /* Try reconnecting if configuration wants it */
+ if (!sconn->no_reconnect) {
+ silc_schedule_task_add_timeout(server->schedule,
+ silc_server_connect_to_router_retry,
+ sconn, 1, 0);
+ silc_dlist_del(server->conns, sconn);
+ return;
+ }
+
if (sconn->callback)
(*sconn->callback)(server, NULL, sconn->callback_context);
silc_server_free_sock_user_data(server, sconn->sock, NULL);
idata->status |= (SILC_IDLIST_STATUS_REGISTERED |
SILC_IDLIST_STATUS_LOCAL);
idata->sconn = sconn;
+ idata->sconn->callback = NULL;
/* Statistics */
server->stat.my_routers++;
silc_server_backup_add(server, server->id_entry, ip,
sconn->remote_port, TRUE);
}
+ }
#if 0
- } else {
+ else {
/* We already have primary router. Disconnect this connection */
SILC_LOG_DEBUG(("We already have primary router, disconnect"));
silc_idlist_del_server(server->global_list, id_entry);
silc_server_disconnect_remote(server, sconn->sock,
SILC_STATUS_ERR_RESOURCE_LIMIT, NULL);
return;
-#endif /* 0 */
}
+#endif /* 0 */
} else {
/* Add this server to be our backup router */
id_entry->server_type = SILC_BACKUP_ROUTER;
{
SilcPacketStream sock = context;
SilcUnknownEntry entry = silc_packet_get_context(sock);
- SilcServerConnection sconn = entry->data.sconn;
- SilcServer server = entry->server;
- SilcServerConfigRouter *conn = sconn->conn.ref_ptr;
+ SilcServerConnection sconn;
+ SilcServer server;
+ SilcServerConfigRouter *conn;
SilcAuthMethod auth_meth = SILC_AUTH_NONE;
void *auth_data = NULL;
SilcUInt32 auth_data_len = 0;
SilcHmac hmac_send, hmac_receive;
SilcHash hash;
- SILC_LOG_DEBUG(("Connection %p, SKE completed, entry %p", sconn, entry));
-
+ server = entry->server;
+ sconn = entry->data.sconn;
+ conn = sconn->conn.ref_ptr;
entry->op = NULL;
+ SILC_LOG_DEBUG(("Connection %p, SKE completed, entry %p", sconn, entry));
+
if (status != SILC_SKE_STATUS_OK) {
/* SKE failed */
SILC_LOG_ERROR(("Error (%s) during Key Exchange protocol with %s (%s)",
silc_ske_map_status(status), entry->hostname, entry->ip));
-
- /* XXX retry connecting */
silc_ske_free(ske);
+
+ /* Try reconnecting if configuration wants it */
+ if (!sconn->no_reconnect) {
+ silc_schedule_task_add_timeout(server->schedule,
+ silc_server_connect_to_router_retry,
+ sconn, 1, 0);
+ silc_dlist_del(server->conns, sconn);
+ return;
+ }
+
if (sconn->callback)
(*sconn->callback)(server, NULL, sconn->callback_context);
silc_server_free_sock_user_data(server, sconn->sock, NULL);
/* Set the keys into use. The data will be encrypted after this. */
if (!silc_ske_set_keys(ske, keymat, prop, &send_key, &receive_key,
&hmac_send, &hmac_receive, &hash)) {
+ silc_ske_free(ske);
- /* XXX retry connecting */
+ /* Try reconnecting if configuration wants it */
+ if (!sconn->no_reconnect) {
+ silc_schedule_task_add_timeout(server->schedule,
+ silc_server_connect_to_router_retry,
+ sconn, 1, 0);
+ silc_dlist_del(server->conns, sconn);
+ return;
+ }
/* Error setting keys */
- silc_ske_free(ske);
if (sconn->callback)
(*sconn->callback)(server, NULL, sconn->callback_context);
silc_server_free_sock_user_data(server, sconn->sock, NULL);
connauth = silc_connauth_alloc(server->schedule, ske,
server->config->conn_auth_timeout);
if (!connauth) {
- /* XXX retry connecting */
+ silc_ske_free(ske);
+
+ /* Try reconnecting if configuration wants it */
+ if (!sconn->no_reconnect) {
+ silc_schedule_task_add_timeout(server->schedule,
+ silc_server_connect_to_router_retry,
+ sconn, 1, 0);
+ silc_dlist_del(server->conns, sconn);
+ return;
+ }
/** Error allocating auth protocol */
- silc_ske_free(ske);
if (sconn->callback)
(*sconn->callback)(server, NULL, sconn->callback_context);
silc_server_free_sock_user_data(server, sconn->sock, NULL);
if (!sconn->sock) {
SILC_LOG_ERROR(("Cannot connect: cannot create packet stream"));
silc_stream_destroy(sconn->stream);
+
+ /* Try reconnecting if configuration wants it */
+ if (!sconn->no_reconnect) {
+ silc_schedule_task_add_timeout(server->schedule,
+ silc_server_connect_to_router_retry,
+ sconn, 1, 0);
+ silc_dlist_del(server->conns, sconn);
+ return;
+ }
+
if (sconn->callback)
(*sconn->callback)(server, NULL, sconn->callback_context);
silc_server_connection_free(sconn);
/* Set source ID to packet stream */
if (!silc_packet_set_ids(sconn->sock, SILC_ID_SERVER, server->id,
0, NULL)) {
+ silc_packet_stream_destroy(sconn->sock);
+
+ /* Try reconnecting if configuration wants it */
+ if (!sconn->no_reconnect) {
+ silc_schedule_task_add_timeout(server->schedule,
+ silc_server_connect_to_router_retry,
+ sconn, 1, 0);
+ silc_dlist_del(server->conns, sconn);
+ return;
+ }
+
if (sconn->callback)
(*sconn->callback)(server, NULL, sconn->callback_context);
- silc_packet_stream_destroy(sconn->sock);
silc_server_connection_free(sconn);
return;
}
entry = silc_calloc(1, sizeof(*entry));
if (!entry) {
silc_packet_stream_destroy(sconn->sock);
+
+ /* Try reconnecting if configuration wants it */
+ if (!sconn->no_reconnect) {
+ silc_schedule_task_add_timeout(server->schedule,
+ silc_server_connect_to_router_retry,
+ sconn, 1, 0);
+ silc_dlist_del(server->conns, sconn);
+ return;
+ }
+
+ if (sconn->callback)
+ (*sconn->callback)(server, NULL, sconn->callback_context);
silc_server_connection_free(sconn);
return;
}
server->public_key, server->private_key, sconn);
if (!ske) {
silc_free(entry);
+ silc_packet_stream_destroy(sconn->sock);
+
+ /* Try reconnecting if configuration wants it */
+ if (!sconn->no_reconnect) {
+ silc_schedule_task_add_timeout(server->schedule,
+ silc_server_connect_to_router_retry,
+ sconn, 1, 0);
+ silc_dlist_del(server->conns, sconn);
+ return;
+ }
+
if (sconn->callback)
(*sconn->callback)(server, NULL, sconn->callback_context);
- silc_packet_stream_destroy(sconn->sock);
silc_server_connection_free(sconn);
return;
}
/* If we've reached max retry count, give up. */
if ((sconn->retry_count > param->reconnect_count) &&
- !param->reconnect_keep_trying) {
+ sconn->no_reconnect) {
SILC_LOG_ERROR(("Could not connect, giving up"));
if (sconn->callback)
SILC_LOG_ERROR(("Could not connect to %s:%d: %s",
sconn->remote_host, sconn->remote_port,
silc_net_get_error_string(status)));
-
- if (sconn->callback)
- (*sconn->callback)(server, NULL, sconn->callback_context);
- silc_server_connection_free(sconn);
+ if (!sconn->no_reconnect) {
+ silc_schedule_task_add_timeout(sconn->server->schedule,
+ silc_server_connect_to_router_retry,
+ sconn, 1, 0);
+ silc_dlist_del(server->conns, sconn);
+ } else {
+ if (sconn->callback)
+ (*sconn->callback)(server, NULL, sconn->callback_context);
+ silc_server_connection_free(sconn);
+ }
break;
default:
SILC_LOG_INFO(("Unconfigured %s connection %s:%d, cannot connect",
(sconn->backup ? "backup router" : "router"),
sconn->remote_host, sconn->remote_port));
+ if (sconn->callback)
+ (*sconn->callback)(server, NULL, sconn->callback_context);
silc_server_connection_free(sconn);
return;
}
if (!sconn->op) {
SILC_LOG_ERROR(("Could not connect to router %s:%d",
sconn->remote_host, sconn->remote_port));
+ if (sconn->callback)
+ (*sconn->callback)(server, NULL, sconn->callback_context);
silc_server_connection_free(sconn);
return;
}
SilcServer server = context;
SilcServerConnection sconn;
SilcServerConfigRouter *ptr;
+ SilcServerConfigConnParams *param;
/* Don't connect if we are shutting down. */
if (server->server_shutdown)
}
}
+ param = (ptr->param ? ptr->param : &server->config->param);
+
/* Allocate connection object for hold connection specific stuff. */
sconn = silc_calloc(1, sizeof(*sconn));
if (!sconn)
sconn->backup_replace_ip = strdup(ptr->backup_replace_ip);
sconn->backup_replace_port = ptr->backup_replace_port;
}
+ sconn->no_reconnect = param->reconnect_keep_trying == FALSE;
SILC_LOG_DEBUG(("Created connection %p", sconn));
sconn->remote_port = port;
silc_dlist_add(server->conns, sconn);
idata->sconn = sconn;
+ idata->sconn->callback = NULL;
idata->last_receive = time(NULL);
/* Add the common data structure to the ID entry. */
entry->port = port;
entry->server = server;
entry->data.conn_type = SILC_CONN_UNKNOWN;
+ entry->data.status |= SILC_IDLIST_STATUS_LOCAL;
silc_packet_set_context(packet_stream, entry);
SILC_LOG_DEBUG(("Created unknown connection %p", entry));
/* We'll need to constantly try to reconnect to the primary
router so that we'll see when it comes back online. */
- silc_server_create_connection(server, FALSE, FALSE, ip, port,
+ silc_server_create_connection(server, TRUE, FALSE, ip, port,
silc_server_backup_connected,
NULL);
}
SilcServer server = app_context;
SilcServerConfigRouter *primary;
+ SILC_LOG_DEBUG(("Reconnecting"));
+
+ if (server->server_shutdown)
+ return;
+
primary = silc_server_config_get_primary_router(server);
if (primary) {
if (!silc_server_find_socket_by_host(server, SILC_CONN_ROUTER,
primary->host, primary->port))
- silc_server_create_connection(server, FALSE, FALSE,
+ silc_server_create_connection(server, TRUE, FALSE,
primary->host, primary->port,
silc_server_backup_connected,
context);
if (!server_entry) {
/* Try again */
+ SILC_LOG_DEBUG(("Connecting failed"));
silc_schedule_task_add_timeout(server->schedule,
silc_server_backup_connected_again,
context, 5, 0);
if (primary) {
if (!silc_server_find_socket_by_host(server, SILC_CONN_ROUTER,
primary->host, primary->port))
- silc_server_create_connection(server, FALSE, FALSE,
+ silc_server_create_connection(server, TRUE, FALSE,
primary->host, primary->port,
silc_server_backup_connect_primary,
context);
SILC_LOG_DEBUG(("Received START (session %d), reconnect to router",
ctx->session));
silc_packet_stream_ref(ctx->sock);
- silc_server_create_connection(server, FALSE, FALSE,
+ silc_server_create_connection(server, TRUE, FALSE,
primary->host, primary->port,
silc_server_backup_connect_primary,
ctx->sock);
silc_file_writefile(pidfile, buf, strlen(buf));
}
- silc_server_drop_privs(silcd);
}
+ silc_server_drop_privs(silcd);
/* Run the server. When this returns the server has been stopped
and we will exit. */
#
# Primary listener. Specify the IP address and the port to bind
- # the server.
+ # the server. The public_ip can be used to specify the public IP
+ # if the server is behind NAT.
#
Primary {
ip = "10.2.1.6";
+ # public_ip = "11.1.1.1";
port = 706;
};
asn1->stack2 = silc_stack_alloc(768);
if (!asn1->stack2) {
- silc_stack_free(asn1->stack2);
+ silc_stack_free(asn1->stack1);
return FALSE;
}
/* Get OID words from the string */
cp = strchr(oidstr, '.');
while (cp) {
- if (sscanf(oidstr, "%lu", (unsigned long *)&oid) != 1) {
+ if (sscanf(oidstr, "%u", &oid) != 1) {
SILC_LOG_DEBUG(("Malformed OID string"));
goto fail;
}
cp = strchr(oidstr, '.');
if (!cp) {
- if (sscanf(oidstr, "%lu", (unsigned long *)&oid) != 1) {
+ if (sscanf(oidstr, "%u", &oid) != 1) {
SILC_LOG_DEBUG(("Malformed OID string"));
goto fail;
}
SilcUInt32 key_len; /* Key data length */
SilcClientKeyAgreement ke; /* Current key agreement context or NULL */
+ SilcAtomic32 refcnt; /* Reference counter */
+ SilcAtomic32 deleted; /* Flag indicating whether the client object is
+ already scheduled for deletion */
+ SilcUInt16 resolve_cmd_ident; /* Command identifier when resolving */
+
/* Flags */
unsigned int valid : 1; /* FALSE if this entry is not valid. Entry
without nickname is not valid. */
unsigned int generated : 1; /* TRUE if library generated `key' */
unsigned int prv_resp : 1; /* TRUE if we are responder when using
private message keys. */
- SilcUInt16 resolve_cmd_ident; /* Command identifier when resolving */
- SilcAtomic32 refcnt; /* Reference counter */
- SilcAtomic32 deleted; /* Flag indicating whether the client object is
- already scheduled for deletion.*/
} SilcClientEntryInternal;
/* Internal channel entry context */
SilcHmac hmac; /* Current HMAC */
unsigned char iv[SILC_CIPHER_MAX_IV_SIZE]; /* Current IV */
+ SilcAtomic32 refcnt; /* Reference counter */
+ SilcAtomic32 deleted; /* Flag indicating whether the
+ channel object is already
+ scheduled for deletion */
SilcUInt16 resolve_cmd_ident; /* Channel information resolving
identifier. This is used when
resolving users, and other
stuff that relates to the
channel. Not used for the
channel resolving itself. */
- SilcAtomic32 refcnt; /* Reference counter */
- SilcAtomic32 deleted; /* Flag indicating whether the channel object is
- already scheduled for deletion.*/
} SilcChannelEntryInternal;
/* Internal server entry context */
channel->cipher = silc_cipher_get_name(channel->internal.send_key);
else
channel->cipher = NULL;
- if (channel->hmac)
+ if (channel->internal.hmac)
channel->hmac = silc_hmac_get_name(channel->internal.hmac);
else
channel->hmac = NULL;
if (!client_entry)
return FALSE;
- if (silc_atomic_sub_int32(&client_entry->internal.deleted, 1) != 0)
- {
- SILC_LOG_DEBUG(("** WARNING ** Deleting a client twice %p", client_entry));
-// asm("int3");
- return FALSE;
+ SILC_LOG_DEBUG(("Marking client entry %p deleted"));
+
+ if (silc_atomic_sub_int32(&client_entry->internal.deleted, 1) != 0) {
+ SILC_LOG_DEBUG(("Client entry %p already marked deleted"));
+ return FALSE;
}
silc_client_unref_client(client, conn, client_entry);
return TRUE;
-
}
/* Internal routine used to find client by ID and if not found this creates
void silc_client_unref_client(SilcClient client, SilcClientConnection conn,
SilcClientEntry client_entry)
{
- if (client_entry) {
- SilcBool ret;
+ SilcBool ret;
- SILC_LOG_DEBUG(("Client %p refcnt %d->%d", client_entry,
- silc_atomic_get_int32(&client_entry->internal.refcnt),
- silc_atomic_get_int32(&client_entry->internal.refcnt) - 1));
+ if (!client_entry)
+ return;
- if (silc_atomic_sub_int32(&client_entry->internal.refcnt, 1) > 0)
- return;
-
- SILC_LOG_DEBUG(("Deleting client %p (%d)", client_entry,
- silc_atomic_get_int32(&client_entry->internal.deleted)));
+ SILC_LOG_DEBUG(("Client %p refcnt %d->%d", client_entry,
+ silc_atomic_get_int32(&client_entry->internal.refcnt),
+ silc_atomic_get_int32(&client_entry->internal.refcnt) - 1));
- silc_mutex_lock(conn->internal->lock);
- ret = silc_idcache_del_by_context(conn->internal->client_cache,
- client_entry, NULL);
- silc_mutex_unlock(conn->internal->lock);
+ if (silc_atomic_sub_int32(&client_entry->internal.refcnt, 1) > 0)
+ return;
- if (ret) {
- /* Remove from channels */
- silc_client_remove_from_channels(client, conn, client_entry);
+ SILC_LOG_DEBUG(("Deleting client %p (%d)", client_entry,
+ silc_atomic_get_int32(&client_entry->internal.deleted)));
- /* Free the client entry data */
- silc_client_del_client_entry(client, conn, client_entry);
- }
+ silc_mutex_lock(conn->internal->lock);
+ ret = silc_idcache_del_by_context(conn->internal->client_cache,
+ client_entry, NULL);
+ silc_mutex_unlock(conn->internal->lock);
+
+ if (ret) {
+ /* Remove from channels */
+ silc_client_remove_from_channels(client, conn, client_entry);
+
+ /* Free the client entry data */
+ silc_client_del_client_entry(client, conn, client_entry);
}
}
if (!channel)
return FALSE;
- if (silc_atomic_sub_int32(&channel->internal.deleted, 1) > 0)
- {
- SILC_LOG_DEBUG(("** WARNING ** Deleting a channel twice %p", channel));
-// asm("int3");
+ SILC_LOG_DEBUG(("Marking channel entry %p deleted"));
+
+ if (silc_atomic_sub_int32(&channel->internal.deleted, 1) != 0) {
+ SILC_LOG_DEBUG(("Channel entry %p already marked deleted"));
return FALSE;
}
void silc_client_unref_channel(SilcClient client, SilcClientConnection conn,
SilcChannelEntry channel_entry)
{
- if (channel_entry) {
- SilcIDCacheEntry id_cache;
- SilcBool ret = TRUE;
- SilcCipher key;
- SilcHmac hmac;
- char *namec;
-
- SILC_LOG_DEBUG(("Channel %p refcnt %d->%d", channel_entry,
- silc_atomic_get_int32(&channel_entry->internal.refcnt),
- silc_atomic_get_int32(&channel_entry->internal.refcnt)
- - 1));
+ SilcIDCacheEntry id_cache;
+ SilcBool ret = TRUE;
+ SilcCipher key;
+ SilcHmac hmac;
+ char *namec;
- if (silc_atomic_sub_int32(&channel_entry->internal.refcnt, 1) > 0)
- return;
+ if (!channel_entry)
+ return;
- SILC_LOG_DEBUG(("Deleting channel %p", channel_entry));
+ SILC_LOG_DEBUG(("Channel %p refcnt %d->%d", channel_entry,
+ silc_atomic_get_int32(&channel_entry->internal.refcnt),
+ silc_atomic_get_int32(&channel_entry->internal.refcnt)
+ - 1));
- silc_mutex_lock(conn->internal->lock);
- if (silc_idcache_find_by_context(conn->internal->channel_cache, channel_entry,
+ if (silc_atomic_sub_int32(&channel_entry->internal.refcnt, 1) > 0)
+ return;
+
+ SILC_LOG_DEBUG(("Deleting channel %p", channel_entry));
+
+ silc_mutex_lock(conn->internal->lock);
+ if (silc_idcache_find_by_context(conn->internal->channel_cache, channel_entry,
&id_cache)) {
- namec = id_cache->name;
- ret = silc_idcache_del_by_context(conn->internal->channel_cache,
+ namec = id_cache->name;
+ ret = silc_idcache_del_by_context(conn->internal->channel_cache,
channel_entry, NULL);
- silc_free(namec);
- }
- silc_mutex_unlock(conn->internal->lock);
+ silc_free(namec);
+ }
+ silc_mutex_unlock(conn->internal->lock);
- if (!ret)
- return;
+ if (!ret)
+ return;
- silc_client_empty_channel(client, conn, channel_entry);
- silc_client_del_channel_private_keys(client, conn, channel_entry);
- silc_hash_table_free(channel_entry->user_list);
- silc_free(channel_entry->channel_name);
- silc_free(channel_entry->topic);
- if (channel_entry->founder_key)
- silc_pkcs_public_key_free(channel_entry->founder_key);
- if (channel_entry->internal.send_key)
- silc_cipher_free(channel_entry->internal.send_key);
- if (channel_entry->internal.receive_key)
- silc_cipher_free(channel_entry->internal.receive_key);
- if (channel_entry->internal.hmac)
- silc_hmac_free(channel_entry->internal.hmac);
- if (channel_entry->internal.old_channel_keys) {
- silc_dlist_start(channel_entry->internal.old_channel_keys);
- while ((key = silc_dlist_get(channel_entry->internal.old_channel_keys)))
- silc_cipher_free(key);
- silc_dlist_uninit(channel_entry->internal.old_channel_keys);
- }
- if (channel_entry->internal.old_hmacs) {
- silc_dlist_start(channel_entry->internal.old_hmacs);
- while ((hmac = silc_dlist_get(channel_entry->internal.old_hmacs)))
- silc_hmac_free(hmac);
- silc_dlist_uninit(channel_entry->internal.old_hmacs);
- }
- if (channel_entry->channel_pubkeys)
- silc_argument_list_free(channel_entry->channel_pubkeys,
+ silc_client_empty_channel(client, conn, channel_entry);
+ silc_client_del_channel_private_keys(client, conn, channel_entry);
+ silc_hash_table_free(channel_entry->user_list);
+ silc_free(channel_entry->channel_name);
+ silc_free(channel_entry->topic);
+ if (channel_entry->founder_key)
+ silc_pkcs_public_key_free(channel_entry->founder_key);
+ if (channel_entry->internal.send_key)
+ silc_cipher_free(channel_entry->internal.send_key);
+ if (channel_entry->internal.receive_key)
+ silc_cipher_free(channel_entry->internal.receive_key);
+ if (channel_entry->internal.hmac)
+ silc_hmac_free(channel_entry->internal.hmac);
+ if (channel_entry->internal.old_channel_keys) {
+ silc_dlist_start(channel_entry->internal.old_channel_keys);
+ while ((key = silc_dlist_get(channel_entry->internal.old_channel_keys)))
+ silc_cipher_free(key);
+ silc_dlist_uninit(channel_entry->internal.old_channel_keys);
+ }
+ if (channel_entry->internal.old_hmacs) {
+ silc_dlist_start(channel_entry->internal.old_hmacs);
+ while ((hmac = silc_dlist_get(channel_entry->internal.old_hmacs)))
+ silc_hmac_free(hmac);
+ silc_dlist_uninit(channel_entry->internal.old_hmacs);
+ }
+ if (channel_entry->channel_pubkeys)
+ silc_argument_list_free(channel_entry->channel_pubkeys,
SILC_ARGUMENT_PUBLIC_KEY);
- silc_atomic_uninit32(&channel_entry->internal.deleted);
- silc_atomic_uninit32(&channel_entry->internal.refcnt);
- silc_rwlock_free(channel_entry->internal.lock);
- silc_schedule_task_del_by_context(conn->client->schedule, channel_entry);
- silc_free(channel_entry);
- }
+ silc_atomic_uninit32(&channel_entry->internal.deleted);
+ silc_atomic_uninit32(&channel_entry->internal.refcnt);
+ silc_rwlock_free(channel_entry->internal.lock);
+ silc_schedule_task_del_by_context(conn->client->schedule, channel_entry);
+ silc_free(channel_entry);
}
/* Free channel entry list */
SilcMutex lock; /* Engine lock */
SilcRng rng; /* RNG for engine */
SilcHashTable contexts; /* Per scheduler contexts */
- SilcPacketCallbacks *callbacks; /* Packet callbacks */
+ const SilcPacketCallbacks *callbacks; /* Packet callbacks */
void *callback_context; /* Context for callbacks */
SilcList streams; /* All streams in engine */
SilcList packet_pool; /* Free list for received packets */
/* Packet processor context */
typedef struct SilcPacketProcessStruct {
SilcPacketType *types; /* Packets to process */
- SilcPacketCallbacks *callbacks; /* Callbacks or NULL */
+ const SilcPacketCallbacks *callbacks; /* Callbacks or NULL */
void *callback_context;
SilcInt32 priority; /* Priority */
} *SilcPacketProcess;
SilcPacketEngine
silc_packet_engine_start(SilcRng rng, SilcBool router,
- SilcPacketCallbacks *callbacks,
+ const SilcPacketCallbacks *callbacks,
void *callback_context)
{
SilcPacketEngine engine;
/* Links `callbacks' to `stream' for specified packet types */
static SilcBool silc_packet_stream_link_va(SilcPacketStream stream,
- SilcPacketCallbacks *callbacks,
+ const SilcPacketCallbacks *callbacks,
void *callback_context,
int priority, va_list ap)
{
/* Links `callbacks' to `stream' for specified packet types */
SilcBool silc_packet_stream_link(SilcPacketStream stream,
- SilcPacketCallbacks *callbacks,
+ const SilcPacketCallbacks *callbacks,
void *callback_context,
int priority, ...)
{
/* Unlinks `callbacks' from `stream'. */
void silc_packet_stream_unlink(SilcPacketStream stream,
- SilcPacketCallbacks *callbacks,
+ const SilcPacketCallbacks *callbacks,
void *callback_context)
{
SilcPacketProcess p;
{
SilcUInt32 len;
unsigned char tmp[32];
+ void *tmp_id;
if (!src_id && !dst_id)
return FALSE;
if (src_id) {
SILC_LOG_DEBUG(("Setting source ID to packet stream %p", stream));
- silc_free(stream->src_id);
- stream->src_id = NULL;
if (!silc_id_id2str(src_id, src_id_type, tmp, sizeof(tmp), &len)) {
silc_mutex_unlock(stream->lock);
return FALSE;
}
- stream->src_id = silc_memdup(tmp, len);
- if (!stream->src_id) {
+ tmp_id = silc_memdup(tmp, len);
+ if (!tmp_id) {
silc_mutex_unlock(stream->lock);
return FALSE;
}
+ silc_free(stream->src_id);
+ stream->src_id = tmp_id;
stream->src_id_type = src_id_type;
stream->src_id_len = len;
}
if (dst_id) {
SILC_LOG_DEBUG(("Setting destination ID to packet stream %p", stream));
- silc_free(stream->dst_id);
- stream->dst_id = NULL;
if (!silc_id_id2str(dst_id, dst_id_type, tmp, sizeof(tmp), &len)) {
silc_mutex_unlock(stream->lock);
return FALSE;
}
- stream->dst_id = silc_memdup(tmp, len);
- if (!stream->dst_id) {
+ tmp_id = silc_memdup(tmp, len);
+ if (!tmp_id) {
silc_mutex_unlock(stream->lock);
return FALSE;
}
+ silc_free(stream->dst_id);
+ stream->dst_id = tmp_id;
stream->dst_id_type = dst_id_type;
stream->dst_id_len = len;
}
void *stream_context);
/* Packet waiting callbacks */
-static SilcPacketCallbacks silc_packet_wait_cbs =
+static const SilcPacketCallbacks silc_packet_wait_cbs =
{
silc_packet_wait_packet_receive, NULL, NULL
};
} *SilcPacketWrapperStream;
/* Packet wrapper callbacks */
-static SilcPacketCallbacks silc_packet_wrap_cbs =
+static const SilcPacketCallbacks silc_packet_wrap_cbs =
{
silc_packet_wrap_packet_receive, NULL, NULL
};
***/
SilcPacketEngine
silc_packet_engine_start(SilcRng rng, SilcBool router,
- SilcPacketCallbacks *callbacks,
+ const SilcPacketCallbacks *callbacks,
void *callback_context);
/****f* silccore/SilcPacketAPI/silc_packet_engine_stop
*
***/
SilcBool silc_packet_stream_link(SilcPacketStream stream,
- SilcPacketCallbacks *callbacks,
+ const SilcPacketCallbacks *callbacks,
void *callback_context,
int priority, ...);
*
***/
void silc_packet_stream_unlink(SilcPacketStream stream,
- SilcPacketCallbacks *callbacks,
+ const SilcPacketCallbacks *callbacks,
void *callback_context);
/****f* silccore/SilcPacketAPI/SilcPacketWrapCoder
Author: Pekka Riikonen <priikone@silcnet.org>
- Copyright (C) 2000 - 2007 Pekka Riikonen
+ Copyright (C) 2000 - 2008 Pekka Riikonen
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
silc_packet_free(ske->packet);
ske->packet = NULL;
- /* Verify the received public key and verify the signature if we are
- doing mutual authentication. */
- if (ske->start_payload &&
- ske->start_payload->flags & SILC_SKE_SP_FLAG_MUTUAL) {
-
- SILC_LOG_DEBUG(("We are doing mutual authentication"));
-
- if (!recv_payload->pk_data && (ske->callbacks->verify_key ||
- ske->repository)) {
+ /* Verify public key, except in rekey, when it is not sent */
+ if (!ske->rekey) {
+ if (!recv_payload->pk_data) {
/** Public key not provided */
SILC_LOG_ERROR(("Remote end did not send its public key (or "
"certificate), even though we require it"));
}
/* Decode the remote's public key */
- if (recv_payload->pk_data &&
- !silc_pkcs_public_key_alloc(recv_payload->pk_type,
+ if (!silc_pkcs_public_key_alloc(recv_payload->pk_type,
recv_payload->pk_data,
recv_payload->pk_len,
&ske->prop->public_key)) {
return SILC_FSM_CONTINUE;
}
- if (ske->prop->public_key && (ske->callbacks->verify_key ||
- ske->repository)) {
- SILC_LOG_DEBUG(("Verifying public key"));
+ SILC_LOG_DEBUG(("Verifying public key"));
- /** Waiting public key verification */
- silc_fsm_next(fsm, silc_ske_st_responder_phase4);
+ /** Waiting public key verification */
+ silc_fsm_next(fsm, silc_ske_st_responder_phase4);
- /* If repository is provided, verify the key from there. */
- if (ske->repository) {
- SilcSKRFind find;
+ /* If repository is provided, verify the key from there. */
+ if (ske->repository) {
+ SilcSKRFind find;
- find = silc_skr_find_alloc();
- if (!find) {
- ske->status = SILC_SKE_STATUS_OUT_OF_MEMORY;
- silc_fsm_next(fsm, silc_ske_st_responder_error);
- return SILC_FSM_CONTINUE;
- }
- silc_skr_find_set_pkcs_type(find,
- silc_pkcs_get_type(ske->prop->public_key));
- silc_skr_find_set_public_key(find, ske->prop->public_key);
- silc_skr_find_set_usage(find, SILC_SKR_USAGE_KEY_AGREEMENT);
-
- /* Find key from repository */
- SILC_FSM_CALL(silc_skr_find(ske->repository,
- silc_fsm_get_schedule(fsm), find,
- silc_ske_skr_callback, ske));
- } else {
- /* Verify from application */
+ find = silc_skr_find_alloc();
+ if (!find) {
+ ske->status = SILC_SKE_STATUS_OUT_OF_MEMORY;
+ silc_fsm_next(fsm, silc_ske_st_responder_error);
+ return SILC_FSM_CONTINUE;
+ }
+ silc_skr_find_set_pkcs_type(find,
+ silc_pkcs_get_type(ske->prop->public_key));
+ silc_skr_find_set_public_key(find, ske->prop->public_key);
+ silc_skr_find_set_usage(find, SILC_SKR_USAGE_KEY_AGREEMENT);
+
+ /* Find key from repository */
+ SILC_FSM_CALL(silc_skr_find(ske->repository,
+ silc_fsm_get_schedule(fsm), find,
+ silc_ske_skr_callback, ske));
+ } else {
+ /* Verify from application */
+ if (ske->callbacks->verify_key)
SILC_FSM_CALL(ske->callbacks->verify_key(ske, ske->prop->public_key,
ske->callbacks->context,
silc_ske_pk_verified, NULL));
- }
- /* NOT REACHED */
}
}
unsigned char hash[SILC_HASH_MAXLEN];
SilcUInt32 hash_len;
- SILC_LOG_DEBUG(("Public key is authentic"));
+ SILC_LOG_DEBUG(("We are doing mutual authentication"));
/* Compute the hash value */
status = silc_ske_make_hash(ske, hash, &hash_len, TRUE);
*
* SOURCE
*/
-#if SILC_SIZEOF_LONG == 4
-typedef unsigned long SilcUInt32;
-typedef signed long SilcInt32;
-#else
#if SILC_SIZEOF_INT == 4
typedef unsigned int SilcUInt32;
typedef signed int SilcInt32;
#else
+#if SILC_SIZEOF_LONG == 4
+typedef unsigned long SilcUInt32;
+typedef signed long SilcInt32;
+#else
#if SILC_SIZEOF_LONG_LONG >= 4
#ifndef WIN32
typedef unsigned long long SilcUInt32;
#endif
/***/
+typedef char __check_size1[sizeof(SilcInt8) == 1 ? 1 : -1];
+typedef char __check_size2[sizeof(SilcUInt8) == 1 ? 1 : -1];
+typedef char __check_size3[sizeof(SilcInt16) == 2 ? 1 : -1];
+typedef char __check_size4[sizeof(SilcUInt16) == 2 ? 1 : -1];
+typedef char __check_size5[sizeof(SilcInt32) == 4 ? 1 : -1];
+typedef char __check_size6[sizeof(SilcUInt32) == 4 ? 1 : -1];
+
#endif /* SILCTYPES_H */