nutcracker 0.2.4.12 → 0.3.0.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +8 -8
  2. data/Rakefile +1 -1
  3. data/ext/nutcracker/ChangeLog +10 -0
  4. data/ext/nutcracker/Makefile.am +2 -0
  5. data/ext/nutcracker/Makefile.in +101 -14
  6. data/ext/nutcracker/README.md +18 -1
  7. data/ext/nutcracker/config.h.in +18 -0
  8. data/ext/nutcracker/configure +196 -25
  9. data/ext/nutcracker/configure.ac +64 -6
  10. data/ext/nutcracker/extconf.rb +1 -1
  11. data/ext/nutcracker/man/nutcracker.8 +76 -0
  12. data/ext/nutcracker/notes/debug.txt +116 -16
  13. data/ext/nutcracker/notes/kqueue.pdf +0 -0
  14. data/ext/nutcracker/notes/recommendation.md +20 -0
  15. data/ext/nutcracker/notes/redis.md +2 -2
  16. data/ext/nutcracker/scripts/nutcracker.spec +1 -1
  17. data/ext/nutcracker/scripts/redis-check.sh +3 -1
  18. data/ext/nutcracker/src/Makefile.am +15 -6
  19. data/ext/nutcracker/src/Makefile.in +39 -36
  20. data/ext/nutcracker/src/event/Makefile.am +16 -0
  21. data/ext/nutcracker/src/event/Makefile.in +492 -0
  22. data/ext/nutcracker/src/event/nc_epoll.c +344 -0
  23. data/ext/nutcracker/src/event/nc_event.h +88 -0
  24. data/ext/nutcracker/src/event/nc_evport.c +420 -0
  25. data/ext/nutcracker/src/event/nc_kqueue.c +412 -0
  26. data/ext/nutcracker/src/hashkit/nc_crc32.c +19 -1
  27. data/ext/nutcracker/src/hashkit/nc_hashkit.h +3 -1
  28. data/ext/nutcracker/src/hashkit/nc_md5.c +257 -315
  29. data/ext/nutcracker/src/nc.c +12 -1
  30. data/ext/nutcracker/src/nc_connection.c +18 -1
  31. data/ext/nutcracker/src/nc_connection.h +1 -0
  32. data/ext/nutcracker/src/nc_core.c +22 -30
  33. data/ext/nutcracker/src/nc_core.h +22 -7
  34. data/ext/nutcracker/src/nc_proxy.c +8 -9
  35. data/ext/nutcracker/src/nc_queue.h +2 -0
  36. data/ext/nutcracker/src/nc_request.c +3 -4
  37. data/ext/nutcracker/src/nc_response.c +25 -8
  38. data/ext/nutcracker/src/nc_server.c +8 -6
  39. data/ext/nutcracker/src/nc_stats.c +46 -43
  40. data/ext/nutcracker/src/nc_stats.h +37 -30
  41. data/ext/nutcracker/src/nc_util.c +6 -1
  42. data/ext/nutcracker/src/proto/nc_redis.c +19 -5
  43. data/lib/nutcracker/version.rb +1 -1
  44. data/lib/nutcracker.rb +1 -1
  45. metadata +10 -4
  46. data/ext/nutcracker/src/nc_event.c +0 -214
  47. data/ext/nutcracker/src/nc_event.h +0 -39
@@ -15,365 +15,307 @@
15
15
  * limitations under the License.
16
16
  */
17
17
 
18
+ #include <nc_core.h>
19
+
18
20
  /*
19
- * This Library has been modified from its original form by
20
- * Brian Aker (brian@tangent.org)
21
- *
22
- * See below for original Copyright.
23
- */
24
- /* MD5C.C - RSA Data Security, Inc., MD5 message-digest algorithm
25
- *
26
- * Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
27
- * rights reserved.
21
+ * This is an OpenSSL-compatible implementation of the RSA Data Security, Inc.
22
+ * MD5 Message-Digest Algorithm (RFC 1321).
28
23
  *
29
- * License to copy and use this software is granted provided that it
30
- * is identified as the "RSA Data Security, Inc. MD5 Message-Digest
31
- * Algorithm" in all material mentioning or referencing this software
32
- * or this function.
24
+ * Homepage: http://openwall.info/wiki/people/solar/software/public-domain-source-code/md5
33
25
  *
34
- * License is also granted to make and use derivative works provided
35
- * that such works are identified as "derived from the RSA Data
36
- * Security, Inc. MD5 Message-Digest Algorithm" in all material
37
- * mentioning or referencing the derived work.
38
- *
39
- * RSA Data Security, Inc. makes no representations concerning either
40
- * the merchantability of this software or the suitability of this
41
- * software for any particular purpose. It is provided "as is"
42
- * without express or implied warranty of any kind.
43
- *
44
- * These notices must be retained in any copies of any part of this
45
- * documentation and/or software.
26
+ * Author: Alexander Peslyak, better known as Solar Designer <solar at openwall.com>
46
27
  */
