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