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