Skip to content

Commit f7c4f6d

Browse files
committed
mysql_adaptor: add function mysql_adaptor_get_user_groups_rec
References: DESK-3893, DESK-3984
1 parent 2a51ea9 commit f7c4f6d

File tree

5 files changed

+57
-1
lines changed

5 files changed

+57
-1
lines changed

Makefile.am

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ tzd_files += data/Greenwich.tzd data/Haiti.tzd data/Hawaiian.tzd data/India.tzd
320320
tzd_files += data/Saratov.tzd data/Singapore.tzd data/South_Africa.tzd data/South_Sudan.tzd data/Sri_Lanka.tzd data/Sudan.tzd data/Syria.tzd data/Taipei.tzd data/Tasmania.tzd data/Tocantins.tzd data/Tokyo.tzd data/Tomsk.tzd data/Tonga.tzd data/Transbaikal.tzd data/Turkey.tzd data/Turks_And_Caicos.tzd data/US_Eastern.tzd data/US_Mountain.tzd data/UTC+12.tzd data/UTC+13.tzd data/UTC-02.tzd data/UTC-08.tzd data/UTC-09.tzd data/UTC-11.tzd data/UTC.tzd data/Ulaanbaatar.tzd data/Venezuela.tzd data/Vladivostok.tzd data/Volgograd.tzd data/W__Australia.tzd data/W__Central_Africa.tzd data/W__Europe.tzd data/W__Mongolia.tzd data/West_Asia.tzd data/West_Bank.tzd data/West_Pacific.tzd data/Yakutsk.tzd data/Yukon.tzd
321321
tzd_files += data/windowsZones.xml
322322
header_files = include/gromox/ab_tree.hpp include/gromox/arcfour.hpp include/gromox/archive.hpp include/gromox/atomic.hpp include/gromox/authmgr.hpp include/gromox/bounce_gen.hpp include/gromox/clock.hpp include/gromox/common_types.hpp include/gromox/config_file.hpp include/gromox/contexts_pool.hpp include/gromox/cookie_parser.hpp include/gromox/cryptoutil.hpp include/gromox/database.h include/gromox/database_mysql.hpp include/gromox/dbop.h include/gromox/dcerpc.hpp include/gromox/defs.h include/gromox/double_list.hpp include/gromox/dsn.hpp include/gromox/eid_array.hpp include/gromox/element_data.hpp include/gromox/exmdb_client.hpp include/gromox/exmdb_common_util.hpp include/gromox/exmdb_ext.hpp include/gromox/exmdb_idef.hpp include/gromox/exmdb_provider_client.hpp include/gromox/exmdb_rpc.hpp include/gromox/exmdb_server.hpp include/gromox/ext_buffer.hpp
323-
header_files += include/gromox/fileio.h include/gromox/flusher_common.h include/gromox/freebusy.hpp include/gromox/gab.hpp include/gromox/generic_connection.hpp include/gromox/hook_common.h include/gromox/hpm_common.h include/gromox/http.hpp include/gromox/ical.hpp include/gromox/icase.hpp include/gromox/json.hpp include/gromox/list_file.hpp include/gromox/lzxpress.hpp include/gromox/mail.hpp include/gromox/mail_func.hpp include/gromox/mapi_types.hpp include/gromox/mapidefs.h include/gromox/mapierr.hpp include/gromox/mapitags.hpp include/gromox/midb.hpp include/gromox/midb_agent.hpp include/gromox/mime.hpp include/gromox/mjson.hpp include/gromox/mysql_adaptor.hpp include/gromox/ndr.hpp include/gromox/ntlmssp.hpp include/gromox/oxcmail.hpp include/gromox/oxoabkt.hpp
323+
header_files += include/gromox/fileio.h include/gromox/flat_set.hpp include/gromox/flusher_common.h include/gromox/freebusy.hpp include/gromox/gab.hpp include/gromox/generic_connection.hpp include/gromox/hook_common.h include/gromox/hpm_common.h include/gromox/http.hpp include/gromox/ical.hpp include/gromox/icase.hpp include/gromox/json.hpp include/gromox/list_file.hpp include/gromox/lzxpress.hpp include/gromox/mail.hpp include/gromox/mail_func.hpp include/gromox/mapi_types.hpp include/gromox/mapidefs.h include/gromox/mapierr.hpp include/gromox/mapitags.hpp include/gromox/midb.hpp include/gromox/midb_agent.hpp include/gromox/mime.hpp include/gromox/mjson.hpp include/gromox/mysql_adaptor.hpp include/gromox/ndr.hpp include/gromox/ntlmssp.hpp include/gromox/oxcmail.hpp include/gromox/oxoabkt.hpp
324324
header_files += include/gromox/paths.h include/gromox/pcl.hpp include/gromox/plugin.hpp include/gromox/proc_common.h include/gromox/process.hpp include/gromox/proptag_array.hpp include/gromox/propval.hpp include/gromox/range_set.hpp include/gromox/resource_pool.hpp include/gromox/restriction.hpp include/gromox/rop_util.hpp include/gromox/rpc_types.hpp include/gromox/rule_actions.hpp include/gromox/safeint.hpp include/gromox/simple_tree.hpp include/gromox/sortorder_set.hpp include/gromox/stream.hpp include/gromox/svc_common.h include/gromox/svc_loader.hpp include/gromox/textmaps.hpp include/gromox/threads_pool.hpp include/gromox/tie.hpp include/gromox/tnef.hpp include/gromox/usercvt.hpp include/gromox/util.hpp include/gromox/vcard.hpp include/gromox/xarray2.hpp include/gromox/zcore_client.hpp include/gromox/zcore_rpc.hpp include/gromox/zcore_types.hpp include/gromox/zz_ndr_stack.hpp
325325
if ENABLE_PRIVATE_HEADERS
326326
pkginclude_HEADERS = ${header_files}

