Skip to content

Commit

Permalink
cmd/snap-confine: switch snap-confine-invocation.[ch] to clang-format
Browse files Browse the repository at this point in the history
The file is brand new and we can still switch without killing relevant
history. This mainly gives us less strict line length and less odd
line breaks.

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
  • Loading branch information
zyga committed Mar 11, 2019
1 parent 25e5a6b commit 36695c3
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 51 deletions.
2 changes: 2 additions & 0 deletions cmd/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ new_format = \
libsnap-confine-private/cgroup-support.h \
snap-confine/seccomp-support-ext.c \
snap-confine/seccomp-support-ext.h \
snap-confine/snap-confine-invocation.c \
snap-confine/snap-confine-invocation.h \
snap-discard-ns/snap-discard-ns.c
.PHONY: fmt
fmt:: $(filter $(addprefix %,$(new_format)),$(foreach dir,$(subdirs),$(wildcard $(srcdir)/$(dir)/*.[ch])))
Expand Down
79 changes: 38 additions & 41 deletions cmd/snap-confine/snap-confine-invocation.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,50 +22,47 @@
#include "../libsnap-confine-private/snap.h"
#include "../libsnap-confine-private/utils.h"

void sc_init_invocation(sc_invocation * inv, const struct sc_args *args,
const char *snap_instance)
{
/* Snap instance name is conveyed via untrusted environment. It may be
* unset (typically when experimenting with snap-confine by hand). It
* must also be a valid snap instance name. */
if (snap_instance == NULL) {
die("SNAP_INSTANCE_NAME is not set");
}
sc_instance_name_validate(snap_instance, NULL);
void sc_init_invocation(sc_invocation *inv, const struct sc_args *args, const char *snap_instance) {
/* Snap instance name is conveyed via untrusted environment. It may be
* unset (typically when experimenting with snap-confine by hand). It
* must also be a valid snap instance name. */
if (snap_instance == NULL) {
die("SNAP_INSTANCE_NAME is not set");
}
sc_instance_name_validate(snap_instance, NULL);

/* The security tag is conveyed via untrusted command line. It must be
* in agreement with snap instance name and must be a valid security
* tag. */
const char *security_tag = sc_args_security_tag(args);
if (!verify_security_tag(security_tag, snap_instance)) {
die("security tag %s not allowed", security_tag);
}
/* The security tag is conveyed via untrusted command line. It must be
* in agreement with snap instance name and must be a valid security
* tag. */
const char *security_tag = sc_args_security_tag(args);
if (!verify_security_tag(security_tag, snap_instance)) {
die("security tag %s not allowed", security_tag);
}

/* The base snap name is conveyed via untrusted, optional, command line
* argument. It may be omitted where it implies the "core" snap is the
* base. */
const char *base_snap_name = sc_args_base_snap(args) ? : "core";
sc_snap_name_validate(base_snap_name, NULL);
/* The base snap name is conveyed via untrusted, optional, command line
* argument. It may be omitted where it implies the "core" snap is the
* base. */
const char *base_snap_name = sc_args_base_snap(args) ?: "core";
sc_snap_name_validate(base_snap_name, NULL);

/* The executable is conveyed via untrusted command lne. It must be set
* but cannot be validated further than that at this time. It might be
* arguable to validate it to be snap-exec in one of the well-known
* locations or one of the special-cases like strace / gdb but this is
* not done at this time. */
const char *executable = sc_args_executable(args);
/* TODO: validate NULL */
/* The executable is conveyed via untrusted command lne. It must be set
* but cannot be validated further than that at this time. It might be
* arguable to validate it to be snap-exec in one of the well-known
* locations or one of the special-cases like strace / gdb but this is
* not done at this time. */
const char *executable = sc_args_executable(args);
/* TODO: validate NULL */

/* Invocation helps to pass relevant data to various parts of snap-confine. */
memset(inv, 0, sizeof *inv);
inv->base_snap_name = base_snap_name;
inv->executable = executable;
inv->security_tag = security_tag;
inv->snap_instance = snap_instance;
inv->classic_confinement = sc_args_is_classic_confinement(args);
/* Invocation helps to pass relevant data to various parts of snap-confine. */
memset(inv, 0, sizeof *inv);
inv->base_snap_name = base_snap_name;
inv->executable = executable;
inv->security_tag = security_tag;
inv->snap_instance = snap_instance;
inv->classic_confinement = sc_args_is_classic_confinement(args);

debug("security tag: %s", inv->security_tag);
debug("executable: %s", inv->executable);
debug("confinement: %s",
inv->classic_confinement ? "classic" : "non-classic");
debug("base snap: %s", inv->base_snap_name);
debug("security tag: %s", inv->security_tag);
debug("executable: %s", inv->executable);
debug("confinement: %s", inv->classic_confinement ? "classic" : "non-classic");
debug("base snap: %s", inv->base_snap_name);
}
19 changes: 9 additions & 10 deletions cmd/snap-confine/snap-confine-invocation.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@
* All of the pointer fields have the life-cycle bound to the main process.
**/
typedef struct sc_invocation {
/* Things declared by the system. */
const char *base_snap_name;
const char *executable;
const char *security_tag;
const char *snap_instance;
bool classic_confinement;
/* Things derived at runtime. */
bool is_normal_mode;
/* Things declared by the system. */
const char *base_snap_name;
const char *executable;
const char *security_tag;
const char *snap_instance;
bool classic_confinement;
/* Things derived at runtime. */
bool is_normal_mode;
} sc_invocation;

/**
Expand All @@ -45,7 +45,6 @@ typedef struct sc_invocation {
* environment value (SNAP_INSTANCE_NAME). All input is untrustee and is
* validated internally.
**/
void sc_init_invocation(sc_invocation * inv, const struct sc_args *args,
const char *snap_instance);
void sc_init_invocation(sc_invocation *inv, const struct sc_args *args, const char *snap_instance);

#endif

0 comments on commit 36695c3

Please sign in to comment.