[Dovecot] passwd-userdb with args
Thomas Wouters
thomas at xs4all.net
Fri Feb 3 14:43:33 EET 2006
I'm not sure why the 'passwd' userdb didn't allow args, but it meant (for
instance) that the quota plugins weren't usable. I spent quite a bit of time
trying to get my new quota-rquotad plugin to work, only to find out that it
was my 'quota=rquotad:<filesystem list>' argument that wasn't being passed
to the imap child :)
The attached patch implements arguments for the 'passwd' userdb, just like
it exists for the 'static' userdb (in fact, mostly copy-pasted from
'static'.) It doesn't try to avoid clashing with the values found in the
passwd-struct, but I suspect it ends up overwriting them. That could
probably be a feature ;) I don't use the passwd-file userdb, but that one
would probably also enjoy being argified.
--
Thomas Wouters <thomas at xs4all.net>
Hi! I'm a .signature virus! copy me into your .signature file to help me spread!
-------------- next part --------------
Index: src/auth/userdb-passwd.c
===================================================================
RCS file: /home/cvs/dovecot/src/auth/userdb-passwd.c,v
retrieving revision 1.18
diff -c -r1.18 userdb-passwd.c
*** src/auth/userdb-passwd.c 16 Oct 2005 14:34:39 -0000 1.18
--- src/auth/userdb-passwd.c 3 Feb 2006 12:34:22 -0000
***************
*** 4,18 ****
--- 4,34 ----
#ifdef USERDB_PASSWD
+ #include "array.h"
+ #include "str.h"
+ #include "var-expand.h"
#include "userdb.h"
#include <pwd.h>
+ struct passwd_userdb_module {
+ struct userdb_module module;
+
+ array_t ARRAY_DEFINE(template, const char *);
+ };
+
static void passwd_lookup(struct auth_request *auth_request,
userdb_callback_t *callback)
{
+ struct userdb_module *_module = auth_request->userdb->userdb;
+ struct passwd_userdb_module *module =
+ (struct passwd_userdb_module *)_module;
struct passwd *pw;
struct auth_stream_reply *reply;
+ const struct var_expand_table *table;
+ string_t *str;
+ const char *const *args, *value;
+ unsigned int i, count;
pw = getpwnam(auth_request->user);
if (pw == NULL) {
***************
*** 29,48 ****
pw->pw_name, auth_request->user);
}
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_interface userdb_passwd = {
"passwd",
! NULL, NULL, NULL,
passwd_lookup
};
--- 45,118 ----
pw->pw_name, auth_request->user);
}
+ 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, 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);
+ /* auth_stream_reply_add(reply, "quota", "rquotad:/var/spool/mail/.3a/S,/var/spool/mail/.3b/S,/var/spool/mail/.4a/S,/var/spool/mail/.4b/S,/var/spool/mail/.3a/L,/var/spool/mail/.3b/L,/var/spool/mail/.4a/L,/var/spool/mail/.4b/L,/home/.1,/home/.2"); */
+
+ args = array_get(&module->template, &count);
+ i_assert((count % 2) == 0);
+ for (i = 0; i < count; i += 2) {
+ if (args[i+1] == NULL)
+ value = NULL;
+ else {
+ str_truncate(str, 0);
+ var_expand(str, args[i+1], table);
+ value = str_c(str);
+ }
+ auth_stream_reply_add(reply, args[i], value);
+ }
callback(reply, auth_request);
+ t_pop();
+ }
+
+ static struct userdb_module *
+ passwd_preinit(struct auth_userdb *auth_userdb, const char *args)
+ {
+ struct passwd_userdb_module *module;
+ const char *const *tmp, *key, *value;
+
+ module = p_new(auth_userdb->auth->pool, struct passwd_userdb_module, 1);
+
+ tmp = t_strsplit_spaces(args, " ");
+ ARRAY_CREATE(&module->template, auth_userdb->auth->pool,
+ const char *, strarray_length(tmp));
+
+ t_push();
+ for (; *tmp != NULL; tmp++) {
+ value = strchr(*tmp, '=');
+ if (value == NULL)
+ key = *tmp;
+ else {
+ key = t_strdup_until(*tmp, value);
+ value++;
+ }
+
+ key = p_strdup(auth_userdb->auth->pool, key);
+ value = p_strdup(auth_userdb->auth->pool, value);
+
+ array_append(&module->template, &key, 1);
+ array_append(&module->template, &value, 1);
+ }
+ t_pop();
+
+ return &module->module;
}
struct userdb_module_interface userdb_passwd = {
"passwd",
! passwd_preinit,
! NULL,
! NULL,
passwd_lookup
};
More information about the dovecot
mailing list