Modify the putty 0.6 code to support saving the SSH password.

Source: Internet
Author: User
You have modified putty code a long time ago to add a timestamp to Telenet output. I have always used the public key method for SSH Login, so I have never thought of adding the password option. However, I know that many of my colleagues use putty login every time, they still have similar requirements.

====> Config. c

1. setup_config_box:
Putty's interface processing method is worth studying. First, consider where to put the newly added passowrd text box on the original interface, I personally think it is a good choice to put the newly added text box behind the original input port.
Modify: Line: ctrl_columns (S, 2, 75, 25) of row 1155; change to ctrl_columns (s, 3, 50, 25, 25); The number behind is only a ratio.
Add: Line: 1165 and then add:

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;

Define the host_password macro at the beginning of the file. If this macro is not defined, replace it with a string.
# Define host_password "password"

2. Add a text box for entering password. Add the configure_userpassword_handler function to any location. This function controls the passowrd input box.

Static void configure_userpassword_handler (Union control * Ctrl, void * DLG, void * data, int event)
{
Config * CFG = (config *) data;
If (event = event_refresh ){
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. Modify the struct hostport structure:
Struct hostport {
Union control * Host, * port, * username;
};

4. Modify config_protocolbuttons_handler: Add dlg_refresh (HP-> port, DLG) after dlg_refresh (HP-> username, DLG );

==> Wintrls. c

Add function:
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;
}
The purpose of this function is to obtain the window handle of the text box.

====> Dialog. h

Declaration of adding a function: hwnd dlg_get_control_handle (Union control * Ctrl, void * DLG );

====> Putty. h

Modify struct config_tag: Add char password [104]; (the maximum allowed password in Putty is 100 characters)

====> Settings. c
Add write_setting_ B (sesskey, "password", CFG-> password) to the save_open_settings function );
In the load_open_settings function, add: GPPs (sesskey, "password", "", CFG-> password, sizeof (CFG-> password ));

====> Ssh. c
In the do_ssh1_login function, the code after line 1 is changed:
If the password to be saved is empty, it will be processed according to the original process; otherwise, the saved password will be copied directly. If (! RET) the process remains unchanged.
 
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 );
}

In the do_ssh2_authconn function, the code after line 1 is changed:

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
Add # define release 0.60 to the file

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.