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.
28 static char sccsid
[] = "@(#) eval.c 1.3 95/01/30 19:51:45";
31 /* System libraries. */
41 * When a string has the value STRING_UNKNOWN, it means: don't bother, I
42 * tried to look up the data but it was unavailable for some reason. When a
43 * host name has the value STRING_PARANOID it means there was a name/address
46 char unknown
[] = STRING_UNKNOWN
;
47 char paranoid
[] = STRING_PARANOID
;
49 /* eval_user - look up user name */
51 char *eval_user(request
)
52 struct request_info
*request
;
54 if (request
->user
[0] == 0) {
55 strcpy(request
->user
, unknown
);
56 if (request
->sink
== 0 && request
->client
->sin
&& request
->server
->sin
)
57 rfc931(request
->client
->sin
, request
->server
->sin
, request
->user
);
59 return (request
->user
);
62 /* eval_hostaddr - look up printable address */
64 char *eval_hostaddr(host
)
65 struct host_info
*host
;
67 if (host
->addr
[0] == 0) {
68 strcpy(host
->addr
, unknown
);
69 if (host
->request
->hostaddr
!= 0)
70 host
->request
->hostaddr(host
);
75 /* eval_hostname - look up host name */
77 char *eval_hostname(host
)
78 struct host_info
*host
;
80 if (host
->name
[0] == 0) {
81 strcpy(host
->name
, unknown
);
82 if (host
->request
->hostname
!= 0)
83 host
->request
->hostname(host
);
88 /* eval_hostinfo - return string with host name (preferred) or address */
90 char *eval_hostinfo(host
)
91 struct host_info
*host
;
95 #ifndef ALWAYS_HOSTNAME /* no implicit host lookups */
96 if (host
->name
[0] == 0)
97 return (eval_hostaddr(host
));
99 hostname
= eval_hostname(host
);
100 if (HOSTNAME_KNOWN(hostname
)) {
103 return (eval_hostaddr(host
));
107 /* eval_client - return string with as much about the client as we know */
109 char *eval_client(request
)
110 struct request_info
*request
;
112 static char both
[2 * STRING_LENGTH
];
113 char *hostinfo
= eval_hostinfo(request
->client
);
115 #ifndef ALWAYS_RFC931 /* no implicit user lookups */
116 if (request
->user
[0] == 0)
119 if (STR_NE(eval_user(request
), unknown
)) {
120 sprintf(both
, "%s@%s", request
->user
, hostinfo
);
127 /* eval_server - return string with as much about the server as we know */
129 char *eval_server(request
)
130 struct request_info
*request
;
132 static char both
[2 * STRING_LENGTH
];
133 char *host
= eval_hostinfo(request
->server
);
134 char *daemon
= eval_daemon(request
);
136 if (STR_NE(host
, unknown
)) {
137 sprintf(both
, "%s@%s", daemon
, host
);