http://packetstormsecurity.org/UNIX/admin/xscreensaver-3.28.tar.gz
[xscreensaver] / driver / test-passwd.c
index 9d35812279f62de2f59c448997589be7fde85a40..eaa884ff2ecb460769e3bcf0c48cc5373b440faa 100644 (file)
@@ -1,4 +1,4 @@
-/* xscreensaver, Copyright (c) 1998 Jamie Zawinski <jwz@jwz.org>
+/* xscreensaver, Copyright (c) 1998, 2001 Jamie Zawinski <jwz@jwz.org>
  *
  * Permission to use, copy, modify, distribute, and sell this software and its
  * documentation for any purpose is hereby granted without fee, provided that
    itself.
  */
 
-#define WHICH 0
+#define WHICH_PASS   100
+#define WHICH_SPLASH 101
+#define WHICH_TTY    102
+
+#define WHICH        WHICH_PASS
 
 #ifdef HAVE_CONFIG_H
 # include "config.h"
@@ -22,6 +26,8 @@
 
 #include <stdio.h>
 #include <ctype.h>
+#include <pwd.h>
+
 #include <X11/Xlib.h>
 #include <X11/Xatom.h>
 #include <X11/Intrinsic.h>
@@ -44,20 +50,34 @@ void monitor_power_on (saver_info *si) {}
 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) {}
-void blank_screen (saver_info *si) {}
+Bool blank_screen (saver_info *si) {return False;}
 void unblank_screen (saver_info *si) {}
 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) {}
+void start_notice_events_timer (saver_info *si, Window w, Bool b) {}
 Bool handle_clientmessage (saver_info *si, XEvent *e, Bool u) { return False; }
 int BadWindow_ehandler (Display *dpy, XErrorEvent *error) { exit(1); }
 const char *signal_name(int signal) { return "???"; }
 void restore_real_vroot (saver_info *si) {}
+void store_saver_status (saver_info *si) {}
 void saver_exit (saver_info *si, int status, const char *core) { exit(status);}
+int move_mouse_grab (saver_info *si, Window to, Cursor cursor) { return 0; }
 
 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,
+                     Bool verbose_p)
+{
+  *x_ret = 0;
+  *y_ret = 0;
+  *w_ret = WidthOfScreen (ssi->screen);
+  *h_ret = HeightOfScreen (ssi->screen);
+}
+
 
 void
 idle_timer (XtPointer closure, XtIntervalId *id)
@@ -79,7 +99,7 @@ static char *fallback[] = {
 int
 main (int argc, char **argv)
 {
-  Widget toplevel_shell;
+  Widget toplevel_shell = 0;
   saver_screen_info ssip;
   saver_info sip;
   saver_info *si = &sip;
@@ -99,22 +119,25 @@ main (int argc, char **argv)
   si->version = (char *) malloc (5);
   memcpy (si->version, screensaver_id + 17, 4);
   progname = argv[0];
-
-# ifdef SCO
-  set_auth_parameters(argc, argv);
-# endif /* SCO */
+  {
+    char *s = strrchr(progname, '/');
+    if (*s) strcpy (progname, s+1);
+  }
 
   /* before hack_uid() for proper permissions */
-  if (! lock_init (argc, argv, True))
+  lock_priv_init (argc, argv, True);
+
+  hack_uid (si);
+
+  if (! lock_init (argc, argv, si->prefs.verbose_p))
     {
       si->locking_disabled_p = True;
       si->nolock_reason = "error getting password";
     }
 
-  hack_uid (si);
-
   progclass = "XScreenSaver";
 
+#if (WHICH != WHICH_TTY)
   toplevel_shell = XtAppInitialize (&si->app, progclass, 0, 0,
                                    &argc, argv, fallback,
                                    0, 0);
@@ -137,9 +160,13 @@ main (int argc, char **argv)
 
   load_init_file (&si->prefs);
 
+#endif /* (WHICH != 2) */
+
+  p->verbose_p = True;
+
   while (1)
     {
-#if WHICH == 0
+#if WHICH == WHICH_PASS
       if (unlock_p (si))
        fprintf (stderr, "%s: password correct\n", progname);
       else
@@ -147,7 +174,7 @@ main (int argc, char **argv)
 
       XSync(si->dpy, False);
       sleep (3);
-#elif WHICH == 1
+#elif WHICH == WHICH_SPLASH
       {
        XEvent event;
        make_splash_dialog (si);
@@ -163,6 +190,26 @@ main (int argc, char **argv)
        XSync (si->dpy, False);
        sleep (1);
       }
+#elif WHICH == WHICH_TTY
+      {
+        char *pass;
+        char buf[255];
+        struct passwd *p = getpwuid (getuid ());
+        printf ("\n%s: %s's password: ", progname, p->pw_name);
+
+        pass = fgets (buf, sizeof(buf)-1, stdin);
+        if (!pass || !*pass)
+          exit (0);
+        if (pass[strlen(pass)-1] == '\n')
+          pass[strlen(pass)-1] = 0;
+
+        if (passwd_valid_p (pass, True))
+          printf ("%s: Ok!\n", progname);
+        else
+          printf ("%s: Wrong!\n", progname);
+      }
+#else
+# error bogus WHICH value!
 #endif
     }
 }