8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / lib / libwrap / eval.c
blobff700a9e3a27204f49910cbf6594447ce099515b
1 /*
2 * Copyright 2001 Sun Microsystems, Inc. All rights reserved.
3 * Use is subject to license terms.
4 */
5 #pragma ident "%Z%%M% %I% %E% SMI"
7 /*
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 #ifndef lint
28 static char sccsid[] = "@(#) eval.c 1.3 95/01/30 19:51:45";
29 #endif
31 /* System libraries. */
33 #include <stdio.h>
34 #include <string.h>
36 /* Local stuff. */
38 #include "tcpd.h"
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
44 * conflict.
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);
72 return (host->addr);
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);
85 return (host->name);
88 /* eval_hostinfo - return string with host name (preferred) or address */
90 char *eval_hostinfo(host)
91 struct host_info *host;
93 char *hostname;
95 #ifndef ALWAYS_HOSTNAME /* no implicit host lookups */
96 if (host->name[0] == 0)
97 return (eval_hostaddr(host));
98 #endif
99 hostname = eval_hostname(host);
100 if (HOSTNAME_KNOWN(hostname)) {
101 return (host->name);
102 } else {
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)
117 return (hostinfo);
118 #endif
119 if (STR_NE(eval_user(request), unknown)) {
120 sprintf(both, "%s@%s", request->user, hostinfo);
121 return (both);
122 } else {
123 return (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);
138 return (both);
139 } else {
140 return (daemon);