Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions cdb2api/cdb2api.c
Original file line number Diff line number Diff line change
Expand Up @@ -8817,6 +8817,38 @@ int cdb2_setDbIdentityBlob(cdb2_hndl_tp *hndl)
}
return 0;
}

int cdb2_serialize_db_identity(int *length, void **dta)
{
*length = 0;
*dta = NULL;
if (!iam_identity || !identity_cb)
return 0;
int flags = 0;
if (cdb2_use_optional_identity)
flags |= CDB2_USE_OPTIONAL_IDENTITY;
if (cdb2_non_threaded_identity)
flags |= CDB2_NON_THREADED_IDENTITY;
CDB2SQLQUERY__IdentityBlob *id_blob = identity_cb->getIdentity(NULL, flags);
if (!id_blob)
return -1;
int rc = 0;
if (id_blob->data.data) {
size_t len = protobuf_c_message_get_packed_size((ProtobufCMessage *)id_blob);
void *buf = malloc(len);
if (!buf) {
rc = -1;
} else {
protobuf_c_message_pack((ProtobufCMessage *)id_blob, (uint8_t *)buf);
*dta = buf;
*length = (int)len;
}
}
free(id_blob->principal);
free(id_blob->data.data);
free(id_blob);
return rc;
}
#endif

static cdb2_ssl_sess *cdb2_get_ssl_sessions(cdb2_hndl_tp *hndl)
Expand Down
1 change: 1 addition & 0 deletions cdb2api/cdb2api_int.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ int cdb2_read_line(char *line, int maxlen, COMDB2BUF *s, const char *buf, int *c
#ifdef CDB2API_SERVER
void cdb2_setIdentityBlob(cdb2_hndl_tp *hndl, void *id);
int cdb2_setDbIdentityBlob(cdb2_hndl_tp *hndl);
int cdb2_serialize_db_identity(int *length, void **dta);

void cdb2_hndl_set_max_retries(cdb2_hndl_tp *hndl, int max_retries);
void cdb2_hndl_set_min_retries(cdb2_hndl_tp *hndl, int min_retries);
Expand Down
5 changes: 4 additions & 1 deletion lua/sp.c
Original file line number Diff line number Diff line change
Expand Up @@ -3767,6 +3767,7 @@ static void reset_clnt_after_sp(struct sqlclntstate *clnt,
clnt->dohsql_disable = saved_dohsql_disable;
clnt->osql_max_trans = saved_osql_max_trans;
clnt->current_user.bypass_auth = 0;
clnt->use_db_identity = 0;
}

static int db_udf_error(Lua L)
Expand Down Expand Up @@ -6873,8 +6874,10 @@ static int exec_procedure_int(struct sqlthdstate *thd,

if (IS_SYS(spname)) init_sys_funcs(L);

if (trigger)
if (trigger) {
clnt->current_user.bypass_auth = 1;
clnt->use_db_identity = 1;
}

struct sql_thread *sqlthd = pthread_getspecific(query_info_key);

Expand Down
28 changes: 28 additions & 0 deletions plugins/remsql/fdb_comm.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <gettimeofday_ms.h>

#include "sql.h"
#include "cdb2api_int.h"
#include "fdb_fend.h"
#include "fdb_comm.h"
#include "fdb_bend.h"
Expand Down Expand Up @@ -453,6 +454,12 @@ int fdb_send_open(struct sqlclntstate *clnt, fdb_msg_t *msg, char *cid, fdb_tran
logmsg(LOGMSG_ERROR, "%s: failed to serialize identity\n", __func__);
return rc;
}
} else if (!clnt->authdata && clnt->use_db_identity && fdb_auth_enabled()) {
rc = cdb2_serialize_db_identity(&msg->co.authdtalen, &msg->co.authdta);
if (rc) {
logmsg(LOGMSG_ERROR, "%s: failed to serialize db identity\n", __func__);
return rc;
}
}

cdb2buf_printf(sb, "remsql\n");
Expand Down Expand Up @@ -3344,6 +3351,12 @@ int fdb_send_2pc_begin(struct sqlclntstate *clnt, fdb_msg_t *msg, fdb_tran_t *tr
logmsg(LOGMSG_ERROR, "%s: failed to serialize identity\n", __func__);
return rc;
}
} else if (!clnt->authdata && clnt->use_db_identity && fdb_auth_enabled()) {
rc = cdb2_serialize_db_identity(&msg->tv.authdtalen, &msg->tv.authdta);
if (rc) {
logmsg(LOGMSG_ERROR, "%s: failed to serialize db identity\n", __func__);
return rc;
}
}

assert(trans->seq == 0);
Expand Down Expand Up @@ -3396,6 +3409,12 @@ int fdb_send_begin(struct sqlclntstate *clnt, fdb_msg_t *msg, fdb_tran_t *trans,
logmsg(LOGMSG_ERROR, "%s: failed to serialize identity\n", __func__);
return rc;
}
} else if (!clnt->authdata && clnt->use_db_identity && fdb_auth_enabled()) {
rc = cdb2_serialize_db_identity(&msg->tr.authdtalen, &msg->tr.authdta);
if (rc) {
logmsg(LOGMSG_ERROR, "%s: failed to serialize db identity\n", __func__);
return rc;
}
}
assert(trans->seq == 0);

Expand Down Expand Up @@ -3639,6 +3658,15 @@ int fdb_bend_trans_2pc_begin(COMDB2BUF *sb, fdb_msg_t *msg, svc_callback_arg_t *
}
}
}

if (!rc && msg->tv.authdta && fdb_auth_enabled() && externalComdb2DeSerializeIdentity) {
rc = externalComdb2DeSerializeIdentity(&clnt->authdata, msg->tv.authdtalen, msg->tv.authdta);
if (rc) {
logmsg(LOGMSG_ERROR, "%s: failed to deserialize identity\n", __func__);
return rc;
}
}

/* Send response & version */
fdb_send_tran_2pc_rc(FDB_2PC_VER, tid, rc, NULL, sb);

Expand Down
Loading