From 7159777fc4554d96f05dadcc038ecd10c8665679 Mon Sep 17 00:00:00 2001
From: Moe Jette <jette1@llnl.gov>
Date: Thu, 5 Feb 2009 22:23:59 +0000
Subject: [PATCH] add account name enforcement to reservations

---
 src/common/assoc_mgr.c      |  8 +++++---
 src/common/assoc_mgr.h      |  1 +
 src/slurmctld/reservation.c | 15 ++++++++++++++-
 3 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/src/common/assoc_mgr.c b/src/common/assoc_mgr.c
index a2a437a15a5..fd13d1c9337 100644
--- a/src/common/assoc_mgr.c
+++ b/src/common/assoc_mgr.c
@@ -1,8 +1,8 @@
 /*****************************************************************************\
- *  accounting_storage_slurmdbd.c - accounting interface to slurmdbd.
+ *  assoc_mgr.h - keep track of local cache of accounting data.
  *****************************************************************************
  *  Copyright (C) 2004-2007 The Regents of the University of California.
- *  Copyright (C) 2008 Lawrence Livermore National Security.
+ *  Copyright (C) 2008-2009 Lawrence Livermore National Security.
  *  Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
  *  Written by Danny Auble <da@llnl.gov>
  *  
@@ -890,7 +890,9 @@ extern int assoc_mgr_fill_in_assoc(void *db_conn, acct_association_rec_t *assoc,
 			}
 			continue;
 		} else {
-			if(assoc->uid == (uint32_t)NO_VAL
+			if(assoc->uid == (uint32_t)INFINITE) {
+				;	/* match any user id */
+			} else if(assoc->uid == (uint32_t)NO_VAL
 			   && found_assoc->uid != (uint32_t)NO_VAL) {
 				debug3("we are looking for a "
 				       "nonuser association");
diff --git a/src/common/assoc_mgr.h b/src/common/assoc_mgr.h
index fc86956716f..8f43cf4ba55 100644
--- a/src/common/assoc_mgr.h
+++ b/src/common/assoc_mgr.h
@@ -93,6 +93,7 @@ extern int assoc_mgr_fill_in_user(void *db_conn, acct_user_rec_t *user,
  * IN/OUT:  assoc - acct_association_rec_t with at least cluster and
  *		    account set for account association.  To get user
  *		    association set user, and optional partition.
+ *		    Input a uid=INFINITE to match any user.
  *		    Sets "id" field with the association ID.
  * IN: enforce - return an error if no such association exists
  * IN/OUT: assoc_pptr - if non-NULL then return a pointer to the 
diff --git a/src/slurmctld/reservation.c b/src/slurmctld/reservation.c
index 5faa1fc9999..d2aa8339572 100644
--- a/src/slurmctld/reservation.c
+++ b/src/slurmctld/reservation.c
@@ -53,6 +53,7 @@
 #include <sys/stat.h>
 #include <sys/types.h>
 
+#include "src/common/assoc_mgr.h"
 #include "src/common/bitstring.h"
 #include "src/common/hostlist.h"
 #include "src/common/list.h"
@@ -272,7 +273,19 @@ static void _generate_resv_name(reserve_request_msg_t *resv_ptr)
 /* Validate an account name */
 static bool _is_account_valid(char *account)
 {
-	/* FIXME: Need to add logic here */
+	acct_association_rec_t assoc_rec, *assoc_ptr;
+
+	if (!(accounting_enforce & ACCOUNTING_ENFORCE_ASSOCS))
+		return true;	/* don't worry about account validity */
+
+	memset(&assoc_rec, 0, sizeof(acct_association_rec_t));
+	assoc_rec.uid       = INFINITE;
+	assoc_rec.acct      = account;
+
+	if (assoc_mgr_fill_in_assoc(acct_db_conn, &assoc_rec,
+				    accounting_enforce, &assoc_ptr)) {
+		return false;
+	}
 	return true;
 }
 
-- 
GitLab