1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
3
* Copyright (C) 2004-2005 William Jon McCann <mccann@jhu.edu>
5
* This program is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU General Public License as
7
* published by the Free Software Foundation; either version 2 of the
8
* License, or (at your option) any later version.
10
* This program is distributed in the hope that it will be useful, but
11
* WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
* General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
20
* Authors: William Jon McCann <mccann@jhu.edu>
29
#include <sys/types.h>
32
#include <glib/gi18n.h>
36
#include "gs-lock-plug.h"
42
/* Profiling stuff adapted from gtkfilechooserdefault */
44
#undef PROFILE_LOCK_DIALOG
45
#ifdef PROFILE_LOCK_DIALOG
47
#define PROFILE_INDENT 4
48
static int profile_indent;
51
profile_add_indent (int indent)
53
profile_indent += indent;
54
if (profile_indent < 0)
55
g_error ("You screwed up your indentation");
59
_gs_lock_plug_profile_log (const char *func,
68
profile_add_indent (indent);
70
g_get_current_time (&now);
72
if (profile_indent == 0)
73
str = g_strdup_printf ("MARK %ld.%6.6ld: %s: %s %s %s", now.tv_sec, now.tv_usec, G_STRLOC, func, msg1 ? msg1 : "", msg2 ? msg2 : "");
75
str = g_strdup_printf ("MARK %ld.%6.6ld: %s: %*c %s %s %s", now.tv_sec, now.tv_usec, G_STRLOC, profile_indent - 1, ' ', func, msg1 ? msg1 : "", msg2 ? msg2 : "");
77
fprintf (stderr, "%s\n", str);
81
profile_add_indent (indent);
84
#define profile_start(x, y) _gs_lock_plug_profile_log (G_STRFUNC, PROFILE_INDENT, x, y)
85
#define profile_end(x, y) _gs_lock_plug_profile_log (G_STRFUNC, -PROFILE_INDENT, x, y)
86
#define profile_msg(x, y) _gs_lock_plug_profile_log (NULL, 0, x, y)
88
#define profile_start(x, y)
89
#define profile_end(x, y)
90
#define profile_msg(x, y)
94
static gboolean verbose = FALSE;
95
static gboolean show_version = FALSE;
96
static gboolean enable_logout = FALSE;
97
static gboolean enable_switch = FALSE;
99
static GOptionEntry entries [] = {
100
{ "verbose", 0, 0, G_OPTION_ARG_NONE, &verbose,
101
N_("Show debugging output"), NULL },
102
{ "version", 0, 0, G_OPTION_ARG_NONE, &show_version,
103
N_("Version of this application"), NULL },
104
{ "enable-logout", 0, 0, G_OPTION_ARG_NONE, &enable_logout,
105
N_("Show the logout button"), NULL },
106
{ "enable-switch", 0, 0, G_OPTION_ARG_NONE, &enable_switch,
107
N_("Show the switch user button"), NULL },
112
get_id_string (GtkWidget *widget)
116
g_return_val_if_fail (widget != NULL, NULL);
117
g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
119
id = g_strdup_printf ("0x%X",
120
(guint32) GDK_WINDOW_XID (widget->window));
125
print_id (GtkWidget *widget)
127
profile_start ("start", NULL);
129
printf ("WINDOW ID=%s\n", get_id_string (widget));
132
profile_end ("end", NULL);
138
response_cancel (void)
140
printf ("RESPONSE=CANCEL\n");
147
printf ("RESPONSE=OK\n");
152
response_lock_init_failed (void)
154
/* if we fail to lock then we should drop the dialog */
159
response_cb (GSLockPlug *plug,
162
switch (response_id) {
163
case (GS_LOCK_PLUG_RESPONSE_OK):
166
case (GS_LOCK_PLUG_RESPONSE_CANCEL):
176
popup_dialog_idle (void)
180
profile_start ("start", NULL);
182
widget = gs_lock_plug_new ();
185
g_object_set (widget, "logout-enabled", TRUE, NULL);
189
g_object_set (widget, "switch-enabled", TRUE, NULL);
192
g_signal_connect (GS_LOCK_PLUG (widget), "response", G_CALLBACK (response_cb), NULL);
194
gtk_widget_show (widget);
198
profile_end ("end", NULL);
205
* Copyright (c) 1991-2004 Jamie Zawinski <jwz@jwz.org>
206
* Copyright (c) 2005 William Jon McCann <mccann@jhu.edu>
208
* Initializations that potentially take place as a priveleged user:
209
If the xscreensaver executable is setuid root, then these initializations
210
are run as root, before discarding privileges.
213
privileged_initialization (int *argc,
222
profile_start ("start", NULL);
225
/* before hack_uid () for proper permissions */
226
lock_priv_init (*argc, argv, verbose);
227
#endif /* NO_LOCKING */
229
ret = hack_uid (&nolock_reason,
233
g_warning ("Locking disabled: %s", nolock_reason);
234
if (uid_message && verbose)
235
g_print ("Modified UID: %s", uid_message);
237
g_free (nolock_reason);
239
g_free (uid_message);
241
profile_end ("end", NULL);
248
* Copyright (c) 1991-2004 Jamie Zawinski <jwz@jwz.org>
249
* Copyright (c) 2005 William Jon McCann <mccann@jhu.edu>
251
* Figure out what locking mechanisms are supported.
254
lock_initialization (int *argc,
256
char **nolock_reason,
259
profile_start ("start", NULL);
262
*nolock_reason = NULL;
266
*nolock_reason = g_strdup ("not compiled with locking support");
268
#else /* !NO_LOCKING */
270
/* Finish initializing locking, now that we're out of privileged code. */
271
if (! lock_init (*argc, argv, verbose)) {
273
*nolock_reason = g_strdup ("error getting password");
277
/* If locking is currently enabled, but the environment indicates that
278
we have been launched as GDM's "Background" program, then disable
279
locking just in case.
281
if (getenv ("RUNNING_UNDER_GDM")) {
283
*nolock_reason = g_strdup ("running under GDM");
287
/* If the server is XDarwin (MacOS X) then disable locking.
288
(X grabs only affect X programs, so you can use Command-Tab
289
to bring any other Mac program to the front, e.g., Terminal.)
292
gboolean macos = FALSE;
295
/* Disable locking if *running* on Apple hardware, since we have no
296
reliable way to determine whether the server is running on MacOS.
297
Hopefully __APPLE__ means "MacOS" and not "Linux on Mac hardware"
298
but I'm not really sure about that.
305
*nolock_reason = g_strdup ("Cannot lock securely on MacOS X");
310
#endif /* NO_LOCKING */
312
profile_end ("end", NULL);
321
GError *error = NULL;
322
char *nolock_reason = NULL;
325
bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
326
# ifdef HAVE_BIND_TEXTDOMAIN_CODESET
327
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
329
textdomain (GETTEXT_PACKAGE);
335
fprintf (stderr, "%s\n", error->message);
336
response_lock_init_failed ();
340
profile_start ("start", NULL);
342
if (! privileged_initialization (&argc, argv, verbose)) {
343
response_lock_init_failed ();
347
if (! gtk_init_with_args (&argc, &argv, NULL, entries, NULL, &error)) {
348
fprintf (stderr, "%s", error->message);
349
g_error_free (error);
354
g_print ("%s %s\n", argv [0], VERSION);
358
if (! lock_initialization (&argc, argv, &nolock_reason, verbose)) {
360
g_warning ("Screen locking disabled: %s", nolock_reason);
361
g_free (nolock_reason);
363
response_lock_init_failed ();
367
g_idle_add ((GSourceFunc)popup_dialog_idle, NULL);
371
profile_end ("end", NULL);