mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-01-09 17:38:00 +00:00
Pass an Interactor to new_connection().
Thanks to the previous commit, this new parameter can replace two of the existing ones: instead of passing a LogPolicy and a Seat, we now pass just an Interactor, from which any proxy implementation can extract the LogPolicy and the Seat anyway if they need it.
This commit is contained in:
parent
aac5e096fa
commit
89a390bdeb
24
network.h
24
network.h
@ -137,19 +137,14 @@ struct PlugVtable {
|
|||||||
* layer is now responsible for freeing it, and the caller shouldn't
|
* layer is now responsible for freeing it, and the caller shouldn't
|
||||||
* assume it exists any more.
|
* assume it exists any more.
|
||||||
*
|
*
|
||||||
* You can optionally pass a LogPolicy to this function, which will be
|
|
||||||
* passed on in turn to proxy types that can use one (e.g. SSH jump
|
|
||||||
* host proxy). If you don't have one, all proxy types are required to
|
|
||||||
* be able to manage without (and will just degrade their logging
|
|
||||||
* control).
|
|
||||||
*
|
|
||||||
* If calling this from a backend with a Seat, you can also give it a
|
* If calling this from a backend with a Seat, you can also give it a
|
||||||
* pointer to your 'Seat *'. In that situation, it might replace the
|
* pointer to the backend's Interactor trait. In that situation, it
|
||||||
* 'Seat *' with a temporary seat of its own, and give the real Seat
|
* might replace the backend's seat with a temporary seat of its own,
|
||||||
* to the proxy system so that it can ask for passwords (and, in the
|
* and give the real Seat to an Interactor somewhere in the proxy
|
||||||
* case of SSH proxying, other prompts like host key checks). If that
|
* system so that it can ask for passwords (and, in the case of SSH
|
||||||
* happens, then the resulting 'temp seat' is the backend's property,
|
* proxying, other prompts like host key checks). If that happens,
|
||||||
* and it will have to remember to free it when cleaning up, or after
|
* then the resulting 'temp seat' is the backend's property, and it
|
||||||
|
* will have to remember to free it when cleaning up, or after
|
||||||
* flushing it back into the real seat when the network connection
|
* flushing it back into the real seat when the network connection
|
||||||
* attempt completes.
|
* attempt completes.
|
||||||
*
|
*
|
||||||
@ -163,7 +158,7 @@ struct PlugVtable {
|
|||||||
Socket *new_connection(SockAddr *addr, const char *hostname,
|
Socket *new_connection(SockAddr *addr, const char *hostname,
|
||||||
int port, bool privport,
|
int port, bool privport,
|
||||||
bool oobinline, bool nodelay, bool keepalive,
|
bool oobinline, bool nodelay, bool keepalive,
|
||||||
Plug *plug, Conf *conf, LogPolicy *lp, Seat **seat);
|
Plug *plug, Conf *conf, Interactor *interactor);
|
||||||
Socket *new_listener(const char *srcaddr, int port, Plug *plug,
|
Socket *new_listener(const char *srcaddr, int port, Plug *plug,
|
||||||
bool local_host_only, Conf *conf, int addressfamily);
|
bool local_host_only, Conf *conf, int addressfamily);
|
||||||
SockAddr *name_lookup(const char *host, int port, char **canonicalname,
|
SockAddr *name_lookup(const char *host, int port, char **canonicalname,
|
||||||
@ -181,8 +176,7 @@ Socket *platform_new_connection(SockAddr *addr, const char *hostname,
|
|||||||
Socket *sshproxy_new_connection(SockAddr *addr, const char *hostname,
|
Socket *sshproxy_new_connection(SockAddr *addr, const char *hostname,
|
||||||
int port, bool privport,
|
int port, bool privport,
|
||||||
bool oobinline, bool nodelay, bool keepalive,
|
bool oobinline, bool nodelay, bool keepalive,
|
||||||
Plug *plug, Conf *conf,
|
Plug *plug, Conf *conf, Interactor *itr);
|
||||||
LogPolicy *clientlp, Seat **clientseat);
|
|
||||||
|
|
||||||
/* socket functions */
|
/* socket functions */
|
||||||
|
|
||||||
|
@ -210,8 +210,7 @@ static char *raw_init(const BackendVtable *vt, Seat *seat,
|
|||||||
* Open socket.
|
* Open socket.
|
||||||
*/
|
*/
|
||||||
raw->s = new_connection(addr, *realhost, port, false, true, nodelay,
|
raw->s = new_connection(addr, *realhost, port, false, true, nodelay,
|
||||||
keepalive, &raw->plug, conf,
|
keepalive, &raw->plug, conf, &raw->interactor);
|
||||||
log_get_policy(logctx), &raw->seat);
|
|
||||||
if ((err = sk_socket_error(raw->s)) != NULL)
|
if ((err = sk_socket_error(raw->s)) != NULL)
|
||||||
return dupstr(err);
|
return dupstr(err);
|
||||||
|
|
||||||
|
@ -290,7 +290,7 @@ static char *rlogin_init(const BackendVtable *vt, Seat *seat,
|
|||||||
*/
|
*/
|
||||||
rlogin->s = new_connection(addr, *realhost, port, true, false,
|
rlogin->s = new_connection(addr, *realhost, port, true, false,
|
||||||
nodelay, keepalive, &rlogin->plug, conf,
|
nodelay, keepalive, &rlogin->plug, conf,
|
||||||
log_get_policy(logctx), &rlogin->seat);
|
&rlogin->interactor);
|
||||||
if ((err = sk_socket_error(rlogin->s)) != NULL)
|
if ((err = sk_socket_error(rlogin->s)) != NULL)
|
||||||
return dupstr(err);
|
return dupstr(err);
|
||||||
|
|
||||||
|
@ -759,7 +759,7 @@ static char *supdup_init(const BackendVtable *x, Seat *seat,
|
|||||||
*/
|
*/
|
||||||
supdup->s = new_connection(addr, *realhost, port, false, true,
|
supdup->s = new_connection(addr, *realhost, port, false, true,
|
||||||
nodelay, keepalive, &supdup->plug, supdup->conf,
|
nodelay, keepalive, &supdup->plug, supdup->conf,
|
||||||
log_get_policy(logctx), &supdup->seat);
|
&supdup->interactor);
|
||||||
if ((err = sk_socket_error(supdup->s)) != NULL)
|
if ((err = sk_socket_error(supdup->s)) != NULL)
|
||||||
return dupstr(err);
|
return dupstr(err);
|
||||||
|
|
||||||
|
@ -782,7 +782,7 @@ static char *telnet_init(const BackendVtable *vt, Seat *seat,
|
|||||||
*/
|
*/
|
||||||
telnet->s = new_connection(addr, *realhost, port, false, true, nodelay,
|
telnet->s = new_connection(addr, *realhost, port, false, true, nodelay,
|
||||||
keepalive, &telnet->plug, telnet->conf,
|
keepalive, &telnet->plug, telnet->conf,
|
||||||
log_get_policy(logctx), &telnet->seat);
|
&telnet->interactor);
|
||||||
if ((err = sk_socket_error(telnet->s)) != NULL)
|
if ((err = sk_socket_error(telnet->s)) != NULL)
|
||||||
return dupstr(err);
|
return dupstr(err);
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ SockAddr *name_lookup(const char *host, int port, char **canonicalname,
|
|||||||
Socket *new_connection(SockAddr *addr, const char *hostname,
|
Socket *new_connection(SockAddr *addr, const char *hostname,
|
||||||
int port, bool privport,
|
int port, bool privport,
|
||||||
bool oobinline, bool nodelay, bool keepalive,
|
bool oobinline, bool nodelay, bool keepalive,
|
||||||
Plug *plug, Conf *conf, LogPolicy *lp, Seat **seat)
|
Plug *plug, Conf *conf, Interactor *itr)
|
||||||
{
|
{
|
||||||
return sk_new(addr, port, privport, oobinline, nodelay, keepalive, plug);
|
return sk_new(addr, port, privport, oobinline, nodelay, keepalive, plug);
|
||||||
}
|
}
|
||||||
|
@ -10,8 +10,7 @@ const bool ssh_proxy_supported = false;
|
|||||||
Socket *sshproxy_new_connection(SockAddr *addr, const char *hostname,
|
Socket *sshproxy_new_connection(SockAddr *addr, const char *hostname,
|
||||||
int port, bool privport,
|
int port, bool privport,
|
||||||
bool oobinline, bool nodelay, bool keepalive,
|
bool oobinline, bool nodelay, bool keepalive,
|
||||||
Plug *plug, Conf *conf,
|
Plug *plug, Conf *conf, Interactor *itr)
|
||||||
LogPolicy *clientlp, Seat **clientseat)
|
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -393,7 +393,7 @@ static const PlugVtable ProxySocket_plugvt = {
|
|||||||
Socket *new_connection(SockAddr *addr, const char *hostname,
|
Socket *new_connection(SockAddr *addr, const char *hostname,
|
||||||
int port, bool privport,
|
int port, bool privport,
|
||||||
bool oobinline, bool nodelay, bool keepalive,
|
bool oobinline, bool nodelay, bool keepalive,
|
||||||
Plug *plug, Conf *conf, LogPolicy *lp, Seat **seat)
|
Plug *plug, Conf *conf, Interactor *itr)
|
||||||
{
|
{
|
||||||
int type = conf_get_int(conf, CONF_proxy_type);
|
int type = conf_get_int(conf, CONF_proxy_type);
|
||||||
|
|
||||||
@ -409,7 +409,7 @@ Socket *new_connection(SockAddr *addr, const char *hostname,
|
|||||||
if (type == PROXY_SSH &&
|
if (type == PROXY_SSH &&
|
||||||
(sret = sshproxy_new_connection(addr, hostname, port, privport,
|
(sret = sshproxy_new_connection(addr, hostname, port, privport,
|
||||||
oobinline, nodelay, keepalive,
|
oobinline, nodelay, keepalive,
|
||||||
plug, conf, lp, seat)) != NULL)
|
plug, conf, itr)) != NULL)
|
||||||
return sret;
|
return sret;
|
||||||
|
|
||||||
if ((sret = platform_new_connection(addr, hostname, port, privport,
|
if ((sret = platform_new_connection(addr, hostname, port, privport,
|
||||||
|
@ -483,7 +483,7 @@ Socket *sshproxy_new_connection(SockAddr *addr, const char *hostname,
|
|||||||
int port, bool privport,
|
int port, bool privport,
|
||||||
bool oobinline, bool nodelay, bool keepalive,
|
bool oobinline, bool nodelay, bool keepalive,
|
||||||
Plug *plug, Conf *clientconf,
|
Plug *plug, Conf *clientconf,
|
||||||
LogPolicy *clientlp, Seat **clientseat)
|
Interactor *clientitr)
|
||||||
{
|
{
|
||||||
SshProxy *sp = snew(SshProxy);
|
SshProxy *sp = snew(SshProxy);
|
||||||
memset(sp, 0, sizeof(*sp));
|
memset(sp, 0, sizeof(*sp));
|
||||||
@ -594,24 +594,27 @@ Socket *sshproxy_new_connection(SockAddr *addr, const char *hostname,
|
|||||||
sfree(realhost);
|
sfree(realhost);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If we've been given useful bits and pieces for interacting with
|
* If we've been given an Interactor by the caller, squirrel away
|
||||||
* the end user, squirrel them away now.
|
* things it's holding.
|
||||||
*/
|
*/
|
||||||
sp->clientlp = clientlp;
|
if (clientitr) {
|
||||||
if (clientseat && (backvt->flags & BACKEND_NOTIFIES_SESSION_START)) {
|
sp->clientlp = interactor_logpolicy(clientitr);
|
||||||
/*
|
if (backvt->flags & BACKEND_NOTIFIES_SESSION_START) {
|
||||||
* We can only keep the client's Seat if our own backend will
|
/*
|
||||||
* tell us when to give it back. (SSH-based backends _should_
|
* We can only keep the client's Seat if our own backend will
|
||||||
* do that, but we check the flag here anyway.)
|
* tell us when to give it back. (SSH-based backends _should_
|
||||||
*
|
* do that, but we check the flag here anyway.)
|
||||||
* Also, check if the client already has a TempSeat, and if
|
*
|
||||||
* so, don't wrap it with another one.
|
* Also, check if the client already has a TempSeat, and if
|
||||||
*/
|
* so, don't wrap it with another one.
|
||||||
if (is_tempseat(*clientseat)) {
|
*/
|
||||||
sp->clientseat = tempseat_get_real(*clientseat);
|
Seat *clientseat = interactor_get_seat(clientitr);
|
||||||
} else {
|
if (is_tempseat(clientseat)) {
|
||||||
sp->clientseat = *clientseat;
|
sp->clientseat = tempseat_get_real(clientseat);
|
||||||
*clientseat = tempseat_new(sp->clientseat);
|
} else {
|
||||||
|
sp->clientseat = clientseat;
|
||||||
|
interactor_set_seat(clientitr, tempseat_new(sp->clientseat));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1159,7 +1159,7 @@ char *portfwdmgr_connect(PortFwdManager *mgr, Channel **chan_ret,
|
|||||||
|
|
||||||
pf->s = new_connection(addr, dummy_realhost, port,
|
pf->s = new_connection(addr, dummy_realhost, port,
|
||||||
false, true, false, false, &pf->plug, mgr->conf,
|
false, true, false, false, &pf->plug, mgr->conf,
|
||||||
NULL, NULL);
|
NULL);
|
||||||
sfree(dummy_realhost);
|
sfree(dummy_realhost);
|
||||||
if ((err = sk_socket_error(pf->s)) != NULL) {
|
if ((err = sk_socket_error(pf->s)) != NULL) {
|
||||||
char *err_ret = dupstr(err);
|
char *err_ret = dupstr(err);
|
||||||
|
@ -826,8 +826,7 @@ static char *connect_to_host(
|
|||||||
|
|
||||||
ssh->s = new_connection(addr, *realhost, port,
|
ssh->s = new_connection(addr, *realhost, port,
|
||||||
false, true, nodelay, keepalive,
|
false, true, nodelay, keepalive,
|
||||||
&ssh->plug, ssh->conf,
|
&ssh->plug, ssh->conf, &ssh->interactor);
|
||||||
log_get_policy(ssh->logctx), &ssh->seat);
|
|
||||||
if ((err = sk_socket_error(ssh->s)) != NULL) {
|
if ((err = sk_socket_error(ssh->s)) != NULL) {
|
||||||
ssh->s = NULL;
|
ssh->s = NULL;
|
||||||
seat_notify_remote_exit(ssh->seat);
|
seat_notify_remote_exit(ssh->seat);
|
||||||
|
@ -563,7 +563,7 @@ static size_t x11_send(
|
|||||||
xconn->s = new_connection(sk_addr_dup(xconn->disp->addr),
|
xconn->s = new_connection(sk_addr_dup(xconn->disp->addr),
|
||||||
xconn->disp->realhost, xconn->disp->port,
|
xconn->disp->realhost, xconn->disp->port,
|
||||||
false, true, false, false, &xconn->plug,
|
false, true, false, false, &xconn->plug,
|
||||||
sshfwd_get_conf(xconn->c), NULL, NULL);
|
sshfwd_get_conf(xconn->c), NULL);
|
||||||
if ((err = sk_socket_error(xconn->s)) != NULL) {
|
if ((err = sk_socket_error(xconn->s)) != NULL) {
|
||||||
char *err_message = dupprintf("unable to connect to"
|
char *err_message = dupprintf("unable to connect to"
|
||||||
" forwarded X server: %s", err);
|
" forwarded X server: %s", err);
|
||||||
|
@ -1189,7 +1189,7 @@ void run_agent(FILE *logfp, const char *symlink_path)
|
|||||||
s = new_connection(sk_addr_dup(disp->addr),
|
s = new_connection(sk_addr_dup(disp->addr),
|
||||||
disp->realhost, disp->port,
|
disp->realhost, disp->port,
|
||||||
false, true, false, false, &conn->plug, conf,
|
false, true, false, false, &conn->plug, conf,
|
||||||
NULL, NULL);
|
NULL);
|
||||||
if ((err = sk_socket_error(s)) != NULL) {
|
if ((err = sk_socket_error(s)) != NULL) {
|
||||||
fprintf(stderr, "pageant: unable to connect to X server: %s", err);
|
fprintf(stderr, "pageant: unable to connect to X server: %s", err);
|
||||||
exit(1);
|
exit(1);
|
||||||
|
@ -297,7 +297,7 @@ int platform_ssh_share(const char *pi_name, Conf *conf,
|
|||||||
if (can_downstream) {
|
if (can_downstream) {
|
||||||
retsock = new_connection(unix_sock_addr(sockname),
|
retsock = new_connection(unix_sock_addr(sockname),
|
||||||
"", 0, false, true, false, false,
|
"", 0, false, true, false, false,
|
||||||
downplug, conf, NULL, NULL);
|
downplug, conf, NULL);
|
||||||
if (sk_socket_error(retsock) == NULL) {
|
if (sk_socket_error(retsock) == NULL) {
|
||||||
sfree(*logtext);
|
sfree(*logtext);
|
||||||
*logtext = sockname;
|
*logtext = sockname;
|
||||||
|
Loading…
Reference in New Issue
Block a user