Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

4019 lines
103 KiB

  1. /*************************************************************************
  2. *
  3. * SCRIPT.C
  4. *
  5. * Script routines, ported from DOS
  6. *
  7. * Copyright (c) 1995 Microsoft Corporation
  8. *
  9. *************************************************************************/
  10. #include "common.h"
  11. #include <direct.h>
  12. #include <time.h>
  13. #include <ctype.h>
  14. #include <process.h>
  15. #include <signal.h>
  16. #include <errno.h>
  17. #include <fcntl.h>
  18. #include <io.h>
  19. #include <time.h>
  20. extern VOID nwShowLastLoginTime( VOID );
  21. #define MAXLEN 256
  22. #define MAX_NUM_IF 10
  23. #define NUMCOMMAND 45
  24. #define CM_IF 20
  25. #define CM_ELSE 21
  26. #define CM_ENDIF 22
  27. #define CM_END 23
  28. //
  29. // 3X and 4X variables
  30. //
  31. #define IDS_DAY_OF_WEEK 0
  32. #define IDS_DAY 1
  33. #define IDS_MONTH_NAME 2
  34. #define IDS_MONTH 3
  35. #define IDS_NDAY_OF_WEEK 4
  36. #define IDS_SHORT_YEAR 5
  37. #define IDS_YEAR 6
  38. #define IDS_AM_PM 7
  39. #define IDS_GREETING_TIME 8
  40. #define IDS_HOUR24 9
  41. #define IDS_HOUR 10
  42. #define IDS_MINUTE 11
  43. #define IDS_SECOND 12
  44. #define IDS_FULL_NAME 13
  45. #define IDS_LOGIN_NAME 14
  46. #define IDS_USER_ID 15
  47. #define IDS_PASSWORD_EXPIRES 16
  48. #define IDS_NETWORK_ADDRESS 17
  49. #define IDS_FILE_SERVER 18
  50. #define IDS_ACCESS_SERVER 19
  51. #define IDS_ERROR_LEVEL 20
  52. #define IDS_ERRORLEVEL 21
  53. #define IDS_MACHINE 22
  54. #define IDS_OS_VERSION 23
  55. #define IDS_OS 24
  56. #define IDS_SMACHINE 25
  57. #define IDS_SHELL_TYPE 26
  58. #define IDS_STATION 27
  59. #define IDS_P_STATION 28
  60. #define IDS_SHELL_VERSION 29
  61. #define NUMVAR_3X IDS_SHELL_VERSION + 1
  62. #define IDS_LAST_NAME 30
  63. #define IDS_LOGIN_CONTEXT 31
  64. #define IDS_NETWARE_REQUESTER 32
  65. #define IDS_REQUESTER_CONTEXT 33
  66. #define IDS_ACCOUNT_BALANCE 34
  67. #define IDS_CN 35
  68. #define IDS_REQUESTER_VERSION 36
  69. #define IDS_SURNAME 37
  70. #define IDS_DOS_REQUESTER 38
  71. #define IDS_REQUESTER 39
  72. #define IDS_ADMINISTRATIVE_ASSISTANT 40
  73. #define IDS_ALLOW_UNLIMITED_CREDIT 41
  74. #define IDS_DESCRIPTION 42
  75. #define IDS_EMAIL_ADDRESS 43
  76. #define IDS_EMPLOYEE_ID 44
  77. #define IDS_FACSIMILE_TELEPHONE_NUMBER 45
  78. #define IDS_GROUP_MEMBERSHIP 46
  79. #define IDS_HIGHER_PRIVILEGES 47
  80. #define IDS_HOME_DIRECTORY 48
  81. #define IDS_INITIALS 49
  82. #define IDS_LANGUAGE 50
  83. #define IDS_LOCKED_BY_INTRUDER 51
  84. #define IDS_LOGIN_DISABLED 52
  85. #define IDS_LOGIN_GRACE_LIMIT 53
  86. #define IDS_LOGIN_GRACE_REMAINING 54
  87. #define IDS_LOGIN_INTRUDER_ATTEMPTS 55
  88. #define IDS_LOGIN_MAXIMUM_SIMULTANEOUS 56
  89. #define IDS_MAILSTOP 57
  90. #define IDS_MESSAGE_SERVER 58
  91. #define IDS_MINIMUM_ACCOUNT_BALANCE 59
  92. #define IDS_NETWORK 60
  93. #define IDS_OBJECT_CLASS 61
  94. #define IDS_OU 62
  95. #define IDS_PASSWORD_ALLOW_CHANGE 63
  96. #define IDS_PASSWORD_MINIMUM_LENGTH 64
  97. #define IDS_PASSWORD_REQUIRED 65
  98. #define IDS_PASSWORD_UNIQUE_REQUIRED 66
  99. #define IDS_PASSWORDS_USED 67
  100. #define IDS_PHYSICAL_DELIVERY_OFFICE_NAME 68
  101. #define IDS_POSTAL_ADDRESS 69
  102. #define IDS_POSTAL_CODE 70
  103. #define IDS_POSTAL_OFFICE_BOX 71
  104. #define IDS_PRIVATE_KEY 72
  105. #define IDS_PROFILE 73
  106. #define IDS_REVISION 74
  107. #define IDS_SECURITY_EQUALS 75
  108. #define IDS_SECURITY_FLAGS 76
  109. #define IDS_SEE_ALSO 77
  110. #define IDS_SERVER_HOLDS 78
  111. #define IDS_SUPERVISOR 79
  112. #define IDS_TELEPHONE_NUMBER 80
  113. #define IDS_TITLE 81
  114. #define IDS_CERTIFICATE_VALIDITY_INTERVAL 82
  115. #define IDS_EQUIVALENT_TO_ME 83
  116. #define IDS_GENERATIONAL_QUALIFIER 84
  117. #define IDS_GIVEN_NAME 85
  118. #define IDS_MAILBOX_ID 86
  119. #define IDS_MAILBOX_LOCATION 87
  120. #define IDS_PROFILE_MEMBERSHIP 88
  121. #define IDS_SA 89
  122. #define IDS_S 90
  123. #define IDS_L 91
  124. #define IDS_ACCESS 92
  125. #define NUMVAR IDS_ACCESS + 1
  126. /*
  127. * String constants.
  128. */
  129. /*
  130. * Text for default Login Script. Don't change.
  131. */
  132. BYTE DefaultLoginScript[] =
  133. "WRITE \"Good %GREETING_TIME, %LOGIN_NAME.\\n\"\n"
  134. "MAP DISPLAY OFF\n"
  135. "MAP ERRORS OFF\n"
  136. "Rem: Set 1st drive to most appropriate directory.\n"
  137. "MAP *1:=%FILE_SERVER/SYS:;*1:=%FILE_SERVER/SYS:%LOGIN_NAME\n"
  138. "If LOGIN_NAME=\"SUPERVISOR\" || LOGIN_NAME=\"ADMIN\" || LOGIN_NAME=\"SUPERVIS\" THEN MAP *1:=%FILE_SERVER/SYS:SYSTEM\n"
  139. "Rem: Set search drives (S2 machine-OS dependent).\n"
  140. "MAP INS S1:=%FILE_SERVER/SYS:PUBLIC\n"
  141. "MAP INS S2:=%FILE_SERVER/SYS:\n"
  142. "Rem: Now display all the current drive settings.\n"
  143. "MAP DISPLAY ON\n"
  144. "MAP\n"
  145. "\0";
  146. char *__SPACES__=" \t";
  147. /*
  148. * Do not change the order of this array.
  149. */
  150. char * COMPARE_OPERATORS[] =
  151. {
  152. "!=",
  153. "<>",
  154. "NOT EQUAL TO",
  155. "DOES NOT EQUAL",
  156. "NOT EQUAL",
  157. "IS NOT EQUAL",
  158. "#",
  159. "IS NOT", // 7
  160. ">=", // 8
  161. "IS GREATER THAN OR EQUAL TO",
  162. "IS GREATER THAN OR EQUAL",
  163. "GREATER THAN OR EQUAL TO",
  164. "GREATER THAN OR EQUAL",
  165. ">", // 13
  166. "IS GREATER THAN",
  167. "GREATER THAN",
  168. "<=", // 16
  169. "IS LESS THAN OR EQUAL TO",
  170. "IS LESS THAN OR EQUAL",
  171. "LESS THAN OR EQUAL TO",
  172. "LESS THAN OR EQUAL",
  173. "<", // 21
  174. "IS LESS THAN",
  175. "LESS THAN",
  176. "==", // 24
  177. "=",
  178. "EQUALS",
  179. "EQUAL",
  180. "IS",
  181. "\0"
  182. };
  183. int IsNotEqual (int nIndex)
  184. {
  185. return(nIndex < 8);
  186. }
  187. int IsGreaterOrEqual (int nIndex)
  188. {
  189. return(nIndex >= 8 && nIndex < 13);
  190. }
  191. int IsGreater (int nIndex)
  192. {
  193. return(nIndex >= 13 && nIndex < 16);
  194. }
  195. int IsLessOrEqual (int nIndex)
  196. {
  197. return(nIndex >= 16 && nIndex < 21);
  198. }
  199. int IsLess (int nIndex)
  200. {
  201. return(nIndex >= 21 && nIndex < 24);
  202. }
  203. /*
  204. * Type defs.
  205. */
  206. typedef int (*PFCommandHandler) (char *lpParam);
  207. typedef struct tagCOMMANDTABLE
  208. {
  209. char *commandStr0;
  210. char *commandStr1;
  211. char *commandStr2;
  212. PFCommandHandler commandhandler;
  213. }COMMANDTABLE;
  214. typedef struct tagLABEL_LIST
  215. {
  216. char *pLabel;
  217. char *pNextLine;
  218. struct tagLABEL_LIST *pNext;
  219. }LABEL_LIST, *PLABEL_LIST;
  220. /*
  221. * Functions that are in command dispatch table.
  222. */
  223. int AttachHandler (char *lpParam);
  224. int BreakHandler (char *lpParam);
  225. int ComspecHandler (char *lpParam);
  226. int DisplayHandler (char *lpParam);
  227. int DosBreakHandler (char *lpParam);
  228. int SetHandler (char *lpParam);
  229. int LocalSetHandler (char *lpParam);
  230. int DosVerifyHandler (char *lpParam);
  231. int DriveHandler (char *lpParam);
  232. int FireHandler (char *lpParam);
  233. int ExitHandler (char *lpParam);
  234. int IfHandler (char *lpParam);
  235. int ElseHandler (char *lpParam);
  236. int EndHandler (char *lpParam);
  237. int IncludeHandler (char *lpParam);
  238. int MapHandler (char *lpParam);
  239. int PauseHandler (char *lpParam);
  240. int WriteHandler (char *lpParam);
  241. int NullHandler (char *lpParam);
  242. int GotoHandler (char *lpParam);
  243. int ShiftHandler (char *lpParam);
  244. int MachineHandler (char *lpParam);
  245. int CompatibleHandler(char *lpParam);
  246. int ClearHandler (char *lpParam);
  247. int LastLoginTimeHandler(char *lpParam);
  248. int ContextHandler (char *lpParam);
  249. int ScriptServerHandler(char *lpParam);
  250. int NoDefaultHandler (char *lpParam);
  251. /*
  252. * Command dispatch table. Do not change.
  253. *
  254. * If you do, you must change CM_IF, CM_ELSE, CM_END and CM_ENDIF
  255. */
  256. COMMANDTABLE nwCommand[NUMCOMMAND] =
  257. {
  258. "LOCAL", "DOS", "SET", LocalSetHandler,
  259. "TEMP", "DOS", "SET", LocalSetHandler,
  260. "TEMPORARY", "DOS", "SET", LocalSetHandler,
  261. "LOCAL", "SET", NULL, LocalSetHandler,
  262. "TEMP", "SET", NULL, LocalSetHandler,
  263. "TEMPORARY", "SET", NULL, LocalSetHandler,
  264. "DOS", "SET", NULL, SetHandler,
  265. "DOS", "VERIFY", NULL, DosVerifyHandler,
  266. "DOS", "BREAK", NULL, DosBreakHandler,
  267. "FIRE", "PHASERS", NULL, FireHandler,
  268. "ATTACH", NULL, NULL, AttachHandler,
  269. "BREAK", NULL, NULL, BreakHandler,
  270. "COMSPEC", NULL, NULL, NullHandler,
  271. "DISPLAY", NULL, NULL, DisplayHandler,
  272. "SET_TIME", NULL, NULL, NullHandler,
  273. "SET", NULL, NULL, SetHandler,
  274. "DRIVE", NULL, NULL, DriveHandler,
  275. "FDISPLAY", NULL, NULL, DisplayHandler,
  276. "FIRE", NULL, NULL, FireHandler,
  277. "EXIT", NULL, NULL, ExitHandler,
  278. "IF", NULL, NULL, IfHandler, // CM_IF
  279. "ELSE", NULL, NULL, ElseHandler, // CM_ELSE
  280. "ENDIF", NULL, NULL, EndHandler, // CM_ENDIF
  281. "END", NULL, NULL, EndHandler, // CM_END
  282. "INCLUDE", NULL, NULL, IncludeHandler,
  283. "MACHINE", NULL, NULL, MachineHandler,
  284. "MAP", NULL, NULL, MapHandler,
  285. "PAUSE", NULL, NULL, PauseHandler,
  286. "COMPATIBLE", NULL, NULL, CompatibleHandler,
  287. "PCCOMPATIBLE", NULL, NULL, CompatibleHandler,
  288. "REMARK", NULL, NULL, NullHandler,
  289. "REM", NULL, NULL, NullHandler,
  290. "SHIFT", NULL, NULL, ShiftHandler,
  291. "WAIT", NULL, NULL, PauseHandler,
  292. "WRITE", NULL, NULL, WriteHandler,
  293. "GOTO", NULL, NULL, GotoHandler,
  294. "CLS", NULL, NULL, ClearHandler,
  295. "CLEAR", NULL, NULL, ClearHandler,
  296. "SWAP", NULL, NULL, NullHandler,
  297. "LASTLOGIN", NULL, NULL, LastLoginTimeHandler, // 39
  298. "CONTEXT", NULL, NULL, ContextHandler, // 40
  299. "SCRIPT_SERVER", NULL, NULL, ScriptServerHandler, // 41
  300. "NO_DEFAULT", NULL, NULL, NoDefaultHandler, // 42
  301. "CX", NULL, NULL, ContextHandler, // 43
  302. "PATH", NULL, NULL, MapHandler, // 44
  303. };
  304. typedef struct tagVARTABLE
  305. {
  306. char *VarName;
  307. }VARTABLE;
  308. VARTABLE varTable[NUMVAR] =
  309. {
  310. "DAY_OF_WEEK",
  311. "DAY",
  312. "MONTH_NAME",
  313. "MONTH",
  314. "NDAY_OF_WEEK",
  315. "SHORT_YEAR",
  316. "YEAR",
  317. "AM_PM",
  318. "GREETING_TIME",
  319. "HOUR24",
  320. "HOUR",
  321. "MINUTE",
  322. "SECOND",
  323. "FULL_NAME",
  324. "LOGIN_NAME",
  325. "USER_ID",
  326. "PASSWORD_EXPIRES",
  327. "NETWORK_ADDRESS",
  328. "FILE_SERVER",
  329. "ACCESS_SERVER",
  330. "ERROR_LEVEL",
  331. "ERRORLEVEL",
  332. "MACHINE",
  333. "OS_VERSION",
  334. "OS",
  335. "SMACHINE",
  336. "SHELL_TYPE",
  337. "STATION",
  338. "P_STATION",
  339. "SHELL_VERSION",
  340. "LAST_NAME",
  341. "LOGIN_CONTEXT",
  342. "NETWARE_REQUESTER",
  343. "REQUESTER_CONTEXT",
  344. "ACCOUNT_BALANCE",
  345. "CN",
  346. "REQUESTER_VERSION",
  347. "SURNAME",
  348. "DOS_REQUESTER",
  349. "REQUESTER",
  350. "ADMINISTRATIVE_ASSISTANT",
  351. "ALLOW_UNLIMITED_CREDIT",
  352. "DESCRIPTION",
  353. "EMAIL_ADDRESS",
  354. "EMPLOYEE_ID",
  355. "FACSIMILE_TELEPHONE_NUMBER",
  356. "GROUP_MEMBERSHIP",
  357. "HIGHER_PRIVILEGES",
  358. "HOME_DIRECTORY",
  359. "INITIALS",
  360. "LANGUAGE",
  361. "LOCKED_BY_INTRUDER",
  362. "LOGIN_DISABLED",
  363. "LOGIN_GRACE_LIMIT",
  364. "LOGIN_GRACE_REMAINING",
  365. "LOGIN_INTRUDER_ATTEMPTS",
  366. "LOGIN_MAXIMUM_SIMULTANEOUS",
  367. "MAILSTOP",
  368. "MESSAGE_SERVER",
  369. "MINIMUM_ACCOUNT_BALANCE",
  370. "NETWORK",
  371. "OBJECT_CLASS",
  372. "OU",
  373. "PASSWORD_ALLOW_CHANGE",
  374. "PASSWORD_MINIMUM_LENGTH",
  375. "PASSWORD_REQUIRED",
  376. "PASSWORD_UNIQUE_REQUIRED",
  377. "PASSWORDS_USED",
  378. "PHYSICAL_DELIVERY_OFFICE_NAME",
  379. "POSTAL_ADDRESS",
  380. "POSTAL_CODE",
  381. "POSTAL_OFFICE_BOX",
  382. "PRIVATE_KEY",
  383. "PROFILE",
  384. "REVISION",
  385. "SECURITY_EQUALS",
  386. "SECURITY_FLAGS",
  387. "SEE_ALSO",
  388. "SERVER_HOLDS",
  389. "SUPERVISOR",
  390. "TELEPHONE_NUMBER",
  391. "TITLE",
  392. "CERTIFICATE_VALIDITY_INTERVAL",
  393. "EQUIVALENT_TO_ME",
  394. "GENERATIONAL_QUALIFIER",
  395. "GIVEN_NAME",
  396. "MAILBOX_ID",
  397. "MAILBOX_LOCATION",
  398. "PROFILE_MEMBERSHIP",
  399. "SA",
  400. "S",
  401. "L",
  402. "ACCESS",
  403. };
  404. /*
  405. * Local functions.
  406. */
  407. void SmartCap(char *ptr);
  408. int NWGetFileSize (char * lpFileName);
  409. void LoadFile (char *lpFileName, char *lpFileBuffer, int nFileSize);
  410. int ProcessLoginScriptFile (char *lpLoginScriptFile);
  411. void ProcessLoginScript (char *lpLoginScript);
  412. int ProcessLoginScriptProperty (unsigned char *);
  413. int CreateLabelList (PLABEL_LIST *ppLabelList, char *lpLoginScript);
  414. void FreeLabelList (LABEL_LIST *pLabelList);
  415. void ExternalCmdHandler(char *lpCommand);
  416. void BadCommandHandler (char *lpCommand);
  417. void CommandDispatch (char *lpCommand);
  418. int GetTableIndex(char *lpCommand, char ** prestbuffer);
  419. DWORD SwapLong(DWORD number);
  420. int EndOfLine (char *buffer);
  421. char *RemoveSpaces (char * buffer);
  422. int IsOn (char *lpParam);
  423. int IsOff (char *lpParam);
  424. int VarTranslate(char *vartext);
  425. int QuotedStringTranslate (char *buffer);
  426. void NotQuotedStringTranslate(char *buffer, BOOL remove_dbs);
  427. void SetLocalEnv(char *buffer);
  428. int SetEnv (char *lpEnvLine);
  429. char *ConvertPercent (char *buffer);
  430. void GetShellVersion(char *buffer, int index);
  431. /*
  432. * Global Defines
  433. */
  434. #define IsWhiteSpace(x) ((x==' ')||(x=='\t')||(x=='\n')||(x=='\r')||(x==0))
  435. /*
  436. * Global variables.
  437. */
  438. //
  439. // The following globals are used for goto processing... this allows us
  440. // to manipulate the line we're processing outside ProcessLoginScript.
  441. //
  442. LABEL_LIST *pGlobalLabelList;
  443. char *lpGlobalLine;
  444. char *lpGlobalLineSeparator;
  445. int fGlobalHaveNulledLineSeparator;
  446. int fGlobalExitFlag;
  447. int fGlobalIfTooDeep;
  448. int fBreakOn = TRUE;
  449. int nCondIndex;
  450. int aCondVal[MAX_NUM_IF];
  451. int ARGC;
  452. char **ARGV;
  453. int nGlobalShiftDelta = 0;
  454. int fGlobalCompatible = FALSE;
  455. int fNoDefaultLoginScript = FALSE;
  456. char *LOGIN_NAME;
  457. char *LAST_NAME;
  458. char *LOGIN_CONTEXT;
  459. char *REQUESTER_CONTEXT;
  460. char *COMMON_NAME;
  461. char *TYPED_USER_NAME;
  462. PWCHAR TYPED_USER_NAME_w;
  463. PBYTE NDSTREE;
  464. PBYTE PREFERRED_SERVER;
  465. HANDLE hconout = INVALID_HANDLE_VALUE;
  466. unsigned int CONNECTION_ID;
  467. unsigned int CONNECTION_NUMBER;
  468. unsigned int SCRIPT_ERROR = 0;
  469. #define REQUESTER_VERSION "V1.20"
  470. extern DWORD GUserObjectID;
  471. int IsEmptyFile (char *lpFile)
  472. {
  473. while (*lpFile != 0)
  474. {
  475. if (*lpFile != ' ' &&
  476. *lpFile != '\t'&&
  477. *lpFile != '\n'&&
  478. *lpFile != '\r')
  479. {
  480. return(FALSE);
  481. }
  482. lpFile++;
  483. }
  484. return(TRUE);
  485. }
  486. /*
  487. * Login was successful. Process both Login Scripts: the System Login
  488. * Script and the User Login Script. If there is an EXIT command in the
  489. * System Login Script, then we do not process the User Login Script.
  490. * If there is no User Login Script, we process a default Login Script,
  491. * which is hard-coded internally. See the Login Script appendix in
  492. * the NetWare Installation guide for more info.
  493. */
  494. void ProcessLoginScripts (unsigned int conn, char *UserName, int argc, char ** argv, char *lpScript)
  495. {
  496. unsigned int iRet = 0;
  497. unsigned long userID ;
  498. char pchUserLoginScriptFile[24];
  499. // Initalize LOGIN_NAME, CONNECTION_ID and CONNECTION_NUMBER.
  500. ARGC = argc;
  501. ARGV = argv;
  502. LOGIN_NAME = UserName;
  503. CONNECTION_ID = conn;
  504. // Initialize some 4X variables
  505. if ( fNDS )
  506. {
  507. COMMON_NAME = UserName;
  508. LOGIN_CONTEXT = malloc ( CONTEXT_MAX );
  509. if (LOGIN_CONTEXT) {
  510. strcpy( LOGIN_CONTEXT, REQUESTER_CONTEXT );
  511. }
  512. LAST_NAME = malloc( MAXLEN );
  513. if (LAST_NAME ) {
  514. NDSGetVar ( "SURNAME", LAST_NAME, MAXLEN );
  515. }
  516. }
  517. else {
  518. LAST_NAME = UserName;
  519. COMMON_NAME = UserName;
  520. LOGIN_CONTEXT = "";
  521. REQUESTER_CONTEXT = "";
  522. }
  523. if (iRet = GetConnectionNumber (conn, &CONNECTION_NUMBER))
  524. {
  525. DisplayError (iRet, "GetConnectionNumber");
  526. return;
  527. }
  528. if (lpScript)
  529. {
  530. if (!ProcessLoginScriptFile(lpScript))
  531. DisplayMessage(IDR_NO_SCRIPT_FILE, lpScript);
  532. }
  533. else
  534. {
  535. if ( fNDS )
  536. {
  537. unsigned char Object[128];
  538. unsigned char ProfileObject[256];
  539. PBYTE p;
  540. int err;
  541. // Browse back from user's node to first occurrence
  542. // or organizational unit or organization and look for
  543. // system script there. If the nearest OU or O doesn't have
  544. // a system script, don't run one.
  545. for ( p = TYPED_USER_NAME; p ; p = strchr ( p, '.' ) )
  546. {
  547. p++;
  548. if ( *p == 'O' && *(p+1) == 'U' && *(p+2) == '=' )
  549. break;
  550. if ( *p == 'O' && *(p+1) == '=' )
  551. break;
  552. }
  553. if ( p != NULL )
  554. {
  555. ProcessLoginScriptProperty( p );
  556. }
  557. // profile login script.
  558. if ( !NDSGetUserProperty ( "Profile", ProfileObject, 256, NULL, NULL) )
  559. {
  560. ConvertUnicodeToAscii( ProfileObject );
  561. ProcessLoginScriptProperty( ProfileObject );
  562. }
  563. // user login script
  564. if ( (!ProcessLoginScriptProperty( TYPED_USER_NAME )) &&
  565. (!fNoDefaultLoginScript) )
  566. {
  567. ProcessLoginScript (DefaultLoginScript);
  568. }
  569. }
  570. else
  571. {
  572. static char SysLoginScriptFile[] = "SYS:PUBLIC/NET$LOG.DAT" ;
  573. // Process system login script file.
  574. ProcessLoginScriptFile (SysLoginScriptFile);
  575. // Check if user login script exists.
  576. if (iRet = GetBinderyObjectID (conn, UserName, OT_USER,
  577. &userID))
  578. return;
  579. sprintf(pchUserLoginScriptFile, "SYS:MAIL/%lx/LOGIN", SwapLong(userID));
  580. if ( (!ProcessLoginScriptFile (pchUserLoginScriptFile)) &&
  581. (!fNoDefaultLoginScript) )
  582. {
  583. ProcessLoginScript (DefaultLoginScript);
  584. }
  585. }
  586. }
  587. }
  588. int ProcessLoginScriptFile (char *lpLoginScriptFile)
  589. {
  590. int nFileSize = 0, bEmpty;
  591. char *lpLoginScript;
  592. nFileSize = NWGetFileSize (lpLoginScriptFile);
  593. if (nFileSize <= 2)
  594. return(FALSE);
  595. // system login script exists.
  596. lpLoginScript = malloc (nFileSize);
  597. if (lpLoginScript == NULL)
  598. {
  599. DisplayMessage(IDR_NOT_ENOUGH_MEMORY);
  600. return FALSE;
  601. }
  602. LoadFile (lpLoginScriptFile, lpLoginScript, nFileSize);
  603. bEmpty = IsEmptyFile(lpLoginScript);
  604. if (!bEmpty)
  605. ProcessLoginScript (lpLoginScript);
  606. free (lpLoginScript);
  607. return(!bEmpty);
  608. }
  609. /*
  610. * Retrieve and process the Login Script property
  611. */
  612. int ProcessLoginScriptProperty ( unsigned char * Object )
  613. {
  614. unsigned int nFileSize = 0;
  615. unsigned int Actual = 0;
  616. unsigned int bEmpty;
  617. char *lpLoginScript;
  618. HANDLE Stream;
  619. int err;
  620. unsigned int i,j;
  621. if ( NDSfopenStream ( Object, "Login Script", &Stream, &nFileSize ) )
  622. return(FALSE);
  623. if ( nFileSize <= 2)
  624. return(FALSE);
  625. // login script exists.
  626. lpLoginScript = malloc (nFileSize+2);
  627. if (lpLoginScript == NULL)
  628. {
  629. DisplayMessage(IDR_NOT_ENOUGH_MEMORY);
  630. return FALSE;
  631. }
  632. memset(lpLoginScript, 0, nFileSize+2);
  633. if ( !ReadFile ( Stream, lpLoginScript, nFileSize, &Actual, NULL ) )
  634. {
  635. bEmpty = TRUE;
  636. }
  637. else if ( IsEmptyFile(lpLoginScript) )
  638. bEmpty = TRUE;
  639. else
  640. bEmpty = FALSE;
  641. if (!bEmpty) {
  642. for ( i = 0, j = 0; i < nFileSize; i++, j++ )
  643. {
  644. if (( lpLoginScript[i] == '\r' ) &&
  645. ( lpLoginScript[i+1] == '\n' ) )
  646. i++;
  647. lpLoginScript[j] = lpLoginScript[i];
  648. }
  649. while ( j < nFileSize )
  650. {
  651. lpLoginScript[j++] = 0;
  652. }
  653. }
  654. CloseHandle( Stream );
  655. if (!bEmpty)
  656. ProcessLoginScript (lpLoginScript);
  657. free (lpLoginScript);
  658. return(!bEmpty);
  659. }
  660. /*
  661. * Return the size of the file.
  662. */
  663. int NWGetFileSize (char * lpFileName)
  664. {
  665. int nFileSize = 0;
  666. FILE * stream;
  667. do
  668. {
  669. if ((stream = fopen (NTNWtoUNCFormat(lpFileName), "r")) == NULL)
  670. break;
  671. while (feof (stream) == 0)
  672. {
  673. fgetc (stream);
  674. nFileSize++;
  675. }
  676. if (fclose (stream))
  677. nFileSize = 0;
  678. }while (FALSE);
  679. return(nFileSize);
  680. }
  681. /*
  682. * Read the file into memory pointed by lpFileBuffer.
  683. */
  684. void LoadFile (char *lpFileName, char *lpFileBuffer, int nFileSize)
  685. {
  686. FILE * stream;
  687. if ((stream = fopen (NTNWtoUNCFormat(lpFileName), "r")) != NULL)
  688. {
  689. (void)fread (lpFileBuffer, sizeof (char), nFileSize, stream);
  690. fclose (stream);
  691. }
  692. *(lpFileBuffer+nFileSize-1) = 0;
  693. }
  694. /*
  695. * Process Login Script that is in memory pointed by lpLoginScript
  696. * line by line.
  697. */
  698. void ProcessLoginScript (char *lpLoginScript)
  699. {
  700. nCondIndex = -1;
  701. fGlobalExitFlag = FALSE;
  702. fGlobalIfTooDeep = FALSE;
  703. lpGlobalLine = lpLoginScript; // we start at the top of the login script
  704. if (!CreateLabelList (&pGlobalLabelList, lpLoginScript))
  705. {
  706. if (pGlobalLabelList != NULL) {
  707. FreeLabelList (pGlobalLabelList);
  708. pGlobalLabelList = NULL;
  709. }
  710. return;
  711. }
  712. while (*lpGlobalLine != 0) {
  713. //
  714. // search for the end of the current line and replace with a null
  715. //
  716. if (lpGlobalLineSeparator = strchr(lpGlobalLine, '\n')) {
  717. //
  718. // we may reset this manually in the goto handler, remember so that
  719. // we don't trample anything needlessly.
  720. //
  721. *lpGlobalLineSeparator = 0;
  722. fGlobalHaveNulledLineSeparator = TRUE;
  723. } else {
  724. fGlobalHaveNulledLineSeparator = FALSE;
  725. }
  726. //
  727. // Now lpGlobalLine points to one line only.
  728. //
  729. CommandDispatch (lpGlobalLine);
  730. if (fGlobalExitFlag)
  731. {
  732. if (fGlobalIfTooDeep)
  733. DisplayMessage(IDR_ORIGINAL_LINE_WAS, lpGlobalLine);
  734. break;
  735. }
  736. if (lpGlobalLineSeparator) {
  737. if ( fGlobalHaveNulledLineSeparator ) {
  738. *lpGlobalLineSeparator = '\n'; // recover the changes made.
  739. fGlobalHaveNulledLineSeparator = FALSE;
  740. }
  741. lpGlobalLine = lpGlobalLineSeparator + 1; // next line please
  742. } else {
  743. break;
  744. }
  745. }
  746. if (pGlobalLabelList != NULL) {
  747. FreeLabelList (pGlobalLabelList);
  748. pGlobalLabelList = NULL;
  749. }
  750. }
  751. /*
  752. * Scan the login script, put labels in a link list and comment out
  753. * those label lines.
  754. */
  755. int CreateLabelList (PLABEL_LIST *ppLabelList, char *lpLoginScript)
  756. {
  757. char *lpLine = lpLoginScript, *lpEnd, *lpLabel, *lpTemp;
  758. int nLen;
  759. PLABEL_LIST *ppNext = ppLabelList;
  760. while (*lpLine != 0)
  761. {
  762. if (lpEnd = strchr (lpLine, '\n'))
  763. *lpEnd = 0;
  764. // Now lpLine points to one line only.
  765. lpLabel = RemoveSpaces (lpLine);
  766. if (isalnum (*lpLabel) || (*lpLabel == '%'))
  767. {
  768. lpTemp = lpLabel;
  769. nLen = 0;
  770. while (*lpTemp != 0 && *lpTemp != ' ' && *lpTemp != '\t' && *lpTemp != ':')
  771. {
  772. if (IsDBCSLeadByte(*lpTemp))
  773. {
  774. lpTemp++;
  775. nLen++;
  776. }
  777. lpTemp++;
  778. nLen++;
  779. }
  780. lpTemp = RemoveSpaces (lpTemp);
  781. if (*lpTemp == ':' && EndOfLine (lpTemp+1))
  782. {
  783. // The Line is label line.
  784. if ((*ppNext = malloc (sizeof (LABEL_LIST))) == NULL ||
  785. ((*ppNext)->pLabel = malloc (nLen+1)) == NULL)
  786. {
  787. DisplayMessage(IDR_NOT_ENOUGH_MEMORY);
  788. return(FALSE);
  789. }
  790. SmartCap(lpLabel);
  791. strncpy ((*ppNext)->pLabel, lpLabel, nLen);
  792. *((*ppNext)->pLabel+nLen) = 0;
  793. (*ppNext)->pNextLine = lpEnd? lpEnd+1 : lpEnd;
  794. (*ppNext)->pNext = NULL;
  795. ppNext = &((*ppNext)->pNext);
  796. // Comment out the label line.
  797. *(lpLine) = ';';
  798. }
  799. }
  800. if (lpEnd)
  801. {
  802. *lpEnd = '\n'; // recover the changes made.
  803. lpLine = lpEnd+1;
  804. }
  805. else
  806. break;
  807. }
  808. return(TRUE);
  809. }
  810. /*
  811. * Free up the memory allocated for the link list.
  812. */
  813. void FreeLabelList (LABEL_LIST *pLabelList)
  814. {
  815. LABEL_LIST *pNext = pLabelList;
  816. while (pLabelList)
  817. {
  818. pNext = pLabelList->pNext;
  819. free (pLabelList->pLabel);
  820. free (pLabelList);
  821. pLabelList = pNext;
  822. }
  823. }
  824. /*
  825. * Dispatch to command hander according to the command.
  826. */
  827. void CommandDispatch (char *lpCommand)
  828. {
  829. char buffer[MAXLEN];
  830. char *restBuffer;
  831. int index, fCommandHandled = FALSE;
  832. int nTemp = -1;
  833. // Get rid of leading spaces.
  834. lpCommand = RemoveSpaces(lpCommand);
  835. // Don't do anything if it's a comment line or empty line.
  836. if (*lpCommand == ';' || *lpCommand == '*' || *lpCommand == '\0' ||
  837. *lpCommand == '\r'|| *lpCommand == '\n')
  838. return;
  839. do // FALSE loop.
  840. {
  841. // Make sure the command line is not too long to process.
  842. if (strlen (lpCommand) > MAXLEN -1) {
  843. break;
  844. }
  845. // Make a copy of the command line to buffer.
  846. strcpy (buffer, lpCommand);
  847. // external command line.
  848. if (*buffer == '#')
  849. {
  850. ExternalCmdHandler (buffer);
  851. return;
  852. }
  853. // Get the command index in the command table.
  854. if ((index = GetTableIndex(buffer, &restBuffer)) == -1)
  855. break;
  856. // Dispatch to the corresponding command handler.
  857. if (nCondIndex > -1 &&
  858. !aCondVal[nCondIndex] &&
  859. index != CM_IF &&
  860. index != CM_ELSE &&
  861. index != CM_END &&
  862. index != CM_ENDIF)
  863. fCommandHandled = TRUE;
  864. else
  865. fCommandHandled = (*nwCommand[index].commandhandler)(restBuffer);
  866. } while (FALSE);
  867. if (!fCommandHandled) {
  868. BadCommandHandler (lpCommand);
  869. }
  870. }
  871. /*
  872. * Used by GetTableIndex().
  873. * This function should capitalize the entire command string except
  874. * those in quotes. It should also skip DBCS characters.
  875. */
  876. void SmartCap(char *ptr)
  877. {
  878. int inquotes = (*ptr == '\"');
  879. char *pNext;
  880. while (*ptr)
  881. {
  882. if (!inquotes && !IsDBCSLeadByte(*ptr))
  883. {
  884. *ptr = (char) toupper((int)*ptr);
  885. }
  886. pNext = NWAnsiNext(ptr);
  887. if (*pNext == '\"' && *ptr != '\\')
  888. inquotes = !inquotes;
  889. ptr = pNext;
  890. }
  891. }
  892. /*
  893. * Return the index of the command in the command dispatch table.
  894. * Return -1 if the command is not found in the command dispatch table.
  895. */
  896. int GetTableIndex(char *buffer, char **prestBuffer)
  897. {
  898. int i, nStrLen;
  899. // Upcase every thing except those in quotes.
  900. SmartCap (buffer);
  901. for (i=0; i<NUMCOMMAND; i++)
  902. {
  903. if (*(WORD *)nwCommand[i].commandStr0 != *(WORD *)buffer)
  904. continue;
  905. nStrLen = strlen (nwCommand[i].commandStr0);
  906. if (strncmp(nwCommand[i].commandStr0, buffer, nStrLen))
  907. continue;
  908. *prestBuffer = buffer + nStrLen;
  909. *prestBuffer = RemoveSpaces (*prestBuffer);
  910. if (nwCommand[i].commandStr1)
  911. {
  912. nStrLen = strlen (nwCommand[i].commandStr1);
  913. if (strncmp(nwCommand[i].commandStr1, *prestBuffer, nStrLen))
  914. continue;
  915. *prestBuffer += nStrLen;
  916. *prestBuffer = RemoveSpaces (*prestBuffer);
  917. if (nwCommand[i].commandStr2)
  918. {
  919. nStrLen = strlen (nwCommand[i].commandStr2);
  920. if (strncmp(nwCommand[i].commandStr2, *prestBuffer, nStrLen))
  921. continue;
  922. *prestBuffer += nStrLen;
  923. *prestBuffer = RemoveSpaces (*prestBuffer);
  924. }
  925. }
  926. return (i);
  927. }
  928. return(-1);
  929. }
  930. /*
  931. * Goto label... We modify the globals controlling what line we're on.
  932. */
  933. int GotoHandler (char *lpParam)
  934. {
  935. int fLabelFound = FALSE;
  936. char *lpLabel, *lpEnd, chEnd;
  937. LABEL_LIST *pLabelList = pGlobalLabelList;
  938. lpLabel = lpParam;
  939. lpLabel = RemoveSpaces (lpLabel);
  940. //
  941. // find the end of the label, we'll slam in a null for the search and
  942. // restore the char after we're done searching.
  943. //
  944. lpEnd = lpLabel;
  945. while (*lpEnd != 0 &&
  946. *lpEnd != ' ' &&
  947. *lpEnd != '\t' &&
  948. *lpEnd != '\r' &&
  949. *lpEnd != '\n')
  950. {
  951. if (*lpEnd == ':')
  952. return(FALSE);
  953. else
  954. lpEnd = NWAnsiNext(lpEnd);
  955. }
  956. chEnd = *lpEnd;
  957. *lpEnd = 0;
  958. while (pLabelList)
  959. {
  960. if (!_stricmp (pLabelList->pLabel, lpLabel))
  961. {
  962. if ( fGlobalHaveNulledLineSeparator )
  963. {
  964. *lpGlobalLineSeparator = '\n'; // recover the changes made.
  965. fGlobalHaveNulledLineSeparator = FALSE;
  966. }
  967. lpGlobalLine = pLabelList->pNextLine;
  968. lpGlobalLineSeparator = lpGlobalLine ? (lpGlobalLine - 1) : NULL;
  969. fLabelFound = TRUE;
  970. break;
  971. }
  972. pLabelList = pLabelList->pNext;
  973. }
  974. if (!fLabelFound)
  975. {
  976. DisplayMessage (IDR_LABEL_NOT_FOUND, lpLabel);
  977. fGlobalExitFlag = TRUE;
  978. }
  979. *lpEnd = chEnd;
  980. return( TRUE );
  981. }
  982. /*
  983. * Attach [FileServer[/UserName[;Password]]]
  984. */
  985. int AttachHandler (char *lpParam)
  986. {
  987. unsigned int iRet = 0;
  988. int fCommandHandled = FALSE;
  989. char serverName[MAX_NAME_LEN] = "";
  990. char userName[MAX_NAME_LEN] = "";
  991. char password[MAX_PASSWORD_LEN] = "";
  992. char *lpSlash, *lpSemiColon, *lpServerName, *lpUserName;
  993. unsigned int conn;
  994. int bAlreadyAttached = FALSE, bReadPassword = TRUE;
  995. do // FALSE loop.
  996. {
  997. NotQuotedStringTranslate (lpParam, TRUE);
  998. // Make sure that there is at most 1 slash.
  999. lpSlash = strchr (lpParam, '\\');
  1000. if (lpSlash == NULL)
  1001. {
  1002. lpSlash = strchr (lpParam, '/');
  1003. if (lpSlash != NULL && strchr (lpSlash+1, '/'))
  1004. break;
  1005. }
  1006. else
  1007. {
  1008. if (strchr (lpParam, '/') ||
  1009. strchr (lpSlash+1, '/') ||
  1010. strchr (lpSlash+1, '\\'))
  1011. break;
  1012. }
  1013. // Break the string at slash.
  1014. if (lpSlash)
  1015. *lpSlash = 0;
  1016. // Server name should not contain semicolon.
  1017. if (strchr (lpParam, ';'))
  1018. break;
  1019. lpServerName = strtok (lpParam, __SPACES__);
  1020. if (lpServerName == NULL)
  1021. {
  1022. if (lpSlash)
  1023. break;
  1024. }
  1025. else
  1026. {
  1027. // Make sure that there is only one name in front of the slash.
  1028. if (strtok (NULL, __SPACES__))
  1029. break;
  1030. // Copy the server name to the buffer.
  1031. if (strlen (lpParam) > MAX_NAME_LEN-1)
  1032. break;
  1033. strcpy (serverName, lpParam);
  1034. if (lpSlash)
  1035. {
  1036. lpSemiColon = strchr (lpSlash+1, ';');
  1037. if (lpSemiColon)
  1038. *lpSemiColon = 0;
  1039. lpUserName = strtok (lpSlash+1, __SPACES__);
  1040. if (lpUserName)
  1041. {
  1042. if ( strtok (NULL, __SPACES__))
  1043. break;
  1044. if (strlen (lpUserName) > MAX_NAME_LEN-1 )
  1045. break;
  1046. strcpy (userName, lpUserName);
  1047. }
  1048. if (lpSemiColon)
  1049. {
  1050. if (strlen (lpSemiColon+1) > MAX_PASSWORD_LEN-1)
  1051. break;
  1052. strcpy (password, strtok (lpSemiColon+1, __SPACES__));
  1053. xstrupr (password);
  1054. bReadPassword = FALSE;
  1055. }
  1056. }
  1057. }
  1058. fCommandHandled = TRUE;
  1059. if (serverName[0] == 0)
  1060. {
  1061. DisplayMessage(IDR_ENTER_SERVER_NAME);
  1062. if (!ReadName(serverName))
  1063. break;
  1064. DisplayMessage(IDR_ENTER_LOGIN_NAME, serverName);
  1065. if (!ReadName(userName))
  1066. break;
  1067. }
  1068. else if (userName[0] == 0)
  1069. strcpy (userName, LOGIN_NAME);
  1070. if (iRet = CAttachToFileServer(serverName, &conn, &bAlreadyAttached))
  1071. {
  1072. if (!SCRIPT_ERROR)
  1073. SCRIPT_ERROR = iRet;
  1074. break;
  1075. }
  1076. // Do not need this connection
  1077. DetachFromFileServer (conn);
  1078. iRet = Login(userName, serverName, password, bReadPassword);
  1079. // Clear out the password
  1080. memset( password, 0, sizeof( password ) );
  1081. //
  1082. // tommye - MS bug 8194 (MCS 240)
  1083. //
  1084. // If we are already attached to this server, then
  1085. // pretend we were never here - just let everything
  1086. // succeed without adding this server to the attach
  1087. // list again.
  1088. //
  1089. if (iRet == ERROR_SESSION_CREDENTIAL_CONFLICT) {
  1090. memset( password, 0, sizeof( password ) );
  1091. continue;
  1092. }
  1093. if (iRet)
  1094. {
  1095. // Ask for user name
  1096. DisplayMessage(IDR_ENTER_LOGIN_NAME, serverName);
  1097. if (!ReadName(userName))
  1098. break;
  1099. if (Login(userName, serverName, password, bReadPassword))
  1100. {
  1101. // Clear out the password
  1102. memset( password, 0, sizeof( password ) );
  1103. break;
  1104. }
  1105. }
  1106. AddServerToAttachList( serverName, LIST_3X_SERVER );
  1107. } while (FALSE);
  1108. return(fCommandHandled);
  1109. }
  1110. /*
  1111. * BREAK ON, enable ctrl-c, ctrl-break
  1112. * BREAK OFF, disable ctrl-c, ctrl-break
  1113. */
  1114. int BreakHandler (char *lpParam)
  1115. {
  1116. int fCommandHandled = TRUE;
  1117. if (IsOn(lpParam))
  1118. {
  1119. if (!fBreakOn)
  1120. BreakOn();
  1121. }
  1122. else if (IsOff(lpParam))
  1123. {
  1124. if (fBreakOn)
  1125. BreakOff();
  1126. }
  1127. else
  1128. fCommandHandled = FALSE;
  1129. return(fCommandHandled);
  1130. }
  1131. /*
  1132. * DISPLAY [pathname]file
  1133. * FDISPLAY [pathname]file
  1134. */
  1135. int DisplayHandler (char *lpParam)
  1136. {
  1137. FILE * stream;
  1138. NotQuotedStringTranslate (lpParam, TRUE);
  1139. if ((stream = fopen (lpParam, "r")) != NULL)
  1140. {
  1141. while (feof (stream) == 0)
  1142. _fputchar(fgetc (stream));
  1143. fclose (stream);
  1144. DisplayMessage(IDR_NEWLINE);
  1145. }
  1146. return(TRUE);
  1147. }
  1148. /*
  1149. * DOS BREAK ON, enable ctrl-break checking for DOS
  1150. * DOS BREAK OFF, disable ctrl-break checking for DOS
  1151. */
  1152. int DosBreakHandler (char *lpParam)
  1153. {
  1154. int fCommandHandled = TRUE;
  1155. if (IsOn (lpParam))
  1156. system ("BREAK ON");
  1157. else if(IsOff (lpParam))
  1158. system ("BREAK OFF");
  1159. else
  1160. fCommandHandled = FALSE;
  1161. return(fCommandHandled);
  1162. }
  1163. /*
  1164. * Used by SetHandler() and LocalSetHandler()
  1165. * Return TRUE if lpParam points to name = "value", and set
  1166. * lpParam to "name=value" on return.
  1167. * Return FALSE otherwise.
  1168. */
  1169. int VerifySetFormat (char *lpParam)
  1170. {
  1171. int fCorrect = FALSE;
  1172. char buffer[MAXLEN];
  1173. char *lpBuffer = buffer;
  1174. strcpy (buffer, lpParam);
  1175. do
  1176. {
  1177. while (*lpBuffer != 0 && *lpBuffer != '=' && *lpBuffer != ' ' && *lpBuffer != '\t')
  1178. lpBuffer = NWAnsiNext(lpBuffer);
  1179. lpParam[lpBuffer-buffer]=0;
  1180. strcat (lpParam, "=");
  1181. if (*lpBuffer != '=')
  1182. lpBuffer = RemoveSpaces (lpBuffer);
  1183. if (*lpBuffer != '=')
  1184. break;
  1185. lpBuffer = RemoveSpaces (lpBuffer+1);
  1186. if (*lpBuffer)
  1187. {
  1188. if (!QuotedStringTranslate (lpBuffer))
  1189. break;
  1190. strcat (lpParam, lpBuffer);
  1191. }
  1192. fCorrect = TRUE;
  1193. }while (FALSE);
  1194. return(fCorrect);
  1195. }
  1196. /*
  1197. * Used by SetHandler() and LocalSetHandler()
  1198. * Set the local environment variable.
  1199. * Don't free the memory allocated because the environment variable will
  1200. * point to free space otherwise.
  1201. */
  1202. void SetLocalEnv(char *buffer)
  1203. {
  1204. char *lpEnvString;
  1205. lpEnvString = malloc(strlen (buffer) + 1);
  1206. if (lpEnvString == NULL)
  1207. DisplayMessage(IDR_NOT_ENOUGH_MEMORY);
  1208. else
  1209. {
  1210. strcpy (lpEnvString, buffer);
  1211. _putenv (lpEnvString);
  1212. }
  1213. }
  1214. /*
  1215. * Set Dos environment variable.
  1216. * [DOS] SET name = "value"
  1217. */
  1218. int SetHandler (char *lpParam)
  1219. {
  1220. int fCommandHandled;
  1221. fCommandHandled = VerifySetFormat(lpParam);
  1222. if (fCommandHandled)
  1223. {
  1224. if ( _strnicmp( "COMSPEC=", lpParam, strlen( "COMSPEC=" ) ) )
  1225. {
  1226. SetLocalEnv(lpParam);
  1227. SetEnv (lpParam);
  1228. }
  1229. }
  1230. return(fCommandHandled);
  1231. }
  1232. /*
  1233. * Set local Dos environment variable.
  1234. * [OPTION] [DOS] SET name = "value"
  1235. */
  1236. int LocalSetHandler (char *lpParam)
  1237. {
  1238. int fCommandHandled;
  1239. fCommandHandled = VerifySetFormat(lpParam);
  1240. if (fCommandHandled)
  1241. if ( _strnicmp( "COMSPEC=", lpParam, strlen( "COMSPEC=" ) ) )
  1242. {
  1243. SetLocalEnv (lpParam);
  1244. }
  1245. return(fCommandHandled);
  1246. }
  1247. /*
  1248. * Used by DosVerifyHandler().
  1249. * Turn /V option of copy on.
  1250. */
  1251. void DosVerifyOn(void)
  1252. {
  1253. }
  1254. /*
  1255. * Used by DosVerifyHandler().
  1256. * Turn /V option of copy off.
  1257. */
  1258. void DosVerifyOff(void)
  1259. {
  1260. }
  1261. /*
  1262. * DOS VERYFY [ON|OFF], Turn /V option of copy on or off.
  1263. */
  1264. int DosVerifyHandler (char *lpParam)
  1265. {
  1266. int fCommandHandled = TRUE;
  1267. if (IsOn(lpParam))
  1268. DosVerifyOn();
  1269. else if (IsOff(lpParam))
  1270. DosVerifyOff();
  1271. else
  1272. fCommandHandled = FALSE;
  1273. return(fCommandHandled);
  1274. }
  1275. /*
  1276. * DRIVE [driveletter: | n*:], set the default drive to the one specified.
  1277. */
  1278. int DriveHandler (char *lpParam)
  1279. {
  1280. int fCommandHandled = FALSE;
  1281. WORD driveNum=0, n;
  1282. char *pColon;
  1283. do // FALSE loop.
  1284. {
  1285. if ((pColon = strchr (lpParam, ':')) == NULL ||
  1286. !EndOfLine (pColon + 1))
  1287. break;
  1288. if (*lpParam == '*')
  1289. {
  1290. *pColon = 0;
  1291. if ((n = (USHORT) atoi (lpParam+1)) < 1)
  1292. break;
  1293. GetFirstDrive (&driveNum);
  1294. driveNum += (n-1);
  1295. }
  1296. else if (pColon == lpParam+1 && isupper(*lpParam))
  1297. driveNum = *lpParam - 'A' + 1;
  1298. else
  1299. break;
  1300. if (_chdrive (driveNum))
  1301. DisplayMessage(IDR_ERROR_SET_DEFAULT_DRIVE, 'A'+driveNum-1);
  1302. else
  1303. ExportCurrentDrive( driveNum );
  1304. fCommandHandled = TRUE;
  1305. } while (FALSE);
  1306. return(fCommandHandled);
  1307. }
  1308. /*
  1309. * Used by FireHandler()
  1310. * Return TRUE if lpTemp points to the legal end of fire statement, ie
  1311. * [TIMES][COMMENTS]. It also set the *lpTemp to 0 if lpTemp is not NULL.
  1312. * Return FALSE otherwise.
  1313. */
  1314. int IsEndOfFireCmd (char *lpTemp)
  1315. {
  1316. int fEnd = FALSE;
  1317. do
  1318. {
  1319. if (*lpTemp != 0)
  1320. {
  1321. if (*lpTemp != ' ' && *lpTemp != '\t' && *lpTemp != '\r')
  1322. break;
  1323. *lpTemp = 0;
  1324. lpTemp = RemoveSpaces (lpTemp+1);
  1325. if (!strncmp (lpTemp, "TIMES", 5))
  1326. lpTemp += 5;
  1327. if (!EndOfLine (lpTemp))
  1328. break;
  1329. }
  1330. fEnd = TRUE;
  1331. }while (FALSE);
  1332. return(fEnd);
  1333. }
  1334. /*
  1335. * [FIRE | FIRE PHASERS] n TIMES.
  1336. */
  1337. int FireHandler (char *lpParam)
  1338. {
  1339. char *lpTemp, vartext[MAXLEN];
  1340. int n = 0, nLen;
  1341. time_t ltimeStart, ltimeEnd;
  1342. if (EndOfLine (lpParam))
  1343. n = 1;
  1344. else if (isdigit(*lpParam))
  1345. {
  1346. lpTemp = lpParam;
  1347. while (isdigit(*lpTemp))
  1348. lpTemp++;
  1349. if (IsEndOfFireCmd (lpTemp))
  1350. n = atoi (lpParam);
  1351. }
  1352. else if (*lpParam == '%')
  1353. {
  1354. strcpy (vartext, lpParam+1);
  1355. if (((nLen = VarTranslate (lpParam)) != 0) &&
  1356. EndOfLine (lpParam+1+nLen))
  1357. n = atoi (vartext);
  1358. }
  1359. if (n < 0)
  1360. return(FALSE);
  1361. else if (n == 0) // Compatible with NetWare.
  1362. n = 1;
  1363. while (n--)
  1364. {
  1365. _beep( 610, 100 );
  1366. _beep( 440, 50 );
  1367. time(&ltimeStart);
  1368. do
  1369. {
  1370. time(&ltimeEnd);
  1371. }while (ltimeEnd-ltimeStart == 0);
  1372. }
  1373. return(TRUE);
  1374. }
  1375. /*
  1376. * EXIT, terminate login script processing.
  1377. */
  1378. int ExitHandler (char *lpParam)
  1379. {
  1380. int n;
  1381. char buffer[16], *argv[10];
  1382. // --- Multi user code merge. Citrix bug fixes ---
  1383. // 11/18/96 cjc (Citrix) Fix DrWatson for EXIT "" command.
  1384. if (!lpParam || !strcmp(lpParam, "\"\"") ){
  1385. CleanupExit(0);
  1386. }
  1387. if (EndOfLine (lpParam)) {
  1388. CleanupExit(0);
  1389. return(TRUE);
  1390. }
  1391. else if (QuotedStringTranslate (lpParam))
  1392. {
  1393. if (!fGlobalCompatible)
  1394. {
  1395. GetShellVersion (buffer, IDS_MACHINE);
  1396. if (_stricmp (buffer, "IBM_PC"))
  1397. {
  1398. DisplayMessage(IDR_EXIT_NOT_SUPPORTED);
  1399. return(TRUE);
  1400. }
  1401. }
  1402. argv[0] = strtok (lpParam, __SPACES__);
  1403. for (n = 1; n < 9; n++)
  1404. {
  1405. if ((argv[n] = strtok (NULL, __SPACES__)) == NULL)
  1406. break;
  1407. }
  1408. argv[9] = NULL;
  1409. if ((SCRIPT_ERROR = (int) _spawnvp (P_WAIT, argv[0], argv)) == -1)
  1410. DisplayMessage(IDR_BAD_COMMAND);
  1411. CleanupExit (0);
  1412. return(TRUE);
  1413. }
  1414. else
  1415. return(FALSE);
  1416. }
  1417. BOOL nwVarNameCompare(LPCSTR src,LPCSTR target)
  1418. {
  1419. CHAR szTempName[64];
  1420. LPSTR pT = szTempName;
  1421. if (!_strnicmp(src,target,strlen(target))) {
  1422. //
  1423. // try to reject obvious problems like
  1424. // %LJUNK where %L would be fine
  1425. //
  1426. if ( !isalpha(src[strlen(target)])
  1427. || IsDBCSLeadByte(src[strlen(target)])
  1428. )
  1429. return 0;
  1430. else
  1431. return 1;
  1432. }
  1433. strcpy(szTempName,target);
  1434. while (*pT) {
  1435. if (!IsDBCSLeadByte(*pT)) {
  1436. if ('_' == *pT)
  1437. *pT = ' ';
  1438. }
  1439. pT = NWAnsiNext(pT);
  1440. }
  1441. if (!_strnicmp(src,szTempName,strlen(szTempName))) {
  1442. //
  1443. // try to reject obvious problems like
  1444. // %LJUNK where %L would be fine
  1445. //
  1446. if ( !isalpha(src[strlen(target)])
  1447. || IsDBCSLeadByte(src[strlen(target)])
  1448. )
  1449. return 0;
  1450. else
  1451. return 1;
  1452. }
  1453. return 1;
  1454. }
  1455. /*
  1456. * Used by the EvalSingleCond() in IfHandler()
  1457. * Return TRUE if buffer is the right member of condition statement.
  1458. * *pfCondition is TRUE if the condition meet, FALSE if not.
  1459. * *ppRest points to the end of the condition statement.
  1460. * Return FALSE if buffer is not the right member of condition statement.
  1461. */
  1462. int MemberOf (char *buffer, int *pfCondition, char **ppRest)
  1463. {
  1464. int i, nChar, fSucceed = FALSE;
  1465. char *lpTemp;
  1466. BYTE dataBuffer[128];
  1467. unsigned char moreFlag;
  1468. unsigned char propertyType;
  1469. unsigned long dwObjectId, *pdwGroups;
  1470. char GroupName[MAXLEN];
  1471. unsigned char segment;
  1472. *pfCondition = FALSE;
  1473. do
  1474. {
  1475. if ((buffer = strchr (buffer, '\"')) == NULL)
  1476. break;
  1477. if ((lpTemp = strchr (buffer+1, '\"')) == NULL)
  1478. break;
  1479. nChar = (int) (lpTemp - buffer + 1);
  1480. if (nChar >= MAXLEN)
  1481. break;
  1482. strncpy (GroupName, buffer, nChar);
  1483. GroupName[nChar] = 0;
  1484. if (!QuotedStringTranslate (GroupName))
  1485. break;
  1486. fSucceed = TRUE;
  1487. *pfCondition = FALSE;
  1488. *ppRest = RemoveSpaces (lpTemp+1);
  1489. if (strlen(GroupName) > MAX_NAME_LEN)
  1490. break;
  1491. if ( fNDS )
  1492. {
  1493. if ( IsMemberOfNDSGroup( GroupName ) )
  1494. {
  1495. *pfCondition = TRUE;
  1496. return(TRUE);
  1497. }
  1498. }
  1499. else
  1500. {
  1501. if (GetBinderyObjectID (CONNECTION_ID,
  1502. _strupr(GroupName),
  1503. OT_USER_GROUP,
  1504. &dwObjectId) )
  1505. goto done;
  1506. //
  1507. // For all the group ID's, try and find a match
  1508. //
  1509. for ( segment = 1, moreFlag = TRUE; moreFlag && segment; segment++ )
  1510. {
  1511. if ( NWReadPropertyValue ((NWCONN_HANDLE)CONNECTION_ID,
  1512. LOGIN_NAME,
  1513. OT_USER,
  1514. "GROUPS_I'M_IN",
  1515. segment,
  1516. dataBuffer,
  1517. &moreFlag,
  1518. &propertyType))
  1519. goto done;
  1520. pdwGroups = (unsigned long *) dataBuffer;
  1521. for (i = 0; i < 32 && *(pdwGroups+i); i++)
  1522. {
  1523. if (*(pdwGroups+i) == dwObjectId)
  1524. {
  1525. *pfCondition = TRUE;
  1526. return(TRUE);
  1527. }
  1528. }
  1529. }
  1530. }
  1531. *pfCondition = FALSE;
  1532. fSucceed = TRUE;
  1533. } while (FALSE);
  1534. done:
  1535. return(fSucceed);
  1536. }
  1537. /*
  1538. * Used by IsCompare() in EvalSingleCond() in IfHandler()
  1539. * Return the next token.
  1540. */
  1541. char *GetNextPart (char *lpTemp)
  1542. {
  1543. INT i;
  1544. if (strncmp (lpTemp, "VALUE", 5) == 0)
  1545. lpTemp = RemoveSpaces (lpTemp+5);
  1546. if (*lpTemp == '\"')
  1547. {
  1548. lpTemp++;
  1549. while (*lpTemp != 0 && *lpTemp != '\"')
  1550. lpTemp = NWAnsiNext(lpTemp);
  1551. if (*lpTemp == 0)
  1552. return(NULL);
  1553. else
  1554. lpTemp++;
  1555. }
  1556. else if (*lpTemp == '<')
  1557. {
  1558. while (*lpTemp != 0 && *lpTemp != '>')
  1559. lpTemp = NWAnsiNext(lpTemp);
  1560. if (*lpTemp == 0)
  1561. return(NULL);
  1562. else
  1563. lpTemp++;
  1564. }
  1565. else
  1566. {
  1567. if (*lpTemp == '%')
  1568. lpTemp++;
  1569. for (i = 0; i < (fNDS ? NUMVAR : NUMVAR_3X); i++)
  1570. {
  1571. if (!nwVarNameCompare(lpTemp, varTable[i].VarName))
  1572. {
  1573. lpTemp += strlen(varTable[i].VarName);
  1574. break;
  1575. }
  1576. }
  1577. if (i == (fNDS ? NUMVAR : NUMVAR_3X))
  1578. return(NULL);
  1579. }
  1580. return(lpTemp);
  1581. }
  1582. /*
  1583. * Used by EvalSingleCond() in IfHandler()
  1584. * left part of buffer could be "...", <...>, or ... for variables.
  1585. * Return TRUE if buffer consists of <left> <compare operator> <right part> +
  1586. * optional rest parts.
  1587. * Return FALSE otherwise.
  1588. */
  1589. int IsCompare (char *buffer, char **ppright,
  1590. int *pnLeftLen, int *pnRightLen,
  1591. int *pindex, char **ppRest)
  1592. {
  1593. int i, nLen;
  1594. char *lpTemp;
  1595. if ((lpTemp = GetNextPart (buffer)) == NULL)
  1596. return (FALSE);
  1597. *pnLeftLen = (int) (lpTemp-buffer);
  1598. lpTemp = RemoveSpaces (lpTemp);
  1599. for (i = 0; COMPARE_OPERATORS[i][0]; i++)
  1600. {
  1601. nLen = strlen (COMPARE_OPERATORS[i]);
  1602. if (!strncmp(lpTemp, COMPARE_OPERATORS[i], nLen))
  1603. {
  1604. *lpTemp = 0;
  1605. lpTemp += nLen;
  1606. *ppright = RemoveSpaces (lpTemp);
  1607. *pindex = i;
  1608. *ppRest = GetNextPart (*ppright);
  1609. if ( *ppRest == NULL )
  1610. return (FALSE);
  1611. *pnRightLen = (int) (*ppRest - *ppright);
  1612. *ppRest = RemoveSpaces (*ppRest);
  1613. return(TRUE);
  1614. }
  1615. }
  1616. return(FALSE);
  1617. }
  1618. /*
  1619. * Used by EvalSingleCond() in IfHandler()
  1620. * Evaluate lpLeft and lpRight and do the compare operation of index
  1621. * and put the result in *pfCondition.
  1622. * Return TRUE if succeed, FALSE otherwise.
  1623. */
  1624. int Compare (char *lpLeft, char *lpRight,
  1625. int nLeftLen, int nRightLen,
  1626. int index, int *pfCondition)
  1627. {
  1628. char szLeft[MAXLEN], szRight[MAXLEN], *lpTemp;
  1629. int nCompare, fValue = FALSE;
  1630. if (strncmp (lpLeft, "VALUE", 5) == 0)
  1631. {
  1632. fValue = TRUE;
  1633. lpTemp = RemoveSpaces (lpLeft+5);
  1634. nLeftLen -= (int) (lpTemp - lpLeft);
  1635. lpLeft = lpTemp;
  1636. }
  1637. if (strncmp (lpRight, "VALUE", 5) == 0)
  1638. {
  1639. fValue = TRUE;
  1640. lpTemp = RemoveSpaces (lpRight+5);
  1641. nRightLen -= (int) (lpTemp - lpRight);
  1642. lpRight = lpTemp;
  1643. }
  1644. strncpy (szLeft, lpLeft, nLeftLen);
  1645. strncpy (szRight, lpRight, nRightLen);
  1646. szLeft[nLeftLen] = 0;
  1647. szRight[nRightLen] = 0;
  1648. if (!QuotedStringTranslate (szLeft) ||
  1649. !QuotedStringTranslate (szRight))
  1650. return(FALSE);
  1651. if (fValue)
  1652. nCompare = atoi(szLeft)-atoi(szRight);
  1653. else
  1654. nCompare = _stricmp (szLeft, szRight);
  1655. if (IsNotEqual(index))
  1656. *pfCondition = (nCompare != 0);
  1657. else if (IsGreaterOrEqual(index))
  1658. *pfCondition = (nCompare >= 0);
  1659. else if (IsGreater(index))
  1660. *pfCondition = (nCompare > 0);
  1661. else if (IsLessOrEqual(index))
  1662. *pfCondition = (nCompare <= 0);
  1663. else if (IsLess(index))
  1664. *pfCondition = (nCompare < 0);
  1665. else
  1666. *pfCondition = (nCompare == 0);
  1667. return(TRUE);
  1668. }
  1669. int IsMemberOf (char *buffer)
  1670. {
  1671. int fIsMemberOf = FALSE;
  1672. if (!strncmp (buffer, "MEMBER", 6))
  1673. {
  1674. buffer += 6;
  1675. if (*buffer == ' ' || *buffer == '\t')
  1676. {
  1677. buffer = RemoveSpaces (buffer);
  1678. if (!strncmp (buffer, "OF", 2))
  1679. {
  1680. buffer += 2;
  1681. if (*buffer == ' ' || *buffer == '\t')
  1682. buffer = RemoveSpaces (buffer);
  1683. }
  1684. }
  1685. fIsMemberOf = (*buffer == '"');
  1686. }
  1687. return(fIsMemberOf);
  1688. }
  1689. int NotMemberOf (char *buffer)
  1690. {
  1691. int fNotMemberOf = FALSE;
  1692. if (!strncmp (buffer, "NOT", 3))
  1693. {
  1694. buffer += 3;
  1695. if (*buffer == ' ' || *buffer == '\t')
  1696. {
  1697. buffer = RemoveSpaces (buffer);
  1698. fNotMemberOf = IsMemberOf (buffer);
  1699. }
  1700. }
  1701. return(fNotMemberOf);
  1702. }
  1703. /*
  1704. * Used by IfHandler()
  1705. * Evaluate one condition clause and put result in *pfCondition, *ppRest
  1706. * points to the rest part of buffer.
  1707. * Return TRUE if succeed, FALSE otherwise.
  1708. */
  1709. int EvalSingleCond (char *buffer, int *pfCondition)
  1710. {
  1711. int index, fSuccess = FALSE, nLeftLen, nRightLen;
  1712. char *pright, *pRest;
  1713. if (IsMemberOf(buffer))
  1714. fSuccess = MemberOf (buffer, pfCondition, &pRest);
  1715. else if (NotMemberOf (buffer))
  1716. {
  1717. fSuccess = MemberOf (buffer, pfCondition, &pRest);
  1718. *pfCondition = !(*pfCondition);
  1719. }
  1720. else if (IsCompare (buffer, &pright, &nLeftLen, &nRightLen, &index, &pRest))
  1721. fSuccess = Compare (buffer, pright, nLeftLen, nRightLen, index, pfCondition);
  1722. else if ( !_strnicmp ("ACCESS_SERVER", buffer, strlen("ACCESS_SERVER")) )
  1723. {
  1724. fSuccess = TRUE;
  1725. *pfCondition = FALSE;
  1726. pRest = buffer + strlen ("ACCESS_SERVER");
  1727. }
  1728. if (fSuccess)
  1729. memmove (buffer, pRest, strlen (pRest)+1);
  1730. return(fSuccess);
  1731. }
  1732. int EvaluateCondExpression(char *lpCondExpression, int *pfCondition)
  1733. {
  1734. int fSuccess = FALSE, fCond;
  1735. char *lpRight, *lpLeft, *lpOp;
  1736. if (lpRight = strchr (lpCondExpression, ')'))
  1737. {
  1738. *lpRight = 0;
  1739. if ((lpLeft = strrchr (lpCondExpression, '(')) == NULL ||
  1740. !EvaluateCondExpression(lpLeft+1, pfCondition))
  1741. return(FALSE);
  1742. *lpLeft = (*pfCondition)? '1' : '0';
  1743. memmove (lpLeft+1, lpRight+1, strlen (lpRight+1)+1);
  1744. return(EvaluateCondExpression (lpCondExpression, pfCondition));
  1745. }
  1746. if (lpOp = strrchr (lpCondExpression, '+'))
  1747. {
  1748. *lpOp = 0;
  1749. if (!EvaluateCondExpression (lpCondExpression, pfCondition) ||
  1750. !EvaluateCondExpression (lpOp+1, &fCond))
  1751. return(FALSE);
  1752. *pfCondition = (*pfCondition || fCond);
  1753. return(TRUE);
  1754. }
  1755. if (lpOp = strrchr (lpCondExpression, '*'))
  1756. {
  1757. *lpOp = 0;
  1758. if (!EvaluateCondExpression (lpCondExpression, pfCondition) ||
  1759. !EvaluateCondExpression (lpOp+1, &fCond))
  1760. return(FALSE);
  1761. *pfCondition = (*pfCondition && fCond);
  1762. return(TRUE);
  1763. }
  1764. if (lpOp = strrchr (lpCondExpression, '^'))
  1765. {
  1766. *lpOp = 0;
  1767. if (!EvaluateCondExpression (lpCondExpression, pfCondition) ||
  1768. !EvaluateCondExpression (lpOp+1, &fCond))
  1769. return(FALSE);
  1770. *pfCondition = !(*pfCondition && fCond);
  1771. return(TRUE);
  1772. }
  1773. if (!strcmp (lpCondExpression, "1"))
  1774. {
  1775. *pfCondition = TRUE;
  1776. return(TRUE);
  1777. }
  1778. else if (!strcmp (lpCondExpression, "0"))
  1779. {
  1780. *pfCondition = FALSE;
  1781. return(TRUE);
  1782. }
  1783. else
  1784. return(FALSE);
  1785. }
  1786. /*
  1787. * Used by IfHandler()
  1788. * Evaluate up to 10 conditions.
  1789. * Return TRUE if succeed, FALSE otherwise.
  1790. * On return, buffer stores whatever after conditional expressions
  1791. * without leading spaces.
  1792. */
  1793. int EvaluateCond(char *buffer, int *pfCondition)
  1794. {
  1795. int fCondition = TRUE, fCurrent, fSucceed = FALSE, nCount;
  1796. char CondExpression[MAXLEN], *lpCond = CondExpression, *lpBuffer = buffer;
  1797. for (nCount = 0; nCount < 10; nCount++)
  1798. {
  1799. while (*lpBuffer == '(')
  1800. {
  1801. *lpCond = *lpBuffer;
  1802. lpCond++;
  1803. lpBuffer++;
  1804. }
  1805. lpBuffer = RemoveSpaces (lpBuffer);
  1806. if (!EvalSingleCond (lpBuffer, &fCurrent))
  1807. break;
  1808. *lpCond = fCurrent? '1' : '0';
  1809. lpCond++;
  1810. while (*lpBuffer == ')')
  1811. {
  1812. *lpCond = *lpBuffer;
  1813. lpCond++;
  1814. lpBuffer++;
  1815. }
  1816. lpBuffer = RemoveSpaces (lpBuffer);
  1817. if (*lpBuffer == ',')
  1818. {
  1819. *lpCond = '*';
  1820. lpCond++;
  1821. lpBuffer = RemoveSpaces (lpBuffer+1);
  1822. if (!strncmp (lpBuffer, "AND", 3))
  1823. lpBuffer = RemoveSpaces (lpBuffer+3);
  1824. }
  1825. else if (!strncmp (lpBuffer, "AND", 3))
  1826. {
  1827. *lpCond = '*';
  1828. lpCond++;
  1829. lpBuffer = RemoveSpaces (lpBuffer+3);
  1830. }
  1831. else if (!strncmp (lpBuffer, "&&", 2))
  1832. {
  1833. *lpCond = '*';
  1834. lpCond++;
  1835. lpBuffer = RemoveSpaces (lpBuffer+2);
  1836. }
  1837. else if ( (!strncmp (lpBuffer, "OR", 2)) ||
  1838. (!strncmp (lpBuffer, "||", 2)) )
  1839. {
  1840. *lpCond = '+';
  1841. lpCond++;
  1842. lpBuffer = RemoveSpaces (lpBuffer+2);
  1843. }
  1844. /*
  1845. * A NOR expression is documented in some books, but isn't
  1846. * implemented in the 4X login.exe I have.
  1847. */
  1848. else if (!strncmp (lpBuffer, "NOR", 3))
  1849. {
  1850. *lpCond = '^';
  1851. lpCond++;
  1852. lpBuffer = RemoveSpaces (lpBuffer+3);
  1853. }
  1854. else
  1855. {
  1856. fSucceed = TRUE;
  1857. *lpCond = 0;
  1858. lpBuffer = RemoveSpaces (lpBuffer);
  1859. memmove (buffer, lpBuffer, strlen (lpBuffer)+1);
  1860. break;
  1861. }
  1862. }
  1863. if (fSucceed)
  1864. fSucceed = EvaluateCondExpression (CondExpression, pfCondition);
  1865. return(fSucceed);
  1866. }
  1867. /*
  1868. * If statement handler.
  1869. */
  1870. int IfHandler (char *lpParam)
  1871. {
  1872. int fCommandHandled = FALSE, fCondition;
  1873. do
  1874. {
  1875. if (nCondIndex+1 == MAX_NUM_IF)
  1876. {
  1877. DisplayMessage(IDR_IF_TOO_DEEP);
  1878. fGlobalExitFlag = TRUE;
  1879. fGlobalIfTooDeep = TRUE;
  1880. return TRUE;
  1881. }
  1882. if (EndOfLine (lpParam))
  1883. break;
  1884. if (!EvaluateCond (lpParam, &fCondition))
  1885. break;
  1886. if (!strncmp (lpParam, "THEN", 4))
  1887. {
  1888. lpParam = RemoveSpaces (lpParam+4);
  1889. if (!strncmp (lpParam, "BEGIN", 5))
  1890. {
  1891. lpParam += 5;
  1892. if (!EndOfLine (lpParam))
  1893. break;
  1894. }
  1895. else if((!strncmp (lpParam, "DO", 2)) &&
  1896. (strncmp (lpParam, "DOS", 3)))
  1897. {
  1898. lpParam += 2;
  1899. if (!EndOfLine (lpParam))
  1900. break;
  1901. }
  1902. }
  1903. else if (!strncmp (lpParam, "BEGIN", 5))
  1904. {
  1905. lpParam += 5;
  1906. if (!EndOfLine (lpParam))
  1907. break;
  1908. }
  1909. if (EndOfLine (lpParam))
  1910. {
  1911. nCondIndex++;
  1912. aCondVal[nCondIndex] =
  1913. (nCondIndex > 0 && !aCondVal[nCondIndex-1])?
  1914. FALSE : fCondition;
  1915. }
  1916. else
  1917. {
  1918. if (fCondition && (nCondIndex == -1 || aCondVal[nCondIndex]))
  1919. CommandDispatch (lpParam);
  1920. }
  1921. fCommandHandled = TRUE;
  1922. }while (FALSE);
  1923. return(fCommandHandled);
  1924. }
  1925. /*
  1926. * Else statement handler.
  1927. */
  1928. int ElseHandler (char *lpParam)
  1929. {
  1930. int fCommandHandled = FALSE;
  1931. if (EndOfLine (lpParam))
  1932. {
  1933. if (nCondIndex == 0 ||
  1934. nCondIndex > 0 && aCondVal[nCondIndex-1])
  1935. aCondVal[nCondIndex] = !aCondVal[nCondIndex];
  1936. fCommandHandled = TRUE;
  1937. }
  1938. return(fCommandHandled);
  1939. }
  1940. /*
  1941. * End statement handler.
  1942. */
  1943. int EndHandler (char *lpParam)
  1944. {
  1945. int fCommandHandled = FALSE;
  1946. if (EndOfLine (lpParam))
  1947. {
  1948. if (nCondIndex > -1)
  1949. nCondIndex--;
  1950. fCommandHandled = TRUE;
  1951. }
  1952. return(fCommandHandled);
  1953. }
  1954. /*
  1955. * INCLUDE [pathname]filename
  1956. */
  1957. int IncludeHandler (char *lpParam)
  1958. {
  1959. int fCommandHandled = FALSE, nFileSize;
  1960. char *lpLoginScript, *lpTemp;
  1961. int i, nCondIndexCopy;
  1962. int aCondValCopy[MAX_NUM_IF];
  1963. int iRet;
  1964. //
  1965. // Save off the old globals that track where we are.
  1966. //
  1967. LABEL_LIST *pLabelList = pGlobalLabelList;
  1968. char *lpLine = lpGlobalLine;
  1969. char *lpLineSeparator = lpGlobalLineSeparator;
  1970. int fHaveNulledLineSeparator = fGlobalHaveNulledLineSeparator;
  1971. pGlobalLabelList = NULL; // so that we don't free it.
  1972. do
  1973. {
  1974. if (strtok (lpParam, __SPACES__) == NULL)
  1975. break;
  1976. lpTemp = strtok(NULL, __SPACES__);
  1977. if (lpTemp && !EndOfLine (lpTemp))
  1978. break;
  1979. fCommandHandled = TRUE;
  1980. // 8/6/96 cjc (Citrix merge) Fix problem with UNC names causing errors.
  1981. NotQuotedStringTranslate(lpParam, FALSE);
  1982. // NotQuotedStringTranslate(lpParam, TRUE);
  1983. nCondIndexCopy = nCondIndex;
  1984. for (i = 0; i < MAX_NUM_IF; i++)
  1985. aCondValCopy[i] = aCondVal[i];
  1986. /*
  1987. * First we try a NDS object and then a file
  1988. */
  1989. iRet = FALSE;
  1990. if ( fNDS )
  1991. {
  1992. iRet = ProcessLoginScriptProperty( lpParam );
  1993. if ( !iRet )
  1994. {
  1995. char Fixup[MAXLEN];
  1996. char * ptr;
  1997. /*
  1998. * Strip off the . in front and add context at end
  1999. */
  2000. ptr = RemoveSpaces (lpParam);
  2001. if ( *ptr == '.' ) {
  2002. ptr++;
  2003. strncpy( Fixup, ptr, MAXLEN );
  2004. }
  2005. else {
  2006. strncpy( Fixup, ptr, MAXLEN );
  2007. if ( Fixup[strlen(Fixup)-1] != '.' )
  2008. strcat( Fixup, "." );
  2009. strcat( Fixup, LOGIN_CONTEXT );
  2010. }
  2011. iRet = ProcessLoginScriptProperty( Fixup );
  2012. }
  2013. }
  2014. if ( !fNDS || !iRet )
  2015. {
  2016. nFileSize = NWGetFileSize (lpParam);
  2017. if (nFileSize == 0)
  2018. {
  2019. DisplayMessage(IDR_ERROR_OPEN_SCRIPT, lpParam);
  2020. break;
  2021. }
  2022. // user login script exists.
  2023. lpLoginScript = malloc (nFileSize);
  2024. if (lpLoginScript == NULL)
  2025. {
  2026. DisplayMessage(IDR_NOT_ENOUGH_MEMORY);
  2027. break;
  2028. }
  2029. LoadFile (lpParam, lpLoginScript, nFileSize);
  2030. // dfergus 19 Apr 2001 - 192395
  2031. // check lpLoginScript for contents
  2032. //
  2033. if( lpLoginScript[0] )
  2034. ProcessLoginScript (lpLoginScript);
  2035. free (lpLoginScript);
  2036. }
  2037. fGlobalExitFlag = FALSE;
  2038. nCondIndex = nCondIndexCopy;
  2039. for (i = 0; i < MAX_NUM_IF; i++)
  2040. aCondVal[i] = aCondValCopy[i];
  2041. }while (FALSE);
  2042. //
  2043. // restore the globals that track where we are in the file.
  2044. //
  2045. pGlobalLabelList = pLabelList;
  2046. lpGlobalLine = lpLine;
  2047. lpGlobalLineSeparator = lpLineSeparator;
  2048. fGlobalHaveNulledLineSeparator = fHaveNulledLineSeparator;
  2049. return(fCommandHandled);
  2050. }
  2051. /*
  2052. * Map command handler.
  2053. */
  2054. int MapHandler (char *lpParam)
  2055. {
  2056. char buffer[MAXLEN]="";
  2057. strcpy( buffer, lpParam );
  2058. NotQuotedStringTranslate( buffer, TRUE );
  2059. Map( buffer );
  2060. return(TRUE);
  2061. }
  2062. /*
  2063. * PAUSE or WAIT.
  2064. */
  2065. int PauseHandler (char *lpParam)
  2066. {
  2067. int fCommandHandled = FALSE;
  2068. if (EndOfLine (lpParam))
  2069. {
  2070. //Empty kb buffer first.
  2071. while (_kbhit())
  2072. _getch();
  2073. DisplayMessage(IDR_STRIKE_KEY);
  2074. _getch();
  2075. DisplayMessage(IDR_NEWLINE);
  2076. fCommandHandled = TRUE;
  2077. }
  2078. return(fCommandHandled);
  2079. }
  2080. /*
  2081. * Used by WriteHandler().
  2082. * Return TRUE if buffer ends with ';'. Set it to 0
  2083. * Return FALSE otherwise.
  2084. */
  2085. int EndWithSemicolon (char *buffer)
  2086. {
  2087. char *lpLastSemicolon, *lpRest;
  2088. lpLastSemicolon = strrchr (buffer, ';');
  2089. if (lpLastSemicolon)
  2090. {
  2091. lpRest = RemoveSpaces (lpLastSemicolon+1);
  2092. if (*lpRest == 0)
  2093. {
  2094. *lpLastSemicolon = 0;
  2095. return(TRUE);
  2096. }
  2097. }
  2098. return(FALSE);
  2099. }
  2100. char *ConvertPercent (char *buffer)
  2101. {
  2102. char *lpPercent, *lpBuffer = buffer;
  2103. int nPercent = 0;
  2104. while (lpPercent = strchr (lpBuffer, '%'))
  2105. {
  2106. nPercent++;
  2107. lpBuffer = lpPercent+1;
  2108. }
  2109. if (nPercent == 0)
  2110. return(NULL);
  2111. lpBuffer = malloc (strlen(buffer)+nPercent+1);
  2112. if (lpBuffer == NULL)
  2113. return(NULL);
  2114. strcpy (lpBuffer, buffer);
  2115. lpPercent = strchr (lpBuffer, '%');
  2116. while (lpPercent)
  2117. {
  2118. memmove (lpPercent+1, lpPercent, strlen (lpPercent)+1);
  2119. lpPercent = strchr ( lpPercent+2, '%');
  2120. }
  2121. return(lpBuffer);
  2122. }
  2123. /*
  2124. * WRITE text, display a text message on the screen.
  2125. */
  2126. int WriteHandler (char *lpParam)
  2127. {
  2128. int fNewLine;
  2129. char *lpBuffer;
  2130. if (*lpParam == 0)
  2131. {
  2132. DisplayMessage(IDR_NEWLINE);
  2133. return(TRUE);
  2134. }
  2135. fNewLine = !EndWithSemicolon (lpParam);
  2136. if (!QuotedStringTranslate (lpParam))
  2137. return FALSE;
  2138. lpBuffer = ConvertPercent (lpParam);
  2139. if (lpBuffer == NULL)
  2140. {
  2141. DisplayOemString(lpParam);
  2142. }
  2143. else
  2144. {
  2145. DisplayOemString(lpBuffer);
  2146. free (lpBuffer);
  2147. }
  2148. if (fNewLine)
  2149. DisplayMessage(IDR_NEWLINE);
  2150. return(TRUE);
  2151. }
  2152. /*
  2153. * Used by ShiftHandler().
  2154. * Return TURE if the line is all numbers + [comments]
  2155. * Return FALSE otherwise.
  2156. */
  2157. int AreAllNumbers(char *buffer)
  2158. {
  2159. while (isdigit(*buffer))
  2160. buffer++;
  2161. return(EndOfLine (buffer));
  2162. }
  2163. /*
  2164. * Set the nGlobalShiftDelta variable.
  2165. */
  2166. int ShiftHandler (char *lpParam)
  2167. {
  2168. int fCommandHandled = TRUE;
  2169. if (EndOfLine (lpParam))
  2170. nGlobalShiftDelta++;
  2171. else if (*lpParam == '-')
  2172. {
  2173. lpParam = RemoveSpaces (lpParam+1);
  2174. if (!AreAllNumbers(lpParam))
  2175. fCommandHandled = FALSE;
  2176. else
  2177. nGlobalShiftDelta -= atoi (lpParam);
  2178. }
  2179. else
  2180. {
  2181. if (*lpParam == '+')
  2182. lpParam = RemoveSpaces (lpParam+1);
  2183. if (!AreAllNumbers(lpParam))
  2184. fCommandHandled = FALSE;
  2185. else
  2186. nGlobalShiftDelta += atoi (lpParam);
  2187. }
  2188. return(fCommandHandled);
  2189. }
  2190. /*
  2191. * Set the machine name.
  2192. */
  2193. int MachineHandler (char *lpParam)
  2194. {
  2195. int nLen, i;
  2196. if (*lpParam != '=')
  2197. return(FALSE);
  2198. lpParam = RemoveSpaces (lpParam+1);
  2199. if (!QuotedStringTranslate(lpParam))
  2200. return(FALSE);
  2201. nLen = strlen (lpParam);
  2202. for (i = nLen; i < 15; i++)
  2203. *(lpParam+i) = ' ';
  2204. *(lpParam+15) = 0;
  2205. return(TRUE);
  2206. }
  2207. /*
  2208. * Set the fGlobalCompatible variable.
  2209. */
  2210. int CompatibleHandler(char *lpParam)
  2211. {
  2212. if (!EndOfLine (lpParam))
  2213. return(FALSE);
  2214. fGlobalCompatible = TRUE;
  2215. return(TRUE);
  2216. }
  2217. /*
  2218. * Clear the screen
  2219. */
  2220. int ClearHandler(char *lpParam)
  2221. {
  2222. CONSOLE_SCREEN_BUFFER_INFO coninfo;
  2223. COORD scrolltarget;
  2224. CHAR_INFO chinfo;
  2225. SMALL_RECT scrollrect;
  2226. if ( hconout == INVALID_HANDLE_VALUE )
  2227. {
  2228. hconout = CreateFile( L"CONOUT$", GENERIC_READ | GENERIC_WRITE,
  2229. FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
  2230. OPEN_EXISTING, 0, NULL );
  2231. }
  2232. if ( hconout == INVALID_HANDLE_VALUE )
  2233. return TRUE;
  2234. GetConsoleScreenBufferInfo( hconout, &coninfo );
  2235. scrolltarget.Y = (SHORT)(0 - coninfo.dwSize.Y);
  2236. scrolltarget.X = 0;
  2237. scrollrect.Top = 0;
  2238. scrollrect.Left = 0;
  2239. scrollrect.Bottom = coninfo.dwSize.Y;
  2240. scrollrect.Right = coninfo.dwSize.X;
  2241. chinfo.Char.AsciiChar = ' ';
  2242. chinfo.Attributes = coninfo.wAttributes;
  2243. ScrollConsoleScreenBufferA( hconout, &scrollrect, NULL,
  2244. scrolltarget, &chinfo);
  2245. coninfo.dwCursorPosition.X = 0;
  2246. coninfo.dwCursorPosition.Y = 0;
  2247. SetConsoleCursorPosition( hconout, coninfo.dwCursorPosition );
  2248. return(TRUE);
  2249. }
  2250. /*
  2251. * Display the Last Login Time
  2252. */
  2253. int LastLoginTimeHandler(char *lpParam)
  2254. {
  2255. BYTE dataBuffer[128];
  2256. unsigned char moreFlag;
  2257. unsigned char propertyType;
  2258. if ( fNDS )
  2259. {
  2260. nwShowLastLoginTime();
  2261. }
  2262. else
  2263. {
  2264. SYSTEMTIME st;
  2265. WCHAR DateBuffer[TIMEDATE_SIZE];
  2266. WCHAR TimeBuffer[TIMEDATE_SIZE];
  2267. NWReadPropertyValue ((NWCONN_HANDLE)CONNECTION_ID,
  2268. LOGIN_NAME,
  2269. OT_USER,
  2270. "MISC_LOGIN_INFO",
  2271. 1,
  2272. dataBuffer,
  2273. &moreFlag,
  2274. &propertyType);
  2275. /**
  2276. Get the data into SYSTEMTIME format:
  2277. 0 = year
  2278. 1 = month
  2279. 2 = day
  2280. 3 = hour
  2281. 4 = minute
  2282. 5 = second
  2283. 6 = day of week
  2284. **/
  2285. memset(&st, 0, sizeof(SYSTEMTIME));
  2286. st.wYear = dataBuffer[0];
  2287. st.wMonth = dataBuffer[1];
  2288. st.wDay = dataBuffer[2];
  2289. st.wHour = dataBuffer[3];
  2290. st.wMinute = dataBuffer[4];
  2291. st.wSecond = dataBuffer[5];
  2292. st.wDayOfWeek = dataBuffer[6];
  2293. /** Get the info based on the local settings **/
  2294. GetDateFormat(
  2295. LOCALE_USER_DEFAULT,
  2296. DATE_LONGDATE,
  2297. &st,
  2298. NULL,
  2299. TimeBuffer,
  2300. TIMEDATE_SIZE);
  2301. GetTimeFormat(
  2302. LOCALE_USER_DEFAULT,
  2303. 0,
  2304. &st,
  2305. NULL,
  2306. TimeBuffer,
  2307. TIMEDATE_SIZE);
  2308. DisplayMessage(IDR_LASTLOGIN, DateBuffer, TimeBuffer);
  2309. }
  2310. return(TRUE);
  2311. }
  2312. /*
  2313. * Change and/or display the current context.
  2314. */
  2315. int ContextHandler (char *lpParam)
  2316. {
  2317. unsigned char Buffer[MAXLEN];
  2318. unsigned char * ptr;
  2319. unsigned char CurrentContext[MAXLEN];
  2320. if ( *lpParam )
  2321. {
  2322. NotQuotedStringTranslate(lpParam, TRUE);
  2323. ptr = RemoveSpaces (lpParam);
  2324. if ( NDSCanonicalizeName( lpParam, Buffer, MAXLEN, TRUE ) )
  2325. {
  2326. DisplayMessage(IDR_CHANGE_CONTEXT_ERROR, lpParam);
  2327. return(TRUE);
  2328. }
  2329. if ( NDSChangeContext( Buffer ) )
  2330. {
  2331. DisplayMessage(IDR_CHANGE_CONTEXT_ERROR, lpParam);
  2332. return(TRUE);
  2333. }
  2334. }
  2335. if ( NDSGetContext( CurrentContext, MAXLEN ) )
  2336. {
  2337. DisplayMessage(IDR_GET_CONTEXT_ERROR);
  2338. }
  2339. else
  2340. {
  2341. DisplayMessage(IDR_DISPLAY_CONTEXT, CurrentContext);
  2342. }
  2343. return(TRUE);
  2344. }
  2345. /*
  2346. * Do nothing. Return TRUE so the the command will not
  2347. * be considered as bad.
  2348. */
  2349. int ScriptServerHandler (char *lpParam)
  2350. {
  2351. return(TRUE);
  2352. }
  2353. /*
  2354. * If this is a 4X login, do not execute the default login script.
  2355. */
  2356. int NoDefaultHandler (char *lpParam)
  2357. {
  2358. if ( fNDS )
  2359. fNoDefaultLoginScript = TRUE;
  2360. return(TRUE);
  2361. }
  2362. /*
  2363. * Do nothing. Return TRUE so the the command will not
  2364. * be considered as bad.
  2365. */
  2366. int NullHandler (char *lpParam)
  2367. {
  2368. return(TRUE);
  2369. }
  2370. #define NUMBER_ARGUMENTS 20
  2371. /*
  2372. * External commands start with '#', such as #command /c cls
  2373. */
  2374. void ExternalCmdHandler (char *lpCommand)
  2375. {
  2376. int n;
  2377. int i;
  2378. unsigned int CommandLength;
  2379. char *lpCmdName, *argv[NUMBER_ARGUMENTS];
  2380. for ( n = 0; n < NUMBER_ARGUMENTS; n++ )
  2381. argv[n] = NULL;
  2382. if ((nCondIndex == -1) || aCondVal[nCondIndex])
  2383. {
  2384. //Convert variables first.
  2385. NotQuotedStringTranslate(lpCommand, FALSE);
  2386. lpCommand = RemoveSpaces(lpCommand+1);
  2387. lpCmdName = strtok (lpCommand, __SPACES__);
  2388. lpCmdName = NTNWtoUNCFormat(lpCmdName);
  2389. argv[0] = lpCmdName;
  2390. for (n = 1; n < NUMBER_ARGUMENTS - 1; n++)
  2391. {
  2392. if ((argv[n] = strtok (NULL, __SPACES__)) == NULL)
  2393. break;
  2394. }
  2395. /*
  2396. * Capture command
  2397. */
  2398. CommandLength = strlen( lpCommand );
  2399. /*
  2400. * First see if a COMMAND.COM is invoked
  2401. */
  2402. if ( ( ( CommandLength >= strlen("COMMAND.COM") ) &&
  2403. ( !_stricmp( &lpCommand[CommandLength-strlen("COMMAND.COM")], "COMMAND.COM") ) ) ||
  2404. ( ( CommandLength >= strlen("COMMAND") ) &&
  2405. ( !_stricmp( &lpCommand[CommandLength-strlen("COMMAND")], "COMMAND") ) ) )
  2406. {
  2407. /*
  2408. * Search for the CAPTURE argument
  2409. */
  2410. for ( i = 1; i < n; i++ )
  2411. {
  2412. CommandLength = strlen( argv[i] );
  2413. if ( ( ( CommandLength >= strlen("CAPTURE.EXE") ) &&
  2414. ( !_stricmp( &(argv[i])[CommandLength-strlen("CAPTURE.EXE")], "CAPTURE.EXE") ) ) ||
  2415. ( ( CommandLength >= strlen("CAPTURE") ) &&
  2416. ( !_stricmp( &(argv[i])[CommandLength-strlen("CAPTURE")], "CAPTURE") ) ) ) {
  2417. Capture( argv + i, n - i );
  2418. return;
  2419. }
  2420. }
  2421. }
  2422. else
  2423. {
  2424. /*
  2425. * Is this a CAPTURE command?
  2426. */
  2427. if ( ( ( CommandLength >= strlen("CAPTURE.EXE") ) &&
  2428. ( !_stricmp( &lpCommand[CommandLength-strlen("CAPTURE.EXE")], "CAPTURE.EXE") ) ) ||
  2429. ( ( CommandLength >= strlen("CAPTURE") ) &&
  2430. ( !_stricmp( &lpCommand[CommandLength-strlen("CAPTURE")], "CAPTURE") ) ) ) {
  2431. Capture( argv, n );
  2432. return;
  2433. }
  2434. }
  2435. if ((SCRIPT_ERROR = (int) _spawnvp (P_WAIT, lpCmdName, argv)) == -1)
  2436. {
  2437. if (errno == ENOENT)
  2438. DisplayMessage(IDR_ENOENT, lpCommand);
  2439. else
  2440. DisplayMessage(IDR_CANNOT_EXECUTE, lpCommand);
  2441. }
  2442. }
  2443. }
  2444. /*
  2445. * Printe out the bad command line.
  2446. */
  2447. void BadCommandHandler (char *lpCommand)
  2448. {
  2449. DisplayMessage(IDR_SCRIPT_ERROR);
  2450. DisplayMessage(IDR_ORIGINAL_LINE_WAS, lpCommand);
  2451. }
  2452. /*
  2453. * Swap the object id.
  2454. */
  2455. DWORD SwapLong(DWORD number)
  2456. {
  2457. BYTE *p, tmp[4];
  2458. p = (BYTE *)&number;
  2459. tmp[0] = p[3];
  2460. tmp[1] = p[2];
  2461. tmp[2] = p[1];
  2462. tmp[3] = p[0];
  2463. return(*(DWORD *)tmp);
  2464. }
  2465. /*
  2466. * Remove leading spaces, including tabs.
  2467. */
  2468. char *RemoveSpaces (char * buffer)
  2469. {
  2470. while (*buffer == ' ' || *buffer == '\t')
  2471. buffer++;
  2472. return(buffer);
  2473. }
  2474. /*
  2475. * Return TRUE if buffer points to the end of the lind, FALSE otherwise.
  2476. */
  2477. int EndOfLine (char *buffer)
  2478. {
  2479. int fEndOfLine = FALSE;
  2480. buffer = RemoveSpaces (buffer);
  2481. if (*buffer == '\0' ||
  2482. *buffer == ';' ||
  2483. *buffer == '*' ||
  2484. *buffer == '\r')
  2485. fEndOfLine = TRUE;
  2486. return(fEndOfLine);
  2487. }
  2488. /*
  2489. * Return TRUE if lpParam points to "ON", FALSE otherwise.
  2490. */
  2491. int IsOn (char *lpParam)
  2492. {
  2493. int fOn = FALSE;
  2494. if (!strncmp (lpParam, "ON", 2))
  2495. {
  2496. lpParam += 2;
  2497. fOn = EndOfLine (lpParam);
  2498. }
  2499. return(fOn);
  2500. }
  2501. /*
  2502. * Return TRUE if lpParam points to "OFF", FALSE otherwise.
  2503. */
  2504. int IsOff (char *lpParam)
  2505. {
  2506. int fOff = FALSE;
  2507. if (!strncmp (lpParam, "OFF", 3))
  2508. {
  2509. lpParam += 3;
  2510. fOff = EndOfLine (lpParam);
  2511. }
  2512. return(fOff);
  2513. }
  2514. /*
  2515. * Used by VarTranslate().
  2516. * Copy to buffer the value of time variable specified by index.
  2517. */
  2518. void GetTime (char *buffer, int index)
  2519. {
  2520. time_t currentTime;
  2521. struct tm *tmCurrentTime;
  2522. time (&currentTime);
  2523. tmCurrentTime = localtime(&currentTime);
  2524. switch (index)
  2525. {
  2526. case IDS_DAY:
  2527. sprintf (buffer, "%02d\0", tmCurrentTime->tm_mday);
  2528. break;
  2529. case IDS_DAY_OF_WEEK:
  2530. LoadStringA(NULL, IDR_SUNDAY+tmCurrentTime->tm_wday, buffer, 256);
  2531. break;
  2532. case IDS_MONTH:
  2533. sprintf (buffer, "%02d\0", tmCurrentTime->tm_mon+1);
  2534. break;
  2535. case IDS_MONTH_NAME:
  2536. LoadStringA(NULL, IDR_JANUARY+tmCurrentTime->tm_mon, buffer, 256);
  2537. break;
  2538. case IDS_NDAY_OF_WEEK:
  2539. sprintf (buffer, "%d\0", tmCurrentTime->tm_wday+1);
  2540. break;
  2541. case IDS_SHORT_YEAR:
  2542. sprintf (buffer, "%04d\0", tmCurrentTime->tm_year+1900);
  2543. strcpy (buffer, buffer+2);
  2544. break;
  2545. case IDS_YEAR:
  2546. sprintf (buffer, "%04d\0", tmCurrentTime->tm_year+1900);
  2547. break;
  2548. case IDS_AM_PM:
  2549. LoadStringA(NULL, IDR_AM+(tmCurrentTime->tm_hour>=12? 1:0),buffer, 256);
  2550. break;
  2551. case IDS_GREETING_TIME:
  2552. if (tmCurrentTime->tm_hour >= 6 && tmCurrentTime->tm_hour < 12)
  2553. index=0;
  2554. else if (tmCurrentTime->tm_hour >= 12 && tmCurrentTime->tm_hour < 18)
  2555. index=1;
  2556. else
  2557. index=2;
  2558. LoadStringA(NULL, IDR_GREETING_MORNING+index, buffer, 256);
  2559. break;
  2560. case IDS_HOUR:
  2561. if (tmCurrentTime->tm_hour > 12)
  2562. tmCurrentTime->tm_hour -= 12;
  2563. sprintf (buffer, "%d\0", tmCurrentTime->tm_hour);
  2564. break;
  2565. case IDS_HOUR24:
  2566. sprintf (buffer, "%02d\0", tmCurrentTime->tm_hour);
  2567. break;
  2568. case IDS_MINUTE:
  2569. sprintf (buffer, "%02d\0", tmCurrentTime->tm_min);
  2570. break;
  2571. case IDS_SECOND:
  2572. sprintf (buffer, "%02d\0", tmCurrentTime->tm_sec);
  2573. break;
  2574. default:
  2575. *buffer = 0;
  2576. }
  2577. }
  2578. /*
  2579. * Used by VarTranslate().
  2580. * Copy to buffer login user's full name.
  2581. */
  2582. void GetFullName (char *buffer)
  2583. {
  2584. unsigned int iRet = 0;
  2585. unsigned char moreFlag;
  2586. unsigned char propertyType;
  2587. if ( fNDS )
  2588. {
  2589. NDSGetVar ( "Full Name", buffer, 128 );
  2590. if ( buffer[0] == '\0' )
  2591. strcpy (buffer, "* Unknown *");
  2592. }
  2593. else
  2594. {
  2595. iRet = NWReadPropertyValue ((NWCONN_HANDLE)CONNECTION_ID,
  2596. LOGIN_NAME,
  2597. OT_USER,
  2598. "IDENTIFICATION",
  2599. 1,
  2600. buffer,
  2601. &moreFlag,
  2602. &propertyType);
  2603. if (iRet)
  2604. strcpy (buffer, "* Unknown *");
  2605. }
  2606. }
  2607. /*
  2608. * Used by VarTranslate().
  2609. * Copy to buffer login user's object id.
  2610. */
  2611. void GetUserID (char *buffer)
  2612. {
  2613. unsigned long dwObjectID = 0;
  2614. if ( fNDS )
  2615. dwObjectID = GUserObjectID;
  2616. else
  2617. NTGetUserID( CONNECTION_ID, &dwObjectID );
  2618. sprintf (buffer, "%lx\0", SwapLong(dwObjectID));
  2619. _strupr (buffer);
  2620. }
  2621. unsigned int GetDays (unsigned int year, BYTE month, BYTE date)
  2622. {
  2623. unsigned int i, days = 0;
  2624. for (i = 1; i < month; i++)
  2625. {
  2626. if (i == 2)
  2627. days += (year%4)? 28 : 29;
  2628. else if (i == 4 || i == 6 || i == 9 || i == 11)
  2629. days += 30;
  2630. else
  2631. days += 31;
  2632. }
  2633. days += date;
  2634. return(days);
  2635. }
  2636. /*
  2637. * Used by VarTranslate().
  2638. * Copy to buffer the days in which the password expires.
  2639. */
  2640. void GetPasswordExpires (char *buffer)
  2641. {
  2642. unsigned int iRet = 0;
  2643. unsigned int iRet2 = 0;
  2644. unsigned char moreFlag;
  2645. unsigned int yearCurrent, yearEnd, days;
  2646. BYTE monthCurrent, dayCurrent, monthEnd, dayEnd;
  2647. unsigned int exptime = 0, logintime = 0;
  2648. unsigned char propertyType;
  2649. if ( fNDS )
  2650. {
  2651. iRet = NDSGetUserProperty ("Password Expiration Time", (PBYTE)&exptime,
  2652. 4, NULL, NULL);
  2653. iRet2 = NDSGetUserProperty ("Login Time", (PBYTE)&logintime,
  2654. 4, NULL, NULL);
  2655. if ( ( exptime && logintime ) && !iRet && !iRet2 )
  2656. {
  2657. if ( exptime <= logintime )
  2658. strcpy( buffer, "0" );
  2659. else
  2660. sprintf( buffer, "%u", ((exptime-logintime)/(60*60*24)) + 1 );
  2661. }
  2662. else
  2663. {
  2664. sprintf( buffer, "%u", 0x7FFF );
  2665. }
  2666. }
  2667. else
  2668. {
  2669. NTGetTheDate( &yearCurrent, &monthCurrent, &dayCurrent );
  2670. NWReadPropertyValue ((NWCONN_HANDLE)CONNECTION_ID,
  2671. LOGIN_NAME,
  2672. OT_USER,
  2673. "LOGIN_CONTROL",
  2674. 1,
  2675. buffer,
  2676. &moreFlag,
  2677. &propertyType);
  2678. yearEnd = 1900 + buffer[4];
  2679. monthEnd = buffer[5];
  2680. dayEnd = buffer[6];
  2681. if (monthEnd == 0)
  2682. days = (((yearCurrent%4)? 365 : 366) - GetDays (yearCurrent, monthCurrent, dayCurrent));
  2683. else if (yearEnd == yearCurrent)
  2684. {
  2685. if (monthEnd < monthCurrent ||
  2686. (monthEnd == monthCurrent && dayEnd <= dayCurrent))
  2687. days = 0;
  2688. else
  2689. days = GetDays (yearEnd, monthEnd, dayEnd) - GetDays (yearCurrent, monthCurrent, dayCurrent) - 1;
  2690. }
  2691. else
  2692. days = ((yearCurrent%4)? 364 : 365) + GetDays (yearEnd, monthEnd, dayEnd) - GetDays (yearCurrent, monthCurrent, dayCurrent);
  2693. sprintf (buffer, "%u", days);
  2694. }
  2695. }
  2696. /*
  2697. * Used by VarTranslate().
  2698. * Copy to buffer value of the dos environment variable.
  2699. * If the variable is not found, buffer is set to be empty string.
  2700. */
  2701. void GetDosEnv (char *buffer)
  2702. {
  2703. char *lpTemp;
  2704. // This could be called from "%<x>" where x is not upcase. capitalize
  2705. // the string first to be sure.
  2706. _strupr(buffer);
  2707. lpTemp = strchr (buffer, '>');
  2708. if (lpTemp) {
  2709. *lpTemp = 0;
  2710. lpTemp = getenv (buffer+1);
  2711. if (lpTemp && (strlen(lpTemp) < MAXLEN)) {
  2712. strcpy (buffer, lpTemp);
  2713. return;
  2714. }
  2715. }
  2716. *buffer = 0;
  2717. }
  2718. /*
  2719. * Used by VarTranslate().
  2720. * Copy to buffer the 8 bytes network address.
  2721. */
  2722. void GetNetWorkAddr (char *buffer)
  2723. {
  2724. unsigned char internetAddress[10] = {0,0,0,0,0,0,0,0,0,0};
  2725. GetInternetAddress (CONNECTION_ID,
  2726. CONNECTION_NUMBER,
  2727. internetAddress);
  2728. sprintf (buffer,
  2729. "%02X%02X%02X%02X\0",
  2730. internetAddress[0],
  2731. internetAddress[1],
  2732. internetAddress[2],
  2733. internetAddress[3] );
  2734. }
  2735. /*
  2736. * Used by VarTranslate().
  2737. * Copy to buffer the 12 bytes node address to buffer.
  2738. */
  2739. void GetPStation (char *buffer)
  2740. {
  2741. unsigned char internetAddress[10] = {0,0,0,0,0,0,0,0,0,0};
  2742. GetInternetAddress (CONNECTION_ID,
  2743. CONNECTION_NUMBER,
  2744. internetAddress);
  2745. sprintf (buffer,
  2746. "%02X%02X%02X%02X%02X%02X\0",
  2747. internetAddress[4],
  2748. internetAddress[5],
  2749. internetAddress[6],
  2750. internetAddress[7],
  2751. internetAddress[8],
  2752. internetAddress[9]);
  2753. }
  2754. /*
  2755. * Used by VarTranslate().
  2756. * Copy to buffer the decimal string representing the remaining account
  2757. * balance
  2758. */
  2759. void GetAccountBalance (char *buffer)
  2760. {
  2761. DWORD balance;
  2762. BYTE dataBuffer[128];
  2763. unsigned char moreFlag;
  2764. unsigned char propertyType;
  2765. unsigned int err;
  2766. if ( fNDS )
  2767. {
  2768. err = NDSGetUserProperty ("Account Balance", dataBuffer,128, NULL, NULL);
  2769. }
  2770. else
  2771. {
  2772. err = NWReadPropertyValue ((NWCONN_HANDLE)CONNECTION_ID,
  2773. LOGIN_NAME,
  2774. OT_USER,
  2775. "ACCOUNT_BALANCE",
  2776. 1,
  2777. dataBuffer,
  2778. &moreFlag,
  2779. &propertyType);
  2780. }
  2781. if ( err )
  2782. balance = 0;
  2783. else
  2784. balance = *((DWORD *)dataBuffer);
  2785. sprintf (buffer, "%d", balance);
  2786. }
  2787. /*
  2788. * Used by VarTranslate().
  2789. * Copy to buffer MACHINE, SMACHINE, OS, OS_VERSION or SHELL_TYPE
  2790. * to buffer according to index.
  2791. */
  2792. void GetShellVersion(char *buffer, int index)
  2793. {
  2794. static char szTemp[40];
  2795. char *lpTemp;
  2796. BYTE shellmajor, shellminor, shellnum;
  2797. NTGetVersionOfShell( szTemp, &shellmajor, &shellminor, &shellnum );
  2798. lpTemp = szTemp;
  2799. switch (index)
  2800. {
  2801. case IDS_OS:
  2802. strcpy (buffer, lpTemp);
  2803. break;
  2804. case IDS_OS_VERSION:
  2805. lpTemp += (strlen (lpTemp)+1);
  2806. strcpy (buffer, lpTemp);
  2807. break;
  2808. case IDS_MACHINE:
  2809. lpTemp += (strlen (lpTemp)+1);
  2810. lpTemp += (strlen (lpTemp)+1);
  2811. strcpy (buffer, lpTemp);
  2812. break;
  2813. case IDS_SMACHINE:
  2814. lpTemp += (strlen (lpTemp)+1);
  2815. lpTemp += (strlen (lpTemp)+1);
  2816. lpTemp += (strlen (lpTemp)+1);
  2817. strcpy (buffer, lpTemp);
  2818. break;
  2819. case IDS_SHELL_TYPE:
  2820. case IDS_SHELL_VERSION:
  2821. sprintf (buffer, "V%d.%d%d%c", shellmajor, shellminor/10, shellminor%10, 'A'+shellnum);
  2822. break;
  2823. default:
  2824. *buffer = 0;
  2825. break;
  2826. }
  2827. }
  2828. void GetArgv(char *buffer)
  2829. {
  2830. int n;
  2831. n = atoi (buffer)+nGlobalShiftDelta;
  2832. if (n == 0)
  2833. strcpy (buffer, PREFERRED_SERVER);
  2834. else if (n == 1)
  2835. strcpy (buffer, LOGIN_NAME);
  2836. else if (n > 1 && n < ARGC)
  2837. strcpy (buffer, ARGV[n]);
  2838. else
  2839. *buffer = 0;
  2840. }
  2841. /*
  2842. * vartext is an array of size MAXLEN.
  2843. * vartext points to a string starts with a variable on enter.
  2844. * vartext stores the value of the variable on exit.
  2845. * Return the lenth of the variable.
  2846. */
  2847. int VarTranslate(char *vartext)
  2848. {
  2849. int i, nVarLen = 0;
  2850. for (i = 0; i < (fNDS ? NUMVAR : NUMVAR_3X); i++)
  2851. {
  2852. if (!nwVarNameCompare(vartext, varTable[i].VarName))
  2853. {
  2854. nVarLen = strlen(varTable[i].VarName);
  2855. switch ( i )
  2856. {
  2857. case IDS_DAY_OF_WEEK:
  2858. case IDS_DAY:
  2859. case IDS_MONTH_NAME:
  2860. case IDS_MONTH:
  2861. case IDS_NDAY_OF_WEEK:
  2862. case IDS_SHORT_YEAR:
  2863. case IDS_YEAR:
  2864. case IDS_AM_PM:
  2865. case IDS_GREETING_TIME:
  2866. case IDS_HOUR24:
  2867. case IDS_HOUR:
  2868. case IDS_MINUTE:
  2869. case IDS_SECOND:
  2870. GetTime (vartext, i);
  2871. break;
  2872. case IDS_FULL_NAME:
  2873. GetFullName (vartext);
  2874. break;
  2875. case IDS_LOGIN_NAME:
  2876. strcpy (vartext, LOGIN_NAME);
  2877. /*
  2878. * 4X LOGIN.EXE always truncates and replaces spaces
  2879. * with underscores. There was a report that some
  2880. * versions of 3X LOGIN.EXE do this also.
  2881. */
  2882. if ( fNDS )
  2883. {
  2884. int i;
  2885. vartext[8] = '\0';
  2886. for ( i = 0; i < 8; i++ )
  2887. if ( vartext[i] == ' ' )
  2888. vartext[i] = '_';
  2889. }
  2890. break;
  2891. case IDS_USER_ID:
  2892. GetUserID (vartext);
  2893. break;
  2894. case IDS_PASSWORD_EXPIRES:
  2895. GetPasswordExpires (vartext);
  2896. break;
  2897. case IDS_NETWORK_ADDRESS:
  2898. case IDS_NETWORK:
  2899. GetNetWorkAddr (vartext);
  2900. break;
  2901. case IDS_FILE_SERVER:
  2902. strcpy (vartext, PREFERRED_SERVER);
  2903. break;
  2904. case IDS_ACCESS_SERVER:
  2905. case IDS_ACCESS:
  2906. strcpy (vartext, "0");
  2907. break;
  2908. case IDS_ERROR_LEVEL:
  2909. case IDS_ERRORLEVEL:
  2910. sprintf (vartext, "%u", SCRIPT_ERROR);
  2911. break;
  2912. case IDS_MACHINE:
  2913. case IDS_OS_VERSION:
  2914. case IDS_OS:
  2915. case IDS_SMACHINE:
  2916. case IDS_SHELL_TYPE:
  2917. case IDS_SHELL_VERSION:
  2918. GetShellVersion (vartext, i);
  2919. break;
  2920. case IDS_STATION:
  2921. sprintf (vartext, "%d", CONNECTION_NUMBER);
  2922. break;
  2923. case IDS_P_STATION:
  2924. GetPStation (vartext);
  2925. break;
  2926. case IDS_LAST_NAME:
  2927. case IDS_SURNAME:
  2928. strcpy (vartext, LAST_NAME);
  2929. break;
  2930. case IDS_LOGIN_CONTEXT:
  2931. strcpy (vartext, LOGIN_CONTEXT);
  2932. break;
  2933. case IDS_NETWARE_REQUESTER:
  2934. case IDS_REQUESTER_VERSION:
  2935. case IDS_DOS_REQUESTER:
  2936. case IDS_REQUESTER:
  2937. strcpy (vartext, REQUESTER_VERSION);
  2938. break;
  2939. case IDS_REQUESTER_CONTEXT:
  2940. strcpy (vartext, REQUESTER_CONTEXT);
  2941. break;
  2942. case IDS_ACCOUNT_BALANCE:
  2943. GetAccountBalance (vartext);
  2944. break;
  2945. case IDS_CN:
  2946. strcpy (vartext, COMMON_NAME);
  2947. break;
  2948. case IDS_HOME_DIRECTORY:
  2949. {
  2950. char buffer[MAXLEN];
  2951. vartext[0] = '\0';
  2952. NDSGetVar ( varTable[i].VarName, buffer, MAXLEN );
  2953. if ( buffer[0] )
  2954. ConverNDSPathToNetWarePathA( buffer, NULL, vartext );
  2955. }
  2956. break;
  2957. case IDS_ADMINISTRATIVE_ASSISTANT:
  2958. case IDS_ALLOW_UNLIMITED_CREDIT:
  2959. case IDS_DESCRIPTION:
  2960. case IDS_EMAIL_ADDRESS:
  2961. case IDS_EMPLOYEE_ID:
  2962. case IDS_FACSIMILE_TELEPHONE_NUMBER:
  2963. case IDS_GROUP_MEMBERSHIP:
  2964. case IDS_HIGHER_PRIVILEGES:
  2965. case IDS_INITIALS:
  2966. case IDS_LANGUAGE:
  2967. case IDS_LOCKED_BY_INTRUDER:
  2968. case IDS_LOGIN_DISABLED:
  2969. case IDS_LOGIN_GRACE_LIMIT:
  2970. case IDS_LOGIN_GRACE_REMAINING:
  2971. case IDS_LOGIN_INTRUDER_ATTEMPTS:
  2972. case IDS_LOGIN_MAXIMUM_SIMULTANEOUS:
  2973. case IDS_MAILSTOP:
  2974. case IDS_MESSAGE_SERVER:
  2975. case IDS_MINIMUM_ACCOUNT_BALANCE:
  2976. case IDS_OBJECT_CLASS:
  2977. case IDS_OU:
  2978. case IDS_PASSWORD_ALLOW_CHANGE:
  2979. case IDS_PASSWORD_MINIMUM_LENGTH:
  2980. case IDS_PASSWORD_REQUIRED:
  2981. case IDS_PASSWORD_UNIQUE_REQUIRED:
  2982. case IDS_PASSWORDS_USED:
  2983. case IDS_PHYSICAL_DELIVERY_OFFICE_NAME:
  2984. case IDS_POSTAL_ADDRESS:
  2985. case IDS_POSTAL_CODE:
  2986. case IDS_POSTAL_OFFICE_BOX:
  2987. case IDS_PRIVATE_KEY:
  2988. case IDS_PROFILE:
  2989. case IDS_REVISION:
  2990. case IDS_SECURITY_EQUALS:
  2991. case IDS_SECURITY_FLAGS:
  2992. case IDS_SEE_ALSO:
  2993. case IDS_SERVER_HOLDS:
  2994. case IDS_SUPERVISOR:
  2995. case IDS_TELEPHONE_NUMBER:
  2996. case IDS_TITLE:
  2997. case IDS_CERTIFICATE_VALIDITY_INTERVAL:
  2998. case IDS_EQUIVALENT_TO_ME:
  2999. case IDS_GENERATIONAL_QUALIFIER:
  3000. case IDS_GIVEN_NAME:
  3001. case IDS_MAILBOX_ID:
  3002. case IDS_MAILBOX_LOCATION:
  3003. case IDS_PROFILE_MEMBERSHIP:
  3004. case IDS_SA:
  3005. case IDS_S:
  3006. case IDS_L:
  3007. NDSGetVar ( varTable[i].VarName, vartext, MAXLEN );
  3008. break;
  3009. }
  3010. return(nVarLen);
  3011. }
  3012. }
  3013. if (isdigit(*vartext))
  3014. {
  3015. while (isdigit(vartext[nVarLen]))
  3016. nVarLen++;
  3017. GetArgv(vartext);
  3018. }
  3019. else if (*vartext == '<')
  3020. {
  3021. nVarLen = 1;
  3022. while (vartext[nVarLen] != '>' && vartext[nVarLen] != 0)
  3023. {
  3024. if (IsDBCSLeadByte(vartext[nVarLen]))
  3025. nVarLen++;
  3026. nVarLen++;
  3027. }
  3028. if (vartext[nVarLen] == 0)
  3029. nVarLen = 0;
  3030. else
  3031. {
  3032. nVarLen++;
  3033. GetDosEnv (vartext);
  3034. }
  3035. }
  3036. return(nVarLen);
  3037. }
  3038. /*
  3039. * Parse path string.
  3040. * If find the %variable value, replace it, otherwise keep as it is.
  3041. */
  3042. void NotQuotedStringTranslate(char *buf, BOOL Remove_dbs)
  3043. {
  3044. char *pPercentSign, *pRest, vartext[MAXLEN];
  3045. int nVarLen, nInsertlen;
  3046. if ( Remove_dbs )
  3047. {
  3048. // Convert \\ to \.
  3049. pRest = buf;
  3050. for (pRest = buf; *pRest; pRest = NWAnsiNext(pRest))
  3051. {
  3052. if (*pRest == '\\' && *(pRest+1) == '\\')
  3053. memmove (pRest, pRest+1, strlen (pRest));
  3054. }
  3055. }
  3056. // Convert variables following '%' sign.
  3057. pRest = buf;
  3058. while (pPercentSign = strchr(pRest, '%'))
  3059. {
  3060. pRest = pPercentSign+1;
  3061. strcpy (vartext, pRest);
  3062. nVarLen = VarTranslate(vartext);
  3063. if (nVarLen == 0)
  3064. continue;
  3065. nInsertlen = strlen (vartext);
  3066. if (strlen (buf) + nInsertlen - nVarLen < MAXLEN)
  3067. {
  3068. pRest = pPercentSign+1+nVarLen;
  3069. memmove (pPercentSign+nInsertlen, pRest, strlen (pRest)+1);
  3070. memmove (pPercentSign, vartext, nInsertlen);
  3071. pRest = pPercentSign+nInsertlen;
  3072. }
  3073. }
  3074. }
  3075. /*
  3076. * Used by QuotedStringTranslate()
  3077. * On enter, *ppTemp point to a variable, on exit *ppTemp points to the
  3078. * charecter next to the variable. *ppBuffer points to the end of the
  3079. * value of the variable.
  3080. */
  3081. int DoVarTranslate (char **ppTemp, char **ppBuffer, unsigned int nMaxLen, int fInquotes)
  3082. {
  3083. int nVarLen;
  3084. char vartext[MAXLEN];
  3085. strcpy (vartext, *ppTemp);
  3086. nVarLen = VarTranslate (vartext);
  3087. if (nVarLen != 0)
  3088. {
  3089. if (strlen(vartext) >= nMaxLen)
  3090. return(FALSE);
  3091. strcpy (*ppBuffer, vartext);
  3092. (*ppBuffer) = (*ppBuffer) + strlen (vartext);
  3093. (*ppTemp) += nVarLen;
  3094. }
  3095. else if (fInquotes)
  3096. {
  3097. strcpy (*ppBuffer, "%");
  3098. (*ppBuffer) += 1;
  3099. }
  3100. else
  3101. return(FALSE);
  3102. return(TRUE);
  3103. }
  3104. /*
  3105. * Used by QuotedStringTranslate()
  3106. * On entry, *(*ppTemp -1) is '\', if **ppTemp is one of those special
  3107. * characters, put the value in **ppBuffer, otherwise copy '\\\ and
  3108. * whatever is in *ppBuffer to *ppBuffer.
  3109. */
  3110. void TranslateSpecialChar (char **ppTemp, char **ppBuffer)
  3111. {
  3112. (*ppTemp)++;
  3113. if (**ppTemp == '\\')
  3114. **(ppBuffer) = '\\';
  3115. else if (**ppTemp == 'n')
  3116. **(ppBuffer) ='\n';
  3117. else if (**ppTemp == 'r')
  3118. **(ppBuffer) ='\r';
  3119. else if (**ppTemp == '\"')
  3120. **(ppBuffer) ='\"';
  3121. else if (**ppTemp == '7')
  3122. **(ppBuffer) ='\7';
  3123. else
  3124. {
  3125. **(ppBuffer) = '\\';
  3126. (*ppBuffer)++;
  3127. return;
  3128. }
  3129. (*ppBuffer)++;
  3130. (*ppTemp)++;;
  3131. }
  3132. /*
  3133. * Used by QuotedStringTranslate().
  3134. * Return TRUE if there are more interesting strings and it's seperated by ';'
  3135. * FALSE otherwise.
  3136. */
  3137. int GetNextString (char **ppTemp, int *pfEnd)
  3138. {
  3139. int fMore = FALSE;
  3140. (*ppTemp) = RemoveSpaces (*ppTemp);
  3141. *pfEnd = (**ppTemp == 0);
  3142. if (**ppTemp == ';')
  3143. {
  3144. (*ppTemp) = RemoveSpaces (*ppTemp+1);
  3145. fMore = TRUE;
  3146. }
  3147. return(fMore);
  3148. }
  3149. int GetLastShiftOp (char *buffer, char *pchOp, char *lpRest)
  3150. {
  3151. int i, inquotes = FALSE;
  3152. // NetWare compatibility fix.
  3153. // for (i = strlen (buffer)-1; i >= 0; i--)
  3154. for (i = 0; buffer[i]; i++)
  3155. {
  3156. if (buffer[i] == '\"' && buffer [i-1] != '\\')
  3157. inquotes = !inquotes;
  3158. if (!inquotes &&
  3159. ( (buffer[i] == '>' && buffer[i+1] == '>')
  3160. ||(buffer[i] == '<' && buffer[i+1] == '<')))
  3161. {
  3162. *pchOp = buffer[i];
  3163. buffer[i] = 0;
  3164. strcpy (lpRest, RemoveSpaces(buffer+i+2));
  3165. return(TRUE);
  3166. }
  3167. }
  3168. return(FALSE);
  3169. }
  3170. int GetLastAddOp (char *buffer, char *pchOp, char *lpRest)
  3171. {
  3172. int i, inquotes = FALSE;
  3173. // NetWare compatibility fix.
  3174. // for (i = strlen (buffer)-1; i >= 0; i--)
  3175. for (i = 0; buffer[i]; i++)
  3176. {
  3177. if (buffer[i] == '\"' && buffer [i-1] != '\\')
  3178. inquotes = !inquotes;
  3179. if (!inquotes &&
  3180. (buffer[i] == '+' || buffer[i] == '-') )
  3181. {
  3182. *pchOp = buffer[i];
  3183. buffer[i] = 0;
  3184. strcpy (lpRest, RemoveSpaces(buffer+i+1));
  3185. return(TRUE);
  3186. }
  3187. }
  3188. return(FALSE);
  3189. }
  3190. int GetLastMultiplyOp (char *buffer, char *pchOp, char *lpRest)
  3191. {
  3192. int i, inquotes = FALSE;
  3193. // NetWare compatibility fix.
  3194. // for (i = strlen (buffer)-1; i >= 0; i--)
  3195. for (i = 0; buffer[i]; i++)
  3196. {
  3197. if (buffer[i] == '\"' && buffer [i-1] != '\\')
  3198. inquotes = !inquotes;
  3199. if (!inquotes &&
  3200. (buffer[i] == '*' || buffer[i] == '/' || buffer[i] == '%') )
  3201. {
  3202. *pchOp = buffer[i];
  3203. buffer[i] = 0;
  3204. strcpy (lpRest, RemoveSpaces(buffer+i+1));
  3205. return(TRUE);
  3206. }
  3207. }
  3208. return(FALSE);
  3209. }
  3210. /*
  3211. * Used by QuotedStringTranslate.
  3212. * Return TRUE if input buffer is right format, FALSE otherwise.
  3213. */
  3214. int SingleStringTranslate (char *buffer)
  3215. {
  3216. int inquotes = FALSE, fEnd = FALSE, nShift, nLen;
  3217. char szRest[MAXLEN], chOp;
  3218. char *lpTemp = szRest, *lpBuffer=buffer;
  3219. buffer = RemoveSpaces (buffer);
  3220. if (GetLastShiftOp (buffer, &chOp, szRest))
  3221. {
  3222. if (!QuotedStringTranslate (buffer))
  3223. return(FALSE);
  3224. while (isdigit (*lpTemp))
  3225. lpTemp++;
  3226. if (!EndOfLine(lpTemp))
  3227. return(FALSE);
  3228. *lpTemp = 0;
  3229. nShift = atoi (szRest);
  3230. nLen = strlen (buffer);
  3231. if (nShift >= nLen)
  3232. *buffer = 0;
  3233. else
  3234. {
  3235. if (chOp == '<')
  3236. memmove (buffer, buffer+nShift, nLen-nShift);
  3237. *(buffer+nLen-nShift) = 0;
  3238. }
  3239. }
  3240. else if (GetLastAddOp (buffer, &chOp, szRest))
  3241. {
  3242. if (!QuotedStringTranslate (buffer) ||
  3243. !QuotedStringTranslate (szRest))
  3244. return(FALSE);
  3245. sprintf (buffer, "%d", (chOp == '+')? (atoi (buffer) + atoi (szRest))
  3246. : (atoi (buffer) - atoi (szRest)));
  3247. }
  3248. else if (GetLastMultiplyOp (buffer, &chOp, szRest))
  3249. {
  3250. if (!QuotedStringTranslate (buffer) ||
  3251. !QuotedStringTranslate (szRest))
  3252. return(FALSE);
  3253. if (chOp == '*')
  3254. sprintf (buffer, "%d", atoi (buffer) * atoi (szRest));
  3255. else
  3256. {
  3257. if (atoi (szRest) == 0)
  3258. {
  3259. DisplayMessage(IDR_DIVIDE_BY_ZERO);
  3260. strcpy (buffer, "0");
  3261. }
  3262. else
  3263. {
  3264. sprintf (buffer, "%d",(chOp == '/')? (atoi (buffer) / atoi (szRest))
  3265. : (atoi (buffer) % atoi (szRest)));
  3266. }
  3267. }
  3268. }
  3269. else
  3270. {
  3271. strcpy (szRest, buffer);
  3272. *buffer = 0;
  3273. while (*lpTemp)
  3274. {
  3275. if (inquotes)
  3276. {
  3277. if (*lpTemp == '\\')
  3278. TranslateSpecialChar (&lpTemp, &buffer);
  3279. else if (*lpTemp == '\"')
  3280. {
  3281. inquotes = !inquotes;
  3282. lpTemp++;
  3283. if (!GetNextString (&lpTemp, &fEnd))
  3284. break;
  3285. }
  3286. else if (*lpTemp == '%')
  3287. {
  3288. lpTemp++;
  3289. DoVarTranslate (&lpTemp, &buffer, MAXLEN-(UINT)(buffer-lpBuffer), TRUE);
  3290. }
  3291. else
  3292. {
  3293. *buffer = *lpTemp;
  3294. if (IsDBCSLeadByte(*buffer))
  3295. {
  3296. buffer++;
  3297. lpTemp++;
  3298. *buffer = *lpTemp;
  3299. }
  3300. buffer++;
  3301. lpTemp++;
  3302. }
  3303. }
  3304. else
  3305. {
  3306. if (*lpTemp == '\"')
  3307. {
  3308. inquotes = !inquotes;
  3309. lpTemp++;
  3310. }
  3311. else
  3312. {
  3313. if (!DoVarTranslate (&lpTemp, &buffer, MAXLEN-(UINT)(buffer-lpBuffer), FALSE) ||
  3314. !GetNextString (&lpTemp, &fEnd))
  3315. break;
  3316. }
  3317. }
  3318. }
  3319. if (!fEnd)
  3320. {
  3321. if ( inquotes )
  3322. DisplayMessage( IDR_NO_END_QUOTE );
  3323. return(FALSE);
  3324. }
  3325. *buffer = 0;
  3326. }
  3327. return(TRUE);
  3328. }
  3329. /*
  3330. * Replace the variables in the string with their value.
  3331. * Use this function when the input string is quoted format.
  3332. * Return TRUE if input buffer is right format, FALSE otherwise.
  3333. */
  3334. int QuotedStringTranslate (char *buffer)
  3335. {
  3336. char szTemp[MAXLEN], *lpLeft, *lpRight, *ptr = buffer, *pNext;
  3337. int inquotes;
  3338. lpLeft = *buffer == '('? buffer : NULL;
  3339. lpRight = *buffer == ')'? buffer : NULL;
  3340. inquotes = (*ptr == '"');
  3341. while (*ptr)
  3342. {
  3343. pNext = NWAnsiNext (ptr);
  3344. if (*pNext == '"' && *(ptr) != '\\')
  3345. {
  3346. pNext++;
  3347. inquotes = !inquotes;
  3348. }
  3349. ptr = pNext;
  3350. if (!inquotes)
  3351. {
  3352. if (*ptr == '(')
  3353. lpLeft = ptr;
  3354. else if (*ptr == ')')
  3355. {
  3356. lpRight = ptr;
  3357. *lpRight = 0;
  3358. if (lpLeft == NULL)
  3359. return(FALSE);
  3360. if (lpRight - lpLeft <= 1) //There should be something in the backets.
  3361. return(FALSE);
  3362. *lpLeft = 0;
  3363. strncpy (szTemp, lpLeft+1, (UINT)(lpRight-lpLeft));
  3364. if (!SingleStringTranslate (szTemp))
  3365. return(FALSE);
  3366. if (strlen (buffer) + strlen(szTemp) + strlen (lpRight+1) + 2 >= MAXLEN)
  3367. return(FALSE);
  3368. *lpLeft = '"';
  3369. *(lpLeft+1+strlen(szTemp)) = '"';
  3370. memmove (lpLeft+2+strlen(szTemp), lpRight+1, strlen (lpRight+1)+1);
  3371. memmove (lpLeft+1, szTemp, strlen(szTemp));
  3372. lpLeft = *buffer == '('? buffer : NULL;
  3373. lpRight = *buffer == ')'? buffer : NULL;
  3374. ptr = buffer;
  3375. inquotes = (*ptr == '"');
  3376. }
  3377. }
  3378. }
  3379. if (lpLeft != NULL || lpRight != NULL)
  3380. return(FALSE);
  3381. return(SingleStringTranslate (buffer));
  3382. }
  3383. void BreakOff(void)
  3384. {
  3385. fBreakOn = FALSE;
  3386. NTBreakOff();
  3387. }
  3388. void BreakOn(void)
  3389. {
  3390. fBreakOn = TRUE;
  3391. NTBreakOn();
  3392. }
  3393. /*
  3394. * Used by ComspecHandler() and SetHandler()
  3395. * Set dos environment variable.
  3396. */
  3397. int SetEnv (char *lpEnvLine)
  3398. {
  3399. ExportEnv( lpEnvLine );
  3400. return(TRUE);
  3401. }