Skip to content
Open
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
97 changes: 96 additions & 1 deletion configure
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,7 @@ BISON
MKDIR_P
LN_S
TAR
USE_MDBLOCALES
install_bin
INSTALL_DATA
INSTALL_SCRIPT
Expand Down Expand Up @@ -943,6 +944,7 @@ with_rt
with_libcurl
with_apr_config
with_gnu_ld
with_mdblocales
with_ssl
with_openssl
enable_openssl_redirect
Expand Down Expand Up @@ -1690,6 +1692,7 @@ Optional Packages:
--without-libcurl do not use libcurl
--with-apr-config=PATH path to apr-1-config utility
--with-gnu-ld assume the C compiler uses GNU ld [default=no]
--without-mdblocales build without MDB locales
--with-ssl=LIB use LIB for SSL/TLS support (openssl)
--with-openssl obsolete spelling of --with-ssl=openssl

Expand Down Expand Up @@ -2906,7 +2909,6 @@ PG_PACKAGE_VERSION=14.4




ac_aux_dir=
for ac_dir in config "$srcdir"/config; do
if test -f "$ac_dir/install-sh"; then
Expand Down Expand Up @@ -12124,6 +12126,38 @@ case $INSTALL in
esac


#
# MDB locales
#




# Check whether --with-mdblocales was given.
if test "${with_mdblocales+set}" = set; then :
withval=$with_mdblocales;
case $withval in
yes)

$as_echo "#define USE_MDBLOCALES 1" >>confdefs.h

;;
no)
:
;;
*)
as_fn_error $? "no argument expected for --with-mdblocales option" "$LINENO" 5
;;
esac

else
with_mdblocales=no

fi




if test -z "$TAR"; then
for ac_prog in tar
do
Expand Down Expand Up @@ -12760,6 +12794,56 @@ $as_echo "${python_libspec} ${python_additional_libs}" >&6; }



fi

if test "$with_mdblocales" = yes; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for mdb_setlocale in -lmdblocales" >&5
$as_echo_n "checking for mdb_setlocale in -lmdblocales... " >&6; }
if ${ac_cv_lib_mdblocales_mdb_setlocale+:} false; then :
$as_echo_n "(cached) " >&6
else
ac_check_lib_save_LIBS=$LIBS
LIBS="-lmdblocales $LIBS"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */

/* Override any GCC internal prototype to avoid an error.
Use char because int might match the return type of a GCC
builtin and then its argument prototype would still apply. */
#ifdef __cplusplus
extern "C"
#endif
char mdb_setlocale ();
int
main ()
{
return mdb_setlocale ();
;
return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
ac_cv_lib_mdblocales_mdb_setlocale=yes
else
ac_cv_lib_mdblocales_mdb_setlocale=no
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext
LIBS=$ac_check_lib_save_LIBS
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_mdblocales_mdb_setlocale" >&5
$as_echo "$ac_cv_lib_mdblocales_mdb_setlocale" >&6; }
if test "x$ac_cv_lib_mdblocales_mdb_setlocale" = xyes; then :
cat >>confdefs.h <<_ACEOF
#define HAVE_LIBMDBLOCALES 1
_ACEOF

LIBS="-lmdblocales $LIBS"

else
as_fn_error $? "mdblocales library not found" "$LINENO" 5
fi

fi

if test x"$cross_compiling" = x"yes" && test -z "$with_system_tzdata"; then
Expand Down Expand Up @@ -16981,6 +17065,17 @@ fi

done

fi

if test "$with_mdblocales" = yes; then
ac_fn_c_check_header_mongrel "$LINENO" "mdblocales.h" "ac_cv_header_mdblocales_h" "$ac_includes_default"
if test "x$ac_cv_header_mdblocales_h" = xyes; then :

else
as_fn_error $? "mdblocales header not found." "$LINENO" 5
fi


fi

if test "$with_gssapi" = yes ; then
Expand Down
17 changes: 17 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -1448,6 +1448,14 @@ case $INSTALL in
esac
AC_SUBST(install_bin)

#
# MDB locales
#

PGAC_ARG_BOOL(with, mdblocales, yes, [build without MDB locales],
[AC_DEFINE([USE_MDBLOCALES], 1, [Define to 1 to build with MDB locales. (--with-mdblocales)])])
AC_SUBST(USE_MDBLOCALES)

PGAC_PATH_PROGS(TAR, tar)
AC_PROG_LN_S
AC_PROG_MKDIR_P
Expand Down Expand Up @@ -1606,6 +1614,11 @@ failure. It is possible the compiler isn't looking in the proper directory.
Use --without-zlib to disable zlib support.])])
fi

if test "$with_mdblocales" = yes; then
AC_CHECK_LIB(mdblocales, mdb_setlocale, [],
[AC_MSG_ERROR([mdblocales library not found])])
fi

