1 /* xscreensaver, Copyright (c) 1998-2005 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"
39 saver_info *global_si_kludge;
41 FILE *real_stderr, *real_stdout;
43 void monitor_power_on (saver_info *si) {}
44 Bool monitor_powered_on_p (saver_info *si) { return True; }
45 void initialize_screensaver_window (saver_info *si) {}
46 void raise_window (saver_info *si, Bool i, Bool b, Bool d) {}
47 Bool blank_screen (saver_info *si) {return False;}
48 void unblank_screen (saver_info *si) {}
49 Bool select_visual (saver_screen_info *ssi, const char *v) { return False; }
50 Bool window_exists_p (Display *dpy, Window window) {return True;}
51 void start_notice_events_timer (saver_info *si, Window w, Bool b) {}
52 Bool handle_clientmessage (saver_info *si, XEvent *e, Bool u) { return False; }
53 int BadWindow_ehandler (Display *dpy, XErrorEvent *error) { exit(1); }
54 const char *signal_name(int signal) { return "???"; }
55 Bool restore_real_vroot (saver_info *si) { return False; }
56 void store_saver_status (saver_info *si) {}
57 void saver_exit (saver_info *si, int status, const char *core) { exit(status);}
58 int move_mouse_grab (saver_info *si, Window to, Cursor c, int ts) { return 0; }
59 int mouse_screen (saver_info *si) { return 0; }
60 void check_for_leaks (const char *where) { }
61 void exec_command (const char *shell, const char *command, int nice) { }
62 void shutdown_stderr (saver_info *si) { }
64 const char *blurb(void) { return progname; }
65 Atom XA_SCREENSAVER, XA_DEMO, XA_PREFS;
68 get_screen_viewport (saver_screen_info *ssi,
69 int *x_ret, int *y_ret,
70 int *w_ret, int *h_ret,
76 *w_ret = WidthOfScreen (ssi->screen);
77 *h_ret = HeightOfScreen (ssi->screen);
79 if (*w_ret > *h_ret * 2) *w_ret /= 2; /* xinerama kludge */
84 idle_timer (XtPointer closure, XtIntervalId *id)
86 saver_info *si = (saver_info *) closure;
88 fake_event.type = 0; /* XAnyEvent type, ignored. */
89 fake_event.xany.display = si->dpy;
90 fake_event.xany.window = 0;
91 XPutBackEvent (si->dpy, &fake_event);
96 __extension__ /* shut up about "string length is greater than the length
97 ISO C89 compilers are required to support" when including
101 static char *fallback[] = {
102 #include "XScreenSaver_ad.h"
107 main (int argc, char **argv)
109 enum { PASS, SPLASH, TTY } which;
110 Widget toplevel_shell = 0;
111 saver_screen_info ssip;
113 saver_info *si = &sip;
114 saver_preferences *p = &si->prefs;
116 memset(&sip, 0, sizeof(sip));
117 memset(&ssip, 0, sizeof(ssip));
120 si->screens = si->default_screen = &ssip;
123 global_si_kludge = si;
124 real_stderr = stderr;
125 real_stdout = stdout;
127 si->version = (char *) malloc (5);
128 memcpy (si->version, screensaver_id + 17, 4);
131 char *s = strrchr(progname, '/');
132 if (*s) strcpy (progname, s+1);
135 if (argc != 2) goto USAGE;
136 else if (!strcmp (argv[1], "pass")) which = PASS;
137 else if (!strcmp (argv[1], "splash")) which = SPLASH;
138 else if (!strcmp (argv[1], "tty")) which = TTY;
142 fprintf (stderr, "usage: %s [ pass | splash | tty ]\n", progname);
146 /* before hack_uid() for proper permissions */
147 lock_priv_init (argc, argv, True);
151 if (! lock_init (argc, argv, True))
153 si->locking_disabled_p = True;
154 si->nolock_reason = "error getting password";
157 progclass = "XScreenSaver";
161 toplevel_shell = XtAppInitialize (&si->app, progclass, 0, 0,
162 &argc, argv, fallback,
165 si->dpy = XtDisplay (toplevel_shell);
166 p->db = XtDatabase (si->dpy);
167 si->default_screen->toplevel_shell = toplevel_shell;
168 si->default_screen->screen = XtScreen(toplevel_shell);
169 si->default_screen->default_visual =
170 si->default_screen->current_visual =
171 DefaultVisualOfScreen(si->default_screen->screen);
172 si->default_screen->screensaver_window =
173 RootWindowOfScreen(si->default_screen->screen);
174 si->default_screen->current_depth =
175 visual_depth(si->default_screen->screen,
176 si->default_screen->current_visual);
179 XtGetApplicationNameAndClass (si->dpy, &progname, &progclass);
181 load_init_file (&si->prefs);
191 fprintf (stderr, "%s: password correct\n", progname);
193 fprintf (stderr, "%s: password INCORRECT!\n", progname);
195 XSync(si->dpy, False);
198 else if (which == SPLASH)
201 make_splash_dialog (si);
202 XtAppAddTimeOut (si->app, p->splash_duration + 1000,
203 idle_timer, (XtPointer) si);
204 while (si->splash_dialog)
206 XtAppNextEvent (si->app, &event);
207 if (event.xany.window == si->splash_dialog)
208 handle_splash_event (si, &event);
209 XtDispatchEvent (&event);
211 XSync (si->dpy, False);
214 else if (which == TTY)
218 struct passwd *p = getpwuid (getuid ());
219 printf ("\n%s: %s's password: ", progname, p->pw_name);
221 pass = fgets (buf, sizeof(buf)-1, stdin);
224 if (pass[strlen(pass)-1] == '\n')
225 pass[strlen(pass)-1] = 0;
227 if (passwd_valid_p (pass, True))
228 printf ("%s: Ok!\n", progname);
230 printf ("%s: Wrong!\n", progname);