STABLE14-non-ad-afs-profile-20040819

NetUserGetProfilePath function provided by Rolandas Naujikas


(cherry picked from commit f2b18e7af8)
This commit is contained in:
Rolandas Naujikas 2004-08-19 20:50:58 +00:00 committed by Jeffrey Altman
parent de3c0220a1
commit e92fa6160f
2 changed files with 468 additions and 428 deletions

View File

@ -221,7 +221,9 @@ LOGON_DLLLIBS =\
$(AFSKFWLIB)
LOGON_DLLSDKLIBS =\
dnsapi.lib mpr.lib \
dnsapi.lib \
netapi32.lib \
mpr.lib \
advapi32.lib \
secur32.lib \
strsafe.lib \

View File

@ -14,7 +14,8 @@
#include <sys/types.h>
#include <fcntl.h>
#include <winsock2.h>
#include <winsock2.h> ]
#include <lm.h>
#include <afs/param.h>
#include <afs/stds.h>
@ -58,7 +59,7 @@ void DebugEvent(char *b,...)
StringCbVPrintf(buf, MAXBUF_+1,b,marker);
buf[MAXBUF_] = '\0';
ptbuf[0] = buf;
ReportEvent(h, EVENTLOG_INFORMATION_TYPE, 0, 0, NULL, 1, 0, (const char **)ptbuf, NULL);\
ReportEvent(h, EVENTLOG_INFORMATION_TYPE, 0, 0, NULL, 1, 0, (const char **)ptbuf, NULL);
DeregisterEventSource(h);
va_end(marker);
}
@ -154,11 +155,11 @@ BOOLEAN AFSWillAutoStart(void)
if (pConfig->dwStartType < SERVICE_DEMAND_START)
result = TRUE;
free_pConfig:
free_pConfig:
GlobalFree(pConfig);
close_svc:
close_svc:
CloseServiceHandle(svc);
close_scm:
close_scm:
CloseServiceHandle(scm);
return result;
@ -173,7 +174,7 @@ DWORD MapAuthError(DWORD code)
* WN_SUCCESS. This is highly undesirable, but we also don't want to
* break other network providers.
*/
/* case KTC_NOCM:
/* case KTC_NOCM:
case KTC_NOCMRPC:
return WN_NO_NETWORK; */
default: return WN_SUCCESS;
@ -196,6 +197,40 @@ DWORD APIENTRY NPGetCaps(DWORD index)
}
}
static NET_API_STATUS
NetUserGetProfilePath( LPCWSTR Domain, LPCWSTR UserName, char * profilePath, DWORD profilePathLen )
{
NET_API_STATUS code;
LPWSTR ServerName = NULL;
LPUSER_INFO_3 p3 = NULL;
code = NetGetAnyDCName(NULL, Domain, (LPBYTE *)&ServerName);
if (code != NERR_Success)
return code;
if (ServerName == NULL)
return NERR_InvalidComputer;
code = NetUserGetInfo(ServerName, UserName, 3, (LPBYTE *)&p3);
if (code == NERR_Success)
{
code = NERR_UserNotFound;
if (p3) {
if (p3->usri3_profile) {
DWORD len = lstrlenW(p3->usri3_profile);
/* Convert From Unicode to ASCII */
len = len < profilePathLen ? len : profilePathLen - 1;
CharToOemBuffW(p3->usri3_profile, profilePath, len);
profilePath[len] = '\0';
code = NERR_Success;
}
NetApiBufferFree(p3);
}
}
NetApiBufferFree(ServerName);
return code;
}
BOOL IsServiceRunning (void)
{
SERVICE_STATUS Status;
@ -251,7 +286,8 @@ BOOL IsServiceRunning (void)
/* Get domain specific configuration info. We are returning void because if anything goes wrong
we just return defaults.
*/
void GetDomainLogonOptions( PLUID lpLogonId, char * username, char * domain, LogonOptions_t *opt ) {
void
GetDomainLogonOptions( PLUID lpLogonId, char * username, char * domain, LogonOptions_t *opt ) {
HKEY hkParm = NULL; /* Service parameter */
HKEY hkNp = NULL; /* network provider key */
HKEY hkDoms = NULL; /* domains key */
@ -322,7 +358,7 @@ void GetDomainLogonOptions( PLUID lpLogonId, char * username, char * domain, Log
/* FailLoginsSilently */
dwSize = sizeof(dwDummy);
rv = RegQueryValueEx(hkParm, REG_CLIENT_FAIL_SILENTLY_PARM, 0, &dwType, (LPBYTE) &dwDummy, &dwSize);
if(rv != ERROR_SUCCESS)
if (rv != ERROR_SUCCESS)
LOOKUPKEYCHAIN(dwDummy, REG_DWORD, DEFAULT_FAIL_SILENTLY, REG_CLIENT_FAIL_SILENTLY_PARM);
opt->failSilently = !!dwDummy;
@ -378,7 +414,7 @@ void GetDomainLogonOptions( PLUID lpLogonId, char * username, char * domain, Log
strlwr(opt->smbName);
bad_strings:
bad_strings:
LsaFreeReturnBuffer(plsd);
}
@ -468,13 +504,13 @@ bad_strings:
else
LocalFree(regexuscript);
doneLogonScript:
doneLogonScript:
if(wuname) free(wuname);
if(regscript) free(regscript);
if(regexscript) free(regexscript);
}
cleanup:
cleanup:
if(hkNp) RegCloseKey(hkNp);
if(hkDom) RegCloseKey(hkDom);
if(hkDoms) RegCloseKey(hkDoms);
@ -885,9 +921,11 @@ VOID AFS_Logoff_Event( PWLX_NOTIFICATION_INFO pInfo )
if (QueryAdHomePathFromSid( profileDir, sizeof(profileDir), tokenUser->User.Sid, pInfo->Domain)) {
WCHAR Domain[64]=L"";
GetLocalShortDomain(Domain, sizeof(Domain));
if (QueryAdHomePathFromSid( profileDir, sizeof(profileDir), tokenUser->User.Sid, Domain))
if (QueryAdHomePathFromSid( profileDir, sizeof(profileDir), tokenUser->User.Sid, Domain)) {
if (NetUserGetProfilePath(pInfo->Domain, pInfo->UserName, profileDir, &len))
GetUserProfileDirectory(pInfo->hToken, profileDir, &len);
}
}
if (strlen(profileDir)) {
DebugEvent("Profile Directory: %s", profileDir);