| 85 | } |
| 86 | |
| 87 | static void |
| 88 | handle_dns(TSHttpTxn txnp, TSCont contp) |
| 89 | { |
| 90 | TSMBuffer bufp; |
| 91 | TSMLoc hdr_loc; |
| 92 | TSMLoc field_loc; |
| 93 | const char *val; |
| 94 | const char *ptr; |
| 95 | |
| 96 | char *user, *password; |
| 97 | int authval_length; |
| 98 | |
| 99 | if (TSHttpTxnClientReqGet(txnp, &bufp, &hdr_loc) != TS_SUCCESS) { |
| 100 | TSError("[%s] Couldn't retrieve client request header", PLUGIN_NAME); |
| 101 | goto done; |
| 102 | } |
| 103 | |
| 104 | field_loc = TSMimeHdrFieldFind(bufp, hdr_loc, TS_MIME_FIELD_PROXY_AUTHORIZATION, TS_MIME_LEN_PROXY_AUTHORIZATION); |
| 105 | if (!field_loc) { |
| 106 | TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc); |
| 107 | TSError("[%s] No Proxy-Authorization field", PLUGIN_NAME); |
| 108 | goto done; |
| 109 | } |
| 110 | |
| 111 | val = TSMimeHdrFieldValueStringGet(bufp, hdr_loc, field_loc, -1, &authval_length); |
| 112 | if (nullptr == val) { |
| 113 | TSError("[%s] No value in Proxy-Authorization field", PLUGIN_NAME); |
| 114 | TSHandleMLocRelease(bufp, hdr_loc, field_loc); |
| 115 | TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc); |
| 116 | goto done; |
| 117 | } |
| 118 | |
| 119 | ptr = val; |
| 120 | if (strncmp(ptr, "Basic", 5) != 0) { |
| 121 | TSError("[%s] No Basic auth type in Proxy-Authorization", PLUGIN_NAME); |
| 122 | TSHandleMLocRelease(bufp, hdr_loc, field_loc); |
| 123 | TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc); |
| 124 | goto done; |
| 125 | } |
| 126 | |
| 127 | ptr += 5; |
| 128 | while ((*ptr == ' ') || (*ptr == '\t')) { |
| 129 | ptr += 1; |
| 130 | } |
| 131 | |
| 132 | user = base64_decode(ptr); |
| 133 | password = strchr(user, ':'); |
| 134 | if (!password) { |
| 135 | TSError("[%s] No password in authorization information", PLUGIN_NAME); |
| 136 | TSfree(user); |
| 137 | TSHandleMLocRelease(bufp, hdr_loc, field_loc); |
| 138 | TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc); |
| 139 | goto done; |
| 140 | } |
| 141 | *password = '\0'; |
| 142 | password += 1; |
| 143 | |
| 144 | if (!authorized(user, password)) { |
no test coverage detected