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.

298 lines
6.4 KiB

  1. //----------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1993.
  5. //
  6. // File: drt.cxx
  7. //
  8. // Contents: Main for OleDs DRT
  9. //
  10. //
  11. // History: 28-Oct-94 KrishnaG, created OleDs DRT
  12. // 28-Oct-94 ChuckC, rewritten.
  13. //
  14. //----------------------------------------------------------------------------
  15. //
  16. // System Includes
  17. //
  18. #define INC_OLE2
  19. #include <windows.h>
  20. //
  21. // CRunTime Includes
  22. //
  23. #include <stdlib.h>
  24. #include <limits.h>
  25. #include <io.h>
  26. #include <stdio.h>
  27. //
  28. // Public OleDs includes
  29. //
  30. //
  31. // Private defines
  32. //
  33. #define BAIL_ON_NULL(p) \
  34. if (!(p)) { \
  35. goto error; \
  36. }
  37. #define BAIL_ON_FAILURE(hr) \
  38. if (FAILED(hr)) { \
  39. goto error; \
  40. }
  41. #include "activeds.h"
  42. #include "main.hxx"
  43. //
  44. // Globals representing the parameters
  45. //
  46. LPWSTR pszTreeName, pszAttrList, pszAttrNames[10];
  47. DWORD dwNumberAttributes = -1;
  48. LPWSTR pszUserName=NULL, pszPassword=NULL;
  49. DWORD dwAuthFlags=0;
  50. //+---------------------------------------------------------------------------
  51. //
  52. // Function: main
  53. //
  54. // Synopsis:
  55. //
  56. //----------------------------------------------------------------------------
  57. INT _CRTAPI1
  58. main(int argc, char * argv[])
  59. {
  60. HRESULT hr=S_OK;
  61. IDirectorySchemaMgmt *pDSSchemaMgmt=NULL;
  62. DWORD dwAttributesReturned;
  63. PADS_ATTR_DEF pAttrDefinition;
  64. //
  65. // Sets the global variables with the parameters
  66. //
  67. hr = ProcessArgs(argc, argv);
  68. BAIL_ON_FAILURE(hr);
  69. hr = CoInitialize(NULL);
  70. if (FAILED(hr)) {
  71. printf("CoInitialize failed\n") ;
  72. return(1) ;
  73. }
  74. hr = ADsOpenObject(
  75. pszTreeName,
  76. pszUserName,
  77. pszPassword,
  78. dwAuthFlags,
  79. IID_IDirectorySchemaMgmt,
  80. (void **)&pDSSchemaMgmt
  81. );
  82. BAIL_ON_FAILURE(hr);
  83. pDSSchemaMgmt->EnumAttributes(
  84. pszAttrNames,
  85. dwNumberAttributes,
  86. &pAttrDefinition,
  87. &dwAttributesReturned
  88. );
  89. BAIL_ON_FAILURE(hr);
  90. PrintAttrDefinition(
  91. pAttrDefinition,
  92. dwAttributesReturned
  93. );
  94. if (pAttrDefinition)
  95. FreeADsMem(pAttrDefinition);
  96. FREE_INTERFACE(pDSSchemaMgmt);
  97. FREE_UNICODE_STRING(pszAttrList) ;
  98. CoUninitialize();
  99. return(0) ;
  100. error:
  101. FREE_INTERFACE(pDSSchemaMgmt);
  102. FREE_UNICODE_STRING(pszAttrList) ;
  103. FREE_UNICODE_STRING(pszUserName) ;
  104. FREE_UNICODE_STRING(pszPassword) ;
  105. wprintf (L"Error! hr = 0x%x\n", hr);
  106. return(1) ;
  107. }
  108. //+---------------------------------------------------------------------------
  109. //
  110. // Function: ProcessArgs
  111. //
  112. // Synopsis:
  113. //
  114. //----------------------------------------------------------------------------
  115. HRESULT
  116. ProcessArgs(
  117. int argc,
  118. char * argv[]
  119. )
  120. {
  121. argc--;
  122. int currArg = 1;
  123. LPWSTR pTemp;
  124. char *pszCurrPref, *pszCurrPrefValue;
  125. while (argc) {
  126. if (argv[currArg][0] != '/' && argv[currArg][0] != '-')
  127. BAIL_ON_FAILURE (E_FAIL);
  128. switch (argv[currArg][1]) {
  129. case 'b':
  130. argc--;
  131. currArg++;
  132. if (argc <= 0)
  133. BAIL_ON_FAILURE (E_FAIL);
  134. pszTreeName = AllocateUnicodeString(argv[currArg]);
  135. BAIL_ON_NULL(pszTreeName);
  136. break;
  137. case 'a':
  138. argc--;
  139. currArg++;
  140. if (argc <= 0)
  141. BAIL_ON_FAILURE(E_FAIL);
  142. pszAttrList = AllocateUnicodeString(argv[currArg]);
  143. BAIL_ON_NULL(pszAttrList);
  144. if (wcslen(pszAttrList) == 0)
  145. break;
  146. dwNumberAttributes = 0;
  147. pTemp = wcstok(pszAttrList, L",");
  148. pszAttrNames[dwNumberAttributes] = RemoveWhiteSpaces(pTemp);
  149. dwNumberAttributes++;
  150. while (pTemp) {
  151. pTemp = wcstok(NULL, L",");
  152. pszAttrNames[dwNumberAttributes] = RemoveWhiteSpaces(pTemp);
  153. dwNumberAttributes++;
  154. }
  155. dwNumberAttributes--;
  156. break;
  157. case 'u':
  158. argc--;
  159. currArg++;
  160. if (argc <= 0)
  161. BAIL_ON_FAILURE (E_FAIL);
  162. pszUserName = AllocateUnicodeString(argv[currArg]);
  163. BAIL_ON_NULL(pszUserName);
  164. argc--;
  165. currArg++;
  166. if (argc <= 0)
  167. BAIL_ON_FAILURE (E_FAIL);
  168. pszPassword = AllocateUnicodeString(argv[currArg]);
  169. BAIL_ON_NULL(pszPassword);
  170. break;
  171. case 't':
  172. argc--;
  173. currArg++;
  174. if (argc <= 0)
  175. BAIL_ON_FAILURE (E_FAIL);
  176. pszCurrPref = strtok(argv[currArg], "=");
  177. pszCurrPrefValue = strtok(NULL, "=");
  178. if (!pszCurrPref || !pszCurrPrefValue)
  179. BAIL_ON_FAILURE(E_FAIL);
  180. if (!_stricmp(pszCurrPref, "SecureAuth")) {
  181. if (!_stricmp(pszCurrPrefValue, "yes" ))
  182. dwAuthFlags |= ADS_SECURE_AUTHENTICATION;
  183. else if (!_stricmp(pszCurrPrefValue, "no" ))
  184. dwAuthFlags &= ~ADS_SECURE_AUTHENTICATION;
  185. else
  186. BAIL_ON_FAILURE(E_FAIL);
  187. }
  188. else if (!_stricmp(pszCurrPref, "UseEncrypt")) {
  189. if (!_stricmp(pszCurrPrefValue, "yes" ))
  190. dwAuthFlags |= ADS_USE_ENCRYPTION;
  191. else if (!_stricmp(pszCurrPrefValue, "no" ))
  192. dwAuthFlags &= ~ADS_USE_ENCRYPTION;
  193. else
  194. BAIL_ON_FAILURE(E_FAIL);
  195. }
  196. else
  197. BAIL_ON_FAILURE(E_FAIL);
  198. break;
  199. default:
  200. BAIL_ON_FAILURE(E_FAIL);
  201. }
  202. argc--;
  203. currArg++;
  204. }
  205. if (!pszTreeName) {
  206. BAIL_ON_FAILURE(E_FAIL);
  207. }
  208. if (dwNumberAttributes == 0) {
  209. //
  210. // Get all the attributes
  211. //
  212. dwNumberAttributes = -1;
  213. }
  214. return (S_OK);
  215. error:
  216. PrintUsage();
  217. return E_FAIL;
  218. }
  219. LPWSTR
  220. RemoveWhiteSpaces(
  221. LPWSTR pszText)
  222. {
  223. LPWSTR pChar;
  224. if(!pszText)
  225. return (pszText);
  226. while(*pszText && iswspace(*pszText))
  227. pszText++;
  228. for(pChar = pszText + wcslen(pszText) - 1; pChar >= pszText; pChar--) {
  229. if(!iswspace(*pChar))
  230. break;
  231. else
  232. *pChar = L'\0';
  233. }
  234. return pszText;
  235. }