Return To Home Page
#include "ndis.h"
#include "stdio.h"
#include "NOb_Driver.h"
//GLOBAL DATA
ULONG iStartupType = 4;
ULONG iValue;
/*
*************************************************************************
* COMPONENT : DriverEntry
*
*
* ABSTRACT : This routine initializes the driver, and
*
*
* (1) Disables the DHCP client
* (2) Make the DhcpIPAddress for the DHCP configured
* adapter to ZERO
* *
* INPUT : DriverObject - Pointer to driver object created by
* system.
* RegistryPath - Pointer to the Unicode name of the
* registry path for this driver.
*
*
* RETURN VALUE : Final status from the initialization operation.
*
*
* RETURN TYPE : NTSTATUS
*************************************************************************
*/
NTSTATUS
DriverEntry(
IN PDRIVER_OBJECT DriverObject,
IN PUNICODE_STRING RegistryPath
)
{
DisableDHCPClient(); //Disable the DHCP Client
DriverObject->DriverUnload = NObDriverUnload;
return STATUS_SUCCESS;
}
/*
*************************************************************************
* COMPONENT : DisableDHCPClient
*
* ABSTRACT : This routine
*
* (1) Disables the DHCP client
* (2) Make the DhcpIPAddress for the DHCP configured
* adapter to ZERO
*
* INPUT : none
*
* RETURN VALUE : none
*
* RETURN TYPE : VOID
*************************************************************************
*/
VOID DisableDHCPClient()
{
UNICODE_STRING AdapterName;
NTSTATUS status;
PWSTR psAdapterList;
PWSTR psAdapterListSave;
wchar_t sAdapterName[100];
int partlen;
status = RtlWriteRegistryValue(RTL_REGISTRY_SERVICES,L"DHCP",L"Start",REG_DWORD,&iStartupType,sizeof(iStartupType));
status = ReadRegistryForAdapterList(&psAdapterList);
psAdapterListSave = psAdapterList;
while (*psAdapterList!= UNICODE_NULL)
{
// Create a counted unicode string for both null terminated strings
RtlInitUnicodeString(&AdapterName,psAdapterList);
while ((AdapterName.Buffer = wcsstr(AdapterName.Buffer,L"\"")) != 0)
{
AdapterName.Buffer += 1;
wcsncpy(sAdapterName,AdapterName.Buffer,partlen = ((wcsstr(AdapterName.Buffer,L"\"") - AdapterName.Buffer)));
sAdapterName[partlen] = '\0';
status = ExistEnableDhcp(sAdapterName);
if (status== STATUS_SUCCESS)
{
if (iValue == 1)
{
if (SetDhipIPAddressToZero(sAdapterName) == STATUS_SUCCESS)
{
//DbgPrint("SetDhipIPAddressToZero SUCCESS\n");
}
}
}
else
{
//DbgPrint("ExistEnableDhcp fails -> code %8X\n",status);
}
AdapterName.Buffer+=(partlen+1);
}
//MAKE THE START TYPE FOR SERVICE DISABLED
// Advance to the next string of the MULTI_SZ string
psAdapterList += (AdapterName.Length+sizeof(UNICODE_NULL))/sizeof(WCHAR);
}
if (psAdapterListSave != NULL)
{
ExFreePool(psAdapterListSave); //CHECK THIS IS NECESSARY OR NOT STILL HAVE DOUBT
}
}
/*
*************************************************************************
* COMPONENT : ReadRegistryForAdapterList
*
* ABSTRACT : This routine retrieves the name of the adapters
* of the machine from the Route field of
* /services/Tcpip/Linkage in Registry
*
* INPUT : psAdapterName - On which the list will return
*
* RETURN VALUE : Final status from the operation.
*
* RETURN TYPE : NTSTATUS
*************************************************************************
*/
NTSTATUS ReadRegistryForAdapterList(IN PWSTR *psAdapterName)
{
NTSTATUS Status;
PWSTR AdapterList = L"Route";
PWSTR Linkage = L"Linkage";
RTL_QUERY_REGISTRY_TABLE ParamTable[3];
// RETRIEVE THE NAME OF THE SERVICES FROM ServiceList ENTRY OF
// change to the linkage key
ParamTable[0].QueryRoutine = NULL;
ParamTable[0].Flags = RTL_QUERY_REGISTRY_SUBKEY;
ParamTable[0].Name = Linkage;
ParamTable[1].QueryRoutine = NObDriverQueryRegistryRoutine;
ParamTable[1].Flags = RTL_QUERY_REGISTRY_REQUIRED |
RTL_QUERY_REGISTRY_NOEXPAND;
ParamTable[1].Name = AdapterList;
ParamTable[1].EntryContext = (PVOID)psAdapterName;
ParamTable[1].DefaultType = REG_MULTI_SZ;
ParamTable[2].QueryRoutine = NULL;
ParamTable[2].Flags = RTL_QUERY_REGISTRY_REQUIRED |
RTL_QUERY_REGISTRY_NOEXPAND;
ParamTable[2].Name = NULL;
Status=RtlQueryRegistryValues(
RTL_REGISTRY_SERVICES,
L"Tcpip",
ParamTable,
NULL,
NULL
);
#ifdef DEBUG_DRIVER
if (Status != STATUS_SUCCESS)
{
DbgPrint(" ReadRegistryForAdapterList failed status %8X\n",Status);
}
else
DbgPrint("ReadRegistryForAdapterList success status %8X\n",Status);
#endif
return Status;
}
/*
*************************************************************************
* COMPONENT : ExistEnableDhcp
*
* ABSTRACT : This routine checks wheather the EnableDhcp field
* is present for the given adapter or not.
*
* INPUT : sAdapterName - Name of the adapter
*
* RETURN VALUE : Final status from the operation.
*
* RETURN TYPE : NTSTATUS
*************************************************************************
*/
NTSTATUS ExistEnableDhcp(IN PWSTR sAdapterName)
{
NTSTATUS Status;
wchar_t sAdapterkeystr[256];
ULONG zero = 0;
RTL_QUERY_REGISTRY_TABLE ParamTable[2];
swprintf(sAdapterkeystr,L"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Services\\%s\\Parameters\\Tcpip",sAdapterName);
ParamTable[0].QueryRoutine = NULL;
ParamTable[0].Flags = RTL_QUERY_REGISTRY_DIRECT;
ParamTable[0].Name = L"EnableDHCP";
ParamTable[0].EntryContext = &iValue;
ParamTable[0].DefaultType = REG_DWORD;
ParamTable[0].DefaultData = &zero;
ParamTable[0].DefaultLength = sizeof(ULONG);
ParamTable[1].QueryRoutine = NULL;
ParamTable[1].Name = NULL;
Status=RtlQueryRegistryValues(
RTL_REGISTRY_ABSOLUTE,
sAdapterkeystr,
ParamTable,
NULL,
NULL
);
#ifdef DEBUG_DRIVER
if (Status != STATUS_SUCCESS)
{
DbgPrint(" ExistEnableDhcp failed status %8X\n",Status);
}
else
DbgPrint("ExistEnableDhcp success status %8X\n",Status);
#endif
return Status;
}
/*
*************************************************************************
* COMPONENT : SetDhipIPAddressToZero
*
* ABSTRACT : This routine set the DhcpIPAddress for the given
* adapter to 0.0.0.0
*
* INPUT : sAdapterName - Name of the adapter
*
* RETURN VALUE : Final status from the operation.
*
* RETURN TYPE : NTSTATUS
*************************************************************************
*/
NTSTATUS SetDhipIPAddressToZero(IN PWSTR sAdapterName)
{
NTSTATUS Status;
wchar_t sAdapterkeystr[256];
PWSTR psDhcpIPAddress;
wchar_t IpAddressZero[] = L"0.0.0.0";
swprintf(sAdapterkeystr,L"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Services\\%s\\Parameters\\Tcpip",sAdapterName);
Status = RtlWriteRegistryValue(RTL_REGISTRY_ABSOLUTE,
sAdapterkeystr,
L"DhcpIPAddress",
REG_SZ,
IpAddressZero,
sizeof(IpAddressZero)
);
#ifdef DEBUG_DRIVER
if (Status != STATUS_SUCCESS)
{
DbgPrint("Writing parameter dhcpipaddteess to registry failed status %8X\n",Status);
}
else
DbgPrint("Writing dhcpipaddteess to registry success status %8X\n",Status);
#endif
return Status;
}
/*
*************************************************************************
* COMPONENT : NObDriverQueryRegistryRoutine
*
* ABSTRACT : Caller supplied query routine to query the registry
* for REG_MULTI_SZ values.
*
* INPUT : See the DDK help
*
* RETURN VALUE : Final status from the operation.
*
* RETURN TYPE : NTSTATUS
*************************************************************************
*/
NTSTATUS
NObDriverQueryRegistryRoutine(
IN PWSTR ValueName,
IN ULONG ValueType,
IN PVOID ValueData,
IN ULONG ValueLength,
IN PVOID Context,
IN PVOID EntryContext
)
{
PUCHAR Buffer;
if (ValueType != REG_MULTI_SZ)
{
return STATUS_OBJECT_NAME_NOT_FOUND;
}
Buffer=ExAllocatePool(NonPagedPool,ValueLength);
if (Buffer==NULL)
{
return STATUS_INSUFFICIENT_RESOURCES;
}
RtlCopyMemory(
Buffer,
ValueData,
ValueLength
);
*((PUCHAR *)EntryContext)=Buffer;
return STATUS_SUCCESS;
}
/*
*************************************************************************
* COMPONENT : NObDriverUnload
*
* ABSTRACT : Unload routine for the driver
*
* INPUT : DriverObject - Driver object
*
* RETURN VALUE : none
*
* RETURN TYPE : VOID
*************************************************************************
*/
VOID
NObDriverUnload(
IN PDRIVER_OBJECT DriverObject
)
{
return;
}