Add (and install) svg for the new krunner interface.
[kdebase/uwolfer.git] / workspace / kcheckpass / checkpass_osfc2passwd.c
blob9a074f987fe5dc28974d4e2e8926704bef63fd86
1 /*
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 *******************************************************************/
33 #include <stdio.h>
34 #include <string.h>
35 #include <stdlib.h>
37 AuthReturn Authenticate(const char *method,
38 const char *login, char *(*conv) (ConvRequest, const char *))
40 char *passwd;
41 char c2passwd[256];
43 if (strcmp(method, "classic"))
44 return AuthError;
46 if (!osf1c2_getprpwent(c2passwd, login, sizeof(c2passwd)))
47 return AuthBad;
49 if (!*c2passwd)
50 return AuthOk;
52 if (!(passwd = conv(ConvGetHidden, 0)))
53 return AuthAbort;
55 if (!strcmp(c2passwd, osf1c2crypt(passwd, c2passwd))) {
56 dispose(passwd);
57 return AuthOk; /* Success */
59 dispose(passwd);
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
70 below.
75 osfc2.c
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>
90 #include <prot.h>
91 #include <sia.h>
93 static int c2security = -1;
94 static int crypt_algo;
96 static void
97 initialize_osf_security(int ac, char **av)
99 FILE *f;
100 char buf[256];
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");
108 exit(1);
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"
115 MATRIX_CONF);
116 exit(1);
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)
125 c2security = 1;
126 else if (strstr(buf, "BSD") != NULL)
127 c2security = 0;
128 break;
131 fclose(f);
132 if (c2security == -1)
134 fprintf(stderr, "C2 security initialization failed : could not determine security level.\n");
135 exit(1);
137 if (c2security == 1)
138 set_auth_parameters(ac, av);
142 static int
143 osf1c2_getprpwent(char *p, char *n, int len)
145 time_t pschg, tnow;
147 if (c2security == 1)
149 struct es_passwd *es;
150 struct pr_passwd *pr = getprpwnam(n);
151 if (pr)
153 strlcpy(p, pr->ufld.fd_encrypt, len);
154 crypt_algo = pr->ufld.fd_oldcrypt;
156 tnow = time(NULL);
157 if (pr->uflg.fg_schange == 1)
158 pschg = pr->ufld.fd_schange;
159 else
160 pschg = 0;
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)
167 return 1;
169 else /** user template, specific values **/
171 es = getespwnam(pr->ufld.fd_template);
172 if (es)
174 if (es->uflg->fg_expire == 1)
175 if (es->ufld->fd_expire > 0 &&
176 pschg + es->ufld->fd_expire < tnow)
177 return 1;
182 else
184 struct passwd *pw = getpwnam(n);
185 if (pw)
187 strlcpy(p, pw->pw_passwd, len);
188 return 1;
191 return 0;
194 static char *
195 osf1c2crypt(const char *pw, char *salt)
197 if (c2security == 1) {
198 return(dispcrypt(pw, salt, crypt_algo));
199 } else
200 return(crypt(pw, salt));
203 #endif