]> granicus.if.org Git - sudo/commitdiff
Use debug logging instead of ignore_result() where possible.
authorTodd C. Miller <Todd.Miller@courtesan.com>
Fri, 12 May 2017 16:02:18 +0000 (10:02 -0600)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Fri, 12 May 2017 16:02:18 +0000 (10:02 -0600)
plugins/sudoers/iolog.c
plugins/sudoers/mkdir_parents.c
plugins/sudoers/set_perms.c
plugins/sudoers/timestamp.c
plugins/sudoers/visudo.c

index 38388fedbb6d799075c79df81a2431cd558c9fee..18543ff019d3703427f20f4cd7e8ae0195e4fd92 100644 (file)
@@ -103,10 +103,20 @@ io_mkdirs(char *path)
     }
     if (ok) {
        if (S_ISDIR(sb.st_mode)) {
-           if (sb.st_uid != iolog_uid || sb.st_gid != iolog_gid)
-               ignore_result(chown(path, iolog_uid, iolog_gid));
-           if ((sb.st_mode & ALLPERMS) != iolog_dirmode)
-               ignore_result(chmod(path, iolog_dirmode));
+           if (sb.st_uid != iolog_uid || sb.st_gid != iolog_gid) {
+               if (chown(path, iolog_uid, iolog_gid) != 0) {
+                   sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_ERRNO,
+                       "%s: unable to chown %d:%d %s", __func__,
+                       (int)iolog_uid, (int)iolog_gid, path);
+               }
+           }
+           if ((sb.st_mode & ALLPERMS) != iolog_dirmode) {
+               if (chmod(path, iolog_dirmode) != 0) {
+                   sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_ERRNO,
+                       "%s: unable to chmod 0%o %s", __func__,
+                       (int)iolog_dirmode, path);
+               }
+           }
        } else {
            sudo_warnx(U_("%s exists but is not a directory (0%o)"),
                path, (unsigned int) sb.st_mode);
@@ -135,7 +145,11 @@ io_mkdirs(char *path)
            if (!ok)
                sudo_warn(U_("unable to mkdir %s"), path);
        } else {
-           ignore_result(chown(path, iolog_uid, iolog_gid));
+           if (chown(path, iolog_uid, iolog_gid) != 0) {
+               sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_ERRNO,
+                   "%s: unable to chown %d:%d %s", __func__,
+                   (int)iolog_uid, (int)iolog_gid, path);
+           }
        }
     }
     if (uid_changed) {
@@ -405,7 +419,11 @@ io_nextid(char *iolog_dir, char *iolog_dir_fallback, char sessid[7])
        goto done;
     }
     sudo_lock_file(fd, SUDO_LOCK);
