return get_port(1);
}
-/* If *host is a name for the loopback interface, try to change
- it to local hostname (not necessarily fully-qualified). */
void
-resolve_localhost(char **host)
+resolve_hostname(char **host)
{
struct hostent *hostinfo;
hostinfo = gethostbyname(*host);
- if (hostinfo &&
- hostinfo->h_addrtype == AF_INET) {
+ if (hostinfo == NULL || hostinfo->h_name == NULL) {
+ debug("gethostbyname(%s) failed", *host);
+ return;
+ }
+ if (hostinfo->h_addrtype == AF_INET) { /* check for localhost */
struct in_addr addr;
addr = *(struct in_addr *)(hostinfo->h_addr);
if (ntohl(addr.s_addr) == INADDR_LOOPBACK) {
char buf[MAXHOSTNAMELEN];
- if (gethostname(buf, sizeof(buf)) == 0) {
- xfree(*host);
- *host = xstrdup(buf);
- }
- }
- }
-}
-
-/* A (hopefully) portable way to make a fully-qualified hostname for
- GSSAPI authentication without relying on a potentially remote,
- untrusted resolver.
- Note: getdomainname() is not portable.
-*/
-void
-make_fqhn(char **host)
-{
- char *domainname = NULL, *fqhn = NULL, myhn[MAXHOSTNAMELEN];
- struct hostent *hent = NULL;
- int i;
-
- if (strchr(*host, '.')) {
- return; /* already fully qualified */
- }
-
- /* Otherwise, figure out our local domainname without using
- getdomainname(). */
- if (gethostname(myhn, sizeof(myhn)) < 0) {
- debug("gethostname() failed, can't convert %s to fqhn", *host);
- return;
- }
- if ((domainname = strchr(myhn, '.')) == NULL) {
-
- /* Resolving our local hostname should be secure
- (unlike resolving a remote hostname). */
- if ((hent = gethostbyname(myhn)) != NULL) {
- if ((domainname = strchr(hent->h_name, '.')) == NULL) {
- for (i=0;
- hent->h_aliases[i] &&
- (domainname =
- strchr(hent->h_aliases[i], '.')) == NULL;
- i++);
+ if (gethostname(buf, sizeof(buf)) < 0) {
+ debug("gethostname() failed");
+ return;
}
+ hostinfo = gethostbyname(buf);
}
}
-
- if (domainname) {
- domainname++;
- fqhn = xmalloc(strlen(*host)+strlen(domainname)+2);
- sprintf(fqhn, "%s.%s", *host, domainname);
- xfree(*host);
- *host = fqhn;
- return;
- }
-
- debug("unable to determine fully-qualified local hostname");
- return;
+ free(*host);
+ *host = strdup(hostinfo->h_name);
}
* previous call to gethostbyname(). */
xhost = xstrdup(host);
- /* If xhost is the loopback interface, switch it to our
- true local hostname. */
- resolve_localhost(&xhost);
-
/* Make sure we have the FQHN. Some GSSAPI implementations don't do
* this for us themselves */
- make_fqhn(&xhost);
+ resolve_hostname(&xhost);
gssbuf.length = sizeof("host@")+strlen(xhost);