From b2f66cfb605d41e6a2d0895d4dcb3c716b5df351 Mon Sep 17 00:00:00 2001 From: Jakob Borg Date: Fri, 6 Jun 2014 21:48:29 +0200 Subject: [PATCH] Reject index for existing repo from unshared node (fixes #342) --- model/model.go | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/model/model.go b/model/model.go index e4d106524..0861ea602 100644 --- a/model/model.go +++ b/model/model.go @@ -260,6 +260,11 @@ func (m *Model) Index(nodeID string, repo string, fs []protocol.FileInfo) { l.Debugf("IDX(in): %s %q: %d files", nodeID, repo, len(fs)) } + if !m.repoSharedWith(repo, nodeID) { + l.Warnf("Unexpected repository ID %q sent from node %q; ensure that the repository exists and that this node is selected under \"Share With\" in the repository configuration.", repo, nodeID) + return + } + var files = make([]scanner.File, len(fs)) for i := range fs { f := fs[i] @@ -279,7 +284,7 @@ func (m *Model) Index(nodeID string, repo string, fs []protocol.FileInfo) { if r, ok := m.repoFiles[repo]; ok { r.Replace(id, files) } else { - l.Warnf("Unexpected repository ID %q sent from node %q; ensure that the repository exists and that this node is selected under \"Share With\" in the repository configuration.", repo, nodeID) + l.Fatalf("Index for nonexistant repo %q", repo) } m.rmut.RUnlock() } @@ -291,6 +296,11 @@ func (m *Model) IndexUpdate(nodeID string, repo string, fs []protocol.FileInfo) l.Debugf("IDXUP(in): %s / %q: %d files", nodeID, repo, len(fs)) } + if !m.repoSharedWith(repo, nodeID) { + l.Warnf("Unexpected repository ID %q sent from node %q; ensure that the repository exists and that this node is selected under \"Share With\" in the repository configuration.", repo, nodeID) + return + } + var files = make([]scanner.File, len(fs)) for i := range fs { f := fs[i] @@ -310,11 +320,22 @@ func (m *Model) IndexUpdate(nodeID string, repo string, fs []protocol.FileInfo) if r, ok := m.repoFiles[repo]; ok { r.Update(id, files) } else { - l.Warnf("Index update from %s for nonexistant repo %q; dropping", nodeID, repo) + l.Fatalf("IndexUpdate for nonexistant repo %q", repo) } m.rmut.RUnlock() } +func (m *Model) repoSharedWith(repo, nodeID string) bool { + m.rmut.RLock() + defer m.rmut.RUnlock() + for _, nrepo := range m.nodeRepos[nodeID] { + if nrepo == repo { + return true + } + } + return false +} + func (m *Model) ClusterConfig(nodeID string, config protocol.ClusterConfigMessage) { compErr := compareClusterConfig(m.clusterConfig(nodeID), config) if debug {