зеркало из https://github.com/github/putty.git
Support for PuTTY-style command-line arguments in Unix PuTTY. I
think it's now actually usable as a day-to-day SSH client, even if things like the Event Log are still missing. So I call that a decent lunch hour's work :-) [originally from svn r3034]
This commit is contained in:
Родитель
9e59f4534b
Коммит
62844b4590
2
Recipe
2
Recipe
|
@ -154,7 +154,7 @@ puttygen : [G] puttygen sshrsag sshdssg sshprime sshdes sshbn sshmd5 version
|
|||
|
||||
pterm : [X] pterm terminal wcwidth uxucs uxmisc tree234 misc ldisc ldiscucs
|
||||
+ logging uxprint settings pty uxsel be_none uxstore signal CHARSET
|
||||
+ ptermm
|
||||
+ cmdline ptermm
|
||||
putty : [X] pterm terminal wcwidth uxucs uxmisc tree234 misc ldisc ldiscucs
|
||||
+ logging uxprint settings pty uxsel be_all uxstore signal CHARSET
|
||||
+ uxputty NONSSH UXSSH UXMISC logging ux_x11 UXCFG
|
||||
|
|
32
cmdline.c
32
cmdline.c
|
@ -111,6 +111,7 @@ static int cmdline_check_unavailable(int flag, char *p)
|
|||
#define RETURN(x) do { \
|
||||
if ((x) == 2 && !value) return -2; \
|
||||
ret = x; \
|
||||
if (need_save < 0) return x; \
|
||||
} while (0)
|
||||
|
||||
int cmdline_process_param(char *p, char *value, int need_save, Config *cfg)
|
||||
|
@ -126,7 +127,7 @@ int cmdline_process_param(char *p, char *value, int need_save, Config *cfg)
|
|||
}
|
||||
if (!strcmp(p, "-ssh")) {
|
||||
RETURN(1);
|
||||
UNAVAILABLE_IN(TOOLTYPE_FILETRANSFER);
|
||||
UNAVAILABLE_IN(TOOLTYPE_FILETRANSFER | TOOLTYPE_NONNETWORK);
|
||||
SAVEABLE(0);
|
||||
default_protocol = cfg->protocol = PROT_SSH;
|
||||
default_port = cfg->port = 22;
|
||||
|
@ -134,7 +135,7 @@ int cmdline_process_param(char *p, char *value, int need_save, Config *cfg)
|
|||
}
|
||||
if (!strcmp(p, "-telnet")) {
|
||||
RETURN(1);
|
||||
UNAVAILABLE_IN(TOOLTYPE_FILETRANSFER);
|
||||
UNAVAILABLE_IN(TOOLTYPE_FILETRANSFER | TOOLTYPE_NONNETWORK);
|
||||
SAVEABLE(0);
|
||||
default_protocol = cfg->protocol = PROT_TELNET;
|
||||
default_port = cfg->port = 23;
|
||||
|
@ -142,7 +143,7 @@ int cmdline_process_param(char *p, char *value, int need_save, Config *cfg)
|
|||
}
|
||||
if (!strcmp(p, "-rlogin")) {
|
||||
RETURN(1);
|
||||
UNAVAILABLE_IN(TOOLTYPE_FILETRANSFER);
|
||||
UNAVAILABLE_IN(TOOLTYPE_FILETRANSFER | TOOLTYPE_NONNETWORK);
|
||||
SAVEABLE(0);
|
||||
default_protocol = cfg->protocol = PROT_RLOGIN;
|
||||
default_port = cfg->port = 513;
|
||||
|
@ -150,7 +151,7 @@ int cmdline_process_param(char *p, char *value, int need_save, Config *cfg)
|
|||
}
|
||||
if (!strcmp(p, "-raw")) {
|
||||
RETURN(1);
|
||||
UNAVAILABLE_IN(TOOLTYPE_FILETRANSFER);
|
||||
UNAVAILABLE_IN(TOOLTYPE_FILETRANSFER | TOOLTYPE_NONNETWORK);
|
||||
SAVEABLE(0);
|
||||
default_protocol = cfg->protocol = PROT_RAW;
|
||||
}
|
||||
|
@ -160,6 +161,7 @@ int cmdline_process_param(char *p, char *value, int need_save, Config *cfg)
|
|||
}
|
||||
if (!strcmp(p, "-l")) {
|
||||
RETURN(2);
|
||||
UNAVAILABLE_IN(TOOLTYPE_NONNETWORK);
|
||||
SAVEABLE(0);
|
||||
strncpy(cfg->username, value, sizeof(cfg->username));
|
||||
cfg->username[sizeof(cfg->username) - 1] = '\0';
|
||||
|
@ -168,7 +170,7 @@ int cmdline_process_param(char *p, char *value, int need_save, Config *cfg)
|
|||
char *fwd, *ptr, *q, *qq;
|
||||
int i=0;
|
||||
RETURN(2);
|
||||
UNAVAILABLE_IN(TOOLTYPE_FILETRANSFER);
|
||||
UNAVAILABLE_IN(TOOLTYPE_FILETRANSFER | TOOLTYPE_NONNETWORK);
|
||||
SAVEABLE(0);
|
||||
fwd = value;
|
||||
ptr = cfg->portfwd;
|
||||
|
@ -213,7 +215,7 @@ int cmdline_process_param(char *p, char *value, int need_save, Config *cfg)
|
|||
int c, d;
|
||||
|
||||
RETURN(2);
|
||||
UNAVAILABLE_IN(TOOLTYPE_FILETRANSFER);
|
||||
UNAVAILABLE_IN(TOOLTYPE_FILETRANSFER | TOOLTYPE_NONNETWORK);
|
||||
SAVEABLE(0);
|
||||
|
||||
filename = value;
|
||||
|
@ -243,11 +245,13 @@ int cmdline_process_param(char *p, char *value, int need_save, Config *cfg)
|
|||
}
|
||||
if (!strcmp(p, "-P")) {
|
||||
RETURN(2);
|
||||
UNAVAILABLE_IN(TOOLTYPE_NONNETWORK);
|
||||
SAVEABLE(1); /* lower priority than -ssh,-telnet */
|
||||
cfg->port = atoi(value);
|
||||
}
|
||||
if (!strcmp(p, "-pw")) {
|
||||
RETURN(2);
|
||||
UNAVAILABLE_IN(TOOLTYPE_NONNETWORK);
|
||||
cmdline_password = value;
|
||||
ssh_get_line = cmdline_get_line;
|
||||
ssh_getline_pw_only = TRUE;
|
||||
|
@ -255,62 +259,66 @@ int cmdline_process_param(char *p, char *value, int need_save, Config *cfg)
|
|||
|
||||
if (!strcmp(p, "-A")) {
|
||||
RETURN(1);
|
||||
UNAVAILABLE_IN(TOOLTYPE_FILETRANSFER);
|
||||
UNAVAILABLE_IN(TOOLTYPE_FILETRANSFER | TOOLTYPE_NONNETWORK);
|
||||
SAVEABLE(0);
|
||||
cfg->agentfwd = 1;
|
||||
}
|
||||
if (!strcmp(p, "-a")) {
|
||||
RETURN(1);
|
||||
UNAVAILABLE_IN(TOOLTYPE_FILETRANSFER);
|
||||
UNAVAILABLE_IN(TOOLTYPE_FILETRANSFER | TOOLTYPE_NONNETWORK);
|
||||
SAVEABLE(0);
|
||||
cfg->agentfwd = 0;
|
||||
}
|
||||
|
||||
if (!strcmp(p, "-X")) {
|
||||
RETURN(1);
|
||||
UNAVAILABLE_IN(TOOLTYPE_FILETRANSFER);
|
||||
UNAVAILABLE_IN(TOOLTYPE_FILETRANSFER | TOOLTYPE_NONNETWORK);
|
||||
SAVEABLE(0);
|
||||
cfg->x11_forward = 1;
|
||||
}
|
||||
if (!strcmp(p, "-x")) {
|
||||
RETURN(1);
|
||||
UNAVAILABLE_IN(TOOLTYPE_FILETRANSFER);
|
||||
UNAVAILABLE_IN(TOOLTYPE_FILETRANSFER | TOOLTYPE_NONNETWORK);
|
||||
SAVEABLE(0);
|
||||
cfg->x11_forward = 0;
|
||||
}
|
||||
|
||||
if (!strcmp(p, "-t")) {
|
||||
RETURN(1);
|
||||
UNAVAILABLE_IN(TOOLTYPE_FILETRANSFER);
|
||||
UNAVAILABLE_IN(TOOLTYPE_FILETRANSFER | TOOLTYPE_NONNETWORK);
|
||||
SAVEABLE(0);
|
||||
cfg->nopty = 0;
|
||||
}
|
||||
if (!strcmp(p, "-T")) {
|
||||
RETURN(1);
|
||||
UNAVAILABLE_IN(TOOLTYPE_FILETRANSFER);
|
||||
UNAVAILABLE_IN(TOOLTYPE_FILETRANSFER | TOOLTYPE_NONNETWORK);
|
||||
SAVEABLE(0);
|
||||
cfg->nopty = 1;
|
||||
}
|
||||
|
||||
if (!strcmp(p, "-C")) {
|
||||
RETURN(1);
|
||||
UNAVAILABLE_IN(TOOLTYPE_NONNETWORK);
|
||||
SAVEABLE(0);
|
||||
cfg->compression = 1;
|
||||
}
|
||||
|
||||
if (!strcmp(p, "-1")) {
|
||||
RETURN(1);
|
||||
UNAVAILABLE_IN(TOOLTYPE_NONNETWORK);
|
||||
SAVEABLE(0);
|
||||
cfg->sshprot = 0; /* ssh protocol 1 only */
|
||||
}
|
||||
if (!strcmp(p, "-2")) {
|
||||
RETURN(1);
|
||||
UNAVAILABLE_IN(TOOLTYPE_NONNETWORK);
|
||||
SAVEABLE(0);
|
||||
cfg->sshprot = 3; /* ssh protocol 2 only */
|
||||
}
|
||||
|
||||
if (!strcmp(p, "-i")) {
|
||||
RETURN(2);
|
||||
UNAVAILABLE_IN(TOOLTYPE_NONNETWORK);
|
||||
SAVEABLE(0);
|
||||
cfg->keyfile = filename_from_str(value);
|
||||
}
|
||||
|
|
1
putty.h
1
putty.h
|
@ -773,6 +773,7 @@ int cmdline_process_param(char *, char *, int, Config *);
|
|||
void cmdline_run_saved(Config *);
|
||||
extern char *cmdline_password;
|
||||
#define TOOLTYPE_FILETRANSFER 1
|
||||
#define TOOLTYPE_NONNETWORK 2
|
||||
extern int cmdline_tooltype;
|
||||
|
||||
void cmdline_error(char *, ...);
|
||||
|
|
|
@ -1911,8 +1911,6 @@ int do_config_box(const char *title, Config *cfg)
|
|||
struct selparam *selparams = NULL;
|
||||
int nselparams = 0, selparamsize = 0;
|
||||
|
||||
do_defaults(NULL, cfg);
|
||||
|
||||
dlg_init(&dp);
|
||||
|
||||
{
|
||||
|
|
33
unix/pterm.c
33
unix/pterm.c
|
@ -1916,6 +1916,17 @@ void modalfatalbox(char *p, ...)
|
|||
exit(1);
|
||||
}
|
||||
|
||||
void cmdline_error(char *p, ...)
|
||||
{
|
||||
va_list ap;
|
||||
fprintf(stderr, "plink: ");
|
||||
va_start(ap, p);
|
||||
vfprintf(stderr, p, ap);
|
||||
va_end(ap);
|
||||
fputc('\n', stderr);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
char *get_x_display(void *frontend)
|
||||
{
|
||||
return gdk_get_display();
|
||||
|
@ -1988,6 +1999,20 @@ int do_cmdline(int argc, char **argv, int do_everything, Config *cfg)
|
|||
char *val;
|
||||
while (--argc > 0) {
|
||||
char *p = *++argv;
|
||||
int ret;
|
||||
|
||||
ret = cmdline_process_param(p, (argc > 1 ? argv[1] : NULL),
|
||||
do_everything ? 1 : -1, cfg);
|
||||
|
||||
if (ret == -2) {
|
||||
cmdline_error("option \"%s\" requires an argument", p);
|
||||
} else if (ret == 2) {
|
||||
--argc, ++argv; /* skip next argument */
|
||||
continue;
|
||||
} else if (ret == 1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!strcmp(p, "-fn") || !strcmp(p, "-font")) {
|
||||
EXPECTS_ARG;
|
||||
SECOND_PASS_ONLY;
|
||||
|
@ -2135,6 +2160,10 @@ int do_cmdline(int argc, char **argv, int do_everything, Config *cfg)
|
|||
help(stdout);
|
||||
exit(0);
|
||||
|
||||
} else if(p[0] != '-' && (!do_everything ||
|
||||
process_nonoption_arg(p, cfg))) {
|
||||
/* do nothing */
|
||||
|
||||
} else {
|
||||
err = 1;
|
||||
fprintf(stderr, "pterm: unrecognized option '%s'\n", p);
|
||||
|
@ -2257,7 +2286,9 @@ int pt_main(int argc, char **argv)
|
|||
if (do_cmdline(argc, argv, 1, &inst->cfg))
|
||||
exit(1); /* post-defaults, do everything */
|
||||
|
||||
if (!cfgbox(&inst->cfg))
|
||||
cmdline_run_saved(&inst->cfg);
|
||||
|
||||
if (!*inst->cfg.host && !cfgbox(&inst->cfg))
|
||||
exit(0); /* config box hit Cancel */
|
||||
|
||||
inst->fonts[0] = gdk_font_load(inst->cfg.font.name);
|
||||
|
|
|
@ -16,6 +16,11 @@ int cfgbox(Config *cfg)
|
|||
return 1; /* no-op in pterm */
|
||||
}
|
||||
|
||||
int process_nonoption_arg(char *arg, Config *cfg)
|
||||
{
|
||||
return 0; /* pterm doesn't have any. */
|
||||
}
|
||||
|
||||
char *make_default_wintitle(char *hostname)
|
||||
{
|
||||
return dupstr("pterm");
|
||||
|
@ -26,6 +31,8 @@ int main(int argc, char **argv)
|
|||
extern int pt_main(int argc, char **argv);
|
||||
extern void pty_pre_init(void); /* declared in pty.c */
|
||||
|
||||
cmdline_tooltype = TOOLTYPE_NONNETWORK;
|
||||
|
||||
pty_pre_init();
|
||||
|
||||
return pt_main(argc, argv);
|
||||
|
|
|
@ -60,6 +60,7 @@ void *get_window(void *frontend); /* void * to avoid depending on gtk.h */
|
|||
|
||||
/* Things pterm.c needs from {ptermm,uxputty}.c */
|
||||
char *make_default_wintitle(char *hostname);
|
||||
int process_nonoption_arg(char *arg, Config *cfg);
|
||||
|
||||
/* Things uxstore.c needs from pterm.c */
|
||||
char *x_get_default(const char *key);
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include <unistd.h>
|
||||
|
@ -72,17 +73,6 @@
|
|||
* - About (and uxcfg.c must also supply the about box)
|
||||
*/
|
||||
|
||||
void cmdline_error(char *p, ...)
|
||||
{
|
||||
va_list ap;
|
||||
fprintf(stderr, "plink: ");
|
||||
va_start(ap, p);
|
||||
vfprintf(stderr, p, ap);
|
||||
va_end(ap);
|
||||
fputc('\n', stderr);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Clean up and exit.
|
||||
*/
|
||||
|
@ -144,6 +134,61 @@ int cfgbox(Config *cfg)
|
|||
return do_config_box("PuTTY Configuration", cfg);
|
||||
}
|
||||
|
||||
static int got_host = 0;
|
||||
|
||||
int process_nonoption_arg(char *arg, Config *cfg)
|
||||
{
|
||||
char *p, *q = arg;
|
||||
|
||||
if (got_host) {
|
||||
/*
|
||||
* If we already have a host name, treat this argument as a
|
||||
* port number. NB we have to treat this as a saved -P
|
||||
* argument, so that it will be deferred until it's a good
|
||||
* moment to run it.
|
||||
*/
|
||||
int ret = cmdline_process_param("-P", arg, 1, cfg);
|
||||
assert(ret == 2);
|
||||
} else if (!strncmp(q, "telnet:", 7)) {
|
||||
/*
|
||||
* If the hostname starts with "telnet:",
|
||||
* set the protocol to Telnet and process
|
||||
* the string as a Telnet URL.
|
||||
*/
|
||||
char c;
|
||||
|
||||
q += 7;
|
||||
if (q[0] == '/' && q[1] == '/')
|
||||
q += 2;
|
||||
cfg->protocol = PROT_TELNET;
|
||||
p = q;
|
||||
while (*p && *p != ':' && *p != '/')
|
||||
p++;
|
||||
c = *p;
|
||||
if (*p)
|
||||
*p++ = '\0';
|
||||
if (c == ':')
|
||||
cfg->port = atoi(p);
|
||||
else
|
||||
cfg->port = -1;
|
||||
strncpy(cfg->host, q, sizeof(cfg->host) - 1);
|
||||
cfg->host[sizeof(cfg->host) - 1] = '\0';
|
||||
got_host = 1;
|
||||
} else {
|
||||
/*
|
||||
* Otherwise, treat this argument as a host name.
|
||||
*/
|
||||
while (*p && !isspace((unsigned char)*p))
|
||||
p++;
|
||||
if (*p)
|
||||
*p++ = '\0';
|
||||
strncpy(cfg->host, q, sizeof(cfg->host) - 1);
|
||||
cfg->host[sizeof(cfg->host) - 1] = '\0';
|
||||
got_host = 1;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
char *make_default_wintitle(char *hostname)
|
||||
{
|
||||
return dupcat(hostname, " - PuTTY", NULL);
|
||||
|
|
Загрузка…
Ссылка в новой задаче