-    ignore_result(fchown(fd, iolog_uid, iolog_gid));
+    if (fchown(fd, iolog_uid, iolog_gid) != 0) {
+       sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_ERRNO,
+           "%s: unable to fchown %d:%d %s", __func__,
+           (int)iolog_uid, (int)iolog_gid, pathbuf);
+    }
 
     /*
      * If there is no seq file in iolog_dir and a fallback dir was
@@ -421,7 +439,11 @@ io_nextid(char *iolog_dir, char *iolog_dir_fallback, char sessid[7])
        if (len > 0 && (size_t)len < sizeof(fallback)) {
            int fd2 = io_open(fallback, O_RDWR|O_CREAT, iolog_filemode);
            if (fd2 != -1) {
-               ignore_result(fchown(fd2, iolog_uid, iolog_gid));
+               if (fchown(fd2, iolog_uid, iolog_gid) != 0) {
+                   sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_ERRNO,
+                       "%s: unable to fchown %d:%d %s", __func__,
+                       (int)iolog_uid, (int)iolog_gid, fallback);
+               }
                nread = read(fd2, buf, sizeof(buf) - 1);
                if (nread > 0) {
                    if (buf[nread - 1] == '\n')
@@ -541,7 +563,11 @@ open_io_fd(char *pathbuf, size_t len, struct io_log_file *iol, bool docompress)
     if (iol->enabled) {
        int fd = io_open(pathbuf, O_CREAT|O_TRUNC|O_WRONLY, iolog_filemode);
        if (fd != -1) {
-           ignore_result(fchown(fd, iolog_uid, iolog_gid));
+           if (fchown(fd, iolog_uid, iolog_gid) != 0) {
+               sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_ERRNO,
+                   "%s: unable to fchown %d:%d %s", __func__,
+                   (int)iolog_uid, (int)iolog_gid, pathbuf);
+           }
            (void)fcntl(fd, F_SETFD, FD_CLOEXEC);
 #ifdef HAVE_ZLIB_H
            if (docompress)
@@ -777,7 +803,11 @@ write_info_log(char *pathbuf, size_t len, struct iolog_details *details,
        log_warning(SLOG_SEND_MAIL, N_("unable to create %s"), pathbuf);
        debug_return_bool(false);
     }
-    ignore_result(fchown(fd, iolog_uid, iolog_gid));
+    if (fchown(fd, iolog_uid, iolog_gid) != 0) {
+       sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_ERRNO,
+           "%s: unable to fchown %d:%d %s", __func__,
+           (int)iolog_uid, (int)iolog_gid, pathbuf);
+    }
 
     fprintf(fp, "%lld:%s:%s:%s:%s:%d:%d\n%s\n%s", (long long)now->tv_sec,
        details->user ? details->user : "unknown", details->runas_pw->pw_name,
index 335a35704fb121bd2f6c5a91e13f8cffe3fdcbe1..36e6ffb973d5712f56f54e5981990e1781a0035b 100644 (file)
@@ -51,8 +51,13 @@ sudo_mkdir_parents(char *path, uid_t uid, gid_t gid, mode_t mode, bool quiet)
            "mkdir %s, mode 0%o, uid %d, gid %d", path, (unsigned int)mode,
            (int)uid, (int)gid);
        if (mkdir(path, mode) == 0) {
-           if (uid != (uid_t)-1 && gid != (gid_t)-1)
-               ignore_result(chown(path, uid, gid));
+           if (uid != (uid_t)-1 && gid != (gid_t)-1) {
+               if (chown(path, uid, gid) != 0) {
+                   sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_ERRNO,
+                       "%s: unable to chown %d:%d %s", __func__,
+                       (int)uid, (int)gid, path);
+               }
+           }
        } else {
            if (errno != EEXIST) {
                if (!quiet)
index 000f33f2c3dad7e9f91574bf58d191046a2a2f97..20890a920ffdeaa89d867837c18179d196b7e15f 100644 (file)
@@ -1181,8 +1181,13 @@ restore_perms(void)
      */
     if (OID(euid) == ROOT_UID) {
        /* setuid() may not set the saved ID unless the euid is ROOT_UID */
-       if (ID(euid) != ROOT_UID)
-           ignore_result(setreuid(-1, ROOT_UID));
+       if (ID(euid) != ROOT_UID) {
+           if (setreuid(-1, ROOT_UID) != 0) {
+               sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_ERRNO,
+                   "setreuid() [%d, %d] -> [-1, %d)", (int)state->ruid,
+                   (int)state->euid, ROOT_UID);
+           }
+       }
        if (setuid(ROOT_UID)) {
            sudo_warn("setuid() [%d, %d] -> %d)", (int)state->ruid,
                (int)state->euid, ROOT_UID);
index 8c2b0c7bdc185c00466d773301e3d058f555bba3..d0d73a947d2d266f5b080f347f788c1e3ac5915e 100644 (file)
@@ -170,7 +170,11 @@ ts_mkdirs(char *path, uid_t owner, gid_t group, mode_t mode,
                sudo_warn(U_("unable to mkdir %s"), path);
            ret = false;
        } else {
-           ignore_result(chown(path, owner, group));
+           if (chown(path, owner, group) != 0) {
+               sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_ERRNO,
+                   "%s: unable to chown %d:%d %s", __func__,
+                   (int)owner, (int)group, path);
+           }
        }
     }
     umask(omask);
index 3a4c8dca404d63a6099fbb7c258f135bbc881e6c..e9254ab92df76c23bafc0a4cc97d7852eea9dcde 100644 (file)
@@ -697,10 +697,20 @@ install_sudoers(struct sudoersfile *sp, bool oldperms)
         */
        (void) unlink(sp->tpath);
        if (!oldperms && fstat(sp->fd, &sb) != -1) {
-           if (sb.st_uid != sudoers_uid || sb.st_gid != sudoers_gid)
-               ignore_result(chown(sp->path, sudoers_uid, sudoers_gid));
-           if ((sb.st_mode & ACCESSPERMS) != sudoers_mode)
-               ignore_result(chmod(sp->path, sudoers_mode));
+           if (sb.st_uid != sudoers_uid || sb.st_gid != sudoers_gid) {
+               if (chown(sp->path, sudoers_uid, sudoers_gid) != 0) {
+                   sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_ERRNO,
+                       "%s: unable to chown %d:%d %s", __func__,
+                       (int)sudoers_uid, (int)sudoers_gid, sp->path);
+               }
+           }
+           if ((sb.st_mode & ACCESSPERMS) != sudoers_mode) {
+               if (chmod(sp->path, sudoers_mode) != 0) {
+                   sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_ERRNO,
+                       "%s: unable to chmod 0%o %s", __func__,
+                       (int)sudoers_mode, sp->path);
+               }
+           }
        }
        ret = true;
        goto done;