Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
DVR(all): don't restrict save/delete/moveup/movedown/cancel operation…
…s only for admin - use class filters, fixes #2893
  • Loading branch information
perexg committed May 26, 2015
1 parent 1d47756 commit 7643f72
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 14 deletions.
3 changes: 2 additions & 1 deletion src/api.h
Expand Up @@ -106,7 +106,8 @@ int api_idnode_load_by_class
( access_t *perm, void *opaque, const char *op, htsmsg_t *args, htsmsg_t **resp );

int api_idnode_handler
( access_t *perm, htsmsg_t *args, htsmsg_t **resp, void (*handler)(access_t *perm, idnode_t *in) );
( access_t *perm, htsmsg_t *args, htsmsg_t **resp,
void (*handler)(access_t *perm, idnode_t *in), const char *op );

/*
* Service mapper
Expand Down
2 changes: 1 addition & 1 deletion src/api/api_dvr.c
Expand Up @@ -236,7 +236,7 @@ static int
api_dvr_entry_cancel
( access_t *perm, void *opaque, const char *op, htsmsg_t *args, htsmsg_t **resp )
{
return api_idnode_handler(perm, args, resp, api_dvr_cancel);
return api_idnode_handler(perm, args, resp, api_dvr_cancel, "cancel");
}

static void
Expand Down
36 changes: 24 additions & 12 deletions src/api/api_idnode.c
Expand Up @@ -458,11 +458,12 @@ api_idnode_class
int
api_idnode_handler
( access_t *perm, htsmsg_t *args, htsmsg_t **resp,
void (*handler)(access_t *perm, idnode_t *in) )
void (*handler)(access_t *perm, idnode_t *in),
const char *op )
{
int err = 0;
idnode_t *in;
htsmsg_t *uuids;
htsmsg_t *uuids, *msg;
htsmsg_field_t *f;
const char *uuid;

Expand All @@ -488,10 +489,18 @@ api_idnode_handler
/* Single */
} else {
uuid = htsmsg_field_get_string(f);
if (!(in = idnode_find(uuid, NULL, NULL)))
if (!(in = idnode_find(uuid, NULL, NULL))) {
err = ENOENT;
else
handler(perm, in);
} else {
msg = htsmsg_create_map();
htsmsg_add_str(msg, "__op__", op);
if (idnode_perm(in, perm, msg)) {
err = EPERM;
} else {
handler(perm, in);
}
htsmsg_destroy(msg);
}
}

pthread_mutex_unlock(&global_lock);
Expand All @@ -509,7 +518,7 @@ static int
api_idnode_delete
( access_t *perm, void *opaque, const char *op, htsmsg_t *args, htsmsg_t **resp )
{
return api_idnode_handler(perm, args, resp, api_idnode_delete_);
return api_idnode_handler(perm, args, resp, api_idnode_delete_, "delete");
}

static void
Expand All @@ -522,7 +531,7 @@ static int
api_idnode_moveup
( access_t *perm, void *opaque, const char *op, htsmsg_t *args, htsmsg_t **resp )
{
return api_idnode_handler(perm, args, resp, api_idnode_moveup_);
return api_idnode_handler(perm, args, resp, api_idnode_moveup_, "moveup");
}

static void
Expand All @@ -535,19 +544,22 @@ static int
api_idnode_movedown
( access_t *perm, void *opaque, const char *op, htsmsg_t *args, htsmsg_t **resp )
{
return api_idnode_handler(perm, args, resp, api_idnode_movedown_);
return api_idnode_handler(perm, args, resp, api_idnode_movedown_, "movedown");
}

void api_idnode_init ( void )
{
/*
* note: permissions are verified using idnode_perm() calls
*/
static api_hook_t ah[] = {
{ "idnode/load", ACCESS_ANONYMOUS, api_idnode_load, NULL },
{ "idnode/save", ACCESS_ADMIN, api_idnode_save, NULL },
{ "idnode/save", ACCESS_ANONYMOUS, api_idnode_save, NULL },
{ "idnode/tree", ACCESS_ANONYMOUS, api_idnode_tree, NULL },
{ "idnode/class", ACCESS_ANONYMOUS, api_idnode_class, NULL },
{ "idnode/delete", ACCESS_ADMIN, api_idnode_delete, NULL },
{ "idnode/moveup", ACCESS_ADMIN, api_idnode_moveup, NULL },
{ "idnode/movedown", ACCESS_ADMIN, api_idnode_movedown, NULL },
{ "idnode/delete", ACCESS_ANONYMOUS, api_idnode_delete, NULL },
{ "idnode/moveup", ACCESS_ANONYMOUS, api_idnode_moveup, NULL },
{ "idnode/movedown", ACCESS_ANONYMOUS, api_idnode_movedown, NULL },
{ NULL },
};

Expand Down

0 comments on commit 7643f72

Please sign in to comment.