Web servers process requests in phases—user authentication, HTTP header processing, URL-to-filename mapping. Each phase creates the opportunity for a server extension—which can be a Netscape Server API (NSAPI) plug-in, or an Apache module, or an ISAPI filter—to alter the server’s behavior in some useful way. In this case we need to hook into the user authentication phase. Microsoft’sVisual C++ compiler makes that very easy to do, because it includes a wizard that knows about the phases of IIS request processing and can generate the framework for a filter that deals with one or more of these phases. To create a custom authentication handler, start the MS Developer Studio and do File → New → Projects → ISAPI Extension Wizard. Check the Generate a Filter Object box, uncheck Generate a Server Extension Object, and then complete the ensuing dialog box, as shown in Figure 12.1.
Figure 12-1. Generating the framework for an ISAPI filter
Example 12.2 shows our completed authentication
filter. It’s mostly boilerplate code written by the wizard. The
four lines in the body of the
CMod_authFilter::onAuthentication( ) method are
the only human contribution to this filter.
Example 12-2. A Pass-Through Isapi Authentication Filter
// MOD_AUTH.CPP - Implementation file for your Internet Server // mod_auth Filter #include "stdafx.h" #include "mod_auth.h" CWinApp ...