summaryrefslogtreecommitdiffstats
path: root/gnu/libexec/uucp/libuuconf/rdlocs.c
blob: 3f5da73b58a64d9f0b762f6b69d2ffbf0fd55cc0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
/* rdlocs.c
   Get the locations of systems in the Taylor UUCP configuration files.

   Copyright (C) 1992 Ian Lance Taylor

   This file is part of the Taylor UUCP uuconf library.

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public License
   as published by the Free Software Foundation; either version 2 of
   the License, or (at your option) any later version.

   This library is distributed in the hope that it will be useful, but
   WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public
   License along with this library; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

   The author of the program may be contacted at ian@airs.com or
   c/o Cygnus Support, 48 Grove Street, Somerville, MA 02144.
   */

#include "uucnfi.h"

#if USE_RCS_ID
const char _uuconf_rdlocs_rcsid[] = "$Id: rdlocs.c,v 1.7 1995/06/21 19:23:52 ian Rel $";
#endif

#include <errno.h>

static int itsystem P((pointer pglobal, int argc, char **argv,
		       pointer pvar, pointer pinfo));
static int itcalled_login P((pointer pglobal, int argc, char **argv,
			     pointer pvar, pointer pinfo));
static int itmyname P((pointer pglobal, int argc, char **argv,
		       pointer pvar, pointer pinfo));

/* This code scans through the Taylor UUCP system files in order to
   locate each system and to gather the login restrictions (since this
   information is held in additional arguments to the "called-login"
   command, it can appear anywhere in the systems files).  It also
   records whether any "myname" appears, as an optimization for
   uuconf_taylor_localname.

   This table is used to dispatch the appropriate commands.  Most
   commands are simply ignored.  Note that this is a uuconf_cmdtab,
   not a cmdtab_offset.  */

static const struct uuconf_cmdtab asTcmds[] =
{
  { "system", UUCONF_CMDTABTYPE_FN | 2, NULL, itsystem },
  { "alias", UUCONF_CMDTABTYPE_FN | 2, (pointer) asTcmds, itsystem },
  { "called-login", UUCONF_CMDTABTYPE_FN | 0, NULL, itcalled_login },
  { "myname", UUCONF_CMDTABTYPE_FN | 2, NULL, itmyname },
  { NULL, 0, NULL, NULL }
};

/* This structure is used to pass information into the command table
   functions.  */

struct sinfo
{
  /* The sys file name.  */
  const char *zname;
  /* The open sys file.  */
  FILE *e;
  /* The list of locations we are building.  */
  struct stsysloc *qlocs;
  /* The list of validation restrictions we are building.  */
  struct svalidate *qvals;
};

/* Look through the sys files to find the location and names of all
   the systems.  Since we're scanning the sys files, we also record
   the validation information specified by the additional arguments to
   the called-login command.  We don't use uuconf_cmd_file to avoid
   the overhead of breaking the line up into arguments if not
   necessary.  */

int
_uuconf_iread_locations (qglobal)
     struct sglobal *qglobal;
{
  char *zline;
  size_t cline;
  struct sinfo si;
  int iret;
  char **pz;

  if (qglobal->qprocess->fread_syslocs)
    return UUCONF_SUCCESS;

  zline = NULL;
  cline = 0;

  si.qlocs = NULL;
  si.qvals = NULL;

  iret = UUCONF_SUCCESS;

  for (pz = qglobal->qprocess->pzsysfiles; *pz != NULL; pz++)
    {
      FILE *e;
      int cchars;

      qglobal->ilineno = 0;

      e = fopen (*pz, "r");
      if (e == NULL)
	{
	  if (FNO_SUCH_FILE ())
	    continue;
	  qglobal->ierrno = errno;
	  iret = UUCONF_FOPEN_FAILED | UUCONF_ERROR_ERRNO;
	  break;
	}

#ifdef CLOSE_ON_EXEC
      CLOSE_ON_EXEC (e);
#endif

      si.zname = *pz;
      si.e = e;

      while ((cchars = _uuconf_getline (qglobal, &zline, &cline, e)) > 0)
	{
	  char *zcmd;

	  ++qglobal->ilineno;

	  zcmd = zline + strspn (zline, " \t");
	  if (strncasecmp (zcmd, "system", sizeof "system" - 1) == 0
	      || strncasecmp (zcmd, "alias", sizeof "alias" - 1) == 0
	      || strncasecmp (zcmd, "called-login",
			      sizeof "called-login" - 1) == 0
	      || strncasecmp (zcmd, "myname", sizeof "myname" - 1) == 0)
	    {
	      iret = uuconf_cmd_line ((pointer) qglobal, zline, asTcmds,
				      (pointer) &si, (uuconf_cmdtabfn) NULL,
				      0, qglobal->pblock);
	      if ((iret & UUCONF_CMDTABRET_KEEP) != 0)
		{
		  iret &=~ UUCONF_CMDTABRET_KEEP;
		  zline = NULL;
		  cline = 0;
		}
	      if (iret != UUCONF_SUCCESS)
		{
		  iret &=~ UUCONF_CMDTABRET_EXIT;
		  break;
		}
	    }
	}

      if (iret != UUCONF_SUCCESS)
	break;
    }

