Nuke INTR_NETSAFE
[dragonfly/netmp.git] / contrib / tcp_wrappers / eval.c
blobd68358f3b9c3c5182dc8a3fb9fc709a8cf8877b3
1 /*
2 * Routines for controlled evaluation of host names, user names, and so on.
3 * They are, in fact, wrappers around the functions that are specific for
4 * the sockets or TLI programming interfaces. The request_info and host_info
5 * structures are used for result cacheing.
6 *
7 * These routines allows us to postpone expensive operations until their
8 * results are really needed. Examples are hostname lookups and double
9 * checks, or username lookups. Information that cannot be retrieved is
10 * given the value "unknown" ("paranoid" in case of hostname problems).
12 * When ALWAYS_HOSTNAME is off, hostname lookup is done only when required by
13 * tcpd paranoid mode, by access control patterns, or by %letter expansions.
15 * When ALWAYS_RFC931 mode is off, user lookup is done only when required by
16 * access control patterns or %letter expansions.
18 * Author: Wietse Venema, Eindhoven University of Technology, The Netherlands.
21 #ifndef lint
22 static char sccsid[] = "@(#) eval.c 1.3 95/01/30 19:51:45";
23 #endif
25 /* System libraries. */
27 #include <stdio.h>
28 #include <string.h>
30 /* Local stuff. */
32 #include "tcpd.h"
35 * When a string has the value STRING_UNKNOWN, it means: don't bother, I
36 * tried to look up the data but it was unavailable for some reason. When a
37 * host name has the value STRING_PARANOID it means there was a name/address
38 * conflict.
40 char unknown[] = STRING_UNKNOWN;
41 char paranoid[] = STRING_PARANOID;
43 /* eval_user - look up user name */
45 char *eval_user(request)
46 struct request_info *request;
48 if (request->user[0] == 0) {
49 strcpy(request->user, unknown);
50 if (request->sink == 0 && request->client->sin && request->server->sin)
51 rfc931(request->client->sin, request->server->sin, request->user);
53 return (request->user);
56 /* eval_hostaddr - look up printable address */
58 char *eval_hostaddr(host)
59 struct host_info *host;
61 if (host->addr[0] == 0) {
62 strcpy(host->addr, unknown);
63 if (host->request->hostaddr != 0)
64 host->request->hostaddr(host);
66 return (host->addr);
69 /* eval_hostname - look up host name */
71 char *eval_hostname(host)
72 struct host_info *host;
74 if (host->name[0] == 0) {
75 strcpy(host->name, unknown);
76 if (host->request->hostname != 0)
77 host->request->hostname(host);
79 return (host->name);
82 /* eval_hostinfo - return string with host name (preferred) or address */
84 char *eval_hostinfo(host)
85 struct host_info *host;
87 char *hostname;
89 #ifndef ALWAYS_HOSTNAME /* no implicit host lookups */
90 if (host->name[0] == 0)
91 return (eval_hostaddr(host));
92 #endif
93 hostname = eval_hostname(host);
94 if (HOSTNAME_KNOWN(hostname)) {
95 return (host->name);
96 } else {
97 return (eval_hostaddr(host));
101 /* eval_client - return string with as much about the client as we know */
103 char *eval_client(request)
104 struct request_info *request;
106 static char both[2 * STRING_LENGTH];
107 char *hostinfo = eval_hostinfo(request->client);
109 #ifndef ALWAYS_RFC931 /* no implicit user lookups */
110 if (request->user[0] == 0)
111 return (hostinfo);
112 #endif
113 if (STR_NE(eval_user(request), unknown)) {
114 sprintf(both, "%s@%s", request->user, hostinfo);
115 return (both);
116 } else {
117 return (hostinfo);
121 /* eval_server - return string with as much about the server as we know */
123 char *eval_server(request)
124 struct request_info *request;
126 static char both[2 * STRING_LENGTH];
127 char *host = eval_hostinfo(request->server);
128 char *daemon = eval_daemon(request);
130 if (STR_NE(host, unknown)) {
131 sprintf(both, "%s@%s", daemon, host);
132 return (both);
133 } else {
134 return (daemon);