extern bool is_user_any_coord(void *db_conn, slurmdb_user_rec_t *user) { xassert(user); if(assoc_mgr_fill_in_user(db_conn, user, 1, NULL) != SLURM_SUCCESS) { error("couldn't get information for this user %s(%d)", user->name, user->uid); return 0; } return (user->coord_accts && list_count(user->coord_accts)); }
/* Get the default account for a user (or NULL if not present) */ static char *_get_default_account(uint32_t user_id) { slurmdb_user_rec_t user; memset(&user, 0, sizeof(slurmdb_user_rec_t)); user.uid = user_id; if (assoc_mgr_fill_in_user(acct_db_conn, &user, 0, NULL) != SLURM_ERROR) { return user.default_acct; } else { return NULL; } }
extern List as_mysql_get_users(mysql_conn_t *mysql_conn, uid_t uid, slurmdb_user_cond_t *user_cond) { char *query = NULL; char *extra = NULL; char *tmp = NULL; List user_list = NULL; ListIterator itr = NULL; char *object = NULL; int set = 0; int i=0, is_admin=1; MYSQL_RES *result = NULL; MYSQL_ROW row; uint16_t private_data = 0; slurmdb_user_rec_t user; /* if this changes you will need to edit the corresponding enum */ char *user_req_inx[] = { "name", "admin_level" }; enum { USER_REQ_NAME, USER_REQ_AL, USER_REQ_COUNT }; if (check_connection(mysql_conn) != SLURM_SUCCESS) return NULL; memset(&user, 0, sizeof(slurmdb_user_rec_t)); user.uid = uid; private_data = slurm_get_private_data(); if (private_data & PRIVATE_DATA_USERS) { if (!(is_admin = is_user_min_admin_level( mysql_conn, uid, SLURMDB_ADMIN_OPERATOR))) { assoc_mgr_fill_in_user( mysql_conn, &user, 1, NULL); } if (!is_admin && !user.name) { debug("User %u has no assocations, and is not admin, " "so not returning any users.", user.uid); return NULL; } } if (!user_cond) { xstrcat(extra, "where deleted=0"); set = 1; goto empty; } if (user_cond->with_deleted) xstrcat(extra, "where (deleted=0 || deleted=1)"); else xstrcat(extra, "where deleted=0"); user_list = _get_other_user_names_to_mod(mysql_conn, uid, user_cond); if (user_list) { if (!user_cond->assoc_cond) user_cond->assoc_cond = xmalloc(sizeof(slurmdb_association_rec_t)); if (!user_cond->assoc_cond->user_list) user_cond->assoc_cond->user_list = user_list; else { list_transfer(user_cond->assoc_cond->user_list, user_list); list_destroy(user_list); } user_list = NULL; } else if ((user_cond->def_acct_list && list_count(user_cond->def_acct_list)) || (user_cond->def_wckey_list && list_count(user_cond->def_wckey_list))) return NULL; if (user_cond->assoc_cond && user_cond->assoc_cond->user_list && list_count(user_cond->assoc_cond->user_list)) { set = 0; xstrcat(extra, " && ("); itr = list_iterator_create(user_cond->assoc_cond->user_list); while ((object = list_next(itr))) { if (set) xstrcat(extra, " || "); xstrfmtcat(extra, "name='%s'", object); set = 1; } list_iterator_destroy(itr); xstrcat(extra, ")"); } if (user_cond->admin_level != SLURMDB_ADMIN_NOTSET) { xstrfmtcat(extra, " && admin_level=%u", user_cond->admin_level); set = 1; } empty: /* This is here to make sure we are looking at only this user * if this flag is set. */ if (!is_admin && (private_data & PRIVATE_DATA_USERS)) { xstrfmtcat(extra, " && name='%s'", user.name); } xfree(tmp); xstrfmtcat(tmp, "%s", user_req_inx[0]); for(i=1; i<USER_REQ_COUNT; i++) { xstrfmtcat(tmp, ", %s", user_req_inx[i]); } query = xstrdup_printf("select %s from %s %s", tmp, user_table, extra); xfree(tmp); xfree(extra); debug3("%d(%s:%d) query\n%s", mysql_conn->conn, THIS_FILE, __LINE__, query); if (!(result = mysql_db_query_ret( mysql_conn, query, 0))) { xfree(query); return NULL; } xfree(query); user_list = list_create(slurmdb_destroy_user_rec); while ((row = mysql_fetch_row(result))) { slurmdb_user_rec_t *user = xmalloc(sizeof(slurmdb_user_rec_t)); list_append(user_list, user); user->name = xstrdup(row[USER_REQ_NAME]); user->admin_level = slurm_atoul(row[USER_REQ_AL]); if (user_cond && user_cond->with_coords) _get_user_coords(mysql_conn, user); } mysql_free_result(result); if (user_cond && (user_cond->with_assocs || (user_cond->assoc_cond && user_cond->assoc_cond->only_defs))) { ListIterator assoc_itr = NULL; slurmdb_user_rec_t *user = NULL; slurmdb_association_rec_t *assoc = NULL; List assoc_list = NULL; /* Make sure we don't get any non-user associations * this is done by at least having a user_list * defined */ if (!user_cond->assoc_cond) user_cond->assoc_cond = xmalloc(sizeof(slurmdb_association_cond_t)); if (!user_cond->assoc_cond->user_list) user_cond->assoc_cond->user_list = list_create(NULL); user_cond->assoc_cond->with_deleted = user_cond->with_deleted; assoc_list = as_mysql_get_assocs( mysql_conn, uid, user_cond->assoc_cond); if (!assoc_list) { error("no associations"); goto get_wckeys; } itr = list_iterator_create(user_list); assoc_itr = list_iterator_create(assoc_list); while ((user = list_next(itr))) { while ((assoc = list_next(assoc_itr))) { if (strcmp(assoc->user, user->name)) continue; /* Set up the default. This is needed * for older versions primarily that * don't have the notion of default * account per cluster. */ if (!user->default_acct && (assoc->is_def == 1)) user->default_acct = xstrdup(assoc->acct); if (!user_cond->with_assocs) { /* We just got the default so no reason to hang around if we aren't getting the associations. */ if (user->default_acct) break; else continue; } if (!user->assoc_list) user->assoc_list = list_create( slurmdb_destroy_association_rec); list_append(user->assoc_list, assoc); list_remove(assoc_itr); } list_iterator_reset(assoc_itr); } list_iterator_destroy(itr); list_iterator_destroy(assoc_itr); list_destroy(assoc_list); } get_wckeys: if (user_cond && (user_cond->with_wckeys || (user_cond->assoc_cond && user_cond->assoc_cond->only_defs))) { ListIterator wckey_itr = NULL; slurmdb_user_rec_t *user = NULL; slurmdb_wckey_rec_t *wckey = NULL; List wckey_list = NULL; slurmdb_wckey_cond_t wckey_cond; memset(&wckey_cond, 0, sizeof(slurmdb_wckey_cond_t)); if (user_cond->assoc_cond) { wckey_cond.user_list = user_cond->assoc_cond->user_list; wckey_cond.cluster_list = user_cond->assoc_cond->cluster_list; wckey_cond.only_defs = user_cond->assoc_cond->only_defs; } wckey_list = as_mysql_get_wckeys(mysql_conn, uid, &wckey_cond); if (!wckey_list) return user_list; itr = list_iterator_create(user_list); wckey_itr = list_iterator_create(wckey_list); while ((user = list_next(itr))) { while ((wckey = list_next(wckey_itr))) { if (strcmp(wckey->user, user->name)) continue; /* Set up the default. This is needed * for older versions primarily that * don't have the notion of default * wckey per cluster. */ if (!user->default_wckey && (wckey->is_def == 1)) user->default_wckey = xstrdup(wckey->name); /* We just got the default so no reason to hang around if we aren't getting the wckeys. */ if (!user_cond->with_wckeys) { /* We just got the default so no reason to hang around if we aren't getting the wckeys. */ if (user->default_wckey) break; else continue; } if (!user->wckey_list) user->wckey_list = list_create( slurmdb_destroy_wckey_rec); list_append(user->wckey_list, wckey); list_remove(wckey_itr); } list_iterator_reset(wckey_itr); /* If a user doesn't have a default wckey (they might not of had track_wckeys on), set it now. */ if (!user->default_wckey) user->default_wckey = xstrdup(""); } list_iterator_destroy(itr); list_iterator_destroy(wckey_itr); list_destroy(wckey_list); } return user_list; }
extern List as_mysql_get_wckeys(mysql_conn_t *mysql_conn, uid_t uid, slurmdb_wckey_cond_t *wckey_cond) { //DEF_TIMERS; char *extra = NULL; char *tmp = NULL; char *cluster_name = NULL; List wckey_list = NULL; int i=0, is_admin=1; uint16_t private_data = 0; slurmdb_user_rec_t user; List use_cluster_list = as_mysql_cluster_list; ListIterator itr; if (!wckey_cond) { xstrcat(extra, " where deleted=0"); goto empty; } if (check_connection(mysql_conn) != SLURM_SUCCESS) return NULL; memset(&user, 0, sizeof(slurmdb_user_rec_t)); user.uid = uid; private_data = slurm_get_private_data(); if (private_data & PRIVATE_DATA_USERS) { if (!(is_admin = is_user_min_admin_level( mysql_conn, uid, SLURMDB_ADMIN_OPERATOR))) { assoc_mgr_fill_in_user( mysql_conn, &user, 1, NULL); } if (!is_admin && !user.name) { debug("User %u has no assocations, and is not admin, " "so not returning any wckeys.", user.uid); return NULL; } } (void) _setup_wckey_cond_limits(wckey_cond, &extra); if (wckey_cond->cluster_list && list_count(wckey_cond->cluster_list)) use_cluster_list = wckey_cond->cluster_list; empty: xfree(tmp); xstrfmtcat(tmp, "t1.%s", wckey_req_inx[i]); for(i=1; i<WCKEY_REQ_COUNT; i++) { xstrfmtcat(tmp, ", t1.%s", wckey_req_inx[i]); } /* this is here to make sure we are looking at only this user * if this flag is set. We also include any accounts they may be * coordinator of. */ if (!is_admin && (private_data & PRIVATE_DATA_USERS)) xstrfmtcat(extra, " && t1.user='******'", user.name); wckey_list = list_create(slurmdb_destroy_wckey_rec); if (use_cluster_list == as_mysql_cluster_list) slurm_mutex_lock(&as_mysql_cluster_list_lock); //START_TIMER; itr = list_iterator_create(use_cluster_list); while ((cluster_name = list_next(itr))) { if (_cluster_get_wckeys(mysql_conn, wckey_cond, tmp, extra, cluster_name, wckey_list) != SLURM_SUCCESS) { list_destroy(wckey_list); wckey_list = NULL; break; } } list_iterator_destroy(itr); if (use_cluster_list == as_mysql_cluster_list) slurm_mutex_unlock(&as_mysql_cluster_list_lock); xfree(tmp); xfree(extra); //END_TIMER2("get_wckeys"); return wckey_list; }
static uint32_t _get_wckeyid(mysql_conn_t *mysql_conn, char **name, uid_t uid, char *cluster, uint32_t associd) { uint32_t wckeyid = 0; if (slurm_get_track_wckey()) { /* Here we are looking for the wckeyid if it doesn't * exist we will create one. We don't need to check * if it is good or not. Right now this is the only * place things are created. We do this only on a job * start, not on a job submit since we don't want to * slow down getting the db_index back to the * controller. */ slurmdb_wckey_rec_t wckey_rec; char *user = NULL; /* since we are unable to rely on uids here (someone could not have there uid in the system yet) we must first get the user name from the associd */ if (!(user = _get_user_from_associd( mysql_conn, cluster, associd))) { error("No user for associd %u", associd); goto no_wckeyid; } /* get the default key */ if (!*name) { slurmdb_user_rec_t user_rec; memset(&user_rec, 0, sizeof(slurmdb_user_rec_t)); user_rec.uid = NO_VAL; user_rec.name = user; if (assoc_mgr_fill_in_user(mysql_conn, &user_rec, 1, NULL) != SLURM_SUCCESS) { error("No user by name of %s assoc %u", user, associd); xfree(user); goto no_wckeyid; } if (user_rec.default_wckey) *name = xstrdup_printf("*%s", user_rec.default_wckey); else *name = xstrdup_printf("*"); } memset(&wckey_rec, 0, sizeof(slurmdb_wckey_rec_t)); wckey_rec.name = (*name); wckey_rec.uid = NO_VAL; wckey_rec.user = user; wckey_rec.cluster = cluster; if (assoc_mgr_fill_in_wckey(mysql_conn, &wckey_rec, ACCOUNTING_ENFORCE_WCKEYS, NULL) != SLURM_SUCCESS) { List wckey_list = NULL; slurmdb_wckey_rec_t *wckey_ptr = NULL; wckey_list = list_create(slurmdb_destroy_wckey_rec); wckey_ptr = xmalloc(sizeof(slurmdb_wckey_rec_t)); wckey_ptr->name = xstrdup((*name)); wckey_ptr->user = xstrdup(user); wckey_ptr->cluster = xstrdup(cluster); list_append(wckey_list, wckey_ptr); /* info("adding wckey '%s' '%s' '%s'", */ /* wckey_ptr->name, wckey_ptr->user, */ /* wckey_ptr->cluster); */ /* we have already checked to make sure this was the slurm user before calling this */ if (as_mysql_add_wckeys(mysql_conn, slurm_get_slurm_user_id(), wckey_list) == SLURM_SUCCESS) acct_storage_p_commit(mysql_conn, 1); /* If that worked lets get it */ assoc_mgr_fill_in_wckey(mysql_conn, &wckey_rec, ACCOUNTING_ENFORCE_WCKEYS, NULL); list_destroy(wckey_list); } xfree(user); /* info("got wckeyid of %d", wckey_rec.id); */ wckeyid = wckey_rec.id; } no_wckeyid: return wckeyid; }