| 84 | } |
| 85 | |
| 86 | static const char *ip_parse_config(cmd_parms *cmd, |
| 87 | const char *require_line, |
| 88 | const void **parsed_require_line) |
| 89 | { |
| 90 | const char *t, *w; |
| 91 | int count = 0; |
| 92 | apr_ipsubnet_t **ip; |
| 93 | apr_pool_t *ptemp = cmd->temp_pool; |
| 94 | apr_pool_t *p = cmd->pool; |
| 95 | |
| 96 | /* The 'ip' provider will allow the configuration to specify a list of |
| 97 | ip addresses to check rather than a single address. This is different |
| 98 | from the previous host based syntax. */ |
| 99 | |
| 100 | t = require_line; |
| 101 | while ((w = ap_getword_conf(ptemp, &t)) && w[0]) |
| 102 | count++; |
| 103 | |
| 104 | if (count == 0) |
| 105 | return "'require ip' requires an argument"; |
| 106 | |
| 107 | ip = apr_pcalloc(p, sizeof(apr_ipsubnet_t *) * (count + 1)); |
| 108 | *parsed_require_line = ip; |
| 109 | |
| 110 | t = require_line; |
| 111 | while ((w = ap_getword_conf(ptemp, &t)) && w[0]) { |
| 112 | char *addr = apr_pstrdup(ptemp, w); |
| 113 | char *mask; |
| 114 | apr_status_t rv; |
| 115 | |
| 116 | if (parsed_subnets && |
| 117 | (*ip = apr_hash_get(parsed_subnets, w, APR_HASH_KEY_STRING)) != NULL) |
| 118 | { |
| 119 | /* we already have parsed this subnet */ |
| 120 | ip++; |
| 121 | continue; |
| 122 | } |
| 123 | |
| 124 | if ((mask = ap_strchr(addr, '/'))) |
| 125 | *mask++ = '\0'; |
| 126 | |
| 127 | rv = apr_ipsubnet_create(ip, addr, mask, p); |
| 128 | |
| 129 | if(APR_STATUS_IS_EINVAL(rv)) { |
| 130 | /* looked nothing like an IP address */ |
| 131 | return apr_psprintf(p, "ip address '%s' appears to be invalid", w); |
| 132 | } |
| 133 | else if (rv != APR_SUCCESS) { |
| 134 | return apr_psprintf(p, "ip address '%s' appears to be invalid: %pm", |
| 135 | w, &rv); |
| 136 | } |
| 137 | |
| 138 | if (parsed_subnets) |
| 139 | apr_hash_set(parsed_subnets, w, APR_HASH_KEY_STRING, *ip); |
| 140 | ip++; |
| 141 | } |
| 142 | |
| 143 | return NULL; |
nothing calls this directly
no test coverage detected