ReactOS 0.4.17-dev-243-g1369312
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 DhcpDeRegisterParamChange (_In_ DWORD Flags, _In_ LPVOID Reserved, _In_ LPVOID Event)
 
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 DhcpRegisterParamChange (_In_ DWORD Flags, _In_ LPVOID Reserved, _In_ LPWSTR AdapterName, _In_ LPDHCPCAPI_CLASSID ClassId, _In_ DHCPCAPI_PARAMS_ARRAY Params, _Inout_ LPVOID Handle)
 
DWORD APIENTRY DhcpReleaseParameters (_In_ PWSTR AdapterName)
 
DWORD APIENTRY DhcpRemoveDNSRegistrations (VOID)
 
DWORD APIENTRY DhcpRequestParams (_In_ DWORD Flags, _In_ PVOID Reserved, _In_ LPWSTR AdapterName, _In_ LPDHCPCAPI_CLASSID ClassId, _In_ DHCPCAPI_PARAMS_ARRAY SendParams, _Inout_ DHCPCAPI_PARAMS_ARRAY RecdParams, _In_ LPBYTE Buffer, _Inout_ LPDWORD pSize, _In_ LPWSTR RequestIdStr)
 
DWORD APIENTRY DhcpStaticRefreshParams (DWORD AdapterIndex, DWORD Address, DWORD Netmask)
 
