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.

318 lines
6.0 KiB

  1. /*--------------------------------------------------------------------------
  2. at.cpp
  3. ldap add/modify/etc test
  4. Copyright (C) 1996 Microsoft Corporation
  5. All rights reserved.
  6. Authors:
  7. davidsan Dave Sanderman
  8. History:
  9. 04/25/96 davidsan Created.
  10. --------------------------------------------------------------------------*/
  11. #include "at.h"
  12. PLCLI g_plcli = NULL;
  13. BOOL
  14. FInit()
  15. {
  16. return TRUE;
  17. }
  18. BOOL
  19. FConnect(char *szServer)
  20. {
  21. HRESULT hr;
  22. XID xid;
  23. hr = HrCreateLdapClient(LDAP_VER_CURRENT, INTERFACE_VER_CURRENT, &g_plcli);
  24. if (FAILED(hr))
  25. {
  26. printf("HrCreateLdapClient returned %08X\n", hr);
  27. return FALSE;
  28. }
  29. hr = g_plcli->HrConnect(szServer);
  30. if (FAILED(hr))
  31. {
  32. printf("HrConnect returned %08X\n", hr);
  33. return FALSE;
  34. }
  35. //$ figure out bind name
  36. hr = g_plcli->HrBindSimple("[email protected], c=us", NULL, &xid);
  37. if (FAILED(hr))
  38. {
  39. printf("HrBindSimple returned %08X\n", hr);
  40. return FALSE;
  41. }
  42. hr = g_plcli->HrGetBindResponse(xid, INFINITE);
  43. if (FAILED(hr))
  44. {
  45. printf("HrBindSimple returned %08X\n", hr);
  46. return FALSE;
  47. }
  48. return TRUE;
  49. }
  50. char *g_rgszAttrib[] = {"title", "cn", "sn", "objectClass"};
  51. BOOL
  52. FSearch()
  53. {
  54. HRESULT hr;
  55. XID xid;
  56. POBJ pobj;
  57. POBJ pobjT;
  58. PATTR pattr;
  59. PVAL pval;
  60. SP sp;
  61. FILTER filter;
  62. FILTER filterS1;
  63. FILTER filterS2;
  64. FILTER filterSS1;
  65. FILTER filterSS2;
  66. FILTER filterSS3;
  67. #ifdef OLDSEARCH
  68. filter.type = LDAP_FILTER_AND;
  69. filter.pfilterSub = &filterS1;
  70. filterS1.type = LDAP_FILTER_OR;
  71. filterS1.pfilterSub = &filterSS1;
  72. filterS1.pfilterNext = &filterS2;
  73. filterSS1.type = LDAP_FILTER_EQUALITY;
  74. filterSS1.ava.szAttrib = "cn";
  75. filterSS1.ava.szValue = "sander";
  76. filterSS1.pfilterNext = &filterSS2;
  77. filterSS2.type = LDAP_FILTER_EQUALITY;
  78. filterSS2.ava.szAttrib = "sn";
  79. filterSS2.ava.szValue = "sander";
  80. filterSS2.pfilterNext = &filterSS3;
  81. filterSS3.type = LDAP_FILTER_EQUALITY;
  82. filterSS3.ava.szAttrib = "uid";
  83. filterSS3.ava.szValue = "sander";
  84. filterSS3.pfilterNext = NULL;
  85. filterS2.type = LDAP_FILTER_EQUALITY;
  86. filterS2.ava.szAttrib = "objectClass";
  87. filterS2.ava.szValue = "Person";
  88. filterS2.pfilterNext = NULL;
  89. #else
  90. // filter.type = LDAP_FILTER_SUBSTRINGS;
  91. // filter.sub.szAttrib = "cn";
  92. // filter.sub.szInitial = NULL;
  93. // filter.sub.szAny = "alex";
  94. // filter.sub.szFinal = NULL;
  95. filter.type = LDAP_FILTER_EQUALITY;
  96. filter.ava.szAttrib = "cn";
  97. filter.ava.szValue = "davidsan2";
  98. #endif
  99. sp.szDNBase = "c=US";
  100. sp.scope = LDAP_SCOPE_WHOLESUBTREE;
  101. sp.deref = LDAP_DEREF_ALWAYS;
  102. sp.cRecordsMax = 0;
  103. sp.cSecondsMax = 0;
  104. sp.fAttrsOnly = FALSE;
  105. sp.pfilter = &filter;
  106. sp.cAttrib = 4;
  107. sp.rgszAttrib = g_rgszAttrib;
  108. hr = g_plcli->HrSearch(&sp, &xid);
  109. if (FAILED(hr))
  110. {
  111. printf("HrSearch returned %08X\n", hr);
  112. return FALSE;
  113. }
  114. hr = g_plcli->HrGetSearchResponse(xid, INFINITE, &pobj);
  115. if (FAILED(hr))
  116. {
  117. printf("HrGetSearchResponse returned %08X\n", hr);
  118. return FALSE;
  119. }
  120. pobjT = pobj;
  121. while (pobjT)
  122. {
  123. printf("OBJ: %s\n", pobjT->szDN);
  124. pattr = pobjT->pattrFirst;
  125. while (pattr)
  126. {
  127. printf(" ATTR: %s\n", pattr->szAttrib);
  128. pval = pattr->pvalFirst;
  129. while (pval)
  130. {
  131. printf(" VAL: %s\n", pval->szVal);
  132. pval = pval->pvalNext;
  133. }
  134. pattr = pattr->pattrNext;
  135. }
  136. pobjT = pobjT->pobjNext;
  137. }
  138. g_plcli->HrFreePobjList(pobj);
  139. return TRUE;
  140. }
  141. void
  142. SetPattr(PATTR pattr, PATTR pattrNext, char *szAttrib, PVAL pval)
  143. {
  144. pattr->pattrNext = pattrNext;
  145. pattr->szAttrib = szAttrib;
  146. pattr->pvalFirst = pval;
  147. }
  148. void
  149. SetPval(PVAL pval, PVAL pvalNext, char *szVal)
  150. {
  151. pval->pvalNext = pvalNext;
  152. pval->szVal = szVal;
  153. }
  154. BOOL
  155. FTestOtherStuff()
  156. {
  157. HRESULT hr;
  158. XID xid;
  159. #ifdef TEST_MODIFY
  160. MOD mod;
  161. ATTR attr;
  162. VAL val;
  163. mod.pmodNext = NULL;
  164. mod.modop = LDAP_MODIFY_REPLACE;
  165. mod.pattrFirst = &attr;
  166. attr.pattrNext = NULL;
  167. attr.szAttrib = "URL";
  168. attr.pvalFirst = &val;
  169. val.pvalNext = NULL;
  170. val.szVal = "http://bite.me.com/";
  171. hr = g_plcli->HrModify("c=us, [email protected]", &mod, &xid);
  172. if (FAILED(hr))
  173. {
  174. printf("HrModify returned %08X\n", hr);
  175. return FALSE;
  176. }
  177. hr = g_plcli->HrGetModifyResponse(xid, INFINITE);
  178. if (FAILED(hr))
  179. {
  180. printf("HrGetModifyResponse returned %08X\n", hr);
  181. }
  182. #endif // TEST_MODIFY
  183. #define TEST_ADD
  184. #ifdef TEST_ADD
  185. ATTR attr1;
  186. ATTR attr2;
  187. ATTR attr3;
  188. ATTR attr4;
  189. ATTR attr5;
  190. VAL val1;
  191. VAL val2;
  192. VAL val3;
  193. VAL val4;
  194. VAL val5;
  195. attr1.pattrNext = &attr2;
  196. attr1.szAttrib = "c";
  197. attr1.pvalFirst = &val1;
  198. attr2.pattrNext = &attr3;
  199. attr2.szAttrib = "sn";
  200. attr2.pvalFirst = &val2;
  201. attr3.pattrNext = &attr4;
  202. attr3.szAttrib = "givenName";
  203. attr3.pvalFirst = &val3;
  204. attr4.pattrNext = &attr5;
  205. attr4.szAttrib = "rfc822Mailbox";
  206. attr4.pvalFirst = &val4;
  207. attr5.pattrNext = NULL;
  208. attr5.szAttrib = "objectClass";
  209. attr5.pvalFirst = &val5;
  210. val1.pvalNext = NULL;
  211. val1.szVal = "us";
  212. val2.pvalNext = NULL;
  213. val2.szVal = "sanderman";
  214. val3.pvalNext = NULL;
  215. val3.szVal = "david";
  216. val4.pvalNext = NULL;
  217. val4.szVal = "[email protected]";
  218. val5.pvalNext = NULL;
  219. val5.szVal = "Person";
  220. hr = g_plcli->HrAdd("c=us, [email protected]", &attr1, &xid);
  221. if (FAILED(hr))
  222. {
  223. printf("HrAdd returned %08X\n", hr);
  224. return FALSE;
  225. }
  226. hr = g_plcli->HrGetAddResponse(xid, INFINITE);
  227. if (FAILED(hr))
  228. {
  229. printf("HrGetAddResponse returned %08X\n", hr);
  230. }
  231. #endif
  232. return TRUE;
  233. }
  234. BOOL
  235. FTerm()
  236. {
  237. if (g_plcli)
  238. {
  239. g_plcli->HrUnbind();
  240. if (g_plcli->HrIsConnected() == NOERROR)
  241. g_plcli->HrDisconnect();
  242. g_plcli->Release();
  243. }
  244. return TRUE;
  245. }
  246. void
  247. usage()
  248. {
  249. printf("usage: lt <server>\n");
  250. exit(1);
  251. }
  252. void __cdecl
  253. main(int argc, char **argv)
  254. {
  255. if (argc < 2)
  256. usage();
  257. if (!FInit())
  258. exit(1);
  259. if (!FConnect(argv[1]))
  260. exit(1);
  261. FSearch();
  262. FTestOtherStuff();
  263. FTerm();
  264. exit(0);
  265. }