From 715f08f3e9ef7fb72ffec8535b04abcc9c45caae Mon Sep 17 00:00:00 2001
From: Moe Jette <jette1@llnl.gov>
Date: Thu, 31 Jul 2008 18:48:19 +0000
Subject: [PATCH] Convert getpw* and getgr* functions to use reentrant
 versions. Also insure we xfree output of uid_to_string() and gid_to_string().

---
 src/api/job_info.c                            |  17 +-
 src/common/assoc_mgr.c                        |  29 +-
 src/database/gold_interface.c                 |   6 +-
 .../gold/accounting_storage_gold.c            |   9 +-
 .../mysql/accounting_storage_mysql.c          | 248 +++++++-----------
 .../slurmdbd/accounting_storage_slurmdbd.c    |   7 +-
 src/plugins/jobcomp/filetxt/jobcomp_filetxt.c |  20 +-
 src/plugins/jobcomp/mysql/jobcomp_mysql.c     |  24 +-
 src/plugins/jobcomp/pgsql/jobcomp_pgsql.c     |  24 +-
 .../bluegene/plugin/bg_record_functions.c     |  20 +-
 src/slurmdbd/proc_req.c                       |   7 +-
 src/slurmdbd/read_config.c                    |   8 +-
 12 files changed, 173 insertions(+), 246 deletions(-)

diff --git a/src/api/job_info.c b/src/api/job_info.c
index c4f3de3ce35..c94e446ed54 100644
--- a/src/api/job_info.c
+++ b/src/api/job_info.c
@@ -124,8 +124,7 @@ extern char *
 slurm_sprint_job_info ( job_info_t * job_ptr, int one_liner )
 {
 	int i, j;
-	char time_str[32], select_buf[122], *user_name;
-	struct group *group_info = NULL;
+	char time_str[32], select_buf[122], *group_name, *user_name;
 	char tmp1[128], tmp2[128], *tmp3_ptr;
 	char tmp_line[512];
 	char *ionodes = NULL;
@@ -146,16 +145,12 @@ slurm_sprint_job_info ( job_info_t * job_ptr, int one_liner )
 	snprintf(tmp_line, sizeof(tmp_line), 
 		"JobId=%u UserId=%s(%u) ", 
 		job_ptr->job_id, user_name, job_ptr->user_id);
-	out = xstrdup(tmp_line);
 	xfree(user_name);
-	group_info = getgrgid((gid_t) job_ptr->group_id );
-	if ( group_info && group_info->gr_name[ 0 ] ) {
-		snprintf(tmp_line, sizeof(tmp_line), "GroupId=%s(%u)",
-			 group_info->gr_name, job_ptr->group_id );
-	} else {
-		snprintf(tmp_line, sizeof(tmp_line), "GroupId=(%u)", 
-			job_ptr->group_id );
-	}
+	out = xstrdup(tmp_line);
+	group_name = gid_to_string((gid_t) job_ptr->group_id);
+	snprintf(tmp_line, sizeof(tmp_line), "GroupId=%s(%u)",
+		 group_name, job_ptr->group_id);
+	xfree(group_name);
 	xstrcat(out, tmp_line);
 	if (one_liner)
 		xstrcat(out, " ");
diff --git a/src/common/assoc_mgr.c b/src/common/assoc_mgr.c
index 39a03431281..3dd7e690832 100644
--- a/src/common/assoc_mgr.c
+++ b/src/common/assoc_mgr.c
@@ -40,6 +40,7 @@
 #include <sys/types.h>
 #include <pwd.h>
 
+#include "src/common/uid.h"
 #include "src/common/xstring.h"
 #include "src/slurmdbd/read_config.h"
 
@@ -74,11 +75,11 @@ static int _set_assoc_parent_and_user(acct_association_rec_t *assoc)
 		list_iterator_destroy(itr);
 	}
 	if(assoc->user) {
-		struct passwd *passwd_ptr = getpwnam(assoc->user);
-		if(passwd_ptr) 
-			assoc->uid = passwd_ptr->pw_uid;
+		uid_t pw_uid = uid_from_string(assoc->user);
+		if(pw_uid == (uid_t) -1)
+			assoc->uid = (uint32_t)NO_VAL;
 		else
-			assoc->uid = (uint32_t)NO_VAL;	
+			assoc->uid = pw_uid;	
 	} else {
 		assoc->uid = (uint32_t)NO_VAL;	
 	}
@@ -191,15 +192,14 @@ static int _get_local_user_list(void *db_conn, int enforce)
 		}		
 	} 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
+			uid_t pw_uid = uid_from_string(user->name);
+			if(pw_uid == (uid_t) -1)
 				user->uid = (uint32_t)NO_VAL;
+			else
+				user->uid = pw_uid;
 		}
 		list_iterator_destroy(itr);
 		//END_TIMER2("load_users");
@@ -658,7 +658,7 @@ extern int assoc_mgr_update_local_users(acct_update_object_t *update)
 		
 	ListIterator itr = NULL;
 	int rc = SLURM_SUCCESS;
-	struct passwd *passwd_ptr = NULL;
+	uid_t pw_uid;
 
 	if(!local_user_list)
 		return SLURM_SUCCESS;
@@ -702,12 +702,11 @@ extern int assoc_mgr_update_local_users(acct_update_object_t *update)
 				//rc = SLURM_ERROR;
 				break;
 			}
-			passwd_ptr = getpwnam(object->name);
-			if(passwd_ptr) 
-				object->uid = passwd_ptr->pw_uid;
-			else
+			pw_uid = uid_from_string(object->name);
+			if(pw_uid == (uid_t) -1) 
 				object->uid = NO_VAL;
-
+			else
+				object->uid = pw_uid;
 			list_append(local_user_list, object);
 			break;
 		case ACCT_REMOVE_USER:
diff --git a/src/database/gold_interface.c b/src/database/gold_interface.c
index f39ad68a090..080f4e495af 100644
--- a/src/database/gold_interface.c
+++ b/src/database/gold_interface.c
@@ -319,7 +319,7 @@ extern gold_response_t *get_gold_response(gold_request_t *gold_request)
 	unsigned int dlen = SHA_DIGEST_LENGTH;
 	unsigned char digest[dlen];
 	unsigned char signature[slen];
-	char c;
+	char c, *user_name;
 	char *object = NULL;
 	char *action = NULL;
 	char *innerds = NULL;
@@ -431,10 +431,12 @@ extern gold_response_t *get_gold_response(gold_request_t *gold_request)
 	}
 	list_iterator_destroy(itr);
 
