@@ -97,6 +97,23 @@ static char pw_homedir_ascii[MAX_PATH] = {'\0'};
97
97
static char pw_password [MAX_PATH ] = {'\0' };
98
98
static char pw_shellpath [MAX_PATH ] = {'\0' };
99
99
100
+ /* given a access token, find the domain name of user account of the access token */
101
+ int GetDomainFromToken ( HANDLE * hAccessToken , UCHAR * domain , DWORD dwSize )
102
+ {
103
+ UCHAR InfoBuffer [1000 ],username [200 ];
104
+ PTOKEN_USER pTokenUser = (PTOKEN_USER )InfoBuffer ;
105
+ DWORD dwInfoBufferSize ,dwAccountSize = 200 , dwDomainSize = dwSize ;
106
+ SID_NAME_USE snu ;
107
+
108
+ domain [0 ] = '\0' ;
109
+ GetTokenInformation (* hAccessToken ,TokenUser ,InfoBuffer ,
110
+ 1000 , & dwInfoBufferSize );
111
+
112
+ LookupAccountSid (NULL , pTokenUser -> User .Sid , (LPSTR )username ,
113
+ & dwAccountSize ,(LPSTR )domain , & dwDomainSize , & snu );
114
+ return 0 ;
115
+ }
116
+
100
117
/*
101
118
* Retrieve user homedir from token, save it in static string
102
119
* and return pointer to this string.
@@ -109,24 +126,30 @@ static char pw_shellpath[MAX_PATH] = {'\0'};
109
126
110
127
char * GetHomeDirFromToken (char * userName , HANDLE token )
111
128
{
112
-
113
- wchar_t userNameW [UNLEN + 1 ];
129
+ UCHAR domain [200 ];
114
130
115
131
debug ("-> GetHomeDirFromToken()..." );
116
132
117
- PROFILEINFOW profileInfo ;
118
-
119
- if (MultiByteToWideChar (CP_UTF8 , 0 , userName , -1 , userNameW , UNLEN ) == 0 )
120
- {
121
- debug ("userName encoding conversion failure" );
122
- return NULL ;
123
- }
124
-
125
- memset (& profileInfo , 0 , sizeof (profileInfo ));
133
+ PROFILEINFO profileInfo ;
134
+
135
+ // find the server name of the domain controller which created this token
136
+ GetDomainFromToken ( & token , domain , sizeof (domain ));
137
+ //if (MultiByteToWideChar(CP_UTF8, 0, domain, -1, domainW, sizeof(domainW)) == 0)
138
+ //{
139
+ //debug("DomainServerName encoding conversion failure");
140
+ //return NULL;
141
+ //}
142
+
143
+ profileInfo .dwFlags = PI_NOUI ;
144
+ profileInfo .lpProfilePath = NULL ;
145
+ profileInfo .lpUserName = userName ;
146
+ profileInfo .lpDefaultPath = NULL ;
147
+ profileInfo .lpServerName = domain ;
148
+ profileInfo .lpPolicyPath = NULL ;
149
+ profileInfo .hProfile = NULL ;
150
+ profileInfo .dwSize = sizeof (profileInfo );
151
+
126
152
127
- profileInfo .dwSize = sizeof (profileInfo );
128
- profileInfo .lpUserName = userNameW ;
129
- profileInfo .lpServerName = NULL ;
130
153
131
154
if (LoadUserProfile (token , & profileInfo ) == FALSE)
132
155
{
0 commit comments