73 if (
hash !=
nullptr) {
80 if (
nullptr ==
hash) {
81 fprintf(stderr,
"digest_file_auth: cannot create hash table\n");
84 FILE *f = fopen(passwordFile,
"r");
87 fprintf(stderr,
"digest_file_auth: cannot open password file: %s\n",
xstrerr(xerrno));
90 unsigned int lineCount = 0;
91 while (fgets(buf,
sizeof(buf), f) !=
nullptr) {
94 if ((buf[0] ==
'#') || (buf[0] ==
' ') || (buf[0] ==
'\t') ||
97 user = strtok(buf,
":\n");
99 fprintf(stderr,
"digest_file_auth: missing user name at line %u in '%s'\n", lineCount, passwordFile);
102 realm = strtok(
nullptr,
":\n");
103 passwd = strtok(
nullptr,
":\n");
108 if ((strlen(user) > 0) && passwd) {
109 if (strncmp(passwd,
"{HHA1}", 6) == 0) {
112 }
else if (isHa1Mode) {
116 if (ha1 && strlen(ha1) != 32) {
120 fprintf(stderr,
"digest_file_auth: ignoring invalid password for %s\n", user);
125 int len = strlen(user) + strlen(realm) + 2;
127 snprintf(
static_cast<char*
>(u->
hash.
key), len,
"%s:%s", user, realm);
148 if ((argc == 3) && !strcmp(
"-c", argv[1])) {
153 fprintf(stderr,
"Usage: digest_file_auth [OPTIONS] <passwordfile>\n");
154 fprintf(stderr,
" -c accept digest hashed passwords rather than plaintext in passwordfile\n");
158 fprintf(stderr,
"cannot stat %s\n",
passwdfile);
178 len = snprintf(buf,
sizeof(buf),
"%s:%s", requestData->
user, requestData->
realm);
179 if (len >=
static_cast<int>(
sizeof(buf)))
193 requestData->
error = -1;
void hashFreeMemory(hash_table *)
void hashFreeItems(hash_table *, HASHFREE *)
hash_link * hash_lookup(hash_table *, const void *)
hash_table * hash_create(HASHCMP *, int, HASHHASH *)
int HASHCMP(const void *, const void *)
void hash_join(hash_table *, hash_link *)
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)