2006-01-09 23:36:17 +00:00
|
|
|
/*
|
2005-04-12 23:25:14 +00:00
|
|
|
* COPYRIGHT: See COPYING in the top level directory
|
|
|
|
* PROJECT: ReactOS system libraries
|
|
|
|
* FILE: lib/dhcpcapi/dhcpcapi.c
|
|
|
|
* PURPOSE: Client API for DHCP
|
2006-01-09 23:36:17 +00:00
|
|
|
* COPYRIGHT: Copyright 2005 Art Yerkes <ayerkes@speakeasy.net>
|
2005-04-12 23:25:14 +00:00
|
|
|
*/
|
|
|
|
|
2010-05-21 20:14:56 +00:00
|
|
|
#include <rosdhcp.h>
|
2014-09-25 22:01:42 +00:00
|
|
|
#include <winsvc.h>
|
2005-04-12 23:25:14 +00:00
|
|
|
|
2006-01-09 23:36:17 +00:00
|
|
|
#define NDEBUG
|
|
|
|
#include <debug.h>
|
|
|
|
|
2014-09-25 22:01:42 +00:00
|
|
|
static WCHAR ServiceName[] = L"DHCP";
|
|
|
|
|
|
|
|
SERVICE_STATUS_HANDLE ServiceStatusHandle = 0;
|
|
|
|
SERVICE_STATUS ServiceStatus;
|
2018-03-21 20:07:26 +00:00
|
|
|
HANDLE hStopEvent = NULL;
|
2021-08-08 12:09:31 +00:00
|
|
|
HANDLE hAdapterStateChangedEvent = NULL;
|
2014-09-25 22:01:42 +00:00
|
|
|
|
2010-05-21 20:14:56 +00:00
|
|
|
static HANDLE PipeHandle = INVALID_HANDLE_VALUE;
|
2021-08-08 12:09:31 +00:00
|
|
|
extern SOCKET DhcpSocket;
|
2005-04-12 23:25:14 +00:00
|
|
|
|
2014-09-25 22:01:42 +00:00
|
|
|
DWORD APIENTRY
|
|
|
|
DhcpCApiInitialize(LPDWORD Version)
|
|
|
|
{
|
2010-05-21 20:14:56 +00:00
|
|
|
DWORD PipeMode;
|
|
|
|
|
|
|
|
/* Wait for the pipe to be available */
|
2014-09-25 22:01:42 +00:00
|
|
|
if (!WaitNamedPipeW(DHCP_PIPE_NAME, NMPWAIT_USE_DEFAULT_WAIT))
|
2010-05-21 20:14:56 +00:00
|
|
|
{
|
2014-09-25 22:01:42 +00:00
|
|
|
/* No good, we failed */
|
|
|
|
return GetLastError();
|
2010-05-21 20:14:56 +00:00
|
|
|
}
|
2014-09-25 22:01:42 +00:00
|
|
|
|
|
|
|
/* It's available, let's try to open it */
|
|
|
|
PipeHandle = CreateFileW(DHCP_PIPE_NAME,
|
|
|
|
GENERIC_READ | GENERIC_WRITE,
|
|
|
|
FILE_SHARE_READ | FILE_SHARE_WRITE,
|
|
|
|
NULL,
|
|
|
|
OPEN_EXISTING,
|
|
|
|
0,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
/* Check if we succeeded in opening the pipe */
|
|
|
|
if (PipeHandle == INVALID_HANDLE_VALUE)
|
2010-05-21 20:14:56 +00:00
|
|
|
{
|
2014-09-25 22:01:42 +00:00
|
|
|
/* We didn't */
|
2010-05-21 20:14:56 +00:00
|
|
|
return GetLastError();
|
|
|
|
}
|
2014-09-25 22:01:42 +00:00
|
|
|
|
|
|
|
/* Change the pipe into message mode */
|
2021-09-13 01:33:14 +00:00
|
|
|
PipeMode = PIPE_READMODE_MESSAGE;
|
2014-09-25 22:01:42 +00:00
|
|
|
if (!SetNamedPipeHandleState(PipeHandle, &PipeMode, NULL, NULL))
|
|
|
|
{
|
|
|
|
/* Mode change failed */
|
|
|
|
CloseHandle(PipeHandle);
|
|
|
|
PipeHandle = INVALID_HANDLE_VALUE;
|
|
|
|
return GetLastError();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* We're good to go */
|
|
|
|
*Version = 2;
|
|
|
|
return NO_ERROR;
|
|
|
|
}
|
2005-04-12 23:25:14 +00:00
|
|
|
}
|
|
|
|
|
2014-09-25 22:01:42 +00:00
|
|
|
VOID APIENTRY
|
|
|
|
DhcpCApiCleanup(VOID)
|
|
|
|
{
|
2010-05-21 20:14:56 +00:00
|
|
|
CloseHandle(PipeHandle);
|
|
|
|
PipeHandle = INVALID_HANDLE_VALUE;
|
2005-04-12 23:25:14 +00:00
|
|
|
}
|
|
|
|
|
2014-09-25 22:01:42 +00:00
|
|
|
DWORD APIENTRY
|
|
|
|
DhcpQueryHWInfo(DWORD AdapterIndex,
|
|
|
|
PDWORD MediaType,
|
|
|
|
PDWORD Mtu,
|
|
|
|
PDWORD Speed)
|
|
|
|
{
|
2005-04-12 23:25:14 +00:00
|
|
|
COMM_DHCP_REQ Req;
|
|
|
|
COMM_DHCP_REPLY Reply;
|
|
|
|
DWORD BytesRead;
|
|
|
|
BOOL Result;
|
|
|
|
|
2010-05-21 20:14:56 +00:00
|
|
|
ASSERT(PipeHandle != INVALID_HANDLE_VALUE);
|
|
|
|
|
2005-04-12 23:25:14 +00:00
|
|
|
Req.Type = DhcpReqQueryHWInfo;
|
|
|
|
Req.AdapterIndex = AdapterIndex;
|
|
|
|
|
2010-05-21 20:14:56 +00:00
|
|
|
Result = TransactNamedPipe(PipeHandle,
|
|
|
|
&Req, sizeof(Req),
|
|
|
|
&Reply, sizeof(Reply),
|
|
|
|
&BytesRead, NULL);
|
|
|
|
if (!Result)
|
|
|
|
{
|
|
|
|
/* Pipe transaction failed */
|
|
|
|
return 0;
|
|
|
|
}
|
2005-04-12 23:25:14 +00:00
|
|
|
|
2014-09-25 22:01:42 +00:00
|
|
|
if (Reply.Reply == 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
*MediaType = Reply.QueryHWInfo.MediaType;
|
|
|
|
*Mtu = Reply.QueryHWInfo.Mtu;
|
|
|
|
*Speed = Reply.QueryHWInfo.Speed;
|
|
|
|
return 1;
|
2005-04-12 23:25:14 +00:00
|
|
|
}
|
|
|
|
|
2014-09-25 22:01:42 +00:00
|
|
|
DWORD APIENTRY
|
|
|
|
DhcpLeaseIpAddress(DWORD AdapterIndex)
|
|
|
|
{
|
2005-04-12 23:25:14 +00:00
|
|
|
COMM_DHCP_REQ Req;
|
|
|
|
COMM_DHCP_REPLY Reply;
|
|
|
|
DWORD BytesRead;
|
|
|
|
BOOL Result;
|
|
|
|
|
2010-05-21 20:14:56 +00:00
|
|
|
ASSERT(PipeHandle != INVALID_HANDLE_VALUE);
|
|
|
|
|
2005-04-12 23:25:14 +00:00
|
|
|
Req.Type = DhcpReqLeaseIpAddress;
|
|
|
|
Req.AdapterIndex = AdapterIndex;
|
|
|
|
|
2010-05-21 20:14:56 +00:00
|
|
|
Result = TransactNamedPipe(PipeHandle,
|
|
|
|
&Req, sizeof(Req),
|
|
|
|
&Reply, sizeof(Reply),
|
|
|
|
&BytesRead, NULL);
|
|
|
|
if (!Result)
|
|
|
|
{
|
|
|
|
/* Pipe transaction failed */
|
|
|
|
return 0;
|
|
|
|
}
|
2005-04-12 23:25:14 +00:00
|
|
|
|
|
|
|
return Reply.Reply;
|
|
|
|
}
|
|
|
|
|
2014-09-25 22:01:42 +00:00
|
|
|
DWORD APIENTRY
|
|
|
|
DhcpReleaseIpAddressLease(DWORD AdapterIndex)
|
|
|
|
{
|
2005-04-12 23:25:14 +00:00
|
|
|
COMM_DHCP_REQ Req;
|
|
|
|
COMM_DHCP_REPLY Reply;
|
|
|
|
DWORD BytesRead;
|
|
|
|
BOOL Result;
|
|
|
|
|
2010-05-21 20:14:56 +00:00
|
|
|
ASSERT(PipeHandle != INVALID_HANDLE_VALUE);
|
|
|
|
|
2005-04-12 23:25:14 +00:00
|
|
|
Req.Type = DhcpReqReleaseIpAddress;
|
|
|
|
Req.AdapterIndex = AdapterIndex;
|
|
|
|
|
2010-05-21 20:14:56 +00:00
|
|
|
Result = TransactNamedPipe(PipeHandle,
|
|
|
|
&Req, sizeof(Req),
|
|
|
|
&Reply, sizeof(Reply),
|
|
|
|
&BytesRead, NULL);
|
|
|
|
if (!Result)
|
|
|
|
{
|
|
|
|
/* Pipe transaction failed */
|
|
|
|
return 0;
|
|
|
|
}
|
2005-04-12 23:25:14 +00:00
|
|
|
|
|
|
|
return Reply.Reply;
|
|
|
|
}
|
|
|
|
|
2014-09-25 22:01:42 +00:00
|
|
|
DWORD APIENTRY
|
|
|
|
DhcpRenewIpAddressLease(DWORD AdapterIndex)
|
|
|
|
{
|
2005-04-12 23:25:14 +00:00
|
|
|
COMM_DHCP_REQ Req;
|
|
|
|
COMM_DHCP_REPLY Reply;
|
|
|
|
DWORD BytesRead;
|
|
|
|
BOOL Result;
|
|
|
|
|
2010-05-21 20:14:56 +00:00
|
|
|
ASSERT(PipeHandle != INVALID_HANDLE_VALUE);
|
|
|
|
|
2005-04-12 23:25:14 +00:00
|
|
|
Req.Type = DhcpReqRenewIpAddress;
|
|
|
|
Req.AdapterIndex = AdapterIndex;
|
|
|
|
|
2010-05-21 20:14:56 +00:00
|
|
|
Result = TransactNamedPipe(PipeHandle,
|
|
|
|
&Req, sizeof(Req),
|
|
|
|
&Reply, sizeof(Reply),
|
|
|
|
&BytesRead, NULL);
|
|
|
|
if (!Result)
|
|
|
|
{
|
|
|
|
/* Pipe transaction failed */
|
|
|
|
return 0;
|
|
|
|
}
|
2005-04-12 23:25:14 +00:00
|
|
|
|
|
|
|
return Reply.Reply;
|
|
|
|
}
|
|
|
|
|
2014-09-25 22:01:42 +00:00
|
|
|
DWORD APIENTRY
|
|
|
|
DhcpStaticRefreshParams(DWORD AdapterIndex,
|
|
|
|
DWORD Address,
|
|
|
|
DWORD Netmask)
|
|
|
|
{
|
2005-04-12 23:25:14 +00:00
|
|
|
COMM_DHCP_REQ Req;
|
|
|
|
COMM_DHCP_REPLY Reply;
|
|
|
|
DWORD BytesRead;
|
|
|
|
BOOL Result;
|
|
|
|
|
2010-05-21 20:14:56 +00:00
|
|
|
ASSERT(PipeHandle != INVALID_HANDLE_VALUE);
|
|
|
|
|
2005-04-12 23:25:14 +00:00
|
|
|
Req.Type = DhcpReqStaticRefreshParams;
|
|
|
|
Req.AdapterIndex = AdapterIndex;
|
|
|
|
Req.Body.StaticRefreshParams.IPAddress = Address;
|
|
|
|
Req.Body.StaticRefreshParams.Netmask = Netmask;
|
|
|
|
|
2010-05-21 20:14:56 +00:00
|
|
|
Result = TransactNamedPipe(PipeHandle,
|
|
|
|
&Req, sizeof(Req),
|
|
|
|
&Reply, sizeof(Reply),
|
|
|
|
&BytesRead, NULL);
|
|
|
|
if (!Result)
|
|
|
|
{
|
|
|
|
/* Pipe transaction failed */
|
|
|
|
return 0;
|
|
|
|
}
|
2005-04-12 23:25:14 +00:00
|
|
|
|
|
|
|
return Reply.Reply;
|
|
|
|
}
|
|
|
|
|
2006-01-09 23:36:17 +00:00
|
|
|
/*!
|
|
|
|
* Set new TCP/IP parameters and notify DHCP client service of this
|
|
|
|
*
|
|
|
|
* \param[in] ServerName
|
|
|
|
* NULL for local machine
|
|
|
|
*
|
|
|
|
* \param[in] AdapterName
|
|
|
|
* IPHLPAPI name of adapter to change
|
|
|
|
*
|
|
|
|
* \param[in] NewIpAddress
|
|
|
|
* TRUE if IP address changes
|
|
|
|
*
|
|
|
|
* \param[in] IpAddress
|
|
|
|
* New IP address (network byte order)
|
|
|
|
*
|
|
|
|
* \param[in] SubnetMask
|
|
|
|
* New subnet mask (network byte order)
|
|
|
|
*
|
|
|
|
* \param[in] DhcpAction
|
|
|
|
* 0 - don't modify
|
|
|
|
* 1 - enable DHCP
|
|
|
|
* 2 - disable DHCP
|
2006-01-08 22:14:26 +00:00
|
|
|
*
|
2006-01-09 23:36:17 +00:00
|
|
|
* \return non-zero on success
|
|
|
|
*
|
|
|
|
* \remarks Undocumented by Microsoft
|
|
|
|
*/
|
|
|
|
DWORD APIENTRY
|
|
|
|
DhcpNotifyConfigChange(LPWSTR ServerName,
|
|
|
|
LPWSTR AdapterName,
|
|
|
|
BOOL NewIpAddress,
|
|
|
|
DWORD IpIndex,
|
|
|
|
DWORD IpAddress,
|
|
|
|
DWORD SubnetMask,
|
2014-09-25 22:01:42 +00:00
|
|
|
INT DhcpAction)
|
2006-01-09 23:36:17 +00:00
|
|
|
{
|
2014-09-25 22:01:42 +00:00
|
|
|
DPRINT1("DHCPCSVC: DhcpNotifyConfigChange not implemented yet\n");
|
2006-01-09 23:36:17 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-12-06 21:24:47 +00:00
|
|
|
DWORD APIENTRY
|
|
|
|
DhcpRequestParams(DWORD Flags,
|
|
|
|
PVOID Reserved,
|
|
|
|
LPWSTR AdapterName,
|
|
|
|
LPDHCPCAPI_CLASSID ClassId,
|
|
|
|
DHCPCAPI_PARAMS_ARRAY SendParams,
|
|
|
|
DHCPCAPI_PARAMS_ARRAY RecdParams,
|
|
|
|
LPBYTE Buffer,
|
|
|
|
LPDWORD pSize,
|
|
|
|
LPWSTR RequestIdStr)
|
|
|
|
{
|
|
|
|
UNIMPLEMENTED;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-01-09 23:36:17 +00:00
|
|
|
/*!
|
2006-01-08 22:14:26 +00:00
|
|
|
* Get DHCP info for an adapter
|
|
|
|
*
|
2006-01-09 23:36:17 +00:00
|
|
|
* \param[in] AdapterIndex
|
2006-01-08 22:14:26 +00:00
|
|
|
* Index of the adapter (iphlpapi-style) for which info is
|
|
|
|
* requested
|
|
|
|
*
|
2006-01-09 23:36:17 +00:00
|
|
|
* \param[out] DhcpEnabled
|
2006-01-08 22:14:26 +00:00
|
|
|
* Returns whether DHCP is enabled for the adapter
|
|
|
|
*
|
2006-01-09 23:36:17 +00:00
|
|
|
* \param[out] DhcpServer
|
2006-01-08 22:14:26 +00:00
|
|
|
* Returns DHCP server IP address (255.255.255.255 if no
|
|
|
|
* server reached yet), in network byte order
|
|
|
|
*
|
2006-01-09 23:36:17 +00:00
|
|
|
* \param[out] LeaseObtained
|
2006-01-08 22:14:26 +00:00
|
|
|
* Returns time at which the lease was obtained
|
|
|
|
*
|
2006-01-09 23:36:17 +00:00
|
|
|
* \param[out] LeaseExpires
|
2006-01-08 22:14:26 +00:00
|
|
|
* Returns time at which the lease will expire
|
|
|
|
*
|
2006-01-09 23:36:17 +00:00
|
|
|
* \return non-zero on success
|
2006-01-08 22:14:26 +00:00
|
|
|
*
|
2006-01-09 23:36:17 +00:00
|
|
|
* \remarks This is a ReactOS-only routine
|
|
|
|
*/
|
2014-09-25 22:01:42 +00:00
|
|
|
DWORD APIENTRY
|
|
|
|
DhcpRosGetAdapterInfo(DWORD AdapterIndex,
|
|
|
|
PBOOL DhcpEnabled,
|
|
|
|
PDWORD DhcpServer,
|
|
|
|
time_t* LeaseObtained,
|
|
|
|
time_t* LeaseExpires)
|
2006-01-08 22:14:26 +00:00
|
|
|
{
|
|
|
|
COMM_DHCP_REQ Req;
|
|
|
|
COMM_DHCP_REPLY Reply;
|
|
|
|
DWORD BytesRead;
|
|
|
|
BOOL Result;
|
|
|
|
|
2010-05-21 20:14:56 +00:00
|
|
|
ASSERT(PipeHandle != INVALID_HANDLE_VALUE);
|
|
|
|
|
2006-01-08 22:14:26 +00:00
|
|
|
Req.Type = DhcpReqGetAdapterInfo;
|
|
|
|
Req.AdapterIndex = AdapterIndex;
|
|
|
|
|
2010-05-21 20:14:56 +00:00
|
|
|
Result = TransactNamedPipe(PipeHandle,
|
|
|
|
&Req, sizeof(Req),
|
|
|
|
&Reply, sizeof(Reply),
|
|
|
|
&BytesRead, NULL);
|
2006-01-08 22:14:26 +00:00
|
|
|
|
2014-09-25 22:01:42 +00:00
|
|
|
if (Result && Reply.Reply != 0)
|
2006-01-08 22:14:26 +00:00
|
|
|
*DhcpEnabled = Reply.GetAdapterInfo.DhcpEnabled;
|
2014-09-25 22:01:42 +00:00
|
|
|
else
|
2006-01-08 22:14:26 +00:00
|
|
|
*DhcpEnabled = FALSE;
|
2014-09-25 22:01:42 +00:00
|
|
|
|
|
|
|
if (*DhcpEnabled)
|
|
|
|
{
|
2006-01-08 22:14:26 +00:00
|
|
|
*DhcpServer = Reply.GetAdapterInfo.DhcpServer;
|
|
|
|
*LeaseObtained = Reply.GetAdapterInfo.LeaseObtained;
|
|
|
|
*LeaseExpires = Reply.GetAdapterInfo.LeaseExpires;
|
2014-09-25 22:01:42 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-01-08 22:14:26 +00:00
|
|
|
*DhcpServer = INADDR_NONE;
|
|
|
|
*LeaseObtained = 0;
|
|
|
|
*LeaseExpires = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Reply.Reply;
|
|
|
|
}
|
|
|
|
|
2014-09-25 22:01:42 +00:00
|
|
|
|
|
|
|
static VOID
|
|
|
|
UpdateServiceStatus(DWORD dwState)
|
|
|
|
{
|
2022-01-16 16:59:41 +00:00
|
|
|
ServiceStatus.dwServiceType = SERVICE_WIN32_SHARE_PROCESS;
|
2014-09-25 22:01:42 +00:00
|
|
|
ServiceStatus.dwCurrentState = dwState;
|
|
|
|
|
2018-03-21 20:07:26 +00:00
|
|
|
if (dwState == SERVICE_RUNNING)
|
|
|
|
ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_SHUTDOWN | SERVICE_ACCEPT_STOP;
|
|
|
|
else
|
|
|
|
ServiceStatus.dwControlsAccepted = 0;
|
2014-09-25 22:01:42 +00:00
|
|
|
|
|
|
|
ServiceStatus.dwWin32ExitCode = 0;
|
|
|
|
ServiceStatus.dwServiceSpecificExitCode = 0;
|
|
|
|
ServiceStatus.dwCheckPoint = 0;
|
|
|
|
|
|
|
|
if (dwState == SERVICE_START_PENDING ||
|
2018-03-21 20:07:26 +00:00
|
|
|
dwState == SERVICE_STOP_PENDING)
|
|
|
|
ServiceStatus.dwWaitHint = 1000;
|
2014-09-25 22:01:42 +00:00
|
|
|
else
|
|
|
|
ServiceStatus.dwWaitHint = 0;
|
|
|
|
|
|
|
|
SetServiceStatus(ServiceStatusHandle,
|
|
|
|
&ServiceStatus);
|
|
|
|
}
|
|
|
|
|
|
|
|
static DWORD WINAPI
|
|
|
|
ServiceControlHandler(DWORD dwControl,
|
|
|
|
DWORD dwEventType,
|
|
|
|
LPVOID lpEventData,
|
|
|
|
LPVOID lpContext)
|
|
|
|
{
|
|
|
|
switch (dwControl)
|
|
|
|
{
|
|
|
|
case SERVICE_CONTROL_STOP:
|
2018-03-21 20:07:26 +00:00
|
|
|
case SERVICE_CONTROL_SHUTDOWN:
|
2014-09-25 22:01:42 +00:00
|
|
|
UpdateServiceStatus(SERVICE_STOP_PENDING);
|
2018-03-21 20:07:26 +00:00
|
|
|
if (hStopEvent != NULL)
|
|
|
|
SetEvent(hStopEvent);
|
2014-09-25 22:01:42 +00:00
|
|
|
return ERROR_SUCCESS;
|
|
|
|
|
|
|
|
case SERVICE_CONTROL_INTERROGATE:
|
|
|
|
SetServiceStatus(ServiceStatusHandle,
|
|
|
|
&ServiceStatus);
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
|
2018-03-21 20:07:26 +00:00
|
|
|
default:
|
2014-09-25 22:01:42 +00:00
|
|
|
return ERROR_CALL_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
VOID WINAPI
|
|
|
|
ServiceMain(DWORD argc, LPWSTR* argv)
|
|
|
|
{
|
2021-08-08 12:09:31 +00:00
|
|
|
HANDLE hPipeThread = INVALID_HANDLE_VALUE;
|
|
|
|
HANDLE hDiscoveryThread = INVALID_HANDLE_VALUE;
|
|
|
|
DWORD ret;
|
|
|
|
|
2014-09-25 22:01:42 +00:00
|
|
|
ServiceStatusHandle = RegisterServiceCtrlHandlerExW(ServiceName,
|
|
|
|
ServiceControlHandler,
|
|
|
|
NULL);
|
|
|
|
if (!ServiceStatusHandle)
|
|
|
|
{
|
|
|
|
DPRINT1("DHCPCSVC: Unable to register service control handler (%lx)\n", GetLastError());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
UpdateServiceStatus(SERVICE_START_PENDING);
|
|
|
|
|
2018-03-21 20:07:26 +00:00
|
|
|
/* Create the stop event */
|
2021-08-08 12:09:31 +00:00
|
|
|
hStopEvent = CreateEventW(NULL, TRUE, FALSE, NULL);
|
2018-03-21 20:07:26 +00:00
|
|
|
if (hStopEvent == NULL)
|
|
|
|
{
|
|
|
|
UpdateServiceStatus(SERVICE_STOPPED);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-08-08 12:09:31 +00:00
|
|
|
hAdapterStateChangedEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
|
|
|
|
if (hAdapterStateChangedEvent == NULL)
|
|
|
|
{
|
|
|
|
CloseHandle(hStopEvent);
|
|
|
|
UpdateServiceStatus(SERVICE_STOPPED);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-03-21 20:07:26 +00:00
|
|
|
UpdateServiceStatus(SERVICE_START_PENDING);
|
|
|
|
|
2014-09-25 22:01:42 +00:00
|
|
|
if (!init_client())
|
|
|
|
{
|
2021-08-08 12:09:31 +00:00
|
|
|
DbgPrint("DHCPCSVC: init_client() failed!\n");
|
|
|
|
CloseHandle(hAdapterStateChangedEvent);
|
|
|
|
CloseHandle(hStopEvent);
|
|
|
|
UpdateServiceStatus(SERVICE_STOPPED);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
UpdateServiceStatus(SERVICE_START_PENDING);
|
|
|
|
|
|
|
|
hPipeThread = PipeInit(hStopEvent);
|
|
|
|
if (hPipeThread == INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
DbgPrint("DHCPCSVC: PipeInit() failed!\n");
|
|
|
|
stop_client();
|
|
|
|
CloseHandle(hAdapterStateChangedEvent);
|
|
|
|
CloseHandle(hStopEvent);
|
|
|
|
UpdateServiceStatus(SERVICE_STOPPED);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
hDiscoveryThread = StartAdapterDiscovery(hStopEvent);
|
|
|
|
if (hDiscoveryThread == INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
DbgPrint("DHCPCSVC: StartAdapterDiscovery() failed!\n");
|
|
|
|
stop_client();
|
|
|
|
CloseHandle(hAdapterStateChangedEvent);
|
|
|
|
CloseHandle(hStopEvent);
|
2014-09-25 22:01:42 +00:00
|
|
|
UpdateServiceStatus(SERVICE_STOPPED);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
DH_DbgPrint(MID_TRACE,("DHCP Service Started\n"));
|
|
|
|
|
|
|
|
UpdateServiceStatus(SERVICE_RUNNING);
|
|
|
|
|
|
|
|
DH_DbgPrint(MID_TRACE,("Going into dispatch()\n"));
|
|
|
|
DH_DbgPrint(MID_TRACE,("DHCPCSVC: DHCP service is starting up\n"));
|
|
|
|
|
2018-03-21 20:07:26 +00:00
|
|
|
dispatch(hStopEvent);
|
2014-09-25 22:01:42 +00:00
|
|
|
|
|
|
|
DH_DbgPrint(MID_TRACE,("DHCPCSVC: DHCP service is shutting down\n"));
|
2021-08-08 12:09:31 +00:00
|
|
|
|
2014-09-25 22:01:42 +00:00
|
|
|
stop_client();
|
|
|
|
|
2021-08-08 12:09:31 +00:00
|
|
|
DPRINT("Wait for pipe thread to close! %p\n", hPipeThread);
|
|
|
|
if (hPipeThread != INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
DPRINT("Waiting for pipe thread\n");
|
|
|
|
ret = WaitForSingleObject(hPipeThread, 5000);
|
|
|
|
DPRINT("Done %lx\n", ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
DPRINT("Wait for discovery thread to close! %p\n", hDiscoveryThread);
|
|
|
|
if (hDiscoveryThread != INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
DPRINT("Waiting for discovery thread\n");
|
|
|
|
ret = WaitForSingleObject(hDiscoveryThread, 5000);
|
|
|
|
DPRINT("Done %lx\n", ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
DPRINT("Closing events!\n");
|
|
|
|
CloseHandle(hAdapterStateChangedEvent);
|
|
|
|
CloseHandle(hStopEvent);
|
|
|
|
|
|
|
|
if (DhcpSocket != INVALID_SOCKET)
|
|
|
|
closesocket(DhcpSocket);
|
|
|
|
|
|
|
|
CloseHandle(hDiscoveryThread);
|
|
|
|
CloseHandle(hPipeThread);
|
|
|
|
|
|
|
|
DPRINT("Done!\n");
|
|
|
|
|
2014-09-25 22:01:42 +00:00
|
|
|
UpdateServiceStatus(SERVICE_STOPPED);
|
|
|
|
}
|
|
|
|
|
2014-09-25 23:45:30 +00:00
|
|
|
BOOL WINAPI
|
|
|
|
DllMain(HINSTANCE hinstDLL,
|
|
|
|
DWORD fdwReason,
|
|
|
|
LPVOID lpvReserved)
|
2005-04-12 23:25:14 +00:00
|
|
|
{
|
2014-09-25 23:45:30 +00:00
|
|
|
switch (fdwReason)
|
2014-09-25 22:01:42 +00:00
|
|
|
{
|
|
|
|
case DLL_PROCESS_ATTACH:
|
2014-09-25 23:45:30 +00:00
|
|
|
DisableThreadLibraryCalls(hinstDLL);
|
2014-09-25 22:01:42 +00:00
|
|
|
break;
|
2005-04-12 23:25:14 +00:00
|
|
|
|
2014-09-25 22:01:42 +00:00
|
|
|
case DLL_PROCESS_DETACH:
|
|
|
|
break;
|
|
|
|
}
|
2005-04-12 23:25:14 +00:00
|
|
|
|
2014-09-25 22:01:42 +00:00
|
|
|
return TRUE;
|
2005-04-12 23:25:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* EOF */
|