winlogon.cpp revision b8908d384db2324f04a2f68a13e67ea32ebf609a
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync/** @file
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync *
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync * VBox Remote Desktop Protocol:
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync * External Authentication Library:
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync * Windows Logon Authentication.
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync */
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync/*
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync * Copyright (C) 2006-2010 Oracle Corporation
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync *
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync * available from http://www.virtualbox.org. This file is free software;
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync * you can redistribute it and/or modify it under the terms of the GNU
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync * General Public License (GPL) as published by the Free Software
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync */
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync/* If defined, debug messages will be written to the specified file. */
8b98c71a5a01d215eafbc3605cb7a66cc91ea774vboxsync// #define AUTH_DEBUG_FILE_NAME "\\VBoxAuth.log"
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync#include <stdio.h>
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync#include <string.h>
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync#include <Windows.h>
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync
b8908d384db2324f04a2f68a13e67ea32ebf609avboxsync#include <VBox/VBoxAuth.h>
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsyncstatic void dprintf(const char *fmt, ...)
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync{
8b98c71a5a01d215eafbc3605cb7a66cc91ea774vboxsync#ifdef AUTH_DEBUG_FILE_NAME
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync va_list va;
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync va_start(va, fmt);
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync char buffer[1024];
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync _vsnprintf (buffer, sizeof (buffer), fmt, va);
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync OutputDebugStringA(buffer);
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync
8b98c71a5a01d215eafbc3605cb7a66cc91ea774vboxsync FILE *f = fopen (AUTH_DEBUG_FILE_NAME, "ab");
8b98c71a5a01d215eafbc3605cb7a66cc91ea774vboxsync if (f)
8b98c71a5a01d215eafbc3605cb7a66cc91ea774vboxsync {
8b98c71a5a01d215eafbc3605cb7a66cc91ea774vboxsync fprintf (f, "%s", buffer);
8b98c71a5a01d215eafbc3605cb7a66cc91ea774vboxsync fclose (f);
8b98c71a5a01d215eafbc3605cb7a66cc91ea774vboxsync }
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync va_end (va);
8b98c71a5a01d215eafbc3605cb7a66cc91ea774vboxsync#endif
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync}
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsyncextern "C"
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync#if defined(_MSC_VER)
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync__declspec(dllexport)
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync#endif
8b98c71a5a01d215eafbc3605cb7a66cc91ea774vboxsyncAuthResult AUTHCALL AuthEntry (const char *szCaller,
8b98c71a5a01d215eafbc3605cb7a66cc91ea774vboxsync PAUTHUUID pUuid,
8b98c71a5a01d215eafbc3605cb7a66cc91ea774vboxsync AuthGuestJudgement guestJudgement,
8b98c71a5a01d215eafbc3605cb7a66cc91ea774vboxsync const char *szUser,
8b98c71a5a01d215eafbc3605cb7a66cc91ea774vboxsync const char *szPassword,
8b98c71a5a01d215eafbc3605cb7a66cc91ea774vboxsync const char *szDomain,
8b98c71a5a01d215eafbc3605cb7a66cc91ea774vboxsync int fLogon,
8b98c71a5a01d215eafbc3605cb7a66cc91ea774vboxsync unsigned clientId)
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync{
8b98c71a5a01d215eafbc3605cb7a66cc91ea774vboxsync AuthResult result = AuthResultAccessDenied;
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync LPTSTR lpszUsername = (char *)szUser;
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync LPTSTR lpszDomain = (char *)szDomain;
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync LPTSTR lpszPassword = (char *)szPassword;
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync /* LOGON32_LOGON_INTERACTIVE is intended for users who will be interactively using the computer,
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync * such as a user being logged on by a terminal server, remote shell, or similar process.
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync */
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync DWORD dwLogonType = LOGON32_LOGON_INTERACTIVE;
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync DWORD dwLogonProvider = LOGON32_PROVIDER_DEFAULT;
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync HANDLE hToken;
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync dprintf("u[%s], d[%s], p[%s]\n", lpszUsername, lpszDomain, lpszPassword);
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync BOOL fSuccess = LogonUser(lpszUsername,
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync lpszDomain,
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync lpszPassword,
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync dwLogonType,
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync dwLogonProvider,
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync &hToken);
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync if (fSuccess)
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync {
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync dprintf("LogonUser success. hToken = %p\n", hToken);
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync
8b98c71a5a01d215eafbc3605cb7a66cc91ea774vboxsync result = AuthResultAccessGranted;
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync CloseHandle (hToken);
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync }
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync else
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync {
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync dprintf("LogonUser failed %08X\n", GetLastError ());
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync }
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync return result;
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync}
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync/* Verify the function prototype. */
8b98c71a5a01d215eafbc3605cb7a66cc91ea774vboxsyncstatic PAUTHENTRY3 gpfnAuthEntry = AuthEntry;