summaryrefslogtreecommitdiffstats
path: root/usr.sbin
diff options
context:
space:
mode:
authorwpaul <wpaul@FreeBSD.org>1995-12-23 21:35:35 +0000
committerwpaul <wpaul@FreeBSD.org>1995-12-23 21:35:35 +0000
commit3be99a55ffecd32ecfa45a807b33d45bf2a13178 (patch)
treece4c9de08d67a611ebd2b072d1809f830327a6b7 /usr.sbin
parent6ef4e82f0f2c507c27c3787fb8e0d899e2dbadca (diff)
downloadFreeBSD-src-3be99a55ffecd32ecfa45a807b33d45bf2a13178.zip
FreeBSD-src-3be99a55ffecd32ecfa45a807b33d45bf2a13178.tar.gz
A few small tweaks related to ypxfr:
- Add a ypxfr_callback() function that we can use to signal failure to yppush(8) in the event that we can't fork()/exec() ypxfr(8). yppush only checks the return status from YPPROC_XFR enough to determine that the RPC succeded: it relies on its callback service to figure out whether or not the transfer actually worked. - Give yp_dblookup.c its own debug variable (ypdb_debug) so that DB access debugging messages can be turned on or off independent of the program's global debug messages. - Have the Makefile rpcgen the ypushresp_xfr_1() client stub for us and nuke the unneeded rule for yp_xdr.c that I left in by mistake (the XDR filters live in libc now).
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/ypserv/Makefile14
-rw-r--r--usr.sbin/ypserv/yp_dblookup.c16
-rw-r--r--usr.sbin/ypserv/yp_extern.h3
-rw-r--r--usr.sbin/ypserv/yp_main.c10
-rw-r--r--usr.sbin/ypserv/yp_server.c78
5 files changed, 84 insertions, 37 deletions
diff --git a/usr.sbin/ypserv/Makefile b/usr.sbin/ypserv/Makefile
index 5249b46..6f0ca9b 100644
--- a/usr.sbin/ypserv/Makefile
+++ b/usr.sbin/ypserv/Makefile
@@ -1,27 +1,27 @@
-# $Id: Makefile,v 1.1.1.1 1995/12/16 20:54:17 wpaul Exp $
+# $Id: Makefile,v 1.2 1995/12/16 23:01:04 bde Exp $
PROG= ypserv
SRCS= yp_svc.c yp_server.c yp_dblookup.c yp_dnslookup.c \
- yp_main.c yp_error.c yp_access.c
+ ypxfr_clnt.c yp_main.c yp_error.c yp_access.c
MAN8= ypserv.8
CFLAGS+= -I.
-CLEANFILES= yp_svc.c yp.h
+CLEANFILES= yp_svc.c ypxfr_clnt.c yp.h
RPCSRC= ${.DESTDIR}/usr/include/rpcsvc/yp.x
-RPCGEN= rpcgen -I -C -DYPSERV_ONLY
+RPCGEN= rpcgen -I -C
# We need to remove the 'static' keyword from _rpcsvcstate so that
# yp_main.c can see it.
yp_svc.c: ${RPCSRC} yp.h
rm -f ${.TARGET}
- ${RPCGEN} -m ${RPCSRC} | \
+ ${RPCGEN} -DYPSERV_ONLY -m ${RPCSRC} | \
sed s/"static int _rpcsvcstate"/"int _rpcsvcstate"/g > ${.TARGET}
-yp_xdr.c: ${RPCSRC} yp.h
- ${RPCGEN} -c -o ${.TARGET} ${RPCSRC}
+ypxfr_clnt.c: ${RPCSRC} yp.h
+ ${RPCGEN} -DYPPUSH_ONLY -l -o ${.TARGET} ${RPCSRC}
yp.h: ${RPCSRC}
${RPCGEN} -h -o ${.TARGET} ${RPCSRC}
diff --git a/usr.sbin/ypserv/yp_dblookup.c b/usr.sbin/ypserv/yp_dblookup.c
index 79df52e..b35c64f 100644
--- a/usr.sbin/ypserv/yp_dblookup.c
+++ b/usr.sbin/ypserv/yp_dblookup.c
@@ -29,7 +29,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: yp_dblookup.c,v 1.13 1995/12/16 04:46:10 wpaul Exp $
+ * $Id: yp_dblookup.c,v 1.1.1.1 1995/12/16 20:54:17 wpaul Exp $
*
*/
#include <stdio.h>
@@ -45,7 +45,7 @@
#include "yp.h"
#include "yp_extern.h"
-extern int debug_flag;
+int ypdb_debug = 0;
int yp_errno = YP_TRUE;
#define PERM_SECURE (S_IRUSR|S_IWUSR)
@@ -118,7 +118,7 @@ int yp_get_record(domain,map,key,data,allow)
{
DB *dbp;
- if (debug)
+ if (ypdb_debug)
yp_error("Looking up key [%.*s] in map [%s]",
key->size, key->data, map);
@@ -141,7 +141,7 @@ int yp_get_record(domain,map,key,data,allow)
(void)(dbp->close)(dbp);
- if (debug)
+ if (ypdb_debug)
yp_error("Result of lookup: key: [%.*s] data: [%.*s]",
key->size, key->data, data->size, data->data);
@@ -154,7 +154,7 @@ int yp_first_record(dbp,key,data)
DBT *data;
{
- if (debug)
+ if (ypdb_debug)
yp_error("Retrieving first key in map.");
if ((dbp->seq)(dbp,key,data,R_FIRST))
@@ -166,7 +166,7 @@ int yp_first_record(dbp,key,data)
return(YP_BADDB);
}
- if (debug)
+ if (ypdb_debug)
yp_error("Result of lookup: key: [%.*s] data: [%.*s]",
key->size, key->data, data->size, data->data);
@@ -184,7 +184,7 @@ int yp_next_record(dbp,key,data,all)
if (key == NULL || key->data == NULL)
return(yp_first_record(dbp,key,data));
- if (debug)
+ if (ypdb_debug)
yp_error("Retreiving next key, previous was: [%.*s]",
key->size, key->data);
@@ -209,7 +209,7 @@ int yp_next_record(dbp,key,data,all)
*key = lkey;
*data = ldata;
- if (debug)
+ if (ypdb_debug)
yp_error("Result of lookup: key: [%.*s] data: [%.*s]",
key->size, key->data, data->size, data->data);
diff --git a/usr.sbin/ypserv/yp_extern.h b/usr.sbin/ypserv/yp_extern.h
index f16ba20..e94d253 100644
--- a/usr.sbin/ypserv/yp_extern.h
+++ b/usr.sbin/ypserv/yp_extern.h
@@ -29,7 +29,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: yp_extern.h,v 1.9 1995/12/16 04:01:55 wpaul Exp $
+ * $Id: yp_extern.h,v 1.1.1.1 1995/12/16 20:54:17 wpaul Exp $
*/
#include <stdio.h>
#include <string.h>
@@ -57,6 +57,7 @@
*/
extern int debug;
+extern int ypdb_debug;
extern int do_dns;
extern int children;
extern char *progname;
diff --git a/usr.sbin/ypserv/yp_main.c b/usr.sbin/ypserv/yp_main.c
index 21748cf..94956b7 100644
--- a/usr.sbin/ypserv/yp_main.c
+++ b/usr.sbin/ypserv/yp_main.c
@@ -29,7 +29,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: yp_main.c,v 1.12 1995/12/11 22:38:19 wpaul Exp $
+ * $Id: yp_main.c,v 1.1.1.1 1995/12/16 20:54:17 wpaul Exp $
*/
/*
@@ -65,7 +65,7 @@
#define _RPCSVC_CLOSEDOWN 120
#ifndef lint
-static char rcsid[] = "$Id: yp_main.c,v 1.12 1995/12/11 22:38:19 wpaul Exp $";
+static char rcsid[] = "$Id: yp_main.c,v 1.1.1.1 1995/12/16 20:54:17 wpaul Exp $";
#endif /* not lint */
int _rpcpmstart; /* Started by a port monitor ? */
static int _rpcfdtype;
@@ -196,9 +196,9 @@ main(argc, argv)
int argc;
char *argv[];
{
- register SVCXPRT *transp;
+ register SVCXPRT *transp = NULL;
int sock;
- int proto;
+ int proto = 0;
struct sockaddr_in saddr;
int asize = sizeof (saddr);
int ch;
@@ -206,7 +206,7 @@ main(argc, argv)
while ((ch = getopt(argc, argv, "hdnkp:")) != EOF) {
switch(ch) {
case 'd':
- debug = 1;
+ debug = ypdb_debug = 1;
break;
case 'n':
do_dns = 1;
diff --git a/usr.sbin/ypserv/yp_server.c b/usr.sbin/ypserv/yp_server.c
index fcc8bbd..dacead6 100644
--- a/usr.sbin/ypserv/yp_server.c
+++ b/usr.sbin/ypserv/yp_server.c
@@ -42,9 +42,10 @@
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
+#include <rpc/rpc.h>
#ifndef lint
-static char rcsid[] = "$Id: yp_server.c,v 1.18 1995/12/16 04:01:55 wpaul Exp $";
+static char rcsid[] = "$Id: yp_server.c,v 1.1.1.1 1995/12/16 20:54:17 wpaul Exp $";
#endif /* not lint */
int forked = 0;
@@ -135,7 +136,7 @@ ypproc_match_2_svc(ypreq_key *argp, struct svc_req *rqstp)
*/
if (do_dns && result.stat != YP_TRUE && strstr(argp->map, "hosts")) {
- char *rval;
+ char *rval = NULL;
/* DNS lookups can take time -- do them in a subprocess */
@@ -268,10 +269,41 @@ ypproc_next_2_svc(ypreq_key *argp, struct svc_req *rqstp)
return (&result);
}
+static void ypxfr_callback(rval,addr,transid,prognum,port)
+ ypxfrstat rval;
+ struct sockaddr_in *addr;
+ unsigned int transid;
+ unsigned int prognum;
+ unsigned long port;
+{
+ CLIENT *clnt;
+ int sock = RPC_ANYSOCK;
+ struct timeval timeout;
+ yppushresp_xfr ypxfr_resp;
+
+ timeout.tv_sec = 20;
+ timeout.tv_usec = 0;
+ addr->sin_port = htons(port);
+
+ if ((clnt = clntudp_create(addr, prognum, 1, timeout, &sock)) == NULL)
+ yp_error("%s", clnt_spcreateerror("failed to establish \
+callback handle"));
+
+ ypxfr_resp.status = rval;
+ ypxfr_resp.transid = transid;
+
+ if (yppushproc_xfrresp_1(&ypxfr_resp, clnt) == NULL)
+ yp_error("%s", clnt_sperror(clnt, "ypxfr callback failed"));
+
+ clnt_destroy(clnt);
+ return;
+}
+
ypresp_xfr *
ypproc_xfr_2_svc(ypreq_xfr *argp, struct svc_req *rqstp)
{
static ypresp_xfr result;
+ struct sockaddr_in *rqhost;
if (yp_access(argp->map_parms.map, (struct svc_req *)rqstp)) {
result.xfrstat = YPXFR_REFUSED;
@@ -288,39 +320,53 @@ ypproc_xfr_2_svc(ypreq_xfr *argp, struct svc_req *rqstp)
return(&result);
}
+ rqhost = svc_getcaller(rqstp->rq_xprt);
+
switch(fork()) {
case 0:
{
char g[11], t[11], p[11];
- struct sockaddr_in *rqhost;
char ypxfr_command[MAXPATHLEN + 2];
- rqhost = svc_getcaller(rqstp->rq_xprt);
sprintf (ypxfr_command, "%sypxfr", _PATH_LIBEXEC);
sprintf (t, "%u", argp->transid);
sprintf (g, "%u", argp->prog);
sprintf (p, "%u", argp->port);
- children++;
- forked = 0;
- execl(ypxfr_command, "ypxfr", "-d", argp->map_parms.domain,
- "-h", argp->map_parms.peer, "-f", "-C", t, g,
- inet_ntoa(rqhost->sin_addr), p, argp->map_parms.map,
- NULL);
+ if (debug)
+ close(0); close(1); close(2);
+ if (strcmp(yp_dir, _PATH_YP)) {
+ execl(ypxfr_command, "ypxfr", "-d", argp->map_parms.domain,
+ "-h", argp->map_parms.peer, "-f", "-p", yp_dir, "-C", t,
+ g, inet_ntoa(rqhost->sin_addr), p, argp->map_parms.map,
+ NULL);
+ } else {
+ execl(ypxfr_command, "ypxfr", "-d", argp->map_parms.domain,
+ "-h", argp->map_parms.peer, "-f", "-C", t, g,
+ inet_ntoa(rqhost->sin_addr), p, argp->map_parms.map,
+ NULL);
+ }
+ forked++;
yp_error("ypxfr execl(): %s", strerror(errno));
- return(NULL);
+ ypxfr_callback(YPXFR_XFRERR,rqhost,argp->transid,
+ argp->prog,argp->port);
+ result.xfrstat = YPXFR_XFRERR;
+ return(&result);
+ break;
}
case -1:
yp_error("ypxfr fork(): %s", strerror(errno));
+ ypxfr_callback(YPXFR_XFRERR,rqhost,argp->transid,
+ argp->prog,argp->port);
result.xfrstat = YPXFR_XFRERR;
+ return(&result);
break;
default:
- result.xfrstat = YPXFR_SUCC;
- forked++;
+ children++;
+ forked = 0;
break;
}
-
- result.transid = argp->transid;
- return (&result);
+ /* Don't return anything -- it's up to ypxfr to do that. */
+ return (NULL);
}
void *
OpenPOWER on IntegriCloud