72 if (
hash !=
nullptr) {
77 if (
nullptr ==
hash) {
78 fprintf(stderr,
"digest_file_auth: cannot create hash table\n");
81 FILE *f = fopen(passwordFile,
"r");
84 fprintf(stderr,
"digest_file_auth: cannot open password file: %s\n",
xstrerr(xerrno));
87 unsigned int lineCount = 0;
88 while (fgets(buf,
sizeof(buf), f) !=
nullptr) {
90 if ((buf[0] ==
'#') || (buf[0] ==
' ') || (buf[0] ==
'\t') ||
93 user = strtok(buf,
":\n");
95 fprintf(stderr,
"digest_file_auth: missing user name at line %u in '%s'\n", lineCount, passwordFile);
98 realm = strtok(
nullptr,
":\n");
99 passwd = strtok(
nullptr,
":\n");
104 if ((strlen(user) > 0) && passwd) {
105 if (strncmp(passwd,
"{HHA1}", 6) == 0) {
108 }
else if (isHa1Mode) {
112 if (ha1 && strlen(ha1) != 32) {
116 fprintf(stderr,
"digest_file_auth: ignoring invalid password for %s\n", user);
121 int len = strlen(user) + strlen(realm) + 2;
123 snprintf(
static_cast<char*
>(u->
hash.
key), len,
"%s:%s", user, realm);
144 if ((argc == 3) && !strcmp(
"-c", argv[1])) {
149 fprintf(stderr,
"Usage: digest_file_auth [OPTIONS] <passwordfile>\n");
150 fprintf(stderr,
" -c accept digest hashed passwords rather than plaintext in passwordfile\n");
154 fprintf(stderr,
"cannot stat %s\n",
passwdfile);
174 len = snprintf(buf,
sizeof(buf),
"%s:%s", requestData->
user, requestData->
realm);
175 if (len >=
static_cast<int>(
sizeof(buf)))
189 requestData->
error = -1;
SQUIDCEXTERN hash_table * hash_create(HASHCMP *, int, HASHHASH *)
SQUIDCEXTERN void hashFreeItems(hash_table *, HASHFREE *)
SQUIDCEXTERN void hash_join(hash_table *, hash_link *)
int HASHCMP(const void *, const void *)
SQUIDCEXTERN HASHHASH hash_string
SQUIDCEXTERN hash_link * hash_lookup(hash_table *, const void *)
void DigestCalcHA1(const char *pszAlg, const char *pszUserName, const char *pszRealm, const char *pszPassword, const char *pszNonce, const char *pszCNonce, HASH HA1, HASHHEX SessionKey)
void TextArguments(int argc, char **argv)
void TextHHA1(RequestData *requestData)
static void read_passwd_file(const char *passwordFile, int isHa1Mode)
static time_t change_time
static const user_data * GetPassword(RequestData *requestData)
struct _user_data user_data
void * xcalloc(size_t n, size_t sz)
const char * xstrerr(int error)
char * xstrncpy(char *dst, const char *src, size_t n)