]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
Rework on the addition of user options for file/dir permissions
authorIan <ian@Server>
Fri, 4 Apr 2014 15:46:56 +0000 (16:46 +0100)
committerIan <ian@Server>
Fri, 4 Apr 2014 15:46:56 +0000 (16:46 +0100)
Note that this will not work without the intervention of someone who actually knows what they're doing ;-)

docs/html/config_dvr.html
src/dvr/dvr_db.c
src/dvr/dvr_rec.c
src/muxer/muxer_pass.c
src/muxer/tvh/mkmux.c
src/tvheadend.h
src/utils.c
src/webui/extjs.c
src/webui/static/app/dvr.js

index 703ef47aca66c353e3b3e40e276460d165ffeb47..2cc9836a01242d73b385be7da7c6dd09b6f0e3fc 100644 (file)
       <table class="hts-doc-text" border="0">
       <tr><td>Common examples:</td></tr> 
       <br>
-      <tr><td>644 == rw-r--r--</td></tr>
-      <tr><td>664 == rw-rw-r-- (default)</td></tr>
-         <tr><td>666 == rw-rw-rw-</td></tr>
+      <tr><td>0644 == rw-r--r--</td></tr>
+      <tr><td>0664 == rw-rw-r-- (default)</td></tr>
+         <tr><td>0666 == rw-rw-rw-</td></tr>
          </table>
          
-         Note that your default user umask applies, so 666 with umask 002 will produce 664.
+         Note that your default user umask applies, so 666 with umask 0002 will produce 0664.
          
          See also <i>Directory permissions</i> in <i>Subdirectory Options</i>. 
          
       <table class="hts-doc-text" border="0">
       <tr><td>Common examples:</td></tr> 
       <br>
-      <tr><td>755 == rwxr--r--</td></tr>
-      <tr><td>775 == rwxrwxr-- (default)</td></tr>
-         <tr><td>777 == rwxrwxrwx</td></tr>
+      <tr><td>0755 == rwxr--r--</td></tr>
+      <tr><td>0775 == rwxrwxr-- (default)</td></tr>
+         <tr><td>0777 == rwxrwxrwx</td></tr>
          </table>
          
-         Note that your default user umask applies, so 777 with umask 002 will produce 775.
+         Note that your default user umask applies, so 0777 with umask 0002 will produce 0775.
          
          See also <i>File permissions</i> in <i>Recording File Options</i>. 
          
index 70e3983ec6dbdbe38d1bb47216d5fd6e6295e482..ca43c3c54d4e79a95f1c582ed8a60e454efc7258 100644 (file)
@@ -1090,7 +1090,7 @@ dvr_init(void)
   struct stat st;
   uint32_t u32;
   dvr_config_t *cfg;
-
+  
   dvr_iov_max = sysconf(_SC_IOV_MAX);
 
   /* Default settings */
@@ -1133,9 +1133,55 @@ dvr_init(void)
       htsmsg_get_s32(m, "post-extra-time", &cfg->dvr_extra_time_post);
       htsmsg_get_u32(m, "retention-days", &cfg->dvr_retention_days);
       tvh_str_set(&cfg->dvr_storage, htsmsg_get_str(m, "storage"));
-      htsmsg_get_s32(m, "file-permissions", &cfg->dvr_muxcnf.m_file_permissions);
-      htsmsg_get_s32(m, "directory-permissions", &cfg->dvr_muxcnf.m_directory_permissions);
+
+//IH      
+
+/* 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"));
+         
+//      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...
+
+      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;
 
@@ -1316,9 +1362,9 @@ dvr_config_create(const char *name)
   cfg->dvr_dup_detect_episode = 1; // detect dup episodes
 
   /* Default recording file and directory permissions */
