9 |
10 |
--------------------------------------------------------------------------------
/src/tftpd32.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | true
5 |
6 |
--------------------------------------------------------------------------------
/src/_common/dialog_common.h:
--------------------------------------------------------------------------------
1 | //////////////////////////////////////////////////////////////////
2 | //
3 | // Projet TFTPD32. Mars 2000 Ph.jounin
4 | //
5 | // released under artistic license (see license.txt)
6 | //
7 | //////////////////////////////////////////////////////////////////
8 |
9 | int SendMsg (SOCKET s, int type, const void *data, int size);
10 |
--------------------------------------------------------------------------------
/doc-help/src/#URLSTR:
--------------------------------------------------------------------------------
1 | FAQ.html Getting Started.html Help Index.html History.html License.html overview.html Protocols Description.html setup DHCP.html setup global.html setup syslog.html setup tftpd.html The TFTP client.html The DNS relay.html Tips.html Settings Entries.html
--------------------------------------------------------------------------------
/src/_libs/event_log/eventlog.h:
--------------------------------------------------------------------------------
1 | //////////////////////////////////////////////////////
2 | //
3 | // Projet TFTPD32. June 2006 Ph.jounin
4 | // File eventlog.h: write error into event log
5 | //
6 | // source released under artistic license (see license.txt)
7 | //
8 | //////////////////////////////////////////////////////
9 |
10 |
11 |
12 | int WriteIntoEventLog (const char *txt, WORD evId);
13 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ################################################################################
2 | # This .gitignore file was automatically created by Microsoft(R) Visual Studio.
3 | ################################################################################
4 |
5 | <<<<<<< HEAD
6 | *.ppj
7 | *.ppw
8 | .gitmodules
9 | /ARTS
10 | /.vs
11 | /src/.vs
12 | /src/obj/Win32/Release
13 | .DS_Store
14 | /src/_services/tftpd32.aps
--------------------------------------------------------------------------------
/src/_libs/log/LogToMonitor.h:
--------------------------------------------------------------------------------
1 | //////////////////////////////////////////////////////
2 | //
3 | // Projet TFTPD32. Mai 98 Ph.jounin - Jan 2003
4 | // File async_log.c: Asynchronous multithread Log management
5 | //
6 | // source released under artistic license (see license.txt)
7 | //
8 | //////////////////////////////////////////////////////
9 |
10 |
11 | #define LOGSIZE 512
12 |
13 | // Synchronous log via OutputDebugString
14 | void LogToMonitor (char *sz, ...);
15 |
16 |
--------------------------------------------------------------------------------
/src/_gui/gui_struct.h:
--------------------------------------------------------------------------------
1 |
2 |
3 | ///////////////////////////////////
4 | // structure of GUI database
5 |
6 | struct S_TftpGui
7 | {
8 | // identifier
9 | DWORD dwTransferId;
10 | // items to be displayed
11 | char *filename;
12 | SOCKADDR_STORAGE stg_addr;
13 | int opcode;
14 | // stats
15 | struct S_Trf_Statistics stat;
16 | // GUI resources
17 | HWND hGaugeWnd;
18 | // next
19 | struct S_TftpGui *next;
20 | };
21 |
--------------------------------------------------------------------------------
/src/_libs/lasterr/lasterr.h:
--------------------------------------------------------------------------------
1 | //////////////////////////////////////////////////////
2 | //
3 | // Projet TFTPD32. Mars 2000 Ph.jounin
4 | // File lasterr.c: function LastErrorText and CopyXXXToClipboard
5 | //
6 | // source released under artistic license (see license.txt)
7 | //
8 | //////////////////////////////////////////////////////
9 |
10 |
11 |
12 | // Function LastErrorText
13 | // A wrapper for FormatMessage : retrieve the message text for a system-defined error
14 | char *LastErrorText (void);
15 |
16 |
--------------------------------------------------------------------------------
/src/_libs/GUI/centerchild.h:
--------------------------------------------------------------------------------
1 | //////////////////////////
2 | // Useful Window proc
3 | // released under European Union Public License (see license.txt)
4 | //////////////////////////
5 |
6 |
7 | // center a window
8 | #define CCW_VISIBLE 0x0010 // window should be inside the physical screen
9 | #define CCW_INSIDE 0x0020 // fails if child window larger than its parent
10 |
11 | BOOL CenterChildWindow (
12 | HWND hChildWnd, // Wnd which have to be centered
13 | int uType // options
14 | );
15 |
--------------------------------------------------------------------------------
/Readme.md:
--------------------------------------------------------------------------------
1 | **Project Description**
2 |
3 | Tftpd64 is a lightweight multi-threaded set of servers : TFTP, DNS, SNTP, SYSLOG and DHCP.
4 |
5 | >
6 | [Go to the wiki page](https://github.com/PJO2/tftpd64//wiki/)
7 | [Go to the download page](https://github.com/PJO2/tftpd64/releases)
8 | [Quick download the recommended release (v4.72 64 bits standard edition)](https://github.com/PJO2/tftpd64/releases/download/v4.72/Tftpd64_Installer_v4.72.exe)
9 |
10 | 
11 |
--------------------------------------------------------------------------------
/src/_libs/GUI/listview.h:
--------------------------------------------------------------------------------
1 | // source released under artistic license (see license.txt)
2 | //
3 |
4 |
5 | struct S_LVHeader
6 | {
7 | int fmt; // format (cf LVCOLUMN)
8 | int cx; // width
9 | char *pszText; // title
10 | } ;
11 |
12 | void SetViewMode (HWND hwndLV, DWORD dwView, DWORD dwExtStyle);
13 | BOOL InitTftpd32ListView (HWND hListV, const struct S_LVHeader *tCol, int Nb, DWORD swExtStyle);
14 | LRESULT ProcessCustomDraw (LPARAM lParam);
15 |
16 | int CALLBACK CompareStringFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort);
17 |
18 |
19 |
--------------------------------------------------------------------------------
/src/_services/async_log.h:
--------------------------------------------------------------------------------
1 | //////////////////////////////////////////////////////
2 | //
3 | // Projet TFTPD32. Mai 98 Ph.jounin - Jan 2003
4 | // File async_log.c: Asynchronous multithread Log management
5 | //
6 | // source released under artistic license (see license.txt)
7 | //
8 | //////////////////////////////////////////////////////
9 |
10 |
11 | #define MAX_MSG_IN_QUEUE 300
12 | #define LOGSIZE 512
13 |
14 | // Asynchronous log
15 | void __cdecl LOG (int DebugLevel, const char *szFmt, ...);
16 | void __cdecl SVC_ERROR (const char *szFmt, ...);
17 | void __cdecl SVC_WARNING (const char *szFmt, ...);
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/src/_libs/GUI/cmsgbox.h:
--------------------------------------------------------------------------------
1 |
2 | // --------------------------------------------
3 | // A plain-C replacement for MessageBox command
4 | //
5 | // myMsgBox opens a messagebox-like modal window at the center of the parent window
6 | //
7 | // by Ph. Jounin Oct 2015
8 | // release under GPLv2 license
9 | // --------------------------------------------
10 |
11 |
12 | int __cdecl CMsgBox(
13 | HWND hParentWnd, // handle of owner window
14 | LPCTSTR lpText, // address of text in message box
15 | LPCTSTR lpCaption, // address of title of message box
16 | UINT uType, // style of message box
17 | ... // follow lpText
18 | );
19 |
--------------------------------------------------------------------------------
/src/_libs/convert/convert.h:
--------------------------------------------------------------------------------
1 | //////////////////////////////////////////////////////
2 | //
3 | // Projet TFTPD32. Nov 2010 Ph.jounin
4 | // File convert.c : Convert text settings to structure
5 | //
6 | // source released under European Union Public License
7 | //
8 | //////////////////////////////////////////////////////
9 |
10 |
11 | #include
12 | #include "convert.h"
13 |
14 |
15 | // translate an "SnmpSet" String into a Setting structure
16 | int ConvertTextToSettings (const char *szTxt, struct S_Setttings *pSettings);
17 | {
18 |
19 | } // ConvertTextToSettings
20 |
21 |
22 | int ConvertSettingsTotext (const struct S_Setttings *pSettings, char *szTxt);
--------------------------------------------------------------------------------
/src/_libs/dump/dump.h:
--------------------------------------------------------------------------------
1 |
2 | /* --------------------
3 | * dump.c is an extract form Tcp4u and therefore released under GPL license
4 | * --------------------- */
5 |
6 |
7 | /* -------------------------------------------------------------- */
8 | /* dump a binary or text frame. The output is the debug window */
9 | /* for Windows system and stderr for unix */
10 | /* The code is a port of the xdump function from the cmu snmp lib */
11 | /* Ajout du cast (unsigned char) */
12 | /* -------------------------------------------------------------- */
13 | void BinDump (LPCSTR cp, int nLen, LPCSTR szPrefix);
14 | void OutputDebugStringW95 (LPCTSTR lpOutputString);
15 |
--------------------------------------------------------------------------------
/installers/tftpd32.ini:
--------------------------------------------------------------------------------
1 | [DHCP]
2 | Lease_NumLeases=0
3 | [TFTPD32]
4 | BaseDirectory=.
5 | TftpPort=69
6 | Hide=0
7 | WinSize=0
8 | Negociate=1
9 | PXECompatibility=0
10 | DirText=0
11 | ShowProgressBar=1
12 | Timeout=3
13 | MaxRetransmit=6
14 | SecurityLevel=1
15 | UnixStrings=1
16 | Beep=0
17 | VirtualRoot=0
18 | MD5=0
19 | LocalIP=
20 | Services=15
21 | TftpLogFile=
22 | SaveSyslogFile=
23 | PipeSyslogMsg=0
24 | LowestUDPPort=0
25 | HighestUDPPort=0
26 | MulticastPort=0
27 | MulticastAddress=
28 | PersistantLeases=1
29 | DHCP Ping=1
30 | DHCP LocalIP=
31 | Max Simultaneous Transfers=100
32 | UseEventLog=0
33 | Console Password=tftpd32
34 | Support for port Option=0
35 | UseEventLog=0
36 | Keep transfer Gui=5
37 | Ignore ack for last TFTP packet=0
38 | Enable IPv6=0
39 |
--------------------------------------------------------------------------------
/src/_libs/convert/convert.c:
--------------------------------------------------------------------------------
1 | //////////////////////////////////////////////////////
2 | //
3 | // Projet TFTPD32. Nov 2010 Ph.jounin
4 | // File convert.h : Convert text settings to structure
5 | //
6 | // source released under European Union Public License
7 | //
8 | //////////////////////////////////////////////////////
9 |
10 | enum {
11 | E_STG_ADDRIP = 'a',
12 | E_STG_CHAR = 'c',
13 | E_STG_INTEGER = 'i',
14 | E_STG_STRING = 's',
15 | };
16 |
17 | #define MAX_STG_DATA 20
18 |
19 | struct S_Settings
20 | {
21 | char cType;
22 | unsigned int nLen;
23 | char cData [MAX_STG_DATA];
24 | };
25 |
26 | int ConvertTextToSettings (const char *szTxt, struct S_Setttings *pSettings);
27 | int ConvertSettingsTotext (const struct S_Setttings *pSettings, char *szTxt);
28 |
29 |
30 |
--------------------------------------------------------------------------------
/src/readme.txt:
--------------------------------------------------------------------------------
1 | This is the complete source code for Tftpd32 and Tftpd64, the industry standard TFTP server.
2 |
3 | The code is splitted into 2 parts :
4 | - the GUI management (main thread)
5 | - the background process (other threads)
6 |
7 | They communicate together by messages sent through a TCP socket. In addition to separate processing and display, this allow a remote monitoring for the service edition.
8 |
9 | _common and _libs directories contains files which belongs to both parts.
10 | GUI processing is in the _gui directory.
11 | Demon and background processing is found into _services directory.
12 | Initializations are in the _main directory
13 |
14 | tftpd32.sln and .vcxproj files are the project files necessary for building the executables with Visual Studio.
15 |
16 | All code is released under the European Union Public License, which is compatible with the GPLv2.
17 |
--------------------------------------------------------------------------------
/src/_libs/md5/global.h:
--------------------------------------------------------------------------------
1 | /* GLOBAL.H - RSAREF types and constants
2 | */
3 |
4 | /* PROTOTYPES should be set to one if and only if the compiler supports
5 | function argument prototyping.
6 | The following makes PROTOTYPES default to 0 if it has not already
7 |
8 | been defined with C compiler flags.
9 | */
10 | #ifndef PROTOTYPES
11 | #define PROTOTYPES 1
12 | #endif
13 |
14 | /* POINTER defines a generic pointer type */
15 | typedef unsigned char *POINTER;
16 |
17 | /* UINT2 defines a two byte word */
18 | typedef unsigned short int UINT2;
19 |
20 | /* UINT4 defines a four byte word */
21 | typedef unsigned long int UINT4;
22 |
23 | /* PROTO_LIST is defined depending on how PROTOTYPES is defined above.
24 | If using PROTOTYPES, then PROTO_LIST returns the list, otherwise it
25 | returns an empty list.
26 | */
27 | #if PROTOTYPES
28 | #define PROTO_LIST(list) list
29 | #else
30 | #define PROTO_LIST(list) ()
31 | #endif
32 |
--------------------------------------------------------------------------------
/src/_common/dialog_common.c:
--------------------------------------------------------------------------------
1 | //////////////////////////////////////////////////////
2 | //
3 | // Projet TFTPD32. Mars 2000 Ph.jounin
4 | // File dialog_common.c:
5 | // A sendmsg API for both GUI and services
6 | // It's a kind of TcpPPSend with a complimentory
7 | // integer parameter
8 | //
9 | // released under European Union Public License
10 | //
11 | //////////////////////////////////////////////////////
12 |
13 |
14 |
15 | #include "headers.h"
16 | #include
17 | #include
18 |
19 |
20 | int SendMsg (SOCKET s, int type, const void *data, int size)
21 | {
22 | int Rc=1;
23 | unsigned short full_size = htons (size + sizeof type);
24 | if (data==NULL) size=0;
25 | // send length of message
26 | Rc = send (s, (char *) & full_size, sizeof full_size, 0);
27 | Rc = send (s, (char *) & type, sizeof type, 0);
28 | if (size>0) Rc = TcpSend (s, data, size, 0);
29 | return Rc;
30 | } // SendMsg
31 |
32 |
33 |
--------------------------------------------------------------------------------
/doc-help/src/The DNS relay.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | The DNS relay
6 |
7 |
8 |
9 |
10 |
11 |
Using the DNS relay
12 |
13 |
14 |
15 |
Manage the host table
16 | Tftpd32 uses the API getaddrinfo to resolve the domain name.
17 |
18 | This API tries to find the host name in the file
19 | %SystemRoot%\System32\drivers\etc\hosts (or the file pointed by the registry key
20 | \HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\DataBasePath).
21 |
22 | Populate this file with your hosts and Tftpd32 will propagate the info.
23 |
24 | If getaddrinfo founds no suitable host, it relays the request to the DNS server.
25 |
26 |
27 |
--------------------------------------------------------------------------------
/src/_libs/registry/registry.h:
--------------------------------------------------------------------------------
1 | //////////////////////////////////////////////////////
2 | //
3 | // Projet TFTPD32. May 1998 Ph.jounin
4 | // Projet DHCPD32. January 2006 Ph.jounin
5 | // File registry.h: Settings
6 | //
7 | // source released under artistic License (see license.txt)
8 | //
9 | //////////////////////////////////////////////////////
10 |
11 | // registry key :
12 | // HKEY_LOCAL_MACHINE\SOFTWARE\TFTPD32
13 |
14 | int ReadKey (const char *szRegPath, const char *szKey,
15 | void *buf, int BufSize, int nType,
16 | const char *szIniFile);
17 | int AsyncSaveKey (const char *szRegPath, const char *szKey,
18 | void *buf, int BufSize, int nType,
19 | const char *szIniFile);
20 | int SaveKey (const char *szRegPath, const char *szKey,
21 | void *buf, int BufSize, int nType,
22 | const char *szIniFile);
23 | int InitAsyncSaveKey ();
24 | int CleanupAsyncSaveKey ();
25 |
26 |
--------------------------------------------------------------------------------
/src/_libs/linked_list/linked_list.h:
--------------------------------------------------------------------------------
1 | //
2 | // source released under artistic license (see license.txt)
3 | //
4 |
5 |
6 | struct savemsg
7 | {
8 | struct savemsg *next;
9 | int size; // sizeof following data
10 | int msg_id; // ident of the item given by LL_PushMsg
11 |
12 | void *data; // the user data is saved here
13 | int type; // complimentary integer stored
14 | }; // savemsg
15 |
16 |
17 | // Create a new linked list
18 | int LL_Create (int id, int max_msg);
19 | void LL_Destroy (int id);
20 | int LL_PushMsg (int id, const void *lpData, int dwSize);
21 | void *LL_PopMsg (int id);
22 | int LL_PushTypedMsg (int id, const void *lpData, int dwSize, int type);
23 | void *LL_PopTypedMsg (int id, int *plen, int *pmsg_id, int *ptype);
24 |
25 | void WaitForMsgQueueToFinish (int id);
26 |
27 |
28 | // we use 3 linked List
29 | #define LL_ID_LOG 0
30 | #define LL_ID_SETTINGS 1
31 | #define LL_ID_MSG_TO_GUI 2
32 |
33 |
34 |
--------------------------------------------------------------------------------
/src/_libs/event_log/eventlog.c:
--------------------------------------------------------------------------------
1 | //////////////////////////////////////////////////////
2 | //
3 | // Projet TFTPD32. June 2006 Ph.jounin
4 | // File eventlog.c : write event into event log
5 | //
6 | // source released under European Union Public License
7 | //
8 | //////////////////////////////////////////////////////
9 |
10 |
11 |
12 | #include
13 | #include "eventlog.h"
14 |
15 | int WriteIntoEventLog (const char *txt, WORD evId)
16 | {
17 | HANDLE hEvLog;
18 | int Rc = (int)INVALID_HANDLE_VALUE;
19 | const char *t[] = { "\n", txt };
20 | hEvLog = RegisterEventSource (NULL, "Tftpd32");
21 | if ( hEvLog != INVALID_HANDLE_VALUE )
22 | {
23 | Rc = ReportEvent ( hEvLog,
24 | EVENTLOG_ERROR_TYPE,
25 | 0, // wCategory
26 | evId, // identifier
27 | NULL, // security
28 | sizeof t / sizeof t[0], // one string to add
29 | lstrlen (txt),
30 | t,
31 | (void *) txt );
32 | DeregisterEventSource (hEvLog);
33 | }
34 | return Rc;
35 | } // WriteIntoEventLog
36 |
--------------------------------------------------------------------------------
/installers/3-sign-releases.bat:
--------------------------------------------------------------------------------
1 | @echo off
2 | setlocal
3 |
4 | REM -- Check for cert thumbprint --
5 | if "%SIGN_CERT_THUMBPRINT%"=="" (
6 | echo [ERROR] SIGN_CERT_THUMBPRINT is not defined. Please set it before running this script.
7 | exit /b 1
8 | )
9 |
10 | REM -- Path to signtool --
11 | set SIGNTOOL="C:\Program Files (x86)\Windows Kits\10\App Certification Kit\signtool.exe"
12 | set RELEASE_DIR=..\releases
13 |
14 | echo Signing only unsigned .exe files in %RELEASE_DIR% ...
15 |
16 | pushd %RELEASE_DIR%
17 |
18 | for %%F in (*%VERSION%.exe) do (
19 | echo Checking %%F ...
20 | powershell -Command ^
21 | "if ((Get-AuthenticodeSignature '%%F').Status -eq 'Valid') { exit 0 } else { exit 1 }"
22 | if not errorlevel 1 (
23 | echo [SKIP] %%F is already signed.
24 | ) else (
25 | echo [SIGN] %%F ...
26 | %SIGNTOOL% sign /sha1 %SIGN_CERT_THUMBPRINT% /tr http://time.certum.pl /td sha256 /fd sha256 /v "%%F"
27 | if errorlevel 1 (
28 | echo [ERROR] Signing failed for %%F
29 | exit /b 1
30 | )
31 | )
32 | )
33 |
34 | popd
35 |
36 | echo Done.
37 | endlocal
38 |
--------------------------------------------------------------------------------
/src/_libs/log/LogToMonitor.c:
--------------------------------------------------------------------------------
1 | //////////////////////////////////////////////////////
2 | //
3 | // Projet TFTPD32. March 2007 Ph.jounin
4 | // File logtomonitor.c: multithread Log management
5 | //
6 | // source released under European Union Public License
7 | //
8 | //////////////////////////////////////////////////////
9 |
10 |
11 |
12 | #include
13 | #include
14 | #include
15 |
16 | #include "logtomonitor.h"
17 |
18 |
19 | ///////////////////////////////
20 | // Synchronous log to debug string
21 | // use DBwin to display debug strings
22 | ///////////////////////////////
23 |
24 | void LogToMonitor (char *fmt, ...)
25 | {
26 | va_list args;
27 | char sz [LOGSIZE];
28 | int n;
29 |
30 | sz[sizeof sz - 1] = 0;
31 | va_start (args, fmt );
32 | #ifdef MSVC
33 | n = sprintf_s (sz, sizeof sz - 1, "Th%5d :", GetCurrentThreadId ());
34 | vsprintf_s (& sz[n], sizeof sz - n - 1, fmt, args );
35 | #else
36 | n = sprintf (sz, "Th%5d :", GetCurrentThreadId ());
37 | wvsprintf (& sz[n], fmt, args );
38 | #endif
39 | OutputDebugString (sz);
40 |
41 | } // LogToFile
42 |
--------------------------------------------------------------------------------
/doc-help/src/setup global.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Tftpd32 settings
6 |
7 |
8 |
9 |
10 |
11 |
The Settings Window : Syslog
12 |
13 |
14 |
15 | The settings window allows you to start or stop the different services offerred by Tftpd32.
16 |
17 |
18 |
19 |
20 |
Start Services
21 |
22 |
Services
23 |
Each checkbox start or stop one service
24 |
Enable IPv6
25 |
Allow dual stack services (need at least Windows Vista or Windows server 2008)
26 |
13 |
14 |
15 | Just start tftpd32.exe (probably you have started it already). You get the following window :
16 |
17 |
18 |
19 |
20 | Tftpd32 has already started
21 |
22 |
23 |
a TFTP server
24 |
a DHCP server (listening mode only)
25 |
a Syslog Server
26 |
27 |
28 | The Syslog server is already full fonctionnal, however you need at least to
29 | configure the TFTP directory (current directory is the default) and the
30 | DHCP server must be configured to answer requests.
31 |
32 | To change the directory, either use the Browse button, or go into the settings window.
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/doc-help/src/setup syslog.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | syslog settings
6 |
7 |
8 |
9 |
10 |
11 |
The Settings Window : Syslog
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
Syslog Settings
20 |
21 |
Forward msg to pipe Tftpd32Syslog :
22 |
Each valid message received by Tftpd32 is forwarded into the named pipe Tftpd32Syslog. Like this another application may receive syslog notifications.
23 |
Save Syslog messages
24 |
Each valid message is timestamped and saved into the designated file
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/src/_libs/lasterr/lasterr.c:
--------------------------------------------------------------------------------
1 | //////////////////////////////////////////////////////
2 | //
3 | // Projet TFTPD32. Mars 2000 Ph.jounin
4 | // File lasterr.c: function LastErrorText
5 | //
6 | // source released under European Union Public License
7 | //
8 | //////////////////////////////////////////////////////
9 |
10 | #include
11 | #include "lasterr.h"
12 |
13 |
14 | // Function LastErrorText
15 | // A wrapper for FormatMessage : retrieve the message text for a system-defined error
16 | char *LastErrorText (void)
17 | {
18 | static char szLastErrorText [512];
19 | LPVOID lpMsgBuf;
20 | LPSTR p;
21 |
22 | FormatMessage(
23 | FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
24 | NULL,
25 | GetLastError(),
26 | MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
27 | (LPTSTR) &lpMsgBuf,
28 | 0,
29 | NULL );
30 | memset (szLastErrorText, 0, sizeof szLastErrorText);
31 | lstrcpyn (szLastErrorText, lpMsgBuf, sizeof szLastErrorText);
32 | // Free the buffer.
33 | LocalFree( lpMsgBuf );
34 | // remove ending \r\n
35 | p = strchr (szLastErrorText, '\r');
36 | if (p!=NULL) *p = 0;
37 | return szLastErrorText;
38 | } // LastErrorText
39 |
40 |
41 |
--------------------------------------------------------------------------------
/src/_services/service_main.c:
--------------------------------------------------------------------------------
1 | //////////////////////////////////////////////////////
2 | //
3 | // Projet TFTPD32. Feb 99 By Ph.jounin
4 | // File start_threads.c: Thread management
5 | //
6 | // The main function of the service
7 | //
8 | // source released under European Union Public License
9 | //
10 | //////////////////////////////////////////////////////
11 |
12 |
13 | #include "headers.h"
14 | #include
15 | #include "threading.h"
16 | #include "bootpd_functions.h"
17 |
18 |
19 | void StartTftpd32Services (void *param)
20 | {
21 | char sz[_MAX_PATH];
22 |
23 | // read log level (env var TFTP_LOG)
24 | if (GetEnvironmentVariable (TFTP_LOG, sz, sizeof sz)!=0)
25 | sSettings.LogLvl = atoi (sz);
26 | else sSettings.LogLvl = TFTPD32_DEF_LOG_LEVEL;
27 |
28 | // search for the ini file
29 | SetIniFileName(INI_FILE, szTftpd32IniFile, sizeof szTftpd32IniFile);
30 |
31 | // Read settings (tftpd32.ini)
32 | #ifndef TFTP_CLIENT_ONLY
33 | Tftpd32ReadSettings ();
34 | #else
35 | sSettings.uServices = TFTPD32_TFTP_CLIENT;
36 | #endif
37 | // DHCPReadConfig ();
38 |
39 | // starts worker threads
40 | StartMultiWorkerThreads (FALSE);
41 | LogToMonitor ("Worker threads started\n");
42 | } // StartTftpd32Services
43 |
44 | void StopTftpd32Services (void)
45 | {
46 | TerminateWorkerThreads (FALSE);
47 | }
48 |
49 |
--------------------------------------------------------------------------------
/src/_services/console_actions.c:
--------------------------------------------------------------------------------
1 | //////////////////////////////////////////////////////
2 | //
3 | // Projet TFTPD32. April 2007 Ph.jounin
4 | // A free TFTP server for Windows
5 | // File console_action.c: reply to complex GUI request
6 | // All procedures are handled by console thread
7 | //
8 | // source released under European Union Public License
9 | //
10 | //////////////////////////////////////////////////////
11 |
12 | #include "headers.h"
13 | #include "threading.h"
14 | #include
15 |
16 | static struct S_DirectoryContent Dir;
17 |
18 | int SendDirectoryContentCbk (char *sz_line_descr, DWORD dummy)
19 | {
20 | if (Dir.nb < SizeOfTab (Dir.ent))
21 | {
22 | lstrcpyn (Dir.ent[Dir.nb++].file_descr, sz_line_descr, sizeof Dir.ent[Dir.nb++].file_descr - 1);
23 | }
24 | return TRUE;
25 | } // SendDirectoryContentCbk
26 |
27 | // Copy directory content into a S_DirectoryContent Structure
28 | void SendDirectoryContent (void)
29 | {
30 | memset (&Dir, 0, sizeof Dir);
31 | ScanDir (SendDirectoryContentCbk, 0, sSettings.szWorkingDirectory);
32 | SendMsgRequest ( C_REPLY_DIRECTORY_CONTENT,
33 | & Dir,
34 | Dir.nb * sizeof Dir.ent[0] + offsetof (struct S_DirectoryContent, ent),
35 | FALSE,
36 | FALSE );
37 | } // SendDirectoryContent
38 |
--------------------------------------------------------------------------------
/src/_libs/GUI/window.h:
--------------------------------------------------------------------------------
1 | //////////////////////////////////////////////////////
2 | //
3 | // Projet TFTPD32. Mai 98 Ph.jounin
4 | // File window.c: re usable windows functions
5 | //
6 | // source released under artistic license (see license.txt)
7 | //
8 | //////////////////////////////////////////////////////
9 |
10 |
11 | int OpenNewDialogBox ( HWND hParentWnd,
12 | DWORD dwDlgBox,
13 | DLGPROC lpProc,
14 | LPARAM lParam,
15 | HINSTANCE hInstance);
16 | /* Attach and destroy icon to the TaskTray */
17 | void TrayMessage(HWND hDlg, DWORD dwMessage, HICON hIcon, int TaskTrayId, int uCallBackMsg);
18 |
19 | /* Create an hidden background window */
20 | HWND CreateBckgWindow (HWND hWnd, WORD wMessage, WNDPROC CbkProc,
21 | const char *szName, const char *szAppli);
22 |
23 |
24 | /* Copy the content of a List Box into ClipBoard */
25 | void CopyListBoxToClipboard (HWND hListBox);
26 |
27 | /* Copy the content of a List View into ClipBoard */
28 | void CopyListViewToClipboard (HWND hListV, int nbSubItems);
29 |
30 |
31 | /* Copy a string into Clipboard */
32 | BOOL CopyTextToClipboard (const char *sz);
33 |
34 | /* copy a combo box into another one */
35 | int CopyCBContent (HWND hFromCB, HWND hToCB, const char *lpszFind, int family);
36 |
--------------------------------------------------------------------------------
/doc-help/src/Protocols Description.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Protocols Description
6 |
7 |
8 |
9 |
10 |
11 |
Protocols Description
12 |
13 |
14 |
15 |
TFTP
16 | Trivial File
17 | Transfer Protocol was first defined in 1980, it is a lightweight
18 | version of the FTP protocol that has no directory browsing or password
19 | capability. Employing UDP rather than TCP for transport, TFTP is
20 | typically used to transfer firmware upgrades to network equipment such
21 | as routers, switches and IP phones.It is also used to boot diskless
22 | computers (PXE).
23 |
24 |
SNTP
25 | Simple Network
26 | Timle Protocol is a simplified version of NTP (Network Time Protocol).
27 | They synchronise the time on workstations across a network.
28 |
29 |
DHCP
30 | DHCP assigns IP
31 | addresses to client stations logging onto a TCP/IP network. It
32 | eliminates having to manually assign permanent IP addresses on each
33 | station.
34 |
35 |
35 |
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/src/_services/bootpd_functions.h.bak:
--------------------------------------------------------------------------------
1 |
2 | // bootpd_util.h
3 | //
4 | // source released under artistic license (see license.txt)
5 | //
6 |
7 |
8 | #define FREE_DHCP_ADDRESS "FF:FF:FF:FF:FF:FF"
9 |
10 | int DHCPSaveConfig ( const struct S_DHCP_Param *pNewParamDHCP );
11 | int DHCPReadConfig ( void );
12 |
13 | int IsMacEmpty (struct LL_IP* pcur);
14 | int QsortCompare (const void *p1, const void *p2);
15 | int MACCompare (const void* p1, const void* p2);
16 | void IncNumAllocated (void);
17 | void DecNumAllocated (void);
18 | void SetNumAllocated(int n);
19 | void SetIP (struct LL_IP* pCur, DWORD newip);
20 | void SetMacAddr (struct LL_IP* pCur, const unsigned char *pMac, int nMacLen);
21 | void ZeroMacAddr (struct LL_IP* pCur);
22 | void SetAllocTime (struct LL_IP* pCur);
23 | void ZeroAllocTime (struct LL_IP* pCur);
24 | void SetRenewTime (struct LL_IP* pCur);
25 | void ForceRenewTime (struct LL_IP* pCur, time_t newtime);
26 | void ZeroRenewTime (struct LL_IP* pCur);
27 | void ReorderLeases (void);
28 | void LoadLeases (void);
29 | void FreeLeases (BOOL freepool);
30 | struct LL_IP *DHCPSearchByIP (const struct in_addr *pAddr, BOOL* wasexpired);
31 | struct LL_IP *DHCPSearchByMacAddress (const unsigned char *pMac, int nMacLen);
32 |
33 | void Dhcp_Send_Leases ( struct LL_IP *tIP[], int nbLeases);
34 | void DHCPDestroyItem (struct LL_IP *pCur);
35 |
36 | int TranslateParam2Value (char *buffer, int len, const char *opt_val, struct in_addr ip, const char *tMac);
37 | int ArpDeleteHost(struct in_addr addr);
38 |
39 |
--------------------------------------------------------------------------------
/src/_libs/md5/md5.h:
--------------------------------------------------------------------------------
1 | /* MD5.H - header file for MD5C.C
2 | */
3 |
4 | /* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
5 | rights reserved.
6 |
7 | License to copy and use this software is granted provided that it
8 | is identified as the "RSA Data Security, Inc. MD5 Message-Digest
9 | Algorithm" in all material mentioning or referencing this software
10 | or this function.
11 |
12 | License is also granted to make and use derivative works provided
13 | that such works are identified as "derived from the RSA Data
14 | Security, Inc. MD5 Message-Digest Algorithm" in all material
15 | mentioning or referencing the derived work.
16 |
17 | RSA Data Security, Inc. makes no representations concerning either
18 | the merchantability of this software or the suitability of this
19 | software for any particular purpose. It is provided "as is"
20 | without express or implied warranty of any kind.
21 |
22 | These notices must be retained in any copies of any part of this
23 | documentation and/or software.
24 | */
25 |
26 | /* MD5 context. */
27 | typedef struct {
28 | UINT4 state[4]; /* state (ABCD) */
29 | UINT4 count[2]; /* number of bits, modulo 2^64 (lsb first) */
30 | unsigned char buffer[64]; /* input buffer */
31 | } MD5_CTX;
32 |
33 | void MD5Init PROTO_LIST ((MD5_CTX *));
34 | void MD5Update PROTO_LIST
35 | ((MD5_CTX *, unsigned char *, unsigned int));
36 | void MD5Final PROTO_LIST ((unsigned char [16], MD5_CTX *));
37 |
38 |
--------------------------------------------------------------------------------
/doc-help/src/The TFTP client.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | The TFTP client
6 |
7 |
8 |
9 |
10 |
11 |
Using the TFTP client
12 |
13 |
14 |
15 |
Download
16 | To download a file (get it from the server) you need to know :
17 |
18 |
The name of the server or its IP address
19 |
The name of the file on the server
20 |
21 | You have to fill the fields Host and Remote File then click on the Get button, the transfer will start.
22 | If you want to change the name of the file, you may complete the field Local File.
23 |
24 |
25 |
Upload
26 | To upload a file (put it on the server), you need to know
27 |
15 | Select an address from the combobox. Tftpd32 copies it into the clipboard.
16 |
17 | Select a file from the directory dialog box. Tftpd32 copies the file name into the clipboard.
18 |
19 |
20 |
21 |
Transfer files using drag and drop ?
22 | Just pick up your files from an explorer window and send them into the field Local File.
23 |
24 |
25 |
26 |
27 |
Use an ini file for settings ?
28 | By default, Tftpd32 uses the registry to save its settings.However
29 | if you create an empty file names tftpd32.ini in the same directory
30 | than tftpd32.exe, it will write its settings there.
31 | Note that restoring default settings deletes all registry entries and the tftpd32.ini file.
32 |
33 |
34 |
Make a portable application, which writes no settings at all ?
35 | Just create a empty read only tftpd32.ini file.
36 |
37 |
38 |
Use Tftpd32 to assign static DHCP address
39 | Open tftpd32.ini file with your favorite editor.
40 | In the DHCP section, create an entry where the key is the mac address and its value is the IP address.
41 | For instance,
42 | 0A:0B:0C:0D:0E:0F=192.168.1.75
43 | Note: if the pool size is 0, Tftpd32 assigns no dynamic address, but distributes static ones.
44 |
45 |
46 |
47 |
--------------------------------------------------------------------------------
/src/_gui/gui_syslogd.c:
--------------------------------------------------------------------------------
1 | //////////////////////////////////////////////////////
2 | //
3 | // Projet TFTPD32. Mai 98 Ph.jounin
4 | // File qui_syslogd.c: Syslog
5 | //
6 | //////////////////////////////////////////////////////
7 |
8 | #include "headers.h"
9 | #include
10 |
11 |
12 | // number of messages kept
13 | #define MAX_MSG 500
14 |
15 |
16 |
17 |
18 | // ---------------------------------------------------------------------
19 | //
20 | // ListView Management
21 | //
22 | // ---------------------------------------------------------------------
23 |
24 |
25 |
26 | void AddSyslogItem (HWND hListV, const char *szIP, const char *szTxt)
27 | {
28 | LVITEM LvItem;
29 | int itemPos;
30 | char szDate [32];
31 | SYSTEMTIME sTime;
32 |
33 | // date of entry
34 | GetLocalTime (&sTime);
35 | wsprintf (szDate, "%02d/%02d %02d:%02d:%02d.%03d",
36 | sTime.wDay, sTime.wMonth,
37 | sTime.wHour, sTime.wMinute, sTime.wSecond, sTime.wMilliseconds );
38 |
39 | // keep only MAX_MSG messages
40 | while (ListView_GetItemCount (hListV) >= MAX_MSG)
41 | ListView_DeleteItem (hListV, 0) ;
42 |
43 | LvItem.mask = LVIF_PARAM | LVIF_STATE;
44 | // LvItem.mask = 0;
45 | LvItem.state = 0;
46 | LvItem.stateMask = 0;
47 | LvItem.iItem = ListView_GetItemCount (hListV); // item pos
48 | LvItem.lParam = 0; // sorting params
49 | LvItem.iSubItem = 0; // column index
50 | // LvItem.pszText = "";
51 |
52 | itemPos = ListView_InsertItem(hListV,(LPARAM)&LvItem);
53 | ListView_SetItemText (hListV, itemPos, 0, (char *) szTxt);
54 | ListView_SetItemText (hListV, itemPos, 1, (char *) szIP);
55 | ListView_SetItemText (hListV, itemPos, 2, szDate);
56 |
57 | // if no row is selected, scroll to the last item
58 | if (ListView_GetSelectedCount (hListV) == 0)
59 | ListView_EnsureVisible (hListV, ListView_GetItemCount (hListV) - 1, TRUE);
60 | } // AddSyslogItem
61 |
62 |
63 |
--------------------------------------------------------------------------------
/src/_services/bootpd_console.c.bak:
--------------------------------------------------------------------------------
1 | //////////////////////////////////////////////////////
2 | //
3 | // Projet TFTPD32. January 2006 Ph.jounin
4 | // Projet DHCPD32. January 2006 Ph.jounin
5 | // File bootpd_console.c: DHCP Reporting
6 | //
7 | // source released under European Union Public License
8 | //
9 | //////////////////////////////////////////////////////
10 |
11 | #ifndef TFTPD32
12 | # pragma message (" Bootp_file : Dhcpd32 compilation")
13 | # include
14 | # include
15 | # include
16 | # include "cmsgbox.h"
17 | # include "dhcpd.h"
18 | # include "dhcpd32.h"
19 | # include
20 | # include // offsetof
21 | # include
22 | #else
23 | // TFTPD32's compilation
24 | # pragma message (" Bootp_file : Tftpd32 compilation")
25 | # include "headers.h"
26 | #endif
27 |
28 | #include // sscanf is used
29 | #include // endthread + beginthread
30 |
31 | #include "threading.h"
32 | #include "bootpd_functions.h"
33 |
34 |
35 |
36 | void Dhcp_Send_Leases ( struct LL_IP *tIP[], int nbLeases)
37 | {
38 | struct S_DhcpLeases dhcp;
39 | int Ark;
40 |
41 | for ( Ark=0, dhcp.nb=0 ;
42 | ArksMacAddr, FREE_DHCP_ADDRESS, 6) == 0)
46 | strcpy (dhcp.l[dhcp.nb].szMAC, "-");
47 | else
48 | strcpy ( dhcp.l[dhcp.nb].szMAC, haddrtoa(tIP[Ark]->sMacAddr, 6,':') );
49 | dhcp.l[dhcp.nb].tAllocated = tIP[Ark]->tAllocated;
50 | dhcp.l[dhcp.nb].tRenewed = tIP[Ark]->tRenewed;
51 | strcpy ( dhcp.l[dhcp.nb].szIP, inet_ntoa (tIP[Ark]->dwIP) );
52 | dhcp.nb++;
53 | }
54 | SendMsgRequest ( C_DHCP_LEASE,
55 | & dhcp,
56 | dhcp.nb * (sizeof dhcp.l[0]) + sizeof dhcp.nb,
57 | TRUE, // block thread until msg sent
58 | FALSE ); // if no GUI return
59 | } // Dhcp_Send_NewLease
60 |
61 |
62 |
--------------------------------------------------------------------------------
/installers/1-sign_exe.bat:
--------------------------------------------------------------------------------
1 | @echo off
2 | setlocal
3 |
4 | if "%VERSION%"=="" (
5 | echo [ERROR] VERSION is not defined. Please set it before running this script.
6 | exit /b 1
7 | )
8 |
9 | REM -- Check thumbprint --
10 | if "%SIGN_CERT_THUMBPRINT%"=="" (
11 | echo [ERROR] SIGN_CERT_THUMBPRINT is not defined. Please set it before running this script.
12 | exit /b 1
13 | )
14 |
15 | REM -- Set path to signtool --
16 | set SIGNTOOL="C:\Program Files (x86)\Windows Kits\10\App Certification Kit\signtool.exe"
17 |
18 | REM -- Move to the build directory --
19 | cd /d ..\ARTS\BIN\release
20 | if errorlevel 1 (
21 | echo [ERROR] Could not change to ..\ARTS\BIN\release
22 | exit /b 1
23 | )
24 | REM -- create destination file
25 | mkdir ..\dist\%VERSION% 2>nul
26 | mkdir ..\dist\%VERSION%\signed 2>nul
27 |
28 | REM -- Copy original executables to their target names --
29 | echo Copying files to target names...
30 |
31 | copy /y tftpd32.x64.exe ..\dist\%VERSION%\signed\tftpd64.exe
32 | copy /y tftpd32.x86.exe ..\dist\%VERSION%\signed\tftpd32.exe
33 | copy /y tftpd32_gui.x64.exe ..\dist\%VERSION%\signed\tftpd64_gui.exe
34 | copy /y tftpd32_gui.x86.exe ..\dist\%VERSION%\signed\tftpd32_gui.exe
35 | copy /y tftpd32_svc.x64.exe ..\dist\%VERSION%\signed\tftpd64_svc.exe
36 | copy /y tftpd32_svc.x86.exe ..\dist\%VERSION%\signed\tftpd32_svc.exe
37 |
38 | REM -- Sign all 6 executables --
39 | echo Signing executables...
40 |
41 | cd /d ..\dist\%VERSION%\signed
42 | if errorlevel 1 (
43 | echo [ERROR] Could not change to ..\ARTS\BIN\release
44 | exit /b 1
45 | )
46 | for %%F in (
47 | tftpd64.exe
48 | tftpd32.exe
49 | tftpd64_gui.exe
50 | tftpd32_gui.exe
51 | tftpd64_svc.exe
52 | tftpd32_svc.exe
53 | ) do (
54 | if exist "%%F" (
55 | echo Signing %%F...
56 | %SIGNTOOL% sign /sha1 %SIGN_CERT_THUMBPRINT% /tr http://time.certum.pl /td sha256 /fd sha256 /v "%%F"
57 | ) else (
58 | echo [WARNING] File not found: %%F
59 | )
60 | )
61 |
62 | echo Done.
63 | endlocal
64 |
--------------------------------------------------------------------------------
/src/_services/bootpd_console.c:
--------------------------------------------------------------------------------
1 | //////////////////////////////////////////////////////
2 | //
3 | // Projet TFTPD32. January 2006 Ph.jounin
4 | // Projet DHCPD32. January 2006 Ph.jounin
5 | // File bootpd_console.c: DHCP Reporting
6 | //
7 | // source released under European Union Public License
8 | //
9 | //////////////////////////////////////////////////////
10 |
11 | #ifndef TFTPD32
12 | # pragma message (" Bootp_file : Dhcpd32 compilation")
13 | # include
14 | # include
15 | # include
16 | # include "cmsgbox.h"
17 | # include "dhcpd.h"
18 | # include "dhcpd32.h"
19 | # include
20 | # include // offsetof
21 | # include
22 | #else
23 | // TFTPD32's compilation
24 | # pragma message (" Bootp_file : Tftpd32 compilation")
25 | # include "headers.h"
26 | #endif
27 |
28 | #include // sscanf is used
29 | #include // endthread + beginthread
30 |
31 | #include "threading.h"
32 | #include "bootpd_functions.h"
33 |
34 |
35 |
36 | void Dhcp_Send_Leases (struct LL_IP *tIP[], int nbLeases)
37 | {
38 | struct S_DhcpLeases dhcp;
39 | int Ark;
40 |
41 | for ( Ark=0, dhcp.nb=0 ;
42 | ArksMacAddr, FREE_DHCP_ADDRESS, 6) == 0)
46 | strcpy (dhcp.l[dhcp.nb].szMAC, "-");
47 | else
48 | strcpy ( dhcp.l[dhcp.nb].szMAC, haddrtoa(tIP[Ark]->sMacAddr, 6,':') );
49 | dhcp.l[dhcp.nb].tAllocated = tIP[Ark]->tAllocated;
50 | dhcp.l[dhcp.nb].tRenewed = tIP[Ark]->tRenewed;
51 | strcpy ( dhcp.l[dhcp.nb].szIP, inet_ntoa (tIP[Ark]->dwIP) );
52 | dhcp.nb++;
53 | }
54 | SendMsgRequest ( C_DHCP_LEASE,
55 | & dhcp,
56 | dhcp.nb * (sizeof dhcp.l[0]) + sizeof dhcp.nb,
57 | TRUE, // block thread until msg sent
58 | FALSE ); // if no GUI return
59 | } // Dhcp_Send_NewLease
60 |
61 |
62 |
--------------------------------------------------------------------------------
/src/_gui/gui_dns.c:
--------------------------------------------------------------------------------
1 | //////////////////////////////////////////////////////
2 | //
3 | // Projet TFTPD32. 2009 Ph.jounin
4 | // File gui_dns.c: DNS window
5 | //
6 | //////////////////////////////////////////////////////
7 |
8 | #include "headers.h"
9 | #include
10 |
11 |
12 | // number of messages kept
13 | #define MAX_MSG 500
14 |
15 |
16 |
17 |
18 | // ---------------------------------------------------------------------
19 | //
20 | // ListView Management
21 | //
22 | // ---------------------------------------------------------------------
23 |
24 |
25 |
26 | void AddDNSItem (HWND hListV, char *szName, char *szIPv4, char *szIPv6)
27 | {
28 | LVITEM LvItem;
29 | LV_FINDINFO LvInfo;
30 | int itemPos;
31 |
32 | // is host already in the list
33 | LvInfo.flags = LVFI_STRING;
34 | LvInfo.psz = szName;
35 | itemPos = ListView_FindItem(hListV, -1, &LvInfo);
36 | if (itemPos != -1)
37 | {
38 | // already displayed : refresh address
39 | memset (& LvItem, 0, sizeof LvItem);
40 | LvItem.iItem = itemPos;
41 | ListView_SetItemText (hListV, itemPos, 1, szIPv4);
42 | ListView_SetItemText (hListV, itemPos, 2, szIPv6);
43 | }
44 | else
45 | {
46 | // a new item should be inserted
47 | // before that keep only MAX_MSG messages
48 | while (ListView_GetItemCount (hListV) >= MAX_MSG)
49 | ListView_DeleteItem (hListV, 0) ;
50 |
51 | LvItem.mask = LVIF_PARAM | LVIF_STATE;
52 | // LvItem.mask = 0;
53 | LvItem.state = 0;
54 | LvItem.stateMask = 0;
55 | LvItem.iItem = ListView_GetItemCount (hListV); // item pos
56 | LvItem.lParam = 0 ; // sorting params
57 | LvItem.iSubItem = 0; // column index
58 | // LvItem.pszText = "";
59 |
60 | itemPos = ListView_InsertItem(hListV,(LPARAM)&LvItem);
61 | ListView_SetItemText (hListV, itemPos, 0, szName);
62 | ListView_SetItemText (hListV, itemPos, 1, szIPv4);
63 | ListView_SetItemText (hListV, itemPos, 2, szIPv6);
64 | } // host not found
65 | } // AddDNSItem
66 |
67 |
68 |
--------------------------------------------------------------------------------
/src/_libs/mini_tcp4u/udp4u.c:
--------------------------------------------------------------------------------
1 | /*
2 | * From Tcp4u v 3.31 Last Revision 08/12/1997 3.31-01
3 | *
4 | *===========================================================================
5 | *
6 | * Project: Tcp4u, Library for tcp protocol
7 | * File: tcp4.c
8 | *
9 | *===========================================================================
10 | * Source released under GPL license
11 | */
12 |
13 | //#include
14 | // #include
15 | #include
16 | #include
17 |
18 | #include "tcp4u.h"
19 | #include "../log/LogToMonitor.h"
20 |
21 |
22 | // send data using Udp
23 | int UdpSend (int nFromPort, struct sockaddr *sa_to, int sa_len, const char *data, int len)
24 | {
25 | SOCKET s;
26 | SOCKADDR_STORAGE sa_from;
27 | int Rc;
28 | int True=1;
29 | char szServ[NI_MAXSERV];
30 | ADDRINFO Hints, *res;
31 |
32 | // populate sa_from
33 | memset (&sa_from, 0, sizeof sa_from);
34 | Hints.ai_family = sa_to->sa_family;
35 | Hints.ai_flags = NI_NUMERICSERV;
36 | Hints.ai_socktype = SOCK_DGRAM;
37 | Hints.ai_protocol = IPPROTO_UDP;
38 | wsprintf (szServ, "%d", nFromPort);
39 | Rc = getaddrinfo (NULL, szServ, & Hints, & res);
40 |
41 | s = socket (res->ai_family, res->ai_socktype, res->ai_protocol);
42 | if (s == INVALID_SOCKET) return TCP4U_ERROR;
43 | // REUSEADDR option in order to allow thread to open 69 port
44 | Rc = setsockopt (s, SOL_SOCKET, SO_REUSEADDR, (char *) & True, sizeof True);
45 | LogToMonitor (Rc==0 ? "UdpSend: Port %d may be reused" : "setsockopt error", nFromPort);
46 |
47 | Rc = bind (s, res->ai_addr, res->ai_addrlen);
48 | freeaddrinfo(res);
49 |
50 | LogToMonitor ("UdpSend bind returns %d (error %d)", Rc, GetLastError ());
51 | if (Rc<0) { closesocket (s); return TCP4U_BINDERROR; }
52 |
53 | Rc = sendto (s, data, len, 0, sa_to, sa_len);
54 | LogToMonitor ("sendto returns %d", Rc);
55 | closesocket (s);
56 | return Rc;
57 | } // UdpSend
58 |
59 |
--------------------------------------------------------------------------------
/src/_libs/GUI/centerchild.c:
--------------------------------------------------------------------------------
1 | ////////////////////////
2 | // Projet DHCPD32. January 2006 Ph.jounin
3 | // A free DHCP server for Windows
4 | // File CMsgBox
5 | // Display a centered messagebox
6 | // Code from Microsoft Knowledge base Q180936
7 | //
8 | // Released under European Union Public License
9 | //
10 | ////////////////////////
11 |
12 |
13 | #include
14 | #include "centerchild.h"
15 |
16 |
17 | /////////////////////////////////////////////////////////////////////////
18 | // A Window centered on its parent
19 | /////////////////////////////////////////////////////////////////////////
20 | BOOL CenterChildWindow (HWND hChildWnd, int uType)
21 | {
22 | HWND hParentWnd ;
23 | RECT sParentRect, sChildRect, sWorkArea;
24 | int x, y;
25 |
26 | hParentWnd = GetParent (hChildWnd);
27 | if (hParentWnd == NULL) return FALSE;
28 |
29 | if ( (uType & CCW_VISIBLE) && ! IsWindowVisible (hParentWnd) ) return FALSE;
30 |
31 | // compute child position
32 | GetWindowRect (hParentWnd, & sParentRect);
33 | GetWindowRect (hChildWnd, & sChildRect);
34 | SystemParametersInfo (SPI_GETWORKAREA, 0, & sWorkArea, 0);
35 |
36 | x = sParentRect.left + (sParentRect.right - sParentRect.left) / 2 - (sChildRect.right - sChildRect.left) / 2;
37 | y = sParentRect.top + (sParentRect.bottom - sParentRect.top) / 2 - (sChildRect.bottom - sChildRect.top) / 2;
38 |
39 | // Child larger than its parent ?
40 | if ( (uType & CCW_INSIDE) &&
41 | ( x < sParentRect.left || y < sParentRect.top )
42 | )
43 | return FALSE;
44 |
45 | // Child window outside the screen ?
46 | if ( (uType & CCW_VISIBLE) &&
47 | ( xsWorkArea.right
48 | || ysWorkArea.bottom ) )
49 | return FALSE;
50 |
51 | // OK : change window Pos
52 | SetWindowPos (hChildWnd, NULL, x, y, 0, 0,
53 | SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE );
54 |
55 | return TRUE;
56 | } // CenterChildWindow
57 |
58 |
--------------------------------------------------------------------------------
/src/_gui/tftp_ip.c:
--------------------------------------------------------------------------------
1 | //////////////////////////////////////////////////////
2 | //
3 | // Projet TFTPD32. Mai 98 Ph.jounin
4 | // File tftp_id.c: retrieves IP address
5 | //
6 | // released under artistic license
7 | //
8 | //////////////////////////////////////////////////////
9 |
10 |
11 | #include "headers.h"
12 |
13 | /////////////////////////////
14 | // The background window
15 | //
16 | long CALLBACK TftpAddIPProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
17 | {
18 | static char buf[MAXGETHOSTSTRUCT];
19 |
20 | switch (message)
21 | {
22 |
23 | /////////////////////////
24 | // This background window and this quirk AsyncGetHostByName call
25 | // is here as workaround for a Windows98 bug :
26 | // If the address has been returned by DHCP and the DNS server is down/unreachable
27 | // the gethostbyname returns "Host not found, or SERVERFAIL"
28 | // This error happens (happened ?) frequently when connected by modem..
29 | // I have kept this asynchronous background window, since it allow the
30 | // IP address list to be refreshed every 20 seconds.
31 | ////////////////////////
32 | case WM_TFTP_GETIP :
33 | {char szName [256];
34 | if ( gethostname (szName, sizeof szName)==SOCKET_ERROR
35 | || WSAAsyncGetHostByName (hWnd, WM_IPADDRESS, szName, buf, sizeof buf) ==0 )
36 | PostMessage (GetParent (hWnd), WM_ADD_IP_CB, 0, 0);
37 | }
38 | break;
39 |
40 | case WM_IPADDRESS :
41 | // Post now the address to the main window
42 | PostMessage (GetParent (hWnd), WM_ADD_IP_CB, 0,
43 | WSAGETASYNCERROR(lParam)==0 ? (LPARAM) buf : 0);
44 | // PostMessage (hWnd, WM_CLOSE, 0, 0);
45 | // refresh list every 20 seconds
46 | SetTimer (hWnd, WM_TFTP_GETIP, 20000, 0);
47 | break;
48 |
49 | case WM_TIMER :
50 | KillTimer(hWnd, wParam);
51 | PostMessage (hWnd, wParam, 0, 0);
52 | break;
53 |
54 | }
55 |
56 | return DefWindowProc (hWnd, message, wParam, lParam);
57 |
58 | } // TftpAddIPProc
59 |
60 |
61 |
62 |
--------------------------------------------------------------------------------
/doc-help/src/overview.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | overview
7 |
8 |
9 |
10 |
11 |
12 |
Overview
13 |
14 |
15 |
Tftpd32 and Tftpd64 version 4.64
16 |
17 | An opensource full featured TFTP server, a TFTP client, a BOOTP/DHCP Server, an SNTP
18 | server, a DNS server and a SYSLOG server combined into a single program which takes
19 | a few hundreds of kBytes.
20 |
21 |
22 |
23 |
24 |
12 |
13 |
14 | DHCP setup is available through the DHCP tab.
15 |
16 |
17 |
18 |
19 |
20 |
IP Pool starting Address
21 |
This is the first address which will be distributed.
22 |
Size of pool
23 |
This is the number of hosts which may be configured by Tftpd32.
24 |
Lease
25 |
This is the amount of time in minutes the address is leased for.
26 |
Boot File
27 |
Used by diskless stations. It is the file which will be retrieved by TFTP to start up the boot process.
28 | The strings $MAC$ and $IP$ are pseudo variables which are translated into the MAC address of the client and its assignated IP address.
29 |
Default router
30 |
The IP address of the LAN gateway.
31 |
Mask
32 |
The network mask which will be assigned to the DHCP clients.
33 |
DNS servers
34 |
The IP address of the DNS. Two DNS can be configured.
35 |
WINS Server
36 |
The IP address of the WINS server.
37 |
NTP Server
38 |
The IP address of the NTP server used for synchronisation.
39 |
SIP Server
40 |
The IP address of the SIP server. It concerns mostly IP phones.
41 |
Domain Name
42 |
Either the NT domain or the internet domain.
43 |
Additional Option
44 |
The first field is the number of the option to be handled
45 |
The second filed is the value of the field. The value is prefixed with its type (a for list of IPv4 address, x for list of hex digits, b for list of decimal bytes, s for an ASCII string) [legacy prefixes: i for integer, n for network order integers]
46 |
More Additional Options ?
47 |
Tftpd32 supports up to 10 additionnal options. They have to be configured by editing the tftpd32.ini settings file. Their syntax is similar to the previous one.
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
--------------------------------------------------------------------------------
/src/_gui/gui_log.c:
--------------------------------------------------------------------------------
1 | //////////////////////////////////////////////////////
2 | //
3 | // Projet TFTPD32. Mai 98 Ph.jounin - Jan 2003
4 | // File qui_log.c: Log management (tab event viewer)
5 | //
6 | //////////////////////////////////////////////////////
7 |
8 |
9 | #include "headers.h"
10 | #include
11 | #include
12 |
13 |
14 | // ---------------------------------------------------------------
15 | // GUI management
16 | // ---------------------------------------------------------------
17 |
18 |
19 | /* ------------------------------------------------- */
20 | /* Manage a list box as a log window */
21 | /* ------------------------------------------------- */
22 | void LB_LOG (HWND hListBox, const char *szTxt)
23 | {
24 | int Ark, NbMsg;
25 | int dwMaxExtent, dwExtent;
26 | SIZE sTextSize = {0, 0};
27 | HDC hDC;
28 | DWORD dwMaxMsg = 250;
29 | char szBuf[LOGSIZE + 30];
30 | LRESULT Rc;
31 | static int bInit=FALSE;
32 |
33 | #define CROLLBAR
34 | #ifdef CROLLBAR
35 |
36 | if (!bInit)
37 | {
38 | SendMessage (hListBox, LB_INITSTORAGE, dwMaxMsg, 0);
39 | bInit = TRUE;
40 | }
41 |
42 | // delete oldest messages
43 | for ( Rc = SendMessage (hListBox, LB_GETCOUNT, 0, 0);
44 | Rc > dwMaxMsg ;
45 | Rc = SendMessage (hListBox, LB_DELETESTRING, 0, 0) );
46 |
47 | Ark = (int) SendMessage (hListBox, LB_ADDSTRING, 0, (LPARAM) szTxt);
48 | if (Ark==LB_ERR)
49 | return;
50 |
51 | // record extent size
52 | hDC = GetDC (hListBox);
53 | GetTextExtentPoint32 (hDC, szTxt, lstrlen (szTxt), & sTextSize);
54 | LPtoDP (hDC, (POINT *) & sTextSize, 1); // convert to physical units
55 | dwExtent = (sTextSize.cx *9) / 10; // experimental !
56 | SendMessage (hListBox, LB_SETITEMDATA, Ark, (LPARAM) dwExtent);
57 | ReleaseDC (hListBox, hDC);
58 |
59 | // search the longest text
60 | dwMaxExtent = 0;
61 | NbMsg = (int)SendMessage(hListBox, LB_GETCOUNT, 0, 0);
62 | for (Ark= NbMsg; Ark>=0 ; Ark --)
63 | {
64 | dwExtent = (DWORD) SendMessage (hListBox, LB_GETITEMDATA, Ark-1, (LPARAM) szBuf);
65 | if (dwExtent > dwMaxExtent) dwMaxExtent = dwExtent ;
66 | }
67 | // and extent horizontal scrollbar accordingly
68 | SendMessage (hListBox, LB_SETHORIZONTALEXTENT, dwMaxExtent, 0);
69 | // scroll to the end of the list box
70 | SendMessage (hListBox, LB_SETTOPINDEX, NbMsg-1, 0);
71 | #endif
72 | } // LB_LOG
73 |
74 | //////////////////////////////////////
75 | // Log Thread management
76 | //////////////////////////////////////
77 |
78 |
79 |
--------------------------------------------------------------------------------
/src/_main/main.c:
--------------------------------------------------------------------------------
1 | //////////////////////////////////////////////////////
2 | //
3 | // Projet TFTPD32. Mai 98 Ph.jounin
4 | // File tftp_mai.c: The MAIN program
5 | //
6 | // source released under European Union Public License
7 | //
8 | //////////////////////////////////////////////////////
9 |
10 |
11 | #include "headers.h"
12 |
13 | //////////////////////////////////////////////////////
14 | //
15 | // Starts services and main window
16 | //
17 | //////////////////////////////////////////////////////
18 |
19 | // A few global variables
20 | char szTftpd32Help [MAX_PATH]; // Full Path for Help file
21 | char szTftpd32IniFile [MAX_PATH]; // Full Path for INI file
22 |
23 |
24 | /* ----------------------------- */
25 | /* WinMain */
26 | /* ----------------------------- */
27 | int PASCAL WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
28 | LPSTR lpszCmdLine, int nCmdShow)
29 | {
30 | WSADATA WSAData;
31 | int Rc;
32 |
33 | // ------------------------------------------
34 | // Quick Uninstaller
35 | // ------------------------------------------
36 | if (lstrcmpi ("-uninstall", lpszCmdLine) == 0)
37 | {
38 | // destroy the registry entries but not the ini file
39 | Tftpd32DestroySettings ();
40 | return 0;
41 | }
42 |
43 | // ------------------------------------------
44 | // Start the App
45 | // ------------------------------------------
46 |
47 | Rc = WSAStartup (MAKEWORD(2,0), & WSAData);
48 | if (Rc != 0)
49 | {
50 | CMsgBox (NULL,
51 | GetLastError()==WSAVERNOTSUPPORTED ?
52 | "Error: Tftpd32 now requires winsock version 2" :
53 | "Error: Can't init Winsocket",
54 | APPLICATION,
55 | MB_OK | MB_ICONERROR);
56 | return FALSE;
57 | }
58 |
59 |
60 | // start Services through a thread
61 | // the thread start the console, wait for 200ms
62 | // (time to start the GUI) then starts the services
63 | // this way, an early call to the SVC_ERROR procedure happens
64 | // when the console/GUI socket is connected.
65 | _beginthread ( StartTftpd32Services, 0, NULL );
66 | // let the console opens its socket
67 | // Pause needs to be higher than the one in StartMultiWorkerThreads (start_threads.c)
68 | // otherwise DHCP settings will not be loaded in GUI
69 | Sleep (100);
70 | // opens Gui
71 | GuiMain (hInstance, hPrevInstance,lpszCmdLine, nCmdShow);
72 |
73 | WSACleanup ();
74 | LogToMonitor ("That's all folks\n");
75 | return 0;
76 | } /* WinMain */
77 |
78 |
79 |
--------------------------------------------------------------------------------
/src/_libs/mini_tcp4u/tcp4u.h:
--------------------------------------------------------------------------------
1 | // -----------------------------------------------------------------------------------------------------
2 | // TCP4U
3 | // Source released under GPL license
4 | // -----------------------------------------------------------------------------------------------------
5 |
6 |
7 | #define TCP4U_SUCCESS 1 /* >=1 function OK */
8 | #define TCP4U_ERROR -1 /* error */
9 | #define TCP4U_TIMEOUT -2 /* timeout has occurred */
10 | #define TCP4U_BUFFERFREED -3 /* the buffer has been freed */
11 | #define TCP4U_HOSTUNKNOWN -4 /* connect to unknown host */
12 | #define TCP4U_NOMORESOCKET -5 /* all sockets have been used */
13 | #define TCP4U_NOMORERESOURCE -5 /* or no more free resource */
14 | #define TCP4U_CONNECTFAILED -6 /* connect function has failed*/
15 | #define TCP4U_UNMATCHEDLENGTH -7 /* TcpPPRecv : Error in length*/
16 | #define TCP4U_BINDERROR -8 /* bind failed (Task already started?) */
17 | #define TCP4U_OVERFLOW -9 /* Overflow during TcpPPRecv */
18 | #define TCP4U_EMPTYBUFFER -10 /* TcpPPRecv receives 0 byte */
19 | #define TCP4U_CANCELLED -11 /* Call cancelled by signal */
20 | #define TCP4U_INSMEMORY -12 /* Not enough memory */
21 | #define TCP4U_BADPORT -13 /* Bad port number or alias */
22 | #define TCP4U_SOCKETCLOSED 0 /* Host has closed connection */
23 | #define TCP4U_FILE_ERROR -14 /* A file operation has failed*/
24 | #define TCP4U_VERSION_ERROR -15 /* Versions differs */
25 | #define TCP4U_BAD_AUTHENT -16 /* Bad authentication */
26 |
27 | /* ------------------------------- */
28 | /* Different modes for TcpRecv */
29 | /* ------------------------------- */
30 | #define TCP4U_WAITFOREVER 0
31 | #define TCP4U_DONTWAIT ((unsigned) -1)
32 |
33 |
34 |
35 |
36 | SOCKET TcpGetListenSocket (int family, LPCSTR szService, unsigned short *pPort);
37 | int TcpRecv (SOCKET s, LPSTR szBuf, unsigned uBufSize, unsigned uTimeOut, HANDLE hLogFile);
38 | int TcpSend (SOCKET s, LPCSTR szBuf, unsigned uBufSize, HANDLE hLogFile);
39 | SOCKET TcpConnect (LPCSTR szHost,
40 | LPCSTR szService,
41 | int family,
42 | unsigned short nPort);
43 | int TcpPPSend (SOCKET s, LPCSTR szBuf, unsigned uBufSize, HANDLE hLogFile);
44 | int TcpPPRecv (SOCKET s, LPSTR szBuf, unsigned uBufSize, int uTimeOut, HANDLE hLogFile);
45 |
46 | int TcpExchangeChallenge (SOCKET s, int seed, int nVersion, int *peerVersion, const char *key);
47 |
48 | int UdpSend (int nFromPort, struct sockaddr *sa_to, int sa_len, const char *data, int len);
49 |
50 |
51 |
--------------------------------------------------------------------------------
/src/_common/setinifilename.c:
--------------------------------------------------------------------------------
1 | //////////////////////////////////////////////////////
2 | //
3 | // Projet TFTPD32. Mars 2000 Ph.jounin
4 | // File setinifilename.c:
5 | // locate ini file in several directories
6 | // try TFTPD32_INI_DIR environment variable
7 | // then several standard locations
8 | //
9 | // released under European Union Public License
10 | //
11 | //////////////////////////////////////////////////////
12 |
13 |
14 | #include "headers.h"
15 |
16 | struct EnvInis
17 | {
18 | const char* env_var;
19 | const char* fmt;
20 | };
21 | struct EnvInis EnvInisList[] = {
22 | { "TFTP_INI", "%s" },
23 | { "TFTPD32_INI_DIR", "%s\\%0.0s%s" }, // ignore APPLICATION_NAME
24 | { "TFTPD32_INI_DIR", "%s\\%s\\%s" }, // but can still try with
25 | { "ALLUSERSPROFILE", "%s\\%s\\%s" },
26 | { "APPDATA", "%s\\%s\\%s" },
27 | { "LOCALAPPDATA", "%s\\%s\\%s" },
28 | { "PROGRAMDATA", "%s\\%s\\%s" },
29 | { "ProgramW6432", "%s\\%s\\%s" },
30 | { NULL, NULL }
31 | };
32 |
33 | static BOOL FileExists(const char* p) {
34 | DWORD a = GetFileAttributes(p);
35 | return (a != INVALID_FILE_ATTRIBUTES) && !(a & FILE_ATTRIBUTE_DIRECTORY);
36 | }
37 |
38 | /* ----------------------------------- */
39 | /* Determine the full name of ini file */
40 | /* ----------------------------------- */
41 | const char *SetIniFileName (const char *szIniFile, char *szFullIniFile, size_t len)
42 | {
43 | char szPath [_MAX_PATH];
44 | int Rc;
45 | char* p;
46 |
47 | szFullIniFile[0] = 0;
48 | szFullIniFile[--len] = 0;
49 | // try searching Tftpd32.ini in data directories
50 | for (struct EnvInis *dir = EnvInisList; dir->env_var != NULL; dir++)
51 | {
52 | p = getenv(dir->env_var);
53 | if (p != NULL)
54 | {
55 | sprintf_s(szFullIniFile, len, dir->fmt, p, APPLICATION_NAME, szIniFile);
56 | if (FileExists(szFullIniFile)) return szFullIniFile;
57 | }
58 | }
59 | // Try current directory
60 | if (GetCurrentDirectory(sizeof szPath, szPath) != 0)
61 | {
62 | sprintf_s(szFullIniFile, len, "%s\\%s", szPath, szIniFile);
63 | if (FileExists(szFullIniFile)) return szFullIniFile;
64 | }
65 | // Try Program location, caling GetModuleFileName
66 | if ( GetModuleFileName(NULL, szPath, sizeof szPath) != 0
67 | && (p = strrchr(szPath, '\\')) != NULL )
68 | {
69 | *p = 0;
70 | sprintf_s(szFullIniFile, len, "%s\\%s", szPath, szIniFile);
71 | if (FileExists(szFullIniFile)) return szFullIniFile;
72 | }
73 |
74 | // try our registry entry, last NULL skip reading into Ini File !!
75 | if (ReadKey("Software\\" APPLICATION_NAME, "IniPath", szFullIniFile, len, REG_SZ, NULL))
76 | return szFullIniFile;
77 |
78 | strcpy_s(szFullIniFile, len, szIniFile); // not found, try local directory
79 | return szFullIniFile;
80 | } // SetIniFileName
81 |
82 |
--------------------------------------------------------------------------------
/src/_services/threading.h:
--------------------------------------------------------------------------------
1 | //////////////////////////////////////////////////////
2 | //
3 | // Projet TFTPD32. January 2006 Ph.jounin
4 | // Projet DHCPD32. January 2006 Ph.jounin
5 | // File threading.h: Manage threads
6 | //
7 | // source released under artistic license (see license.txt)
8 | //
9 | //////////////////////////////////////////////////////
10 |
11 | #include "async_log.h"
12 |
13 |
14 | // Starts one thread per service (Tftpd, Sntpd, dhcpd)
15 | // Order is the same than tThreadsConfig array
16 | // pseudo service should be first
17 | enum e_Threads { TH_CONSOLE,
18 | TH_ASYNCSAVEKEY,
19 | TH_SCHEDULER,
20 | TH_DHCP,
21 | TH_TFTP,
22 | TH_SNTP,
23 | TH_DNS,
24 | TH_SYSLOG,
25 | TH_NUMBER };
26 |
27 | // Events created for main threads
28 | struct S_ThreadMonitoring
29 | {
30 | int gRunning; // thread status
31 | HANDLE tTh; // thread handle
32 | HANDLE hEv; // wake up event
33 | SOCKET skt; // Listening SOCKET
34 | int bSoftReset; // Thread will be reset
35 | BOOL bInit; // inits are terminated
36 | }
37 | tThreads [TH_NUMBER];
38 |
39 | struct S_RestartTable
40 | {
41 | int oldservices;
42 | int newservices;
43 | int flapservices;
44 | };
45 |
46 |
47 | // threads started by StartAllThreads
48 | void TftpdConsole (void *param);
49 | void ListenDhcpMessage (void *param);
50 | void TftpdMain (void *param);
51 | void SntpdProc (void *param);
52 | void SyslogProc (void *param);
53 | void AsyncSaveKeyBckgProc (void *param);
54 | void Scheduler (void *param);
55 | void ListenDNSMessage (void * param);
56 |
57 |
58 | // Threads management : birth, life and death
59 | int StartAllWorkerThreads (void);
60 | int StartMultiWorkerThreads (BOOL bSoft);
61 | int WakeUpThread (int Idx);
62 | void TerminateWorkerThreads (BOOL bSoft);
63 | int GetRunningThreads (void);
64 |
65 | // Access to console
66 | int SendMsgRequest (int type, // msg type
67 | const void *msg_stuff, // data
68 | int size, // size of data
69 | BOOL bBlocking, // block thread until msg sent
70 | BOOL bRetain ); // retain msg if GUI not connected
71 |
72 | BOOL Tftpd32ReadSettings (void);
73 | BOOL Tftpd32SaveSettings (void);
74 | BOOL Tftpd32DestroySettings (void);
75 | void Tftpd32UpdateServices (void *lparam);
76 |
77 | // Send the IP interfaces
78 | int AnswerIPList (void);
79 |
80 | // Complex actions handled by console thread
81 | void SendDirectoryContent (void);
82 |
83 | // interaction between tftp and console (statistics)
84 | DWORD WINAPI StartTftpTransfer (LPVOID pThreadArgs);
85 | int ReportNewTrf (const struct LL_TftpInfo *pTftp);
86 | void ConsoleTftpGetStatistics (void);
87 |
88 | // Actions called by Scheduler
89 | int PoolNetworkInterfaces (void);
90 | int GetIPv4Address (const char *szIf, char *szIP);
91 |
--------------------------------------------------------------------------------
/doc-help/src/Table of Contents.hhc:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
10 |
17 | Q: What is Tftpd32's Export Control Classification Number (ECCN)
18 |
19 | A: Since Tftpd32 have no encryption functionality, there is no export restriction regarding the US classification.
20 | The corresponding EECN code is EAR99/NLR and CCATS code is not applicable.
21 |
22 |
23 |
24 |
25 | Q: Where can i get the latest version of Tftpd32 ?
26 | Q: Has TFTPD32 an official home page ?
27 |
33 | Q: What are the Export Control Classification Number (ECCN) and the CCATS number (Commerce Classification and Tracking System) of Tftpd32 ?
34 | Q: Since Tftpd32 have no encryption functionality, there is no export restriction. The corresponding EECN code is EAR99/NLR and CCATS code is N/A (not applicable).
35 | !
36 |
37 |
38 | Q: Does TFTPD32 work with Netscape or Internet Explorer ?
39 | Q: I am unable to use TFTPD32 with my FTP client !
40 |
41 |
42 | A: TFTPD32 is a TFTP server, whereas Netscape and IE need an FTP server. The
43 | protocols are quite different and are not interchangeable.
44 |
45 |
46 |
47 | Q: Sometimes the client begins a transfer correctly, but receives no data; what's wrong ?
48 |
49 |
50 | A: The requested block size is too high. Either decrease it from the client or disable
51 | the option negotiation switch from the server.
52 | Alternatively you can adjust the MTU parameter in your TCP/IP settings.
53 |
54 |
55 |
56 | Q: I have checked "Hide Window at startup" option and i am now unable to change settings anymore !
57 |
58 |
59 | A: Look at the right of your task bar. You will find the TFTPD32 icon near the clock.
60 | Double click on it and the main window will be displayed.
61 | A: Since version 2.2, you can also launch a new instance of Tftpd32.
62 |
63 |
64 |
65 | Q: How to manually desinstall Tftpd32 ?
66 |
67 |
68 | A: Start tftpd32, go in the settings part and click on Default. This will remove the
69 | registry entry and the INI file. Then manually delete the files Tftpd32.chm and
70 | Tftpd32.exe.
71 |
72 |
73 |
74 | Q: I got this window. What happens ?
75 |
76 |
77 |
78 | A: A process has already bound the DHCP port. If you do not need a DHCP server,
79 | go into the settings window and disable the DHCP server. Otherwise, you can use
80 | TcpView from Sysinternals in order to know which process has bound the DHCP
81 | port.
82 |
83 |
84 |
85 | Q: Can tftpd32 run as a service ?
86 |
87 |
88 | A: You can use third party tools like SrvAny or fireDaemon to turn Tftpd32 into a service.
89 | A: I am working on service edition, which will be soon available...
90 |
91 |
92 |
93 | Q: Can the DHCP server assign only static address ?
94 |
95 |
96 | A: Yes, see the Tips section.
97 |
98 |
99 |
100 |
--------------------------------------------------------------------------------
/src/_gui/about.c:
--------------------------------------------------------------------------------
1 | //////////////////////////////////////////////////////
2 | //
3 | // Projet TFTPD32. Started, May 98 Ph.jounin
4 | // File about.c: Display license
5 | //
6 | // source released under European Union Public License
7 | //
8 | //////////////////////////////////////////////////////
9 |
10 |
11 |
12 | #include "headers.h"
13 |
14 | #ifdef _M_X64
15 | # define TFTPD_STRING "TFTPD64 v4.74 Build " __DATE__ " " __TIME__
16 | # define TFTPD_ABOUT_TITLE "About TFTPD64"
17 | #else
18 | #ifndef TFTP_CLIENT_ONLY
19 | # define TFTPD_STRING "TFTPD32 v4.74 Build " __DATE__ " " __TIME__
20 | #else
21 | # define TFTPD_STRING "TFTPD32 Client v4.70 Build " __DATE__ " " __TIME__
22 | #endif
23 | # define TFTPD_ABOUT_TITLE "About TFTPD32"
24 | #endif
25 |
26 | //#define INTERIM_VERSION
27 |
28 | #ifdef INTERIM_VERSION
29 | const char LICENSE_TFTPD32 [] =
30 | "Tftpd32 and Tftpd64 are\r\n"
31 | "copyrighted by Ph. Jounin\r\n"
32 | "This in an Interim Release\r\n"
33 | "Please do not distribute\r\n"
34 | "NO WARRANTY\r\n\r\n"
35 | "Full credits will be given into release version\r\n"
36 | "Official site: https://www.tftpd64.com";
37 | #elif defined BAE_SYSTEMS_LEN_WHITE
38 | const char LICENSE_TFTPD32 [] =
39 | "\r\n\r\n"
40 | " Tftpd32 Standalone Edition\r\n\r\n"
41 | " copyrighted 2007 by Philippe Jounin,\r\n"
42 | " provided by BAE Systems Australia\r\n"
43 | " for the Australian Department of Defence\r\n\r\n";
44 | #elif defined TFTP_CLIENT_ONLY
45 | const char LICENSE_TFTPD32 [] =
46 | "TFTPD32_Client is copyrighted 2025 by Philippe Jounin (philippe@jounin.net) "
47 | "and released under the European Union Public License 1.1 "
48 | "(see either the help file or the file EUPL-EN.pdf for the full text of the license)\r\n\r\n"
49 | "Official site: https://www.tftpd64.com\r\n\r\n";
50 | #elif defined STANDALONE_EDITION
51 | const char LICENSE_TFTPD32 [] =
52 | "TFTPD32 and TFTPD64 are copyrighted 1998-2025 by Philippe Jounin (philippe@jounin.net) "
53 | "and released under the European Union Public License 1.1 "
54 | "(see either the help file or the file EUPL-EN.pdf for the full text of the license)\r\n\r\n"
55 | "Official site: https://www.tftpd64.com\r\n\r\n"
56 | "Tftpd32 and Tftpd64 use the following copyrights or contributions\r\n"
57 | " - MD5 part is from RSA Data Security\r\n"
58 | " - Icon designed by Marco\r\n"
59 | " - IP checksum computation is from Mike Muss\r\n"
60 | " - DHCP lease persistence is from Nick Wagner\r\n"
61 | " - DHCP opts 82, 42 and 120 from Jesus Soto\r\n"
62 | " - DHCP header file from The Internet Software\r\n Consortium\r\n";
63 | #elif defined SERVICE_EDITION
64 | # ifdef _M_X64
65 | const char LICENSE_TFTPD32 [] =
66 | "Tftpd64 Service Edition copyrighted 2007-2025 by Philippe Jounin\r\n";
67 | # else
68 | const char LICENSE_TFTPD32 [] =
69 | "Tftpd32 Service Edition copyrighted 2007-2025 by Philippe Jounin\r\n";
70 | # endif
71 | #endif
72 |
73 |
74 |
75 | LRESULT CALLBACK AboutProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
76 | {
77 | switch (message)
78 | {
79 | case WM_INITDIALOG :
80 | SetWindowText (hWnd, TFTPD_ABOUT_TITLE);
81 | SetDlgItemText (hWnd, IDC_TFTPD_STRING, TFTPD_STRING);
82 | SetDlgItemText (hWnd, IDC_ABOUT_TFTPD32, LICENSE_TFTPD32);
83 | CenterChildWindow (hWnd, CCW_INSIDE | CCW_VISIBLE);
84 | break;
85 |
86 | case WM_COMMAND :
87 | switch (wParam)
88 | {
89 | case IDOK :
90 | EndDialog (hWnd, 0);
91 | break;
92 | }
93 | break;
94 |
95 |
96 | case WM_CLOSE :
97 | #if (defined INTERIM_VERSION && defined STANDALONE_VERSION)
98 | sSettings.LogLvl=15;
99 | #endif // INTERIM_VERSION
100 | case WM_DESTROY :
101 | EndDialog (hWnd, 0);
102 | break;
103 |
104 | } // switch
105 |
106 | return FALSE;
107 | } // AboutProc
108 |
109 |
110 |
--------------------------------------------------------------------------------
/src/_common/bootpd_util.h.bak:
--------------------------------------------------------------------------------
1 | //////////////////////////////////////////////////////
2 | //
3 | // Projet TFTPD32. Mai 98 Ph.jounin - June 2006
4 | // File bootpd_util.h: dhcp module data structure
5 | //
6 | // released under artistic license (see license.txt)
7 | //
8 | //////////////////////////////////////////////////////
9 |
10 |
11 |
12 | #define DHCP_DEFAULT_LEASE_TIME (2*24*60) // two days (in minutes)
13 |
14 | // DHCP assignations data base
15 | struct LL_IP
16 | {
17 | struct in_addr dwIP; // assignated address
18 | char sMacAddr[16]; // MAC Address of the client
19 | time_t tAllocated; // time of assignation
20 | time_t tRenewed; // time of client ack
21 | int dwAllocNum; // the number this record occupies in the ini file
22 | };
23 |
24 | extern struct LL_IP **tFirstIP; // sorted array of pointers on struct LL_IP
25 | extern struct LL_IP **tMAC; //sorted Pointers to elements in tFirstIP, indexed by MAC addr
26 | extern int nAllocatedIP; // number of item allocated (even if never acked)
27 |
28 |
29 |
30 | // The main settings table :
31 | // DHCP parameters in memory
32 |
33 | struct S_DHCP_Param
34 | {
35 | // struct in_addr dwAddr;
36 | char szAddr[64];
37 | int nPoolSize;
38 | // struct in_addr dwMask;
39 | char szMask[64];
40 | // struct in_addr dwDns;
41 | char szDns1[64];
42 | char szDns2[64];
43 | // struct in_addr dwWins;
44 | char szWins[64];
45 | // struct in_addr dwGateway;
46 | char szGateway[64];
47 | // struct in_addr dwOpt42;
48 | char szOpt42[64];
49 | // struct in_addr dwOpt120;
50 | char szOpt120[64];
51 |
52 | char szBootFile[256];
53 | char szDomainName[128];
54 | int nLease;
55 | int nIgnoreBootp;
56 | struct
57 | {
58 | int nAddOption;
59 | char szAddOption[128];
60 | }
61 | t[10];
62 | };
63 |
64 | extern struct S_DHCP_Param sParamDHCP;
65 | extern struct S_DHCP_Param sGuiParamDHCP;
66 |
67 | // written by Cengiz Beytas, it has been rewritten by Jesus Soto
68 | // int FindAdapterIP(char *szIP, DWORD *pdwAdapter, DWORD *pdwFirstAdapter);//
69 | // struct in_addr DlgItem2Address (HWND hWnd, int nDlgItem, const char *szDescr, BOOL bStrict);
70 |
71 |
72 | //struct in_addr DlgItem2Address (HWND hWnd, int nDlgItem, const char *szDescr, BOOL bStrict);
73 | int CheckInetAddress (HWND hWnd, char *szAddr, const char *szDescr, BOOL bStrict);
74 | int QsortCompare (const void *p1, const void *p2);
75 | int MACCompare (const void* p1, const void* p2);
76 | void IncNumAllocated (void);
77 | void DecNumAllocated (void);
78 | void DecNumAllocated (void);
79 | void SetNumAllocated(int n);
80 | void SetIP(struct LL_IP* pCur, DWORD newip);
81 | void SetMacAddr(struct LL_IP* pCur, const unsigned char *pMac, int nMacLen);
82 | void ZeroMacAddr(struct LL_IP* pCur);
83 | void SetAllocTime(struct LL_IP* pCur);
84 | void ZeroAllocTime(struct LL_IP* pCur);
85 | void SetRenewTime(struct LL_IP* pCur);
86 | void ForceRenewTime(struct LL_IP* pCur, time_t newtime);
87 | void ZeroRenewTime(struct LL_IP* pCur);
88 | void ReorderLeases (void);
89 | void LoadLeases(void);
90 | void FreeLeases(BOOL freepool);
91 | struct LL_IP *DHCPSearchByIP (const struct in_addr *pAddr, BOOL* wasexpired);
92 | struct LL_IP *DHCPSearchByMacAddress (const unsigned char *pMac, int nMacLen);
93 | char *TranslateExp (const char *exp, char *to, struct in_addr ip, const char *tMac);
94 |
95 | //////////////
96 | // From ip_util.h
97 | char * haddrtoa(const unsigned char *haddr, int hlen, char cSep); //A few decls so we can use these here
98 | void atohaddr(const unsigned char *addrstr, unsigned char* haddr, int haddrlen);
99 | char* timetoa(time_t t);
100 | time_t atotime(char* str);
101 | int AddrFitsPool(struct in_addr* addr);
102 | BOOL bIPSameSubnet (struct in_addr *p1, struct in_addr *p2, struct in_addr *pMask);
103 | struct in_addr *FindNearestServerAddress (struct in_addr *pHost, struct in_addr *pMask, BOOL bExact);
104 | unsigned long AddrInc(struct in_addr in);
105 |
--------------------------------------------------------------------------------
/src/_main/Svc main.c:
--------------------------------------------------------------------------------
1 | //////////////////////////////////////////////////////
2 | //
3 | // Projet TFTPD32. Mai 98 Ph.jounin
4 | // File SVC main.c: The MAIN program for the service edition
5 | //
6 | // derivative work from sdk_service.cpp
7 | // by Craig Link - Microsoft Developer Support
8 | //
9 | //
10 | // source released under European Union Public License
11 | //
12 | //////////////////////////////////////////////////////
13 |
14 |
15 | #include "headers.h"
16 | #include
17 | #include "service stuff.h"
18 |
19 | // A few global variables
20 | char szTftpd32IniFile [MAX_PATH]; // Full Path for INI file
21 |
22 |
23 |
24 | // internal variables
25 |
26 | BOOL bDebug = FALSE;
27 |
28 |
29 | //////////////////////////////////////////////////////
30 | //
31 | // Starts services and main window
32 | //
33 | //////////////////////////////////////////////////////
34 |
35 |
36 |
37 | /* ----------------------------- */
38 | /* WinMain */
39 | /* ----------------------------- */
40 | #ifdef WINMAIN
41 | int PASCAL WinMain ( HINSTANCE hInstance,
42 | HINSTANCE hPrevInstance,
43 | LPSTR lpszCmdLine,
44 | int nCmdShow )
45 | #endif
46 | int main (int argc, char *argv[])
47 | {
48 | LPSTR lpszCmdLine = argv[1];
49 | static const SERVICE_TABLE_ENTRY dispatchTable[] =
50 | {
51 | { SZSERVICENAME, (LPSERVICE_MAIN_FUNCTION) service_main },
52 | { NULL, NULL }
53 | };
54 |
55 | // ------------------------------------------
56 | // Actions :
57 | // install as service
58 | // remove as service
59 | // start in dos box
60 | // uninstall
61 | // ------------------------------------------
62 | if ( lstrcmpi( "-install", lpszCmdLine ) == 0 )
63 | {
64 | CmdInstallService();
65 | }
66 | else if ( lstrcmpi( "-remove", lpszCmdLine ) == 0 )
67 | {
68 | CmdRemoveService();
69 | }
70 | else if ( lstrcmpi( "-debug", lpszCmdLine ) == 0 )
71 | {
72 | bDebug = TRUE;
73 | CmdDebugService();
74 | }
75 | else if (lstrcmpi ("-uninstall", lpszCmdLine) == 0)
76 | {
77 | // destroy the registry entries but not the ini file
78 | Tftpd32DestroySettings ();
79 | }
80 | else
81 | {
82 | // this is just to be friendly
83 | printf ( "%s -install to install the service\n", APPLICATION );
84 | printf ( "%s -remove to remove the service\n", APPLICATION );
85 | printf ( "%s -debug to run as a console app for debugging\n", APPLICATION );
86 | printf ( "%s -uninstall to suppress registry entries and settings\n", APPLICATION );
87 | printf ( "\nStartServiceCtrlDispatcher being called.\n" );
88 | printf ( "This may take several seconds. Please wait.\n" );
89 |
90 | if (!StartServiceCtrlDispatcher(dispatchTable))
91 | {
92 | LogToMonitor ("StartServiceCtrlDispatcher failed. Error %d", GetLastError ());
93 | AddToMessageLog ("StartServiceCtrlDispatcher failed.");
94 | }
95 | }
96 | return 0;
97 | } // WinMain
98 |
99 |
100 | void ServiceStart (void)
101 | {
102 | int Rc;
103 | WSADATA WSAData;
104 | // ------------------------------------------
105 | // Start the App
106 | // ------------------------------------------
107 |
108 | Rc = WSAStartup (MAKEWORD(2,0), & WSAData);
109 | if (Rc != 0)
110 | {
111 | CMsgBox (NULL,
112 | GetLastError()==WSAVERNOTSUPPORTED ?
113 | "Error: Tftpd32 now requires winsock version 2" :
114 | "Error: Can't init Winsocket",
115 | APPLICATION,
116 | MB_OK | MB_ICONERROR);
117 | }
118 | else
119 | {
120 | // start Services
121 | StartTftpd32Services (NULL);
122 | LogToMonitor ("Tftpd32 Service Edition is ready\n");
123 | while (bDebug) { Sleep (10000); LogToMonitor ("Still Alive\n"); }
124 | }
125 | return ;
126 | } /* ServiceStart */
127 |
128 | void ServiceStop (void)
129 | {
130 | StopTftpd32Services ();
131 | Sleep (1500);
132 | WSACleanup ();
133 | LogToMonitor ("Tftpd32 service edition has ended\n");
134 | } // ServiceStop
135 |
136 |
137 |
--------------------------------------------------------------------------------
/doc-help/src/Settings Entries.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Settings Entries
6 |
7 |
8 |
9 |
10 |
11 |
Settings Entries
12 |
13 |
14 | This page lists all entries saved into the tftpd32.ini.
15 |
16 |
17 |
18 |
19 |
TFTPD32 Section
20 |
DHCP Section
21 |
22 |
23 |
24 |
25 |
BaseDirectory
26 |
The directory chosen at startup
27 |
TftpPort
28 |
The port used by the TFTP server
29 |
Hide
30 |
0 to display the main window, 1 to hide it
31 |
WinSize
32 |
The anticipation window in bytes, you may try values like 512 or 1024 bytes
33 |
Negociate
34 |
1 to enable negotiattion between client and server
35 |
PXECompatibility
36 |
1 to allow transfer size negotiation
37 |
DirText
38 |
1 to create dir.txt files
39 |
ShowProgressBar
40 |
1 to create gauge windows
41 |
Timeout
42 |
The max timeout for one packet
43 |
MaxRetransmit
44 |
The max number of retransmission for one packet
45 |
SecurityLevel
46 |
The security level. 0=NONE, 1=Standard, 2=High, 3=Read Only
47 |
UnixStrings
48 |
1 to accept file names with '/'
49 |
Beep
50 |
1 to beep when a "long transfer" terminates
51 |
VirtualRoot
52 |
1 to enable Virtual Root (the heading \ is translated to the working directory)
53 |
MD5
54 |
1 to create MD5 files for read requests
55 |
LocalIP
56 |
The address of the interface which will be bound by Tthe TFTP server, empty to accept requests from every interface
57 |
Services
58 |
An integer which gives the services to be enabled at startup
59 |
TftpLogFile
60 |
The name of the log file for TFTP server events
61 |
SaveSyslogFile
62 |
The name of the log file for syslog events
63 |
LowestUDPPort
64 |
The lowest local port to be used by the TFTP server
65 |
HighestUDPPort
66 |
The highest local port to be used by the TFTP server
67 |
MulticastPort
68 |
Unused
69 |
MulticastAddress
70 |
Unused
71 |
PersistantLeases
72 |
1 to save DHCP leases into the tftpd32.ini file
73 |
DHCP LocalIP
74 |
The IP address to be bound to the DHCP Port, empty to accept incoming requests from any interfaces
75 |
DHCP Ping
76 |
1 to ping host before address assignation
77 |
PipeSyslogMsg
78 |
1 to forward syslog messages into the named pipe Tftpd32Syslog
79 |
Max Simultaneous Transfers
80 |
Unused (limitation is actually in the code)
81 |
UseEventLog
82 |
1 to send errors into NT event log
83 |
Console Password
84 |
The password exchanged between the services and the GUI.
85 |
86 |
87 |
88 |
89 |
IP_Pool
90 |
The 4 bytes of the first address which will be assigned.
91 |
PoolSize
92 |
The number of addresses which may be distributed
93 |
BootFile
94 |
The name of the file which will be retrieved at boot for diskless or PXE clients
95 |
DNS
96 |
The 4 bytes of the IP address of the DNS
97 |
Mask
98 |
The 4 bytes of the mask to be distributed
99 |
Gateway
100 |
The 4 bytes of the gateway/router to be distributed
101 |
DomainName
102 |
The name of the window or internet domain
103 |
AddOptionNumber
104 |
The number of a specific option
105 |
AddOptionValue
106 |
The option value. the default type is text. The hexadecimal format prefixed by '0x' is also supported either for numerical values or for IP addresses.
107 |
Lease (minutes)
108 |
The DHCP lease in minutes
109 |
Static DHCP entries
110 |
The key is the MAC address (separator :), the value is the IP address
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
--------------------------------------------------------------------------------
/src/_common/bootpd_util.h:
--------------------------------------------------------------------------------
1 | //////////////////////////////////////////////////////
2 | //
3 | // Projet TFTPD32. Mai 98 Ph.jounin - June 2006
4 | // File bootpd_util.h: dhcp module data structure
5 | //
6 | // released under artistic license (see license.txt)
7 | //
8 | //////////////////////////////////////////////////////
9 |
10 |
11 | // RFC 4578 Architecture name
12 | struct S_PXE_Option93_Architecture
13 | {
14 | unsigned short val;
15 | char* name;
16 | };
17 |
18 |
19 | #define DHCP_DEFAULT_LEASE_TIME (2*24*60) // two days (in minutes)
20 |
21 | // DHCP assignations data base
22 | struct LL_IP
23 | {
24 | struct in_addr dwIP; // assignated address
25 | char sMacAddr[16]; // MAC Address of the client
26 | time_t tAllocated; // time of assignation
27 | time_t tRenewed; // time of client ack
28 | int dwAllocNum; // the number this record occupies in the ini file
29 | };
30 |
31 | extern struct LL_IP **tFirstIP; // sorted array of pointers on struct LL_IP
32 | extern struct LL_IP **tMAC; //sorted Pointers to elements in tFirstIP, indexed by MAC addr
33 | extern int nAllocatedIP; // number of item allocated (even if never acked)
34 |
35 |
36 |
37 | // The main settings table :
38 | // DHCP parameters in memory
39 |
40 | struct S_DHCP_Param
41 | {
42 | // struct in_addr dwAddr;
43 | char szAddr[64];
44 | int nPoolSize;
45 | // struct in_addr dwMask;
46 | char szMask[64];
47 | // struct in_addr dwDns;
48 | char szDns1[64];
49 | char szDns2[64];
50 | // struct in_addr dwWins;
51 | char szWins[64];
52 | // struct in_addr dwGateway;
53 | char szGateway[64];
54 | // struct in_addr dwOpt42;
55 | char szOpt42[64];
56 | // struct in_addr dwOpt120;
57 | char szOpt120[64];
58 |
59 | char szBootFile[256];
60 | char szDomainName[128];
61 | int nLease;
62 | int nIgnoreBootp;
63 | struct
64 | {
65 | int nAddOption;
66 | char szAddOption[128];
67 | }
68 | t[10];
69 | };
70 |
71 | extern struct S_DHCP_Param sParamDHCP;
72 | extern struct S_DHCP_Param sGuiParamDHCP;
73 |
74 | // written by Cengiz Beytas, it has been rewritten by Jesus Soto
75 | // int FindAdapterIP(char *szIP, DWORD *pdwAdapter, DWORD *pdwFirstAdapter);//
76 | // struct in_addr DlgItem2Address (HWND hWnd, int nDlgItem, const char *szDescr, BOOL bStrict);
77 |
78 |
79 | //struct in_addr DlgItem2Address (HWND hWnd, int nDlgItem, const char *szDescr, BOOL bStrict);
80 | int CheckInetAddress (HWND hWnd, char *szAddr, const char *szDescr, BOOL bStrict);
81 | int QsortCompare (const void *p1, const void *p2);
82 | int MACCompare (const void* p1, const void* p2);
83 | void IncNumAllocated (void);
84 | void DecNumAllocated (void);
85 | void DecNumAllocated (void);
86 | void SetNumAllocated(int n);
87 | void SetIP(struct LL_IP* pCur, DWORD newip);
88 | void SetMacAddr(struct LL_IP* pCur, const unsigned char *pMac, int nMacLen);
89 | void ZeroMacAddr(struct LL_IP* pCur);
90 | void SetAllocTime(struct LL_IP* pCur);
91 | void ZeroAllocTime(struct LL_IP* pCur);
92 | void SetRenewTime(struct LL_IP* pCur);
93 | void ForceRenewTime(struct LL_IP* pCur, time_t newtime);
94 | void ZeroRenewTime(struct LL_IP* pCur);
95 | void ReorderLeases (void);
96 | void LoadLeases(void);
97 | void FreeLeases(BOOL freepool);
98 | struct LL_IP *DHCPSearchByIP (const struct in_addr *pAddr, BOOL* wasexpired);
99 | struct LL_IP *DHCPSearchByMacAddress (const unsigned char *pMac, int nMacLen);
100 | char *TranslateExp (const char *exp, char *to, struct in_addr ip, const char *tMac, unsigned short architecture);
101 |
102 | //////////////
103 | // From ip_util.h
104 | char * haddrtoa(const unsigned char *haddr, int hlen, char cSep); //A few decls so we can use these here
105 | void atohaddr(const unsigned char *addrstr, unsigned char* haddr, int haddrlen);
106 | char* timetoa(time_t t);
107 | time_t atotime(char* str);
108 | int AddrFitsPool(struct in_addr* addr);
109 | BOOL bIPSameSubnet (struct in_addr *p1, struct in_addr *p2, struct in_addr *pMask);
110 | struct in_addr *FindNearestServerAddress (struct in_addr *pHost, struct in_addr *pMask, BOOL bExact);
111 | unsigned long AddrInc(struct in_addr in);
112 |
--------------------------------------------------------------------------------
/src/_libs/GUI/listview.c:
--------------------------------------------------------------------------------
1 | //////////////////////////////////////////////////////
2 | //
3 | // Projet TFTPD32. June 2006 Ph.jounin
4 | // File listview.c: ListView management
5 | //
6 | // source released under European Union Public License
7 | //
8 | //////////////////////////////////////////////////////
9 |
10 |
11 |
12 | #include
13 | #include
14 | #include
15 |
16 | #include "listview.h"
17 |
18 | // A workaround for a quirk bug : if the listview owns the focus, it is not properly refreshed
19 | // --> all ListView windows are subclassed to LVProc.
20 | static WNDPROC wpOrigLVProc ;
21 | #define TM_REPAINT WM_USER+10
22 | #define TM_REPAINT2 WM_USER+11
23 |
24 |
25 | // This proc just hide and show the listview control and display is OK
26 | // All others messages are parsed by the default ListView handler
27 | LRESULT CALLBACK LVProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
28 | {
29 | switch (message)
30 | {
31 | case WM_ERASEBKGND : if (GetFocus ()==hWnd)
32 | SetTimer (hWnd, TM_REPAINT, 10, NULL);
33 | break;
34 | case TM_REPAINT : // Force full repaint of the list view
35 | // This will cause a annoying flashing effect
36 | ShowWindow (hWnd, SW_HIDE);
37 | SetTimer (hWnd, TM_REPAINT2, 10, NULL);
38 | break;
39 |
40 | case TM_REPAINT2 :
41 | ShowWindow (hWnd, SW_SHOW);
42 | break;
43 |
44 | case WM_TIMER :
45 | KillTimer(hWnd, wParam);
46 | PostMessage (hWnd, (UINT) wParam, 0, 0);
47 | break;
48 | }
49 | return CallWindowProc (wpOrigLVProc, hWnd, message, wParam, lParam);
50 | } // LVProc
51 |
52 |
53 | // SetViewMode : force a style and ExtStyle for the ListView
54 | void SetViewMode (HWND hwndLV, DWORD dwView, DWORD dwExtStyle)
55 | {
56 | // recuperer le style actuel
57 | DWORD dwStyle = GetWindowLong(hwndLV, GWL_STYLE);
58 | if ((dwStyle & LVS_TYPEMASK) != dwView)
59 | SetWindowLong(hwndLV, GWL_STYLE, (dwStyle & ~LVS_TYPEMASK) | dwView);
60 | dwStyle = ListView_GetExtendedListViewStyle (hwndLV);
61 | dwStyle |= dwExtStyle;
62 | ListView_SetExtendedListViewStyle (hwndLV, dwStyle);
63 | } // SetViewMode
64 |
65 |
66 | // InitTftpd32ListView : Creates a ListView in the Tftpd32 style : LVS_REPORT
67 | // An array gives the text headers, the text alignment and the columns width
68 | BOOL InitTftpd32ListView (HWND hListV, const struct S_LVHeader *tCol, int nb, DWORD dwExtStyle)
69 | {
70 | int Ark;
71 | LVCOLUMN lvc;
72 |
73 | SetViewMode (hListV, LVS_REPORT, dwExtStyle);
74 | // subclass LV Item
75 | // wpOrigLVProc = (PVOID)SetWindowLong (hListV, GWL_WNDPROC, (LONG) LVProc);
76 | wpOrigLVProc = (WNDPROC) SetWindowLongPtr(hListV, GWLP_WNDPROC, (LONG_PTR)LVProc);
77 |
78 | for (Ark = 0; Ark < nb; Ark++)
79 | {
80 | lvc.mask = LVCF_TEXT | LVCF_FMT | LVCF_WIDTH | LVCF_SUBITEM;
81 | lvc.fmt = tCol[Ark].fmt;
82 | lvc.cx = tCol[Ark].cx;
83 | lvc.pszText = tCol[Ark].pszText;
84 | lvc.iSubItem = Ark;
85 | ListView_InsertColumn (hListV, Ark, & lvc);
86 | // SendMessage (hListV, LVM_INSERTCOLUMN, Ark, (LPARAM) &lvc);
87 | }
88 | return Ark;
89 | } // InitTftpd32ListView
90 |
91 |
92 | // Alternates background
93 | LRESULT ProcessCustomDraw (LPARAM lParam)
94 | {
95 | LPNMLVCUSTOMDRAW lplvcd = (LPNMLVCUSTOMDRAW)lParam;
96 |
97 | switch (lplvcd->nmcd.dwDrawStage)
98 | {
99 | //request notifications for individual listview items
100 | case CDDS_PREPAINT : //Before the paint cycle begins
101 | return CDRF_NOTIFYITEMDRAW;
102 |
103 | case CDDS_ITEMPREPAINT: //Before an item is drawn
104 | lplvcd->clrText = RGB(0, 0, 0);
105 | lplvcd->clrTextBk = (lplvcd->nmcd.dwItemSpec & 1) ? RGB(224,255,255) : RGB(255,255,255);
106 | return CDRF_NEWFONT;
107 | }
108 | return CDRF_DODEFAULT;
109 | } // ProcessCustomDraw
110 |
111 |
112 | // CompareStringFunc not used for DHCP server
113 | int CALLBACK CompareStringFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
114 | {
115 | LPNM_LISTVIEW pnm = (LPNM_LISTVIEW)lParamSort;
116 | char str1[256], str2[256];
117 | //Get strings item
118 | ListView_GetItemText(pnm->hdr.hwndFrom, lParam1, pnm->iSubItem, str1, sizeof str1);
119 | ListView_GetItemText(pnm->hdr.hwndFrom, lParam2, pnm->iSubItem, str2, sizeof str2);
120 | return strcmp (str1, str2);
121 | }
122 |
123 |
--------------------------------------------------------------------------------
/src/_common/Tftp.h:
--------------------------------------------------------------------------------
1 | /*
2 | * From TFTP.H
3 | * Changes made by Ph. Jounin : Constant have been prefixed by TFTP_
4 | */
5 |
6 | /*
7 | * Copyright (c) 1983, 1993
8 | * The Regents of the University of California. All rights reserved.
9 | *
10 | * Redistribution and use in source and binary forms, with or without
11 | * modification, are permitted provided that the following conditions
12 | * are met:
13 | * 1. Redistributions of source code must retain the above copyright
14 | * notice, this list of conditions and the following disclaimer.
15 | * 2. Redistributions in binary form must reproduce the above copyright
16 | * notice, this list of conditions and the following disclaimer in the
17 | * documentation and/or other materials provided with the distribution.
18 | * 3. All advertising materials mentioning features or use of this software
19 | * must display the following acknowledgement:
20 | * This product includes software developed by the University of
21 | * California, Berkeley and its contributors.
22 | * 4. Neither the name of the University nor the names of its contributors
23 | * may be used to endorse or promote products derived from this software
24 | * without specific prior written permission.
25 | *
26 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 | * SUCH DAMAGE.
37 | *
38 | * @(#)tftp.h 8.1 (Berkeley) 6/2/93
39 | */
40 |
41 |
42 |
43 | #ifndef _ARPA_TFTP_H
44 | #define _ARPA_TFTP_H
45 |
46 | /*
47 | * Trivial File Transfer Protocol (IEN-133)
48 | */
49 | #define TFTP_SEGSIZE 512 /* data segment size */
50 | #define TFTP_MAXSEGSIZE 16384 /* data segment size */
51 | #define TFTP_MINSEGSIZE 8 /* data segment size */
52 | /*
53 | * Packet types.
54 | */
55 | #define TFTP_RRQ 01 /* read request */
56 | #define TFTP_WRQ 02 /* write request */
57 | #define TFTP_DATA 03 /* data packet */
58 | #define TFTP_ACK 04 /* acknowledgement */
59 | #define TFTP_ERROR 05 /* error code */
60 | #define TFTP_OACK 06 /* option acknowledgement */
61 |
62 |
63 | struct tftphdr {
64 | short th_opcode; /* packet type */
65 | union {
66 | short tu_block; /* block # */
67 | short tu_code; /* error code */
68 | char tu_stuff[1]; /* request packet stuff */
69 | } th_u;
70 | char th_data[2]; /* data or error string */
71 | };
72 |
73 |
74 | #define th_block th_u.tu_block
75 | #define th_code th_u.tu_code
76 | #define th_stuff th_u.tu_stuff
77 | #define th_msg th_data
78 |
79 | #define TFTP_DATA_HEADERSIZE ( offsetof (struct tftphdr, th_data ) )
80 | #define TFTP_ACK_HEADERSIZE ( offsetof (struct tftphdr, th_block ) \
81 | + sizeof ( ((struct tftphdr *) (0))->th_block) )
82 |
83 | /*
84 | * Error codes.
85 | */
86 | #define EUNDEF 0 /* not defined */
87 | #define ENOTFOUND 1 /* file not found */
88 | #define EACCESS 2 /* access violation */
89 | #define ENOSPACE 3 /* disk full or allocation exceeded */
90 | #define EBADOP 4 /* illegal TFTP operation */
91 | #define EBADID 5 /* unknown transfer ID */
92 | #define EEXISTS 6 /* file already exists */
93 | #define ENOUSER 7 /* no such user */
94 | #define EBADOPTION 8 /* bad option */
95 | #define ECANCELLED 99 /* cancelled by administrator */
96 |
97 |
98 | /*
99 | * options
100 | */
101 | #define TFTP_OPT_TSIZE "tsize"
102 | #define TFTP_OPT_TIMEOUT "timeout"
103 | #define TFTP_OPT_BLKSIZE "blksize"
104 | #define TFTP_OPT_MCAST "multicast"
105 | #define TFTP_OPT_PORT "udpport"
106 |
107 | #define IS_OPT(s,opt) (lstrcmpi (s, opt)==0)
108 |
109 | #define PKTSIZE TFTP_SEGSIZE+4
110 | #define MAXPKTSIZE TFTP_MAXSEGSIZE+4
111 |
112 |
113 | #endif /* _ARPA_TFTP_H */
114 |
--------------------------------------------------------------------------------
/tftpd32.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 11.00
3 | # Visual Studio 2010
4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libs", "src\libs.vcxproj", "{03DA840D-A90F-4898-9752-9756FE2ECDFC}"
5 | EndProject
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "tftpd32", "src\tftpd32.vcxproj", "{D473F930-F0BE-4F67-9941-280EBD6D0026}"
7 | ProjectSection(ProjectDependencies) = postProject
8 | {03DA840D-A90F-4898-9752-9756FE2ECDFC} = {03DA840D-A90F-4898-9752-9756FE2ECDFC}
9 | EndProjectSection
10 | EndProject
11 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "tftpd32_gui", "src\tftpd32_gui.vcxproj", "{FB022672-AC7E-4DB2-8405-845C838CCEC6}"
12 | ProjectSection(ProjectDependencies) = postProject
13 | {03DA840D-A90F-4898-9752-9756FE2ECDFC} = {03DA840D-A90F-4898-9752-9756FE2ECDFC}
14 | EndProjectSection
15 | EndProject
16 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "tftpd32_svc", "src\tftpd32_svc.vcxproj", "{F6533807-DC90-41CD-A8E4-0785DB31B92A}"
17 | ProjectSection(ProjectDependencies) = postProject
18 | {03DA840D-A90F-4898-9752-9756FE2ECDFC} = {03DA840D-A90F-4898-9752-9756FE2ECDFC}
19 | EndProjectSection
20 | EndProject
21 | Global
22 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
23 | Debug|Itanium = Debug|Itanium
24 | Debug|Win32 = Debug|Win32
25 | Debug|x64 = Debug|x64
26 | Release|Itanium = Release|Itanium
27 | Release|Win32 = Release|Win32
28 | Release|x64 = Release|x64
29 | EndGlobalSection
30 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
31 | {03DA840D-A90F-4898-9752-9756FE2ECDFC}.Debug|Itanium.ActiveCfg = Debug|x64
32 | {03DA840D-A90F-4898-9752-9756FE2ECDFC}.Debug|Win32.ActiveCfg = Debug|Win32
33 | {03DA840D-A90F-4898-9752-9756FE2ECDFC}.Debug|Win32.Build.0 = Debug|Win32
34 | {03DA840D-A90F-4898-9752-9756FE2ECDFC}.Debug|x64.ActiveCfg = Debug|x64
35 | {03DA840D-A90F-4898-9752-9756FE2ECDFC}.Debug|x64.Build.0 = Debug|x64
36 | {03DA840D-A90F-4898-9752-9756FE2ECDFC}.Release|Itanium.ActiveCfg = Release|x64
37 | {03DA840D-A90F-4898-9752-9756FE2ECDFC}.Release|Win32.ActiveCfg = Release|Win32
38 | {03DA840D-A90F-4898-9752-9756FE2ECDFC}.Release|Win32.Build.0 = Release|Win32
39 | {03DA840D-A90F-4898-9752-9756FE2ECDFC}.Release|x64.ActiveCfg = Release|x64
40 | {03DA840D-A90F-4898-9752-9756FE2ECDFC}.Release|x64.Build.0 = Release|x64
41 | {D473F930-F0BE-4F67-9941-280EBD6D0026}.Debug|Itanium.ActiveCfg = Debug|Win32
42 | {D473F930-F0BE-4F67-9941-280EBD6D0026}.Debug|Win32.ActiveCfg = Debug|Win32
43 | {D473F930-F0BE-4F67-9941-280EBD6D0026}.Debug|Win32.Build.0 = Debug|Win32
44 | {D473F930-F0BE-4F67-9941-280EBD6D0026}.Debug|x64.ActiveCfg = Debug|x64
45 | {D473F930-F0BE-4F67-9941-280EBD6D0026}.Debug|x64.Build.0 = Debug|x64
46 | {D473F930-F0BE-4F67-9941-280EBD6D0026}.Release|Itanium.ActiveCfg = Release|Win32
47 | {D473F930-F0BE-4F67-9941-280EBD6D0026}.Release|Win32.ActiveCfg = Release|Win32
48 | {D473F930-F0BE-4F67-9941-280EBD6D0026}.Release|Win32.Build.0 = Release|Win32
49 | {D473F930-F0BE-4F67-9941-280EBD6D0026}.Release|x64.ActiveCfg = Release|x64
50 | {D473F930-F0BE-4F67-9941-280EBD6D0026}.Release|x64.Build.0 = Release|x64
51 | {FB022672-AC7E-4DB2-8405-845C838CCEC6}.Debug|Itanium.ActiveCfg = Debug|Win32
52 | {FB022672-AC7E-4DB2-8405-845C838CCEC6}.Debug|Win32.ActiveCfg = Debug|Win32
53 | {FB022672-AC7E-4DB2-8405-845C838CCEC6}.Debug|Win32.Build.0 = Debug|Win32
54 | {FB022672-AC7E-4DB2-8405-845C838CCEC6}.Debug|x64.ActiveCfg = Debug|x64
55 | {FB022672-AC7E-4DB2-8405-845C838CCEC6}.Debug|x64.Build.0 = Debug|x64
56 | {FB022672-AC7E-4DB2-8405-845C838CCEC6}.Release|Itanium.ActiveCfg = Release|Win32
57 | {FB022672-AC7E-4DB2-8405-845C838CCEC6}.Release|Win32.ActiveCfg = Release|Win32
58 | {FB022672-AC7E-4DB2-8405-845C838CCEC6}.Release|Win32.Build.0 = Release|Win32
59 | {FB022672-AC7E-4DB2-8405-845C838CCEC6}.Release|x64.ActiveCfg = Release|x64
60 | {FB022672-AC7E-4DB2-8405-845C838CCEC6}.Release|x64.Build.0 = Release|x64
61 | {F6533807-DC90-41CD-A8E4-0785DB31B92A}.Debug|Itanium.ActiveCfg = Debug|Win32
62 | {F6533807-DC90-41CD-A8E4-0785DB31B92A}.Debug|Win32.ActiveCfg = Debug|Win32
63 | {F6533807-DC90-41CD-A8E4-0785DB31B92A}.Debug|Win32.Build.0 = Debug|Win32
64 | {F6533807-DC90-41CD-A8E4-0785DB31B92A}.Debug|x64.ActiveCfg = Debug|x64
65 | {F6533807-DC90-41CD-A8E4-0785DB31B92A}.Debug|x64.Build.0 = Debug|x64
66 | {F6533807-DC90-41CD-A8E4-0785DB31B92A}.Release|Itanium.ActiveCfg = Release|Win32
67 | {F6533807-DC90-41CD-A8E4-0785DB31B92A}.Release|Win32.ActiveCfg = Release|Win32
68 | {F6533807-DC90-41CD-A8E4-0785DB31B92A}.Release|Win32.Build.0 = Release|Win32
69 | {F6533807-DC90-41CD-A8E4-0785DB31B92A}.Release|x64.ActiveCfg = Release|x64
70 | {F6533807-DC90-41CD-A8E4-0785DB31B92A}.Release|x64.Build.0 = Release|x64
71 | EndGlobalSection
72 | GlobalSection(SolutionProperties) = preSolution
73 | HideSolutionNode = FALSE
74 | EndGlobalSection
75 | EndGlobal
76 |
--------------------------------------------------------------------------------
/installers/4-vt_upload.ps1.bak.txt:
--------------------------------------------------------------------------------
1 | <# vt_upload.ps1 — VirusTotal v3 uploader (PS 5.1+ compatible)
2 | Usage:
3 | $env:VT_API_KEY = 'YOUR_API_KEY'
4 | powershell -ExecutionPolicy Bypass -File .\vt_upload.ps1 -Path "..\ARTS\BIN\dist\4.72\signed\" -ApiKey f1..
5 | # Or pass a directory; the script will expand to *.exe inside it.
6 | #>
7 |
8 | param(
9 | [Parameter(Mandatory=$true)]
10 | [string[]]$Path,
11 | [string]$ApiKey = $env:VT_API_KEY,
12 | [switch]$Private,
13 | [switch]$NoWait,
14 | [int]$PollSeconds = 4,
15 | [int]$MaxPolls = 150
16 | )
17 |
18 | if (-not $ApiKey) { throw "Set -ApiKey or `$env:VT_API_KEY`." }
19 |
20 | $VTBase = "https://www.virustotal.com/api/v3"
21 | $Headers = @{ "x-apikey" = $ApiKey }
22 |
23 | function Resolve-Targets([string[]]$Paths) {
24 | $items = @()
25 | foreach ($p in $Paths) {
26 | if (Test-Path -LiteralPath $p -PathType Container) {
27 | $items += Get-ChildItem -LiteralPath $p -Filter *.exe -File
28 | } else {
29 | $items += Get-ChildItem -LiteralPath $p -File
30 | }
31 | }
32 | $items | Sort-Object FullName -Unique
33 | }
34 |
35 | function Get-UploadUrl([int64]$Size, [switch]$UsePrivate) {
36 | if ($UsePrivate) {
37 | if ($Size -le 32MB) { return "$VTBase/private/files" }
38 | return (Invoke-RestMethod -Headers $Headers -Uri "$VTBase/private/files/upload_url" -Method GET).data
39 | } else {
40 | if ($Size -le 32MB) { return "$VTBase/files" }
41 | return (Invoke-RestMethod -Headers $Headers -Uri "$VTBase/files/upload_url" -Method GET).data
42 | }
43 | }
44 |
45 | # PS 5.1-safe multipart/form-data upload using HttpClient
46 | Add-Type -AssemblyName System.Net.Http
47 | Add-Type -AssemblyName System.Net.Http.WebRequest
48 | function Post-FileMultipart([string]$Uri, [System.IO.FileInfo]$File) {
49 | $handler = New-Object System.Net.Http.HttpClientHandler
50 | $client = New-Object System.Net.Http.HttpClient($handler)
51 | $client.DefaultRequestHeaders.Add("x-apikey", $ApiKey)
52 | $content = New-Object System.Net.Http.MultipartFormDataContent
53 | $fs = [System.IO.File]::OpenRead($File.FullName)
54 | try {
55 | $sc = New-Object System.Net.Http.StreamContent($fs)
56 | $sc.Headers.ContentType = [System.Net.Http.Headers.MediaTypeHeaderValue]::Parse("application/octet-stream")
57 | $content.Add($sc, "file", $File.Name)
58 | $resp = $client.PostAsync($Uri, $content).Result
59 | $resp.EnsureSuccessStatusCode() | Out-Null
60 | $json = $resp.Content.ReadAsStringAsync().Result
61 | return ($json | ConvertFrom-Json)
62 | } finally {
63 | $content.Dispose(); $client.Dispose(); $fs.Dispose()
64 | }
65 | }
66 |
67 | function Wait-Analysis([string]$Id) {
68 | for ($i=0; $i -lt $MaxPolls; $i++) {
69 | $a = Invoke-RestMethod -Headers $Headers -Uri "$VTBase/analyses/$Id" -Method GET
70 | if ($a.data.attributes.status -eq 'completed') { return $a }
71 | Start-Sleep -Seconds $PollSeconds
72 | }
73 | throw "Timeout waiting for $Id"
74 | }
75 |
76 | function Get-Report([string]$Sha256) {
77 | Invoke-RestMethod -Headers $Headers -Uri "$VTBase/files/$Sha256" -Method GET
78 | }
79 |
80 | $files = Resolve-Targets $Path
81 | if (-not $files) { Write-Error "No files matched."; exit 1 }
82 |
83 | $rows = @()
84 | foreach ($fi in $files) {
85 | $sha = (Get-FileHash -LiteralPath $fi.FullName -Algorithm SHA256).Hash.ToLower()
86 | Write-Host ">> Uploading $($fi.Name) (SHA256=$sha)..."
87 | try {
88 | $upl = Get-UploadUrl -Size $fi.Length -UsePrivate:$Private
89 | $submit = Post-FileMultipart -Uri $upl -File $fi
90 | $analysisId = $submit.data.id
91 |
92 | if ($NoWait) {
93 | $rows += [pscustomobject]@{File=$fi.Name; Sha256=$sha; AnalysisId=$analysisId; Link="https://www.virustotal.com/gui/file/$sha"}
94 | continue
95 | }
96 |
97 | $done = Wait-Analysis $analysisId
98 | $sha_dl = $done.meta.file_info.sha256
99 | if (-not $sha_dl) { $sha_dl = $sha }
100 | $rep = Get-Report $sha_dl
101 | $s = $rep.data.attributes.last_analysis_stats
102 | $link = "https://www.virustotal.com/gui/file/$sha_dl"
103 | "{0} => M:{1} S:{2} H:{3} U:{4} {5}" -f $fi.Name, $s.malicious, $s.suspicious, $s.harmless, $s.undetected, $link | Write-Host
104 |
105 | $rows += [pscustomobject]@{
106 | File=$fi.Name; Sha256=$sha_dl; AnalysisId=$analysisId
107 | Malicious=$s.malicious; Suspicious=$s.suspicious; Harmless=$s.harmless; Undetected=$s.undetected
108 | Link=$link
109 | }
110 | } catch {
111 | Write-Warning "Failed on $($fi.Name): $($_.Exception.Message)"
112 | $rows += [pscustomobject]@{File=$fi.Name; Sha256=$sha; AnalysisId=$null; Malicious=$null; Suspicious=$null; Harmless=$null; Undetected=$null; Link=$null; Error=$_.Exception.Message}
113 | }
114 | }
115 |
116 | if ($rows.Count) {
117 | $csv = "vt_results_{0:yyyyMMdd_HHmmss}.csv" -f (Get-Date)
118 | $rows | Export-Csv -Path $csv -NoTypeInformation -Encoding UTF8
119 | Write-Host "Saved CSV: $csv"
120 | }
121 |
--------------------------------------------------------------------------------
/src/_common/tftp_struct.h:
--------------------------------------------------------------------------------
1 | //////////////////////////////////////////////////////
2 | //
3 | // Projet TFTPD32. Mai 98 Ph.jounin - June 2006
4 | // File tftp_struct.h: Tftpd32 data structure
5 | //
6 | // released under artistic license (see license.txt)
7 | //
8 | //////////////////////////////////////////////////////
9 |
10 |
11 | #define MAX_TFTP_OPTIONS 16
12 |
13 |
14 | ////////////////////////////////////////////////////////////
15 | // The transfer/thread structure
16 | // This whole structure is allocated for each transfer = for each thread
17 | // (since a new thread is started for each new transfer)
18 | ////////////////////////////////////////////////////////////
19 |
20 | enum e_TftpRetCode { TFTP_TRF_RUNNING, TFTP_TRF_SUCCESS, TFTP_TRF_STOPPED, TFTP_TRF_ERROR };
21 |
22 | // settings for the current transfer
23 | struct S_Trf_Settings
24 | {
25 | DWORD dwPacketSize; // Size of a data packet : Note this is a key data
26 | // since if size of received packet != dwPacketSize
27 | // transfer is terminated
28 | DWORD dwTimeout; // Timeout
29 | unsigned TftpMode; // transfer mode, only binary mode is supported
30 | unsigned ExtraWinSize; // Data to sent without waiting for ACK
31 | __int64 qwFileSize; // -1 if not set
32 | DWORD dwMcastAddr; // Multicast address
33 | }; // struct S_Trf_Settings
34 |
35 | // Buffers
36 | struct S_Trf_Buffers
37 | {
38 | char buf[MAXPKTSIZE]; // one piece of file
39 | char ackbuf[PKTSIZE];
40 | SOCKADDR_STORAGE from ; // stack of address of remote peers
41 | char cnx_frame[PKTSIZE]; // The 'connexion' datagram, contains file name
42 | char padding[4]; // set to zero before reading connect datagram
43 | } ; // struct S_Trf_Buffers
44 |
45 | // transfer stats and progress bar : not mandatory
46 | struct S_Trf_Statistics
47 | {
48 | DWORD dwTransfert; // number of simultaned trf
49 | __int64 qwTotalBytes; // number of transferred bytes
50 | __int64 qwTransferSize; // transfer size (GetFileSizeEx)
51 | DWORD dwTotalTimeOut; // for stat
52 | time_t StartTime;
53 | time_t dLastUpdate; // Last gauge update (seconds)
54 | DWORD ret_code;
55 | } ; // struct S_Trf_Statistics
56 | // control data
57 | struct S_Trf_Control
58 | {
59 | BOOL bMCast; // current transfer is multicast
60 | DWORD nCount; // current packet #
61 | DWORD nLastBlockOfFile; // Last block of file
62 | // DWORD dwLastAckPacket; // Sorcerer's Apprentice Syndrome
63 | DWORD nLastToSend; // last sent packet
64 | DWORD dwBytes; // taille de la zone Data (th_stuff)
65 | unsigned nTimeOut; // # of consecutive timeouts
66 | unsigned nRetries; // same datagram resent # times
67 | int nOAckPort; // OAck should be sent on this port
68 | }; // struct S_Trf_Control
69 | // resource allocated for the transfer
70 | struct S_Trf_Resource
71 | {
72 | SOCKET skt; // socket de la connexion
73 | HANDLE hFile; // file handler
74 | // HWND hGaugeWnd; // Handler of Gauge Window
75 | } ; // struct S_Trf_Resource
76 | // Thread management
77 | struct S_Thread_Management
78 | {
79 | // The thread which manages the transfer
80 | BOOL bActive ; // act as a semaphore
81 | // TRUE if thread is busy
82 | BOOL bPermanentThread ; // is thread permanent
83 | HANDLE dwThreadHandle;
84 | DWORD dwThreadHandleId;
85 | HANDLE hEvent; // Event used to activate permanent threads
86 | HWND hWnd; // identifiant of main window
87 | DWORD dwTransferId; // transfer id
88 | int N;
89 | } ; // struct S_Thread_Management
90 | // MD5 computation data
91 | struct S_Trf_MD5
92 | {
93 | BOOL bInit; // contains a copy of bMD5 settings (which may be changed)
94 | MD5_CTX ctx;
95 | unsigned char ident [16];
96 | } ; // struct S_Trf_MD5
97 |
98 |
99 | // The super structure and pointer to next block
100 | struct LL_TftpInfo
101 | {
102 | struct S_Thread_Management tm;
103 | struct S_Trf_Resource r;
104 | struct S_Trf_Control c;
105 | struct S_Trf_Settings s;
106 | struct S_Trf_Buffers b;
107 | struct S_Trf_Statistics st;
108 | struct S_Trf_MD5 m;
109 |
110 | struct LL_TftpInfo *next;
111 | } ;
112 |
113 | ////////////////////////////////////////////////////////////
114 | // End of transfer/thread structure
115 | ////////////////////////////////////////////////////////////
116 |
--------------------------------------------------------------------------------
/src/_services/syslogd.c:
--------------------------------------------------------------------------------
1 | //////////////////////////////////////////////////////
2 | //
3 | // Projet TFTPD32. Mai 98 Ph.jounin
4 | // File syslogd.c: Syslog
5 | //
6 | // source released under European Union Public License
7 | //
8 | //////////////////////////////////////////////////////
9 |
10 | #include "headers.h"
11 | #include "threading.h"
12 |
13 |
14 | static HANDLE hSysLogFile = INVALID_HANDLE_VALUE;
15 |
16 | const char *sPipeName = "\\\\.\\pipe\\Tftpd32Syslog";
17 |
18 |
19 | ///////////////////////////////////////////////////////
20 | // Open the log file
21 | // uses sSettings, modifies hSysLogFile
22 | ///////////////////////////////////////////////////////
23 | void SyslogCreateLogFile (LPSTR szLogFile)
24 | {
25 | if (hSysLogFile !=INVALID_HANDLE_VALUE)
26 | CloseHandle (hSysLogFile);
27 |
28 | // if file already exists append at end of file
29 | if (szLogFile != NULL && szLogFile[0]!=0)
30 | {
31 | hSysLogFile = CreateFile (szLogFile,
32 | GENERIC_WRITE,
33 | FILE_SHARE_READ,
34 | NULL,
35 | OPEN_ALWAYS,
36 | FILE_ATTRIBUTE_ARCHIVE | FILE_FLAG_SEQUENTIAL_SCAN ,
37 | NULL);
38 | // seek end of file
39 | //if (hSysLogFile==INVALID_HANDLE_VALUE)
40 | // MY_WARNING ("can not open Syslog File");
41 | SetFilePointer (hSysLogFile, 0, 0, FILE_END);
42 | }
43 | } // SyslogOpenLog
44 |
45 |
46 |
47 |
48 | // check that received message match the form '<....?.?>'
49 | // may be this must be an option
50 | BOOL CheckSyslogMsg (char *SyslogTxt, int nSize)
51 | {
52 | int Ark;
53 | if (nSize < 5) return FALSE;
54 | if ( SyslogTxt[0] != '<'
55 | && (SyslogTxt[4] != '>' || SyslogTxt[5] != '>' || SyslogTxt[6] != '>')
56 | ) return FALSE;
57 |
58 | SyslogTxt[nSize] = 0;
59 | for (Ark=0 ; Ark0 && CheckSyslogMsg (szSyslogBuf, Rc) )
101 | {
102 |
103 | // who sent the UDP message
104 | getnameinfo ( (LPSOCKADDR) & sSock, sizeof sSock,
105 | msg.from, sizeof msg.from,
106 | NULL, 0,
107 | NI_NUMERICHOST );
108 | if ( sSock.ss_family == AF_INET6
109 | && IN6_IS_ADDR_V4MAPPED ( & (* (struct sockaddr_in6 *) & sSock ).sin6_addr ) )
110 | {
111 | memmove (msg.from, msg.from + sizeof ("::ffff:") - 1, strlen (msg.from + sizeof ("::ffff:") -1) +1 );
112 | }
113 | msg.from[sizeof msg.from - 1] = 0; // probably paranoid
114 |
115 |
116 | if (hSysLogFile != INVALID_HANDLE_VALUE)
117 | {
118 | struct tm *newtime;
119 | time_t tm;
120 | int Dummy;
121 | char szTxt[SYSLOG_MAXMSG + 1 + 30];
122 | time(&tm);
123 | newtime = localtime(&tm);
124 | // copy in file the string without the new-line
125 | wsprintf(szTxt,"%24.24s;%s; %s\r\n",asctime(newtime),msg.from,szSyslogBuf);
126 | WriteFile(hSysLogFile, szTxt, lstrlen(szTxt), &Dummy, NULL);
127 | } // log in file
128 |
129 | if (m_hPipe != INVALID_HANDLE_VALUE) WriteFile(m_hPipe, szSyslogBuf, Rc, &nDummy, NULL);
130 |
131 | lstrcpy (msg.txt, szSyslogBuf);
132 | SendMsgRequest ( C_SYSLOG,
133 | & msg,
134 | 1 + Rc + sizeof msg.from,
135 | FALSE, // don't block thread until msg sent
136 | FALSE ); // if no GUI return
137 | }
138 | } // loop
139 |
140 | if (m_hPipe != INVALID_HANDLE_VALUE) CloseHandle (m_hPipe);
141 | if (hSysLogFile != INVALID_HANDLE_VALUE) CloseHandle (hSysLogFile);
142 | LogToMonitor ("End of Syslog thread\n");
143 | _endthread ();
144 | } // SyslogDProc
145 |
146 |
--------------------------------------------------------------------------------
/src/_gui/gui_tftp_dir.c:
--------------------------------------------------------------------------------
1 | //////////////////////////////////////////////////////
2 | //
3 | // Projet TFTPD32. Nov 2002 Ph.jounin
4 | // File tftp_dir.c: Display contents of current directory
5 | //
6 | // released under artistic license
7 | //
8 | //////////////////////////////////////////////////////
9 |
10 |
11 | #include "headers.h"
12 |
13 |
14 | #ifdef _M_X64
15 | # define TFTPD_DIR_TITLE "Tftpd64: directory"
16 | #else
17 | # define TFTPD_DIR_TITLE "Tftpd32: directory"
18 | #endif
19 |
20 |
21 | // Start an explorer window, directory is Tftpd32's default directory
22 | int StartExplorer (void)
23 | {
24 | // A fix from Colin to authorize directories including commas
25 | #define EXPLORER "explorer.exe \""
26 | STARTUPINFO sInfo;
27 | PROCESS_INFORMATION pInfo;
28 | int Rc;
29 | char szCmdString [sizeof EXPLORER + _MAX_PATH];
30 |
31 | lstrcpy (szCmdString, EXPLORER);
32 | GetActiveDirectory (szCmdString + (sizeof EXPLORER - 1), _MAX_PATH-1);
33 | lstrcat (szCmdString, "\"");
34 |
35 | memset (& sInfo, 0, sizeof sInfo);
36 | sInfo.cb = sizeof sInfo;
37 |
38 | Rc = CreateProcess(NULL, szCmdString, NULL, NULL, FALSE,
39 | NORMAL_PRIORITY_CLASS, NULL, NULL, &sInfo, &pInfo) ;
40 | CloseHandle (pInfo.hProcess);
41 | CloseHandle (pInfo.hThread);
42 | return Rc;
43 | } // StartExplorer
44 |
45 |
46 | ////////////////////////
47 | // The change directory command :
48 | // manages the CB_DIR combo box
49 | int TftpDir_AddEntry (HWND hCBWnd, const char *szPath)
50 | {
51 | int Rc=-1;
52 |
53 | Rc = ComboBox_FindStringExact (hCBWnd, -1, szPath);
54 | if (Rc==CB_ERR) Rc = ComboBox_AddString (hCBWnd, szPath);
55 | ComboBox_SetCurSel (hCBWnd, Rc);
56 | return Rc;
57 | } // TftpDir_AddEntry
58 |
59 |
60 |
61 | int TftpDir_SelectEntry (HWND hCBWnd)
62 | {
63 | char szPath[_MAX_PATH];
64 |
65 | int n = ComboBox_GetCurSel (hCBWnd);
66 | if ( n!=CB_ERR
67 | && ComboBox_GetLBTextLen (hCBWnd, n) < sizeof szPath )
68 | {
69 | ComboBox_GetLBText (hCBWnd, n, sGuiSettings.szWorkingDirectory);
70 | }
71 | return TRUE;
72 | } // TftpDir_SelectEntry
73 |
74 |
75 |
76 | // list the entries (called ONCE at the end in order to save them)
77 | int TftpDir_GetNextEntry (HWND hCBWnd)
78 | {
79 | static int n;
80 | static char szPath [_MAX_PATH];
81 | return (ComboBox_GetLBText (hCBWnd, n++, szPath) != CB_ERR);
82 | } // TftpDir_GetNextEntry
83 |
84 | ////////////////////////
85 | // Callback for the Show Dir function
86 | static int CbkDisplay (char *szLine, DWORD dw)
87 | {
88 | SendMessage ((HWND) dw, LB_ADDSTRING, 0, (LPARAM) szLine);
89 | return 0;
90 | }
91 |
92 |
93 |
94 | // The commands : Select, OK & Cancel
95 | static int Handle_VM_Command (HWND hWnd, WPARAM wParam, LPARAM lParam)
96 | {
97 | int wItem = (int) LOWORD (wParam);
98 | switch (wItem)
99 | {
100 | // Copy filename into clipboard
101 | case IDC_LB_SHDIR :
102 | if (HIWORD(wParam) == LBN_SELCHANGE)
103 | {char szLine [256], *p ;
104 | int n = (int) SendMessage ((HWND) lParam, LB_GETCURSEL, 0, 0);
105 | SendMessage ((HWND) lParam, LB_GETTEXT, n, (LPARAM) szLine);
106 | if (SendMessage ((HWND) lParam, LB_GETTEXTLEN, n, 0) >= sizeof szLine)
107 | break;
108 | // cut string before tab
109 | p = strchr (szLine, '\t');
110 | if (p!=NULL) *p=0;
111 | CopyTextToClipboard (szLine);
112 | }
113 | break;
114 | case IDOK :
115 | // fallthrough
116 | case IDCANCEL :
117 | EndDialog (hWnd, 0);
118 | break;
119 | case IDC_SD_COPY :
120 | // do nothing since the file name has already been copied
121 | break;
122 | case IDC_SD_EXPLORER : // start an explorer and close window
123 | StartExplorer ();
124 | PostMessage (hWnd, WM_CLOSE, 0, 0);
125 | break;
126 | } // switch wItem
127 | return FALSE;
128 | } // Handle_VM_Command
129 |
130 |
131 |
132 | /////////////////////////////////////////
133 | // Dir window callback
134 | LRESULT CALLBACK ShDirProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
135 | {
136 | static const int tTabs[] = { 100, 150 };
137 | struct S_DirectoryContent *pDir = (struct S_DirectoryContent *) lParam;
138 | HWND hLBWnd = GetDlgItem (hWnd, IDC_LB_SHDIR);
139 | int Ark;
140 |
141 | switch (message)
142 | {
143 | case WM_INITDIALOG :
144 | // Set the window name to either tftpd32 or tftpd64
145 | SetWindowText (hWnd, TFTPD_DIR_TITLE);
146 |
147 | ListBox_SetTabStops ( hLBWnd, SizeOfTab(tTabs), tTabs );
148 | ListBox_ResetContent ( hLBWnd );
149 | for ( Ark=0 ; Ark < pDir->nb ; Ark++ )
150 | ListBox_AddString ( hLBWnd, pDir->ent[Ark].file_descr );
151 | CenterChildWindow (hWnd, CCW_INSIDE | CCW_VISIBLE);
152 | // If GUI is in remote mode, deactivate Explorer Button
153 | if ( IsGuiConnectedToRemoteService () )
154 | Button_Enable (GetDlgItem (hWnd, IDC_SD_EXPLORER), FALSE);
155 | break;
156 |
157 | case WM_COMMAND :
158 | Handle_VM_Command (hWnd, wParam, lParam);
159 | break;
160 | case WM_CLOSE :
161 | case WM_DESTROY :
162 | EndDialog (hWnd, 0);
163 | break;
164 |
165 | } // switch
166 |
167 | return FALSE;
168 | } // ShDirProc
169 |
170 |
--------------------------------------------------------------------------------
/tests/tftp_test_utils.py:
--------------------------------------------------------------------------------
1 | """
2 | Minimal TFTP client utilities for testing Tftpd64 (RFC 1350).
3 | No third-party deps. Python 3.8+.
4 | """
5 | import os
6 | import socket
7 | import struct
8 | import time
9 | from typing import Tuple, Optional
10 |
11 | # TFTP opcodes
12 | OP_RRQ = 1
13 | OP_WRQ = 2
14 | OP_DATA = 3
15 | OP_ACK = 4
16 | OP_ERROR = 5
17 | OP_OACK = 6 # not used here, but defined
18 |
19 | DEFAULT_MODE = b'octet'
20 |
21 | class TftpError(Exception):
22 | def __init__(self, code:int, msg:str):
23 | super().__init__(f"TFTP Error {code}: {msg}")
24 | self.code = code
25 | self.msg = msg
26 |
27 | def _build_request(op:int, filename:bytes, mode:bytes=DEFAULT_MODE) -> bytes:
28 | if b'\x00' in filename:
29 | raise ValueError("filename must not contain NUL")
30 | return struct.pack("!H", op) + filename + b'\x00' + mode + b'\x00'
31 |
32 | def _parse_error(pkt:bytes) -> Tuple[int,str]:
33 | _, errcode = struct.unpack("!HH", pkt[:4])
34 | msg = pkt[4:].split(b'\x00',1)[0].decode(errors='replace')
35 | return errcode, msg
36 |
37 | def parse_tftp_error(pkt: Optional[bytes]) -> Optional[Tuple[int, str]]:
38 | """
39 | Public helper: return (code, message) if pkt is a TFTP ERROR(5), else None.
40 | """
41 | if not pkt or len(pkt) < 5 or pkt[:2] != struct.pack("!H", OP_ERROR):
42 | return None
43 | return _parse_error(pkt)
44 |
45 | def tftp_rrq(host:str, port:int, filename:str, timeout:float=5.0, blocksize:int=512) -> bytes:
46 | """Read a file from TFTP server. Returns the content as bytes."""
47 | addr = (host, port)
48 | sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
49 | sock.settimeout(timeout)
50 | try:
51 | # send RRQ to well-known port
52 | sock.sendto(_build_request(OP_RRQ, filename.encode('utf-8')), addr)
53 | data = bytearray()
54 | expected_block = 1
55 | server_addr = None
56 | while True:
57 | pkt, srv = sock.recvfrom(4 + 2 + blocksize)
58 | if server_addr is None:
59 | server_addr = srv # server chooses a new ephemeral port (TID)
60 | if pkt[:2] == struct.pack("!H", OP_ERROR):
61 | code, msg = _parse_error(pkt)
62 | raise TftpError(code, msg)
63 | op = struct.unpack("!H", pkt[:2])[0]
64 | if op != OP_DATA:
65 | # ignore unexpected
66 | continue
67 | _, block = struct.unpack("!HH", pkt[:4])
68 | if block == expected_block:
69 | payload = pkt[4:]
70 | data.extend(payload)
71 | # ACK
72 | sock.sendto(struct.pack("!HH", OP_ACK, block), server_addr)
73 | expected_block = (expected_block + 1) & 0xFFFF
74 | if len(payload) < blocksize:
75 | break
76 | else:
77 | # Duplicate/out-of-order: ACK last good
78 | last = (expected_block - 1) & 0xFFFF
79 | sock.sendto(struct.pack("!HH", OP_ACK, last), server_addr)
80 | return bytes(data)
81 | finally:
82 | sock.close()
83 |
84 | def tftp_wrq(host:str, port:int, filename:str, content:bytes, timeout:float=5.0, blocksize:int=512) -> None:
85 | """Write a file to a TFTP server. Raises TftpError if refused or failed."""
86 | addr = (host, port)
87 | sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
88 | sock.settimeout(timeout)
89 | try:
90 | sock.sendto(_build_request(OP_WRQ, filename.encode('utf-8')), addr)
91 | # Expect ACK(0) from server with new TID
92 | pkt, server_addr = sock.recvfrom(4 + 2)
93 | if pkt[:2] == struct.pack("!H", OP_ERROR):
94 | code, msg = _parse_error(pkt)
95 | raise TftpError(code, msg)
96 | if pkt[:2] != struct.pack("!H", OP_ACK) or pkt[2:4] != b'\x00\x00':
97 | raise RuntimeError("Unexpected response to WRQ")
98 | # send DATA blocks
99 | block = 1
100 | offset = 0
101 | while True:
102 | chunk = content[offset:offset+blocksize]
103 | sock.sendto(struct.pack("!HH", OP_DATA, block) + chunk, server_addr)
104 | # wait ACK(block)
105 | pkt, _ = sock.recvfrom(4 + 2)
106 | if pkt[:2] == struct.pack("!H", OP_ERROR):
107 | code, msg = _parse_error(pkt)
108 | raise TftpError(code, msg)
109 | op, ack_block = struct.unpack("!HH", pkt[:4])
110 | if op != OP_ACK or ack_block != block:
111 | # retry simple once on mismatch
112 | pkt, _ = sock.recvfrom(4 + 2)
113 | op, ack_block = struct.unpack("!HH", pkt[:4])
114 | if op != OP_ACK or ack_block != block:
115 | raise RuntimeError("Did not receive matching ACK")
116 | offset += len(chunk)
117 | block = (block + 1) & 0xFFFF
118 | if len(chunk) < blocksize:
119 | break
120 | finally:
121 | sock.close()
122 |
123 | def send_forged_packet(host:str, port:int, payload:bytes, timeout:float=1.0) -> Optional[bytes]:
124 | """Send a raw UDP packet to TFTP well-known port and return any immediate reply (if any)."""
125 | sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
126 | sock.settimeout(timeout)
127 | try:
128 | sock.sendto(payload, (host, port))
129 | try:
130 | resp, _ = sock.recvfrom(1500)
131 | return resp
132 | except socket.timeout:
133 | return None
134 | finally:
135 | sock.close()
136 |
--------------------------------------------------------------------------------
/src/_libs/linked_list/linked_list.c:
--------------------------------------------------------------------------------
1 | //////////////////////////////////////////////////////
2 | //
3 | // Projet TFTPD32. November 2006 Ph.jounin
4 | // A free DHCP server for Windows
5 | // File linked list.c: Linked list management
6 | // from Nick Wagner
7 | //
8 | //
9 | // Released under European Union Public License
10 | //
11 | //////////////////////////////////////////////////////
12 |
13 | #include
14 | #include
15 | #include "linked_list.h"
16 |
17 | // ---------------------------------------------------------------
18 | // A multithread linked list
19 | // This module exports the function LL_PushMsg and LL_PopMsg
20 | // which add (retrieve) a message to (from) a list
21 | // A Semaphore is defined in order to prevent corrupted data
22 | // ---------------------------------------------------------------
23 |
24 |
25 | #define SizeOfTab(x) ( (int) (sizeof x / sizeof *x) )
26 |
27 | static struct S_LL
28 | {
29 | struct savemsg *phead;
30 | struct savemsg *ptail;
31 | int nb_items;
32 | int cur_msg_id; // current identifier
33 | int max_items;
34 | HANDLE msglock;
35 | }
36 | tLL [10];
37 | static int nbLL=0;
38 |
39 |
40 |
41 | // ---------------------------------------------------------------
42 | // linked list management
43 | // ---------------------------------------------------------------
44 |
45 | // Create a new LL structure (should be also protected by a semaphore...)
46 | int LL_Create (int id, int max_msg)
47 | {
48 | if (id >= SizeOfTab (tLL)-1) return -1;
49 | tLL[id].phead = tLL[nbLL].ptail = NULL;
50 | tLL[id].nb_items = 0;
51 | tLL[id].cur_msg_id = 1;
52 | tLL[id].max_items = max_msg;
53 | tLL[id].msglock = CreateMutex(NULL, 0, NULL);
54 | return id;
55 | } // LL_Create
56 |
57 | void LL_Destroy (int id)
58 | {
59 | CloseHandle (tLL[id].msglock);
60 | } // LL_Destroy
61 |
62 | // AddItem
63 | int LL_PushTypedMsg (int id, const void *lpData, int dwSize, int type)
64 | {
65 | struct savemsg* pmsg ;
66 | int msg_id;
67 | int Rc;
68 | int Try = 0, bSuccess=FALSE;
69 | #define MAX_TRIES 5
70 |
71 |
72 | while (! bSuccess && ++Try < MAX_TRIES)
73 | {
74 | Rc = WaitForSingleObject(tLL[id].msglock, INFINITE);
75 | assert (Rc==WAIT_OBJECT_0);
76 |
77 | // queue full ?
78 | if (tLL[id].nb_items < tLL[id].max_items - 1)
79 | {
80 | // one more item
81 | ++tLL[id].nb_items;
82 |
83 | pmsg = malloc(sizeof(struct savemsg));
84 | assert(pmsg != NULL);
85 |
86 | pmsg->data = malloc(dwSize);
87 | pmsg->size = dwSize;
88 | pmsg->next = NULL;
89 | memcpy(pmsg->data, lpData, dwSize);
90 | pmsg->type = type;
91 | // attribute unique id to the msg
92 | pmsg->msg_id = msg_id = tLL[id].cur_msg_id++;
93 |
94 |
95 | // Assumes you have the lock
96 | if (!tLL[id].phead)
97 | tLL[id].phead = tLL[id].ptail = pmsg;
98 | else
99 | {
100 | if (!tLL[id].ptail) //Shouldn't be hit, but just in case
101 | {
102 | struct savemsg* ptmp = tLL[id].phead;
103 | while (ptmp)
104 | {
105 | tLL[id].ptail = ptmp;
106 | ptmp = ptmp->next;
107 | }
108 | }
109 |
110 | tLL[id].ptail->next = pmsg;
111 | tLL[id].ptail = pmsg;
112 | }
113 | bSuccess = TRUE;
114 | } // queue is not full
115 | else
116 | {
117 | ReleaseMutex(tLL[id].msglock);
118 | OutputDebugString("--------- Log queue full\n");
119 | Sleep(50);
120 | }
121 | } // 5 tries
122 |
123 | ReleaseMutex(tLL[id].msglock);
124 |
125 | // can not return directly pmsg->msg_id
126 | // since it may have already been freed
127 | return msg_id;
128 | } // LL_PushTypedMsg
129 |
130 |
131 | // Returns when the message queue is empty. Useful for loading the ini file after a save
132 | void WaitForMsgQueueToFinish (int id)
133 | {
134 | struct savemsg* pmsg = tLL[id].phead;
135 | int Rc;
136 | while (pmsg != NULL)
137 | {
138 | Sleep(0); // Pass the hand to other threads for the queue to empty
139 | Rc = WaitForSingleObject(tLL[id].msglock, INFINITE);
140 | assert (Rc==WAIT_OBJECT_0);
141 | pmsg = tLL[id].phead;
142 | ReleaseMutex (tLL[id].msglock);
143 | } ;
144 | } // WaitForMsgQueueToFinish()
145 |
146 |
147 | //Assumes you have the lock
148 | //Returns NULL if no message available
149 | void *LL_PopTypedMsg (int id, int *plen, int *pmsg_id, int *ptype)
150 | {
151 | struct savemsg *pcur;
152 | void *lpData;
153 | int Rc;
154 |
155 | if (tLL[id].phead==NULL) return NULL;
156 |
157 | Rc = WaitForSingleObject(tLL[id].msglock, INFINITE);
158 | assert (Rc==WAIT_OBJECT_0);
159 |
160 | pcur = tLL[id].phead;
161 | if(tLL[id].phead)
162 | {
163 | if(tLL[id].ptail == tLL[id].phead)
164 | tLL[id].ptail = NULL; //We'll be removing the head
165 | tLL[id].phead = tLL[id].phead->next;
166 | }
167 | tLL[id].nb_items--;
168 |
169 | ReleaseMutex (tLL[id].msglock);
170 |
171 | // return only user data, forget container
172 | lpData = pcur->data;
173 | if (pmsg_id != NULL) *pmsg_id = pcur->msg_id ;
174 | if (ptype != NULL) *ptype = pcur->type;
175 | if (plen != NULL) *plen = pcur->size;
176 | free (pcur);
177 |
178 | return lpData;
179 | } // LL_PopTypedMsg
180 |
181 | //Assumes you have the lock
182 | //Returns NULL if no message available
183 | void *LL_PopMsg (int id)
184 | {
185 | return LL_PopTypedMsg (id, NULL, NULL, NULL);
186 | } // LL_PopMsg
187 |
188 |
189 | int LL_PushMsg (int id, const void *data, int dwSize)
190 | {
191 | return LL_PushTypedMsg (id, data, dwSize, 0);
192 | } // LL_PushMsg
193 |
--------------------------------------------------------------------------------
/src/_services/ip_util.c:
--------------------------------------------------------------------------------
1 | //////////////////////////////////////////////////////
2 | //
3 | // Projet TFTPD32. December 2006 Ph.jounin
4 | // Projet DHCPD32. December 2006 Ph.jounin
5 | // File bootp.c: Bootp/DHCP utilities
6 | //
7 | // source released under European Union Public License
8 | //
9 | //////////////////////////////////////////////////////
10 |
11 | #include
12 | #include
13 | #include
14 | #include
15 | #include "bootpd_util.h"
16 |
17 | #ifndef MSVC
18 | # define sscanf_s sscanf
19 | #endif
20 |
21 |
22 |
23 | //quick smart increment function to avoid addresses ending in 0 or 255.
24 | //in is in network order, but what is returned is in host order
25 | unsigned long AddrInc(struct in_addr in)
26 | {
27 | unsigned long addr = ntohl(in.s_addr);
28 | if((addr & 0xff) == 254)
29 | return addr + 3; //Skip 0 and 1
30 | if((addr & 0xff) == 255)
31 | return addr + 2; //At least skip 0...
32 | return addr + 1;
33 | } // AddrInc
34 |
35 |
36 | //Returns true if the address would fit in the pool
37 | int AddrFitsPool(struct in_addr* addr)
38 | {
39 | return ntohl(addr->s_addr) >= ntohl (inet_addr(sParamDHCP.szAddr))
40 | && ntohl (addr->s_addr) < ntohl (inet_addr(sParamDHCP.szAddr)) + sParamDHCP.nPoolSize;
41 | }
42 |
43 | // Return TRUE if 2 IP addresses are in the same subnet
44 | BOOL bIPSameSubnet (struct in_addr *p1, struct in_addr *p2, struct in_addr *pMask)
45 | { return (p1->s_addr & pMask->s_addr) == (p2->s_addr & pMask->s_addr); } // bIPSameSubnet
46 |
47 | // Return TRUE if given address belongs to current host
48 | BOOL IsThisOurAddress (struct in_addr *pHost)
49 | {
50 | int Ark;
51 | char szName [256];
52 | struct hostent *pHostEntry;
53 |
54 | // search for an address which fit the pool
55 | if ( gethostname (szName, sizeof szName)!=SOCKET_ERROR
56 | && (pHostEntry=gethostbyname (szName)) !=0
57 | && pHostEntry->h_addr_list!=NULL
58 | )
59 | {
60 | for (Ark=0 ; pHostEntry->h_addr_list[Ark]!=NULL ; Ark++ )
61 | if (* (DWORD *) pHostEntry->h_addr_list[Ark] == pHost->s_addr)
62 | return TRUE;
63 | }
64 | return FALSE ;
65 | } // IsThisOurAddress
66 |
67 | /////
68 | // scan the addresses of the server, returns the first which has the same subnet than the host
69 | // if bExact is FALSE and the search was not successful, the first address is returned
70 | struct in_addr *FindNearestServerAddress (struct in_addr *pHost, struct in_addr *pMask, BOOL bExact)
71 | {
72 | int Ark=0;
73 | char szName [256];
74 | struct hostent *pHostEntry=NULL;
75 | static DWORD dwLoopback = 0x7F000001; // loopback
76 | char *pLoopback = (char *) &dwLoopback;
77 |
78 | // search for an address which fit the pool
79 | if ( gethostname (szName, sizeof szName)!=SOCKET_ERROR
80 | && (pHostEntry=gethostbyname (szName)) !=0
81 | && pHostEntry->h_addr_list!=NULL
82 | )
83 | {
84 | for (Ark=0 ;
85 | pHostEntry->h_addr_list[Ark]!=NULL
86 | && ! bIPSameSubnet ((struct in_addr *)pHostEntry->h_addr_list[Ark], pHost, pMask);
87 | Ark++) ;
88 | if (pHostEntry->h_addr_list[Ark]!=NULL)
89 | return (struct in_addr *) pHostEntry->h_addr_list[Ark];
90 | }
91 | return (struct in_addr *) ( bExact ? NULL : (Ark>0 ? pHostEntry->h_addr_list[0] : pLoopback) );
92 | } //FindNearestServerAddress
93 |
94 |
95 |
96 | #define MAXHADDRLEN 16
97 | char * haddrtoa(const unsigned char *haddr, int hlen, char cSep)
98 | {
99 | static char haddrbuf[3 * MAXHADDRLEN + 1];
100 | char *bufptr;
101 |
102 | if (hlen > MAXHADDRLEN)
103 | hlen = MAXHADDRLEN;
104 |
105 | bufptr = haddrbuf;
106 | while (hlen > 0) {
107 | wsprintf(bufptr, "%02X%c", (unsigned) (*haddr++ & 0xFF), cSep);
108 | bufptr += 3;
109 | hlen--;
110 | }
111 | bufptr[-1] = 0;
112 | return (haddrbuf);
113 | } // haddrtoa
114 |
115 | //Converts an ASCII string to a macaddr, assuming it was formed with haddrtoa
116 | void atohaddr(const unsigned char *addrstr, unsigned char* haddr, int haddrlen)
117 | {
118 | if(haddrlen == 6)
119 | {
120 | int b0, b1, b2, b3, b4, b5;
121 | b0=b1=b2=b3=b4=b5=0;
122 | sscanf_s (addrstr, "%x:%x:%x:%x:%x:%x", &b0, &b1, &b2, &b3, &b4, &b5);
123 | haddr[0] = (unsigned char) b0;
124 | haddr[1] = (unsigned char) b1;
125 | haddr[2] = (unsigned char) b2;
126 | haddr[3] = (unsigned char) b3;
127 | haddr[4] = (unsigned char) b4;
128 | haddr[5] = (unsigned char) b5;
129 | }
130 | }
131 |
132 | //Converts a time value to the "standard" date/time string -- works like haddrtoa
133 | #define MAXTIMESTR 20 //"mm/dd/yyyy/00:00:00"/0
134 | char* timetoa(time_t t)
135 | {
136 | static char timebuf[MAXTIMESTR];
137 | struct tm *tt = localtime(&t);
138 | if (tt==NULL) timebuf[0]=0;
139 | else sprintf(timebuf, "%02d/%02d/%04d/%02d:%02d:%02d",
140 | tt->tm_mon + 1, tt->tm_mday, tt->tm_year + 1900,
141 | tt->tm_hour, tt->tm_min, tt->tm_sec);
142 | return timebuf;
143 | }
144 |
145 | //Converts our "standard" date/time string to a time_t
146 | time_t atotime(char* str)
147 | {
148 | struct tm t;
149 | memset(&t, 0, sizeof(t));
150 | t.tm_isdst = -1; //For daylight savings calculation
151 | #ifdef MSVC
152 | sscanf_s (str, "%d/%d/%d/%d:%d:%d", &t.tm_mon, &t.tm_mday, &t.tm_year, &t.tm_hour, &t.tm_min, &t.tm_sec);
153 | #else
154 | sscanf(str, "%d/%d/%d/%d:%d:%d", &t.tm_mon, &t.tm_mday, &t.tm_year, &t.tm_hour, &t.tm_min, &t.tm_sec);
155 | #endif
156 | t.tm_mon -= 1;
157 | t.tm_year -= 1900;
158 | return mktime(&t);
159 | }
160 |
161 |
162 |
--------------------------------------------------------------------------------
/src/_services/ip_thread.c:
--------------------------------------------------------------------------------
1 | //////////////////////////////////////////////////////
2 | //
3 | // Projet TFTPD32. April 2007 Ph.jounin
4 | // A free TFTP server for Windows
5 | // File ip_thread.c: periodically checks server interfaces status
6 | //
7 | //
8 | // source released under European Union Public License
9 | //
10 | //////////////////////////////////////////////////////
11 |
12 | #include "headers.h"
13 | #include "threading.h"
14 |
15 | static struct S_IPAddressList old_if;
16 |
17 | // called by console thread
18 | int AnswerIPList (void)
19 | {
20 | // change old_if structure ie : force a refresh
21 | memset (& old_if, 0, sizeof old_if);
22 | // wake up scheduler thread
23 | WakeUpThread (TH_SCHEDULER);
24 | return 0;
25 | } //
26 |
27 | // -----------------------
28 | // Get all interfaces. This function is restricted to IPv4 in order to run under XP
29 | // -----------------------
30 | int PoolNetworkInterfaces (void)
31 | {
32 | ULONG outBufLen;
33 | IP_ADAPTER_ADDRESSES *pAddresses=NULL, *pCurrAddresses;
34 | IP_ADAPTER_UNICAST_ADDRESS *pUnicast;
35 | int Rc;
36 | struct S_IPAddressList new_if;
37 |
38 | memset (& new_if, 0, sizeof new_if);
39 |
40 | outBufLen = sizeof (IP_ADAPTER_ADDRESSES);
41 | pAddresses = (IP_ADAPTER_ADDRESSES *) malloc (outBufLen);
42 |
43 | // Make an initial call to GetAdaptersAddresses to get the
44 | // size needed into the outBufLen variable
45 | if (GetAdaptersAddresses (sSettings.bIPv6 ? AF_UNSPEC : AF_INET,
46 | GAA_FLAG_INCLUDE_PREFIX,
47 | NULL,
48 | pAddresses,
49 | & outBufLen) == ERROR_BUFFER_OVERFLOW)
50 | {
51 | free(pAddresses);
52 | pAddresses = (IP_ADAPTER_ADDRESSES *) malloc (outBufLen);
53 | }
54 |
55 | if (pAddresses == NULL) {
56 | return FALSE;
57 | }
58 | // Make a second call to GetAdapters Addresses to get the
59 | // actual data we want
60 | Rc = GetAdaptersAddresses (sSettings.bIPv6 ? AF_UNSPEC : AF_INET,
61 | GAA_FLAG_INCLUDE_PREFIX | GAA_FLAG_SKIP_MULTICAST,
62 | NULL,
63 | pAddresses,
64 | & outBufLen);
65 | if (Rc == NO_ERROR)
66 | {
67 | for ( pCurrAddresses = pAddresses, new_if.nb_itf = 0, new_if.nb_addr = 0 ;
68 | pCurrAddresses && new_if.nb_itf < MAX_ITF ;
69 | pCurrAddresses=pCurrAddresses->Next, new_if.nb_itf++ )
70 | {
71 | // can not use lstrcpy since Description is unicode
72 | // may give strange results in Japan/China/..
73 | wsprintf (new_if.itf[new_if.nb_itf].sz, "%ls", pCurrAddresses->Description);
74 | new_if.itf[new_if.nb_itf].status = pCurrAddresses->OperStatus;
75 |
76 | for ( pUnicast = pCurrAddresses->FirstUnicastAddress;
77 | pUnicast != NULL && new_if.nb_addrNext )
79 | {
80 | // convert into string (do not use InetNtoP which is not supported under XP)
81 | Rc = getnameinfo (pUnicast->Address.lpSockaddr,
82 | pUnicast->Length,
83 | new_if.addr[new_if.nb_addr].sz, MAXLEN_IPv6,
84 | NULL, 0, NI_NUMERICHOST);
85 | if (Rc==0) // success : link address with name of interface & increment addr number
86 | new_if.addr[new_if.nb_addr++].idx = new_if.nb_itf;
87 | } // for each address
88 | } // for each interface
89 | } // GetAdaptersAddresses successful
90 | else
91 | {
92 | free (pAddresses);
93 | Rc = WSAGetLastError ();
94 | return FALSE;
95 | }
96 |
97 | // signal a change on request or if interface list has changed
98 | if (memcmp (&new_if, &old_if, sizeof old_if)!=0)
99 | {
100 | old_if = new_if ;
101 | SendMsgRequest ( C_REPLY_GET_INTERFACES,
102 | & old_if,
103 | sizeof old_if,
104 | FALSE,
105 | FALSE );
106 | }
107 | free (pAddresses);
108 | return TRUE;
109 | } // PoolNetworkInterfaces
110 |
111 |
112 | // -----------------------
113 | // Retrieve IPv4 assigned to an interface
114 | // -----------------------
115 | int GetIPv4Address (const char *szIf, char *szIP)
116 | {
117 | ULONG outBufLen;
118 | IP_ADAPTER_ADDRESSES *pAddresses=NULL, *pCurrAddresses;
119 | IP_ADAPTER_UNICAST_ADDRESS *pUnicast;
120 | int Rc;
121 | char szBuf [MAX_ADAPTER_DESCRIPTION_LENGTH+4];
122 |
123 | szIP[0]=0;
124 | outBufLen = sizeof (IP_ADAPTER_ADDRESSES);
125 | pAddresses = (IP_ADAPTER_ADDRESSES *) malloc (outBufLen);
126 |
127 | // Make an initial call to GetAdaptersAddresses to get the
128 | // size needed into the outBufLen variable
129 | if (GetAdaptersAddresses (AF_INET,
130 | GAA_FLAG_INCLUDE_PREFIX,
131 | NULL,
132 | pAddresses,
133 | & outBufLen) == ERROR_BUFFER_OVERFLOW)
134 | {
135 | free(pAddresses);
136 | pAddresses = (IP_ADAPTER_ADDRESSES *) malloc (outBufLen);
137 | }
138 |
139 | if (pAddresses == NULL) {
140 | return -1;
141 | }
142 | // Make a second call to GetAdapters Addresses to get the
143 | // actual data we want
144 | Rc = GetAdaptersAddresses (sSettings.bIPv6 ? AF_UNSPEC : AF_INET,
145 | GAA_FLAG_INCLUDE_PREFIX,
146 | NULL,
147 | pAddresses,
148 | & outBufLen);
149 | if (Rc == NO_ERROR)
150 | {
151 | for ( pCurrAddresses = pAddresses ; pCurrAddresses ; pCurrAddresses=pCurrAddresses->Next )
152 | {
153 | wsprintf (szBuf, "%ls", pCurrAddresses->Description);
154 | if (
155 | lstrcmp (szBuf, sSettings.szTftpLocalIP) == 0
156 | && pCurrAddresses->FirstUnicastAddress !=0
157 | )
158 | {SOCKADDR *sAddr = pCurrAddresses->FirstUnicastAddress->Address.lpSockaddr;
159 | lstrcpy ( szIP,
160 | inet_ntoa ( ((struct sockaddr_in *) sAddr)->sin_addr ) );
161 | free (pAddresses);
162 | return 0;
163 | }
164 | }
165 | }
166 | free (pAddresses);
167 | return -1;
168 | } // GetIPv4Address
169 |
170 |
171 |
172 |
--------------------------------------------------------------------------------