|
|
1.1 root 1: /* rdlocs.c
2: Get the locations of systems in the Taylor UUCP configuration files.
3:
4: Copyright (C) 1992 Ian Lance Taylor
5:
6: This file is part of the Taylor UUCP uuconf library.
7:
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.
12:
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.
17:
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., 675 Mass Ave, Cambridge, MA 02139, USA.
21:
22: The author of the program may be contacted at [email protected] or
23: c/o Infinity Development Systems, P.O. Box 520, Waltham, MA 02254.
24: */
25:
26: #include "uucnfi.h"
27:
28: #if USE_RCS_ID
29: const char _uuconf_rdlocs_rcsid[] = "$Id: rdlocs.c,v 1.1 93/07/30 08:07:28 bin Exp Locker: bin $";
30: #endif
31:
32: #include <errno.h>
33:
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));
40:
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.
47:
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. */
51:
52: static const struct uuconf_cmdtab asTcmds[] =
53: {
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 }
59: };
60:
61: /* This structure is used to pass information into the command table
62: functions. */
63:
64: struct sinfo
65: {
66: /* The sys file name. */
67: const char *zname;
68: /* The open sys file. */
69: FILE *e;
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;
74: };
75:
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
81: necessary. */
82:
83: int
84: _uuconf_iread_locations (qglobal)
85: struct sglobal *qglobal;
86: {
87: char *zline;
88: size_t cline;
89: struct sinfo si;
90: int iret;
91: char **pz;
92:
93: if (qglobal->qprocess->fread_syslocs)
94: return UUCONF_SUCCESS;
95:
96: zline = NULL;
97: cline = 0;
98:
99: si.qlocs = NULL;
100: si.qvals = NULL;
101:
102: iret = UUCONF_SUCCESS;
103:
104: for (pz = qglobal->qprocess->pzsysfiles; *pz != NULL; pz++)
105: {
106: FILE *e;
107: int cchars;
108:
109: qglobal->ilineno = 0;
110:
111: e = fopen (*pz, "r");
112: if (e == NULL)
113: {
114: if (FNO_SUCH_FILE ())
115: continue;
116: qglobal->ierrno = errno;
117: iret = UUCONF_FOPEN_FAILED | UUCONF_ERROR_ERRNO;
118: break;
119: }
120:
121: #ifdef CLOSE_ON_EXEC
122: CLOSE_ON_EXEC (e);
123: #endif
124:
125: si.zname = *pz;
126: si.e = e;
127:
128: while ((cchars = _uuconf_getline (qglobal, &zline, &cline, e)) > 0)
129: {
130: char *zcmd;
131:
132: ++qglobal->ilineno;
133:
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)
140: {
141: iret = uuconf_cmd_line ((pointer) qglobal, zline, asTcmds,
142: (pointer) &si, (uuconf_cmdtabfn) NULL,
143: 0, qglobal->pblock);
144: if ((iret & UUCONF_CMDTABRET_KEEP) != 0)
145: {
146: iret &=~ UUCONF_CMDTABRET_KEEP;
147: zline = NULL;
148: cline = 0;
149: }
150: if (iret != UUCONF_SUCCESS)
151: {
152: iret &=~ UUCONF_CMDTABRET_EXIT;
153: break;
154: }
155: }
156: }
157:
158: if (iret != UUCONF_SUCCESS)
159: break;
160: }
161:
162: if (zline != NULL)
163: free ((pointer) zline);
164:
165: if (iret != UUCONF_SUCCESS)
166: {
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;
171: }
172: else
173: {
174: qglobal->qprocess->qsyslocs = si.qlocs;
175: qglobal->qprocess->qvalidate = si.qvals;
176: qglobal->qprocess->fread_syslocs = TRUE;
177: }
178:
179: return iret;
180: }
181:
182: /* Handle a "system" or "alias" command by recording the file and
183: location. If pvar is not NULL, this is an "alias" command. */
184:
185: /*ARGSUSED*/
186: static int
187: itsystem (pglobal, argc, argv, pvar, pinfo)
188: pointer pglobal;
189: int argc;
190: char **argv;
191: pointer pvar;
192: pointer pinfo;
193: {
194: struct sglobal *qglobal = (struct sglobal *) pglobal;
195: struct sinfo *qinfo = (struct sinfo *) pinfo;
196: struct stsysloc *q;
197: size_t csize;
198:
199: q = (struct stsysloc *) uuconf_malloc (qglobal->pblock,
200: sizeof (struct stsysloc));
201: if (q == NULL)
202: {
203: qglobal->ierrno = errno;
204: return (UUCONF_MALLOC_FAILED
205: | UUCONF_ERROR_ERRNO
206: | UUCONF_CMDTABRET_EXIT);
207: }
208:
209: csize = strlen (argv[1]) + 1;
210: q->zname = uuconf_malloc (qglobal->pblock, csize);
211: if (q->zname == NULL)
212: {
213: qglobal->ierrno = errno;
214: return (UUCONF_MALLOC_FAILED
215: | UUCONF_ERROR_ERRNO
216: | UUCONF_CMDTABRET_EXIT);
217: }
218:
219: q->qnext = qinfo->qlocs;
220: memcpy ((pointer) q->zname, (pointer) argv[1], csize);
221: q->falias = pvar != NULL;
222: q->zfile = qinfo->zname;
223: q->e = qinfo->e;
224: q->iloc = ftell (qinfo->e);
225: q->ilineno = qglobal->ilineno;
226:
227: qinfo->qlocs = q;
228:
229: return UUCONF_CMDTABRET_CONTINUE;
230: }
231:
232: /* Handle the "called-login" command. This just records any extra
233: arguments, so that uuconf_validate can check them later if
234: necessary. */
235:
236: /*ARGSUSED*/
237: static int
238: itcalled_login (pglobal, argc, argv, pvar, pinfo)
239: pointer pglobal;
240: int argc;
241: char **argv;
242: pointer pvar;
243: pointer pinfo;
244: {
245: struct sglobal *qglobal = (struct sglobal *) pglobal;
246: struct sinfo *qinfo = (struct sinfo *) pinfo;
247: register struct svalidate *qval;
248: int i;
249:
250: if (argc <= 2)
251: return UUCONF_CMDTABRET_CONTINUE;
252:
253: for (qval = qinfo->qvals; qval != NULL; qval = qval->qnext)
254: if (strcmp (argv[1], qval->zlogname) == 0)
255: break;
256:
257: if (qval == NULL)
258: {
259: qval = (struct svalidate *) uuconf_malloc (qglobal->pblock,
260: sizeof (struct svalidate));
261: if (qval == NULL)
262: {
263: qglobal->ierrno = errno;
264: return (UUCONF_MALLOC_FAILED
265: | UUCONF_ERROR_ERRNO
266: | UUCONF_CMDTABRET_EXIT);
267: }
268:
269: qval->qnext = qinfo->qvals;
270: qval->zlogname = argv[1];
271: qval->pzmachines = NULL;
272:
273: qinfo->qvals = qval;
274: }
275:
276: for (i = 2; i < argc; i++)
277: {
278: int iret;
279:
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;
284: }
285:
286: return UUCONF_CMDTABRET_KEEP;
287: }
288:
289: /* Handle the "myname" command by simply recording that it appears.
290: This information is used by uuconf_taylor_localname. */
291:
292: /*ARGSUSED*/
293: static int
294: itmyname (pglobal, argc, argv, pvar, pinfo)
295: pointer pglobal;
296: int argc;
297: char **argv;
298: pointer pvar;
299: pointer pinfo;
300: {
301: struct sglobal *qglobal = (struct sglobal *) pglobal;
302:
303: qglobal->qprocess->fuses_myname = TRUE;
304: return UUCONF_CMDTABRET_CONTINUE;
305: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.