1 | /* |
2 | * Copyright (c) 1998 Christian Esken <esken@kde.org> |
3 | * Copyright (c) 2003 Oswald Buddenhagen <ossi@kde.org> |
4 | * |
5 | * This program is free software; you can redistribute it and/or |
6 | * modify it under the terms of the GNU General Public |
7 | * License as published by the Free Software Foundation; either |
8 | * version 2 of the License, or (at your option) any later version. |
9 | * |
10 | * This program is distributed in the hope that it will be useful, |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | * General Public License for more details. |
14 | * |
15 | * You should have received a copy of the GNU General Public |
16 | * License along with this program; if not, write to the Free |
17 | * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
18 | * |
19 | * Copyright (C) 1998, Christian Esken <esken@kde.org> |
20 | */ |
21 | |
22 | #include "kcheckpass.h" |
23 | |
24 | #ifdef HAVE_ETCPASSWD |
25 | |
26 | /******************************************************************* |
27 | * This is the authentication code for /etc/passwd passwords |
28 | *******************************************************************/ |
29 | |
30 | #include <string.h> |
31 | #include <stdlib.h> |
32 | |
33 | AuthReturn Authenticate(const char *method, |
34 | const char *login, char *(*conv) (ConvRequest, const char *)) |
35 | { |
36 | struct passwd *pw; |
37 | char *passwd; |
38 | char *crpt_passwd; |
39 | |
40 | if (strcmp(method, "classic" )) |
41 | return AuthError; |
42 | |
43 | /* Get the password entry for the user we want */ |
44 | if (!(pw = getpwnam(login))) |
45 | return AuthBad; |
46 | |
47 | if (!*pw->pw_passwd) |
48 | return AuthOk; |
49 | |
50 | if (!(passwd = conv(ConvGetHidden, 0))) |
51 | return AuthAbort; |
52 | |
53 | if ((crpt_passwd = crypt(passwd, pw->pw_passwd)) && !strcmp(pw->pw_passwd, crpt_passwd)) { |
54 | dispose(passwd); |
55 | return AuthOk; /* Success */ |
56 | } |
57 | dispose(passwd); |
58 | return AuthBad; /* Password wrong or account locked */ |
59 | } |
60 | |
61 | #endif |
62 | |