2 Check a login name and password against the UUCP password file.
4 Copyright (C) 1992, 1993, 1995 Ian Lance Taylor
6 This file is part of the Taylor UUCP uuconf library.
8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Library General Public License
10 as published by the Free Software Foundation; either version 2 of
11 the License, or (at your option) any later version.
13 This library is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Library General Public License for more details.
18 You should have received a copy of the GNU Library General Public
19 License along with this library; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 The author of the program may be contacted at ian@airs.com or
23 c/o Cygnus Support, 48 Grove Street, Somerville, MA 02144.
29 const char _uuconf_callin_rcsid[] = "$FreeBSD$";
34 static int ipcheck P((pointer pglobal, int argc, char **argv,
35 pointer pvar, pointer pinfo));
39 int (*pcmpfn) P((int, pointer, const char *));
45 /* Check a login name and password against the UUCP password file.
46 This looks at the Taylor UUCP password file, but will work even if
47 uuconf_taylor_init was not called. It accepts either spaces or
48 colons as field delimiters. */
51 uuconf_callin (pglobal, pcmpfn, pinfo)
53 int (*pcmpfn) P((int, pointer, const char *));
56 struct sglobal *qglobal = (struct sglobal *) pglobal;
59 struct uuconf_cmdtab as[1];
64 /* If we have no password file names, fill in the default name. */
65 if (qglobal->qprocess->pzpwdfiles == NULL)
67 char ab[sizeof NEWCONFIGLIB + sizeof PASSWDFILE - 1];
69 memcpy ((pointer) ab, (pointer) NEWCONFIGLIB,
70 sizeof NEWCONFIGLIB - 1);
71 memcpy ((pointer) (ab + sizeof NEWCONFIGLIB - 1), (pointer) PASSWDFILE,
73 iret = _uuconf_iadd_string (qglobal, ab, TRUE, FALSE,
74 &qglobal->qprocess->pzpwdfiles,
76 if (iret != UUCONF_SUCCESS)
80 as[0].uuconf_zcmd = NULL;
90 iret = UUCONF_SUCCESS;
92 for (pz = qglobal->qprocess->pzpwdfiles; *pz != NULL; pz++)
101 qglobal->ierrno = errno;
102 iret = UUCONF_FOPEN_FAILED | UUCONF_ERROR_ERRNO;
106 qglobal->ilineno = 0;
108 iret = UUCONF_SUCCESS;
110 while (getline (&zline, &cline, e) > 0)
116 /* We have a few hacks to make Unix style passwd files work.
117 1) We turn the first two colon characters into spaces.
118 2) If the colon characters are adjacent, we assume there
119 is no password, and we skip the entry.
120 3) If the password between colon characters contains a
121 space, we assume that it has been disabled, and we
123 z0 = strchr (zline, ':');
127 z1 = strchr (z0, ':');
133 if (strchr (z0 + 1, ' ') != NULL)
137 iret = uuconf_cmd_line (pglobal, zline, as, (pointer) &s,
138 ipcheck, 0, (pointer) NULL);
139 if ((iret & UUCONF_CMDTABRET_EXIT) != 0)
141 iret &=~ UUCONF_CMDTABRET_EXIT;
142 if (iret != UUCONF_SUCCESS)
143 iret |= UUCONF_ERROR_LINENO;
147 iret = UUCONF_SUCCESS;
152 if (iret != UUCONF_SUCCESS || s.ffound)
157 free ((pointer) zline);
159 if (iret != UUCONF_SUCCESS)
161 qglobal->zfilename = *pz;
162 iret |= UUCONF_ERROR_FILENAME;
164 else if (! s.ffound || ! s.fmatched)
165 iret = UUCONF_NOT_FOUND;
170 /* This is called on each line of the file. It checks to see if the
171 login name from the file is the one we are looking for. If it is,
172 it sets ffound, and then sets fmatched according to whether the
173 password matches or not. */
176 ipcheck (pglobal, argc, argv, pvar, pinfo)
183 struct sinfo *q = (struct sinfo *) pinfo;
186 return UUCONF_SYNTAX_ERROR | UUCONF_CMDTABRET_EXIT;
188 if (! (*q->pcmpfn) (0, q->pinfo, argv[0]))
189 return UUCONF_CMDTABRET_CONTINUE;
192 q->fmatched = (*q->pcmpfn) (1, q->pinfo, argv[1]) != 0;
194 return UUCONF_CMDTABRET_EXIT;