Remove use of dynamic memory (strlist_t) from linux.c.
This commit is contained in:
parent
6e9d856a9d
commit
a60a5fddb1
@ -8,6 +8,7 @@
|
|||||||
#define MAX_BUF 1024
|
#define MAX_BUF 1024
|
||||||
#define SOCK_QUEUE 2
|
#define SOCK_QUEUE 2
|
||||||
#define CONN_TIMEOUT 60
|
#define CONN_TIMEOUT 60
|
||||||
|
#define MAX_IFACES 10
|
||||||
|
|
||||||
#include <net/if.h>
|
#include <net/if.h>
|
||||||
#include "strlist.h"
|
#include "strlist.h"
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/* linux.c - ifchd Linux-specific functions
|
/* linux.c - ifchd Linux-specific functions
|
||||||
*
|
*
|
||||||
* Copyright (c) 2004-2011 Nicholas J. Kain <njkain at gmail dot com>
|
* Copyright (c) 2004-2012 Nicholas J. Kain <njkain at gmail dot com>
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@ -47,37 +47,34 @@
|
|||||||
|
|
||||||
#include "ifchd-defines.h"
|
#include "ifchd-defines.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "strlist.h"
|
|
||||||
#include "ifch_proto.h"
|
#include "ifch_proto.h"
|
||||||
#include "strl.h"
|
#include "strl.h"
|
||||||
|
|
||||||
extern struct ifchd_client clients[SOCK_QUEUE];
|
extern struct ifchd_client clients[SOCK_QUEUE];
|
||||||
static strlist_t *okif;
|
|
||||||
|
static size_t numokif;
|
||||||
|
static char okif[MAX_IFACES][IFNAMSIZ];
|
||||||
|
|
||||||
/* Adds to the list of interface names ifchd clients are allowed to change. */
|
/* Adds to the list of interface names ifchd clients are allowed to change. */
|
||||||
void add_permitted_if(char *s)
|
void add_permitted_if(char *s)
|
||||||
{
|
{
|
||||||
if (!s)
|
if (numokif >= MAX_IFACES)
|
||||||
return;
|
return;
|
||||||
add_to_strlist(&okif, s);
|
strlcpy(okif[numokif++], s, IFNAMSIZ);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Checks if changes are permitted to a given interface. 1 == allowed */
|
/* Checks if changes are permitted to a given interface. 1 == allowed */
|
||||||
static int is_permitted(char *name)
|
static int is_permitted(char *name)
|
||||||
{
|
{
|
||||||
strlist_t *p;
|
|
||||||
|
|
||||||
/* If empty, permit all. */
|
/* If empty, permit all. */
|
||||||
if (!okif)
|
if (!numokif)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
if (!name || strlen(name) == 0)
|
if (!name || strlen(name) == 0)
|
||||||
return 0;
|
return 0;
|
||||||
p = okif;
|
for (size_t i = 0; i < numokif; ++i) {
|
||||||
while (p) {
|
if (strcmp(name, okif[i]) == 0)
|
||||||
if (strcmp(name, p->str) == 0)
|
|
||||||
return 1;
|
return 1;
|
||||||
p = p->next;
|
|
||||||
}
|
}
|
||||||
log_line("attempt to modify interface %s denied\n", name);
|
log_line("attempt to modify interface %s denied\n", name);
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user