diff options
author | Mats O Jansson <maja@cvs.openbsd.org> | 1997-02-09 09:49:38 +0000 |
---|---|---|
committer | Mats O Jansson <maja@cvs.openbsd.org> | 1997-02-09 09:49:38 +0000 |
commit | c47737c3754d9757fbbc40a5744a8a08dc9550f2 (patch) | |
tree | f3c924d3a9c5debf585f8848a60e2efbe10706ba /usr.sbin | |
parent | 1e17a8a2bbcb16a6e3e8319596774d98301a9122 (diff) |
Add another routine in ypdb (ypdb_open_suf) that doesn't add the suffix to
the database name. The suffix is added in the call to mkstemp. Now ypdb and
mkstemp can coexist and do what we excpect. All code from 1.12 has been
reintegrated now.
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/ypserv/common/ypdb.c | 40 | ||||
-rw-r--r-- | usr.sbin/ypserv/common/ypdb.h | 3 | ||||
-rw-r--r-- | usr.sbin/ypserv/ypxfr/ypxfr.c | 63 |
3 files changed, 66 insertions, 40 deletions
diff --git a/usr.sbin/ypserv/common/ypdb.c b/usr.sbin/ypserv/common/ypdb.c index 7de9001e169..6f6234d9574 100644 --- a/usr.sbin/ypserv/common/ypdb.c +++ b/usr.sbin/ypserv/common/ypdb.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ypdb.c,v 1.4 1996/06/26 21:26:33 maja Exp $ */ +/* $OpenBSD: ypdb.c,v 1.5 1997/02/09 09:49:36 maja Exp $ */ /* * Copyright (c) 1990, 1993 @@ -95,6 +95,44 @@ ypdb_open(file, flags, mode) #endif } +/* + * Returns: + * *DBM on success + * NULL on failure + */ + +extern DBM * +ypdb_open_suf(file, flags, mode) + const char *file; + int flags, mode; +{ +#ifdef YPDB_PATCH + HASHINFO info; + + info.bsize = 4096; + info.ffactor = 40; + info.nelem = 1; + info.cachesize = NULL; + info.hash = NULL; + info.lorder = 0; + return ((DBM *)__hash_open(file, flags, mode, &info, 0)); +#else + BTREEINFO info; + DBM *db; + + info.flags = 0; + info.cachesize = 0; + info.maxkeypage = 0; + info.minkeypage = 0; + info.psize = 0; + info.compare = NULL; + info.prefix = NULL; + info.lorder = 0; + db = (DBM *)__bt_open(file, flags, mode, &info, 0); + return (db); +#endif +} + extern void ypdb_close(db) DBM *db; diff --git a/usr.sbin/ypserv/common/ypdb.h b/usr.sbin/ypserv/common/ypdb.h index f645bf3b831..80aac6ce77b 100644 --- a/usr.sbin/ypserv/common/ypdb.h +++ b/usr.sbin/ypserv/common/ypdb.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ypdb.h,v 1.4 1996/06/26 21:26:34 maja Exp $ */ +/* $OpenBSD: ypdb.h,v 1.5 1997/02/09 09:49:37 maja Exp $ */ /* * Copyright (c) 1990, 1993 @@ -70,6 +70,7 @@ datum ypdb_firstkey __P((DBM *)); datum ypdb_nextkey __P((DBM *)); datum ypdb_setkey __P((DBM *, datum)); DBM *ypdb_open __P((const char *, int, int)); +DBM *ypdb_open_suf __P((const char *, int, int)); int ypdb_store __P((DBM *, datum, datum, int)); __END_DECLS diff --git a/usr.sbin/ypserv/ypxfr/ypxfr.c b/usr.sbin/ypserv/ypxfr/ypxfr.c index 31d9b73b064..6bcd6003642 100644 --- a/usr.sbin/ypserv/ypxfr/ypxfr.c +++ b/usr.sbin/ypserv/ypxfr/ypxfr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ypxfr.c,v 1.14 1997/02/08 19:58:51 maja Exp $ */ +/* $OpenBSD: ypxfr.c,v 1.15 1997/02/09 09:49:37 maja Exp $ */ /* * Copyright (c) 1994 Mats O Jansson <moj@stacken.kth.se> @@ -32,7 +32,7 @@ */ #ifndef LINT -static char rcsid[] = "$OpenBSD: ypxfr.c,v 1.14 1997/02/08 19:58:51 maja Exp $"; +static char rcsid[] = "$OpenBSD: ypxfr.c,v 1.15 1997/02/09 09:49:37 maja Exp $"; #endif #include <sys/types.h> @@ -113,7 +113,7 @@ u_long *lordernum; if (!((stat(map_path, &finfo) == 0) && ((finfo.st_mode & S_IFMT) == S_IFDIR))) { fprintf(stderr, "%s: domain %s not found locally\n", - __progname, domain); + __progname, domain); status = YPPUSH_NODOM; } @@ -203,17 +203,7 @@ char *domain; char *map; char *temp_map; { - DBM *db; - char db_temp[255]; - - snprintf(db_temp,sizeof db_temp, "%s/%s/%s", - YP_DB_PATH,domain,temp_map); - - db = ypdb_open(db_temp, O_RDWR|O_CREAT, 0444); - - return db; - - yplog("Open DB %s", db_temp); + return ypdb_open_suf(temp_map, O_RDWR, 0444); } int @@ -222,26 +212,11 @@ char *domain; char *map; char *temp_map; { - char db_name[MAXPATHLEN],db_temp[MAXPATHLEN]; + char db_name[MAXPATHLEN]; snprintf(db_name, sizeof db_name, "%s/%s/%s%s", YP_DB_PATH,domain,map,YPDB_SUFFIX); - snprintf(db_temp, sizeof db_temp, "%s/%s/%s%s", - YP_DB_PATH,domain,temp_map,YPDB_SUFFIX); - rename(db_temp,db_name); - - return YPPUSH_SUCC; -} - -int -unlink_db(domain,map,temp_map) -char *temp_map; -{ - char db_temp[MAXPATHLEN]; - - snprintf(db_temp, sizeof db_temp, "%s/%s/%s%s", - YP_DB_PATH,domain,temp_map,YPDB_SUFFIX); - unlink(db_temp); + rename(temp_map,db_name); return YPPUSH_SUCC; } @@ -461,7 +436,6 @@ char *argv[]; u_long ordernum,new_ordernum; struct ypall_callback callback; CLIENT *client; - char mapname[] = "ypdbXXXXXX"; int status,xfr_status; int srvport; @@ -511,8 +485,11 @@ char *argv[]; } if (usage) { - status = YPPUSH_BADARGS; - (void)fprintf(stderr,"usage: %s [-cf] [-d domain] [-h host] [-s domain] [-C tid prog ipadd port] mapname\n",__progname); + status = YPPUSH_BADARGS; + fprintf(stderr, "usage: %s %s %s\n", + "[-cf] [-d domain] [-h host] [-s domain]", + "[-C tid prog ipadd port] mapname\n", + __progname); } if (status > 0) { @@ -577,12 +554,21 @@ char *argv[]; } if (status == YPPUSH_SUCC) { + char tmpmapname[MAXPATHLEN]; + int fd; /* Create temporary db */ - mktemp(mapname); + snprintf(tmpmapname, sizeof tmpmapname, + "%s/%s/ypdbXXXXXXXXXX%s", + YP_DB_PATH, domain, YPDB_SUFFIX); + fd = mkstemp(tmpmapname); + if (fd == -1) + status = YPPUSH_DBM; + else + close(fd); if (status > 0) { - db = create_db(domain,map,mapname); + db = create_db(domain,map,tmpmapname); if(db == NULL) status = YPPUSH_DBM; } @@ -619,9 +605,10 @@ char *argv[]; /* Rename db */ if(status > 0) { - status = install_db(domain,map,mapname); + status = install_db(domain,map,tmpmapname); } else { - status = unlink_db(domain,map,mapname); + unlink(tmpmapname); + status = YPPUSH_SUCC; } } |