htdbm.c revision 3d81f57512275ca06a60a9bcbd23c1f8b429fdf2
/* Copyright 2001-2006 The Apache Software Foundation or its licensors, as
* applicable.
*
* Licensed 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 "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*/
#include <unistd.h>
#endif
#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 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[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. */
#if APR_HAVE_CRYPT_H
"server on this platform!\n");
#endif
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 = 0;
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) {
if (!need_cmnt) {
}
else {
h->comment);
}
}
htdbm_terminate(h);
return 0; /* Suppress compiler warning. */
}