summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>1997-02-07 09:24:04 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>1997-02-07 09:24:04 +0000
commit03c419bb7bb91fde255b4fe9a29e1525bc2a6701 (patch)
treed54282177c13c211c0f068c1189d664b5e463c83
parent04d15718f6e93432946affd70fcbd80f7ddbb0a0 (diff)
back out mktemp fix; for some reason i cannot understand it causes big problems
-rw-r--r--usr.sbin/ypserv/ypxfr/ypxfr.c89
1 files changed, 51 insertions, 38 deletions
diff --git a/usr.sbin/ypserv/ypxfr/ypxfr.c b/usr.sbin/ypserv/ypxfr/ypxfr.c
index 5a2c7f6e5f6..80a237be61f 100644
--- a/usr.sbin/ypserv/ypxfr/ypxfr.c
+++ b/usr.sbin/ypserv/ypxfr/ypxfr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ypxfr.c,v 1.12 1997/02/03 12:15:59 deraadt Exp $ */
+/* $OpenBSD: ypxfr.c,v 1.13 1997/02/07 09:24:03 deraadt Exp $ */
/*
* Copyright (c) 1994 Mats O Jansson <moj@stacken.kth.se>
@@ -32,25 +32,23 @@
*/
#ifndef LINT
-static char rcsid[] = "$OpenBSD: ypxfr.c,v 1.12 1997/02/03 12:15:59 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: ypxfr.c,v 1.13 1997/02/07 09:24:03 deraadt Exp $";
#endif
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/socket.h>
-
-#include <netinet/in.h>
-#include <arpa/inet.h>
-
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
+#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <sys/socket.h>
#include <netdb.h>
#include <rpc/rpc.h>
#include <rpc/xdr.h>
+/* #include <rpcsvc/yp_prot.h> */
#include <rpcsvc/ypclnt.h>
#include <rpcsvc/yp.h>
@@ -59,7 +57,7 @@ static char rcsid[] = "$OpenBSD: ypxfr.c,v 1.12 1997/02/03 12:15:59 deraadt Exp
#include "ypdb.h"
#include "ypdef.h"
-extern char *__progname;
+char *progname = "ypxfr";
DBM *db;
extern bool_t xdr_ypresp_all_seq();
@@ -72,7 +70,7 @@ ypxfr_foreach(status,keystr,keylen,valstr,vallen,data)
int status,keylen,vallen,*data;
char *keystr,*valstr;
{
- datum key,val;
+ datum key,val;
if (status == 2)
return(0);
@@ -97,7 +95,7 @@ char *domain;
char *map;
u_long *lordernum;
{
- char map_path[MAXPATHLEN];
+ char map_path[1024];
char order_key[] = YP_LAST_KEY;
char order[MAX_LAST_LEN+1];
struct stat finfo;
@@ -109,18 +107,17 @@ u_long *lordernum;
status = YPPUSH_SUCC;
- snprintf(map_path, sizeof map_path, "%s/%s",YP_DB_PATH,domain);
+ sprintf(map_path,"%s/%s",YP_DB_PATH,domain);
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;
}
if(status > 0) {
- snprintf(map_path, sizeof map_path, "%s/%s/%s%s",
- YP_DB_PATH,domain,map,YPDB_SUFFIX);
+ sprintf(map_path,"%s/%s/%s%s",YP_DB_PATH,domain,map,YPDB_SUFFIX);
if(!(stat(map_path, &finfo) == 0)) {
status = YPPUSH_NOMAP;
}
@@ -128,8 +125,7 @@ u_long *lordernum;
if(status > 0) {
- snprintf(map_path, sizeof map_path, "%s/%s/%s",
- YP_DB_PATH,domain,map);
+ sprintf(map_path,"%s/%s/%s",YP_DB_PATH,domain,map);
db = ypdb_open(map_path, O_RDONLY, 0444);
if(db == NULL) {
status = YPPUSH_DBM;
@@ -193,7 +189,9 @@ char *domain;
char *map;
struct ypall_callback *incallback;
{
- (void)yp_all_host(client, domain, map, incallback);
+ u_long status;
+
+ status = yp_all_host(client, domain, map, incallback);
}
@@ -203,7 +201,16 @@ char *domain;
char *map;
char *temp_map;
{
- return ypdb_open(temp_map, O_RDWR, 0444);
+ DBM *db;
+ char db_temp[255];
+
+ sprintf(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);
}
int
@@ -212,11 +219,23 @@ char *domain;
char *map;
char *temp_map;
{
- char db_name[MAXPATHLEN];
+ char db_name[255],db_temp[255];
+
+ sprintf(db_name,"%s/%s/%s%s",YP_DB_PATH,domain,map,YPDB_SUFFIX);
+ sprintf(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[255];
- snprintf(db_name, sizeof db_name, "%s/%s/%s%s",
- YP_DB_PATH,domain,map,YPDB_SUFFIX);
- rename(temp_map,db_name);
+ sprintf(db_temp,"%s/%s/%s%s",YP_DB_PATH,domain,temp_map,YPDB_SUFFIX);
+ unlink(db_temp);
return YPPUSH_SUCC;
}
@@ -436,6 +455,7 @@ char *argv[];
u_long ordernum,new_ordernum;
struct ypall_callback callback;
CLIENT *client;
+ char mapname[] = "ypdbXXXXXX";
int status,xfr_status;
int srvport;
@@ -485,11 +505,8 @@ char *argv[];
}
if (usage) {
- 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);
+ status = YPPUSH_BADARGS;
+ (void)fprintf(stderr,"usage: %s [-cf] [-d domain] [-h host] [-s domain] [-C tid prog ipadd port] mapname\n",progname);
}
if (status > 0) {
@@ -554,20 +571,17 @@ char *argv[];
}
if (status == YPPUSH_SUCC) {
- char tmpmapname[MAXPATHLEN];
- int fd;
+ int fd;
/* Create temporary db */
- snprintf(tmpmapname, sizeof tmpmapname, "%s/%s/ypdbXXXXXXXXXX",
- YP_DB_PATH, domain);
- fd = mkstemp(tmpmapname);
+ fd = mkstemp(mapname);
if (fd == -1)
status = YPPUSH_DBM;
else
close(fd);
if (status > 0) {
- db = create_db(domain,map,tmpmapname);
+ db = create_db(domain,map,mapname);
if(db == NULL)
status = YPPUSH_DBM;
}
@@ -604,10 +618,9 @@ char *argv[];
/* Rename db */
if(status > 0) {
- status = install_db(domain,map,tmpmapname);
+ status = install_db(domain,map,mapname);
} else {
- unlink(tmpmapname);
- status = YPPUSH_SUCC;
+ status = unlink_db(domain,map,mapname);
}
}