1 /* mts.c - definitions for the mail transport system */
3 static char ident[] = "@(#)$Id: mts.c,v 2.20 1994/03/23 23:35:23 jromine Exp $";
9 #if defined(BSD41A) || defined(BSD42) || defined(SOCKETS)
13 #include "../h/strings.h"
18 #if defined(BSD42) || defined(SOCKETS)
25 #include <sys/utsname.h>
34 #define NULLCP ((char *) 0)
38 static char *tailor_value ();
41 #if defined(SYS5) && !defined(_AIX)
43 #define rindex strrchr
46 #if !defined(__STDC__) && !defined(_AIX) && !defined(_POSIX_SOURCE)
47 char *index (), *malloc (), *mktemp (), *rindex (), *strcpy ();
50 struct passwd *getpwuid ();
52 #endif /* !__STDC__ */
57 *mmdfldir and *uucpldir are the maildrop directories. If maildrops
58 are kept in the user's home directory, then these should be empty
59 strings. In this case, the appropriate ...lfil array should contain
60 the name of the file in the user's home directory. Usually, this is
61 something like ".mail".
64 static char *mtstailor = "/opt/mh-6.8.5/lib/mtstailor";
66 static char *localname = "";
67 static char *localdomain = "";
68 static char *systemname = "";
70 static char *UUCPchan = "";
72 char *mmdfldir = "/var/spool/mail";
74 char *uucpldir = "/usr/spool/mail";
78 char *mmdlm1 = "\001\001\001\001\n";
79 char *mmdlm2 = "\001\001\001\001\n";
82 static int MMailids = 0;
83 static char *mmailid = "0";
87 char *umincproc = "/opt/mh-6.8.5/lib/uminc";
89 char *umincproc = NULL;
93 int lockstyle = LOK_UNIX;
94 static char *lkstyle = "0";
99 /* MTS specific variables */
102 char *Mailqdir = "/usr/spool/netmail";
103 char *TMailqdir = "/usr/tmp";
105 static char *syscpy = "1";
106 char *Overseer = "root";
107 char *Mailer = "root";
108 char *Fromtmp = "/tmp/rml.f.XXXXXX";
109 char *Msgtmp = "/tmp/rml.m.XXXXXX";
110 char *Errtmp = "/tmp/rml.e.XXXXXX";
112 static char *tmpmode = "0600";
113 char *Okhosts = "/opt/mh-6.8.5/lib/Rmail.OkHosts";
114 char *Okdests = "/opt/mh-6.8.5/lib/Rmail.OkDests";
121 char *hostable = "/opt/mh-6.8.5/lib/hosts";
122 char *sendmail = "/usr/lib/sendmail";
128 char *clientname = (char *)0;
129 char *servers = "localhost \01localnet";
133 /* BBoards-specific variables */
135 char *bb_domain = "";
138 /* POP BBoards-specific variables */
141 char *popbbhost = "";
142 char *popbbuser = "";
143 char *popbblist = "/opt/mh-6.8.5/lib/hosts.popbb";
149 char *maildelivery = "/opt/mh-6.8.5/lib/maildelivery";
152 /* Aliasing Facility (doesn't belong here) */
154 int Everyone = NOTOK;
155 static char *everyone = "-1";
160 /* customize the MTS settings for MH by reading /opt/mh-6.8.5/lib/mtstailor */
166 "localname", &localname,
167 "localdomain", &localdomain,
168 "systemname", &systemname,
170 "uucpchan", &UUCPchan,
172 "mmdfldir", &mmdfldir,
173 "mmdflfil", &mmdflfil,
174 "uucpldir", &uucpldir,
175 "uucplfil", &uucplfil,
179 "umincproc", &umincproc,
180 "lockstyle", &lkstyle,
181 "lockldir", &lockldir,
184 "mailqdir", &Mailqdir,
185 "tmailqdir", &TMailqdir,
187 "overseer", &Overseer,
201 "hostable", &hostable,
202 "sendmail", &sendmail,
205 "clientname", &clientname,
209 "bbdomain", &bb_domain,
212 "popbbhost", &popbbhost,
213 "popbbuser", &popbbuser,
214 "popbblist", &popbblist,
217 "nntphost", &popbbhost,
220 "maildelivery", &maildelivery,
222 "everyone", &everyone,
230 /* I'd like to use m_getfld() here, but not all programs loading mts.o may be
231 MH-style programs... */
241 register struct bind *b;
243 static int inited = 0;
245 if (inited++ || (fp = fopen (mtstailor, "r")) == NULL)
248 while (fgets (buffer, sizeof buffer, fp)) {
249 if ((cp = index (buffer, '\n')) == NULL)
252 if (*buffer == '#' || *buffer == '\0')
254 if ((bp = index (buffer, ':')) == NULL)
257 while (isspace (*bp))
260 for (b = binds; b -> keyword; b++)
261 if (strcmp (buffer, b -> keyword) == 0)
263 if (b -> keyword && (cp = tailor_value (bp)))
269 MMailids = atoi (mmailid);
270 if ((lockstyle = atoi (lkstyle)) < LOK_UNIX || lockstyle > LOK_MMDF)
271 lockstyle = LOK_UNIX;
273 Syscpy = atoi (syscpy);
274 (void) sscanf (tmpmode, "0%o", &Tmpmode);
276 Everyone = atoi (everyone);
283 static char *tailor_value (s)
291 for (bp = buffer; *s; bp++, s++)
296 #define grot(y,z) case y: *bp = z; break;
313 r = *s != '0' ? 10 : 8;
314 for (i = 0; isdigit (*s); s++)
315 i = i * r + *s - '0';
322 bp = malloc ((unsigned) (strlen (buffer) + 1));
324 (void) strcpy (bp, buffer);
335 #if defined(BSD42) || defined(SOCKETS)
336 register struct hostent *hp;
337 #endif /* BSD42 or SOCKETS */
338 #if defined(SYS5) && !defined(NETWORK)
340 #endif /* SYS5 and not NETWORK */
341 static char buffer[BUFSIZ] = "";
348 strcpy (buffer, localname);
352 (void) strcpy (buffer, locname);
353 #else /* not locname */
357 if (rhost (&myname) == -1)
358 (void) gethostname (buffer, sizeof buffer);
360 (void) strcpy (buffer, myname);
364 #if defined(BSD42) || defined(SOCKETS)
365 (void) gethostname (buffer, sizeof buffer);
369 if (hp = gethostbyname (buffer))
370 (void) strcpy (buffer, hp -> h_name);
371 #endif /* BSD42 or SOCKETS */
372 #else /* not NETWORK */
374 (void) strcpy (buffer, SystemName ());
376 (void) uname (&name);
377 (void) strcpy (buffer, name.nodename);
379 #endif /* not NETWORK */
380 #endif /* not locname */
383 strcat (buffer, ".");
384 strcat (buffer, localdomain);
391 char *SystemName () {
392 #if defined(SYS5) && !defined(NETWORK)
394 #endif /* SYS5 and not NETWORK */
395 static char buffer[BUFSIZ] = "";
402 return strcpy (buffer, systemname);
405 (void) strcpy (buffer, sysname);
407 #if !defined(SYS5) || defined(NETWORK)
408 (void) gethostname (buffer, sizeof buffer);
409 #else /* SYS5 and not NETWORK */
411 (void) uname (&name);
412 (void) strcpy (buffer, name.nodename);
414 #endif /* SYS5 and not NETWORK */
424 static char buffer[BUFSIZ] = "";
435 return strcpy (buffer, UUCPchan);
438 (void) strcpy (buffer, uucpchan);
440 (void) strcpy (buffer, "uucp");
441 #endif /* uucpchan */
449 gethostname (name, len)
456 if (fp = fopen ("/etc/systemid", "r")) {
457 if (fgets (name, len, fp)) {
458 if (cp = index (name, '\n'))
465 (void) strncpy (name, "altos", len);
473 static char username[BUFSIZ];
474 static char fullname[BUFSIZ];
483 register struct passwd *pw;
489 if ((pw = getpwuid (getuid ())) == NULL
490 || pw -> pw_name == NULL
491 || *pw -> pw_name == NULL) {
494 if (uid == geteuid () && (cp = getenv ("USER")) != NULL
495 && (pw = getpwnam (cp)) != NULL)
496 strcpy (username, cp);
497 else if ((pw = getpwuid (uid)) == NULL
498 || pw -> pw_name == NULL
499 || *pw -> pw_name == '\0') {
501 (void) strcpy (username, "unknown");
502 (void) sprintf (fullname, "The Unknown User-ID (%d)", getuid ());
508 for (cp = fullname; *np && *np != (MMailids ? '<' : ','); *cp++ = *np++)
511 for (cp = fullname; *np && *np != (MMailids ? '<' : ','); )
512 if (*np == '&') { /* blech! */
513 (void) strcpy(cp, pw -> pw_name);
526 for (cp = username; *np && *np != '>'; *cp++ = *np++)
530 if (MMailids == 0 || *np == '\0')
531 (void) strcpy (username, pw -> pw_name);
533 if ((cp = getenv ("SIGNATURE")) && *cp)
534 (void) strcpy (fullname, cp);
535 if (index(fullname, '.')) { /* quote any .'s */
537 sprintf (tmp, "\"%s\"", fullname);/* should quote "'s too */
538 strcpy (fullname, tmp);
545 char *getfullname () {
546 if (username[0] == '\0')
555 #ifndef notdef /* Supposedly this works, I prefer the
556 recursive solution... */
570 if ((d = fcntl (d1, F_DUPFD, d2)) == NOTOK)
588 return dup2aux (d1, d2);
592 static int dup2aux (d1, d2)
600 if ((d = dup (d1)) == NOTOK)
605 i = dup2aux (d1, d2);