Annotation of src/lib/libwrap/eval.c, Revision 1.6.56.2
1.6.56.2! riz 1: /* $NetBSD: eval.c,v 1.6.56.1 2012/04/23 16:48:56 riz Exp $ */
1.3 christos 2:
1.1 mrg 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.
1.5 simonb 8: *
1.1 mrg 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).
1.5 simonb 13: *
1.1 mrg 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.
1.5 simonb 16: *
1.1 mrg 17: * When ALWAYS_RFC931 mode is off, user lookup is done only when required by
18: * access control patterns or %letter expansions.
1.5 simonb 19: *
1.1 mrg 20: * Author: Wietse Venema, Eindhoven University of Technology, The Netherlands.
21: */
22:
1.3 christos 23: #include <sys/cdefs.h>
1.1 mrg 24: #ifndef lint
1.3 christos 25: #if 0
1.1 mrg 26: static char sccsid[] = "@(#) eval.c 1.3 95/01/30 19:51:45";
1.3 christos 27: #else
1.6.56.2! riz 28: __RCSID("$NetBSD: eval.c,v 1.6.56.1 2012/04/23 16:48:56 riz Exp $");
1.3 christos 29: #endif
1.1 mrg 30: #endif
31:
32: /* System libraries. */
33:
34: #include <stdio.h>
35: #include <string.h>
36:
37: /* Local stuff. */
38:
39: #include "tcpd.h"
40:
41: /*
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.
46: */
47: char unknown[] = STRING_UNKNOWN;
48: char paranoid[] = STRING_PARANOID;
49:
50: /* eval_user - look up user name */
51:
1.6.56.2! riz 52: char *eval_user(request)
! 53: struct request_info *request;
1.1 mrg 54: {
55: if (request->user[0] == 0) {
1.6 itojun 56: (void)strlcpy(request->user, unknown, sizeof(request->user));
1.1 mrg 57: if (request->sink == 0 && request->client->sin && request->server->sin)
58: rfc931(request->client->sin, request->server->sin, request->user);
59: }
60: return (request->user);
61: }
62:
63: /* eval_hostaddr - look up printable address */
64:
1.6.56.2! riz 65: char *eval_hostaddr(host)
! 66: struct host_info *host;
1.1 mrg 67: {
68: if (host->addr[0] == 0) {
1.6 itojun 69: (void)strlcpy(host->addr, unknown, sizeof(host->addr));
1.1 mrg 70: if (host->request->hostaddr != 0)
71: host->request->hostaddr(host);
72: }
73: return (host->addr);
74: }
75:
76: /* eval_hostname - look up host name */
77:
1.6.56.2! riz 78: char *eval_hostname(host)
! 79: struct host_info *host;
1.1 mrg 80: {
81: if (host->name[0] == 0) {
1.6 itojun 82: (void)strlcpy(host->name, unknown, sizeof(host->name));
1.1 mrg 83: if (host->request->hostname != 0)
84: host->request->hostname(host);
85: }
86: return (host->name);
87: }
88:
89: /* eval_hostinfo - return string with host name (preferred) or address */
90:
1.6.56.2! riz 91: char *eval_hostinfo(host)
! 92: struct host_info *host;
1.1 mrg 93: {
94: char *hostname;
95:
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));
105: }
106: }
107:
108: /* eval_client - return string with as much about the client as we know */
109:
1.6.56.2! riz 110: char *eval_client(request)
! 111: struct request_info *request;
1.1 mrg 112: {
113: static char both[2 * STRING_LENGTH];
114: char *hostinfo = eval_hostinfo(request->client);
115:
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)) {
1.2 mrg 121: (void)snprintf(both, sizeof both, "%s@%s", request->user, hostinfo);
1.1 mrg 122: return (both);
123: } else {
124: return (hostinfo);
125: }
126: }
127:
128: /* eval_server - return string with as much about the server as we know */
129:
1.6.56.2! riz 130: char *eval_server(request)
! 131: struct request_info *request;
1.1 mrg 132: {
133: static char both[2 * STRING_LENGTH];
134: char *host = eval_hostinfo(request->server);
135: char *daemon = eval_daemon(request);
136:
137: if (STR_NE(host, unknown)) {
1.2 mrg 138: (void)snprintf(both, sizeof both, "%s@%s", daemon, host);
1.1 mrg 139: return (both);
140: } else {
141: return (daemon);
142: }
143: }
CVSweb <webmaster@jp.NetBSD.org>