Selaa lähdekoodia

Merge branch 'master' of https://github.com/kamailio/kamailio

# By Ovidiu Sas
# Via Ovidiu Sas
* 'master' of https://github.com/kamailio/kamailio:
  auth: harmonize logs - use LM_* macro
The Root 9 vuotta sitten
vanhempi
commit
ea3dd0acf1
6 muutettua tiedostoa jossa 47 lisäystä ja 51 poistoa
  1. 16 16
      modules/auth/auth_mod.c
  2. 7 10
      modules/auth/challenge.c
  3. 10 10
      modules/auth/nc.c
  4. 3 3
      modules/auth/nid.c
  5. 1 2
      modules/auth/nonce.c
  6. 10 10
      modules/auth/ot_nonce.c

+ 16 - 16
modules/auth/auth_mod.c

@@ -238,7 +238,7 @@ static inline int generate_random_secret(void)
 	sec_rand1 = (char*)pkg_malloc(RAND_SECRET_LEN);
 	sec_rand2 = (char*)pkg_malloc(RAND_SECRET_LEN);
 	if (!sec_rand1 || !sec_rand2) {
-		LOG(L_ERR, "auth:generate_random_secret: No memory left\n");
+		LM_ERR("No memory left\n");
 		if (sec_rand1){
 			pkg_free(sec_rand1);
 			sec_rand1=0;
@@ -286,7 +286,7 @@ static int mod_init(void)
 	if (sec_param == 0) {
 		/* Generate secret using random generator */
 		if (generate_random_secret() < 0) {
-			LOG(L_ERR, "auth:mod_init: Error while generating random secret\n");
+			LM_ERR("Error while generating random secret\n");
 			return -3;
 		}
 	} else {
@@ -301,7 +301,7 @@ static int mod_init(void)
 			secret1.len -= secret2.len;
 			secret2.s = secret1.s + secret1.len;
 			if (secret2.len < 16) {
-				WARN("auth: consider a longer secret when extra auth checks are"
+				LM_WARN("consider a longer secret when extra auth checks are"
 						" enabled (the config secret is divided in 2!)\n");
 			}
 		}
@@ -309,7 +309,7 @@ static int mod_init(void)
 
 	if ((!challenge_attr.s || challenge_attr.len == 0) ||
 			challenge_attr.s[0] != '$') {
-		ERR("auth: Invalid value of challenge_attr module parameter\n");
+		LM_ERR("Invalid value of challenge_attr module parameter\n");
 		return -1;
 	}
 
@@ -317,7 +317,7 @@ static int mod_init(void)
 	attr.len = challenge_attr.len - 1;
 
 	if (parse_avp_ident(&attr, &challenge_avpid) < 0) {
-		ERR("auth: Error while parsing value of challenge_attr module"
+		LM_ERR("Error while parsing value of challenge_attr module"
 				" parameter\n");
 		return -1;
 	}
@@ -325,13 +325,13 @@ static int mod_init(void)
 	parse_qop(&auth_qop);
 	switch(auth_qop.qop_parsed){
 		case QOP_OTHER:
-			ERR("auth: Unsupported qop parameter value\n");
+			LM_ERR("Unsupported qop parameter value\n");
 			return -1;
 		case QOP_AUTH:
 		case QOP_AUTHINT:
 			if (nc_enabled){
 #ifndef USE_NC
-				WARN("auth: nounce count support enabled from config, but"
+				LM_WARN("nounce count support enabled from config, but"
 						" disabled at compile time (recompile with -DUSE_NC)\n");
 				nc_enabled=0;
 #else
@@ -343,14 +343,14 @@ static int mod_init(void)
 			}
 #ifdef USE_NC
 			else{
-				INFO("auth: qop set, but nonce-count (nc_enabled) support"
+				LM_INFO("qop set, but nonce-count (nc_enabled) support"
 						" disabled\n");
 			}
 #endif
 			break;
 		default:
 			if (nc_enabled){
-				WARN("auth: nonce-count support enabled, but qop not set\n");
+				LM_WARN("nonce-count support enabled, but qop not set\n");
 				nc_enabled=0;
 			}
 			break;
@@ -361,7 +361,7 @@ static int mod_init(void)
 		if (init_ot_nonce()!=0)
 			return -1;
 #else
-		WARN("auth: one-time-nonce support enabled from config, but "
+		LM_WARN("one-time-nonce support enabled from config, but "
 				"disabled at compile time (recompile with -DUSE_OT_NONCE)\n");
 		otn_enabled=0;
 #endif /* USE_OT_NONCE */
@@ -378,7 +378,8 @@ static int mod_init(void)
 		calc_response = calc_response_sha256;
 	}
 	else {
-		ERR("auth: Invalid algorithm provided. Possible values are \"\", \"MD5\" or \"SHA-256\"\n");
+		LM_ERR("Invalid algorithm provided."
+				" Possible values are \"\", \"MD5\" or \"SHA-256\"\n");
 		return -1;
 	}
 
@@ -417,8 +418,7 @@ int consume_credentials(struct sip_msg* msg)
 	if (!h) {
 		get_authorized_cred(msg->proxy_auth, &h);
 		if (!h) {
-			LOG(L_ERR, "auth:consume_credentials: No authorized "
-					"credentials found (error in scripts)\n");
+			LM_ERR("No authorized credentials found (error in scripts)\n");
 			return -1;
 		}
 	}
@@ -426,7 +426,7 @@ int consume_credentials(struct sip_msg* msg)
 	len = h->len;
 
 	if (del_lump(msg, h->name.s - msg->buf, len, 0) == 0) {
-		LOG(L_ERR, "auth:consume_credentials: Can't remove credentials\n");
+		LM_ERR("Can't remove credentials\n");
 		return -1;
 	}
 
@@ -567,7 +567,7 @@ end:
 		}
 		if (get_challenge_hf(msg, (cred ? cred->stale : 0),
 					realm, NULL, (auth_algorithm.len ? &auth_algorithm : NULL), qop, hftype, &hf) < 0) {
-			ERR("Error while creating challenge\n");
+			LM_ERR("Error while creating challenge\n");
 			ret = AUTH_ERROR;
 		} else {
 			val.s = hf;
@@ -933,7 +933,7 @@ int auth_challenge_helper(struct sip_msg *msg, str *realm, int flags, int hftype
 	}
 	if (get_challenge_hf(msg, stale, realm, NULL, (auth_algorithm.len ? &auth_algorithm : NULL), qop, hftype, &hf)
 			< 0) {
-		ERR("Error while creating challenge\n");
+		LM_ERR("Error while creating challenge\n");
 		ret = -2;
 		goto error;
 	}

+ 7 - 10
modules/auth/challenge.c

@@ -162,18 +162,16 @@ int get_challenge_hf(struct sip_msg* msg, int stale, str* realm,
 
 	strip_realm(realm);
 	if (realm) {
-		DEBUG("build_challenge_hf: realm='%.*s'\n", realm->len, realm->s);
+		LM_DBG("realm='%.*s'\n", realm->len, realm->s);
 	}
 	if (nonce) {
-		DEBUG("build_challenge_hf: nonce='%.*s'\n", nonce->len, nonce->s);
+		LM_DBG("nonce='%.*s'\n", nonce->len, nonce->s);
 	}
 	if (algorithm) {
-		DEBUG("build_challenge_hf: algorithm='%.*s'\n", algorithm->len,
-				algorithm->s);
+		LM_DBG("algorithm='%.*s'\n", algorithm->len, algorithm->s);
 	}
 	if (qop && qop->qop_parsed != QOP_UNSPEC) {
-		DEBUG("build_challenge_hf: qop='%.*s'\n", qop->qop_str.len,
-				qop->qop_str.s);
+		LM_DBG("qop='%.*s'\n", qop->qop_str.len, qop->qop_str.s);
 	}
 
 	if (hftype == HDR_PROXYAUTH_T) {
@@ -220,7 +218,7 @@ int get_challenge_hf(struct sip_msg* msg, int stale, str* realm,
 	hf.len += CRLF_LEN;
 	p = hf.s = pkg_malloc(hf.len);
 	if (!hf.s) {
-		ERR("auth: No memory left (%d bytes)\n", hf.len);
+		LM_ERR("No memory left (%d bytes)\n", hf.len);
 		return -1;
 	}
 
@@ -239,8 +237,7 @@ int get_challenge_hf(struct sip_msg* msg, int stale, str* realm,
 		l=nonce_len;
 		if (calc_new_nonce(p, &l, cfg, msg) != 0)
 		{
-			ERR("auth: calc_nonce failed (len %d, needed %d)\n",
-					nonce_len, l);
+			LM_ERR("calc_nonce failed (len %d, needed %d)\n", nonce_len, l);
 			pkg_free(hf.s);
 			return -1;
 		}
@@ -308,7 +305,7 @@ int build_challenge_hf(struct sip_msg* msg, int stale, str* realm,
 	val.s = hf;
 	if(add_avp(challenge_avpid.flags | AVP_VAL_STR, challenge_avpid.name, val)
 			< 0) {
-		ERR("auth: Error while creating attribute with challenge\n");
+		LM_ERR("Error while creating attribute with challenge\n");
 		pkg_free(hf.s);
 		return -1;
 	}

+ 10 - 10
modules/auth/nc.c

@@ -70,36 +70,36 @@ int init_nonce_count()
 	}
 	size=1UL<<nc_array_k; /* ROUNDDOWN to 2^nc_array_k */
 	if (size < MIN_NC_ARRAY_SIZE){
-		WARN("auth: nonce-count in.flight nonces is very low (%d),"
+		LM_WARN("nonce-count in.flight nonces is very low (%d),"
 				" consider increasing nc_array_size to at least %d\n",
 				orig_array_size, MIN_NC_ARRAY_SIZE);
 	}
 	if (size > MAX_NC_ARRAY_SIZE){
-		WARN("auth: nonce-count in flight nonces is too high (%d),"
+		LM_WARN("nonce-count in flight nonces is too high (%d),"
 				" consider decreasing nc_array_size to at least %d\n",
 				orig_array_size, MAX_NC_ARRAY_SIZE);
 	}
 	if (size!=nc_array_size){
 		if (orig_array_size!=0)
-			INFO("auth: nc_array_size rounded down to %ld\n", size);
+			LM_INFO("nc_array_size rounded down to %ld\n", size);
 		else
-			INFO("auth: nc_array_size set to %ld\n", size);
+			LM_INFO("nc_array_size set to %ld\n", size);
 	}
 	max_mem=shm_available();
 	if (size*sizeof(nc_t) >= max_mem){
-		ERR("auth: nc_array_size (%ld) is too big for the configured "
+		LM_ERR("nc_array_size (%ld) is too big for the configured "
 				"amount of shared memory (%ld bytes <= %ld bytes)\n",
 				size, max_mem, size*sizeof(nc_t));
 		return -1;
 	}else if (size*sizeof(nc_t) >= max_mem/2){
-		WARN("auth: the currently configured nc_array_size (%ld)  "
+		LM_WARN("the currently configured nc_array_size (%ld)  "
 				"would use more then 50%% of the available shared"
 				" memory(%ld bytes)\n", size, max_mem);
 	}
 	nc_array_size=size;
 
 	if (nid_pool_no>=nc_array_size){
-		ERR("auth: nid_pool_no (%d) too high for the configured "
+		LM_ERR("nid_pool_no (%d) too high for the configured "
 				"nc_array_size (%d)\n", nid_pool_no, nc_array_size);
 		return -1;
 	}
@@ -110,12 +110,12 @@ int init_nonce_count()
 	assert(1<<(nc_partition_k+nid_pool_k) == nc_array_size);
 
 	if ((nid_t)nc_partition_size >= ((nid_t)(-1)/NID_INC)){
-		ERR("auth: nc_array_size too big, try decreasing it or increasing"
+		LM_ERR("nc_array_size too big, try decreasing it or increasing"
 				"the number of pools/partitions\n");
 		return -1;
 	}
 	if (nc_partition_size  < MIN_NC_ARRAY_PARTITION){
-		WARN("auth: nonce-count in-flight nonces very low,"
+		LM_WARN("nonce-count in-flight nonces very low,"
 				" consider either decreasing nc_pool_no (%d) or "
 				" increasing nc_array_size (%d) such that "
 				"nc_array_size/nid_pool_no >= %d\n",
@@ -126,7 +126,7 @@ int init_nonce_count()
 	 *  access it as an uint array */
 	nc_array=shm_malloc(sizeof(nc_t)*ROUND_INT(nc_array_size));
 	if (nc_array==0){
-		ERR("auth: init_nonce_count: memory allocation failure, consider"
+		LM_ERR("init_nonce_count: memory allocation failure, consider"
 				" either decreasing nc_array_size of increasing the"
 				" the shared memory amount\n");
 		goto error;

+ 3 - 3
modules/auth/nid.c

@@ -58,7 +58,7 @@ int init_nonce_id()
 		nid_pool_no=DEFAULT_NID_POOL_SIZE;
 	}
 	if (nid_pool_no>MAX_NID_POOL_SIZE){
-		WARN("auth: nid_pool_no too big, truncating to %d\n",
+		LM_WARN("nid_pool_no too big, truncating to %d\n",
 				MAX_NID_POOL_SIZE);
 		nid_pool_no=MAX_NID_POOL_SIZE;
 	}
@@ -66,13 +66,13 @@ int init_nonce_id()
 	nid_pool_mask=(1<<nid_pool_k)-1;
 	pool_no=1UL<<nid_pool_k; /* ROUNDDOWN to 2^k */
 	if (pool_no!=nid_pool_no){
-		INFO("auth: nid_pool_no rounded down to %d\n", pool_no);
+		LM_INFO("nid_pool_no rounded down to %d\n", pool_no);
 	}
 	nid_pool_no=pool_no;
 
 	nid_crt=shm_malloc(sizeof(*nid_crt)*nid_pool_no);
 	if (nid_crt==0){
-		ERR("auth: init_nonce_id: memory allocation failure\n");
+		LM_ERR("init_nonce_id: memory allocation failure\n");
 		return -1;
 	}
 	/*  init nc_crt_id with random values */

+ 1 - 2
modules/auth/nonce.c

@@ -415,8 +415,7 @@ if (!memcmp(&b_nonce.n.md5_1[0], &b_nonce2.n.md5_1[0], 16)) {
 			auth->digest.nc.len){
 		if ((auth->digest.nc.len != 8) ||
 				l8hex2int(auth->digest.nc.s, &nc) != 0) {
-			ERR("check_nonce: bad nc value %.*s\n",
-					auth->digest.nc.len, auth->digest.nc.s);
+			LM_ERR("bad nc value %.*s\n", auth->digest.nc.len, auth->digest.nc.s);
 			return 5; /* invalid nc */
 		}
 		switch(nc_check_val(n_id, pf & NF_POOL_NO_MASK, nc)){

+ 10 - 10
modules/auth/ot_nonce.c

@@ -71,35 +71,35 @@ int init_ot_nonce()
 	}
 	size=1UL<<otn_in_flight_k; /* ROUNDDOWN to 2^otn_in_flight_k */
 	if (size < MIN_OTN_IN_FLIGHT){
-		WARN("auth: one-time-nonce maximum in-flight nonces is very low (%d),"
+		LM_WARN("one-time-nonce maximum in-flight nonces is very low (%d),"
 				" consider increasing otn_in_flight_no to at least %d\n",
 				orig_array_size, MIN_OTN_IN_FLIGHT);
 	}
 	if (size > MAX_OTN_IN_FLIGHT){
-		WARN("auth: one-time-nonce maximum in-flight nonces is too high (%d),"
+		LM_WARN("one-time-nonce maximum in-flight nonces is too high (%d),"
 				" consider decreasing otn_in_flight_no to at least %d\n",
 				orig_array_size, MAX_OTN_IN_FLIGHT);
 	}
 	if (size!=otn_in_flight_no){
 		if (orig_array_size!=0)
-			INFO("auth: otn_in_flight_no rounded down to %ld\n", size);
+			LM_INFO("otn_in_flight_no rounded down to %ld\n", size);
 		else
-			INFO("auth: otn_in_flight_no set to %ld\n", size);
+			LM_INFO("otn_in_flight_no set to %ld\n", size);
 	}
 	max_mem=shm_available();
 	if (size/8 >= max_mem){
-		ERR("auth: otn_in_flight_no (%ld) is too big for the configured "
+		LM_ERR("otn_in_flight_no (%ld) is too big for the configured "
 				"amount of shared memory (%ld bytes)\n", size, max_mem);
 		return -1;
 	}else if (size/8 >= max_mem/2){
-		WARN("auth: the currently configured otn_in_flight_no (%ld)  "
+		LM_WARN("the currently configured otn_in_flight_no (%ld)  "
 				"would use more then 50%% of the available shared"
 				" memory(%ld bytes)\n", size, max_mem);
 	}
 	otn_in_flight_no=size;
 
 	if (nid_pool_no>=otn_in_flight_no/(8*sizeof(otn_cell_t))){
-		ERR("auth: nid_pool_no (%d) too high for the configured "
+		LM_ERR("nid_pool_no (%d) too high for the configured "
 				"otn_in_flight_no (%d)\n", nid_pool_no, otn_in_flight_no);
 		return -1;
 	}
@@ -110,14 +110,14 @@ int init_ot_nonce()
 	assert(1<<(otn_partition_k+nid_pool_k) == otn_in_flight_no);
 
 	if ((nid_t)otn_partition_size >= ((nid_t)(-1)/NID_INC)){
-		ERR("auth: otn_in_flight_no too big, try decreasing it or increasing"
+		LM_ERR("otn_in_flight_no too big, try decreasing it or increasing"
 				"the number of pools/partitions, such that "
 				"otn_in_flight_no/nid_pool_no < %d\n",
 				(unsigned int)((nid_t)(-1)/NID_INC));
 		return -1;
 	}
 	if (otn_partition_size  < MIN_OTN_PARTITION){
-		WARN("auth: one-time-nonces in-flight nonces very low,"
+		LM_WARN("one-time-nonces in-flight nonces very low,"
 				" consider either decreasing nid_pool_no (%d) or "
 				" increasing otn_array_size (%d) such that "
 				"otn_array_size/nid_pool_no >= %d\n",
@@ -128,7 +128,7 @@ int init_ot_nonce()
 	 *  access it as an otn_cell_t array */
 	otn_array=shm_malloc(ROUND2TYPE((otn_in_flight_no+7)/8, otn_cell_t));
 	if (otn_array==0){
-		ERR("auth: init_ot_nonce: memory allocation failure, consider"
+		LM_ERR("init_ot_nonce: memory allocation failure, consider"
 				" either decreasing otn_in_flight_no of increasing the"
 				" the shared memory amount\n");
 		goto error;