VirtualBox

source: vbox/trunk/src/VBox/Additions/linux/lightdm-greeter/vbox-greeter.cpp@ 85416

Last change on this file since 85416 was 82968, checked in by vboxsync, 5 years ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 51.2 KB
Line 
1/* $Id: vbox-greeter.cpp 82968 2020-02-04 10:35:17Z vboxsync $ */
2/** @file
3 * vbox-greeter - an own LightDM greeter module supporting auto-logons
4 * controlled by the host.
5 */
6
7/*
8 * Copyright (C) 2012-2020 Oracle Corporation
9 *
10 * This file is part of VirtualBox Open Source Edition (OSE), as
11 * available from http://www.virtualbox.org. This file is free software;
12 * you can redistribute it and/or modify it under the terms of the GNU
13 * General Public License (GPL) as published by the Free Software
14 * Foundation, in version 2 as it comes in the "COPYING" file of the
15 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
16 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
17 */
18
19
20/*********************************************************************************************************************************
21* Header Files *
22*********************************************************************************************************************************/
23#define GLIB_DISABLE_DEPRECATION_WARNINGS 1 /* g_type_init() is deprecated */
24#include <pwd.h>
25#include <syslog.h>
26#include <stdlib.h>
27
28#include <lightdm.h>
29#ifdef VBOX_WITH_FLTK
30# include <FL/Fl.H>
31# include <FL/fl_ask.H> /* Yes, the casing is correct for 1.3.0 -- d'oh. */
32# include <FL/Fl_Box.H>
33# include <FL/Fl_Button.H>
34# include <FL/fl_draw.H> /* Same as above. */
35# include <FL/Fl_Double_Window.H>
36# include <FL/Fl_Input.H>
37# include <FL/Fl_Menu_Button.H>
38# ifdef VBOX_GREETER_WITH_PNG_SUPPORT
39# include <FL/Fl_PNG_Image.H>
40# include <FL/Fl_Shared_Image.H>
41# endif
42# include <FL/Fl_Secret_Input.H>
43#else
44# include <cairo-xlib.h>
45# include <gtk/gtk.h>
46# include <gdk/gdkx.h>
47#endif
48
49#include <package-generated.h>
50#include "product-generated.h"
51
52#include <iprt/assert.h>
53#include <iprt/buildconfig.h>
54#include <iprt/env.h>
55#include <iprt/file.h>
56#include <iprt/getopt.h>
57#include <iprt/initterm.h>
58#include <iprt/mem.h>
59#include <iprt/message.h>
60#include <iprt/path.h>
61#include <iprt/process.h>
62#include <iprt/stream.h>
63#include <iprt/system.h>
64#include <iprt/string.h>
65#include <iprt/thread.h>
66#include <iprt/time.h>
67
68#include <VBox/log.h>
69#include <VBox/VBoxGuestLib.h>
70
71/* The greeter's full name for logging. */
72#define VBOX_MODULE_NAME "vbox-lightdm-greeter"
73
74/* UI elements used in this greeter. */
75#define VBOX_GREETER_UI_WND_GREETER "wnd_greeter"
76
77#define VBOX_GREETER_UI_EDT_USER "edt_username"
78#define VBOX_GREETER_UI_EDT_PASSWORD "edt_password"
79#define VBOX_GREETER_UI_BTN_LOGIN "btn_login"
80#define VBOX_GREETER_UI_LBL_INFO "lbl_info"
81
82/* UI display options. */
83/** Show the restart menu entry / button. */
84#define VBOX_GREETER_UI_SHOW_RESTART RT_BIT(0)
85/** Show the shutdown menu entry / button. */
86#define VBOX_GREETER_UI_SHOW_SHUTDOWN RT_BIT(1)
87/** Show the (customized) top banner. */
88#define VBOX_GREETER_UI_SHOW_BANNER RT_BIT(2)
89/** Enable custom colors */
90#define VBOX_GREETER_UI_USE_THEMING RT_BIT(3)
91
92/** Extracts the 8-bit red component from an uint32_t. */
93#define VBOX_RGB_COLOR_RED(uColor) uColor & 0xFF
94/** Extracts the 8-bit green component from an uint32_t. */
95#define VBOX_RGB_COLOR_GREEN(uColor) (uColor >> 8) & 0xFF
96/** Extracts the 8-bit blue component from an uint32_t. */
97#define VBOX_RGB_COLOR_BLUE(uColor) (uColor >> 16) & 0xFF
98
99#include <VBox/log.h>
100#ifdef VBOX_WITH_GUEST_PROPS
101# include <VBox/HostServices/GuestPropertySvc.h>
102#endif
103
104/** The program name (derived from argv[0]). */
105char *g_pszProgName = (char *)"";
106/** For debugging. */
107#ifdef DEBUG
108 static int g_iVerbosity = 99;
109#else
110 static int g_iVerbosity = 0;
111#endif
112static bool g_fRunning = true;
113
114/** Logging parameters. */
115/** @todo Make this configurable later. */
116static PRTLOGGER g_pLoggerRelease = NULL;
117static uint32_t g_cHistory = 10; /* Enable log rotation, 10 files. */
118static uint32_t g_uHistoryFileTime = RT_SEC_1DAY; /* Max 1 day per file. */
119static uint64_t g_uHistoryFileSize = 100 * _1M; /* Max 100MB per file. */
120
121/**
122 * Context structure which contains all needed
123 * data within callbacks.
124 */
125typedef struct VBOXGREETERCTX
126{
127 /** Pointer to this greeter instance. */
128 LightDMGreeter *pGreeter;
129#ifdef VBOX_WITH_FLTK
130 Fl_Button *pBtnLogin;
131 Fl_Input *pEdtUsername;
132 Fl_Secret_Input *pEdtPassword;
133 Fl_Box *pLblInfo;
134#else
135 /** The GTK builder instance for accessing
136 * the UI elements. */
137 GtkBuilder *pBuilder;
138#endif
139 /** The timeout (in ms) to wait for credentials. */
140 uint32_t uTimeoutMS;
141 /** The starting timestamp (in ms) to calculate
142 * the timeout. */
143 uint64_t uStartMS;
144 /** Timestamp of last abort message. */
145 uint64_t uTsAbort;
146 /** The HGCM client ID. */
147 uint32_t uClientId;
148 /** The credential password. */
149 char *pszPassword;
150} VBOXGREETERCTX, *PVBOXGREETERCTX;
151
152static void vboxGreeterError(const char *pszFormat, ...)
153{
154 va_list va;
155 char *buf;
156 va_start(va, pszFormat);
157 if (RTStrAPrintfV(&buf, pszFormat, va))
158 {
159 RTLogRelPrintf("%s: error: %s", VBOX_MODULE_NAME, buf);
160 RTStrFree(buf);
161 }
162 va_end(va);
163}
164
165static void vboxGreeterLog(const char *pszFormat, ...)
166{
167 if (g_iVerbosity)
168 {
169 va_list va;
170 char *buf;
171 va_start(va, pszFormat);
172 if (RTStrAPrintfV(&buf, pszFormat, va))
173 {
174 /* Only do normal logging in debug mode; could contain
175 * sensitive data! */
176 RTLogRelPrintf("%s: %s", VBOX_MODULE_NAME, buf);
177 RTStrFree(buf);
178 }
179 va_end(va);
180 }
181}
182
183/** @tood Move the following two functions to VbglR3 (also see pam_vbox). */
184#ifdef VBOX_WITH_GUEST_PROPS
185
186/**
187 * Reads a guest property.
188 *
189 * @return IPRT status code.
190 * @param hPAM PAM handle.
191 * @param uClientID Guest property service client ID.
192 * @param pszKey Key (name) of guest property to read.
193 * @param fReadOnly Indicates whether this key needs to be
194 * checked if it only can be read (and *not* written)
195 * by the guest.
196 * @param pszValue Buffer where to store the key's value.
197 * @param cbValue Size of buffer (in bytes).
198 * @param puTimestamp Timestamp of the value
199 * retrieved. Optional.
200 */
201static int vbox_read_prop(uint32_t uClientID,
202 const char *pszKey, bool fReadOnly,
203 char *pszValue, size_t cbValue, uint64_t *puTimestamp)
204{
205 AssertReturn(uClientID, VERR_INVALID_PARAMETER);
206 AssertPtrReturn(pszKey, VERR_INVALID_POINTER);
207 AssertPtrReturn(pszValue, VERR_INVALID_POINTER);
208 /* puTimestamp is optional. */
209
210 int rc;
211
212 uint64_t u64Timestamp = 0;
213 char *pszValTemp = NULL;
214 char *pszFlags = NULL;
215 /* The buffer for storing the data and its initial size. We leave a bit
216 * of space here in case the maximum values are raised. */
217 void *pvBuf = NULL;
218 uint32_t cbBuf = GUEST_PROP_MAX_VALUE_LEN + GUEST_PROP_MAX_FLAGS_LEN + _1K;
219
220 /* Because there is a race condition between our reading the size of a
221 * property and the guest updating it, we loop a few times here and
222 * hope. Actually this should never go wrong, as we are generous
223 * enough with buffer space. */
224 for (unsigned i = 0; i < 10; i++)
225 {
226 pvBuf = RTMemRealloc(pvBuf, cbBuf);
227 if (pvBuf)
228 {
229 rc = VbglR3GuestPropRead(uClientID, pszKey, pvBuf, cbBuf,
230 &pszValTemp, &u64Timestamp, &pszFlags,
231 &cbBuf);
232 }
233 else
234 rc = VERR_NO_MEMORY;
235
236 switch (rc)
237 {
238 case VERR_BUFFER_OVERFLOW:
239 {
240 /* Buffer too small, try it with a bigger one next time. */
241 cbBuf += _1K;
242 continue; /* Try next round. */
243 }
244
245 default:
246 break;
247 }
248
249 /* Everything except VERR_BUFFER_OVERLOW makes us bail out ... */
250 break;
251 }
252
253 if (RT_SUCCESS(rc))
254 {
255 /* Check security bits. */
256 if (pszFlags)
257 {
258 if ( fReadOnly
259 && !RTStrStr(pszFlags, "RDONLYGUEST"))
260 {
261 /* If we want a property which is read-only on the guest
262 * and it is *not* marked as such, deny access! */
263 rc = VERR_ACCESS_DENIED;
264 }
265 }
266 else /* No flags, no access! */
267 rc = VERR_ACCESS_DENIED;
268
269 if (RT_SUCCESS(rc))
270 {
271 /* If everything went well copy property value to our destination buffer. */
272 if (!RTStrPrintf(pszValue, cbValue, "%s", pszValTemp))
273 rc = VERR_BUFFER_OVERFLOW;
274
275 if (puTimestamp)
276 *puTimestamp = u64Timestamp;
277 }
278 }
279
280#ifdef DEBUG
281 vboxGreeterLog("Read guest property \"%s\"=\"%s\" (Flags: %s, TS: %RU64): %Rrc\n",
282 pszKey, pszValTemp ? pszValTemp : "<None>",
283 pszFlags ? pszFlags : "<None>", u64Timestamp, rc);
284#endif
285
286 if (pvBuf)
287 RTMemFree(pvBuf);
288
289 return rc;
290}
291
292# if 0 /* unused */
293/**
294 * Waits for a guest property to be changed.
295 *
296 * @return IPRT status code.
297 * @param hPAM PAM handle.
298 * @param uClientID Guest property service client ID.
299 * @param pszKey Key (name) of guest property to wait for.
300 * @param uTimeoutMS Timeout (in ms) to wait for the change. Specify
301 * RT_INDEFINITE_WAIT to wait indefinitly.
302 */
303static int vbox_wait_prop(uint32_t uClientID,
304 const char *pszKey, uint32_t uTimeoutMS)
305{
306 AssertReturn(uClientID, VERR_INVALID_PARAMETER);
307 AssertPtrReturn(pszKey, VERR_INVALID_POINTER);
308
309 int rc;
310
311 /* The buffer for storing the data and its initial size. We leave a bit
312 * of space here in case the maximum values are raised. */
313 void *pvBuf = NULL;
314 uint32_t cbBuf = MAX_NAME_LEN + MAX_VALUE_LEN + MAX_FLAGS_LEN + _1K;
315
316 for (int i = 0; i < 10; i++)
317 {
318 void *pvTmpBuf = RTMemRealloc(pvBuf, cbBuf);
319 if (pvTmpBuf)
320 {
321 char *pszName = NULL;
322 char *pszValue = NULL;
323 uint64_t u64TimestampOut = 0;
324 char *pszFlags = NULL;
325
326 pvBuf = pvTmpBuf;
327 rc = VbglR3GuestPropWait(uClientID, pszKey, pvBuf, cbBuf,
328 0 /* Last timestamp; just wait for next event */, uTimeoutMS,
329 &pszName, &pszValue, &u64TimestampOut,
330 &pszFlags, &cbBuf);
331 }
332 else
333 rc = VERR_NO_MEMORY;
334
335 if (rc == VERR_BUFFER_OVERFLOW)
336 {
337 /* Buffer too small, try it with a bigger one next time. */
338 cbBuf += _1K;
339 continue; /* Try next round. */
340 }
341
342 /* Everything except VERR_BUFFER_OVERLOW makes us bail out ... */
343 break;
344 }
345
346 return rc;
347}
348# endif /* unused */
349
350#endif /* VBOX_WITH_GUEST_PROPS */
351
352/**
353 * Checks for credentials provided by the host / HGCM.
354 *
355 * @return IPRT status code. VERR_NOT_FOUND if no credentials are available,
356 * VINF_SUCCESS on successful retrieval or another IPRT error.
357 * @param pCtx Greeter context.
358 */
359static int vboxGreeterCheckCreds(PVBOXGREETERCTX pCtx)
360{
361 AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
362
363 static bool s_fCredsNotFoundMsgShown = false;
364 int rc = VbglR3CredentialsQueryAvailability();
365 if (RT_FAILURE(rc))
366 {
367 if (rc != VERR_NOT_FOUND)
368 vboxGreeterError("vboxGreeterCheckCreds: could not query for credentials! rc=%Rrc. Aborting\n", rc);
369 else if (!s_fCredsNotFoundMsgShown)
370 {
371 vboxGreeterLog("vboxGreeterCheckCreds: no credentials available\n");
372 s_fCredsNotFoundMsgShown = true;
373 }
374 }
375 else
376 {
377 /** @todo Domain handling needed? */
378 char *pszUsername; /* User name only is kept local. */
379 char *pszDomain = NULL;
380 rc = VbglR3CredentialsRetrieve(&pszUsername, &pCtx->pszPassword, &pszDomain);
381 if (RT_FAILURE(rc))
382 {
383 vboxGreeterError("vboxGreeterCheckCreds: could not retrieve credentials! rc=%Rrc. Aborting\n", rc);
384 }
385 else
386 {
387 vboxGreeterLog("vboxGreeterCheckCreds: credentials retrieved: user=%s, password=%s, domain=%s\n",
388 pszUsername,
389#ifdef DEBUG
390 pCtx->pszPassword,
391#else
392 "XXX",
393#endif
394 pszDomain);
395 /* Trigger LightDM authentication with the user name just retrieved. */
396 lightdm_greeter_authenticate(pCtx->pGreeter, pszUsername); /* Must be the real user name from host! */
397
398 /* Securely wipe the user name + domain again. */
399 VbglR3CredentialsDestroy(pszUsername, NULL /* pszPassword */, pszDomain,
400 3 /* Three wipe passes */);
401 }
402 }
403
404#ifdef DEBUG
405 vboxGreeterLog("vboxGreeterCheckCreds: returned with rc=%Rrc\n", rc);
406#endif
407 return rc;
408}
409
410/**
411 * Called by LightDM when greeter is not needed anymore.
412 *
413 * @param signum Signal number.
414 */
415static void cb_sigterm(int signum)
416{
417 RT_NOREF(signum);
418
419 /* Note: This handler must be reentrant-safe. */
420#ifdef VBOX_WITH_FLTK
421 g_fRunning = false;
422#else
423 exit(RTEXITCODE_SUCCESS);
424#endif
425}
426
427/**
428 * Callback for showing a user prompt, issued by the LightDM server.
429 *
430 * @param pGreeter Pointer to this greeter instance.
431 * @param pszText Text to display.
432 * @param enmType Type of prompt to display.
433 * @param pvData Pointer to user-supplied data.
434 */
435static void cb_lightdm_show_prompt(LightDMGreeter *pGreeter,
436 const gchar *pszText, LightDMPromptType enmType,
437 gpointer pvData)
438{
439 vboxGreeterLog("cb_lightdm_show_prompt: text=%s, type=%d\n", pszText, enmType);
440
441 PVBOXGREETERCTX pCtx = (PVBOXGREETERCTX)pvData;
442 AssertPtr(pCtx);
443
444 switch (enmType)
445 {
446 case 1: /* Password. */
447 {
448 if (pCtx->pszPassword)
449 {
450 lightdm_greeter_respond(pGreeter, pCtx->pszPassword);
451 }
452 else
453 {
454#ifdef VBOX_WITH_FLTK
455 AssertPtr(pCtx->pEdtPassword);
456 const char *pszPwd = pCtx->pEdtPassword->value();
457#else
458 GtkEntry *pEdtPwd = GTK_ENTRY(gtk_builder_get_object(pCtx->pBuilder, "edt_password"));
459 AssertPtr(pEdtPwd);
460 const gchar *pszPwd = gtk_entry_get_text(pEdtPwd);
461#endif
462 lightdm_greeter_respond(pGreeter, pszPwd);
463 }
464 break;
465 }
466 /** @todo Other fields? */
467
468 default:
469 break;
470 }
471
472 VbglR3CredentialsDestroy(NULL /* pszUsername */, pCtx->pszPassword, NULL /* pszDomain */,
473 3 /* Three wipe passes */);
474 pCtx->pszPassword = NULL;
475}
476
477/**
478 * Callback for showing a message, issued by the LightDM server.
479 *
480 * @param pGreeter Pointer to this greeter instance.
481 * @param pszText Text to display.
482 * @param enmType Type of message to display.
483 * @param pvData Pointer to user-supplied data.
484 */
485static void cb_lightdm_show_message(LightDMGreeter *pGreeter,
486 const gchar *pszText, LightDMPromptType enmType,
487 gpointer pvData)
488{
489 RT_NOREF(pGreeter);
490 vboxGreeterLog("cb_lightdm_show_message: text=%s, type=%d\n", pszText, enmType);
491
492 PVBOXGREETERCTX pCtx = (PVBOXGREETERCTX)pvData;
493 AssertPtrReturnVoid(pCtx);
494
495#ifdef VBOX_WITH_FLTK
496 AssertPtr(pCtx->pLblInfo);
497 pCtx->pLblInfo->copy_label(pszText);
498#else
499 GtkLabel *pLblInfo = GTK_LABEL(gtk_builder_get_object(pCtx->pBuilder, "lbl_info"));
500 AssertPtr(pLblInfo);
501 gtk_label_set_text(pLblInfo, pszText);
502#endif
503}
504
505/**
506 * Callback for authentication completion, issued by the LightDM server.
507 *
508 * @param pGreeter Pointer to this greeter instance.
509 */
510static void cb_lightdm_auth_complete(LightDMGreeter *pGreeter)
511{
512 vboxGreeterLog("cb_lightdm_auth_complete\n");
513
514 const gchar *pszUser = lightdm_greeter_get_authentication_user(pGreeter);
515 vboxGreeterLog("authenticating user: %s\n", pszUser ? pszUser : "<NULL>");
516
517 if (lightdm_greeter_get_is_authenticated(pGreeter))
518 {
519 /** @todo Add non-default session support. */
520 gchar *pszSession = g_strdup(lightdm_greeter_get_default_session_hint(pGreeter));
521 if (pszSession)
522 {
523 vboxGreeterLog("starting session: %s\n", pszSession);
524 GError *pError = NULL;
525 if (!lightdm_greeter_start_session_sync(pGreeter, pszSession, &pError))
526 {
527 vboxGreeterError("unable to start session '%s': %s\n",
528 pszSession, pError ? pError->message : "Unknown error");
529 }
530 else
531 {
532 AssertPtr(pszSession);
533 vboxGreeterLog("session '%s' successfully started\n", pszSession);
534 }
535 if (pError)
536 g_error_free(pError);
537 g_free(pszSession);
538 }
539 else
540 vboxGreeterError("unable to get default session\n");
541 }
542 else
543 vboxGreeterLog("user not authenticated successfully (yet)\n");
544}
545
546/**
547 * Callback for clicking on the "Login" button.
548 *
549 * @param pWidget Widget this callback is bound to.
550 * @param pvData Pointer to user-supplied data.
551 */
552#ifdef VBOX_WITH_FLTK
553void cb_btn_login(Fl_Widget *pWidget, void *pvData)
554#else
555void cb_btn_login(GtkWidget *pWidget, gpointer pvData)
556#endif
557{
558 PVBOXGREETERCTX pCtx = (PVBOXGREETERCTX)pvData;
559 RT_NOREF(pWidget);
560 AssertPtr(pCtx);
561
562#ifdef VBOX_WITH_FLTK
563 AssertPtr(pCtx->pEdtUsername);
564 const char *pszUser = pCtx->pEdtUsername->value();
565 AssertPtr(pCtx->pEdtPassword);
566 const char *pszPwd = pCtx->pEdtPassword->value();
567#else
568 GtkEntry *pEdtUser = GTK_ENTRY(gtk_builder_get_object(pCtx->pBuilder, VBOX_GREETER_UI_EDT_USER));
569 AssertPtr(pEdtUser);
570 const gchar *pszUser = gtk_entry_get_text(pEdtUser);
571
572 GtkEntry *pEdtPwd = GTK_ENTRY(gtk_builder_get_object(pCtx->pBuilder, VBOX_GREETER_UI_EDT_PASSWORD));
573 AssertPtr(pEdtPwd);
574 const gchar *pszPwd = gtk_entry_get_text(pEdtPwd);
575#endif
576
577 /** @todo Add domain handling? */
578 vboxGreeterLog("login button pressed: greeter=%p, user=%s, password=%s\n",
579 pCtx->pGreeter,
580 pszUser ? pszUser : "<NONE>",
581#ifdef DEBUG
582 pszPwd ? pszPwd : "<NONE>");
583#else
584 /* Don't log passwords in release mode! */
585 "XXX");
586#endif
587 if (strlen(pszUser)) /* Only authenticate if username is given. */
588 {
589 lightdm_greeter_respond(pCtx->pGreeter, pszPwd);
590 lightdm_greeter_authenticate(pCtx->pGreeter, pszUser);
591 }
592}
593
594/**
595 * Callback for clicking on the "Menu" button.
596 *
597 * @param pWidget Widget this callback is bound to.
598 * @param pvData Pointer to user-supplied data.
599 */
600#ifdef VBOX_WITH_FLTK
601void cb_btn_menu(Fl_Widget *pWidget, void *pvData)
602#else
603void cb_btn_menu(GtkWidget *pWidget, gpointer pvData)
604#endif
605{
606 RT_NOREF(pWidget, pvData);
607 vboxGreeterLog("menu button pressed\n");
608}
609
610/**
611 * Callback for clicking on the "Restart" button / menu entry.
612 *
613 * @param pWidget Widget this callback is bound to.
614 * @param pvData Pointer to user-supplied data.
615 */
616#ifdef VBOX_WITH_FLTK
617void cb_btn_restart(Fl_Widget *pWidget, void *pvData)
618#else
619void cb_btn_restart(GtkWidget *pWidget, gpointer pvData)
620#endif
621{
622 RT_NOREF(pWidget, pvData);
623 vboxGreeterLog("restart button pressed\n");
624
625 bool fRestart = true;
626#ifdef VBOX_WITH_FLTK
627 int rc = fl_choice("Really restart the system?", "Yes", "No", NULL);
628 fRestart = rc == 0;
629#endif
630
631 if (fRestart)
632 {
633 vboxGreeterLog("restart requested\n");
634#ifndef DEBUG
635 lightdm_restart(NULL);
636#endif
637 }
638}
639
640/**
641 * Callback for clicking on the "Shutdown" button / menu entry.
642 *
643 * @param pWidget Widget this callback is bound to.
644 * @param pvData Pointer to user-supplied data.
645 */
646#ifdef VBOX_WITH_FLTK
647void cb_btn_shutdown(Fl_Widget *pWidget, void *pvData)
648#else
649void cb_btn_shutdown(GtkWidget *pWidget, gpointer pvData)
650#endif
651{
652 RT_NOREF(pWidget, pvData);
653 vboxGreeterLog("shutdown button pressed\n");
654
655 bool fShutdown = true;
656#ifdef VBOX_WITH_FLTK
657 int rc = fl_choice("Really shutdown the system?", "Yes", "No", NULL);
658 fShutdown = rc == 0;
659#endif
660
661 if (fShutdown)
662 {
663 vboxGreeterLog("shutdown requested\n");
664#ifndef DEBUG
665 lightdm_shutdown(NULL);
666#endif
667 }
668}
669
670#ifdef VBOX_WITH_FLTK
671void cb_edt_username(Fl_Widget *pWidget, void *pvData)
672#else
673void cb_edt_username(GtkWidget *pWidget, gpointer pvData)
674#endif
675{
676 RT_NOREF(pWidget);
677 vboxGreeterLog("cb_edt_username called\n");
678
679 PVBOXGREETERCTX pCtx = (PVBOXGREETERCTX)pvData;
680 AssertPtr(pCtx);
681#ifdef VBOX_WITH_FLTK
682 AssertPtr(pCtx->pEdtPassword);
683 Fl::focus(pCtx->pEdtPassword);
684#endif
685}
686
687#ifdef VBOX_WITH_FLTK
688void cb_edt_password(Fl_Widget *pWidget, void *pvData)
689#else
690void cb_edt_password(GtkWidget *pWidget, gpointer pvData)
691#endif
692{
693 RT_NOREF(pWidget, pvData);
694 vboxGreeterLog("cb_edt_password called\n");
695
696 PVBOXGREETERCTX pCtx = (PVBOXGREETERCTX)pvData;
697 AssertPtr(pCtx);
698#ifdef VBOX_WITH_FLTK
699 AssertPtr(pCtx->pBtnLogin);
700 cb_btn_login(pCtx->pBtnLogin, pvData);
701#endif
702}
703
704/**
705 * Callback for the timer event which is checking for new credentials
706 * from the host.
707 *
708 * @param pvData Pointer to user-supplied data.
709 */
710#ifdef VBOX_WITH_FLTK
711static void cb_check_creds(void *pvData)
712#else
713static gboolean cb_check_creds(gpointer pvData)
714#endif
715{
716 PVBOXGREETERCTX pCtx = (PVBOXGREETERCTX)pvData;
717 AssertPtr(pCtx);
718
719#ifdef DEBUG
720 vboxGreeterLog("cb_check_creds called, clientId=%RU32, timeoutMS=%RU32\n",
721 pCtx->uClientId, pCtx->uTimeoutMS);
722#endif
723
724 int rc = VINF_SUCCESS;
725
726#ifdef VBOX_WITH_GUEST_PROPS
727 bool fAbort = false;
728 char szVal[255];
729 if (pCtx->uClientId)
730 {
731 uint64_t tsAbort;
732 rc = vbox_read_prop(pCtx->uClientId,
733 "/VirtualBox/GuestAdd/PAM/CredsWaitAbort",
734 true /* Read-only on guest */,
735 szVal, sizeof(szVal), &tsAbort);
736 switch (rc)
737 {
738 case VINF_SUCCESS:
739# ifdef DEBUG
740 vboxGreeterLog("cb_check_creds: tsAbort %RU64 <-> %RU64\n",
741 pCtx->uTsAbort, tsAbort);
742# endif
743 if (tsAbort != pCtx->uTsAbort)
744 fAbort = true; /* Timestamps differs, abort. */
745 pCtx->uTsAbort = tsAbort;
746 break;
747
748 case VERR_TOO_MUCH_DATA:
749 vboxGreeterError("cb_check_creds: temporarily unable to get abort notification\n");
750 break;
751
752 case VERR_NOT_FOUND:
753 /* Value not found, continue checking for credentials. */
754 break;
755
756 default:
757 vboxGreeterError("cb_check_creds: the abort notification request failed with rc=%Rrc\n", rc);
758 fAbort = true; /* Abort on error. */
759 break;
760 }
761 }
762
763 if (fAbort)
764 {
765 /* Get optional message. */
766 szVal[0] = '\0';
767 int rc2 = vbox_read_prop(pCtx->uClientId,
768 "/VirtualBox/GuestAdd/PAM/CredsMsgWaitAbort",
769 true /* Read-only on guest */,
770 szVal, sizeof(szVal), NULL /* Timestamp. */);
771 if ( RT_FAILURE(rc2)
772 && rc2 != VERR_NOT_FOUND)
773 vboxGreeterError("cb_check_creds: getting wait abort message failed with rc=%Rrc\n", rc2);
774# ifdef VBOX_WITH_FLTK
775 AssertPtr(pCtx->pLblInfo);
776 pCtx->pLblInfo->copy_label(szVal);
777# else /* !VBOX_WITH_FLTK */
778 GtkLabel *pLblInfo = GTK_LABEL(gtk_builder_get_object(pCtx->pBuilder, VBOX_GREETER_UI_LBL_INFO));
779 AssertPtr(pLblInfo);
780 gtk_label_set_text(pLblInfo, szVal);
781# endif /* !VBOX_WITH_FLTK */
782 vboxGreeterLog("cb_check_creds: got notification from host to abort waiting\n");
783 }
784 else
785 {
786#endif /* VBOX_WITH_GUEST_PROPS */
787 rc = vboxGreeterCheckCreds(pCtx);
788 if (RT_SUCCESS(rc))
789 {
790 /* Credentials retrieved. */
791 }
792 else if (rc == VERR_NOT_FOUND)
793 {
794 /* No credentials found, but try next round (if there's
795 * time left for) ... */
796 }
797#ifdef VBOX_WITH_GUEST_PROPS
798 }
799#endif /* VBOX_WITH_GUEST_PROPS */
800
801 if (rc == VERR_NOT_FOUND) /* No credential found this round. */
802 {
803 /* Calculate timeout value left after process has been started. */
804 uint64_t u64Elapsed = RTTimeMilliTS() - pCtx->uStartMS;
805 /* Is it time to bail out? */
806 if (pCtx->uTimeoutMS < u64Elapsed)
807 {
808#ifdef VBOX_WITH_GUEST_PROPS
809 szVal[0] = '\0';
810 int rc2 = vbox_read_prop(pCtx->uClientId,
811 "/VirtualBox/GuestAdd/PAM/CredsMsgWaitTimeout",
812 true /* Read-only on guest */,
813 szVal, sizeof(szVal), NULL /* Timestamp. */);
814 if ( RT_FAILURE(rc2)
815 && rc2 != VERR_NOT_FOUND)
816 vboxGreeterError("cb_check_creds: getting wait timeout message failed with rc=%Rrc\n", rc2);
817# ifdef VBOX_WITH_FLTK
818 AssertPtr(pCtx->pLblInfo);
819 pCtx->pLblInfo->copy_label(szVal);
820# else
821 GtkLabel *pLblInfo = GTK_LABEL(gtk_builder_get_object(pCtx->pBuilder, VBOX_GREETER_UI_LBL_INFO));
822 AssertPtr(pLblInfo);
823 gtk_label_set_text(pLblInfo, szVal);
824# endif
825#endif /* VBOX_WITH_GUEST_PROPS */
826 vboxGreeterLog("cb_check_creds: no credentials retrieved within time (%RU32ms), giving up\n",
827 pCtx->uTimeoutMS);
828 rc = VERR_TIMEOUT;
829 }
830 }
831
832#ifdef DEBUG
833 vboxGreeterLog("cb_check_creds returned with rc=%Rrc\n", rc);
834#endif
835
836 /* At the moment we only allow *one* shot from the host,
837 * so setting credentials in a second attempt won't be possible
838 * intentionally. */
839
840 if (rc == VERR_NOT_FOUND)
841#ifdef VBOX_WITH_FLTK
842 Fl::repeat_timeout(0.5 /* 500 ms */, cb_check_creds, pvData);
843#else
844 return TRUE; /* No credentials found, do another round. */
845
846 return FALSE; /* Remove timer source on every other error / status. */
847#endif
848}
849
850/**
851 * Release logger callback.
852 *
853 * @return IPRT status code.
854 * @param pLoggerRelease
855 * @param enmPhase
856 * @param pfnLog
857 */
858static DECLCALLBACK(void) vboxGreeterLogHeaderFooter(PRTLOGGER pLoggerRelease, RTLOGPHASE enmPhase, PFNRTLOGPHASEMSG pfnLog)
859{
860 /* Some introductory information. */
861 static RTTIMESPEC s_TimeSpec;
862 char szTmp[256];
863 if (enmPhase == RTLOGPHASE_BEGIN)
864 RTTimeNow(&s_TimeSpec);
865 RTTimeSpecToString(&s_TimeSpec, szTmp, sizeof(szTmp));
866
867 switch (enmPhase)
868 {
869 case RTLOGPHASE_BEGIN:
870 {
871 pfnLog(pLoggerRelease,
872 "vbox-greeter %s r%s (verbosity: %d) %s (%s %s) release log\n"
873 "Log opened %s\n",
874 RTBldCfgVersion(), RTBldCfgRevisionStr(), g_iVerbosity, VBOX_BUILD_TARGET,
875 __DATE__, __TIME__, szTmp);
876
877 int vrc = RTSystemQueryOSInfo(RTSYSOSINFO_PRODUCT, szTmp, sizeof(szTmp));
878 if (RT_SUCCESS(vrc) || vrc == VERR_BUFFER_OVERFLOW)
879 pfnLog(pLoggerRelease, "OS Product: %s\n", szTmp);
880 vrc = RTSystemQueryOSInfo(RTSYSOSINFO_RELEASE, szTmp, sizeof(szTmp));
881 if (RT_SUCCESS(vrc) || vrc == VERR_BUFFER_OVERFLOW)
882 pfnLog(pLoggerRelease, "OS Release: %s\n", szTmp);
883 vrc = RTSystemQueryOSInfo(RTSYSOSINFO_VERSION, szTmp, sizeof(szTmp));
884 if (RT_SUCCESS(vrc) || vrc == VERR_BUFFER_OVERFLOW)
885 pfnLog(pLoggerRelease, "OS Version: %s\n", szTmp);
886 if (RT_SUCCESS(vrc) || vrc == VERR_BUFFER_OVERFLOW)
887 pfnLog(pLoggerRelease, "OS Service Pack: %s\n", szTmp);
888
889 /* the package type is interesting for Linux distributions */
890 char szExecName[RTPATH_MAX];
891 char *pszExecName = RTProcGetExecutablePath(szExecName, sizeof(szExecName));
892 pfnLog(pLoggerRelease,
893 "Executable: %s\n"
894 "Process ID: %u\n"
895 "Package type: %s"
896#ifdef VBOX_OSE
897 " (OSE)"
898#endif
899 "\n",
900 pszExecName ? pszExecName : "unknown",
901 RTProcSelf(),
902 VBOX_PACKAGE_STRING);
903 break;
904 }
905
906 case RTLOGPHASE_PREROTATE:
907 pfnLog(pLoggerRelease, "Log rotated - Log started %s\n", szTmp);
908 break;
909
910 case RTLOGPHASE_POSTROTATE:
911 pfnLog(pLoggerRelease, "Log continuation - Log started %s\n", szTmp);
912 break;
913
914 case RTLOGPHASE_END:
915 pfnLog(pLoggerRelease, "End of log file - Log started %s\n", szTmp);
916 break;
917
918 default:
919 /* nothing */;
920 }
921}
922
923/**
924 * Creates the default release logger outputting to the specified file.
925 *
926 * @return IPRT status code.
927 * @param pszLogFile Filename for log output. Optional.
928 */
929static int vboxGreeterLogCreate(const char *pszLogFile)
930{
931 /* Create release logger (stdout + file). */
932 static const char * const s_apszGroups[] = VBOX_LOGGROUP_NAMES;
933 RTUINT fFlags = RTLOGFLAGS_PREFIX_THREAD | RTLOGFLAGS_PREFIX_TIME_PROG;
934#if defined(RT_OS_WINDOWS) || defined(RT_OS_OS2)
935 fFlags |= RTLOGFLAGS_USECRLF;
936#endif
937 int rc = RTLogCreateEx(&g_pLoggerRelease, fFlags, "all", "VBOXGREETER_RELEASE_LOG",
938 RT_ELEMENTS(s_apszGroups), s_apszGroups, UINT32_MAX /*cMaxEntriesPerGroup*/, RTLOGDEST_STDOUT,
939 vboxGreeterLogHeaderFooter, g_cHistory, g_uHistoryFileSize, g_uHistoryFileTime,
940 NULL /*pErrInfo*/, pszLogFile);
941 if (RT_SUCCESS(rc))
942 {
943 /* register this logger as the release logger */
944 RTLogRelSetDefaultInstance(g_pLoggerRelease);
945
946 /* Explicitly flush the log in case of VBOXGREETER_RELEASE_LOG_FLAGS=buffered. */
947 RTLogFlush(g_pLoggerRelease);
948 }
949
950 return rc;
951}
952
953static void vboxGreeterLogDestroy(void)
954{
955 RTLogDestroy(RTLogRelSetDefaultInstance(NULL));
956}
957
958static int vboxGreeterUsage(void)
959{
960 RTPrintf("Usage:\n"
961 " %-12s [-h|-?|--help] [-F|--logfile <file>]\n"
962 " [-v|--verbose] [-V|--version]\n", g_pszProgName);
963
964 RTPrintf("\n"
965 " Copyright (C) 2012-" VBOX_C_YEAR " " VBOX_VENDOR "\n");
966
967 return RTEXITCODE_SYNTAX;
968}
969
970int main(int argc, char **argv)
971{
972 int rc = RTR3InitExe(argc, &argv, 0);
973 if (RT_FAILURE(rc))
974 return RTMsgInitFailure(rc);
975 g_pszProgName = RTPathFilename(argv[0]);
976
977 static const RTGETOPTDEF s_aOptions[] =
978 {
979 { "--logfile", 'F', RTGETOPT_REQ_STRING },
980 { "--verbose", 'v', RTGETOPT_REQ_NOTHING },
981 { "--version", 'V', RTGETOPT_REQ_NOTHING }
982 };
983
984 char szLogFile[RTPATH_MAX + 128] = "";
985
986 int ch;
987 RTGETOPTUNION ValueUnion;
988 RTGETOPTSTATE GetState;
989 RTGetOptInit(&GetState, argc, argv,
990 s_aOptions, RT_ELEMENTS(s_aOptions),
991 1 /*iFirst*/, RTGETOPTINIT_FLAGS_OPTS_FIRST);
992
993 while ( (ch = RTGetOpt(&GetState, &ValueUnion))
994 && RT_SUCCESS(rc))
995 {
996 /* For options that require an argument, ValueUnion has received the value. */
997 switch (ch)
998 {
999 case 'F':
1000 if (!RTStrPrintf(szLogFile, sizeof(szLogFile), "%s", ValueUnion.psz))
1001 return RTMsgErrorExit(RTEXITCODE_FAILURE, "Failed to get prepare log file name");
1002 break;
1003
1004 case 'h':
1005 case '?':
1006 return vboxGreeterUsage();
1007
1008 case 'v': /* Raise verbosity. */
1009 g_iVerbosity++;
1010 break;
1011
1012 case 'V': /* Print version and exit. */
1013 RTPrintf("%sr%s\n", RTBldCfgVersion(), RTBldCfgRevisionStr());
1014 return RTEXITCODE_SUCCESS;
1015 break; /* Never reached. */
1016
1017 default:
1018 return RTGetOptPrintError(ch, &ValueUnion);
1019 }
1020 }
1021
1022 if (RT_FAILURE(rc))
1023 return RTEXITCODE_SYNTAX;
1024
1025 rc = VbglR3InitUser();
1026 if (RT_FAILURE(rc))
1027 return RTMsgErrorExit(RTEXITCODE_FAILURE, "Failed to init Vbgl (%Rrc)", rc);
1028
1029 rc = vboxGreeterLogCreate(strlen(szLogFile) ? szLogFile : NULL);
1030 if (RT_FAILURE(rc))
1031 return RTMsgErrorExit(RTEXITCODE_FAILURE, "Failed to create release log (%s, %Rrc)",
1032 strlen(szLogFile) ? szLogFile : "<None>", rc);
1033
1034 vboxGreeterLog("init\n");
1035
1036 signal(SIGTERM, cb_sigterm);
1037
1038 /** @todo This function already is too long. Move code into
1039 * functions. */
1040
1041 VBOXGREETERCTX ctx;
1042 RT_ZERO(ctx);
1043
1044 /* UI parameters. */
1045 uint32_t uBgColor = 0; /* The background color. */
1046 uint32_t uLogonDlgHdrColor = 0;
1047 uint32_t uLogonDlgBgColor = 0; /* The greeter's dialog color. */
1048 uint32_t uLogonDlgBtnColor = 0; /* The greeter's button color. */
1049
1050#ifdef VBOX_GREETER_WITH_PNG_SUPPORT
1051 char szBannerPath[RTPATH_MAX];
1052#endif
1053
1054 /* By default most UI elements are shown. */
1055 uint32_t uOptsUI = VBOX_GREETER_UI_SHOW_RESTART
1056 | VBOX_GREETER_UI_SHOW_SHUTDOWN;
1057#ifdef VBOX_WITH_GUEST_PROPS
1058 uint32_t uClientId = 0;
1059 rc = VbglR3GuestPropConnect(&uClientId);
1060 if (RT_SUCCESS(rc))
1061 {
1062 vboxGreeterLog("clientId=%RU32\n", uClientId);
1063
1064 ctx.uClientId = uClientId;
1065
1066 char szVal[256];
1067 int rc2 = vbox_read_prop(uClientId,
1068 "/VirtualBox/GuestAdd/Greeter/HideRestart",
1069 true /* Read-only on guest */,
1070 szVal, sizeof(szVal), NULL /* Timestamp. */);
1071 if ( RT_SUCCESS(rc2)
1072 && !RTStrICmp(szVal, "1"))
1073 {
1074 uOptsUI &= ~VBOX_GREETER_UI_SHOW_RESTART;
1075 }
1076
1077 rc2 = vbox_read_prop(uClientId,
1078 "/VirtualBox/GuestAdd/Greeter/HideShutdown",
1079 true /* Read-only on guest */,
1080 szVal, sizeof(szVal), NULL /* Timestamp. */);
1081 if ( RT_SUCCESS(rc2)
1082 && !RTStrICmp(szVal, "1"))
1083 {
1084 uOptsUI &= ~VBOX_GREETER_UI_SHOW_SHUTDOWN;
1085 }
1086
1087# ifdef VBOX_GREETER_WITH_PNG_SUPPORT
1088 /* Load the banner. */
1089 rc2 = vbox_read_prop(uClientId,
1090 "/VirtualBox/GuestAdd/Greeter/BannerPath",
1091 true /* Read-only on guest */,
1092 szBannerPath, sizeof(szBannerPath), NULL /* Timestamp. */);
1093 if (RT_SUCCESS(rc2))
1094 {
1095 if (RTFileExists(szBannerPath))
1096 {
1097 vboxGreeterLog("showing banner from '%s'\n", szBannerPath);
1098 uOptsUI |= VBOX_GREETER_UI_SHOW_BANNER;
1099 }
1100 else
1101 vboxGreeterLog("warning: unable to find banner at '%s', skipping\n", szBannerPath);
1102 }
1103# endif /* VBOX_GREETER_WITH_PNG_SUPPORT */
1104
1105 /* Use theming?. */
1106 rc2 = vbox_read_prop(uClientId,
1107 "/VirtualBox/GuestAdd/Greeter/UseTheming",
1108 true /* Read-only on guest */,
1109 szVal, sizeof(szVal), NULL /* Timestamp. */);
1110 if ( RT_SUCCESS(rc2)
1111 && !RTStrICmp(szVal, "1"))
1112 {
1113 vboxGreeterLog("custom theming enabled\n");
1114 uOptsUI |= VBOX_GREETER_UI_USE_THEMING;
1115 }
1116
1117 if (uOptsUI & VBOX_GREETER_UI_USE_THEMING)
1118 {
1119 /* Get background color. */
1120 rc2 = vbox_read_prop(uClientId,
1121 "/VirtualBox/GuestAdd/Greeter/Theme/BackgroundColor",
1122 true /* Read-only on guest */,
1123 szVal, sizeof(szVal), NULL /* Timestamp. */);
1124 if (RT_SUCCESS(rc2))
1125 {
1126 uBgColor = strtol(szVal, NULL,
1127 /* Change conversion base when having a 0x prefix. */
1128 RTStrStr(szVal, "0x") == szVal ? 0 : 16);
1129 }
1130
1131 /* Logon dialog. */
1132
1133 /* Get header color. */
1134 rc2 = vbox_read_prop(uClientId,
1135 "/VirtualBox/GuestAdd/Greeter/Theme/LogonDialog/HeaderColor",
1136 true /* Read-only on guest */,
1137 szVal, sizeof(szVal), NULL /* Timestamp. */);
1138 if (RT_SUCCESS(rc2))
1139 {
1140 uLogonDlgHdrColor = strtol(szVal, NULL,
1141 /* Change conversion base when having a 0x prefix. */
1142 RTStrStr(szVal, "0x") == szVal ? 0 : 16);
1143 }
1144
1145 /* Get dialog color. */
1146 rc2 = vbox_read_prop(uClientId,
1147 "/VirtualBox/GuestAdd/Greeter/Theme/LogonDialog/BackgroundColor",
1148 true /* Read-only on guest */,
1149 szVal, sizeof(szVal), NULL /* Timestamp. */);
1150 if (RT_SUCCESS(rc2))
1151 {
1152 uLogonDlgBgColor = strtol(szVal, NULL,
1153 /* Change conversion base when having a 0x prefix. */
1154 RTStrStr(szVal, "0x") == szVal ? 0 : 16);
1155 }
1156
1157 /* Get button color. */
1158 rc2 = vbox_read_prop(uClientId,
1159 "/VirtualBox/GuestAdd/Greeter/Theme/LogonDialog/ButtonColor",
1160 true /* Read-only on guest */,
1161 szVal, sizeof(szVal), NULL /* Timestamp. */);
1162 if (RT_SUCCESS(rc2))
1163 {
1164 uLogonDlgBtnColor = strtol(szVal, NULL,
1165 /* Change conversion base when having a 0x prefix. */
1166 RTStrStr(szVal, "0x") == szVal ? 0 : 16);
1167 }
1168 }
1169 }
1170 else
1171 vboxGreeterError("unable to connect to guest property service, rc=%Rrc\n", rc);
1172#endif
1173 vboxGreeterLog("UI options are: %RU32\n", uOptsUI);
1174
1175#ifdef VBOX_WITH_FLTK
1176 int rc2 = Fl::scheme("plastic");
1177 if (!rc2)
1178 vboxGreeterLog("warning: unable to set visual scheme\n");
1179
1180 Fl::visual(FL_DOUBLE | FL_INDEX);
1181 Fl_Double_Window *pWndMain = new Fl_Double_Window(Fl::w(), Fl::h(), "VirtualBox Guest Additions");
1182 AssertPtr(pWndMain);
1183 if (uOptsUI & VBOX_GREETER_UI_USE_THEMING)
1184 pWndMain->color(fl_rgb_color(VBOX_RGB_COLOR_RED(uBgColor),
1185 VBOX_RGB_COLOR_GREEN(uBgColor),
1186 VBOX_RGB_COLOR_BLUE(uBgColor)));
1187 else /* Default colors. */
1188 pWndMain->color(fl_rgb_color(0x73, 0x7F, 0x8C));
1189
1190 Fl_Double_Window *pWndGreeter = new Fl_Double_Window(500, 350);
1191 AssertPtr(pWndGreeter);
1192 pWndGreeter->set_modal();
1193 if (uOptsUI & VBOX_GREETER_UI_USE_THEMING)
1194 pWndGreeter->color(fl_rgb_color(VBOX_RGB_COLOR_RED(uLogonDlgBgColor),
1195 VBOX_RGB_COLOR_GREEN(uLogonDlgBgColor),
1196 VBOX_RGB_COLOR_BLUE(uLogonDlgBgColor)));
1197 else /* Default colors. */
1198 pWndGreeter->color(fl_rgb_color(255, 255, 255));
1199
1200 uint32_t uOffsetX = 130;
1201 /**
1202 * For now we're using a simple Y offset for moving all elements
1203 * down if a banner needs to be shown on top of the greeter. Not
1204 * very clean but does the job. Use some more layouting stuff
1205 * when this gets more complex.
1206 */
1207 uint32_t uOffsetY = 80;
1208
1209# ifdef VBOX_GREETER_WITH_PNG_SUPPORT
1210 fl_register_images();
1211
1212 /** @todo Add basic image type detection based on file
1213 * extension. */
1214
1215 Fl_PNG_Image *pImgBanner = NULL;
1216 if (uOptsUI & VBOX_GREETER_UI_SHOW_BANNER)
1217 {
1218 pImgBanner = new Fl_PNG_Image(szBannerPath);
1219 AssertPtr(pImgBanner);
1220
1221 /** @todo Make the banner size configurable via guest
1222 * properties. For now it's hardcoded to 460 x 90px. */
1223 Fl_Box *pBoxBanner = new Fl_Box(20, uOffsetY, 460, 90, "");
1224 AssertPtr(pBoxBanner);
1225 pBoxBanner->image(pImgBanner);
1226
1227 uOffsetY = 120;
1228 }
1229# endif
1230
1231 Fl_Box *pLblHeader = new Fl_Box(FL_NO_BOX, 242, uOffsetY, 300, 20,
1232 "Desktop Login");
1233 AssertPtr(pLblHeader);
1234
1235 /** Note to use an own font:
1236 * Fl_Font myfnt = FL_FREE_FONT + 1;
1237 * Fl::set_font(myfnt, "MyFont"); */
1238 Fl_Font fntHeader = FL_FREE_FONT;
1239 Fl::set_font(fntHeader, "Courier");
1240
1241 pLblHeader->align(FL_ALIGN_LEFT);
1242 pLblHeader->labelfont(FL_BOLD);
1243 pLblHeader->labelsize(24);
1244 if (uOptsUI & VBOX_GREETER_UI_USE_THEMING)
1245 pLblHeader->labelcolor(fl_rgb_color(VBOX_RGB_COLOR_RED(uLogonDlgHdrColor),
1246 VBOX_RGB_COLOR_GREEN(uLogonDlgHdrColor),
1247 VBOX_RGB_COLOR_BLUE(uLogonDlgHdrColor)));
1248 else /* Default color. */
1249 pLblHeader->labelcolor(fl_rgb_color(0x51, 0x5F, 0x77));
1250 uOffsetY += 40;
1251
1252 /** @todo Add basic NLS support. */
1253
1254 Fl_Input *pEdtUsername = new Fl_Input(uOffsetX, uOffsetY,
1255 300, 20, "User Name");
1256 AssertPtr(pEdtUsername);
1257 pEdtUsername->callback(cb_edt_username, &ctx);
1258 pEdtUsername->when(FL_WHEN_ENTER_KEY_ALWAYS);
1259 Fl::focus(pEdtUsername);
1260 ctx.pEdtUsername = pEdtUsername;
1261
1262 Fl_Secret_Input *pEdtPassword = new Fl_Secret_Input(uOffsetX, uOffsetY + 40,
1263 300, 20, "Password");
1264 AssertPtr(pEdtPassword);
1265 pEdtPassword->callback(cb_edt_password, &ctx);
1266 pEdtPassword->when(FL_WHEN_ENTER_KEY_ALWAYS);
1267 ctx.pEdtPassword = pEdtPassword;
1268
1269 Fl_Button *pBtnLogin = new Fl_Button(uOffsetX, uOffsetY + 70,
1270 100, 40, "Log In");
1271 AssertPtr(pBtnLogin);
1272 pBtnLogin->callback(cb_btn_login, &ctx);
1273 if (uOptsUI & VBOX_GREETER_UI_USE_THEMING)
1274 pBtnLogin->color(fl_rgb_color(VBOX_RGB_COLOR_RED(uLogonDlgBtnColor),
1275 VBOX_RGB_COLOR_GREEN(uLogonDlgBtnColor),
1276 VBOX_RGB_COLOR_BLUE(uLogonDlgBtnColor)));
1277 else /* Default color. */
1278 pBtnLogin->color(fl_rgb_color(255, 255, 255));
1279 ctx.pBtnLogin = pBtnLogin;
1280
1281 Fl_Menu_Button *pBtnMenu = new Fl_Menu_Button(uOffsetX + 120, uOffsetY + 70,
1282 100, 40, "Options");
1283 AssertPtr(pBtnMenu);
1284 pBtnMenu->callback(cb_btn_menu, &ctx);
1285 if (uOptsUI & VBOX_GREETER_UI_USE_THEMING)
1286 pBtnMenu->color(fl_rgb_color(VBOX_RGB_COLOR_RED(uLogonDlgBtnColor),
1287 VBOX_RGB_COLOR_GREEN(uLogonDlgBtnColor),
1288 VBOX_RGB_COLOR_BLUE(uLogonDlgBtnColor)));
1289 else /* Default color. */
1290 pBtnMenu->color(fl_rgb_color(255, 255, 255));
1291
1292 if (uOptsUI & VBOX_GREETER_UI_SHOW_RESTART)
1293 pBtnMenu->add("Restart", "" /* Shortcut */, cb_btn_restart, &ctx, 0 /* Flags */);
1294 if (uOptsUI & VBOX_GREETER_UI_SHOW_SHUTDOWN)
1295 pBtnMenu->add("Shutdown", "" /* Shortcut */, cb_btn_shutdown, &ctx, 0 /* Flags */);
1296
1297 char szLabel[255];
1298 RTStrPrintf(szLabel, sizeof(szLabel), "Oracle VM VirtualBox Guest Additions %sr%s",
1299 RTBldCfgVersion(), RTBldCfgRevisionStr());
1300 Fl_Box *pLblInfo = new Fl_Box(FL_NO_BOX , 50, uOffsetY + 150,
1301 400, 20, szLabel);
1302 AssertPtr(pLblInfo);
1303 ctx.pLblInfo = pLblInfo;
1304
1305 pWndGreeter->end();
1306 pWndGreeter->position((Fl::w() - pWndGreeter->w()) / 2,
1307 (Fl::h() - pWndGreeter->h()) / 2);
1308
1309 pWndMain->fullscreen();
1310 pWndMain->show(argc, argv);
1311 pWndMain->end();
1312
1313 pWndGreeter->show();
1314#else /* !VBOX_WITH_FLTK */
1315 gtk_init(&argc, &argv);
1316
1317 /* Set default cursor */
1318 gdk_window_set_cursor(gdk_get_default_root_window(), gdk_cursor_new(GDK_LEFT_PTR));
1319
1320 GError *pError = NULL;
1321 GtkBuilder *pBuilder = gtk_builder_new();
1322 AssertPtr(pBuilder);
1323 if (!gtk_builder_add_from_file(pBuilder, "/usr/share/xgreeters/vbox-greeter.ui", &pError))
1324 {
1325 AssertPtr(pError);
1326 vboxGreeterError("unable to load UI: %s", pError->message);
1327 return RTEXITCODE_FAILURE;
1328 }
1329
1330 GtkWindow *pWndGreeter = GTK_WINDOW(gtk_builder_get_object(pBuilder, VBOX_GREETER_UI_WND_GREETER));
1331 AssertPtr(pWndGreeter);
1332 GtkButton *pBtnLogin = GTK_BUTTON(gtk_builder_get_object(pBuilder, VBOX_GREETER_UI_BTN_LOGIN));
1333 AssertPtr(pBtnLogin);
1334 GtkLabel *pLblInfo = GTK_LABEL(gtk_builder_get_object(pBuilder, VBOX_GREETER_UI_LBL_INFO));
1335 AssertPtr(pLblInfo);
1336
1337 ctx.pBuilder = pBuilder;
1338
1339 g_signal_connect(G_OBJECT(pBtnLogin), "clicked", G_CALLBACK(cb_btn_login), &ctx);
1340
1341 GdkRectangle rectScreen;
1342 gdk_screen_get_monitor_geometry(gdk_screen_get_default(), gdk_screen_get_primary_monitor(gdk_screen_get_default()), &rectScreen);
1343 vboxGreeterLog("monitor (default) is %dx%d\n", rectScreen.width, rectScreen.height);
1344
1345 gint iWndX, iWndY;
1346 gtk_window_get_default_size(pWndGreeter, &iWndX, &iWndY);
1347 vboxGreeterLog("greeter is %dx%d\n", iWndX, iWndY);
1348
1349 gtk_window_move(pWndGreeter,
1350 (rectScreen.width / 2) - (iWndX / 2),
1351 (rectScreen.height / 2) - (iWndY / 2));
1352 gtk_widget_show(GTK_WIDGET(pWndGreeter));
1353
1354 g_clear_error(&pError);
1355#endif /* !VBOX_WITH_FLTK */
1356
1357 /* GType is needed in any case (for LightDM), whether we
1358 * use GTK3 or not. */
1359 g_type_init();
1360
1361 GMainLoop *pMainLoop = g_main_loop_new(NULL, FALSE /* Not yet running */);
1362 AssertPtr(pMainLoop); NOREF(pMainLoop);
1363
1364 LightDMGreeter *pGreeter = lightdm_greeter_new();
1365 AssertPtr(pGreeter);
1366
1367 g_signal_connect(pGreeter, "show-prompt", G_CALLBACK(cb_lightdm_show_prompt), &ctx);
1368 g_signal_connect(pGreeter, "show-message", G_CALLBACK(cb_lightdm_show_message), &ctx);
1369 g_signal_connect(pGreeter, "authentication-complete", G_CALLBACK(cb_lightdm_auth_complete), &ctx);
1370
1371 ctx.pGreeter = pGreeter;
1372
1373 if (!lightdm_greeter_connect_sync(pGreeter, NULL))
1374 {
1375 vboxGreeterError("unable to connect to LightDM server, aborting\n");
1376 return RTEXITCODE_FAILURE;
1377 }
1378
1379 vboxGreeterLog("connected to LightDM server\n");
1380
1381#ifdef VBOX_WITH_GUEST_PROPS
1382 bool fCheckCreds = false;
1383 if (uClientId) /* Connected to guest property service? */
1384 {
1385 char szVal[256];
1386 rc2 = vbox_read_prop(uClientId,
1387 "/VirtualBox/GuestAdd/PAM/CredsWait",
1388 true /* Read-only on guest */,
1389 szVal, sizeof(szVal), NULL /* Timestamp. */);
1390 if (RT_SUCCESS(rc2))
1391 {
1392 uint32_t uTimeoutMS = RT_INDEFINITE_WAIT; /* Wait infinite by default. */
1393 rc2 = vbox_read_prop(uClientId,
1394 "/VirtualBox/GuestAdd/PAM/CredsWaitTimeout",
1395 true /* Read-only on guest */,
1396 szVal, sizeof(szVal), NULL /* Timestamp. */);
1397 if (RT_SUCCESS(rc2))
1398 {
1399 uTimeoutMS = RTStrToUInt32(szVal);
1400 if (!uTimeoutMS)
1401 {
1402 vboxGreeterError("pam_vbox_authenticate: invalid waiting timeout value specified, defaulting to infinite timeout\n");
1403 uTimeoutMS = RT_INDEFINITE_WAIT;
1404 }
1405 else
1406 uTimeoutMS = uTimeoutMS * 1000; /* Make ms out of s. */
1407 }
1408
1409 ctx.uTimeoutMS = uTimeoutMS;
1410
1411 rc2 = vbox_read_prop(uClientId,
1412 "/VirtualBox/GuestAdd/PAM/CredsMsgWaiting",
1413 true /* Read-only on guest */,
1414 szVal, sizeof(szVal), NULL /* Timestamp. */);
1415 if (RT_SUCCESS(rc2))
1416 {
1417# ifdef VBOX_WITH_FLTK
1418 Assert(pLblInfo);
1419 pLblInfo->copy_label(szVal);
1420# else
1421 gtk_label_set_text(pLblInfo, szVal);
1422# endif
1423 }
1424
1425 /* Get initial timestamp so that we can compare the time
1426 * whether the value has been changed or not in our event callback. */
1427 vbox_read_prop(uClientId,
1428 "/VirtualBox/GuestAdd/PAM/CredsWaitAbort",
1429 true /* Read-only on guest */,
1430 szVal, sizeof(szVal), &ctx.uTsAbort);
1431
1432 if (RT_SUCCESS(rc))
1433 {
1434 /* Before we actuall wait for credentials just make sure we didn't already get credentials
1435 * set so that we can skip waiting for them ... */
1436 rc2 = vboxGreeterCheckCreds(&ctx);
1437 if (rc2 == VERR_NOT_FOUND)
1438 {
1439 /* Get current time stamp to later calculate rest of timeout left. */
1440 ctx.uStartMS = RTTimeMilliTS();
1441
1442 fCheckCreds = true;
1443 }
1444 }
1445 }
1446
1447 /* Start the timer to check credentials availability. */
1448 if (fCheckCreds)
1449 {
1450 vboxGreeterLog("No credentials available on startup, starting to check periodically ...\n");
1451# ifdef VBOX_WITH_FLTK
1452 Fl::add_timeout(0.5 /* 500 ms */, cb_check_creds, &ctx);
1453# else
1454 g_timeout_add(500 /* ms */, (GSourceFunc)cb_check_creds, &ctx);
1455# endif
1456 }
1457 }
1458#endif /* VBOX_WITH_GUEST_PROPS */
1459
1460#ifdef VBOX_WITH_FLTK
1461 /*
1462 * Do own GDK main loop processing because FLTK also needs
1463 * to have the chance of processing its events.
1464 */
1465 GMainContext *pMainCtx = g_main_context_default();
1466 AssertPtr(pMainCtx);
1467
1468 while (g_fRunning)
1469 {
1470 g_main_context_iteration(pMainCtx,
1471 FALSE /* No blocking */);
1472 Fl::check();
1473 RTThreadSleep(10); /* Wait a bit, don't hog the CPU too much. */
1474 }
1475
1476 g_main_context_unref(pMainCtx);
1477
1478# ifdef VBOX_GREETER_WITH_PNG_SUPPORT
1479 if (pImgBanner)
1480 {
1481 delete pImgBanner; /* Call destructor to free bitmap data. */
1482 pImgBanner = NULL;
1483 }
1484# endif /* VBOX_GREETER_WITH_PNG_SUPPORT */
1485#else /* !VBOX_WITH_FLTK */
1486 gtk_main();
1487 /** @todo Never reached so far. LightDM sends a SIGTERM. */
1488#endif /* !VBOX_WITH_FLTK */
1489
1490 vboxGreeterLog("terminating\n");
1491
1492#ifdef VBOX_WITH_GUEST_PROPS
1493 if (uClientId)
1494 {
1495 rc2 = VbglR3GuestPropDisconnect(uClientId);
1496 AssertRC(rc2);
1497 }
1498#endif /* VBOX_WITH_GUEST_PROPS */
1499
1500 VbglR3Term();
1501
1502 RTEXITCODE rcExit = RT_SUCCESS(rc)
1503 ? RTEXITCODE_SUCCESS : RTEXITCODE_FAILURE;
1504
1505 vboxGreeterLog("terminated with exit code %ld (rc=%Rrc)\n",
1506 rcExit, rc);
1507
1508 vboxGreeterLogDestroy();
1509
1510 return rcExit;
1511}
1512
1513#ifdef DEBUG
1514DECLEXPORT(void) RTAssertMsg1Weak(const char *pszExpr, unsigned uLine, const char *pszFile, const char *pszFunction)
1515{
1516 RTAssertMsg1(pszExpr, uLine, pszFile, pszFunction);
1517}
1518#endif
1519
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette