Changeset 453:3cb368c406cb
- Timestamp:
- 08/01/08 15:56:55
(5 months ago)
- Author:
- "Brian Warner <warner@lothar.com>"
- branch:
- default
- Message:
gatherer: use getRemoteTubID instead of sanitizing the received tubid string
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r452 |
r453 |
|
| 5 | 5 | not sure this is a good idea, but it fixes the immediate problem |
|---|
| 6 | 6 | I'm dealing with. |
|---|
| | 7 | * foolscap/logging/gatherer.py: use "tubid_s" instead of "nodeid_s" |
|---|
| | 8 | (IncidentGathererService.remote_logport): use getRemoteTubID() |
|---|
| | 9 | instead of trying to sanitize the tubid we receive, since we |
|---|
| | 10 | use it as a directory name |
|---|
| 7 | 11 | |
|---|
| 8 | 12 | * foolscap/test/test_logging.py (IncidentGatherer.test_emit): add |
|---|
| r450 |
r453 |
|
| 294 | 294 | implements(RILogObserver) |
|---|
| 295 | 295 | |
|---|
| 296 | | def __init__(self, basedir, nodeid_s, gatherer, publisher, stdout): |
|---|
| | 296 | def __init__(self, basedir, tubid_s, gatherer, publisher, stdout): |
|---|
| 297 | 297 | if not os.path.isdir(basedir): |
|---|
| 298 | 298 | os.makedirs(basedir) |
|---|
| 299 | 299 | self.basedir = filepath.FilePath(basedir) |
|---|
| 300 | | self.nodeid_s = nodeid_s # printable string |
|---|
| | 300 | self.tubid_s = tubid_s # printable string |
|---|
| 301 | 301 | self.gatherer = gatherer |
|---|
| 302 | 302 | self.publisher = publisher |
|---|
| … | … | |
| 314 | 314 | pass |
|---|
| 315 | 315 | print >>self.stdout, "connected to %s, last known incident is %s" \ |
|---|
| 316 | | % (self.nodeid_s, latest) |
|---|
| | 316 | % (self.tubid_s, latest) |
|---|
| 317 | 317 | # now subscribe to everything since then |
|---|
| 318 | 318 | d = self.publisher.callRemote("subscribe_to_incidents", self, |
|---|
| … | … | |
| 339 | 339 | # we need to record the relative pathname of the savefile, for use by |
|---|
| 340 | 340 | # the classifiers (they write it into their output files) |
|---|
| 341 | | rel_fn = os.path.join("incidents", self.nodeid_s, name) + ".flog.bz2" |
|---|
| | 341 | rel_fn = os.path.join("incidents", self.tubid_s, name) + ".flog.bz2" |
|---|
| 342 | 342 | self.save_incident(abs_fn, incident) |
|---|
| 343 | 343 | self.update_latest(name) |
|---|
| 344 | | self.gatherer.new_incident(abs_fn, rel_fn, self.nodeid_s, incident) |
|---|
| | 344 | self.gatherer.new_incident(abs_fn, rel_fn, self.tubid_s, incident) |
|---|
| 345 | 345 | |
|---|
| 346 | 346 | def save_incident(self, filename, incident): |
|---|
| … | … | |
| 351 | 351 | pickle.dump(h, f) |
|---|
| 352 | 352 | for e in events: |
|---|
| 353 | | wrapper = {"from": self.nodeid_s, |
|---|
| | 353 | wrapper = {"from": self.tubid_s, |
|---|
| 354 | 354 | "rx_time": now, |
|---|
| 355 | 355 | "d": e} |
|---|
| … | … | |
| 417 | 417 | print >>stdout, "No classified/ directory: reclassifying stored incidents" |
|---|
| 418 | 418 | # now classify all stored incidents |
|---|
| 419 | | for nodeid_s in os.listdir(indir): |
|---|
| 420 | | nodedir = os.path.join(indir, nodeid_s) |
|---|
| | 419 | for tubid_s in os.listdir(indir): |
|---|
| | 420 | nodedir = os.path.join(indir, tubid_s) |
|---|
| 421 | 421 | for fn in os.listdir(nodedir): |
|---|
| 422 | 422 | if fn.startswith("incident-"): |
|---|
| 423 | 423 | abs_fn = os.path.join(nodedir, fn) |
|---|
| 424 | 424 | incident = self.load_incident(abs_fn) |
|---|
| 425 | | rel_fn = os.path.join("incidents", nodeid_s, fn) |
|---|
| 426 | | self.classify_incident(rel_fn, nodeid_s, incident) |
|---|
| | 425 | rel_fn = os.path.join("incidents", tubid_s, fn) |
|---|
| | 426 | self.classify_incident(rel_fn, tubid_s, incident) |
|---|
| 427 | 427 | |
|---|
| 428 | 428 | def load_incident(self, abs_fn): |
|---|
| … | … | |
| 441 | 441 | |
|---|
| 442 | 442 | def remote_logport(self, nodeid, publisher): |
|---|
| 443 | | # nodeid is actually a printable string |
|---|
| 444 | | tubid_s = nodeid |
|---|
| 445 | | if not base32.is_base32(tubid_s): |
|---|
| 446 | | # we must check it to exclude .. and / and other nasties |
|---|
| 447 | | raise BadTubID("%s is not a valid base32-encoded Tub ID" % tubid_s) |
|---|
| | 443 | # we ignore nodeid (which is a printable string), and get the tubid |
|---|
| | 444 | # (or its <unauth> name) from the publisher remoteReference. |
|---|
| | 445 | # getRemoteTubID() protects us from .. and / and other nasties. |
|---|
| | 446 | tubid_s = publisher.getRemoteTubID() |
|---|
| 448 | 447 | basedir = os.path.join(self.basedir, "incidents", tubid_s) |
|---|
| 449 | 448 | stdout = self.stdout or sys.stdout |
|---|
| … | … | |
| 453 | 452 | return d # mostly for testing |
|---|
| 454 | 453 | |
|---|
| 455 | | def new_incident(self, abs_fn, rel_fn, nodeid_s, incident): |
|---|
| | 454 | def new_incident(self, abs_fn, rel_fn, tubid_s, incident): |
|---|
| 456 | 455 | stdout = self.stdout or sys.stdout |
|---|
| 457 | 456 | print >>stdout, "NEW INCIDENT", rel_fn |
|---|
| 458 | | self.classify_incident(rel_fn, nodeid_s, incident) |
|---|
| 459 | | |
|---|
| 460 | | def classify_incident(self, rel_fn, nodeid_s, incident): |
|---|
| | 457 | self.classify_incident(rel_fn, tubid_s, incident) |
|---|
| | 458 | |
|---|
| | 459 | def classify_incident(self, rel_fn, tubid_s, incident): |
|---|
| 461 | 460 | categories = set() |
|---|
| 462 | 461 | for f in self.classifiers: |
|---|
| 463 | | c = f(nodeid_s, incident) |
|---|
| | 462 | c = f(tubid_s, incident) |
|---|
| 464 | 463 | if c: # allow the classifier to return None, or [], or ["foo"] |
|---|
| 465 | 464 | if isinstance(c, str): |
|---|