Browse code

- HA1 wasn't calculated properly if username contained domain and calc_ha1 was set, fixed.

Jan Janak authored on 10/09/2003 14:38:54
Showing 1 changed files
... ...
@@ -47,7 +47,7 @@
47 47
 #define MESSAGE_500 "Server Internal Error"
48 48
 
49 49
 
50
-static inline int get_ha1(str* _user, str* _domain, int use_ha1b, char* _table, char* _ha1)
50
+static inline int get_ha1(struct username* _username, str* _domain, char* _table, char* _ha1)
51 51
 {
52 52
 	db_key_t keys[2];
53 53
 	db_val_t vals[2];
... ...
@@ -57,13 +57,13 @@ static inline int get_ha1(str* _user, str* _domain, int use_ha1b, char* _table,
57 57
 
58 58
 	keys[0] = user_column;
59 59
 	keys[1] = domain_column;
60
-	col[0] = (use_ha1b && !calc_ha1) ? (pass_column_2) : (pass_column);	
60
+	col[0] = (_username->domain.len && !calc_ha1) ? (pass_column_2) : (pass_column);	
61 61
 
62 62
 	VAL_TYPE(vals) = VAL_TYPE(vals + 1) = DB_STR;
63 63
 	VAL_NULL(vals) = VAL_NULL(vals + 1) = 0;
64 64
 	
65
-	VAL_STR(vals).s = _user->s;
66
-	VAL_STR(vals).len = _user->len;
65
+	VAL_STR(vals).s = _username->user.s;
66
+	VAL_STR(vals).len = _username->user.len;
67 67
 
68 68
 	VAL_STR(vals + 1).s = _domain->s;
69 69
 	VAL_STR(vals + 1).len = _domain->len;
... ...
@@ -76,7 +76,7 @@ static inline int get_ha1(str* _user, str* _domain, int use_ha1b, char* _table,
76 76
 
77 77
 	if (RES_ROW_N(res) == 0) {
78 78
 		DBG("get_ha1(): no result for user \'%.*s@%.*s\'\n", 
79
-		    _user->len, ZSW(_user->s), (use_domain ? (_domain->len) : 0), ZSW(_domain->s));
79
+		    _username->user.len, ZSW(_username->user.s), (use_domain ? (_domain->len) : 0), ZSW(_domain->s));
80 80
 		db_free_query(db_handle, res);
81 81
 		return 1;
82 82
 	}
... ...
@@ -87,7 +87,7 @@ static inline int get_ha1(str* _user, str* _domain, int use_ha1b, char* _table,
87 87
 	if (calc_ha1) {
88 88
 		     /* Only plaintext passwords are stored in database,
89 89
 		      * we have to calculate HA1 */
90
-		calc_HA1(HA_MD5, _user, _domain, &result, 0, 0, _ha1);
90
+		calc_HA1(HA_MD5, &_username->whole, _domain, &result, 0, 0, _ha1);
91 91
 		DBG("HA1 string calculated: %s\n", _ha1);
92 92
 	} else {
93 93
 		memcpy(_ha1, result.s, result.len);
... ...
@@ -166,7 +166,7 @@ static inline int authorize(struct sip_msg* _m, str* _realm, char* _table, int _
166 166
 
167 167
 	cred = (auth_body_t*)h->parsed;
168 168
 
169
-	res = get_ha1(&cred->digest.username.user, &domain, cred->digest.username.domain.len, _table, ha1);
169
+	res = get_ha1(&cred->digest.username, &domain, _table, ha1);
170 170
         if (res < 0) {
171 171
 		     /* Error while accessing the database */
172 172
 		if (sl_reply(_m, (char*)500, MESSAGE_500) == -1) {