Skip to content

Commit

Permalink
trust: Forcibly mark "Default Trust" read-only
Browse files Browse the repository at this point in the history
The "Default Trust" token is typically mounted as $datadir, which is
considered as read-only on modern OSes.

Suggestd by Kai Engert in:
https://bugzilla.redhat.com/show_bug.cgi?id=1523630
  • Loading branch information
ueno committed Jan 19, 2018
1 parent 031d3c7 commit de847aa
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
12 changes: 8 additions & 4 deletions trust/module.c
Expand Up @@ -194,10 +194,11 @@ create_tokens_inlock (p11_array *tokens,
struct {
const char *prefix;
const char *label;
bool readonly;
} labels[] = {
{ "~/", "User Trust" },
{ DATA_DIR, "Default Trust" },
{ SYSCONFDIR, "System Trust" },
{ "~/", "User Trust", false },
{ DATA_DIR, "Default Trust", true },
{ SYSCONFDIR, "System Trust", false },
{ NULL },
};

Expand All @@ -206,6 +207,7 @@ create_tokens_inlock (p11_array *tokens,
CK_SLOT_ID slot;
const char *path;
const char *label;
bool readonly;
char *alloc;
char *remaining;
char *base;
Expand Down Expand Up @@ -233,12 +235,14 @@ create_tokens_inlock (p11_array *tokens,

label = NULL;
base = NULL;
readonly = false;

/* Claim the various labels based on prefix */
for (i = 0; label == NULL && labels[i].prefix != NULL; i++) {
if (strncmp (path, labels[i].prefix, strlen (labels[i].prefix)) == 0) {
label = labels[i].label;
labels[i].label = NULL;
readonly = labels[i].readonly;
}
}

Expand All @@ -248,7 +252,7 @@ create_tokens_inlock (p11_array *tokens,
return_val_if_fail (base != NULL, false);
}

token = p11_token_new (slot, path, label);
token = p11_token_new (slot, path, label, readonly);
return_val_if_fail (token != NULL, false);

if (!p11_array_push (tokens, token))
Expand Down
9 changes: 8 additions & 1 deletion trust/token.c
Expand Up @@ -817,7 +817,8 @@ p11_token_free (p11_token *token)
p11_token *
p11_token_new (CK_SLOT_ID slot,
const char *path,
const char *label)
const char *label,
bool readonly)
{
p11_token *token;

Expand Down Expand Up @@ -859,6 +860,12 @@ p11_token_new (CK_SLOT_ID slot,

token->slot = slot;

if (readonly) {
token->checked_path = true;
token->make_directory = false;
token->is_writable = false;
}

load_builtin_objects (token);

p11_debug ("token: %s: %s", token->label, token->path);
Expand Down
3 changes: 2 additions & 1 deletion trust/token.h
Expand Up @@ -44,7 +44,8 @@ typedef struct _p11_token p11_token;

p11_token * p11_token_new (CK_SLOT_ID slot,
const char *path,
const char *label);
const char *label,
bool readonly);

void p11_token_free (p11_token *token);

Expand Down

0 comments on commit de847aa

Please sign in to comment.