Remove building with NOCRYPTO option
[minix3.git] / lib / libwrap / eval.c
blobdb10d588a49a480e8c0d5d08057aec178f40fd1c
1 /* $NetBSD: eval.c,v 1.7 2012/03/21 10:10:37 matt Exp $ */
3 /*
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.
8 *
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>
24 #ifndef lint
25 #if 0
26 static char sccsid[] = "@(#) eval.c 1.3 95/01/30 19:51:45";
27 #else
28 __RCSID("$NetBSD: eval.c,v 1.7 2012/03/21 10:10:37 matt Exp $");
29 #endif
30 #endif
32 /* System libraries. */
34 #include <stdio.h>
35 #include <string.h>
37 /* Local stuff. */
39 #include "tcpd.h"
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
45 * conflict.
47 char unknown[] = STRING_UNKNOWN;
48 char paranoid[] = STRING_PARANOID;
50 /* eval_user - look up user name */
52 char *
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 */
65 char *
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);
73 return (host->addr);
76 /* eval_hostname - look up host name */
78 char *
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);
86 return (host->name);
89 /* eval_hostinfo - return string with host name (preferred) or address */
91 char *
92 eval_hostinfo(struct host_info *host)
94 char *hostname;
96 #ifndef ALWAYS_HOSTNAME /* no implicit host lookups */
97 if (host->name[0] == 0)
98 return (eval_hostaddr(host));
99 #endif
100 hostname = eval_hostname(host);
101 if (HOSTNAME_KNOWN(hostname)) {
102 return (host->name);
103 } else {
104 return (eval_hostaddr(host));
108 /* eval_client - return string with as much about the client as we know */
110 char *
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)
118 return (hostinfo);
119 #endif
120 if (STR_NE(eval_user(request), unknown)) {
121 (void)snprintf(both, sizeof both, "%s@%s", request->user, hostinfo);
122 return (both);
123 } else {
124 return (hostinfo);
128 /* eval_server - return string with as much about the server as we know */
130 char *
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);
139 return (both);
140 } else {
141 return (daemon);