`ssh-log-pw-blank': known password fields are now omitted from SSH packet logs
[sgt/putty] / unix / uxputty.c
CommitLineData
1d009ae7 1/*
2 * Unix PuTTY main program.
3 */
4
5#include <stdio.h>
46a3419b 6#include <ctype.h>
5bf9955d 7#include <stdlib.h>
1d009ae7 8#include <assert.h>
1d009ae7 9#include <unistd.h>
10
11#include "putty.h"
12#include "storage.h"
13
14/*
1d009ae7 15 * Clean up and exit.
16 */
17void cleanup_exit(int code)
18{
19 /*
20 * Clean up.
21 */
22 sk_cleanup();
23 random_save_seed();
24 exit(code);
25}
26
1d009ae7 27Backend *select_backend(Config *cfg)
28{
29 int i;
30 Backend *back = NULL;
31 for (i = 0; backends[i].backend != NULL; i++)
32 if (backends[i].protocol == cfg->protocol) {
33 back = backends[i].backend;
34 break;
35 }
36 assert(back != NULL);
37 return back;
38}
39
40int cfgbox(Config *cfg)
41{
56b9b9a7 42 return do_config_box("PuTTY Configuration", cfg, 0);
1d009ae7 43}
44
46a3419b 45static int got_host = 0;
46
56801e3d 47const int use_event_log = 1, new_session = 1, saved_sessions = 1;
8eed910d 48
46a3419b 49int process_nonoption_arg(char *arg, Config *cfg)
50{
51 char *p, *q = arg;
52
53 if (got_host) {
54 /*
55 * If we already have a host name, treat this argument as a
56 * port number. NB we have to treat this as a saved -P
57 * argument, so that it will be deferred until it's a good
58 * moment to run it.
59 */
60 int ret = cmdline_process_param("-P", arg, 1, cfg);
61 assert(ret == 2);
62 } else if (!strncmp(q, "telnet:", 7)) {
63 /*
64 * If the hostname starts with "telnet:",
65 * set the protocol to Telnet and process
66 * the string as a Telnet URL.
67 */
68 char c;
69
70 q += 7;
71 if (q[0] == '/' && q[1] == '/')
72 q += 2;
73 cfg->protocol = PROT_TELNET;
74 p = q;
75 while (*p && *p != ':' && *p != '/')
76 p++;
77 c = *p;
78 if (*p)
79 *p++ = '\0';
80 if (c == ':')
81 cfg->port = atoi(p);
82 else
83 cfg->port = -1;
84 strncpy(cfg->host, q, sizeof(cfg->host) - 1);
85 cfg->host[sizeof(cfg->host) - 1] = '\0';
86 got_host = 1;
87 } else {
88 /*
89 * Otherwise, treat this argument as a host name.
90 */
320cb4be 91 p = arg;
46a3419b 92 while (*p && !isspace((unsigned char)*p))
93 p++;
94 if (*p)
95 *p++ = '\0';
96 strncpy(cfg->host, q, sizeof(cfg->host) - 1);
97 cfg->host[sizeof(cfg->host) - 1] = '\0';
98 got_host = 1;
99 }
100 return 1;
101}
102
10705014 103char *make_default_wintitle(char *hostname)
104{
105 return dupcat(hostname, " - PuTTY", NULL);
106}
107
1d009ae7 108int main(int argc, char **argv)
109{
110 extern int pt_main(int argc, char **argv);
111 sk_init();
112 flags = FLAG_VERBOSE | FLAG_INTERACTIVE;
113 default_protocol = be_default_protocol;
114 /* Find the appropriate default port. */
115 {
116 int i;
117 default_port = 0; /* illegal */
118 for (i = 0; backends[i].backend != NULL; i++)
119 if (backends[i].protocol == default_protocol) {
120 default_port = backends[i].backend->default_port;
121 break;
122 }
123 }
124 return pt_main(argc, argv);
125}