if test "$enable_external_fts" = yes; then
AC_CHECK_LIB(jansson, jansson_version_str, [],
[AC_MSG_ERROR([jansson library not found or version is too old, version must >= 2.13])])
Expand Down Expand Up @@ -1985,6 +1998,10 @@ if test "$with_lz4" = yes; then
AC_CHECK_HEADERS(lz4.h, [], [AC_MSG_ERROR([lz4.h header file is required for LZ4])])
fi

if test "$with_mdblocales" = yes; then
AC_CHECK_HEADER(mdblocales.h, [], [AC_MSG_ERROR([mdblocales header not found.])])
fi

if test "$with_gssapi" = yes ; then
AC_CHECK_HEADERS(gssapi/gssapi.h, [],
[AC_CHECK_HEADERS(gssapi.h, [], [AC_MSG_ERROR([gssapi.h header file is required for GSSAPI])])])
Expand Down
5 changes: 3 additions & 2 deletions contrib/pax_storage/src/cpp/storage/oper/pax_oper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
*-------------------------------------------------------------------------
*/

#include "common/mdb_locale.h"
#include "storage/oper/pax_oper.h"

#include "comm/cbdb_wrappers.h"
Expand Down Expand Up @@ -588,9 +589,9 @@ static inline bool LocaleIsC(Oid collation) {
return (bool)result;
}

localeptr = setlocale(LC_COLLATE, NULL);
localeptr = SETLOCALE(LC_COLLATE, NULL);
CBDB_CHECK(localeptr, cbdb::CException::ExType::kExTypeCError,
fmt("Invalid locale, fail to `setlocale`, errno: %d", errno));
fmt("Invalid locale, fail to `SETLOCALE`, errno: %d", errno));

if (strcmp(localeptr, "C") == 0 || // cut line
strcmp(localeptr, "POSIX") == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,10 @@ SET SESSION AUTHORIZATION regress_unpriv_user;
SET search_path TO temp_func_test, public;
ALTER FUNCTION functest_E_1(int) NOT LEAKPROOF;
ALTER FUNCTION functest_E_2(int) LEAKPROOF;
ERROR: only superuser can define a leakproof function
ERROR: only superuser or mdb_admin can define a leakproof function
CREATE FUNCTION functest_E_3(int) RETURNS bool LANGUAGE 'sql'
LEAKPROOF AS 'SELECT $1 < 200'; -- fail
ERROR: only superuser can define a leakproof function
ERROR: only superuser or mdb_admin can define a leakproof function
RESET SESSION AUTHORIZATION;
--
-- CALLED ON NULL INPUT | RETURNS NULL ON NULL INPUT | STRICT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,10 @@ SET SESSION AUTHORIZATION regress_unpriv_user;
SET search_path TO temp_func_test, public;
ALTER FUNCTION functest_E_1(int) NOT LEAKPROOF;
ALTER FUNCTION functest_E_2(int) LEAKPROOF;
ERROR: only superuser can define a leakproof function
ERROR: only superuser or mdb_admin can define a leakproof function
CREATE FUNCTION functest_E_3(int) RETURNS bool LANGUAGE 'sql'
LEAKPROOF AS 'SELECT $1 < 200'; -- fail
ERROR: only superuser can define a leakproof function
ERROR: only superuser or mdb_admin can define a leakproof function
RESET SESSION AUTHORIZATION;
--
-- CALLED ON NULL INPUT | RETURNS NULL ON NULL INPUT | STRICT
Expand Down
12 changes: 12 additions & 0 deletions devops/build/automation/cloudberry/scripts/configure-cloudberry.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@
# --enable-cassert
# --enable-debug-extensions
#
# ENABLE_MDBLOCALES - Enable custom locales (true/false, defaults to
# false)
#
# When true, add option:
# --with-mdblocales
#
# Prerequisites:
# - System dependencies must be installed:
# * xerces-c development files
Expand Down Expand Up @@ -132,6 +138,11 @@ if [ "${ENABLE_DEBUG:-false}" = "true" ]; then
--enable-debug-extensions"
fi

CONFIGURE_MDBLOCALES_OPTS="--without-mdblocales"
if [ "${ENABLE_MDBLOCALES:-false}" = "true" ]; then
CONFIGURE_MDBLOCALES_OPTS="--with-mdblocales"
fi

# Configure build
log_section "Configure"
execute_cmd ./configure --prefix=${BUILD_DESTINATION} \
Expand All @@ -158,6 +169,7 @@ execute_cmd ./configure --prefix=${BUILD_DESTINATION} \
--with-ssl=openssl \
--with-openssl \
--with-uuid=e2fs \
${CONFIGURE_MDBLOCALES_OPTS} \
--with-includes=/usr/local/xerces-c/include \
--with-libraries=${BUILD_DESTINATION}/lib || exit 4
log_section_end "Configure"
Expand Down
9 changes: 5 additions & 4 deletions gpcontrib/orafce/others.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include "utils/uuid.h"
#include "orafce.h"
#include "builtins.h"
#include "common/mdb_locale.h"

/*
* Source code for nlssort is taken from postgresql-nls-string
Expand Down Expand Up @@ -322,7 +323,7 @@ _nls_run_strxfrm(text *string, text *locale)
*/
if (!lc_collate_cache)
{
if ((lc_collate_cache = setlocale(LC_COLLATE, NULL)))
if ((lc_collate_cache = SETLOCALE(LC_COLLATE, NULL)))
/* Make a copy of the locale name string. */
#ifdef _MSC_VER
lc_collate_cache = _strdup(lc_collate_cache);
Expand Down Expand Up @@ -364,7 +365,7 @@ _nls_run_strxfrm(text *string, text *locale)
* If setlocale failed, we know the default stayed the same,
* co we can safely elog.
*/
if (!setlocale(LC_COLLATE, locale_str))
if (!SETLOCALE(LC_COLLATE, locale_str))
elog(ERROR, "failed to set the requested LC_COLLATE value [%s]", locale_str);

changed_locale = true;
Expand Down Expand Up @@ -409,7 +410,7 @@ _nls_run_strxfrm(text *string, text *locale)
/*
* Set original locale
*/
if (!setlocale(LC_COLLATE, lc_collate_cache))
if (!SETLOCALE(LC_COLLATE, lc_collate_cache))
elog(FATAL, "failed to set back the default LC_COLLATE value [%s]", lc_collate_cache);
}

Expand All @@ -422,7 +423,7 @@ _nls_run_strxfrm(text *string, text *locale)
/*
* Set original locale
*/
if (!setlocale(LC_COLLATE, lc_collate_cache))
if (!SETLOCALE(LC_COLLATE, lc_collate_cache))
elog(FATAL, "failed to set back the default LC_COLLATE value [%s]", lc_collate_cache);
pfree(locale_str);
}
Expand Down
20 changes: 18 additions & 2 deletions src/backend/catalog/namespace.c
Original file line number Diff line number Diff line change
Expand Up @@ -2971,7 +2971,6 @@ LookupExplicitNamespace(const char *nspname, bool missing_ok)
{
Oid namespaceId;
AclResult aclresult;

/* check for pg_temp alias */
if (strcmp(nspname, "pg_temp") == 0)
{
Expand All @@ -2989,7 +2988,24 @@ LookupExplicitNamespace(const char *nspname, bool missing_ok)
if (missing_ok && !OidIsValid(namespaceId))
return InvalidOid;

aclresult = pg_namespace_aclcheck(namespaceId, GetUserId(), ACL_USAGE);
HeapTuple tuple;
Oid ownerId;

tuple = SearchSysCache1(NAMESPACEOID, ObjectIdGetDatum(namespaceId));
if (!HeapTupleIsValid(tuple))
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_SCHEMA),
errmsg("schema with OID %u does not exist", namespaceId)));

