]>
diplodocus.org Git - nmh/blob - zotnet/mts/mts.c
3 * mts.c -- definitions for the mail transport system
10 #define nmhetcdir(file) NMHETCDIR#file
18 #ifdef HAVE_SYS_UTSNAME_H
19 # include <sys/utsname.h>
30 static char *tailor_value (char *);
31 static void getuserinfo (void);
34 * *mmdfldir and *uucpldir are the maildrop directories. If maildrops
35 * are kept in the user's home directory, then these should be empty
36 * strings. In this case, the appropriate ...lfil array should contain
37 * the name of the file in the user's home directory. Usually, this is
38 * something like ".mail".
42 * nmh mail transport interface customization file
44 static char *mtsconf
= nmhetcdir(/mts
.conf
);
46 static char *localname
= "";
47 static char *localdomain
= "";
48 static char *systemname
= "";
50 char *mmdfldir
= MAILSPOOL
;
52 char *uucpldir
= "/usr/spool/mail";
55 char *mmdlm1
= "\001\001\001\001\n";
56 char *mmdlm2
= "\001\001\001\001\n";
58 /* Cache the username and fullname of the user */
59 static char username
[BUFSIZ
];
60 static char fullname
[BUFSIZ
];
62 /* variables for username masquerading */
63 static int MMailids
= 0;
64 static char *mmailid
= "0";
68 * MTS specific variables
70 #if defined(SENDMTS) || defined(SMTPMTS)
71 char *hostable
= nmhetcdir(/hosts
);
72 char *sendmail
= SENDMAILPATH
;
78 char *clientname
= NULL
;
79 char *servers
= "localhost \01localnet";
83 * BBoards-specific variables
89 * POP BBoards-specific variables
94 char *popbblist
= nmhetcdir(/hosts
.popbb
);
98 * Global MailDelivery file
100 char *maildelivery
= nmhetcdir(/maildelivery
);
104 * Aliasing Facility (doesn't belong here)
106 int Everyone
= NOTOK
;
107 static char *everyone
= "-1";
111 * Customize the MTS settings for nmh by adjusting
112 * the file mts.conf in the nmh etc directory.
120 static struct bind binds
[] = {
121 { "localname", &localname
},
122 { "localdomain", &localdomain
},
123 { "systemname", &systemname
},
124 { "mmdfldir", &mmdfldir
},
125 { "mmdflfil", &mmdflfil
},
126 { "uucpldir", &uucpldir
},
127 { "uucplfil", &uucplfil
},
128 { "mmdelim1", &mmdlm1
},
129 { "mmdelim2", &mmdlm2
},
130 { "mmailid", &mmailid
},
132 #if defined(SENDMTS) || defined(SMTPMTS)
133 { "hostable", &hostable
},
137 { "sendmail", &sendmail
},
140 { "clientname", &clientname
},
141 { "servers", &servers
},
142 { "pophost", &pophost
},
143 { "bbdomain", &bb_domain
},
146 { "popbbhost", &popbbhost
},
147 { "popbbuser", &popbbuser
},
148 { "popbblist", &popbblist
},
152 { "nntphost", &popbbhost
},
155 { "maildelivery", &maildelivery
},
156 { "everyone", &everyone
},
157 { "noshell", &NoShell
},
163 * Read the configuration file for the nmh interface
164 * to the mail transport system (MTS).
168 mts_init (char *name
)
170 char *bp
, *cp
, buffer
[BUFSIZ
];
173 static int inited
= 0;
175 if (inited
++ || (fp
= fopen (mtsconf
, "r")) == NULL
)
178 while (fgets (buffer
, sizeof(buffer
), fp
)) {
179 if (!(cp
= strchr(buffer
, '\n')))
182 if (*buffer
== '#' || *buffer
== '\0')
184 if (!(bp
= strchr(buffer
, ':')))
187 while (isspace (*bp
))
190 for (b
= binds
; b
->keyword
; b
++)
191 if (!strcmp (buffer
, b
->keyword
))
193 if (b
->keyword
&& (cp
= tailor_value (bp
)))
198 MMailids
= atoi (mmailid
);
199 Everyone
= atoi (everyone
);
206 * Convert escaped values, malloc some new space,
207 * and copy string to malloc'ed memory.
211 tailor_value (char *s
)
218 for (bp
= buffer
; *s
; bp
++, s
++) {
223 case 'b': *bp
= '\b'; break;
224 case 'f': *bp
= '\f'; break;
225 case 'n': *bp
= '\n'; break;
226 case 't': *bp
= '\t'; break;
238 r
= *s
!= '0' ? 10 : 8;
239 for (i
= 0; isdigit (*s
); s
++)
240 i
= i
* r
+ *s
- '0';
249 len
= strlen (buffer
) + 1;
250 if ((bp
= malloc (len
)))
251 memcpy (bp
, buffer
, len
);
257 * Get the fully qualified name of the local host.
263 static char buffer
[BUFSIZ
] = "";
270 /* check if we have cached the local name */
276 /* check if the mts.conf file specifies a "localname" */
278 strncpy (buffer
, localname
, sizeof(buffer
));
281 /* first get our local name */
283 strncpy (buffer
, name
.nodename
, sizeof(buffer
));
285 /* first get our local name */
286 gethostname (buffer
, sizeof(buffer
));
288 #ifdef HAVE_SETHOSTENT
291 /* now fully qualify our name */
292 if ((hp
= gethostbyname (buffer
)))
293 strncpy (buffer
, hp
->h_name
, sizeof(buffer
));
297 * If the mts.conf file specifies a "localdomain",
298 * we append that now. This should rarely be needed.
301 strcat (buffer
, ".");
302 strcat (buffer
, localdomain
);
310 * This is only for UUCP mail. It gets the hostname
311 * as part of the UUCP "domain".
317 static char buffer
[BUFSIZ
] = "";
323 /* check if we have cached the system name */
329 /* check if mts.conf file specifies a "systemname" */
331 strncpy (buffer
, systemname
, sizeof(buffer
));
337 strncpy (buffer
, name
.nodename
, sizeof(buffer
));
339 gethostname (buffer
, sizeof(buffer
));
347 * Get the username of current user
353 if (username
[0] == '\0')
361 * Get full name of current user (typically from GECOS
362 * field of password file).
368 if (username
[0] == '\0')
376 * Find the user's username and full name, and cache them.
377 * It also handles mmailid processing (username masquerading)
383 register char *cp
, *np
;
384 register struct passwd
*pw
;
390 if (uid
== geteuid () && (cp
= getenv ("USER")) != NULL
391 && (pw
= getpwnam (cp
)) != NULL
)
392 strncpy (username
, cp
, sizeof(username
));
393 else if ((pw
= getpwuid (uid
)) == NULL
394 || pw
->pw_name
== NULL
395 || *pw
->pw_name
== '\0') {
397 if ((pw
= getpwuid (getuid ())) == NULL
398 || pw
->pw_name
== NULL
399 || *pw
->pw_name
== '\0') {
402 strncpy (username
, "unknown", sizeof(username
));
403 snprintf (fullname
, sizeof(fullname
), "The Unknown User-ID (%d)",
411 * Do mmailid (username masquerading) processing. The GECOS
412 * field should have the form "Full Name <fakeusername>".
415 for (cp
= fullname
; *np
&& *np
!= (MMailids
? '<' : ','); *cp
++ = *np
++)
418 for (cp
= fullname
; *np
&& *np
!= (MMailids
? '<' : ','); ) {
419 if (*np
== '&') { /* blech! */
420 strcpy (cp
, pw
->pw_name
);
435 for (cp
= username
; *np
&& *np
!= '>'; *cp
++ = *np
++)
439 if (MMailids
== 0 || *np
== '\0')
440 strncpy (username
, pw
->pw_name
, sizeof(username
));
442 if ((cp
= getenv ("SIGNATURE")) && *cp
)
443 strncpy (fullname
, cp
, sizeof(fullname
));
445 if (strchr(fullname
, '.')) { /* quote any .'s */
448 /* should quote "'s too */
449 snprintf (tmp
, sizeof(tmp
), "\"%s\"", fullname
);
450 strncpy (fullname
, tmp
, sizeof(fullname
));