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