Exemple #1
0
int ntlm_SetContextTargetName(NTLM_CONTEXT* context, char* TargetName)
{
	int status;
	DWORD nSize = 0;
	char* name = TargetName;

	if (!TargetName)
	{
		if (!GetComputerNameExA(ComputerNameDnsHostname, NULL, &nSize))
			return -1;

		name = (char*) malloc(nSize);

		if (!name)
			return -1;

		if (!GetComputerNameExA(ComputerNameDnsHostname, name, &nSize))
			return -1;

		CharUpperA(TargetName);
	}

	context->TargetName.pvBuffer = NULL;
	status = ConvertToUnicode(CP_UTF8, 0, name, -1, (LPWSTR*) &context->TargetName.pvBuffer, 0);

	if (status <= 0)
		return -1;

	context->TargetName.cbBuffer = (USHORT) ((status - 1) * 2);

	if (!TargetName)
		free(name);

	return 1;
}
Exemple #2
0
int ntlm_SetContextWorkstation(NTLM_CONTEXT* context, char* Workstation)
{
	int status;
	DWORD nSize = 0;
	char* ws = Workstation;

	if (!Workstation)
	{
		GetComputerNameExA(ComputerNameNetBIOS, NULL, &nSize);
		
		ws = (char*) malloc(nSize);

		if (!ws)
			return -1;

		if (!GetComputerNameExA(ComputerNameNetBIOS, ws, &nSize))
			return 0;
	}

	context->Workstation.Buffer = NULL;
	status = ConvertToUnicode(CP_UTF8, 0, ws, -1, &context->Workstation.Buffer, 0);
	free(ws);

	if (status <= 0)
		return -1;

	context->Workstation.Length = (USHORT) (status - 1);
	context->Workstation.Length *= 2;

	if (!Workstation)
		free(Workstation);

	return 1;
}
Exemple #3
0
void settings_get_computer_name(rdpSettings* settings)
{
	DWORD nSize = 0;

	GetComputerNameExA(ComputerNameNetBIOS, NULL, &nSize);
	settings->ComputerName = (char*) malloc(nSize);
	GetComputerNameExA(ComputerNameNetBIOS, settings->ComputerName, &nSize);
}
Exemple #4
0
int ntlm_SetContextTargetName(NTLM_CONTEXT* context, char* TargetName)
{
	int status;
	char* name = TargetName;
	DWORD nSize = 0;
	CHAR* computerName = NULL;

	if (!name)
	{
		if (GetComputerNameExA(ComputerNameNetBIOS, NULL, &nSize) || (GetLastError() != ERROR_MORE_DATA) ||
		    (nSize < 2))
			return -1;

		computerName = calloc(nSize, sizeof(CHAR));

		if (!computerName)
			return -1;

		if (!GetComputerNameExA(ComputerNameNetBIOS, computerName, &nSize))
		{
			free(computerName);
			return -1;
		}

		if (nSize > MAX_COMPUTERNAME_LENGTH)
			computerName[MAX_COMPUTERNAME_LENGTH] = '\0';

		name = computerName;

		if (!name)
			return -1;

		CharUpperA(name);
	}

	context->TargetName.pvBuffer = NULL;
	status = ConvertToUnicode(CP_UTF8, 0, name, -1, (LPWSTR*) &context->TargetName.pvBuffer, 0);

	if (status <= 0)
	{
		if (!TargetName)
			free(name);

		return -1;
	}

	context->TargetName.cbBuffer = (USHORT)((status - 1) * 2);

	if (!TargetName)
		free(name);

	return 1;
}
Exemple #5
0
static char *get_computer_name( COMPUTER_NAME_FORMAT format )
{
    char *ret;
    DWORD size = 0;

    GetComputerNameExA( format, NULL, &size );
    if (GetLastError() != ERROR_MORE_DATA) return NULL;
    if (!(ret = heap_alloc( size ))) return NULL;
    if (!GetComputerNameExA( format, ret, &size ))
    {
        heap_free( ret );
        return NULL;
    }
    return ret;
}
Exemple #6
0
/** @brief returns host name of this host
 *
 * @param hostname buffer (hostname will be stored here)
 * @param hostname_len length of the buffer
 * @return LOWLEVEL_NO_ERROR if successful, appropriate LOWLEVEL_ERROR_* otherwise
 */
