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.
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.
22 static char sccsid
[] = "@(#) eval.c 1.3 95/01/30 19:51:45";
25 /* System libraries. */
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
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
);
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
);
82 /* eval_hostinfo - return string with host name (preferred) or address */
84 char *eval_hostinfo(host
)
85 struct host_info
*host
;
89 #ifndef ALWAYS_HOSTNAME /* no implicit host lookups */
90 if (host
->name
[0] == 0)
91 return (eval_hostaddr(host
));
93 hostname
= eval_hostname(host
);
94 if (HOSTNAME_KNOWN(hostname
)) {
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)
113 if (STR_NE(eval_user(request
), unknown
)) {
114 sprintf(both
, "%s@%s", request
->user
, 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
);