-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsync.c
More file actions
320 lines (287 loc) · 8.1 KB
/
sync.c
File metadata and controls
320 lines (287 loc) · 8.1 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
317
318
319
320
/******************************************************************************
* COPYRIGHT ? 2011 EMC CORPORATION *
* ---ALL RIGHTS RESERVED--- *
* *
* THIS SOFTWARE IS PROPRIETARY AND CONFIDENTIAL TO EMC CORPORATION , IS *
* FURNISHED UNDER A LICENSE AND MAY BE USED AND COPIED ONLY IN ACCORDANCE THE *
* TERMS OF SUCH LICENSE AND WITH THE INCLUSION OF THE ABOVE COPYRIGHT NOTICE. *
* THIS SOFTWARE OR ANY OTHER COPIES THEREOF MAY NOT BE PROVIDED OR OTHERWISE *
* MADE AVAILABLE TO ANY OTHER PERSON. NO TITLE TO AND OWNERSHIP OF THE *
* SOFTWARE IS HEREBY TRANSFERRED. *
* *
* THE INFORMATION IN THIS SOFTWARE IS SUBJECT TO CHANGE WITHOUT NOTICE AND *
* SHOULD NOT BE CONSTRUED AS A COMMITMENT BY EMC CORPORATION. *
******************************************************************************/
// sd_auth.c : Defines the entry point for the console application.
//
#ifdef WIN32
#include <windows.h>
#define sleep(x) Sleep(x*1000)
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifndef WIN32
#include <termio.h>
#include <fcntl.h>
#endif
// in NT this allows using the aceclnt.lib file for linking
#define USE_ACE_AGENT_API_PROTOTYPES
#include "acexport.h"
#ifndef WIN32
int sd_echo_off(void);
int sd_echo_on(void);
#endif
// safe prompt function
static int promptUser( const char *prompt, char * buf, const int bufsize )
{
int i;
// flush pre-typing if terminal I/O
//fflush(stdin);
// tel the user what to do
printf(prompt);
// get the response
if (0 == fgets(buf, bufsize, stdin))
return 0;
// remove line ender, two for NT
i = strlen(buf);
if (buf[i] < ' ')
buf[i--] = 0;
if (buf[i] < ' ')
buf[i--] = 0;
return 1;
}
///////////////////////////////////////////////////////////////////////////////
// this function is a demonstration of the use of the new synchronous API
// defined by the calls AceStartAuth(), AceContinueAuth(), and AceCloseAuth().
// Please notice the use of the AceGetAuthenticationStatus() call before the
// AceCloseAuth() call to determine the final authentication result.
//
SD_BOOL authenticate(char *username,char* passcode)
{
SDI_HANDLE aceHdl;
SD_CHAR resp[128];
SD_CHAR prompt[512];
SD_I32 promptLen;
SD_I32 nextRespLen;
SD_I32 respTimeout;
SD_BOOL moreFlag;
SD_BOOL noechoFlag;
SD_I32 AuthStatus;
#ifdef WIN32
HANDLE hStdIn;
DWORD OrigConsoleMode, ConsoleMode;
#endif
SD_BOOL retVal;
#ifdef WIN32
// get the handle to stdin and the console mode
hStdIn = GetStdHandle(STD_INPUT_HANDLE);
GetConsoleMode(hStdIn, &OrigConsoleMode);
// enable input echo
ConsoleMode = OrigConsoleMode|ENABLE_ECHO_INPUT|ENABLE_LINE_INPUT;
#endif
if (!AceInitialize())
{
printf("\nAceInitialize failed\n");
return SD_FALSE;
}
//if (0 == promptUser("Enter USERNAME: ", resp, sizeof(resp)) )
// {
// return SD_FALSE;
//}
strcpy(resp,username);
// reset size of prompt string
promptLen = sizeof(prompt);
//retVal = AceStartAuth(&aceHdl, resp, strlen(resp),
// &moreFlag, &noechoFlag, &respTimeout, &nextRespLen,
// prompt, &promptLen);
// printf("username=%s\n",resp);
SDI_HANDLE SdiHandle;
if(SD_Init(&SdiHandle)!=ACM_OK)
{
printf("sd_init fail\n");
exit(-1);
}
retVal=SD_Check(SdiHandle,passcode,resp);
return retVal;
// printf("passcode=%s\n",passcode);
// if (retVal == ACM_OK)
///{
// printf("%s", prompt);
// return failure
// return SD_FALSE;
//}
// else
// return 1;
/* moreFlag=0;
// loop until no more data is requested
while (moreFlag)
{
#ifdef WIN32
// if echo is on make sure it is turned on
if (noechoFlag)
SetConsoleMode(hStdIn, ConsoleMode & ~ENABLE_ECHO_INPUT);
else
SetConsoleMode(hStdIn, ConsoleMode);
#else
if (noechoFlag)
sd_echo_off();
else
sd_echo_on();
#endif
// a system PIN is about to be displayed
if (respTimeout == 10)
{
printf("%s", prompt);
// wait for 10 seconds
sleep(10);
// clear the screen
printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
// make sure display is cleared
fflush(stdout);
// clear keystrokes from impatient users
fflush(stdin);
}
else
{
if (0 == promptUser(prompt, resp, sizeof(resp)) )
{
// must also cause access denied
break;
}
#ifdef WIN32
// if echo is off make linefeeds
if (noechoFlag)
puts("");
#else
if (noechoFlag)
sd_echo_on();
printf("\n");
#endif
}
// reset size of prompt string
promptLen = sizeof(prompt);
retVal = AceContinueAuth(aceHdl, resp, strlen(resp),
&moreFlag, &noechoFlag, &respTimeout, &nextRespLen,
prompt, &promptLen);
}
#ifndef WIN32
sd_echo_on();
#endif
// write final prompt to output
printf("%s", prompt);
// we need to call AceGetAuthenticationStatus() to retrieve
// the final result. the return code from AceContinueAuth()
// indicates the success/failure of the call and not of the
// authentication request.
AuthStatus = ACM_ACCESS_DENIED;
if (moreFlag) // the loop was broken by I/O error?
{
puts("\n\nAccess denied.");
}
else
{
retVal = AceGetAuthenticationStatus(aceHdl, &AuthStatus);
}
// close authentication context
AceCloseAuth(aceHdl);
#ifdef WIN32
// reset console and close handle
SetConsoleMode(hStdIn, OrigConsoleMode);
CloseHandle(hStdIn);
#endif
// return true if status is ACM_OK
return AuthStatus == ACM_OK;
*/
}
#ifndef WIN32
int sd_echo_off()
{
struct termio sd_echo_sav;
if (ioctl (0, TCGETA, &sd_echo_sav) == -1)
{
printf("can't get orginal settings");
return(1);
}
sd_echo_sav.c_lflag &= ~ECHO;
if (ioctl(0, TCSETA, &sd_echo_sav) == -1)
{
printf("can't initiate new settings");
return(2);
}
}
int sd_echo_on()
{
struct termio sd_echo_sav;
if (ioctl (0, TCGETA, &sd_echo_sav) == -1)
{
printf("can't get orginal settings");
return(1);
}
sd_echo_sav.c_lflag |= ECHO;
if (ioctl(0, TCSETA, &sd_echo_sav) == -1)
{
printf("can't initiate new settings");
return(3);
}
}
#endif
// a simple main() to drive this program
int main(int argc, char* argv[])
{
if(argc!=3)
{
printf("input:%s username passcode\n",argv[0]);
exit(-1);
}
SD_BOOL retVal=authenticate(argv[1],argv[2]);
//if ()
//{
// // successful auth. let them do what they want
// printf("1");
// return 1;
//}
//// authentication failed
//printf("0");
//return 0;
if(retVal==ACM_OK)
{
printf("1");
return 1;
}
else if(retVal==ACE_ERR_INVALID_HANDLE)
{
printf("-1");
return -1;
}
else if(retVal==ACM_ACCESS_DENIED)
{
printf("-2");
return -2;
}
else if(retVal==ACM_NEXT_CODE_REQUIRED)
{
printf("-3");
return -3;
}
else if(retVal==ACM_NEW_PIN_REQUIRED)
{
printf("-4");
return -4;
}
else if(retVal==ACE_TOO_MANY_CALLERS)
{
printf("-5");
return -5;
}
else if(retVal==ACE_INVALID_ARG)
{
printf("-6");
return -6;
}
else
{
printf("0");
return 0;
}
}