Revert "Remove contra productive _string_check"

This reverts commit b06a6c4c8e61013b7461c6fc946c1530ae47584e.
The previous commit breaks the guest agent badly because the
string type is required to be unicode, this code previously was
converting it most of the times to unicode, however in some cases
it won't do so and causes the data to be an ascii string or even
replaces valid characters even though it should not.

The attempt for fixing this issue will be addressed by a new patch.

Change-Id: I47176ac60e069e7d557312d7047d9bc4b15ac768
Signed-off-by: Vinzenz Feenstra <vfeenstr@redhat.com>
Adding Unit Tests and Functional Tests

The functional tests so far are testing the retrieval
of data from the underlying system and ensures the structure
of the data. It does not however validate the content.
It ensures that the messages sent over the VirtIO Serial
channel have the format defined.
If we change the format it will break the unit tests.

Additionally a check for the unicode filtering.

Change-Id: I4c1d740c948e33aed8a04a1013b22276cf7d85e3
Signed-off-by: Vinzenz Feenstra <vfeenstr@redhat.com>
Replaced String check with string conversion

Currently the string_check is destroying the data when the system
is not able to convert them properly.
This is now fixed by allowing unicode strings as they are
and an attempt of decoding input (non-unicode) strings based
on the prefered locale encoding.

If this will fail, the replacement of unknown characters are applied.

In any case an unicode string is created. If the string is not
convertible, the return value will be "????" as a replacement.
This however is the last resort, to allow at least some level of
data to go through. (e.g. when the application list contains one
invalid data string currently it would cause the whole list NOT to
be sent. Now it will be sent)

Please also note that this commit will fix the failing unit tests.

Change-Id: Ie277069cbfa39f9735a2b85b9e9da9c3fcfe5938
Signed-off-by: Vinzenz Feenstra <vfeenstr@redhat.com>
Packaging: Add the missing dependencies

automake and pkg-confg are needed when building ovirt-guest-agent in a
fresh Ubuntu environment.

This patch also split each dependency to separated lines. The debhelper
is a boilerplate so leave it at the first line. The other lines are
custom dependencies so sort them to make it easier to maintain.

Change-Id: I90f86100946c5b60cc816e664a2857cad5b4b0f5
Signed-off-by: Zhou Zheng Sheng <zhshzhou@linux.vnet.ibm.com>
agent: Fix python-2.4 compatibility

Rewrote the use of ternary operator to if since it is not
supported in python-2.4.

Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=1006861
Change-Id: I03c63477a2d2bcb9eb4c4307946a3486300663e1
Signed-off-by: Martin Betak <mbetak@redhat.com>
Ubuntu Packaging: add python-apt to dependency

In ovirt-guest-agent/GuestAgentLinux2.py we try to import apt module.
This module is provided by python-apt on Debian and Ubuntu. This patch
adds python-apt to package dependency.

Change-Id: I7a248b43c541ded03a26625896881d89a0d6401d
Signed-off-by: Zhou Zheng Sheng <zhshzhou@linux.vnet.ibm.com>
Ubuntu packaging: add python-nose to build requirements

"make check" during the build process runs tests which import
python-nose modules.

Change-Id: I529b4fe19e191cf2551943f2ed132edee7349ac0
Signed-off-by: Zhou Zheng Sheng <zhshzhou@linux.vnet.ibm.com>
Fixed package name in ovirt-guest-agent.conf

The package is called ovirt-guest-agent-common now, if searched for
the package in the package database.

Change-Id: Ia647838379e5823a8451721ed3f76c248e59e234
Signed-off-by: Vinzenz Feenstra <vfeenstr@redhat.com>
agent: Report swap usage of the guests

Change-Id: I09f1c0dbbe12eee352637c97a4fa23835d14307a
Bug-Url: https://bugzilla.redhat.com/1025845
Signed-off-by: Vinzenz Feenstra <vfeenstr@redhat.com>
Update README-windows.txt

python OVirtGuestService.py install should be without "-" near install to work as expected. Tested on 3.3. and windows 2003 and 2008

Change-Id: I0e5eb8a6a78a9a6c1a036a4fb451e75bb6fb2d3e
Signed-off-by: Vinzenz Feenstra <vfeenstr@redhat.com>
pam: Fix the pam conversation approach

Until now our PAM conversation was errorneous using pam_get_user
which is not correct for requests other than accquiring the username.

To correctly request the Token from the frontend we have to use a PAM
conversation. This is done via the pam_prompt function.

We also do check now, if the requesting user (if set) is identical with
the preset user. If this is not the case we will not unlock the screen.
Preset users should only be available if the screen was locked.
If the usernames aren't equal, the module will return PAM_CRED_UNAVAIL.

Additionally the logging was rewritten to use the syslog and more comments
have been added to describe the steps we're doing.

