2 * Copyright (c) 1997-2000 The Stanford SRP Authentication Project
5 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
18 * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
20 * IN NO EVENT SHALL STANFORD BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
21 * INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES WHATSOEVER
22 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT ADVISED OF
23 * THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY, ARISING OUT
24 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
26 * In addition, the following conditions apply:
28 * 1. Any software that incorporates the SRP authentication technology
29 * must display the following acknowlegment:
30 * "This product uses the 'Secure Remote Password' cryptographic
31 * authentication system developed by Tom Wu (tjw@CS.Stanford.EDU)."
33 * 2. Any software that incorporates all or part of the SRP distribution
34 * itself must also display the following acknowledgment:
35 * "This product includes software developed by Tom Wu and Eugene
36 * Jhong for the SRP Distribution (http://srp.stanford.edu/srp/)."
38 * 3. Redistributions in source or binary form must retain an intact copy
39 * of this copyright notice and list of conditions.
42 #include "t_defines.h"
46 #endif /* HAVE_UNISTD_H */
49 #include <sys/types.h>
63 static struct t_pw * syspw = NULL;
64 static struct t_passwd tpass;
66 _TYPE( struct t_server * )
67 t_serveropen(username)
68 const char * username;
71 p = gettpnam(username);
75 return t_serveropenraw(&p->tp, &p->tc);
80 /* t_openpw(NULL) is deprecated - use settpent()/gettpnam() instead */
82 _TYPE( struct t_pw * )
89 if(fp == NULL) { /* Deprecated */
90 if((fp = fopen(DEFAULT_PASSWD, "r")) == NULL)
97 if((tpw = malloc(sizeof(struct t_pw))) == NULL)
100 tpw->close_on_exit = close_flag;
101 tpw->state = FILE_ONLY;
106 _TYPE( struct t_pw * )
107 t_openpwbyname(pwname)
113 if(pwname == NULL) /* Deprecated */
114 return t_openpw(NULL);
116 if((fp = fopen(pwname, "r")) == NULL)
120 t->close_on_exit = 1;
128 if(tpw->close_on_exit)
129 fclose(tpw->instream);
138 if(tpw->state == IN_NIS)
139 tpw->state = FILE_NIS;
141 rewind(tpw->instream);
146 savepwent(tpw, pwent)
148 struct t_pwent *pwent;
150 tpw->pebuf.name = tpw->userbuf;
151 tpw->pebuf.password.data = tpw->pwbuf;
152 tpw->pebuf.salt.data = tpw->saltbuf;
153 strcpy(tpw->pebuf.name, pwent->name);
154 tpw->pebuf.password.len = pwent->password.len;
155 memcpy(tpw->pebuf.password.data, pwent->password.data, pwent->password.len);
156 tpw->pebuf.salt.len = pwent->salt.len;
157 memcpy(tpw->pebuf.salt.data, pwent->salt.data, pwent->salt.len);
158 tpw->pebuf.index = pwent->index;
160 #endif /* ENABLE_YP */
162 _TYPE( struct t_pwent * )
163 t_getpwbyname(tpw, user)
168 char passbuf[MAXB64PARAMLEN];
169 char saltstr[MAXB64SALTLEN];
170 char username[MAXUSERLEN];
172 struct t_passwd * nisent;
177 while(t_nextfield(tpw->instream, username, MAXUSERLEN) > 0) {
179 if(tpw->state == FILE_NIS && *username == '+') {
180 if(strlen(username) == 1 || strcmp(user, username+1) == 0) {
181 nisent = _yp_gettpnam(user); /* Entry is +username or + */
183 savepwent(tpw, &nisent->tp);
189 if(strcmp(user, username) == 0)
190 if(t_nextfield(tpw->instream, passbuf, MAXB64PARAMLEN) > 0 &&
191 (tpw->pebuf.password.len = t_fromb64(tpw->pwbuf, passbuf)) > 0 &&
192 t_nextfield(tpw->instream, saltstr, MAXB64SALTLEN) > 0 &&
193 (tpw->pebuf.salt.len = t_fromb64(tpw->saltbuf, saltstr)) > 0 &&
194 t_nextfield(tpw->instream, indexbuf, 16) > 0 &&
195 (tpw->pebuf.index = atoi(indexbuf)) > 0) {
196 strcpy(tpw->userbuf, username);
197 tpw->pebuf.name = tpw->userbuf;
198 tpw->pebuf.password.data = tpw->pwbuf;
199 tpw->pebuf.salt.data = tpw->saltbuf;
200 t_nextline(tpw->instream);
203 if(t_nextline(tpw->instream) < 0)
209 /* System password file accessors */
215 if((syspw = t_openpwbyname(DEFAULT_PASSWD)) == NULL)
217 syspw->state = FILE_NIS;
223 pwsetup(out, tpwd, tcnf)
224 struct t_passwd * out;
225 struct t_pwent * tpwd;
226 struct t_confent * tcnf;
228 out->tp.name = tpwd->name;
229 out->tp.password.len = tpwd->password.len;
230 out->tp.password.data = tpwd->password.data;
231 out->tp.salt.len = tpwd->salt.len;
232 out->tp.salt.data = tpwd->salt.data;
233 out->tp.index = tpwd->index;
235 out->tc.index = tcnf->index;
236 out->tc.modulus.len = tcnf->modulus.len;
237 out->tc.modulus.data = tcnf->modulus.data;
238 out->tc.generator.len = tcnf->generator.len;
239 out->tc.generator.data = tcnf->generator.data;
242 _TYPE( struct t_passwd * )
247 struct t_pwent * tpptr;
248 struct t_confent * tcptr;
252 tpptr = t_getpwbyname(syspw, user);
260 pwsetup(&tpass, tpptr, tcptr);