From a4f8721edf13bfa86210f063f6a7bc1f55b301f2 Mon Sep 17 00:00:00 2001
From: Danny Auble <da@llnl.gov>
Date: Mon, 9 Jun 2008 19:50:01 +0000
Subject: [PATCH] added better option support to the sacctmgr also added
 correct uid gathering to the association mgr

---
 src/common/assoc_mgr.c                        | 18 ++++++++++++-
 .../mysql/accounting_storage_mysql.c          | 26 ++++++++++++++-----
 src/sacctmgr/account_functions.c              |  5 ++++
 src/sacctmgr/association_functions.c          |  5 +++-
 src/sacctmgr/cluster_functions.c              |  5 ++++
 src/sacctmgr/user_functions.c                 |  8 ++++--
 6 files changed, 57 insertions(+), 10 deletions(-)

diff --git a/src/common/assoc_mgr.c b/src/common/assoc_mgr.c
index f9fb1f62549..fe3914613d9 100644
--- a/src/common/assoc_mgr.c
+++ b/src/common/assoc_mgr.c
@@ -162,7 +162,23 @@ static int _get_local_user_list(void *db_conn, int enforce)
 		} else {
 			return SLURM_SUCCESS;
 		}		
-	} 
+	} else {
+		acct_user_rec_t *user = NULL;
+		struct passwd *passwd_ptr = NULL;
+		ListIterator itr = list_iterator_create(local_user_list);
+		//START_TIMER;
+		while((user = list_next(itr))) {
+			passwd_ptr = getpwnam(user->name);
+			if(passwd_ptr) 
+				user->uid = passwd_ptr->pw_uid;
+			else
+				user->uid = (uint32_t)NO_VAL;
+		}
+		list_iterator_destroy(itr);
+		//END_TIMER2("load_users");
+	}
+	
+
 
 	slurm_mutex_unlock(&local_user_lock);
 	return SLURM_SUCCESS;
