ReactOS 0.4.16-dev-2588-g215d409
dhcpcsvc.c File Reference
#include <rosdhcp.h>
#include <winsvc.h>
#include <dhcpcapi.h>
#include <debug.h>
Include dependency graph for dhcpcsvc.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

void __RPC_FAR *__RPC_USER MIDL_user_allocate (SIZE_T len)
 
void __RPC_USER MIDL_user_free (void __RPC_FAR *ptr)
 
handle_t __RPC_USER PDHCP_SERVER_NAME_bind (_In_ PDHCP_SERVER_NAME pszServerName)
 
void __RPC_USER PDHCP_SERVER_NAME_unbind (_In_ PDHCP_SERVER_NAME pszServerName, _In_ handle_t hBinding)
 
static DWORD SetBinaryClassId (_In_ PWSTR pszAdapterName)
 
DWORD APIENTRY DhcpCApiInitialize (_Out_ LPDWORD Version)
 
VOID APIENTRY DhcpCApiCleanup (VOID)
 
DWORD APIENTRY DhcpAcquireParameters (_In_ PWSTR AdapterName)
 
DWORD APIENTRY DhcpEnumClasses (_In_ DWORD Unknown1, _In_ PWSTR AdapterName, _In_ DWORD Unknown3, _In_ DWORD Unknown4)
 
DWORD APIENTRY DhcpFallbackRefreshParams (_In_ PWSTR AdapterName)
 
DWORD APIENTRY DhcpHandlePnPEvent (_In_ DWORD Unknown1, _In_ DWORD Unknown2, _In_ PWSTR AdapterName, _In_ PDHCP_PNP_EVENT PnpEvent, _In_ DWORD Unknown5)
 
DWORD APIENTRY DhcpNotifyConfigChange (_In_ LPWSTR ServerName, _In_ LPWSTR AdapterName, _In_ BOOL NewIpAddress, _In_ DWORD IpIndex, _In_ DWORD IpAddress, _In_ DWORD SubnetMask, _In_ INT DhcpAction)
 
DWORD APIENTRY DhcpQueryHWInfo (DWORD AdapterIndex, PDWORD MediaType, PDWORD Mtu, PDWORD Speed)
 
DWORD APIENTRY DhcpReleaseParameters (_In_ PWSTR AdapterName)
 
DWORD WINAPI DhcpRemoveDNSRegistrations (VOID)
 
DWORD APIENTRY DhcpStaticRefreshParams (DWORD AdapterIndex, DWORD Address, DWORD Netmask)
 
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)
 
static VOID UpdateServiceStatus (DWORD dwState)
 
static DWORD WINAPI ServiceControlHandler (DWORD dwControl, DWORD dwEventType, LPVOID lpEventData, LPVOID lpContext)
 
VOID WINAPI ServiceMain (DWORD argc, LPWSTR *argv)
 
BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
 

Variables

static WCHAR ServiceName [] = L"DHCP"
 
SERVICE_STATUS_HANDLE ServiceStatusHandle = 0
 
SERVICE_STATUS ServiceStatus
 
HANDLE hStopEvent = NULL
 
HANDLE hAdapterStateChangedEvent = NULL
 
SOCKET DhcpSocket
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 13 of file dhcpcsvc.c.

Function Documentation

◆ DhcpAcquireParameters()

DWORD APIENTRY DhcpAcquireParameters ( _In_ PWSTR  AdapterName)

Renews a DHCP Lease

Parameters
[in]AdapterNameName (GUID) of the Adapter
Returns
ERROR_SUCCESS on success
Remarks
Undocumented by Microsoft

Definition at line 243 of file dhcpcsvc.c.

245{
246 DWORD ret;
247
248 DPRINT("DhcpAcquireParameters(%S)\n", AdapterName);
249
251 {
252 ret = Client_AcquireParameters(NULL, AdapterName);
253 }
255 {
257 }
259
260 return ret;
261}
#define NULL
Definition: types.h:112
return ret
Definition: mutex.c:146
unsigned long DWORD
Definition: ntddk_ex.h:95
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:90
_Must_inspect_result_ _Out_ PNDIS_STATUS _Out_ PNDIS_STATUS _Out_ PNDIS_HANDLE _Out_ PUINT _In_ UINT _In_ NDIS_HANDLE _In_ NDIS_HANDLE _In_ PNDIS_STRING AdapterName
Definition: ndis.h:6016
LONG WINAPI I_RpcMapWin32Status(RPC_STATUS status)
Definition: rpcrt4_main.c:771
#define RpcEndExcept
Definition: rpc.h:123
#define RpcTryExcept
Definition: rpc.h:121
#define RpcExcept(expr)
Definition: rpc.h:122
#define RpcExceptionCode()
Definition: rpc.h:127
#define DPRINT
Definition: sndvol32.h:73

