diff --git a/base/services/dhcpcsvc/dhcp/adapter.c b/base/services/dhcpcsvc/dhcp/adapter.c index 1feab088276..029fc8fe8bc 100644 --- a/base/services/dhcpcsvc/dhcp/adapter.c +++ b/base/services/dhcpcsvc/dhcp/adapter.c @@ -509,7 +509,7 @@ PDHCP_ADAPTER AdapterFindIndex( unsigned int indx ) { return NULL; } -PDHCP_ADAPTER AdapterFindName( const WCHAR *name ) { +PDHCP_ADAPTER AdapterFindName( const CHAR *name ) { PDHCP_ADAPTER Adapter; PLIST_ENTRY ListEntry; @@ -517,7 +517,7 @@ PDHCP_ADAPTER AdapterFindName( const WCHAR *name ) { ListEntry != &AdapterList; ListEntry = ListEntry->Flink ) { Adapter = CONTAINING_RECORD( ListEntry, DHCP_ADAPTER, ListEntry ); - if( !_wcsicmp( Adapter->IfMib.wszName, name ) ) return Adapter; + if( !stricmp((const CHAR*)Adapter->IfMib.bDescr, name ) ) return Adapter; } return NULL; diff --git a/base/services/dhcpcsvc/dhcp/api.c b/base/services/dhcpcsvc/dhcp/api.c index 87ec8ec0713..240c61efb10 100644 --- a/base/services/dhcpcsvc/dhcp/api.c +++ b/base/services/dhcpcsvc/dhcp/api.c @@ -33,6 +33,101 @@ VOID ApiFree() { /* This represents the service portion of the DHCP client API */ +DWORD +DSAcquireParams( + _In_ PipeSendFunc Send, + _In_ HANDLE CommPipe, + _Out_ COMM_DHCP_REQ *Req) +{ + COMM_DHCP_REPLY Reply; + PDHCP_ADAPTER Adapter; + struct protocol* proto; + + DPRINT1("DSAcquireParams()\n"); + + ApiLock(); + + Adapter = AdapterFindName(Req->Body.AcquireParams.AdapterName); + DPRINT1("Adapter: %p\n", Adapter); + + if (Adapter == NULL || Adapter->DhclientState.state == S_STATIC) + { + Reply.Reply = 0; + ApiUnlock(); + return Send(CommPipe, &Reply); + } + + Reply.Reply = 1; + + proto = find_protocol_by_adapter(&Adapter->DhclientInfo); + if (proto) + remove_protocol(proto); + + add_protocol(Adapter->DhclientInfo.name, + Adapter->DhclientInfo.rfdesc, got_one, + &Adapter->DhclientInfo); + + Adapter->DhclientInfo.client->state = S_INIT; + state_reboot(&Adapter->DhclientInfo); + + if (hAdapterStateChangedEvent != NULL) + SetEvent(hAdapterStateChangedEvent); + + ApiUnlock(); + + return Send(CommPipe, &Reply); +} + + +DWORD +DSReleaseParams( + _In_ PipeSendFunc Send, + _In_ HANDLE CommPipe, + _Out_ COMM_DHCP_REQ *Req) +{ + COMM_DHCP_REPLY Reply; + PDHCP_ADAPTER Adapter; + struct protocol* proto; + + DPRINT1("DSReleaseParams()\n"); + + ApiLock(); + + Adapter = AdapterFindName(Req->Body.AcquireParams.AdapterName); + DPRINT1("Adapter: %p\n", Adapter); + + Reply.Reply = Adapter ? 1 : 0; + + if (Adapter) + { + if (Adapter->NteContext) + { + DeleteIPAddress(Adapter->NteContext); + Adapter->NteContext = 0; + } + if (Adapter->RouterMib.dwForwardNextHop) + { + DeleteIpForwardEntry(&Adapter->RouterMib); + Adapter->RouterMib.dwForwardNextHop = 0; + } + + proto = find_protocol_by_adapter(&Adapter->DhclientInfo); + if (proto) + remove_protocol(proto); + + Adapter->DhclientInfo.client->active = NULL; + Adapter->DhclientInfo.client->state = S_INIT; + + if (hAdapterStateChangedEvent != NULL) + SetEvent(hAdapterStateChangedEvent); + } + + ApiUnlock(); + + return Send(CommPipe, &Reply); +} + + DWORD DSLeaseIpAddress( PipeSendFunc Send, HANDLE CommPipe, COMM_DHCP_REQ *Req ) { COMM_DHCP_REPLY Reply; PDHCP_ADAPTER Adapter; diff --git a/base/services/dhcpcsvc/dhcp/pipe.c b/base/services/dhcpcsvc/dhcp/pipe.c index d8a59c07845..9088ab9f29a 100644 --- a/base/services/dhcpcsvc/dhcp/pipe.c +++ b/base/services/dhcpcsvc/dhcp/pipe.c @@ -377,11 +377,21 @@ DWORD WINAPI PipeThreadProc( LPVOID Parameter ) { } } - if( Result ) { - switch( Req.Type ) { - case DhcpReqQueryHWInfo: - DSQueryHWInfo( PipeSend, CommPipe, &Req ); - break; + if( Result ) + { + switch( Req.Type ) + { + case DhcpReqAcquireParams: + DSAcquireParams(PipeSend, CommPipe, &Req); + break; + + case DhcpReqReleaseParams: + DSReleaseParams(PipeSend, CommPipe, &Req); + break; + + case DhcpReqQueryHWInfo: + DSQueryHWInfo(PipeSend, CommPipe, &Req); + break; case DhcpReqLeaseIpAddress: DSLeaseIpAddress( PipeSend, CommPipe, &Req ); diff --git a/base/services/dhcpcsvc/dhcpcsvc.c b/base/services/dhcpcsvc/dhcpcsvc.c index 5e413c277ac..4e0dabff021 100644 --- a/base/services/dhcpcsvc/dhcpcsvc.c +++ b/base/services/dhcpcsvc/dhcpcsvc.c @@ -74,6 +74,69 @@ DhcpCApiCleanup(VOID) PipeHandle = INVALID_HANDLE_VALUE; } + +/* FIXME: The adapter name should be a unicode string */ +DWORD +APIENTRY +DhcpAcquireParameters( + _In_ PSTR AdapterName) +{ + COMM_DHCP_REQ Req; + COMM_DHCP_REPLY Reply; + DWORD BytesRead; + BOOL Result; + + DPRINT1("DhcpAcquireParameters(%s)\n", AdapterName); + + ASSERT(PipeHandle != INVALID_HANDLE_VALUE); + + Req.Type = DhcpReqAcquireParams; + strcpy(Req.Body.AcquireParams.AdapterName, AdapterName); + + Result = TransactNamedPipe(PipeHandle, + &Req, sizeof(Req), + &Reply, sizeof(Reply), + &BytesRead, NULL); + if (!Result) + { + /* Pipe transaction failed */ + return GetLastError(); + } + + return Reply.Reply; +} + +/* FIXME: The adapter name should be a unicode string */ +DWORD +APIENTRY +DhcpReleaseParameters( + _In_ PSTR AdapterName) +{ + COMM_DHCP_REQ Req; + COMM_DHCP_REPLY Reply; + DWORD BytesRead; + BOOL Result; + + DPRINT1("DhcpReleaseParameters(%s)\n", AdapterName); + + ASSERT(PipeHandle != INVALID_HANDLE_VALUE); + + Req.Type = DhcpReqReleaseParams; + strcpy(Req.Body.AcquireParams.AdapterName, AdapterName); + + Result = TransactNamedPipe(PipeHandle, + &Req, sizeof(Req), + &Reply, sizeof(Reply), + &BytesRead, NULL); + if (!Result) + { + /* Pipe transaction failed */ + return GetLastError(); + } + + return Reply.Reply; +} + DWORD APIENTRY DhcpQueryHWInfo(DWORD AdapterIndex, PDWORD MediaType, diff --git a/base/services/dhcpcsvc/dhcpcsvc.spec b/base/services/dhcpcsvc/dhcpcsvc.spec index 4654e2eafd6..e061bb4dc1c 100644 --- a/base/services/dhcpcsvc/dhcpcsvc.spec +++ b/base/services/dhcpcsvc/dhcpcsvc.spec @@ -5,7 +5,7 @@ # PURPOSE: dhcpcsvc exports # COPYRIGHT: Copyright 2006 Ge van Geldorp # -@ stub DhcpAcquireParameters +@ stdcall DhcpAcquireParameters(str) @ stub DhcpAcquireParametersByBroadcast @ stdcall DhcpCApiCleanup() @ stdcall DhcpCApiInitialize(ptr) @@ -27,7 +27,7 @@ @ stub DhcpRegisterParamChange @ stdcall DhcpReleaseIpAddressLease(long) @ stub DhcpReleaseIpAddressLeaseEx -@ stub DhcpReleaseParameters +@ stdcall DhcpReleaseParameters(str) @ stub DhcpRemoveDNSRegistrations @ stdcall DhcpRenewIpAddressLease(long) @ stub DhcpRenewIpAddressLeaseEx diff --git a/base/services/dhcpcsvc/include/rosdhcp.h b/base/services/dhcpcsvc/include/rosdhcp.h index f71ffc214f0..9e0ec510fd5 100644 --- a/base/services/dhcpcsvc/include/rosdhcp.h +++ b/base/services/dhcpcsvc/include/rosdhcp.h @@ -90,6 +90,7 @@ void AdapterStop(VOID); extern PDHCP_ADAPTER AdapterGetFirst(VOID); extern PDHCP_ADAPTER AdapterGetNext(PDHCP_ADAPTER); extern PDHCP_ADAPTER AdapterFindIndex( unsigned int AdapterIndex ); +extern PDHCP_ADAPTER AdapterFindName(const CHAR *name); extern PDHCP_ADAPTER AdapterFindInfo( struct interface_info *info ); extern PDHCP_ADAPTER AdapterFindByHardwareAddress( u_int8_t haddr[16], u_int8_t hlen ); extern HANDLE PipeInit(HANDLE hStopEvent); @@ -97,6 +98,8 @@ extern VOID ApiInit(VOID); extern VOID ApiFree(VOID); extern VOID ApiLock(VOID); extern VOID ApiUnlock(VOID); +extern DWORD DSAcquireParams(PipeSendFunc Send, HANDLE CommPipe, COMM_DHCP_REQ *Req); +extern DWORD DSReleaseParams(PipeSendFunc Send, HANDLE CommPipe, COMM_DHCP_REQ *Req); extern DWORD DSQueryHWInfo( PipeSendFunc Send, HANDLE CommPipe, COMM_DHCP_REQ *Req ); extern DWORD DSLeaseIpAddress( PipeSendFunc Send, HANDLE CommPipe, COMM_DHCP_REQ *Req ); extern DWORD DSRenewIpAddressLease( PipeSendFunc Send, HANDLE CommPipe, COMM_DHCP_REQ *Req ); diff --git a/base/services/dhcpcsvc/include/rosdhcp_pipe.h b/base/services/dhcpcsvc/include/rosdhcp_pipe.h index 52c5e8c6c3d..a51182fba12 100644 --- a/base/services/dhcpcsvc/include/rosdhcp_pipe.h +++ b/base/services/dhcpcsvc/include/rosdhcp_pipe.h @@ -2,6 +2,8 @@ #define ROSDHCP_PIPE_H enum { + DhcpReqAcquireParams, + DhcpReqReleaseParams, DhcpReqLeaseIpAddress, DhcpReqQueryHWInfo, DhcpReqReleaseIpAddress, @@ -12,7 +14,12 @@ enum { typedef struct _COMM_DHCP_REQ { UINT Type; DWORD AdapterIndex; - union { + union + { + struct + { + CHAR AdapterName[64]; + } AcquireParams; struct { BOOL Inserted; } PnpEvent; diff --git a/sdk/include/psdk/dhcpcapi.h b/sdk/include/psdk/dhcpcapi.h index 9b7416c773f..c4c101f8647 100644 --- a/sdk/include/psdk/dhcpcapi.h +++ b/sdk/include/psdk/dhcpcapi.h @@ -5,6 +5,16 @@ extern "C" { #endif +DWORD +APIENTRY +DhcpAcquireParameters( + _In_ PSTR AdapterName); + +DWORD +APIENTRY +DhcpReleaseParameters( + _In_ PSTR AdapterName); + DWORD APIENTRY DhcpLeaseIpAddress( DWORD AdapterIndex ); DWORD APIENTRY DhcpQueryHWInfo( DWORD AdapterIndex, PDWORD MediaType, @@ -23,11 +33,6 @@ DhcpNotifyConfigChange(LPWSTR ServerName, DWORD IpAddress, DWORD SubnetMask, int DhcpAction); -DWORD APIENTRY DhcpRosGetAdapterInfo( DWORD AdapterIndex, - PBOOL DhcpEnabled, - PDWORD DhcpServer, - time_t *LeaseObtained, - time_t *LeaseExpires ); #ifdef __cplusplus }