Changeset: 31b227e1acca for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=31b227e1acca
Modified Files:
clients/mapiclient/dump.c
sql/backends/monet5/sql.c
sql/backends/monet5/sql.h
sql/backends/monet5/sql.mal
sql/scripts/22_clients.sql
Branch: remote_auth
Log Message:
Fix msqldump to support remote table credentials
When dumping a database we need to output the username and the
encrypted password, as we do with database users.
diffs (135 lines):
diff --git a/clients/mapiclient/dump.c b/clients/mapiclient/dump.c
--- a/clients/mapiclient/dump.c
+++ b/clients/mapiclient/dump.c
@@ -870,8 +870,21 @@ describe_table(Mapi mid, const char *sch
if (dump_column_definition(mid, toConsole, schema, tname, NULL,
foreign, hashge))
goto bailout;
- if (type == 5)
- mnstr_printf(toConsole, " ON '%s'", view);
+ if (type == 5) { /* remote table */
+ char *rt_user = NULL;
+ char *rt_hash = NULL;
+ snprintf(query, maxquerylen,
+ "SELECT * FROM
sys.remote_table_credentials('%s.%s')",
+ schema, tname);
+ if ((hdl = mapi_query(mid, query)) == NULL ||
mapi_error(mid))
+ goto bailout;
+ cnt = 0;
+ while(mapi_fetch_row(hdl) != 0) {
+ rt_user = mapi_fetch_field(hdl, 1);
+ rt_hash = mapi_fetch_field(hdl, 2);
+ }
+ mnstr_printf(toConsole, " ON '%s' WITH USER '%s'
ENCRYPTED PASSWORD '%s'", view, rt_user, rt_hash);
+ }
mnstr_printf(toConsole, ";\n");
comment_on(toConsole, "TABLE", schema, tname, NULL, remark);
diff --git a/sql/backends/monet5/sql.c b/sql/backends/monet5/sql.c
--- a/sql/backends/monet5/sql.c
+++ b/sql/backends/monet5/sql.c
@@ -37,6 +37,7 @@
#include "clients.h"
#include "mal_instruction.h"
#include "mal_resource.h"
+#include "mal_authorize.h"
static int
rel_is_table(sql_rel *rel)
@@ -3579,6 +3580,57 @@ sql_sessions_wrap(Client cntxt, MalBlkPt
}
str
+sql_rt_credentials_wrap(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr
pci)
+{
+ BAT *urib = NULL;
+ BAT *unameb = NULL;
+ BAT *hashb = NULL;
+ bat *uri = getArgReference_bat(stk, pci, 0);
+ bat *uname = getArgReference_bat(stk, pci, 1);
+ bat *hash = getArgReference_bat(stk, pci, 2);
+ str *table = getArgReference_str(stk, pci, 3);
+ str uris;
+ str unames;
+ str hashs;
+ str msg = MAL_SUCCEED;
+ (void)mb;
+ (void)cntxt;
+
+ urib = COLnew(0, TYPE_str, 0, TRANSIENT);
+ unameb = COLnew(0, TYPE_str, 0, TRANSIENT);
+ hashb = COLnew(0, TYPE_str, 0, TRANSIENT);
+
+ if (urib == NULL || unameb == NULL || hashb == NULL) {
+ msg = createException(SQL, "sql.remote_table_credentials",
SQLSTATE(HY001) MAL_MALLOC_FAIL);
+ goto bailout;
+ }
+
+ MT_lock_set(&mal_contextLock);
+ if ((msg = AUTHgetRemoteTableCredentials(*table, &uris, &unames,
&hashs)) != MAL_SUCCEED)
+ goto bailout;
+
+ if (BUNappend(urib, uris, FALSE) != GDK_SUCCEED)
+ goto bailout;
+ if (BUNappend(unameb, unames, FALSE) != GDK_SUCCEED)
+ goto bailout;
+ if (BUNappend(hashb, hashs, FALSE) != GDK_SUCCEED)
+ goto bailout;
+ MT_lock_unset(&mal_contextLock);
+ BBPkeepref(*uri = urib->batCacheid);
+ BBPkeepref(*uname = unameb->batCacheid);
+ BBPkeepref(*hash = hashb->batCacheid);
+
+ return MAL_SUCCEED;
+
+ bailout:
+ if (urib) BBPunfix(urib->batCacheid);
+ if (unameb) BBPunfix(unameb->batCacheid);
+ if (hashb) BBPunfix(hashb->batCacheid);
+ return msg;
+}
+
+
+str
sql_querylog_catalog(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
{
int i;
diff --git a/sql/backends/monet5/sql.h b/sql/backends/monet5/sql.h
--- a/sql/backends/monet5/sql.h
+++ b/sql/backends/monet5/sql.h
@@ -131,6 +131,7 @@ sql5_export str dump_cache(Client cntxt,
sql5_export str dump_opt_stats(Client cntxt, MalBlkPtr mb, MalStkPtr stk,
InstrPtr pci);
sql5_export str dump_trace(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr
pci);
sql5_export str sql_sessions_wrap(Client cntxt, MalBlkPtr mb, MalStkPtr stk,
InstrPtr pci);
+sql5_export str sql_rt_credentials_wrap(Client cntxt, MalBlkPtr mb, MalStkPtr
stk, InstrPtr pci);
sql5_export str sql_storage(Client cntxt, MalBlkPtr mb, MalStkPtr stk,
InstrPtr pci);
sql5_export str sql_querylog_catalog(Client cntxt, MalBlkPtr mb, MalStkPtr
stk, InstrPtr pci);
sql5_export str sql_querylog_calls(Client cntxt, MalBlkPtr mb, MalStkPtr stk,
InstrPtr pci);
diff --git a/sql/backends/monet5/sql.mal b/sql/backends/monet5/sql.mal
--- a/sql/backends/monet5/sql.mal
+++ b/sql/backends/monet5/sql.mal
@@ -373,6 +373,10 @@ pattern batsql.password(user:bat[:str])
address db_password_wrap
comment "Return password hash of user";
+pattern rt_credentials(tablename:str) (uri:bat[:str], username:bat[:str],
hash:bat[:str])
+address sql_rt_credentials_wrap
+comment "Return the remote table credentials for the given table";
+
pattern dump_cache()(query:bat[:str],count:bat[:int])
address dump_cache
comment "dump the content of the query cache";
diff --git a/sql/scripts/22_clients.sql b/sql/scripts/22_clients.sql
--- a/sql/scripts/22_clients.sql
+++ b/sql/scripts/22_clients.sql
@@ -8,6 +8,10 @@ create function sys.password_hash (usern
returns string
external name sql.password;
+create function sys.remote_table_credentials (tablename string)
+returns table ("uri" string, "username" string, "hash" string)
+external name sql.rt_credentials;
+
create function sys.sessions()
returns table("user" string, "login" timestamp, "sessiontimeout" bigint,
"lastcommand" timestamp, "querytimeout" bigint, "active" bool)
external name sql.sessions;
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list