You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by bu...@apache.org on 2010/12/14 16:22:36 UTC
svn commit: r780656 - in
/websites/staging/trafficserver/trunk/content/docs/trunk: ./
sdk/header-based-plugin-examples/basic-authorization-plugin/
Author: buildbot
Date: Tue Dec 14 15:22:36 2010
New Revision: 780656
Log:
Staging update by buildbot
Modified:
websites/staging/trafficserver/trunk/content/docs/trunk/STATUS
websites/staging/trafficserver/trunk/content/docs/trunk/sdk/header-based-plugin-examples/basic-authorization-plugin/implementing-the-handler-and-getting-a-handle-to-the-transaction.en.html
websites/staging/trafficserver/trunk/content/docs/trunk/sdk/header-based-plugin-examples/basic-authorization-plugin/index.en.html
websites/staging/trafficserver/trunk/content/docs/trunk/sdk/header-based-plugin-examples/basic-authorization-plugin/setting-a-transaction-hook.en.html
websites/staging/trafficserver/trunk/content/docs/trunk/sdk/header-based-plugin-examples/basic-authorization-plugin/working-with-http-headers.en.html
Modified: websites/staging/trafficserver/trunk/content/docs/trunk/STATUS
==============================================================================
--- websites/staging/trafficserver/trunk/content/docs/trunk/STATUS (original)
+++ websites/staging/trafficserver/trunk/content/docs/trunk/STATUS Tue Dec 14 15:22:36 2010
@@ -54,7 +54,7 @@ getting-started -- igalic
how-to-create-trafficserver-plugins -- igalic
remap-plugin -- igalic
header-based-plugin-examples -- igalic
-http-transformation-plugin
+http-transformation-plugin -- igalic
new-protocol-plugins
cache-plugin
http-hoooks-and-transactions
Modified: websites/staging/trafficserver/trunk/content/docs/trunk/sdk/header-based-plugin-examples/basic-authorization-plugin/implementing-the-handler-and-getting-a-handle-to-the-transaction.en.html
==============================================================================
--- websites/staging/trafficserver/trunk/content/docs/trunk/sdk/header-based-plugin-examples/basic-authorization-plugin/implementing-the-handler-and-getting-a-handle-to-the-transaction.en.html (original)
+++ websites/staging/trafficserver/trunk/content/docs/trunk/sdk/header-based-plugin-examples/basic-authorization-plugin/implementing-the-handler-and-getting-a-handle-to-the-transaction.en.html Tue Dec 14 15:22:36 2010
@@ -8,8 +8,8 @@
<link rel="stylesheet" href="/styles/pygments_style.css">
- <title></title>
-
+ <title>Apache Traffic Server⢠Software Developers Kit</title>
+ <!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at . http://www.apache.org/licenses/LICENSE-2.0 . Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -->
</head>
<body>
@@ -17,11 +17,34 @@
<span id="ts_logo">
<a href="http://trafficserver.apache.org/"><img src="/images/ts75.png" /></a>
</span>
- <h1></h1>
+ <h1>Apache Traffic Server⢠Software Developers Kit</h1>
</div>
<div id="content">
-
+ <p><a href="../basic-authorization-plugin">Prev</a> - The Basic Authorization Plugin</p>
+<p>Working With HTTP Headers - <a href="working-with-http-headers">Next</a></p>
+<h3 id="ImplementingHandlerGettingaHandleTransaction">Implementing the Handler and Getting a Handle to the Transaction</h3>
+<p>The handler function for the plugin's parent continuation is implemented as
+follows:</p>
+<div class="codehilite"><pre><span class="k">static</span> <span class="kt">int</span>
+<span class="nf">auth_plugin</span> <span class="p">(</span><span class="n">TSCont</span> <span class="n">contp</span><span class="p">,</span> <span class="n">TSEvent</span> <span class="n">event</span><span class="p">,</span> <span class="kt">void</span> <span class="o">*</span><span class="n">edata</span><span class="p">)</span>
+<span class="p">{</span>
+
+ <span class="n">TSHttpTxn</span> <span class="n">txnp</span> <span class="o">=</span> <span class="p">(</span><span class="n">TSHttpTxn</span><span class="p">)</span> <span class="n">edata</span><span class="p">;</span>
+ <span class="k">switch</span> <span class="p">(</span><span class="n">event</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">case</span> <span class="n">TS_EVENT_HTTP_OS_DNS</span>:
+ <span class="n">handle_dns</span> <span class="p">(</span><span class="n">txnp</span><span class="p">,</span> <span class="n">contp</span><span class="p">);</span>
+ <span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
+ <span class="k">case</span> <span class="n">TS_EVENT_HTTP_SEND_RESPONSE_HDR</span>:
+ <span class="n">handle_response</span> <span class="p">(</span><span class="n">txnp</span><span class="p">);</span>
+ <span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
+ <span class="nl">default:</span>
+ <span class="k">break</span><span class="p">;</span>
+ <span class="p">}</span>
+
+ <span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
+<span class="p">}</span>
+</pre></div>
</div>
<div id="footer">
Modified: websites/staging/trafficserver/trunk/content/docs/trunk/sdk/header-based-plugin-examples/basic-authorization-plugin/index.en.html
==============================================================================
--- websites/staging/trafficserver/trunk/content/docs/trunk/sdk/header-based-plugin-examples/basic-authorization-plugin/index.en.html (original)
+++ websites/staging/trafficserver/trunk/content/docs/trunk/sdk/header-based-plugin-examples/basic-authorization-plugin/index.en.html Tue Dec 14 15:22:36 2010
@@ -8,8 +8,8 @@
<link rel="stylesheet" href="/styles/pygments_style.css">
- <title></title>
-
+ <title>Apache Traffic Server⢠Software Developers Kit</title>
+ <!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at . http://www.apache.org/licenses/LICENSE-2.0 . Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -->
</head>
<body>
@@ -17,11 +17,23 @@
<span id="ts_logo">
<a href="http://trafficserver.apache.org/"><img src="/images/ts75.png" /></a>
</span>
- <h1></h1>
+ <h1>Apache Traffic Server⢠Software Developers Kit</h1>
</div>
<div id="content">
-
+ <p><a href="../blacklist-plugin/working-with-http-header-functions">Prev</a> - Working with HTTP Header Functions</p>
+<p>Implementing the Handler and Getting a Handle to the Transaction - <a href="implementing-the-handler-and-getting-a-handle-to-the-transaction">Next</a></p>
+<h2 id="BasicAuthorizationPlugin">The Basic Authorization Plugin</h2>
+<p>The sample basic authorization plugin, <code>basic-auth.c</code>, checks for basic HTTP
+proxy authorization. In HTTP basic proxy authorization, client user names and
+passwords are contained in the <code>Proxy-Authorization</code> header. The password is
+encoded using base64 encoding. The plugin checks all incoming requests for
+the authorization header, user name, and password. If the plugin does not find
+all of the these, then it reenables with an error (effectively stopping the
+transaction) and adds a transaction hook to the send response header event. </p>
+<h3 id="CreatingPluginsParentContinuationGlobalHook">Creating the Plugin's Parent Continuation and Global Hook</h3>
+<p>The parent continuation and global hook are created as follows:</p>
+<p><code>TSHttpHookAdd (TS_HTTP_OS_DNS_HOOK, TSContCreate (auth_plugin, NULL));</code></p>
</div>
<div id="footer">
Modified: websites/staging/trafficserver/trunk/content/docs/trunk/sdk/header-based-plugin-examples/basic-authorization-plugin/setting-a-transaction-hook.en.html
==============================================================================
--- websites/staging/trafficserver/trunk/content/docs/trunk/sdk/header-based-plugin-examples/basic-authorization-plugin/setting-a-transaction-hook.en.html (original)
+++ websites/staging/trafficserver/trunk/content/docs/trunk/sdk/header-based-plugin-examples/basic-authorization-plugin/setting-a-transaction-hook.en.html Tue Dec 14 15:22:36 2010
@@ -8,8 +8,8 @@
<link rel="stylesheet" href="/styles/pygments_style.css">
- <title></title>
-
+ <title>Apache Traffic Server⢠Software Developers Kit</title>
+ <!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at . http://www.apache.org/licenses/LICENSE-2.0 . Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -->
</head>
<body>
@@ -17,11 +17,41 @@
<span id="ts_logo">
<a href="http://trafficserver.apache.org/"><img src="/images/ts75.png" /></a>
</span>
- <h1></h1>
+ <h1>Apache Traffic Server⢠Software Developers Kit</h1>
</div>
<div id="content">
-
+ <p><a href="working-with-http-headers">Prev</a> - Working With HTTP Headers</p>
+<p>Chapter 5. HTTP Transformation Plugins - <a href="../../http-transformation-plugin">Next</a></p>
+<h3 id="SettingaTransactionHook">Setting a Transaction Hook</h3>
+<p>If the request does not have the <code>Proxy-Authorization</code> field set to Basic
+authorization or a valid username/password, then the plugin sends the
+407 Proxy authorization <code>required</code> status code back to the client. The
+client will then prompt the user for a username and password, and then resend
+the request.</p>
+<p>In the <code>handle_dns</code> routine, the following lines handle the authorization
+error case:</p>
+<div class="codehilite"><pre><span class="nl">done:</span>
+ <span class="n">TSHttpTxnHookAdd</span> <span class="p">(</span><span class="n">txnp</span><span class="p">,</span> <span class="n">TS_HTTP_SEND_RESPONSE_HDR_HOOK</span><span class="p">,</span> <span class="n">contp</span><span class="p">);</span>
+ <span class="n">TSHttpTxnReenable</span> <span class="p">(</span><span class="n">txnp</span><span class="p">,</span> <span class="n">TS_EVENT_HTTP_ERROR</span><span class="p">);</span>
+</pre></div>
+
+
+<p>If <code>handle_dns</code> does not find the <code>Proxy-Authorization</code> field set to Basic
+authorization or a valid username/password, then it adds a <code>SEND_RESPONSE_HDR_HOOK</code>
+to the transaction being processed. This means that Traffic Server will call
+the plugin back when sending the client response. <code>handle_dns</code> reenables the
+transaction with <code>TS_EVENT_HTTP_ERROR</code>, which means that the plugin wants
+Traffic Server to terminate the transaction.</p>
+<p>When Traffic Server terminates the transaction, it sends the client an error
+message. Because of the <code>SEND_RESPONSE_HDR_HOOK</code>, Traffic Server calls the
+plugin back. The <code>auth-plugin</code> routine calls <code>handle_response</code> to send the
+client a <code>407</code> status code. When the client resends the request with the
+<code>Proxy-Authorization</code> field, a new transaction begins.</p>
+<p><code>handle_dns</code> calls <code>base64_decode</code> to decode the username and password;
+<code>handle_dns</code> also calls <code>authorized</code> to validate the username and password.
+In this plugin, sample NT code is provided for password validation.
+UNIX programmers can supply their own validation mechanism.</p>
</div>
<div id="footer">
Modified: websites/staging/trafficserver/trunk/content/docs/trunk/sdk/header-based-plugin-examples/basic-authorization-plugin/working-with-http-headers.en.html
==============================================================================
--- websites/staging/trafficserver/trunk/content/docs/trunk/sdk/header-based-plugin-examples/basic-authorization-plugin/working-with-http-headers.en.html (original)
+++ websites/staging/trafficserver/trunk/content/docs/trunk/sdk/header-based-plugin-examples/basic-authorization-plugin/working-with-http-headers.en.html Tue Dec 14 15:22:36 2010
@@ -8,8 +8,8 @@
<link rel="stylesheet" href="/styles/pygments_style.css">
- <title></title>
-
+ <title>Apache Traffic Server⢠Software Developers Kit</title>
+ <!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at . http://www.apache.org/licenses/LICENSE-2.0 . Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -->
</head>
<body>
@@ -17,11 +17,84 @@
<span id="ts_logo">
<a href="http://trafficserver.apache.org/"><img src="/images/ts75.png" /></a>
</span>
- <h1></h1>
+ <h1>Apache Traffic Server⢠Software Developers Kit</h1>
</div>
<div id="content">
-
+ <p><a href="implementing-the-handler-and-getting-a-handle-to-the-transaction">Prev</a> - Implementing the Handler and Getting a Handle to the Transaction</p>
+<p>Setting a Transaction Hook - <a href="setting-a-transaction-hook">Next</a></p>
+<h3 id="WorkingWithHTTPHeaders">Working With HTTP Headers</h3>
+<p>The plugin checks all client request headers for the Proxy-Authorization MIME
+field, which should contain the user name and password. The plugin's continuation
+handler, <code>auth-plugin</code>, calls <code>handle_dns</code> to check the <code>Proxy-Authorization</code>
+field. The <code>handle_dns</code> routine uses <code>TSHttpTxnClientReqGet</code> and <code>TSMimeHdrFieldFind</code>
+to obtain the <code>Proxy-Authorization</code> field:</p>
+<div class="codehilite"><pre><span class="p">{</span>
+ <span class="n">TSMBuffer</span> <span class="n">bufp</span><span class="p">;</span>
+ <span class="n">TSMLoc</span> <span class="n">hdr_loc</span><span class="p">;</span>
+ <span class="n">TSMLoc</span> <span class="n">field_loc</span><span class="p">;</span>
+ <span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">val</span><span class="p">;</span>
+ <span class="kt">char</span> <span class="o">*</span><span class="n">user</span><span class="p">,</span> <span class="o">*</span><span class="n">password</span><span class="p">;</span>
+
+ <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="n">TSHttpTxnClientReqGet</span> <span class="p">(</span><span class="n">txnp</span><span class="p">,</span> <span class="o">&</span><span class="n">bufp</span><span class="p">,</span> <span class="o">&</span><span class="n">hdr_loc</span><span class="p">))</span> <span class="p">{</span>
+ <span class="n">TSError</span> <span class="p">(</span><span class="s">"couldn't retrieve client request header</span><span class="se">\n</span><span class="s">"</span><span class="p">);</span>
+ <span class="k">goto</span> <span class="n">done</span><span class="p">;</span>
+ <span class="p">}</span>
+
+ <span class="n">field_loc</span> <span class="o">=</span> <span class="n">TSMimeHdrFieldFind</span> <span class="p">(</span><span class="n">bufp</span><span class="p">,</span> <span class="n">hdr_loc</span><span class="p">,</span>
+ <span class="n">TS_MIME_FIELD_PROXY_AUTHORIZATION</span><span class="p">);</span>
+</pre></div>
+
+
+<p>If the <code>Proxy-Authorization</code> field is present, then the plugin checks that
+the authentication type is "Basic", and the user name and password are present
+and valid:</p>
+<div class="codehilite"><pre><span class="n">val</span> <span class="o">=</span> <span class="n">TSMimeHdrFieldValueStringGet</span> <span class="p">(</span><span class="n">bufp</span><span class="p">,</span> <span class="n">hdr_loc</span><span class="p">,</span> <span class="n">field_loc</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="o">&</span><span class="n">authval_length</span><span class="p">);</span>
+<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="n">val</span><span class="p">)</span> <span class="p">{</span>
+ <span class="n">TSError</span> <span class="p">(</span><span class="s">"no value in Proxy-Authorization field</span><span class="se">\n</span><span class="s">"</span><span class="p">);</span>
+ <span class="n">TSHandleMLocRelease</span> <span class="p">(</span><span class="n">bufp</span><span class="p">,</span> <span class="n">hdr_loc</span><span class="p">,</span> <span class="n">field_loc</span><span class="p">);</span>
+ <span class="n">TSHandleMLocRelease</span> <span class="p">(</span><span class="n">bufp</span><span class="p">,</span> <span class="n">TS_NULL_MLOC</span><span class="p">,</span> <span class="n">hdr_loc</span><span class="p">);</span>
+ <span class="k">goto</span> <span class="n">done</span><span class="p">;</span>
+<span class="p">}</span>
+
+<span class="k">if</span> <span class="p">(</span><span class="n">strncmp</span> <span class="p">(</span><span class="n">val</span><span class="p">,</span> <span class="s">"Basic"</span><span class="p">,</span> <span class="mi">5</span><span class="p">)</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">)</span> <span class="p">{</span>
+ <span class="n">TSError</span> <span class="p">(</span><span class="s">"no Basic auth type in Proxy-Authorization</span><span class="se">\n</span><span class="s">"</span><span class="p">);</span>
+ <span class="n">TSHandleMLocRelease</span> <span class="p">(</span><span class="n">bufp</span><span class="p">,</span> <span class="n">hdr_loc</span><span class="p">,</span> <span class="n">field_loc</span><span class="p">);</span>
+ <span class="n">TSHandleMLocRelease</span> <span class="p">(</span><span class="n">bufp</span><span class="p">,</span> <span class="n">TS_NULL_MLOC</span><span class="p">,</span> <span class="n">hdr_loc</span><span class="p">);</span>
+ <span class="k">goto</span> <span class="n">done</span><span class="p">;</span>
+<span class="p">}</span>
+
+<span class="n">val</span> <span class="o">+=</span> <span class="mi">5</span><span class="p">;</span>
+<span class="k">while</span> <span class="p">((</span><span class="o">*</span><span class="n">val</span> <span class="o">==</span> <span class="sc">' '</span><span class="p">)</span> <span class="o">||</span> <span class="p">(</span><span class="o">*</span><span class="n">val</span> <span class="o">==</span> <span class="sc">'\t'</span><span class="p">))</span> <span class="p">{</span>
+ <span class="n">val</span> <span class="o">+=</span> <span class="mi">1</span><span class="p">;</span>
+<span class="p">}</span>
+
+<span class="n">user</span> <span class="o">=</span> <span class="n">base64_decode</span> <span class="p">(</span><span class="n">val</span><span class="p">);</span>
+<span class="n">password</span> <span class="o">=</span> <span class="n">strchr</span> <span class="p">(</span><span class="n">user</span><span class="p">,</span> <span class="sc">':'</span><span class="p">);</span>
+<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="n">password</span><span class="p">)</span> <span class="p">{</span>
+ <span class="n">TSError</span> <span class="p">(</span><span class="s">"no password in authorization information</span><span class="se">\n</span><span class="s">"</span><span class="p">);</span>
+ <span class="n">TSfree</span> <span class="p">(</span><span class="n">user</span><span class="p">);</span>
+ <span class="n">TSHandleMLocRelease</span> <span class="p">(</span><span class="n">bufp</span><span class="p">,</span> <span class="n">hdr_loc</span><span class="p">,</span> <span class="n">field_loc</span><span class="p">);</span>
+ <span class="n">TSHandleMLocRelease</span> <span class="p">(</span><span class="n">bufp</span><span class="p">,</span> <span class="n">TS_NULL_MLOC</span><span class="p">,</span> <span class="n">hdr_loc</span><span class="p">);</span>
+ <span class="k">goto</span> <span class="n">done</span><span class="p">;</span>
+<span class="p">}</span>
+<span class="o">*</span><span class="n">password</span> <span class="o">=</span> <span class="sc">'\0'</span><span class="p">;</span>
+<span class="n">password</span> <span class="o">+=</span> <span class="mi">1</span><span class="p">;</span>
+
+<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="n">authorized</span> <span class="p">(</span><span class="n">user</span><span class="p">,</span> <span class="n">password</span><span class="p">))</span> <span class="p">{</span>
+ <span class="n">TSError</span> <span class="p">(</span><span class="s">"%s:%s not authorized</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> <span class="n">user</span><span class="p">,</span> <span class="n">password</span><span class="p">);</span>
+ <span class="n">TSfree</span> <span class="p">(</span><span class="n">user</span><span class="p">);</span>
+ <span class="n">TSHandleMLocRelease</span> <span class="p">(</span><span class="n">bufp</span><span class="p">,</span> <span class="n">hdr_loc</span><span class="p">,</span> <span class="n">field_loc</span><span class="p">);</span>
+ <span class="n">TSHandleMLocRelease</span> <span class="p">(</span><span class="n">bufp</span><span class="p">,</span> <span class="n">TS_NULL_MLOC</span><span class="p">,</span> <span class="n">hdr_loc</span><span class="p">);</span>
+ <span class="k">goto</span> <span class="n">done</span><span class="p">;</span>
+<span class="p">}</span>
+
+<span class="n">TSfree</span> <span class="p">(</span><span class="n">user</span><span class="p">);</span>
+<span class="n">TSHandleMLocRelease</span> <span class="p">(</span><span class="n">bufp</span><span class="p">,</span> <span class="n">hdr_loc</span><span class="p">,</span> <span class="n">field_loc</span><span class="p">);</span>
+<span class="n">TSHandleMLocRelease</span> <span class="p">(</span><span class="n">bufp</span><span class="p">,</span> <span class="n">TS_NULL_MLOC</span><span class="p">,</span> <span class="n">hdr_loc</span><span class="p">);</span>
+<span class="n">TSHttpTxnReenable</span> <span class="p">(</span><span class="n">txnp</span><span class="p">,</span> <span class="n">TS_EVENT_HTTP_CONTINUE</span><span class="p">);</span>
+<span class="k">return</span><span class="p">;</span>
+</pre></div>
</div>
<div id="footer">