Mercurial > dovecot > core-2.2
annotate src/anvil/penalty.c @ 22576:707ae9de3812
lib: istream-multiplex - Minor code cleanup
Avoid propagating the error twice, and avoid any confusion about what "got"
actually contains.
author | Timo Sirainen <timo.sirainen@dovecot.fi> |
---|---|
date | Thu, 05 Oct 2017 20:24:11 +0300 |
parents | 2e2563132d5f |
children | cb108f786fb4 |
rev | line source |
---|---|
21390
2e2563132d5f
Updated copyright notices to include the year 2017.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
19552
diff
changeset
|
1 /* Copyright (c) 2009-2017 Dovecot authors, see the included COPYING file */ |
10298
ea209b33ef96
anvil: Added support for penalty tracking.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
2 |
15356
483199c2ca13
anvil: Added a comment to remind what the anvil checksums are all about.
Timo Sirainen <tss@iki.fi>
parents:
15068
diff
changeset
|
3 /* The idea behind checksums is that the same username+password doesn't |
483199c2ca13
anvil: Added a comment to remind what the anvil checksums are all about.
Timo Sirainen <tss@iki.fi>
parents:
15068
diff
changeset
|
4 increase the penalty, because it's most likely a user with a misconfigured |
483199c2ca13
anvil: Added a comment to remind what the anvil checksums are all about.
Timo Sirainen <tss@iki.fi>
parents:
15068
diff
changeset
|
5 account. */ |
483199c2ca13
anvil: Added a comment to remind what the anvil checksums are all about.
Timo Sirainen <tss@iki.fi>
parents:
15068
diff
changeset
|
6 |
10298
ea209b33ef96
anvil: Added support for penalty tracking.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
7 #include "lib.h" |
ea209b33ef96
anvil: Added support for penalty tracking.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
8 #include "ioloop.h" |
ea209b33ef96
anvil: Added support for penalty tracking.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
9 #include "hash.h" |
10779
1282d027ce67
anvil: Added PENALTY-DUMP command to dump penalty state.
Timo Sirainen <tss@iki.fi>
parents:
10778
diff
changeset
|
10 #include "str.h" |
1282d027ce67
anvil: Added PENALTY-DUMP command to dump penalty state.
Timo Sirainen <tss@iki.fi>
parents:
10778
diff
changeset
|
11 #include "strescape.h" |
10298
ea209b33ef96
anvil: Added support for penalty tracking.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
12 #include "llist.h" |
10779
1282d027ce67
anvil: Added PENALTY-DUMP command to dump penalty state.
Timo Sirainen <tss@iki.fi>
parents:
10778
diff
changeset
|
13 #include "ostream.h" |
10298
ea209b33ef96
anvil: Added support for penalty tracking.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
14 #include "penalty.h" |
ea209b33ef96
anvil: Added support for penalty tracking.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
15 |
ea209b33ef96
anvil: Added support for penalty tracking.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
16 #include <time.h> |
ea209b33ef96
anvil: Added support for penalty tracking.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
17 |
ea209b33ef96
anvil: Added support for penalty tracking.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
18 #define PENALTY_DEFAULT_EXPIRE_SECS (60*60) |
10773
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
19 #define PENALTY_CHECKSUM_SAVE_COUNT |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
20 #define CHECKSUM_VALUE_COUNT 2 |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
21 #define CHECKSUM_VALUE_PTR_COUNT 10 |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
22 |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
23 #define LAST_UPDATE_BITS 15 |
10298
ea209b33ef96
anvil: Added support for penalty tracking.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
24 |
ea209b33ef96
anvil: Added support for penalty tracking.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
25 struct penalty_rec { |
ea209b33ef96
anvil: Added support for penalty tracking.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
26 /* ordered by last_update */ |
ea209b33ef96
anvil: Added support for penalty tracking.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
27 struct penalty_rec *prev, *next; |
ea209b33ef96
anvil: Added support for penalty tracking.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
28 |
ea209b33ef96
anvil: Added support for penalty tracking.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
29 char *ident; |
10773
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
30 unsigned int last_penalty; |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
31 |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
32 unsigned int penalty:16; |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
33 unsigned int last_update:LAST_UPDATE_BITS; /* last_penalty + n */ |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
34 unsigned int checksum_is_pointer:1; |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
35 /* we use value up to two different checksums. |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
36 after that switch to pointer. */ |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
37 union { |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
38 unsigned int value[CHECKSUM_VALUE_COUNT]; |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
39 unsigned int *value_ptr; |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
40 } checksum; |
10298
ea209b33ef96
anvil: Added support for penalty tracking.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
41 }; |
ea209b33ef96
anvil: Added support for penalty tracking.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
42 |
ea209b33ef96
anvil: Added support for penalty tracking.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
43 struct penalty { |
ea209b33ef96
anvil: Added support for penalty tracking.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
44 /* ident => penalty_rec */ |
14918
8eae4e205c82
Hash table API is now (mostly) type safe.
Timo Sirainen <tss@iki.fi>
parents:
14917
diff
changeset
|
45 HASH_TABLE(char *, struct penalty_rec *) hash; |
10298
ea209b33ef96
anvil: Added support for penalty tracking.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
46 struct penalty_rec *oldest, *newest; |
ea209b33ef96
anvil: Added support for penalty tracking.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
47 |
ea209b33ef96
anvil: Added support for penalty tracking.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
48 unsigned int expire_secs; |
ea209b33ef96
anvil: Added support for penalty tracking.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
49 struct timeout *to; |
ea209b33ef96
anvil: Added support for penalty tracking.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
50 }; |
ea209b33ef96
anvil: Added support for penalty tracking.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
51 |
ea209b33ef96
anvil: Added support for penalty tracking.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
52 struct penalty *penalty_init(void) |
ea209b33ef96
anvil: Added support for penalty tracking.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
53 { |
ea209b33ef96
anvil: Added support for penalty tracking.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
54 struct penalty *penalty; |
ea209b33ef96
anvil: Added support for penalty tracking.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
55 |
ea209b33ef96
anvil: Added support for penalty tracking.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
56 penalty = i_new(struct penalty, 1); |
14918
8eae4e205c82
Hash table API is now (mostly) type safe.
Timo Sirainen <tss@iki.fi>
parents:
14917
diff
changeset
|
57 hash_table_create(&penalty->hash, default_pool, 0, str_hash, strcmp); |
10298
ea209b33ef96
anvil: Added support for penalty tracking.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
58 penalty->expire_secs = PENALTY_DEFAULT_EXPIRE_SECS; |
ea209b33ef96
anvil: Added support for penalty tracking.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
59 return penalty; |
ea209b33ef96
anvil: Added support for penalty tracking.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
60 } |
ea209b33ef96
anvil: Added support for penalty tracking.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
61 |
ea209b33ef96
anvil: Added support for penalty tracking.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
62 static void penalty_rec_free(struct penalty *penalty, struct penalty_rec *rec) |
ea209b33ef96
anvil: Added support for penalty tracking.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
63 { |
ea209b33ef96
anvil: Added support for penalty tracking.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
64 DLLIST2_REMOVE(&penalty->oldest, &penalty->newest, rec); |
10773
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
65 if (rec->checksum_is_pointer) |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
66 i_free(rec->checksum.value_ptr); |
10298
ea209b33ef96
anvil: Added support for penalty tracking.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
67 i_free(rec->ident); |
ea209b33ef96
anvil: Added support for penalty tracking.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
68 i_free(rec); |
ea209b33ef96
anvil: Added support for penalty tracking.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
69 } |
ea209b33ef96
anvil: Added support for penalty tracking.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
70 |
ea209b33ef96
anvil: Added support for penalty tracking.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
71 void penalty_deinit(struct penalty **_penalty) |
ea209b33ef96
anvil: Added support for penalty tracking.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
72 { |
ea209b33ef96
anvil: Added support for penalty tracking.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
73 struct penalty *penalty = *_penalty; |
ea209b33ef96
anvil: Added support for penalty tracking.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
74 |
ea209b33ef96
anvil: Added support for penalty tracking.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
75 *_penalty = NULL; |
ea209b33ef96
anvil: Added support for penalty tracking.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
76 |
ea209b33ef96
anvil: Added support for penalty tracking.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
77 while (penalty->oldest != NULL) |
ea209b33ef96
anvil: Added support for penalty tracking.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
78 penalty_rec_free(penalty, penalty->oldest); |
ea209b33ef96
anvil: Added support for penalty tracking.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
79 hash_table_destroy(&penalty->hash); |
ea209b33ef96
anvil: Added support for penalty tracking.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
80 |
ea209b33ef96
anvil: Added support for penalty tracking.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
81 if (penalty->to != NULL) |
ea209b33ef96
anvil: Added support for penalty tracking.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
82 timeout_remove(&penalty->to); |
ea209b33ef96
anvil: Added support for penalty tracking.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
83 i_free(penalty); |
ea209b33ef96
anvil: Added support for penalty tracking.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
84 } |
ea209b33ef96
anvil: Added support for penalty tracking.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
85 |
ea209b33ef96
anvil: Added support for penalty tracking.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
86 void penalty_set_expire_secs(struct penalty *penalty, unsigned int expire_secs) |
ea209b33ef96
anvil: Added support for penalty tracking.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
87 { |
ea209b33ef96
anvil: Added support for penalty tracking.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
88 penalty->expire_secs = expire_secs; |
ea209b33ef96
anvil: Added support for penalty tracking.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
89 } |
ea209b33ef96
anvil: Added support for penalty tracking.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
90 |
10773
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
91 static bool |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
92 penalty_bump_checksum(struct penalty_rec *rec, unsigned int checksum) |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
93 { |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
94 unsigned int *checksums; |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
95 unsigned int i, count; |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
96 |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
97 if (!rec->checksum_is_pointer) { |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
98 checksums = rec->checksum.value; |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
99 count = CHECKSUM_VALUE_COUNT; |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
100 } else { |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
101 checksums = rec->checksum.value_ptr; |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
102 count = CHECKSUM_VALUE_PTR_COUNT; |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
103 } |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
104 |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
105 for (i = 0; i < count; i++) { |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
106 if (checksums[i] == checksum) { |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
107 if (i > 0) { |
18617
398d94f08407
anvil: Penalty tracking was moving last checksums wrongly with memcpy().
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
108 memmove(checksums + 1, checksums, |
398d94f08407
anvil: Penalty tracking was moving last checksums wrongly with memcpy().
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
109 sizeof(checksums[0]) * i); |
10773
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
110 checksums[0] = checksum; |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
111 } |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
112 return TRUE; |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
113 } |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
114 } |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
115 return FALSE; |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
116 } |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
117 |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
118 static void penalty_add_checksum(struct penalty_rec *rec, unsigned int checksum) |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
119 { |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
120 unsigned int *checksums; |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
121 |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
122 i_assert(checksum != 0); |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
123 |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
124 if (!rec->checksum_is_pointer) { |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
125 if (rec->checksum.value[CHECKSUM_VALUE_COUNT-1] == 0) { |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
126 memcpy(rec->checksum.value + 1, rec->checksum.value, |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
127 sizeof(rec->checksum.value[0]) * |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
128 (CHECKSUM_VALUE_COUNT-1)); |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
129 rec->checksum.value[0] = checksum; |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
130 return; |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
131 } |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
132 |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
133 /* switch to using a pointer */ |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
134 checksums = i_new(unsigned int, CHECKSUM_VALUE_PTR_COUNT); |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
135 memcpy(checksums, rec->checksum.value, |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
136 sizeof(checksums[0]) * CHECKSUM_VALUE_COUNT); |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
137 rec->checksum.value_ptr = checksums; |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
138 rec->checksum_is_pointer = TRUE; |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
139 } |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
140 |
14338
f94f289ce009
anvil: s/memcpy/memmove/ for updating checksum list.
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
141 memmove(rec->checksum.value_ptr + 1, rec->checksum.value_ptr, |
f94f289ce009
anvil: s/memcpy/memmove/ for updating checksum list.
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
142 sizeof(rec->checksum.value_ptr[0]) * |
f94f289ce009
anvil: s/memcpy/memmove/ for updating checksum list.
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
143 (CHECKSUM_VALUE_PTR_COUNT-1)); |
10773
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
144 rec->checksum.value_ptr[0] = checksum; |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
145 } |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
146 |
10298
ea209b33ef96
anvil: Added support for penalty tracking.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
147 unsigned int penalty_get(struct penalty *penalty, const char *ident, |
10773
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
148 time_t *last_penalty_r) |
10298
ea209b33ef96
anvil: Added support for penalty tracking.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
149 { |
ea209b33ef96
anvil: Added support for penalty tracking.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
150 struct penalty_rec *rec; |
ea209b33ef96
anvil: Added support for penalty tracking.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
151 |
ea209b33ef96
anvil: Added support for penalty tracking.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
152 rec = hash_table_lookup(penalty->hash, ident); |
ea209b33ef96
anvil: Added support for penalty tracking.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
153 if (rec == NULL) { |
10773
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
154 *last_penalty_r = 0; |
10298
ea209b33ef96
anvil: Added support for penalty tracking.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
155 return 0; |
ea209b33ef96
anvil: Added support for penalty tracking.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
156 } |
10773
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
157 |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
158 *last_penalty_r = rec->last_penalty; |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
159 return rec->penalty; |
10298
ea209b33ef96
anvil: Added support for penalty tracking.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
160 } |
ea209b33ef96
anvil: Added support for penalty tracking.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
161 |
ea209b33ef96
anvil: Added support for penalty tracking.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
162 static void penalty_timeout(struct penalty *penalty) |
ea209b33ef96
anvil: Added support for penalty tracking.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
163 { |
10773
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
164 struct penalty_rec *rec; |
10829 | 165 time_t rec_last_update, expire_time; |
166 unsigned int diff; | |
10298
ea209b33ef96
anvil: Added support for penalty tracking.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
167 |
10838
f48ce6049176
anvil: Recent changes broke penalty timeout handling.
Timo Sirainen <tss@iki.fi>
parents:
10829
diff
changeset
|
168 timeout_remove(&penalty->to); |
f48ce6049176
anvil: Recent changes broke penalty timeout handling.
Timo Sirainen <tss@iki.fi>
parents:
10829
diff
changeset
|
169 |
10298
ea209b33ef96
anvil: Added support for penalty tracking.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
170 expire_time = ioloop_time - penalty->expire_secs; |
10773
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
171 while (penalty->oldest != NULL) { |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
172 rec = penalty->oldest; |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
173 |
10829 | 174 rec_last_update = rec->last_penalty + rec->last_update; |
175 if (rec_last_update > expire_time) { | |
176 diff = rec_last_update - expire_time; | |
177 penalty->to = timeout_add(diff * 1000, | |
178 penalty_timeout, penalty); | |
10773
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
179 break; |
10829 | 180 } |
10773
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
181 hash_table_remove(penalty->hash, rec->ident); |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
182 penalty_rec_free(penalty, rec); |
10298
ea209b33ef96
anvil: Added support for penalty tracking.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
183 } |
ea209b33ef96
anvil: Added support for penalty tracking.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
184 } |
ea209b33ef96
anvil: Added support for penalty tracking.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
185 |
10773
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
186 void penalty_inc(struct penalty *penalty, const char *ident, |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
187 unsigned int checksum, unsigned int value) |
10298
ea209b33ef96
anvil: Added support for penalty tracking.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
188 { |
ea209b33ef96
anvil: Added support for penalty tracking.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
189 struct penalty_rec *rec; |
10773
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
190 time_t diff; |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
191 |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
192 i_assert(value > 0 || checksum == 0); |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
193 i_assert(value <= INT_MAX); |
10298
ea209b33ef96
anvil: Added support for penalty tracking.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
194 |
ea209b33ef96
anvil: Added support for penalty tracking.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
195 rec = hash_table_lookup(penalty->hash, ident); |
ea209b33ef96
anvil: Added support for penalty tracking.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
196 if (rec == NULL) { |
ea209b33ef96
anvil: Added support for penalty tracking.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
197 rec = i_new(struct penalty_rec, 1); |
ea209b33ef96
anvil: Added support for penalty tracking.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
198 rec->ident = i_strdup(ident); |
ea209b33ef96
anvil: Added support for penalty tracking.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
199 hash_table_insert(penalty->hash, rec->ident, rec); |
ea209b33ef96
anvil: Added support for penalty tracking.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
200 } else { |
ea209b33ef96
anvil: Added support for penalty tracking.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
201 DLLIST2_REMOVE(&penalty->oldest, &penalty->newest, rec); |
ea209b33ef96
anvil: Added support for penalty tracking.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
202 } |
10773
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
203 |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
204 if (checksum == 0) { |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
205 rec->penalty = value; |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
206 rec->last_penalty = ioloop_time; |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
207 } else { |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
208 if (penalty_bump_checksum(rec, checksum)) |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
209 rec->penalty = value - 1; |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
210 else { |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
211 penalty_add_checksum(rec, checksum); |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
212 rec->penalty = value; |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
213 rec->last_penalty = ioloop_time; |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
214 } |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
215 } |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
216 |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
217 diff = ioloop_time - rec->last_penalty; |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
218 if (diff >= (1 << LAST_UPDATE_BITS)) { |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
219 rec->last_update = (1 << LAST_UPDATE_BITS) - 1; |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
220 rec->last_penalty = ioloop_time - rec->last_update; |
10778
3f2d9da0c6bc
anvil: Fixed penalty "last update" tracking.
Timo Sirainen <tss@iki.fi>
parents:
10773
diff
changeset
|
221 } else { |
3f2d9da0c6bc
anvil: Fixed penalty "last update" tracking.
Timo Sirainen <tss@iki.fi>
parents:
10773
diff
changeset
|
222 rec->last_update = diff; |
10773
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
223 } |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
224 |
10298
ea209b33ef96
anvil: Added support for penalty tracking.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
225 DLLIST2_APPEND(&penalty->oldest, &penalty->newest, rec); |
ea209b33ef96
anvil: Added support for penalty tracking.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
226 |
ea209b33ef96
anvil: Added support for penalty tracking.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
227 if (penalty->to == NULL) { |
ea209b33ef96
anvil: Added support for penalty tracking.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
228 penalty->to = timeout_add(penalty->expire_secs * 1000, |
ea209b33ef96
anvil: Added support for penalty tracking.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
229 penalty_timeout, penalty); |
ea209b33ef96
anvil: Added support for penalty tracking.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
230 } |
ea209b33ef96
anvil: Added support for penalty tracking.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
231 } |
10773
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
232 |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
233 bool penalty_has_checksum(struct penalty *penalty, const char *ident, |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
234 unsigned int checksum) |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
235 { |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
236 struct penalty_rec *rec; |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
237 const unsigned int *checksums; |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
238 unsigned int i, count; |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
239 |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
240 rec = hash_table_lookup(penalty->hash, ident); |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
241 if (rec == NULL) |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
242 return FALSE; |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
243 |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
244 if (!rec->checksum_is_pointer) { |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
245 checksums = rec->checksum.value; |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
246 count = CHECKSUM_VALUE_COUNT; |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
247 } else { |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
248 checksums = rec->checksum.value_ptr; |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
249 count = CHECKSUM_VALUE_PTR_COUNT; |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
250 } |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
251 |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
252 for (i = 0; i < count; i++) { |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
253 if (checksums[i] == checksum) |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
254 return TRUE; |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
255 } |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
256 return FALSE; |
4cdb58bb0360
auth/anvil: Penalty is no longer increased if the same user+pass combination was recently used.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
257 } |
10779
1282d027ce67
anvil: Added PENALTY-DUMP command to dump penalty state.
Timo Sirainen <tss@iki.fi>
parents:
10778
diff
changeset
|
258 |
1282d027ce67
anvil: Added PENALTY-DUMP command to dump penalty state.
Timo Sirainen <tss@iki.fi>
parents:
10778
diff
changeset
|
259 void penalty_dump(struct penalty *penalty, struct ostream *output) |
1282d027ce67
anvil: Added PENALTY-DUMP command to dump penalty state.
Timo Sirainen <tss@iki.fi>
parents:
10778
diff
changeset
|
260 { |
1282d027ce67
anvil: Added PENALTY-DUMP command to dump penalty state.
Timo Sirainen <tss@iki.fi>
parents:
10778
diff
changeset
|
261 const struct penalty_rec *rec; |
1282d027ce67
anvil: Added PENALTY-DUMP command to dump penalty state.
Timo Sirainen <tss@iki.fi>
parents:
10778
diff
changeset
|
262 string_t *str = t_str_new(256); |
1282d027ce67
anvil: Added PENALTY-DUMP command to dump penalty state.
Timo Sirainen <tss@iki.fi>
parents:
10778
diff
changeset
|
263 |
1282d027ce67
anvil: Added PENALTY-DUMP command to dump penalty state.
Timo Sirainen <tss@iki.fi>
parents:
10778
diff
changeset
|
264 for (rec = penalty->oldest; rec != NULL; rec = rec->next) { |
1282d027ce67
anvil: Added PENALTY-DUMP command to dump penalty state.
Timo Sirainen <tss@iki.fi>
parents:
10778
diff
changeset
|
265 str_truncate(str, 0); |
15068
002e0a120c2a
Renamed str_tabescape_write() to str_append_tabescaped()
Timo Sirainen <tss@iki.fi>
parents:
14918
diff
changeset
|
266 str_append_tabescaped(str, rec->ident); |
10779
1282d027ce67
anvil: Added PENALTY-DUMP command to dump penalty state.
Timo Sirainen <tss@iki.fi>
parents:
10778
diff
changeset
|
267 str_printfa(str, "\t%u\t%u\t%u\n", |
1282d027ce67
anvil: Added PENALTY-DUMP command to dump penalty state.
Timo Sirainen <tss@iki.fi>
parents:
10778
diff
changeset
|
268 rec->penalty, rec->last_penalty, |
1282d027ce67
anvil: Added PENALTY-DUMP command to dump penalty state.
Timo Sirainen <tss@iki.fi>
parents:
10778
diff
changeset
|
269 rec->last_penalty + rec->last_update); |
1282d027ce67
anvil: Added PENALTY-DUMP command to dump penalty state.
Timo Sirainen <tss@iki.fi>
parents:
10778
diff
changeset
|
270 if (o_stream_send(output, str_data(str), str_len(str)) < 0) |
1282d027ce67
anvil: Added PENALTY-DUMP command to dump penalty state.
Timo Sirainen <tss@iki.fi>
parents:
10778
diff
changeset
|
271 break; |
1282d027ce67
anvil: Added PENALTY-DUMP command to dump penalty state.
Timo Sirainen <tss@iki.fi>
parents:
10778
diff
changeset
|
272 } |
14681
ca37d1577291
Added o_stream_nsend*() and related functions to make delayed error handling safer.
Timo Sirainen <tss@iki.fi>
parents:
14338
diff
changeset
|
273 o_stream_nsend(output, "\n", 1); |
10779
1282d027ce67
anvil: Added PENALTY-DUMP command to dump penalty state.
Timo Sirainen <tss@iki.fi>
parents:
10778
diff
changeset
|
274 } |