ReactOS 0.4.16-dev-2491-g3dc6630
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 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_fnApplyRegistryChanges(), 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_fnApplyRegistryChanges(), 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

◆ DhcpHandlePnPEvent()

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

Enumerates the DHCP user classes for the given adapter

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 319 of file dhcpcsvc.c.

325{
326 DWORD dwError = ERROR_SUCCESS;
327
328 DPRINT1("DhcpHandlePnPEvent(%lx %lx %S %p %lx)\n",
329 Unknown1, Unknown2, AdapterName, PnpEvent, Unknown5);
330
331 if ((Unknown1 != 0) || (Unknown2 != 1) || (PnpEvent == NULL) || (Unknown5 != 0))
333
334 if (PnpEvent->Unknown5)
335 {
336 dwError = SetBinaryClassId(AdapterName);
337 }
338
339 return dwError;
340}
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 374 of file dhcpcsvc.c.

382{
383 DPRINT1("DHCPCSVC: DhcpNotifyConfigChange not implemented yet\n");
384 DPRINT1("DhcpNotifyConfigChange(%S %S %lu %lu %lu %lu %d)\n",
385 ServerName, AdapterName, NewIpAddress, IpIndex, IpAddress, SubnetMask, DhcpAction);
386
387 if (AdapterName == NULL)
389
391 return ERROR_SUCCESS;
392}
#define UNIMPLEMENTED
Definition: ntoskrnl.c:15

◆ DhcpQueryHWInfo()

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

Definition at line 395 of file dhcpcsvc.c.

399{
400 DWORD ret;
401
402 DPRINT("DhcpQueryHWInfo()\n");
403
405 {
406 ret = Client_QueryHWInfo(NULL, AdapterIndex, MediaType, Mtu, Speed);
407 }
409 {
411 }
413
414 return (ret == ERROR_SUCCESS) ? 1 : 0;
415}

◆ 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 429 of file dhcpcsvc.c.

431{
432 DWORD ret;
433
434 DPRINT("DhcpReleaseParameters(%S)\n", AdapterName);
435
437 {
438 ret = Client_ReleaseParameters(NULL, AdapterName);
439 }
441 {
443 }
445
446 return ret;
447}

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 456 of file dhcpcsvc.c.

457{
458 DWORD ret;
459
460 DPRINT("DhcpRemoveDNSRegistrations()\n");
461
463 {
464 ret = Client_RemoveDNSRegistrations(NULL);
465 }
467 {
469 }
471
472 return ret;
473}

◆ 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 500 of file dhcpcsvc.c.

509{
511 return 0;
512}

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 477 of file dhcpcsvc.c.

480{
481 DWORD ret;
482
483 DPRINT("DhcpStaticRefreshParams()\n");
484
486 {
487 ret = Client_StaticRefreshParams(NULL, AdapterIndex, Address, Netmask);
488 }
490 {
492 }
494
495 return (ret == ERROR_SUCCESS) ? 1 : 0;
496}
static WCHAR Address[46]
Definition: ping.c:68

Referenced by INetCfgComponentControl_fnApplyRegistryChanges().

◆ DllMain()

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

Definition at line 680 of file dhcpcsvc.c.

683{
684 switch (fdwReason)
685 {
688 break;
689
691 break;
692 }
693
694 return TRUE;
695}
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
WCHAR * LPWSTR
Definition: xmlstorage.h:184

◆ 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 540 of file dhcpcsvc.c.

544{
545 switch (dwControl)
546 {
550 if (hStopEvent != NULL)
552 return ERROR_SUCCESS;
553
557 return ERROR_SUCCESS;
558
559 default:
561 }
562}
static VOID UpdateServiceStatus(DWORD dwState)
Definition: dhcpcsvc.c:515
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 565 of file dhcpcsvc.c.

566{
567 HANDLE hPipeThread = INVALID_HANDLE_VALUE;
568 HANDLE hDiscoveryThread = INVALID_HANDLE_VALUE;
569 DWORD ret;
570
573 NULL);
575 {
576 DPRINT1("DHCPCSVC: Unable to register service control handler (%lx)\n", GetLastError());
577 return;
578 }
579
581
582 /* Create the stop event */
584 if (hStopEvent == NULL)
585 {
587 return;
588 }
589
592 {
595 return;
596 }
597
599
600 if (!init_client())
601 {
602 DbgPrint("DHCPCSVC: init_client() failed!\n");
606 return;
607 }
608
610
611 hPipeThread = InitRpc();
612 if (hPipeThread == INVALID_HANDLE_VALUE)
613 {
614 DbgPrint("DHCPCSVC: PipeInit() failed!\n");
615 stop_client();
619 return;
620 }
621
622 hDiscoveryThread = StartAdapterDiscovery(hStopEvent);
623 if (hDiscoveryThread == INVALID_HANDLE_VALUE)
624 {
625 DbgPrint("DHCPCSVC: StartAdapterDiscovery() failed!\n");
626 ShutdownRpc();
627 stop_client();
631 return;
632 }
633
634 DH_DbgPrint(MID_TRACE,("DHCP Service Started\n"));
635
637
638 DH_DbgPrint(MID_TRACE,("Going into dispatch()\n"));
639 DH_DbgPrint(MID_TRACE,("DHCPCSVC: DHCP service is starting up\n"));
640
642
643 DH_DbgPrint(MID_TRACE,("DHCPCSVC: DHCP service is shutting down\n"));
644
645 ShutdownRpc();
646 stop_client();
647
648 DPRINT("Wait for pipe thread to close! %p\n", hPipeThread);
649 if (hPipeThread != INVALID_HANDLE_VALUE)
650 {
651 DPRINT("Waiting for pipe thread\n");
652 ret = WaitForSingleObject(hPipeThread, 5000);
653 DPRINT("Done %lx\n", ret);
654 }
655
656 DPRINT("Wait for discovery thread to close! %p\n", hDiscoveryThread);
657 if (hDiscoveryThread != INVALID_HANDLE_VALUE)
658 {
659 DPRINT("Waiting for discovery thread\n");
660 ret = WaitForSingleObject(hDiscoveryThread, 5000);
661 DPRINT("Done %lx\n", ret);
662 }
663
664 DPRINT("Closing events!\n");
667
670
671 CloseHandle(hDiscoveryThread);
672 CloseHandle(hPipeThread);
673
674 DPRINT("Done!\n");
675
677}
HANDLE StartAdapterDiscovery(HANDLE hStopEvent)
Definition: adapter.c:483
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:540
#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
uint16_t * PWSTR
Definition: typedefs.h:56
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by DhcpHandlePnPEvent().

◆ UpdateServiceStatus()

static VOID UpdateServiceStatus ( DWORD  dwState)
static

Definition at line 515 of file dhcpcsvc.c.

516{
519
520 if (dwState == SERVICE_RUNNING)
522 else
524
528
529 if (dwState == SERVICE_START_PENDING ||
530 dwState == SERVICE_STOP_PENDING)
532 else
534
537}
#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().