~snappy-dev/snappy-hub/snappy-debug.15.04

« back to all changes in this revision

Viewing changes to bin/snappy-security-scanlog

  • Committer: Jamie Strandboge
  • Date: 2017-05-17 22:06:31 UTC
  • Revision ID: jamie@ubuntu.com-20170517220631-qbm4d1p8qmsxoxvx
start fixes for journald on trusty

Show diffs side-by-side

added added

removed removed

Lines of Context:
170
170
 
171
171
    def scan_log(self, logs, snap_name, follow, from_end):
172
172
        def _format_journald_entry(entry):
173
 
            tm = datetime.strftime(entry['_SOURCE_REALTIME_TIMESTAMP'],
 
173
            tm = datetime.strftime(entry['__REALTIME_TIMESTAMP'],
174
174
                                   "%b %d %H:%M:%S")
175
 
            tp = 'type=%s' % entry['_AUDIT_TYPE']
176
 
 
177
 
            # 'localhost kernel: audit: ' is needed for parsing and so is
178
 
            # 'audit(0.0:0):' (which is discarded)
179
 
            prefix = '%s localhost kernel: audit: %s audit(0.0:0): ' % (tm, tp)
180
 
 
181
 
            pat = re.compile(r'^(AVC|SECCOMP) ')
182
 
            s = pat.sub('%s' % prefix, entry['MESSAGE'])
 
175
 
 
176
            if entry['_TRANSPORT'] == "kernel":  # old style
 
177
                prefix = '%s localhost kernel:' % tm
 
178
                s = "%s %s" % (prefix, entry['MESSAGE'])
 
179
            else:
 
180
                tp = 'type=%s' % entry['_AUDIT_TYPE']
 
181
 
 
182
                # 'localhost kernel: audit: ' is needed for parsing and so is
 
183
                # 'audit(0.0:0):' (which is discarded)
 
184
                prefix = '%s localhost kernel: audit: %s audit(0.0:0): ' % (tm, tp)
 
185
 
 
186
                pat = re.compile(r'^(AVC|SECCOMP) ')
 
187
                s = pat.sub('%s' % prefix, entry['MESSAGE'])
 
188
 
183
189
 
184
190
            return s
185
191
 
226
232
                ":log-observe' as root"
227
233
            raise ScanLogsException(m)
228
234
 
229
 
        print("Reading from %s" % logs)
230
 
 
231
235
        if logs == "journald":
 
236
            print("Reading from %s" % logs)
 
237
 
232
238
            # FIXME: check if have permissions
233
239
            j = journal.Reader()
234
240
 
239
245
            # filter by seccomp (1326) or apparmor (1400) audit messages
240
246
            j.add_match(_TRANSPORT=u'audit', _AUDIT_TYPE=1326)
241
247
            j.add_match(_TRANSPORT=u'audit', _AUDIT_TYPE=1400)
 
248
            j.add_match(_TRANSPORT=u'kernel')
242
249
 
243
250
            if from_end:
244
251
                # move to end of journal