PDA

View Full Version : [C++] NT access token


Teo@Unix
18-10-2010, 13:08
Ciao,

sto rivedendo un pò di cose riguardo a NT...
mi domando perchè molto spesso vengono chiamate routine del tipo seguente...

so che quando un utente riesce a loggarsi viene creato il rispettivo access token, perchè prima di lavorare su processi o altro vengono eseguite le funzioni per la modifica dell'access token? E' una procedura di sicurezza ?
Leggendo su MSDN mi sembra di capire che tutte le volte occorre fare una operazione di un certo tipo, i privilegi vanno abilitati modificando il token utente. mi date conferma?

Ad esempio:

BOOL EnableTokenPrivilege(HANDLE htok, LPCTSTR szPrivilege, TOKEN_PRIVILEGES& tpOld)

{
TOKEN_PRIVILEGES tp;
tp.PrivilegeCount = 1;
tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
if (LookupPrivilegeValue(0, szPrivilege, &tp.Privileges[0].Luid)) {

// htok must have been opened with the following permissions:
// TOKEN_QUERY (to get the old priv setting)
// TOKEN_ADJUST_PRIVILEGES (to adjust the priv)

DWORD cbOld = sizeof tpOld;

if (AdjustTokenPrivileges(htok, FALSE, &tp, cbOld, &tpOld, &cbOld))

// Note that AdjustTokenPrivileges may succeed, and yet
// some privileges weren't actually adjusted.
// You've got to check GetLastError() to be sure!
return(ERROR_NOT_ALL_ASSIGNED != GetLastError());
else
return(FALSE);
}
else
return(FALSE);
}