int main(int argc, char *argv[]) { lList *answer_list = NULL; int i=0, ret=0; static const char* denied[] = { "forbiddencharacterwithing@thestring", ".forbiddencharacteratthebeginning", "TEMPLATE", "ALL", "NONE", "thisisawordwithmorethanfivehundredandtwelvecharactersitishardtowritesomethinglongbecauseidontknwowhatishouldwritesoidecidedtowritedownashortstoryaboutanythingwhichisnotrealonceuponatimetherewasalittlesoftwareprogrammerhewasinsanebecausehehastofindwordswhicharelongerthanfivehunderdandtwelvecharactersandhefoundithardtowritesuchlongwordsbuthediditandhedecidedtowritedownashortstoryaboutalittleprogrammerasoftwareprogrammerwhohastowritetestsfortestingfunctionwhichteststehlengthofstringsandaftmanymanymanycharactershesolvedtheproblem", "bla%sfoo", NULL }; static const char* allowed[] = { "forbiddencharacterwithingthestring", "forbiddencharacteratthebeginning", "EMPLATE", "boutanythingwhichisnotrealonceuponatimetherewasalittlesoftwareprogrammerhewasinsanebecausehehastofindwordswhicharelongerthanfivehunderdandtwelvecharactersandhefoundithardtowritesuchlongwordsbuthediditandhedecidedtowritedownashortstoryaboutalittleprogrammerasoftwareprogrammerwhohastowritetestsfortestingfunctionwhichteststehlengthofstringsandaftmanymanymanycharactershesolvedtheproblem", NULL }; for (i=0; denied[i] != NULL; i++) { if (verify_str_key( &answer_list, denied[i], MAX_VERIFY_STRING, "test", KEY_TABLE) == STATUS_OK) { printf("%s should be forbidden\n", denied[i]); ret++; } } for (i=0; allowed[i] != NULL; i++) { if (verify_str_key( &answer_list, allowed[i], MAX_VERIFY_STRING, "test", KEY_TABLE) != STATUS_OK) { printf("%s should be allowed\n", allowed[i]); ret++; } } if (ret == 0) { printf("PASS: test solved!\n"); } else { printf("FAILED: test NOT solved!\n"); } return ret; }
/****** sge_resource_quota_qmaster/rqs_mod() ************************************** * NAME * rqs_mod() -- gdi callback function for modifing resource quota sets * * SYNOPSIS * int rqs_mod(lList **alpp, lListElem *new_rqs, lListElem *rqs, int add, * const char *ruser, const char *rhost, gdi_object_t *object, int * sub_command, monitoring_t *monitor) * * FUNCTION * This function is called from the framework that * add/modify/delete generic gdi objects. * The purpose of this function is it to add new rqs * objects or modify existing resource quota sets. * * INPUTS * lList **alpp - reference to an answer list * lListElem *new_rqs - if a new rqs object will be created by this * function, then new_rqs is a newly initialized * CULL object. * if this function was called due to a modify request * than new_rqs will contain the old data * lListElem *rqs - a reduced rqs object which contains all * necessary information to create a new object * or modify parts of an existing one * int add - 1 if a new element should be added to the master list * 0 to modify an existing object * const char *ruser - username who invoked this gdi request * const char *rhost - hostname of where the gdi request was invoked * gdi_object_t *object - structure of the gdi framework which contains * additional information to perform the request * int sub_command - how should we handle sublist elements * SGE_GDI_CHANGE - modify sublist elements * SGE_GDI_APPEND - add elements to a sublist * SGE_GDI_REMOVE - remove sublist elements * SGE_GDI_SET - replace the complete sublist * monitoring_t *monitor - monitoring structure * * RESULT * int - 0 on success * STATUS_EUNKNOWN if an error occured * * NOTES * MT-NOTE: rqs_mod() is MT safe *******************************************************************************/ int rqs_mod(sge_gdi_ctx_class_t *ctx, lList **alpp, lListElem *new_rqs, lListElem *rqs, int add, const char *ruser, const char *rhost, gdi_object_t *object, int sub_command, monitoring_t *monitor) { const char *rqs_name = NULL; bool rules_changed = false; bool previous_enabled = (bool)lGetBool(new_rqs, RQS_enabled); DENTER(TOP_LAYER, "rqs_mod"); /* ---- RQS_name */ if (add) { if (attr_mod_str(alpp, rqs, new_rqs, RQS_name, object->object_name)) goto ERROR; } rqs_name = lGetString(new_rqs, RQS_name); /* Name has to be a valid name */ if (add && verify_str_key(alpp, rqs_name, MAX_VERIFY_STRING, MSG_OBJ_RQS, KEY_TABLE) != STATUS_OK) { goto ERROR; } /* ---- RQS_description */ attr_mod_zerostr(rqs, new_rqs, RQS_description, "description"); /* ---- RQS_enabled */ attr_mod_bool(rqs, new_rqs, RQS_enabled, "enabled"); /* ---- RQS_rule */ if (lGetPosViaElem(rqs, RQS_rule, SGE_NO_ABORT)>=0) { rules_changed = true; if (SGE_GDI_IS_SUBCOMMAND_SET(sub_command, SGE_GDI_SET_ALL)) { normalize_sublist(rqs, RQS_rule); attr_mod_sub_list(alpp, new_rqs, RQS_rule, RQS_name, rqs, sub_command, SGE_ATTR_RQSRULES, SGE_OBJ_RQS, 0, NULL); } else { /* *attr cases */ lList *rule_list = lGetList(rqs, RQS_rule); lListElem *rule = NULL; for_each(rule, rule_list) { lList *new_rule_list = lGetList(new_rqs, RQS_rule); lListElem *new_rule = NULL; new_rule = rqs_rule_locate(new_rule_list, lGetString(rule, RQR_name)); if (new_rule != NULL) { /* ---- RQR_limit */ attr_mod_sub_list(alpp, new_rule, RQR_limit, RQRL_name, rule, sub_command, SGE_ATTR_RQSRULES, SGE_OBJ_RQS, 0, NULL); } else { ERROR((SGE_EVENT, SFNMAX, MSG_RESOURCEQUOTA_NORULEDEFINED)); answer_list_add(alpp, SGE_EVENT, STATUS_ESEMANTIC, ANSWER_QUALITY_ERROR); goto ERROR; } } }
/****** qmaster/ckpt/ckpt_mod() *********************************************** * NAME * ckpt_mod -- add/modify ckpt object in Master_Ckpt_List * * SYNOPSIS * int ckpt_mod (lList **alpp, lListElem *new_ckpt, lListElem *ckpt, * int add, char *ruser, char *rhost, gdi_object_t *object, * int sub_command); * * FUNCTION * This function will be called from the framework which will * add/modify/delete generic gdi objects. * The purpose of this function is it to add new ckpt * objects or modify existing checkpointing interfaces. * * * INPUTS * alpp - reference to an answer list. * new_ckpt - if a new ckpt object will be created by this * function, than new_ckpt is new uninitialized * CULL object * if this function was called due to a modify request * than new_ckpt will contain the old data * (see add parameter) * ckpt - a reduced ckpt object which contains all * necessary information to create a new object * or modify parts of an existing one * add - 1 if a new element should be added to the master list * 0 to modify an existing object * ruser - username of person who invoked this gdi request * rhost - hostname of the host where someone initiated an gdi call * object - structure of the gdi framework which contains * additional information to perform the request * (function pointers, names, CULL-types) * sub_command - how should we handle sublist elements * SGE_GDI_CHANGE - modify sublist elements * SGE_GDI_APPEND - add elements to a sublist * SGE_GDI_REMOVE - remove sublist elements * SGE_GDI_SET - replace the complete sublist * * RESULT * [alpp] - error messages will be added to this list * 0 - success * STATUS_EUNKNOWN - an error occured ******************************************************************************/ int ckpt_mod(sge_gdi_ctx_class_t *ctx, lList **alpp, lListElem *new_ckpt, lListElem *ckpt, int add, const char *ruser, const char *rhost, gdi_object_t *object, int sub_command, monitoring_t *monitor) { const char *ckpt_name; DENTER(TOP_LAYER, "ckpt_mod"); /* ---- CK_name */ if (lGetPosViaElem(ckpt, CK_name, SGE_NO_ABORT) >= 0) { if (add) { if (attr_mod_str(alpp, ckpt, new_ckpt, CK_name, SGE_ATTR_CKPT_NAME)) { goto ERROR; } } ckpt_name = lGetString(new_ckpt, CK_name); if (add && verify_str_key( alpp, ckpt_name, MAX_VERIFY_STRING, SGE_ATTR_CKPT_NAME, KEY_TABLE) != STATUS_OK) { DEXIT; return STATUS_EUNKNOWN; } } else { ERROR((SGE_EVENT, MSG_SGETEXT_MISSINGCULLFIELD_SS, lNm2Str(CK_name), SGE_FUNC)); answer_list_add(alpp, SGE_EVENT, STATUS_EUNKNOWN, ANSWER_QUALITY_ERROR); goto ERROR; } /* ---- CK_interface */ attr_mod_str(alpp, ckpt, new_ckpt, CK_interface, SGE_ATTR_INTERFACE); /* ---- CK_ckpt_command */ attr_mod_str(alpp, ckpt, new_ckpt, CK_ckpt_command, SGE_ATTR_CKPT_COMMAND); /* ---- CK_migr_command */ attr_mod_str(alpp, ckpt, new_ckpt, CK_migr_command, SGE_ATTR_MIGR_COMMAND); /* ---- CK_rest_command */ attr_mod_str(alpp, ckpt, new_ckpt, CK_rest_command, SGE_ATTR_RESTART_COMMAND); /* ---- CK_ckpt_dir */ attr_mod_str(alpp, ckpt, new_ckpt, CK_ckpt_dir, SGE_ATTR_CKPT_DIR); /* ---- CK_when */ if (lGetPosViaElem(ckpt, CK_when, SGE_NO_ABORT) >= 0) { int new_flags, flags; new_flags = sge_parse_checkpoint_attr(lGetString(new_ckpt, CK_when)); flags = sge_parse_checkpoint_attr(lGetString(ckpt, CK_when)); if (SGE_GDI_IS_SUBCOMMAND_SET(sub_command, SGE_GDI_APPEND) || SGE_GDI_IS_SUBCOMMAND_SET(sub_command, SGE_GDI_CHANGE)) { new_flags |= flags; } else if (SGE_GDI_IS_SUBCOMMAND_SET(sub_command, SGE_GDI_REMOVE)) { new_flags &= (~flags); } else { new_flags = flags; } if (is_checkpoint_when_valid(new_flags)) { lSetString(new_ckpt, CK_when, get_checkpoint_when(new_flags)); } else { ERROR((SGE_EVENT, MSG_CKPT_INVALIDWHENATTRIBUTE_S, ckpt_name)); answer_list_add(alpp, SGE_EVENT, STATUS_EUNKNOWN, ANSWER_QUALITY_ERROR); goto ERROR; } } /* ---- CK_signal */ attr_mod_str(alpp, ckpt, new_ckpt, CK_signal, SGE_ATTR_SIGNAL); /* ---- CK_clean_command */ attr_mod_str(alpp, ckpt, new_ckpt, CK_clean_command, SGE_ATTR_CLEAN_COMMAND); /* ---- CK_job_pid */ attr_mod_ulong(ckpt, new_ckpt, CK_job_pid, "job_pid"); /* validate ckpt data */ if (ckpt_validate(new_ckpt, alpp) != STATUS_OK) { goto ERROR; } DEXIT; return 0; ERROR: DEXIT; return STATUS_EUNKNOWN; }
/****** sge_advance_reservation/ar_validate() ********************************** * NAME * ar_validate() -- validate a advance reservation * * SYNOPSIS * bool ar_validate(lListElem *ar, lList **alpp, bool in_master) * * FUNCTION * Ensures a new ar has valid start and end times * * INPUTS * lListElem *ar - the ar to check * lList **alpp - answer list pointer * bool in_master - are we in qmaster? * bool is_spool - do we validate for spooling? * * RESULT * bool - true if OK, else false * * NOTES * MT-NOTE: ar_validate() is MT safe *******************************************************************************/ bool ar_validate(lListElem *ar, lList **alpp, bool in_master, bool is_spool) { u_long32 start_time; u_long32 end_time; u_long32 duration; u_long32 now = sge_get_gmt(); object_description *object_base = object_type_get_object_description(); DENTER(TOP_LAYER, "ar_validate"); /* AR_start_time, SGE_ULONG */ if ((start_time = lGetUlong(ar, AR_start_time)) == 0) { start_time = now; lSetUlong(ar, AR_start_time, start_time); } /* AR_end_time, SGE_ULONG */ end_time = lGetUlong(ar, AR_end_time); duration = lGetUlong(ar, AR_duration); if (end_time == 0 && duration == 0) { answer_list_add_sprintf(alpp, STATUS_EEXIST, ANSWER_QUALITY_ERROR, MSG_AR_MISSING_VALUE_S, "end time or duration"); goto ERROR; } else if (end_time == 0) { end_time = duration_add_offset(start_time, duration); duration = end_time - start_time; lSetUlong(ar, AR_end_time, end_time); lSetUlong(ar, AR_duration, duration); } else if (duration == 0) { duration = end_time - start_time; lSetUlong(ar, AR_duration, duration); } if ((end_time - start_time) != duration) { answer_list_add_sprintf(alpp, STATUS_EEXIST, ANSWER_QUALITY_ERROR, MSG_AR_START_END_DURATION_INVALID); goto ERROR; } if (start_time > end_time) { answer_list_add_sprintf(alpp, STATUS_EEXIST, ANSWER_QUALITY_ERROR, MSG_AR_START_LATER_THAN_END); goto ERROR; } if (!is_spool) { if (start_time < now) { answer_list_add_sprintf(alpp, STATUS_EEXIST, ANSWER_QUALITY_ERROR, MSG_AR_START_IN_PAST); goto ERROR; } } /* AR_owner, SGE_STRING */ if (in_master) { /* AR_name, SGE_STRING */ NULL_OUT_NONE(ar, AR_name); if (object_verify_name(ar, alpp, AR_name, SGE_OBJ_AR)) { goto ERROR; } /* AR_account, SGE_STRING */ NULL_OUT_NONE(ar, AR_account); if (!lGetString(ar, AR_account)) { lSetString(ar, AR_account, DEFAULT_ACCOUNT); } else { if (verify_str_key(alpp, lGetString(ar, AR_account), MAX_VERIFY_STRING, "account string", QSUB_TABLE) != STATUS_OK) { goto ERROR; } } /* AR_verify, SGE_ULONG just verify the reservation or final case */ /* AR_error_handling, SGE_ULONG how to deal with soft and hard exceptions */ /* AR_checkpoint_name, SGE_STRING Named checkpoint */ NULL_OUT_NONE(ar, AR_checkpoint_name); { /* request for non existing ckpt object will be refused */ const char *ckpt_name = NULL; ckpt_name = lGetString(ar, AR_checkpoint_name); if (ckpt_name != NULL) { lList *master_ckpt_list = *object_base[SGE_TYPE_CKPT].list; lListElem *ckpt_ep = ckpt_list_locate(master_ckpt_list, ckpt_name); if (!ckpt_ep) { ERROR((SGE_EVENT, MSG_JOB_CKPTUNKNOWN_S, ckpt_name)); answer_list_add(alpp, SGE_EVENT, STATUS_EUNKNOWN, ANSWER_QUALITY_ERROR); goto ERROR; } } } /* AR_resource_list, SGE_LIST */ { lList *master_centry_list = *object_base[SGE_TYPE_CENTRY].list; if (centry_list_fill_request(lGetList(ar, AR_resource_list), alpp, master_centry_list, false, true, false)) { goto ERROR; } if (compress_ressources(alpp, lGetList(ar, AR_resource_list), SGE_OBJ_AR)) { goto ERROR; } if (!centry_list_is_correct(lGetList(ar, AR_resource_list), alpp)) { goto ERROR; } } /* AR_queue_list, SGE_LIST */ if (!qref_list_is_valid(lGetList(ar, AR_queue_list), alpp)) { goto ERROR; } /* AR_mail_options, SGE_ULONG */ /* AR_mail_list, SGE_LIST */ /* AR_master_queue_list -masterq wc_queue_list, SGE_LIST bind master task to queue(s) */ if (!qref_list_is_valid(lGetList(ar, AR_master_queue_list), alpp)) { goto ERROR; } /* AR_pe, SGE_STRING, AR_pe_range, SGE_LIST */ NULL_OUT_NONE(ar, AR_pe); { const char *pe_name = NULL; lList *pe_range = NULL; pe_name = lGetString(ar, AR_pe); if (pe_name) { const lListElem *pep; pep = pe_list_find_matching(*object_base[SGE_TYPE_PE].list, pe_name); if (!pep) { ERROR((SGE_EVENT, MSG_JOB_PEUNKNOWN_S, pe_name)); answer_list_add(alpp, SGE_EVENT, STATUS_EUNKNOWN, ANSWER_QUALITY_ERROR); goto ERROR; } /* check pe_range */ pe_range = lGetList(ar, AR_pe_range); if (object_verify_pe_range(alpp, pe_name, pe_range, SGE_OBJ_AR)!=STATUS_OK) { goto ERROR; } } } /* AR_acl_list, SGE_LIST */ if (userset_list_validate_access(lGetList(ar, AR_acl_list), ARA_name, alpp) != STATUS_OK) { goto ERROR; } /* AR_xacl_list, SGE_LIST */ if (userset_list_validate_access(lGetList(ar, AR_xacl_list), ARA_name, alpp) != STATUS_OK) { goto ERROR; } if (is_spool) { lListElem *jg; dstring cqueue_buffer = DSTRING_INIT; dstring hostname_buffer = DSTRING_INIT; for_each(jg, lGetList(ar, AR_granted_slots)){ const char *hostname = NULL; const char *qname = lGetString(jg, JG_qname); bool has_hostname = false; bool has_domain = false; cqueue_name_split(qname, &cqueue_buffer, &hostname_buffer, &has_hostname, &has_domain); hostname = sge_dstring_get_string(&hostname_buffer); lSetHost(jg, JG_qhostname, hostname); } sge_dstring_free(&cqueue_buffer); sge_dstring_free(&hostname_buffer); } /* AR_type, SGE_ULONG */ /* AR_state, SGE_ULONG state of the AR */ if(lGetUlong(ar, AR_state) == ARL_UNKNOWN){ lSetUlong(ar, AR_state, ARL_CREATION); } } DRETURN(true); ERROR: DRETURN(false); }