[DHCP/DHCPCSVC]

- Restore the SVN history
- Part 3 of 3 (hopefully)

svn path=/trunk/; revision=47292
This commit is contained in:
Cameron Gutman 2010-05-21 20:14:56 +00:00
parent 2835ee84ed
commit 0a0e20e1bd
39 changed files with 186 additions and 2291 deletions

View file

@ -1,33 +0,0 @@
Acknowledgements:
Tinus provided the initial port of these dhclient file.
Ok I need these things:
1) Adapter concept thingy
Needs a name and index
Current IP address etc
interface_info
Must be able to get one from an adapter index or name
Must query the ip address and such
Must be able to set the address
2) System state doodad
List of adapters
List of parameter changes
List of persistent stuff
Must be able to initialize from the registry
(persistent stuff, some adapter info)
Save changes to persistent set
3) Parameter change set
TODO
4) Persistent queries
TODO

View file

@ -1,30 +0,0 @@
<?xml version="1.0"?>
<!DOCTYPE module SYSTEM "../../../tools/rbuild/project.dtd">
<module name="dhcp" type="win32cui" installbase="system32" installname="dhcp.exe">
<include base="dhcp">.</include>
<include base="dhcp">include</include>
<library>ntdll</library>
<library>ws2_32</library>
<library>iphlpapi</library>
<library>advapi32</library>
<library>oldnames</library>
<file>adapter.c</file>
<file>alloc.c</file>
<file>api.c</file>
<file>compat.c</file>
<file>dhclient.c</file>
<file>dispatch.c</file>
<file>hash.c</file>
<file>options.c</file>
<file>pipe.c</file>
<file>privsep.c</file>
<file>socket.c</file>
<file>tables.c</file>
<file>timer.c</file>
<file>util.c</file>
<file>dhcp.rc</file>
<directory name="include">
<pch>rosdhcp.h</pch>
</directory>
</module>

View file

@ -1,6 +0,0 @@
/* $Id: regsvr32.rc 12852 2005-01-06 13:58:04Z mf $ */
#define REACTOS_STR_FILE_DESCRIPTION "DHCP Client Service"
#define REACTOS_STR_INTERNAL_NAME "dhcp\0"
#define REACTOS_STR_ORIGINAL_FILENAME "dhcp.exe\0"
#include <reactos/version.rc>

View file

@ -1,72 +0,0 @@
/* $Id:$
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS Service
* FILE: subsys/system/dhcp
* PURPOSE: DHCP client service entry point
* PROGRAMMER: Art Yerkes (arty@users.sf.net)
* UPDATE HISTORY:
* Created 03/08/2005
*/
#include <windows.h>
#include "dhcpd.h"
#include "version.h"
typedef struct _DHCP_API_REQUEST {
int type;
UINT flags;
LPDHCPAPI_CLASSID class_id;
DHCP_API_PARAMS_ARRAY vendor_params;
DHCP_API_PARAMS_ARRAY general_params;
LPWSTR request_id, adapter_name;
} DHCP_API_REQUEST;
typedef struct _DHCP_MANAGED_ADAPTER {
LPWSTR adapter_name, hostname, dns_server;
UINT adapter_index;
struct sockaddr_in address, netmask;
struct interface_info *dhcp_info;
} DHCP_MANAGED_ADAPTER;
#define DHCP_REQUESTPARAM WM_USER + 0
#define DHCP_PARAMCHANGE WM_USER + 1
#define DHCP_CANCELREQUEST WM_USER + 2
#define DHCP_NOPARAMCHANGE WM_USER + 3
#define DHCP_MANAGEADAPTER WM_USER + 4
#define DHCP_UNMANAGEADAPTER WM_USER + 5
UINT DhcpEventTimer;
HANDLE DhcpServiceThread;
DWORD DhcpServiceThreadId;
LIST_ENTRY ManagedAdapters;
LRESULT WINAPI ServiceThread( PVOID Data ) {
MSG msg;
while( GetMessage( &msg, 0, 0, 0 ) ) {
switch( msg.message ) {
case DHCP_MANAGEADAPTER:
break;
case DHCP_UNMANAGEADAPTER:
break;
case DHCP_REQUESTPARAM:
break;
case DHCP_CANCELREQUEST:
break;
case DHCP_PARAMCHANGE:
break;
case DHCP_NOPARAMCHANGE:
break;
}
}
}
int main( int argc, char **argv ) {
}

View file

@ -1,57 +0,0 @@
/* cdefs.h
Standard C definitions... */
/*
* Copyright (c) 1996 The Internet Software Consortium.
* All Rights Reserved.
* Copyright (c) 1995 RadioMail Corporation. 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 RadioMail Corporation, the Internet Software
* Consortium 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 RADIOMAIL CORPORATION, THE INTERNET
* SOFTWARE CONSORTIUM 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 RADIOMAIL CORPORATION 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.
*
* This software was written for RadioMail Corporation by Ted Lemon
* under a contract with Vixie Enterprises. Further modifications have
* been made for the Internet Software Consortium under a contract
* with Vixie Laboratories.
*/
#if (defined (__GNUC__) || defined (__STDC__)) && !defined (BROKEN_ANSI)
#define PROTO(x) x
#define KandR(x)
#define ANSI_DECL(x) x
#if defined (__GNUC__)
#define INLINE inline
#else
#define INLINE
#endif /* __GNUC__ */
#else
#define PROTO(x) ()
#define KandR(x) x
#define ANSI_DECL(x)
#define INLINE
#endif /* __GNUC__ || __STDC__ */

View file

@ -1,136 +0,0 @@
/* dhctoken.h
Tokens for config file lexer and parser. */
/*
* Copyright (c) 1995, 1996, 1997, 1998, 1999
* The Internet Software Consortium. 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 Internet Software Consortium 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 INTERNET SOFTWARE CONSORTIUM 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 INTERNET SOFTWARE CONSORTIUM 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.
*
* This software has been written for the Internet Software Consortium
* by Ted Lemon <mellon@fugue.com> in cooperation with Vixie
* Enterprises. To learn more about the Internet Software Consortium,
* see ``http://www.vix.com/isc''. To learn more about Vixie
* Enterprises, see ``http://www.vix.com''.
*/
#define SEMI ';'
#define DOT '.'
#define COLON ':'
#define COMMA ','
#define SLASH '/'
#define LBRACE '{'
#define RBRACE '}'
#define FIRST_TOKEN HOST
#define HOST 256
#define HARDWARE 257
#define FILENAME 258
#define FIXED_ADDR 259
#define OPTION 260
#define ETHERNET 261
#define STRING 262
#define NUMBER 263
#define NUMBER_OR_NAME 264
#define NAME 265
#define TIMESTAMP 266
#define STARTS 267
#define ENDS 268
#define UID 269
#define CLASS 270
#define LEASE 271
#define RANGE 272
#define PACKET 273
#define CIADDR 274
#define YIADDR 275
#define SIADDR 276
#define GIADDR 277
#define SUBNET 278
#define NETMASK 279
#define DEFAULT_LEASE_TIME 280
#define MAX_LEASE_TIME 281
#define VENDOR_CLASS 282
#define USER_CLASS 283
#define SHARED_NETWORK 284
#define SERVER_NAME 285
#define DYNAMIC_BOOTP 286
#define SERVER_IDENTIFIER 287
#define DYNAMIC_BOOTP_LEASE_CUTOFF 288
#define DYNAMIC_BOOTP_LEASE_LENGTH 289
#define BOOT_UNKNOWN_CLIENTS 290
#define NEXT_SERVER 291
#define TOKEN_RING 292
#define GROUP 293
#define ONE_LEASE_PER_CLIENT 294
#define GET_LEASE_HOSTNAMES 295
#define USE_HOST_DECL_NAMES 296
#define SEND 297
#define CLIENT_IDENTIFIER 298
#define REQUEST 299
#define REQUIRE 300
#define TIMEOUT 301
#define RETRY 302
#define SELECT_TIMEOUT 303
#define SCRIPT 304
#define INTERFACE 305
#define RENEW 306
#define REBIND 307
#define EXPIRE 308
#define UNKNOWN_CLIENTS 309
#define ALLOW 310
#define BOOTP 311
#define DENY 312
#define BOOTING 313
#define DEFAULT 314
#define MEDIA 315
#define MEDIUM 316
#define ALIAS 317
#define REBOOT 318
#define ABANDONED 319
#define BACKOFF_CUTOFF 320
#define INITIAL_INTERVAL 321
#define NAMESERVER 322
#define DOMAIN 323
#define SEARCH 324
#define SUPERSEDE 325
#define APPEND 326
#define PREPEND 327
#define HOSTNAME 328
#define CLIENT_HOSTNAME 329
#define REJECT 330
#define FDDI 331
#define USE_LEASE_ADDR_FOR_DEFAULT_ROUTE 332
#define AUTHORITATIVE 333
#define TOKEN_NOT 334
#define ALWAYS_REPLY_RFC1048 335
#define is_identifier(x) ((x) >= FIRST_TOKEN && \
(x) != STRING && \
(x) != NUMBER && \
(x) != EOF)

View file

@ -1,52 +0,0 @@
/* inet.h
Portable definitions for internet addresses */
/*
* Copyright (c) 1996 The Internet Software Consortium. 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 Internet Software Consortium 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 INTERNET SOFTWARE CONSORTIUM 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 INTERNET SOFTWARE CONSORTIUM 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.
*
* This software has been written for the Internet Software Consortium
* by Ted Lemon <mellon@fugue.com> in cooperation with Vixie
* Enterprises. To learn more about the Internet Software Consortium,
* see ``http://www.vix.com/isc''. To learn more about Vixie
* Enterprises, see ``http://www.vix.com''.
*/
/* An internet address of up to 128 bits. */
typedef struct _iaddr {
int len;
unsigned char iabuf [16];
} iaddr;
typedef struct _iaddrlist {
struct _iaddrlist *next;
iaddr addr;
} iaddrlist;

