Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/ypserv/ypxfr yppush RPC is supposed to return yppus...



details:   https://anonhg.NetBSD.org/src/rev/e9066d0e4651
branches:  trunk
changeset: 748794:e9066d0e4651
user:      chuck <chuck%NetBSD.org@localhost>
date:      Thu Nov 05 15:23:55 2009 +0000

description:
yppush RPC is supposed to return yppush_status error/status codes
(e.g. YPPUSH_SUCC, YPPUSH_NOMAP, etc.).

Functions like yp_master, yp_order_host, yp_master_host, and
yp_match_host return YPERR-style error codes.  YPERR-style error
codes do not directly correspond to yppush_status codes, so it
is a bad idea to just directly YPERR codes into the yppush return
status value (it causes failing yppush runs to print confusing
error messages).

Change ypxfr.c to convert the YPERR codes to YPPUSH codes.

diffstat:

 usr.sbin/ypserv/ypxfr/ypxfr.c |  42 ++++++++++++++++++++++++++++++++++++++----
 1 files changed, 38 insertions(+), 4 deletions(-)

diffs (119 lines):

diff -r c1406b9c4510 -r e9066d0e4651 usr.sbin/ypserv/ypxfr/ypxfr.c
--- a/usr.sbin/ypserv/ypxfr/ypxfr.c     Thu Nov 05 14:22:54 2009 +0000
+++ b/usr.sbin/ypserv/ypxfr/ypxfr.c     Thu Nov 05 15:23:55 2009 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ypxfr.c,v 1.17 2009/10/20 00:51:15 snj Exp $   */
+/*     $NetBSD: ypxfr.c,v 1.18 2009/11/05 15:23:55 chuck Exp $ */
 
 /*
  * Copyright (c) 1994 Mats O Jansson <moj%stacken.kth.se@localhost>
@@ -28,7 +28,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: ypxfr.c,v 1.17 2009/10/20 00:51:15 snj Exp $");
+__RCSID("$NetBSD: ypxfr.c,v 1.18 2009/11/05 15:23:55 chuck Exp $");
 #endif
 
 #include <sys/param.h>
@@ -58,6 +58,7 @@
 
 DBM    *db;
 
+static int yperr2yppush(int);
 static int ypxfr_foreach(int, char *, int, char *, int, char *);
 
 int    main(int, char *[]);
@@ -150,7 +151,7 @@
                fprintf(stderr, "usage: %s [-cf] [-d domain] [-h host] %s\n",
                   getprogname(),
                   "[-s domain] [-C tid prog ipadd port] mapname");
-               goto punt;
+               exit(1);
        }
 
 #ifdef DEBUG
@@ -190,7 +191,7 @@
                if (status == 0)
                        status = YPPUSH_SUCC;
                else {
-                       status = -status;
+                       status = YPPUSH_MADDR;
                        goto punt;
                }
        }
@@ -266,6 +267,30 @@
        exit (0);
 }
 
+/*
+ * yperr2yppush: convert error codes from functions like yp_order_host,
+ * yp_master_host, and yp_match_host into YPPUSH rpc status values.
+ */
+static int
+yperr2yppush(int yperr) {
+       switch (yperr) {
+       case YPERR_DOMAIN:
+               return(YPPUSH_NODOM);
+       case YPERR_MAP:
+               return(YPPUSH_NOMAP);
+       case YPERR_KEY:
+               return(YPPUSH_YPERR);
+       case YPERR_BADDB:
+               return(YPPUSH_YPERR);
+       }
+
+       /*
+        * generic error status for the rest (BADARGS, RPC, YPERR, RESRC,
+        * NOMORE, PMAP, YPBIND, YPSERV, NODOM, VERS, ACCESS, BUSY)
+        */
+       return(YPPUSH_XFRERR);   /* generic error status */
+}
+
 static int
 ypxfr_foreach(int status, char *keystr, int keylen, char *valstr,
              int vallen, char *data)
@@ -284,6 +309,7 @@
        val.dptr = valstr;
        val.dsize = strlen(valstr);
 
+        /* XXX: suspect... ignoring return value here */
        ypdb_store(db, key, val, YPDB_INSERT);
 
        return (0);
@@ -365,6 +391,8 @@
                        status = YPPUSH_AGE;
                else
                        status = YPPUSH_SUCC;
+       } else {
+               status = yperr2yppush(status);
        }
 
        return status;
@@ -470,6 +498,8 @@
                        status = YPPUSH_SUCC;
                else
                        status = YPPUSH_DBM;
+       } else {
+               status = yperr2yppush(status);
        }
 
        return status;
@@ -502,6 +532,8 @@
                        else
                                status = YPPUSH_DBM;
                }
+       } else {
+               status = yperr2yppush(status);
        }
 
        return status;
@@ -534,6 +566,8 @@
                        else
                                status = YPPUSH_DBM;
                }
+       } else {
+               status = yperr2yppush(status);
        }
 
        return status;



Home | Main Index | Thread Index | Old Index