str sql_create_role(mvc *m, str auth, int grantor) { oid id; sql_schema *sys = find_sql_schema(m->session->tr, "sys"); sql_table *auths = find_sql_table(sys, "auths"); sql_column *auth_name = find_sql_column(auths, "name"); if (table_funcs.column_find_row(m->session->tr, auth_name, auth, NULL) != oid_nil) return sql_message("0P000!CREATE ROLE: role '%s' already exists", auth); id = store_next_oid(); table_funcs.table_insert(m->session->tr, auths, &id, auth, &grantor); return NULL; }
/*Function to create a connection*/ int sql_trans_connect_catalog(sql_trans *tr, const char *server, int port, const char *db, const char *db_alias, const char *user, const char *passwd, const char *lang) { int id = store_next_oid(), port_l = port; sql_schema *s = find_sql_schema(tr, "sys"); sql_table *t = find_sql_table(s, "connections"); sql_column *c_server = find_sql_column(t, "server"); sql_column *c_db = find_sql_column(t, "db"); sql_column *c_db_alias = find_sql_column(t, "db_alias"); if ((table_funcs.column_find_row(tr, c_server, server, c_db, db, NULL) == oid_nil) && (table_funcs.column_find_row(tr, c_db_alias, db_alias, NULL) == oid_nil)) { table_funcs.table_insert(tr, t, &id, server, &port_l, db, db_alias, user, passwd, lang); return id; } return 0; }
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; }