htpasswd.c revision ea283513d76eccfc30ee79bc031188e2c2b12b0c
765f3b8c82bca96eeb44463da2305201b1a493daChristian Maeder/* ====================================================================
765f3b8c82bca96eeb44463da2305201b1a493daChristian Maeder * The Apache Software License, Version 1.1
765f3b8c82bca96eeb44463da2305201b1a493daChristian Maeder * Copyright (c) 2000-2001 The Apache Software Foundation. All rights
765f3b8c82bca96eeb44463da2305201b1a493daChristian Maeder * Redistribution and use in source and binary forms, with or without
765f3b8c82bca96eeb44463da2305201b1a493daChristian Maeder * modification, are permitted provided that the following conditions
765f3b8c82bca96eeb44463da2305201b1a493daChristian Maeder * 1. Redistributions of source code must retain the above copyright
765f3b8c82bca96eeb44463da2305201b1a493daChristian Maeder * notice, this list of conditions and the following disclaimer.
765f3b8c82bca96eeb44463da2305201b1a493daChristian Maeder * 2. Redistributions in binary form must reproduce the above copyright
765f3b8c82bca96eeb44463da2305201b1a493daChristian Maeder * notice, this list of conditions and the following disclaimer in
765f3b8c82bca96eeb44463da2305201b1a493daChristian Maeder * the documentation and/or other materials provided with the
765f3b8c82bca96eeb44463da2305201b1a493daChristian Maeder * distribution.
765f3b8c82bca96eeb44463da2305201b1a493daChristian Maeder * 3. The end-user documentation included with the redistribution,
765f3b8c82bca96eeb44463da2305201b1a493daChristian Maeder * if any, must include the following acknowledgment:
765f3b8c82bca96eeb44463da2305201b1a493daChristian Maeder * "This product includes software developed by the
765f3b8c82bca96eeb44463da2305201b1a493daChristian Maeder * Apache Software Foundation (http://www.apache.org/)."
765f3b8c82bca96eeb44463da2305201b1a493daChristian Maeder * Alternately, this acknowledgment may appear in the software itself,
765f3b8c82bca96eeb44463da2305201b1a493daChristian Maeder * if and wherever such third-party acknowledgments normally appear.
765f3b8c82bca96eeb44463da2305201b1a493daChristian Maeder * 4. The names "Apache" and "Apache Software Foundation" must
765f3b8c82bca96eeb44463da2305201b1a493daChristian Maeder * not be used to endorse or promote products derived from this
765f3b8c82bca96eeb44463da2305201b1a493daChristian Maeder * software without prior written permission. For written
765f3b8c82bca96eeb44463da2305201b1a493daChristian Maeder * permission, please contact apache@apache.org.
765f3b8c82bca96eeb44463da2305201b1a493daChristian Maeder * 5. Products derived from this software may not be called "Apache",
765f3b8c82bca96eeb44463da2305201b1a493daChristian Maeder * nor may "Apache" appear in their name, without prior written
765f3b8c82bca96eeb44463da2305201b1a493daChristian Maeder * permission of the Apache Software Foundation.
765f3b8c82bca96eeb44463da2305201b1a493daChristian Maeder * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
765f3b8c82bca96eeb44463da2305201b1a493daChristian Maeder * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
765f3b8c82bca96eeb44463da2305201b1a493daChristian Maeder * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
765f3b8c82bca96eeb44463da2305201b1a493daChristian Maeder * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
765f3b8c82bca96eeb44463da2305201b1a493daChristian Maeder * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
765f3b8c82bca96eeb44463da2305201b1a493daChristian Maeder * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
765f3b8c82bca96eeb44463da2305201b1a493daChristian Maeder * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
765f3b8c82bca96eeb44463da2305201b1a493daChristian Maeder * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
765f3b8c82bca96eeb44463da2305201b1a493daChristian Maeder * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
765f3b8c82bca96eeb44463da2305201b1a493daChristian Maeder * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
765f3b8c82bca96eeb44463da2305201b1a493daChristian Maeder * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
4d7def117f71589712fa1f9b13b1997609e4a0b0Christian Maeder * SUCH DAMAGE.
4d7def117f71589712fa1f9b13b1997609e4a0b0Christian Maeder * ====================================================================
765f3b8c82bca96eeb44463da2305201b1a493daChristian Maeder * This software consists of voluntary contributions made by many
765f3b8c82bca96eeb44463da2305201b1a493daChristian Maeder * individuals on behalf of the Apache Software Foundation. For more
4d7def117f71589712fa1f9b13b1997609e4a0b0Christian Maeder * information on the Apache Software Foundation, please see
4d7def117f71589712fa1f9b13b1997609e4a0b0Christian Maeder * Portions of this software are based upon public domain software
4d7def117f71589712fa1f9b13b1997609e4a0b0Christian Maeder * originally written at the National Center for Supercomputing Applications,
4d7def117f71589712fa1f9b13b1997609e4a0b0Christian Maeder * University of Illinois, Urbana-Champaign.
765f3b8c82bca96eeb44463da2305201b1a493daChristian Maeder/******************************************************************************
765f3b8c82bca96eeb44463da2305201b1a493daChristian Maeder ******************************************************************************
765f3b8c82bca96eeb44463da2305201b1a493daChristian Maeder * NOTE! This program is not safe as a setuid executable! Do not make it
765f3b8c82bca96eeb44463da2305201b1a493daChristian Maeder ******************************************************************************
765f3b8c82bca96eeb44463da2305201b1a493daChristian Maeder *****************************************************************************/
765f3b8c82bca96eeb44463da2305201b1a493daChristian Maeder * htpasswd.c: simple program for manipulating password file for
765f3b8c82bca96eeb44463da2305201b1a493daChristian Maeder * the Apache HTTP server
765f3b8c82bca96eeb44463da2305201b1a493daChristian Maeder * Originally by Rob McCool
765f3b8c82bca96eeb44463da2305201b1a493daChristian Maeder * Exit values:
765f3b8c82bca96eeb44463da2305201b1a493daChristian Maeder * 1: Failure; file access/permission problem
#include "apr.h"
#include "apr_lib.h"
#include "apr_strings.h"
#include "apr_errno.h"
#include "apr_file_io.h"
#include "apr_general.h"
#include "apr_signal.h"
#if APR_HAVE_STDIO_H
#include <stdio.h>
#include "apr_md5.h"
#include "apr_sha1.h"
#include <time.h>
#if APR_HAVE_CRYPT_H
#include <crypt.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#ifdef WIN32
#include <conio.h>
#if !APR_CHARSET_EBCDIC
#define ALG_PLAIN 0
static char *tempfilename;
#ifdef L_tmpnam
s[i] = (char) fgetc(f);
if (s[i] == CR) {
s[i] = fgetc(f);
fputc(l[x], f);
static void to64(char *s, unsigned long v, int n)
int alg)
char *pw;
return ERR_OVERFLOW;
return ERR_PWMISMATCH;
switch (alg) {
case ALG_APSHA:
case ALG_APMD5:
case ALG_PLAIN:
case ALG_CRYPT:
return ERR_OVERFLOW;
static int usage(void)
return ERR_SYNTAX;
static void interrupted(void)
FILE *s;
if (s == NULL) {
fclose(s);
#ifdef NETWARE
void nwTerminate()
pressanykey();
char *arg;
int found = 0;
int newfile = 0;
int nofile = 0;
int noninteractive = 0;
#ifdef NETWARE
if (rv) {
if (rv) {
if (rv) {
return usage();
newfile++;
nofile++;
args_left--;
args_left++;
return usage();
return usage();
return ERR_SYNTAX;
if (nofile) {
return ERR_OVERFLOW;
return ERR_OVERFLOW;
return ERR_BADUSER;
if (noninteractive) {
return ERR_OVERFLOW;
if (! nofile) {
alg);
exit(i);
if (nofile) {
exit(0);
errno = 0;
argv[0]);
if (errno == 0) {
if (! newfile) {
char *colon;
found++;
if (found) {
if (! newfile) {