1 | /* $Id: hostversion.cpp 86874 2020-11-12 10:54:39Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * X11 guest client - Host version check.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2011-2020 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 | #include <stdio.h>
|
---|
18 | #include <iprt/assert.h>
|
---|
19 | #include <iprt/errcore.h>
|
---|
20 | #include <iprt/mem.h>
|
---|
21 | #include <iprt/ldr.h>
|
---|
22 | #include <iprt/string.h>
|
---|
23 | #include <iprt/thread.h>
|
---|
24 |
|
---|
25 | #ifdef VBOX_WITH_DBUS
|
---|
26 | # include <VBox/dbus.h>
|
---|
27 | #endif
|
---|
28 | #include <VBox/log.h>
|
---|
29 | #include <VBox/VBoxGuestLib.h>
|
---|
30 | #ifdef VBOX_OSE
|
---|
31 | # include <VBox/version.h>
|
---|
32 | #endif
|
---|
33 |
|
---|
34 | #include "VBoxClient.h"
|
---|
35 |
|
---|
36 | static int showNotify(const char *pszHeader, const char *pszBody)
|
---|
37 | {
|
---|
38 | int rc;
|
---|
39 | # ifdef VBOX_WITH_DBUS
|
---|
40 | DBusConnection *conn;
|
---|
41 | DBusMessage* msg = NULL;
|
---|
42 | conn = dbus_bus_get(DBUS_BUS_SESSION, NULL);
|
---|
43 | if (conn == NULL)
|
---|
44 | {
|
---|
45 | VBClLogError("Could not retrieve D-BUS session bus\n");
|
---|
46 | rc = VERR_INVALID_HANDLE;
|
---|
47 | }
|
---|
48 | else
|
---|
49 | {
|
---|
50 | msg = dbus_message_new_method_call("org.freedesktop.Notifications",
|
---|
51 | "/org/freedesktop/Notifications",
|
---|
52 | "org.freedesktop.Notifications",
|
---|
53 | "Notify");
|
---|
54 | if (msg == NULL)
|
---|
55 | {
|
---|
56 | VBClLogError("Could not create D-BUS message!\n");
|
---|
57 | rc = VERR_INVALID_HANDLE;
|
---|
58 | }
|
---|
59 | else
|
---|
60 | rc = VINF_SUCCESS;
|
---|
61 | }
|
---|
62 | if (RT_SUCCESS(rc))
|
---|
63 | {
|
---|
64 | uint32_t msg_replace_id = 0;
|
---|
65 | const char *msg_app = "VBoxClient";
|
---|
66 | const char *msg_icon = "";
|
---|
67 | const char *msg_summary = pszHeader;
|
---|
68 | const char *msg_body = pszBody;
|
---|
69 | int32_t msg_timeout = -1; /* Let the notification server decide */
|
---|
70 |
|
---|
71 | DBusMessageIter iter;
|
---|
72 | DBusMessageIter array;
|
---|
73 | /*DBusMessageIter dict; - unused */
|
---|
74 | /*DBusMessageIter value; - unused */
|
---|
75 | /*DBusMessageIter variant; - unused */
|
---|
76 | /*DBusMessageIter data; - unused */
|
---|
77 |
|
---|
78 | /* Format: UINT32 org.freedesktop.Notifications.Notify
|
---|
79 | * (STRING app_name, UINT32 replaces_id, STRING app_icon, STRING summary, STRING body,
|
---|
80 | * ARRAY actions, DICT hints, INT32 expire_timeout)
|
---|
81 | */
|
---|
82 | dbus_message_iter_init_append(msg,&iter);
|
---|
83 | dbus_message_iter_append_basic(&iter,DBUS_TYPE_STRING,&msg_app);
|
---|
84 | dbus_message_iter_append_basic(&iter,DBUS_TYPE_UINT32,&msg_replace_id);
|
---|
85 | dbus_message_iter_append_basic(&iter,DBUS_TYPE_STRING,&msg_icon);
|
---|
86 | dbus_message_iter_append_basic(&iter,DBUS_TYPE_STRING,&msg_summary);
|
---|
87 | dbus_message_iter_append_basic(&iter,DBUS_TYPE_STRING,&msg_body);
|
---|
88 | dbus_message_iter_open_container(&iter,DBUS_TYPE_ARRAY,DBUS_TYPE_STRING_AS_STRING,&array);
|
---|
89 | dbus_message_iter_close_container(&iter,&array);
|
---|
90 | dbus_message_iter_open_container(&iter,DBUS_TYPE_ARRAY,"{sv}",&array);
|
---|
91 | dbus_message_iter_close_container(&iter,&array);
|
---|
92 | dbus_message_iter_append_basic(&iter,DBUS_TYPE_INT32,&msg_timeout);
|
---|
93 |
|
---|
94 | DBusError err;
|
---|
95 | dbus_error_init(&err);
|
---|
96 |
|
---|
97 | DBusMessage *reply;
|
---|
98 | reply = dbus_connection_send_with_reply_and_block(conn, msg, 30 * 1000 /* 30 seconds timeout */, &err);
|
---|
99 | if (dbus_error_is_set(&err))
|
---|
100 | VBClLogError("D-BUS returned an error while sending the notification: %s", err.message);
|
---|
101 | else if (reply)
|
---|
102 | {
|
---|
103 | dbus_connection_flush(conn);
|
---|
104 | dbus_message_unref(reply);
|
---|
105 | }
|
---|
106 | if (dbus_error_is_set(&err))
|
---|
107 | dbus_error_free(&err);
|
---|
108 | }
|
---|
109 | if (msg != NULL)
|
---|
110 | dbus_message_unref(msg);
|
---|
111 | # else
|
---|
112 | /** @todo Implement me */
|
---|
113 | RT_NOREF(pszHeader, pszBody);
|
---|
114 | rc = VINF_SUCCESS;
|
---|
115 | # endif /* VBOX_WITH_DBUS */
|
---|
116 | return rc;
|
---|
117 | }
|
---|
118 |
|
---|
119 | /**
|
---|
120 | * @interface_method_impl{VBCLSERVICE,pfnWorker}
|
---|
121 | */
|
---|
122 | static DECLCALLBACK(int) vbclHostVerWorker(bool volatile *pfShutdown)
|
---|
123 | {
|
---|
124 | /** @todo Move this part in VbglR3 and just provide a callback for the platform-specific
|
---|
125 | notification stuff, since this is very similar to the VBoxTray code. */
|
---|
126 |
|
---|
127 | RT_NOREF(pfShutdown);
|
---|
128 |
|
---|
129 | LogFlowFuncEnter();
|
---|
130 |
|
---|
131 | int rc;
|
---|
132 | # ifdef VBOX_WITH_DBUS
|
---|
133 | rc = RTDBusLoadLib();
|
---|
134 | if (RT_FAILURE(rc))
|
---|
135 | VBClLogError("D-Bus seems not to be installed; no host version check/notification done\n");
|
---|
136 | # else
|
---|
137 | rc = VERR_NOT_IMPLEMENTED;
|
---|
138 | # endif /* VBOX_WITH_DBUS */
|
---|
139 |
|
---|
140 | # ifdef VBOX_WITH_GUEST_PROPS
|
---|
141 | uint32_t uGuestPropSvcClientID;
|
---|
142 | if (RT_SUCCESS(rc))
|
---|
143 | {
|
---|
144 | rc = VbglR3GuestPropConnect(&uGuestPropSvcClientID);
|
---|
145 | if (RT_FAILURE(rc))
|
---|
146 | VBClLogError("Cannot connect to guest property service while chcking for host version, rc = %Rrc\n", rc);
|
---|
147 | }
|
---|
148 |
|
---|
149 | if (RT_SUCCESS(rc))
|
---|
150 | {
|
---|
151 | /* Let the main thread know that it can continue spawning services. */
|
---|
152 | RTThreadUserSignal(RTThreadSelf());
|
---|
153 |
|
---|
154 | /* Because we need desktop notifications to be displayed, wait
|
---|
155 | * some time to make the desktop environment load (as a work around). */
|
---|
156 | if (g_fDaemonized)
|
---|
157 | RTThreadSleep(RT_MS_30SEC);
|
---|
158 |
|
---|
159 | char *pszHostVersion;
|
---|
160 | char *pszGuestVersion;
|
---|
161 | bool fUpdate;
|
---|
162 |
|
---|
163 | rc = VbglR3HostVersionCheckForUpdate(uGuestPropSvcClientID, &fUpdate, &pszHostVersion, &pszGuestVersion);
|
---|
164 | if (RT_SUCCESS(rc))
|
---|
165 | {
|
---|
166 | if (fUpdate)
|
---|
167 | {
|
---|
168 | char szMsg[1024];
|
---|
169 | char szTitle[64];
|
---|
170 |
|
---|
171 | /** @todo add some translation macros here */
|
---|
172 | RTStrPrintf(szTitle, sizeof(szTitle), "VirtualBox Guest Additions update available!");
|
---|
173 | #ifndef VBOX_OSE
|
---|
174 | RTStrPrintf(szMsg, sizeof(szMsg), "Your guest is currently running the Guest Additions version %s. "
|
---|
175 | "We recommend updating to the latest version (%s) by choosing the "
|
---|
176 | "install option from the Devices menu.", pszGuestVersion, pszHostVersion);
|
---|
177 | #else
|
---|
178 | /* This is the message which appears for non-Oracle builds of the
|
---|
179 | * Guest Additions. Distributors are encouraged to customise this. */
|
---|
180 | RTStrPrintf(szMsg, sizeof(szMsg), "Your virtual machine is currently running the Guest Additions version %s. Since you are running a version of the Guest Additions provided by the operating system you installed in the virtual machine we recommend that you update it to at least version %s using that system's update features, or alternatively that you remove this version and then install the " VBOX_VENDOR_SHORT " Guest Additions package using the install option from the Devices menu. Please consult the documentation for the operating system you are running to find out how to update or remove the current Guest Additions package.", pszGuestVersion, pszHostVersion);
|
---|
181 | #endif
|
---|
182 | rc = showNotify(szTitle, szMsg);
|
---|
183 | VBClLogInfo("VirtualBox Guest Additions update available!\n");
|
---|
184 | if (RT_FAILURE(rc))
|
---|
185 | VBClLogError("Could not show version notifier tooltip! rc = %d\n", rc);
|
---|
186 | }
|
---|
187 |
|
---|
188 | /* Store host version to not notify again */
|
---|
189 | rc = VbglR3HostVersionLastCheckedStore(uGuestPropSvcClientID, pszHostVersion);
|
---|
190 |
|
---|
191 | VbglR3GuestPropReadValueFree(pszHostVersion);
|
---|
192 | VbglR3GuestPropReadValueFree(pszGuestVersion);
|
---|
193 | }
|
---|
194 | VbglR3GuestPropDisconnect(uGuestPropSvcClientID);
|
---|
195 | }
|
---|
196 | # endif /* VBOX_WITH_GUEST_PROPS */
|
---|
197 |
|
---|
198 | return rc;
|
---|
199 | }
|
---|
200 |
|
---|
201 | VBCLSERVICE g_SvcHostVersion =
|
---|
202 | {
|
---|
203 | "hostversion", /* szName */
|
---|
204 | "VirtualBox host version check", /* pszDescription */
|
---|
205 | ".vboxclient-hostversion.pid", /* pszPidFilePath */
|
---|
206 | NULL, /* pszUsage */
|
---|
207 | NULL, /* pszOptions */
|
---|
208 | NULL, /* pfnOption */
|
---|
209 | NULL, /* pfnInit */
|
---|
210 | vbclHostVerWorker, /* pfnWorker */
|
---|
211 | NULL, /* pfnStop*/
|
---|
212 | NULL /* pfnTerm */
|
---|
213 | };
|
---|
214 |
|
---|