+++ /dev/null
-/*\r
- * winstore.c: Windows-specific implementation of the interface\r
- * defined in storage.h.\r
- */\r
-\r
-#include <stdio.h>\r
-#include <stdlib.h>\r
-#include <limits.h>\r
-#include "putty.h"\r
-#include "storage.h"\r
-\r
-#include <shlobj.h>\r
-#ifndef CSIDL_APPDATA\r
-#define CSIDL_APPDATA 0x001a\r
-#endif\r
-#ifndef CSIDL_LOCAL_APPDATA\r
-#define CSIDL_LOCAL_APPDATA 0x001c\r
-#endif\r
-\r
-static const char *const reg_jumplist_key = PUTTY_REG_POS "\\Jumplist";\r
-static const char *const reg_jumplist_value = "Recent sessions";\r
-static const char *const puttystr = PUTTY_REG_POS "\\Sessions";\r
-\r
-static const char hex[16] = "0123456789ABCDEF";\r
-\r
-static int tried_shgetfolderpath = FALSE;\r
-static HMODULE shell32_module = NULL;\r
-DECL_WINDOWS_FUNCTION(static, HRESULT, SHGetFolderPathA, \r
- (HWND, int, HANDLE, DWORD, LPSTR));\r
-\r
-static void mungestr(const char *in, char *out)\r
-{\r
- int candot = 0;\r
-\r
- while (*in) {\r
- if (*in == ' ' || *in == '\\' || *in == '*' || *in == '?' ||\r
- *in == '%' || *in < ' ' || *in > '~' || (*in == '.'\r
- && !candot)) {\r
- *out++ = '%';\r
- *out++ = hex[((unsigned char) *in) >> 4];\r
- *out++ = hex[((unsigned char) *in) & 15];\r
- } else\r
- *out++ = *in;\r
- in++;\r
- candot = 1;\r
- }\r
- *out = '\0';\r
- return;\r
-}\r
-\r
-static void unmungestr(const char *in, char *out, int outlen)\r
-{\r
- while (*in) {\r
- if (*in == '%' && in[1] && in[2]) {\r
- int i, j;\r
-\r
- i = in[1] - '0';\r
- i -= (i > 9 ? 7 : 0);\r
- j = in[2] - '0';\r
- j -= (j > 9 ? 7 : 0);\r
-\r
- *out++ = (i << 4) + j;\r
- if (!--outlen)\r
- return;\r
- in += 3;\r
- } else {\r
- *out++ = *in++;\r
- if (!--outlen)\r
- return;\r
- }\r
- }\r
- *out = '\0';\r
- return;\r
-}\r
-\r
-void *open_settings_w(const char *sessionname, char **errmsg)\r
-{\r
- HKEY subkey1, sesskey;\r
- int ret;\r
- char *p;\r
-\r
- *errmsg = NULL;\r
-\r
- if (!sessionname || !*sessionname)\r
- sessionname = "Default Settings";\r
-\r
- p = snewn(3 * strlen(sessionname) + 1, char);\r
- mungestr(sessionname, p);\r
-\r
- ret = RegCreateKey(HKEY_CURRENT_USER, puttystr, &subkey1);\r
- if (ret != ERROR_SUCCESS) {\r
- sfree(p);\r
- *errmsg = dupprintf("Unable to create registry key\n"\r
- "HKEY_CURRENT_USER\\%s", puttystr);\r
- return NULL;\r
- }\r
- ret = RegCreateKey(subkey1, p, &sesskey);\r
- RegCloseKey(subkey1);\r
- if (ret != ERROR_SUCCESS) {\r
- *errmsg = dupprintf("Unable to create registry key\n"\r
- "HKEY_CURRENT_USER\\%s\\%s", puttystr, p);\r
- sfree(p);\r
- return NULL;\r
- }\r
- sfree(p);\r
- return (void *) sesskey;\r
-}\r
-\r
-void write_setting_s(void *handle, const char *key, const char *value)\r
-{\r
- if (handle)\r
- RegSetValueEx((HKEY) handle, key, 0, REG_SZ, value,\r
- 1 + strlen(value));\r
-}\r
-\r
-void write_setting_i(void *handle, const char *key, int value)\r
-{\r
- if (handle)\r
- RegSetValueEx((HKEY) handle, key, 0, REG_DWORD,\r
- (CONST BYTE *) &value, sizeof(value));\r
-}\r
-\r
-void close_settings_w(void *handle)\r
-{\r
- RegCloseKey((HKEY) handle);\r
-}\r
-\r
-void *open_settings_r(const char *sessionname)\r
-{\r
- HKEY subkey1, sesskey;\r
- char *p;\r
-\r
- if (!sessionname || !*sessionname)\r
- sessionname = "Default Settings";\r
-\r
- p = snewn(3 * strlen(sessionname) + 1, char);\r
- mungestr(sessionname, p);\r
-\r
- if (RegOpenKey(HKEY_CURRENT_USER, puttystr, &subkey1) != ERROR_SUCCESS) {\r
- sesskey = NULL;\r
- } else {\r
- if (RegOpenKey(subkey1, p, &sesskey) != ERROR_SUCCESS) {\r
- sesskey = NULL;\r
- }\r
- RegCloseKey(subkey1);\r
- }\r
-\r
- sfree(p);\r
-\r
- return (void *) sesskey;\r
-}\r
-\r
-char *read_setting_s(void *handle, const char *key, char *buffer, int buflen)\r
-{\r
- DWORD type, size;\r
- size = buflen;\r
-\r
- if (!handle ||\r
- RegQueryValueEx((HKEY) handle, key, 0,\r
- &type, buffer, &size) != ERROR_SUCCESS ||\r
- type != REG_SZ) return NULL;\r
- else\r
- return buffer;\r
-}\r
-\r
-int read_setting_i(void *handle, const char *key, int defvalue)\r
-{\r
- DWORD type, val, size;\r
- size = sizeof(val);\r
-\r
- if (!handle ||\r
- RegQueryValueEx((HKEY) handle, key, 0, &type,\r
- (BYTE *) &val, &size) != ERROR_SUCCESS ||\r
- size != sizeof(val) || type != REG_DWORD)\r
- return defvalue;\r
- else\r
- return val;\r
-}\r
-\r
-int read_setting_fontspec(void *handle, const char *name, FontSpec *result)\r
-{\r
- char *settingname;\r
- FontSpec ret;\r
-\r
- if (!read_setting_s(handle, name, ret.name, sizeof(ret.name)))\r
- return 0;\r
- settingname = dupcat(name, "IsBold", NULL);\r
- ret.isbold = read_setting_i(handle, settingname, -1);\r
- sfree(settingname);\r
- if (ret.isbold == -1) return 0;\r
- settingname = dupcat(name, "CharSet", NULL);\r
- ret.charset = read_setting_i(handle, settingname, -1);\r
- sfree(settingname);\r
- if (ret.charset == -1) return 0;\r
- settingname = dupcat(name, "Height", NULL);\r
- ret.height = read_setting_i(handle, settingname, INT_MIN);\r
- sfree(settingname);\r
- if (ret.height == INT_MIN) return 0;\r
- *result = ret;\r
- return 1;\r
-}\r
-\r
-void write_setting_fontspec(void *handle, const char *name, FontSpec font)\r
-{\r
- char *settingname;\r
-\r
- write_setting_s(handle, name, font.name);\r
- settingname = dupcat(name, "IsBold", NULL);\r
- write_setting_i(handle, settingname, font.isbold);\r
- sfree(settingname);\r
- settingname = dupcat(name, "CharSet", NULL);\r
- write_setting_i(handle, settingname, font.charset);\r
- sfree(settingname);\r
- settingname = dupcat(name, "Height", NULL);\r
- write_setting_i(handle, settingname, font.height);\r
- sfree(settingname);\r
-}\r
-\r
-int read_setting_filename(void *handle, const char *name, Filename *result)\r
-{\r
- return !!read_setting_s(handle, name, result->path, sizeof(result->path));\r
-}\r
-\r
-void write_setting_filename(void *handle, const char *name, Filename result)\r
-{\r
- write_setting_s(handle, name, result.path);\r
-}\r
-\r
-void close_settings_r(void *handle)\r
-{\r
- RegCloseKey((HKEY) handle);\r
-}\r
-\r
-void del_settings(const char *sessionname)\r
-{\r
- HKEY subkey1;\r
- char *p;\r
-\r
- if (RegOpenKey(HKEY_CURRENT_USER, puttystr, &subkey1) != ERROR_SUCCESS)\r
- return;\r
-\r
- p = snewn(3 * strlen(sessionname) + 1, char);\r
- mungestr(sessionname, p);\r
- RegDeleteKey(subkey1, p);\r
- sfree(p);\r
-\r
- RegCloseKey(subkey1);\r
-\r
- remove_session_from_jumplist(sessionname);\r
-}\r
-\r
-struct enumsettings {\r
- HKEY key;\r
- int i;\r
-};\r
-\r
-void *enum_settings_start(void)\r
-{\r
- struct enumsettings *ret;\r
- HKEY key;\r
-\r
- if (RegOpenKey(HKEY_CURRENT_USER, puttystr, &key) != ERROR_SUCCESS)\r
- return NULL;\r
-\r
- ret = snew(struct enumsettings);\r
- if (ret) {\r
- ret->key = key;\r
- ret->i = 0;\r
- }\r
-\r
- return ret;\r
-}\r
-\r
-char *enum_settings_next(void *handle, char *buffer, int buflen)\r
-{\r
- struct enumsettings *e = (struct enumsettings *) handle;\r
- char *otherbuf;\r
- otherbuf = snewn(3 * buflen, char);\r
- if (RegEnumKey(e->key, e->i++, otherbuf, 3 * buflen) == ERROR_SUCCESS) {\r
- unmungestr(otherbuf, buffer, buflen);\r
- sfree(otherbuf);\r
- return buffer;\r
- } else {\r
- sfree(otherbuf);\r
- return NULL;\r
- }\r
-}\r
-\r
-void enum_settings_finish(void *handle)\r
-{\r
- struct enumsettings *e = (struct enumsettings *) handle;\r
- RegCloseKey(e->key);\r
- sfree(e);\r
-}\r
-\r
-static void hostkey_regname(char *buffer, const char *hostname,\r
- int port, const char *keytype)\r
-{\r
- int len;\r
- strcpy(buffer, keytype);\r
- strcat(buffer, "@");\r
- len = strlen(buffer);\r
- len += sprintf(buffer + len, "%d:", port);\r
- mungestr(hostname, buffer + strlen(buffer));\r
-}\r
-\r
-int verify_host_key(const char *hostname, int port,\r
- const char *keytype, const char *key)\r
-{\r
- char *otherstr, *regname;\r
- int len;\r
- HKEY rkey;\r
- DWORD readlen;\r
- DWORD type;\r
- int ret, compare;\r
-\r
- len = 1 + strlen(key);\r
-\r
- /*\r
- * Now read a saved key in from the registry and see what it\r
- * says.\r
- */\r
- otherstr = snewn(len, char);\r
- regname = snewn(3 * (strlen(hostname) + strlen(keytype)) + 15, char);\r
-\r
- hostkey_regname(regname, hostname, port, keytype);\r
-\r
- if (RegOpenKey(HKEY_CURRENT_USER, PUTTY_REG_POS "\\SshHostKeys",\r
- &rkey) != ERROR_SUCCESS)\r
- return 1; /* key does not exist in registry */\r
-\r
- readlen = len;\r
- ret = RegQueryValueEx(rkey, regname, NULL, &type, otherstr, &readlen);\r
-\r
- if (ret != ERROR_SUCCESS && ret != ERROR_MORE_DATA &&\r
- !strcmp(keytype, "rsa")) {\r
- /*\r
- * Key didn't exist. If the key type is RSA, we'll try\r
- * another trick, which is to look up the _old_ key format\r
- * under just the hostname and translate that.\r
- */\r
- char *justhost = regname + 1 + strcspn(regname, ":");\r
- char *oldstyle = snewn(len + 10, char); /* safety margin */\r
- readlen = len;\r
- ret = RegQueryValueEx(rkey, justhost, NULL, &type,\r
- oldstyle, &readlen);\r
-\r
- if (ret == ERROR_SUCCESS && type == REG_SZ) {\r
- /*\r
- * The old format is two old-style bignums separated by\r
- * a slash. An old-style bignum is made of groups of\r
- * four hex digits: digits are ordered in sensible\r
- * (most to least significant) order within each group,\r
- * but groups are ordered in silly (least to most)\r
- * order within the bignum. The new format is two\r
- * ordinary C-format hex numbers (0xABCDEFG...XYZ, with\r
- * A nonzero except in the special case 0x0, which\r
- * doesn't appear anyway in RSA keys) separated by a\r
- * comma. All hex digits are lowercase in both formats.\r
- */\r
- char *p = otherstr;\r
- char *q = oldstyle;\r
- int i, j;\r
-\r
- for (i = 0; i < 2; i++) {\r
- int ndigits, nwords;\r
- *p++ = '0';\r
- *p++ = 'x';\r
- ndigits = strcspn(q, "/"); /* find / or end of string */\r
- nwords = ndigits / 4;\r
- /* now trim ndigits to remove leading zeros */\r
- while (q[(ndigits - 1) ^ 3] == '0' && ndigits > 1)\r
- ndigits--;\r
- /* now move digits over to new string */\r
- for (j = 0; j < ndigits; j++)\r
- p[ndigits - 1 - j] = q[j ^ 3];\r
- p += ndigits;\r
- q += nwords * 4;\r
- if (*q) {\r
- q++; /* eat the slash */\r
- *p++ = ','; /* add a comma */\r
- }\r
- *p = '\0'; /* terminate the string */\r
- }\r
-\r
- /*\r
- * Now _if_ this key matches, we'll enter it in the new\r
- * format. If not, we'll assume something odd went\r
- * wrong, and hyper-cautiously do nothing.\r
- */\r
- if (!strcmp(otherstr, key))\r
- RegSetValueEx(rkey, regname, 0, REG_SZ, otherstr,\r
- strlen(otherstr) + 1);\r
- }\r
- }\r
-\r
- RegCloseKey(rkey);\r
-\r
- compare = strcmp(otherstr, key);\r
-\r
- sfree(otherstr);\r
- sfree(regname);\r
-\r
- if (ret == ERROR_MORE_DATA ||\r
- (ret == ERROR_SUCCESS && type == REG_SZ && compare))\r
- return 2; /* key is different in registry */\r
- else if (ret != ERROR_SUCCESS || type != REG_SZ)\r
- return 1; /* key does not exist in registry */\r
- else\r
- return 0; /* key matched OK in registry */\r
-}\r
-\r
-void store_host_key(const char *hostname, int port,\r
- const char *keytype, const char *key)\r
-{\r
- char *regname;\r
- HKEY rkey;\r
-\r
- regname = snewn(3 * (strlen(hostname) + strlen(keytype)) + 15, char);\r
-\r
- hostkey_regname(regname, hostname, port, keytype);\r
-\r
- if (RegCreateKey(HKEY_CURRENT_USER, PUTTY_REG_POS "\\SshHostKeys",\r
- &rkey) == ERROR_SUCCESS) {\r
- RegSetValueEx(rkey, regname, 0, REG_SZ, key, strlen(key) + 1);\r
- RegCloseKey(rkey);\r
- } /* else key does not exist in registry */\r
-\r
- sfree(regname);\r
-}\r
-\r
-/*\r
- * Open (or delete) the random seed file.\r
- */\r
-enum { DEL, OPEN_R, OPEN_W };\r
-static int try_random_seed(char const *path, int action, HANDLE *ret)\r
-{\r
- if (action == DEL) {\r
- remove(path);\r
- *ret = INVALID_HANDLE_VALUE;\r
- return FALSE; /* so we'll do the next ones too */\r
- }\r
-\r
- *ret = CreateFile(path,\r
- action == OPEN_W ? GENERIC_WRITE : GENERIC_READ,\r
- action == OPEN_W ? 0 : (FILE_SHARE_READ |\r
- FILE_SHARE_WRITE),\r
- NULL,\r
- action == OPEN_W ? CREATE_ALWAYS : OPEN_EXISTING,\r
- action == OPEN_W ? FILE_ATTRIBUTE_NORMAL : 0,\r
- NULL);\r
-\r
- return (*ret != INVALID_HANDLE_VALUE);\r
-}\r
-\r
-static HANDLE access_random_seed(int action)\r
-{\r
- HKEY rkey;\r
- DWORD type, size;\r
- HANDLE rethandle;\r
- char seedpath[2 * MAX_PATH + 10] = "\0";\r
-\r
- /*\r
- * Iterate over a selection of possible random seed paths until\r
- * we find one that works.\r
- * \r
- * We do this iteration separately for reading and writing,\r
- * meaning that we will automatically migrate random seed files\r
- * if a better location becomes available (by reading from the\r
- * best location in which we actually find one, and then\r
- * writing to the best location in which we can _create_ one).\r
- */\r
-\r
- /*\r
- * First, try the location specified by the user in the\r
- * Registry, if any.\r
- */\r
- size = sizeof(seedpath);\r
- if (RegOpenKey(HKEY_CURRENT_USER, PUTTY_REG_POS, &rkey) ==\r
- ERROR_SUCCESS) {\r
- int ret = RegQueryValueEx(rkey, "RandSeedFile",\r
- 0, &type, seedpath, &size);\r
- if (ret != ERROR_SUCCESS || type != REG_SZ)\r
- seedpath[0] = '\0';\r
- RegCloseKey(rkey);\r
-\r
- if (*seedpath && try_random_seed(seedpath, action, &rethandle))\r
- return rethandle;\r
- }\r
-\r
- /*\r
- * Next, try the user's local Application Data directory,\r
- * followed by their non-local one. This is found using the\r
- * SHGetFolderPath function, which won't be present on all\r
- * versions of Windows.\r
- */\r
- if (!tried_shgetfolderpath) {\r
- /* This is likely only to bear fruit on systems with IE5+\r
- * installed, or WinMe/2K+. There is some faffing with\r
- * SHFOLDER.DLL we could do to try to find an equivalent\r
- * on older versions of Windows if we cared enough.\r
- * However, the invocation below requires IE5+ anyway,\r
- * so stuff that. */\r
- shell32_module = load_system32_dll("shell32.dll");\r
- GET_WINDOWS_FUNCTION(shell32_module, SHGetFolderPathA);\r
- tried_shgetfolderpath = TRUE;\r
- }\r
- if (p_SHGetFolderPathA) {\r
- if (SUCCEEDED(p_SHGetFolderPathA(NULL, CSIDL_LOCAL_APPDATA,\r
- NULL, SHGFP_TYPE_CURRENT, seedpath))) {\r
- strcat(seedpath, "\\PUTTY.RND");\r
- if (try_random_seed(seedpath, action, &rethandle))\r
- return rethandle;\r
- }\r
-\r
- if (SUCCEEDED(p_SHGetFolderPathA(NULL, CSIDL_APPDATA,\r
- NULL, SHGFP_TYPE_CURRENT, seedpath))) {\r
- strcat(seedpath, "\\PUTTY.RND");\r
- if (try_random_seed(seedpath, action, &rethandle))\r
- return rethandle;\r
- }\r
- }\r
-\r
- /*\r
- * Failing that, try %HOMEDRIVE%%HOMEPATH% as a guess at the\r
- * user's home directory.\r
- */\r
- {\r
- int len, ret;\r
-\r
- len =\r
- GetEnvironmentVariable("HOMEDRIVE", seedpath,\r
- sizeof(seedpath));\r
- ret =\r
- GetEnvironmentVariable("HOMEPATH", seedpath + len,\r
- sizeof(seedpath) - len);\r
- if (ret != 0) {\r
- strcat(seedpath, "\\PUTTY.RND");\r
- if (try_random_seed(seedpath, action, &rethandle))\r
- return rethandle;\r
- }\r
- }\r
-\r
- /*\r
- * And finally, fall back to C:\WINDOWS.\r
- */\r
- GetWindowsDirectory(seedpath, sizeof(seedpath));\r
- strcat(seedpath, "\\PUTTY.RND");\r
- if (try_random_seed(seedpath, action, &rethandle))\r
- return rethandle;\r
-\r
- /*\r
- * If even that failed, give up.\r
- */\r
- return INVALID_HANDLE_VALUE;\r
-}\r
-\r
-void read_random_seed(noise_consumer_t consumer)\r
-{\r
- HANDLE seedf = access_random_seed(OPEN_R);\r
-\r
- if (seedf != INVALID_HANDLE_VALUE) {\r
- while (1) {\r
- char buf[1024];\r
- DWORD len;\r
-\r
- if (ReadFile(seedf, buf, sizeof(buf), &len, NULL) && len)\r
- consumer(buf, len);\r
- else\r
- break;\r
- }\r
- CloseHandle(seedf);\r
- }\r
-}\r
-\r
-void write_random_seed(void *data, int len)\r
-{\r
- HANDLE seedf = access_random_seed(OPEN_W);\r
-\r
- if (seedf != INVALID_HANDLE_VALUE) {\r
- DWORD lenwritten;\r
-\r
- WriteFile(seedf, data, len, &lenwritten, NULL);\r
- CloseHandle(seedf);\r
- }\r
-}\r
-\r
-/*\r
- * Internal function supporting the jump list registry code. All the\r
- * functions to add, remove and read the list have substantially\r
- * similar content, so this is a generalisation of all of them which\r
- * transforms the list in the registry by prepending 'add' (if\r
- * non-null), removing 'rem' from what's left (if non-null), and\r
- * returning the resulting concatenated list of strings in 'out' (if\r
- * non-null).\r
- */\r
-static int transform_jumplist_registry\r
- (const char *add, const char *rem, char **out)\r
-{\r
- int ret;\r
- HKEY pjumplist_key, psettings_tmp;\r
- DWORD type;\r
- int value_length;\r
- char *old_value, *new_value;\r
- char *piterator_old, *piterator_new, *piterator_tmp;\r
-\r
- ret = RegCreateKeyEx(HKEY_CURRENT_USER, reg_jumplist_key, 0, NULL,\r
- REG_OPTION_NON_VOLATILE, (KEY_READ | KEY_WRITE), NULL,\r
- &pjumplist_key, NULL);\r
- if (ret != ERROR_SUCCESS) {\r
- return JUMPLISTREG_ERROR_KEYOPENCREATE_FAILURE;\r
- }\r
-\r
- /* Get current list of saved sessions in the registry. */\r
- value_length = 200;\r
- old_value = snewn(value_length, char);\r
- ret = RegQueryValueEx(pjumplist_key, reg_jumplist_value, NULL, &type,\r
- old_value, &value_length);\r
- /* When the passed buffer is too small, ERROR_MORE_DATA is\r
- * returned and the required size is returned in the length\r
- * argument. */\r
- if (ret == ERROR_MORE_DATA) {\r
- sfree(old_value);\r
- old_value = snewn(value_length, char);\r
- ret = RegQueryValueEx(pjumplist_key, reg_jumplist_value, NULL, &type,\r
- old_value, &value_length);\r
- }\r
-\r
- if (ret == ERROR_FILE_NOT_FOUND) {\r
- /* Value doesn't exist yet. Start from an empty value. */\r
- *old_value = '\0';\r
- *(old_value + 1) = '\0';\r
- } else if (ret != ERROR_SUCCESS) {\r
- /* Some non-recoverable error occurred. */\r
- sfree(old_value);\r
- RegCloseKey(pjumplist_key);\r
- return JUMPLISTREG_ERROR_VALUEREAD_FAILURE;\r
- } else if (type != REG_MULTI_SZ) {\r
- /* The value present in the registry has the wrong type: we\r
- * try to delete it and start from an empty value. */\r
- ret = RegDeleteValue(pjumplist_key, reg_jumplist_value);\r
- if (ret != ERROR_SUCCESS) {\r
- sfree(old_value);\r
- RegCloseKey(pjumplist_key);\r
- return JUMPLISTREG_ERROR_VALUEREAD_FAILURE;\r
- }\r
-\r
- *old_value = '\0';\r
- *(old_value + 1) = '\0';\r
- }\r
-\r
- /* Check validity of registry data: REG_MULTI_SZ value must end\r
- * with \0\0. */\r
- piterator_tmp = old_value;\r
- while (((piterator_tmp - old_value) < (value_length - 1)) &&\r
- !(*piterator_tmp == '\0' && *(piterator_tmp+1) == '\0')) {\r
- ++piterator_tmp;\r
- }\r
-\r
- if ((piterator_tmp - old_value) >= (value_length-1)) {\r
- /* Invalid value. Start from an empty value. */\r
- *old_value = '\0';\r
- *(old_value + 1) = '\0';\r
- }\r
-\r
- /*\r
- * Modify the list, if we're modifying.\r
- */\r
- if (add || rem) {\r
- /* Walk through the existing list and construct the new list of\r
- * saved sessions. */\r
- new_value = snewn(value_length + (add ? strlen(add) + 1 : 0), char);\r
- piterator_new = new_value;\r
- piterator_old = old_value;\r
-\r
- /* First add the new item to the beginning of the list. */\r
- if (add) {\r
- strcpy(piterator_new, add);\r
- piterator_new += strlen(piterator_new) + 1;\r
- }\r
- /* Now add the existing list, taking care to leave out the removed\r
- * item, if it was already in the existing list. */\r
- while (*piterator_old != '\0') {\r
- if (!rem || strcmp(piterator_old, rem) != 0) {\r
- /* Check if this is a valid session, otherwise don't add. */\r
- psettings_tmp = open_settings_r(piterator_old);\r
- if (psettings_tmp != NULL) {\r
- close_settings_r(psettings_tmp);\r
- strcpy(piterator_new, piterator_old);\r
- piterator_new += strlen(piterator_new) + 1;\r
- }\r
- }\r
- piterator_old += strlen(piterator_old) + 1;\r
- }\r
- *piterator_new = '\0';\r
- ++piterator_new;\r
-\r
- /* Save the new list to the registry. */\r
- ret = RegSetValueEx(pjumplist_key, reg_jumplist_value, 0, REG_MULTI_SZ,\r
- new_value, piterator_new - new_value);\r
-\r
- sfree(old_value);\r
- old_value = new_value;\r
- } else\r
- ret = ERROR_SUCCESS;\r
-\r
- /*\r
- * Either return or free the result.\r
- */\r
- if (out)\r
- *out = old_value;\r
- else\r
- sfree(old_value);\r
-\r
- /* Clean up and return. */\r
- RegCloseKey(pjumplist_key);\r
-\r
- if (ret != ERROR_SUCCESS) {\r
- return JUMPLISTREG_ERROR_VALUEWRITE_FAILURE;\r
- } else {\r
- return JUMPLISTREG_OK;\r
- }\r
-}\r
-\r
-/* Adds a new entry to the jumplist entries in the registry. */\r
-int add_to_jumplist_registry(const char *item)\r
-{\r
- return transform_jumplist_registry(item, item, NULL);\r
-}\r
-\r
-/* Removes an item from the jumplist entries in the registry. */\r
-int remove_from_jumplist_registry(const char *item)\r
-{\r
- return transform_jumplist_registry(NULL, item, NULL);\r
-}\r
-\r
-/* Returns the jumplist entries from the registry. Caller must free\r
- * the returned pointer. */\r
-char *get_jumplist_registry_entries (void)\r
-{\r
- char *list_value;\r
-\r
- if (transform_jumplist_registry(NULL,NULL,&list_value) != ERROR_SUCCESS) {\r
- list_value = snewn(2, char);\r
- *list_value = '\0';\r
- *(list_value + 1) = '\0';\r
- }\r
- return list_value;\r
-}\r
-\r
-/*\r
- * Recursively delete a registry key and everything under it.\r
- */\r
-static void registry_recursive_remove(HKEY key)\r
-{\r
- DWORD i;\r
- char name[MAX_PATH + 1];\r
- HKEY subkey;\r
-\r
- i = 0;\r
- while (RegEnumKey(key, i, name, sizeof(name)) == ERROR_SUCCESS) {\r
- if (RegOpenKey(key, name, &subkey) == ERROR_SUCCESS) {\r
- registry_recursive_remove(subkey);\r
- RegCloseKey(subkey);\r
- }\r
- RegDeleteKey(key, name);\r
- }\r
-}\r
-\r
-void cleanup_all(void)\r
-{\r
- HKEY key;\r
- int ret;\r
- char name[MAX_PATH + 1];\r
-\r
- /* ------------------------------------------------------------\r
- * Wipe out the random seed file, in all of its possible\r
- * locations.\r
- */\r
- access_random_seed(DEL);\r
-\r
- /* ------------------------------------------------------------\r
- * Ask Windows to delete any jump list information associated\r
- * with this installation of PuTTY.\r
- */\r
- clear_jumplist();\r
-\r
- /* ------------------------------------------------------------\r
- * Destroy all registry information associated with PuTTY.\r
- */\r
-\r
- /*\r
- * Open the main PuTTY registry key and remove everything in it.\r
- */\r
- if (RegOpenKey(HKEY_CURRENT_USER, PUTTY_REG_POS, &key) ==\r
- ERROR_SUCCESS) {\r
- registry_recursive_remove(key);\r
- RegCloseKey(key);\r
- }\r
- /*\r
- * Now open the parent key and remove the PuTTY main key. Once\r
- * we've done that, see if the parent key has any other\r
- * children.\r
- */\r
- if (RegOpenKey(HKEY_CURRENT_USER, PUTTY_REG_PARENT,\r
- &key) == ERROR_SUCCESS) {\r
- RegDeleteKey(key, PUTTY_REG_PARENT_CHILD);\r
- ret = RegEnumKey(key, 0, name, sizeof(name));\r
- RegCloseKey(key);\r
- /*\r
- * If the parent key had no other children, we must delete\r
- * it in its turn. That means opening the _grandparent_\r
- * key.\r
- */\r
- if (ret != ERROR_SUCCESS) {\r
- if (RegOpenKey(HKEY_CURRENT_USER, PUTTY_REG_GPARENT,\r
- &key) == ERROR_SUCCESS) {\r
- RegDeleteKey(key, PUTTY_REG_GPARENT_CHILD);\r
- RegCloseKey(key);\r
- }\r
- }\r
- }\r
- /*\r
- * Now we're done.\r
- */\r
-}\r