diff options
Diffstat (limited to 'usr/src/lib')
| -rw-r--r-- | usr/src/lib/libnsl/rpc/rpcb_clnt.c | 25 | ||||
| -rw-r--r-- | usr/src/lib/nametoaddr/straddr/common/straddr.c | 65 |
2 files changed, 22 insertions, 68 deletions
diff --git a/usr/src/lib/libnsl/rpc/rpcb_clnt.c b/usr/src/lib/libnsl/rpc/rpcb_clnt.c index c8812e50b1..0fb7a8f32e 100644 --- a/usr/src/lib/libnsl/rpc/rpcb_clnt.c +++ b/usr/src/lib/libnsl/rpc/rpcb_clnt.c @@ -21,6 +21,10 @@ */ /* + * Copyright 2015 Nexenta Systems, Inc. All rights reserved. + */ + +/* * Copyright 2014 Gary Mills * Copyright 2006 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. @@ -52,7 +56,6 @@ #include <netinet/in.h> /* FOR IPPROTO_TCP/UDP definitions */ #include <rpc/pmap_prot.h> #endif -#include <sys/utsname.h> #include <errno.h> #include <stdlib.h> #include <string.h> @@ -404,7 +407,6 @@ static CLIENT * local_rpcb(void) { static struct netconfig *loopnconf; - static char hostname[MAXHOSTNAMELEN + 1]; extern mutex_t loopnconf_lock; /* VARIABLES PROTECTED BY loopnconf_lock: loopnconf */ @@ -413,13 +415,6 @@ local_rpcb(void) struct netconfig *nconf, *tmpnconf = NULL; void *nc_handle; - if ((hostname[0] == '\0') && (gethostname(hostname, - sizeof (hostname)) < 0)) { - syslog(LOG_ERR, "local_rpcb: gethostname failed."); - rpc_createerr.cf_stat = RPC_UNKNOWNHOST; - (void) mutex_unlock(&loopnconf_lock); - return (NULL); - } nc_handle = setnetconfig(); if (nc_handle == NULL) { /* fails to open netconfig file */ @@ -444,7 +439,7 @@ local_rpcb(void) (void) endnetconfig(nc_handle); } (void) mutex_unlock(&loopnconf_lock); - return (getclnthandle(hostname, loopnconf, NULL)); + return (getclnthandle(HOST_SELF_CONNECT, loopnconf, NULL)); } /* @@ -564,17 +559,12 @@ got_entry(rpcb_entry_list_ptr relp, struct netconfig *nconf) bool_t __rpcbind_is_up(void) { - char hostname[MAXHOSTNAMELEN + 1]; - char uaddr[SYS_NMLN]; struct netbuf *addr; int fd; struct t_call *sndcall; struct netconfig *netconf; bool_t res; - if (gethostname(hostname, sizeof (hostname)) < 0) - return (TRUE); - if ((fd = t_open("/dev/ticotsord", O_RDWR, NULL)) == -1) return (TRUE); @@ -589,15 +579,12 @@ __rpcbind_is_up(void) return (TRUE); } - uaddr[0] = '\0'; - (void) strlcpy(uaddr, hostname, sizeof (uaddr) - 5); - (void) strcat(uaddr, ".rpc"); if ((netconf = getnetconfigent("ticotsord")) == NULL) { (void) t_free((char *)sndcall, T_CALL); (void) t_close(fd); return (FALSE); } - addr = uaddr2taddr(netconf, uaddr); + addr = uaddr2taddr(netconf, "localhost.rpc"); freenetconfigent(netconf); if (addr == NULL || addr->buf == NULL) { if (addr) diff --git a/usr/src/lib/nametoaddr/straddr/common/straddr.c b/usr/src/lib/nametoaddr/straddr/common/straddr.c index 69995ba6c9..a5fc2839d1 100644 --- a/usr/src/lib/nametoaddr/straddr/common/straddr.c +++ b/usr/src/lib/nametoaddr/straddr/common/straddr.c @@ -18,6 +18,11 @@ * * CDDL HEADER END */ + +/* + * Copyright 2015 Nexenta Systems, Inc. All rights reserved. + */ + /* * Copyright 2006 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. @@ -26,9 +31,6 @@ /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ /* All Rights Reserved */ - -#pragma ident "%Z%%M% %I% %E% SMI" - #include <ctype.h> #include <stdio.h> #include <tiuser.h> @@ -38,7 +40,6 @@ #include <sys/param.h> #include <string.h> #include <stdlib.h> -#include <synch.h> /* * The generic name to address mappings for any transport that @@ -70,10 +71,10 @@ #define SERVICEFILE "/etc/net/%s/services" #define FIELD1 1 #define FIELD2 2 +#define LOCALHOST "localhost" static int searchhost(struct netconfig *, char *, int, char *); static int searchserv(struct netconfig *, char *, int, char *); -static const char *nodename(void); /* * _netdir_getbyname() returns all of the addresses for @@ -344,8 +345,8 @@ _uaddr2taddr(struct netconfig *netconfigp, char *uaddr) from += 2; } else { *to = ((*(from+1) - '0') << 6) + - ((*(from+2) - '0') << 3) + - (*(from+3) - '0'); + ((*(from+2) - '0') << 3) + + (*(from+3) - '0'); from += 4; } } else { @@ -411,28 +412,21 @@ searchhost(struct netconfig *netconfigp, char *token, int field, char *hostbuf) char *nexttok; /* next token to process */ FILE *fp; /* the opened searchfile */ int nelements = 0; /* total number of elements found */ - const char *myname; /* my own nodename */ - - myname = nodename(); + struct utsname utsname; /* - * Unless /etc/netconfig has been altered, the only transport - * that will use straddr.so is loopback. In this case, we - * always return our nodename if that's what we were passed, - * or we fail (note that we'd like to return a constant like - * "localhost" so that changes to the machine name won't cause - * problems, but things like autofs actually assume that we're - * using our nodename). + * Unless /etc/netconfig has been altered, the only transport that + * will use straddr.so is loopback. In this case, we always + * return "localhost" if either our nodename, or "localhost", or + * some of special-case host names were passed, or we fail. */ if ((strcmp(token, HOST_SELF_BIND) == 0) || (strcmp(token, HOST_SELF_CONNECT) == 0) || (strcmp(token, HOST_ANY) == 0) || - (myname != NULL && (strcmp(token, myname) == 0))) { - if (myname == NULL) - return (0); - - (void) strcpy(hostbuf, myname); + (strcmp(token, LOCALHOST) == 0) || + (uname(&utsname) >= 0 && strcmp(token, utsname.nodename) == 0)) { + (void) strcpy(hostbuf, LOCALHOST); return (1); } @@ -560,30 +554,3 @@ searchserv(struct netconfig *netconfigp, char *token, int field, char *servname) (void) fclose(fp); return (0); } - -static const char * -nodename(void) -{ - static mutex_t nodename_lock = DEFAULTMUTEX; - static const char *myname; - struct utsname utsname; - - (void) mutex_lock(&nodename_lock); - if (myname != NULL) { - (void) mutex_unlock(&nodename_lock); - return (myname); - } - - if (uname(&utsname) == -1) { - (void) mutex_unlock(&nodename_lock); - _nderror = ND_SYSTEM; - return (NULL); - } - - myname = strdup(utsname.nodename); - if (myname == NULL) - _nderror = ND_NOMEM; - - (void) mutex_unlock(&nodename_lock); - return (myname); -} |
