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.

107 lines
2.5 KiB

  1. /*++
  2. DELEGTOOLS.C
  3. Copyright (C) 1998 Microsoft Corporation, all rights reserved.
  4. DESCRIPTION: tools required to support the delegation library
  5. Created, Dec 22, 1998 by DavidCHR.
  6. CONTENTS: ConnectAndBindToDefaultDsa
  7. --*/
  8. #pragma warning(disable:4057) /* indirection to slightly different
  9. base types. Useless warning that hits
  10. thousands of times in this file. */
  11. #pragma warning(disable:4221) /* allow nonstandard extension (automatic
  12. initialization of a variable with
  13. address of another automatic variable) */
  14. #include "unimacro.h"
  15. #include <nt.h>
  16. #include <ntrtl.h>
  17. #include <nturtl.h>
  18. #include <ntdef.h> // required to keep winbase.h from breaking
  19. #include <ntpoapi.h> // required to keep winbase.h from breaking
  20. #include <windows.h>
  21. #include <winbase.h>
  22. #include <lmaccess.h>
  23. #include <winldap.h>
  24. #include <tchar.h>
  25. #include <stdlib.h>
  26. #include <stdio.h>
  27. #include "delegtools.h"
  28. /*++**************************************************************
  29. NAME: ConnectAndBindToDefaultDsa
  30. does just what the function name says. We call the default
  31. DSA and bind to it. We then return the ldap handle
  32. MODIFIES: ppLdap -- PLDAP returned that describes the connection
  33. (now bound) to the DSA as requested
  34. TAKES: BindTarget -- target (domain name or DC name) passed to ldap_open
  35. RETURNS: TRUE when the function succeeds.
  36. FALSE otherwise.
  37. LASTERROR: not set.
  38. LOGGING: printf is called on failure
  39. CALLED BY: anyone
  40. FREE WITH: ldap_unbind
  41. **************************************************************--*/
  42. BOOL
  43. ConnectAndBindToDefaultDsa( IN OPTIONAL LPWSTR BindTarget,
  44. OUT PLDAP *ppLdap ) {
  45. PLDAP pLdap;
  46. DWORD dwErr = (DWORD) STATUS_INTERNAL_ERROR;
  47. pLdap = ldap_openW( BindTarget, LDAP_PORT );
  48. if ( pLdap ) {
  49. dwErr = ldap_bind_s( pLdap, NULL, NULL, LDAP_AUTH_NEGOTIATE );
  50. if ( dwErr == LDAP_SUCCESS ) {
  51. *ppLdap = pLdap;
  52. return TRUE;
  53. } else {
  54. printf( "FAIL: ldap_bind_s failed: 0x%x.\n",
  55. dwErr );
  56. SetLastError( dwErr );
  57. }
  58. /* note that there is no ldap_close-- we must unbind,
  59. even though we aren't actually bound. */
  60. ldap_unbind( pLdap );
  61. } else {
  62. // ldap_open() sets lastError on failure.
  63. printf( "FAIL: ldap_open failed for default server: 0x%x.\n",
  64. GetLastError() );
  65. }
  66. return FALSE;
  67. }