static int TestReuseRegex() { regex* re = regex_create("asd.", NULL); mu_assert("should match", regex_matches(re, "asdf", NULL)); mu_assert("should match again", regex_matches(re, "asdf", NULL)); mu_assert("should not", !regex_matches(re, "", NULL)); regex_destroy(re); return 1; }
/// Matches the regular expression against a string. /// /// \param str String to match the regular expression against. /// /// \return A new regex_matches object with the results of the match. text::regex_matches text::regex::match(const std::string& str) const { std::shared_ptr< regex_matches::impl > pimpl(new regex_matches::impl( &_pimpl->_preg, str, _pimpl->_ngroups)); return regex_matches(pimpl); }
int match(char* re_str, char* str) { re_error er; regex* re = regex_create(re_str, &er); //print_program(&(re->prog)); if(re == NULL) return 0; int m = regex_matches(re, str, NULL); regex_destroy(re); return m; }
static const char * process_scope(PyObject *out, const char *start, const char *buff, const char *end, PyObject *var_matcher, PyObject *func_matcher, const char endchar, PyObject *envvar_callback) { const char *p = NULL; const char *window_start = NULL, *window_end = NULL; const char *new_p = NULL; const char *com_start = NULL; char *s = NULL; char *e = NULL; char *temp_string = NULL; regmatch_t matches[3]; p = buff; matches[0].rm_so = matches[1].rm_so = matches[2].rm_so = -1; window_start = buff; window_end = NULL; while (p < end && *p != endchar) { /* wander forward to the next non space */ if (window_end != NULL) { if (out) { PyObject *string = PyString_FromStringAndSize( window_start, window_end - window_start); if (!string) return NULL; PyObject *result = PyObject_CallMethodObjArgs( out, write_str, string, NULL); Py_DECREF(string); if (!result) return NULL; Py_DECREF(result); } window_start = p; window_end = NULL; } com_start = p; if (isspace(*p)) { ++p; continue; } /* ignore comments */ if (*p == '#') { p = walk_statement_pound(start, p, endchar); continue; } if(NULL != (new_p = is_function(p, &s, &e))) { if(-1 == asprintf(&temp_string, "%.*s", (int)(e - s), s)) return NULL; INFO("matched func name '%s'", temp_string); /* output it if it doesn't match */ new_p = process_scope( NULL, start, new_p, end, NULL, NULL, '}', NULL); INFO("ended processing '%s'", temp_string); if (func_matcher) { int regex_result = regex_matches(func_matcher, temp_string); if (-1 == regex_result) { free(temp_string); return NULL; } if (regex_result) { /* well, it matched. so it gets skipped. */ INFO("filtering func '%s'", temp_string); window_end = com_start; } } free(temp_string); if(!new_p) return NULL; p = new_p; ++p; continue; } // check for env assignment if (NULL == (new_p = is_envvar(p, &s, &e))) { //exactly as it sounds, non env assignment. p = walk_command_complex(start, p, end, endchar, COMMAND_PARSING); if (!p) return NULL; // icky icky icky icky if (p < end && *p != endchar) ++p; } else { //env assignment if(-1 == asprintf(&temp_string, "%.*s", (int)(e - s), s)) return NULL; INFO("matched env assign '%s'", temp_string); do_envvar_callback(envvar_callback, temp_string); if (var_matcher) { int regex_result = regex_matches(var_matcher, temp_string); if (-1 == regex_result) { free(temp_string); return NULL; } if (regex_result) { //this would be filtered. INFO("filtering var '%s'", temp_string); window_end = com_start; } } free(temp_string); p = new_p; if (p >= end) { return p; } while(p < end && !isspace(*p) && ';' != *p) { if ('\'' == *p) p = walk_statement_no_parsing(p + 1, end, '\'') + 1; else if ('"' == *p || '`' == *p) p = walk_command_escaped_parsing(start, p + 1, end, *p) + 1; else if ('(' == *p) { p = walk_command_escaped_parsing(start, p + 1, end, ')') + 1; } else if ('$' == *p) { ++p; if (p >= end) { continue; } p = walk_dollar_expansion(start, p, end, endchar, endchar); continue; } else { // blah=cah ; single word. p = walk_command_complex(start, p, end, ' ', SPACE_PARSING); if (!p) { return NULL; } } } } } if (out) { if (window_end == NULL) window_end = p; if (window_end > end) window_end = end; PyObject *string = PyString_FromStringAndSize( window_start, window_end - window_start); if (!string) return NULL; PyObject *result = PyObject_CallMethodObjArgs( out, write_str, string, NULL); Py_DECREF(string); if (!result) return NULL; Py_DECREF(result); } return p; }
static int gssattr_dynacl_mask( void *priv, Operation *op, Entry *target, AttributeDescription *desc, struct berval *val, int nmatch, regmatch_t *matches, slap_access_t *grant, slap_access_t *deny ) { gssattr_t *gssattr = (gssattr_t *)priv; sasl_conn_t *sasl_ctx = op->o_conn->c_sasl_authctx; gss_name_t gss_name = GSS_C_NO_NAME; OM_uint32 major, minor; int more = -1; int authenticated, complete; gss_buffer_desc attr = GSS_C_EMPTY_BUFFER; int granted = 0; ACL_INVALIDATE( *deny ); if ( sasl_ctx == NULL || sasl_getprop( sasl_ctx, SASL_GSS_PEER_NAME, (const void **)&gss_name) != 0 || gss_name == GSS_C_NO_NAME ) { return 0; } attr.length = gssattr->gssattr_name.bv_len; attr.value = gssattr->gssattr_name.bv_val; while ( more != 0 ) { AclRegexMatches amatches = { 0 }; gss_buffer_desc gss_value = GSS_C_EMPTY_BUFFER; gss_buffer_desc gss_display_value = GSS_C_EMPTY_BUFFER; struct berval bv_value; major = gss_get_name_attribute( &minor, gss_name, &attr, &authenticated, &complete, &gss_value, &gss_display_value, &more ); if ( GSS_ERROR( major ) ) { break; } else if ( authenticated == 0 ) { gss_release_buffer( &minor, &gss_value ); gss_release_buffer( &minor, &gss_display_value ); continue; } bv_value.bv_len = gss_value.length; bv_value.bv_val = (char *)gss_value.value; if ( !ber_bvccmp( &gssattr->gssattr_value, '*' ) ) { if ( gssattr->gssattr_style != ACL_STYLE_BASE ) { amatches.dn_count = nmatch; AC_MEMCPY( amatches.dn_data, matches, sizeof( amatches.dn_data ) ); } switch ( gssattr->gssattr_style ) { case ACL_STYLE_REGEX: /* XXX assumes value NUL terminated */ granted = regex_matches( &gssattr->gssattr_value, bv_value.bv_val, &target->e_nname, val, &amatches ); break; case ACL_STYLE_EXPAND: { struct berval bv; char buf[ACL_BUF_SIZE]; bv.bv_len = sizeof( buf ) - 1; bv.bv_val = buf; granted = ( acl_string_expand( &bv, &gssattr->gssattr_value, &target->e_nname, val, &amatches ) == 0 ) && ( ber_bvstrcmp( &bv, &bv_value) == 0 ); break; } case ACL_STYLE_BASE: granted = ( ber_bvstrcmp( &gssattr->gssattr_value, &bv_value ) == 0 ); break; default: assert(0); break; } } else { granted = 1; } gss_release_buffer( &minor, &gss_value ); gss_release_buffer( &minor, &gss_display_value ); if ( granted ) { break; } } if ( granted ) { ACL_LVL_ASSIGN_WRITE( *grant ); } return 0; }