static htaccess_context_s *
_htaccess_newctxt(pblock *pb, Session *sn, Request *rq)
{
    htaccess_context_s *ctxt = 
        (htaccess_context_s *) MALLOC(sizeof(htaccess_context_s));
    char *rhst = session_dns(sn);

    ctxt->pb = pb;
    ctxt->sn = sn;
    ctxt->rq = rq;

    ctxt->auth_type = NULL;
    ctxt->auth_name = NULL;
    ctxt->auth_pwfile = NULL;
    ctxt->auth_grpfile = NULL;
    ctxt->auth_authdb = 0;
    ctxt->auth_grplist = 0;
    ctxt->auth_grplfile = 0;
    ctxt->auth_grpllen = 0;
    ctxt->user_check_fn = NULL;
    ctxt->group_check_fn = NULL;

#ifdef AUTHNSDBFILE
    ctxt->auth_uoptr = 0;
    ctxt->auth_nsdb = 0;
#endif /* AUTHNSDBFILE */
    ctxt->auth_line = pblock_findval("authorization", rq->headers);

    ctxt->num_sec = 0;

    ctxt->remote_host = rhst;
    ctxt->remote_ip = pblock_findval("ip", sn->client);
    ctxt->remote_name = rhst ? rhst : ctxt->remote_ip;

    ctxt->access_name = pblock_findval("filename", pb);
    if(!ctxt->access_name)
        ctxt->access_name = DEFAULT_ACCESS_FNAME;

    ctxt->user[0] = '\0';
    ctxt->groupname[0] = '\0';

    ctxt->sec = htaccess_newsec();

    return ctxt;
}
Exemple #2
0
/*
 *	Copy Headers into the request.
 *
 *	This is kind of like an easter egg hunt, CGI equivilant headers are
 *	stashed all over in different pblocks.  Do the best we can without
 *	missing any...
 */
static void copyHeaders(pblock *pb, Session *sn, Request *rq, HTTPRequest *req)
{
   int i;
   const char *hdrval;
   char *portstr;
   const char *server;


   /*
    *	the following line will generate a compiler warning. uncomment if
    *	Netscape ever implements it. request_loadheaders(sn,rq);
    */

   /*
    *	first, blindly copy the request headers
    */
   for (i=0; i < rq->headers->hsize; i++) {
      struct pb_entry *entry = rq->headers->ht[i];
      while (entry != NULL) {
         pb_param *hdr = entry->param;
         if (hdr != NULL)
            req_addHeader(req, hdr->name, hdr->value, 0);
         	   entry = entry->next;
      }
   }

   for (i=0; i < rq->vars->hsize; i++) {
      struct pb_entry *entry = rq->vars->ht[i];
      while (entry != NULL) {
         pb_param *hdr = entry->param;
          if (hdr != NULL) {
              /*
               * BEGIN Support for getting the client's certificate as one liner.
               */
              if (strcmp((const char *)hdr->name, "auth-cert") == 0 && hdr->value != NULL) {
                  const char *val = (const char *)make_cert_one_line((char *)hdr->value);
                  if(val != NULL){
                      req_addHeader(req, "SSL_CLIENT_CERT", val, 0);
                      //WOLog(WO_DBG, "Adding server variable %s", hdr->name);
                      //WOLog(WO_DBG, "With value %s", hdr->value);
                  }
                  /*
                   * END Support for getting the client's certificate.
                   */
                  else {
                      req_addHeader(req, hdr->name, hdr->value, 0);
                      //WOLog(WO_DBG, "Adding server variable %s", hdr->name);
                      //WOLog(WO_DBG, "With value %s", hdr->value);
                  }
              }
         }
         entry = entry->next;
      }
   }

   if (req->method == HTTP_POST_METHOD)
      req_addHeader(req,"REQUEST_METHOD","POST", 0);
   else if (req->method == HTTP_HEAD_METHOD)
      req_addHeader(req,"REQUEST_METHOD","HEAD", 0);
   else
      req_addHeader(req,"REQUEST_METHOD","GET", 0);

   /*
    *	collect up the server specific headers
    */
   cpyhdr("ip", sn->client, req, "REMOTE_ADDR");
   cpyhdr("query", rq->reqpb, req, "QUERY_STRING");
   cpyhdr("protocol", rq->reqpb, req, "SERVER_PROTOCOL");

   hdrval = session_maxdns(sn);
   if (!hdrval)	hdrval = session_dns(sn);
   if (hdrval)
      req_addHeader(req, "REMOTE_HOST", hdrval, 0);
   req_addHeader(req, "SERVER_SOFTWARE", system_version(), 0);
   portstr = (char *)WOMALLOC(32);
   if (portstr)
   {
      util_itoa(server_portnum, portstr);
      req_addHeader(req, "SERVER_PORT", portstr, STR_FREEVALUE);
   }

   /*
    *	Netscape claims to have fixed this in 3, if it causes a problem
    *	comment it out
    */
   server = server_hostname;
   if (server != NULL)
      req_addHeader(req, "SERVER_NAME", server, 0);


   return;
}