47
28
 
48
- #include <nc_core.h>
49
-
50
- /* POINTER defines a generic pointer type */
51
- typedef unsigned char *POINTER;
52
-
29
+ #include <string.h>
53
30
 
54
- /* UINT4 defines a four byte word */
55
- typedef unsigned int UINT4;
31
+ typedef unsigned int MD5_u32plus;
56
32
 
57
-
58
- /* MD5 context. */
59
33
  typedef struct {
60
- UINT4 state[4]; /* state (ABCD) */
61
- UINT4 count[2]; /* number of bits, modulo 2^64 (lsb first) */
62
- unsigned char buffer[64]; /* input buffer */
34
+ MD5_u32plus lo, hi;
35
+ MD5_u32plus a, b, c, d;
36
+ unsigned char buffer[64];
37
+ MD5_u32plus block[16];
63
38
  } MD5_CTX;
64
39
 
65
- static void MD5Init (MD5_CTX *context); /* context */
66
- static void MD5Update ( MD5_CTX *context, /* context */
67
- const unsigned char *input, /* input block */
68
- unsigned int inputLen); /* length of input block */
69
- static void MD5Final ( unsigned char digest[16], /* message digest */
70
- MD5_CTX *context); /* context */
71
-
72
- /* Constants for MD5Transform routine. */
73
-
74
- #define S11 7
75
- #define S12 12
76
- #define S13 17
77
- #define S14 22
78
- #define S21 5
79
- #define S22 9
80
- #define S23 14
81
- #define S24 20
82
- #define S31 4
83
- #define S32 11
84
- #define S33 16
85
- #define S34 23
86
- #define S41 6
87
- #define S42 10
88
- #define S43 15
89
- #define S44 21
90
-
91
-
92
- static void MD5Transform (UINT4 state[4],
93
- unsigned char block[64]);
94
- static void Encode (unsigned char *output,
95
- UINT4 *input,
96
- unsigned int len);
97
- static void Decode(UINT4 *output, unsigned char *input, unsigned int len);
98
-
99
- static unsigned char PADDING[64] = {
100
- 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
101
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
102
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
103
- };
104
-
105
- /* F, G, H and I are basic MD5 functions.
40
+ /*
41
+ * The basic MD5 functions.
42
+ *
43
+ * F and G are optimized compared to their RFC 1321 definitions for
44
+ * architectures that lack an AND-NOT instruction, just like in Colin Plumb's
45
+ * implementation.
106
46
  */
107
- #define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
108
- #define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
109
- #define H(x, y, z) ((x) ^ (y) ^ (z))
110
- #define I(x, y, z) ((y) ^ ((x) | (~z)))
47
+ #define F(x, y, z) ((z) ^ ((x) & ((y) ^ (z))))
48
+ #define G(x, y, z) ((y) ^ ((z) & ((x) ^ (y))))
49
+ #define H(x, y, z) ((x) ^ (y) ^ (z))
50
+ #define I(x, y, z) ((y) ^ ((x) | ~(z)))
111
51
 
112
- /* ROTATE_LEFT rotates x left n bits.
52
+ /*
53
+ * The MD5 transformation for all four rounds.
113
54
  */
114
- #define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
55
+ #define STEP(f, a, b, c, d, x, t, s) \
56
+ (a) += f((b), (c), (d)) + (x) + (t); \
57
+ (a) = (((a) << (s)) | (((a) & 0xffffffff) >> (32 - (s)))); \
58
+ (a) += (b);
115
59
 
116
- /* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
117
- Rotation is separate from addition to prevent recomputation.
60
+ /*
61
+ * SET reads 4 input bytes in little-endian byte order and stores them
62
+ * in a properly aligned word in host byte order.
63
+ *
64
+ * The check for little-endian architectures that tolerate unaligned
65
+ * memory accesses is just an optimization. Nothing will break if it
66
+ * doesn't work.
118
67
  */