View file

@ -1,294 +0,0 @@
/* osdep.h
Operating system dependencies... */
/*
* Copyright (c) 1996, 1997, 1998, 1999 The Internet Software Consortium.
* 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 Internet Software Consortium 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 INTERNET SOFTWARE CONSORTIUM 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 INTERNET SOFTWARE CONSORTIUM 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.
*
* This software was written for the Internet Software Consortium by Ted Lemon
* under a contract with Vixie Laboratories.
*/
#include "site.h"
/* Porting::
If you add a new network API, you must add a check for it below: */
#if !defined (USE_SOCKETS) && \
!defined (USE_SOCKET_SEND) && \
!defined (USE_SOCKET_RECEIVE) && \
!defined (USE_RAW_SOCKETS) && \
!defined (USE_RAW_SEND) && \
!defined (USE_SOCKET_RECEIVE) && \
!defined (USE_BPF) && \
!defined (USE_BPF_SEND) && \
!defined (USE_BPF_RECEIVE) && \
!defined (USE_LPF) && \
!defined (USE_LPF_SEND) && \
!defined (USE_LPF_RECEIVE) && \
!defined (USE_NIT) && \
!defined (USE_NIT_SEND) && \
!defined (USE_NIT_RECEIVE) && \
!defined (USR_DLPI_SEND) && \
!defined (USE_DLPI_RECEIVE)
# define USE_DEFAULT_NETWORK
#endif
/* Porting::
If you add a new system configuration file, include it here: */
#if defined (sun)
# if defined (__svr4__) || defined (__SVR4)
# include "cf/sunos5-5.h"
# else
# include "cf/sunos4.h"
# endif
#endif
#ifdef aix
# include "cf/aix.h"
#endif
#ifdef bsdi
# include "cf/bsdos.h"
#endif
#ifdef __NetBSD__
# include "cf/netbsd.h"
#endif
#ifdef __FreeBSD__
# include "cf/freebsd.h"
#endif
#if defined (__osf__) && defined (__alpha)
# include "cf/alphaosf.h"
#endif
#ifdef ultrix
# include "cf/ultrix.h"
#endif
#ifdef linux
# include "cf/linux.h"
#endif
#ifdef SCO
# include "cf/sco.h"
#endif
#if defined (hpux) || defined (__hpux)
# include "cf/hpux.h"
#endif
#ifdef __QNX__
# include "cf/qnx.h"
#endif
#ifdef __CYGWIN32__
# include "cf/cygwin32.h"
#endif
#ifdef __APPLE__
# include "cf/rhapsody.h"
#else
# if defined (NeXT)
# include "cf/nextstep.h"
# endif
#endif
#if defined(IRIX) || defined(__sgi)
# include "cf/irix.h"
#endif
#if !defined (TIME_MAX)
# define TIME_MAX 2147483647
#endif
/* Porting::
If you add a new network API, and have it set up so that it can be
used for sending or receiving, but doesn't have to be used for both,
then set up an ifdef like the ones below: */
#ifdef USE_SOCKETS
# define USE_SOCKET_SEND
# define USE_SOCKET_RECEIVE
#endif
#ifdef USE_RAW_SOCKETS
# define USE_RAW_SEND
# define USE_SOCKET_RECEIVE
#endif
#ifdef USE_BPF
# define USE_BPF_SEND
# define USE_BPF_RECEIVE
#endif
#ifdef USE_LPF
# define USE_LPF_SEND
# define USE_LPF_RECEIVE
#endif
#ifdef USE_NIT
# define USE_NIT_SEND
# define USE_NIT_RECEIVE
#endif
#ifdef USE_DLPI
# define USE_DLPI_SEND
# define USE_DLPI_RECEIVE
#endif
#ifdef USE_UPF
# define USE_UPF_SEND
# define USE_UPF_RECEIVE
#endif
/* Porting::
If you add support for sending packets directly out an interface,
and your support does not do ARP or routing, you must use a fallback
mechanism to deal with packets that need to be sent to routers.
Currently, all low-level packet interfaces use BSD sockets as a
fallback. */
#if defined (USE_BPF_SEND) || defined (USE_NIT_SEND) || \
defined (USE_DLPI_SEND) || defined (USE_UPF_SEND) || defined (USE_LPF_SEND)
# define USE_SOCKET_FALLBACK
# define USE_FALLBACK
#endif
/* Porting::
If you add support for sending packets directly out an interface
and need to be able to assemble packets, add the USE_XXX_SEND
definition for your interface to the list tested below. */
#if defined (USE_RAW_SEND) || defined (USE_BPF_SEND) || \
defined (USE_NIT_SEND) || defined (USE_UPF_SEND) || \
defined (USE_DLPI_SEND) || defined (USE_LPF_SEND)
# define PACKET_ASSEMBLY
#endif
/* Porting::
If you add support for receiving packets directly from an interface
and need to be able to decode raw packets, add the USE_XXX_RECEIVE
definition for your interface to the list tested below. */
#if defined (USE_RAW_RECEIVE) || defined (USE_BPF_SEND) || \
defined (USE_NIT_RECEIVE) || defined (USE_UPF_RECEIVE) || \
defined (USE_DLPI_RECEIVE) || \
defined (USE_LPF_SEND) || \
(defined (USE_SOCKET_SEND) && defined (SO_BINDTODEVICE))
# define PACKET_DECODING
#endif
/* If we don't have a DLPI packet filter, we have to filter in userland.
Probably not worth doing, actually. */
#if defined (USE_DLPI_RECEIVE) && !defined (USE_DLPI_PFMOD)
# define USERLAND_FILTER
#endif
/* jmp_buf is assumed to be a struct unless otherwise defined in the
system header. */
#ifndef jbp_decl
# define jbp_decl(x) jmp_buf *x
#endif
#ifndef jref
# define jref(x) (&(x))
#endif
#ifndef jdref
# define jdref(x) (*(x))
#endif
#ifndef jrefproto
# define jrefproto jmp_buf *
#endif
#ifndef BPF_FORMAT
# define BPF_FORMAT "/dev/bpf%d"
#endif
#if defined (IFF_POINTOPOINT) && !defined (HAVE_IFF_POINTOPOINT)
# define HAVE_IFF_POINTOPOINT
#endif
#if defined (AF_LINK) && !defined (HAVE_AF_LINK)
# define HAVE_AF_LINK
#endif
#if defined (ARPHRD_TUNNEL) && !defined (HAVE_ARPHRD_TUNNEL)
# define HAVE_ARPHRD_TUNNEL
#endif
#if defined (ARPHRD_LOOPBACK) && !defined (HAVE_ARPHRD_LOOPBACK)
# define HAVE_ARPHRD_LOOPBACK
#endif
#if defined (ARPHRD_ROSE) && !defined (HAVE_ARPHRD_ROSE)
# define HAVE_ARPHRD_ROSE
#endif
#if defined (ARPHRD_IEEE802) && !defined (HAVE_ARPHRD_IEEE802)
# define HAVE_ARPHRD_IEEE802
#endif
#if defined (ARPHRD_FDDI) && !defined (HAVE_ARPHRD_FDDI)
# define HAVE_ARPHRD_FDDI
#endif
#if defined (ARPHRD_AX25) && !defined (HAVE_ARPHRD_AX25)
# define HAVE_ARPHRD_AX25
#endif
#if defined (ARPHRD_NETROM) && !defined (HAVE_ARPHRD_NETROM)
# define HAVE_ARPHRD_NETROM
#endif
#if defined (ARPHRD_METRICOM) && !defined (HAVE_ARPHRD_METRICOM)
# define HAVE_ARPHRD_METRICOM
#endif
#if defined (SO_BINDTODEVICE) && !defined (HAVE_SO_BINDTODEVICE)
# define HAVE_SO_BINDTODEVICE
#endif
#if defined (SIOCGIFHWADDR) && !defined (HAVE_SIOCGIFHWADDR)
# define HAVE_SIOCGIFHWADDR
#endif
#if defined (AF_LINK) && !defined (HAVE_AF_LINK)
# define HAVE_AF_LINK
#endif

View file

@ -1,4 +0,0 @@
#pragma once
struct iaddr;
struct interface_info;

View file