Referenced by IpRenewAddress(), and Renew().

◆ DhcpCApiCleanup()

VOID APIENTRY DhcpCApiCleanup ( VOID  )

Cleans up the DHCP interface

Remarks
Other DHCP Functions must not be called after DhcpCApiCleanup.

Definition at line 227 of file dhcpcsvc.c.

228{
229}

Referenced by INetCfgComponentControl_fnApplyPnpChanges(), IpReleaseAddress(), IpRenewAddress(), Release(), and Renew().

◆ DhcpCApiInitialize()

DWORD APIENTRY DhcpCApiInitialize ( _Out_ LPDWORD  Version)

Initializes the DHCP interface

Parameters
[out]VersionReturns the DHCP Interface Version
Returns
ERROR_SUCCESS on success
Remarks
DhcpCApiInitialized must be called before any other DHCP Function.

Definition at line 213 of file dhcpcsvc.c.

215{
216 *Version = 2;
217 return ERROR_SUCCESS;
218}
#define ERROR_SUCCESS
Definition: deptool.c:10
_Must_inspect_result_ _In_ WDFDEVICE _In_ LPCGUID _Out_ PINTERFACE _In_ USHORT _In_ USHORT Version
Definition: wdffdo.h:469

Referenced by INetCfgComponentControl_fnApplyPnpChanges(), IpReleaseAddress(), IpRenewAddress(), Release(), and Renew().

◆ DhcpEnumClasses()

DWORD APIENTRY DhcpEnumClasses ( _In_ DWORD  Unknown1,
_In_ PWSTR  AdapterName,
_In_ DWORD  Unknown3,
_In_ DWORD  Unknown4 
)

Enumerates the DHCP user classes for the given adapter

Parameters
[in]Unknown1Unknown
[in]AdapterNameName (GUID) of the Adapter
[in]Unknown3Unknown
[in]Unknown4Unknown
Returns
ERROR_SUCCESS on success
Remarks
Undocumented by Microsoft

Definition at line 284 of file dhcpcsvc.c.

289{
290 DPRINT1("DhcpEnumClasses(%lx %S %lx %lx)\n",
291 Unknown1, AdapterName, Unknown3, Unknown4);
292 return 0;
293}
PRTL_UNICODE_STRING_BUFFER PULONG PULONG Unknown4
#define DPRINT1
Definition: precomp.h:8
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES IN DWORD Unknown3
Definition: conport.c:37

◆ DhcpFallbackRefreshParams()

DWORD APIENTRY DhcpFallbackRefreshParams ( _In_ PWSTR  AdapterName)

Notify the DHCP client to refresh its fallback configuration

Parameters
[in]AdapterNameName (GUID) of the Adapter
Returns
ERROR_SUCCESS on success
Remarks
Undocumented by Microsoft

Definition at line 307 of file dhcpcsvc.c.

309{
310 DWORD ret;
311
312 DPRINT("DhcpFallbackRefreshParams(%S)\n", AdapterName);
313
315 {
316 ret = Client_FallbackRefreshParams(NULL, AdapterName);
317 }
319 {
321 }
323
324 return ret;
325}

◆ DhcpHandlePnPEvent()

DWORD APIENTRY DhcpHandlePnPEvent ( _In_ DWORD  Unknown1,
_In_ DWORD  Unknown2,
_In_ PWSTR  AdapterName,
_In_ PDHCP_PNP_EVENT  PnpEvent,
_In_ DWORD  Unknown5 
)

Notify the DHCP client of PNP events

Parameters
[in]Unknown1Unknown
[in]Unknown2Unknown
[in]AdapterNameName (GUID) of the Adapter
[in]PnpEventUnknown
[in]Unknown5Unknown
Returns
ERROR_SUCCESS on success
Remarks
Undocumented by Microsoft

