├── .gitattributes ├── .gitignore ├── AUTHORS ├── COPYING ├── ChangeLog ├── GinaSSO ├── GinaDlg.cpp ├── GinaDlg.h ├── GinaSSO.Def ├── GinaSSO.cpp ├── GinaSSO.h ├── GinaSSO.rc ├── GinaSSO.sln ├── GinaSSO.vcproj ├── Makefile.am ├── ReadMe.txt ├── afxres.h ├── resource.h ├── stdafx.cpp └── stdafx.h ├── Makefile.am ├── NEWS ├── README ├── README.md ├── README_Fedora.txt ├── autogen.sh ├── automation ├── README.md ├── build-artifacts.packages ├── build-artifacts.packages.el6 ├── build-artifacts.packages.el7 ├── build-artifacts.repos ├── build-artifacts.repos.el6 ├── build-artifacts.repos.el7 ├── build-artifacts.sh ├── check-patch.packages ├── check-patch.packages.el6 ├── check-patch.packages.el7 ├── check-patch.repos ├── check-patch.repos.el6 ├── check-patch.repos.el7 └── check-patch.sh ├── configurations ├── Makefile.am ├── default-logger.conf ├── default-logger.ini ├── default.conf ├── default.ini ├── ovirt-guest-agent.conf └── ovirt-guest-agent.ini ├── configure.ac ├── gdm-plugin ├── Makefile.am ├── gdm-ovirtcred-extension.c ├── gdm-ovirtcred-extension.h ├── gdm-ovirtcred.pam ├── icons │ ├── 16x16 │ │ ├── Makefile.am │ │ └── gdm-ovirtcred.png │ ├── 48x48 │ │ ├── Makefile.am │ │ └── gdm-ovirtcred.png │ └── Makefile.am ├── page.ui └── test-login.py ├── gdm2-plugin ├── Makefile.am ├── gdm-ovirtcred-extension.c ├── gdm-ovirtcred-extension.h ├── gdm2-Makefile.am └── plugin.c ├── hooks ├── 55-flush-caches.consolehelper ├── 55-flush-caches.sudo ├── Makefile.am └── flush-caches ├── kdm-plugin ├── Makefile.am ├── credentials.xml ├── kdm-ovirtcred.pam └── src │ ├── CMakeLists.txt │ ├── OVirtCred.cpp │ ├── OVirtCred.h │ ├── kgreet_ovirtcred.cpp │ └── kgreet_ovirtcred.h ├── m4 ├── .keep └── fhs.m4 ├── ovirt-guest-agent-windows.spec ├── ovirt-guest-agent.rhel6.spec ├── ovirt-guest-agent.spec ├── ovirt-guest-agent ├── CredServer.py ├── GuestAgentLinux2.py ├── GuestAgentWin32.py ├── LockActiveSession.py ├── LogoutActiveUser.py ├── Makefile.am ├── Makefile.el5 ├── OVirtAgentLogic.py ├── OVirtGuestService.py ├── README-windows.txt ├── VirtIoChannel.py ├── WinFile.py ├── bytesio.py ├── consoleapps │ ├── Makefile.am │ ├── ovirt-container-list │ ├── ovirt-flush-caches │ ├── ovirt-hibernate │ ├── ovirt-locksession │ ├── ovirt-logout │ └── ovirt-shutdown ├── hibernate ├── hooks.py ├── org.ovirt.vdsm.Credentials.conf ├── ovirt-guest-agent.el5.rules ├── ovirt-guest-agent.in ├── ovirt-guest-agent.py ├── ovirt-guest-agent.rules ├── ovirt-guest-agent.service ├── ovirt-guest-agent.sles ├── pam │ ├── Makefile.am │ ├── ovirt-container-list │ ├── ovirt-flush-caches │ ├── ovirt-hibernate │ ├── ovirt-locksession │ ├── ovirt-logout │ └── ovirt-shutdown └── timezone.py ├── pam-ovirt-cred ├── Makefile.am ├── cred_channel.c ├── pam_ovirt_cred.c └── test.c ├── scripts ├── Makefile.am ├── container-list ├── diskmapper │ ├── Makefile.am │ ├── diskmapper.el5 │ └── diskmapper.libudev ├── ovirt-osinfo ├── sudoers.ovirt-guest-agent └── wrappers │ ├── Makefile.am │ ├── ovirt-container-list-wrapper.sh │ ├── ovirt-flush-caches-wrapper.sh │ ├── ovirt-hibernate-wrapper.sh │ ├── ovirt-locksession-wrapper.sh │ ├── ovirt-logout-wrapper.sh │ ├── ovirt-shutdown-wrapper.sh │ └── ovirt-sudo-wrapper.sh ├── tests ├── Makefile.am ├── encoding_test.py ├── guest_agent_test.py ├── message_validator.py ├── test_port.py ├── testrunner.py └── unittest.bat └── windows-credprov ├── CredentialsChannel.cpp ├── CredentialsChannel.h ├── Helpers.cpp ├── Helpers.h ├── Makefile.am ├── OVirtCredProv.cpp ├── OVirtCredProv.def ├── OVirtCredProv.h ├── OVirtCredProv.rc ├── OVirtCredProv.sln ├── OVirtCredProv.vcproj ├── OVirtCredentials.cpp ├── OVirtCredentials.h ├── OVirtProvider.cpp ├── OVirtProvider.h ├── Pch.cpp ├── Pch.h ├── README ├── Register.reg ├── Unregister.reg ├── afxres.h ├── credentialprovider.h ├── intsafe.h └── resource.h /.gitattributes: -------------------------------------------------------------------------------- 1 | *.c text eol=lf 2 | *.cpp text eol=lf 3 | *.py text eol=lf 4 | *.h text eol=lf 5 | *.rc text eol=lf 6 | *.txt text eol=lf 7 | *.bat text eol=crlf 8 | *.vc*proj* text eol=crlf 9 | *.ini text eol=crlf 10 | *.sln text eol=crlf 11 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.la 2 | *.lo 3 | *.ncb 4 | *.o 5 | *.pyc 6 | *.suo 7 | *.vcproj.*.user 8 | *.sw? 9 | .deps 10 | .idea 11 | .libs 12 | INSTALL 13 | Makefile 14 | Makefile.in 15 | aclocal.m4 16 | ar-lib 17 | autom4te.cache/ 18 | compile 19 | config.cache 20 | config.guess 21 | config.h 22 | config.h.in 23 | config.h.in~ 24 | config.log 25 | config.status 26 | config.sub 27 | configure 28 | depcomp 29 | install-sh 30 | libtool 31 | ltmain.sh 32 | m4/ 33 | missing 34 | py-compile 35 | stamp-h1 36 | test-driver 37 | ovirt-guest-agent/ovirt-guest-agent 38 | ovirt-guest-agent/ovirt-guest-agent.upstart.conf 39 | ovirt-guest-agent-*.tar.bz2 40 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Gal Hammer 2 | Vinzenz Feenstra 3 | -------------------------------------------------------------------------------- /GinaSSO/GinaDlg.h: -------------------------------------------------------------------------------- 1 | // Function prototypes. 2 | void HookWlxDialogBoxParam(PVOID pWinlogonFunctions, DWORD dwWlxVersion, HANDLE a_hWlx); 3 | void KillListenerThread(); -------------------------------------------------------------------------------- /GinaSSO/GinaSSO.Def: -------------------------------------------------------------------------------- 1 | LIBRARY GINASSO 2 | EXPORTS 3 | WlxActivateUserShell 4 | WlxDisconnectNotify 5 | WlxDisplayLockedNotice 6 | WlxDisplaySASNotice 7 | WlxDisplayStatusMessage 8 | WlxGetConsoleSwitchCredentials 9 | WlxGetStatusMessage 10 | WlxInitialize 11 | WlxIsLockOk 12 | WlxIsLogoffOk 13 | WlxLoggedOnSAS 14 | WlxLoggedOutSAS 15 | WlxLogoff 16 | WlxNegotiate 17 | WlxNetworkProviderLoad 18 | WlxReconnectNotify 19 | WlxRemoveStatusMessage 20 | WlxShutdown 21 | WlxWkstaLockedSAS 22 | WlxScreenSaverNotify 23 | WlxStartApplication 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /GinaSSO/GinaSSO.h: -------------------------------------------------------------------------------- 1 | // The following ifdef block is the standard way of creating macros which make exporting 2 | // from a DLL simpler. All files within this DLL are compiled with the GINASSO_EXPORTS 3 | // symbol defined on the command line. this symbol should not be defined on any project 4 | // that uses this DLL. This way any other project whose source files include this file see 5 | // GINASSO_API functions as being imported from a DLL, whereas this DLL sees symbols 6 | // defined with this macro as being exported. 7 | #ifdef GINASSO_EXPORTS 8 | #define GINASSO_API __declspec(dllexport) 9 | #else 10 | #define GINASSO_API __declspec(dllimport) 11 | #endif 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif // __cplusplus 16 | 17 | /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 18 | 19 | THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, 20 | EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. 22 | 23 | Copyright (C) 1996 - 2000. Microsoft Corporation. All rights reserved. 24 | 25 | Module: Ginahook.h 26 | 27 | Abstract: See ReadMe.txt for more detail information about this sample. 28 | 29 | Revision: August 6, 1999. 30 | 31 | ------------------------------------------------------------------------------*/ 32 | 33 | // 34 | // Function prototypes for the GINA interface. 35 | // 36 | 37 | typedef BOOL (WINAPI * PFWLXNEGOTIATE) (DWORD, DWORD *); 38 | typedef BOOL (WINAPI * PFWLXINITIALIZE) (LPWSTR, HANDLE, PVOID, PVOID, PVOID *); 39 | typedef VOID (WINAPI * PFWLXDISPLAYSASNOTICE) (PVOID); 40 | typedef int (WINAPI * PFWLXLOGGEDOUTSAS) (PVOID, DWORD, PLUID, PSID, PDWORD, 41 | PHANDLE, PWLX_MPR_NOTIFY_INFO, 42 | PVOID *); 43 | typedef BOOL (WINAPI * PFWLXACTIVATEUSERSHELL) (PVOID, PWSTR, PWSTR, PVOID); 44 | typedef int (WINAPI * PFWLXLOGGEDONSAS) (PVOID, DWORD, PVOID); 45 | typedef VOID (WINAPI * PFWLXDISPLAYLOCKEDNOTICE) (PVOID); 46 | typedef int (WINAPI * PFWLXWKSTALOCKEDSAS) (PVOID, DWORD); 47 | typedef BOOL (WINAPI * PFWLXISLOCKOK) (PVOID); 48 | typedef BOOL (WINAPI * PFWLXISLOGOFFOK) (PVOID); 49 | typedef VOID (WINAPI * PFWLXLOGOFF) (PVOID); 50 | typedef VOID (WINAPI * PFWLXSHUTDOWN) (PVOID, DWORD); 51 | 52 | // 53 | // New for version 1.1 54 | // 55 | 56 | typedef BOOL (WINAPI * PFWLXSCREENSAVERNOTIFY) (PVOID, BOOL *); 57 | typedef BOOL (WINAPI * PFWLXSTARTAPPLICATION) (PVOID, PWSTR, PVOID, PWSTR); 58 | 59 | // 60 | // New for version 1.3 61 | // 62 | 63 | typedef BOOL (WINAPI * PFWLXNETWORKPROVIDERLOAD) (PVOID, PWLX_MPR_NOTIFY_INFO); 64 | typedef BOOL (WINAPI * PFWLXDISPLAYSTATUSMESSAGE) (PVOID, HDESK, DWORD, PWSTR, PWSTR); 65 | typedef BOOL (WINAPI * PFWLXGETSTATUSMESSAGE) (PVOID, DWORD *, PWSTR, DWORD); 66 | typedef BOOL (WINAPI * PFWLXREMOVESTATUSMESSAGE) (PVOID); 67 | 68 | // New for version 1.4 added by Itai Shaham, 21/08/07 to support TC connections 69 | // get prototypes from ...\Microsoft Platform SDK\Include\winwlx.h 70 | typedef BOOL (WINAPI * PFWLXGETCONSOLESWITCHCREDENTIALS) (PVOID, PVOID); 71 | typedef VOID (WINAPI * PFWLXRECONNECTNOTIFY) (PVOID); 72 | typedef VOID (WINAPI * PFWLXDISCONNECTNOTIFY) (PVOID); 73 | 74 | #ifdef __cplusplus 75 | } 76 | #endif // __cplusplus 77 | -------------------------------------------------------------------------------- /GinaSSO/GinaSSO.rc: -------------------------------------------------------------------------------- 1 | // Microsoft Visual C++ generated resource script. 2 | // 3 | #include "resource.h" 4 | 5 | #define APSTUDIO_READONLY_SYMBOLS 6 | ///////////////////////////////////////////////////////////////////////////// 7 | // 8 | // Generated from the TEXTINCLUDE 2 resource. 9 | // 10 | #include "afxres.h" 11 | 12 | ///////////////////////////////////////////////////////////////////////////// 13 | #undef APSTUDIO_READONLY_SYMBOLS 14 | 15 | ///////////////////////////////////////////////////////////////////////////// 16 | // English (U.S.) resources 17 | 18 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) 19 | #ifdef _WIN32 20 | LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US 21 | #pragma code_page(1252) 22 | #endif //_WIN32 23 | 24 | #ifdef APSTUDIO_INVOKED 25 | ///////////////////////////////////////////////////////////////////////////// 26 | // 27 | // TEXTINCLUDE 28 | // 29 | 30 | 1 TEXTINCLUDE 31 | BEGIN 32 | "resource.h\0" 33 | END 34 | 35 | 2 TEXTINCLUDE 36 | BEGIN 37 | "#include ""afxres.h""\r\n" 38 | "\0" 39 | END 40 | 41 | 3 TEXTINCLUDE 42 | BEGIN 43 | "\r\n" 44 | "\0" 45 | END 46 | 47 | #endif // APSTUDIO_INVOKED 48 | 49 | 50 | ///////////////////////////////////////////////////////////////////////////// 51 | // 52 | // Version 53 | // 54 | 55 | VS_VERSION_INFO VERSIONINFO 56 | FILEVERSION 1,0,0,1 57 | PRODUCTVERSION 1,0,0,1 58 | FILEFLAGSMASK 0x17L 59 | #ifdef _DEBUG 60 | FILEFLAGS 0x1L 61 | #else 62 | FILEFLAGS 0x0L 63 | #endif 64 | FILEOS 0x4L 65 | FILETYPE 0x2L 66 | FILESUBTYPE 0x0L 67 | BEGIN 68 | BLOCK "StringFileInfo" 69 | BEGIN 70 | BLOCK "040904b0" 71 | BEGIN 72 | VALUE "CompanyName", "Red Hat Inc." 73 | VALUE "FileDescription", "SSO replacement for the GINA module" 74 | VALUE "FileVersion", "1, 0, 0, 1" 75 | VALUE "InternalName", "GinaSSO" 76 | VALUE "LegalCopyright", "Copyright (C) 2009 Red Hat Inc. All rights reserved." 77 | VALUE "OriginalFilename", "GinaSSO.dll" 78 | VALUE "ProductName", "Red Hat SSO" 79 | VALUE "ProductVersion", "1, 0, 0, 1" 80 | END 81 | END 82 | BLOCK "VarFileInfo" 83 | BEGIN 84 | VALUE "Translation", 0x409, 1200 85 | END 86 | END 87 | 88 | #endif // English (U.S.) resources 89 | ///////////////////////////////////////////////////////////////////////////// 90 | 91 | 92 | 93 | #ifndef APSTUDIO_INVOKED 94 | ///////////////////////////////////////////////////////////////////////////// 95 | // 96 | // Generated from the TEXTINCLUDE 3 resource. 97 | // 98 | 99 | 100 | ///////////////////////////////////////////////////////////////////////////// 101 | #endif // not APSTUDIO_INVOKED 102 | 103 | -------------------------------------------------------------------------------- /GinaSSO/GinaSSO.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 10.00 3 | # Visual Studio 2008 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "GinaSSO", "GinaSSO.vcproj", "{87EADA77-9319-446D-9BC3-419B9020B41D}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Win32 = Debug|Win32 9 | Release|Win32 = Release|Win32 10 | EndGlobalSection 11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 12 | {87EADA77-9319-446D-9BC3-419B9020B41D}.Debug|Win32.ActiveCfg = Debug|Win32 13 | {87EADA77-9319-446D-9BC3-419B9020B41D}.Debug|Win32.Build.0 = Debug|Win32 14 | {87EADA77-9319-446D-9BC3-419B9020B41D}.Release|Win32.ActiveCfg = Release|Win32 15 | {87EADA77-9319-446D-9BC3-419B9020B41D}.Release|Win32.Build.0 = Release|Win32 16 | EndGlobalSection 17 | GlobalSection(SolutionProperties) = preSolution 18 | HideSolutionNode = FALSE 19 | EndGlobalSection 20 | EndGlobal 21 | -------------------------------------------------------------------------------- /GinaSSO/GinaSSO.vcproj: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 15 | 16 | 17 | 18 | 19 | 26 | 30 | 33 | 36 | 39 | 42 | 54 | 57 | 60 | 63 | 74 | 77 | 80 | 83 | 86 | 89 | 92 | 96 | 97 | 105 | 108 | 111 | 114 | 117 | 120 | 129 | 132 | 135 | 138 | 151 | 154 | 157 | 160 | 163 | 166 | 169 | 172 | 173 | 174 | 175 | 176 | 177 | 182 | 185 | 186 | 189 | 190 | 193 | 196 | 200 | 201 | 204 | 208 | 209 | 210 | 211 | 216 | 219 | 220 | 223 | 224 | 227 | 228 | 231 | 232 | 233 | 238 | 241 | 242 | 245 | 246 | 247 | 250 | 251 | 252 | 253 | 254 | 255 | -------------------------------------------------------------------------------- /GinaSSO/Makefile.am: -------------------------------------------------------------------------------- 1 | # Copyright 2013-2015 Red Hat, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # Refer to the README and COPYING files for full details of the license. 16 | 17 | EXTRA_DIST= \ 18 | afxres.h \ 19 | GinaDlg.cpp \ 20 | GinaDlg.h \ 21 | GinaSSO.cpp \ 22 | GinaSSO.Def \ 23 | GinaSSO.h \ 24 | GinaSSO.rc \ 25 | GinaSSO.sln \ 26 | GinaSSO.vcproj \ 27 | ReadMe.txt \ 28 | resource.h \ 29 | stdafx.cpp \ 30 | stdafx.h \ 31 | $(NULL) 32 | 33 | MAINTAINERCLEANFILES = \ 34 | *~ \ 35 | Makefile.in \ 36 | $(NULL) 37 | -------------------------------------------------------------------------------- /GinaSSO/ReadMe.txt: -------------------------------------------------------------------------------- 1 | ======================================================================== 2 | DYNAMIC LINK LIBRARY : GinaSSO Project Overview 3 | ======================================================================== 4 | 5 | How to install GinaSSO 6 | ======================= 7 | 8 | 1) Copy GinaSSO.dll to %SystemRoot%\System32 directory. 9 | 2) Run RegEdit 10 | 3) Create the following value under 11 | HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon. 12 | Value Name: GinaDLL 13 | Value Type: REG_SZ 14 | Value Data: "GinaSSO.dll" 15 | 4) Exit RegEdit. 16 | 5) Reboot. 17 | -------------------------------------------------------------------------------- /GinaSSO/afxres.h: -------------------------------------------------------------------------------- 1 | #ifndef OVIRT_AGENT_GINASSO_AFXRES_H_INCLUDED 2 | #define OVIRT_AGENT_GINASSO_AFXRES_H_INCLUDED 3 | 4 | #include 5 | 6 | #ifndef IDC_STATIC 7 | # define IDC_STATIC (-1) 8 | #endif 9 | 10 | #endif //OVIRT_AGENT_GINASSO_AFXRES_H_INCLUDED 11 | -------------------------------------------------------------------------------- /GinaSSO/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by GinaSSO.rc 4 | 5 | // Next default values for new objects 6 | // 7 | #ifdef APSTUDIO_INVOKED 8 | #ifndef APSTUDIO_READONLY_SYMBOLS 9 | #define _APS_NEXT_RESOURCE_VALUE 101 10 | #define _APS_NEXT_COMMAND_VALUE 40001 11 | #define _APS_NEXT_CONTROL_VALUE 1001 12 | #define _APS_NEXT_SYMED_VALUE 101 13 | #endif 14 | #endif 15 | -------------------------------------------------------------------------------- /GinaSSO/stdafx.cpp: -------------------------------------------------------------------------------- 1 | // stdafx.cpp : source file that includes just the standard includes 2 | // GinaSSO.pch will be the pre-compiled header 3 | // stdafx.obj will contain the pre-compiled type information 4 | 5 | #include "stdafx.h" 6 | -------------------------------------------------------------------------------- /GinaSSO/stdafx.h: -------------------------------------------------------------------------------- 1 | // stdafx.h : include file for standard system include files, 2 | // or project specific include files that are used frequently, but 3 | // are changed infrequently 4 | // 5 | 6 | #pragma once 7 | 8 | // Modify the following defines if you have to target a platform prior to the ones specified below. 9 | // Refer to MSDN for the latest info on corresponding values for different platforms. 10 | #ifndef WINVER // Allow use of features specific to Windows XP or later. 11 | #define WINVER 0x0501 // Change this to the appropriate value to target other versions of Windows. 12 | #endif 13 | 14 | #ifndef _WIN32_WINNT // Allow use of features specific to Windows XP or later. 15 | #define _WIN32_WINNT 0x0501 // Change this to the appropriate value to target other versions of Windows. 16 | #endif 17 | 18 | #ifndef _WIN32_WINDOWS // Allow use of features specific to Windows 98 or later. 19 | #define _WIN32_WINDOWS 0x0410 // Change this to the appropriate value to target Windows Me or later. 20 | #endif 21 | 22 | #ifndef _WIN32_IE // Allow use of features specific to IE 6.0 or later. 23 | #define _WIN32_IE 0x0600 // Change this to the appropriate value to target other versions of IE. 24 | #endif 25 | 26 | #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers 27 | // Windows Header Files: 28 | #include 29 | #include 30 | #include -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | ACLOCAL_AMFLAGS=-I m4 2 | 3 | SUBDIRS = \ 4 | configurations \ 5 | ovirt-guest-agent \ 6 | GinaSSO \ 7 | tests \ 8 | windows-credprov \ 9 | scripts \ 10 | hooks \ 11 | $(NULL) 12 | 13 | if BUILD_SSO_MODULES 14 | SUBDIRS += \ 15 | pam-ovirt-cred 16 | endif 17 | 18 | if BUILD_GDM_MODULE 19 | SUBDIRS += \ 20 | gdm-plugin \ 21 | gdm2-plugin 22 | endif 23 | 24 | if BUILD_KDM_MODULE 25 | SUBDIRS += \ 26 | kdm-plugin 27 | endif 28 | 29 | DIST_SUBDIRS=$(SUBDIRS) 30 | 31 | CLEANFILES = \ 32 | *~ 33 | 34 | MAINTAINERCLEANFILES = \ 35 | config.h.in \ 36 | Makefile.in 37 | 38 | EXTRA_DIST= \ 39 | AUTHORS \ 40 | README_Fedora.txt \ 41 | ovirt-guest-agent.spec \ 42 | ovirt-guest-agent.rhel6.spec\ 43 | m4/fhs.m4 \ 44 | $(NULL) 45 | 46 | # When fixing a file to conform with pep8 add it to the WL here so it will be 47 | # checkd from now on 48 | PEP8_WHITELIST = \ 49 | ovirt-guest-agent/CredServer.py \ 50 | ovirt-guest-agent/GuestAgentLinux2.py \ 51 | ovirt-guest-agent/GuestAgentWin32.py \ 52 | ovirt-guest-agent/LockActiveSession.py \ 53 | ovirt-guest-agent/OVirtAgentLogic.py \ 54 | ovirt-guest-agent/OVirtGuestService.py \ 55 | ovirt-guest-agent/VirtIoChannel.py \ 56 | ovirt-guest-agent/WinFile.py \ 57 | ovirt-guest-agent/ovirt-guest-agent.py \ 58 | ovirt-guest-agent/hooks.py \ 59 | tests/*.py 60 | 61 | PEP8_BLACKLIST = ovirt-guest-agent/setup.py 62 | 63 | # Only execute the PEP8 checks if it was found 64 | # If pep8 couldn't be located don't execute this 65 | # Switch to pycodestyle revealed lots `bare except` issues. 66 | # Excluding those from test for now. 67 | # Excluding also warnings: 68 | # - W504 line break after binary operator 69 | if HAVE_PEP8 70 | check-local: 71 | $(PEP8) --exclude="$(PEP8_BLACKLIST)" --filename '*.py,*.py.in' \ 72 | --ignore=E722,W504 $(PEP8_WHITELIST) 73 | @if test -f .gitignore; then \ 74 | for i in `git ls-files \*.in`; do \ 75 | if ! grep -q -x $${i%%.in} .gitignore; then \ 76 | echo "Missing $${i%%.in} in .gitignore"; exit 1; \ 77 | fi; \ 78 | done; \ 79 | fi; 80 | endif 81 | 82 | install-exec-hook: 83 | $(INSTALL) -d $(DESTDIR)/$(localstatedir)/log/ovirt-guest-agent 84 | -------------------------------------------------------------------------------- /NEWS: -------------------------------------------------------------------------------- 1 | Reserved for future news. 2 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | Copyright 2009-2012 Red Hat, Inc. and/or its affiliates. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | 15 | In addition, as a special exception, Red Hat, Inc. and its affiliates 16 | give you permission to distribute this program, or a work based on it, 17 | linked or combined with the OpenSSL project's OpenSSL library (or a 18 | modified version of that library) to the extent that the library, or 19 | modified version, is covered by the terms of the OpenSSL or SSLeay 20 | licenses. Corresponding source code for the object code form of such 21 | a combination shall include source code for the parts of OpenSSL 22 | contained in the combination. 23 | 24 | If you modify this program, you may extend this exception to your 25 | version, but you are not obligated to do so. If you do not wish to do 26 | so, delete this exception statement from your version. 27 | 28 | The named copyright holder of the file vdsm/tunctl.c, Jeff Dike, 29 | indicated his assent to permitting combinations of this code with 30 | OpenSSL code covered by the OpenSSL and SSLeay licenses, in an e-mail 31 | sent to Red Hat counsel Richard Fontana dated 29 Jan 2009. 32 | 33 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | > IMPORTANT: This project has been dropped from oVirt 2 | > 3 | > Keeping the repo only for reference. -------------------------------------------------------------------------------- /README_Fedora.txt: -------------------------------------------------------------------------------- 1 | Ovirt Guest Agent for Fedora - setting up dev env & building the rpms 2 | ===================================================================== 3 | NOTE: 4 | - In order to build on Fedora you may need to use rpmdevtools 5 | - there are still some sub rpms that do not compile properly in Fedora 15 6 | (gdm & kdm plugins) so there are still lot's of commented lines in the 7 | configure.ac & spec file. These issues will be resolved soon. 8 | - was tested on Fedora 15. 9 | 10 | 11 | 12 | Getting started 13 | --------------- 14 | git clone 15 | cd ovirt-guest-agent 16 | ./autogen.sh 17 | ./configure 18 | 19 | Building sources 20 | ---------------- 21 | make 22 | 23 | Installing locally 24 | ------------------ 25 | sudo make install 26 | 27 | 28 | Building rpms 29 | ------------- 30 | make dist 31 | 32 | rpmbuild -bb --define="_sourcedir " ovirt-guest-agent.spec 33 | 34 | you may skip --define="_sourcedir if you used rpmdevtools to setup your env 35 | -------------------------------------------------------------------------------- /autogen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | autoreconf -ivf 4 | -------------------------------------------------------------------------------- /automation/README.md: -------------------------------------------------------------------------------- 1 | See http://www.ovirt.org/index.php?title=CI/Build_and_test_standards 2 | -------------------------------------------------------------------------------- /automation/build-artifacts.packages: -------------------------------------------------------------------------------- 1 | autoconf 2 | automake 3 | dnf-utils 4 | gettext-devel 5 | git 6 | libtool 7 | python2-devel 8 | -------------------------------------------------------------------------------- /automation/build-artifacts.packages.el6: -------------------------------------------------------------------------------- 1 | autoconf 2 | automake 3 | gettext-devel 4 | git 5 | libtool 6 | python2-devel 7 | yum-utils 8 | -------------------------------------------------------------------------------- /automation/build-artifacts.packages.el7: -------------------------------------------------------------------------------- 1 | autoconf 2 | automake 3 | gettext-devel 4 | git 5 | libtool 6 | python2-devel 7 | yum-utils 8 | -------------------------------------------------------------------------------- /automation/build-artifacts.repos: -------------------------------------------------------------------------------- 1 | ovirt-master-snapshot,http://resources.ovirt.org/pub/ovirt-master-snapshot/rpm/$distro 2 | ovirt-master-snapshot-static,http://resources.ovirt.org/pub/ovirt-master-snapshot-static/rpm/$distro 3 | -------------------------------------------------------------------------------- /automation/build-artifacts.repos.el6: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oVirt/ovirt-guest-agent/639a30df2d607011c367a451cb4179e8370cd6a0/automation/build-artifacts.repos.el6 -------------------------------------------------------------------------------- /automation/build-artifacts.repos.el7: -------------------------------------------------------------------------------- 1 | ovirt-master-snapshot,http://resources.ovirt.org/pub/ovirt-master-snapshot/rpm/$distro 2 | ovirt-master-snapshot-static,http://resources.ovirt.org/pub/ovirt-master-snapshot-static/rpm/$distro 3 | sbonazzo-wine-epel-x86_64,https://copr-be.cloud.fedoraproject.org/results/sbonazzo/wine-epel/epel-7-x86_64/ 4 | sbonazzo-wine-epel-i386,https://copr-be.cloud.fedoraproject.org/results/sbonazzo/wine-epel/custom-1-i386/ 5 | -------------------------------------------------------------------------------- /automation/build-artifacts.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -xe 2 | 3 | # cleanup leftovers from previous builds 4 | rm -rf exported-artifacts 5 | rm -rf tmp.repos 6 | 7 | mkdir -p exported-artifacts 8 | mkdir -p tmp.repos 9 | 10 | if git describe --exact-match --tags --match "[0-9]*" > /dev/null 2>&1 ; then 11 | SUFFIX="" 12 | else 13 | SUFFIX=".$(date -u +%Y%m%d%H%M%S).git$(git rev-parse --short HEAD)" 14 | fi 15 | 16 | ./autogen.sh 17 | ./configure \ 18 | --with-dist 19 | make dist 20 | 21 | if ! rpm --eval "%dist" | grep -qFi 'el6'; then 22 | yum-builddep -y ovirt-guest-agent-windows.spec 23 | rpmbuild \ 24 | -D "_topdir $PWD/tmp.repos" \ 25 | -D "_sourcedir $PWD" \ 26 | ${SUFFIX:+-D "release_suffix ${SUFFIX}"} \ 27 | -ba ovirt-guest-agent-windows.spec 28 | fi 29 | 30 | if rpm --eval "%dist" | grep -qFi 'el6'; then 31 | yum-builddep -y ovirt-guest-agent.rhel6.spec 32 | rpmbuild \ 33 | -D "_topdir $PWD/tmp.repos" \ 34 | -D "_sourcedir $PWD" \ 35 | ${SUFFIX:+-D "release_suffix ${SUFFIX}"} \ 36 | -ba ovirt-guest-agent.rhel6.spec 37 | fi 38 | 39 | if rpm --eval "%dist" | grep -qFi 'el7'; then 40 | yum-builddep -y ovirt-guest-agent.spec 41 | rpmbuild \ 42 | -D "_topdir $PWD/tmp.repos" \ 43 | -D "_sourcedir $PWD" \ 44 | ${SUFFIX:+-D "release_suffix ${SUFFIX}"} \ 45 | -ba ovirt-guest-agent.spec 46 | fi 47 | 48 | mv *.tar.bz2 exported-artifacts 49 | find \ 50 | "$PWD/tmp.repos" \ 51 | -iname \*.rpm \ 52 | -exec mv {} exported-artifacts/ \; 53 | -------------------------------------------------------------------------------- /automation/check-patch.packages: -------------------------------------------------------------------------------- 1 | autoconf 2 | automake 3 | dnf-utils 4 | gettext-devel 5 | git 6 | libtool 7 | make 8 | python2-devel 9 | python-nose 10 | python-pycodestyle 11 | -------------------------------------------------------------------------------- /automation/check-patch.packages.el6: -------------------------------------------------------------------------------- 1 | autoconf 2 | automake 3 | gettext-devel 4 | git 5 | libtool 6 | make 7 | python2-devel 8 | python-nose 9 | python-pep8 10 | yum-utils 11 | -------------------------------------------------------------------------------- /automation/check-patch.packages.el7: -------------------------------------------------------------------------------- 1 | autoconf 2 | automake 3 | gettext-devel 4 | git 5 | libtool 6 | make 7 | python2-devel 8 | python-nose 9 | python-pep8 10 | yum-utils 11 | -------------------------------------------------------------------------------- /automation/check-patch.repos: -------------------------------------------------------------------------------- 1 | ovirt-master-snapshot,http://resources.ovirt.org/pub/ovirt-master-snapshot/rpm/$distro 2 | ovirt-master-snapshot-static,http://resources.ovirt.org/pub/ovirt-master-snapshot-static/rpm/$distro 3 | -------------------------------------------------------------------------------- /automation/check-patch.repos.el6: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oVirt/ovirt-guest-agent/639a30df2d607011c367a451cb4179e8370cd6a0/automation/check-patch.repos.el6 -------------------------------------------------------------------------------- /automation/check-patch.repos.el7: -------------------------------------------------------------------------------- 1 | ovirt-master-snapshot,http://resources.ovirt.org/pub/ovirt-master-snapshot/rpm/$distro 2 | ovirt-master-snapshot-static,http://resources.ovirt.org/pub/ovirt-master-snapshot-static/rpm/$distro 3 | sbonazzo-wine-epel-x86_64,https://copr-be.cloud.fedoraproject.org/results/sbonazzo/wine-epel/epel-7-x86_64/ 4 | sbonazzo-wine-epel-i386,https://copr-be.cloud.fedoraproject.org/results/sbonazzo/wine-epel/custom-1-i386/ 5 | -------------------------------------------------------------------------------- /automation/check-patch.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -xe 2 | 3 | ./autogen.sh 4 | ./configure \ 5 | --prefix=/usr \ 6 | --exec_prefix=/usr \ 7 | --sysconfdir=/etc \ 8 | --localstatedir=/var \ 9 | --without-sso 10 | make check 11 | 12 | ./automation/build-artifacts.sh 13 | -------------------------------------------------------------------------------- /configurations/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | EXTRA_DIST= \ 3 | ovirt-guest-agent.ini \ 4 | default.ini \ 5 | default-logger.ini \ 6 | $(NULL) 7 | 8 | agentconfdir=$(sysconfdir) 9 | dist_agentconf_DATA=ovirt-guest-agent.conf 10 | 11 | agentdefaultconfdir=$(datadir)/ovirt-guest-agent 12 | dist_agentdefaultconf_DATA=\ 13 | default.conf \ 14 | default-logger.conf \ 15 | $(NULL) 16 | 17 | -------------------------------------------------------------------------------- /configurations/default-logger.conf: -------------------------------------------------------------------------------- 1 | [loggers] 2 | keys=root 3 | 4 | [handlers] 5 | keys=console,syslog,logfile 6 | 7 | [formatters] 8 | keys=long,simple,none,sysform 9 | 10 | [logger_root] 11 | level=INFO 12 | handlers=logfile 13 | propagate=0 14 | 15 | [handler_syslog] 16 | class=handlers.SysLogHandler 17 | formatter=sysform 18 | args=(('localhost', handlers.SYSLOG_UDP_PORT), handlers.SysLogHandler.LOG_USER) 19 | 20 | [handler_logfile] 21 | class=handlers.RotatingFileHandler 22 | args=('/var/log/ovirt-guest-agent/ovirt-guest-agent.log', 'a+', 100*1024, 5) 23 | formatter=long 24 | 25 | [handler_console] 26 | class: StreamHandler 27 | args: [] 28 | formatter: none 29 | 30 | [formatter_simple] 31 | format: %(name)s:%(levelname)s: %(message)s 32 | 33 | [formatter_none] 34 | format: %(message)s 35 | 36 | [formatter_long] 37 | format: %(threadName)s::%(levelname)s::%(asctime)s::%(module)s::%(lineno)d::%(name)s::%(message)s 38 | 39 | [formatter_sysform] 40 | format= %(asctime)s %(levelname)s %(message)s 41 | datefmt= 42 | -------------------------------------------------------------------------------- /configurations/default-logger.ini: -------------------------------------------------------------------------------- 1 | [loggers] 2 | keys=root 3 | 4 | [handlers] 5 | keys=console,logfile 6 | 7 | [formatters] 8 | keys=long,simple,none,sysform 9 | 10 | [logger_root] 11 | level=INFO 12 | handlers=logfile 13 | propagate=0 14 | 15 | [handler_logfile] 16 | class=handlers.RotatingFileHandler 17 | args=('ovirt-guest-agent.log', 'a+', 100*1024, 5) 18 | formatter=long 19 | 20 | [handler_console] 21 | class: StreamHandler 22 | args: [] 23 | formatter: none 24 | 25 | [formatter_simple] 26 | format: %(name)s:%(levelname)s: %(message)s 27 | 28 | [formatter_none] 29 | format: %(message)s 30 | 31 | [formatter_long] 32 | format: %(threadName)s::%(levelname)s::%(asctime)s::%(module)s::%(lineno)d::%(name)s::%(message)s 33 | 34 | [formatter_sysform] 35 | format= %(asctime)s %(levelname)s %(message)s 36 | datefmt= 37 | -------------------------------------------------------------------------------- /configurations/default.conf: -------------------------------------------------------------------------------- 1 | # 2 | # default.conf 3 | # 4 | 5 | [general] 6 | 7 | heart_beat_rate = 5 8 | report_user_rate = 10 9 | report_num_cpu_rate = 60 10 | report_application_rate = 120 11 | report_disk_usage = 300 12 | 13 | # Generic: ovirt-guest-agent 14 | # RHEL/Fedora Packages: kernel ovirt-guest-agent-common xorg-x11-drv-qxl 15 | # Debian Packages: linux-image xserver-xorg-video-qxl 16 | # openSUSE Packages: xf86-video-qxl kernel-desktop kernel-default kernel-trace kernel-vanilla kernel-debug kernel-ec2 kernel-xen kernel-ppc64 17 | applications_list = kernel ovirt-guest-agent ovirt-guest-agent-common xorg-x11-drv-qxl linux-image xserver-xorg-video-qxl xf86-video-qxl kernel-desktop kernel-default kernel-trace kernel-vanilla kernel-debug kernel-ec2 kernel-xen kernel-ppc64 cloud-init 18 | ignored_fs = autofs binfmt_misc cgroup cgroup2 configfs debugfs devpts devtmpfs fusectl fuse.gvfsd-fuse fuse.gvfs-fuse-daemon hugetlbfs mqueue nfsd proc pstore rootfs rpc_pipefs securityfs selinuxfs sysfs tmpfs tracefs udev usbfs 19 | ignore_zero_size_fs = true 20 | ignored_nics = docker0 21 | 22 | [virtio] 23 | device_prefix = /dev/virtio-ports/ 24 | -------------------------------------------------------------------------------- /configurations/default.ini: -------------------------------------------------------------------------------- 1 | # 2 | # default.ini - ovirt-guest-agent/Windows default configuration file 3 | # 4 | 5 | [general] 6 | heart_beat_rate = 5 7 | report_user_rate = 10 8 | report_num_cpu_rate = 60 9 | report_application_rate = 120 10 | report_disk_usage = 300 11 | apply_timer_configuration = true 12 | 13 | [virtio] 14 | device_prefix = \\.\Global\ 15 | -------------------------------------------------------------------------------- /configurations/ovirt-guest-agent.conf: -------------------------------------------------------------------------------- 1 | # 2 | # ovirt-guest-agent.conf 3 | # 4 | 5 | [general] 6 | 7 | # heart_beat_rate = 5 8 | # report_user_rate = 10 9 | # report_num_cpu_rate = 60 10 | # report_application_rate = 120 11 | # report_disk_usage = 300 12 | 13 | ## Generic: ovirt-guest-agent 14 | ## RHEL/Fedora Packages: kernel ovirt-guest-agent-common xorg-x11-drv-qxl 15 | ## Debian Packages: linux-image xserver-xorg-video-qxl 16 | ## openSUSE Packages: xf86-video-qxl kernel-desktop kernel-default kernel-trace kernel-vanilla kernel-debug kernel-ec2 kernel-xen kernel-ppc64 17 | # applications_list = kernel ovirt-guest-agent ovirt-guest-agent-common xorg-x11-drv-qxl linux-image xserver-xorg-video-qxl xf86-video-qxl kernel-desktop kernel-default kernel-trace kernel-vanilla kernel-debug kernel-ec2 kernel-xen kernel-ppc64 cloud-init 18 | # ignored_fs = autofs binfmt_misc cgroup cgroup2 configfs debugfs devpts devtmpfs fusectl fuse.gvfsd-fuse fuse.gvfs-fuse-daemon hugetlbfs mqueue nfsd proc pstore rootfs rpc_pipefs securityfs selinuxfs sysfs tmpfs tracefs udev usbfs 19 | # ignore_zero_size_fs = true 20 | # ignored_nics = docker0 21 | 22 | [virtio] 23 | # device_prefix = /dev/virtio-ports/ 24 | 25 | #[loggers] 26 | #keys=root 27 | 28 | #[handlers] 29 | #keys=console,syslog,logfile 30 | 31 | #[formatters] 32 | #keys=long,simple,none,sysform 33 | 34 | #[logger_root] 35 | #level=INFO 36 | #handlers=logfile 37 | #propagate=0 38 | 39 | #[handler_syslog] 40 | #class=handlers.SysLogHandler 41 | #formatter=sysform 42 | #args=(('localhost', handlers.SYSLOG_UDP_PORT), handlers.SysLogHandler.LOG_USER) 43 | 44 | #[handler_logfile] 45 | #class=handlers.RotatingFileHandler 46 | #args=('/var/log/ovirt-guest-agent/ovirt-guest-agent.log', 'a+', 100*1024, 5) 47 | #formatter=long 48 | 49 | #[handler_console] 50 | #class: StreamHandler 51 | #args: [] 52 | #formatter: none 53 | 54 | #[formatter_simple] 55 | #format: %(name)s:%(levelname)s: %(message)s 56 | 57 | #[formatter_none] 58 | #format: %(message)s 59 | 60 | #[formatter_long] 61 | #format: %(threadName)s::%(levelname)s::%(asctime)s::%(module)s::%(lineno)d::%(name)s::%(message)s 62 | 63 | #[formatter_sysform] 64 | #format= %(asctime)s %(levelname)s %(message)s 65 | #datefmt= 66 | -------------------------------------------------------------------------------- /configurations/ovirt-guest-agent.ini: -------------------------------------------------------------------------------- 1 | # 2 | # ovirt-guest-agent.ini - ovirt-guest-agent/Windows configuration file 3 | # 4 | 5 | [general] 6 | 7 | # heart_beat_rate = 5 8 | # report_user_rate = 10 9 | # report_num_cpu_rate = 60 10 | # report_application_rate = 120 11 | # report_disk_usage = 300 12 | # apply_timer_configuration = true 13 | 14 | [virtio] 15 | 16 | # device_prefix = \\.\Global\ 17 | 18 | #[loggers] 19 | #keys=root 20 | 21 | #[handlers] 22 | #keys=console,logfile 23 | 24 | #[formatters] 25 | #keys=long,simple,none,sysform 26 | 27 | #[logger_root] 28 | #level=INFO 29 | #handlers=logfile 30 | #propagate=0 31 | 32 | #[handler_logfile] 33 | #class=handlers.RotatingFileHandler 34 | #args=('ovirt-guest-agent.log', 'a+', 100*1024, 5) 35 | #formatter=long 36 | 37 | #[handler_console] 38 | #class: StreamHandler 39 | #args: [] 40 | #formatter: none 41 | 42 | #[formatter_simple] 43 | #format: %(name)s:%(levelname)s: %(message)s 44 | 45 | #[formatter_none] 46 | #format: %(message)s 47 | 48 | #[formatter_long] 49 | #format: %(threadName)s::%(levelname)s::%(asctime)s::%(module)s::%(lineno)d::%(name)s::%(message)s 50 | 51 | #[formatter_sysform] 52 | #format= %(asctime)s %(levelname)s %(message)s 53 | #datefmt= 54 | -------------------------------------------------------------------------------- /gdm-plugin/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | SUBDIRS = icons 3 | 4 | NULL = 5 | 6 | PAM_SERVICE_NAME = gdm-ovirtcred 7 | 8 | extensiondir = $(extensionsdatadir)/ovirtcred 9 | extension_DATA = page.ui 10 | 11 | AM_CPPFLAGS = \ 12 | -DPLUGINDATADIR=\""$(extensiondir)"\" \ 13 | -DGDM_OVIRTCRED_EXTENSION_SERVICE_NAME=\""$(PAM_SERVICE_NAME)"\" \ 14 | $(DISABLE_DEPRECATED_CFLAGS) \ 15 | $(GTK_CFLAGS) \ 16 | $(GDM_PLUGIN_CFLAGS) \ 17 | $(POLKIT_GNOME_CFLAGS) \ 18 | $(NULL) 19 | 20 | plugindir = $(GDM_SIMPLE_GREETER_PLUGINS_DIR) 21 | plugin_LTLIBRARIES = libovirtcred.la 22 | 23 | libovirtcred_la_CFLAGS = $(SIMPLE_GREETER_CFLAGS) -fPIC 24 | libovirtcred_la_LDFLAGS = -module -avoid-version -export-dynamic 25 | libovirtcred_la_LIBADD = $(GDM_PLUGIN_LIBS) 26 | libovirtcred_la_SOURCES = \ 27 | gdm-ovirtcred-extension.h \ 28 | gdm-ovirtcred-extension.c 29 | 30 | $(PAM_SERVICE_NAME): $(PAM_SERVICE_NAME).pam 31 | cp $(PAM_SERVICE_NAME).pam $(PAM_SERVICE_NAME) 32 | 33 | pamdir = $(PAM_PREFIX)/pam.d 34 | pam_DATA = $(PAM_SERVICE_NAME) 35 | 36 | EXTRA_DIST = \ 37 | $(extension_DATA) \ 38 | $(PAM_SERVICE_NAME).pam \ 39 | $(NULL) 40 | 41 | MAINTAINERCLEANFILES = \ 42 | *~ \ 43 | $(PAM_SERVICE_NAME) \ 44 | Makefile.in 45 | -------------------------------------------------------------------------------- /gdm-plugin/gdm-ovirtcred-extension.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 Red Hat, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Refer to the README and COPYING files for full details of the license. 17 | * 18 | * Written By: Gal Hammer 19 | * Based on a code written by: Ray Strode 20 | */ 21 | 22 | #ifndef __GDM_OVIRTCRED_EXTENSION_H 23 | #define __GDM_OVIRTCRED_EXTENSION_H 24 | 25 | #include 26 | #include "gdm-login-extension.h" 27 | 28 | G_BEGIN_DECLS 29 | 30 | #define GDM_TYPE_OVIRTCRED_EXTENSION (gdm_ovirtcred_extension_get_type ()) 31 | #define GDM_OVIRTCRED_EXTENSION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GDM_TYPE_OVIRTCRED_EXTENSION, GdmOVirtCredExtension)) 32 | #define GDM_OVIRTCRED_EXTENSION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GDM_TYPE_OVIRTCRED_EXTENSION, GdmOVirtCredExtensionClass)) 33 | #define GDM_IS_OVIRTCRED_EXTENSION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GDM_TYPE_OVIRTCRED_EXTENSION)) 34 | #define GDM_IS_OVIRTCRED_EXTENSION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GDM_TYPE_OVIRTCRED_EXTENSION)) 35 | #define GDM_OVIRTCRED_EXTENSION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GDM_TYPE_OVIRTCRED_EXTENSION, GdmOVirtCredExtensionClass)) 36 | 37 | #define GDM_OVIRTCRED_EXTENSION_NAME "gdm-ovirtcred-extension" 38 | 39 | typedef struct _GdmOVirtCredExtensionPrivate GdmOVirtCredExtensionPrivate; 40 | 41 | typedef struct 42 | { 43 | GObject parent; 44 | GdmOVirtCredExtensionPrivate *priv; 45 | } GdmOVirtCredExtension; 46 | 47 | typedef struct 48 | { 49 | GObjectClass parent_class; 50 | } GdmOVirtCredExtensionClass; 51 | 52 | GType gdm_ovirtcred_extension_get_type (void); 53 | 54 | G_END_DECLS 55 | 56 | #endif /* GDM_OVIRTCRED_EXTENSION_H */ 57 | -------------------------------------------------------------------------------- /gdm-plugin/gdm-ovirtcred.pam: -------------------------------------------------------------------------------- 1 | #%PAM-1.0 2 | auth required pam_ovirt_cred.so 3 | auth include password-auth 4 | account include password-auth 5 | password include password-auth 6 | session required pam_selinux.so close 7 | session required pam_selinux.so open 8 | session include password-auth 9 | -------------------------------------------------------------------------------- /gdm-plugin/icons/16x16/Makefile.am: -------------------------------------------------------------------------------- 1 | iconsdir = $(datadir)/icons/hicolor/16x16/apps 2 | 3 | icons_DATA = gdm-ovirtcred.png 4 | 5 | EXTRA_DIST = $(icons_DATA) 6 | -------------------------------------------------------------------------------- /gdm-plugin/icons/16x16/gdm-ovirtcred.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oVirt/ovirt-guest-agent/639a30df2d607011c367a451cb4179e8370cd6a0/gdm-plugin/icons/16x16/gdm-ovirtcred.png -------------------------------------------------------------------------------- /gdm-plugin/icons/48x48/Makefile.am: -------------------------------------------------------------------------------- 1 | iconsdir = $(datadir)/icons/hicolor/48x48/apps 2 | 3 | icons_DATA = gdm-ovirtcred.png 4 | 5 | EXTRA_DIST = $(icons_DATA) 6 | -------------------------------------------------------------------------------- /gdm-plugin/icons/48x48/gdm-ovirtcred.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oVirt/ovirt-guest-agent/639a30df2d607011c367a451cb4179e8370cd6a0/gdm-plugin/icons/48x48/gdm-ovirtcred.png -------------------------------------------------------------------------------- /gdm-plugin/icons/Makefile.am: -------------------------------------------------------------------------------- 1 | SUBDIRS = 16x16 48x48 2 | -------------------------------------------------------------------------------- /gdm-plugin/page.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | True 6 | vertical 7 | 8 | 9 | True 10 | 11 | 12 | True 13 | True 14 | 0 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /gdm-plugin/test-login.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python2 2 | 3 | import getpass, socket, struct 4 | 5 | def pack(user, password, domain = ''): 6 | if domain != '': 7 | username = user + '@' + domain 8 | else: 9 | username = user 10 | username = username.encode('utf-8') 11 | password = password.encode('utf-8') 12 | s = struct.pack('>I%ds%ds' % (len(username), len(password) + 1), 13 | len(username), username, password) 14 | return s 15 | 16 | def main(): 17 | user = raw_input('user: ') 18 | password = getpass.getpass('password: ') 19 | sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) 20 | sock.connect('/tmp/gdm-rhevcred-plugin') 21 | sock.send(pack(user, password)) 22 | 23 | if __name__ == "__main__": 24 | main() 25 | -------------------------------------------------------------------------------- /gdm2-plugin/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | EXTRA_DIST = \ 3 | gdm2-Makefile.am \ 4 | gdm-ovirtcred-extension.c \ 5 | gdm-ovirtcred-extension.h \ 6 | plugin.c 7 | 8 | MAINTAINERCLEANFILES = \ 9 | *~ \ 10 | Makefile.in 11 | -------------------------------------------------------------------------------- /gdm2-plugin/gdm-ovirtcred-extension.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010-2012 Red Hat, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Refer to the README and COPYING files for full details of the license. 17 | * 18 | * Written By: Gal Hammer 19 | * Base on code written by: Ray Strode 20 | * 21 | */ 22 | 23 | #ifndef __GDM_OVIRTCRED_EXTENSION_H 24 | #define __GDM_OVIRTCRED_EXTENSION_H 25 | 26 | #include 27 | #include "gdm-greeter-extension.h" 28 | 29 | G_BEGIN_DECLS 30 | 31 | #define GDM_TYPE_OVIRTCRED_EXTENSION (gdm_ovirtcred_extension_get_type ()) 32 | #define GDM_OVIRTCRED_EXTENSION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GDM_TYPE_OVIRTCRED_EXTENSION, GdmOVirtCredExtension)) 33 | #define GDM_OVIRTCRED_EXTENSION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GDM_TYPE_OVIRTCRED_EXTENSION, GdmOVirtCredExtensionClass)) 34 | #define GDM_IS_OVIRTCRED_EXTENSION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GDM_TYPE_OVIRTCRED_EXTENSION)) 35 | #define GDM_IS_OVIRTCRED_EXTENSION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GDM_TYPE_OVIRTCRED_EXTENSION)) 36 | #define GDM_OVIRTCRED_EXTENSION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GDM_TYPE_OVIRTCRED_EXTENSION, GdmOVirtCredExtensionClass)) 37 | 38 | typedef struct _GdmOVirtCredExtensionPrivate GdmOVirtCredExtensionPrivate; 39 | 40 | typedef struct 41 | { 42 | GObject parent; 43 | GdmOVirtCredExtensionPrivate *priv; 44 | 45 | } GdmOVirtCredExtension; 46 | 47 | typedef struct 48 | { 49 | GObjectClass parent_class; 50 | 51 | } GdmOVirtCredExtensionClass; 52 | 53 | GType gdm_ovirtcred_extension_get_type (void); 54 | 55 | GdmOVirtCredExtension *gdm_ovirtcred_extension_new (void); 56 | 57 | G_END_DECLS 58 | 59 | #endif /* GDM_OVIRTCRED_EXTENSION_H */ 60 | -------------------------------------------------------------------------------- /gdm2-plugin/gdm2-Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | SUBDIRS = icons 3 | 4 | PAM_SERVICE_NAME = gdm-ovirtcred 5 | 6 | extensiondir = $(extensionsdatadir)/ovirtcred 7 | extension_DATA = page.ui 8 | 9 | AM_CPPFLAGS = \ 10 | -I$(GDM_SRC_DIR)/common \ 11 | -I$(GDM_SRC_DIR)/gui/simple-greeter/libgdmsimplegreeter \ 12 | -DPLUGINDATADIR=\""$(extensiondir)"\" \ 13 | -DPAMSERVICENAME=\""$(PAM_SERVICE_NAME)"\" \ 14 | $(DISABLE_DEPRECATED_CFLAGS) \ 15 | $(GDM_PLUGIN_CFLAGS) \ 16 | $(NULL) 17 | 18 | plugindir = $(GDM_SIMPLE_GREETER_PLUGINS_DIR) 19 | plugin_LTLIBRARIES = ovirtcred.la 20 | 21 | ovirtcred_la_CFLAGS = \ 22 | $(GDM_PLUGIN_CFLAGS) \ 23 | $(NULL) 24 | 25 | ovirtcred_la_LDFLAGS = -module -avoid-version -export-dynamic 26 | ovirtcred_la_LIBADD = $(GDM_SRC_DIR)/gui/simple-greeter/libgdmsimplegreeter/libgdmsimplegreeter.la 27 | ovirtcred_la_SOURCES = \ 28 | gdm-ovirtcred-extension.h \ 29 | gdm-ovirtcred-extension.c \ 30 | plugin.c 31 | 32 | $(PAM_SERVICE_NAME): $(PAM_SERVICE_NAME).pam 33 | cp $(PAM_SERVICE_NAME).pam $(PAM_SERVICE_NAME) 34 | 35 | pamdir = $(PAM_PREFIX)/pam.d 36 | pam_DATA = $(PAM_SERVICE_NAME) 37 | 38 | EXTRA_DIST = $(extension_DATA) $(PAM_SERVICE_NAME).pam 39 | CLEANFILES = $(PAM_SERVICE_NAME) 40 | 41 | MAINTAINERCLEANFILES = \ 42 | *~ \ 43 | $(PAM_SERVICE_NAME) \ 44 | Makefile.in 45 | -------------------------------------------------------------------------------- /gdm2-plugin/plugin.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010-2012 Red Hat, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Refer to the README and COPYING files for full details of the license. 17 | * 18 | * Written By: Gal Hammer 19 | * Base on code written by: Ray Strode 20 | * 21 | */ 22 | 23 | #include "gdm-ovirtcred-extension.h" 24 | 25 | #include 26 | #include 27 | 28 | GdmGreeterExtension * 29 | gdm_greeter_plugin_get_extension (void) 30 | { 31 | static GObject *extension; 32 | 33 | if (extension != NULL) { 34 | g_object_ref (extension); 35 | } else { 36 | extension = g_object_new (GDM_TYPE_OVIRTCRED_EXTENSION, NULL); 37 | g_object_add_weak_pointer (extension, (gpointer *) &extension); 38 | } 39 | 40 | return GDM_GREETER_EXTENSION (extension); 41 | } 42 | -------------------------------------------------------------------------------- /hooks/55-flush-caches.consolehelper: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | /usr/share/ovirt-guest-agent/ovirt-flush-caches 4 | -------------------------------------------------------------------------------- /hooks/55-flush-caches.sudo: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | sudo /usr/share/ovirt-guest-agent/ovirt-flush-caches 4 | -------------------------------------------------------------------------------- /hooks/Makefile.am: -------------------------------------------------------------------------------- 1 | flush_caches_scriptdir = $(pkgdatadir)/scripts/hooks/defaults 2 | flush_caches_script_SCRIPTS= \ 3 | flush-caches \ 4 | $(NULL) 5 | 6 | EXTRA_DIST= \ 7 | flush-caches \ 8 | 55-flush-caches.consolehelper \ 9 | 55-flush-caches.sudo \ 10 | $(NULL) 11 | 12 | flushcachesinvocatordir = $(pkgdatadir)/scripts/hooks/defaults 13 | if INSTALL_SUDO_SCRIPTS 14 | FLUSH_CACHES_INVOCATOR=55-flush-caches.sudo 15 | else 16 | if INSTALL_USERMODE_SCRIPTS 17 | FLUSH_CACHES_INVOCATOR=55-flush-caches.consolehelper 18 | endif 19 | endif 20 | 21 | flushcachesinvocator_SCRIPTS= \ 22 | $(FLUSH_CACHES_INVOCATOR) \ 23 | $(NULL) 24 | 25 | install-exec-hook: 26 | $(MKDIR_P) $(DESTDIR)/$(pkgdatadir) 27 | $(MKDIR_P) $(DESTDIR)/$(pkgdatadir)/scripts/hooks/defaults 28 | $(MKDIR_P) $(DESTDIR)/$(pkgdatadir)/scripts/hooks/before_migration 29 | $(MKDIR_P) $(DESTDIR)/$(pkgdatadir)/scripts/hooks/after_migration 30 | $(MKDIR_P) $(DESTDIR)/$(pkgdatadir)/scripts/hooks/before_hibernation 31 | $(MKDIR_P) $(DESTDIR)/$(pkgdatadir)/scripts/hooks/after_hibernation 32 | $(MKDIR_P) $(DESTDIR)/$(sysconfdir)/ovirt-guest-agent/hooks.d/before_migration 33 | $(MKDIR_P) $(DESTDIR)/$(sysconfdir)/ovirt-guest-agent/hooks.d/after_migration 34 | $(MKDIR_P) $(DESTDIR)/$(sysconfdir)/ovirt-guest-agent/hooks.d/before_hibernation 35 | $(MKDIR_P) $(DESTDIR)/$(sysconfdir)/ovirt-guest-agent/hooks.d/after_hibernation 36 | $(LN_S) -f $(pkgdatadir)/scripts/hooks/defaults/55-flush-caches $(DESTDIR)/$(pkgdatadir)/scripts/hooks/before_migration/55_flush-caches 37 | $(LN_S) -f $(pkgdatadir)/scripts/hooks/defaults/55-flush-caches $(DESTDIR)/$(pkgdatadir)/scripts/hooks/before_hibernation/55_flush-caches 38 | $(LN_S) -f $(pkgdatadir)/scripts/hooks/before_migration/55_flush-caches $(DESTDIR)/$(sysconfdir)/ovirt-guest-agent/hooks.d/before_migration/55_flush-caches 39 | $(LN_S) -f $(pkgdatadir)/scripts/hooks/before_hibernation/55_flush-caches $(DESTDIR)/$(sysconfdir)/ovirt-guest-agent/hooks.d/before_hibernation/55_flush-caches 40 | $(LN_S) -f $(pkgdatadir)/scripts/hooks/defaults/$(FLUSH_CACHES_INVOCATOR) $(DESTDIR)/$(pkgdatadir)/scripts/hooks/defaults/55-flush-caches 41 | -------------------------------------------------------------------------------- /hooks/flush-caches: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # This line will drop all caches on Linux systems 4 | # See https://www.kernel.org/doc/Documentation/sysctl/vm.txt for more 5 | # information 6 | echo 3 > /proc/sys/vm/drop_caches 7 | -------------------------------------------------------------------------------- /kdm-plugin/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | PAM_SERVICE_NAME = kdm-ovirtcred 3 | 4 | dist_noinst_DATA = \ 5 | src/CMakeLists.txt \ 6 | src/kgreet_ovirtcred.h \ 7 | src/kgreet_ovirtcred.cpp \ 8 | src/OVirtCred.h \ 9 | src/OVirtCred.cpp 10 | 11 | all-local: 12 | cmake -DCMAKE_INSTALL_PREFIX=$(prefix) src/CMakeLists.txt 13 | make -C src 14 | 15 | clean-local: 16 | make -C src clean || : 17 | 18 | install-exec-hook: 19 | make -C src install DESTDIR=$(DESTDIR) 20 | 21 | $(PAM_SERVICE_NAME): $(PAM_SERVICE_NAME).pam 22 | cp $(PAM_SERVICE_NAME).pam $(PAM_SERVICE_NAME) 23 | 24 | pamdir = $(PAM_PREFIX)/pam.d 25 | pam_DATA = $(PAM_SERVICE_NAME) 26 | 27 | EXTRA_DIST = \ 28 | $(PAM_SERVICE_NAME).pam \ 29 | credentials.xml \ 30 | $(NULL) 31 | 32 | CLEANFILES = \ 33 | *~ \ 34 | $(PAM_SERVICE_NAME) 35 | -------------------------------------------------------------------------------- /kdm-plugin/credentials.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /kdm-plugin/kdm-ovirtcred.pam: -------------------------------------------------------------------------------- 1 | #%PAM-1.0 2 | auth required pam_ovirt_cred.so 3 | auth include password-auth 4 | account include password-auth 5 | password include password-auth 6 | session required pam_selinux.so close 7 | session required pam_selinux.so open 8 | session include password-auth 9 | -------------------------------------------------------------------------------- /kdm-plugin/src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | CMAKE_MINIMUM_REQUIRED(VERSION 2.6) 2 | 3 | PROJECT( KGREET_OVIRTCRED ) 4 | 5 | ADD_DEFINITIONS( -Wall -std=c++98 ) 6 | 7 | FIND_PACKAGE( KDE4 REQUIRED ) 8 | 9 | INCLUDE_DIRECTORIES( ./ ../ ${KDE4_INCLUDES} ${CMAKE_CURRENT_BINARY_DIR} ) 10 | 11 | SET( kgreet_ovirtcred_PART_SRCS ./kgreet_ovirtcred.cpp ./OVirtCred.cpp ) 12 | 13 | KDE4_ADD_PLUGIN( kgreet_ovirtcred ${kgreet_ovirtcred_PART_SRCS} ) 14 | 15 | TARGET_LINK_LIBRARIES( kgreet_ovirtcred ${KDE4_KDEUI_LIBS} ) 16 | 17 | INSTALL(TARGETS kgreet_ovirtcred DESTINATION ${PLUGIN_INSTALL_DIR} ) 18 | 19 | -------------------------------------------------------------------------------- /kdm-plugin/src/OVirtCred.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file was generated by qdbusxml2cpp version 0.7 3 | * Command line was: qdbusxml2cpp -v -c OVirtCred -p OVirtCred.h:OVirtCred.cpp credentials.xml 4 | * 5 | * qdbusxml2cpp is Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). 6 | * 7 | * This is an auto-generated file. 8 | * This file may have been hand-edited. Look for HAND-EDIT comments 9 | * before re-generating it. 10 | */ 11 | 12 | #include "OVirtCred.h" 13 | 14 | /* 15 | * Implementation of interface class OVirtCred 16 | */ 17 | 18 | OVirtCred::OVirtCred(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent) 19 | : QDBusAbstractInterface(service, path, staticInterfaceName(), connection, parent) 20 | { 21 | } 22 | 23 | OVirtCred::~OVirtCred() 24 | { 25 | } 26 | 27 | -------------------------------------------------------------------------------- /kdm-plugin/src/OVirtCred.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file was generated by qdbusxml2cpp version 0.7 3 | * Command line was: qdbusxml2cpp -v -c OVirtCred -p OVirtCred.h:OVirtCred.cpp credentials.xml 4 | * 5 | * qdbusxml2cpp is Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). 6 | * 7 | * This is an auto-generated file. 8 | * Do not edit! All changes made to it will be lost. 9 | */ 10 | 11 | #ifndef OVIRTCRED_H_1320323908 12 | #define OVIRTCRED_H_1320323908 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | /* 24 | * Proxy class for interface org.ovirt.vdsm.Credentials 25 | */ 26 | class OVirtCred: public QDBusAbstractInterface 27 | { 28 | Q_OBJECT 29 | public: 30 | static inline const char *staticInterfaceName() 31 | { return "org.ovirt.vdsm.Credentials"; } 32 | 33 | public: 34 | OVirtCred(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent = 0); 35 | 36 | ~OVirtCred(); 37 | 38 | public Q_SLOTS: // METHODS 39 | Q_SIGNALS: // SIGNALS 40 | void UserAuthenticated(const QString &token); 41 | }; 42 | 43 | namespace org { 44 | namespace ovirt { 45 | namespace vdsm { 46 | typedef ::OVirtCred Credentials; 47 | } 48 | } 49 | } 50 | #endif 51 | -------------------------------------------------------------------------------- /kdm-plugin/src/kgreet_ovirtcred.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "kgreet_ovirtcred.h" 3 | #include "OVirtCred.h" 4 | 5 | #include 6 | #include 7 | 8 | #include 9 | #include 10 | 11 | #define KDM_OVIRTCRED_SERVER_DBUS_NAME "org.ovirt.vdsm.Credentials" 12 | #define KDM_OVIRTCRED_SERVER_DBUS_PATH "/org/ovirt/vdsm/Credentials" 13 | #define KDM_OVIRTCRED_SERVER_DBUS_INTERFACE KDM_OVIRTCRED_SERVER_DBUS_NAME 14 | 15 | KOVirtCredGreeter::KOVirtCredGreeter(KGreeterPluginHandler *handler, 16 | QWidget *parent, 17 | const QString &fixedEntity, 18 | Function func, Context ctx) : 19 | QObject(), 20 | KGreeterPlugin(handler) 21 | { 22 | Q_UNUSED(parent); 23 | Q_UNUSED(fixedEntity); 24 | Q_UNUSED(func); 25 | Q_UNUSED(ctx); 26 | 27 | parent = new QWidget(parent); 28 | parent->setObjectName("welcome"); 29 | widgetList << parent; 30 | 31 | QBoxLayout *grid = new QBoxLayout(QBoxLayout::LeftToRight, parent); 32 | m_titleLabel = new QLabel(i18n("oVirt Automatic Login System"), parent); 33 | grid->addWidget(m_titleLabel, 0, Qt::AlignHCenter); 34 | 35 | m_Credentials = new OVirtCred(KDM_OVIRTCRED_SERVER_DBUS_NAME, KDM_OVIRTCRED_SERVER_DBUS_PATH, 36 | QDBusConnection::systemBus(), 0); 37 | 38 | QObject::connect(m_Credentials, SIGNAL(UserAuthenticated(QString)), 39 | this, SLOT(userAuthenticated(QString))); 40 | } 41 | 42 | KOVirtCredGreeter::~KOVirtCredGreeter() 43 | { 44 | abort(); 45 | qDeleteAll(widgetList); 46 | 47 | delete m_Credentials; 48 | } 49 | 50 | void KOVirtCredGreeter::loadUsers(const QStringList &users) 51 | { 52 | // We do no offer a selectable users list. 53 | Q_UNUSED(users); 54 | } 55 | 56 | void KOVirtCredGreeter::presetEntity(const QString &entity, int field) 57 | { 58 | // We do not care about preloaded users either. 59 | Q_UNUSED(entity); 60 | Q_UNUSED(field); 61 | } 62 | 63 | QString KOVirtCredGreeter::getEntity() const 64 | { 65 | return QString(); 66 | } 67 | 68 | void KOVirtCredGreeter::setUser(const QString &user) 69 | { 70 | Q_UNUSED(user); 71 | } 72 | 73 | void KOVirtCredGreeter::setEnabled(bool on) 74 | { 75 | Q_UNUSED(on); 76 | } 77 | 78 | bool KOVirtCredGreeter::textMessage(const char *message, bool error) 79 | { 80 | if (error) { 81 | // Stop authentication. 82 | abort(); 83 | } else { 84 | handler->gplugMsgBox(QMessageBox::Information, message); 85 | } 86 | 87 | return true; 88 | } 89 | 90 | void KOVirtCredGreeter::textPrompt(const char *prompt, bool echo, bool nonBlocking) 91 | { 92 | Q_UNUSED(echo); 93 | Q_UNUSED(nonBlocking); 94 | 95 | QString text = QString(prompt); 96 | if (text.contains(QString("Token?"), Qt::CaseInsensitive)) { 97 | handler->gplugReturnText(m_token.toAscii(), KGreeterPluginHandler::IsSecret); 98 | m_token.clear(); 99 | } else { 100 | abort(); 101 | } 102 | } 103 | 104 | bool KOVirtCredGreeter::binaryPrompt(const char *prompt, bool nonBlocking) 105 | { 106 | Q_UNUSED(prompt); 107 | Q_UNUSED(nonBlocking); 108 | return true; 109 | } 110 | 111 | void KOVirtCredGreeter::start() 112 | { 113 | 114 | } 115 | 116 | void KOVirtCredGreeter::suspend() 117 | { 118 | 119 | } 120 | 121 | void KOVirtCredGreeter::resume() 122 | { 123 | 124 | } 125 | 126 | void KOVirtCredGreeter::next() 127 | { 128 | 129 | } 130 | 131 | void KOVirtCredGreeter::abort() 132 | { 133 | 134 | } 135 | 136 | void KOVirtCredGreeter::succeeded() 137 | { 138 | 139 | } 140 | 141 | void KOVirtCredGreeter::failed() 142 | { 143 | 144 | } 145 | 146 | void KOVirtCredGreeter::revive() 147 | { 148 | 149 | } 150 | 151 | void KOVirtCredGreeter::clear() 152 | { 153 | 154 | } 155 | 156 | void KOVirtCredGreeter::userAuthenticated(QString token) 157 | { 158 | m_token = token; 159 | 160 | handler->gplugStart(); 161 | } 162 | 163 | static bool init(const QString &, 164 | QVariant (*getConf)(void *, const char *, const QVariant &), 165 | void *ctx) 166 | { 167 | Q_UNUSED(getConf); 168 | Q_UNUSED(ctx); 169 | KGlobal::locale()->insertCatalog("kgreet_ovirtcred"); 170 | return true; 171 | } 172 | 173 | static void done() 174 | { 175 | KGlobal::locale()->removeCatalog("kgreet_ovirtcred"); 176 | } 177 | 178 | static KGreeterPlugin* create(KGreeterPluginHandler *handler, 179 | QWidget *parent, 180 | const QString &fixedEntity, 181 | KGreeterPlugin::Function func, 182 | KGreeterPlugin::Context ctx) 183 | { 184 | return new KOVirtCredGreeter(handler, parent, fixedEntity, func, ctx); 185 | } 186 | 187 | KDE_EXPORT KGreeterPluginInfo kgreeterplugin_info = { 188 | I18N_NOOP2("@item:inmenu authentication method", "oVirt Authentication"), "ovirtcred", 189 | KGreeterPluginInfo::Local | KGreeterPluginInfo::Presettable, 190 | init, done, create 191 | }; 192 | 193 | #include "kgreet_ovirtcred.moc" 194 | -------------------------------------------------------------------------------- /kdm-plugin/src/kgreet_ovirtcred.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef KGREET_OVIRTCRED_H 3 | #define KGREET_OVIRTCRED_H 4 | 5 | #include 6 | 7 | #include 8 | 9 | class OVirtCred; 10 | 11 | class KOVirtCredGreeter : public QObject, public KGreeterPlugin 12 | { 13 | Q_OBJECT 14 | 15 | public: 16 | KOVirtCredGreeter(KGreeterPluginHandler *handler, 17 | QWidget *parent, 18 | const QString &fixedEntitiy, 19 | Function func, Context ctx ); 20 | virtual ~KOVirtCredGreeter(); 21 | 22 | // KGreeterPlugin's methods. 23 | 24 | virtual void loadUsers(const QStringList &users); 25 | virtual void presetEntity(const QString &entity, int field); 26 | virtual QString getEntity() const; 27 | virtual void setUser(const QString &user); 28 | virtual void setEnabled(bool on); 29 | virtual bool textMessage(const char *message, bool error); 30 | virtual void textPrompt(const char *prompt, bool echo, bool nonBlocking); 31 | virtual bool binaryPrompt(const char *prompt, bool nonBlocking); 32 | virtual void start(); 33 | virtual void suspend(); 34 | virtual void resume(); 35 | virtual void next(); 36 | virtual void abort(); 37 | virtual void succeeded(); 38 | virtual void failed(); 39 | virtual void revive(); 40 | virtual void clear(); 41 | 42 | public Q_SLOTS: 43 | void userAuthenticated(QString token); 44 | 45 | private: 46 | OVirtCred *m_Credentials; 47 | QLabel *m_titleLabel; 48 | QString m_token; 49 | }; 50 | 51 | #endif // KGREET_OVIRTCRED_H 52 | -------------------------------------------------------------------------------- /m4/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oVirt/ovirt-guest-agent/639a30df2d607011c367a451cb4179e8370cd6a0/m4/.keep -------------------------------------------------------------------------------- /m4/fhs.m4: -------------------------------------------------------------------------------- 1 | AC_DEFUN([DEFINE_FHS_REDHAT],[ 2 | AC_SUBST([exec_prefix], ['${prefix}']) 3 | AC_SUBST([bindir], ['${exec_prefix}/bin']) 4 | AC_SUBST([sbindir], ['${exec_prefix}/sbin']) 5 | AC_SUBST([libexecdir], ['${exec_prefix}/libexec']) 6 | AC_SUBST([datarootdir], ['${prefix}/share']) 7 | AC_SUBST([datadir], ['${datarootdir}']) 8 | AC_SUBST([sysconfdir], ['/etc']) 9 | AC_SUBST([localstatedir], ['/var']) 10 | AC_SUBST([sharedstatedir], ['/var/lib']) 11 | AC_SUBST([includedir], ['${prefix}/include']) 12 | AC_SUBST([oldincludedir], ['/usr/include']) 13 | AC_SUBST([libdir], ['${exec_prefix}/lib']) 14 | AC_SUBST([localedir], ['${datarootdir}/locale']) 15 | AC_SUBST([mandir], ['/usr/share/man']) 16 | AC_SUBST([infodir], ['/usr/share/info']) 17 | AC_SUBST([rundir], ['${sharedstatedir}/run']) 18 | AC_SUBST([udevdir], ['${sysconfdir}/udev']) 19 | ]) 20 | 21 | AC_DEFUN([DEFINE_FHS_SUSE],[ 22 | AC_SUBST([exec_prefix], ['${prefix}']) 23 | AC_SUBST([bindir], ['${exec_prefix}/bin']) 24 | AC_SUBST([sbindir], ['${exec_prefix}/sbin']) 25 | AC_SUBST([libexecdir], ['${exec_prefix}/libexec']) 26 | AC_SUBST([datarootdir], ['${prefix}/share']) 27 | AC_SUBST([datadir], ['${datarootdir}']) 28 | AC_SUBST([sysconfdir], ['/etc']) 29 | AC_SUBST([localstatedir], ['/var']) 30 | AC_SUBST([sharedstatedir], ['/var/lib']) 31 | AC_SUBST([includedir], ['${prefix}/include']) 32 | AC_SUBST([oldincludedir], ['/usr/include']) 33 | AC_SUBST([libdir], ['${exec_prefix}/lib']) 34 | AC_SUBST([localedir], ['${datarootdir}/locale']) 35 | AC_SUBST([mandir], ['/usr/share/man']) 36 | AC_SUBST([infodir], ['/usr/share/info']) 37 | AC_SUBST([rundir], ['${sharedstatedir}/run']) 38 | AC_SUBST([udevdir], ['/lib/udev']) 39 | ]) 40 | 41 | AC_DEFUN([DEFINE_FHS_DEBIAN],[ 42 | AC_SUBST([exec_prefix], ['${prefix}']) 43 | AC_SUBST([bindir], ['${exec_prefix}/bin']) 44 | AC_SUBST([sbindir], ['${exec_prefix}/sbin']) 45 | AC_SUBST([libexecdir], ['${exec_prefix}/libexec']) 46 | AC_SUBST([datarootdir], ['${prefix}/share']) 47 | AC_SUBST([datadir], ['${datarootdir}']) 48 | AC_SUBST([sysconfdir], ['/etc']) 49 | AC_SUBST([localstatedir], ['/var']) 50 | AC_SUBST([sharedstatedir], ['/var/lib']) 51 | AC_SUBST([includedir], ['${prefix}/include']) 52 | AC_SUBST([oldincludedir], ['/usr/include']) 53 | AC_SUBST([libdir], ['${exec_prefix}/lib']) 54 | AC_SUBST([localedir], ['${datarootdir}/locale']) 55 | AC_SUBST([mandir], ['/usr/share/man']) 56 | AC_SUBST([infodir], ['/usr/share/info']) 57 | AC_SUBST([rundir], ['${sharedstatedir}/run']) 58 | AC_SUBST([udevdir], ['/lib/udev']) 59 | ]) 60 | 61 | 62 | AC_DEFUN([DEFINE_FHS],[ 63 | if test -f /etc/redhat-release; then 64 | DEFINE_FHS_REDHAT 65 | elif test -f /etc/SuSE-release; then 66 | DEFINE_FHS_SUSE 67 | elif test -f /etc/debian_version; then 68 | DEFINE_FHS_DEBIAN 69 | fi 70 | 71 | AC_SUBST([pkgdocdir], [m4_ifset([AC_PACKAGE_TARNAME], 72 | ['${docdir}/${PACKAGE_TARNAME}'], 73 | ['${docdir}/${PACKAGE}'])]) 74 | 75 | if test "x${udevdir}" == "x"; then 76 | AC_SUBST([udevdir], ['${sysconfdir}/udev']) 77 | fi 78 | AC_SUBST([udevrulesdir], ['${udevdir}/rules.d']) 79 | AC_SUBST([pkgdatadir], ['${datadir}/${PACKAGE}']) 80 | AC_SUBST([pkgdaemonpidpath], ['${rundir}/${PACKAGE}.pid']) 81 | 82 | AC_SUBST([lib64dir], ['${exec_prefix}/lib64']) 83 | 84 | if test -d /usr/lib64; then 85 | AC_SUBST([libarchdir], ['${lib64dir}']) 86 | else 87 | AC_SUBST([libarchdir], ['${libdir}']) 88 | fi 89 | 90 | if test -d /var/lock/subsys; then 91 | AC_SUBST([lock_dir], ['/var/lock/subsys']) 92 | else 93 | AC_SUBST([lock_dir], ['/var/lock']) 94 | fi 95 | ]) 96 | 97 | AC_DEFUN([PRINT_VARS],[ 98 | echo "prefix: $prefix" 99 | echo "exec_prefix: $exec_prefix" 100 | echo "bindir: $bindir" 101 | echo "sbindir: $sbindir" 102 | echo "libexecdir: $libexecdir" 103 | echo "datarootdir: $datarootdir" 104 | echo "datadir: $datadir" 105 | echo "sysconfdir: $sysconfdir" 106 | echo "sharedstatedir: $sharedstatedir" 107 | echo "localstatedir: $localstatedir" 108 | echo "includedir: $includedir" 109 | echo "oldincludedir: $oldincludedir" 110 | echo "docdir: $docdir" 111 | echo "infodir: $infodir" 112 | echo "htmldir: $htmldir" 113 | echo "dvidir: $dvidir" 114 | echo "pdfdir: $pdfdir" 115 | echo "psdir: $psdir" 116 | echo "libdir: $libdir" 117 | echo "lib64dir: $lib64dir" 118 | echo "libarchdir: $libarchdir" 119 | echo "localedir: $localedir" 120 | echo "mandir: $mandir" 121 | echo "pkgdocdir: $pkgdocdir" 122 | echo "pkgdatadir: $pkgdatadir" 123 | echo "pkgdaemonpidpath: $pkgdaemonpidpath" 124 | ]) 125 | 126 | -------------------------------------------------------------------------------- /ovirt-guest-agent-windows.spec: -------------------------------------------------------------------------------- 1 | %global python_windows_version 2.7.14 2 | %global pywin32_py27_version 222 3 | 4 | Name: ovirt-guest-agent-windows 5 | Version: 1.0.16 6 | Release: 1%{?release_suffix}%{?dist} 7 | Summary: oVirt Guest Agent Service for Windows 8 | License: ASL 2.0 9 | Source0: http:///resources.ovirt.org/pub/src/ovirt-guest-agent/ovirt-guest-agent-%{version}.tar.bz2 10 | 11 | URL: http://www.ovirt.org/ 12 | BuildArch: noarch 13 | Packager: Lev Veyde 14 | 15 | BuildRequires: p7zip 16 | BuildRequires: py2exe-py2.7 = 0.6.9 17 | BuildRequires: python-windows = %{python_windows_version} 18 | BuildRequires: pywin32-py2.7 = %{pywin32_py27_version} 19 | BuildRequires: wine 20 | BuildRequires: wget 21 | BuildRequires: mingw32-gcc-c++ 22 | BuildRequires: mingw64-gcc-c++ 23 | 24 | %description 25 | oVirt Guest Agent Service executable for Microsoft Windows platform. 26 | 27 | %prep 28 | %setup -q -n ovirt-guest-agent-%{version} 29 | 30 | %build 31 | 32 | pushd windows-credprov 33 | x86_64-w64-mingw32-g++ *.cpp -I . -o oVirtCredentialsProvider64.dll -shared -static-libstdc++ -static-libgcc -lshlwapi -lsecur32 -lole32 -luuid -lcredui 34 | i686-w64-mingw32-g++ *.cpp -I . -o oVirtCredentialsProvider32.dll -shared -static-libstdc++ -static-libgcc -lshlwapi -lsecur32 -lole32 -luuid -lcredui 35 | popd 36 | 37 | pushd GinaSSO 38 | i686-w64-mingw32-g++ *.cpp -I . -o oVirtGinaSSO.dll -shared -static-libstdc++ -static-libgcc -lshlwapi -lsecur32 -lole32 -luuid -lwsock32 -DUNICODE 39 | popd 40 | 41 | # Use this instead of ~/.wine. See wine(1). 42 | export WINEPREFIX=$PWD/wineprefix 43 | 44 | wine msiexec /i %{_datadir}/python-windows/python-%{python_windows_version}.msi /qn ADDLOCAL=ALL 45 | export Path="%PATH%;C:\Python27" 46 | 47 | 7za x %{_datadir}/pywin32-py2.7/pywin32-%{pywin32_py27_version}.win32-py2.7.exe 48 | mv PLATLIB/* $WINEPREFIX/drive_c/Python27/Lib/site-packages/ 49 | rmdir PLATLIB 50 | mv SCRIPTS/* $WINEPREFIX/drive_c/Python27/Lib/site-packages/ 51 | rmdir SCRIPTS 52 | pushd $WINEPREFIX/drive_c/Python27/Lib/site-packages/ 53 | wine python pywin32_postinstall.py -install -silent -quiet 54 | rm -f ./pywin32_postinstall.py 55 | popd 56 | 57 | 7za x %{_datadir}/py2exe-py2.7/py2exe-0.6.9.win32-py2.7.exe 58 | mv PLATLIB/* $WINEPREFIX/drive_c/Python27/Lib/site-packages/ 59 | rmdir PLATLIB 60 | mv SCRIPTS/* $WINEPREFIX/drive_c/Python27/Lib/site-packages/ 61 | rmdir SCRIPTS 62 | pushd $WINEPREFIX/drive_c/Python27/Lib/site-packages/ 63 | wine python ./py2exe_postinstall.py -install 64 | rm -f ./py2exe_postinstall.py 65 | popd 66 | 67 | pushd ovirt-guest-agent 68 | mkdir -p build/bdist.win32/winexe/bundle-2.7/ 69 | cp $WINEPREFIX/drive_c/Python27/python27.dll build/bdist.win32/winexe/bundle-2.7/ 70 | wine cmd.exe /C win-guest-agent-build-exe.bat 71 | popd 72 | 73 | %install 74 | DST=%{buildroot}%{_datadir}/%{name}/ 75 | mkdir -p $DST 76 | cp -v %{_builddir}/ovirt-guest-agent-%{version}/ovirt-guest-agent/dist/*.exe $DST 77 | cp -v %{_builddir}/ovirt-guest-agent-%{version}/configurations/default.ini $DST 78 | cp -v %{_builddir}/ovirt-guest-agent-%{version}/configurations/default-logger.ini $DST 79 | cp -v %{_builddir}/ovirt-guest-agent-%{version}/configurations/ovirt-guest-agent.ini $DST 80 | 81 | # SSO Plugins 82 | cp -v %{_builddir}/ovirt-guest-agent-%{version}/GinaSSO/oVirtGinaSSO.dll $DST 83 | cp -v %{_builddir}/ovirt-guest-agent-%{version}/windows-credprov/oVirtCredentialsProvider32.dll $DST 84 | cp -v %{_builddir}/ovirt-guest-agent-%{version}/windows-credprov/oVirtCredentialsProvider64.dll $DST 85 | 86 | %files 87 | %{_datadir}/%{name} 88 | 89 | %changelog 90 | * Wed Feb 20 2019 Tomáš Golembiovský - 1.0.16-1 91 | - New upstream version 1.0.16 92 | 93 | * Tue Jan 22 2019 Tomáš Golembiovský - 1.0.15-1 94 | - New upstream version 1.0.15 95 | 96 | * Mon Oct 23 2017 Tomáš Golembiovský - 1.0.14-1 97 | - New upstream version 1.0.14 98 | 99 | * Mon Oct 23 2017 Tomáš Golembiovský - 1.0.13-3 100 | - Requrires pywin32 version 221 instead of 220 101 | 102 | * Tue Oct 10 2017 Sandro Bonazzola - 1.0.13-2 103 | - Requires python 2.7.14 instead of 2.7.12 104 | 105 | * Tue Dec 06 2016 Vinzenz Feenstra - 1.0.13-1 106 | - New upstream version 1.0.13 107 | 108 | * Thu May 19 2016 Vinzenz Feenstra - 1.0.12-1 109 | - Updated version 1.0.12 110 | 111 | * Tue Oct 20 2015 Yedidyah Bar David - 1.0.11-2 112 | - dropped "artifacts" from all paths 113 | 114 | * Wed Aug 12 2015 Sandro Bonazzola - 1.0.11-1 115 | - New upstream version 1.0.11 116 | 117 | * Mon Nov 24 2014 Lev Veyde 1.0.10.3-1 118 | - Updated oVirt Guest Agent 119 | 120 | * Wed Oct 08 2014 Lev Veyde 1.0.10.2-2 121 | - Small fixes 122 | -------------------------------------------------------------------------------- /ovirt-guest-agent/LockActiveSession.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python2 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # Refer to the README and COPYING files for full details of the license. 16 | # 17 | 18 | import logging 19 | import os 20 | import os.path 21 | import subprocess 22 | 23 | import dbus 24 | 25 | 26 | class SessionWrapper(object): 27 | def __init__(self, session, bus, path): 28 | self._bus = bus 29 | self._path = path 30 | self._session = session 31 | self._props = GetInterface(bus, 'login1', '', path, 32 | 'org.freedesktop.DBus.Properties') 33 | 34 | def _getProperty(self, name): 35 | return self._props.Get('org.freedesktop.login1.Session', name) 36 | 37 | def GetId(self): 38 | return self._getProperty('Id') 39 | 40 | def IsActive(self): 41 | return self._getProperty('Active') 42 | 43 | def GetX11Display(self): 44 | return self._getProperty('Display') 45 | 46 | def GetUnixUser(self): 47 | return self._getProperty('User')[0] 48 | 49 | def Lock(self): 50 | return self._session.Lock() 51 | 52 | 53 | def GetInterface(bus, service, name, path, fname=None): 54 | obj = bus.get_object('org.freedesktop.%s' % service, path) 55 | iface = fname 56 | if not iface: 57 | iface = 'org.freedesktop.%s.%s' % (service, name) 58 | if not name: 59 | iface = iface[:-1] 60 | return dbus.Interface(obj, dbus_interface=iface) 61 | 62 | 63 | def GetInterfaceByName(bus, service, name, isSub): 64 | path = '/org/freedesktop/' + service 65 | if isSub: 66 | path += '/' + name 67 | return GetInterface(bus, service, name, path) 68 | 69 | 70 | def GetSessions(manager): 71 | try: 72 | return manager.GetSessions() 73 | except dbus.DBusException: 74 | return [x[4] for x in manager.ListSessions()] 75 | 76 | 77 | def GetSession(bus, service, managerIsSub, wrapSession): 78 | session = None 79 | try: 80 | manager = GetInterfaceByName(bus, service, 'Manager', managerIsSub) 81 | for session_path in GetSessions(manager): 82 | s = GetInterface(bus, service, 'Session', session_path) 83 | s = wrapSession(s, bus, session_path) 84 | if s.IsActive(): 85 | session = s 86 | break 87 | except dbus.DBusException: 88 | logging.exception("%s seems not to be available", service) 89 | return session 90 | 91 | 92 | def GetActiveSession(): 93 | bus = dbus.SystemBus() 94 | ARGS = (('ConsoleKit', True, lambda *a: a[0]), 95 | ('login1', False, SessionWrapper)) 96 | for args in ARGS: 97 | session = GetSession(bus, *args) 98 | if session: 99 | break 100 | return session 101 | 102 | 103 | def GetScreenSaver(): 104 | try: 105 | bus = dbus.SessionBus() 106 | screensaver = GetInterface(bus, 'ScreenSaver', '', '/ScreenSaver') 107 | except dbus.DBusException: 108 | logging.exception("Error retrieving ScreenSaver interface (ignore if " 109 | "running on GNOME).") 110 | screensaver = None 111 | return screensaver 112 | 113 | 114 | def LockSession(session): 115 | # First try to lock in the KDE "standard" interface. Since KDE is 116 | # using a session bus, all operations must be execued in the user 117 | # context. 118 | pid = os.fork() 119 | if pid == 0: 120 | os.environ['DISPLAY'] = session.GetX11Display() 121 | os.setuid(session.GetUnixUser()) 122 | screensaver = GetScreenSaver() 123 | if screensaver is not None: 124 | screensaver.Lock() 125 | exitcode = 0 126 | else: 127 | logging.info("KDE standard interface seems not to be supported") 128 | exitcode = 1 129 | os._exit(exitcode) 130 | 131 | result = os.waitpid(pid, 0) 132 | logging.debug("Process %d terminated (result = %s)", pid, result) 133 | 134 | # If our first try failed, try the GNOME "standard" interface. 135 | if result[1] != 0: 136 | logging.info("Attempting session lock via ConsoleKit/LoginD") 137 | session.Lock() 138 | 139 | 140 | def main(): 141 | if os.path.exists('/usr/bin/loginctl'): 142 | subprocess.call(['/usr/bin/loginctl', 'lock-sessions']) 143 | else: 144 | session = GetActiveSession() 145 | if session is not None: 146 | try: 147 | LockSession(session) 148 | logging.info("Session %s should be locked now.", 149 | session.GetId()) 150 | except dbus.DBusException: 151 | logging.exception("Error while trying to lock session.") 152 | else: 153 | logging.error("Error locking session (no active session).") 154 | 155 | 156 | if __name__ == '__main__': 157 | main() 158 | -------------------------------------------------------------------------------- /ovirt-guest-agent/LogoutActiveUser.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/python2 2 | # -*- coding: utf-8 -*- 3 | # vim:fenc=utf-8 4 | # 5 | # Copyright 2014 Vinzenz Feenstra, Red Hat, Inc. and/or its affiliates. 6 | # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); 8 | # you may not use this file except in compliance with the License. 9 | # You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # 19 | # Refer to the README and COPYING files for full details of the license. 20 | # 21 | import os 22 | import subprocess 23 | 24 | from LockActiveSession import GetActiveSession 25 | 26 | 27 | def LogoutUserGnome(session): 28 | pid = os.fork() 29 | if pid == 0: 30 | os.setuid(session.GetUnixUser()) 31 | os.environ['DISPLAY'] = session.GetX11Display() 32 | subprocess.call(['/usr/bin/gnome-session-save', '--force-logout']) 33 | else: 34 | os.waitpid(pid, 0) 35 | 36 | 37 | def LogoutUser(): 38 | session = GetActiveSession() 39 | if os.path.exists('/usr/bin/loginctl'): 40 | subprocess.call(['/usr/bin/loginctl', 'terminate-session', 41 | session.GetId()]) 42 | else: 43 | LogoutUserGnome(session) 44 | 45 | 46 | if __name__ == '__main__': 47 | LogoutUser() 48 | -------------------------------------------------------------------------------- /ovirt-guest-agent/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | SUBDIRS = pam consoleapps 3 | 4 | AGENT_NAME = ovirt-guest-agent 5 | 6 | agentdir=$(datadir)/ovirt-guest-agent 7 | agent_PYTHON= \ 8 | CredServer.py \ 9 | GuestAgentLinux2.py \ 10 | OVirtAgentLogic.py \ 11 | VirtIoChannel.py \ 12 | ovirt-guest-agent.py \ 13 | timezone.py \ 14 | hooks.py \ 15 | $(NULL) 16 | 17 | noinst_PYTHON=\ 18 | bytesio.py \ 19 | GuestAgentWin32.py \ 20 | setup.py \ 21 | WinFile.py \ 22 | OVirtGuestService.py \ 23 | $(NULL) 24 | 25 | dist_pkgdata_SCRIPTS= \ 26 | hibernate \ 27 | LockActiveSession.py \ 28 | LogoutActiveUser.py \ 29 | $(NULL) 30 | 31 | dbusconfdir=$(sysconfdir)/dbus-1/system.d 32 | dbusconf_DATA=org.ovirt.vdsm.Credentials.conf 33 | 34 | rulesdir=$(udevrulesdir) 35 | rules_DATA = 55-$(AGENT_NAME).rules 36 | 37 | 55-$(AGENT_NAME).rules: $(AGENT_NAME).rules 38 | cp $(AGENT_NAME).rules 55-$(AGENT_NAME).rules 39 | 40 | # Conditionally install the systemd service 41 | if HAVE_SYSTEMD 42 | systemdsystemunit_DATA = ovirt-guest-agent.service 43 | endif 44 | 45 | EXTRA_DIST= \ 46 | $(agent_DATA) \ 47 | $(agentconf_DATA) \ 48 | $(daemon_DATA) \ 49 | $(dbusconf_DATA) \ 50 | $(AGENT_NAME).rules \ 51 | ovirt-guest-agent.in \ 52 | ovirt-guest-agent.service \ 53 | ovirt-guest-agent.sles \ 54 | ovirt-guest-agent.el5.rules \ 55 | Makefile.el5 \ 56 | README-windows.txt \ 57 | win-guest-agent-build-exe.bat \ 58 | $(NULL) 59 | 60 | CLEANFILES = \ 61 | *~ \ 62 | 55-$(AGENT_NAME).rules \ 63 | $(NULL) 64 | 65 | MAINTAINERCLEANFILES = \ 66 | ovirt-guest-agent \ 67 | $(NULL) 68 | -------------------------------------------------------------------------------- /ovirt-guest-agent/Makefile.el5: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2010-2012 Red Hat, Inc. All rights reserved. 3 | # Use is subject to license terms. 4 | # 5 | 6 | FILES=ovirt-guest-agent.py OVirtAgentLogic.py VirtIoChannel.py \ 7 | GuestAgentLinux2.py hibernate bytesio.py ../configurations/default.conf \ 8 | ../configurations/default-logger.conf ../scripts/diskmapper/diskmapper.el5 9 | 10 | AGENTDIR=/usr/share/ovirt-guest-agent 11 | CONFDIR=/etc 12 | 13 | all: 14 | 15 | install: 16 | mkdir -p $(DESTDIR)$(AGENTDIR) 17 | mkdir -p $(DESTDIR)$(CONFDIR)/init.d 18 | mkdir -p $(DESTDIR)$(CONFDIR)/udev/rules.d 19 | mkdir -p $(DESTDIR)$(CONFDIR)/pam.d 20 | mkdir -p $(DESTDIR)$(CONFDIR)/security/console.apps 21 | cp $(FILES) $(DESTDIR)$(AGENTDIR) 22 | cp ../configurations/ovirt-guest-agent.conf $(DESTDIR)$(CONFDIR) 23 | cp ovirt-guest-agent $(DESTDIR)$(CONFDIR)/init.d 24 | cp ovirt-guest-agent.el5.rules $(DESTDIR)$(CONFDIR)/udev/rules.d/55-ovirt-guest-agent.rules 25 | cp pam/ovirt-shutdown $(DESTDIR)$(CONFDIR)/pam.d 26 | cp pam/ovirt-hibernate $(DESTDIR)$(CONFDIR)/pam.d 27 | cp consoleapps/ovirt-shutdown $(DESTDIR)$(CONFDIR)/security/console.apps 28 | cp consoleapps/ovirt-hibernate $(DESTDIR)$(CONFDIR)/security/console.apps 29 | 30 | uninstall: 31 | $(RM) $(DESTDIR)$(CONFDIR)/security/console.apps/ovirt-shutdown 32 | $(RM) $(DESTDIR)$(CONFDIR)/security/console.apps/ovirt-hibernate 33 | $(RM) $(DESTDIR)$(CONFDIR)/pam.d/ovirt-shutdown 34 | $(RM) $(DESTDIR)$(CONFDIR)/pam.d/ovirt-hibernate 35 | $(RM) $(DESTDIR)$(CONFDIR)/udev/rules.d/55-ovirt-guest-agent.rules 36 | $(RM) $(DESTDIR)$(CONFDIR)/init.d/ovirt-guest-agent 37 | $(RM) $(DESTDIR)$(CONFDIR)/ovirt-guest-agent.conf 38 | (cd $(DESTDIR)$(AGENTDIR); $(RM) $(FILES); cd ..; rmdir $(DESTDIR)$(AGENTDIR)) 39 | 40 | clean: 41 | $(RM) -f *~ *.pyc 42 | -------------------------------------------------------------------------------- /ovirt-guest-agent/OVirtGuestService.py: -------------------------------------------------------------------------------- 1 | # Windows service wrapper for oVirt Guest Agent 2 | # The service is converted into an exe-file with py2exe 3 | 4 | import ConfigParser 5 | import _winreg 6 | import cStringIO 7 | import io 8 | import logging 9 | import logging.config 10 | import os 11 | import os.path 12 | 13 | import servicemanager 14 | import win32evtlogutil 15 | import win32service 16 | import win32serviceutil 17 | 18 | from GuestAgentWin32 import WinVdsAgent 19 | 20 | 21 | AGENT_CONFIG = 'ovirt-guest-agent.ini' 22 | AGENT_DEFAULT_CONFIG = 'default.ini' 23 | AGENT_DEFAULT_LOG_CONFIG = 'default-logger.ini' 24 | 25 | # Values from WM_WTSSESSION_CHANGE message 26 | # (http://msdn.microsoft.com/en-us/library/aa383828.aspx) 27 | WTS_SESSION_LOGON = 0x5 28 | WTS_SESSION_LOGOFF = 0x6 29 | WTS_SESSION_LOCK = 0x7 30 | WTS_SESSION_UNLOCK = 0x8 31 | 32 | 33 | class OVirtGuestService(win32serviceutil.ServiceFramework): 34 | _svc_name_ = "OVirtGuestService" 35 | _svc_display_name_ = "OVirt Guest Agent Service" 36 | _svc_description_ = "OVirt Guest Agent Service" 37 | _svc_deps_ = ["EventLog"] 38 | 39 | def __init__(self, args): 40 | win32serviceutil.ServiceFramework.__init__(self, args) 41 | self._shutting_down = False 42 | 43 | global AGENT_CONFIG, AGENT_DEFAULT_CONFIG, AGENT_DEFAULT_LOG_CONFIG 44 | regKey = "System\\CurrentControlSet\\services\\%s" % self._svc_name_ 45 | hkey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, regKey) 46 | filePath = _winreg.QueryValueEx(hkey, "ImagePath")[0].replace('"', '') 47 | hkey.Close() 48 | if "PythonService.exe" in filePath: 49 | hkey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, 50 | "%s\\PythonClass" % regKey) 51 | filePath = _winreg.QueryValueEx(hkey, "")[0].replace('"', '') 52 | hkey.Close() 53 | filePath = os.path.dirname(filePath) 54 | self._install_dir = filePath 55 | AGENT_CONFIG = os.path.join(filePath, AGENT_CONFIG) 56 | AGENT_DEFAULT_CONFIG = os.path.join(filePath, AGENT_DEFAULT_CONFIG) 57 | AGENT_DEFAULT_LOG_CONFIG = os.path.join(filePath, 58 | AGENT_DEFAULT_LOG_CONFIG) 59 | 60 | cparser = ConfigParser.ConfigParser() 61 | if os.path.exists(AGENT_DEFAULT_LOG_CONFIG): 62 | cparser.read(AGENT_DEFAULT_LOG_CONFIG) 63 | cparser.read(AGENT_CONFIG) 64 | strio = cStringIO.StringIO() 65 | cparser.write(strio) 66 | bio = io.BytesIO(strio.getvalue()) 67 | logging.config.fileConfig(bio) 68 | bio.close() 69 | strio.close() 70 | 71 | # Overriding this method in order to accept session change notifications. 72 | def GetAcceptedControls(self): 73 | accepted = win32serviceutil.ServiceFramework.GetAcceptedControls(self) 74 | accepted |= win32service.SERVICE_ACCEPT_SESSIONCHANGE 75 | return accepted 76 | 77 | def SvcStop(self): 78 | self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING) 79 | self.vdsAgent.stop() 80 | 81 | def SvcDoRun(self): 82 | # Write a 'started' event to the event log... 83 | self.ReportEvent(servicemanager.PYS_SERVICE_STARTED) 84 | logging.info("Starting OVirt Guest Agent service") 85 | config = ConfigParser.ConfigParser() 86 | if os.path.exists(AGENT_DEFAULT_CONFIG): 87 | config.read(AGENT_DEFAULT_CONFIG) 88 | config.read(AGENT_CONFIG) 89 | 90 | self.vdsAgent = WinVdsAgent(config, install_dir=self._install_dir) 91 | self.vdsAgent.run() 92 | 93 | # and write a 'stopped' event to the event log (skip this step if the 94 | # computer is shutting down, because the event log might be down). 95 | if not self._shutting_down: 96 | self.ReportEvent(servicemanager.PYS_SERVICE_STOPPED) 97 | 98 | logging.info("Stopping OVirt Guest Agent service") 99 | 100 | def SvcShutdown(self): 101 | self._shutting_down = True 102 | self.vdsAgent.stop() 103 | 104 | def SvcSessionChange(self, event_type): 105 | if event_type == WTS_SESSION_LOGON: 106 | self.vdsAgent.sessionLogon() 107 | elif event_type == WTS_SESSION_LOGOFF: 108 | self.vdsAgent.sessionLogoff() 109 | elif event_type == WTS_SESSION_LOCK: 110 | self.vdsAgent.sessionLock() 111 | elif event_type == WTS_SESSION_UNLOCK: 112 | self.vdsAgent.sessionUnlock() 113 | 114 | def SvcOtherEx(self, control, event_type, data): 115 | if control == win32service.SERVICE_CONTROL_SESSIONCHANGE: 116 | self.SvcSessionChange(event_type) 117 | 118 | def ReportEvent(self, EventID): 119 | try: 120 | win32evtlogutil.ReportEvent( 121 | self._svc_name_, 122 | EventID, 123 | 0, # category 124 | servicemanager.EVENTLOG_INFORMATION_TYPE, 125 | (self._svc_name_, '')) 126 | except: 127 | logging.exception("Failed to write to the event log") 128 | 129 | 130 | if __name__ == '__main__': 131 | # Note that this code will not be run in the 'frozen' exe-file!!! 132 | win32serviceutil.HandleCommandLine(OVirtGuestService) 133 | -------------------------------------------------------------------------------- /ovirt-guest-agent/README-windows.txt: -------------------------------------------------------------------------------- 1 | oVirt Guest Agent for Windows - Howto setup devel environment 2 | =========================================================== 3 | Supported guest OSs: 4 | - xp (32) 5 | - windows 7 (32/64) 6 | - windows 8 (32/64) 7 | - windows 2003 (32/64/r2) 8 | - windows 2008 (64/r2) 9 | - windows 2012 (64) 10 | 11 | Please note that we always use the 32 bit python even on 64 bit platforms 12 | 13 | Requirements: 14 | ------------- 15 | 16 | Install Python 2.7.3 for Windows. 17 | (http://www.python.org/ftp/python/2.7.3/python-2.7.3.msi) 18 | 19 | Install Python for Windows extension (pywin32) version 221 for Python 2.7 20 | (https://sourceforge.net/projects/pywin32/files/pywin32/Build%20221/pywin32-221.win32-py2.7.exe/download) 21 | 22 | Optionally install py2exe if you want to build an executable file which 23 | doesn't require Python installation for running 24 | (http://sourceforge.net/projects/py2exe/files/py2exe/0.6.9/py2exe-0.6.9.win32-py2.7.exe/download) 25 | 26 | Source code modifications: 27 | -------------------------- 28 | 29 | Update the AGENT_CONFIG global variable in OVirtGuestService.py to point to 30 | right configuration location. 31 | 32 | Running the service: 33 | -------------------- 34 | 35 | > python OVirtGuestService.py install 36 | > net start OVirtGuestService 37 | 38 | Building executable file: 39 | ------------------------- 40 | 41 | > python setup.py py2exe -b 1 42 | -------------------------------------------------------------------------------- /ovirt-guest-agent/VirtIoChannel.py: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2010-2013 Red Hat, Inc. and/or its affiliates. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | # Refer to the README and COPYING files for full details of the license. 17 | # 18 | 19 | import locale 20 | import logging 21 | import os 22 | import platform 23 | import time 24 | import unicodedata 25 | 26 | 27 | # avoid pep8 warnings 28 | def import_json(): 29 | try: 30 | import json 31 | return json 32 | except ImportError: 33 | import simplejson 34 | return simplejson 35 | 36 | 37 | json = import_json() 38 | 39 | __REPLACEMENT_CHAR = u'\ufffd' 40 | # Set taken from http://www.w3.org/TR/xml11/#NT-RestrictedChar 41 | __RESTRICTED_CHARS = set(range(8 + 1))\ 42 | .union(set(range(0xB, 0xC + 1)))\ 43 | .union(set(range(0xE, 0x1F + 1)))\ 44 | .union(set(range(0x7F, 0x84 + 1)))\ 45 | .union(set(range(0x86, 0x9F + 1))) 46 | 47 | 48 | def _string_convert(str): 49 | """ 50 | This function tries to convert the given string to an unicode string 51 | """ 52 | if isinstance(str, unicode): 53 | return str 54 | try: 55 | return str.decode(locale.getpreferredencoding(), 'strict') 56 | except UnicodeError: 57 | try: 58 | return str.decode(locale.getpreferredencoding(), 'replace') 59 | except UnicodeError: 60 | # unrepresentable string 61 | return u'????' 62 | 63 | 64 | def _filter_xml_chars(u): 65 | """ 66 | The set of characters allowed in XML documents is described in 67 | http://www.w3.org/TR/xml11/#charsets 68 | 69 | "Char" is defined as any unicode character except the surrogate blocks, 70 | \ufffe and \uffff. 71 | "RestrictedChar" is defiend as the code points in __RESTRICTED_CHARS above 72 | 73 | It's a little hard to follow, but the uposhot is an XML document must 74 | contain only characters in Char that are not in RestrictedChar. 75 | 76 | Note that Python's xmlcharrefreplace option is not relevant here - 77 | that's about handling charaters which can't be encoded in a given charset 78 | encoding, not which aren't permitted in XML. 79 | """ 80 | def filter_xml_char(c): 81 | if ord(c) > 0x10ffff: 82 | return __REPLACEMENT_CHAR # Outside Unicode range 83 | elif unicodedata.category(c) == 'Cs': 84 | return __REPLACEMENT_CHAR # Surrogate pair code point 85 | elif ord(c) == 0xFFFE or ord(c) == 0xFFFF: 86 | return __REPLACEMENT_CHAR # Specifically excluded code points 87 | elif ord(c) in __RESTRICTED_CHARS: 88 | return __REPLACEMENT_CHAR 89 | else: 90 | return c 91 | if not isinstance(u, unicode): 92 | raise TypeError 93 | 94 | return ''.join(filter_xml_char(c) for c in u) 95 | 96 | 97 | def _filter_object(obj): 98 | """ 99 | Apply _filter_xml_chars and _string_check on all strings in the given 100 | object 101 | """ 102 | def filt(o): 103 | if isinstance(o, dict): 104 | return dict(map(filt, o.iteritems())) 105 | if isinstance(o, list): 106 | return map(filt, o) 107 | if isinstance(o, tuple): 108 | return tuple(map(filt, o)) 109 | if isinstance(o, basestring): 110 | return _filter_xml_chars(_string_convert(o)) 111 | return o 112 | 113 | return filt(obj) 114 | 115 | 116 | def get_vports(prefix): 117 | return (os.path.join(prefix, 'ovirt-guest-agent.0'), 118 | os.path.join(prefix, 'com.redhat.rhevm.vdsm')) 119 | 120 | 121 | class VirtIoStream(object): 122 | # Python on Windows 7 returns 'Microsoft' rather than 'Windows' as 123 | # documented. 124 | is_windows = platform.system() in ['Windows', 'Microsoft'] 125 | is_test = False 126 | 127 | def __init__(self, vport_prefix): 128 | if self.is_test: 129 | from test_port import get_test_port 130 | self._vport = get_test_port(vport_prefix) 131 | self._read = self._vport.read 132 | self._write = self._vport.write 133 | elif self.is_windows: 134 | from WinFile import WinFile 135 | self._vport = WinFile(get_vports(vport_prefix)) 136 | self._read = self._vport.read 137 | self._write = self._vport.write 138 | else: 139 | current_port, legacy_port = get_vports(vport_prefix) 140 | vport_name = current_port 141 | if os.path.exists(legacy_port): 142 | vport_name = legacy_port 143 | self._vport = os.open(vport_name, os.O_RDWR) 144 | self._read = self._os_read 145 | self._write = self._os_write 146 | 147 | def _os_read(self, size): 148 | return os.read(self._vport, size) 149 | 150 | def _os_write(self, buffer): 151 | return os.write(self._vport, buffer) 152 | 153 | def read(self, size): 154 | return self._read(size) 155 | 156 | def write(self, buffer): 157 | return self._write(buffer) 158 | 159 | 160 | class VirtIoChannel: 161 | def __init__(self, vport_name): 162 | self._stream = VirtIoStream(vport_name) 163 | self._buffer = '' 164 | 165 | def _readbuffer(self): 166 | buffer = self._stream.read(4096) 167 | if buffer: 168 | self._buffer += buffer 169 | else: 170 | # read() returns immediately (non-blocking) if no one is 171 | # listening on the other side of the virtio-serial port. 172 | # So in order not to be in a tight-loop and waste CPU 173 | # time, we just sleep for a while and hope someone will 174 | # be there when we will awake from our nap. 175 | time.sleep(1) 176 | 177 | def _readline(self): 178 | newline = self._buffer.find('\n') 179 | while newline < 0: 180 | self._readbuffer() 181 | newline = self._buffer.find('\n') 182 | if newline >= 0: 183 | line, self._buffer = self._buffer.split('\n', 1) 184 | else: 185 | line = None 186 | return line 187 | 188 | def _parseLine(self, line): 189 | try: 190 | args = json.loads(line.decode('utf8')) 191 | name = args['__name__'] 192 | del args['__name__'] 193 | except: 194 | name = None 195 | args = None 196 | return (name, args) 197 | 198 | def read(self): 199 | return self._parseLine(self._readline()) 200 | 201 | def write(self, name, args={}): 202 | if not isinstance(name, str): 203 | raise TypeError("1nd arg must be a str.") 204 | if not isinstance(args, dict): 205 | raise TypeError("2nd arg must be a dict.") 206 | args['__name__'] = name 207 | args = _filter_object(args) 208 | message = (json.dumps(args) + '\n').encode('utf8') 209 | while len(message) > 0: 210 | written = self._stream.write(message) 211 | logging.debug("Written %s" % message[:written]) 212 | message = message[written:] 213 | -------------------------------------------------------------------------------- /ovirt-guest-agent/WinFile.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # 3 | # Copyright 2011 Red Hat, Inc. and/or its affiliates. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | # Refer to the README and COPYING files for full details of the license. 18 | # 19 | import logging 20 | import time 21 | 22 | import pywintypes 23 | import win32con 24 | import win32event 25 | import win32file 26 | import win32security 27 | 28 | 29 | # Using Python's os.read() to do a blocking-read doesn't allow 30 | # to use os.write() on a different thread. This class overrides 31 | # this problem by using Windows's API. 32 | class WinFile(object): 33 | def _open_port(self, name): 34 | self._hfile = win32file.CreateFile( 35 | name, 36 | win32con.GENERIC_READ | win32con.GENERIC_WRITE, 37 | win32con.FILE_SHARE_READ | win32con.FILE_SHARE_WRITE, 38 | win32security.SECURITY_ATTRIBUTES(), 39 | win32con.OPEN_EXISTING, 40 | win32con.FILE_FLAG_OVERLAPPED, 41 | 0) 42 | 43 | def __init__(self, ports): 44 | current_port, legacy_port = ports 45 | try: 46 | try: 47 | self._open_port(current_port) 48 | except win32file.error: 49 | self._open_port(legacy_port) 50 | except win32file.error: 51 | logging.exception('Failed to connect to virtio channel') 52 | 53 | self._read_ovrlpd = pywintypes.OVERLAPPED() 54 | self._read_ovrlpd.hEvent = win32event.CreateEvent(None, True, False, 55 | None) 56 | self._write_ovrlpd = pywintypes.OVERLAPPED() 57 | self._write_ovrlpd.hEvent = win32event.CreateEvent(None, True, False, 58 | None) 59 | 60 | def read(self, n): 61 | (nr, buf) = (0, ()) 62 | try: 63 | (hr, buf) = win32file.ReadFile( 64 | self._hfile, 65 | win32file.AllocateReadBuffer(n), 66 | self._read_ovrlpd) 67 | nr = win32file.GetOverlappedResult(self._hfile, 68 | self._read_ovrlpd, 69 | True) 70 | except: 71 | logging.debug("Exception on reading from VirtIO", exc_info=True) 72 | # We do sleep here to avoid constant reads spike the CPU 73 | time.sleep(1) 74 | return buf[:nr] 75 | 76 | def write(self, s): 77 | try: 78 | win32file.WriteFile(self._hfile, s, self._write_ovrlpd) 79 | return win32file.GetOverlappedResult(self._hfile, 80 | self._write_ovrlpd, 81 | True) 82 | except: 83 | logging.debug("Exception writing to VirtIO", exc_info=True) 84 | # We do sleep here to avoid constant writes to spike the CPU 85 | time.sleep(1) 86 | return 0 87 | -------------------------------------------------------------------------------- /ovirt-guest-agent/bytesio.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python2 2 | 3 | class BytesIO: 4 | def __init__(self, buffer): 5 | self._data = buffer 6 | if not self._data: 7 | self._data = str() 8 | self._pos = 0 9 | 10 | def getvalue(self): 11 | return self._data 12 | 13 | def close(self): 14 | pass 15 | 16 | def readline(self): 17 | return self.read(self._data[self._pos:].find('\n') + 1) 18 | 19 | def read(self, n=None): 20 | if n == None: 21 | n = -1 22 | if not isinstance(n, (int, long)): 23 | raise TypeError("Argument must be an integer") 24 | if n < 0: 25 | n = len(self._data) 26 | if len(self._data) <= self._pos: 27 | return '' 28 | newpos = min(len(self._data), self._pos + n) 29 | b = self._data[self._pos : newpos] 30 | self._pos = newpos 31 | return b 32 | 33 | def readable(self): 34 | return True 35 | 36 | def writable(self): 37 | return True 38 | 39 | def seekable(self): 40 | return False 41 | -------------------------------------------------------------------------------- /ovirt-guest-agent/consoleapps/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | if INSTALL_USERMODE_SCRIPTS 3 | consoleappsdir = $(sysconfdir)/security/console.apps 4 | consoleapps_DATA = \ 5 | ovirt-container-list \ 6 | ovirt-shutdown \ 7 | ovirt-logout \ 8 | ovirt-locksession \ 9 | ovirt-hibernate \ 10 | ovirt-flush-caches \ 11 | $(NULL) 12 | endif 13 | 14 | EXTRA_DIST = \ 15 | ovirt-container-list \ 16 | ovirt-shutdown \ 17 | ovirt-logout \ 18 | ovirt-locksession \ 19 | ovirt-hibernate \ 20 | ovirt-flush-caches \ 21 | $(NULL) 22 | 23 | CLEANFILES = \ 24 | *~ 25 | 26 | MAINTAINERCLEANFILES = \ 27 | Makefile.in 28 | -------------------------------------------------------------------------------- /ovirt-guest-agent/consoleapps/ovirt-container-list: -------------------------------------------------------------------------------- 1 | PROGRAM=/usr/share/ovirt-guest-agent/container-list 2 | -------------------------------------------------------------------------------- /ovirt-guest-agent/consoleapps/ovirt-flush-caches: -------------------------------------------------------------------------------- 1 | PROGRAM=/usr/share/ovirt-guest-agent/scripts/hooks/defaults/flush-caches 2 | -------------------------------------------------------------------------------- /ovirt-guest-agent/consoleapps/ovirt-hibernate: -------------------------------------------------------------------------------- 1 | PROGRAM=/usr/share/ovirt-guest-agent/hibernate 2 | -------------------------------------------------------------------------------- /ovirt-guest-agent/consoleapps/ovirt-locksession: -------------------------------------------------------------------------------- 1 | PROGRAM=/usr/share/ovirt-guest-agent/LockActiveSession.py 2 | -------------------------------------------------------------------------------- /ovirt-guest-agent/consoleapps/ovirt-logout: -------------------------------------------------------------------------------- 1 | PROGRAM=/usr/share/ovirt-guest-agent/LogoutActiveUser.py 2 | -------------------------------------------------------------------------------- /ovirt-guest-agent/consoleapps/ovirt-shutdown: -------------------------------------------------------------------------------- 1 | PROGRAM=/sbin/shutdown 2 | -------------------------------------------------------------------------------- /ovirt-guest-agent/hibernate: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | usage() { 4 | echo "usage: $0 disk|mem" 5 | exit 1 6 | } 7 | 8 | state="$1" 9 | 10 | if [ "x$state" = "xdisk" ]; then 11 | param="hibernate" 12 | elif [ "x$state" = "xmem" ]; then 13 | param="suspend" 14 | else 15 | usage 16 | fi 17 | 18 | pm=`which pm-$param` 19 | 20 | if [ -x $pm ]; then 21 | $pm 22 | else 23 | echo $state > /sys/power/state 24 | fi 25 | -------------------------------------------------------------------------------- /ovirt-guest-agent/hooks.py: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016 Hat, Inc. and/or its affiliates. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | # Refer to the README and COPYING files for full details of the license. 17 | # 18 | 19 | import os 20 | import os.path 21 | import subprocess 22 | 23 | 24 | class UnknownHookError(LookupError): 25 | def __init__(self, hook_name): 26 | LookupError.__init__(self, 'Unknown hook "%s" requested' % hook_name) 27 | 28 | 29 | class Hooks(object): 30 | def __init__(self, log, hook_dir): 31 | self._hook_dir = hook_dir 32 | self._log = log 33 | 34 | def _find_hooks(self, name): 35 | """ Return a sorted list of hooks for the given hook name """ 36 | hooks_dir = os.path.join(self._hook_dir, name) 37 | files = os.listdir(hooks_dir) 38 | files.sort() 39 | return [os.path.join(hooks_dir, f) for f in files] 40 | 41 | def _execute(self, path): 42 | """ Executes the given path and returns return code and output """ 43 | try: 44 | proc = subprocess.Popen(path, stderr=subprocess.PIPE, 45 | stdout=subprocess.PIPE) 46 | out, err = proc.communicate() 47 | except OSError: 48 | self._log.warning('Executing %s failed', path, exc_info=True) 49 | return -1, '', '' 50 | return proc.returncode, out, err 51 | 52 | def _run(self, name): 53 | """ Executes all hooks which are currently configured for the given 54 | event 55 | """ 56 | for path in self._find_hooks(name): 57 | self._log.debug('Attempting to execute hook %s', path) 58 | retval, out, err = self._execute(path) 59 | if retval != 0: 60 | self._log.warning('Hook(%s) "%s" return non-zero exit code %d ' 61 | '\nSTDOUT:\n%sSTDERR:\n%s\n', name, path, 62 | retval, out, err) 63 | else: 64 | self._log.info('Hook(%s) "%s" executed', name, path) 65 | 66 | def dispatch(self, hook): 67 | """ Runtime dispatch of the hook by name """ 68 | func = getattr(self, hook, None) 69 | if func is not None: 70 | if callable(func): 71 | return func() 72 | raise UnknownHookError(hook) 73 | 74 | def before_hibernation(self): 75 | self._run('before_hibernation') 76 | 77 | def after_hibernation(self): 78 | self._run('after_hibernation') 79 | 80 | def before_migration(self): 81 | self._run('before_migration') 82 | 83 | def after_migration(self): 84 | self._run('after_migration') 85 | -------------------------------------------------------------------------------- /ovirt-guest-agent/org.ovirt.vdsm.Credentials.conf: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 14 | 15 | 16 | 17 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /ovirt-guest-agent/ovirt-guest-agent.el5.rules: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2010-2012 Red Hat, Inc. and/or its affiliates. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | # Refer to the README and COPYING files for full details of the license. 17 | # 18 | 19 | KERNEL=="vport*", SYSFS{name}=="com.redhat.rhevm.vdsm", OWNER="ovirtagent", GROUP="ovirtagent" 20 | KERNEL=="vport*", SYSFS{name}=="ovirt-guest-agent.0", OWNER="ovirtagent", GROUP="ovirtagent" 21 | -------------------------------------------------------------------------------- /ovirt-guest-agent/ovirt-guest-agent.in: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # ovirt-guest-agent - Startup script for the oVirt agent daemon 4 | # 5 | # chkconfig: 35 85 15 6 | # description: Startup/shutdown script for the oVirt agent. 7 | # processname: ovirt-guest-agent 8 | # config: /etc/ovirt-guest-agent.conf 9 | # pidfile: /var/run/ovirt-guest-agent.pid 10 | 11 | # Source function library. 12 | . /etc/rc.d/init.d/functions 13 | 14 | agentd=/usr/share/ovirt-guest-agent/ovirt-guest-agent.py 15 | prog=ovirt-guest-agent 16 | lockfile=@lock_dir@/${prog} 17 | pidfile=/var/run/${prog}.pid 18 | 19 | RETVAL=0 20 | 21 | start() { 22 | echo -n $"Starting $prog: " 23 | # RHEL5 doesn't automatically load the virtio serial module. 24 | if [ ! -d /dev/virtio-ports ]; then 25 | modprobe virtio_console >/dev/null 2>&1 26 | # Give udev some time to create the symbolic links. 27 | for retries in `seq 5`; do 28 | sleep 1 29 | [ -d /dev/virtio-ports ] && break 30 | done 31 | [ -f /sbin/udevtrigger ] && /sbin/udevtrigger 32 | fi 33 | # Create as root an empty pidfile for the agent. 34 | if [ ! -f ${pidfile} ]; then 35 | /bin/touch ${pidfile} 36 | /bin/chown ovirtagent:ovirtagent ${pidfile} 37 | [ -x /sbin/restorecon ] && /sbin/restorecon ${pidfile} 38 | fi 39 | daemon --pidfile=${pidfile} --user=ovirtagent $agentd -p ${pidfile} -d $OPTIONS 40 | RETVAL=$? 41 | [ $RETVAL -eq 0 ] && touch $lockfile 42 | echo 43 | return $RETVAL 44 | } 45 | 46 | stop() { 47 | echo -n $"Stopping $prog: " 48 | killproc -p ${pidfile} -d 10 $agentd 49 | RETVAL=$? 50 | [ $RETVAL -eq 0 ] && rm -f $lockfile 51 | echo 52 | } 53 | 54 | case "$1" in 55 | 56 | start) 57 | $0 status > /dev/null 2>&1 58 | if [ $? -ne 0 ]; then 59 | start 60 | fi 61 | ;; 62 | 63 | stop) 64 | $0 status > /dev/null 2>&1 65 | if [ $? -eq 0 ]; then 66 | stop 67 | fi 68 | ;; 69 | 70 | status) 71 | status -p ${pidfile} ${prog} 72 | RETVAL=$? 73 | ;; 74 | 75 | restart) 76 | $0 stop 77 | $0 start 78 | ;; 79 | 80 | condrestart) 81 | if [ -s ${pidfile} ] ; then 82 | $0 stop 83 | $0 start 84 | fi 85 | ;; 86 | 87 | *) 88 | echo $"Usage: $prog {start|stop|restart|condrestart|status}" 89 | exit 1 90 | esac 91 | 92 | exit $RETVAL 93 | -------------------------------------------------------------------------------- /ovirt-guest-agent/ovirt-guest-agent.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python2 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # Refer to the README and COPYING files for full details of the license. 16 | # 17 | 18 | import ConfigParser 19 | import cStringIO 20 | import getopt 21 | import logging 22 | import logging.config 23 | import os 24 | import signal 25 | import sys 26 | 27 | from GuestAgentLinux2 import LinuxVdsAgent 28 | 29 | 30 | io = None 31 | try: 32 | import io as modio 33 | io = modio 34 | except ImportError: 35 | import bytesio as modio 36 | io = modio 37 | 38 | 39 | AGENT_CONFIG = '/etc/ovirt-guest-agent.conf' 40 | AGENT_DEFAULT_CONFIG = '/usr/share/ovirt-guest-agent/default.conf' 41 | AGENT_DEFAULT_LOG_CONFIG = '/usr/share/ovirt-guest-agent/default-logger.conf' 42 | AGENT_PIDFILE = '/run/ovirt-guest-agent.pid' 43 | 44 | 45 | class OVirtAgentDaemon: 46 | 47 | def __init__(self): 48 | cparser = ConfigParser.ConfigParser() 49 | cparser.read(AGENT_DEFAULT_LOG_CONFIG) 50 | cparser.read(AGENT_CONFIG) 51 | strio = cStringIO.StringIO() 52 | cparser.write(strio) 53 | bio = io.BytesIO(strio.getvalue()) 54 | logging.config.fileConfig(bio) 55 | bio.close() 56 | strio.close() 57 | 58 | def run(self, daemon, pidfile): 59 | logging.info("Starting oVirt guest agent") 60 | config = ConfigParser.ConfigParser() 61 | config.read(AGENT_DEFAULT_CONFIG) 62 | config.read(AGENT_DEFAULT_LOG_CONFIG) 63 | config.read(AGENT_CONFIG) 64 | 65 | self.agent = LinuxVdsAgent(config) 66 | 67 | if daemon: 68 | self._daemonize() 69 | 70 | f = file(pidfile, "w") 71 | f.write("%s\n" % (os.getpid())) 72 | f.close() 73 | os.chmod(pidfile, 0644) # rw-rw-r-- (664) 74 | 75 | self.register_signal_handler() 76 | self.agent.run() 77 | 78 | logging.info("oVirt guest agent is down.") 79 | 80 | def _daemonize(self): 81 | if os.getppid() == 1: 82 | raise RuntimeError("already a daemon") 83 | pid = os.fork() 84 | if pid == 0: 85 | os.umask(0) 86 | os.setsid() 87 | os.chdir("/") 88 | self._reopen_file_as_null(sys.stdin) 89 | self._reopen_file_as_null(sys.stdout) 90 | self._reopen_file_as_null(sys.stderr) 91 | else: 92 | os._exit(0) 93 | 94 | def _reopen_file_as_null(self, oldfile): 95 | nullfile = file("/dev/null", "rw") 96 | os.dup2(nullfile.fileno(), oldfile.fileno()) 97 | nullfile.close() 98 | 99 | def register_signal_handler(self): 100 | 101 | def sigterm_handler(signum, frame): 102 | logging.debug("Handling signal %d" % (signum)) 103 | if signum == signal.SIGTERM: 104 | logging.info("Stopping oVirt guest agent") 105 | self.agent.stop() 106 | 107 | signal.signal(signal.SIGTERM, sigterm_handler) 108 | 109 | 110 | def usage(): 111 | print "Usage: %s [OPTION]..." % (sys.argv[0]) 112 | print "" 113 | print " -p, --pidfile\t\tset pid file name (default: %s)" % AGENT_PIDFILE 114 | print " -d\t\t\trun program as a daemon." 115 | print " -h, --help\t\tdisplay this help and exit." 116 | print "" 117 | 118 | 119 | if __name__ == '__main__': 120 | try: 121 | try: 122 | opts, args = getopt.getopt(sys.argv[1:], 123 | "?hp:d", ["help", "pidfile="]) 124 | pidfile = AGENT_PIDFILE 125 | daemon = False 126 | for opt, value in opts: 127 | if opt in ("-h", "-?", "--help"): 128 | usage() 129 | os._exit(2) 130 | elif opt in ("-p", "--pidfile"): 131 | pidfile = value 132 | elif opt in ("-d"): 133 | daemon = True 134 | agent = OVirtAgentDaemon() 135 | agent.run(daemon, pidfile) 136 | except getopt.GetoptError, err: 137 | print str(err) 138 | print "Try `%s --help' for more information." % (sys.argv[0]) 139 | os._exit(2) 140 | except: 141 | logging.exception("Unhandled exception in oVirt guest agent!") 142 | sys.exit(1) 143 | finally: 144 | try: 145 | os.unlink(AGENT_PIDFILE) 146 | except: 147 | pass 148 | -------------------------------------------------------------------------------- /ovirt-guest-agent/ovirt-guest-agent.rules: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2010 Red Hat, Inc. and/or its affiliates. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | # Refer to the README and COPYING files for full details of the license. 17 | # 18 | 19 | SYMLINK=="virtio-ports/com.redhat.rhevm.vdsm", OWNER="ovirtagent", GROUP="ovirtagent" 20 | SYMLINK=="virtio-ports/ovirt-guest-agent.0", OWNER="ovirtagent", GROUP="ovirtagent" 21 | 22 | -------------------------------------------------------------------------------- /ovirt-guest-agent/ovirt-guest-agent.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=oVirt Guest Agent 3 | Wants=qemu-guest-agent.service 4 | After=qemu-guest-agent.service 5 | 6 | [Service] 7 | Type=simple 8 | PIDFile=/run/ovirt-guest-agent.pid 9 | EnvironmentFile=-/etc/sysconfig/ovirt-guest-agent 10 | User=ovirtagent 11 | PermissionsStartOnly=true 12 | ExecStartPre=/sbin/modprobe virtio_console 13 | ExecStartPre=/bin/touch /run/ovirt-guest-agent.pid 14 | ExecStartPre=/bin/chown ovirtagent:ovirtagent /run/ovirt-guest-agent.pid 15 | ExecStart=/usr/bin/python2 /usr/share/ovirt-guest-agent/ovirt-guest-agent.py 16 | 17 | [Install] 18 | WantedBy=multi-user.target 19 | -------------------------------------------------------------------------------- /ovirt-guest-agent/ovirt-guest-agent.sles: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # SUSE system startup script for the ovirt-guest-agent daemon 4 | # Copyright (C) 1995--2005 Kurt Garloff, SUSE / Novell Inc. 5 | # Copyright (C) 2014 Vinzenz Feenstra, Red Hat Inc. 6 | # 7 | # This library is free software; you can redistribute it and/or modify it 8 | # under the terms of the GNU Lesser General Public License as published by 9 | # the Free Software Foundation; either version 2.1 of the License, or (at 10 | # your option) any later version. 11 | # 12 | # This library is distributed in the hope that it will be useful, but 13 | # WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | # Lesser General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU Lesser General Public 18 | # License along with this library; if not, write to the Free Software 19 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, 20 | # USA. 21 | # 22 | # /etc/init.d/ovirt-guest-agent 23 | # and its symbolic link 24 | # /(usr/)sbin/rcovirt-guest-agent 25 | # 26 | ### BEGIN INIT INFO 27 | # Provides: ovirt-guest-agent 28 | # Required-Start: 29 | # Should-Start: 30 | # Required-Stop: 31 | # Should-Stop: 32 | # Default-Start: 3 5 33 | # Default-Stop: 0 1 2 6 34 | # Short-Description: ovirt-guest-agent 35 | # Description: Start ovirt-guest-agent 36 | ### END INIT INFO 37 | 38 | 39 | # Check for missing binaries (stale symlinks should not happen) 40 | # Note: Special treatment of stop for LSB conformance 41 | ovirt_guest_agent_BIN=/usr/share/ovirt-guest-agent/ovirt-guest-agent.py 42 | test -x $ovirt_guest_agent_BIN || { echo "$ovirt_guest_agent_BIN not installed"; 43 | if [ "$1" = "stop" ]; then exit 0; 44 | else exit 5; fi; } 45 | 46 | . /etc/rc.status 47 | 48 | # Reset status of this service 49 | rc_reset 50 | 51 | pidfile=/var/run/ovirt-guest-agent.pid 52 | 53 | case "$1" in 54 | start) 55 | echo -n "Starting ovirt-guest-agent " 56 | if [ ! -d /dev/virtio-ports ]; then 57 | modprobe virtio_console > /dev/null 2>&1 58 | for retries in `seq 5`; do 59 | sleep 1 60 | [ -d /dev/virtio-ports ] && break 61 | done 62 | [ -f /sbin/udevadm ] && /sbin/udevadm trigger 63 | fi 64 | if [ ! -f ${pidfile} ]; then 65 | /bin/touch ${pidfile} 66 | /bin/chown ovirtagent:ovirtagent ${pidfile} 67 | fi 68 | 69 | /sbin/startproc -u ovirtagent -g ovirtagent $ovirt_guest_agent_BIN 70 | rc_status -v 71 | ;; 72 | stop) 73 | echo -n "Shutting down ovirt-guest-agent " 74 | /sbin/killproc -TERM $ovirt_guest_agent_BIN 75 | rc_status -v 76 | ;; 77 | try-restart) 78 | $0 status 79 | if test $? = 0; then 80 | $0 restart 81 | else 82 | rc_reset 83 | fi 84 | rc_status 85 | ;; 86 | restart) 87 | $0 stop 88 | $0 start 89 | rc_status 90 | ;; 91 | force-reload) 92 | echo -n "Reload service ovirt-guest-agent " 93 | /sbin/killproc -HUP $ovirt_guest_agent_BIN 94 | rc_status -v 95 | ;; 96 | reload) 97 | echo -n "Reload service ovirt-guest-agent " 98 | /sbin/killproc -HUP $ovirt_guest_agent_BIN 99 | rc_status -v 100 | ;; 101 | status) 102 | echo -n "Checking for service ovirt-guest-agent " 103 | /sbin/checkproc $ovirt_guest_agent_BIN 104 | rc_status -v 105 | ;; 106 | probe) 107 | test /etc/ovirt-guest-agent.conf -nt /var/run/ovirt-guest-agent.pid && echo reload 108 | ;; 109 | *) 110 | echo "Usage: $0 {start|stop|status|try-restart|restart|force-reload|reload|probe}" 111 | exit 1 112 | ;; 113 | esac 114 | 115 | rc_exit 116 | -------------------------------------------------------------------------------- /ovirt-guest-agent/pam/Makefile.am: -------------------------------------------------------------------------------- 1 | if INSTALL_USERMODE_SCRIPTS 2 | pamdir = $(PAM_PREFIX)/pam.d 3 | pam_DATA = \ 4 | ovirt-container-list \ 5 | ovirt-flush-caches \ 6 | ovirt-shutdown \ 7 | ovirt-logout \ 8 | ovirt-locksession \ 9 | ovirt-hibernate \ 10 | $(NULL) 11 | endif 12 | 13 | EXTRA_DIST = \ 14 | ovirt-container-list \ 15 | ovirt-flush-caches \ 16 | ovirt-shutdown \ 17 | ovirt-logout \ 18 | ovirt-locksession \ 19 | ovirt-hibernate \ 20 | $(NULL) 21 | 22 | CLEANFILES = \ 23 | *~ 24 | 25 | MAINTAINERCLEANFILES = \ 26 | Makefile.in 27 | -------------------------------------------------------------------------------- /ovirt-guest-agent/pam/ovirt-container-list: -------------------------------------------------------------------------------- 1 | #%PAM-1.0 2 | auth sufficient pam_succeed_if.so quiet_success user = ovirtagent 3 | auth required pam_deny.so 4 | account required pam_permit.so 5 | -------------------------------------------------------------------------------- /ovirt-guest-agent/pam/ovirt-flush-caches: -------------------------------------------------------------------------------- 1 | #%PAM-1.0 2 | auth sufficient pam_succeed_if.so user = ovirtagent 3 | auth required pam_deny.so 4 | account required pam_permit.so 5 | -------------------------------------------------------------------------------- /ovirt-guest-agent/pam/ovirt-hibernate: -------------------------------------------------------------------------------- 1 | #%PAM-1.0 2 | auth sufficient pam_succeed_if.so user = ovirtagent 3 | auth required pam_deny.so 4 | account required pam_permit.so 5 | -------------------------------------------------------------------------------- /ovirt-guest-agent/pam/ovirt-locksession: -------------------------------------------------------------------------------- 1 | #%PAM-1.0 2 | auth sufficient pam_succeed_if.so user = ovirtagent 3 | auth required pam_deny.so 4 | account required pam_permit.so 5 | -------------------------------------------------------------------------------- /ovirt-guest-agent/pam/ovirt-logout: -------------------------------------------------------------------------------- 1 | #%PAM-1.0 2 | auth sufficient pam_succeed_if.so user = ovirtagent 3 | auth required pam_deny.so 4 | account required pam_permit.so 5 | -------------------------------------------------------------------------------- /ovirt-guest-agent/pam/ovirt-shutdown: -------------------------------------------------------------------------------- 1 | #%PAM-1.0 2 | auth sufficient pam_succeed_if.so user = ovirtagent 3 | auth required pam_deny.so 4 | account required pam_permit.so 5 | -------------------------------------------------------------------------------- /ovirt-guest-agent/timezone.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/python2 2 | # -*- coding: utf-8 -*- 3 | # vim:fenc=utf-8 4 | # Copyright 2014 Vinzenz Feenstra, Red Hat, Inc. and/or its affiliates. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | # Refer to the README and COPYING files for full details of the license. 19 | # 20 | 21 | import os 22 | import os.path 23 | import platform 24 | import time 25 | 26 | 27 | _IS_WINDOWS = platform.system() in ('Windows', 'Microsoft') 28 | 29 | 30 | def _get_win_timezone_info(): 31 | try: 32 | import win32com.client 33 | from pywintypes import com_error 34 | wmi = win32com.client.Dispatch('WbemScripting.SWbemLocator') 35 | server = wmi.ConnectServer('.', 'root\cimv2') 36 | for tz in server.ExecQuery('SELECT * FROM Win32_TimeZone'): 37 | return (tz.StandardName, (tz.Bias + tz.StandardBias)) 38 | except (ImportError, AttributeError, com_error): 39 | pass 40 | return ('', 0) 41 | 42 | 43 | def _read_etc_timezone(): 44 | try: 45 | f = open('/etc/timezone', 'r') 46 | result = f.read().strip() 47 | f.close() 48 | except (OSError, IOError): 49 | return None 50 | return result 51 | 52 | 53 | def _parse_etc_sysconfig_clock(): 54 | try: 55 | f = open('/etc/sysconfig/clock', 'r') 56 | data = f.read().split('\n') 57 | f.close() 58 | except (OSError, IOError): 59 | return None 60 | for line in data: 61 | kv = line.split('=') 62 | if len(kv) == 2 and kv[0] == 'ZONE': 63 | return kv[1].replace('"', '') 64 | return None 65 | 66 | 67 | def _zoneinfo_to_tz(path): 68 | return '/'.join(path.split('/')[-2:]) 69 | 70 | 71 | def _split_etc_localtime_symlink(): 72 | return _zoneinfo_to_tz(os.readlink('/etc/localtime')) 73 | 74 | 75 | def _get_linux_offset(): 76 | return -time.timezone / 60 77 | 78 | 79 | def _get_name_linux(): 80 | result = None 81 | # is /etc/localtime a symlink? 82 | if os.path.islink('/etc/localtime'): 83 | result = _split_etc_localtime_symlink() 84 | # Debianoid 85 | if not result and os.path.exists('/etc/timezone'): 86 | result = _read_etc_timezone() 87 | # Pre-systemd RHEL/Fedora/CentOS 88 | if not result and os.path.exists('/etc/sysconfig/clock'): 89 | result = _parse_etc_sysconfig_clock() 90 | return result or '' 91 | 92 | 93 | def get_timezone_info(): 94 | if _IS_WINDOWS: 95 | return _get_win_timezone_info() 96 | return (_get_name_linux(), _get_linux_offset()) 97 | 98 | 99 | def get_name(): 100 | if _IS_WINDOWS: 101 | return _get_win_timezone_info()[0] 102 | return _get_name_linux() 103 | 104 | 105 | def _main(): 106 | print "Timezone info:", get_timezone_info() 107 | if _IS_WINDOWS: 108 | return 109 | if os.path.islink('/etc/localtime'): 110 | print '_split_etc_localtime_symlink =', _split_etc_localtime_symlink() 111 | if os.path.exists('/etc/sysconfig/clock'): 112 | print '_parse_etc_sysconfig_clock =', _parse_etc_sysconfig_clock() 113 | if os.path.exists('/etc/timezone'): 114 | print '_read_etc_timezone =', _read_etc_timezone() 115 | print 'get_name_linux =', _get_name_linux() 116 | 117 | 118 | if __name__ == '__main__': 119 | _main() 120 | -------------------------------------------------------------------------------- /pam-ovirt-cred/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | AM_CFLAGS = -I$(top_srcdir) -Wall -pedantic 3 | AM_LDFLAGS = -no-undefined -avoid-version -module 4 | 5 | securelibdir = $(SECUREDIR) 6 | securelib_LTLIBRARIES = pam_ovirt_cred.la 7 | 8 | pam_ovirt_cred_la_CFLAGS=-fPIC 9 | pam_ovirt_cred_la_LIBADD = -lpam 10 | pam_ovirt_cred_la_SOURCES = \ 11 | pam_ovirt_cred.c \ 12 | cred_channel.c 13 | 14 | CLEANFILES = *~ 15 | -------------------------------------------------------------------------------- /pam-ovirt-cred/cred_channel.c: -------------------------------------------------------------------------------- 1 | 2 | #include "config.h" 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #include 18 | 19 | #define CREDENTIAL_CHANNEL "x/tmp/ovirt-cred-channel" 20 | 21 | static int parse_credentials_buffer(const char *creds, 22 | size_t len, 23 | char **username, 24 | char **password) 25 | { 26 | char *domain; 27 | int user_len, pass_len; 28 | 29 | if (len < sizeof(int)) { 30 | return -1; 31 | } 32 | 33 | user_len = ntohl(*((int *)creds)); 34 | *username = strndup(creds + sizeof(int), user_len); 35 | if (*username == NULL) { 36 | return -1; 37 | } 38 | 39 | pass_len = len - sizeof(int) - user_len; 40 | *password = strndup(creds + sizeof(int) + user_len, pass_len); 41 | if (*password == NULL) { 42 | _pam_drop(*username); 43 | return -1; 44 | } 45 | 46 | domain = strchr(*username, '@'); 47 | if (domain != NULL) { 48 | *domain = '\0'; 49 | /* local/nis users doesn't have a domain. */ 50 | if (getpwnam(*username) == NULL) { 51 | *domain = '@'; 52 | } else { 53 | domain += 1; 54 | } 55 | } 56 | 57 | return 0; 58 | } 59 | 60 | static int set_sock_non_blocking(int sock) 61 | { 62 | int flags; 63 | 64 | if ((flags = fcntl(sock, F_GETFL)) == -1) { 65 | D(("fcntl(F_GETFL) failed.")); 66 | return -1; 67 | } 68 | 69 | if (fcntl(sock, F_SETFL, flags | O_NONBLOCK) == -1) { 70 | D(("fcntl(F_SETFL, O_NONBLOCK) failed.")); 71 | return -1; 72 | } 73 | 74 | return 0; 75 | } 76 | 77 | static int do_acquire_user_credentials(int sock, 78 | const char *ticket, 79 | char* creds, 80 | size_t *creds_len) 81 | { 82 | struct sockaddr_un remote; 83 | struct timeval timeout; 84 | int ret, len; 85 | fd_set rfds; 86 | 87 | memset(&remote, 0, sizeof(remote)); 88 | remote.sun_family = AF_UNIX; 89 | strncpy(remote.sun_path, CREDENTIAL_CHANNEL, sizeof(remote.sun_path) - 1); 90 | len = SUN_LEN(&remote); 91 | remote.sun_path[0] = '\0'; 92 | 93 | if (connect(sock, (struct sockaddr *)&remote, len) == -1) { 94 | D(("connect() failed.")); 95 | return -1; 96 | } 97 | 98 | if (set_sock_non_blocking(sock) == -1) { 99 | return -1; 100 | } 101 | 102 | do { 103 | ret = send(sock, ticket, strlen(ticket), 0); 104 | } while ((ret == -1) && (errno == EINTR)); 105 | 106 | if (ret == -1) { 107 | D(("send() failed.")); 108 | return -1; 109 | } 110 | 111 | do { 112 | FD_ZERO(&rfds); 113 | FD_SET(sock, &rfds); 114 | timeout.tv_sec = 3; 115 | timeout.tv_usec = 0; 116 | ret = select(sock + 1, &rfds, NULL, NULL, &timeout); 117 | } while ((ret == -1) && (errno == EINTR)); 118 | 119 | if (ret == -1) { 120 | D(("select() failed.")); 121 | return -1; 122 | } else if (ret == 0) { 123 | D(("recv() timeout.")); 124 | return -1; 125 | } 126 | 127 | if (FD_ISSET(sock, &rfds)) { 128 | do { 129 | ret = recv(sock, creds, *creds_len, 0); 130 | } while ((ret == -1) && (errno == EINTR)); 131 | } 132 | 133 | if (ret == -1) { 134 | D(("recv() failed.")); 135 | return -1; 136 | } 137 | 138 | *creds_len = ret; 139 | 140 | return 0; 141 | } 142 | 143 | int acquire_user_credentials(const char *ticket, 144 | char **username, 145 | char **password) 146 | { 147 | char creds[0x100]; 148 | size_t creds_len = sizeof(creds); 149 | int sock; 150 | int ret; 151 | 152 | sock = socket(AF_UNIX,SOCK_STREAM, 0); 153 | if (sock == -1) { 154 | D(("socket() failed.")); 155 | return -1; 156 | } 157 | 158 | ret = do_acquire_user_credentials(sock, ticket, creds, &creds_len); 159 | 160 | close(sock); 161 | 162 | if (ret == 0) { 163 | ret = parse_credentials_buffer(creds, creds_len, username, password); 164 | if (ret != 0) { 165 | D(("failed to parse credentials.")); 166 | } 167 | } else { 168 | D((" %s (errno = %d)", strerror(errno), errno)); 169 | } 170 | 171 | _pam_overwrite_n(creds, creds_len); 172 | 173 | return ret; 174 | } 175 | -------------------------------------------------------------------------------- /pam-ovirt-cred/pam_ovirt_cred.c: -------------------------------------------------------------------------------- 1 | /* pam_ovirt_cred module */ 2 | 3 | #include "config.h" 4 | 5 | #include 6 | #include 7 | 8 | #define PAM_SM_AUTH 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | extern int acquire_user_credentials(const char *token, 15 | char **username, 16 | char **password); 17 | 18 | PAM_EXTERN int 19 | pam_sm_authenticate(pam_handle_t *pamh, int flags, 20 | int argc, const char **argv) 21 | { 22 | char *token = NULL; 23 | const char * preset_user = NULL; 24 | char *username = NULL; 25 | char *password = NULL; 26 | int retval; 27 | 28 | D(("called.")); 29 | 30 | /* Request the authentication token via pam conversation */ 31 | retval = pam_prompt(pamh, PAM_PROMPT_ECHO_OFF, &token, "Token?"); 32 | if(retval != PAM_SUCCESS) { 33 | pam_syslog(pamh, LOG_ERR, "Failed to retrieve auth token: %s", 34 | pam_strerror(pamh, retval)); 35 | retval = PAM_USER_UNKNOWN; 36 | goto cleanup; 37 | } 38 | 39 | /* The conversation succeeded but we have retrieved an invalid value */ 40 | if (token == NULL) { 41 | pam_syslog(pamh, LOG_ERR, "Conversation result is an invalid token"); 42 | retval = PAM_USER_UNKNOWN; 43 | goto cleanup; 44 | } 45 | 46 | /* Retrieve the user credentials from the guest agent service */ 47 | if (acquire_user_credentials(token, &username, &password) != 0) { 48 | pam_syslog(pamh, LOG_ERR, "Failed to acquire user's credentials"); 49 | retval = PAM_USER_UNKNOWN; 50 | goto cleanup; 51 | } 52 | 53 | /* Ensure that the username retrieved and the preset user name are 54 | * identical, in case the username was provided 55 | * We don't want to unlock a screen which was locked for a different 56 | * user. 57 | */ 58 | retval = pam_get_item(pamh, PAM_USER, (void const **)&preset_user); 59 | if (retval == PAM_SUCCESS) { 60 | if(username && preset_user) { 61 | if(strcmp(username, preset_user) != 0) { 62 | pam_syslog(pamh, LOG_ERR, "Preset user [%s] is not the same" 63 | "as the retrieved user [%s]", preset_user, 64 | username); 65 | retval = PAM_CRED_UNAVAIL; 66 | goto cleanup; 67 | } 68 | } 69 | } 70 | 71 | /* Hand the username over to PAM */ 72 | retval = pam_set_item(pamh, PAM_USER, (const void *) username); 73 | if (retval != PAM_SUCCESS) { 74 | pam_syslog(pamh, LOG_ERR, "Username not set: %s", 75 | pam_strerror(pamh, retval)); 76 | goto cleanup; 77 | } 78 | 79 | /* Hand the password over to PAM */ 80 | retval = pam_set_item(pamh, PAM_AUTHTOK, (const void *) password); 81 | if (retval != PAM_SUCCESS) { 82 | pam_syslog(pamh, LOG_ERR, "Password not set: %s", 83 | pam_strerror(pamh, retval)); 84 | goto cleanup; 85 | } 86 | 87 | retval = PAM_SUCCESS; 88 | 89 | cleanup: 90 | /* We have to cleanup the token we have retrieved via the conversation */ 91 | if (token) { 92 | free(token); 93 | } 94 | _pam_overwrite(password); 95 | _pam_drop(password); 96 | _pam_drop(username); 97 | 98 | return retval; 99 | } 100 | 101 | PAM_EXTERN int 102 | pam_sm_setcred(pam_handle_t *pamh, int flags, 103 | int argc, const char **argv) 104 | { 105 | return PAM_SUCCESS; 106 | } 107 | 108 | #ifdef PAM_STATIC 109 | 110 | struct pam_module _pam_unix_auth_modstruct = { 111 | "pam_ovirt_cred", 112 | pam_sm_authenticate, 113 | pam_sm_setcred, 114 | NULL, 115 | NULL, 116 | NULL, 117 | NULL, 118 | }; 119 | 120 | #endif /* PAM_STATIC */ 121 | -------------------------------------------------------------------------------- /pam-ovirt-cred/test.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | extern int acquire_user_credentials(const char *token, 5 | char **username, 6 | char **password); 7 | 8 | int main(int argc,char **argv) 9 | { 10 | char *token = "token"; 11 | char *username = NULL; 12 | char *password = NULL; 13 | 14 | if (argc > 1) { 15 | token = argv[1]; 16 | } 17 | 18 | if (acquire_user_credentials(token, &username, &password) == 0) { 19 | free(username); 20 | free(password); 21 | } 22 | 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /scripts/Makefile.am: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2014 Red Hat, Inc. and/or its affiliates. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | # Refer to the README and COPYING files for full details of the license. 17 | # 18 | 19 | SUBDIRS = \ 20 | diskmapper \ 21 | wrappers \ 22 | $(NULL) 23 | 24 | osinfoscriptdir = $(pkgdatadir) 25 | osinfoscript_SCRIPTS= \ 26 | ovirt-osinfo \ 27 | container-list \ 28 | $(NULL) 29 | 30 | EXTRA_DIST= \ 31 | ovirt-osinfo \ 32 | container-list \ 33 | sudoers.ovirt-guest-agent \ 34 | $(NULL) 35 | 36 | if INSTALL_SUDO_SCRIPTS 37 | install-data-hook: 38 | $(MKDIR_P) $(DESTDIR)/$(sysconfdir)/sudoers.d 39 | $(INSTALL) -m 440 sudoers.ovirt-guest-agent $(DESTDIR)/$(sysconfdir)/sudoers.d/50_ovirt-guest-agent 40 | endif 41 | -------------------------------------------------------------------------------- /scripts/container-list: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python2 2 | 3 | import json 4 | import os.path 5 | import socket 6 | 7 | 8 | if 'container' in os.environ and os.environ['container'] == 'docker': 9 | _DOCKER_PATH = '/host/var/run/docker.sock' 10 | else: 11 | _DOCKER_PATH = '/var/run/docker.sock' 12 | 13 | 14 | def transform(container): 15 | TRANSFORM = (('Id', 'id'), ('Names', 'names'), ('Image', 'image'), 16 | ('Command', 'command'), ('Status', 'status')) 17 | result = {} 18 | for mapping in TRANSFORM: 19 | if mapping[0] in container: 20 | result[mapping[1]] = container[mapping[0]] 21 | return result 22 | 23 | 24 | def print_transformed(data): 25 | print json.dumps([transform(container) for container in json.loads(data)]), 26 | 27 | 28 | if os.path.exists(_DOCKER_PATH): 29 | try: 30 | s = socket.socket(socket.SOCK_STREAM, socket.AF_UNIX) 31 | s.connect(_DOCKER_PATH) 32 | s.send('GET /containers/json?all=true HTTP/1.0\r\n\r\n') 33 | sockfile = s.makefile() 34 | data = sockfile.read() 35 | idx = data.find('\r\n\r\n') 36 | if idx != -1: 37 | print_transformed(data[idx + 4:]) 38 | else: 39 | print '[]', 40 | except: 41 | print '[]', 42 | else: 43 | print '[]', 44 | -------------------------------------------------------------------------------- /scripts/diskmapper/Makefile.am: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2014 Red Hat, Inc. and/or its affiliates. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | # Refer to the README and COPYING files for full details of the license. 17 | # 18 | 19 | EXTRA_DIST=\ 20 | diskmapper.el5 \ 21 | diskmapper.libudev \ 22 | $(NULL) 23 | 24 | install-data-hook: 25 | $(MKDIR_P) $(DESTDIR)/$(pkgdatadir) 26 | $(INSTALL) -m 755 diskmapper.libudev $(DESTDIR)/$(pkgdatadir)/diskmapper 27 | -------------------------------------------------------------------------------- /scripts/diskmapper/diskmapper.el5: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Copyright 2014 Red Hat, Inc. and/or its affiliates. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | # Refer to the README and COPYING files for full details of the license. 18 | # 19 | 20 | 21 | for devname in `ls /sys/block`; do 22 | if [ -f /sys/block/$devname/device/serial ]; then 23 | serial=`cat /sys/block/$devname/device/serial` 24 | echo "/dev/$devname|$serial" 25 | fi 26 | done 27 | -------------------------------------------------------------------------------- /scripts/diskmapper/diskmapper.libudev: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python2 2 | # 3 | # Copyright 2014 Red Hat, Inc. and/or its affiliates. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | # Refer to the README and COPYING files for full details of the license. 18 | # 19 | 20 | from ctypes import CDLL, POINTER, c_ulonglong, c_char_p, c_int, Structure 21 | from ctypes.util import find_library 22 | 23 | 24 | class udev(Structure): 25 | pass 26 | 27 | 28 | class udev_enumerate(Structure): 29 | pass 30 | 31 | 32 | class udev_list_entry(Structure): 33 | pass 34 | 35 | 36 | class udev_device(Structure): 37 | pass 38 | 39 | 40 | udev_p = POINTER(udev) 41 | udev_enumerate_p = POINTER(udev_enumerate) 42 | udev_list_entry_p = POINTER(udev_list_entry) 43 | udev_device_p = POINTER(udev_device) 44 | dev_t = c_ulonglong 45 | 46 | 47 | _SIGNATURES = { 48 | 'udev': dict( 49 | new=([], udev_p), 50 | unref=([udev_p], None), 51 | ), 52 | 'udev_enumerate': dict( 53 | new=([udev_p], udev_enumerate_p), 54 | unref=([udev_enumerate_p], None), 55 | add_match_subsystem=([udev_enumerate_p, c_char_p], c_int), 56 | add_match_property=([udev_enumerate_p, c_char_p, c_char_p], c_int), 57 | scan_devices=([udev_enumerate_p], c_int), 58 | get_list_entry=([udev_enumerate_p], udev_list_entry_p) 59 | ), 60 | 'udev_list_entry': dict( 61 | get_next=([udev_list_entry_p], udev_list_entry_p), 62 | get_name=([udev_list_entry_p], c_char_p), 63 | ), 64 | 'udev_device': dict( 65 | new_from_syspath=([udev_p, c_char_p], udev_device_p), 66 | unref=([udev_device_p], None), 67 | get_devtype=([udev_device_p], c_char_p), 68 | get_devnode=([udev_device_p], c_char_p), 69 | get_property_value=([udev_device_p, c_char_p], c_char_p) 70 | ) 71 | } 72 | 73 | 74 | def load_udev(): 75 | libudev_name = find_library("udev") 76 | ludev = CDLL(libudev_name, use_errno=True) 77 | for cls, funcs in _SIGNATURES.iteritems(): 78 | for name, signature in funcs.iteritems(): 79 | f = getattr(ludev, '%s_%s' % (cls, name)) 80 | if f: 81 | (argtypes, restype) = signature 82 | f.argtypes = argtypes 83 | f.restype = restype 84 | else: 85 | print 'Couldn\'t load', '%s_%s' % (cls, name) 86 | return ludev 87 | 88 | if __name__ == '__main__': 89 | ludev = load_udev() 90 | udev = ludev.udev_new() 91 | udevenum = ludev.udev_enumerate_new(udev) 92 | try: 93 | ludev.udev_enumerate_add_match_subsystem(udevenum, "block") 94 | ludev.udev_enumerate_scan_devices(udevenum) 95 | devices = ludev.udev_enumerate_get_list_entry(udevenum) 96 | entry = devices 97 | while entry: 98 | name = ludev.udev_list_entry_get_name(entry) 99 | dev = ludev.udev_device_new_from_syspath(udev, name) 100 | devtype = ludev.udev_device_get_devtype(dev) 101 | if devtype == "disk": 102 | devnode = ludev.udev_device_get_devnode(dev) 103 | serial = ludev.udev_device_get_property_value(dev, "ID_SERIAL") 104 | if serial: 105 | print '%s|%s' % (devnode, serial) 106 | entry = ludev.udev_list_entry_get_next(entry) 107 | finally: 108 | ludev.udev_enumerate_unref(udevenum) 109 | ludev.udev_unref(udev) 110 | -------------------------------------------------------------------------------- /scripts/ovirt-osinfo: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python2 2 | 3 | import platform 4 | 5 | arch_replace = { 6 | 'i686': 'x86', 7 | 'i586': 'x86', 8 | 'i386': 'x86'} 9 | 10 | 11 | def get_arch(): 12 | arch = platform.uname()[-2].lower().strip() 13 | if arch in arch_replace: 14 | return arch_replace[arch] 15 | return arch 16 | 17 | 18 | try: 19 | info = platform.linux_distribution() 20 | except AttributeError: 21 | info = platform.dist() 22 | if info[0] == 'redhat': 23 | try: 24 | f = open('/etc/redhat-release', 'r') 25 | r = f.read().split(' release ', 1) 26 | f.close() 27 | info = (r[0],) + info[1:] 28 | except IOError: 29 | pass 30 | 31 | print 'distribution=%s' % info[0] 32 | print 'version=%s' % info[1] 33 | print 'codename=%s' % info[2] 34 | print 'arch=%s' % get_arch() 35 | print 'kernel=%s' % platform.release() 36 | print 'type=linux' 37 | -------------------------------------------------------------------------------- /scripts/sudoers.ovirt-guest-agent: -------------------------------------------------------------------------------- 1 | Cmnd_Alias OVIRTAGENT_SCRIPTS =\ 2 | /usr/share/ovirt-guest-agent/ovirt-hibernate-wrapper.sh *,\ 3 | /usr/share/ovirt-guest-agent/ovirt-shutdown-wrapper.sh *,\ 4 | /usr/share/ovirt-guest-agent/ovirt-container-list-wrapper.sh,\ 5 | /usr/share/ovirt-guest-agent/ovirt-locksession-wrapper.sh,\ 6 | /usr/share/ovirt-guest-agent/scripts/hooks/defaults/ovirt-flush-caches-wrapper.sh 7 | 8 | ovirtagent ALL= NOPASSWD: OVIRTAGENT_SCRIPTS 9 | Defaults:ovirtagent !requiretty 10 | Defaults:ovirtagent !syslog 11 | -------------------------------------------------------------------------------- /scripts/wrappers/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | EXTRA_DIST = \ 3 | ovirt-container-list-wrapper.sh \ 4 | ovirt-hibernate-wrapper.sh \ 5 | ovirt-logout-wrapper.sh \ 6 | ovirt-locksession-wrapper.sh \ 7 | ovirt-shutdown-wrapper.sh \ 8 | ovirt-flush-caches-wrapper.sh \ 9 | ovirt-sudo-wrapper.sh \ 10 | $(NULL) 11 | 12 | CLEANFILES = \ 13 | *~ 14 | 15 | if INSTALL_SUDO_SCRIPTS 16 | sudoscriptsdir = $(pkgdatadir) 17 | sudoscripts_SCRIPTS= \ 18 | ovirt-sudo-wrapper.sh \ 19 | ovirt-container-list-wrapper.sh \ 20 | ovirt-hibernate-wrapper.sh \ 21 | ovirt-logout-wrapper.sh \ 22 | ovirt-shutdown-wrapper.sh \ 23 | ovirt-locksession-wrapper.sh \ 24 | ovirt-flush-caches-wrapper.sh \ 25 | $(NULL) 26 | 27 | install-exec-hook: 28 | $(LN_S) -f $(pkgdatadir)/ovirt-sudo-wrapper.sh $(DESTDIR)/$(pkgdatadir)/ovirt-container-list 29 | $(LN_S) -f $(pkgdatadir)/ovirt-sudo-wrapper.sh $(DESTDIR)/$(pkgdatadir)/ovirt-hibernate 30 | $(LN_S) -f $(pkgdatadir)/ovirt-sudo-wrapper.sh $(DESTDIR)/$(pkgdatadir)/ovirt-locksession 31 | $(LN_S) -f $(pkgdatadir)/ovirt-sudo-wrapper.sh $(DESTDIR)/$(pkgdatadir)/ovirt-shutdown 32 | $(LN_S) -f $(pkgdatadir)/ovirt-sudo-wrapper.sh $(DESTDIR)/$(pkgdatadir)/ovirt-logout 33 | $(LN_S) -f $(pkgdatadir)/ovirt-sudo-wrapper.sh $(DESTDIR)/$(pkgdatadir)/ovirt-flush-caches 34 | endif 35 | 36 | if INSTALL_USERMODE_SCRIPTS 37 | install-exec-hook: 38 | $(LN_S) -f $(bindir)/consolehelper $(DESTDIR)/$(pkgdatadir)/ovirt-container-list 39 | $(LN_S) -f $(bindir)/consolehelper $(DESTDIR)/$(pkgdatadir)/ovirt-locksession 40 | $(LN_S) -f $(bindir)/consolehelper $(DESTDIR)/$(pkgdatadir)/ovirt-shutdown 41 | $(LN_S) -f $(bindir)/consolehelper $(DESTDIR)/$(pkgdatadir)/ovirt-hibernate 42 | $(LN_S) -f $(bindir)/consolehelper $(DESTDIR)/$(pkgdatadir)/ovirt-logout 43 | $(LN_S) -f $(bindir)/consolehelper $(DESTDIR)/$(pkgdatadir)/ovirt-flush-caches 44 | endif 45 | -------------------------------------------------------------------------------- /scripts/wrappers/ovirt-container-list-wrapper.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Copyright (C) 2014 Vinzenz Feenstra, Red Hat, Inc. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | # Refer to the README and COPYING files for full details of the license. 18 | # 19 | 20 | /usr/share/ovirt-guest-agent/container-list 21 | 22 | 23 | -------------------------------------------------------------------------------- /scripts/wrappers/ovirt-flush-caches-wrapper.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Copyright (C) 2016 Vinzenz Feenstra, Red Hat, Inc. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | # Refer to the README and COPYING files for full details of the license. 18 | # 19 | 20 | /usr/share/ovirt-guest-agent/scripts/hooks/defaults/flush-caches 21 | 22 | 23 | -------------------------------------------------------------------------------- /scripts/wrappers/ovirt-hibernate-wrapper.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Copyright (C) 2014 Vinzenz Feenstra, Red Hat, Inc. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | # Refer to the README and COPYING files for full details of the license. 18 | # 19 | 20 | /usr/share/ovirt-guest-agent/hibernate $@ 21 | 22 | 23 | -------------------------------------------------------------------------------- /scripts/wrappers/ovirt-locksession-wrapper.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Copyright (C) 2014 Vinzenz Feenstra, Red Hat, Inc. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | # Refer to the README and COPYING files for full details of the license. 18 | # 19 | 20 | /usr/share/ovirt-guest-agent/LockActiveSession.py $@ &> /dev/null 21 | 22 | 23 | -------------------------------------------------------------------------------- /scripts/wrappers/ovirt-logout-wrapper.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Copyright (C) 2014 Vinzenz Feenstra, Red Hat, Inc. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | # Refer to the README and COPYING files for full details of the license. 18 | # 19 | 20 | /usr/share/ovirt-guest-agent/LogoutActiveUser.py $@ &> /dev/null 21 | 22 | 23 | -------------------------------------------------------------------------------- /scripts/wrappers/ovirt-shutdown-wrapper.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Copyright (C) 2014 Vinzenz Feenstra, Red Hat, Inc. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | # Refer to the README and COPYING files for full details of the license. 18 | # 19 | 20 | /sbin/shutdown $@ 21 | 22 | 23 | -------------------------------------------------------------------------------- /scripts/wrappers/ovirt-sudo-wrapper.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Copyright (C) 2014 Vinzenz Feenstra, Red Hat, Inc. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | # Refer to the README and COPYING files for full details of the license. 18 | # 19 | 20 | sudo "/usr/share/ovirt-guest-agent/`basename $0`-wrapper.sh" $@ 21 | 22 | 23 | -------------------------------------------------------------------------------- /tests/Makefile.am: -------------------------------------------------------------------------------- 1 | AM_TESTS_ENVIRONMENT=PYTHONPATH=$(PYTHONPATH):$(top_srcdir)/ovirt-guest-agent:$(top_srcdir)/tests; export PYTHONPATH; 2 | LOG_COMPILER=$(PYTHON) 3 | AM_LOG_FLAGS=$(top_srcdir)/tests/testrunner.py 4 | 5 | TESTS=\ 6 | encoding_test.py \ 7 | guest_agent_test.py \ 8 | $(NULL) 9 | 10 | EXTRA_DIST= \ 11 | encoding_test.py \ 12 | guest_agent_test.py \ 13 | message_validator.py \ 14 | test_port.py \ 15 | testrunner.py \ 16 | unittest.bat \ 17 | $(NULL) 18 | 19 | -------------------------------------------------------------------------------- /tests/encoding_test.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/python2 2 | # -*- coding: utf-8 -*- 3 | # vim:fenc=utf-8 4 | 5 | from testrunner import GuestAgentTestCase as TestCaseBase 6 | from VirtIoChannel import _filter_object 7 | 8 | 9 | class EncodingTest(TestCaseBase): 10 | 11 | def testNonUnicodeKeyInput(self): 12 | non_unicode_key = {'non-unicode-key': u'unicode value'} 13 | self.assertEquals({u'non-unicode-key': u'unicode value'}, 14 | _filter_object(non_unicode_key)) 15 | 16 | def testNonUnicodeValueInput(self): 17 | non_unicode_value = {u'unicode-key': 'non-unicode value'} 18 | self.assertEquals({u'unicode-key': u'non-unicode value'}, 19 | _filter_object(non_unicode_value)) 20 | 21 | def testWindowsFailureOnValidValue(self): 22 | VALID = u'\u0F65' 23 | self.assertEquals(VALID, _filter_object(VALID)) 24 | 25 | def testNullChar(self): 26 | non_unicode_value = {u'unicode-key': '\x00'} 27 | self.assertEquals({u'unicode-key': u'\ufffd'}, 28 | _filter_object(non_unicode_value)) 29 | 30 | def testIllegalUnicodeInput(self): 31 | ILLEGAL_DATA = {u'foo': u'\x00data\x00test\uffff\ufffe\udc79\ud800'} 32 | EXPECTED = {u'foo': u'\ufffddata\ufffdtest\ufffd\ufffd\ufffd\ufffd'} 33 | self.assertEqual(EXPECTED, _filter_object(ILLEGAL_DATA)) 34 | 35 | def testIllegalUnicodeCharacters(self): 36 | INVALID = (u'\u0000', u'\ufffe', u'\uffff', u'\ud800', u'\udc79', 37 | u'\U00000000', '\x00', '\x01', '\x02', '\x03', '\x04', 38 | '\x05') 39 | for invchar in INVALID: 40 | self.assertEqual(u'\ufffd', _filter_object(invchar)) 41 | 42 | def testLegalUnicodeCharacters(self): 43 | LEGAL = (u'\u2122', u'Hello World') 44 | for legalchar in LEGAL: 45 | self.assertEqual(legalchar, _filter_object(legalchar)) 46 | -------------------------------------------------------------------------------- /tests/guest_agent_test.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/python2 2 | # -*- coding: utf-8 -*- 3 | # vim:fenc=utf-8 4 | 5 | 6 | from ConfigParser import ConfigParser 7 | import os.path 8 | import platform 9 | 10 | from message_validator import MessageValidator 11 | from testrunner import GuestAgentTestCase 12 | 13 | import test_port 14 | 15 | 16 | def _get_scripts_path(): 17 | scriptdir = os.path.dirname(__file__) 18 | return os.path.abspath(os.path.join(scriptdir, '../scripts')) 19 | 20 | 21 | def _linux_setup_test(conf): 22 | port_name = 'linux-functional-test-port' 23 | conf.set('general', 'applications_list', 24 | 'kernel ovirt-guest-agent xorg-x11-drv-qxl ' 25 | 'linux-image xserver-xorg-video-qxl') 26 | conf.set('general', 'ignored_fs', 27 | 'rootfs tmpfs autofs cgroup selinuxfs udev mqueue ' 28 | 'nfds proc sysfs devtmpfs hugetlbfs rpc_pipefs devpts ' 29 | 'securityfs debugfs binfmt_misc fuse.gvfsd-fuse ' 30 | 'fuse.gvfs-fuse-daemon fusectl usbfs') 31 | conf.set('general', 'ignore_zero_size_fs', 'true') 32 | conf.set('general', 'ignored_nics', 'docker0') 33 | import GuestAgentLinux2 34 | GuestAgentLinux2._GUEST_SCRIPTS_INSTALL_PATH = _get_scripts_path() 35 | return port_name, GuestAgentLinux2.LinuxVdsAgent 36 | 37 | 38 | def _win32_setup_test(conf): 39 | port_name = "windows-functional-test-port" 40 | from GuestAgentWin32 import WinVdsAgent 41 | return port_name, WinVdsAgent 42 | 43 | 44 | class FunctionalTest(GuestAgentTestCase): 45 | def setUp(self): 46 | self._config = ConfigParser() 47 | self._config.add_section('general') 48 | self._config.add_section('virtio') 49 | 50 | agent_class = None 51 | if platform.system() in ['Windows', 'Microsoft']: 52 | self._vport_name, agent_class = _win32_setup_test(self._config) 53 | else: 54 | self._vport_name, agent_class = _linux_setup_test(self._config) 55 | 56 | self._validator = MessageValidator(self._vport_name) 57 | self._vport = self._validator.port() 58 | test_port.add_test_port(self._vport_name, self._vport) 59 | 60 | self._config.set('general', 'heart_beat_rate', '5') 61 | self._config.set('general', 'report_user_rate', '10') 62 | self._config.set('general', 'report_num_cpu_rate', '60') 63 | self._config.set('general', 'report_application_rate', '120') 64 | self._config.set('general', 'report_disk_usage', '300') 65 | self._config.set('virtio', 'device_prefix', self._vport_name) 66 | 67 | self.vdsAgent = agent_class(self._config) 68 | 69 | def testRefresh(self): 70 | self._validator.verifyRefreshReply(self.vdsAgent) 71 | 72 | def testRefresh2(self): 73 | self._validator.verifyRefreshReply2(self.vdsAgent) 74 | 75 | def testRefresh3(self): 76 | self._validator.verifyRefreshReply3(self.vdsAgent) 77 | 78 | def testRefresh4(self): 79 | self._validator.verifyRefreshReply4(self.vdsAgent) 80 | 81 | def testRefresh5(self): 82 | self._validator.verifyRefreshReply5(self.vdsAgent) 83 | 84 | def testRefresh6(self): 85 | self._validator.verifyRefreshReply6(self.vdsAgent) 86 | 87 | def testSendInfo(self): 88 | self._validator.verifySendInfo(self.vdsAgent) 89 | 90 | def testSendAppList(self): 91 | self._validator.verifySendAppList(self.vdsAgent) 92 | 93 | def testSendDisksUsages(self): 94 | self._validator.verifySendDisksUsages(self.vdsAgent) 95 | 96 | def testSendMemoryStats(self): 97 | self._validator.verifySendMemoryStats(self.vdsAgent) 98 | 99 | def testSendFQDN(self): 100 | self._validator.verifySendFQDN(self.vdsAgent) 101 | 102 | def testSendUserInfo(self): 103 | self._validator.verifySendUserInfo(self.vdsAgent) 104 | 105 | def testSendNumberOfCPUs(self): 106 | self._validator.verifySendNumberOfCPUs(self.vdsAgent) 107 | 108 | def testSessionLogon(self): 109 | self._validator.verifySessionLogon(self.vdsAgent) 110 | 111 | def testSessionLogoff(self): 112 | self._validator.verifySessionLogon(self.vdsAgent) 113 | 114 | def testSessionLock(self): 115 | self._validator.verifySessionLock(self.vdsAgent) 116 | 117 | def testSessionUnlock(self): 118 | self._validator.verifySessionUnlock(self.vdsAgent) 119 | 120 | def testSessionStartup(self): 121 | self._validator.verifySessionStartup(self.vdsAgent) 122 | 123 | def testSessionShutdown(self): 124 | self._validator.verifySessionShutdown(self.vdsAgent) 125 | 126 | def testAPIVersion(self): 127 | self._validator.verifyAPIVersion(self.vdsAgent) 128 | 129 | def testAPIVersion2(self): 130 | self._validator.verifyAPIVersion2(self.vdsAgent) 131 | -------------------------------------------------------------------------------- /tests/test_port.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/python2 2 | # -*- coding: utf-8 -*- 3 | # vim:fenc=utf-8 4 | 5 | 6 | class TestPort(object): 7 | def __init__(self, vport_name, *args, **kwargs): 8 | self._vport_name = vport_name 9 | 10 | def write(buffer): 11 | return len(buffer) 12 | 13 | def read(size): 14 | return "" 15 | 16 | 17 | _registered_ports = {} 18 | 19 | 20 | def get_test_port(vport_name): 21 | return _registered_ports.get(vport_name, TestPort(vport_name)) 22 | 23 | 24 | def add_test_port(vport_name, port): 25 | assert(isinstance(port, TestPort)) 26 | _registered_ports[vport_name] = port 27 | -------------------------------------------------------------------------------- /tests/testrunner.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/python2 2 | # -*- coding: utf-8 -*- 3 | 4 | import logging 5 | import os 6 | import sys 7 | import unittest 8 | 9 | from nose import config 10 | from nose import core 11 | from nose import result 12 | 13 | from VirtIoChannel import VirtIoStream 14 | 15 | 16 | class GuestAgentTestCase(unittest.TestCase): 17 | def __init__(self, *args, **kwargs): 18 | unittest.TestCase.__init__(self, *args, **kwargs) 19 | self.log = logging.getLogger(self.__class__.__name__) 20 | 21 | def assertRaises(self, exceptions, callable, *args, **kwargs): 22 | passed = False 23 | try: 24 | callable(*args, **kwargs) 25 | except exceptions: 26 | passed = True 27 | self.assertTrue(passed) 28 | 29 | 30 | class GuestAgentTestRunner(core.TextTestRunner): 31 | def __init__(self, *args, **kwargs): 32 | core.TextTestRunner.__init__(self, *args, **kwargs) 33 | 34 | def _makeResult(self): 35 | return result.TextTestResult(self.stream, 36 | self.descriptions, 37 | self.verbosity, 38 | self.config) 39 | 40 | def run(self, test): 41 | result_ = core.TextTestRunner.run(self, test) 42 | return result_ 43 | 44 | 45 | def run(): 46 | argv = sys.argv 47 | stream = sys.stdout 48 | verbosity = 3 49 | testdir = os.path.dirname(os.path.abspath(__file__)) 50 | 51 | conf = config.Config(stream=stream, 52 | env=os.environ, 53 | verbosity=verbosity, 54 | workingDir=testdir, 55 | plugins=core.DefaultPluginManager()) 56 | 57 | runner = GuestAgentTestRunner(stream=conf.stream, 58 | verbosity=conf.verbosity, 59 | config=conf) 60 | 61 | sys.exit(not core.run(config=conf, testRunner=runner, argv=argv)) 62 | 63 | 64 | if __name__ == '__main__': 65 | # We're ensuring VirtIoStream is monkey patched to unit test output mode 66 | # which requires no VirtIO Channel to be present 67 | VirtIoStream.is_test = True 68 | run() 69 | -------------------------------------------------------------------------------- /tests/unittest.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | REM Run unittests for Windows 3 | 4 | set PYTHONPATH=%PYTHONPATH%;../ovirt-guest-agent;.; 5 | python testrunner.py guest_agent_test.py encoding_test.py 6 | -------------------------------------------------------------------------------- /windows-credprov/CredentialsChannel.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Pch.h" 3 | 4 | #include "CredentialsChannel.h" 5 | 6 | static LPCTSTR lpszPipeName = "\\\\.\\pipe\\VDSMDPipe"; 7 | static const DWORD dwPipeBuffer = 1024; 8 | 9 | static inline unsigned long _ntohl(unsigned long n) 10 | { 11 | return ((n & 0xFF) << 24) | ((n & 0xFF00) << 8) | ((n & 0xFF0000) >> 8) | ((n & 0xFF000000) >> 24); 12 | } 13 | 14 | static inline BOOL SafeCloseHandle(HANDLE& hObject) 15 | { 16 | BOOL bRet = TRUE; 17 | 18 | if (hObject != INVALID_HANDLE_VALUE) 19 | { 20 | bRet = ::CloseHandle(hObject); 21 | hObject = INVALID_HANDLE_VALUE; 22 | } 23 | 24 | return bRet; 25 | } 26 | 27 | static inline void SafeLocalFreeString(LPWSTR& sz) 28 | { 29 | SecureZeroMemory(sz, wcslen(sz)); 30 | ::LocalFree(sz); 31 | sz = NULL; 32 | } 33 | 34 | CredentialsChannel::CredentialsChannel() : 35 | _hCredsPipe(INVALID_HANDLE_VALUE), 36 | _hCredsThread(INVALID_HANDLE_VALUE), 37 | _pListener(NULL) 38 | { 39 | 40 | } 41 | 42 | CredentialsChannel::~CredentialsChannel() 43 | { 44 | DestroyChannel(); 45 | } 46 | 47 | bool CredentialsChannel::CreateChannel(CredChannelListener *pListener) 48 | { 49 | ASSERT(_hCredsPipe == INVALID_HANDLE_VALUE); 50 | ASSERT(_hCredsThread == INVALID_HANDLE_VALUE); 51 | 52 | _hCredsPipe = ::CreateNamedPipe(lpszPipeName, 53 | PIPE_ACCESS_DUPLEX, 54 | PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT, 55 | PIPE_UNLIMITED_INSTANCES, 56 | dwPipeBuffer, 57 | dwPipeBuffer, 58 | NMPWAIT_WAIT_FOREVER, 59 | NULL); 60 | 61 | if (_hCredsPipe != INVALID_HANDLE_VALUE) 62 | { 63 | _hCredsThread = ::CreateThread( 64 | NULL, 0, CredentialsChannelThread, this, 0, NULL); 65 | 66 | if (_hCredsThread) 67 | { 68 | _pListener = pListener; 69 | } 70 | } 71 | 72 | return (_hCredsThread != INVALID_HANDLE_VALUE); 73 | } 74 | 75 | void CredentialsChannel::DestroyChannel() 76 | { 77 | if (_hCredsThread != INVALID_HANDLE_VALUE) 78 | { 79 | VERIFY(::TerminateThread(_hCredsThread, 0L)); 80 | SafeCloseHandle(_hCredsThread); 81 | } 82 | 83 | if (_hCredsPipe != NULL) 84 | { 85 | VERIFY(::DisconnectNamedPipe(_hCredsPipe)); 86 | SafeCloseHandle(_hCredsPipe); 87 | } 88 | 89 | _pListener = NULL; 90 | } 91 | 92 | DWORD CredentialsChannel::CredentialsChannelThread(LPVOID lpParameter) 93 | { 94 | CredentialsChannel *pThis = reinterpret_cast(lpParameter); 95 | ASSERT(pThis != NULL); 96 | pThis->CredentialsChannelWait(); 97 | return 0L; 98 | } 99 | 100 | void CredentialsChannel::CredentialsChannelWait() 101 | { 102 | BOOL bConnected = ::ConnectNamedPipe(_hCredsPipe, NULL); 103 | if ((bConnected == TRUE) || (::GetLastError() == ERROR_PIPE_CONNECTED)) 104 | { 105 | BYTE CredBuf[dwPipeBuffer]; 106 | DWORD nRead = 0; 107 | 108 | BOOL bRead = ::ReadFile(_hCredsPipe, CredBuf, sizeof(CredBuf), &nRead, NULL); 109 | if ((bRead == TRUE) && (nRead > 0)) 110 | { 111 | ParseCredentialsBuffer(CredBuf, nRead); 112 | } 113 | } 114 | 115 | // The application on the other side expect a reply. Just say nothing. 116 | ::WriteFile(_hCredsPipe, NULL, 0, NULL, NULL); 117 | 118 | VERIFY(::DisconnectNamedPipe(_hCredsPipe)); 119 | SafeCloseHandle(_hCredsPipe); 120 | 121 | // I'm about to terminate and quite sure about it. 122 | _hCredsThread = NULL; 123 | } 124 | 125 | void CredentialsChannel::ParseCredentialsBuffer(BYTE *pCredBuf, DWORD nSize) 126 | { 127 | ASSERT(nSize > sizeof(int)); 128 | int nUserLen = _ntohl(*((int *)pCredBuf)); 129 | 130 | // Both name and password are encoded as UTF-8 strings. This mean that 131 | // we can threat the buffer size as string length when allocating the 132 | // the buffer for the UTF-16 conversion. 133 | 134 | LPWSTR szUserName = reinterpret_cast( 135 | ::LocalAlloc(LMEM_FIXED|LMEM_ZEROINIT, ((nUserLen + 1) * sizeof(WCHAR)))); 136 | 137 | if (szUserName == NULL) 138 | { 139 | return; 140 | } 141 | 142 | int nPasswordLen = nSize - 4 - nUserLen; 143 | 144 | LPWSTR szPassword = reinterpret_cast( 145 | ::LocalAlloc(LMEM_FIXED|LMEM_ZEROINIT, ((nPasswordLen + 1) * sizeof(WCHAR)))); 146 | 147 | if (szPassword == NULL) 148 | { 149 | SafeLocalFreeString(szUserName); 150 | return; 151 | } 152 | 153 | ::MultiByteToWideChar(CP_UTF8, 0, 154 | reinterpret_cast(pCredBuf + 4), nUserLen, 155 | szUserName, nUserLen + 1); 156 | 157 | ::MultiByteToWideChar(CP_UTF8, 0, 158 | reinterpret_cast(pCredBuf + 4 + nUserLen), nPasswordLen, 159 | szPassword, nPasswordLen + 1); 160 | 161 | if ((wcslen(szUserName) > 0) && (wcslen(szPassword) > 0)) 162 | { 163 | LPWSTR szDomain = wcschr(szUserName, L'@'); 164 | if (szDomain != NULL) 165 | { 166 | *szDomain = L'\0'; 167 | szDomain += 1; 168 | } 169 | 170 | if (_pListener != NULL) 171 | { 172 | _pListener->OnCredentialsArrivial(szUserName, szPassword, szDomain); 173 | } 174 | } 175 | 176 | SafeLocalFreeString(szUserName); 177 | SafeLocalFreeString(szPassword); 178 | } 179 | -------------------------------------------------------------------------------- /windows-credprov/CredentialsChannel.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _CREDENTIALS_CHANNEL_H_INCLUDED_ 3 | #define _CREDENTIALS_CHANNEL_H_INCLUDED_ 4 | 5 | #include 6 | 7 | class CredChannelListener 8 | { 9 | public: 10 | virtual void OnCredentialsArrivial(LPCWSTR wzUserName, LPCWSTR wzPassword, LPCWSTR wzDomain) = 0; 11 | virtual ~CredChannelListener() { } 12 | }; 13 | 14 | class CredentialsChannel 15 | { 16 | public: 17 | 18 | CredentialsChannel(); 19 | ~CredentialsChannel(); 20 | 21 | bool CreateChannel(CredChannelListener *pListener); 22 | void DestroyChannel(); 23 | 24 | private: 25 | 26 | static DWORD WINAPI CredentialsChannelThread(LPVOID lpParameter); 27 | void CredentialsChannelWait(); 28 | void ParseCredentialsBuffer(BYTE *pCredBuf, DWORD nSize); 29 | 30 | private: 31 | 32 | HANDLE _hCredsPipe; 33 | HANDLE _hCredsThread; 34 | CredChannelListener *_pListener; 35 | }; 36 | 37 | #endif // _CREDENTIALS_CHANNEL_H_INCLUDED_ 38 | -------------------------------------------------------------------------------- /windows-credprov/Helpers.h: -------------------------------------------------------------------------------- 1 | // 2 | // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF 3 | // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO 4 | // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A 5 | // PARTICULAR PURPOSE. 6 | // 7 | // Copyright (c) Microsoft Corporation. All rights reserved. 8 | // 9 | // 10 | // The MIT License (MIT) 11 | // 12 | // Copyright (c) Microsoft Corporation 13 | // 14 | // Permission is hereby granted, free of charge, to any person obtaining a copy 15 | // of this software and associated documentation files (the "Software"), to 16 | // deal in the Software without restriction, including without limitation the 17 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 18 | // sell copies of the Software, and to permit persons to whom the Software is 19 | // furnished to do so, subject to the following conditions: 20 | // 21 | // The above copyright notice and this permission notice shall be included in 22 | // all copies or substantial portions of the Software. 23 | // 24 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 25 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 26 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 27 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 28 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 29 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 30 | // IN THE SOFTWARE. 31 | // 32 | // 33 | // Helper functions for copying parameters and packaging the buffer 34 | // for GetSerialization. 35 | 36 | #pragma once 37 | 38 | // Fix compilation with mingw 39 | // ... the following belongs to sal.h 40 | #define _Outptr_result_nullonfailure_ 41 | #define _Outptr_result_bytebuffer_(s) 42 | #define _In_reads_bytes_(s) 43 | #define _Inout_updates_bytes_(s) 44 | 45 | #pragma warning(push) 46 | #pragma warning(disable: 28251) 47 | #include 48 | #include 49 | #pragma warning(pop) 50 | 51 | #define SECURITY_WIN32 52 | #include 53 | #include 54 | 55 | #include 56 | #include 57 | 58 | #pragma warning(push) 59 | #pragma warning(disable: 4995) 60 | #include 61 | #pragma warning(pop) 62 | 63 | #pragma warning(push) 64 | #pragma warning(disable: 28301) 65 | #include 66 | #pragma warning(pop) 67 | 68 | //makes a copy of a field descriptor using CoTaskMemAlloc 69 | HRESULT FieldDescriptorCoAllocCopy( 70 | _In_ const CREDENTIAL_PROVIDER_FIELD_DESCRIPTOR &rcpfd, 71 | _Outptr_result_nullonfailure_ CREDENTIAL_PROVIDER_FIELD_DESCRIPTOR **ppcpfd 72 | ); 73 | 74 | //makes a copy of a field descriptor on the normal heap 75 | HRESULT FieldDescriptorCopy( 76 | _In_ const CREDENTIAL_PROVIDER_FIELD_DESCRIPTOR &rcpfd, 77 | _Out_ CREDENTIAL_PROVIDER_FIELD_DESCRIPTOR *pcpfd 78 | ); 79 | 80 | //creates a UNICODE_STRING from a NULL-terminated string 81 | HRESULT UnicodeStringInitWithString( 82 | _In_ PWSTR pwz, 83 | _Out_ UNICODE_STRING *pus 84 | ); 85 | 86 | //initializes a KERB_INTERACTIVE_UNLOCK_LOGON with weak references to the provided credentials 87 | HRESULT KerbInteractiveUnlockLogonInit( 88 | _In_ PWSTR pwzDomain, 89 | _In_ PWSTR pwzUsername, 90 | _In_ PWSTR pwzPassword, 91 | _In_ CREDENTIAL_PROVIDER_USAGE_SCENARIO cpus, 92 | _Out_ KERB_INTERACTIVE_UNLOCK_LOGON *pkiul 93 | ); 94 | 95 | //packages the credentials into the buffer that the system expects 96 | HRESULT KerbInteractiveUnlockLogonPack( 97 | _In_ const KERB_INTERACTIVE_UNLOCK_LOGON &rkiulIn, 98 | _Outptr_result_bytebuffer_(*pcb) BYTE **prgb, 99 | _Out_ DWORD *pcb 100 | ); 101 | 102 | //get the authentication package that will be used for our logon attempt 103 | HRESULT RetrieveNegotiateAuthPackage( 104 | _Out_ ULONG *pulAuthPackage 105 | ); 106 | 107 | //encrypt a password (if necessary) and copy it; if not, just copy it 108 | HRESULT ProtectIfNecessaryAndCopyPassword( 109 | _In_ PCWSTR pwzPassword, 110 | _In_ CREDENTIAL_PROVIDER_USAGE_SCENARIO cpus, 111 | _Outptr_result_nullonfailure_ PWSTR *ppwzProtectedPassword 112 | ); 113 | 114 | HRESULT KerbInteractiveUnlockLogonRepackNative( 115 | _In_reads_bytes_(cbWow) BYTE *rgbWow, 116 | _In_ DWORD cbWow, 117 | _Outptr_result_bytebuffer_(*pcbNative) BYTE **prgbNative, 118 | _Out_ DWORD *pcbNative 119 | ); 120 | 121 | void KerbInteractiveUnlockLogonUnpackInPlace( 122 | _Inout_updates_bytes_(cb) KERB_INTERACTIVE_UNLOCK_LOGON *pkiul, 123 | DWORD cb 124 | ); 125 | 126 | HRESULT DomainUsernameStringAlloc( 127 | _In_ PCWSTR pwszDomain, 128 | _In_ PCWSTR pwszUsername, 129 | _Outptr_result_nullonfailure_ PWSTR *ppwszDomainUsername 130 | ); 131 | 132 | //HRESULT SplitDomainAndUsername(_In_ PCWSTR pszQualifiedUserName, _Outptr_result_nullonfailure_ PWSTR *ppszDomain, _Outptr_result_nullonfailure_ PWSTR *ppszUsername); 133 | -------------------------------------------------------------------------------- /windows-credprov/Makefile.am: -------------------------------------------------------------------------------- 1 | # Copyright 2013-2015 Red Hat, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # Refer to the README and COPYING files for full details of the license. 16 | 17 | EXTRA_DIST= \ 18 | afxres.h \ 19 | credentialprovider.h \ 20 | CredentialsChannel.cpp \ 21 | CredentialsChannel.h \ 22 | Helpers.cpp \ 23 | Helpers.h \ 24 | intsafe.h \ 25 | OVirtCredentials.cpp \ 26 | OVirtCredentials.h \ 27 | OVirtCredProv.cpp \ 28 | OVirtCredProv.def \ 29 | OVirtCredProv.h \ 30 | OVirtCredProv.rc \ 31 | OVirtCredProv.sln \ 32 | OVirtCredProv.vcproj \ 33 | OVirtProvider.cpp \ 34 | OVirtProvider.h \ 35 | Pch.cpp \ 36 | Pch.h \ 37 | Register.reg \ 38 | resource.h \ 39 | Unregister.reg \ 40 | $(NULL) 41 | 42 | MAINTAINERCLEANFILES = \ 43 | *~ \ 44 | Makefile.in \ 45 | $(NULL) 46 | -------------------------------------------------------------------------------- /windows-credprov/OVirtCredProv.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Pch.h" 3 | 4 | #include 5 | 6 | DEFINE_GUID(IID_ICredentialProviderCredential, 0x63913a93, 0x40c1, 0x481a, 0x81,0x8d, 0x40,0x72,0xff,0x8c,0x70,0xcc); 7 | DEFINE_GUID(IID_ICredentialProvider, 0xd27c3481, 0x5a1c, 0x45b2, 0x8a,0xaa, 0xc2,0x0e,0xbb,0xe8,0x22,0x9e); 8 | #include "OVirtCredProv.h" 9 | 10 | // A global DLL reference count. 11 | static LONG g_nRefCount = 0; 12 | 13 | extern HRESULT OVirtCredProv_CreateInstance(REFIID riid, void** ppv); 14 | 15 | class CClassFactory : public IClassFactory 16 | { 17 | public: 18 | 19 | // IUnknown 20 | 21 | STDMETHOD_(ULONG, AddRef)() 22 | { 23 | return _cRef++; 24 | } 25 | 26 | STDMETHOD_(ULONG, Release)() 27 | { 28 | LONG cRef = _cRef--; 29 | if (!cRef) 30 | { 31 | delete this; 32 | } 33 | return cRef; 34 | } 35 | 36 | STDMETHOD (QueryInterface)(REFIID riid, void** ppv) 37 | { 38 | HRESULT hr; 39 | if (ppv != NULL) 40 | { 41 | if (IID_IClassFactory == riid || IID_IUnknown == riid) 42 | { 43 | *ppv = static_cast(this); 44 | reinterpret_cast(*ppv)->AddRef(); 45 | hr = S_OK; 46 | } 47 | else 48 | { 49 | *ppv = NULL; 50 | hr = E_NOINTERFACE; 51 | } 52 | } 53 | else 54 | { 55 | hr = E_INVALIDARG; 56 | } 57 | return hr; 58 | } 59 | 60 | // IClassFactory 61 | 62 | STDMETHOD (CreateInstance)(IUnknown* pUnkOuter, REFIID riid, void** ppv) 63 | { 64 | HRESULT hr; 65 | if (!pUnkOuter) 66 | { 67 | hr = OVirtCredProv_CreateInstance(riid, ppv); 68 | } 69 | else 70 | { 71 | hr = CLASS_E_NOAGGREGATION; 72 | } 73 | return hr; 74 | } 75 | 76 | STDMETHOD (LockServer)(BOOL bLock) 77 | { 78 | if (bLock) 79 | { 80 | DllAddRef(); 81 | } 82 | else 83 | { 84 | DllRelease(); 85 | } 86 | return S_OK; 87 | } 88 | 89 | private: 90 | CClassFactory() : _cRef(1) { } 91 | ~CClassFactory() { } 92 | 93 | private: 94 | LONG _cRef; 95 | 96 | friend HRESULT ClassFactory_CreateInstance(REFCLSID rclsid, REFIID riid, void** ppv); 97 | }; 98 | 99 | HRESULT ClassFactory_CreateInstance(REFCLSID rclsid, REFIID riid, void** ppv) 100 | { 101 | HRESULT hr; 102 | if (CLSID_OVirtProvider == rclsid) 103 | { 104 | CClassFactory* pcf = new CClassFactory; 105 | if (pcf) 106 | { 107 | hr = pcf->QueryInterface(riid, ppv); 108 | pcf->Release(); 109 | } 110 | else 111 | { 112 | hr = E_OUTOFMEMORY; 113 | } 114 | } 115 | else 116 | { 117 | hr = CLASS_E_CLASSNOTAVAILABLE; 118 | } 119 | return hr; 120 | } 121 | 122 | BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID pReserved) 123 | { 124 | UNREFERENCED_PARAMETER(pReserved); 125 | 126 | switch (dwReason) 127 | { 128 | case DLL_PROCESS_ATTACH: 129 | DisableThreadLibraryCalls(hInstance); 130 | break; 131 | 132 | case DLL_PROCESS_DETACH: 133 | case DLL_THREAD_ATTACH: 134 | case DLL_THREAD_DETACH: 135 | break; 136 | } 137 | 138 | return TRUE; 139 | } 140 | 141 | STDAPI DllCanUnloadNow() 142 | { 143 | return (g_nRefCount <= 0); 144 | } 145 | 146 | STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, void** ppv) 147 | { 148 | return ClassFactory_CreateInstance(rclsid, riid, ppv); 149 | } 150 | 151 | void DllAddRef() 152 | { 153 | InterlockedIncrement(&g_nRefCount); 154 | } 155 | 156 | void DllRelease() 157 | { 158 | InterlockedDecrement(&g_nRefCount); 159 | } 160 | -------------------------------------------------------------------------------- /windows-credprov/OVirtCredProv.def: -------------------------------------------------------------------------------- 1 | 2 | LIBRARY OVirtCredProv.DLL 3 | 4 | EXPORTS 5 | 6 | DllCanUnloadNow PRIVATE 7 | DllGetClassObject PRIVATE 8 | -------------------------------------------------------------------------------- /windows-credprov/OVirtCredProv.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | // {82D99859-33A8-438b-8B83-3988A20089DD} 5 | DEFINE_GUID(CLSID_OVirtProvider, 0x82d99859, 0x33a8, 0x438b, 0x8b, 0x83, 0x39, 0x88, 0xa2, 0x0, 0x89, 0xdd); 6 | 7 | void DllAddRef(); 8 | 9 | void DllRelease(); 10 | -------------------------------------------------------------------------------- /windows-credprov/OVirtCredProv.rc: -------------------------------------------------------------------------------- 1 | // Microsoft Visual C++ generated resource script. 2 | // 3 | #include "resource.h" 4 | 5 | #define APSTUDIO_READONLY_SYMBOLS 6 | ///////////////////////////////////////////////////////////////////////////// 7 | // 8 | // Generated from the TEXTINCLUDE 2 resource. 9 | // 10 | #include "afxres.h" 11 | 12 | ///////////////////////////////////////////////////////////////////////////// 13 | #undef APSTUDIO_READONLY_SYMBOLS 14 | 15 | ///////////////////////////////////////////////////////////////////////////// 16 | // English (U.S.) resources 17 | 18 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) 19 | #ifdef _WIN32 20 | LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US 21 | #pragma code_page(1252) 22 | #endif //_WIN32 23 | 24 | #ifdef APSTUDIO_INVOKED 25 | ///////////////////////////////////////////////////////////////////////////// 26 | // 27 | // TEXTINCLUDE 28 | // 29 | 30 | 1 TEXTINCLUDE 31 | BEGIN 32 | "resource.h\0" 33 | END 34 | 35 | 2 TEXTINCLUDE 36 | BEGIN 37 | "#include ""afxres.h""\r\n" 38 | "\0" 39 | END 40 | 41 | 3 TEXTINCLUDE 42 | BEGIN 43 | "\r\n" 44 | "\0" 45 | END 46 | 47 | #endif // APSTUDIO_INVOKED 48 | 49 | #endif // English (U.S.) resources 50 | ///////////////////////////////////////////////////////////////////////////// 51 | 52 | 53 | ///////////////////////////////////////////////////////////////////////////// 54 | // Hebrew resources 55 | 56 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_HEB) 57 | #ifdef _WIN32 58 | LANGUAGE LANG_HEBREW, SUBLANG_DEFAULT 59 | #pragma code_page(1255) 60 | #endif //_WIN32 61 | 62 | ///////////////////////////////////////////////////////////////////////////// 63 | // 64 | // Version 65 | // 66 | 67 | VS_VERSION_INFO VERSIONINFO 68 | FILEVERSION 1,0,0,1 69 | PRODUCTVERSION 1,0,0,1 70 | FILEFLAGSMASK 0x17L 71 | #ifdef _DEBUG 72 | FILEFLAGS 0x1L 73 | #else 74 | FILEFLAGS 0x0L 75 | #endif 76 | FILEOS 0x4L 77 | FILETYPE 0x2L 78 | FILESUBTYPE 0x0L 79 | BEGIN 80 | BLOCK "StringFileInfo" 81 | BEGIN 82 | BLOCK "040d04b0" 83 | BEGIN 84 | VALUE "FileDescription", "OVirtCred Dynamic Link Library" 85 | VALUE "FileVersion", "1, 0, 0, 1" 86 | VALUE "InternalName", "OVirtCred" 87 | VALUE "LegalCopyright", "Copyright (C) 2010" 88 | VALUE "OriginalFilename", "OVirtCred.dll" 89 | VALUE "ProductName", "OVirtCred Dynamic Link Library" 90 | VALUE "ProductVersion", "1, 0, 0, 1" 91 | END 92 | END 93 | BLOCK "VarFileInfo" 94 | BEGIN 95 | VALUE "Translation", 0x40d, 1200 96 | END 97 | END 98 | 99 | #endif // Hebrew resources 100 | ///////////////////////////////////////////////////////////////////////////// 101 | 102 | 103 | 104 | #ifndef APSTUDIO_INVOKED 105 | ///////////////////////////////////////////////////////////////////////////// 106 | // 107 | // Generated from the TEXTINCLUDE 3 resource. 108 | // 109 | 110 | 111 | ///////////////////////////////////////////////////////////////////////////// 112 | #endif // not APSTUDIO_INVOKED 113 | 114 | -------------------------------------------------------------------------------- /windows-credprov/OVirtCredProv.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 10.00 3 | # Visual Studio 2008 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "OVirtCredProv", "OVirtCredProv.vcproj", "{3FA043C2-E5CF-4652-86FB-C3D985C9F1AA}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Win32 = Debug|Win32 9 | Debug|x64 = Debug|x64 10 | Release|Win32 = Release|Win32 11 | Release|x64 = Release|x64 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {3FA043C2-E5CF-4652-86FB-C3D985C9F1AA}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {3FA043C2-E5CF-4652-86FB-C3D985C9F1AA}.Debug|Win32.Build.0 = Debug|Win32 16 | {3FA043C2-E5CF-4652-86FB-C3D985C9F1AA}.Debug|x64.ActiveCfg = Debug|x64 17 | {3FA043C2-E5CF-4652-86FB-C3D985C9F1AA}.Debug|x64.Build.0 = Debug|x64 18 | {3FA043C2-E5CF-4652-86FB-C3D985C9F1AA}.Release|Win32.ActiveCfg = Release|Win32 19 | {3FA043C2-E5CF-4652-86FB-C3D985C9F1AA}.Release|Win32.Build.0 = Release|Win32 20 | {3FA043C2-E5CF-4652-86FB-C3D985C9F1AA}.Release|x64.ActiveCfg = Release|x64 21 | {3FA043C2-E5CF-4652-86FB-C3D985C9F1AA}.Release|x64.Build.0 = Release|x64 22 | EndGlobalSection 23 | GlobalSection(SolutionProperties) = preSolution 24 | HideSolutionNode = FALSE 25 | EndGlobalSection 26 | EndGlobal 27 | -------------------------------------------------------------------------------- /windows-credprov/OVirtCredentials.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Pch.h" 3 | #include "OVirtCredProv.h" 4 | #include "OVirtCredentials.h" 5 | #include "Helpers.h" 6 | 7 | OVirtCredentials::OVirtCredentials () : 8 | _cRef(1), 9 | _wzUserName(NULL), 10 | _wzPassword(NULL), 11 | _wzDomain(NULL) 12 | { 13 | DllAddRef(); 14 | } 15 | 16 | OVirtCredentials::~OVirtCredentials () 17 | { 18 | ResetCredentials(); 19 | DllRelease(); 20 | } 21 | 22 | // IUnknown 23 | 24 | IFACEMETHODIMP_(ULONG) OVirtCredentials::AddRef() 25 | { 26 | return ++_cRef; 27 | } 28 | 29 | IFACEMETHODIMP_(ULONG) OVirtCredentials::Release() 30 | { 31 | LONG cRef = --_cRef; 32 | if (!cRef) 33 | { 34 | delete this; 35 | } 36 | return cRef; 37 | } 38 | 39 | IFACEMETHODIMP OVirtCredentials::QueryInterface(__in REFIID riid, __deref_out void** ppv) 40 | { 41 | HRESULT hr; 42 | if (ppv) 43 | { 44 | if ((IID_IUnknown == riid) || (IID_ICredentialProviderCredential == riid)) 45 | { 46 | *ppv = static_cast(this); 47 | reinterpret_cast(*ppv)->AddRef(); 48 | hr = S_OK; 49 | } 50 | else 51 | { 52 | *ppv = NULL; 53 | hr = E_NOINTERFACE; 54 | } 55 | } 56 | else 57 | { 58 | hr = E_INVALIDARG; 59 | } 60 | return hr; 61 | } 62 | 63 | // ICredentialProviderCredential 64 | 65 | IFACEMETHODIMP OVirtCredentials::Advise(__in ICredentialProviderCredentialEvents *pcpce) 66 | { 67 | UNREFERENCED_PARAMETER(pcpce); 68 | return S_OK; 69 | } 70 | 71 | IFACEMETHODIMP OVirtCredentials::UnAdvise() 72 | { 73 | return S_OK; 74 | } 75 | 76 | IFACEMETHODIMP OVirtCredentials::SetSelected(__out BOOL *pbAutoLogon) 77 | { 78 | UNREFERENCED_PARAMETER(pbAutoLogon); 79 | return S_FALSE; 80 | } 81 | 82 | IFACEMETHODIMP OVirtCredentials::SetDeselected() 83 | { 84 | return S_OK; 85 | } 86 | 87 | IFACEMETHODIMP OVirtCredentials::GetFieldState(__in DWORD dwFieldID, 88 | __out CREDENTIAL_PROVIDER_FIELD_STATE *pcpfs, 89 | __out CREDENTIAL_PROVIDER_FIELD_INTERACTIVE_STATE *pcpfis) 90 | { 91 | UNREFERENCED_PARAMETER(dwFieldID); 92 | UNREFERENCED_PARAMETER(pcpfs); 93 | UNREFERENCED_PARAMETER(pcpfis); 94 | return E_NOTIMPL; 95 | } 96 | 97 | IFACEMETHODIMP OVirtCredentials::GetStringValue(__in DWORD dwFieldID, __deref_out PWSTR* ppwsz) 98 | { 99 | UNREFERENCED_PARAMETER(dwFieldID); 100 | UNREFERENCED_PARAMETER(ppwsz); 101 | return E_NOTIMPL; 102 | } 103 | 104 | IFACEMETHODIMP OVirtCredentials::GetBitmapValue(__in DWORD dwFieldID, __out HBITMAP* phbmp) 105 | { 106 | UNREFERENCED_PARAMETER(dwFieldID); 107 | UNREFERENCED_PARAMETER(phbmp); 108 | return E_NOTIMPL; 109 | } 110 | 111 | IFACEMETHODIMP OVirtCredentials::GetCheckboxValue(__in DWORD dwFieldID, 112 | __out BOOL* pbChecked, 113 | __deref_out PWSTR* ppwszLabel) 114 | { 115 | UNREFERENCED_PARAMETER(dwFieldID); 116 | UNREFERENCED_PARAMETER(pbChecked); 117 | UNREFERENCED_PARAMETER(ppwszLabel); 118 | return E_NOTIMPL; 119 | } 120 | 121 | IFACEMETHODIMP OVirtCredentials::GetComboBoxValueCount(__in DWORD dwFieldID, 122 | __out DWORD* pcItems, 123 | __out_range(<,*pcItems) DWORD* pdwSelectedItem) 124 | { 125 | UNREFERENCED_PARAMETER(dwFieldID); 126 | UNREFERENCED_PARAMETER(pcItems); 127 | UNREFERENCED_PARAMETER(pdwSelectedItem); 128 | return E_NOTIMPL; 129 | } 130 | 131 | IFACEMETHODIMP OVirtCredentials::GetComboBoxValueAt(__in DWORD dwFieldID, 132 | __in DWORD dwItem, 133 | __deref_out PWSTR* ppwszItem) 134 | { 135 | UNREFERENCED_PARAMETER(dwFieldID); 136 | UNREFERENCED_PARAMETER(dwItem); 137 | UNREFERENCED_PARAMETER(ppwszItem); 138 | return E_NOTIMPL; 139 | 140 | } 141 | 142 | IFACEMETHODIMP OVirtCredentials::GetSubmitButtonValue(__in DWORD dwFieldID, 143 | __out DWORD* pdwAdjacentTo) 144 | { 145 | UNREFERENCED_PARAMETER(dwFieldID); 146 | UNREFERENCED_PARAMETER(pdwAdjacentTo); 147 | return E_NOTIMPL; 148 | } 149 | 150 | IFACEMETHODIMP OVirtCredentials::SetStringValue(__in DWORD dwFieldID, __in PCWSTR pwz) 151 | { 152 | UNREFERENCED_PARAMETER(dwFieldID); 153 | UNREFERENCED_PARAMETER(pwz); 154 | return E_NOTIMPL; 155 | } 156 | 157 | IFACEMETHODIMP OVirtCredentials::SetCheckboxValue(__in DWORD dwFieldID, __in BOOL bChecked) 158 | { 159 | UNREFERENCED_PARAMETER(dwFieldID); 160 | UNREFERENCED_PARAMETER(bChecked); 161 | return E_NOTIMPL; 162 | } 163 | 164 | IFACEMETHODIMP OVirtCredentials::SetComboBoxSelectedValue(__in DWORD dwFieldID, 165 | __in DWORD dwSelectedItem) 166 | { 167 | UNREFERENCED_PARAMETER(dwFieldID); 168 | UNREFERENCED_PARAMETER(dwSelectedItem); 169 | return E_NOTIMPL; 170 | } 171 | 172 | IFACEMETHODIMP OVirtCredentials::CommandLinkClicked(__in DWORD dwFieldID) 173 | { 174 | UNREFERENCED_PARAMETER(dwFieldID); 175 | return E_NOTIMPL; 176 | } 177 | 178 | IFACEMETHODIMP OVirtCredentials::GetSerialization(__out CREDENTIAL_PROVIDER_GET_SERIALIZATION_RESPONSE* pcpgsr, 179 | __out CREDENTIAL_PROVIDER_CREDENTIAL_SERIALIZATION* pcpcs, 180 | __deref_out_opt PWSTR* ppwszOptionalStatusText, 181 | __out CREDENTIAL_PROVIDER_STATUS_ICON* pcpsiOptionalStatusIcon) 182 | { 183 | UNREFERENCED_PARAMETER(ppwszOptionalStatusText); 184 | UNREFERENCED_PARAMETER(pcpsiOptionalStatusIcon); 185 | 186 | KERB_INTERACTIVE_UNLOCK_LOGON kiul; 187 | ZeroMemory(&kiul, sizeof(kiul)); 188 | 189 | KERB_INTERACTIVE_LOGON *pkil = &kiul.Logon; 190 | 191 | HRESULT hr; 192 | 193 | // Initialize the UNICODE_STRINGS to share our username and password strings 194 | hr = UnicodeStringInitWithString(_wzDomain, &pkil->LogonDomainName); 195 | if (SUCCEEDED(hr)) 196 | { 197 | hr = UnicodeStringInitWithString(_wzUserName, &pkil->UserName); 198 | if (SUCCEEDED(hr)) 199 | { 200 | hr = UnicodeStringInitWithString(_wzPassword, &pkil->Password); 201 | if (SUCCEEDED(hr)) 202 | { 203 | // 204 | // Allocate copies of, and package, the strings in a binary blob 205 | // 206 | pkil->MessageType = ((_cpus == CPUS_UNLOCK_WORKSTATION) ? KerbWorkstationUnlockLogon : KerbInteractiveLogon); 207 | 208 | hr = KerbInteractiveUnlockLogonPack(kiul, &pcpcs->rgbSerialization, &pcpcs->cbSerialization); 209 | if (SUCCEEDED(hr)) 210 | { 211 | ULONG ulAuthPackage; 212 | 213 | hr = RetrieveNegotiateAuthPackage(&ulAuthPackage); 214 | if (SUCCEEDED(hr)) 215 | { 216 | pcpcs->ulAuthenticationPackage = ulAuthPackage; 217 | pcpcs->clsidCredentialProvider = CLSID_OVirtProvider; 218 | 219 | // At this point the credential has created the serialized credential used for logon 220 | // By setting this to CPGSR_RETURN_CREDENTIAL_FINISHED we are letting logonUI know 221 | // that we have all the information we need and it should attempt to submit the 222 | // serialized credential. 223 | *pcpgsr = CPGSR_RETURN_CREDENTIAL_FINISHED; 224 | } 225 | } 226 | } 227 | } 228 | } 229 | 230 | return hr; 231 | } 232 | 233 | IFACEMETHODIMP OVirtCredentials::ReportResult(__in NTSTATUS ntsStatus, 234 | __in NTSTATUS ntsSubstatus, 235 | __deref_out_opt PWSTR* ppwszOptionalStatusText, 236 | __out CREDENTIAL_PROVIDER_STATUS_ICON* pcpsiOptionalStatusIcon) 237 | { 238 | UNREFERENCED_PARAMETER(ntsStatus); 239 | UNREFERENCED_PARAMETER(ntsStatus); 240 | UNREFERENCED_PARAMETER(ntsSubstatus); 241 | UNREFERENCED_PARAMETER(ppwszOptionalStatusText); 242 | UNREFERENCED_PARAMETER(pcpsiOptionalStatusIcon); 243 | return E_NOTIMPL; 244 | } 245 | 246 | bool OVirtCredentials::GotCredentials() 247 | { 248 | return ((_wzUserName != NULL) && (_wzPassword != NULL) && (_wzDomain != NULL)); 249 | } 250 | 251 | void OVirtCredentials::SetCredentials(LPCWSTR wzUserName, LPCWSTR wzPassword, LPCWSTR wzDomain) 252 | { 253 | ASSERT(wzUserName != NULL); 254 | ASSERT(wzPassword != NULL); 255 | 256 | ResetCredentials(); 257 | 258 | if (wzUserName != NULL) 259 | { 260 | _wzUserName = _wcsdup(wzUserName); 261 | } 262 | 263 | if (wzPassword != NULL) 264 | { 265 | _wzPassword = _wcsdup(wzPassword); 266 | } 267 | 268 | if (wzDomain != NULL) 269 | { 270 | _wzDomain = _wcsdup(wzDomain); 271 | } 272 | else 273 | { 274 | WCHAR wsz[MAX_COMPUTERNAME_LENGTH+1]; 275 | DWORD cch = ARRAYSIZE(wsz); 276 | 277 | if (::GetComputerNameW(wsz, &cch)) 278 | { 279 | _wzDomain = _wcsdup(wsz); 280 | } 281 | } 282 | 283 | if (GotCredentials() == false) 284 | { 285 | ResetCredentials(); 286 | } 287 | } 288 | 289 | void OVirtCredentials::ResetCredentials() 290 | { 291 | if (_wzUserName != NULL) 292 | { 293 | free(_wzUserName); 294 | _wzUserName = NULL; 295 | } 296 | 297 | if (_wzPassword != NULL) 298 | { 299 | ::SecureZeroMemory(_wzPassword, wcslen(_wzPassword) * sizeof(WCHAR)); 300 | free(_wzPassword); 301 | _wzPassword = NULL; 302 | } 303 | 304 | if (_wzDomain != NULL) 305 | { 306 | free(_wzDomain); 307 | _wzDomain = NULL; 308 | } 309 | } 310 | 311 | void OVirtCredentials::SetUsageScenario(CREDENTIAL_PROVIDER_USAGE_SCENARIO cpus) 312 | { 313 | _cpus = cpus; 314 | } 315 | -------------------------------------------------------------------------------- /windows-credprov/OVirtCredentials.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include 5 | 6 | #ifndef __in 7 | #define __in 8 | #endif 9 | #ifndef __out 10 | #define __out 11 | #endif 12 | #ifndef __deref_out 13 | #define __deref_out 14 | #endif 15 | #ifndef __out_range 16 | #define __out_range(x,y) 17 | #endif 18 | #ifndef __deref_out_opt 19 | #define __deref_out_opt 20 | #endif 21 | 22 | class OVirtCredentials : public ICredentialProviderCredential 23 | { 24 | public: 25 | 26 | OVirtCredentials(); 27 | 28 | HRESULT Initialize(const CREDENTIAL_PROVIDER_FIELD_DESCRIPTOR* rgcpfd, 29 | /*const FIELD_STATE_PAIR* rgfsp,*/ 30 | PCWSTR pwzUsername, 31 | PCWSTR pwzPassword, 32 | PCWSTR pwzDomainName); 33 | 34 | // IUnknown 35 | 36 | IFACEMETHODIMP_(ULONG) AddRef(); 37 | IFACEMETHODIMP_(ULONG) Release(); 38 | IFACEMETHODIMP QueryInterface(__in REFIID riid, __deref_out void** ppv); 39 | 40 | // ICredentialProviderCredential 41 | 42 | IFACEMETHODIMP Advise(__in ICredentialProviderCredentialEvents* pcpce); 43 | IFACEMETHODIMP UnAdvise(); 44 | IFACEMETHODIMP SetSelected(__out BOOL* pbAutoLogon); 45 | IFACEMETHODIMP SetDeselected(); 46 | IFACEMETHODIMP GetFieldState(__in DWORD dwFieldID, 47 | __out CREDENTIAL_PROVIDER_FIELD_STATE* pcpfs, 48 | __out CREDENTIAL_PROVIDER_FIELD_INTERACTIVE_STATE* pcpfis); 49 | IFACEMETHODIMP GetStringValue(__in DWORD dwFieldID, __deref_out PWSTR* ppwsz); 50 | IFACEMETHODIMP GetBitmapValue(__in DWORD dwFieldID, __out HBITMAP* phbmp); 51 | IFACEMETHODIMP GetCheckboxValue(__in DWORD dwFieldID, __out BOOL* pbChecked, 52 | __deref_out PWSTR* ppwszLabel); 53 | IFACEMETHODIMP GetComboBoxValueCount(__in DWORD dwFieldID, 54 | __out DWORD* pcItems, __out_range(<,*pcItems) DWORD* pdwSelectedItem); 55 | IFACEMETHODIMP GetComboBoxValueAt(__in DWORD dwFieldID, __in DWORD dwItem, 56 | __deref_out PWSTR* ppwszItem); 57 | IFACEMETHODIMP GetSubmitButtonValue(__in DWORD dwFieldID, 58 | __out DWORD* pdwAdjacentTo); 59 | IFACEMETHODIMP SetStringValue(__in DWORD dwFieldID, __in PCWSTR pwz); 60 | IFACEMETHODIMP SetCheckboxValue(__in DWORD dwFieldID, __in BOOL bChecked); 61 | IFACEMETHODIMP SetComboBoxSelectedValue(__in DWORD dwFieldID, 62 | __in DWORD dwSelectedItem); 63 | IFACEMETHODIMP CommandLinkClicked(__in DWORD dwFieldID); 64 | IFACEMETHODIMP GetSerialization(__out CREDENTIAL_PROVIDER_GET_SERIALIZATION_RESPONSE* pcpgsr, 65 | __out CREDENTIAL_PROVIDER_CREDENTIAL_SERIALIZATION* pcpcs, 66 | __deref_out_opt PWSTR* ppwszOptionalStatusText, 67 | __out CREDENTIAL_PROVIDER_STATUS_ICON* pcpsiOptionalStatusIcon); 68 | IFACEMETHODIMP ReportResult(__in NTSTATUS ntsStatus, __in NTSTATUS ntsSubstatus, 69 | __deref_out_opt PWSTR* ppwszOptionalStatusText, 70 | __out CREDENTIAL_PROVIDER_STATUS_ICON* pcpsiOptionalStatusIcon); 71 | 72 | bool GotCredentials(); 73 | void SetCredentials(LPCWSTR wzUserName, LPCWSTR wzPassword, LPCWSTR wzDomain); 74 | void ResetCredentials(); 75 | void SetUsageScenario(CREDENTIAL_PROVIDER_USAGE_SCENARIO cpus); 76 | 77 | protected: 78 | 79 | ~OVirtCredentials(); 80 | 81 | private: 82 | LONG _cRef; 83 | CREDENTIAL_PROVIDER_USAGE_SCENARIO _cpus; 84 | PWSTR _wzUserName; 85 | PWSTR _wzDomain; 86 | PWSTR _wzPassword; 87 | }; 88 | -------------------------------------------------------------------------------- /windows-credprov/OVirtProvider.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Pch.h" 3 | 4 | #include "OVirtCredProv.h" 5 | #include "OVirtProvider.h" 6 | #include "OVirtCredentials.h" 7 | #include "Helpers.h" 8 | 9 | OVirtProvider::OVirtProvider() : 10 | _cRef(1), 11 | _pCredentialsChannel(NULL), 12 | _pOVirtCredentials(NULL), 13 | _pCredentialProviderEvents(NULL) 14 | { 15 | DllAddRef(); 16 | } 17 | 18 | OVirtProvider::~OVirtProvider() 19 | { 20 | if (_pCredentialsChannel != NULL) 21 | { 22 | delete _pCredentialsChannel; 23 | _pCredentialsChannel = NULL; 24 | } 25 | 26 | if (_pOVirtCredentials != NULL) 27 | { 28 | _pOVirtCredentials->Release(); 29 | _pOVirtCredentials = NULL; 30 | } 31 | 32 | if (_pCredentialProviderEvents != NULL) 33 | { 34 | _pCredentialProviderEvents->Release(); 35 | _pCredentialProviderEvents = NULL; 36 | } 37 | 38 | DllRelease(); 39 | } 40 | 41 | // IUnknown 42 | 43 | IFACEMETHODIMP_(ULONG) OVirtProvider::AddRef() 44 | { 45 | return ++_cRef; 46 | } 47 | 48 | IFACEMETHODIMP_(ULONG) OVirtProvider::Release() 49 | { 50 | LONG cRef = --_cRef; 51 | if (!cRef) 52 | { 53 | delete this; 54 | } 55 | return cRef; 56 | } 57 | 58 | IFACEMETHODIMP OVirtProvider::QueryInterface(__in REFIID riid, __deref_out void** ppv) 59 | { 60 | HRESULT hr; 61 | if (ppv) 62 | { 63 | if ((IID_IUnknown == riid) || (IID_ICredentialProvider == riid)) 64 | { 65 | *ppv = static_cast(this); 66 | reinterpret_cast(*ppv)->AddRef(); 67 | hr = S_OK; 68 | } 69 | else 70 | { 71 | *ppv = NULL; 72 | hr = E_NOINTERFACE; 73 | } 74 | } 75 | else 76 | { 77 | hr = E_INVALIDARG; 78 | } 79 | return hr; 80 | } 81 | 82 | // ICredentialProvider 83 | 84 | HRESULT STDMETHODCALLTYPE OVirtProvider::SetUsageScenario(CREDENTIAL_PROVIDER_USAGE_SCENARIO cpus, 85 | DWORD dwFlags) 86 | { 87 | UNREFERENCED_PARAMETER(dwFlags); 88 | 89 | HRESULT hr = E_INVALIDARG; 90 | 91 | switch (cpus) 92 | { 93 | case CPUS_LOGON: 94 | case CPUS_UNLOCK_WORKSTATION: 95 | { 96 | if ((_pOVirtCredentials == NULL) && (_pCredentialsChannel == NULL)) 97 | { 98 | _pOVirtCredentials = new OVirtCredentials(); 99 | if (_pOVirtCredentials != NULL) 100 | { 101 | _pCredentialsChannel = new CredentialsChannel(); 102 | if (_pCredentialsChannel == NULL) 103 | { 104 | _pOVirtCredentials->Release(); 105 | _pOVirtCredentials = NULL; 106 | 107 | hr = E_OUTOFMEMORY; 108 | } 109 | } 110 | else 111 | { 112 | hr = E_OUTOFMEMORY; 113 | } 114 | } 115 | 116 | if (_pOVirtCredentials != NULL) 117 | { 118 | _pOVirtCredentials->SetUsageScenario(cpus); 119 | } 120 | 121 | if (_pCredentialsChannel != NULL) 122 | { 123 | hr = _pCredentialsChannel->CreateChannel(this); 124 | } 125 | 126 | break; 127 | } 128 | 129 | case CPUS_CHANGE_PASSWORD: 130 | case CPUS_CREDUI: 131 | hr = E_NOTIMPL; 132 | break; 133 | 134 | default: 135 | hr = E_INVALIDARG; 136 | break; 137 | } 138 | 139 | return hr; 140 | } 141 | 142 | HRESULT STDMETHODCALLTYPE OVirtProvider::SetSerialization(const CREDENTIAL_PROVIDER_CREDENTIAL_SERIALIZATION *pcpcs) 143 | { 144 | UNREFERENCED_PARAMETER(pcpcs); 145 | return E_NOTIMPL; 146 | } 147 | 148 | HRESULT STDMETHODCALLTYPE OVirtProvider::Advise(ICredentialProviderEvents *pcpe, 149 | UINT_PTR upAdviseContext) 150 | { 151 | if (_pCredentialProviderEvents != NULL) 152 | { 153 | _pCredentialProviderEvents->Release(); 154 | } 155 | 156 | _pCredentialProviderEvents = pcpe; 157 | _pCredentialProviderEvents->AddRef(); 158 | _upAdviseContext = upAdviseContext; 159 | 160 | return S_OK; 161 | } 162 | 163 | HRESULT STDMETHODCALLTYPE OVirtProvider::UnAdvise() 164 | { 165 | if (_pCredentialProviderEvents != NULL) 166 | { 167 | _pCredentialProviderEvents->Release(); 168 | _pCredentialProviderEvents = NULL; 169 | } 170 | 171 | return S_OK; 172 | } 173 | 174 | HRESULT STDMETHODCALLTYPE OVirtProvider::GetFieldDescriptorCount(DWORD *pdwCount) 175 | { 176 | ASSERT(pdwCount != NULL); 177 | *pdwCount = 0; 178 | return S_OK; 179 | } 180 | 181 | HRESULT STDMETHODCALLTYPE OVirtProvider::GetFieldDescriptorAt(DWORD dwIndex, 182 | CREDENTIAL_PROVIDER_FIELD_DESCRIPTOR **ppcpfd) 183 | { 184 | UNREFERENCED_PARAMETER(dwIndex); 185 | UNREFERENCED_PARAMETER(ppcpfd); 186 | return E_NOTIMPL; 187 | } 188 | 189 | HRESULT STDMETHODCALLTYPE OVirtProvider::GetCredentialCount(DWORD *pdwCount, 190 | DWORD *pdwDefault, 191 | BOOL *pbAutoLogonWithDefault) 192 | { 193 | ASSERT(pdwCount != NULL); 194 | ASSERT(pdwDefault != NULL); 195 | ASSERT(pbAutoLogonWithDefault != NULL); 196 | 197 | *pdwCount = (_pOVirtCredentials->GotCredentials() ? 1 : 0); 198 | *pdwDefault = 0; 199 | *pbAutoLogonWithDefault = TRUE; 200 | 201 | return S_OK; 202 | } 203 | 204 | HRESULT STDMETHODCALLTYPE OVirtProvider::GetCredentialAt(DWORD dwIndex, 205 | ICredentialProviderCredential **ppcpc) 206 | { 207 | ASSERT(dwIndex < 1); 208 | ASSERT(ppcpc != NULL); 209 | ASSERT(_pOVirtCredentials != NULL); 210 | 211 | HRESULT hr; 212 | 213 | if ((dwIndex < 1) && _pOVirtCredentials && ppcpc) 214 | { 215 | hr = _pOVirtCredentials->QueryInterface( 216 | IID_ICredentialProviderCredential, reinterpret_cast(ppcpc)); 217 | } 218 | else 219 | { 220 | hr = E_INVALIDARG; 221 | } 222 | 223 | return hr; 224 | } 225 | 226 | void OVirtProvider::OnCredentialsArrivial(LPCWSTR wzUserName, LPCWSTR wzPassword, LPCWSTR wzDomain) 227 | { 228 | ASSERT(_pCredentialProviderEvents != NULL); 229 | ASSERT(_pOVirtCredentials != NULL); 230 | 231 | _pOVirtCredentials->SetCredentials(wzUserName, wzPassword, wzDomain); 232 | 233 | if (_pCredentialProviderEvents != NULL) 234 | { 235 | _pCredentialProviderEvents->CredentialsChanged(_upAdviseContext); 236 | } 237 | } 238 | 239 | HRESULT OVirtCredProv_CreateInstance(REFIID riid, void** ppv) 240 | { 241 | HRESULT hr; 242 | 243 | OVirtProvider *pProvider = new OVirtProvider(); 244 | if (pProvider != NULL) 245 | { 246 | hr = pProvider->QueryInterface(riid, ppv); 247 | pProvider->Release(); 248 | } 249 | else 250 | { 251 | hr = E_OUTOFMEMORY; 252 | } 253 | 254 | return hr; 255 | } 256 | -------------------------------------------------------------------------------- /windows-credprov/OVirtProvider.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include 5 | 6 | #include "CredentialsChannel.h" 7 | 8 | #ifndef __in 9 | #define __in 10 | #endif 11 | #ifndef __deref_out 12 | #define __deref_out 13 | #endif 14 | 15 | class OVirtCredentials; 16 | 17 | class OVirtProvider : public ICredentialProvider, public CredChannelListener 18 | { 19 | public: 20 | 21 | // IUnknown 22 | 23 | IFACEMETHODIMP_(ULONG) AddRef(); 24 | IFACEMETHODIMP_(ULONG) Release(); 25 | IFACEMETHODIMP QueryInterface(__in REFIID riid, __deref_out void** ppv); 26 | 27 | // ICredentialProvider 28 | 29 | HRESULT STDMETHODCALLTYPE SetUsageScenario(CREDENTIAL_PROVIDER_USAGE_SCENARIO cpus, DWORD dwFlags); 30 | HRESULT STDMETHODCALLTYPE SetSerialization(const CREDENTIAL_PROVIDER_CREDENTIAL_SERIALIZATION *pcpcs); 31 | HRESULT STDMETHODCALLTYPE Advise(ICredentialProviderEvents *pcpe, UINT_PTR upAdviseContext); 32 | HRESULT STDMETHODCALLTYPE UnAdvise(); 33 | HRESULT STDMETHODCALLTYPE GetFieldDescriptorCount(DWORD *pdwCount); 34 | HRESULT STDMETHODCALLTYPE GetFieldDescriptorAt(DWORD dwIndex, CREDENTIAL_PROVIDER_FIELD_DESCRIPTOR **ppcpfd); 35 | HRESULT STDMETHODCALLTYPE GetCredentialCount(DWORD *pdwCount, DWORD *pdwDefault, BOOL *pbAutoLogonWithDefault); 36 | HRESULT STDMETHODCALLTYPE GetCredentialAt(DWORD dwIndex, ICredentialProviderCredential **ppcpc); 37 | 38 | // CredChannelListener 39 | 40 | virtual void OnCredentialsArrivial(LPCWSTR wzUserName, LPCWSTR wzPassword, LPCWSTR wzDomain); 41 | 42 | friend HRESULT OVirtCredProv_CreateInstance(REFIID riid, __deref_out void** ppv); 43 | 44 | protected: 45 | OVirtProvider(); 46 | ~OVirtProvider(); 47 | 48 | private: 49 | LONG _cRef; 50 | CredentialsChannel *_pCredentialsChannel; 51 | OVirtCredentials *_pOVirtCredentials; 52 | ICredentialProviderEvents *_pCredentialProviderEvents; 53 | UINT_PTR _upAdviseContext; 54 | }; 55 | -------------------------------------------------------------------------------- /windows-credprov/Pch.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Pch.h" 3 | -------------------------------------------------------------------------------- /windows-credprov/Pch.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | // The OVirt Credentials Provider should be used on Windows Vista and above. 5 | #define _WIN32_WINNT 0x0600 6 | #define WINVER 0x0600 7 | 8 | #include 9 | #include 10 | 11 | #include 12 | 13 | #ifdef _DEBUG 14 | #define ASSERT(x) assert(x) 15 | #define VERIFY(x) ASSERT(x) 16 | #else 17 | #define ASSERT(x) 18 | #define VERIFY(x) (x) 19 | #endif 20 | -------------------------------------------------------------------------------- /windows-credprov/README: -------------------------------------------------------------------------------- 1 | How to produce the credentialprovider.h 2 | ======================================= 3 | 4 | The credentials provider header file has been generated from the IDL file 5 | provided in the Windows SDK 6 | 7 | Which can be retrieved from this (ca 1.4 GiB) ISO: 8 | 9 | http://www.microsoft.com/en-us/download/details.aspx?id=18950 10 | 11 | The IDL file is located on the ISO in /Setup/WinSDKBuild/cab2.cab and is called 12 | credentialprovider.idl 13 | 14 | The header file has been generated on Fedora with help of the following packags: 15 | 16 | - wine-devel 17 | - mingw-w64-tools 18 | 19 | The command to produce the header file from the IDL file is the following: 20 | $ x86_64-w64-mingw32-widl -I /usr/include/wine/windows/ -h ./credentialprovider.idl -o credentialprovider.h 21 | 22 | 23 | Where to get the intsafe.h header 24 | ================================= 25 | 26 | https://svn.reactos.org/svn/reactos/trunk/reactos/sdk/include/psdk/ 27 | -------------------------------------------------------------------------------- /windows-credprov/Register.reg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oVirt/ovirt-guest-agent/639a30df2d607011c367a451cb4179e8370cd6a0/windows-credprov/Register.reg -------------------------------------------------------------------------------- /windows-credprov/Unregister.reg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oVirt/ovirt-guest-agent/639a30df2d607011c367a451cb4179e8370cd6a0/windows-credprov/Unregister.reg -------------------------------------------------------------------------------- /windows-credprov/afxres.h: -------------------------------------------------------------------------------- 1 | #ifndef OVIRT_AGENT_CREDPROV_AFXRES_H_INCLUDED 2 | #define OVIRT_AGENT_CREDPROV_AFXRES_H_INCLUDED 3 | 4 | #include 5 | 6 | #ifndef IDC_STATIC 7 | # define IDC_STATIC (-1) 8 | #endif 9 | 10 | #endif //OVIRT_AGENT_CREDPROV_AFXRES_H_INCLUDED 11 | -------------------------------------------------------------------------------- /windows-credprov/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by OVirtCredProv.rc 4 | 5 | // Next default values for new objects 6 | // 7 | #ifdef APSTUDIO_INVOKED 8 | #ifndef APSTUDIO_READONLY_SYMBOLS 9 | #define _APS_NEXT_RESOURCE_VALUE 101 10 | #define _APS_NEXT_COMMAND_VALUE 40001 11 | #define _APS_NEXT_CONTROL_VALUE 1001 12 | #define _APS_NEXT_SYMED_VALUE 101 13 | #endif 14 | #endif 15 | --------------------------------------------------------------------------------