/****** sge_binding_hlp/get_explicit_amount() ********************************** * NAME * get_explicit_amount() -- Counts the amount of <socket,core> pairs. * * SYNOPSIS * int get_explicit_amount(const char* expl) * * FUNCTION * Counts the amount of <socket,core> pairs in the binding explicit request. * * INPUTS * const char* expl - pointer to explicit binding request string * const bool with_explicit_prefix - does string start with "explicit:"? * * RESULT * int - amount of <socket,core> pairs in explicit binding request string * * NOTES * MT-NOTE: get_explicit_amount() is MT safe * * SEE ALSO * sge_binding_hlp/check_explicit_binding_string() *******************************************************************************/ int get_explicit_amount(const char* expl, const bool with_explicit_prefix) { int amount = 0; char* pair = NULL; struct saved_vars_s* context = NULL; if (expl == NULL) { return amount; } pair = sge_strtok_r(expl, ":", &context); if (pair == NULL) { sge_free_saved_vars(context); return amount; } if (with_explicit_prefix == false) { /* it begins with a pair */ amount++; } while (sge_strtok_r(NULL, ":", &context) != NULL) { amount++; } sge_free_saved_vars(context); return amount; }
static const lDescr * get_descr_from_key(const char *key) { const lDescr *descr = NULL; DENTER(TOP_LAYER, "get_descr_from_key"); if (key != NULL) { struct saved_vars_s *context = NULL; const char *type_name; type_name = sge_strtok_r(key, ":", &context); if (type_name != NULL) { sge_object_type type = object_name_get_type(type_name); if (type != SGE_TYPE_ALL) { descr = object_type_get_descr(type); } } sge_free_saved_vars(context); if (descr == NULL) { ERROR((SGE_EVENT, MSG_DBSTAT_INVALIDKEY_S, key)); } } DRETURN(descr); }
/****** sge_binding_hlp/check_explicit_binding_string() ************************ * NAME * check_explicit_binding_string() -- Checks binding string for duplicate pairs. * * SYNOPSIS * bool check_explicit_binding_string(const char* expl, const int amount) * * FUNCTION * Checks binding string for duplicate <socket,core> pairs. Works * also when the first pair is the "explicit" string. * * INPUTS * const char* expl - pointer to the explicit binding request * const int amount - expected amount of pairs * const bool with_explicit_prefix - expl start with "excplicit:" * * RESULT * bool - true if the explicit binding request is duplicate free * * NOTES * MT-NOTE: check_explicit_binding_string() is MT safe * * SEE ALSO * sge_binding_hlp/get_explicit_amount() *******************************************************************************/ bool check_explicit_binding_string(const char* expl, const int amount, const bool with_explicit_prefix) { bool success = true; struct saved_vars_s* context = NULL; /* pointer to the first position of all <socket,core> pairs */ int pair_number = 0; char* pairs[amount]; char* pair = NULL; if (expl == NULL || amount == 0) { return false; } /* skip "explicit:" */ if (with_explicit_prefix == true) { pair = sge_strtok_r(expl, ":", &context); if (pair == NULL) { success = false; } } /* get pointer to first pair */ if (success == true) { if (with_explicit_prefix == true) { pair = sge_strtok_r(NULL, ":", &context); } else { pair = sge_strtok_r(expl, ":", &context); } if (pair == NULL) { success = false; } } /* store pointer to first <socket,core> pair */ if (success == true) { pairs[pair_number] = pair; pair_number++; } /* split string in <socket,core> pairs and store them */ while ((success == true) && (pair = sge_strtok_r(NULL, ":", &context)) != NULL) { if (pair_number > amount) { /* found more pairs than expected */ success = false; break; } /* save string and check if it is unique */ pairs[pair_number] = pair; pair_number++; } /* check if amount of pairs did match */ if (success == true && pair_number != amount) { success = false; } /* check if there is a duplicate <socket,core> pair */ if (success == true) { int i,j; for (i = 0; i < amount && success == true; i++) { for (j = i+1; j < amount; j++) { if (strcmp(pairs[i], pairs[j]) == 0) { /* identical <socket,core> pair found -> illegal */ success = false; break; } } } } sge_free_saved_vars(context); return success; }
/****** sge_var/var_list_parse_from_string() ******************************* * NAME * var_list_parse_from_string() -- parse vars from string list * * SYNOPSIS * int var_list_parse_from_string(lList **lpp, * const char *variable_str, * int check_environment) * * FUNCTION * Parse a list of variables ("lpp") from a comma separated * string list ("variable_str"). The boolean "check_environment" * defined wether the current value of a variable is taken from * the environment of the calling process. * * INPUTS * lList **lpp - VA_Type list * const char *variable_str - source string * int check_environment - boolean * * RESULT * int - error state * 0 - OK * >0 - Error * * NOTES * MT-NOTE: var_list_parse_from_string() is MT safe *******************************************************************************/ int var_list_parse_from_string(lList **lpp, const char *variable_str, int check_environment) { char *variable; char *val_str; int var_len; char **str_str; char **pstr; lListElem *ep; char *va_string; DENTER(TOP_LAYER, "var_list_parse_from_string"); if (!lpp) { DEXIT; return 1; } va_string = sge_strdup(NULL, variable_str); if (!va_string) { *lpp = NULL; DEXIT; return 2; } str_str = string_list(va_string, ",", NULL); if (!str_str || !*str_str) { *lpp = NULL; sge_free(&va_string); DEXIT; return 3; } if (!*lpp) { *lpp = lCreateList("variable list", VA_Type); if (!*lpp) { sge_free(&va_string); sge_free(&str_str); DEXIT; return 4; } } for (pstr = str_str; *pstr; pstr++) { struct saved_vars_s *context; ep = lCreateElem(VA_Type); /* SGE_ASSERT(ep); */ lAppendElem(*lpp, ep); context = NULL; variable = sge_strtok_r(*pstr, "=", &context); SGE_ASSERT((variable)); var_len=strlen(variable); lSetString(ep, VA_variable, variable); val_str=*pstr; /* * The character at the end of the first token must be either '=' or '\0'. * If it's a '=' then we treat the following string as the value * If it's a '\0' and check_environment is set, then we get the value from * the environment variable value. * If it's a '\0' and check_environment is not set, then we set the value * to NULL. */ if (val_str[var_len] == '=') { lSetString(ep, VA_value, &val_str[var_len+1]); } else if (check_environment) { lSetString(ep, VA_value, sge_getenv(variable)); } else { lSetString(ep, VA_value, NULL); } sge_free_saved_vars(context); } sge_free(&va_string); sge_free(&str_str); DRETURN(0); }
static int check_config(lList **alpp, lListElem *conf) { lListElem *ep; const char *name, *value; const char *conf_name; DENTER(TOP_LAYER, "check_config"); conf_name = lGetHost(conf, CONF_name); for_each(ep, lGetList(conf, CONF_entries)) { name = lGetString(ep, CF_name); value = lGetString(ep, CF_value); if (name == NULL) { ERROR((SGE_EVENT, MSG_CONF_NAMEISNULLINCONFIGURATIONLISTOFX_S, conf_name)); answer_list_add(alpp, SGE_EVENT, STATUS_EEXIST, ANSWER_QUALITY_ERROR); DRETURN(STATUS_EEXIST); } if (value == NULL) { ERROR((SGE_EVENT, MSG_CONF_VALUEISNULLFORATTRXINCONFIGURATIONLISTOFY_SS, name, conf_name)); answer_list_add(alpp, SGE_EVENT, STATUS_EEXIST, ANSWER_QUALITY_ERROR); DRETURN(STATUS_EEXIST); } if (!strcmp(name, "loglevel")) { u_long32 tmp_uval; if (sge_parse_loglevel_val(&tmp_uval, value) != 1) { ERROR((SGE_EVENT, MSG_CONF_GOTINVALIDVALUEXFORLOGLEVEL_S, value)); answer_list_add(alpp, SGE_EVENT, STATUS_EEXIST, ANSWER_QUALITY_ERROR); DRETURN(STATUS_EEXIST); } } else if (strcmp(name, "jsv_url") == 0) { if (strcasecmp("none", value) != 0) { dstring input = DSTRING_INIT; dstring type = DSTRING_INIT; dstring user = DSTRING_INIT; dstring path = DSTRING_INIT; bool lret = true; sge_dstring_append(&input, value); lret = jsv_url_parse(&input, alpp, &type, &user, &path, false); sge_dstring_free(&input); sge_dstring_free(&type); sge_dstring_free(&user); sge_dstring_free(&path); if (!lret) { /* answer is written by jsv_url_parse */ DRETURN(STATUS_EEXIST); } } } else if (!strcmp(name, "shell_start_mode")) { if ((strcasecmp("unix_behavior", value) != 0) && (strcasecmp("posix_compliant", value) != 0) && (strcasecmp("script_from_stdin", value) != 0) ) { ERROR((SGE_EVENT, MSG_CONF_GOTINVALIDVALUEXFORSHELLSTARTMODE_S, value)); answer_list_add(alpp, SGE_EVENT, STATUS_EEXIST, ANSWER_QUALITY_ERROR); DRETURN(STATUS_EEXIST); } } else if (!strcmp(name, "shell")) { if (!path_verify(name, alpp, "shell", true)) { ERROR((SGE_EVENT, MSG_CONF_GOTINVALIDVALUEXFORSHELL_S, value)); answer_list_add(alpp, SGE_EVENT, STATUS_EEXIST, ANSWER_QUALITY_ERROR); DRETURN(STATUS_EEXIST); } } else if (!strcmp(name, "load_report_time")) { /* do not allow infinity entry for load_report_time */ if (strcasecmp(value, "infinity") == 0) { ERROR((SGE_EVENT, MSG_CONF_INFNOTALLOWEDFORATTRXINCONFLISTOFY_SS, name, conf_name)); answer_list_add(alpp, SGE_EVENT, STATUS_EEXIST, ANSWER_QUALITY_ERROR); DRETURN(STATUS_EEXIST); } } else if (!strcmp(name, "max_unheard")) { /* do not allow infinity entry */ if (strcasecmp(value,"infinity") == 0) { ERROR((SGE_EVENT, MSG_CONF_INFNOTALLOWEDFORATTRXINCONFLISTOFY_SS, name, conf_name)); answer_list_add(alpp, SGE_EVENT, STATUS_EEXIST, ANSWER_QUALITY_ERROR); DRETURN(STATUS_EEXIST); } } else if (!strcmp(name, "admin_user")) { struct passwd pw_struct; char *buffer; int size; size = get_pw_buffer_size(); buffer = sge_malloc(size); if (strcasecmp(value, "none") && !sge_getpwnam_r(value, &pw_struct, buffer, size)) { ERROR((SGE_EVENT, MSG_CONF_GOTINVALIDVALUEXASADMINUSER_S, value)); answer_list_add(alpp, SGE_EVENT, STATUS_EEXIST, ANSWER_QUALITY_ERROR); sge_free(&buffer); DRETURN(STATUS_EEXIST); } sge_free(&buffer); } else if (!strcmp(name, "user_lists")||!strcmp(name, "xuser_lists")) { lList *tmp = NULL; int ok; /* parse just for .. */ if (lString2ListNone(value, &tmp, US_Type, US_name, " \t,")) { ERROR((SGE_EVENT, MSG_CONF_FORMATERRORFORXINYCONFIG_SS, name, conf_name)); answer_list_add(alpp, SGE_EVENT, STATUS_EEXIST, ANSWER_QUALITY_ERROR); DRETURN(STATUS_EEXIST); } /* .. checking userset names */ ok = (userset_list_validate_acl_list(tmp, alpp) == STATUS_OK); lFreeList(&tmp); if (!ok) { DRETURN(STATUS_EEXIST); } } else if (!strcmp(name, "projects") || !strcmp(name, "xprojects")) { lList *tmp = NULL; int ok=1; /* parse just for .. */ if (lString2ListNone(value, &tmp, PR_Type, PR_name, " \t,")) { ERROR((SGE_EVENT, MSG_CONF_FORMATERRORFORXINYCONFIG_SS, name, conf_name)); answer_list_add(alpp, SGE_EVENT, STATUS_EEXIST, ANSWER_QUALITY_ERROR); DRETURN(STATUS_EEXIST); } /* .. checking project names */ ok = (verify_project_list(alpp, tmp, *object_type_get_master_list(SGE_TYPE_PROJECT), name, "configuration", conf_name)==STATUS_OK); lFreeList(&tmp); if (!ok) { DRETURN(STATUS_EEXIST); } } else if (!strcmp(name, "prolog") || !strcmp(name, "epilog") || !strcmp(name, "mailer")) { if (strcasecmp(value, "none")) { const char *t, *script = value; /* skip user name */ if ((t = strpbrk(script, "@ ")) && *t == '@') script = &t[1]; /* force use of absolute paths if string <> none */ if (script[0] != '/' ) { ERROR((SGE_EVENT, MSG_CONF_THEPATHGIVENFORXMUSTSTARTWITHANY_S, name)); answer_list_add(alpp, SGE_EVENT, STATUS_EUNKNOWN, ANSWER_QUALITY_ERROR); DRETURN(STATUS_EEXIST); } /* ensure that variables are valid */ if (replace_params(script, NULL, 0, prolog_epilog_variables)) { ERROR((SGE_EVENT, MSG_CONF_PARAMETERXINCONFIGURATION_SS, name, err_msg)); answer_list_add(alpp, SGE_EVENT, STATUS_EEXIST, ANSWER_QUALITY_ERROR); DRETURN(STATUS_EEXIST); } } } else if (!strcmp(name, "auto_user_oticket") || !strcmp(name, "auto_user_fshare")) { u_long32 uval = 0; if (!extended_parse_ulong_val(NULL, &uval, TYPE_INT, value, NULL, 0, 0, true)) { ERROR((SGE_EVENT, MSG_CONF_FORMATERRORFORXINYCONFIG_SS, name, value ? value : "(NULL)")); answer_list_add(alpp, SGE_EVENT, STATUS_EEXIST, ANSWER_QUALITY_ERROR); DRETURN(STATUS_EEXIST); } } /* * check paths, see also CR 6506580. * The following must be none or a valid absolute path: * - load_sensor * - set_token_cmd * - pag_cmd * - shepherd_cmd * * The following must be a valid absolute path: * - mailer * - xterm * - *_daemon, may also be "builtin" */ else if (strcmp(name, "set_token_cmd") == 0 || strcmp(name, "pag_cmd") == 0 || strcmp(name, "shepherd_cmd") == 0) { if (strcasecmp(value, "none") != 0) { if (!path_verify(value, alpp, name, true)) { answer_list_log(alpp, false, false); DRETURN(STATUS_EEXIST); } } } else if (strcmp(name, "mailer") == 0 || strcmp(name, "xterm") == 0) { if (!path_verify(value, alpp, name, true)) { answer_list_log(alpp, false, false); DRETURN(STATUS_EEXIST); } } else if (strcmp(name, "qlogin_daemon") == 0 || strcmp(name, "rlogin_daemon") == 0 || strcmp(name, "rsh_daemon") == 0) { if (strcasecmp(value, "builtin") != 0) { if (!path_verify(value, alpp, name, true)) { answer_list_log(alpp, false, false); DRETURN(STATUS_EEXIST); } } } /* load_sensor is a comma separated list of scripts */ else if (strcmp(name, "load_sensor") == 0 && strcasecmp(value, "none") != 0) { struct saved_vars_s *context = NULL; const char *path = sge_strtok_r(value, ",", &context); do { if (!path_verify(path, alpp, name, true)) { answer_list_log(alpp, false, false); sge_free_saved_vars(context); DRETURN(STATUS_EEXIST); } } while ((path = sge_strtok_r(NULL, ",", &context)) != NULL); sge_free_saved_vars(context); } }