3 * mts.c -- definitions for the mail transport system
8 #include "h/mh.h" /* for snprintf() */
11 #define nmhetcdir(file) NMHETCDIR#file
19 #ifdef HAVE_SYS_UTSNAME_H
20 # include <sys/utsname.h>
31 static char *tailor_value (char *);
32 static void getuserinfo (void);
35 * *mmdfldir and *uucpldir are the maildrop directories. If maildrops
36 * are kept in the user's home directory, then these should be empty
37 * strings. In this case, the appropriate ...lfil array should contain
38 * the name of the file in the user's home directory. Usually, this is
39 * something like ".mail".
43 * nmh mail transport interface customization file
45 static char *mtsconf = nmhetcdir(/mts.conf);
47 static char *localname = "";
48 static char *localdomain = "";
49 static char *systemname = "";
51 char *mmdfldir = MAILSPOOL;
53 char *uucpldir = "/usr/spool/mail";
56 char *mmdlm1 = "\001\001\001\001\n";
57 char *mmdlm2 = "\001\001\001\001\n";
59 /* Cache the username and fullname of the user */
60 static char username[BUFSIZ];
61 static char fullname[BUFSIZ];
63 /* variables for username masquerading */
64 int MMailids = 0; /* used from post.c as well as here */
65 static char *mmailid = "0";
69 * MTS specific variables
71 #if defined(SENDMTS) || defined(SMTPMTS)
72 char *hostable = nmhetcdir(/hosts);
73 char *sendmail = SENDMAILPATH;
79 char *clientname = NULL;
80 char *servers = "localhost \01localnet";
84 * BBoards-specific variables
90 * POP BBoards-specific variables
95 char *popbblist = nmhetcdir(/hosts.popbb);
99 * Global MailDelivery file
101 char *maildelivery = nmhetcdir(/maildelivery);
105 * Aliasing Facility (doesn't belong here)
107 int Everyone = NOTOK;
108 static char *everyone = "-1";
112 * Customize the MTS settings for nmh by adjusting
113 * the file mts.conf in the nmh etc directory.
121 static struct bind binds[] = {
122 { "localname", &localname },
123 { "localdomain", &localdomain },
124 { "systemname", &systemname },
125 { "mmdfldir", &mmdfldir },
126 { "mmdflfil", &mmdflfil },
127 { "uucpldir", &uucpldir },
128 { "uucplfil", &uucplfil },
129 { "mmdelim1", &mmdlm1 },
130 { "mmdelim2", &mmdlm2 },
131 { "mmailid", &mmailid },
133 #if defined(SENDMTS) || defined(SMTPMTS)
134 { "hostable", &hostable },
138 { "sendmail", &sendmail },
141 { "clientname", &clientname },
142 { "servers", &servers },
143 { "pophost", &pophost },
144 { "bbdomain", &bb_domain },
147 { "popbbhost", &popbbhost },
148 { "popbbuser", &popbbuser },
149 { "popbblist", &popbblist },
153 { "nntphost", &popbbhost },
156 { "maildelivery", &maildelivery },
157 { "everyone", &everyone },
158 { "noshell", &NoShell },
164 * Read the configuration file for the nmh interface
165 * to the mail transport system (MTS).
169 mts_init (char *name)
171 char *bp, *cp, buffer[BUFSIZ];
174 static int inited = 0;
176 if (inited++ || (fp = fopen (mtsconf, "r")) == NULL)
179 while (fgets (buffer, sizeof(buffer), fp)) {
180 if (!(cp = strchr(buffer, '\n')))
183 if (*buffer == '#' || *buffer == '\0')
185 if (!(bp = strchr(buffer, ':')))
188 while (isspace (*bp))
191 for (b = binds; b->keyword; b++)
192 if (!strcmp (buffer, b->keyword))
194 if (b->keyword && (cp = tailor_value (bp)))
199 MMailids = atoi (mmailid);
200 Everyone = atoi (everyone);
207 * Convert escaped values, malloc some new space,
208 * and copy string to malloc'ed memory.
212 tailor_value (char *s)
219 for (bp = buffer; *s; bp++, s++) {
224 case 'b': *bp = '\b'; break;
225 case 'f': *bp = '\f'; break;
226 case 'n': *bp = '\n'; break;
227 case 't': *bp = '\t'; break;
239 r = *s != '0' ? 10 : 8;
240 for (i = 0; isdigit (*s); s++)
241 i = i * r + *s - '0';
250 len = strlen (buffer) + 1;
251 if ((bp = malloc (len)))
252 memcpy (bp, buffer, len);
258 * Get the fully qualified name of the local host.
264 static char buffer[BUFSIZ] = "";
271 /* check if we have cached the local name */
277 /* check if the mts.conf file specifies a "localname" */
279 strncpy (buffer, localname, sizeof(buffer));
282 /* first get our local name */
284 strncpy (buffer, name.nodename, sizeof(buffer));
286 /* first get our local name */
287 gethostname (buffer, sizeof(buffer));
289 #ifdef HAVE_SETHOSTENT
292 /* now fully qualify our name */
293 if ((hp = gethostbyname (buffer)))
294 strncpy (buffer, hp->h_name, sizeof(buffer));
298 * If the mts.conf file specifies a "localdomain",
299 * we append that now. This should rarely be needed.
302 strcat (buffer, ".");
303 strcat (buffer, localdomain);
311 * This is only for UUCP mail. It gets the hostname
312 * as part of the UUCP "domain".
318 static char buffer[BUFSIZ] = "";
324 /* check if we have cached the system name */
330 /* check if mts.conf file specifies a "systemname" */
332 strncpy (buffer, systemname, sizeof(buffer));
338 strncpy (buffer, name.nodename, sizeof(buffer));
340 gethostname (buffer, sizeof(buffer));
348 * Get the username of current user
354 if (username[0] == '\0')
362 * Get full name of current user (typically from GECOS
363 * field of password file).
369 if (username[0] == '\0')
377 * Find the user's username and full name, and cache them.
378 * Also, handle "mmailid" username masquerading controlled from the GECOS field
379 * of the passwd file.
385 register char *cp, *np;
386 register struct passwd *pw;
392 if (uid == geteuid () && (cp = getenv ("USER")) != NULL
393 && (pw = getpwnam (cp)) != NULL)
394 strncpy (username, cp, sizeof(username));
395 else if ((pw = getpwuid (uid)) == NULL
396 || pw->pw_name == NULL
397 || *pw->pw_name == '\0') {
399 if ((pw = getpwuid (getuid ())) == NULL
400 || pw->pw_name == NULL
401 || *pw->pw_name == '\0') {
404 strncpy (username, "unknown", sizeof(username));
405 snprintf (fullname, sizeof(fullname), "The Unknown User-ID (%d)",
413 * Do mmailid (username masquerading) processing. The GECOS
414 * field should have the form "Full Name <fakeusername>". For instance,
415 * "Dan Harkless <Dan.Harkless>". Naturally, you'll want your MTA to have
416 * an alias (e.g. in /etc/aliases) from "fakeusername" to your account name.
419 /* What is this code here for? As of 2000-01-25, GCOS_HACK doesn't appear
420 anywhere else in nmh. -- Dan Harkless <dan-nmh@dilvish.speed.net> */
421 for (cp = fullname; *np && *np != (MMailids ? '<' : ','); *cp++ = *np++)
424 for (cp = fullname; *np && *np != (MMailids ? '<' : ','); ) {
425 if (*np == '&') { /* blech! */
426 strcpy (cp, pw->pw_name);
441 for (cp = username; *np && *np != '>'; *cp++ = *np++)
445 if (MMailids == 0 || *np == '\0')
446 strncpy (username, pw->pw_name, sizeof(username));
448 if ((cp = getenv ("SIGNATURE")) && *cp)
449 strncpy (fullname, cp, sizeof(fullname));
451 if (strchr(fullname, '.')) { /* quote any .'s */
454 /* should quote "'s too */
455 snprintf (tmp, sizeof(tmp), "\"%s\"", fullname);
456 strncpy (fullname, tmp, sizeof(fullname));