-  /* Note that these are decimal literal equivalents of the octal - they get converted later. Yes, it's a kludge. Sue me. */  
-  cfg->dvr_muxcnf.m_file_permissions 664;
-  cfg->dvr_muxcnf.m_directory_permissions = 775;
+
+  cfg->dvr_muxcnf.m_file_permissions      = 0664;
+  cfg->dvr_muxcnf.m_directory_permissions = 0775;
   
   LIST_INSERT_HEAD(&dvrconfigs, cfg, config_link);
 
@@ -1358,12 +1404,27 @@ 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
   
   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);
-  htsmsg_add_u32(m, "file-permissions", cfg->dvr_muxcnf.m_file_permissions);
-  htsmsg_add_u32(m, "directory-permissions", cfg->dvr_muxcnf.m_directory_permissions);
+
+//  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);
+
+  snprintf(buffer,5,"%o",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);
+  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",
index 2d9938abc29e078f957818530bec4d37cec98dcf..25814e815d04e01ae9f89823fa2c0a654b2a203f 100644 (file)
@@ -204,15 +204,7 @@ pvr_generate_filename(dvr_entry_t *de, const streaming_start_t *ss)
     free(title);
   }
 
-// Very ugly hack alert!
-// Convert my nasty stored-as-decimal permissions into literal octal equivalent (i.e. 777 => 0777)
-  
-  int decimal_perms = cfg->dvr_muxcnf.m_directory_permissions;
-  int octal_perms = ((decimal_perms / 100) << 6) | ((decimal_perms % 100 / 10) << 3) | (decimal_perms % 10);
-
-// Create directory path
-  
-  if(makedirs(path, octal_perms) != 0) {
+  if(makedirs(path, cfg->dvr_muxcnf.m_directory_permissions) != 0) {
     return -1;
   }
   
index abde368950bf4b6b3993b0503763063d72a3a892..b9bc3b5ec78b504df17c18a4da1c2d5c03730108 100644 (file)
@@ -378,14 +378,9 @@ pass_muxer_open_file(muxer_t *m, const char *filename)
   int fd;
   pass_muxer_t *pm = (pass_muxer_t*)m;
 
-// Very ugly hack alert!
-// Convert my nasty stored-as-decimal permissions into literal octal equivalent (i.e. 777 => 0777)
-  
-  int decimal_perms = pm->m_config.m_file_permissions;
-  int octal_perms = ((decimal_perms / 100) << 6) | ((decimal_perms % 100 / 10) << 3) | (decimal_perms % 10);
-
-  tvhlog(LOG_DEBUG, "pass", "Creating file \"%s\" with octal permissions \"%o\"", filename, octal_perms);
-  fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, octal_perms);
+  tvhlog(LOG_DEBUG, "pass", "Creating file \"%s\" with file permissions \"%o\"", filename, pm->m_config.m_file_permissions);
+  fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, pm->m_config.m_file_permissions);
 
   if(fd < 0) {
     pm->pm_error = errno;
index a810cb35a15485e2749620397abba5801d847946..35b0350765b29d24b5456fd1dc02bc4d9afb38ca 100644 (file)
@@ -1050,13 +1050,10 @@ mk_mux_open_file(mk_mux_t *mkm, const char *filename, int permissions)
 {
   int fd;
 
-// Very ugly hack alert!
-// Convert my nasty stored-as-decimal permissions into literal octal equivalent (i.e. 777 => 0777)
+  tvhlog(LOG_DEBUG, "mkv", "Creating file \"%s\" with file permissions \"%o\"", filename, permissions);
+  
+  fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, permissions);
   
-  int octal_perms = ((permissions / 100) << 6) | ((permissions % 100 / 10) << 3) | (permissions % 10);
-
-  tvhlog(LOG_DEBUG, "mkv", "Creating file \"%s\" with octal permissions \"%o\"", filename, octal_perms);
-  fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, octal_perms);
   if(fd < 0) {
     mkm->error = errno;
     tvhlog(LOG_ERR, "mkv", "%s: Unable to create file, open failed -- %s",
index ace8a63ecaf84f79d5528f0b289661d30f621187..852ceab97c24ebed942f6a413607bd08bde10f75 100644 (file)
@@ -628,6 +628,13 @@ 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)
index 6eab4ec7209d7d2994ceaa5bfd035b80cab5b738..f8d45f6075e68f26faa6917e58a185ee0a0b99e9 100644 (file)
@@ -473,3 +473,25 @@ 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;
+}
index 9e369644c285ec40c3d977c191e9bdf8927302b7..81f60c73f2dcf8f06a9b57a16df8b34a0a029f08 100755 (executable)
@@ -970,6 +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
 
   if(op == NULL)
     op = "loadSettings";
