1
0
mirror of https://github.com/unrealircd/unrealircd.git synced 2026-06-12 17:14:46 +02:00

Move mkpasswd operation to unrealircdctl. For *NIX users no change as this

is done behind-the-scenes (the command is still ./unrealircd mkpasswd).
For Windows users it finally means they can generate passwords via the CLI
using: unrealircdctl mkpasswd pwdhere
This commit is contained in:
Bram Matthys
2022-01-03 14:12:32 +01:00
parent 243c6635da
commit e35c29f3d5
3 changed files with 42 additions and 39 deletions
-37
View File
@@ -626,43 +626,6 @@ int InitUnrealIRCd(int argc, char *argv[])
safe_strdup(configfile, p);
convert_to_absolute_path(&configfile, CONFDIR);
break;
#ifndef _WIN32
case 'P':{
short type;
const char *result;
srandom(TStime());
type = Auth_FindType(NULL, p);
if (type == -1)
{
type = AUTHTYPE_ARGON2;
} else {
p = *++argv;
argc--;
}
if (BadPtr(p))
{
#ifndef _WIN32
p = getpass("Enter password to hash: ");
#else
printf("ERROR: You should specify a password to hash");
exit(1);
#endif
}
if ((type == AUTHTYPE_UNIXCRYPT) && (strlen(p) > 8))
{
/* Hmmm.. is this warning really still true (and always) ?? */
printf("WARNING: Password truncated to 8 characters due to 'crypt' algorithm. "
"You are suggested to use the 'argon2' algorithm instead.");
p[8] = '\0';
}
if (!(result = Auth_Hash(type, p))) {
printf("Failed to generate password. Deprecated method? Try 'argon2' instead.\n");
exit(0);
}
printf("Encrypted password is: %s\n", result);
exit(0);
}
#endif
#if 0
case 'S':
charsys_dump_table(p ? p : "*");
+41 -1
View File
@@ -71,6 +71,44 @@ void unrealircdctl_status(void)
exit(1);
}
void unrealircdctl_mkpasswd(int argc, char *argv[])
{
AuthenticationType type;
const char *result;
char *p = argv[2];
srandom(TStime());
type = Auth_FindType(NULL, p);
if (type == -1)
{
type = AUTHTYPE_ARGON2;
} else {
p = argv[3];
}
if (BadPtr(p))
{
#ifndef _WIN32
p = getpass("Enter password to hash: ");
#else
printf("ERROR: You should specify a password to hash");
exit(1);
#endif
}
if ((type == AUTHTYPE_UNIXCRYPT) && (strlen(p) > 8))
{
/* Hmmm.. is this warning really still true (and always) ?? */
printf("WARNING: Password truncated to 8 characters due to 'crypt' algorithm. "
"You are suggested to use the 'argon2' algorithm instead.");
p[8] = '\0';
}
if (!(result = Auth_Hash(type, p))) {
printf("Failed to generate password. Deprecated method? Try 'argon2' instead.\n");
exit(0);
}
printf("Encrypted password is: %s\n", result);
exit(0);
}
int main(int argc, char *argv[])
{
dbuf_init();
@@ -87,7 +125,9 @@ int main(int argc, char *argv[])
unrealircdctl_reloadtls();
else if (!strcmp(argv[1], "status"))
unrealircdctl_status();
else if (!strcmp(argv[1], "mkpasswd"))
unrealircdctl_mkpasswd(argc, argv);
else
printf("Hai frienz: %d\n", argc);
unrealircdctl_usage(argv[0]);
exit(0);
}
+1 -1
View File
@@ -114,7 +114,7 @@ elif [ "$1" = "module" ] ; then
shift
@BINDIR@/unrealircd -m $*
elif [ "$1" = "mkpasswd" ] ; then
@BINDIR@/unrealircd -P $2 $3
$UNREALIRCDCTL mkpasswd $2 $3
elif [ "$1" = "version" ] ; then
@BINDIR@/unrealircd -v
elif [ "$1" = "gencloak" ] ; then