|
|
1.1 root 1: /* xqtfil.c
2: Routines to read execute files.
3:
4: Copyright (C) 1991, 1992 Ian Lance Taylor
5:
6: This file is part of the Taylor UUCP package.
7:
8: This program is free software; you can redistribute it and/or
9: modify it under the terms of the GNU General Public License as
10: published by the Free Software Foundation; either version 2 of the
11: License, or (at your option) any later version.
12:
13: This program 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: General Public License for more details.
17:
18: You should have received a copy of the GNU General Public License
19: along with this program; 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 "uucp.h"
27:
28: #if USE_RCS_ID
29: const char xqtfil_rcsid[] = "$Id: xqtfil.c,v 1.1 93/07/30 08:03:40 bin Exp Locker: bin $";
30: #endif
31:
32: #include "uudefs.h"
33: #include "sysdep.h"
34: #include "system.h"
35:
36: #include <errno.h>
37:
38: #if HAVE_OPENDIR
39: #if HAVE_DIRENT_H
40: #include <dirent.h>
41: #else /* ! HAVE_DIRENT_H */
42: #include <sys/dir.h>
43: #define dirent direct
44: #endif /* ! HAVE_DIRENT_H */
45: #endif /* HAVE_OPENDIR */
46:
47: /* Under the V2 or BSD42 spool directory scheme, all execute files are
48: in the main spool directory. Under the BSD43 scheme, they are all
49: in the directory X.. Under the HDB or SVR4 scheme, they are in
50: directories named after systems. Under the ULTRIX scheme, they are
51: in X. subdirectories of subdirectories of sys. Under the TAYLOR
52: scheme, they are all in the subdirectory X. of a directory named
53: after the system.
54:
55: This means that for HDB, ULTRIX, SVR4 or TAYLOR, we have to search
56: directories of directories. */
57:
58: #if SPOOLDIR_V2 || SPOOLDIR_BSD42
59: #define ZDIR "."
60: #define SUBDIRS 0
61: #endif
62: #if SPOOLDIR_HDB || SPOOLDIR_SVR4 || SPOOLDIR_TAYLOR
63: #define ZDIR "."
64: #define SUBDIRS 1
65: #endif
66: #if SPOOLDIR_ULTRIX
67: #define ZDIR "sys"
68: #define SUBDIRS 1
69: #endif
70: #if SPOOLDIR_BSD43
71: #define ZDIR "X."
72: #define SUBDIRS 0
73: #endif
74:
75: /* Static variables for the execute file scan. */
76:
77: static DIR *qSxqt_topdir;
78: #if ! SUBDIRS
79: static const char *zSdir;
80: #else /* SUBDIRS */
81: static char *zSdir;
82: static DIR *qSxqt_dir;
83: static char *zSsystem;
84: #endif /* SUBDIRS */
85:
86: /* Initialize the scan for execute files. The function
87: usysdep_get_xqt_free will clear the data out when we are done with
88: the system. This returns FALSE on error. */
89:
90: /*ARGSUSED*/
91: boolean
92: fsysdep_get_xqt_init ()
93: {
94: usysdep_get_xqt_free ();
95:
96: qSxqt_topdir = opendir ((char *) ZDIR);
97: if (qSxqt_topdir == NULL)
98: {
99: if (errno == ENOENT)
100: return TRUE;
101: ulog (LOG_ERROR, "opendir (%s): %s", ZDIR, strerror (errno));
102: return FALSE;
103: }
104:
105: return TRUE;
106: }
107:
108: /* Return the name of the next execute file to read and process. If
109: this returns NULL, *pferr must be checked. If will be TRUE on
110: error, FALSE if there are no more files. On a successful return
111: *pzsystem will be set to the system for which the execute file was
112: created. */
113:
114: char *
115: zsysdep_get_xqt (pzsystem, pferr)
116: char **pzsystem;
117: boolean *pferr;
118: {
119: *pferr = FALSE;
120:
121: if (qSxqt_topdir == NULL)
122: return NULL;
123:
124: /* This loop continues until we find a file. */
125: while (TRUE)
126: {
127: DIR *qdir;
128: struct dirent *q;
129:
130: #if ! SUBDIRS
131: zSdir = ZDIR;
132: qdir = qSxqt_topdir;
133: #else /* SUBDIRS */
134: /* This loop continues until we find a subdirectory to read. */
135: while (qSxqt_dir == NULL)
136: {
137: struct dirent *qtop;
138:
139: qtop = readdir (qSxqt_topdir);
140: if (qtop == NULL)
141: {
142: (void) closedir (qSxqt_topdir);
143: qSxqt_topdir = NULL;
144: return NULL;
145: }
146:
147: /* No system name may start with a dot (this is enforced by
148: tisystem in sysinf.c). This allows us to quickly skip
149: impossible directories. */
150: if (qtop->d_name[0] == '.')
151: continue;
152:
153: DEBUG_MESSAGE1 (DEBUG_SPOOLDIR,
154: "zsysdep_get_xqt: Found %s in top directory",
155: qtop->d_name);
156:
157: ubuffree (zSdir);
158:
159: #if SPOOLDIR_HDB || SPOOLDIR_SVR4
160: zSdir = zbufcpy (qtop->d_name);
161: #endif
162: #if SPOOLDIR_ULTRIX
163: zSdir = zsappend3 ("sys", qtop->d_name, "X.");
164: #endif
165: #if SPOOLDIR_TAYLOR
166: zSdir = zsysdep_in_dir (qtop->d_name, "X.");
167: #endif
168:
169: ubuffree (zSsystem);
170: zSsystem = zbufcpy (qtop->d_name);
171:
172: qSxqt_dir = opendir (zSdir);
173:
174: if (qSxqt_dir == NULL
175: && errno != ENOTDIR
176: && errno != ENOENT)
177: ulog (LOG_ERROR, "opendir (%s): %s", zSdir, strerror (errno));
178: }
179:
180: qdir = qSxqt_dir;
181: #endif /* SUBDIRS */
182:
183: q = readdir (qdir);
184:
185: #if DEBUG > 1
186: if (q != NULL)
187: DEBUG_MESSAGE2 (DEBUG_SPOOLDIR,
188: "zsysdep_get_xqt: Found %s in subdirectory %s",
189: q->d_name, zSdir);
190: #endif
191:
192: /* If we've found an execute file, return it. We have to get
193: the system name, which is easy for HDB or TAYLOR. For other
194: spool directory schemes, we have to pull it out of the X.
195: file name; this would be insecure, except that zsfind_file
196: clobbers the file name to include the real system name. */
197: if (q != NULL
198: && q->d_name[0] == 'X'
199: && q->d_name[1] == '.')
200: {
201: char *zret;
202:
203: #if SPOOLDIR_HDB || SPOOLDIR_SVR4 || SPOOLDIR_TAYLOR
204: *pzsystem = zbufcpy (zSsystem);
205: #else
206: {
207: size_t clen;
208:
209: clen = strlen (q->d_name) - 7;
210: *pzsystem = zbufalc (clen + 1);
211: memcpy (*pzsystem, q->d_name + 2, clen);
212: (*pzsystem)[clen] = '\0';
213: }
214: #endif
215:
216: zret = zsysdep_in_dir (zSdir, q->d_name);
217: #if DEBUG > 1
218: DEBUG_MESSAGE2 (DEBUG_SPOOLDIR,
219: "zsysdep_get_xqt: Returning %s (system %s)",
220: zret, *pzsystem);
221: #endif
222: return zret;
223: }
224:
225: /* If we've reached the end of the directory, then if we are
226: using subdirectories loop around to read the next one,
227: otherwise we are finished. */
228: if (q == NULL)
229: {
230: (void) closedir (qdir);
231: #if SUBDIRS
232: qSxqt_dir = NULL;
233: continue;
234: #else
235: qSxqt_topdir = NULL;
236: return NULL;
237: #endif
238: }
239: }
240: }
241:
242: /* Free up the results of an execute file scan, when we're done with
243: this system. */
244:
245: /*ARGSUSED*/
246: void
247: usysdep_get_xqt_free ()
248: {
249: if (qSxqt_topdir != NULL)
250: {
251: (void) closedir (qSxqt_topdir);
252: qSxqt_topdir = NULL;
253: }
254: #if SUBDIRS
255: if (qSxqt_dir != NULL)
256: {
257: (void) closedir (qSxqt_dir);
258: qSxqt_dir = NULL;
259: }
260: ubuffree (zSdir);
261: zSdir = NULL;
262: ubuffree (zSsystem);
263: zSsystem = NULL;
264: #endif
265: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.