]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
When creating journal files (including -wal and -shm files) try to set the
authordrh <drh@noemail.net>
Sat, 11 Feb 2012 19:23:48 +0000 (19:23 +0000)
committerdrh <drh@noemail.net>
Sat, 11 Feb 2012 19:23:48 +0000 (19:23 +0000)
ownership to be the same as the original database.  This will prevent root
from locking out the original owner of the file.

FossilOrigin-Name: 1254dffe4071656a783cd000b1dd40c975ac18cb

manifest
manifest.uuid
src/os_unix.c

index 4c3f43e124487f6b910663f40487222b9663f606..bf76b978d3ecd964189d81aa5bc64d297592c91b 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Remove\sa\sredundant\stest\sfrom\sthe\sshared-memory\slogic\sin\sos_unix.c.
-D 2012-02-11T18:51:34.899
+C When\screating\sjournal\sfiles\s(including\s-wal\sand\s-shm\sfiles)\stry\sto\sset\sthe\nownership\sto\sbe\sthe\ssame\sas\sthe\soriginal\sdatabase.\s\sThis\swill\sprevent\sroot\nfrom\slocking\sout\sthe\soriginal\sowner\sof\sthe\sfile.
+D 2012-02-11T19:23:48.068
 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
 F Makefile.in 3f79a373e57c3b92dabf76f40b065e719d31ac34
 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -166,7 +166,7 @@ F src/os.c e1acdc09ff3ac2412945cca9766e2dcf4675f31c
 F src/os.h 59beba555b65a450bd1d804220532971d4299f60
 F src/os_common.h 92815ed65f805560b66166e3583470ff94478f04
 F src/os_os2.c 4a75888ba3dfc820ad5e8177025972d74d7f2440
-F src/os_unix.c 35fb4bc9bc1acf2fb67d4c3b78d1ab471e22a0fd
+F src/os_unix.c f7e7b3e4f6922e3b07250a22c81da766ac2cc8fa
 F src/os_win.c 5ac061ae1326a71500cee578ed0fd9113b4f6a37
 F src/pager.c 2d892f7b901a8867a33bc21742086165a3a99af8
 F src/pager.h a435da8421dc7844b7f9c7f37b636c160c50208a
@@ -989,7 +989,7 @@ F tool/tostr.awk e75472c2f98dd76e06b8c9c1367f4ab07e122d06
 F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
 F tool/warnings-clang.sh 9f406d66e750e8ac031c63a9ef3248aaa347ef2a
 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381
-P 33294bbd1724665832464b33f865a29dc82b90f6
-R 00b08584e9c041156461ca40087c2e4e
+P 31142ca795005bf664f34000591e6572c72652f2
+R bf3c1343906df15f83435e1a674bd11e
 U drh
-Z c9bd46f5e0e3af1639554e403a310b26
+Z 10acee19c2f6805ba89a4f170956f4c5
index b10ed1b83c845acdbc40c1294fda8dc8b2c3ac53..be561debed16c082406e85c187e4efd42672180c 100644 (file)
@@ -1 +1 @@
-31142ca795005bf664f34000591e6572c72652f2
\ No newline at end of file
+1254dffe4071656a783cd000b1dd40c975ac18cb
\ No newline at end of file
index b717a08d72b7c8a2ca7e7ba61111a50d75a7cb86..5e4ab8d24820af06ed1f349b40d4e08d12c01cc3 100644 (file)
@@ -3904,6 +3904,13 @@ static int unixOpenSharedMemory(unixFile *pDbFd){
         rc = unixLogError(SQLITE_CANTOPEN_BKPT, "open", zShmFilename);
         goto shm_open_err;
       }
+
+      /* If this process is running as root, make sure that the SHM file
+      ** is owned by the same user that owns the original database.  Otherwise,
+      ** the original owner will not be able to connect. If this process is
+      ** not root, the following fchown() will fail, but we don't care.
+      */
+      fchown(pShmNode->h, sStat.st_uid, sStat.st_gid);
   
       /* Check to see if another process is holding the dead-man switch.
       ** If not, truncate the file to zero length. 
@@ -4896,10 +4903,14 @@ static UnixUnusedFd *findReusableFd(const char *zPath, int flags){
 static int findCreateFileMode(
   const char *zPath,              /* Path of file (possibly) being created */
   int flags,                      /* Flags passed as 4th argument to xOpen() */
-  mode_t *pMode                   /* OUT: Permissions to open file with */
+  mode_t *pMode,                  /* OUT: Permissions to open file with */
+  uid_t *pUid,                    /* OUT: uid to set on the file */
+  gid_t *pGid                     /* OUT: gid to set on the file */
 ){
   int rc = SQLITE_OK;             /* Return Code */
   *pMode = SQLITE_DEFAULT_FILE_PERMISSIONS;
+  *pUid = 0;
+  *pGid = 0;
   if( flags & (SQLITE_OPEN_WAL|SQLITE_OPEN_MAIN_JOURNAL) ){
     char zDb[MAX_PATHNAME+1];     /* Database file path */
     int nDb;                      /* Number of valid bytes in zDb */
@@ -4933,6 +4944,8 @@ static int findCreateFileMode(
 
     if( 0==osStat(zDb, &sStat) ){
       *pMode = sStat.st_mode & 0777;
+      *pUid = sStat.st_uid;
+      *pGid = sStat.st_gid;
     }else{
       rc = SQLITE_IOERR_FSTAT;
     }
@@ -5079,7 +5092,9 @@ static int unixOpen(
 
   if( fd<0 ){
     mode_t openMode;              /* Permissions to create file with */
-    rc = findCreateFileMode(zName, flags, &openMode);
+    uid_t uid;                    /* Userid for the file */
+    gid_t gid;                    /* Groupid for the file */
+    rc = findCreateFileMode(zName, flags, &openMode, &uid, &gid);
     if( rc!=SQLITE_OK ){
       assert( !p->pUnused );
       assert( eType==SQLITE_OPEN_WAL || eType==SQLITE_OPEN_MAIN_JOURNAL );
@@ -5100,6 +5115,16 @@ static int unixOpen(
       rc = unixLogError(SQLITE_CANTOPEN_BKPT, "open", zName);
       goto open_finished;
     }
+
+    /* If this process is running as root and if creating a new rollback
+    ** journal or WAL file, set the ownership of the journal or WAL to be
+    ** the same as the original database.  If we are not running as root,
+    ** then the fchown() call will fail, but that's ok - there is nothing
+    ** we can do about it so just ignore the error.
+    */
+    if( flags & (SQLITE_OPEN_WAL|SQLITE_OPEN_MAIN_JOURNAL) ){
+      fchown(fd, uid, gid);
+    }
   }
   assert( fd>=0 );
   if( pOutFlags ){