From: Marcel Holtmann Date: Thu, 24 Dec 2009 15:05:53 +0000 (-0800) Subject: Fix permissions of newly created /etc/resolv.conf X-Git-Tag: 2.0_alpha~2970 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=da5d569557a805dd3f4cc4c0d4cd582481b4c7cd;p=framework%2Fconnectivity%2Fconnman.git Fix permissions of newly created /etc/resolv.conf --- diff --git a/src/resolver.c b/src/resolver.c index fa6880c..59adeab 100644 --- a/src/resolver.c +++ b/src/resolver.c @@ -338,30 +338,46 @@ static int resolvfile_append(const char *interface, const char *domain, { char *cmd; int fd, len, err; + mode_t old_umask; DBG("interface %s server %s", interface, server); if (interface == NULL) return -ENOENT; + old_umask = umask(022); + fd = open("/etc/resolv.conf", O_RDWR | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); - if (fd < 0) - return -errno; + if (fd < 0) { + err = -errno; + goto done; + } + + if (ftruncate(fd, 0) < 0) { + err = -errno; + goto failed; + } - err = ftruncate(fd, 0); + err = 0; cmd = g_strdup_printf("# Generated by Connection Manager\n" "options edns0\n" "nameserver %s\n", server); len = write(fd, cmd, strlen(cmd)); + if (len < 0) + err = -errno; g_free(cmd); +failed: close(fd); - return 0; +done: + umask(old_umask); + + return err; } static int resolvfile_remove(const char *interface, const char *domain,