static int monet5_drop_user(ptr _mvc, str user) { mvc *m = (mvc *) _mvc; oid rid; sql_schema *sys; sql_table *users; sql_column *users_name; str err; Client c = MCgetClient(m->clientid); err = AUTHremoveUser(c, user); if (err !=MAL_SUCCEED) { (void) sql_error(m, 02, "DROP USER: %s", getExceptionMessage(err)); _DELETE(err); return FALSE; } sys = find_sql_schema(m->session->tr, "sys"); users = find_sql_table(sys, "db_user_info"); users_name = find_sql_column(users, "name"); rid = table_funcs.column_find_row(m->session->tr, users_name, user, NULL); if (!is_oid_nil(rid)) table_funcs.table_delete(m->session->tr, users, rid); /* FIXME: We have to ignore this inconsistency here, because the * user was already removed from the system authorisation. Once * we have warnings, we could issue a warning about this * (seemingly) inconsistency between system and sql shadow * administration. */ return TRUE; }
static void monet5_freecode(int clientid, backend_code code, backend_stack stk, int nr, char *name) { str msg; (void) code; (void) stk; (void) nr; (void) clientid; msg = SQLCacheRemove(MCgetClient(clientid), name); if (msg) GDKfree(msg); /* do something with error? */ #ifdef _SQL_SCENARIO_DEBUG mnstr_printf(GDKout, "#monet5_free:%d\n", nr); #endif }
static int monet5_find_user(ptr mp, str user) { BAT *uid, *nme; BUN p; mvc *m = (mvc *) mp; Client c = MCgetClient(m->clientid); str err; if ((err = AUTHgetUsers(&uid, &nme, c)) != MAL_SUCCEED) { _DELETE(err); return -1; } p = BUNfnd(nme, user); BBPunfix(uid->batCacheid); BBPunfix(nme->batCacheid); /* yeah, I would prefer to return something different too */ return (p == BUN_NONE ? -1 : 1); }
static str monet5_create_user(ptr _mvc, str user, str passwd, char enc, str fullname, sqlid schema_id, sqlid grantorid) { mvc *m = (mvc *) _mvc; oid uid = 0; bat bid = 0; str ret; sqlid user_id; str pwd; sql_schema *s = find_sql_schema(m->session->tr, "sys"); sql_table *db_user_info, *auths; Client c = MCgetClient(m->clientid); if (!enc) { pwd = mcrypt_BackendSum(passwd, strlen(passwd)); if (pwd == NULL) { BBPunfix(bid); throw(MAL, "sql.create_user", SQLSTATE(42000) "Crypt backend hash not found"); } } else { pwd = passwd; } /* add the user to the M5 authorisation administration */ ret = AUTHaddUser(&uid, c, user, pwd); if (!enc) free(pwd); if (ret != MAL_SUCCEED) return ret; user_id = store_next_oid(); db_user_info = find_sql_table(s, "db_user_info"); auths = find_sql_table(s, "auths"); table_funcs.table_insert(m->session->tr, db_user_info, user, fullname, &schema_id); table_funcs.table_insert(m->session->tr, auths, &user_id, user, &grantorid); return NULL; }