diff options
author | Holger Hans Peter Freyther <holger@moiji-mobile.com> | 2014-03-23 14:01:08 +0100 |
---|---|---|
committer | Holger Hans Peter Freyther <holger@moiji-mobile.com> | 2014-03-23 14:05:49 +0100 |
commit | 2d99eeb7f2c7978e9d96f5df61e462e6feb05973 (patch) | |
tree | ffe29fa00874ddb3aade11d773c49b8ea35f32e3 /openbsc/src/libmsc/ctrl_commands.c | |
parent | 9dbc3f8db7ca2c95ad6b986cdc4cd6c7a602a8b4 (diff) |
nitb/ctrl: Implement creating and deleting subscribers
Sadly there is no proper foreign key relationship on the tables
that related to the Subscriber. This means we can't use a DELETE
with Cascade and need to delete everything by hand. To make things
worse maybe the SMS/Paging code is still using the subscriber
making the operation more dangerous. I had added NULL checks for
sender_id/receiver_id at 30C3 so we should not crash in this
situation.
Fixes: SYS#274
Diffstat (limited to 'openbsc/src/libmsc/ctrl_commands.c')
-rw-r--r-- | openbsc/src/libmsc/ctrl_commands.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/openbsc/src/libmsc/ctrl_commands.c b/openbsc/src/libmsc/ctrl_commands.c index 75b094af1..b66cece8e 100644 --- a/openbsc/src/libmsc/ctrl_commands.c +++ b/openbsc/src/libmsc/ctrl_commands.c @@ -22,6 +22,7 @@ #include <openbsc/gsm_data.h> #include <openbsc/gsm_subscriber.h> #include <openbsc/db.h> +#include <openbsc/debug.h> static int verify_subscriber_modify(struct ctrl_cmd *cmd, const char *value, void *d) { @@ -97,10 +98,53 @@ fail: CTRL_CMD_DEFINE(subscriber_modify, "subscriber-modify-v1"); +static int verify_subscriber_delete(struct ctrl_cmd *cmd, const char *v, void *d) +{ + return 0; +} + +static int get_subscriber_delete(struct ctrl_cmd *cmd, void *data) +{ + cmd->reply = "Set only attribute"; + return CTRL_CMD_ERROR; +} + +static int set_subscriber_delete(struct ctrl_cmd *cmd, void *data) +{ + int was_used = 0; + int rc; + struct gsm_subscriber *subscr; + struct gsm_network *net = cmd->node; + + subscr = subscr_get_by_imsi(net, cmd->value); + if (!subscr) { + cmd->reply = "Failed to find subscriber"; + return CTRL_CMD_ERROR; + } + + if (subscr->use_count != 1) { + LOGP(DCTRL, LOGL_NOTICE, "Going to remove active subscriber.\n"); + was_used = 1; + } + + rc = db_subscriber_delete(subscr); + subscr_put(subscr); + + if (rc != 0) { + cmd->reply = "Failed to remove subscriber"; + return CTRL_CMD_ERROR; + } + + cmd->reply = was_used ? "Removed active subscriber" : "Removed"; + return CTRL_CMD_REPLY; +} +CTRL_CMD_DEFINE(subscriber_delete, "subscriber-delete-v1"); + int msc_ctrl_cmds_install(void) { int rc = 0; rc |= ctrl_cmd_install(CTRL_NODE_ROOT, &cmd_subscriber_modify); + rc |= ctrl_cmd_install(CTRL_NODE_ROOT, &cmd_subscriber_delete); return rc; } |