|
Packit Service |
102278 |
/* Copyright (C) 2005 Red Hat, Inc. */
|
|
Packit Service |
102278 |
|
|
Packit Service |
102278 |
struct semanage_port;
|
|
Packit Service |
102278 |
struct semanage_port_key;
|
|
Packit Service |
102278 |
typedef struct semanage_port_key record_key_t;
|
|
Packit Service |
102278 |
typedef struct semanage_port record_t;
|
|
Packit Service |
102278 |
#define DBASE_RECORD_DEFINED
|
|
Packit Service |
102278 |
|
|
Packit Service |
102278 |
#include <stdlib.h>
|
|
Packit Service |
102278 |
#include "port_internal.h"
|
|
Packit Service |
102278 |
#include "debug.h"
|
|
Packit Service |
102278 |
#include "handle.h"
|
|
Packit Service |
102278 |
#include "database.h"
|
|
Packit Service |
102278 |
|
|
Packit Service |
102278 |
int semanage_port_modify_local(semanage_handle_t * handle,
|
|
Packit Service |
102278 |
const semanage_port_key_t * key,
|
|
Packit Service |
102278 |
const semanage_port_t * data)
|
|
Packit Service |
102278 |
{
|
|
Packit Service |
102278 |
|
|
Packit Service |
102278 |
dbase_config_t *dconfig = semanage_port_dbase_local(handle);
|
|
Packit Service |
102278 |
return dbase_modify(handle, dconfig, key, data);
|
|
Packit Service |
102278 |
}
|
|
Packit Service |
102278 |
|
|
Packit Service |
102278 |
int semanage_port_del_local(semanage_handle_t * handle,
|
|
Packit Service |
102278 |
const semanage_port_key_t * key)
|
|
Packit Service |
102278 |
{
|
|
Packit Service |
102278 |
|
|
Packit Service |
102278 |
dbase_config_t *dconfig = semanage_port_dbase_local(handle);
|
|
Packit Service |
102278 |
return dbase_del(handle, dconfig, key);
|
|
Packit Service |
102278 |
}
|
|
Packit Service |
102278 |
|
|
Packit Service |
102278 |
int semanage_port_query_local(semanage_handle_t * handle,
|
|
Packit Service |
102278 |
const semanage_port_key_t * key,
|
|
Packit Service |
102278 |
semanage_port_t ** response)
|
|
Packit Service |
102278 |
{
|
|
Packit Service |
102278 |
|
|
Packit Service |
102278 |
dbase_config_t *dconfig = semanage_port_dbase_local(handle);
|
|
Packit Service |
102278 |
return dbase_query(handle, dconfig, key, response);
|
|
Packit Service |
102278 |
}
|
|
Packit Service |
102278 |
|
|
Packit Service |
102278 |
int semanage_port_exists_local(semanage_handle_t * handle,
|
|
Packit Service |
102278 |
const semanage_port_key_t * key, int *response)
|
|
Packit Service |
102278 |
{
|
|
Packit Service |
102278 |
|
|
Packit Service |
102278 |
dbase_config_t *dconfig = semanage_port_dbase_local(handle);
|
|
Packit Service |
102278 |
return dbase_exists(handle, dconfig, key, response);
|
|
Packit Service |
102278 |
}
|
|
Packit Service |
102278 |
|
|
Packit Service |
102278 |
int semanage_port_count_local(semanage_handle_t * handle,
|
|
Packit Service |
102278 |
unsigned int *response)
|
|
Packit Service |
102278 |
{
|
|
Packit Service |
102278 |
|
|
Packit Service |
102278 |
dbase_config_t *dconfig = semanage_port_dbase_local(handle);
|
|
Packit Service |
102278 |
return dbase_count(handle, dconfig, response);
|
|
Packit Service |
102278 |
}
|
|
Packit Service |
102278 |
|
|
Packit Service |
102278 |
int semanage_port_iterate_local(semanage_handle_t * handle,
|
|
Packit Service |
102278 |
int (*handler) (const semanage_port_t * record,
|
|
Packit Service |
102278 |
void *varg), void *handler_arg)
|
|
Packit Service |
102278 |
{
|
|
Packit Service |
102278 |
|
|
Packit Service |
102278 |
dbase_config_t *dconfig = semanage_port_dbase_local(handle);
|
|
Packit Service |
102278 |
return dbase_iterate(handle, dconfig, handler, handler_arg);
|
|
Packit Service |
102278 |
}
|
|
Packit Service |
102278 |
|
|
Packit Service |
102278 |
int semanage_port_list_local(semanage_handle_t * handle,
|
|
Packit Service |
102278 |
semanage_port_t *** records, unsigned int *count)
|
|
Packit Service |
102278 |
{
|
|
Packit Service |
102278 |
|
|
Packit Service |
102278 |
dbase_config_t *dconfig = semanage_port_dbase_local(handle);
|
|
Packit Service |
102278 |
return dbase_list(handle, dconfig, records, count);
|
|
Packit Service |
102278 |
}
|
|
Packit Service |
102278 |
|
|
Packit Service |
102278 |
hidden_def(semanage_port_list_local)
|
|
Packit Service |
102278 |
|
|
Packit Service |
102278 |
int hidden semanage_port_validate_local(semanage_handle_t * handle)
|
|
Packit Service |
102278 |
{
|
|
Packit Service |
102278 |
|
|
Packit Service |
102278 |
semanage_port_t **ports = NULL;
|
|
Packit Service |
102278 |
unsigned int nports = 0;
|
|
Packit Service |
102278 |
unsigned int i = 0, j = 0;
|
|
Packit Service |
102278 |
|
|
Packit Service |
102278 |
/* List and sort the ports */
|
|
Packit Service |
102278 |
if (semanage_port_list_local(handle, &ports, &nports) < 0)
|
|
Packit Service |
102278 |
goto err;
|
|
Packit Service |
102278 |
qsort(ports, nports, sizeof(semanage_port_t *),
|
|
Packit Service |
102278 |
(int (*)(const void *, const void *))
|
|
Packit Service |
102278 |
&semanage_port_compare2_qsort);
|
|
Packit Service |
102278 |
|
|
Packit Service |
102278 |
/* Test each port for overlap */
|
|
Packit Service |
102278 |
while (i < nports) {
|
|
Packit Service |
102278 |
|
|
Packit Service |
102278 |
int proto = semanage_port_get_proto(ports[i]);
|
|
Packit Service |
102278 |
int low = semanage_port_get_low(ports[i]);
|
|
Packit Service |
102278 |
int high = semanage_port_get_high(ports[i]);
|
|
Packit Service |
102278 |
const char *proto_str = semanage_port_get_proto_str(proto);
|
|
Packit Service |
102278 |
|
|
Packit Service |
102278 |
const char *proto_str2;
|
|
Packit Service |
102278 |
int proto2, low2, high2;
|
|
Packit Service |
102278 |
|
|
Packit Service |
102278 |
/* Find the first port with matching
|
|
Packit Service |
102278 |
protocol to compare against */
|
|
Packit Service |
102278 |
do {
|
|
Packit Service |
102278 |
if (j == nports - 1)
|
|
Packit Service |
102278 |
goto next;
|
|
Packit Service |
102278 |
j++;
|
|
Packit Service |
102278 |
proto2 = semanage_port_get_proto(ports[j]);
|
|
Packit Service |
102278 |
low2 = semanage_port_get_low(ports[j]);
|
|
Packit Service |
102278 |
high2 = semanage_port_get_high(ports[j]);
|
|
Packit Service |
102278 |
proto_str2 = semanage_port_get_proto_str(proto2);
|
|
Packit Service |
102278 |
|
|
Packit Service |
102278 |
} while (proto != proto2);
|
|
Packit Service |
102278 |
|
|
Packit Service |
102278 |
/* Overlap detected */
|
|
Packit Service |
102278 |
if (low2 <= high) {
|
|
Packit Service |
102278 |
ERR(handle, "port overlap between ranges "
|
|
Packit Service |
102278 |
"%u - %u (%s) <--> %u - %u (%s).",
|
|
Packit Service |
102278 |
low, high, proto_str, low2, high2, proto_str2);
|
|
Packit Service |
102278 |
goto invalid;
|
|
Packit Service |
102278 |
}
|
|
Packit Service |
102278 |
|
|
Packit Service |
102278 |
/* If closest port of matching protocol doesn't overlap with
|
|
Packit Service |
102278 |
* test port, neither do the rest of them, because that's
|
|
Packit Service |
102278 |
* how the sort function works on ports - lower bound
|
|
Packit Service |
102278 |
* ports come first */
|
|
Packit Service |
102278 |
next:
|
|
Packit Service |
102278 |
i++;
|
|
Packit Service |
102278 |
j = i;
|
|
Packit Service |
102278 |
}
|
|
Packit Service |
102278 |
|
|
Packit Service |
102278 |
for (i = 0; i < nports; i++)
|
|
Packit Service |
102278 |
semanage_port_free(ports[i]);
|
|
Packit Service |
102278 |
free(ports);
|
|
Packit Service |
102278 |
return STATUS_SUCCESS;
|
|
Packit Service |
102278 |
|
|
Packit Service |
102278 |
err:
|
|
Packit Service |
102278 |
ERR(handle, "could not complete ports validity check");
|
|
Packit Service |
102278 |
|
|
Packit Service |
102278 |
invalid:
|
|
Packit Service |
102278 |
for (i = 0; i < nports; i++)
|
|
Packit Service |
102278 |
semanage_port_free(ports[i]);
|
|
Packit Service |
102278 |
free(ports);
|
|
Packit Service |
102278 |
return STATUS_ERR;
|
|
Packit Service |
102278 |
}
|