From bc66df81bb910c5e0bcb9475b2c11c977d1c197e Mon Sep 17 00:00:00 2001 From: Bill Paul Date: Sun, 4 Feb 1996 05:18:44 +0000 Subject: [PATCH] ypxfr_getmap.c: - Handle 'empty' maps more gracefully. By empty I mean a valid map that just happens not to have any entries in it, such as you would get if you built a map database from an empty file. Previously, trying to ypxfr such a map would yield an 'NIS map/database error' which is not the correct behavior. ypxfr_misc: - Make sure to free() or xdr_free() dynamically allocated memory in ypxfr_get_master() as necessary. --- libexec/ypxfr/ypxfr_getmap.c | 7 ++++-- libexec/ypxfr/ypxfr_misc.c | 41 ++++++++++++++++++++++++++---------- 2 files changed, 35 insertions(+), 13 deletions(-) diff --git a/libexec/ypxfr/ypxfr_getmap.c b/libexec/ypxfr/ypxfr_getmap.c index 702b5cb6c522..bac203cd6a90 100644 --- a/libexec/ypxfr/ypxfr_getmap.c +++ b/libexec/ypxfr/ypxfr_getmap.c @@ -29,7 +29,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: ypxfr_getmap.c,v 1.6 1995/12/24 04:39:04 wpaul Exp $ + * $Id: ypxfr_getmap.c,v 1.7 1996/02/03 23:09:28 wpaul Exp $ */ #include #include @@ -40,7 +40,7 @@ #include "ypxfr_extern.h" #ifndef lint -static const char rcsid[] = "$Id: ypxfr_getmap.c,v 1.6 1995/12/24 04:39:04 wpaul Exp $"; +static const char rcsid[] = "$Id: ypxfr_getmap.c,v 1.7 1996/02/03 23:09:28 wpaul Exp $"; #endif extern bool_t xdr_ypresp_all_seq __P(( XDR *, unsigned long * )); @@ -90,6 +90,9 @@ int ypxfr_get_map(map, domain, host, callback) clnt_destroy(clnt); + if (status == YP_NOMORE) + return(0); + if (status != YP_TRUE) { yp_errno = YPXFR_YPERR; return(1); diff --git a/libexec/ypxfr/ypxfr_misc.c b/libexec/ypxfr/ypxfr_misc.c index 4093dae5daaa..8a6059a6e2a4 100644 --- a/libexec/ypxfr/ypxfr_misc.c +++ b/libexec/ypxfr/ypxfr_misc.c @@ -29,8 +29,11 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: ypxfr_misc.c,v 1.6 1995/12/24 04:39:55 wpaul Exp $ + * $Id: ypxfr_misc.c,v 1.7 1996/02/04 04:05:30 wpaul Exp $ */ +#include +#include +#include #include #include struct dom_binding {}; @@ -38,7 +41,7 @@ struct dom_binding {}; #include "ypxfr_extern.h" #ifndef lint -static const char rcsid[] = "$Id: ypxfr_misc.c,v 1.6 1995/12/24 04:39:55 wpaul Exp $"; +static const char rcsid[] = "$Id: ypxfr_misc.c,v 1.7 1996/02/04 04:05:30 wpaul Exp $"; #endif char *ypxfrerr_string(code) @@ -108,12 +111,23 @@ char *ypxfrerr_string(code) * an NIS client in order to be an NIS server). */ +/* + * Careful: yp_master() returns a pointer to a dynamically allocated + * buffer. Calling ypproc_master_2() ourselves also returns a pointer + * to dynamically allocated memory, though this time it's memory + * allocated by the XDR routines. We have to rememver to free() or + * xdr_free() the memory as required to avoid leaking memory. + */ char *ypxfr_get_master(domain,map,source,yplib) char *domain; char *map; char *source; const int yplib; { + static char mastername[MAXPATHLEN + 2]; + + bzero((char *)&mastername, sizeof(mastername)); + if (yplib) { int res; char *master; @@ -131,8 +145,11 @@ char *ypxfr_get_master(domain,map,source,yplib) break; } return(NULL); - } else - return(master); + } else { + snprintf(mastername, sizeof(mastername), "%s", master); + free(master); + return((char *)&mastername); + } } else { CLIENT *clnt; ypresp_master *resp; @@ -170,7 +187,9 @@ failed")); } return(NULL); } - return(resp->peer); + snprintf(mastername, sizeof(mastername), "%s", resp->peer); + xdr_free(xdr_ypresp_master, (char *)&resp); + return((char *)&mastername); } } @@ -185,13 +204,13 @@ unsigned long ypxfr_get_order(domain, map, source, yplib) int res; if ((res = yp_order(domain, map, (int *)&order))) { switch (res) { - case (YPERR_DOMAIN): + case YPERR_DOMAIN: yp_errno = YPXFR_NODOM; break; - case (YPERR_MAP): + case YPERR_MAP: yp_errno = YPXFR_NOMAP; break; - case (YPERR_YPERR): + case YPERR_YPERR: default: yp_errno = YPXFR_YPERR; break; @@ -222,13 +241,13 @@ failed")); clnt_destroy(clnt); if (resp->stat != YP_TRUE) { switch (resp->stat) { - case (YP_NODOM): + case YP_NODOM: yp_errno = YPXFR_NODOM; break; - case (YP_NOMAP): + case YP_NOMAP: yp_errno = YPXFR_NOMAP; break; - case (YP_YPERR): + case YP_YPERR: default: yp_errno = YPXFR_YPERR; break;