Mercurial > dovecot > core-2.2
annotate src/auth/userinfo-passwd-file.c @ 903:fd8888f6f037 HEAD
Naming style changes, finally got tired of most of the typedefs. Also the
previous enum -> macro change reverted so that we don't use the highest bit
anymore, that's incompatible with old indexes so they will be rebuilt.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sun, 05 Jan 2003 15:09:51 +0200 |
parents | 5043e48c022f |
children | 2d6db119ca9a |
rev | line source |
---|---|
0 | 1 /* Copyright (C) 2002 Timo Sirainen */ |
2 | |
571
944dbdc61f3d
Fixed warnings when compiling with Solaris 8
Timo Sirainen <tss@iki.fi>
parents:
546
diff
changeset
|
3 #include "config.h" |
944dbdc61f3d
Fixed warnings when compiling with Solaris 8
Timo Sirainen <tss@iki.fi>
parents:
546
diff
changeset
|
4 #undef HAVE_CONFIG_H |
0 | 5 |
6 #ifdef USERINFO_PASSWD_FILE | |
7 | |
571
944dbdc61f3d
Fixed warnings when compiling with Solaris 8
Timo Sirainen <tss@iki.fi>
parents:
546
diff
changeset
|
8 #include "userinfo-passwd.h" |
944dbdc61f3d
Fixed warnings when compiling with Solaris 8
Timo Sirainen <tss@iki.fi>
parents:
546
diff
changeset
|
9 |
765
553f050c8313
Added buffer API. Point is to hide all buffer writing behind this API which
Timo Sirainen <tss@iki.fi>
parents:
764
diff
changeset
|
10 #include "buffer.h" |
764
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
686
diff
changeset
|
11 #include "istream.h" |
0 | 12 #include "hash.h" |
13 #include "hex-binary.h" | |
14 #include "md5.h" | |
686
ae9e39383a72
Still more crypt() problems. Wrapped it into mycrypt() which should finally
Timo Sirainen <tss@iki.fi>
parents:
619
diff
changeset
|
15 #include "mycrypt.h" |
0 | 16 |
17 #include <stdlib.h> | |
18 #include <fcntl.h> | |
19 #include <sys/stat.h> | |
20 | |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
902
diff
changeset
|
21 struct passwd_file { |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
902
diff
changeset
|
22 pool_t pool; |
0 | 23 |
24 char *path; | |
25 time_t stamp; | |
26 int fd; | |
27 | |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
902
diff
changeset
|
28 struct hash_table *users; |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
902
diff
changeset
|
29 }; |
0 | 30 |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
902
diff
changeset
|
31 enum password_type { |
0 | 32 PASSWORD_DES, |
33 PASSWORD_MD5, | |
34 PASSWORD_DIGEST_MD5 | |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
902
diff
changeset
|
35 }; |
0 | 36 |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
902
diff
changeset
|
37 struct passwd_user { |
0 | 38 char *user_realm; /* user:realm */ |
39 const char *realm; /* NULL or points to user_realm */ | |
40 char *password; | |
41 char *home; | |
42 char *mail; | |
43 | |
44 uid_t uid; | |
45 gid_t gid; | |
46 | |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
902
diff
changeset
|
47 enum password_type password_type; |
0 | 48 unsigned int chroot:1; |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
902
diff
changeset
|
49 }; |
0 | 50 |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
902
diff
changeset
|
51 static struct passwd_file *passwd_file; |
0 | 52 |
619
fcdff89c3df2
re-read passwd file when it changes.
Timo Sirainen <tss@iki.fi>
parents:
571
diff
changeset
|
53 static void passwd_file_sync(void); |
fcdff89c3df2
re-read passwd file when it changes.
Timo Sirainen <tss@iki.fi>
parents:
571
diff
changeset
|
54 |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
902
diff
changeset
|
55 static int get_reply_data(struct passwd_user *pu, |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
902
diff
changeset
|
56 struct auth_cookie_reply_data *reply) |
0 | 57 { |
58 const char *user; | |
59 struct passwd *pw; | |
60 | |
61 if (pu->uid == 0 || pu->gid == 0 || | |
62 (pu->home == NULL && pu->mail == NULL)) { | |
63 /* all required information was not set in passwd file, | |
64 check from system's passwd */ | |
65 user = pu->realm == NULL ? pu->user_realm : | |
66 t_strndup(pu->user_realm, strlen(pu->user_realm) - | |
67 strlen(pu->realm) - 1); | |
68 | |
69 pw = getpwnam(user); | |
70 if (pw == NULL) | |
71 return FALSE; | |
72 | |
73 passwd_fill_cookie_reply(pw, reply); | |
74 } | |
75 | |
76 if (pu->uid != 0) | |
77 reply->uid = pu->uid; | |
78 if (pu->gid != 0) | |
79 reply->gid = pu->gid; | |
80 | |
81 if (pu->home != NULL) { | |
807
35abd7a5d381
Buffer related cleanups. Use PATH_MAX instead of hardcoded 1024 for paths.
Timo Sirainen <tss@iki.fi>
parents:
805
diff
changeset
|
82 if (strocpy(reply->home, pu->home, sizeof(reply->home)) < 0) |
35abd7a5d381
Buffer related cleanups. Use PATH_MAX instead of hardcoded 1024 for paths.
Timo Sirainen <tss@iki.fi>
parents:
805
diff
changeset
|
83 i_panic("home overflow"); |
0 | 84 } |
85 | |
86 if (pu->mail != NULL) { | |
807
35abd7a5d381
Buffer related cleanups. Use PATH_MAX instead of hardcoded 1024 for paths.
Timo Sirainen <tss@iki.fi>
parents:
805
diff
changeset
|
87 if (strocpy(reply->mail, pu->mail, sizeof(reply->mail)) < 0) |
35abd7a5d381
Buffer related cleanups. Use PATH_MAX instead of hardcoded 1024 for paths.
Timo Sirainen <tss@iki.fi>
parents:
805
diff
changeset
|
88 i_panic("mail overflow"); |
0 | 89 } |
90 | |
807
35abd7a5d381
Buffer related cleanups. Use PATH_MAX instead of hardcoded 1024 for paths.
Timo Sirainen <tss@iki.fi>
parents:
805
diff
changeset
|
91 if (strocpy(reply->virtual_user, pu->user_realm, |
35abd7a5d381
Buffer related cleanups. Use PATH_MAX instead of hardcoded 1024 for paths.
Timo Sirainen <tss@iki.fi>
parents:
805
diff
changeset
|
92 sizeof(reply->virtual_user)) < 0) |
35abd7a5d381
Buffer related cleanups. Use PATH_MAX instead of hardcoded 1024 for paths.
Timo Sirainen <tss@iki.fi>
parents:
805
diff
changeset
|
93 i_panic("virtual_user overflow"); |
791
6efced4f80de
Clear separation of virtual and system usernames. passwd-file didn't work
Timo Sirainen <tss@iki.fi>
parents:
772
diff
changeset
|
94 |
6efced4f80de
Clear separation of virtual and system usernames. passwd-file didn't work
Timo Sirainen <tss@iki.fi>
parents:
772
diff
changeset
|
95 if (pu->realm != NULL) { |
807
35abd7a5d381
Buffer related cleanups. Use PATH_MAX instead of hardcoded 1024 for paths.
Timo Sirainen <tss@iki.fi>
parents:
805
diff
changeset
|
96 /* @UNSAFE: ':' -> '@' to make it look prettier */ |
791
6efced4f80de
Clear separation of virtual and system usernames. passwd-file didn't work
Timo Sirainen <tss@iki.fi>
parents:
772
diff
changeset
|
97 size_t pos; |
6efced4f80de
Clear separation of virtual and system usernames. passwd-file didn't work
Timo Sirainen <tss@iki.fi>
parents:
772
diff
changeset
|
98 |
6efced4f80de
Clear separation of virtual and system usernames. passwd-file didn't work
Timo Sirainen <tss@iki.fi>
parents:
772
diff
changeset
|
99 pos = (size_t) (pu->realm - (const char *) pu->user_realm); |
902 | 100 reply->virtual_user[pos-1] = '@'; |
791
6efced4f80de
Clear separation of virtual and system usernames. passwd-file didn't work
Timo Sirainen <tss@iki.fi>
parents:
772
diff
changeset
|
101 } |
6efced4f80de
Clear separation of virtual and system usernames. passwd-file didn't work
Timo Sirainen <tss@iki.fi>
parents:
772
diff
changeset
|
102 |
0 | 103 reply->chroot = pu->chroot; |
104 return TRUE; | |
105 } | |
106 | |
107 static int passwd_file_verify_plain(const char *user, const char *password, | |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
902
diff
changeset
|
108 struct auth_cookie_reply_data *reply) |
0 | 109 { |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
902
diff
changeset
|
110 struct passwd_user *pu; |
847
7f41a4b33975
t_strsplit() returns now const char **, which removes a few nasty casts.
Timo Sirainen <tss@iki.fi>
parents:
825
diff
changeset
|
111 const char *const *tmp; |
0 | 112 unsigned char digest[16]; |
113 const char *str; | |
114 | |
619
fcdff89c3df2
re-read passwd file when it changes.
Timo Sirainen <tss@iki.fi>
parents:
571
diff
changeset
|
115 passwd_file_sync(); |
fcdff89c3df2
re-read passwd file when it changes.
Timo Sirainen <tss@iki.fi>
parents:
571
diff
changeset
|
116 |
0 | 117 /* find it from all realms */ |
118 pu = hash_lookup(passwd_file->users, user); | |
119 if (pu == NULL) { | |
120 t_push(); | |
121 for (tmp = auth_realms; *tmp != NULL; tmp++) { | |
122 str = t_strconcat(user, ":", *tmp, NULL); | |
123 pu = hash_lookup(passwd_file->users, str); | |
124 } | |
125 t_pop(); | |
126 } | |
127 | |
128 if (pu == NULL) | |
129 return FALSE; | |
130 | |
131 /* verify that password matches */ | |
132 switch (pu->password_type) { | |
133 case PASSWORD_DES: | |
686
ae9e39383a72
Still more crypt() problems. Wrapped it into mycrypt() which should finally
Timo Sirainen <tss@iki.fi>
parents:
619
diff
changeset
|
134 if (strcmp(mycrypt(password, pu->password), pu->password) != 0) |
0 | 135 return FALSE; |
136 break; | |
137 case PASSWORD_MD5: | |
138 md5_get_digest(password, strlen(password), digest); | |
139 str = binary_to_hex(digest, sizeof(digest)); | |
140 | |
141 if (strcmp(str, pu->password) != 0) | |
142 return FALSE; | |
143 break; | |
144 case PASSWORD_DIGEST_MD5: | |
145 /* user:realm:passwd */ | |
146 str = t_strconcat(pu->user_realm, | |
147 pu->realm == NULL ? ":" : "", ":", | |
148 password, NULL); | |
149 | |
150 md5_get_digest(str, strlen(str), digest); | |
151 str = binary_to_hex(digest, sizeof(digest)); | |
152 | |
153 if (strcmp(str, pu->password) != 0) | |
154 return FALSE; | |
155 break; | |
156 default: | |
546
e1254b838e0b
Added --enable-asserts (default) and fixed some warnings when building
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
157 i_unreached(); |
0 | 158 } |
159 | |
160 /* found */ | |
161 return get_reply_data(pu, reply); | |
162 } | |
163 | |
164 static int passwd_file_lookup_digest_md5(const char *user, const char *realm, | |
5
1b34ec11fff8
Message data is parsed in blocks (no longer entirely mmap()ed). Several
Timo Sirainen <tss@iki.fi>
parents:
0
diff
changeset
|
165 unsigned char digest[16], |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
902
diff
changeset
|
166 struct auth_cookie_reply_data *reply) |
0 | 167 { |
168 const char *id; | |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
902
diff
changeset
|
169 struct passwd_user *pu; |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
902
diff
changeset
|
170 buffer_t *buf; |
0 | 171 |
619
fcdff89c3df2
re-read passwd file when it changes.
Timo Sirainen <tss@iki.fi>
parents:
571
diff
changeset
|
172 passwd_file_sync(); |
fcdff89c3df2
re-read passwd file when it changes.
Timo Sirainen <tss@iki.fi>
parents:
571
diff
changeset
|
173 |
0 | 174 /* FIXME: we simply ignore UTF8 setting.. */ |
175 | |
176 id = realm == NULL || *realm == '\0' ? user : | |
177 t_strconcat(user, ":", realm, NULL); | |
178 | |
179 pu = hash_lookup(passwd_file->users, id); | |
180 if (pu == NULL) | |
181 return FALSE; | |
182 | |
183 /* found */ | |
184 i_assert(strlen(pu->password) == 32); | |
765
553f050c8313
Added buffer API. Point is to hide all buffer writing behind this API which
Timo Sirainen <tss@iki.fi>
parents:
764
diff
changeset
|
185 |
772 | 186 buf = buffer_create_data(data_stack_pool, digest, 16); |
765
553f050c8313
Added buffer API. Point is to hide all buffer writing behind this API which
Timo Sirainen <tss@iki.fi>
parents:
764
diff
changeset
|
187 if (!hex_to_binary(pu->password, buf)) |
0 | 188 return FALSE; |
189 | |
190 return get_reply_data(pu, reply); | |
191 } | |
192 | |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
902
diff
changeset
|
193 static void passwd_file_add(struct passwd_file *pw, const char *username, |
847
7f41a4b33975
t_strsplit() returns now const char **, which removes a few nasty casts.
Timo Sirainen <tss@iki.fi>
parents:
825
diff
changeset
|
194 const char *pass, const char *const *args) |
0 | 195 { |
196 /* args = uid, gid, user info, home dir, shell, realm, mail, chroot */ | |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
902
diff
changeset
|
197 struct passwd_user *pu; |
0 | 198 const char *p; |
199 | |
200 if (strlen(username) >= AUTH_MAX_USER_LEN) { | |
201 i_error("Username %s is too long (max. %d chars) in password " | |
202 "file %s", username, AUTH_MAX_USER_LEN, pw->path); | |
203 return; | |
204 } | |
205 | |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
902
diff
changeset
|
206 pu = p_new(pw->pool, struct passwd_user, 1); |
0 | 207 |
208 p = strchr(pass, '['); | |
209 if (p == NULL) { | |
210 pu->password = p_strdup(pw->pool, pass); | |
211 pu->password_type = PASSWORD_DES; | |
212 } else { | |
213 /* password[type] - we're being libpam-pwdfile compatible | |
214 here. it uses 13 = DES and 34 = MD5. We add | |
215 56 = Digest-MD5. */ | |
184 | 216 pu->password = p_strndup(pw->pool, pass, (size_t) (p-pass)); |
0 | 217 if (p[1] == '3' && p[2] == '4') { |
218 pu->password_type = PASSWORD_MD5; | |
219 str_lcase(pu->password); | |
220 } else if (p[1] == '5' && p[2] == '6') { | |
221 pu->password_type = PASSWORD_DIGEST_MD5; | |
222 if (strlen(pu->password) != 32) { | |
223 i_error("User %s has invalid password in " | |
224 "file %s", username, pw->path); | |
225 return; | |
226 } | |
227 str_lcase(pu->password); | |
228 } else { | |
229 pu->password_type = PASSWORD_DES; | |
230 } | |
231 } | |
232 | |
233 if (args[0] != NULL) { | |
234 pu->uid = atoi(args[0]); | |
235 if (pu->uid == 0) { | |
236 i_error("User %s has UID 0 in password file %s", | |
237 username, pw->path); | |
238 return; | |
239 } | |
240 args++; | |
241 } | |
242 | |
243 if (args[0] != NULL) { | |
244 pu->gid = atoi(args[0]); | |
245 if (pu->gid == 0) { | |
246 i_error("User %s has GID 0 in password file %s", | |
247 username, pw->path); | |
248 return; | |
249 } | |
250 args++; | |
251 } | |
252 | |
253 /* user info */ | |
254 if (args[0] != NULL) | |
255 args++; | |
256 | |
257 /* home */ | |
258 if (args[0] != NULL) { | |
259 if (strlen(args[0]) >= AUTH_MAX_HOME_LEN) { | |
260 i_error("User %s has too long home directory in " | |
261 "password file %s", username, pw->path); | |
262 return; | |
263 } | |
264 | |
265 pu->home = p_strdup(pw->pool, args[0]); | |
266 args++; | |
267 } | |
268 | |
269 /* shell */ | |
270 if (args[0] != NULL) | |
271 args++; | |
272 | |
273 /* realm */ | |
274 if (args[0] == NULL || *args[0] == '\0') { | |
275 pu->user_realm = p_strdup(pw->pool, username); | |
276 if (hash_lookup(pw->users, username) != NULL) { | |
277 i_error("User %s already exists in password file %s", | |
278 username, pw->path); | |
279 return; | |
280 } | |
281 } else { | |
282 pu->user_realm = p_strconcat(pw->pool, username, ":", | |
283 args[0], NULL); | |
284 pu->realm = pu->user_realm + strlen(username)+1; | |
285 | |
286 if (hash_lookup(pw->users, pu->user_realm) != NULL) { | |
287 i_error("User %s already exists in realm %s in " | |
288 "password file %s", username, args[0], | |
289 pw->path); | |
290 return; | |
291 } | |
292 } | |
293 | |
294 /* mail storage */ | |
295 if (args[0] != NULL) { | |
296 if (strlen(args[0]) >= AUTH_MAX_MAIL_LEN) { | |
297 i_error("User %s has too long mail storage in " | |
298 "password file %s", username, pw->path); | |
299 return; | |
300 } | |
301 | |
302 pu->mail = p_strdup(pw->pool, args[0]); | |
303 args++; | |
304 } | |
305 | |
306 /* chroot */ | |
307 if (args[0] != NULL && strstr(args[0], "chroot") != NULL) | |
308 pu->chroot = TRUE; | |
309 | |
310 hash_insert(pw->users, pu->user_realm, pu); | |
311 } | |
312 | |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
902
diff
changeset
|
313 static void passwd_file_parse_file(struct passwd_file *pw) |
0 | 314 { |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
902
diff
changeset
|
315 struct istream *input; |
847
7f41a4b33975
t_strsplit() returns now const char **, which removes a few nasty casts.
Timo Sirainen <tss@iki.fi>
parents:
825
diff
changeset
|
316 const char *const *args; |
805
5ac361acb316
Marked all non-trivial buffer modifications with @UNSAFE tag. Several
Timo Sirainen <tss@iki.fi>
parents:
791
diff
changeset
|
317 const char *line; |
0 | 318 |
764
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
686
diff
changeset
|
319 input = i_stream_create_file(pw->fd, default_pool, 2048, FALSE); |
0 | 320 for (;;) { |
764
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
686
diff
changeset
|
321 line = i_stream_next_line(input); |
0 | 322 if (line == NULL) { |
764
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
686
diff
changeset
|
323 if (i_stream_read(input) <= 0) |
0 | 324 break; |
325 continue; | |
326 } | |
327 | |
328 if (*line == '\0' || *line == ':') | |
329 continue; /* no username */ | |
330 | |
331 t_push(); | |
332 args = t_strsplit(line, ":"); | |
333 if (args[1] != NULL && IS_VALID_PASSWD(args[1])) { | |
334 /* valid user/pass */ | |
335 passwd_file_add(pw, args[0], args[1], args+2); | |
336 } | |
337 t_pop(); | |
338 } | |
764
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
686
diff
changeset
|
339 i_stream_unref(input); |
0 | 340 } |
341 | |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
902
diff
changeset
|
342 static struct passwd_file *passwd_file_parse(const char *path) |
0 | 343 { |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
902
diff
changeset
|
344 struct passwd_file *pw; |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
902
diff
changeset
|
345 pool_t pool; |
0 | 346 struct stat st; |
347 int fd; | |
348 | |
349 fd = open(path, O_RDONLY); | |
350 if (fd == -1) { | |
351 i_fatal("Can't open passwd-file %s: %m", path); | |
352 } | |
353 | |
354 if (fstat(fd, &st) != 0) | |
355 i_fatal("fstat() failed for passwd-file %s: %m", path); | |
356 | |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
902
diff
changeset
|
357 pool = pool_alloconly_create("passwd_file", 10240); |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
902
diff
changeset
|
358 pw = p_new(pool, struct passwd_file, 1); |
0 | 359 pw->pool = pool; |
360 pw->path = p_strdup(pool, path); | |
361 pw->stamp = st.st_mtime; | |
362 pw->fd = fd; | |
363 pw->users = hash_create(pool, 100, str_hash, (HashCompareFunc) strcmp); | |
364 | |
365 passwd_file_parse_file(pw); | |
366 return pw; | |
367 } | |
368 | |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
902
diff
changeset
|
369 static void passwd_file_free(struct passwd_file *pw) |
0 | 370 { |
371 pool_unref(pw->pool); | |
372 } | |
373 | |
374 static void passwd_file_init(const char *args) | |
375 { | |
376 passwd_file = passwd_file_parse(args); | |
377 } | |
378 | |
379 static void passwd_file_deinit(void) | |
380 { | |
381 passwd_file_free(passwd_file); | |
382 } | |
383 | |
619
fcdff89c3df2
re-read passwd file when it changes.
Timo Sirainen <tss@iki.fi>
parents:
571
diff
changeset
|
384 static void passwd_file_sync(void) |
fcdff89c3df2
re-read passwd file when it changes.
Timo Sirainen <tss@iki.fi>
parents:
571
diff
changeset
|
385 { |
fcdff89c3df2
re-read passwd file when it changes.
Timo Sirainen <tss@iki.fi>
parents:
571
diff
changeset
|
386 const char *path; |
fcdff89c3df2
re-read passwd file when it changes.
Timo Sirainen <tss@iki.fi>
parents:
571
diff
changeset
|
387 struct stat st; |
fcdff89c3df2
re-read passwd file when it changes.
Timo Sirainen <tss@iki.fi>
parents:
571
diff
changeset
|
388 |
fcdff89c3df2
re-read passwd file when it changes.
Timo Sirainen <tss@iki.fi>
parents:
571
diff
changeset
|
389 if (stat(passwd_file->path, &st) < 0) |
fcdff89c3df2
re-read passwd file when it changes.
Timo Sirainen <tss@iki.fi>
parents:
571
diff
changeset
|
390 i_fatal("stat() failed for %s: %m", passwd_file->path); |
fcdff89c3df2
re-read passwd file when it changes.
Timo Sirainen <tss@iki.fi>
parents:
571
diff
changeset
|
391 |
fcdff89c3df2
re-read passwd file when it changes.
Timo Sirainen <tss@iki.fi>
parents:
571
diff
changeset
|
392 if (st.st_mtime != passwd_file->stamp) { |
fcdff89c3df2
re-read passwd file when it changes.
Timo Sirainen <tss@iki.fi>
parents:
571
diff
changeset
|
393 path = t_strdup(passwd_file->path); |
fcdff89c3df2
re-read passwd file when it changes.
Timo Sirainen <tss@iki.fi>
parents:
571
diff
changeset
|
394 passwd_file_free(passwd_file); |
fcdff89c3df2
re-read passwd file when it changes.
Timo Sirainen <tss@iki.fi>
parents:
571
diff
changeset
|
395 passwd_file = passwd_file_parse(path); |
fcdff89c3df2
re-read passwd file when it changes.
Timo Sirainen <tss@iki.fi>
parents:
571
diff
changeset
|
396 } |
fcdff89c3df2
re-read passwd file when it changes.
Timo Sirainen <tss@iki.fi>
parents:
571
diff
changeset
|
397 } |
fcdff89c3df2
re-read passwd file when it changes.
Timo Sirainen <tss@iki.fi>
parents:
571
diff
changeset
|
398 |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
902
diff
changeset
|
399 struct user_info_module userinfo_passwd_file = { |
0 | 400 passwd_file_init, |
401 passwd_file_deinit, | |
402 | |
403 passwd_file_verify_plain, | |
404 passwd_file_lookup_digest_md5 | |
405 }; | |
406 | |
407 #endif |