1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
|
/* GDM - The Gnome Display Manager
* Copyright (C) 1998, 1999 Martin Kasper Petersen <mkp@mkp.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <syslog.h>
#include <pwd.h>
#include <glib.h>
#include <crypt.h>
#include <config.h>
#include <gnome.h>
#ifdef HAVE_PAM
#include <security/pam_appl.h>
#endif /* HAVE_PAM */
#ifdef HAVE_SHADOW
#include <shadow.h>
#endif /* HAVE_SHADOW */
#include "gdm.h"
static const gchar RCSid[]="$Id$";
extern void gdm_abort (const char*, ...);
extern void gdm_debug (const char*, ...);
extern void gdm_error (const char*, ...);
extern gchar *gdm_slave_greeter_ctl (gchar cmd, gchar *str);
extern gboolean GdmVerboseAuth;
extern gboolean GdmAllowRoot;
gchar *gdm_verify_user (gchar *display);
void gdm_verify_cleanup (void);
#ifdef HAVE_PAM
pam_handle_t *pamh;
static gint
gdm_verify_pam_conv (int num_msg, const struct pam_message **msg,
struct pam_response **resp,
void *appdata_ptr)
{
gint replies = 0;
struct pam_response *reply = NULL;
gchar *s;
reply = g_new0 (struct pam_response, num_msg);
if (!reply)
return PAM_CONV_ERR;
for (replies = 0; replies < num_msg; replies++) {
switch (msg[replies]->msg_style) {
case PAM_PROMPT_ECHO_ON:
s = gdm_slave_greeter_ctl (GDM_PROMPT, (gchar *) msg[replies]->msg);
reply[replies].resp_retcode = PAM_SUCCESS;
reply[replies].resp = g_strdup (s);
g_free (s);
break;
case PAM_PROMPT_ECHO_OFF:
s = gdm_slave_greeter_ctl (GDM_NOECHO, (gchar *) msg[replies]->msg);
reply[replies].resp_retcode = PAM_SUCCESS;
reply[replies].resp = g_strdup (s);
g_free (s);
break;
case PAM_ERROR_MSG:
case PAM_TEXT_INFO:
gdm_slave_greeter_ctl (GDM_MSGERR, (gchar *) msg[replies]->msg);
reply[replies].resp_retcode = PAM_SUCCESS;
reply[replies].resp = NULL;
break;
default:
g_free (reply);
return (PAM_CONV_ERR);
}
}
*resp = reply;
return (PAM_SUCCESS);
}
static struct pam_conv pamc = {
&gdm_verify_pam_conv,
NULL
};
gchar *
gdm_verify_user (gchar *display)
{
gint pamerr, i;
gchar *login;
gchar **pamenv;
struct passwd *pwent;
login = gdm_slave_greeter_ctl (GDM_PROMPT, _("Login:"));
if (!login)
return (NULL);
pwent = getpwnam (login);
if (!pwent) {
gdm_error (_("Couldn't authenticate %s"), login);
if (GdmVerboseAuth)
gdm_slave_greeter_ctl (GDM_MSGERR, _("User unknown"));
return (NULL);
}
if (GdmAllowRoot && pwent->pw_uid == 0) {
gdm_error (_("Root login disallowed on display '%s'"), display);
if (GdmVerboseAuth)
gdm_slave_greeter_ctl (GDM_MSGERR, _("Root login disallowed"));
return (NULL);
}
if ((pamerr = pam_start ("gdm", login, &pamc, &pamh)) != PAM_SUCCESS) {
gdm_error (_("Can't find /etc/pam.d/gdm!"));
}
if ((pamerr = pam_set_item (pamh, PAM_TTY, display)) != PAM_SUCCESS) {
gdm_error (_("Can't set PAM_TTY=%s"), ":0");
goto pamerr;
}
if ((pamerr = pam_authenticate (pamh, 0)) != PAM_SUCCESS) {
gdm_error (_("Couldn't authenticate %s"), login);
goto pamerr;
}
if ((pamerr = pam_acct_mgmt (pamh, 0)) != PAM_SUCCESS) {
gdm_error (_("Couldn't set acct. mgmt for %s"), login);
goto pamerr;
}
if ((pamerr = pam_setcred (pamh, 0)) != PAM_SUCCESS) {
gdm_error (_("Couldn't set credentials for %s"), login);
goto pamerr;
}
if ((pamerr = pam_open_session (pamh, 0)) != PAM_SUCCESS) {
gdm_error (_("Couldn't open session for %s"), login);
goto pamerr;
}
if ((pamenv = pam_getenvlist (pamh))) {
for (i = 0 ; pamenv[i] ; i++) {
putenv (pamenv[i]);
}
}
return (login);
pamerr:
if (GdmVerboseAuth)
gdm_slave_greeter_ctl (GDM_MSGERR, (gchar *) pam_strerror (pamh, pamerr));
pam_end (pamh, pamerr);
pamh = NULL;
/* Workaround to avoid gdm messages being logged as PAM_pwdb */
closelog();
openlog ("gdm", LOG_PID, LOG_DAEMON);
return (NULL);
}
#else /* HAVE_PAM */
gchar *
gdm_verify_user (gchar *display)
{
gchar *login, *passwd, *ppasswd;
struct passwd *pwent;
#ifdef HAVE_SHADOW
struct spwd *sp;
#endif
login = gdm_slave_greeter_ctl (GDM_PROMPT, _("Login:"));
pwent = getpwnam (login);
if (!pwent) {
gdm_error (_("Couldn't authenticate %s"), login);
if (GdmVerboseAuth)
gdm_slave_greeter_ctl (GDM_MSGERR, _("User unknown"));
return (NULL);
}
if (GdmAllowRoot && pwent->pw_uid == 0) {
gdm_error (_("Root login disallowed on display '%s'"), display);
if (GdmVerboseAuth)
gdm_slave_greeter_ctl (GDM_MSGERR, _("Root login disallowed"));
return (NULL);
}
ppasswd = !pwent ? NULL : pwent->pw_passwd;
#ifdef HAVE_SHADOW
sp = getspnam (login);
if (sp)
ppasswd = sp->sp_pwdp;
endspent();
#endif /* HAVE_SHADOW */
passwd = gdm_slave_greeter_ctl (GDM_NOECHO, _("Password:"));
if (!passwd || !ppasswd || strcmp (crypt (passwd, ppasswd), ppasswd)) {
if (GdmVerboseAuth)
gdm_slave_greeter_ctl (GDM_MSGERR, _("Incorrect password"));
return (NULL);
}
return (login);
}
#endif /* HAVE_PAM */
void
gdm_verify_cleanup (void)
{
#ifdef HAVE_PAM
gdm_debug ("gdm_verify_cleanup: Closing session %d", pamh);
if (pamh) {
pam_close_session (pamh, 0);
pam_end (pamh, PAM_SUCCESS);
pamh = NULL;
}
/* Workaround to avoid gdm messages being logged as PAM_pwdb */
closelog();
openlog ("gdm", LOG_PID, LOG_DAEMON);
#endif /* HAVE_PAM */
}
/* EOF */
|