8a77240a809197c92c0736c431b4b88947a7bac1Christian Maeder/* Licensed to the Apache Software Foundation (ASF) under one or more
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroeder * contributor license agreements. See the NOTICE file distributed with
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroeder * this work for additional information regarding copyright ownership.
ece3b1a5353a9af3c966a1d5453594ed35334f7bJonathan von Schroeder * The ASF licenses this file to You under the Apache License, Version 2.0
ece3b1a5353a9af3c966a1d5453594ed35334f7bJonathan von Schroeder * (the "License"); you may not use this file except in compliance with
ece3b1a5353a9af3c966a1d5453594ed35334f7bJonathan von Schroeder * the License. You may obtain a copy of the License at
98890889ffb2e8f6f722b00e265a211f13b5a861Corneliu-Claudiu Prodescu * http://www.apache.org/licenses/LICENSE-2.0
6820f0de92751e29d73d64db48e776591f529a76Christian Maeder * Unless required by applicable law or agreed to in writing, software
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroeder * distributed under the License is distributed on an "AS IS" BASIS,
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroeder * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroeder * See the License for the specific language governing permissions and
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroeder * limitations under the License.
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroeder * htdbm.c: simple program for manipulating DBM
6820f0de92751e29d73d64db48e776591f529a76Christian Maeder * password databases for the Apache HTTP server
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroeder * Contributed by Mladen Turk <mturk mappingsoft.com>
c56a356d3fcc5e123efa790aab320781d94df3c7Jonathan von Schroeder#endif /*APR_CHARSET_EBCDIC*/
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroederstatic void htdbm_terminate(htdbm_t *htdbm)
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroeder fprintf(stderr, "htdbm Interrupted !\n");
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroederstatic apr_status_t htdbm_init(apr_pool_t **pool, htdbm_t **hdbm)
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroeder apr_pool_abort_set(abort_on_oom, *pool);
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroeder apr_file_open_stderr(&errfile, *pool);
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroeder apr_signal(SIGINT, (void (*)(int)) htdbm_interrupted);
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroeder (*hdbm) = (htdbm_t *)apr_pcalloc(*pool, sizeof(htdbm_t));
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroeder rv = apr_xlate_open(&((*hdbm)->to_ascii), "ISO-8859-1", APR_DEFAULT_CHARSET, (*hdbm)->ctx.pool);
ece3b1a5353a9af3c966a1d5453594ed35334f7bJonathan von Schroeder fprintf(stderr, "apr_xlate_open(to ASCII)->%d\n", rv);
ece3b1a5353a9af3c966a1d5453594ed35334f7bJonathan von Schroeder rv = apr_SHA1InitEBCDIC((*hdbm)->to_ascii);
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroeder fprintf(stderr, "apr_SHA1InitEBCDIC()->%d\n", rv);
ece3b1a5353a9af3c966a1d5453594ed35334f7bJonathan von Schroeder rv = apr_MD5InitEBCDIC((*hdbm)->to_ascii);
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroeder fprintf(stderr, "apr_MD5InitEBCDIC()->%d\n", rv);
ece3b1a5353a9af3c966a1d5453594ed35334f7bJonathan von Schroeder#endif /*APR_CHARSET_EBCDIC*/
80d2ec8f37d5ddec13c14b17b1bab01e9c94630aChristian Maeder /* Set MD5 as default */
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroederstatic apr_status_t htdbm_open(htdbm_t *htdbm)
ece3b1a5353a9af3c966a1d5453594ed35334f7bJonathan von Schroeder return apr_dbm_open_ex(&htdbm->dbm, htdbm->type, htdbm->filename, APR_DBM_RWCREATE,
d71447e45047d07006b4c20409fbd8ea287df01fJonathan von Schroeder return apr_dbm_open_ex(&htdbm->dbm, htdbm->type, htdbm->filename,
ece3b1a5353a9af3c966a1d5453594ed35334f7bJonathan von Schroeder htdbm->rdonly ? APR_DBM_READONLY : APR_DBM_READWRITE,
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroederstatic apr_status_t htdbm_save(htdbm_t *htdbm, int *changed)
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroeder val.dsize = strlen(htdbm->ctx.passwd);
d71447e45047d07006b4c20409fbd8ea287df01fJonathan von Schroeder val.dptr = apr_pstrcat(htdbm->ctx.pool, htdbm->ctx.passwd, ":",
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroeder val.dsize += (strlen(htdbm->comment) + 1);
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroeder return apr_dbm_store(htdbm->dbm, key, val);
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroederstatic apr_status_t htdbm_del(htdbm_t *htdbm)
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroeder if (!apr_dbm_exists(htdbm->dbm, key))
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroeder return apr_dbm_delete(htdbm->dbm, key);
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroederstatic apr_status_t htdbm_verify(htdbm_t *htdbm)
return APR_ENOENT;
return APR_ENOENT;
if (cmnt)
return APR_ENOENT;
return APR_EGENERAL;
if (cmnt)
return APR_SUCCESS;
if (ret != 0) {
return ret;
return APR_EINVAL;
return APR_EINVAL;
return APR_SUCCESS;
switch (opt) {
need_file = 0;
args_left--;
need_pwd = 0;
need_user = 0;
args_left--;
args_left++;
need_pwd = 0;
if (ret) {
need_pwd = 0;
args_left++;
htdbm_usage();
if (need_file) {
if (need_user) {
if (need_pwd) {
if (ret) {
if (need_cmnt)
switch (cmd) {
case HTDBM_VERIFY:
case HTDBM_DELETE:
case HTDBM_LIST:
htdbm_list(h);
if (ret)
if (!need_cmnt) {
h->comment);
htdbm_terminate(h);