OpenThreadToken & loadUserProfile in Vista/Win7



  • Hi,

    ich versuche das Userprofil mittels loadUserProfile zu laden, das übergeben Token hole ich mit

    OpenThreadToken(GetCurrentThread(), 
    			 TOKEN_QUERY|TOKEN_ASSIGN_PRIMARY|TOKEN_DUPLICATE|TOKEN_IMPERSONATE,
    	 	openAsSelf, &threadToken)
    

    raus. Unter Windows XP klappt das auch wunderbar, unter Vista/Windows 7 bekomme ich aber beim loadUserProfile die fehlernummer 1008 zurück.
    Das ganze läuft im Spooler context, in einer dll da es sich um einen Druckertreiber handelt. Das ganze ist in VS6 gebaut und hat auch bis dato super funktioniert.
    Was kann man da machen?

    grüße
    Henry





  • Hi,

    ja das hab ich auch ausprobiert, erst token holen:

    if (!OpenThreadToken(GetCurrentThread(), TOKEN_QUERY|TOKEN_DUPLICATE|TOKEN_IMPERSONATE, TRUE, &Token)){
    		DWORD error = GetLastError();
    		if (error == ERROR_NO_TOKEN)
    		{
    			rc=OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY|TOKEN_DUPLICATE|TOKEN_IMPERSONATE, &Token);
    		}
    	}
    

    dann Profil laden:

    client = RevertToPrinterSelf();
    	// LoadUserProfile() open registry user hive
    	// This is needed by CreateEnvironmentBlock() to include user-specific 
    	// environment variables such as %USERPROFILE% 
    	profileInfo = new(sizeof(PROFILEINFO));
    	memset(profileInfo, 0, sizeof(PROFILEINFO));
    	profileInfo->dwSize = sizeof(PROFILEINFO);
    	profileInfo->lpUserName = (wchar_t*)userName;
    	profileInfo->hProfile = NULL;
    	profileInfo->dwFlags = PI_NOUI;
    
    	rc = LoadUserProfile(Token, profileInfo);
    

    dann bekomm ich aber den 1008 Fehler, ich kapiers nicht, fehlt da noch was?

    Dem Spooler musste ich in der Registry die Berechtigungen SeRestorePrivilege & SeBackupPrivilege zuweisen da ich sonst die 1314 (Berechtigunsproblem) bekommen habe.

    Hab im Netz im zusammenhang mit citrix was von "assuming thread is not impersonating" gelesen, weiss nur nicht was ich da machen sollte in meinem fall.

    Später im code versuch ich auch mittels

    threadToken = getThreadToken(); //ruft den ersten codeabschnitt oben auf
    	if (threadToken != NULL)
    	{
    		// make a primary token from thread token (client impersonation)
    		securityAttributes = new(sizeof(SECURITY_ATTRIBUTES));
    		memset(securityAttributes, 0, sizeof(SECURITY_ATTRIBUTES));
    		securityAttributes->nLength = sizeof(SECURITY_ATTRIBUTES);
    		securityAttributes->lpSecurityDescriptor = NULL;
    		securityAttributes->bInheritHandle = TRUE; // token gets inherited
    		rc = DuplicateTokenEx(
    			threadToken, TOKEN_IMPERSONATE|TOKEN_READ|TOKEN_ASSIGN_PRIMARY|TOKEN_DUPLICATE,
    			securityAttributes,
    			SecurityImpersonation, TokenPrimary, &primaryToken);
    		CloseHandle(threadToken);
    	}
    

    und gebe das dann an LoadUserProfile, bekomme aber den gleichen Fehler.

    grüße
    Henry


Anmelden zum Antworten