htdbm.c revision e39eb98e3ad3fbf5c34b2fa1d16861f95143e22e
/* 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.
*/
/*
* 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 "passwd_common.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 "apr_getopt.h"
#include <stdlib.h>
#endif
#include <string.h>
#endif
#include <strings.h>
#endif
#include <time.h>
#include "apr_xlate.h"
#endif /*APR_CHARSET_EBCDIC*/
#include <unistd.h>
#endif
#if APR_HAVE_CRYPT_H
#include <crypt.h>
#endif
struct htdbm_t {
struct passwd_ctx ctx;
#endif
char *filename;
char *username;
char *comment;
char *type;
int create;
int rdonly;
};
#define HTDBM_MAKE 0
#define HTDBM_DELETE 1
#define HTDBM_VERIFY 2
#define HTDBM_LIST 3
#define HTDBM_NOFILE 4
static void terminate(void)
{
#ifdef NETWARE
pressanykey();
#endif
}
{
}
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;
return APR_ENOENT;
return APR_ENOENT;
if (cmnt)
else
}
{
char *cmnt;
int i = 0;
if (rv != APR_SUCCESS) {
return APR_ENOENT;
}
if (rv != APR_SUCCESS) {
return APR_EGENERAL;
}
/* Note: we don't store \0-terminators on our dbm data */
if (cmnt)
if (rv != APR_SUCCESS)
++i;
}
return APR_SUCCESS;
}
{
char cpw[MAX_STRING_LEN];
int ret;
if (ret != 0) {
return ret;
}
return 0;
}
{
return APR_EINVAL;
}
return APR_EINVAL;
}
return APR_SUCCESS;
}
static void htdbm_usage(void)
{
"htdbm -- program for manipulating DBM password databases.\n\n"
"Usage: htdbm [-cmBdpstvx] [-Ccost] [-TDBTYPE] database username\n"
" -b[cmBdptsv] [-Ccost] [-TDBTYPE] database username password\n"
" -n[mBdpst] [-Ccost] username\n"
" -nb[mBdpst] [-Ccost] username password\n"
" -v[mBdps] [-Ccost] [-TDBTYPE] database username\n"
" -vb[mBdps] [-Ccost] [-TDBTYPE] database username password\n"
" -x [-Ccost] [-TDBTYPE] database username\n"
" -l [-Ccost] [-TDBTYPE] database\n"
"Options:\n"
" -b Use the password from the command line rather than prompting for it.\n"
" -c Create a new database.\n"
" -n Don't update database; display results on stdout.\n"
" -m Force MD5 encryption of the password (default).\n"
" -B Force BCRYPT encryption of the password (very secure).\n"
" -d Force CRYPT encryption of the password (8 chars max, insecure).\n"
" -p Do not encrypt the password (plaintext).\n"
" -s Force SHA encryption of the password (insecure).\n"
" -C Set the computing time used for the bcrypt algorithm.\n"
" (higher is more secure but slower, default: %d, valid: 4 to 31)\n"
" -T DBM Type (SDBM|GDBM|DB|default).\n"
" -l Display usernames from database on stdout.\n"
" -t The last param is username comment.\n"
" -x Remove the username record from database.\n"
"The SHA algorithm does not use a salt and is less secure than the "
"MD5 algorithm.\n",
}
{
char errbuf[MAX_STRING_LEN];
int need_file = 1;
int need_user = 1;
int need_pwd = 1;
int need_cmnt = 0;
int changed = 0;
int cmd = HTDBM_MAKE;
char opt;
const char *opt_arg;
exit(1);
}
if (rv != APR_SUCCESS)
switch (opt) {
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':
break;
case 'v':
h->rdonly = 1;
cmd = HTDBM_VERIFY;
break;
case 'x':
need_pwd = 0;
cmd = HTDBM_DELETE;
break;
default:
if (ret) {
}
}
}
need_pwd = 0;
args_left++;
}
/*
* 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) {
}
}
if (need_user) {
if (htdbm_valid_username(h) != APR_SUCCESS)
}
if (need_pwd) {
if (ret) {
}
}
if (need_cmnt)
switch (cmd) {
case HTDBM_VERIFY:
if (APR_STATUS_IS_ENOENT(rv)) {
}
else {
}
}
else
break;
case HTDBM_DELETE:
if (htdbm_del(h) != APR_SUCCESS) {
}
changed = 1;
break;
case HTDBM_LIST:
htdbm_list(h);
break;
default:
ret = htdbm_make(h);
if (ret)
break;
}
}
}
if (cmd == HTDBM_NOFILE) {
if (!need_cmnt) {
}
else {
h->comment);
}
}
htdbm_terminate(h);
return 0; /* Suppress compiler warning. */
}