119
- #define FF(a, b, c, d, x, s, ac) { \
120
- (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \
121
- (a) = ROTATE_LEFT ((a), (s)); \
122
- (a) += (b); \
123
- }
124
- #define GG(a, b, c, d, x, s, ac) { \
125
- (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \
126
- (a) = ROTATE_LEFT ((a), (s)); \
127
- (a) += (b); \
128
- }
129
- #define HH(a, b, c, d, x, s, ac) { \
130
- (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \
131
- (a) = ROTATE_LEFT ((a), (s)); \
132
- (a) += (b); \
133
- }
134
- #define II(a, b, c, d, x, s, ac) { \
135
- (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \
136
- (a) = ROTATE_LEFT ((a), (s)); \
137
- (a) += (b); \
138
- }
139
-
140
-
141
- /*
142
- Just a simple method for getting the signature
143
- result must be == 16
144
- */
145
- void md5_signature(const unsigned char *key, unsigned int length, unsigned char *result)
146
- {
147
- MD5_CTX my_md5;
148
-
149
- MD5Init(&my_md5);
150
- (void)MD5Update(&my_md5, key, length);
151
- MD5Final(result, &my_md5);
152
- }
68
+ #if defined(__i386__) || defined(__x86_64__) || defined(__vax__)
69
+ #define SET(n) \
70
+ (*(MD5_u32plus *)&ptr[(n) * 4])
71
+ #define GET(n) \
72
+ SET(n)
73
+ #else
74
+ #define SET(n) \
75
+ (ctx->block[(n)] = \
76
+ (MD5_u32plus)ptr[(n) * 4] | \
77
+ ((MD5_u32plus)ptr[(n) * 4 + 1] << 8) | \
78
+ ((MD5_u32plus)ptr[(n) * 4 + 2] << 16) | \
79
+ ((MD5_u32plus)ptr[(n) * 4 + 3] << 24))
80
+ #define GET(n) \
81
+ (ctx->block[(n)])
82
+ #endif
153
83
 
154
- /* MD5 initialization. Begins an MD5 operation, writing a new context.
84
+ /*
85
+ * This processes one or more 64-byte data blocks, but does NOT update
86
+ * the bit counters. There are no alignment requirements.
155
87
  */