Definition at line 351 of file dhcpcsvc.c.

357{
358 DWORD dwError = ERROR_SUCCESS;
359
360 DPRINT1("DhcpHandlePnPEvent(%lx %lx %S %p %lx)\n",
361 Unknown1, Unknown2, AdapterName, PnpEvent, Unknown5);
362
363 if ((Unknown1 != 0) || (Unknown2 != 1) || (PnpEvent == NULL) || (Unknown5 != 0))
365
366 if (PnpEvent->Unknown5)
367 {
368 dwError = SetBinaryClassId(AdapterName);
369 }
370
371 return dwError;
372}
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES IN DWORD IN DWORD IN DWORD Unknown5
Definition: conport.c:39
static DWORD SetBinaryClassId(_In_ PWSTR pszAdapterName)
Definition: dhcpcsvc.c:93
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101

Referenced by SetClassId().

◆ DhcpNotifyConfigChange()

DWORD APIENTRY DhcpNotifyConfigChange ( _In_ LPWSTR  ServerName,
_In_ LPWSTR  AdapterName,
_In_ BOOL  NewIpAddress,
_In_ DWORD  IpIndex,
_In_ DWORD  IpAddress,
_In_ DWORD  SubnetMask,
_In_ INT  DhcpAction 
)

Set new TCP/IP parameters and notify DHCP client service of this

Parameters
[in]ServerNameNULL for local machine
[in]AdapterNameIPHLPAPI name of adapter to change
[in]NewIpAddressTRUE if IP address changes
[in]IpIndex...
[in]IpAddressNew IP address (network byte order)
[in]SubnetMaskNew subnet mask (network byte order)
[in]DhcpAction0 - don't modify 1 - enable DHCP 2 - disable DHCP
Returns
ERROR_SUCCESS on success
Remarks
Undocumented by Microsoft

Definition at line 406 of file dhcpcsvc.c.

414{
415 DPRINT1("DHCPCSVC: DhcpNotifyConfigChange not implemented yet\n");
416 DPRINT1("DhcpNotifyConfigChange(%S %S %lu %lu %lu %lu %d)\n",
417 ServerName, AdapterName, NewIpAddress, IpIndex, IpAddress, SubnetMask, DhcpAction);
418
419 if (AdapterName == NULL)
421
423 return ERROR_SUCCESS;
424}
#define UNIMPLEMENTED
Definition: ntoskrnl.c:15

◆ DhcpQueryHWInfo()

DWORD APIENTRY DhcpQueryHWInfo ( DWORD  AdapterIndex,
PDWORD  MediaType,
PDWORD  Mtu,
PDWORD  Speed 
)

Definition at line 427 of file dhcpcsvc.c.

431{
432 DWORD ret;
433
434 DPRINT("DhcpQueryHWInfo()\n");
435
437 {
438 ret = Client_QueryHWInfo(NULL, AdapterIndex, MediaType, Mtu, Speed);
439 }
441 {
443 }
445
446 return (ret == ERROR_SUCCESS) ? 1 : 0;
447}

◆ DhcpReleaseParameters()

DWORD APIENTRY DhcpReleaseParameters ( _In_ PWSTR  AdapterName)

Releases a DHCP Lease

Parameters
[in]AdapterNameName (GUID) of the Adapter
Returns
ERROR_SUCCESS on success
Remarks
Undocumented by Microsoft

Definition at line 461 of file dhcpcsvc.c.

463{
464 DWORD ret;
465
466 DPRINT("DhcpReleaseParameters(%S)\n", AdapterName);
467
469 {
470 ret = Client_ReleaseParameters(NULL, AdapterName);
471 }
473 {
475 }
477
478 return ret;
479}

Referenced by IpReleaseAddress(), and Release().

◆ DhcpRemoveDNSRegistrations()

DWORD WINAPI DhcpRemoveDNSRegistrations ( VOID  )

Removes all DNS Registrations which were added by the DHCP Client

Returns
ERROR_SUCCESS on success

Definition at line 488 of file dhcpcsvc.c.

