Browse code

- small rpid fix

Jan Janak authored on 05/11/2003 03:49:32
Showing 2 changed files
... ...
@@ -47,7 +47,11 @@
47 47
 #define MESSAGE_500 "Server Internal Error"
48 48
 
49 49
 
50
-static inline int get_ha1(struct username* _username, str* _domain, char* _table, char* _ha1, char* _rpid)
50
+static char rpid_buffer[MAX_RPID_LEN];
51
+static str rpid = {rpid_buffer, 0};
52
+
53
+
54
+static inline int get_ha1(struct username* _username, str* _domain, char* _table, char* _ha1, str* _rpid)
51 55
 {
52 56
 	db_key_t keys[2];
53 57
 	db_val_t vals[2];
... ...
@@ -98,12 +102,10 @@ static inline int get_ha1(struct username* _username, str* _domain, char* _table
98 102
 		_ha1[result.len] = '\0';
99 103
 	}
100 104
 
101
-	if (use_rpid && VAL_NULL(&(res->rows[0].values[1])) != 1) {
105
+	if (use_rpid && (VAL_NULL(&(res->rows[0].values[1])) == 0)) {
102 106
 		result.s = (char*)VAL_STRING(&(res->rows[0].values[1]));
103
-		result.len = strlen(result.s);
104
-		memcpy(_rpid, result.s, result.len);
105
-		_rpid[result.len] = '\0';
106
-		DBG("RPID: %s\n", _rpid);
107
+		_rpid->len = strlen(result.s);
108
+		memcpy(_rpid->s, result.s, _rpid->len);
107 109
 	}
108 110
 
109 111
 	db_free_query(db_handle, res);
... ...
@@ -158,12 +160,11 @@ static inline int check_response(dig_cred_t* _cred, str* _method, char* _ha1)
158 160
 static inline int authorize(struct sip_msg* _m, str* _realm, char* _table, int _hftype)
159 161
 {
160 162
 	char ha1[256];
161
-	char rpid_buffer[MAX_RPID_LEN];
162 163
 	int res;
163 164
 	struct hdr_field* h;
164 165
 	auth_body_t* cred;
165 166
 	auth_result_t ret;
166
-	str domain, rpid;
167
+	str domain;
167 168
 
168 169
 	domain = *_realm;
169 170
 
... ...
@@ -178,7 +179,10 @@ static inline int authorize(struct sip_msg* _m, str* _realm, char* _table, int _
178 179
 
179 180
 	cred = (auth_body_t*)h->parsed;
180 181
 
181
-	res = get_ha1(&cred->digest.username, &domain, _table, ha1, rpid_buffer);
182
+	     /* Clear the rpid buffer from previous value*/
183
+	rpid.len = 0;
184
+
185
+	res = get_ha1(&cred->digest.username, &domain, _table, ha1, &rpid);
182 186
         if (res < 0) {
183 187
 		     /* Error while accessing the database */
184 188
 		if (sl_reply(_m, (char*)500, MESSAGE_500) == -1) {
... ...
@@ -190,14 +194,6 @@ static inline int authorize(struct sip_msg* _m, str* _realm, char* _table, int _
190 194
 		return -1;
191 195
 	}
192 196
 
193
-	if (use_rpid) {
194
-		rpid.s = rpid_buffer;
195
-		rpid.len = strlen(rpid_buffer);
196
-	} else {
197
-		rpid.s = NULL;
198
-		rpid.len = 0;
199
-	}
200
-
201 197
 	     /* Recalculate response, it must be same to authorize sucessfully */
202 198
         if (!check_response(&(cred->digest), &_m->first_line.u.request.method, ha1)) {
203 199
 		ret = post_auth_func(_m, h, &rpid);
... ...
@@ -53,6 +53,7 @@
53 53
  * Buffer to store rpid retrieved from the radius server
54 54
  */
55 55
 static char rpid_buffer[MAX_RPID_LEN];
56
+static str rpid = {rpid_buffer, 0};
56 57
 
57 58
 
58 59
 /* 
... ...
@@ -86,7 +87,7 @@ static inline int authorize(struct sip_msg* _msg, str* _realm, int _hftype)
86 87
 	auth_result_t ret;
87 88
 	struct hdr_field* h;
88 89
 	auth_body_t* cred;
89
-	str* uri, rpid;
90
+	str* uri;
90 91
 	struct sip_uri puri;
91 92
 	str user, domain;
92 93
 
... ...
@@ -124,7 +125,7 @@ static inline int authorize(struct sip_msg* _msg, str* _realm, int _hftype)
124 125
 	user.s = (char *)pkg_malloc(puri.user.len);
125 126
 	un_escape(&(puri.user), &user);
126 127
 
127
-	rpid.s = rpid_buffer;
128
+	     /* Clear the rpid buffer from previous value */
128 129
 	rpid.len = 0;
129 130
 
130 131
 	res = radius_authorize_sterman(&cred->digest, &_msg->first_line.u.request.method, &user, &rpid);