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.

279 lines
5.3 KiB

  1. /*++
  2. Copyright (c) 1998, Microsoft Corporation
  3. Module Name:
  4. api.c
  5. Abstract:
  6. This module contains code for the API routines which support connection
  7. sharing.
  8. Author:
  9. Abolade Gbadegesin (aboladeg) 22-Apr-1998
  10. Revision History:
  11. --*/
  12. #include "precomp.h"
  13. #pragma hdrstop
  14. #include <netconp.h>
  15. #include <routprot.h>
  16. #include <mprapip.h>
  17. const WCHAR c_szNetmanDll[] = L"NETMAN.DLL";
  18. const WCHAR c_szSharedAutoDial[] = L"SharedAutoDial";
  19. DWORD
  20. APIENTRY
  21. RasAutoDialSharedConnection(
  22. VOID
  23. )
  24. /*++
  25. Routine Description:
  26. This routine is invoked to attempt to connect the shared connection.
  27. It returns before the connection is completed, having signalled
  28. the autodial service to perform the connection.
  29. Arguments:
  30. none.
  31. Return Value:
  32. ULONG - Win32 status code.
  33. --*/
  34. {
  35. ULONG Error;
  36. HANDLE Event;
  37. TRACE("RasAutoDialSharedConnection");
  38. Event =
  39. OpenEventA(
  40. SYNCHRONIZE|EVENT_MODIFY_STATE,
  41. FALSE,
  42. RAS_AUTO_DIAL_SHARED_CONNECTION_EVENT
  43. );
  44. if (!Event) {
  45. Error = GetLastError();
  46. TRACE1("RasAutoDialSharedConnection: OpenEvent=%d", Error);
  47. return Error;
  48. }
  49. //
  50. // Signal the event
  51. //
  52. Error = (SetEvent(Event) ? NO_ERROR : GetLastError());
  53. if (Error) { TRACE1("RasAutoDialSharedConnection: SetEvent=%d", Error); }
  54. CloseHandle(Event);
  55. return Error;
  56. } // RasAutoDialSharedConnection
  57. DWORD
  58. APIENTRY
  59. RasIsSharedConnection (
  60. IN LPRASSHARECONN pConn,
  61. OUT PBOOL pfShared
  62. )
  63. /*++
  64. Routine Description:
  65. This routine attempts to determine whether or not the given connection
  66. is currently the shared connection.
  67. Arguments:
  68. pConn - the connection to be examined
  69. pfShared - receives 'TRUE' if connection is found to be shared,
  70. and 'FALSE' otherwise.
  71. Return Value:
  72. DWORD - Win32 status code.
  73. --*/
  74. {
  75. ULONG Error;
  76. BOOLEAN Shared;
  77. TRACE("RasIsSharedConnection");
  78. if (!pfShared) { return ERROR_INVALID_PARAMETER; }
  79. if (Error = CsInitializeModule()) { return Error; }
  80. Error = CsIsSharedConnection(pConn, &Shared);
  81. if (!Error) { *pfShared = (Shared ? TRUE : FALSE); }
  82. return Error;
  83. } // RasIsSharedConnection
  84. DWORD
  85. APIENTRY
  86. RasQuerySharedAutoDial(
  87. IN PBOOL pfEnabled
  88. )
  89. /*++
  90. Routine Description:
  91. This routine retrieves the autodial-setting for shared connections
  92. from the registry.
  93. Arguments:
  94. pfEnabled - receives the autodial-setting
  95. Return Value:
  96. DWORD - Win32 status code.
  97. --*/
  98. {
  99. PKEY_VALUE_PARTIAL_INFORMATION Information;
  100. HANDLE Key;
  101. NTSTATUS status;
  102. TRACE("RasQuerySharedAutoDial");
  103. *pfEnabled = TRUE;
  104. //
  105. // Bypass initialization, since this is just a registry access.
  106. //
  107. status = CsOpenKey(&Key, KEY_READ, c_szSharedAccessParametersKey);
  108. if (!NT_SUCCESS(status)) {
  109. TRACE1("RasQuerySharedAutoDial: NtOpenKey=%x", status);
  110. return RtlNtStatusToDosError(status);
  111. }
  112. //
  113. // Read the 'SharedAutoDial' value
  114. //
  115. status = CsQueryValueKey(Key, c_szSharedAutoDial, &Information);
  116. NtClose(Key);
  117. if (NT_SUCCESS(status)) {
  118. if (!*(PULONG)Information->Data) { *pfEnabled = FALSE; }
  119. Free(Information);
  120. }
  121. return NO_ERROR;
  122. } // RasQuerySharedAutoDial
  123. DWORD
  124. APIENTRY
  125. RasQuerySharedConnection(
  126. OUT LPRASSHARECONN pConn
  127. )
  128. /*++
  129. Routine Description:
  130. This routine is invoked to retrieve the name of the connection
  131. that is currently shared, if any.
  132. Arguments:
  133. pConn - receives information about the shared connection, if any
  134. Return Value:
  135. DWORD - Win32 status code.
  136. --*/
  137. {
  138. ULONG Error;
  139. TRACE("RasQuerySharedConnection");
  140. if (Error = CsInitializeModule()) { return Error; }
  141. return CsQuerySharedConnection(pConn);
  142. } // RasQuerySharedConnection
  143. DWORD
  144. APIENTRY
  145. RasSetSharedAutoDial(
  146. IN BOOL fEnable
  147. )
  148. /*++
  149. Routine Description:
  150. This routine sets the autodial-setting for shared connections
  151. in the registry.
  152. Arguments:
  153. fEnable - contains the new autodial-setting
  154. Return Value:
  155. DWORD - Win32 status code.
  156. --*/
  157. {
  158. HANDLE Key;
  159. NTSTATUS status;
  160. UNICODE_STRING UnicodeString;
  161. ULONG Value;
  162. TRACE("RasSetSharedAutoDial");
  163. //
  164. // Bypass initialization, since this is just a registry access.
  165. //
  166. status = CsOpenKey(&Key, KEY_ALL_ACCESS, c_szSharedAccessParametersKey);
  167. if (!NT_SUCCESS(status)) {
  168. TRACE1("RasSetSharedAutoDial: CsOpenKey=%x", status);
  169. return RtlNtStatusToDosError(status);
  170. }
  171. //
  172. // Install the new 'SharedAutoDial' value
  173. //
  174. RtlInitUnicodeString(&UnicodeString, c_szSharedAutoDial);
  175. Value = !!fEnable;
  176. status =
  177. NtSetValueKey(
  178. Key,
  179. &UnicodeString,
  180. 0,
  181. REG_DWORD,
  182. &Value,
  183. sizeof(Value)
  184. );
  185. NtClose(Key);
  186. CsControlService(IPNATHLP_CONTROL_UPDATE_AUTODIAL);
  187. return NT_SUCCESS(status) ? NO_ERROR : RtlNtStatusToDosError(status);
  188. } // RasSetSharedAutoDial