ReactOS 0.4.16-dev-2613-g9533ad7
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 DhcpAcquireParametersByBroadcast (_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 DhcpNotifyConfigChangeEx (_In_ LPWSTR ServerName, _In_ LPWSTR AdapterName, _In_ BOOL NewIpAddress, _In_ DWORD IpIndex, _In_ DWORD IpAddress, _In_ DWORD SubnetMask, _In_ INT DhcpAction, _In_ DWORD Unknown8)
 
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().

◆ DhcpAcquireParametersByBroadcast()

DWORD APIENTRY DhcpAcquireParametersByBroadcast ( _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 275 of file dhcpcsvc.c.

277{
278 DWORD ret;
279
280 DPRINT("DhcpAcquireParametersByBroadcast(%S)\n", AdapterName);
281
283 {
284 ret = Client_AcquireParametersByBroadcast(NULL, AdapterName);
285 }
287 {
289 }
291
292 return ret;
293}

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

321{
322 DPRINT1("DhcpEnumClasses(%lx %S %lx %lx)\n",
323 Unknown1, AdapterName, Unknown3, Unknown4);
324 return 0;
325}
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 339 of file dhcpcsvc.c.

341{
342 DWORD ret;
343
344 DPRINT("DhcpFallbackRefreshParams(%S)\n", AdapterName);
345
347 {
348 ret = Client_FallbackRefreshParams(NULL, AdapterName);
349 }
351 {
353 }
355
356 return ret;
357}

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

389{
390 DWORD dwError = ERROR_SUCCESS;
391
392 DPRINT1("DhcpHandlePnPEvent(%lx %lx %S %p %lx)\n",
393 Unknown1, Unknown2, AdapterName, PnpEvent, Unknown5);
394
395 if ((Unknown1 != 0) || (Unknown2 != 1) || (PnpEvent == NULL) || (Unknown5 != 0))
397
398 if (PnpEvent->Unknown5)
399 {
400 dwError = SetBinaryClassId(AdapterName);
401 }
402
403 return dwError;
404}
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 438 of file dhcpcsvc.c.

446{
447 DPRINT("DhcpNotifyConfigChange(%S %S %lu %lu %lu %lu %d)\n",
448 ServerName, AdapterName, NewIpAddress, IpIndex, IpAddress, SubnetMask, DhcpAction);
449 return DhcpNotifyConfigChangeEx(ServerName, AdapterName, NewIpAddress,
450 IpIndex, IpAddress, SubnetMask, DhcpAction, 0);
451}
DWORD APIENTRY DhcpNotifyConfigChangeEx(_In_ LPWSTR ServerName, _In_ LPWSTR AdapterName, _In_ BOOL NewIpAddress, _In_ DWORD IpIndex, _In_ DWORD IpAddress, _In_ DWORD SubnetMask, _In_ INT DhcpAction, _In_ DWORD Unknown8)
Definition: dhcpcsvc.c:488

◆ DhcpNotifyConfigChangeEx()

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

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
[in]Unknown8Unknown
Returns
ERROR_SUCCESS on success
Remarks
Undocumented by Microsoft

Definition at line 488 of file dhcpcsvc.c.

497{
499
500 DPRINT1("DHCPCSVC: DhcpNotifyConfigChangeEx not implemented yet\n");
501 DPRINT1("DhcpNotifyConfigChangeEx(%S %S %lu %lu %lu %lu %d %lu)\n",
502 ServerName, AdapterName, NewIpAddress, IpIndex, IpAddress, SubnetMask, DhcpAction, Unknown8);
503
504 if (AdapterName == NULL)
506
507 if (DhcpAction == 1) // Enable DHCP
508 {
509 if ((NewIpAddress != FALSE) ||
510 (IpIndex != 0) ||
511 (IpAddress != 0) ||
512 (SubnetMask != 0))
514 }
515 else if (DhcpAction == 2) // Disable DHCP
516 {
517 if ((NewIpAddress == FALSE) ||
518 (IpIndex != 0) ||
519 (IpAddress == 0) ||
520 (SubnetMask == 0))
522 }
523 else if (DhcpAction == 0) // Do not modify
524 {
525
526 }
527 else
528 {
530 }
531
532 if (DhcpAction == 1) // Enable DHCP
533 {
534 /* TODO: Remove static IP address(es) */
535
537 {
538 ret = Server_EnableDhcp(ServerName, AdapterName, TRUE);
539 }
541 {
543 }
545 }
546 else if (DhcpAction == 2) // Disable DHCP
547 {
549 {
550 ret = Server_EnableDhcp(ServerName, AdapterName, FALSE);
551 }
553 {
555 }
557 }
558 else if (DhcpAction == 0) // Do not modify
559 {
560
561 }
562
563 return ret;
564}
DWORD __stdcall Server_EnableDhcp(_In_ PDHCP_SERVER_NAME ServerName, _In_ LPWSTR AdapterName, _In_ BOOL Enable)
Definition: api.c:81
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117

Referenced by DhcpNotifyConfigChange().

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

580{
581 DWORD ret;
582
583 DPRINT("DhcpReleaseParameters(%S)\n", AdapterName);
584
586 {
587 ret = Client_ReleaseParameters(NULL, AdapterName);
588 }
590 {
592 }
594
595 return ret;
596}

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

606{
607 DWORD ret;
608
609 DPRINT("DhcpRemoveDNSRegistrations()\n");
610
612 {
613 ret = Client_RemoveDNSRegistrations(NULL);
614 }
616 {
618 }
620
621 return ret;
622}

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

658{
660 return 0;
661}
#define UNIMPLEMENTED
Definition: ntoskrnl.c:15

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

629{
630 DWORD ret;
631
632 DPRINT("DhcpStaticRefreshParams()\n");
633
635 {
636 ret = Client_StaticRefreshParams(NULL, AdapterIndex, Address, Netmask);
637 }
639 {
641 }
643
644 return (ret == ERROR_SUCCESS) ? 1 : 0;
645}
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 829 of file dhcpcsvc.c.

832{
833 switch (fdwReason)
834 {
837 break;
838
840 break;
841 }
842
843 return TRUE;
844}
static DWORD const fdwReason
#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 689 of file dhcpcsvc.c.

693{
694 switch (dwControl)
695 {
699 if (hStopEvent != NULL)
701 return ERROR_SUCCESS;
702
706 return ERROR_SUCCESS;
707
708 default:
710 }
711}
static VOID UpdateServiceStatus(DWORD dwState)
Definition: dhcpcsvc.c:664
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 714 of file dhcpcsvc.c.

715{
716 HANDLE hPipeThread = INVALID_HANDLE_VALUE;
717 HANDLE hDiscoveryThread = INVALID_HANDLE_VALUE;
718 DWORD ret;
719
722 NULL);
724 {
725 DPRINT1("DHCPCSVC: Unable to register service control handler (%lx)\n", GetLastError());
726 return;
727 }
728
730
731 /* Create the stop event */
733 if (hStopEvent == NULL)
734 {
736 return;
737 }
738
741 {
744 return;
745 }
746
748
749 if (!init_client())
750 {
751 DbgPrint("DHCPCSVC: init_client() failed!\n");
755 return;
756 }
757
759
760 hPipeThread = InitRpc();
761 if (hPipeThread == INVALID_HANDLE_VALUE)
762 {
763 DbgPrint("DHCPCSVC: PipeInit() failed!\n");
764 stop_client();
768 return;
769 }
770
771 hDiscoveryThread = StartAdapterDiscovery(hStopEvent);
772 if (hDiscoveryThread == INVALID_HANDLE_VALUE)
773 {
774 DbgPrint("DHCPCSVC: StartAdapterDiscovery() failed!\n");
775 ShutdownRpc();
776 stop_client();
780 return;
781 }
782
783 DH_DbgPrint(MID_TRACE,("DHCP Service Started\n"));
784
786
787 DH_DbgPrint(MID_TRACE,("Going into dispatch()\n"));
788 DH_DbgPrint(MID_TRACE,("DHCPCSVC: DHCP service is starting up\n"));
789
791
792 DH_DbgPrint(MID_TRACE,("DHCPCSVC: DHCP service is shutting down\n"));
793
794 ShutdownRpc();
795 stop_client();
796
797 DPRINT("Wait for pipe thread to close! %p\n", hPipeThread);
798 if (hPipeThread != INVALID_HANDLE_VALUE)
799 {
800 DPRINT("Waiting for pipe thread\n");
801 ret = WaitForSingleObject(hPipeThread, 5000);
802 DPRINT("Done %lx\n", ret);
803 }
804
805 DPRINT("Wait for discovery thread to close! %p\n", hDiscoveryThread);
806 if (hDiscoveryThread != INVALID_HANDLE_VALUE)
807 {
808 DPRINT("Waiting for discovery thread\n");
809 ret = WaitForSingleObject(hDiscoveryThread, 5000);
810 DPRINT("Done %lx\n", ret);
811 }
812
813 DPRINT("Closing events!\n");
816
819
820 CloseHandle(hDiscoveryThread);
821 CloseHandle(hPipeThread);
822
823 DPRINT("Done!\n");
824
826}
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:689
#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 664 of file dhcpcsvc.c.

665{
668
669 if (dwState == SERVICE_RUNNING)
671 else
673
677
678 if (dwState == SERVICE_START_PENDING ||
679 dwState == SERVICE_STOP_PENDING)
681 else
683
686}
#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().