Solved

some problem with NetGetAnyDCName()

Posted on 2001-07-29
8
492 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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

This article describes how to programmatically preset the "Pages per Sheet" option that's available with most printer drivers.   This setting lets you do "n-Up" printing, where two, four, or more pages are printed on each sheet of paper. If your …
What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

762 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

19 Experts available now in Live!

Get 1:1 Help Now