summaryrefslogtreecommitdiffstats
path: root/source/lib
diff options
context:
space:
mode:
Diffstat (limited to 'source/lib')
-rw-r--r--source/lib/fnmatch.c200
-rw-r--r--source/lib/hash.c320
-rw-r--r--source/lib/interfaces.c404
-rw-r--r--source/lib/talloc.c96
4 files changed, 0 insertions, 1020 deletions
diff --git a/source/lib/fnmatch.c b/source/lib/fnmatch.c
deleted file mode 100644
index 056ad8b232e..00000000000
--- a/source/lib/fnmatch.c
+++ /dev/null
@@ -1,200 +0,0 @@
-#include "includes.h"
-#ifndef HAVE_FNMATCH
-
-/* Copyright (C) 1991, 1992, 1993 Free Software Foundation, Inc.
-
-NOTE: The canonical source of this file is maintained with the GNU C Library.
-Bugs can be reported to bug-glibc@prep.ai.mit.edu.
-
-This program is free software; you can redistribute it and/or modify it
-under the terms of the GNU General Public License as published by the
-Free Software Foundation; either version 2, or (at your option) any
-later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
-
-#if defined (STDC_HEADERS) || !defined (isascii)
-#define ISASCII(c) 1
-#else
-#define ISASCII(c) isascii(c)
-#endif
-
-#define ISUPPER(c) (ISASCII (c) && isupper (c))
-
-
-/* Comment out all this code if we are using the GNU C Library, and are not
- actually compiling the library itself. This code is part of the GNU C
- Library, but also included in many other GNU distributions. Compiling
- and linking in this code is a waste when using the GNU C library
- (especially if it is a shared library). Rather than having every GNU
- program understand `configure --with-gnu-libc' and omit the object files,
- it is simpler to just do this in the source for each such file. */
-
-#if !defined(__GNU_LIBRARY__) && !defined(STDC_HEADERS)
-extern int errno;
-#endif
-
-/* Match STRING against the filename pattern PATTERN, returning zero if
- it matches, nonzero if not. */
-int fnmatch (const char *pattern, const char *string, int flags)
-{
- register const char *p = pattern, *n = string;
- register char c;
-
-/* Note that this evalutes C many times. */
-#define FOLD(c) ((flags & FNM_CASEFOLD) && ISUPPER (c) ? tolower (c) : (c))
-
- while ((c = *p++) != '\0')
- {
- c = FOLD (c);
-
- switch (c)
- {
- case '?':
- if (*n == '\0')
- return FNM_NOMATCH;
- else if ((flags & FNM_FILE_NAME) && *n == '/')
- return FNM_NOMATCH;
- else if ((flags & FNM_PERIOD) && *n == '.' &&
- (n == string || ((flags & FNM_FILE_NAME) && n[-1] == '/')))
- return FNM_NOMATCH;
- break;
-
- case '\\':
- if (!(flags & FNM_NOESCAPE))
- {
- c = *p++;
- c = FOLD (c);
- }
- if (FOLD (*n) != c)
- return FNM_NOMATCH;
- break;
-
- case '*':
- if ((flags & FNM_PERIOD) && *n == '.' &&
- (n == string || ((flags & FNM_FILE_NAME) && n[-1] == '/')))
- return FNM_NOMATCH;
-
- for (c = *p++; c == '?' || c == '*'; c = *p++, ++n)
- if (((flags & FNM_FILE_NAME) && *n == '/') ||
- (c == '?' && *n == '\0'))
- return FNM_NOMATCH;
-
- if (c == '\0')
- return 0;
-
- {
- char c1 = (!(flags & FNM_NOESCAPE) && c == '\\') ? *p : c;
- c1 = FOLD (c1);
- for (--p; *n != '\0'; ++n)
- if ((c == '[' || FOLD (*n) == c1) &&
- fnmatch (p, n, flags & ~FNM_PERIOD) == 0)
- return 0;
- return FNM_NOMATCH;
- }
-
- case '[':
- {
- /* Nonzero if the sense of the character class is inverted. */
- register int not;
-
- if (*n == '\0')
- return FNM_NOMATCH;
-
- if ((flags & FNM_PERIOD) && *n == '.' &&
- (n == string || ((flags & FNM_FILE_NAME) && n[-1] == '/')))
- return FNM_NOMATCH;
-
- not = (*p == '!' || *p == '^');
- if (not)
- ++p;
-
- c = *p++;
- for (;;)
- {
- register char cstart = c, cend = c;
-
- if (!(flags & FNM_NOESCAPE) && c == '\\')
- cstart = cend = *p++;
-
- cstart = cend = FOLD (cstart);
-
- if (c == '\0')
- /* [ (unterminated) loses. */
- return FNM_NOMATCH;
-
- c = *p++;
- c = FOLD (c);
-
- if ((flags & FNM_FILE_NAME) && c == '/')
- /* [/] can never match. */
- return FNM_NOMATCH;
-
- if (c == '-' && *p != ']')
- {
- cend = *p++;
- if (!(flags & FNM_NOESCAPE) && cend == '\\')
- cend = *p++;
- if (cend == '\0')
- return FNM_NOMATCH;
- cend = FOLD (cend);
-
- c = *p++;
- }
-
- if (FOLD (*n) >= cstart && FOLD (*n) <= cend)
- goto matched;
-
- if (c == ']')
- break;
- }
- if (!not)
- return FNM_NOMATCH;
- break;
-
- matched:;
- /* Skip the rest of the [...] that already matched. */
- while (c != ']')
- {
- if (c == '\0')
- /* [... (unterminated) loses. */
- return FNM_NOMATCH;
-
- c = *p++;
- if (!(flags & FNM_NOESCAPE) && c == '\\')
- /* XXX 1003.2d11 is unclear if this is right. */
- ++p;
- }
- if (not)
- return FNM_NOMATCH;
- }
- break;
-
- default:
- if (c != FOLD (*n))
- return FNM_NOMATCH;
- }
-
- ++n;
- }
-
- if (*n == '\0')
- return 0;
-
- if ((flags & FNM_LEADING_DIR) && *n == '/')
- /* The FNM_LEADING_DIR flag says that "foo*" matches "foobar/frobozz". */
- return 0;
-
- return FNM_NOMATCH;
-}
-
-#else /* HAVE_FNMATCH */
- void fnmatch_dummy(void) {}
-#endif
diff --git a/source/lib/hash.c b/source/lib/hash.c
deleted file mode 100644
index ccaf65b55a0..00000000000
--- a/source/lib/hash.c
+++ /dev/null
@@ -1,320 +0,0 @@
-/*
- Unix SMB/Netbios implementation.
- Version 2.0
-
- Copyright (C) Ying Chen 2000.
- Copyright (C) Jeremy Allison 2000.
- - added some defensive programming.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-*/
-
-/*
- * NB. We may end up replacing this functionality in a future 2.x
- * release to reduce the number of hashing/lookup methods we support. JRA.
- */
-
-#include "includes.h"
-
-extern int DEBUGLEVEL;
-
-#define NUM_PRIMES 11
-
-static BOOL enlarge_hash_table(hash_table *table);
-static int primes[NUM_PRIMES] =
- {17, 37, 67, 131, 257, 521, 1031, 2053, 4099, 8209, 16411};
-
-/****************************************************************************
- * This function initializes the hash table.
- * This hash function hashes on string keys.
- * This number of hash buckets is always rounded up to a power of
- * 2 first, then to a prime number that is large than the power of two.
- * Input:
- * table -- the hash table pointer.
- * num_buckets -- the number of buckets to be allocated. This
- * hash function can dynamically increase its size when the
- * the hash table size becomes small. There is a MAX hash table
- * size defined in hash.h.
- * compare_func -- the function pointer to a comparison function
- * used by the hash key comparison.
- ****************************************************************************
- */
-
-BOOL hash_table_init(hash_table *table, int num_buckets, compare_function compare_func)
-{
- int i;
- ubi_dlList *bucket;
-
- table->num_elements = 0;
- table->size = 2;
- table->comp_func = compare_func;
- while (table->size < num_buckets)
- table->size <<= 1;
- for (i = 0; i < NUM_PRIMES; i++) {
- if (primes[i] > table->size) {
- table->size = primes[i];
- break;
- }
- }
-
- DEBUG(5, ("Hash size = %d.\n", table->size));
-
- if(!(table->buckets = (ubi_dlList *) malloc(sizeof(ubi_dlList) * table->size))) {
- DEBUG(0,("hash_table_init: malloc fail !\n"));
- return False;
- }
- ubi_dlInitList(&(table->lru_chain));
- for (i=0, bucket = table->buckets; i < table->size; i++, bucket++)
- ubi_dlInitList(bucket);
-
- return True;
-}
-
-/*
- **************************************************************
- * Compute a hash value based on a string key value.
- * Make the string key into an array of int's if possible.
- * For the last few chars that cannot be int'ed, use char instead.
- * The function returns the bucket index number for the hashed
- * key.
- **************************************************************
- */
-
-int string_hash(int hash_size, const char *key)
-{
- int j=0;
- while (*key)
- j = j*10 + *key++;
- return(((j>=0)?j:(-j)) % hash_size);
-}
-
-/* *************************************************************************
- * Search the hash table for the entry in the hash chain.
- * The function returns the pointer to the
- * element found in the chain or NULL if none is found.
- * If the element is found, the element is also moved to
- * the head of the LRU list.
- *
- * Input:
- * table -- The hash table where the element is stored in.
- * hash_chain -- The pointer to the bucket that stores the
- * element to be found.
- * key -- The hash key to be found.
- ***************************************************************************
- */
-
-static hash_element *hash_chain_find(hash_table *table, ubi_dlList *hash_chain, char *key)
-{
- hash_element *hash_elem;
- ubi_dlNodePtr lru_item;
- int i = 0;
-
- for (hash_elem = (hash_element *)(ubi_dlFirst(hash_chain)); i < hash_chain->count;
- i++, hash_elem = (hash_element *)(ubi_dlNext(hash_elem))) {
- if ((table->comp_func)(hash_elem->key, key) == 0) {
- /* Move to the head of the lru List. */
- lru_item = ubi_dlRemove(&(table->lru_chain), &(hash_elem->lru_link.lru_link));
- ubi_dlAddHead(&(table->lru_chain), lru_item);
- return(hash_elem);
- }
- }
- return ((hash_element *) NULL);
-}
-
-/* ***************************************************************************
- *
- * Lookup a hash table for an element with key.
- * The function returns a pointer to the hash element.
- * If no element is found, the function returns NULL.
- *
- * Input:
- * table -- The hash table to be searched on.
- * key -- The key to be found.
- *****************************************************************************
- */
-
-hash_element *hash_lookup(hash_table *table, char *key)
-{
- return (hash_chain_find(table, &(table->buckets[string_hash(table->size, key)]), key));
-}
-
-/* ***************************************************************
- *
- * This function first checks if an element with key "key"
- * exists in the hash table. If so, the function moves the
- * element to the front of the LRU list. Otherwise, a new
- * hash element corresponding to "value" and "key" is allocated
- * and inserted into the hash table. The new elements are
- * always inserted in the LRU order to the LRU list as well.
- *
- * Input:
- * table -- The hash table to be inserted in.
- * value -- The content of the element to be inserted.
- * key -- The key of the new element to be inserted.
- *
- ****************************************************************
- */
-
-hash_element *hash_insert(hash_table *table, char *value, char *key)
-{
- hash_element *hash_elem;
- ubi_dlNodePtr lru_item;
- ubi_dlList *bucket;
-
- /*
- * If the hash table size has not reached the MAX_HASH_TABLE_SIZE,
- * the hash table may be enlarged if the current hash table is full.
- * If the hash table size has reached the MAX_HASH_TABLE_SIZE,
- * use LRU to remove the oldest element from the hash table.
- */
-
- if ((table->num_elements >= table->size) &&
- (table->num_elements < MAX_HASH_TABLE_SIZE)) {
- if(!enlarge_hash_table(table))
- return (hash_element *)NULL;
- table->num_elements += 1;
- } else if (table->num_elements >= MAX_HASH_TABLE_SIZE) {
- /* Do an LRU replacement. */
- lru_item = ubi_dlLast(&(table->lru_chain));
- hash_elem = (hash_element *)(((lru_node *)lru_item)->hash_elem);
- bucket = hash_elem->bucket;
- ubi_dlRemThis(&(table->lru_chain), &(hash_elem->lru_link.lru_link));
- ubi_dlRemThis(bucket, (ubi_dlNodePtr)hash_elem);
- free((char*)(hash_elem->value));
- free(hash_elem);
- } else {
- table->num_elements += 1;
- }
-
- bucket = &(table->buckets[string_hash(table->size, key)]);
-
- /* Since we only have 1-byte for the key string, we need to
- * allocate extra space in the hash_element to store the entire key
- * string.
- */
-
- if(!(hash_elem = (hash_element *) malloc(sizeof(hash_element) + strlen(key)))) {
- DEBUG(0,("hash_insert: malloc fail !\n"));
- return (hash_element *)NULL;
- }
-
- safe_strcpy((char *) hash_elem->key, key, strlen(key)+1);
-
- hash_elem->value = (char *)value;
- hash_elem->bucket = bucket;
- /* Insert in front of the lru list and the bucket list. */
- ubi_dlAddHead(bucket, hash_elem);
- hash_elem->lru_link.hash_elem = hash_elem;
- ubi_dlAddHead(&(table->lru_chain), &(hash_elem->lru_link.lru_link));
-
- return(hash_elem);
-}
-
-/* **************************************************************************
- *
- * Remove a hash element from the hash table. The hash element is
- * removed from both the LRU list and the hash bucket chain.
- *
- * Input:
- * table -- the hash table to be manipulated on.
- * hash_elem -- the element to be removed.
- **************************************************************************
- */
-
-void hash_remove(hash_table *table, hash_element *hash_elem)
-{
- if (hash_elem) {
- ubi_dlRemove(&(table->lru_chain), &(hash_elem->lru_link.lru_link));
- ubi_dlRemove(hash_elem->bucket, (ubi_dlNodePtr) hash_elem);
- if(hash_elem->value)
- free((char *)(hash_elem->value));
- if(hash_elem)
- free((char *) hash_elem);
- table->num_elements--;
- }
-}
-
-/* ******************************************************************
- * Increase the hash table size if it is too small.
- * The hash table size is increased by the HASH_TABLE_INCREMENT
- * ratio.
- * Input:
- * table -- the hash table to be enlarged.
- ******************************************************************
- */
-
-static BOOL enlarge_hash_table(hash_table *table)
-{
- hash_element *hash_elem;
- int size, hash_value;
- ubi_dlList *buckets;
- ubi_dlList *old_bucket;
- ubi_dlList *bucket;
- ubi_dlList lru_chain;
-
- buckets = table->buckets;
- lru_chain = table->lru_chain;
- size = table->size;
-
- /* Reinitialize the hash table. */
- if(!hash_table_init(table, table->size * HASH_TABLE_INCREMENT, table->comp_func))
- return False;
-
- for (old_bucket = buckets; size > 0; size--, old_bucket++) {
- while (old_bucket->count != 0) {
- hash_elem = (hash_element *) ubi_dlRemHead(old_bucket);
- ubi_dlRemove(&lru_chain, &(hash_elem->lru_link.lru_link));
- hash_value = string_hash(table->size, (char *) hash_elem->key);
- bucket = &(table->buckets[hash_value]);
- ubi_dlAddHead(bucket, hash_elem);
- ubi_dlAddHead(&(table->lru_chain), &(hash_elem->lru_link.lru_link));
- hash_elem->bucket = bucket;
- hash_elem->lru_link.hash_elem = hash_elem;
- table->num_elements++;
- }
- }
- if(buckets)
- free((char *) buckets);
-
- return True;
-}
-
-/* **********************************************************************
- *
- * Remove everything from a hash table and free up the memory it
- * occupies.
- * Input:
- * table -- the hash table to be cleared.
- *
- *************************************************************************
- */
-
-void hash_clear(hash_table *table)
-{
- int i;
- ubi_dlList *bucket = table->buckets;
- hash_element *hash_elem;
- for (i = 0; i < table->size; bucket++, i++) {
- while (bucket->count != 0) {
- hash_elem = (hash_element *) ubi_dlRemHead(bucket);
- if(hash_elem->value)
- free((char *)(hash_elem->value));
- if(hash_elem)
- free((char *)hash_elem);
- }
- }
- if(table->buckets)
- free((char *) table->buckets);
-}
diff --git a/source/lib/interfaces.c b/source/lib/interfaces.c
deleted file mode 100644
index e7b9efa1f0a..00000000000
--- a/source/lib/interfaces.c
+++ /dev/null
@@ -1,404 +0,0 @@
-/*
- Unix SMB/Netbios implementation.
- Version 2.0
- return a list of network interfaces
- Copyright (C) Andrew Tridgell 1998
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-*/
-
-
-/* working out the interfaces for a OS is an incredibly non-portable
- thing. We have several possible implementations below, and autoconf
- tries each of them to see what works
-
- Note that this file does _not_ include includes.h. That is so this code
- can be called directly from the autoconf tests. That also means
- this code cannot use any of the normal Samba debug stuff or defines.
- This is standalone code.
-
-*/
-
-#include <unistd.h>
-#include <stdio.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <netdb.h>
-#include <sys/ioctl.h>
-#ifdef HAVE_SYS_TIME_H
-#include <sys/time.h>
-#endif
-#include <net/if.h>
-
-#ifndef SIOCGIFCONF
-#include <sys/sockio.h>
-#endif
-
-#ifdef AUTOCONF_TEST
-struct iface_struct {
- char name[16];
- struct in_addr ip;
- struct in_addr netmask;
-};
-#else
-#include "config.h"
-#include "interfaces.h"
-#endif
-
-#ifdef HAVE_STDLIB_H
-#include <stdlib.h>
-#endif
-
-#ifdef HAVE_STRING_H
-#include <string.h>
-#endif
-
-#ifdef HAVE_STRINGS_H
-#include <strings.h>
-#endif
-
-#ifdef __COMPAR_FN_T
-#define QSORT_CAST (__compar_fn_t)
-#endif
-
-#ifndef QSORT_CAST
-#define QSORT_CAST (int (*)(const void *, const void *))
-#endif
-
-#if HAVE_IFACE_IFCONF
-
-/* this works for Linux 2.2, Solaris 2.5, SunOS4, HPUX 10.20, OSF1
- V4.0, Ultrix 4.4, SCO Unix 3.2, IRIX 6.4 and FreeBSD 3.2.
-
- It probably also works on any BSD style system. */
-
-/****************************************************************************
- get the netmask address for a local interface
-****************************************************************************/
-static int _get_interfaces(struct iface_struct *ifaces, int max_interfaces)
-{
- struct ifconf ifc;
- char buff[8192];
- int fd, i, n;
- struct ifreq *ifr=NULL;
- int total = 0;
- struct in_addr ipaddr;
- struct in_addr nmask;
- char *iname;
-
- if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {
- return -1;
- }
-
- ifc.ifc_len = sizeof(buff);
- ifc.ifc_buf = buff;
-
- if (ioctl(fd, SIOCGIFCONF, &ifc) != 0) {
- close(fd);
- return -1;
- }
-
- ifr = ifc.ifc_req;
-
- n = ifc.ifc_len / sizeof(struct ifreq);
-
- /* Loop through interfaces, looking for given IP address */
- for (i=n-1;i>=0 && total < max_interfaces;i--) {
- if (ioctl(fd, SIOCGIFADDR, &ifr[i]) != 0) {
- continue;
- }
-
- iname = ifr[i].ifr_name;
- ipaddr = (*(struct sockaddr_in *)&ifr[i].ifr_addr).sin_addr;
-
- if (ioctl(fd, SIOCGIFFLAGS, &ifr[i]) != 0) {
- continue;
- }
-
- if (!(ifr[i].ifr_flags & IFF_UP)) {
- continue;
- }
-
- if (ioctl(fd, SIOCGIFNETMASK, &ifr[i]) != 0) {
- continue;
- }
-
- nmask = ((struct sockaddr_in *)&ifr[i].ifr_addr)->sin_addr;
-
- strncpy(ifaces[total].name, iname, sizeof(ifaces[total].name)-1);
- ifaces[total].name[sizeof(ifaces[total].name)-1] = 0;
- ifaces[total].ip = ipaddr;
- ifaces[total].netmask = nmask;
- total++;
- }
-
- close(fd);
-
- return total;
-}
-
-#elif HAVE_IFACE_IFREQ
-
-#ifndef I_STR
-#include <sys/stropts.h>
-#endif
-
-/****************************************************************************
-this should cover most of the streams based systems
-Thanks to Andrej.Borsenkow@mow.siemens.ru for several ideas in this code
-****************************************************************************/
-static int _get_interfaces(struct iface_struct *ifaces, int max_interfaces)
-{
- struct ifreq ifreq;
- struct strioctl strioctl;
- char buff[8192];
- int fd, i, n;
- struct ifreq *ifr=NULL;
- int total = 0;
- struct in_addr ipaddr;
- struct in_addr nmask;
- char *iname;
-
- if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {
- return -1;
- }
-
- strioctl.ic_cmd = SIOCGIFCONF;
- strioctl.ic_dp = buff;
- strioctl.ic_len = sizeof(buff);
- if (ioctl(fd, I_STR, &strioctl) < 0) {
- close(fd);
- return -1;
- }
-
- /* we can ignore the possible sizeof(int) here as the resulting
- number of interface structures won't change */
- n = strioctl.ic_len / sizeof(struct ifreq);
-
- /* we will assume that the kernel returns the length as an int
- at the start of the buffer if the offered size is a
- multiple of the structure size plus an int */
- if (n*sizeof(struct ifreq) + sizeof(int) == strioctl.ic_len) {
- ifr = (struct ifreq *)(buff + sizeof(int));
- } else {
- ifr = (struct ifreq *)buff;
- }
-
- /* Loop through interfaces */
-
- for (i = 0; i<n && total < max_interfaces; i++) {
- ifreq = ifr[i];
-
- strioctl.ic_cmd = SIOCGIFFLAGS;
- strioctl.ic_dp = (char *)&ifreq;
- strioctl.ic_len = sizeof(struct ifreq);
- if (ioctl(fd, I_STR, &strioctl) != 0) {
- continue;
- }
-
- if (!(ifreq.ifr_flags & IFF_UP)) {
- continue;
- }
-
- strioctl.ic_cmd = SIOCGIFADDR;
- strioctl.ic_dp = (char *)&ifreq;
- strioctl.ic_len = sizeof(struct ifreq);
- if (ioctl(fd, I_STR, &strioctl) != 0) {
- continue;
- }
-
- ipaddr = (*(struct sockaddr_in *) &ifreq.ifr_addr).sin_addr;
- iname = ifreq.ifr_name;
-
- strioctl.ic_cmd = SIOCGIFNETMASK;
- strioctl.ic_dp = (char *)&ifreq;
- strioctl.ic_len = sizeof(struct ifreq);
- if (ioctl(fd, I_STR, &strioctl) != 0) {
- continue;
- }
-
- nmask = ((struct sockaddr_in *)&ifreq.ifr_addr)->sin_addr;
-
- strncpy(ifaces[total].name, iname, sizeof(ifaces[total].name)-1);
- ifaces[total].name[sizeof(ifaces[total].name)-1] = 0;
- ifaces[total].ip = ipaddr;
- ifaces[total].netmask = nmask;
-
- total++;
- }
-
- close(fd);
-
- return total;
-}
-
-#elif HAVE_IFACE_AIX
-
-/****************************************************************************
-this one is for AIX (tested on 4.2)
-****************************************************************************/
-static int _get_interfaces(struct iface_struct *ifaces, int max_interfaces)
-{
- char buff[8192];
- int fd, i;
- struct ifconf ifc;
- struct ifreq *ifr=NULL;
- struct in_addr ipaddr;
- struct in_addr nmask;
- char *iname;
- int total = 0;
-
- if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {
- return -1;
- }
-
-
- ifc.ifc_len = sizeof(buff);
- ifc.ifc_buf = buff;
-
- if (ioctl(fd, SIOCGIFCONF, &ifc) != 0) {
- close(fd);
- return -1;
- }
-
- ifr = ifc.ifc_req;
-
- /* Loop through interfaces */
- i = ifc.ifc_len;
-
- while (i > 0 && total < max_interfaces) {
- unsigned inc;
-
- inc = ifr->ifr_addr.sa_len;
-
- if (ioctl(fd, SIOCGIFADDR, ifr) != 0) {
- goto next;
- }
-
- ipaddr = (*(struct sockaddr_in *) &ifr->ifr_addr).sin_addr;
- iname = ifr->ifr_name;
-
- if (ioctl(fd, SIOCGIFFLAGS, ifr) != 0) {
- goto next;
- }
-
- if (!(ifr->ifr_flags & IFF_UP)) {
- goto next;
- }
-
- if (ioctl(fd, SIOCGIFNETMASK, ifr) != 0) {
- goto next;
- }
-
- nmask = ((struct sockaddr_in *)&ifr->ifr_addr)->sin_addr;
-
- strncpy(ifaces[total].name, iname, sizeof(ifaces[total].name)-1);
- ifaces[total].name[sizeof(ifaces[total].name)-1] = 0;
- ifaces[total].ip = ipaddr;
- ifaces[total].netmask = nmask;
-
- total++;
-
- next:
- /*
- * Patch from Archie Cobbs (archie@whistle.com). The
- * addresses in the SIOCGIFCONF interface list have a
- * minimum size. Usually this doesn't matter, but if
- * your machine has tunnel interfaces, etc. that have
- * a zero length "link address", this does matter. */
-
- if (inc < sizeof(ifr->ifr_addr))
- inc = sizeof(ifr->ifr_addr);
- inc += IFNAMSIZ;
-
- ifr = (struct ifreq*) (((char*) ifr) + inc);
- i -= inc;
- }
-
-
- close(fd);
- return total;
-}
-
-#else /* a dummy version */
-static int _get_interfaces(struct iface_struct *ifaces, int max_interfaces)
-{
- return -1;
-}
-#endif
-
-
-static int iface_comp(struct iface_struct *i1, struct iface_struct *i2)
-{
- int r;
- r = strcmp(i1->name, i2->name);
- if (r) return r;
- r = ntohl(i1->ip.s_addr) - ntohl(i2->ip.s_addr);
- if (r) return r;
- r = ntohl(i1->netmask.s_addr) - ntohl(i2->netmask.s_addr);
- return r;
-}
-
-/* this wrapper is used to remove duplicates from the interface list generated
- above */
-int get_interfaces(struct iface_struct *ifaces, int max_interfaces)
-{
- int total, i, j;
-
- total = _get_interfaces(ifaces, max_interfaces);
- if (total <= 0) return total;
-
- /* now we need to remove duplicates */
- qsort(ifaces, total, sizeof(ifaces[0]), QSORT_CAST iface_comp);
-
- for (i=1;i<total;) {
- if (iface_comp(&ifaces[i-1], &ifaces[i]) == 0) {
- for (j=i-1;j<total-1;j++) {
- ifaces[j] = ifaces[j+1];
- }
- total--;
- } else {
- i++;
- }
- }
-
- return total;
-}
-
-
-#ifdef AUTOCONF_TEST
-/* this is the autoconf driver to test get_interfaces() */
-
-#define MAX_INTERFACES 128
-
- int main()
-{
- struct iface_struct ifaces[MAX_INTERFACES];
- int total = get_interfaces(ifaces, MAX_INTERFACES);
- int i;
-
- printf("got %d interfaces:\n", total);
- if (total <= 0) exit(1);
-
- for (i=0;i<total;i++) {
- printf("%-10s ", ifaces[i].name);
- printf("IP=%s ", inet_ntoa(ifaces[i].ip));
- printf("NETMASK=%s\n", inet_ntoa(ifaces[i].netmask));
- }
- return 0;
-}
-#endif
diff --git a/source/lib/talloc.c b/source/lib/talloc.c
deleted file mode 100644
index 9ba793092d3..00000000000
--- a/source/lib/talloc.c
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- Unix SMB/Netbios implementation.
- Version 3.0
- Samba temporary memory allocation functions
- Copyright (C) Andrew Tridgell 2000
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-*/
-
-/* this is a very simple temporary memory allocator. To use it do the following:
-
- 1) when you first want to allocate a pool of meomry use
- talloc_init() and save the resulting context pointer somewhere
-
- 2) to allocate memory use talloc()
-
- 3) when _all_ of the memory allocated using this context is no longer needed
- use talloc_destroy()
-
- talloc does not zero the memory. It guarantees memory of a
- TALLOC_ALIGN alignment
-*/
-
-#include "includes.h"
-
-#define TALLOC_ALIGN 32
-#define TALLOC_CHUNK_SIZE (0x2000)
-
-/* initialissa talloc context. */
-TALLOC_CTX *talloc_init(void)
-{
- TALLOC_CTX *t;
-
- t = (TALLOC_CTX *)malloc(sizeof(*t));
- if (!t) return NULL;
-
- t->list = NULL;
-
- return t;
-}
-
-/* allocate a bit of memory from the specified pool */
-void *talloc(TALLOC_CTX *t, size_t size)
-{
- void *p;
-
- size = (size + TALLOC_ALIGN) & (~TALLOC_ALIGN-1);
-
- if (!t->list || (t->list->total_size - t->list->alloc_size) < size) {
- struct talloc_chunk *c;
- size_t asize = (size + TALLOC_CHUNK_SIZE) & ~(TALLOC_CHUNK_SIZE-1);
-
- c = (struct talloc_chunk *)malloc(sizeof(*c));
- if (!c) return NULL;
- c->next = t->list;
- c->ptr = (void *)malloc(asize);
- if (!c->ptr) {
- free(c);
- return NULL;
- }
- c->alloc_size = 0;
- c->total_size = asize;
- t->list = c;
- }
-
- p = ((char *)t->list->ptr) + t->list->alloc_size;
- t->list->alloc_size += size;
- return p;
-}
-
-/* destroy a whole pool */
-void talloc_destroy(TALLOC_CTX *t)
-{
- struct talloc_chunk *c;
-
- while (t->list) {
- c = t->list->next;
- free(t->list->ptr);
- free(t->list);
- t->list = c;
- }
-
- free(t);
-}