xref: /illumos-gate/usr/src/cmd/ttymon/uucp.h (revision 0ccfe5834c3b867c1b6c273cae02ec8922bc0fd2)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
23 /*	  All Rights Reserved	*/
24 /*
25  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
26  * Use is subject to license terms.
27  */
28 
29 
30 #ifndef _UUCP_H
31 #define	_UUCP_H
32 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36 
37 #include <unistd.h>
38 #include <stdlib.h>
39 #include <string.h>
40 #include "parms.h"
41 
42 #ifdef DIAL
43 #define	EXTERN static
44 #define	GLOBAL static
45 #else
46 #define	EXTERN extern
47 #define	GLOBAL
48 #endif
49 
50 #ifdef BSD4_2
51 #define	V7
52 #undef NONAP
53 #undef FASTTIMER
54 #endif /* BSD4_2 */
55 
56 #ifdef FASTTIMER
57 #undef NONAP
58 #endif
59 
60 #ifdef V8
61 #define	V7
62 #endif /* V8 */
63 
64 #include <stdio.h>
65 #include <ctype.h>
66 #include <setjmp.h>
67 #include <sys/param.h>
68 
69 /*
70  * param.h includes types.h and signal.h in 4bsd
71  */
72 #ifdef V7
73 #include <sgtty.h>
74 #include <sys/timeb.h>
75 #else /* !V7 */
76 #include <termio.h>
77 #include <sys/types.h>
78 #include <signal.h>
79 #include <fcntl.h>
80 #endif
81 
82 #include <sys/stat.h>
83 #include <utime.h>
84 #include <dirent.h>
85 
86 #ifdef BSD4_2
87 #include <sys/time.h>
88 #else /* !BSD4_2 */
89 #include <time.h>
90 #endif
91 
92 #include <sys/times.h>
93 #include <errno.h>
94 
95 #ifdef ATTSV
96 #include <sys/mkdev.h>
97 #endif /* ATTSV */
98 
99 #ifdef	RT
100 #include "rt/types.h"
101 #include "rt/unix/param.h"
102 #include "rt/stat.h"
103 #include <sys/ustat.h>
104 #endif /* RT */
105 
106 /* what mode should user files be allowed to have upon creation? */
107 /* NOTE: This does not allow setuid or execute bits on transfer. */
108 #define	LEGALMODE (mode_t)0666
109 
110 /* what mode should public files have upon creation? */
111 #define	PUB_FILEMODE (mode_t)0666
112 
113 /* what mode should log files have upon creation? */
114 #define	LOGFILEMODE (mode_t)0644
115 
116 /* what mode should C. files have upon creation? */
117 #define	CFILEMODE (mode_t)0644
118 
119 /* what mode should D. files have upon creation? */
120 #define	DFILEMODE (mode_t)0600
121 
122 /* define the value of PUBMASK, used for creating "public" directories */
123 #define	PUBMASK (mode_t)0000
124 
125 /* what mode should public directories have upon creation? */
126 #define	PUB_DIRMODE (mode_t)0777
127 
128 /* define the value of DIRMASK, used for creating "system" subdirectories */
129 #define	DIRMASK (mode_t)0022
130 
131 #define	MAXSTART	300	/* how long to wait on startup */
132 
133 /* define the last characters for ACU  (used for 801/212 dialers) */
134 #define	ACULAST "<"
135 
136 /*
137  *  caution - the following names are also in Makefile
138  *    any changes here have to also be made there
139  *
140  * it's a good idea to make directories .foo, since this ensures
141  * that they'll be ignored by processes that search subdirectories in SPOOL
142  *
143  *  XQTDIR=/var/uucp/.Xqtdir
144  *  CORRUPT=/var/uucp/.Corrupt
145  *  LOGDIR=/var/uucp/.Log
146  *  SEQDIR=/var/uucp/.Sequence
147  *  STATDIR=/var/uucp/.Status
148  *
149  */
150 
151 /* where to put the STST. files? */
152 #define	STATDIR		"/var/uucp/.Status"
153 
154 /* where should logfiles be kept? */
155 #define	LOGUUX		"/var/uucp/.Log/uux"
156 #define	LOGUUXQT	"/var/uucp/.Log/uuxqt"
157 #define	LOGUUCP		"/var/uucp/.Log/uucp"
158 #define	LOGCICO		"/var/uucp/.Log/uucico"
159 #define	CORRUPTDIR	"/var/uucp/.Corrupt"
160 
161 /* some sites use /var/uucp/.XQTDIR here */
162 /* use caution since things are linked into there */
163 #define	XQTDIR		"/var/uucp/.Xqtdir"
164 
165 /* how much of a system name can we print in a [CX]. file? */
166 /* MAXBASENAME - 1 (pre) - 1 ('.') - 1 (grade) - 4 (sequence number) */
167 #define	SYSNSIZE (MAXBASENAME - 7)
168 
169 #ifdef USRSPOOLLOCKS
170 #define	LOCKPRE		"/var/spool/locks/LCK."
171 #else
172 #define	LOCKPRE		"/var/spool/uucp/LCK."
173 #endif /* USRSPOOLLOCKS */
174 
175 #define	SQFILE		"/etc/uucp/SQFILE"
176 #define	SQTMP		"/etc/uucp/SQTMP"
177 #define	SLCKTIME	5400	/* system/device timeout (LCK.. files) */
178 #define	DIALCODES	"/etc/uucp/Dialcodes"
179 #define	PERMISSIONS	"/etc/uucp/Permissions"
180 
181 #define	SPOOL		"/var/spool/uucp"
182 #define	SEQDIR		"/var/uucp/.Sequence"
183 
184 #define	X_LOCKTIME	3600
185 #ifdef USRSPOOLLOCKS
186 #define	SEQLOCK		"/var/spool/locks/LCK.SQ."
187 #define	SQLOCK		"/var/spool/locks/LCK.SQ"
188 #define	X_LOCK		"/var/spool/locks/LCK.X"
189 #define	S_LOCK		"/var/spool/locks/LCK.S"
190 #define	L_LOCK		"/var/spool/locks/LK"
191 #define	X_LOCKDIR	"/var/spool/locks"	/* must be dir part of above */
192 #else
193 #define	SEQLOCK		"/var/spool/uucp/LCK.SQ."
194 #define	SQLOCK		"/var/spool/uucp/LCK.SQ"
195 #define	X_LOCK		"/var/spool/uucp/LCK.X"
196 #define	S_LOCK		"/var/spool/uucp/LCK.S"
197 #define	L_LOCK		"/var/spool/uucp/LK"
198 #define	X_LOCKDIR	"/var/spool/uucp"	/* must be dir part of above */
199 #endif /* USRSPOOLLOCKS */
200 #define	X_LOCKPRE	"LCK.X"		/* must be last part of above */
201 
202 #define	PUBDIR		"/var/spool/uucppublic"
203 #define	ADMIN		"/var/uucp/.Admin"
204 #define	ERRLOG		"/var/uucp/.Admin/errors"
205 #define	SYSLOG		"/var/uucp/.Admin/xferstats"
206 #define	RMTDEBUG	"/var/uucp/.Admin/audit"
207 #define	CLEANUPLOGFILE	"/var/uucp/.Admin/uucleanup"
208 #define	CMDLOG		"/var/uucp/.Admin/command"
209 #define	PERFLOG		"/var/uucp/.Admin/perflog"
210 #define	ACCOUNT		"/var/uucp/.Admin/account"
211 #define	SECURITY	"/var/uucp/.Admin/security"
212 
213 #define	WORKSPACE	"/var/uucp/.Workspace"
214 
215 #define	SQTIME		60
216 #define	TRYCALLS	2	/* number of tries to dial call */
217 #define	MINULIMIT	(1L<<11)	/* minimum reasonable ulimit */
218 #define	MAX_LOCKTRY	5	/* number of attempts to lock device */
219 
220 /*
221  * CDEBUG is for communication line debugging
222  * DEBUG is for program debugging
223  * #define SMALL to compile without the DEBUG code
224  */
225 
226 #ifndef DIAL
227 #define	CDEBUG(l, f, s) if (Debug >= l) (void)fprintf(stderr, f, s)
228 #else
229 #define	CDEBUG(l, f, s)
230 #define	SMALL
231 #endif
232 
233 #ifndef SMALL
234 #define	DEBUG(l, f, s) if (Debug >= l) (void)fprintf(stderr, f, s)
235 #else
236 #define	DEBUG(l, f, s)
237 #endif /* SMALL */
238 
239 /*
240  * VERBOSE is used by cu and ct to inform the user of progress
241  * In other programs, the Value of Verbose is always 0.
242  */
243 #define	VERBOSE(f, s) { if (Verbose > 0) (void)fprintf(stderr, f, s); }
244 
245 #define	PREFIX(pre, str)	(strncmp((pre), (str), strlen(pre)) == SAME)
246 #define	BASENAME(str, c) ((Bnptr = strrchr((str), c)) ? (Bnptr + 1) : (str))
247 #define	EQUALS(a, b)	\
248 	((a != CNULL) && (b != CNULL) && (strcmp((a), (b)) == SAME))
249 #define	EQUALSN(a, b, n)	\
250 	((a != CNULL) && (b != CNULL) && (strncmp((a), (b), (n)) == SAME))
251 #define	LASTCHAR(s)	(s + strlen(s) - 1)
252 
253 #define	SAME 0
254 #define	ANYREAD 04
255 #define	ANYWRITE 02
256 #define	FAIL -1
257 #define	SUCCESS 0
258 #define	NULLCHAR	'\0'
259 #define	CNULL NULL
260 #define	STBNULL NULL
261 #define	MASTER 1
262 #define	SLAVE 0
263 #define	MAXBASENAME 14 /* should be DIRSIZ but that is now fs dependent */
264 #define	MAXFULLNAME BUFSIZ
265 #define	MAXNAMESIZE	64	/* /var/spool/uucp/<14 chars>/<14 chars>+slop */
266 #define	CONNECTTIME 30
267 #define	EXPECTTIME 45
268 #define	MSGTIME 60
269 #define	NAMESIZE MAXBASENAME+1
270 #define	SIZEOFPID	10		/* maximum number of digits in a pid */
271 #define	EOTMSG "\004\n\004\n"
272 #define	CALLBACK 1
273 
274 /* manifests for sysfiles.c's sysaccess()	*/
275 /* check file access for REAL user id */
276 #define	ACCESS_SYSTEMS	1
277 #define	ACCESS_DEVICES	2
278 #define	ACCESS_DIALERS	3
279 /* check file access for EFFECTIVE user id */
280 #define	EACCESS_SYSTEMS	4
281 #define	EACCESS_DEVICES	5
282 #define	EACCESS_DIALERS	6
283 
284 /* manifest for chkpth flag */
285 #define	CK_READ		0
286 #define	CK_WRITE	1
287 
288 /*
289  * commands
290  */
291 #define	SHELL		"/usr/bin/sh"
292 #define	MAIL		"mail"
293 #define	UUCICO		"/usr/lib/uucp/uucico"
294 #define	UUXQT		"/usr/lib/uucp/uuxqt"
295 #define	UUX		"/usr/bin/uux"
296 #define	UUCP		"/usr/bin/uucp"
297 
298 
299 /* system status stuff */
300 #define	SS_OK			0
301 #define	SS_NO_DEVICE		1
302 #define	SS_TIME_WRONG		2
303 #define	SS_INPROGRESS		3
304 #define	SS_CONVERSATION		4
305 #define	SS_SEQBAD		5
306 #define	SS_LOGIN_FAILED		6
307 #define	SS_DIAL_FAILED		7
308 #define	SS_BAD_LOG_MCH		8
309 #define	SS_LOCKED_DEVICE	9
310 #define	SS_ASSERT_ERROR		10
311 #define	SS_BADSYSTEM		11
312 #define	SS_CANT_ACCESS_DEVICE	12
313 #define	SS_DEVICE_FAILED	13	/* used for interface failure */
314 #define	SS_WRONG_MCH		14
315 #define	SS_CALLBACK		15
316 #define	SS_RLOCKED		16
317 #define	SS_RUNKNOWN		17
318 #define	SS_RLOGIN		18
319 #define	SS_UNKNOWN_RESPONSE	19
320 #define	SS_STARTUP		20
321 #define	SS_CHAT_FAILED		21
322 #define	SS_CALLBACK_LOOP	22
323 
324 #define	MAXPH	60	/* maximum phone string size */
325 #define	MAXC	BUFSIZ
326 
327 #define	TRUE	1
328 #define	FALSE	0
329 #define	NAMEBUF	32
330 
331 /* The call structure is used by ct.c, cu.c, and dial.c.	*/
332 
333 struct call {
334 	char *speed;		/* transmission baud rate */
335 	char *line;		/* device name for outgoing line */
336 	char *telno;		/* ptr to tel-no digit string */
337 	char *type;		/* type of device to use for call. */
338 };
339 
340 /* structure of an Systems file line */
341 #define	F_MAX	50	/* max number of fields in Systems file line */
342 #define	F_NAME 0
343 #define	F_TIME 1
344 #define	F_TYPE 2
345 #define	F_CLASS 3	/* an optional prefix and the speed */
346 #define	F_PHONE 4
347 #define	F_LOGIN 5
348 
349 /* structure of an Devices file line */
350 #define	D_TYPE 0
351 #define	D_LINE 1
352 #define	D_CALLDEV 2
353 #define	D_CLASS 3
354 #define	D_CALLER 4
355 #define	D_ARG 5
356 #define	D_MAX	50	/* max number of fields in Devices file line */
357 
358 #define	D_ACU 1
359 #define	D_DIRECT 2
360 #define	D_PROT 4
361 
362 #define	GRADES "/etc/uucp/Grades"
363 
364 #define	D_QUEUE	'Z'	/* default queue */
365 
366 /* past here, local changes are not recommended */
367 #define	CMDPRE		'C'
368 #define	DATAPRE		'D'
369 #define	XQTPRE		'X'
370 
371 /*
372  * stuff for command execution
373  */
374 #define	X_RQDFILE	'F'
375 #define	X_STDIN		'I'
376 #define	X_STDOUT	'O'
377 #define	X_STDERR	'E'
378 #define	X_CMD		'C'
379 #define	X_USER		'U'
380 #define	X_BRINGBACK	'B'
381 #define	X_MAILF		'M'
382 #define	X_RETADDR	'R'
383 #define	X_COMMENT	'#'
384 #define	X_NONZERO	'Z'
385 #define	X_SENDNOTHING	'N'
386 #define	X_SENDZERO	'n'
387 
388 
389 /* This structure describes call routines */
390 struct caller {
391 	char	*CA_type;
392 	int	(*CA_caller)();
393 };
394 
395 /* structure for a saved C file */
396 
397 struct cs_struct {
398 	char	file[NAMESIZE];
399 	char	sys[NAMESIZE+5];
400 	char	sgrade[NAMESIZE];
401 	char	grade;
402 	long	jsize;
403 };
404 
405 /* This structure describes dialing routines */
406 struct dialer {
407 	char	*DI_type;
408 	int	(*DI_dialer)();
409 };
410 
411 struct nstat {
412 	pid_t	t_pid;		/* process id				*/
413 	time_t	t_start;	/* start time				*/
414 	time_t	t_scall;	/* start call to system			*/
415 	time_t	t_ecall;	/* end call to system			*/
416 	time_t	t_tacu;		/* acu time				*/
417 	time_t	t_tlog;		/* login time				*/
418 	time_t	t_sftp;		/* start file transfer protocol		*/
419 	time_t	t_sxf;		/* start xfer				*/
420 	time_t	t_exf;		/* end xfer				*/
421 	time_t	t_eftp;		/* end file transfer protocol		*/
422 	time_t	t_qtime;	/* time file queued			*/
423 	int	t_ndial;	/* # of dials				*/
424 	int	t_nlogs;	/* # of login trys			*/
425 	struct tms t_tbb;	/* start execution times		*/
426 	struct tms t_txfs;	/* xfer start times			*/
427 	struct tms t_txfe;	/* xfer end times			*/
428 	struct tms t_tga;	/* garbage execution times		*/
429 };
430 
431 /* This structure describes the values from Limits file */
432 struct limits {
433 	int	totalmax;	/* overall limit */
434 	int	sitemax;	/* limit per site */
435 	char	mode[64];	/* uucico mode */
436 };
437 
438 /* external declarations */
439 
440 EXTERN int (*Read)(), (*Write)();
441 EXTERN int (*Ioctl)(int, int, ...);
442 EXTERN int Ifn, Ofn;
443 EXTERN int Debug, Verbose;
444 EXTERN uid_t Uid, Euid;		/* user-id and effective-uid */
445 EXTERN long Ulimit;
446 EXTERN mode_t Dev_mode;		/* save device mode here */
447 EXTERN char Wrkdir[];
448 EXTERN long Retrytime;
449 EXTERN char **Env;
450 EXTERN char Uucp[];
451 EXTERN char Pchar;
452 EXTERN struct nstat Nstat;
453 EXTERN char Dc[];			/* line name			*/
454 EXTERN int Seqn;			/* sequence #			*/
455 EXTERN int Role;
456 EXTERN int Sgrades;	/* flag for administrator defined service grades */
457 EXTERN char Grade;
458 EXTERN char Logfile[];
459 EXTERN char Rmtname[];
460 EXTERN char JobGrade[];
461 EXTERN char User[];
462 EXTERN char Loginuser[];
463 EXTERN char *Spool;
464 EXTERN char *Pubdir;
465 EXTERN char Myname[];
466 EXTERN char Progname[];
467 EXTERN char RemSpool[];
468 EXTERN char *Bnptr;		/* used when BASENAME macro is expanded */
469 EXTERN int SizeCheck;		/* ulimit check supported flag */
470 EXTERN long RemUlimit;		/* remote ulimit if supported */
471 EXTERN int Restart;		/* checkpoint restart supported flag */
472 
473 EXTERN char Jobid[];		/* Jobid of current C. file */
474 EXTERN int Uerror;		/* global error code */
475 EXTERN char *UerrorText[];	/* text for error code */
476 
477 #define	UERRORTEXT		UerrorText[Uerror]
478 #define	UTEXT(x)		UerrorText[x]
479 
480 /* things get kind of tricky beyond this point -- please stay out */
481 
482 #ifdef ATTSV
483 #define	index strchr
484 #define	rindex strrchr
485 #define	vfork fork
486 #define	ATTSVKILL
487 #define	UNAME
488 #else
489 #define	strchr index
490 #define	strrchr rindex
491 #endif
492 
493 EXTERN struct stat __s_;
494 #define	READANY(f)	\
495 	((stat((f), &__s_) == 0) && ((__s_.st_mode & (0004)) != 0))
496 #define	READSOME(f)	\
497 	((stat((f), &__s_) == 0) && ((__s_.st_mode & (0444)) != 0))
498 #define	WRITEANY(f)	\
499 	((stat((f), &__s_) == 0) && ((__s_.st_mode & (0002)) != 0))
500 #define	DIRECTORY(f)	\
501 	((stat((f), &__s_) == 0) && ((__s_.st_mode & (S_IFMT)) == S_IFDIR))
502 #define	NOTEMPTY(f)	((stat((f), &__s_) == 0) && (__s_.st_size != 0))
503 
504 /* uucp functions and subroutine */
505 EXTERN void	(*genbrk)();
506 extern int	iswrk(), gtwvec();			/* anlwrk.c */
507 extern void	findgrade();				/* grades.c */
508 extern void	chremdir(), mkremdir();			/* chremdir.c */
509 extern void	toCorrupt();				/* cpmv.c  */
510 extern int	xmv();					/* cpmv.c  */
511 
512 EXTERN int	getargs();				/* getargs.c */
513 EXTERN void	bsfix();				/* getargs.c */
514 extern char	*getprm();				/* getprm.c */
515 
516 extern char	*next_token();				/* permission.c */
517 extern char	*nextarg();				/* permission.c */
518 extern int	getuline();				/* permission.c */
519 
520 EXTERN void	logent(), syslog(), closelog();		/* logent.c */
521 extern void	commandlog();				/* logent.c */
522 extern time_t	millitick();				/* logent.c */
523 
524 extern unsigned long	getfilesize();			/* statlog.c */
525 extern void		putfilesize();			/* statlog.c */
526 
527 EXTERN char	*protoString();				/* permission.c */
528 extern int	logFind(), mchFind();			/* permission.c */
529 extern int	chkperm(), chkpth();			/* permission.c */
530 extern int	cmdOK(), switchRole();			/* permission.c */
531 extern int	callBack(), requestOK();		/* permission.c */
532 extern int	noSpool();				/* permission.c */
533 extern void	myName();				/* permission.c */
534 
535 extern int	mkdirs();				/* expfile.c */
536 extern int	scanlimit();				/* limits.c */
537 extern void	systat();				/* systat.c */
538 EXTERN int	fd_mklock(), fd_cklock();		/* ulockf.c */
539 EXTERN int	fn_cklock();				/* ulockf.c */
540 EXTERN int	mklock(), cklock(), mlock();		/* ulockf.c */
541 EXTERN void	fd_rmlock(), delock(), rmlock();	/* ulockf.c */
542 extern char	*timeStamp();				/* utility.c */
543 EXTERN void	assert(), errent();			/* utility.c */
544 extern void	uucpname();				/* uucpname.c */
545 extern int	versys();				/* versys.c */
546 extern void	xuuxqt(), xuucico();			/* xqt.c */
547 EXTERN void	cleanup();				/* misc main.c */
548 
549 #define	ASSERT(e, s1, s2, i1) if (!(e)) {\
550 	assert(s1, s2, i1, __FILE__, __LINE__);\
551 	cleanup(FAIL); };
552 
553 #ifdef ATTSV
554 unsigned	sleep();
555 void	exit(), setbuf();
556 long	ulimit();
557 #else /* !ATTSV */
558 int	sleep(), exit(), setbuf(), ftime();
559 #endif
560 
561 #ifdef UNAME
562 #include <sys/utsname.h>
563 #endif /* UNAME */
564 
565 #ifndef NOUSTAT
566 #ifdef V7USTAT
567 struct  ustat {
568 	daddr_t	f_tfree;	/* total free */
569 	ino_t	f_tinode;	/* total inodes free */
570 };
571 #else /* !NOUSTAT && !V7USTAT */
572 #include <ustat.h>
573 #endif /* V7USTAT */
574 #endif /* NOUSTAT */
575 
576 #ifdef BSD4_2
577 char *gethostname();
578 #endif /* BSD4_2 */
579 
580 /* messages */
581 EXTERN char *Ct_OPEN;
582 EXTERN char *Ct_WRITE;
583 EXTERN char *Ct_READ;
584 EXTERN char *Ct_CREATE;
585 EXTERN char *Ct_ALLOCATE;
586 EXTERN char *Ct_LOCK;
587 EXTERN char *Ct_STAT;
588 EXTERN char *Ct_CHOWN;
589 EXTERN char *Ct_CHMOD;
590 EXTERN char *Ct_LINK;
591 EXTERN char *Ct_CHDIR;
592 EXTERN char *Ct_UNLINK;
593 EXTERN char *Wr_ROLE;
594 EXTERN char *Ct_CORRUPT;
595 EXTERN char *Ct_FORK;
596 EXTERN char *Ct_CLOSE;
597 EXTERN char *Ct_BADOWN;
598 EXTERN char *Fl_EXISTS;
599 
600 #ifdef __cplusplus
601 }
602 #endif
603 
604 #endif /* _UUCP_H */
605