logonuser returns 1314
-
when i try to impersonate the process to a different user,the logonUser call fails with error no 1314 (privilage not held by the client ) in windows 2000 series it was working in xp series of os Please find sample code below #define SECURITY_WIN32 #include <windows.h> #include <tchar.h> #include <stdio.h> #include <conio.h> #include <sspi.h> #include <lm.h> #include <lmcons.h> #include <userenv.h> #ifndef SEC_I_COMPLETE_NEEDED #include <issperr.h> #endif typedef struct _AUTH_SEQ { BOOL fInitialized; BOOL fHaveCredHandle; BOOL fHaveCtxtHandle; CredHandle hcred; struct _SecHandle hctxt; } AUTH_SEQ, *PAUTH_SEQ; // Function pointers ACCEPT_SECURITY_CONTEXT_FN _AcceptSecurityContext = NULL; ACQUIRE_CREDENTIALS_HANDLE_FN _AcquireCredentialsHandle = NULL; COMPLETE_AUTH_TOKEN_FN _CompleteAuthToken = NULL; DELETE_SECURITY_CONTEXT_FN _DeleteSecurityContext = NULL; FREE_CONTEXT_BUFFER_FN _FreeContextBuffer = NULL; FREE_CREDENTIALS_HANDLE_FN _FreeCredentialsHandle = NULL; INITIALIZE_SECURITY_CONTEXT_FN _InitializeSecurityContext = NULL; QUERY_SECURITY_PACKAGE_INFO_FN _QuerySecurityPackageInfo = NULL; QUERY_SECURITY_CONTEXT_TOKEN_FN _QuerySecurityContextToken = NULL; #define CheckAndLocalFree(ptr) \ if (ptr != NULL) \ { \ LocalFree(ptr); \ ptr = NULL; \ } #pragma comment(lib, "netapi32.lib") LPVOID RetrieveTokenInformationClass( HANDLE hToken, TOKEN_INFORMATION_CLASS InfoClass, LPDWORD lpdwSize) { LPVOID pInfo = NULL; BOOL fSuccess = FALSE; __try { *lpdwSize = 0; GetTokenInformation( hToken, InfoClass, NULL, *lpdwSize, lpdwSize); if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) { _tprintf(_T("GetTokenInformation failed with %d\n"), GetLastError()); __leave; } pInfo = LocalAlloc(LPTR, *lpdwSize); if (pInfo == NULL) { _tprintf(_T("LocalAlloc failed with %d\n"), GetLastError()); __leave; } if (!GetTokenInformation( hToken, InfoClass, pInfo, *lpdwSize, lpdwSize)) { _tprintf(_T("GetTokenInformation failed with %d\n"), GetLastError()); __leave; } fSuccess
-
when i try to impersonate the process to a different user,the logonUser call fails with error no 1314 (privilage not held by the client ) in windows 2000 series it was working in xp series of os Please find sample code below #define SECURITY_WIN32 #include <windows.h> #include <tchar.h> #include <stdio.h> #include <conio.h> #include <sspi.h> #include <lm.h> #include <lmcons.h> #include <userenv.h> #ifndef SEC_I_COMPLETE_NEEDED #include <issperr.h> #endif typedef struct _AUTH_SEQ { BOOL fInitialized; BOOL fHaveCredHandle; BOOL fHaveCtxtHandle; CredHandle hcred; struct _SecHandle hctxt; } AUTH_SEQ, *PAUTH_SEQ; // Function pointers ACCEPT_SECURITY_CONTEXT_FN _AcceptSecurityContext = NULL; ACQUIRE_CREDENTIALS_HANDLE_FN _AcquireCredentialsHandle = NULL; COMPLETE_AUTH_TOKEN_FN _CompleteAuthToken = NULL; DELETE_SECURITY_CONTEXT_FN _DeleteSecurityContext = NULL; FREE_CONTEXT_BUFFER_FN _FreeContextBuffer = NULL; FREE_CREDENTIALS_HANDLE_FN _FreeCredentialsHandle = NULL; INITIALIZE_SECURITY_CONTEXT_FN _InitializeSecurityContext = NULL; QUERY_SECURITY_PACKAGE_INFO_FN _QuerySecurityPackageInfo = NULL; QUERY_SECURITY_CONTEXT_TOKEN_FN _QuerySecurityContextToken = NULL; #define CheckAndLocalFree(ptr) \ if (ptr != NULL) \ { \ LocalFree(ptr); \ ptr = NULL; \ } #pragma comment(lib, "netapi32.lib") LPVOID RetrieveTokenInformationClass( HANDLE hToken, TOKEN_INFORMATION_CLASS InfoClass, LPDWORD lpdwSize) { LPVOID pInfo = NULL; BOOL fSuccess = FALSE; __try { *lpdwSize = 0; GetTokenInformation( hToken, InfoClass, NULL, *lpdwSize, lpdwSize); if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) { _tprintf(_T("GetTokenInformation failed with %d\n"), GetLastError()); __leave; } pInfo = LocalAlloc(LPTR, *lpdwSize); if (pInfo == NULL) { _tprintf(_T("LocalAlloc failed with %d\n"), GetLastError()); __leave; } if (!GetTokenInformation( hToken, InfoClass, pInfo, *lpdwSize, lpdwSize)) { _tprintf(_T("GetTokenInformation failed with %d\n"), GetLastError()); __leave; } fSuccess
vineeshV wrote:
Please help me ....
Why not help us by removing 99% of your code from this post? Do you honestly think anyone would spend their valuable time reading through all of this? :rolleyes:
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne