[PATCH 1/3] nitb/ctrl: Add ctrl command to get/set auth policy

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/OpenBSC@lists.osmocom.org/.

Ivan Kluchnikov kluchnikovi at gmail.com
Tue May 6 15:35:57 UTC 2014


---
 openbsc/src/libbsc/bsc_ctrl_commands.c |   31 +++++++++++++++++++++++++++++++
 openbsc/tests/ctrl_test_runner.py      |   18 ++++++++++++++++++
 2 files changed, 49 insertions(+)

diff --git a/openbsc/src/libbsc/bsc_ctrl_commands.c b/openbsc/src/libbsc/bsc_ctrl_commands.c
index 3759593..3cb77cc 100644
--- a/openbsc/src/libbsc/bsc_ctrl_commands.c
+++ b/openbsc/src/libbsc/bsc_ctrl_commands.c
@@ -66,6 +66,36 @@ CTRL_CMD_DEFINE_RANGE(net_mcc, "mcc", struct gsm_network, country_code, 1, 999);
 CTRL_CMD_VTY_STRING(net_short_name, "short-name", struct gsm_network, name_short);
 CTRL_CMD_VTY_STRING(net_long_name, "long-name", struct gsm_network, name_long);
 
+static int verify_net_auth_policy(struct ctrl_cmd *cmd, const char *value, void *data)
+{
+
+	if ((int)gsm_auth_policy_parse(value) < 0) {
+		return -1;
+	}
+
+	return 0;
+}
+
+static int get_net_auth_policy(struct ctrl_cmd *cmd, void *data)
+{
+	struct gsm_network *net = cmd->node;
+	cmd->reply = talloc_asprintf(cmd, "%s", gsm_auth_policy_name(net->auth_policy));
+	if (!cmd->reply) {
+		cmd->reply = "OOM";
+		return CTRL_CMD_ERROR;
+	}
+	return CTRL_CMD_REPLY;
+}
+
+static int set_net_auth_policy(struct ctrl_cmd *cmd, void *data)
+{
+	struct gsm_network *net = cmd->node;
+	net->auth_policy = gsm_auth_policy_parse(cmd->value);
+	return get_net_auth_policy(cmd, data);
+}
+
+CTRL_CMD_DEFINE(net_auth_policy, "auth-policy");
+
 static int verify_net_apply_config(struct ctrl_cmd *cmd, const char *v, void *d)
 {
 	return 0;
@@ -200,6 +230,7 @@ int bsc_base_ctrl_cmds_install(void)
 	rc |= ctrl_cmd_install(CTRL_NODE_ROOT, &cmd_net_mcc);
 	rc |= ctrl_cmd_install(CTRL_NODE_ROOT, &cmd_net_short_name);
 	rc |= ctrl_cmd_install(CTRL_NODE_ROOT, &cmd_net_long_name);
+	rc |= ctrl_cmd_install(CTRL_NODE_ROOT, &cmd_net_auth_policy);
 	rc |= ctrl_cmd_install(CTRL_NODE_ROOT, &cmd_net_apply_config);
 	rc |= ctrl_cmd_install(CTRL_NODE_ROOT, &cmd_net_mcc_mnc_apply);
 
diff --git a/openbsc/tests/ctrl_test_runner.py b/openbsc/tests/ctrl_test_runner.py
index b50e93c..f24d52a 100644
--- a/openbsc/tests/ctrl_test_runner.py
+++ b/openbsc/tests/ctrl_test_runner.py
@@ -362,6 +362,24 @@ class TestCtrlNITB(TestCtrlBase):
     def ctrl_app(self):
         return (4249, "./src/osmo-nitb/osmo-nitb", "OsmoBSC", "nitb")
 
+    def testAuthPolicy(self):
+        policies = ['token', 'closed', 'accept-all']
+
+        for policy in policies:
+            r = self.do_set('auth-policy', policy)
+            self.assertEquals(r['mtype'], 'SET_REPLY')
+            self.assertEquals(r['var'], 'auth-policy')
+            self.assertEquals(r['value'], policy)
+
+            r = self.do_get('auth-policy')
+            self.assertEquals(r['mtype'], 'GET_REPLY')
+            self.assertEquals(r['var'], 'auth-policy')
+            self.assertEquals(r['value'], policy)
+
+        r = self.do_set('auth-policy', 'qwerty')
+        self.assertEquals(r['mtype'], 'ERROR')
+        self.assertEquals(r['error'], 'Value failed verification.')
+
     def testSubscriberAddRemove(self):
         r = self.do_set('subscriber-modify-v1', '2620345,445566')
         self.assertEquals(r['mtype'], 'SET_REPLY')
-- 
1.7.9.5





More information about the OpenBSC mailing list