1 /* passwd.c --- verifying typed passwords with the OS.
2 * xscreensaver, Copyright (c) 1993-1998 Jamie Zawinski <jwz@jwz.org>
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation. No representations are made about the suitability of this
9 * software for any purpose. It is provided "as is" without express or
17 #ifndef NO_LOCKING /* whole file */
25 extern char *blurb(void);
37 #define countof(x) (sizeof((x))/sizeof(*(x)))
41 Bool (*init) (int argc, char **argv, Bool verbose_p);
42 Bool (*valid_p) (const char *typed_passwd, Bool verbose_p);
48 extern Bool kerberos_lock_init (int argc, char **argv, Bool verbose_p);
49 extern Bool kerberos_passwd_valid_p (const char *typed_passwd, Bool verbose_p);
52 extern Bool pam_lock_init (int argc, char **argv, Bool verbose_p);
53 extern Bool pam_passwd_valid_p (const char *typed_passwd, Bool verbose_p);
55 extern Bool pwent_lock_init (int argc, char **argv, Bool verbose_p);
56 extern Bool pwent_passwd_valid_p (const char *typed_passwd, Bool verbose_p);
59 /* The authorization methods to try, in order.
60 Note that the last one (the pwent version) is actually two auth methods,
61 since that code tries shadow passwords, and then non-shadow passwords.
62 (It's all in the same file since the APIs are randomly nearly-identical.)
64 struct auth_methods methods[] = {
66 { "Kerberos", kerberos_lock_init, kerberos_passwd_valid_p, False },
69 { "PAM", pam_lock_init, pam_passwd_valid_p, False },
71 { "normal", pwent_lock_init, pwent_passwd_valid_p, False }
76 lock_init (int argc, char **argv, Bool verbose_p)
80 for (i = 0; i < countof(methods); i++)
82 methods[i].initted_p = methods[i].init (argc, argv, verbose_p);
83 if (methods[i].initted_p)
86 fprintf (stderr, "%s: initialization of %s passwords failed.\n",
87 blurb(), methods[i].name);
94 passwd_valid_p (const char *typed_passwd, Bool verbose_p)
97 for (i = 0; i < countof(methods); i++)
99 if (methods[i].initted_p &&
100 methods[i].valid_p (typed_passwd, verbose_p))
102 /* If we successfully authenticated by method N, but attempting
103 to authenticate by method N-1 failed, mention that (since if
104 an earlier authentication method fails and a later one succeeds,
105 something screwy is probably going on.)
109 for (j = 0; j < i; j++)
110 if (methods[j].initted_p)
112 "%s: authentication via %s passwords failed.\n",
113 blurb(), methods[j].name);
115 "%s: but authentication via %s passwords succeeded.\n",
116 blurb(), methods[i].name);
119 return True; /* Successfully authenticated! */
123 return False; /* Authentication failure. */
126 #endif /* NO_LOCKING -- whole file */