@@ -1126,8 +1127,15 @@ extjs_dvr(http_connection_t *hc, const char *remain, void *opaque)
     r = htsmsg_create_map();
     htsmsg_add_str(r, "storage", cfg->dvr_storage);
     htsmsg_add_str(r, "container", muxer_container_type2txt(cfg->dvr_mc));
-    htsmsg_add_u32(r, "filePermissions", cfg->dvr_muxcnf.m_file_permissions);
-    htsmsg_add_u32(r, "dirPermissions", cfg->dvr_muxcnf.m_directory_permissions);
+
+//IH Convert integer permissions to an octal-format string and store it in the config file
+
+    snprintf(buffer,5,"%o",cfg->dvr_muxcnf.m_file_permissions);
+    htsmsg_add_str(r, "filePermissions", buffer);
+    snprintf(buffer,5,"%o",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",
                    !!(cfg->dvr_muxcnf.m_flags & MC_REWRITE_PAT));
@@ -1168,13 +1176,31 @@ 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
+
    if((s = http_arg_get(&hc->hc_req_args, "filePermissions")) != NULL)
-      dvr_file_permissions_set(cfg,atoi(s));
+      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,atoi(s));
-      
+      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));
 
index 63fde3f528e95e3a7d2804ca1a481b1f8b6be1f7..9b9163bf996ef1c40aa8dc4e9c283570109049e8 100644 (file)
@@ -829,15 +829,15 @@ tvheadend.dvrsettings = function() {
                name : 'storage'
        });
 
-/* NB: recordingPermissions is defined as a TextField for validation purposes (leading zeros), but is ultimately a decimal number */
+/* NB: recordingPermissions is defined as a TextField for validation purposes (leading zeros), but is ultimately a number */
        
        var recordingPermissions = new Ext.form.TextField({
-               regex : /^[0-7]{3}$/,
+               regex : /^[0][0-7]{3}$/,
            maskRe : /[0-7]/,
                width : 100,
                allowBlank : false,
-               blankText : 'You must provide a value - use octal chmod notation, e.g. 664',
-               fieldLabel : 'File permissions (octal, e.g. 664)',
+               blankText : 'You must provide a value - use octal chmod notation, e.g. 0664',
+               fieldLabel : 'File permissions (octal, e.g. 0664)',
                name : 'filePermissions'
        });
 
@@ -865,15 +865,15 @@ tvheadend.dvrsettings = function() {
                
 /* Subdirectories and filename handling */
 
-/* NB: directoryPermissions is defined as a TextField for validation purposes (leading zeros), but is ultimately a decimal number */
+/* NB: directoryPermissions is defined as a TextField for validation purposes (leading zeros), but is ultimately a number */
 
        var directoryPermissions = new Ext.form.TextField({
-               regex : /^[0-7]{3}$/,
+               regex : /^[0][0-7]{3}$/,
            maskRe : /[0-7]/,
                width : 100,
                allowBlank : false,
-               blankText : 'You must provide a value - use octal chmod notation, e.g. 775',
-               fieldLabel : 'Directory permissions (octal, e.g. 775)',
+               blankText : 'You must provide a value - use octal chmod notation, e.g. 0775',
+               fieldLabel : 'Directory permissions (octal, e.g. 0775)',
                name : 'dirPermissions'
        });