MCPcopy Create free account
hub / github.com/apache/trafficserver / TSRemapDoRemap

Function TSRemapDoRemap

plugins/experimental/access_control/plugin.cc:570–626  ·  view source on GitHub ↗

* @brief Remap and sets up access control based on whether access control is required, failed, etc. * * @param instance plugin instance pointer * @param txn transaction handle * @param rri remap request info pointer * @return TSREMAP_NO_REMAP (access validation = success) * TSREMAP_DID_REMAP (access validation = failure and rejection of failed requests is configured) */

Source from the content-addressed store, hash-verified

568 * TSREMAP_DID_REMAP (access validation = failure and rejection of failed requests is configured)
569 */
570TSRemapStatus
571TSRemapDoRemap(void *instance, TSHttpTxn txnp, TSRemapRequestInfo *rri)
572{
573 TSRemapStatus remapStatus = TSREMAP_NO_REMAP;
574 AccessControlConfig *config = static_cast<AccessControlConfig *>(instance);
575
576 if (nullptr != config) {
577 /* Plugin is designed to be used only with TLS, check the scheme */
578 int schemeLen = 0;
579 const char *scheme = TSUrlSchemeGet(rri->requestBufp, rri->requestUrl, &schemeLen);
580 if (nullptr != scheme) {
581 if (/* strlen("https") */ 5 == schemeLen && 0 == strncmp(scheme, "https", schemeLen)) {
582 AccessControlDebug("validate the access token");
583
584 String reqPath;
585 int pathLen = 0;
586 const char *path = TSUrlPathGet(rri->requestBufp, rri->requestUrl, &pathLen);
587 if (nullptr != path && 0 < pathLen) {
588 reqPath.assign(path, pathLen);
589 }
590 /* Check if any of the uri-path multi-pattern matched and if yes enforce access control. */
591 String filename;
592 String pattern;
593 if (config->_uriPathScope.empty()) {
594 /* Scope match enforce access control */
595 AccessControlDebug("no plugin scope specified, enforcing access control");
596 remapStatus = enforceAccessControl(txnp, rri, config);
597 } else {
598 if (true == config->_uriPathScope.matchAll(reqPath, filename, pattern)) {
599 AccessControlDebug("matched plugin scope enforcing access control for path %s", reqPath.c_str());
600
601 /* Scope match enforce access control */
602 remapStatus = enforceAccessControl(txnp, rri, config);
603 } else {
604 AccessControlDebug("not matching plugin scope (file: %s, pattern %s), skipping access control for path '%s'",
605 filename.c_str(), pattern.c_str(), reqPath.c_str());
606 }
607 }
608 } else {
609 TSHttpTxnStatusSet(txnp, config->_invalidRequest);
610 AccessControlDebug("https is the only allowed scheme (plugin should be used only with TLS)");
611 remapStatus = TSREMAP_DID_REMAP;
612 }
613 } else {
614 TSHttpTxnStatusSet(txnp, config->_internalError);
615 AccessControlError("failed to get request uri-scheme");
616 remapStatus = TSREMAP_DID_REMAP;
617 }
618 } else {
619 /* Something is terribly wrong, we cannot get the configuration */
620 TSHttpTxnStatusSet(txnp, TS_HTTP_STATUS_INTERNAL_SERVER_ERROR);
621 AccessControlError("configuration unavailable");
622 remapStatus = TSREMAP_DID_REMAP;
623 }
624
625 return remapStatus;
626}

Callers

nothing calls this directly

Calls 8

TSUrlSchemeGetFunction · 0.85
TSUrlPathGetFunction · 0.85
enforceAccessControlFunction · 0.85
TSHttpTxnStatusSetFunction · 0.85
matchAllMethod · 0.80
assignMethod · 0.45
emptyMethod · 0.45
c_strMethod · 0.45

Tested by

no test coverage detected