489{
490 DWORD ret;
491
492 DPRINT("DhcpRemoveDNSRegistrations()\n");
493
495 {
496 ret = Client_RemoveDNSRegistrations(NULL);
497 }
499 {
501 }
503
504 return ret;
505}

◆ DhcpRequestParams()

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 
)

Definition at line 532 of file dhcpcsvc.c.

541{
543 return 0;
544}

Referenced by detect_autoproxyconfig_url_dhcp(), and detect_proxy_autoconfig_url_dhcp().

◆ DhcpStaticRefreshParams()

DWORD APIENTRY DhcpStaticRefreshParams ( DWORD  AdapterIndex,
DWORD  Address,
DWORD  Netmask 
)

Definition at line 509 of file dhcpcsvc.c.

512{
513 DWORD ret;
514
515 DPRINT("DhcpStaticRefreshParams()\n");
516
518 {
519 ret = Client_StaticRefreshParams(NULL, AdapterIndex, Address, Netmask);
520 }
522 {
524 }
526
527 return (ret == ERROR_SUCCESS) ? 1 : 0;
528}
static WCHAR Address[46]
Definition: ping.c:68

Referenced by INetCfgComponentControl_fnApplyPnpChanges().

◆ DllMain()

BOOL WINAPI DllMain ( HINSTANCE  hinstDLL,
DWORD  fdwReason,
LPVOID  lpvReserved 
)

Definition at line 712 of file dhcpcsvc.c.

715{
716 switch (fdwReason)
717 {
720 break;
721
723 break;
724 }
725
726 return TRUE;
727}
static DWORD const fdwReason
#define TRUE
Definition: types.h:120
#define DLL_PROCESS_ATTACH
Definition: compat.h:131
#define DLL_PROCESS_DETACH
Definition: compat.h:130
BOOL WINAPI DisableThreadLibraryCalls(IN HMODULE hLibModule)
Definition: loader.c:85

◆ MIDL_user_allocate()

void __RPC_FAR *__RPC_USER MIDL_user_allocate ( SIZE_T  len)

◆ MIDL_user_free()

void __RPC_USER MIDL_user_free ( void __RPC_FAR ptr)

Definition at line 31 of file dhcpcsvc.c.

32{
34}
#define HeapFree(x, y, z)
Definition: compat.h:735
static PVOID ptr
Definition: dispmode.c:27

Referenced by DsAddressToSiteNamesExW(), DsAddressToSiteNamesW(), DsGetDcSiteCoverageW(), free_pyramid_doub_carr(), LsaEnumerateAccountRights(), LsaEnumerateAccounts(), LsaEnumerateAccountsWithUserRight(), LsaEnumeratePrivileges(), LsaEnumerateTrustedDomains(), LsaEnumerateTrustedDomainsEx(), LsaGetRemoteUserName(), LsaGetUserName(), LsaLookupNames(), LsaLookupNames2(), LsaLookupPrivilegeDisplayName(), LsaLookupPrivilegeName(), LsaLookupSids(), LsapAddAuthorityToDomainsList(), LsapAddDomainToDomainsList(), LsapLookupAccountRightName(), LsapLookupFullyQualifiedWellKnownNames(), LsapLookupIsolatedNames(), LsapLookupNames(), LsapLookupSids(), LsapSplitNames(), LsaQueryDomainInformationPolicy(), LsaQueryInformationPolicy(), LsaQueryInfoTrustedDomain(), LsarAddPrivilegesToAccount(), LsarEnumerateAccountRights(), LsarEnumeratePrivilegesAccount(), LsarLookupNames(), LsarLookupNames2(), LsarLookupSids(), LsarpEnumeratePrivileges(), LsarpLookupPrivilegeDisplayName(), LsarpLookupPrivilegeName(), LsarQueryAccountDomain(), LsarQueryAuditEvents(), LsarQueryAuditFull(), LsarQueryAuditLog(), LsarQueryDefaultQuota(), LsarQueryDnsDomain(), LsarQueryModification(), LsarQueryPrimaryDomain(), LsarQuerySecurityObject(), LsarQueryServerRole(), LsarRemovePrivilegesFromAccount(), LsarSetAuditFull(), LsaSetSecurityObject(), pointer_tests(), SamGetGroupsForUser(), SamGetMembersInGroup(), SamIFree_SAMPR_ALIAS_INFO_BUFFER(), SamIFree_SAMPR_DISPLAY_INFO_BUFFER(), SamIFree_SAMPR_DOMAIN_INFO_BUFFER(), SamIFree_SAMPR_ENUMERATION_BUFFER(), SamIFree_SAMPR_GET_GROUPS_BUFFER(), SamIFree_SAMPR_GET_MEMBERS_BUFFER(), SamIFree_SAMPR_GROUP_INFO_BUFFER(), SamIFree_SAMPR_PSID_ARRAY(), SamIFree_SAMPR_RETURNED_USTRING_ARRAY(), SamIFree_SAMPR_SR_SECURITY_DESCRIPTOR(), SamIFree_SAMPR_ULONG_ARRAY(), SamIFree_SAMPR_USER_INFO_BUFFER(), SamIFreeVoid(), SamrQuerySecurityObject(), SamSetSecurityObject(), and ScmGetServiceNameFromTag().