+	user_name = uid_to_string(geteuid());
 	xstrfmtcat(gold_request->body,
 		   "<Body><Request action=\"%s\" actor=\"%s\">"
 		   "<Object>%s</Object>",
-		   action, uid_to_string(geteuid()), object);
+		   action, user_name, object);
+	xfree(user_name);
 	if(innerds) {
 		xstrcat(gold_request->body, innerds);
 		xfree(innerds);
diff --git a/src/plugins/accounting_storage/gold/accounting_storage_gold.c b/src/plugins/accounting_storage/gold/accounting_storage_gold.c
index bc1ee12af98..2d5a9db4418 100644
--- a/src/plugins/accounting_storage/gold/accounting_storage_gold.c
+++ b/src/plugins/accounting_storage/gold/accounting_storage_gold.c
@@ -3208,11 +3208,14 @@ extern List jobacct_storage_p_get_jobs(void *db_conn,
 						size_t bufsize;
 						char *buffer;
 						int rc;
-						bufsize = sysconf(_SC_GETPW_R_SIZE_MAX);
+						bufsize = sysconf(
+							_SC_GETPW_R_SIZE_MAX);
 						buffer = xmalloc(bufsize);
-						rc = getpwnam_r(account_rec.user,
+						rc = getpwnam_r(account_rec.
+								user,
 								&pwd, buffer,
-								bufsize, &result);
+								bufsize, 
+								&result);
 						if (rc != 0)
 							result = NULL;
 						job->user = xstrdup(account_rec.
diff --git a/src/plugins/accounting_storage/mysql/accounting_storage_mysql.c b/src/plugins/accounting_storage/mysql/accounting_storage_mysql.c
index 456f03aaec6..304fdf2b707 100644
--- a/src/plugins/accounting_storage/mysql/accounting_storage_mysql.c
+++ b/src/plugins/accounting_storage/mysql/accounting_storage_mysql.c
@@ -1759,7 +1759,6 @@ extern int acct_storage_p_add_users(mysql_conn_t *mysql_conn, uint32_t uid,
 	int rc = SLURM_SUCCESS;
 	acct_user_rec_t *object = NULL;
 	char *cols = NULL, *vals = NULL, *query = NULL, *txn_query = NULL;
-	struct passwd *pw = NULL;
 	time_t now = time(NULL);
 	char *user = NULL;
 	char *extra = NULL;
@@ -1769,10 +1768,7 @@ extern int acct_storage_p_add_users(mysql_conn_t *mysql_conn, uint32_t uid,
 	if(_check_connection(mysql_conn) != SLURM_SUCCESS)
 		return SLURM_ERROR;
 
-	if((pw=getpwuid(uid))) {
-		user = pw->pw_name;
-	}
-
+	user_name = uid_to_string((uid_t) uid);
 	itr = list_iterator_create(user_list);
 	while((object = list_next(itr))) {
 		if(!object->name || !object->default_acct) {
@@ -1847,7 +1843,7 @@ extern int acct_storage_p_add_users(mysql_conn_t *mysql_conn, uint32_t uid,
 			xstrfmtcat(txn_query, 	
 				   ", (%d, %u, '%s', '%s', \"%s\")",
 				   now, DBD_ADD_USERS, object->name,
-				   user, extra);
+				   user_name, extra);
 		else
 			xstrfmtcat(txn_query, 	
 				   "insert into %s "
@@ -1855,7 +1851,7 @@ extern int acct_storage_p_add_users(mysql_conn_t *mysql_conn, uint32_t uid,
 				   "values (%d, %u, '%s', '%s', \"%s\")",
 				   txn_table,
 				   now, DBD_ADD_USERS, object->name,
-				   user, extra);
+				   user_name, extra);
 		xfree(extra);
 		
 		if(!object->assoc_list)
@@ -1864,6 +1860,7 @@ extern int acct_storage_p_add_users(mysql_conn_t *mysql_conn, uint32_t uid,
 		list_transfer(assoc_list, object->assoc_list);
 	}
 	list_iterator_destroy(itr);
+	xfree(user_name);
 
 	if(rc != SLURM_ERROR) {
 		if(txn_query) {
@@ -1900,7 +1897,6 @@ extern int acct_storage_p_add_coord(mysql_conn_t *mysql_conn, uint32_t uid,
 #ifdef HAVE_MYSQL
 	char *query = NULL, *user = NULL, *acct = NULL;
 	char *user_name = NULL, *txn_query = NULL;
-	struct passwd *pw = NULL;
 	ListIterator itr, itr2;
 	time_t now = time(NULL);
 	int rc = SLURM_SUCCESS;
@@ -1917,10 +1913,7 @@ extern int acct_storage_p_add_coord(mysql_conn_t *mysql_conn, uint32_t uid,
 	if(_check_connection(mysql_conn) != SLURM_SUCCESS)
 		return SLURM_ERROR;
 
-	if((pw=getpwuid(uid))) {
-		user_name = pw->pw_name;
-	}
-
+	user_name = uid_to_string((uid_t) uid);
 	itr = list_iterator_create(user_cond->assoc_cond->user_list);
 	itr2 = list_iterator_create(acct_list);
 	while((user = list_next(itr))) {
@@ -1953,10 +1946,10 @@ extern int acct_storage_p_add_coord(mysql_conn_t *mysql_conn, uint32_t uid,
 		}
 		list_iterator_reset(itr2);
 	}
+	xfree(user_name);
 	list_iterator_destroy(itr);
 	list_iterator_destroy(itr2);
 
-
 	if(query) {
 		xstrfmtcat(query, 
 			   " on duplicate key update mod_time=%d, deleted=0;%s",
@@ -1997,9 +1990,8 @@ extern int acct_storage_p_add_accts(mysql_conn_t *mysql_conn, uint32_t uid,
 	int rc = SLURM_SUCCESS;
 	acct_account_rec_t *object = NULL;
 	char *cols = NULL, *vals = NULL, *query = NULL, *txn_query = NULL;
-	struct passwd *pw = NULL;
 	time_t now = time(NULL);
-	char *user = NULL;
+	char *user_name = NULL;
 	char *extra = NULL;
 	int affect_rows = 0;
 	List assoc_list = list_create(destroy_acct_association_rec);
@@ -2007,10 +1999,7 @@ extern int acct_storage_p_add_accts(mysql_conn_t *mysql_conn, uint32_t uid,
 	if(_check_connection(mysql_conn) != SLURM_SUCCESS)
 		return SLURM_ERROR;
 
-	if((pw=getpwuid(uid))) {
-		user = pw->pw_name;
-	}
-
+	user_name = pw->pw_name;
 	itr = list_iterator_create(acct_list);
 	while((object = list_next(itr))) {
 		if(!object->name || !object->description
@@ -2073,7 +2062,7 @@ extern int acct_storage_p_add_accts(mysql_conn_t *mysql_conn, uint32_t uid,
 			xstrfmtcat(txn_query, 	
 				   ", (%d, %u, '%s', '%s', \"%s\")",
 				   now, DBD_ADD_ACCOUNTS, object->name,
-				   user, extra);
+				   user_name, extra);
 		else
 			xstrfmtcat(txn_query, 	
 				   "insert into %s "
@@ -2081,7 +2070,7 @@ extern int acct_storage_p_add_accts(mysql_conn_t *mysql_conn, uint32_t uid,
 				   "values (%d, %u, '%s', '%s', \"%s\")",
 				   txn_table,
 				   now, DBD_ADD_ACCOUNTS, object->name,
-				   user, extra);
+				   user_name, extra);
 		xfree(extra);
 		
 		if(!object->assoc_list)
@@ -2090,6 +2079,7 @@ extern int acct_storage_p_add_accts(mysql_conn_t *mysql_conn, uint32_t uid,
 		list_transfer(assoc_list, object->assoc_list);
 	}
 	list_iterator_destroy(itr);
+	xfree(user_name);
 	
 	if(rc != SLURM_ERROR) {
 		if(txn_query) {
@@ -2129,18 +2119,14 @@ extern int acct_storage_p_add_clusters(mysql_conn_t *mysql_conn, uint32_t uid,
 	acct_cluster_rec_t *object = NULL;
 	char *cols = NULL, *vals = NULL, *extra = NULL, *query = NULL;
 	time_t now = time(NULL);
-	struct passwd *pw = NULL;
-	char *user = NULL;
+	char *user_name = NULL;
 	int affect_rows = 0;
 	int added = 0;
 
 	if(_check_connection(mysql_conn) != SLURM_SUCCESS)
 		return SLURM_ERROR;
 
-	if((pw=getpwuid(uid))) {
-		user = pw->pw_name;
-	}
-
+	user_name = uid_to_string((uid_t) uid);
 	itr = list_iterator_create(cluster_list);
 	while((object = list_next(itr))) {
 		if(!object->name) {
@@ -2275,8 +2261,8 @@ extern int acct_storage_p_add_clusters(mysql_conn_t *mysql_conn, uint32_t uid,
 			   "insert into %s "
 			   "(timestamp, action, name, actor, info) "
 			   "values (%d, %u, '%s', '%s', \"%s\");",
-			   txn_table,
-			   now, DBD_ADD_CLUSTERS, object->name, user, extra);
+			   txn_table, now, DBD_ADD_CLUSTERS, 
+			   object->name, user_name, extra);
 		xfree(extra);			
 		debug4("query\n%s",query);
 		rc = mysql_db_query(mysql_conn->db_conn, query);
@@ -2287,6 +2273,7 @@ extern int acct_storage_p_add_clusters(mysql_conn_t *mysql_conn, uint32_t uid,
 			added++;
 	}
 	list_iterator_destroy(itr);
+	xfree(user_name);
 
 	if(!added) {
 		if(mysql_conn->rollback) {
@@ -2314,7 +2301,6 @@ extern int acct_storage_p_add_associations(mysql_conn_t *mysql_conn,
 		*extra = NULL, *query = NULL, *update = NULL;
 	char *parent = NULL;
 	time_t now = time(NULL);
-	struct passwd *pw = NULL;
 	char *user = NULL;
 	char *tmp_char = NULL;
 	int assoc_id = 0;
@@ -2348,10 +2334,7 @@ extern int acct_storage_p_add_associations(mysql_conn_t *mysql_conn,
 	if(_check_connection(mysql_conn) != SLURM_SUCCESS)
 		return SLURM_ERROR;
 
-	if((pw=getpwuid(uid))) {
-		user = pw->pw_name;
-	}
-
+	user_name = uid_to_string((uid_t) uid;
 	itr = list_iterator_create(association_list);
 	while((object = list_next(itr))) {
 		if(!object->cluster || !object->acct) {
@@ -2656,17 +2639,21 @@ extern int acct_storage_p_add_associations(mysql_conn_t *mysql_conn,
 		if(txn_query)
 			xstrfmtcat(txn_query, 	
 				   ", (%d, %d, '%d', '%s', \"%s\")",
-				   now, DBD_ADD_ASSOCS, assoc_id, user, extra);
+				   now, DBD_ADD_ASSOCS, assoc_id, user_name,
+				   extra);
 		else
 			xstrfmtcat(txn_query, 	
 				   "insert into %s "
 				   "(timestamp, action, name, actor, info) "
 				   "values (%d, %d, '%d', '%s', \"%s\")",
 				   txn_table,
-				   now, DBD_ADD_ASSOCS, assoc_id, user, extra);
+				   now, DBD_ADD_ASSOCS, assoc_id, user_name, 
+				   extra);
 		xfree(extra);
 	}
 	list_iterator_destroy(itr);
+	xfree(user_name);
+
 	if(rc != SLURM_SUCCESS)
 		goto end_it;
 
@@ -2731,18 +2718,14 @@ extern int acct_storage_p_add_qos(mysql_conn_t *mysql_conn, uint32_t uid,
 	acct_qos_rec_t *object = NULL;
 	char *query = NULL;
 	time_t now = time(NULL);
-	struct passwd *pw = NULL;
-	char *user = NULL;
+	char *user_name = NULL;
 	int affect_rows = 0;
 	int added = 0;
 
 	if(_check_connection(mysql_conn) != SLURM_SUCCESS)
 		return SLURM_ERROR;
 
-	if((pw=getpwuid(uid))) {
-		user = pw->pw_name;
-	}
-
+	user_name = uid_to_string((uid_t) uid);
 	itr = list_iterator_create(qos_list);
 	while((object = list_next(itr))) {
 		if(!object->name) {
@@ -2780,7 +2763,7 @@ extern int acct_storage_p_add_qos(mysql_conn_t *mysql_conn, uint32_t uid,
 			   "(timestamp, action, name, actor, info) "
 			   "values (%d, %u, '%s', '%s', \"%s\");",
 			   txn_table,
-			   now, DBD_ADD_QOS, object->name, user,
+			   now, DBD_ADD_QOS, object->name, user_name,
 			   object->description);
 
 		debug4("query\n%s",query);
@@ -2798,6 +2781,7 @@ extern int acct_storage_p_add_qos(mysql_conn_t *mysql_conn, uint32_t uid,
 		
 	}
 	list_iterator_destroy(itr);
+	xfree(user_name);
 
 	if(!added) {
 		if(mysql_conn->rollback) {
@@ -2823,7 +2807,6 @@ extern List acct_storage_p_modify_users(mysql_conn_t *mysql_conn, uint32_t uid,
 	char *object = NULL;
 	char *vals = NULL, *extra = NULL, *query = NULL, *name_char = NULL;
 	time_t now = time(NULL);
-	struct passwd *pw = NULL;
 	char *user_name = NULL;
 	int set = 0;
 	MYSQL_RES *result = NULL;
@@ -2838,10 +2821,6 @@ extern List acct_storage_p_modify_users(mysql_conn_t *mysql_conn, uint32_t uid,
 	if(_check_connection(mysql_conn) != SLURM_SUCCESS)
 		return NULL;
 
-	if((pw=getpwuid(uid))) {
-		user_name = pw->pw_name;
-	}
-
 	xstrcat(extra, "where deleted=0");
 	if(user_cond->assoc_cond && user_cond->assoc_cond->user_list
 	   && list_count(user_cond->assoc_cond->user_list)) {
@@ -3024,16 +3003,17 @@ extern List acct_storage_p_modify_users(mysql_conn_t *mysql_conn, uint32_t uid,
 	xfree(query);
 	xstrcat(name_char, ")");
 
-	if(_modify_common(mysql_conn, DBD_MODIFY_USERS, now,
-			  user_name, user_table, name_char, vals)
-	   == SLURM_ERROR) {
+	user_name = uid_to_string((uid_t) uid);
+	rc = _modify_common(mysql_conn, DBD_MODIFY_USERS, now,
+			    user_name, user_table, name_char, vals);
+	xfree(user_name);
+	xfree(name_char);
+	xfree(vals);
+	if (rc == SLURM_ERROR) {
 		error("Couldn't modify users");
 		list_destroy(ret_list);
 		ret_list = NULL;
 	}
-
-	xfree(name_char);
-	xfree(vals);
 				
 	return ret_list;
 #else
@@ -3053,8 +3033,7 @@ extern List acct_storage_p_modify_accounts(
 	char *object = NULL;
 	char *vals = NULL, *extra = NULL, *query = NULL, *name_char = NULL;
 	time_t now = time(NULL);
-	struct passwd *pw = NULL;
-	char *user = NULL;
+	char *user_name = NULL;
 	int set = 0;
 	MYSQL_RES *result = NULL;
 	MYSQL_ROW row;
@@ -3067,10 +3046,6 @@ extern List acct_storage_p_modify_accounts(
 	if(_check_connection(mysql_conn) != SLURM_SUCCESS)
 		return NULL;
 
-	if((pw=getpwuid(uid))) {
-		user = pw->pw_name;
-	}
-
 	xstrcat(extra, "where deleted=0");
 	if(acct_cond->assoc_cond 
 	   && acct_cond->assoc_cond->acct_list 
@@ -3209,9 +3184,11 @@ extern List acct_storage_p_modify_accounts(
 	xfree(query);
 	xstrcat(name_char, ")");
 
-	if(_modify_common(mysql_conn, DBD_MODIFY_ACCOUNTS, now,
-			  user, acct_table, name_char, vals)
-	   == SLURM_ERROR) {
+	user_name = uid_to_string((uid_t) uid);
+	rc = _modify_common(mysql_conn, DBD_MODIFY_ACCOUNTS, now,
+			    user_name, acct_table, name_char, vals);
+	xfree(user_name);
+	if (rc == SLURM_ERROR) {
 		error("Couldn't modify accounts");
 		list_destroy(ret_list);
 		errno = SLURM_ERROR;
@@ -3240,8 +3217,7 @@ extern List acct_storage_p_modify_clusters(mysql_conn_t *mysql_conn,
 	char *vals = NULL, *extra = NULL, *query = NULL,
 		*name_char = NULL, *assoc_char= NULL, *send_char = NULL;
 	time_t now = time(NULL);
-	struct passwd *pw = NULL;
-	char *user = NULL;
+	char *user_name = NULL;
 	int set = 0;
 	MYSQL_RES *result = NULL;
 	MYSQL_ROW row;
@@ -3259,10 +3235,6 @@ extern List acct_storage_p_modify_clusters(mysql_conn_t *mysql_conn,
 	if(_check_connection(mysql_conn) != SLURM_SUCCESS)
 		return NULL;
 
-	if((pw=getpwuid(uid))) {
-		user = pw->pw_name;
-	}
-
 	xstrcat(extra, "where deleted=0");
 	if(cluster_cond->cluster_list
 	   && list_count(cluster_cond->cluster_list)) {
@@ -3329,9 +3301,11 @@ extern List acct_storage_p_modify_clusters(mysql_conn_t *mysql_conn,
 
 	if(vals) {
 		send_char = xstrdup_printf("(%s)", name_char);
-		if(_modify_common(mysql_conn, DBD_MODIFY_CLUSTERS, now,
-				  user, cluster_table, send_char, vals)
-		   == SLURM_ERROR) {
+		user_name = uid_to_string((uid_t) uid);
+		rc = _modify_common(mysql_conn, DBD_MODIFY_CLUSTERS, now,
+				    user_name, cluster_table, send_char, vals);
+		xfree(user_name);
+		if (rc == SLURM_ERROR) {
 			error("Couldn't modify cluster 1");
 			list_destroy(ret_list);
 			ret_list = NULL;
@@ -3363,7 +3337,6 @@ extern List acct_storage_p_modify_associations(
 	char *object = NULL;
 	char *vals = NULL, *extra = NULL, *query = NULL, *name_char = NULL;
 	time_t now = time(NULL);
-	struct passwd *pw = NULL;
 	char *user_name = NULL;
 	int set = 0, i = 0, is_admin=0;
 	MYSQL_RES *result = NULL;
@@ -3440,10 +3413,6 @@ extern List acct_storage_p_modify_associations(
 		is_admin = 1;
 	}
 
-	if((pw=getpwuid(uid))) {
-		user_name = pw->pw_name;
-	}
-
 	if(assoc_cond->acct_list && list_count(assoc_cond->acct_list)) {
 		set = 0;
 		xstrcat(extra, " && (");
@@ -3762,9 +3731,11 @@ extern List acct_storage_p_modify_associations(
 	xstrcat(name_char, ")");
 
 	if(vals) {
-		if(_modify_common(mysql_conn, DBD_MODIFY_ASSOCS, now,
-				  user_name, assoc_table, name_char, vals)
-		   == SLURM_ERROR) {
+		user_name = uid_to_string((uid_t) uid);
+		rc = _modify_common(mysql_conn, DBD_MODIFY_ASSOCS, now,
+				    user_name, assoc_table, name_char, vals);
+		xfree(user_name);
+		if (rc == SLURM_ERROR) {
 			if(mysql_conn->rollback) {
 				mysql_db_rollback(mysql_conn->db_conn);
 			}
@@ -3797,7 +3768,6 @@ extern List acct_storage_p_remove_users(mysql_conn_t *mysql_conn, uint32_t uid,
 	char *extra = NULL, *query = NULL,
 		*name_char = NULL, *assoc_char = NULL;
 	time_t now = time(NULL);
-	struct passwd *pw = NULL;
 	char *user_name = NULL;
 	int set = 0;
 	MYSQL_RES *result = NULL;
@@ -3811,10 +3781,6 @@ extern List acct_storage_p_remove_users(mysql_conn_t *mysql_conn, uint32_t uid,
 	if(_check_connection(mysql_conn) != SLURM_SUCCESS)
 		return NULL;
 
-	if((pw=getpwuid(uid))) {
-		user_name = pw->pw_name;
-	}
-
 	xstrcat(extra, "where deleted=0");
 
 	if(user_cond->assoc_cond && user_cond->assoc_cond->user_list
@@ -3910,15 +3876,16 @@ extern List acct_storage_p_remove_users(mysql_conn_t *mysql_conn, uint32_t uid,
 	}
 	xfree(query);
 
-	if(_remove_common(mysql_conn, DBD_REMOVE_USERS, now,
-			  user_name, user_table, name_char, assoc_char)
-	   == SLURM_ERROR) {
+	user_name = uid_to_string((uid_t) uid);
+	rc = _remove_common(mysql_conn, DBD_REMOVE_USERS, now,
+			    user_name, user_table, name_char, assoc_char);
+	xfree(user_name);
+	xfree(name_char);
+	if (rc == SLURM_ERROR) {
 		list_destroy(ret_list);
-		xfree(name_char);
 		xfree(assoc_char);
 		return NULL;
 	}
-	xfree(name_char);
 
 	query = xstrdup_printf(
 		"update %s as t2 set deleted=1, mod_time=%d where %s",
@@ -3947,9 +3914,8 @@ extern List acct_storage_p_remove_coord(mysql_conn_t *mysql_conn, uint32_t uid,
 #ifdef HAVE_MYSQL
 	char *query = NULL, *object = NULL, *extra = NULL, *last_user = NULL;
 	char *user_name = NULL;
-	struct passwd *pw = NULL;
 	time_t now = time(NULL);
-	int set = 0, is_admin=0;
+	int set = 0, is_admin=0, rc;
 	ListIterator itr = NULL;
 	acct_user_rec_t *user_rec = NULL;
 	List ret_list = NULL;
@@ -4005,10 +3971,6 @@ extern List acct_storage_p_remove_coord(mysql_conn_t *mysql_conn, uint32_t uid,
 		is_admin = 1;
 	}
 
-	if((pw=getpwuid(uid))) {
-		user_name = pw->pw_name;
-	}
-
 	/* Leave it this way since we are using extra below */
 
 	if(user_cond->assoc_cond && user_cond->assoc_cond->user_list
@@ -4110,16 +4072,18 @@ extern List acct_storage_p_remove_coord(mysql_conn_t *mysql_conn, uint32_t uid,
 	}
 	mysql_free_result(result);
 	
-	if(_remove_common(mysql_conn, DBD_REMOVE_ACCOUNT_COORDS, now,
-			  user_name, acct_coord_table, extra, NULL)
-	   == SLURM_ERROR) {
+	user_name = uid_to_string((uid_t) uid);
+	rc = _remove_common(mysql_conn, DBD_REMOVE_ACCOUNT_COORDS, now,
+			    user_name, acct_coord_table, extra, NULL);
+	xfree(user_name);
+	xfree(extra);
+	if (rc == SLURM_ERROR) {
 		list_destroy(ret_list);
 		list_destroy(user_list);
-		xfree(extra);
 		errno = SLURM_ERROR;
 		return NULL;
 	}
-	xfree(extra);
+
 	/* get the update list set */
 	itr = list_iterator_create(user_list);
 	while((last_user = list_next(itr))) {
@@ -4149,7 +4113,6 @@ extern List acct_storage_p_remove_accts(mysql_conn_t *mysql_conn, uint32_t uid,
 	char *extra = NULL, *query = NULL,
 		*name_char = NULL, *assoc_char = NULL;
 	time_t now = time(NULL);
-	struct passwd *pw = NULL;
 	char *user_name = NULL;
 	int set = 0;
 	MYSQL_RES *result = NULL;
@@ -4160,10 +4123,6 @@ extern List acct_storage_p_remove_accts(mysql_conn_t *mysql_conn, uint32_t uid,
 		return NULL;
 	}
 
-	if((pw=getpwuid(uid))) {
-		user_name = pw->pw_name;
-	}
-
 	if(_check_connection(mysql_conn) != SLURM_SUCCESS)
 		return NULL;
 
@@ -4267,16 +4226,16 @@ extern List acct_storage_p_remove_accts(mysql_conn_t *mysql_conn, uint32_t uid,
 	}
 	xfree(query);
 
-	if(_remove_common(mysql_conn, DBD_REMOVE_ACCOUNTS, now,
-			  user_name, acct_table, name_char, assoc_char)
-	   == SLURM_ERROR) {
+	user_name = uid_to_string((uid_t) uid);
+	rc = _remove_common(mysql_conn, DBD_REMOVE_ACCOUNTS, now,
+			    user_name, acct_table, name_char, assoc_char);
+	xfree(user_name);
+	xfree(name_char);
+	xfree(assoc_char);
+	if (rc == SLURM_ERROR) {
 		list_destroy(ret_list);
-		xfree(name_char);
-		xfree(assoc_char);
 		return NULL;
 	}
-	xfree(name_char);
-	xfree(assoc_char);
 
 	return ret_list;
 #else
@@ -4296,7 +4255,6 @@ extern List acct_storage_p_remove_clusters(mysql_conn_t *mysql_conn,
 	char *extra = NULL, *query = NULL,
 		*name_char = NULL, *assoc_char = NULL;
 	time_t now = time(NULL);
-	struct passwd *pw = NULL;
 	char *user_name = NULL;
 	int set = 0;
 	MYSQL_RES *result = NULL;
@@ -4311,9 +4269,6 @@ extern List acct_storage_p_remove_clusters(mysql_conn_t *mysql_conn,
 	if(_check_connection(mysql_conn) != SLURM_SUCCESS)
 		return NULL;
 
-	if((pw=getpwuid(uid))) {
-		user_name = pw->pw_name;
-	}
 	xstrcat(extra, "where deleted=0");
 	if(cluster_cond->cluster_list
 	   && list_count(cluster_cond->cluster_list)) {
@@ -4400,16 +4355,16 @@ extern List acct_storage_p_remove_clusters(mysql_conn_t *mysql_conn,
 	assoc_char = xstrdup_printf("t2.acct='root' && (%s)", extra);
 	xfree(extra);
 
-	if(_remove_common(mysql_conn, DBD_REMOVE_CLUSTERS, now,
-			  user_name, cluster_table, name_char, assoc_char)
-	   == SLURM_ERROR) {
+	user_name = uid_to_string((uid_t) uid);
+	rc = _remove_common(mysql_conn, DBD_REMOVE_CLUSTERS, now,
+			    user_name, cluster_table, name_char, assoc_char);
+	xfree(user_name);
+	xfree(name_char);
+	xfree(assoc_char);
+	if (rc  == SLURM_ERROR) {
 		list_destroy(ret_list);
-		xfree(name_char);
-		xfree(assoc_char);
 		return NULL;
 	}
-	xfree(name_char);
-	xfree(assoc_char);
 
 	return ret_list;
 #else
@@ -4429,7 +4384,6 @@ extern List acct_storage_p_remove_associations(
 	char *extra = NULL, *query = NULL,
 		*name_char = NULL, *assoc_char = NULL;
 	time_t now = time(NULL);
-	struct passwd *pw = NULL;
 	char *user_name = NULL;
 	int set = 0, i = 0, is_admin=0;
 	MYSQL_RES *result = NULL;
@@ -4506,10 +4460,6 @@ extern List acct_storage_p_remove_associations(
 
 	xstrcat(extra, "where id>0 && deleted=0");
 
-	if((pw=getpwuid(uid))) {
-		user_name = pw->pw_name;
-	}
-
 	if(assoc_cond->acct_list && list_count(assoc_cond->acct_list)) {
 		set = 0;
 		xstrcat(extra, " && (");
@@ -4714,15 +4664,14 @@ extern List acct_storage_p_remove_associations(
 	}
 	mysql_free_result(result);
 
-	if(_remove_common(mysql_conn, DBD_REMOVE_ASSOCS, now,
-			  user_name, assoc_table, name_char, assoc_char)
-	   == SLURM_ERROR) {
-		xfree(name_char);
-		xfree(assoc_char);
-		goto end_it;
-	}
+	user_name = uid_to_string(pw->pw_name);
+	rc = _remove_common(mysql_conn, DBD_REMOVE_ASSOCS, now,
+			    user_name, assoc_table, name_char, assoc_char);
+	xfree(user_name);
 	xfree(name_char);
 	xfree(assoc_char);
+	if (rc  == SLURM_ERROR)
+		goto end_it;
 
 	return ret_list;
 end_it:
@@ -4754,7 +4703,6 @@ extern List acct_storage_p_remove_qos(mysql_conn_t *mysql_conn, uint32_t uid,
 	char *extra = NULL, *query = NULL,
 		*name_char = NULL, *assoc_char = NULL;
 	time_t now = time(NULL);
-	struct passwd *pw = NULL;
 	char *user_name = NULL;
 	int set = 0;
 	MYSQL_RES *result = NULL;
@@ -4765,10 +4713,6 @@ extern List acct_storage_p_remove_qos(mysql_conn_t *mysql_conn, uint32_t uid,
 		return NULL;
 	}
 
-	if((pw=getpwuid(uid))) {
-		user_name = pw->pw_name;
-	}
-
 	if(_check_connection(mysql_conn) != SLURM_SUCCESS)
 		return NULL;
 
@@ -4863,14 +4807,15 @@ extern List acct_storage_p_remove_qos(mysql_conn_t *mysql_conn, uint32_t uid,
 	}
 	xfree(query);
 
-	if(_remove_common(mysql_conn, DBD_REMOVE_ACCOUNTS, now,
-			  user_name, qos_table, name_char, assoc_char)
-	   == SLURM_ERROR) {
+	user_name = uid_to_string((uid_t) uid);
+	rc = _remove_common(mysql_conn, DBD_REMOVE_ACCOUNTS, now,
+			    user_name, qos_table, name_char, assoc_char);
+	xfree(name_char);
+	xfree(user_name);
+	if (rc == SLURM_ERROR) {
 		list_destroy(ret_list);
-		xfree(name_char);
 		return NULL;
 	}
-	xfree(name_char);
 
 	return ret_list;
 #else
@@ -4998,7 +4943,7 @@ empty:
 
 	while((row = mysql_fetch_row(result))) {
 		acct_user_rec_t *user = xmalloc(sizeof(acct_user_rec_t));
-/* 		struct passwd *passwd_ptr = NULL; */
+/* 		uid_t pw_uid; */
 		list_append(user_list, user);
 
 		user->name =  xstrdup(row[USER_REQ_NAME]);
@@ -5014,11 +4959,12 @@ empty:
 		 * 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 */
+/* 		pw_uid = uid_from_string(user->name); */
+/* 		if(pw_uid == (uid_t) -1)  */
 /* 			user->uid = (uint32_t)NO_VAL; */
+/* 		else */
+/* 			user->uid = passwd_ptr->pw_uid; */
+
 		if(user_cond && user_cond->with_coords) {
 			_get_user_coords(mysql_conn, user);
 		}
diff --git a/src/plugins/accounting_storage/slurmdbd/accounting_storage_slurmdbd.c b/src/plugins/accounting_storage/slurmdbd/accounting_storage_slurmdbd.c
index cda10275770..f0c8556f26d 100644
--- a/src/plugins/accounting_storage/slurmdbd/accounting_storage_slurmdbd.c
+++ b/src/plugins/accounting_storage/slurmdbd/accounting_storage_slurmdbd.c
@@ -56,6 +56,7 @@
 #include "src/common/read_config.h"
 #include "src/common/slurm_accounting_storage.h"
 #include "src/common/slurmdbd_defs.h"
+#include "src/common/uid.h"
 #include "src/common/xstring.h"
 #include "src/slurmctld/slurmctld.h"
 
@@ -1355,7 +1356,6 @@ extern List jobacct_storage_p_get_jobs(void *db_conn,
 	dbd_list_msg_t *got_msg;
 	int rc;
 	List job_list = NULL;
-	struct passwd *pw = NULL;
 
 	get_msg.selected_steps = selected_steps;
 	get_msg.selected_parts = selected_parts;
@@ -1367,14 +1367,15 @@ extern List jobacct_storage_p_get_jobs(void *db_conn,
 	}
 	get_msg.gid = params->opt_gid;
 	
-	if (params->opt_uid >=0 && (pw=getpwuid(params->opt_uid)))
-		get_msg.user = pw->pw_name;
+	if (params->opt_uid >=0)
+		get_msg.user = uid_to_string((uid_t) params->opt_uid);
 	else
 		get_msg.user = NULL;
 
 	req.msg_type = DBD_GET_JOBS;
 	req.data = &get_msg;
 	rc = slurm_send_recv_slurmdbd_msg(&req, &resp);
+	xfree(get_msg.user);
 
 	if (rc != SLURM_SUCCESS)
 		error("slurmdbd: DBD_GET_JOBS failure: %m");
diff --git a/src/plugins/jobcomp/filetxt/jobcomp_filetxt.c b/src/plugins/jobcomp/filetxt/jobcomp_filetxt.c
index 24ce21bf401..77b558162e3 100644
--- a/src/plugins/jobcomp/filetxt/jobcomp_filetxt.c
+++ b/src/plugins/jobcomp/filetxt/jobcomp_filetxt.c
@@ -132,21 +132,15 @@ static void
 _get_group_name(uint32_t group_id, char *group_name, int buf_size)
 {
 	static uint32_t cache_gid      = 0;
-	static char     cache_name[32] = "root";
-	struct group  *group_info      = NULL;
-
-	if (group_id == cache_gid)
-		snprintf(group_name, buf_size, "%s", cache_name);
-	else {
-		group_info = getgrgid((gid_t) group_id);
-		if (group_info && group_info->gr_name[0])
-			snprintf(cache_name, sizeof(cache_name), "%s", 
-				group_info->gr_name);
-		else
-			snprintf(cache_name, sizeof(cache_name), "Unknown");
+	static char     cache_name[32] = "root", *gname;
+
+	if (group_id != cache_gid) {
+		gname = gid_to_string((gid_t) group_id);
+		snprintf(cache_name, sizeof(cache_name), "%s", gname);
+		xfree(gname);
 		cache_gid = group_id;
-		snprintf(group_name, buf_size, "%s", cache_name);
 	}
+	snprintf(group_name, buf_size, "%s", cache_name);
 }
 
 /* 
diff --git a/src/plugins/jobcomp/mysql/jobcomp_mysql.c b/src/plugins/jobcomp/mysql/jobcomp_mysql.c
index 69f24292ca4..a977b8ec574 100644
--- a/src/plugins/jobcomp/mysql/jobcomp_mysql.c
+++ b/src/plugins/jobcomp/mysql/jobcomp_mysql.c
@@ -155,18 +155,14 @@ static int _mysql_jobcomp_check_tables()
 static char *_get_user_name(uint32_t user_id)
 {
 	static uint32_t cache_uid      = 0;
-	static char     cache_name[32] = "root";
-	struct passwd * user_info      = NULL;
+	static char     cache_name[32] = "root", *uname;
 	char *ret_name = NULL;
 
 	slurm_mutex_lock(&jobcomp_lock);
 	if (user_id != cache_uid) {
-		user_info = getpwuid((uid_t) user_id);
-		if (user_info && user_info->pw_name[0])
-			snprintf(cache_name, sizeof(cache_name), "%s", 
-				user_info->pw_name);
-		else
-			snprintf(cache_name, sizeof(cache_name), "Unknown");
+		uname = uid_to_string((uid_t) user_id);
+		snprintf(cache_name, sizeof(cache_name), "%s", uname);
+		xfree(uname);
 		cache_uid = user_id;
 	}
 	ret_name = xstrdup(cache_name);
@@ -179,18 +175,14 @@ static char *_get_user_name(uint32_t user_id)
 static char *_get_group_name(uint32_t group_id)
 {
 	static uint32_t cache_gid      = 0;
-	static char     cache_name[32] = "root";
-	struct group  *group_info      = NULL;
+	static char     cache_name[32] = "root", *gname
 	char *ret_name = NULL;
 
 	slurm_mutex_lock(&jobcomp_lock);
 	if (group_id != cache_gid) {
-		group_info = getgrgid((gid_t) group_id);
-		if (group_info && group_info->gr_name[0])
-			snprintf(cache_name, sizeof(cache_name), "%s", 
-				 group_info->gr_name);
-		else
-			snprintf(cache_name, sizeof(cache_name), "Unknown");
+		gname = gid_to_string((gid_t) group_id);
+		snprintf(cache_name, sizeof(cache_name), "%s", gname);
+		xfree(gname);
 		cache_gid = group_id;
 	}
 	ret_name = xstrdup(cache_name);
diff --git a/src/plugins/jobcomp/pgsql/jobcomp_pgsql.c b/src/plugins/jobcomp/pgsql/jobcomp_pgsql.c
index c9f9ad5b1fa..f4f154ce2ea 100644
--- a/src/plugins/jobcomp/pgsql/jobcomp_pgsql.c
+++ b/src/plugins/jobcomp/pgsql/jobcomp_pgsql.c
@@ -178,18 +178,14 @@ static int _pgsql_jobcomp_check_tables(char *user)
 static char *_get_user_name(uint32_t user_id)
 {
 	static uint32_t cache_uid      = 0;
-	static char     cache_name[32] = "root";
-	struct passwd * user_info      = NULL;
+	static char     cache_name[32] = "root", *uname;
 	char *ret_name = NULL;
 
 	slurm_mutex_lock(&jobcomp_lock);
 	if (user_id != cache_uid) {
-		user_info = getpwuid((uid_t) user_id);
-		if (user_info && user_info->pw_name[0])
-			snprintf(cache_name, sizeof(cache_name), "%s", 
-				user_info->pw_name);
-		else
-			snprintf(cache_name, sizeof(cache_name), "Unknown");
+		uname = uid_to_string((uid_t) user_id);
+		snprintf(cache_name, sizeof(cache_name), "%s", uname);
+		xfree(uname);
 		cache_uid = user_id;
 	}
 	ret_name = xstrdup(cache_name);
@@ -202,18 +198,14 @@ static char *_get_user_name(uint32_t user_id)
 static char *_get_group_name(uint32_t group_id)
 {
 	static uint32_t cache_gid      = 0;
-	static char     cache_name[32] = "root";
-	struct group  *group_info      = NULL;
+	static char     cache_name[32] = "root", *gname;
 	char *ret_name = NULL;
 
 	slurm_mutex_lock(&jobcomp_lock);
 	if (group_id != cache_gid) {
-		group_info = getgrgid((gid_t) group_id);
-		if (group_info && group_info->gr_name[0])
-			snprintf(cache_name, sizeof(cache_name), "%s", 
-				 group_info->gr_name);
-		else
-			snprintf(cache_name, sizeof(cache_name), "Unknown");
+		gname = gid_to_string((gid_t) group_id);
+		snprintf(cache_name, sizeof(cache_name), "%s", gname);
+		xfree(gname);
 		cache_gid = group_id;
 	}
 	ret_name = xstrdup(cache_name);
diff --git a/src/plugins/select/bluegene/plugin/bg_record_functions.c b/src/plugins/select/bluegene/plugin/bg_record_functions.c
index 42b4727107a..9d7d8c7d94d 100644
--- a/src/plugins/select/bluegene/plugin/bg_record_functions.c
+++ b/src/plugins/select/bluegene/plugin/bg_record_functions.c
@@ -39,6 +39,7 @@
 #include "bluegene.h"
 #include "dynamic_block.h"
 
+#include "src/common/uid.h"
 #include "src/slurmctld/trigger_mgr.h"
 
 /* some local functions */
@@ -456,8 +457,6 @@ extern bg_record_t *find_bg_record_in_list(List my_list, char *bg_block_id)
 */
 extern int update_block_user(bg_record_t *bg_record, int set) 
 {
-	struct passwd *pw_ent = NULL;
-
 	if(!bg_record->target_name) {
 		error("Must set target_name to run update_block_user.");
 		return -1;
@@ -500,13 +499,15 @@ extern int update_block_user(bg_record_t *bg_record, int set)
 #endif
 	
 	if(strcmp(bg_record->target_name, bg_record->user_name)) {
+		uid_t pw_uid;
 		xfree(bg_record->user_name);
 		bg_record->user_name = xstrdup(bg_record->target_name);
-		if((pw_ent = getpwnam(bg_record->user_name)) == NULL) {
-			error("getpwnam(%s): %m", bg_record->user_name);
+		pw_uid = uid_from_string(bg_record->user_name);
+		if(pw_uid == (uid_t) -1) {
+			error("No such user: %s", bg_record->user_name);
 			return -1;
 		} else {
-			bg_record->user_uid = pw_ent->pw_uid; 
+			bg_record->user_uid = pw_uid; 
 		}		
 		return 1;
 	}
@@ -616,7 +617,7 @@ extern int add_bg_record(List records, List used_nodes, blockreq_t *blockreq)
 	bg_record_t *found_record = NULL;
 	ba_node_t *ba_node = NULL;
 	ListIterator itr;
-	struct passwd *pw_ent = NULL;
+	uid_t pw_uid;
 	int i, len;
 	int small_size = 0;
 	int small_count = 0;
@@ -635,10 +636,11 @@ extern int add_bg_record(List records, List used_nodes, blockreq_t *blockreq)
 	bg_record->target_name = 
 		xstrdup(slurmctld_conf.slurm_user_name);
 	slurm_conf_unlock();
-	if((pw_ent = getpwnam(bg_record->user_name)) == NULL) {
-		error("getpwnam(%s): %m", bg_record->user_name);
+	pw_uid = uid_from_string(bg_record->user_name);
+	if(pw_uid == (uid_t) -1) {
+		error("No such user: %s", bg_record->user_name);
 	} else {
-		bg_record->user_uid = pw_ent->pw_uid;
+		bg_record->user_uid = pw_uid;
 	}
 
 	bg_record->bg_block_list = list_create(destroy_ba_node);
diff --git a/src/slurmdbd/proc_req.c b/src/slurmdbd/proc_req.c
index a563310262a..ab9e00ac9da 100644
--- a/src/slurmdbd/proc_req.c
+++ b/src/slurmdbd/proc_req.c
@@ -42,6 +42,7 @@
 #include "src/common/jobacct_common.h"
 #include "src/common/slurm_protocol_api.h"
 #include "src/common/slurm_protocol_defs.h"
+#include "src/common/uid.h"
 #include "src/slurmdbd/read_config.h"
 #include "src/slurmdbd/rpc_mgr.h"
 #include "src/slurmctld/slurmctld.h"
@@ -780,9 +781,9 @@ static int _get_jobs(void *db_conn,
 
 	sacct_params.opt_uid = -1;
 	if(get_jobs_msg->user) {
-		struct passwd *pw = NULL;
-		if ((pw=getpwnam(get_jobs_msg->user)))
-			sacct_params.opt_uid = pw->pw_uid;
+		uid_t pw_uid = uid_from_string(get_jobs_msg->user);
+		if (pw_uid != (uid_t) -1)
+			sacct_params.opt_uid = pw_uid;
 	}
 		
 	list_msg.my_list = jobacct_storage_g_get_jobs(
diff --git a/src/slurmdbd/read_config.c b/src/slurmdbd/read_config.c
index e14489454bb..5df989cf6a5 100644
--- a/src/slurmdbd/read_config.c
+++ b/src/slurmdbd/read_config.c
@@ -48,6 +48,7 @@
 #include "src/common/log.h"
 #include "src/common/parse_config.h"
 #include "src/common/read_config.h"
+#include "src/common/uid.h"
 #include "src/common/xmalloc.h"
 #include "src/common/xstring.h"
 #include "src/slurmdbd/read_config.h"
@@ -208,13 +209,12 @@ extern int read_slurmdbd_conf(void)
 	if(slurmdbd_conf->plugindir == NULL)
 		slurmdbd_conf->plugindir = xstrdup(default_plugin_path);
 	if (slurmdbd_conf->slurm_user_name) {
-		struct passwd *slurm_passwd;
-		slurm_passwd = getpwnam(slurmdbd_conf->slurm_user_name);
-		if (slurm_passwd == NULL) {
+		uid_t pw_uid = uid_from_string(slurmdbd_conf->slurm_user_name);
+		if (pw_uid == (uid_t) -1) {
 			fatal("Invalid user for SlurmUser %s, ignored",
 			      slurmdbd_conf->slurm_user_name);
 		} else
-			slurmdbd_conf->slurm_user_id = slurm_passwd->pw_uid;
+			slurmdbd_conf->slurm_user_id = pw_uid;
 	} else {
 		slurmdbd_conf->slurm_user_name = xstrdup("root");
 		slurmdbd_conf->slurm_user_id = 0;
-- 
GitLab