X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=libatalk%2Fdsi%2Fdsi_stream.c;h=dd7b9ef680cb6ca1c4baf2f39f38fd9cb7d01410;hb=80fe6e63eb8ec9a396b4383cb8210fd5ded6ad35;hp=5c99ac2c363a084a70bffc741fcb8934ccb29844;hpb=daf7143d8b751bea2da8ae3358ffaf930c74d6d8;p=netatalk.git diff --git a/libatalk/dsi/dsi_stream.c b/libatalk/dsi/dsi_stream.c index 5c99ac2c..dd7b9ef6 100644 --- a/libatalk/dsi/dsi_stream.c +++ b/libatalk/dsi/dsi_stream.c @@ -28,7 +28,6 @@ #include #include -#include #include #define min(a,b) ((a) < (b) ? (a) : (b)) @@ -125,7 +124,7 @@ static int dsi_peek(DSI *dsi) /* * Return all bytes up to count from dsi->buffer if there are any buffered there */ -static size_t from_buf(DSI *dsi, u_int8_t *buf, size_t count) +static size_t from_buf(DSI *dsi, uint8_t *buf, size_t count) { size_t nbe = 0; @@ -160,7 +159,7 @@ static size_t from_buf(DSI *dsi, u_int8_t *buf, size_t count) * Note: this may return fewer bytes then requested in count !! * 3. If the buffer was empty, read from the socket. */ -static ssize_t buf_read(DSI *dsi, u_int8_t *buf, size_t count) +static ssize_t buf_read(DSI *dsi, uint8_t *buf, size_t count) { ssize_t len; @@ -184,7 +183,7 @@ static ssize_t buf_read(DSI *dsi, u_int8_t *buf, size_t count) * Get "length" bytes from buffer and/or socket. In order to avoid frequent small reads * this tries to read larger chunks (8192 bytes) into a buffer. */ -static size_t dsi_buffered_stream_read(DSI *dsi, u_int8_t *data, const size_t length) +static size_t dsi_buffered_stream_read(DSI *dsi, uint8_t *data, const size_t length) { size_t len; size_t buflen; @@ -237,11 +236,17 @@ static void unblock_sig(DSI *dsi) * * 1. close the socket * 2. set the DSI_DISCONNECTED flag + * + * @returns 0 if successfully entered disconnected state + * -1 if ppid is 1 which means afpd master died + * or euid == 0 ie where still running as root (unauthenticated session) */ int dsi_disconnect(DSI *dsi) { dsi->proto_close(dsi); /* 1 */ dsi->flags |= DSI_DISCONNECTED; /* 2 */ + if (geteuid() == 0) + return -1; return 0; } @@ -264,7 +269,7 @@ ssize_t dsi_stream_write(DSI *dsi, void *data, const size_t length, int mode) return -1; while (written < length) { - len = send(dsi->socket, (u_int8_t *) data + written, length - written, flags); + len = send(dsi->socket, (uint8_t *) data + written, length - written, flags); if (len >= 0) { written += len; continue; @@ -375,14 +380,16 @@ size_t dsi_stream_read(DSI *dsi, void *data, const size_t length) stored = 0; while (stored < length) { - len = buf_read(dsi, (u_int8_t *) data + stored, length - stored); + len = buf_read(dsi, (uint8_t *) data + stored, length - stored); if (len == -1 && (errno == EINTR || errno == EAGAIN)) { - LOG(log_debug, logtype_dsi, "dsi_stream_read: select read loop"); + LOG(log_maxdebug, logtype_dsi, "dsi_stream_read: select read loop"); continue; } else if (len > 0) { stored += len; } else { /* eof or error */ /* don't log EOF error if it's just after connect (OSX 10.3 probe) */ + if (errno == ECONNRESET) + dsi->flags |= DSI_GOT_ECONNRESET; if (len || stored || dsi->read_count) { if (! (dsi->flags & DSI_DISCONNECTED)) { LOG(log_error, logtype_dsi, "dsi_stream_read: len:%d, %s", @@ -491,7 +498,7 @@ int dsi_stream_receive(DSI *dsi, void *buf, const size_t ilength, return 0; /* read in the header */ - if (dsi_buffered_stream_read(dsi, (u_int8_t *)block, sizeof(block)) != sizeof(block)) + if (dsi_buffered_stream_read(dsi, (uint8_t *)block, sizeof(block)) != sizeof(block)) return 0; dsi->header.dsi_flags = block[0];