htdbm.c revision 563fa6715f6ad5703d30354644d61968a8460804
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000-2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
*
* Portions of this software are based upon public domain software
* originally written at the National Center for Supercomputing Applications,
* University of Illinois, Urbana-Champaign.
*/
/*
* htdbm.c: simple program for manipulating DBM
* password databases for the Apache HTTP server
*
* Contributed by Mladen Turk <mturk@mappingsoft.com>
* 12 Oct 2001
*/
#include "apr.h"
#include "apr_lib.h"
#include "apr_strings.h"
#include "apr_file_io.h"
#include "apr_file_info.h"
#include "apr_pools.h"
#include "apr_signal.h"
#include "apr_md5.h"
#include "apr_sha1.h"
#include "apr_dbm.h"
#include <stdlib.h>
#endif
#include <string.h>
#endif
#include <strings.h>
#endif
#include <time.h>
#include "apr_xlate.h"
#endif /*APR_CHARSET_EBCDIC*/
#if APR_HAVE_CRYPT_H
#include <crypt.h>
#endif
#if !APR_CHARSET_EBCDIC
#define LF 10
#define CR 13
#else /*APR_CHARSET_EBCDIC*/
#define LF '\n'
#define CR '\r'
#endif /*APR_CHARSET_EBCDIC*/
#define MAX_STRING_LEN 256
#define ALG_PLAIN 0
#define ALG_APMD5 1
#define ALG_APSHA 2
#if APR_HAVE_CRYPT_H
#define ALG_CRYPT 3
#endif
#define ERR_FILEPERM 1
#define ERR_SYNTAX 2
#define ERR_PWMISMATCH 3
#define ERR_INTERRUPTED 4
#define ERR_OVERFLOW 5
#define ERR_BADUSER 6
#define ERR_EMPTY 7
struct htdbm_t {
#endif
char *filename;
char *username;
char *userpass;
char *comment;
char *type;
int create;
int rdonly;
int alg;
};
#define HTDBM_MAKE 0
#define HTDBM_DELETE 1
#define HTDBM_VERIFY 2
#define HTDBM_LIST 3
#define HTDBM_NOFILE 4
#define HTDBM_STDIN 5
{
}
static htdbm_t *h;
static void htdbm_interrupted(void)
{
htdbm_terminate(h);
}
{
#endif
if (rv) {
return APR_EGENERAL;
}
if (rv) {
return APR_EGENERAL;
}
if (rv) {
return APR_EGENERAL;
}
#endif /*APR_CHARSET_EBCDIC*/
/* Set MD5 as default */
return APR_SUCCESS;
}
{
else
}
{
return APR_SUCCESS;
*changed = 1;
else {
}
}
{
return APR_ENOENT;
}
{
char pwd[MAX_STRING_LEN] = {0};
return APR_ENOENT;
return APR_ENOENT;
if (cmnt)
else
}
{
char kb[MAX_STRING_LEN];
int i = 0;
if (rv != APR_SUCCESS) {
return APR_ENOENT;
}
if (rv != APR_SUCCESS) {
return APR_EGENERAL;
}
if (cmnt)
if (rv != APR_SUCCESS)
++i;
}
return APR_SUCCESS;
}
static void to64(char *s, unsigned long v, int n)
{
static unsigned char itoa64[] = /* 0 ... 63 => ASCII - 64 */
"./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
while (--n >= 0) {
*s++ = itoa64[v&0x3f];
v >>= 6;
}
}
{
char cpw[MAX_STRING_LEN];
char salt[9];
case ALG_APSHA:
/* XXX cpw >= 28 + strlen(sha1) chars - fixed len SHA */
break;
case ALG_APMD5:
break;
case ALG_PLAIN:
/* XXX this len limitation is not in sync with any HTTPd len. */
break;
#if APR_HAVE_CRYPT_H
case ALG_CRYPT:
#endif
default:
break;
}
return APR_SUCCESS;
}
{
return APR_EINVAL;
}
return APR_EINVAL;
}
return APR_SUCCESS;
}
static void htdbm_usage(void)
{
#if APR_HAVE_CRYPT_H
#define CRYPT_OPTION "d"
#else
#define CRYPT_OPTION ""
#endif
"than prompting for it.\n");
#if APR_HAVE_CRYPT_H
#endif
}
{
apr_size_t l;
char pwi[MAX_STRING_LEN];
char pwc[MAX_STRING_LEN];
char errbuf[MAX_STRING_LEN];
const char *arg;
int need_file = 1;
int need_user = 1;
int need_pwd = 1;
int need_cmnt = 0;
int pwd_supplied = 0;
int changed;
int cmd = HTDBM_MAKE;
int i;
int args_left = 2;
exit(1);
}
/*
* Preliminary check to make sure they provided at least
* three arguments, we'll do better argument checking as
* we parse the command line.
*/
if (argc < 3)
htdbm_usage();
/*
* Go through the argument list and pick out any options. They
* have to precede any other arguments.
*/
for (i = 1; i < argc; i++) {
if (*arg != '-')
break;
while (*++arg != '\0') {
switch (*arg) {
case 'b':
pwd_supplied = 1;
need_pwd = 0;
args_left++;
break;
case 'c':
h->create = 1;
break;
case 'n':
need_file = 0;
cmd = HTDBM_NOFILE;
args_left--;
break;
case 'l':
need_pwd = 0;
need_user = 0;
cmd = HTDBM_LIST;
h->rdonly = 1;
args_left--;
break;
case 't':
need_cmnt = 1;
args_left++;
break;
case 'T':
while (*arg != '\0')
++arg;
--arg; /* so incrementing this in the loop with find a null */
break;
case 'v':
h->rdonly = 1;
cmd = HTDBM_VERIFY;
break;
case 'x':
need_pwd = 0;
cmd = HTDBM_DELETE;
break;
case 'm':
break;
case 'p':
break;
case 's':
break;
#if APR_HAVE_CRYPT_H
case 'd':
break;
#endif
default:
htdbm_usage();
break;
}
}
}
/*
* Make sure we still have exactly the right number of arguments left
* (the filename, the username, and possibly the password if -b was
* specified).
*/
htdbm_usage();
if (!need_file)
i--;
else {
}
}
if (need_user) {
if (htdbm_valid_username(h) != APR_SUCCESS)
}
if (pwd_supplied)
if (need_pwd) {
l = sizeof(pwc);
}
l = sizeof(pwc);
}
}
}
if (need_cmnt && pwd_supplied)
else if (need_cmnt)
switch (cmd) {
case HTDBM_VERIFY:
if(rv == APR_ENOENT) {
}
else {
}
}
else
break;
case HTDBM_DELETE:
if (htdbm_del(h) != APR_SUCCESS) {
}
changed = 1;
break;
case HTDBM_LIST:
htdbm_list(h);
break;
default:
htdbm_make(h);
break;
}
}
}
if (cmd == HTDBM_NOFILE)
htdbm_terminate(h);
return 0; /* Suppress compiler warning. */
}