passwd_common.c revision d6fc66efa723db8b3ee5e9fd32579bed884e4e58
/* 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 "passwd_common.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"
#include <time.h>
#if APR_HAVE_CRYPT_H
#include <crypt.h>
#endif
#include <stdlib.h>
#endif
#include <string.h>
#endif
#include <unistd.h>
#endif
#ifdef WIN32
#include <conio.h>
#endif
{
unsigned char rnd[32];
static const char itoa64[] =
"./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
apr_size_t n;
if (n > sizeof(rnd)) {
abort();
}
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;
}
void putline(apr_file_t *f, const char *l)
{
rv = apr_file_puts(l, f);
if (rv != APR_SUCCESS) {
apr_file_close(f);
}
}
{
goto err_too_long;
return ERR_PWMISMATCH;
}
return 0;
return ERR_OVERFLOW;
}
/*
* Make a password record from the given information. A zero return
* indicates success; on failure, ctx->errstr points to the error message.
*/
{
char *pw;
char pwin[MAX_STRING_LEN];
char salt[16];
int ret = 0;
char *cbuf;
#endif
}
else {
return ret;
}
case ALG_APSHA:
/* XXX out >= 28 + strlen(sha1) chars - fixed len SHA */
break;
case ALG_APMD5:
if (ret != 0)
break;
if (rv != APR_SUCCESS) {
"could not encode password: %pm", &rv);
ret = ERR_GENERAL;
}
break;
case ALG_PLAIN:
/* XXX this len limitation is not in sync with any HTTPd len. */
break;
case ALG_CRYPT:
if (ret != 0)
break;
break;
}
"characters by CRYPT algorithm." NL);
}
}
break;
#endif /* CRYPT_ALGO_SUPPORTED */
default:
abort();
}
return ret;
}
const char *opt_arg)
{
switch (opt) {
case 'b':
break;
case 'm':
break;
case 's':
break;
case 'p':
#if !PLAIN_ALGO_SUPPORTED
/* Backward compatible behavior: Just print a warning */
"Warning: storing passwords as plain text might just "
"not work on this platform." NL);
#endif
break;
case 'd':
#else
/* Backward compatible behavior: Use MD5. OK since MD5 is more secure */
"Warning: CRYPT algorithm not supported on this "
"platform." NL
"Automatically using MD5 format." NL);
#endif
break;
default:
abort();
}
return 0;
}