Solved

some problem with NetGetAnyDCName()

Posted on 2001-07-29
8
493 Views
Last Modified: 2013-12-03
Hi folks,

i try to do:


NET_API_STATUS retc;
LPBYTE * Servername = NULL;

retc = NetGetAnyDCName(
     NULL,
     NULL,
     Servername
     );

if( retc == NERR_Success)
{
    // DO STUFF
}
else
{
  switch(retc)
  {
    case ERROR_NO_LOGON_SERVERS:
      m_ResultText.Format("No domain controllers could be found\r\n");
      break;
    case ERROR_NO_SUCH_DOMAIN:
      m_ResultText.Format("The specified domain is not a trusted domain.\r\n");
      break;
    case ERROR_NO_TRUST_LSA_SECRET:
      m_ResultText.Format("The client side of the trust relationship is broken.\r\n");
      break;
    case ERROR_NO_TRUST_SAM_ACCOUNT:
      m_ResultText.Format("The server side of the trust relationship is broken or the password is broken.\r\n");
      break;
    case ERROR_DOMAIN_TRUST_INCONSISTENT:
      m_ResultText.Format("The server that responded is not a proper domain controller of the specified domain.\r\n");
      break;
    default:
      m_ResultText.Format("Can't find a domain controller for domain(%d)\r\n", retc);
    }
    MessageBox( m_ResultText, MB_OK);
}

but when i run, i always get: "Can't find a domain controller for domain (-1073741819)" which as you can see, is the default switch condition, because retc is "-1073741819"!!

i don;t get it - if i specify the PDC, i can use NetUserEnum() with no problems at all.  but i want to first use NetGetAnyDCName() or NetGetDCName() to find them first so that the user need not enter it manually...

any ideas guys?


0
Comment
Question by:slamhound
  • 5
  • 3
8 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 6332716
The error code acually is C0000005 (-1073741819) - ERROR_ACCESS_VIOLATION.
0
 
LVL 86

Accepted Solution

by:
jkr earned 200 total points
ID: 6332728
MAke it read

NET_API_STATUS retc;
LPBYTE Servername = NULL;

retc = NetGetAnyDCName(
    NULL,
    NULL,
    &Servername
    );

and it will work...
0
 
LVL 86

Expert Comment

by:jkr
ID: 6332731
To elaborate - this API takes a pointer to a pointer to store the actually allocated address in. When coding

NET_API_STATUS retc;
LPBYTE * Servername = NULL;

retc = NetGetAnyDCName(
    NULL,
    NULL,
    Servername
    );


you're syntacrically correct, as you're passing a BYTE**. But, as this pointer points to NULL, 'NetGetAnyDCName()' tries to store the value at the position NULL, thus leading to the accvio that is probably caught in a SEH frame. You can think of it as it is doing

GetNamr ( char** ppsz)
{
 *ppsz = "name";
}

If you'd call that using your method, it' be like '*NULL = "name";'
0
 
LVL 10

Author Comment

by:slamhound
ID: 6332733
jkr,

Oooo-Kay!

well that makes some sense then...  but i am logged in as domain admin - i will start poking about some, any tips for me?

thanks for that!

regards.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 86

Expert Comment

by:jkr
ID: 6332737
>>but i am logged in as domain admin - i will start poking
>>about some, any tips for me?

Read my answer :o)
All you have to do is to change your code to read


NET_API_STATUS retc;
LPBYTE Servername = NULL;

retc = NetGetAnyDCName(
   NULL,
   NULL,
   &Servername
   );
0
 
LVL 10

Author Comment

by:slamhound
ID: 6332755
yeah, i'd written that last one at the same time you were preparing your second response - didn;t see it until after i had submitted! ;-)

thanks for that - makes perfect sense.  what i was thinking is that the function would take my pointer and set it to the value of the buffer created by th net_api....

i can see where i went wrong.  

back soon.
0
 
LVL 86

Expert Comment

by:jkr
ID: 6332764
>>what i was thinking is that the function would take my
>>pointer and set it to the value of the buffer created by
>>th net_api....

That's what it does. But in order to do that, this function needs the address of a pointer, and not a pointer to a pointer. I know, the docs are a bit fuzzy about that.
0
 
LVL 10

Author Comment

by:slamhound
ID: 6332768
thanks a bunch :)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to add a user-defined command button to the Windows 7 Explorer toolbar.  In the previous article (http://www.experts-exchange.com/A_2172.html), we saw how to put the Delete button back there where it belongs.  "Delete" is …
This article surveys and compares options for encoding and decoding base64 data.  It includes source code in C++ as well as examples of how to use standard Windows API functions for these tasks. We'll look at the algorithms — how encoding and decodi…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now