htdigest.c revision f2159535eb8f7ea510a17038b8156256abc77a41
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny/* ====================================================================
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * The Apache Software License, Version 1.1
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * Copyright (c) 2000 The Apache Software Foundation. All rights
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * Redistribution and use in source and binary forms, with or without
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * modification, are permitted provided that the following conditions
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * 1. Redistributions of source code must retain the above copyright
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * notice, this list of conditions and the following disclaimer.
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * 2. Redistributions in binary form must reproduce the above copyright
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * notice, this list of conditions and the following disclaimer in
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * the documentation and/or other materials provided with the
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * distribution.
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * 3. The end-user documentation included with the redistribution,
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * if any, must include the following acknowledgment:
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * "This product includes software developed by the
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * Apache Software Foundation (http://www.apache.org/)."
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * Alternately, this acknowledgment may appear in the software itself,
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * if and wherever such third-party acknowledgments normally appear.
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * 4. The names "Apache" and "Apache Software Foundation" must
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zeleny * not be used to endorse or promote products derived from this
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * software without prior written permission. For written
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * permission, please contact apache@apache.org.
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * 5. Products derived from this software may not be called "Apache",
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * nor may "Apache" appear in their name, without prior written
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * permission of the Apache Software Foundation.
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zeleny * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zeleny * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * SUCH DAMAGE.
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * ====================================================================
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * This software consists of voluntary contributions made by many
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * individuals on behalf of the Apache Software Foundation. For more
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * information on the Apache Software Foundation, please see
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny/******************************************************************************
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny ******************************************************************************
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * NOTE! This program is not safe as a setuid executable! Do not make it
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny ******************************************************************************
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny *****************************************************************************/
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * htdigest.c: simple program for manipulating digest passwd file for Apache
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * by Alexei Kosut, based on htpasswd.c, by Rob McCool
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny#endif /* CHARSET_EBCDIC */
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zelenystatic void getword(char *word, char *line, char stop)
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny int x = 0, y;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny for (x = 0; ((line[x]) && (line[x] != stop)); x++)
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny register int i = 0;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny if (s[i] == CR)
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny if ((s[i] == 0x4) || (s[i] == LF) || (i == (n - 1))) {
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny s[i] = '\0';
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny for (x = 0; l[x]; x++)
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zelenystatic void add_password(char *user, char *realm, apr_file_t *f)
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny unsigned int i;
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zeleny if (apr_getpass("New password: ", pwin, &len) != APR_SUCCESS) {
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny apr_getpass("Re-type new password: ", pwv, &len);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny /* Do MD5 stuff */
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny apr_MD5Update(&context, (unsigned char *) string, strlen(string));
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny for (i = 0; i < 16; i++)
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zelenystatic void usage(void)
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny fprintf(stderr, "Usage: htdigest [-c] passwordfile realm username\n");
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny fprintf(stderr, "The -c flag creates a new file.\n");
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zelenystatic void interrupted(void)
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny rv = apr_xlate_open(&to_ascii, "ISO8859-1", APR_DEFAULT_CHARSET, cntxt);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny if (apr_open(&tfp, argv[2], APR_WRITE | APR_CREATE, -1, cntxt) != APR_SUCCESS) {
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny fprintf(stderr, "Could not open passwd file %s for writing.\n",
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny printf("Adding password for %s in realm %s.\n", argv[4], argv[3]);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny if (apr_open(&tfp, tn, APR_WRITE | APR_CREATE, -1, cntxt)!= APR_SUCCESS) {
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny if (apr_open(&f, argv[1], APR_READ, -1, cntxt) != APR_SUCCESS) {
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny "Could not open passwd file %s for reading.\n", argv[1]);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny fprintf(stderr, "Use -c option to create new one.\n");
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny printf("Changing password for user %s in realm %s\n", user, realm);
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zeleny printf("Adding user %s in realm %s\n", user, realm);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny sprintf(command, "copy \"%s\" \"%s\"", tn, argv[1]);