2 Get the locations of systems in the Taylor UUCP configuration files.
4 Copyright (C) 1992 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_rdlocs_rcsid[] = "$FreeBSD$";
34 static int itsystem P((pointer pglobal, int argc, char **argv,
35 pointer pvar, pointer pinfo));
36 static int itcalled_login P((pointer pglobal, int argc, char **argv,
37 pointer pvar, pointer pinfo));
38 static int itmyname P((pointer pglobal, int argc, char **argv,
39 pointer pvar, pointer pinfo));
41 /* This code scans through the Taylor UUCP system files in order to
42 locate each system and to gather the login restrictions (since this
43 information is held in additional arguments to the "called-login"
44 command, it can appear anywhere in the systems files). It also
45 records whether any "myname" appears, as an optimization for
46 uuconf_taylor_localname.
48 This table is used to dispatch the appropriate commands. Most
49 commands are simply ignored. Note that this is a uuconf_cmdtab,
50 not a cmdtab_offset. */
52 static const struct uuconf_cmdtab asTcmds[] =
54 { "system", UUCONF_CMDTABTYPE_FN | 2, NULL, itsystem },
55 { "alias", UUCONF_CMDTABTYPE_FN | 2, (pointer) asTcmds, itsystem },
56 { "called-login", UUCONF_CMDTABTYPE_FN | 0, NULL, itcalled_login },
57 { "myname", UUCONF_CMDTABTYPE_FN | 2, NULL, itmyname },
58 { NULL, 0, NULL, NULL }
61 /* This structure is used to pass information into the command table
66 /* The sys file name. */
68 /* The open sys file. */
70 /* The list of locations we are building. */
71 struct stsysloc *qlocs;
72 /* The list of validation restrictions we are building. */
73 struct svalidate *qvals;
76 /* Look through the sys files to find the location and names of all
77 the systems. Since we're scanning the sys files, we also record
78 the validation information specified by the additional arguments to
79 the called-login command. We don't use uuconf_cmd_file to avoid
80 the overhead of breaking the line up into arguments if not
84 _uuconf_iread_locations (qglobal)
85 struct sglobal *qglobal;
93 if (qglobal->qprocess->fread_syslocs)
94 return UUCONF_SUCCESS;
102 iret = UUCONF_SUCCESS;
104 for (pz = qglobal->qprocess->pzsysfiles; *pz != NULL; pz++)
109 qglobal->ilineno = 0;
111 e = fopen (*pz, "r");
114 if (FNO_SUCH_FILE ())
116 qglobal->ierrno = errno;
117 iret = UUCONF_FOPEN_FAILED | UUCONF_ERROR_ERRNO;
128 while ((cchars = _uuconf_getline (qglobal, &zline, &cline, e)) > 0)
134 zcmd = zline + strspn (zline, " \t");
135 if (strncasecmp (zcmd, "system", sizeof "system" - 1) == 0
136 || strncasecmp (zcmd, "alias", sizeof "alias" - 1) == 0
137 || strncasecmp (zcmd, "called-login",
138 sizeof "called-login" - 1) == 0
139 || strncasecmp (zcmd, "myname", sizeof "myname" - 1) == 0)
141 iret = uuconf_cmd_line ((pointer) qglobal, zline, asTcmds,
142 (pointer) &si, (uuconf_cmdtabfn) NULL,
144 if ((iret & UUCONF_CMDTABRET_KEEP) != 0)
146 iret &=~ UUCONF_CMDTABRET_KEEP;
150 if (iret != UUCONF_SUCCESS)
152 iret &=~ UUCONF_CMDTABRET_EXIT;
158 if (iret != UUCONF_SUCCESS)
163 free ((pointer) zline);
165 if (iret != UUCONF_SUCCESS)
167 qglobal->zfilename = *pz;
168 iret |= UUCONF_ERROR_FILENAME | UUCONF_ERROR_LINENO;
169 if (UUCONF_ERROR_VALUE (iret) != UUCONF_MALLOC_FAILED)
170 qglobal->qprocess->fread_syslocs = TRUE;
174 qglobal->qprocess->qsyslocs = si.qlocs;
175 qglobal->qprocess->qvalidate = si.qvals;
176 qglobal->qprocess->fread_syslocs = TRUE;
182 /* Handle a "system" or "alias" command by recording the file and
183 location. If pvar is not NULL, this is an "alias" command. */
187 itsystem (pglobal, argc, argv, pvar, pinfo)
194 struct sglobal *qglobal = (struct sglobal *) pglobal;
195 struct sinfo *qinfo = (struct sinfo *) pinfo;
199 q = (struct stsysloc *) uuconf_malloc (qglobal->pblock,
200 sizeof (struct stsysloc));
203 qglobal->ierrno = errno;
204 return (UUCONF_MALLOC_FAILED
206 | UUCONF_CMDTABRET_EXIT);
209 csize = strlen (argv[1]) + 1;
210 q->zname = uuconf_malloc (qglobal->pblock, csize);
211 if (q->zname == NULL)
213 qglobal->ierrno = errno;
214 return (UUCONF_MALLOC_FAILED
216 | UUCONF_CMDTABRET_EXIT);
219 q->qnext = qinfo->qlocs;
220 memcpy ((pointer) q->zname, (pointer) argv[1], csize);
221 q->falias = pvar != NULL;
222 q->zfile = qinfo->zname;
224 q->iloc = ftell (qinfo->e);
225 q->ilineno = qglobal->ilineno;
229 return UUCONF_CMDTABRET_CONTINUE;
232 /* Handle the "called-login" command. This just records any extra
233 arguments, so that uuconf_validate can check them later if
238 itcalled_login (pglobal, argc, argv, pvar, pinfo)
245 struct sglobal *qglobal = (struct sglobal *) pglobal;
246 struct sinfo *qinfo = (struct sinfo *) pinfo;
247 register struct svalidate *qval;
251 return UUCONF_CMDTABRET_CONTINUE;
253 for (qval = qinfo->qvals; qval != NULL; qval = qval->qnext)
254 if (strcmp (argv[1], qval->zlogname) == 0)
259 qval = (struct svalidate *) uuconf_malloc (qglobal->pblock,
260 sizeof (struct svalidate));
263 qglobal->ierrno = errno;
264 return (UUCONF_MALLOC_FAILED
266 | UUCONF_CMDTABRET_EXIT);
269 qval->qnext = qinfo->qvals;
270 qval->zlogname = argv[1];
271 qval->pzmachines = NULL;
276 for (i = 2; i < argc; i++)
280 iret = _uuconf_iadd_string (qglobal, argv[i], FALSE, TRUE,
281 &qval->pzmachines, qglobal->pblock);
282 if (iret != UUCONF_SUCCESS)
283 return iret | UUCONF_CMDTABRET_EXIT;
286 return UUCONF_CMDTABRET_KEEP;
289 /* Handle the "myname" command by simply recording that it appears.
290 This information is used by uuconf_taylor_localname. */
294 itmyname (pglobal, argc, argv, pvar, pinfo)
301 struct sglobal *qglobal = (struct sglobal *) pglobal;
303 qglobal->qprocess->fuses_myname = TRUE;
304 return UUCONF_CMDTABRET_CONTINUE;