Mercurial > dovecot > original-hg > dovecot-1.2
annotate src/auth/userdb-static.c @ 8958:16c286aee307 HEAD
Implemented support for per-namespace quotas. Can be used with public namespaces.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Thu, 16 Apr 2009 21:31:30 -0400 |
parents | b9faf4db2a9f |
children | 00cd9aacd03c |
rev | line source |
---|---|
8590
b9faf4db2a9f
Updated copyright notices to include year 2009.
Timo Sirainen <tss@iki.fi>
parents:
8217
diff
changeset
|
1 /* Copyright (c) 2003-2009 Dovecot authors, see the included COPYING file */ |
1035
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 |
3520 | 5 #include "array.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
|
6 #include "str.h" |
fe49ece0f3ea
We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
7 #include "var-expand.h" |
fe49ece0f3ea
We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
8 #include "userdb.h" |
6246
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
9 #include "userdb-static.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 |
fe49ece0f3ea
We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
11 #include <stdlib.h> |
fe49ece0f3ea
We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
12 |
6246
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
13 struct userdb_static_template { |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
14 ARRAY_DEFINE(args, const char *); |
5371
fdcea7e3cf0c
If doing a plain userdb lookup with userdb static, verify the user's
Timo Sirainen <tss@iki.fi>
parents:
4880
diff
changeset
|
15 }; |
fdcea7e3cf0c
If doing a plain userdb lookup with userdb static, verify the user's
Timo Sirainen <tss@iki.fi>
parents:
4880
diff
changeset
|
16 |
6246
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
17 struct userdb_static_template * |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
18 userdb_static_template_build(pool_t pool, const char *userdb_name, |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
19 const char *args) |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
20 { |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
21 struct userdb_static_template *tmpl; |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
22 const char *const *tmp, *key, *value; |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
23 uid_t uid; |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
24 gid_t gid; |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
25 |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
26 tmpl = p_new(pool, struct userdb_static_template, 1); |
3658
fc4622b1c1ef
Separated userdb_module's interface and the actual data struct.
Timo Sirainen <tss@iki.fi>
parents:
3639
diff
changeset
|
27 |
6246
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
28 tmp = t_strsplit_spaces(args, " "); |
6424
687efa138e77
Renamed strarray_length/remote() to str_array_length/remove()
Timo Sirainen <tss@iki.fi>
parents:
6411
diff
changeset
|
29 p_array_init(&tmpl->args, pool, str_array_length(tmp)); |
6246
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
30 |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
31 for (; *tmp != NULL; tmp++) { |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
32 value = strchr(*tmp, '='); |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
33 if (value == NULL) |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
34 key = *tmp; |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
35 else { |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
36 key = t_strdup_until(*tmp, value); |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
37 value++; |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
38 } |
5371
fdcea7e3cf0c
If doing a plain userdb lookup with userdb static, verify the user's
Timo Sirainen <tss@iki.fi>
parents:
4880
diff
changeset
|
39 |
6246
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
40 if (strcasecmp(key, "uid") == 0) { |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
41 uid = userdb_parse_uid(NULL, value); |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
42 if (uid == (uid_t)-1) { |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
43 i_fatal("%s userdb: Invalid uid: %s", |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
44 userdb_name, value); |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
45 } |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
46 value = dec2str(uid); |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
47 } else if (strcasecmp(key, "gid") == 0) { |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
48 gid = userdb_parse_gid(NULL, value); |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
49 if (gid == (gid_t)-1) { |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
50 i_fatal("%s userdb: Invalid gid: %s", |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
51 userdb_name, value); |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
52 } |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
53 value = dec2str(gid); |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
54 } else if (*key == '\0') { |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
55 i_fatal("%s userdb: Empty key (=%s)", |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
56 userdb_name, value); |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
57 } |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
58 key = p_strdup(pool, key); |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
59 value = p_strdup(pool, value); |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
60 |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
61 array_append(&tmpl->args, &key, 1); |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
62 array_append(&tmpl->args, &value, 1); |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
63 } |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
64 return tmpl; |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
65 } |
1035
fe49ece0f3ea
We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
66 |
6246
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
67 bool userdb_static_template_isset(struct userdb_static_template *tmpl, |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
68 const char *key) |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
69 { |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
70 const char *const *args; |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
71 unsigned int i, count; |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
72 |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
73 args = array_get(&tmpl->args, &count); |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
74 i_assert((count % 2) == 0); |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
75 for (i = 0; i < count; i += 2) { |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
76 if (strcmp(args[i], key) == 0) |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
77 return TRUE; |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
78 } |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
79 return FALSE; |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
80 } |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
81 |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
82 bool userdb_static_template_remove(struct userdb_static_template *tmpl, |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
83 const char *key, const char **value_r) |
1035
fe49ece0f3ea
We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
84 { |
6246
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
85 const char *const *args; |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
86 unsigned int i, count; |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
87 |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
88 args = array_get(&tmpl->args, &count); |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
89 i_assert((count % 2) == 0); |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
90 for (i = 0; i < count; i += 2) { |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
91 if (strcmp(args[i], key) == 0) { |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
92 *value_r = args[i+1]; |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
93 array_delete(&tmpl->args, i, 2); |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
94 return TRUE; |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
95 } |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
96 } |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
97 return FALSE; |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
98 } |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
99 |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
100 void userdb_static_template_export(struct userdb_static_template *tmpl, |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
101 struct auth_request *auth_request) |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
102 { |
3520 | 103 const struct var_expand_table *table; |
1035
fe49ece0f3ea
We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
104 string_t *str; |
3639
35a6bc4876e4
Don't crash if there are keys without =value part in static userdb template.
Timo Sirainen <tss@iki.fi>
parents:
3528
diff
changeset
|
105 const char *const *args, *value; |
3520 | 106 unsigned int i, count; |
107 | |
108 str = t_str_new(256); | |
109 table = auth_request_get_var_expand_table(auth_request, NULL); | |
1035
fe49ece0f3ea
We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
110 |
6246
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
111 args = array_get(&tmpl->args, &count); |
3520 | 112 i_assert((count % 2) == 0); |
113 for (i = 0; i < count; i += 2) { | |
3639
35a6bc4876e4
Don't crash if there are keys without =value part in static userdb template.
Timo Sirainen <tss@iki.fi>
parents:
3528
diff
changeset
|
114 if (args[i+1] == NULL) |
35a6bc4876e4
Don't crash if there are keys without =value part in static userdb template.
Timo Sirainen <tss@iki.fi>
parents:
3528
diff
changeset
|
115 value = NULL; |
35a6bc4876e4
Don't crash if there are keys without =value part in static userdb template.
Timo Sirainen <tss@iki.fi>
parents:
3528
diff
changeset
|
116 else { |
35a6bc4876e4
Don't crash if there are keys without =value part in static userdb template.
Timo Sirainen <tss@iki.fi>
parents:
3528
diff
changeset
|
117 str_truncate(str, 0); |
35a6bc4876e4
Don't crash if there are keys without =value part in static userdb template.
Timo Sirainen <tss@iki.fi>
parents:
3528
diff
changeset
|
118 var_expand(str, args[i+1], table); |
35a6bc4876e4
Don't crash if there are keys without =value part in static userdb template.
Timo Sirainen <tss@iki.fi>
parents:
3528
diff
changeset
|
119 value = str_c(str); |
35a6bc4876e4
Don't crash if there are keys without =value part in static userdb template.
Timo Sirainen <tss@iki.fi>
parents:
3528
diff
changeset
|
120 } |
5872
93bd157917ca
Changed userdb callback API. Don't require uid/gid to be returned by userdb.
Timo Sirainen <tss@iki.fi>
parents:
5598
diff
changeset
|
121 auth_request_set_userdb_field(auth_request, args[i], value); |
3520 | 122 } |
6246
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
123 } |
3520 | 124 |
6246
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
125 #ifdef USERDB_STATIC |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
126 |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
127 struct static_context { |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
128 userdb_callback_t *callback, *old_callback; |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
129 void *old_context; |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
130 }; |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
131 |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
132 struct static_userdb_module { |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
133 struct userdb_module module; |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
134 struct userdb_static_template *tmpl; |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
135 |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
136 unsigned int allow_all_users:1; |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
137 }; |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
138 |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
139 static void static_lookup_real(struct auth_request *auth_request, |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
140 userdb_callback_t *callback) |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
141 { |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
142 struct userdb_module *_module = auth_request->userdb->userdb; |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
143 struct static_userdb_module *module = |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
144 (struct static_userdb_module *)_module; |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
145 |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
146 auth_request_init_userdb_reply(auth_request); |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
147 userdb_static_template_export(module->tmpl, auth_request); |
5872
93bd157917ca
Changed userdb callback API. Don't require uid/gid to be returned by userdb.
Timo Sirainen <tss@iki.fi>
parents:
5598
diff
changeset
|
148 callback(USERDB_RESULT_OK, 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
|
149 } |
fe49ece0f3ea
We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
150 |
5475
769aaaee6821
Reverted accidental commit. This code isn't ready yet.
Timo Sirainen <tss@iki.fi>
parents:
5462
diff
changeset
|
151 static void |
5371
fdcea7e3cf0c
If doing a plain userdb lookup with userdb static, verify the user's
Timo Sirainen <tss@iki.fi>
parents:
4880
diff
changeset
|
152 static_credentials_callback(enum passdb_result result, |
6411
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
6246
diff
changeset
|
153 const unsigned char *credentials ATTR_UNUSED, |
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
6246
diff
changeset
|
154 size_t size ATTR_UNUSED, |
5371
fdcea7e3cf0c
If doing a plain userdb lookup with userdb static, verify the user's
Timo Sirainen <tss@iki.fi>
parents:
4880
diff
changeset
|
155 struct auth_request *auth_request) |
fdcea7e3cf0c
If doing a plain userdb lookup with userdb static, verify the user's
Timo Sirainen <tss@iki.fi>
parents:
4880
diff
changeset
|
156 { |
fdcea7e3cf0c
If doing a plain userdb lookup with userdb static, verify the user's
Timo Sirainen <tss@iki.fi>
parents:
4880
diff
changeset
|
157 struct static_context *ctx = auth_request->context; |
fdcea7e3cf0c
If doing a plain userdb lookup with userdb static, verify the user's
Timo Sirainen <tss@iki.fi>
parents:
4880
diff
changeset
|
158 |
fdcea7e3cf0c
If doing a plain userdb lookup with userdb static, verify the user's
Timo Sirainen <tss@iki.fi>
parents:
4880
diff
changeset
|
159 auth_request->private_callback.userdb = ctx->old_callback; |
fdcea7e3cf0c
If doing a plain userdb lookup with userdb static, verify the user's
Timo Sirainen <tss@iki.fi>
parents:
4880
diff
changeset
|
160 auth_request->context = ctx->old_context; |
fdcea7e3cf0c
If doing a plain userdb lookup with userdb static, verify the user's
Timo Sirainen <tss@iki.fi>
parents:
4880
diff
changeset
|
161 auth_request->state = AUTH_REQUEST_STATE_USERDB; |
fdcea7e3cf0c
If doing a plain userdb lookup with userdb static, verify the user's
Timo Sirainen <tss@iki.fi>
parents:
4880
diff
changeset
|
162 |
fdcea7e3cf0c
If doing a plain userdb lookup with userdb static, verify the user's
Timo Sirainen <tss@iki.fi>
parents:
4880
diff
changeset
|
163 switch (result) { |
fdcea7e3cf0c
If doing a plain userdb lookup with userdb static, verify the user's
Timo Sirainen <tss@iki.fi>
parents:
4880
diff
changeset
|
164 case PASSDB_RESULT_OK: |
fdcea7e3cf0c
If doing a plain userdb lookup with userdb static, verify the user's
Timo Sirainen <tss@iki.fi>
parents:
4880
diff
changeset
|
165 static_lookup_real(auth_request, ctx->callback); |
fdcea7e3cf0c
If doing a plain userdb lookup with userdb static, verify the user's
Timo Sirainen <tss@iki.fi>
parents:
4880
diff
changeset
|
166 break; |
fdcea7e3cf0c
If doing a plain userdb lookup with userdb static, verify the user's
Timo Sirainen <tss@iki.fi>
parents:
4880
diff
changeset
|
167 case PASSDB_RESULT_USER_UNKNOWN: |
fdcea7e3cf0c
If doing a plain userdb lookup with userdb static, verify the user's
Timo Sirainen <tss@iki.fi>
parents:
4880
diff
changeset
|
168 case PASSDB_RESULT_USER_DISABLED: |
fdcea7e3cf0c
If doing a plain userdb lookup with userdb static, verify the user's
Timo Sirainen <tss@iki.fi>
parents:
4880
diff
changeset
|
169 case PASSDB_RESULT_PASS_EXPIRED: |
5872
93bd157917ca
Changed userdb callback API. Don't require uid/gid to be returned by userdb.
Timo Sirainen <tss@iki.fi>
parents:
5598
diff
changeset
|
170 ctx->callback(USERDB_RESULT_USER_UNKNOWN, auth_request); |
5371
fdcea7e3cf0c
If doing a plain userdb lookup with userdb static, verify the user's
Timo Sirainen <tss@iki.fi>
parents:
4880
diff
changeset
|
171 break; |
fdcea7e3cf0c
If doing a plain userdb lookup with userdb static, verify the user's
Timo Sirainen <tss@iki.fi>
parents:
4880
diff
changeset
|
172 case PASSDB_RESULT_SCHEME_NOT_AVAILABLE: |
fdcea7e3cf0c
If doing a plain userdb lookup with userdb static, verify the user's
Timo Sirainen <tss@iki.fi>
parents:
4880
diff
changeset
|
173 auth_request_log_error(auth_request, "static", |
fdcea7e3cf0c
If doing a plain userdb lookup with userdb static, verify the user's
Timo Sirainen <tss@iki.fi>
parents:
4880
diff
changeset
|
174 "passdb doesn't support lookups, " |
fdcea7e3cf0c
If doing a plain userdb lookup with userdb static, verify the user's
Timo Sirainen <tss@iki.fi>
parents:
4880
diff
changeset
|
175 "can't verify user's existence"); |
fdcea7e3cf0c
If doing a plain userdb lookup with userdb static, verify the user's
Timo Sirainen <tss@iki.fi>
parents:
4880
diff
changeset
|
176 /* fall through */ |
fdcea7e3cf0c
If doing a plain userdb lookup with userdb static, verify the user's
Timo Sirainen <tss@iki.fi>
parents:
4880
diff
changeset
|
177 default: |
5872
93bd157917ca
Changed userdb callback API. Don't require uid/gid to be returned by userdb.
Timo Sirainen <tss@iki.fi>
parents:
5598
diff
changeset
|
178 ctx->callback(USERDB_RESULT_INTERNAL_FAILURE, auth_request); |
5371
fdcea7e3cf0c
If doing a plain userdb lookup with userdb static, verify the user's
Timo Sirainen <tss@iki.fi>
parents:
4880
diff
changeset
|
179 break; |
fdcea7e3cf0c
If doing a plain userdb lookup with userdb static, verify the user's
Timo Sirainen <tss@iki.fi>
parents:
4880
diff
changeset
|
180 } |
fdcea7e3cf0c
If doing a plain userdb lookup with userdb static, verify the user's
Timo Sirainen <tss@iki.fi>
parents:
4880
diff
changeset
|
181 |
fdcea7e3cf0c
If doing a plain userdb lookup with userdb static, verify the user's
Timo Sirainen <tss@iki.fi>
parents:
4880
diff
changeset
|
182 i_free(ctx); |
fdcea7e3cf0c
If doing a plain userdb lookup with userdb static, verify the user's
Timo Sirainen <tss@iki.fi>
parents:
4880
diff
changeset
|
183 } |
fdcea7e3cf0c
If doing a plain userdb lookup with userdb static, verify the user's
Timo Sirainen <tss@iki.fi>
parents:
4880
diff
changeset
|
184 |
fdcea7e3cf0c
If doing a plain userdb lookup with userdb static, verify the user's
Timo Sirainen <tss@iki.fi>
parents:
4880
diff
changeset
|
185 static void static_lookup(struct auth_request *auth_request, |
fdcea7e3cf0c
If doing a plain userdb lookup with userdb static, verify the user's
Timo Sirainen <tss@iki.fi>
parents:
4880
diff
changeset
|
186 userdb_callback_t *callback) |
fdcea7e3cf0c
If doing a plain userdb lookup with userdb static, verify the user's
Timo Sirainen <tss@iki.fi>
parents:
4880
diff
changeset
|
187 { |
fdcea7e3cf0c
If doing a plain userdb lookup with userdb static, verify the user's
Timo Sirainen <tss@iki.fi>
parents:
4880
diff
changeset
|
188 struct userdb_module *_module = auth_request->userdb->userdb; |
fdcea7e3cf0c
If doing a plain userdb lookup with userdb static, verify the user's
Timo Sirainen <tss@iki.fi>
parents:
4880
diff
changeset
|
189 struct static_userdb_module *module = |
fdcea7e3cf0c
If doing a plain userdb lookup with userdb static, verify the user's
Timo Sirainen <tss@iki.fi>
parents:
4880
diff
changeset
|
190 (struct static_userdb_module *)_module; |
fdcea7e3cf0c
If doing a plain userdb lookup with userdb static, verify the user's
Timo Sirainen <tss@iki.fi>
parents:
4880
diff
changeset
|
191 struct static_context *ctx; |
fdcea7e3cf0c
If doing a plain userdb lookup with userdb static, verify the user's
Timo Sirainen <tss@iki.fi>
parents:
4880
diff
changeset
|
192 |
fdcea7e3cf0c
If doing a plain userdb lookup with userdb static, verify the user's
Timo Sirainen <tss@iki.fi>
parents:
4880
diff
changeset
|
193 if (!auth_request->successful && !module->allow_all_users) { |
fdcea7e3cf0c
If doing a plain userdb lookup with userdb static, verify the user's
Timo Sirainen <tss@iki.fi>
parents:
4880
diff
changeset
|
194 /* this is a userdb-only lookup. we need to know if this |
fdcea7e3cf0c
If doing a plain userdb lookup with userdb static, verify the user's
Timo Sirainen <tss@iki.fi>
parents:
4880
diff
changeset
|
195 users exists or not. use a passdb lookup to do that. |
fdcea7e3cf0c
If doing a plain userdb lookup with userdb static, verify the user's
Timo Sirainen <tss@iki.fi>
parents:
4880
diff
changeset
|
196 if the passdb doesn't support returning credentials, this |
fdcea7e3cf0c
If doing a plain userdb lookup with userdb static, verify the user's
Timo Sirainen <tss@iki.fi>
parents:
4880
diff
changeset
|
197 will of course fail.. */ |
fdcea7e3cf0c
If doing a plain userdb lookup with userdb static, verify the user's
Timo Sirainen <tss@iki.fi>
parents:
4880
diff
changeset
|
198 ctx = i_new(struct static_context, 1); |
fdcea7e3cf0c
If doing a plain userdb lookup with userdb static, verify the user's
Timo Sirainen <tss@iki.fi>
parents:
4880
diff
changeset
|
199 ctx->old_callback = auth_request->private_callback.userdb; |
fdcea7e3cf0c
If doing a plain userdb lookup with userdb static, verify the user's
Timo Sirainen <tss@iki.fi>
parents:
4880
diff
changeset
|
200 ctx->old_context = auth_request->context; |
fdcea7e3cf0c
If doing a plain userdb lookup with userdb static, verify the user's
Timo Sirainen <tss@iki.fi>
parents:
4880
diff
changeset
|
201 ctx->callback = callback; |
fdcea7e3cf0c
If doing a plain userdb lookup with userdb static, verify the user's
Timo Sirainen <tss@iki.fi>
parents:
4880
diff
changeset
|
202 |
fdcea7e3cf0c
If doing a plain userdb lookup with userdb static, verify the user's
Timo Sirainen <tss@iki.fi>
parents:
4880
diff
changeset
|
203 i_assert(auth_request->state == AUTH_REQUEST_STATE_USERDB); |
fdcea7e3cf0c
If doing a plain userdb lookup with userdb static, verify the user's
Timo Sirainen <tss@iki.fi>
parents:
4880
diff
changeset
|
204 auth_request->state = AUTH_REQUEST_STATE_MECH_CONTINUE; |
fdcea7e3cf0c
If doing a plain userdb lookup with userdb static, verify the user's
Timo Sirainen <tss@iki.fi>
parents:
4880
diff
changeset
|
205 |
fdcea7e3cf0c
If doing a plain userdb lookup with userdb static, verify the user's
Timo Sirainen <tss@iki.fi>
parents:
4880
diff
changeset
|
206 auth_request->context = ctx; |
5598
971050640e3b
All password schemes can now be encoded with base64 or hex. The encoding is
Timo Sirainen <tss@iki.fi>
parents:
5593
diff
changeset
|
207 auth_request_lookup_credentials(auth_request, "", |
5371
fdcea7e3cf0c
If doing a plain userdb lookup with userdb static, verify the user's
Timo Sirainen <tss@iki.fi>
parents:
4880
diff
changeset
|
208 static_credentials_callback); |
fdcea7e3cf0c
If doing a plain userdb lookup with userdb static, verify the user's
Timo Sirainen <tss@iki.fi>
parents:
4880
diff
changeset
|
209 } else { |
fdcea7e3cf0c
If doing a plain userdb lookup with userdb static, verify the user's
Timo Sirainen <tss@iki.fi>
parents:
4880
diff
changeset
|
210 static_lookup_real(auth_request, callback); |
fdcea7e3cf0c
If doing a plain userdb lookup with userdb static, verify the user's
Timo Sirainen <tss@iki.fi>
parents:
4880
diff
changeset
|
211 } |
fdcea7e3cf0c
If doing a plain userdb lookup with userdb static, verify the user's
Timo Sirainen <tss@iki.fi>
parents:
4880
diff
changeset
|
212 } |
fdcea7e3cf0c
If doing a plain userdb lookup with userdb static, verify the user's
Timo Sirainen <tss@iki.fi>
parents:
4880
diff
changeset
|
213 |
3658
fc4622b1c1ef
Separated userdb_module's interface and the actual data struct.
Timo Sirainen <tss@iki.fi>
parents:
3639
diff
changeset
|
214 static struct userdb_module * |
fc4622b1c1ef
Separated userdb_module's interface and the actual data struct.
Timo Sirainen <tss@iki.fi>
parents:
3639
diff
changeset
|
215 static_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
|
216 { |
3658
fc4622b1c1ef
Separated userdb_module's interface and the actual data struct.
Timo Sirainen <tss@iki.fi>
parents:
3639
diff
changeset
|
217 struct static_userdb_module *module; |
6246
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
218 const char *value; |
3658
fc4622b1c1ef
Separated userdb_module's interface and the actual data struct.
Timo Sirainen <tss@iki.fi>
parents:
3639
diff
changeset
|
219 |
6246
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
220 module = p_new(auth_userdb->auth->pool, struct static_userdb_module, 1); |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
221 module->tmpl = userdb_static_template_build(auth_userdb->auth->pool, |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
222 "static", args); |
3520 | 223 |
6246
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
224 if (userdb_static_template_remove(module->tmpl, "allow_all_users", |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
225 &value)) { |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
226 module->allow_all_users = value == NULL || |
1cc70ab3482a
userdb passwd supports now adding key=value fields to args. They can
Timo Sirainen <tss@iki.fi>
parents:
6245
diff
changeset
|
227 strcasecmp(value, "yes") == 0; |
1035
fe49ece0f3ea
We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
228 } |
3658
fc4622b1c1ef
Separated userdb_module's interface and the actual data struct.
Timo Sirainen <tss@iki.fi>
parents:
3639
diff
changeset
|
229 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
|
230 } |
fe49ece0f3ea
We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
231 |
3658
fc4622b1c1ef
Separated userdb_module's interface and the actual data struct.
Timo Sirainen <tss@iki.fi>
parents:
3639
diff
changeset
|
232 struct userdb_module_interface userdb_static = { |
2942
c7d426f8cb58
Added name variable for userdb_module and passdb_module and changed their
Timo Sirainen <tss@iki.fi>
parents:
2648
diff
changeset
|
233 "static", |
c7d426f8cb58
Added name variable for userdb_module and passdb_module and changed their
Timo Sirainen <tss@iki.fi>
parents:
2648
diff
changeset
|
234 |
3658
fc4622b1c1ef
Separated userdb_module's interface and the actual data struct.
Timo Sirainen <tss@iki.fi>
parents:
3639
diff
changeset
|
235 static_preinit, |
2648
cc2e39912eb3
Added preinit() call to userdb/passdbs, which is called before dropping
Timo Sirainen <tss@iki.fi>
parents:
2515
diff
changeset
|
236 NULL, |
3658
fc4622b1c1ef
Separated userdb_module's interface and the actual data struct.
Timo Sirainen <tss@iki.fi>
parents:
3639
diff
changeset
|
237 NULL, |
1035
fe49ece0f3ea
We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
238 |
fe49ece0f3ea
We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
239 static_lookup |
fe49ece0f3ea
We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
240 }; |
8217
c47b78e843aa
Separate "unknown passdb/userdb X" and "support for X not compiled in" error messages.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
241 #else |
c47b78e843aa
Separate "unknown passdb/userdb X" and "support for X not compiled in" error messages.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
242 struct userdb_module_interface userdb_static = { |
c47b78e843aa
Separate "unknown passdb/userdb X" and "support for X not compiled in" error messages.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
243 MEMBER(name) "static" |
c47b78e843aa
Separate "unknown passdb/userdb X" and "support for X not compiled in" error messages.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
244 }; |
1035
fe49ece0f3ea
We have now separate "userdb" and "passdb". They aren't tied to each others
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
245 #endif |