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