Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
htsp: Fix config profile selection based on user ACL
  • Loading branch information
perexg committed Sep 22, 2014
1 parent 616e774 commit 4bdcdd2
Showing 1 changed file with 35 additions and 4 deletions.
39 changes: 35 additions & 4 deletions src/htsp_server.c
Expand Up @@ -1229,6 +1229,39 @@ htsp_method_getEpgObject(htsp_connection_t *htsp, htsmsg_t *in)
return out;
}

static const char *
htsp_dvr_config_name( access_t *perm, const char *config_name )
{
dvr_config_t *cfg = NULL, *cfg2;
htsmsg_field_t *f;
const char *uuid;

lock_assert(&global_lock);

if (config_name == NULL)
return "";

if (perm->aa_dvrcfgs == NULL)
return config_uuid; /* no change */

config_uuid = config_uuid ?: "";
HTSMSG_FOREACH(f, perm->aa_dvrcfgs) {
uuid = htsmsg_field_get_str(f) ?: "";
if (strcmp(uuid, config_name) == 0)
return config_name;
cfg2 = dvr_config_entry_find_by_uuid(uuid);
if (cfg2 && strcmp(cfg2->dvr_config_name, config_name) == 0)
return uuid;
if (!cfg)
cfg = cfg2;
}

if (!cfg && perm->aa_username)
tvhlog(LOG_INFO, "htsp", "User '%s' has no valid dvr config in ACL, using default...", perm->aa_username);

return cfg ? idnode_uuid_as_str(&cfg->dvr_id) : NULL;
}

/**
* add a Dvrentry
*/
Expand All @@ -1246,8 +1279,7 @@ htsp_method_addDvrEntry(htsp_connection_t *htsp, htsmsg_t *in)
channel_t *ch = NULL;

/* Options */
if(!(dvr_config_name = htsmsg_get_str(in, "configName")))
dvr_config_name = "";
dvr_config_name = htsp_dvr_config_name(htsmsg_get_str(in, "configName")))
if(htsmsg_get_s64(in, "startExtra", &start_extra))
start_extra = 0;
if(htsmsg_get_s64(in, "stopExtra", &stop_extra))
Expand Down Expand Up @@ -1435,8 +1467,7 @@ htsp_method_addAutorecEntry(htsp_connection_t *htsp, htsmsg_t *in)
/* Options */
if(!(title = htsmsg_get_str(in, "title")))
return htsp_error("Invalid arguments");
if(!(dvr_config_name = htsmsg_get_str(in, "configName")))
dvr_config_name = "";
dvr_config_name = htsp_dvr_config_name(htsmsg_get_str(in, "configName")))
if(!htsmsg_get_u32(in, "channelId", &u32))
ch = channel_find_by_id(u32);
if(htsmsg_get_u32(in, "maxDuration", &max_duration))
Expand Down

0 comments on commit 4bdcdd2

Please sign in to comment.