diff --git a/src/plugins/accounting_storage/mysql/accounting_storage_mysql.c b/src/plugins/accounting_storage/mysql/accounting_storage_mysql.c
index 8efa22f0ba7..777e6038fee 100644
--- a/src/plugins/accounting_storage/mysql/accounting_storage_mysql.c
+++ b/src/plugins/accounting_storage/mysql/accounting_storage_mysql.c
@@ -3747,7 +3747,7 @@ empty:
 
 	while((row = mysql_fetch_row(result))) {
 		acct_user_rec_t *user = xmalloc(sizeof(acct_user_rec_t));
-		struct passwd *passwd_ptr = NULL;
+/* 		struct passwd *passwd_ptr = NULL; */
 		list_append(user_list, user);
 
 		user->name =  xstrdup(row[USER_REQ_NAME]);
@@ -3755,11 +3755,15 @@ empty:
 		user->admin_level = atoi(row[USER_REQ_AL]);
 		user->qos = atoi(row[USER_REQ_EX]);
 
-		passwd_ptr = getpwnam(user->name);
-		if(passwd_ptr) 
-			user->uid = passwd_ptr->pw_uid;
-		else
-			user->uid = (uint32_t)NO_VAL;
+		/* user id will be set on the client since this could be on a
+		 * different machine where this user may not exist or
+		 * may have a different uid
+		 */
+/* 		passwd_ptr = getpwnam(user->name); */
+/* 		if(passwd_ptr)  */
+/* 			user->uid = passwd_ptr->pw_uid; */
+/* 		else */
+/* 			user->uid = (uint32_t)NO_VAL; */
 		user->coord_accts = list_create(destroy_acct_coord_rec);
 		query = xstrdup_printf("select acct from %s where user='%s' "
 				       "&& deleted=0",
@@ -4270,6 +4274,16 @@ extern List acct_storage_p_get_associations(mysql_conn_t *mysql_conn,
 		xstrcat(extra, " && (");
 		itr = list_iterator_create(assoc_q->id_list);
 		while((object = list_next(itr))) {
+			char *ptr = NULL;
+			long num = strtol(object, &ptr, 10);
+			if ((num == 0) && ptr && ptr[0]) {
+				error("Invalid value for assoc id (%s)",
+				      object);
+				xfree(extra);
+				list_iterator_destroy(itr);
+				return NULL;
+			}
+
 			if(set) 
 				xstrcat(extra, " || ");
 			xstrfmtcat(extra, "id=%s", object);
diff --git a/src/sacctmgr/account_functions.c b/src/sacctmgr/account_functions.c
index f055f4b9bb8..c128420f201 100644
--- a/src/sacctmgr/account_functions.c
+++ b/src/sacctmgr/account_functions.c
@@ -55,6 +55,8 @@ static int _set_cond(int *start, int argc, char *argv[],
 			break;
 		} else if (strncasecmp (argv[i], "WithAssoc", 4) == 0) {
 			acct_cond->with_assocs = 1;
+		} else if(!end && !strncasecmp(argv[i], "where", 5)) {
+			continue;
 		} else if(!end) {
 			addto_char_list(acct_cond->acct_list, argv[i]);
 			addto_char_list(acct_cond->assoc_cond->acct_list,
@@ -118,6 +120,8 @@ static int _set_rec(int *start, int argc, char *argv[],
 		if (strncasecmp (argv[i], "Where", 5) == 0) {
 			i--;
 			break;
+		} else if(!end && !strncasecmp(argv[i], "set", 3)) {
+			continue;
 		} else if(!end) {
 			printf(" Bad format on %s: End your option with "
 			       "an '=' sign\n", argv[i]);
@@ -686,6 +690,7 @@ extern int sacctmgr_list_account(int argc, char *argv[])
 	destroy_acct_account_cond(acct_cond);
 
 	if(!acct_list) {
+		printf(" Problem with query.\n");
 		list_destroy(format_list);
 		return SLURM_ERROR;
 	}
diff --git a/src/sacctmgr/association_functions.c b/src/sacctmgr/association_functions.c
index cec4ace3a0b..fda26526888 100644
--- a/src/sacctmgr/association_functions.c
+++ b/src/sacctmgr/association_functions.c
@@ -48,7 +48,9 @@ static int _set_cond(int *start, int argc, char *argv[],
 
 	for (i=(*start); i<argc; i++) {
 		end = parse_option_end(argv[i]);
-		if(!end) {
+		if(!end && !strncasecmp(argv[i], "where", 5)) {
+			continue;
+		} else if(!end) {
 			addto_char_list(association_cond->id_list, argv[i]);
 			set = 1;
 		} else if (strncasecmp (argv[i], "Id", 1) == 0) {
@@ -235,6 +237,7 @@ extern int sacctmgr_list_association(int argc, char *argv[])
 	destroy_acct_association_cond(assoc_cond);
 	
 	if(!assoc_list) {
+		printf(" Problem with query.\n");
 		list_destroy(format_list);
 		return SLURM_ERROR;
 	}
diff --git a/src/sacctmgr/cluster_functions.c b/src/sacctmgr/cluster_functions.c
index 8a099cbce44..f214ed4d2b5 100644
--- a/src/sacctmgr/cluster_functions.c
+++ b/src/sacctmgr/cluster_functions.c
@@ -53,6 +53,8 @@ static int _set_cond(int *start, int argc, char *argv[],
 		if (strncasecmp (argv[i], "Set", 3) == 0) {
 			i--;
 			break;
+		} else if(!end && !strncasecmp(argv[i], "where", 5)) {
+			continue;
 		} else if(!end) {
 			addto_char_list(cluster_list, argv[i]);
 			set = 1;
@@ -85,6 +87,8 @@ static int _set_rec(int *start, int argc, char *argv[],
 		if (strncasecmp (argv[i], "Where", 5) == 0) {
 			i--;
 			break;
+		} else if(!end && !strncasecmp(argv[i], "set", 3)) {
+			continue;
 		} else if(!end) {
 			printf(" Bad format on %s: End your option with "
 			       "an '=' sign\n", argv[i]);			
@@ -333,6 +337,7 @@ extern int sacctmgr_list_cluster(int argc, char *argv[])
 	destroy_acct_cluster_cond(cluster_cond);
 	
 	if(!cluster_list) {
+		printf(" Problem with query.\n");
 		list_destroy(format_list);
 		return SLURM_ERROR;
 	}
diff --git a/src/sacctmgr/user_functions.c b/src/sacctmgr/user_functions.c
index e1cf404d368..a42924cd670 100644
--- a/src/sacctmgr/user_functions.c
+++ b/src/sacctmgr/user_functions.c
@@ -55,6 +55,8 @@ static int _set_cond(int *start, int argc, char *argv[],
 			break;
 		} else if (strncasecmp (argv[i], "WithAssoc", 4) == 0) {
 			user_cond->with_assocs = 1;
+		} else if(!end && !strncasecmp(argv[i], "where", 5)) {
+			continue;
 		} else if(!end) {
 			addto_char_list(user_cond->user_list, argv[i]);
 			addto_char_list(user_cond->assoc_cond->user_list,
@@ -121,6 +123,8 @@ static int _set_rec(int *start, int argc, char *argv[],
 		if (strncasecmp (argv[i], "Where", 5) == 0) {
 			i--;
 			break;
+		} else if(!end && !strncasecmp(argv[i], "set", 3)) {
+			continue;
 		} else if(!end) {
 			printf(" Bad format on %s: End your option with "
 			       "an '=' sign\n", argv[i]);
@@ -633,8 +637,7 @@ no_default:
 
 	notice_thread_init();
 	if(list_count(user_list)) {
-		rc = acct_storage_g_add_users(db_conn, my_uid, 
-					      user_list);
+		rc = acct_storage_g_add_users(db_conn, my_uid, user_list);
 	}
 
 	if(rc == SLURM_SUCCESS) {
@@ -728,6 +731,7 @@ extern int sacctmgr_list_user(int argc, char *argv[])
 	destroy_acct_user_cond(user_cond);
 
 	if(!user_list) {
+		printf(" Problem with query.\n");
 		list_destroy(format_list);
 		return SLURM_ERROR;
 	}
-- 
GitLab