Mercurial > dovecot > core-2.2
comparison 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 |
comparison
equal
deleted
inserted
replaced
902:5043e48c022f | 903:fd8888f6f037 |
---|---|
16 | 16 |
17 #include <stdlib.h> | 17 #include <stdlib.h> |
18 #include <fcntl.h> | 18 #include <fcntl.h> |
19 #include <sys/stat.h> | 19 #include <sys/stat.h> |
20 | 20 |
21 typedef struct { | 21 struct passwd_file { |
22 Pool pool; | 22 pool_t pool; |
23 | 23 |
24 char *path; | 24 char *path; |
25 time_t stamp; | 25 time_t stamp; |
26 int fd; | 26 int fd; |
27 | 27 |
28 HashTable *users; | 28 struct hash_table *users; |
29 } PasswdFile; | 29 }; |
30 | 30 |
31 typedef enum { | 31 enum password_type { |
32 PASSWORD_DES, | 32 PASSWORD_DES, |
33 PASSWORD_MD5, | 33 PASSWORD_MD5, |
34 PASSWORD_DIGEST_MD5 | 34 PASSWORD_DIGEST_MD5 |
35 } PasswordType; | 35 }; |
36 | 36 |
37 typedef struct { | 37 struct passwd_user { |
38 char *user_realm; /* user:realm */ | 38 char *user_realm; /* user:realm */ |
39 const char *realm; /* NULL or points to user_realm */ | 39 const char *realm; /* NULL or points to user_realm */ |
40 char *password; | 40 char *password; |
41 char *home; | 41 char *home; |
42 char *mail; | 42 char *mail; |
43 | 43 |
44 uid_t uid; | 44 uid_t uid; |
45 gid_t gid; | 45 gid_t gid; |
46 | 46 |
47 PasswordType password_type; | 47 enum password_type password_type; |
48 unsigned int chroot:1; | 48 unsigned int chroot:1; |
49 } PasswdUser; | 49 }; |
50 | 50 |
51 static PasswdFile *passwd_file; | 51 static struct passwd_file *passwd_file; |
52 | 52 |
53 static void passwd_file_sync(void); | 53 static void passwd_file_sync(void); |
54 | 54 |
55 static int get_reply_data(PasswdUser *pu, AuthCookieReplyData *reply) | 55 static int get_reply_data(struct passwd_user *pu, |
56 struct auth_cookie_reply_data *reply) | |
56 { | 57 { |
57 const char *user; | 58 const char *user; |
58 struct passwd *pw; | 59 struct passwd *pw; |
59 | 60 |
60 if (pu->uid == 0 || pu->gid == 0 || | 61 if (pu->uid == 0 || pu->gid == 0 || |
102 reply->chroot = pu->chroot; | 103 reply->chroot = pu->chroot; |
103 return TRUE; | 104 return TRUE; |
104 } | 105 } |
105 | 106 |
106 static int passwd_file_verify_plain(const char *user, const char *password, | 107 static int passwd_file_verify_plain(const char *user, const char *password, |
107 AuthCookieReplyData *reply) | 108 struct auth_cookie_reply_data *reply) |
108 { | 109 { |
109 PasswdUser *pu; | 110 struct passwd_user *pu; |
110 const char *const *tmp; | 111 const char *const *tmp; |
111 unsigned char digest[16]; | 112 unsigned char digest[16]; |
112 const char *str; | 113 const char *str; |
113 | 114 |
114 passwd_file_sync(); | 115 passwd_file_sync(); |
160 return get_reply_data(pu, reply); | 161 return get_reply_data(pu, reply); |
161 } | 162 } |
162 | 163 |
163 static int passwd_file_lookup_digest_md5(const char *user, const char *realm, | 164 static int passwd_file_lookup_digest_md5(const char *user, const char *realm, |
164 unsigned char digest[16], | 165 unsigned char digest[16], |
165 AuthCookieReplyData *reply) | 166 struct auth_cookie_reply_data *reply) |
166 { | 167 { |
167 const char *id; | 168 const char *id; |
168 PasswdUser *pu; | 169 struct passwd_user *pu; |
169 Buffer *buf; | 170 buffer_t *buf; |
170 | 171 |
171 passwd_file_sync(); | 172 passwd_file_sync(); |
172 | 173 |
173 /* FIXME: we simply ignore UTF8 setting.. */ | 174 /* FIXME: we simply ignore UTF8 setting.. */ |
174 | 175 |
187 return FALSE; | 188 return FALSE; |
188 | 189 |
189 return get_reply_data(pu, reply); | 190 return get_reply_data(pu, reply); |
190 } | 191 } |
191 | 192 |
192 static void passwd_file_add(PasswdFile *pw, const char *username, | 193 static void passwd_file_add(struct passwd_file *pw, const char *username, |
193 const char *pass, const char *const *args) | 194 const char *pass, const char *const *args) |
194 { | 195 { |
195 /* args = uid, gid, user info, home dir, shell, realm, mail, chroot */ | 196 /* args = uid, gid, user info, home dir, shell, realm, mail, chroot */ |
196 PasswdUser *pu; | 197 struct passwd_user *pu; |
197 const char *p; | 198 const char *p; |
198 | 199 |
199 if (strlen(username) >= AUTH_MAX_USER_LEN) { | 200 if (strlen(username) >= AUTH_MAX_USER_LEN) { |
200 i_error("Username %s is too long (max. %d chars) in password " | 201 i_error("Username %s is too long (max. %d chars) in password " |
201 "file %s", username, AUTH_MAX_USER_LEN, pw->path); | 202 "file %s", username, AUTH_MAX_USER_LEN, pw->path); |
202 return; | 203 return; |
203 } | 204 } |
204 | 205 |
205 pu = p_new(pw->pool, PasswdUser, 1); | 206 pu = p_new(pw->pool, struct passwd_user, 1); |
206 | 207 |
207 p = strchr(pass, '['); | 208 p = strchr(pass, '['); |
208 if (p == NULL) { | 209 if (p == NULL) { |
209 pu->password = p_strdup(pw->pool, pass); | 210 pu->password = p_strdup(pw->pool, pass); |
210 pu->password_type = PASSWORD_DES; | 211 pu->password_type = PASSWORD_DES; |
307 pu->chroot = TRUE; | 308 pu->chroot = TRUE; |
308 | 309 |
309 hash_insert(pw->users, pu->user_realm, pu); | 310 hash_insert(pw->users, pu->user_realm, pu); |
310 } | 311 } |
311 | 312 |
312 static void passwd_file_parse_file(PasswdFile *pw) | 313 static void passwd_file_parse_file(struct passwd_file *pw) |
313 { | 314 { |
314 IStream *input; | 315 struct istream *input; |
315 const char *const *args; | 316 const char *const *args; |
316 const char *line; | 317 const char *line; |
317 | 318 |
318 input = i_stream_create_file(pw->fd, default_pool, 2048, FALSE); | 319 input = i_stream_create_file(pw->fd, default_pool, 2048, FALSE); |
319 for (;;) { | 320 for (;;) { |
336 t_pop(); | 337 t_pop(); |
337 } | 338 } |
338 i_stream_unref(input); | 339 i_stream_unref(input); |
339 } | 340 } |
340 | 341 |
341 static PasswdFile *passwd_file_parse(const char *path) | 342 static struct passwd_file *passwd_file_parse(const char *path) |
342 { | 343 { |
343 PasswdFile *pw; | 344 struct passwd_file *pw; |
344 Pool pool; | 345 pool_t pool; |
345 struct stat st; | 346 struct stat st; |
346 int fd; | 347 int fd; |
347 | 348 |
348 fd = open(path, O_RDONLY); | 349 fd = open(path, O_RDONLY); |
349 if (fd == -1) { | 350 if (fd == -1) { |
351 } | 352 } |
352 | 353 |
353 if (fstat(fd, &st) != 0) | 354 if (fstat(fd, &st) != 0) |
354 i_fatal("fstat() failed for passwd-file %s: %m", path); | 355 i_fatal("fstat() failed for passwd-file %s: %m", path); |
355 | 356 |
356 pool = pool_alloconly_create("PasswdFile", 10240); | 357 pool = pool_alloconly_create("passwd_file", 10240); |
357 pw = p_new(pool, PasswdFile, 1); | 358 pw = p_new(pool, struct passwd_file, 1); |
358 pw->pool = pool; | 359 pw->pool = pool; |
359 pw->path = p_strdup(pool, path); | 360 pw->path = p_strdup(pool, path); |
360 pw->stamp = st.st_mtime; | 361 pw->stamp = st.st_mtime; |
361 pw->fd = fd; | 362 pw->fd = fd; |
362 pw->users = hash_create(pool, 100, str_hash, (HashCompareFunc) strcmp); | 363 pw->users = hash_create(pool, 100, str_hash, (HashCompareFunc) strcmp); |
363 | 364 |
364 passwd_file_parse_file(pw); | 365 passwd_file_parse_file(pw); |
365 return pw; | 366 return pw; |
366 } | 367 } |
367 | 368 |
368 static void passwd_file_free(PasswdFile *pw) | 369 static void passwd_file_free(struct passwd_file *pw) |
369 { | 370 { |
370 pool_unref(pw->pool); | 371 pool_unref(pw->pool); |
371 } | 372 } |
372 | 373 |
373 static void passwd_file_init(const char *args) | 374 static void passwd_file_init(const char *args) |
393 passwd_file_free(passwd_file); | 394 passwd_file_free(passwd_file); |
394 passwd_file = passwd_file_parse(path); | 395 passwd_file = passwd_file_parse(path); |
395 } | 396 } |
396 } | 397 } |
397 | 398 |
398 UserInfoModule userinfo_passwd_file = { | 399 struct user_info_module userinfo_passwd_file = { |
399 passwd_file_init, | 400 passwd_file_init, |
400 passwd_file_deinit, | 401 passwd_file_deinit, |
401 | 402 |
402 passwd_file_verify_plain, | 403 passwd_file_verify_plain, |
403 passwd_file_lookup_digest_md5 | 404 passwd_file_lookup_digest_md5 |