Skip to content

Commit

Permalink
Created new data types Filename' and FontSpec', intended to be
Browse files Browse the repository at this point in the history
opaque to all platform-independent modules and only handled within
per-platform code. `Filename' is there because the Mac has a magic
way to store filenames (though currently this checkin doesn't
support it!); `FontSpec' is there so that all the auxiliary stuff
such as font height and charset and so on which is needed under
Windows but not Unix can be kept where it belongs, and so that I can
have a hope in hell of dealing with a font chooser in the forthcoming
cross-platform config box code, and best of all it gets the horrid
font height wart out of settings.c and into the Windows code where
it should be.
The Mac part of this checkin is a bunch of random guesses which will
probably not quite compile, but which look roughly right to me.
Sorry if I screwed it up, Ben :-)

[originally from svn r2765]
  • Loading branch information
sgtatham committed Feb 1, 2003
1 parent ccf35b8 commit f26b7aa
Show file tree
Hide file tree
Showing 30 changed files with 612 additions and 271 deletions.
6 changes: 3 additions & 3 deletions Recipe
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ SFTP = sftp int64 logging
# Pageant or PuTTYgen).
WINMISC = misc version winstore settings tree234 winnet proxy cmdline
+ windefs winmisc
UXMISC = misc version uxstore settings tree234 uxnet proxy cmdline
UXMISC = misc version uxstore settings tree234 uxnet proxy cmdline uxmisc
MACMISC = misc version macstore settings tree234 macnet mtcpnet otnet proxy

# Character set library, for use in pterm.
Expand All @@ -140,11 +140,11 @@ pscp : [C] scp console WINSSH be_none SFTP wildcard WINMISC scp.res LIBS1
psftp : [C] psftp console WINSSH be_none SFTP WINMISC scp.res LIBS1

pageant : [G] pageant sshrsa sshpubk sshdes sshbn sshmd5 version tree234
+ misc sshaes sshsha pageantc sshdss sshsh512 winutils
+ misc sshaes sshsha pageantc sshdss sshsh512 winutils winmisc
+ pageant.res LIBS

puttygen : [G] puttygen sshrsag sshdssg sshprime sshdes sshbn sshmd5 version
+ sshrand noise sshsha winstore misc winctrls sshrsa sshdss
+ sshrand noise sshsha winstore misc winctrls sshrsa sshdss winmisc
+ sshpubk sshaes sshsh512 import winutils puttygen.res LIBS

pterm : [X] pterm terminal wcwidth uxucs uxmisc tree234 misc ldisc ldiscucs
Expand Down
3 changes: 1 addition & 2 deletions cmdline.c
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,7 @@ int cmdline_process_param(char *p, char *value, int need_save, Config *cfg)
if (!strcmp(p, "-i")) {
RETURN(2);
SAVEABLE(1);
strncpy(cfg->keyfile, value, sizeof(cfg->keyfile));
cfg->keyfile[sizeof(cfg->keyfile)-1] = '\0';
cfg->keyfile = filename_from_str(value);
}

return ret; /* unrecognised */
Expand Down
6 changes: 3 additions & 3 deletions console.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ void askcipher(void *frontend, char *ciphername, int cs)
* 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, char *filename)
int askappend(void *frontend, Filename filename)
{
HANDLE hin;
DWORD savemode, i;
Expand All @@ -213,11 +213,11 @@ int askappend(void *frontend, char *filename)
char line[32];

if (console_batch_mode) {
fprintf(stderr, msgtemplate_batch, FILENAME_MAX, filename);
fprintf(stderr, msgtemplate_batch, FILENAME_MAX, filename.path);
fflush(stderr);
return 0;
}
fprintf(stderr, msgtemplate, FILENAME_MAX, filename);
fprintf(stderr, msgtemplate, FILENAME_MAX, filename.path);
fflush(stderr);

hin = GetStdHandle(STD_INPUT_HANDLE);
Expand Down
57 changes: 33 additions & 24 deletions import.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <assert.h>
#include <ctype.h>

#include "putty.h"
#include "ssh.h"
#include "misc.h"

Expand All @@ -23,13 +24,15 @@
((unsigned long)(unsigned char)(cp)[2] << 8) | \
((unsigned long)(unsigned char)(cp)[3]))

int openssh_encrypted(char *filename);
struct ssh2_userkey *openssh_read(char *filename, char *passphrase);
int openssh_write(char *filename, struct ssh2_userkey *key, char *passphrase);
int openssh_encrypted(const Filename *filename);
struct ssh2_userkey *openssh_read(const Filename *filename, char *passphrase);
int openssh_write(const Filename *filename, struct ssh2_userkey *key,
char *passphrase);

int sshcom_encrypted(char *filename, char **comment);
struct ssh2_userkey *sshcom_read(char *filename, char *passphrase);
int sshcom_write(char *filename, struct ssh2_userkey *key, char *passphrase);
int sshcom_encrypted(const Filename *filename, char **comment);
struct ssh2_userkey *sshcom_read(const Filename *filename, char *passphrase);
int sshcom_write(const Filename *filename, struct ssh2_userkey *key,
char *passphrase);

