Changeset: 88142f55f857 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/88142f55f857
Modified Files:
        sql/backends/monet5/sql_gencode.c
        sql/backends/monet5/sql_scenario.c
        sql/backends/monet5/sql_user.c
        sql/backends/monet5/sql_user.h
Branch: triggers
Log Message:

small cleanup/aligning of api's


diffs (166 lines):

diff --git a/sql/backends/monet5/sql_gencode.c 
b/sql/backends/monet5/sql_gencode.c
--- a/sql/backends/monet5/sql_gencode.c
+++ b/sql/backends/monet5/sql_gencode.c
@@ -443,9 +443,15 @@ static int
 
        /* get username / password */
        sql_table *rt = sql_trans_find_table(m->session->tr, table_id);
+       if (!rt) {
+               sql_error(m, 10, SQLSTATE(HY013) MAL_MALLOC_FAIL);
+               return -1;
+       }
        str username = NULL, password = NULL;
-       if (!rt || remote_get(m, table_id, &username, &password) != 0) {
-               sql_error(m, 10, SQLSTATE(HY013) MAL_MALLOC_FAIL);
+       str msg = remote_get(m, table_id, &username, &password);
+       if (msg) {
+               sql_error(m, 10, "%s", msg);
+               GDKfree(msg);
                return -1;
        }
        /* q := remote.connect("uri", "username", "password", "msql"); */
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
@@ -262,23 +262,22 @@ SQLexecPostLoginTriggers(Client c)
 }
 
 static str
-userCheckCredentials( mvc *m, Client c, str passwd, str challenge, str algo)
+userCheckCredentials( mvc *m, Client c, str pwhash, str challenge, str algo)
 {
        oid uid = getUserOIDByName(m, c->username);
 
-       if (strNil(passwd))
+       if (strNil(pwhash))
                throw(INVCRED, "checkCredentials", INVCRED_INVALID_USER " 
'%s'", c->username);
        str passValue = getUserPassword(m, uid);
        if (strNil(passValue))
                throw(INVCRED, "checkCredentials", INVCRED_INVALID_USER " 
'%s'", c->username);
            /* find the corresponding password to the user */
 
-       /* decypher the password (we lose the original tmp here) */
        str pwd = NULL;
-       str tmp = AUTHdecypherValue(&pwd, passValue);
+       str msg = AUTHdecypherValue(&pwd, passValue);
        GDKfree(passValue);
-       if (tmp)
-               return tmp;
+       if (msg)
+               return msg;
 
        /* generate the hash as the client should have done */
        str hash = mcrypt_hashPassword(algo, pwd, challenge);
@@ -287,7 +286,7 @@ userCheckCredentials( mvc *m, Client c, 
                throw(MAL, "checkCredentials", "hash '%s' backend not found", 
algo);
 
        /* and now we have it, compare it to what was given to us */
-       if (strcmp(passwd, hash) == 0) {
+       if (strcmp(pwhash, hash) == 0) {
                free(hash);
                c->user = uid;
                return MAL_SUCCEED;
@@ -305,9 +304,9 @@ userCheckCredentials( mvc *m, Client c, 
                        throw(MAL, "checkCredentials", SQLSTATE(HY013) 
MAL_MALLOC_FAIL);
                hash = mcrypt_hashPassword(algo, encrypted, challenge);
                free(encrypted);
-               if (hash && strcmp(passwd, hash) == 0) {
+               if (hash && strcmp(pwhash, hash) == 0) {
+                       free(hash);
                        c->user = uid;
-                       free(hash);
                        return(MAL_SUCCEED);
                }
                free(hash);
@@ -318,7 +317,7 @@ userCheckCredentials( mvc *m, Client c, 
 }
 
 static char*
-SQLprepareClient(Client c, str passwd, str challenge, str algo)
+SQLprepareClient(Client c, str pwhash, str challenge, str algo)
 {
        mvc *m = NULL;
        backend *be = NULL;
@@ -347,14 +346,14 @@ SQLprepareClient(Client c, str passwd, s
                assert(0);
        }
        MT_lock_unset(&sql_contextLock);
-       if (c->username && passwd) {
+       if (c->username && pwhash) {
 
                if (mvc_trans(m) < 0) {
                        // we have -1 here
                        throw(INVCRED, "checkCredentials", INVCRED_INVALID_USER 
" '%s'", c->username);
                }
 
-               msg = userCheckCredentials( m, c, passwd, challenge, algo);
+               msg = userCheckCredentials( m, c, pwhash, challenge, algo);
                if (msg)
                        goto bailout1;
 
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
@@ -920,8 +920,12 @@ remote_create(mvc *m, sqlid id, const st
                }
        }
        str msg = AUTHcypherValue(&cypher, pwhash);
-       if (pwhash != password)
-               GDKfree(pwhash);
+       if (pwhash != password) {
+               if (!pw_encrypted)
+                       free(pwhash);
+               else
+                       GDKfree(pwhash);
+       }
        if (msg != MAL_SUCCEED)
                return msg;
        log_res = store->table_api.table_insert(m->session->tr, 
remote_user_info, &id, &username, &cypher, NULL);
@@ -931,8 +935,8 @@ remote_create(mvc *m, sqlid id, const st
        return MAL_SUCCEED;
 }
 
-int
-remote_get(mvc *m, sqlid id, str *username, str *password)
+str
+remote_get(mvc *m, sqlid id, str *username, str *pwhash)
 {
        sql_trans *tr = m->session->tr;
        sqlstore *store = tr->store;
@@ -942,18 +946,16 @@ remote_get(mvc *m, sqlid id, str *userna
        oid rid = store->table_api.column_find_row(tr, remote_user_info_id, 
&id, NULL);
 
        if (is_oid_nil(rid))
-               return -1;
+               throw(MAL, "remote", SQLSTATE(42000) "remote table credentials 
not found");
        *username = store->table_api.column_find_value(tr, 
find_sql_column(remote_user_info, "username"), rid);
        if (strNil(*username)) {
                GDKfree(*username);
                *username = GDKstrdup("");
        }
-       str hashpw = store->table_api.column_find_value(tr, 
find_sql_column(remote_user_info, "password"), rid);
-       str err = AUTHdecypherValue(password, hashpw);
-       GDKfree(hashpw);
-       if (err) {
-               GDKfree(err); /* pass up, change api to return str */
-               return -2;
-       }
-       return 0;
+       str cypher = store->table_api.column_find_value(tr, 
find_sql_column(remote_user_info, "password"), rid);
+       str err = AUTHdecypherValue(pwhash, cypher);
+       GDKfree(cypher);
+       if (err)
+               return err;
+       return MAL_SUCCEED;
 }
diff --git a/sql/backends/monet5/sql_user.h b/sql/backends/monet5/sql_user.h
--- a/sql/backends/monet5/sql_user.h
+++ b/sql/backends/monet5/sql_user.h
@@ -23,6 +23,6 @@ extern int monet5_user_get_limits(mvc *m
 extern str monet5_password_hash(mvc *m, const char *username);
 
 extern str remote_create(mvc *sql, sqlid id, const str username, const str 
password, int pw_encrypted);
-extern int remote_get(mvc *sql, sqlid id, str *username, str *password);
+extern str remote_get(mvc *sql, sqlid id, str *username, str *pwhash);
 
 #endif /* _SQL_USER_H_ */
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to