FreeBSD/crypto/openssh/authfd.c
/* Communicate with agent: send request and read reply */
Communicate with agent: send request and read reply
Communicate with agent : send request and read reply
static int
ssh_request_reply(int sock, struct sshbuf *request, struct sshbuf *reply)
{
	int r;
	size_t l, len;
	char buf[1024];
	len = sshbuf_len(request);
	put_u32(buf, len);
	if (atomicio(vwrite, sock, buf, 4) != 4 ||
	    atomicio(vwrite, sock, (u_char *)sshbuf_ptr(request),
	    sshbuf_len(request)) != sshbuf_len(request))
		return SSH_ERR_AGENT_COMMUNICATION;
	if (atomicio(read, sock, buf, 4) != 4)
	    return SSH_ERR_AGENT_COMMUNICATION;
	len = get_u32(buf);
	if (len > MAX_AGENT_REPLY_LEN)
		return SSH_ERR_INVALID_FORMAT;
	sshbuf_reset(reply);
	while (len > 0) {
		l = len;
		if (l > sizeof(buf))
			l = sizeof(buf);
		if (atomicio(read, sock, buf, l) != l)
			return SSH_ERR_AGENT_COMMUNICATION;
		if ((r = sshbuf_put(reply, buf, l)) != 0)
			return r;
		len -= l;
	}
	return 0;
}
static int ssh_request_reply ( int sock , struct sshbuf * request , struct sshbuf * reply ) { int r ; size_t l , len ; char buf [ 1024 ] ; len = sshbuf_len ( request ) ; put_u32 ( buf , len ) ; if ( atomicio ( vwrite , sock , buf , 4 ) != 4 || atomicio ( vwrite , sock , ( u_char * ) sshbuf_ptr ( request ) , sshbuf_len ( request ) ) != sshbuf_len ( request ) ) return SSH_ERR_AGENT_COMMUNICATION ; if ( atomicio ( read , sock , buf , 4 ) != 4 ) return SSH_ERR_AGENT_COMMUNICATION ; len = get_u32 ( buf ) ; if ( len > MAX_AGENT_REPLY_LEN ) return SSH_ERR_INVALID_FORMAT ; sshbuf_reset ( reply ) ; while ( len > 0 ) { l = len ; if ( l > sizeof ( buf ) ) l = sizeof ( buf ) ; if ( atomicio ( read , sock , buf , l ) != l ) return SSH_ERR_AGENT_COMMUNICATION ; if ( ( r = sshbuf_put ( reply , buf , l ) ) != 0 ) return r ; len -= l ; } return 0 ; }
Communicate with agent: send request and read reply
Communicate with agent : send request and read reply
/* Get the length of the message, and format it in the buffer. */ /* Send the length and then the packet to the agent. */ /*
	 * Wait for response from the agent.  First read the length of the
	 * response packet.
	 */ /* Extract the length, and check it for sanity. */ /* Read the rest of the response in to the buffer. */