Skip to content
Snippets Groups Projects
Commit 0ba069f1 authored by Danny Auble's avatar Danny Auble
Browse files

ok query for users and accounts work with sshare now

parent 2f948214
No related branches found
No related tags found
No related merge requests found
...@@ -74,10 +74,6 @@ Display associations. ...@@ -74,10 +74,6 @@ Display associations.
\fB\-\-accounts\fR <\fIAccount\fR> \fB\-\-accounts\fR <\fIAccount\fR>
Display accounts. Display accounts.
.TP
\fB\-\-cluster\fR <\fICluster\fR>
Display cluster.
.TP .TP
\fB\-\-help\fP \fB\-\-help\fP
Display a description of sshare options and commands. Display a description of sshare options and commands.
...@@ -128,14 +124,6 @@ The name of a bank account. ...@@ -128,14 +124,6 @@ The name of a bank account.
.RE .RE
.SH "CLUSTER "
.TP
\fICluster\fP
The name of the cluster.
.RE
.SH " USER " .SH " USER "
.TP .TP
......
...@@ -1098,7 +1098,8 @@ extern int assoc_mgr_is_user_acct_coord(void *db_conn, ...@@ -1098,7 +1098,8 @@ extern int assoc_mgr_is_user_acct_coord(void *db_conn,
return 0; return 0;
} }
extern List assoc_mgr_get_shares(List acct_list, List user_list) extern List assoc_mgr_get_shares(void *db_conn,
uid_t uid, List acct_list, List user_list)
{ {
ListIterator itr = NULL; ListIterator itr = NULL;
ListIterator user_itr = NULL; ListIterator user_itr = NULL;
...@@ -1107,22 +1108,42 @@ extern List assoc_mgr_get_shares(List acct_list, List user_list) ...@@ -1107,22 +1108,42 @@ extern List assoc_mgr_get_shares(List acct_list, List user_list)
association_shares_object_t *share = NULL; association_shares_object_t *share = NULL;
List ret_list = NULL; List ret_list = NULL;
char *tmp_char = NULL; char *tmp_char = NULL;
acct_user_rec_t user;
int is_admin=1;
uint16_t private_data = slurm_get_private_data();
if(!assoc_mgr_association_list if(!assoc_mgr_association_list
|| !list_count(assoc_mgr_association_list)) || !list_count(assoc_mgr_association_list))
return NULL; return NULL;
memset(&user, 0, sizeof(acct_user_rec_t));
user.uid = uid;
if(user_list && list_count(user_list)) if(user_list && list_count(user_list))
user_itr = list_iterator_create(user_list); user_itr = list_iterator_create(user_list);
if(acct_list && list_count(acct_list)) if(acct_list && list_count(acct_list))
acct_itr = list_iterator_create(acct_list); acct_itr = list_iterator_create(acct_list);
if (private_data & PRIVATE_DATA_USAGE) {
uint32_t slurm_uid = slurm_get_slurm_user_id();
is_admin = 0;
/* Check permissions of the requesting user.
*/
if((uid == slurm_uid || uid == 0)
|| assoc_mgr_get_admin_level(db_conn, uid)
>= ACCT_ADMIN_OPERATOR)
is_admin = 1;
else {
assoc_mgr_fill_in_user(db_conn, &user, 1, NULL);
}
}
ret_list = list_create(slurm_destroy_association_shares_object); ret_list = list_create(slurm_destroy_association_shares_object);
slurm_mutex_lock(&assoc_mgr_association_lock); slurm_mutex_lock(&assoc_mgr_association_lock);
itr = list_iterator_create(assoc_mgr_association_list); itr = list_iterator_create(assoc_mgr_association_list);
while((assoc = list_next(itr))) { while((assoc = list_next(itr))) {
if(user_itr && assoc->user) { if(user_itr && assoc->user) {
while((tmp_char = list_next(user_itr))) { while((tmp_char = list_next(user_itr))) {
if(!strcasecmp(tmp_char, assoc->user)) if(!strcasecmp(tmp_char, assoc->user))
...@@ -1130,9 +1151,10 @@ extern List assoc_mgr_get_shares(List acct_list, List user_list) ...@@ -1130,9 +1151,10 @@ extern List assoc_mgr_get_shares(List acct_list, List user_list)
} }
list_iterator_reset(user_itr); list_iterator_reset(user_itr);
/* not correct user */ /* not correct user */
if(!tmp_char) if(!tmp_char)
continue; continue;
} }
if(acct_itr) { if(acct_itr) {
while((tmp_char = list_next(acct_itr))) { while((tmp_char = list_next(acct_itr))) {
if(!strcasecmp(tmp_char, assoc->acct)) if(!strcasecmp(tmp_char, assoc->acct))
...@@ -1140,9 +1162,46 @@ extern List assoc_mgr_get_shares(List acct_list, List user_list) ...@@ -1140,9 +1162,46 @@ extern List assoc_mgr_get_shares(List acct_list, List user_list)
} }
list_iterator_reset(acct_itr); list_iterator_reset(acct_itr);
/* not correct account */ /* not correct account */
if(!tmp_char) if(!tmp_char)
continue;
}
if (private_data & PRIVATE_DATA_USAGE) {
if(!is_admin) {
ListIterator itr = NULL;
acct_coord_rec_t *coord = NULL;
if(assoc->user &&
!strcmp(assoc->user, user.name))
goto is_user;
if(!user.coord_accts) {
debug4("This user isn't a coord.");
goto bad_user;
}
if(!assoc->acct) {
debug("No account name given "
"in association.");
goto bad_user;
}
itr = list_iterator_create(user.coord_accts);
while((coord = list_next(itr))) {
if(!strcasecmp(coord->name,
assoc->acct))
break;
}
list_iterator_destroy(itr);
if(coord)
goto is_user;
bad_user:
continue; continue;
}
} }
is_user:
share = xmalloc(sizeof(association_shares_object_t)); share = xmalloc(sizeof(association_shares_object_t));
list_append(ret_list, share); list_append(ret_list, share);
......
...@@ -151,10 +151,12 @@ extern int assoc_mgr_set_cpu_shares(uint32_t procs, uint32_t half_life); ...@@ -151,10 +151,12 @@ extern int assoc_mgr_set_cpu_shares(uint32_t procs, uint32_t half_life);
/* /*
* get the share information from the association list in the form of * get the share information from the association list in the form of
* a list containing association_share_object_t's * a list containing association_share_object_t's
* IN: uid: uid_t of user issuing the request
* IN: acct_list: char * list of accounts you want (NULL for all) * IN: acct_list: char * list of accounts you want (NULL for all)
* IN: user_list: char * list of user names you want (NULL for all) * IN: user_list: char * list of user names you want (NULL for all)
*/ */
extern List assoc_mgr_get_shares(List acct_list, List user_list); extern List assoc_mgr_get_shares(
void *db_conn, uid_t uid, List acct_list, List user_list);
/* /*
* update associations in cache * update associations in cache
......
...@@ -858,7 +858,9 @@ static void _slurm_rpc_get_shares(slurm_msg_t *msg) ...@@ -858,7 +858,9 @@ static void _slurm_rpc_get_shares(slurm_msg_t *msg)
debug2("Processing RPC: REQUEST GET SHARES from uid=%u", debug2("Processing RPC: REQUEST GET SHARES from uid=%u",
(unsigned int)uid); (unsigned int)uid);
resp_msg.tot_shares = assoc_mgr_root_assoc->cpu_shares; resp_msg.tot_shares = assoc_mgr_root_assoc->cpu_shares;
resp_msg.assoc_shares_list = assoc_mgr_get_shares(req_msg->acct_list, resp_msg.assoc_shares_list = assoc_mgr_get_shares(acct_db_conn,
uid,
req_msg->acct_list,
req_msg->user_list); req_msg->user_list);
slurm_msg_t_init(&response_msg); slurm_msg_t_init(&response_msg);
response_msg.address = msg->address; response_msg.address = msg->address;
......
...@@ -52,8 +52,8 @@ uint32_t my_uid = 0; ...@@ -52,8 +52,8 @@ uint32_t my_uid = 0;
static int _set_time_format(char *format); static int _set_time_format(char *format);
static int _get_info(shares_request_msg_t *shares_req, static int _get_info(shares_request_msg_t *shares_req,
shares_response_msg_t **shares_resp); shares_response_msg_t **shares_resp);
static int _addto_id_char_list(List char_list, char *names, bool gid); static int _addto_name_char_list(List char_list, char *names, bool gid);
static char * _convert_to_id(char *name, bool gid); static char * _convert_to_name(int id, bool gid);
static void _print_version( void ); static void _print_version( void );
static void _usage (); static void _usage ();
...@@ -71,7 +71,6 @@ main (int argc, char *argv[]) ...@@ -71,7 +71,6 @@ main (int argc, char *argv[])
static struct option long_options[] = { static struct option long_options[] = {
{"all", 0,0, 'a'}, {"all", 0,0, 'a'},
{"accounts", 1, 0, 'A'}, {"accounts", 1, 0, 'A'},
{"cluster", 1, 0, 'C'},
{"help", 0, 0, 'h'}, {"help", 0, 0, 'h'},
{"no_header", 0, 0, 'n'}, {"no_header", 0, 0, 'n'},
{"parsable", 0, 0, 'p'}, {"parsable", 0, 0, 'p'},
...@@ -85,6 +84,17 @@ main (int argc, char *argv[]) ...@@ -85,6 +84,17 @@ main (int argc, char *argv[])
{NULL, 0, 0, 0} {NULL, 0, 0, 0}
}; };
/* Check to see if we are running a supported accounting plugin */
temp = slurm_get_priority_type();
if(strcasecmp(temp, "priority/multifactor")) {
fprintf (stderr, "You are not running a supported "
"priority plugin\n(%s).\n"
"Only 'priority/multifactor' is supported.\n",
temp);
xfree(temp);
exit(1);
}
xfree(temp);
exit_code = 0; exit_code = 0;
quiet_flag = 0; quiet_flag = 0;
...@@ -136,7 +146,7 @@ main (int argc, char *argv[]) ...@@ -136,7 +146,7 @@ main (int argc, char *argv[])
if(!req_msg.user_list) if(!req_msg.user_list)
req_msg.user_list = req_msg.user_list =
list_create(slurm_destroy_char); list_create(slurm_destroy_char);
_addto_id_char_list(req_msg.user_list, optarg, 0); _addto_name_char_list(req_msg.user_list, optarg, 0);
break; break;
case 't': case 't':
_set_time_format(optarg); _set_time_format(optarg);
...@@ -163,17 +173,49 @@ main (int argc, char *argv[]) ...@@ -163,17 +173,49 @@ main (int argc, char *argv[])
log_alter(opts, 0, NULL); log_alter(opts, 0, NULL);
} }
/* Check to see if we are running a supported accounting plugin */ if(all_users) {
temp = slurm_get_priority_type(); if(req_msg.user_list
if(strcasecmp(temp, "priority/multifactor")) { && list_count(req_msg.user_list)) {
fprintf (stderr, "You are not running a supported " list_destroy(req_msg.user_list);
"priority plugin\n(%s).\n" req_msg.user_list = NULL;
"Only 'priority/multifactor' is supported.\n", }
temp); if(verbosity)
xfree(temp); fprintf(stderr, "Users requested:\n\t: all\n");
exit(1); } else if (verbosity && req_msg.user_list
&& list_count(req_msg.user_list)) {
fprintf(stderr, "Users requested:\n");
ListIterator itr = list_iterator_create(req_msg.user_list);
while((temp = list_next(itr)))
fprintf(stderr, "\t: %s\n", temp);
list_iterator_destroy(itr);
} else if(!req_msg.user_list || !list_count(req_msg.user_list)) {
struct passwd *pwd = getpwuid(getuid());
if(!req_msg.user_list)
req_msg.user_list = list_create(slurm_destroy_char);
temp = xstrdup(pwd->pw_name);
list_append(req_msg.user_list, temp);
if(verbosity) {
fprintf(stderr, "Users requested:\n");
fprintf(stderr, "\t: %s\n", temp);
}
}
if(req_msg.acct_list && list_count(req_msg.acct_list)) {
fprintf(stderr, "Accounts requested:\n");
ListIterator itr = list_iterator_create(req_msg.acct_list);
while((temp = list_next(itr)))
fprintf(stderr, "\t: %s\n", temp);
list_iterator_destroy(itr);
} else {
if(req_msg.acct_list
&& list_count(req_msg.acct_list)) {
list_destroy(req_msg.acct_list);
req_msg.acct_list = NULL;
}
if(verbosity)
fprintf(stderr, "Accounts requested:\n\t: all\n");
} }
xfree(temp);
error_code = _get_info(&req_msg, &resp_msg); error_code = _get_info(&req_msg, &resp_msg);
...@@ -250,7 +292,7 @@ static int _get_info(shares_request_msg_t *shares_req, ...@@ -250,7 +292,7 @@ static int _get_info(shares_request_msg_t *shares_req,
} }
/* returns number of objects added to list */ /* returns number of objects added to list */
static int _addto_id_char_list(List char_list, char *names, bool gid) static int _addto_name_char_list(List char_list, char *names, bool gid)
{ {
int i=0, start=0; int i=0, start=0;
char *name = NULL, *tmp_char = NULL; char *name = NULL, *tmp_char = NULL;
...@@ -283,9 +325,11 @@ static int _addto_id_char_list(List char_list, char *names, bool gid) ...@@ -283,9 +325,11 @@ static int _addto_id_char_list(List char_list, char *names, bool gid)
name = xmalloc((i-start+1)); name = xmalloc((i-start+1));
memcpy(name, names+start, (i-start)); memcpy(name, names+start, (i-start));
//info("got %s %d", name, i-start); //info("got %s %d", name, i-start);
if (!isdigit((int) *name)) { if (isdigit((int) *name)) {
name = _convert_to_id( int id = atoi(name);
name, gid); xfree(name);
name = _convert_to_name(
id, gid);
} }
while((tmp_char = list_next(itr))) { while((tmp_char = list_next(itr))) {
...@@ -315,8 +359,10 @@ static int _addto_id_char_list(List char_list, char *names, bool gid) ...@@ -315,8 +359,10 @@ static int _addto_id_char_list(List char_list, char *names, bool gid)
name = xmalloc((i-start)+1); name = xmalloc((i-start)+1);
memcpy(name, names+start, (i-start)); memcpy(name, names+start, (i-start));
if (!isdigit((int) *name)) { if (isdigit((int) *name)) {
name = _convert_to_id(name, gid); int id = atoi(name);
xfree(name);
name = _convert_to_name(id, gid);
} }
while((tmp_char = list_next(itr))) { while((tmp_char = list_next(itr))) {
...@@ -335,24 +381,24 @@ static int _addto_id_char_list(List char_list, char *names, bool gid) ...@@ -335,24 +381,24 @@ static int _addto_id_char_list(List char_list, char *names, bool gid)
return count; return count;
} }
static char *_convert_to_id(char *name, bool gid) static char *_convert_to_name(int id, bool gid)
{ {
char *name = NULL;
if(gid) { if(gid) {
struct group *grp; struct group *grp;
if (!(grp=getgrnam(name))) { if (!(grp=getgrgid(id))) {
fprintf(stderr, "Invalid group id: %s\n", name); fprintf(stderr, "Invalid group id: %s\n", name);
exit(1); exit(1);
} }
xfree(name); name = xstrdup(grp->gr_name);
name = xstrdup_printf("%d", grp->gr_gid);
} else { } else {
struct passwd *pwd; struct passwd *pwd;
if (!(pwd=getpwnam(name))) { if (!(pwd=getpwuid(id))) {
fprintf(stderr, "Invalid user id: %s\n", name); fprintf(stderr, "Invalid user id: %s\n", name);
exit(1); exit(1);
} }
xfree(name); name = xstrdup(pwd->pw_name);
name = xstrdup_printf("%d", pwd->pw_uid);
} }
return name; return name;
} }
...@@ -376,7 +422,6 @@ sshare [<OPTION>] [<COMMAND>] \n\ ...@@ -376,7 +422,6 @@ sshare [<OPTION>] [<COMMAND>] \n\
Valid <OPTION> values are: \n\ Valid <OPTION> values are: \n\
-a or --all: equivalent to \"all\" command \n\ -a or --all: equivalent to \"all\" command \n\
-A or --accounts: equivalent to \"accounts\" command \n\ -A or --accounts: equivalent to \"accounts\" command \n\
-C or --cluster: equivalent to \"cluster\" command \n\
-h or --help or --usage: equivalent to \"help\" command \n\ -h or --help or --usage: equivalent to \"help\" command \n\
-n or --no_header: no header will be added to the beginning of output \n\ -n or --no_header: no header will be added to the beginning of output \n\
-p or --parsable: output will be '|' delimited with a '|' at the end \n\ -p or --parsable: output will be '|' delimited with a '|' at the end \n\
...@@ -390,19 +435,18 @@ sshare [<OPTION>] [<COMMAND>] \n\ ...@@ -390,19 +435,18 @@ sshare [<OPTION>] [<COMMAND>] \n\
\n\ \n\
\n\ \n\
Valid <COMMAND> values are: \n\ Valid <COMMAND> values are: \n\
--all list all \n\ --all list all \n\
--accounts <Account> list accounts \n\ --accounts <Account> list accounts (comma separated list) \n\
--cluster <Cluster> list cluster \n\ --help print this description of use. \n\
--help print this description of use. \n\ --no_header output without a header \n\
--no_header output without a header \n\
--parsable output will be | delimited with an ending '|'\n\ --parsable output will be | delimited with an ending '|'\n\
--parsable2 output will be | delimited without an ending '|'\n\ --parsable2 output will be | delimited without an ending '|'\n\
--quiet print no messages other than error messages. \n\ --quiet print no messages other than error messages. \n\
--uid list help \n\ --uid list uid (comma separated list) \n\
--usage show help \n\ --usage show help \n\
--user <User> list user \n\ --user <User> list user (comma separated list) \n\
--verbose wordy and windy output. \n\ --verbose wordy and windy output. \n\
--version display tool version number. \n\ --version display tool version number. \n\
\n\ \n\
\n\ \n\
\n\ \n\
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment