1 /* xscreensaver, Copyright (c) 1998-2008 Jamie Zawinski <jwz@jwz.org>
3 * Permission to use, copy, modify, distribute, and sell this software and its
4 * documentation for any purpose is hereby granted without fee, provided that
5 * the above copyright notice appear in all copies and that both that
6 * copyright notice and this permission notice appear in supporting
7 * documentation. No representations are made about the suitability of this
8 * software for any purpose. It is provided "as is" without express or
12 /* This is a kludgy test harness for debugging the password dialog box.
13 It's somewhat easier to debug it here than in the xscreensaver executable
26 #include <X11/Xatom.h>
27 #include <X11/Intrinsic.h>
28 #include <X11/StringDefs.h>
29 #include <X11/Shell.h>
31 #include "xscreensaver.h"
32 #include "resources.h"
40 saver_info *global_si_kludge;
42 FILE *real_stderr, *real_stdout;
44 void monitor_power_on (saver_info *si) {}
45 Bool monitor_powered_on_p (saver_info *si) { return True; }
46 void initialize_screensaver_window (saver_info *si) {}
47 void raise_window (saver_info *si, Bool i, Bool b, Bool d) {}
48 Bool blank_screen (saver_info *si) {return False;}
49 void unblank_screen (saver_info *si) {}
50 Bool select_visual (saver_screen_info *ssi, const char *v) { return False; }
51 Bool window_exists_p (Display *dpy, Window window) {return True;}
52 void start_notice_events_timer (saver_info *si, Window w, Bool b) {}
53 Bool handle_clientmessage (saver_info *si, XEvent *e, Bool u) { return False; }
54 int BadWindow_ehandler (Display *dpy, XErrorEvent *error) { exit(1); }
55 const char *signal_name(int signal) { return "???"; }
56 Bool restore_real_vroot (saver_info *si) { return False; }
57 void store_saver_status (saver_info *si) {}
58 void saver_exit (saver_info *si, int status, const char *core) { exit(status);}
59 int move_mouse_grab (saver_info *si, Window to, Cursor c, int ts) { return 0; }
60 int mouse_screen (saver_info *si) { return 0; }
61 void check_for_leaks (const char *where) { }
62 void shutdown_stderr (saver_info *si) { }
64 const char *blurb(void) { return progname; }
65 Atom XA_SCREENSAVER, XA_DEMO, XA_PREFS;
68 idle_timer (XtPointer closure, XtIntervalId *id)
70 saver_info *si = (saver_info *) closure;
72 fake_event.type = 0; /* XAnyEvent type, ignored. */
73 fake_event.xany.display = si->dpy;
74 fake_event.xany.window = 0;
75 XPutBackEvent (si->dpy, &fake_event);
82 const struct auth_message *auth_msgs,
83 struct auth_response **resp,
88 struct auth_response *responses;
91 responses = calloc(num_msg, sizeof(struct auth_response));
95 /* The unlock state won't actually be used until this function returns and
96 * the auth module processes the response, but set it anyway for consistency
98 si->unlock_state = ul_read;
100 for (i = 0; i < num_msg; ++i)
102 printf ("\n%s: %s", progname, auth_msgs[i].msg);
103 if ( auth_msgs[i].type == AUTH_MSGTYPE_PROMPT_NOECHO
104 || auth_msgs[i].type == AUTH_MSGTYPE_PROMPT_ECHO)
106 input = fgets (buf, sizeof(buf)-1, stdin);
107 if (!input || !*input)
109 if (input[strlen(input)-1] == '\n')
110 input[strlen(input)-1] = 0;
112 responses[i].response = strdup(input);
118 si->unlock_state = ul_finished;
125 __extension__ /* shut up about "string length is greater than the length
126 ISO C89 compilers are required to support" when including
130 static char *fallback[] = {
131 #include "XScreenSaver_ad.h"
136 main (int argc, char **argv)
138 enum { PASS, SPLASH, TTY } which;
139 Widget toplevel_shell = 0;
140 saver_screen_info ssip;
142 saver_info *si = &sip;
143 saver_preferences *p = &si->prefs;
146 memset(&sip, 0, sizeof(sip));
147 memset(&ssip, 0, sizeof(ssip));
150 si->screens = si->default_screen = &ssip;
153 global_si_kludge = si;
154 real_stderr = stderr;
155 real_stdout = stdout;
157 si->version = (char *) malloc (5);
158 memcpy (si->version, screensaver_id + 17, 4);
161 char *s = strrchr(progname, '/');
162 if (*s) strcpy (progname, s+1);
165 if (argc != 2) goto USAGE;
166 else if (!strcmp (argv[1], "pass")) which = PASS;
167 else if (!strcmp (argv[1], "splash")) which = SPLASH;
168 else if (!strcmp (argv[1], "tty")) which = TTY;
172 fprintf (stderr, "usage: %s [ pass | splash | tty ]\n", progname);
177 if (which == PASS || which == TTY)
179 fprintf (stderr, "%s: compiled with NO_LOCKING\n", progname);
185 /* before hack_uid() for proper permissions */
186 lock_priv_init (argc, argv, True);
190 if (! lock_init (argc, argv, True))
192 si->locking_disabled_p = True;
193 si->nolock_reason = "error getting password";
197 progclass = "XScreenSaver";
201 toplevel_shell = XtAppInitialize (&si->app, progclass, 0, 0,
202 &argc, argv, fallback,
205 si->dpy = XtDisplay (toplevel_shell);
206 p->db = XtDatabase (si->dpy);
207 si->default_screen->toplevel_shell = toplevel_shell;
208 si->default_screen->screen = XtScreen(toplevel_shell);
209 si->default_screen->default_visual =
210 si->default_screen->current_visual =
211 DefaultVisualOfScreen(si->default_screen->screen);
212 si->default_screen->screensaver_window =
213 RootWindowOfScreen(si->default_screen->screen);
214 si->default_screen->current_depth =
215 visual_depth(si->default_screen->screen,
216 si->default_screen->current_visual);
218 ssip.width = WidthOfScreen(ssip.screen);
219 ssip.height = HeightOfScreen(ssip.screen);
222 XtGetApplicationNameAndClass (si->dpy, &progname, &progclass);
224 load_init_file (si->dpy, &si->prefs);
229 pw = getpwuid (getuid ());
230 si->user = strdup (pw->pw_name);
233 si->screens = si->default_screen = 0; */
240 si->unlock_cb = gui_auth_conv;
241 si->auth_finished_cb = auth_finished_cb;
243 xss_authenticate(si, True);
245 if (si->unlock_state == ul_success)
246 fprintf (stderr, "%s: authentication succeeded\n", progname);
248 fprintf (stderr, "%s: authentication FAILED!\n", progname);
250 XSync(si->dpy, False);
251 fprintf (stderr, "\n######################################\n\n");
259 make_splash_dialog (si);
260 XtAppAddTimeOut (si->app, p->splash_duration + 1000,
261 idle_timer, (XtPointer) si);
262 while (si->splash_dialog)
264 XtAppNextEvent (si->app, &event);
265 if (event.xany.window == si->splash_dialog)
266 handle_splash_event (si, &event);
267 XtDispatchEvent (&event);
269 XSync (si->dpy, False);
273 else if (which == TTY)
275 si->unlock_cb = text_auth_conv;
277 printf ("%s: Authenticating user %s\n", progname, si->user);
278 xss_authenticate(si, True);
280 if (si->unlock_state == ul_success)
281 printf ("%s: Ok!\n", progname);
283 printf ("%s: Wrong!\n", progname);