-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMorKeeper.cpp
More file actions
317 lines (276 loc) · 8.77 KB
/
MorKeeper.cpp
File metadata and controls
317 lines (276 loc) · 8.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
// MorKeeper.cpp
//
#include "stdafx.h"
#include "Ras.h"
#include <string>
#include "CXKUsername.h"
#include <sstream>
//
// This is a part of the Microsoft Source Code Samples.
// Copyright 1993 - 2000 Microsoft Corporation.
// All rights reserved.
// This source code is only intended as a supplement to
// Microsoft Development Tools and/or Help documentation.
// See these sources for detailed information regarding the
// Microsoft samples programs.
//
//
// RasDialAsync.c
//
// Usage:
// RasDialAsync
//
// RAS API's used:
// RasDial
// RasHangUp
//
// Callback function:
// RasDialFunc
//
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x500
#endif
#ifdef UNICODE
#undef UNICODE
#endif
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#include <stdio.h>
#include <windows.h>
#include <ras.h>
#include <raserror.h>
#include <string.h>
#include <winbase.h>
#include <time.h>
#include <stdlib.h>
#include <tchar.h>
#include <strsafe.h>
// Macro for counting maximum characters that will fit into a buffer
#define CELEMS(x) ((sizeof(x))/(sizeof(x[0])))
void WINAPI RasDialFunc(UINT unMsg,
RASCONNSTATE rasconnstate,
DWORD dwError);
HANDLE gEvent_handle; // Global event handle
// Usage
// Begin main()...
int __cdecl main(int argc, char*argv[])
{
LPRASDIALPARAMS lpRasDialParams = NULL; // Structure to store the RasDial parameters
HRASCONN hRasConn = NULL; // Handle to RAS connection
DWORD nRet = 0; // Return value from a function
DWORD dwMaxTickCount = 0; // Final Tick Count value
int i = 0;
int j = 0;
BOOL fRequired = FALSE;
char szTempBuf[256] = { 0 };
// Create the event, which indicates completion of RasDial()
gEvent_handle = CreateEvent(NULL, FALSE, FALSE, NULL);
if (!gEvent_handle)
{
nRet = GetLastError();
printf("CreateEvent failed: Error = %d", nRet);
return nRet;
}
// Initialize the RASDIALPARAMS structure
lpRasDialParams = (LPRASDIALPARAMS)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(RASDIALPARAMS));
std::string knownUsername = "xxxxxx@cqupt";
std::string knownPassword = "xxxxxx";
char *connName = "CQUPT";
CXKUsername XKUser(knownUsername);
CString prefix = "\0d\0a";
CString realUsername = prefix + XKUser.GetConnUsername();
CString realPassword = knownPassword;
lpRasDialParams->dwSize = sizeof(RASDIALPARAMS);
StringCchCopy(lpRasDialParams->szEntryName, CELEMS(lpRasDialParams->szEntryName), "CQUPT");
StringCchCopy(lpRasDialParams->szUserName, CELEMS(lpRasDialParams->szUserName), realUsername.c_str());
StringCchCopy(lpRasDialParams->szPassword, CELEMS(lpRasDialParams->szPassword), realPassword.c_str());
// Dial out asynchronously using RasDial()
ZeroMemory((LPVOID)szTempBuf, sizeof(szTempBuf));
StringCchPrintf(szTempBuf, CELEMS(szTempBuf) - 1, "Dialing... %s\n", lpRasDialParams->szPhoneNumber);
printf(szTempBuf);
hRasConn = NULL;
nRet = RasDial(NULL, NULL, lpRasDialParams, 0, NULL, &hRasConn);
//nRet = RasDial(NULL, NULL, lpRasDialParams, 0, &RasDialFunc, &hRasConn);
// Check whether RasDial() succeeded
if (nRet)
{
printf("RasDial failed: Error = %d\n", nRet);
goto done;
}
//// Wait for the RasDial() to complete, signaled by the SetEvent()
//nRet = WaitForSingleObject(gEvent_handle, 10000);
//switch (nRet)
//{
//case WAIT_OBJECT_0:
// // Normal completion or Ras Error encountered
// printf("Done!\n");
// //printf("Will exit in 5 seconds...\n");
// break;
//case WAIT_TIMEOUT: // RasDial timed out
// printf("RasDial Timed out...\n");
// break;
//default:
// printf("WaitForSingleObject returned %d\n", nRet);
// break;
//}
done:
CloseHandle(gEvent_handle);
if (lpRasDialParams)
{
// Clear password from memory
ZeroMemory(lpRasDialParams->szPassword, sizeof(lpRasDialParams->szPassword));
HeapFree(GetProcessHeap(), 0, (LPVOID)lpRasDialParams);
}
return (int)nRet;
}
// Callback function RasDialFunc()
void WINAPI RasDialFunc(UINT unMsg,
RASCONNSTATE rasconnstate,
DWORD dwError)
{
char szRasString[256] = { 0 }; // Buffer for storing the error string
char szTempBuf[256] = { 0 }; // Buffer used for printing out the text
if (dwError) // Error occurred
{
RasGetErrorString((UINT)dwError, szRasString, CELEMS(szRasString));
ZeroMemory((LPVOID)szTempBuf, sizeof(szTempBuf));
StringCchPrintf(szTempBuf, CELEMS(szTempBuf), "Error: %d - %s\n", dwError, szRasString);
printf(szTempBuf);
SetEvent(gEvent_handle);
return;
}
// Map each of the states of RasDial() and display on the screen
// the next state that RasDial() is entering
switch (rasconnstate)
{
case RASCS_OpenPort:
printf("RASCS_OpenPort = %d\n", rasconnstate);
printf("Opening port...\n");
break;
case RASCS_PortOpened:
printf("RASCS_PortOpened = %d\n", rasconnstate);
printf("Port opened.\n");
break;
case RASCS_ConnectDevice:
printf("RASCS_ConnectDevice = %d\n", rasconnstate);
printf("Connecting device...\n");
break;
case RASCS_DeviceConnected:
printf("RASCS_DeviceConnected = %d\n", rasconnstate);
printf("Device connected.\n");
break;
case RASCS_AllDevicesConnected:
printf("RASCS_AllDevicesConnected = %d\n", rasconnstate);
printf("All devices connected.\n");
break;
case RASCS_Authenticate:
printf("RASCS_Authenticate = %d\n", rasconnstate);
printf("Authenticating...\n");
break;
case RASCS_AuthNotify:
printf("RASCS_AuthNotify = %d\n", rasconnstate);
printf("Authentication notify.\n");
break;
case RASCS_AuthRetry:
printf("RASCS_AuthRetry = %d\n", rasconnstate);
printf("Retrying authentication...\n");
break;
case RASCS_AuthCallback:
printf("RASCS_AuthCallback = %d\n", rasconnstate);
printf("Authentication callback...\n");
break;
case RASCS_AuthChangePassword:
printf("RASCS_AuthChangePassword = %d\n", rasconnstate);
printf("Change password...\n");
break;
case RASCS_AuthProject:
printf("RASCS_AuthProject = %d\n", rasconnstate);
printf("Projection phase started...\n");
break;
case RASCS_AuthLinkSpeed:
printf("RASCS_AuthLinkSpeed = %d\n", rasconnstate);
printf("Negoting speed...\n");
break;
case RASCS_AuthAck:
printf("RASCS_AuthAck = %d\n", rasconnstate);
printf("Authentication acknowledge...\n");
break;
case RASCS_ReAuthenticate:
printf("RASCS_ReAuthenticate = %d\n", rasconnstate);
printf("Retrying Authentication...\n");
break;
case RASCS_Authenticated:
printf("RASCS_Authenticated = %d\n", rasconnstate);
printf("Authentication complete.\n");
break;
case RASCS_PrepareForCallback:
printf("RASCS_PrepareForCallback = %d\n", rasconnstate);
printf("Preparing for callback...\n");
break;
case RASCS_WaitForModemReset:
printf("RASCS_WaitForModemReset = %d\n", rasconnstate);
printf("Waiting for modem reset...\n");
break;
case RASCS_WaitForCallback:
printf("RASCS_WaitForCallback = %d\n", rasconnstate);
printf("Waiting for callback...\n");
break;
case RASCS_Projected:
printf("RASCS_Projected = %d\n", rasconnstate);
printf("Projection completed.\n");
break;
#if (WINVER >= 0x400)
case RASCS_StartAuthentication: // Windows 95 only
printf("RASCS_StartAuthentication = %d\n", rasconnstate);
printf("Starting authentication...\n");
break;
case RASCS_CallbackComplete: // Windows 95 only
printf("RASCS_CallbackComplete = %d\n", rasconnstate);
printf("Callback complete.\n");
break;
case RASCS_LogonNetwork: // Windows 95 only
printf("RASCS_LogonNetwork = %d\n", rasconnstate);
printf("Login to the network.\n");
break;
#endif
case RASCS_SubEntryConnected:
printf("RASCS_SubEntryConnected = %d\n", rasconnstate);
printf("Subentry connected.\n");
break;
case RASCS_SubEntryDisconnected:
printf("RASCS_SubEntryDisconnected = %d\n", rasconnstate);
printf("Subentry disconnected.\n");
break;
//PAUSED STATES:
case RASCS_Interactive:
printf("RASCS_Interactive = %d\n", rasconnstate);
printf("In Paused state: Interactive mode.\n");
break;
case RASCS_RetryAuthentication:
printf("RASCS_RetryAuthentication = %d\n", rasconnstate);
printf("In Paused state: Retry Authentication...\n");
break;
case RASCS_CallbackSetByCaller:
printf("RASCS_CallbackSetByCaller = %d\n", rasconnstate);
printf("In Paused state: Callback set by Caller.\n");
break;
case RASCS_PasswordExpired:
printf("RASCS_PasswordExpired = %d\n", rasconnstate);
printf("In Paused state: Password has expired...\n");
break;
case RASCS_Connected: // = RASCS_DONE:
printf("RASCS_Connected = %d\n", rasconnstate);
printf("Connection completed.\n");
SetEvent(gEvent_handle);
break;
case RASCS_Disconnected:
printf("RASCS_Disconnected = %d\n", rasconnstate);
printf("Disconnecting...\n");
break;
default:
printf("Unknown Status = %d\n", rasconnstate);
printf("What are you going to do about it?\n");
break;
}
}