◆ PDHCP_SERVER_NAME_bind()

handle_t __RPC_USER PDHCP_SERVER_NAME_bind ( _In_ PDHCP_SERVER_NAME  pszServerName)

Definition at line 37 of file dhcpcsvc.c.

39{
41 LPWSTR pszStringBinding;
43
44 DPRINT("PDHCP_SERVER_NAME_bind() called\n");
45
47 L"ncacn_np",
48 pszServerName,
49 L"\\pipe\\dhcpcsvc",
50 NULL,
51 &pszStringBinding);
52 if (status)
53 {
54 DPRINT1("RpcStringBindingCompose returned 0x%x\n", status);
55 return NULL;
56 }
57
58 /* Set the binding handle that will be used to bind to the server. */
59 status = RpcBindingFromStringBindingW(pszStringBinding,
60 &hBinding);
61 if (status)
62 {
63 DPRINT1("RpcBindingFromStringBinding returned 0x%x\n", status);
64 }
65
66 status = RpcStringFreeW(&pszStringBinding);
67 if (status)
68 {
69 DPRINT1("RpcStringFree returned 0x%x\n", status);
70 }
71
72 return hBinding;
73}
handle_t hBinding
Definition: ctx_c.c:54
#define L(x)
Definition: resources.c:13
RPC_STATUS WINAPI RpcBindingFromStringBindingW(RPC_WSTR StringBinding, RPC_BINDING_HANDLE *Binding)
Definition: rpc_binding.c:862
RPC_STATUS WINAPI RpcStringBindingComposeW(RPC_WSTR ObjUuid, RPC_WSTR Protseq, RPC_WSTR NetworkAddr, RPC_WSTR Endpoint, RPC_WSTR Options, RPC_WSTR *StringBinding)
Definition: rpc_binding.c:493
RPC_STATUS WINAPI RpcStringFreeW(RPC_WSTR *String)
Definition: rpcrt4_main.c:181
long RPC_STATUS
Definition: rpc.h:48
Definition: ps.c:97
uint16_t * LPWSTR
Definition: typedefs.h:56

◆ PDHCP_SERVER_NAME_unbind()

void __RPC_USER PDHCP_SERVER_NAME_unbind ( _In_ PDHCP_SERVER_NAME  pszServerName,
_In_ handle_t  hBinding 
)

Definition at line 76 of file dhcpcsvc.c.

79{
81
82 DPRINT("PDHCP_SERVER_NAME_unbind() called\n");
83
85 if (status)
86 {
87 DPRINT1("RpcBindingFree returned 0x%x\n", status);
88 }
89}
RPC_STATUS WINAPI RpcBindingFree(RPC_BINDING_HANDLE *Binding)
Definition: rpc_binding.c:769

◆ ServiceControlHandler()

static DWORD WINAPI ServiceControlHandler ( DWORD  dwControl,
DWORD  dwEventType,
LPVOID  lpEventData,
LPVOID  lpContext 
)
static

Definition at line 572 of file dhcpcsvc.c.

