2 ** mts.c -- definitions for the mail transport system
4 ** This code is Copyright (c) 2002, by the authors of nmh. See the
5 ** COPYRIGHT file in the root directory of the nmh distribution for
6 ** complete copyright information.
9 #include <h/mh.h> /* for snprintf() */
18 #ifdef HAVE_SYS_UTSNAME_H
19 # include <sys/utsname.h>
28 static void getuserinfo(void);
30 /* Cache the username and fullname of the user */
31 static char username[BUFSIZ];
32 static char fullname[BUFSIZ];
36 ** Get the fully qualified name of the local host.
41 static char buffer[BUFSIZ] = "";
42 struct addrinfo hints, *res;
47 /* check if we have cached the local name */
51 memset(buffer, 0, sizeof(buffer));
53 /* first get our local name */
55 strncpy(buffer, name.nodename, sizeof(buffer) - 1);
57 /* first get our local name */
58 gethostname(buffer, sizeof(buffer) - 1);
60 /* now fully qualify our name */
62 memset(&hints, 0, sizeof(hints));
63 hints.ai_flags = AI_CANONNAME;
64 hints.ai_family = PF_UNSPEC;
65 if (getaddrinfo(buffer, NULL, &hints, &res) == 0) {
66 strncpy(buffer, res->ai_canonname, sizeof(buffer) - 1);
75 ** This is only for UUCP mail. It gets the hostname
76 ** as part of the UUCP "domain".
81 static char buffer[BUFSIZ] = "";
87 /* check if we have cached the system name */
93 strncpy(buffer, name.nodename, sizeof(buffer));
95 gethostname(buffer, sizeof(buffer));
103 ** Get the username of current user
108 if (username[0] == '\0')
116 ** Get full name of current user (typically from GECOS
117 ** field of password file).
122 if (username[0] == '\0')
130 ** Find the user's username and full name, and cache them.
135 register unsigned char *cp;
137 register struct passwd *pw;
139 if ((pw = getpwuid(getuid())) == NULL
140 || pw->pw_name == NULL
141 || *pw->pw_name == '\0') {
142 strncpy(username, "unknown", sizeof(username));
143 snprintf(fullname, sizeof(fullname), "The Unknown User-ID (%d)",
151 ** Get the user's real name from the GECOS field. Stop once
152 ** we hit a ',', which some OSes use to separate other 'finger'
153 ** information in the GECOS field, like phone number.
155 for (cp = fullname; *np != '\0' && *np != ',';) {
160 ** On BSD(-derived) systems, the system utilities that
161 ** deal with the GECOS field (finger, mail, sendmail,
162 ** etc.) translate any '&' character in it to the login name,
163 ** with the first letter capitalized. So, for instance,
164 ** fingering a user "bob" with the GECOS field "& Jones"
165 ** would reveal him to be "In real life: Bob Jones".
166 ** Surprisingly, though, the OS doesn't do the translation
167 ** for you, so we have to do it manually here.
169 if (*np == '&') { /* blech! */
170 strcpy(cp, pw->pw_name);
181 strncpy(username, pw->pw_name, sizeof(username));
184 ** The $SIGNATURE environment variable overrides the GECOS field's
185 ** idea of your real name.
187 if ((cp = getenv("SIGNATURE")) && *cp)
188 strncpy(fullname, cp, sizeof(fullname));
190 if (strchr(fullname, '.')) { /* quote any .'s */
193 /* should quote "'s too */
194 snprintf(tmp, sizeof(tmp), "\"%s\"", fullname);
195 strncpy(fullname, tmp, sizeof(fullname));