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.

231 lines
6.2 KiB

  1. /*++
  2. Copyright (c) 1992 Microsoft Corporation
  3. Module Name:
  4. Internal.c
  5. Abstract:
  6. This module contains "internal" APIs exported by the server service.
  7. --*/
  8. #include "srvsvcp.h"
  9. #include <debugfmt.h>
  10. #include <tstr.h>
  11. #include <lmerr.h>
  12. NET_API_STATUS NET_API_FUNCTION
  13. I_NetrServerSetServiceBitsEx (
  14. IN LPTSTR ServerName,
  15. IN LPTSTR EmulatedServerName OPTIONAL,
  16. IN LPTSTR TransportName OPTIONAL,
  17. IN DWORD ServiceBitsOfInterest,
  18. IN DWORD ServiceBits,
  19. IN DWORD UpdateImmediately
  20. )
  21. /*++
  22. Routine Description:
  23. This routine sets the value of the Server Type as sent in server
  24. announcement messages. It is an internal API used only by the
  25. service controller.
  26. Arguments:
  27. ServerName - Used by RPC to direct the call. This API may only be
  28. issued locally. This is enforced by the client stub.
  29. EmulatedServerName - server name being emulated on this computer
  30. TransportName - parameter optionally giving specific transport for which
  31. to set the bits
  32. ServiceBitsOfInterest - bit mask indicating significant 'ServiceBits'
  33. ServiceBits - Bits (preassigned to various components by Microsoft)
  34. indicating which services are active. This field is not
  35. interpreted by the server service.
  36. Return Value:
  37. NET_API_STATUS - NO_ERROR or ERROR_NOT_SUPPORTED.
  38. --*/
  39. {
  40. BOOL changed = FALSE;
  41. PNAME_LIST_ENTRY Service;
  42. PTRANSPORT_LIST_ENTRY transport;
  43. DWORD newBits;
  44. NET_API_STATUS error;
  45. CHAR serverNameBuf[ MAX_PATH ];
  46. PCHAR emulatedName;
  47. ULONG namelen;
  48. ServerName; // avoid compiler warnings
  49. //
  50. // validate incomming string lengths
  51. //
  52. if(EmulatedServerName!=NULL && StringCchLength(EmulatedServerName,1024,NULL) != S_OK) {
  53. return ERROR_INVALID_PARAMETER;
  54. }
  55. if(TransportName!=NULL && StringCchLength(TransportName,1024,NULL) != S_OK) {
  56. return ERROR_INVALID_PARAMETER;
  57. }
  58. if( SsData.SsInitialized ) {
  59. error = SsCheckAccess(
  60. &SsConfigInfoSecurityObject,
  61. SRVSVC_CONFIG_INFO_SET
  62. );
  63. if ( error != NO_ERROR ) {
  64. return ERROR_ACCESS_DENIED;
  65. }
  66. }
  67. if( ARGUMENT_PRESENT( EmulatedServerName ) ) {
  68. UNICODE_STRING name;
  69. RtlInitUnicodeString( &name, EmulatedServerName );
  70. error = ConvertStringToTransportAddress( &name, serverNameBuf, &namelen );
  71. if( error != NERR_Success ) {
  72. return error;
  73. }
  74. emulatedName = serverNameBuf;
  75. } else {
  76. emulatedName = SsData.SsServerTransportAddress;
  77. namelen = SsData.SsServerTransportAddressLength;
  78. }
  79. //
  80. // Don't let bits that are controlled by the server be set.
  81. //
  82. ServiceBitsOfInterest &= ~SERVER_TYPE_INTERNAL_BITS;
  83. ServiceBits &= ServiceBitsOfInterest;
  84. //
  85. // Make the modifications under control of the service resource.
  86. //
  87. (VOID)RtlAcquireResourceExclusive( &SsData.SsServerInfoResource, TRUE );
  88. if( SsData.SsServerNameList == NULL && !ARGUMENT_PRESENT( TransportName ) ) {
  89. //
  90. // We have not bound to any transports yet.
  91. // Remember the setting which is being asked for so we can use it later
  92. //
  93. SsData.ServiceBits &= ~ServiceBitsOfInterest;
  94. SsData.ServiceBits |= ServiceBits;
  95. RtlReleaseResource( &SsData.SsServerInfoResource );
  96. return NO_ERROR;
  97. }
  98. //
  99. // Find the entry for the server name of interest
  100. //
  101. for( Service = SsData.SsServerNameList; Service != NULL; Service = Service->Next ) {
  102. if( Service->TransportAddressLength != namelen ) {
  103. continue;
  104. }
  105. if( RtlEqualMemory( emulatedName, Service->TransportAddress, namelen ) ) {
  106. break;
  107. }
  108. }
  109. if( Service == NULL ) {
  110. RtlReleaseResource( &SsData.SsServerInfoResource );
  111. return NERR_NetNameNotFound;
  112. }
  113. //
  114. // Apply any saved ServiceBits
  115. //
  116. if( SsData.ServiceBits != 0 && Service->PrimaryName ) {
  117. Service->ServiceBits = SsData.ServiceBits;
  118. SsData.ServiceBits = 0;
  119. }
  120. if( ARGUMENT_PRESENT( TransportName ) ) {
  121. //
  122. // Transport name specified. Set the bits for that transport only.
  123. //
  124. for( transport = Service->Transports; transport != NULL; transport = transport->Next ) {
  125. if( !STRCMPI( TransportName, transport->TransportName ) ) {
  126. //
  127. // This is the transport of interest!
  128. //
  129. if( (transport->ServiceBits & ServiceBitsOfInterest) != ServiceBits ) {
  130. transport->ServiceBits &= ~ServiceBitsOfInterest;
  131. transport->ServiceBits |= ServiceBits;
  132. changed = TRUE;
  133. }
  134. break;
  135. }
  136. }
  137. if( transport == NULL ) {
  138. //
  139. // The requested transport was not found.
  140. //
  141. RtlReleaseResource( &SsData.SsServerInfoResource );
  142. return ERROR_PATH_NOT_FOUND;
  143. }
  144. } else {
  145. //
  146. // No transport name specified. Change the bits for the whole server
  147. //
  148. if( ( Service->ServiceBits & ServiceBitsOfInterest ) != ServiceBits ) {
  149. Service->ServiceBits &= ~ServiceBitsOfInterest;
  150. Service->ServiceBits |= ServiceBits;
  151. changed = TRUE;
  152. }
  153. }
  154. RtlReleaseResource( &SsData.SsServerInfoResource );
  155. if ( changed ) {
  156. SsSetExportedServerType( NULL, TRUE, (BOOL)UpdateImmediately );
  157. }
  158. return NO_ERROR;
  159. } // I_NetrServerSetServiceBits
  160. NET_API_STATUS NET_API_FUNCTION
  161. I_NetrServerSetServiceBits (
  162. IN LPTSTR ServerName,
  163. IN LPTSTR TransportName OPTIONAL,
  164. IN DWORD ServiceBits,
  165. IN DWORD UpdateImmediately
  166. )
  167. {
  168. return I_NetrServerSetServiceBitsEx (
  169. ServerName,
  170. NULL,
  171. TransportName,
  172. 0xFFFFFFFF, // All bits are of interest (just overlay the old bits)
  173. ServiceBits,
  174. UpdateImmediately
  175. );
  176. }