Lines 1-104
Link Here
|
1 |
--- slock.c.orig 2016-02-17 12:36:44.640577000 -0800 |
|
|
2 |
+++ slock.c 2016-02-17 12:48:20.966625000 -0800 |
3 |
@@ -23,6 +23,10 @@ |
4 |
#include <bsd_auth.h> |
5 |
#endif |
6 |
|
7 |
+#if HAVE_PAM |
8 |
+#include <security/pam_appl.h> |
9 |
+#endif |
10 |
+ |
11 |
enum { |
12 |
INIT, |
13 |
INPUT, |
14 |
@@ -85,7 +89,7 @@ |
15 |
} |
16 |
#endif |
17 |
|
18 |
-#ifndef HAVE_BSD_AUTH |
19 |
+#if !defined(HAVE_BSD_AUTH) && !defined(HAVE_PAM) |
20 |
/* only run as root */ |
21 |
static const char * |
22 |
getpw(void) |
23 |
@@ -119,8 +123,41 @@ |
24 |
} |
25 |
#endif |
26 |
|
27 |
+#ifdef HAVE_PAM |
28 |
+static int |
29 |
+slock_conv (int nof_msg, const struct pam_message **msg, struct pam_response **resp, void *data) { |
30 |
+ struct pam_response *r = calloc (nof_msg, sizeof **resp); |
31 |
+ if (r == NULL) { |
32 |
+ die("slock: malloc: %s", strerror(errno)); |
33 |
+ } |
34 |
+ |
35 |
+ while (nof_msg--) { |
36 |
+ r[nof_msg].resp_retcode = 0; |
37 |
+ r[nof_msg].resp = strdup (data); |
38 |
+ } |
39 |
+ |
40 |
+ *resp = r; |
41 |
+ |
42 |
+ return PAM_SUCCESS; |
43 |
+} |
44 |
+ |
45 |
+static int |
46 |
+auth_pam (const char *user, char *pass) { |
47 |
+ static struct pam_conv conv = {slock_conv, NULL}; |
48 |
+ pam_handle_t *ph; |
49 |
+ |
50 |
+ conv.appdata_ptr = pass; |
51 |
+ |
52 |
+ if (pam_start("slock", user, &conv, &ph) != PAM_SUCCESS) { |
53 |
+ die("slock: pam_start"); |
54 |
+ } |
55 |
+ |
56 |
+ return (pam_authenticate(ph, 0) == PAM_SUCCESS); |
57 |
+} |
58 |
+#endif |
59 |
+ |
60 |
static void |
61 |
-#ifdef HAVE_BSD_AUTH |
62 |
+#if defined(HAVE_BSD_AUTH) || defined(HAVE_PAM) |
63 |
readpw(Display *dpy) |
64 |
#else |
65 |
readpw(Display *dpy, const char *pws) |
66 |
@@ -159,8 +196,10 @@ |
67 |
switch (ksym) { |
68 |
case XK_Return: |
69 |
passwd[len] = 0; |
70 |
-#ifdef HAVE_BSD_AUTH |
71 |
+#if defined (HAVE_BSD_AUTH) |
72 |
running = !auth_userokay(getlogin(), NULL, "auth-xlock", passwd); |
73 |
+#elif defined (HAVE_PAM) |
74 |
+ running = !auth_pam(getlogin(), passwd); |
75 |
#else |
76 |
running = !!strcmp(crypt(passwd, pws), pws); |
77 |
#endif |
78 |
@@ -289,7 +328,7 @@ |
79 |
|
80 |
int |
81 |
main(int argc, char **argv) { |
82 |
-#ifndef HAVE_BSD_AUTH |
83 |
+#if !defined(HAVE_BSD_AUTH) && !defined(HAVE_PAM) |
84 |
const char *pws; |
85 |
#endif |
86 |
Display *dpy; |
87 |
@@ -308,7 +347,7 @@ |
88 |
if (!getpwuid(getuid())) |
89 |
die("slock: no passwd entry for you\n"); |
90 |
|
91 |
-#ifndef HAVE_BSD_AUTH |
92 |
+#if !defined(HAVE_BSD_AUTH) && !defined(HAVE_PAM) |
93 |
pws = getpw(); |
94 |
#endif |
95 |
|
96 |
@@ -341,7 +380,7 @@ |
97 |
} |
98 |
|
99 |
/* Everything is now blank. Now wait for the correct password. */ |
100 |
-#ifdef HAVE_BSD_AUTH |
101 |
+#if defined(HAVE_BSD_AUTH) || defined(HAVE_PAM) |
102 |
readpw(dpy); |
103 |
#else |
104 |
readpw(dpy, pws); |