Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into nocheck
Browse files Browse the repository at this point in the history
  • Loading branch information
zyga committed Jan 12, 2017
2 parents 60d7846 + 8c09891 commit 836e325
Show file tree
Hide file tree
Showing 110 changed files with 3,208 additions and 758 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ cmd/snap-confine/decode-mount-opts
*~
.*.swp
*.o
*.a

# manual pages
cmd/snap-confine/manpages/*.[1-9]
Expand Down
18 changes: 3 additions & 15 deletions asserts/snapasserts/snapasserts.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,22 +108,10 @@ func DeriveSideInfo(snapPath string, db asserts.RODatabase) (*snap.SideInfo, err

name := snapDecl.SnapName()

// TODO: once we are fully migrated to assertions this can
// be done dynamically later instead of statically here
a, err = db.Find(asserts.AccountType, map[string]string{
"account-id": snapRev.DeveloperID(),
})
if err != nil {
return nil, fmt.Errorf("internal error: cannot find developer account for snap %q (%q): %s", name, snapPath, snapRev.DeveloperID())
}
devAcct := a.(*asserts.Account)

return &snap.SideInfo{
RealName: name,
SnapID: snapID,
Revision: snap.R(snapRev.SnapRevision()),
DeveloperID: snapRev.DeveloperID(),
Developer: devAcct.Username(),
RealName: name,
SnapID: snapID,
Revision: snap.R(snapRev.SnapRevision()),
}, nil
}

Expand Down
10 changes: 4 additions & 6 deletions asserts/snapasserts/snapasserts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,12 +234,10 @@ func (s *snapassertsSuite) TestDeriveSideInfoHappy(c *C) {
si, err := snapasserts.DeriveSideInfo(snapPath, s.localDB)
c.Assert(err, IsNil)
c.Check(si, DeepEquals, &snap.SideInfo{
RealName: "foo",
SnapID: "snap-id-1",
Revision: snap.R(42),
Channel: "",
DeveloperID: s.dev1Acct.AccountID(),
Developer: "developer1",
RealName: "foo",
SnapID: "snap-id-1",
Revision: snap.R(42),
Channel: "",
})
}

Expand Down
12 changes: 12 additions & 0 deletions client/aliases.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,15 @@ func (client *Client) ResetAliases(snapName string, aliases []string) (changeID
Aliases: aliases,
})
}

// AliasStatus represents the status of an alias.
type AliasStatus struct {
App string `json:"app,omitempty"`
Status string `json:"status,omitempty"`
}

// Aliases returns a map snap -> alias -> AliasStatus for all snaps and aliases in the system.
func (client *Client) Aliases() (allStatuses map[string]map[string]AliasStatus, err error) {
_, err = client.doSync("GET", "/v2/aliases", nil, nil, nil, &allStatuses)
return
}
37 changes: 37 additions & 0 deletions client/aliases_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (
"encoding/json"

"gopkg.in/check.v1"

"github.com/snapcore/snapd/client"
)

func (cs *clientSuite) TestClientAliasCallsEndpoint(c *check.C) {
Expand Down Expand Up @@ -105,3 +107,38 @@ func (cs *clientSuite) TestClientResetAliases(c *check.C) {
"aliases": []interface{}{"alias1", "alias2"},
})
}

func (cs *clientSuite) TestClientAliasesCallsEndpoint(c *check.C) {
_, _ = cs.cli.Aliases()
c.Check(cs.req.Method, check.Equals, "GET")
c.Check(cs.req.URL.Path, check.Equals, "/v2/aliases")
}

func (cs *clientSuite) TestClientAliases(c *check.C) {
cs.rsp = `{
"type": "sync",
"result": {
"foo": {
"foo0": {"app": "foo", "status": "auto"},
"foo_reset": {"app": "foo.reset"}
},
"bar": {
"bar_dump": {"app": "bar.dump", "status": "enabled"},
"bar_dump.1": {"status": "disabled"}
}
}
}`
allStatuses, err := cs.cli.Aliases()
c.Assert(err, check.IsNil)
c.Check(allStatuses, check.DeepEquals, map[string]map[string]client.AliasStatus{
"foo": {
"foo0": {App: "foo", Status: "auto"},
"foo_reset": {App: "foo.reset", Status: ""},
},
"bar": {
"bar_dump": {App: "bar.dump", Status: "enabled"},
"bar_dump.1": {App: "", Status: "disabled"},
},
})
}
43 changes: 22 additions & 21 deletions client/packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,28 @@ import (

// Snap holds the data for a snap as obtained from snapd.
type Snap struct {
ID string `json:"id"`
Summary string `json:"summary"`
Description string `json:"description"`
DownloadSize int64 `json:"download-size"`
Icon string `json:"icon"`
InstalledSize int64 `json:"installed-size"`
InstallDate time.Time `json:"install-date"`
Name string `json:"name"`
Developer string `json:"developer"`
Status string `json:"status"`
Type string `json:"type"`
Version string `json:"version"`
Channel string `json:"channel"`
Revision snap.Revision `json:"revision"`
Confinement string `json:"confinement"`
Private bool `json:"private"`
DevMode bool `json:"devmode"`
JailMode bool `json:"jailmode"`
TryMode bool `json:"trymode"`
Apps []AppInfo `json:"apps"`
Broken string `json:"broken"`
ID string `json:"id"`
Summary string `json:"summary"`
Description string `json:"description"`
DownloadSize int64 `json:"download-size"`
Icon string `json:"icon"`
InstalledSize int64 `json:"installed-size"`
InstallDate time.Time `json:"install-date"`
Name string `json:"name"`
Developer string `json:"developer"`
Status string `json:"status"`
Type string `json:"type"`
Version string `json:"version"`
Channel string `json:"channel"`
TrackingChannel string `json:"tracking-channel"`
Revision snap.Revision `json:"revision"`
Confinement string `json:"confinement"`
Private bool `json:"private"`
DevMode bool `json:"devmode"`
JailMode bool `json:"jailmode"`
TryMode bool `json:"trymode"`
Apps []AppInfo `json:"apps"`
Broken string `json:"broken"`

Prices map[string]float64 `json:"prices"`
Screenshots []Screenshot `json:"screenshots"`
Expand Down
4 changes: 4 additions & 0 deletions cmd/configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ AC_PROG_CC_C99
AC_PROG_CPP
AC_PROG_INSTALL
AC_PROG_MAKE_SET
AC_PROG_RANLIB

AC_LANG([C])
# Checks for libraries.
Expand Down Expand Up @@ -161,5 +162,8 @@ AS_IF([test "x$enable_caps_over_setuid" = "xyes"], [
AC_DEFINE([CAPS_OVER_SETUID], [1],
[Use capabilities rather than setuid bit])])

AC_PATH_PROG([HAVE_RST2MAN],[rst2man])
AS_IF([test "x$HAVE_RST2MAN" = "x"], [AC_MSG_ERROR(["cannot find the rst2man tool, install python-docutils or similar"])])

AC_CONFIG_FILES([Makefile snap-confine/Makefile snap-confine/tests/Makefile snap-confine/manpages/Makefile])
AC_OUTPUT
27 changes: 14 additions & 13 deletions cmd/snap-confine/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
SUBDIRS = manpages tests

noinst_LIBRARIES = libsnap-confine-private.a

libsnap_confine_private_a_SOURCES = \
error.h \
error.c \
utils.h \
utils.c \
secure-getenv.c \
secure-getenv.h

libexec_PROGRAMS = snap-confine snap-discard-ns
noinst_PROGRAMS = decode-mount-opts
if WITH_UNIT_TESTS
Expand All @@ -15,18 +26,14 @@ snap_discard_ns_SOURCES = \
ns-support.h \
apparmor-support.c \
apparmor-support.h \
utils.c \
utils.h \
secure-getenv.c \
secure-getenv.h \
cleanup-funcs.c \
cleanup-funcs.h \
mountinfo.c \
mountinfo.h \
snap-discard-ns.c
snap_discard_ns_CFLAGS = -Wall -Werror $(AM_CFLAGS)
snap_discard_ns_LDFLAGS = $(AM_LDFLAGS)
snap_discard_ns_LDADD =
snap_discard_ns_LDADD = libsnap-confine-private.a
snap_discard_ns_CFLAGS += $(SECCOMP_CFLAGS)
snap_discard_ns_LDADD += $(SECCOMP_LIBS)

Expand All @@ -37,10 +44,6 @@ endif

snap_confine_SOURCES = \
snap-confine.c \
utils.c \
utils.h \
secure-getenv.c \
secure-getenv.h \
snap.c \
snap.h \
classic.c \
Expand All @@ -64,13 +67,11 @@ snap_confine_SOURCES = \
ns-support.c \
ns-support.h \
apparmor-support.c \
apparmor-support.h \
error.c \
error.h
apparmor-support.h

snap_confine_CFLAGS = -Wall -Werror $(AM_CFLAGS)
snap_confine_LDFLAGS = $(AM_LDFLAGS)
snap_confine_LDADD =
snap_confine_LDADD = libsnap-confine-private.a
snap_confine_CFLAGS += $(LIBUDEV_CFLAGS)
snap_confine_LDADD += $(LIBUDEV_LIBS)

Expand Down
33 changes: 14 additions & 19 deletions cmd/snap-confine/seccomp-support.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2015 Canonical Ltd
* Copyright (C) 2015-2017 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
Expand Down Expand Up @@ -46,9 +46,6 @@
#define SC_ARGS_MAXLENGTH 6
#define SC_MAX_LINE_LENGTH 82 // 80 + '\n' + '\0'

char *filter_profile_dir = "/var/lib/snapd/seccomp/profiles/";
struct hsearch_data sc_map_htab;

enum parse_ret {
PARSE_INVALID_SYSCALL = -2,
PARSE_ERROR = -1,
Expand Down Expand Up @@ -83,7 +80,9 @@ struct sc_map_list {
int count;
};

struct sc_map_list *sc_map_entries = NULL;
static char *filter_profile_dir = "/var/lib/snapd/seccomp/profiles/";
static struct hsearch_data sc_map_htab;
static struct sc_map_list sc_map_entries;

/*
* Setup an hsearch map to map strings in the policy (eg, AF_UNIX) to
Expand Down Expand Up @@ -144,26 +143,23 @@ static void sc_map_add_kvp(const char *key, scmp_datum_t value)
node->ep = NULL;
node->next = NULL;

if (sc_map_entries->list == NULL) {
sc_map_entries->count = 1;
sc_map_entries->list = node;
if (sc_map_entries.list == NULL) {
sc_map_entries.count = 1;
sc_map_entries.list = node;
} else {
struct sc_map_entry *p = sc_map_entries->list;
struct sc_map_entry *p = sc_map_entries.list;
while (p->next != NULL)
p = p->next;
p->next = node;
sc_map_entries->count++;
sc_map_entries.count++;
}
}

static void sc_map_init()
{
// initialize the map linked list
sc_map_entries = malloc(sizeof(*sc_map_entries));
if (sc_map_entries == NULL)
die("Out of memory creating sc_map_entries");
sc_map_entries->list = NULL;
sc_map_entries->count = 0;
sc_map_entries.list = NULL;
sc_map_entries.count = 0;

// build up the map linked list

Expand Down Expand Up @@ -289,11 +285,11 @@ static void sc_map_init()

// initialize the htab for our map
memset((void *)&sc_map_htab, 0, sizeof(sc_map_htab));
if (hcreate_r(sc_map_entries->count, &sc_map_htab) == 0)
if (hcreate_r(sc_map_entries.count, &sc_map_htab) == 0)
die("could not create map");

// add elements from linked list to map
struct sc_map_entry *p = sc_map_entries->list;
struct sc_map_entry *p = sc_map_entries.list;
while (p != NULL) {
errno = 0;
if (hsearch_r(*p->e, ENTER, &p->ep, &sc_map_htab) == 0)
Expand All @@ -311,7 +307,7 @@ static void sc_map_destroy()
// this frees all of the nodes' ep so we don't have to below
hdestroy_r(&sc_map_htab);

struct sc_map_entry *next = sc_map_entries->list;
struct sc_map_entry *next = sc_map_entries.list;
struct sc_map_entry *p = NULL;
while (next != NULL) {
p = next;
Expand All @@ -321,7 +317,6 @@ static void sc_map_destroy()
free(p->e);
free(p);
}
free(sc_map_entries);
}

/* Caller must check if errno != 0 */
Expand Down
2 changes: 1 addition & 1 deletion cmd/snap-confine/seccomp-support.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2015 Canonical Ltd
* Copyright (C) 2015-2017 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
Expand Down
Loading

0 comments on commit 836e325

Please sign in to comment.