static OSErr mac_opensessionfrom(FSSpec *fss) { FInfo fi; Session *s; void *sesshandle; OSErr err; s = snew(Session); memset(s, 0, sizeof(*s)); err = FSpGetFInfo(fss, &fi); if (err != noErr) return err; if (fi.fdFlags & kIsStationery) s->hasfile = FALSE; else { s->hasfile = TRUE; s->savefile = *fss; } sesshandle = open_settings_r_fsp(fss); if (sesshandle == NULL) { /* XXX need a way to pass up an error number */ err = -9999; goto fail; } load_open_settings(sesshandle, &s->cfg); close_settings_r(sesshandle); mac_startsession(s); return noErr; fail: sfree(s); return err; }
void load_settings(char *section, Config * cfg) { void *sesskey; sesskey = open_settings_r(section); load_open_settingsc(sesskey, cfg); close_settings_r(sesskey); }
void load_settings(char *section, int do_host, Config * cfg) { void *sesskey; sesskey = open_settings_r(section); load_open_settings(sesskey, do_host, cfg); close_settings_r(sesskey); }
void load_settings(char *section, Config * cfg) { void *sesskey; sesskey = open_settings_r(section); load_open_settings(sesskey, cfg); close_settings_r(sesskey); if (cfg_launchable(cfg)) add_session_to_jumplist(section); }
void load_settings(char *section, Config * cfg) { void *sesskey; sesskey = open_settings_r(section); load_open_settings(sesskey, cfg); #ifdef PERSOPORT if( section != NULL ) strcpy( cfg->sessionname, section ) ; else strcpy( cfg->sessionname, "" ) ; #endif close_settings_r(sesskey); }
/* * Function to make an IShellLink describing a particular PuTTY * command. If 'appname' is null, the command run will be the one * returned by GetModuleFileName, i.e. our own executable; if it's * non-null then it will be assumed to be a filename in the same * directory as our own executable, and the return value will be NULL * if that file doesn't exist. * * If 'sessionname' is null then no command line will be passed to the * program. If it's non-null, the command line will be that text * prefixed with an @ (to load a PuTTY saved session). * * Hence, you can launch a saved session using make_shell_link(NULL, * sessionname), and launch another app using e.g. * make_shell_link("puttygen.exe", NULL). */ static IShellLink *make_shell_link(const char *appname, const char *sessionname) { IShellLink *ret; char *app_path, *param_string, *desc_string; IPropertyStore *pPS; PROPVARIANT pv; /* Retrieve path to executable. */ if (!putty_path[0]) GetModuleFileName(NULL, putty_path, sizeof(putty_path) - 1); if (appname) { char *p, *q = putty_path; FILE *fp; if ((p = strrchr(q, '\\')) != NULL) q = p+1; if ((p = strrchr(q, ':')) != NULL) q = p+1; app_path = dupprintf("%.*s%s", (int)(q - putty_path), putty_path, appname); if ((fp = fopen(app_path, "r")) == NULL) { sfree(app_path); return NULL; } fclose(fp); } else { app_path = dupstr(putty_path); } /* Check if this is a valid session, otherwise don't add. */ if (sessionname) { settings_r *psettings_tmp = open_settings_r(sessionname); if (!psettings_tmp) { sfree(app_path); return NULL; } close_settings_r(psettings_tmp); } /* Create the new item. */ if (!SUCCEEDED(CoCreateInstance(&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, COMPTR(IShellLink, &ret)))) { sfree(app_path); return NULL; } /* Set path, parameters, icon and description. */ ret->lpVtbl->SetPath(ret, app_path); if (sessionname) { /* The leading space is reported to work around a Windows 10 * behaviour change in which an argument string starting with * '@' causes the SetArguments method to silently do the wrong * thing. */ param_string = dupcat(" @", sessionname, NULL); } else { param_string = dupstr(""); } ret->lpVtbl->SetArguments(ret, param_string); sfree(param_string); if (sessionname) { desc_string = dupcat("Connect to PuTTY session '", sessionname, "'", NULL); } else { assert(appname); desc_string = dupprintf("Run %.*s", (int)strcspn(appname, "."), appname); } ret->lpVtbl->SetDescription(ret, desc_string); sfree(desc_string); ret->lpVtbl->SetIconLocation(ret, app_path, 0); /* To set the link title, we require the property store of the link. */ if (SUCCEEDED(ret->lpVtbl->QueryInterface(ret, COMPTR(IPropertyStore, &pPS)))) { PropVariantInit(&pv); pv.vt = VT_LPSTR; if (sessionname) { pv.pszVal = dupstr(sessionname); } else { assert(appname); pv.pszVal = dupprintf("Run %.*s", (int)strcspn(appname, "."), appname); } pPS->lpVtbl->SetValue(pPS, &PKEY_Title, &pv); sfree(pv.pszVal); pPS->lpVtbl->Commit(pPS); pPS->lpVtbl->Release(pPS); } sfree(app_path); return ret; }
void load_settings(char *section, int do_host, Config * cfg) { int i; char prot[10]; void *sesskey; sesskey = open_settings_r(section); cfg->ssh_subsys = 0; /* FIXME: load this properly */ cfg->remote_cmd_ptr = cfg->remote_cmd; cfg->remote_cmd_ptr2 = NULL; if (do_host) { gpps(sesskey, "HostName", "", cfg->host, sizeof(cfg->host)); } else { cfg->host[0] = '\0'; /* blank hostname */ } gpps(sesskey, "LogFileName", "putty.log", cfg->logfilename, sizeof(cfg->logfilename)); gppi(sesskey, "LogType", 0, &cfg->logtype); gppi(sesskey, "LogFileClash", LGXF_ASK, &cfg->logxfovr); gpps(sesskey, "Protocol", "default", prot, 10); cfg->protocol = default_protocol; cfg->port = default_port; for (i = 0; backends[i].name != NULL; i++) if (!strcmp(prot, backends[i].name)) { cfg->protocol = backends[i].protocol; gppi(sesskey, "PortNumber", default_port, &cfg->port); break; } gppi(sesskey, "CloseOnExit", COE_NORMAL, &cfg->close_on_exit); gppi(sesskey, "WarnOnClose", 1, &cfg->warn_on_close); { /* This is two values for backward compatibility with 0.50/0.51 */ int pingmin, pingsec; gppi(sesskey, "PingInterval", 0, &pingmin); gppi(sesskey, "PingIntervalSecs", 0, &pingsec); cfg->ping_interval = pingmin * 60 + pingsec; } gppi(sesskey, "TCPNoDelay", 1, &cfg->tcp_nodelay); gpps(sesskey, "TerminalType", "xterm", cfg->termtype, sizeof(cfg->termtype)); gpps(sesskey, "TerminalSpeed", "38400,38400", cfg->termspeed, sizeof(cfg->termspeed)); { char buf[2 * sizeof(cfg->environmt)], *p, *q; gpps(sesskey, "Environment", "", buf, sizeof(buf)); p = buf; q = cfg->environmt; while (*p) { while (*p && *p != ',') { int c = *p++; if (c == '=') c = '\t'; if (c == '\\') c = *p++; *q++ = c; } if (*p == ',') p++; *q++ = '\0'; } *q = '\0'; } gpps(sesskey, "UserName", "", cfg->username, sizeof(cfg->username)); gpps(sesskey, "LocalUserName", "", cfg->localusername, sizeof(cfg->localusername)); gppi(sesskey, "NoPTY", 0, &cfg->nopty); gppi(sesskey, "Compression", 0, &cfg->compression); gppi(sesskey, "AgentFwd", 0, &cfg->agentfwd); gppi(sesskey, "ChangeUsername", 0, &cfg->change_username); gprefs(sesskey, "Cipher", "\0", ciphernames, CIPHER_MAX, cfg->ssh_cipherlist); gppi(sesskey, "SshProt", 1, &cfg->sshprot); gppi(sesskey, "BuggyMAC", 0, &cfg->buggymac); gppi(sesskey, "SSH2DES", 0, &cfg->ssh2_des_cbc); gppi(sesskey, "AuthTIS", 0, &cfg->try_tis_auth); gppi(sesskey, "AuthKI", 1, &cfg->try_ki_auth); gpps(sesskey, "PublicKeyFile", "", cfg->keyfile, sizeof(cfg->keyfile)); gpps(sesskey, "RemoteCommand", "", cfg->remote_cmd, sizeof(cfg->remote_cmd)); gppi(sesskey, "RFCEnviron", 0, &cfg->rfc_environ); gppi(sesskey, "PassiveTelnet", 0, &cfg->passive_telnet); gppi(sesskey, "BackspaceIsDelete", 1, &cfg->bksp_is_delete); gppi(sesskey, "RXVTHomeEnd", 0, &cfg->rxvt_homeend); gppi(sesskey, "LinuxFunctionKeys", 0, &cfg->funky_type); gppi(sesskey, "NoApplicationKeys", 0, &cfg->no_applic_k); gppi(sesskey, "NoApplicationCursors", 0, &cfg->no_applic_c); gppi(sesskey, "ApplicationCursorKeys", 0, &cfg->app_cursor); gppi(sesskey, "ApplicationKeypad", 0, &cfg->app_keypad); gppi(sesskey, "NetHackKeypad", 0, &cfg->nethack_keypad); gppi(sesskey, "AltF4", 1, &cfg->alt_f4); gppi(sesskey, "AltSpace", 0, &cfg->alt_space); gppi(sesskey, "AltOnly", 0, &cfg->alt_only); gppi(sesskey, "ComposeKey", 0, &cfg->compose_key); gppi(sesskey, "CtrlAltKeys", 1, &cfg->ctrlaltkeys); gppi(sesskey, "TelnetKey", 0, &cfg->telnet_keyboard); gppi(sesskey, "TelnetRet", 1, &cfg->telnet_newline); gppi(sesskey, "LocalEcho", LD_BACKEND, &cfg->localecho); gppi(sesskey, "LocalEdit", LD_BACKEND, &cfg->localedit); gpps(sesskey, "Answerback", "PuTTY", cfg->answerback, sizeof(cfg->answerback)); gppi(sesskey, "AlwaysOnTop", 0, &cfg->alwaysontop); gppi(sesskey, "FullScreenOnAltEnter", 0, &cfg->fullscreenonaltenter); gppi(sesskey, "HideMousePtr", 0, &cfg->hide_mouseptr); gppi(sesskey, "SunkenEdge", 0, &cfg->sunken_edge); gppi(sesskey, "WindowBorder", 1, &cfg->window_border); gppi(sesskey, "CurType", 0, &cfg->cursor_type); gppi(sesskey, "BlinkCur", 0, &cfg->blink_cur); /* pedantic compiler tells me I can't use &cfg->beep as an int * :-) */ gppi(sesskey, "Beep", 1, &i); cfg->beep = i; gppi(sesskey, "BeepInd", 0, &i); cfg->beep_ind = i; gpps(sesskey, "BellWaveFile", "", cfg->bell_wavefile, sizeof(cfg->bell_wavefile)); gppi(sesskey, "BellOverload", 1, &cfg->bellovl); gppi(sesskey, "BellOverloadN", 5, &cfg->bellovl_n); gppi(sesskey, "BellOverloadT", 2000, &cfg->bellovl_t); gppi(sesskey, "BellOverloadS", 5000, &cfg->bellovl_s); gppi(sesskey, "ScrollbackLines", 200, &cfg->savelines); gppi(sesskey, "DECOriginMode", 0, &cfg->dec_om); gppi(sesskey, "AutoWrapMode", 1, &cfg->wrap_mode); gppi(sesskey, "LFImpliesCR", 0, &cfg->lfhascr); gppi(sesskey, "WinNameAlways", 0, &cfg->win_name_always); gpps(sesskey, "WinTitle", "", cfg->wintitle, sizeof(cfg->wintitle)); gppi(sesskey, "TermWidth", 80, &cfg->width); gppi(sesskey, "TermHeight", 24, &cfg->height); gpps(sesskey, "Font", "Courier New", cfg->font, sizeof(cfg->font)); gppi(sesskey, "FontIsBold", 0, &cfg->fontisbold); gppi(sesskey, "FontCharSet", ANSI_CHARSET, &cfg->fontcharset); gppi(sesskey, "FontHeight", 10, &cfg->fontheight); if (cfg->fontheight < 0) { int oldh, newh; HDC hdc = GetDC(NULL); int logpix = GetDeviceCaps(hdc, LOGPIXELSY); ReleaseDC(NULL, hdc); oldh = -cfg->fontheight; newh = MulDiv(oldh, 72, logpix) + 1; if (MulDiv(newh, logpix, 72) > oldh) newh--; cfg->fontheight = newh; } gppi(sesskey, "FontVTMode", VT_UNICODE, (int *) &cfg->vtmode); gppi(sesskey, "TryPalette", 0, &cfg->try_palette); gppi(sesskey, "BoldAsColour", 1, &cfg->bold_colour); for (i = 0; i < 22; i++) { static char *defaults[] = { "187,187,187", "255,255,255", "0,0,0", "85,85,85", "0,0,0", "0,255,0", "0,0,0", "85,85,85", "187,0,0", "255,85,85", "0,187,0", "85,255,85", "187,187,0", "255,255,85", "0,0,187", "85,85,255", "187,0,187", "255,85,255", "0,187,187", "85,255,255", "187,187,187", "255,255,255" }; char buf[20], buf2[30]; int c0, c1, c2; sprintf(buf, "Colour%d", i); gpps(sesskey, buf, defaults[i], buf2, sizeof(buf2)); if (sscanf(buf2, "%d,%d,%d", &c0, &c1, &c2) == 3) { cfg->colours[i][0] = c0; cfg->colours[i][1] = c1; cfg->colours[i][2] = c2; } } gppi(sesskey, "RawCNP", 0, &cfg->rawcnp); gppi(sesskey, "PasteRTF", 0, &cfg->rtf_paste); gppi(sesskey, "MouseIsXterm", 0, &cfg->mouse_is_xterm); gppi(sesskey, "RectSelect", 0, &cfg->rect_select); gppi(sesskey, "MouseOverride", 1, &cfg->mouse_override); for (i = 0; i < 256; i += 32) { static char *defaults[] = { "0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0", "0,1,2,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1", "1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,2", "1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1", "1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1", "1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1", "2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,2,2,2,2,2,2,2,2", "2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,2,2,2,2,2,2,2,2" }; char buf[20], buf2[256], *p; int j; sprintf(buf, "Wordness%d", i); gpps(sesskey, buf, defaults[i / 32], buf2, sizeof(buf2)); p = buf2; for (j = i; j < i + 32; j++) { char *q = p; while (*p && *p != ',') p++; if (*p == ',') *p++ = '\0'; cfg->wordness[j] = atoi(q); } } /* * The empty default for LineCodePage will be converted later * into a plausible default for the locale. */ gpps(sesskey, "LineCodePage", "", cfg->line_codepage, sizeof(cfg->line_codepage)); gppi (sesskey, "CapsLockCyr", 0, &cfg->xlat_capslockcyr); gppi(sesskey, "ScrollBar", 1, &cfg->scrollbar); gppi(sesskey, "ScrollBarFullScreen", 0, &cfg->scrollbar_in_fullscreen); gppi(sesskey, "ScrollOnKey", 0, &cfg->scroll_on_key); gppi(sesskey, "ScrollOnDisp", 1, &cfg->scroll_on_disp); gppi(sesskey, "LockSize", 0, &cfg->resize_action); gppi(sesskey, "BCE", 0, &cfg->bce); gppi(sesskey, "BlinkText", 0, &cfg->blinktext); gppi(sesskey, "X11Forward", 0, &cfg->x11_forward); gpps(sesskey, "X11Display", "localhost:0", cfg->x11_display, sizeof(cfg->x11_display)); gppi(sesskey, "LocalPortAcceptAll", 0, &cfg->lport_acceptall); gppi(sesskey, "RemotePortAcceptAll", 0, &cfg->rport_acceptall); { char buf[2 * sizeof(cfg->portfwd)], *p, *q; gpps(sesskey, "PortForwardings", "", buf, sizeof(buf)); p = buf; q = cfg->portfwd; while (*p) { while (*p && *p != ',') { int c = *p++; if (c == '=') c = '\t'; if (c == '\\') c = *p++; *q++ = c; } if (*p == ',') p++; *q++ = '\0'; } *q = '\0'; } close_settings_r(sesskey); }
/* Updates jumplist from registry. */ void update_jumplist_from_registry (void) { ICustomDestinationList *pCDL; /* ICustomDestinationList is the COM Object used to create application jumplists. */ char *pjumplist_reg_entries, *piterator; char *param_string, *desc_string; IPropertyStore *pPS; PROPVARIANT pv; IObjectCollection *pjumplist_items; IObjectArray *pjumplist_items_as_array; IShellLink *pSL[MAX_JUMPLIST_ITEMS], *pcurrent_link; IObjectArray *pRemoved; /* Items removed by user from jump list. These may not be re-added. We don't use this, because IShellLink items can't be removed from the jumplist, only pinned. */ UINT num_items; int jumplist_counter; HKEY psettings_tmp; char b[2048], *p, *q, *r, *putty_path; /* Retrieve path to Putty executable. */ GetModuleFileName(NULL, b, sizeof(b) - 1); r = b; p = strrchr(b, '\\'); if (p && p >= r) r = p+1; q = strrchr(b, ':'); if (q && q >= r) r = q+1; strcpy(r, "putty.exe"); putty_path = dupstr(b); pjumplist_reg_entries = get_jumplist_registry_entries(); if (CoCreateInstance(&CLSID_DestinationList, NULL, CLSCTX_INPROC_SERVER, &IID_ICustomDestinationList, &pCDL) == S_OK) { if (SUCCEEDED(pCDL->lpVtbl->BeginList(pCDL, &num_items, &IID_IObjectArray, &pRemoved))) { if (SUCCEEDED(CoCreateInstance(&CLSID_EnumerableObjectCollection, NULL, CLSCTX_INPROC_SERVER, &IID_IObjectCollection, &pjumplist_items))) { /* Walk through the jumplist entries from the registry and add them to the new jumplist. */ piterator = pjumplist_reg_entries; jumplist_counter = 0; while (*piterator != '\0' && (jumplist_counter < min(MAX_JUMPLIST_ITEMS,(int) num_items)) ) { /* Check if this is a valid session, otherwise don't add. */ psettings_tmp = open_settings_r(piterator); if (psettings_tmp != NULL ) { close_settings_r(psettings_tmp); /* Create and add the new item to the list. */ if (SUCCEEDED(CoCreateInstance(&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, &IID_IShellLink, &(pSL[jumplist_counter]) ))) { pcurrent_link = pSL[jumplist_counter]; /* Set path, parameters, icon and description. */ pcurrent_link->lpVtbl->SetPath(pcurrent_link, putty_path); param_string = snewn(7 + strlen(piterator) + 1 + 1, char); strcpy(param_string, "-load \""); strcat(param_string, piterator); strcat(param_string, "\""); pcurrent_link->lpVtbl->SetArguments(pcurrent_link, param_string); sfree(param_string); desc_string = snewn(20 + strlen(piterator) + 1 + 1, char); strcpy(desc_string, "Connect to session '"); strcat(desc_string, piterator); strcat(desc_string, "'"); pcurrent_link->lpVtbl->SetDescription(pcurrent_link, desc_string); sfree(desc_string); pcurrent_link->lpVtbl->SetIconLocation(pcurrent_link, putty_path, 0); /* To set the link title, we require the property store of the link. */ if (SUCCEEDED(pcurrent_link->lpVtbl->QueryInterface(pcurrent_link, &IID_IPropertyStore, &pPS))) { PropVariantInit(&pv); pv.vt = VT_LPSTR; pv.pszVal = dupstr(piterator); pPS->lpVtbl->SetValue(pPS, &PKEY_Title, &pv); sfree(pv.pszVal); pPS->lpVtbl->Commit(pPS); /* Add link to jumplist. */ pjumplist_items->lpVtbl->AddObject(pjumplist_items, pcurrent_link); pPS->lpVtbl->Release(pPS); } ++jumplist_counter; } } piterator += strlen(piterator) + 1; } /* Now commit the jumplist. */ if (SUCCEEDED( pjumplist_items->lpVtbl->QueryInterface(pjumplist_items, &IID_IObjectArray, &pjumplist_items_as_array) )) { pCDL->lpVtbl->AppendCategory(pCDL, L"Recent Sessions", pjumplist_items_as_array); pCDL->lpVtbl->CommitList(pCDL); pjumplist_items_as_array->lpVtbl->Release(pjumplist_items_as_array); } /* Release COM objects used for the Shell links. */ --jumplist_counter; while (jumplist_counter >= 0) { pSL[jumplist_counter]->lpVtbl->Release(pSL[jumplist_counter]); --jumplist_counter; } pjumplist_items->lpVtbl->Release(pjumplist_items); }