[dovecot-cvs] dovecot/src/auth Makefile.am, 1.39,
1.40 auth-client-connection.c, 1.24, 1.25 userdb.c, 1.14,
1.15 userdb.h, 1.14, 1.15 userdb-passdb.c, NONE, 1.1
cras at dovecot.org
cras at dovecot.org
Fri Jan 7 20:15:18 EET 2005
Update of /var/lib/cvs/dovecot/src/auth
In directory talvi:/tmp/cvs-serv12122/src/auth
Modified Files:
Makefile.am auth-client-connection.c userdb.c userdb.h
Added Files:
userdb-passdb.c
Log Message:
Added "passdb" userdb. It works only if passdb gives all the information
needed for userdb. For example with SQL you can use ".. uid AS userdb_uid, gid
AS userdb_gid, home AS userdb_home .." in password_query.
Index: Makefile.am
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/Makefile.am,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -d -r1.39 -r1.40
--- Makefile.am 21 Oct 2004 02:23:12 -0000 1.39
+++ Makefile.am 7 Jan 2005 18:15:15 -0000 1.40
@@ -62,6 +62,7 @@
passdb-sql.c \
userdb.c \
userdb-ldap.c \
+ userdb-passdb.c \
userdb-passwd.c \
userdb-passwd-file.c \
userdb-static.c \
Index: auth-client-connection.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/auth-client-connection.c,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -d -r1.24 -r1.25
--- auth-client-connection.c 7 Jan 2005 17:27:20 -0000 1.24
+++ auth-client-connection.c 7 Jan 2005 18:15:15 -0000 1.25
@@ -52,11 +52,33 @@
t_pop();
}
+static const char *get_client_extra_fields(struct auth_request *request)
+{
+ const char **fields;
+ unsigned int src, dest;
+
+ if (request->extra_fields == NULL)
+ return NULL;
+
+ /* we only wish to remove all fields prefixed with "userdb_" */
+ if (strstr(request->extra_fields, "userdb_") == NULL)
+ return request->extra_fields;
+
+ fields = t_strsplit(request->extra_fields, "\t");
+ for (src = dest = 0; fields[src] != NULL; src++) {
+ if (strncmp(fields[src], "userdb_", 7) == 0)
+ fields[dest++] = fields[src];
+ }
+ fields[dest] = NULL;
+ return t_strarray_join(fields, "\t");
+}
+
static void auth_callback(struct auth_request *request,
enum auth_client_result result,
const void *reply, size_t reply_size)
{
string_t *str = NULL;
+ const char *fields;
ssize_t ret;
t_push();
@@ -75,22 +97,28 @@
str_append(str, "\tresp=");
base64_encode(reply, reply_size, str);
}
- if (request->extra_fields) {
+ t_push();
+ fields = get_client_extra_fields(request);
+ if (fields != NULL) {
str_append_c(str, '\t');
- str_append(str, request->extra_fields);
+ str_append(str, fields);
}
+ t_pop();
break;
case AUTH_CLIENT_RESULT_FAILURE:
str = t_str_new(128);
str_printfa(str, "FAIL\t%u", request->id);
if (request->user != NULL)
str_printfa(str, "\tuser=%s", request->user);
- if (request->extra_fields) {
- str_append_c(str, '\t');
- str_append(str, request->extra_fields);
- }
if (request->internal_failure)
str_append(str, "\ttemp");
+ t_push();
+ fields = get_client_extra_fields(request);
+ if (fields != NULL) {
+ str_append_c(str, '\t');
+ str_append(str, fields);
+ }
+ t_pop();
break;
}
Index: userdb.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/userdb.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- userdb.c 6 Jan 2005 20:13:26 -0000 1.14
+++ userdb.c 7 Jan 2005 18:15:15 -0000 1.15
@@ -19,6 +19,9 @@
#ifdef USERDB_PASSWD_FILE
&userdb_passwd_file,
#endif
+#ifdef USERDB_PASSDB
+ &userdb_passdb,
+#endif
#ifdef USERDB_STATIC
&userdb_static,
#endif
Index: userdb.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/userdb.h,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- userdb.h 6 Jan 2005 20:13:26 -0000 1.14
+++ userdb.h 7 Jan 2005 18:15:15 -0000 1.15
@@ -28,6 +28,7 @@
extern struct userdb_module *userdb;
+extern struct userdb_module userdb_passdb;
extern struct userdb_module userdb_static;
extern struct userdb_module userdb_passwd;
extern struct userdb_module userdb_passwd_file;
--- NEW FILE: userdb-passdb.c ---
/* Copyright (C) 2004 Timo Sirainen */
#include "config.h"
#undef HAVE_CONFIG_H
#ifdef USERDB_PASSDB
#include "common.h"
#include "str.h"
#include "var-expand.h"
#include "userdb.h"
#include <stdlib.h>
static void passdb_lookup(struct auth_request *auth_request,
userdb_callback_t *callback, void *context)
{
struct user_data data;
const char *const *args;
int uid_seen, gid_seen;
memset(&data, 0, sizeof(data));
data.virtual_user = auth_request->user;
uid_seen = gid_seen = FALSE;
data.uid = (uid_t)-1;
data.gid = (gid_t)-1;
t_push();
args = t_strsplit(auth_request->extra_fields, "\t");
for (; *args != NULL; args++) {
const char *arg = *args;
if (strncmp(arg, "userdb_", 7) != 0)
continue;
arg += 7;
if (strncmp(arg, "uid=", 4) == 0) {
uid_seen = TRUE;
data.uid = userdb_parse_uid(auth_request, arg+4);
} else if (strncmp(arg, "gid=", 4) == 0) {
gid_seen = TRUE;
data.gid = userdb_parse_gid(auth_request, arg+4);
} else if (strncmp(arg, "home=", 5) == 0)
data.home = arg + 5;
else if (strncmp(arg, "mail=", 5) == 0)
data.mail = arg + 5;
}
if (!uid_seen) {
i_error("passdb(%s): userdb_uid not returned",
get_log_prefix(auth_request));
}
if (!gid_seen) {
i_error("passdb(%s): userdb_gid not returned",
get_log_prefix(auth_request));
}
if (data.uid == (uid_t)-1 || data.gid == (gid_t)-1)
callback(NULL, context);
else
callback(&data, context);
t_pop();
}
struct userdb_module userdb_passdb = {
"passdb",
NULL,
NULL,
NULL,
passdb_lookup
};
#endif
More information about the dovecot-cvs
mailing list