dovecot-2.2: auth: Code cleanup: Renamed auth-stream to auth-fie...
dovecot at dovecot.org
dovecot at dovecot.org
Wed Jan 30 22:17:28 EET 2013
details: http://hg.dovecot.org/dovecot-2.2/rev/17f5257d60c1
changeset: 15685:17f5257d60c1
user: Timo Sirainen <tss at iki.fi>
date: Wed Jan 30 19:57:20 2013 +0200
description:
auth: Code cleanup: Renamed auth-stream to auth-fields.
diffstat:
src/auth/Makefile.am | 4 +-
src/auth/auth-client-connection.c | 2 +-
src/auth/auth-fields.c | 147 ++++++++++++++++++++++++++++++++++++
src/auth/auth-fields.h | 34 ++++++++
src/auth/auth-master-connection.c | 16 +-
src/auth/auth-postfix-connection.c | 3 +-
src/auth/auth-request-handler.c | 20 ++--
src/auth/auth-request.c | 85 ++++++++++----------
src/auth/auth-request.h | 4 +-
src/auth/auth-stream.c | 149 -------------------------------------
src/auth/auth-stream.h | 36 --------
src/auth/auth-worker-client.c | 10 +-
src/auth/db-checkpassword.c | 8 +-
src/auth/passdb-blocking.c | 6 +-
src/auth/userdb-blocking.c | 6 +-
src/auth/userdb.h | 2 +-
16 files changed, 261 insertions(+), 271 deletions(-)
diffs (truncated from 944 to 300 lines):
diff -r cc4472f02f70 -r 17f5257d60c1 src/auth/Makefile.am
--- a/src/auth/Makefile.am Wed Jan 30 19:46:58 2013 +0200
+++ b/src/auth/Makefile.am Wed Jan 30 19:57:20 2013 +0200
@@ -71,7 +71,7 @@
auth-request.c \
auth-request-handler.c \
auth-settings.c \
- auth-stream.c \
+ auth-fields.c \
auth-token.c \
auth-worker-client.c \
auth-worker-server.c \
@@ -138,7 +138,7 @@
auth-request.h \
auth-request-handler.h \
auth-settings.h \
- auth-stream.h \
+ auth-fields.h \
auth-token.h \
auth-worker-client.h \
auth-worker-server.h \
diff -r cc4472f02f70 -r 17f5257d60c1 src/auth/auth-client-connection.c
--- a/src/auth/auth-client-connection.c Wed Jan 30 19:46:58 2013 +0200
+++ b/src/auth/auth-client-connection.c Wed Jan 30 19:57:20 2013 +0200
@@ -14,7 +14,7 @@
#include "safe-memset.h"
#include "master-service.h"
#include "mech.h"
-#include "auth-stream.h"
+#include "auth-fields.h"
#include "auth-request-handler.h"
#include "auth-client-interface.h"
#include "auth-client-connection.h"
diff -r cc4472f02f70 -r 17f5257d60c1 src/auth/auth-fields.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/auth/auth-fields.c Wed Jan 30 19:57:20 2013 +0200
@@ -0,0 +1,147 @@
+/* Copyright (c) 2005-2012 Dovecot authors, see the included COPYING file */
+
+#include "auth-common.h"
+#include "array.h"
+#include "str.h"
+#include "strescape.h"
+#include "ostream.h"
+#include "auth-request.h"
+#include "auth-fields.h"
+
+struct auth_fields {
+ pool_t pool;
+ ARRAY_TYPE(auth_field) fields;
+};
+
+struct auth_fields *auth_fields_init(pool_t pool)
+{
+ struct auth_fields *reply;
+
+ reply = p_new(pool, struct auth_fields, 1);
+ reply->pool = pool;
+ p_array_init(&reply->fields, pool, 16);
+ return reply;
+}
+
+static bool
+auth_fields_find_idx(struct auth_fields *reply, const char *key,
+ unsigned int *idx_r)
+{
+ const struct auth_field *fields;
+ unsigned int i, count;
+
+ fields = array_get(&reply->fields, &count);
+ for (i = 0; i < count; i++) {
+ if (strcmp(fields[i].key, key) == 0) {
+ *idx_r = i;
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
+void auth_fields_add(struct auth_fields *reply,
+ const char *key, const char *value,
+ enum auth_field_flags flags)
+{
+ struct auth_field *field;
+ unsigned int idx;
+
+ i_assert(*key != '\0');
+ i_assert(strchr(key, '\t') == NULL &&
+ strchr(key, '\n') == NULL);
+
+ if (!auth_fields_find_idx(reply, key, &idx)) {
+ field = array_append_space(&reply->fields);
+ field->key = p_strdup(reply->pool, key);
+ } else {
+ field = array_idx_modifiable(&reply->fields, idx);
+ }
+ field->value = p_strdup_empty(reply->pool, value);
+ field->flags = flags;
+}
+
+void auth_fields_remove(struct auth_fields *reply, const char *key)
+{
+ unsigned int idx;
+
+ if (auth_fields_find_idx(reply, key, &idx))
+ array_delete(&reply->fields, idx, 1);
+}
+
+const char *auth_fields_find(struct auth_fields *reply, const char *key)
+{
+ const struct auth_field *field;
+ unsigned int idx;
+
+ if (!auth_fields_find_idx(reply, key, &idx))
+ return NULL;
+
+ field = array_idx(&reply->fields, idx);
+ return field->value == NULL ? "" : field->value;
+}
+
+bool auth_fields_exists(struct auth_fields *reply, const char *key)
+{
+ return auth_fields_find(reply, key) != NULL;
+}
+
+void auth_fields_reset(struct auth_fields *reply)
+{
+ array_clear(&reply->fields);
+}
+
+void auth_fields_import(struct auth_fields *reply, const char *str,
+ enum auth_field_flags flags)
+{
+ T_BEGIN {
+ const char *const *arg = t_strsplit_tab(str);
+ const char *key, *value;
+
+ for (; *arg != NULL; arg++) {
+ value = strchr(*arg, '=');
+ if (value == NULL) {
+ key = *arg;
+ value = NULL;
+ } else {
+ key = t_strdup_until(*arg, value++);
+ }
+ auth_fields_add(reply, key, value, flags);
+ }
+ } T_END;
+}
+
+const ARRAY_TYPE(auth_field) *auth_fields_export(struct auth_fields *reply)
+{
+ return &reply->fields;
+}
+
+void auth_fields_append(struct auth_fields *reply, string_t *dest,
+ bool include_hidden)
+{
+ const struct auth_field *fields;
+ unsigned int i, count;
+ bool first = TRUE;
+
+ fields = array_get(&reply->fields, &count);
+ for (i = 0; i < count; i++) {
+ if (!include_hidden &&
+ (fields[i].flags & AUTH_FIELD_FLAG_HIDDEN) != 0)
+ continue;
+
+ if (first)
+ first = FALSE;
+ else
+ str_append_c(dest, '\t');
+ str_append(dest, fields[i].key);
+ if (fields[i].value != NULL) {
+ str_append_c(dest, '=');
+ str_append_tabescaped(dest, fields[i].value);
+ }
+ }
+}
+
+bool auth_fields_is_empty(struct auth_fields *reply)
+{
+ return reply == NULL || array_count(&reply->fields) == 0;
+}
diff -r cc4472f02f70 -r 17f5257d60c1 src/auth/auth-fields.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/auth/auth-fields.h Wed Jan 30 19:57:20 2013 +0200
@@ -0,0 +1,34 @@
+#ifndef AUTH_FIELDS_H
+#define AUTH_FIELDS_H
+
+struct auth_request;
+
+enum auth_field_flags {
+ /* This field is internal to auth process and won't be sent to client */
+ AUTH_FIELD_FLAG_HIDDEN = 0x01
+};
+
+struct auth_field {
+ const char *key, *value;
+ enum auth_field_flags flags;
+};
+ARRAY_DEFINE_TYPE(auth_field, struct auth_field);
+
+struct auth_fields *auth_fields_init(pool_t pool);
+void auth_fields_add(struct auth_fields *fields,
+ const char *key, const char *value,
+ enum auth_field_flags flags) ATTR_NULL(3);
+void auth_fields_reset(struct auth_fields *reply);
+void auth_fields_remove(struct auth_fields *reply, const char *key);
+
+const char *auth_fields_find(struct auth_fields *reply, const char *key);
+bool auth_fields_exists(struct auth_fields *reply, const char *key);
+
+void auth_fields_import(struct auth_fields *reply, const char *str,
+ enum auth_field_flags flags);
+const ARRAY_TYPE(auth_field) *auth_fields_export(struct auth_fields *reply);
+void auth_fields_append(struct auth_fields *reply, string_t *dest,
+ bool include_hidden);
+bool auth_fields_is_empty(struct auth_fields *reply);
+
+#endif
diff -r cc4472f02f70 -r 17f5257d60c1 src/auth/auth-master-connection.c
--- a/src/auth/auth-master-connection.c Wed Jan 30 19:46:58 2013 +0200
+++ b/src/auth/auth-master-connection.c Wed Jan 30 19:57:20 2013 +0200
@@ -214,14 +214,14 @@
user_verify_restricted_uid(struct auth_request *auth_request)
{
struct auth_master_connection *conn = auth_request->master;
- struct auth_stream_reply *reply = auth_request->userdb_reply;
+ struct auth_fields *reply = auth_request->userdb_reply;
const char *value, *reason;
uid_t uid;
if (conn->userdb_restricted_uid == 0)
return 0;
- value = auth_stream_reply_find(reply, "uid");
+ value = auth_fields_find(reply, "uid");
if (value == NULL)
reason = "userdb reply doesn't contain uid";
else if (str_to_uid(value, &uid) < 0)
@@ -262,8 +262,8 @@
case USERDB_RESULT_INTERNAL_FAILURE:
str_printfa(str, "FAIL\t%u", auth_request->id);
if (auth_request->userdb_lookup_failed) {
- value = auth_stream_reply_find(auth_request->userdb_reply,
- "reason");
+ value = auth_fields_find(auth_request->userdb_reply,
+ "reason");
if (value != NULL)
str_printfa(str, "\treason=%s", value);
}
@@ -275,7 +275,7 @@
str_printfa(str, "USER\t%u\t", auth_request->id);
str_append_tabescaped(str, auth_request->user);
str_append_c(str, '\t');
- auth_stream_reply_append(auth_request->userdb_reply, str, FALSE);
+ auth_fields_append(auth_request->userdb_reply, str, FALSE);
break;
}
@@ -323,10 +323,10 @@
case PASSDB_RESULT_OK:
str_printfa(str, "PASS\t%u\tuser=", auth_request->id);
str_append_tabescaped(str, auth_request->user);
- if (!auth_stream_is_empty(auth_request->extra_fields)) {
+ if (!auth_fields_is_empty(auth_request->extra_fields)) {
str_append_c(str, '\t');
- auth_stream_reply_append(auth_request->extra_fields,
- str, FALSE);
+ auth_fields_append(auth_request->extra_fields,
+ str, FALSE);
}
break;
case PASSDB_RESULT_USER_UNKNOWN:
diff -r cc4472f02f70 -r 17f5257d60c1 src/auth/auth-postfix-connection.c
--- a/src/auth/auth-postfix-connection.c Wed Jan 30 19:46:58 2013 +0200
+++ b/src/auth/auth-postfix-connection.c Wed Jan 30 19:57:20 2013 +0200
@@ -66,7 +66,6 @@
user_callback(enum userdb_result result, struct auth_request *auth_request)
{
struct auth_postfix_connection *conn = auth_request->context;
- struct auth_stream_reply *reply = auth_request->userdb_reply;
string_t *str;
const char *value;
@@ -77,7 +76,7 @@
switch (result) {
case USERDB_RESULT_INTERNAL_FAILURE:
if (auth_request->userdb_lookup_failed)
- value = auth_stream_reply_find(reply, "reason");
+ value = auth_fields_find(auth_request->userdb_reply, "reason");
else
value = NULL;
str_printfa(str, "400 %s",
diff -r cc4472f02f70 -r 17f5257d60c1 src/auth/auth-request-handler.c
--- a/src/auth/auth-request-handler.c Wed Jan 30 19:46:58 2013 +0200
+++ b/src/auth/auth-request-handler.c Wed Jan 30 19:57:20 2013 +0200
@@ -166,15 +166,15 @@
More information about the dovecot-cvs
mailing list