Skip to content
Browse files

Should have just used git rebase but oh well. Forgot the generated HT…

…ML files.
  • Loading branch information...
1 parent ea40835 commit 1192135feaa8653b0d3fa5c454c8b804a2540f05 @cwgem committed Mar 24, 2013
Showing with 141 additions and 133 deletions.
  1. +31 −31 git/git-rebase-fixing.html
  2. +80 −80 python/class-methods-and-self.html
  3. +30 −22 security/secure-workstation.html
View
62 git/git-rebase-fixing.html
@@ -43,26 +43,26 @@ <h2 id="_introduction" class="sect1">Introduction</h2>
<h2 id="_woops" class="sect1">Woops</h2>
<p class="paragraph">So right now there&#8217;s a fix I made for a bug in RVM that I&#8217;m about to put in a pull request for. So now I&#8217;ll fake a mistake and commit it:</p>
<div class="listingblock">
-<div class="content"><div class="highlight"><pre><span class="gp">$</span> vim scripts/cli
-<span class="gp">$</span> git add scripts/cli
-<span class="gp">$</span> git commit -m <span class="s2">&quot;This is a mistake&quot;</span>
-<span class="go">[ruby-reinstall 618f439] This is a mistake</span>
-<span class="gp">$</span> git push origin ruby-reinstall
-<span class="go">Counting objects: 7, done.</span>
-<span class="go">Delta compression using up to 4 threads.</span>
-<span class="go">Compressing objects: 100% (4/4), done.</span>
-<span class="go">Writing objects: 100% (4/4), 364 bytes, done.</span>
-<span class="go">Total 4 (delta 3), reused 0 (delta 0)</span>
-<span class="go">To git@github.com:cwgem/rvm.git</span>
-<span class="go"> 4994dd5..618f439 ruby-reinstall -&gt; ruby-reinstall</span>
+<div class="content"><div class="highlight"><pre>$ vim scripts/cli
+$ git add scripts/cli
+$ git commit -m &quot;This is a mistake&quot;
+[ruby-reinstall 618f439] This is a mistake
+$ git push origin ruby-reinstall
+Counting objects: 7, done.
+Delta compression using up to 4 threads.
+Compressing objects: 100% (4/4), done.
+Writing objects: 100% (4/4), 364 bytes, done.
+Total 4 (delta 3), reused 0 (delta 0)
+To git@github.com:cwgem/rvm.git
+ 4994dd5..618f439 ruby-reinstall -&gt; ruby-reinstall
</pre></div></div></div>
<p class="paragraph">Now it&#8217;s not only committed, but also pushed to the remote repository (which is once again an exclusive use fork). While looking over the pull request I notice my horrible error. On top of that I look at the commit message and realize that I forgot to include the issue number. Fortunately this can be fixed.</p>
<h2 id="_git_magic" class="sect1">Git Magic</h2>
<p class="paragraph">The first order of business is reverting the mistake:</p>
<div class="listingblock">
-<div class="content"><div class="highlight"><pre><span class="gp">$</span> git revert 618f4398bfeea938a1b9878b9fcf419b94d85e6c
-<span class="go">[ruby-reinstall 67b8cf6] Revert &quot;This is a mistake&quot;</span>
-<span class="go"> 1 file changed, 1 insertion(+)</span>
+<div class="content"><div class="highlight"><pre>$ git revert 618f4398bfeea938a1b9878b9fcf419b94d85e6c
+[ruby-reinstall 67b8cf6] Revert &quot;This is a mistake&quot;
+ 1 file changed, 1 insertion(+)
</pre></div></div></div>
<p class="paragraph">But now looking at the logs:</p>
<div class="listingblock">
@@ -89,7 +89,7 @@ <h2 id="_git_magic" class="sect1">Git Magic</h2>
</pre></div></div></div>
<p class="paragraph">This would be annoying for the person on the other side of the pull request to review. That&#8217;s where <code>git rebase</code> comes in handy. In this case <code>git rebase</code> will be started by what&#8217;s called interactive mode. Interactive mode uses <code>$EDITOR</code> to handle history adjustments:</p>
<div class="listingblock">
-<div class="content"><div class="highlight"><pre><span class="gp">$</span> git rebase -i HEAD~3 <span class="c"># work with all commits starting from 3 commits up to HEAD</span>
+<div class="content"><div class="highlight"><pre>$ git rebase -i HEAD~3 # work with all commits starting from 3 commits up to HEAD
</pre></div></div></div>
<div class="listingblock">
<div class="content"><div class="highlight"><pre>pick 4994dd5 Fixed rvm reinstall/remove ruby not working properly
@@ -142,12 +142,12 @@ <h2 id="_git_magic" class="sect1">Git Magic</h2>
</pre></div></div></div>
<p class="paragraph">This results in the final commit message:</p>
<div class="listingblock">
-<div class="content"><div class="highlight"><pre><span class="gp">$</span> git rebase -i HEAD~3
-<span class="go">[detached HEAD b3d43f3] Fixed rvm reinstall/remove ruby not working properly. Addresses issue #1550.</span>
-<span class="go"> 1 file changed, 8 insertions(+), 8 deletions(-)</span>
-<span class="go">[detached HEAD 0473035] Fixed rvm reinstall/remove ruby not working properly. Addresses issue #1550.</span>
-<span class="go"> 1 file changed, 8 insertions(+), 8 deletions(-)</span>
-<span class="go">Successfully rebased and updated refs/heads/ruby-reinstall.</span>
+<div class="content"><div class="highlight"><pre>$ git rebase -i HEAD~3
+[detached HEAD b3d43f3] Fixed rvm reinstall/remove ruby not working properly. Addresses issue #1550.
+ 1 file changed, 8 insertions(+), 8 deletions(-)
+[detached HEAD 0473035] Fixed rvm reinstall/remove ruby not working properly. Addresses issue #1550.
+ 1 file changed, 8 insertions(+), 8 deletions(-)
+Successfully rebased and updated refs/heads/ruby-reinstall.
</pre></div></div></div>
<p class="paragraph">Just to be safe, verify with <code>git log</code>:</p>
<div class="listingblock">
@@ -170,22 +170,22 @@ <h2 id="_git_magic" class="sect1">Git Magic</h2>
</tr></table>
</div>
<div class="listingblock">
-<div class="content"><div class="highlight"><pre><span class="gp">$</span> git push origin ruby-reinstall --force
-<span class="go">Counting objects: 7, done.</span>
-<span class="go">Delta compression using up to 4 threads.</span>
-<span class="go">Compressing objects: 100% (3/3), done.</span>
-<span class="go">Writing objects: 100% (4/4), 491 bytes, done.</span>
-<span class="go">Total 4 (delta 3), reused 1 (delta 1)</span>
-<span class="go">To git@github.com:cwgem/rvm.git</span>
-<span class="go"> + 618f439...0473035 ruby-reinstall -&gt; ruby-reinstall (forced update)</span>
+<div class="content"><div class="highlight"><pre>$ git push origin ruby-reinstall --force
+Counting objects: 7, done.
+Delta compression using up to 4 threads.
+Compressing objects: 100% (3/3), done.
+Writing objects: 100% (4/4), 491 bytes, done.
+Total 4 (delta 3), reused 1 (delta 1)
+To git@github.com:cwgem/rvm.git
+ + 618f439...0473035 ruby-reinstall -&gt; ruby-reinstall (forced update)
</pre></div></div></div>
<p class="paragraph">This effectively overwrites the remote repository&#8217;s history as well, merging the commits so that everything looks clean when the pull request is done.</p>
<h2 id="_conclusion" class="sect1">Conclusion</h2>
<p class="paragraph">While being a useful piece of functionality, <code>git rebase</code> should be used with caution when dealing with other people&#8217;s work. Consider it like proofreading a book, where someone edits paragraphs and sentence structure. Once the book goes out to customers, the proofreader wouldn&#8217;t visit customers in person to fix an issue they noticed after the fact. Instead they would most likely issue an errata (<code>git revert</code> or additional commits). <code>git rebase</code> works the same way, "proofreading" commits before publishing them to the public (or internally within an organization). It&#8217;s definitely a great tool to have in one&#8217;s git toolbox.</p>
</div>
<div id="footer">
<p id="footer-text">
-Last updated 2013-03-24 18:35:49 PDT
+Last updated 2013-03-24 18:49:15 PDT
</p>
<div id="footer-badges">
<a href="http://validator.w3.org/check?uri=referer">
View
160 python/class-methods-and-self.html
@@ -35,18 +35,18 @@ <h2 id="_introduction" class="sect1">Introduction</h2>
<h2 id="_a_basic_method" class="sect1">A Basic Method</h2>
<p class="paragraph">A basic example of a method being called in a class is something like this:</p>
<div class="listingblock">
-<div class="content"><div class="highlight"><pre><span class="c">#!/bin/python</span>
+<div class="content"><div class="highlight"><pre>#!/bin/python
-<span class="k">class</span> <span class="nc">Person</span><span class="p">:</span>
- <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">name</span><span class="p">):</span>
- <span class="bp">self</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="n">name</span>
+class Person:
+ def __init__(self,name):
+ self.name = name
- <span class="k">def</span> <span class="nf">sayname</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
- <span class="k">print</span><span class="p">(</span><span class="s">&quot;Your name is&quot;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
+ def sayname(self):
+ print(&quot;Your name is&quot;, self.name)
-<span class="n">myself</span> <span class="o">=</span> <span class="n">Person</span><span class="p">(</span><span class="s">&quot;Chris&quot;</span><span class="p">)</span>
-<span class="n">myself</span><span class="o">.</span><span class="n">sayname</span><span class="p">()</span>
+myself = Person(&quot;Chris&quot;)
+myself.sayname()
</pre></div></div></div>
<p class="paragraph">The output of this code is:</p>
<div class="listingblock">
@@ -63,71 +63,71 @@ <h2 id="_the_hidden_self" class="sect1">The Hidden self</h2>
<code>Objects/classobject.c</code> in the Python source tree. The code listing for
<code>method_call</code> is as follows:</p>
<div class="listingblock">
-<div class="content"><div class="highlight"><pre><span class="k">static</span> <span class="n">PyObject</span> <span class="o">*</span>
-<span class="nf">method_call</span><span class="p">(</span><span class="n">PyObject</span> <span class="o">*</span><span class="n">func</span><span class="p">,</span> <span class="n">PyObject</span> <span class="o">*</span><span class="n">arg</span><span class="p">,</span> <span class="n">PyObject</span> <span class="o">*</span><span class="n">kw</span><span class="p">)</span>
-<span class="p">{</span>
- <span class="n">PyObject</span> <span class="o">*</span><span class="n">self</span> <span class="o">=</span> <span class="n">PyMethod_GET_SELF</span><span class="p">(</span><span class="n">func</span><span class="p">);</span>
- <span class="n">PyObject</span> <span class="o">*</span><span class="n">result</span><span class="p">;</span>
-
- <span class="n">func</span> <span class="o">=</span> <span class="n">PyMethod_GET_FUNCTION</span><span class="p">(</span><span class="n">func</span><span class="p">);</span>
- <span class="k">if</span> <span class="p">(</span><span class="n">self</span> <span class="o">==</span> <span class="nb">NULL</span><span class="p">)</span> <span class="p">{</span>
- <span class="n">PyErr_BadInternalCall</span><span class="p">();</span>
- <span class="k">return</span> <span class="nb">NULL</span><span class="p">;</span>
- <span class="p">}</span>
- <span class="k">else</span> <span class="p">{</span>
- <span class="n">Py_ssize_t</span> <span class="n">argcount</span> <span class="o">=</span> <span class="n">PyTuple_Size</span><span class="p">(</span><span class="n">arg</span><span class="p">);</span>
- <span class="n">PyObject</span> <span class="o">*</span><span class="n">newarg</span> <span class="o">=</span> <span class="n">PyTuple_New</span><span class="p">(</span><span class="n">argcount</span> <span class="o">+</span> <span class="mi">1</span><span class="p">);</span>
- <span class="kt">int</span> <span class="n">i</span><span class="p">;</span>
- <span class="k">if</span> <span class="p">(</span><span class="n">newarg</span> <span class="o">==</span> <span class="nb">NULL</span><span class="p">)</span>
- <span class="k">return</span> <span class="nb">NULL</span><span class="p">;</span>
- <span class="n">Py_INCREF</span><span class="p">(</span><span class="n">self</span><span class="p">);</span>
- <span class="n">PyTuple_SET_ITEM</span><span class="p">(</span><span class="n">newarg</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="n">self</span><span class="p">);</span>
- <span class="k">for</span> <span class="p">(</span><span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="n">argcount</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span>
- <span class="n">PyObject</span> <span class="o">*</span><span class="n">v</span> <span class="o">=</span> <span class="n">PyTuple_GET_ITEM</span><span class="p">(</span><span class="n">arg</span><span class="p">,</span> <span class="n">i</span><span class="p">);</span>
- <span class="n">Py_XINCREF</span><span class="p">(</span><span class="n">v</span><span class="p">);</span>
- <span class="n">PyTuple_SET_ITEM</span><span class="p">(</span><span class="n">newarg</span><span class="p">,</span> <span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">,</span> <span class="n">v</span><span class="p">);</span>
- <span class="p">}</span>
- <span class="n">arg</span> <span class="o">=</span> <span class="n">newarg</span><span class="p">;</span>
- <span class="p">}</span>
- <span class="n">result</span> <span class="o">=</span> <span class="n">PyObject_Call</span><span class="p">((</span><span class="n">PyObject</span> <span class="o">*</span><span class="p">)</span><span class="n">func</span><span class="p">,</span> <span class="n">arg</span><span class="p">,</span> <span class="n">kw</span><span class="p">);</span>
- <span class="n">Py_DECREF</span><span class="p">(</span><span class="n">arg</span><span class="p">);</span>
- <span class="k">return</span> <span class="n">result</span><span class="p">;</span>
-<span class="p">}</span>
+<div class="content"><div class="highlight"><pre>static PyObject *
+method_call(PyObject *func, PyObject *arg, PyObject *kw)
+{
+ PyObject *self = PyMethod_GET_SELF(func);
+ PyObject *result;
+
+ func = PyMethod_GET_FUNCTION(func);
+ if (self == NULL) {
+ PyErr_BadInternalCall();
+ return NULL;
+ }
+ else {
+ Py_ssize_t argcount = PyTuple_Size(arg);
+ PyObject *newarg = PyTuple_New(argcount + 1);
+ int i;
+ if (newarg == NULL)
+ return NULL;
+ Py_INCREF(self);
+ PyTuple_SET_ITEM(newarg, 0, self);
+ for (i = 0; i &lt; argcount; i++) {
+ PyObject *v = PyTuple_GET_ITEM(arg, i);
+ Py_XINCREF(v);
+ PyTuple_SET_ITEM(newarg, i+1, v);
+ }
+ arg = newarg;
+ }
+ result = PyObject_Call((PyObject *)func, arg, kw);
+ Py_DECREF(arg);
+ return result;
+}
</pre></div></div></div>
<p class="paragraph">There&#8217;s quite a bit of C code here, but only a few parts need to be focused
on. First the code attempts to get <code>self</code> by looking at what called the
method. If nothing comes back, Python throws an error:</p>
<div class="listingblock">
-<div class="content"><div class="highlight"><pre> <span class="n">PyObject</span> <span class="o">*</span><span class="n">self</span> <span class="o">=</span> <span class="n">PyMethod_GET_SELF</span><span class="p">(</span><span class="n">func</span><span class="p">);</span>
- <span class="n">PyObject</span> <span class="o">*</span><span class="n">result</span><span class="p">;</span>
-
- <span class="n">func</span> <span class="o">=</span> <span class="n">PyMethod_GET_FUNCTION</span><span class="p">(</span><span class="n">func</span><span class="p">);</span>
- <span class="k">if</span> <span class="p">(</span><span class="n">self</span> <span class="o">==</span> <span class="nb">NULL</span><span class="p">)</span> <span class="p">{</span>
- <span class="n">PyErr_BadInternalCall</span><span class="p">();</span>
- <span class="k">return</span> <span class="nb">NULL</span><span class="p">;</span>
- <span class="p">}</span>
+<div class="content"><div class="highlight"><pre> PyObject *self = PyMethod_GET_SELF(func);
+ PyObject *result;
+
+ func = PyMethod_GET_FUNCTION(func);
+ if (self == NULL) {
+ PyErr_BadInternalCall();
+ return NULL;
+ }
</pre></div></div></div>
<p class="paragraph">Next it resizes the argument array, adding one to the length in order to
accommodate <code>self</code> being passed in:</p>
<div class="listingblock">
-<div class="content"><div class="highlight"><pre> <span class="n">Py_ssize_t</span> <span class="n">argcount</span> <span class="o">=</span> <span class="n">PyTuple_Size</span><span class="p">(</span><span class="n">arg</span><span class="p">);</span>
- <span class="n">PyObject</span> <span class="o">*</span><span class="n">newarg</span> <span class="o">=</span> <span class="n">PyTuple_New</span><span class="p">(</span><span class="n">argcount</span> <span class="o">+</span> <span class="mi">1</span><span class="p">);</span>
+<div class="content"><div class="highlight"><pre> Py_ssize_t argcount = PyTuple_Size(arg);
+ PyObject *newarg = PyTuple_New(argcount + 1);
</pre></div></div></div>
<p class="paragraph">Then it shifts in self as the first argument, adding the other arguments at
the end:</p>
<div class="listingblock">
-<div class="content"><div class="highlight"><pre> <span class="n">PyTuple_SET_ITEM</span><span class="p">(</span><span class="n">newarg</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="n">self</span><span class="p">);</span>
- <span class="k">for</span> <span class="p">(</span><span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="n">argcount</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span>
- <span class="n">PyObject</span> <span class="o">*</span><span class="n">v</span> <span class="o">=</span> <span class="n">PyTuple_GET_ITEM</span><span class="p">(</span><span class="n">arg</span><span class="p">,</span> <span class="n">i</span><span class="p">);</span>
- <span class="n">Py_XINCREF</span><span class="p">(</span><span class="n">v</span><span class="p">);</span>
- <span class="n">PyTuple_SET_ITEM</span><span class="p">(</span><span class="n">newarg</span><span class="p">,</span> <span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">,</span> <span class="n">v</span><span class="p">);</span>
- <span class="p">}</span>
- <span class="n">arg</span> <span class="o">=</span> <span class="n">newarg</span><span class="p">;</span>
+<div class="content"><div class="highlight"><pre> PyTuple_SET_ITEM(newarg, 0, self);
+ for (i = 0; i &lt; argcount; i++) {
+ PyObject *v = PyTuple_GET_ITEM(arg, i);
+ Py_XINCREF(v);
+ PyTuple_SET_ITEM(newarg, i+1, v);
+ }
+ arg = newarg;
</pre></div></div></div>
<p class="paragraph">Finally the method is now called with self and the other arguments passed into
the method:</p>
<div class="listingblock">
-<div class="content"><div class="highlight"><pre><span class="n">result</span> <span class="o">=</span> <span class="n">PyObject_Call</span><span class="p">((</span><span class="n">PyObject</span> <span class="o">*</span><span class="p">)</span><span class="n">func</span><span class="p">,</span> <span class="n">arg</span><span class="p">,</span> <span class="n">kw</span><span class="p">);</span>
+<div class="content"><div class="highlight"><pre>result = PyObject_Call((PyObject *)func, arg, kw);
</pre></div></div></div>
<div class="admonitionblock">
<table><tr>
@@ -146,23 +146,23 @@ <h2 id="_why" class="sect1">Why?</h2>
<h3 id="_instance_variables_vs_local_variables" class="sect2">Instance Variables vs Local Variables</h3>
<p class="paragraph">Take for example the following code:</p>
<div class="listingblock">
-<div class="content"><div class="highlight"><pre><span class="k">class</span> <span class="nc">Person</span><span class="p">:</span>
+<div class="content"><div class="highlight"><pre>class Person:
- <span class="k">def</span> <span class="nf">setname</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">firstname</span><span class="p">,</span><span class="n">lastname</span><span class="p">):</span>
- <span class="bp">self</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="n">firstname</span> <span class="o">+</span> <span class="s">&quot; &quot;</span> <span class="o">+</span> <span class="n">lastname</span>
- <span class="k">print</span><span class="p">(</span><span class="s">&quot;Name changed to&quot;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
+ def setname(self,firstname,lastname):
+ self.name = firstname + &quot; &quot; + lastname
+ print(&quot;Name changed to&quot;, self.name)
-<span class="n">myself</span> <span class="o">=</span> <span class="n">Person</span><span class="p">()</span>
-<span class="n">myself</span><span class="o">.</span><span class="n">setname</span><span class="p">(</span><span class="s">&quot;Chris&quot;</span><span class="p">,</span> <span class="s">&quot;White&quot;</span><span class="p">)</span>
+myself = Person()
+myself.setname(&quot;Chris&quot;, &quot;White&quot;)
</pre></div></div></div>
<p class="paragraph">Now take away the <code>self</code>:</p>
<div class="listingblock">
-<div class="content"><div class="highlight"><pre><span class="k">class</span> <span class="nc">Person</span><span class="p">:</span>
+<div class="content"><div class="highlight"><pre>class Person:
- <span class="k">def</span> <span class="nf">setname</span><span class="p">(</span><span class="n">firstname</span><span class="p">,</span><span class="n">lastname</span><span class="p">):</span>
- <span class="n">name</span> <span class="o">=</span> <span class="n">firstname</span> <span class="o">+</span> <span class="s">&quot; &quot;</span> <span class="o">+</span> <span class="n">lastname</span>
- <span class="k">print</span><span class="p">(</span><span class="s">&quot;Name changed to&quot;</span><span class="p">,</span> <span class="n">name</span><span class="p">)</span>
+ def setname(firstname,lastname):
+ name = firstname + &quot; &quot; + lastname
+ print(&quot;Name changed to&quot;, name)
</pre></div></div></div>
<p class="paragraph">Is this just setting name temporarily for local use? Or is it going to be
re-used in the class somewhere else? It&#8217;s hard to tell with the later example.
@@ -171,25 +171,25 @@ <h3 id="_instance_variables_vs_local_variables" class="sect2">Instance Variables
<h3 id="_base_classes_and_overrides" class="sect2">Base Classes and Overrides</h3>
<p class="paragraph">For an example of this:</p>
<div class="listingblock">
-<div class="content"><div class="highlight"><pre><span class="c">#!/bin/python</span>
+<div class="content"><div class="highlight"><pre>#!/bin/python
-<span class="k">class</span> <span class="nc">Chris</span><span class="p">:</span>
+class Chris:
- <span class="k">def</span> <span class="nf">givefood</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">food</span><span class="p">):</span>
- <span class="bp">self</span><span class="o">.</span><span class="n">food</span> <span class="o">=</span> <span class="n">food</span>
+ def givefood(self,food):
+ self.food = food
- <span class="k">def</span> <span class="nf">eatfood</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
- <span class="k">print</span><span class="p">(</span><span class="s">&quot;Chris eats&quot;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">food</span><span class="p">)</span>
+ def eatfood(self):
+ print(&quot;Chris eats&quot;, self.food)
-<span class="k">class</span> <span class="nc">AngryChris</span><span class="p">(</span><span class="n">Chris</span><span class="p">):</span>
+class AngryChris(Chris):
- <span class="k">def</span> <span class="nf">eatfood</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
- <span class="n">Chris</span><span class="o">.</span><span class="n">eatfood</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>
- <span class="k">print</span><span class="p">(</span><span class="s">&quot;Then he storms off&quot;</span><span class="p">)</span>
+ def eatfood(self):
+ Chris.eatfood(self)
+ print(&quot;Then he storms off&quot;)
-<span class="n">myself</span> <span class="o">=</span> <span class="n">AngryChris</span><span class="p">()</span>
-<span class="n">myself</span><span class="o">.</span><span class="n">givefood</span><span class="p">(</span><span class="s">&quot;carrots&quot;</span><span class="p">)</span>
-<span class="n">myself</span><span class="o">.</span><span class="n">eatfood</span><span class="p">()</span>
+myself = AngryChris()
+myself.givefood(&quot;carrots&quot;)
+myself.eatfood()
</pre></div></div></div>
<p class="paragraph">Here there is a base class of &#8216;Chris` which is inherited by <code>AngryChris</code>. The
method <code>eatfood</code> is overridden by the <code>AngryChris</code> class, but still calls the
@@ -209,7 +209,7 @@ <h2 id="_conclusion" class="sect1">Conclusion</h2>
<div id="footer">
<p id="footer-text">
Version 1.0<br />
-Last updated 2013-03-21 22:51:42 PDT
+Last updated 2013-03-24 18:48:28 PDT
</p>
<div id="footer-badges">
<a href="http://validator.w3.org/check?uri=referer">
View
52 security/secure-workstation.html
@@ -109,36 +109,36 @@ <h3 id="_caveats" class="sect2">Caveats</h3>
<h4 id="_skype" class="sect3">Skype</h4>
<p class="paragraph">Skype has a binary tampering system which prevents flagging some security protections off so it works properly. While this is rather unfortunate Skype is an essential business tool. With that in mind it takes a few steps to get it running:</p>
<div class="listingblock">
-<div class="content"><div class="highlight"><pre><span class="gp">#</span> mkdir -p /etc/portage/package.unmask
-<span class="gp">#</span> mkdir -p /etc/portage/package.license
-<span class="gp">#</span> <span class="nb">echo</span> <span class="s1">&#39;=net-im/skype-4.1.0.20&#39;</span> &gt;&gt; /etc/portage/package.keywords/skype
-<span class="gp">#</span> <span class="nb">echo</span> <span class="s1">&#39;=net-im/skype-4.1.0.20 skype-4.0.0.7-copyright&#39;</span> &gt;&gt; /etc/portage/package.license/skype
-<span class="gp">#</span> emerge skype
-<span class="gp">#</span> paxctl -c /opt/bin/skype
-<span class="gp">#</span> paxctl -m /opt/bin/skype <span class="c"># disable MPROTECT so it actually runs</span>
+<div class="content"><div class="highlight"><pre># mkdir -p /etc/portage/package.unmask
+# mkdir -p /etc/portage/package.license
+# echo &#39;=net-im/skype-4.1.0.20&#39; &gt;&gt; /etc/portage/package.keywords/skype
+# echo &#39;=net-im/skype-4.1.0.20 skype-4.0.0.7-copyright&#39; &gt;&gt; /etc/portage/package.license/skype
+# emerge skype
+# paxctl -c /opt/bin/skype
+# paxctl -m /opt/bin/skype # disable MPROTECT so it actually runs
</pre></div></div></div>
<p class="paragraph">After this and some headset setup Skype worked without a hitch and showed no issues during two group meetings.</p>
<h4 id="_dropbox" class="sect3">DropBox</h4>
<p class="paragraph">Same here with needing to disable protections. This was achieved through doing:</p>
<div class="listingblock">
-<div class="content"><div class="highlight"><pre><span class="gp">#</span> emerge dropbox
-<span class="gp">#</span> paxctl -c /opt/dropbox/dropbox
-<span class="gp">#</span> paxctl -m /opt/dropbox/dropbox
+<div class="content"><div class="highlight"><pre># emerge dropbox
+# paxctl -c /opt/dropbox/dropbox
+# paxctl -m /opt/dropbox/dropbox
</pre></div></div></div>
<h4 id="_google_talk" class="sect3">Google Talk</h4>
<p class="paragraph">This needs to use the latest version to keep up with the Google download page:</p>
<div class="listingblock">
-<div class="content"><div class="highlight"><pre><span class="gp">#</span> <span class="nb">echo</span> <span class="s1">&#39;www-plugins/google-talkplugin&#39;</span> &gt;&gt; /etc/portage/package.keywords/googletalk
-<span class="gp">#</span> <span class="nb">echo</span> <span class="s1">&#39;=www-plugins/google-talkplugin-3.13.2.0 Google-TOS&#39;</span> &gt;&gt; /etc/portage/package.license/googletalk
+<div class="content"><div class="highlight"><pre># echo &#39;www-plugins/google-talkplugin&#39; &gt;&gt; /etc/portage/package.keywords/googletalk
+# echo &#39;=www-plugins/google-talkplugin-3.13.2.0 Google-TOS&#39; &gt;&gt; /etc/portage/package.license/googletalk
</pre></div></div></div>
<p class="paragraph">That enables usage of Google Voice for phone calls in Chromium. Nothing had to be disabled for it protection wise to work.</p>
<h2 id="_home_directory_encryption" class="sect1">Home Directory Encryption</h2>
<p class="paragraph">This was put off till the end in order to avoid dealing with too much trouble during setup. After much research I came to the conclusion that using <a href="http://www.arg0.net/encfs">encfs</a> would allow for a reasonable balance in having a secure system and time to setup. Everything that would contain personal documents was in <code>/home</code>, so the idea was to encrypt that alone and leave the rest of the system (freely available software) to its own. As this works with FUSE, support will need to be enabled in the kernel, and fuse (sys-fs/fuse) will need to be installed.</p>
<p class="paragraph">First is to logout of the system entirely for all users. In this case there was only one user. Also X11 based login managers such as gdm, kdm, and xdm will all need to be shutdown. Next, have a root screen up to handle the administrative tasks, and be sure it isn&#8217;t in the <code>/home</code> directory somewhere. Now to create an encrypted location for <code>/home</code> to map to:</p>
<div class="listingblock">
-<div class="content"><div class="highlight"><pre><span class="gp">#</span> mv /home /home.orig
-<span class="gp">#</span> mkdir /home /home.enc
-<span class="gp">#</span> encfs --public /home.enc /home
+<div class="content"><div class="highlight"><pre># mv /home /home.orig
+# mkdir /home /home.enc
+# encfs --public /home.enc /home
</pre></div></div></div>
<p class="paragraph">This creates a directory, <code>/home.enc</code>, where all of the <code>/home</code> files will be in encrypted form. <code>/home</code> will become the unencrypted version when the proper key is given. From then on all files that go to <code>/home</code> are encrypted. <code>--public</code> was provided to make DropBox work properly, which will fail to run without it set. When first run, <code>encfs</code> will promopt:</p>
<div class="listingblock">
@@ -151,21 +151,29 @@ <h2 id="_home_directory_encryption" class="sect1">Home Directory Encryption</h2>
</pre></div></div></div>
<p class="paragraph">Here standard mode was selected by simply pressing enter. This provides a reasonable balance between security an performance for a desktop system. After selection of the security mode, a prompt will appear to set the key for encryption. Enter the password and remember, if you lose it your home data will no longer be accessible in plain form. It&#8217;s recommended to back up the data to a tarball somewhere, and then use gpg encryption to secure it:</p>
<div class="listingblock">
-<div class="content"><div class="highlight"><pre><span class="gp">#</span> tar cjpvf /backup/someplace/home-backup.tar.bz2 /home.orig
-<span class="gp">#</span> gpg -c /backup/someplace/home-backup.tar.bz2
+<div class="content"><div class="highlight"><pre># tar cjpvf /backup/someplace/home-backup.tar.bz2 /home.orig
+# gpg -c /backup/someplace/home-backup.tar.bz2
</pre></div></div></div>
<p class="paragraph">Later backups can be retrieved by running:</p>
<div class="listingblock">
-<div class="content"><div class="highlight"><pre><span class="gp">#</span> gpg /backup/someplace/home-backup.tar.bz2.gpg
+<div class="content"><div class="highlight"><pre># gpg /backup/someplace/home-backup.tar.bz2.gpg
</pre></div></div></div>
<p class="paragraph">Which will prompt for the password used to protect the file, and decrypt if it was successfully entered. Now it&#8217;s time to encrypt the home data by simply copying the old data to the new encrypted home:</p>
<div class="listingblock">
-<div class="content"><div class="highlight"><pre><span class="gp">#</span> rsync -a --progress /home.orig/ /home/
+<div class="content"><div class="highlight"><pre># rsync -a --progress /home.orig/ /home/
</pre></div></div></div>
+<div class="admonitionblock">
+<table><tr>
+<td class="icon">
+<img src="/images/warning.png" alt="Warning" />
+</td>
+<td class="content">You don&#8217;t need to do this if you use a desktop login system like <code>xdm</code></td>
+</tr></table>
+</div>
<p class="paragraph">One final step for X11 users is to get around an issue with the Xauthority file not locking properly. The following snippet can be added to the user shell&#8217;s rc file (<code>~/.bashrc</code> for example):</p>
<div class="listingblock">
-<div class="content"><div class="highlight"><pre><span class="go">export XAUTHORITY=/tmp/.Xauthority-$USER</span>
-<span class="go">export ICEAUTHORITY=/tmp/.ICEauthority-$USER</span>
+<div class="content"><div class="highlight"><pre>export XAUTHORITY=/tmp/.Xauthority-$USER
+export ICEAUTHORITY=/tmp/.ICEauthority-$USER
</pre></div></div></div>
<p class="paragraph">From there X11 should start without any issues.</p>
<h2 id="_conclusion" class="sect1">Conclusion</h2>
@@ -212,7 +220,7 @@ <h2 id="_conclusion" class="sect1">Conclusion</h2>
</div>
<div id="footer">
<p id="footer-text">
-Last updated 2013-03-24 18:30:25 PDT
+Last updated 2013-03-24 18:51:31 PDT
</p>
<div id="footer-badges">
<a href="http://validator.w3.org/check?uri=referer">

0 comments on commit 1192135

Please sign in to comment.
Something went wrong with that request. Please try again.