  if (zline != NULL)
    free ((pointer) zline);

  if (iret != UUCONF_SUCCESS)
    {
      qglobal->zfilename = *pz;
      iret |= UUCONF_ERROR_FILENAME | UUCONF_ERROR_LINENO;
      if (UUCONF_ERROR_VALUE (iret) != UUCONF_MALLOC_FAILED)
	qglobal->qprocess->fread_syslocs = TRUE;
    }
  else
    {
      qglobal->qprocess->qsyslocs = si.qlocs;
      qglobal->qprocess->qvalidate = si.qvals;
      qglobal->qprocess->fread_syslocs = TRUE;
    }	

  return iret;
}

/* Handle a "system" or "alias" command by recording the file and
   location.  If pvar is not NULL, this is an "alias" command.  */

/*ARGSUSED*/
static int
itsystem (pglobal, argc, argv, pvar, pinfo)
     pointer pglobal;
     int argc;
     char **argv;
     pointer pvar;
     pointer pinfo;
{
  struct sglobal *qglobal = (struct sglobal *) pglobal;
  struct sinfo *qinfo = (struct sinfo *) pinfo;
  struct stsysloc *q;
  size_t csize;

  q = (struct stsysloc *) uuconf_malloc (qglobal->pblock,
					 sizeof (struct stsysloc));
  if (q == NULL)
    {
      qglobal->ierrno = errno;
      return (UUCONF_MALLOC_FAILED
	      | UUCONF_ERROR_ERRNO
	      | UUCONF_CMDTABRET_EXIT);
    }

  csize = strlen (argv[1]) + 1;
  q->zname = uuconf_malloc (qglobal->pblock, csize);
  if (q->zname == NULL)
    {
      qglobal->ierrno = errno;
      return (UUCONF_MALLOC_FAILED
	      | UUCONF_ERROR_ERRNO
	      | UUCONF_CMDTABRET_EXIT);
    }

  q->qnext = qinfo->qlocs;
  memcpy ((pointer) q->zname, (pointer) argv[1], csize);
  q->falias = pvar != NULL;
  q->zfile = qinfo->zname;
  q->e = qinfo->e;
  q->iloc = ftell (qinfo->e);
  q->ilineno = qglobal->ilineno;

  qinfo->qlocs = q;

  return UUCONF_CMDTABRET_CONTINUE;
}

/* Handle the "called-login" command.  This just records any extra
   arguments, so that uuconf_validate can check them later if
   necessary.  */

/*ARGSUSED*/
static int
itcalled_login (pglobal, argc, argv, pvar, pinfo)
     pointer pglobal;
     int argc;
     char **argv;
     pointer pvar;
     pointer pinfo;
{
  struct sglobal *qglobal = (struct sglobal *) pglobal;
  struct sinfo *qinfo = (struct sinfo *) pinfo;
  register struct svalidate *qval;
  int i;

  if (argc <= 2)
    return UUCONF_CMDTABRET_CONTINUE;

  for (qval = qinfo->qvals; qval != NULL; qval = qval->qnext)
    if (strcmp (argv[1], qval->zlogname) == 0)
      break;

  if (qval == NULL)
    {
      qval = (struct svalidate *) uuconf_malloc (qglobal->pblock,
						 sizeof (struct svalidate));
      if (qval == NULL)
	{
	  qglobal->ierrno = errno;
	  return (UUCONF_MALLOC_FAILED
		  | UUCONF_ERROR_ERRNO
		  | UUCONF_CMDTABRET_EXIT);
	}

      qval->qnext = qinfo->qvals;
      qval->zlogname = argv[1];
      qval->pzmachines = NULL;

      qinfo->qvals = qval;
    }

  for (i = 2; i < argc; i++)
    {
      int iret;

      iret = _uuconf_iadd_string (qglobal, argv[i], FALSE, TRUE,
				  &qval->pzmachines, qglobal->pblock);
      if (iret != UUCONF_SUCCESS)
	return iret | UUCONF_CMDTABRET_EXIT;
    }

  return UUCONF_CMDTABRET_KEEP;
}

/* Handle the "myname" command by simply recording that it appears.
   This information is used by uuconf_taylor_localname.  */

/*ARGSUSED*/
static int
itmyname (pglobal, argc, argv, pvar, pinfo)
     pointer pglobal;
     int argc;
     char **argv;
     pointer pvar;
     pointer pinfo;
{
  struct sglobal *qglobal = (struct sglobal *) pglobal;

  qglobal->qprocess->fuses_myname = TRUE;
  return UUCONF_CMDTABRET_CONTINUE;
}
OpenPOWER on IntegriCloud