#include <atalk/logger.h>
#include <atalk/dsi.h>
-#include <netatalk/endian.h>
#include <atalk/util.h>
#define min(a,b) ((a) < (b) ? (a) : (b))
/*
* 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;
* 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;
* 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;
*
* 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;
}
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;
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",
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];