dovecot-2.2: lib-sasl: Use dsasl_ prefix so we don't conflict wi...
dovecot at dovecot.org
dovecot at dovecot.org
Wed Jun 26 14:38:11 EEST 2013
details: http://hg.dovecot.org/dovecot-2.2/rev/2dd27b0e7e49
changeset: 16555:2dd27b0e7e49
user: Timo Sirainen <tss at iki.fi>
date: Wed Jun 26 14:37:34 2013 +0300
description:
lib-sasl: Use dsasl_ prefix so we don't conflict with Cyrus SASL library.
diffstat:
src/imap-login/imap-proxy.c | 20 +++---
src/lib-sasl/Makefile.am | 6 +-
src/lib-sasl/dsasl-client-private.h | 33 ++++++++++
src/lib-sasl/dsasl-client.c | 104 ++++++++++++++++++++++++++++++++++
src/lib-sasl/dsasl-client.h | 39 ++++++++++++
src/lib-sasl/mech-login.c | 20 +++--
src/lib-sasl/mech-plain.c | 20 +++--
src/lib-sasl/sasl-client-private.h | 33 ----------
src/lib-sasl/sasl-client.c | 104 ----------------------------------
src/lib-sasl/sasl-client.h | 39 ------------
src/login-common/client-common-auth.c | 10 +-
src/login-common/client-common.c | 4 +-
src/login-common/client-common.h | 4 +-
src/login-common/main.c | 6 +-
src/pop3-login/pop3-proxy.c | 20 +++---
15 files changed, 233 insertions(+), 229 deletions(-)
diffs (truncated from 736 to 300 lines):
diff -r d6b18c237be5 -r 2dd27b0e7e49 src/imap-login/imap-proxy.c
--- a/src/imap-login/imap-proxy.c Tue Jun 25 16:03:04 2013 +0300
+++ b/src/imap-login/imap-proxy.c Wed Jun 26 14:37:34 2013 +0300
@@ -9,7 +9,7 @@
#include "str.h"
#include "str-sanitize.h"
#include "safe-memset.h"
-#include "sasl-client.h"
+#include "dsasl-client.h"
#include "client.h"
#include "client-authenticate.h"
#include "imap-resp-code.h"
@@ -58,7 +58,7 @@
static int proxy_write_login(struct imap_client *client, string_t *str)
{
- struct sasl_client_settings sasl_set;
+ struct dsasl_client_settings sasl_set;
const unsigned char *output;
unsigned int len;
const char *mech_name, *error;
@@ -85,14 +85,14 @@
sasl_set.authzid = client->common.proxy_user;
sasl_set.password = client->common.proxy_password;
client->common.proxy_sasl_client =
- sasl_client_new(client->common.proxy_mech, &sasl_set);
- mech_name = sasl_client_mech_get_name(client->common.proxy_mech);
+ dsasl_client_new(client->common.proxy_mech, &sasl_set);
+ mech_name = dsasl_client_mech_get_name(client->common.proxy_mech);
str_append(str, "L AUTHENTICATE ");
str_append(str, mech_name);
if (client->proxy_sasl_ir) {
- if (sasl_client_output(client->common.proxy_sasl_client,
- &output, &len, &error) < 0) {
+ if (dsasl_client_output(client->common.proxy_sasl_client,
+ &output, &len, &error) < 0) {
client_log_err(&client->common, t_strdup_printf(
"proxy: SASL mechanism %s init failed: %s",
mech_name, error));
@@ -226,11 +226,11 @@
client_proxy_failed(client, TRUE);
return -1;
}
- ret = sasl_client_input(client->proxy_sasl_client,
- str_data(str), str_len(str), &error);
+ ret = dsasl_client_input(client->proxy_sasl_client,
+ str_data(str), str_len(str), &error);
if (ret == 0) {
- ret = sasl_client_output(client->proxy_sasl_client,
- &data, &data_len, &error);
+ ret = dsasl_client_output(client->proxy_sasl_client,
+ &data, &data_len, &error);
}
if (ret < 0) {
client_log_err(client, t_strdup_printf(
diff -r d6b18c237be5 -r 2dd27b0e7e49 src/lib-sasl/Makefile.am
--- a/src/lib-sasl/Makefile.am Tue Jun 25 16:03:04 2013 +0300
+++ b/src/lib-sasl/Makefile.am Wed Jun 26 14:37:34 2013 +0300
@@ -6,11 +6,11 @@
libsasl_la_SOURCES = \
mech-login.c \
mech-plain.c \
- sasl-client.c
+ dsasl-client.c
headers = \
- sasl-client.h \
- sasl-client-private.h
+ dsasl-client.h \
+ dsasl-client-private.h
pkginc_libdir=$(pkgincludedir)
pkginc_lib_HEADERS = $(headers)
diff -r d6b18c237be5 -r 2dd27b0e7e49 src/lib-sasl/dsasl-client-private.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/lib-sasl/dsasl-client-private.h Wed Jun 26 14:37:34 2013 +0300
@@ -0,0 +1,33 @@
+#ifndef DSASL_CLIENT_PRIVATE_H
+#define DSASL_CLIENT_PRIVATE_H
+
+#include "dsasl-client.h"
+
+struct dsasl_client {
+ pool_t pool;
+ struct dsasl_client_settings set;
+ char *password;
+ const struct dsasl_client_mech *mech;
+};
+
+struct dsasl_client_mech {
+ const char *name;
+ size_t struct_size;
+
+ int (*input)(struct dsasl_client *client,
+ const unsigned char *input,
+ unsigned int input_len,
+ const char **error_r);
+ int (*output)(struct dsasl_client *client,
+ const unsigned char **output_r,
+ unsigned int *output_len_r,
+ const char **error_r);
+ void (*free)(struct dsasl_client *client);
+};
+
+extern const struct dsasl_client_mech dsasl_client_mech_login;
+
+void dsasl_client_mech_register(const struct dsasl_client_mech *mech);
+void dsasl_client_mech_unregister(const struct dsasl_client_mech *mech);
+
+#endif
diff -r d6b18c237be5 -r 2dd27b0e7e49 src/lib-sasl/dsasl-client.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/lib-sasl/dsasl-client.c Wed Jun 26 14:37:34 2013 +0300
@@ -0,0 +1,104 @@
+/* Copyright (c) 2013 Dovecot authors, see the included COPYING file */
+
+#include "lib.h"
+#include "array.h"
+#include "safe-memset.h"
+#include "dsasl-client-private.h"
+
+static ARRAY(const struct dsasl_client_mech *) dsasl_mechanisms = ARRAY_INIT;
+
+static const struct dsasl_client_mech *
+dsasl_client_mech_find_idx(const char *name, unsigned int *idx_r)
+{
+ const struct dsasl_client_mech *const *mechp;
+
+ array_foreach(&dsasl_mechanisms, mechp) {
+ if (strcasecmp((*mechp)->name, name) == 0) {
+ *idx_r = array_foreach_idx(&dsasl_mechanisms, mechp);
+ return *mechp;
+ }
+ }
+ return NULL;
+}
+
+const struct dsasl_client_mech *dsasl_client_mech_find(const char *name)
+{
+ unsigned int idx;
+
+ return dsasl_client_mech_find_idx(name, &idx);
+}
+
+const char *dsasl_client_mech_get_name(const struct dsasl_client_mech *mech)
+{
+ return mech->name;
+}
+
+void dsasl_client_mech_register(const struct dsasl_client_mech *mech)
+{
+ array_append(&dsasl_mechanisms, &mech, 1);
+}
+
+void dsasl_client_mech_unregister(const struct dsasl_client_mech *mech)
+{
+ unsigned int idx;
+
+ if (dsasl_client_mech_find_idx(mech->name, &idx) == NULL)
+ i_panic("SASL mechanism not registered: %s", mech->name);
+ array_delete(&dsasl_mechanisms, idx, 1);
+}
+
+struct dsasl_client *dsasl_client_new(const struct dsasl_client_mech *mech,
+ const struct dsasl_client_settings *set)
+{
+ struct dsasl_client *client;
+ pool_t pool = pool_alloconly_create("sasl client", 512);
+
+ client = p_malloc(pool, mech->struct_size);
+ client->pool = pool;
+ client->mech = mech;
+ client->set.authid = p_strdup(pool, set->authid);
+ client->set.authzid = p_strdup(pool, set->authzid);
+ client->password = p_strdup(pool, set->password);
+ client->set.password = client->password;
+ return client;
+}
+
+void dsasl_client_free(struct dsasl_client **_client)
+{
+ struct dsasl_client *client = *_client;
+
+ *_client = NULL;
+
+ if (client->mech->free != NULL)
+ client->mech->free(client);
+ safe_memset(client->password, 0, strlen(client->password));
+ pool_unref(&client->pool);
+}
+
+int dsasl_client_input(struct dsasl_client *client,
+ const unsigned char *input,
+ unsigned int input_len,
+ const char **error_r)
+{
+ return client->mech->input(client, input, input_len, error_r);
+}
+
+int dsasl_client_output(struct dsasl_client *client,
+ const unsigned char **output_r,
+ unsigned int *output_len_r,
+ const char **error_r)
+{
+ return client->mech->output(client, output_r, output_len_r, error_r);
+}
+
+void dsasl_clients_init(void)
+{
+ i_array_init(&dsasl_mechanisms, 8);
+ dsasl_client_mech_register(&dsasl_client_mech_plain);
+ dsasl_client_mech_register(&dsasl_client_mech_login);
+}
+
+void dsasl_clients_deinit(void)
+{
+ array_free(&dsasl_mechanisms);
+}
diff -r d6b18c237be5 -r 2dd27b0e7e49 src/lib-sasl/dsasl-client.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/lib-sasl/dsasl-client.h Wed Jun 26 14:37:34 2013 +0300
@@ -0,0 +1,39 @@
+#ifndef DSASL_CLIENT_H
+#define DSASL_CLIENT_H
+
+struct dsasl_client_settings {
+ /* authentication ID - must be set with most mechanisms */
+ const char *authid;
+ /* authorization ID (who to log in as, if authentication ID is a
+ master user) */
+ const char *authzid;
+ /* password - must be set with most mechanisms */
+ const char *password;
+};
+
+/* PLAIN mechanism always exists and can be accessed directly via this. */
+extern const struct dsasl_client_mech dsasl_client_mech_plain;
+
+const struct dsasl_client_mech *dsasl_client_mech_find(const char *name);
+const char *dsasl_client_mech_get_name(const struct dsasl_client_mech *mech);
+
+struct dsasl_client *dsasl_client_new(const struct dsasl_client_mech *mech,
+ const struct dsasl_client_settings *set);
+void dsasl_client_free(struct dsasl_client **client);
+
+/* Call for server input. */
+int dsasl_client_input(struct dsasl_client *client,
+ const unsigned char *input,
+ unsigned int input_len,
+ const char **error_r);
+/* Call for getting server output. Also used to get the initial SASL response
+ if supported by the protocol. */
+int dsasl_client_output(struct dsasl_client *client,
+ const unsigned char **output_r,
+ unsigned int *output_len_r,
+ const char **error_r);
+
+void dsasl_clients_init(void);
+void dsasl_clients_deinit(void);
+
+#endif
diff -r d6b18c237be5 -r 2dd27b0e7e49 src/lib-sasl/mech-login.c
--- a/src/lib-sasl/mech-login.c Tue Jun 25 16:03:04 2013 +0300
+++ b/src/lib-sasl/mech-login.c Wed Jun 26 14:37:34 2013 +0300
@@ -2,7 +2,7 @@
#include "lib.h"
#include "str.h"
-#include "sasl-client-private.h"
+#include "dsasl-client-private.h"
enum login_state {
STATE_INIT = 0,
@@ -10,18 +10,19 @@
STATE_PASS
};
-struct login_sasl_client {
- struct sasl_client client;
+struct login_dsasl_client {
+ struct dsasl_client client;
enum login_state state;
};
static int
-mech_login_input(struct sasl_client *_client,
+mech_login_input(struct dsasl_client *_client,
const unsigned char *input ATTR_UNUSED,
unsigned int input_len ATTR_UNUSED,
const char **error_r)
{
- struct login_sasl_client *client = (struct login_sasl_client *)_client;
+ struct login_dsasl_client *client =
+ (struct login_dsasl_client *)_client;
if (client->state == STATE_PASS) {
*error_r = "Server didn't finish authentication";
@@ -32,11 +33,12 @@
}
More information about the dovecot-cvs
mailing list