diff options
Diffstat (limited to 'roaming_common.c')
-rw-r--r-- | roaming_common.c | 47 |
1 files changed, 46 insertions, 1 deletions
diff --git a/roaming_common.c b/roaming_common.c index 73db09d79..272deade3 100644 --- a/roaming_common.c +++ b/roaming_common.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: roaming_common.c,v 1.5 2009/06/27 09:32:43 andreas Exp $ */ | 1 | /* $OpenBSD: roaming_common.c,v 1.6 2009/10/24 11:22:37 andreas Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2004-2009 AppGate Network Security AB | 3 | * Copyright (c) 2004-2009 AppGate Network Security AB |
4 | * | 4 | * |
@@ -147,6 +147,16 @@ roaming_write(int fd, const void *buf, size_t count, int *cont) | |||
147 | } | 147 | } |
148 | debug3("Wrote %ld bytes for a total of %llu", (long)ret, | 148 | debug3("Wrote %ld bytes for a total of %llu", (long)ret, |
149 | (unsigned long long)write_bytes); | 149 | (unsigned long long)write_bytes); |
150 | if (out_buf_size > 0 && | ||
151 | (ret == 0 || (ret == -1 && errno == EPIPE))) { | ||
152 | if (wait_for_roaming_reconnect() != 0) { | ||
153 | ret = 0; | ||
154 | *cont = 1; | ||
155 | } else { | ||
156 | ret = -1; | ||
157 | errno = EAGAIN; | ||
158 | } | ||
159 | } | ||
150 | return ret; | 160 | return ret; |
151 | } | 161 | } |
152 | 162 | ||
@@ -158,6 +168,15 @@ roaming_read(int fd, void *buf, size_t count, int *cont) | |||
158 | if (!resume_in_progress) { | 168 | if (!resume_in_progress) { |
159 | read_bytes += ret; | 169 | read_bytes += ret; |
160 | } | 170 | } |
171 | } else if (out_buf_size > 0 && | ||
172 | (ret == 0 || (ret == -1 && (errno == ECONNRESET | ||
173 | || errno == ECONNABORTED || errno == ETIMEDOUT | ||
174 | || errno == EHOSTUNREACH)))) { | ||
175 | debug("roaming_read failed for %d ret=%ld errno=%d", | ||
176 | fd, (long)ret, errno); | ||
177 | ret = 0; | ||
178 | if (wait_for_roaming_reconnect() == 0) | ||
179 | *cont = 1; | ||
161 | } | 180 | } |
162 | return ret; | 181 | return ret; |
163 | } | 182 | } |
@@ -199,3 +218,29 @@ resend_bytes(int fd, u_int64_t *offset) | |||
199 | atomicio(vwrite, fd, out_buf + (out_last - needed), needed); | 218 | atomicio(vwrite, fd, out_buf + (out_last - needed), needed); |
200 | } | 219 | } |
201 | } | 220 | } |
221 | |||
222 | /* | ||
223 | * Caclulate a new key after a reconnect | ||
224 | */ | ||
225 | void | ||
226 | calculate_new_key(u_int64_t *key, u_int64_t cookie, u_int64_t challenge) | ||
227 | { | ||
228 | const EVP_MD *md = EVP_sha1(); | ||
229 | EVP_MD_CTX ctx; | ||
230 | char hash[EVP_MAX_MD_SIZE]; | ||
231 | Buffer b; | ||
232 | |||
233 | buffer_init(&b); | ||
234 | buffer_put_int64(&b, *key); | ||
235 | buffer_put_int64(&b, cookie); | ||
236 | buffer_put_int64(&b, challenge); | ||
237 | |||
238 | EVP_DigestInit(&ctx, md); | ||
239 | EVP_DigestUpdate(&ctx, buffer_ptr(&b), buffer_len(&b)); | ||
240 | EVP_DigestFinal(&ctx, hash, NULL); | ||
241 | |||
242 | buffer_clear(&b); | ||
243 | buffer_append(&b, hash, EVP_MD_size(md)); | ||
244 | *key = buffer_get_int64(&b); | ||
245 | buffer_free(&b); | ||
246 | } | ||