Develop and Download Open Source Software

Browse Subversion Repository

Diff of /branches/ssh_chacha20poly1305/ttssh2/ttxssh/ttxssh.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 3427 by maya, Fri May 29 15:40:00 2009 UTC revision 3433 by maya, Tue Jun 2 13:03:24 2009 UTC
# Line 1432  static void read_ssh_options_from_user_f Line 1432  static void read_ssh_options_from_user_f
1432          FWDUI_load_settings(pvar);          FWDUI_load_settings(pvar);
1433  }  }
1434    
1435    #ifdef USE_ATCMDLINE
1436  // @をブランクに置換する。 (2005.1.26 yutaka)  // @をブランクに置換する。 (2005.1.26 yutaka)
1437  static void replace_to_blank(char *src, char *dst, int dst_len)  static void replace_to_blank(char *src, char *dst, int dst_len)
1438  {  {
# Line 1456  static void replace_to_blank(char *src, Line 1456  static void replace_to_blank(char *src,
1456          }          }
1457          *dst = '\0';          *dst = '\0';
1458  }  }
1459    #endif
1460    
1461  // Percent-encodeされた文字列srcをデコードしてdstにコピーする。  // Percent-encodeされた文字列srcをデコードしてdstにコピーする。
1462  // dstlenはdstのサイズ。これより結果が長い場合、その分は切り捨てられる。  // dstlenはdstのサイズ。これより結果が長い場合、その分は切り捨てられる。
# Line 1612  static int parse_option(PTInstVar pvar, Line 1613  static int parse_option(PTInstVar pvar,
1613                          }                          }
1614    
1615                  } else if (MATCH_STR(option + 1, "user=") == 0) {                  } else if (MATCH_STR(option + 1, "user=") == 0) {
1616    #ifdef USE_ATCMDLINE
1617                          replace_to_blank(option + 6, pvar->ssh2_username, sizeof(pvar->ssh2_username));                          replace_to_blank(option + 6, pvar->ssh2_username, sizeof(pvar->ssh2_username));
1618                          //_snprintf(pvar->ssh2_username, sizeof(pvar->ssh2_username), "%s", option + 6);                          //_snprintf(pvar->ssh2_username, sizeof(pvar->ssh2_username), "%s", option + 6);
1619    
1620    #else
1621                            _snprintf_s(pvar->ssh2_username, sizeof(pvar->ssh2_username), _TRUNCATE, "%s", option + 6);
1622    #endif
1623    
1624                  } else if (MATCH_STR(option + 1, "passwd=") == 0) {                  } else if (MATCH_STR(option + 1, "passwd=") == 0) {
1625    #ifdef USE_ATCMDLINE
1626                          replace_to_blank(option + 8, pvar->ssh2_password, sizeof(pvar->ssh2_password));                          replace_to_blank(option + 8, pvar->ssh2_password, sizeof(pvar->ssh2_password));
1627                          //_snprintf(pvar->ssh2_password, sizeof(pvar->ssh2_password), "%s", option + 8);                          //_snprintf(pvar->ssh2_password, sizeof(pvar->ssh2_password), "%s", option + 8);
1628    #else
1629                            _snprintf_s(pvar->ssh2_password, sizeof(pvar->ssh2_password), _TRUNCATE, "%s", option + 8);
1630    #endif
1631    
1632                  } else if (MATCH_STR(option + 1, "keyfile=") == 0) {                  } else if (MATCH_STR(option + 1, "keyfile=") == 0) {
1633    #ifdef USE_ATCMDLINE
1634                          replace_to_blank(option + 9, pvar->ssh2_keyfile, sizeof(pvar->ssh2_keyfile));                          replace_to_blank(option + 9, pvar->ssh2_keyfile, sizeof(pvar->ssh2_keyfile));
1635    #else
1636                            _snprintf_s(pvar->ssh2_keyfile, sizeof(pvar->ssh2_keyfile), _TRUNCATE, "%s", option + 9);
1637    #endif
1638    
1639                  } else if (MATCH_STR(option + 1, "ask4passwd") == 0) {                  } else if (MATCH_STR(option + 1, "ask4passwd") == 0) {
1640                          // パスワードを聞く (2006.9.18 maya)                          // パスワードを聞く (2006.9.18 maya)
# Line 1742  static int parse_option(PTInstVar pvar, Line 1756  static int parse_option(PTInstVar pvar,
1756  static void FAR PASCAL TTXParseParam(PCHAR param, PTTSet ts,  static void FAR PASCAL TTXParseParam(PCHAR param, PTTSet ts,
1757                                       PCHAR DDETopic)                                       PCHAR DDETopic)
1758  {  {
1759  #if 1  #ifndef USE_ATCMDLINE
1760          int i;          int i;
1761          BOOL inParam = FALSE;          BOOL inParam = FALSE;
1762          BOOL inQuotes = FALSE;          BOOL inQuotes = FALSE;
# Line 1760  static void FAR PASCAL TTXParseParam(PCH Line 1774  static void FAR PASCAL TTXParseParam(PCH
1774                  if (inQuotes) {                  if (inQuotes) {
1775                          // 現在位置が"の中                          // 現在位置が"の中
1776                          if (param[i] == '"') {                          if (param[i] == '"') {
 #if 0  
 // "を表すために""を渡す仕様にする場合  
1777                                  if (param[i+1] == '"') {                                  if (param[i+1] == '"') {
1778                                          buf[buf_len] = param[i];                                          buf[buflen] = param[i];
1779                                          buf_len++;                                          buflen++;
1780                                          i++;                                          i++;
1781                                  }                                  }
1782                                  else {                                  else {
 #else  
                                 {  
 #endif  
1783                                          // クォートしているときはここで終わり                                          // クォートしているときはここで終わり
1784                                          // "をbufに入れずに解析に渡す                                          // "をbufに入れずに解析に渡す
1785                                          switch (parse_option(pvar, buf)) {                                          switch (parse_option(pvar, buf)) {
# Line 4015  static int PASCAL FAR TTXProcessCommand( Line 4024  static int PASCAL FAR TTXProcessCommand(
4024  }  }
4025    
4026    
4027    static void _dquote_string(char *str, char *dst, int dst_len)
4028    {
4029            int i, len, n;
4030            
4031            len = strlen(str);
4032            n = 0;
4033            for (i = 0 ; i < len ; i++) {
4034                    if (str[i] == '"')
4035                            n++;
4036            }
4037            if (dst_len < (len + 2*n + 2 + 1))
4038                    return;
4039    
4040            *dst++ = '"';
4041            for (i = 0 ; i < len ; i++) {
4042                    if (str[i] == '"') {
4043                            *dst++ = '"';
4044                            *dst++ = '"';
4045    
4046                    } else {
4047                            *dst++ = str[i];
4048    
4049                    }
4050            }
4051            *dst++ = '"';
4052            *dst = '\0';
4053    }
4054    
4055    static void dquote_string(char *str, char *dst, int dst_len)
4056    {
4057            // " で始まるか、スペースが含まれる場合にはクオートする
4058            if (str[0] == '"' || strchr(str, '" ') != NULL) {
4059                    _dquote_string(str, dst, dst_len);
4060                    return;
4061            }
4062            // そのままコピーして戻る
4063            strncpy_s(dst, dst_len, str, _TRUNCATE);
4064    }
4065    
4066    #ifdef USE_ATCMDLINE
4067  // 以下はTeraTerm Menuのコード(ttpmenu.cpp)と同一。  // 以下はTeraTerm Menuのコード(ttpmenu.cpp)と同一。
4068  // 空白を @ に置き換える。@自身は@@にする。(2005.1.28 yutaka)  // 空白を @ に置き換える。@自身は@@にする。(2005.1.28 yutaka)
4069  static void replace_blank_to_mark(char *str, char *dst, int dst_len)  static void replace_blank_to_mark(char *str, char *dst, int dst_len)
# Line 4046  static void replace_blank_to_mark(char * Line 4095  static void replace_blank_to_mark(char *
4095          *dst = '\0';          *dst = '\0';
4096    
4097  }  }
4098    #endif
4099    
4100  static void PASCAL FAR TTXSetCommandLine(PCHAR cmd, int cmdlen,  static void PASCAL FAR TTXSetCommandLine(PCHAR cmd, int cmdlen,
4101                                                                                   PGetHNRec rec)                                                                                   PGetHNRec rec)
# Line 4122  static void PASCAL FAR TTXSetCommandLine Line 4172  static void PASCAL FAR TTXSetCommandLine
4172                          // パスワードを覚えている場合のみ、コマンドラインに渡す。(2006.8.3 yutaka)                          // パスワードを覚えている場合のみ、コマンドラインに渡す。(2006.8.3 yutaka)
4173                          if (pvar->settings.remember_password &&                          if (pvar->settings.remember_password &&
4174                              pvar->auth_state.cur_cred.method == SSH_AUTH_PASSWORD) {                              pvar->auth_state.cur_cred.method == SSH_AUTH_PASSWORD) {
4175    #ifdef USE_ATCMDLINE
4176                                  replace_blank_to_mark(pvar->auth_state.cur_cred.password, mark, sizeof(mark));                                  replace_blank_to_mark(pvar->auth_state.cur_cred.password, mark, sizeof(mark));
4177    #else
4178                                    dquote_string(pvar->auth_state.cur_cred.password, mark, sizeof(mark));
4179    #endif
4180                                  _snprintf_s(tmp, sizeof(tmp), _TRUNCATE,                                  _snprintf_s(tmp, sizeof(tmp), _TRUNCATE,
4181                                              " /auth=password /user=%s /passwd=%s", pvar->auth_state.user, mark);                                              " /auth=password /user=%s /passwd=%s", pvar->auth_state.user, mark);
4182                                  strncat_s(cmd, cmdlen, tmp, _TRUNCATE);                                  strncat_s(cmd, cmdlen, tmp, _TRUNCATE);
4183    
4184                          } else if (pvar->settings.remember_password &&                          } else if (pvar->settings.remember_password &&
4185                                     pvar->auth_state.cur_cred.method == SSH_AUTH_RSA) {                                     pvar->auth_state.cur_cred.method == SSH_AUTH_RSA) {
4186    #ifdef USE_ATCMDLINE
4187                                  replace_blank_to_mark(pvar->auth_state.cur_cred.password, mark, sizeof(mark));                                  replace_blank_to_mark(pvar->auth_state.cur_cred.password, mark, sizeof(mark));
4188    #else
4189                                    dquote_string(pvar->auth_state.cur_cred.password, mark, sizeof(mark));
4190    #endif
4191                                  _snprintf_s(tmp, sizeof(tmp), _TRUNCATE,                                  _snprintf_s(tmp, sizeof(tmp), _TRUNCATE,
4192                                              " /auth=publickey /user=%s /passwd=%s", pvar->auth_state.user, mark);                                              " /auth=publickey /user=%s /passwd=%s", pvar->auth_state.user, mark);
4193                                  strncat_s(cmd, cmdlen, tmp, _TRUNCATE);                                  strncat_s(cmd, cmdlen, tmp, _TRUNCATE);
4194    
4195    #ifdef USE_ATCMDLINE
4196                                  replace_blank_to_mark(pvar->session_settings.DefaultRSAPrivateKeyFile, mark, sizeof(mark));                                  replace_blank_to_mark(pvar->session_settings.DefaultRSAPrivateKeyFile, mark, sizeof(mark));
4197    #else
4198                                    dquote_string(pvar->session_settings.DefaultRSAPrivateKeyFile, mark, sizeof(mark));
4199    #endif
4200                                  _snprintf_s(tmp, sizeof(tmp), _TRUNCATE, " /keyfile=%s", mark);                                  _snprintf_s(tmp, sizeof(tmp), _TRUNCATE, " /keyfile=%s", mark);
4201                                  strncat_s(cmd, cmdlen, tmp, _TRUNCATE);                                  strncat_s(cmd, cmdlen, tmp, _TRUNCATE);
4202    
4203                          } else if (pvar->settings.remember_password &&                          } else if (pvar->settings.remember_password &&
4204                                     pvar->auth_state.cur_cred.method == SSH_AUTH_TIS) {                                     pvar->auth_state.cur_cred.method == SSH_AUTH_TIS) {
4205    #ifdef USE_ATCMDLINE
4206                                  replace_blank_to_mark(pvar->auth_state.cur_cred.password, mark, sizeof(mark));                                  replace_blank_to_mark(pvar->auth_state.cur_cred.password, mark, sizeof(mark));
4207    #else
4208                                    dquote_string(pvar->auth_state.cur_cred.password, mark, sizeof(mark));
4209    #endif
4210                                  _snprintf_s(tmp, sizeof(tmp), _TRUNCATE,                                  _snprintf_s(tmp, sizeof(tmp), _TRUNCATE,
4211                                              " /auth=challenge /user=%s /passwd=%s", pvar->auth_state.user, mark);                                              " /auth=challenge /user=%s /passwd=%s", pvar->auth_state.user, mark);
4212                                  strncat_s(cmd, cmdlen, tmp, _TRUNCATE);                                  strncat_s(cmd, cmdlen, tmp, _TRUNCATE);

Legend:
Removed from v.3427  
changed lines
  Added in v.3433

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26