[dovecot-cvs] dovecot/src/auth Makefile.am, 1.46,
1.47 auth-master-connection.c, 1.36,
1.37 auth-request-handler.c, 1.8, 1.9 auth-request.c, 1.26,
1.27 auth-request.h, 1.16, 1.17 auth-worker-client.c, 1.13,
1.14 passdb-blocking.c, 1.5, 1.6 passdb-checkpassword.c, 1.9,
1.10 passdb.h, 1.25, 1.26 userdb-blocking.c, 1.3,
1.4 userdb-ldap.c, 1.33, 1.34 userdb-passdb.c, 1.6,
1.7 userdb-passwd-file.c, 1.15, 1.16 userdb-passwd.c, 1.16,
1.17 userdb-sql.c, 1.10, 1.11 userdb-static.c, 1.13,
1.14 userdb-vpopmail.c, 1.16, 1.17 userdb.c, 1.19,
1.20 userdb.h, 1.22, 1.23
cras at dovecot.org
cras at dovecot.org
Sun Aug 7 14:41:22 EEST 2005
Update of /var/lib/cvs/dovecot/src/auth
In directory talvi:/tmp/cvs-serv27981/src/auth
Modified Files:
Makefile.am auth-master-connection.c auth-request-handler.c
auth-request.c auth-request.h auth-worker-client.c
passdb-blocking.c passdb-checkpassword.c passdb.h
userdb-blocking.c userdb-ldap.c userdb-passdb.c
userdb-passwd-file.c userdb-passwd.c userdb-sql.c
userdb-static.c userdb-vpopmail.c userdb.c userdb.h
Log Message:
s/occured/occurred/
Index: Makefile.am
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/Makefile.am,v
retrieving revision 1.46
retrieving revision 1.47
diff -u -d -r1.46 -r1.47
--- Makefile.am 19 Apr 2005 13:11:12 -0000 1.46
+++ Makefile.am 7 Aug 2005 11:41:19 -0000 1.47
@@ -40,6 +40,7 @@
auth-module.c \
auth-request.c \
auth-request-handler.c \
+ auth-stream.c \
auth-worker-client.c \
auth-worker-server.c \
db-ldap.c \
@@ -88,6 +89,7 @@
auth-module.h \
auth-request.h \
auth-request-handler.h \
+ auth-stream.h \
auth-worker-client.h \
auth-worker-server.h \
db-ldap.h \
Index: auth-master-connection.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/auth-master-connection.c,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -d -r1.36 -r1.37
--- auth-master-connection.c 4 Jul 2005 11:32:13 -0000 1.36
+++ auth-master-connection.c 7 Aug 2005 11:41:19 -0000 1.37
@@ -78,17 +78,18 @@
}
static void
-user_callback(const char *result, struct auth_request *auth_request)
+user_callback(struct auth_stream_reply *reply,
+ struct auth_request *auth_request)
{
struct auth_master_connection *conn = auth_request->context;
string_t *str;
str = t_str_new(128);
- if (result == NULL)
+ if (reply == NULL)
str_printfa(str, "NOTFOUND\t%u\n", auth_request->id);
else {
str_printfa(str, "USER\t%u\t", auth_request->id);
- str_append(str, result);
+ str_append(str, auth_stream_reply_export(reply));
str_append_c(str, '\n');
}
(void)o_stream_send(conn->output, str_data(str), str_len(str));
Index: auth-request-handler.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/auth-request-handler.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- auth-request-handler.c 29 Jul 2005 09:21:27 -0000 1.8
+++ auth-request-handler.c 7 Aug 2005 11:41:19 -0000 1.9
@@ -104,16 +104,19 @@
static const char *get_client_extra_fields(struct auth_request *request)
{
string_t *str;
- const char **fields;
+ const char **fields, *extra_fields;
unsigned int src, dest;
+ extra_fields = request->extra_fields == NULL ? NULL :
+ auth_stream_reply_export(request->extra_fields);
+
if (!request->proxy) {
- if (request->extra_fields == NULL)
+ if (extra_fields == NULL)
return NULL;
/* we only wish to remove all fields prefixed with "userdb_" */
- if (strstr(str_c(request->extra_fields), "userdb_") == NULL)
- return str_c(request->extra_fields);
+ if (strstr(extra_fields, "userdb_") == NULL)
+ return extra_fields;
}
str = t_str_new(128);
@@ -123,7 +126,7 @@
str_printfa(str, "pass=%s", request->mech_password);
}
- fields = t_strsplit(str_c(request->extra_fields), "\t");
+ fields = t_strsplit(extra_fields, "\t");
for (src = dest = 0; fields[src] != NULL; src++) {
if (strncmp(fields[src], "userdb_", 7) != 0) {
if (str_len(str) > 0)
@@ -374,23 +377,24 @@
return TRUE;
}
-static void userdb_callback(const char *result, struct auth_request *request)
+static void userdb_callback(struct auth_stream_reply *reply,
+ struct auth_request *request)
{
struct auth_request_handler *handler = request->context;
- string_t *reply;
+ string_t *str;
i_assert(request->state == AUTH_REQUEST_STATE_USERDB);
request->state = AUTH_REQUEST_STATE_FINISHED;
- reply = t_str_new(256);
- if (result == NULL)
- str_printfa(reply, "NOTFOUND\t%u", request->id);
+ str = t_str_new(256);
+ if (reply == NULL)
+ str_printfa(str, "NOTFOUND\t%u", request->id);
else {
- str_printfa(reply, "USER\t%u\t", request->id);
- str_append(reply, result);
+ str_printfa(str, "USER\t%u\t", request->id);
+ str_append(str, auth_stream_reply_export(reply));
}
- handler->master_callback(str_c(reply), request->master);
+ handler->master_callback(str_c(str), request->master);
auth_request_unref(request);
auth_request_handler_unref(handler);
Index: auth-request.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/auth-request.c,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -d -r1.26 -r1.27
--- auth-request.c 16 Jun 2005 08:21:17 -0000 1.26
+++ auth-request.c 7 Aug 2005 11:41:19 -0000 1.27
@@ -153,11 +153,14 @@
enum passdb_result result)
{
struct passdb_module *passdb = request->passdb->passdb;
+ const char *extra_fields;
string_t *str;
- i_assert(request->extra_fields == NULL ||
- (strstr(str_c(request->extra_fields), "\tpass=") == NULL &&
- strncmp(str_c(request->extra_fields), "pass=", 5) != 0));
+ extra_fields = request->extra_fields == NULL ? NULL :
+ auth_stream_reply_export(request->extra_fields);
+ i_assert(extra_fields == NULL ||
+ (strstr(extra_fields, "\tpass=") == NULL &&
+ strncmp(extra_fields, "pass=", 5) != 0));
if (passdb_cache == NULL)
return;
@@ -175,8 +178,7 @@
}
/* save all except the currently given password in cache */
- str = t_str_new(32 + (request->extra_fields != NULL ?
- str_len(request->extra_fields) : 0));
+ str = t_str_new(256);
if (request->passdb_password != NULL) {
if (*request->passdb_password != '{') {
/* cached passwords must have a known scheme */
@@ -184,12 +186,16 @@
str_append(str, passdb->default_pass_scheme);
str_append_c(str, '}');
}
+ if (strchr(request->passdb_password, '\t') != NULL)
+ i_panic("%s: Password contains TAB", request->user);
+ if (strchr(request->passdb_password, '\n') != NULL)
+ i_panic("%s: Password contains LF", request->user);
str_append(str, request->passdb_password);
}
- if (request->extra_fields != NULL) {
+ if (extra_fields != NULL) {
str_append_c(str, '\t');
- str_append_str(str, request->extra_fields);
+ str_append(str, extra_fields);
}
if (request->no_failure_delay) {
str_append_c(str, '\t');
@@ -235,7 +241,7 @@
request->passdb->next != NULL) {
/* try next passdb. */
if (request->extra_fields != NULL)
- str_truncate(request->extra_fields, 0);
+ auth_stream_reply_reset(request->extra_fields);
request->state = AUTH_REQUEST_STATE_MECH_CONTINUE;
request->passdb = request->passdb->next;
@@ -355,13 +361,13 @@
}
}
-void auth_request_userdb_callback(const char *result,
+void auth_request_userdb_callback(struct auth_stream_reply *reply,
struct auth_request *request)
{
- if (result == NULL && request->userdb->next != NULL) {
+ if (reply == NULL && request->userdb->next != NULL) {
/* try next userdb. */
if (request->extra_fields != NULL)
- str_truncate(request->extra_fields, 0);
+ auth_stream_reply_reset(request->extra_fields);
request->userdb = request->userdb->next;
auth_request_lookup_user(request,
@@ -369,13 +375,13 @@
return;
}
- if (result == NULL && request->client_pid != 0) {
+ if (reply == NULL && request->client_pid != 0) {
/* this was actual login attempt */
auth_request_log_error(request, "userdb",
"user not found from userdb");
}
- request->private_callback.userdb(result, request);
+ request->private_callback.userdb(reply, request);
}
void auth_request_lookup_user(struct auth_request *request,
@@ -426,8 +432,6 @@
const char *name, const char *value,
const char *default_scheme)
{
- string_t *str;
-
i_assert(value != NULL);
if (strcmp(name, "password") == 0) {
@@ -466,29 +470,19 @@
return;
}
- str = request->extra_fields;
- if (str == NULL)
- request->extra_fields = str = str_new(request->pool, 64);
-
if (strcmp(name, "nologin") == 0) {
/* user can't actually login - don't keep this
reply for master */
request->no_login = TRUE;
- if (str_len(str) > 0)
- str_append_c(str, '\t');
- str_append(str, name);
} else if (strcmp(name, "proxy") == 0) {
/* we're proxying authentication for this user. send
password back if using plaintext authentication. */
request->proxy = TRUE;
- if (str_len(str) > 0)
- str_append_c(str, '\t');
- str_append(str, name);
- } else {
- if (str_len(str) > 0)
- str_append_c(str, '\t');
- str_printfa(str, "%s=%s", name, value);
}
+
+ if (request->extra_fields == NULL)
+ request->extra_fields = auth_stream_reply_init(request);
+ auth_stream_reply_add(request->extra_fields, name, value);
}
static const char *escape_none(const char *str)
Index: auth-request.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/auth-request.h,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- auth-request.h 26 Apr 2005 11:43:36 -0000 1.16
+++ auth-request.h 7 Aug 2005 11:41:19 -0000 1.17
@@ -24,7 +24,7 @@
char *user;
char *mech_password; /* set if verify_plain() is called */
char *passdb_password; /* set after password lookup if successful */
- string_t *extra_fields;
+ struct auth_stream_reply *extra_fields;
struct mech_module *mech;
struct auth *auth;
@@ -116,7 +116,7 @@
void auth_request_lookup_credentials_callback(enum passdb_result result,
const char *credentials,
struct auth_request *request);
-void auth_request_userdb_callback(const char *result,
+void auth_request_userdb_callback(struct auth_stream_reply *reply,
struct auth_request *request);
#endif
Index: auth-worker-client.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/auth-worker-client.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- auth-worker-client.c 16 Jun 2005 08:21:17 -0000 1.13
+++ auth-worker-client.c 7 Aug 2005 11:41:19 -0000 1.14
@@ -90,8 +90,11 @@
if (request->passdb_password != NULL)
str_append(str, request->passdb_password);
str_append_c(str, '\t');
- if (request->extra_fields != NULL)
- str_append_str(str, request->extra_fields);
+ if (request->extra_fields != NULL) {
+ const char *field =
+ auth_stream_reply_export(request->extra_fields);
+ str_append(str, field);
+ }
}
str_append_c(str, '\n');
o_stream_send(client->output, str_data(str), str_len(str));
@@ -161,8 +164,11 @@
str_printfa(str, "OK\t%s\t{%s}%s\t", request->user,
passdb_credentials_to_str(request->credentials),
credentials);
- if (request->extra_fields != NULL)
- str_append_str(str, request->extra_fields);
+ if (request->extra_fields != NULL) {
+ const char *field =
+ auth_stream_reply_export(request->extra_fields);
+ str_append(str, field);
+ }
}
str_append_c(str, '\n');
o_stream_send(client->output, str_data(str), str_len(str));
@@ -220,15 +226,16 @@
}
static void
-lookup_user_callback(const char *result, struct auth_request *auth_request)
+lookup_user_callback(struct auth_stream_reply *reply,
+ struct auth_request *auth_request)
{
struct auth_worker_client *client = auth_request->context;
string_t *str;
str = t_str_new(64);
str_printfa(str, "%u\t", auth_request->id);
- if (result != NULL)
- str_append(str, result);
+ if (reply != NULL)
+ str_append(str, auth_stream_reply_export(reply));
str_append_c(str, '\n');
o_stream_send(client->output, str_data(str), str_len(str));
Index: passdb-blocking.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/passdb-blocking.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- passdb-blocking.c 16 Jun 2005 08:21:17 -0000 1.5
+++ passdb-blocking.c 7 Aug 2005 11:41:19 -0000 1.6
@@ -87,8 +87,8 @@
if (p != NULL && (p[6] == '\0' || p[6] == '\t'))
request->proxy = TRUE;
- request->extra_fields = str_new(request->pool, 128);
- str_append(request->extra_fields, reply);
+ request->extra_fields = auth_stream_reply_init(request);
+ auth_stream_reply_import(request->extra_fields, reply);
}
return 0;
}
Index: passdb-checkpassword.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/passdb-checkpassword.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- passdb-checkpassword.c 12 Jul 2005 12:58:47 -0000 1.9
+++ passdb-checkpassword.c 7 Aug 2005 11:41:19 -0000 1.10
@@ -62,10 +62,9 @@
if (result == PASSDB_RESULT_OK) {
request->request->extra_fields =
- str_new(request->request->pool,
- str_len(request->input_buf));
- str_append_str(request->request->extra_fields,
- request->input_buf);
+ auth_stream_reply_init(request->request);
+ auth_stream_reply_import(request->request->extra_fields,
+ str_c(request->input_buf));
}
if (auth_request_unref(request->request)) {
Index: passdb.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/passdb.h,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -d -r1.25 -r1.26
--- passdb.h 16 Mar 2005 20:18:13 -0000 1.25
+++ passdb.h 7 Aug 2005 11:41:19 -0000 1.26
@@ -67,7 +67,7 @@
lookup_credentials_callback_t *callback,
struct auth_request *auth_request);
-const char * passdb_credentials_to_str(enum passdb_credentials credentials);
+const char *passdb_credentials_to_str(enum passdb_credentials credentials);
void passdb_preinit(struct auth *auth, const char *driver, const char *args);
void passdb_init(struct auth_passdb *passdb);
Index: userdb-blocking.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/userdb-blocking.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- userdb-blocking.c 7 Mar 2005 19:16:15 -0000 1.3
+++ userdb-blocking.c 7 Aug 2005 11:41:19 -0000 1.4
@@ -10,10 +10,15 @@
static void user_callback(struct auth_request *request, const char *reply)
{
+ struct auth_stream_reply *stream_reply;
+
if (*reply == '\0')
reply = NULL;
- request->private_callback.userdb(reply, request);
+ stream_reply = auth_stream_reply_init(request);
+ auth_stream_reply_import(stream_reply, reply);
+
+ request->private_callback.userdb(stream_reply, request);
}
void userdb_blocking_lookup(struct auth_request *request)
Index: userdb-ldap.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/userdb-ldap.c,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -d -r1.33 -r1.34
--- userdb-ldap.c 22 Jul 2005 11:32:57 -0000 1.33
+++ userdb-ldap.c 7 Aug 2005 11:41:19 -0000 1.34
@@ -25,57 +25,53 @@
static struct ldap_connection *userdb_ldap_conn;
-static int append_uid_list(struct auth_request *auth_request, string_t *str,
+static int append_uid_list(struct auth_request *auth_request,
+ struct auth_stream_reply *reply,
const char *name, char **vals)
{
uid_t uid;
for (; *vals != NULL; vals++) {
- str_append_c(str, '\t');
- str_append(str, name);
- str_append_c(str, '=');
-
uid = userdb_parse_uid(auth_request, *vals);
if (uid == (uid_t)-1)
return FALSE;
- str_append(str, dec2str(uid));
+
+ auth_stream_reply_add(reply, name, dec2str(uid));
}
return TRUE;
}
-static int append_gid_list(struct auth_request *auth_request, string_t *str,
+static int append_gid_list(struct auth_request *auth_request,
+ struct auth_stream_reply *reply,
const char *name, char **vals)
{
gid_t gid;
for (; *vals != NULL; vals++) {
- str_append_c(str, '\t');
- str_append(str, name);
- str_append_c(str, '=');
-
gid = userdb_parse_gid(auth_request, *vals);
if (gid == (gid_t)-1)
return FALSE;
- str_append(str, dec2str(gid));
+
+ auth_stream_reply_add(reply, name, dec2str(gid));
}
return TRUE;
}
-static const char *
+static struct auth_stream_reply *
ldap_query_get_result(struct ldap_connection *conn, LDAPMessage *entry,
struct auth_request *auth_request)
{
- string_t *str;
+ struct auth_stream_reply *reply;
BerElement *ber;
const char *name;
char *attr, **vals;
unsigned int i;
int seen_uid = FALSE, seen_gid = FALSE;
- str = t_str_new(256);
- str_append(str, auth_request->user);
+ reply = auth_stream_reply_init(auth_request);
+ auth_stream_reply_add(reply, NULL, auth_request->user);
attr = ldap_first_attribute(conn->ld, entry, &ber);
while (attr != NULL) {
@@ -84,21 +80,19 @@
if (name != NULL && vals != NULL && vals[0] != NULL) {
if (strcmp(name, "uid") == 0) {
- if (!append_uid_list(auth_request, str,
+ if (!append_uid_list(auth_request, reply,
name, vals))
return NULL;
seen_uid = TRUE;
} else if (strcmp(name, "gid") == 0) {
- if (!append_gid_list(auth_request, str,
- name, vals))
+ if (!append_gid_list(auth_request, reply,
+ name, vals))
return NULL;
seen_gid = TRUE;
} else {
for (i = 0; vals[i] != NULL; i++) {
- str_append_c(str, '\t');
- str_append(str, name);
- str_append_c(str, '=');
- str_append(str, vals[i]);
+ auth_stream_reply_add(reply, name,
+ vals[i]);
}
}
}
@@ -109,30 +103,27 @@
}
if (!seen_uid) {
- }
-
- if (!seen_uid) {
if (conn->set.uid == (uid_t)-1) {
auth_request_log_error(auth_request, "ldap",
"uid not in user_attrs and no default given in "
"user_global_uid");
+ return NULL;
}
- str_append(str, "\tuid=");
- str_append(str, dec2str(conn->set.uid));
+ auth_stream_reply_add(reply, "uid", dec2str(conn->set.uid));
}
if (!seen_gid) {
if (conn->set.gid == (gid_t)-1) {
auth_request_log_error(auth_request, "ldap",
"gid not in user_attrs and no default given in "
"user_global_gid");
+ return NULL;
}
- str_append(str, "\tgid=");
- str_append(str, dec2str(conn->set.gid));
+ auth_stream_reply_add(reply, "gid", dec2str(conn->set.gid));
}
- return str_c(str);
+ return reply;
}
static void handle_request(struct ldap_connection *conn,
@@ -142,7 +133,7 @@
(struct userdb_ldap_request *) request;
struct auth_request *auth_request = urequest->auth_request;
LDAPMessage *entry;
- const char *result;
+ struct auth_stream_reply *reply = NULL;
int ret;
ret = ldap_result2error(conn->ld, res, 0);
@@ -159,17 +150,16 @@
auth_request_log_error(auth_request, "ldap",
"Authenticated user not found");
}
- result = NULL;
} else {
- result = ldap_query_get_result(conn, entry, auth_request);
+ reply = ldap_query_get_result(conn, entry, auth_request);
if (ldap_next_entry(conn->ld, entry) != NULL) {
auth_request_log_error(auth_request, "ldap",
"Multiple replies found for user");
- result = NULL;
+ reply = NULL;
}
}
- urequest->userdb_callback(result, auth_request);
+ urequest->userdb_callback(reply, auth_request);
}
static void userdb_ldap_lookup(struct auth_request *auth_request,
Index: userdb-passdb.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/userdb-passdb.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- userdb-passdb.c 12 Jul 2005 12:58:47 -0000 1.6
+++ userdb-passdb.c 7 Aug 2005 11:41:19 -0000 1.7
@@ -2,7 +2,8 @@
#include "common.h"
-#ifdef USERDB_PASSDB
+//#ifdef USERDB_PASSDB
+#if 1
#include "str.h"
#include "var-expand.h"
@@ -34,7 +35,10 @@
str = t_str_new(256);
str_append(str, auth_request->user);
- args = t_strsplit(str_c(auth_request->extra_fields), "\t");
+ /* export the request. keep all keys starting with userdb_ but strip
+ the userdb_ away. */
+ args = t_strsplit(auth_stream_reply_export(auth_request->extra_fields),
+ "\t");
for (; *args != NULL; args++) {
const char *arg = *args;
@@ -75,8 +79,15 @@
if (uid == (uid_t)-1 || gid == (gid_t)-1)
callback(NULL, auth_request);
- else
- callback(str_c(str), auth_request);
+ else {
+ struct auth_stream_reply *reply;
+
+ /* import the string into request. since the values were
+ exported they are already in escaped form in the string. */
+ reply = auth_stream_reply_init(auth_request);
+ auth_stream_reply_import(reply, str_c(str));
+ callback(reply, auth_request);
+ }
t_pop();
}
Index: userdb-passwd-file.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/userdb-passwd-file.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- userdb-passwd-file.c 22 Jul 2005 12:42:57 -0000 1.15
+++ userdb-passwd-file.c 7 Aug 2005 11:41:19 -0000 1.16
@@ -13,8 +13,8 @@
static void passwd_file_lookup(struct auth_request *auth_request,
userdb_callback_t *callback)
{
+ struct auth_stream_reply *reply;
struct passwd_user *pu;
- string_t *str;
pu = db_passwd_file_lookup(userdb_pwf, auth_request);
if (pu == NULL) {
@@ -22,16 +22,17 @@
return;
}
- str = t_str_new(128);
- str_printfa(str, "%s\tuid=%s\tgid=%s",
- auth_request->user, dec2str(pu->uid), dec2str(pu->gid));
+ reply = auth_stream_reply_init(auth_request);
+ auth_stream_reply_add(reply, NULL, auth_request->user);
+ auth_stream_reply_add(reply, "uid", dec2str(pu->uid));
+ auth_stream_reply_add(reply, "gid", dec2str(pu->gid));
if (pu->home != NULL)
- str_printfa(str, "\thome=%s", pu->home);
+ auth_stream_reply_add(reply, "home", pu->home);
if (pu->mail != NULL)
- str_printfa(str, "\tmail=%s", pu->mail);
+ auth_stream_reply_add(reply, "mail", pu->mail);
- callback(str_c(str), auth_request);
+ callback(reply, auth_request);
}
static void passwd_file_init(const char *args)
Index: userdb-passwd.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/userdb-passwd.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- userdb-passwd.c 12 Jul 2005 12:58:47 -0000 1.16
+++ userdb-passwd.c 7 Aug 2005 11:41:19 -0000 1.17
@@ -12,7 +12,7 @@
userdb_callback_t *callback)
{
struct passwd *pw;
- const char *result;
+ struct auth_stream_reply *reply;
pw = getpwnam(auth_request->user);
if (pw == NULL) {
@@ -29,11 +29,14 @@
pw->pw_name, auth_request->user);
}
- result = t_strdup_printf("%s\tsystem_user=%s\tuid=%s\tgid=%s\t"
- "home=%s", pw->pw_name, pw->pw_name,
- dec2str(pw->pw_uid), dec2str(pw->pw_gid),
- pw->pw_dir);
- callback(result, auth_request);
+ reply = auth_stream_reply_init(auth_request);
+ auth_stream_reply_add(reply, NULL, pw->pw_name);
+ auth_stream_reply_add(reply, "system_user", pw->pw_name);
+ auth_stream_reply_add(reply, "uid", dec2str(pw->pw_uid));
+ auth_stream_reply_add(reply, "gid", dec2str(pw->pw_gid));
+ auth_stream_reply_add(reply, "home", pw->pw_dir);
+
+ callback(reply, auth_request);
}
struct userdb_module userdb_passwd = {
Index: userdb-sql.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/userdb-sql.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- userdb-sql.c 12 Jul 2005 12:58:47 -0000 1.10
+++ userdb-sql.c 7 Aug 2005 11:41:19 -0000 1.11
@@ -22,10 +22,11 @@
static struct sql_connection *userdb_sql_conn;
-static const char *sql_query_get_result(struct sql_result *result,
- struct auth_request *auth_request)
+static struct auth_stream_reply *
+sql_query_get_result(struct sql_result *result,
+ struct auth_request *auth_request)
{
- string_t *str;
+ struct auth_stream_reply *reply;
uid_t uid, gid;
const char *name, *value;
unsigned int i, fields_count;
@@ -33,8 +34,8 @@
uid = (uid_t)-1;
gid = (gid_t)-1;
- str = t_str_new(256);
- str_append(str, auth_request->user);
+ reply = auth_stream_reply_init(auth_request);
+ auth_stream_reply_add(reply, NULL, auth_request->user);
fields_count = sql_result_get_fields_count(result);
for (i = 0; i < fields_count; i++) {
@@ -44,10 +45,6 @@
if (value == NULL)
continue;
- str_append_c(str, '\t');
- str_append(str, name);
- str_append_c(str, '=');
-
/* some special handling for UID and GID. */
if (strcmp(name, "uid") == 0) {
uid = userdb_parse_uid(auth_request, value);
@@ -61,26 +58,28 @@
value = dec2str(gid);
}
- str_append(str, value);
+ auth_stream_reply_add(reply, name, value);
}
if (uid == (uid_t)-1) {
auth_request_log_error(auth_request, "sql",
"Password query didn't return uid, or it was NULL");
+ return NULL;
}
if (gid == (gid_t)-1) {
auth_request_log_error(auth_request, "sql",
"Password query didn't return gid, or it was NULL");
+ return NULL;
}
- return str_c(str);
+ return reply;
}
static void sql_query_callback(struct sql_result *result, void *context)
{
struct userdb_sql_request *sql_request = context;
struct auth_request *auth_request = sql_request->auth_request;
- const char *user_result = NULL;
+ struct auth_stream_reply *reply = NULL;
int ret;
ret = sql_result_next_row(result);
@@ -90,10 +89,10 @@
} else if (ret == 0) {
auth_request_log_info(auth_request, "sql", "User not found");
} else {
- user_result = sql_query_get_result(result, auth_request);
+ reply = sql_query_get_result(result, auth_request);
}
- sql_request->callback(user_result, auth_request);
+ sql_request->callback(reply, auth_request);
i_free(sql_request);
}
Index: userdb-static.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/userdb-static.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- userdb-static.c 12 Jul 2005 12:58:47 -0000 1.13
+++ userdb-static.c 7 Aug 2005 11:41:19 -0000 1.14
@@ -4,74 +4,97 @@
#ifdef USERDB_STATIC
+#include "array.h"
#include "str.h"
#include "var-expand.h"
#include "userdb.h"
#include <stdlib.h>
-static char *static_template;
+static pool_t static_pool;
+static array_t ARRAY_DEFINE(static_template, const char *);
static void static_lookup(struct auth_request *auth_request,
userdb_callback_t *callback)
{
+ const struct var_expand_table *table;
+ struct auth_stream_reply *reply;
string_t *str;
+ const char *const *args;
+ unsigned int i, count;
- str = t_str_new(128);
- str_append(str, auth_request->user);
- var_expand(str, static_template,
- auth_request_get_var_expand_table(auth_request, NULL));
- callback(str_c(str), auth_request);
+ t_push();
+ str = t_str_new(256);
+ table = auth_request_get_var_expand_table(auth_request, NULL);
+
+ reply = auth_stream_reply_init(auth_request);
+ auth_stream_reply_add(reply, NULL, auth_request->user);
+
+ args = array_get(&static_template, &count);
+ i_assert((count % 2) == 0);
+ for (i = 0; i < count; i += 2) {
+ str_truncate(str, 0);
+ var_expand(str, args[i+1], table);
+ auth_stream_reply_add(reply, args[i], str_c(str));
+ }
+
+ callback(reply, auth_request);
}
static void static_init(const char *args)
{
- const char *const *tmp;
+ const char *const *tmp, *key, *value;
uid_t uid;
gid_t gid;
- string_t *str;
+ static_pool = pool_alloconly_create("static userdb", 256);
uid = (uid_t)-1;
gid = (gid_t)-1;
- t_push();
- str = t_str_new(128);
+ ARRAY_CREATE(&static_template, static_pool, const char *, 16);
+ t_push();
for (tmp = t_strsplit_spaces(args, " "); *tmp != NULL; tmp++) {
- str_append_c(str, '\t');
- if (strncasecmp(*tmp, "uid=", 4) == 0) {
- uid = userdb_parse_uid(NULL, *tmp + 4);
+ value = strchr(*tmp, '=');
+ if (value == NULL)
+ key = *tmp;
+ else {
+ key = t_strdup_until(*tmp, value);
+ value++;
+ }
+
+ if (strcasecmp(key, "uid") == 0) {
+ uid = userdb_parse_uid(NULL, value);
if (uid == (uid_t)-1) {
i_fatal("static userdb: Invalid uid: %s",
- *tmp + 4);
+ value);
}
- str_append(str, "uid=");
- str_append(str, dec2str(uid));
- } else if (strncasecmp(*tmp, "gid=", 4) == 0) {
- gid = userdb_parse_gid(NULL, *tmp + 4);
+ value = dec2str(uid);
+ } else if (strcasecmp(key, "gid") == 0) {
+ gid = userdb_parse_gid(NULL, value);
if (gid == (gid_t)-1) {
i_fatal("static userdb: Invalid gid: %s",
- *tmp + 4);
+ value);
}
- str_append(str, "gid=");
- str_append(str, dec2str(gid));
- } else {
- str_append(str, *tmp);
+ value = dec2str(gid);
}
+ key = p_strdup(static_pool, key);
+ value = p_strdup(static_pool, value);
+
+ array_append(&static_template, &key, 1);
+ array_append(&static_template, &value, 1);
}
+ t_pop();
if (uid == (uid_t)-1)
i_fatal("static userdb: uid missing");
if (gid == (gid_t)-1)
i_fatal("static userdb: gid missing");
-
- static_template = i_strdup(str_c(str));
- t_pop();
}
static void static_deinit(void)
{
- i_free(static_template);
+ pool_unref(static_pool);
}
struct userdb_module userdb_static = {
Index: userdb-vpopmail.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/userdb-vpopmail.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- userdb-vpopmail.c 12 Jul 2005 12:58:47 -0000 1.16
+++ userdb-vpopmail.c 7 Aug 2005 11:41:19 -0000 1.17
@@ -44,7 +44,7 @@
{
char vpop_user[VPOPMAIL_LIMIT], vpop_domain[VPOPMAIL_LIMIT];
struct vqpasswd *vpw;
- const char *result;
+ struct auth_stream_reply *reply;
uid_t uid;
gid_t gid;
@@ -84,11 +84,13 @@
}
}
- result = t_strdup_printf("%s\tuid=%s\tgid=%s\thome=%s",
- vpw->pw_name, dec2str(uid), dec2str(gid),
- vpw->pw_dir);
+ reply = auth_stream_reply_init();
+ auth_stream_reply_add(reply, NULL, vpw->pw_name);
+ auth_stream_reply_add(reply, "uid", dec2str(uid));
+ auth_stream_reply_add(reply, "gid", dec2str(gid));
+ auth_stream_reply_add(reply, "home", vpw->pw_dir);
- callback(result, auth_request);
+ callback(reply, auth_request);
}
struct userdb_module userdb_vpopmail = {
Index: userdb.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/userdb.c,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- userdb.c 7 Mar 2005 18:55:13 -0000 1.19
+++ userdb.c 7 Aug 2005 11:41:19 -0000 1.20
@@ -45,6 +45,9 @@
{
struct passwd *pw;
+ if (str == NULL)
+ return (uid_t)-1;
+
if (*str >= '0' && *str <= '9')
return (uid_t)strtoul(str, NULL, 10);
@@ -63,6 +66,9 @@
{
struct group *gr;
+ if (str == NULL)
+ return (uid_t)-1;
+
if (*str >= '0' && *str <= '9')
return (gid_t)strtoul(str, NULL, 10);
Index: userdb.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/userdb.h,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -d -r1.22 -r1.23
--- userdb.h 7 Mar 2005 18:55:13 -0000 1.22
+++ userdb.h 7 Aug 2005 11:41:19 -0000 1.23
@@ -1,9 +1,11 @@
#ifndef __USERDB_H
#define __USERDB_H
+#include "auth-stream.h"
+
struct auth_request;
-typedef void userdb_callback_t(const char *result,
+typedef void userdb_callback_t(struct auth_stream_reply *reply,
struct auth_request *request);
struct userdb_module {
More information about the dovecot-cvs
mailing list