From 2e66b0e1b7f493ab81e171e566a026b9ba541862 Mon Sep 17 00:00:00 2001 From: Ian Date: Fri, 4 Apr 2014 17:57:49 +0100 Subject: [PATCH] Final fix for user permissions (file/directory) on recordings. I hope! --- docs/html/config_dvr.html | 8 ++--- src/dvr/dvr_db.c | 66 ++++++--------------------------------- src/tvheadend.h | 7 ----- src/utils.c | 22 ------------- src/webui/extjs.c | 28 ++++------------- 5 files changed, 20 insertions(+), 111 deletions(-) diff --git a/docs/html/config_dvr.html b/docs/html/config_dvr.html index 2cc9836a..68a44ee7 100644 --- a/docs/html/config_dvr.html +++ b/docs/html/config_dvr.html @@ -86,7 +86,7 @@ 0666 == rw-rw-rw- - Note that your default user umask applies, so 666 with umask 0002 will produce 0664. + Note that the applicable umask applies, so 0666 with umask 0022 will produce 0644 (rw-r--r--). See also Directory permissions in Subdirectory Options. @@ -113,12 +113,12 @@
- - + +
Common examples:
0755 == rwxr--r--
0775 == rwxrwxr-- (default)
0755 == rwxr-xr-x
0775 == rwxrwxr-x (default)
0777 == rwxrwxrwx
- Note that your default user umask applies, so 0777 with umask 0002 will produce 0775. + Note that the applicable umask applies, so 0777 with umask 0022 will produce 0755 (rwxr-xr-x). See also File permissions in Recording File Options. diff --git a/src/dvr/dvr_db.c b/src/dvr/dvr_db.c index ca43c3c5..19e85a20 100644 --- a/src/dvr/dvr_db.c +++ b/src/dvr/dvr_db.c @@ -1134,54 +1134,15 @@ dvr_init(void) htsmsg_get_u32(m, "retention-days", &cfg->dvr_retention_days); tvh_str_set(&cfg->dvr_storage, htsmsg_get_str(m, "storage")); -//IH +// Convert 0xxx format permission strings to integer for internal use +// Note no checking that strtol won't overflow int - this should never happen with three-digit numbers -/* THIS IS WHERE IT ALL GOES HORRIBLY WRONG - * - * I need to pass tvh_str_set a type char**, but I'm genuinely guessing, and that's not good even if it compiles! - * - */ - - tvhlog(LOG_INFO, "loading", "%s Before load octal file-permission \"%o\"", cfg->dvr_config_name, cfg->dvr_muxcnf.m_file_permissions); - - tvhlog(LOG_INFO, "loading", "calling tvh_str_set"); - -// This is embarassingly poor code. Sorry. - - char placeholder[5]; // Yes, I know it should be at the start of the function - char *placeholderptr; // Ditto - - placeholderptr = placeholder; - -// tvhlog(LOG_INFO, "loading", "placeholder \"%s\"", placeholder); -// tvhlog(LOG_INFO, "loading", "placeholderptr \"%i\"", &placeholderptr); -// tvhlog(LOG_INFO, "loading", "placeholder \"%i\"", &placeholder); - - tvh_str_set(&placeholderptr, htsmsg_get_str(m, "file-permissions")); + if ((s = htsmsg_get_str(m, "file-permissions"))) + cfg->dvr_muxcnf.m_file_permissions = (int)strtol(s,NULL,0); -// tvhlog(LOG_INFO, "loading", "copying cfg"); - -// Thought: we know that strtol will return a type that can be cast to int -// What if someone manually enters 123456789 in the config file? What then? -// Worth checking if strtol returns > int size then throw error and revert to default as it's clearly invalid? -// Isn't the same true of editing it to be "file perms : abolloxstring" or "boolean-flags : aaargh"? It's their fault... + if ((s = htsmsg_get_str(m, "directory-permissions"))) + cfg->dvr_muxcnf.m_directory_permissions = (int)strtol(s,NULL,0); - cfg->dvr_muxcnf.m_file_permissions = (int)strtol(placeholder,NULL,0); - -// tvhlog(LOG_INFO, "loading", "%s Loaded octal placeholder file-permission \"%o\"", cfg->dvr_config_name,cfg->dvr_muxcnf.m_file_permissions); -// tvhlog(LOG_INFO, "loading", "%s After load octal file-permission \"%o\"", cfg->dvr_config_name,cfg->dvr_muxcnf.m_file_permissions); - -// tvhlog(LOG_INFO, "loading", "%s Before load octal dir-permission \"%o\"", cfg->dvr_config_name,cfg->dvr_muxcnf.m_directory_permissions); - -// THIS WILL BREAK AS WELL. Amateur. - - tvh_str_set(&placeholderptr, htsmsg_get_str(m, "directory-permissions")); - cfg->dvr_muxcnf.m_directory_permissions = (int)strtol(placeholder,NULL,0); - -// tvhlog(LOG_INFO, "loading", "%s Loaded octal directory-permission \"%o\"", cfg->dvr_config_name,cfg->dvr_muxcnf.m_directory_permissions); -// tvhlog(LOG_INFO, "loading", "%s After load octal directory-permission \"%o\"", cfg->dvr_config_name,cfg->dvr_muxcnf.m_directory_permissions); - - if(!htsmsg_get_u32(m, "day-dir", &u32) && u32) cfg->dvr_flags |= DVR_DIR_PER_DAY; @@ -1404,27 +1365,20 @@ static void dvr_save(dvr_config_t *cfg) { htsmsg_t *m = htsmsg_create_map(); - char buffer[5]; //IH - leading zero, three octal digits plus terminating null + char buffer[5]; // Permissions buffer: leading zero, three octal digits plus terminating null if (cfg->dvr_config_name != NULL && strlen(cfg->dvr_config_name) != 0) htsmsg_add_str(m, "config_name", cfg->dvr_config_name); htsmsg_add_str(m, "storage", cfg->dvr_storage); -// tvhlog(LOG_INFO, "saving", "****** To be written: file-permission decimal \"%i\"", cfg->dvr_muxcnf.m_file_permissions); -// tvhlog(LOG_INFO, "saving", "****** equivalent to octal \"%o\"", cfg->dvr_muxcnf.m_file_permissions); -// tvhlog(LOG_INFO, "saving", "****** To be written: directory-permission decimal \"%i\"", cfg->dvr_muxcnf.m_directory_permissions); -// tvhlog(LOG_INFO, "saving", "****** equivalent to octal \"%o\"", cfg->dvr_muxcnf.m_directory_permissions); +// Convert permissions to 0xxx octal format and output - snprintf(buffer,5,"%o",cfg->dvr_muxcnf.m_file_permissions); + snprintf(buffer,sizeof(buffer),"%04o",cfg->dvr_muxcnf.m_file_permissions); htsmsg_add_str(m, "file-permissions", buffer); -// tvhlog(LOG_INFO, "saving", "****** Saved file-permission as string \"%s\"", buffer); - - snprintf(buffer,5,"%o",cfg->dvr_muxcnf.m_directory_permissions); + snprintf(buffer,sizeof(buffer),"%04o",cfg->dvr_muxcnf.m_directory_permissions); htsmsg_add_str(m, "directory-permissions", buffer); -// tvhlog(LOG_INFO, "saving", "****** Saved directory-permission as string \"%s\"", buffer); - htsmsg_add_u32(m, "container", cfg->dvr_mc); htsmsg_add_u32(m, "cache", cfg->dvr_muxcnf.m_cache); htsmsg_add_u32(m, "rewrite-pat", diff --git a/src/tvheadend.h b/src/tvheadend.h index 852ceab9..ace8a63e 100644 --- a/src/tvheadend.h +++ b/src/tvheadend.h @@ -628,13 +628,6 @@ int rmtree ( const char *path ); char *regexp_escape ( const char *str ); -//IH -// Helper functions to convert between string/decimal literals and octal notation (i.e. 777 => 0777 => 777) -// Potentially superseded by other methods - -int decimal_to_octal ( const int decimal ); -int octal_to_decimal ( const int octal ); - #define SKEL_DECLARE(name, type) type *name; #define SKEL_ALLOC(name) do { if (!name) name = calloc(1, sizeof(*name)); } while (0) #define SKEL_USED(name) do { name = NULL; } while (0) diff --git a/src/utils.c b/src/utils.c index f8d45f60..6eab4ec7 100644 --- a/src/utils.c +++ b/src/utils.c @@ -473,25 +473,3 @@ regexp_escape(const char* str) *b = 0; return tmp; } - -//IH - no longer needed? Delete afterwards as required. I think snprintf and strtol have superseded them, though - -int -decimal_to_octal(const int decimal) -{ - int octal; - - octal = ((decimal / 100) * 64) | ((decimal % 100 / 10) * 8) | (decimal % 10); - - return octal; -} - -int -octal_to_decimal(const int octal) -{ - int decimal; - - decimal = ((octal / 64) * 100) | ((octal % 64 / 8) * 10) | (octal % 8); - - return decimal; -} diff --git a/src/webui/extjs.c b/src/webui/extjs.c index 81f60c73..9ddb549b 100755 --- a/src/webui/extjs.c +++ b/src/webui/extjs.c @@ -970,7 +970,7 @@ extjs_dvr(http_connection_t *hc, const char *remain, void *opaque) int flags = 0; dvr_config_t *cfg; epg_broadcast_t *e; - char buffer[5]; //IH - leading zero, three octal digits plus terminating null + char buffer[5]; // Permissions buffer: leading zero, three octal digits plus terminating null if(op == NULL) op = "loadSettings"; @@ -1128,13 +1128,12 @@ extjs_dvr(http_connection_t *hc, const char *remain, void *opaque) htsmsg_add_str(r, "storage", cfg->dvr_storage); htsmsg_add_str(r, "container", muxer_container_type2txt(cfg->dvr_mc)); -//IH Convert integer permissions to an octal-format string and store it in the config file +// Convert integer permissions to an octal-format 0xxx string and store it in the config file - snprintf(buffer,5,"%o",cfg->dvr_muxcnf.m_file_permissions); + snprintf(buffer,sizeof(buffer),"%04o",cfg->dvr_muxcnf.m_file_permissions); htsmsg_add_str(r, "filePermissions", buffer); - snprintf(buffer,5,"%o",cfg->dvr_muxcnf.m_directory_permissions); + snprintf(buffer,sizeof(buffer),"%04o",cfg->dvr_muxcnf.m_directory_permissions); htsmsg_add_str(r, "dirPermissions", buffer); -// htsmsg_add_u32(r, "cache", cfg->dvr_muxcnf.m_cache); htsmsg_add_u32(r, "rewritePAT", @@ -1177,30 +1176,15 @@ extjs_dvr(http_connection_t *hc, const char *remain, void *opaque) if((s = http_arg_get(&hc->hc_req_args, "container")) != NULL) dvr_container_set(cfg,s); -//IH -// Convert the octal string permissions to integer - -// Theoretical risk of overflowing the (int) cast from long, but this shouldn't ever happen in normal use -// Only if someone's been dicking about with the config by hand -// and then a plague be upon their houses +// Convert 0xxx format permission strings to integer for internal use +// Note no checking that strtol won't overflow int - this should never happen with three-digit numbers if((s = http_arg_get(&hc->hc_req_args, "filePermissions")) != NULL) dvr_file_permissions_set(cfg,(int)strtol(s,NULL,0)); -// tvhlog(LOG_INFO, "extjs.c", "****** Testing string \"%s\"", s); -// tvhlog(LOG_INFO, "extjs.c", "****** Testing decimal \"%i\"", (int)strtol(s,NULL,0)); -// tvhlog(LOG_INFO, "extjs.c", "****** Testing octal \"%o\"", (int)strtol(s,NULL,0)); - -// tvhlog(LOG_INFO, "extjs.c", "****** Line 1190+ - File permissions set to decimal \"%i\"", cfg->dvr_muxcnf.m_file_permissions); -// tvhlog(LOG_INFO, "extjs.c", "****** Line 1190+ - equivalent to octal \"%o\"", cfg->dvr_muxcnf.m_file_permissions); - if((s = http_arg_get(&hc->hc_req_args, "dirPermissions")) != NULL) dvr_directory_permissions_set(cfg,(int)strtol(s,NULL,0)); -// tvhlog(LOG_INFO, "extjs.c", "****** Line 1190+ = Dir permissions set to decimal \"%i\"", cfg->dvr_muxcnf.m_directory_permissions); -// tvhlog(LOG_INFO, "extjs.c", "****** Line 1190+ = equivalent to octal \"%o\"", cfg->dvr_muxcnf.m_directory_permissions); - - if((s = http_arg_get(&hc->hc_req_args, "cache")) != NULL) dvr_mux_cache_set(cfg,atoi(s));