[tor-bugs] #4896 [Stem]: Chroot set up for stem

Tor Bug Tracker & Wiki torproject-admin at torproject.org
Thu Jan 12 17:48:56 UTC 2012


#4896: Chroot set up for stem
-------------------------+--------------------------------------------------
 Reporter:  gsathya      |          Owner:  atagar
     Type:  enhancement  |         Status:  new   
 Priority:  normal       |      Milestone:        
Component:  Stem         |        Version:        
 Keywords:               |         Parent:        
   Points:               |   Actualpoints:        
-------------------------+--------------------------------------------------
 I'm going to bounce of a couple of ideas for emulating a chroot set up.
 I'll attach the relevant branches to the ideas. Also, most of the code is
 just temp stuff to check which idea looks the least ugly.

 Ok, so starting off -

 Idea 1 (This is the one atagar mentioned) -
 https://gitweb.torproject.org/user/gsathya/stem.git/shortlog/refs/heads/chroot

 In stem/socket.py,
   Define a stripping_function(original_recv, prefix, control_file)
   Arguments -
      -- original_recv is the original function that we want to create a
 partial function of; in our case it is recv_message(control_file)
      -- prefix is the string that should be stripped out of the
 ControlMessage returned by recv_message(control_file)
      -- control_file is the argument passed to the original function,
 recv_message(control_file)

   This function returns a ControlMessage which has prefix stripped from
 it.

 In test/runner.py,
   Add a constant CHROOT_ENV that is set by run_tests.py when the --chroot
 arg is used.

   In Runner.start(),
     Check if CHROOT_ENV is set. If it is then do,
     stem.socket.recv_message =
 functools.partial(stem.socket.stripping_function, self._original_recv,
 self.get_test_dir())

   In Runner.stop(),
      Check if CHROOT_ENV is set. If it is then do,
      stem.socket.recv_message = self._original_recv

 Idea 2 -
 https://gitweb.torproject.org/user/gsathya/stem.git/shortlog/refs/heads/chroot2

 In stem/socket.py,
    Define a function strip(self, prefix) in ControlMessage.
    This function is similar to the stripping_function explained above. It
 takes a prefix as an argument and strips it from the content.

    recv_message(control_file) is modified -
       -- Add an extra argument "prefix" which is False by default. We set
 this to a string which we want to strip from the content.
       -- return ControlMessage(parsed_content, raw_content, prefix) rather
 than ControlMessage(parsed_content, raw_content)

 In test/runner.py.
     Initialise,
       self._chroot = False
       self._original_recv = stem.socket.recv_message

     In Runner.start(),
       Check if CHROOT_ENV is set. If it is then do,
       stem.socket.recv_message =
 functools.partial(stem.socket.recv_message, prefix = self.get_test_dir())

     In Runner.stop(),
       Check if CHROOT_ENV is set. If it is then do,
       stem.socket.recv_message = self._original_recv

 Note -
 - This idea follows from Idea 1.
 - This idea cleans up a bit on the monkey patching by defining a proper
 method strip() in ControlMessage.
 - But this changes the recv_message() by adding an extra argument "prefix"
 which is kinda ugly.

 Idea 3 -
 https://gitweb.torproject.org/user/gsathya/stem.git/shortlog/refs/heads/chroot1

 In stem/socket.py,
    Define a constant CHROOT_PREFIX = None. This constant is set to the
 prefix that needs to stripped from the content. This is done by
 stem.test.Runner
    If the CHROOT_PREFIX is not None, then the ControlMessage.strip()
 function is called.

 In test/runner.py,
   In Runner.start()
     Check if CHROOT_ENV is set. If it is then do,
        stem.socket.CHROOT_PREFIX = self.get_test_dir()

   In Runner.stop()
     Check if CHROOT_ENV is set. If it is then do,
        stem.socket.CHROOT_PREFIX = None

 Note -
 - This idea follows from Idea 2.
 - This involves no monkey patching. This is more like flicking on a
 switch.
 - I like this the best, unless I overlooked something really obvious which
 renders this useless.

 I haven't defined the strip()/stripping_function() yet, i'm not entirely
 sure what to do in it. It's just a bunch of comments of my vague
 understanding of it.

 If I didn't really make much sense, I blame it on my insomnia trying to
 get this to work. And also it's almost midnight here.

-- 
Ticket URL: <https://trac.torproject.org/projects/tor/ticket/4896>
Tor Bug Tracker & Wiki <https://trac.torproject.org/>
The Tor Project: anonymity online


More information about the tor-bugs mailing list