From 27fa44ef414a09872f21c888f273a804e8df2a67 Mon Sep 17 00:00:00 2001
From: Utz-Uwe Haus <uhaus@cray.com>
Date: Wed, 22 Dec 2021 12:50:05 +0100
Subject: [PATCH] implement mstro_drc_init_from_credential()

---
 maestro/drc.c | 34 +++++++++++++++++++++++++++++++++-
 1 file changed, 33 insertions(+), 1 deletion(-)

diff --git a/maestro/drc.c b/maestro/drc.c
index d06fb481..5556920b 100644
--- a/maestro/drc.c
+++ b/maestro/drc.c
@@ -347,7 +347,39 @@ mstro_status
 mstro_drc_init_from_credential(mstro_drc_info *result_p,
                                uint32_t credential)
 {
-  return MSTRO_UNIMPL;
+  mstro_status stat = MSTRO_UNIMPL;
+  uint32_t id = credential;
+  int ret;
+
+  if(result_p==NULL)
+    return MSTRO_INVOUT;
+  
+  *result_p = malloc(sizeof(struct mstro_drc_info_));
+  if(*result_p) {
+    drc_info_handle_t info;
+    (*result_p)->drc_id = id;
+    
+    ret = drc_access((*result_p)->drc_id, 0, &info);
+    if(ret!=DRC_SUCCESS) {
+      ERR("Failed to drc_access credential %" PRIu32 ": %d\n", id, ret);
+      goto BAILOUT_FREE;
+    }
+
+    mstro_drc_init_internal(*result_p, info);
+
+    DEBUG("Accessing DRC credential %d (OOB: is %s), cookie %" PRIx64 ")\n",
+          (*result_p)->drc_id,
+          (*result_p)->serialized_id,
+          (*result_p)->auth_key.raw.protection_key);
+    stat = MSTRO_OK;
+  } else {
+    stat = MSTRO_NOMEM;
+  }
+  goto BAILOUT;
+BAILOUT_FREE:
+  NFREE(*result_p);
+BAILOUT:
+  return stat;  
 }
 
 
-- 
GitLab