summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorRuss Allbery <rra@stanford.edu>2012-02-19 10:36:43 -0800
committerRuss Allbery <rra@stanford.edu>2012-02-19 10:37:49 -0800
commit16cae416b11482468d024a009acf55c063ffafc7 (patch)
tree0c651a8c5c84765c42108a01af1c8b37662df730 /util
parentb1b071fed1a4c9a3cf4c3aa3861ac734498a7346 (diff)
Map timeout errors to a token error code
Set up a general framework for mapping certain errno values to token error codes, also used for EOF, and map the timeout error to the corresponding token error code so that special action can be taken where appropriate. Update the logging functions for client and server to recognize the new token error code. Change-Id: Ibc2a38574657273ec92c9af5806177ac8f11556a
Diffstat (limited to 'util')
-rw-r--r--util/tokens.c26
1 files changed, 20 insertions, 6 deletions
diff --git a/util/tokens.c b/util/tokens.c
index 4687975..4682116 100644
--- a/util/tokens.c
+++ b/util/tokens.c
@@ -28,11 +28,25 @@
/*
+ * Given a socket errno, map it to one of our error codes.
+ */
+static enum token_status
+map_socket_error(int err)
+{
+ switch (err) {
+ case EPIPE: return TOKEN_FAIL_EOF;
+ case ETIMEDOUT: return TOKEN_FAIL_TIMEOUT;
+ default: return TOKEN_FAIL_SOCKET;
+ }
+}
+
+
+/*
* Send a token to a file descriptor. Takes the file descriptor, the token,
* and the flags (a single byte, even though they're passed in as an integer)
* and writes them to the file descriptor. Returns TOKEN_OK on success and
- * TOKEN_FAIL_SYSTEM or TOKEN_FAIL_SOCKET on an error (including partial
- * writes).
+ * TOKEN_FAIL_SYSTEM, TOKEN_FAIL_SOCKET, or TOKEN_FAIL_TIMEOUT on an error
+ * (including partial writes).
*/
enum token_status
token_send(socket_type fd, int flags, gss_buffer_t tok, time_t timeout)
@@ -53,7 +67,7 @@ token_send(socket_type fd, int flags, gss_buffer_t tok, time_t timeout)
memcpy(buffer + 1 + sizeof(OM_uint32), tok->value, tok->length);
okay = network_write(fd, buffer, buflen, timeout);
free(buffer);
- return okay ? TOKEN_OK : TOKEN_FAIL_SOCKET;
+ return okay ? TOKEN_OK : map_socket_error(socket_errno);
}
@@ -88,11 +102,11 @@ token_recv(socket_type fd, int *flags, gss_buffer_t tok, size_t max,
int err;
if (!network_read(fd, &char_flags, 1, timeout))
- return (socket_errno == EPIPE) ? TOKEN_FAIL_EOF : TOKEN_FAIL_SOCKET;
+ return map_socket_error(socket_errno);
*flags = char_flags;
if (!network_read(fd, &len, sizeof(OM_uint32), timeout))
- return (socket_errno == EPIPE) ? TOKEN_FAIL_EOF : TOKEN_FAIL_SOCKET;
+ return map_socket_error(socket_errno);
tok->length = ntohl(len);
if (tok->length > max)
return TOKEN_FAIL_LARGE;
@@ -108,7 +122,7 @@ token_recv(socket_type fd, int *flags, gss_buffer_t tok, size_t max,
err = socket_errno;
free(tok->value);
socket_set_errno(err);
- return (err == EPIPE) ? TOKEN_FAIL_EOF : TOKEN_FAIL_SOCKET;
+ return map_socket_error(err);
}
return TOKEN_OK;
}