htdbm.c revision f4e4643c309e5b5da60e13f9a25984d54b307caa
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd/* ====================================================================
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * The Apache Software License, Version 1.1
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * Copyright (c) 2000-2001 The Apache Software Foundation. All rights
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * reserved.
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * Redistribution and use in source and binary forms, with or without
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * modification, are permitted provided that the following conditions
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * are met:
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * 1. Redistributions of source code must retain the above copyright
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * notice, this list of conditions and the following disclaimer.
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * 2. Redistributions in binary form must reproduce the above copyright
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * notice, this list of conditions and the following disclaimer in
27e52281f1522522b170cafc76b08b58aa70ccaand * the documentation and/or other materials provided with the
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * distribution.
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * 3. The end-user documentation included with the redistribution,
4b5981e276e93df97c34e4da05ca5cf8bbd937dand * if any, must include the following acknowledgment:
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * "This product includes software developed by the
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * Apache Software Foundation (http://www.apache.org/)."
ad74a0524a06bfe11b7de9e3b4ce7233ab3bd3f7nd * Alternately, this acknowledgment may appear in the software itself,
ad74a0524a06bfe11b7de9e3b4ce7233ab3bd3f7nd * if and wherever such third-party acknowledgments normally appear.
ad74a0524a06bfe11b7de9e3b4ce7233ab3bd3f7nd * 4. The names "Apache" and "Apache Software Foundation" must
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end * not be used to endorse or promote products derived from this
ecc5150d35c0dc5ee5119c2717e6660fa331abbftakashi * software without prior written permission. For written
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * permission, please contact apache@apache.org.
a76bfec941c4c5e3e1e24d7007108f4d3dac91a5nd * 5. Products derived from this software may not be called "Apache",
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * nor may "Apache" appear in their name, without prior written
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * permission of the Apache Software Foundation.
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * SUCH DAMAGE.
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * ====================================================================
71fccc298df6a1540d408151a26aa22beed55d0bnd * This software consists of voluntary contributions made by many
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * individuals on behalf of the Apache Software Foundation. For more
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * information on the Apache Software Foundation, please see
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * Portions of this software are based upon public domain software
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * originally written at the National Center for Supercomputing Applications,
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * University of Illinois, Urbana-Champaign.
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * htdbm.c: simple program for manipulating DBM
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * password databases for the Apache HTTP server
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * Contributed by Mladen Turk <mturk@mappingsoft.com>
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * 12 Oct 2001
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd#endif /*APR_CHARSET_EBCDIC*/
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd#else /*APR_CHARSET_EBCDIC*/
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd#endif /*APR_CHARSET_EBCDIC*/
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd#define APU_HTDBM_DECLARE(x) static x
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndAPU_HTDBM_DECLARE(void) apu_htdbm_terminate(apu_htdbm_t *htdbm)
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndAPU_HTDBM_DECLARE(apr_status_t) apu_htdbm_init(apr_pool_t **pool, apu_htdbm_t **hdbm)
6fe26506780e73be2a412d758af77fafdf03291and apr_signal(SIGINT, (void (*)(int)) apu_htdbm_interrupted);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd (*hdbm) = (apu_htdbm_t *)apr_pcalloc(*pool, sizeof(apu_htdbm_t));
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd rv = apr_xlate_open(to_ascii, "ISO8859-1", APR_DEFAULT_CHARSET, (*hdbm)->pool);
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd#endif /*APR_CHARSET_EBCDIC*/
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd /* Set MD5 as default */
4b5981e276e93df97c34e4da05ca5cf8bbd937dandAPU_HTDBM_DECLARE(apr_status_t) apu_htdbm_open(apu_htdbm_t *htdbm)
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd return apr_dbm_open(&htdbm->dbm, htdbm->filename, APR_DBM_RWCREATE,
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndAPU_HTDBM_DECLARE(char *) ap_getword(apr_pool_t *atrans, char **line, char stop)
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndAPU_HTDBM_DECLARE(apr_status_t) apu_htdbm_save(apu_htdbm_t *htdbm, int *changed)
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd val.dptr = apr_pstrcat(htdbm->pool, htdbm->userpass, ";",
71fccc298df6a1540d408151a26aa22beed55d0bndAPU_HTDBM_DECLARE(apr_status_t) apu_htdbm_del(apu_htdbm_t *htdbm)
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1endAPU_HTDBM_DECLARE(apr_status_t) apu_htdbm_verify(apu_htdbm_t *htdbm)
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 APU_HTDBM_VERIFY:
case APU_HTDBM_DELETE:
case APU_HTDBM_LIST:
apu_htdbm_list(h);
apu_htdbm_make(h);