Code cleanup during merge.
Reverted External IP commit
Reverted changes to silcsocketstream API. The user context can be now
set to SilcClientConnectionParams. Increased shared library revision to
avoid backwards incompatiblity.
Signed-off-by: Pekka Riikonen <priikone@silcnet.org>
Author: Pekka Riikonen <priikone@silcnet.org>
- Copyright (C) 2001 - 2007 Pekka Riikonen
+ Copyright (C) 2001 - 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
}
/*
- * Drop our references as need be.
- */
- switch (getkey->id_type)
- {
- case SILC_ID_CLIENT:
- silc_client_unref_client(getkey->client, getkey->conn, (SilcClientEntry)getkey->entry);
- break;
-
- case SILC_ID_SERVER:
- silc_client_unref_server(getkey->client, getkey->conn, (SilcServerEntry)getkey->entry);
- break;
+ * Drop our references as need be.
+ */
+ switch (getkey->id_type) {
+ case SILC_ID_CLIENT:
+ silc_client_unref_client(getkey->client, getkey->conn,
+ (SilcClientEntry)getkey->entry);
+ break;
+
+ case SILC_ID_SERVER:
+ silc_client_unref_server(getkey->client, getkey->conn,
+ (SilcServerEntry)getkey->entry);
+ break;
}
silc_free(getkey);
((SilcClientEntry)entry)->nickname :
((SilcServerEntry)entry)->server_name);
- switch (id_type)
- {
- case SILC_ID_CLIENT:
- name = ((SilcClientEntry)entry)->nickname;
- silc_client_ref_client(client, conn, (SilcClientEntry)entry);
- break;
-
- case SILC_ID_SERVER:
- name = ((SilcServerEntry)entry)->server_name;
- silc_client_ref_server(client, conn, (SilcServerEntry)entry);
- break;
+ switch (id_type) {
+ case SILC_ID_CLIENT:
+ name = ((SilcClientEntry)entry)->nickname;
+ silc_client_ref_client(client, conn, (SilcClientEntry)entry);
+ break;
+
+ case SILC_ID_SERVER:
+ name = ((SilcServerEntry)entry)->server_name;
+ silc_client_ref_server(client, conn, (SilcServerEntry)entry);
+ break;
}
silc_verify_public_key_internal(client, conn, name,
} *PublicKeyVerify;
static void verify_public_key_completion(const char *line, void *context,
- SilcKeyboardPromptStatus reason)
+ SilcKeyboardPromptStatus reason)
{
PublicKeyVerify verify = (PublicKeyVerify)context;
- bool success = (reason == KeyboardCompletionSuccess);
+ SilcBool success = (reason == KeyboardCompletionSuccess);
if (success && (line[0] == 'Y' || line[0] == 'y')) {
/* Call the completion */
* we failed due to an overlapping callback, in which case we shouldn't
* overwrite the async context block pointer.
*/
-
- if (reason != KeyboardCompletionFailed)
- {
+ if (reason != KeyboardCompletionFailed) {
/*
- * Null out the completion context in the server record as this operation
- * is done as far as we are concerned. The underlying keyboard library
- * routine will take care of freeing the async context memory when the
- * actual callback is called by irssi in the abort case. In the success
- * case, it will free the async context memory after we return from this
- * routine.
- */
-
- SILC_SERVER_REC *server = (SILC_SERVER_REC*)(verify->conn->context);
-
- server->prompt_op = NULL;
+ * Null out the completion context in the server record as this operation
+ * is done as far as we are concerned. The underlying keyboard library
+ * routine will take care of freeing the async context memory when the
+ * actual callback is called by irssi in the abort case. In the success
+ * case, it will free the async context memory after we return from this
+ * routine.
+ */
+ SILC_SERVER_REC *server = (SILC_SERVER_REC*)(verify->conn->context);
+ server->prompt_op = NULL;
}
silc_free(verify->filename);
int i;
server = (SILC_SERVER_REC*)conn->context;
-
- /*
- * If we don't have a context yet, then we'll set it up based on the
- * stream context associated with the SilcPacketStream that is attached
- * to the SilcClientConnection. This is a bit ugly, but we need to have a
- * per-connection context value to perform the public key verify operation,
- * and the public API was not designed to let us have this in a particularly
- * straightforward fashion.
- */
-
+ SILC_VERIFY(server);
if (!server) {
- SilcPacketStream packet_stream;
- SilcStream stream;
-
- packet_stream = conn->stream;
-
- if (!packet_stream)
- {
- if (completion)
- completion(FALSE, context);
- return;
- }
-
- stream = silc_packet_stream_get_stream(packet_stream);
-
- if (!stream)
- {
- if (completion)
- completion(FALSE, context);
- return;
- }
-
- server = (SILC_SERVER_REC*)(silc_socket_stream_get_context(stream));
-
- if (!server)
- {
- if (completion)
- completion(FALSE, context);
- return;
- }
-
- conn->context = (void *)server;
+ if (completion)
+ completion(FALSE, context);
+ return;
}
if (silc_pkcs_get_type(public_key) != SILC_PKCS_SILC) {
} *AskPassphrase;
void ask_passphrase_completion(const char *passphrase, void *context,
- SilcKeyboardPromptStatus reason)
+ SilcKeyboardPromptStatus reason)
{
AskPassphrase p = (AskPassphrase)context;
if (passphrase && passphrase[0] == '\0')
p->completion((unsigned char *)passphrase,
passphrase ? strlen(passphrase) : 0, p->context);
- if (reason != KeyboardCompletionFailed)
- {
+ if (reason != KeyboardCompletionFailed) {
SILC_SERVER_REC *server = (SILC_SERVER_REC *)(p->conn->context);
-
- server->prompt_op = NULL;
+ server->prompt_op = NULL;
}
silc_free(p);
SilcAskPassphrase completion, void *context)
{
SILC_SERVER_REC *server = (SILC_SERVER_REC*)(conn->context);
- AskPassphrase p = silc_calloc(1, sizeof(*p));
-
+ AskPassphrase p;
+
+ p = silc_calloc(1, sizeof(*p));
+ if (!p) {
+ if (completion)
+ completion(NULL, 0, context);
+ return;
+ }
+
p->completion = completion;
p->conn = conn;
p->context = context;
silc_keyboard_entry_redirect(ask_passphrase_completion,
- "Passphrase: ", ENTRY_REDIRECT_FLAG_HIDDEN, p, &server->prompt_op);
+ "Passphrase: ", ENTRY_REDIRECT_FLAG_HIDDEN,
+ p, &server->prompt_op);
}
typedef struct {
Author: Pekka Riikonen <priikone@silcnet.org>
- Copyright (C) 1997 - 2006 Pekka Riikonen
+ Copyright (C) 1997 - 2006, 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
{
char pub[256], prv[256];
struct passwd *pw;
- bool ret;
+ SilcBool ret;
SILC_LOG_DEBUG(("Loading public and private keys"));
return ret;
}
-static bool silc_keyboard_prompt_pending;
+static SilcBool silc_keyboard_prompt_pending;
-typedef struct
-{
- SilcAsyncOperation async_context;
- SILC_KEYBOARD_PROMPT_PROC user_prompt_proc;
- void *user_context;
- bool aborted;
- bool *immediate_completion;
-} * SilcKeyboardEntryRedirectContext;
-
-static void silc_keyboard_entry_redirect_abort(
- SilcAsyncOperation op,
- void *context)
-{
- SilcKeyboardEntryRedirectContext ctx = (SilcKeyboardEntryRedirectContext)context;
-
- /*
- * Flag ourselves as aborted so the irssi callback doesn't do any real
- * work here.
- */
-
- ctx->aborted = TRUE;
-
- /*
- * Call the user routine to notify it that we are aborting, so that it may
- * clean up anything that needs cleaning up, e.g. references. The user
- * may not reference the SilcAsyncOperation beyond this abort call. The
- * recommended procedure is for the user prompt routine to null out its
- * reference to the SilcAsyncOperation context. The underlying context
- * structure will be released when the actual wrappered callback fires,
- * though the wrappered callback will not call into user code now that
- * the operation has been aborted.
- */
-
- ctx->user_prompt_proc(NULL, ctx->user_context, KeyboardCompletionAborted);
-}
+typedef struct {
+ SilcAsyncOperation async_context;
+ SILC_KEYBOARD_PROMPT_PROC user_prompt_proc;
+ void *user_context;
+ SilcBool aborted;
+ SilcBool *immediate_completion;
+} *SilcKeyboardEntryRedirectContext;
-static void silc_keyboard_entry_redirect_completion(
- const char *line,
- void *context)
+static void silc_keyboard_entry_redirect_abort(SilcAsyncOperation op,
+ void *context)
{
- SilcKeyboardEntryRedirectContext ctx = (SilcKeyboardEntryRedirectContext)context;
-
- /*
- * If we are aborted, then don't call the user routine. Note that we
- * already notified the user that they were aborted when the abort
- * call was made in the first place, so the user should not have any
- * dangling references at this point.
- *
- * Otherwise, call the user routine.
- */
-
- if (!ctx->aborted)
- {
- ctx->user_prompt_proc(line, ctx->user_context,
- KeyboardCompletionSuccess);
- }
+ SilcKeyboardEntryRedirectContext ctx = context;
- /*
- * If there's a flag to set on completion, such that we can detect when the
- * operation finished immediately instead of being processed as a callback,
- * then set that now.
- */
+ /*
+ * Flag ourselves as aborted so the irssi callback doesn't do any real
+ * work here.
+ */
+ ctx->aborted = TRUE;
- if (ctx->immediate_completion)
- *ctx->immediate_completion = TRUE;
+ /*
+ * Call the user routine to notify it that we are aborting, so that it may
+ * clean up anything that needs cleaning up, e.g. references. The user
+ * may not reference the SilcAsyncOperation beyond this abort call. The
+ * recommended procedure is for the user prompt routine to null out its
+ * reference to the SilcAsyncOperation context. The underlying context
+ * structure will be released when the actual wrappered callback fires,
+ * though the wrappered callback will not call into user code now that
+ * the operation has been aborted.
+ */
+ ctx->user_prompt_proc(NULL, ctx->user_context, KeyboardCompletionAborted);
+}
- /*
- * Clean up our internal context structures. Note that we are considered
- * responsible for handling the SilcAsyncOperation release in this model,
- * unless we were aborted, in which case the abort request has released it.
- */
+static void silc_keyboard_entry_redirect_completion(const char *line,
+ void *context)
+{
+ SilcKeyboardEntryRedirectContext ctx = context;
- if (!ctx->aborted)
- silc_async_free(ctx->async_context);
+ /*
+ * If we are aborted, then don't call the user routine. Note that we
+ * already notified the user that they were aborted when the abort
+ * call was made in the first place, so the user should not have any
+ * dangling references at this point.
+ *
+ * Otherwise, call the user routine.
+ */
+ if (!ctx->aborted) {
+ ctx->user_prompt_proc(line, ctx->user_context,
+ KeyboardCompletionSuccess);
+ }
- silc_free(ctx);
+ /*
+ * If there's a flag to set on completion, such that we can detect when the
+ * operation finished immediately instead of being processed as a callback,
+ * then set that now.
+ */
+ if (ctx->immediate_completion)
+ *ctx->immediate_completion = TRUE;
+
+ /*
+ * Clean up our internal context structures. Note that we are considered
+ * responsible for handling the SilcAsyncOperation release in this model,
+ * unless we were aborted, in which case the abort request has released it.
+ */
+ if (!ctx->aborted)
+ silc_async_free(ctx->async_context);
- /*
- * Mark us as not having a keyboard prompt pending.
- */
+ silc_free(ctx);
- silc_keyboard_prompt_pending = FALSE;
+ /*
+ * Mark us as not having a keyboard prompt pending.
+ */
+ silc_keyboard_prompt_pending = FALSE;
}
/* Prompt for user input. */
-bool silc_keyboard_entry_redirect(
- SILC_KEYBOARD_PROMPT_PROC prompt_func,
- const char *entry,
- int flags,
- void *data,
- SilcAsyncOperation *async)
+SilcBool silc_keyboard_entry_redirect(SILC_KEYBOARD_PROMPT_PROC prompt_func,
+ const char *entry,
+ int flags,
+ void *data,
+ SilcAsyncOperation *async)
{
- SilcKeyboardEntryRedirectContext ctx;
- bool completed_now;
-
- /*
- * Check if we already have a keyboard prompt pending. This sucks, but
- * irssi stores the keyboard prompt data in a global, and if we request
- * a prompt while there is already a prompt in progress, the old prompt
- * data is leaked. If irssi gets its act together, this can (and should)
- * go away.
- */
-
- if (silc_keyboard_prompt_pending)
- {
- prompt_func(NULL, data, KeyboardCompletionFailed);
- return FALSE;
- }
+ SilcKeyboardEntryRedirectContext ctx;
+ SilcBool completed_now;
+
+ /*
+ * Check if we already have a keyboard prompt pending. This sucks, but
+ * irssi stores the keyboard prompt data in a global, and if we request
+ * a prompt while there is already a prompt in progress, the old prompt
+ * data is leaked. If irssi gets its act together, this can (and should)
+ * go away.
+ */
+ if (silc_keyboard_prompt_pending) {
+ prompt_func(NULL, data, KeyboardCompletionFailed);
+ return FALSE;
+ }
- /*
- * Allocate our context blocks.
- */
+ /*
+ * Allocate our context blocks.
+ */
+ ctx = (SilcKeyboardEntryRedirectContext)silc_calloc(1, sizeof(*ctx));
+ if (!ctx) {
+ prompt_func(NULL, data, KeyboardCompletionFailed);
+ return FALSE;
+ }
- ctx = (SilcKeyboardEntryRedirectContext)silc_calloc(1, sizeof(*ctx));
+ ctx->async_context = silc_async_alloc(silc_keyboard_entry_redirect_abort,
+ NULL, ctx);
+ if (!ctx->async_context) {
+ silc_free(ctx);
+ prompt_func(NULL, data, KeyboardCompletionFailed);
+ return FALSE;
+ }
- if (!ctx)
- {
- prompt_func(NULL, data, KeyboardCompletionFailed);
- return FALSE;
- }
+ /*
+ * Initially, we don't consider ourselves as having finished.
+ */
+ completed_now = FALSE;
- ctx->async_context = silc_async_alloc(silc_keyboard_entry_redirect_abort,
- NULL, ctx);
+ /*
+ * Since irssi can't handle overlapping keyboard prompt requests, block
+ * future requests until we are finished. N.B. This should really be
+ * handled inside of irssi, but this requires a breaking change to how
+ * keyboard callbacks are processed from an API perspective. A problem
+ * exists where another user could call a keyboard redirect request
+ * external to silc while we have one pending, and cause ours to get
+ * lost, in which case we will get stuck denying future prompt requests.
+ *
+ * Fortunately, nobody else seems to use keyboard prompt requests, at least
+ * not that I can tell.
+ */
+ silc_keyboard_prompt_pending = TRUE;
- if (!ctx->async_context)
- {
- silc_free(ctx);
- prompt_func(NULL, data, KeyboardCompletionFailed);
- return FALSE;
- }
+ /*
+ * Set up the call to the irssi keyboard entry redirection facility.
+ */
- /*
- * Initially, we don't consider ourselves as having finished.
- */
-
- completed_now = FALSE;
-
- /*
- * Since irssi can't handle overlapping keyboard prompt requests, block
- * future requests until we are finished. N.B. This should really be
- * handled inside of irssi, but this requires a breaking change to how
- * keyboard callbacks are processed from an API perspective. A problem
- * exists where another user could call a keyboard redirect request
- * external to silc while we have one pending, and cause ours to get
- * lost, in which case we will get stuck denying future prompt requests.
- *
- * Fortunately, nobody else seems to use keyboard prompt requests, at least
- * not that I can tell.
- */
-
- silc_keyboard_prompt_pending = TRUE;
-
- /*
- * Set up the call to the irssi keyboard entry redirection facility.
- */
-
- ctx->user_prompt_proc = prompt_func;
- ctx->user_context = data;
- ctx->aborted = FALSE;
- ctx->immediate_completion = &completed_now;
-
- keyboard_entry_redirect((SIGNAL_FUNC)silc_keyboard_entry_redirect_completion,
- entry, 0, ctx);
-
- ctx->immediate_completion = NULL;
-
- /*
- * If we completed immediately, then there is nothing to return as the async
- * context has already been released. In this case we have completed with a
- * success status, but there is no SilcAsyncOperation context to return.
- */
-
- if (completed_now)
- {
- *async = NULL;
- return TRUE;
- }
+ ctx->user_prompt_proc = prompt_func;
+ ctx->user_context = data;
+ ctx->aborted = FALSE;
+ ctx->immediate_completion = &completed_now;
- /*
- * Otherwise, we must return an async operation context to the caller, and
- * we must unset the immediate_completion flag as we don't want to be
- * notified anymore since we're returning out. Note that this is not safe
- * if keyboard_entry_redirect can call from a different thread, but we are
- * assuming that it doesn't as there's already many other things that seem
- * to make this assumption.
- */
+ keyboard_entry_redirect((SIGNAL_FUNC)silc_keyboard_entry_redirect_completion,
+ entry, 0, ctx);
- *async = ctx->async_context;
+ ctx->immediate_completion = NULL;
+
+ /*
+ * If we completed immediately, then there is nothing to return as the async
+ * context has already been released. In this case we have completed with a
+ * success status, but there is no SilcAsyncOperation context to return.
+ */
+ if (completed_now) {
+ *async = NULL;
+ return TRUE;
+ }
- /*
- * All done. Irssi will invoke the callback on this thread at a later point
- * in time.
- */
+ /*
+ * Otherwise, we must return an async operation context to the caller, and
+ * we must unset the immediate_completion flag as we don't want to be
+ * notified anymore since we're returning out. Note that this is not safe
+ * if keyboard_entry_redirect can call from a different thread, but we are
+ * assuming that it doesn't as there's already many other things that seem
+ * to make this assumption.
+ */
+ *async = ctx->async_context;
- return TRUE;
+ /*
+ * All done. Irssi will invoke the callback on this thread at a later point
+ * in time.
+ */
+ return TRUE;
}
#ifdef SILC_PLUGIN
if ((rec->passphrase == NULL) && (answer) && (*answer != '\0')) {
rec->passphrase = g_strdup(answer);
- /*
- * This can continue to use keyboard_entry_redirect as it's a one-time at
- * initialization function. If create_key_passphrase is used
- * somewhere else, then this needs to be ripped out and changed to use
- * the new, more correct silc_keyboard_entry_redirect.
- */
keyboard_entry_redirect((SIGNAL_FUNC) create_key_passphrase,
format_get_text("fe-common/silc", NULL, NULL,
NULL, SILCTXT_CONFIG_PASS_ASK2),
if (rec->old == NULL) {
rec->old = g_strdup((answer == NULL ? "" : answer));
- /*
- * This can continue to use keyboard_entry_redirect as it's a one-time at
- * initialization function. If change_private_key_passphrase is used
- * somewhere else, then this needs to be ripped out and changed to use
- * the new, more correct silc_keyboard_entry_redirect.
- */
keyboard_entry_redirect((SIGNAL_FUNC) change_private_key_passphrase,
format_get_text("fe-common/silc", NULL, NULL,
NULL, SILCTXT_CONFIG_PASS_ASK2),
if ((rec->passphrase == NULL) && (answer) && (*answer != '\0')) {
rec->passphrase = g_strdup(answer);
- /*
- * This can continue to use keyboard_entry_redirect as it's a one-time at
- * initialization function. If change_private_key_passphrase is used
- * somewhere else, then this needs to be ripped out and changed to use
- * the new, more correct silc_keyboard_entry_redirect.
- */
keyboard_entry_redirect((SIGNAL_FUNC) change_private_key_passphrase,
format_get_text("fe-common/silc", NULL, NULL,
NULL, SILCTXT_CONFIG_PASS_ASK3),
Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
- Copyright (C) 1997 - 2000 Pekka Riikonen
+ Copyright (C) 1997 - 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
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
-
+
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
int silc_client_check_silc_dir();
int silc_client_load_keys(SilcClient client);
-typedef enum
-{
- KeyboardCompletionSuccess, /* Success; keyboard data returned to callback. */
- KeyboardCompletionAborted, /* Operation was aborted after starting successfully. */
- KeyboardCompletionFailed /* Operation was not started successfully. */
+typedef enum {
+ KeyboardCompletionSuccess, /* Success; keyboard data returned to callback. */
+ KeyboardCompletionAborted, /* Operation was aborted after starting successfully. */
+ KeyboardCompletionFailed /* Operation was not started successfully. */
} SilcKeyboardPromptStatus;
-typedef void (*SILC_KEYBOARD_PROMPT_PROC)(
- const char *line,
- void *context,
- SilcKeyboardPromptStatus reason);
+typedef void (*SILC_KEYBOARD_PROMPT_PROC)(const char *line,
+ void *context,
+ SilcKeyboardPromptStatus reason);
/*
* Prompt for keyboard input.
* keyboard redirect operation is aborted while we are still waiting for data,
* then we abort all callbacks until that callback returns.
*/
-bool silc_keyboard_entry_redirect(
- SILC_KEYBOARD_PROMPT_PROC prompt_func,
- const char *entry,
- int flags,
- void *data,
- SilcAsyncOperation *async);
+SilcBool silc_keyboard_entry_redirect(SILC_KEYBOARD_PROMPT_PROC prompt_func,
+ const char *entry,
+ int flags,
+ void *data,
+ SilcAsyncOperation *async);
#ifdef SILC_PLUGIN
typedef struct {
Author: Pekka Riikonen <priikone@silcnet.org>
- Copyright (C) 2002 - 2007 Pekka Riikonen
+ Copyright (C) 2002 - 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
#include "fe-common/core/keyboard.h"
#include "fe-common/silc/module-formats.h"
-static void silc_query_attributes_print_final(bool success, void *context);
+static void silc_query_attributes_print_final(SilcBool success, void *context);
static void silc_query_attributes_accept(const char *line, void *context,
SilcKeyboardPromptStatus reason);
SilcUInt32 argc;
SilcUInt32 *argv_lens, *argv_types;
const char *sv;
- bool allowed;
+ SilcBool allowed;
/* Now parse all arguments */
tmp = g_strconcat("ATTR", " ", data, NULL);
SilcAttributeObjDevice dev;
SilcAttributeObjPk pk;
SilcVCardStruct vcard;
- bool allowed;
+ SilcBool allowed;
memset(&service, 0, sizeof(service));
memset(&geo, 0, sizeof(geo));
SilcVCardStruct vcard;
SilcMime message;
SilcMime extension;
- bool nopk;
- bool autoaccept;
+ SilcBool nopk;
+ SilcBool autoaccept;
} *AttrVerify;
void silc_query_attributes_print(SILC_SERVER_REC *server,
}
}
-static void silc_query_attributes_print_final(bool success, void *context)
+static void silc_query_attributes_print_final(SilcBool success, void *context)
{
AttrVerify verify = context;
SILC_SERVER_REC *server = verify->server;
format, 0, verify, &server->prompt_op);
} else {
/* Save new data to existing directory */
- verify->autoaccept = TRUE; /* Ensure we don't twiddle the async context */
+ verify->autoaccept = TRUE; /* Ensure we don't twiddle the async context */
silc_query_attributes_accept("Y", verify, KeyboardCompletionSuccess);
}
unsigned char filename[256], filename2[256], *fingerprint = NULL, *tmp;
SilcUInt32 len;
int i;
- bool success = (reason == KeyboardCompletionSuccess);
+ SilcBool success = (reason == KeyboardCompletionSuccess);
if (success && (line[0] == 'Y' || line[0] == 'y')) {
/* Save the attributes */
/*
silc-server.c : irssi
- Copyright (C) 2000 - 2007 Timo Sirainen
+ Copyright (C) 2000 - 2008 Timo Sirainen
Pekka Riikonen <priikone@silcnet.org>
This program is free software; you can redistribute it and/or modify
params.timeout_secs = settings_get_int("key_exchange_timeout_secs");
params.rekey_secs = settings_get_int("key_exchange_rekey_secs");
params.pfs = settings_get_bool("key_exchange_rekey_pfs");
+ params.context = server;
/* Try to read detached session data and use it if found. */
file = silc_get_session_filename(server);
SILCTXT_REATTACH, server->tag);
silc_free(file);
- /*
- * Store the SILC_SERVER_REC in the stream context so that we can fetch it
- * from the verify key exchange prompt. There should have been an initial
- * user parameter value for the SilcClientConnection that could have been
- * passed to SilcClientConnectionParams, but because there's no version
- * number or size field in SilcClientConnectionParams, it is fixed for all
- * time and not extendable.
- *
- * Instead, we must revert to pulling the SilcStream out of the
- * SilcPacketStream associated with the SilcClientConnection object in the
- * verify key exchange prompt callback in order to get our per-connection
- * context. Hence, the extra levels of indirection.
- */
-
- silc_socket_stream_set_context(stream, server);
-
/* Start key exchange */
server->op = silc_client_key_exchange(silc_client, ¶ms,
irssi_pubkey, irssi_privkey,
/* If we have a prompt in progress, then abort it. */
if (server->prompt_op) {
silc_async_abort(server->prompt_op, NULL, NULL);
- server->prompt_op = NULL;
+ server->prompt_op = NULL;
}
if (server->conn) {
#include "serverincludes.h"
#include "server_internal.h"
-#include <assert.h>
/* Received notify packet. Server can receive notify packets from router.
Server then relays the notify messages to clients if needed. */
tmp_len = 128;
/* Update statistics */
- assert(server->stat.clients > 0);
+ SILC_VERIFY(server->stat.clients > 0);
server->stat.clients--;
if (server->stat.cell_clients)
server->stat.cell_clients--;
}
/* Update statistics */
- assert(server->stat.clients > 0);
+ SILC_VERIFY(server->stat.clients > 0);
server->stat.clients--;
if (server->stat.cell_clients)
server->stat.cell_clients--;
}
/* Update statistics */
- assert(server->stat.clients > 0);
+ SILC_VERIFY(server->stat.clients > 0);
server->stat.clients--;
if (server->stat.cell_clients)
server->stat.cell_clients--;
/* Delete this current client entry since we're resuming to old one. */
server->stat.my_clients--;
- assert(server->stat.clients > 0);
+ SILC_VERIFY(server->stat.clients > 0);
server->stat.clients--;
if (server->stat.cell_clients)
server->stat.cell_clients--;
#include "serverincludes.h"
#include "server_internal.h"
-#include <assert.h>
/************************* Types and definitions ****************************/
SilcNetListener listener;
SilcUInt16 *port;
char **ip;
- char *external_ip;
SILC_LOG_DEBUG(("Initializing server"));
/* Create a Server ID for the server. */
port = silc_net_listener_get_port(listener, NULL);
ip = silc_net_listener_get_ip(listener, NULL);
- external_ip = server->config->server_info->external_ip ?
- server->config->server_info->external_ip :
- server->config->server_info->primary->public_ip;
- silc_id_create_server_id(external_ip ?
- external_ip :
+ silc_id_create_server_id(server->config->server_info->primary->public_ip ?
+ server->config->server_info->primary->public_ip :
ip[0], port[0], server->rng, &id);
if (!id)
goto err;
/* Update statistics */
server->stat.my_clients--;
- assert(server->stat.clients > 0);
+ SILC_VERIFY(server->stat.clients > 0);
server->stat.clients--;
if (server->stat.cell_clients)
server->stat.cell_clients--;
#include "serverincludes.h"
#include "server_internal.h"
-#include <assert.h>
extern char *server_version;
silc_hash_table_add(channels, channel, channel);
}
silc_hash_table_list_reset(&htl);
- assert(!silc_hash_table_count(client->channels));
+ SILC_VERIFY(!silc_hash_table_count(client->channels));
}
/* This function removes all client entries that are originated from
}
/* Update statistics */
- assert(server->stat.clients > 0);
+ SILC_VERIFY(server->stat.clients > 0);
server->stat.clients--;
if (server->stat.cell_clients)
server->stat.cell_clients--;
}
/* Update statistics */
- assert(server->stat.clients > 0);
+ SILC_VERIFY(server->stat.clients > 0);
server->stat.clients--;
if (server->stat.cell_clients)
server->stat.cell_clients--;
}
} else {
/* Update statistics */
- assert(server->stat.clients > 0);
+ SILC_VERIFY(server->stat.clients > 0);
server->stat.clients--;
if (server->stat.cell_clients)
server->stat.cell_clients--;
CONFIG_IS_DOUBLE(server_info->server_type);
server_info->server_type = strdup((char *) val);
}
- else if (!strcmp(name, "externalip")) {
- CONFIG_IS_DOUBLE(server_info->external_ip);
- server_info->external_ip = strdup((char *) val);
- }
else if (!strcmp(name, "admin")) {
CONFIG_IS_DOUBLE(server_info->admin);
server_info->admin = strdup((char *) val);
{ "primary", SILC_CONFIG_ARG_BLOCK, fetch_serverinfo, table_serverinfo_c},
{ "secondary", SILC_CONFIG_ARG_BLOCK, fetch_serverinfo, table_serverinfo_c},
{ "servertype", SILC_CONFIG_ARG_STR, fetch_serverinfo, NULL},
- { "externalip", SILC_CONFIG_ARG_STR, fetch_serverinfo, NULL},
{ "location", SILC_CONFIG_ARG_STR, fetch_serverinfo, NULL},
{ "admin", SILC_CONFIG_ARG_STR, fetch_serverinfo, NULL},
{ "adminemail", SILC_CONFIG_ARG_STR, fetch_serverinfo, NULL},
silc_free(di);
}
silc_free(si->server_type);
- silc_free(si->external_ip);
silc_free(si->location);
silc_free(si->admin);
silc_free(si->email);
char *server_name;
SilcServerConfigServerInfoInterface *primary;
SilcServerConfigServerInfoInterface *secondary;
- char *external_ip; /* E.g. public IP if we're in a NAT */
char *server_type; /* E.g. "Test Server" */
char *location; /* geographic location */
char *admin; /* admin full name */
LIBSILC_AGE=1 # prev = 1
# libsilcclient versions
-LIBSILCCLIENT_CURRENT=2 # prev = 1
-LIBSILCCLIENT_REVISION=1 # prev = 1
+LIBSILCCLIENT_CURRENT=3 # prev = 2
+LIBSILCCLIENT_REVISION=0 # prev = 1
LIBSILCCLIENT_AGE=0 # prev = 0
# libsilcserver versions
Author: Pekka Riikonen <priikone@silcnet.org>
- Copyright (C) 1997 - 2007 Pekka Riikonen
+ Copyright (C) 1997 - 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
}
/* Set parameters */
- if (params)
+ if (params) {
conn->internal->params = *params;
+ conn->context = params->context;
+ }
if (!conn->internal->params.rekey_secs)
conn->internal->params.rekey_secs = 3600;
#ifndef SILC_DIST_INPLACE
SilcRwLock lock; /* Read/write lock */
SilcUInt16 resolve_cmd_ident; /* Resolving identifier */
SilcAtomic32 refcnt; /* Reference counter */
- SilcAtomic32 deleted; /* Flag indicating whether the server object is
- already scheduled for deletion.*/
+ SilcAtomic32 deleted; /* Flag indicating whether the
+ server object is already
+ scheduled for deletion. */
} SilcServerEntryInternal;
#endif /* CLIENT_H */
Author: Pekka Riikonen <priikone@silcnet.org>
- Copyright (C) 2001 - 2007 Pekka Riikonen
+ Copyright (C) 2001 - 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
NULL, NULL, NULL, TRUE);
if (!client_entry->channels) {
silc_free(client_entry->realname);
- silc_atomic_uninit32(&client_entry->internal.deleted);
- silc_atomic_uninit32(&client_entry->internal.refcnt);
- silc_rwlock_free(client_entry->internal.lock);
+ silc_atomic_uninit32(&client_entry->internal.deleted);
+ silc_atomic_uninit32(&client_entry->internal.refcnt);
+ silc_rwlock_free(client_entry->internal.lock);
silc_free(client_entry);
return NULL;
}
if (!nick) {
silc_hash_table_free(client_entry->channels);
silc_free(client_entry->realname);
- silc_atomic_uninit32(&client_entry->internal.deleted);
- silc_atomic_uninit32(&client_entry->internal.refcnt);
- silc_rwlock_free(client_entry->internal.lock);
+ silc_atomic_uninit32(&client_entry->internal.deleted);
+ silc_atomic_uninit32(&client_entry->internal.refcnt);
+ silc_rwlock_free(client_entry->internal.lock);
silc_free(client_entry);
return NULL;
}
silc_free(nick);
silc_hash_table_free(client_entry->channels);
silc_free(client_entry->realname);
- silc_atomic_uninit32(&client_entry->internal.deleted);
- silc_atomic_uninit32(&client_entry->internal.refcnt);
- silc_rwlock_free(client_entry->internal.lock);
+ silc_atomic_uninit32(&client_entry->internal.deleted);
+ silc_atomic_uninit32(&client_entry->internal.refcnt);
+ silc_rwlock_free(client_entry->internal.lock);
silc_free(client_entry);
silc_mutex_unlock(conn->internal->lock);
return NULL;
if (!channel->channel_name) {
silc_rwlock_free(channel->internal.lock);
silc_atomic_uninit32(&channel->internal.refcnt);
- silc_atomic_uninit32(&channel->internal.deleted);
+ silc_atomic_uninit32(&channel->internal.deleted);
silc_free(channel);
return NULL;
}
if (!channel->user_list) {
silc_rwlock_free(channel->internal.lock);
silc_atomic_uninit32(&channel->internal.refcnt);
- silc_atomic_uninit32(&channel->internal.deleted);
+ silc_atomic_uninit32(&channel->internal.deleted);
silc_free(channel->channel_name);
silc_free(channel);
return NULL;
if (!channel_namec) {
silc_rwlock_free(channel->internal.lock);
silc_atomic_uninit32(&channel->internal.refcnt);
- silc_atomic_uninit32(&channel->internal.deleted);
+ silc_atomic_uninit32(&channel->internal.deleted);
silc_free(channel->channel_name);
silc_hash_table_free(channel->user_list);
silc_free(channel);
&channel->id, channel)) {
silc_rwlock_free(channel->internal.lock);
silc_atomic_uninit32(&channel->internal.refcnt);
- silc_atomic_uninit32(&channel->internal.deleted);
+ silc_atomic_uninit32(&channel->internal.deleted);
silc_free(channel_namec);
silc_free(channel->channel_name);
silc_hash_table_free(channel->user_list);
return FALSE;
if (silc_atomic_sub_int32(&server->internal.deleted, 1) != 0)
- {
- SILC_LOG_DEBUG(("** WARNING ** Deleting a server twice %p", server));
-// asm("int3");
- return FALSE;
- }
+ return FALSE;
silc_client_unref_server(client, conn, server);
return TRUE;
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_client_attribute_add for more information on attributes. */
SilcBool ignore_requested_attributes;
+ /* User context for SilcClientConnection. If non-NULL this context is
+ set to the 'context' field in SilcClientConnection when the connection
+ context is created. */
+ void *context;
} SilcClientConnectionParams;
/***/
#include "silc.h"
#include "silcserver.h"
#include "server_internal.h"
-#include <assert.h>
/* Return next available command identifier. */
const unsigned char *data,
SilcUInt32 data_len);
-static void silc_ske_notify_failure(SilcSKE ske);
+/*
+ * Notify the owner of the ske that we failed. Ensures that we don't make the
+ * same callout twice, as the notification callback routines are not designed
+ * to handle that case.
+ */
+static void silc_ske_notify_failure(SilcSKE ske)
+{
+ SILC_LOG_DEBUG(("Notifying SKE %p owner of failure (failure_notified = %lu)",
+ ske, ske->failure_notified));
+
+ /*
+ * First, check if we have already made a failure callout. If so, then we
+ * will stop here.
+ */
+ if (ske->failure_notified)
+ return;
+
+ /*
+ * Mark ourselves as having already sent the failure notification here and
+ * now.
+ */
+ ske->failure_notified = TRUE;
+
+ SILC_LOG_DEBUG(("Deliver failure notification for SKE %p (%s)",
+ ske, ske->responder ? "responder" : "initiator"));
+
+ /*
+ * Finally, make the call to the owner's registered failure callback.
+ */
+ if (ske->responder)
+ silc_fsm_next(&ske->fsm, silc_ske_st_responder_failure);
+ else
+ silc_fsm_next(&ske->fsm, silc_ske_st_initiator_failure);
+}
+
/* Packet callback */
static SilcBool silc_ske_packet_receive(SilcPacketEngine engine,
}
/* See if received failure from remote */
- if (packet->type == SILC_PACKET_FAILURE) {
+ if (packet->type == SILC_PACKET_FAILURE)
silc_ske_notify_failure(ske);
- }
/* Handle rekey and SUCCESS packets synchronously. After SUCCESS packets
they keys are taken into use immediately, hence the synchronous
void *destructor_context)
{
SilcSKE ske = fsm_context;
- ske->fsm_finished = TRUE;
- silc_ske_free(ske);
+ silc_ske_free(ske);
}
/* Key exchange timeout task callback */
if (!ske)
return;
- SILC_LOG_DEBUG(("Freeing Key Exchange object %p: aborted=%u refcount=%hu", ske, ske->aborted, ske->refcnt));
-
- if (ske->aborted) {
- /*
- * If already aborted, destroy the session immediately. Only do the
- * notification work if we have not already though, as doing so twice
- * results in memory corruption. We may have silc_ske_free called
- * twice, once when the abort is requested, and then again when the
- * FSM finish routine is called. We have to be prepared to handle
- * that case.
- */
+ SILC_LOG_DEBUG(("Freeing Key Exchange object %p: aborted=%u refcount=%hu",
+ ske, ske->aborted, ske->refcnt));
- ske->packet = NULL;
- ske->status = SILC_SKE_STATUS_ERROR;
+ if (ske->aborted) {
+ /*
+ * If already aborted, destroy the session immediately. Only do the
+ * notification work if we have not already though, as doing so twice
+ * results in memory corruption. We may have silc_ske_free called
+ * twice, once when the abort is requested, and then again when the
+ * FSM finish routine is called. We have to be prepared to handle
+ * that case.
+ */
+ ske->packet = NULL;
+ ske->status = SILC_SKE_STATUS_ERROR;
- silc_ske_notify_failure(ske);
+ silc_ske_notify_failure(ske);
- if (!ske->fsm_finished)
- silc_fsm_continue_sync(&ske->fsm);
- else
- SILC_LOG_DEBUG(("Not continuing FSM as it's finished for SKE %p", ske));
- }
+ if (silc_fsm_is_started(&ske->fsm))
+ silc_fsm_continue_sync(&ske->fsm);
+ else
+ SILC_LOG_DEBUG(("Not continuing FSM as it's finished for SKE %p", ske));
+ }
ske->refcnt--;
if (ske->refcnt > 0)
SilcSKEParams params,
SilcSKEStartPayload start_payload)
{
- SILC_LOG_DEBUG(("Start SKE %p as initiator; stream=%p; params=%p; start_payload=%p", ske, stream, params, start_payload));
+ SILC_LOG_DEBUG(("Start SKE %p as initiator; stream=%p; params=%p; "
+ "start_payload=%p", ske, stream, params, start_payload));
if (!ske || !stream || !params || !params->version)
return NULL;
{
return ske->keymat;
}
-
-/*
- * Notify the owner of the ske that we failed. Ensures that we don't make the
- * same callout twice, as the notification callback routines are not designed
- * to handle that case.
- */
-static void silc_ske_notify_failure(SilcSKE ske)
-{
- SILC_LOG_DEBUG(("Notifying SKE %p owner of failure (failure_notified = %lu)", ske, ske->failure_notified));
-
- /*
- * First, check if we have already made a failure callout. If so, then we
- * will stop here.
- */
-
- if (ske->failure_notified)
- return;
-
- /*
- * Mark ourselves as having already sent the failure notification here and
- * now.
- */
-
- ske->failure_notified = TRUE;
-
- SILC_LOG_DEBUG(("Actually calling real failure notify callback for SKE %p (responder = %s)", ske, ske->responder ? "TRUE" : "FALSE"));
-
- /*
- * Finally, make the call to the owner's registered failure callback.
- */
-
- if (ske->responder)
- silc_fsm_next(&ske->fsm, silc_ske_st_responder_failure);
- else
- silc_fsm_next(&ske->fsm, silc_ske_st_initiator_failure);
-}
-
Author: Pekka Riikonen <priikone@silcnet.org>
- Copyright (C) 2005 - 2007 Pekka Riikonen
+ Copyright (C) 2005 - 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
SilcUInt16 timeout; /* SKE timeout */
SilcUInt16 refcnt; /* Reference counter */
- unsigned int aborted : 1; /* Set when SKE aborted */
- unsigned int responder : 1; /* Set when we are responder side */
- unsigned int rekeying : 1; /* Set when rekeying */
- unsigned int failure_notified : 1; /* Set to indicate that we already called the failure notify routine */
- unsigned int fsm_finished : 1; /* Set when we're in FSM teardown */
+ unsigned int aborted : 1; /* Set when SKE aborted */
+ unsigned int responder : 1; /* Set when we are responder side */
+ unsigned int rekeying : 1; /* Set when rekeying */
+ unsigned int failure_notified : 1; /* Set to indicate that we already called
+ the failure notify routine */
};
#endif /* SILCSKE_I_H */
return socket_stream->schedule;
}
-/* Return associated context. */
-
-void *
-silc_socket_stream_get_context(SilcStream stream)
-{
- SilcSocketStream socket_stream = stream;
-
- if (!SILC_IS_SOCKET_STREAM(socket_stream))
- return NULL;
-
- return socket_stream->user_context;
-}
-
-/* Set associated context. */
-
-void
-silc_socket_stream_set_context(SilcStream stream,
- void *context)
-{
- SilcSocketStream socket_stream = stream;
-
- if (!SILC_IS_SOCKET_STREAM(socket_stream))
- return;
-
- socket_stream->user_context = context;
-}
-
/* SILC Socket Stream ops. Functions are implemented under the
platform specific subdirectories. */
const SilcStreamOps silc_socket_stream_ops =
SilcUInt32 limit_sec,
SilcUInt32 limit_usec);
-
-/****f* silcutil/SilcSocketStreamAPI/silc_socket_stream_get_context
- *
- * SYNOPSIS
- *
- * void *
- * silc_socket_stream_get_context(SilcSocketStream stream);
- *
- * DESCRIPTION
- *
- * Returns the context associated with a stream. This context is
- * set via silc_socket_stream_set_context.
- *
- ***/
-void *
-silc_socket_stream_get_context(SilcStream stream);
-
-/****f* silcutil/SilcSocketStreamAPI/silc_socket_stream_set_context
- *
- * SYNOPSIS
- *
- * void
- * silc_socket_stream_set_context(SilcSocketStream stream,
- * void *context);
- *
- * DESCRIPTION
- *
- * Returns the context associated with a stream. This context is
- * set via silc_socket_stream_set_context.
- *
- ***/
-void
-silc_socket_stream_set_context(SilcStream stream,
- void *context);
-
#include "silcsocketstream_i.h"
#endif /* SILCSOCKETSTREAM_H */
SilcSocketQos qos;
SilcStreamNotifier notifier;
void *notifier_context;
- void *user_context;
unsigned int ipv6 : 1; /* UDP IPv6 */
unsigned int connected : 1; /* UDP connected state */
};