From 4eafc7409d11bc51c63183642a86734330c9fbeb Mon Sep 17 00:00:00 2001 From: prabatuty Date: Sat, 10 Oct 2009 13:35:20 +0000 Subject: [PATCH] changed sharedmem permissions and file creation umask to 660 --- include/os.h | 1 + src/storage/Connection.cxx | 1 + src/storage/DatabaseManagerImpl.cxx | 14 +++++++------- src/storage/os.cxx | 4 ++++ 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/include/os.h b/include/os.h index 3a343a94..156cdff6 100644 --- a/include/os.h +++ b/include/os.h @@ -188,6 +188,7 @@ class os static bool fileExists(char *fileName); static char* strcasestr(char *s1, const char *s2); static int getNoOfProcessors(); + static mode_t umask(mode_t mask); }; #endif diff --git a/src/storage/Connection.cxx b/src/storage/Connection.cxx index 6f3d48ba..9089b764 100644 --- a/src/storage/Connection.cxx +++ b/src/storage/Connection.cxx @@ -35,6 +35,7 @@ char *Connection::getUserName() } DbRetVal Connection::open(const char *username, const char *password) { + os::umask(002); if (username == NULL || password == NULL ) { printError(ErrBadArg, "Username or password should not be NULL\n"); diff --git a/src/storage/DatabaseManagerImpl.cxx b/src/storage/DatabaseManagerImpl.cxx index d84a1c04..988da4fb 100644 --- a/src/storage/DatabaseManagerImpl.cxx +++ b/src/storage/DatabaseManagerImpl.cxx @@ -118,12 +118,12 @@ DbRetVal DatabaseManagerImpl::createDatabase(const char *name, size_t size) key = Conf::config.getUserDbKey(); } if (!isMmapNeeded || isMmapNeeded && 0 == strcmp(name, SYSTEMDB)) { - shm_id = os::shm_create(key, size, 0666); + shm_id = os::shm_create(key, size, 0660); if (-1 == shm_id) { if (errno == EEXIST) printError(ErrOS, "Shared Memory already exists"); printError(ErrOS, "Shared memory create failed"); - shm_id = os::shm_open(Conf::config.getSysDbKey(), 100, 0666); + shm_id = os::shm_open(Conf::config.getSysDbKey(), 100, 0660); os::shmctl(shm_id, IPC_RMID); delete systemDatabase_; systemDatabase_ = NULL; @@ -141,7 +141,7 @@ DbRetVal DatabaseManagerImpl::createDatabase(const char *name, size_t size) } } sprintf(dbMapFile, "%s/db.chkpt.data", Conf::config.getDbFile()); - fd = open(dbMapFile, O_CREAT | O_RDWR, 0666); + fd = open(dbMapFile, O_CREAT | O_RDWR, 0660); if (-1 == fd) { printError(ErrOS, "Mmap file could not be opened"); return ErrOS; @@ -227,12 +227,12 @@ DbRetVal DatabaseManagerImpl::deleteDatabase(const char *name) shared_memory_id shm_id = 0; if (0 == strcmp(name, SYSTEMDB)) { - shm_id = os::shm_open(Conf::config.getSysDbKey(), 100, 0666); + shm_id = os::shm_open(Conf::config.getSysDbKey(), 100, 0660); os::shmctl(shm_id, IPC_RMID); delete systemDatabase_; systemDatabase_ = NULL; } else { - shm_id = os::shm_open(Conf::config.getUserDbKey(), 100, 0666); + shm_id = os::shm_open(Conf::config.getUserDbKey(), 100, 0660); os::shmctl(shm_id, IPC_RMID); delete db_; db_ = NULL; @@ -299,7 +299,7 @@ DbRetVal DatabaseManagerImpl::openDatabase(const char *name) if ( ( ProcessManager::noThreads == 0 && 0 == strcmp(name, SYSTEMDB) || ProcessManager::noThreads == 1 && 0 != strcmp(name, SYSTEMDB) ) && ( !isMmapNeeded || isMmapNeeded && 0 == strcmp(name, SYSTEMDB) ) ) { - shm_id = os::shm_open(key, size, 0666); + shm_id = os::shm_open(key, size, 0660); if (shm_id == -1 ) { printError(ErrOS, "Shared memory open failed"); @@ -320,7 +320,7 @@ DbRetVal DatabaseManagerImpl::openDatabase(const char *name) 0 != strcmp(name, SYSTEMDB) && isMmapNeeded) { //dbFile to be mmapped sprintf(dbMapFile, "%s/db.chkpt.data", Conf::config.getDbFile()); - fd = open(dbMapFile, O_RDWR, 0666); + fd = open(dbMapFile, O_RDWR, 0660); if (-1 == fd) { printError(ErrOS, "Mmap file could not be opened"); ProcessManager::mutex.releaseLock(-1, false); diff --git a/src/storage/os.cxx b/src/storage/os.cxx index 65f35564..0de96e08 100644 --- a/src/storage/os.cxx +++ b/src/storage/os.cxx @@ -347,4 +347,8 @@ int os::getNoOfProcessors() { return ::sysconf(_SC_NPROCESSORS_ONLN); } +mode_t os::umask(mode_t mask) +{ + return::umask(mask); +} -- 2.11.4.GIT