@ -1,47 +0,0 @@
/* $OpenBSD: privsep.h,v 1.2 2004/05/04 18:51:18 henning Exp $ */
/*
* Copyright (c) 2004 Henning Brauer <henning@openbsd.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER IN
* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
* OF OR IN CONNECTION WITH THE USE, ABUSE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <sys/types.h>
//#include <poll.h>
//#include <pwd.h>
struct buf {
u_char *buf;
size_t size;
size_t wpos;
size_t rpos;
};
enum imsg_code {
IMSG_NONE,
IMSG_SCRIPT_INIT,
IMSG_SCRIPT_WRITE_PARAMS,
IMSG_SCRIPT_GO,
IMSG_SCRIPT_GO_RET
};
struct imsg_hdr {
enum imsg_code code;
size_t len;
};
struct buf *buf_open(size_t);
int buf_add(struct buf *, void *, size_t);
int buf_close(int, struct buf *);
ssize_t buf_read(int sock, void *, size_t);

View file

@ -1,100 +0,0 @@
/* Site-specific definitions.
For supported systems, you shouldn't need to make any changes here.
However, you may want to, in order to deal with site-specific
differences. */
/* Add any site-specific definitions and inclusions here... */
/* #include <site-foo-bar.h> */
/* #define SITE_FOOBAR */
/* Define this if you don't want dhcpd to run as a daemon and do want
to see all its output printed to stdout instead of being logged via
syslog(). This also makes dhcpd use the dhcpd.conf in its working
directory and write the dhcpd.leases file there. */
/* #define DEBUG */
/* Define this to see what the parser is parsing. You probably don't
want to see this. */
/* #define DEBUG_TOKENS */
/* Define this to see dumps of incoming and outgoing packets. This
slows things down quite a bit... */
/* #define DEBUG_PACKET */
/* Define this if you want to see dumps of tree evaluations. The most
common reason for doing this is to watch what happens with DNS name
lookups. */
/* #define DEBUG_EVAL */
/* Define this if you want the dhcpd.pid file to go somewhere other than
the default (which varies from system to system, but is usually either
/etc or /var/run. */
/* #define _PATH_DHCPD_PID "/var/run/dhcpd.pid" */
/* Define this if you want the dhcpd.leases file (the dynamic lease database)
to go somewhere other than the default location, which is normally
/etc/dhcpd.leases. */
/* #define _PATH_DHCPD_DB "/etc/dhcpd.leases" */
/* Define this if you want the dhcpd.conf file to go somewhere other than
the default location. By default, it goes in /etc/dhcpd.conf. */
/* #define _PATH_DHCPD_CONF "/etc/dhcpd.conf" */
/* Network API definitions. You do not need to choose one of these - if
you don't choose, one will be chosen for you in your system's config
header. DON'T MESS WITH THIS UNLESS YOU KNOW WHAT YOU'RE DOING!!! */
/* Define this to use the standard BSD socket API.
On many systems, the BSD socket API does not provide the ability to
send packets to the 255.255.255.255 broadcast address, which can
prevent some clients (e.g., Win95) from seeing replies. This is
not a problem on Solaris.
In addition, the BSD socket API will not work when more than one
network interface is configured on the server.
However, the BSD socket API is about as efficient as you can get, so if
the aforementioned problems do not matter to you, or if no other
API is supported for your system, you may want to go with it. */
/* #define USE_SOCKETS */
/* Define this to use the Sun Streams NIT API.
The Sun Streams NIT API is only supported on SunOS 4.x releases. */
/* #define USE_NIT */
/* Define this to use the Berkeley Packet Filter API.
The BPF API is available on all 4.4-BSD derivatives, including
NetBSD, FreeBSD and BSDI's BSD/OS. It's also available on
DEC Alpha OSF/1 in a compatibility mode supported by the Alpha OSF/1
packetfilter interface. */
/* #define USE_BPF */
/* Define this to use the raw socket API.
The raw socket API is provided on many BSD derivatives, and provides
a way to send out raw IP packets. It is only supported for sending
packets - packets must be received with the regular socket API.
This code is experimental - I've never gotten it to actually transmit
a packet to the 255.255.255.255 broadcast address - so use it at your
own risk. */
/* #define USE_RAW_SOCKETS */
/* Define this to change the logging facility used by dhcpd. */
/* #define DHCPD_LOG_FACILITY LOG_DAEMON */

View file

@ -1,10 +0,0 @@
#pragma once
typedef signed char int8_t;
typedef unsigned char u_int8_t;
typedef short int16_t;
typedef unsigned short u_int16_t;
typedef int int32_t;
typedef unsigned int u_int32_t;
typedef char *caddr_t;

View file

@ -1,52 +0,0 @@
/* systat.h
Definitions for systat protocol... */
/*
* Copyright (c) 1997 The Internet Software Consortium.
* 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 Internet Software Consortium 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 INTERNET SOFTWARE CONSORTIUM 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 INTERNET SOFTWARE CONSORTIUM 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.
*
* This software has been written for the Internet Software Consortium
* by Ted Lemon <mellon@fugue.com> in cooperation with Vixie
* Enterprises. To learn more about the Internet Software Consortium,
* see ``http://www.vix.com/isc''. To learn more about Vixie
* Enterprises, see ``http://www.vix.com''.
*/
#define SYSCONF_SOCKET "/var/run/sysconf"
struct sysconf_header {
u_int32_t type; /* Type of status message... */
u_int32_t length; /* Length of message. */
};
/* Message types... */
#define NETWORK_LOCATION_CHANGED 1

View file

@ -1,3 +0,0 @@
/* Current version of ISC DHCP Distribution. */
#define DHCP_VERSION "2.0pl5"

View file

