From: Thom May Date: Wed, 14 May 2003 19:23:30 +0000 (+0000) Subject: Add a delete flag to htpasswd. X-Git-Tag: pre_ajp_proxy~1701 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=28fa3585521c929c2514454a534ceac658b85429;p=thirdparty%2Fapache%2Fhttpd.git Add a delete flag to htpasswd. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@99828 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/CHANGES b/CHANGES index 80189948ee3..45461313dcc 100644 --- a/CHANGES +++ b/CHANGES @@ -2,6 +2,9 @@ Changes with Apache 2.1.0-dev [Remove entries to the current 2.0 section below, when backported] + *) Add a delete flag to htpasswd. + [Thom May] + *) Ensure that ssl-std.conf is generated at configure time, and switch to using the expanded config variables to work the same as httpd-std.conf PR 19611 diff --git a/docs/man/htpasswd.1 b/docs/man/htpasswd.1 index 05ea498088c..47504240d65 100644 --- a/docs/man/htpasswd.1 +++ b/docs/man/htpasswd.1 @@ -27,10 +27,10 @@ htpasswd \- Manage user files for basic authentication .SH "SYNOPSIS" .PP -\fBhtpasswd\fR [ -\fBc\fR ] [ -\fBm\fR ] \fIpasswdfile\fR \fIusername\fR +\fBhtpasswd\fR [ -\fBc\fR ] [ -\fBm\fR ] [ -\fBD\fB ] \fIpasswdfile\fR \fIusername\fR .PP -\fBhtpasswd\fR -\fBb\fR [ -\fBc\fR ] [ -\fBm\fR | -\fBd\fR | -\fBp\fR | -\fBs\fR ] \fIpasswdfile\fR \fIusername\fR \fIpassword\fR +\fBhtpasswd\fR -\fBb\fR [ -\fBc\fR ] [ -\fBm\fR | -\fBd\fR | -\fBp\fR | -\fBs\fR ] [ -\fBD\fB ] \fIpasswdfile\fR \fIusername\fR \fIpassword\fR .PP \fBhtpasswd\fR -\fBn\fR [ -\fBm\fR | -\fBd\fR | -\fBs\fR | -\fBp\fR ] \fIusername\fR @@ -80,6 +80,9 @@ Use SHA encryption for passwords\&. Facilitates migration from/to Netscape serve -p Use plaintext passwords\&. Though htpasswd will support creation on all platforms, the httpd daemon will only accept plain text passwords on Windows, Netware and TPF\&. .TP +-D +Delete user\&. If the username exists in the specified htpasswd file, it will be deleted\&. +.TP \fIpasswdfile\fR Name of the file to contain the user name and password\&. If -c is given, this file is created if it does not already exist, or rewritten and truncated if it does exist\&. .TP diff --git a/support/htpasswd.c b/support/htpasswd.c index 2a28653ab46..0dabffc77d8 100644 --- a/support/htpasswd.c +++ b/support/htpasswd.c @@ -139,6 +139,7 @@ #define APHTP_NEWFILE 1 #define APHTP_NOFILE 2 #define APHTP_NONINTERACTIVE 4 +#define APHTP_DELUSER 8 apr_file_t *errfile; apr_file_t *ftemp = NULL; @@ -245,8 +246,8 @@ static int mkrecord(char *user, char *record, apr_size_t rlen, char *passwd, static void usage(void) { apr_file_printf(errfile, "Usage:\n"); - apr_file_printf(errfile, "\thtpasswd [-cmdps] passwordfile username\n"); - apr_file_printf(errfile, "\thtpasswd -b[cmdps] passwordfile username " + apr_file_printf(errfile, "\thtpasswd [-cmdpsD] passwordfile username\n"); + apr_file_printf(errfile, "\thtpasswd -b[cmdpsD] passwordfile username " "password\n\n"); apr_file_printf(errfile, "\thtpasswd -n[mdps] username\n"); apr_file_printf(errfile, "\thtpasswd -nb[mdps] username password\n"); @@ -267,6 +268,7 @@ static void usage(void) apr_file_printf(errfile, " -s Force SHA encryption of the password.\n"); apr_file_printf(errfile, " -b Use the password from the command line " "rather than prompting for it.\n"); + apr_file_printf(errfile, " -D Delete the specified user.\n"); apr_file_printf(errfile, "On Windows, NetWare and TPF systems the '-m' flag is used by " "default.\n"); @@ -359,6 +361,9 @@ static void check_args(apr_pool_t *pool, int argc, const char *const argv[], *mask |= APHTP_NONINTERACTIVE; args_left++; } + else if (*arg == 'D') { + *mask |= APHTP_DELUSER; + } else { usage(); } @@ -369,6 +374,14 @@ static void check_args(apr_pool_t *pool, int argc, const char *const argv[], apr_file_printf(errfile, "%s: -c and -n options conflict\n", argv[0]); exit(ERR_SYNTAX); } + if ((*mask & APHTP_NEWFILE) && (*mask & APHTP_DELUSER)) { + apr_file_printf(errfile, "%s: -c and -D options conflict\n", argv[0]); + exit(ERR_SYNTAX); + } + if ((*mask & APHTP_NOFILE) && (*mask & APHTP_DELUSER)) { + apr_file_printf(errfile, "%s: -n and -D options conflict\n", argv[0]); + exit(ERR_SYNTAX); + } /* * Make sure we still have exactly the right number of arguments left * (the filename, the username, and possibly the password if -b was @@ -532,15 +545,17 @@ int main(int argc, const char * const argv[]) * Any error message text is returned in the record buffer, since * the mkrecord() routine doesn't have access to argv[]. */ - i = mkrecord(user, record, sizeof(record) - 1, - password, alg); - if (i != 0) { - apr_file_printf(errfile, "%s: %s\n", argv[0], record); - exit(i); - } - if (mask & APHTP_NOFILE) { - printf("%s\n", record); - exit(0); + if (!(mask & APHTP_DELUSER)) { + i = mkrecord(user, record, sizeof(record) - 1, + password, alg); + if (i != 0) { + apr_file_printf(errfile, "%s: %s\n", argv[0], record); + exit(i); + } + if (mask & APHTP_NOFILE) { + printf("%s\n", record); + exit(0); + } } /* @@ -597,19 +612,33 @@ int main(int argc, const char * const argv[]) continue; } else { - /* We found the user we were looking for, add him to the file. - */ - apr_file_printf(errfile, "Updating "); - putline(ftemp, record); - found++; + if (!(mask & APHTP_DELUSER)) { + /* We found the user we were looking for. + * Add him to the file. + */ + apr_file_printf(errfile, "Updating "); + putline(ftemp, record); + found++; + } + else { + /* We found the user we were looking for. + * Delete them from the file. + */ + apr_file_printf(errfile, "Deleting "); + found++; + } } } apr_file_close(fpw); } - if (!found) { + if (!found && !(mask & APHTP_DELUSER)) { apr_file_printf(errfile, "Adding "); putline(ftemp, record); } + else if (!found && (mask & APHTP_DELUSER)) { + apr_file_printf(errfile, "User %s not found\n", user); + exit(0); + } apr_file_printf(errfile, "password for user %s\n", user); /* The temporary file has all the data, just copy it to the new location.