2006-10-05 13:18:11 +04:00
|
|
|
/* $NetBSD: ypbind.c,v 1.56 2006/10/05 09:18:11 tron Exp $ */
|
1996-03-31 01:49:08 +03:00
|
|
|
|
1993-05-16 06:47:20 +04:00
|
|
|
/*
|
1994-05-25 13:55:39 +04:00
|
|
|
* Copyright (c) 1992, 1993 Theo de Raadt <deraadt@fsa.ca>
|
1993-05-16 06:47:20 +04:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
|
|
|
|
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
|
|
|
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
1997-07-07 06:27:05 +04:00
|
|
|
#include <sys/cdefs.h>
|
1993-05-16 06:47:20 +04:00
|
|
|
#ifndef LINT
|
2006-10-05 13:18:11 +04:00
|
|
|
__RCSID("$NetBSD: ypbind.c,v 1.56 2006/10/05 09:18:11 tron Exp $");
|
1993-05-16 06:47:20 +04:00
|
|
|
#endif
|
|
|
|
|
1993-04-26 12:09:02 +04:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/signal.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/file.h>
|
1993-12-03 13:08:12 +03:00
|
|
|
#include <sys/uio.h>
|
1993-04-26 12:09:02 +04:00
|
|
|
#include <sys/syslog.h>
|
1996-06-22 21:59:52 +04:00
|
|
|
#include <sys/stat.h>
|
1999-02-12 18:04:00 +03:00
|
|
|
#include <fcntl.h>
|
1996-10-01 04:22:27 +04:00
|
|
|
#include <limits.h>
|
1993-04-26 12:09:02 +04:00
|
|
|
#include <stdio.h>
|
1994-12-23 19:21:49 +03:00
|
|
|
#include <stdlib.h>
|
1993-04-26 12:09:02 +04:00
|
|
|
#include <errno.h>
|
1998-08-21 13:39:04 +04:00
|
|
|
#include <syslog.h>
|
|
|
|
#include <stdarg.h>
|
1993-04-26 12:09:02 +04:00
|
|
|
#include <ctype.h>
|
|
|
|
#include <dirent.h>
|
|
|
|
#include <netdb.h>
|
|
|
|
#include <string.h>
|
1996-06-22 21:59:52 +04:00
|
|
|
#include <err.h>
|
1993-04-26 12:09:02 +04:00
|
|
|
#include <rpc/rpc.h>
|
|
|
|
#include <rpc/xdr.h>
|
|
|
|
#include <net/if.h>
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
#include <rpc/pmap_clnt.h>
|
|
|
|
#include <rpc/pmap_prot.h>
|
|
|
|
#include <rpc/pmap_rmt.h>
|
|
|
|
#include <unistd.h>
|
1999-06-06 06:38:00 +04:00
|
|
|
#include <util.h>
|
1993-04-26 12:09:02 +04:00
|
|
|
#include <rpcsvc/yp_prot.h>
|
|
|
|
#include <rpcsvc/ypclnt.h>
|
2000-04-11 15:36:47 +04:00
|
|
|
#include <ifaddrs.h>
|
1993-04-26 12:09:02 +04:00
|
|
|
|
1996-10-01 04:22:27 +04:00
|
|
|
#include "pathnames.h"
|
|
|
|
|
1996-06-22 21:59:52 +04:00
|
|
|
#ifndef O_SHLOCK
|
|
|
|
#define O_SHLOCK 0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define BUFSIZE 1400
|
1996-10-01 04:22:27 +04:00
|
|
|
|
1996-10-02 09:55:05 +04:00
|
|
|
#define YPSERVERSSUFF ".ypservers"
|
2000-12-20 04:34:39 +03:00
|
|
|
#define BINDINGDIR (_PATH_VAR_YP "binding")
|
1993-04-26 12:09:02 +04:00
|
|
|
|
|
|
|
struct _dom_binding {
|
|
|
|
struct _dom_binding *dom_pnext;
|
|
|
|
char dom_domain[YPMAXDOMAIN + 1];
|
|
|
|
struct sockaddr_in dom_server_addr;
|
|
|
|
int dom_socket;
|
|
|
|
CLIENT *dom_client;
|
1998-02-12 06:32:51 +03:00
|
|
|
long dom_vers;
|
1993-04-26 12:09:02 +04:00
|
|
|
time_t dom_check_t;
|
1994-07-02 10:45:48 +04:00
|
|
|
time_t dom_ask_t;
|
1993-04-26 12:09:02 +04:00
|
|
|
int dom_lockfd;
|
|
|
|
int dom_alive;
|
1997-07-07 06:27:05 +04:00
|
|
|
u_int32_t dom_xid;
|
1993-04-26 12:09:02 +04:00
|
|
|
};
|
|
|
|
|
1996-06-22 21:59:52 +04:00
|
|
|
static char *domainname;
|
1993-04-26 12:09:02 +04:00
|
|
|
|
1996-06-22 21:59:52 +04:00
|
|
|
static struct _dom_binding *ypbindlist;
|
|
|
|
static int check;
|
1993-04-26 12:09:02 +04:00
|
|
|
|
1996-10-01 04:22:27 +04:00
|
|
|
typedef enum {
|
|
|
|
YPBIND_DIRECT, YPBIND_BROADCAST, YPBIND_SETLOCAL, YPBIND_SETALL
|
|
|
|
} ypbind_mode_t;
|
|
|
|
|
|
|
|
ypbind_mode_t ypbindmode;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If ypbindmode is YPBIND_SETLOCAL or YPBIND_SETALL, this indicates
|
|
|
|
* whether or not we've been "ypset". If we haven't, we behave like
|
|
|
|
* YPBIND_BROADCAST. If we have, we behave like YPBIND_DIRECT.
|
|
|
|
*/
|
|
|
|
int been_ypset;
|
|
|
|
|
1996-06-22 21:59:52 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
static int debug;
|
|
|
|
#endif
|
|
|
|
|
1997-07-07 06:27:05 +04:00
|
|
|
static int insecure;
|
1996-06-22 21:59:52 +04:00
|
|
|
static int rpcsock, pingsock;
|
|
|
|
static struct rmtcallargs rmtca;
|
|
|
|
static struct rmtcallres rmtcr;
|
1996-07-25 22:53:43 +04:00
|
|
|
static bool_t rmtcr_outval;
|
1998-02-12 06:32:51 +03:00
|
|
|
static u_long rmtcr_port;
|
1996-06-22 21:59:52 +04:00
|
|
|
static SVCXPRT *udptransp, *tcptransp;
|
|
|
|
|
2002-07-07 01:44:40 +04:00
|
|
|
int _yp_invalid_domain(const char *); /* from libc */
|
|
|
|
int main(int, char *[]);
|
1996-06-22 21:59:52 +04:00
|
|
|
|
2002-07-07 01:44:40 +04:00
|
|
|
static void usage(void);
|
|
|
|
static void yp_log(int, const char *, ...)
|
2000-10-12 00:23:46 +04:00
|
|
|
__attribute__((__format__(__printf__, 2, 3)));
|
2002-07-07 01:44:40 +04:00
|
|
|
static struct _dom_binding *makebinding(const char *);
|
|
|
|
static int makelock(struct _dom_binding *);
|
|
|
|
static void removelock(struct _dom_binding *);
|
|
|
|
static void *ypbindproc_null_2(SVCXPRT *, void *);
|
|
|
|
static void *ypbindproc_domain_2(SVCXPRT *, void *);
|
|
|
|
static void *ypbindproc_setdom_2(SVCXPRT *, void *);
|
|
|
|
static void ypbindprog_2(struct svc_req *, SVCXPRT *);
|
|
|
|
static void checkwork(void);
|
|
|
|
static int ping(struct _dom_binding *);
|
|
|
|
static int nag_servers(struct _dom_binding *);
|
|
|
|
static enum clnt_stat handle_replies(void);
|
|
|
|
static enum clnt_stat handle_ping(void);
|
|
|
|
static void rpc_received(char *, struct sockaddr_in *, int);
|
|
|
|
static struct _dom_binding *xid2ypdb(u_int32_t);
|
|
|
|
static u_int32_t unique_xid(struct _dom_binding *);
|
|
|
|
static int broadcast(char *, int);
|
|
|
|
static int direct(char *, int);
|
|
|
|
static int direct_set(char *, int, struct _dom_binding *);
|
1996-06-22 21:59:52 +04:00
|
|
|
|
|
|
|
static void
|
2002-07-07 01:44:40 +04:00
|
|
|
usage(void)
|
1996-06-22 21:59:52 +04:00
|
|
|
{
|
|
|
|
char *opt = "";
|
|
|
|
#ifdef DEBUG
|
|
|
|
opt = " [-d]";
|
|
|
|
#endif
|
1998-07-13 16:01:03 +04:00
|
|
|
|
|
|
|
(void)fprintf(stderr,
|
2004-01-06 02:23:32 +03:00
|
|
|
"usage: %s [-broadcast] [-insecure] [-ypset] [-ypsetme] %s\n",
|
2001-02-20 02:22:40 +03:00
|
|
|
getprogname(), opt);
|
1996-06-22 21:59:52 +04:00
|
|
|
exit(1);
|
|
|
|
}
|
1998-08-21 13:39:04 +04:00
|
|
|
|
|
|
|
static void
|
|
|
|
yp_log(int pri, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
|
|
|
|
#if defined(DEBUG)
|
|
|
|
if (debug)
|
|
|
|
vfprintf(stderr, fmt, ap);
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
vsyslog(pri, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
1996-06-22 21:59:52 +04:00
|
|
|
static struct _dom_binding *
|
2002-07-07 01:44:40 +04:00
|
|
|
makebinding(const char *dm)
|
1996-06-22 21:59:52 +04:00
|
|
|
{
|
|
|
|
struct _dom_binding *ypdb;
|
|
|
|
|
1998-08-21 13:39:04 +04:00
|
|
|
if ((ypdb = (struct _dom_binding *)malloc(sizeof *ypdb)) == NULL) {
|
|
|
|
yp_log(LOG_ERR, "makebinding");
|
|
|
|
exit(1);
|
|
|
|
}
|
1996-06-22 21:59:52 +04:00
|
|
|
|
1998-07-13 16:01:03 +04:00
|
|
|
(void)memset(ypdb, 0, sizeof *ypdb);
|
2004-09-07 17:20:39 +04:00
|
|
|
(void)strlcpy(ypdb->dom_domain, dm, sizeof ypdb->dom_domain);
|
1996-06-22 21:59:52 +04:00
|
|
|
return ypdb;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2002-07-07 01:44:40 +04:00
|
|
|
makelock(struct _dom_binding *ypdb)
|
1996-06-22 21:59:52 +04:00
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
char path[MAXPATHLEN];
|
|
|
|
|
1998-07-13 16:01:03 +04:00
|
|
|
(void)snprintf(path, sizeof(path), "%s/%s.%ld", BINDINGDIR,
|
1996-06-22 21:59:52 +04:00
|
|
|
ypdb->dom_domain, ypdb->dom_vers);
|
|
|
|
|
|
|
|
if ((fd = open(path, O_CREAT|O_SHLOCK|O_RDWR|O_TRUNC, 0644)) == -1) {
|
1998-07-13 16:01:03 +04:00
|
|
|
(void)mkdir(BINDINGDIR, 0755);
|
1996-06-22 21:59:52 +04:00
|
|
|
if ((fd = open(path, O_CREAT|O_SHLOCK|O_RDWR|O_TRUNC, 0644)) == -1)
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if O_SHLOCK == 0
|
1998-07-13 16:01:03 +04:00
|
|
|
(void)flock(fd, LOCK_SH);
|
1996-06-22 21:59:52 +04:00
|
|
|
#endif
|
|
|
|
return fd;
|
|
|
|
}
|
1993-04-26 12:09:02 +04:00
|
|
|
|
1996-06-22 21:59:52 +04:00
|
|
|
static void
|
2002-07-07 01:44:40 +04:00
|
|
|
removelock(struct _dom_binding *ypdb)
|
1996-06-22 21:59:52 +04:00
|
|
|
{
|
|
|
|
char path[MAXPATHLEN];
|
1993-04-26 12:09:02 +04:00
|
|
|
|
1998-07-13 16:01:03 +04:00
|
|
|
(void)snprintf(path, sizeof(path), "%s/%s.%ld",
|
1996-06-22 21:59:52 +04:00
|
|
|
BINDINGDIR, ypdb->dom_domain, ypdb->dom_vers);
|
1998-07-13 16:01:03 +04:00
|
|
|
(void)unlink(path);
|
1996-06-22 21:59:52 +04:00
|
|
|
}
|
1996-03-31 01:49:08 +03:00
|
|
|
|
1996-06-22 21:59:52 +04:00
|
|
|
static void *
|
2002-07-07 01:44:40 +04:00
|
|
|
ypbindproc_null_2(SVCXPRT *transp, void *argp)
|
1993-04-26 12:09:02 +04:00
|
|
|
{
|
|
|
|
static char res;
|
|
|
|
|
1996-06-22 21:59:52 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
if (debug)
|
|
|
|
printf("ypbindproc_null_2\n");
|
|
|
|
#endif
|
1998-07-13 16:01:03 +04:00
|
|
|
(void)memset(&res, 0, sizeof(res));
|
1993-04-26 12:09:02 +04:00
|
|
|
return (void *)&res;
|
|
|
|
}
|
|
|
|
|
1996-06-22 21:59:52 +04:00
|
|
|
static void *
|
2002-07-07 01:44:40 +04:00
|
|
|
ypbindproc_domain_2(SVCXPRT *transp, void *argp)
|
1993-04-26 12:09:02 +04:00
|
|
|
{
|
|
|
|
static struct ypbind_resp res;
|
|
|
|
struct _dom_binding *ypdb;
|
1996-06-22 21:59:52 +04:00
|
|
|
char *arg = *(char **) argp;
|
1994-07-02 10:45:48 +04:00
|
|
|
time_t now;
|
1997-07-07 06:27:05 +04:00
|
|
|
int count;
|
1993-04-26 12:09:02 +04:00
|
|
|
|
1996-06-22 21:59:52 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
if (debug)
|
|
|
|
printf("ypbindproc_domain_2 %s\n", arg);
|
|
|
|
#endif
|
1997-07-07 06:27:05 +04:00
|
|
|
if (_yp_invalid_domain(arg))
|
|
|
|
return NULL;
|
|
|
|
|
1998-07-13 16:01:03 +04:00
|
|
|
(void)memset(&res, 0, sizeof res);
|
1993-04-26 12:09:02 +04:00
|
|
|
res.ypbind_status = YPBIND_FAIL_VAL;
|
|
|
|
|
1997-07-07 06:27:05 +04:00
|
|
|
for (count = 0, ypdb = ypbindlist;
|
|
|
|
ypdb != NULL;
|
|
|
|
ypdb = ypdb->dom_pnext, count++) {
|
|
|
|
if (count > 100)
|
|
|
|
return NULL; /* prevent denial of service */
|
1996-06-04 00:32:55 +04:00
|
|
|
if (!strcmp(ypdb->dom_domain, arg))
|
1993-04-26 12:09:02 +04:00
|
|
|
break;
|
1997-07-07 06:27:05 +04:00
|
|
|
}
|
1993-04-26 12:09:02 +04:00
|
|
|
|
1995-01-15 11:55:59 +03:00
|
|
|
if (ypdb == NULL) {
|
1996-06-22 21:59:52 +04:00
|
|
|
ypdb = makebinding(arg);
|
1993-04-26 12:09:02 +04:00
|
|
|
ypdb->dom_vers = YPVERS;
|
|
|
|
ypdb->dom_alive = 0;
|
|
|
|
ypdb->dom_lockfd = -1;
|
1996-06-22 21:59:52 +04:00
|
|
|
removelock(ypdb);
|
1996-03-31 01:49:08 +03:00
|
|
|
ypdb->dom_xid = unique_xid(ypdb);
|
1993-04-26 12:09:02 +04:00
|
|
|
ypdb->dom_pnext = ypbindlist;
|
|
|
|
ypbindlist = ypdb;
|
|
|
|
check++;
|
1996-06-22 21:59:52 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
if (debug)
|
|
|
|
printf("unknown domain %s\n", arg);
|
|
|
|
#endif
|
1993-04-26 12:09:02 +04:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
1996-06-22 21:59:52 +04:00
|
|
|
if (ypdb->dom_alive == 0) {
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (debug)
|
|
|
|
printf("dead domain %s\n", arg);
|
|
|
|
#endif
|
1993-04-26 12:09:02 +04:00
|
|
|
return NULL;
|
1996-06-22 21:59:52 +04:00
|
|
|
}
|
1993-04-26 12:09:02 +04:00
|
|
|
|
1994-07-02 10:45:48 +04:00
|
|
|
#ifdef HEURISTIC
|
|
|
|
time(&now);
|
|
|
|
if (now < ypdb->dom_ask_t + 5) {
|
1993-04-26 12:09:02 +04:00
|
|
|
/*
|
1994-07-02 10:45:48 +04:00
|
|
|
* Hmm. More than 2 requests in 5 seconds have indicated
|
|
|
|
* that my binding is possibly incorrect.
|
|
|
|
* Ok, do an immediate poll of the server.
|
1993-04-26 12:09:02 +04:00
|
|
|
*/
|
1994-07-02 10:45:48 +04:00
|
|
|
if (ypdb->dom_check_t >= now) {
|
|
|
|
/* don't flood it */
|
|
|
|
ypdb->dom_check_t = 0;
|
|
|
|
check++;
|
|
|
|
}
|
1993-04-26 12:09:02 +04:00
|
|
|
}
|
1994-07-02 10:45:48 +04:00
|
|
|
ypdb->dom_ask_t = now;
|
1993-04-26 12:09:02 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
res.ypbind_status = YPBIND_SUCC_VAL;
|
|
|
|
res.ypbind_respbody.ypbind_bindinfo.ypbind_binding_addr.s_addr =
|
|
|
|
ypdb->dom_server_addr.sin_addr.s_addr;
|
|
|
|
res.ypbind_respbody.ypbind_bindinfo.ypbind_binding_port =
|
2003-11-18 00:29:21 +03:00
|
|
|
ypdb->dom_server_addr.sin_port;
|
1996-06-22 21:59:52 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
if (debug)
|
|
|
|
printf("domain %s at %s/%d\n", ypdb->dom_domain,
|
|
|
|
inet_ntoa(ypdb->dom_server_addr.sin_addr),
|
|
|
|
ntohs(ypdb->dom_server_addr.sin_port));
|
|
|
|
#endif
|
1993-04-26 12:09:02 +04:00
|
|
|
return &res;
|
|
|
|
}
|
|
|
|
|
1996-06-22 21:59:52 +04:00
|
|
|
static void *
|
2002-07-07 01:44:40 +04:00
|
|
|
ypbindproc_setdom_2(SVCXPRT *transp, void *argp)
|
1993-04-26 12:09:02 +04:00
|
|
|
{
|
1996-06-22 21:59:52 +04:00
|
|
|
struct ypbind_setdom *sd = argp;
|
1993-04-26 12:09:02 +04:00
|
|
|
struct sockaddr_in *fromsin, bindsin;
|
1994-09-28 04:39:54 +03:00
|
|
|
static bool_t res;
|
1993-04-26 12:09:02 +04:00
|
|
|
|
1996-06-22 21:59:52 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
if (debug)
|
|
|
|
printf("ypbindproc_setdom_2 %s\n", inet_ntoa(bindsin.sin_addr));
|
|
|
|
#endif
|
1998-07-13 16:01:03 +04:00
|
|
|
(void)memset(&res, 0, sizeof(res));
|
1993-04-26 12:09:02 +04:00
|
|
|
fromsin = svc_getcaller(transp);
|
|
|
|
|
1996-10-01 04:22:27 +04:00
|
|
|
switch (ypbindmode) {
|
|
|
|
case YPBIND_SETLOCAL:
|
1996-06-22 21:59:52 +04:00
|
|
|
if (fromsin->sin_addr.s_addr != htonl(INADDR_LOOPBACK)) {
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (debug)
|
|
|
|
printf("ypset from %s denied\n",
|
|
|
|
inet_ntoa(fromsin->sin_addr));
|
|
|
|
#endif
|
|
|
|
return NULL;
|
|
|
|
}
|
1996-10-01 04:22:27 +04:00
|
|
|
/* FALLTHROUGH */
|
|
|
|
|
|
|
|
case YPBIND_SETALL:
|
|
|
|
been_ypset = 1;
|
1993-04-26 12:09:02 +04:00
|
|
|
break;
|
1996-10-01 04:22:27 +04:00
|
|
|
|
|
|
|
case YPBIND_DIRECT:
|
|
|
|
case YPBIND_BROADCAST:
|
1993-04-26 12:09:02 +04:00
|
|
|
default:
|
1996-06-22 21:59:52 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
if (debug)
|
|
|
|
printf("ypset denied\n");
|
|
|
|
#endif
|
|
|
|
return NULL;
|
1993-04-26 12:09:02 +04:00
|
|
|
}
|
|
|
|
|
1996-06-22 21:59:52 +04:00
|
|
|
if (ntohs(fromsin->sin_port) >= IPPORT_RESERVED) {
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (debug)
|
1999-08-16 06:59:22 +04:00
|
|
|
printf("ypset from unprivileged port denied\n");
|
1996-06-22 21:59:52 +04:00
|
|
|
#endif
|
1994-09-28 04:39:54 +03:00
|
|
|
return &res;
|
1996-06-22 21:59:52 +04:00
|
|
|
}
|
1993-11-15 11:20:05 +03:00
|
|
|
|
1996-06-22 21:59:52 +04:00
|
|
|
if (sd->ypsetdom_vers != YPVERS) {
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (debug)
|
|
|
|
printf("ypset with wrong version denied\n");
|
|
|
|
#endif
|
1994-09-28 04:39:54 +03:00
|
|
|
return &res;
|
1996-06-22 21:59:52 +04:00
|
|
|
}
|
1993-04-26 12:09:02 +04:00
|
|
|
|
1998-07-13 16:01:03 +04:00
|
|
|
(void)memset(&bindsin, 0, sizeof bindsin);
|
1993-04-26 12:09:02 +04:00
|
|
|
bindsin.sin_family = AF_INET;
|
1995-01-15 11:55:59 +03:00
|
|
|
bindsin.sin_len = sizeof(bindsin);
|
1996-06-22 21:59:52 +04:00
|
|
|
bindsin.sin_addr = sd->ypsetdom_addr;
|
|
|
|
bindsin.sin_port = sd->ypsetdom_port;
|
|
|
|
rpc_received(sd->ypsetdom_domain, &bindsin, 1);
|
1993-04-26 12:09:02 +04:00
|
|
|
|
1996-06-22 21:59:52 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
if (debug)
|
|
|
|
printf("ypset to %s succeeded\n", inet_ntoa(bindsin.sin_addr));
|
|
|
|
#endif
|
1993-04-26 12:09:02 +04:00
|
|
|
res = 1;
|
1994-09-28 04:39:54 +03:00
|
|
|
return &res;
|
1993-04-26 12:09:02 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-07-07 01:44:40 +04:00
|
|
|
ypbindprog_2(struct svc_req *rqstp, register SVCXPRT *transp)
|
1993-04-26 12:09:02 +04:00
|
|
|
{
|
|
|
|
union {
|
1996-06-04 00:32:55 +04:00
|
|
|
char ypbindproc_domain_2_arg[YPMAXDOMAIN + 1];
|
1993-04-26 12:09:02 +04:00
|
|
|
struct ypbind_setdom ypbindproc_setdom_2_arg;
|
2006-10-05 13:18:11 +04:00
|
|
|
void *alignment;
|
1993-04-26 12:09:02 +04:00
|
|
|
} argument;
|
|
|
|
struct authunix_parms *creds;
|
|
|
|
char *result;
|
1996-06-22 21:59:52 +04:00
|
|
|
xdrproc_t xdr_argument, xdr_result;
|
2002-07-07 01:44:40 +04:00
|
|
|
void *(*local)(SVCXPRT *, void *);
|
1993-04-26 12:09:02 +04:00
|
|
|
|
|
|
|
switch (rqstp->rq_proc) {
|
|
|
|
case YPBINDPROC_NULL:
|
|
|
|
xdr_argument = xdr_void;
|
|
|
|
xdr_result = xdr_void;
|
1996-06-22 21:59:52 +04:00
|
|
|
local = ypbindproc_null_2;
|
1993-04-26 12:09:02 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case YPBINDPROC_DOMAIN:
|
1996-05-30 00:11:10 +04:00
|
|
|
xdr_argument = xdr_ypdomain_wrap_string;
|
1993-04-26 12:09:02 +04:00
|
|
|
xdr_result = xdr_ypbind_resp;
|
1996-06-22 21:59:52 +04:00
|
|
|
local = ypbindproc_domain_2;
|
1993-04-26 12:09:02 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case YPBINDPROC_SETDOM:
|
1995-01-15 11:55:59 +03:00
|
|
|
switch (rqstp->rq_cred.oa_flavor) {
|
1993-04-26 12:09:02 +04:00
|
|
|
case AUTH_UNIX:
|
|
|
|
creds = (struct authunix_parms *)rqstp->rq_clntcred;
|
1995-01-15 11:55:59 +03:00
|
|
|
if (creds->aup_uid != 0) {
|
1993-04-26 12:09:02 +04:00
|
|
|
svcerr_auth(transp, AUTH_BADCRED);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
svcerr_auth(transp, AUTH_TOOWEAK);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
xdr_argument = xdr_ypbind_setdom;
|
|
|
|
xdr_result = xdr_void;
|
1996-06-22 21:59:52 +04:00
|
|
|
local = ypbindproc_setdom_2;
|
1993-04-26 12:09:02 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
svcerr_noproc(transp);
|
|
|
|
return;
|
|
|
|
}
|
1998-07-13 16:01:03 +04:00
|
|
|
(void)memset(&argument, 0, sizeof(argument));
|
1994-12-23 19:21:49 +03:00
|
|
|
if (!svc_getargs(transp, xdr_argument, (caddr_t)&argument)) {
|
1993-04-26 12:09:02 +04:00
|
|
|
svcerr_decode(transp);
|
|
|
|
return;
|
|
|
|
}
|
1996-06-22 21:59:52 +04:00
|
|
|
result = (*local)(transp, &argument);
|
1993-04-26 12:09:02 +04:00
|
|
|
if (result != NULL && !svc_sendreply(transp, xdr_result, result)) {
|
|
|
|
svcerr_systemerr(transp);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1996-06-22 21:59:52 +04:00
|
|
|
int
|
2002-07-07 01:44:40 +04:00
|
|
|
main(int argc, char *argv[])
|
1993-04-26 12:09:02 +04:00
|
|
|
{
|
|
|
|
struct timeval tv;
|
|
|
|
fd_set fdsr;
|
1994-09-28 04:39:54 +03:00
|
|
|
int width, lockfd;
|
1995-01-15 12:09:30 +03:00
|
|
|
int evil = 0, one;
|
1996-10-01 04:22:27 +04:00
|
|
|
char pathname[MAXPATHLEN];
|
|
|
|
struct stat st;
|
1993-04-26 12:09:02 +04:00
|
|
|
|
|
|
|
yp_get_default_domain(&domainname);
|
1996-06-22 21:59:52 +04:00
|
|
|
if (domainname[0] == '\0')
|
|
|
|
errx(1, "Domainname not set. Aborting.");
|
1993-04-26 12:09:02 +04:00
|
|
|
|
1996-10-01 04:22:27 +04:00
|
|
|
/*
|
|
|
|
* Per traditional ypbind(8) semantics, if a ypservers
|
|
|
|
* file does not exist, we default to broadcast mode.
|
|
|
|
* If the file does exist, we default to direct mode.
|
|
|
|
* Note that we can still override direct mode by passing
|
|
|
|
* the -broadcast flag.
|
|
|
|
*/
|
1996-10-02 09:55:05 +04:00
|
|
|
snprintf(pathname, sizeof(pathname), "%s/%s%s", BINDINGDIR,
|
|
|
|
domainname, YPSERVERSSUFF);
|
1996-10-01 04:22:27 +04:00
|
|
|
if (stat(pathname, &st) < 0) {
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (debug)
|
|
|
|
fprintf(stderr,
|
|
|
|
"%s does not exist, defaulting to broadcast\n",
|
|
|
|
pathname);
|
|
|
|
#endif
|
|
|
|
ypbindmode = YPBIND_BROADCAST;
|
|
|
|
} else
|
|
|
|
ypbindmode = YPBIND_DIRECT;
|
|
|
|
|
1995-01-15 12:09:30 +03:00
|
|
|
while (--argc) {
|
|
|
|
++argv;
|
1997-07-07 06:27:05 +04:00
|
|
|
if (!strcmp("-insecure", *argv))
|
|
|
|
insecure = 1;
|
|
|
|
else if (!strcmp("-ypset", *argv))
|
1996-10-01 04:22:27 +04:00
|
|
|
ypbindmode = YPBIND_SETALL;
|
1995-01-15 12:09:30 +03:00
|
|
|
else if (!strcmp("-ypsetme", *argv))
|
1996-10-01 04:22:27 +04:00
|
|
|
ypbindmode = YPBIND_SETLOCAL;
|
|
|
|
else if (!strcmp("-broadcast", *argv))
|
|
|
|
ypbindmode = YPBIND_BROADCAST;
|
1996-06-22 21:59:52 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
else if (!strcmp("-d", *argv))
|
|
|
|
debug++;
|
|
|
|
#endif
|
|
|
|
else
|
|
|
|
usage();
|
1993-04-26 12:09:02 +04:00
|
|
|
}
|
|
|
|
|
1998-08-21 13:39:04 +04:00
|
|
|
/* initialise syslog */
|
|
|
|
openlog("ypbind", LOG_PERROR | LOG_PID, LOG_DAEMON);
|
|
|
|
|
1993-04-26 12:09:02 +04:00
|
|
|
/* blow away everything in BINDINGDIR */
|
|
|
|
|
1996-10-01 04:22:27 +04:00
|
|
|
lockfd = open(_PATH_YPBIND_LOCK, O_CREAT|O_SHLOCK|O_RDWR|O_TRUNC, 0644);
|
1996-06-22 21:59:52 +04:00
|
|
|
if (lockfd == -1)
|
1996-10-01 04:22:27 +04:00
|
|
|
err(1, "Cannot create %s", _PATH_YPBIND_LOCK);
|
1996-06-22 21:59:52 +04:00
|
|
|
|
|
|
|
#if O_SHLOCK == 0
|
1998-07-13 16:01:03 +04:00
|
|
|
(void)flock(lockfd, LOCK_SH);
|
1994-09-28 04:39:54 +03:00
|
|
|
#endif
|
1993-04-26 12:09:02 +04:00
|
|
|
|
1998-07-13 16:01:03 +04:00
|
|
|
(void)pmap_unset(YPBINDPROG, YPBINDVERS);
|
1993-04-26 12:09:02 +04:00
|
|
|
|
1993-12-03 13:08:12 +03:00
|
|
|
udptransp = svcudp_create(RPC_ANYSOCK);
|
1996-06-22 21:59:52 +04:00
|
|
|
if (udptransp == NULL)
|
|
|
|
errx(1, "Cannot create udp service.");
|
|
|
|
|
1993-12-03 13:08:12 +03:00
|
|
|
if (!svc_register(udptransp, YPBINDPROG, YPBINDVERS, ypbindprog_2,
|
1996-06-22 21:59:52 +04:00
|
|
|
IPPROTO_UDP))
|
|
|
|
errx(1, "Unable to register (YPBINDPROG, YPBINDVERS, udp).");
|
1993-04-26 12:09:02 +04:00
|
|
|
|
1993-12-03 13:08:12 +03:00
|
|
|
tcptransp = svctcp_create(RPC_ANYSOCK, 0, 0);
|
1996-06-22 21:59:52 +04:00
|
|
|
if (tcptransp == NULL)
|
|
|
|
errx(1, "Cannot create tcp service.");
|
|
|
|
|
1993-12-03 13:08:12 +03:00
|
|
|
if (!svc_register(tcptransp, YPBINDPROG, YPBINDVERS, ypbindprog_2,
|
1996-06-22 21:59:52 +04:00
|
|
|
IPPROTO_TCP))
|
|
|
|
errx(1, "Unable to register (YPBINDPROG, YPBINDVERS, tcp).");
|
1993-04-26 12:09:02 +04:00
|
|
|
|
1996-10-01 04:22:27 +04:00
|
|
|
/* XXX use SOCK_STREAM for direct queries? */
|
1996-06-22 21:59:52 +04:00
|
|
|
if ((rpcsock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1)
|
|
|
|
err(1, "rpc socket");
|
|
|
|
if ((pingsock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1)
|
|
|
|
err(1, "ping socket");
|
1993-12-03 13:08:12 +03:00
|
|
|
|
1998-07-13 16:01:03 +04:00
|
|
|
(void)fcntl(rpcsock, F_SETFL, fcntl(rpcsock, F_GETFL, 0) | FNDELAY);
|
|
|
|
(void)fcntl(pingsock, F_SETFL, fcntl(pingsock, F_GETFL, 0) | FNDELAY);
|
1996-06-22 21:59:52 +04:00
|
|
|
|
1995-01-15 12:09:30 +03:00
|
|
|
one = 1;
|
1998-07-13 16:01:03 +04:00
|
|
|
(void)setsockopt(rpcsock, SOL_SOCKET, SO_BROADCAST, &one, sizeof(one));
|
1993-04-26 12:09:02 +04:00
|
|
|
rmtca.prog = YPPROG;
|
|
|
|
rmtca.vers = YPVERS;
|
|
|
|
rmtca.proc = YPPROC_DOMAIN_NONACK;
|
|
|
|
rmtca.xdr_args = NULL; /* set at call time */
|
|
|
|
rmtca.args_ptr = NULL; /* set at call time */
|
|
|
|
rmtcr.port_ptr = &rmtcr_port;
|
|
|
|
rmtcr.xdr_results = xdr_bool;
|
|
|
|
rmtcr.results_ptr = (caddr_t)&rmtcr_outval;
|
|
|
|
|
1997-07-07 06:27:05 +04:00
|
|
|
if (_yp_invalid_domain(domainname))
|
|
|
|
errx(1, "bad domainname: %s", domainname);
|
|
|
|
|
1993-04-26 12:09:02 +04:00
|
|
|
/* build initial domain binding, make it "unsuccessful" */
|
1996-06-22 21:59:52 +04:00
|
|
|
ypbindlist = makebinding(domainname);
|
1993-04-26 12:09:02 +04:00
|
|
|
ypbindlist->dom_vers = YPVERS;
|
|
|
|
ypbindlist->dom_alive = 0;
|
|
|
|
ypbindlist->dom_lockfd = -1;
|
1996-06-22 21:59:52 +04:00
|
|
|
removelock(ypbindlist);
|
1993-04-26 12:09:02 +04:00
|
|
|
|
1994-09-20 11:21:46 +04:00
|
|
|
checkwork();
|
|
|
|
|
1996-10-01 04:22:27 +04:00
|
|
|
for (;;) {
|
2003-09-05 18:59:37 +04:00
|
|
|
width = svc_maxfd;
|
|
|
|
if (rpcsock > width)
|
|
|
|
width = rpcsock;
|
|
|
|
if (pingsock > width)
|
|
|
|
width = pingsock;
|
|
|
|
width++;
|
1993-04-26 12:09:02 +04:00
|
|
|
fdsr = svc_fdset;
|
|
|
|
FD_SET(rpcsock, &fdsr);
|
1994-07-15 00:54:29 +04:00
|
|
|
FD_SET(pingsock, &fdsr);
|
1993-04-26 12:09:02 +04:00
|
|
|
tv.tv_sec = 1;
|
|
|
|
tv.tv_usec = 0;
|
|
|
|
|
1995-01-15 11:55:59 +03:00
|
|
|
switch (select(width, &fdsr, NULL, NULL, &tv)) {
|
1993-04-26 12:09:02 +04:00
|
|
|
case 0:
|
|
|
|
checkwork();
|
|
|
|
break;
|
|
|
|
case -1:
|
1998-08-21 13:39:04 +04:00
|
|
|
yp_log(LOG_WARNING, "select: %m");
|
1993-04-26 12:09:02 +04:00
|
|
|
break;
|
|
|
|
default:
|
1994-12-30 07:49:06 +03:00
|
|
|
if (FD_ISSET(rpcsock, &fdsr))
|
1993-04-26 12:09:02 +04:00
|
|
|
handle_replies();
|
1994-12-30 07:49:06 +03:00
|
|
|
if (FD_ISSET(pingsock, &fdsr))
|
1994-07-15 00:54:29 +04:00
|
|
|
handle_ping();
|
1993-04-26 12:09:02 +04:00
|
|
|
svc_getreqset(&fdsr);
|
1994-12-30 07:49:06 +03:00
|
|
|
if (check)
|
1993-04-26 12:09:02 +04:00
|
|
|
checkwork();
|
|
|
|
break;
|
|
|
|
}
|
1995-01-15 12:09:30 +03:00
|
|
|
|
|
|
|
if (!evil && ypbindlist->dom_alive) {
|
|
|
|
evil = 1;
|
1996-06-22 21:59:52 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
if (!debug)
|
|
|
|
#endif
|
1996-07-09 10:34:12 +04:00
|
|
|
daemon(0, 0);
|
1999-06-06 06:38:00 +04:00
|
|
|
pidfile(NULL);
|
1995-01-15 12:09:30 +03:00
|
|
|
}
|
1993-04-26 12:09:02 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1994-07-02 10:45:48 +04:00
|
|
|
* State transition is done like this:
|
|
|
|
*
|
1994-07-16 15:50:58 +04:00
|
|
|
* STATE EVENT ACTION NEWSTATE TIMEOUT
|
|
|
|
* no binding timeout broadcast no binding 5 sec
|
|
|
|
* no binding answer -- binding 60 sec
|
|
|
|
* binding timeout ping server checking 5 sec
|
|
|
|
* checking timeout ping server + broadcast checking 5 sec
|
|
|
|
* checking answer -- binding 60 sec
|
1993-04-26 12:09:02 +04:00
|
|
|
*/
|
1996-06-22 21:59:52 +04:00
|
|
|
void
|
2002-07-07 01:44:40 +04:00
|
|
|
checkwork(void)
|
1993-04-26 12:09:02 +04:00
|
|
|
{
|
|
|
|
struct _dom_binding *ypdb;
|
|
|
|
time_t t;
|
|
|
|
|
|
|
|
check = 0;
|
|
|
|
|
|
|
|
time(&t);
|
1995-01-15 11:55:59 +03:00
|
|
|
for (ypdb = ypbindlist; ypdb; ypdb = ypdb->dom_pnext) {
|
|
|
|
if (ypdb->dom_check_t < t) {
|
1994-07-15 00:54:29 +04:00
|
|
|
if (ypdb->dom_alive == 1)
|
|
|
|
ping(ypdb);
|
|
|
|
else
|
1996-10-01 04:22:27 +04:00
|
|
|
nag_servers(ypdb);
|
1993-04-26 12:09:02 +04:00
|
|
|
time(&t);
|
|
|
|
ypdb->dom_check_t = t + 5;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1996-06-22 21:59:52 +04:00
|
|
|
int
|
2002-07-07 01:44:40 +04:00
|
|
|
ping(struct _dom_binding *ypdb)
|
1994-07-15 00:54:29 +04:00
|
|
|
{
|
|
|
|
char *dom = ypdb->dom_domain;
|
1995-01-15 11:55:59 +03:00
|
|
|
struct rpc_msg msg;
|
1996-06-22 21:59:52 +04:00
|
|
|
char buf[BUFSIZE];
|
1994-07-15 00:54:29 +04:00
|
|
|
enum clnt_stat st;
|
|
|
|
int outlen;
|
|
|
|
AUTH *rpcua;
|
1995-01-15 11:55:59 +03:00
|
|
|
XDR xdr;
|
1994-07-15 00:54:29 +04:00
|
|
|
|
1998-07-13 16:01:03 +04:00
|
|
|
(void)memset(&xdr, 0, sizeof xdr);
|
|
|
|
(void)memset(&msg, 0, sizeof msg);
|
1994-07-15 00:54:29 +04:00
|
|
|
|
|
|
|
rpcua = authunix_create_default();
|
1996-06-22 21:59:52 +04:00
|
|
|
if (rpcua == NULL) {
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (debug)
|
|
|
|
printf("cannot get unix auth\n");
|
|
|
|
#endif
|
1994-07-15 00:54:29 +04:00
|
|
|
return RPC_SYSTEMERROR;
|
|
|
|
}
|
1996-06-22 21:59:52 +04:00
|
|
|
|
1995-01-15 11:55:59 +03:00
|
|
|
msg.rm_direction = CALL;
|
|
|
|
msg.rm_call.cb_rpcvers = RPC_MSG_VERSION;
|
|
|
|
msg.rm_call.cb_prog = YPPROG;
|
|
|
|
msg.rm_call.cb_vers = YPVERS;
|
|
|
|
msg.rm_call.cb_proc = YPPROC_DOMAIN_NONACK;
|
|
|
|
msg.rm_call.cb_cred = rpcua->ah_cred;
|
|
|
|
msg.rm_call.cb_verf = rpcua->ah_verf;
|
|
|
|
|
1996-03-31 01:49:08 +03:00
|
|
|
msg.rm_xid = ypdb->dom_xid;
|
1995-01-15 11:55:59 +03:00
|
|
|
xdrmem_create(&xdr, buf, sizeof buf, XDR_ENCODE);
|
|
|
|
if (!xdr_callmsg(&xdr, &msg)) {
|
1994-07-15 00:54:29 +04:00
|
|
|
st = RPC_CANTENCODEARGS;
|
|
|
|
AUTH_DESTROY(rpcua);
|
|
|
|
return st;
|
|
|
|
}
|
1996-06-04 00:44:51 +04:00
|
|
|
if (!xdr_ypdomain_wrap_string(&xdr, &dom)) {
|
1994-07-15 00:54:29 +04:00
|
|
|
st = RPC_CANTENCODEARGS;
|
|
|
|
AUTH_DESTROY(rpcua);
|
|
|
|
return st;
|
|
|
|
}
|
1995-01-15 11:55:59 +03:00
|
|
|
outlen = (int)xdr_getpos(&xdr);
|
|
|
|
xdr_destroy(&xdr);
|
|
|
|
if (outlen < 1) {
|
1994-07-15 00:54:29 +04:00
|
|
|
st = RPC_CANTENCODEARGS;
|
|
|
|
AUTH_DESTROY(rpcua);
|
|
|
|
return st;
|
|
|
|
}
|
|
|
|
AUTH_DESTROY(rpcua);
|
|
|
|
|
|
|
|
ypdb->dom_alive = 2;
|
|
|
|
if (sendto(pingsock, buf, outlen, 0,
|
|
|
|
(struct sockaddr *)&ypdb->dom_server_addr,
|
1996-06-22 21:59:52 +04:00
|
|
|
sizeof ypdb->dom_server_addr) == -1)
|
1998-08-21 13:39:04 +04:00
|
|
|
yp_log(LOG_WARNING, "ping: sendto: %m");
|
1994-07-15 00:54:29 +04:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
1996-10-01 04:22:27 +04:00
|
|
|
static int
|
2002-07-07 01:44:40 +04:00
|
|
|
nag_servers(struct _dom_binding *ypdb)
|
1993-04-26 12:09:02 +04:00
|
|
|
{
|
1994-07-01 23:40:23 +04:00
|
|
|
char *dom = ypdb->dom_domain;
|
1995-01-15 11:55:59 +03:00
|
|
|
struct rpc_msg msg;
|
1996-10-01 04:22:27 +04:00
|
|
|
char buf[BUFSIZE];
|
1993-04-26 12:09:02 +04:00
|
|
|
enum clnt_stat st;
|
1996-10-01 04:22:27 +04:00
|
|
|
int outlen;
|
1993-04-26 12:09:02 +04:00
|
|
|
AUTH *rpcua;
|
1995-01-15 11:55:59 +03:00
|
|
|
XDR xdr;
|
1993-04-26 12:09:02 +04:00
|
|
|
|
1996-05-30 00:11:10 +04:00
|
|
|
rmtca.xdr_args = xdr_ypdomain_wrap_string;
|
|
|
|
rmtca.args_ptr = (char *)&dom;
|
1993-04-26 12:09:02 +04:00
|
|
|
|
1998-07-13 16:01:03 +04:00
|
|
|
(void)memset(&xdr, 0, sizeof xdr);
|
|
|
|
(void)memset(&msg, 0, sizeof msg);
|
1993-04-26 12:09:02 +04:00
|
|
|
|
|
|
|
rpcua = authunix_create_default();
|
1996-06-22 21:59:52 +04:00
|
|
|
if (rpcua == NULL) {
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (debug)
|
|
|
|
printf("cannot get unix auth\n");
|
|
|
|
#endif
|
1993-04-26 12:09:02 +04:00
|
|
|
return RPC_SYSTEMERROR;
|
|
|
|
}
|
1995-01-15 11:55:59 +03:00
|
|
|
msg.rm_direction = CALL;
|
|
|
|
msg.rm_call.cb_rpcvers = RPC_MSG_VERSION;
|
|
|
|
msg.rm_call.cb_prog = PMAPPROG;
|
|
|
|
msg.rm_call.cb_vers = PMAPVERS;
|
|
|
|
msg.rm_call.cb_proc = PMAPPROC_CALLIT;
|
|
|
|
msg.rm_call.cb_cred = rpcua->ah_cred;
|
|
|
|
msg.rm_call.cb_verf = rpcua->ah_verf;
|
|
|
|
|
1996-03-31 01:49:08 +03:00
|
|
|
msg.rm_xid = ypdb->dom_xid;
|
1995-01-15 11:55:59 +03:00
|
|
|
xdrmem_create(&xdr, buf, sizeof buf, XDR_ENCODE);
|
|
|
|
if (!xdr_callmsg(&xdr, &msg)) {
|
1993-04-26 12:09:02 +04:00
|
|
|
st = RPC_CANTENCODEARGS;
|
|
|
|
AUTH_DESTROY(rpcua);
|
|
|
|
return st;
|
|
|
|
}
|
1995-01-15 11:55:59 +03:00
|
|
|
if (!xdr_rmtcall_args(&xdr, &rmtca)) {
|
1993-04-26 12:09:02 +04:00
|
|
|
st = RPC_CANTENCODEARGS;
|
|
|
|
AUTH_DESTROY(rpcua);
|
|
|
|
return st;
|
|
|
|
}
|
1995-01-15 11:55:59 +03:00
|
|
|
outlen = (int)xdr_getpos(&xdr);
|
|
|
|
xdr_destroy(&xdr);
|
|
|
|
if (outlen < 1) {
|
1994-07-15 00:54:29 +04:00
|
|
|
st = RPC_CANTENCODEARGS;
|
1993-04-26 12:09:02 +04:00
|
|
|
AUTH_DESTROY(rpcua);
|
|
|
|
return st;
|
|
|
|
}
|
|
|
|
AUTH_DESTROY(rpcua);
|
|
|
|
|
1995-01-15 11:55:59 +03:00
|
|
|
if (ypdb->dom_lockfd != -1) {
|
1998-07-13 16:01:03 +04:00
|
|
|
(void)close(ypdb->dom_lockfd);
|
1994-07-02 10:45:48 +04:00
|
|
|
ypdb->dom_lockfd = -1;
|
1996-06-22 21:59:52 +04:00
|
|
|
removelock(ypdb);
|
1994-07-02 10:45:48 +04:00
|
|
|
}
|
1994-07-01 23:40:23 +04:00
|
|
|
|
1994-07-16 15:50:58 +04:00
|
|
|
if (ypdb->dom_alive == 2) {
|
|
|
|
/*
|
|
|
|
* This resolves the following situation:
|
|
|
|
* ypserver on other subnet was once bound,
|
|
|
|
* but rebooted and is now using a different port
|
|
|
|
*/
|
1996-10-01 04:22:27 +04:00
|
|
|
struct sockaddr_in bindsin;
|
|
|
|
|
|
|
|
memset(&bindsin, 0, sizeof bindsin);
|
|
|
|
bindsin.sin_family = AF_INET;
|
|
|
|
bindsin.sin_len = sizeof(bindsin);
|
|
|
|
bindsin.sin_port = htons(PMAPPORT);
|
1995-01-15 11:55:59 +03:00
|
|
|
bindsin.sin_addr = ypdb->dom_server_addr.sin_addr;
|
1996-10-01 04:22:27 +04:00
|
|
|
|
1995-01-15 11:55:59 +03:00
|
|
|
if (sendto(rpcsock, buf, outlen, 0, (struct sockaddr *)&bindsin,
|
1996-06-22 21:59:52 +04:00
|
|
|
sizeof bindsin) == -1)
|
2006-10-01 23:43:15 +04:00
|
|
|
yp_log(LOG_WARNING, "nag_servers: sendto: %m");
|
1994-07-16 15:50:58 +04:00
|
|
|
}
|
1996-10-01 04:22:27 +04:00
|
|
|
|
|
|
|
switch (ypbindmode) {
|
|
|
|
case YPBIND_SETALL:
|
|
|
|
case YPBIND_SETLOCAL:
|
|
|
|
if (been_ypset)
|
|
|
|
return direct_set(buf, outlen, ypdb);
|
|
|
|
/* FALLTHROUGH */
|
|
|
|
|
|
|
|
case YPBIND_BROADCAST:
|
|
|
|
return broadcast(buf, outlen);
|
|
|
|
|
|
|
|
case YPBIND_DIRECT:
|
|
|
|
return direct(buf, outlen);
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2002-07-07 01:44:40 +04:00
|
|
|
broadcast(char *buf, int outlen)
|
1996-10-01 04:22:27 +04:00
|
|
|
{
|
2000-04-11 15:36:47 +04:00
|
|
|
struct ifaddrs *ifap, *ifa;
|
1996-10-01 04:22:27 +04:00
|
|
|
struct sockaddr_in bindsin;
|
2000-04-11 15:36:47 +04:00
|
|
|
struct in_addr in;
|
1996-10-01 04:22:27 +04:00
|
|
|
|
|
|
|
memset(&bindsin, 0, sizeof bindsin);
|
|
|
|
bindsin.sin_family = AF_INET;
|
|
|
|
bindsin.sin_len = sizeof(bindsin);
|
|
|
|
bindsin.sin_port = htons(PMAPPORT);
|
|
|
|
|
2000-04-11 15:36:47 +04:00
|
|
|
if (getifaddrs(&ifap) != 0) {
|
|
|
|
yp_log(LOG_WARNING, "broadcast: getifaddrs: %m");
|
|
|
|
return (-1);
|
1993-04-26 12:09:02 +04:00
|
|
|
}
|
2000-04-11 15:36:47 +04:00
|
|
|
for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
|
|
|
|
if (ifa->ifa_addr->sa_family != AF_INET)
|
1993-04-26 12:09:02 +04:00
|
|
|
continue;
|
2000-04-11 15:36:47 +04:00
|
|
|
if ((ifa->ifa_flags & IFF_UP) == 0)
|
1993-04-26 12:09:02 +04:00
|
|
|
continue;
|
|
|
|
|
2000-04-11 15:36:47 +04:00
|
|
|
switch (ifa->ifa_flags & (IFF_LOOPBACK | IFF_BROADCAST)) {
|
|
|
|
case IFF_BROADCAST:
|
|
|
|
if (!ifa->ifa_broadaddr)
|
1993-04-26 12:09:02 +04:00
|
|
|
continue;
|
2000-04-11 15:36:47 +04:00
|
|
|
if (ifa->ifa_broadaddr->sa_family != AF_INET)
|
1993-04-26 12:09:02 +04:00
|
|
|
continue;
|
2000-04-11 15:36:47 +04:00
|
|
|
in = ((struct sockaddr_in *)ifa->ifa_broadaddr)->sin_addr;
|
|
|
|
break;
|
|
|
|
case IFF_LOOPBACK:
|
|
|
|
in = ((struct sockaddr_in *)ifa->ifa_addr)->sin_addr;
|
|
|
|
break;
|
|
|
|
default:
|
1993-04-26 12:09:02 +04:00
|
|
|
continue;
|
2000-04-11 15:36:47 +04:00
|
|
|
}
|
1993-04-26 12:09:02 +04:00
|
|
|
|
1995-01-15 11:55:59 +03:00
|
|
|
bindsin.sin_addr = in;
|
|
|
|
if (sendto(rpcsock, buf, outlen, 0, (struct sockaddr *)&bindsin,
|
2000-04-11 15:36:47 +04:00
|
|
|
bindsin.sin_len) == -1)
|
1998-08-21 13:39:04 +04:00
|
|
|
yp_log(LOG_WARNING, "broadcast: sendto: %m");
|
1993-04-26 12:09:02 +04:00
|
|
|
}
|
2000-04-11 15:36:47 +04:00
|
|
|
freeifaddrs(ifap);
|
|
|
|
return (0);
|
1993-04-26 12:09:02 +04:00
|
|
|
}
|
|
|
|
|
1996-10-01 04:22:27 +04:00
|
|
|
static int
|
2002-07-07 01:44:40 +04:00
|
|
|
direct(char *buf, int outlen)
|
1996-10-01 04:22:27 +04:00
|
|
|
{
|
|
|
|
static FILE *df;
|
|
|
|
static char ypservers_path[MAXPATHLEN];
|
|
|
|
char line[_POSIX2_LINE_MAX];
|
|
|
|
char *p;
|
|
|
|
struct hostent *hp;
|
|
|
|
struct sockaddr_in bindsin;
|
|
|
|
int i, count = 0;
|
|
|
|
|
|
|
|
if (df)
|
|
|
|
rewind(df);
|
|
|
|
else {
|
|
|
|
snprintf(ypservers_path, sizeof(ypservers_path),
|
1996-10-02 09:55:05 +04:00
|
|
|
"%s/%s%s", BINDINGDIR, domainname, YPSERVERSSUFF);
|
1996-10-01 04:22:27 +04:00
|
|
|
df = fopen(ypservers_path, "r");
|
1998-08-21 13:39:04 +04:00
|
|
|
if (df == NULL) {
|
2001-01-11 04:47:55 +03:00
|
|
|
yp_log(LOG_ERR, "%s: ", ypservers_path);
|
1998-08-21 13:39:04 +04:00
|
|
|
exit(1);
|
|
|
|
}
|
1996-10-01 04:22:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
memset(&bindsin, 0, sizeof bindsin);
|
|
|
|
bindsin.sin_family = AF_INET;
|
|
|
|
bindsin.sin_len = sizeof(bindsin);
|
|
|
|
bindsin.sin_port = htons(PMAPPORT);
|
|
|
|
|
|
|
|
while(fgets(line, sizeof(line), df) != NULL) {
|
|
|
|
/* skip lines that are too big */
|
|
|
|
p = strchr(line, '\n');
|
|
|
|
if (p == NULL) {
|
|
|
|
int c;
|
|
|
|
|
|
|
|
while ((c = getc(df)) != '\n' && c != EOF)
|
|
|
|
;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
*p = '\0';
|
|
|
|
p = line;
|
2004-10-30 19:51:20 +04:00
|
|
|
while (isspace((unsigned char)*p))
|
1996-10-01 04:22:27 +04:00
|
|
|
p++;
|
|
|
|
if (*p == '#')
|
|
|
|
continue;
|
|
|
|
hp = gethostbyname(p);
|
|
|
|
if (!hp) {
|
2001-01-11 04:47:55 +03:00
|
|
|
yp_log(LOG_WARNING, "%s: %s", p, hstrerror(h_errno));
|
1996-10-01 04:22:27 +04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/* step through all addresses in case first is unavailable */
|
|
|
|
for (i = 0; hp->h_addr_list[i]; i++) {
|
|
|
|
memmove(&bindsin.sin_addr, hp->h_addr_list[0],
|
|
|
|
hp->h_length);
|
|
|
|
if (sendto(rpcsock, buf, outlen, 0,
|
|
|
|
(struct sockaddr *)&bindsin, sizeof bindsin) < 0) {
|
1998-08-21 13:39:04 +04:00
|
|
|
yp_log(LOG_WARNING, "direct: sendto: %m");
|
1996-10-01 04:22:27 +04:00
|
|
|
continue;
|
|
|
|
} else
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
1998-08-21 13:39:04 +04:00
|
|
|
if (!count) {
|
2001-01-11 04:47:55 +03:00
|
|
|
yp_log(LOG_WARNING, "no contactable servers found in %s",
|
1996-10-01 04:22:27 +04:00
|
|
|
ypservers_path);
|
1998-08-21 13:39:04 +04:00
|
|
|
return -1;
|
|
|
|
}
|
1996-10-01 04:22:27 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2002-07-07 01:44:40 +04:00
|
|
|
direct_set(char *buf, int outlen, struct _dom_binding *ypdb)
|
1996-10-01 04:22:27 +04:00
|
|
|
{
|
|
|
|
struct sockaddr_in bindsin;
|
|
|
|
char path[MAXPATHLEN];
|
|
|
|
struct iovec iov[2];
|
|
|
|
struct ypbind_resp ybr;
|
|
|
|
SVCXPRT dummy_svc;
|
|
|
|
int fd, bytes;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Gack, we lose if binding file went away. We reset
|
|
|
|
* "been_set" if this happens, otherwise we'll never
|
|
|
|
* bind again.
|
|
|
|
*/
|
1998-02-12 06:32:51 +03:00
|
|
|
snprintf(path, sizeof(path), "%s/%s.%ld", BINDINGDIR,
|
1996-10-01 04:22:27 +04:00
|
|
|
ypdb->dom_domain, ypdb->dom_vers);
|
|
|
|
|
|
|
|
if ((fd = open(path, O_SHLOCK|O_RDONLY, 0644)) == -1) {
|
1998-08-21 13:39:04 +04:00
|
|
|
yp_log(LOG_WARNING, "%s: %m", path);
|
1996-10-01 04:22:27 +04:00
|
|
|
been_ypset = 0;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if O_SHLOCK == 0
|
1998-07-13 16:01:03 +04:00
|
|
|
(void)flock(fd, LOCK_SH);
|
1996-10-01 04:22:27 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Read the binding file... */
|
|
|
|
iov[0].iov_base = (caddr_t)&(dummy_svc.xp_port);
|
|
|
|
iov[0].iov_len = sizeof(dummy_svc.xp_port);
|
|
|
|
iov[1].iov_base = (caddr_t)&ybr;
|
|
|
|
iov[1].iov_len = sizeof(ybr);
|
|
|
|
bytes = readv(fd, iov, 2);
|
|
|
|
(void)close(fd);
|
|
|
|
if (bytes != (iov[0].iov_len + iov[1].iov_len)) {
|
|
|
|
/* Binding file corrupt? */
|
1998-08-21 13:39:04 +04:00
|
|
|
yp_log(LOG_WARNING, "%s: %m", path);
|
1996-10-01 04:22:27 +04:00
|
|
|
been_ypset = 0;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
bindsin.sin_addr =
|
|
|
|
ybr.ypbind_respbody.ypbind_bindinfo.ypbind_binding_addr;
|
|
|
|
|
|
|
|
if (sendto(rpcsock, buf, outlen, 0, (struct sockaddr *)&bindsin,
|
|
|
|
sizeof(bindsin)) < 0) {
|
1998-08-21 13:39:04 +04:00
|
|
|
yp_log(LOG_WARNING, "direct_set: sendto: %m");
|
1996-10-01 04:22:27 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1996-06-22 21:59:52 +04:00
|
|
|
static enum clnt_stat
|
2002-07-07 01:44:40 +04:00
|
|
|
handle_replies(void)
|
1993-04-26 12:09:02 +04:00
|
|
|
{
|
1996-06-22 21:59:52 +04:00
|
|
|
char buf[BUFSIZE];
|
2006-05-10 00:18:05 +04:00
|
|
|
socklen_t fromlen;
|
|
|
|
int inlen;
|
1996-03-31 01:49:08 +03:00
|
|
|
struct _dom_binding *ypdb;
|
1993-04-26 12:09:02 +04:00
|
|
|
struct sockaddr_in raddr;
|
|
|
|
struct rpc_msg msg;
|
|
|
|
XDR xdr;
|
|
|
|
|
|
|
|
recv_again:
|
1998-07-13 16:01:03 +04:00
|
|
|
(void)memset(&xdr, 0, sizeof(xdr));
|
|
|
|
(void)memset(&msg, 0, sizeof(msg));
|
1993-04-26 12:09:02 +04:00
|
|
|
msg.acpted_rply.ar_verf = _null_auth;
|
|
|
|
msg.acpted_rply.ar_results.where = (caddr_t)&rmtcr;
|
|
|
|
msg.acpted_rply.ar_results.proc = xdr_rmtcallres;
|
|
|
|
|
|
|
|
try_again:
|
1998-07-13 16:01:03 +04:00
|
|
|
fromlen = sizeof(struct sockaddr);
|
1993-04-26 12:09:02 +04:00
|
|
|
inlen = recvfrom(rpcsock, buf, sizeof buf, 0,
|
|
|
|
(struct sockaddr *)&raddr, &fromlen);
|
1995-01-15 11:55:59 +03:00
|
|
|
if (inlen < 0) {
|
|
|
|
if (errno == EINTR)
|
1993-04-26 12:09:02 +04:00
|
|
|
goto try_again;
|
|
|
|
return RPC_CANTRECV;
|
|
|
|
}
|
1995-01-15 11:55:59 +03:00
|
|
|
if (inlen < sizeof(u_int32_t))
|
1993-04-26 12:09:02 +04:00
|
|
|
goto recv_again;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* see if reply transaction id matches sent id.
|
|
|
|
* If so, decode the results.
|
|
|
|
*/
|
|
|
|
xdrmem_create(&xdr, buf, (u_int)inlen, XDR_DECODE);
|
1995-01-15 11:55:59 +03:00
|
|
|
if (xdr_replymsg(&xdr, &msg)) {
|
|
|
|
if ((msg.rm_reply.rp_stat == MSG_ACCEPTED) &&
|
|
|
|
(msg.acpted_rply.ar_stat == SUCCESS)) {
|
1998-02-12 06:32:51 +03:00
|
|
|
raddr.sin_port = htons((u_short)rmtcr_port);
|
1996-03-31 01:49:08 +03:00
|
|
|
ypdb = xid2ypdb(msg.rm_xid);
|
|
|
|
if (ypdb != NULL)
|
|
|
|
rpc_received(ypdb->dom_domain, &raddr, 0);
|
1993-04-26 12:09:02 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
xdr.x_op = XDR_FREE;
|
|
|
|
msg.acpted_rply.ar_results.proc = xdr_void;
|
|
|
|
xdr_destroy(&xdr);
|
|
|
|
|
|
|
|
return RPC_SUCCESS;
|
|
|
|
}
|
|
|
|
|
1996-06-22 21:59:52 +04:00
|
|
|
static enum clnt_stat
|
2002-07-07 01:44:40 +04:00
|
|
|
handle_ping(void)
|
1994-07-15 00:54:29 +04:00
|
|
|
{
|
1996-06-22 21:59:52 +04:00
|
|
|
char buf[BUFSIZE];
|
2006-05-10 00:18:05 +04:00
|
|
|
socklen_t fromlen;
|
|
|
|
int inlen;
|
1996-03-31 01:49:08 +03:00
|
|
|
struct _dom_binding *ypdb;
|
1994-07-15 00:54:29 +04:00
|
|
|
struct sockaddr_in raddr;
|
|
|
|
struct rpc_msg msg;
|
|
|
|
XDR xdr;
|
|
|
|
bool_t res;
|
|
|
|
|
|
|
|
recv_again:
|
1998-07-13 16:01:03 +04:00
|
|
|
(void)memset(&xdr, 0, sizeof(xdr));
|
|
|
|
(void)memset(&msg, 0, sizeof(msg));
|
1994-07-15 00:54:29 +04:00
|
|
|
msg.acpted_rply.ar_verf = _null_auth;
|
|
|
|
msg.acpted_rply.ar_results.where = (caddr_t)&res;
|
|
|
|
msg.acpted_rply.ar_results.proc = xdr_bool;
|
|
|
|
|
|
|
|
try_again:
|
|
|
|
fromlen = sizeof (struct sockaddr);
|
|
|
|
inlen = recvfrom(pingsock, buf, sizeof buf, 0,
|
|
|
|
(struct sockaddr *)&raddr, &fromlen);
|
1995-01-15 11:55:59 +03:00
|
|
|
if (inlen < 0) {
|
|
|
|
if (errno == EINTR)
|
1994-07-15 00:54:29 +04:00
|
|
|
goto try_again;
|
|
|
|
return RPC_CANTRECV;
|
|
|
|
}
|
1995-01-15 11:55:59 +03:00
|
|
|
if (inlen < sizeof(u_int32_t))
|
1994-07-15 00:54:29 +04:00
|
|
|
goto recv_again;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* see if reply transaction id matches sent id.
|
|
|
|
* If so, decode the results.
|
|
|
|
*/
|
|
|
|
xdrmem_create(&xdr, buf, (u_int)inlen, XDR_DECODE);
|
1995-01-15 11:55:59 +03:00
|
|
|
if (xdr_replymsg(&xdr, &msg)) {
|
|
|
|
if ((msg.rm_reply.rp_stat == MSG_ACCEPTED) &&
|
|
|
|
(msg.acpted_rply.ar_stat == SUCCESS)) {
|
1996-03-31 01:49:08 +03:00
|
|
|
ypdb = xid2ypdb(msg.rm_xid);
|
|
|
|
if (ypdb != NULL)
|
|
|
|
rpc_received(ypdb->dom_domain, &raddr, 0);
|
1994-07-15 00:54:29 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
xdr.x_op = XDR_FREE;
|
|
|
|
msg.acpted_rply.ar_results.proc = xdr_void;
|
|
|
|
xdr_destroy(&xdr);
|
|
|
|
|
|
|
|
return RPC_SUCCESS;
|
|
|
|
}
|
|
|
|
|
1993-04-26 12:09:02 +04:00
|
|
|
/*
|
|
|
|
* LOOPBACK IS MORE IMPORTANT: PUT IN HACK
|
|
|
|
*/
|
1996-06-22 21:59:52 +04:00
|
|
|
void
|
2002-07-07 01:44:40 +04:00
|
|
|
rpc_received(char *dom, struct sockaddr_in *raddrp, int force)
|
1993-04-26 12:09:02 +04:00
|
|
|
{
|
|
|
|
struct _dom_binding *ypdb;
|
1993-12-03 13:08:12 +03:00
|
|
|
struct iovec iov[2];
|
|
|
|
struct ypbind_resp ybr;
|
1993-04-26 12:09:02 +04:00
|
|
|
int fd;
|
|
|
|
|
1996-06-22 21:59:52 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
if (debug)
|
|
|
|
printf("returned from %s about %s\n",
|
|
|
|
inet_ntoa(raddrp->sin_addr), dom);
|
|
|
|
#endif
|
1993-04-26 12:09:02 +04:00
|
|
|
|
1995-01-15 11:55:59 +03:00
|
|
|
if (dom == NULL)
|
1993-04-26 12:09:02 +04:00
|
|
|
return;
|
|
|
|
|
1997-07-07 06:27:05 +04:00
|
|
|
if (_yp_invalid_domain(dom))
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* don't support insecure servers by default */
|
|
|
|
if (!insecure && ntohs(raddrp->sin_port) >= IPPORT_RESERVED)
|
|
|
|
return;
|
|
|
|
|
1995-01-15 11:55:59 +03:00
|
|
|
for (ypdb = ypbindlist; ypdb; ypdb = ypdb->dom_pnext)
|
|
|
|
if (!strcmp(ypdb->dom_domain, dom))
|
1993-04-26 12:09:02 +04:00
|
|
|
break;
|
|
|
|
|
1995-01-15 11:55:59 +03:00
|
|
|
if (ypdb == NULL) {
|
|
|
|
if (force == 0)
|
1993-04-26 12:09:02 +04:00
|
|
|
return;
|
1996-06-22 21:59:52 +04:00
|
|
|
ypdb = makebinding(dom);
|
1993-04-26 12:09:02 +04:00
|
|
|
ypdb->dom_lockfd = -1;
|
|
|
|
ypdb->dom_pnext = ypbindlist;
|
|
|
|
ypbindlist = ypdb;
|
|
|
|
}
|
|
|
|
|
1994-07-01 23:40:23 +04:00
|
|
|
/* soft update, alive */
|
1995-01-15 11:55:59 +03:00
|
|
|
if (ypdb->dom_alive == 1 && force == 0) {
|
|
|
|
if (!memcmp(&ypdb->dom_server_addr, raddrp,
|
|
|
|
sizeof ypdb->dom_server_addr)) {
|
1994-07-01 23:40:23 +04:00
|
|
|
ypdb->dom_alive = 1;
|
1996-06-22 21:59:52 +04:00
|
|
|
/* recheck binding in 60 sec */
|
|
|
|
ypdb->dom_check_t = time(NULL) + 60;
|
1994-07-01 23:40:23 +04:00
|
|
|
}
|
1993-04-26 12:09:02 +04:00
|
|
|
return;
|
1994-07-01 23:40:23 +04:00
|
|
|
}
|
|
|
|
|
1998-07-13 16:01:03 +04:00
|
|
|
(void)memcpy(&ypdb->dom_server_addr, raddrp,
|
1996-06-22 21:59:52 +04:00
|
|
|
sizeof ypdb->dom_server_addr);
|
|
|
|
/* recheck binding in 60 seconds */
|
|
|
|
ypdb->dom_check_t = time(NULL) + 60;
|
1993-04-26 12:09:02 +04:00
|
|
|
ypdb->dom_vers = YPVERS;
|
|
|
|
ypdb->dom_alive = 1;
|
|
|
|
|
1995-01-15 11:55:59 +03:00
|
|
|
if (ypdb->dom_lockfd != -1)
|
1998-07-13 16:01:03 +04:00
|
|
|
(void)close(ypdb->dom_lockfd);
|
1993-04-26 12:09:02 +04:00
|
|
|
|
1996-06-22 21:59:52 +04:00
|
|
|
if ((fd = makelock(ypdb)) == -1)
|
|
|
|
return;
|
1993-04-26 12:09:02 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* ok, if BINDINGDIR exists, and we can create the binding file,
|
|
|
|
* then write to it..
|
|
|
|
*/
|
|
|
|
ypdb->dom_lockfd = fd;
|
1993-12-03 13:08:12 +03:00
|
|
|
|
|
|
|
iov[0].iov_base = (caddr_t)&(udptransp->xp_port);
|
|
|
|
iov[0].iov_len = sizeof udptransp->xp_port;
|
|
|
|
iov[1].iov_base = (caddr_t)&ybr;
|
|
|
|
iov[1].iov_len = sizeof ybr;
|
|
|
|
|
1998-07-13 16:01:03 +04:00
|
|
|
(void)memset(&ybr, 0, sizeof ybr);
|
1993-12-03 13:08:12 +03:00
|
|
|
ybr.ypbind_status = YPBIND_SUCC_VAL;
|
1996-06-22 21:59:52 +04:00
|
|
|
ybr.ypbind_respbody.ypbind_bindinfo.ypbind_binding_addr =
|
|
|
|
raddrp->sin_addr;
|
|
|
|
ybr.ypbind_respbody.ypbind_bindinfo.ypbind_binding_port =
|
|
|
|
raddrp->sin_port;
|
|
|
|
|
|
|
|
if (writev(ypdb->dom_lockfd, iov, 2) !=
|
|
|
|
iov[0].iov_len + iov[1].iov_len) {
|
1998-08-21 13:39:04 +04:00
|
|
|
yp_log(LOG_WARNING, "writev: %m");
|
1998-07-13 16:01:03 +04:00
|
|
|
(void)close(ypdb->dom_lockfd);
|
1996-06-22 21:59:52 +04:00
|
|
|
removelock(ypdb);
|
1993-04-26 12:09:02 +04:00
|
|
|
ypdb->dom_lockfd = -1;
|
|
|
|
}
|
|
|
|
}
|
1996-03-31 01:49:08 +03:00
|
|
|
|
1996-06-22 21:59:52 +04:00
|
|
|
static struct _dom_binding *
|
2002-07-07 01:44:40 +04:00
|
|
|
xid2ypdb(u_int32_t xid)
|
1996-03-31 01:49:08 +03:00
|
|
|
{
|
|
|
|
struct _dom_binding *ypdb;
|
|
|
|
|
|
|
|
for (ypdb = ypbindlist; ypdb; ypdb = ypdb->dom_pnext)
|
|
|
|
if (ypdb->dom_xid == xid)
|
|
|
|
break;
|
|
|
|
return (ypdb);
|
|
|
|
}
|
|
|
|
|
1997-07-07 06:27:05 +04:00
|
|
|
static u_int32_t
|
2002-07-07 01:44:40 +04:00
|
|
|
unique_xid(struct _dom_binding *ypdb)
|
1996-03-31 01:49:08 +03:00
|
|
|
{
|
1997-07-07 06:27:05 +04:00
|
|
|
u_int32_t tmp_xid;
|
1996-03-31 01:49:08 +03:00
|
|
|
|
1998-02-12 06:32:51 +03:00
|
|
|
tmp_xid = (u_int32_t)(((u_long)ypdb) & 0xffffffff);
|
1996-03-31 01:49:08 +03:00
|
|
|
while (xid2ypdb(tmp_xid) != NULL)
|
|
|
|
tmp_xid++;
|
|
|
|
|
|
|
|
return tmp_xid;
|
|
|
|
}
|