annotate src/auth/userdb-passwd-file.c @ 5304:afcb29d8faff HEAD

Don't expand %variables in extra fields, let dovecot master do that.
author Timo Sirainen <tss@iki.fi>
date Wed, 14 Mar 2007 15:59:05 +0200
parents f0cc5486696e
children 1c6c3d9494fb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1035
fe49ece0f3ea We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1 /* Copyright (C) 2002-2003 Timo Sirainen */
fe49ece0f3ea We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2
3474
9096b7957413 Removed direct config.h including. I'm not sure why it was done before,
Timo Sirainen <tss@iki.fi>
parents: 3166
diff changeset
3 #include "common.h"
1035
fe49ece0f3ea We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
4
fe49ece0f3ea We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
5 #ifdef USERDB_PASSWD_FILE
fe49ece0f3ea We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
6
3158
8849f2e380d1 userdb can now return extra parameters to master. Removed special handling
Timo Sirainen <tss@iki.fi>
parents: 3127
diff changeset
7 #include "str.h"
4955
f0cc5486696e Authentication cache caches now also userdb data. Code by Tommi Saviranta.
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4880
diff changeset
8 #include "auth-cache.h"
4034
b533c52196e3 Updated passwd-file format to allow specifying any key=value fields. Since the value fields may contain ':' characters, this changes the file format a bit. Previously the last two fields were "flags" and "mail". Flags has been empty for last 3 years however, so the new format is used if the flags field contains something. In that case there is no separate mail field, it can instead be specified by adding userdb_mail=<mail> parameter.
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3891
diff changeset
9 #include "var-expand.h"
1035
fe49ece0f3ea We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
10 #include "userdb.h"
1062
0522a0315d2f Cleanups, LDAP support compiles again and generally looks ok, even if it
Timo Sirainen <tss@iki.fi>
parents: 1046
diff changeset
11 #include "db-passwd-file.h"
1035
fe49ece0f3ea We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
12
4955
f0cc5486696e Authentication cache caches now also userdb data. Code by Tommi Saviranta.
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4880
diff changeset
13 #define PASSWD_FILE_CACHE_KEY "%u"
f0cc5486696e Authentication cache caches now also userdb data. Code by Tommi Saviranta.
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4880
diff changeset
14
3658
fc4622b1c1ef Separated userdb_module's interface and the actual data struct.
Timo Sirainen <tss@iki.fi>
parents: 3657
diff changeset
15 struct passwd_file_userdb_module {
fc4622b1c1ef Separated userdb_module's interface and the actual data struct.
Timo Sirainen <tss@iki.fi>
parents: 3657
diff changeset
16 struct userdb_module module;
fc4622b1c1ef Separated userdb_module's interface and the actual data struct.
Timo Sirainen <tss@iki.fi>
parents: 3657
diff changeset
17
3891
2d0859490a2f If debug is enabled, tell how many users are found from passwd-file whenever
Timo Sirainen <tss@iki.fi>
parents: 3879
diff changeset
18 struct auth *auth;
3658
fc4622b1c1ef Separated userdb_module's interface and the actual data struct.
Timo Sirainen <tss@iki.fi>
parents: 3657
diff changeset
19 struct db_passwd_file *pwf;
fc4622b1c1ef Separated userdb_module's interface and the actual data struct.
Timo Sirainen <tss@iki.fi>
parents: 3657
diff changeset
20 };
1035
fe49ece0f3ea We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
21
2057
5e0167577399 Fixed var_expand() to take a table of variables rather than a few predefined
Timo Sirainen <tss@iki.fi>
parents: 1443
diff changeset
22 static void passwd_file_lookup(struct auth_request *auth_request,
3166
e6a487d80288 Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents: 3158
diff changeset
23 userdb_callback_t *callback)
1035
fe49ece0f3ea We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
24 {
3658
fc4622b1c1ef Separated userdb_module's interface and the actual data struct.
Timo Sirainen <tss@iki.fi>
parents: 3657
diff changeset
25 struct userdb_module *_module = auth_request->userdb->userdb;
fc4622b1c1ef Separated userdb_module's interface and the actual data struct.
Timo Sirainen <tss@iki.fi>
parents: 3657
diff changeset
26 struct passwd_file_userdb_module *module =
fc4622b1c1ef Separated userdb_module's interface and the actual data struct.
Timo Sirainen <tss@iki.fi>
parents: 3657
diff changeset
27 (struct passwd_file_userdb_module *)_module;
3520
e2fe8222449d s/occured/occurred/
Timo Sirainen <tss@iki.fi>
parents: 3504
diff changeset
28 struct auth_stream_reply *reply;
1035
fe49ece0f3ea We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
29 struct passwd_user *pu;
4034
b533c52196e3 Updated passwd-file format to allow specifying any key=value fields. Since the value fields may contain ':' characters, this changes the file format a bit. Previously the last two fields were "flags" and "mail". Flags has been empty for last 3 years however, so the new format is used if the flags field contains something. In that case there is no separate mail field, it can instead be specified by adding userdb_mail=<mail> parameter.
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3891
diff changeset
30 const char *key, *value;
b533c52196e3 Updated passwd-file format to allow specifying any key=value fields. Since the value fields may contain ':' characters, this changes the file format a bit. Previously the last two fields were "flags" and "mail". Flags has been empty for last 3 years however, so the new format is used if the flags field contains something. In that case there is no separate mail field, it can instead be specified by adding userdb_mail=<mail> parameter.
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3891
diff changeset
31 char **p;
1035
fe49ece0f3ea We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
32
3658
fc4622b1c1ef Separated userdb_module's interface and the actual data struct.
Timo Sirainen <tss@iki.fi>
parents: 3657
diff changeset
33 pu = db_passwd_file_lookup(module->pwf, auth_request);
1046
561da07883b6 Async userdb and passdb interface.
Timo Sirainen <tss@iki.fi>
parents: 1035
diff changeset
34 if (pu == NULL) {
4880
4ec6a4def05b We treated internal userdb lookup errors as "user unknown" errors. In such
Timo Sirainen <tss@iki.fi>
parents: 4035
diff changeset
35 callback(USERDB_RESULT_USER_UNKNOWN, NULL, auth_request);
1046
561da07883b6 Async userdb and passdb interface.
Timo Sirainen <tss@iki.fi>
parents: 1035
diff changeset
36 return;
561da07883b6 Async userdb and passdb interface.
Timo Sirainen <tss@iki.fi>
parents: 1035
diff changeset
37 }
1035
fe49ece0f3ea We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
38
3520
e2fe8222449d s/occured/occurred/
Timo Sirainen <tss@iki.fi>
parents: 3504
diff changeset
39 reply = auth_stream_reply_init(auth_request);
e2fe8222449d s/occured/occurred/
Timo Sirainen <tss@iki.fi>
parents: 3504
diff changeset
40 auth_stream_reply_add(reply, NULL, auth_request->user);
e2fe8222449d s/occured/occurred/
Timo Sirainen <tss@iki.fi>
parents: 3504
diff changeset
41 auth_stream_reply_add(reply, "uid", dec2str(pu->uid));
e2fe8222449d s/occured/occurred/
Timo Sirainen <tss@iki.fi>
parents: 3504
diff changeset
42 auth_stream_reply_add(reply, "gid", dec2str(pu->gid));
1035
fe49ece0f3ea We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
43
3158
8849f2e380d1 userdb can now return extra parameters to master. Removed special handling
Timo Sirainen <tss@iki.fi>
parents: 3127
diff changeset
44 if (pu->home != NULL)
3520
e2fe8222449d s/occured/occurred/
Timo Sirainen <tss@iki.fi>
parents: 3504
diff changeset
45 auth_stream_reply_add(reply, "home", pu->home);
4034
b533c52196e3 Updated passwd-file format to allow specifying any key=value fields. Since the value fields may contain ':' characters, this changes the file format a bit. Previously the last two fields were "flags" and "mail". Flags has been empty for last 3 years however, so the new format is used if the flags field contains something. In that case there is no separate mail field, it can instead be specified by adding userdb_mail=<mail> parameter.
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3891
diff changeset
46
4035
335ac59efffd If passwd-file is being used as userdb, complain immediately if some entries
Timo Sirainen <tss@iki.fi>
parents: 4034
diff changeset
47 if (pu->extra_fields != NULL) {
335ac59efffd If passwd-file is being used as userdb, complain immediately if some entries
Timo Sirainen <tss@iki.fi>
parents: 4034
diff changeset
48 t_push();
335ac59efffd If passwd-file is being used as userdb, complain immediately if some entries
Timo Sirainen <tss@iki.fi>
parents: 4034
diff changeset
49 for (p = pu->extra_fields; *p != NULL; p++) {
335ac59efffd If passwd-file is being used as userdb, complain immediately if some entries
Timo Sirainen <tss@iki.fi>
parents: 4034
diff changeset
50 if (strncmp(*p, "userdb_", 7) != 0)
335ac59efffd If passwd-file is being used as userdb, complain immediately if some entries
Timo Sirainen <tss@iki.fi>
parents: 4034
diff changeset
51 continue;
4034
b533c52196e3 Updated passwd-file format to allow specifying any key=value fields. Since the value fields may contain ':' characters, this changes the file format a bit. Previously the last two fields were "flags" and "mail". Flags has been empty for last 3 years however, so the new format is used if the flags field contains something. In that case there is no separate mail field, it can instead be specified by adding userdb_mail=<mail> parameter.
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3891
diff changeset
52
4035
335ac59efffd If passwd-file is being used as userdb, complain immediately if some entries
Timo Sirainen <tss@iki.fi>
parents: 4034
diff changeset
53 key = *p + 7;
335ac59efffd If passwd-file is being used as userdb, complain immediately if some entries
Timo Sirainen <tss@iki.fi>
parents: 4034
diff changeset
54 value = strchr(key, '=');
5304
afcb29d8faff Don't expand %variables in extra fields, let dovecot master do that.
Timo Sirainen <tss@iki.fi>
parents: 4955
diff changeset
55 if (value != NULL)
afcb29d8faff Don't expand %variables in extra fields, let dovecot master do that.
Timo Sirainen <tss@iki.fi>
parents: 4955
diff changeset
56 key = t_strdup_until(key, value++);
4035
335ac59efffd If passwd-file is being used as userdb, complain immediately if some entries
Timo Sirainen <tss@iki.fi>
parents: 4034
diff changeset
57 auth_stream_reply_add(reply, key, value);
4034
b533c52196e3 Updated passwd-file format to allow specifying any key=value fields. Since the value fields may contain ':' characters, this changes the file format a bit. Previously the last two fields were "flags" and "mail". Flags has been empty for last 3 years however, so the new format is used if the flags field contains something. In that case there is no separate mail field, it can instead be specified by adding userdb_mail=<mail> parameter.
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3891
diff changeset
58 }
4035
335ac59efffd If passwd-file is being used as userdb, complain immediately if some entries
Timo Sirainen <tss@iki.fi>
parents: 4034
diff changeset
59 t_pop();
4034
b533c52196e3 Updated passwd-file format to allow specifying any key=value fields. Since the value fields may contain ':' characters, this changes the file format a bit. Previously the last two fields were "flags" and "mail". Flags has been empty for last 3 years however, so the new format is used if the flags field contains something. In that case there is no separate mail field, it can instead be specified by adding userdb_mail=<mail> parameter.
Timo Sirainen <timo.sirainen@movial.fi>
parents: 3891
diff changeset
60 }
1035
fe49ece0f3ea We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
61
4880
4ec6a4def05b We treated internal userdb lookup errors as "user unknown" errors. In such
Timo Sirainen <tss@iki.fi>
parents: 4035
diff changeset
62 callback(USERDB_RESULT_OK, reply, auth_request);
1035
fe49ece0f3ea We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
63 }
fe49ece0f3ea We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
64
3658
fc4622b1c1ef Separated userdb_module's interface and the actual data struct.
Timo Sirainen <tss@iki.fi>
parents: 3657
diff changeset
65 static struct userdb_module *
4035
335ac59efffd If passwd-file is being used as userdb, complain immediately if some entries
Timo Sirainen <tss@iki.fi>
parents: 4034
diff changeset
66 passwd_file_preinit(struct auth_userdb *auth_userdb, const char *args)
1035
fe49ece0f3ea We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
67 {
3658
fc4622b1c1ef Separated userdb_module's interface and the actual data struct.
Timo Sirainen <tss@iki.fi>
parents: 3657
diff changeset
68 struct passwd_file_userdb_module *module;
fc4622b1c1ef Separated userdb_module's interface and the actual data struct.
Timo Sirainen <tss@iki.fi>
parents: 3657
diff changeset
69
fc4622b1c1ef Separated userdb_module's interface and the actual data struct.
Timo Sirainen <tss@iki.fi>
parents: 3657
diff changeset
70 module = p_new(auth_userdb->auth->pool,
fc4622b1c1ef Separated userdb_module's interface and the actual data struct.
Timo Sirainen <tss@iki.fi>
parents: 3657
diff changeset
71 struct passwd_file_userdb_module, 1);
3891
2d0859490a2f If debug is enabled, tell how many users are found from passwd-file whenever
Timo Sirainen <tss@iki.fi>
parents: 3879
diff changeset
72 module->auth = auth_userdb->auth;
4035
335ac59efffd If passwd-file is being used as userdb, complain immediately if some entries
Timo Sirainen <tss@iki.fi>
parents: 4034
diff changeset
73 module->pwf =
335ac59efffd If passwd-file is being used as userdb, complain immediately if some entries
Timo Sirainen <tss@iki.fi>
parents: 4034
diff changeset
74 db_passwd_file_init(args, TRUE, module->auth->verbose_debug);
4955
f0cc5486696e Authentication cache caches now also userdb data. Code by Tommi Saviranta.
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4880
diff changeset
75
f0cc5486696e Authentication cache caches now also userdb data. Code by Tommi Saviranta.
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4880
diff changeset
76 if (!module->pwf->vars)
f0cc5486696e Authentication cache caches now also userdb data. Code by Tommi Saviranta.
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4880
diff changeset
77 module->module.cache_key = PASSWD_FILE_CACHE_KEY;
f0cc5486696e Authentication cache caches now also userdb data. Code by Tommi Saviranta.
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4880
diff changeset
78 else {
f0cc5486696e Authentication cache caches now also userdb data. Code by Tommi Saviranta.
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4880
diff changeset
79 module->module.cache_key =
f0cc5486696e Authentication cache caches now also userdb data. Code by Tommi Saviranta.
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4880
diff changeset
80 auth_cache_parse_key(auth_userdb->auth->pool,
f0cc5486696e Authentication cache caches now also userdb data. Code by Tommi Saviranta.
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4880
diff changeset
81 t_strconcat(PASSWD_FILE_CACHE_KEY,
f0cc5486696e Authentication cache caches now also userdb data. Code by Tommi Saviranta.
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4880
diff changeset
82 module->pwf->path,
f0cc5486696e Authentication cache caches now also userdb data. Code by Tommi Saviranta.
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4880
diff changeset
83 NULL));
f0cc5486696e Authentication cache caches now also userdb data. Code by Tommi Saviranta.
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4880
diff changeset
84 }
3658
fc4622b1c1ef Separated userdb_module's interface and the actual data struct.
Timo Sirainen <tss@iki.fi>
parents: 3657
diff changeset
85 return &module->module;
1035
fe49ece0f3ea We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
86 }
fe49ece0f3ea We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
87
4035
335ac59efffd If passwd-file is being used as userdb, complain immediately if some entries
Timo Sirainen <tss@iki.fi>
parents: 4034
diff changeset
88 static void passwd_file_init(struct userdb_module *_module,
335ac59efffd If passwd-file is being used as userdb, complain immediately if some entries
Timo Sirainen <tss@iki.fi>
parents: 4034
diff changeset
89 const char *args __attr_unused__)
1035
fe49ece0f3ea We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
90 {
3658
fc4622b1c1ef Separated userdb_module's interface and the actual data struct.
Timo Sirainen <tss@iki.fi>
parents: 3657
diff changeset
91 struct passwd_file_userdb_module *module =
fc4622b1c1ef Separated userdb_module's interface and the actual data struct.
Timo Sirainen <tss@iki.fi>
parents: 3657
diff changeset
92 (struct passwd_file_userdb_module *)_module;
fc4622b1c1ef Separated userdb_module's interface and the actual data struct.
Timo Sirainen <tss@iki.fi>
parents: 3657
diff changeset
93
4035
335ac59efffd If passwd-file is being used as userdb, complain immediately if some entries
Timo Sirainen <tss@iki.fi>
parents: 4034
diff changeset
94 db_passwd_file_parse(module->pwf);
1035
fe49ece0f3ea We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
95 }
fe49ece0f3ea We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
96
3658
fc4622b1c1ef Separated userdb_module's interface and the actual data struct.
Timo Sirainen <tss@iki.fi>
parents: 3657
diff changeset
97 static void passwd_file_deinit(struct userdb_module *_module)
fc4622b1c1ef Separated userdb_module's interface and the actual data struct.
Timo Sirainen <tss@iki.fi>
parents: 3657
diff changeset
98 {
fc4622b1c1ef Separated userdb_module's interface and the actual data struct.
Timo Sirainen <tss@iki.fi>
parents: 3657
diff changeset
99 struct passwd_file_userdb_module *module =
fc4622b1c1ef Separated userdb_module's interface and the actual data struct.
Timo Sirainen <tss@iki.fi>
parents: 3657
diff changeset
100 (struct passwd_file_userdb_module *)_module;
fc4622b1c1ef Separated userdb_module's interface and the actual data struct.
Timo Sirainen <tss@iki.fi>
parents: 3657
diff changeset
101
3879
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3658
diff changeset
102 db_passwd_file_unref(&module->pwf);
3658
fc4622b1c1ef Separated userdb_module's interface and the actual data struct.
Timo Sirainen <tss@iki.fi>
parents: 3657
diff changeset
103 }
fc4622b1c1ef Separated userdb_module's interface and the actual data struct.
Timo Sirainen <tss@iki.fi>
parents: 3657
diff changeset
104
fc4622b1c1ef Separated userdb_module's interface and the actual data struct.
Timo Sirainen <tss@iki.fi>
parents: 3657
diff changeset
105 struct userdb_module_interface userdb_passwd_file = {
2942
c7d426f8cb58 Added name variable for userdb_module and passdb_module and changed their
Timo Sirainen <tss@iki.fi>
parents: 2648
diff changeset
106 "passwd-file",
c7d426f8cb58 Added name variable for userdb_module and passdb_module and changed their
Timo Sirainen <tss@iki.fi>
parents: 2648
diff changeset
107
3658
fc4622b1c1ef Separated userdb_module's interface and the actual data struct.
Timo Sirainen <tss@iki.fi>
parents: 3657
diff changeset
108 passwd_file_preinit,
1035
fe49ece0f3ea We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
109 passwd_file_init,
fe49ece0f3ea We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
110 passwd_file_deinit,
fe49ece0f3ea We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
111
fe49ece0f3ea We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
112 passwd_file_lookup
fe49ece0f3ea We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
113 };
fe49ece0f3ea We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
114
fe49ece0f3ea We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
115 #endif