Merge lp:~stefanor/ibid/logfile-visibility-567576-0.1 into lp:~ibid-core/ibid/old-release-0.1-1.6

Proposed by Stefano Rivera
Status: Merged
Approved by: Stefano Rivera
Approved revision: 950
Merged at revision: 950
Proposed branch: lp:~stefanor/ibid/logfile-visibility-567576-0.1
Merge into: lp:~ibid-core/ibid/old-release-0.1-1.6
Diff against target: 78 lines (+33/-3)
1 file modified
ibid/plugins/log.py (+33/-3)
To merge this branch: bzr merge lp:~stefanor/ibid/logfile-visibility-567576-0.1
Reviewer Review Type Date Requested Status
marcog (community) Approve
Jonathan Hitchcock Approve
Review via email: mp+36937@code.launchpad.net

Commit message

[SECURITY] Add a configuration glob-list of channels which should have public logs, rather than attempting to guess.

To post a comment you must log in.
Revision history for this message
Jonathan Hitchcock (vhata) wrote :

"Configuration value must contain a colon" is *NOT* the same as "Configuration value must be of the form 'source:channel'". The user needs to be told why it should contain a colon, or what the colon means, not just that it needs to be there.

User-Centric Design, people!

(Otherwise, it's good :) )

review: Needs Fixing
Revision history for this message
Stefano Rivera (stefanor) wrote :

r949

Revision history for this message
Jonathan Hitchcock (vhata) :
review: Approve
Revision history for this message
Max Rabkin (max-rabkin) wrote :

On that note, shouldn't we log misspelled source names?

Revision history for this message
Stefano Rivera (stefanor) wrote :

Done

Revision history for this message
Ibid Branch Auto-Lander (ibid-tarmac) wrote :

Voting does not meet specified criteria. Required: Approve >= 2, Disapprove == 0. Got: 1 Approve.

Revision history for this message
marcog (marco-gallotta) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ibid/plugins/log.py'
2--- ibid/plugins/log.py 2010-06-04 14:43:45 +0000
3+++ ibid/plugins/log.py 2010-10-01 14:23:35 +0000
4@@ -5,6 +5,8 @@
5
6 from datetime import datetime
7 from errno import EEXIST
8+import fnmatch
9+import logging
10 from os.path import dirname, join, expanduser
11 from os import chmod, makedirs
12 from threading import Lock
13@@ -14,9 +16,11 @@
14
15 import ibid
16 from ibid.plugins import Processor, handler
17-from ibid.config import Option, BoolOption, IntOption
18+from ibid.config import Option, BoolOption, IntOption, ListOption
19 from ibid.event import Event
20
21+log = logging.getLogger('plugins.log')
22+
23 class Log(Processor):
24
25 addressed = False
26@@ -41,6 +45,9 @@
27 rename_format = Option('rename_format', 'Format string for rename events',
28 u'%(timestamp)s %(sender_nick)s (%(sender_connection)s) has renamed to %(new_nick)s')
29
30+ public_logs = ListOption('public_logs',
31+ u'List of source:channel globs for channels which should have public logs',
32+ [])
33 public_mode = Option('public_mode',
34 u'File Permissions mode for public channels, in octal', '644')
35 private_mode = Option('private_mode',
36@@ -55,6 +62,21 @@
37 # Ensures that recently used FDs are still available in logs:
38 recent_logs = []
39
40+ def setup(self):
41+ sources = list(set(ibid.config.sources.keys())
42+ | set(ibid.sources.keys()))
43+ for glob in self.public_logs:
44+ if u':' not in glob:
45+ log.warning(u"public_logs configuration values must follow the "
46+ u"format source:channel. \"%s\" doesn't contain a "
47+ u"colon.", glob)
48+ continue
49+ source_glob = glob.split(u':', 1)[0]
50+ if not fnmatch.filter(sources, source_glob):
51+ log.warning(u'public_logs includes "%s", but there is no '
52+ u'configured source matching "%s"',
53+ glob, source_glob)
54+
55 def get_logfile(self, event):
56 self.lock.acquire()
57 try:
58@@ -84,10 +106,18 @@
59
60 log = open(filename, 'a')
61 self.logs[filename] = log
62- if event.get('public', True):
63- chmod(filename, int(self.public_mode, 8))
64+
65+ for glob in self.public_logs:
66+ if u':' not in glob:
67+ continue
68+ source_glob, channel_glob = glob.split(u':', 1)
69+ if (fnmatch.fnmatch(event.source, source_glob)
70+ and fnmatch.fnmatch(event.channel, channel_glob)):
71+ chmod(filename, int(self.public_mode, 8))
72+ break
73 else:
74 chmod(filename, int(self.private_mode, 8))
75+
76 if len(self.recent_logs) > self.fd_cache:
77 self.recent_logs.pop()
78 else:

Subscribers

People subscribed via source and target branches