Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions libpromises/conversion.c
Original file line number Diff line number Diff line change
Expand Up @@ -1190,10 +1190,9 @@ gid_t Str2Gid(const char *gidbuff, char *groupcopy, const Promise *pp)
}
else if ((gr = getgrnam(gidbuff)) == NULL)
{
Log(LOG_LEVEL_INFO, "Unknown group '%s' in promise", gidbuff);

if (pp)
{
Log(LOG_LEVEL_INFO, "Unknown group '%s' in promise", gidbuff);
PromiseRef(LOG_LEVEL_INFO, pp);
}

Expand Down
38 changes: 37 additions & 1 deletion libpromises/dbm_lmdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include <file_lib.h>
#include <known_dirs.h>
#include <bootstrap.h>
#include <conversion.h>

#ifdef LMDB

Expand Down Expand Up @@ -537,7 +538,31 @@ DBPriv *DBPrivOpenDB(const char *dbpath, dbid id)
open_flags |= MDB_WRITEMAP;
#endif

rc = LmdbEnvOpen(db->env, dbpath, open_flags, 0644);
#ifndef __MINGW32__
// If effective user is root then change to system group for lmdb files
// otherwise leave group as-is.
uid_t p_euid = geteuid();
gid_t current_gid = getgid();
if (p_euid == 0)
{
gid_t system_gid = Str2Gid(CF_SYSTEM_GROUP, NULL /* no groupcopy */, NULL /* no Promise */);
if (system_gid == CF_SAME_GROUP || system_gid == CF_UNKNOWN_GROUP)
{
Log(LOG_LEVEL_ERR, "Could not get gid_t for CF_SYSTEM_GROUP('%s'), got %d", CF_SYSTEM_GROUP, system_gid);
goto err;
}
else
{
rc = setgid(system_gid);
if (rc)
{
Log(LOG_LEVEL_WARNING, "Could not set system group. setgid(%d): %s", system_gid, strerror(errno));
}
}
}
#endif

rc = LmdbEnvOpen(db->env, dbpath, open_flags, CF_PERMS_DEFAULT);
if (rc)
{
Log(LOG_LEVEL_ERR, "Could not open database %s: %s",
Expand All @@ -546,6 +571,17 @@ DBPriv *DBPrivOpenDB(const char *dbpath, dbid id)
{
HandleLMDBCorruption(db->env, mdb_strerror(rc));
}
#ifndef __MINGW32__
if (p_euid == 0)
{
rc = setgid(current_gid);
if (rc)
{
Log(LOG_LEVEL_ERR, "Could not set group id back to previous value.");
goto err;
}
}
#endif
goto err;
}
if (DB_MAX_READERS > 0)
Expand Down
20 changes: 20 additions & 0 deletions libutils/definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,24 @@
#define CF_BUFSIZE 4096
#define CF_EXPANDSIZE (2 * CF_BUFSIZE)

/*****************************************************************************
* File permissions *
*****************************************************************************/
// 0600 - Read/Write for owner
#define CF_PERMS_DEFAULT S_IRUSR | S_IWUSR
// 0644 - World readable
#define CF_PERMS_SHARED CF_PERMS_DEFAULT | S_IRGRP | S_IROTH

/*****************************************************************************
* File Ownership *
*****************************************************************************/
#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__APPLE__)
# define CF_SYSTEM_GROUP "wheel"
#elif defined(__sun__) || defined(__hpux__)
# define CF_SYSTEM_GROUP "sys"
#elif defined(_AIX)
# define CF_SYSTEM_GROUP "system"
#else
# define CF_SYSTEM_GROUP "root"
#endif
#endif // CFENGINE_DEFINITIONS_H
2 changes: 1 addition & 1 deletion tests/load/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ check_PROGRAMS = db_load lastseen_load lastseen_threaded_load


db_load_SOURCES = db_load.c
db_load_LDADD = ../unit/libdb.la
db_load_LDADD = ../unit/libdb.la ../../libpromises/libpromises.la


lastseen_load_SOURCES = lastseen_load.c \
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ db_test_LDADD = libtest.la ../../libpromises/libpromises.la

db_concurrent_test_SOURCES = db_concurrent_test.c
#db_concurrent_test_CPPFLAGS = $(libdb_la_CPPFLAGS)
db_concurrent_test_LDADD = libdb.la
db_concurrent_test_LDADD = libdb.la ../../libpromises/libpromises.la

lastseen_test_SOURCES = lastseen_test.c \
../../libpromises/item_lib.c \
Expand Down