3 * Copyright (C) 1999 Mark Davies <mark@MCS.VUW.AC.NZ>
4 * Copyright (C) 2003 Oswald Buddenhagen <ossi@kde.org>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public
17 * License along with this program; if not, write to the Free
18 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 #include "kcheckpass.h"
24 #ifdef HAVE_OSF_C2_PASSWD
26 static char *osf1c2crypt(const char *pw
, char *salt
);
27 static int osf1c2_getprpwent(char *p
, char *n
, int len
);
29 /*******************************************************************
30 * This is the authentication code for OSF C2 security passwords
31 *******************************************************************/
37 AuthReturn
Authenticate(const char *method
,
38 const char *login
, char *(*conv
) (ConvRequest
, const char *))
43 if (strcmp(method
, "classic"))
46 if (!osf1c2_getprpwent(c2passwd
, login
, sizeof(c2passwd
)))
52 if (!(passwd
= conv(ConvGetHidden
, 0)))
55 if (!strcmp(c2passwd
, osf1c2crypt(passwd
, c2passwd
))) {
57 return AuthOk
; /* Success */
60 return AuthBad
; /* Password wrong or account locked */
65 The following code was lifted from the file osfc2.c from the ssh 1.2.26
66 distribution. Parts of the code that were not needed by kcheckpass
67 (notably the osf1c2_check_account_and_terminal() function and the code
68 to set the external variable days_before_password_expires have been
69 removed). The original copyright from the osfc2.c file is included
77 Author: Christophe Wolfhugel
79 Copyright (c) 1995 Christophe Wolfhugel
81 Free use of this file is permitted for any purpose as long as
82 this copyright is preserved in the header.
84 This program implements the use of the OSF/1 C2 security extensions
85 within ssh. See the file COPYING for full licensing information.
89 #include <sys/security.h>
93 static int c2security
= -1;
94 static int crypt_algo
;
97 initialize_osf_security(int ac
, char **av
)
101 char siad
[] = "siad_ses_init=";
103 if (access(SIAIGOODFILE
, F_OK
) == -1)
105 /* Broken OSF/1 system, better don't run on it. */
106 fprintf(stderr
, SIAIGOODFILE
);
107 fprintf(stderr
, " does not exist. Your OSF/1 system is probably broken\n");
110 if ((f
= fopen(MATRIX_CONF
, "r")) == NULL
)
112 /* Another way OSF/1 is probably broken. */
113 fprintf(stderr
, "%s unreadable. Your OSF/1 system is probably broken.\n"
119 /* Read matrix.conf to check if we run C2 or not */
120 while (fgets(buf
, sizeof(buf
), f
) != NULL
)
122 if (strncmp(buf
, siad
, sizeof(siad
) - 1) == 0)
124 if (strstr(buf
, "OSFC2") != NULL
)
126 else if (strstr(buf
, "BSD") != NULL
)
132 if (c2security
== -1)
134 fprintf(stderr
, "C2 security initialization failed : could not determine security level.\n");
138 set_auth_parameters(ac
, av
);
143 osf1c2_getprpwent(char *p
, char *n
, int len
)
149 struct es_passwd
*es
;
150 struct pr_passwd
*pr
= getprpwnam(n
);
153 strlcpy(p
, pr
->ufld
.fd_encrypt
, len
);
154 crypt_algo
= pr
->ufld
.fd_oldcrypt
;
157 if (pr
->uflg
.fg_schange
== 1)
158 pschg
= pr
->ufld
.fd_schange
;
161 if (pr
->uflg
.fg_template
== 0)
163 /** default template, system values **/
164 if (pr
->sflg
.fg_lifetime
== 1)
165 if (pr
->sfld
.fd_lifetime
> 0 &&
166 pschg
+ pr
->sfld
.fd_lifetime
< tnow
)
169 else /** user template, specific values **/
171 es
= getespwnam(pr
->ufld
.fd_template
);
174 if (es
->uflg
->fg_expire
== 1)
175 if (es
->ufld
->fd_expire
> 0 &&
176 pschg
+ es
->ufld
->fd_expire
< tnow
)
184 struct passwd
*pw
= getpwnam(n
);
187 strlcpy(p
, pw
->pw_passwd
, len
);
195 osf1c2crypt(const char *pw
, char *salt
)
197 if (c2security
== 1) {
198 return(dispcrypt(pw
, salt
, crypt_algo
));
200 return(crypt(pw
, salt
));