Example #1
0
//---------------------------------------------------------------------------
//  getAccountInfo
//---------------------------------------------------------------------------
void getAccountInfo(const char* computer, StringAttr& user, StringAttr& pwd, IConstEnvironment* pConstEnv) 
{
  if (!pConstEnv)
    throw MakeStringException(-1, "No environment is available!");

  Owned<IConstMachineInfo> machine = pConstEnv->getMachine(computer);
  if (!machine)
  {
    StringBuffer sComputer(computer);
    StringBuffer sExtra;
    if (sExtra.length() == 0)
      machine.setown( pConstEnv->getMachineByAddress(computer) );

    if (!machine)
      throw MakeStringException(-1, "The computer '%s' is undefined!", computer);
  }

  Owned<IConstDomainInfo> domain = machine->getDomain();
  if (!domain)
    throw MakeStringException(-1, "The computer '%s' does not have any domain information!", computer);

  StringBuffer x;
  domain->getName(StringBufferAdaptor(x));
  if (x.length()) 
    x.append(PATHSEPCHAR);
  domain->getAccountInfo(StringBufferAdaptor(x), StringAttrAdaptor(pwd));
  user.set(x.str());
}