DWORD APIENTRY DhcpUndoRequestParams (_In_ DWORD Flags, _In_ LPVOID Reserved, _In_ LPWSTR AdapterName, _In_ 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().

◆ DhcpDeRegisterParamChange()

DWORD APIENTRY DhcpDeRegisterParamChange ( _In_ DWORD  Flags,
_In_ LPVOID  Reserved,
_In_ LPVOID  Event 
)

Definition at line 297 of file dhcpcsvc.c.

301{
303 return 0;
304}
#define UNIMPLEMENTED
Definition: ntoskrnl.c:15

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

332{
333 DPRINT1("DhcpEnumClasses(%lx %S %lx %lx)\n",
334 Unknown1, AdapterName, Unknown3, Unknown4);
335 return 0;
336}
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 350 of file dhcpcsvc.c.

352{
353 DWORD ret;
354
355 DPRINT("DhcpFallbackRefreshParams(%S)\n", AdapterName);
356
358 {
359 ret = Client_FallbackRefreshParams(NULL, AdapterName);
360 }
362 {
364 }
366
367 return ret;
368}

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

400{
401 DWORD dwError = ERROR_SUCCESS;
402
403 DPRINT1("DhcpHandlePnPEvent(%lx %lx %S %p %lx)\n",
404 Unknown1, Unknown2, AdapterName, PnpEvent, Unknown5);
405
406 if ((Unknown1 != 0) || (Unknown2 != 1) || (PnpEvent == NULL) || (Unknown5 != 0))
408
409 if (PnpEvent->Unknown5)
410 {
411 dwError = SetBinaryClassId(AdapterName);
412 }
413
414 return dwError;
415}
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 449 of file dhcpcsvc.c.

457{
458 DPRINT("DhcpNotifyConfigChange(%S %S %lu %lu %lu %lu %d)\n",
459 ServerName, AdapterName, NewIpAddress, IpIndex, IpAddress, SubnetMask, DhcpAction);
460 return DhcpNotifyConfigChangeEx(ServerName, AdapterName, NewIpAddress,
461 IpIndex, IpAddress, SubnetMask, DhcpAction, 0);
462}
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:499

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

508{
510
511 DPRINT1("DHCPCSVC: DhcpNotifyConfigChangeEx not implemented yet\n");
512 DPRINT1("DhcpNotifyConfigChangeEx(%S %S %lu %lu %lu %lu %d %lu)\n",
513 ServerName, AdapterName, NewIpAddress, IpIndex, IpAddress, SubnetMask, DhcpAction, Unknown8);
514
515 if (AdapterName == NULL)
517
518 if (DhcpAction == 1) // Enable DHCP
519 {
520 if ((NewIpAddress != FALSE) ||
521 (IpIndex != 0) ||
522 (IpAddress != 0) ||
523 (SubnetMask != 0))
525 }
526 else if (DhcpAction == 2) // Disable DHCP
527 {
528 if ((NewIpAddress == FALSE) ||
529 (IpIndex != 0) ||
530 (IpAddress == 0) ||
531 (SubnetMask == 0))
533 }
534 else if (DhcpAction == 0) // Do not modify
535 {
536
537 }
538 else
539 {
541 }
542
543 if (DhcpAction == 1) // Enable DHCP
544 {
545 /* TODO: Remove static IP address(es) */
546
548 {
549 ret = Server_EnableDhcp(ServerName, AdapterName, TRUE);
550 }
552 {
554 }
556 }
557 else if (DhcpAction == 2) // Disable DHCP
558 {
560 {
561 ret = Server_EnableDhcp(ServerName, AdapterName, FALSE);
562 }
564 {
566 }
568 }
569 else if (DhcpAction == 0) // Do not modify
570 {
571
572 }
573
574 return ret;
575}
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().

◆ DhcpRegisterParamChange()

DWORD APIENTRY DhcpRegisterParamChange ( _In_ DWORD  Flags,
_In_ LPVOID  Reserved,
_In_ LPWSTR  AdapterName,
_In_ LPDHCPCAPI_CLASSID  ClassId,
_In_ DHCPCAPI_PARAMS_ARRAY  Params,
_Inout_ LPVOID  Handle 
)

Definition at line 579 of file dhcpcsvc.c.

586{
587 DPRINT1("DhcpRegisterParamChange(%lx %p %S)\n", Flags, Reserved, AdapterName);
588
591
592 if ((Reserved != NULL) || (AdapterName == NULL) || (Handle == NULL))
594
596 return 0;
597}
#define DHCPCAPI_REGISTER_HANDLE_EVENT
Definition: dhcpcsdk.h:126
ULONG Handle
Definition: gdb_input.c:15
_Reserved_ PVOID Reserved
Definition: winddi.h:3974
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170

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

613{
614 DWORD ret;
615
616 DPRINT("DhcpReleaseParameters(%S)\n", AdapterName);
617
619 {
620 ret = Client_ReleaseParameters(NULL, AdapterName);
621 }
623 {
625 }
627
628 return ret;
629}

Referenced by IpReleaseAddress(), and Release().

◆ DhcpRemoveDNSRegistrations()

DWORD APIENTRY DhcpRemoveDNSRegistrations ( VOID  )

Removes all DNS Registrations which were added by the DHCP Client

Returns
ERROR_SUCCESS on success

Definition at line 638 of file dhcpcsvc.c.

639{
640 DWORD ret;
641
642 DPRINT("DhcpRemoveDNSRegistrations()\n");
643
645 {
646 ret = Client_RemoveDNSRegistrations(NULL);
647 }
649 {
651 }
653
654 return ret;
655}

◆ DhcpRequestParams()

DWORD APIENTRY DhcpRequestParams ( _In_ DWORD  Flags,
_In_ PVOID  Reserved,
_In_ LPWSTR  AdapterName,
_In_ LPDHCPCAPI_CLASSID  ClassId,
_In_ DHCPCAPI_PARAMS_ARRAY  SendParams,
_Inout_ DHCPCAPI_PARAMS_ARRAY  RecdParams,
_In_ LPBYTE  Buffer,
_Inout_ LPDWORD  pSize,
_In_ LPWSTR  RequestIdStr 
)

Definition at line 659 of file dhcpcsvc.c.

669{
671
672 DPRINT1("DhcpRequestParams(%lx %p %S %p %lu %p %lu %p %p %p %S)\n",
673 Flags, Reserved, AdapterName, ClassId, SendParams.nParams, SendParams.Params,
674 RecdParams.nParams, RecdParams.Params, Buffer, pSize, RequestIdStr);
675
680
681 if ((Reserved != NULL) || (AdapterName == NULL))
683
684 if (ClassId != NULL)
685 {
686 if (ClassId->Flags != 0)
688
689 if ((ClassId->Data == NULL) || (ClassId->nBytesData == 0))
691 }
692
693 if ((SendParams.nParams != 0) && (SendParams.Params == NULL))
695
696 if (RecdParams.Params == NULL)
698
700 {
701 ret = Client_RequestParams(NULL,
703 ClassId,
704 &SendParams,
705 0,
706 0);
707 }
709 {
711 }
713
714 return ret;
715}
Definition: bufpool.h:45
#define DHCPCAPI_REQUEST_SYNCHRONOUS
Definition: dhcpcsdk.h:129
#define DHCPCAPI_REQUEST_PERSISTENT
Definition: dhcpcsdk.h:128

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

722{
723 DWORD ret;
724
725 DPRINT("DhcpStaticRefreshParams()\n");
726
728 {
729 ret = Client_StaticRefreshParams(NULL, AdapterIndex, Address, Netmask);
730 }
732 {
734 }
736
737 return (ret == ERROR_SUCCESS) ? 1 : 0;
738}
static WCHAR Address[46]
Definition: ping.c:68

Referenced by INetCfgComponentControl_fnApplyPnpChanges().

◆ DhcpUndoRequestParams()

DWORD APIENTRY DhcpUndoRequestParams ( _In_ DWORD  Flags,
_In_ LPVOID  Reserved,
_In_ LPWSTR  AdapterName,
_In_ LPWSTR  RequestIdStr 
)

Definition at line 742 of file dhcpcsvc.c.

747{
748 DPRINT1("DhcpUndoRequestParams(%lx %p %S %S)\n",
749 Flags, Reserved, AdapterName, RequestIdStr);
750
751 if ((Flags != 0) || (Reserved != NULL) || (RequestIdStr == NULL))
753
755 return STATUS_SUCCESS;
756}
#define STATUS_SUCCESS
Definition: shellext.h:65

◆ DllMain()

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

Definition at line 924 of file dhcpcsvc.c.

927{
928 switch (fdwReason)
929 {
932 break;
933
935 break;
936 }
937
938 return TRUE;
939}
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 784 of file dhcpcsvc.c.

788{
789 switch (dwControl)
790 {
794 if (hStopEvent != NULL)
796 return ERROR_SUCCESS;
797
801 return ERROR_SUCCESS;
802
803 default:
805 }
806}
static VOID UpdateServiceStatus(DWORD dwState)
Definition: dhcpcsvc.c:759
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 809 of file dhcpcsvc.c.

810{
811 HANDLE hPipeThread = INVALID_HANDLE_VALUE;
812 HANDLE hDiscoveryThread = INVALID_HANDLE_VALUE;
813 DWORD ret;
814
817 NULL);
819 {
820 DPRINT1("DHCPCSVC: Unable to register service control handler (%lx)\n", GetLastError());
821 return;
822 }
823
825
826 /* Create the stop event */
828 if (hStopEvent == NULL)
829 {
831 return;
832 }
833
836 {
839 return;
840 }
841
843
844 if (!init_client())
845 {
846 DbgPrint("DHCPCSVC: init_client() failed!\n");
850 return;
851 }
852
854
855 hPipeThread = InitRpc();
856 if (hPipeThread == INVALID_HANDLE_VALUE)
857 {
858 DbgPrint("DHCPCSVC: PipeInit() failed!\n");
859 stop_client();
863 return;
864 }
865
866 hDiscoveryThread = StartAdapterDiscovery(hStopEvent);
867 if (hDiscoveryThread == INVALID_HANDLE_VALUE)
868 {
869 DbgPrint("DHCPCSVC: StartAdapterDiscovery() failed!\n");
870 ShutdownRpc();
871 stop_client();
875 return;
876 }
877
878 DH_DbgPrint(MID_TRACE,("DHCP Service Started\n"));
879
881
882 DH_DbgPrint(MID_TRACE,("Going into dispatch()\n"));
883 DH_DbgPrint(MID_TRACE,("DHCPCSVC: DHCP service is starting up\n"));
884
886
887 DH_DbgPrint(MID_TRACE,("DHCPCSVC: DHCP service is shutting down\n"));
888
889 ShutdownRpc();
890 stop_client();
891
892 DPRINT("Wait for pipe thread to close! %p\n", hPipeThread);
893 if (hPipeThread != INVALID_HANDLE_VALUE)
894 {
895 DPRINT("Waiting for pipe thread\n");
896 ret = WaitForSingleObject(hPipeThread, 5000);
897 DPRINT("Done %lx\n", ret);
898 }
899
900 DPRINT("Wait for discovery thread to close! %p\n", hDiscoveryThread);
901 if (hDiscoveryThread != INVALID_HANDLE_VALUE)
902 {
903 DPRINT("Waiting for discovery thread\n");
904 ret = WaitForSingleObject(hDiscoveryThread, 5000);
905 DPRINT("Done %lx\n", ret);
906 }
907
908 DPRINT("Closing events!\n");
911
914
915 CloseHandle(hDiscoveryThread);
916 CloseHandle(hPipeThread);
917
918 DPRINT("Done!\n");
919
921}
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:784
#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
FxAutoRegKey hKey
_Null_terminated_ char * PSZ
Definition: minwindef.h:56
#define _swprintf(buf, format,...)
Definition: sprintf.c: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 759 of file dhcpcsvc.c.

760{
763
764 if (dwState == SERVICE_RUNNING)
766 else
768
772
773 if (dwState == SERVICE_START_PENDING ||
774 dwState == SERVICE_STOP_PENDING)
776 else
778
781}
#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().