Example #1
0
void GetAgentInfo(AgentSystemInfo *info)
{

    SYSTEM_INFO siSysInfo;
    // get cpu info
    GetSystemInfo(&siSysInfo); 
    switch(siSysInfo.wProcessorArchitecture)
    {
    case PROCESSOR_ARCHITECTURE_AMD64:
        info->cpu = "x64";
        break;
    case PROCESSOR_ARCHITECTURE_IA64:
        info->cpu = "IA64";
        break;
    case PROCESSOR_ARCHITECTURE_INTEL:
        info->cpu = "x86";
        break;
    default:
        info->cpu = "Unknown";
        break;
    }
    // get dns hostname
    DWORD dwSize = 0;
    // first get the buffer size
    GetComputerNameEx(ComputerNameDnsFullyQualified, NULL, &dwSize);
    char *name_buf = new char[dwSize + 1];
    // second get the host name, dns full qualified
    if (!GetComputerNameEx(ComputerNameDnsFullyQualified, name_buf, &dwSize))
    {
        Log::Error("Get dns fully qualified name failed, exit now!");
	    exit(-1);
        info->hostname = "Unknown";
    }	
    else
    {
        info->hostname = string(name_buf, dwSize);
    }
    delete [] name_buf;
    info->system = "Windows";
    char buf[255];

    // get release and version
    OSVERSIONINFO osvi;
    ZeroMemory(&osvi, sizeof(OSVERSIONINFO));
    osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
    GetVersionEx(&osvi);
    sprintf(buf, "%d.%d", osvi.dwMajorVersion, osvi.dwMinorVersion);
    info->release = buf;
    
    TCHAR szOS[BUFSIZE];
    if( GetOSDisplayString(szOS))
    {
        info->version = szOS;
    }
    else
    {
        info->version = "Unknown";
    }
    info->agent_version = AGENT_VERSION;
}
Example #2
0
HRESULT
ceGetMachineDnsName(
    OUT WCHAR **ppwszDnsName)
{
    HRESULT hr;
    WCHAR *pwszDnsName = NULL;
    DWORD cwc;
    COMPUTER_NAME_FORMAT NameType = ComputerNameDnsFullyQualified;

    *ppwszDnsName = NULL;
    while (TRUE)
    {
	cwc = 0;
	if (!GetComputerNameEx(NameType, NULL, &cwc))
	{
	    hr = ceHLastError();
	    if (HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) == hr &&
		ComputerNameDnsFullyQualified == NameType)
	    {
		_PrintError(hr, "GetComputerNameEx(DnsFullyQualified) -- switching to NetBIOS");
		NameType = ComputerNameNetBIOS;
		continue;
	    }
	    if (HRESULT_FROM_WIN32(ERROR_MORE_DATA) != hr)
	    {
		_JumpError(hr, error, "GetComputerNameEx");
	    }
	    break;
	}
    }
    pwszDnsName = (WCHAR *) LocalAlloc(LMEM_FIXED, cwc * sizeof(WCHAR));
    if (NULL == pwszDnsName)
    {
	hr = E_OUTOFMEMORY;
	_JumpError(hr, error, "LocalAlloc");
    }

    if (!GetComputerNameEx(NameType, pwszDnsName, &cwc))
    {
	hr = ceHLastError();
	_JumpError(hr, error, "GetComputerNameEx");
    }

    *ppwszDnsName = pwszDnsName;
    pwszDnsName = NULL;
    hr = S_OK;

error:
    if (NULL != pwszDnsName)
    {
	LocalFree(pwszDnsName);
    }
    return(hr);
}
Example #3
0
/**
 * Runs the DNS-SD sequence to discover the sFlow server settings,
 * collector addresses and ports and sampling rates and polling interval
 * settings.
 * The DNS query is scoped to query for entries in the domain (zone)
 * configured as the domain override in the registry (if set), or the
 * primary domain name configured on the system if there is no domain
 * override.
 * Note that the DNS query could fail or return no results if we are
 * unable to discover the primary domain of the system.
 * HSP *sp used to update the min TTL for DNS entries so that the
 * next DNS request can be scheduled.
 * HSPSFlowSettings *settings in which sFlow collector addresses and ports
 * and sampling and polling settings will be populated.
 * Returns the number of sFlow collectors discovered or -1 on failure.
 */
