/* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "lua_passwd.h"
#include "apr_strings.h"
#include "apr_errno.h"
#if APR_HAVE_STDIO_H
#include <stdio.h>
#endif
#include "apr_md5.h"
#include "apr_sha1.h"
#if APR_HAVE_TIME_H
#include <time.h>
#endif
#if APR_HAVE_CRYPT_H
#include <crypt.h>
#endif
#include <stdlib.h>
#endif
#include <string.h>
#endif
#include <unistd.h>
#endif
#if APR_HAVE_IO_H
#include <io.h>
#endif
{
static const char itoa64[] =
"./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
apr_size_t n;
if (n > sizeof(rnd)) {
return ERR_RANDOM;
}
if (rv) {
&rv);
return ERR_RANDOM;
}
n = 0;
while (size > 0) {
if (bits < 6) {
bits += 8;
}
size--;
val >>= 6;
bits -= 6;
}
*s = '\0';
return 0;
}
/*
* Make a password record from the given information. A zero return
* indicates success; on failure, ctx->errstr points to the error message.
*/
{
char *pw;
int ret = 0;
char *cbuf;
#endif
case ALG_APSHA:
/* XXX out >= 28 + strlen(sha1) chars - fixed len SHA */
break;
case ALG_APMD5:
if (ret != 0) {
ret = ERR_GENERAL;
break;
}
if (rv != APR_SUCCESS) {
"could not encode password: %pm", &rv);
ret = ERR_GENERAL;
}
break;
case ALG_CRYPT:
if (ret != 0)
break;
break;
}
"Warning: Password truncated to 8 "
"characters by CRYPT algorithm.");
}
}
break;
#endif /* CRYPT_ALGO_SUPPORTED */
case ALG_BCRYPT:
if (rv != APR_SUCCESS) {
"bytes: %pm", &rv);
ret = ERR_RANDOM;
break;
}
if (rv != APR_SUCCESS) {
"bcrypt: %pm", &rv);
break;
}
break;
#endif /* BCRYPT_ALGO_SUPPORTED */
default:
"mk_password_hash(): unsupported algorithm %d",
ret = ERR_GENERAL;
}
return ret;
}