1 /*
2  * Supporting routines used in common by all the various components of
3  * the SSH system.
4  */
5 
6 #include <assert.h>
7 #include <stdlib.h>
8 
9 #include "putty.h"
10 #include "ssh.h"
11 #include "sshchan.h"
12 
13 /* ----------------------------------------------------------------------
14  * Centralised standard methods for other channel implementations to
15  * borrow.
16  */
17 
chan_remotely_opened_confirmation(Channel * chan)18 void chan_remotely_opened_confirmation(Channel *chan)
19 {
20     unreachable("this channel type should never receive OPEN_CONFIRMATION");
21 }
22 
chan_remotely_opened_failure(Channel * chan,const char * errtext)23 void chan_remotely_opened_failure(Channel *chan, const char *errtext)
24 {
25     unreachable("this channel type should never receive OPEN_FAILURE");
26 }
27 
chan_default_want_close(Channel * chan,bool sent_local_eof,bool rcvd_remote_eof)28 bool chan_default_want_close(
29     Channel *chan, bool sent_local_eof, bool rcvd_remote_eof)
30 {
31     /*
32      * Default close policy: we start initiating the CHANNEL_CLOSE
33      * procedure as soon as both sides of the channel have seen EOF.
34      */
35     return sent_local_eof && rcvd_remote_eof;
36 }
37 
chan_no_exit_status(Channel * chan,int status)38 bool chan_no_exit_status(Channel *chan, int status)
39 {
40     return false;
41 }
42 
chan_no_exit_signal(Channel * chan,ptrlen signame,bool core_dumped,ptrlen msg)43 bool chan_no_exit_signal(
44     Channel *chan, ptrlen signame, bool core_dumped, ptrlen msg)
45 {
46     return false;
47 }
48 
chan_no_exit_signal_numeric(Channel * chan,int signum,bool core_dumped,ptrlen msg)49 bool chan_no_exit_signal_numeric(
50     Channel *chan, int signum, bool core_dumped, ptrlen msg)
51 {
52     return false;
53 }
54 
chan_no_run_shell(Channel * chan)55 bool chan_no_run_shell(Channel *chan)
56 {
57     return false;
58 }
59 
chan_no_run_command(Channel * chan,ptrlen command)60 bool chan_no_run_command(Channel *chan, ptrlen command)
61 {
62     return false;
63 }
64 
chan_no_run_subsystem(Channel * chan,ptrlen subsys)65 bool chan_no_run_subsystem(Channel *chan, ptrlen subsys)
66 {
67     return false;
68 }
69 
chan_no_enable_x11_forwarding(Channel * chan,bool oneshot,ptrlen authproto,ptrlen authdata,unsigned screen_number)70 bool chan_no_enable_x11_forwarding(
71     Channel *chan, bool oneshot, ptrlen authproto, ptrlen authdata,
72     unsigned screen_number)
73 {
74     return false;
75 }
76 
chan_no_enable_agent_forwarding(Channel * chan)77 bool chan_no_enable_agent_forwarding(Channel *chan)
78 {
79     return false;
80 }
81 
chan_no_allocate_pty(Channel * chan,ptrlen termtype,unsigned width,unsigned height,unsigned pixwidth,unsigned pixheight,struct ssh_ttymodes modes)82 bool chan_no_allocate_pty(
83     Channel *chan, ptrlen termtype, unsigned width, unsigned height,
84     unsigned pixwidth, unsigned pixheight, struct ssh_ttymodes modes)
85 {
86     return false;
87 }
88 
chan_no_set_env(Channel * chan,ptrlen var,ptrlen value)89 bool chan_no_set_env(Channel *chan, ptrlen var, ptrlen value)
90 {
91     return false;
92 }
93 
chan_no_send_break(Channel * chan,unsigned length)94 bool chan_no_send_break(Channel *chan, unsigned length)
95 {
96     return false;
97 }
98 
chan_no_send_signal(Channel * chan,ptrlen signame)99 bool chan_no_send_signal(Channel *chan, ptrlen signame)
100 {
101     return false;
102 }
103 
chan_no_change_window_size(Channel * chan,unsigned width,unsigned height,unsigned pixwidth,unsigned pixheight)104 bool chan_no_change_window_size(
105     Channel *chan, unsigned width, unsigned height,
106     unsigned pixwidth, unsigned pixheight)
107 {
108     return false;
109 }
110 
chan_no_request_response(Channel * chan,bool success)111 void chan_no_request_response(Channel *chan, bool success)
112 {
113     unreachable("this channel type should never send a want-reply request");
114 }
115 
116 /* ----------------------------------------------------------------------
117  * Other miscellaneous utility functions.
118  */
119 
free_rportfwd(struct ssh_rportfwd * rpf)120 void free_rportfwd(struct ssh_rportfwd *rpf)
121 {
122     if (rpf) {
123         sfree(rpf->log_description);
124         sfree(rpf->shost);
125         sfree(rpf->dhost);
126         sfree(rpf);
127     }
128 }
129