/mandos/trunk

To get this branch, use:
bzr branch http://bzr.recompile.se/loggerhead/mandos/trunk

« back to all changes in this revision

Viewing changes to mandos

  • Committer: teddy at recompile
  • Date: 2012-02-25 03:49:47 UTC
  • mto: This revision was merged to the branch mainline in revision 561.
  • Revision ID: teddy@recompile.se-20120225034947-qdjgp2h92bpote0d
* mandos: Use os.devnull instead of os.path.devnull.  Fix some white
          space.
  (PGPEngine.encrypt, PGPEngine.decrypt): Bug fix: open /dev/null for
                                          writing, not reading.

Show diffs side-by-side

added added

removed removed

Lines of Context:
175
175
    
176
176
    def encrypt(self, data, password):
177
177
        self.gnupg.passphrase = self.password_encode(password)
178
 
        with open(os.devnull) as devnull:
 
178
        with open(os.devnull, "w") as devnull:
179
179
            try:
180
180
                proc = self.gnupg.run(['--symmetric'],
181
181
                                      create_fhs=['stdin', 'stdout'],
192
192
    
193
193
    def decrypt(self, data, password):
194
194
        self.gnupg.passphrase = self.password_encode(password)
195
 
        with open(os.devnull) as devnull:
 
195
        with open(os.devnull, "w") as devnull:
196
196
            try:
197
197
                proc = self.gnupg.run(['--decrypt'],
198
198
                                      create_fhs=['stdin', 'stdout'],
199
199
                                      attach_fhs={'stderr': devnull})
200
 
                with contextlib.closing(proc.handles['stdin'] ) as f:
 
200
                with contextlib.closing(proc.handles['stdin']) as f:
201
201
                    f.write(data)
202
202
                with contextlib.closing(proc.handles['stdout']) as f:
203
203
                    decrypted_plaintext = f.read()
1963
1963
        sys.exit()
1964
1964
    if not noclose:
1965
1965
        # Close all standard open file descriptors
1966
 
        null = os.open(os.path.devnull, os.O_NOCTTY | os.O_RDWR)
 
1966
        null = os.open(os.devnull, os.O_NOCTTY | os.O_RDWR)
1967
1967
        if not stat.S_ISCHR(os.fstat(null).st_mode):
1968
1968
            raise OSError(errno.ENODEV,
1969
1969
                          "%s not a character device"
1970
 
                          % os.path.devnull)
 
1970
                          % os.devnull)
1971
1971
        os.dup2(null, sys.stdin.fileno())
1972
1972
        os.dup2(null, sys.stdout.fileno())
1973
1973
        os.dup2(null, sys.stderr.fileno())
2156
2156
         .gnutls_global_set_log_function(debug_gnutls))
2157
2157
        
2158
2158
        # Redirect stdin so all checkers get /dev/null
2159
 
        null = os.open(os.path.devnull, os.O_NOCTTY | os.O_RDWR)
 
2159
        null = os.open(os.devnull, os.O_NOCTTY | os.O_RDWR)
2160
2160
        os.dup2(null, sys.stdin.fileno())
2161
2161
        if null > 2:
2162
2162
            os.close(null)
2170
2170
    
2171
2171
    global main_loop
2172
2172
    # From the Avahi example code
2173
 
    DBusGMainLoop(set_as_default=True )
 
2173
    DBusGMainLoop(set_as_default=True)
2174
2174
    main_loop = gobject.MainLoop()
2175
2175
    bus = dbus.SystemBus()
2176
2176
    # End of Avahi example code