int smpd_set_user_data(const char *key, const char *value)
{
#ifdef HAVE_WINDOWS_H
    HKEY tkey;
    DWORD len, result;
    char err_msg[512];

    smpd_enter_fn(FCNAME);

    if (key == NULL || value == NULL)
    {
	smpd_exit_fn(FCNAME);
	return SMPD_FAIL;
    }

    result = RegCreateKeyEx(HKEY_CURRENT_USER, SMPD_REGISTRY_KEY,
	0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &tkey, NULL);
    if (result != ERROR_SUCCESS)
    {
	smpd_translate_win_error(result, err_msg, 512, "Unable to open the HKEY_CURRENT_USER\\" SMPD_REGISTRY_KEY " registry key, error %d: ", result);
	smpd_err_printf("%s\n", err_msg);
	smpd_exit_fn(FCNAME);
	return SMPD_FAIL;
    }

    len = (DWORD)(strlen(value)+1);
    result = RegSetValueEx(tkey, key, 0, REG_SZ, (const BYTE *)value, len);
    if (result != ERROR_SUCCESS)
    {
	smpd_translate_win_error(result, err_msg, 512, "Unable to write the user smpd registry value '%s:%s', error %d\n", key, value, result);
	smpd_err_printf("%s\n", err_msg);
	RegCloseKey(tkey);
	smpd_exit_fn(FCNAME);
	return SMPD_FAIL;
    }

    result = RegCloseKey(tkey);
    if (result != ERROR_SUCCESS)
    {
	smpd_translate_win_error(result, err_msg, 512, "Unable to close the HKEY_CURRENT_USER\\" SMPD_REGISTRY_KEY " registry key, error %d: ", result);
	smpd_err_printf("%s\n", err_msg);
	smpd_exit_fn(FCNAME);
	return SMPD_FAIL;
    }

    smpd_exit_fn(FCNAME);
    return SMPD_SUCCESS;
#else
    int result;
    smpd_enter_fn(FCNAME);
    result = smpd_set_smpd_data(key, value);
    smpd_exit_fn(FCNAME);
    return result;
#endif
}
int smpd_get_user_data(const char *key, char *value, int value_len)
{
#ifdef HAVE_WINDOWS_H
    HKEY tkey;
    DWORD len, result;
    char err_msg[512];

    smpd_enter_fn(FCNAME);

    result = RegOpenKeyEx(HKEY_CURRENT_USER, SMPD_REGISTRY_KEY, 0, KEY_READ, &tkey);
    if (result != ERROR_SUCCESS)
    {
	smpd_translate_win_error(result, err_msg, 512, "Unable to open the HKEY_CURRENT_USER\\" SMPD_REGISTRY_KEY " registry key, error %d\n", result);
	smpd_dbg_printf("%s\n", err_msg);
	result = smpd_get_user_data_default(key, value, value_len);
	smpd_exit_fn(FCNAME);
	return result;
    }

    len = value_len;
    result = RegQueryValueEx(tkey, key, 0, NULL, (unsigned char *)value, &len);
    if (result != ERROR_SUCCESS)
    {
	smpd_translate_win_error(result, err_msg, 512, "Unable to read the smpd registry key '%s', error %d\n", key, result);
	smpd_dbg_printf("%s\n", err_msg);
	RegCloseKey(tkey);
	result = smpd_get_user_data_default(key, value, value_len);
	smpd_exit_fn(FCNAME);
	return result;
    }

    result = RegCloseKey(tkey);
    if (result != ERROR_SUCCESS)
    {
	smpd_translate_win_error(result, err_msg, 512, "Unable to close the HKEY_CURRENT_USER\\" SMPD_REGISTRY_KEY " registry key, error %d: ", result);
	smpd_err_printf("%s\n", err_msg);
	smpd_exit_fn(FCNAME);
	return SMPD_FAIL;
    }

    smpd_exit_fn(FCNAME);
    return SMPD_SUCCESS;
#else
    int result;
    smpd_enter_fn(FCNAME);
    result = smpd_get_smpd_data(key, value, value_len);
    if (result != SMPD_SUCCESS)
    {
	result = smpd_get_user_data_default(key, value, value_len);
    }
    smpd_exit_fn(FCNAME);
    return result;
#endif
}
int smpd_delete_user_data(const char *key)
{
#ifdef HAVE_WINDOWS_H
    HKEY tkey;
    DWORD result;
    char err_msg[512];

    smpd_enter_fn(FCNAME);

    if (key == NULL)
    {
	smpd_exit_fn(FCNAME);
	return SMPD_FAIL;
    }

    result = RegCreateKeyEx(HKEY_CURRENT_USER, SMPD_REGISTRY_KEY,
	0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &tkey, NULL);
    if (result != ERROR_SUCCESS)
    {
	smpd_translate_win_error(result, err_msg, 512, "Unable to open the HKEY_CURRENT_USER\\" SMPD_REGISTRY_KEY " registry key, error %d: ", result);
	smpd_err_printf("%s\n", err_msg);
	smpd_exit_fn(FCNAME);
	return SMPD_FAIL;
    }

    result = RegDeleteValue(tkey, key);
    if (result != ERROR_SUCCESS)
    {
	smpd_translate_win_error(result, err_msg, 512, "Unable to delete the user smpd registry value '%s', error %d: ", key, result);
	smpd_err_printf("%s\n", err_msg);
	RegCloseKey(tkey);
	smpd_exit_fn(FCNAME);
	return SMPD_FAIL;
    }

    result = RegCloseKey(tkey);
    if (result != ERROR_SUCCESS)
    {
	smpd_translate_win_error(result, err_msg, 512, "Unable to close the HKEY_CURRENT_USER\\" SMPD_REGISTRY_KEY " registry key, error %d: ", result);
	smpd_err_printf("%s\n", err_msg);
	smpd_exit_fn(FCNAME);
	return SMPD_FAIL;
    }

    smpd_exit_fn(FCNAME);
    return SMPD_SUCCESS;
#else
    int result;
    smpd_enter_fn(FCNAME);
    result = smpd_delete_smpd_data(key);
    smpd_exit_fn(FCNAME);
    return result;
#endif
}
Example #4
0
int smpd_hash(char *input, int input_length, char *output, int output_length)
{
    /*int i;*/
    unsigned char hash[MD5_DIGEST_LENGTH];

    smpd_enter_fn(FCNAME);

    if (output_length < (MD5_DIGEST_LENGTH * 2 + 1))
    {
	smpd_exit_fn(FCNAME);
	return SMPD_FAIL;
    }

#ifdef HAVE_MD5_CALC
    md5_calc(hash, (unsigned char *)input, (unsigned int)input_length);
#else
    MD5(input, input_length, hash);
#endif

    /*
    for (i=0; i<MD5_DIGEST_LENGTH; i++)
    {
	sprintf(output, "%02x", hash[i]);
	output += 2;
    }
    */
    sprintf(output, "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
	hash[0], hash[1], hash[2], hash[3], hash[4], hash[5], hash[6], hash[7],
	hash[8], hash[9], hash[10], hash[11], hash[12], hash[13], hash[14], hash[15]);

    smpd_exit_fn(FCNAME);
    return SMPD_SUCCESS;
}
int smpd_lock_smpd_data(void)
{
    smpd_enter_fn(FCNAME);
#ifdef HAVE_WINDOWS_H
    if (smpd_process.hSMPDDataMutex == NULL)
    {
	smpd_process.hSMPDDataMutex = CreateMutex(NULL, FALSE, SMPD_DATA_MUTEX_NAME);
	if (smpd_process.hSMPDDataMutex == NULL)
	{
	    smpd_exit_fn(FCNAME);
	    return SMPD_FAIL;
	}
    }
    if (WaitForSingleObject(smpd_process.hSMPDDataMutex, SMPD_SHORT_TIMEOUT*1000) != WAIT_OBJECT_0)
    {
	smpd_err_printf("lock_smpd_data failed\n");
	smpd_exit_fn(FCNAME);
	return SMPD_FAIL;
    }
#else
    /* No lock implemented for Unix systems */
#endif
    smpd_exit_fn(FCNAME);
    return SMPD_SUCCESS;
}
Example #6
0
int smpd_hpc_js_task_setenv(ISchedulerTask *ptask, char *proc_encoded_env)
{
    char name[SMPD_MAX_ENV_LENGTH], equals[3], value[SMPD_MAX_ENV_LENGTH];
    wchar_t namew[SMPD_MAX_ENV_LENGTH], valuew[SMPD_MAX_ENV_LENGTH];
    HRESULT hr;

    smpd_enter_fn(FCNAME);
    if((ptask == NULL) || (proc_encoded_env == NULL)){
        smpd_err_printf("Invalid ptr to task or proc environment\n");
        smpd_exit_fn(FCNAME);
        return SMPD_FAIL;
    }

    for (;;){
        name[0] = '\0';
        equals[0] = '\0';
        value[0] = '\0';
        if (MPIU_Str_get_string(&proc_encoded_env, name, SMPD_MAX_ENV_LENGTH) != MPIU_STR_SUCCESS)
            break;
        if (name[0] == '\0')
            break;
        if (MPIU_Str_get_string(&proc_encoded_env, equals, 3) != MPIU_STR_SUCCESS)
            break;
        if (equals[0] == '\0')
            break;
        if (MPIU_Str_get_string(&proc_encoded_env, value, SMPD_MAX_ENV_LENGTH) != MPIU_STR_SUCCESS)
            break;
        smpd_dbg_printf("setting environment variable: <%s> = <%s>\n", name, value);
        mbstowcs(namew, name, SMPD_MAX_ENV_LENGTH);
        mbstowcs(valuew, value, SMPD_MAX_ENV_LENGTH);
        hr = ptask->SetHpcEnvironmentVariable(_bstr_t(namew), _bstr_t(valuew));
    }
    smpd_exit_fn(FCNAME);
    return SMPD_SUCCESS;
}
int smpd_dbs_nextdb(char *name)
{
    smpd_enter_fn(FCNAME);

#ifdef USE_WIN_MUTEX_PROTECT
    WaitForSingleObject(smpd_process.hDBSMutex, INFINITE);
#endif

    if (smpd_process.pDatabaseIter == NULL)
	name[0] = '\0';
    else
    {
	smpd_process.pDatabaseIter = smpd_process.pDatabaseIter->pNext;
	if (smpd_process.pDatabaseIter)
	    strcpy(name, smpd_process.pDatabaseIter->pszName);
	else
	    name[0] = '\0';
    }

#ifdef USE_WIN_MUTEX_PROTECT
    ReleaseMutex(smpd_process.hDBSMutex);
#endif

    smpd_exit_fn(FCNAME);
    return SMPD_DBS_SUCCESS;
}
int smpd_get_opt_double(int *argc, char ***argv, char * flag, double *d)
{
    int i,j;

    smpd_enter_fn(FCNAME);
    if (flag == NULL)
    {
	smpd_exit_fn(FCNAME);
	return 0;
    }

    for (i=0; i<*argc; i++)
    {
	if (strcmp((*argv)[i], flag) == 0)
	{
	    if (i+1 == *argc)
	    {
		smpd_exit_fn(FCNAME);
		return 0;
	    }
	    *d = atof((*argv)[i+1]);
	    for (j=i; j<*argc-1; j++)
	    {
		(*argv)[j] = (*argv)[j+2];
	    }
	    *argc -= 2;
	    smpd_exit_fn(FCNAME);
	    return 1;
	}
    }
    smpd_exit_fn(FCNAME);
    return 0;
}
Example #9
0
int smpd_hpc_js_finalize(smpd_hpc_js_ctxt_t *pctxt)
{
    int result;
    smpd_enter_fn(FCNAME);

    if(pctxt == NULL){
        smpd_err_printf("ERROR: Invalid pointer to js ctxt\n");
        smpd_exit_fn(FCNAME);
        return SMPD_FAIL;
    }

    if(*pctxt == NULL){
        smpd_dbg_printf("Null js handle\n");
        smpd_exit_fn(FCNAME);
        return SMPD_SUCCESS;
    }

    /* Release the job scheduler object */
    if((*pctxt)->pscheduler){
        ((*pctxt)->pscheduler)->Release();
        (*pctxt)->pscheduler = NULL;
    }

    /* Free the job scheduler handle */
    MPIU_Free(*pctxt);
    *pctxt = NULL;

    smpd_exit_fn(FCNAME);
    return SMPD_SUCCESS;
}
Example #10
0
int smpd_get_opt(int *argc, char ***argv, char * flag)
{
    int i,j;

    smpd_enter_fn(FCNAME);
    if (flag == NULL)
    {
	smpd_exit_fn(FCNAME);
	return 0;
    }

    for (i=0; i<*argc; i++)
    {
	if (strcmp((*argv)[i], flag) == 0)
	{
	    for (j=i; j<*argc; j++)
	    {
		(*argv)[j] = (*argv)[j+1];
	    }
	    *argc -= 1;
	    smpd_exit_fn(FCNAME);
	    return 1;
	}
    }
    smpd_exit_fn(FCNAME);
    return 0;
}
Example #11
0
int smpd_spn_list_finalize(smpd_spn_list_hnd_t *spn_list_hnd_p)
{
    smpd_host_spn_node_t *spn_list_head, *cur_node;
    smpd_enter_fn(FCNAME);
    if(spn_list_hnd_p == NULL){
        smpd_err_printf("Invalid pointer to spn list handle\n");
        smpd_exit_fn(FCNAME);
        return SMPD_FAIL;
    }
    if(!SMPD_SPN_LIST_HND_IS_INIT(*spn_list_hnd_p)){
        smpd_dbg_printf("Trying to finalize an uninitialized handle\n");
        smpd_exit_fn(FCNAME);
        return SMPD_FAIL;
    }

    spn_list_head = **spn_list_hnd_p;
    while(spn_list_head != NULL){
        cur_node = spn_list_head;
        spn_list_head = cur_node->next;
        MPIU_Free(cur_node);
    }
    /* Free contents of the spn handle */
    MPIU_Free(*spn_list_hnd_p);

    *spn_list_hnd_p = NULL;

    smpd_exit_fn(FCNAME);
    return SMPD_SUCCESS;
}
Example #12
0
const char * smpd_get_string(const char *str, char *val, int maxlen, int *num_chars)
{
    smpd_enter_fn(FCNAME);
    if (maxlen < 1)
    {
	*num_chars = 0;
	smpd_exit_fn(FCNAME);
	return NULL;
    }

    /* line up with the first token */
    str = first_token(str);
    if (str == NULL)
    {
	*num_chars = 0;
	smpd_exit_fn(FCNAME);
	return NULL;
    }

    /* copy the token */
    token_copy(str, val, maxlen);
    *num_chars = (int)strlen(val);

    /* move to the next token */
    str = next_token(str);

    smpd_exit_fn(FCNAME);
    return str;
}
Example #13
0
int smpd_free_sspi_client_context(smpd_sspi_client_context_t **context)
{
    smpd_sspi_client_context_t *iter, *trailer;

    smpd_enter_fn(FCNAME);

    trailer = iter = smpd_process.sspi_context_list;
    while (iter)
    {
	if (iter == *context)
	{
	    if (trailer != iter)
	    {
		trailer->next = iter->next;
	    }
	    else
	    {
		smpd_process.sspi_context_list = iter->next;
	    }
	    break;
	}
	if (trailer != iter)
	    trailer = trailer->next;
	iter = iter->next;
    }
    if (iter == NULL)
    {
	smpd_dbg_printf("freeing a sspi_client_context not in the global list\n");
    }
    /* FIXME: cleanup sspi structures */
    MPIU_Free(*context);
    *context = NULL;
    smpd_exit_fn(FCNAME);
    return SMPD_SUCCESS;
}
Example #14
0
/* This function formats the environment strings of the form,
 *    foo1=bar1 foo2=bar2 foo3=bar3
 *    TO
 *     "foo1=bar1" "foo2=bar2" "foo3=bar3"
 *    and returns the length of the formatted string
 *    Note: The formatted string contains a space in the front
 */