156
- static void MD5Init (MD5_CTX *context) /* context */
88
+ static void *
89
+ body(MD5_CTX *ctx, void *data, unsigned long size)
157
90
  {
158
- context->count[0] = context->count[1] = 0;
159
- /* Load magic initialization constants.
160
- */
161
- context->state[0] = 0x67452301;
162
- context->state[1] = 0xefcdab89;
163
- context->state[2] = 0x98badcfe;
164
- context->state[3] = 0x10325476;
91
+ unsigned char *ptr;
92
+ MD5_u32plus a, b, c, d;
93
+ MD5_u32plus saved_a, saved_b, saved_c, saved_d;
94
+
95
+ ptr = data;
96
+
97
+ a = ctx->a;
98
+ b = ctx->b;
99
+ c = ctx->c;
100
+ d = ctx->d;
101
+
102
+ do {
103
+ saved_a = a;
104
+ saved_b = b;
105
+ saved_c = c;
106
+ saved_d = d;
107
+
108
+ /* Round 1 */
109
+ STEP(F, a, b, c, d, SET(0), 0xd76aa478, 7)
110
+ STEP(F, d, a, b, c, SET(1), 0xe8c7b756, 12)
111
+ STEP(F, c, d, a, b, SET(2), 0x242070db, 17)
112
+ STEP(F, b, c, d, a, SET(3), 0xc1bdceee, 22)
113
+ STEP(F, a, b, c, d, SET(4), 0xf57c0faf, 7)
114
+ STEP(F, d, a, b, c, SET(5), 0x4787c62a, 12)
115
+ STEP(F, c, d, a, b, SET(6), 0xa8304613, 17)
116
+ STEP(F, b, c, d, a, SET(7), 0xfd469501, 22)
117
+ STEP(F, a, b, c, d, SET(8), 0x698098d8, 7)
118
+ STEP(F, d, a, b, c, SET(9), 0x8b44f7af, 12)
119
+ STEP(F, c, d, a, b, SET(10), 0xffff5bb1, 17)
120
+ STEP(F, b, c, d, a, SET(11), 0x895cd7be, 22)
121
+ STEP(F, a, b, c, d, SET(12), 0x6b901122, 7)
122
+ STEP(F, d, a, b, c, SET(13), 0xfd987193, 12)
123
+ STEP(F, c, d, a, b, SET(14), 0xa679438e, 17)
124
+ STEP(F, b, c, d, a, SET(15), 0x49b40821, 22)
125
+
126
+ /* Round 2 */
127
+ STEP(G, a, b, c, d, GET(1), 0xf61e2562, 5)
128
+ STEP(G, d, a, b, c, GET(6), 0xc040b340, 9)
129
+ STEP(G, c, d, a, b, GET(11), 0x265e5a51, 14)
130
+ STEP(G, b, c, d, a, GET(0), 0xe9b6c7aa, 20)
131
+ STEP(G, a, b, c, d, GET(5), 0xd62f105d, 5)
132
+ STEP(G, d, a, b, c, GET(10), 0x02441453, 9)
133
+ STEP(G, c, d, a, b, GET(15), 0xd8a1e681, 14)
134
+ STEP(G, b, c, d, a, GET(4), 0xe7d3fbc8, 20)
135
+ STEP(G, a, b, c, d, GET(9), 0x21e1cde6, 5)
136
+ STEP(G, d, a, b, c, GET(14), 0xc33707d6, 9)
137
+ STEP(G, c, d, a, b, GET(3), 0xf4d50d87, 14)
138
+ STEP(G, b, c, d, a, GET(8), 0x455a14ed, 20)
139
+ STEP(G, a, b, c, d, GET(13), 0xa9e3e905, 5)
140
+ STEP(G, d, a, b, c, GET(2), 0xfcefa3f8, 9)
141
+ STEP(G, c, d, a, b, GET(7), 0x676f02d9, 14)
142
+ STEP(G, b, c, d, a, GET(12), 0x8d2a4c8a, 20)
143
+
144
+ /* Round 3 */
145
+ STEP(H, a, b, c, d, GET(5), 0xfffa3942, 4)
146
+ STEP(H, d, a, b, c, GET(8), 0x8771f681, 11)
147
+ STEP(H, c, d, a, b, GET(11), 0x6d9d6122, 16)
148
+ STEP(H, b, c, d, a, GET(14), 0xfde5380c, 23)
149
+ STEP(H, a, b, c, d, GET(1), 0xa4beea44, 4)
150
+ STEP(H, d, a, b, c, GET(4), 0x4bdecfa9, 11)
151
+ STEP(H, c, d, a, b, GET(7), 0xf6bb4b60, 16)
152
+ STEP(H, b, c, d, a, GET(10), 0xbebfbc70, 23)
153
+ STEP(H, a, b, c, d, GET(13), 0x289b7ec6, 4)
154
+ STEP(H, d, a, b, c, GET(0), 0xeaa127fa, 11)
155
+ STEP(H, c, d, a, b, GET(3), 0xd4ef3085, 16)
156
+ STEP(H, b, c, d, a, GET(6), 0x04881d05, 23)
157
+ STEP(H, a, b, c, d, GET(9), 0xd9d4d039, 4)
158
+ STEP(H, d, a, b, c, GET(12), 0xe6db99e5, 11)
159
+ STEP(H, c, d, a, b, GET(15), 0x1fa27cf8, 16)
160
+ STEP(H, b, c, d, a, GET(2), 0xc4ac5665, 23)
161
+
162
+ /* Round 4 */
163
+ STEP(I, a, b, c, d, GET(0), 0xf4292244, 6)
164
+ STEP(I, d, a, b, c, GET(7), 0x432aff97, 10)
165
+ STEP(I, c, d, a, b, GET(14), 0xab9423a7, 15)
166
+ STEP(I, b, c, d, a, GET(5), 0xfc93a039, 21)
167
+ STEP(I, a, b, c, d, GET(12), 0x655b59c3, 6)
168
+ STEP(I, d, a, b, c, GET(3), 0x8f0ccc92, 10)
169
+ STEP(I, c, d, a, b, GET(10), 0xffeff47d, 15)
170
+ STEP(I, b, c, d, a, GET(1), 0x85845dd1, 21)
171
+ STEP(I, a, b, c, d, GET(8), 0x6fa87e4f, 6)
172
+ STEP(I, d, a, b, c, GET(15), 0xfe2ce6e0, 10)
173
+ STEP(I, c, d, a, b, GET(6), 0xa3014314, 15)
174
+ STEP(I, b, c, d, a, GET(13), 0x4e0811a1, 21)
175
+ STEP(I, a, b, c, d, GET(4), 0xf7537e82, 6)
176
+ STEP(I, d, a, b, c, GET(11), 0xbd3af235, 10)
177
+ STEP(I, c, d, a, b, GET(2), 0x2ad7d2bb, 15)
178
+ STEP(I, b, c, d, a, GET(9), 0xeb86d391, 21)
179
+
180
+ a += saved_a;
181
+ b += saved_b;
182
+ c += saved_c;
183
+ d += saved_d;
184
+
185
+ ptr += 64;
186
+ } while (size -= 64);
187
+
188
+ ctx->a = a;
189
+ ctx->b = b;
190
+ ctx->c = c;
191
+ ctx->d = d;
192
+
193
+ return ptr;
165
194
  }
