2014-02-04 01:38:45 +00:00
|
|
|
/*
|
2015-06-18 09:53:20 -07:00
|
|
|
* Copyright (c) 2014-2015 Intel, Inc. All rights reserved.
|
2014-02-04 01:38:45 +00:00
|
|
|
* $COPYRIGHT$
|
2015-06-23 20:59:57 -07:00
|
|
|
*
|
2014-02-04 01:38:45 +00:00
|
|
|
* Additional copyrights may follow
|
2015-06-23 20:59:57 -07:00
|
|
|
*
|
2014-02-04 01:38:45 +00:00
|
|
|
* $HEADER$
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "opal_config.h"
|
|
|
|
#include "opal/constants.h"
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "opal_stdint.h"
|
|
|
|
#include "opal/dss/dss_types.h"
|
|
|
|
#include "opal/util/error.h"
|
|
|
|
#include "opal/util/output.h"
|
|
|
|
#include "opal/util/show_help.h"
|
|
|
|
|
|
|
|
#include "opal/mca/sec/base/base.h"
|
|
|
|
#include "sec_basic.h"
|
|
|
|
|
|
|
|
static int init(void);
|
|
|
|
static void finalize(void);
|
2015-06-18 09:53:20 -07:00
|
|
|
static int get_my_cred(opal_process_name_t *my_id,
|
2015-03-28 20:34:26 -07:00
|
|
|
opal_sec_cred_t *cred);
|
2014-02-04 14:47:04 +00:00
|
|
|
static int authenticate(opal_sec_cred_t *cred);
|
2014-02-04 01:38:45 +00:00
|
|
|
|
|
|
|
opal_sec_base_module_t opal_sec_basic_module = {
|
|
|
|
init,
|
|
|
|
finalize,
|
2014-02-04 14:47:04 +00:00
|
|
|
get_my_cred,
|
2014-02-04 01:38:45 +00:00
|
|
|
authenticate
|
|
|
|
};
|
|
|
|
|
2014-02-04 14:47:04 +00:00
|
|
|
static opal_sec_cred_t my_cred;
|
|
|
|
static bool initialized = false;
|
|
|
|
|
2014-02-04 01:38:45 +00:00
|
|
|
static int init(void)
|
|
|
|
{
|
|
|
|
return OPAL_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void finalize(void)
|
|
|
|
{
|
2014-02-04 14:47:04 +00:00
|
|
|
if (initialized) {
|
|
|
|
free(my_cred.credential);
|
|
|
|
}
|
2014-02-04 01:38:45 +00:00
|
|
|
}
|
|
|
|
|
2015-06-18 09:53:20 -07:00
|
|
|
static int get_my_cred(opal_process_name_t *my_id,
|
2015-03-28 20:34:26 -07:00
|
|
|
opal_sec_cred_t *cred)
|
2014-02-04 01:38:45 +00:00
|
|
|
{
|
2014-02-04 14:47:04 +00:00
|
|
|
if (!initialized) {
|
2015-06-18 09:53:20 -07:00
|
|
|
/* make the default credential 7-bytes long so we hit a nice
|
|
|
|
* 8-byte alignment (including NULL terminator) to keep valgrind
|
|
|
|
* from barking in optimized builds
|
2014-02-04 14:47:04 +00:00
|
|
|
*/
|
2015-06-18 09:53:20 -07:00
|
|
|
my_cred.credential = strdup("1234567");
|
|
|
|
my_cred.size = strlen(my_cred.credential)+1; // include the NULL
|
2014-02-04 14:47:04 +00:00
|
|
|
}
|
|
|
|
initialized = true;
|
2014-02-04 01:38:45 +00:00
|
|
|
|
2015-03-28 20:34:26 -07:00
|
|
|
cred->method = strdup("basic");
|
|
|
|
cred->credential = strdup(my_cred.credential);
|
|
|
|
cred->size = my_cred.size;
|
2014-02-04 01:38:45 +00:00
|
|
|
|
|
|
|
return OPAL_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2014-02-04 14:47:04 +00:00
|
|
|
static int authenticate(opal_sec_cred_t *cred)
|
2014-02-04 01:38:45 +00:00
|
|
|
{
|
2015-03-28 20:34:26 -07:00
|
|
|
opal_output_verbose(5, opal_sec_base_framework.framework_output,
|
|
|
|
"opal_sec:basic Received credential %s of size %lu",
|
|
|
|
cred->credential, (unsigned long)cred->size);
|
2014-02-04 01:38:45 +00:00
|
|
|
|
2015-03-28 20:34:26 -07:00
|
|
|
if (0 == strncmp(cred->credential, "1234567", strlen("1234567"))) {
|
2014-02-04 14:47:04 +00:00
|
|
|
return OPAL_SUCCESS;
|
2014-02-04 01:38:45 +00:00
|
|
|
}
|
2014-02-04 14:47:04 +00:00
|
|
|
return OPAL_ERR_AUTHENTICATION_FAILED;
|
2014-02-04 01:38:45 +00:00
|
|
|
}
|
|
|
|
|