[prev in list] [next in list] [prev in thread] [next in thread] 

List:       launchd-changes
Subject:    [launchd-changes] [23457] branches/SULeopard/launchd/src/launchctl.c
From:       source_changes () macosforge ! org
Date:       2007-12-07 21:00:10
Message-ID: 20071207210010.39A2E2CDFFE () beta ! macosforge ! org
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


Revision: 23457
          http://trac.macosforge.org/projects/launchd/changeset/23457
Author:   zarzycki@apple.com
Date:     2007-12-07 12:59:53 -0800 (Fri, 07 Dec 2007)

Log Message:
-----------
<rdar://problem/5619757> SULeoCeto: Detect and fix bogus permissions on /sbin/launchd

Modified Paths:
--------------
    branches/SULeopard/launchd/src/launchctl.c

Modified: branches/SULeopard/launchd/src/launchctl.c
===================================================================
--- branches/SULeopard/launchd/src/launchctl.c	2007-12-07 20:59:06 UTC (rev 23456)
+++ branches/SULeopard/launchd/src/launchctl.c	2007-12-07 20:59:53 UTC (rev 23457)
@@ -148,6 +148,7 @@
 static bool do_single_user_mode2(void);
 static void read_launchd_conf(void);
 static bool job_disabled_logic(launch_data_t obj);
+static void fix_bogus_file_metadata(void);
 
 typedef enum {
 	BOOTCACHE_START = 1,
@@ -2782,8 +2783,66 @@
 	 */
 
 	assumes(fwexec(remount_tool, true) != -1);
+
+	fix_bogus_file_metadata();
 }
 
+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);
+		}
+	}
+}
+
 bool
 path_check(const char *path)
 {


[Attachment #5 (text/html)]

<!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>[23457] branches/SULeopard/launchd/src/launchctl.c</title>
</head>
<body>

<div id="msg">
<dl>
<dt>Revision</dt> <dd><a \
href="http://trac.macosforge.org/projects/launchd/changeset/23457">23457</a></dd> \
<dt>Author</dt> <dd>zarzycki@apple.com</dd> <dt>Date</dt> <dd>2007-12-07 12:59:53 \
-0800 (Fri, 07 Dec 2007)</dd> </dl>

<h3>Log Message</h3>
<pre>&lt;rdar://problem/5619757&gt; SULeoCeto: Detect and fix bogus permissions on \
/sbin/launchd</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#branchesSULeopardlaunchdsrclaunchctlc">branches/SULeopard/launchd/src/launchctl.c</a></li>
 </ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="branchesSULeopardlaunchdsrclaunchctlc"></a>
<div class="modfile"><h4>Modified: branches/SULeopard/launchd/src/launchctl.c (23456 \
=> 23457)</h4> <pre class="diff"><span>
<span class="info">--- branches/SULeopard/launchd/src/launchctl.c	2007-12-07 20:59:06 \
                UTC (rev 23456)
+++ branches/SULeopard/launchd/src/launchctl.c	2007-12-07 20:59:53 UTC (rev 23457)
</span><span class="lines">@@ -148,6 +148,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">@@ -2782,8 +2783,66 @@
</span><span class="cx"> 	 */
</span><span class="cx"> 
</span><span class="cx"> 	assumes(fwexec(remount_tool, true) != -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[] = {
+		{ &quot;/sbin/launchd&quot;, 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 &lt; (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, &amp;sb) != -1)) {
+			continue;
+		}
+
+		i_needed_bits = ~sb.st_mode &amp; f[i].needed_bits;
+		i_bad_bits = sb.st_mode &amp; f[i].bad_bits;
+
+		if (i_bad_bits) {
+			fprintf(stderr, &quot;Crucial filesystem check: Removing bogus mode bits 0%o on \
path: %s\n&quot;, i_bad_bits, f[i].path); +			fix_mode = true;
+		}
+		if (i_needed_bits) {
+			fprintf(stderr, &quot;Crucial filesystem check: Adding missing mode bits 0%o on \
path: %s\n&quot;, i_needed_bits, f[i].path); +			fix_mode = true;
+		}
+		if (sb.st_uid != f[i].owner) {
+			fprintf(stderr, &quot;Crucial filesystem check: Fixing bogus UID %u on path: \
%s\n&quot;, sb.st_uid, f[i].path); +			fix_id = true;
+		}
+		if (sb.st_gid != f[i].group) {
+			fprintf(stderr, &quot;Crucial filesystem check: Fixing bogus GID %u on path: \
%s\n&quot;, sb.st_gid, f[i].path); +			fix_id = true;
+		}
+
+		if (fix_mode) {
+			assumes(chmod(f[i].path, (sb.st_mode &amp; ~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>



_______________________________________________
launchd-changes mailing list
launchd-changes@lists.macosforge.org
http://lists.macosforge.org/mailman/listinfo/launchd-changes


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic