- Make _do_ypbind() check for /var/run/ypbind.lock and attempt to flock()

it before before trying to establish a binding. If /var/run/ypbind.lock
  doesn't exist, or if it exists and isn't locked, then ypbind isn't
  running, which means NIS is either turned off or hosed.

- Have _yp_check() call yp_unbind() after it sucessfully calls yp_bind()
  to make sure it frees resources correctly. (I don't think there's really
  a memory leak here, but it seems somehow wrong to call yp_bind() without
  making a corresponding call to yp_unbind() afterwards.)

This makes the NIS code behave a little better in cases where libc makes
calls to NIS, but it isn't running correctly (i.e. there's no ypbind).

This cleans up some strange libc behavior that manifests itself if
you have the system domain name set, but aren't actually running NIS.
In this event, the getrpcent(3) code could try to call into NIS and
cause several inexplicable "clnttcp_create error: RPC program not
registered" messages to appear. This happens because _yp_check() checks
if the system domain name is set and, if it is, proceeds to call
yp_bind() to attempt to establish a binding. Since there is no
binding file (remember: ypbind isn't running, so /var/yp/binding
will be empty), _yp_dobind() will attempt to contact ypbind to
prod it into binding the domain. And because ypbind isn't running,
the code generates the 'clnttcp_create' error. Ultimately the
_yp_check() fails and the getrpcent(3) code rolls over to the /etc/rpc
file, but the error messages are annoying, and the code should be
smart enough to forgo the binding attempt when NIS is turned off.
This commit is contained in:
Bill Paul 1995-11-05 05:39:04 +00:00
parent deb0ea4125
commit 0f98415ed4

View File

@ -28,7 +28,7 @@
*/
#ifndef LINT
static char *rcsid = "$Id: yplib.c,v 1.11 1995/07/05 06:04:20 wpaul Exp $";
static char *rcsid = "$Id: yplib.c,v 1.12 1995/09/02 04:16:21 wpaul Exp $";
#endif
#include <sys/param.h>
@ -46,6 +46,10 @@ static char *rcsid = "$Id: yplib.c,v 1.11 1995/07/05 06:04:20 wpaul Exp $";
#include <rpcsvc/yp_prot.h>
#include <rpcsvc/ypclnt.h>
#ifndef YPBINDLOCK
#define YPBINDLOCK "/var/run/ypbind.lock"
#endif
#ifndef BINDINGDIR
#define BINDINGDIR "/var/yp/binding"
#endif
@ -199,7 +203,7 @@ struct dom_binding **ypdb;
struct ypbind_resp ypbr;
struct timeval tv;
struct sockaddr_in clnt_sin;
int clnt_sock, fd, gpid;
int clnt_sock, lfd, fd, gpid;
CLIENT *client;
int new = 0, r;
int retries = 0;
@ -234,6 +238,21 @@ struct dom_binding **ypdb;
ysd->dom_vers = 0;
new = 1;
}
if ((lfd = open(YPBINDLOCK, O_RDONLY)) == -1)
return(YPERR_YPBIND);
errno = 0;
switch (flock(lfd, LOCK_EX|LOCK_NB) == -1 && errno == EWOULDBLOCK) {
case 0:
close(lfd);
return (YPERR_YPBIND);
break;
case 1:
default:
close(lfd);
break;
}
again:
retries++;
if (retries > MAX_RETRIES) {
@ -865,7 +884,9 @@ char **dom;
if(dom)
*dom = _yp_domain;
if( yp_bind(_yp_domain)==0 )
if( yp_bind(_yp_domain)==0 ) {
yp_unbind(_yp_domain);
return 1;
}
return 0;
}