1/* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements. See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
--- 52 unchanged lines hidden (view full) ---
61
62#else
63
64#error apr_password_validate() is not threadsafe. rebuild APR without thread support.
65
66#endif
67#endif
68
69/*
70 * Validate a plaintext password against a smashed one. Uses either
71 * crypt() (if available) or apr_md5_encode() or apr_sha1_base64(), depending
72 * upon the format of the smashed input password. Returns APR_SUCCESS if
73 * they match, or APR_EMISMATCH if they don't. If the platform doesn't
74 * support crypt, then the default check is against a clear text string.
75 */
76APU_DECLARE(apr_status_t) apr_password_validate(const char *passwd,
77 const char *hash)
78{
79 char sample[200];
80#if !defined(WIN32) && !defined(BEOS) && !defined(NETWARE)
81 char *crypt_pw;
82#endif
83 if (hash[0] == '$'
84 && hash[1] == '2'
85 && (hash[2] == 'a' || hash[2] == 'y')
86 && hash[3] == '$') {
87 if (_crypt_blowfish_rn(passwd, hash, sample, sizeof(sample)) == NULL)
88 return APR_FROM_OS_ERROR(errno);
--- 6 unchanged lines hidden (view full) ---
95 }
96 else if (!strncmp(hash, APR_SHA1PW_ID, APR_SHA1PW_IDLEN)) {
97 apr_sha1_base64(passwd, (int)strlen(passwd), sample);
98 }
99 else {
100 /*
101 * It's not our algorithm, so feed it to crypt() if possible.
102 */
103#if defined(WIN32) || defined(BEOS) || defined(NETWARE)
104 return (strcmp(passwd, hash) == 0) ? APR_SUCCESS : APR_EMISMATCH;
105#elif defined(CRYPT_R_CRYPTD)
106 apr_status_t rv;
107 CRYPTD *buffer = malloc(sizeof(*buffer));
108
109 if (buffer == NULL)
110 return APR_ENOMEM;
111 crypt_pw = crypt_r(passwd, hash, buffer);
--- 83 unchanged lines hidden ---
2 * contributor license agreements. See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
--- 52 unchanged lines hidden (view full) ---
61
62#else
63
64#error apr_password_validate() is not threadsafe. rebuild APR without thread support.
65
66#endif
67#endif
68
69/*
70 * Validate a plaintext password against a smashed one. Uses either
71 * crypt() (if available) or apr_md5_encode() or apr_sha1_base64(), depending
72 * upon the format of the smashed input password. Returns APR_SUCCESS if
73 * they match, or APR_EMISMATCH if they don't. If the platform doesn't
74 * support crypt, then the default check is against a clear text string.
75 */
76APU_DECLARE(apr_status_t) apr_password_validate(const char *passwd,
77 const char *hash)
78{
79 char sample[200];
80#if !defined(WIN32) && !defined(BEOS) && !defined(NETWARE)
81 char *crypt_pw;
82#endif
83 if (hash[0] == '$'
84 && hash[1] == '2'
85 && (hash[2] == 'a' || hash[2] == 'y')
86 && hash[3] == '$') {
87 if (_crypt_blowfish_rn(passwd, hash, sample, sizeof(sample)) == NULL)
88 return APR_FROM_OS_ERROR(errno);
--- 6 unchanged lines hidden (view full) ---
95 }
96 else if (!strncmp(hash, APR_SHA1PW_ID, APR_SHA1PW_IDLEN)) {
97 apr_sha1_base64(passwd, (int)strlen(passwd), sample);
98 }
99 else {
100 /*
101 * It's not our algorithm, so feed it to crypt() if possible.
102 */
103#if defined(WIN32) || defined(BEOS) || defined(NETWARE)
104 return (strcmp(passwd, hash) == 0) ? APR_SUCCESS : APR_EMISMATCH;
105#elif defined(CRYPT_R_CRYPTD)
106 apr_status_t rv;
107 CRYPTD *buffer = malloc(sizeof(*buffer));
108
109 if (buffer == NULL)
110 return APR_ENOMEM;
111 crypt_pw = crypt_r(passwd, hash, buffer);
--- 83 unchanged lines hidden ---