166
195
 
167
- /* MD5 block update operation. Continues an MD5 message-digest
168
- operation, processing another message block, and updating the
169
- context.
170
- */
171
-
172
- static void MD5Update (
173
- MD5_CTX *context, /* context */
174
- const unsigned char *input, /* input block */
175
- unsigned int inputLen) /* length of input block */
196
+ void
197
+ MD5_Init(MD5_CTX *ctx)
176
198
  {
177
- unsigned int i, idx, partLen;
178
-
179
- /* Compute number of bytes mod 64 */
180
- idx = (unsigned int)((context->count[0] >> 3) & 0x3F);
181
-
182
-
183
- /* Update number of bits */
184
- if ((context->count[0] += ((UINT4)inputLen << 3))
185
- < ((UINT4)inputLen << 3))
186
- context->count[1]++;
187
- context->count[1] += ((UINT4)inputLen >> 29);
188
-
189
- partLen = 64 - idx;
190
-
191
- /* Transform as many times as possible.
192
- */
193
- if (inputLen >= partLen) {
194
- memcpy((POINTER)&context->buffer[idx], (POINTER)input, partLen);
195
- MD5Transform(context->state, context->buffer);
196
-
197
- for (i = partLen; i + 63 < inputLen; i += 64)
198
- MD5Transform (context->state, (unsigned char *)&input[i]);
199
-
200
- idx = 0;
201
- }
202
- else
203
- i = 0;
199
+ ctx->a = 0x67452301;
200
+ ctx->b = 0xefcdab89;
201
+ ctx->c = 0x98badcfe;
202
+ ctx->d = 0x10325476;
204
203
 
205
- /* Buffer remaining input */
206
- memcpy((POINTER)&context->buffer[idx], (POINTER)&input[i],
207
- inputLen-i);
204
+ ctx->lo = 0;
205
+ ctx->hi = 0;
208
206
  }
209
207
 
210
- /* MD5 finalization. Ends an MD5 message-digest operation, writing the
211
- the message digest and zeroizing the context.
212
- */
213
-
214
- static void MD5Final (
215
- unsigned char digest[16], /* message digest */
216
- MD5_CTX *context) /* context */
208
+ void
209
+ MD5_Update(MD5_CTX *ctx, void *data, unsigned long size)
217
210
  {
218
- unsigned char bits[8];
219
- unsigned int idx, padLen;
211
+ MD5_u32plus saved_lo;
212
+ unsigned long used, free;
220
213
 
221
- /* Save number of bits */
222
- Encode (bits, context->count, 8);
214
+ saved_lo = ctx->lo;
215
+ if ((ctx->lo = (saved_lo + size) & 0x1fffffff) < saved_lo) {
216
+ ctx->hi++;
217
+ }
218
+ ctx->hi += size >> 29;
223
219
 
224
- /* Pad out to 56 mod 64.
225
- */
226
- idx = (unsigned int)((context->count[0] >> 3) & 0x3f);
227
- padLen = (idx < 56) ? (56 - idx) : (120 - idx);
228
- MD5Update (context, PADDING, padLen);
220
+ used = saved_lo & 0x3f;
229
221
 
230
- /* Append length (before padding) */
231
- MD5Update (context, bits, 8);
222
+ if (used) {
223
+ free = 64 - used;
232
224
 
233
- /* Store state in digest */
234
- Encode (digest, context->state, 16);
225
+ if (size < free) {
226
+ memcpy(&ctx->buffer[used], data, size);
227
+ return;
228
+ }
235
229
 
236
- /* Zeroize sensitive information.
237
- */
238
- memset((POINTER)context, 0, sizeof (*context));
239
- }
230
+ memcpy(&ctx->buffer[used], data, free);
231
+ data = (unsigned char *)data + free;
232
+ size -= free;
233
+ body(ctx, ctx->buffer, 64);
234
+ }
240
235
 