int dnsSD(HSP *sp, HSPSFlowSettings *settings)
{
    char request[HSP_MAX_DNS_LEN];
	if (sp->DNSSD_domain) {
		sprintf_s(request, HSP_MAX_DNS_LEN, "%s%s", SFLOW_DNS_SD, sp->DNSSD_domain);
	} else {
		char domain[MAX_HOSTNAME_LEN];
		memset(domain, 0, MAX_HOSTNAME_LEN);
		DWORD len = MAX_HOSTNAME_LEN;
		char *dot = "";
		if (GetComputerNameEx(ComputerNameDnsDomain, domain, &len) == 0) {
			DWORD err = GetLastError();
			logErr(LOG_ERR, err, "dnsSD: cannot determined DNS domain for this computer error=%u", err);
		} else if (len == 0) {
			myLog(LOG_ERR, "dnsSD: DNS domain for this computer not set");
		} else {
			dot = ".";
		}
		sprintf_s(request, HSP_MAX_DNS_LEN, "%s%s%s", SFLOW_DNS_SD, dot, domain);
	}
	myLog(LOG_INFO, "dnsSD: request=%s", request);
    int num_servers = dnsSD_Request(sp, settings, request, DNS_TYPE_SRV);
    dnsSD_Request(sp, settings, request, DNS_TYPE_TEXT);
    // it's ok even if only the SRV request succeeded
    return num_servers; //  -1 on error
}
/*!
 @brief ユーザ情報の表示
*/
void CUserInfoDlg::ExecUserInfo()
{
	TCHAR szUserName[UNLEN + 1];
	DWORD nUserNameSize = sizeof(szUserName) / sizeof(TCHAR);
	GetUserName(szUserName, &nUserNameSize);
	m_strUserName = szUserName;

	TCHAR szDomainName[DNLEN + 1];
	DWORD nDomainNameSize = sizeof(szDomainName) / sizeof(TCHAR);
	GetComputerNameEx(ComputerNameDnsDomain, szDomainName, & nDomainNameSize);
	m_strDomainName = szDomainName;

	TCHAR szFullUserName[UNLEN + 1];
	ZeroMemory(szFullUserName, sizeof(szFullUserName));
	GetFullName(szUserName, szDomainName, szFullUserName);
	m_strFullUserName = szFullUserName;

	m_bAdminUser = IsUserAnAdmin();

	TCHAR szGroupName[(GNLEN + 1) * 5];
	ZeroMemory(szGroupName, sizeof(szGroupName));
	GetGroupName(szUserName, szGroupName);
	m_strGroupName = szGroupName;	
	m_strGroupName.TrimLeft(_T(','));

	UpdateData(FALSE);
}
Example #5
0
int gethostname(char* name, size_t len) {
  /* GetComputerName is not the right thing.  gethostname from <winsock2.h>
     would be right, but requires linking with -lws2_32.  So we use
     GetComputerNameEx.  */
  DWORD size = (len <= (DWORD)~0 ? len : (DWORD)~0);

  if (!GetComputerNameEx(ComputerNameDnsHostname, name, &size)) {
    return -1;
  }
  return 0;
}
Example #6
0
std::wstring getFqdn( )
{
	BOOL result;
	wchar_t buffer[400];
	DWORD size = _countof(buffer) - 1;

	result = GetComputerNameEx( ComputerNameDnsFullyQualified, buffer, &size );
	if( !result ) {
		throw Win32Exception( "Trying to get computer name" );
	}

	return std::wstring(buffer);
}
/**
 * Populates the host_descr structure with, computer name for hostname,
 * processor architecture, os_name (Windows), os version, and BIOS UUID.
 */
