[4/7] MM Auth: introduce AUTH_ERROR constant.
diff mbox

Message ID 1459329750-2318-5-git-send-email-nhofmeyr@sysmocom.de
State New
Headers show

Commit Message

Neels Hofmeyr March 30, 2016, 9:22 a.m. UTC
Instead of using hardcoded -1 for errors, include -1 in the enum auth_action
type; apply its use.

In the mm_auth test, the string output changes from '(internal error)' to
'AUTH_ERROR', since now the proper enum value is used in auth_action_names[].
---
 openbsc/include/openbsc/auth.h        | 1 +
 openbsc/src/libmsc/auth.c             | 6 +++---
 openbsc/tests/mm_auth/mm_auth_test.c  | 2 +-
 openbsc/tests/mm_auth/mm_auth_test.ok | 2 +-
 4 files changed, 6 insertions(+), 5 deletions(-)

Patch
diff mbox

diff --git a/openbsc/include/openbsc/auth.h b/openbsc/include/openbsc/auth.h
index 90495bb..6181131 100644
--- a/openbsc/include/openbsc/auth.h
+++ b/openbsc/include/openbsc/auth.h
@@ -7,6 +7,7 @@  struct gsm_auth_tuple;
 struct gsm_subscriber;
 
 enum auth_action {
+	AUTH_ERROR		= -1,	/* Internal error */
 	AUTH_NOT_AVAIL		= 0,	/* No auth tuple available */
 	AUTH_DO_AUTH_THEN_CIPH	= 1,	/* Firsth authenticate, then cipher */
 	AUTH_DO_CIPH		= 2,	/* Only ciphering */
diff --git a/openbsc/src/libmsc/auth.c b/openbsc/src/libmsc/auth.c
index 8512316..99e3a24 100644
--- a/openbsc/src/libmsc/auth.c
+++ b/openbsc/src/libmsc/auth.c
@@ -33,7 +33,7 @@ 
 
 const struct value_string auth_action_names[] = {
 #define AUTH_ACTION_STR(X) { X, #X }
-	{ -1, "(internal error)" }, /* soon to be fixed with an enum val */
+	AUTH_ACTION_STR(AUTH_ERROR),
 	AUTH_ACTION_STR(AUTH_NOT_AVAIL),
 	AUTH_ACTION_STR(AUTH_DO_AUTH_THEN_CIPH),
 	AUTH_ACTION_STR(AUTH_DO_CIPH),
@@ -93,7 +93,7 @@  int auth_get_tuple_for_subscr(struct gsm_auth_tuple *atuple,
 	if (rc < 0) {
 		LOGP(DMM, LOGL_NOTICE,
 			"No retrievable Ki for subscriber, skipping auth\n");
-		return rc == -ENOENT ? AUTH_NOT_AVAIL : -1;
+		return rc == -ENOENT ? AUTH_NOT_AVAIL : AUTH_ERROR;
 	}
 
 	/* If possible, re-use the last tuple and skip auth */
@@ -114,7 +114,7 @@  int auth_get_tuple_for_subscr(struct gsm_auth_tuple *atuple,
 
 	if (RAND_bytes(atuple->rand, sizeof(atuple->rand)) != 1) {
 		LOGP(DMM, LOGL_NOTICE, "RAND_bytes failed, can't generate new auth tuple\n");
-		return -1;
+		return AUTH_ERROR;
 	}
 
 	switch (ainfo.auth_algo) {
diff --git a/openbsc/tests/mm_auth/mm_auth_test.c b/openbsc/tests/mm_auth/mm_auth_test.c
index e541898..1d65984 100644
--- a/openbsc/tests/mm_auth/mm_auth_test.c
+++ b/openbsc/tests/mm_auth/mm_auth_test.c
@@ -141,7 +141,7 @@  static void test_error()
 	test_get_authinfo_rc = -EIO;
 	auth_action = auth_get_tuple_for_subscr_verbose(&atuple, &subscr,
 							key_seq);
-	OSMO_ASSERT(auth_action == -1);
+	OSMO_ASSERT(auth_action == AUTH_ERROR);
 }
 
 static void test_auth_not_avail()
diff --git a/openbsc/tests/mm_auth/mm_auth_test.ok b/openbsc/tests/mm_auth/mm_auth_test.ok
index cc0e769..7dedadc 100644
--- a/openbsc/tests/mm_auth/mm_auth_test.ok
+++ b/openbsc/tests/mm_auth/mm_auth_test.ok
@@ -1,7 +1,7 @@ 
 
 * test_error()
 wrapped: db_get_authinfo_for_subscr(): rc = -5
-auth_get_tuple_for_subscr(key_seq=0) --> auth_action == (internal error)
+auth_get_tuple_for_subscr(key_seq=0) --> auth_action == AUTH_ERROR
 
 * test_auth_not_avail()
 wrapped: db_get_authinfo_for_subscr(): rc = -2