This repository has been archived by the owner on Apr 19, 2024. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
git-svn-id: svn://svn.tartarus.org/sgt/putty@11 cda61777-01e9-0310-a592-d414129be87e
- Loading branch information
simon
committed
Jan 8, 1999
0 parents
commit 374330e
Showing
20 changed files
with
8,474 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,56 @@ | |||
# Makefile for PuTTY. Use `FWHACK=/DFWHACK' to cause the firewall hack | |||
# to be built in. (requires rebuild of ssh.obj only) | |||
|
|||
CFLAGS = /nologo /W3 /YX /O2 /Yd /D_X86_ /D_WINDOWS /DDEBUG /ML /Fd | |||
|
|||
.c.obj: | |||
cl $(FWHACK) $(CFLAGS) /c $*.c | |||
|
|||
OBJS1 = window.obj windlg.obj terminal.obj telnet.obj misc.obj noise.obj | |||
OBJS2 = ssh.obj sshcrc.obj sshdes.obj sshmd5.obj sshrsa.obj sshrand.obj | |||
OBJS3 = sshsha.obj | |||
RESRC = win_res.res | |||
LIBS1 = advapi32.lib user32.lib gdi32.lib | |||
LIBS2 = wsock32.lib comctl32.lib comdlg32.lib | |||
|
|||
putty.exe: $(OBJS1) $(OBJS2) $(OBJS3) $(RESRC) link.rsp | |||
link /debug -out:putty.exe @link.rsp | |||
|
|||
puttyd.exe: $(OBJS1) $(OBJS2) $(OBJS3) $(RESRC) link.rsp | |||
link /debug -out:puttyd.exe @link.rsp | |||
|
|||
link.rsp: makefile | |||
echo /nologo /subsystem:windows > link.rsp | |||
echo $(OBJS1) >> link.rsp | |||
echo $(OBJS2) >> link.rsp | |||
echo $(OBJS3) >> link.rsp | |||
echo $(RESRC) >> link.rsp | |||
echo $(LIBS1) >> link.rsp | |||
echo $(LIBS2) >> link.rsp | |||
|
|||
window.obj: window.c putty.h win_res.h | |||
windlg.obj: windlg.c putty.h ssh.h win_res.h | |||
terminal.obj: terminal.c putty.h | |||
telnet.obj: telnet.c putty.h | |||
misc.obj: misc.c putty.h | |||
noise.obj: noise.c putty.h ssh.h | |||
ssh.obj: ssh.c ssh.h putty.h | |||
sshcrc.obj: sshcrc.c ssh.h | |||
sshdes.obj: sshdes.c ssh.h | |||
sshmd5.obj: sshmd5.c ssh.h | |||
sshrsa.obj: sshrsa.c ssh.h | |||
sshsha.obj: sshsha.c ssh.h | |||
sshrand.obj: sshrand.c ssh.h | |||
|
|||
win_res.res: win_res.rc win_res.h putty.ico | |||
rc $(FWHACK) -r win_res.rc | |||
|
|||
clean: | |||
del *.obj | |||
del *.exe | |||
del *.res | |||
del *.pch | |||
del *.aps | |||
del *.ilk | |||
del *.pdb | |||
del link.rsp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,67 @@ | |||
#include <windows.h> | |||
#include <stdio.h> | |||
#include <stdlib.h> | |||
#include "putty.h" | |||
|
|||
/* My own versions of malloc, realloc and free. Because I want malloc and | |||
* realloc to bomb out and exit the program if they run out of memory, | |||
* realloc to reliably call malloc if passed a NULL pointer, and free | |||
* to reliably do nothing if passed a NULL pointer. Of course we can also | |||
* put trace printouts in, if we need to. */ | |||
|
|||
#ifdef MALLOC_LOG | |||
static FILE *fp = NULL; | |||
|
|||
void mlog(char *file, int line) { | |||
if (!fp) | |||
fp = fopen("putty_mem.log", "w"); | |||
if (fp) | |||
fprintf (fp, "%s:%d: ", file, line); | |||
} | |||
#endif | |||
|
|||
void *safemalloc(size_t size) { | |||
void *p = malloc (size); | |||
if (!p) { | |||
MessageBox(NULL, "Out of memory!", "PuTTY Fatal Error", | |||
MB_SYSTEMMODAL | MB_ICONERROR | MB_OK); | |||
exit(1); | |||
} | |||
#ifdef MALLOC_LOG | |||
if (fp) | |||
fprintf(fp, "malloc(%d) returns %p\n", size, p); | |||
#endif | |||
return p; | |||
} | |||
|
|||
void *saferealloc(void *ptr, size_t size) { | |||
void *p; | |||
if (!ptr) | |||
p = malloc (size); | |||
else | |||
p = realloc (ptr, size); | |||
if (!p) { | |||
MessageBox(NULL, "Out of memory!", "PuTTY Fatal Error", | |||
MB_SYSTEMMODAL | MB_ICONERROR | MB_OK); | |||
exit(1); | |||
} | |||
#ifdef MALLOC_LOG | |||
if (fp) | |||
fprintf(fp, "realloc(%p,%d) returns %p\n", ptr, size, p); | |||
#endif | |||
return p; | |||
} | |||
|
|||
void safefree(void *ptr) { | |||
if (ptr) { | |||
#ifdef MALLOC_LOG | |||
if (fp) | |||
fprintf(fp, "free(%p)\n", ptr); | |||
#endif | |||
free (ptr); | |||
} | |||
#ifdef MALLOC_LOG | |||
else if (fp) | |||
fprintf(fp, "freeing null pointer - no action taken\n"); | |||
#endif | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,148 @@ | |||
/* | |||
* Noise generation for PuTTY's cryptographic random number | |||
* generator. | |||
*/ | |||
|
|||
#include <windows.h> | |||
#include <stdio.h> | |||
|
|||
#include "putty.h" | |||
#include "ssh.h" | |||
|
|||
static char seedpath[2*MAX_PATH+10] = "\0"; | |||
|
|||
/* | |||
* Find the random seed file path and store it in `seedpath'. | |||
*/ | |||
static void get_seedpath(void) { | |||
HKEY rkey; | |||
DWORD type, size; | |||
|
|||
size = sizeof(seedpath); | |||
|
|||
if (RegOpenKey(HKEY_CURRENT_USER, PUTTY_REG_POS, &rkey)==ERROR_SUCCESS) { | |||
int ret = RegQueryValueEx(rkey, "RandSeedFile", | |||
0, &type, seedpath, &size); | |||
if (ret != ERROR_SUCCESS || type != REG_SZ) | |||
seedpath[0] = '\0'; | |||
RegCloseKey(rkey); | |||
} else | |||
seedpath[0] = '\0'; | |||
|
|||
if (!seedpath[0]) { | |||
int len, ret; | |||
|
|||
len = GetEnvironmentVariable("HOMEDRIVE", seedpath, sizeof(seedpath)); | |||
ret = GetEnvironmentVariable("HOMEPATH", seedpath+len, | |||
sizeof(seedpath)-len); | |||
if (ret == 0) { /* probably win95; store in \WINDOWS */ | |||
GetWindowsDirectory(seedpath, sizeof(seedpath)); | |||
len = strlen(seedpath); | |||
} else | |||
len += ret; | |||
strcpy(seedpath+len, "\\PUTTY.RND"); | |||
} | |||
} | |||
|
|||
/* | |||
* This function is called once, at PuTTY startup, and will do some | |||
* seriously silly things like listing directories and getting disk | |||
* free space and a process snapshot. | |||
*/ | |||
|
|||
void noise_get_heavy(void (*func) (void *, int)) { | |||
HANDLE srch; | |||
HANDLE seedf; | |||
WIN32_FIND_DATA finddata; | |||
char winpath[MAX_PATH+3]; | |||
|
|||
GetWindowsDirectory(winpath, sizeof(winpath)); | |||
strcat(winpath, "\\*"); | |||
srch = FindFirstFile(winpath, &finddata); | |||
if (srch != INVALID_HANDLE_VALUE) { | |||
do { | |||
func(&finddata, sizeof(finddata)); | |||
} while (FindNextFile(srch, &finddata)); | |||
FindClose(srch); | |||
} | |||
|
|||
if (!seedpath[0]) | |||
get_seedpath(); | |||
|
|||
seedf = CreateFile(seedpath, GENERIC_READ, | |||
FILE_SHARE_READ | FILE_SHARE_WRITE, | |||
NULL, OPEN_EXISTING, 0, NULL); | |||
|
|||
if (seedf) { | |||
while (1) { | |||
char buf[1024]; | |||
DWORD len; | |||
|
|||
if (ReadFile(seedf, buf, sizeof(buf), &len, NULL) && len) | |||
func(buf, len); | |||
else | |||
break; | |||
} | |||
CloseHandle(seedf); | |||
} | |||
} | |||
|
|||
void random_save_seed(void) { | |||
HANDLE seedf; | |||
|
|||
if (!seedpath[0]) | |||
get_seedpath(); | |||
|
|||
seedf = CreateFile(seedpath, GENERIC_WRITE, 0, | |||
NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); | |||
|
|||
if (seedf) { | |||
int len; | |||
DWORD lenwritten; | |||
void *data; | |||
|
|||
random_get_savedata(&data, &len); | |||
WriteFile(seedf, data, len, &lenwritten, NULL); | |||
CloseHandle(seedf); | |||
} | |||
} | |||
|
|||
/* | |||
* This function is called every time the random pool needs | |||
* stirring, and will acquire the system time in all available | |||
* forms and the battery status. | |||
*/ | |||
void noise_get_light(void (*func) (void *, int)) { | |||
SYSTEMTIME systime; | |||
DWORD adjust[2]; | |||
BOOL rubbish; | |||
SYSTEM_POWER_STATUS pwrstat; | |||
|
|||
GetSystemTime(&systime); | |||
func(&systime, sizeof(systime)); | |||
|
|||
GetSystemTimeAdjustment(&adjust[0], &adjust[1], &rubbish); | |||
func(&adjust, sizeof(adjust)); | |||
|
|||
if (GetSystemPowerStatus(&pwrstat)) | |||
func(&pwrstat, sizeof(pwrstat)); | |||
} | |||
|
|||
/* | |||
* This function is called on every keypress or mouse move, and | |||
* will add the current Windows time and performance monitor | |||
* counter to the noise pool. It gets the scan code or mouse | |||
* position passed in. | |||
*/ | |||
void noise_ultralight(DWORD data) { | |||
DWORD wintime; | |||
LARGE_INTEGER perftime; | |||
|
|||
random_add_noise(&data, sizeof(DWORD)); | |||
|
|||
wintime = GetTickCount(); | |||
random_add_noise(&wintime, sizeof(DWORD)); | |||
|
|||
if (QueryPerformanceCounter(&perftime)) | |||
random_add_noise(&perftime, sizeof(perftime)); | |||
} |
Oops, something went wrong.