diff -rc squid-2.5.STABLE1/helpers/digest_auth/password/digest_pw_auth.c squid-2.5.STABLE1.modded/helpers/digest_auth/password/digest_pw_auth.c *** squid-2.5.STABLE1/helpers/digest_auth/password/digest_pw_auth.c Thu Feb 1 08:46:42 2001 --- squid-2.5.STABLE1.modded/helpers/digest_auth/password/digest_pw_auth.c Thu Feb 6 08:44:37 2003 *************** *** 73,85 **** } static void ! read_passwd_file(const char *passwdfile) { FILE *f; char buf[8192]; user_data *u; char *user; char *passwd; if (hash != NULL) { hashFreeItems(hash, my_free); } --- 73,87 ---- } static void ! read_passwd_file(const char *passwdfile, int ha1mode) { FILE *f; char buf[8192]; user_data *u; char *user; char *passwd; + int passwdha1; + if (hash != NULL) { hashFreeItems(hash, my_free); } *************** *** 97,106 **** user = strtok(buf, ":\n"); passwd = strtok(NULL, ":\n"); if ((strlen(user) > 0) && passwd) { ! u = xmalloc(sizeof(*u)); ! u->user = xstrdup(user); ! u->passwd = xstrdup(passwd); ! hash_join(hash, (hash_link *) u); } } fclose(f); --- 99,117 ---- user = strtok(buf, ":\n"); passwd = strtok(NULL, ":\n"); if ((strlen(user) > 0) && passwd) { ! passwdha1 = (strncmp("{HHA1}", passwd, 6))?0:1; ! if(passwdha1 == ha1mode) { ! u = xmalloc(sizeof(*u)); ! u->user = xstrdup(user); ! u->passwd = xstrdup(passwd); ! hash_join(hash, (hash_link *) u); ! } else { ! /* We cannot accept passwords of the wrong format, as plaintext ! * may be passwd back to squid, which may output them to ! * cache.log if debugging is turned on */ ! fprintf(stderr, "digest_pw_auth: ignoring %s password for %s\n", ! (passwdha1)?"HHA1":"plaintext", user); ! } } } fclose(f); *************** *** 112,127 **** struct stat sb; time_t change_time = 0; char buf[256]; ! char *user, *realm, *p; user_data *u; HASH HA1; HASHHEX HHA1; setbuf(stdout, NULL); ! if (argc != 2) { ! fprintf(stderr, "Usage: digest_pw_auth \n"); exit(1); } ! if (stat(argv[1], &sb) != 0) { fprintf(stderr, "cannot stat %s\n", argv[1]); exit(1); } --- 123,148 ---- struct stat sb; time_t change_time = 0; char buf[256]; ! char *user, *realm, *p, *passwdfile=NULL; user_data *u; HASH HA1; HASHHEX HHA1; + int ha1mode=0; + setbuf(stdout, NULL); ! if(argc == 2){ ! passwdfile = argv[1]; ! } ! if((argc == 3) && !strcmp("-c", argv[1])){ ! ha1mode=1; ! passwdfile = argv[2]; ! } ! if (!passwdfile) { ! fprintf(stderr, "Usage: digest_pw_auth [OPTIONS] \n"); ! fprintf(stderr, " -c accept HHA1 passwords rather than plaintext in passwordfile\n"); exit(1); } ! if (stat(passwdfile, &sb) != 0) { fprintf(stderr, "cannot stat %s\n", argv[1]); exit(1); } *************** *** 130,136 **** *p = '\0'; /* strip \n */ if (stat(argv[1], &sb) == 0) { if (sb.st_mtime != change_time) { ! read_passwd_file(argv[1]); change_time = sb.st_mtime; } } --- 151,157 ---- *p = '\0'; /* strip \n */ if (stat(argv[1], &sb) == 0) { if (sb.st_mtime != change_time) { ! read_passwd_file(passwdfile, ha1mode); change_time = sb.st_mtime; } } *************** *** 150,157 **** if (u == NULL) { printf("ERR\n"); } else { ! DigestCalcHA1("md5", user, realm, u->passwd, NULL, NULL, HA1, HHA1); ! printf("%s\n", HHA1); } } exit(0); --- 171,187 ---- if (u == NULL) { printf("ERR\n"); } else { ! ! if(! ha1mode ) ! { ! DigestCalcHA1("md5", user, realm, u->passwd, NULL, NULL, HA1, HHA1); ! printf("%s\n", HHA1); ! /* fprintf(stderr, "digest_pw_auth: %s:{HHA1}%s\n", user, HHA1); */ ! } ! else ! { ! printf("%s\n", &u->passwd[6]); ! } } } exit(0);