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.

613 lines
12 KiB

  1. #define GET_LDAPDN_FROM_PATH( pszPath ) (_tcschr( pszPath + 2, TEXT('\\')) + 1)
  2. //
  3. // Opening a connection
  4. //
  5. HRESULT LdapOpen(
  6. WCHAR *domainName,
  7. WCHAR *hostname,
  8. int portno,
  9. ADS_LDP *pld,
  10. DWORD dwFlags
  11. );
  12. //
  13. // Authenticating to the directory
  14. //
  15. HRESULT LdapBindS(
  16. ADS_LDP *ld,
  17. WCHAR *dn,
  18. WCHAR *passwd,
  19. BOOL fSimple
  20. );
  21. //
  22. // Closing the connection
  23. //
  24. HRESULT LdapUnbind(
  25. ADS_LDP *ld
  26. );
  27. //
  28. // Search
  29. //
  30. HRESULT LdapSearchS(
  31. ADS_LDP *ld,
  32. WCHAR *base,
  33. int scope,
  34. WCHAR *filter,
  35. WCHAR *attrs[],
  36. int attrsonly,
  37. LDAPMessage **res
  38. );
  39. HRESULT LdapSearchST(
  40. ADS_LDP *ld,
  41. WCHAR *base,
  42. int scope,
  43. WCHAR *filter,
  44. WCHAR *attrs[],
  45. int attrsonly,
  46. struct l_timeval *timeout,
  47. LDAPMessage **res
  48. );
  49. HRESULT LdapSearch(
  50. ADS_LDP *ld,
  51. WCHAR *base,
  52. int scope,
  53. WCHAR *filter,
  54. WCHAR *attrs[],
  55. int attrsonly,
  56. int *msgid
  57. );
  58. //
  59. // Modifying an entry
  60. //
  61. HRESULT LdapModifyS(
  62. ADS_LDP *ld,
  63. WCHAR *dn,
  64. LDAPModW *mods[]
  65. );
  66. //
  67. // Modifying the RDN of an entry
  68. //
  69. HRESULT LdapModRdnS(
  70. ADS_LDP *ld,
  71. WCHAR *dn,
  72. WCHAR *newrdn
  73. );
  74. //
  75. // Modifying the DN of an entry
  76. //
  77. HRESULT LdapModDnS(
  78. ADS_LDP *ld,
  79. WCHAR *dn,
  80. WCHAR *newdn,
  81. int deleteoldrdn
  82. );
  83. //
  84. // Adding an entry
  85. //
  86. HRESULT LdapAddS(
  87. ADS_LDP *ld,
  88. WCHAR *dn,
  89. LDAPModW *attrs[]
  90. );
  91. //
  92. // Adding an entry with controls
  93. //
  94. HRESULT LdapAddExtS(
  95. ADS_LDP *ld,
  96. WCHAR *dn,
  97. LDAPModW *attrs[],
  98. PLDAPControlW * ServerControls,
  99. PLDAPControlW *ClientControls
  100. );
  101. //
  102. // Deleting an entry
  103. //
  104. HRESULT LdapDeleteS(
  105. ADS_LDP *ld,
  106. WCHAR *dn
  107. );
  108. //
  109. // Calls for abandoning an operation
  110. //
  111. HRESULT LdapAbandon(
  112. ADS_LDP *ld,
  113. int msgid
  114. );
  115. //
  116. // Calls for obtaining results
  117. //
  118. HRESULT LdapResult(
  119. ADS_LDP *ld,
  120. int msgid,
  121. int all,
  122. struct l_timeval *timeout,
  123. LDAPMessage **res,
  124. int *restype
  125. );
  126. void LdapMsgFree(
  127. LDAPMessage *res
  128. );
  129. //
  130. // Calls for error handling
  131. //
  132. int LdapResult2Error(
  133. ADS_LDP *ld,
  134. LDAPMessage *res,
  135. int freeit
  136. );
  137. int LdapError2String(
  138. int err,
  139. WCHAR **pszError
  140. );
  141. //
  142. // Calls for parsing search entries
  143. //
  144. HRESULT LdapFirstEntry(
  145. ADS_LDP *ld,
  146. LDAPMessage *res,
  147. LDAPMessage **pfirst
  148. );
  149. HRESULT LdapNextEntry(
  150. ADS_LDP *ld,
  151. LDAPMessage *entry,
  152. LDAPMessage **pnext
  153. );
  154. int LdapCountEntries(
  155. ADS_LDP *ld,
  156. LDAPMessage *res
  157. );
  158. HRESULT LdapFirstAttribute(
  159. ADS_LDP *ld,
  160. LDAPMessage *entry,
  161. void **ptr,
  162. WCHAR **pattr
  163. );
  164. HRESULT LdapNextAttribute(
  165. ADS_LDP *ld,
  166. LDAPMessage *entry,
  167. void *ptr,
  168. WCHAR **pattr
  169. );
  170. HRESULT LdapGetValues(
  171. ADS_LDP *ld,
  172. LDAPMessage *entry,
  173. WCHAR *attr,
  174. WCHAR ***pvalues,
  175. int *pcount
  176. );
  177. HRESULT LdapGetValuesLen(
  178. ADS_LDP *ld,
  179. LDAPMessage *entry,
  180. WCHAR *attr,
  181. struct berval ***pvalues,
  182. int *pcount
  183. );
  184. void LdapValueFree(
  185. WCHAR **vals
  186. );
  187. void LdapValueFreeLen(
  188. struct berval **vals
  189. );
  190. void LdapMemFree(
  191. WCHAR *pszString
  192. );
  193. void LdapAttributeFree(
  194. WCHAR *pszString
  195. );
  196. HRESULT LdapGetDn(
  197. ADS_LDP *ld,
  198. LDAPMessage *entry,
  199. WCHAR **pdn
  200. );
  201. //
  202. // Misc
  203. //
  204. HRESULT LdapOpenObject(
  205. LPWSTR szLDAPServer,
  206. LPWSTR szLDAPDn,
  207. ADS_LDP **ld,
  208. CCredentials& Credentials,
  209. DWORD dwPort
  210. );
  211. HRESULT LdapOpenObject2(
  212. LPWSTR szDomainName,
  213. LPWSTR szLDAPServer,
  214. LPWSTR szLDAPDn,
  215. ADS_LDP **ld,
  216. CCredentials& Credentials,
  217. DWORD dwPort
  218. );
  219. void LdapCloseObject(
  220. ADS_LDP *ld
  221. );
  222. void LdapCacheAddRef(
  223. ADS_LDP *ld
  224. );
  225. HRESULT LdapReadAttribute(
  226. WCHAR *szLDAPPath,
  227. LPWSTR szLDAPDn,
  228. WCHAR *szAttr,
  229. WCHAR ***aValues,
  230. int *nCount,
  231. CCredentials& Credentials,
  232. DWORD dwPort
  233. );
  234. HRESULT LdapReadAttribute2(
  235. WCHAR *szDomainName,
  236. WCHAR *szServerName,
  237. LPWSTR szLDAPDn,
  238. WCHAR *szAttr,
  239. WCHAR ***aValues,
  240. int *nCount,
  241. CCredentials& Credentials,
  242. DWORD dwPort,
  243. LPWSTR szfilter = NULL // defaulted to NULL
  244. );
  245. // Fast version of read attribute
  246. // uses the already open handle instead
  247. // of going through LDAPOpenObject
  248. HRESULT LdapReadAttributeFast(
  249. IN ADS_LDP *ld,
  250. IN LPWSTR szLDAPDn,
  251. IN WCHAR *szAttr,
  252. OUT WCHAR ***aValues,
  253. IN OUT int *nCount
  254. );
  255. int ConvertToUnicode(
  256. char *pszAscii,
  257. WCHAR **pszUnicode
  258. );
  259. void
  260. LdapGetCredentialsFromRegistry(
  261. CCredentials& Credentials
  262. );
  263. HRESULT
  264. LdapOpenBindWithDefaultCredentials(
  265. WCHAR *szDomainName,
  266. WCHAR *szServerName,
  267. CCredentials& Credentials,
  268. PADS_LDP pCacheEntry,
  269. DWORD dwPort
  270. );
  271. HRESULT
  272. LdapOpenBindWithDefaultCredentials(
  273. WCHAR *szDomainName,
  274. WCHAR *szServerName,
  275. CCredentials& Credentials,
  276. PADS_LDP pCacheEntry,
  277. DWORD dwPort
  278. );
  279. HRESULT
  280. LdapOpenBindWithCredentials(
  281. WCHAR *szServerName,
  282. CCredentials& Credentials,
  283. PADS_LDP pCacheEntry,
  284. DWORD dwPort
  285. );
  286. HRESULT
  287. LdapOpenBindWithCredentials(
  288. WCHAR *szDomainName,
  289. WCHAR *szServerName,
  290. CCredentials& Credentials,
  291. PADS_LDP pCacheEntry,
  292. DWORD dwPort
  293. );
  294. HRESULT
  295. LdapCrackUserDNtoNTLMUser(
  296. LPWSTR pszDN,
  297. LPWSTR * ppszNTLMUser,
  298. LPWSTR * ppszNTLMDomain
  299. );
  300. //
  301. // Handle domain\user case properly
  302. //
  303. HRESULT
  304. LdapCrackUserDNtoNTLMUser2(
  305. IN LPWSTR pszDN,
  306. OUT LPWSTR * ppszNTLMUser,
  307. OUT LPWSTR * ppszNTLMDomain
  308. );
  309. VOID
  310. CheckAndSetExtendedError(
  311. LDAP *ld,
  312. HRESULT *perr,
  313. int ldaperr,
  314. LDAPMessage *ldapResMsg = NULL
  315. );
  316. BOOL LdapConnectionErr(
  317. int err,
  318. int ldaperr,
  319. BOOL *fTryRebind
  320. );
  321. HRESULT LdapSearchExtS(
  322. ADS_LDP *ld,
  323. WCHAR *base,
  324. int scope,
  325. WCHAR *filter,
  326. WCHAR *attrs[],
  327. int attrsonly,
  328. PLDAPControlW * ServerControls,
  329. PLDAPControlW *ClientControls,
  330. struct l_timeval *timeout,
  331. ULONG SizeLimit,
  332. LDAPMessage **res
  333. );
  334. HRESULT LdapSearchExt(
  335. ADS_LDP *ld,
  336. WCHAR *base,
  337. int scope,
  338. WCHAR *filter,
  339. WCHAR *attrs[],
  340. int attrsonly,
  341. PLDAPControlW *ServerControls,
  342. PLDAPControlW *ClientControls,
  343. ULONG TimeLimit,
  344. ULONG SizeLimit,
  345. ULONG *MessageNumber
  346. );
  347. ULONG _cdecl QueryForConnection(
  348. PLDAP PrimaryConnection,
  349. PLDAP ReferralFromConnection,
  350. PWCHAR NewDN,
  351. PCHAR HostName,
  352. ULONG PortNumber,
  353. PVOID SecAuthIdentity, // if null, use CurrentUser below
  354. PVOID CurrentUserToken, // pointer to current user's LUID
  355. PLDAP *ConnectionToUse
  356. );
  357. BOOLEAN _cdecl NotifyNewConnection(
  358. PLDAP PrimaryConnection,
  359. PLDAP ReferralFromConnection,
  360. PWCHAR NewDN,
  361. PCHAR HostName,
  362. PLDAP NewConnection,
  363. ULONG PortNumber,
  364. PVOID SecAuthIdentity, // if null, use CurrentUser below
  365. PVOID CurrentUser, // pointer to current user's LUID
  366. ULONG ErrorCodeFromBind
  367. );
  368. ULONG _cdecl DereferenceConnection(
  369. PLDAP PrimaryConnection,
  370. PLDAP ConnectionToDereference
  371. );
  372. HRESULT LdapSearchInitPage(
  373. ADS_LDP *ld,
  374. PWCHAR base,
  375. ULONG scope,
  376. PWCHAR filter,
  377. PWCHAR attrs[],
  378. ULONG attrsonly,
  379. PLDAPControlW *serverControls,
  380. PLDAPControlW *clientControls,
  381. ULONG pageSizeLimit,
  382. ULONG totalSizeLimit,
  383. PLDAPSortKeyW *sortKeys,
  384. PLDAPSearch *ppSearch
  385. );
  386. HRESULT LdapGetNextPage(
  387. ADS_LDP *ld,
  388. PLDAPSearch searchHandle,
  389. ULONG pageSize,
  390. ULONG *pMessageNumber
  391. );
  392. HRESULT LdapGetNextPageS(
  393. ADS_LDP *ld,
  394. PLDAPSearch searchHandle,
  395. struct l_timeval *timeout,
  396. ULONG pageSize,
  397. ULONG *totalCount,
  398. LDAPMessage **results
  399. );
  400. HRESULT LdapGetPagedCount(
  401. ADS_LDP *ld,
  402. PLDAPSearch searchBlock,
  403. ULONG *totalCount,
  404. PLDAPMessage results
  405. );
  406. HRESULT LdapSearchAbandonPage(
  407. ADS_LDP *ld,
  408. PLDAPSearch searchBlock
  409. );
  410. HRESULT LdapEncodeSortControl(
  411. ADS_LDP *ld,
  412. PLDAPSortKeyW *SortKeys,
  413. PLDAPControlW Control,
  414. BOOLEAN Criticality
  415. );
  416. BOOL IsGCNamespace(
  417. LPWSTR szADsPath
  418. );
  419. HRESULT LdapModifyExtS(
  420. ADS_LDP *ld,
  421. WCHAR *dn,
  422. LDAPModW *mods[],
  423. PLDAPControlW * ServerControls,
  424. PLDAPControlW * ClientControls
  425. );
  426. HRESULT LdapDeleteExtS(
  427. ADS_LDP *ld,
  428. WCHAR *dn,
  429. PLDAPControlW * ServerControls,
  430. PLDAPControlW * ClientControls
  431. );
  432. //
  433. // Extnded rename/move operation which will move objects across namesapces
  434. //
  435. HRESULT LdapRenameExtS(
  436. ADS_LDP *ld,
  437. WCHAR *dn,
  438. WCHAR *newRDN,
  439. WCHAR *newParent,
  440. int deleteOldRDN,
  441. PLDAPControlW * ServerControls,
  442. PLDAPControlW * ClientControls
  443. );
  444. HRESULT LdapCreatePageControl(
  445. ADS_LDP *ld,
  446. ULONG dwPageSize,
  447. struct berval *Cookie,
  448. BOOL fIsCritical,
  449. PLDAPControl *Control // Use LdapControlFree to free
  450. );
  451. HRESULT LdapParsePageControl(
  452. ADS_LDP *ld,
  453. PLDAPControl *ServerControls,
  454. ULONG *TotalCount,
  455. struct berval **Cookie // Use BerBvFree to free
  456. );
  457. HRESULT LdapCreateVLVControl(
  458. ADS_LDP *pld,
  459. PLDAPVLVInfo pVLVInfo,
  460. UCHAR fCritical,
  461. PLDAPControl *ppControl // Use LdapControlFree to free
  462. );
  463. HRESULT LdapParseVLVControl(
  464. ADS_LDP *pld,
  465. PLDAPControl *ppServerControls,
  466. ULONG *pTargetPos,
  467. ULONG *pListCount,
  468. struct berval **ppCookie // Use BerBvFree to free
  469. );
  470. HRESULT LdapParseResult(
  471. ADS_LDP *ld,
  472. LDAPMessage *ResultMessage,
  473. ULONG *ReturnCode OPTIONAL, // returned by server
  474. PWCHAR *MatchedDNs OPTIONAL, // free with LdapMemFree
  475. PWCHAR *ErrorMessage OPTIONAL, // free with LdapMemFree
  476. PWCHAR **Referrals OPTIONAL, // free with LdapValueFree
  477. PLDAPControlW **ServerControls OPTIONAL, // free with LdapFreeControls
  478. BOOL Freeit
  479. );
  480. //
  481. // Wrapper API for ldap_compare_extsW
  482. //
  483. HRESULT
  484. LdapCompareExt(
  485. ADS_LDP *ld,
  486. const LPWSTR pszDn,
  487. const LPWSTR pszAttribute,
  488. const LPWSTR pszValue,
  489. struct berval *berData = NULL,
  490. PLDAPControlW * ServerControls = NULL,
  491. PLDAPControlW * ClientControls = NULL
  492. );
  493. void
  494. LdapControlsFree(
  495. PLDAPControl *ppControl
  496. );
  497. void
  498. LdapControlFree(
  499. PLDAPControl pControl
  500. );
  501. void
  502. BerBvFree(
  503. struct berval *bv
  504. );
  505. HRESULT
  506. LdapcSetStickyServer(
  507. LPWSTR pszDomainName,
  508. LPWSTR pszServerName
  509. );
  510. // Keeps track of global name to try first for severless case.
  511. // If domainName is also set, then server is used for the
  512. // domain specified.
  513. extern LPWSTR gpszServerName;
  514. extern LPWSTR gpszDomainName;