diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 1998-03-12 08:22:29 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 1998-03-12 08:22:29 +0000 |
commit | 0a2601beeb3f57139ba4239fa36a70a452583b3e (patch) | |
tree | e36b12fc59b6c03807b5cfcadf7ade6ed6b5cf3e | |
parent | cc76ddea08a01ad568ac0abe80a1050587741937 (diff) |
mkstemp()
-rw-r--r-- | usr.sbin/ypserv/makedbm/makedbm.c | 25 | ||||
-rw-r--r-- | usr.sbin/ypserv/mkalias/mkalias.c | 70 |
2 files changed, 56 insertions, 39 deletions
diff --git a/usr.sbin/ypserv/makedbm/makedbm.c b/usr.sbin/ypserv/makedbm/makedbm.c index e81b7130d0e..4085e7b9eb0 100644 --- a/usr.sbin/ypserv/makedbm/makedbm.c +++ b/usr.sbin/ypserv/makedbm/makedbm.c @@ -1,4 +1,4 @@ -/* $OpenBSD: makedbm.c,v 1.9 1997/08/18 03:11:34 millert Exp $ */ +/* $OpenBSD: makedbm.c,v 1.10 1998/03/12 08:22:27 deraadt Exp $ */ /* * Copyright (c) 1994-97 Mats O Jansson <moj@stacken.kth.se> @@ -32,7 +32,7 @@ */ #ifndef LINT -static char rcsid[] = "$OpenBSD: makedbm.c,v 1.9 1997/08/18 03:11:34 millert Exp $"; +static char rcsid[] = "$OpenBSD: makedbm.c,v 1.10 1998/03/12 08:22:27 deraadt Exp $"; #endif #include <stdio.h> @@ -191,7 +191,7 @@ create_database(infile,database, char data_line[4096]; /* XXX: DB bsize = 4096 in ypdb.c */ char myname[MAXHOSTNAMELEN]; int line_no = 0; - int len; + int len, fd; char *p,*k,*v; char *slash; DBM *new_db; @@ -229,17 +229,28 @@ create_database(infile,database, if (strlen(database) + strlen(mapname) + strlen(YPDB_SUFFIX) > MAXPATHLEN) { fprintf(stderr,"%s: %s: directory name too long\n", - __progname, database); + __progname, database); exit(1); } snprintf(db_tempname, sizeof(db_tempname), "%s%s", database, mapname); - mktemp(db_tempname); - snprintf(db_mapname, sizeof(db_mapname), "%s%s", db_tempname, - YPDB_SUFFIX); + fd = mkstemp(db_tempname); + if (fd == -1) + goto fail; + close(fd); + snprintf(db_mapname, sizeof(db_mapname), "%s%s", db_tempname, + YPDB_SUFFIX); new_db = ypdb_open(db_tempname, O_RDWR|O_CREAT, 0444); + if (new_db == NULL) { +fail: + if (fd != -1) + unlink(db_tempname); + fprintf(stderr, "%s: Unable to open output database %s\n", + __progname, db_outfile); + exit(1); + } while (read_line(data_file,data_line,sizeof(data_line))) { diff --git a/usr.sbin/ypserv/mkalias/mkalias.c b/usr.sbin/ypserv/mkalias/mkalias.c index c044ad29c16..e430db8c2cd 100644 --- a/usr.sbin/ypserv/mkalias/mkalias.c +++ b/usr.sbin/ypserv/mkalias/mkalias.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mkalias.c,v 1.3 1997/07/28 22:48:01 deraadt Exp $ */ +/* $OpenBSD: mkalias.c,v 1.4 1998/03/12 08:22:28 deraadt Exp $ */ /* * Copyright (c) 1997 Mats O Jansson <moj@stacken.kth.se> @@ -32,7 +32,7 @@ */ #ifndef LINT -static char rcsid[] = "$OpenBSD: mkalias.c,v 1.3 1997/07/28 22:48:01 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: mkalias.c,v 1.4 1998/03/12 08:22:28 deraadt Exp $"; #endif #include <ctype.h> @@ -160,7 +160,7 @@ char *argv[]; int uflag = 0; int vflag = 0; int Eflag = 0; - int ch; + int ch, fd; char *input = NULL; char *output = NULL; DBM *db; @@ -176,33 +176,33 @@ char *argv[]; char myname[MAXHOSTNAMELEN]; while ((ch = getopt(argc, argv, "Edensuv")) != -1) - switch(ch) { - case 'E': - eflag++; /* Check hostname */ - Eflag++; /* .. even check MX records */ - break; - case 'd': - dflag++; /* Don't check DNS hostname */ - break; - case 'e': - eflag++; /* Check hostname */ - break; - case 'n': - nflag++; /* Capitalize name parts */ - break; - case 's': - sflag++; /* Don't know... */ - break; - case 'u': - uflag++; /* Don't check UUCP hostname */ - break; - case 'v': - vflag++; /* Verbose */ - break; - default: - usage++; - break; - } + switch(ch) { + case 'E': + eflag++; /* Check hostname */ + Eflag++; /* .. even check MX records */ + break; + case 'd': + dflag++; /* Don't check DNS hostname */ + break; + case 'e': + eflag++; /* Check hostname */ + break; + case 'n': + nflag++; /* Capitalize name parts */ + break; + case 's': + sflag++; /* Don't know... */ + break; + case 'u': + uflag++; /* Don't check UUCP hostname */ + break; + case 'v': + vflag++; /* Verbose */ + break; + default: + usage++; + break; + } if (optind == argc) { usage++; @@ -255,12 +255,18 @@ char *argv[]; snprintf(db_tempname, sizeof(db_tempname), "%s%s", output, mapname); - mktemp(db_tempname); + fd = mkstemp(db_tempname); + if (fd == -1) + goto fail; + close(fd); + snprintf(db_mapname, sizeof(db_mapname), "%s%s", db_tempname, YPDB_SUFFIX); - new_db = ypdb_open(db_tempname, O_RDWR|O_CREAT, 0444); if (new_db == NULL) { +fail: + if (fd != -1) + unlink(db_tempname); fprintf(stderr, "%s: Unable to open output database %s\n", __progname, |