2N/A/*
2N/A * Copyright 2001 Sun Microsystems, Inc. All rights reserved.
2N/A * Use is subject to license terms.
2N/A */
2N/A#pragma ident "%Z%%M% %I% %E% SMI"
2N/A
2N/A /*
2N/A * Routines for controlled evaluation of host names, user names, and so on.
2N/A * They are, in fact, wrappers around the functions that are specific for
2N/A * the sockets or TLI programming interfaces. The request_info and host_info
2N/A * structures are used for result cacheing.
2N/A *
2N/A * These routines allows us to postpone expensive operations until their
2N/A * results are really needed. Examples are hostname lookups and double
2N/A * checks, or username lookups. Information that cannot be retrieved is
2N/A * given the value "unknown" ("paranoid" in case of hostname problems).
2N/A *
2N/A * When ALWAYS_HOSTNAME is off, hostname lookup is done only when required by
2N/A * tcpd paranoid mode, by access control patterns, or by %letter expansions.
2N/A *
2N/A * When ALWAYS_RFC931 mode is off, user lookup is done only when required by
2N/A * access control patterns or %letter expansions.
2N/A *
2N/A * Author: Wietse Venema, Eindhoven University of Technology, The Netherlands.
2N/A */
2N/A
2N/A#ifndef lint
2N/Astatic char sccsid[] = "@(#) eval.c 1.3 95/01/30 19:51:45";
2N/A#endif
2N/A
2N/A/* System libraries. */
2N/A
2N/A#include <stdio.h>
2N/A#include <string.h>
2N/A
2N/A/* Local stuff. */
2N/A
2N/A#include "tcpd.h"
2N/A
2N/A /*
2N/A * When a string has the value STRING_UNKNOWN, it means: don't bother, I
2N/A * tried to look up the data but it was unavailable for some reason. When a
2N/A * host name has the value STRING_PARANOID it means there was a name/address
2N/A * conflict.
2N/A */
2N/Achar unknown[] = STRING_UNKNOWN;
2N/Achar paranoid[] = STRING_PARANOID;
2N/A
2N/A/* eval_user - look up user name */
2N/A
2N/Achar *eval_user(request)
2N/Astruct request_info *request;
2N/A{
2N/A if (request->user[0] == 0) {
2N/A strcpy(request->user, unknown);
2N/A if (request->sink == 0 && request->client->sin && request->server->sin)
2N/A rfc931(request->client->sin, request->server->sin, request->user);
2N/A }
2N/A return (request->user);
2N/A}
2N/A
2N/A/* eval_hostaddr - look up printable address */
2N/A
2N/Achar *eval_hostaddr(host)
2N/Astruct host_info *host;
2N/A{
2N/A if (host->addr[0] == 0) {
2N/A strcpy(host->addr, unknown);
2N/A if (host->request->hostaddr != 0)
2N/A host->request->hostaddr(host);
2N/A }
2N/A return (host->addr);
2N/A}
2N/A
2N/A/* eval_hostname - look up host name */
2N/A
2N/Achar *eval_hostname(host)
2N/Astruct host_info *host;
2N/A{
2N/A if (host->name[0] == 0) {
2N/A strcpy(host->name, unknown);
2N/A if (host->request->hostname != 0)
2N/A host->request->hostname(host);
2N/A }
2N/A return (host->name);
2N/A}
2N/A
2N/A/* eval_hostinfo - return string with host name (preferred) or address */
2N/A
2N/Achar *eval_hostinfo(host)
2N/Astruct host_info *host;
2N/A{
2N/A char *hostname;
2N/A
2N/A#ifndef ALWAYS_HOSTNAME /* no implicit host lookups */
2N/A if (host->name[0] == 0)
2N/A return (eval_hostaddr(host));
2N/A#endif
2N/A hostname = eval_hostname(host);
2N/A if (HOSTNAME_KNOWN(hostname)) {
2N/A return (host->name);
2N/A } else {
2N/A return (eval_hostaddr(host));
2N/A }
2N/A}
2N/A
2N/A/* eval_client - return string with as much about the client as we know */
2N/A
2N/Achar *eval_client(request)
2N/Astruct request_info *request;
2N/A{
2N/A static char both[2 * STRING_LENGTH];
2N/A char *hostinfo = eval_hostinfo(request->client);
2N/A
2N/A#ifndef ALWAYS_RFC931 /* no implicit user lookups */
2N/A if (request->user[0] == 0)
2N/A return (hostinfo);
2N/A#endif
2N/A if (STR_NE(eval_user(request), unknown)) {
2N/A sprintf(both, "%s@%s", request->user, hostinfo);
2N/A return (both);
2N/A } else {
2N/A return (hostinfo);
2N/A }
2N/A}
2N/A
2N/A/* eval_server - return string with as much about the server as we know */
2N/A
2N/Achar *eval_server(request)
2N/Astruct request_info *request;
2N/A{
2N/A static char both[2 * STRING_LENGTH];
2N/A char *host = eval_hostinfo(request->server);
2N/A char *daemon = eval_daemon(request);
2N/A
2N/A if (STR_NE(host, unknown)) {
2N/A sprintf(both, "%s@%s", daemon, host);
2N/A return (both);
2N/A } else {
2N/A return (daemon);
2N/A }
2N/A}