1
1
Этот коммит содержится в:
Ralph Castain 2016-06-01 20:56:07 -07:00
родитель bfcf145613
Коммит ecea1e3bb5
27 изменённых файлов: 807 добавлений и 391 удалений

Просмотреть файл

@ -43,6 +43,9 @@ Master (not on release branches yet)
- Do not install internal headers unless specifically
requested to do so
- Add support for multiple calls to Put/Commit
- Silence some "return code unchecked" warnings. Thanks
to Jim Garlick for pointing them out
- Resolve a race condition during register_clients
1.1.3

Просмотреть файл

@ -23,14 +23,14 @@ release=4
# The only requirement is that it must be entirely printable ASCII
# characters and have no white space.
greek=rc2
greek=rc3
# If repo_rev is empty, then the repository version number will be
# obtained during "make dist" via the "git describe --tags --always"
# command, or with the date (if "git describe" fails) in the form of
# "date<date>".
repo_rev=git65d985c
repo_rev=git4695e45
# If tarball_version is not empty, it is used as the version string in
# the tarball filename, regardless of all other versions listed in
@ -44,7 +44,7 @@ tarball_version=
# The date when this release was created
date="May 19, 2016"
date="Jun 01, 2016"
# The shared library version of each of PMIx's public libraries.
# These versions are maintained in accordance with the "Library

Просмотреть файл

