htdbm.c revision 8cd53d45c40b817e3467b29262ee0a2892fe98dd
6ae232055d4d8a97267517c5e50074c2c819941and/* ====================================================================
6ae232055d4d8a97267517c5e50074c2c819941and * The Apache Software License, Version 1.1
6ae232055d4d8a97267517c5e50074c2c819941and * Copyright (c) 2000-2001 The Apache Software Foundation. All rights
6ae232055d4d8a97267517c5e50074c2c819941and * reserved.
6ae232055d4d8a97267517c5e50074c2c819941and * Redistribution and use in source and binary forms, with or without
6ae232055d4d8a97267517c5e50074c2c819941and * modification, are permitted provided that the following conditions
6ae232055d4d8a97267517c5e50074c2c819941and * are met:
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * 1. Redistributions of source code must retain the above copyright
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * notice, this list of conditions and the following disclaimer.
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * 2. Redistributions in binary form must reproduce the above copyright
6ae232055d4d8a97267517c5e50074c2c819941and * notice, this list of conditions and the following disclaimer in
6ae232055d4d8a97267517c5e50074c2c819941and * the documentation and/or other materials provided with the
6ae232055d4d8a97267517c5e50074c2c819941and * distribution.
3f08db06526d6901aa08c110b5bc7dde6bc39905nd * 3. The end-user documentation included with the redistribution,
6ae232055d4d8a97267517c5e50074c2c819941and * if any, must include the following acknowledgment:
6ae232055d4d8a97267517c5e50074c2c819941and * "This product includes software developed by the
6ae232055d4d8a97267517c5e50074c2c819941and * Apache Software Foundation (http://www.apache.org/)."
b43f840409794ed298e8634f6284741f193b6c4ftakashi * Alternately, this acknowledgment may appear in the software itself,
6ae232055d4d8a97267517c5e50074c2c819941and * if and wherever such third-party acknowledgments normally appear.
6ae232055d4d8a97267517c5e50074c2c819941and * 4. The names "Apache" and "Apache Software Foundation" must
b43f840409794ed298e8634f6284741f193b6c4ftakashi * not be used to endorse or promote products derived from this
bc9d4698fce0238d2f6f2682e99423ebb1149976rbowen * software without prior written permission. For written
6ae232055d4d8a97267517c5e50074c2c819941and * permission, please contact apache@apache.org.
6ae232055d4d8a97267517c5e50074c2c819941and * 5. Products derived from this software may not be called "Apache",
b43f840409794ed298e8634f6284741f193b6c4ftakashi * nor may "Apache" appear in their name, without prior written
b43f840409794ed298e8634f6284741f193b6c4ftakashi * permission of the Apache Software Foundation.
b43f840409794ed298e8634f6284741f193b6c4ftakashi * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
6ae232055d4d8a97267517c5e50074c2c819941and * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
6ae232055d4d8a97267517c5e50074c2c819941and * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
6ae232055d4d8a97267517c5e50074c2c819941and * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
6ae232055d4d8a97267517c5e50074c2c819941and * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
6ae232055d4d8a97267517c5e50074c2c819941and * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
6ae232055d4d8a97267517c5e50074c2c819941and * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
6ae232055d4d8a97267517c5e50074c2c819941and * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
6ae232055d4d8a97267517c5e50074c2c819941and * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
6ae232055d4d8a97267517c5e50074c2c819941and * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
6ae232055d4d8a97267517c5e50074c2c819941and * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
6ae232055d4d8a97267517c5e50074c2c819941and * SUCH DAMAGE.
6ae232055d4d8a97267517c5e50074c2c819941and * ====================================================================
6ae232055d4d8a97267517c5e50074c2c819941and * This software consists of voluntary contributions made by many
6ae232055d4d8a97267517c5e50074c2c819941and * individuals on behalf of the Apache Software Foundation. For more
6ae232055d4d8a97267517c5e50074c2c819941and * information on the Apache Software Foundation, please see
6ae232055d4d8a97267517c5e50074c2c819941and * Portions of this software are based upon public domain software
6ae232055d4d8a97267517c5e50074c2c819941and * originally written at the National Center for Supercomputing Applications,
6ae232055d4d8a97267517c5e50074c2c819941and * University of Illinois, Urbana-Champaign.
6ae232055d4d8a97267517c5e50074c2c819941and * htdbm.c: simple program for manipulating DBM
6ae232055d4d8a97267517c5e50074c2c819941and * password databases for the Apache HTTP server
6ae232055d4d8a97267517c5e50074c2c819941and * Contributed by Mladen Turk <mturk@mappingsoft.com>
6ae232055d4d8a97267517c5e50074c2c819941and * 12 Oct 2001
6ae232055d4d8a97267517c5e50074c2c819941and#endif /*APR_CHARSET_EBCDIC*/
6ae232055d4d8a97267517c5e50074c2c819941and#else /*APR_CHARSET_EBCDIC*/
6ae232055d4d8a97267517c5e50074c2c819941and#endif /*APR_CHARSET_EBCDIC*/
6ae232055d4d8a97267517c5e50074c2c819941andstatic void htdbm_interrupted(void)
6ae232055d4d8a97267517c5e50074c2c819941andstatic apr_status_t htdbm_init(apr_pool_t **pool, htdbm_t **hdbm)
6ae232055d4d8a97267517c5e50074c2c819941and (*hdbm) = (htdbm_t *)apr_pcalloc(*pool, sizeof(htdbm_t));
6ae232055d4d8a97267517c5e50074c2c819941and rv = apr_xlate_open(to_ascii, "ISO8859-1", APR_DEFAULT_CHARSET, (*hdbm)->pool);
6ae232055d4d8a97267517c5e50074c2c819941and#endif /*APR_CHARSET_EBCDIC*/
6ae232055d4d8a97267517c5e50074c2c819941and /* Set MD5 as default */
6ae232055d4d8a97267517c5e50074c2c819941and return apr_dbm_open(&htdbm->dbm, htdbm->filename, APR_DBM_RWCREATE,
6ae232055d4d8a97267517c5e50074c2c819941andstatic char * ap_getword(apr_pool_t *atrans, char **line, char stop)
727872d18412fc021f03969b8641810d8896820bhumbedoohstatic apr_status_t htdbm_save(htdbm_t *htdbm, int *changed)
return APR_ENOENT;
return APR_ENOENT;
return APR_ENOENT;
if (cmnt)
return APR_ENOENT;
return APR_EGENERAL;
if (cmnt)
return APR_SUCCESS;
static void to64(char *s, unsigned long v, int n)
case ALG_APSHA:
case ALG_APMD5:
case ALG_PLAIN:
#if APR_HAVE_CRYPT_H
case ALG_CRYPT:
return APR_SUCCESS;
return APR_EINVAL;
return APR_EINVAL;
return APR_SUCCESS;
static void htdbm_usage(void)
#if APR_HAVE_CRYPT_H
#if APR_HAVE_CRYPT_H
apr_size_t l;
const char *arg;
int need_cmnt = 0;
int pwd_supplied = 0;
int changed;
htdbm_usage();
switch (*arg) {
need_pwd = 0;
args_left++;
need_file = 0;
args_left--;
need_pwd = 0;
need_user = 0;
args_left--;
args_left++;
need_pwd = 0;
#if APR_HAVE_CRYPT_H
htdbm_usage();
htdbm_usage();
if (!need_file)
if (need_user) {
if (pwd_supplied)
if (need_pwd) {
l = sizeof(pwc);
l = sizeof(pwc);
else if (need_cmnt)
switch (cmd) {
case HTDBM_VERIFY:
case HTDBM_DELETE:
case HTDBM_LIST:
htdbm_list(h);
htdbm_make(h);
htdbm_terminate(h);