#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;
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");
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");
*mask |= APHTP_NONINTERACTIVE;
args_left++;
}
+ else if (*arg == 'D') {
+ *mask |= APHTP_DELUSER;
+ }
else {
usage();
}
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
* 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);
+ }
}
/*
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.