htpasswd.c revision 5647769dc9969e353cff0c3b116c2cd9fac1538e
1276N/A/* ==================================================================== 1276N/A * The Apache Software License, Version 1.1 1276N/A * Copyright (c) 2000-2003 The Apache Software Foundation. All rights 486N/A * Redistribution and use in source and binary forms, with or without 486N/A * modification, are permitted provided that the following conditions 486N/A * 1. Redistributions of source code must retain the above copyright 486N/A * notice, this list of conditions and the following disclaimer. 486N/A * 2. Redistributions in binary form must reproduce the above copyright 1276N/A * notice, this list of conditions and the following disclaimer in 1068N/A * the documentation and/or other materials provided with the 486N/A * 3. The end-user documentation included with the redistribution, 486N/A * if any, must include the following acknowledgment: 486N/A * "This product includes software developed by the 1276N/A * Alternately, this acknowledgment may appear in the software itself, 486N/A * if and wherever such third-party acknowledgments normally appear. 486N/A * 4. The names "Apache" and "Apache Software Foundation" must 1276N/A * not be used to endorse or promote products derived from this 486N/A * software without prior written permission. For written 1276N/A * permission, please contact apache@apache.org. 1276N/A * 5. Products derived from this software may not be called "Apache", 486N/A * nor may "Apache" appear in their name, without prior written 486N/A * permission of the Apache Software Foundation. 1276N/A * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED 486N/A * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 486N/A * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 486N/A * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR 486N/A * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 486N/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 486N/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 486N/A * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 486N/A * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 486N/A * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 486N/A * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 486N/A * ==================================================================== 486N/A * This software consists of voluntary contributions made by many 486N/A * individuals on behalf of the Apache Software Foundation. For more 486N/A * information on the Apache Software Foundation, please see 486N/A * Portions of this software are based upon public domain software 486N/A * originally written at the National Center for Supercomputing Applications, 486N/A * University of Illinois, Urbana-Champaign. 1276N/A/****************************************************************************** 486N/A ****************************************************************************** 486N/A * NOTE! This program is not safe as a setuid executable! Do not make it 486N/A ****************************************************************************** 486N/A *****************************************************************************/ 486N/A * the Apache HTTP server 486N/A * Originally by Rob McCool 486N/A * 2: Failure; command line syntax problem (usage message issued) 486N/A * 3: Failure; password verification failure 486N/A * 4: Failure; operation interrupted (such as with CTRL/C) 486N/A * 5: Failure; buffer would overflow (username, filename, or computed 486N/A * 6: Failure; username contains illegal or reserved characters 1068N/A * 7: Failure; file is not a valid htpasswd file 486N/A#
else /*APR_CHARSET_EBCDIC*/ 486N/A#
endif /*APR_CHARSET_EBCDIC*/ 486N/Astatic void to64(
char *s,
unsigned long v,
int n)
486N/A static unsigned char itoa64[] =
/* 0 ... 63 => ASCII - 64 */ 486N/A "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
* Make a password record from the given information. A zero return * indicates success; failure means that the output buffer contains an /* XXX cpw >= 28 + strlen(sha1) chars - fixed len SHA */ /* XXX this len limitation is not in sync with any HTTPd len. */ * Check to see if the buffer is large enough to hold the username, "rather than prompting for it.\n");
"On Windows, NetWare and TPF systems the '-m' flag is used by " "On all other systems, the '-p' flag will probably not work.\n");
* Check to see if the specified file can be opened for the given * Return true if the named file exists, regardless of permissions. * Preliminary check to make sure they provided at least * three arguments, we'll do better argument checking as * we parse the command line. * Go through the argument list and pick out any options. They * have to precede any other arguments. for (i =
1; i <
argc; i++) {
* Make sure we still have exactly the right number of arguments left * (the filename, the username, and possibly the password if -b was "character '%c'\n",
argv[0], *
arg);
* Let's do it. We end up doing a lot of file opening and closing, * but what do we care? This application isn't run constantly. #
endif /*APR_CHARSET_EBCDIC*/ "might just not work on this platform.\n");
* Only do the file checks if we're supposed to frob it. * Check that this existing file is readable and writable. * Error out if -c was omitted for this non-existant file. "%s: cannot modify file %s; use '-c' to create it\n",
* As it doesn't exist yet, verify that we can create it. * All the file access checks (if any) have been made. Time to go to work; * try to create the record for the username in question. If that * fails, there's no need to waste any time on file manipulations. * Any error message text is returned in the record buffer, since * the mkrecord() routine doesn't have access to argv[]. * We can access the files the right way, and we have a record * to add or update. Let's do it.. * If we're not creating a new file, copy records from the existing * one to the temporary file until we find the specified user. if ((
line[0] ==
'#') || (
line[0] ==
'\0')) {
* See if this is our user. * If we've not got a colon on the line, this could well * not be a valid htpasswd file. * We should bail at this point. "to be a valid htpasswd file.\n",
/* We found the user we were looking for, add him to the file. /* The temporary file has all the data, just copy it to the new location.