@ -1,919 +0,0 @@
/* memory.c
Memory-resident database... */
/*
* Copyright (c) 1995, 1996, 1997, 1998 The Internet Software Consortium.
* 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 Internet Software Consortium 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 INTERNET SOFTWARE CONSORTIUM 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 INTERNET SOFTWARE CONSORTIUM 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.
*
* This software has been written for the Internet Software Consortium
* by Ted Lemon <mellon@fugue.com> in cooperation with Vixie
* Enterprises. To learn more about the Internet Software Consortium,
* see ``http://www.vix.com/isc''. To learn more about Vixie
* Enterprises, see ``http://www.vix.com''.
*/
#ifndef lint
static char copyright[] =
"$Id: memory.c,v 1.35.2.4 1999/05/27 17:47:43 mellon Exp $ Copyright (c) 1995, 1996, 1997, 1998 The Internet Software Consortium. All rights reserved.\n";
#endif /* not lint */
#include "rosdhcp.h"
#include "dhcpd.h"
struct subnet *subnets;
struct shared_network *shared_networks;
static struct hash_table *host_hw_addr_hash;
static struct hash_table *host_uid_hash;
static struct hash_table *lease_uid_hash;
static struct hash_table *lease_ip_addr_hash;
static struct hash_table *lease_hw_addr_hash;
struct lease *dangling_leases;
static struct hash_table *vendor_class_hash;
static struct hash_table *user_class_hash;
void enter_host (hd)
struct host_decl *hd;
{
struct host_decl *hp = (struct host_decl *)0;
struct host_decl *np = (struct host_decl *)0;
hd -> n_ipaddr = (struct host_decl *)0;
if (hd -> interface.hlen) {
if (!host_hw_addr_hash)
host_hw_addr_hash = new_hash ();
else
hp = (struct host_decl *)
hash_lookup (host_hw_addr_hash,
hd -> interface.haddr,
hd -> interface.hlen);
/* If there isn't already a host decl matching this
address, add it to the hash table. */
if (!hp)
add_hash (host_hw_addr_hash,
hd -> interface.haddr, hd -> interface.hlen,
(unsigned char *)hd);
}
/* If there was already a host declaration for this hardware
address, add this one to the end of the list. */
if (hp) {
for (np = hp; np -> n_ipaddr; np = np -> n_ipaddr)
;
np -> n_ipaddr = hd;
}
if (hd -> group -> options [DHO_DHCP_CLIENT_IDENTIFIER]) {
if (!tree_evaluate (hd -> group -> options
[DHO_DHCP_CLIENT_IDENTIFIER]))
return;
/* If there's no uid hash, make one; otherwise, see if
there's already an entry in the hash for this host. */
if (!host_uid_hash) {
host_uid_hash = new_hash ();
hp = (struct host_decl *)0;
} else
hp = (struct host_decl *) hash_lookup
(host_uid_hash,
hd -> group -> options
[DHO_DHCP_CLIENT_IDENTIFIER] -> value,
hd -> group -> options
[DHO_DHCP_CLIENT_IDENTIFIER] -> len);
/* If there's already a host declaration for this
client identifier, add this one to the end of the
list. Otherwise, add it to the hash table. */
if (hp) {
/* Don't link it in twice... */
if (!np) {
for (np = hp; np -> n_ipaddr;
np = np -> n_ipaddr)
;
np -> n_ipaddr = hd;
}
} else {
add_hash (host_uid_hash,
hd -> group -> options
[DHO_DHCP_CLIENT_IDENTIFIER] -> value,
hd -> group -> options
[DHO_DHCP_CLIENT_IDENTIFIER] -> len,
(unsigned char *)hd);
}
}
}
struct host_decl *find_hosts_by_haddr (htype, haddr, hlen)
int htype;
unsigned char *haddr;
int hlen;
{
struct host_decl *foo;
foo = (struct host_decl *)hash_lookup (host_hw_addr_hash,
haddr, hlen);
return foo;
}
struct host_decl *find_hosts_by_uid (data, len)
unsigned char *data;
int len;
{
struct host_decl *foo;
foo = (struct host_decl *)hash_lookup (host_uid_hash, data, len);
return foo;
}
/* More than one host_decl can be returned by find_hosts_by_haddr or
find_hosts_by_uid, and each host_decl can have multiple addresses.
Loop through the list of hosts, and then for each host, through the
list of addresses, looking for an address that's in the same shared
network as the one specified. Store the matching address through
the addr pointer, update the host pointer to point at the host_decl
that matched, and return the subnet that matched. */
subnet *find_host_for_network (struct host_decl **host, iaddr *addr,
shared_network *share)
{
int i;
subnet *subnet;
iaddr ip_address;
struct host_decl *hp;
for (hp = *host; hp; hp = hp -> n_ipaddr) {
if (!hp -> fixed_addr || !tree_evaluate (hp -> fixed_addr))
continue;
for (i = 0; i < hp -> fixed_addr -> len; i += 4) {
ip_address.len = 4;
memcpy (ip_address.iabuf,
hp -> fixed_addr -> value + i, 4);
subnet = find_grouped_subnet (share, ip_address);
if (subnet) {
*addr = ip_address;
*host = hp;
return subnet;
}
}
}
return (struct _subnet *)0;
}
void new_address_range (iaddr low, iaddr high, subnet *subnet, int dynamic)
{
lease *address_range, *lp, *plp;
iaddr net;
int min, max, i;
char lowbuf [16], highbuf [16], netbuf [16];
shared_network *share = subnet -> shared_network;
struct hostent *h;
struct in_addr ia;
/* All subnets should have attached shared network structures. */
if (!share) {
strcpy (netbuf, piaddr (subnet -> net));
error ("No shared network for network %s (%s)",
netbuf, piaddr (subnet -> netmask));
}
/* Initialize the hash table if it hasn't been done yet. */
if (!lease_uid_hash)
lease_uid_hash = new_hash ();
if (!lease_ip_addr_hash)
lease_ip_addr_hash = new_hash ();
if (!lease_hw_addr_hash)
lease_hw_addr_hash = new_hash ();
/* Make sure that high and low addresses are in same subnet. */
net = subnet_number (low, subnet -> netmask);
if (!addr_eq (net, subnet_number (high, subnet -> netmask))) {
strcpy (lowbuf, piaddr (low));
strcpy (highbuf, piaddr (high));
strcpy (netbuf, piaddr (subnet -> netmask));
error ("Address range %s to %s, netmask %s spans %s!",
lowbuf, highbuf, netbuf, "multiple subnets");
}
/* Make sure that the addresses are on the correct subnet. */
if (!addr_eq (net, subnet -> net)) {
strcpy (lowbuf, piaddr (low));
strcpy (highbuf, piaddr (high));
strcpy (netbuf, piaddr (subnet -> netmask));
error ("Address range %s to %s not on net %s/%s!",
lowbuf, highbuf, piaddr (subnet -> net), netbuf);
}
/* Get the high and low host addresses... */
max = host_addr (high, subnet -> netmask);
min = host_addr (low, subnet -> netmask);
/* Allow range to be specified high-to-low as well as low-to-high. */
if (min > max) {
max = min;
min = host_addr (high, subnet -> netmask);
}
/* Get a lease structure for each address in the range. */
address_range = new_leases (max - min + 1, "new_address_range");
if (!address_range) {
strcpy (lowbuf, piaddr (low));
strcpy (highbuf, piaddr (high));
error ("No memory for address range %s-%s.", lowbuf, highbuf);
}
memset (address_range, 0, (sizeof *address_range) * (max - min + 1));
/* Fill in the last lease if it hasn't been already... */
if (!share -> last_lease) {
share -> last_lease = &address_range [0];
}
/* Fill out the lease structures with some minimal information. */
for (i = 0; i < max - min + 1; i++) {
address_range [i].ip_addr =
ip_addr (subnet -> net, subnet -> netmask, i + min);
address_range [i].starts =
address_range [i].timestamp = MIN_TIME;
address_range [i].ends = MIN_TIME;
address_range [i].subnet = subnet;
address_range [i].shared_network = share;
address_range [i].flags = dynamic ? DYNAMIC_BOOTP_OK : 0;
memcpy (&ia, address_range [i].ip_addr.iabuf, 4);
if (subnet -> group -> get_lease_hostnames) {
h = gethostbyaddr ((char *)&ia, sizeof ia, AF_INET);
if (!h)
warn ("No hostname for %s", inet_ntoa (ia));
else {
address_range [i].hostname =
malloc (strlen (h -> h_name) + 1);
if (!address_range [i].hostname)
error ("no memory for hostname %s.",
h -> h_name);
strcpy (address_range [i].hostname,
h -> h_name);
}
}
/* Link this entry into the list. */
address_range [i].next = share -> leases;
address_range [i].prev = (struct lease *)0;
share -> leases = &address_range [i];
if (address_range [i].next)
address_range [i].next -> prev = share -> leases;
add_hash (lease_ip_addr_hash,
address_range [i].ip_addr.iabuf,
address_range [i].ip_addr.len,
(unsigned char *)&address_range [i]);
}
/* Find out if any dangling leases are in range... */
plp = (struct lease *)0;
for (lp = dangling_leases; lp; lp = lp -> next) {
iaddr lnet;
int lhost;
lnet = subnet_number (lp -> ip_addr, subnet -> netmask);
lhost = host_addr (lp -> ip_addr, subnet -> netmask);
/* If it's in range, fill in the real lease structure with
the dangling lease's values, and remove the lease from
the list of dangling leases. */
if (addr_eq (lnet, subnet -> net) &&
lhost >= i && lhost <= max) {
if (plp) {
plp -> next = lp -> next;
} else {
dangling_leases = lp -> next;
}
lp -> next = (struct lease *)0;
address_range [lhost - i].hostname = lp -> hostname;
address_range [lhost - i].client_hostname =
lp -> client_hostname;
supersede_lease (&address_range [lhost - i], lp, 0);
free_lease (lp, "new_address_range");
} else
plp = lp;
}
}
subnet *find_subnet (iaddr addr)
{
subnet *rv;
for (rv = subnets; rv; rv = rv -> next_subnet) {
if (addr_eq (subnet_number (addr, rv -> netmask), rv -> net))
return rv;
}
return (subnet *)0;
}
subnet *find_grouped_subnet (shared_network *share, iaddr addr)
{
subnet *rv;
for (rv = share -> subnets; rv; rv = rv -> next_sibling) {
if (addr_eq (subnet_number (addr, rv -> netmask), rv -> net))
return rv;
}
return (subnet *)0;
}
int subnet_inner_than (struct _subnet *subnet, struct _subnet *scan, int warnp)
{
if (addr_eq (subnet_number (subnet -> net, scan -> netmask),
scan -> net) ||
addr_eq (subnet_number (scan -> net, subnet -> netmask),
subnet -> net)) {
char n1buf [16];
int i, j;
for (i = 0; i < 32; i++)
if (subnet -> netmask.iabuf [3 - (i >> 3)]
& (1 << (i & 7)))
break;
for (j = 0; j < 32; j++)
if (scan -> netmask.iabuf [3 - (j >> 3)] &
(1 << (j & 7)))
break;
strcpy (n1buf, piaddr (subnet -> net));
if (warnp)
warn ("%ssubnet %s/%d conflicts with subnet %s/%d",
"Warning: ", n1buf, 32 - i,
piaddr (scan -> net), 32 - j);
if (i < j)
return 1;
}
return 0;
}
/* Enter a new subnet into the subnet list. */
void enter_subnet (struct _subnet *subnet)
{
struct _subnet *scan, *prev = (struct _subnet *)0;
/* Check for duplicates... */
for (scan = subnets; scan; scan = scan -> next_subnet) {
/* When we find a conflict, make sure that the
subnet with the narrowest subnet mask comes
first. */
if (subnet_inner_than (subnet, scan, 1)) {
if (prev) {
prev -> next_subnet = subnet;
} else
subnets = subnet;
subnet -> next_subnet = scan;
return;
}
prev = scan;
}
/* XXX use the BSD radix tree code instead of a linked list. */
subnet -> next_subnet = subnets;
subnets = subnet;
}
/* Enter a new shared network into the shared network list. */
void enter_shared_network (shared_network *share)
{
/* XXX Sort the nets into a balanced tree to make searching quicker. */
share -> next = shared_networks;
shared_networks = share;
}
/* Enter a lease into the system. This is called by the parser each
time it reads in a new lease. If the subnet for that lease has
already been read in (usually the case), just update that lease;
otherwise, allocate temporary storage for the lease and keep it around
until we're done reading in the config file. */
void enter_lease (struct _lease *lease)
{
struct _lease *comp = find_lease_by_ip_addr (lease -> ip_addr);
/* If we don't have a place for this lease yet, save it for
later. */
if (!comp) {
comp = new_lease ("enter_lease");
if (!comp) {
error ("No memory for lease %s\n",
piaddr (lease -> ip_addr));
}
*comp = *lease;
comp -> next = dangling_leases;
comp -> prev = (struct lease *)0;
dangling_leases = comp;
} else {
/* Record the hostname information in the lease. */
comp -> hostname = lease -> hostname;
comp -> client_hostname = lease -> client_hostname;
supersede_lease (comp, lease, 0);
}
}
/* Replace the data in an existing lease with the data in a new lease;
adjust hash tables to suit, and insertion sort the lease into the
list of leases by expiry time so that we can always find the oldest
lease. */
int supersede_lease (struct _lease *comp, struct _lease *lease, int commit)
{
int enter_uid = 0;
int enter_hwaddr = 0;
struct _lease *lp;
/* Static leases are not currently kept in the database... */
if (lease -> flags & STATIC_LEASE)
return 1;
/* If the existing lease hasn't expired and has a different
unique identifier or, if it doesn't have a unique
identifier, a different hardware address, then the two
leases are in conflict. If the existing lease has a uid
and the new one doesn't, but they both have the same
hardware address, and dynamic bootp is allowed on this
lease, then we allow that, in case a dynamic BOOTP lease is
requested *after* a DHCP lease has been assigned. */
if (!(lease -> flags & ABANDONED_LEASE) &&
comp -> ends > cur_time &&
(((comp -> uid && lease -> uid) &&
(comp -> uid_len != lease -> uid_len ||
memcmp (comp -> uid, lease -> uid, comp -> uid_len))) ||
(!comp -> uid &&
((comp -> hardware_addr.htype !=
lease -> hardware_addr.htype) ||
(comp -> hardware_addr.hlen !=
lease -> hardware_addr.hlen) ||
memcmp (comp -> hardware_addr.haddr,
lease -> hardware_addr.haddr,
comp -> hardware_addr.hlen))))) {
warn ("Lease conflict at %s",
piaddr (comp -> ip_addr));
return 0;
} else {
/* If there's a Unique ID, dissociate it from the hash
table and free it if necessary. */
if (comp -> uid) {
uid_hash_delete (comp);
enter_uid = 1;
if (comp -> uid != &comp -> uid_buf [0]) {
free (comp -> uid);
comp -> uid_max = 0;
comp -> uid_len = 0;
}
comp -> uid = (unsigned char *)0;
} else
enter_uid = 1;
if (comp -> hardware_addr.htype &&
((comp -> hardware_addr.hlen !=
lease -> hardware_addr.hlen) ||
(comp -> hardware_addr.htype !=
lease -> hardware_addr.htype) ||
memcmp (comp -> hardware_addr.haddr,
lease -> hardware_addr.haddr,
comp -> hardware_addr.hlen))) {
hw_hash_delete (comp);
enter_hwaddr = 1;
} else if (!comp -> hardware_addr.htype)
enter_hwaddr = 1;
/* Copy the data files, but not the linkages. */
comp -> starts = lease -> starts;
if (lease -> uid) {
if (lease -> uid_len < sizeof (lease -> uid_buf)) {
memcpy (comp -> uid_buf,
lease -> uid, lease -> uid_len);
comp -> uid = &comp -> uid_buf [0];
comp -> uid_max = sizeof comp -> uid_buf;
} else if (lease -> uid != &lease -> uid_buf [0]) {
comp -> uid = lease -> uid;
comp -> uid_max = lease -> uid_max;
lease -> uid = (unsigned char *)0;
lease -> uid_max = 0;
} else {
error ("corrupt lease uid."); /* XXX */
}
} else {
comp -> uid = (unsigned char *)0;
comp -> uid_max = 0;
}
comp -> uid_len = lease -> uid_len;
comp -> host = lease -> host;
comp -> hardware_addr = lease -> hardware_addr;
comp -> flags = ((lease -> flags & ~PERSISTENT_FLAGS) |
(comp -> flags & ~EPHEMERAL_FLAGS));
/* Record the lease in the uid hash if necessary. */
if (enter_uid && lease -> uid) {
uid_hash_add (comp);
}
/* Record it in the hardware address hash if necessary. */
if (enter_hwaddr && lease -> hardware_addr.htype) {
hw_hash_add (comp);
}
/* Remove the lease from its current place in the
timeout sequence. */
if (comp -> prev) {
comp -> prev -> next = comp -> next;
} else {
comp -> shared_network -> leases = comp -> next;
}
if (comp -> next) {
comp -> next -> prev = comp -> prev;
}
if (comp -> shared_network -> last_lease == comp) {
comp -> shared_network -> last_lease = comp -> prev;
}
/* Find the last insertion point... */
if (comp == comp -> shared_network -> insertion_point ||
!comp -> shared_network -> insertion_point) {
lp = comp -> shared_network -> leases;
} else {
lp = comp -> shared_network -> insertion_point;
}
if (!lp) {
/* Nothing on the list yet? Just make comp the
head of the list. */
comp -> shared_network -> leases = comp;
comp -> shared_network -> last_lease = comp;
} else if (lp -> ends > lease -> ends) {
/* Skip down the list until we run out of list
or find a place for comp. */
while (lp -> next && lp -> ends > lease -> ends) {
lp = lp -> next;
}
if (lp -> ends > lease -> ends) {
/* If we ran out of list, put comp
at the end. */
lp -> next = comp;
comp -> prev = lp;
comp -> next = (struct lease *)0;
comp -> shared_network -> last_lease = comp;
} else {
/* If we didn't, put it between lp and
the previous item on the list. */
if ((comp -> prev = lp -> prev))
comp -> prev -> next = comp;
comp -> next = lp;
lp -> prev = comp;
}
} else {
/* Skip up the list until we run out of list
or find a place for comp. */
while (lp -> prev && lp -> ends < lease -> ends) {
lp = lp -> prev;
}
if (lp -> ends < lease -> ends) {
/* If we ran out of list, put comp
at the beginning. */
lp -> prev = comp;
comp -> next = lp;
comp -> prev = (struct lease *)0;
comp -> shared_network -> leases = comp;
} else {
/* If we didn't, put it between lp and
the next item on the list. */
if ((comp -> next = lp -> next))
comp -> next -> prev = comp;
comp -> prev = lp;
lp -> next = comp;
}
}
comp -> shared_network -> insertion_point = comp;
comp -> ends = lease -> ends;
}
/* Return zero if we didn't commit the lease to permanent storage;
nonzero if we did. */
return commit && write_lease (comp) && commit_leases ();
}
/* Release the specified lease and re-hash it as appropriate. */
void release_lease (struct _lease *lease)
{
struct _lease lt;
lt = *lease;
if (lt.ends > cur_time) {
lt.ends = cur_time;
supersede_lease (lease, &lt, 1);
}
}
/* Abandon the specified lease (set its timeout to infinity and its
particulars to zero, and re-hash it as appropriate. */
void abandon_lease (struct _lease *lease, char *message)
{
struct _lease lt;
lease -> flags |= ABANDONED_LEASE;
lt = *lease;
lt.ends = cur_time;
warn ("Abandoning IP address %s: %s",
piaddr (lease -> ip_addr), message);
lt.hardware_addr.htype = 0;
lt.hardware_addr.hlen = 0;
lt.uid = (unsigned char *)0;
lt.uid_len = 0;
supersede_lease (lease, &lt, 1);
}
/* Locate the lease associated with a given IP address... */
lease *find_lease_by_ip_addr (iaddr addr)
{
lease *lease = (struct _lease *)hash_lookup (lease_ip_addr_hash,
addr.iabuf,
addr.len);
return lease;
}
lease *find_lease_by_uid (unsigned char *uid, int len)
{
lease *lease = (struct lease *)hash_lookup (lease_uid_hash,
uid, len);
return lease;
}
lease *find_lease_by_hw_addr (unsigned char *hwaddr, int hwlen)
{
struct _lease *lease =
(struct _lease *)hash_lookup (lease_hw_addr_hash,
hwaddr, hwlen);
return lease;
}
/* Add the specified lease to the uid hash. */
void uid_hash_add (lease *lease)
{
struct _lease *head = find_lease_by_uid (lease -> uid, lease -> uid_len);
struct _lease *scan;
#ifdef DEBUG
if (lease -> n_uid)
abort ();
#endif
/* If it's not in the hash, just add it. */
if (!head)
add_hash (lease_uid_hash, lease -> uid,
lease -> uid_len, (unsigned char *)lease);
else {
/* Otherwise, attach it to the end of the list. */
for (scan = head; scan -> n_uid; scan = scan -> n_uid)
#ifdef DEBUG
if (scan == lease)
abort ()
#endif
;
scan -> n_uid = lease;
}
}
/* Delete the specified lease from the uid hash. */
void uid_hash_delete (lease *lease)
{
struct _lease *head =
find_lease_by_uid (lease -> uid, lease -> uid_len);
struct _lease *scan;
/* If it's not in the hash, we have no work to do. */
if (!head) {
lease -> n_uid = (struct lease *)0;
return;
}
/* If the lease we're freeing is at the head of the list,
remove the hash table entry and add a new one with the
next lease on the list (if there is one). */
if (head == lease) {
delete_hash_entry (lease_uid_hash,
lease -> uid, lease -> uid_len);
if (lease -> n_uid)
add_hash (lease_uid_hash,
lease -> n_uid -> uid,
lease -> n_uid -> uid_len,
(unsigned char *)(lease -> n_uid));
} else {
/* Otherwise, look for the lease in the list of leases
attached to the hash table entry, and remove it if
we find it. */
for (scan = head; scan -> n_uid; scan = scan -> n_uid) {
if (scan -> n_uid == lease) {
scan -> n_uid = scan -> n_uid -> n_uid;
break;
}
}
}
lease -> n_uid = (struct lease *)0;
}
/* Add the specified lease to the hardware address hash. */
void hw_hash_add (lease *lease)
{
struct _lease *head =
find_lease_by_hw_addr (lease -> hardware_addr.haddr,
lease -> hardware_addr.hlen);
struct _lease *scan;
/* If it's not in the hash, just add it. */
if (!head)
add_hash (lease_hw_addr_hash,
lease -> hardware_addr.haddr,
lease -> hardware_addr.hlen,
(unsigned char *)lease);
else {
/* Otherwise, attach it to the end of the list. */
for (scan = head; scan -> n_hw; scan = scan -> n_hw)
;
scan -> n_hw = lease;
}
}
/* Delete the specified lease from the hardware address hash. */
void hw_hash_delete (lease *lease)
{
struct _lease *head =
find_lease_by_hw_addr (lease -> hardware_addr.haddr,
lease -> hardware_addr.hlen);
struct _lease *scan;
/* If it's not in the hash, we have no work to do. */
if (!head) {
lease -> n_hw = (struct lease *)0;
return;
}
/* If the lease we're freeing is at the head of the list,
remove the hash table entry and add a new one with the
next lease on the list (if there is one). */
if (head == lease) {
delete_hash_entry (lease_hw_addr_hash,
lease -> hardware_addr.haddr,
lease -> hardware_addr.hlen);
if (lease -> n_hw)
add_hash (lease_hw_addr_hash,
lease -> n_hw -> hardware_addr.haddr,
lease -> n_hw -> hardware_addr.hlen,
(unsigned char *)(lease -> n_hw));
} else {
/* Otherwise, look for the lease in the list of leases
attached to the hash table entry, and remove it if
we find it. */
for (scan = head; scan -> n_hw; scan = scan -> n_hw) {
if (scan -> n_hw == lease) {
scan -> n_hw = scan -> n_hw -> n_hw;
break;
}
}
}
lease -> n_hw = (struct lease *)0;
}
struct class *add_class (type, name)
int type;
char *name;
{
struct class *class = new_class ("add_class");
char *tname = (char *)malloc (strlen (name) + 1);
if (!vendor_class_hash)
vendor_class_hash = new_hash ();
if (!user_class_hash)
user_class_hash = new_hash ();
if (!tname || !class || !vendor_class_hash || !user_class_hash)
{
if (tname != NULL)
free(tname);
return (struct class *)0;
}
memset (class, 0, sizeof *class);
strcpy (tname, name);
class -> name = tname;
if (type)
add_hash (user_class_hash,
(unsigned char *)tname, strlen (tname),
(unsigned char *)class);
else
add_hash (vendor_class_hash,
(unsigned char *)tname, strlen (tname),
(unsigned char *)class);
return class;
}
struct class *find_class (type, name, len)
int type;
unsigned char *name;
int len;
{
struct class *class =
(struct class *)hash_lookup (type
? user_class_hash
: vendor_class_hash, name, len);
return class;
}
struct group *clone_group (group, caller)
struct group *group;
char *caller;
{
struct group *g = new_group (caller);
if (!g)
error ("%s: can't allocate new group", caller);
*g = *group;
return g;
}
/* Write all interesting leases to permanent storage. */
void write_leases ()
{
lease *l;
shared_network *s;
for (s = shared_networks; s; s = (shared_network *)s -> next) {
for (l = s -> leases; l; l = l -> next) {
if (l -> hardware_addr.hlen ||
l -> uid_len ||
(l -> flags & ABANDONED_LEASE))
if (!write_lease (l))
error ("Can't rewrite lease database");
}
}
if (!commit_leases ())
error ("Can't commit leases to new database: %m");
}
void dump_subnets ()
{
struct _lease *l;
shared_network *s;
subnet *n;
note ("Subnets:");
for (n = subnets; n; n = n -> next_subnet) {
debug (" Subnet %s", piaddr (n -> net));
debug (" netmask %s",
piaddr (n -> netmask));
}
note ("Shared networks:");
for (s = shared_networks; s; s = (shared_network *)s -> next) {
note (" %s", s -> name);
for (l = s -> leases; l; l = l -> next) {
print_lease (l);
}
if (s -> last_lease) {
debug (" Last Lease:");
print_lease (s -> last_lease);
}
}
}

