- }
- }
-}
-
-/* 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++);
+ hostinfo = gethostbyname(buf);
+ xfree(*host);
+ if (hostinfo == NULL || hostinfo->h_name == NULL) {
+ *host = xstrdup(buf);
+ } else {
+ *host = xstrdup(hostinfo->h_name);