fix pw-inspector

This commit is contained in:
vanhauser-thc 2023-06-24 12:03:03 +02:00
parent 714b051867
commit 28f073fd79

View file

@ -50,7 +50,7 @@ int main(int argc, char *argv[]) {
int32_t sets = 0, countsets = 0, minlen = 0, maxlen = MAXLENGTH, count = 0; int32_t sets = 0, countsets = 0, minlen = 0, maxlen = MAXLENGTH, count = 0;
int32_t set_low = 0, set_up = 0, set_no = 0, set_print = 0, set_other = 0; int32_t set_low = 0, set_up = 0, set_no = 0, set_print = 0, set_other = 0;
FILE *in = stdin, *out = stdout; FILE *in = stdin, *out = stdout;
char buf[MAXLENGTH + 1]; unsigned char buf[MAXLENGTH + 1];
prg = argv[0]; prg = argv[0];
if (argc < 2) if (argc < 2)
@ -124,9 +124,9 @@ int main(int argc, char *argv[]) {
if (countsets == 0) if (countsets == 0)
countsets = sets; countsets = sets;
while (fgets(buf, sizeof(buf), in) != NULL) { while (fgets((void *)buf, sizeof(buf), in) != NULL) {
i = -1; int is_low = 0, is_up = 0, is_no = 0, is_print = 0, is_other = 0;
if (buf[0] == 0) if (!buf[0])
continue; continue;
if (buf[strlen(buf) - 1] == '\n') if (buf[strlen(buf) - 1] == '\n')
buf[strlen(buf) - 1] = 0; buf[strlen(buf) - 1] = 0;
@ -134,40 +134,31 @@ int main(int argc, char *argv[]) {
buf[strlen(buf) - 1] = 0; buf[strlen(buf) - 1] = 0;
if (strlen(buf) >= minlen && strlen(buf) <= maxlen) { if (strlen(buf) >= minlen && strlen(buf) <= maxlen) {
i = 0; i = 0;
if (countsets > 0) { j = 1;
if (set_low) for (i = 0; i < strlen(buf) && j; i++) {
if (strpbrk(buf, "abcdefghijklmnopqrstuvwxyz") != NULL) j = 0;
i++; if (set_low && islower(buf[i])) {
if (set_up) j = 1;
if (strpbrk(buf, "ABCDEFGHIJKLMNOPQRSTUVWXYZ") != NULL) is_low = 1;
i++; } else if (set_up && isupper(buf[i])) {
if (set_no) j = 1;
if (strpbrk(buf, "0123456789") != NULL) is_up = 1;
i++; } else if (set_no && isdigit(buf[i])) {
if (set_print) { j = 1;
j = 0; is_no = 1;
for (k = 0; k < strlen(buf); k++) } else if (set_print && isprint(buf[i]) && !isalnum(buf[i])) {
if (isprint((int32_t)buf[k]) != 0 && isalnum((int32_t)buf[k]) == 0) j = 1;
j = 1; is_print = 1;
if (j) } else if (set_other && !isprint(buf[i])) {
i++; j = 1;
} is_other = 1;
if (set_other) {
j = 0;
for (k = 0; k < strlen(buf); k++)
if (isprint((int32_t)buf[k]) == 0 && isalnum((int32_t)buf[k]) == 0)
j = 1;
if (j)
i++;
} }
} }
if (i >= countsets) { if (j && countsets <= is_low + is_up + is_no + is_print + is_other) {
fprintf(out, "%s\n", buf); fprintf(out, "%s\n", buf);
count++; count++;
} }
} }
/* fprintf(stderr, "[DEBUG] i: %d minlen: %d maxlen: %d len: %d\n", i,
* minlen, maxlen, strlen(buf)); */
} }
fclose(in); fclose(in);
fclose(out); fclose(out);