66
66
if (hash != NULL) {
67
hashFreeItems(hash, my_free);
67
hashFreeItems(hash, my_free);
69
69
/* initial setup */
70
70
hash = hash_create((HASHCMP *) strcmp, 7921, hash_string);
71
71
if (NULL == hash) {
72
fprintf(stderr, "digest_pw_auth: cannot create hash table\n");
72
fprintf(stderr, "digest_pw_auth: cannot create hash table\n");
75
f = fopen(passwdfile, "r");
75
f = fopen(passwordFile, "r");
76
76
while (fgets(buf, 8192, f) != NULL) {
77
if ((buf[0] == '#') || (buf[0] == ' ') || (buf[0] == '\t') ||
80
user = strtok(buf, ":\n");
81
realm = strtok(NULL, ":\n");
82
passwd = strtok(NULL, ":\n");
87
if ((strlen(user) > 0) && passwd) {
88
if (strncmp(passwd, "{HHA1}", 6) == 0) {
95
if (ha1 && strlen(ha1) != 32) {
96
/* We cannot accept plaintext passwords when using HA1 encoding,
97
* as the passwords may be output to cache.log if debugging is on.
99
fprintf(stderr, "digest_pw_auth: ignoring invalid password for %s\n", user);
102
u = xcalloc(1, sizeof(*u));
104
int len = strlen(user) + strlen(realm) + 2;
105
u->hash.key = malloc(len);
106
snprintf(u->hash.key, len, "%s:%s", user, realm);
108
u->hash.key = xstrdup(user);
111
u->ha1 = xstrdup(ha1);
113
u->passwd = xstrdup(passwd);
114
hash_join(hash, &u->hash);
77
if ((buf[0] == '#') || (buf[0] == ' ') || (buf[0] == '\t') ||
80
user = strtok(buf, ":\n");
81
realm = strtok(NULL, ":\n");
82
passwd = strtok(NULL, ":\n");
87
if ((strlen(user) > 0) && passwd) {
88
if (strncmp(passwd, "{HHA1}", 6) == 0) {
91
} else if (isHa1Mode) {
95
if (ha1 && strlen(ha1) != 32) {
96
/* We cannot accept plaintext passwords when using HA1 encoding,
97
* as the passwords may be output to cache.log if debugging is on.
99
fprintf(stderr, "digest_pw_auth: ignoring invalid password for %s\n", user);
102
u = xcalloc(1, sizeof(*u));
104
int len = strlen(user) + strlen(realm) + 2;
105
u->hash.key = malloc(len);
106
snprintf(u->hash.key, len, "%s:%s", user, realm);
108
u->hash.key = xstrdup(user);
111
u->ha1 = xstrdup(ha1);
113
u->passwd = xstrdup(passwd);
114
hash_join(hash, &u->hash);
126
passwdfile = argv[1];
126
passwdfile = argv[1];
127
127
if ((argc == 3) && !strcmp("-c", argv[1])) {
129
passwdfile = argv[2];
129
passwdfile = argv[2];
131
131
if (!passwdfile) {
132
fprintf(stderr, "Usage: digest_pw_auth [OPTIONS] <passwordfile>\n");
133
fprintf(stderr, " -c accept digest hashed passwords rather than plaintext in passwordfile\n");
132
fprintf(stderr, "Usage: digest_pw_auth [OPTIONS] <passwordfile>\n");
133
fprintf(stderr, " -c accept digest hashed passwords rather than plaintext in passwordfile\n");
136
136
if (stat(passwdfile, &sb) != 0) {
137
fprintf(stderr, "cannot stat %s\n", passwdfile);
137
fprintf(stderr, "cannot stat %s\n", passwdfile);
149
149
if (stat(passwdfile, &sb) == 0) {
150
if (sb.st_mtime != change_time) {
151
read_passwd_file(passwdfile, ha1mode);
152
change_time = sb.st_mtime;
150
if (sb.st_mtime != change_time) {
151
read_passwd_file(passwdfile, ha1mode);
152
change_time = sb.st_mtime;
157
157
len = snprintf(buf, sizeof(buf), "%s:%s", requestData->user, requestData->realm);
158
158
if (len >= sizeof(buf))
160
160
u = (user_data *) hash_lookup(hash, buf);
163
163
u = (user_data *) hash_lookup(hash, requestData->user);
170
170
const user_data *u = GetPassword(requestData);
172
requestData->error = -1;
172
requestData->error = -1;
176
xstrncpy(requestData->HHA1, u->ha1, sizeof(requestData->HHA1));
176
xstrncpy(requestData->HHA1, u->ha1, sizeof(requestData->HHA1));
179
DigestCalcHA1("md5", requestData->user, requestData->realm, u->passwd, NULL, NULL, HA1, requestData->HHA1);
179
DigestCalcHA1("md5", requestData->user, requestData->realm, u->passwd, NULL, NULL, HA1, requestData->HHA1);