576{
577 switch (dwControl)
578 {
582 if (hStopEvent != NULL)
584 return ERROR_SUCCESS;
585
589 return ERROR_SUCCESS;
590
591 default:
593 }
594}
static VOID UpdateServiceStatus(DWORD dwState)
Definition: dhcpcsvc.c:547
SERVICE_STATUS_HANDLE ServiceStatusHandle
Definition: dhcpcsvc.c:18
HANDLE hStopEvent
Definition: dhcpcsvc.c:20
SERVICE_STATUS ServiceStatus
Definition: dhcpcsvc.c:19
#define ERROR_CALL_NOT_IMPLEMENTED
Definition: compat.h:102
#define SERVICE_STOP_PENDING
Definition: winsvc.h:23
#define SERVICE_CONTROL_SHUTDOWN
Definition: winsvc.h:46
#define SERVICE_CONTROL_STOP
Definition: winsvc.h:42
#define SERVICE_CONTROL_INTERROGATE
Definition: winsvc.h:45
BOOL WINAPI SetServiceStatus(SERVICE_STATUS_HANDLE hServiceStatus, LPSERVICE_STATUS lpServiceStatus)
Definition: sctrl.c:1016
BOOL WINAPI DECLSPEC_HOTPATCH SetEvent(IN HANDLE hEvent)
Definition: synch.c:669

Referenced by ServiceMain().

◆ ServiceMain()

static VOID CALLBACK ServiceMain ( DWORD  argc,
LPWSTR argv 
)

Definition at line 597 of file dhcpcsvc.c.

598{
599 HANDLE hPipeThread = INVALID_HANDLE_VALUE;
600 HANDLE hDiscoveryThread = INVALID_HANDLE_VALUE;
601 DWORD ret;
602
605 NULL);
607 {
608 DPRINT1("DHCPCSVC: Unable to register service control handler (%lx)\n", GetLastError());
609 return;
610 }
611
613
614 /* Create the stop event */
616 if (hStopEvent == NULL)
617 {
619 return;
620 }
621
624 {
627 return;
628 }
629
631
632 if (!init_client())
633 {
634 DbgPrint("DHCPCSVC: init_client() failed!\n");
638 return;
639 }
640
642
643 hPipeThread = InitRpc();
644 if (hPipeThread == INVALID_HANDLE_VALUE)
645 {
646 DbgPrint("DHCPCSVC: PipeInit() failed!\n");
647 stop_client();
651 return;
652 }
653
654 hDiscoveryThread = StartAdapterDiscovery(hStopEvent);
655 if (hDiscoveryThread == INVALID_HANDLE_VALUE)
656 {
657 DbgPrint("DHCPCSVC: StartAdapterDiscovery() failed!\n");
658 ShutdownRpc();
659 stop_client();
663 return;
664 }
665
666 DH_DbgPrint(MID_TRACE,("DHCP Service Started\n"));
667
669
670 DH_DbgPrint(MID_TRACE,("Going into dispatch()\n"));
671 DH_DbgPrint(MID_TRACE,("DHCPCSVC: DHCP service is starting up\n"));
672
674
675 DH_DbgPrint(MID_TRACE,("DHCPCSVC: DHCP service is shutting down\n"));
676
677 ShutdownRpc();
678 stop_client();
679
680 DPRINT("Wait for pipe thread to close! %p\n", hPipeThread);
681 if (hPipeThread != INVALID_HANDLE_VALUE)
682 {
683 DPRINT("Waiting for pipe thread\n");
684 ret = WaitForSingleObject(hPipeThread, 5000);
685 DPRINT("Done %lx\n", ret);
686 }
687
688 DPRINT("Wait for discovery thread to close! %p\n", hDiscoveryThread);
689 if (hDiscoveryThread != INVALID_HANDLE_VALUE)
690 {
691 DPRINT("Waiting for discovery thread\n");
692 ret = WaitForSingleObject(hDiscoveryThread, 5000);
693 DPRINT("Done %lx\n", ret);
694 }
695
696 DPRINT("Closing events!\n");
699
702
703 CloseHandle(hDiscoveryThread);
704 CloseHandle(hPipeThread);
705
706 DPRINT("Done!\n");
707
709}
HANDLE StartAdapterDiscovery(HANDLE hStopEvent)
Definition: adapter.c:591
VOID ShutdownRpc(VOID)
Definition: api.c:71
HANDLE InitRpc(VOID)
Definition: api.c:65
void dispatch(HANDLE hStopEvent)
Definition: dispatch.c:70
#define MID_TRACE
Definition: debug.h:15
#define DH_DbgPrint(_t_, _x_)
Definition: debug.h:49
int init_client(void)
Definition: dhclient.c:111
void stop_client(void)
Definition: dhclient.c:129
static WCHAR ServiceName[]
Definition: dhcpcsvc.c:16
HANDLE hAdapterStateChangedEvent
Definition: dhcpcsvc.c:21
SOCKET DhcpSocket
Definition: adapter.c:8
static DWORD WINAPI ServiceControlHandler(DWORD dwControl, DWORD dwEventType, LPVOID lpEventData, LPVOID lpContext)
Definition: dhcpcsvc.c:572
#define FALSE
Definition: types.h:117
#define CloseHandle
Definition: compat.h:739
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define DbgPrint
Definition: hal.h:12
#define closesocket
Definition: ncftp.h:477
#define SERVICE_STOPPED
Definition: winsvc.h:21
#define SERVICE_START_PENDING
Definition: winsvc.h:22
#define SERVICE_RUNNING
Definition: winsvc.h:24
SERVICE_STATUS_HANDLE WINAPI RegisterServiceCtrlHandlerExW(LPCWSTR lpServiceName, LPHANDLER_FUNCTION_EX lpHandlerProc, LPVOID lpContext)
Definition: sctrl.c:831
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
HANDLE WINAPI DECLSPEC_HOTPATCH CreateEventW(IN LPSECURITY_ATTRIBUTES lpEventAttributes OPTIONAL, IN BOOL bManualReset, IN BOOL bInitialState, IN LPCWSTR lpName OPTIONAL)
Definition: synch.c:587
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define CreateEvent
Definition: winbase.h:3497
#define INVALID_SOCKET
Definition: winsock.h:326

