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.

184 lines
6.5 KiB

  1. //================================================================================
  2. // Copyright (C) 1997 Microsoft Corporation
  3. // Author: RameshV
  4. // Description: common headers for dhcp ds stuff.. used by both the core <store>
  5. // and by the dhcp-ds implementation..
  6. //================================================================================
  7. #define INC_OLE2
  8. #include <mm/mm.h>
  9. #include <mm/array.h>
  10. #include <activeds.h>
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include <align.h>
  14. #include <lmcons.h>
  15. #include <netlib.h>
  16. #include <lmapibuf.h>
  17. #include <dsgetdc.h>
  18. #include <dnsapi.h>
  19. #include <adsi.h>
  20. //================================================================================
  21. // defines and constants
  22. //================================================================================
  23. #define DHCP_OBJECTS_LOCATION L"CN=NetServices,CN=Services"
  24. #define DHCP_SEARCH_FILTER L"(objectClass=dHCPClass)"
  25. #define DHCP_ADDRESS_ATTRIB L"ipAddress"
  26. // global attribute names
  27. #define ATTRIB_NAME L"name"
  28. #define ATTRIB_DN_NAME L"cn"
  29. #define ATTRIB_INSTANCE_TYPE L"instanceType"
  30. // dhcp only attribute names
  31. #define ATTRIB_IPADDR_OBSOLETE L"IPAddress"
  32. #define ATTRIB_DHCP_UNIQUE_KEY L"dhcpUniqueKey"
  33. #define ATTRIB_DHCP_TYPE L"dhcpType"
  34. #define ATTRIB_DHCP_IDENTIFICATION L"dhcpIdentification"
  35. #define ATTRIB_DHCP_FLAGS L"dhcpFlags"
  36. #define ATTRIB_OBJECT_CLASS L"objectClass"
  37. #define ATTRIB_OBJECT_CATEGORY L"objectCategory"
  38. #define ATTRIB_DHCP_SERVERS L"dhcpServers"
  39. #define ATTRIB_DHCP_OPTIONS L"dhcpOptions"
  40. // default attribute values
  41. #define DEFAULT_DHCP_CLASS_ATTRIB_VALUE L"dHCPClass"
  42. #define DEFAULT_INSTANCE_TYPE_ATTRIB_VALUE 4
  43. //================================================================================
  44. // defines and constants
  45. //================================================================================
  46. #define DEFAULT_LDAP_ROOTDSE L"LDAP://ROOTDSE"
  47. #define LDAP_PREFIX L"LDAP://"
  48. #define ROOTDSE_POSTFIX L"/ROOTDSE"
  49. #define ENT_ROOT_PREFIX L"CN=Configuration"
  50. #define CONNECTOR L","
  51. #define LDAP_JOIN L"="
  52. #define ENT_ROOT_PREFIX_LEN 16
  53. // other stuff
  54. #define Investigate Require
  55. #define ALIGN(X) ((X) = ROUND_UP_COUNT((X), ALIGN_WORST))
  56. #if 0
  57. #define DhcpDsDbgPrint printf
  58. #define StoreTrace2 printf
  59. #define StoreTrace3 printf
  60. #else
  61. #define DhcpDsDbgPrint (void)
  62. #define StoreTrace2 (void)
  63. #define StoreTrace3 (void)
  64. #endif
  65. static const
  66. LPWSTR constNamingContextString = L"configurationNamingContext";
  67. static const // cn is NOT mandatory..what is?
  68. LPWSTR constCNAttrib = L"cn"; // the attribute that is unique,mandator for each object..
  69. //================================================================================
  70. // interal helpers
  71. //================================================================================
  72. LPWSTR _inline
  73. DuplicateString( // allocate and copy this LPWSTR value
  74. IN LPWSTR StringIn,
  75. IN BOOL EmptyString // convert empty string to L"" ?
  76. )
  77. {
  78. LPWSTR StringOut;
  79. if( NULL == StringIn ) {
  80. if( FALSE == EmptyString ) return NULL;
  81. StringIn = L"";
  82. }
  83. StringOut = MemAlloc(sizeof(WCHAR)*(1 + wcslen(StringIn)));
  84. if( NULL == StringOut) return NULL;
  85. wcscpy(StringOut, StringIn);
  86. return StringOut;
  87. }
  88. DWORD _inline
  89. SizeString( // # of bytes to copy the string
  90. IN LPWSTR StringIn, // OPTIONAL
  91. IN BOOL EmptyString // Convert NULL to L"" ?
  92. )
  93. {
  94. if( NULL == StringIn ) {
  95. return EmptyString? sizeof(WCHAR) : 0;
  96. }
  97. return sizeof(WCHAR)*(1+wcslen(StringIn));
  98. }
  99. LPWSTR _inline
  100. MakeColumnName(
  101. IN LPWSTR RawColumnName
  102. )
  103. {
  104. LPWSTR RetVal;
  105. RetVal = MemAlloc(SizeString(constCNAttrib,FALSE) + sizeof(LDAP_JOIN) + sizeof(WCHAR)*wcslen(RawColumnName));
  106. if( NULL == RetVal ) return RetVal;
  107. wcscpy(RetVal, constCNAttrib);
  108. wcscat(RetVal, LDAP_JOIN);
  109. wcscat(RetVal, RawColumnName);
  110. return RetVal;
  111. }
  112. LPWSTR _inline
  113. MakeSubnetLocation( // make a DN name out of servername. address
  114. IN LPWSTR ServerName, // name of server
  115. IN DWORD IpAddress // subnet address
  116. )
  117. {
  118. DWORD Size;
  119. LPWSTR RetVal;
  120. LPSTR AddrString;
  121. Size = SizeString(constCNAttrib,FALSE) + sizeof(LDAP_JOIN) + sizeof(WCHAR)*wcslen(ServerName);
  122. Size += sizeof(WCHAR) + sizeof(L"000.000.000.000");
  123. RetVal = MemAlloc(Size);
  124. if( NULL == RetVal ) return NULL; // not enough memory
  125. wcscpy(RetVal, constCNAttrib);
  126. wcscat(RetVal, LDAP_JOIN);
  127. wcscat(RetVal, ServerName);
  128. wcscat(RetVal, L"!" );
  129. IpAddress = htonl(IpAddress); // convert to network order before writing...
  130. AddrString = inet_ntoa(*(struct in_addr *)&IpAddress);
  131. mbstowcs(&RetVal[wcslen(RetVal)], AddrString, 1+strlen(AddrString));
  132. return RetVal;
  133. }
  134. LPWSTR _inline
  135. MakeReservationLocation( // make a DN name out of server name. address
  136. IN LPWSTR ServerName, // name of server
  137. IN DWORD IpAddress // subnet address
  138. )
  139. {
  140. return MakeSubnetLocation(ServerName, IpAddress);
  141. }
  142. DWORD _inline
  143. ConvertHresult( // try to convert HRESULT to Win32 errors
  144. IN HRESULT HResult
  145. )
  146. {
  147. if( 0 == (((ULONG)(HRESULT_FACILITY(HResult))) & ~0xF )) {
  148. return HRESULT_CODE(HResult); // known result
  149. }
  150. return HResult ; // unknown facility
  151. }
  152. //================================================================================
  153. // end of file
  154. //================================================================================