Changed port back to 23
[reactos.git] / rosapps / applications / sysutils / telnetd / telnetd.h
1 #ifndef __TELNETD_H
2 #define __TELNETD_H
3
4 #define _CRT_SECURE_NO_WARNINGS
5
6 #define WIN32_NO_STATUS
7 #include <stdio.h>
8 #include <winsock2.h>
9 #include <tchar.h>
10 #include <time.h>
11
12 /*
13 ** macro definitions
14 */
15 #define TELNET_PORT (23)
16
17 #define BUFSIZE (4096)
18 #define USERID_SIZE (64)
19 #define CTRLC (3)
20 #define BS (8)
21 #define CR (13)
22 #define LF (10)
23 #define DEL (127)
24
25 #define IAC "\xff"
26 #define DONT "\xfe"
27 #define WONT "\xfc"
28 #define WILL "\xfb"
29 #define DO "\xfd"
30 #define SB "\xfa"
31 #define SE "\xf0"
32 #define ECHO "\x01"
33 #define SUPPRESS_GO_AHEAD "\x03"
34 #define TERMINAL_TYPE "\x18"
35 #define NAWS "\x1f"
36 #define LINEMODE "\x22"
37 #define NEWENVIRON "\x27"
38 #define MODE "\x01"
39
40 #define HANDSHAKE_TIMEOUT (3)
41
42 /*
43 ** types
44 */
45
46 typedef struct client_s
47 {
48 char userID[USERID_SIZE];
49 int socket;
50 BOOLEAN bTerminate;
51 BOOLEAN bReadFromPipe;
52 BOOLEAN bWriteToPipe;
53 HANDLE hProcess;
54 DWORD dwProcessId;
55 HANDLE hChildStdinWr;
56 HANDLE hChildStdoutRd;
57 } client_t;
58
59 typedef enum
60 {
61 NoEcho = 0,
62 Echo = 1,
63 Password = 2
64 } EchoMode;
65
66 /*
67 ** Forward function declarations
68 */
69 static BOOL WINAPI Cleanup(DWORD dwControlType);
70 static void WaitForConnect(void);
71 static BOOLEAN StartSocketInterface(void);
72 static void CreateSocket(void);
73 static void UserLogin(int client_socket);
74 static DWORD WINAPI UserLoginThread(LPVOID);
75 static int DoTelnetHandshake(int sock);
76 static int ReceiveLine(int sock, char *buffer, int len, EchoMode echo);
77 static void RunShell(client_t *client);
78 //static BOOL CreateChildProcess(const char *);
79 static DWORD WINAPI MonitorChildThread(LPVOID);
80 static DWORD WINAPI WriteToPipeThread(LPVOID);
81 static DWORD WINAPI ReadFromPipeThread(LPVOID);
82 static void TerminateShell(client_t *client);
83 static VOID ErrorExit(LPTSTR);
84 int kickoff_telnetd(void);
85
86 #endif /* __TELNETD_H */
87