diff options
author | drh <drh@noemail.net> | 2012-05-31 13:10:49 +0000 |
---|---|---|
committer | drh <drh@noemail.net> | 2012-05-31 13:10:49 +0000 |
commit | ed4668271909964bfa81cc968ccbea5be7f4c15e (patch) | |
tree | fcdaf28fd381676d0f9a0ba93ad3ee56ca31bf3a /src/os_unix.c | |
parent | 1b28b89319c8c0831ed84296cf0c6937f881eee8 (diff) | |
download | sqlite-ed4668271909964bfa81cc968ccbea5be7f4c15e.tar.gz sqlite-ed4668271909964bfa81cc968ccbea5be7f4c15e.zip |
Avoid calling fchown() if the process is not running as root.
FossilOrigin-Name: 70c419a434be77b042a23174483d6a411899eb5d
Diffstat (limited to 'src/os_unix.c')
-rw-r--r-- | src/os_unix.c | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/src/os_unix.c b/src/os_unix.c index f1d3a08a0..0f11613b0 100644 --- a/src/os_unix.c +++ b/src/os_unix.c @@ -262,7 +262,6 @@ struct unixFile { #define UNIXFILE_DELETE 0x20 /* Delete on close */ #define UNIXFILE_URI 0x40 /* Filename might have query parameters */ #define UNIXFILE_NOLOCK 0x80 /* Do no file locking */ -#define UNIXFILE_CHOWN 0x100 /* File ownership was changed */ /* ** Include code that is common to all os_*.c files @@ -308,6 +307,15 @@ static int posixOpen(const char *zFile, int flags, int mode){ return open(zFile, flags, mode); } +/* +** On some systems, calls to fchown() will trigger a message in a security +** log if they come from non-root processes. So avoid calling fchown() if +** we are not running as root. +*/ +static int posixFchown(int fd, uid_t uid, gid_t gid){ + return geteuid() ? 0 : fchown(fd,uid,gid); +} + /* Forward reference */ static int openDirectory(const char*, int*); @@ -419,7 +427,7 @@ static struct unix_syscall { { "rmdir", (sqlite3_syscall_ptr)rmdir, 0 }, #define osRmdir ((int(*)(const char*))aSyscall[19].pCurrent) - { "fchown", (sqlite3_syscall_ptr)fchown, 0 }, + { "fchown", (sqlite3_syscall_ptr)posixFchown, 0 }, #define osFchown ((int(*)(int,uid_t,gid_t))aSyscall[20].pCurrent) { "umask", (sqlite3_syscall_ptr)umask, 0 }, @@ -3944,14 +3952,9 @@ static int unixOpenSharedMemory(unixFile *pDbFd){ /* 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. The - ** if(){..} and the UNIXFILE_CHOWN flag are purely to silence compiler - ** warnings. + ** the original owner will not be able to connect. */ - if( osFchown(pShmNode->h, sStat.st_uid, sStat.st_gid)==0 ){ - pDbFd->ctrlFlags |= UNIXFILE_CHOWN; - } + osFchown(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. @@ -5157,13 +5160,10 @@ static int unixOpen( /* 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. The "if(){}" and - ** the setting of the UNIXFILE_CHOWN flag are purely to silence compiler - ** warnings from gcc. + ** the same as the original database. */ if( flags & (SQLITE_OPEN_WAL|SQLITE_OPEN_MAIN_JOURNAL) ){ - if( osFchown(fd, uid, gid)==0 ){ p->ctrlFlags |= UNIXFILE_CHOWN; } + osFchown(fd, uid, gid); } } assert( fd>=0 ); |