Jacob Erlbeck | 3b5d407 | 2014-10-24 15:11:03 +0200 | [diff] [blame] | 1 | /* MS authorization and subscriber data handling */ |
| 2 | |
| 3 | /* (C) 2009-2010 by Harald Welte <laforge@gnumonks.org> |
| 4 | * |
| 5 | * All Rights Reserved |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU Affero General Public License as published by |
| 9 | * the Free Software Foundation; either version 3 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU Affero General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU Affero General Public License |
| 18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | #include <openbsc/sgsn.h> |
| 23 | #include <openbsc/gprs_sgsn.h> |
| 24 | |
| 25 | void sgsn_auth_init(struct sgsn_instance *sgi) |
| 26 | { |
| 27 | INIT_LLIST_HEAD(&sgi->cfg.imsi_acl); |
| 28 | } |
| 29 | |
| 30 | /* temporary IMSI ACL hack */ |
| 31 | struct imsi_acl_entry *sgsn_acl_lookup(const char *imsi, struct sgsn_config *cfg) |
| 32 | { |
| 33 | struct imsi_acl_entry *acl; |
| 34 | llist_for_each_entry(acl, &cfg->imsi_acl, list) { |
| 35 | if (!strcmp(imsi, acl->imsi)) |
| 36 | return acl; |
| 37 | } |
| 38 | return NULL; |
| 39 | } |
| 40 | |
| 41 | int sgsn_acl_add(const char *imsi, struct sgsn_config *cfg) |
| 42 | { |
| 43 | struct imsi_acl_entry *acl; |
| 44 | |
| 45 | if (sgsn_acl_lookup(imsi, cfg)) |
| 46 | return -EEXIST; |
| 47 | |
| 48 | acl = talloc_zero(NULL, struct imsi_acl_entry); |
| 49 | if (!acl) |
| 50 | return -ENOMEM; |
| 51 | strncpy(acl->imsi, imsi, sizeof(acl->imsi)); |
| 52 | |
| 53 | llist_add(&acl->list, &cfg->imsi_acl); |
| 54 | |
| 55 | return 0; |
| 56 | } |
| 57 | |
| 58 | int sgsn_acl_del(const char *imsi, struct sgsn_config *cfg) |
| 59 | { |
| 60 | struct imsi_acl_entry *acl; |
| 61 | |
| 62 | acl = sgsn_acl_lookup(imsi, cfg); |
| 63 | if (!acl) |
| 64 | return -ENODEV; |
| 65 | |
| 66 | llist_del(&acl->list); |
| 67 | talloc_free(acl); |
| 68 | |
| 69 | return 0; |
| 70 | } |
| 71 | |