Change-Id: I4455ea61ffb27e854fe93bdc51068e12617955a2
Signed-off-by: Vinzenz Feenstra <vfeenstr@redhat.com>
agent: handle failures on Windows' write requests.

Windows' virtio-serial driver behavior was changed so a write
request when the host is not connected results in immediate
return with an error.

Change-Id: I28ca3c1115f6b18295a29d1f87bf3144c00759e1
Signed-off-by: Gal Hammer <ghammer@redhat.com>
Bug-Url: https://bugzilla.redhat.com/1026474
packaging: Depend on the qemu-guest-agent

For support of freezing and thawing the filesystem for the
Backup and Restore API feature of oVirt

Change-Id: I4c550801326dfa0b8d9357770f48a6d9b64eb3a1
Bug-Url: https://bugzilla.redhat.com/1055524
Signed-off-by: Vinzenz Feenstra <vfeenstr@redhat.com>
Build fixes

* Don't execute PEP8 checks when PEP8 is not installed
* configure.ac: Don't fail on systems where AM_PROG_AR is not yet
  available in automake
* m4/fhs.m4 don't fail if neither /var/lock/subsys nor /var/lock
  are present

Change-Id: Iaa33a029b2e8fbbbd2e1329814dd8dc182109552
Signed-off-by: Vinzenz Feenstra <vfeenstr@redhat.com>
Version 1.0.9 update

Change-Id: I4a914522846fb879ed09c47992bc5f13d0456ead
Signed-off-by: Vinzenz Feenstra <vfeenstr@redhat.com>
Implementation of logind based session locking

Support screen lock for logind based systems, since ConsoleKit
is no longer developed in the long run this will be the way to
go.

Change-Id: Iafc4b88d9c508647e1d09407556359fbefbba34c
Signed-off-by: Vinzenz Feenstra <vfeenstr@redhat.com>
agent: Implement basics for API Versioning

This commit introduces the basics needed to support API versioning between
the ovirt-guest-agent and VDSM.

How the negotiation works:
- VDSM has as a default the apiVersion value set to _DISABLED_API_VALUE marking
  it as unsupported
- The guest agent sends its max supported version with every `heartbeat`
  message
- VDSM checks that `apiVersion` exists in the `heartbeat` message arguments
  - If it exists it retrieves the minimum common version and sends the
    `api-version` message with the common version as `apiVersion` argument
  - If it does NOT exist it and the apiVersion is not set to
    _DISABLED_API_VALUE it will set it to _DISABLED_API_VALUE, with the meaning
    that it is not supported at all by the guest agent on the other end.
- The guest agent on receiving this message makes it own check and sets the
  `apiVersion` to the commonVersion

- If VDSM sends the `refresh` command it also sends its `apiVersion` value
  however if it does not, capable guest agents are disabling the versioning
  support and will know it in pre-supported state as well.

NOTE: VDSM will never send an api-version message without being triggered.
      This is to ensure backwards compatibility.

Change-Id: I754d52009538914dd0143894b24ad48fbf13cb38
Signed-off-by: Vinzenz Feenstra <vfeenstr@redhat.com>
agent: Report number of CPU cores visible online on the guest OS

This patches a new message and increases the Guest Agent API to
version 1.

The new message has this format:
{"__name__": "number-of-cpus", "count": <int>}

The reported number 'count' is the number of visible online CPU cores
on the guest OS system.

Change-Id: Ief777608519a35319665c4cd0f580b7b38305b3e
Guest-Agent-API-Version: 1
Bug-URL: https://bugzilla.redhat.com/show_bug.cgi?id=1063280
Signed-off-by: Vinzenz Feenstra <vfeenstr@redhat.com>
win32: Retrieve the active session through enumeration

Using WTSGetActiveConsoleSessionId() does in case of RDP connections give
a session id which is not corresponding to the users session in some cases.
By enumerating through the sessions and retriving the session with the 'State'
'WTSActive' we are able to reliably retrieve the current active session.
This is required in order to get the logged-in user and being able to retrieve
the user token for performing operations in their name.

Change-Id: I569d4b6b80e102b83b7e6e39c12524f2d588ad37
Bug-Url: https://bugzilla.redhat.com/1068750
Signed-off-by: Vinzenz Feenstra <vfeenstr@redhat.com>
Added support for sudo

This patch introduces configure controlled choice of the elevation mechanism
used on the system.

configure has now a new option --with-sudohelper=[usermode|sudo]

Values:
 - usermode: elevation via consolehelper and pam
 - sudo: elevation via sudo

Change-Id: I202c1bbea8c95f5ad12edb4959a7d614c89ea246
Bug-Url: https://bugzilla.redhat.com/1043471
Signed-off-by: Vinzenz Feenstra <vfeenstr@redhat.com>