-
Notifications
You must be signed in to change notification settings - Fork 6
/
sysdep.h
562 lines (455 loc) · 16 KB
/
sysdep.h
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
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
/* sysdep.h -*- C -*-
The header file for the UNIX system dependent routines.
Copyright (C) 1991, 1992, 1993, 1995, 2002 Ian Lance Taylor
This file is part of the Taylor UUCP package.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
This program 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
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; 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.
*/
#ifndef SYSDEP_H
#define SYSDEP_H
#if ANSI_C
/* These structures are used in prototypes but are not defined in this
header file. */
struct uuconf_system;
struct sconnection;
#endif
/* SCO, SVR4 and Sequent lockfiles are basically just like HDB
lockfiles. */
#if HAVE_SCO_LOCKFILES || HAVE_SVR4_LOCKFILES || HAVE_SEQUENT_LOCKFILES
#undef HAVE_HDB_LOCKFILES
#define HAVE_HDB_LOCKFILES 1
#endif
#if HAVE_BSD_TTY + HAVE_SYSV_TERMIO + HAVE_POSIX_TERMIOS != 1
#error Terminal driver define not set or duplicated
#endif
#if SPOOLDIR_V2 + SPOOLDIR_BSD42 + SPOOLDIR_BSD43 + SPOOLDIR_HDB + SPOOLDIR_ULTRIX + SPOOLDIR_SVR4 + SPOOLDIR_TAYLOR != 1
#error Spool directory define not set or duplicated
#endif
/* If setreuid is broken, don't use it. */
#if HAVE_BROKEN_SETREUID
#undef HAVE_SETREUID
#define HAVE_SETREUID 0
#endif
/* Get some standard types from the configuration header file. */
#ifdef PID_T
typedef PID_T pid_t;
#endif
#ifdef UID_T
typedef UID_T uid_t;
#endif
#ifdef GID_T
typedef GID_T gid_t;
#endif
#ifdef OFF_T
typedef OFF_T off_t;
#endif
/* On Unix, binary files are the same as text files. */
#define BINREAD "r"
#define BINWRITE "w"
/* If we have sigaction, we can force system calls to not be
restarted. */
#if HAVE_SIGACTION
#undef HAVE_RESTARTABLE_SYSCALLS
#define HAVE_RESTARTABLE_SYSCALLS 0
#endif
/* If we have sigvec, and we have HAVE_SIGVEC_SV_FLAGS, and
SV_INTERRUPT is defined, we can force system calls to not be
restarted (signal.h is included by uucp.h before this point, so
SV_INTERRUPT will be defined by now if it it ever is). */
#if HAVE_SIGVEC && HAVE_SIGVEC_SV_FLAGS
#ifdef SV_INTERRUPT
#undef HAVE_RESTARTABLE_SYSCALLS
#define HAVE_RESTARTABLE_SYSCALLS 0
#endif
#endif
/* If we were cross-configured, we will have a value of -1 for
HAVE_RESTARTABLE_SYSCALLS. In this case, we try to guess what the
correct value should be. Yuck. If we have sigvec, but neither of
the above cases applied (which we know because they would have
changed HAVE_RESTARTABLE_SYSCALLS) then we are probably on 4.2BSD
and system calls are automatically restarted. Otherwise, assume
that they are not. */
#if HAVE_RESTARTABLE_SYSCALLS == -1
#undef HAVE_RESTARTABLE_SYSCALLS
#if HAVE_SIGVEC
#define HAVE_RESTARTABLE_SYSCALLS 1
#else
#define HAVE_RESTARTABLE_SYSCALLS 0
#endif
#endif /* HAVE_RESTARTABLE_SYSCALLS == -1 */
/* We don't handle sigset in combination with restartable system
calls, so we check for it although this combination will never
happen. */
#if ! HAVE_SIGACTION && ! HAVE_SIGVEC && HAVE_SIGSET
#if HAVE_RESTARTABLE_SYSCALLS
#undef HAVE_SIGSET
#define HAVE_SIGSET 0
#endif
#endif
/* If we don't have restartable system calls, we can ignore
fsysdep_catch, usysdep_start_catch and usysdep_end_catch.
Otherwise fsysdep_catch has to do a setjmp. */
#if ! HAVE_RESTARTABLE_SYSCALLS
#define fsysdep_catch() (TRUE)
#define usysdep_start_catch()
#define usysdep_end_catch()
#define CATCH_PROTECT
#else /* HAVE_RESTARTABLE_SYSCALLS */
#if HAVE_SETRET && ! HAVE_SIGSETJMP
#include <setret.h>
#define setjmp setret
#define longjmp longret
#define jmp_buf ret_buf
#else /* ! HAVE_SETRET || HAVE_SIGSETJMP */
#include <setjmp.h>
#if HAVE_SIGSETJMP
#undef setjmp
#undef longjmp
#undef jmp_buf
#define setjmp(s) sigsetjmp ((s), TRUE)
#define longjmp siglongjmp
#define jmp_buf sigjmp_buf
#endif /* HAVE_SIGSETJMP */
#endif /* ! HAVE_SETRET || HAVE_SIGSETJMP */
extern volatile sig_atomic_t fSjmp;
extern volatile jmp_buf sSjmp_buf;
#define fsysdep_catch() (setjmp (sSjmp_buf) == 0)
#define usysdep_start_catch() (fSjmp = TRUE)
#define usysdep_end_catch() (fSjmp = FALSE)
#define CATCH_PROTECT volatile
#endif /* HAVE_RESTARTABLE_SYSCALLS */
/* Get definitions for the terminal driver. */
#if HAVE_BSD_TTY
#include <sgtty.h>
struct sbsd_terminal
{
struct sgttyb stty;
struct tchars stchars;
struct ltchars sltchars;
};
typedef struct sbsd_terminal sterminal;
#define fgetterminfo(o, q) \
(ioctl ((o), TIOCGETP, &(q)->stty) == 0 \
&& ioctl ((o), TIOCGETC, &(q)->stchars) == 0 \
&& ioctl ((o), TIOCGLTC, &(q)->sltchars) == 0)
#define fsetterminfo(o, q) \
(ioctl ((o), TIOCSETN, &(q)->stty) == 0 \
&& ioctl ((o), TIOCSETC, &(q)->stchars) == 0 \
&& ioctl ((o), TIOCSLTC, &(q)->sltchars) == 0)
#define fsetterminfodrain(o, q) \
(ioctl ((o), TIOCSETP, &(q)->stty) == 0 \
&& ioctl ((o), TIOCSETC, &(q)->stchars) == 0 \
&& ioctl ((o), TIOCSLTC, &(q)->sltchars) == 0)
#endif /* HAVE_BSD_TTY */
#if HAVE_SYSV_TERMIO
#include <termio.h>
typedef struct termio sterminal;
#define fgetterminfo(o, q) (ioctl ((o), TCGETA, (q)) == 0)
#define fsetterminfo(o, q) (ioctl ((o), TCSETA, (q)) == 0)
#define fsetterminfodrain(o, q) (ioctl ((o), TCSETAW, (q)) == 0)
#endif /* HAVE_SYSV_TERMIO */
#if HAVE_POSIX_TERMIOS
#include <termios.h>
typedef struct termios sterminal;
#define fgetterminfo(o, q) (tcgetattr ((o), (q)) == 0)
#define fsetterminfo(o, q) (tcsetattr ((o), TCSANOW, (q)) == 0)
#define fsetterminfodrain(o, q) (tcsetattr ((o), TCSADRAIN, (q)) == 0)
/* On some systems it is not possible to include both <sys/ioctl.h>
and <termios.h> in the same source files; I don't really know why.
On such systems, we pretend that we don't have <sys/ioctl.h>. */
#if ! HAVE_TERMIOS_AND_SYS_IOCTL_H
#undef HAVE_SYS_IOCTL_H
#define HAVE_SYS_IOCTL_H 0
#endif
#endif /* HAVE_POSIX_TERMIOS */
/* The root directory (this is needed by the system independent stuff
as the default for local-send). */
#define ZROOTDIR "/"
/* The name of the execution directory within the spool directory
(this is need by the system independent uuxqt.c). */
#define XQTDIR ".Xqtdir"
/* The name of the directory in which we preserve file transfers that
failed. */
#define PRESERVEDIR ".Preserve"
/* The name of the directory to which we move corrupt files. */
#define CORRUPTDIR ".Corrupt"
/* The name of the directory to which we move failed execution files. */
#define FAILEDDIR ".Failed"
/* The length of the sequence number used in a file name. */
#define CSEQLEN (4)
/* Get some standard definitions. Avoid including the files more than
once--some might have been included by uucp.h. */
#if USE_STDIO && HAVE_UNISTD_H
#include <unistd.h>
#endif
#if ! USE_TYPES_H
#include <sys/types.h>
#endif
#include <sys/stat.h>
/* Get definitions for the file permission bits. */
#ifndef S_IRWXU
#define S_IRWXU 0700
#endif
#ifndef S_IRUSR
#define S_IRUSR 0400
#endif
#ifndef S_IWUSR
#define S_IWUSR 0200
#endif
#ifndef S_IXUSR
#define S_IXUSR 0100
#endif
#ifndef S_IRWXG
#define S_IRWXG 0070
#endif
#ifndef S_IRGRP
#define S_IRGRP 0040
#endif
#ifndef S_IWGRP
#define S_IWGRP 0020
#endif
#ifndef S_IXGRP
#define S_IXGRP 0010
#endif
#ifndef S_IRWXO
#define S_IRWXO 0007
#endif
#ifndef S_IROTH
#define S_IROTH 0004
#endif
#ifndef S_IWOTH
#define S_IWOTH 0002
#endif
#ifndef S_IXOTH
#define S_IXOTH 0001
#endif
#if STAT_MACROS_BROKEN
#undef S_ISDIR
#endif
#ifndef S_ISDIR
#ifdef S_IFDIR
#define S_ISDIR(i) (((i) & S_IFMT) == S_IFDIR)
#else /* ! defined (S_IFDIR) */
#define S_ISDIR(i) (((i) & 0170000) == 040000)
#endif /* ! defined (S_IFDIR) */
#endif /* ! defined (S_ISDIR) */
/* We need the access macros. */
#ifndef R_OK
#define R_OK 4
#define W_OK 2
#define X_OK 1
#define F_OK 0
#endif /* ! defined (R_OK) */
/* We create files with these modes (should this be configurable?). */
#define IPRIVATE_FILE_MODE (S_IRUSR | S_IWUSR)
#define IPUBLIC_FILE_MODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)
/* We create directories with this mode (should this be configurable?). */
#define IDIRECTORY_MODE (S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)
#define IPUBLIC_DIRECTORY_MODE (S_IRWXU | S_IRWXG | S_IRWXO)
#if ! HAVE_OPENDIR
/* Define some structures to use if we don't have opendir, etc. These
will only work if we have the old Unix filesystem, with a 2 byte
inode and a 14 byte filename. */
#include <sys/dir.h>
struct dirent
{
char d_name[DIRSIZ + 1];
};
typedef struct
{
int o;
struct dirent s;
} DIR;
extern DIR *opendir P((const char *zdir));
extern struct dirent *readdir P((DIR *));
extern int closedir P((DIR *));
#endif /* ! HAVE_OPENDIR */
#if ! HAVE_FTW_H
/* If there is no <ftw.h>, define the ftw constants. */
#define FTW_F (0)
#define FTW_D (1)
#define FTW_DNR (2)
#define FTW_NS (3)
#endif /* ! HAVE_FTW_H */
/* This structure holds the system dependent information we keep for a
connection. This is used by the TCP and TLI code. */
struct ssysdep_conn
{
/* File descriptor. */
int o;
/* File descriptor to read from (used by stdin and pipe port types). */
int ord;
/* File descriptor to write to (used by stdin and pipe port types). */
int owr;
/* Device name. */
char *zdevice;
/* File status flags. */
int iflags;
/* File status flags for write descriptor (-1 if not used). */
int iwr_flags;
/* Hold the real descriptor when using a dialer device. */
int ohold;
/* TRUE if this is a terminal and the remaining fields are valid. */
boolean fterminal;
/* TRUE if this is a TLI descriptor. */
boolean ftli;
/* Baud rate. */
long ibaud;
/* Original terminal settings. */
sterminal sorig;
/* Current terminal settings. */
sterminal snew;
/* Process ID of currently executing pipe command, or parent process
of forked TCP or TLI server, or -1. */
pid_t ipid;
#if HAVE_COHERENT_LOCKFILES
/* On Coherent we need to hold on to the real port name which will
be used to enable the port. Ick. */
char *zenable;
#endif
};
/* These functions do I/O and chat scripts to a port. They are called
by the TCP and TLI routines. */
extern boolean fsysdep_conn_read P((struct sconnection *qconn,
char *zbuf, size_t *pclen,
size_t cmin, int ctimeout,
boolean freport));
extern boolean fsysdep_conn_write P((struct sconnection *qconn,
const char *zbuf, size_t clen));
extern boolean fsysdep_conn_io P((struct sconnection *qconn,
const char *zwrite, size_t *pcwrite,
char *zread, size_t *pcread));
extern boolean fsysdep_conn_chat P((struct sconnection *qconn,
char **pzprog));
/* Set a signal handler. */
extern void usset_signal P((int isig, RETSIGTYPE (*pfn) P((int)),
boolean fforce, boolean *pfignored));
/* Default signal handler. This sets the appropriate element of the
afSignal array. If system calls are automatically restarted, it
may do a longjmp to an fsysdep_catch. */
extern RETSIGTYPE ussignal P((int isig));
/* Try to fork, repeating several times. */
extern pid_t ixsfork P((void));
/* Spawn a job. Returns the process ID of the spawned job or -1 on
error. The following macros may be passed in aidescs. */
/* Set descriptor to /dev/null. */
#define SPAWN_NULL (-1)
/* Set element of aidescs to a pipe for caller to read from. */
#define SPAWN_READ_PIPE (-2)
/* Set element of aidescs to a pipe for caller to write to. */
#define SPAWN_WRITE_PIPE (-3)
extern pid_t ixsspawn P((const char **pazargs, int *aidescs,
boolean fkeepuid, boolean fkeepenv,
const char *zchdir, boolean fnosigs,
boolean fshell, const char *zpath,
const char *zuu_machine,
const char *zuu_user));
/* Do a form of popen using ixsspawn. */
extern FILE *espopen P((const char **pazargs, boolean frd,
pid_t *pipid));
/* Wait for a particular process to finish, returning the exit status.
The process ID should be pid_t, but we can't put that in a
prototype. */
extern int ixswait P((unsigned long ipid, const char *zreport));
/* Read from a connection using two file descriptors. */
extern boolean fsdouble_read P((struct sconnection *qconn, char *zbuf,
size_t *pclen, size_t cmin, int ctimeout,
boolean freport));
/* Write to a connection using two file descriptors. */
extern boolean fsdouble_write P((struct sconnection *qconn,
const char *zbuf, size_t clen));
/* Run a chat program on a connection using two file descriptors. */
extern boolean fsdouble_chat P((struct sconnection *qconn,
char **pzprog));
/* Find a spool file in the spool directory. For a local file, the
bgrade argument is the grade of the file. This is needed for
SPOOLDIR_SVR4. */
extern char *zsfind_file P((const char *zsimple, const char *zsystem,
int bgrade));
/* Return the grade given a sequence number. */
extern int bsgrade P((pointer pseq));
/* Lock a string. */
extern boolean fsdo_lock P((const char *, boolean fspooldir,
boolean *pferr));
/* Unlock a string. */
extern boolean fsdo_unlock P((const char *, boolean fspooldir));
/* Check access for a particular user name, or NULL to check access
for any user. */
extern boolean fsuser_access P((const struct stat *, int imode,
const char *zuser));
/* Switch to the permissions of the invoking user. This sets the
arguments to values to pass to fsuucp_perms. */
extern boolean fsuser_perms P((uid_t *, gid_t *));
/* Switch back to the permissions of the UUCP user ID. This should be
passed the values returned by fsuser_perms in its arguments. */
extern boolean fsuucp_perms P((long, long));
/* Stick two directories and a file name together. */
extern char *zsappend3 P((const char *zdir1, const char *zdir2,
const char *zfile));
/* Stick three directories and a file name together. */
extern char *zsappend4 P((const char *zdir1, const char *zdir2,
const char *zdir3, const char *zfile));
/* Get a temporary file name. */
extern char *zstemp_file P((const struct uuconf_system *qsys));
/* Get a command file name. */
extern char *zscmd_file P((const struct uuconf_system *qsys, int bgrade));
/* Get a jobid from a system, a file name, and a grade. */
extern char *zsfile_to_jobid P((const struct uuconf_system *qsys,
const char *zfile,
int bgrade));
/* Get a file name from a jobid. This also returns the associated system
in *pzsystem and the grade in *pbgrade. */
extern char *zsjobid_to_file P((const char *zid, char **pzsystem,
char *pbgrade));
/* See whether there is a spool directory for a system when using
SPOOLDIR_ULTRIX. */
extern boolean fsultrix_has_spool P((const char *zsystem));
#if HAVE_COHERENT_LOCKFILES
/* Lock a coherent tty. */
extern boolean lockttyexist P((const char *z));
extern boolean fscoherent_disable_tty P((const char *zdevice,
char **pzenable));
#endif
/* Some replacements for standard Unix functions. */
#if ! HAVE_DUP2
extern int dup2 P((int oold, int onew));
#endif
#if ! HAVE_FTW
extern int ftw P((const char *zdir,
int (*pfn) P((const char *zfile,
const struct stat *qstat,
int iflag)),
int cdescriptors));
#endif
#if ! HAVE_GETCWD && ! HAVE_GETWD
extern char *getcwd P((char *zbuf, size_t cbuf));
#endif
#if ! HAVE_MKDIR
extern int mkdir P((const char *zdir, int imode));
#endif
#if ! HAVE_RENAME
extern int rename P((const char *zold, const char *znew));
#endif
#if ! HAVE_RMDIR
extern int rmdir P((const char *zdir));
#endif
/* The working directory from which the program was run (this is set
by usysdep_initialize if called with INIT_GETCWD). */
extern char *zScwd;
/* The spool directory name. */
extern const char *zSspooldir;
/* The lock directory name. */
extern const char *zSlockdir;
/* The local UUCP name (needed for some spool directory stuff). */
extern const char *zSlocalname;
#endif /* ! defined (SYSDEP_H) */