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.
21 /* System libraries. */
31 * When a string has the value STRING_UNKNOWN, it means: don't bother, I
32 * tried to look up the data but it was unavailable for some reason. When a
33 * host name has the value STRING_PARANOID it means there was a name/address
36 char unknown
[] = STRING_UNKNOWN
;
37 char paranoid
[] = STRING_PARANOID
;
39 /* eval_user - look up user name */
41 char *eval_user(request
)
42 struct request_info
*request
;
44 if (request
->user
[0] == 0) {
45 strcpy(request
->user
, unknown
);
46 if (request
->sink
== 0 && request
->client
->sin
&& request
->server
->sin
)
47 rfc931(request
->client
->sin
, request
->server
->sin
, request
->user
);
49 return (request
->user
);
52 /* eval_hostaddr - look up printable address */
54 char *eval_hostaddr(host
)
55 struct host_info
*host
;
57 if (host
->addr
[0] == 0) {
58 strcpy(host
->addr
, unknown
);
59 if (host
->request
->hostaddr
!= 0)
60 host
->request
->hostaddr(host
);
65 /* eval_hostname - look up host name */
67 char *eval_hostname(host
)
68 struct host_info
*host
;
70 if (host
->name
[0] == 0) {
71 strcpy(host
->name
, unknown
);
72 if (host
->request
->hostname
!= 0)
73 host
->request
->hostname(host
);
78 /* eval_hostinfo - return string with host name (preferred) or address */
80 char *eval_hostinfo(host
)
81 struct host_info
*host
;
85 #ifndef ALWAYS_HOSTNAME /* no implicit host lookups */
86 if (host
->name
[0] == 0)
87 return (eval_hostaddr(host
));
89 hostname
= eval_hostname(host
);
90 if (HOSTNAME_KNOWN(hostname
)) {
93 return (eval_hostaddr(host
));
97 /* eval_client - return string with as much about the client as we know */
99 char *eval_client(request
)
100 struct request_info
*request
;
102 static char both
[2 * STRING_LENGTH
];
103 char *hostinfo
= eval_hostinfo(request
->client
);
105 #ifndef ALWAYS_RFC931 /* no implicit user lookups */
106 if (request
->user
[0] == 0)
109 if (STR_NE(eval_user(request
), unknown
)) {
110 sprintf(both
, "%s@%s", request
->user
, hostinfo
);
117 /* eval_server - return string with as much about the server as we know */
119 char *eval_server(request
)
120 struct request_info
*request
;
122 static char both
[2 * STRING_LENGTH
];
123 char *host
= eval_hostinfo(request
->server
);
124 char *daemon
= eval_daemon(request
);
126 if (STR_NE(host
, unknown
)) {
127 sprintf(both
, "%s@%s", daemon
, host
);