void readHidCounters(HSP *sp, SFLHost_hid_counters *hid){
	DWORD dwRes;
	OSVERSIONINFO osvi;
	SYSTEM_INFO si;
#define MAX_FDQN_CHARS 255
	char dnsBuf[MAX_FDQN_CHARS+1];
	DWORD dnsLen = MAX_FDQN_CHARS;

	if (GetComputerNameEx(ComputerNameDnsHostname,dnsBuf,&dnsLen)) {
		uint32_t copyLen = dnsLen < SFL_MAX_HOSTNAME_CHARS ? dnsLen :  SFL_MAX_HOSTNAME_CHARS;
		memcpy(hid->hostname.str, dnsBuf, copyLen);
		hid->hostname.str[copyLen] = '\0';
		hid->hostname.len = copyLen;
	}

	hid->os_name = SFLOS_windows;

	ZeroMemory(&osvi, sizeof(OSVERSIONINFO));
    osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
	dwRes = GetVersionEx(&osvi);
	if (dwRes){
		sprintf_s(hid->os_release.str, SFL_MAX_OSRELEASE_CHARS,"%d.%d.%d %s",
				osvi.dwMajorVersion,
				osvi.dwMinorVersion,
				osvi.dwBuildNumber,
				osvi.szCSDVersion);
		hid->os_release.len = (uint32_t)strnlen(hid->os_release.str, SFL_MAX_OSRELEASE_CHARS);
	}

	GetNativeSystemInfo(&si);
	hid->machine_type = SFLMT_unknown;
	switch(si.wProcessorArchitecture){
		case PROCESSOR_ARCHITECTURE_AMD64:
			hid->machine_type = SFLMT_x86_64;
			break;
		case PROCESSOR_ARCHITECTURE_IA64:
			hid->machine_type = SFLMT_ia64;
			break;
		case PROCESSOR_ARCHITECTURE_INTEL:
			hid->machine_type = SFLMT_x86;
			break;
	}

	dwRes = readSystemUUID(hid->uuid);
	if (LOG_INFO <= debug) {
		u_char uuidbuf[FORMATTED_GUID_LEN+1];
		printUUID(hid->uuid, uuidbuf, FORMATTED_GUID_LEN);
		myLog(LOG_INFO,"readHidCounters:\n\thostname:\t%s\n\trelease:\t%s\n\tmachine_type:\t%d\n\tuuid:\t%s\n",
			hid->hostname.str, hid->os_release.str, hid->machine_type, uuidbuf);
	}
}
Example #8
0
int uname(struct utsname *name)
{
        DWORD nodeNameSize = sizeof(name->nodename) - 1;

        memset(name, 0, sizeof(struct utsname));
        if (!GetComputerNameEx
            (ComputerNameDnsFullyQualified, name->nodename, &nodeNameSize))
                ERR("GetComputerNameEx failed");

        strncpy(name->sysname, "Windows", sizeof(name->sysname) - 1);
        /* FIXME - these should be easy to fetch */
        strncpy(name->release, "-", sizeof(name->release) - 1);
        strncpy(name->version, "-", sizeof(name->version) - 1);
        strncpy(name->machine, "-", sizeof(name->machine) - 1);
        return 0;
}
Example #9
0
int
sethostname (const char *name, size_t len)
{
  char name_asciz[HOST_NAME_MAX + 1];
  char old_name[HOST_NAME_MAX + 1];
  DWORD old_name_len;

  /* Ensure the string isn't too long.  glibc does allow setting an
     empty hostname so no point in enforcing a lower bound. */
  if (len > HOST_NAME_MAX)
    {
      errno = EINVAL;
      return -1;
    }

  /* Prepare a NUL-terminated copy of name.  */
  memcpy (name_asciz, name, len);
  name_asciz[len] = '\0';

  /* Save the old NetBIOS name.  */
  old_name_len = sizeof (old_name) - 1;
  if (! GetComputerNameEx (ComputerNamePhysicalNetBIOS,
                           old_name, &old_name_len))
    old_name_len = 0;

  /* Set both the NetBIOS and the first part of the IP / DNS name.  */
  if (! SetComputerNameEx (ComputerNamePhysicalNetBIOS, name_asciz))
    {
      errno = (GetLastError () == ERROR_ACCESS_DENIED ? EPERM : EINVAL);
      return -1;
    }
  if (! SetComputerNameEx (ComputerNamePhysicalDnsHostname, name_asciz))
    {
      errno = (GetLastError () == ERROR_ACCESS_DENIED ? EPERM : EINVAL);
      /* Restore the old NetBIOS name.  */
      if (old_name_len > 0)
        {
          old_name[old_name_len] = '\0';
          SetComputerNameEx (ComputerNamePhysicalNetBIOS, old_name);
        }
      return -1;
    }

  /* Note that the new host name becomes effective only after a reboot!  */
  return 0;
}
int _tmain(int argc, _TCHAR* argv[])
{
	setup();

	//Prepare Audio Manager
	RawAudio audio_manager = RawAudio();

	//setup destination location
	//get the computer name
	DWORD name_length = MAX_COMPUTERNAME_LENGTH + 1;
	LPWSTR computer_name = (LPWSTR)malloc(MAX_COMPUTERNAME_LENGTH + 1);
	GetComputerNameEx(ComputerNameDnsHostname, computer_name, &name_length);

	/* Determine the transmitter and receiver by comparing this computer's
	   name with communicator names */
	if (wcscmp(computer_name, COMMUNICATOR_ONE_NAME) == 0)
	{
		audio_manager.SetupStream("CommunicatorOne", "CommunicatorTwo");
	}
	else
	{
		audio_manager.SetupStream("CommunicatorTwo", "CommunicatorOne");
	}

	//Play startup noise, set Ready Light on
	audio_manager.PlayWavFile(L"C:\\Communicator\\aud\\ready.wav", DAC_CS_PIN);
	digitalWrite(READY_LED, 1);

	while (true)
	{
		if (digitalRead(CONTROL_BUTTON) == 1)
		{
			//stream out when the button is pressed, in 1 second clips
			audio_manager.StreamOutAnalog(DAC_CS_PIN, MICROPHONE_INPUT, CONTROL_BUTTON, 1);
		}
		else
		{
			//stream in 1 second clips
			audio_manager.StreamInAnalog(DAC_CS_PIN, CONTROL_BUTTON, 1);
		}
	}



}
Example #11
0
void Get_NET_info()
{
	DWORD temp;
	DWORD ComputerName_Size = (MAX_COMPUTERNAME_LENGTH+1);
	TCHAR ComputerName[MAX_COMPUTERNAME_LENGTH+1];
	temp = ComputerName_Size;
	GetComputerNameEx(ComputerNameNetBIOS,ComputerName,&temp);
	printf("ComputerNameNetBIOS : %s\n",ComputerName);

	temp = ComputerName_Size;
	GetComputerNameEx(ComputerNameDnsHostname,ComputerName,&temp);
	printf("ComputerNameDnsHostname : %s\n",ComputerName);

	temp = ComputerName_Size;
	GetComputerNameEx( ComputerNameDnsDomain,ComputerName,&temp);
	printf(" ComputerNameDnsDomain : %s\n",ComputerName);

	temp = ComputerName_Size;
	GetComputerNameEx(ComputerNameDnsFullyQualified,ComputerName,&temp);
	printf("ComputerNameDnsFullyQualified : %s\n",ComputerName);

	temp = ComputerName_Size;
	GetComputerNameEx(ComputerNamePhysicalDnsHostname,ComputerName,&temp);
	printf("ComputerNamePhysicalDnsHostname : %s\n",ComputerName);


	temp = ComputerName_Size;
	GetComputerNameEx(ComputerNamePhysicalDnsDomain,ComputerName,&temp);
	printf("ComputerNamePhysicalDnsDomain : %s\n",ComputerName);

	temp = ComputerName_Size;
	GetComputerNameEx(ComputerNamePhysicalDnsFullyQualified,ComputerName,&temp);
	printf("ComputerNamePhysicalDnsFullyQualified : %s\n",ComputerName);


	temp = ComputerName_Size;
	GetComputerNameEx(ComputerNameMax,ComputerName,&temp);
	printf("ComputerNameMax : %s\n",ComputerName);
}
//********************************************************************************************
// Function: InitializeDrt
//
// Description: Initializes and brings a DRT instance online
//   1) Brings up an ipv6 transport layer
//   2) Attaches a security provider (according to user's choice)
//   3) Attaches a bootstrap provider (according to user's choice)
//   4) Calls DrtOpen to bring the DRT instance online
//
//********************************************************************************************
bool InitializeDrt(DRT_CONTEXT *Drt)
{
    HRESULT         hr = S_OK;
    DWORD           dwSize = 0;
    PWSTR           pwszCompName = NULL;
    WCHAR           pwszBootstrapHostname[1024] = {0};
    USHORT          usBootstrapPort = 0;

    //
    // Initialize DrtSettings
    //
    Drt->port = 0;
    Drt->settings.pwzDrtInstancePrefix = L"Local_DRT";
    Drt->settings.dwSize = sizeof(DRT_SETTINGS);
    Drt->settings.cbKey = KEYSIZE;
    Drt->settings.ulMaxRoutingAddresses = 4;
    Drt->settings.bProtocolMajorVersion = 0x6;
    Drt->settings.bProtocolMinorVersion = 0x65;
    Drt->settings.eSecurityMode = DRT_SECURE_CONFIDENTIALPAYLOAD;
    Drt->settings.hTransport = NULL;
    Drt->settings.pSecurityProvider = NULL;
    Drt->settings.pBootstrapProvider = NULL;
    Drt->hDrt = NULL;

    //
    // *Transport*
    //

    hr = DrtCreateIpv6UdpTransport(
        DRT_GLOBAL_SCOPE, 
        0,
        300, 
        &Drt->port, 
        &Drt->settings.hTransport
        );
    
    VERIFY_OR_ABORT("DrtCreateTransport",hr);
    
    //
    // *Security Provider*
    //

    if(Drt->SecurityProviderType == 0) //Null Security Provider
    {
        hr = DrtCreateNullSecurityProvider(&Drt->settings.pSecurityProvider);
    }
    else if(Drt->SecurityProviderType == 1) //Derived Key Security Provider
    {
        hr = ReadCertFromFile(L"RootCertificate.cer", &Drt->pRoot, NULL);
        if (FAILED(hr))
        {
            wprintf(L"No RootCertificate.cer file found in the current directory, Creating a new root certificate.\n");
            hr = MakeCert(L"RootCertificate.cer", L"RootCert", NULL, NULL);
            VERIFY_OR_ABORT(L"MakeCert",hr);
            hr = ReadCertFromFile(L"RootCertificate.cer", &Drt->pRoot, NULL);
            VERIFY_OR_ABORT(L"ReadCertFromFile", hr);
        }

        // We now have a root cert, read an existing local cert or create one based on root cert
        hr = ReadCertFromFile(L"LocalCertificate.cer", &Drt->pLocal, NULL);
        if (FAILED(hr))
        {
            wprintf(L"No LocalCertificate.cer file found in the current directory, Creating a new local certificate.\n");
            hr = MakeCert(L"LocalCertificate.cer", L"LocalCert", L"RootCertificate.cer", L"RootCert");
            VERIFY_OR_ABORT(L"MakeCert",hr);
            hr = ReadCertFromFile(L"LocalCertificate.cer", &Drt->pLocal, NULL);
            VERIFY_OR_ABORT(L"ReadCertFromFile", hr);
        }
        hr = DrtCreateDerivedKeySecurityProvider(
            Drt->pRoot,
            Drt->pLocal,
            &Drt->settings.pSecurityProvider
            );
    }
    else if(Drt->SecurityProviderType == 2) //Custom Security Provider
    {
        hr = DrtCreateCustomSecurityProvider(&Drt->settings.pSecurityProvider);
    }
    else
    {
        wprintf(L"Invalid Security Provider passed to InitializeDrt");
        hr = E_FAIL;
    }
    VERIFY_OR_ABORT("DrtCreateSecurityProvider",hr);

    //
    // *Bootstrap Provider*
    //

    if(Drt->BootstrapProviderType == 0) //DNS Bootstrap Provider
    {
        GetComputerNameEx(ComputerNameDnsFullyQualified, NULL, &dwSize );
        pwszCompName = new WCHAR[dwSize+1];
        if(pwszCompName == NULL)
        {
            hr = E_OUTOFMEMORY;
            wprintf(L"Out of memory");
            goto Cleanup;
        }
        ::GetComputerNameEx(ComputerNameDnsFullyQualified, pwszCompName, &dwSize);

        wprintf(L"Enter 'hostname port' for DNS Bootstrap Provider (currently %s %i):\n", pwszCompName, Drt->port);
        if(wscanf_s(L"%s %hu",pwszBootstrapHostname, 1024, &usBootstrapPort) < 2)
        {
            FlushCurrentLine();
            hr = E_INVALIDARG;
            wprintf(L"Invalid hostname:port\n");
            goto Cleanup;
        }
        wprintf(L"DNS Bootstrapping from: %s:%i\n",pwszBootstrapHostname, usBootstrapPort);
        FlushCurrentLine();
     
        hr = DrtCreateDnsBootstrapResolver(
            usBootstrapPort,
            pwszBootstrapHostname,
            &Drt->settings.pBootstrapProvider
            );
    }
    else if (Drt->BootstrapProviderType == 1) //PNRP Bootstrap Provider
    {
        wprintf(L"Enter a PNRP name for PNRP Bootstrap Provider (IE 0.DemoName)\n");
        if(wscanf_s(L"%s",pwszBootstrapHostname, 1024) < 1)
        {
            FlushCurrentLine();
            wprintf(L"Invalid PNRP name\n");
            goto Cleanup;
        }
        wprintf(L"PNRP Bootstrapping from: %s\n",pwszBootstrapHostname);
        FlushCurrentLine();
        hr = DrtCreatePnrpBootstrapResolver(
            TRUE,
            pwszBootstrapHostname,
            L"Global_",
            NULL,
            &Drt->settings.pBootstrapProvider
            );
    }
    else if (Drt->BootstrapProviderType == 2) //Custom Bootstrap Provider
    {
        GetComputerNameEx(ComputerNameDnsFullyQualified, NULL, &dwSize );
        pwszCompName = new WCHAR[dwSize+1];
        ::GetComputerNameEx(ComputerNameDnsFullyQualified, pwszCompName, &dwSize);

        if(pwszCompName == NULL)
        {
            hr = E_OUTOFMEMORY;
            wprintf(L"Out of memory");
            goto Cleanup;
        }

        wprintf(L"Enter 'hostname port' for Custom Bootstrap Provider (currently %s %i\n", pwszCompName, Drt->port);
        if(wscanf_s(L"%s %hu",pwszBootstrapHostname, 1024, &usBootstrapPort) < 2)
        {
            FlushCurrentLine();
            hr = E_INVALIDARG;
            wprintf(L"Invalid hostname:port\n");
            goto Cleanup;
        }
        wprintf(L"Custom Bootstrapping from: %s:%i\n",pwszBootstrapHostname, usBootstrapPort);
        FlushCurrentLine();
     
        hr = DrtCreateCustomBootstrapResolver(
            usBootstrapPort,
            pwszBootstrapHostname,
            &Drt->settings.pBootstrapProvider
            );
    }
    else
    {
        wprintf(L"Invalid Bootstrap Provider passed to InitializeDrt");
        hr = E_FAIL;
    }
    VERIFY_OR_ABORT("DrtCreateBootstrapResolver",hr);

    //
    // *Make sure the Windows Firewall is open*
    //  Also open port 3540 (used by PNRP, if the PNRP bootstrap provider is chosen)
    //

    if(Drt->BootstrapProviderType==1)
        hr = OpenFirewallForDrtSdkSample(TRUE);
    else
        hr = OpenFirewallForDrtSdkSample(FALSE);

    VERIFY_OR_ABORT("OpenFirewallForDrtSdkSample",hr);
    
    //
    // Open the DRT
    //

    Drt->eventHandle = CreateEvent(NULL, FALSE, FALSE, NULL);
    if(NULL == Drt->eventHandle)
    {
        hr = E_OUTOFMEMORY;
        goto Cleanup;
    }

    hr = DrtOpen(&Drt->settings, Drt->eventHandle, NULL, &Drt->hDrt);

    VERIFY_OR_ABORT("DrtOpen", hr);

    //
    // Register a callback to handle DRT Events
    //
    RegisterWaitForSingleObject(&Drt->DrtWaitEvent, Drt->eventHandle, (WAITORTIMERCALLBACK)DrtEventCallback, Drt, INFINITE, WT_EXECUTEDEFAULT);
    
Cleanup:
    if(pwszCompName)
        delete pwszCompName;
    return SUCCEEDED(hr);
}
Example #13
0
/*
** Name: check_host
**
** Description:
**      Test the characters in thehostnames as returned from
**      the operating system.
**
** Inputs:
**      None
**
** Output:
**      error_msg   pointer to the area where an error message should be
**                  copied
**
** Returns:
**      None.
**
** History:
**      24-Jun-2002 (fanra01)
**          Created.
**      07-Dec-2004 (wansh01)
**          Bug 113521
**          Changed nsize to MAX_COMPUTERNAME_LENGTH +1 for GetComputerName()
**          for NT platform to avoid rc=10 error.
**
*/
static i4
check_host()
{
    i4			result;
    char                compname[MAX_COMPNAME + 1] = { 0 };
    char                hostname[MAX_HOSTNAME + 1] = { 0 };
    i4                  nsize = MAX_COMPNAME;
#if defined(UNIX)
    struct   passwd     *p_pswd, pwd;
    char                pwuid_buf[BUFSIZ];
    int                 size = BUFSIZ;
#else
    WSADATA             wsadata;
    WORD                wVersionRequested;
#endif

#if defined(NT_GENERIC)
    /*
    ** Get the computer name as defined for the system.
    */
    nsize = MAX_COMPNAME + 1;
    if (GetComputerNameEx( ComputerNameDnsHostname, compname, &nsize ))
    {
        /*
        ** Check the computer name for any characters that we do not support
        */
        if (!CMvalidhostname( compname ))
        {
            result = II_INVALID_HOST;
            return(result);
        }
    }
    else
    {
        result = II_GET_COMPUTER_FAIL;
        return(result);
    }

    /*
    ** Minimum version of the sockets implementation that we require.
    */
    wVersionRequested = MAKEWORD( 1, 1 );

    /*
    ** Check the version we require with the one that is available
    */
    if (WSAStartup( wVersionRequested, &wsadata ) != 0)
    {
        result = II_GET_HOST_FAIL;
        return(result);
    }
#endif  /* NT_GENERIC */
    
    /*
    ** Get the network hostname
    */
    nsize = MAX_HOSTNAME + 1;
    if (gethostname( hostname, nsize ) == 0)
    {
        /*
        ** Check if the computer is defined as different from the network name
        */
#if defined(NT_GENERIC)
        if (stricmp( compname, hostname ) != 0)
        {
            result = II_UNMATCHED_NAME;
            return(result);
        }
#endif  /* NT_GENERIC */
        /*
        ** Check if the hostname contains unsupported characters
        */
        if (!CMvalidhostname( hostname ))
        {
            result = II_INVALID_HOST;
            return(result);
        }
    }
    else
    {
        result = II_GET_HOST_FAIL;
        return(result);
    }

    result = II_SUCCESSFUL;
    return(result);
}
Example #14
0
static int start_root_smpd(char *host, int len, int *port, PROCESS_HANDLE_TYPE *pHnd)
{
    mpiexec_rsh_rsmpd_args_t rsmpdArgs;
#ifdef HAVE_WINDOWS_H
    DWORD dwLength = len;
#else
    int pipe_fd[2];
    int result;
#endif
    if(!host){
        smpd_err_printf("Invalid host name - NULL - provided\n");
        return SMPD_FAIL;
    }
    if(len <= 0){
        smpd_err_printf("Invalid host name length (%d) provided\n", len);
        return SMPD_FAIL;
    }
    if(!port){
        smpd_err_printf("Invalid port - NULL - provided\n");
        return SMPD_FAIL;
    }
    if(!pHnd){
        smpd_err_printf("Invalid pointer to process handle - NULL - provided\n");
        return SMPD_FAIL;
    }

#ifdef HAVE_WINDOWS_H
    if(!(rsmpdArgs.hRootSMPDRdyEvent = CreateEvent(NULL, TRUE, FALSE, NULL))){
    	smpd_err_printf("unable to create the root listener synchronization event, error: %d\n", 
            GetLastError());
	    return SMPD_FAIL;
    }
    rsmpdArgs.pRootPort = port;
    /* FIXME: Do we need a generic handle type for smpd thread/proc ? */
    if(!(*pHnd = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)root_smpd, &rsmpdArgs, 0, NULL))){
	    smpd_err_printf("unable to create the root listener thread: error %d\n", GetLastError());
	    return SMPD_FAIL;
    }
    /* Wait for 1 minute for root smpd thread to start */
    if (WaitForSingleObject(rsmpdArgs.hRootSMPDRdyEvent, 60000) != WAIT_OBJECT_0){
	    smpd_err_printf("the root process thread failed to initialize.\n");
	    return SMPD_FAIL;
    }
    CloseHandle(rsmpdArgs.hRootSMPDRdyEvent);
    /*GetComputerName(host, &dwLength);*/
    GetComputerNameEx(ComputerNameDnsFullyQualified, host, &dwLength);
