From patchwork Tue May 6 15:35:57 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ivan Kluchnikov X-Patchwork-Id: 346242 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from ganesha.gnumonks.org (ganesha.gnumonks.org [213.95.27.120]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id D47121413AC for ; Wed, 7 May 2014 01:38:05 +1000 (EST) Received: from localhost ([127.0.0.1] helo=ganesha.gnumonks.org) by ganesha.gnumonks.org with esmtp (Exim 4.72) (envelope-from ) id 1WhhRE-0005og-48; Tue, 06 May 2014 17:37:48 +0200 Received: from mail-lb0-x22a.google.com ([2a00:1450:4010:c04::22a]) by ganesha.gnumonks.org with esmtps (TLS1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.72) (envelope-from ) id 1WhhPh-0005oR-OA for openbsc@lists.osmocom.org; Tue, 06 May 2014 17:36:19 +0200 Received: by mail-lb0-f170.google.com with SMTP id w7so2501390lbi.29 for ; Tue, 06 May 2014 08:36:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:date:message-id; bh=hg2rNKZptNCaXu2am/lCQXHemCSUc5Ll68/AgumRtI0=; b=mpkUMIsnqwL3PEcrGmUgkPj11J/WFvAs5s20+nWQEj5RRMdqPT/AwjmPdnP6bVor0k 2PCDVz4fUZUdZwAQm+tDar1VekSEVI+OjCDRq6WUJTe68G3JRgHjDL5Z8P03s1Ke8wMP 36uaZn8XLAKP/T3IYq0wT6TdGUrS+Druc2OkKNmpM++ngEzE6U3D3XEn7kwpvgmsuZkb ZXmLOLCre48ICVG4jHmTsqIJkcggC2smp/FIQ4czbK1pdg9Sn6tji27Oiu/0XVnjZSoe 8PmfU8+olx2Oo9xLaYruHk8LA+yzwro/AKbgoKEHARXWIkRAu75re/W7l1xg52uOItER eltg== X-Received: by 10.112.164.148 with SMTP id yq20mr32762304lbb.22.1399390571814; Tue, 06 May 2014 08:36:11 -0700 (PDT) Received: from kluchnikov.neuronspace.ru ([84.253.75.222]) by mx.google.com with ESMTPSA id jp6sm13898997lbc.15.2014.05.06.08.36.09 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 06 May 2014 08:36:10 -0700 (PDT) From: Ivan Kluchnikov To: openbsc@lists.osmocom.org Subject: [PATCH 1/3] nitb/ctrl: Add ctrl command to get/set auth policy Date: Tue, 6 May 2014 19:35:57 +0400 Message-Id: <1399390559-22655-1-git-send-email-kluchnikovi@gmail.com> X-Mailer: git-send-email 1.7.9.5 X-Spam-Score: -0.1 (/) X-BeenThere: openbsc@lists.osmocom.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Development of the OpenBSC GSM base station controller List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: openbsc-bounces@lists.osmocom.org Errors-To: openbsc-bounces@lists.osmocom.org --- 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')