Changeset: e301f4673b87 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/e301f4673b87
Modified Files:
        sql/backends/monet5/sql_upgrades.c
Branch: Sep2022
Log Message:

Fix .snapshot password after certain upgrades.
An upgrade that both creates a new .snapshot user and extends the
db_user_info table with (among others) a password column did these in
the wrong order so that the password for .snapshot was NULL.


diffs (66 lines):

diff --git a/sql/backends/monet5/sql_upgrades.c 
b/sql/backends/monet5/sql_upgrades.c
--- a/sql/backends/monet5/sql_upgrades.c
+++ b/sql/backends/monet5/sql_upgrades.c
@@ -5209,6 +5209,50 @@ bailout:
        return err;             /* usually MAL_SUCCEED */
 }
 
+static str
+sql_update_sep2022_sp4(Client c, mvc *sql)
+{
+       size_t bufsize = 1024, pos = 0;
+       char *err = NULL, *buf = GDKmalloc(bufsize);
+       res_table *output;
+       BAT *b;
+
+       (void) sql;
+
+       if (buf == NULL)
+               throw(SQL, __func__, SQLSTATE(HY013) MAL_MALLOC_FAIL);
+
+       /* if the password value for user .snapshot is null in
+        * sys.db_user_info, we need to set it
+        * this can happen if an upgrade is done from a version before the
+        * .snapshot user existed to Sep2022 where the db_user_info table
+        * was extended with new columns */
+       pos = snprintf(buf, bufsize,
+                                  "select \"password\" from sys.db_user_info 
where name = '.snapshot';\n");
+       if ((err = SQLstatementIntern(c, buf, "update", true, false, &output)) 
== MAL_SUCCEED) {
+               if ((b = BATdescriptor(output->cols[0].b)) != NULL) {
+                       if (BATcount(b) > 0) {
+                               BATiter bi = bat_iterator(b);
+                               const char *pwd = BUNtvar(bi, 0);
+                               if (strNil(pwd)) {
+                                       pos = snprintf(buf, bufsize,
+                                                                  "alter user 
\".snapshot\" with encrypted password 
'00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';\n");
+                                       assert(pos < bufsize);
+
+                                       printf("Running database upgrade 
commands:\n%s\n", buf);
+                                       fflush(stdout);
+                                       err = SQLstatementIntern(c, buf, 
"update", true, false, NULL);
+                               }
+                               bat_iterator_end(&bi);
+                       }
+                       BBPunfix(b->batCacheid);
+               }
+               res_table_destroy(output);
+       }
+       GDKfree(buf);
+       return err;             /* usually MAL_SUCCEED */
+}
+
 int
 SQLupgrades(Client c, mvc *m)
 {
@@ -5410,5 +5454,11 @@ SQLupgrades(Client c, mvc *m)
                return -1;
        }
 
+       if ((err = sql_update_sep2022_sp4(c, m)) != NULL) {
+               TRC_CRITICAL(SQL_PARSER, "%s\n", err);
+               freeException(err);
+               return -1;
+       }
+
        return 0;
 }
_______________________________________________
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org

Reply via email to