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