ownerId = ((Form_pg_namespace) GETSTRUCT(tuple))->nspowner;

ReleaseSysCache(tuple);

if (!mdb_admin_allow_bypass_owner_checks(GetUserId(), ownerId)) {
aclresult = pg_namespace_aclcheck(namespaceId, GetUserId(), ACL_USAGE);
} else {
aclresult = ACLCHECK_OK;
}
if (aclresult != ACLCHECK_OK)
aclcheck_error(aclresult, OBJECT_SCHEMA,
nspname);
Expand Down
8 changes: 4 additions & 4 deletions src/backend/commands/alter.c
Original file line number Diff line number Diff line change
Expand Up @@ -1085,7 +1085,8 @@ AlterObjectOwner_internal(Relation rel, Oid objectId, Oid new_ownerId)
if (!superuser())
{
/* must be owner */
if (!has_privs_of_role(GetUserId(), old_ownerId))
if (!has_privs_of_role(GetUserId(), old_ownerId)
&& !mdb_admin_allow_bypass_owner_checks(GetUserId(), old_ownerId))
{
char *objname;
char namebuf[NAMEDATALEN];
Expand All @@ -1105,14 +1106,13 @@ AlterObjectOwner_internal(Relation rel, Oid objectId, Oid new_ownerId)
aclcheck_error(ACLCHECK_NOT_OWNER, get_object_type(classId, objectId),
objname);
}
/* Must be able to become new owner */
check_is_member_of_role(GetUserId(), new_ownerId);

check_mdb_admin_is_member_of_role(GetUserId(), new_ownerId);

/* New owner must have CREATE privilege on namespace */
if (OidIsValid(namespaceId))
{
AclResult aclresult;

aclresult = pg_namespace_aclcheck(namespaceId, new_ownerId,
ACL_CREATE);
if (aclresult != ACLCHECK_OK)
Expand Down
Loading
Loading