From 81a82d4dfd8407c94eaf04f2164f7c9d15ad784f Mon Sep 17 00:00:00 2001 From: Bill Paul Date: Fri, 25 Oct 1996 16:13:09 +0000 Subject: Give ypxfr the ability to detect the presence of the YP_INTERDOMAIN and YP_SECURE flags so that it can properly add them to newly created maps when needed. This applies only when using the 'standard' method for map transfers. When using rpc.ypxfrd, the whole map is copied verbatim, along with any special entries that may be encoded in it. Also made -Wall a little quieter for ypxfrd_getmap.c. --- libexec/ypxfr/ypxfr_extern.h | 3 ++- libexec/ypxfr/ypxfr_main.c | 38 ++++++++++++++++++++++++++++++-- libexec/ypxfr/ypxfr_misc.c | 50 +++++++++++++++++++++++++++++++++++++++++-- libexec/ypxfr/ypxfrd_getmap.c | 7 ++++-- 4 files changed, 91 insertions(+), 7 deletions(-) (limited to 'libexec') diff --git a/libexec/ypxfr/ypxfr_extern.h b/libexec/ypxfr/ypxfr_extern.h index b18282ea90c0..f826499e3d8e 100644 --- a/libexec/ypxfr/ypxfr_extern.h +++ b/libexec/ypxfr/ypxfr_extern.h @@ -29,7 +29,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: ypxfr_extern.h,v 1.7 1996/06/03 03:10:42 wpaul Exp $ + * $Id: ypxfr_extern.h,v 1.7 1996/06/03 03:10:42 wpaul Exp wpaul $ */ #include #include @@ -56,6 +56,7 @@ extern int yp_get_record __P(( const char *, const char *, const DBT *, DBT *, i extern int ypxfr_get_map __P(( char *, char *, char *, int (*)() )); extern char *ypxfr_get_master __P(( char *, char *, char *, const int )); extern unsigned long ypxfr_get_order __P(( char *, char *, char *, const int )); +extern int ypxfr_match __P(( char *, char *, char *, char *, unsigned long )); extern char *ypxfxerr_string __P(( ypxfrstat )); extern int ypxfrd_get_map __P(( char *, char *, char *, char *)); extern int callrpc __P(( char *, int, int, int, xdrproc_t, char *, xdrproc_t, char *)); diff --git a/libexec/ypxfr/ypxfr_main.c b/libexec/ypxfr/ypxfr_main.c index f26c5cb6c91b..821bf871da4b 100644 --- a/libexec/ypxfr/ypxfr_main.c +++ b/libexec/ypxfr/ypxfr_main.c @@ -29,7 +29,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: ypxfr_main.c,v 1.18 1996/10/20 19:44:45 wpaul Exp $ + * $Id: ypxfr_main.c,v 1.19 1996/10/25 15:58:15 wpaul Exp $ */ #include #include @@ -51,7 +51,7 @@ struct dom_binding {}; #include "ypxfr_extern.h" #ifndef lint -static const char rcsid[] = "$Id: ypxfr_main.c,v 1.18 1996/10/20 19:44:45 wpaul Exp $"; +static const char rcsid[] = "$Id: ypxfr_main.c,v 1.19 1996/10/25 15:58:15 wpaul Exp $"; #endif char *progname = "ypxfr"; @@ -163,6 +163,8 @@ main(argc,argv) char buf[MAXPATHLEN + 2]; DBT key, data; int remoteport; + int interdom = 0; + int secure = 0; debug = 1; @@ -352,6 +354,14 @@ the local domain name isn't set"); ypxfr_exit(YPXFR_YPERR,NULL); } + if (ypxfr_match(ypxfr_master, ypxfr_source_domain, ypxfr_mapname, + "YP_INTERDOMAIN", sizeof("YP_INTERDOMAIN") - 1)) + interdom++; + + if (ypxfr_match(ypxfr_master, ypxfr_source_domain, ypxfr_mapname, + "YP_SECURE", sizeof("YP_SECURE") - 1)) + secure++; + key.data = "YP_LAST_MODIFIED"; key.size = sizeof("YP_LAST_MODIFIED") - 1; @@ -469,6 +479,30 @@ the local domain name isn't set"); ypxfr_exit(YPXFR_DBM,&ypxfr_temp_map); } + if (interdom) { + key.data = "YP_INTERDOMAIN"; + key.size = sizeof("YP_INTERDOMAIN") - 1; + data.data = ""; + data.size = 0; + + if (yp_put_record(dbp, &key, &data, 0) != YP_TRUE) { + yp_error("failed to add interdomain flag to database"); + ypxfr_exit(YPXFR_DBM,&ypxfr_temp_map); + } + } + + if (secure) { + key.data = "YP_SECURE"; + key.size = sizeof("YP_SECURE") - 1; + data.data = ""; + data.size = 0; + + if (yp_put_record(dbp, &key, &data, 0) != YP_TRUE) { + yp_error("failed to add secure flag to database"); + ypxfr_exit(YPXFR_DBM,&ypxfr_temp_map); + } + } + /* Now suck over the contents of the map from the master. */ if (ypxfr_get_map(ypxfr_mapname,ypxfr_source_domain, diff --git a/libexec/ypxfr/ypxfr_misc.c b/libexec/ypxfr/ypxfr_misc.c index 2c0e895ad70c..93efdb0d6ae4 100644 --- a/libexec/ypxfr/ypxfr_misc.c +++ b/libexec/ypxfr/ypxfr_misc.c @@ -29,8 +29,10 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: ypxfr_misc.c,v 1.8 1996/06/02 05:12:00 wpaul Exp $ + * $Id: ypxfr_misc.c,v 1.9 1996/10/25 15:58:15 wpaul Exp $ */ +#include +#include #include #include #include @@ -41,7 +43,7 @@ struct dom_binding {}; #include "ypxfr_extern.h" #ifndef lint -static const char rcsid[] = "$Id: ypxfr_misc.c,v 1.8 1996/06/02 05:12:00 wpaul Exp $"; +static const char rcsid[] = "$Id: ypxfr_misc.c,v 1.9 1996/10/25 15:58:15 wpaul Exp $"; #endif char *ypxfrerr_string(code) @@ -257,3 +259,47 @@ failed")); return(resp->ordernum); } } + +int ypxfr_match(server, domain, map, key, keylen) + char *server; + char *domain; + char *map; + char *key; + unsigned long keylen; +{ + ypreq_key ypkey; + ypresp_val *ypval; + CLIENT *clnt; + static char buf[YPMAXRECORD + 2]; + + bzero((char *)buf, sizeof(buf)); + + if ((clnt = clnt_create(server, YPPROG,YPVERS,"udp")) == NULL) { + yp_error("failed to create UDP handle: %s", + clnt_spcreateerror(server)); + return(0); + } + + ypkey.domain = domain; + ypkey.map = map; + ypkey.key.keydat_len = keylen; + ypkey.key.keydat_val = key; + + if ((ypval = ypproc_match_2(&ypkey, clnt)) == NULL) { + clnt_destroy(clnt); + yp_error("%s: %s", server, + clnt_sperror(clnt,"YPPROC_MATCH failed")); + return(0); + } + + clnt_destroy(clnt); + + if (ypval->stat != YP_TRUE) { + xdr_free(xdr_ypresp_val, (char *)ypval); + return(0); + } + + xdr_free(xdr_ypresp_val, (char *)ypval); + + return(1); +} diff --git a/libexec/ypxfr/ypxfrd_getmap.c b/libexec/ypxfr/ypxfrd_getmap.c index e598883f8a41..7e9cd007fff4 100644 --- a/libexec/ypxfr/ypxfrd_getmap.c +++ b/libexec/ypxfr/ypxfrd_getmap.c @@ -29,9 +29,12 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: ypxfrd_getmap.c,v 1.7 1996/06/02 19:51:33 wpaul Exp wpaul $ + * $Id: ypxfrd_getmap.c,v 1.9 1996/10/25 15:58:15 wpaul Exp $ */ +#include +#include +#include #include #include #include @@ -44,7 +47,7 @@ #include "ypxfr_extern.h" #ifndef lint -static const char rcsid[] = "$Id: ypxfrd_getmap.c,v 1.7 1996/06/02 19:51:33 wpaul Exp wpaul $"; +static const char rcsid[] = "$Id: ypxfrd_getmap.c,v 1.9 1996/10/25 15:58:15 wpaul Exp $"; #endif int fp = 0; -- cgit v1.3