/*
* Given a key type, determine whether we know how to import it.
Expand Down Expand Up @@ -59,10 +62,11 @@ int import_target_type(int type)
/*
* Determine whether a foreign key is encrypted.
*/
int import_encrypted(char *filename, int type, char **comment)
int import_encrypted(const Filename *filename, int type, char **comment)
{
if (type == SSH_KEYTYPE_OPENSSH) {
*comment = dupstr(filename); /* OpenSSH doesn't do key comments */
/* OpenSSH doesn't do key comments */
*comment = dupstr(filename_to_str(*filename));
return openssh_encrypted(filename);
}
if (type == SSH_KEYTYPE_SSHCOM) {
Expand All @@ -74,15 +78,17 @@ int import_encrypted(char *filename, int type, char **comment)
/*
* Import an SSH1 key.
*/
int import_ssh1(char *filename, int type, struct RSAKey *key, char *passphrase)
int import_ssh1(const Filename *filename, int type,
struct RSAKey *key, char *passphrase)
{
return 0;
}

/*
* Import an SSH2 key.
*/
struct ssh2_userkey *import_ssh2(char *filename, int type, char *passphrase)
struct ssh2_userkey *import_ssh2(const Filename *filename, int type,
char *passphrase)
{
if (type == SSH_KEYTYPE_OPENSSH)
return openssh_read(filename, passphrase);
Expand All @@ -94,15 +100,16 @@ struct ssh2_userkey *import_ssh2(char *filename, int type, char *passphrase)
/*
* Export an SSH1 key.
*/
int export_ssh1(char *filename, int type, struct RSAKey *key, char *passphrase)
int export_ssh1(const Filename *filename, int type, struct RSAKey *key,
char *passphrase)
{
return 0;
}

/*
* Export an SSH2 key.
*/
int export_ssh2(char *filename, int type,
int export_ssh2(const Filename *filename, int type,
struct ssh2_userkey *key, char *passphrase)
{
if (type == SSH_KEYTYPE_OPENSSH)
Expand Down Expand Up @@ -309,7 +316,7 @@ struct openssh_key {
int keyblob_len, keyblob_size;
};

struct openssh_key *load_openssh_key(char *filename)
struct openssh_key *load_openssh_key(const Filename *filename)
{
struct openssh_key *ret;
FILE *fp;
Expand All @@ -325,7 +332,7 @@ struct openssh_key *load_openssh_key(char *filename)
ret->encrypted = 0;
memset(ret->iv, 0, sizeof(ret->iv));

fp = fopen(filename, "r");
fp = f_open(*filename, "r");
if (!fp) {
errmsg = "Unable to open key file";
goto error;
Expand Down Expand Up @@ -451,7 +458,7 @@ struct openssh_key *load_openssh_key(char *filename)
return NULL;
}

int openssh_encrypted(char *filename)
int openssh_encrypted(const Filename *filename)
{
struct openssh_key *key = load_openssh_key(filename);
int ret;
Expand All @@ -466,7 +473,7 @@ int openssh_encrypted(char *filename)
return ret;
}

struct ssh2_userkey *openssh_read(char *filename, char *passphrase)
struct ssh2_userkey *openssh_read(const Filename *filename, char *passphrase)
{
struct openssh_key *key = load_openssh_key(filename);
struct ssh2_userkey *retkey;
Expand Down Expand Up @@ -655,7 +662,8 @@ struct ssh2_userkey *openssh_read(char *filename, char *passphrase)
return retval;
}

int openssh_write(char *filename, struct ssh2_userkey *key, char *passphrase)
int openssh_write(const Filename *filename, struct ssh2_userkey *key,
char *passphrase)
{
unsigned char *pubblob, *privblob, *spareblob;
int publen, privlen, sparelen;
Expand Down Expand Up @@ -860,7 +868,7 @@ int openssh_write(char *filename, struct ssh2_userkey *key, char *passphrase)
* And save it. We'll use Unix line endings just in case it's
* subsequently transferred in binary mode.
*/
fp = fopen(filename, "wb"); /* ensure Unix line endings */
fp = f_open(*filename, "wb"); /* ensure Unix line endings */
if (!fp)
goto error;
fputs(header, fp);
Expand Down Expand Up @@ -977,7 +985,7 @@ struct sshcom_key {
int keyblob_len, keyblob_size;
};

struct sshcom_key *load_sshcom_key(char *filename)
struct sshcom_key *load_sshcom_key(const Filename *filename)
{
struct sshcom_key *ret;
FILE *fp;
Expand All @@ -993,7 +1001,7 @@ struct sshcom_key *load_sshcom_key(char *filename)
ret->keyblob = NULL;
ret->keyblob_len = ret->keyblob_size = 0;

fp = fopen(filename, "r");
fp = f_open(*filename, "r");
if (!fp) {
errmsg = "Unable to open key file";
goto error;
Expand Down Expand Up @@ -1095,7 +1103,7 @@ struct sshcom_key *load_sshcom_key(char *filename)
return NULL;
}

int sshcom_encrypted(char *filename, char **comment)
int sshcom_encrypted(const Filename *filename, char **comment)
{
struct sshcom_key *key = load_sshcom_key(filename);
int pos, len, answer;
Expand Down Expand Up @@ -1177,7 +1185,7 @@ static int sshcom_put_mpint(void *target, void *data, int len)
return len+4;
}

struct ssh2_userkey *sshcom_read(char *filename, char *passphrase)
struct ssh2_userkey *sshcom_read(const Filename *filename, char *passphrase)
{
struct sshcom_key *key = load_sshcom_key(filename);
char *errmsg;
Expand Down Expand Up @@ -1407,7 +1415,8 @@ struct ssh2_userkey *sshcom_read(char *filename, char *passphrase)
return ret;
}

int sshcom_write(char *filename, struct ssh2_userkey *key, char *passphrase)
int sshcom_write(const Filename *filename, struct ssh2_userkey *key,
char *passphrase)
{
unsigned char *pubblob, *privblob;
int publen, privlen;
Expand Down Expand Up @@ -1571,7 +1580,7 @@ int sshcom_write(char *filename, struct ssh2_userkey *key, char *passphrase)
* And save it. We'll use Unix line endings just in case it's
* subsequently transferred in binary mode.
*/
fp = fopen(filename, "wb"); /* ensure Unix line endings */
fp = f_open(*filename, "wb"); /* ensure Unix line endings */
if (!fp)
goto error;
fputs("---- BEGIN SSH2 ENCRYPTED PRIVATE KEY ----\n", fp);
Expand Down
26 changes: 17 additions & 9 deletions logging.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
/* log session to file stuff ... */
struct LogContext {
FILE *lgfp;
char currlogfilename[FILENAME_MAX];
Filename currlogfilename;
void *frontend;
Config cfg;
};

static void xlatlognam(char *d, char *s, char *hostname, struct tm *tm);
static void xlatlognam(Filename *d, Filename s, char *hostname, struct tm *tm);

/*
* Log session traffic.
Expand Down Expand Up @@ -113,9 +113,9 @@ void logfopen(void *handle)
tm = *localtime(&t);

/* substitute special codes in file name */
xlatlognam(ctx->currlogfilename, ctx->cfg.logfilename,ctx->cfg.host, &tm);
xlatlognam(&ctx->currlogfilename, ctx->cfg.logfilename,ctx->cfg.host, &tm);

ctx->lgfp = fopen(ctx->currlogfilename, "r"); /* file already present? */
ctx->lgfp = f_open(ctx->currlogfilename, "r"); /* file already present? */
if (ctx->lgfp) {
int i;
fclose(ctx->lgfp);
Expand All @@ -132,7 +132,7 @@ void logfopen(void *handle)
}
}

ctx->lgfp = fopen(ctx->currlogfilename, writemod);
ctx->lgfp = f_open(ctx->currlogfilename, writemod);
if (ctx->lgfp) { /* enter into event log */
/* --- write header line into log file */
fputs("=~=~=~=~=~=~=~=~=~=~=~= PuTTY log ", ctx->lgfp);
Expand All @@ -146,7 +146,7 @@ void logfopen(void *handle)
ctx->cfg.logtype == LGTYP_DEBUG ? "raw" :
ctx->cfg.logtype == LGTYP_PACKETS ? "SSH packets" : "<ukwn>"));
/* Make sure we do not exceed the output buffer size */
strncat(buf, ctx->currlogfilename, 128);
strncat(buf, filename_to_str(ctx->currlogfilename), 128);
buf[strlen(buf)] = '\0';
logevent(ctx->frontend, buf);
}
Expand Down Expand Up @@ -183,7 +183,7 @@ void log_reconfig(void *handle, Config *cfg)
struct LogContext *ctx = (struct LogContext *)handle;
int reset_logging;

if (strcmp(ctx->cfg.logfilename, cfg->logfilename) ||
if (!filename_equal(ctx->cfg.logfilename, cfg->logfilename) ||
ctx->cfg.logtype != cfg->logtype)
reset_logging = TRUE;
else
Expand All @@ -204,10 +204,16 @@ void log_reconfig(void *handle, Config *cfg)
*
* "&Y":YYYY "&m":MM "&d":DD "&T":hhmm "&h":<hostname> "&&":&
*/
static void xlatlognam(char *d, char *s, char *hostname, struct tm *tm) {
static void xlatlognam(Filename *dest, Filename src,
char *hostname, struct tm *tm) {
char buf[10], *bufp;
int size;
int len = FILENAME_MAX-1;
char buffer[FILENAME_MAX];
int len = sizeof(buffer)-1;
char *d, *s;

d = buffer;
s = filename_to_str(src);

while (*s) {
/* Let (bufp, len) be the string to append. */
Expand Down Expand Up @@ -250,4 +256,6 @@ static void xlatlognam(char *d, char *s, char *hostname, struct tm *tm) {
len -= size;
}
*d = '\0';

*dest = filename_from_str(s);
}
Loading

0 comments on commit f26b7aa

Please sign in to comment.