#else
    pipe(pipe_fd);
    result = fork();
    if (result == -1){
	    smpd_err_printf("unable to fork the root listener, errno %d\n", errno);
	    return SMPD_FAIL;
    }
    if (result == 0){
        /* child process */
	    close(pipe_fd[0]); /* close the read end of the pipe */
        rsmpdArgs.pipe_fd = pipe_fd[1];
	    result = root_smpd(&rsmpdArgs);
	    exit(result);
    }
    /* parent process */
    PROCESS_HANDLE_SET_PID(*pHnd, result);

    /* close the write end of the pipe */
    close(pipe_fd[1]);
    /* read the port from the root_smpd process */
    readbuf(pipe_fd[0], port, sizeof(int));
    /* read the kvs name */
    readbuf(pipe_fd[0], smpd_process.kvs_name, SMPD_MAX_DBS_NAME_LEN);
    /* close the read end of the pipe */
    close(pipe_fd[0]);
    gethostname(host, len);
#endif
    return SMPD_SUCCESS;
}
Example #15
0
int smpd_get_default_hosts()
{
    char hosts[8192];
    char *host;
    char *ncpu;
    smpd_host_node_t *cur_host, *iter;
#ifdef HAVE_WINDOWS_H
    DWORD len;
#else
    int dynamic = SMPD_FALSE;
    char myhostname[SMPD_MAX_HOST_LENGTH];
    int found;
#endif

    smpd_enter_fn(FCNAME);

    if (smpd_process.default_host_list != NULL && smpd_process.cur_default_host != NULL)
    {
	smpd_dbg_printf("default list already populated, returning success.\n");
	smpd_exit_fn(FCNAME);
	return SMPD_SUCCESS;
    }

    if (smpd_get_smpd_data("hosts", hosts, 8192) != SMPD_SUCCESS)
    {
#ifdef HAVE_WINDOWS_H
	len = 8192;
	/*if (GetComputerName(hosts, &len))*/
	if (GetComputerNameEx(ComputerNameDnsFullyQualified, hosts, &len))
	{
	    smpd_process.default_host_list = (smpd_host_node_t*)MPIU_Malloc(sizeof(smpd_host_node_t));
	    if (smpd_process.default_host_list == NULL)
	    {
		smpd_exit_fn(FCNAME);
		return SMPD_FAIL;
	    }
	    strcpy(smpd_process.default_host_list->host, hosts);
	    smpd_process.default_host_list->alt_host[0] = '\0';
	    smpd_process.default_host_list->nproc = 1;
	    smpd_process.default_host_list->connected = SMPD_FALSE;
	    smpd_process.default_host_list->connect_cmd_tag = -1;
	    smpd_process.default_host_list->next = smpd_process.default_host_list;
	    smpd_process.default_host_list->left = NULL;
	    smpd_process.default_host_list->right = NULL;
	    smpd_process.cur_default_host = smpd_process.default_host_list;
	    smpd_exit_fn(FCNAME);
	    return SMPD_SUCCESS;
	}
	smpd_exit_fn(FCNAME);
	return SMPD_FAIL;
#else
	if (smpd_option_on("no_dynamic_hosts"))
	{
	    if (smpd_get_hostname(myhostname, SMPD_MAX_HOST_LENGTH) == SMPD_SUCCESS)
	    {
		smpd_process.default_host_list = (smpd_host_node_t*)MPIU_Malloc(sizeof(smpd_host_node_t));
		if (smpd_process.default_host_list == NULL)
		{
		    smpd_exit_fn(FCNAME);
		    return SMPD_FAIL;
		}
		strcpy(smpd_process.default_host_list->host, myhostname);
		smpd_process.default_host_list->alt_host[0] = '\0';
		smpd_process.default_host_list->nproc = 1;
		smpd_process.default_host_list->connected = SMPD_FALSE;
		smpd_process.default_host_list->connect_cmd_tag = -1;
		smpd_process.default_host_list->next = smpd_process.default_host_list;
		smpd_process.default_host_list->left = NULL;
		smpd_process.default_host_list->right = NULL;
		smpd_process.cur_default_host = smpd_process.default_host_list;
		smpd_exit_fn(FCNAME);
		return SMPD_SUCCESS;
	    }
	    smpd_exit_fn(FCNAME);
	    return SMPD_FAIL;
	}

	smpd_lock_smpd_data();
	if (smpd_get_smpd_data(SMPD_DYNAMIC_HOSTS_KEY, hosts, 8192) != SMPD_SUCCESS)
	{
	    smpd_unlock_smpd_data();
	    if (smpd_get_hostname(hosts, 8192) == 0)
	    {
		smpd_process.default_host_list = (smpd_host_node_t*)MPIU_Malloc(sizeof(smpd_host_node_t));
		if (smpd_process.default_host_list == NULL)
		{
		    smpd_exit_fn(FCNAME);
		    return SMPD_FAIL;
		}
		strcpy(smpd_process.default_host_list->host, hosts);
		smpd_process.default_host_list->alt_host[0] = '\0';
		smpd_process.default_host_list->nproc = 1;
		smpd_process.default_host_list->connected = SMPD_FALSE;
		smpd_process.default_host_list->connect_cmd_tag = -1;
		smpd_process.default_host_list->next = smpd_process.default_host_list;
		smpd_process.default_host_list->left = NULL;
		smpd_process.default_host_list->right = NULL;
		smpd_process.cur_default_host = smpd_process.default_host_list;
		/* add this host to the dynamic_hosts key */
		strcpy(myhostname, hosts);
		smpd_lock_smpd_data();
		hosts[0] = '\0';
		smpd_get_smpd_data(SMPD_DYNAMIC_HOSTS_KEY, hosts, 8192);
		if (strlen(hosts) > 0)
		{
		    /* FIXME this could overflow */
		    strcat(hosts, " ");
		    strcat(hosts, myhostname);
		}
		else
		{
		    strcpy(hosts, myhostname);
		}
		smpd_set_smpd_data(SMPD_DYNAMIC_HOSTS_KEY, hosts);
		smpd_unlock_smpd_data();
		smpd_exit_fn(FCNAME);
		return SMPD_SUCCESS;
	    }
	    smpd_exit_fn(FCNAME);
	    return SMPD_FAIL;
	}
	smpd_unlock_smpd_data();
	if (smpd_get_hostname(myhostname, SMPD_MAX_HOST_LENGTH) != 0)
	{
	    dynamic = SMPD_FALSE;
	    myhostname[0] = '\0';
	}
	else
	{
	    dynamic = SMPD_TRUE;
	}
#endif
    }

    /* FIXME: Insert code here to parse a compressed host string */
    /* For now, just use a space separated list of host names */

    host = strtok(hosts, " \t\r\n");
    while (host)
    {
	cur_host = (smpd_host_node_t*)MPIU_Malloc(sizeof(smpd_host_node_t));
	if (cur_host != NULL)
	{
	    /*printf("default host: %s\n", host);*/
	    strcpy(cur_host->host, host);
	    cur_host->alt_host[0] = '\0';
	    cur_host->nproc = 1;
	    ncpu = strstr(cur_host->host, ":");
	    if (ncpu)
	    {
		*ncpu = '\0';
		ncpu++;
		cur_host->nproc = atoi(ncpu);
		if (cur_host->nproc < 1)
		    cur_host->nproc = 1;
	    }
	    cur_host->connected = SMPD_FALSE;
	    cur_host->connect_cmd_tag = -1;
	    cur_host->next = NULL;
	    cur_host->left = NULL;
	    cur_host->right = NULL;
	    if (smpd_process.default_host_list == NULL)
	    {
		smpd_process.default_host_list = cur_host;
	    }
	    else
	    {
		iter = smpd_process.default_host_list;
		while (iter->next)
		    iter = iter->next;
		iter->next = cur_host;
	    }
	}
	host = strtok(NULL, " \t\r\n");
    }
    if (smpd_process.default_host_list)
    {
#ifndef HAVE_WINDOWS_H
	if (dynamic)
	{
	    found = SMPD_FALSE;
	    iter = smpd_process.default_host_list;
	    while (iter)
	    {
		if (strcmp(iter->host, myhostname) == 0)
		{
		    found = SMPD_TRUE;
		    break;
		}
		iter = iter->next;
	    }
	    if (!found)
	    {
		/* add this host to the dynamic_hosts key */
		smpd_lock_smpd_data();
		hosts[0] = '\0';
		smpd_get_smpd_data(SMPD_DYNAMIC_HOSTS_KEY, hosts, 8192);
		if (strlen(hosts) > 0)
		{
		    /* FIXME this could overflow */
		    strcat(hosts, " ");
		    strcat(hosts, myhostname);
		}
		else
		{
		    strcpy(hosts, myhostname);
		}
		smpd_set_smpd_data(SMPD_DYNAMIC_HOSTS_KEY, hosts);
		smpd_unlock_smpd_data();
	    }
	}
#endif
	/* make the default list into a ring */
	iter = smpd_process.default_host_list;
	while (iter->next)
	    iter = iter->next;
	iter->next = smpd_process.default_host_list;
	/* point the cur_default_host to the first node in the ring */
	smpd_process.cur_default_host = smpd_process.default_host_list;
    }

    smpd_exit_fn(FCNAME);
    return SMPD_SUCCESS;
}