◆ SetBinaryClassId()

static DWORD SetBinaryClassId ( _In_ PWSTR  pszAdapterName)
static

Definition at line 93 of file dhcpcsvc.c.

95{
96 WCHAR szKeyName[256];
97 PWSTR pszUnicodeBuffer = NULL;
98 PSZ pszAnsiBuffer = NULL;
99 DWORD dwUnicodeSize = 0, dwAnsiSize = 0;
100 HKEY hKey = NULL;
101 DWORD dwError = ERROR_SUCCESS;
102
103 DPRINT("SetBinaryClassId(%S)\n", pszAdapterName);
104
105 _swprintf(szKeyName,
106 L"System\\CurrentControlSet\\Services\\Tcpip\\Parameters\\Interfaces\\%s",
107 pszAdapterName);
108 DPRINT("KeyName %S\n", szKeyName);
109
111 szKeyName,
112 0,
114 &hKey);
115 if (dwError != ERROR_SUCCESS)
116 {
117 DPRINT1("Error %lu\n", dwError);
118 return dwError;
119 }
120
122 L"DhcpClassId",
123 NULL,
124 NULL,
125 NULL,
126 &dwUnicodeSize);
127 DPRINT("UnicodeSize %lu\n", dwUnicodeSize);
128
129 pszUnicodeBuffer = HeapAlloc(GetProcessHeap(), 0, dwUnicodeSize);
130 if (pszUnicodeBuffer == NULL)
131 {
132 dwError = ERROR_NOT_ENOUGH_MEMORY;
133 DPRINT1("Error %lu\n", dwError);
134 goto done;
135 }
136
137 dwError = RegQueryValueExW(hKey,
138 L"DhcpClassId",
139 NULL,
140 NULL,
141 (PBYTE)pszUnicodeBuffer,
142 &dwUnicodeSize);
143 if (dwError != ERROR_SUCCESS)
144 {
145 DPRINT1("Error %lu\n", dwError);
146 goto done;
147 }
148
149 dwAnsiSize = WideCharToMultiByte(CP_ACP,
150 0,
151 pszUnicodeBuffer,
152 -1,
153 NULL,
154 0,
155 NULL,
156 NULL);
157 DPRINT("AnsiSize %lu\n", dwAnsiSize);
158
159 pszAnsiBuffer = HeapAlloc(GetProcessHeap(), 0, dwAnsiSize);
160 if (pszAnsiBuffer == NULL)
161 {
162 dwError = ERROR_NOT_ENOUGH_MEMORY;
163 DPRINT1("Error %lu\n", dwError);
164 goto done;
165 }
166
168 0,
169 pszUnicodeBuffer,
170 -1,
171 pszAnsiBuffer,
172 dwAnsiSize,
173 NULL,
174 NULL);
175 DPRINT("AnsiBuffer %s\n", pszAnsiBuffer);
176
177 dwError = RegSetValueExW(hKey,
178 L"DhcpClassIdBin",
179 0,
181 (PBYTE)pszAnsiBuffer,
182 strlen(pszAnsiBuffer));
183 if (dwError != ERROR_SUCCESS)
184 {
185 DPRINT1("Error %lu\n", dwError);
186 }
187
188done:
189 if (hKey)
191
192 if (pszAnsiBuffer)
193 HeapFree(GetProcessHeap(), 0, pszAnsiBuffer);
194
195 if (pszUnicodeBuffer)
196 HeapFree(GetProcessHeap(), 0, pszUnicodeBuffer);
197
198 return dwError;
199}
#define RegCloseKey(hKey)
Definition: registry.h:49
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3333
LONG WINAPI RegSetValueExW(_In_ HKEY hKey, _In_ LPCWSTR lpValueName, _In_ DWORD Reserved, _In_ DWORD dwType, _In_ CONST BYTE *lpData, _In_ DWORD cbData)
Definition: reg.c:4882
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4103
#define CP_ACP
Definition: compat.h:109
#define WideCharToMultiByte
Definition: compat.h:111
_ACRTIMP size_t __cdecl strlen(const char *)
Definition: string.c:1592
int WINAPIV _swprintf(wchar_t *str, const wchar_t *format,...)
Definition: wcs.c:1687
FxAutoRegKey hKey
_Null_terminated_ char * PSZ
Definition: minwindef.h:56
#define REG_BINARY
Definition: nt_native.h:1499
#define KEY_QUERY_VALUE
Definition: nt_native.h:1019
#define KEY_SET_VALUE
Definition: nt_native.h:1020
BYTE * PBYTE
Definition: pedump.c:66
short WCHAR
Definition: pedump.c:58
uint16_t * PWSTR
Definition: typedefs.h:56
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12