241
- /* MD5 basic transformation. Transforms state based on block.
242
- */
243
- static void MD5Transform (
244
- UINT4 state[4],
245
- unsigned char block[64])
246
- {
247
- UINT4 a = state[0], b = state[1], c = state[2], d = state[3], x[16];
248
-
249
- Decode (x, block, 64);
250
-
251
- /* Round 1 */
252
- FF (a, b, c, d, x[ 0], S11, 0xd76aa478); /* 1 */
253
- FF (d, a, b, c, x[ 1], S12, 0xe8c7b756); /* 2 */
254
- FF (c, d, a, b, x[ 2], S13, 0x242070db); /* 3 */
255
- FF (b, c, d, a, x[ 3], S14, 0xc1bdceee); /* 4 */
256
- FF (a, b, c, d, x[ 4], S11, 0xf57c0faf); /* 5 */
257
- FF (d, a, b, c, x[ 5], S12, 0x4787c62a); /* 6 */
258
- FF (c, d, a, b, x[ 6], S13, 0xa8304613); /* 7 */
259
- FF (b, c, d, a, x[ 7], S14, 0xfd469501); /* 8 */
260
- FF (a, b, c, d, x[ 8], S11, 0x698098d8); /* 9 */
261
- FF (d, a, b, c, x[ 9], S12, 0x8b44f7af); /* 10 */
262
- FF (c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */
263
- FF (b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */
264
- FF (a, b, c, d, x[12], S11, 0x6b901122); /* 13 */
265
- FF (d, a, b, c, x[13], S12, 0xfd987193); /* 14 */
266
- FF (c, d, a, b, x[14], S13, 0xa679438e); /* 15 */
267
- FF (b, c, d, a, x[15], S14, 0x49b40821); /* 16 */
268
-
269
- /* Round 2 */
270
- GG (a, b, c, d, x[ 1], S21, 0xf61e2562); /* 17 */
271
- GG (d, a, b, c, x[ 6], S22, 0xc040b340); /* 18 */
272
- GG (c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */
273
- GG (b, c, d, a, x[ 0], S24, 0xe9b6c7aa); /* 20 */
274
- GG (a, b, c, d, x[ 5], S21, 0xd62f105d); /* 21 */
275
- GG (d, a, b, c, x[10], S22, 0x2441453); /* 22 */
276
- GG (c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */
277
- GG (b, c, d, a, x[ 4], S24, 0xe7d3fbc8); /* 24 */
278
- GG (a, b, c, d, x[ 9], S21, 0x21e1cde6); /* 25 */
279
- GG (d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */
280
- GG (c, d, a, b, x[ 3], S23, 0xf4d50d87); /* 27 */
281
- GG (b, c, d, a, x[ 8], S24, 0x455a14ed); /* 28 */
282
- GG (a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */
283
- GG (d, a, b, c, x[ 2], S22, 0xfcefa3f8); /* 30 */
284
- GG (c, d, a, b, x[ 7], S23, 0x676f02d9); /* 31 */
285
- GG (b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */
286
-
287
- /* Round 3 */
288
- HH (a, b, c, d, x[ 5], S31, 0xfffa3942); /* 33 */
289
- HH (d, a, b, c, x[ 8], S32, 0x8771f681); /* 34 */
290
- HH (c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */
291
- HH (b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */
292
- HH (a, b, c, d, x[ 1], S31, 0xa4beea44); /* 37 */
293
- HH (d, a, b, c, x[ 4], S32, 0x4bdecfa9); /* 38 */
294
- HH (c, d, a, b, x[ 7], S33, 0xf6bb4b60); /* 39 */
295
- HH (b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */
296
- HH (a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */
297
- HH (d, a, b, c, x[ 0], S32, 0xeaa127fa); /* 42 */
298
- HH (c, d, a, b, x[ 3], S33, 0xd4ef3085); /* 43 */
299
- HH (b, c, d, a, x[ 6], S34, 0x4881d05); /* 44 */
300
- HH (a, b, c, d, x[ 9], S31, 0xd9d4d039); /* 45 */
301
- HH (d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */
302
- HH (c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */
303
- HH (b, c, d, a, x[ 2], S34, 0xc4ac5665); /* 48 */
304
-
305
- /* Round 4 */
306
- II (a, b, c, d, x[ 0], S41, 0xf4292244); /* 49 */
307
- II (d, a, b, c, x[ 7], S42, 0x432aff97); /* 50 */
308
- II (c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */
309
- II (b, c, d, a, x[ 5], S44, 0xfc93a039); /* 52 */
310
- II (a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */
311
- II (d, a, b, c, x[ 3], S42, 0x8f0ccc92); /* 54 */
312
- II (c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */
313
- II (b, c, d, a, x[ 1], S44, 0x85845dd1); /* 56 */
314
- II (a, b, c, d, x[ 8], S41, 0x6fa87e4f); /* 57 */
315
- II (d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */
316
- II (c, d, a, b, x[ 6], S43, 0xa3014314); /* 59 */
317
- II (b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */
318
- II (a, b, c, d, x[ 4], S41, 0xf7537e82); /* 61 */
319
- II (d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */
320
- II (c, d, a, b, x[ 2], S43, 0x2ad7d2bb); /* 63 */
321
- II (b, c, d, a, x[ 9], S44, 0xeb86d391); /* 64 */
322
-
323
-
324
- state[0] += a;
325
- state[1] += b;
326
- state[2] += c;
327
- state[3] += d;
328
-
329
- /* Zeroize sensitive information.
330
- */
331
- memset((POINTER)x, 0, sizeof (x));
236
+ if (size >= 64) {
237
+ data = body(ctx, data, size & ~(unsigned long)0x3f);
238
+ size &= 0x3f;
239
+ }
240
+
241
+ memcpy(ctx->buffer, data, size);
332
242
  }
333
243
 
334
- /* Encodes input (UINT4) into output (unsigned char). Assumes len is
335
- a multiple of 4.
336
- */
337
- static void Encode (
338
- unsigned char *output,
339
- UINT4 *input,
340
- unsigned int len)
244
+ void
245
+ MD5_Final(unsigned char *result, MD5_CTX *ctx)
341
246
  {
342
- unsigned int i, j;
343
-
344
- for (i = 0, j = 0; j < len; i++, j += 4) {
345
- output[j] = (unsigned char)(input[i] & 0xff);
346
- output[j+1] = (unsigned char)((input[i] >> 8) & 0xff);
347
- output[j+2] = (unsigned char)((input[i] >> 16) & 0xff);
348
- output[j+3] = (unsigned char)((input[i] >> 24) & 0xff);
349
- }
247
+ unsigned long used, free;
248
+
249
+ used = ctx->lo & 0x3f;
250
+
251
+ ctx->buffer[used++] = 0x80;
252
+
253
+ free = 64 - used;
254
+
255
+ if (free < 8) {
256
+ memset(&ctx->buffer[used], 0, free);
257
+ body(ctx, ctx->buffer, 64);
258
+ used = 0;
259
+ free = 64;
260
+ }
261
+
262
+ memset(&ctx->buffer[used], 0, free - 8);
263
+
264
+ ctx->lo <<= 3;
265
+ ctx->buffer[56] = ctx->lo;
266
+ ctx->buffer[57] = ctx->lo >> 8;
267
+ ctx->buffer[58] = ctx->lo >> 16;
268
+ ctx->buffer[59] = ctx->lo >> 24;
269
+ ctx->buffer[60] = ctx->hi;
270
+ ctx->buffer[61] = ctx->hi >> 8;
271
+ ctx->buffer[62] = ctx->hi >> 16;
272
+ ctx->buffer[63] = ctx->hi >> 24;
273
+
274
+ body(ctx, ctx->buffer, 64);
275
+
276
+ result[0] = ctx->a;
277
+ result[1] = ctx->a >> 8;
278
+ result[2] = ctx->a >> 16;
279
+ result[3] = ctx->a >> 24;
280
+ result[4] = ctx->b;
281
+ result[5] = ctx->b >> 8;
282
+ result[6] = ctx->b >> 16;
283
+ result[7] = ctx->b >> 24;
284
+ result[8] = ctx->c;
285
+ result[9] = ctx->c >> 8;
286
+ result[10] = ctx->c >> 16;
287
+ result[11] = ctx->c >> 24;
288
+ result[12] = ctx->d;
289
+ result[13] = ctx->d >> 8;
290
+ result[14] = ctx->d >> 16;
291
+ result[15] = ctx->d >> 24;
292
+
293
+ memset(ctx, 0, sizeof(*ctx));
350
294
  }
351
295
 
352
-
353
- /* Decodes input (unsigned char) into output (UINT4). Assumes len is
354
- a multiple of 4.
296
+ /*
297
+ * Just a simple method for getting the signature
298
+ * result must be == 16
355
299
  */
356
- static void Decode (
357
- UINT4 *output,
358
- unsigned char *input,
359
- unsigned int len)
300
+ void
301
+ md5_signature(unsigned char *key, unsigned long length, unsigned char *result)
360
302
  {
361
- unsigned int i, j;
303
+ MD5_CTX my_md5;
362
304
 
363
- for (i = 0, j = 0; j < len; i++, j += 4)
364
- output[i] = ((UINT4)input[j]) | (((UINT4)input[j+1]) << 8) |
365
- (((UINT4)input[j+2]) << 16) | (((UINT4)input[j+3]) << 24);
305
+ MD5_Init(&my_md5);
306
+ (void)MD5_Update(&my_md5, key, length);
307
+ MD5_Final(result, &my_md5);
366
308
  }
367
309
 
368
310
  uint32_t
369
311
  hash_md5(const char *key, size_t key_length)
370
312
  {
371
- unsigned char results[16];
313
+ unsigned char results[16];
372
314
 
373
- md5_signature((unsigned char*)key, (unsigned int)key_length, results);
315
+ md5_signature((unsigned char*)key, (unsigned long)key_length, results);
374
316
 
375
- return ((uint32_t) (results[3] & 0xFF) << 24)
376
- | ((uint32_t) (results[2] & 0xFF) << 16)
377
- | ((uint32_t) (results[1] & 0xFF) << 8)
378
- | (results[0] & 0xFF);
317
+ return ((uint32_t) (results[3] & 0xFF) << 24) |
318
+ ((uint32_t) (results[2] & 0xFF) << 16) |
319
+ ((uint32_t) (results[1] & 0xFF) << 8) |
320
+ (results[0] & 0xFF);
379
321
  }
@@ -22,6 +22,7 @@
22
22
  #include <getopt.h>
23
23
  #include <fcntl.h>
24
24
  #include <sys/stat.h>
25
+ #include <sys/utsname.h>
25
26
 
26
27
  #include <nc_core.h>
27
28
  #include <nc_conf.h>
@@ -174,7 +175,17 @@ nc_daemonize(int dump_core)
174
175
  static void
175
176
  nc_print_run(struct instance *nci)
176
177
  {
177
- loga("nutcracker-%s started on pid %d", NC_VERSION_STRING, nci->pid);
178
+ int status;
179
+ struct utsname name;
180
+
181
+ status = uname(&name);
182
+ if (status < 0) {
183
+ loga("nutcracker-%s started on pid %d", NC_VERSION_STRING, nci->pid);
184
+ } else {
185
+ loga("nutcracker-%s built for %s %s %s started on pid %d",
186
+ NC_VERSION_STRING, name.sysname, name.release, name.machine,
187
+ nci->pid);
188
+ }
178
189
 
179
190
  loga("run, rabbit run / dig that hole, forget the sun / "
180
191
  "and when at last the work is done / don't sit down / "
@@ -79,12 +79,29 @@
79
79
  * out_q ensures that we always send back the response of request at the head
80
80
  * of the queue, before sending out responses of other completed requests in
81
81
  * the queue.
82
- *
83
82
  */
84
83
 
85
84
  static uint32_t nfree_connq; /* # free conn q */
86
85
  static struct conn_tqh free_connq; /* free conn q */
87
86
 
87
+ /*
88
+ * Return the context associated with this connection.
89
+ */
90
+ struct context *
91
+ conn_to_ctx(struct conn *conn)
92
+ {
93
+ struct server_pool *pool;
94
+
95
+ if (conn->proxy || conn->client) {
96
+ pool = conn->owner;
97
+ } else {
98
+ struct server *server = conn->owner;
99
+ pool = server->owner;
100
+ }
101
+
102
+ return pool->ctx;
103
+ }
104
+
88
105
  static struct conn *
89
106
  _conn_get(void)
90
107
  {