View file

@ -1,225 +0,0 @@
/* $OpenBSD: privsep.c,v 1.7 2004/05/10 18:34:42 deraadt Exp $ */
/*
* Copyright (c) 2004 Henning Brauer <henning@openbsd.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER IN
* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
* OF OR IN CONNECTION WITH THE USE, ABUSE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include "rosdhcp.h"
#include "dhcpd.h"
#include "privsep.h"
struct buf *
buf_open(size_t len)
{
struct buf *buf;
if ((buf = calloc(1, sizeof(struct buf))) == NULL)
return (NULL);
if ((buf->buf = malloc(len)) == NULL) {
free(buf);
return (NULL);
}
buf->size = len;
return (buf);
}
int
buf_add(struct buf *buf, void *data, size_t len)
{
if (buf->wpos + len > buf->size)
return (-1);
memcpy(buf->buf + buf->wpos, data, len);
buf->wpos += len;
return (0);
}
int
buf_close(int sock, struct buf *buf)
{
ssize_t n;
n = write(sock, buf->buf + buf->rpos, buf->size - buf->rpos);
if (n != -1)
buf->rpos += n;
if (n == 0) { /* connection closed */
return (-1);
}
if (buf->rpos < buf->size)
error("short write: wanted %lu got %ld bytes",
(unsigned long)buf->size, (long)buf->rpos);
free(buf->buf);
free(buf);
return (n);
}
ssize_t
buf_read(int sock, void *buf, size_t nbytes)
{
ssize_t n, r = 0;
char *p = buf;
n = read(sock, p, nbytes);
if (n == 0)
error("connection closed");
if (n != -1) {
r += n;
p += n;
nbytes -= n;
}
if (n == -1)
error("buf_read: %d", WSAGetLastError());
if (r < nbytes)
error("short read: wanted %lu got %ld bytes",
(unsigned long)nbytes, (long)r);
return (r);
}
void
dispatch_imsg(int fd)
{
struct imsg_hdr hdr;
char *medium, *reason, *filename,
*servername, *prefix;
size_t medium_len, reason_len, filename_len,
servername_len, prefix_len, totlen;
struct client_lease lease;
int ret, i, optlen;
struct buf *buf;
buf_read(fd, &hdr, sizeof(hdr));
switch (hdr.code) {
case IMSG_SCRIPT_INIT:
if (hdr.len < sizeof(hdr) + sizeof(size_t))
error("corrupted message received");
buf_read(fd, &medium_len, sizeof(medium_len));
if (hdr.len < medium_len + sizeof(size_t) + sizeof(hdr)
+ sizeof(size_t) || medium_len == SIZE_T_MAX)
error("corrupted message received");
if (medium_len > 0) {
if ((medium = calloc(1, medium_len + 1)) != NULL)
buf_read(fd, medium, medium_len);
} else
medium = NULL;
buf_read(fd, &reason_len, sizeof(reason_len));
if (hdr.len < medium_len + reason_len + sizeof(hdr) ||
reason_len == SIZE_T_MAX)
error("corrupted message received");
if (reason_len > 0) {
if ((reason = calloc(1, reason_len + 1)) != NULL)
buf_read(fd, reason, reason_len);
} else
reason = NULL;
// priv_script_init(reason, medium);
free(reason);
free(medium);
break;
case IMSG_SCRIPT_WRITE_PARAMS:
//bzero(&lease, sizeof lease);
memset(&lease, 0, sizeof(lease));
totlen = sizeof(hdr) + sizeof(lease) + sizeof(size_t);
if (hdr.len < totlen)
error("corrupted message received");
buf_read(fd, &lease, sizeof(lease));
buf_read(fd, &filename_len, sizeof(filename_len));
totlen += filename_len + sizeof(size_t);
if (hdr.len < totlen || filename_len == SIZE_T_MAX)
error("corrupted message received");
if (filename_len > 0) {
if ((filename = calloc(1, filename_len + 1)) != NULL)
buf_read(fd, filename, filename_len);
} else
filename = NULL;
buf_read(fd, &servername_len, sizeof(servername_len));
totlen += servername_len + sizeof(size_t);
if (hdr.len < totlen || servername_len == SIZE_T_MAX)
error("corrupted message received");
if (servername_len > 0) {
if ((servername =
calloc(1, servername_len + 1)) != NULL)
buf_read(fd, servername, servername_len);
} else
servername = NULL;
buf_read(fd, &prefix_len, sizeof(prefix_len));
totlen += prefix_len;
if (hdr.len < totlen || prefix_len == SIZE_T_MAX)
error("corrupted message received");
if (prefix_len > 0) {
if ((prefix = calloc(1, prefix_len + 1)) != NULL)
buf_read(fd, prefix, prefix_len);
} else
prefix = NULL;
for (i = 0; i < 256; i++) {
totlen += sizeof(optlen);
if (hdr.len < totlen)
error("corrupted message received");
buf_read(fd, &optlen, sizeof(optlen));
lease.options[i].data = NULL;
lease.options[i].len = optlen;
if (optlen > 0) {
totlen += optlen;
if (hdr.len < totlen || optlen == SIZE_T_MAX)
error("corrupted message received");
lease.options[i].data =
calloc(1, optlen + 1);
if (lease.options[i].data != NULL)
buf_read(fd, lease.options[i].data, optlen);
}
}
lease.server_name = servername;
lease.filename = filename;
// priv_script_write_params(prefix, &lease);
free(servername);
free(filename);
free(prefix);
for (i = 0; i < 256; i++)
if (lease.options[i].len > 0)
free(lease.options[i].data);
break;
case IMSG_SCRIPT_GO:
if (hdr.len != sizeof(hdr))
error("corrupted message received");
// ret = priv_script_go();
hdr.code = IMSG_SCRIPT_GO_RET;
hdr.len = sizeof(struct imsg_hdr) + sizeof(int);
buf = buf_open(hdr.len);
if (buf != NULL) {
buf_add(buf, &hdr, sizeof(hdr));
buf_add(buf, &ret, sizeof(ret));
buf_close(fd, buf);
}
break;
default:
error("received unknown message, code %d", hdr.code);
}
}