Referenced by DhcpHandlePnPEvent().

◆ UpdateServiceStatus()

static VOID UpdateServiceStatus ( DWORD  dwState)
static

Definition at line 547 of file dhcpcsvc.c.

548{
551
552 if (dwState == SERVICE_RUNNING)
554 else
556
560
561 if (dwState == SERVICE_START_PENDING ||
562 dwState == SERVICE_STOP_PENDING)
564 else
566
569}
#define SERVICE_ACCEPT_STOP
Definition: winsvc.h:28
#define SERVICE_ACCEPT_SHUTDOWN
Definition: winsvc.h:30
DWORD dwServiceType
Definition: winsvc.h:105
DWORD dwWin32ExitCode
Definition: winsvc.h:108
DWORD dwControlsAccepted
Definition: winsvc.h:107
DWORD dwWaitHint
Definition: winsvc.h:111
DWORD dwCurrentState
Definition: winsvc.h:106
DWORD dwCheckPoint
Definition: winsvc.h:110
DWORD dwServiceSpecificExitCode
Definition: winsvc.h:109
#define SERVICE_WIN32_SHARE_PROCESS
Definition: cmtypes.h:963

Referenced by ServiceControlHandler(), and ServiceMain().

Variable Documentation

◆ DhcpSocket

SOCKET DhcpSocket
extern

Definition at line 8 of file adapter.c.

Referenced by AdapterDiscoveryThread(), and ServiceMain().

◆ hAdapterStateChangedEvent

◆ hStopEvent

◆ ServiceName

WCHAR ServiceName[] = L"DHCP"
static

Definition at line 16 of file dhcpcsvc.c.

Referenced by ServiceMain().

◆ ServiceStatus

SERVICE_STATUS ServiceStatus

Definition at line 19 of file dhcpcsvc.c.

Referenced by ServiceControlHandler(), and UpdateServiceStatus().

◆ ServiceStatusHandle

SERVICE_STATUS_HANDLE ServiceStatusHandle = 0

Definition at line 18 of file dhcpcsvc.c.

Referenced by ServiceControlHandler(), ServiceMain(), and UpdateServiceStatus().