很早之前曾經修改過putty 的代碼,使得telenet 的輸出能夠加入時間戳記。 自己一向都是通過public key 的方式來完成SSH 登入,也就沒有想過添加password 選項,但我知道我的很多同事每次在使用putty login 的時候,都不厭其煩的輸入password ,他們還是有類似的需求。
====> config.c
1、setup_config_box :
putty 的介面的處理方式是很值得研究研究的。 首先要考慮在原有的介面上把新加的輸入passowrd 的文字框放在什麼地方,個人認為把新加入的文字框放在原有的輸入port 連接埠後面的文字框後面是一個比較好的選擇。
修改: line :1155 行的 ctrl_columns(s, 2, 75, 25); 改為 ctrl_columns(s, 3, 50, 25,25); 後面的數字只是一個比例。
添加: line : 1165 後加入:
c = ctrl_editbox(s, HOST_PASSWORD, NO_SHORTCUT ,100,
HELPCTX(session_hostname),
configure_userpassword_handler, I(0), I(0));
c->editbox.password = 1;
c->generic.column = 2;
hp->username = c;
在檔案開始處定義 HOST_PASSWORD 這個宏,如果不定義的話,上面使用這個宏的地方,用字串自己代替。
#define HOST_PASSWORD "Password"
2、 這裡加入一個輸入 password 的輸入文字框。 隨便找個地方加入函數 configure_userpassword_handler ,這個函數是對passowrd 輸入框的一些控制。
static void configure_userpassword_handler(union control * ctrl, void *dlg, void * data, int event)
{
Config * cfg = (Config *) data ;
if(event == EVENT_REFRESH) {
HWND hWnd = dlg_get_control_handle(ctrl,dlg);
if(cfg->protocol == PROT_SERIAL) { /* don't need password for serail port */
if(hWnd) EnableWindow(hWnd, 0);
} else {
if(hWnd) EnableWindow(hWnd, 1);
dlg_editbox_set(ctrl, dlg, cfg->password);
}
} else if( event == EVENT_VALCHANGE) {
if(cfg->protocol != PROT_SERIAL) {
dlg_editbox_get(ctrl,dlg,cfg->password,lenof(cfg->password));
}
}
}
3、修改 struct hostport 結構 為 :
struct hostport {
union control *host, *port , *username;
};
4、修改 config_protocolbuttons_handler : 在dlg_refresh(hp->port, dlg); 後面加入 dlg_refresh(hp->username,dlg);
===> wintrls.c
加入函數:
HWND dlg_get_control_handle(union control * ctrl, void *dlg)
{
struct dlgparam * dp = (struct dlgparam *) dlg;
struct winctrl *c = dlg_findbyctrl(dp, ctrl);
HWND hw = GetDlgItem(dp->hwnd, c->base_id+1);
return hw;
}
這個函數的目的是可以得到文字框的window 控制代碼。
====> dialog.h
加入函數的聲明: HWND dlg_get_control_handle(union control * ctrl, void *dlg) ;
====> putty.h
修改 struct config_tag : 加入 char password[104]; (Putty 中允許的最長的密碼是 100 個字元)
====> settings.c
在函數 save_open_settings 中添加: write_setting_b(sesskey,"Password",cfg->password);
在函數 load_open_settings 中加入: gpps(sesskey,"Password","", cfg->password,sizeof(cfg->password));
====> ssh.c
在函數 do_ssh1_login 中 3861 行後面的代碼改為:
如果儲存的密碼是空的話,這按照原來流程處理,否則直接拷貝儲存的密碼。 後面的 if(!ret) 流程不變。
if(strlen(ssh->cfg.password) == 0 ) {
ret = get_userpass_input(s->cur_prompt, NULL, 0);
while (ret < 0) {
ssh->send_ok = 1;
crWaitUntil(!pktin);
ret = get_userpass_input(s->cur_prompt, in, inlen);
ssh->send_ok = 0;
}
} else {
ret = 1;
strcpy(s->cur_prompt->prompts[0]->result, ssh->cfg.password);
}
在函數 do_ssh2_authconn 中 7926 行後面的代碼改為:
if(strlen(ssh->cfg.password) == 0 ) {
ret = get_userpass_input(s->cur_prompt, NULL, 0);
while (ret < 0) {
ssh->send_ok = 1;
crWaitUntilV(!pktin);
ret = get_userpass_input(s->cur_prompt, in, inlen);
ssh->send_ok = 0;
}
}
else {
ret = 1;
strcpy(s->cur_prompt->prompts[0]->result, ssh->cfg.password);
}
====> version.c
在檔案開始加入 #define RELEASE 0.60