]> asedeno.scripts.mit.edu Git - PuTTY.git/blobdiff - cmdline.c
first pass
[PuTTY.git] / cmdline.c
index 9c873503d15913964ff5ab862e837ba6520cfeba..f288ed629ee837272998ec554cb45e3bbfbc3552 100644 (file)
--- a/cmdline.c
+++ b/cmdline.c
@@ -44,15 +44,15 @@ struct cmdline_saved_param_set {
  */
 static struct cmdline_saved_param_set saves[NPRIORITIES];
 
-static void cmdline_save_param(char *p, char *value, int pri)
+static void cmdline_save_param(const char *p, const char *value, int pri)
 {
     if (saves[pri].nsaved >= saves[pri].savesize) {
        saves[pri].savesize = saves[pri].nsaved + 32;
        saves[pri].params = sresize(saves[pri].params, saves[pri].savesize,
                                    struct cmdline_saved_param);
     }
-    saves[pri].params[saves[pri].nsaved].p = p;
-    saves[pri].params[saves[pri].nsaved].value = value;
+    saves[pri].params[saves[pri].nsaved].p = dupstr(p);
+    saves[pri].params[saves[pri].nsaved].value = dupstr(value);
     saves[pri].nsaved++;
 }
 
@@ -63,7 +63,7 @@ void cmdline_cleanup(void)
     int pri;
 
     if (cmdline_password) {
-       memset(cmdline_password, 0, strlen(cmdline_password));
+       smemclr(cmdline_password, strlen(cmdline_password));
        sfree(cmdline_password);
        cmdline_password = NULL;
     }
@@ -85,8 +85,8 @@ void cmdline_cleanup(void)
  * return means that we aren't capable of processing the prompt and
  * someone else should do it.
  */
-int cmdline_get_passwd_input(prompts_t *p, unsigned char *in, int inlen) {
-
+int cmdline_get_passwd_input(prompts_t *p, const unsigned char *in, int inlen)
+{
     static int tried_once = 0;
 
     /*
@@ -105,15 +105,12 @@ int cmdline_get_passwd_input(prompts_t *p, unsigned char *in, int inlen) {
     if (tried_once)
        return 0;
 
-    strncpy(p->prompts[0]->result, cmdline_password,
-           p->prompts[0]->result_len);
-    p->prompts[0]->result[p->prompts[0]->result_len-1] = '\0';
-    memset(cmdline_password, 0, strlen(cmdline_password));
+    prompt_set_result(p->prompts[0], cmdline_password);
+    smemclr(cmdline_password, strlen(cmdline_password));
     sfree(cmdline_password);
     cmdline_password = NULL;
     tried_once = 1;
     return 1;
-
 }
 
 /*
@@ -128,7 +125,7 @@ int cmdline_get_passwd_input(prompts_t *p, unsigned char *in, int inlen) {
  */
 int cmdline_tooltype = 0;
 
-static int cmdline_check_unavailable(int flag, char *p)
+static int cmdline_check_unavailable(int flag, const char *p)
 {
     if (cmdline_tooltype & flag) {
        cmdline_error("option \"%s\" not available in this tool", p);
@@ -162,7 +159,8 @@ static int cmdline_check_unavailable(int flag, char *p)
     if (need_save < 0) return x; \
 } while (0)
 
-int cmdline_process_param(char *p, char *value, int need_save, Conf *conf)
+int cmdline_process_param(const char *p, char *value,
+                          int need_save, Conf *conf)
 {
     int ret = 0;
 
@@ -239,6 +237,21 @@ int cmdline_process_param(char *p, char *value, int need_save, Conf *conf)
        SAVEABLE(0);
        conf_set_str(conf, CONF_loghost, value);
     }
+    if (!strcmp(p, "-hostkey")) {
+        char *dup;
+       RETURN(2);
+       UNAVAILABLE_IN(TOOLTYPE_NONNETWORK);
+       SAVEABLE(0);
+        dup = dupstr(value);
+        if (!validate_manual_hostkey(dup)) {
+            cmdline_error("'%s' is not a valid format for a manual host "
+                          "key specification", value);
+            sfree(dup);
+            return ret;
+        }
+       conf_set_str_str(conf, CONF_ssh_manual_hostkeys, dup, "");
+        sfree(dup);
+    }
     if ((!strcmp(p, "-L") || !strcmp(p, "-R") || !strcmp(p, "-D"))) {
        char type, *q, *qq, *key, *val;
        RETURN(2);
@@ -264,9 +277,9 @@ int cmdline_process_param(char *p, char *value, int need_save, Conf *conf)
 
             type = p[1];               /* 'L' or 'R' */
 
-           q = qq = strchr(value, ':');
+           q = qq = host_strchr(value, ':');
            while (qq) {
-               char *qqq = strchr(qq+1, ':');
+               char *qqq = host_strchr(qq+1, ':');
                if (qqq)
                    q = qq;
                qq = qqq;
@@ -278,7 +291,7 @@ int cmdline_process_param(char *p, char *value, int need_save, Conf *conf)
                return ret;
            }
 
-           key = dupprintf("%c%.*s", type, q - value, value);
+           key = dupprintf("%c%.*s", type, (int)(q - value), value);
            val = dupstr(q+1);
        } else {
             /*
@@ -304,19 +317,20 @@ int cmdline_process_param(char *p, char *value, int need_save, Conf *conf)
        UNAVAILABLE_IN(TOOLTYPE_FILETRANSFER | TOOLTYPE_NONNETWORK);
        SAVEABLE(0);
 
-       portp = strchr(value, ':');
+       portp = host_strchr(value, ':');
        if (!portp) {
            cmdline_error("-nc expects argument of form 'host:port'");
            return ret;
        }
 
-       host = dupprintf("%.*s", portp - value, value);
+       host = dupprintf("%.*s", (int)(portp - value), value);
        conf_set_str(conf, CONF_ssh_nc_host, host);
        conf_set_int(conf, CONF_ssh_nc_port, atoi(portp + 1));
         sfree(host);
     }
     if (!strcmp(p, "-m")) {
-       char *filename, *command;
+       const char *filename;
+        char *command;
        int cmdlen, cmdsize;
        FILE *fp;
        int c, d;
@@ -371,7 +385,7 @@ int cmdline_process_param(char *p, char *value, int need_save, Conf *conf)
            /* Assuming that `value' is directly from argv, make a good faith
             * attempt to trample it, to stop it showing up in `ps' output
             * on Unix-like systems. Not guaranteed, of course. */
-           memset(value, 0, strlen(value));
+           smemclr(value, strlen(value));
        }
     }
 
@@ -560,14 +574,66 @@ int cmdline_process_param(char *p, char *value, int need_save, Conf *conf)
            nextitem += length + skip;
        }
     }
+
+    if (!strcmp(p, "-sessionlog")) {
+       Filename *fn;
+       RETURN(2);
+       UNAVAILABLE_IN(TOOLTYPE_FILETRANSFER);
+       /* but available even in TOOLTYPE_NONNETWORK, cf pterm "-log" */
+       SAVEABLE(0);
+       fn = filename_from_str(value);
+       conf_set_filename(conf, CONF_logfilename, fn);
+       conf_set_int(conf, CONF_logtype, LGTYP_DEBUG);
+        filename_free(fn);
+    }
+
+    if (!strcmp(p, "-sshlog") ||
+        !strcmp(p, "-sshrawlog")) {
+       Filename *fn;
+       RETURN(2);
+       UNAVAILABLE_IN(TOOLTYPE_NONNETWORK);
+       SAVEABLE(0);
+       fn = filename_from_str(value);
+       conf_set_filename(conf, CONF_logfilename, fn);
+       conf_set_int(conf, CONF_logtype,
+                     !strcmp(p, "-sshlog") ? LGTYP_PACKETS :
+                     /* !strcmp(p, "-sshrawlog") ? */ LGTYP_SSHRAW);
+        filename_free(fn);
+    }
+
+    if (!strcmp(p, "-proxycmd")) {
+       RETURN(2);
+       UNAVAILABLE_IN(TOOLTYPE_NONNETWORK);
+       SAVEABLE(0);
+        conf_set_int(conf, CONF_proxy_type, PROXY_CMD);
+       conf_set_str(conf, CONF_proxy_telnet_command, value);
+    }
+
+#ifdef _WINDOWS
+    /*
+     * Cross-tool options only available on Windows.
+     */
+    if (!strcmp(p, "-restrict-acl") || !strcmp(p, "-restrict_acl") ||
+        !strcmp(p, "-restrictacl")) {
+       RETURN(1);
+        restrict_process_acl();
+        restricted_acl = TRUE;
+    }
+#endif
+
     return ret;                               /* unrecognised */
 }
 
 void cmdline_run_saved(Conf *conf)
 {
     int pri, i;
-    for (pri = 0; pri < NPRIORITIES; pri++)
-       for (i = 0; i < saves[pri].nsaved; i++)
+    for (pri = 0; pri < NPRIORITIES; pri++) {
+       for (i = 0; i < saves[pri].nsaved; i++) {
            cmdline_process_param(saves[pri].params[i].p,
                                  saves[pri].params[i].value, 0, conf);
+            sfree(saves[pri].params[i].p);
+            sfree(saves[pri].params[i].value);
+        }
+        saves[pri].nsaved = 0;
+    }
 }