New option to allow use of the local OS username for login to the remote side
[u/mdw/putty] / settings.c
index a175e4d..7ecd561 100644 (file)
@@ -75,6 +75,25 @@ Backend *backend_from_proto(int proto)
     return NULL;
 }
 
+int get_remote_username(Config *cfg, char *user, size_t len)
+{
+    if (*cfg->username) {
+       strncpy(user, cfg->username, len);
+       user[len-1] = '\0';
+    } else {
+       if (cfg->username_from_env) {
+           /* Use local username. */
+           char *luser = get_username();
+           strncpy(user, luser, len);
+           user[len-1] = '\0';
+           sfree(luser);
+       } else {
+           *user = '\0';
+       }
+    }
+    return (*user != '\0');
+}
+
 static void gpps(void *handle, const char *name, const char *def,
                 char *val, int len)
 {
@@ -316,11 +335,13 @@ void save_open_settings(void *sesskey, Config *cfg)
     write_setting_s(sesskey, "ProxyTelnetCommand", cfg->proxy_telnet_command);
     wmap(sesskey, "Environment", cfg->environmt, lenof(cfg->environmt));
     write_setting_s(sesskey, "UserName", cfg->username);
+    write_setting_i(sesskey, "UserNameFromEnvironment", cfg->username_from_env);
     write_setting_s(sesskey, "LocalUserName", cfg->localusername);
     write_setting_i(sesskey, "NoPTY", cfg->nopty);
     write_setting_i(sesskey, "Compression", cfg->compression);
     write_setting_i(sesskey, "TryAgent", cfg->tryagent);
     write_setting_i(sesskey, "AgentFwd", cfg->agentfwd);
+    write_setting_i(sesskey, "GssapiFwd", cfg->gssapifwd);
     write_setting_i(sesskey, "ChangeUsername", cfg->change_username);
     wprefs(sesskey, "Cipher", ciphernames, CIPHER_MAX,
           cfg->ssh_cipherlist);
@@ -330,6 +351,7 @@ void save_open_settings(void *sesskey, Config *cfg)
     write_setting_i(sesskey, "SshNoAuth", cfg->ssh_no_userauth);
     write_setting_i(sesskey, "AuthTIS", cfg->try_tis_auth);
     write_setting_i(sesskey, "AuthKI", cfg->try_ki_auth);
+    write_setting_i(sesskey, "AuthGSSAPI", cfg->try_gssapi_auth);
     write_setting_i(sesskey, "SshNoShell", cfg->ssh_no_shell);
     write_setting_i(sesskey, "SshProt", cfg->sshprot);
     write_setting_s(sesskey, "LogHost", cfg->loghost);
@@ -444,6 +466,7 @@ void save_open_settings(void *sesskey, Config *cfg)
     write_setting_i(sesskey, "X11Forward", cfg->x11_forward);
     write_setting_s(sesskey, "X11Display", cfg->x11_display);
     write_setting_i(sesskey, "X11AuthType", cfg->x11_auth);
+    write_setting_filename(sesskey, "X11AuthFile", cfg->xauthfile);
     write_setting_i(sesskey, "LocalPortAcceptAll", cfg->lport_acceptall);
     write_setting_i(sesskey, "RemotePortAcceptAll", cfg->rport_acceptall);
     wmap(sesskey, "PortForwardings", cfg->portfwd, lenof(cfg->portfwd));
@@ -582,6 +605,7 @@ void load_open_settings(void *sesskey, Config *cfg)
         cfg->proxy_telnet_command, sizeof(cfg->proxy_telnet_command));
     gppmap(sesskey, "Environment", "", cfg->environmt, lenof(cfg->environmt));
     gpps(sesskey, "UserName", "", cfg->username, sizeof(cfg->username));
+    gppi(sesskey, "UserNameFromEnvironment", 0, &cfg->username_from_env);
     gpps(sesskey, "LocalUserName", "", cfg->localusername,
         sizeof(cfg->localusername));
     gppi(sesskey, "NoPTY", 0, &cfg->nopty);
@@ -589,6 +613,7 @@ void load_open_settings(void *sesskey, Config *cfg)
     gppi(sesskey, "TryAgent", 1, &cfg->tryagent);
     gppi(sesskey, "AgentFwd", 0, &cfg->agentfwd);
     gppi(sesskey, "ChangeUsername", 0, &cfg->change_username);
+    gppi(sesskey, "GssapiFwd", 0, &cfg->gssapifwd);
     gprefs(sesskey, "Cipher", "\0",
           ciphernames, CIPHER_MAX, cfg->ssh_cipherlist);
     {
@@ -614,6 +639,7 @@ void load_open_settings(void *sesskey, Config *cfg)
     gppi(sesskey, "SshNoAuth", 0, &cfg->ssh_no_userauth);
     gppi(sesskey, "AuthTIS", 0, &cfg->try_tis_auth);
     gppi(sesskey, "AuthKI", 1, &cfg->try_ki_auth);
+    gppi(sesskey, "AuthGSSAPI", 1, &cfg->try_gssapi_auth);
     gppi(sesskey, "SshNoShell", 0, &cfg->ssh_no_shell);
     gppfile(sesskey, "PublicKeyFile", &cfg->keyfile);
     gpps(sesskey, "RemoteCommand", "", cfg->remote_cmd,
@@ -771,6 +797,7 @@ void load_open_settings(void *sesskey, Config *cfg)
     gpps(sesskey, "X11Display", "", cfg->x11_display,
         sizeof(cfg->x11_display));
     gppi(sesskey, "X11AuthType", X11_MIT, &cfg->x11_auth);
+    gppfile(sesskey, "X11AuthFile", &cfg->xauthfile);
 
     gppi(sesskey, "LocalPortAcceptAll", 0, &cfg->lport_acceptall);
     gppi(sesskey, "RemotePortAcceptAll", 0, &cfg->rport_acceptall);