2 * Copyright 2001 Sun Microsystems, Inc. All rights reserved.
3 * Use is subject to license terms.
5 #pragma ident "%Z%%M% %I% %E% SMI"
8 * Routines for controlled evaluation of host names, user names, and so on.
9 * They are, in fact, wrappers around the functions that are specific for
10 * the sockets or TLI programming interfaces. The request_info and host_info
11 * structures are used for result cacheing.
13 * These routines allows us to postpone expensive operations until their
14 * results are really needed. Examples are hostname lookups and double
15 * checks, or username lookups. Information that cannot be retrieved is
16 * given the value "unknown" ("paranoid" in case of hostname problems).
18 * When ALWAYS_HOSTNAME is off, hostname lookup is done only when required by
19 * tcpd paranoid mode, by access control patterns, or by %letter expansions.
21 * When ALWAYS_RFC931 mode is off, user lookup is done only when required by
22 * access control patterns or %letter expansions.
24 * Author: Wietse Venema, Eindhoven University of Technology, The Netherlands.
27 static char sccsid
[] = "@(#) eval.c 1.3 95/01/30 19:51:45";
29 /* System libraries. */
39 * When a string has the value STRING_UNKNOWN, it means: don't bother, I
40 * tried to look up the data but it was unavailable for some reason. When a
41 * host name has the value STRING_PARANOID it means there was a name/address
44 char unknown
[] = STRING_UNKNOWN
;
45 char paranoid
[] = STRING_PARANOID
;
47 /* eval_user - look up user name */
49 char *eval_user(request
)
50 struct request_info
*request
;
52 if (request
->user
[0] == 0) {
53 strcpy(request
->user
, unknown
);
54 if (request
->sink
== 0 && request
->client
->sin
&& request
->server
->sin
)
55 rfc931(request
->client
->sin
, request
->server
->sin
, request
->user
);
57 return (request
->user
);
60 /* eval_hostaddr - look up printable address */
62 char *eval_hostaddr(host
)
63 struct host_info
*host
;
65 if (host
->addr
[0] == 0) {
66 strcpy(host
->addr
, unknown
);
67 if (host
->request
->hostaddr
!= 0)
68 host
->request
->hostaddr(host
);
73 /* eval_hostname - look up host name */
75 char *eval_hostname(host
)
76 struct host_info
*host
;
78 if (host
->name
[0] == 0) {
79 strcpy(host
->name
, unknown
);
80 if (host
->request
->hostname
!= 0)
81 host
->request
->hostname(host
);
86 /* eval_hostinfo - return string with host name (preferred) or address */
88 char *eval_hostinfo(host
)
89 struct host_info
*host
;
93 #ifndef ALWAYS_HOSTNAME /* no implicit host lookups */
94 if (host
->name
[0] == 0)
95 return (eval_hostaddr(host
));
97 hostname
= eval_hostname(host
);
98 if (HOSTNAME_KNOWN(hostname
)) {
101 return (eval_hostaddr(host
));
105 /* eval_client - return string with as much about the client as we know */
107 char *eval_client(request
)
108 struct request_info
*request
;
110 static char both
[2 * STRING_LENGTH
];
111 char *hostinfo
= eval_hostinfo(request
->client
);
113 #ifndef ALWAYS_RFC931 /* no implicit user lookups */
114 if (request
->user
[0] == 0)
117 if (STR_NE(eval_user(request
), unknown
)) {
118 sprintf(both
, "%s@%s", request
->user
, hostinfo
);
125 /* eval_server - return string with as much about the server as we know */
127 char *eval_server(request
)
128 struct request_info
*request
;
130 static char both
[2 * STRING_LENGTH
];
131 char *host
= eval_hostinfo(request
->server
);
132 char *daemon
= eval_daemon(request
);
134 if (STR_NE(host
, unknown
)) {
135 sprintf(both
, "%s@%s", daemon
, host
);