Ignore:
Timestamp:
Aug 25, 2008, 7:32:06 PM (13 years ago)
Author:
charles
Message:

upgrade to shttpd 1.42

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/third-party/shttpd/auth.c

    r6349 r6644  
    159159                return (0);
    160160
    161         md5(a2, &known_http_methods[method], &digest->uri, NULL);
     161        md5(a2, &_shttpd_known_http_methods[method], &digest->uri, NULL);
    162162        vec_a2.ptr = a2;
    163163        vec_a2.len = sizeof(a2);
    164164        md5(resp, ha1, &digest->nonce, &digest->nc,
    165165            &digest->cnonce, &digest->qop, &vec_a2, NULL);
     166        DBG(("%s: uri [%.*s] expected_resp [%.*s] resp [%.*s]",
     167            "check_password", digest->uri.len, digest->uri.ptr,
     168            32, resp, digest->resp.len, digest->resp.ptr));
    166169
    167170        return (!memcmp(resp, digest->resp.ptr, 32));
     
    178181        if (ctx->options[OPT_AUTH_GPASSWD] != NULL) {
    179182                /* Use global passwords file */
    180                 my_snprintf(name, sizeof(name), "%s",
     183                _shttpd_snprintf(name, sizeof(name), "%s",
    181184                    ctx->options[OPT_AUTH_GPASSWD]);
    182185        } else {
    183                 /* Try to find .htpasswd in requested directory */
     186                /*
     187                 * Try to find .htpasswd in requested directory.
     188                 * Given the path, create the path to .htpasswd file
     189                 * in the same directory. Find the right-most
     190                 * directory separator character first. That would be the
     191                 * directory name. If directory separator character is not
     192                 * found, 'e' will point to 'p'.
     193                 */
    184194                for (p = path, e = p + strlen(p) - 1; e > p; e--)
    185195                        if (IS_DIRSEP_CHAR(*e))
    186196                                break;
    187197
    188                 assert(IS_DIRSEP_CHAR(*e));
    189                 (void) my_snprintf(name, sizeof(name), "%.*s/%s",
     198                /*
     199                 * Make up the path by concatenating directory name and
     200                 * .htpasswd file name.
     201                 */
     202                (void) _shttpd_snprintf(name, sizeof(name), "%.*s/%s",
    190203                    (int) (e - p), p, HTPASSWD);
    191204        }
    192205
    193         if ((fd = my_open(name, O_RDONLY, 0)) == -1) {
     206        if ((fd = _shttpd_open(name, O_RDONLY, 0)) == -1) {
    194207                DBG(("open_auth_file: open(%s)", name));
    195208        } else if ((fp = fdopen(fd, "r")) == NULL) {
     
    242255
    243256        if (auth_vec->len > 20 &&
    244             !my_strncasecmp(auth_vec->ptr, "Digest ", 7)) {
     257            !_shttpd_strncasecmp(auth_vec->ptr, "Digest ", 7)) {
    245258
    246259                parse_authorization_header(auth_vec, &digest);
     
    268281
    269282int
    270 check_authorization(struct conn *c, const char *path)
     283_shttpd_check_authorization(struct conn *c, const char *path)
    271284{
    272285        FILE            *fp = NULL;
     
    286299                                n = sizeof(protected_path) - 1;
    287300
    288                         my_strlcpy(protected_path, p + 1, n);
     301                        _shttpd_strlcpy(protected_path, p + 1, n);
    289302
    290303                        if ((fp = fopen(protected_path, "r")) == NULL)
    291                                 elog(E_LOG, c, "check_auth: cannot open %s: %s",
     304                                _shttpd_elog(E_LOG, c,
     305                                    "check_auth: cannot open %s: %s",
    292306                                    protected_path, strerror(errno));
    293307                        break;
     
    307321
    308322int
    309 is_authorized_for_put(struct conn *c)
     323_shttpd_is_authorized_for_put(struct conn *c)
    310324{
    311325        FILE    *fp;
     
    321335
    322336void
    323 send_authorization_request(struct conn *c)
     337_shttpd_send_authorization_request(struct conn *c)
    324338{
    325339        char    buf[512];
    326340
    327         (void) my_snprintf(buf, sizeof(buf), "Unauthorized\r\n"
     341        (void) _shttpd_snprintf(buf, sizeof(buf), "Unauthorized\r\n"
    328342            "WWW-Authenticate: Digest qop=\"auth\", realm=\"%s\", "
    329343            "nonce=\"%lu\"", c->ctx->options[OPT_AUTH_REALM],
    330             (unsigned long) current_time);
    331 
    332         send_server_error(c, 401, buf);
     344            (unsigned long) _shttpd_current_time);
     345
     346        _shttpd_send_server_error(c, 401, buf);
    333347}
    334348
     
    337351 */
    338352int
    339 edit_passwords(const char *fname, const char *domain,
     353_shttpd_edit_passwords(const char *fname, const char *domain,
    340354                const char *user, const char *pass)
    341355{
     
    345359        FILE            *fp = NULL, *fp2 = NULL;
    346360
    347         (void) my_snprintf(tmp, sizeof(tmp), "%s.tmp", fname);
     361        (void) _shttpd_snprintf(tmp, sizeof(tmp), "%s.tmp", fname);
    348362
    349363        /* Create the file if does not exist */
     
    353367        /* Open the given file and temporary file */
    354368        if ((fp = fopen(fname, "r")) == NULL)
    355                 elog(E_FATAL, 0, "Cannot open %s: %s", fname, strerror(errno));
     369                _shttpd_elog(E_FATAL, NULL,
     370                    "Cannot open %s: %s", fname, strerror(errno));
    356371        else if ((fp2 = fopen(tmp, "w+")) == NULL)
    357                 elog(E_FATAL, 0, "Cannot open %s: %s", tmp, strerror(errno));
     372                _shttpd_elog(E_FATAL, NULL,
     373                    "Cannot open %s: %s", tmp, strerror(errno));
    358374
    359375        p.ptr = pass;
     
    396412
    397413        /* Put the temp file in place of real file */
    398         (void) my_remove(fname);
    399         (void) my_rename(tmp, fname);
     414        (void) _shttpd_remove(fname);
     415        (void) _shttpd_rename(tmp, fname);
    400416
    401417        return (ret);
Note: See TracChangeset for help on using the changeset viewer.