1 /* $NetBSD: eval.c,v 1.7 2012/03/21 10:10:37 matt Exp $ */
4 * Routines for controlled evaluation of host names, user names, and so on.
5 * They are, in fact, wrappers around the functions that are specific for
6 * the sockets or TLI programming interfaces. The request_info and host_info
7 * structures are used for result cacheing.
9 * These routines allows us to postpone expensive operations until their
10 * results are really needed. Examples are hostname lookups and double
11 * checks, or username lookups. Information that cannot be retrieved is
12 * given the value "unknown" ("paranoid" in case of hostname problems).
14 * When ALWAYS_HOSTNAME is off, hostname lookup is done only when required by
15 * tcpd paranoid mode, by access control patterns, or by %letter expansions.
17 * When ALWAYS_RFC931 mode is off, user lookup is done only when required by
18 * access control patterns or %letter expansions.
20 * Author: Wietse Venema, Eindhoven University of Technology, The Netherlands.
23 #include <sys/cdefs.h>
26 static char sccsid
[] = "@(#) eval.c 1.3 95/01/30 19:51:45";
28 __RCSID("$NetBSD: eval.c,v 1.7 2012/03/21 10:10:37 matt Exp $");
32 /* System libraries. */
42 * When a string has the value STRING_UNKNOWN, it means: don't bother, I
43 * tried to look up the data but it was unavailable for some reason. When a
44 * host name has the value STRING_PARANOID it means there was a name/address
47 char unknown
[] = STRING_UNKNOWN
;
48 char paranoid
[] = STRING_PARANOID
;
50 /* eval_user - look up user name */
53 eval_user(struct request_info
*request
)
55 if (request
->user
[0] == 0) {
56 (void)strlcpy(request
->user
, unknown
, sizeof(request
->user
));
57 if (request
->sink
== 0 && request
->client
->sin
&& request
->server
->sin
)
58 rfc931(request
->client
->sin
, request
->server
->sin
, request
->user
);
60 return (request
->user
);
63 /* eval_hostaddr - look up printable address */
66 eval_hostaddr(struct host_info
*host
)
68 if (host
->addr
[0] == 0) {
69 (void)strlcpy(host
->addr
, unknown
, sizeof(host
->addr
));
70 if (host
->request
->hostaddr
!= 0)
71 host
->request
->hostaddr(host
);
76 /* eval_hostname - look up host name */
79 eval_hostname(struct host_info
*host
)
81 if (host
->name
[0] == 0) {
82 (void)strlcpy(host
->name
, unknown
, sizeof(host
->name
));
83 if (host
->request
->hostname
!= 0)
84 host
->request
->hostname(host
);
89 /* eval_hostinfo - return string with host name (preferred) or address */
92 eval_hostinfo(struct host_info
*host
)
96 #ifndef ALWAYS_HOSTNAME /* no implicit host lookups */
97 if (host
->name
[0] == 0)
98 return (eval_hostaddr(host
));
100 hostname
= eval_hostname(host
);
101 if (HOSTNAME_KNOWN(hostname
)) {
104 return (eval_hostaddr(host
));
108 /* eval_client - return string with as much about the client as we know */
111 eval_client(struct request_info
*request
)
113 static char both
[2 * STRING_LENGTH
];
114 char *hostinfo
= eval_hostinfo(request
->client
);
116 #ifndef ALWAYS_RFC931 /* no implicit user lookups */
117 if (request
->user
[0] == 0)
120 if (STR_NE(eval_user(request
), unknown
)) {
121 (void)snprintf(both
, sizeof both
, "%s@%s", request
->user
, hostinfo
);
128 /* eval_server - return string with as much about the server as we know */
131 eval_server(struct request_info
*request
)
133 static char both
[2 * STRING_LENGTH
];
134 char *host
= eval_hostinfo(request
->server
);
135 char *daemon
= eval_daemon(request
);
137 if (STR_NE(host
, unknown
)) {
138 (void)snprintf(both
, sizeof both
, "%s@%s", daemon
, host
);