static int FmtEnvVarsForSSH(char *bEnv, char *fmtEnv, int fmtEnvLen)
{
    char name[SMPD_MAX_ENV_LENGTH], equals[3], value[SMPD_MAX_ENV_LENGTH];
    int curLen = 0, totLen = 0;

    smpd_enter_fn(FCNAME);
    if(fmtEnv && bEnv){
     for (;;)
     {
	 name[0] = '\0';
	 equals[0] = '\0';
	 value[0] = '\0';
	 if(fmtEnvLen <= 0)
	     break;
	 if (MPIU_Str_get_string(&bEnv, name, SMPD_MAX_ENV_LENGTH) != MPIU_STR_SUCCESS)
	     break;
	 if (name[0] == '\0')
	     break;
	 if (MPIU_Str_get_string(&bEnv, equals, 3) != MPIU_STR_SUCCESS)
	     break;
	 if (equals[0] == '\0')
	     break;
	 if (MPIU_Str_get_string(&bEnv, value, SMPD_MAX_ENV_LENGTH) != MPIU_STR_SUCCESS)
	     break;
	 MPIU_Snprintf(fmtEnv, fmtEnvLen, " \"%s=%s\"", name, value);
	 curLen = strlen(fmtEnv);
	 totLen += curLen;
	 fmtEnv += curLen;
	 fmtEnvLen -= curLen;
     }
    }
    smpd_exit_fn(FCNAME);
    return totLen;
}
Example #15
0
void smpd_get_password(char *password)
{
#ifdef HAVE_WINDOWS_H
    HANDLE hStdin;
    DWORD dwMode;
#else
    struct termios terminal_settings, original_settings;
#endif
    size_t len;

    smpd_enter_fn(FCNAME);

#ifdef HAVE_WINDOWS_H

    hStdin = GetStdHandle(STD_INPUT_HANDLE);
    if (!GetConsoleMode(hStdin, &dwMode))
	dwMode = ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT | ENABLE_MOUSE_INPUT;
    SetConsoleMode(hStdin, dwMode & ~ENABLE_ECHO_INPUT);
    *password = '******';
    fgets(password, 100, stdin);
    SetConsoleMode(hStdin, dwMode);

    fprintf(stderr, "\n");

#else

    /* save the current terminal settings */
    tcgetattr(STDIN_FILENO, &terminal_settings);
    original_settings = terminal_settings;

    /* turn off echo */
    terminal_settings.c_lflag &= ~ECHO;
    terminal_settings.c_lflag |= ECHONL;
    tcsetattr(STDIN_FILENO, TCSAFLUSH, &terminal_settings);

    /* check that echo is off */
    tcgetattr(STDIN_FILENO, &terminal_settings);
    if (terminal_settings.c_lflag & ECHO)
    {
	smpd_err_printf("\nunable to turn off the terminal echo\n");
	tcsetattr(STDIN_FILENO, TCSANOW, &original_settings);
    }

    fgets(password, 100, stdin);

    /* restore the original settings */
    tcsetattr(STDIN_FILENO, TCSANOW, &original_settings);

#endif

    while ((len = strlen(password)) > 0)
    {
	if (password[len-1] == '\r' || password[len-1] == '\n')
	    password[len-1] = '\0';
	else
	    break;
    }
    smpd_exit_fn(FCNAME);
}
Example #16
0
int smpd_watch_processes()
{
    smpd_enter_fn(FCNAME);
    printf("Process watching not implemented under unix systems, exiting...\n");
    fflush(stdout);
    smpd_exit_fn(FCNAME);
    return SMPD_SUCCESS;
}
Example #17
0
int smpd_add_host_to_default_list(const char *hostname)
{
    int result;
    smpd_enter_fn(FCNAME);
    result = smpd_add_extended_host_to_default_list(hostname, NULL, 1);
    smpd_exit_fn(FCNAME);
    return result;
}
int smpd_dbsIter_finalize(smpd_dbsIter_t *pIter){
    smpd_enter_fn(FCNAME);
    if(pIter){
        *pIter = NULL;
    }
    smpd_exit_fn(FCNAME);
    return SMPD_DBS_SUCCESS;
}
Example #19
0
int smpd_get_smpd_password_from_parent(SMPDU_Sock_set_t set, SMPDU_Sock_t sock)
{
    smpd_enter_fn(FCNAME);
    SMPD_UNREFERENCED_ARG(set);
    SMPD_UNREFERENCED_ARG(sock);
    smpd_exit_fn(FCNAME);
    return SMPD_FAIL;
}
Example #20
0
int smpd_remove_from_dynamic_hosts(void)
{
#ifndef HAVE_WINDOWS_H
    char myhostname[SMPD_MAX_HOST_LENGTH];
    char hosts[8192];
    char hosts_less_me[8192];
    char *host;
#endif

    smpd_enter_fn(FCNAME);
#ifndef HAVE_WINDOWS_H
    if (smpd_get_hostname(myhostname, SMPD_MAX_HOST_LENGTH) != 0)
    {
	smpd_err_printf("smpd_get_hostname failed, errno = %d\n", errno);
	smpd_exit_fn(FCNAME);
	return SMPD_FAIL;
    }

    smpd_lock_smpd_data();

    hosts[0] = '\0';
    if (smpd_get_smpd_data(SMPD_DYNAMIC_HOSTS_KEY, hosts, 8192) != SMPD_SUCCESS)
    {
	smpd_unlock_smpd_data();
	smpd_dbg_printf("not removing host because "SMPD_DYNAMIC_HOSTS_KEY" does not exist\n");
	smpd_exit_fn(FCNAME);
	return SMPD_FAIL;
    }

    /* create a new hosts lists without this host name in it */
    hosts_less_me[0] = '\0';
    host = strtok(hosts, " \t\r\n");
    while (host)
    {
	if (strcmp(host, myhostname))
	{
	    if (hosts_less_me[0] != '\0')
		strcat(hosts_less_me, " ");
	    strcat(hosts_less_me, host);
	}
	host = strtok(NULL, " \t\r\n");
    }

    if (hosts_less_me[0] == '\0')
    {
	smpd_dbg_printf("removing "SMPD_DYNAMIC_HOSTS_KEY"\n");
	smpd_delete_smpd_data(SMPD_DYNAMIC_HOSTS_KEY);
    }
    else
    {
	smpd_dbg_printf("setting new "SMPD_DYNAMIC_HOSTS_KEY": %s\n", hosts_less_me);
	smpd_set_smpd_data(SMPD_DYNAMIC_HOSTS_KEY, hosts_less_me);
    }
    smpd_unlock_smpd_data();
#endif
    smpd_exit_fn(FCNAME);
    return SMPD_SUCCESS;
}
int smpd_get_smpd_data_default(const char *key, char *value, int value_len)
{
    smpd_enter_fn(FCNAME);
#ifdef HAVE_WINDOWS_H
    /* A default passphrase is only available for Windows */
    if (strcmp(key, "phrase") == 0)
    {
	strncpy(value, SMPD_DEFAULT_PASSPHRASE, value_len);
	value[value_len-1] = '\0';
	smpd_exit_fn(FCNAME);
	return SMPD_SUCCESS;
    }
    if(strcmp(key, "port") == 0)
    {
    snprintf(value, value_len, "%d", SMPD_LISTENER_PORT);
    smpd_exit_fn(FCNAME);
    return SMPD_SUCCESS;
    }
#endif
    if (strcmp(key, "log") == 0)
    {
	strncpy(value, "no", value_len);
	value[value_len-1] = '\0';
    }
    else if (strcmp(key, "prepend_rank") == 0)
    {
	strncpy(value, "yes", value_len);
	value[value_len-1] = '\0';
    }
    else if (strcmp(key, "trace") == 0)
    {
	strncpy(value, "yes", value_len);
	value[value_len-1] = '\0';
    }
    else if (strcmp(key, "noprompt") == 0)
    {
	strncpy(value, "no", value_len);
	value[value_len-1] = '\0';
    }
    /*
    else if (strcmp(key, "hosts") == 0)
    {
	if (smpd_get_hostname(value, value_len) != 0)
	{
	    smpd_exit_fn(FCNAME);
	    return SMPD_FAIL;
	}
    }
    */
    else
    {
	smpd_exit_fn(FCNAME);
	return SMPD_FAIL;
    }
    smpd_exit_fn(FCNAME);
    return SMPD_SUCCESS;
}
int smpd_get_user_data_default(const char *key, char *value, int value_len)
{
    smpd_enter_fn(FCNAME);
    /* FIXME: function not implemented */
    SMPD_UNREFERENCED_ARG(key);
    SMPD_UNREFERENCED_ARG(value);
    SMPD_UNREFERENCED_ARG(value_len);
    smpd_exit_fn(FCNAME);
    return SMPD_FAIL;
}
Example #23
0
int smpd_add_int_arg(char **str_ptr, int *maxlen_ptr, const char *flag, int val)
{
    int result;
    char val_str[12];
    smpd_enter_fn(FCNAME);
    sprintf(val_str, "%d", val);
    result = smpd_add_string_arg(str_ptr, maxlen_ptr, flag, val_str);
    smpd_exit_fn(FCNAME);
    return result;
}
SMPD_BOOL smpd_dbs_hasMoreKeys(smpd_dbsIter_t iter){
    smpd_enter_fn(FCNAME);
    if(iter){
        smpd_exit_fn(FCNAME);
        return SMPD_TRUE;
    }
    else{
        smpd_exit_fn(FCNAME);
        return SMPD_FALSE;
    }
}
static FILE * smpd_open_smpd_file(SMPD_BOOL create)
{
    char *homedir;
    struct stat s;
    FILE *fin = NULL;

    smpd_enter_fn(FCNAME);
    if (smpd_process.smpd_filename[0] == '\0')
    {
	homedir = getenv("HOME");
	if (homedir != NULL)
	{
	    strcpy(smpd_process.smpd_filename, homedir);
	    if (smpd_process.smpd_filename[strlen(smpd_process.smpd_filename)-1] != '/')
	    {
		strcat(smpd_process.smpd_filename, "/.smpd");
	    }
	    else
	    {
		strcat(smpd_process.smpd_filename, ".smpd");
	    }
	}
	else
	{
	    strcpy(smpd_process.smpd_filename, ".smpd");
	}
    }
    if (stat(smpd_process.smpd_filename, &s) == 0)
    {
	if (s.st_mode & 00077)
	{
	    printf(".smpd file, %s, cannot be readable by anyone other than the current user, please set the permissions accordingly (0600).\n", smpd_process.smpd_filename);
	}
	else
	{
	    if (create)
	    {
		fin = fopen(smpd_process.smpd_filename, "w");
	    }
	    else
	    {
		fin = fopen(smpd_process.smpd_filename, "r+");
	    }
	}
    }
    if (fin == NULL && create)
    {
	umask(077);
	fin = fopen(smpd_process.smpd_filename, "w");
    }
    smpd_exit_fn(FCNAME);
    return fin;
}
Example #26
0
int smpd_hpc_js_init(smpd_hpc_js_ctxt_t *pctxt)
{
    HRESULT hr;
    int result;

    smpd_enter_fn(FCNAME);

    if(pctxt == NULL){
        smpd_err_printf("ERROR: Invalid pointer to js handle\n");
        smpd_exit_fn(FCNAME);
        return SMPD_FAIL;
    }

    /* Alloc memory for scheduler object */
    *pctxt = (smpd_hpc_js_ctxt_t )MPIU_Malloc(sizeof(smpd_hpc_js_ctxt_));
    if(*pctxt == NULL){
        smpd_err_printf("ERROR: Unable to allocate memory for js handle\n");
        smpd_exit_fn(FCNAME);
        return SMPD_FAIL;
    }

    (*pctxt)->pscheduler = NULL;
    (*pctxt)->pnode_names = NULL;

    CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);

    /* Get an instance of the Scheduler object */
    hr = CoCreateInstance( __uuidof(Scheduler),
                           NULL,
                           CLSCTX_INPROC_SERVER,
                           __uuidof(IScheduler),
                           reinterpret_cast<void **>(&((*pctxt)->pscheduler)));

    CoUninitialize();

    if (FAILED(hr)){
        smpd_err_printf("ERROR: CoCreateInstance(IScheduler) failed, 0x%x\n", hr);
        smpd_exit_fn(FCNAME);
        return SMPD_FAIL;
    }

    /* Connect to the head node */
    result = smpd_hpc_js_connect_to_head_node(*pctxt, NULL);
    if(result != SMPD_SUCCESS){
        smpd_err_printf("Unable to connect to head node \n");
        smpd_exit_fn(FCNAME);
        return SMPD_FAIL;
    }

    smpd_exit_fn(FCNAME);
    return SMPD_SUCCESS;
}
int smpd_dbs_getNextKeyVal(smpd_dbsIter_t *pIter, char *key, char *value){
    smpd_enter_fn(FCNAME);
    if(!pIter || !(*pIter) || !key || !value){
        /* FIXME: Desc error msgs ?*/
        smpd_err_printf("Invalid args to smpd_dbs_getNextKeyVal()\n");
        return SMPD_DBS_FAIL;
    }
    MPIU_Strncpy(key, (*pIter)->pszKey, SMPD_MAX_DBS_KEY_LEN);
    MPIU_Strncpy(value, (*pIter)->pszValue, SMPD_MAX_DBS_VALUE_LEN);
    (*pIter) = (*pIter)->pNext;
    smpd_exit_fn(FCNAME);
    return SMPD_DBS_SUCCESS;
}
Example #28
0
int smpd_get_opt_two_strings(int *argc, char ***argv, char * flag, char *str1, int len1, char *str2, int len2)
{
    int i, j;

    smpd_enter_fn(FCNAME);
    if (flag == NULL)
    {
	smpd_exit_fn(FCNAME);
	return 0;
    }

    for (i=0; i<*argc; i++)
    {
	if (strcmp((*argv)[i], flag) == 0)
	{
	    if (i+1 == (*argc))
	    {
		smpd_exit_fn(FCNAME);
		return 0;
	    }
	    if ((*argv)[i+1][0] == '-')
	    {
		smpd_exit_fn(FCNAME);
		return 0;
	    }
	    if (i+2 == (*argc))
	    {
		smpd_exit_fn(FCNAME);
		return 0;
	    }
	    if ((*argv)[i+2][0] == '-')
	    {
		smpd_exit_fn(FCNAME);
		return 0;
	    }
	    strncpy(str1, (*argv)[i+1], len1);
	    str1[len1-1] = '\0';
	    strncpy(str2, (*argv)[i+2], len2);
	    str2[len2-1] = '\0';
	    for (j=i; j<(*argc)-2; j++)
	    {
		(*argv)[j] = (*argv)[j+3];
	    }
	    *argc -= 3;
	    smpd_exit_fn(FCNAME);
	    return 1;
	}
    }
    smpd_exit_fn(FCNAME);
    return 0;
}
int smpd_dbs_delete(const char *name, const char *key)
{
    smpd_database_node_t *pNode;
    smpd_database_element_t *pElement, *pElementTrailer;

    smpd_enter_fn(FCNAME);

#ifdef USE_WIN_MUTEX_PROTECT
    WaitForSingleObject(smpd_process.hDBSMutex, INFINITE);
#endif

    pNode = smpd_process.pDatabase;
    while (pNode)
    {
	if (strcmp(pNode->pszName, name) == 0)
	{
	    pElementTrailer = pElement = pNode->pData;
	    while (pElement)
	    {
		if (strcmp(pElement->pszKey, key) == 0)
		{
		    if (pElementTrailer != pElement)
			pElementTrailer->pNext = pElement->pNext;
		    else
			pNode->pData = pElement->pNext;
		    MPIU_Free(pElement);
#ifdef USE_WIN_MUTEX_PROTECT
		    ReleaseMutex(smpd_process.hDBSMutex);
#endif
		    smpd_exit_fn(FCNAME);
		    return SMPD_DBS_SUCCESS;
		}
		pElementTrailer = pElement;
		pElement = pElement->pNext;
	    }
#ifdef USE_WIN_MUTEX_PROTECT
	    ReleaseMutex(smpd_process.hDBSMutex);
#endif
	    smpd_exit_fn(FCNAME);
	    return SMPD_DBS_FAIL;
	}
	pNode = pNode->pNext;
    }

#ifdef USE_WIN_MUTEX_PROTECT
    ReleaseMutex(smpd_process.hDBSMutex);
#endif

    smpd_exit_fn(FCNAME);
    return SMPD_DBS_FAIL;
}
int smpd_dbs_put(const char *name, const char *key, const char *value)
{
    smpd_database_node_t *pNode;
    smpd_database_element_t *pElement;

    smpd_enter_fn(FCNAME);

#ifdef USE_WIN_MUTEX_PROTECT
    WaitForSingleObject(smpd_process.hDBSMutex, INFINITE);
#endif

    pNode = smpd_process.pDatabase;
    while (pNode)
    {
	if (strcmp(pNode->pszName, name) == 0)
	{
	    pElement = pNode->pData;
	    while (pElement)
	    {
		if (strcmp(pElement->pszKey, key) == 0)
		{
		    strcpy(pElement->pszValue, value);
#ifdef USE_WIN_MUTEX_PROTECT
		    ReleaseMutex(smpd_process.hDBSMutex);
#endif
		    smpd_exit_fn(FCNAME);
		    return SMPD_DBS_SUCCESS;
		}
		pElement = pElement->pNext;
	    }
	    pElement = (smpd_database_element_t*)MPIU_Malloc(sizeof(smpd_database_element_t));
	    pElement->pNext = pNode->pData;
	    strcpy(pElement->pszKey, key);
	    strcpy(pElement->pszValue, value);
	    pNode->pData = pElement;
#ifdef USE_WIN_MUTEX_PROTECT
	    ReleaseMutex(smpd_process.hDBSMutex);
#endif
	    smpd_exit_fn(FCNAME);
	    return SMPD_DBS_SUCCESS;
	}
	pNode = pNode->pNext;
    }

#ifdef USE_WIN_MUTEX_PROTECT
    ReleaseMutex(smpd_process.hDBSMutex);
#endif

    smpd_exit_fn(FCNAME);
    return SMPD_DBS_FAIL;
}