Ejemplo n.º 1
0
ssize_t cli_receive_smb_data(struct cli_state *cli, char *buffer, size_t len)
{
	NTSTATUS status;

	set_smb_read_error(&cli->smb_rw_error, SMB_READ_OK);

	status = read_fd_with_timeout(
		cli->fd, buffer, len, len, cli->timeout, NULL);
	if (NT_STATUS_IS_OK(status)) {
		return len;
	}

	if (NT_STATUS_EQUAL(status, NT_STATUS_END_OF_FILE)) {
		set_smb_read_error(&cli->smb_rw_error, SMB_READ_EOF);
		return -1;
	}

	if (NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT)) {
		set_smb_read_error(&cli->smb_rw_error, SMB_READ_TIMEOUT);
		return -1;
	}

	set_smb_read_error(&cli->smb_rw_error, SMB_READ_ERROR);
	return -1;
}
Ejemplo n.º 2
0
NTSTATUS receive_smb_raw(int fd, char *buffer, size_t buflen, unsigned int timeout,
			 size_t maxlen, size_t *p_len)
{
	size_t len;
	NTSTATUS status;

	status = read_smb_length_return_keepalive(fd,buffer,timeout,&len);

	if (!NT_STATUS_IS_OK(status)) {
		DEBUG(0, ("read_fd_with_timeout failed, read "
			  "error = %s.\n", nt_errstr(status)));
		return status;
	}

	if (len > buflen) {
		DEBUG(0,("Invalid packet length! (%lu bytes).\n",
					(unsigned long)len));
		return NT_STATUS_INVALID_PARAMETER;
	}

	if(len > 0) {
		if (maxlen) {
			len = MIN(len,maxlen);
		}

		status = read_fd_with_timeout(
			fd, buffer+4, len, len, timeout, &len);

		if (!NT_STATUS_IS_OK(status)) {
			DEBUG(0, ("read_fd_with_timeout failed, read error = "
				  "%s.\n", nt_errstr(status)));
			return status;
		}

		/* not all of samba3 properly checks for packet-termination
		 * of strings. This ensures that we don't run off into
		 * empty space. */
		SSVAL(buffer+4,len, 0);
	}

	*p_len = len;
	return NT_STATUS_OK;
}
Ejemplo n.º 3
0
NTSTATUS read_smb_length_return_keepalive(int fd, char *inbuf,
					  unsigned int timeout,
					  size_t *len)
{
	int msg_type;
	NTSTATUS status;

	status = read_fd_with_timeout(fd, inbuf, 4, 4, timeout, NULL);

	if (!NT_STATUS_IS_OK(status)) {
		return status;
	}

	*len = smb_len(inbuf);
	msg_type = CVAL(inbuf,0);

	if (msg_type == NBSSkeepalive) {
		DEBUG(5,("Got keepalive packet\n"));
	}

	DEBUG(10,("got smb length of %lu\n",(unsigned long)(*len)));

	return NT_STATUS_OK;
}
Ejemplo n.º 4
0
NTSTATUS read_data(int fd, char *buffer, size_t N)
{
	return read_fd_with_timeout(fd, buffer, N, N, 0, NULL);
}
Ejemplo n.º 5
0
static int expect(int master, char *issue, char *expected)
{
	char buffer[1024];
	int attempts, timeout, nread;
	size_t len;
	bool match = False;

	for (attempts = 0; attempts < 2; attempts++) {
		NTSTATUS status;
		if (!strequal(issue, ".")) {
			if (lp_passwd_chat_debug())
				DEBUG(100, ("expect: sending [%s]\n", issue));

			if ((len = sys_write(master, issue, strlen(issue))) != strlen(issue)) {
				DEBUG(2,("expect: (short) write returned %d\n",
					 (int)len ));
				return False;
			}
		}

		if (strequal(expected, "."))
			return True;

		/* Initial timeout. */
		timeout = lp_passwd_chat_timeout() * 1000;
		nread = 0;
		buffer[nread] = 0;

		while (True) {
			status = read_fd_with_timeout(
				master, buffer + nread, 1,
				sizeof(buffer) - nread - 1,
				timeout, &len);

			if (!NT_STATUS_IS_OK(status)) {
				DEBUG(2, ("expect: read error %s\n",
					  nt_errstr(status)));
				break;
			}
			nread += len;
			buffer[nread] = 0;

			{
				/* Eat leading/trailing whitespace before match. */
				char *str = SMB_STRDUP(buffer);
				if (!str) {
					DEBUG(2,("expect: ENOMEM\n"));
					return False;
				}
				trim_char(str, ' ', ' ');

				if ((match = unix_wild_match(expected, str)) == True) {
					/* Now data has started to return, lower timeout. */
					timeout = lp_passwd_chat_timeout() * 100;
				}
				SAFE_FREE(str);
			}
		}

		if (lp_passwd_chat_debug())
			DEBUG(100, ("expect: expected [%s] received [%s] match %s\n",
				    expected, buffer, match ? "yes" : "no" ));

		if (match)
			break;

		if (!NT_STATUS_IS_OK(status)) {
			DEBUG(2, ("expect: %s\n", nt_errstr(status)));
			return False;
		}
	}

	DEBUG(10,("expect: returning %s\n", match ? "True" : "False" ));
	return match;
}