if (idle && nickname) {
memset(buf, 0, sizeof(buf));
- snprintf(buf, sizeof(buf) - 1, "%lu %s",
+ snprintf(buf, sizeof(buf) - 1, "%u %s",
idle > 60 ? (idle / 60) : idle,
idle > 60 ? "minutes" : "seconds");
if (!tl) {
fprintf(stderr, "Couldn't open mail file (%s).\n", filename);
} else {
- while((fscanf(tl, "%s", data)) != EOF) {
+ while((fscanf(tl, "%1023s", data)) != EOF) {
if(!strcmp(data, "From:"))
num++;
}
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 {
/* If backup disconnected then mark that resuming will not be allowed */
if (server->server_type == SILC_ROUTER && !server->backup_router &&
if (!silc_packet_stream_is_valid(stream))
return;
+ /* In case we get here many times, register only one timeout */
+ silc_schedule_task_del_by_all(server->schedule, 0,
+ silc_server_packet_error_timeout, stream);
+
+ /* Close connection with random timeout */
silc_schedule_task_add_timeout(server->schedule,
silc_server_packet_error_timeout, stream,
- silc_rng_get_byte(server->rng) % 5, 0);
+ silc_rng_get_byte(server->rng) % 10, 0);
}
/* Packet stream callbacks */
}
if (!(client->data.status & SILC_IDLIST_STATUS_REGISTERED)) {
- SILC_LOG_ERROR(("Attempting to add unregistered client to channel ",
+ SILC_LOG_ERROR(("Attempting to add unregistered client to channel "
"%s", channel->channel_name));
continue;
}
#define SILC_IS_LOCAL(entry) \
(((SilcIDListData)entry)->status & SILC_IDLIST_STATUS_LOCAL)
-/* Registers generic task for file descriptor for reading from network and
- writing to network. As being generic task the actual task is allocated
- only once and after that the same task applies to all registered fd's. */
-#define SILC_REGISTER_CONNECTION_FOR_IO(fd) \
-do { \
- silc_schedule_task_add(server->schedule, (fd), \
- silc_server_packet_process, \
- context, 0, 0, \
- SILC_TASK_GENERIC, \
- SILC_TASK_PRI_NORMAL); \
-} while(0)
-
-#define SILC_SET_CONNECTION_FOR_INPUT(s, fd) \
-do { \
- silc_schedule_set_listen_fd((s), (fd), SILC_TASK_READ, FALSE); \
-} while(0)
-
-#define SILC_SET_CONNECTION_FOR_OUTPUT(s, fd) \
-do { \
- silc_schedule_set_listen_fd((s), (fd), (SILC_TASK_READ | SILC_TASK_WRITE), \
- FALSE); \
-} while(0)
-
#define SILC_OPER_STATS_UPDATE(c, type, mod) \
do { \
if ((c)->mode & (mod)) { \
silc_config_strerror(ret)));
linebuf = silc_config_read_line(file, line);
if (linebuf) {
- SILC_SERVER_LOG_ERROR((" file %s line %lu: %s\n", filename,
+ SILC_SERVER_LOG_ERROR((" file %s line %u: %s\n", filename,
line, linebuf));
silc_free(linebuf);
}
}
/* Read width and height */
- ret = sscanf(header, "%s %ld %ld %ld\n", type,
+ ret = sscanf(header, "%2s %ld %ld %ld\n", type,
(unsigned long *)&map->width,
(unsigned long *)&map->height,
(unsigned long *)&map->maxcolor);
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
void *app_context)
{
if (cache->destructor)
- cache->destructor(cache, entry, cache->destructor, app_context);
+ cache->destructor(cache, entry, cache->context, app_context);
memset(entry, 'F', sizeof(*entry));
silc_free(entry);
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
*
* SYNOPSIS
*
- * SilcBool silc_idcache_del_by_context(SilcIDCache cache, void *context);
+ * SilcBool silc_idcache_del_by_context(SilcIDCache cache, void *context,
+ * void *app_context);
*
* DESCRIPTION
*
if (!client_entry)
return FALSE;
- SILC_LOG_DEBUG(("Marking client entry %p deleted"));
+ SILC_LOG_DEBUG(("Marking client entry %p deleted", client_entry));
if (silc_atomic_sub_int32(&client_entry->internal.deleted, 1) != 0) {
- SILC_LOG_DEBUG(("Client entry %p already marked deleted"));
+ SILC_LOG_DEBUG(("Client entry %p already marked deleted", client_entry));
return FALSE;
}
if (!channel)
return FALSE;
- SILC_LOG_DEBUG(("Marking channel entry %p deleted"));
+ SILC_LOG_DEBUG(("Marking channel entry %p deleted", channel));
if (silc_atomic_sub_int32(&channel->internal.deleted, 1) != 0) {
- SILC_LOG_DEBUG(("Channel entry %p already marked deleted"));
+ SILC_LOG_DEBUG(("Channel entry %p already marked deleted", channel));
return FALSE;
}
ke = client_entry->internal.ke;
- SILC_LOG_DEBUG(("Abort key agreement %p"));
+ SILC_LOG_DEBUG(("Abort key agreement ke %p for client %p on connection %p",
+ ke, client, conn));
ke->completion(client, conn, client_entry,
SILC_KEY_AGREEMENT_ABORTED, NULL, ke->context);
SILC_LOG_HEXDUMP(("Counter Block"), iv, 16);
}
+/* Return special packet's encrypted length */
+
+static inline int silc_packet_special_len(unsigned char *data)
+{
+ return (((SilcUInt8)data[4] + (SilcUInt8)data[6] +
+ (SilcUInt8)data[7] + SILC_PACKET_HEADER_LEN));
+}
+
/* Decrypts SILC packet. Handles both normal and special packet decryption.
Return 0 when packet is normal and 1 when it it special, -1 on error. */
/* Padding length + src id len + dst id len + header length - 16
bytes already decrypted, gives the rest of the encrypted packet */
silc_buffer_push(buffer, block_len);
- len = (((SilcUInt8)buffer->data[4] + (SilcUInt8)buffer->data[6] +
- (SilcUInt8)buffer->data[7] + SILC_PACKET_HEADER_LEN) -
- block_len);
+ len = silc_packet_special_len(buffer->data) - block_len;
silc_buffer_pull(buffer, block_len);
if (silc_unlikely(len > silc_buffer_len(buffer))) {
SilcCipher cipher;
SilcHmac hmac;
SilcPacket packet;
- SilcUInt8 sid;
+ SilcUInt8 sid, flags, type;
SilcUInt16 packetlen;
SilcUInt32 paddedlen, mac_len, block_len, ivlen, psnlen;
unsigned char tmp[SILC_PACKET_MIN_HEADER_LEN], *header;
/* Get packet length and full packet length with padding */
SILC_PACKET_LENGTH(header, packetlen, paddedlen);
+ /* Parse packet header */
+ flags = (SilcPacketFlags)header[2];
+ type = (SilcPacketType)header[3];
+
+ if (stream->sc->engine->local_is_router) {
+ if (type == SILC_PACKET_PRIVATE_MESSAGE &&
+ (flags & SILC_PACKET_FLAG_PRIVMSG_KEY))
+ normal = FALSE;
+ else if (type != SILC_PACKET_CHANNEL_MESSAGE ||
+ (type == SILC_PACKET_CHANNEL_MESSAGE &&
+ stream->is_router == TRUE))
+ normal = TRUE;
+ } else {
+ if (type == SILC_PACKET_PRIVATE_MESSAGE &&
+ (flags & SILC_PACKET_FLAG_PRIVMSG_KEY))
+ normal = FALSE;
+ else if (type != SILC_PACKET_CHANNEL_MESSAGE)
+ normal = TRUE;
+ }
+
+ /* Padding sanity checks */
+ if (cipher && silc_cipher_get_mode(cipher) != SILC_CIPHER_MODE_CTR &&
+ ((normal && paddedlen % block_len != 0) ||
+ (!normal && silc_packet_special_len(header) % block_len != 0))) {
+ SILC_LOG_DEBUG(("Packet length %d not multiple by cipher block length",
+ paddedlen));
+ silc_mutex_unlock(stream->lock);
+ SILC_PACKET_CALLBACK_ERROR(stream, SILC_PACKET_ERR_MALFORMED);
+ silc_mutex_lock(stream->lock);
+ memset(tmp, 0, sizeof(tmp));
+ goto out;
+ }
+
if (silc_buffer_len(inbuf) < paddedlen + ivlen + mac_len) {
SILC_LOG_DEBUG(("Received partial packet, waiting for the rest "
"(%d bytes)",
goto out;
}
packet->stream = stream;
+ packet->flags = flags;
+ packet->type = type;
/* Allocate more space to packet buffer, if needed */
if (silc_unlikely(silc_buffer_truelen(&packet->buffer) < paddedlen)) {
}
}
- /* Parse packet header */
- packet->flags = (SilcPacketFlags)header[2];
- packet->type = (SilcPacketType)header[3];
-
- if (stream->sc->engine->local_is_router) {
- if (packet->type == SILC_PACKET_PRIVATE_MESSAGE &&
- (packet->flags & SILC_PACKET_FLAG_PRIVMSG_KEY))
- normal = FALSE;
- else if (packet->type != SILC_PACKET_CHANNEL_MESSAGE ||
- (packet->type == SILC_PACKET_CHANNEL_MESSAGE &&
- stream->is_router == TRUE))
- normal = TRUE;
- } else {
- if (packet->type == SILC_PACKET_PRIVATE_MESSAGE &&
- (packet->flags & SILC_PACKET_FLAG_PRIVMSG_KEY))
- normal = FALSE;
- else if (packet->type != SILC_PACKET_CHANNEL_MESSAGE)
- normal = TRUE;
- }
-
SILC_LOG_HEXDUMP(("Incoming packet (%d) len %d",
stream->receive_psn, paddedlen + ivlen + mac_len),
inbuf->data, paddedlen + ivlen + mac_len);
/* Check we have received all data */
cl = silc_mime_get_field(conn->curheaders, "Content-Length");
- if (cl && sscanf(cl, "%lu", (unsigned long *)&cll) == 1) {
+ if (cl && sscanf(cl, "%u", &cll) == 1) {
if (data_len < cll) {
/* More data to come */
silc_mime_free(conn->curheaders);
*/
static void silc_ske_notify_failure(SilcSKE ske)
{
- SILC_LOG_DEBUG(("Notifying SKE %p owner of failure (failure_notified = %lu)",
+ SILC_LOG_DEBUG(("Notifying SKE %p owner of failure (failure_notified = %d)",
ske, ske->failure_notified));
/*
SilcSKRKeyInternal k = (SilcSKRKeyInternal)key;
silc_mutex_lock(skr->lock);
- SILC_LOG_DEBUG(("SKR key %p ref %d -> %d", k->refcnt, k->refcnt + 1));
+ SILC_LOG_DEBUG(("SKR key %p ref %d -> %d", k, k->refcnt, k->refcnt + 1));
k->refcnt++;
silc_mutex_unlock(skr->lock);
}
silc_mutex_lock(skr->lock);
- SILC_LOG_DEBUG(("SKR key %p ref %d -> %d", k->refcnt, k->refcnt - 1));
+ SILC_LOG_DEBUG(("SKR key %p ref %d -> %d", k, k->refcnt, k->refcnt - 1));
k->refcnt--;
if (k->refcnt == 0) {
if (task) {
schedule->timeout = curtime;
schedule->has_timeout = TRUE;
- SILC_LOG_DEBUG(("timeout: sec=%d, usec=%d", schedule->timeout.tv_sec,
+ SILC_LOG_DEBUG(("timeout: sec=%ld, usec=%ld", schedule->timeout.tv_sec,
schedule->timeout.tv_usec));
}
}
{
SilcTaskFd ftask;
fprintf(stdout, "Schedule %p statistics:\n\n", schedule);
- fprintf(stdout, "Num FD tasks : %lu (%lu bytes allocated)\n",
+ fprintf(stdout, "Num FD tasks : %u (%u bytes allocated)\n",
silc_hash_table_count(schedule->fd_queue),
sizeof(*ftask) * silc_hash_table_count(schedule->fd_queue));
fprintf(stdout, "Num Timeout tasks : %d (%d bytes allocated)\n",
}
}
- SILC_LOG_DEBUG(("New timeout task %p: sec=%d, usec=%d", ttask,
+ SILC_LOG_DEBUG(("New timeout task %p: sec=%ld, usec=%ld", ttask,
seconds, useconds));
/* Add task to correct spot so that the first task in the list has
return NULL;
}
- SILC_LOG_DEBUG(("Creating TCP socket stream %p, sock %lu", stream, sock));
+ SILC_LOG_DEBUG(("Creating TCP socket stream %p, sock %lu", stream, (long unsigned) sock));
stream->ops = &silc_socket_stream_ops;
stream->sock = sock;
if (!internal)
return TRUE;
- SILC_LOG_DEBUG(("Scheduling fd %lu, mask %x", task->fd, event_mask));
+ SILC_LOG_DEBUG(("Scheduling fd %u, mask %x", task->fd, event_mask));
memset(&event, 0, sizeof(event));
if (event_mask & SILC_TASK_READ)
if (strncmp ("http://", cur_char, strlen ("http://")) == 0)
{
- sscanf (cur_char, "%s", link);
+ sscanf (cur_char, "%1023s", link);
RB_Say ("found link %s\n", link);
res = (strlen (link) - 1);
fprintf (dest_doc, "<A HREF=\"%s\">%s</A>", link, link);
else if (strncmp ("href:", cur_char, strlen ("href:")) == 0)
{
/* handy in relative hyperlink paths, e.g. href:../../modulex/ */
- sscanf ((cur_char + strlen ("href:")), "%s", link);
+ sscanf ((cur_char + strlen ("href:")), "%1023s", link);
RB_Say ("found link %s\n", link);
res = (strlen (link) + strlen ("href:") - 1);
fprintf (dest_doc, "<A HREF=\"%s\">%s</A>", link, link);
}
else if (strncmp ("mailto:", cur_char, strlen ("mailto:")) == 0)
{
- sscanf ((cur_char + strlen ("mailto:")), "%s", link);
+ sscanf ((cur_char + strlen ("mailto:")), "%1023s", link);
RB_Say ("found mail to %s\n", link);
res = (strlen (link) + strlen ("mailto:") - 1);
fprintf (dest_doc, "<A HREF=\"mailto:%s\">%s</A>", link, link);