Skip to content
This repository has been archived by the owner on Nov 8, 2022. It is now read-only.

Commit

Permalink
Fix for issue #954
Browse files Browse the repository at this point in the history
  • Loading branch information
obourdon committed Jun 2, 2016
1 parent 4d7d4ca commit 99636c8
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 18 deletions.
1 change: 1 addition & 0 deletions control/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ func (p *pluginControl) returnPluginDetails(rp *core.RequestedPlugin) (*pluginDe
details.Path = rp.Path()
details.CheckSum = rp.CheckSum()
details.Signature = rp.Signature()
details.IsAutoLoaded = rp.AutoLoaded()

if filepath.Ext(rp.Path()) == ".aci" {
f, err := os.Open(rp.Path())
Expand Down
24 changes: 14 additions & 10 deletions control/plugin_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,15 @@ func (l *loadedPlugins) findLatest(typeName, name string) (*loadedPlugin, error)

// the struct representing a plugin that is loaded into snap
type pluginDetails struct {
CheckSum [sha256.Size]byte
Exec string
ExecPath string
IsPackage bool
Manifest *schema.ImageManifest
Path string
Signed bool
Signature []byte
CheckSum [sha256.Size]byte
Exec string
ExecPath string
IsPackage bool
IsAutoLoaded bool
Manifest *schema.ImageManifest
Path string
Signed bool
Signature []byte
}

type loadedPlugin struct {
Expand Down Expand Up @@ -484,8 +485,11 @@ func (p *pluginManager) UnloadPlugin(pl core.Plugin) (*loadedPlugin, serror.Snap
return nil, se
}

// If the plugin was loaded from os.TempDir() clean up
if strings.Contains(plugin.Details.Path, os.TempDir()) {
// If the plugin has been uploaded via REST API
// aka, was not auto loaded from auto_discover_path
// nor loaded from tests
// then do clean up
if !plugin.Details.IsAutoLoaded {
pmLogger.WithFields(log.Fields{
"plugin-type": plugin.TypeName(),
"plugin-name": plugin.Name(),
Expand Down
7 changes: 4 additions & 3 deletions control/plugin_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,10 @@ func loadPlugin(p *pluginManager, path string) (*loadedPlugin, serror.SnapError)
var e serror.SnapError
var lp *loadedPlugin
details := &pluginDetails{
Path: path,
ExecPath: filepath.Dir(path),
Exec: filepath.Base(path),
Path: path,
ExecPath: filepath.Dir(path),
Exec: filepath.Base(path),
IsAutoLoaded: true,
}
for i := 0; i < 3; i++ {
lp, e = p.LoadPlugin(details, nil)
Expand Down
20 changes: 15 additions & 5 deletions core/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,17 @@ type SubscribedPlugin interface {
}

type RequestedPlugin struct {
path string
checkSum [sha256.Size]byte
signature []byte
path string
checkSum [sha256.Size]byte
signature []byte
autoLoaded bool
}

func NewRequestedPlugin(path string) (*RequestedPlugin, error) {
rp := &RequestedPlugin{
path: path,
signature: nil,
path: path,
signature: nil,
autoLoaded: true,
}
err := rp.generateCheckSum()
if err != nil {
Expand All @@ -123,6 +125,10 @@ func (p *RequestedPlugin) Signature() []byte {
return p.signature
}

func (p *RequestedPlugin) AutoLoaded() bool {
return p.autoLoaded
}

func (p *RequestedPlugin) SetPath(path string) {
p.path = path
}
Expand All @@ -131,6 +137,10 @@ func (p *RequestedPlugin) SetSignature(data []byte) {
p.signature = data
}

func (p *RequestedPlugin) SetAutoLoaded(isAutoLoaded bool) {
p.autoLoaded = isAutoLoaded
}

func (p *RequestedPlugin) generateCheckSum() error {
var b []byte
var err error
Expand Down
1 change: 1 addition & 0 deletions mgmt/rest/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ func (s *Server) loadPlugin(w http.ResponseWriter, r *http.Request, _ httprouter
respond(500, rbody.FromError(err), w)
return
}
rp.SetAutoLoaded(false)
// Sanity check, verify the checkSum on the file sent is the same
// as after it is written to disk.
if rp.CheckSum() != checkSum {
Expand Down

0 comments on commit 99636c8

Please sign in to comment.