exch/mysql_adaptor/sql2.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include <gromox/dbop.h>
3232
#include <gromox/defs.h>
3333
#include <gromox/fileio.h>
34+
#include <gromox/flat_set.hpp>
3435
#include <gromox/mapidefs.h>
3536
#include <gromox/mysql_adaptor.hpp>
3637
#include <gromox/svc_common.h>
@@ -904,6 +905,42 @@ bool mysql_plugin::check_mlist_include(const char *mlist_name,
904905
return false;
905906
}
906907

908+
errno_t mysql_plugin::get_user_groups_rec(const char *username, std::vector<std::string> &groups) try
909+
{
910+
gromox::maybe_flat_set<uint32_t> seen_ml;
911+
auto conn = g_sqlconn_pool.get_wait();
912+
if (!conn)
913+
return EIO;
914+
bool round = 0;
915+
size_t rescan_begin = 0, rescan_end = 0;
916+
for (size_t i = rescan_begin; i < rescan_end || round == 0; ++i) {
917+
auto entity = round != 0 ? groups[i].c_str() : username;
918+
auto qstr = "SELECT DISTINCT m.listname FROM associations AS a "
919+
"INNER JOIN mlists AS m ON a.list_id=m.id "
920+
"WHERE a.username='" + conn->quote(entity) + "'";
921+
if (!conn->query(qstr))
922+
return EIO;
923+
auto result = conn->store_result();
924+
DB_ROW row;
925+
++rescan_begin;
926+
round = 1;
927+
while ((row = result.fetch_row()) != nullptr) {
928+
if (row[1] == nullptr)
929+
continue;
930+
auto list_id = strtoul(row[0], nullptr, 0);
931+
if (seen_ml.contains(list_id))
932+
continue;
933+
seen_ml.emplace(list_id);
934+
groups.emplace_back(row[1]);
935+
++rescan_end;
936+
}
937+
}
938+
return 0;
939+
} catch (const std::bad_alloc &e) {
940+
mlog(LV_ERR, "E-1731: ENOMEM");
941+
return ENOMEM;
942+
}
943+
907944
errno_t mysql_adaptor_meta(const char *u, unsigned int p, sql_meta_result &r)
908945
{
909946
return le_mysql_plugin->meta(u, p, r);
@@ -1055,3 +1092,8 @@ errno_t mysql_adaptor_mda_domain_list(sql_domain_set &v)
10551092
{
10561093
return le_mysql_plugin->mda_domain_list(v);
10571094
}
1095+
1096+
errno_t mysql_adaptor_get_user_groups_rec(const char *user, std::vector<std::string> &groups)
1097+
{
1098+
return le_mysql_plugin->get_user_groups_rec(user, groups);
1099+
}

exch/mysql_adaptor/sql2.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ struct mysql_plugin final {
8080
int mbop_userlist(std::vector<sql_user> &);
8181
gromox::errno_t mda_alias_list(gromox::sql_alias_map &, size_t &);
8282
gromox::errno_t mda_domain_list(gromox::sql_domain_set &);
83+
gromox::errno_t get_user_groups_rec(const char *, std::vector<std::string> &);
8384

8485
protected:
8586
bool mlist_domain_contains(sqlconn *, const char *mlist, const char *account);

include/gromox/flat_set.hpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#pragma once
2+
#if __cplusplus >= 202300L
3+
#include <flat_set>
4+
namespace gromox {
5+
template<typename T> using maybe_flat_set = std::flat_set<T>;
6+
}
7+
#else
8+
# include <set>
9+
namespace gromox {
10+
template<typename T> using maybe_flat_set = std::set<T>;
11+
}
12+
#endif

include/gromox/mysql_adaptor.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ extern GX_EXPORT int mysql_adaptor_domain_list_query(const char *dom);
147147
extern GX_EXPORT int mysql_adaptor_mbop_userlist(std::vector<sql_user> &);
148148
extern GX_EXPORT gromox::errno_t mysql_adaptor_mda_alias_list(gromox::sql_alias_map &, size_t &);
149149
extern GX_EXPORT gromox::errno_t mysql_adaptor_mda_domain_list(gromox::sql_domain_set &);
150+
extern GX_EXPORT gromox::errno_t mysql_adaptor_get_user_groups_rec(const char *, std::vector<std::string> &);
150151

151152
/**
152153
* Determines whether an arbitrary actor can generally open/read the primary

0 commit comments

Comments
 (0)