Kaynağa Gözat

auth_db(k): close db handle only for second param fixup

- digest_authenticate() refurbished to accept clear text values for
  realm and table
Daniel-Constantin Mierla 15 yıl önce
ebeveyn
işleme
c70565c3aa
2 değiştirilmiş dosya ile 53 ekleme ve 30 silme
  1. 1 1
      modules_k/auth_db/authdb_mod.c
  2. 52 29
      modules_k/auth_db/authorize.c

+ 1 - 1
modules_k/auth_db/authdb_mod.c

@@ -253,7 +253,7 @@ static int auth_fixup(void** param, int param_no)
 			auth_dbf.close(dbh);
 			return -1;
 		}
+		auth_dbf.close(dbh);
 	}
-	auth_dbf.close(dbh);
 	return 0;
 }

+ 52 - 29
modules_k/auth_db/authorize.c

@@ -204,41 +204,20 @@ static int generate_avps(db1_res_t* result)
 /*
  * Authorize digest credentials
  */
-static inline int digest_authenticate(struct sip_msg* msg, fparam_t* realm,
-									char* tname, hdr_types_t hftype)
+static int digest_authenticate(struct sip_msg* msg, str *realm,
+				str *table, hdr_types_t hftype)
 {
 	char ha1[256];
 	int res;
 	struct hdr_field* h;
 	auth_body_t* cred;
-	str domain, table;
 	db1_res_t* result = NULL;
 	int ret;
 
 	cred = 0;
 	ret = AUTH_ERROR;
 
-	if(!tname) {
-		LM_ERR("invalid table parameter\n");
-		return AUTH_ERROR;
-	}
-
-	table.s = tname;
-	table.len = strlen(tname);
-
-	if (get_str_fparam(&domain, msg, realm) < 0) {
-		LM_ERR("failed to get realm value\n");
-		goto end;
-	}
-
-	if (domain.len==0)
-	{
-		LM_ERR("invalid realm parameter - empty value\n");
-		goto end;
-	}
-	LM_DBG("realm value [%.*s]\n", domain.len, domain.s);
-
-	ret = auth_api.pre_auth(msg, &domain, hftype, &h, NULL);
+	ret = auth_api.pre_auth(msg, realm, hftype, &h, NULL);
 	switch(ret) {
 		case ERROR:
 		case BAD_CREDENTIALS:
@@ -266,7 +245,7 @@ static inline int digest_authenticate(struct sip_msg* msg, fparam_t* realm,
 
 	cred = (auth_body_t*)h->parsed;
 
-	res = get_ha1(&cred->digest.username, &domain, &table, ha1, &result);
+	res = get_ha1(&cred->digest.username, realm, table, ha1, &result);
 	if (res < 0) {
 		/* Error while accessing the database */
 		ret = AUTH_ERROR;
@@ -310,8 +289,30 @@ end:
  */
 int proxy_authenticate(struct sip_msg* _m, char* _realm, char* _table)
 {
-	return digest_authenticate(_m, (fparam_t*)_realm, _table,
-			HDR_PROXYAUTH_T);
+	str srealm;
+	str stable;
+
+	if(_table==NULL) {
+		LM_ERR("invalid table parameter\n");
+		return AUTH_ERROR;
+	}
+
+	stable.s   = _table;
+	stable.len = strlen(stable.s);
+
+	if (get_str_fparam(&srealm, _m, (fparam_t*)_realm) < 0) {
+		LM_ERR("failed to get realm value\n");
+		return AUTH_ERROR;
+	}
+
+	if (srealm.len==0)
+	{
+		LM_ERR("invalid realm parameter - empty value\n");
+		return AUTH_ERROR;
+	}
+	LM_DBG("realm value [%.*s]\n", srealm.len, srealm.s);
+
+	return digest_authenticate(_m, &srealm, &stable, HDR_PROXYAUTH_T);
 }
 
 
@@ -320,6 +321,28 @@ int proxy_authenticate(struct sip_msg* _m, char* _realm, char* _table)
  */
 int www_authenticate(struct sip_msg* _m, char* _realm, char* _table)
 {
-	return digest_authenticate(_m, (fparam_t*)_realm, _table,
-			HDR_AUTHORIZATION_T);
+	str srealm;
+	str stable;
+
+	if(_table==NULL) {
+		LM_ERR("invalid table parameter\n");
+		return AUTH_ERROR;
+	}
+
+	stable.s   = _table;
+	stable.len = strlen(stable.s);
+
+	if (get_str_fparam(&srealm, _m, (fparam_t*)_realm) < 0) {
+		LM_ERR("failed to get realm value\n");
+		return AUTH_ERROR;
+	}
+
+	if (srealm.len==0)
+	{
+		LM_ERR("invalid realm parameter - empty value\n");
+		return AUTH_ERROR;
+	}
+	LM_DBG("realm value [%.*s]\n", srealm.len, srealm.s);
+
+	return digest_authenticate(_m, &srealm, &stable, HDR_AUTHORIZATION_T);
 }