1
0
mirror of https://github.com/unrealircd/unrealircd.git synced 2026-07-06 17:23:13 +02:00

Check that the automatically-generated cloak keys fit unrealircd's own criteria before printing them out. (#4017)

This commit is contained in:
Nathan Phillip Brink
2011-06-05 23:03:36 -04:00
parent ceba1d07c6
commit 80806af8bd
2 changed files with 21 additions and 3 deletions
+2
View File
@@ -2293,3 +2293,5 @@
the connection'). This has now been fixed.
- Fix compile failure introduced by last change when zip links are
disabled.
- Check that the automatically-generated cloak keys fit unrealircd's
own criteria before printing them out. (#4017)
+19 -3
View File
@@ -1003,18 +1003,26 @@ struct ThrottlingBucket z = { NULL, NULL, {0}, 0, 0};
static void generate_cloakkeys()
{
/* Generate 3 cloak keys */
#define GENERATE_CLOAKKEY_MINLEN 10
#define GENERATE_CLOAKKEY_MAXLEN 20 /* Length of cloak keys to generate. */
#define GENERATE_CLOAKKEY_MINLEN 16
#define GENERATE_CLOAKKEY_MAXLEN 32 /* Length of cloak keys to generate. */
char keyBuf[GENERATE_CLOAKKEY_MAXLEN + 1];
int keyNum;
int keyLen;
int charIndex;
int value;
short has_upper;
short has_lower;
short has_num;
fprintf(stderr, "Here are 3 random cloak keys:\n");
for (keyNum = 0; keyNum < 3; ++keyNum)
{
has_upper = 0;
has_lower = 0;
has_num = 0;
keyLen = (getrandom8() % (GENERATE_CLOAKKEY_MAXLEN - GENERATE_CLOAKKEY_MINLEN + 1)) + GENERATE_CLOAKKEY_MINLEN;
for (charIndex = 0; charIndex < keyLen; ++charIndex)
{
@@ -1022,17 +1030,25 @@ static void generate_cloakkeys()
{
case 0: /* Uppercase. */
keyBuf[charIndex] = (char)('A' + (getrandom8() % ('Z' - 'A')));
has_upper = 1;
break;
case 1: /* Lowercase. */
keyBuf[charIndex] = (char)('a' + (getrandom8() % ('z' - 'a')));
has_lower = 1;
break;
case 2: /* Digit. */
keyBuf[charIndex] = (char)('0' + (getrandom8() % ('9' - '0')));
has_num = 1;
break;
}
}
keyBuf[keyLen] = '\0';
(void)fprintf(stderr, "%s\n", keyBuf);
if (has_upper && has_lower && has_num)
(void)fprintf(stderr, "%s\n", keyBuf);
else
/* Try again. For this reason, keyNum must be signed. */
keyNum--;
}
}
#endif