Prepare to remove MOD_CUGTERM patch
This commit is contained in:
@@ -32,9 +32,6 @@ const struct BackendVtable *const backends[] = {
|
||||
&rlogin_backend,
|
||||
&raw_backend,
|
||||
&serial_backend,
|
||||
#ifdef MOD_CYGTERM
|
||||
&cygterm_backend,
|
||||
#endif
|
||||
#ifdef MOD_ADB
|
||||
&adb_backend,
|
||||
#endif
|
||||
|
||||
@@ -18,9 +18,6 @@ const struct BackendVtable *const backends[] = {
|
||||
&adb_backend,
|
||||
#endif
|
||||
&serial_backend,
|
||||
#ifdef MOD_CYGTERM
|
||||
&cygterm_backend,
|
||||
#endif
|
||||
NULL
|
||||
};
|
||||
|
||||
|
||||
@@ -16,9 +16,6 @@ const struct BackendVtable *const backends[] = {
|
||||
&raw_backend,
|
||||
#ifdef MOD_ADB
|
||||
&adb_backend,
|
||||
#endif
|
||||
#ifdef MOD_CYGTERM
|
||||
&cygterm_backend,
|
||||
#endif
|
||||
NULL
|
||||
};
|
||||
|
||||
@@ -168,12 +168,6 @@ static bool cmdline_check_unavailable(int flag, const char *p)
|
||||
static bool seen_hostname_argument = false;
|
||||
static bool seen_port_argument = false;
|
||||
|
||||
#ifdef MOD_CYGTERM
|
||||
void cygterm_set_flag( int flag ) ;
|
||||
bool get_got_host(void){ return seen_hostname_argument ; }
|
||||
void set_got_host(bool val ){ seen_hostname_argument = val ; }
|
||||
#endif
|
||||
|
||||
int cmdline_process_param(const char *p, char *value,
|
||||
int need_save, Conf *conf)
|
||||
{
|
||||
@@ -533,17 +527,6 @@ int cmdline_process_param(const char *p, char *value,
|
||||
SetAutoStoreSSHKey();
|
||||
}
|
||||
#endif
|
||||
#ifdef MOD_CYGTERM
|
||||
if (!strcmp(p, "-cygterm")) {
|
||||
RETURN(1);
|
||||
UNAVAILABLE_IN(TOOLTYPE_FILETRANSFER | TOOLTYPE_NONNETWORK);
|
||||
cygterm_set_flag( 1 ) ;
|
||||
//default_protocol = cfg->protocol = PROT_CYGTERM;
|
||||
default_protocol = PROT_CYGTERM;
|
||||
conf_set_int(conf, CONF_protocol, default_protocol) ;
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
#ifdef MOD_ADB
|
||||
if (!strcmp(p, "-adb") && GetADBFlag()) {
|
||||
RETURN(1);
|
||||
|
||||
@@ -13,9 +13,6 @@
|
||||
#ifdef MOD_RUTTY
|
||||
#include "script.h"
|
||||
#endif /* rutty */
|
||||
#ifdef MOD_CYGTERM
|
||||
int cygterm_get_flag( void ) ;
|
||||
#endif
|
||||
#ifdef MOD_PERSO
|
||||
#include "kitty.h"
|
||||
union control * ctrlHostnameEdit = NULL ;
|
||||
@@ -256,11 +253,6 @@ static void config_host_handler(union control *ctrl, dlgparam *dlg,
|
||||
*/
|
||||
dlg_label_change(ctrl, dlg, "Serial line");
|
||||
dlg_editbox_set(ctrl, dlg, conf_get_str(conf, CONF_serline));
|
||||
#ifdef MOD_CYGTERM
|
||||
} else if( cygterm_get_flag() && (conf_get_int(conf, CONF_protocol) == PROT_CYGTERM) ) {
|
||||
dlg_label_change(ctrl, dlg, "Command (use - for login shell, ? for exe)");
|
||||
dlg_editbox_set(ctrl, dlg, conf_get_str(conf, CONF_cygcmd) );
|
||||
#endif
|
||||
#ifdef MOD_ADB
|
||||
} else if (conf_get_int(conf, CONF_protocol) == PROT_ADB) {
|
||||
char *saved_host = conf_get_str(conf, CONF_host);
|
||||
@@ -277,12 +269,6 @@ static void config_host_handler(union control *ctrl, dlgparam *dlg,
|
||||
char *s = dlg_editbox_get(ctrl, dlg);
|
||||
if (conf_get_int(conf, CONF_protocol) == PROT_SERIAL)
|
||||
conf_set_str(conf, CONF_serline, s);
|
||||
#ifdef MOD_CYGTERM
|
||||
else if( cygterm_get_flag() && (conf_get_int(conf, CONF_protocol) == PROT_CYGTERM) ) {
|
||||
char *s = dlg_editbox_get(ctrl, dlg);
|
||||
conf_set_str(conf, CONF_cygcmd, s);
|
||||
}
|
||||
#endif
|
||||
else
|
||||
conf_set_str(conf, CONF_host, s);
|
||||
sfree(s);
|
||||
@@ -308,11 +294,6 @@ static void config_port_handler(union control *ctrl, dlgparam *dlg,
|
||||
*/
|
||||
dlg_label_change(ctrl, dlg, "Speed");
|
||||
sprintf(buf, "%d", conf_get_int(conf, CONF_serspeed));
|
||||
#ifdef MOD_CYGTERM
|
||||
} else if( cygterm_get_flag() && (conf_get_int(conf, CONF_protocol) == PROT_CYGTERM) ) {
|
||||
dlg_label_change(ctrl, dlg, "Port (ignored)");
|
||||
strcpy(buf, "-");
|
||||
#endif
|
||||
} else {
|
||||
dlg_label_change(ctrl, dlg, PORT_BOX_TITLE);
|
||||
if (conf_get_int(conf, CONF_port) != 0)
|
||||
@@ -329,9 +310,6 @@ static void config_port_handler(union control *ctrl, dlgparam *dlg,
|
||||
|
||||
if (conf_get_int(conf, CONF_protocol) == PROT_SERIAL)
|
||||
conf_set_int(conf, CONF_serspeed, i);
|
||||
#ifdef MOD_CYGTERM
|
||||
else if( cygterm_get_flag() && (conf_get_int(conf, CONF_protocol) == PROT_CYGTERM) ) ;
|
||||
#endif
|
||||
else
|
||||
conf_set_int(conf, CONF_port, i);
|
||||
}
|
||||
@@ -2298,9 +2276,6 @@ void setup_config_box(struct controlbox *b, bool midsession,
|
||||
ssd->listbox->listbox.height = GetConfigBoxHeight() ;
|
||||
#else
|
||||
ssd->listbox->listbox.height = 7;
|
||||
#endif
|
||||
#ifdef MOD_CYGTERM
|
||||
if( cygterm_get_flag() ) ssd->listbox->listbox.height-- ;
|
||||
#endif
|
||||
if (!midsession) {
|
||||
ssd->loadbutton = ctrl_pushbutton(s, "Load", 'l',
|
||||
|
||||
@@ -105,10 +105,6 @@ bool conf_launchable(Conf *conf)
|
||||
{
|
||||
if (conf_get_int(conf, CONF_protocol) == PROT_SERIAL)
|
||||
return conf_get_str(conf, CONF_serline)[0] != 0;
|
||||
#ifdef MOD_CYGTERM
|
||||
else if (conf_get_int(conf, CONF_protocol) == PROT_CYGTERM)
|
||||
return conf_get_str(conf, CONF_cygcmd)[0] != 0;
|
||||
#endif
|
||||
else
|
||||
return conf_get_str(conf, CONF_host)[0] != 0;
|
||||
}
|
||||
@@ -117,10 +113,6 @@ char const *conf_dest(Conf *conf)
|
||||
{
|
||||
if (conf_get_int(conf, CONF_protocol) == PROT_SERIAL)
|
||||
return conf_get_str(conf, CONF_serline);
|
||||
#ifdef MOD_CYGTERM
|
||||
else if (conf_get_int(conf, CONF_protocol) == PROT_CYGTERM)
|
||||
return conf_get_str(conf, CONF_cygcmd) ;
|
||||
#endif
|
||||
else
|
||||
return conf_get_str(conf, CONF_host);
|
||||
}
|
||||
|
||||
@@ -145,10 +145,6 @@ Socket *sk_new(SockAddr *addr, int port, bool privport, bool oobinline,
|
||||
Socket *sk_newlistener(const char *srcaddr, int port, Plug *plug,
|
||||
bool local_host_only, int address_family);
|
||||
|
||||
#ifdef MOD_CYGTERM
|
||||
int sk_getport(Socket *s);
|
||||
#endif
|
||||
|
||||
static inline Plug *sk_plug(Socket *s, Plug *p)
|
||||
{ return s->vt->plug(s, p); }
|
||||
static inline void sk_close(Socket *s)
|
||||
|
||||
@@ -412,9 +412,6 @@ enum {
|
||||
enum {
|
||||
/* Protocol back ends. (CONF_protocol) */
|
||||
PROT_RAW, PROT_TELNET, PROT_RLOGIN, PROT_SSH,
|
||||
#ifdef MOD_CYGTERM
|
||||
PROT_CYGTERM,
|
||||
#endif
|
||||
#ifdef MOD_ADB
|
||||
PROT_ADB,
|
||||
#endif
|
||||
@@ -1586,13 +1583,6 @@ NORETURN void cleanup_exit(int);
|
||||
X(STR, NONE, script_waitfor) \
|
||||
X(STR, NONE, script_halton) \
|
||||
/* #endif */ \
|
||||
/* #ifdef MOD_CYGTERM */ \
|
||||
/* Cygterm options */ \
|
||||
X(INT, NONE, cygautopath) \
|
||||
X(INT, NONE, cygterm64) \
|
||||
X(STR, NONE, cygcmd) \
|
||||
X(INT, NONE, alt_metabit) /* set meta instead of escape */ \
|
||||
/* #endif */ \
|
||||
/* #if (defined MOD_BACKGROUNDIMAGE) && (!defined FDJ) */\
|
||||
X(INT, NONE, bg_opacity) \
|
||||
X(INT, NONE, bg_slideshow) \
|
||||
@@ -1932,14 +1922,6 @@ extern const struct BackendVtable raw_backend;
|
||||
|
||||
//extern Backend adb_backend;
|
||||
extern const struct BackendVtable adb_backend ;
|
||||
#endif
|
||||
#ifdef MOD_CYGTERM
|
||||
/*
|
||||
* Exports from cygterm.c.
|
||||
*/
|
||||
extern const struct BackendVtable cygterm_backend;
|
||||
void cygterm_setup_config_box(struct controlbox *b, int midsession);
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
|
||||
@@ -866,13 +866,6 @@ void save_open_settings(settings_w *sesskey, Conf *conf)
|
||||
write_setting_s(sesskey, "HyperlinkRegularExpression", conf_get_str(conf, CONF_url_regex));
|
||||
#endif
|
||||
#endif
|
||||
#ifdef MOD_CYGTERM
|
||||
//if (do_host)
|
||||
write_setting_i(sesskey, "CygtermAltMetabit", conf_get_int(conf, CONF_alt_metabit));
|
||||
write_setting_i(sesskey, "CygtermAutoPath", conf_get_int(conf, CONF_cygautopath) );
|
||||
write_setting_i(sesskey, "Cygterm64", conf_get_int(conf, CONF_cygterm64));
|
||||
write_setting_s(sesskey, "CygtermCommand", conf_get_str(conf, CONF_cygcmd) );
|
||||
#endif
|
||||
#ifdef MOD_ZMODEM
|
||||
write_setting_filename(sesskey, "rzCommand", conf_get_filename(conf, CONF_rzcommand) );
|
||||
write_setting_s(sesskey, "rzOptions", conf_get_str(conf, CONF_rzoptions) );
|
||||
@@ -1506,12 +1499,6 @@ void load_open_settings(settings_r *sesskey, Conf *conf)
|
||||
gpps(sesskey, "HyperlinkRegularExpression", urlhack_default_regex, conf, CONF_url_regex);
|
||||
#endif
|
||||
#endif
|
||||
#ifdef MOD_CYGTERM
|
||||
gppi(sesskey, "CygtermAltMetabit", 0, conf, CONF_alt_metabit);
|
||||
gppi(sesskey, "CygtermAutoPath", 1, conf, CONF_cygautopath );
|
||||
gppi(sesskey, "Cygterm64", 0, conf, CONF_cygterm64);
|
||||
gpps(sesskey, "CygtermCommand", "", conf, CONF_cygcmd );
|
||||
#endif
|
||||
#ifdef MOD_ZMODEM
|
||||
gppfile(sesskey, "rzCommand", conf, CONF_rzcommand );
|
||||
gpps(sesskey, "rzOptions", "-e -v", conf, CONF_rzoptions );
|
||||
|
||||
@@ -127,7 +127,7 @@ CFLAGS += -D_WIN32_IE=0x0500
|
||||
################################################################################
|
||||
CFLAGS += -DWINVER=0x0501 -D_WIN32_WINDOWS=0x0410 -D_WIN32_WINNT=0x0501
|
||||
|
||||
# -DMOD_PERSO -DMOD_CYGTERM -DMOD_BACKGROUNDIMAGE -DMOD_RECONNECT -DMOD_HYPERLINK -DMOD_ZMODEM -DMOD_STARTBUTTON -DMOD_LAUNCHER -DMOD_SAVEDUMP -DMOD_KEYMAPPING -DMOD_WINCRYPT -DMOD_TUTTY -DMOD_PORTKNOCKING -DMOD_PUTTYX -DMOD_WTS -DMOD_PRINTCLIP -DMOD_RUTTY -DMOD_ADB \
|
||||
# -DMOD_PERSO -DMOD_BACKGROUNDIMAGE -DMOD_RECONNECT -DMOD_HYPERLINK -DMOD_ZMODEM -DMOD_STARTBUTTON -DMOD_LAUNCHER -DMOD_SAVEDUMP -DMOD_KEYMAPPING -DMOD_WINCRYPT -DMOD_TUTTY -DMOD_PORTKNOCKING -DMOD_PUTTYX -DMOD_WTS -DMOD_PRINTCLIP -DMOD_RUTTY -DMOD_ADB \
|
||||
|
||||
|
||||
# Flag special FDJ
|
||||
@@ -166,7 +166,6 @@ CFLAGS += -D__WINE__ \
|
||||
-I../../bcrypt \
|
||||
-I../../md5 -I../../regex -I../../url -I../../wincrypt -I../../rutty
|
||||
|
||||
# -DMOD_CYGTERM \
|
||||
# -DHAS_WINX509 -DMOD_WINCRYPT \
|
||||
# -DMOD_ZMODEM \
|
||||
|
||||
@@ -181,7 +180,7 @@ CFLAGS += -D__WINE__ \
|
||||
# MOD_INTEGRATED_KEYGEN: intègre le key generator directement
|
||||
|
||||
CFLAGS_PLINK = -Wall -O2 -D_WINDOWS -DWIN32S_COMPAT \
|
||||
-DMOD_PERSO -DPUTTYCYG -DMOD_RECONNECT -DNO_MOD_RUTTY \
|
||||
-DMOD_PERSO -DMOD_RECONNECT -DNO_MOD_RUTTY \
|
||||
-D_NO_OLDNAMES -DNO_MULTIMON -DNO_HTMLHELP -I../. \
|
||||
-I../charset -I../windows -I../unix -I../mac -I.\
|
||||
-I../macosx \
|
||||
@@ -381,7 +380,7 @@ putty.exe: agentf.o aqsync.o be_all_s.o be_misc.o callback.o cmdline.o \
|
||||
winmiscs.o winnet.o winnoise.o winnpc.o winnps.o winpgntc.o \
|
||||
winprint.o winproxy.o winsecur.o winser.o winshare.o \
|
||||
winstore.o wintime.o winucs.o winutils.o winx11.o x11fwd.o \
|
||||
adb.o cygcfg.o cygterm.o \
|
||||
adb.o \
|
||||
kitty.o kitty_commun.o kitty_crypt.o kitty_image.o kitty_registry.o kitty_ssh.o \
|
||||
kitty_store.o kitty_tools.o kitty_win.o \
|
||||
urlhack.o pageant_integrated.o wincrypto.o winpgnt_integrated.o winpgen_integrated.o winpzmodem.o \
|
||||
@@ -409,7 +408,7 @@ putty.exe: agentf.o aqsync.o be_all_s.o be_misc.o callback.o cmdline.o \
|
||||
winnps.o winpgntc.o winprint.o winproxy.o winsecur.o \
|
||||
winser.o winshare.o winstore.o wintime.o winucs.o winutils.o \
|
||||
winx11.o x11fwd.o \
|
||||
adb.o cygcfg.o cygterm.o \
|
||||
adb.o \
|
||||
kitty.o kitty_commun.o kitty_crypt.o kitty_image.o kitty_registry.o kitty_ssh.o \
|
||||
kitty_store.o kitty_tools.o kitty_win.o \
|
||||
urlhack.o pageant_integrated.o wincrypto.o winpgnt_integrated.o winpgen_integrated.o winpzmodem.o \
|
||||
@@ -1806,12 +1805,6 @@ FORCE:
|
||||
################################################################################
|
||||
# BEGIN MOD_PERSO
|
||||
################################################################################
|
||||
cygcfg.o: ../../cygterm/cygcfg.c
|
||||
$(CC) $(COMPAT) $(XFLAGS) $(CFLAGS) -c ../../cygterm/cygcfg.c -I../../cygterm/ -I../../
|
||||
|
||||
cygterm.o: ../../cygterm/cygterm.c
|
||||
$(CC) $(COMPAT) $(XFLAGS) $(CFLAGS) -c ../../cygterm/cygterm.c -I../../cygterm -I../../
|
||||
|
||||
be_all_s_plink.o: ../be_all_s.c ../putty.h ../puttyps.h ../network.h ../misc.h \
|
||||
../windows/winstuff.h \
|
||||
../unix/unix.h ../puttymem.h ../tree234.h \
|
||||
@@ -2087,7 +2080,7 @@ putty_portable.exe: agentf.o aqsync.o be_all_s.o be_misc.o callback.o cmdline.o
|
||||
winmiscs.o winnet.o winnoise.o winnpc.o winnps.o winpgntc.o \
|
||||
winprint.o winproxy.o winsecur.o winser.o winshare.o \
|
||||
winstore.o wintime.o winucs.o winutils.o winx11.o x11fwd.o \
|
||||
adb.o cygcfg.o cygterm.o \
|
||||
adb.o \
|
||||
kitty_portable.o kitty_commun_portable.o kitty_crypt.o kitty_image.o kitty_registry.o kitty_ssh.o \
|
||||
kitty_store.o kitty_tools.o kitty_win.o \
|
||||
urlhack.o pageant_integrated.o winpgnt_integrated.o winpgen_integrated.o winpzmodem.o \
|
||||
@@ -2117,7 +2110,7 @@ putty_portable.exe: agentf.o aqsync.o be_all_s.o be_misc.o callback.o cmdline.o
|
||||
winnps.o winpgntc.o winprint.o winproxy.o winsecur.o \
|
||||
winser.o winshare.o winstore.o wintime.o winucs.o winutils.o \
|
||||
winx11.o x11fwd.o \
|
||||
adb.o cygcfg.o cygterm.o \
|
||||
adb.o \
|
||||
kitty_portable.o kitty_commun_portable.o kitty_crypt.o kitty_image.o kitty_registry.o kitty_ssh.o \
|
||||
kitty_store.o kitty_tools.o kitty_win.o \
|
||||
urlhack.o pageant_integrated.o winpgnt_integrated.o winpgen_integrated.o winpzmodem.o \
|
||||
|
||||
@@ -219,12 +219,6 @@ void win_setup_config_box(struct controlbox *b, HWND *hwndp, bool has_help,
|
||||
ctrl_checkbox(s, "Control-Alt is different from AltGr", 'd',
|
||||
HELPCTX(keyboard_ctrlalt),
|
||||
conf_checkbox_handler, I(CONF_ctrlaltkeys));
|
||||
#ifdef MOD_CYGTERM
|
||||
if( cygterm_get_flag() )
|
||||
ctrl_checkbox(s, "Set meta bit on alt (instead of escape)", NO_SHORTCUT,
|
||||
HELPCTX(no_help),
|
||||
conf_checkbox_handler, I(CONF_alt_metabit));
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Windows allows an arbitrary .WAV to be played as a bell, and
|
||||
@@ -610,14 +604,6 @@ void win_setup_config_box(struct controlbox *b, HWND *hwndp, bool has_help,
|
||||
HELPCTX(ssh_tunnels_xauthority),
|
||||
conf_filesel_handler, I(CONF_xauthfile));
|
||||
}
|
||||
#ifdef MOD_CYGTERM
|
||||
/*
|
||||
* cygterm back end is available on Windows.
|
||||
*/
|
||||
if( cygterm_get_flag() )
|
||||
if (!midsession || (protocol == PROT_CYGTERM))
|
||||
cygterm_setup_config_box(b, midsession);
|
||||
#endif
|
||||
#ifdef MOD_PERSO
|
||||
if( !GetPuttyFlag() && 0 ) {
|
||||
|
||||
|
||||
@@ -637,20 +637,6 @@ static void close_session(void *ignored_context)
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef MOD_CYGTERM
|
||||
/* Copy at most n characters from src to dst or until copying a '\0'
|
||||
* character. A pointer to the terminal '\0' in dst is returned, or if no
|
||||
* '\0' was written, dst+n is returned. */
|
||||
static char *
|
||||
stpcpy_max(char *dst, const char *src, size_t n)
|
||||
{
|
||||
while (n-- && (*dst = *src++))
|
||||
dst++;
|
||||
return dst;
|
||||
}
|
||||
bool get_got_host(void) ;
|
||||
void set_got_host(bool val ) ;
|
||||
#endif
|
||||
#ifdef MOD_RECONNECT
|
||||
void RestartSession( void ) {
|
||||
win_seat_connection_fatal( win_seat, "User request session restart..." ) ;
|
||||
@@ -854,13 +840,6 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
|
||||
conf_set_str( conf, CONF_password, bufpass ) ;
|
||||
memset( bufpass, 0, strlen(bufpass) ) ;
|
||||
memset( argv[i], 0, strlen(argv[i]) ) ;
|
||||
#endif
|
||||
#ifdef MOD_CYGTERM
|
||||
} else if( !strcmp(p, "-cc") ) {
|
||||
conf_set_str( conf, CONF_host, "cmd.exe /k" ) ;
|
||||
conf_set_int( conf, CONF_port, 0 ) ;
|
||||
conf_set_int( conf, CONF_protocol, PROT_CYGTERM ) ;
|
||||
special_launchable_argument = true ;
|
||||
#endif
|
||||
} else if( !strcmp(p, "-auto_store_sshkey") || !strcmp(p, "-auto-store-sshkey") ) {
|
||||
SetAutoStoreSSHKeyFlag( 1 ) ;
|
||||
@@ -950,12 +929,6 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
|
||||
} else if( !strcmp(p, "-notrans") ) {
|
||||
SetTransparencyFlag( 0 ) ;
|
||||
conf_set_int(conf,CONF_transparencynumber, -1) ;
|
||||
#ifdef MOD_CYGTERM
|
||||
} else if( !strcmp(p, "-cygterm") ) {
|
||||
cygterm_set_flag( 1 ) ;
|
||||
} else if( !strcmp(p, "-nocygterm") ) {
|
||||
cygterm_set_flag( 0 ) ;
|
||||
#endif
|
||||
#ifdef MOD_SAVEDUMP
|
||||
} else if( !strcmp(p, "-savedump") ) {
|
||||
SaveDump() ;
|
||||
@@ -1025,9 +998,6 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
|
||||
SetRuttyFlag( 0 ) ;
|
||||
SetDefaultSettingsFlag(1);
|
||||
SetReadOnlyFlag(0);
|
||||
#ifdef MOD_CYGTERM
|
||||
cygterm_set_flag( 0 ) ;
|
||||
#endif
|
||||
#if (defined MOD_BACKGROUNDIMAGE) && (!defined FDJ)
|
||||
SetBackgroundImageFlag(0) ;
|
||||
#endif
|
||||
@@ -1144,29 +1114,6 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
|
||||
pgp_fingerprints();
|
||||
exit(1);
|
||||
} else if (*p != '-') {
|
||||
#ifdef MOD_CYGTERM
|
||||
} else if ( conf_get_int(conf,CONF_protocol) == PROT_CYGTERM) {
|
||||
/* Concatenate all the remaining arguments separating
|
||||
* them with spaces to get the command line to execute.
|
||||
*/
|
||||
|
||||
char *p,*pst;
|
||||
pst=(char*)malloc(1000);
|
||||
p=pst;
|
||||
strcpy( p, conf_get_str(conf,CONF_cygcmd) );
|
||||
char *const end = p + 1000 ;
|
||||
|
||||
for (; i < argc && p < end; i++) {
|
||||
p = stpcpy_max(p, argv[i], end - p - 1);
|
||||
*p++ = ' ';
|
||||
}
|
||||
assert(p > pst && p <= end);
|
||||
*--p = '\0';
|
||||
set_got_host(true) ;
|
||||
|
||||
conf_set_str( conf, CONF_cygcmd, pst );
|
||||
free(pst);
|
||||
#endif
|
||||
cmdline_error("unexpected argument \"%s\"", p);
|
||||
} else {
|
||||
cmdline_error("unknown option \"%s\"", p);
|
||||
@@ -6698,11 +6645,7 @@ if( !get_param("PUTTY") && conf_get_int(conf, CONF_disablealtgr) ) {
|
||||
*p++ = 0;
|
||||
return -2;
|
||||
}
|
||||
#ifdef MOD_CYGTERM
|
||||
if (wParam == VK_BACK && shift_state != 0) { /* Shift-Backspace, Ctrl-Backspace */
|
||||
#else
|
||||
if (wParam == VK_BACK && shift_state == 1) { /* Shift Backspace */
|
||||
#endif
|
||||
/* We do the opposite of what is configured */
|
||||
*p++ = (conf_get_bool(conf, CONF_bksp_is_delete) ? 0x08 : 0x7F);
|
||||
*p++ = 0;
|
||||
@@ -6721,9 +6664,6 @@ if( !get_param("PUTTY") && conf_get_int(conf, CONF_disablealtgr) ) {
|
||||
}
|
||||
#endif
|
||||
if (wParam == VK_TAB && shift_state == 1) { /* Shift tab */
|
||||
#ifdef MOD_CYGTERM
|
||||
p = output; /* don't also pass escape */
|
||||
#endif
|
||||
*p++ = 0x1B;
|
||||
*p++ = '[';
|
||||
*p++ = 'Z';
|
||||
@@ -6734,16 +6674,7 @@ if( !get_param("PUTTY") && conf_get_int(conf, CONF_disablealtgr) ) {
|
||||
return p - output;
|
||||
}
|
||||
if (wParam == VK_SPACE && shift_state == 3) { /* Ctrl-Shift-Space */
|
||||
#ifdef MOD_CYGTERM
|
||||
p = output; /* don't also pass escape */
|
||||
*p++ = 160; /* Latin1 NBSP */
|
||||
return p - output;
|
||||
}
|
||||
if (wParam == '/' && shift_state == 2) { /* Ctrl-/ sends ^_ */
|
||||
*p++ = 037;
|
||||
#else
|
||||
*p++ = 160;
|
||||
#endif
|
||||
return p - output;
|
||||
}
|
||||
if (wParam == VK_CANCEL && shift_state == 2) { /* Ctrl-Break */
|
||||
@@ -6773,13 +6704,6 @@ if( !get_param("PUTTY") && conf_get_int(conf, CONF_disablealtgr) ) {
|
||||
*p++ = 0x1E; /* Ctrl-~ == Ctrl-^ in xterm at least */
|
||||
return p - output;
|
||||
}
|
||||
#ifdef MOD_CYGTERM
|
||||
if (wParam == VK_RETURN && shift_state != 0) { /* Shift-Return, Ctrl-Return */
|
||||
/* send LINEFEED */
|
||||
*p++ = 012;
|
||||
return p - output;
|
||||
}
|
||||
#endif
|
||||
|
||||
switch (wParam) {
|
||||
case VK_NUMPAD0: keypad_key = '0'; goto numeric_keypad;
|
||||
@@ -7035,13 +6959,8 @@ if( !get_param("PUTTY") && conf_get_int(conf, CONF_disablealtgr) ) {
|
||||
} else {
|
||||
WCHAR cbuf[2];
|
||||
cbuf[0] = '\033';
|
||||
#ifdef MOD_CYGTERM
|
||||
cbuf[1] = wch | ((left_alt & conf_get_int(conf,CONF_alt_metabit)) << 7);
|
||||
term_keyinputw(term, cbuf + !(left_alt & !conf_get_int(conf,CONF_alt_metabit)), 1 + !!(left_alt & !conf_get_int(conf,CONF_alt_metabit)) );
|
||||
#else
|
||||
cbuf[1] = wch;
|
||||
term_keyinputw(term, cbuf+!left_alt, 1+!!left_alt);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
show_mouseptr(false);
|
||||
@@ -7114,9 +7033,6 @@ void make_title( char * res, char * fmt, const char * title ) {
|
||||
case PROT_TELNET: strcpy(b,"telnet"); if(port==-1) port=23 ; break;
|
||||
case PROT_RLOGIN: strcpy(b,"rlogin"); break;
|
||||
case PROT_SSH: strcpy(b,"ssh"); if(port==-1) port=22 ; break;
|
||||
#ifdef MOD_CYGTERM
|
||||
case PROT_CYGTERM: strcpy(b,"cyg"); break;
|
||||
#endif
|
||||
case PROT_SERIAL: strcpy(b,"serial"); break;
|
||||
}
|
||||
while( (p=poss( "%%P", res)) > 0 ) { del(res,p,3); insert(res,b,p); }
|
||||
|
||||
@@ -195,11 +195,6 @@ DECL_WINDOWS_FUNCTION(static, int, WSAIoctl,
|
||||
(SOCKET, DWORD, LPVOID, DWORD, LPVOID, DWORD,
|
||||
LPDWORD, LPWSAOVERLAPPED,
|
||||
LPWSAOVERLAPPED_COMPLETION_ROUTINE));
|
||||
#ifdef MOD_CYGTERM
|
||||
DECL_WINDOWS_FUNCTION(static, int, getsockname,
|
||||
(SOCKET, const struct sockaddr FAR *, int FAR *));
|
||||
#endif
|
||||
|
||||
#ifndef NO_IPV6
|
||||
DECL_WINDOWS_FUNCTION(static, int, getaddrinfo,
|
||||
(const char *nodename, const char *servname,
|
||||
@@ -333,9 +328,6 @@ void sk_init(void)
|
||||
GET_WINDOWS_FUNCTION(winsock_module, getpeername);
|
||||
GET_WINDOWS_FUNCTION(winsock_module, recv);
|
||||
GET_WINDOWS_FUNCTION(winsock_module, WSAIoctl);
|
||||
#ifdef MOD_CYGTERM
|
||||
GET_WINDOWS_FUNCTION(winsock_module, getsockname);
|
||||
#endif
|
||||
|
||||
/* Try to get the best WinSock version we can get */
|
||||
if (!sk_startup(2,2) &&
|
||||
@@ -1443,26 +1435,6 @@ Socket *sk_newlistener(const char *srcaddr, int port, Plug *plug,
|
||||
return &ret->sock;
|
||||
}
|
||||
|
||||
#ifdef MOD_CYGTERM
|
||||
int sk_getport(Socket *sock)
|
||||
{
|
||||
/* I won't even try to get IPv6 working here since it is apparently borken
|
||||
* in this release of PuTTY */
|
||||
SOCKADDR_IN a;
|
||||
socklen_t salen;
|
||||
int retcode;
|
||||
NetSocket * s = container_of(sock, NetSocket, sock);
|
||||
|
||||
salen = sizeof(a);
|
||||
retcode = p_getsockname(s->s, (struct sockaddr *) &a, &salen);
|
||||
|
||||
if (retcode != 0)
|
||||
return -1;
|
||||
|
||||
return p_ntohs(a.sin_port);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef NO_MOD_ZMODEM /* A partir de 0.64.0.3 on prend le code normal */
|
||||
static void sk_tcp_really_close(Actual_Socket s)
|
||||
{
|
||||
|
||||
@@ -49,9 +49,6 @@ void SetUsernameInConfig( char * username ) {
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#ifdef MOD_CYGTERM
|
||||
void cygterm_set_flag( int flag ) { }
|
||||
#endif
|
||||
|
||||
#define WM_AGENT_CALLBACK (WM_APP + 4)
|
||||
|
||||
|
||||
@@ -48,9 +48,6 @@ void SetUsernameInConfig( char * username ) {
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#ifdef MOD_CYGTERM
|
||||
void cygterm_set_flag( int flag ) { }
|
||||
#endif
|
||||
|
||||
int filexfer_get_userpass_input(Seat *seat, prompts_t *p, bufchain *input)
|
||||
{
|
||||
|
||||
Binary file not shown.
+1
-1
@@ -51,7 +51,7 @@ void license_init( void ) {
|
||||
char buf[64], c ;
|
||||
int i ;
|
||||
time_t t = time(0) ;
|
||||
sprintf( buf, "%ld", t ) ;
|
||||
sprintf( buf, "%ld", (const long int)t ) ;
|
||||
for( i=0;i<(strlen(buf)/2);i++ ) { c=buf[i];buf[i]=buf[strlen(buf)-1-i];buf[strlen(buf)-1-i]=c;}
|
||||
srand( atol(buf) ) ;
|
||||
}
|
||||
|
||||
@@ -1,78 +0,0 @@
|
||||
/*
|
||||
-- putty-0.59/windows/cygcfg.c 1969-12-31 17:00:00.000000000 -0700
|
||||
++ putty-0.59-cygterm/windows/cygcfg.c 2007-02-06 16:16:15.000000000 -0700
|
||||
@ -0,0 +1,33 @@
|
||||
*/
|
||||
|
||||
#ifdef MOD_CYGTERM
|
||||
|
||||
#include "putty.h"
|
||||
#include "dialog.h"
|
||||
|
||||
static int CygTermFlag = 1 ;
|
||||
|
||||
void cygterm_set_flag( int flag ) {
|
||||
if( flag >= 1 ) CygTermFlag = 1 ;
|
||||
else CygTermFlag = 0 ;
|
||||
}
|
||||
|
||||
int cygterm_get_flag( void ) {
|
||||
return CygTermFlag ;
|
||||
}
|
||||
|
||||
extern void config_protocolbuttons_handler(union control *, dlgparam *, void *, int);
|
||||
|
||||
static int is64Bits() {
|
||||
return (NULL != GetProcAddress(GetModuleHandle("kernel32"), "IsWow64Process")) ? 1 : 0;
|
||||
}
|
||||
|
||||
void cygterm_setup_config_box(struct controlbox *b, int midsession)
|
||||
{
|
||||
union control *c;
|
||||
int i;
|
||||
|
||||
if( !CygTermFlag ) return ;
|
||||
|
||||
struct controlset *s;
|
||||
s = ctrl_getset(b, "Session", "hostport",
|
||||
"Specify the destination you want to connect to");
|
||||
for (i = 0; i < s->ncontrols; i++) {
|
||||
c = s->ctrls[i];
|
||||
if (c->generic.type == CTRL_RADIO &&
|
||||
c->generic.handler == config_protocolbuttons_handler) {
|
||||
c->radio.nbuttons++;
|
||||
/* c->radio.ncolumns++; */
|
||||
c->radio.buttons =
|
||||
sresize(c->radio.buttons, c->radio.nbuttons, char *);
|
||||
c->radio.buttons[c->radio.nbuttons-1] = dupstr("Cygterm");
|
||||
c->radio.buttondata =
|
||||
sresize(c->radio.buttondata, c->radio.nbuttons, intorptr);
|
||||
c->radio.buttondata[c->radio.nbuttons-1] = I(PROT_CYGTERM);
|
||||
if (c->radio.shortcuts) {
|
||||
c->radio.shortcuts =
|
||||
sresize(c->radio.shortcuts, c->radio.nbuttons, char);
|
||||
c->radio.shortcuts[c->radio.nbuttons-1] = NO_SHORTCUT;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!midsession) {
|
||||
ctrl_settitle(b, "Connection/Cygterm",
|
||||
"Options controlling Cygterm sessions");
|
||||
s = ctrl_getset(b, "Connection/Cygterm", "cygterm",
|
||||
"Configure Cygwin paths");
|
||||
ctrl_checkbox(s, "Autodetect Cygwin installation", 'd',
|
||||
HELPCTX(no_help),
|
||||
conf_checkbox_handler/*dlg_stdcheckbox_handler*/,
|
||||
I(CONF_cygautopath)
|
||||
);
|
||||
if( is64Bits() )
|
||||
{
|
||||
ctrl_checkbox(s, "Use Cygwin64", 'u',
|
||||
HELPCTX(no_help),
|
||||
conf_checkbox_handler,
|
||||
I(CONF_cygterm64));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,663 +0,0 @@
|
||||
#ifdef MOD_CYGTERM
|
||||
|
||||
#include <stdio.h> /* sprintf */
|
||||
#include <string.h>
|
||||
#include <limits.h> /* INT_MAX */
|
||||
#include "putty.h"
|
||||
#include "cthelper/cthelper.h"
|
||||
#include "cthelper/message.h"
|
||||
|
||||
void SearchCtHelper( void ) ;
|
||||
|
||||
#define CYGTERM_MAX_BACKLOG 16384
|
||||
|
||||
#define CYGTERM_NAME "Cygterm"
|
||||
|
||||
#ifdef __INTERIX
|
||||
#define CTHELPER "posix.exe /u /c cthelper.exe"
|
||||
#define CTHELPER64 "posix.exe /u /c cthelper64.exe"
|
||||
#else
|
||||
#define CTHELPER "cthelper"
|
||||
#define CTHELPER64 "cthelper64"
|
||||
#endif
|
||||
|
||||
#if !defined(DEBUG)
|
||||
#define cygterm_debug(f,...)
|
||||
#elif !defined(cygterm_debug)
|
||||
#define cygterm_debug(f,...) debug(("\n%s:%d:%s: "f"\n",__FILE__,__LINE__,__FUNCTION__,##__VA_ARGS__))
|
||||
#endif
|
||||
|
||||
#define putenv _putenv
|
||||
|
||||
size_t win_seat_output_local(Seat *seat, bool is_stderr, const void *data, size_t len) ;
|
||||
|
||||
typedef struct cygterm_backend_data {
|
||||
//const struct plug_function_table *fn;
|
||||
|
||||
Socket *a;
|
||||
Socket *s;
|
||||
Seat *seat;
|
||||
LogContext *logctx;
|
||||
//void *frontend;
|
||||
|
||||
PROCESS_INFORMATION pi;
|
||||
HANDLE ctl;
|
||||
Conf * conf;
|
||||
|
||||
Plug plug;
|
||||
Backend backend;
|
||||
int bufsize;
|
||||
int editing, echoing;
|
||||
int exitcode;
|
||||
} Local;
|
||||
|
||||
/* Plug functions for cthelper data connection */
|
||||
static void cygterm_log(Plug *p, int type, SockAddr *addr, int port, const char *error_msg, int error_code)
|
||||
{
|
||||
/* Do nothing */
|
||||
}
|
||||
|
||||
/*
|
||||
static void c_write(Local *local, const char *buf, int len)
|
||||
{
|
||||
//int backlog = from_backend(local->frontend, 0, buf, len);
|
||||
int backlog = win_seat_output_local(local->seat,false,buf,len);
|
||||
sk_set_frozen(local->s, backlog > CYGTERM_MAX_BACKLOG);
|
||||
}
|
||||
*/
|
||||
static int cygterm_closing(Plug *plug, const char *error_msg, int error_code, bool calling_back)
|
||||
{
|
||||
//Local local = (Local)plug;
|
||||
Local *local = container_of(plug, Local, plug) ;
|
||||
|
||||
cygterm_debug("top");
|
||||
if (local->s) {
|
||||
sk_close(local->s);
|
||||
local->s = NULL;
|
||||
}
|
||||
/* check for errors from cthelper */
|
||||
CloseHandle(local->ctl);
|
||||
/* wait for cthelper */
|
||||
if (local->pi.hProcess != INVALID_HANDLE_VALUE) {
|
||||
if (WAIT_OBJECT_0 == WaitForSingleObject(local->pi.hProcess, 2000)) {
|
||||
DWORD status;
|
||||
GetExitCodeProcess(local->pi.hProcess, &status);
|
||||
switch (status) {
|
||||
case CthelperSuccess:
|
||||
break;
|
||||
case CthelperInvalidUsage:
|
||||
case CthelperInvalidPort:
|
||||
case CthelperConnectFailed:
|
||||
local->exitcode = INT_MAX;
|
||||
error_msg = "Internal error";
|
||||
break;
|
||||
case CthelperPtyforkFailure:
|
||||
local->exitcode = INT_MAX;
|
||||
error_msg = "Failed to allocate pseudoterminal";
|
||||
break;
|
||||
case CthelperExecFailure:
|
||||
local->exitcode = INT_MAX;
|
||||
error_msg = "Failed to execute command";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* this calls cygterm_exitcode() */
|
||||
//notify_remote_exit(local->frontend);
|
||||
seat_notify_remote_exit(local->seat);
|
||||
if (error_msg) {
|
||||
cygterm_debug("error_msg: %s", error_msg);
|
||||
//connection_fatal(local->frontend, "%s", error_msg);
|
||||
seat_connection_fatal(local->seat, "%s", error_msg);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cygterm_receive(Plug * plug, int urgent, const char *data, size_t len)
|
||||
{
|
||||
//Local local = (Local)plug;
|
||||
Local *local = container_of(plug,Local,plug);
|
||||
|
||||
int backlog;
|
||||
cygterm_debug("backend -> display %u", len);
|
||||
// dmemdump(data, len);
|
||||
//backlog = from_backend(local->frontend, 0, data, len);
|
||||
backlog = win_seat_output_local(local->seat,false,data,len);
|
||||
// dmemdumpl(data, len);
|
||||
sk_set_frozen(local->s, backlog > CYGTERM_MAX_BACKLOG);
|
||||
cygterm_debug("OK");
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void cygterm_sent(Plug * plug, size_t bufsize)
|
||||
{
|
||||
//Local local = (Local)plug;
|
||||
Local *local = container_of(plug,Local,plug);
|
||||
local->bufsize = bufsize;
|
||||
}
|
||||
|
||||
static void
|
||||
cygterm_size(void *handle, int width, int height);
|
||||
|
||||
|
||||
Socket sk_tcp_accept(accept_ctx_t ctx, Plug plug);
|
||||
static int
|
||||
cygterm_accepting(Plug * plug, accept_fn_t constructor, accept_ctx_t ctx)
|
||||
{
|
||||
//Local local = (Local)plug;
|
||||
Local *local = container_of(plug,Local,plug);
|
||||
cygterm_debug("top");
|
||||
local->s = constructor(ctx, plug);
|
||||
sk_set_frozen(local->s, 0);
|
||||
// Reset terminal size
|
||||
cygterm_size(local, conf_get_int(local->conf,CONF_width), conf_get_int(local->conf,CONF_height));
|
||||
cygterm_debug("OK");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static char *getCygwinBin(int use64);
|
||||
void appendPath(const char *append);
|
||||
static size_t makeAttributes(char *buf, Conf *conf);
|
||||
static const char *spawnChild(char *cmd, Conf *conf, LPPROCESS_INFORMATION ppi, PHANDLE pin);
|
||||
|
||||
/* Backend functions for the cygterm backend */
|
||||
void RunCommand( HWND hwnd, char * cmd ) ;
|
||||
|
||||
|
||||
static const struct PlugVtable Cygterm_plugvt = {
|
||||
cygterm_log,
|
||||
cygterm_closing,
|
||||
cygterm_receive,
|
||||
cygterm_sent,
|
||||
};
|
||||
|
||||
/*
|
||||
static const char * cygterm_init(void *frontend_handle, void **backend_handle,
|
||||
Conf *conf,
|
||||
const char *unused_host, int unused_port,
|
||||
char **realhost, int nodelay, int keepalive)
|
||||
*/
|
||||
static const char * cygterm_init(Seat *seat, Backend **backend_handle,
|
||||
LogContext *logctx,
|
||||
Conf *conf,
|
||||
const char *unused_host, int unused_port,
|
||||
char **realhost, int nodelay, int keepalive)
|
||||
{
|
||||
/* XXX: I'm not sure if it is OK to overload Plug like this.
|
||||
* cygterm_accepting should only be used for the listening socket
|
||||
* (local->a) while the cygterm_closing, cygterm_receive, and cygterm_sent
|
||||
* should be used only for the actual connection (local->s).
|
||||
*/
|
||||
|
||||
Local *local;
|
||||
const char *command;
|
||||
char cmdline[2 * MAX_PATH];
|
||||
int cport;
|
||||
const char *err;
|
||||
int cmdlinelen;
|
||||
|
||||
cygterm_debug("top");
|
||||
|
||||
local = snew(Local);
|
||||
//local->fn = &fn_table;
|
||||
local->plug.vt = &Cygterm_plugvt;
|
||||
local->backend.vt = &cygterm_backend;
|
||||
local->a = NULL;
|
||||
local->s = NULL;
|
||||
local->conf = conf_copy(conf);
|
||||
local->editing = 0;
|
||||
local->echoing = 0;
|
||||
local->exitcode = 0;
|
||||
*backend_handle = &local->backend;
|
||||
|
||||
local->seat = seat;
|
||||
local->logctx = logctx;
|
||||
|
||||
//local->frontend = frontend_handle;
|
||||
|
||||
/* set up listen socket for communication with child */
|
||||
cygterm_debug("setupCygTerm");
|
||||
|
||||
/* let sk use INADDR_LOOPBACK and let WinSock choose a port */
|
||||
//local->a = sk_newlistener(0, 0, (Plug)local, 1, ADDRTYPE_IPV4);
|
||||
local->a = sk_newlistener(0, 0, (Plug*)&local->plug, 1, ADDRTYPE_IPV4); // local-> ou seat ou local tout court
|
||||
|
||||
if ((err = sk_socket_error(local->a)) != NULL)
|
||||
goto fail_free;
|
||||
|
||||
/* now, get the port that WinSock chose */
|
||||
/* XXX: Is there another function in PuTTY to do this? */
|
||||
cygterm_debug("getting port");
|
||||
cport = sk_getport(local->a);
|
||||
if (cport == -1) {
|
||||
err = "Failed to get port number for cthelper";
|
||||
goto fail_close;
|
||||
}
|
||||
|
||||
if (strchr(conf_get_str(local->conf,CONF_termtype), ' ')) {
|
||||
err = "term type contains spaces";
|
||||
goto fail_close;
|
||||
}
|
||||
|
||||
/* Build cthelper command line */
|
||||
char * CTHELPER_PATH = getenv( "CTHELPER_PATH" ) ;
|
||||
if( CTHELPER_PATH==NULL ) { SearchCtHelper() ; CTHELPER_PATH = getenv( "CTHELPER_PATH" ) ; }
|
||||
if( CTHELPER_PATH!=NULL ) cmdlinelen = sprintf(cmdline, "\"%s\" %u %s ", CTHELPER_PATH, cport, conf_get_str(local->conf,CONF_termtype));
|
||||
else {
|
||||
//cmdlinelen = sprintf(cmdline, CTHELPER" %u %s ", cport,conf_get_str(local->conf,CONF_termtype));
|
||||
if(conf_get_int(conf, CONF_cygterm64)) {
|
||||
cmdlinelen = sprintf(cmdline, CTHELPER64" %u %s ", cport, conf_get_str(local->conf, CONF_termtype));
|
||||
}
|
||||
else {
|
||||
cmdlinelen = sprintf(cmdline, CTHELPER" %u %s ", cport, conf_get_str(local->conf, CONF_termtype));
|
||||
}
|
||||
}
|
||||
cmdlinelen += makeAttributes(cmdline + cmdlinelen, local->conf);
|
||||
|
||||
command = conf_get_str(conf,CONF_cygcmd);
|
||||
|
||||
if( command[0]=='?' ) {
|
||||
RunCommand(NULL,(char*)(command+1));
|
||||
exit(0);
|
||||
}
|
||||
else {
|
||||
cygterm_debug("command is :%s:", command);
|
||||
/* A command of "." or "-" tells us to pass no command arguments to
|
||||
* cthelper which will then run the user's shell under Cygwin. */
|
||||
if ((command[0]=='-'||command[0]=='.') && command[1]=='\0')
|
||||
;
|
||||
else if (cmdlinelen + strlen(command) + 2 > sizeof cmdline) {
|
||||
err = "command is too long";
|
||||
goto fail_close;
|
||||
}
|
||||
else {
|
||||
cmdlinelen += sprintf(cmdline + cmdlinelen, " %s", command);
|
||||
}
|
||||
|
||||
/* Add the Cygwin /bin path to the PATH. */
|
||||
if (conf_get_int(conf,CONF_cygautopath)) {
|
||||
char *cygwinBinPath = getCygwinBin(conf_get_int(conf, CONF_cygterm64));
|
||||
if (!cygwinBinPath) {
|
||||
/* we'll try anyway */
|
||||
cygterm_debug("cygwin bin directory not found");
|
||||
}
|
||||
else {
|
||||
cygterm_debug("found cygwin directory: %s", cygwinBinPath);
|
||||
appendPath(cygwinBinPath);
|
||||
sfree(cygwinBinPath);
|
||||
}
|
||||
}
|
||||
|
||||
cygterm_debug("starting cthelper: %s", cmdline);
|
||||
{ char buffer[1024] ; sprintf( buffer,"starting cthelper: %s", cmdline ) ; logevent( NULL,buffer ) ; }
|
||||
if ((err = spawnChild(cmdline, conf, &local->pi, &local->ctl)))
|
||||
goto fail_close;
|
||||
|
||||
/* This should be set to the local hostname, Apparently, realhost is used
|
||||
* only to set the window title.
|
||||
*/
|
||||
strcpy(*realhost = smalloc(sizeof CYGTERM_NAME), CYGTERM_NAME);
|
||||
cygterm_debug("OK");
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
fail_close:
|
||||
sk_close(local->a);
|
||||
fail_free:
|
||||
sfree(local);
|
||||
return err;
|
||||
}
|
||||
|
||||
static void
|
||||
cygterm_free(void *handle)
|
||||
{
|
||||
//Local local = handle;
|
||||
Local *local = container_of(handle, Local, backend);
|
||||
cygterm_debug("top");
|
||||
sfree(local);
|
||||
}
|
||||
|
||||
static void
|
||||
cygterm_reconfig(void *handle, Conf *conf)
|
||||
{
|
||||
//Local local = handle;
|
||||
Local *local = container_of(handle, Local, backend);
|
||||
cygterm_debug("top");
|
||||
local->conf = conf;
|
||||
}
|
||||
|
||||
static int
|
||||
cygterm_send(void *handle, const char *buf, int len)
|
||||
{
|
||||
//Local local = handle;
|
||||
Local *local = container_of(handle, Local, backend);
|
||||
cygterm_debug("frontend -> pty %u", len);
|
||||
// dmemdump(buf, len);
|
||||
#if 0
|
||||
/* HACK */
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < len - 1; i++)
|
||||
if (buf[i] == 033 && !(buf[i+1]&0x80)) {
|
||||
memmove(buf + i, buf + i + 1, --len - i);
|
||||
buf[i] |= 0x80;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if (local->s != 0)
|
||||
local->bufsize = sk_write(local->s, buf, len);
|
||||
cygterm_debug("OK");
|
||||
return local->bufsize;
|
||||
}
|
||||
|
||||
static int
|
||||
cygterm_sendbuffer(void *handle)
|
||||
{
|
||||
//Local local = handle;
|
||||
Local *local = container_of(handle, Local, backend);
|
||||
cygterm_debug("top");
|
||||
return local->bufsize;
|
||||
}
|
||||
|
||||
static void
|
||||
cygterm_size(void *handle, int width, int height)
|
||||
{
|
||||
//Local local = handle;
|
||||
Local *local = container_of(handle, Local, backend);
|
||||
cygterm_debug("top");
|
||||
cygterm_debug("size=%d,%d (last=%d,%d)",
|
||||
width, height, conf_get_int(local->conf,CONF_width), conf_get_int(local->conf,CONF_height));
|
||||
conf_set_int(local->conf,CONF_width,width);
|
||||
conf_set_int(local->conf,CONF_height,height);
|
||||
if (local->s) {
|
||||
DWORD n;
|
||||
Message m;
|
||||
m.size = MESSAGE_MIN + sizeof(m.msg);
|
||||
m.type = MSG_RESIZE;
|
||||
m.msg.resize.width = width;
|
||||
m.msg.resize.height = height;
|
||||
cygterm_debug("WriteFile %p %p:%u", local->ctl, &m, m.size);
|
||||
WriteFile(local->ctl, (const char *)&m, m.size, &n, 0);
|
||||
cygterm_debug("WriteFile returns %d");
|
||||
}
|
||||
}
|
||||
|
||||
//static void cygterm_special(void *handle, Telnet_Special code)
|
||||
static void cygterm_special(void *handle, SessionSpecialCode code)
|
||||
{
|
||||
cygterm_debug("top");
|
||||
}
|
||||
|
||||
static const struct telnet_special * cygterm_get_specials(void *handle)
|
||||
{
|
||||
cygterm_debug("top");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int
|
||||
cygterm_connected(void *handle)
|
||||
{
|
||||
//Local local = handle;
|
||||
Local *local = container_of(handle, Local, backend);
|
||||
cygterm_debug("top");
|
||||
return local->s != NULL;
|
||||
}
|
||||
|
||||
static int
|
||||
cygterm_exitcode(void *handle)
|
||||
{
|
||||
//Local local = handle;
|
||||
Local *local = container_of(handle, Local, backend);
|
||||
cygterm_debug("top");
|
||||
return local->exitcode;
|
||||
}
|
||||
|
||||
static int
|
||||
cygterm_sendok(void *handle)
|
||||
{
|
||||
cygterm_debug("top");
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void
|
||||
cygterm_unthrottle(void *handle, int backlog)
|
||||
{
|
||||
//Local local = handle;
|
||||
Local *local = container_of(handle, Local, backend);
|
||||
cygterm_debug("top");
|
||||
sk_set_frozen(local->s, backlog > CYGTERM_MAX_BACKLOG);
|
||||
}
|
||||
|
||||
static int
|
||||
cygterm_ldisc(void *handle, int option)
|
||||
{
|
||||
//Local local = handle;
|
||||
Local *local = container_of(handle, Local, backend);
|
||||
cygterm_debug("cygterm_ldisc: %d", option);
|
||||
switch (option) {
|
||||
case LD_EDIT:
|
||||
return local->editing;
|
||||
case LD_ECHO:
|
||||
return local->echoing;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
cygterm_provide_ldisc(void *handle, void *ldisc)
|
||||
{
|
||||
cygterm_debug("top");
|
||||
}
|
||||
|
||||
static void
|
||||
cygterm_provide_logctx(void *handle, void *logctx)
|
||||
{
|
||||
cygterm_debug("top");
|
||||
}
|
||||
|
||||
static int
|
||||
cygterm_cfg_info(void *handle)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
const struct BackendVtable cygterm_backend = {
|
||||
cygterm_init,
|
||||
cygterm_free,
|
||||
cygterm_reconfig,
|
||||
cygterm_send,
|
||||
cygterm_sendbuffer,
|
||||
cygterm_size,
|
||||
cygterm_special,
|
||||
cygterm_get_specials,
|
||||
cygterm_connected,
|
||||
cygterm_exitcode,
|
||||
cygterm_sendok,
|
||||
cygterm_ldisc,
|
||||
cygterm_provide_logctx,
|
||||
cygterm_unthrottle,
|
||||
cygterm_cfg_info,
|
||||
NULL /* test_for_upstream */,
|
||||
"cygterm",
|
||||
PROT_CYGTERM,
|
||||
1
|
||||
};
|
||||
|
||||
/* like strcpy(), but return pointer to terminating null character */
|
||||
static char *
|
||||
strecpy(char *d,const char *s)
|
||||
{
|
||||
while ((*d = *s++))
|
||||
d++;
|
||||
return d;
|
||||
}
|
||||
|
||||
/* Make cthelper attribute string from PuTTY Config */
|
||||
static size_t
|
||||
makeAttributes(char *buf, Conf *conf)
|
||||
{
|
||||
char *e = buf;
|
||||
|
||||
if (conf_get_bool(conf,CONF_bksp_is_delete))
|
||||
e = strecpy(e, ":erase=^?");
|
||||
else
|
||||
e = strecpy(e, ":erase=^H");
|
||||
|
||||
e += sprintf(e, ":size=%d,%d", conf_get_int(conf,CONF_height), conf_get_int(conf,CONF_width));
|
||||
|
||||
/* TODO: other options? localedit? localecho? */
|
||||
|
||||
return e - buf;
|
||||
}
|
||||
|
||||
#ifndef KEY_WOW64_64KEY
|
||||
#define KEY_WOW64_64KEY 0x0100
|
||||
#endif
|
||||
#ifndef KEY_WOW64_32KEY
|
||||
#define KEY_WOW64_32KEY 0x0200
|
||||
#endif
|
||||
|
||||
/* Utility functions for spawning cthelper process */
|
||||
static BOOL
|
||||
getRegistry(char *valueData, LPDWORD psize, HKEY key, const char *subKey, const char *valueName, int use64)
|
||||
{
|
||||
HKEY k;
|
||||
LONG ret;
|
||||
|
||||
if (ERROR_SUCCESS != (ret = RegOpenKeyEx(key, subKey, 0, KEY_READ | (use64 ? KEY_WOW64_64KEY : KEY_WOW64_32KEY), &k )))
|
||||
return ret;
|
||||
|
||||
ERROR_SUCCESS == (ret = RegQueryInfoKey(k, 0, 0, 0, 0, 0, 0, 0, 0, psize, 0, 0))
|
||||
&& ERROR_SUCCESS == (ret = RegQueryValueEx(k, valueName, 0, 0, (LPBYTE)valueData, psize)) ;
|
||||
|
||||
RegCloseKey(k);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Cygwin 1.5 definition */
|
||||
#define CYGWIN_SYS_ROOT_MOUNT \
|
||||
HKEY_LOCAL_MACHINE,\
|
||||
"Software\\Cygnus Solutions\\Cygwin\\mounts v2\\/",\
|
||||
"native"
|
||||
#define CYGWIN_USER_ROOT_MOUNT \
|
||||
HKEY_CURRENT_USER,\
|
||||
"Software\\Cygnus Solutions\\Cygwin\\mounts v2\\/",\
|
||||
"native"
|
||||
|
||||
/* As of Cygwin 1.7, one of these keys contains the Cygwin install root. */
|
||||
#define CYGWIN_U_SETUP_ROOTDIR \
|
||||
HKEY_CURRENT_USER,\
|
||||
"Software\\Cygwin\\setup",\
|
||||
"rootdir"
|
||||
#define CYGWIN_S_SETUP_ROOTDIR \
|
||||
HKEY_LOCAL_MACHINE,\
|
||||
"Software\\Cygwin\\setup",\
|
||||
"rootdir"
|
||||
|
||||
static char *
|
||||
getCygwinBin(int use64)
|
||||
{
|
||||
char *dir;
|
||||
DWORD size = MAX_PATH;
|
||||
|
||||
dir = smalloc(size);
|
||||
dir[0] = '\0';
|
||||
|
||||
if (ERROR_SUCCESS == getRegistry(dir, &size, CYGWIN_U_SETUP_ROOTDIR, use64) || ERROR_SUCCESS == getRegistry(dir, &size, CYGWIN_S_SETUP_ROOTDIR, use64))
|
||||
{
|
||||
strcat(dir, "\\bin");
|
||||
}
|
||||
else if (ERROR_SUCCESS == getRegistry(dir, &size, CYGWIN_SYS_ROOT_MOUNT, use64) || ERROR_SUCCESS == getRegistry(dir, &size, CYGWIN_USER_ROOT_MOUNT, use64))
|
||||
{
|
||||
strcat(dir, "\\bin");
|
||||
}
|
||||
else
|
||||
{
|
||||
sfree(dir);
|
||||
dir = 0;
|
||||
}
|
||||
|
||||
return dir;
|
||||
}
|
||||
|
||||
void
|
||||
appendPath(const char *append)
|
||||
{
|
||||
char *path;
|
||||
char *newPath;
|
||||
|
||||
cygterm_debug("getting PATH");
|
||||
if (!(path = getenv("PATH"))) {
|
||||
cygterm_debug("hmm.. PATH not set");
|
||||
path = "";
|
||||
}
|
||||
cygterm_debug("alloc newPath");
|
||||
newPath = smalloc(5 + strlen(append) + 1 + strlen(path) + 1);
|
||||
cygterm_debug("init newPath");
|
||||
sprintf(newPath, "PATH=%s;%s", path, append);
|
||||
cygterm_debug("set newPath");
|
||||
putenv(newPath);
|
||||
cygterm_debug("free newPath");
|
||||
sfree(newPath);
|
||||
}
|
||||
|
||||
static const char *
|
||||
spawnChild(char *cmd, Conf *conf, LPPROCESS_INFORMATION ppi, PHANDLE pin)
|
||||
{
|
||||
STARTUPINFO si = {sizeof(si)};
|
||||
SECURITY_ATTRIBUTES sa = {sizeof(sa)};
|
||||
HANDLE in;
|
||||
|
||||
/* Create an anonymous pipe over which to send events such as resize */
|
||||
sa.lpSecurityDescriptor = NULL;
|
||||
sa.bInheritHandle = TRUE;
|
||||
if (!CreatePipe(&in, pin, &sa, 1))
|
||||
return "failed to create event pipe";
|
||||
|
||||
/* cthelper will use stdin to get event messages */
|
||||
si.dwFlags = STARTF_USESTDHANDLES|STARTF_USESHOWWINDOW;
|
||||
si.hStdInput = in;
|
||||
si.wShowWindow = SW_HIDE;
|
||||
|
||||
/* Add the Cygwin /bin path to the PATH env var. */
|
||||
if (!getenv("NOCYGWIN")) {
|
||||
char *cygwinBinPath = getCygwinBin(conf_get_int(conf, CONF_cygterm64));
|
||||
if (!cygwinBinPath) {
|
||||
/* we'll try anyway */
|
||||
cygterm_debug("cygwin bin directory not found");
|
||||
}
|
||||
else {
|
||||
cygterm_debug("found cygwin directory: %s", cygwinBinPath);
|
||||
appendPath(cygwinBinPath);
|
||||
sfree(cygwinBinPath);
|
||||
}
|
||||
}
|
||||
{ char buffer[1024] ; sprintf(buffer, "Create process %s", cmd ) ; logevent(NULL,buffer); }
|
||||
/* We allow cthelper to inherit handles. I have no idea if there are
|
||||
* other inheritable handles in PuTTY that this will effect. cthelper
|
||||
* will attempt to close all open descriptors.
|
||||
*/
|
||||
if (!CreateProcess(
|
||||
NULL, cmd, /* command line */
|
||||
NULL, NULL, /* no process or thread security attributes */
|
||||
TRUE, /* inherit handles */
|
||||
CREATE_NEW_CONSOLE, /* create a new console window */
|
||||
NULL, /* use parent environment */
|
||||
0, /* use parent working directory */
|
||||
&si, /* STARTUPINFO sets stdin to read end of pipe */
|
||||
ppi))
|
||||
{
|
||||
CloseHandle(in);
|
||||
CloseHandle(*pin);
|
||||
*pin = INVALID_HANDLE_VALUE;
|
||||
return "failed to run cthelper";
|
||||
}
|
||||
|
||||
/* close the read end of the pipe */
|
||||
CloseHandle(in);
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
-174
@@ -1,174 +0,0 @@
|
||||
/*
|
||||
* Main program.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stddef.h>
|
||||
#include <stdarg.h>
|
||||
#include <signal.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
#include "sel.h"
|
||||
#include "pty.h"
|
||||
#include "telnet.h"
|
||||
|
||||
int signalpipe[2];
|
||||
|
||||
sel *asel;
|
||||
sel_rfd *netr, *ptyr, *sigr;
|
||||
int ptyfd;
|
||||
sel_wfd *netw, *ptyw;
|
||||
Telnet *telnet;
|
||||
|
||||
#define BUF 65536
|
||||
|
||||
void sigchld(int signum)
|
||||
{
|
||||
write(signalpipe[1], "C", 1);
|
||||
}
|
||||
|
||||
void fatal(const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
fprintf(stderr, "cygtermd: ");
|
||||
va_start(ap, fmt);
|
||||
vfprintf(stderr, fmt, ap);
|
||||
va_end(ap);
|
||||
fprintf(stderr, "\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
void net_readdata(sel_rfd *rfd, void *data, size_t len)
|
||||
{
|
||||
if (len == 0)
|
||||
exit(0); /* EOF on network - client went away */
|
||||
telnet_from_net(telnet, data, len);
|
||||
if (sel_write(netw, NULL, 0) > BUF)
|
||||
sel_rfd_freeze(ptyr);
|
||||
if (sel_write(ptyw, NULL, 0) > BUF)
|
||||
sel_rfd_freeze(netr);
|
||||
}
|
||||
|
||||
void net_readerr(sel_rfd *rfd, int error)
|
||||
{
|
||||
fprintf(stderr, "standard input: read: %s\n", strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
void net_written(sel_wfd *wfd, size_t bufsize)
|
||||
{
|
||||
if (bufsize < BUF)
|
||||
sel_rfd_unfreeze(ptyr);
|
||||
}
|
||||
|
||||
void net_writeerr(sel_wfd *wfd, int error)
|
||||
{
|
||||
fprintf(stderr, "standard input: write: %s\n", strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
void pty_readdata(sel_rfd *rfd, void *data, size_t len)
|
||||
{
|
||||
if (len == 0)
|
||||
exit(0); /* EOF on pty */
|
||||
telnet_from_pty(telnet, data, len);
|
||||
if (sel_write(netw, NULL, 0) > BUF)
|
||||
sel_rfd_freeze(ptyr);
|
||||
if (sel_write(ptyw, NULL, 0) > BUF)
|
||||
sel_rfd_freeze(netr);
|
||||
}
|
||||
|
||||
void pty_readerr(sel_rfd *rfd, int error)
|
||||
{
|
||||
if (error == EIO) /* means EOF, on a pty */
|
||||
exit(0);
|
||||
fprintf(stderr, "pty: read: %s\n", strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
void pty_written(sel_wfd *wfd, size_t bufsize)
|
||||
{
|
||||
if (bufsize < BUF)
|
||||
sel_rfd_unfreeze(netr);
|
||||
}
|
||||
|
||||
void pty_writeerr(sel_wfd *wfd, int error)
|
||||
{
|
||||
fprintf(stderr, "pty: write: %s\n", strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
void sig_readdata(sel_rfd *rfd, void *data, size_t len)
|
||||
{
|
||||
char *p = data;
|
||||
|
||||
while (len > 0) {
|
||||
if (*p == 'C') {
|
||||
int status;
|
||||
waitpid(-1, &status, WNOHANG);
|
||||
if (WIFEXITED(status) || WIFSIGNALED(status))
|
||||
exit(0); /* child process vanished */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void sig_readerr(sel_rfd *rfd, int error)
|
||||
{
|
||||
fprintf(stderr, "signal pipe: read: %s\n", strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int ret;
|
||||
int shell_started = 0;
|
||||
char *directory = NULL;
|
||||
char **program_args = NULL;
|
||||
|
||||
if (argc > 1 && argv[1][0]) {
|
||||
directory = argv[1];
|
||||
argc--, argv++;
|
||||
}
|
||||
if (argc > 1) {
|
||||
program_args = argv + 1;
|
||||
}
|
||||
|
||||
pty_preinit();
|
||||
|
||||
asel = sel_new(NULL);
|
||||
netr = sel_rfd_add(asel, 0, net_readdata, net_readerr, NULL);
|
||||
netw = sel_wfd_add(asel, 1, net_written, net_writeerr, NULL);
|
||||
ptyr = sel_rfd_add(asel, -1, pty_readdata, pty_readerr, NULL);
|
||||
ptyw = sel_wfd_add(asel, -1, pty_written, pty_writeerr, NULL);
|
||||
|
||||
telnet = telnet_new(netw, ptyw);
|
||||
|
||||
if (pipe(signalpipe) < 0) {
|
||||
perror("pipe");
|
||||
return 1;
|
||||
}
|
||||
sigr = sel_rfd_add(asel, signalpipe[0], sig_readdata,
|
||||
sig_readerr, NULL);
|
||||
|
||||
signal(SIGCHLD, sigchld);
|
||||
|
||||
do {
|
||||
struct shell_data shdata;
|
||||
|
||||
ret = sel_iterate(asel, -1);
|
||||
if (!shell_started && telnet_shell_ok(telnet, &shdata)) {
|
||||
ptyfd = run_program_in_pty(&shdata, directory, program_args);
|
||||
sel_rfd_setfd(ptyr, ptyfd);
|
||||
sel_wfd_setfd(ptyw, ptyfd);
|
||||
shell_started = 1;
|
||||
}
|
||||
} while (ret == 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
/*
|
||||
* malloc.c: implementation of malloc.h
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "malloc.h"
|
||||
|
||||
extern void fatal(const char *, ...);
|
||||
|
||||
void *smalloc(size_t size) {
|
||||
void *p;
|
||||
p = malloc(size);
|
||||
if (!p) {
|
||||
fatal("out of memory");
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
void sfree(void *p) {
|
||||
if (p) {
|
||||
free(p);
|
||||
}
|
||||
}
|
||||
|
||||
void *srealloc(void *p, size_t size) {
|
||||
void *q;
|
||||
if (p) {
|
||||
q = realloc(p, size);
|
||||
} else {
|
||||
q = malloc(size);
|
||||
}
|
||||
if (!q)
|
||||
fatal("out of memory");
|
||||
return q;
|
||||
}
|
||||
|
||||
char *dupstr(const char *s) {
|
||||
char *r = smalloc(1+strlen(s));
|
||||
strcpy(r,s);
|
||||
return r;
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
/*
|
||||
* malloc.h: safe wrappers around malloc, realloc, free, strdup
|
||||
*/
|
||||
|
||||
#ifndef UMLWRAP_MALLOC_H
|
||||
#define UMLWRAP_MALLOC_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
/*
|
||||
* smalloc should guarantee to return a useful pointer - Halibut
|
||||
* can do nothing except die when it's out of memory anyway.
|
||||
*/
|
||||
void *smalloc(size_t size);
|
||||
|
||||
/*
|
||||
* srealloc should guaranteeably be able to realloc NULL
|
||||
*/
|
||||
void *srealloc(void *p, size_t size);
|
||||
|
||||
/*
|
||||
* sfree should guaranteeably deal gracefully with freeing NULL
|
||||
*/
|
||||
void sfree(void *p);
|
||||
|
||||
/*
|
||||
* dupstr is like strdup, but with the never-return-NULL property
|
||||
* of smalloc (and also reliably defined in all environments :-)
|
||||
*/
|
||||
char *dupstr(const char *s);
|
||||
|
||||
/*
|
||||
* snew allocates one instance of a given type, and casts the
|
||||
* result so as to type-check that you're assigning it to the
|
||||
* right kind of pointer. Protects against allocation bugs
|
||||
* involving allocating the wrong size of thing.
|
||||
*/
|
||||
#define snew(type) \
|
||||
( (type *) smalloc (sizeof (type)) )
|
||||
|
||||
/*
|
||||
* snewn allocates n instances of a given type, for arrays.
|
||||
*/
|
||||
#define snewn(number, type) \
|
||||
( (type *) smalloc ((number) * sizeof (type)) )
|
||||
|
||||
/*
|
||||
* sresize wraps realloc so that you specify the new number of
|
||||
* elements and the type of the element, with the same type-
|
||||
* checking advantages. Also type-checks the input pointer.
|
||||
*/
|
||||
#define sresize(array, number, type) \
|
||||
( (void)sizeof((array)-(type *)0), \
|
||||
(type *) srealloc ((array), (number) * sizeof (type)) )
|
||||
|
||||
#endif /* UMLWRAP_MALLOC_H */
|
||||
-202
@@ -1,202 +0,0 @@
|
||||
/*
|
||||
* pty.c - pseudo-terminal handling
|
||||
*/
|
||||
|
||||
#define _XOPEN_SOURCE 500
|
||||
#include <features.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <termios.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/types.h>
|
||||
#include <pwd.h>
|
||||
|
||||
#include "pty.h"
|
||||
#include "malloc.h"
|
||||
|
||||
static char ptyname[FILENAME_MAX];
|
||||
int master = -1;
|
||||
|
||||
void pty_preinit(void)
|
||||
{
|
||||
/*
|
||||
* Allocate the pty.
|
||||
*/
|
||||
master = open("/dev/ptmx", O_RDWR);
|
||||
if (master < 0) {
|
||||
perror("/dev/ptmx: open");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (grantpt(master) < 0) {
|
||||
perror("grantpt");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (unlockpt(master) < 0) {
|
||||
perror("unlockpt");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
void pty_resize(int w, int h)
|
||||
{
|
||||
struct winsize sz;
|
||||
|
||||
assert(master >= 0);
|
||||
|
||||
sz.ws_row = h;
|
||||
sz.ws_col = w;
|
||||
sz.ws_xpixel = sz.ws_ypixel = 0;
|
||||
ioctl(master, TIOCSWINSZ, &sz);
|
||||
}
|
||||
|
||||
int run_program_in_pty(const struct shell_data *shdata,
|
||||
char *directory, char **program_args)
|
||||
{
|
||||
int slave, pid;
|
||||
char *fallback_args[2];
|
||||
|
||||
assert(master >= 0);
|
||||
|
||||
ptyname[FILENAME_MAX-1] = '\0';
|
||||
strncpy(ptyname, ptsname(master), FILENAME_MAX-1);
|
||||
|
||||
#if 0
|
||||
{
|
||||
struct winsize ws;
|
||||
struct termios ts;
|
||||
|
||||
/*
|
||||
* FIXME: think up some good defaults here
|
||||
*/
|
||||
|
||||
if (!ioctl(0, TIOCGWINSZ, &ws))
|
||||
ioctl(master, TIOCSWINSZ, &ws);
|
||||
if (!tcgetattr(0, &ts))
|
||||
tcsetattr(master, TCSANOW, &ts);
|
||||
}
|
||||
#endif
|
||||
|
||||
slave = open(ptyname, O_RDWR | O_NOCTTY);
|
||||
if (slave < 0) {
|
||||
perror("slave pty: open");
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Fork and execute the command.
|
||||
*/
|
||||
pid = fork();
|
||||
if (pid < 0) {
|
||||
perror("fork");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (pid == 0) {
|
||||
int i, fd;
|
||||
|
||||
/*
|
||||
* We are the child.
|
||||
*/
|
||||
close(master);
|
||||
|
||||
fcntl(slave, F_SETFD, 0); /* don't close on exec */
|
||||
dup2(slave, 0);
|
||||
dup2(slave, 1);
|
||||
if (slave != 0 && slave != 1)
|
||||
close(slave);
|
||||
dup2(1, 2);
|
||||
setsid();
|
||||
setpgrp();
|
||||
i = 0;
|
||||
#ifdef TIOCNOTTY
|
||||
if ((fd = open("/dev/tty", O_RDWR)) >= 0) {
|
||||
ioctl(fd, TIOCNOTTY, &i);
|
||||
close(fd);
|
||||
}
|
||||
#endif
|
||||
/*
|
||||
* Make the new pty our controlling terminal. On some OSes
|
||||
* this is done with TIOCSCTTY; Cygwin doesn't have that, so
|
||||
* instead it's done by simply opening the pty without
|
||||
* O_NOCTTY. This code is primarily intended for Cygwin, but
|
||||
* it's useful to have it work in other contexts for testing
|
||||
* purposes, so I leave the TIOCSCTTY here anyway.
|
||||
*/
|
||||
if ((fd = open(ptyname, O_RDWR)) >= 0) {
|
||||
#ifdef TIOCSCTTY
|
||||
ioctl(fd, TIOCSCTTY, &i);
|
||||
#endif
|
||||
close(fd);
|
||||
} else {
|
||||
perror("slave pty: open");
|
||||
exit(127);
|
||||
}
|
||||
tcsetpgrp(0, getpgrp());
|
||||
|
||||
for (i = 0; i < shdata->nenvvars; i++)
|
||||
putenv(shdata->envvars[i]);
|
||||
if (shdata->termtype)
|
||||
putenv(shdata->termtype);
|
||||
|
||||
if (directory)
|
||||
chdir(directory);
|
||||
|
||||
/*
|
||||
* Use the provided shell program name, if the user gave
|
||||
* one. Failing that, use $SHELL; failing that, look up
|
||||
* the user's default shell in the password file; failing
|
||||
* _that_, revert to the bog-standard /bin/sh.
|
||||
*/
|
||||
if (!program_args) {
|
||||
char *shell;
|
||||
|
||||
shell = getenv("SHELL");
|
||||
if (!shell) {
|
||||
const char *login;
|
||||
uid_t uid;
|
||||
struct passwd *pwd;
|
||||
|
||||
/*
|
||||
* For maximum generality in the face of multiple
|
||||
* /etc/passwd entries with different login names and
|
||||
* shells but a shared uid, we start by using
|
||||
* getpwnam(getlogin()) if it's available - but we
|
||||
* insist that its uid must match our real one, or we
|
||||
* give up and fall back to getpwuid(getuid()).
|
||||
*/
|
||||
uid = getuid();
|
||||
login = getlogin();
|
||||
if (login && (pwd = getpwnam(login)) && pwd->pw_uid == uid)
|
||||
shell = pwd->pw_shell;
|
||||
else if ((pwd = getpwuid(uid)))
|
||||
shell = pwd->pw_shell;
|
||||
}
|
||||
if (!shell)
|
||||
shell = "/bin/sh";
|
||||
|
||||
fallback_args[0] = shell;
|
||||
fallback_args[1] = NULL;
|
||||
program_args = fallback_args;
|
||||
}
|
||||
|
||||
execv(program_args[0], program_args);
|
||||
|
||||
/*
|
||||
* If we're here, exec has gone badly foom.
|
||||
*/
|
||||
perror("exec");
|
||||
exit(127);
|
||||
}
|
||||
|
||||
close(slave);
|
||||
|
||||
return master;
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
/*
|
||||
* pty.h - declare functions for pty setup
|
||||
*/
|
||||
|
||||
#ifndef CYGTERMD_PTY_H
|
||||
#define CYGTERMD_PTY_H
|
||||
|
||||
#include "telnet.h" /* for struct shdata */
|
||||
|
||||
/*
|
||||
* Called at program startup to actually allocate a pty, so that
|
||||
* we can start passing in resize events as soon as they arrive.
|
||||
*/
|
||||
void pty_preinit(void);
|
||||
|
||||
/*
|
||||
* Set the terminal size for the pty.
|
||||
*/
|
||||
void pty_resize(int w, int h);
|
||||
|
||||
/*
|
||||
* Start a program in a subprocess running in the pty we allocated.
|
||||
* Returns the fd of the pty master.
|
||||
*/
|
||||
int run_program_in_pty(const struct shell_data *shdata,
|
||||
char *directory, char **program_args);
|
||||
|
||||
#endif /* CYGTERMD_PTY_H */
|
||||
-386
@@ -1,386 +0,0 @@
|
||||
/*
|
||||
* sel.c: implementation of sel.h.
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/select.h>
|
||||
|
||||
#include "sel.h"
|
||||
#include "malloc.h"
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
* Chunk of code lifted from PuTTY's misc.c to manage buffers of
|
||||
* data to be written to an fd.
|
||||
*/
|
||||
|
||||
#define BUFFER_GRANULE 512
|
||||
|
||||
typedef struct bufchain_tag {
|
||||
struct bufchain_granule *head, *tail;
|
||||
size_t buffersize; /* current amount of buffered data */
|
||||
} bufchain;
|
||||
struct bufchain_granule {
|
||||
struct bufchain_granule *next;
|
||||
size_t buflen, bufpos;
|
||||
char buf[BUFFER_GRANULE];
|
||||
};
|
||||
|
||||
static void bufchain_init(bufchain *ch)
|
||||
{
|
||||
ch->head = ch->tail = NULL;
|
||||
ch->buffersize = 0;
|
||||
}
|
||||
|
||||
static void bufchain_clear(bufchain *ch)
|
||||
{
|
||||
struct bufchain_granule *b;
|
||||
while (ch->head) {
|
||||
b = ch->head;
|
||||
ch->head = ch->head->next;
|
||||
sfree(b);
|
||||
}
|
||||
ch->tail = NULL;
|
||||
ch->buffersize = 0;
|
||||
}
|
||||
|
||||
static size_t bufchain_size(bufchain *ch)
|
||||
{
|
||||
return ch->buffersize;
|
||||
}
|
||||
|
||||
static void bufchain_add(bufchain *ch, const void *data, size_t len)
|
||||
{
|
||||
const char *buf = (const char *)data;
|
||||
|
||||
if (len == 0) return;
|
||||
|
||||
ch->buffersize += len;
|
||||
|
||||
if (ch->tail && ch->tail->buflen < BUFFER_GRANULE) {
|
||||
size_t copylen = BUFFER_GRANULE - ch->tail->buflen;
|
||||
if (copylen > len)
|
||||
copylen = len;
|
||||
memcpy(ch->tail->buf + ch->tail->buflen, buf, copylen);
|
||||
buf += copylen;
|
||||
len -= copylen;
|
||||
ch->tail->buflen += copylen;
|
||||
}
|
||||
while (len > 0) {
|
||||
struct bufchain_granule *newbuf;
|
||||
size_t grainlen = BUFFER_GRANULE;
|
||||
if (grainlen > len)
|
||||
grainlen = len;
|
||||
newbuf = snew(struct bufchain_granule);
|
||||
newbuf->bufpos = 0;
|
||||
newbuf->buflen = grainlen;
|
||||
memcpy(newbuf->buf, buf, grainlen);
|
||||
buf += grainlen;
|
||||
len -= grainlen;
|
||||
if (ch->tail)
|
||||
ch->tail->next = newbuf;
|
||||
else
|
||||
ch->head = ch->tail = newbuf;
|
||||
newbuf->next = NULL;
|
||||
ch->tail = newbuf;
|
||||
}
|
||||
}
|
||||
|
||||
static void bufchain_consume(bufchain *ch, size_t len)
|
||||
{
|
||||
struct bufchain_granule *tmp;
|
||||
|
||||
assert(ch->buffersize >= len);
|
||||
while (len > 0) {
|
||||
size_t remlen = len;
|
||||
assert(ch->head != NULL);
|
||||
if (remlen >= ch->head->buflen - ch->head->bufpos) {
|
||||
remlen = ch->head->buflen - ch->head->bufpos;
|
||||
tmp = ch->head;
|
||||
ch->head = tmp->next;
|
||||
sfree(tmp);
|
||||
if (!ch->head)
|
||||
ch->tail = NULL;
|
||||
} else
|
||||
ch->head->bufpos += remlen;
|
||||
ch->buffersize -= remlen;
|
||||
len -= remlen;
|
||||
}
|
||||
}
|
||||
|
||||
static void bufchain_prefix(bufchain *ch, void **data, size_t *len)
|
||||
{
|
||||
*len = ch->head->buflen - ch->head->bufpos;
|
||||
*data = ch->head->buf + ch->head->bufpos;
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
* The actual implementation of the sel interface.
|
||||
*/
|
||||
|
||||
struct sel {
|
||||
void *ctx;
|
||||
sel_rfd *rhead, *rtail;
|
||||
sel_wfd *whead, *wtail;
|
||||
};
|
||||
|
||||
struct sel_rfd {
|
||||
sel *parent;
|
||||
sel_rfd *prev, *next;
|
||||
sel_readdata_fn_t readdata;
|
||||
sel_readerr_fn_t readerr;
|
||||
void *ctx;
|
||||
int fd;
|
||||
int frozen;
|
||||
};
|
||||
|
||||
struct sel_wfd {
|
||||
sel *parent;
|
||||
sel_wfd *prev, *next;
|
||||
sel_written_fn_t written;
|
||||
sel_writeerr_fn_t writeerr;
|
||||
void *ctx;
|
||||
int fd;
|
||||
bufchain buf;
|
||||
};
|
||||
|
||||
sel *sel_new(void *ctx)
|
||||
{
|
||||
sel *sel = snew(struct sel);
|
||||
|
||||
sel->ctx = ctx;
|
||||
sel->rhead = sel->rtail = NULL;
|
||||
sel->whead = sel->wtail = NULL;
|
||||
|
||||
return sel;
|
||||
}
|
||||
|
||||
sel_wfd *sel_wfd_add(sel *sel, int fd,
|
||||
sel_written_fn_t written, sel_writeerr_fn_t writeerr,
|
||||
void *ctx)
|
||||
{
|
||||
sel_wfd *wfd = snew(sel_wfd);
|
||||
|
||||
wfd->written = written;
|
||||
wfd->writeerr = writeerr;
|
||||
wfd->ctx = ctx;
|
||||
wfd->fd = fd;
|
||||
bufchain_init(&wfd->buf);
|
||||
|
||||
wfd->next = NULL;
|
||||
wfd->prev = sel->wtail;
|
||||
if (sel->wtail)
|
||||
sel->wtail->next = wfd;
|
||||
else
|
||||
sel->whead = wfd;
|
||||
sel->wtail = wfd;
|
||||
wfd->parent = sel;
|
||||
|
||||
return wfd;
|
||||
}
|
||||
|
||||
sel_rfd *sel_rfd_add(sel *sel, int fd,
|
||||
sel_readdata_fn_t readdata, sel_readerr_fn_t readerr,
|
||||
void *ctx)
|
||||
{
|
||||
sel_rfd *rfd = snew(sel_rfd);
|
||||
|
||||
rfd->readdata = readdata;
|
||||
rfd->readerr = readerr;
|
||||
rfd->ctx = ctx;
|
||||
rfd->fd = fd;
|
||||
rfd->frozen = 0;
|
||||
|
||||
rfd->next = NULL;
|
||||
rfd->prev = sel->rtail;
|
||||
if (sel->rtail)
|
||||
sel->rtail->next = rfd;
|
||||
else
|
||||
sel->rhead = rfd;
|
||||
sel->rtail = rfd;
|
||||
rfd->parent = sel;
|
||||
|
||||
return rfd;
|
||||
}
|
||||
|
||||
size_t sel_write(sel_wfd *wfd, const void *data, size_t len)
|
||||
{
|
||||
bufchain_add(&wfd->buf, data, len);
|
||||
return bufchain_size(&wfd->buf);
|
||||
}
|
||||
|
||||
void sel_wfd_setfd(sel_wfd *wfd, int fd)
|
||||
{
|
||||
wfd->fd = fd;
|
||||
}
|
||||
|
||||
void sel_rfd_setfd(sel_rfd *rfd, int fd)
|
||||
{
|
||||
rfd->fd = fd;
|
||||
}
|
||||
|
||||
void sel_rfd_freeze(sel_rfd *rfd)
|
||||
{
|
||||
rfd->frozen = 1;
|
||||
}
|
||||
|
||||
void sel_rfd_unfreeze(sel_rfd *rfd)
|
||||
{
|
||||
rfd->frozen = 0;
|
||||
}
|
||||
|
||||
int sel_wfd_delete(sel_wfd *wfd)
|
||||
{
|
||||
sel *sel = wfd->parent;
|
||||
int ret;
|
||||
|
||||
if (wfd->prev)
|
||||
wfd->prev->next = wfd->next;
|
||||
else
|
||||
sel->whead = wfd->next;
|
||||
if (wfd->next)
|
||||
wfd->next->prev = wfd->prev;
|
||||
else
|
||||
sel->wtail = wfd->prev;
|
||||
|
||||
bufchain_clear(&wfd->buf);
|
||||
|
||||
ret = wfd->fd;
|
||||
sfree(wfd);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int sel_rfd_delete(sel_rfd *rfd)
|
||||
{
|
||||
sel *sel = rfd->parent;
|
||||
int ret;
|
||||
|
||||
if (rfd->prev)
|
||||
rfd->prev->next = rfd->next;
|
||||
else
|
||||
sel->rhead = rfd->next;
|
||||
if (rfd->next)
|
||||
rfd->next->prev = rfd->prev;
|
||||
else
|
||||
sel->rtail = rfd->prev;
|
||||
|
||||
ret = rfd->fd;
|
||||
sfree(rfd);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void sel_free(sel *sel)
|
||||
{
|
||||
while (sel->whead)
|
||||
sel_wfd_delete(sel->whead);
|
||||
while (sel->rhead)
|
||||
sel_rfd_delete(sel->rhead);
|
||||
sfree(sel);
|
||||
}
|
||||
|
||||
void *sel_get_ctx(sel *sel) { return sel->ctx; }
|
||||
void sel_set_ctx(sel *sel, void *ctx) { sel->ctx = ctx; }
|
||||
void *sel_wfd_get_ctx(sel_wfd *wfd) { return wfd->ctx; }
|
||||
void sel_wfd_set_ctx(sel_wfd *wfd, void *ctx) { wfd->ctx = ctx; }
|
||||
void *sel_rfd_get_ctx(sel_rfd *rfd) { return rfd->ctx; }
|
||||
void sel_rfd_set_ctx(sel_rfd *rfd, void *ctx) { rfd->ctx = ctx; }
|
||||
|
||||
int sel_iterate(sel *sel, long timeout)
|
||||
{
|
||||
sel_rfd *rfd;
|
||||
sel_wfd *wfd;
|
||||
fd_set rset, wset;
|
||||
int maxfd = 0;
|
||||
struct timeval tv, *ptv;
|
||||
char buf[65536];
|
||||
int ret;
|
||||
|
||||
FD_ZERO(&rset);
|
||||
FD_ZERO(&wset);
|
||||
|
||||
for (rfd = sel->rhead; rfd; rfd = rfd->next) {
|
||||
if (rfd->fd >= 0 && !rfd->frozen) {
|
||||
FD_SET(rfd->fd, &rset);
|
||||
if (maxfd < rfd->fd + 1)
|
||||
maxfd = rfd->fd + 1;
|
||||
}
|
||||
}
|
||||
|
||||
for (wfd = sel->whead; wfd; wfd = wfd->next) {
|
||||
if (wfd->fd >= 0 && bufchain_size(&wfd->buf)) {
|
||||
FD_SET(wfd->fd, &wset);
|
||||
if (maxfd < wfd->fd + 1)
|
||||
maxfd = wfd->fd + 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (timeout < 0) {
|
||||
ptv = NULL;
|
||||
} else {
|
||||
ptv = &tv;
|
||||
tv.tv_sec = timeout / 1000;
|
||||
tv.tv_usec = 1000 * (timeout % 1000);
|
||||
}
|
||||
|
||||
do {
|
||||
ret = select(maxfd, &rset, &wset, NULL, ptv);
|
||||
} while (ret < 0 && (errno == EINTR || errno == EAGAIN));
|
||||
|
||||
if (ret < 0)
|
||||
return errno;
|
||||
|
||||
/*
|
||||
* Just in case one of the callbacks destroys an rfd or wfd we
|
||||
* had yet to get round to, we must loop from the start every
|
||||
* single time. Algorithmically irritating, but necessary
|
||||
* unless we want to store the rfd structures in a heavyweight
|
||||
* tree sorted by fd. And let's face it, if we cared about
|
||||
* good algorithmic complexity it's not at all clear we'd be
|
||||
* using select in the first place.
|
||||
*/
|
||||
do {
|
||||
for (wfd = sel->whead; wfd; wfd = wfd->next)
|
||||
if (wfd->fd >= 0 && FD_ISSET(wfd->fd, &wset)) {
|
||||
void *data;
|
||||
size_t len;
|
||||
|
||||
FD_CLR(wfd->fd, &wset);
|
||||
bufchain_prefix(&wfd->buf, &data, &len);
|
||||
ret = write(wfd->fd, data, len);
|
||||
assert(ret != 0);
|
||||
if (ret < 0) {
|
||||
if (wfd->writeerr)
|
||||
wfd->writeerr(wfd, errno);
|
||||
} else {
|
||||
bufchain_consume(&wfd->buf, len);
|
||||
if (wfd->written)
|
||||
wfd->written(wfd, bufchain_size(&wfd->buf));
|
||||
}
|
||||
break;
|
||||
}
|
||||
} while (wfd);
|
||||
do {
|
||||
for (rfd = sel->rhead; rfd; rfd = rfd->next)
|
||||
if (rfd->fd >= 0 && !rfd->frozen && FD_ISSET(rfd->fd, &rset)) {
|
||||
FD_CLR(rfd->fd, &rset);
|
||||
ret = read(rfd->fd, buf, sizeof(buf));
|
||||
if (ret < 0) {
|
||||
if (rfd->readerr)
|
||||
rfd->readerr(rfd, errno);
|
||||
} else {
|
||||
if (rfd->readdata)
|
||||
rfd->readdata(rfd, buf, ret);
|
||||
}
|
||||
break;
|
||||
}
|
||||
} while (rfd);
|
||||
|
||||
return 0;
|
||||
}
|
||||
-161
@@ -1,161 +0,0 @@
|
||||
/*
|
||||
* sel.h: subsystem to manage the grubby details of a select loop,
|
||||
* buffering data to write, and performing the actual writes and
|
||||
* reads.
|
||||
*/
|
||||
|
||||
#ifndef CYGTERMD_SEL_H
|
||||
#define CYGTERMD_SEL_H
|
||||
|
||||
typedef struct sel sel;
|
||||
typedef struct sel_wfd sel_wfd;
|
||||
typedef struct sel_rfd sel_rfd;
|
||||
|
||||
/*
|
||||
* Callback called when some data is written to a wfd. "bufsize"
|
||||
* is the remaining quantity of data buffered in that wfd.
|
||||
*/
|
||||
typedef void (*sel_written_fn_t)(sel_wfd *wfd, size_t bufsize);
|
||||
|
||||
/*
|
||||
* Callback called when an error occurs on a wfd, preventing
|
||||
* further writing to it. "error" is the errno value.
|
||||
*/
|
||||
typedef void (*sel_writeerr_fn_t)(sel_wfd *wfd, int error);
|
||||
|
||||
/*
|
||||
* Callback called when some data is read from an rfd. On EOF,
|
||||
* this will be called with len==0.
|
||||
*/
|
||||
typedef void (*sel_readdata_fn_t)(sel_rfd *rfd, void *data, size_t len);
|
||||
|
||||
/*
|
||||
* Callback called when an error occurs on an rfd, preventing
|
||||
* further reading from it. "error" is the errno value.
|
||||
*/
|
||||
typedef void (*sel_readerr_fn_t)(sel_rfd *rfd, int error);
|
||||
|
||||
/*
|
||||
* Create a sel structure, which will oversee a select loop.
|
||||
*
|
||||
* "ctx" is user-supplied data stored in the sel structure; it can
|
||||
* be read and written with sel_get_ctx() and sel_set_ctx().
|
||||
*/
|
||||
sel *sel_new(void *ctx);
|
||||
|
||||
/*
|
||||
* Add a new fd for writing. Returns a sel_wfd which identifies
|
||||
* that fd in the sel structure, e.g. for putting data into its
|
||||
* output buffer.
|
||||
*
|
||||
* "ctx" is user-supplied data stored in the sel structure; it can
|
||||
* be read and written with sel_wfd_get_ctx() and sel_wfd_set_ctx().
|
||||
*
|
||||
* "written" and "writeerr" are called from the event loop when
|
||||
* things happen.
|
||||
*
|
||||
* The fd passed in can be -1, in which case it will be assumed to
|
||||
* be unwritable at all times. An actual fd can be passed in later
|
||||
* using sel_wfd_setfd.
|
||||
*/
|
||||
sel_wfd *sel_wfd_add(sel *sel, int fd,
|
||||
sel_written_fn_t written, sel_writeerr_fn_t writeerr,
|
||||
void *ctx);
|
||||
|
||||
/*
|
||||
* Add a new fd for reading. Returns a sel_rfd which identifies
|
||||
* that fd in the sel structure.
|
||||
*
|
||||
* "ctx" is user-supplied data stored in the sel structure; it can
|
||||
* be read and written with sel_rfd_get_ctx() and sel_rfd_set_ctx().
|
||||
*
|
||||
* "readdata" and "readerr" are called from the event loop when
|
||||
* things happen. "ctx" is passed to both of them.
|
||||
*/
|
||||
sel_rfd *sel_rfd_add(sel *sel, int fd,
|
||||
sel_readdata_fn_t readdata, sel_readerr_fn_t readerr,
|
||||
void *ctx);
|
||||
|
||||
/*
|
||||
* Write data into the output buffer of a wfd. Returns the new
|
||||
* size of the output buffer. (You can call it with len==0 if you
|
||||
* just want to know the buffer size; in that situation data==NULL
|
||||
* is also safe.)
|
||||
*/
|
||||
size_t sel_write(sel_wfd *wfd, const void *data, size_t len);
|
||||
|
||||
/*
|
||||
* Freeze and unfreeze an rfd. When frozen, sel will temporarily
|
||||
* not attempt to read from it, but all its state is retained so
|
||||
* it can be conveniently unfrozen later. (You might use this
|
||||
* facility, for instance, if what you were doing with the
|
||||
* incoming data could only accept it at a certain rate: freeze
|
||||
* the rfd when you've got lots of backlog, and unfreeze it again
|
||||
* when things get calmer.)
|
||||
*/
|
||||
void sel_rfd_freeze(sel_rfd *rfd);
|
||||
void sel_rfd_unfreeze(sel_rfd *rfd);
|
||||
|
||||
/*
|
||||
* Delete a wfd structure from its containing sel. Returns the
|
||||
* underlying fd, which the client may now consider itself to own
|
||||
* once more.
|
||||
*/
|
||||
int sel_wfd_delete(sel_wfd *wfd);
|
||||
|
||||
/*
|
||||
* Delete an rfd structure from its containing sel. Returns the
|
||||
* underlying fd, which the client may now consider itself to own
|
||||
* once more.
|
||||
*/
|
||||
int sel_rfd_delete(sel_rfd *rfd);
|
||||
|
||||
/*
|
||||
* NOT IMPLEMENTED YET: useful functions here might be ones which
|
||||
* enumerated all the wfds/rfds in a sel structure in some
|
||||
* fashion, so you could go through them and remove them all while
|
||||
* doing sensible things to them. Or, at the very least, just
|
||||
* return an arbitrary one of the wfds/rfds.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Free a sel structure and all its remaining wfds and rfds.
|
||||
*/
|
||||
void sel_free(sel *sel);
|
||||
|
||||
/*
|
||||
* Read and write the ctx parameters in sel, sel_wfd and sel_rfd.
|
||||
*/
|
||||
void *sel_get_ctx(sel *sel);
|
||||
void sel_set_ctx(sel *sel, void *ctx);
|
||||
void *sel_wfd_get_ctx(sel_wfd *wfd);
|
||||
void sel_wfd_set_ctx(sel_wfd *wfd, void *ctx);
|
||||
void *sel_rfd_get_ctx(sel_rfd *rfd);
|
||||
void sel_rfd_set_ctx(sel_rfd *rfd, void *ctx);
|
||||
|
||||
/*
|
||||
* Run one iteration of the sel event loop, calling callbacks as
|
||||
* necessary. Returns zero on success; in the event of a fatal
|
||||
* error, returns the errno value.
|
||||
*
|
||||
* "timeout" is a value in microseconds to limit the length of the
|
||||
* select call. Less than zero means to wait indefinitely.
|
||||
*/
|
||||
int sel_iterate(sel *sel, long timeout);
|
||||
|
||||
/*
|
||||
* Change the underlying fd in a wfd. If set to -1, no write
|
||||
* attempts will take place and the wfd's buffer will simply store
|
||||
* everything passed to sel_write(). If later set to something
|
||||
* other than -1, all that buffered data will become eligible for
|
||||
* real writing.
|
||||
*/
|
||||
void sel_wfd_setfd(sel_wfd *wfd, int fd);
|
||||
|
||||
/*
|
||||
* Change the underlying fd in a rfd. If set to -1, no read
|
||||
* attempts will take place.
|
||||
*/
|
||||
void sel_rfd_setfd(sel_rfd *rfd, int fd);
|
||||
|
||||
#endif /* CYGTERMD_SEL_H */
|
||||
@@ -1,565 +0,0 @@
|
||||
/*
|
||||
* Simple Telnet server code, adapted from PuTTY's own Telnet
|
||||
* client code for use as a Cygwin local pty proxy.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "sel.h"
|
||||
#include "telnet.h"
|
||||
#include "malloc.h"
|
||||
#include "pty.h"
|
||||
|
||||
#define IAC 255 /* interpret as command: */
|
||||
#define DONT 254 /* you are not to use option */
|
||||
#define DO 253 /* please, you use option */
|
||||
#define WONT 252 /* I won't use option */
|
||||
#define WILL 251 /* I will use option */
|
||||
#define SB 250 /* interpret as subnegotiation */
|
||||
#define SE 240 /* end sub negotiation */
|
||||
|
||||
#define GA 249 /* you may reverse the line */
|
||||
#define EL 248 /* erase the current line */
|
||||
#define EC 247 /* erase the current character */
|
||||
#define AYT 246 /* are you there */
|
||||
#define AO 245 /* abort output--but let prog finish */
|
||||
#define IP 244 /* interrupt process--permanently */
|
||||
#define BREAK 243 /* break */
|
||||
#define DM 242 /* data mark--for connect. cleaning */
|
||||
#define NOP 241 /* nop */
|
||||
#define EOR 239 /* end of record (transparent mode) */
|
||||
#define ABORT 238 /* Abort process */
|
||||
#define SUSP 237 /* Suspend process */
|
||||
#define xEOF 236 /* End of file: EOF is already used... */
|
||||
|
||||
#define TELOPTS(X) \
|
||||
X(BINARY, 0) /* 8-bit data path */ \
|
||||
X(ECHO, 1) /* echo */ \
|
||||
X(RCP, 2) /* prepare to reconnect */ \
|
||||
X(SGA, 3) /* suppress go ahead */ \
|
||||
X(NAMS, 4) /* approximate message size */ \
|
||||
X(STATUS, 5) /* give status */ \
|
||||
X(TM, 6) /* timing mark */ \
|
||||
X(RCTE, 7) /* remote controlled transmission and echo */ \
|
||||
X(NAOL, 8) /* negotiate about output line width */ \
|
||||
X(NAOP, 9) /* negotiate about output page size */ \
|
||||
X(NAOCRD, 10) /* negotiate about CR disposition */ \
|
||||
X(NAOHTS, 11) /* negotiate about horizontal tabstops */ \
|
||||
X(NAOHTD, 12) /* negotiate about horizontal tab disposition */ \
|
||||
X(NAOFFD, 13) /* negotiate about formfeed disposition */ \
|
||||
X(NAOVTS, 14) /* negotiate about vertical tab stops */ \
|
||||
X(NAOVTD, 15) /* negotiate about vertical tab disposition */ \
|
||||
X(NAOLFD, 16) /* negotiate about output LF disposition */ \
|
||||
X(XASCII, 17) /* extended ascic character set */ \
|
||||
X(LOGOUT, 18) /* force logout */ \
|
||||
X(BM, 19) /* byte macro */ \
|
||||
X(DET, 20) /* data entry terminal */ \
|
||||
X(SUPDUP, 21) /* supdup protocol */ \
|
||||
X(SUPDUPOUTPUT, 22) /* supdup output */ \
|
||||
X(SNDLOC, 23) /* send location */ \
|
||||
X(TTYPE, 24) /* terminal type */ \
|
||||
X(EOR, 25) /* end or record */ \
|
||||
X(TUID, 26) /* TACACS user identification */ \
|
||||
X(OUTMRK, 27) /* output marking */ \
|
||||
X(TTYLOC, 28) /* terminal location number */ \
|
||||
X(3270REGIME, 29) /* 3270 regime */ \
|
||||
X(X3PAD, 30) /* X.3 PAD */ \
|
||||
X(NAWS, 31) /* window size */ \
|
||||
X(TSPEED, 32) /* terminal speed */ \
|
||||
X(LFLOW, 33) /* remote flow control */ \
|
||||
X(LINEMODE, 34) /* Linemode option */ \
|
||||
X(XDISPLOC, 35) /* X Display Location */ \
|
||||
X(OLD_ENVIRON, 36) /* Old - Environment variables */ \
|
||||
X(AUTHENTICATION, 37) /* Authenticate */ \
|
||||
X(ENCRYPT, 38) /* Encryption option */ \
|
||||
X(NEW_ENVIRON, 39) /* New - Environment variables */ \
|
||||
X(TN3270E, 40) /* TN3270 enhancements */ \
|
||||
X(XAUTH, 41) \
|
||||
X(CHARSET, 42) /* Character set */ \
|
||||
X(RSP, 43) /* Remote serial port */ \
|
||||
X(COM_PORT_OPTION, 44) /* Com port control */ \
|
||||
X(SLE, 45) /* Suppress local echo */ \
|
||||
X(STARTTLS, 46) /* Start TLS */ \
|
||||
X(KERMIT, 47) /* Automatic Kermit file transfer */ \
|
||||
X(SEND_URL, 48) \
|
||||
X(FORWARD_X, 49) \
|
||||
X(PRAGMA_LOGON, 138) \
|
||||
X(SSPI_LOGON, 139) \
|
||||
X(PRAGMA_HEARTBEAT, 140) \
|
||||
X(EXOPL, 255) /* extended-options-list */
|
||||
|
||||
#define telnet_enum(x,y) TELOPT_##x = y,
|
||||
enum { TELOPTS(telnet_enum) dummy=0 };
|
||||
#undef telnet_enum
|
||||
|
||||
#define TELQUAL_IS 0 /* option is... */
|
||||
#define TELQUAL_SEND 1 /* send option */
|
||||
#define TELQUAL_INFO 2 /* ENVIRON: informational version of IS */
|
||||
#define BSD_VAR 1
|
||||
#define BSD_VALUE 0
|
||||
#define RFC_VAR 0
|
||||
#define RFC_VALUE 1
|
||||
|
||||
#define CR 13
|
||||
#define LF 10
|
||||
#define NUL 0
|
||||
|
||||
#define iswritable(x) ( (x) != IAC && (x) != CR )
|
||||
|
||||
static char *telopt(int opt)
|
||||
{
|
||||
#define telnet_str(x,y) case TELOPT_##x: return #x;
|
||||
switch (opt) {
|
||||
TELOPTS(telnet_str)
|
||||
default:
|
||||
return "<unknown>";
|
||||
}
|
||||
#undef telnet_str
|
||||
}
|
||||
|
||||
static void telnet_size(void *handle, int width, int height);
|
||||
|
||||
struct Opt {
|
||||
int send; /* what we initially send */
|
||||
int nsend; /* -ve send if requested to stop it */
|
||||
int ack, nak; /* +ve and -ve acknowledgements */
|
||||
int option; /* the option code */
|
||||
int index; /* index into telnet->opt_states[] */
|
||||
enum {
|
||||
REQUESTED, ACTIVE, INACTIVE, REALLY_INACTIVE
|
||||
} initial_state;
|
||||
};
|
||||
|
||||
enum {
|
||||
OPTINDEX_NAWS,
|
||||
OPTINDEX_TSPEED,
|
||||
OPTINDEX_TTYPE,
|
||||
OPTINDEX_OENV,
|
||||
OPTINDEX_NENV,
|
||||
OPTINDEX_ECHO,
|
||||
OPTINDEX_WE_SGA,
|
||||
OPTINDEX_THEY_SGA,
|
||||
OPTINDEX_WE_BIN,
|
||||
OPTINDEX_THEY_BIN,
|
||||
NUM_OPTS
|
||||
};
|
||||
|
||||
static const struct Opt o_naws =
|
||||
{ DO, DONT, WILL, WONT, TELOPT_NAWS, OPTINDEX_NAWS, REQUESTED };
|
||||
static const struct Opt o_ttype =
|
||||
{ DO, DONT, WILL, WONT, TELOPT_TTYPE, OPTINDEX_TTYPE, REQUESTED };
|
||||
static const struct Opt o_oenv =
|
||||
{ DO, DONT, WILL, WONT, TELOPT_OLD_ENVIRON, OPTINDEX_OENV, INACTIVE };
|
||||
static const struct Opt o_nenv =
|
||||
{ DO, DONT, WILL, WONT, TELOPT_NEW_ENVIRON, OPTINDEX_NENV, REQUESTED };
|
||||
static const struct Opt o_echo =
|
||||
{ WILL, WONT, DO, DONT, TELOPT_ECHO, OPTINDEX_ECHO, REQUESTED };
|
||||
static const struct Opt o_they_sga =
|
||||
{ DO, DONT, WILL, WONT, TELOPT_SGA, OPTINDEX_WE_SGA, REQUESTED };
|
||||
static const struct Opt o_we_sga =
|
||||
{ WILL, WONT, DO, DONT, TELOPT_SGA, OPTINDEX_THEY_SGA, REQUESTED };
|
||||
|
||||
static const struct Opt *const opts[] = {
|
||||
&o_echo, &o_we_sga, &o_they_sga, &o_naws, &o_ttype, &o_oenv, &o_nenv, NULL
|
||||
};
|
||||
|
||||
struct Telnet {
|
||||
int opt_states[NUM_OPTS];
|
||||
|
||||
int sb_opt, sb_len;
|
||||
unsigned char *sb_buf;
|
||||
int sb_size;
|
||||
|
||||
enum {
|
||||
TOP_LEVEL, SEENIAC, SEENWILL, SEENWONT, SEENDO, SEENDONT,
|
||||
SEENSB, SUBNEGOT, SUBNEG_IAC, SEENCR
|
||||
} state;
|
||||
|
||||
sel_wfd *net, *pty;
|
||||
|
||||
/*
|
||||
* Options we must finish processing before launching the shell
|
||||
*/
|
||||
int old_environ_done, new_environ_done, ttype_done;
|
||||
|
||||
/*
|
||||
* Ready to start shell?
|
||||
*/
|
||||
int shell_ok;
|
||||
int envvarsize;
|
||||
struct shell_data shdata;
|
||||
};
|
||||
|
||||
#define TELNET_MAX_BACKLOG 4096
|
||||
|
||||
#define SB_DELTA 1024
|
||||
|
||||
static void send_opt(Telnet *telnet, int cmd, int option)
|
||||
{
|
||||
unsigned char b[3];
|
||||
|
||||
b[0] = IAC;
|
||||
b[1] = cmd;
|
||||
b[2] = option;
|
||||
sel_write(telnet->net, b, 3);
|
||||
}
|
||||
|
||||
static void deactivate_option(Telnet *telnet, const struct Opt *o)
|
||||
{
|
||||
if (telnet->opt_states[o->index] == REQUESTED ||
|
||||
telnet->opt_states[o->index] == ACTIVE)
|
||||
send_opt(telnet, o->nsend, o->option);
|
||||
telnet->opt_states[o->index] = REALLY_INACTIVE;
|
||||
}
|
||||
|
||||
/*
|
||||
* Generate side effects of enabling or disabling an option.
|
||||
*/
|
||||
static void option_side_effects(Telnet *telnet, const struct Opt *o, int enabled)
|
||||
{
|
||||
}
|
||||
|
||||
static void activate_option(Telnet *telnet, const struct Opt *o)
|
||||
{
|
||||
if (o->option == TELOPT_NEW_ENVIRON ||
|
||||
o->option == TELOPT_OLD_ENVIRON ||
|
||||
o->option == TELOPT_TTYPE) {
|
||||
char buf[6];
|
||||
buf[0] = IAC;
|
||||
buf[1] = SB;
|
||||
buf[2] = o->option;
|
||||
buf[3] = TELQUAL_SEND;
|
||||
buf[4] = IAC;
|
||||
buf[5] = SE;
|
||||
sel_write(telnet->net, buf, 6);
|
||||
}
|
||||
option_side_effects(telnet, o, 1);
|
||||
}
|
||||
|
||||
static void done_option(Telnet *telnet, int option)
|
||||
{
|
||||
if (option == TELOPT_OLD_ENVIRON)
|
||||
telnet->old_environ_done = 1;
|
||||
else if (option == TELOPT_NEW_ENVIRON)
|
||||
telnet->new_environ_done = 1;
|
||||
else if (option == TELOPT_TTYPE)
|
||||
telnet->ttype_done = 1;
|
||||
|
||||
if (telnet->old_environ_done && telnet->new_environ_done &&
|
||||
telnet->ttype_done) {
|
||||
telnet->shell_ok = 1;
|
||||
}
|
||||
}
|
||||
|
||||
static void refused_option(Telnet *telnet, const struct Opt *o)
|
||||
{
|
||||
done_option(telnet, o->option);
|
||||
if (o->send == WILL && o->option == TELOPT_NEW_ENVIRON &&
|
||||
telnet->opt_states[o_oenv.index] == INACTIVE) {
|
||||
send_opt(telnet, WILL, TELOPT_OLD_ENVIRON);
|
||||
telnet->opt_states[o_oenv.index] = REQUESTED;
|
||||
telnet->old_environ_done = 0;
|
||||
}
|
||||
option_side_effects(telnet, o, 0);
|
||||
}
|
||||
|
||||
static void proc_rec_opt(Telnet *telnet, int cmd, int option)
|
||||
{
|
||||
const struct Opt *const *o;
|
||||
|
||||
for (o = opts; *o; o++) {
|
||||
if ((*o)->option == option && (*o)->ack == cmd) {
|
||||
switch (telnet->opt_states[(*o)->index]) {
|
||||
case REQUESTED:
|
||||
telnet->opt_states[(*o)->index] = ACTIVE;
|
||||
activate_option(telnet, *o);
|
||||
break;
|
||||
case ACTIVE:
|
||||
break;
|
||||
case INACTIVE:
|
||||
telnet->opt_states[(*o)->index] = ACTIVE;
|
||||
send_opt(telnet, (*o)->send, option);
|
||||
activate_option(telnet, *o);
|
||||
break;
|
||||
case REALLY_INACTIVE:
|
||||
send_opt(telnet, (*o)->nsend, option);
|
||||
break;
|
||||
}
|
||||
return;
|
||||
} else if ((*o)->option == option && (*o)->nak == cmd) {
|
||||
switch (telnet->opt_states[(*o)->index]) {
|
||||
case REQUESTED:
|
||||
telnet->opt_states[(*o)->index] = INACTIVE;
|
||||
refused_option(telnet, *o);
|
||||
break;
|
||||
case ACTIVE:
|
||||
telnet->opt_states[(*o)->index] = INACTIVE;
|
||||
send_opt(telnet, (*o)->nsend, option);
|
||||
option_side_effects(telnet, *o, 0);
|
||||
break;
|
||||
case INACTIVE:
|
||||
case REALLY_INACTIVE:
|
||||
break;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* If we reach here, the option was one we weren't prepared to
|
||||
* cope with. If the request was positive (WILL or DO), we send
|
||||
* a negative ack to indicate refusal. If the request was
|
||||
* negative (WONT / DONT), we must do nothing.
|
||||
*/
|
||||
if (cmd == WILL || cmd == DO)
|
||||
send_opt(telnet, (cmd == WILL ? DONT : WONT), option);
|
||||
}
|
||||
|
||||
static void process_subneg(Telnet *telnet)
|
||||
{
|
||||
int var, value, n;
|
||||
|
||||
switch (telnet->sb_opt) {
|
||||
case TELOPT_OLD_ENVIRON:
|
||||
case TELOPT_NEW_ENVIRON:
|
||||
if (telnet->sb_buf[0] == TELQUAL_IS) {
|
||||
if (telnet->sb_opt == TELOPT_NEW_ENVIRON) {
|
||||
var = RFC_VAR;
|
||||
value = RFC_VALUE;
|
||||
} else {
|
||||
if (telnet->sb_len > 1 && !(telnet->sb_buf[0] &~ 1)) {
|
||||
var = telnet->sb_buf[0];
|
||||
value = BSD_VAR ^ BSD_VALUE ^ var;
|
||||
} else {
|
||||
var = BSD_VAR;
|
||||
value = BSD_VALUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
n = 1;
|
||||
while (n < telnet->sb_len && telnet->sb_buf[n] == var) {
|
||||
int varpos, varlen, valpos, vallen;
|
||||
char *result;
|
||||
|
||||
varpos = ++n;
|
||||
while (n < telnet->sb_len && telnet->sb_buf[n] != value)
|
||||
n++;
|
||||
if (n == telnet->sb_len)
|
||||
break;
|
||||
varlen = n - varpos;
|
||||
valpos = ++n;
|
||||
while (n < telnet->sb_len && telnet->sb_buf[n] != var)
|
||||
n++;
|
||||
vallen = n - valpos;
|
||||
|
||||
result = snewn(varlen + vallen + 2, char);
|
||||
sprintf(result, "%.*s=%.*s",
|
||||
varlen, telnet->sb_buf+varpos,
|
||||
vallen, telnet->sb_buf+valpos);
|
||||
if (telnet->shdata.nenvvars >= telnet->envvarsize) {
|
||||
telnet->envvarsize = telnet->shdata.nenvvars * 3 / 2 + 16;
|
||||
telnet->shdata.envvars = sresize(telnet->shdata.envvars,
|
||||
telnet->envvarsize, char *);
|
||||
}
|
||||
telnet->shdata.envvars[telnet->shdata.nenvvars++] = result;
|
||||
}
|
||||
done_option(telnet, telnet->sb_opt);
|
||||
break;
|
||||
case TELOPT_TTYPE:
|
||||
if (telnet->sb_len >= 1 && telnet->sb_buf[0] == TELQUAL_IS) {
|
||||
telnet->shdata.termtype = snewn(5 + telnet->sb_len, char);
|
||||
strcpy(telnet->shdata.termtype, "TERM=");
|
||||
for (n = 0; n < telnet->sb_len-1; n++) {
|
||||
char c = telnet->sb_buf[n+1];
|
||||
if (c >= 'A' && c <= 'Z')
|
||||
c = c + 'a' - 'A';
|
||||
telnet->shdata.termtype[n+5] = c;
|
||||
}
|
||||
telnet->shdata.termtype[telnet->sb_len+5-1] = '\0';
|
||||
}
|
||||
done_option(telnet, telnet->sb_opt);
|
||||
break;
|
||||
case TELOPT_NAWS:
|
||||
if (telnet->sb_len == 4) {
|
||||
int w, h;
|
||||
w = (unsigned char)telnet->sb_buf[0];
|
||||
w = (w << 8) | (unsigned char)telnet->sb_buf[1];
|
||||
h = (unsigned char)telnet->sb_buf[2];
|
||||
h = (h << 8) | (unsigned char)telnet->sb_buf[3];
|
||||
pty_resize(w, h);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void telnet_from_net(Telnet *telnet, char *buf, int len)
|
||||
{
|
||||
while (len--) {
|
||||
int c = (unsigned char) *buf++;
|
||||
|
||||
switch (telnet->state) {
|
||||
case TOP_LEVEL:
|
||||
case SEENCR:
|
||||
/*
|
||||
* PuTTY sends Telnet's new line sequence (CR LF on
|
||||
* the wire) in response to the return key. We must
|
||||
* therefore treat that as equivalent to CR NUL, and
|
||||
* send CR to the pty.
|
||||
*/
|
||||
if ((c == NUL || c == '\n') && telnet->state == SEENCR)
|
||||
telnet->state = TOP_LEVEL;
|
||||
else if (c == IAC)
|
||||
telnet->state = SEENIAC;
|
||||
else {
|
||||
char cc = c;
|
||||
sel_write(telnet->pty, &cc, 1);
|
||||
|
||||
if (c == CR)
|
||||
telnet->state = SEENCR;
|
||||
else
|
||||
telnet->state = TOP_LEVEL;
|
||||
}
|
||||
break;
|
||||
case SEENIAC:
|
||||
if (c == DO)
|
||||
telnet->state = SEENDO;
|
||||
else if (c == DONT)
|
||||
telnet->state = SEENDONT;
|
||||
else if (c == WILL)
|
||||
telnet->state = SEENWILL;
|
||||
else if (c == WONT)
|
||||
telnet->state = SEENWONT;
|
||||
else if (c == SB)
|
||||
telnet->state = SEENSB;
|
||||
else if (c == DM)
|
||||
telnet->state = TOP_LEVEL;
|
||||
else {
|
||||
/* ignore everything else; print it if it's IAC */
|
||||
if (c == IAC) {
|
||||
char cc = c;
|
||||
sel_write(telnet->pty, &cc, 1);
|
||||
}
|
||||
telnet->state = TOP_LEVEL;
|
||||
}
|
||||
break;
|
||||
case SEENWILL:
|
||||
proc_rec_opt(telnet, WILL, c);
|
||||
telnet->state = TOP_LEVEL;
|
||||
break;
|
||||
case SEENWONT:
|
||||
proc_rec_opt(telnet, WONT, c);
|
||||
telnet->state = TOP_LEVEL;
|
||||
break;
|
||||
case SEENDO:
|
||||
proc_rec_opt(telnet, DO, c);
|
||||
telnet->state = TOP_LEVEL;
|
||||
break;
|
||||
case SEENDONT:
|
||||
proc_rec_opt(telnet, DONT, c);
|
||||
telnet->state = TOP_LEVEL;
|
||||
break;
|
||||
case SEENSB:
|
||||
telnet->sb_opt = c;
|
||||
telnet->sb_len = 0;
|
||||
telnet->state = SUBNEGOT;
|
||||
break;
|
||||
case SUBNEGOT:
|
||||
if (c == IAC)
|
||||
telnet->state = SUBNEG_IAC;
|
||||
else {
|
||||
subneg_addchar:
|
||||
if (telnet->sb_len >= telnet->sb_size) {
|
||||
telnet->sb_size += SB_DELTA;
|
||||
telnet->sb_buf = sresize(telnet->sb_buf, telnet->sb_size,
|
||||
unsigned char);
|
||||
}
|
||||
telnet->sb_buf[telnet->sb_len++] = c;
|
||||
telnet->state = SUBNEGOT; /* in case we came here by goto */
|
||||
}
|
||||
break;
|
||||
case SUBNEG_IAC:
|
||||
if (c != SE)
|
||||
goto subneg_addchar; /* yes, it's a hack, I know, but... */
|
||||
else {
|
||||
process_subneg(telnet);
|
||||
telnet->state = TOP_LEVEL;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Telnet *telnet_new(sel_wfd *net, sel_wfd *pty)
|
||||
{
|
||||
Telnet *telnet;
|
||||
|
||||
telnet = snew(Telnet);
|
||||
telnet->sb_buf = NULL;
|
||||
telnet->sb_size = 0;
|
||||
telnet->state = TOP_LEVEL;
|
||||
telnet->net = net;
|
||||
telnet->pty = pty;
|
||||
telnet->shdata.envvars = NULL;
|
||||
telnet->shdata.nenvvars = telnet->envvarsize = 0;
|
||||
telnet->shdata.termtype = NULL;
|
||||
|
||||
/*
|
||||
* Initialise option states.
|
||||
*/
|
||||
{
|
||||
const struct Opt *const *o;
|
||||
|
||||
for (o = opts; *o; o++) {
|
||||
telnet->opt_states[(*o)->index] = (*o)->initial_state;
|
||||
if (telnet->opt_states[(*o)->index] == REQUESTED)
|
||||
send_opt(telnet, (*o)->send, (*o)->option);
|
||||
}
|
||||
}
|
||||
|
||||
telnet->old_environ_done = 1; /* initially don't want to bother */
|
||||
telnet->new_environ_done = 0;
|
||||
telnet->ttype_done = 0;
|
||||
telnet->shell_ok = 0;
|
||||
|
||||
return telnet;
|
||||
}
|
||||
|
||||
void telnet_free(Telnet *telnet)
|
||||
{
|
||||
sfree(telnet->sb_buf);
|
||||
sfree(telnet);
|
||||
}
|
||||
|
||||
void telnet_from_pty(Telnet *telnet, char *buf, int len)
|
||||
{
|
||||
unsigned char *p, *end;
|
||||
static const unsigned char iac[2] = { IAC, IAC };
|
||||
static const unsigned char cr[2] = { CR, NUL };
|
||||
#if 0
|
||||
static const unsigned char nl[2] = { CR, LF };
|
||||
#endif
|
||||
|
||||
p = (unsigned char *)buf;
|
||||
end = (unsigned char *)(buf + len);
|
||||
while (p < end) {
|
||||
unsigned char *q = p;
|
||||
|
||||
while (p < end && iswritable(*p))
|
||||
p++;
|
||||
sel_write(telnet->net, q, p - q);
|
||||
|
||||
while (p < end && !iswritable(*p)) {
|
||||
sel_write(telnet->net, *p == IAC ? iac : cr, 2);
|
||||
p++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int telnet_shell_ok(Telnet *telnet, struct shell_data *shdata)
|
||||
{
|
||||
if (telnet->shell_ok)
|
||||
*shdata = telnet->shdata; /* structure copy */
|
||||
return telnet->shell_ok;
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
/*
|
||||
* Header declaring Telnet-handling functions.
|
||||
*/
|
||||
|
||||
#ifndef CYGTERMD_TELNET_H
|
||||
#define CYGTERMD_TELNET_H
|
||||
|
||||
#include "sel.h"
|
||||
|
||||
typedef struct Telnet Telnet;
|
||||
|
||||
struct shell_data {
|
||||
char **envvars; /* array of "VAR=value" terms */
|
||||
int nenvvars;
|
||||
char *termtype;
|
||||
};
|
||||
|
||||
/*
|
||||
* Create and destroy a Telnet structure.
|
||||
*/
|
||||
Telnet *telnet_new(sel_wfd *net, sel_wfd *pty);
|
||||
void telnet_free(Telnet *telnet);
|
||||
|
||||
/*
|
||||
* Process data read from the pty.
|
||||
*/
|
||||
void telnet_from_pty(Telnet *telnet, char *buf, int len);
|
||||
|
||||
/*
|
||||
* Process Telnet protocol data received from the network.
|
||||
*/
|
||||
void telnet_from_net(Telnet *telnet, char *buf, int len);
|
||||
|
||||
/*
|
||||
* Return true if pre-shell-startup negotiations are complete and
|
||||
* it's safe to start the shell subprocess now. On a true return,
|
||||
* also fills in the shell_data structure.
|
||||
*/
|
||||
int telnet_shell_ok(Telnet *telnet, struct shell_data *shdata);
|
||||
|
||||
#endif /* CYGTERMD_TELNET_H */
|
||||
@@ -611,9 +611,6 @@ int get_param( const char * val ) {
|
||||
#endif
|
||||
#ifdef MOD_BACKGROUNDIMAGE
|
||||
else if( !stricmp( val, "BACKGROUNDIMAGE" ) ) return GetBackgroundImageFlag() ;
|
||||
#endif
|
||||
#ifdef MOD_CYGTERM
|
||||
else if( !stricmp( val, "CYGTERM" ) ) return cygterm_get_flag() ;
|
||||
#endif
|
||||
// else if( !stricmp( val, "CONFIGBOXHEIGHT" ) ) return ConfigBoxHeight ;
|
||||
// else if( !stricmp( val, "AUTOSTORESSHKEY" ) ) return AutoStoreSSHKeyFlag ;
|
||||
@@ -1255,11 +1252,6 @@ void CreateDefaultIniFile( void ) {
|
||||
writeINI( KittyIniFile, INIT_SECTION, "conf", "yes" ) ;
|
||||
writeINI( KittyIniFile, INIT_SECTION, "#configdir", "" ) ;
|
||||
writeINI( KittyIniFile, INIT_SECTION, "#CtHelperPath", "" ) ;
|
||||
#ifndef FDJ
|
||||
writeINI( KittyIniFile, INIT_SECTION, "cygterm", "no" ) ;
|
||||
#else
|
||||
writeINI( KittyIniFile, INIT_SECTION, "cygterm", "no" ) ;
|
||||
#endif
|
||||
// writeINI( KittyIniFile, INIT_SECTION, "debug", "#no" ) ;
|
||||
writeINI( KittyIniFile, INIT_SECTION, "#downloaddir", "" ) ;
|
||||
#ifdef MOD_HYPERLINK
|
||||
@@ -4991,12 +4983,6 @@ void LoadParameters( void ) {
|
||||
if( strlen( buffer ) > 0 ) { if( existdirectory(buffer) ) SetConfigDirectory( buffer ) ; }
|
||||
}
|
||||
if( ReadParameter( INIT_SECTION, "ctrltab", buffer ) ) { if( !stricmp( buffer, "NO" ) ) SetCtrlTabFlag( 0 ) ; }
|
||||
#ifdef MOD_CYGTERM
|
||||
if( ReadParameter( INIT_SECTION, "cygterm", buffer ) ) {
|
||||
if( !stricmp( buffer, "YES" ) ) cygterm_set_flag( 1 ) ; // Broken en 0.71 On desactive
|
||||
if( !stricmp( buffer, "NO" ) ) cygterm_set_flag( 0 ) ;
|
||||
}
|
||||
#endif
|
||||
#ifdef MOD_HYPERLINK
|
||||
#ifndef MOD_NOHYPERLINK
|
||||
if( ReadParameter( INIT_SECTION, "hyperlink", buffer ) ) {
|
||||
@@ -5257,12 +5243,6 @@ void InitWinMain( void ) {
|
||||
#ifdef MOD_NOTRANSPARENCY
|
||||
sprintf( BuildVersionTime, "%s.%dn @ %s", BUILD_VERSION, BUILD_SUBVERSION, BUILD_TIME ) ;
|
||||
#endif
|
||||
#ifdef MOD_CYGTERM
|
||||
// Par defaut Cygterm est desactive, il faut l'activer dans le fichier kitty.ini
|
||||
cygterm_set_flag(0);
|
||||
#endif
|
||||
|
||||
//sprintf( BuildVersionTime, "%s.%d @ %s", "0.60", 60, "07/02/2008-22:07:31(GMT)" ) ; // Pour compilation CygWin
|
||||
|
||||
// Initialisation de la librairie de cryptage
|
||||
bcrypt_init( 0 ) ;
|
||||
@@ -5292,13 +5272,7 @@ void InitWinMain( void ) {
|
||||
LoadParameters() ;
|
||||
|
||||
// Ajoute les répertoires InitialDirectory et ConfigDirectory au PATH
|
||||
#ifdef MOD_CYGTERM
|
||||
appendPath(InitialDirectory); // Initialise dans la fonction GetInitialDirectory
|
||||
if( strcmp(InitialDirectory,ConfigDirectory) ) {
|
||||
appendPath(ConfigDirectory); // Initialise dans LoadParameters
|
||||
}
|
||||
if( getenv("KITTY_PATH")!=NULL ) { appendPath(getenv("KITTY_PATH")); }
|
||||
#endif
|
||||
|
||||
// Initialisation des shortcuts
|
||||
InitShortcuts() ;
|
||||
|
||||
|
||||
@@ -387,10 +387,6 @@ void create_settings( const char * name ) ;
|
||||
#ifdef MOD_LAUNCHER
|
||||
void InitLauncherRegistry( void ) ;
|
||||
#endif
|
||||
#ifdef MOD_CYGTERM
|
||||
void cygterm_set_flag( int flag ) ;
|
||||
int cygterm_get_flag( void ) ;
|
||||
#endif
|
||||
|
||||
int getpid(void) ;
|
||||
|
||||
|
||||
@@ -543,13 +543,6 @@ void SaveDumpConfig( FILE *fp, Conf * conf ) {
|
||||
fprintf( fp, "ScriptWait=%s\n", conf_get_str(conf,CONF_script_waitfor) ) ;
|
||||
fprintf( fp, "ScriptHalt=%s\n", conf_get_str(conf,CONF_script_halton) ) ;
|
||||
#endif
|
||||
#ifdef MOD_CYGTERM
|
||||
/* Cygterm options */
|
||||
fprintf( fp, "cygautopath=%d\n", conf_get_int(conf,CONF_cygautopath) ) ;
|
||||
fprintf( fp, "cygterm64=%d\n", conf_get_int(conf,CONF_cygterm64) ) ;
|
||||
fprintf( fp, "cygcmd=%s\n", conf_get_str(conf,CONF_cygcmd) ) ;
|
||||
fprintf( fp, "alt_metabit=%d\n", conf_get_int(conf,CONF_alt_metabit) ) ;
|
||||
#endif
|
||||
#if (defined MOD_BACKGROUNDIMAGE) && (!defined FDJ)
|
||||
/* Image Options */
|
||||
fprintf( fp, "bg_opacity=%d\n", conf_get_int(conf,CONF_bg_opacity) ) ;
|
||||
@@ -636,9 +629,6 @@ void SaveDumpConfig( FILE *fp, Conf * conf ) {
|
||||
#ifdef MOD_RECONNECT
|
||||
fprintf( fp,"AutoreconnectFlag=%d\nReconnectDelay=%d\n",AutoreconnectFlag,ReconnectDelay );
|
||||
#endif
|
||||
#ifdef MOD_CYGTERM
|
||||
fprintf( fp,"CygTermFlag=%d\n",cygterm_get_flag() );
|
||||
#endif
|
||||
#ifdef MOD_ADB
|
||||
fprintf( fp,"ADBFlag=%d\n",GetADBFlag() );
|
||||
#endif
|
||||
|
||||
@@ -374,13 +374,6 @@ void save_open_settings_forced(char *filename, Conf *conf) {
|
||||
write_setting_s_forced(sesskey, "HyperlinkRegularExpression", conf_get_str(conf, CONF_url_regex));
|
||||
#endif
|
||||
#endif
|
||||
#ifdef MOD_CYGTERM
|
||||
//if (do_host)
|
||||
write_setting_i_forced(sesskey, "CygtermAltMetabit", conf_get_int(conf, CONF_alt_metabit));
|
||||
write_setting_i_forced(sesskey, "CygtermAutoPath", conf_get_int(conf, CONF_cygautopath) );
|
||||
write_setting_i_forced(sesskey, "Cygterm64", conf_get_int(conf, CONF_cygterm64));
|
||||
write_setting_s_forced(sesskey, "CygtermCommand", conf_get_str(conf, CONF_cygcmd) );
|
||||
#endif
|
||||
#ifdef MOD_ZMODEM
|
||||
write_setting_filename_forced(sesskey, "rzCommand", conf_get_filename(conf, CONF_rzcommand) );
|
||||
write_setting_s_forced(sesskey, "rzOptions", conf_get_str(conf, CONF_rzoptions) );
|
||||
@@ -1005,12 +998,6 @@ void load_open_settings_forced(char *filename, Conf *conf) {
|
||||
gpps_forced(sesskey, "HyperlinkRegularExpression", urlhack_default_regex, conf, CONF_url_regex);
|
||||
#endif
|
||||
#endif
|
||||
#ifdef MOD_CYGTERM
|
||||
gppi_forced(sesskey, "CygtermAltMetabit", 0, conf, CONF_alt_metabit);
|
||||
gppi_forced(sesskey, "CygtermAutoPath", 1, conf, CONF_cygautopath );
|
||||
gppi_forced(sesskey, "Cygterm64", 0, conf, CONF_cygterm64);
|
||||
gpps_forced(sesskey, "CygtermCommand", "", conf, CONF_cygcmd );
|
||||
#endif
|
||||
#ifdef MOD_ZMODEM
|
||||
gppfile_forced(sesskey, "rzCommand", conf, CONF_rzcommand );
|
||||
gpps_forced(sesskey, "rzOptions", "-e -v", conf, CONF_rzoptions );
|
||||
|
||||
Reference in New Issue
Block a user