@ -456,7 +456,11 @@ AC_DEFUN([PMIX_SETUP_CORE],[
#endif
])
#
AC_CHECK_MEMBERS([struct ucred.uid, struct ucred.cr_uid, struct sockpeercred.uid],
[], [],
[#include <sys/types.h>
#include <sys/socket.h> ])
# Check for ptrdiff type. Yes, there are platforms where
# sizeof(void*) != sizeof(long) (64 bit Windows, apparently).
#
@ -491,7 +495,7 @@ AC_DEFUN([PMIX_SETUP_CORE],[
# Darwin doesn't need -lm, as it's a symlink to libSystem.dylib
PMIX_SEARCH_LIBS_CORE([ceil], [m])
AC_CHECK_FUNCS([asprintf snprintf vasprintf vsnprintf strsignal socketpair strncpy_s usleep])
AC_CHECK_FUNCS([asprintf snprintf vasprintf vsnprintf strsignal socketpair strncpy_s usleep getpeereid])
# On some hosts, htonl is a define, so the AC_CHECK_FUNC will get
# confused. On others, it's in the standard library, but stubbed with

Просмотреть файл

@ -1,6 +1,6 @@
# -*- shell-script -*-
#
# Copyright (c) 2015 Intel, Inc. All rights reserved
# Copyright (c) 2015-2016 Intel, Inc. All rights reserved
# Copyright (c) 2015 Cisco Systems, Inc. All rights reserved.
# $COPYRIGHT$
#
@ -24,9 +24,9 @@ AC_DEFUN([PMIX_MUNGE_CONFIG],[
[Search for munge libraries in DIR ])])
pmix_munge_support=0
if test "$with_munge" != "no"; then
if test ! -z "$with_munge" && test "$with_munge" != "no"; then
AC_MSG_CHECKING([for munge in])
if test ! -z "$with_munge" && test "$with_munge" != "yes"; then
if test "$with_munge" != "yes"; then
if test -d $with_munge/include/munge; then
pmix_munge_dir=$with_munge/include/munge
else
@ -76,8 +76,8 @@ AC_DEFUN([PMIX_MUNGE_CONFIG],[
AC_MSG_RESULT([yes])
fi
AC_DEFINE_UNQUOTED([PMIX_HAVE_MUNGE], [$pmix_munge_support],
[Whether we have munge support or not])
AC_DEFINE_UNQUOTED([PMIX_WANT_MUNGE], [$pmix_munge_support],
[Whether we want munge support or not])
PMIX_VAR_SCOPE_POP
])dnl

Просмотреть файл

@ -27,9 +27,9 @@ AC_DEFUN([PMIX_SASL_CONFIG],[
[Search for sasl libraries in DIR ])])
pmix_sasl_support=0
if test "$with_sasl" != "no"; then
if test ! -z "$with_sasl" && test "$with_sasl" != "no"; then
AC_MSG_CHECKING([for sasl in])
if test ! -z "$with_sasl" && test "$with_sasl" != "yes"; then
if test "$with_sasl" != "yes"; then
pmix_sasl_dir=$with_sasl/include/sasl
if test -d $with_sasl/lib; then
pmix_sasl_libdir=$with_sasl/lib

Просмотреть файл

@ -61,7 +61,9 @@ int main(int argc, char **argv)
fprintf(stderr, "Client %s:%d universe size %d\n", myproc.nspace, myproc.rank, nprocs);
/* put a few values */
(void)asprintf(&tmp, "%s-%d-internal", myproc.nspace, myproc.rank);
if (0 > asprintf(&tmp, "%s-%d-internal", myproc.nspace, myproc.rank)) {
exit(1);
}
value.type = PMIX_UINT32;
value.data.uint32 = 1234;
if (PMIX_SUCCESS != (rc = PMIx_Store_internal(&myproc, tmp, &value))) {
@ -70,7 +72,9 @@ int main(int argc, char **argv)
}
free(tmp);
(void)asprintf(&tmp, "%s-%d-local", myproc.nspace, myproc.rank);
if (0 > asprintf(&tmp, "%s-%d-local", myproc.nspace, myproc.rank)) {
exit(1);
}
value.type = PMIX_UINT64;
value.data.uint64 = 1234;
if (PMIX_SUCCESS != (rc = PMIx_Put(PMIX_LOCAL, tmp, &value))) {
@ -79,7 +83,9 @@ int main(int argc, char **argv)
}
free(tmp);
(void)asprintf(&tmp, "%s-%d-remote", myproc.nspace, myproc.rank);
if (0 > asprintf(&tmp, "%s-%d-remote", myproc.nspace, myproc.rank)) {
exit(1);
}
value.type = PMIX_STRING;
value.data.string = "1234";
if (PMIX_SUCCESS != (rc = PMIx_Put(PMIX_REMOTE, tmp, &value))) {
@ -108,7 +114,9 @@ int main(int argc, char **argv)
/* check the returned data */
for (n=0; n < nprocs; n++) {
(void)asprintf(&tmp, "%s-%d-local", myproc.nspace, myproc.rank);
if (0 > asprintf(&tmp, "%s-%d-local", myproc.nspace, myproc.rank)) {
exit(1);
}
if (PMIX_SUCCESS != (rc = PMIx_Get(&myproc, tmp, NULL, 0, &val))) {
fprintf(stderr, "Client ns %s rank %d: PMIx_Get %s failed: %d\n", myproc.nspace, myproc.rank, tmp, rc);
goto done;
@ -128,7 +136,9 @@ int main(int argc, char **argv)
fprintf(stderr, "Client ns %s rank %d: PMIx_Get %s returned correct\n", myproc.nspace, myproc.rank, tmp);
PMIX_VALUE_RELEASE(val);
free(tmp);
(void)asprintf(&tmp, "%s-%d-remote", myproc.nspace, myproc.rank);
if (0 > asprintf(&tmp, "%s-%d-remote", myproc.nspace, myproc.rank)) {
exit(1);
}
if (PMIX_SUCCESS != (rc = PMIx_Get(&myproc, tmp, NULL, 0, &val))) {
fprintf(stderr, "Client ns %s rank %d: PMIx_Get %s failed: %d\n", myproc.nspace, myproc.rank, tmp, rc);
goto done;

Просмотреть файл

@ -117,7 +117,9 @@ int main(int argc, char **argv)
fprintf(stderr, "Client %s:%d universe size %d\n", myproc.nspace, myproc.rank, nprocs);
/* put a few values */
(void)asprintf(&tmp, "%s-%d-internal", myproc.nspace, myproc.rank);
if (0 > asprintf(&tmp, "%s-%d-internal", myproc.nspace, myproc.rank)) {
exit(1);
}
value.type = PMIX_UINT32;
value.data.uint32 = 1234;
if (PMIX_SUCCESS != (rc = PMIx_Store_internal(&myproc, tmp, &value))) {
@ -126,7 +128,9 @@ int main(int argc, char **argv)
}
free(tmp);
(void)asprintf(&tmp, "%s-%d-local", myproc.nspace, myproc.rank);
if (0 > asprintf(&tmp, "%s-%d-local", myproc.nspace, myproc.rank)) {
exit(1);
}
value.type = PMIX_UINT64;
value.data.uint64 = 1234;
if (PMIX_SUCCESS != (rc = PMIx_Put(PMIX_LOCAL, tmp, &value))) {
@ -135,7 +139,9 @@ int main(int argc, char **argv)
}
free(tmp);
(void)asprintf(&tmp, "%s-%d-remote", myproc.nspace, myproc.rank);
if (0 > asprintf(&tmp, "%s-%d-remote", myproc.nspace, myproc.rank)) {
exit(1);
}
value.type = PMIX_STRING;
value.data.string = "1234";
if (PMIX_SUCCESS != (rc = PMIx_Put(PMIX_REMOTE, tmp, &value))) {
@ -170,7 +176,9 @@ int main(int argc, char **argv)
/* get the committed data - ask for someone who doesn't exist as well */
num_gets = 0;
for (n=0; n <= nprocs; n++) {
(void)asprintf(&tmp, "%s-%d-local", myproc.nspace, n);
if (0 > asprintf(&tmp, "%s-%d-local", myproc.nspace, n)) {
exit(1);
}
(void)strncpy(proc.nspace, tmp, PMIX_MAX_NSLEN);
proc.rank = n;
if (PMIX_SUCCESS != (rc = PMIx_Get_nb(&proc, tmp,
@ -179,7 +187,9 @@ int main(int argc, char **argv)
goto done;
}
++num_gets;
(void)asprintf(&tmp, "%s-%d-remote", myproc.nspace, n);
if (0 > asprintf(&tmp, "%s-%d-remote", myproc.nspace, n)) {
exit(1);
}
(void)strncpy(proc.nspace, tmp, PMIX_MAX_NSLEN);
if (PMIX_SUCCESS != (rc = PMIx_Get_nb(&proc, tmp,
NULL, 0, valcbfunc, tmp))) {

Просмотреть файл

@ -50,8 +50,12 @@ int main(int argc, char **argv)
size_t npeers, ntmp=0;
char *nodelist;
gethostname(hostname, sizeof(hostname));
getcwd(dir, 1024);
if (0 > gethostname(hostname, sizeof(hostname))) {
exit(1);
}
if (NULL == getcwd(dir, 1024)) {
exit(1);
}
/* init us */
if (PMIX_SUCCESS != (rc = PMIx_Init(&myproc))) {
@ -81,11 +85,15 @@ int main(int argc, char **argv)
/* rank=0 calls spawn */
if (0 == myproc.rank) {
PMIX_APP_CREATE(app, 1);
(void)asprintf(&app->cmd, "%s/client", dir);
if (0 > asprintf(&app->cmd, "%s/client", dir)) {
exit(1);
}
app->maxprocs = 2;
app->argc = 1;
app->argv = (char**)malloc(2 * sizeof(char*));
(void)asprintf(&app->argv[0], "%s/client", dir);
if (0 > asprintf(&app->argv[0], "%s/client", dir)) {
exit(1);
}
app->argv[1] = NULL;
app->env = (char**)malloc(2 * sizeof(char*));
app->env[0] = strdup("PMIX_ENV_VALUE=3");

Просмотреть файл

@ -93,6 +93,9 @@ BEGIN_C_DECLS
#define PMIX_USERID "pmix.euid" // (uint32_t) effective user id
#define PMIX_GRPID "pmix.egid" // (uint32_t) effective group id
/* attributes for the rendezvous socket */
#define PMIX_SOCKET_MODE "pmix.sockmode" // (uint32_t) POSIX mode_t (9 bits valid)
/* general proc-level attributes */
#define PMIX_CPUSET "pmix.cpuset" // (char*) hwloc bitmap applied to proc upon launch
#define PMIX_CREDENTIAL "pmix.cred" // (char*) security credential assigned to proc

Просмотреть файл

@ -332,7 +332,9 @@ pmix_status_t pmix_bfrop_pack_float(pmix_buffer_t *buffer, const void *src,
char *convert;
for (i = 0; i < num_vals; ++i) {
asprintf(&convert, "%f", ssrc[i]);
if (0 > asprintf(&convert, "%f", ssrc[i])) {
return PMIX_ERR_NOMEM;
}
if (PMIX_SUCCESS != (ret = pmix_bfrop_pack_string(buffer, &convert, 1, PMIX_STRING))) {
free(convert);
return ret;
@ -353,7 +355,9 @@ pmix_status_t pmix_bfrop_pack_double(pmix_buffer_t *buffer, const void *src,
char *convert;
for (i = 0; i < num_vals; ++i) {
asprintf(&convert, "%f", ssrc[i]);
if (0 > asprintf(&convert, "%f", ssrc[i])) {
return PMIX_ERR_NOMEM;
}
if (PMIX_SUCCESS != (ret = pmix_bfrop_pack_string(buffer, &convert, 1, PMIX_STRING))) {
free(convert);
return ret;

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -648,7 +648,9 @@ PMIX_EXPORT int PMI_Spawn_multiple(int count,
}
/* push the preput values into the apps environ */
for (k = 0; k < preput_keyval_size; k++) {
(void)asprintf(&evar, "%s=%s", preput_keyval_vector[k].key, preput_keyval_vector[k].val);
if (0 > asprintf(&evar, "%s=%s", preput_keyval_vector[k].key, preput_keyval_vector[k].val)) {
return PMIX_ERR_NOMEM;
}
pmix_argv_append_nosize(&apps[i].env, evar);
free(evar);
}

Просмотреть файл

@ -199,7 +199,9 @@ PMIX_EXPORT int PMI2_Job_Spawn(int count, const char * cmds[],
}
/* push the preput values into the apps environ */
for (k=0; k < preput_keyval_size; k++) {
(void)asprintf(&evar, "%s=%s", preput_keyval_vector[j]->key, preput_keyval_vector[j]->val);
if (0 > asprintf(&evar, "%s=%s", preput_keyval_vector[j]->key, preput_keyval_vector[j]->val)) {
return PMIX_ERR_NOMEM;
}
pmix_argv_append_nosize(&apps[i].env, evar);
free(evar);
}

Просмотреть файл

@ -118,7 +118,7 @@ static int validate_cred(pmix_peer_t *peer, char *cred)
munge_err_t rc;
pmix_output_verbose(2, pmix_globals.debug_output,
"sec: munge validate_cred %s", cred);
"sec: munge validate_cred %s", cred ? cred : "NULL");
/* parse the inbound string */
if (EMUNGE_SUCCESS != (rc = munge_decode(cred, NULL, NULL, NULL, &uid, &gid))) {

Просмотреть файл

@ -12,6 +12,7 @@
#include <pmix/pmix_common.h>
#include "src/include/pmix_socket_errno.h"
#include "src/include/pmix_globals.h"
#include "src/util/argv.h"
#include "src/util/output.h"
@ -27,14 +28,13 @@
static int native_init(void);
static void native_finalize(void);
static char* create_cred(void);
static pmix_status_t validate_cred(pmix_peer_t *peer, char *cred);
pmix_sec_base_module_t pmix_native_module = {
"native",
native_init,
native_finalize,
create_cred,
NULL,
NULL,
validate_cred,
NULL
@ -53,56 +53,71 @@ static void native_finalize(void)
"sec: native finalize");
}
static char* create_cred(void)
{
char *cred;
pmix_output_verbose(2, pmix_globals.debug_output,
"sec: native create_cred");
/* print them and return the string */
(void)asprintf(&cred, "%lu:%lu", (unsigned long)pmix_globals.uid,
(unsigned long)pmix_globals.gid);
pmix_output_verbose(2, pmix_globals.debug_output,
"sec: using credential %s", cred);
return cred;
}
static pmix_status_t validate_cred(pmix_peer_t *peer, char *cred)
{
uid_t uid;
#if defined(SO_PEERCRED)
#ifdef HAVE_STRUCT_SOCKPEERCRED_UID
#define HAVE_STRUCT_UCRED_UID
struct sockpeercred ucred;
#else
struct ucred ucred;
#endif
socklen_t crlen = sizeof (ucred);
#endif
uid_t euid;
gid_t gid;
char **vals;
pmix_output_verbose(2, pmix_globals.debug_output,
"sec: native validate_cred %s", cred);
"sec: native validate_cred %s", cred ? cred : "NULL");
/* parse the inbound string */
vals = pmix_argv_split(cred, ':');
if (2 != pmix_argv_count(vals)) {
pmix_argv_free(vals);
#if defined(SO_PEERCRED) && (defined(HAVE_STRUCT_UCRED_UID) || defined(HAVE_STRUCT_UCRED_CR_UID))
/* Ignore received 'cred' and validate ucred for socket instead. */
pmix_output_verbose(2, pmix_globals.debug_output,
"sec:native checking getsockopt for peer credentials");
if (getsockopt (peer->sd, SOL_SOCKET, SO_PEERCRED, &ucred, &crlen) < 0) {
pmix_output_verbose(2, pmix_globals.debug_output,
"sec: getsockopt SO_PEERCRED failed: %s",
strerror (pmix_socket_errno));
return PMIX_ERR_INVALID_CRED;
}
#if defined(HAVE_STRUCT_UCRED_UID)
euid = ucred.uid;
gid = ucred.gid;
#else
euid = ucred.cr_uid;
gid = ucred.cr_gid;
#endif
#elif defined(HAVE_GETPEEREID)
pmix_output_verbose(2, pmix_globals.debug_output,
"sec:native checking getpeereid for peer credentials");
if (0 != getpeereid(peer->sd, &euid, &gid)) {
pmix_output_verbose(2, pmix_globals.debug_output,
"sec: getsockopt getpeereid failed: %s",
strerror (pmix_socket_errno));
return PMIX_ERR_INVALID_CRED;
}
#else
return PMIX_ERR_NOT_SUPPORTED;
#endif
/* check uid */
uid = strtoul(vals[0], NULL, 10);
if (uid != peer->info->uid) {
pmix_argv_free(vals);
if (euid != peer->info->uid) {
pmix_output_verbose(2, pmix_globals.debug_output,
"sec: socket cred contains invalid uid %u", euid);
return PMIX_ERR_INVALID_CRED;
}
/* check guid */
gid = strtoul(vals[1], NULL, 10);
/* check gid */
if (gid != peer->info->gid) {
pmix_argv_free(vals);
pmix_output_verbose(2, pmix_globals.debug_output,
"sec: socket cred contains invalid gid %u", gid);
return PMIX_ERR_INVALID_CRED;
}
pmix_argv_free(vals);
pmix_output_verbose(2, pmix_globals.debug_output,
"sec: native credential valid");
"sec: native credential %u:%u valid",
euid, gid);
return PMIX_SUCCESS;
}

Просмотреть файл

@ -45,7 +45,7 @@
#include "pmix_sec.h"
#include "src/sec/pmix_native.h"
#if PMIX_HAVE_MUNGE
#if PMIX_WANT_MUNGE
#include "src/sec/pmix_munge.h"
#endif
#
@ -61,12 +61,9 @@
#define PMIX_SEC_NAVAIL 3
static pmix_sec_base_module_t *all[] = {
#if PMIX_HAVE_MUNGE
/* Start the array with the least heavy option, if available */
#if PMIX_WANT_MUNGE
&pmix_munge_module,
#endif
/* Our native module should always be the lowest priority */
&pmix_native_module,
/* Always end the array with a NULL */

Просмотреть файл

@ -219,7 +219,9 @@ static pmix_status_t initialize_server_base(pmix_server_module_t *module)
/* now set the address - we use the pid here to reduce collisions */
memset(&myaddress, 0, sizeof(struct sockaddr_un));
myaddress.sun_family = AF_UNIX;
asprintf(&pmix_pid, "pmix-%d", pid);
if (0 > asprintf(&pmix_pid, "pmix-%d", pid)) {
return PMIX_ERR_NOMEM;
}
// If the above set temporary directory name plus the pmix-PID string
// plus the '/' separator are too long, just fail, so the caller
// may provide the user with a proper help... *Cough*, *Cough* OSX...
@ -229,7 +231,10 @@ static pmix_status_t initialize_server_base(pmix_server_module_t *module)
}
snprintf(myaddress.sun_path, sizeof(myaddress.sun_path)-1, "%s/%s", tdir, pmix_pid);
free(pmix_pid);
asprintf(&myuri, "%s:%lu:%s", pmix_globals.myid.nspace, (unsigned long)pmix_globals.myid.rank, myaddress.sun_path);
if (0 > asprintf(&myuri, "%s:%lu:%s", pmix_globals.myid.nspace,
(unsigned long)pmix_globals.myid.rank, myaddress.sun_path)) {
return PMIX_ERR_NOMEM;
}
pmix_output_verbose(2, pmix_globals.debug_output,
@ -245,6 +250,9 @@ PMIX_EXPORT pmix_status_t PMIx_server_init(pmix_server_module_t *module,
pmix_status_t rc;
size_t n;
pmix_kval_t kv;
uid_t sockuid = -1;
gid_t sockgid = -1;
mode_t sockmode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH;
++pmix_globals.init_cntr;
if (1 < pmix_globals.init_cntr) {
@ -272,10 +280,12 @@ PMIX_EXPORT pmix_status_t PMIx_server_init(pmix_server_module_t *module,
for (n=0; n < ninfo; n++) {
if (0 == strcmp(info[n].key, PMIX_USERID)) {
/* the userid is in the uint32_t storage */
chown(myaddress.sun_path, info[n].value.data.uint32, -1);
sockuid = info[n].value.data.uint32;
} else if (0 == strcmp(info[n].key, PMIX_GRPID)) {
/* the grpid is in the uint32_t storage */
chown(myaddress.sun_path, -1, info[n].value.data.uint32);
sockgid = info[n].value.data.uint32;
} else if (0 == strcmp(info[n].key, PMIX_SOCKET_MODE)) {
sockmode = info[n].value.data.uint32 & 0777;
}
}
}
@ -288,32 +298,29 @@ PMIX_EXPORT pmix_status_t PMIx_server_init(pmix_server_module_t *module,
pmix_list_append(&pmix_usock_globals.posted_recvs, &req->super);
/* start listening */
if (PMIX_SUCCESS != pmix_start_listening(&myaddress)) {
if (PMIX_SUCCESS != pmix_start_listening(&myaddress, sockmode, sockuid, sockgid)) {
PMIx_server_finalize();
return PMIX_ERR_INIT;
}
/* check the info keys for a directive about the uid/gid
* to be set for the rendezvous file, and any info we
/* check the info keys for info we
* need to provide to every client */
if (NULL != info) {
PMIX_CONSTRUCT(&kv, pmix_kval_t);
for (n=0; n < ninfo; n++) {
if (0 == strcmp(info[n].key, PMIX_USERID)) {
/* the userid is in the uint32_t storage */
chown(myaddress.sun_path, info[n].value.data.uint32, -1);
} else if (0 == strcmp(info[n].key, PMIX_GRPID)) {
/* the grpid is in the uint32_t storage */
chown(myaddress.sun_path, -1, info[n].value.data.uint32);
} else {
/* store and pass along to every client */
kv.key = info[n].key;
kv.value = &info[n].value;
if (PMIX_SUCCESS != (rc = pmix_bfrop.pack(&pmix_server_globals.gdata, &kv, 1, PMIX_KVAL))) {
PMIX_ERROR_LOG(rc);
PMIX_DESTRUCT(&kv);
return rc;
}
if (0 == strcmp(info[n].key, PMIX_USERID))
continue;
if (0 == strcmp(info[n].key, PMIX_GRPID))
continue;
if (0 == strcmp(info[n].key, PMIX_SOCKET_MODE))
continue;
/* store and pass along to every client */
kv.key = info[n].key;
kv.value = &info[n].value;
if (PMIX_SUCCESS != (rc = pmix_bfrop.pack(&pmix_server_globals.gdata, &kv, 1, PMIX_KVAL))) {
PMIX_ERROR_LOG(rc);
PMIX_DESTRUCT(&kv);
return rc;
}
}
/* protect the incoming data */
@ -723,10 +730,12 @@ void pmix_server_execute_collective(int sd, short args, void *cbdata)
static void _register_client(int sd, short args, void *cbdata)
{
pmix_setup_caddy_t *cd = (pmix_setup_caddy_t*)cbdata;
pmix_rank_info_t *info;
pmix_rank_info_t *info, *iptr, *iptr2;
pmix_nspace_t *nptr, *tmp;
pmix_server_trkr_t *trk;
pmix_trkr_caddy_t *tcd;
bool all_def;
size_t i;
pmix_output_verbose(2, pmix_globals.debug_output,
"pmix:server _register_client for nspace %s rank %d",
@ -772,8 +781,49 @@ static void _register_client(int sd, short args, void *cbdata)
if (trk->def_complete) {
continue;
}
/* see if any of our procs are involved - the tracker will
* have been created because a callback was received, but
* no rank info will have been entered since the clients
* had not yet been registered. Thus, we couldn't enter rank
* objects into the tracker as we didn't know which
* of the ranks were local */
for (i=0; i < trk->npcs; i++) {
if (0 != strncmp(cd->proc.nspace, trk->pcs[i].nspace, PMIX_MAX_NSLEN)) {
continue;
}
/* need to check if this rank is one of mine */
PMIX_LIST_FOREACH(iptr, &nptr->server->ranks, pmix_rank_info_t) {
if (PMIX_RANK_WILDCARD == trk->pcs[i].rank ||
iptr->rank == trk->pcs[i].rank) {
/* add a tracker for this proc - don't need more than
* the nspace pointer and rank */
iptr2 = PMIX_NEW(pmix_rank_info_t);
PMIX_RETAIN(info->nptr);
iptr2->nptr = info->nptr;
iptr2->rank = info->rank;
pmix_list_append(&trk->ranks, &iptr2->super);
/* track the count */
++trk->nlocal;
}
}
}
/* we need to know if this tracker is now complete - the only
* way to do this is to check if all participating
* nspaces are fully registered */
all_def = true;
/* search all the involved procs - fortunately, this
* list is usually very small */
PMIX_LIST_FOREACH(iptr, &trk->ranks, pmix_rank_info_t) {
if (!iptr->nptr->server->all_registered) {
/* nope */
all_def = false;
break;
}
}
/* update this tracker's status */
trk->def_complete = all_def;
/* is this now completed? */
if (pmix_list_get_size(&trk->local_cbs) == trk->nlocal) {
if (trk->def_complete && pmix_list_get_size(&trk->local_cbs) == trk->nlocal) {
/* it did, so now we need to process it
* we don't want to block someone
* here, so kick any completed trackers into a
@ -1531,7 +1581,9 @@ PMIX_EXPORT pmix_status_t PMIx_generate_regex(const char *input, char **regexp)
if (0 == pmix_list_get_size(&vreg->ranges)) {
if (NULL != vreg->prefix) {
/* solitary value */
asprintf(&tmp, "%s", vreg->prefix);
if (0 > asprintf(&tmp, "%s", vreg->prefix)) {
return PMIX_ERR_NOMEM;
}
pmix_argv_append_nosize(&regexargs, tmp);
free(tmp);
}
@ -1540,16 +1592,24 @@ PMIX_EXPORT pmix_status_t PMIx_generate_regex(const char *input, char **regexp)
}
/* start the regex for this value with the prefix */
if (NULL != vreg->prefix) {
asprintf(&tmp, "%s[%d:", vreg->prefix, vreg->num_digits);
if (0 > asprintf(&tmp, "%s[%d:", vreg->prefix, vreg->num_digits)) {
return PMIX_ERR_NOMEM;
}
} else {
asprintf(&tmp, "[%d:", vreg->num_digits);
if (0 > asprintf(&tmp, "[%d:", vreg->num_digits)) {
return PMIX_ERR_NOMEM;
}
}
/* add the ranges */
while (NULL != (range = (pmix_regex_range_t*)pmix_list_remove_first(&vreg->ranges))) {
if (1 == range->cnt) {
asprintf(&tmp2, "%s%d,", tmp, range->start);
if (0 > asprintf(&tmp2, "%s%d,", tmp, range->start)) {
return PMIX_ERR_NOMEM;
}
} else {
asprintf(&tmp2, "%s%d-%d,", tmp, range->start, range->start + range->cnt - 1);
if (0 > asprintf(&tmp2, "%s%d-%d,", tmp, range->start, range->start + range->cnt - 1)) {
return PMIX_ERR_NOMEM;
}
}
free(tmp);
tmp = tmp2;
@ -1559,7 +1619,9 @@ PMIX_EXPORT pmix_status_t PMIx_generate_regex(const char *input, char **regexp)
tmp[strlen(tmp)-1] = ']';
if (NULL != vreg->suffix) {
/* add in the suffix, if provided */
asprintf(&tmp2, "%s%s", tmp, vreg->suffix);
if (0 > asprintf(&tmp2, "%s%s", tmp, vreg->suffix)) {
return PMIX_ERR_NOMEM;
}
free(tmp);
tmp = tmp2;
}
@ -1570,7 +1632,9 @@ PMIX_EXPORT pmix_status_t PMIx_generate_regex(const char *input, char **regexp)
/* assemble final result */
tmp = pmix_argv_join(regexargs, ',');
asprintf(regexp, "pmix[%s]", tmp);
if (0 > asprintf(regexp, "pmix[%s]", tmp)) {
return PMIX_ERR_NOMEM;
}
free(tmp);
/* cleanup */
@ -1671,9 +1735,13 @@ PMIX_EXPORT pmix_status_t PMIx_generate_ppn(const char *input, char **regexp)
PMIX_LIST_FOREACH(vreg, &nodes, pmix_regex_value_t) {
while (NULL != (rng = (pmix_regex_range_t*)pmix_list_remove_first(&vreg->ranges))) {
if (1 == rng->cnt) {
asprintf(&tmp2, "%s%d,", tmp, rng->start);
if (0 > asprintf(&tmp2, "%s%d,", tmp, rng->start)) {
return PMIX_ERR_NOMEM;
}
} else {
asprintf(&tmp2, "%s%d-%d,", tmp, rng->start, rng->start + rng->cnt - 1);
if (0 > asprintf(&tmp2, "%s%d-%d,", tmp, rng->start, rng->start + rng->cnt - 1)) {
return PMIX_ERR_NOMEM;
}
}
free(tmp);
tmp = tmp2;

Просмотреть файл

@ -71,7 +71,8 @@ static pthread_t engine;
/*
* start listening on our rendezvous file
*/
pmix_status_t pmix_start_listening(struct sockaddr_un *address)
pmix_status_t pmix_start_listening(struct sockaddr_un *address,
mode_t mode, uid_t sockuid, gid_t sockgid)
{
int flags;
pmix_status_t rc;
@ -90,27 +91,32 @@ pmix_status_t pmix_start_listening(struct sockaddr_un *address)
printf("%s:%d bind() failed\n", __FILE__, __LINE__);
return PMIX_ERROR;
}
/* chown as required */
if (0 != chown(address->sun_path, sockuid, sockgid)) {
pmix_output(0, "CANNOT CHOWN socket %s: %s", address->sun_path, strerror (errno));
goto sockerror;
}
/* set the mode as required */
if (0 != chmod(address->sun_path, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH)) {
pmix_output(0, "CANNOT CHMOD %s", address->sun_path);
return PMIX_ERROR;
if (0 != chmod(address->sun_path, mode)) {
pmix_output(0, "CANNOT CHMOD socket %s: %s", address->sun_path, strerror (errno));
goto sockerror;
}
/* setup listen backlog to maximum allowed by kernel */
if (listen(pmix_server_globals.listen_socket, SOMAXCONN) < 0) {
printf("%s:%d listen() failed\n", __FILE__, __LINE__);
return PMIX_ERROR;
goto sockerror;
}
/* set socket up to be non-blocking, otherwise accept could block */
if ((flags = fcntl(pmix_server_globals.listen_socket, F_GETFL, 0)) < 0) {
printf("%s:%d fcntl(F_GETFL) failed\n", __FILE__, __LINE__);
return PMIX_ERROR;
goto sockerror;
}
flags |= O_NONBLOCK;
if (fcntl(pmix_server_globals.listen_socket, F_SETFL, flags) < 0) {
printf("%s:%d fcntl(F_SETFL) failed\n", __FILE__, __LINE__);
return PMIX_ERROR;
goto sockerror;
}
/* setup my version for validating connections - we
@ -156,6 +162,11 @@ pmix_status_t pmix_start_listening(struct sockaddr_un *address)
}
return PMIX_SUCCESS;
sockerror:
(void)close(pmix_server_globals.listen_socket);
pmix_server_globals.listen_socket = -1;
return PMIX_ERROR;
}
void pmix_stop_listening(void)
@ -176,7 +187,9 @@ void pmix_stop_listening(void)
* case the thread is blocked in a call to select for
* a long time */
i=1;
write(pmix_server_globals.stop_thread[1], &i, sizeof(int));
if (0 > write(pmix_server_globals.stop_thread[1], &i, sizeof(int))) {
return;
}
/* wait for thread to exit */
pthread_join(engine, NULL);
/* close the socket to remove the connection point */
@ -295,6 +308,42 @@ static void listener_cb(int incoming_sd)
event_active(&pending_connection->ev, EV_WRITE, 1);
}
/* Parse init-ack message:
* NSPACE<0><rank>VERSION<0>[CRED<0>]
*/
static pmix_status_t parse_connect_ack (char *msg, int len,
char **nspace, int *rank,
char **version, char **cred)
{
if ((int)strnlen (msg, len) < len) {
*nspace = msg;
msg += strlen(*nspace) + 1;
len -= strlen(*nspace) + 1;
} else
return PMIX_ERR_BAD_PARAM;
if ((int)sizeof(int) <= len) {
*rank = *(int *)msg;
msg += sizeof(int);
len -= sizeof(int);
} else
return PMIX_ERR_BAD_PARAM;
if ((int)strnlen (msg, len) < len) {
*version = msg;
msg += strlen(*version) + 1;
len -= strlen(*version) + 1;
} else
return PMIX_ERR_BAD_PARAM;
if ((int)strnlen (msg, len) < len)
*cred = msg;
else
*cred = NULL;
return PMIX_SUCCESS;
}
/* Receive the peer's identification info from a newly
* connected socket and verify the expected response.
*/
@ -308,7 +357,6 @@ static pmix_status_t pmix_server_authenticate(int sd, int *out_rank,
pmix_nspace_t *nptr, *tmp;
pmix_rank_info_t *info;
pmix_peer_t *psave = NULL;
size_t csize;
bool found;
pmix_proc_t proc;
@ -341,44 +389,22 @@ static pmix_status_t pmix_server_authenticate(int sd, int *out_rank,
return PMIX_ERR_UNREACH;
}
/* get the nspace */
nspace = msg; // a NULL terminator is in the data
/* get the rank */
memcpy(&rank, msg+strlen(nspace)+1, sizeof(int));
if (PMIX_SUCCESS != (rc = parse_connect_ack (msg, hdr.nbytes, &nspace,
&rank, &version, &cred))) {
pmix_output_verbose(2, pmix_globals.debug_output,
"error parsing connect-ack from client ON SOCKET %d", sd);
free(msg);
return rc;
}
pmix_output_verbose(2, pmix_globals.debug_output,
"connect-ack recvd from peer %s:%d",
nspace, rank);
"connect-ack recvd from peer %s:%d:%s",
nspace, rank, version);
/* do not check the version - we only retain it at this
* time in case we need to check it at some future date.
* For now, our intent is to retain backward compatibility
* and so we will assume that all versions are compatible. */
csize = strlen(nspace)+1+sizeof(int);
version = (char*)(msg+csize);
csize += strlen(version) + 1; // position ourselves before modifiying version
#if 0
/* find the first '.' */
ptr = strchr(version, '.');
if (NULL != ptr) {
++ptr;
/* stop it at the second '.', if present */
if (NULL != (ptr = strchr(ptr, '.'))) {
*ptr = '\0';
}
}
if (0 != strcmp(version, myversion)) {
pmix_output_verbose(2, pmix_globals.debug_output,
"pmix:server client/server PMIx versions mismatch - server %s client %s",
myversion, version);
free(msg);
return PMIX_ERR_NOT_SUPPORTED;
}
pmix_output_verbose(2, pmix_globals.debug_output,
"connect-ack version from client matches ours");
#endif
/* see if we know this nspace */
nptr = NULL;
@ -429,21 +455,18 @@ static pmix_status_t pmix_server_authenticate(int sd, int *out_rank,
}
/* see if there is a credential */
if (csize < hdr.nbytes) {
cred = (char*)(msg + csize);
if (NULL != cred && NULL != pmix_sec.validate_cred) {
if (PMIX_SUCCESS != (rc = pmix_sec.validate_cred(psave, cred))) {
pmix_output_verbose(2, pmix_globals.debug_output,
"validation of client credential failed");
free(msg);
pmix_pointer_array_set_item(&pmix_server_globals.clients, psave->index, NULL);
PMIX_RELEASE(psave);
/* send an error reply to the client */
goto error;
}
if (NULL != pmix_sec.validate_cred) {
if (PMIX_SUCCESS != (rc = pmix_sec.validate_cred(psave, cred))) {
pmix_output_verbose(2, pmix_globals.debug_output,
"client credential validated");
"validation of client credential failed");
free(msg);
pmix_pointer_array_set_item(&pmix_server_globals.clients, psave->index, NULL);
PMIX_RELEASE(psave);
/* send an error reply to the client */
goto error;
}
pmix_output_verbose(2, pmix_globals.debug_output,
"client credential validated");
}
free(msg);

Просмотреть файл

@ -147,7 +147,8 @@ typedef struct {
} while (0)
pmix_status_t pmix_start_listening(struct sockaddr_un *address);
pmix_status_t pmix_start_listening(struct sockaddr_un *address,
mode_t mode, uid_t sockuid, gid_t sockgid);
void pmix_stop_listening(void);
bool pmix_server_trk_update(pmix_server_trkr_t *trk);

Просмотреть файл

@ -1,6 +1,6 @@
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
/*
* Copyright (c) 2014-2015 Intel, Inc. All rights reserved.
* Copyright (c) 2014-2016 Intel, Inc. All rights reserved.
* Copyright (c) 2014-2015 Research Organization for Information Science
* and Technology (RIST). All rights reserved.
* Copyright (c) 2014 Artem Y. Polyakov <artpol84@gmail.com>.
@ -528,7 +528,9 @@ static pmix_status_t pmix_regex_extract_ppn(char *regexp, char ***procs)
++t;
end = strtol(t, NULL, 10);
for (k=start; k <= end; k++) {
asprintf(&t, "%d", k);
if (0 > asprintf(&t, "%d", k)) {
return PMIX_ERR_NOMEM;
}
pmix_argv_append_nosize(&ps, t);
free(t);
}

Просмотреть файл

@ -207,8 +207,8 @@ pmix_status_t pmix_lookup_errhandler(pmix_notification_fn_t err,
int *index)
{
int i;
pmix_error_reg_info_t *errreg;
pmix_status_t rc = PMIX_ERR_NOT_FOUND;
pmix_error_reg_info_t *errreg = NULL;
for (i = 0; i < pmix_pointer_array_get_size(&pmix_globals.errregs) ; i++) {
errreg = (pmix_error_reg_info_t*)pmix_pointer_array_get_item(&pmix_globals.errregs, i);

Просмотреть файл

@ -10,7 +10,7 @@
* Copyright (c) 2004-2006 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 2007-2008 Cisco Systems, Inc. All rights reserved.
* Copyright (c) 2014-2015 Intel, Inc. All rights reserved.
* Copyright (c) 2014-2016 Intel, Inc. All rights reserved.
* Copyright (c) 2015 Research Organization for Information Science
* and Technology (RIST). All rights reserved.
* $COPYRIGHT$
@ -176,7 +176,9 @@ bool pmix_output_init(void)
}
gethostname(hostname, sizeof(hostname));
hostname[sizeof(hostname)-1] = '\0';
asprintf(&verbose.lds_prefix, "[%s:%05d] ", hostname, getpid());
if (0 > asprintf(&verbose.lds_prefix, "[%s:%05d] ", hostname, getpid())) {
return PMIX_ERR_NOMEM;
}
for (i = 0; i < PMIX_OUTPUT_MAX_STREAMS; ++i) {
info[i].ldi_used = false;
@ -195,7 +197,9 @@ bool pmix_output_init(void)
/* Set some defaults */
asprintf(&output_prefix, "output-pid%d-", getpid());
if (0 > asprintf(&output_prefix, "output-pid%d-", getpid())) {
return false;
}
output_dir = strdup(pmix_tmp_directory());
/* Open the default verbose stream */
@ -264,48 +268,10 @@ void pmix_output_reopen_all(void)
free(verbose.lds_prefix);
verbose.lds_prefix = NULL;
}
asprintf(&verbose.lds_prefix, "[%s:%05d] ", hostname, getpid());
#if 0
int i;
pmix_output_stream_t lds;
for (i = 0; i < PMIX_OUTPUT_MAX_STREAMS; ++i) {
/* scan till we find ldi_used == 0, which is the end-marker */
if (!info[i].ldi_used) {
break;
}
/*
* set this to zero to ensure that pmix_output_open will
* return this same index as the output stream id
*/
info[i].ldi_used = false;
#if USE_SYSLOG
lds.lds_want_syslog = info[i].ldi_syslog;
lds.lds_syslog_priority = info[i].ldi_syslog_priority;
lds.lds_syslog_ident = info[i].ldi_syslog_ident;
#else
lds.lds_want_syslog = false;
#endif
lds.lds_prefix = info[i].ldi_prefix;
lds.lds_suffix = info[i].ldi_suffix;
lds.lds_want_stdout = info[i].ldi_stdout;
lds.lds_want_stderr = info[i].ldi_stderr;
lds.lds_want_file = (-1 == info[i].ldi_fd) ? false : true;
/* open all streams in append mode */
lds.lds_want_file_append = true;
lds.lds_file_suffix = info[i].ldi_file_suffix;
/*
* call pmix_output_open to open the stream. The return value
* is guaranteed to be i. So we can ignore it.
*/
pmix_output_open(&lds);
if (0 > asprintf(&verbose.lds_prefix, "[%s:%05d] ", hostname, getpid())) {
verbose.lds_prefix = NULL;
return;
}
#endif
}
@ -854,7 +820,9 @@ static int make_string(char **no_newline_string, output_desc_t *ldi,
/* Make the formatted string */
vasprintf(no_newline_string, format, arglist);
if (0 > vasprintf(no_newline_string, format, arglist)) {
return PMIX_ERR_NOMEM;
}
total_len = len = strlen(*no_newline_string);
if ('\n' != (*no_newline_string)[len - 1]) {
want_newline = true;
@ -962,15 +930,19 @@ static int output(int output_id, const char *format, va_list arglist)
/* stdout output */
if (ldi->ldi_stdout) {
write(fileno(stdout), out, (int)strlen(out));
if (0 > write(fileno(stdout), out, (int)strlen(out))) {
return PMIX_ERROR;
}
fflush(stdout);
}
/* stderr output */
if (ldi->ldi_stderr) {
write((-1 == default_stderr_fd) ?
fileno(stderr) : default_stderr_fd,
out, (int)strlen(out));
if (0 > write((-1 == default_stderr_fd) ?
fileno(stderr) : default_stderr_fd,
out, (int)strlen(out))) {
return PMIX_ERROR;
}
fflush(stderr);
}
@ -990,7 +962,9 @@ static int output(int output_id, const char *format, va_list arglist)
snprintf(buffer, BUFSIZ - 1,
"[WARNING: %d lines lost because the PMIx process session directory did\n not exist when pmix_output() was invoked]\n",
ldi->ldi_file_num_lines_lost);
write(ldi->ldi_fd, buffer, (int)strlen(buffer));
if (0 > write(ldi->ldi_fd, buffer, (int)strlen(buffer))) {
return PMIX_ERROR;
}
ldi->ldi_file_num_lines_lost = 0;
if (out != buffer) {
free(out);
@ -998,7 +972,9 @@ static int output(int output_id, const char *format, va_list arglist)
}
}
if (ldi->ldi_fd != -1) {
write(ldi->ldi_fd, out, (int)strlen(out));
if (0 > write(ldi->ldi_fd, out, (int)strlen(out))) {
return PMIX_ERROR;
}
}
}
free(str);

Просмотреть файл

@ -12,7 +12,7 @@
* Copyright (c) 2006 Cisco Systems, Inc. All rights reserved.
* Copyright (c) 2007-2013 Los Alamos National Security, LLC. All rights
* reserved.
* Copyright (c) 2014-2015 Intel, Inc. All rights reserved.
* Copyright (c) 2014-2016 Intel, Inc. All rights reserved.
* Copyright (c) 2016 IBM Corporation. All rights reserved.
* $COPYRIGHT$
*
@ -103,11 +103,11 @@ char **pmix_environ_merge(char **minor, char **major)
/* Make the new value */
if (NULL == value) {
asprintf(&newvalue, "%s=", name);
i = asprintf(&newvalue, "%s=", name);
} else {
asprintf(&newvalue, "%s=%s", name, value);
i = asprintf(&newvalue, "%s=%s", name, value);
}
if (NULL == newvalue) {
if (NULL == newvalue || 0 > i) {
return PMIX_ERR_OUT_OF_RESOURCE;
}
@ -135,8 +135,8 @@ char **pmix_environ_merge(char **minor, char **major)
/* Make something easy to compare to */
asprintf(&compare, "%s=", name);
if (NULL == compare) {
i = asprintf(&compare, "%s=", name);
if (NULL == compare || 0 > i) {
free(newvalue);
return PMIX_ERR_OUT_OF_RESOURCE;
}
@ -191,8 +191,8 @@ char **pmix_environ_merge(char **minor, char **major)
/* Make something easy to compare to */
asprintf(&compare, "%s=", name);
if (NULL == compare) {
i = asprintf(&compare, "%s=", name);
if (NULL == compare || 0 > i) {
return PMIX_ERR_OUT_OF_RESOURCE;
}
len = strlen(compare);

Просмотреть файл

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014-2015 Intel, Inc. All rights reserved.
* Copyright (c) 2014-2016 Intel, Inc. All rights reserved.
* Copyright (c) 2015 Research Organization for Information Science
* and Technology (RIST). All rights reserved.
* Copyright (c) 2016 Mellanox Technologies, Inc.
@ -113,7 +113,9 @@ void pmix_stop_progress_thread(pmix_event_base_t *ev_base)
* a long time */
if (block_active) {
i=1;
write(block_pipe[1], &i, sizeof(int));
if (0 > write(block_pipe[1], &i, sizeof(int))) {
return;
}
}
/* break the event loop - this will cause the loop to exit
* upon completion of any current event */

Просмотреть файл

@ -29,6 +29,7 @@ headers = test_common.h cli_stages.h server_callbacks.h utils.h test_fence.h tes
AM_CPPFLAGS = -I$(top_builddir)/src -I$(top_builddir)/src/include -I$(top_builddir)/src/api
noinst_SCRIPTS = pmix_client_otheruser.sh
noinst_PROGRAMS = pmi_client pmi2_client
if !WANT_HIDDEN
noinst_PROGRAMS += pmix_test pmix_client pmix_regex
@ -64,3 +65,4 @@ pmix_regex_LDFLAGS = $(PMIX_PKG_CONFIG_LDFLAGS)
pmix_regex_LDADD = \
$(top_builddir)/libpmix.la
EXTRA_DIST = $(noinst_SCRIPTS)

Просмотреть файл

@ -0,0 +1,19 @@
#!/bin/bash
OTHERUSER=dummy
# To test sec:native we run client as a different user e.g.
#
# ./pmix_test -e ./pmix_client_otheruser.sh
#
# Prerequisites:
# - ensure directories leading up to source tree are o+x
# - add dummy user and set OTHERUSER to its name
# - give yourself passwordless sudo capability to that user
#
# The test should fail with message similar to
# PMIX ERROR: INVALID-CREDENTIAL in file
# ../src/server/pmix_server_listener.c at line 524
#
sudo --user $OTHERUSER --preserve-env ./pmix_client $*

Просмотреть файл

@ -81,7 +81,12 @@ int main(int argc, char **argv)
}
/* setup the server library */
if (PMIX_SUCCESS != (rc = PMIx_server_init(&mymodule, NULL, 0))) {
pmix_info_t info[1];
(void)strncpy(info[0].key, PMIX_SOCKET_MODE, PMIX_MAX_KEYLEN);
info[0].value.type = PMIX_UINT32;
info[0].value.data.uint32 = 0666;
if (PMIX_SUCCESS != (rc = PMIx_server_init(&mymodule, info, 1))) {
TEST_ERROR(("Init failed with error %d", rc));
FREE_TEST_PARAMS(params);
return rc;