<?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>ptone &#187; osx</title>
	<atom:link href="http://ptone.com/dablog/tag/osx/feed/" rel="self" type="application/rss+xml" />
	<link>http://ptone.com/dablog</link>
	<description>Hodgepodge of thoughts, technical notes, and random observations</description>
	<lastBuildDate>Sat, 04 Jun 2011 14:42:35 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.5</generator>
		<item>
		<title>Restricting login to account based on IP address</title>
		<link>http://ptone.com/dablog/2009/10/restricting-login-to-account-based-on-ip-address/</link>
		<comments>http://ptone.com/dablog/2009/10/restricting-login-to-account-based-on-ip-address/#comments</comments>
		<pubDate>Wed, 28 Oct 2009 16:31:38 +0000</pubDate>
		<dc:creator>ptone</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[osx]]></category>
		<category><![CDATA[sys-admin]]></category>

		<guid isPermaLink="false">http://ptone.com/dablog/2009/10/restricting-login-to-account-based-on-ip-address/</guid>
		<description><![CDATA[At work we needed to have a standard local account that would work off campus, but not on campus. Here was my solution. First I check for the user and create it if it doesn&#8217;t exist #!bash user_exists=`dscl . -read /Users/remote GeneratedUID &#124; grep -c GeneratedUID` if [ $user_exists -ne 1 ]; then echo "creating [...]]]></description>
			<content:encoded><![CDATA[<p>At work we needed to have a standard local account that would work off campus, but not on campus. Here was my solution.</p>

<p><span id="more-97"></span>
First I check for the user and create it if it doesn&#8217;t exist</p>

<pre><code>#!bash
user_exists=`dscl . -read /Users/remote GeneratedUID | grep -c GeneratedUID`
if [ $user_exists -ne 1 ]; then
    echo "creating remote user"
    sudo dscl . -create /Users/remote
    dscl . -create /Users/remote UserShell /bin/bash
    sudo dscl . -create /Users/remote RealName "remote"
    dscl . -create /Users/remote UniqueID 509
    dscl . -create /Users/remote PrimaryGroupID 1000
    dscl . -create /Users/remote NFSHomeDirectory /Local/Users/remote
    dscl . -passwd /Users/remote remote
fi
</code></pre>

<p>because these are fully managed machines, I know what UIDs are available.  (For a method that checks for available UID I&#8217;ve posted a script from Andrew Mortensen below)</p>

<p>The next part of the script will check if the user is logged in as &#8220;remote&#8221; and on campus using a regular expression (our two subnets are 10.5.5.X and 10.6.6.X).  You could also check a router, DHCP server, or internal DNS as other approaches.  If they are on campus I use a display utility called BigHonkingText to throw up a message and then kill the loginwindow.</p>

<pre><code>#!bash
user="$1"

if [ "$user" == "remote" ]; then
    IP=`ifconfig | grep "inet " | grep -v 127.0.0.1 | awk 'NR&gt;1{exit};{ print $2 }'`
    echo $IP
    if [[ "$IP" =~ 10.[5,6].[5,6].[0-9]* ]]; then
        echo "on campus"
    /usr/local/bin/BigHonkingText "account not allowed on campus"
    killall loginwindow
        # reboot
    fi
fi
</code></pre>

<p>Here is the script from Andrew Mortensen:</p>

<pre><code>#!bash
#! /bin/sh

# create a template user

export PATH=/bin:/usr/bin:/sbin:/usr/sbin

# arbitrary uid
N_UID=501

# arbitrary gid
N_GID=501

# user name
N_USERNAME="$1"

# home
N_HOME="/var/${N_USERNAME}"

# system default user home template
SYSHOMETEMPLATE="/System/Library/User Template/English.lproj"

# make sure the uid and gid are available
while [ true ]; do
    user="`dscl . -search /users UniqueID ${N_UID} 2&gt;/dev/null`"

    if [ -z "${user}" ]; then
    break
    fi

    N_UID=$((${N_UID} + 1));
done

while [ true ]; do
    group=`dscl . -search /groups PrimaryGroupID ${N_GID} 2&gt;/dev/null`

    if [ -z "${group}" ]; then
    break
    fi

    N_GID=$((${N_GID} + 1));
done

# create user
dscl . &lt;&lt;EOF
create "/users/${N_USERNAME}"
create "/users/${N_USERNAME}" AppleMetaNodeLocation /Local/Default
create "/users/${N_USERNAME}" GeneratedUID `uuidgen`
create "/users/${N_USERNAME}" UniqueID ${N_UID}
create "/users/${N_USERNAME}" PrimaryGroupID ${N_GID}
create "/users/${N_USERNAME}" Password "*"
create "/users/${N_USERNAME}" RecordName ${N_USERNAME}
create "/users/${N_USERNAME}" RecordType dsRecTypeNative:users
create "/users/${N_USERNAME}" NFSHomeDirectory ${N_HOME}
create "/users/${N_USERNAME}" RealName "Template User"
create "/users/${N_USERNAME}" UserShell /bin/bash
EOF
if [ $? -ne 0 ]; then
    logger -is Creation of ${N_USERNAME} failed.

    # destroy account
    dscl . -delete "/users/${N_USERNAME}" 2&gt;/dev/null
    exit 2
fi

# create group
dscl . &lt;&lt;EOF
create "/groups/${N_USERNAME}"
create "/groups/${N_USERNAME}" AppleMetaNodeLocation /Local/Default
create "/groups/${N_USERNAME}" GeneratedUID `uuidgen`
create "/groups/${N_USERNAME}" PrimaryGroupID ${N_GID}
create "/groups/${N_USERNAME}" RecordName ${N_USERNAME}
create "/groups/${N_USERNAME}" RecordType dsRecTypeNative:groups
create "/groups/${N_USERNAME}" Password "*"
create "/groups/${N_USERNAME}" GroupMembership ${N_USERNAME}
EOF
if [ $? -ne 0 ]; then
    logger -is Creation of ${N_USERNAME} failed.

    # destroy account
    dscl . -delete "/users/${N_USERNAME}" 2&gt;/dev/null
    dscl . -delete "/groups/${N_USERNAME}" 2&gt;/dev/null
    exit 2
fi

# make home directory
mkdir -m 0700 -p ${N_HOME}
ditto --rsrc "${SYSHOMETEMPLATE}" "${N_HOME}"

if [ $? -ne 0 ]; then
    logger -is Creation of ${N_USERNAME} failed.

    # destroy account
    dscl . -delete "/users/${N_USERNAME}" 2&gt;/dev/null
    dscl . -delete "/groups/${N_USERNAME}" 2&gt;/dev/null
    exit 2
fi

chown -R ${N_USERNAME}:${N_USERNAME} ${N_HOME}

logger -i Creation of template user ${N_USERNAME} succeeded.

exit 0
</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://ptone.com/dablog/2009/10/restricting-login-to-account-based-on-ip-address/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Launching OE-Cake</title>
		<link>http://ptone.com/dablog/2009/09/launching-oe-cake/</link>
		<comments>http://ptone.com/dablog/2009/09/launching-oe-cake/#comments</comments>
		<pubDate>Wed, 09 Sep 2009 17:24:25 +0000</pubDate>
		<dc:creator>ptone</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[osx]]></category>
		<category><![CDATA[sysadmin]]></category>

		<guid isPermaLink="false">http://ptone.com/dablog/2009/09/launching-oe-cake/</guid>
		<description><![CDATA[OE-Cake is still expired for OS X &#8211; lets work around that So OE-Cake now has a beta for windows &#8211; but not OS X. We still have the binary from their old version that expired some time ago &#8211; we were launching it with ARD with the below trick, but now I&#8217;ve moved it [...]]]></description>
			<content:encoded><![CDATA[<p>OE-Cake is still expired for OS X &#8211; lets work around that</p>

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

<p>So OE-Cake now has a beta for windows &#8211; but not OS X.</p>

<p>We still have the binary from their old version that expired some time ago &#8211; we were launching it with ARD with the below trick, but now I&#8217;ve moved it into a read-only applescript application that the students can launch themselves:</p>

<pre><code>try
    do shell script "sudo date 1103100008" user name "admin" password "*****" with administrator privileges
end try

do shell script "open /Applications/OE-CAKE\\!.app"
delay 10
do shell script "launchctl stop org.ntp.ntpd" user name "admin" password "*****" with administrator privileges
do shell script "launchctl start org.ntp.ntpd" user name "admin" password "*****" with administrator privileges
</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://ptone.com/dablog/2009/09/launching-oe-cake/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Making Google Earth work for us</title>
		<link>http://ptone.com/dablog/2009/09/making-google-earth-work-for-us/</link>
		<comments>http://ptone.com/dablog/2009/09/making-google-earth-work-for-us/#comments</comments>
		<pubDate>Wed, 09 Sep 2009 00:02:07 +0000</pubDate>
		<dc:creator>ptone</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[osx]]></category>
		<category><![CDATA[sysadmin]]></category>

		<guid isPermaLink="false">http://ptone.com/dablog/2009/09/making-google-earth-work-for-us/</guid>
		<description><![CDATA[In our school environment, we had a couple issues with Google Earth&#8217;s default behaviors &#8211; here are my workarounds. First off we have a student web proxy that works based on a whitelist concept. So we have to allow any web traffic explicitly. With the help of little snitch and one incomplete help page from [...]]]></description>
			<content:encoded><![CDATA[<p>In our school environment, we had a couple issues with Google Earth&#8217;s default behaviors &#8211; here are my workarounds.</p>

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

<p>First off we have a student web proxy that works based on a whitelist concept.  So we have to allow any web traffic explicitly.  With the help of little snitch and one incomplete help page from google, here is what I&#8217;ve added to our global whitelist and seems to be allowing all the features:</p>

<ul>
<li>kh.google.com</li>
<li>www.keyhole.com</li>
<li>mw2.google.com</li>
<li>earth.google.com</li>
<li>auth.keyhole.com</li>
<li>maps.google.com</li>
<li>khmdb.google.com</li>
</ul>

<p>It also want access to www.google.com &#8211; but we don&#8217;t allow students to full google access &#8211; but Google Earth still seems to run fine.</p>

<p>The next annoyance was Google&#8217;s softwareupdate which wants to run for all users and update Google Earth on launch.</p>

<p>Adding the following to our loginhook fixed that:</p>

<pre><code>mkdir -P $nethomedir/Library/Google/
touch $nethomedir/Library/Google/GoogleSoftwareUpdate
chown root $nethomedir/Library/Google/GoogleSoftwareUpdate
chmod 644 $nethomedir/Library/Google/GoogleSoftwareUpdate
</code></pre>

<p>the $nethomedir var is fetched from dscl earlier in the script</p>

<p>Students need to have stored the proxy password in their keychain &#8211; but most have already done that when visiting a web page earlier.  They then just need to allow Google Earth to access their keychain.</p>
]]></content:encoded>
			<wfw:commentRss>http://ptone.com/dablog/2009/09/making-google-earth-work-for-us/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Editing long commands</title>
		<link>http://ptone.com/dablog/2009/08/editing-long-commands/</link>
		<comments>http://ptone.com/dablog/2009/08/editing-long-commands/#comments</comments>
		<pubDate>Tue, 18 Aug 2009 21:39:52 +0000</pubDate>
		<dc:creator>ptone</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[osx]]></category>
		<category><![CDATA[tip]]></category>

		<guid isPermaLink="false">http://ptone.com/dablog/2009/08/editing-long-commands/</guid>
		<description><![CDATA[Sometimes you get in a situation where you are editing a long command on the command line and you&#8217;d kill to be able to use your mouse to select a word or option in the middle. This tip makes it a pleasure First for me their was the discovery of cntl-a which jumps one back [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes you get in a situation where you are editing a long command on the command line and you&#8217;d kill to be able to use your mouse to select a word or option in the middle.  This tip makes it a pleasure</p>

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

<p>First for me their was the discovery of cntl-a which jumps one back to the beginning of a line, but just as often I wanted to delete a long path as an opt to a long command.</p>

<p>The first thing is to set your default Editor in your environment variables.  I use TextMate &#8211; but you could use textwrangler, VI, Emacs.</p>

<p>add a line like this to your ~/.bash_profile</p>

<p>export EDITOR=&#8221;mate -w&#8221;</p>

<p>then close your terminal session or &#8220;source ~/.bash_profile&#8221;</p>

<p>Now when you are in the middle of typing a long command, or after hitting the up arrow, press cntl-x and hold it, then hit &#8220;e&#8221;</p>

<p>boom &#8211; your current command opens up in your editor, you can use all the features of that editor, and when you save and close that file &#8211; the command will be executed back in your shell.</p>

<p>Since I&#8217;ve integrated this tip into my workflow &#8211; I find I use it all the time.</p>

<p>Only downside is GUI editors won&#8217;t work for SSH since you are in the remote hosts env &#8211; there is probably a tricky way to reverse-ssh the editor command back to you, but I haven&#8217;t explored that.</p>
]]></content:encoded>
			<wfw:commentRss>http://ptone.com/dablog/2009/08/editing-long-commands/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

