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.

278 lines
7.0 KiB

  1. /***
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. Search.c
  5. Abstract:
  6. Command line test tool for testing the NDS Search API.
  7. Author:
  8. Glenn Curtis [glennc] 22-Apr-96
  9. ***/
  10. #include <utils.c>
  11. int
  12. _cdecl main( int argc, char **argv )
  13. {
  14. DWORD status = NO_ERROR;
  15. HANDLE hObject;
  16. OEM_STRING OemArg;
  17. UNICODE_STRING ObjectName;
  18. WCHAR szObjectName[256];
  19. WCHAR szTempName[256];
  20. WCHAR szTempAttrName[256];
  21. WCHAR szSubjectName[256];
  22. WCHAR szAttributeName[256];
  23. DWORD dwRights;
  24. ASN1_TYPE_20 Asn1_20;
  25. ASN1_TYPE_22 Asn1_22;
  26. WCHAR szText[256];
  27. LPQUERY_NODE lpNode1;
  28. LPQUERY_NODE lpNode2;
  29. LPQUERY_NODE lpNode3;
  30. LPQUERY_NODE lpNode4;
  31. HANDLE hOperationData = NULL;
  32. DWORD NumberOfObjects;
  33. DWORD InformationType;
  34. DWORD dwIterHandle = NDS_INITIAL_SEARCH;
  35. LPNDS_OBJECT_INFO lpObjects;
  36. Asn1_20.ClassName = szText;
  37. ObjectName.Length = 0;
  38. ObjectName.MaximumLength = sizeof( szObjectName );
  39. ObjectName.Buffer = szObjectName;
  40. //
  41. // Check the arguments.
  42. //
  43. if ( argc != 2 )
  44. {
  45. Usage:
  46. printf( "\nUsage: Search <Path to object to start search from>\n" );
  47. printf( " where: Path = \\\\<tree name>\\<Object distiguished name>\n" );
  48. return -1;
  49. }
  50. OemArg.Length = strlen( argv[1] );
  51. OemArg.MaximumLength = OemArg.Length;
  52. OemArg.Buffer = argv[1];
  53. RtlOemStringToUnicodeString( &ObjectName, &OemArg, FALSE );
  54. status = NwNdsOpenObject( ObjectName.Buffer,
  55. NULL,
  56. NULL,
  57. &hObject,
  58. NULL,
  59. NULL,
  60. NULL,
  61. NULL,
  62. NULL );
  63. if ( status )
  64. {
  65. printf( "\nError: NwNdsOpenObject returned status 0x%.8X\n", status );
  66. printf( "Error: GetLastError returned: 0x%.8X\n\n",
  67. GetLastError() );
  68. return -1;
  69. }
  70. //
  71. // "Object Class" == "User"
  72. //
  73. wcscpy( Asn1_20.ClassName, NDS_CLASS_USER );
  74. status = NwNdsCreateQueryNode( NDS_QUERY_EQUAL,
  75. NDS_OBJECT_CLASS,
  76. &Asn1_20,
  77. &lpNode1 );
  78. if ( status )
  79. {
  80. printf( "\nError: NwNdsCreateQueryNode returned status 0x%.8X\n", status );
  81. printf( "Error: GetLastError returned: 0x%.8X\n\n",
  82. GetLastError() );
  83. return -1;
  84. }
  85. //
  86. // "Telephone Number" attribute present
  87. //
  88. status = NwNdsCreateQueryNode( NDS_QUERY_PRESENT,
  89. L"Telephone Number",
  90. 0,
  91. NULL,
  92. &lpNode2 );
  93. if ( status )
  94. {
  95. printf( "\nError: NwNdsCreateQueryNode returned status 0x%.8X\n", status );
  96. printf( "Error: GetLastError returned: 0x%.8X\n\n",
  97. GetLastError() );
  98. return -1;
  99. }
  100. //
  101. // NOT lpNode2
  102. //
  103. status = NwNdsCreateQueryNode( NDS_QUERY_NOT,
  104. lpNode2,
  105. 0,
  106. NULL,
  107. &lpNode3 );
  108. if ( status )
  109. {
  110. printf( "\nError: NwNdsCreateQueryNode returned status 0x%.8X\n", status );
  111. printf( "Error: GetLastError returned: 0x%.8X\n\n",
  112. GetLastError() );
  113. return -1;
  114. }
  115. //
  116. // lpNode1 AND lpNode3
  117. //
  118. status = NwNdsCreateQueryNode( NDS_QUERY_AND,
  119. lpNode1,
  120. 0,
  121. lpNode3,
  122. &lpNode4 );
  123. if ( status )
  124. {
  125. printf( "\nError: NwNdsCreateQueryNode returned status 0x%.8X\n", status );
  126. printf( "Error: GetLastError returned: 0x%.8X\n\n",
  127. GetLastError() );
  128. return -1;
  129. }
  130. status = NwNdsCreateBuffer( NDS_SEARCH,
  131. &hOperationData );
  132. if ( status )
  133. {
  134. printf( "\nError: NwNdsCreateBuffer returned status 0x%.8X\n", status );
  135. printf( "Error: GetLastError returned: 0x%.8X\n\n", GetLastError() );
  136. return -1;
  137. }
  138. do
  139. {
  140. printf( "\nEnter attribute name or <Enter> to end : " );
  141. GetStringOrDefault( szTempAttrName, L"" );
  142. if ( wcslen(szTempAttrName) > 0 )
  143. {
  144. status = NwNdsPutInBuffer( szTempAttrName,
  145. 0,
  146. NULL,
  147. 0,
  148. 0,
  149. hOperationData );
  150. if ( status )
  151. {
  152. printf( "\nError: NwNdsPutInBuffer returned status 0x%.8X\n",
  153. status );
  154. printf( "Error: GetLastError returned: 0x%.8X\n\n",
  155. GetLastError() );
  156. return -1;
  157. }
  158. }
  159. } while ( wcslen(szTempAttrName) > 0 );
  160. SearchLoop :
  161. status = NwNdsSearch( hObject,
  162. NDS_INFO_ATTR_NAMES_VALUES,
  163. FALSE, // Search subtree
  164. FALSE, // Deref aliases
  165. lpNode4,
  166. &dwIterHandle,
  167. &hOperationData );
  168. if ( status )
  169. {
  170. printf( "\nError: NwNdsSearch returned status 0x%.8X\n", status );
  171. printf( "Error: GetLastError returned: 0x%.8X\n\n",
  172. GetLastError() );
  173. return -1;
  174. }
  175. NwNdsGetObjectListFromBuffer( hOperationData,
  176. &NumberOfObjects,
  177. &InformationType,
  178. &lpObjects );
  179. printf( "-- Calling NwNdsGetObjectListFromBuffer returned %ld objects.\n",
  180. NumberOfObjects );
  181. DumpObjectsToConsole( NumberOfObjects, InformationType, lpObjects );
  182. if ( dwIterHandle != NDS_NO_MORE_ITERATIONS )
  183. {
  184. goto SearchLoop;
  185. }
  186. status = NwNdsDeleteQueryTree( lpNode4 );
  187. if ( status )
  188. {
  189. printf( "\nError: NwNdsDeleteQueryTree returned status 0x%.8X\n",
  190. status );
  191. printf( "Error: GetLastError returned: 0x%.8X\n\n",
  192. GetLastError() );
  193. return -1;
  194. }
  195. status = NwNdsCloseObject( hObject );
  196. if ( status )
  197. {
  198. printf( "\nError: NwNdsCloseObject returned status 0x%.8X\n", status );
  199. printf( "Error: GetLastError returned: 0x%.8X\n\n",
  200. GetLastError() );
  201. return -1;
  202. }
  203. status = NwNdsFreeBuffer( hOperationData );
  204. if ( status )
  205. {
  206. printf( "\nError: NwNdsFreeBuffer returned status 0x%.8X\n", status );
  207. printf( "Error: GetLastError returned: 0x%.8X\n\n",
  208. GetLastError() );
  209. return -1;
  210. }
  211. }