View file

@ -1,2 +0,0 @@
#include "rosdhcp.h"

View file

@ -28,6 +28,10 @@ VOID ApiUnlock() {
LeaveCriticalSection( &ApiCriticalSection );
}
VOID ApiFree() {
DeleteCriticalSection( &ApiCriticalSection );
}
/* This represents the service portion of the DHCP client API */
DWORD DSLeaseIpAddress( PipeSendFunc Send, COMM_DHCP_REQ *Req ) {

View file

@ -54,10 +54,7 @@
*/
#include "rosdhcp.h"
#include <winsock2.h>
#include "dhcpd.h"
#include "privsep.h"
#include "debug.h"
#define PERIOD 0x2e
#define hyphenchar(c) ((c) == 0x2d)
@ -110,16 +107,9 @@ int check_arp( struct interface_info *ip, struct client_lease *lp )
time_t scripttime;
static VOID CALLBACK ServiceMain(DWORD argc, LPWSTR *argv);
static WCHAR ServiceName[] = L"DHCP";
static SERVICE_TABLE_ENTRYW ServiceTable[] =
{
{ServiceName, ServiceMain},
{NULL, NULL}
};
SERVICE_STATUS_HANDLE ServiceStatusHandle;
SERVICE_STATUS_HANDLE ServiceStatusHandle = 0;
SERVICE_STATUS ServiceStatus;
@ -192,7 +182,7 @@ ServiceControlHandler(DWORD dwControl,
}
static VOID CALLBACK
VOID NTAPI
ServiceMain(DWORD argc, LPWSTR *argv)
{
ServiceStatusHandle = RegisterServiceCtrlHandlerExW(ServiceName,
@ -200,53 +190,49 @@ ServiceMain(DWORD argc, LPWSTR *argv)
NULL);
if (!ServiceStatusHandle)
{
DbgPrint("DHCPCSVC: Unable to register service control handler (%x)\n", GetLastError);
return;
}
UpdateServiceStatus(SERVICE_START_PENDING);
ApiInit();
AdapterInit();
tzset();
memset(&sockaddr_broadcast, 0, sizeof(sockaddr_broadcast));
sockaddr_broadcast.sin_family = AF_INET;
sockaddr_broadcast.sin_port = htons(REMOTE_PORT);
sockaddr_broadcast.sin_addr.s_addr = INADDR_BROADCAST;
inaddr_any.s_addr = INADDR_ANY;
bootp_packet_handler = do_packet;
if (PipeInit() == INVALID_HANDLE_VALUE)
{
DbgPrint("DHCPCSVC: PipeInit() failed!\n");
AdapterStop();
ApiFree();
UpdateServiceStatus(SERVICE_STOPPED);
}
DH_DbgPrint(MID_TRACE,("DHCP Service Started\n"));
UpdateServiceStatus(SERVICE_RUNNING);
DH_DbgPrint(MID_TRACE,("Going into dispatch()\n"));
DbgPrint("DHCPCSVC: DHCP service is starting up\n");
dispatch();
}
DbgPrint("DHCPCSVC: DHCP service is shutting down\n");
int
main(int argc, char *argv[])
{
ApiInit();
AdapterInit();
PipeInit();
//AdapterStop();
//ApiFree();
/* FIXME: Close pipe and kill pipe thread */
tzset();
memset(&sockaddr_broadcast, 0, sizeof(sockaddr_broadcast));
sockaddr_broadcast.sin_family = AF_INET;
sockaddr_broadcast.sin_port = htons(REMOTE_PORT);
sockaddr_broadcast.sin_addr.s_addr = INADDR_BROADCAST;
inaddr_any.s_addr = INADDR_ANY;
DH_DbgPrint(MID_TRACE,("DHCP Service Started\n"));
bootp_packet_handler = do_packet;
DH_DbgPrint(MID_TRACE,("Going into dispatch()\n"));
StartServiceCtrlDispatcherW(ServiceTable);
/* not reached */
return (0);
}
void
usage(void)
{
// extern char *__progname;
// fprintf(stderr, "usage: %s [-dqu] ", __progname);
fprintf(stderr, "usage: dhclient [-dqu] ");
fprintf(stderr, "[-c conffile] [-l leasefile] interface\n");
exit(1);
UpdateServiceStatus(SERVICE_STOPPED);
}
/*
@ -1117,83 +1103,12 @@ void
state_panic(void *ipp)
{
struct interface_info *ip = ipp;
struct client_lease *loop = ip->client->active;
struct client_lease *lp;
time_t cur_time;
time_t cur_time;
time(&cur_time);
note("No DHCPOFFERS received.");
time(&cur_time);
/* We may not have an active lease, but we may have some
predefined leases that we can try. */
if (!ip->client->active && ip->client->leases)
goto activate_next;
/* Run through the list of leases and see if one can be used. */
while (ip->client->active) {
if (ip->client->active->expiry > cur_time) {
note("Trying recorded lease %s",
piaddr(ip->client->active->address));
/* Run the client script with the existing
parameters. */
script_init("TIMEOUT",
ip->client->active->medium);
script_write_params("new_", ip->client->active);
if (ip->client->alias)
script_write_params("alias_",
ip->client->alias);
/* If the old lease is still good and doesn't
yet need renewal, go into BOUND state and
timeout at the renewal time. */
if (cur_time <
ip->client->active->renewal) {
ip->client->state = S_BOUND;
note("bound: renewal in %ld seconds.",
(long int)(ip->client->active->renewal -
cur_time));
add_timeout(
ip->client->active->renewal,
state_bound, ip);
} else {
ip->client->state = S_BOUND;
note("bound: immediate renewal.");
state_bound(ip);
}
return;
}
/* If there are no other leases, give up. */
if (!ip->client->leases) {
ip->client->leases = ip->client->active;
ip->client->active = NULL;
break;
}
activate_next:
/* Otherwise, put the active lease at the end of the
lease list, and try another lease.. */
for (lp = ip->client->leases; lp->next; lp = lp->next)
;
lp->next = ip->client->active;
if (lp->next)
lp->next->next = NULL;
ip->client->active = ip->client->leases;
ip->client->leases = ip->client->leases->next;
/* If we already tried this lease, we've exhausted the
set of leases, so we might as well give up for
now. */
if (ip->client->active == loop)
break;
else if (!loop)
loop = ip->client->active;
}
/* No leases were available, or what was available didn't work, so
tell the shell script that we failed to allocate an address,
and try again later. */
note("No working leases in persistent database - sleeping.\n");
ip->client->state = S_INIT;
add_timeout(cur_time + ip->client->config->retry_interval, state_init,
@ -1239,8 +1154,6 @@ send_request(void *ipp)
if (ip->client->state == S_REBOOTING &&
!ip->client->medium &&
ip->client->active->medium ) {
script_init("MEDIUM", ip->client->active->medium);
/* If the medium we chose won't fly, go to INIT state. */
/* XXX Nothing for now */
@ -1708,41 +1621,6 @@ write_client_lease(struct interface_info *ip, struct client_lease *lease,
fflush(leaseFile);
}
void
script_init(char *reason, struct string_list *medium)
{
size_t len, mediumlen = 0;
struct imsg_hdr hdr;
struct buf *buf;
int errs;
if (medium != NULL && medium->string != NULL)
mediumlen = strlen(medium->string);
hdr.code = IMSG_SCRIPT_INIT;
hdr.len = sizeof(struct imsg_hdr) +
sizeof(size_t) + mediumlen +
sizeof(size_t) + strlen(reason);
if ((buf = buf_open(hdr.len)) == NULL)
return;
errs = 0;
errs += buf_add(buf, &hdr, sizeof(hdr));
errs += buf_add(buf, &mediumlen, sizeof(mediumlen));
if (mediumlen > 0)
errs += buf_add(buf, medium->string, mediumlen);
len = strlen(reason);
errs += buf_add(buf, &len, sizeof(len));
errs += buf_add(buf, reason, len);
if (errs)
error("buf_add: %d", WSAGetLastError());
if (buf_close(privfd, buf) == -1)
error("buf_close: %d", WSAGetLastError());
}
void
priv_script_init(struct interface_info *ip, char *reason, char *medium)
{
@ -1889,58 +1767,6 @@ supersede:
#endif
}
void
script_write_params(char *prefix, struct client_lease *lease)
{
size_t fn_len = 0, sn_len = 0, pr_len = 0;
struct imsg_hdr hdr;
struct buf *buf;
int errs, i;
if (lease->filename != NULL)
fn_len = strlen(lease->filename);
if (lease->server_name != NULL)
sn_len = strlen(lease->server_name);
if (prefix != NULL)
pr_len = strlen(prefix);
hdr.code = IMSG_SCRIPT_WRITE_PARAMS;
hdr.len = sizeof(hdr) + sizeof(struct client_lease) +
sizeof(size_t) + fn_len + sizeof(size_t) + sn_len +
sizeof(size_t) + pr_len;
for (i = 0; i < 256; i++)
hdr.len += sizeof(int) + lease->options[i].len;
scripttime = time(NULL);
if ((buf = buf_open(hdr.len)) == NULL)
return;
errs = 0;
errs += buf_add(buf, &hdr, sizeof(hdr));
errs += buf_add(buf, lease, sizeof(struct client_lease));
errs += buf_add(buf, &fn_len, sizeof(fn_len));
errs += buf_add(buf, lease->filename, fn_len);
errs += buf_add(buf, &sn_len, sizeof(sn_len));
errs += buf_add(buf, lease->server_name, sn_len);
errs += buf_add(buf, &pr_len, sizeof(pr_len));
errs += buf_add(buf, prefix, pr_len);
for (i = 0; i < 256; i++) {
errs += buf_add(buf, &lease->options[i].len,
sizeof(lease->options[i].len));
errs += buf_add(buf, lease->options[i].data,
lease->options[i].len);
}
if (errs)
error("buf_add: %d", WSAGetLastError());
if (buf_close(privfd, buf) == -1)
error("buf_close: %d", WSAGetLastError());
}
int
dhcp_option_ev_name(char *buf, size_t buflen, struct dhcp_option *option)
{

View file

@ -69,10 +69,8 @@ dispatch(void)
time_t howlong, cur_time;
struct timeval timeval;
if (!AdapterDiscover()) {
AdapterStop();
if (!AdapterDiscover())
return;
}
ApiLock();
@ -151,7 +149,7 @@ dispatch(void)
}
} while (1);
ApiUnlock(); /* Not reached currently */
ApiUnlock();
}
void
@ -182,7 +180,7 @@ got_one(struct protocol *l)
warning("Interface %s no longer appears valid.",
ip->name);
ip->dead = 1;
close(l->fd);
closesocket(l->fd);
remove_protocol(l);
adapter = AdapterFindInfo(ip);
if (adapter) {

View file

@ -6,22 +6,63 @@
* COPYRIGHT: Copyright 2005 Art Yerkes <ayerkes@speakeasy.net>
*/
#include <winsock2.h>
#include <dhcpcsdk.h>
#include <time.h>
#include <dhcp/rosdhcp_public.h>
#include <rosdhcp.h>
#define NDEBUG
#include <debug.h>
#define DHCP_TIMEOUT 1000
static HANDLE PipeHandle = INVALID_HANDLE_VALUE;
DWORD APIENTRY DhcpCApiInitialize(LPDWORD Version) {
*Version = 2;
return 0;
DWORD PipeMode;
/* Wait for the pipe to be available */
if (WaitNamedPipeW(DHCP_PIPE_NAME, NMPWAIT_USE_DEFAULT_WAIT))
{
/* It's available, let's try to open it */
PipeHandle = CreateFileW(DHCP_PIPE_NAME,
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
0,
NULL);
/* Check if we succeeded in opening the pipe */
if (PipeHandle == INVALID_HANDLE_VALUE)
{
/* We didn't */
return GetLastError();
}
else
{
/* Change the pipe into message mode */
PipeMode = PIPE_READMODE_MESSAGE;
if (!SetNamedPipeHandleState(PipeHandle, &PipeMode, NULL, NULL))
{
/* Mode change failed */
CloseHandle(PipeHandle);
PipeHandle = INVALID_HANDLE_VALUE;
return GetLastError();
}
else
{
/* We're good to go */
*Version = 2;
return NO_ERROR;
}
}
}
else
{
/* No good, we failed */
return GetLastError();
}
}
VOID APIENTRY DhcpCApiCleanup() {
CloseHandle(PipeHandle);
PipeHandle = INVALID_HANDLE_VALUE;
}
DWORD APIENTRY DhcpQueryHWInfo( DWORD AdapterIndex,
@ -33,12 +74,20 @@ DWORD APIENTRY DhcpQueryHWInfo( DWORD AdapterIndex,
DWORD BytesRead;
BOOL Result;
ASSERT(PipeHandle != INVALID_HANDLE_VALUE);
Req.Type = DhcpReqQueryHWInfo;
Req.AdapterIndex = AdapterIndex;
Result = CallNamedPipeW
( DHCP_PIPE_NAME, &Req, sizeof(Req), &Reply, sizeof(Reply),
&BytesRead, DHCP_TIMEOUT );
Result = TransactNamedPipe(PipeHandle,
&Req, sizeof(Req),
&Reply, sizeof(Reply),
&BytesRead, NULL);
if (!Result)
{
/* Pipe transaction failed */
return 0;
}
if( !Reply.Reply ) return 0;
else {
@ -55,12 +104,20 @@ DWORD APIENTRY DhcpLeaseIpAddress( DWORD AdapterIndex ) {
DWORD BytesRead;
BOOL Result;
ASSERT(PipeHandle != INVALID_HANDLE_VALUE);
Req.Type = DhcpReqLeaseIpAddress;
Req.AdapterIndex = AdapterIndex;
Result = CallNamedPipeW
( DHCP_PIPE_NAME, &Req, sizeof(Req), &Reply, sizeof(Reply),
&BytesRead, DHCP_TIMEOUT );
Result = TransactNamedPipe(PipeHandle,
&Req, sizeof(Req),
&Reply, sizeof(Reply),
&BytesRead, NULL);
if (!Result)
{
/* Pipe transaction failed */
return 0;
}
return Reply.Reply;
}
@ -71,12 +128,20 @@ DWORD APIENTRY DhcpReleaseIpAddressLease( DWORD AdapterIndex ) {
DWORD BytesRead;
BOOL Result;
ASSERT(PipeHandle != INVALID_HANDLE_VALUE);
Req.Type = DhcpReqReleaseIpAddress;
Req.AdapterIndex = AdapterIndex;
Result = CallNamedPipeW
( DHCP_PIPE_NAME, &Req, sizeof(Req), &Reply, sizeof(Reply),
&BytesRead, DHCP_TIMEOUT );
Result = TransactNamedPipe(PipeHandle,
&Req, sizeof(Req),
&Reply, sizeof(Reply),
&BytesRead, NULL);
if (!Result)
{
/* Pipe transaction failed */
return 0;
}
return Reply.Reply;
}
@ -87,12 +152,20 @@ DWORD APIENTRY DhcpRenewIpAddressLease( DWORD AdapterIndex ) {
DWORD BytesRead;
BOOL Result;
ASSERT(PipeHandle != INVALID_HANDLE_VALUE);
Req.Type = DhcpReqRenewIpAddress;
Req.AdapterIndex = AdapterIndex;
Result = CallNamedPipeW
( DHCP_PIPE_NAME, &Req, sizeof(Req), &Reply, sizeof(Reply),
&BytesRead, DHCP_TIMEOUT );
Result = TransactNamedPipe(PipeHandle,
&Req, sizeof(Req),
&Reply, sizeof(Reply),
&BytesRead, NULL);
if (!Result)
{
/* Pipe transaction failed */
return 0;
}
return Reply.Reply;
}
@ -105,14 +178,22 @@ DWORD APIENTRY DhcpStaticRefreshParams( DWORD AdapterIndex,
DWORD BytesRead;
BOOL Result;
ASSERT(PipeHandle != INVALID_HANDLE_VALUE);
Req.Type = DhcpReqStaticRefreshParams;
Req.AdapterIndex = AdapterIndex;
Req.Body.StaticRefreshParams.IPAddress = Address;
Req.Body.StaticRefreshParams.Netmask = Netmask;
Result = CallNamedPipeW
( DHCP_PIPE_NAME, &Req, sizeof(Req), &Reply, sizeof(Reply),
&BytesRead, DHCP_TIMEOUT );
Result = TransactNamedPipe(PipeHandle,
&Req, sizeof(Req),
&Reply, sizeof(Reply),
&BytesRead, NULL);
if (!Result)
{
/* Pipe transaction failed */
return 0;
}
return Reply.Reply;
}
@ -153,7 +234,7 @@ DhcpNotifyConfigChange(LPWSTR ServerName,
DWORD SubnetMask,
int DhcpAction)
{
DPRINT1("DhcpNotifyConfigChange not implemented yet\n");
DbgPrint("DHCPCSVC: DhcpNotifyConfigChange not implemented yet\n");
return 0;
}
@ -192,12 +273,15 @@ DWORD APIENTRY DhcpRosGetAdapterInfo( DWORD AdapterIndex,
DWORD BytesRead;
BOOL Result;
ASSERT(PipeHandle != INVALID_HANDLE_VALUE);
Req.Type = DhcpReqGetAdapterInfo;
Req.AdapterIndex = AdapterIndex;
Result = CallNamedPipeW
( DHCP_PIPE_NAME, &Req, sizeof(Req), &Reply, sizeof(Reply),
&BytesRead, DHCP_TIMEOUT );
Result = TransactNamedPipe(PipeHandle,
&Req, sizeof(Req),
&Reply, sizeof(Reply),
&BytesRead, NULL);
if ( 0 != Result && 0 != Reply.Reply ) {
*DhcpEnabled = Reply.GetAdapterInfo.DhcpEnabled;

View file

@ -2,8 +2,28 @@
<importlibrary definition="dhcpcsvc.spec" />
<include base="dhcpcsvc">include</include>
<library>ntdll</library>
<library>msvcrt</library>
<library>ws2_32</library>
<library>iphlpapi</library>
<library>advapi32</library>
<library>oldnames</library>
<directory name="dhcp">
<file>adapter.c</file>
<file>alloc.c</file>
<file>api.c</file>
<file>compat.c</file>
<file>dhclient.c</file>
<file>dispatch.c</file>
<file>hash.c</file>
<file>options.c</file>
<file>pipe.c</file>
<file>socket.c</file>
<file>tables.c</file>
<file>util.c</file>
</directory>
<directory name="include">
<pch>rosdhcp.h</pch>
</directory>
<file>dhcpcsvc.c</file>
<file>dhcpcsvc.rc</file>
</module>

View file

@ -43,5 +43,4 @@
@ stub McastRenewAddress
@ stub McastRequestAddress
@ stdcall DhcpRosGetAdapterInfo(long ptr ptr ptr ptr)
# The Windows DHCP client service is implemented in the DLL too
#@ stub ServiceMain
@ stdcall ServiceMain(long ptr)

View file

@ -8,11 +8,9 @@
#include <iprtrmib.h>
#include <iphlpapi.h>
#include <dhcpcsdk.h>
#include <stdio.h>
#include <io.h>
#include "stdint.h"
#include "predec.h"
#include <dhcp/rosdhcp_public.h>
#include <stdio.h>
#include <time.h>
#include "debug.h"
#define IFNAMSIZ MAX_INTERFACE_NAME_LEN
#undef interface /* wine/objbase.h -- Grrr */
@ -27,6 +25,10 @@
#define DHCP_DEFAULT_LEASE_TIME 43200 /* 12 hours */
#define _PATH_DHCLIENT_PID "\\systemroot\\system32\\drivers\\etc\\dhclient.pid"
typedef void *VOIDPTR;
typedef unsigned char u_int8_t;
typedef unsigned short u_int16_t;
typedef unsigned int u_int32_t;
typedef char *caddr_t;
#ifndef _SSIZE_T_DEFINED
#define _SSIZE_T_DEFINED
@ -51,6 +53,9 @@ typedef u_int32_t uintTIME;
typedef void (*handler_t) PROTO ((struct packet *));
struct iaddr;
struct interface_info;
typedef struct _DHCP_ADAPTER {
LIST_ENTRY ListEntry;
MIB_IFROW IfMib;
@ -74,13 +79,14 @@ typedef DWORD (*PipeSendFunc)( COMM_DHCP_REPLY *Reply );
void AdapterInit(VOID);
BOOLEAN AdapterDiscover(VOID);
void AdapterStop(VOID);
HANDLE PipeInit(VOID);
extern PDHCP_ADAPTER AdapterGetFirst();
extern PDHCP_ADAPTER AdapterGetNext(PDHCP_ADAPTER);
extern PDHCP_ADAPTER AdapterFindIndex( unsigned int AdapterIndex );
extern PDHCP_ADAPTER AdapterFindInfo( struct interface_info *info );
extern PDHCP_ADAPTER AdapterFindByHardwareAddress( u_int8_t haddr[16], u_int8_t hlen );
extern HANDLE PipeInit();
extern VOID ApiInit();
extern VOID ApiFree();
extern VOID ApiLock();
extern VOID ApiUnlock();
extern DWORD DSQueryHWInfo( PipeSendFunc Send, COMM_DHCP_REQ *Req );