/ Check-in [6c4c2b7d]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Do not use umask() since it change the umask for the entire process, not just the thread using SQLite. Make whatever permission changes are needed using fchmod() after the file is created, instead.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 6c4c2b7dbadedac384d380efd54f12f6ccbf4ca9
User & Date: drh 2013-01-04 20:45:13
Context
2013-01-04
22:26
Remove superfluous text from a comment. check-in: e9ac5339 user: mistachkin tags: trunk
20:45
Do not use umask() since it change the umask for the entire process, not just the thread using SQLite. Make whatever permission changes are needed using fchmod() after the file is created, instead. check-in: 6c4c2b7d user: drh tags: trunk
19:22
Fix an out-of-order local variable declaration in test_regexp.c. check-in: 8285b15a user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/os_unix.c.

   408    408     { "pwrite64",     (sqlite3_syscall_ptr)pwrite64,   0  },
   409    409   #else
   410    410     { "pwrite64",     (sqlite3_syscall_ptr)0,          0  },
   411    411   #endif
   412    412   #define osPwrite64  ((ssize_t(*)(int,const void*,size_t,off_t))\
   413    413                       aSyscall[13].pCurrent)
   414    414   
   415         -#if SQLITE_ENABLE_LOCKING_STYLE
   416    415     { "fchmod",       (sqlite3_syscall_ptr)fchmod,     0  },
   417         -#else
   418         -  { "fchmod",       (sqlite3_syscall_ptr)0,          0  },
   419         -#endif
   420    416   #define osFchmod    ((int(*)(int,mode_t))aSyscall[14].pCurrent)
   421    417   
   422    418   #if defined(HAVE_POSIX_FALLOCATE) && HAVE_POSIX_FALLOCATE
   423    419     { "fallocate",    (sqlite3_syscall_ptr)posix_fallocate,  0 },
   424    420   #else
   425    421     { "fallocate",    (sqlite3_syscall_ptr)0,                0 },
   426    422   #endif
................................................................................
   437    433   
   438    434     { "rmdir",        (sqlite3_syscall_ptr)rmdir,           0 },
   439    435   #define osRmdir     ((int(*)(const char*))aSyscall[19].pCurrent)
   440    436   
   441    437     { "fchown",       (sqlite3_syscall_ptr)posixFchown,     0 },
   442    438   #define osFchown    ((int(*)(int,uid_t,gid_t))aSyscall[20].pCurrent)
   443    439   
   444         -  { "umask",        (sqlite3_syscall_ptr)umask,           0 },
   445         -#define osUmask     ((mode_t(*)(mode_t))aSyscall[21].pCurrent)
   446         -
   447    440   }; /* End of the overrideable system calls */
   448    441   
   449    442   /*
   450    443   ** This is the xSetSystemCall() method of sqlite3_vfs for all of the
   451    444   ** "unix" VFSes.  Return SQLITE_OK opon successfully updating the
   452    445   ** system call pointer, or SQLITE_NOTFOUND if there is no configurable
   453    446   ** system call named zName.
................................................................................
   544    537   ** In that way, if a database file is -rw-rw-rw or -rw-rw-r-, and a
   545    538   ** transaction crashes and leaves behind hot journals, then any
   546    539   ** process that is able to write to the database will also be able to
   547    540   ** recover the hot journals.
   548    541   */
   549    542   static int robust_open(const char *z, int f, mode_t m){
   550    543     int fd;
   551         -  mode_t m2;
   552         -  mode_t origM = 0;
   553         -  if( m==0 ){
   554         -    m2 = SQLITE_DEFAULT_FILE_PERMISSIONS;
   555         -  }else{
   556         -    m2 = m;
   557         -    origM = osUmask(0);
   558         -  }
          544  +  mode_t m2 = m ? m : SQLITE_DEFAULT_FILE_PERMISSIONS;
   559    545     do{
   560    546   #if defined(O_CLOEXEC)
   561    547       fd = osOpen(z,f|O_CLOEXEC,m2);
   562    548   #else
   563    549       fd = osOpen(z,f,m2);
   564    550   #endif
   565    551     }while( fd<0 && errno==EINTR );
   566         -  if( m ){
   567         -    osUmask(origM);
   568         -  }
          552  +  if( fd>=0 ){
          553  +    if( m!=0 ){
          554  +      struct stat statbuf;
          555  +      if( osFstat(fd, &statbuf)==0 && (statbuf.st_mode&0777)!=m ){
          556  +        osFchmod(fd, m);
          557  +      }
          558  +    }
   569    559   #if defined(FD_CLOEXEC) && (!defined(O_CLOEXEC) || O_CLOEXEC==0)
   570         -  if( fd>=0 ) osFcntl(fd, F_SETFD, osFcntl(fd, F_GETFD, 0) | FD_CLOEXEC);
          560  +    osFcntl(fd, F_SETFD, osFcntl(fd, F_GETFD, 0) | FD_CLOEXEC);
   571    561   #endif
          562  +  }
   572    563     return fd;
   573    564   }
   574    565   
   575    566   /*
   576    567   ** Helper functions to obtain and relinquish the global mutex. The
   577    568   ** global mutex is used to protect the unixInodeInfo and
   578    569   ** vxworksFileId objects used by this file, all of which may be 
................................................................................
  6990   6981       UNIXVFS("unix-proxy",    proxyIoFinder ),
  6991   6982   #endif
  6992   6983     };
  6993   6984     unsigned int i;          /* Loop counter */
  6994   6985   
  6995   6986     /* Double-check that the aSyscall[] array has been constructed
  6996   6987     ** correctly.  See ticket [bb3a86e890c8e96ab] */
  6997         -  assert( ArraySize(aSyscall)==22 );
         6988  +  assert( ArraySize(aSyscall)==21 );
  6998   6989   
  6999   6990     /* Register all VFSes defined in the aVfs[] array */
  7000   6991     for(i=0; i<(sizeof(aVfs)/sizeof(sqlite3_vfs)); i++){
  7001   6992       sqlite3_vfs_register(&aVfs[i], i==0);
  7002   6993     }
  7003   6994     return SQLITE_OK; 
  7004   6995   }

