Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
ACL: allow multiple channel ranges per user
  • Loading branch information
perexg committed Jun 1, 2015
1 parent 145ca52 commit d8c3296
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 15 deletions.
31 changes: 21 additions & 10 deletions src/access.c
Expand Up @@ -200,6 +200,14 @@ access_copy(access_t *src)
dst->aa_profiles = htsmsg_copy(src->aa_profiles);
if (src->aa_dvrcfgs)
dst->aa_dvrcfgs = htsmsg_copy(src->aa_dvrcfgs);
if (src->aa_chrange) {
size_t l = src->aa_chrange_count * sizeof(uint64_t);
dst->aa_chrange = malloc(l);
if (dst->aa_chrange == NULL)
dst->aa_chrange_count = 0;
else
memcpy(dst->aa_chrange, src->aa_chrange, l);
}
if (src->aa_chtags)
dst->aa_chtags = htsmsg_copy(src->aa_chtags);
return dst;
Expand Down Expand Up @@ -356,7 +364,7 @@ access_dump_a(access_t *a)
int first;

tvh_strlcatf(buf, sizeof(buf), l,
"%s:%s [%c%c%c%c%c%c%c%c%c%c], conn=%u, chmin=%llu, chmax=%llu%s",
"%s:%s [%c%c%c%c%c%c%c%c%c%c], conn=%u%s",
a->aa_representative ?: "<no-id>",
a->aa_username ?: "<no-user>",
a->aa_rights & ACCESS_STREAMING ? 'S' : ' ',
Expand All @@ -370,7 +378,6 @@ access_dump_a(access_t *a)
a->aa_rights & ACCESS_FAILED_RECORDER ? 'F' : ' ',
a->aa_rights & ACCESS_ADMIN ? '*' : ' ',
a->aa_conn_limit,
(long long)a->aa_chmin, (long long)a->aa_chmax,
a->aa_match ? ", matched" : "");

if (a->aa_profiles) {
Expand Down Expand Up @@ -405,6 +412,13 @@ access_dump_a(access_t *a)
tvh_strlcatf(buf, sizeof(buf), l, ", dvr=ANY");
}

if (a->aa_chrange) {
for (first = 0; first < a->aa_chrange_count; first += 2)
tvh_strlcatf(buf, sizeof(buf), l, ", [chmin=%llu, chmax=%llu]",
(long long)a->aa_chrange[first],
(long long)a->aa_chrange[first+1]);
}

if (a->aa_chtags) {
first = 1;
HTSMSG_FOREACH(f, a->aa_chtags) {
Expand Down Expand Up @@ -434,14 +448,11 @@ access_update(access_t *a, access_entry_t *ae)
a->aa_conn_limit = ae->ae_conn_limit;

if(ae->ae_chmin || ae->ae_chmax) {
if(a->aa_chmin || a->aa_chmax) {
if (a->aa_chmin < ae->ae_chmin)
a->aa_chmin = ae->ae_chmin;
if (a->aa_chmax > ae->ae_chmax)
a->aa_chmax = ae->ae_chmax;
} else {
a->aa_chmin = ae->ae_chmin;
a->aa_chmax = ae->ae_chmax;
uint64_t *p = realloc(a->aa_chrange, (a->aa_chrange_count + 2) * sizeof(uint64_t));
if (p) {
p[a->aa_chrange_count++] = ae->ae_chmin;
p[a->aa_chrange_count++] = ae->ae_chmax;
a->aa_chrange = p;
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/access.h
Expand Up @@ -94,8 +94,8 @@ typedef struct access {
uint32_t aa_rights;
htsmsg_t *aa_profiles;
htsmsg_t *aa_dvrcfgs;
uint64_t aa_chmin;
uint64_t aa_chmax;
uint64_t *aa_chrange;
int aa_chrange_count;
htsmsg_t *aa_chtags;
int aa_match;
uint32_t aa_conn_limit;
Expand Down
8 changes: 5 additions & 3 deletions src/channels.c
Expand Up @@ -477,10 +477,12 @@ channel_access(channel_t *ch, access_t *a, int disabled)
return 0;

/* Channel number check */
if (a->aa_chmin || a->aa_chmax) {
if (a->aa_chrange) {
int64_t chnum = channel_get_number(ch);
if (chnum < a->aa_chmin || chnum > a->aa_chmax)
return 0;
int i;
for (i = 0; i < a->aa_chrange_count; i += 2)
if (chnum < a->aa_chrange[i] || chnum > a->aa_chrange[i+1])
return 0;
}

/* Channel tag check */
Expand Down

2 comments on commit d8c3296

@ckarrie
Copy link
Contributor

@ckarrie ckarrie commented on d8c3296 Jun 1, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not allow multiple Channel Tags instead of Channel ranges?

@perexg
Copy link
Contributor Author

@perexg perexg commented on d8c3296 Jun 1, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already implemented in the same way. See help (second paragraph).

Please sign in to comment.