Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wine-winehq
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wine
wine-winehq
Commits
f8fb43aa
Commit
f8fb43aa
authored
Apr 16, 2020
by
Alexandre Julliard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
advapi32: Use WINEUSERNAME variable to implement GetUserNameA/W.
Signed-off-by:
Alexandre Julliard
<
julliard@winehq.org
>
parent
52bf0fbd
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
65 deletions
+14
-65
advapi.c
dlls/advapi32/advapi.c
+14
-65
No files found.
dlls/advapi32/advapi.c
View file @
f8fb43aa
...
...
@@ -32,7 +32,6 @@
#include "wincred.h"
#include "wct.h"
#include "wine/library.h"
#include "wine/unicode.h"
#include "wine/debug.h"
...
...
@@ -42,81 +41,31 @@ WINE_DEFAULT_DEBUG_CHANNEL(advapi);
/******************************************************************************
* GetUserNameA [ADVAPI32.@]
*
* Get the current user name.
*
* PARAMS
* lpszName [O] Destination for the user name.
* lpSize [I/O] Size of lpszName.
*
* RETURNS
* Success: The length of the user name, including terminating NUL.
* Failure: ERROR_MORE_DATA if *lpSize is too small.
*/
BOOL
WINAPI
GetUserNameA
(
LPSTR
lpszName
,
LPDWORD
lpSize
)
BOOL
WINAPI
GetUserNameA
(
LPSTR
name
,
LPDWORD
size
)
{
WCHAR
*
buffer
;
DWORD
len
=
GetEnvironmentVariableA
(
"WINEUSERNAME"
,
name
,
*
size
)
;
BOOL
ret
;
DWORD
sizeW
=
*
lpSize
;
if
(
!
(
buffer
=
heap_alloc
(
sizeW
*
sizeof
(
WCHAR
)
)))
{
SetLastError
(
ERROR_NOT_ENOUGH_MEMORY
);
return
FALSE
;
}
ret
=
GetUserNameW
(
buffer
,
&
sizeW
);
if
(
ret
)
*
lpSize
=
WideCharToMultiByte
(
CP_ACP
,
0
,
buffer
,
-
1
,
lpszName
,
*
lpSize
,
NULL
,
NULL
);
else
*
lpSize
=
sizeW
;
heap_free
(
buffer
);
if
(
!
len
)
return
FALSE
;
if
((
ret
=
(
len
<
*
size
)))
len
++
;
*
size
=
len
;
return
ret
;
}
/******************************************************************************
* GetUserNameW [ADVAPI32.@]
*
* See GetUserNameA.
*/
BOOL
WINAPI
GetUserNameW
(
LPWSTR
lpszName
,
LPDWORD
lpSize
)
BOOL
WINAPI
GetUserNameW
(
LPWSTR
name
,
LPDWORD
size
)
{
const
char
*
name
=
wine_get_user_name
();
DWORD
i
,
len
=
MultiByteToWideChar
(
CP_UNIXCP
,
0
,
name
,
-
1
,
NULL
,
0
);
LPWSTR
backslash
;
if
(
len
>
*
lpSize
)
{
SetLastError
(
ERROR_INSUFFICIENT_BUFFER
);
*
lpSize
=
len
;
return
FALSE
;
}
*
lpSize
=
len
;
MultiByteToWideChar
(
CP_UNIXCP
,
0
,
name
,
-
1
,
lpszName
,
len
);
/* Word uses the user name to create named mutexes and file mappings,
* and backslashes in the name cause the creation to fail.
* Also, Windows doesn't return the domain name in the user name even when
* joined to a domain. A Unix box joined to a domain using winbindd will
* contain the domain name in the username. So we need to cut this off.
* FIXME: Only replaces forward and backslashes for now, should get the
* winbind separator char from winbindd and replace that.
*/
for
(
i
=
0
;
lpszName
[
i
];
i
++
)
if
(
lpszName
[
i
]
==
'/'
)
lpszName
[
i
]
=
'\\'
;
backslash
=
strrchrW
(
lpszName
,
'\\'
);
if
(
backslash
==
NULL
)
return
TRUE
;
len
=
lstrlenW
(
backslash
);
memmove
(
lpszName
,
backslash
+
1
,
len
*
sizeof
(
WCHAR
));
*
lpSize
=
len
;
return
TRUE
;
static
const
WCHAR
wineusernameW
[]
=
{
'W'
,
'I'
,
'N'
,
'E'
,
'U'
,
'S'
,
'E'
,
'R'
,
'N'
,
'A'
,
'M'
,
'E'
,
0
};
DWORD
len
=
GetEnvironmentVariableW
(
wineusernameW
,
name
,
*
size
);
BOOL
ret
;
if
(
!
len
)
return
FALSE
;
if
((
ret
=
(
len
<
*
size
)))
len
++
;
*
size
=
len
;
return
ret
;
}
/******************************************************************************
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment