diff options
author | Elliott Hughes <enh@google.com> | 2014-06-24 23:34:23 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2014-06-24 07:39:41 +0000 |
commit | a02b96d06acdeb377ffa05525b3b912938fe685c (patch) | |
tree | 6beef5cde9e64354cf498e0dbfcc8f63e343d41c | |
parent | 397f843f6c8dc55a48cad015eecbb74f902145b9 (diff) | |
parent | 09cda4fad9681e8500485ef0b71974d16c28fcc3 (diff) | |
download | android_external_dhcpcd-a02b96d06acdeb377ffa05525b3b912938fe685c.tar.gz android_external_dhcpcd-a02b96d06acdeb377ffa05525b3b912938fe685c.tar.bz2 android_external_dhcpcd-a02b96d06acdeb377ffa05525b3b912938fe685c.zip |
Merge "Move dhcpcd off its own getline."
-rw-r--r-- | Android.mk | 2 | ||||
-rw-r--r-- | compat/arc4random.c | 158 | ||||
-rw-r--r-- | compat/arc4random.h | 36 | ||||
-rw-r--r-- | compat/getline.c | 75 | ||||
-rw-r--r-- | compat/getline.h | 36 | ||||
-rw-r--r-- | compat/linkaddr.c | 120 | ||||
-rw-r--r-- | compat/strlcpy.c | 51 | ||||
-rw-r--r-- | compat/strlcpy.h | 34 | ||||
-rw-r--r-- | config.h | 11 |
9 files changed, 2 insertions, 521 deletions
@@ -8,7 +8,7 @@ hooks_target := $(etc_dir)/$(hooks_dir) include $(CLEAR_VARS) LOCAL_SRC_FILES := arp.c bind.c common.c control.c dhcp.c dhcpcd.c duid.c \ eloop.c if-options.c if-pref.c ipv4ll.c net.c signals.c configure.c \ - if-linux.c if-linux-wireless.c lpf.c compat/getline.c \ + if-linux.c if-linux-wireless.c lpf.c \ platform-linux.c compat/closefrom.c ifaddrs.c ipv6rs.c LOCAL_SHARED_LIBRARIES := libc libcutils libnetutils diff --git a/compat/arc4random.c b/compat/arc4random.c deleted file mode 100644 index 48ef29d..0000000 --- a/compat/arc4random.c +++ /dev/null @@ -1,158 +0,0 @@ -/* - * Arc4 random number generator for OpenBSD. - * Copyright 1996 David Mazieres <dm@lcs.mit.edu>. - * - * Modification and redistribution in source and binary forms is - * permitted provided that due credit is given to the author and the - * OpenBSD project by leaving this copyright notice intact. - */ - -/* - * This code is derived from section 17.1 of Applied Cryptography, - * second edition, which describes a stream cipher allegedly - * compatible with RSA Labs "RC4" cipher (the actual description of - * which is a trade secret). The same algorithm is used as a stream - * cipher called "arcfour" in Tatu Ylonen's ssh package. - * - * Here the stream cipher has been modified always to include the time - * when initializing the state. That makes it impossible to - * regenerate the same random sequence twice, so this can't be used - * for encryption, but will generate good random numbers. - * - * RC4 is a registered trademark of RSA Laboratories. - */ - -#include <sys/time.h> - -#include <fcntl.h> -#include <stdint.h> -#include <stdlib.h> -#include <unistd.h> - -#include "arc4random.h" - -struct arc4_stream { - uint8_t i; - uint8_t j; - uint8_t s[256]; -}; - -static int rs_initialized; -static struct arc4_stream rs; -static int arc4_count; - -static void -arc4_init(struct arc4_stream *as) -{ - int n; - - for (n = 0; n < 256; n++) - as->s[n] = n; - as->i = 0; - as->j = 0; -} - -static void -arc4_addrandom(struct arc4_stream *as, unsigned char *dat, int datlen) -{ - int n; - uint8_t si; - - as->i--; - for (n = 0; n < 256; n++) { - as->i = (as->i + 1); - si = as->s[as->i]; - as->j = (as->j + si + dat[n % datlen]); - as->s[as->i] = as->s[as->j]; - as->s[as->j] = si; - } - as->j = as->i; -} - -static uint8_t -arc4_getbyte(struct arc4_stream *as) -{ - uint8_t si, sj; - - as->i = (as->i + 1); - si = as->s[as->i]; - as->j = (as->j + si); - sj = as->s[as->j]; - as->s[as->i] = sj; - as->s[as->j] = si; - return (as->s[(si + sj) & 0xff]); -} - -static uint32_t -arc4_getword(struct arc4_stream *as) -{ - uint32_t val; - - val = arc4_getbyte(as) << 24; - val |= arc4_getbyte(as) << 16; - val |= arc4_getbyte(as) << 8; - val |= arc4_getbyte(as); - return val; -} - -static void -arc4_stir(struct arc4_stream *as) -{ - int fd; - struct { - struct timeval tv; - unsigned int rnd[(128 - sizeof(struct timeval)) / - sizeof(unsigned int)]; - } rdat; - int n; - - gettimeofday(&rdat.tv, NULL); - fd = open("/dev/urandom", O_RDONLY); - if (fd != -1) { - n = read(fd, rdat.rnd, sizeof(rdat.rnd)); - close(fd); - } - - /* fd < 0? Ah, what the heck. We'll just take - * whatever was on the stack... */ - arc4_addrandom(as, (void *) &rdat, sizeof(rdat)); - - /* - * Throw away the first N words of output, as suggested in the - * paper "Weaknesses in the Key Scheduling Algorithm of RC4" - * by Fluher, Mantin, and Shamir. (N = 256 in our case.) - */ - for (n = 0; n < 256 * 4; n++) - arc4_getbyte(as); - arc4_count = 1600000; -} - -void -arc4random_stir() -{ - - if (!rs_initialized) { - arc4_init(&rs); - rs_initialized = 1; - } - arc4_stir(&rs); -} - -void -arc4random_addrandom(unsigned char *dat, int datlen) -{ - - if (!rs_initialized) - arc4random_stir(); - arc4_addrandom(&rs, dat, datlen); -} - -uint32_t -arc4random() -{ - - arc4_count -= 4; - if (!rs_initialized || arc4_count <= 0) - arc4random_stir(); - return arc4_getword(&rs); -} diff --git a/compat/arc4random.h b/compat/arc4random.h deleted file mode 100644 index 2b10902..0000000 --- a/compat/arc4random.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * dhcpcd - DHCP client daemon - * Copyright (c) 2006-2010 Roy Marples <roy@marples.name> - * All rights reserved - - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef ARC4RANDOM_H -#define ARC4RANDOM_H - -#include <stdint.h> - -void arc4random_stir(void); -void arc4random_addrandom(unsigned char *, int); -uint32_t arc4random(void); -#endif diff --git a/compat/getline.c b/compat/getline.c deleted file mode 100644 index 3f01b66..0000000 --- a/compat/getline.c +++ /dev/null @@ -1,75 +0,0 @@ -/* - * dhcpcd - DHCP client daemon - * Copyright (c) 2006-2009 Roy Marples <roy@marples.name> - * All rights reserved - - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include <errno.h> -#include <stdint.h> -#include <stdlib.h> -#include <stdio.h> -#include <string.h> - -#include "getline.h" - -/* Redefine a small buffer for our simple text config files */ -#undef BUFSIZ -#define BUFSIZ 128 - -ssize_t -getline(char ** __restrict buf, size_t * __restrict buflen, - FILE * __restrict fp) -{ - size_t bytes, newlen; - char *newbuf, *p; - - if (buf == NULL || buflen == NULL) { - errno = EINVAL; - return -1; - } - if (*buf == NULL) - *buflen = 0; - - bytes = 0; - do { - if (feof(fp)) - break; - if (*buf == NULL || bytes != 0) { - newlen = *buflen + BUFSIZ; - newbuf = realloc(*buf, newlen); - if (newbuf == NULL) - return -1; - *buf = newbuf; - *buflen = newlen; - } - p = *buf + bytes; - memset(p, 0, BUFSIZ); - if (fgets(p, BUFSIZ, fp) == NULL) - break; - bytes += strlen(p); - } while (bytes == 0 || *(*buf + (bytes - 1)) != '\n'); - if (bytes == 0) - return -1; - return bytes; -} diff --git a/compat/getline.h b/compat/getline.h deleted file mode 100644 index 390632c..0000000 --- a/compat/getline.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * dhcpcd - DHCP client daemon - * Copyright (c) 2006-2009 Roy Marples <roy@marples.name> - * All rights reserved - - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef GETLINE_H -#define GETLINE_H - -#include <sys/types.h> -#include <stdio.h> - -ssize_t getline(char ** __restrict buf, size_t * __restrict buflen, - FILE * __restrict fp); -#endif diff --git a/compat/linkaddr.c b/compat/linkaddr.c deleted file mode 100644 index c4e6fa5..0000000 --- a/compat/linkaddr.c +++ /dev/null @@ -1,120 +0,0 @@ -/*- - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include <sys/cdefs.h> -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)linkaddr.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ - -#include <sys/types.h> -#include <sys/socket.h> -#include <net/if_dl.h> - -#include <string.h> - -/* States*/ -#define NAMING 0 -#define GOTONE 1 -#define GOTTWO 2 -#define RESET 3 -/* Inputs */ -#define DIGIT (4*0) -#define END (4*1) -#define DELIM (4*2) -#define LETTER (4*3) - -void -link_addr(addr, sdl) - const char *addr; - struct sockaddr_dl *sdl; -{ - char *cp = sdl->sdl_data; - char *cplim = sdl->sdl_len + (char *)(void *)sdl; - int byte = 0, state = NAMING; - int newaddr = 0; - - (void)memset(&sdl->sdl_family, 0, (size_t)sdl->sdl_len - 1); - sdl->sdl_family = AF_LINK; - do { - state &= ~LETTER; - if ((*addr >= '0') && (*addr <= '9')) { - newaddr = *addr - '0'; - } else if ((*addr >= 'a') && (*addr <= 'f')) { - newaddr = *addr - 'a' + 10; - } else if ((*addr >= 'A') && (*addr <= 'F')) { - newaddr = *addr - 'A' + 10; - } else if (*addr == 0) { - state |= END; - } else if (state == NAMING && - (((*addr >= 'A') && (*addr <= 'Z')) || - ((*addr >= 'a') && (*addr <= 'z')))) - state |= LETTER; - else - state |= DELIM; - addr++; - switch (state /* | INPUT */) { - case NAMING | DIGIT: - case NAMING | LETTER: - *cp++ = addr[-1]; - continue; - case NAMING | DELIM: - state = RESET; - sdl->sdl_nlen = cp - sdl->sdl_data; - continue; - case GOTTWO | DIGIT: - *cp++ = byte; - /* FALLTHROUGH */ - case RESET | DIGIT: - state = GOTONE; - byte = newaddr; - continue; - case GOTONE | DIGIT: - state = GOTTWO; - byte = newaddr + (byte << 4); - continue; - default: /* | DELIM */ - state = RESET; - *cp++ = byte; - byte = 0; - continue; - case GOTONE | END: - case GOTTWO | END: - *cp++ = byte; - /* FALLTHROUGH */ - case RESET | END: - break; - } - break; - } while (cp < cplim); - sdl->sdl_alen = cp - LLADDR(sdl); - newaddr = cp - (char *)(void *)sdl; - if ((size_t) newaddr > sizeof(*sdl)) - sdl->sdl_len = newaddr; - return; -} diff --git a/compat/strlcpy.c b/compat/strlcpy.c deleted file mode 100644 index e44d19c..0000000 --- a/compat/strlcpy.c +++ /dev/null @@ -1,51 +0,0 @@ -/* - * dhcpcd - DHCP client daemon - * Copyright (c) 2006-2009 Roy Marples <roy@marples.name> - * All rights reserved - - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include <sys/types.h> - -#include "strlcpy.h" - -size_t -strlcpy(char *dst, const char *src, size_t size) -{ - const char *s = src; - size_t n = size; - - if (n && --n) - do { - if (!(*dst++ = *src++)) - break; - } while (--n); - - if (!n) { - if (size) - *dst = '\0'; - while (*src++); - } - - return src - s - 1; -} diff --git a/compat/strlcpy.h b/compat/strlcpy.h deleted file mode 100644 index 0ff3854..0000000 --- a/compat/strlcpy.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * dhcpcd - DHCP client daemon - * Copyright (c) 2006-2009 Roy Marples <roy@marples.name> - * All rights reserved - - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef STRLCPY_H -#define STRLCPY_H - -#include <sys/types.h> - -size_t strlcpy(char *, const char *, size_t); -#endif @@ -4,15 +4,6 @@ #define LIBEXECDIR "/system/etc/dhcpcd" #define DBDIR "/data/misc/dhcp" #define RUNDIR "/data/misc/dhcp" -#include "compat/arc4random.h" #include "compat/closefrom.h" -#include "compat/strlcpy.h" -#include "compat/getline.h" -#ifndef MAX -#define MAX(a,b) ((a) >= (b) ? (a) : (b)) -#endif - -#ifndef MIN -#define MIN(a,b) ((a) <= (b) ? (a) : (b)) -#endif +#include <sys/param.h> |