int get_hostname(char* hostname, int hostname_len) {
    memset(hostname,0, hostname_len);
    if (GetComputerNameExA(ComputerNameDnsFullyQualified, hostname, &hostname_len)) {
        return LOWLEVEL_NO_ERROR;
    }
    return LOWLEVEL_ERROR_UNSPEC;
}
std::string hostname()
{
  char buf[1000];
  DWORD bufsize = sizeof(buf);
  GetComputerNameExA(ComputerNameDnsHostname, buf, &bufsize);
  return std::string(buf, bufsize);
}
Exemple #8
0
int ntlm_SetContextWorkstation(NTLM_CONTEXT* context, char* Workstation)
{
	int status;
	char* ws = Workstation;
	DWORD nSize = 0;
	CHAR* computerName;

	if (!Workstation)
	{
		if (GetComputerNameExA(ComputerNameNetBIOS, NULL, &nSize) || (GetLastError() != ERROR_MORE_DATA) ||
		    (nSize < 2))
			return -1;

		computerName = calloc(nSize, sizeof(CHAR));

		if (!computerName)
			return -1;

		if (!GetComputerNameExA(ComputerNameNetBIOS, computerName, &nSize))
		{
			free(computerName);
			return -1;
		}

		if (nSize > MAX_COMPUTERNAME_LENGTH)
			computerName[MAX_COMPUTERNAME_LENGTH] = '\0';

		ws = computerName;

		if (!ws)
			return -1;
	}

	context->Workstation.Buffer = NULL;
	status = ConvertToUnicode(CP_UTF8, 0, ws, -1, &context->Workstation.Buffer, 0);

	if (!Workstation)
		free(ws);

	if (status <= 0)
		return -1;

	context->Workstation.Length = (USHORT)(status - 1);
	context->Workstation.Length *= 2;
	return 1;
}
Exemple #9
0
void ntlm_SetContextWorkstation(NTLM_CONTEXT* context, char* Workstation)
{
	DWORD nSize = 0;

	if (!Workstation)
	{
		GetComputerNameExA(ComputerNameNetBIOS, NULL, &nSize);
		Workstation = malloc(nSize);
		GetComputerNameExA(ComputerNameNetBIOS, Workstation, &nSize);
	}

	context->Workstation.Length = strlen(Workstation) * 2;
	context->Workstation.Buffer = (PWSTR) malloc(context->Workstation.Length);
	MultiByteToWideChar(CP_ACP, 0, Workstation, strlen(Workstation),
			context->Workstation.Buffer, context->Workstation.Length / 2);

	if (nSize > 0)
		free(Workstation);
}
Exemple #10
0
void ntlm_SetContextTargetName(NTLM_CONTEXT* context, char* TargetName)
{
	DWORD nSize = 0;

	if (!TargetName)
	{
		GetComputerNameExA(ComputerNameDnsHostname, NULL, &nSize);
		TargetName = malloc(nSize);
		GetComputerNameExA(ComputerNameDnsHostname, TargetName, &nSize);
		CharUpperA(TargetName);
	}

	context->TargetName.cbBuffer = strlen(TargetName) * 2;
	context->TargetName.pvBuffer = (void*) malloc(context->TargetName.cbBuffer);
	MultiByteToWideChar(CP_ACP, 0, TargetName, strlen(TargetName),
			(LPWSTR) context->TargetName.pvBuffer, context->TargetName.cbBuffer / 2);

	if (nSize > 0)
		free(TargetName);
}
Exemple #11
0
void ntlm_get_target_computer_name(PUNICODE_STRING pName, COMPUTER_NAME_FORMAT type)
{
	char* name;
	DWORD nSize = 0;

	GetComputerNameExA(type, NULL, &nSize);
	name = malloc(nSize);
	GetComputerNameExA(type, name, &nSize);

	if (type == ComputerNameNetBIOS)
		CharUpperA(name);

	pName->Length = strlen(name) * 2;
	pName->Buffer = (PWSTR) malloc(pName->Length);
	MultiByteToWideChar(CP_ACP, 0, name, strlen(name),
			(LPWSTR) pName->Buffer, pName->Length / 2);

	pName->MaximumLength = pName->Length;

	free(name);
}
Exemple #12
0
BOOL settings_get_computer_name(rdpSettings* settings)
{
	DWORD nSize = MAX_COMPUTERNAME_LENGTH + 1;
	CHAR computerName[MAX_COMPUTERNAME_LENGTH + 1];

	if (!GetComputerNameExA(ComputerNameNetBIOS, computerName, &nSize))
		return FALSE;

	settings->ComputerName = _strdup(computerName);
	if (!settings->ComputerName)
		return FALSE;

	return TRUE;
}
Exemple #13
0
static DNS_STATUS dns_get_hostname_a( COMPUTER_NAME_FORMAT format,
                                      PSTR buffer, PDWORD len )
{
    char name[256];
    DWORD size = sizeof(name);

    if (!GetComputerNameExA( format, name, &size ))
        return DNS_ERROR_NAME_DOES_NOT_EXIST;

    if (!buffer || (size = lstrlenA( name ) + 1) > *len)
    {
        *len = size;
        return ERROR_INSUFFICIENT_BUFFER;
    }

    lstrcpyA( buffer, name );
    return ERROR_SUCCESS;
}