Source code of Windows XP (NT5)
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.

295 lines
8.1 KiB

  1. #include <stdio.h>
  2. #include <fstream.h>
  3. #include <windows.h>
  4. #include <winver.h>
  5. #include <tchar.h>
  6. #include <ole2.h>
  7. #include <shlobj.h>
  8. #include "other.h"
  9. #define UNICODE
  10. #define _UNICODE
  11. #define DEBUGTEMP
  12. //
  13. // prototypes...
  14. //
  15. int __cdecl main(int ,char *argv[]);
  16. void ShowHelp(void);
  17. LPSTR StripWhitespace(LPSTR pszString);
  18. BOOL DoStuff1(WCHAR *szUserName,WCHAR *szUserDomain,WCHAR *szUserPass);
  19. //
  20. // Globals
  21. //
  22. int g_Flag_u = FALSE;
  23. int g_Flag_d = FALSE;
  24. int g_Flag_p = FALSE;
  25. WCHAR g_wszUserName[50];
  26. WCHAR g_wszUserDomain[50];
  27. WCHAR g_wszUserPass[50];
  28. //-------------------------------------------------------------------
  29. // purpose: main
  30. //-------------------------------------------------------------------
  31. int __cdecl main(int argc,char *argv[])
  32. {
  33. LPSTR pArg = NULL;
  34. LPSTR pCmdStart = NULL;
  35. int argno;
  36. int nflags=0;
  37. char szTempFileName[MAX_PATH];
  38. char szTempString[MAX_PATH];
  39. szTempFileName[0] = '\0';
  40. // process command line arguments
  41. for(argno=1; argno<argc; argno++)
  42. {
  43. if ( argv[argno][0] == '-' || argv[argno][0] == '/' )
  44. {
  45. nflags++;
  46. switch (argv[argno][1])
  47. {
  48. case 'u':
  49. case 'U':
  50. g_Flag_u = TRUE;
  51. // Get the string for this flag
  52. pArg = CharNext(argv[argno]);
  53. pArg = CharNext(pArg);
  54. if (*pArg == ':')
  55. {
  56. pArg = CharNext(pArg);
  57. // Check if it's quoted
  58. if (*pArg == '\"')
  59. {
  60. pArg = CharNext(pArg);
  61. pCmdStart = pArg;
  62. while ((*pArg) && (*pArg != '\"')){pArg = CharNext(pArg);}
  63. }
  64. else
  65. {
  66. pCmdStart = pArg;
  67. // while ((*pArg) && (*pArg != '/') && (*pArg != '-')){pArg = CharNext(pArg);}
  68. while (*pArg){pArg = CharNext(pArg);}
  69. }
  70. *pArg = '\0';
  71. lstrcpy(szTempString, StripWhitespace(pCmdStart));
  72. #ifdef DEBUGTEMP
  73. printf(szTempString); printf("\n");
  74. #endif
  75. // Convert to unicode
  76. // And assign it to the global.
  77. MultiByteToWideChar(CP_ACP, 0, (LPCSTR)szTempString, -1, (LPWSTR) g_wszUserName, 50);
  78. }
  79. break;
  80. case 'd':
  81. case 'D':
  82. g_Flag_d = TRUE;
  83. // Get the string for this flag
  84. pArg = CharNext(argv[argno]);
  85. pArg = CharNext(pArg);
  86. if (*pArg == ':')
  87. {
  88. pArg = CharNext(pArg);
  89. // Check if it's quoted
  90. if (*pArg == '\"')
  91. {
  92. pArg = CharNext(pArg);
  93. pCmdStart = pArg;
  94. while ((*pArg) && (*pArg != '\"')){pArg = CharNext(pArg);}
  95. }
  96. else
  97. {
  98. pCmdStart = pArg;
  99. // while ((*pArg) && (*pArg != '/') && (*pArg != '-')){pArg = CharNext(pArg);}
  100. while (*pArg){pArg = CharNext(pArg);}
  101. }
  102. *pArg = '\0';
  103. lstrcpy(szTempString, StripWhitespace(pCmdStart));
  104. #ifdef DEBUGTEMP
  105. printf(szTempString); printf("\n");
  106. #endif
  107. // Convert to unicode
  108. // And assign it to the global.
  109. MultiByteToWideChar(CP_ACP, 0, (LPCSTR)szTempString, -1, (LPWSTR) g_wszUserDomain, 50);
  110. }
  111. break;
  112. case 'p':
  113. case 'P':
  114. g_Flag_p = TRUE;
  115. // Get the string for this flag
  116. pArg = CharNext(argv[argno]);
  117. pArg = CharNext(pArg);
  118. if (*pArg == ':')
  119. {
  120. pArg = CharNext(pArg);
  121. // Check if it's quoted
  122. if (*pArg == '\"')
  123. {
  124. pArg = CharNext(pArg);
  125. pCmdStart = pArg;
  126. while ((*pArg) && (*pArg != '\"')){pArg = CharNext(pArg);}
  127. }
  128. else
  129. {
  130. pCmdStart = pArg;
  131. // while ((*pArg) && (*pArg != '/') && (*pArg != '-')){pArg = CharNext(pArg);}
  132. while (*pArg){pArg = CharNext(pArg);}
  133. }
  134. *pArg = '\0';
  135. lstrcpy(szTempString, StripWhitespace(pCmdStart));
  136. #ifdef DEBUGTEMP
  137. printf(szTempString); printf("\n");
  138. #endif
  139. // Convert to unicode
  140. // And assign it to the global.
  141. MultiByteToWideChar(CP_ACP, 0, (LPCSTR)szTempString, -1, (LPWSTR) g_wszUserPass, 50);
  142. }
  143. break;
  144. case '?':
  145. goto main_exit_with_help;
  146. break;
  147. }
  148. } // if switch character found
  149. else
  150. {
  151. if ( *szTempFileName == '\0' )
  152. {
  153. // if no arguments, then
  154. // get the ini_filename_dir and put it into
  155. strcpy(szTempFileName, argv[argno]);
  156. }
  157. } // non-switch char found
  158. } // for all arguments
  159. if (FALSE == DoStuff1(g_wszUserName,g_wszUserDomain,g_wszUserPass))
  160. {goto main_exit_with_help;}
  161. goto main_exit_gracefully;
  162. main_exit_gracefully:
  163. printf("Done.\n");
  164. return TRUE;
  165. main_exit_with_help:
  166. ShowHelp();
  167. return FALSE;
  168. }
  169. void ShowHelp()
  170. {
  171. char szModuleName[_MAX_PATH];
  172. char szFilename_only[_MAX_FNAME];
  173. char szMyString[_MAX_PATH + _MAX_PATH];
  174. GetModuleFileName(NULL, szModuleName, _MAX_PATH);
  175. // Trim off the filename only.
  176. _tsplitpath(szModuleName, NULL, NULL, szFilename_only, NULL);
  177. sprintf(szMyString, "\n%s - Checks if password is valid for given Username\\Domain\\Password\n", szFilename_only);
  178. printf(szMyString);
  179. sprintf(szMyString, "------------------------------------------------------------------------\n", szFilename_only);
  180. printf(szMyString);
  181. sprintf(szMyString, "Usage: %s -u:(username) -d:(domain) -p:(password) \n", szFilename_only);
  182. printf(szMyString);
  183. sprintf(szMyString, "Example: %s -u:aaronl -d:redmond -p:mypassword \n", szFilename_only);
  184. printf(szMyString);
  185. sprintf(szMyString, "Hint: Special characters like a quotation mark in the password, \n");
  186. printf(szMyString);
  187. sprintf(szMyString, "should be designated like: %s -u:(username) -d:(domain) -p:Mr\\\"Weekend\\\" \n", szFilename_only);
  188. printf(szMyString);
  189. return;
  190. }
  191. //***************************************************************************
  192. //* *
  193. //* NAME: StripWhitespace *
  194. //* *
  195. //* SYNOPSIS: Strips spaces and tabs from both sides of given string. *
  196. //* *
  197. //***************************************************************************
  198. LPSTR StripWhitespace( LPSTR pszString )
  199. {
  200. LPSTR pszTemp = NULL;
  201. if ( pszString == NULL ) {
  202. return NULL;
  203. }
  204. while ( *pszString == ' ' || *pszString == '\t' ) {
  205. pszString += 1;
  206. }
  207. // Catch case where string consists entirely of whitespace or empty string.
  208. if ( *pszString == '\0' ) {
  209. return pszString;
  210. }
  211. pszTemp = pszString;
  212. pszString += lstrlen(pszString) - 1;
  213. while ( *pszString == ' ' || *pszString == '\t' ) {
  214. *pszString = '\0';
  215. pszString -= 1;
  216. }
  217. return pszTemp;
  218. }
  219. //-------------------------------------------------------------------
  220. // purpose: misc
  221. //-------------------------------------------------------------------
  222. BOOL DoStuff1(WCHAR *szUserName,WCHAR *szUserDomain,WCHAR *szUserPass)
  223. {
  224. BOOL bReturn = FALSE;
  225. char szMyString[_MAX_PATH + _MAX_PATH];
  226. char szTempString1[100];
  227. char szTempString2[100];
  228. char szTempString3[100];
  229. LPCWSTR lpszUserName = szUserName;
  230. LPCWSTR lpszUserDomain = szUserDomain;
  231. LPCWSTR lpszUserPass = szUserPass;
  232. // check if any of the fields are blank...
  233. if (!szUserName) {goto DoStuff1_Exit_BlankUser;}
  234. if (_wcsicmp(szUserName,L"") == 0) {goto DoStuff1_Exit_BlankUser;}
  235. WideCharToMultiByte( CP_ACP, 0, (WCHAR *)szUserName, -1, szTempString1, 100, NULL, NULL );
  236. WideCharToMultiByte( CP_ACP, 0, (WCHAR *)szUserDomain, -1, szTempString2, 100, NULL, NULL );
  237. WideCharToMultiByte( CP_ACP, 0, (WCHAR *)szUserPass, -1, szTempString3, 100, NULL, NULL );
  238. sprintf(szMyString, "Validating:User=%s,Domain=%s,Password=%s\n",szTempString1,szTempString2,szTempString3);
  239. printf(szMyString);
  240. if (TRUE == ValidatePassword(lpszUserName, lpszUserDomain, lpszUserPass))
  241. {
  242. printf("Yes! Password is valid.\n");
  243. bReturn = TRUE;
  244. }
  245. else
  246. {printf("No! Password is not valid.\n");}
  247. DoStuff1_Exit:
  248. return bReturn;
  249. DoStuff1_Exit_BlankUser:
  250. sprintf(szMyString, "Error: Missing required parameter. User Name is empty.\n");
  251. printf(szMyString);
  252. goto DoStuff1_Exit;
  253. }