<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Jabbering Giraffe &#187; unix</title>
	<atom:link href="http://happygiraffe.net/blog/tag/unix/feed/" rel="self" type="application/rss+xml" />
	<link>http://happygiraffe.net/blog</link>
	<description></description>
	<lastBuildDate>Tue, 07 Feb 2012 20:49:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<atom:link rel="hub" href="http://pubsubhubbub.appspot.com"/><atom:link rel="hub" href="http://superfeedr.com/hubbub"/>		<item>
		<title>pruning your tree</title>
		<link>http://happygiraffe.net/blog/2011/02/25/pruning-your-tree/</link>
		<comments>http://happygiraffe.net/blog/2011/02/25/pruning-your-tree/#comments</comments>
		<pubDate>Fri, 25 Feb 2011 21:28:46 +0000</pubDate>
		<dc:creator>Dominic Mitchell</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[unix]]></category>

		<guid isPermaLink="false">http://happygiraffe.net/blog/?p=1693</guid>
		<description><![CDATA[This is from a mailing list post I&#8217;ve just replied to. Since I had to look it up, it&#8217;s worth blogging. It seems like a simple task. Find all the files in the current directory, excluding .svn directories. I&#8217;ve mocked &#8230; <a href="http://happygiraffe.net/blog/2011/02/25/pruning-your-tree/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>This is from a mailing list <a href="https://groups.google.com/d/topic/brightonnewmedia/DNl7jBFr3FI/discussion">post</a> I&#8217;ve just replied to.  Since I had to look it up, it&#8217;s worth blogging. <img src='http://happygiraffe.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>It seems like a simple task.  Find all the files in the current directory, excluding <code>.svn</code> directories.  I&#8217;ve mocked up a simple layout.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">%</span> <span style="color: #c20cb9; font-weight: bold;">find</span> .
.
.<span style="color: #000000; font-weight: bold;">/</span>.svn
.<span style="color: #000000; font-weight: bold;">/</span>.svn<span style="color: #000000; font-weight: bold;">/</span>README.txt
.<span style="color: #000000; font-weight: bold;">/</span>README.txt
.<span style="color: #000000; font-weight: bold;">/</span>src
.<span style="color: #000000; font-weight: bold;">/</span>src<span style="color: #000000; font-weight: bold;">/</span>.svn
.<span style="color: #000000; font-weight: bold;">/</span>src<span style="color: #000000; font-weight: bold;">/</span>.svn<span style="color: #000000; font-weight: bold;">/</span>foo.c
.<span style="color: #000000; font-weight: bold;">/</span>src<span style="color: #000000; font-weight: bold;">/</span>foo.c</pre></div></div>

<p>By default, find prints out everything.  But we only want files.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">%</span> <span style="color: #c20cb9; font-weight: bold;">find</span> . <span style="color: #660033;">-type</span> f
.<span style="color: #000000; font-weight: bold;">/</span>.svn<span style="color: #000000; font-weight: bold;">/</span>README.txt
.<span style="color: #000000; font-weight: bold;">/</span>README.txt
.<span style="color: #000000; font-weight: bold;">/</span>src<span style="color: #000000; font-weight: bold;">/</span>.svn<span style="color: #000000; font-weight: bold;">/</span>foo.c
.<span style="color: #000000; font-weight: bold;">/</span>src<span style="color: #000000; font-weight: bold;">/</span>foo.c</pre></div></div>

<p>Now, we want to exclude everything under <code>.svn</code>.  Easy.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">%</span> <span style="color: #c20cb9; font-weight: bold;">find</span> . <span style="color: #660033;">-name</span> .svn <span style="color: #660033;">-prune</span> <span style="color: #660033;">-type</span> f</pre></div></div>

<p>Ooops.  That&#8217;s not good.  What happened here?  Well, the default for find is to <em>and</em> two expressions together.  If we or it, we get what we want.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">%</span> <span style="color: #c20cb9; font-weight: bold;">find</span> . <span style="color: #660033;">-name</span> .svn <span style="color: #660033;">-prune</span> <span style="color: #660033;">-or</span> <span style="color: #660033;">-type</span> f
.<span style="color: #000000; font-weight: bold;">/</span>.svn
.<span style="color: #000000; font-weight: bold;">/</span>README.txt
.<span style="color: #000000; font-weight: bold;">/</span>src<span style="color: #000000; font-weight: bold;">/</span>.svn
.<span style="color: #000000; font-weight: bold;">/</span>src<span style="color: #000000; font-weight: bold;">/</span>foo.c</pre></div></div>

<p>Again, not so good.  The problem is that default action to print everything.  Because we&#8217;ve specified no action, it&#8217;ll print out each match, and that includes the <code>.svn</code> directories (even though it correctly stops going into them).</p>
<p>The answer is to provide an explicit action instead.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">%</span> <span style="color: #c20cb9; font-weight: bold;">find</span> . <span style="color: #660033;">-name</span> .svn <span style="color: #660033;">-prune</span> <span style="color: #660033;">-or</span> <span style="color: #660033;">-type</span> f <span style="color: #660033;">-print</span>
.<span style="color: #000000; font-weight: bold;">/</span>README.txt
.<span style="color: #000000; font-weight: bold;">/</span>src<span style="color: #000000; font-weight: bold;">/</span>foo.c</pre></div></div>

<p>This works, because now there is no default action, and the explicit action is only associated with the <code>-type f</code> predicate.</p>
]]></content:encoded>
			<wfw:commentRss>http://happygiraffe.net/blog/2011/02/25/pruning-your-tree/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>sandbox(7)</title>
		<link>http://happygiraffe.net/blog/2009/06/02/sandbox7/</link>
		<comments>http://happygiraffe.net/blog/2009/06/02/sandbox7/#comments</comments>
		<pubDate>Tue, 02 Jun 2009 20:12:06 +0000</pubDate>
		<dc:creator>Dominic Mitchell</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[osx]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[unix]]></category>

		<guid isPermaLink="false">http://happygiraffe.net/blog/?p=1524</guid>
		<description><![CDATA[Like a lot of people, most of my Unix knowledge comes from an early reading of Advanced Programming in the UNIX Environment. This is an excellent tome on the interfaces provided by the kernel to programs on a Unix system. &#8230; <a href="http://happygiraffe.net/blog/2009/06/02/sandbox7/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Like a lot of people, most of my Unix knowledge comes from an early reading of <a href="http://www.kohala.com/start/apue.html">Advanced Programming in the UNIX Environment</a>.  This is an <em>excellent</em> tome on the interfaces provided by the kernel to programs on a Unix system.</p>
<p>Unfortunately, it&#8217;s over 15 years old now, and things have moved on.  Naturally, I haven&#8217;t quite kept up.  So I&#8217;ve just been pleasantly surprised to see that OS X has grown a sandbox system (<a href="http://blog.chromium.org/2009/06/google-chrome-sandboxing-and-mac-os-x.html">via</a>).  There is scant documentation available:</p>
<ul>
<li><a href="http://developer.apple.com/DOCUMENTATION/DARWIN/Reference/ManPages/man1/sandbox-exec.1.html#//apple_ref/doc/man/1/sandbox-exec">sandbox-exec(1)</a></li>
<li><a href="http://developer.apple.com/DOCUMENTATION/DARWIN/Reference/ManPages/man3/sandbox_init.3.html">sandbox_init(3)</a></li>
<li><a href="http://developer.apple.com/DOCUMENTATION/DARWIN/Reference/ManPages/man7/sandbox.7.html#//apple_ref/doc/man/7/sandbox">sandbox(7)</a></li>
<li><a href="http://developer.apple.com/DOCUMENTATION/DARWIN/Reference/ManPages/man8/sandbox-compilerd.8.html#//apple_ref/doc/man/8/sandbox-compilerd">sandbox-compilerd(8)</a></li>
</ul>
<p>Also, if you poke around, you&#8217;ll find <code>/usr/include/sandbox.h</code> and <code>/usr/share/sandbox</code>.  The latter is interesting — it contains lisp-like definitions of access control lists for various processes.</p>
<p>What&#8217;s interesting to me is <code>sandbox-exec</code> though.  This can be used with one of the builtin profiles to easily restrict access.  For example:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ sandbox-exec <span style="color: #660033;">-n</span> nowrite <span style="color: #c20cb9; font-weight: bold;">touch</span> <span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>foo
<span style="color: #c20cb9; font-weight: bold;">touch</span>: <span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>foo: Operation not permitted</pre></div></div>

<p>After using <a href="http://developer.apple.com/DOCUMENTATION/DARWIN/Reference/ManPages/man1/strings.1.html">strings(1)</a> on apple&#8217;s libc (<code>/usr/lib/libSystem.dylib</code>), I managed to get these builtin profile names out:</p>
<dl>
<dt><em>nointernet</em></dt>
<dd>TCP/IP networking is prohibited</dd>
<dt><em>nonet</em></dt>
<dd>All sockets-based networking is prohibited.</dd>
<dt><em>pure-computation</em></dt>
<dd>All operating system services are prohibited.</dd>
<dt><em>nowrite</em></dt>
<dd>File system writes are prohibited.</dd>
<dt><em>write-tmp-only</em></dt>
<dd>File system writes are restricted to the temporary folder <code>/var/tmp</code> and the folder specified by the <a href="http://developer.apple.com/DOCUMENTATION/DARWIN/Reference/ManPages/man3/confstr.3.html#//apple_ref/doc/man/3/confstr">confstr(3)</a> configuration variable <code>_CS_DARWIN_USER_TEMP_DIR</code>.</dd>
</dl>
<p>They&#8217;re only documented as internal constants for C programs, but it&#8217;s quite handy to have them available for <code>sandbox-exec</code>.  It would be nice to know in more detail what they actually <em>did</em>, though.</p>
<p>Of course, this still isn&#8217;t really getting down to how the sandbox is implemented.  Is it done inside the kernel or on the userland side?  I don&#8217;t really know.  And I don&#8217;t yet have enough dtrace-fu to figure it out.</p>
<p>See also:</p>
<ul>
<li><a href="http://www.318.com/techjournal/security/a-brief-introduction-to-mac-os-x-sandbox-technology/">A brief introduction to Mac OS X SandBox Technology</a></li>
<li><a href="http://www.usefulsecurity.com/2007/11/apple-sandboxes-part-1/">Apple Sandboxes Part 1</a></li>
<li><a href="http://www.usefulsecurity.com/2007/11/apple-sandboxes-part-2/">Apple Sandboxes Part 2</a></li>
<li><a href="http://www.matasano.com/log/981/a-roundup-of-leopard-security-features/">A Roundup Of Leopard Security Features</a></li>
</ul>
<p>Anyway, this seems like a fun toy.  And of course, it&#8217;s reminded me that I need to try out <a href="http://build.chromium.org/buildbot/snapshots/sub-rel-mac/">chromium on the mac</a>…  Drat, no PPC support.  <img src='http://happygiraffe.net/blog/wp-includes/images/smilies/icon_sad.gif' alt=':-(' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://happygiraffe.net/blog/2009/06/02/sandbox7/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Locales That Work</title>
		<link>http://happygiraffe.net/blog/2006/11/06/locales-that-work/</link>
		<comments>http://happygiraffe.net/blog/2006/11/06/locales-that-work/#comments</comments>
		<pubDate>Mon, 06 Nov 2006 12:01:00 +0000</pubDate>
		<dc:creator>Dominic Mitchell</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[unicode]]></category>
		<category><![CDATA[unix]]></category>

		<guid isPermaLink="false">http://happygiraffe.net/2006/11/06/locales-that-work/</guid>
		<description><![CDATA[As I mentioned before, I don&#8217;t like locales. But of course, the solution is blindingly obvious and had passed me by. Unicode Support on FreeBSD points out the correct solution, which avoids breaking ls. % export LANG=en_GB.UTF-8 LC_COLLATE=POSIX Marvellous. Now &#8230; <a href="http://happygiraffe.net/blog/2006/11/06/locales-that-work/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>As I mentioned before, I don&#8217;t like locales.  But of course, the solution is blindingly obvious and had passed me by.  <a href="http://opal.com/freebsd/unicode.html#langctype">Unicode Support on FreeBSD</a> points out the correct solution, which avoids breaking ls.</p>
<pre>
  % export LANG=en_GB.UTF-8 LC_COLLATE=POSIX
</pre>
<p>Marvellous.  Now things can autodetect that I&#8217;d like <span class="caps">UTF</span>-8, please.</p>
]]></content:encoded>
			<wfw:commentRss>http://happygiraffe.net/blog/2006/11/06/locales-that-work/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

