gsm_04_08: factor out subscr authorization check

Add function subscr_authorized(), absorbing the guts of static
authorize_subscriber() from gsm_04_08.c, except the parts specific to Location
Updating.

subscr_authorized() is a check that is to be added to validation of a paging
response.
This commit is contained in:
Neels Hofmeyr
2016-05-02 15:02:32 +02:00
parent 5c4386c692
commit 00007897d4
3 changed files with 36 additions and 27 deletions

View File

@@ -1,6 +1,8 @@
#ifndef _GSM_SUBSCR_H
#define _GSM_SUBSCR_H
#include <stdbool.h>
#include "gsm_data.h"
#include <osmocom/core/linuxlist.h>
@@ -130,6 +132,8 @@ void subscr_update_from_db(struct gsm_subscriber *subscr);
void subscr_expire(struct gsm_subscriber_group *sgrp);
int subscr_update_expire_lu(struct gsm_network *network, struct gsm_subscriber *subscr);
bool subscr_authorized(struct gsm_subscriber *subsc);
/*
* Paging handling with authentication
*/

View File

@@ -272,12 +272,12 @@ int gsm48_secure_channel(struct gsm_subscriber_connection *conn, int key_seq,
return -EINVAL; /* not reached */
}
static int authorize_subscriber(struct gsm_loc_updating_operation *loc,
struct gsm_subscriber *subscriber)
static bool authorize_subscriber(struct gsm_loc_updating_operation *loc,
struct gsm_subscriber *subscriber)
{
if (!subscriber) {
LOGP(DMM, LOGL_DEBUG, "authorize_subscriber() on NULL subscriber\n");
return 0;
return false;
}
/*
@@ -291,32 +291,10 @@ static int authorize_subscriber(struct gsm_loc_updating_operation *loc,
loc->waiting_for_imsi? " IMSI": "",
loc->waiting_for_imei? " IMEI": "",
subscr_name(subscriber));
return 0;
return false;
}
switch (subscriber->group->net->auth_policy) {
case GSM_AUTH_POLICY_CLOSED:
LOGP(DMM, LOGL_DEBUG, "subscriber %s authorized = %d\n",
subscr_name(subscriber), subscriber->authorized);
return subscriber->authorized;
case GSM_AUTH_POLICY_TOKEN:
if (subscriber->authorized) {
LOGP(DMM, LOGL_DEBUG,
"subscriber %s authorized = %d\n",
subscr_name(subscriber), subscriber->authorized);
return subscriber->authorized;
}
LOGP(DMM, LOGL_DEBUG, "subscriber %s first contact = %d\n",
subscr_name(subscriber),
(int)(subscriber->flags & GSM_SUBSCRIBER_FIRST_CONTACT));
return (subscriber->flags & GSM_SUBSCRIBER_FIRST_CONTACT);
case GSM_AUTH_POLICY_ACCEPT_ALL:
return 1;
default:
LOGP(DMM, LOGL_DEBUG, "unknown auth_policy, rejecting"
" subscriber %s\n", subscr_name(subscriber));
return 0;
}
return subscr_authorized(subscriber);
}
static void release_loc_updating_req(struct gsm_subscriber_connection *conn, int release)

View File

@@ -405,3 +405,30 @@ void msc_subscr_con_free(struct gsm_subscriber_connection *conn)
llist_del(&conn->entry);
talloc_free(conn);
}
bool subscr_authorized(struct gsm_subscriber *subscriber)
{
switch (subscriber->group->net->auth_policy) {
case GSM_AUTH_POLICY_CLOSED:
LOGP(DMM, LOGL_DEBUG, "subscriber %s authorized = %d\n",
subscr_name(subscriber), subscriber->authorized);
return subscriber->authorized ? true : false;
case GSM_AUTH_POLICY_TOKEN:
if (subscriber->authorized) {
LOGP(DMM, LOGL_DEBUG,
"subscriber %s authorized = %d\n",
subscr_name(subscriber), subscriber->authorized);
return subscriber->authorized;
}
LOGP(DMM, LOGL_DEBUG, "subscriber %s first contact = %d\n",
subscr_name(subscriber),
(int)(subscriber->flags & GSM_SUBSCRIBER_FIRST_CONTACT));
return (subscriber->flags & GSM_SUBSCRIBER_FIRST_CONTACT);
case GSM_AUTH_POLICY_ACCEPT_ALL:
return true;
default:
LOGP(DMM, LOGL_DEBUG, "unknown auth_policy, rejecting"
" subscriber %s\n", subscr_name(subscriber));
return false;
}
}