Skip to content

Commit

Permalink
resource: ucmd-module: add KV_SUP_{RD,WR} to sid_ucmd_kv_flags_t
Browse files Browse the repository at this point in the history
Just like KV_SUB_{RD,WR}, but the other way round - make it
possible to define permissions for superior modules.
  • Loading branch information
prajnoha committed Aug 21, 2023
1 parent 70d50c8 commit 304a024
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/include/resource/ucmd-module.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,13 @@ typedef enum {

KV_FRG_RD = UINT64_C(0x0000000000000010), /* foreign modules can read */
KV_SUB_RD = UINT64_C(0x0000000000000020), /* subordinate modules can read */
KV_RD = UINT64_C(0x0000000000000030), /* all modules can read */
KV_SUP_RD = UINT64_C(0x0000000000000040), /* superior modules can read */
KV_RD = UINT64_C(0x0000000000000070), /* all modules can read */

KV_FRG_WR = UINT64_C(0x0000000000000040), /* foreign modules can write */
KV_SUB_WR = UINT64_C(0x0000000000000080), /* subordinate modules can write */
KV_WR = UINT64_C(0x00000000000000C0), /* all modules can write */
KV_FRG_WR = UINT64_C(0x0000000000000080), /* foreign modules can write */
KV_SUB_WR = UINT64_C(0x0000000000000100), /* subordinate modules can write */
KV_SUP_WR = UINT64_C(0x0000000000000200), /* superior modules can write */
KV_WR = UINT64_C(0x0000000000000380), /* all modules can write */

_KV_ENUM_SIZE = UINT64_C(0x7fffffffffffffff), /* used to force the enum to 64 bits */
} sid_ucmd_kv_flags_t;
Expand Down
31 changes: 31 additions & 0 deletions src/resource/ubridge.c
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ typedef enum {
MOD_NO_MATCH, /* modules do not match */
MOD_MATCH, /* modules do match (1:1) */
MOD_SUB_MATCH, /* modules do match (submod of a mod) */
MOD_SUP_MATCH, /* modules do match (supmod of a mod) */
} mod_match_t;

typedef enum {
Expand Down Expand Up @@ -832,6 +833,10 @@ static mod_match_t _mod_match(const char *mod1, const char *mod2)
else
/* no match */
return MOD_NO_MATCH;
} else if (i && mod1[i]) {
if (!strncmp(mod1 + i, MODULE_NAME_DELIM, sizeof(MODULE_NAME_DELIM) - 1))
/* match - mod2 is supermod of mod1 */
return MOD_SUP_MATCH;
}

/* no match */
Expand Down Expand Up @@ -892,6 +897,22 @@ static int _check_kv_wr_allowed(struct kv_update_arg *update_arg, const char *ke
}
}
break;
case MOD_SUP_MATCH:
if (old_flags & KV_SUP_WR)
r = 1;
else {
if (old_flags & KV_RS) {
reason = reason_reserved;
r = -EBUSY;
} else if (old_flags & KV_SUP_RD) {
reason = reason_readonly;
r = -EPERM;
} else {
reason = reason_private;
r = -EACCES;
}
}
break;
}

if (r < 0)
Expand Down Expand Up @@ -1298,6 +1319,9 @@ static int _check_global_kv_rs_for_wr(struct sid_ucmd_ctx *ucmd_ctx,
case MOD_SUB_MATCH:
r = VVALUE_FLAGS(vvalue) & KV_SUB_WR;
break;
case MOD_SUP_MATCH:
r = VVALUE_FLAGS(vvalue) & KV_SUP_WR;
break;
}

if (!r)
Expand Down Expand Up @@ -2223,6 +2247,10 @@ static const void *_cmd_get_key_spec_value(struct module *mod,
if (!(svalue->flags & KV_SUB_RD))
goto out;
break;
case MOD_SUP_MATCH:
if (!(svalue->flags & KV_SUP_RD))
goto out;
break;
}

if (flags)
Expand Down Expand Up @@ -4814,6 +4842,9 @@ static int _kv_cb_main_unset(struct kv_store_update_spec *spec)
case MOD_SUB_MATCH:
r = VVALUE_FLAGS(vvalue_old) & KV_SUB_WR;
break;
case MOD_SUP_MATCH:
r = VVALUE_FLAGS(vvalue_old) & KV_SUP_WR;
break;
}

if (!r) {
Expand Down

0 comments on commit 304a024

Please sign in to comment.