<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre, #msg p { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; }
#msg ul { overflow: auto; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<title>[23458] trunk/launchd/src/launchctl.c</title>
</head>
<body>
<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.macosforge.org/projects/launchd/changeset/23458">23458</a></dd>
<dt>Author</dt> <dd>zarzycki@apple.com</dd>
<dt>Date</dt> <dd>2007-12-07 13:06:19 -0800 (Fri, 07 Dec 2007)</dd>
</dl>
<h3>Log Message</h3>
<pre><rdar://problem/5619757> SULeoCeto: Detect and fix bogus permissions on /sbin/launchd</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunklaunchdsrclaunchctlc">trunk/launchd/src/launchctl.c</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunklaunchdsrclaunchctlc"></a>
<div class="modfile"><h4>Modified: trunk/launchd/src/launchctl.c (23457 => 23458)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/launchd/src/launchctl.c        2007-12-07 20:59:53 UTC (rev 23457)
+++ trunk/launchd/src/launchctl.c        2007-12-07 21:06:19 UTC (rev 23458)
</span><span class="lines">@@ -151,6 +151,7 @@
</span><span class="cx"> static bool do_single_user_mode2(void);
</span><span class="cx"> static void read_launchd_conf(void);
</span><span class="cx"> static bool job_disabled_logic(launch_data_t obj);
</span><ins>+static void fix_bogus_file_metadata(void);
</ins><span class="cx">
</span><span class="cx"> typedef enum {
</span><span class="cx">         BOOTCACHE_START = 1,
</span><span class="lines">@@ -2781,8 +2782,67 @@
</span><span class="cx">          */
</span><span class="cx">
</span><span class="cx">         assumes(fwexec(remount_tool, NULL) != -1);
</span><ins>+
+        fix_bogus_file_metadata();
</ins><span class="cx"> }
</span><span class="cx">
</span><ins>+void
+fix_bogus_file_metadata(void)
+{
+        static const struct {
+                const char *path;
+                const uid_t owner;
+                const gid_t group;
+                const mode_t needed_bits;
+                const mode_t bad_bits;
+        } f[] = {
+                { "/sbin/launchd", 0, 0, S_IRUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH, S_ISUID|S_ISGID|S_ISVTX|S_IWOTH },
+                { _PATH_TMP, 0, 0, S_ISTXT|S_IRWXU|S_IRWXG|S_IRWXO, S_ISUID|S_ISGID },
+                { _PATH_VARTMP, 0, 0, S_ISTXT|S_IRWXU|S_IRWXG|S_IRWXO, S_ISUID|S_ISGID },
+        };
+        struct stat sb;
+        size_t i;
+
+        for (i = 0; i < (sizeof(f) / sizeof(f[0])); i++) {
+                mode_t i_needed_bits;
+                mode_t i_bad_bits;
+                bool fix_mode = false;
+                bool fix_id = false;
+
+                if (!assumes(stat(f[i].path, &sb) != -1)) {
+                        continue;
+                }
+
+                i_needed_bits = ~sb.st_mode & f[i].needed_bits;
+                i_bad_bits = sb.st_mode & f[i].bad_bits;
+
+                if (i_bad_bits) {
+                        fprintf(stderr, "Crucial filesystem check: Removing bogus mode bits 0%o on path: %s\n", i_bad_bits, f[i].path);
+                        fix_mode = true;
+                }
+                if (i_needed_bits) {
+                        fprintf(stderr, "Crucial filesystem check: Adding missing mode bits 0%o on path: %s\n", i_needed_bits, f[i].path);
+                        fix_mode = true;
+                }
+                if (sb.st_uid != f[i].owner) {
+                        fprintf(stderr, "Crucial filesystem check: Fixing bogus UID %u on path: %s\n", sb.st_uid, f[i].path);
+                        fix_id = true;
+                }
+                if (sb.st_gid != f[i].group) {
+                        fprintf(stderr, "Crucial filesystem check: Fixing bogus GID %u on path: %s\n", sb.st_gid, f[i].path);
+                        fix_id = true;
+                }
+
+                if (fix_mode) {
+                        assumes(chmod(f[i].path, (sb.st_mode & ~i_bad_bits) | i_needed_bits) != -1);
+                }
+                if (fix_id) {
+                        assumes(chown(f[i].path, f[i].owner, f[i].group) != -1);
+                }
+        }
+}
+
+
</ins><span class="cx"> bool
</span><span class="cx"> path_check(const char *path)
</span><span class="cx"> {
</span></span></pre>
</div>
</div>
</body>
</html>