1999-01-03 13:48:29 +01:00
|
|
|
/*
|
|
|
|
* Win32 advapi functions
|
|
|
|
*
|
|
|
|
* Copyright 1995 Sven Verdoolaege
|
|
|
|
*/
|
|
|
|
|
2001-11-20 21:26:54 +01:00
|
|
|
#include <errno.h>
|
1999-06-12 16:55:11 +02:00
|
|
|
#include <stdio.h>
|
1999-02-17 14:51:06 +01:00
|
|
|
#include <unistd.h>
|
1999-02-19 16:42:11 +01:00
|
|
|
#include <string.h>
|
2000-08-14 16:42:41 +02:00
|
|
|
#include <pwd.h>
|
1999-02-17 14:51:06 +01:00
|
|
|
|
1999-07-03 18:01:42 +02:00
|
|
|
#include "winbase.h"
|
1999-03-14 17:35:05 +01:00
|
|
|
#include "windef.h"
|
2000-11-28 23:40:56 +01:00
|
|
|
#include "winnls.h"
|
1999-01-03 13:48:29 +01:00
|
|
|
#include "winerror.h"
|
|
|
|
|
1999-05-14 10:17:14 +02:00
|
|
|
#include "debugtools.h"
|
1999-02-17 14:51:06 +01:00
|
|
|
|
2001-11-20 21:26:54 +01:00
|
|
|
DEFAULT_DEBUG_CHANNEL(advapi);
|
1999-01-03 13:48:29 +01:00
|
|
|
|
1999-01-28 14:46:25 +01:00
|
|
|
/******************************************************************************
|
2001-02-15 00:11:17 +01:00
|
|
|
* GetUserNameA [ADVAPI32.@]
|
2001-11-20 21:26:54 +01:00
|
|
|
*
|
|
|
|
* NOTE: lpSize returns the total length of the username, including the
|
|
|
|
* terminating null character.
|
1999-01-03 13:48:29 +01:00
|
|
|
*/
|
1999-02-26 12:11:13 +01:00
|
|
|
BOOL WINAPI
|
|
|
|
GetUserNameA( LPSTR lpszName, LPDWORD lpSize )
|
1999-01-03 13:48:29 +01:00
|
|
|
{
|
|
|
|
size_t len;
|
|
|
|
char *name;
|
|
|
|
|
2000-08-14 16:42:41 +02:00
|
|
|
struct passwd *pwd = getpwuid( getuid() );
|
2001-11-20 21:26:54 +01:00
|
|
|
if (!pwd)
|
|
|
|
{
|
|
|
|
ERR("Username lookup failed: %s\n", strerror(errno));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-08-14 16:42:41 +02:00
|
|
|
name = pwd->pw_name;
|
2001-11-20 21:26:54 +01:00
|
|
|
|
|
|
|
/* We need to include the null character when determining the size of the buffer. */
|
|
|
|
len = strlen(name) + 1;
|
|
|
|
if (len > *lpSize)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_MORE_DATA);
|
|
|
|
*lpSize = len;
|
1999-01-03 13:48:29 +01:00
|
|
|
return 0;
|
|
|
|
}
|
2001-11-20 21:26:54 +01:00
|
|
|
|
|
|
|
*lpSize = len;
|
1999-01-03 13:48:29 +01:00
|
|
|
strcpy(lpszName, name);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
1999-01-28 14:46:25 +01:00
|
|
|
/******************************************************************************
|
2001-02-15 00:11:17 +01:00
|
|
|
* GetUserNameW [ADVAPI32.@]
|
1999-01-28 14:46:25 +01:00
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* lpszName []
|
|
|
|
* lpSize []
|
1999-01-03 13:48:29 +01:00
|
|
|
*/
|
1999-02-26 12:11:13 +01:00
|
|
|
BOOL WINAPI
|
|
|
|
GetUserNameW( LPWSTR lpszName, LPDWORD lpSize )
|
1999-01-03 13:48:29 +01:00
|
|
|
{
|
|
|
|
LPSTR name = (LPSTR)HeapAlloc( GetProcessHeap(), 0, *lpSize );
|
|
|
|
DWORD size = *lpSize;
|
1999-02-26 12:11:13 +01:00
|
|
|
BOOL res = GetUserNameA(name,lpSize);
|
1999-01-03 13:48:29 +01:00
|
|
|
|
2000-11-28 23:40:56 +01:00
|
|
|
/* FIXME: should set lpSize in WCHARs */
|
|
|
|
if (size && !MultiByteToWideChar( CP_ACP, 0, name, -1, lpszName, size ))
|
|
|
|
lpszName[size-1] = 0;
|
1999-01-03 13:48:29 +01:00
|
|
|
HeapFree( GetProcessHeap(), 0, name );
|
|
|
|
return res;
|
|
|
|
}
|