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
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.
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]
23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
34 #pragma ident "%Z%%M% %I% %E% SMI"
49 #include <sys/types.h>
79 #undef NONAP /* conn.c has a nap() for 4.2 -- it's called select() */
96 #include <sys/param.h>
99 * param.h includes types.h and signal.h in 4bsd
106 #endif /* ATTSVTTY */
107 #include <sys/timeb.h>
113 #include <sys/types.h>
118 #include <sys/stat.h>
123 #include <sys/time.h>
128 #include <sys/times.h>
133 #include <sys/mkdev.h>
135 #include <sys/sysmacros.h>
140 #include "rt/types.h"
141 #include "rt/unix/param.h"
143 #include <sys/ustat.h>
146 #include <sysexits.h>
152 /* what mode should user files be allowed to have upon creation? */
153 /* NOTE: This does not allow setuid or execute bits on transfer. */
154 #define LEGALMODE (mode_t) 0666
156 /* what mode should public files have upon creation? */
157 #define PUB_FILEMODE (mode_t) 0666
159 /* what mode should log files have upon creation? */
160 #define LOGFILEMODE (mode_t) 0644
162 /* what mode should C. files have upon creation? */
163 #define CFILEMODE (mode_t) 0644
165 /* what mode should D. files have upon creation? */
166 #define DFILEMODE (mode_t) 0600
168 /* define the value of PUBMASK, used for creating "public" directories */
169 #define PUBMASK (mode_t) 0000
171 /* what mode should public directories have upon creation? */
172 #define PUB_DIRMODE (mode_t) 0777
174 /* define the value of DIRMASK, used for creating "system" subdirectories */
175 #define DIRMASK (mode_t) 0022
177 #define MAXSTART 300 /* how long to wait on startup */
179 /* define the last characters for ACU (used for 801/212 dialers) */
182 /* caution - the fillowing names are also in Makefile
183 * any changes here have to also be made there
185 * it's a good idea to make directories .foo, since this ensures
186 * that they'll be ignored by processes that search subdirectories in SPOOL
188 * XQTDIR=/var/uucp/.Xqtdir
189 * CORRUPT=/var/uucp/.Corrupt
190 * LOGDIR=/var/uucp/.Log
191 * SEQDIR=/var/uucp/.Sequence
192 * STATDIR=/var/uucp/.Status
196 /* where to put the STST. files? */
197 #define STATDIR "/var/uucp/.Status"
199 /* where should logfiles be kept? */
200 #define LOGUUX "/var/uucp/.Log/uux"
201 #define LOGUUXQT "/var/uucp/.Log/uuxqt"
202 #define LOGUUCP "/var/uucp/.Log/uucp"
203 #define LOGCICO "/var/uucp/.Log/uucico"
205 /* some sites use /var/uucp/.Corrupt and /var/uucp/.Xqtdir here */
206 /* use caution since things are linked into there from /var/spool/uucp */
207 #define CORRUPTDIR "/var/spool/uucp/.Corrupt"
208 #define XQTDIR "/var/spool/uucp/.Xqtdir"
210 /* how much of a system name can we print in a [CX]. file? */
211 /* MAXBASENAME - 1 (pre) - 1 ('.') - 1 (grade) - 4 (sequence number) */
212 #define SYSNSIZE (MAXBASENAME - 7)
215 #define LOCKPRE "/var/spool/locks/LCK."
216 #else /*!USRSPOOLLOCKS*/
217 #define LOCKPRE "/var/spool/uucp/LCK."
218 #endif /* USRSPOOLLOCKS */
220 #define SQFILE "/etc/uucp/SQFILE"
221 #define SQTMP "/etc/uucp/SQTMP"
222 #define SLCKTIME 5400 /* system/device timeout (LCK.. files) */
223 #define DIALCODES "/etc/uucp/Dialcodes"
224 #define PERMISSIONS "/etc/uucp/Permissions"
225 #define SYSNAMEFILE "/etc/uucp/Sysname"
227 #define SPOOL "/var/spool/uucp"
228 #define SEQDIR "/var/uucp/.Sequence"
230 #define X_LOCKTIME 3600
232 #define SEQLOCK "/var/spool/locks/LCK.SQ."
233 #define SQLOCK "/var/spool/locks/LCK.SQ"
234 #define X_LOCK "/var/spool/locks/LCK.X"
235 #define S_LOCK "/var/spool/locks/LCK.S"
236 #define L_LOCK "/var/spool/locks/LK"
237 #define X_LOCKDIR "/var/spool/locks" /* must be dir part of above */
238 #else /*!USRSPOOLLOCKS*/
239 #define SEQLOCK "/var/spool/uucp/LCK.SQ."
240 #define SQLOCK "/var/spool/uucp/LCK.SQ"
241 #define X_LOCK "/var/spool/uucp/LCK.X"
242 #define S_LOCK "/var/spool/uucp/LCK.S"
243 #define L_LOCK "/var/spool/uucp/LK"
244 #define X_LOCKDIR "/var/spool/uucp" /* must be dir part of above */
245 #endif /* USRSPOOLLOCKS */
246 #define X_LOCKPRE "LCK.X" /* must be last part of above */
247 #define S_LOCKPRE "LCK.S"
250 * Note: this should be "/usr/spool/uucppublic", not "/var/spool/uucppublic",
251 * because if a Permissions file entry doesn't explicitly list directories to
252 * which and from which files can be copied you can only copy files to and from
253 * PUBDIR, and most systems out there will think PUBDIR is
254 * "/usr/spool/uucppublic" not "/var/spool/uucppublic" (i.e., if you change
255 * this, other systems may be rudely surprised when they try to get things from
258 #define PUBDIR "/usr/spool/uucppublic"
259 #define ADMIN "/var/uucp/.Admin"
260 #define ERRLOG "/var/uucp/.Admin/errors"
261 #define SYSLOG "/var/uucp/.Admin/xferstats"
262 #define RMTDEBUG "/var/uucp/.Admin/audit"
263 #define CLEANUPLOGFILE "/var/uucp/.Admin/uucleanup"
264 #define CMDLOG "/var/uucp/.Admin/command"
265 #define PERFLOG "/var/uucp/.Admin/perflog"
266 #define ACCOUNT "/var/uucp/.Admin/account"
267 #define SECURITY "/var/uucp/.Admin/security"
270 * WORKSPACE should be in the same filesystem as SPOOL so that "mv"
271 * between the two will work. Otherwise, the file must be copied
272 * and a window exists during which the file is mode 666.
274 #define WORKSPACE "/var/spool/uucp/.Workspace"
277 #define TRYCALLS 2 /* number of tries to dial call */
278 #define MINULIMIT (1L<<11) /* minimum reasonable ulimit */
279 #define MAX_LOCKTRY 5 /* number of attempts to lock device */
282 * CDEBUG is for communication line debugging
283 * DEBUG is for program debugging
284 * #define SMALL to compile without the DEBUG code
288 #define CDEBUG(l, f, s) if (Debug >= l) fprintf(stderr, f, s)
290 #define CDEBUG(l, f, s)
295 #define DEBUG(l, f, s) if (Debug >= l) fprintf(stderr, f, s)
297 #define DEBUG(l, f, s)
301 * VERBOSE is used by cu and ct to inform the user of progress
302 * In other programs, the Value of Verbose is always 0.
304 #define VERBOSE(f, s) { if (Verbose > 0) fprintf(stderr, f, s); }
306 #define PREFIX(pre, str) (strncmp((pre), (str), strlen(pre)) == SAME)
307 #define BASENAME(str, c) ((Bnptr = strrchr((str), c)) ? (Bnptr + 1) : (str))
308 #define EQUALS(a,b) ((a != CNULL) && (b != CNULL) && (strcmp((a),(b))==SAME))
309 #define WEQUALS(a,b) ((a != CNULL) && (b != CNULL) && (wcscmp((a),(b))==SAME))
310 #define EQUALSN(a,b,n) ((a != CNULL) && (b != CNULL) && (strncmp((a),(b),(n))==SAME))
311 #define WEQUALSN(a,b,n) ((a != CNULL) && (b != CNULL) && (wcsncmp((a),(b),(n))==SAME))
312 #define LASTCHAR(s) (s+strlen(s)-1)
319 #define NULLCHAR '\0'
320 #define CNULL ((void *) 0)
321 #define STBNULL (struct sgttyb *) 0
324 #define MAXBASENAME 14 /* should be DIRSIZ but that is now fs dependent */
325 #define MAXFULLNAME BUFSIZ
326 #define MAXNAMESIZE 64 /* /var/spool/uucp/<14 chars>/<14 chars>+slop */
327 #define CONNECTTIME 30
328 #define EXPECTTIME 45
330 #define NAMESIZE MAXBASENAME+1
331 #define SIZEOFPID 10 /* maximum number of digits in a pid */
332 #define EOTMSG "\004\n\004\n"
335 /* manifests for sysfiles.c's sysaccess() */
336 /* check file access for REAL user id */
337 #define ACCESS_SYSTEMS 1
338 #define ACCESS_DEVICES 2
339 #define ACCESS_DIALERS 3
340 /* check file access for EFFECTIVE user id */
341 #define EACCESS_SYSTEMS 4
342 #define EACCESS_DEVICES 5
343 #define EACCESS_DIALERS 6
345 /* manifest for chkpth flag */
352 #define SHELL "/usr/bin/sh"
354 #define UUCICO "/usr/lib/uucp/uucico"
355 #define UUXQT "/usr/lib/uucp/uuxqt"
356 #define UUX "/usr/bin/uux"
357 #define UUCP "/usr/bin/uucp"
360 /* system status stuff */
362 #define SS_NO_DEVICE 1
363 #define SS_TIME_WRONG 2
364 #define SS_INPROGRESS 3
365 #define SS_CONVERSATION 4
367 #define SS_LOGIN_FAILED 6
368 #define SS_DIAL_FAILED 7
369 #define SS_BAD_LOG_MCH 8
370 #define SS_LOCKED_DEVICE 9
371 #define SS_ASSERT_ERROR 10
372 #define SS_BADSYSTEM 11
373 #define SS_CANT_ACCESS_DEVICE 12
374 #define SS_DEVICE_FAILED 13 /* used for interface failure */
375 #define SS_WRONG_MCH 14
376 #define SS_CALLBACK 15
377 #define SS_RLOCKED 16
378 #define SS_RUNKNOWN 17
380 #define SS_UNKNOWN_RESPONSE 19
381 #define SS_STARTUP 20
382 #define SS_CHAT_FAILED 21
383 #define SS_CALLBACK_LOOP 22
385 #define MAXPH 60 /* maximum phone string size */
392 /* The call structure is used by ct.c, cu.c, and dial.c. */
395 char *speed
; /* transmission baud rate */
396 char *line
; /* device name for outgoing line */
397 char *telno
; /* ptr to tel-no digit string */
398 char *type
; /* type of device to use for call. */
401 /* structure of an Systems file line */
402 #define F_MAX 50 /* max number of fields in Systems file line */
406 #define F_CLASS 3 /* an optional prefix and the speed */
410 /* structure of an Devices file line */
417 #define D_MAX 50 /* max number of fields in Devices file line */
423 #define GRADES "/etc/uucp/Grades"
425 #define D_QUEUE 'Z' /* default queue */
427 /* past here, local changes are not recommended */
433 * stuff for command execution
435 #define X_RQDFILE 'F'
441 #define X_BRINGBACK 'B'
443 #define X_RETADDR 'R'
444 #define X_COMMENT '#'
445 #define X_NONZERO 'Z'
446 #define X_SENDNOTHING 'N'
447 #define X_SENDZERO 'n'
451 /* This structure describes call routines */
457 /* structure for a saved C file */
461 char sys
[NAMESIZE
+5];
462 char sgrade
[NAMESIZE
];
467 /* This structure describes dialing routines */
474 pid_t t_pid
; /* process id */
475 time_t t_start
; /* start time */
476 time_t t_scall
; /* start call to system */
477 time_t t_ecall
; /* end call to system */
478 time_t t_tacu
; /* acu time */
479 time_t t_tlog
; /* login time */
480 time_t t_sftp
; /* start file transfer protocol */
481 time_t t_sxf
; /* start xfer */
482 time_t t_exf
; /* end xfer */
483 time_t t_eftp
; /* end file transfer protocol */
484 time_t t_qtime
; /* time file queued */
485 int t_ndial
; /* # of dials */
486 int t_nlogs
; /* # of login trys */
487 struct tms t_tbb
; /* start execution times */
488 struct tms t_txfs
; /* xfer start times */
489 struct tms t_txfe
; /* xfer end times */
490 struct tms t_tga
; /* garbage execution times */
493 /* This structure describes the values from Limits file */
495 int totalmax
; /* overall limit */
496 int sitemax
; /* limit per site */
497 char mode
[64]; /* uucico mode */
500 /* external declarations */
502 EXTERN
ssize_t (*Read
)(), (*Write
)();
503 #if defined(__STDC__)
504 EXTERN
int (*Ioctl
)(int,int,...);
506 EXTERN
int (*Ioctl
)();
509 EXTERN
int Debug
, Verbose
;
510 EXTERN uid_t Uid
, Euid
; /* user-id and effective-uid */
512 EXTERN mode_t Dev_mode
; /* save device mode here */
513 EXTERN
char Wrkdir
[];
514 EXTERN
long Retrytime
;
518 EXTERN
struct nstat Nstat
;
519 EXTERN
char Dc
[]; /* line name */
520 EXTERN
int Seqn
; /* sequence # */
522 EXTERN
int Sgrades
; /* flag for administrator defined service grades */
524 EXTERN
char Logfile
[MAXFULLNAME
];
525 EXTERN
char Rmtname
[MAXFULLNAME
];
526 EXTERN
char JobGrade
[MAXBASENAME
+1];
527 EXTERN
char User
[MAXFULLNAME
];
528 EXTERN
char Loginuser
[NAMESIZE
];
531 EXTERN
char Myname
[];
532 EXTERN
char Progname
[];
533 EXTERN
char RemSpool
[];
534 EXTERN
char *Bnptr
; /* used when BASENAME macro is expanded */
535 EXTERN
char *Shchar
; /* shell meta-charaters */
536 EXTERN
int SizeCheck
; /* ulimit check supported flag */
537 EXTERN
long RemUlimit
; /* remote ulimit if supported */
538 EXTERN
int Restart
; /* checkpoint restart supported flag */
540 EXTERN
char Jobid
[NAMESIZE
]; /* Jobid of current C. file */
541 EXTERN
int Uerror
; /* global error code */
542 EXTERN
char *UerrorText
[]; /* text for error code */
544 #define UERRORTEXT UerrorText[Uerror]
545 #define UTEXT(x) UerrorText[x]
547 /* things get kind of tricky beyond this point -- please stay out */
551 #define rindex strrchr
554 #define strrchr rindex
558 #define memcpy(s1,s2,n) bcopy(s2,s1,n)
563 extern char *memcpy();
567 EXTERN
struct stat __s_
;
568 #define F_READANY(f) ((fstat((f),&__s_)==0) && ((__s_.st_mode&(0004))!=0) )
569 #define READANY(f) ((stat((f),&__s_)==0) && ((__s_.st_mode&(0004))!=0) )
571 #define WRITEANY(f) ((stat((f),&__s_)==0) && ((__s_.st_mode&(0002))!=0) )
572 #define DIRECTORY(f) ((stat((f),&__s_)==0) && ((__s_.st_mode&(S_IFMT))==S_IFDIR) )
573 #define NOTEMPTY(f) ((stat((f),&__s_)==0) && (__s_.st_size!=0) )
575 /* uucp functions and subroutine */
576 EXTERN
void (*genbrk
)();
577 extern int iswrk(), gtwvec(); /* anlwrk.c */
578 extern void findgrade(); /* grades.c */
579 extern void chremdir(), mkremdir(); /* chremdir.c */
580 extern void toCorrupt(); /* cpmv.c */
581 extern int xmv(); /* cpmv.c */
583 EXTERN
int getargs(); /* getargs.c */
584 EXTERN
void bsfix(); /* getargs.c */
585 extern char *_uu_setlocale(); /* getargs.c */
586 extern void _uu_resetlocale(); /* getargs.c */
587 extern char *getprm(); /* getprm.c */
589 extern char *next_token(); /* permission.c */
590 extern char *nextarg(); /* permission.c */
591 extern int getuline(); /* permission.c */
593 EXTERN
void logent(), usyslog(), ucloselog(); /* logent.c */
594 extern void commandlog(); /* logent.c */
595 extern time_t millitick(); /* logent.c */
597 extern unsigned long getfilesize(); /* statlog.c */
598 extern void putfilesize(); /* statlog.c */
600 EXTERN
char *protoString(); /* permission.c */
601 extern int logFind(), mchFind(); /* permission.c */
602 extern int chkperm(), chkpth(); /* permission.c */
603 extern int cmdOK(), switchRole(); /* permission.c */
604 extern int callBack(), requestOK(); /* permission.c */
605 extern int noSpool(); /* permission.c */
606 extern void myName(); /* permission.c */
608 extern int mkdirs(); /* expfile.c */
609 extern int scanlimit(); /* limits.c */
610 extern void systat(); /* systat.c */
611 EXTERN
int fd_mklock(), fd_cklock(); /* ulockf.c */
612 EXTERN
int fn_cklock(); /* ulockf.c */
613 EXTERN
int mklock(), cklock(), umlock(); /* ulockf.c */
614 EXTERN
void fd_rmlock(), delock(), rmlock(); /* ulockf.c */
615 extern char *timeStamp(); /* utility.c */
616 EXTERN
void assert(), errent(); /* utility.c */
617 extern void uucpname(); /* uucpname.c */
618 extern int versys(); /* versys.c */
619 extern void xuuxqt(), xuucico(); /* xqt.c */
620 EXTERN
void cleanup(); /* misc main.c */
622 #define ASSERT(e, s1, s2, i1) if (!(e)) {\
623 assert(s1, s2, i1, __FILE__, __LINE__);\
629 int setbuf(), ftime();
634 #include <sys/utsname.h>
640 daddr_t f_tfree
; /* total free */
641 ino_t f_tinode
; /* total inodes free */
643 #else /* !NOUSTAT && !V7USTAT */
657 EXTERN
char *Ct_OPEN
;
658 EXTERN
char *Ct_WRITE
;
659 EXTERN
char *Ct_READ
;
660 EXTERN
char *Ct_CREATE
;
661 EXTERN
char *Ct_ALLOCATE
;
662 EXTERN
char *Ct_LOCK
;
663 EXTERN
char *Ct_STAT
;
664 EXTERN
char *Ct_CHOWN
;
665 EXTERN
char *Ct_CHMOD
;
666 EXTERN
char *Ct_LINK
;
667 EXTERN
char *Ct_CHDIR
;
668 EXTERN
char *Ct_UNLINK
;
669 EXTERN
char *Wr_ROLE
;
670 EXTERN
char *Ct_CORRUPT
;
671 EXTERN
char *Ct_FORK
;
672 EXTERN
char *Ct_CLOSE
;
673 EXTERN
char *Ct_BADOWN
;
674 EXTERN
char *Fl_EXISTS
;