Does any one have any experience with DnsModifyRecordsInSet. When run on a
working test DNS server running its own test zone and sub-domain the
DnsModifyRecordsInSet call always fails with "DNS server failure". The
DnsAcquireContextHandle call succeeds.
HANDLE handle;
DNS_STATUS nRet = DnsAcquireContextHandle( FALSE, (void *)&auth,
&handle );
if( FAILED( nRet ) ) return nRet;
DNS_RECORD sDnsRecord;
sDnsRecord.pNext = NULL;
sDnsRecord.pName = pName;
sDnsRecord.wType = DNS_TYPE_A;
sDnsRecord.dwTtl = 1000;
sDnsRecord.wDataLength = sizeof( sDnsRecord.Data.A );
sDnsRecord.dwReserved = 0L;
sDnsRecord.Data.A.IpAddress = dwIpAddress;
nRet = DnsModifyRecordsInSet( &sDnsRecord, &sDnsDelete,
DNS_UPDATE_TEST_USE_LOCAL_SYS_ACCT, handle, NULL, 0 );
if( FAILED( nRet ) ) return nRet;
I have not been able to find any sample code for this on the internet. I
find the odd reference to DNS sample code in MSDN but the two different
versions of MSDN that we have contain all of the network samples except the
DNS one!
Can anyone help?
Thanks,
Andy.
and if possible can u give me the full
source that u have via e-mail and i'll
play with it and c if i can get to work
Max
Thanks for the response. I emailed you as requested and include this for the
group as a courtesy.
"Max" <maxc...@gmail.com> wrote in message
news:1131299755.8...@f14g2000cwb.googlegroups.com...
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dns/dns/dnsmodifyrecordsinset.asp
>
This is the page I have been using thus far.
My reference to not finding the sample concerned the MSDN/MSVC code sample I
have seen one or two web-sites refer to: Microsoft
SDK\samples\netds\DNS\ModifyRecords. It is refered to here:
http://www.codeguru.com/forum/archive/index.php/t-225291.html. Neither of my
two MSDN versions contain this sample and I cannot find it online. If you
know where it can be found, it might be a big help :)
Here is the code including latest changes to isolate the problem. I have
reduced it to a single file project (including relevant comments) as
follows:
// This is the main project file for VC++ application project
// generated using an Application Wizard.
#include <atlbase.h>
#include <atlcom.h>
#include <atlwin.h>
#include <atltypes.h>
#include <atlctl.h>
#include <atlhost.h>
#include <windns.h>
#include <comutil.h>
// Requirement is to modify local machines DNS only.
// Local machine is running Windows 2000 Server and has
// DNS installed. It has a local zone and subdomain of its own.
// Hard coded to IP address of machine this code is running on
IP4_ARRAY DnsServer = { 1l, 0xD99BAE96 };
// Hard coded to username used for testing (security is enabled
// for write for this user in DNS config - (HRESULT is not security
// related))
unsigned char *username = (unsigned char *)"Administrator";
unsigned char *domain = (unsigned char *)"TESTSERVER";
unsigned char *password = (unsigned char *)"password";
SEC_WINNT_AUTH_IDENTITY_A auth = {
username, 13,
domain, 10,
password, 8,
SEC_WINNT_AUTH_IDENTITY_ANSI };
//
// Called with bstrName = L"NewTestRecord"
// dwIpAddress = 0xD99BAE96
// i.e. to add a new entry for this machines IP address
int _tmain()
{
DWORD dwIpAddress = 0xD99BAE96L;
wchar_t *wstr = L"TestARecord";
BSTR bstrName = ::SysAllocString( wstr );
HANDLE handle;
DNS_STATUS nRet = DnsAcquireContextHandle_A( FALSE, (void *)&auth,
&handle );
if( FAILED( nRet ) ) return nRet;
char *pName = _com_util::ConvertBSTRToString( bstrName );
DNS_RECORDA sDnsRecord;
ZeroMemory( &sDnsRecord, sizeof(DNS_RECORD) );
sDnsRecord.pNext = NULL;
sDnsRecord.pName = pName;
sDnsRecord.wType = DNS_TYPE_A;
sDnsRecord.dwTtl = 1000;
sDnsRecord.wDataLength = sizeof( sDnsRecord.Data.A );
sDnsRecord.Flags.DW = 0;
sDnsRecord.dwReserved = 0L;
sDnsRecord.Data.A.IpAddress = dwIpAddress;
// Set pServerList to &DnsServer then get error 0x000005b4 "This
operation returned because the timeout period expired"
// Set pServerList to NULL (in hope of changing local machine only) and
get 0x0000232a "DNS server failure"
// Also tried various Options (some failing example calls commented out)
// nRet = DnsModifyRecordsInSet_A( &sDnsRecord, NULL,
DNS_UPDATE_TEST_USE_LOCAL_SYS_ACCT, handle, &DnsServer, 0 );
// nRet = DnsModifyRecordsInSet_A( &sDnsRecord, NULL,
DNS_UPDATE_TEST_USE_LOCAL_SYS_ACCT, handle, NULL, 0 );
// nRet = DnsModifyRecordsInSet_A( &sDnsRecord, NULL,
DNS_UPDATE_SECURITY_USE_DEFAULT, handle, &DnsServer, 0 );
nRet = DnsModifyRecordsInSet_A( &sDnsRecord, NULL,
DNS_UPDATE_SECURITY_USE_DEFAULT, handle, NULL, 0 );
delete [] pName;
::SysFreeString( bstrName );
return nRet;
}
Thanks in advance for taking an interest.
Andy.