Changeset: e90585e60595 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/e90585e60595
Modified Files:
clients/Tests/exports.stable.out
ctest/monetdb5/mal/test_malInclude.c
monetdb5/mal/mal.c
monetdb5/mal/mal.h
monetdb5/mal/mal_authorize.c
monetdb5/mal/mal_authorize.h
monetdb5/mal/mal_embedded.c
monetdb5/mal/mal_prelude.c
monetdb5/mal/mal_prelude.h
monetdb5/mal/mal_session.c
monetdb5/mal/mal_session.h
sql/backends/monet5/sql_scenario.c
sql/backends/monet5/sql_user.c
sql/common/sql_backend.c
sql/common/sql_backend.h
sql/server/sql_mvc.c
sql/server/sql_mvc.h
sql/server/sql_privileges.c
sql/server/sql_privileges.h
tools/mserver/mserver5.c
tools/mserver/shutdowntest.c
Branch: Sep2022
Log Message:
Fix "monetdb create -p ...".
The initial password is passed down many levels of code, and once even
in a pretty hacky way, but it works.
diffs (truncated from 487 to 300 lines):
diff --git a/clients/Tests/exports.stable.out b/clients/Tests/exports.stable.out
--- a/clients/Tests/exports.stable.out
+++ b/clients/Tests/exports.stable.out
@@ -737,7 +737,7 @@ str AUTHdeleteRemoteTableCredentials(con
str AUTHgetPasswordHash(str *ret, Client c, const char *username);
str AUTHgetRemoteTableCredentials(const char *local_table, str *uri, str
*username, str *password);
str AUTHgetUsername(str *ret, Client c);
-str AUTHinitTables(const char *passwd);
+str AUTHinitTables(void);
str AUTHrequireAdmin(Client c);
str AUTHunlockVault(const char *password);
str AUTHverifyPassword(const char *passwd);
@@ -1099,13 +1099,13 @@ const char *lockRef;
const char *lookupRef;
str mal2str(MalBlkPtr mb, int first, int last);
int malAtomSize(int size, const char *name);
-str malBootstrap(char *modules[], bool embedded);
+str malBootstrap(char *modules[], bool embedded, const char *initpasswd);
str malEmbeddedBoot(int workerlimit, int memorylimit, int querytimeout, int
sessionlimit, bool with_mapi_server);
void malEmbeddedReset(void);
_Noreturn void malEmbeddedStop(int status);
str malExtraModulesBoot(Client c, str extraMalModules[], char *mal_scripts);
str malInclude(Client c, const char *name, int listing);
-str malIncludeModules(Client c, char *modules[], int listing, bool embedded);
+str malIncludeModules(Client c, char *modules[], int listing, bool embedded,
const char *initpasswd);
str malIncludeString(Client c, const char *name, str mal, int listing, MALfcn
address);
int malLibraryEnabled(const char *name);
char *malLibraryHowToEnable(const char *name);
@@ -1116,7 +1116,7 @@ MT_Lock mal_contextLock;
MT_Lock mal_copyLock;
MT_Lock mal_delayLock;
_Noreturn void mal_exit(int status);
-int mal_init(char *modules[], bool embedded);
+int mal_init(char *modules[], bool embedded, const char *initpasswd);
void mal_instruction_reset(void);
void mal_module(const char *name, mel_atom *atoms, mel_func *funcs);
void mal_module2(const char *name, mel_atom *atoms, mel_func *funcs, mel_init
initfunc, const char *code);
diff --git a/ctest/monetdb5/mal/test_malInclude.c
b/ctest/monetdb5/mal/test_malInclude.c
--- a/ctest/monetdb5/mal/test_malInclude.c
+++ b/ctest/monetdb5/mal/test_malInclude.c
@@ -25,6 +25,6 @@ main(void)
char *modules[2];
modules[0] = "sql";
modules[1] = 0;
- mal_init(modules, true);
+ mal_init(modules, true, NULL);
return 0;
}
diff --git a/monetdb5/mal/mal.c b/monetdb5/mal/mal.c
--- a/monetdb5/mal/mal.c
+++ b/monetdb5/mal/mal.c
@@ -139,7 +139,7 @@ mal_version(void)
*/
int
-mal_init(char *modules[], bool embedded)
+mal_init(char *modules[], bool embedded, const char *initpasswd)
{
/* Any error encountered here terminates the process
* with a message sent to stderr
@@ -161,7 +161,7 @@ mal_init(char *modules[], bool embedded)
if (initialize_tl_client_key() != 0)
return -1;
- if ((err = AUTHinitTables(NULL)) != MAL_SUCCEED) {
+ if ((err = AUTHinitTables()) != MAL_SUCCEED) {
freeException(err);
return -1;
}
@@ -177,7 +177,7 @@ mal_init(char *modules[], bool embedded)
initNamespace();
initParser();
- err = malBootstrap(modules, embedded);
+ err = malBootstrap(modules, embedded, initpasswd);
if (err != MAL_SUCCEED) {
mal_client_reset();
#ifndef NDEBUG
diff --git a/monetdb5/mal/mal.h b/monetdb5/mal/mal.h
--- a/monetdb5/mal/mal.h
+++ b/monetdb5/mal/mal.h
@@ -72,7 +72,7 @@ mal_export MT_Lock mal_profileLock ;
mal_export MT_Lock mal_copyLock ;
mal_export MT_Lock mal_delayLock ;
-mal_export int mal_init(char *modules[], bool embedded);
+mal_export int mal_init(char *modules[], bool embedded, const char
*initpasswd);
mal_export _Noreturn void mal_exit(int status);
mal_export void mal_reset(void);
mal_export const char *mal_version(void);
diff --git a/monetdb5/mal/mal_authorize.c b/monetdb5/mal/mal_authorize.c
--- a/monetdb5/mal/mal_authorize.c
+++ b/monetdb5/mal/mal_authorize.c
@@ -98,13 +98,11 @@ AUTHcommit(void)
* after the GDK kernel has been initialized.
*/
str
-AUTHinitTables(const char *passwd) {
+AUTHinitTables(void) {
bat bid;
int isNew = 1;
str msg = MAL_SUCCEED;
- (void) passwd;
-
/* skip loading if already loaded */
if (rt_key != NULL && rt_deleted != NULL)
return(MAL_SUCCEED);
diff --git a/monetdb5/mal/mal_authorize.h b/monetdb5/mal/mal_authorize.h
--- a/monetdb5/mal/mal_authorize.h
+++ b/monetdb5/mal/mal_authorize.h
@@ -20,7 +20,7 @@ mal_export str AUTHcheckCredentials(oid
mal_export str AUTHgetUsername(str *ret, Client c);
mal_export str AUTHgetPasswordHash(str *ret, Client c, const char *username);
-mal_export str AUTHinitTables(const char *passwd);
+mal_export str AUTHinitTables(void);
mal_export str AUTHaddRemoteTableCredentials(const char *local_table, const
char *localuser, const char *uri, const char *remoteuser, const char *pass,
bool pw_encrypted);
mal_export str AUTHgetRemoteTableCredentials(const char *local_table, str
*uri, str *username, str *password);
diff --git a/monetdb5/mal/mal_embedded.c b/monetdb5/mal/mal_embedded.c
--- a/monetdb5/mal/mal_embedded.c
+++ b/monetdb5/mal/mal_embedded.c
@@ -83,7 +83,7 @@ malEmbeddedBoot(int workerlimit, int mem
return msg;
}
}
- if ((msg = AUTHinitTables(NULL)) != MAL_SUCCEED)
+ if ((msg = AUTHinitTables()) != MAL_SUCCEED)
return msg;
if (!MCinit())
@@ -124,7 +124,7 @@ malEmbeddedBoot(int workerlimit, int mem
return msg;
}
char *modules[5] = { "embedded", "sql", "generator", "udf" };
- if ((msg = malIncludeModules(c, modules, 0, !with_mapi_server)) !=
MAL_SUCCEED) {
+ if ((msg = malIncludeModules(c, modules, 0, !with_mapi_server, NULL))
!= MAL_SUCCEED) {
MCcloseClient(c);
setClientContext(c_old); // restore context
return msg;
diff --git a/monetdb5/mal/mal_prelude.c b/monetdb5/mal/mal_prelude.c
--- a/monetdb5/mal/mal_prelude.c
+++ b/monetdb5/mal/mal_prelude.c
@@ -71,7 +71,7 @@ mal_module(const char *name, mel_atom *a
}
static char *
-initModule(Client c, const char *name)
+initModule(Client c, const char *name, const char *initpasswd)
{
char *msg = MAL_SUCCEED;
@@ -92,6 +92,12 @@ initModule(Client c, const char *name)
(void)ret;
} else if (pci && pci->token == PATTERNsymbol) {
assert(pci->fcn != NULL);
+ if (strcmp(name, "sql") == 0) {
+ /* HACK ALERT: temporarily use
sqlcontext to pass
+ * the initial password to the prelude
function */
+ assert(c->sqlcontext == NULL);
+ c->sqlcontext = (void *) initpasswd;
+ }
msg = (*pci->fcn)(c, NULL, NULL, NULL);
}
}
@@ -454,7 +460,7 @@ malPrelude(Client c, int listing, int *s
continue;
}
if (!mel_module[i].inits) {
- msg = initModule(c, mel_module[i].name);
+ msg = initModule(c, mel_module[i].name, NULL);
if (msg)
return msg;
}
@@ -472,7 +478,7 @@ malPrelude(Client c, int listing, int *s
}
str
-malIncludeModules(Client c, char *modules[], int listing, bool no_mapi_server)
+malIncludeModules(Client c, char *modules[], int listing, bool no_mapi_server,
const char *initpasswd)
{
str msg;
int sql = -1, mapi = -1;
@@ -492,15 +498,15 @@ malIncludeModules(Client c, char *module
if (mel_module[sql].inits)
msg = mel_module[sql].inits();
else
- msg = initModule(c, "sql");
+ msg = initModule(c, "sql", initpasswd);
if (msg)
return msg;
}
- if (!no_mapi_server && mapi >= 0) {
+ if (!no_mapi_server && mapi >= 0 && initpasswd == NULL) {
if (mel_module[mapi].inits)
msg = mel_module[mapi].inits();
else
- msg = initModule(c, "mapi");
+ msg = initModule(c, "mapi", NULL);
if (msg)
return msg;
}
diff --git a/monetdb5/mal/mal_prelude.h b/monetdb5/mal/mal_prelude.h
--- a/monetdb5/mal/mal_prelude.h
+++ b/monetdb5/mal/mal_prelude.h
@@ -19,6 +19,6 @@ mal_export int mal_startup(void);
mal_export void mal_module(const char *name, mel_atom *atoms, mel_func *funcs);
mal_export void mal_module2(const char *name, mel_atom *atoms, mel_func
*funcs, mel_init initfunc, const char *code);
-mal_export str malIncludeModules(Client c, char *modules[], int listing, bool
embedded);
+mal_export str malIncludeModules(Client c, char *modules[], int listing, bool
embedded, const char *initpasswd);
#endif /* _MAL_PRELUDE_H */
diff --git a/monetdb5/mal/mal_session.c b/monetdb5/mal/mal_session.c
--- a/monetdb5/mal/mal_session.c
+++ b/monetdb5/mal/mal_session.c
@@ -27,7 +27,7 @@
* The startup script is run as user Admin.
*/
str
-malBootstrap(char *modules[], bool embedded)
+malBootstrap(char *modules[], bool embedded, const char *initpasswd)
{
Client c;
str msg = MAL_SUCCEED;
@@ -55,7 +55,7 @@ malBootstrap(char *modules[], bool embed
MCfreeClient(c);
throw(MAL, "malBootstrap", "Failed to create client thread");
}
- if ((msg = malIncludeModules(c, modules, 0, embedded)) != MAL_SUCCEED) {
+ if ((msg = malIncludeModules(c, modules, 0, embedded, initpasswd)) !=
MAL_SUCCEED) {
MCfreeClient(c);
return msg;
}
diff --git a/monetdb5/mal/mal_session.h b/monetdb5/mal/mal_session.h
--- a/monetdb5/mal/mal_session.h
+++ b/monetdb5/mal/mal_session.h
@@ -12,7 +12,7 @@
#include "mal_scenario.h"
#include "mal_resolve.h"
-mal_export str malBootstrap(char *modules[], bool embedded);
+mal_export str malBootstrap(char *modules[], bool embedded, const char
*initpasswd);
mal_export str MSinitClientPrg(Client cntxt, const char *mod, const char *nme);
mal_export void MSscheduleClient(str command, str challenge, bstream *fin,
stream *fout, protocol_version protocol, size_t blocksize);
diff --git a/sql/backends/monet5/sql_scenario.c
b/sql/backends/monet5/sql_scenario.c
--- a/sql/backends/monet5/sql_scenario.c
+++ b/sql/backends/monet5/sql_scenario.c
@@ -79,7 +79,7 @@ int SQLdebug = 0;
static const char *sqlinit = NULL;
static MT_Lock sql_contextLock = MT_LOCK_INITIALIZER(sql_contextLock);
-static str SQLinit(Client c);
+static str SQLinit(Client c, const char *initpasswd);
str
//SQLprelude(void *ret)
@@ -87,6 +87,10 @@ SQLprelude(Client cntxt, MalBlkPtr mb, M
{
str tmp;
Scenario ms, s = getFreeScenario();
+ /* HACK ALERT: temporarily use sqlcontext to pass the initial
+ * password to the prelude function */
+ const char *initpasswd = cntxt->sqlcontext;
+ cntxt->sqlcontext = NULL;
(void) mb;
(void) stk;
@@ -137,7 +141,7 @@ SQLprelude(Client cntxt, MalBlkPtr mb, M
.callbackCmd = MALcallback,
};
- tmp = SQLinit(cntxt);
+ tmp = SQLinit(cntxt, initpasswd);
if (tmp != MAL_SUCCEED) {
TRC_CRITICAL(SQL_PARSER, "Fatal error during initialization:
%s\n", tmp);
if (!GDKembedded()) {
@@ -365,7 +369,7 @@ SQLresetClient(Client c)
MT_Id sqllogthread;
static str
-SQLinit(Client c)
+SQLinit(Client c, const char *initpasswd)
{
const char *debug_str = GDKgetenv("sql_debug");
char *msg = MAL_SUCCEED, *other = MAL_SUCCEED;
@@ -398,7 +402,7 @@ SQLinit(Client c)
if (readonly)
SQLdebug |= 32;
- if ((SQLstore = mvc_init(SQLdebug, GDKinmemory(0) ? store_mem :
store_bat, readonly, single_user)) == NULL) {
+ if ((SQLstore = mvc_init(SQLdebug, GDKinmemory(0) ? store_mem :
store_bat, readonly, single_user, initpasswd)) == NULL) {
MT_lock_unset(&sql_contextLock);
throw(SQL, "SQLinit", SQLSTATE(42000) "Catalogue initialization
failed");
}
diff --git a/sql/backends/monet5/sql_user.c b/sql/backends/monet5/sql_user.c
--- a/sql/backends/monet5/sql_user.c
+++ b/sql/backends/monet5/sql_user.c
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]