X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=driver%2Ftest-passwd.c;h=2bd62199084b96fe3b00e2b28e6b686a2127d2bf;hb=aa75c7476aeaa84cf3abc192b376a8b03c325213;hp=4b6476397b0cfa50b712d8f026b45c18ecddbc55;hpb=447db08c956099b3b183886729108bf5b364c4b8;p=xscreensaver diff --git a/driver/test-passwd.c b/driver/test-passwd.c index 4b647639..2bd62199 100644 --- a/driver/test-passwd.c +++ b/driver/test-passwd.c @@ -1,4 +1,4 @@ -/* xscreensaver, Copyright (c) 1998-2005 Jamie Zawinski +/* xscreensaver, Copyright (c) 1998-2016 Jamie Zawinski * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that @@ -27,11 +27,13 @@ #include #include #include +#include #include "xscreensaver.h" #include "resources.h" #include "version.h" #include "visual.h" +#include "auth.h" char *progname = 0; char *progclass = 0; @@ -40,12 +42,13 @@ saver_info *global_si_kludge; FILE *real_stderr, *real_stdout; -void monitor_power_on (saver_info *si) {} +void monitor_power_on (saver_info *si, Bool on_p) {} Bool monitor_powered_on_p (saver_info *si) { return True; } void initialize_screensaver_window (saver_info *si) {} void raise_window (saver_info *si, Bool i, Bool b, Bool d) {} Bool blank_screen (saver_info *si) {return False;} void unblank_screen (saver_info *si) {} +void reset_watchdog_timer(saver_info *si, Bool on_p) {} Bool select_visual (saver_screen_info *ssi, const char *v) { return False; } Bool window_exists_p (Display *dpy, Window window) {return True;} void start_notice_events_timer (saver_info *si, Window w, Bool b) {} @@ -58,28 +61,16 @@ void saver_exit (saver_info *si, int status, const char *core) { exit(status);} int move_mouse_grab (saver_info *si, Window to, Cursor c, int ts) { return 0; } int mouse_screen (saver_info *si) { return 0; } void check_for_leaks (const char *where) { } -void exec_command (const char *shell, const char *command, int nice) { } void shutdown_stderr (saver_info *si) { } +void resize_screensaver_window (saver_info *si) { } +void describe_monitor_layout (saver_info *si) { } +Bool update_screen_layout (saver_info *si) { return 0; } +Bool in_signal_handler_p = 0; +char *timestring (time_t when) { return ""; } const char *blurb(void) { return progname; } Atom XA_SCREENSAVER, XA_DEMO, XA_PREFS; -void -get_screen_viewport (saver_screen_info *ssi, - int *x_ret, int *y_ret, - int *w_ret, int *h_ret, - int tx, int ty, - Bool verbose_p) -{ - *x_ret = 0; - *y_ret = 0; - *w_ret = WidthOfScreen (ssi->screen); - *h_ret = HeightOfScreen (ssi->screen); - - if (*w_ret > *h_ret * 2) *w_ret /= 2; /* xinerama kludge */ -} - - void idle_timer (XtPointer closure, XtIntervalId *id) { @@ -91,6 +82,50 @@ idle_timer (XtPointer closure, XtIntervalId *id) XPutBackEvent (si->dpy, &fake_event); } +static int +text_auth_conv ( + int num_msg, + const struct auth_message *auth_msgs, + struct auth_response **resp, + saver_info *si) +{ + char *input; + char buf[255]; + struct auth_response *responses; + int i; + + responses = calloc(num_msg, sizeof(struct auth_response)); + if (!responses) + return -1; + + /* The unlock state won't actually be used until this function returns and + * the auth module processes the response, but set it anyway for consistency + */ + si->unlock_state = ul_read; + + for (i = 0; i < num_msg; ++i) + { + printf ("\n%s: %s", progname, auth_msgs[i].msg); + if ( auth_msgs[i].type == AUTH_MSGTYPE_PROMPT_NOECHO + || auth_msgs[i].type == AUTH_MSGTYPE_PROMPT_ECHO) + { + input = fgets (buf, sizeof(buf)-1, stdin); + if (!input || !*input) + exit (0); + if (input[strlen(input)-1] == '\n') + input[strlen(input)-1] = 0; + + responses[i].response = strdup(input); + } + } + + *resp = responses; + + si->unlock_state = ul_finished; + + return 0; +} + #ifdef __GNUC__ __extension__ /* shut up about "string length is greater than the length @@ -103,6 +138,8 @@ static char *fallback[] = { 0 }; +extern Bool debug_passwd_window_p; /* lock.c kludge */ + int main (int argc, char **argv) { @@ -112,6 +149,7 @@ main (int argc, char **argv) saver_info sip; saver_info *si = &sip; saver_preferences *p = &si->prefs; + struct passwd *pw; memset(&sip, 0, sizeof(sip)); memset(&ssip, 0, sizeof(ssip)); @@ -126,6 +164,7 @@ main (int argc, char **argv) si->version = (char *) malloc (5); memcpy (si->version, screensaver_id + 17, 4); + si->version[4] = 0; progname = argv[0]; { char *s = strrchr(progname, '/'); @@ -143,6 +182,15 @@ main (int argc, char **argv) exit (1); } +#ifdef NO_LOCKING + if (which == PASS || which == TTY) + { + fprintf (stderr, "%s: compiled with NO_LOCKING\n", progname); + exit (1); + } +#endif + +#ifndef NO_LOCKING /* before hack_uid() for proper permissions */ lock_priv_init (argc, argv, True); @@ -153,9 +201,15 @@ main (int argc, char **argv) si->locking_disabled_p = True; si->nolock_reason = "error getting password"; } +#endif progclass = "XScreenSaver"; + if (!setlocale (LC_CTYPE, "")) + fprintf (stderr, "%s: warning: could not set default locale\n", + progname); + + if (which != TTY) { toplevel_shell = XtAppInitialize (&si->app, progclass, 0, 0, @@ -175,27 +229,46 @@ main (int argc, char **argv) visual_depth(si->default_screen->screen, si->default_screen->current_visual); + ssip.width = WidthOfScreen(ssip.screen); + ssip.height = HeightOfScreen(ssip.screen); + db = p->db; XtGetApplicationNameAndClass (si->dpy, &progname, &progclass); - load_init_file (&si->prefs); + load_init_file (si->dpy, &si->prefs); } p->verbose_p = True; + pw = getpwuid (getuid ()); + si->user = strdup (pw->pw_name); + +/* si->nscreens = 0; + si->screens = si->default_screen = 0; */ + while (1) { +#ifndef NO_LOCKING if (which == PASS) { - if (unlock_p (si)) - fprintf (stderr, "%s: password correct\n", progname); + si->unlock_cb = gui_auth_conv; + si->auth_finished_cb = auth_finished_cb; + + debug_passwd_window_p = True; + xss_authenticate(si, True); + + if (si->unlock_state == ul_success) + fprintf (stderr, "%s: authentication succeeded\n", progname); else - fprintf (stderr, "%s: password INCORRECT!\n", progname); + fprintf (stderr, "%s: authentication FAILED!\n", progname); XSync(si->dpy, False); + fprintf (stderr, "\n######################################\n\n"); sleep (3); } - else if (which == SPLASH) + else +#endif + if (which == SPLASH) { XEvent event; make_splash_dialog (si); @@ -211,25 +284,23 @@ main (int argc, char **argv) XSync (si->dpy, False); sleep (1); } +#ifndef NO_LOCKING else if (which == TTY) { - char *pass; - char buf[255]; - struct passwd *p = getpwuid (getuid ()); - printf ("\n%s: %s's password: ", progname, p->pw_name); + si->unlock_cb = text_auth_conv; - pass = fgets (buf, sizeof(buf)-1, stdin); - if (!pass || !*pass) - exit (0); - if (pass[strlen(pass)-1] == '\n') - pass[strlen(pass)-1] = 0; + printf ("%s: Authenticating user %s\n", progname, si->user); + xss_authenticate(si, True); - if (passwd_valid_p (pass, True)) + if (si->unlock_state == ul_success) printf ("%s: Ok!\n", progname); else printf ("%s: Wrong!\n", progname); } +#endif else abort(); } + + free(si->user); }