/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 Hogeborn
  • Date: 2009-12-27 03:35:58 UTC
  • Revision ID: teddy@fukt.bsnet.se-20091227033558-y57wv1u4cls3i8kq
TODO file changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
780
780
                                 dbus.Boolean(False, variant_level=1))
781
781
        return r
782
782
    
783
 
    ## D-Bus methods, signals & properties
 
783
    ## D-Bus methods & signals
784
784
    _interface = u"se.bsnet.fukt.Mandos.Client"
785
785
    
786
 
    ## Signals
 
786
    # CheckedOK - method
 
787
    @dbus.service.method(_interface)
 
788
    def CheckedOK(self):
 
789
        return self.checked_ok()
787
790
    
788
791
    # CheckerCompleted - signal
789
792
    @dbus.service.signal(_interface, signature=u"nxs")
815
818
        "D-Bus signal"
816
819
        pass
817
820
    
818
 
    ## Methods
819
 
    
820
 
    # CheckedOK - method
821
 
    @dbus.service.method(_interface)
822
 
    def CheckedOK(self):
823
 
        return self.checked_ok()
824
 
    
825
821
    # Enable - method
826
822
    @dbus.service.method(_interface)
827
823
    def Enable(self):
845
841
    def StopChecker(self):
846
842
        self.stop_checker()
847
843
    
848
 
    ## Properties
849
 
    
850
844
    # name - property
851
845
    @dbus_service_property(_interface, signature=u"s", access=u"read")
852
846
    def name_dbus_property(self):
995
989
    def handle(self):
996
990
        logger.info(u"TCP connection from: %s",
997
991
                    unicode(self.client_address))
998
 
        logger.debug(u"IPC Pipe FD: %d",
999
 
                     self.server.child_pipe[1].fileno())
 
992
        logger.debug(u"IPC Pipe FD: %d", self.server.child_pipe[1])
1000
993
        # Open IPC pipe to parent process
1001
 
        with contextlib.nested(self.server.child_pipe[1],
1002
 
                               self.server.parent_pipe[0]
1003
 
                               ) as (ipc, ipc_return):
 
994
        with contextlib.nested(os.fdopen(self.server.child_pipe[1],
 
995
                                         u"w", 1),
 
996
                               os.fdopen(self.server.parent_pipe[0],
 
997
                                         u"r", 0)) as (ipc,
 
998
                                                       ipc_return):
1004
999
            session = (gnutls.connection
1005
1000
                       .ClientSession(self.request,
1006
1001
                                      gnutls.connection
1147
1142
        
1148
1143
        This function creates a new pipe in self.pipe
1149
1144
        """
1150
 
        # Child writes to child_pipe
1151
 
        self.child_pipe = map(os.fdopen, os.pipe(), u"rw", (1, 0))
1152
 
        # Parent writes to parent_pipe
1153
 
        self.parent_pipe = map(os.fdopen, os.pipe(), u"rw", (1, 0))
 
1145
        self.child_pipe = os.pipe() # Child writes here
 
1146
        self.parent_pipe = os.pipe() # Parent writes here
1154
1147
        super(ForkingMixInWithPipes,
1155
1148
              self).process_request(request, client_address)
1156
1149
        # Close unused ends for parent
1157
 
        self.parent_pipe[0].close() # close read end
1158
 
        self.child_pipe[1].close()  # close write end
 
1150
        os.close(self.parent_pipe[0]) # close read end
 
1151
        os.close(self.child_pipe[1])  # close write end
1159
1152
        self.add_pipe_fds(self.child_pipe[0], self.parent_pipe[1])
1160
1153
    def add_pipe_fds(self, child_pipe_fd, parent_pipe_fd):
1161
1154
        """Dummy function; override as necessary"""
1162
 
        child_pipe_fd.close()
1163
 
        parent_pipe_fd.close()
 
1155
        os.close(child_pipe_fd)
 
1156
        os.close(parent_pipe_fd)
1164
1157
 
1165
1158
 
1166
1159
class IPv6_TCPServer(ForkingMixInWithPipes,
1256
1249
        self.enabled = True
1257
1250
    def add_pipe_fds(self, child_pipe_fd, parent_pipe_fd):
1258
1251
        # Call "handle_ipc" for both data and EOF events
1259
 
        gobject.io_add_watch(child_pipe_fd.fileno(),
 
1252
        gobject.io_add_watch(child_pipe_fd,
1260
1253
                             gobject.IO_IN | gobject.IO_HUP,
1261
1254
                             functools.partial(self.handle_ipc,
1262
 
                                               reply = parent_pipe_fd,
1263
 
                                               sender= child_pipe_fd))
1264
 
    def handle_ipc(self, source, condition, reply=None, sender=None):
 
1255
                                               reply_fd
 
1256
                                               =parent_pipe_fd))
 
1257
    def handle_ipc(self, source, condition, reply_fd=None,
 
1258
                   file_objects={}):
1265
1259
        condition_names = {
1266
1260
            gobject.IO_IN: u"IN",   # There is data to read.
1267
1261
            gobject.IO_OUT: u"OUT", # Data can be written (without
1279
1273
        logger.debug(u"Handling IPC: FD = %d, condition = %s", source,
1280
1274
                     conditions_string)
1281
1275
        
 
1276
        # Turn the pipe file descriptors into Python file objects
 
1277
        if source not in file_objects:
 
1278
            file_objects[source] = os.fdopen(source, u"r", 1)
 
1279
        if reply_fd not in file_objects:
 
1280
            file_objects[reply_fd] = os.fdopen(reply_fd, u"w", 0)
 
1281
        
1282
1282
        # Read a line from the file object
1283
 
        cmdline = sender.readline()
 
1283
        cmdline = file_objects[source].readline()
1284
1284
        if not cmdline:             # Empty line means end of file
1285
1285
            # close the IPC pipes
1286
 
            sender.close()
1287
 
            reply.close()
 
1286
            file_objects[source].close()
 
1287
            del file_objects[source]
 
1288
            file_objects[reply_fd].close()
 
1289
            del file_objects[reply_fd]
1288
1290
            
1289
1291
            # Stop calling this function
1290
1292
            return False
1329
1331
                if client.fingerprint == fpr:
1330
1332
                    attr_value = getattr(client, attr_name, None)
1331
1333
                    logger.debug("IPC reply: %r", attr_value)
1332
 
                    pickle.dump(attr_value, reply)
 
1334
                    pickle.dump(attr_value, file_objects[reply_fd])
1333
1335
                    break
1334
1336
            else:
1335
1337
                logger.error(u"Client %s on address %s requesting "
1336
1338
                             u"attribute %s not found", fpr, address,
1337
1339
                             attr_name)
1338
 
                pickle.dump(None, reply)
 
1340
                pickle.dump(None, file_objects[reply_fd])
1339
1341
        else:
1340
1342
            logger.error(u"Unknown IPC command: %r", cmdline)
1341
1343