Update to latest ncmlib changes.
This commit is contained in:
parent
abda60e0e9
commit
82d9682ed8
@ -2,8 +2,8 @@ project (ndhcp)
|
||||
|
||||
cmake_minimum_required (VERSION 2.6)
|
||||
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -pedantic -Wall -Wextra -Wformat=2 -Wformat-nonliteral -Wformat-security -Wshadow -Wpointer-arith -Wmissing-prototypes -lrt -lcap -D_GNU_SOURCE -DHAVE_CLEARENV")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -pedantic -Wall -Wextra -Wformat=2 -Wformat-nonliteral -Wformat-security -Wshadow -Wpointer-arith -Wmissing-prototypes -lrt -lcap -D_GNU_SOURCE -DHAVE_CLEARENV")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -pedantic -Wall -Wextra -Wformat=2 -Wformat-nonliteral -Wformat-security -Wshadow -Wpointer-arith -Wmissing-prototypes -lrt -lcap -D_GNU_SOURCE -DNK_USE_CAPABILITY")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -pedantic -Wall -Wextra -Wformat=2 -Wformat-nonliteral -Wformat-security -Wshadow -Wpointer-arith -Wmissing-prototypes -lrt -lcap -D_GNU_SOURCE -DNK_USE_CAPABILITY")
|
||||
|
||||
if (WIN32)
|
||||
set(OSNAME "Win32")
|
||||
|
@ -39,6 +39,8 @@
|
||||
#include <linux/filter.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include "nk/log.h"
|
||||
#include "nk/io.h"
|
||||
#include "arp.h"
|
||||
#include "state.h"
|
||||
#include "dhcp.h"
|
||||
@ -46,8 +48,6 @@
|
||||
#include "ifchange.h"
|
||||
#include "options.h"
|
||||
#include "leasefile.h"
|
||||
#include "log.h"
|
||||
#include "io.h"
|
||||
|
||||
#define ARP_MSG_SIZE 0x2a
|
||||
#define ARP_RETRANS_DELAY 5000 // ms
|
||||
|
@ -30,7 +30,6 @@
|
||||
|
||||
#include <stdint.h>
|
||||
#include <net/if_arp.h>
|
||||
|
||||
#include "ndhc.h"
|
||||
#include "dhcp.h"
|
||||
|
||||
|
@ -44,16 +44,16 @@
|
||||
#include <linux/filter.h>
|
||||
#include <time.h>
|
||||
#include <errno.h>
|
||||
#include "nk/log.h"
|
||||
#include "nk/io.h"
|
||||
#include "nk/random.h"
|
||||
|
||||
#include "dhcp.h"
|
||||
#include "state.h"
|
||||
#include "arp.h"
|
||||
#include "ifchange.h"
|
||||
#include "sys.h"
|
||||
#include "log.h"
|
||||
#include "io.h"
|
||||
#include "options.h"
|
||||
#include "random.h"
|
||||
|
||||
typedef enum {
|
||||
LM_NONE = 0,
|
||||
|
@ -29,6 +29,7 @@
|
||||
#ifndef NDHC_DHCP_H_
|
||||
#define NDHC_DHCP_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include <netinet/udp.h>
|
||||
#include <netinet/ip.h>
|
||||
#include "ndhc.h"
|
||||
|
@ -35,10 +35,10 @@
|
||||
#include <fcntl.h>
|
||||
#include <limits.h>
|
||||
#include <errno.h>
|
||||
#include "nk/log.h"
|
||||
#include "nk/random.h"
|
||||
#include "nk/io.h"
|
||||
#include "duiaid.h"
|
||||
#include "log.h"
|
||||
#include "random.h"
|
||||
#include "io.h"
|
||||
#include "ndhc.h"
|
||||
|
||||
static void get_duid_path(char *duidfile, size_t dlen)
|
||||
@ -81,7 +81,7 @@ static void get_iaid_path(char *iaidfile, size_t ilen, uint8_t *hwaddr,
|
||||
|
||||
static int open_duidfile_read(void)
|
||||
{
|
||||
char duidfile[MAX_PATH_LENGTH];
|
||||
char duidfile[PATH_MAX];
|
||||
get_duid_path(duidfile, sizeof duidfile);
|
||||
int fd = open(duidfile, O_RDONLY, 0);
|
||||
if (fd < 0) {
|
||||
@ -93,7 +93,7 @@ static int open_duidfile_read(void)
|
||||
|
||||
static int open_duidfile_write(void)
|
||||
{
|
||||
char duidfile[MAX_PATH_LENGTH];
|
||||
char duidfile[PATH_MAX];
|
||||
get_duid_path(duidfile, sizeof duidfile);
|
||||
int fd = open(duidfile, O_WRONLY|O_TRUNC|O_CREAT, 0644);
|
||||
if (fd < 0) {
|
||||
@ -106,7 +106,7 @@ static int open_duidfile_write(void)
|
||||
|
||||
static int open_iaidfile_read(uint8_t *hwaddr, size_t hwaddrlen)
|
||||
{
|
||||
char iaidfile[MAX_PATH_LENGTH];
|
||||
char iaidfile[PATH_MAX];
|
||||
get_iaid_path(iaidfile, sizeof iaidfile, hwaddr, hwaddrlen);
|
||||
int fd = open(iaidfile, O_RDONLY, 0);
|
||||
if (fd < 0) {
|
||||
@ -118,7 +118,7 @@ static int open_iaidfile_read(uint8_t *hwaddr, size_t hwaddrlen)
|
||||
|
||||
static int open_iaidfile_write(uint8_t *hwaddr, size_t hwaddrlen)
|
||||
{
|
||||
char iaidfile[MAX_PATH_LENGTH];
|
||||
char iaidfile[PATH_MAX];
|
||||
get_iaid_path(iaidfile, sizeof iaidfile, hwaddr, hwaddrlen);
|
||||
int fd = open(iaidfile, O_WRONLY|O_TRUNC|O_CREAT, 0644);
|
||||
if (fd < 0) {
|
||||
|
@ -35,14 +35,14 @@
|
||||
#include <sys/types.h>
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include "nk/log.h"
|
||||
#include "nk/io.h"
|
||||
|
||||
#include "options.h"
|
||||
#include "ndhc.h"
|
||||
#include "dhcp.h"
|
||||
#include "options.h"
|
||||
#include "arp.h"
|
||||
#include "log.h"
|
||||
#include "io.h"
|
||||
#include "ifchange.h"
|
||||
|
||||
static struct dhcpmsg cfg_packet; // Copy of the current configuration packet.
|
||||
|
@ -31,10 +31,10 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <arpa/inet.h>
|
||||
#include "nk/log.h"
|
||||
|
||||
#include "ifchd-parse.h"
|
||||
#include "ifchd.h"
|
||||
#include "log.h"
|
||||
#include "ifset.h"
|
||||
#include "ndhc.h"
|
||||
|
||||
|
23
ndhc/ifchd.c
23
ndhc/ifchd.c
@ -39,24 +39,21 @@
|
||||
#include <sys/prctl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include <signal.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <getopt.h>
|
||||
#include "nk/log.h"
|
||||
#include "nk/privilege.h"
|
||||
#include "nk/pidfile.h"
|
||||
#include "nk/signals.h"
|
||||
#include "nk/io.h"
|
||||
|
||||
#include "seccomp.h"
|
||||
#include "ifchd.h"
|
||||
#include "ndhc.h"
|
||||
#include "log.h"
|
||||
#include "chroot.h"
|
||||
#include "pidfile.h"
|
||||
#include "signals.h"
|
||||
#include "ifchd-parse.h"
|
||||
#include "cap.h"
|
||||
#include "io.h"
|
||||
#include "sys.h"
|
||||
#include "ifset.h"
|
||||
#include "seccomp.h"
|
||||
|
||||
struct ifchd_client cl;
|
||||
|
||||
@ -70,7 +67,7 @@ static int resolv_conf_fd = -1;
|
||||
/* If true, allow HOSTNAME changes from dhcp server. */
|
||||
int allow_hostname = 0;
|
||||
|
||||
char pidfile_ifch[MAX_PATH_LENGTH] = PID_FILE_IFCH_DEFAULT;
|
||||
char pidfile_ifch[PATH_MAX] = PID_FILE_IFCH_DEFAULT;
|
||||
uid_t ifch_uid = 0;
|
||||
gid_t ifch_gid = 0;
|
||||
|
||||
@ -417,10 +414,10 @@ void ifch_main(void)
|
||||
}
|
||||
memset(resolv_conf_d, '\0', sizeof resolv_conf_d);
|
||||
|
||||
imprison(chroot_dir);
|
||||
nk_set_chroot(chroot_dir);
|
||||
memset(chroot_dir, '\0', sizeof chroot_dir);
|
||||
set_cap(ifch_uid, ifch_gid, "cap_net_admin=ep");
|
||||
drop_root(ifch_uid, ifch_gid);
|
||||
nk_set_capability("cap_net_admin=ep");
|
||||
nk_set_uidgid(ifch_uid, ifch_gid);
|
||||
|
||||
do_ifch_work();
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
#ifndef NJK_IFCHD_H_
|
||||
#define NJK_IFCHD_H_
|
||||
|
||||
#include <limits.h>
|
||||
#include "ndhc-defines.h"
|
||||
|
||||
enum ifchd_states {
|
||||
@ -32,7 +33,7 @@ struct ifchd_client {
|
||||
extern struct ifchd_client cl;
|
||||
|
||||
extern int allow_hostname;
|
||||
extern char pidfile_ifch[MAX_PATH_LENGTH];
|
||||
extern char pidfile_ifch[PATH_MAX];
|
||||
extern uid_t ifch_uid;
|
||||
extern gid_t ifch_gid;
|
||||
|
||||
|
@ -44,13 +44,12 @@
|
||||
#include <linux/rtnetlink.h>
|
||||
#include <pwd.h>
|
||||
#include <grp.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include "nk/log.h"
|
||||
|
||||
#include "ifset.h"
|
||||
#include "ifchd.h"
|
||||
#include "ndhc.h"
|
||||
#include "log.h"
|
||||
#include "nl.h"
|
||||
|
||||
static uint32_t ifset_nl_seq = 1;
|
||||
|
@ -37,11 +37,10 @@
|
||||
#include <arpa/inet.h>
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include "nk/log.h"
|
||||
#include "nk/io.h"
|
||||
#include "leasefile.h"
|
||||
#include "ndhc.h"
|
||||
#include "log.h"
|
||||
#include "io.h"
|
||||
#include "defines.h"
|
||||
|
||||
static int leasefilefd = -1;
|
||||
|
||||
|
@ -1,8 +1,6 @@
|
||||
#ifndef NDHC_DEFINES_H_
|
||||
#define NDHC_DEFINES_H_
|
||||
|
||||
#include "defines.h"
|
||||
|
||||
#define PID_FILE_DEFAULT "/var/run/ndhc.pid"
|
||||
#define PID_FILE_IFCH_DEFAULT "/var/run/ifchd.pid"
|
||||
#define NDHC_VERSION "1.5"
|
||||
|
28
ndhc/ndhc.c
28
ndhc/ndhc.c
@ -49,9 +49,15 @@
|
||||
#include <pwd.h>
|
||||
#include <grp.h>
|
||||
#include <limits.h>
|
||||
#include "nk/log.h"
|
||||
#include "nk/privilege.h"
|
||||
#include "nk/pidfile.h"
|
||||
#include "nk/io.h"
|
||||
#include "nk/copy_cmdarg.h"
|
||||
|
||||
#include "ndhc.h"
|
||||
#include "ndhc-defines.h"
|
||||
#include "seccomp.h"
|
||||
#include "state.h"
|
||||
#include "options.h"
|
||||
#include "dhcp.h"
|
||||
@ -62,15 +68,8 @@
|
||||
#include "netlink.h"
|
||||
#include "leasefile.h"
|
||||
#include "ifset.h"
|
||||
#include "log.h"
|
||||
#include "chroot.h"
|
||||
#include "cap.h"
|
||||
#include "pidfile.h"
|
||||
#include "io.h"
|
||||
#include "seccomp.h"
|
||||
#include "ifchd.h"
|
||||
#include "duiaid.h"
|
||||
#include "copy_cmdarg.h"
|
||||
|
||||
struct client_state_t cs = {
|
||||
.ifchWorking = 0,
|
||||
@ -339,10 +338,10 @@ jumpstart:
|
||||
}
|
||||
}
|
||||
|
||||
char state_dir[MAX_PATH_LENGTH] = "/etc/ndhc";
|
||||
char chroot_dir[MAX_PATH_LENGTH] = "";
|
||||
char resolv_conf_d[MAX_PATH_LENGTH] = "";
|
||||
static char pidfile[MAX_PATH_LENGTH] = PID_FILE_DEFAULT;
|
||||
char state_dir[PATH_MAX] = "/etc/ndhc";
|
||||
char chroot_dir[PATH_MAX] = "";
|
||||
char resolv_conf_d[PATH_MAX] = "";
|
||||
static char pidfile[PATH_MAX] = PID_FILE_DEFAULT;
|
||||
static uid_t ndhc_uid = 0;
|
||||
static gid_t ndhc_gid = 0;
|
||||
int pToNdhcR;
|
||||
@ -390,12 +389,11 @@ static void ndhc_main(void) {
|
||||
|
||||
open_leasefile();
|
||||
|
||||
imprison(chroot_dir);
|
||||
nk_set_chroot(chroot_dir);
|
||||
memset(chroot_dir, '\0', sizeof chroot_dir);
|
||||
|
||||
set_cap(ndhc_uid, ndhc_gid,
|
||||
"cap_net_bind_service,cap_net_broadcast,cap_net_raw=ep");
|
||||
drop_root(ndhc_uid, ndhc_gid);
|
||||
nk_set_capability("cap_net_bind_service,cap_net_broadcast,cap_net_raw=ep");
|
||||
nk_set_uidgid(ndhc_uid, ndhc_gid);
|
||||
|
||||
if (cs.ifsPrevState != IFS_UP)
|
||||
ifchange_deconfig(&cs);
|
||||
|
10
ndhc/ndhc.h
10
ndhc/ndhc.h
@ -29,9 +29,9 @@
|
||||
#define NJK_NDHC_NDHC_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include <limits.h>
|
||||
#include <net/if.h>
|
||||
#include "defines.h"
|
||||
#include "random.h"
|
||||
#include "nk/random.h"
|
||||
|
||||
struct client_state_t {
|
||||
unsigned long long leaseStartTime;
|
||||
@ -71,9 +71,9 @@ extern int pToIfchR;
|
||||
extern int pToIfchW;
|
||||
extern int pToNdhcR;
|
||||
extern int pToNdhcW;
|
||||
extern char state_dir[MAX_PATH_LENGTH];
|
||||
extern char chroot_dir[MAX_PATH_LENGTH];
|
||||
extern char resolv_conf_d[MAX_PATH_LENGTH];
|
||||
extern char state_dir[PATH_MAX];
|
||||
extern char chroot_dir[PATH_MAX];
|
||||
extern char resolv_conf_d[PATH_MAX];
|
||||
|
||||
void background(void);
|
||||
|
||||
|
@ -37,9 +37,9 @@
|
||||
#include <time.h>
|
||||
#include <errno.h>
|
||||
#include <poll.h>
|
||||
#include "nk/log.h"
|
||||
|
||||
#include "netlink.h"
|
||||
#include "log.h"
|
||||
#include "nl.h"
|
||||
#include "state.h"
|
||||
|
||||
|
@ -35,7 +35,7 @@
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include "log.h"
|
||||
#include "nk/log.h"
|
||||
#include "nl.h"
|
||||
|
||||
int rtattr_assign(struct rtattr *attr, int type, void *data)
|
||||
|
@ -30,9 +30,9 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <arpa/inet.h>
|
||||
#include "nk/log.h"
|
||||
|
||||
#include "options.h"
|
||||
#include "log.h"
|
||||
|
||||
static int do_overload_value(const uint8_t *buf, ssize_t blen, int overload)
|
||||
{
|
||||
|
@ -27,8 +27,8 @@
|
||||
*/
|
||||
#include <stdbool.h>
|
||||
#include "seccomp.h"
|
||||
#include "log.h"
|
||||
#include "seccomp-bpf.h"
|
||||
#include "nk/log.h"
|
||||
#include "nk/seccomp-bpf.h"
|
||||
|
||||
bool seccomp_enforce = false;
|
||||
|
||||
|
@ -31,14 +31,15 @@
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include "nk/log.h"
|
||||
#include "nk/random.h"
|
||||
|
||||
#include "state.h"
|
||||
#include "ifchange.h"
|
||||
#include "arp.h"
|
||||
#include "options.h"
|
||||
#include "log.h"
|
||||
#include "ndhc.h"
|
||||
#include "sys.h"
|
||||
#include "random.h"
|
||||
|
||||
static void selecting_packet(struct client_state_t *cs, struct dhcpmsg *packet,
|
||||
uint8_t msgtype);
|
||||
|
@ -30,8 +30,9 @@
|
||||
#include <errno.h>
|
||||
#include <sys/epoll.h>
|
||||
#include <sys/signalfd.h>
|
||||
#include "nk/log.h"
|
||||
|
||||
#include "sys.h"
|
||||
#include "log.h"
|
||||
|
||||
void epoll_add(int epfd, int fd)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user