]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
relax safe_create().
authorMark Andrews <marka@isc.org>
Sat, 4 Aug 2001 08:15:02 +0000 (08:15 +0000)
committerMark Andrews <marka@isc.org>
Sat, 4 Aug 2001 08:15:02 +0000 (08:15 +0000)
bin/rndc/unix/os.c

index 8dfdf8d5927dc424a1a400cf1700f35b92d10864..1e4cf8a9c70f428aac93db9b52d6de4ac8b315d9 100644 (file)
@@ -15,7 +15,7 @@
  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: os.c,v 1.1 2001/08/03 05:56:22 marka Exp $ */
+/* $Id: os.c,v 1.2 2001/08/04 08:15:02 marka Exp $ */
 
 #include <config.h>
 
@@ -46,18 +46,22 @@ safe_create(const char *filename) {
        int fd;
        FILE *f;
         struct stat sb;
+       int flags = O_WRONLY;
 
         if (stat(filename, &sb) == -1) {
                 if (errno != ENOENT)
                        return (NULL);
+               flags = O_WRONLY|O_CREAT|O_EXCL;
         } else if ((sb.st_mode & S_IFREG) == 0) {
                errno = EOPNOTSUPP;
                return (NULL);
-       }
+       } else
+               flags = O_WRONLY|O_TRUNC;
 
-       fd = open(filename, O_WRONLY|O_CREAT|O_EXCL, S_IRUSR|S_IWUSR);
+       fd = open(filename, flags, S_IRUSR|S_IWUSR);
        if (fd == -1)
                return (NULL);
+       (void)fchmod(fd, S_IRUSR|S_IWUSR);
        f = fdopen(fd, "w");
        if (f == NULL)
                close(fd);