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