LTP GCOV extension - code coverage report
Current view: directory - and-httpd/src - httpd_policy.c
Test: And-httpd coverage
Date: 2006-09-11 Instrumented lines: 429
Code covered: 88.3 % Executed lines: 379

       1                 : 
       2                 : #include "httpd.h"
       3                 : #include "httpd_policy.h"
       4                 : 
       5                 : #define EX_UTILS_NO_FUNCS 1
       6                 : #include "ex_utils.h"
       7                 : 
       8                 : #include "mk.h"
       9                 : 
      10                 : static void httpd__policy_path_ref_free(Vstr_ref *ref)
      11            5384 : {
      12            5384 :   Httpd_policy_path *path = NULL;
      13                 : 
      14            5384 :   if (!ref)
      15               0 :     return;
      16                 :   
      17            5384 :   path = ref->ptr;
      18            5384 :   vstr_free_base(path->s1);
      19            5384 :   (*path->ref_func)(ref);
      20                 : }
      21                 : 
      22                 : static int httpd__policy_path_init(Httpd_policy_path *path,
      23                 :                                    Vstr_base *s1, size_t pos, size_t len, 
      24                 :                                    Vstr_ref *ref)
      25            5384 : {
      26            5384 :   size_t tmp = 0;
      27                 :   
      28            2692 :   ASSERT(ref->ref == 1);
      29                 :   
      30            5384 :   if (!(s1 = vstr_dup_vstr(s1->conf, s1, pos, len, 0)))
      31               0 :     return (FALSE);
      32            5384 :   path->s1 = s1;
      33                 : 
      34                 :   /* remove any double slashes... */
      35           10768 :   while ((tmp = vstr_srch_cstr_buf_fwd(s1, 1, s1->len, "//")))
      36               0 :     if (!vstr_del(s1, tmp, 1))
      37                 :     {
      38               0 :       vstr_free_base(s1);
      39               0 :       return (FALSE);
      40                 :     }
      41                 :   
      42            5384 :   path->ref_func = ref->func;
      43                 :   
      44            5384 :   ref->func = httpd__policy_path_ref_free;
      45                 : 
      46            5384 :   return (TRUE);
      47                 : }
      48                 : 
      49                 : static int httpd_policy__build_parent_path(Vstr_base *s1, Vstr_base *s2)
      50             480 : {
      51             480 :   size_t pos = 0;
      52             480 :   size_t len = 0;
      53                 : 
      54             240 :   ASSERT(s1 && s2);
      55                 :   
      56             480 :   if (!s2->len)
      57               0 :     return (TRUE);
      58                 :       
      59             480 :   if (s2->len == 1)
      60                 :   {
      61               0 :     ASSERT(vstr_cmp_cstr_eq(s2, 1, s2->len, "/"));
      62               0 :     vstr_add_cstr_ptr(s1, s1->len, "/");
      63               0 :     return (TRUE);
      64                 :   }
      65                 :       
      66             480 :   if (!(pos = vstr_srch_chr_rev(s2, 1, s2->len - 1, '/')))
      67                 :   {
      68             480 :     vstr_add_cstr_ptr(s1, s1->len, "./");
      69             480 :     return (TRUE);
      70                 :   }
      71                 :       
      72               0 :   len = vstr_sc_posdiff(1, pos);
      73               0 :   HTTPD_APP_REF_VSTR(s1, s2, 1, len);
      74                 : 
      75               0 :   return (TRUE);
      76                 : }
      77                 : 
      78                 : /* builds into conf->tmp */
      79                 : static int httpd_policy__build_path(struct Con *con, Httpd_req_data *req,
      80                 :                                     const Conf_parse *conf, Conf_token *token,
      81                 :                                     int *used_policy, int *used_req)
      82            8320 : {
      83            8320 :   struct Opt_serv_opts *opts = req->policy->s->beg;
      84            8320 :   int clist = FALSE;
      85            8320 :   size_t vhost_prefix_len = req->vhost_prefix_len;
      86            8320 :   size_t fname_pos = 0;
      87            8320 :   size_t fname_len = 0;
      88                 : 
      89                 :   /* FIXME: how does (vhost_prefix_len >= req->fname->len) happen ? */
      90            8320 :   if (vhost_prefix_len >= req->fname->len)
      91               0 :     vhost_prefix_len = 0;
      92                 :   
      93            8320 :   fname_pos = vhost_prefix_len + 1;
      94            8320 :   fname_len = vstr_sc_posdiff(fname_pos, req->fname->len);
      95                 : 
      96           38144 :   CONF_SC_MAKE_CLIST_BEG(policy_build_path, clist);
      97                 :     
      98           21504 :   else if (OPT_SERV_SYM_EQ("<basename>"))
      99                 :   {
     100             160 :     size_t pos = fname_pos;
     101             160 :     size_t len = fname_len;
     102                 :     
     103             160 :     *used_req = TRUE;
     104             160 :     httpd_policy_path_mod_name(req->fname, &pos, &len);
     105             160 :     HTTPD_APP_REF_VSTR(conf->tmp, req->fname, pos, len);
     106                 :   }
     107           21344 :   else if (OPT_SERV_SYM_EQ("<url-basename>"))
     108                 :   {
     109             160 :     size_t pos = req->path_pos;
     110             160 :     size_t len = req->path_len;
     111                 :     
     112             160 :     *used_req = TRUE;
     113             160 :     if (req->policy->chk_encoded_dot && req->policy->chk_encoded_slash)
     114               0 :       httpd_policy_path_mod_name(con->evnt->io_r, &pos, &len);
     115                 :     else
     116             160 :       httpd_policy_uri_mod_name(con->evnt->io_r, &pos, &len);
     117             160 :     HTTPD_APP_REF_VSTR(conf->tmp, con->evnt->io_r, pos, len);
     118                 :   }
     119           21184 :   else if (OPT_SERV_SYM_EQ("<basename-without-extension>"))
     120                 :   {
     121             160 :     size_t pos = fname_pos;
     122             160 :     size_t len = fname_len;
     123                 :     
     124             160 :     *used_req = TRUE;
     125             160 :     httpd_policy_path_mod_bwen(req->fname, &pos, &len);
     126             160 :     HTTPD_APP_REF_VSTR(conf->tmp, req->fname, pos, len);
     127                 :   }
     128           21024 :   else if (OPT_SERV_SYM_EQ("<url-basename-without-extension>"))
     129                 :   {
     130             160 :     size_t pos = req->path_pos;
     131             160 :     size_t len = req->path_len;
     132                 :     
     133             160 :     *used_req = TRUE;
     134             160 :     if (req->policy->chk_encoded_dot && req->policy->chk_encoded_slash)
     135               0 :       httpd_policy_path_mod_bwen(con->evnt->io_r, &pos, &len);
     136                 :     else
     137             160 :       httpd_policy_uri_mod_bwen(con->evnt->io_r, &pos, &len);
     138             160 :     HTTPD_APP_REF_VSTR(conf->tmp, con->evnt->io_r, pos, len);
     139                 :   }
     140           20864 :   else if (OPT_SERV_SYM_EQ("<basename-without-extensions>"))
     141                 :   {
     142             160 :     size_t pos = fname_pos;
     143             160 :     size_t len = fname_len;
     144                 :     
     145             160 :     *used_req = TRUE;
     146             160 :     httpd_policy_path_mod_bwes(req->fname, &pos, &len);
     147             160 :     HTTPD_APP_REF_VSTR(conf->tmp, req->fname, pos, len);
     148                 :   }
     149           20704 :   else if (OPT_SERV_SYM_EQ("<url-basename-without-extensions>"))
     150                 :   {
     151             160 :     size_t pos = req->path_pos;
     152             160 :     size_t len = req->path_len;
     153                 :     
     154             160 :     *used_req = TRUE;
     155             160 :     if (req->policy->chk_encoded_dot && req->policy->chk_encoded_slash)
     156               0 :       httpd_policy_path_mod_bwes(con->evnt->io_r, &pos, &len);
     157                 :     else
     158             160 :       httpd_policy_uri_mod_bwes(con->evnt->io_r, &pos, &len);
     159             160 :     HTTPD_APP_REF_VSTR(conf->tmp, con->evnt->io_r, pos, len);
     160                 :   }
     161           20544 :   else if (OPT_SERV_SYM_EQ("<directory-filename>"))
     162                 :   {
     163            1696 :     Vstr_base *s1 = req->policy->dir_filename;
     164            1696 :     *used_policy = TRUE;
     165            1696 :     HTTPD_APP_REF_ALLVSTR(conf->tmp, s1);
     166                 :   }
     167           18848 :   else if (OPT_SERV_SYM_EQ("<dirname>"))
     168                 :   {
     169             160 :     size_t pos = fname_pos;
     170             160 :     size_t len = fname_len;
     171                 :     
     172             160 :     *used_req = TRUE;
     173             160 :     httpd_policy_path_mod_dirn(req->fname, &pos, &len);
     174             160 :     HTTPD_APP_REF_VSTR(conf->tmp, req->fname, pos, len);
     175                 :   }
     176           18688 :   else if (OPT_SERV_SYM_EQ("<url-dirname>"))
     177                 :   {
     178             160 :     size_t pos = req->path_pos;
     179             160 :     size_t len = req->path_len;
     180                 :     
     181             160 :     *used_req = TRUE;
     182             160 :     if (req->policy->chk_encoded_dot && req->policy->chk_encoded_slash)
     183               0 :       httpd_policy_path_mod_dirn(con->evnt->io_r, &pos, &len);
     184                 :     else
     185             160 :       httpd_policy_uri_mod_dirn(con->evnt->io_r, &pos, &len);
     186             160 :     HTTPD_APP_REF_VSTR(conf->tmp, con->evnt->io_r, pos, len);
     187                 :   }
     188           18720 :   else if (OPT_SERV_SYM_EQ("<document-root>") ||
     189                 :            OPT_SERV_SYM_EQ("<doc-root>"))
     190                 :   {
     191             192 :     Vstr_base *s1 = req->policy->document_root;
     192             192 :     *used_policy = TRUE;
     193             192 :     HTTPD_APP_REF_ALLVSTR(conf->tmp, s1);
     194                 :   }
     195           18496 :   else if (OPT_SERV_SYM_EQ("<document-root/..>") ||
     196                 :            OPT_SERV_SYM_EQ("<doc-root/..>"))
     197                 :   {
     198              80 :     ASSERT(req->policy->document_root->len);
     199             160 :     if (!httpd_policy__build_parent_path(conf->tmp,
     200                 :                                          req->policy->document_root))
     201               0 :       return (FALSE);
     202             160 :     *used_policy = TRUE;
     203                 :   }
     204           18176 :   else if (OPT_SERV_SYM_EQ("<extension>"))
     205                 :   {
     206             416 :     size_t pos = fname_pos;
     207             416 :     size_t len = fname_len;
     208                 :     
     209             416 :     *used_req = TRUE;
     210             416 :     httpd_policy_path_mod_extn(req->fname, &pos, &len);
     211             416 :     HTTPD_APP_REF_VSTR(conf->tmp, req->fname, pos, len);
     212                 :   }
     213           17760 :   else if (OPT_SERV_SYM_EQ("<url-extension>"))
     214                 :   {
     215             160 :     size_t pos = req->path_pos;
     216             160 :     size_t len = req->path_len;
     217                 :     
     218             160 :     *used_req = TRUE;
     219             160 :     if (req->policy->chk_encoded_dot && req->policy->chk_encoded_slash)
     220               0 :       httpd_policy_path_mod_extn(con->evnt->io_r, &pos, &len);
     221                 :     else
     222             160 :       httpd_policy_uri_mod_extn(con->evnt->io_r, &pos, &len);
     223             160 :     HTTPD_APP_REF_VSTR(conf->tmp, con->evnt->io_r, pos, len);
     224                 :   }
     225           17600 :   else if (OPT_SERV_SYM_EQ("<extensions>"))
     226                 :   {
     227             416 :     size_t pos = fname_pos;
     228             416 :     size_t len = fname_len;
     229                 :     
     230             416 :     *used_req = TRUE;
     231             416 :     httpd_policy_path_mod_exts(req->fname, &pos, &len);
     232             416 :     HTTPD_APP_REF_VSTR(conf->tmp, req->fname, pos, len);
     233                 :   }
     234           17184 :   else if (OPT_SERV_SYM_EQ("<url-extensions>"))
     235                 :   {
     236             160 :     size_t pos = req->path_pos;
     237             160 :     size_t len = req->path_len;
     238                 :     
     239             160 :     *used_req = TRUE;
     240             160 :     if (req->policy->chk_encoded_dot && req->policy->chk_encoded_slash)
     241               0 :       httpd_policy_path_mod_exts(con->evnt->io_r, &pos, &len);
     242                 :     else
     243             160 :       httpd_policy_uri_mod_exts(con->evnt->io_r, &pos, &len);      
     244             160 :     HTTPD_APP_REF_VSTR(conf->tmp, con->evnt->io_r, pos, len);
     245                 :   }
     246           17248 :   else if (OPT_SERV_SYM_EQ("<hostname>") || OPT_SERV_SYM_EQ("<url-hostname>"))
     247                 :   { /* this adds hostname:port */
     248             224 :     *used_req = TRUE;
     249             224 :     httpd_sc_add_hostname(con, req, conf->tmp, conf->tmp->len);
     250                 :   }
     251           16960 :   else if (OPT_SERV_SYM_EQ("<request-configuration-directory>") ||
     252                 :            OPT_SERV_SYM_EQ("<req-conf-dir>"))
     253                 :   {
     254             160 :     Vstr_base *s1 = req->policy->req_conf_dir;
     255             160 :     *used_policy = TRUE;
     256             160 :     HTTPD_APP_REF_ALLVSTR(conf->tmp, s1);
     257                 :   }
     258           16800 :   else if (OPT_SERV_SYM_EQ("<request-configuration-directory/..>") ||
     259                 :            OPT_SERV_SYM_EQ("<req-conf-dir/..>"))
     260                 :   {
     261             160 :     if (!httpd_policy__build_parent_path(conf->tmp,
     262                 :                                          req->policy->req_conf_dir))
     263               0 :       return (FALSE);
     264             160 :     *used_policy = TRUE;
     265                 :   }
     266           16640 :   else if (OPT_SERV_SYM_EQ("<request-error-directory>") ||
     267                 :            OPT_SERV_SYM_EQ("<req-err-dir>"))
     268                 :   {
     269             160 :     Vstr_base *s1 = req->policy->req_err_dir;
     270             160 :     *used_policy = TRUE;
     271             160 :     HTTPD_APP_REF_ALLVSTR(conf->tmp, s1);
     272                 :   }
     273           16480 :   else if (OPT_SERV_SYM_EQ("<request-error-directory/..>") ||
     274                 :            OPT_SERV_SYM_EQ("<req-err-dir/..>"))
     275                 :   {
     276             160 :     if (!httpd_policy__build_parent_path(conf->tmp, req->policy->req_err_dir))
     277               0 :       return (FALSE);
     278             160 :     *used_policy = TRUE;
     279                 :   }
     280           17024 :   else if (OPT_SERV_SYM_EQ("<path>") ||
     281                 :            (!req->direct_uri      && OPT_SERV_SYM_EQ("<file-path>")) ||
     282                 :            (!req->direct_filename && OPT_SERV_SYM_EQ("<Location:>")))
     283                 :   {
     284             864 :     size_t pos = fname_pos;
     285             864 :     size_t len = fname_len;
     286                 :     
     287             864 :     *used_req = TRUE;
     288                 :     
     289             864 :     HTTPD_APP_REF_VSTR(conf->tmp, req->fname, pos, len);
     290                 :   }
     291           15296 :   else if (OPT_SERV_SYM_EQ("<path-full>") ||
     292                 :            (!req->direct_uri      && OPT_SERV_SYM_EQ("<file-path-full>")))
     293                 :   { /* includes virtual host data, if it's there */
     294               0 :     *used_req = TRUE;
     295                 :     
     296               0 :     HTTPD_APP_REF_ALLVSTR(conf->tmp, req->fname);
     297                 :   }
     298           15296 :   else if (OPT_SERV_SYM_EQ("<url-path>"))
     299                 :   {
     300             160 :     *used_req = TRUE;
     301             160 :     HTTPD_APP_REF_VSTR(conf->tmp,
     302                 :                        con->evnt->io_r, req->path_pos, req->path_len);
     303                 :   }
     304           16496 :   else if (OPT_SERV_SYM_EQ("<content-type-ext>") ||
     305                 :            OPT_SERV_SYM_EQ("<content-type-extension>") ||
     306                 :            OPT_SERV_SYM_EQ("<content-type-path>"))
     307                 :   {
     308            2720 :     const Vstr_base *s1 = req->ext_vary_a_vs1;
     309            2720 :     size_t pos          = req->ext_vary_a_pos;
     310            2720 :     size_t len          = req->ext_vary_a_len;
     311                 :     
     312            2720 :     *used_req = TRUE;
     313            2720 :     if (s1 && len)
     314            2624 :       HTTPD_APP_REF_VSTR(conf->tmp, s1, pos, len);
     315                 :   }
     316           13856 :   else if (OPT_SERV_SYM_EQ("<content-lang-ext>") ||
     317                 :            OPT_SERV_SYM_EQ("<content-language-ext>") ||
     318                 :            OPT_SERV_SYM_EQ("<content-language-extension>") ||
     319                 :            OPT_SERV_SYM_EQ("<content-language-path>"))
     320                 :   {
     321            2880 :     const Vstr_base *s1 = req->ext_vary_al_vs1;
     322            2880 :     size_t pos          = req->ext_vary_al_pos;
     323            2880 :     size_t len          = req->ext_vary_al_len;
     324                 :       
     325            2880 :     *used_req = TRUE;
     326            2880 :     if (s1 && len)
     327            2592 :       HTTPD_APP_REF_VSTR(conf->tmp, s1, pos, len);
     328                 :   }
     329            9536 :   else if (OPT_SERV_SYM_EQ("<lowercase>"))
     330                 :   {
     331             480 :     size_t olen = conf->tmp->len;
     332             480 :     size_t nlen = 0;
     333                 :     
     334             480 :     if (!httpd_policy__build_path(con, req, conf, token, used_policy, used_req))
     335               0 :       return (FALSE);
     336             480 :     nlen = conf->tmp->len;
     337                 :     
     338             480 :     if (olen < nlen)
     339                 :     {
     340             480 :       ++olen;
     341             480 :       vstr_conv_lowercase(conf->tmp, olen, vstr_sc_posdiff(olen, nlen));
     342                 :     }
     343                 :     else
     344               0 :       ASSERT(nlen == olen);
     345                 :   }
     346            9056 :   else if (OPT_SERV_SYM_EQ("<uppercase>"))
     347                 :   {
     348             416 :     size_t olen = conf->tmp->len;
     349             416 :     size_t nlen = 0;
     350                 :     
     351             416 :     if (!httpd_policy__build_path(con, req, conf, token, used_policy, used_req))
     352               0 :       return (FALSE);
     353             416 :     nlen = conf->tmp->len;
     354                 :     
     355             416 :     if (olen < nlen)
     356                 :     {
     357             416 :       ++olen;
     358             416 :       vstr_conv_uppercase(conf->tmp, olen, vstr_sc_posdiff(olen, nlen));
     359                 :     }
     360                 :     else
     361               0 :       ASSERT(nlen == olen);
     362                 :   }
     363                 :   else if (TRUE)
     364                 :   {
     365            8640 :     if (!opt_serv_build_single_str(opts, conf, token, clist, FALSE))
     366               0 :       return (FALSE);
     367                 :   }
     368                 :   
     369                 :   CONF_SC_MAKE_CLIST_END();
     370                 : 
     371            8320 :   return (TRUE);
     372                 : }
     373                 : 
     374                 : int httpd_policy_build_path(struct Con *con, Httpd_req_data *req,
     375                 :                             const Conf_parse *conf, Conf_token *token,
     376                 :                             int *used_policy, int *used_req)
     377            7424 : {
     378                 :   int dummy_used_policy;
     379                 :   int dummy_used_req;
     380                 : 
     381            7424 :   if (!used_policy) used_policy = &dummy_used_policy;
     382            7424 :   if (!used_req)    used_req    = &dummy_used_req;
     383            7424 :   *used_policy = *used_req = FALSE;
     384                 :   
     385            7424 :   vstr_del(conf->tmp, 1, conf->tmp->len);
     386            7424 :   if (!httpd_policy__build_path(con, req, conf, token, used_policy, used_req))
     387               0 :     return (FALSE);
     388                 : 
     389                 :   /* we "didn't use the policy" if we only have one policy */
     390            7424 :   if (!con->policy->s->beg->def_policy->next)
     391               0 :     *used_policy = FALSE;
     392                 :   /* FIXME: if we are in here inside a group with a test for policy-eq
     393                 :    * then we can act like we didn't use the policy.
     394                 :    */
     395                 :   
     396            7424 :   return (TRUE);
     397                 : }
     398                 : 
     399                 : int httpd_policy_path_make(struct Con *con, Httpd_req_data *req,
     400                 :                            Conf_parse *conf, Conf_token *token,
     401                 :                            unsigned int type, Vstr_ref **ret_ref)
     402            5384 : {
     403            5384 :   Conf_token save = *token;
     404            5384 :   Vstr_ref *ref = NULL;
     405            5384 :   int ret = FALSE;
     406            5384 :   int used_pol = FALSE;
     407            5384 :   int used_req = FALSE;
     408            5384 :   int clist = FALSE;
     409                 :   
     410            2692 :   ASSERT(ret_ref);
     411            5384 :   *ret_ref     = NULL;
     412                 : 
     413            5384 :   CONF_SC_PARSE_TOP_TOKEN_RET(conf, token, FALSE);
     414            5384 :   CONF_SC_TOGGLE_CLIST_VAR(clist);
     415                 : 
     416            6264 :   if (OPT_SERV_SYM_EQ("assign") || OPT_SERV_SYM_EQ("="))
     417                 :   {
     418            1760 :     if (!httpd_policy_build_path(con, req, conf, token, &used_pol, &used_req))
     419               0 :       return (FALSE);
     420                 :   }
     421            3624 :   else if (clist)
     422               0 :     return (FALSE);
     423                 :   else
     424                 :   {
     425            3624 :     const Vstr_sect_node *pv = conf_token_value(token);
     426            3624 :     Vstr_base *s1 = conf->tmp;
     427            3624 :     if (!pv || !vstr_sub_vstr(s1, 1, s1->len, conf->data, pv->pos, pv->len,
     428                 :                               VSTR_TYPE_SUB_BUF_REF))
     429               0 :       return (FALSE);
     430            3624 :     OPT_SERV_X__ESC_VSTR(s1, 1, pv->len);    
     431                 :   }
     432                 :   
     433            5384 :   if (!(ref = vstr_ref_make_malloc(sizeof(Httpd_policy_path))))
     434               0 :     return (FALSE);
     435                 : 
     436            5384 :   ret = httpd__policy_path_init(ref->ptr, conf->tmp, 1, conf->tmp->len, ref);
     437            5384 :   if (ret && !(used_pol || used_req))
     438            3624 :     ret = conf_token_set_user_value(conf, &save, type, ref, token->num);
     439                 :   
     440            5384 :   if (ret)
     441            5384 :     *ret_ref = ref;
     442                 : 
     443            5384 :   return (ret);
     444                 : }
     445                 : 
     446                 : void httpd_policy_exit(Httpd_policy_opts *opts)
     447             144 : {
     448              72 :   ASSERT(opts);
     449                 :   
     450             144 :   vstr_free_base(opts->document_root);     opts->document_root      = NULL;
     451             144 :   vstr_free_base(opts->server_name);       opts->server_name        = NULL;
     452             144 :   vstr_free_base(opts->dir_filename);      opts->dir_filename       = NULL;
     453             144 :   vstr_free_base(opts->mime_types_def_ct); opts->mime_types_def_ct  = NULL;
     454             144 :   vstr_free_base(opts->mime_types_main);   opts->mime_types_main    = NULL;
     455             144 :   vstr_free_base(opts->mime_types_xtra);   opts->mime_types_xtra    = NULL;
     456             144 :   vstr_free_base(opts->default_hostname);  opts->default_hostname   = NULL;
     457             144 :   vstr_free_base(opts->req_conf_dir);      opts->req_conf_dir       = NULL;
     458             144 :   vstr_free_base(opts->req_err_dir);       opts->req_err_dir        = NULL;
     459             144 :   vstr_free_base(opts->auth_realm);        opts->auth_realm         = NULL;
     460             144 :   vstr_free_base(opts->auth_token);        opts->auth_token         = NULL;
     461                 : 
     462             144 :   opt_policy_exit(opts->s);
     463             144 : }
     464                 : 
     465                 : int httpd_policy_init(Httpd_opts *beg, Httpd_policy_opts *opts)
     466             162 : { 
     467             162 :   if (!opt_policy_init(beg->s, opts->s))
     468               0 :     return (FALSE);
     469                 : 
     470              81 :   ASSERT(opts->s->beg == beg->s);
     471                 :   
     472                 :   /* do all, then check ... so we don't have to unwind */
     473             162 :   opts->document_root     = vstr_make_base(NULL);
     474             162 :   opts->server_name       = vstr_make_base(NULL);
     475             162 :   opts->dir_filename      = vstr_make_base(NULL);
     476             162 :   opts->mime_types_def_ct = vstr_make_base(NULL);
     477             162 :   opts->mime_types_main   = vstr_make_base(NULL);
     478             162 :   opts->mime_types_xtra   = vstr_make_base(NULL);
     479             162 :   opts->default_hostname  = vstr_make_base(NULL);
     480             162 :   opts->req_conf_dir      = vstr_make_base(NULL);
     481             162 :   opts->req_err_dir       = vstr_make_base(NULL);
     482             162 :   opts->auth_realm        = vstr_make_base(NULL);
     483             162 :   opts->auth_token        = vstr_make_base(NULL);
     484                 :   
     485             162 :   if (!opts->document_root     ||
     486                 :       !opts->server_name       ||
     487                 :       !opts->dir_filename      ||
     488                 :       !opts->mime_types_def_ct ||
     489                 :       !opts->mime_types_main   ||
     490                 :       !opts->mime_types_xtra   ||
     491                 :       !opts->default_hostname  ||
     492                 :       !opts->req_conf_dir      ||
     493                 :       !opts->req_err_dir       ||
     494                 :       !opts->auth_realm        ||
     495                 :       !opts->auth_token        ||
     496                 :       FALSE)
     497                 :   {
     498               0 :     httpd_policy_exit(opts);
     499               0 :     return (FALSE);
     500                 :   }
     501                 : 
     502             162 :   opts->mime_types->ref = NULL;
     503             162 :   opts->mime_types->def_type_vs1 = NULL;
     504             162 :   opts->mime_types->def_type_pos = 0;
     505             162 :   opts->mime_types->def_type_len = 0;
     506                 :   
     507             162 :   opts->use_mmap           = HTTPD_CONF_USE_MMAP;
     508             162 :   opts->use_sendfile       = HTTPD_CONF_USE_SENDFILE;
     509             162 :   opts->use_keep_alive     = HTTPD_CONF_USE_KEEPA;
     510             162 :   opts->use_keep_alive_1_0 = HTTPD_CONF_USE_KEEPA_1_0;
     511             162 :   opts->use_vhosts_name    = HTTPD_CONF_USE_VHOSTS_NAME;
     512             162 :   opts->use_range          = HTTPD_CONF_USE_RANGE;
     513             162 :   opts->use_range_1_0      = HTTPD_CONF_USE_RANGE_1_0;
     514             162 :   opts->use_adv_range      = HTTPD_CONF_USE_ADV_RANGE;
     515             162 :   opts->use_public_only    = HTTPD_CONF_USE_PUBLIC_ONLY;
     516             162 :   opts->use_enc_content_replacement = HTTPD_CONF_USE_ENC_CONTENT_REPLACEMENT;
     517                 : 
     518             162 :   opts->use_err_406        = HTTPD_CONF_USE_ERR_406;
     519             162 :   opts->use_canonize_host  = HTTPD_CONF_USE_CANONIZE_HOST;
     520             162 :   opts->use_host_err_400   = HTTPD_CONF_USE_HOST_ERR_400;
     521             162 :   opts->use_internal_host_chk = HTTPD_CONF_USE_INTERNAL_HOST_CHK;
     522             162 :   opts->use_host_chk       = HTTPD_CONF_USE_HOST_CHK;
     523             162 :   opts->use_hdrs_no_x2     = HTTPD_CONF_USE_HDRS_NO_x2;
     524             162 :   opts->use_hdrs_non_spc   = HTTPD_CONF_USE_HDRS_NON_SPC;
     525             162 :   opts->use_hdrs_err_411   = HTTPD_CONF_USE_HDRS_ERR_411;  
     526             162 :   opts->allow_trace_op     = HTTPD_CONF_ALLOW_TRACE_OP;
     527             162 :   opts->allow_http_0_9     = HTTPD_CONF_ALLOW_HTTP_0_9;
     528                 :   
     529             162 :   opts->remove_url_frag    = HTTPD_CONF_USE_REMOVE_FRAG;
     530             162 :   opts->remove_url_query   = HTTPD_CONF_USE_REMOVE_QUERY;
     531             162 :   opts->use_secure_dirs    = HTTPD_CONF_USE_SECURE_DIRS;
     532             162 :   opts->use_friendly_dirs  = HTTPD_CONF_USE_FRIENDLY_DIRS;
     533                 :   
     534             162 :   opts->use_posix_fadvise  = HTTPD_CONF_USE_POSIX_FADVISE;
     535             162 :   opts->use_tcp_cork       = HTTPD_CONF_USE_TCP_CORK;
     536                 :   
     537             162 :   opts->use_req_conf       = HTTPD_CONF_USE_REQ_CONF;
     538             162 :   opts->allow_hdr_split    = HTTPD_CONF_USE_ALLOW_HDR_SPLIT;
     539             162 :   opts->allow_hdr_nil      = HTTPD_CONF_USE_ALLOW_HDR_NIL;
     540                 :   
     541             162 :   opts->chk_dot_dir        = HTTPD_CONF_USE_CHK_DOT_DIR;
     542                 :   
     543             162 :   opts->chk_encoded_slash  = HTTPD_CONF_USE_CHK_ENCODED_SLASH;
     544             162 :   opts->chk_encoded_dot    = HTTPD_CONF_USE_CHK_ENCODED_DOT;
     545                 :   
     546             162 :   opts->add_def_port       = HTTPD_CONF_ADD_DEF_PORT;
     547                 : 
     548             162 :   opts->use_noatime        = HTTPD_CONF_USE_NOATIME;
     549                 :   
     550             162 :   opts->use_text_redirect  = HTTPD_CONF_USE_TEXT_REDIRECT;
     551                 :   
     552             162 :   opts->use_mime_xattr     = HTTPD_CONF_USE_MIME_XATTR;
     553                 :   
     554             162 :   opts->output_keep_alive_hdr = HTTPD_CONF_OUTPUT_KEEPA_HDR;
     555                 :   
     556             162 :   opts->etag_auto_type     = HTTPD_CONF_ETAG_TYPE_AUTO;
     557                 :   
     558             162 :   opts->max_header_sz      = HTTPD_CONF_INPUT_MAXSZ;
     559                 : 
     560             162 :   opts->max_requests       = HTTPD_CONF_MAX_REQUESTS;
     561                 : 
     562             162 :   opts->max_neg_A_nodes    = HTTPD_CONF_MAX_NEG_A_NODES;
     563             162 :   opts->max_neg_AL_nodes   = HTTPD_CONF_MAX_NEG_AL_NODES;
     564                 :   
     565             162 :   opts->max_A_nodes        = HTTPD_CONF_MAX_A_NODES;
     566             162 :   opts->max_AC_nodes       = HTTPD_CONF_MAX_AC_NODES;
     567             162 :   opts->max_AE_nodes       = HTTPD_CONF_MAX_AE_NODES;
     568             162 :   opts->max_AL_nodes       = HTTPD_CONF_MAX_AL_NODES;
     569                 :   
     570             162 :   opts->max_connection_nodes = HTTPD_CONF_MAX_CONNECTION_NODES;
     571             162 :   opts->max_etag_nodes     = HTTPD_CONF_MAX_ETAG_NODES;
     572                 : 
     573             162 :   opts->max_range_nodes    = HTTPD_CONF_MAX_RANGE_NODES;
     574                 :   
     575             162 :   opts->max_req_conf_sz    = HTTPD_CONF_REQ_CONF_MAXSZ;
     576                 :   
     577             162 :   return (TRUE);
     578                 : }
     579                 : 
     580                 : static void httpd_policy_free(Vstr_ref *ref)
     581             144 : {
     582             144 :   Httpd_policy_opts *opts = NULL;
     583                 :   
     584             144 :   if (!ref)
     585               0 :     return;
     586                 : 
     587             144 :   if ((opts = ref->ptr))
     588             144 :     httpd_policy_exit(opts);
     589             144 :   F(opts);
     590             144 :   free(ref);
     591                 : }
     592                 : 
     593                 : Opt_serv_policy_opts *httpd_policy_make(Opt_serv_opts *beg)
     594             162 : {
     595             162 :   Opt_serv_policy_opts *opts = MK(sizeof(Httpd_policy_opts));
     596             162 :   Vstr_ref *ref = NULL;
     597                 :   
     598             162 :   if (!opts)
     599               0 :     goto mk_opts_fail;
     600                 : 
     601             162 :   if (!(ref = vstr_ref_make_ptr(opts, httpd_policy_free)))
     602               0 :     goto mk_ref_fail;
     603             162 :   opts->ref = ref;
     604                 : 
     605             162 :   if (!httpd_policy_init((Httpd_opts *)beg, (Httpd_policy_opts *)opts))
     606               0 :     goto policy_init_fail;
     607                 :   
     608             162 :   return (opts);
     609                 : 
     610               0 :  policy_init_fail:
     611               0 :   ref->ptr = NULL;
     612               0 :   vstr_ref_del(ref);
     613               0 :  mk_ref_fail:
     614               0 :   F(opts);
     615               0 :  mk_opts_fail:
     616               0 :   return (NULL);
     617                 : }
     618                 : 
     619                 : #define HTTPD_POLICY_CP_VSTR(x)                               \
     620                 :     vstr_sub_vstr(dst-> x , 1, dst-> x ->len, src-> x , 1, src-> x ->len, \
     621                 :                   VSTR_TYPE_SUB_BUF_REF)
     622                 : #define HTTPD_POLICY_CP_VAL(x)        \
     623                 :     dst-> x = src-> x
     624                 : 
     625                 : int httpd_policy_copy(Opt_serv_policy_opts *sdst,
     626                 :                       const Opt_serv_policy_opts *ssrc)
     627             142 : {
     628             142 :   Httpd_policy_opts *dst = (Httpd_policy_opts *)sdst;
     629             142 :   Httpd_policy_opts *src = (Httpd_policy_opts *)ssrc;
     630                 : 
     631             142 :   if (!opt_policy_copy(sdst, ssrc))
     632               0 :     return (FALSE);
     633                 :   
     634             142 :   HTTPD_POLICY_CP_VSTR(document_root);
     635             142 :   HTTPD_POLICY_CP_VSTR(server_name);
     636             142 :   HTTPD_POLICY_CP_VSTR(dir_filename);
     637                 : 
     638             142 :   HTTPD_POLICY_CP_VSTR(mime_types_def_ct);
     639             142 :   HTTPD_POLICY_CP_VSTR(mime_types_main);
     640             142 :   HTTPD_POLICY_CP_VSTR(mime_types_xtra);
     641             142 :   HTTPD_POLICY_CP_VSTR(default_hostname);
     642             142 :   HTTPD_POLICY_CP_VSTR(req_conf_dir);
     643             142 :   HTTPD_POLICY_CP_VSTR(req_err_dir);
     644                 : 
     645             142 :   HTTPD_POLICY_CP_VAL(use_mmap);
     646             142 :   HTTPD_POLICY_CP_VAL(use_sendfile);
     647             142 :   HTTPD_POLICY_CP_VAL(use_keep_alive);
     648             142 :   HTTPD_POLICY_CP_VAL(use_keep_alive_1_0);
     649             142 :   HTTPD_POLICY_CP_VAL(use_vhosts_name);
     650             142 :   HTTPD_POLICY_CP_VAL(use_range);
     651             142 :   HTTPD_POLICY_CP_VAL(use_range_1_0);
     652             142 :   HTTPD_POLICY_CP_VAL(use_adv_range);
     653             142 :   HTTPD_POLICY_CP_VAL(use_public_only);
     654             142 :   HTTPD_POLICY_CP_VAL(use_enc_content_replacement);
     655             142 :   HTTPD_POLICY_CP_VAL(use_err_406);
     656             142 :   HTTPD_POLICY_CP_VAL(use_canonize_host);
     657             142 :   HTTPD_POLICY_CP_VAL(use_host_err_400);
     658             142 :   HTTPD_POLICY_CP_VAL(use_internal_host_chk);
     659             142 :   HTTPD_POLICY_CP_VAL(use_host_chk);
     660             142 :   HTTPD_POLICY_CP_VAL(use_hdrs_no_x2);
     661             142 :   HTTPD_POLICY_CP_VAL(use_hdrs_non_spc);
     662             142 :   HTTPD_POLICY_CP_VAL(use_hdrs_err_411);
     663             142 :   HTTPD_POLICY_CP_VAL(allow_trace_op);
     664             142 :   HTTPD_POLICY_CP_VAL(allow_http_0_9);
     665             142 :   HTTPD_POLICY_CP_VAL(remove_url_frag);
     666             142 :   HTTPD_POLICY_CP_VAL(remove_url_query);
     667             142 :   HTTPD_POLICY_CP_VAL(use_secure_dirs);
     668             142 :   HTTPD_POLICY_CP_VAL(use_friendly_dirs);
     669             142 :   HTTPD_POLICY_CP_VAL(use_posix_fadvise);
     670             142 :   HTTPD_POLICY_CP_VAL(use_tcp_cork);
     671             142 :   HTTPD_POLICY_CP_VAL(use_req_conf);
     672             142 :   HTTPD_POLICY_CP_VAL(allow_hdr_split);
     673             142 :   HTTPD_POLICY_CP_VAL(allow_hdr_nil);
     674             142 :   HTTPD_POLICY_CP_VAL(chk_dot_dir);
     675             142 :   HTTPD_POLICY_CP_VAL(chk_encoded_slash);
     676             142 :   HTTPD_POLICY_CP_VAL(chk_encoded_dot);
     677             142 :   HTTPD_POLICY_CP_VAL(add_def_port);
     678             142 :   HTTPD_POLICY_CP_VAL(use_noatime);
     679             142 :   HTTPD_POLICY_CP_VAL(use_text_redirect);
     680             142 :   HTTPD_POLICY_CP_VAL(use_mime_xattr);
     681             142 :   HTTPD_POLICY_CP_VAL(output_keep_alive_hdr);
     682             142 :   HTTPD_POLICY_CP_VAL(etag_auto_type);
     683                 : 
     684             142 :   HTTPD_POLICY_CP_VAL(max_header_sz);
     685             142 :   HTTPD_POLICY_CP_VAL(max_requests);
     686                 : 
     687             142 :   HTTPD_POLICY_CP_VAL(max_neg_A_nodes);
     688             142 :   HTTPD_POLICY_CP_VAL(max_neg_AL_nodes);
     689                 :   
     690             142 :   HTTPD_POLICY_CP_VAL(max_A_nodes);
     691             142 :   HTTPD_POLICY_CP_VAL(max_AC_nodes);
     692             142 :   HTTPD_POLICY_CP_VAL(max_AE_nodes);
     693             142 :   HTTPD_POLICY_CP_VAL(max_AL_nodes);
     694                 :   
     695             142 :   HTTPD_POLICY_CP_VAL(max_connection_nodes);
     696             142 :   HTTPD_POLICY_CP_VAL(max_etag_nodes);
     697                 : 
     698             142 :   HTTPD_POLICY_CP_VAL(max_range_nodes);
     699                 : 
     700             142 :   HTTPD_POLICY_CP_VAL(max_req_conf_sz);
     701                 : 
     702             142 :   return (!dst->document_root->conf->malloc_bad);
     703                 : }

Generated by: LTP GCOV extension version 1.4