mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-01-09 09:27:59 +00:00
Implement "putty -cleanup"
[originally from svn r626]
This commit is contained in:
parent
0fb760b16d
commit
f80f9d4299
10
noise.c
10
noise.c
@ -107,6 +107,16 @@ void random_save_seed(void) {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* This function is called from `putty -cleanup'. It removes the
|
||||
* random seed file.
|
||||
*/
|
||||
void random_destroy_seed(void) {
|
||||
if (!seedpath[0])
|
||||
get_seedpath();
|
||||
remove(seedpath);
|
||||
}
|
||||
|
||||
/*
|
||||
* This function is called every time the random pool needs
|
||||
* stirring, and will acquire the system time in all available
|
||||
|
6
putty.h
6
putty.h
@ -2,6 +2,10 @@
|
||||
#define PUTTY_PUTTY_H
|
||||
|
||||
#define PUTTY_REG_POS "Software\\SimonTatham\\PuTTY"
|
||||
#define PUTTY_REG_PARENT "Software\\SimonTatham"
|
||||
#define PUTTY_REG_PARENT_CHILD "PuTTY"
|
||||
#define PUTTY_REG_GPARENT "Software"
|
||||
#define PUTTY_REG_GPARENT_CHILD "SimonTatham"
|
||||
|
||||
/*
|
||||
* Global variables. Most modules declare these `extern', but
|
||||
@ -254,6 +258,7 @@ void noise_get_heavy(void (*func) (void *, int));
|
||||
void noise_get_light(void (*func) (void *, int));
|
||||
void noise_ultralight(DWORD data);
|
||||
void random_save_seed(void);
|
||||
void random_destroy_seed(void);
|
||||
|
||||
/*
|
||||
* Exports from windlg.c.
|
||||
@ -266,6 +271,7 @@ void showeventlog (HWND);
|
||||
void showabout (HWND);
|
||||
void verify_ssh_host_key(char *host, char *keystr);
|
||||
void get_sesslist(int allocate);
|
||||
void registry_cleanup(void);
|
||||
|
||||
GLOBAL int nsessions;
|
||||
GLOBAL char **sessions;
|
||||
|
61
windlg.c
61
windlg.c
@ -1708,3 +1708,64 @@ void verify_ssh_host_key(char *host, char *keystr) {
|
||||
RegCloseKey(rkey);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Recursively delete a registry key and everything under it.
|
||||
*/
|
||||
static void registry_recursive_remove(HKEY key) {
|
||||
DWORD i;
|
||||
char name[MAX_PATH+1];
|
||||
HKEY subkey;
|
||||
|
||||
i = 0;
|
||||
while (RegEnumKey(key, i, name, sizeof(name)) == ERROR_SUCCESS) {
|
||||
if (RegOpenKey(key, name, &subkey) == ERROR_SUCCESS) {
|
||||
registry_recursive_remove(subkey);
|
||||
RegCloseKey(subkey);
|
||||
}
|
||||
RegDeleteKey(key, name);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Destroy all registry information associated with PuTTY.
|
||||
*/
|
||||
void registry_cleanup(void) {
|
||||
HKEY key;
|
||||
int ret;
|
||||
char name[MAX_PATH+1];
|
||||
|
||||
/*
|
||||
* Open the main PuTTY registry key and remove everything in it.
|
||||
*/
|
||||
if (RegOpenKey(HKEY_CURRENT_USER, PUTTY_REG_POS, &key) == ERROR_SUCCESS) {
|
||||
registry_recursive_remove(key);
|
||||
RegCloseKey(key);
|
||||
}
|
||||
/*
|
||||
* Now open the parent key and remove the PuTTY main key. Once
|
||||
* we've done that, see if the parent key has any other
|
||||
* children.
|
||||
*/
|
||||
if (RegOpenKey(HKEY_CURRENT_USER, PUTTY_REG_PARENT,
|
||||
&key) == ERROR_SUCCESS) {
|
||||
RegDeleteKey(key, PUTTY_REG_PARENT_CHILD);
|
||||
ret = RegEnumKey(key, 0, name, sizeof(name));
|
||||
RegCloseKey(key);
|
||||
/*
|
||||
* If the parent key had no other children, we must delete
|
||||
* it in its turn. That means opening the _grandparent_
|
||||
* key.
|
||||
*/
|
||||
if (ret != ERROR_SUCCESS) {
|
||||
if (RegOpenKey(HKEY_CURRENT_USER, PUTTY_REG_GPARENT,
|
||||
&key) == ERROR_SUCCESS) {
|
||||
RegDeleteKey(key, PUTTY_REG_GPARENT_CHILD);
|
||||
RegCloseKey(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Now we're done.
|
||||
*/
|
||||
}
|
||||
|
27
window.c
27
window.c
@ -153,6 +153,33 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show) {
|
||||
tolower(p[1]) == 'o' &&
|
||||
tolower(p[2]) == 'g') {
|
||||
logfile = "putty.log";
|
||||
} else if (q == p + 7 &&
|
||||
tolower(p[0]) == 'c' &&
|
||||
tolower(p[1]) == 'l' &&
|
||||
tolower(p[2]) == 'e' &&
|
||||
tolower(p[3]) == 'a' &&
|
||||
tolower(p[4]) == 'n' &&
|
||||
tolower(p[5]) == 'u' &&
|
||||
tolower(p[6]) == 'p') {
|
||||
/*
|
||||
* `putty -cleanup'. Remove all registry entries
|
||||
* associated with PuTTY, and also find and delete
|
||||
* the random seed file.
|
||||
*/
|
||||
if (MessageBox(NULL,
|
||||
"This procedure will remove ALL Registry\n"
|
||||
"entries associated with PuTTY, and will\n"
|
||||
"also remove the PuTTY random seed file.\n"
|
||||
"\n"
|
||||
"THIS PROCESS WILL DESTROY YOUR SAVED\n"
|
||||
"SESSIONS. Are you really sure you want\n"
|
||||
"to continue?",
|
||||
"PuTTY Warning",
|
||||
MB_YESNO | MB_ICONWARNING) == IDYES) {
|
||||
random_destroy_seed();
|
||||
registry_cleanup();
|
||||
}
|
||||
exit(0);
|
||||
}
|
||||
p = q + strspn(q, " \t");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user