Changes to test/pager1.test.

   879    879       INSERT INTO t1 VALUES('IV', 'sixteen');
   880    880       INSERT INTO t1 VALUES('V' , 'twentyfive');
   881    881     COMMIT;
   882    882   } {delete}
   883    883   tv filter {}
   884    884   db close
   885    885   tv delete 
          886  +catch {
          887  +  test_syscall install fchmod
          888  +  test_syscall fault 1 1
          889  +}
   886    890   do_test pager1.4.7.2 {
   887    891     faultsim_restore_and_reopen
   888    892     catch {file attributes test.db-journal -permissions r--------}
   889    893     catch {file attributes test.db-journal -readonly 1}
   890    894     catchsql { SELECT * FROM t1 }
   891    895   } {1 {unable to open database file}}
          896  +catch {
          897  +  test_syscall reset
          898  +  test_syscall fault 0 0
          899  +}
   892    900   do_test pager1.4.7.3 {
   893    901     db close
   894    902     catch {file attributes test.db-journal -permissions rw-rw-rw-}
   895    903     catch {file attributes test.db-journal -readonly 0}
   896    904     delete_file test.db-journal
   897    905     file exists test.db-journal
   898    906   } {0}

Changes to test/tkt3457.test.

    28     28   # 
    29     29   #   tkt3457-1.2: Application has neither read, nor write permission on
    30     30   #                the hot-journal file. Result: SQLITE_CANTOPEN.
    31     31   #                
    32     32   #   tkt3457-1.3: Application has write but not read permission on
    33     33   #                the hot-journal file. Result: SQLITE_CANTOPEN.
    34     34   #
    35         -#   tkt3457-1.4: Application has read but not write permission on
           35  +#   tkt3457-1.4: Application has read but not write permission ongrep
    36     36   #                the hot-journal file. Result: SQLITE_CANTOPEN.
    37     37   #
    38     38   #   tkt3457-1.5: Application has read/write permission on the hot-journal 
    39     39   #                file. Result: SQLITE_OK.
    40     40   # 
    41     41   do_test tkt3457-1.1 {
    42     42     execsql {
................................................................................
    57     57     fconfigure $fd -encoding binary -translation binary
    58     58     seek $fd 0
    59     59     puts -nonewline $fd "\xd9\xd5\x05\xf9\x20\xa1\x63\xd7"
    60     60     close $fd
    61     61   
    62     62     execsql COMMIT
    63     63   } {}
           64  +
           65  +# Disable fchmod to make sure SQLite itself does not try to change the
           66  +# permission bits on us
           67  +#
           68  +catch {
           69  +  test_syscall install fchmod
           70  +  test_syscall fault 1 1
           71  +}
    64     72   
    65     73   do_test tkt3457-1.2 {
    66     74     forcecopy bak.db-journal test.db-journal
    67     75     file attributes test.db-journal -permissions ---------
    68     76     catchsql { SELECT * FROM t1 }
    69     77   } {1 {unable to open database file}}
    70     78   do_test tkt3457-1.3 {
................................................................................
    79     87   } {1 {unable to open database file}}
    80     88   
    81     89   do_test tkt3457-1.5 {
    82     90     forcecopy bak.db-journal test.db-journal
    83     91     file attributes test.db-journal -permissions rw-rw-rw-
    84     92     catchsql { SELECT * FROM t1 }
    85     93   } {0 {1 2 3 4 5 6}}
           94  +
           95  +# Reenable fchmod
           96  +catch {
           97  +  test_syscall uninstall
           98  +  test_syscall fault 0 0
           99  +}
    86    100   
    87    101   finish_test