mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-07-01 03:22:48 -05:00
Turn 'Filename' into a dynamically allocated type with no arbitrary
length limit, just as I did to FontSpec yesterday. [originally from svn r9316]
This commit is contained in:
@ -201,7 +201,7 @@ int askalg(void *frontend, const char *algtype, const char *algname,
|
||||
* Ask whether to wipe a session log file before writing to it.
|
||||
* Returns 2 for wipe, 1 for append, 0 for cancel (don't log).
|
||||
*/
|
||||
int askappend(void *frontend, Filename filename,
|
||||
int askappend(void *frontend, Filename *filename,
|
||||
void (*callback)(void *ctx, int result), void *ctx)
|
||||
{
|
||||
HANDLE hin;
|
||||
@ -223,11 +223,11 @@ int askappend(void *frontend, Filename filename,
|
||||
char line[32];
|
||||
|
||||
if (console_batch_mode) {
|
||||
fprintf(stderr, msgtemplate_batch, FILENAME_MAX, filename.path);
|
||||
fprintf(stderr, msgtemplate_batch, FILENAME_MAX, filename->path);
|
||||
fflush(stderr);
|
||||
return 0;
|
||||
}
|
||||
fprintf(stderr, msgtemplate, FILENAME_MAX, filename.path);
|
||||
fprintf(stderr, msgtemplate, FILENAME_MAX, filename->path);
|
||||
fflush(stderr);
|
||||
|
||||
hin = GetStdHandle(STD_INPUT_HANDLE);
|
||||
|
@ -2098,23 +2098,26 @@ void dlg_editbox_set(union control *ctrl, void *dlg, char const *text)
|
||||
SetDlgItemText(dp->hwnd, c->base_id+1, text);
|
||||
}
|
||||
|
||||
static char *getdlgitemtext_alloc(HWND hwnd, int id)
|
||||
{
|
||||
char *ret = NULL;
|
||||
int size = 0;
|
||||
|
||||
do {
|
||||
size = size * 4 / 3 + 512;
|
||||
ret = sresize(ret, size, char);
|
||||
GetDlgItemText(hwnd, id, ret, size);
|
||||
} while (!memchr(ret, '\0', size-1));
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
char *dlg_editbox_get(union control *ctrl, void *dlg)
|
||||
{
|
||||
struct dlgparam *dp = (struct dlgparam *)dlg;
|
||||
struct winctrl *c = dlg_findbyctrl(dp, ctrl);
|
||||
char *ret;
|
||||
int size;
|
||||
assert(c && c->ctrl->generic.type == CTRL_EDITBOX);
|
||||
|
||||
size = 0;
|
||||
ret = NULL;
|
||||
do {
|
||||
size = size * 4 / 3 + 512;
|
||||
ret = sresize(ret, size, char);
|
||||
GetDlgItemText(dp->hwnd, c->base_id+1, ret, size);
|
||||
} while (!memchr(ret, '\0', size-1));
|
||||
|
||||
return ret;
|
||||
return getdlgitemtext_alloc(dp->hwnd, c->base_id+1);
|
||||
}
|
||||
|
||||
/* The `listbox' functions can also apply to combo boxes. */
|
||||
@ -2294,21 +2297,25 @@ void dlg_label_change(union control *ctrl, void *dlg, char const *text)
|
||||
}
|
||||
}
|
||||
|
||||
void dlg_filesel_set(union control *ctrl, void *dlg, Filename fn)
|
||||
void dlg_filesel_set(union control *ctrl, void *dlg, Filename *fn)
|
||||
{
|
||||
struct dlgparam *dp = (struct dlgparam *)dlg;
|
||||
struct winctrl *c = dlg_findbyctrl(dp, ctrl);
|
||||
assert(c && c->ctrl->generic.type == CTRL_FILESELECT);
|
||||
SetDlgItemText(dp->hwnd, c->base_id+1, fn.path);
|
||||
SetDlgItemText(dp->hwnd, c->base_id+1, fn->path);
|
||||
}
|
||||
|
||||
void dlg_filesel_get(union control *ctrl, void *dlg, Filename *fn)
|
||||
Filename *dlg_filesel_get(union control *ctrl, void *dlg)
|
||||
{
|
||||
struct dlgparam *dp = (struct dlgparam *)dlg;
|
||||
struct winctrl *c = dlg_findbyctrl(dp, ctrl);
|
||||
char *tmp;
|
||||
Filename *ret;
|
||||
assert(c && c->ctrl->generic.type == CTRL_FILESELECT);
|
||||
GetDlgItemText(dp->hwnd, c->base_id+1, fn->path, lenof(fn->path));
|
||||
fn->path[lenof(fn->path)-1] = '\0';
|
||||
tmp = getdlgitemtext_alloc(dp->hwnd, c->base_id+1);
|
||||
ret = filename_from_str(tmp);
|
||||
sfree(tmp);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void dlg_fontsel_set(union control *ctrl, void *dlg, FontSpec *fs)
|
||||
|
@ -14,14 +14,12 @@ FontSpec *platform_default_fontspec(const char *name)
|
||||
return fontspec_new("", 0, 0, 0);
|
||||
}
|
||||
|
||||
Filename platform_default_filename(const char *name)
|
||||
Filename *platform_default_filename(const char *name)
|
||||
{
|
||||
Filename ret;
|
||||
if (!strcmp(name, "LogFileName"))
|
||||
strcpy(ret.path, "putty.log");
|
||||
return filename_from_str("putty.log");
|
||||
else
|
||||
*ret.path = '\0';
|
||||
return ret;
|
||||
return filename_from_str("");
|
||||
}
|
||||
|
||||
char *platform_default_s(const char *name)
|
||||
|
@ -858,7 +858,7 @@ int askalg(void *frontend, const char *algtype, const char *algname,
|
||||
* Ask whether to wipe a session log file before writing to it.
|
||||
* Returns 2 for wipe, 1 for append, 0 for cancel (don't log).
|
||||
*/
|
||||
int askappend(void *frontend, Filename filename,
|
||||
int askappend(void *frontend, Filename *filename,
|
||||
void (*callback)(void *ctx, int result), void *ctx)
|
||||
{
|
||||
static const char msgtemplate[] =
|
||||
@ -872,7 +872,7 @@ int askappend(void *frontend, Filename filename,
|
||||
char *mbtitle;
|
||||
int mbret;
|
||||
|
||||
message = dupprintf(msgtemplate, FILENAME_MAX, filename.path);
|
||||
message = dupprintf(msgtemplate, FILENAME_MAX, filename->path);
|
||||
mbtitle = dupprintf("%s Log to File", appname);
|
||||
|
||||
mbret = MessageBox(NULL, message, mbtitle,
|
||||
|
@ -14,27 +14,58 @@ char *platform_get_x_display(void) {
|
||||
return dupstr(getenv("DISPLAY"));
|
||||
}
|
||||
|
||||
Filename filename_from_str(const char *str)
|
||||
Filename *filename_from_str(const char *str)
|
||||
{
|
||||
Filename ret;
|
||||
strncpy(ret.path, str, sizeof(ret.path));
|
||||
ret.path[sizeof(ret.path)-1] = '\0';
|
||||
Filename *ret = snew(Filename);
|
||||
ret->path = dupstr(str);
|
||||
return ret;
|
||||
}
|
||||
|
||||
Filename *filename_copy(const Filename *fn)
|
||||
{
|
||||
return filename_from_str(fn->path);
|
||||
}
|
||||
|
||||
const char *filename_to_str(const Filename *fn)
|
||||
{
|
||||
return fn->path;
|
||||
}
|
||||
|
||||
int filename_equal(Filename f1, Filename f2)
|
||||
int filename_equal(const Filename *f1, const Filename *f2)
|
||||
{
|
||||
return !strcmp(f1.path, f2.path);
|
||||
return !strcmp(f1->path, f2->path);
|
||||
}
|
||||
|
||||
int filename_is_null(Filename fn)
|
||||
int filename_is_null(const Filename *fn)
|
||||
{
|
||||
return !*fn.path;
|
||||
return !*fn->path;
|
||||
}
|
||||
|
||||
void filename_free(Filename *fn)
|
||||
{
|
||||
sfree(fn->path);
|
||||
sfree(fn);
|
||||
}
|
||||
|
||||
int filename_serialise(const Filename *f, void *vdata)
|
||||
{
|
||||
char *data = (char *)vdata;
|
||||
int len = strlen(f->path) + 1; /* include trailing NUL */
|
||||
if (data) {
|
||||
strcpy(data, f->path);
|
||||
}
|
||||
return len;
|
||||
}
|
||||
Filename *filename_deserialise(void *vdata, int maxsize, int *used)
|
||||
{
|
||||
char *data = (char *)vdata;
|
||||
char *end;
|
||||
end = memchr(data, '\0', maxsize);
|
||||
if (!end)
|
||||
return NULL;
|
||||
end++;
|
||||
*used = end - data;
|
||||
return filename_from_str(data);
|
||||
}
|
||||
|
||||
char *get_username(void)
|
||||
|
@ -615,7 +615,7 @@ void ui_set_state(HWND hwnd, struct MainDlgState *state, int status)
|
||||
}
|
||||
|
||||
void load_key_file(HWND hwnd, struct MainDlgState *state,
|
||||
Filename filename, int was_import_cmd)
|
||||
Filename *filename, int was_import_cmd)
|
||||
{
|
||||
char passphrase[PASSPHRASE_MAXLEN];
|
||||
int needs_pass;
|
||||
@ -627,7 +627,7 @@ void load_key_file(HWND hwnd, struct MainDlgState *state,
|
||||
struct RSAKey newkey1;
|
||||
struct ssh2_userkey *newkey2 = NULL;
|
||||
|
||||
type = realtype = key_type(&filename);
|
||||
type = realtype = key_type(filename);
|
||||
if (type != SSH_KEYTYPE_SSH1 &&
|
||||
type != SSH_KEYTYPE_SSH2 &&
|
||||
!import_possible(type)) {
|
||||
@ -647,13 +647,11 @@ void load_key_file(HWND hwnd, struct MainDlgState *state,
|
||||
|
||||
comment = NULL;
|
||||
if (realtype == SSH_KEYTYPE_SSH1)
|
||||
needs_pass = rsakey_encrypted(&filename, &comment);
|
||||
needs_pass = rsakey_encrypted(filename, &comment);
|
||||
else if (realtype == SSH_KEYTYPE_SSH2)
|
||||
needs_pass =
|
||||
ssh2_userkey_encrypted(&filename, &comment);
|
||||
needs_pass = ssh2_userkey_encrypted(filename, &comment);
|
||||
else
|
||||
needs_pass = import_encrypted(&filename, realtype,
|
||||
&comment);
|
||||
needs_pass = import_encrypted(filename, realtype, &comment);
|
||||
pps.passphrase = passphrase;
|
||||
pps.comment = comment;
|
||||
do {
|
||||
@ -671,18 +669,15 @@ void load_key_file(HWND hwnd, struct MainDlgState *state,
|
||||
*passphrase = '\0';
|
||||
if (type == SSH_KEYTYPE_SSH1) {
|
||||
if (realtype == type)
|
||||
ret = loadrsakey(&filename, &newkey1,
|
||||
passphrase, &errmsg);
|
||||
ret = loadrsakey(filename, &newkey1, passphrase, &errmsg);
|
||||
else
|
||||
ret = import_ssh1(&filename, realtype,
|
||||
&newkey1, passphrase, &errmsg);
|
||||
ret = import_ssh1(filename, realtype, &newkey1,
|
||||
passphrase, &errmsg);
|
||||
} else {
|
||||
if (realtype == type)
|
||||
newkey2 = ssh2_load_userkey(&filename,
|
||||
passphrase, &errmsg);
|
||||
newkey2 = ssh2_load_userkey(filename, passphrase, &errmsg);
|
||||
else
|
||||
newkey2 = import_ssh2(&filename, realtype,
|
||||
passphrase, &errmsg);
|
||||
newkey2 = import_ssh2(filename, realtype, passphrase, &errmsg);
|
||||
if (newkey2 == SSH2_WRONG_PASSPHRASE)
|
||||
ret = -1;
|
||||
else if (!newkey2)
|
||||
@ -1166,22 +1161,24 @@ static int CALLBACK MainDlgProc(HWND hwnd, UINT msg,
|
||||
}
|
||||
|
||||
if (state->ssh2) {
|
||||
Filename fn = filename_from_str(filename);
|
||||
Filename *fn = filename_from_str(filename);
|
||||
if (type != realtype)
|
||||
ret = export_ssh2(&fn, type, &state->ssh2key,
|
||||
ret = export_ssh2(fn, type, &state->ssh2key,
|
||||
*passphrase ? passphrase : NULL);
|
||||
else
|
||||
ret = ssh2_save_userkey(&fn, &state->ssh2key,
|
||||
ret = ssh2_save_userkey(fn, &state->ssh2key,
|
||||
*passphrase ? passphrase :
|
||||
NULL);
|
||||
filename_free(fn);
|
||||
} else {
|
||||
Filename fn = filename_from_str(filename);
|
||||
Filename *fn = filename_from_str(filename);
|
||||
if (type != realtype)
|
||||
ret = export_ssh1(&fn, type, &state->key,
|
||||
ret = export_ssh1(fn, type, &state->key,
|
||||
*passphrase ? passphrase : NULL);
|
||||
else
|
||||
ret = saversakey(&fn, &state->key,
|
||||
ret = saversakey(fn, &state->key,
|
||||
*passphrase ? passphrase : NULL);
|
||||
filename_free(fn);
|
||||
}
|
||||
if (ret <= 0) {
|
||||
MessageBox(hwnd, "Unable to save key file",
|
||||
|
@ -385,7 +385,7 @@ static void keylist_update(void)
|
||||
/*
|
||||
* This function loads a key from a file and adds it.
|
||||
*/
|
||||
static void add_keyfile(Filename filename)
|
||||
static void add_keyfile(Filename *filename)
|
||||
{
|
||||
char passphrase[PASSPHRASE_MAXLEN];
|
||||
struct RSAKey *rkey = NULL;
|
||||
@ -399,7 +399,7 @@ static void add_keyfile(Filename filename)
|
||||
int type;
|
||||
int original_pass;
|
||||
|
||||
type = key_type(&filename);
|
||||
type = key_type(filename);
|
||||
if (type != SSH_KEYTYPE_SSH1 && type != SSH_KEYTYPE_SSH2) {
|
||||
char *msg = dupprintf("Couldn't load this key (%s)",
|
||||
key_type_to_str(type));
|
||||
@ -419,7 +419,7 @@ static void add_keyfile(Filename filename)
|
||||
int i, nkeys, bloblen, keylistlen;
|
||||
|
||||
if (type == SSH_KEYTYPE_SSH1) {
|
||||
if (!rsakey_pubblob(&filename, &blob, &bloblen, NULL, &error)) {
|
||||
if (!rsakey_pubblob(filename, &blob, &bloblen, NULL, &error)) {
|
||||
char *msg = dupprintf("Couldn't load private key (%s)", error);
|
||||
message_box(msg, APPNAME, MB_OK | MB_ICONERROR,
|
||||
HELPCTXID(errors_cantloadkey));
|
||||
@ -429,7 +429,7 @@ static void add_keyfile(Filename filename)
|
||||
keylist = get_keylist1(&keylistlen);
|
||||
} else {
|
||||
unsigned char *blob2;
|
||||
blob = ssh2_userkey_loadpub(&filename, NULL, &bloblen,
|
||||
blob = ssh2_userkey_loadpub(filename, NULL, &bloblen,
|
||||
NULL, &error);
|
||||
if (!blob) {
|
||||
char *msg = dupprintf("Couldn't load private key (%s)", error);
|
||||
@ -517,9 +517,9 @@ static void add_keyfile(Filename filename)
|
||||
|
||||
error = NULL;
|
||||
if (type == SSH_KEYTYPE_SSH1)
|
||||
needs_pass = rsakey_encrypted(&filename, &comment);
|
||||
needs_pass = rsakey_encrypted(filename, &comment);
|
||||
else
|
||||
needs_pass = ssh2_userkey_encrypted(&filename, &comment);
|
||||
needs_pass = ssh2_userkey_encrypted(filename, &comment);
|
||||
attempts = 0;
|
||||
if (type == SSH_KEYTYPE_SSH1)
|
||||
rkey = snew(struct RSAKey);
|
||||
@ -549,9 +549,9 @@ static void add_keyfile(Filename filename)
|
||||
} else
|
||||
*passphrase = '\0';
|
||||
if (type == SSH_KEYTYPE_SSH1)
|
||||
ret = loadrsakey(&filename, rkey, passphrase, &error);
|
||||
ret = loadrsakey(filename, rkey, passphrase, &error);
|
||||
else {
|
||||
skey = ssh2_load_userkey(&filename, passphrase, &error);
|
||||
skey = ssh2_load_userkey(filename, passphrase, &error);
|
||||
if (skey == SSH2_WRONG_PASSPHRASE)
|
||||
ret = -1;
|
||||
else if (!skey)
|
||||
|
@ -230,21 +230,20 @@ void write_setting_fontspec(void *handle, const char *name, FontSpec *font)
|
||||
sfree(settingname);
|
||||
}
|
||||
|
||||
int read_setting_filename(void *handle, const char *name, Filename *result)
|
||||
Filename *read_setting_filename(void *handle, const char *name)
|
||||
{
|
||||
char *tmp = read_setting_s(handle, name);
|
||||
if (tmp) {
|
||||
strncpy(result->path, tmp, sizeof(result->path)-1);
|
||||
result->path[sizeof(result->path)-1] = '\0';
|
||||
Filename *ret = filename_from_str(tmp);
|
||||
sfree(tmp);
|
||||
return TRUE;
|
||||
return ret;
|
||||
} else
|
||||
return FALSE;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void write_setting_filename(void *handle, const char *name, Filename result)
|
||||
void write_setting_filename(void *handle, const char *name, Filename *result)
|
||||
{
|
||||
write_setting_s(handle, name, result.path);
|
||||
write_setting_s(handle, name, result->path);
|
||||
}
|
||||
|
||||
void close_settings_r(void *handle)
|
||||
|
@ -16,9 +16,9 @@
|
||||
#include "winhelp.h"
|
||||
|
||||
struct Filename {
|
||||
char path[FILENAME_MAX];
|
||||
char *path;
|
||||
};
|
||||
#define f_open(filename, mode, isprivate) ( fopen((filename).path, (mode)) )
|
||||
#define f_open(filename, mode, isprivate) ( fopen((filename)->path, (mode)) )
|
||||
|
||||
struct FontSpec {
|
||||
char *name;
|
||||
|
Reference in New Issue
Block a user