<?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"
	>

<channel>
	<title>aaron.harnly.net &#187; macosx</title>
	<atom:link href="http://harnly.net/category/blog/geek/macosx/feed/" rel="self" type="application/rss+xml" />
	<link>http://harnly.net</link>
	<description>Sì, abbiamo un'anima. Ma è fatta di tanti piccoli robot.</description>
	<pubDate>Sat, 23 Aug 2008 04:59:59 +0000</pubDate>
	<generator>http://wordpress.org/?v=abc</generator>
	<language>en</language>
			<item>
		<title>The Future Is Now: Treasures in the Carbon docs</title>
		<link>http://harnly.net/2008/blog/geek/macosx/the-future-is-now-treasures-in-the-carbon-docs/</link>
		<comments>http://harnly.net/2008/blog/geek/macosx/the-future-is-now-treasures-in-the-carbon-docs/#comments</comments>
		<pubDate>Sun, 10 Feb 2008 18:28:38 +0000</pubDate>
		<dc:creator>aaronharnly</dc:creator>
		
		<category><![CDATA[macosx]]></category>

		<guid isPermaLink="false">http://harnly.net/2008/blog/geek/macosx/the-future-is-now-treasures-in-the-carbon-docs/</guid>
		<description><![CDATA[Ran across these funny notes in the Carbon documentation:

This warning that &#8220;The Future&#8221; could arrive any day:

Important: In the future, individual application processes may not always share the same address space, so in general you should never attempt to access code or data in another process.

and this one is just precious:

Note: Because multitasking allows an [...]]]></description>
			<content:encoded><![CDATA[<p>Ran across these funny notes in the Carbon documentation:</p>

<p><a href="http://developer.apple.com/documentation/Carbon/Conceptual/Multitasking_MultiproServ/03tasks/chapter_3_section_13.html">This warning that &#8220;The Future&#8221; could arrive any day:</a></p>

<blockquote><b>Important</b>: In the future, individual application processes may not always share the same address space, so in general you should never attempt to access code or data in another process.</b></blockquote>

<p>and <a href="http://developer.apple.com/documentation/Carbon/Conceptual/Multitasking_MultiproServ/02concepts/chapter_2_section_3.html#//apple_ref/doc/uid/TP30000268-DontLinkElementID_5">this one is just precious</a>:</p>

<blockquote><b>Note</b>: Because multitasking allows an operating system to attend to several different operations at the same time, these operations may appear to occur simultaneously on even a single-processor system, due to the speed of the processor.</blockquote>

<p>You don&#8217;t say. </p>
]]></content:encoded>
			<wfw:commentRss>http://harnly.net/2008/blog/geek/macosx/the-future-is-now-treasures-in-the-carbon-docs/feed/</wfw:commentRss>
		</item>
		<item>
		<title>TextMate bundle for Scala</title>
		<link>http://harnly.net/2007/blog/geek/macosx/textmate-bundle-for-scala/</link>
		<comments>http://harnly.net/2007/blog/geek/macosx/textmate-bundle-for-scala/#comments</comments>
		<pubDate>Wed, 25 Apr 2007 18:52:11 +0000</pubDate>
		<dc:creator>aaronharnly</dc:creator>
		
		<category><![CDATA[macosx]]></category>

		<category><![CDATA[scala]]></category>

		<guid isPermaLink="false">http://harnly.net/2007/blog/computers/macosx/textmate-bundle-for-scala/</guid>
		<description><![CDATA[I&#8217;ve put together a stub of a TextMate bundle for Scala. 

At the moment, it just contains a bare-bones language definition, a template for Ant tasks, and a couple of snippets. I&#8217;d like to keep improving it, and would welcome suggestions and modifications.

I&#8217;ll be setting up anonymous SVN access one of these days (yeah, right), [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve put together a stub of a <a href="http://macromates.com/textmate/manual/bundles">TextMate bundle</a> for <a href="http://www.scala-lang.org">Scala</a>. </p>

<p>At the moment, it just contains a bare-bones language definition, a template for Ant tasks, and a couple of snippets. I&#8217;d like to keep improving it, and would welcome suggestions and modifications.</p>

<p>I&#8217;ll be setting up anonymous SVN access one of these days (yeah, right), but for the moment, you can download the bundle directly: </p>

<p><a href="/projects/scala-textmate-bundle/downloads/ScalaAWH.tmbundle.zip"><img src="/projects/images/filetypes/128/tmbundle.png">
ScalaAWH.tmbundle.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>http://harnly.net/2007/blog/geek/macosx/textmate-bundle-for-scala/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Sharing the wealth: My dotfiles</title>
		<link>http://harnly.net/2007/blog/geek/macosx/sharing-the-wealth-my-dotfiles/</link>
		<comments>http://harnly.net/2007/blog/geek/macosx/sharing-the-wealth-my-dotfiles/#comments</comments>
		<pubDate>Mon, 26 Mar 2007 23:44:23 +0000</pubDate>
		<dc:creator>aaronharnly</dc:creator>
		
		<category><![CDATA[macosx]]></category>

		<guid isPermaLink="false">http://harnly.net/2007/blog/computers/macosx/sharing-the-wealth-my-dotfiles/</guid>
		<description><![CDATA[It is the fashion these days to share your .bashrc, so I thought I&#8217;d do so.

Here is my .bashrc in all its glory. 

And here is a typical prompt it produces:



The first little box there just displays the login information &#8212; whether I&#8217;m local or remote, and from which host. That&#8217;s handy if I&#8217;m bouncing [...]]]></description>
			<content:encoded><![CDATA[<p>It is the <a href="http://blogsearch.google.com/blogsearch?hl=en&amp;q=bashrc&amp;btnG=Search+Blogs">fashion these days</a> to share your .bashrc, so I thought I&#8217;d do so.</p>

<p><a href="/code/bashrc.txt">Here is my .bashrc</a> in all its glory. </p>

<p>And here is a typical prompt it produces:</p>

<p><img src="/images/screenshots/aarons-login.png"></p>

<p>The first little box there just displays the login information &#8212; whether I&#8217;m local or remote, and from which host. That&#8217;s handy if I&#8217;m bouncing between servers and have forgotten whether I&#8217;m connected to machine C via machine B, or directly from A, etc.</p>

<p>Also of interest there is an updated version of <a href="http://www.macosxhints.com/article.php?story=20021114055617124">this MacOSXHints.com suggestion of mine</a>, which lists available <a href="http://www.gnu.org/software/screen/">GNU screen</a> sessions. </p>

<p>Some other little functions I use daily are <b>path<em>append</b>, <b>path</em>prepend</b>, and <b>try_export</b>, which simply add a directory (if it exists) to the beginning or end of a given env variable, usually $PATH.</p>

<p>So, for example, I have these lines:</p>

<pre><code>path_prepend $HOME/software/crossplatform/bin
try_export "/usr/local/java/java1.5" JAVA_HOME
try_export "/System/Library/Frameworks/JavaVM.framework/Versions/1.5/Home/" JAVA_HOME
</code></pre>

<p>which I think makes for a much tidier way to conditionally set a variable depending on which platform I happen to be logged into. IMHO.</p>

<p>Anyway, enjoy. </p>
]]></content:encoded>
			<wfw:commentRss>http://harnly.net/2007/blog/geek/macosx/sharing-the-wealth-my-dotfiles/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Using snippets in Textmate templates</title>
		<link>http://harnly.net/2007/blog/geek/macosx/using-snippets-in-textmate-templates/</link>
		<comments>http://harnly.net/2007/blog/geek/macosx/using-snippets-in-textmate-templates/#comments</comments>
		<pubDate>Tue, 20 Mar 2007 03:31:31 +0000</pubDate>
		<dc:creator>aaronharnly</dc:creator>
		
		<category><![CDATA[macosx]]></category>

		<guid isPermaLink="false">http://harnly.net/2007/blog/computers/macosx/using-snippets-in-textmate-templates/</guid>
		<description><![CDATA[Pursuant to the post below, I found myself creating a simple Scala bundle for Textmate, as there isn&#8217;t one at the moment. (Getting in on the ground floor!) 

The Textmate snippet system is a wonderful creation &#8212; simple, delightful, and helpful. Unfortunately, the templating system is not nearly so nice &#8212; just a Perl one-liner [...]]]></description>
			<content:encoded><![CDATA[<p>Pursuant to the post below, I found myself creating a simple Scala bundle for Textmate, as there isn&#8217;t one at the moment. (Getting in on the ground floor!) </p>

<p>The Textmate snippet system is a wonderful creation &#8212; simple, delightful, and helpful. Unfortunately, the templating system is not nearly so nice &#8212; just a Perl one-liner to substitute in some environment variables, and no snappy tab-tab autofill magic.</p>

<p>Then I ran across <a href="http://henrik.nyh.se/2007/02/27/snippet-power-templates-in-textmate/">this great post by Henrik Nyh</a>, in which he scrapes together a little Applescript to create a Textmate template as a snippet.</p>

<p>However, I found myself wanting <em>both</em> some templated boilerplate, with variable substitution, and some snippetized text below. This proved a little trickier than I first thought, since the Applescript inserts at the top of the document, and it would require a nasty keypress script to insert the snippet below.</p>

<p>So, I came up with a slightly modified version of Henrik&#8217;s system, which supports a template_in.txt file with the usual variable substitutions, as well as a snippet below. </p>

<p>The template script looks like this:
<code>if [[ ! -f "$TM<em>NEW</em>FILE" ]]; then
   TM<em>YEAR=<code>date +%Y</code> \
   TM</em>DATE=<code>date +%Y-%m-%d</code> \
   TM<em>USERNAME=<code>niutil -readprop / /users/\$USER realname</code> \
   TM</em>TEMPLATE<em>OUTPUT=$(mktemp &#8220;/tmp/tm</em>template_XXXXXX&#8221;)</p>

<p>perl -pe &#8217;s/\${([^}]*)}/$ENV{$1}/g&#8217; \
      &lt; template<em>in.txt > &#8220;$TM</em>TEMPLATE_OUTPUT&#8221;</p>

<p>touch &#8220;$TM<em>NEW</em>FILE&#8221;</p>

<pre><code>{ # Insert the template &amp; snippet!
osascript "${TM_BUNDLE_SUPPORT}/load_snippet.scpt" "$TM_TEMPLATE_OUTPUT" "snippet.txt" 
} &amp;&gt;/dev/null &amp;
</code></pre>

<p>fi
</code></p>

<p>and the Applescript is modified to this:
<code>
on run args
    set template<em>output</em>file to (item 1 of args)
    set snippet_file to (item 2 of args)</p>

<pre><code>-- retrieve the template and snippet text
set existing_text to read (POSIX file (template_output_file)) as «class utf8»
set loaded_snippet to read (POSIX file (snippet_file)) as «class utf8»

-- insert both into the document
tell application "TextMate"
    insert existing_text
    insert loaded_snippet with as snippet
end tell

-- remove the temporary file
do shell script "rm \"" &amp; template_output_file &amp; "\""
</code></pre>

<p>end run
</code></p>

<p>You can <a href="/downloads/Snipplate2 (AWH).tmbundle.zip">download Snipplate2 (AWH) here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://harnly.net/2007/blog/geek/macosx/using-snippets-in-textmate-templates/feed/</wfw:commentRss>
		</item>
		<item>
		<title>List all application versions</title>
		<link>http://harnly.net/2007/blog/geek/macosx/list-all-application-versions/</link>
		<comments>http://harnly.net/2007/blog/geek/macosx/list-all-application-versions/#comments</comments>
		<pubDate>Mon, 12 Mar 2007 19:59:18 +0000</pubDate>
		<dc:creator>aaronharnly</dc:creator>
		
		<category><![CDATA[macosx]]></category>

		<guid isPermaLink="false">http://harnly.net/2007/blog/computers/macosx/list-all-application-versions/</guid>
		<description><![CDATA[Here&#8217;s a nice little one-liner for listing the current version and installation date of every application on your OS X system, using the wonders of Spotlight:

mdfind &#8220;kMDItemKind == &#8216;Application&#8217;&#8221; &#124; perl -ne &#8216;chomp; print &#8220;\&#8221;$_\&#8221;\n&#8221; &#8216;
&#124; xargs mdls -name kMDItemFSContentChangeDate -name kMDItemVersion -name kMDItemDisplayName -name kMDItemPath &#124;  perl -pe &#8217;s/^\/.+/&#8221;-&#8221; x 20/e&#8217;

Sample output:

kMDItemDisplayName  [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a nice little one-liner for listing the current version and installation date of every application on your OS X system, using the wonders of Spotlight:</p>

<p>mdfind &#8220;kMDItemKind == &#8216;Application&#8217;&#8221; | perl -ne &#8216;chomp; print &#8220;\&#8221;$_\&#8221;\n&#8221; &#8216;
| xargs mdls -name kMDItemFSContentChangeDate -name kMDItemVersion -name kMDItemDisplayName -name kMDItemPath |  perl -pe &#8217;s/^\/.+/&#8221;-&#8221; x 20/e&#8217;</p>

<h2>Sample output:</h2>

<pre><code>kMDItemDisplayName         = "MarsEdit.app"
kMDItemFSContentChangeDate = 2006-03-13 22:58:25 -0500
kMDItemPath                = "/Applications/3rdPartyApps/Write/MarsEdit.app"
kMDItemVersion             = "1.1.2"
--------------------
kMDItemDisplayName         = "OmniWeb.app"
kMDItemFSContentChangeDate = 2007-02-14 17:23:51 -0500
kMDItemPath                = "/Applications/3rdPartyApps/Connect/OmniWeb.app"
kMDItemVersion             = "5.5.4"
--------------------
kMDItemDisplayName         = "CandyBar.app"
kMDItemFSContentChangeDate = 2006-04-14 18:40:52 -0400
kMDItemPath                = "/Applications/3rdPartyApps/Tinker/prettify/CandyBar.app"
kMDItemVersion             = "2.6.1"
--------------------
kMDItemDisplayName         = "Vienna.app"
kMDItemFSContentChangeDate = 2007-01-27 13:38:17 -0500
kMDItemPath                = "/Applications/3rdPartyApps/Connect/Vienna.app"
kMDItemVersion             = "2.1.1.2109"
</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://harnly.net/2007/blog/geek/macosx/list-all-application-versions/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Triple-Quote to use a shell variable in awk</title>
		<link>http://harnly.net/2007/blog/geek/macosx/triple-quote-to-use-a-shell-variable-in-awk/</link>
		<comments>http://harnly.net/2007/blog/geek/macosx/triple-quote-to-use-a-shell-variable-in-awk/#comments</comments>
		<pubDate>Mon, 12 Mar 2007 17:53:30 +0000</pubDate>
		<dc:creator>aaronharnly</dc:creator>
		
		<category><![CDATA[macosx]]></category>

		<guid isPermaLink="false">http://harnly.net/2007/blog/computers/macosx/triple-quote-to-use-a-shell-variable-in-awk/</guid>
		<description><![CDATA[Just a little note: Found myself wanting to print a shell variable as part of an &#8216;awk&#8217; one-liner, but found it rather surprisingly difficult. Here&#8217;s the magic tickle required:

x="foo"
awk '{ print "'"$x"'" }'


That&#8217;s a &#8221; followed by &#8216; and then another &#8220;.

For the curious, the actual script was a one-liner for dumping out Mac OS [...]]]></description>
			<content:encoded><![CDATA[<p>Just a little note: Found myself wanting to print a shell variable as part of an &#8216;awk&#8217; one-liner, but found it rather surprisingly difficult. Here&#8217;s the magic tickle required:</p>

<pre><code>x="foo"
awk '{ print "'"$x"'" }'
</code></pre>

<p>That&#8217;s a &#8221; followed by &#8216; and then another &#8220;.</p>

<p>For the curious, the actual script was a one-liner for dumping out Mac OS X application version information:</p>

<pre><code>for x in /Applications/*.app 
do mdls $x | awk -F \" '/kMDItemVersion/ { print "'"$(basename $x)"'", $2 }'
done
</code></pre>

<p>cheers.</p>
]]></content:encoded>
			<wfw:commentRss>http://harnly.net/2007/blog/geek/macosx/triple-quote-to-use-a-shell-variable-in-awk/feed/</wfw:commentRss>
		</item>
		<item>
		<title>A Widget-Toot</title>
		<link>http://harnly.net/2005/blog/autobiography/a-widget-toot/</link>
		<comments>http://harnly.net/2005/blog/autobiography/a-widget-toot/#comments</comments>
		<pubDate>Tue, 24 May 2005 22:16:48 +0000</pubDate>
		<dc:creator>aaronharnly</dc:creator>
		
		<category><![CDATA[autobiography]]></category>

		<category><![CDATA[macosx]]></category>

		<guid isPermaLink="false">http://harnly.net/blog/autobiography/a-widget-toot</guid>
		<description><![CDATA[So thanks to that widget-post below (or actually the original page here), yours truly found himself mentioned at length in this Boston Globe article condemning Apple for its security slipup. Both the true discoverer of the flaw, Stephan.com, and this elaborator upon its implications are quoted, though despite my protestations, my nom de birth rather [...]]]></description>
			<content:encoded><![CDATA[<p>So thanks to that <a href="http://harnly.net/blog/computers/macosx/safari-dashboard-vulnerability-in-os-x-1040">widget-post below</a> (or actually the <a href="http://www1.cs.columbia.edu/~aaron/files/widgets/">original page here</a>), yours truly found himself mentioned at length in this <a href="http://www.boston.com/business/personaltech/articles/2005/05/16/apple_gives_identity_thieves_a_way_in?pg=full">Boston Globe article condemning Apple</a> for its security slipup. Both the true discoverer of the flaw, Stephan.com, and this elaborator upon its implications are quoted, though despite my protestations, my <em>nom de birth</em> rather than this <em>nom de guerre</em> is used.</p>

<p><span id="more-45"></span></p>

<p>Because the universe is propelled by an elaborate irony-generating engine, Apple released a 10.4.1 update addressing the flaw within hours of the publication of the article. (Hmmm, is that really ironic? Perhaps the engine also produces&#8230;)</p>

<p>It is still my aim to see Mithras himself appear in a major publication, i.e. one that has actual deadlines. I shall not resort to acts of violence or property destruction, fear not.</p>
]]></content:encoded>
			<wfw:commentRss>http://harnly.net/2005/blog/autobiography/a-widget-toot/feed/</wfw:commentRss>
		</item>
		<item>
		<title>machine_info.pl: Getting your bearings on a new machine</title>
		<link>http://harnly.net/2005/blog/geek/macosx/machine-info/</link>
		<comments>http://harnly.net/2005/blog/geek/macosx/machine-info/#comments</comments>
		<pubDate>Tue, 10 May 2005 18:13:16 +0000</pubDate>
		<dc:creator>aaronharnly</dc:creator>
		
		<category><![CDATA[macosx]]></category>

		<guid isPermaLink="false">http://harnly.net/blog/autobiography/43</guid>
		<description><![CDATA[Continuing the spate of brain-dumps of scripts I use often, this is a favorite: machine_info.pl

I&#8217;m often hunting around for machines to run jobs on, and so log into a bunch of different machines to find one well-suited to my task. So when I log into a machine, I often want to get a quick sense [...]]]></description>
			<content:encoded><![CDATA[<p>Continuing the spate of brain-dumps of scripts I use often, this is a favorite: <tt>machine_info.pl</tt></p>

<p>I&#8217;m often hunting around for machines to run jobs on, and so log into a bunch of different machines to find one well-suited to my task. So when I log into a machine, I often want to get a quick sense of its capabilities. I got tired of trying to remember that Solaris uses /usr/sbin/psrinfo, while Linux uses /proc/cpuinfo, and which lines to grep for in each. So I wrote this script.</p>

<p>I also find this script handy for my duties as part-time administrator; it helps me keep tabs on which machines we&#8217;ve upgraded to how much RAM, etc.</p>

<p><span id="more-43"></span></p>

<p>Example output &mdash; at home:</p>

<p><code>[11:14 AM mithras@powerbook: ~] machine<em>info.pl
cpu</em>count=1
cpu<em>speed</em>mhz=667
cpu<em>type=Power</em>Macintosh
host<em>ip=xxx.xx.245.99
host</em>mac=00:03:93:a3:95:c2
host<em>name=powerbook.school.edu
os=Darwin
os</em>notes=Mac OS X 10.4 (build 8A428)
os<em>version=8.0.0
ram</em>mbytes=768</code></p>

<p>And on a work server:</p>

<p><code>08:17 PM mithras@server6: src] machine<em>info.pl 
cpu</em>count=4
cpu<em>speed</em>mhz=3056
cpu<em>type=i686
host</em>ip=xxx.xx.22.98
host<em>mac=00:0E:0C:31:59:CF
host</em>name=server6.school.edu
os=Linux
os<em>notes=Red Hat Linux release 9 (Shrike)
os</em>version=2.4.20-31.9.progeny.6smp
ram_mbytes=2016</code></p>

<p>Here&#8217;s the script:</p>


<div class="wp_syntax"><div class="code"><pre class="perl"><span style="color: #666666; font-style: italic;">#!/usr/bin/perl -w</span>
<span style="color: #000000; font-weight: bold;">use</span> strict<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># FILE: machine_info.pl</span>
<span style="color: #666666; font-style: italic;"># AUTHOR: Mithras THe Prophet (mithras.the.prophet, which is a gmail account)</span>
<span style="color: #666666; font-style: italic;"># DATE: June 2004</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># This script runs on Linux, Solaris, and Mac OS X machines</span>
<span style="color: #666666; font-style: italic;">#  to give you a quick rundown of the setup of the machine:</span>
<span style="color: #666666; font-style: italic;">#  The processor type and speed, memory, disks, etc.</span>
<span style="color: #666666; font-style: italic;">#  </span>
<span style="color: #666666; font-style: italic;"># I find this useful when I've just logged into an unfamiliar machine</span>
<span style="color: #666666; font-style: italic;">#  and want to get my bearings.</span>
<span style="color: #666666; font-style: italic;">#</span>
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;">#---- settings</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#-----</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;">#</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;">#----- globals</span>
 <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">%info</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">#--</span>
<span style="color: #666666; font-style: italic;">#</span>
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Step 0: Determine platform</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$PLATFORM</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#123;</span>
 <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$uname_s</span> <span style="color: #339933;">=</span> `uname <span style="color: #339933;">-</span><span style="color: #000066;">s</span>`<span style="color: #339933;">;</span>
 <span style="color: #000066;">chomp</span> <span style="color: #0000ff;">$uname_s</span><span style="color: #339933;">;</span>
 <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$uname_m</span> <span style="color: #339933;">=</span> `uname <span style="color: #339933;">-</span><span style="color: #000066;">m</span>`<span style="color: #339933;">;</span>
 <span style="color: #000066;">chomp</span> <span style="color: #0000ff;">$uname_m</span><span style="color: #339933;">;</span>
 <span style="color: #0000ff;">$uname_m</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">s/ /_/g</span><span style="color: #339933;">;</span>
 <span style="color: #0000ff;">$PLATFORM</span><span style="color: #339933;">=</span><span style="color: #0000ff;">$uname_s</span> . <span style="color: #ff0000;">&quot;-&quot;</span> . <span style="color: #0000ff;">$uname_m</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># print STDERR &quot;## machineinfo\n&quot;;</span>
<span style="color: #666666; font-style: italic;"># print STDERR &quot;##\n&quot;;</span>
<span style="color: #666666; font-style: italic;"># print STDERR &quot;## running on $PLATFORM\n&quot;;</span>
<span style="color: #666666; font-style: italic;"># print STDERR &quot;##\n&quot;;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># os</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #009900;">&#123;</span>
 <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$uname_s</span> <span style="color: #339933;">=</span> `uname <span style="color: #339933;">-</span><span style="color: #000066;">s</span>`<span style="color: #339933;">;</span>
 <span style="color: #000066;">chomp</span> <span style="color: #0000ff;">$uname_s</span><span style="color: #339933;">;</span>
&nbsp;
 <span style="color: #0000ff;">$info</span><span style="color: #009900;">&#123;</span><span style="color: #ff0000;">'os'</span><span style="color: #009900;">&#125;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$uname_s</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># cpu_count</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #009900;">&#123;</span>
 <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$cpu_num</span><span style="color: #339933;">=</span><span style="color: #ff0000;">&quot;1&quot;</span><span style="color: #339933;">;</span>
 <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$info</span><span style="color: #009900;">&#123;</span><span style="color: #ff0000;">'os'</span><span style="color: #009900;">&#125;</span> eq <span style="color: #ff0000;">&quot;Darwin&quot;</span> <span style="color: #009900;">&#41;</span>
 <span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$command</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">'/usr/sbin/sysctl hw.ncpu | awk <span style="color: #000099; font-weight: bold;">\'</span>{print $2}<span style="color: #000099; font-weight: bold;">\'</span> '</span><span style="color: #339933;">;</span>
  <span style="color: #0000ff;">$cpu_num</span> <span style="color: #339933;">=</span> `<span style="color: #0000ff;">$command</span>`<span style="color: #339933;">;</span>
  <span style="color: #000066;">chomp</span> <span style="color: #0000ff;">$cpu_num</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span>
 <span style="color: #b1b100;">elsif</span> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$info</span><span style="color: #009900;">&#123;</span><span style="color: #ff0000;">'os'</span><span style="color: #009900;">&#125;</span> eq <span style="color: #ff0000;">&quot;Linux&quot;</span> <span style="color: #009900;">&#41;</span>
 <span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$command</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">'awk <span style="color: #000099; font-weight: bold;">\'</span>/processor/ { max_num=$3 } END { print max_num &quot; +1&quot;} <span style="color: #000099; font-weight: bold;">\'</span> /proc/cpuinfo | bc '</span><span style="color: #339933;">;</span>
  <span style="color: #0000ff;">$cpu_num</span> <span style="color: #339933;">=</span> `<span style="color: #0000ff;">$command</span>`<span style="color: #339933;">;</span>
  <span style="color: #000066;">chomp</span> <span style="color: #0000ff;">$cpu_num</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span>
 <span style="color: #b1b100;">elsif</span> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$info</span><span style="color: #009900;">&#123;</span><span style="color: #ff0000;">'os'</span><span style="color: #009900;">&#125;</span> eq <span style="color: #ff0000;">&quot;SunOS&quot;</span> <span style="color: #009900;">&#41;</span>
 <span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$command</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">'/usr/sbin/psrinfo -v | perl -ne <span style="color: #000099; font-weight: bold;">\'</span> BEGIN { $count = 0 } if (/processor (\d+)/) { $count++ } END { print ($count) }<span style="color: #000099; font-weight: bold;">\'</span> '</span><span style="color: #339933;">;</span>
  <span style="color: #0000ff;">$cpu_num</span> <span style="color: #339933;">=</span> `<span style="color: #0000ff;">$command</span>`<span style="color: #339933;">;</span>
  <span style="color: #000066;">chomp</span> <span style="color: #0000ff;">$cpu_num</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span>
&nbsp;
 <span style="color: #0000ff;">$info</span><span style="color: #009900;">&#123;</span><span style="color: #ff0000;">'cpu_count'</span><span style="color: #009900;">&#125;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$cpu_num</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># cpu_speed_mhz</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #009900;">&#123;</span>
 <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$cpu_speed</span><span style="color: #339933;">=</span><span style="color: #ff0000;">&quot;unknown&quot;</span><span style="color: #339933;">;</span>
&nbsp;
 <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$info</span><span style="color: #009900;">&#123;</span><span style="color: #ff0000;">'os'</span><span style="color: #009900;">&#125;</span> eq <span style="color: #ff0000;">&quot;Darwin&quot;</span> <span style="color: #009900;">&#41;</span>
 <span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$command</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">'/usr/sbin/sysctl hw.cpufrequency | awk <span style="color: #000099; font-weight: bold;">\'</span>{print $2 &quot;/ 1000000&quot;}<span style="color: #000099; font-weight: bold;">\'</span> | bc'</span><span style="color: #339933;">;</span>
  <span style="color: #0000ff;">$cpu_speed</span><span style="color: #339933;">=</span>`<span style="color: #0000ff;">$command</span>`<span style="color: #339933;">;</span>
  <span style="color: #000066;">chomp</span> <span style="color: #0000ff;">$cpu_speed</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">#  $cpu_speed .= &quot; MHz&quot;;</span>
 <span style="color: #009900;">&#125;</span>
 <span style="color: #b1b100;">elsif</span> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$info</span><span style="color: #009900;">&#123;</span><span style="color: #ff0000;">'os'</span><span style="color: #009900;">&#125;</span> eq <span style="color: #ff0000;">&quot;Linux&quot;</span> <span style="color: #009900;">&#41;</span>
 <span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$command</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">'cat /proc/cpuinfo | perl -ne <span style="color: #000099; font-weight: bold;">\'</span>if (/cpu MHz\s+: (\d+)/) { print &quot;$1\n&quot; unless ($done); $done=1 } <span style="color: #000099; font-weight: bold;">\'</span> '</span><span style="color: #339933;">;</span>
  <span style="color: #0000ff;">$cpu_speed</span><span style="color: #339933;">=</span>`<span style="color: #0000ff;">$command</span>`<span style="color: #339933;">;</span>
  <span style="color: #000066;">chomp</span> <span style="color: #0000ff;">$cpu_speed</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">#  $cpu_speed .= &quot; MHz&quot;;</span>
 <span style="color: #009900;">&#125;</span>
 <span style="color: #b1b100;">elsif</span> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$info</span><span style="color: #009900;">&#123;</span><span style="color: #ff0000;">'os'</span><span style="color: #009900;">&#125;</span> eq <span style="color: #ff0000;">&quot;SunOS&quot;</span> <span style="color: #009900;">&#41;</span>
 <span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$command</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">'/usr/sbin/psrinfo -v | perl -ne <span style="color: #000099; font-weight: bold;">\'</span>if (/(\d+) MHz/) { print &quot;$1\n&quot; unless ($done); $done=1 }<span style="color: #000099; font-weight: bold;">\'</span>  '</span><span style="color: #339933;">;</span>
  <span style="color: #0000ff;">$cpu_speed</span><span style="color: #339933;">=</span>`<span style="color: #0000ff;">$command</span>`<span style="color: #339933;">;</span>
  <span style="color: #000066;">chomp</span> <span style="color: #0000ff;">$cpu_speed</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">#  $cpu_speed .= &quot; MHz&quot;;</span>
 <span style="color: #009900;">&#125;</span>
&nbsp;
 <span style="color: #0000ff;">$info</span><span style="color: #009900;">&#123;</span><span style="color: #ff0000;">'cpu_speed_mhz'</span><span style="color: #009900;">&#125;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$cpu_speed</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># config_cpu_type</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #009900;">&#123;</span>
 <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$uname_m</span> <span style="color: #339933;">=</span> `uname <span style="color: #339933;">-</span><span style="color: #000066;">m</span>`<span style="color: #339933;">;</span>
 <span style="color: #000066;">chomp</span> <span style="color: #0000ff;">$uname_m</span><span style="color: #339933;">;</span>
 <span style="color: #0000ff;">$uname_m</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">s/ /_/g</span><span style="color: #339933;">;</span>
&nbsp;
 <span style="color: #0000ff;">$info</span><span style="color: #009900;">&#123;</span><span style="color: #ff0000;">'cpu_type'</span><span style="color: #009900;">&#125;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$uname_m</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># hostname</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #009900;">&#123;</span>
 <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$hostname</span><span style="color: #339933;">=</span>`hostname`<span style="color: #339933;">;</span>
 <span style="color: #000066;">chomp</span> <span style="color: #0000ff;">$hostname</span><span style="color: #339933;">;</span>
&nbsp;
 <span style="color: #0000ff;">$info</span><span style="color: #009900;">&#123;</span><span style="color: #ff0000;">'host_name'</span><span style="color: #009900;">&#125;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$hostname</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># host_ip</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #009900;">&#123;</span>
 <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$dig_command</span><span style="color: #339933;">=</span><span style="color: #ff0000;">&quot;dig &quot;</span> . <span style="color: #0000ff;">$info</span><span style="color: #009900;">&#123;</span><span style="color: #ff0000;">'host_name'</span><span style="color: #009900;">&#125;</span> . <span style="color: #ff0000;">&quot; | awk 'BEGIN { ans=0 } /;;/ { if (ans==1) { ans=0 } } /ANSWER SECTION/ { ans=1 } /&quot;</span> 
  . <span style="color: #0000ff;">$info</span><span style="color: #009900;">&#123;</span><span style="color: #ff0000;">'host_name'</span><span style="color: #009900;">&#125;</span> . <span style="color: #ff0000;">&quot;/ { if (ans==1) { print <span style="color: #000099; font-weight: bold;">\$</span>5 } } '&quot;</span><span style="color: #339933;">;</span>
 <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$ip</span> <span style="color: #339933;">=</span> `<span style="color: #0000ff;">$dig_command</span>`<span style="color: #339933;">;</span>
 <span style="color: #000066;">chomp</span> <span style="color: #0000ff;">$ip</span><span style="color: #339933;">;</span>
&nbsp;
 <span style="color: #0000ff;">$info</span><span style="color: #009900;">&#123;</span><span style="color: #ff0000;">'host_ip'</span><span style="color: #009900;">&#125;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$ip</span><span style="color: #339933;">;</span> 
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># host_mac</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #009900;">&#123;</span>
 <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$mac</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;unknown&quot;</span><span style="color: #339933;">;</span>
 <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$info</span><span style="color: #009900;">&#123;</span><span style="color: #ff0000;">'os'</span><span style="color: #009900;">&#125;</span> eq <span style="color: #ff0000;">&quot;Darwin&quot;</span> <span style="color: #009900;">&#41;</span>
 <span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$command</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">'/sbin/ifconfig | perl -ne '</span> . <span style="color: #ff0000;">&quot;'&quot;</span> . <span style="color: #ff0000;">'if (/en0/) { $next = 1; } ; if (/ether\s+(.*)/) { if ($next==1) { print $1; $next=0; } }'</span> . <span style="color: #ff0000;">&quot;'&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #0000ff;">$mac</span><span style="color: #339933;">=</span>`<span style="color: #0000ff;">$command</span>`
 <span style="color: #009900;">&#125;</span>
 <span style="color: #b1b100;">elsif</span> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$info</span><span style="color: #009900;">&#123;</span><span style="color: #ff0000;">'os'</span><span style="color: #009900;">&#125;</span> eq <span style="color: #ff0000;">&quot;Linux&quot;</span> <span style="color: #009900;">&#41;</span>
 <span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$command</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">'/sbin/ifconfig  | awk '</span> . <span style="color: #ff0000;">&quot;'&quot;</span> . <span style="color: #ff0000;">'/eth0/ {print $5}'</span> . <span style="color: #ff0000;">&quot;'&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #0000ff;">$mac</span><span style="color: #339933;">=</span>`<span style="color: #0000ff;">$command</span>`<span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span>
 <span style="color: #b1b100;">elsif</span> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$info</span><span style="color: #009900;">&#123;</span><span style="color: #ff0000;">'os'</span><span style="color: #009900;">&#125;</span> eq <span style="color: #ff0000;">&quot;SunOS&quot;</span> <span style="color: #009900;">&#41;</span>
 <span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$command</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">'arp `hostname` | awk '</span> . <span style="color: #ff0000;">&quot;'&quot;</span> . <span style="color: #ff0000;">'{print $4}'</span> . <span style="color: #ff0000;">&quot;'&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #0000ff;">$mac</span><span style="color: #339933;">=</span>`<span style="color: #0000ff;">$command</span>`<span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span>
 <span style="color: #000066;">chomp</span> <span style="color: #0000ff;">$mac</span><span style="color: #339933;">;</span>
 <span style="color: #0000ff;">$info</span><span style="color: #009900;">&#123;</span><span style="color: #ff0000;">'host_mac'</span><span style="color: #009900;">&#125;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$mac</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># OS-version</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #009900;">&#123;</span>
 <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$uname_r</span> <span style="color: #339933;">=</span> `uname <span style="color: #339933;">-</span>r`<span style="color: #339933;">;</span>
 <span style="color: #000066;">chomp</span> <span style="color: #0000ff;">$uname_r</span><span style="color: #339933;">;</span>
&nbsp;
 <span style="color: #0000ff;">$info</span><span style="color: #009900;">&#123;</span><span style="color: #ff0000;">'os_version'</span><span style="color: #009900;">&#125;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$uname_r</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># OS-notes</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #009900;">&#123;</span>
 <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$os_flavor</span><span style="color: #339933;">=</span><span style="color: #ff0000;">&quot;&quot;</span><span style="color: #339933;">;</span>
 <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$info</span><span style="color: #009900;">&#123;</span><span style="color: #ff0000;">'os'</span><span style="color: #009900;">&#125;</span> eq <span style="color: #ff0000;">&quot;Darwin&quot;</span><span style="color: #009900;">&#41;</span>
 <span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">-</span>e <span style="color: #ff0000;">'/usr/bin/sw_vers'</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
   <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$productName</span> <span style="color: #339933;">=</span> `<span style="color: #339933;">/</span>usr<span style="color: #339933;">/</span>bin<span style="color: #339933;">/</span>sw_vers <span style="color: #339933;">-</span>productName`<span style="color: #339933;">;</span>
   <span style="color: #000066;">chomp</span> <span style="color: #0000ff;">$productName</span><span style="color: #339933;">;</span>
   <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$productVersion</span> <span style="color: #339933;">=</span> `<span style="color: #339933;">/</span>usr<span style="color: #339933;">/</span>bin<span style="color: #339933;">/</span>sw_vers <span style="color: #339933;">-</span>productVersion`<span style="color: #339933;">;</span>
   <span style="color: #000066;">chomp</span> <span style="color: #0000ff;">$productVersion</span><span style="color: #339933;">;</span>
   <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$buildVersion</span> <span style="color: #339933;">=</span> `<span style="color: #339933;">/</span>usr<span style="color: #339933;">/</span>bin<span style="color: #339933;">/</span>sw_vers <span style="color: #339933;">-</span>buildVersion`<span style="color: #339933;">;</span>
   <span style="color: #000066;">chomp</span> <span style="color: #0000ff;">$buildVersion</span><span style="color: #339933;">;</span>
   <span style="color: #0000ff;">$os_flavor</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;$productName $productVersion (build $buildVersion)&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
 <span style="color: #009900;">&#125;</span>
 <span style="color: #b1b100;">elsif</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$info</span><span style="color: #009900;">&#123;</span><span style="color: #ff0000;">'os'</span><span style="color: #009900;">&#125;</span> eq <span style="color: #ff0000;">&quot;Linux&quot;</span><span style="color: #009900;">&#41;</span>
 <span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">-</span>f <span style="color: #ff0000;">'/etc/redhat-release'</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
   <span style="color: #0000ff;">$os_flavor</span><span style="color: #339933;">=</span>`cat <span style="color: #ff0000;">'/etc/redhat-release'</span>`<span style="color: #339933;">;</span>
   <span style="color: #000066;">chomp</span> <span style="color: #0000ff;">$os_flavor</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #b1b100;">else</span>
  <span style="color: #009900;">&#123;</span>
   <span style="color: #0000ff;">$os_flavor</span><span style="color: #339933;">=</span><span style="color: #ff0000;">&quot;unknown Linux distro&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
 <span style="color: #009900;">&#125;</span>
 <span style="color: #b1b100;">elsif</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$info</span><span style="color: #009900;">&#123;</span><span style="color: #ff0000;">'os'</span><span style="color: #009900;">&#125;</span> eq <span style="color: #ff0000;">&quot;SunOS&quot;</span><span style="color: #009900;">&#41;</span>
 <span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">-</span>f <span style="color: #ff0000;">'/etc/release'</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
   <span style="color: #0000ff;">$os_flavor</span><span style="color: #339933;">=</span>`head <span style="color: #339933;">-</span>n <span style="color: #cc66cc;">1</span> <span style="color: #ff0000;">'/etc/release'</span>`<span style="color: #339933;">;</span>
   <span style="color: #000066;">chomp</span> <span style="color: #0000ff;">$os_flavor</span><span style="color: #339933;">;</span>
   <span style="color: #0000ff;">$os_flavor</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">s/^\s+//</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
 <span style="color: #009900;">&#125;</span>
 <span style="color: #0000ff;">$info</span><span style="color: #009900;">&#123;</span><span style="color: #ff0000;">'os_notes'</span><span style="color: #009900;">&#125;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$os_flavor</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># ram</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #009900;">&#123;</span>
 <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$mem</span><span style="color: #339933;">=</span><span style="color: #ff0000;">&quot;unknown&quot;</span><span style="color: #339933;">;</span>
 <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$info</span><span style="color: #009900;">&#123;</span><span style="color: #ff0000;">'os'</span><span style="color: #009900;">&#125;</span> eq <span style="color: #ff0000;">&quot;Darwin&quot;</span><span style="color: #009900;">&#41;</span>
 <span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$command</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">'sysctl hw.memsize | awk <span style="color: #000099; font-weight: bold;">\'</span>{print $2 &quot; / (1024*1024)&quot;}<span style="color: #000099; font-weight: bold;">\'</span> | bc'</span><span style="color: #339933;">;</span>
  <span style="color: #0000ff;">$mem</span> <span style="color: #339933;">=</span> `<span style="color: #0000ff;">$command</span>`<span style="color: #339933;">;</span>
  <span style="color: #000066;">chomp</span> <span style="color: #0000ff;">$mem</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">#  $mem .= &quot; MB&quot;;</span>
 <span style="color: #009900;">&#125;</span>
 <span style="color: #b1b100;">elsif</span> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$info</span><span style="color: #009900;">&#123;</span><span style="color: #ff0000;">'os'</span><span style="color: #009900;">&#125;</span> eq <span style="color: #ff0000;">&quot;Linux&quot;</span> <span style="color: #009900;">&#41;</span>
 <span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$command</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">'cat /proc/meminfo | perl -ne <span style="color: #000099; font-weight: bold;">\'</span>if (/Mem:\s+(\d+)/) { print int( $1 / (1024 * 1024) ) }<span style="color: #000099; font-weight: bold;">\'</span> '</span><span style="color: #339933;">;</span>
  <span style="color: #0000ff;">$mem</span> <span style="color: #339933;">=</span> `<span style="color: #0000ff;">$command</span>`<span style="color: #339933;">;</span>
  <span style="color: #000066;">chomp</span> <span style="color: #0000ff;">$mem</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">#  $mem .= &quot; MB&quot;;</span>
 <span style="color: #009900;">&#125;</span>
 <span style="color: #b1b100;">elsif</span> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$info</span><span style="color: #009900;">&#123;</span><span style="color: #ff0000;">'os'</span><span style="color: #009900;">&#125;</span> eq <span style="color: #ff0000;">&quot;SunOS&quot;</span> <span style="color: #009900;">&#41;</span>
 <span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$command</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">'/usr/local/bin/sysinfo -msglevel terse -show &quot;memory&quot;'</span><span style="color: #339933;">;</span>
  <span style="color: #0000ff;">$mem</span> <span style="color: #339933;">=</span> `<span style="color: #0000ff;">$command</span>`<span style="color: #339933;">;</span>
  <span style="color: #000066;">chomp</span> <span style="color: #0000ff;">$mem</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$mem</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">m/(\d+) MB/</span><span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;"># chop out the ' MB' part</span>
  <span style="color: #009900;">&#123;</span>
   <span style="color: #0000ff;">$mem</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$1</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
 <span style="color: #009900;">&#125;</span>
 <span style="color: #0000ff;">$info</span><span style="color: #009900;">&#123;</span><span style="color: #ff0000;">'ram_mbytes'</span><span style="color: #009900;">&#125;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$mem</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#########</span>
<span style="color: #666666; font-style: italic;"># print out info</span>
<span style="color: #b1b100;">foreach</span> <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$key</span> <span style="color: #009900;">&#40;</span><span style="color: #000066;">sort</span> <span style="color: #000066;">keys</span> <span style="color: #0000ff;">%info</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
 <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$key</span> <span style="color: #b1b100;">ne</span> <span style="color: #ff0000;">&quot;&quot;</span><span style="color: #009900;">&#41;</span>
 <span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$value</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$info</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$key</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
  <span style="color: #000066;">print</span> <span style="color: #ff0000;">&quot;$key=$value<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>


<div style="clear:both; padding-bottom:0.25em"></div>
]]></content:encoded>
			<wfw:commentRss>http://harnly.net/2005/blog/geek/macosx/machine-info/feed/</wfw:commentRss>
		</item>
		<item>
		<title>GNU screen hack-fu: running one command in multiple windows</title>
		<link>http://harnly.net/2005/blog/geek/macosx/gnu-screen/</link>
		<comments>http://harnly.net/2005/blog/geek/macosx/gnu-screen/#comments</comments>
		<pubDate>Mon, 09 May 2005 21:26:21 +0000</pubDate>
		<dc:creator>aaronharnly</dc:creator>
		
		<category><![CDATA[macosx]]></category>

		<guid isPermaLink="false">http://harnly.net/blog/computers/macosx/42</guid>
		<description><![CDATA[I&#8217;ve long used the wonderful GNU screen text-windowing system, which allows you to do lots of neat things like detach a terminal session and reattach later, and switch between multiple terminal `windows&#8217; within a single session.

When you have lots of gnu screen windows open, sometimes it&#8217;d be nice to run the same command on several [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve long used the wonderful <a href="http://www.gnu.org/software/screen/">GNU screen</a> text-windowing system, which allows you to do lots of neat things like detach a terminal session and reattach later, and switch between multiple terminal `windows&#8217; within a single session.</p>

<p>When you have lots of gnu screen windows open, sometimes it&#8217;d be nice to run the same command on several of them &#8212; for example, <tt>cd</tt> several windows to the same directory, or <tt>ssh</tt> to the same server. I&#8217;ve always done this by copy-and-pasting, though there are some funky commands in screen for copying and pasting text between windows.</p>

<p>Now, thanks to the <b>screen -X</b> command and a short shell script, I can do this very easily.</p><p>I name the script <b>screenex</b>, and use it as follows:</p>

<p><span id="more-42"></span></p>

<p><code> [03:36 PM mithras@powerbook: ~] screenex 1 6 ls
In windows 1 - 6, doing: ls</code></p>

<p>I simply pass the range of window numbers to run the command in, followed by the command itself. I can also omit the second number, to execute the command on just one other window:</p>

<p><code>[03:39 PM mithras@powerbook: ~] screenex 2 pine
In windows 2 - 2, doing: pine</code></p>

<p>Neat! This becomes much more powerful, though, when you add substitution of the window number. When you include the token <tt>&#8211;INDEX&#8211;</tt> in the command, the window number is substituted for <tt>&#8211;INDEX&#8211;</tt>. I use this to launch <tt>ssh</tt> connections to six machines at once, which is handy when I&#8217;m running a bunch of jobs in parallel. At work we have a bunch of servers, named server1.school.edu, server2.school.edu, etc. So to connect to a different machine in each window, I just run:</p>

<p><code>[03:41 PM mithras@powerbook: ~] screenex 1 6 ssh server&#8211;INDEX&#8211;.school.edu
In windows 1 - 6, doing: ssh server&#8211;INDEX&#8211;.school.edu</code></p>

<p>And I&#8217;m connected, ready to run my parallel jobs! You can also do cool stuff if you have environment variables that are indexed by number, for example WORKING<em>DIR</em>1, WORKING<em>DIR</em>2, etc. Anyway, I&#8217;ll save more for later.</p>

<hr />

<h2>The script:</h2>

<p>(Note that the ^M character is a literal newline character, which you can enter in <tt>vi</tt> by typing ctrl-V, then enter.)</p>


<div class="wp_syntax"><div class="code"><pre class="bash"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># command to run the given command on multiple `GNU screen' windows</span>
<span style="color: #666666; font-style: italic;">#  usage: screenex [begin-window] [end-window] command</span>
<span style="color: #666666; font-style: italic;"># </span>
<span style="color: #666666; font-style: italic;">#  by Mithras The Prophet (mithras.the.prophet, which is a gmail account.)</span>
<span style="color: #666666; font-style: italic;"># </span>
&nbsp;
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># returns 1 if arg is numeric, 0 otherwise</span>
<span style="color: #666666; font-style: italic;">#</span>
is_numeric<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #7a0874; font-weight: bold;">&#123;</span>
	<span style="color: #007800;">var=</span><span style="color: #ff0000;">&quot;$1&quot;</span>
	<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> -z <span style="color: #ff0000;">&quot;$var&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
		<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;0&quot;</span>
	<span style="color: #000000; font-weight: bold;">else</span>
		<span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;$var&quot;</span> -eq <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$?</span> -eq <span style="color: #000000;">0</span> -o <span style="color: #007800;">$?</span> -eq <span style="color: #000000;">1</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span> 
			<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;1&quot;</span>
		<span style="color: #000000; font-weight: bold;">else</span>
			<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;0&quot;</span>
		<span style="color: #000000; font-weight: bold;">fi</span>
	<span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># if argument 1, or arguments 1 and 2 are numeric, then</span>
<span style="color: #666666; font-style: italic;">#   we apply the command to just that range of windows;</span>
<span style="color: #666666; font-style: italic;">#   otherwise, to all windows</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #007800;">mycommand=</span><span style="color: #ff0000;">&quot;&quot;</span>
<span style="color: #007800;">window_begin=</span><span style="color: #ff0000;">&quot;1&quot;</span> <span style="color: #666666; font-style: italic;"># beginning of range of windows to send command to</span>
<span style="color: #007800;">window_end=</span><span style="color: #ff0000;">&quot;6&quot;</span>  <span style="color: #666666; font-style: italic;"># and end</span>
&nbsp;
<span style="color: #007800;">arg1=</span><span style="color: #ff0000;">&quot;$1&quot;</span>
<span style="color: #7a0874; font-weight: bold;">shift</span>;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> -z <span style="color: #ff0000;">&quot;$arg1&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
	<span style="color: #7a0874; font-weight: bold;">exit</span>;
<span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> $<span style="color: #7a0874; font-weight: bold;">&#40;</span>is_numeric <span style="color: #ff0000;">&quot;$arg1&quot;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> -eq <span style="color: #000000;">1</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
	<span style="color: #666666; font-style: italic;"># this is beginning of range</span>
	<span style="color: #007800;">window_begin=</span><span style="color: #ff0000;">&quot;$arg1&quot;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;"># try to grab a second numeric arg?</span>
	<span style="color: #007800;">arg2=</span><span style="color: #ff0000;">&quot;$1&quot;</span>
	<span style="color: #7a0874; font-weight: bold;">shift</span>;
	<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> $<span style="color: #7a0874; font-weight: bold;">&#40;</span>is_numeric <span style="color: #ff0000;">&quot;$arg2&quot;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> -eq <span style="color: #000000;">1</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
		<span style="color: #666666; font-style: italic;"># we have a second number!</span>
		<span style="color: #007800;">window_end=</span><span style="color: #ff0000;">&quot;$arg2&quot;</span>
		<span style="color: #666666; font-style: italic;"># get start of command</span>
		<span style="color: #007800;">arg3=</span><span style="color: #ff0000;">&quot;$1&quot;</span>
		<span style="color: #7a0874; font-weight: bold;">shift</span>;
		<span style="color: #007800;">mycommand=</span><span style="color: #ff0000;">&quot;$arg3&quot;</span>
	<span style="color: #000000; font-weight: bold;">else</span>
		<span style="color: #666666; font-style: italic;"># ahve second arg, but not a number</span>
		<span style="color: #666666; font-style: italic;"># so it must be start of command</span>
		<span style="color: #007800;">window_end=</span><span style="color: #ff0000;">&quot;$window_begin&quot;</span> <span style="color: #666666; font-style: italic;"># just do the one window</span>
		<span style="color: #007800;">mycommand=</span><span style="color: #ff0000;">&quot;$arg2&quot;</span>
	<span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #000000; font-weight: bold;">else</span>
	<span style="color: #666666; font-style: italic;"># arg1 -not- numeric, </span>
	<span style="color: #666666; font-style: italic;"># so it must be start of command</span>
	<span style="color: #007800;">mycommand=</span><span style="color: #ff0000;">&quot;$arg1&quot;</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">while</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000; font-weight: bold;">!</span> -z <span style="color: #ff0000;">&quot;$1&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">do</span>
	<span style="color: #007800;">mycommand=</span><span style="color: #ff0000;">&quot;$mycommand <span style="color: #000099; font-weight: bold;">\&quot;</span>$1<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span> <span style="color: #666666; font-style: italic;"># rest of line</span>
	<span style="color: #7a0874; font-weight: bold;">shift</span>
<span style="color: #000000; font-weight: bold;">done</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;In windows $window_begin - $window_end, doing: $mycommand&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># now execute!</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #007800;">newline=</span><span style="color: #000000; font-weight: bold;">&lt;&lt;</span>EOQ
&nbsp;
EOQ
<span style="color: #7a0874; font-weight: bold;">let</span> <span style="color: #ff0000;">&quot;window_end = $window_end + 1&quot;</span> <span style="color: #666666; font-style: italic;"># so we can do strict -lt test</span>
<span style="color: #007800;">index=</span><span style="color: #ff0000;">&quot;$window_begin&quot;</span>
<span style="color: #000000; font-weight: bold;">while</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$index</span> -lt <span style="color: #007800;">$window_end</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">do</span>
	<span style="color: #007800;">thiscommand=</span><span style="color: #800000;">${mycommand//--INDEX--/$index}</span>
	screen -X at <span style="color: #800000;">${index}</span><span style="color: #666666; font-style: italic;"># stuff &quot;${thiscommand}</span>
<span style="color: #ff0000;">&quot;
	let &quot;</span>index = <span style="color: #007800;">$index</span> + <span style="color: #000000;">1</span><span style="color: #ff0000;">&quot;
done
</span</pre></div></div>


<div style="clear:both; padding-bottom:0.25em"></div>
]]></content:encoded>
			<wfw:commentRss>http://harnly.net/2005/blog/geek/macosx/gnu-screen/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Safari / Dashboard vulnerability in OS X 10.4.0</title>
		<link>http://harnly.net/2005/blog/geek/macosx/safari-dashboard-vulnerability-in-os-x-1040/</link>
		<comments>http://harnly.net/2005/blog/geek/macosx/safari-dashboard-vulnerability-in-os-x-1040/#comments</comments>
		<pubDate>Mon, 09 May 2005 20:23:55 +0000</pubDate>
		<dc:creator>aaronharnly</dc:creator>
		
		<category><![CDATA[macosx]]></category>

		<guid isPermaLink="false">http://harnly.net/blog/computers/macosx/safari-dashboard-vulnerability-in-os-x-1040</guid>
		<description><![CDATA[This page discusses a security flaw resulting from a series of bad design choices in Safari and Dashboard in OS X 10.4, and links to a demonstration exploit.

<p class="warning">You can make your machine safe by <b>unchecking</b> the ``automatically open `safe' files" option in Safari:<br />
<img src="http://www1.cs.columbia.edu/~aaron/files/widgets/uncheck-safe.png">]]></description>
			<content:encoded><![CDATA[<p>This and the next few posts are full `geek_mode=on&#8217; posts. Sorry.</p>

<hr />

<p><img src="http://img.photobucket.com/albums/v609/mithrastheprophet/forum/2005/dashboard-evil.png"></p>

<h1>Safari / Dashboard vulnerability in OS X 10.4</h1>

<p>This page discusses a security flaw resulting from a series of bad design choices in Safari and Dashboard in OS X 10.4, and links to a demonstration exploit.</p>

<p class="warning">You can make your machine safe by <b>unchecking</b> the &#8220;automatically open `safe&#8217; files&#8221; option in Safari:<br />
<img src="http://www1.cs.columbia.edu/~aaron/files/widgets/uncheck-safe.png"></p>

<hr />

<p>*<b>Update: Mac OS X 10.4.1</b> fixes this vulnerability, by changing Safari to present a dialog when downloading <i>all</i> widgets. Kudos to Apple for their speedy response to the issue.</li>
* <b>Updated May 10</b> with a new, simpler, more deadly exploit.</li></p>

<hr />

<h2>1. Widget Auto-Install</h2>

<p>Safari 2.0 in Mac OS X 10.4 Tiger has a dangerous new &#8220;feature&#8221;. By default, when asked to download a .zipped Dashboard widget, Safari not only unzips the widget, but also <a href="http://developer.apple.com/documentation/AppleApplications/Conceptual/Dashboard_Tutorial/Deployment/chapter_14_section_2.html#//apple_ref/doc/uid/TP40001340-CH214-DontLinkElementID_2">copies the widget into ~/Library/Widgets</a>, and adds it to your <a href="http://www.apple.com/macosx/tips/">Dashboard Bar</a>. As first pointed out by <a href="http://stephan.com/widgets/zaptastic/">Stephan.com</a>, Safari does this not only for widgets you explicitly click on, but also for widgets that are silently, automatically downloaded by a web page&#8217;s META refresh tag. So a malicious website can auto-install potentially malicious widgets without you even realizing the installation happened.</p>

<p>This is the rough equivalent of automatically installing auto-downloaded applications into the /Applications/ folder, and putting them on the Dock.</p>

<h2>2. The Evil Twin</h2>

<p>Apple&#8217;s second major mistake in Dashboard is in how widgets are loaded.</p>

<p>First, it is important to emphasize that the auto-installed widgets <i>do not execute automatically</i>. It remains a `social engineering&#8217; task for a malicious attacker to get you to launch with widget by dragging it from your Dashboard Bar.</p>

<p>However, this is aided by Apple&#8217;s second <b>incredibly bad design decision.</b> Widgets are identified by a `bundle identifier&#8217;, such as <tt>com.apple.widget.stickies</tt>. When Dashboard encounters two or more widgets with the same bundle identifier, it <b>only displays the last one loaded.</b> And &#8212; you guessed it &#8212; widgets in ~/Library/Widgets are loaded after the system-supplied widgets in /Library/Widgets.</p>

<p>This means that our malicious widget can <b>completely replace</b> an Apple-supplied widget. Your ordinary Stickies widget simply will not appear in the Dashboard Bar &#8212; but in its place, silently installed by Safari, is a malicious widget.</p>

<div class="photoframe">
For example, here is the Dashboard Bar before visiting a malicious web page:
 <div><img src="http://www1.cs.columbia.edu/~aaron/files/widgets/before.png"></div>
</div>

<div class="photoframe">
And here it is afterwards:
 <div><img src="http://www1.cs.columbia.edu/~aaron/files/widgets/after.png"></div>
 <div>Can you tell the difference? If you can&#8217;t, and try to create a new Sticky note&#8230;</div>
</div>

<div class="photoframe">
 <div><img src="http://www1.cs.columbia.edu/~aaron/files/widgets/oops.png"></div>
 <div>&#8230;you have just launched a malicious program.</div>
</div>

<p><strong>Note:</strong> It appears that an additional, unrelated bug in Dashboard may actually be a saving grace here. After ~/Library/Widgets has been updated, Dashboard sometimes garbles the contents of the Dashboard Bar, so when you try to drag a widget from the Bar, you get no widget, or an entirely different widget. Scrolling between pages of the bar resolves the issue. Nonetheless, your original safe Stickies is now gone, with a malicious one in its place.</p>

<h2>3. The Sandbox That Isn&#8217;t</h2>

<p>And now we come to Apple&#8217;s third major mistake. Apple went to great lengths to develop a <a href="http://developer.apple.com/documentation/AppleApplications/Conceptual/Dashboard_Tutorial/Security/chapter_10_section_1.html#//apple_ref/doc/uid/TP40001340-CH210-TPXREF101">security model for Dashboard widgets</a>. By default, Widgets do not have access to local files, your network connection, or the ability to run native code, other than opening applicications and web pages.</p>

<p>Widgets can request additional privileges, including the ability to run arbitrary shell commands with the <tt>widget.system()</tt> call. The first time you double-click to run a widget that requests extra privileges, in most cases Dashboard presents an `are you sure?&#8217; prompt before allowing it to run.</p>

<div class="photoframe"><div><img src="http://www1.cs.columbia.edu/~aaron/files/widgets/areyousure.png"></div>
<div>Ought to appear, but does not.</div></div>

<p><b>However &#8212; incredibly, amazingly, stupidly &#8212; Dashboard does not present a prompt before running a privileged widget that is one of the Library/Widgets folders, including our auto-installed widgets.</b> So now your auto-installed replacement look-alike widget has <i>complete access to your system</i>, and could do nasty things like delete your home folder.</p>

<p>If a widget contains a native Mach-O executable, Safari will present a warning before downloading the widget. However, because widgets in ~/Library/Widgets can run shell commands with the <tt>widget.system()</tt> call, this protection is easily defeated. The demonstration exploit below includes a native Mach-O application with its bits reversed, so Safari does not realize it&#8217;s an application. A call to a Perl script unreverses the bits and makes the file executable, allowing full native code to be run.</p>

<p>Or, in a self-propagating attack, the widget could start a user-level Apache (on a user-accessible port like 8080), and email everyone in your addressbook with the URL to visit. They need only click on the URL to install the widget on their own Macs running Tiger, etc. etc.</p>

<hr />

<h2>4. Privilege Escalation</h2>

<p>Our malicious widget has all of the capabilities of an ordinary application launched by your user. This is bad enough, but it could also take advantage of privilege escalation vulnerabilities to run as root, where the damage could be more widespread. If the widget acquired root it could, for example, start Apache for you and proceed as described above in the self-propagation.</p>

<p>One such privilege escalation that is known to work on Tiger is <a href="http://adbas.net/OSX_Vuln.txt">this sudo-piggyback method</a>, in which the widget waits silently in the background for an admin user to run sudo, then piggy-backs onto the sudo grace period and acquires root. I&#8217;m sure there are a few other buffer-overflow vulnerabilities lying around.</p>

<hr />

<h1>Demonstration Exploit</h1>

<div class="warning">WARNING! This example exploit page will:<br />
1. download a single .zip file<br />
2. In Safari on OS X 10.4, auto-install a Stickies widget to your Dashboard Bar that replaces the Apple-supplied widget.<br />
3. Upon dragging the `Evil Stickies&#8217; widget out of the Dashboard Bar, request (and receive) full system access, unpacks a binary executable, and runs a Perl script to speak some greetings. <br />
</div>

<p>I have received feedback that due to an unrelated Dashboard bug, you might have to scroll the Dashboard Bar once or twice before you can drag new widgets from it.</p>

<p>None of these widgets does anything actually malicious. (My school would kill me if I were distributing malware from their servers <img src='http://harnly.net/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>

<p>To get rid of the evil <code>Stickies' widget, simply go to ~/Library/Widgets, and delete the widget named</code>Stickies.wdgt&#8217;. It will be gone &#8212; and the normal Apple widget back again &#8212; the next time you invoke the Dashboard.</p>

<p>If and only if you understand those removal instructions, you may now try the example exploit:</p>

<blockquote><a href="http://www1.cs.columbia.edu/~aaron/files/widgets/exploit.html">exploit.html</a></blockquote>

<p>I&#8217;d appreciate feedback on how these widgets behaved on your system. Did the Stickies widget require confirmation to run? Did the widget displace the Apple one from your Dashboard Bar?</p>

<p>Please write with comments to <a href="mailto:mithras.the.prophet@gmail.com">mithras.the.prophet@gmail.com</a>. Thanks.</p>
]]></content:encoded>
			<wfw:commentRss>http://harnly.net/2005/blog/geek/macosx/safari-dashboard-vulnerability-in-os-x-1040/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 1.201 seconds -->
