mirror of
https://github.com/nikdoof/dhsd.git
synced 2025-12-11 09:32:16 +00:00
v0.0.3
This commit is contained in:
11
AUTHORS
11
AUTHORS
@@ -1,3 +1,8 @@
|
||||
* Andrew Williams (nik_doof@users.sourceforge.net)
|
||||
* Lee Robinson (boxy@users.sourceforge.net)
|
||||
* Mark Harrison (qwaszx@users.sourceforge.net)
|
||||
Programmers:
|
||||
|
||||
* Andrew Williams (nik_doof@users.sourceforge.net)
|
||||
|
||||
Testing:
|
||||
|
||||
* Lee Robinson (boxy@users.sourceforge.net)
|
||||
* Mark Harrison (qwaszx@users.sourceforge.net)
|
||||
|
||||
17
ChangeLog
17
ChangeLog
@@ -6,3 +6,20 @@ Version 0.02
|
||||
|
||||
* New makefile compile/install system
|
||||
* Now uses a config file
|
||||
|
||||
Version 0.02-1
|
||||
|
||||
* Fatal problems in the packaging, problems with the makefiles
|
||||
* Few minor bugfixes
|
||||
|
||||
Version 0.03
|
||||
|
||||
* Error checking code for HTTP returns
|
||||
* Fixed problem with devcheck() not returning properly on ip changes
|
||||
total re-write of the checking methods.
|
||||
* Multiple host support capable of handling upto 10 hosts.
|
||||
* Various speed improvements and bugfixes.
|
||||
|
||||
Version 0.04
|
||||
|
||||
*
|
||||
@@ -1,3 +1,4 @@
|
||||
EXTRA_DIST = TODO ChangeLog
|
||||
SUBDIRS = src scripts
|
||||
|
||||
|
||||
TAR = tar
|
||||
|
||||
@@ -64,6 +64,8 @@ VERSION = @VERSION@
|
||||
|
||||
EXTRA_DIST = TODO ChangeLog
|
||||
SUBDIRS = src scripts
|
||||
|
||||
TAR = tar
|
||||
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
|
||||
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
|
||||
CONFIG_HEADER = ./src/config.h
|
||||
@@ -75,7 +77,6 @@ missing mkinstalldirs src/config.h.in src/stamp-h.in
|
||||
|
||||
DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST)
|
||||
|
||||
TAR = gtar
|
||||
GZIP_ENV = --best
|
||||
all: all-redirect
|
||||
.SUFFIXES:
|
||||
|
||||
7
README
7
README
@@ -1,4 +1,4 @@
|
||||
DHSD v0.01 Beta
|
||||
DHSD v0.03 Beta
|
||||
---------------
|
||||
|
||||
DHSD is a dynamic update engine for the dhs.org dynamic dns service.
|
||||
@@ -13,5 +13,8 @@ Thanks go to:
|
||||
|
||||
* Sourceforge for hosting my project
|
||||
* Dyfet for his pdetach() code
|
||||
* DFX for his dprintf() code
|
||||
* Peter Mac Millan for his base64.c
|
||||
* #linpeople on OpenProjects for various linux ioctl help
|
||||
* #c on efnet for various c coding help
|
||||
* Boxy & Qwaz for the odd testing and bitching
|
||||
|
||||
|
||||
10
TODO
10
TODO
@@ -1,8 +1,8 @@
|
||||
* Multiple Device/Host config
|
||||
* Setuid/Setgid for daemon
|
||||
* More information in Syslog
|
||||
* .pid file output and more daemon config options
|
||||
* Error checking on http returns
|
||||
* Multiple Device/Host config (99%)
|
||||
* Setuid/Setgid for daemon (needed?) (0%)
|
||||
* More information in Syslog (50%)
|
||||
* .pid file output and more daemon config options (0%)
|
||||
* Error checking on http returns (99%)
|
||||
|
||||
Possible features:
|
||||
|
||||
|
||||
2
configure
vendored
2
configure
vendored
@@ -693,7 +693,7 @@ fi
|
||||
|
||||
PACKAGE=dhsd
|
||||
|
||||
VERSION=0.02
|
||||
VERSION=0.03
|
||||
|
||||
if test "`cd $srcdir && pwd`" != "`pwd`" && test -f $srcdir/config.status; then
|
||||
{ echo "configure: error: source directory already configured; run "make distclean" there first" 1>&2; exit 1; }
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
dnl Process this file with autoconf to produce a configure script.
|
||||
|
||||
AC_INIT(src/main.c)
|
||||
AM_INIT_AUTOMAKE(dhsd, 0.02)
|
||||
AM_INIT_AUTOMAKE(dhsd, 0.03)
|
||||
AC_PROG_MAKE_SET
|
||||
|
||||
dnl Checks for programs.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
EXTRA_DIST = dhsd dhsd.conf
|
||||
EXTRA_DIST = dhsd-rh dhsd-deb dhsd.conf
|
||||
|
||||
sysconfdir = /etc
|
||||
sysconf_DATA = dhsd.conf
|
||||
|
||||
@@ -61,7 +61,7 @@ MAKEINFO = @MAKEINFO@
|
||||
PACKAGE = @PACKAGE@
|
||||
VERSION = @VERSION@
|
||||
|
||||
EXTRA_DIST = dhsd dhsd.conf
|
||||
EXTRA_DIST = dhsd-rh dhsd-deb dhsd.conf
|
||||
|
||||
sysconfdir = /etc
|
||||
sysconf_DATA = dhsd.conf
|
||||
@@ -75,7 +75,7 @@ DIST_COMMON = Makefile.am Makefile.in
|
||||
|
||||
DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST)
|
||||
|
||||
TAR = gtar
|
||||
TAR = tar
|
||||
GZIP_ENV = --best
|
||||
all: all-redirect
|
||||
.SUFFIXES:
|
||||
|
||||
23
scripts/dhsd-deb
Executable file
23
scripts/dhsd-deb
Executable file
@@ -0,0 +1,23 @@
|
||||
#!/bin/sh
|
||||
# Start/stop the dhsd daemon by Boxy.
|
||||
|
||||
test -f /usr/sbin/dhsd || exit 0
|
||||
|
||||
case "$1" in
|
||||
start) echo -n "Starting dhsd ... "
|
||||
start-stop-daemon --start --quiet --exec /usr/sbin/dhsd
|
||||
echo "done"
|
||||
;;
|
||||
stop) echo -n "Stopping dhsd ... "
|
||||
start-stop-daemon --stop --quiet --exec /usr/sbin/dhsd
|
||||
echo "done"
|
||||
;;
|
||||
restart) echo -n "Re-starting dhsd ... "
|
||||
start-stop-daemon --stop --quiet --exec /usr/sbin/dhsd
|
||||
start-stop-daemon --start --quiet --exec /usr/sbin/dhsd
|
||||
echo "done"
|
||||
;;
|
||||
*) echo "Usage: /etc/init.d/dhsd start|stop|restart"; exit 1
|
||||
;;
|
||||
esac
|
||||
exit 0
|
||||
@@ -1,8 +1,9 @@
|
||||
# DHSD configure script
|
||||
# Please note that CASE MATTERS!
|
||||
|
||||
username=usernamehere
|
||||
passwd=passwdhere
|
||||
host=hosthere
|
||||
domain=domainhere
|
||||
device=ppp0
|
||||
USER=usernamehere
|
||||
PASS=passwdhere
|
||||
DEV=ppp0
|
||||
|
||||
HOST=example1.2y.net
|
||||
HOST=example2.2y.net
|
||||
|
||||
@@ -3,7 +3,7 @@ prefix = /usr
|
||||
EXTRA_DIST = config.h.in stamp-h.in
|
||||
|
||||
sbin_PROGRAMS = dhsd
|
||||
dhsd_SOURCES = main.c dhsd.h rconfig.c pdetach.c dprintf.c updateip.c devcheck.c base64.c debug.c
|
||||
dhsd_SOURCES = main.c dhsd.h rconfig.c pdetach.c updateip.c devcheck.c base64.c debug.c utils.c
|
||||
|
||||
if DEBUG
|
||||
DBG = -DDEBUG=1
|
||||
|
||||
@@ -66,7 +66,7 @@ prefix = /usr
|
||||
EXTRA_DIST = config.h.in stamp-h.in
|
||||
|
||||
sbin_PROGRAMS = dhsd
|
||||
dhsd_SOURCES = main.c dhsd.h rconfig.c pdetach.c dprintf.c updateip.c devcheck.c base64.c debug.c
|
||||
dhsd_SOURCES = main.c dhsd.h rconfig.c pdetach.c updateip.c devcheck.c base64.c debug.c utils.c
|
||||
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
|
||||
CONFIG_HEADER = ../src/config.h
|
||||
CONFIG_CLEAN_FILES =
|
||||
@@ -77,8 +77,8 @@ DEFS = @DEFS@ -I. -I$(srcdir) -I../src
|
||||
CPPFLAGS = @CPPFLAGS@
|
||||
LDFLAGS = @LDFLAGS@
|
||||
LIBS = @LIBS@
|
||||
dhsd_OBJECTS = main.o rconfig.o pdetach.o dprintf.o updateip.o \
|
||||
devcheck.o base64.o debug.o
|
||||
dhsd_OBJECTS = main.o rconfig.o pdetach.o updateip.o devcheck.o \
|
||||
base64.o debug.o utils.o
|
||||
dhsd_LDADD = $(LDADD)
|
||||
dhsd_DEPENDENCIES =
|
||||
dhsd_LDFLAGS =
|
||||
@@ -91,7 +91,7 @@ DIST_COMMON = Makefile.am Makefile.in
|
||||
|
||||
DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST)
|
||||
|
||||
TAR = gtar
|
||||
TAR = tar
|
||||
GZIP_ENV = --best
|
||||
SOURCES = $(dhsd_SOURCES)
|
||||
OBJECTS = $(dhsd_OBJECTS)
|
||||
|
||||
@@ -49,7 +49,7 @@ void benc( unsigned char *dst, unsigned char *s )
|
||||
|
||||
void encbasic( char *d, const char *u, const char *p )
|
||||
{
|
||||
char _buf[4*1024];
|
||||
char _buf[1024];
|
||||
|
||||
sprintf( _buf, "%s:%s", u, p);
|
||||
benc( d, _buf);
|
||||
|
||||
17
src/debug.c
17
src/debug.c
@@ -21,22 +21,33 @@
|
||||
#include "dhsd.h"
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
|
||||
void han_segv()
|
||||
{
|
||||
|
||||
/* TODO: add a method of debugging...dunno how! */
|
||||
|
||||
#ifdef HAVE_SYSLOG_H
|
||||
syslog(LOG_NOTICE,"Segmentation fault...exiting safely...");
|
||||
closelog();
|
||||
#endif
|
||||
close(sockfd);
|
||||
pdebug("SegFault in DHSD...exiting safely...");
|
||||
//return 1;
|
||||
exit(0);
|
||||
|
||||
signal(SIGSEGV,SIG_DFL);
|
||||
}
|
||||
|
||||
void pdebug(char *dmsg)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
printf("DhsD Debug: %s\n",dmsg);
|
||||
|
||||
#ifndef HAVE_SYSLOG_H
|
||||
printf("DHSD Debug: %s\n",dmsg);
|
||||
#else
|
||||
syslog(LOG_DEBUG,"DHSD Debug: %s",dmsg);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -32,14 +32,11 @@
|
||||
int devcheck(char *dev)
|
||||
{
|
||||
int fd;
|
||||
int strl;
|
||||
struct sockaddr *sa;
|
||||
struct sockaddr_in *sin;
|
||||
struct ifreq ifr;
|
||||
|
||||
char *toldaddr;
|
||||
|
||||
toldaddr = oldaddr;
|
||||
|
||||
fd = socket(PF_INET,SOCK_STREAM,0);
|
||||
if (fd == -1) {
|
||||
pdebug("socket() failed");
|
||||
@@ -49,17 +46,19 @@ int devcheck(char *dev)
|
||||
/* Copy the interface name into the buffer */
|
||||
strncpy(ifr.ifr_name,dev,IFNAMSIZ);
|
||||
|
||||
if (ioctl(fd,SIOCGIFADDR,&ifr) == -1) {
|
||||
if (ioctl(fd,SIOCGIFADDR,&ifr)) {
|
||||
pdebug("device ioctl failed");
|
||||
oldaddr = '\0'; // Hackaratus?
|
||||
//oldaddr = 0; // Hackaratus?
|
||||
return -1;
|
||||
}
|
||||
/* Now the buffer will contain the information we requested */
|
||||
sa = (struct sockaddr *)&(ifr.ifr_addr);
|
||||
if (sa->sa_family == AF_INET) {
|
||||
sin = (struct sockaddr_in*) sa;
|
||||
if (inet_ntoa(sin->sin_addr) != toldaddr) {
|
||||
oldaddr = inet_ntoa(sin->sin_addr);
|
||||
if (inet_addr(inet_ntoa(sin->sin_addr)) != oldaddr) {
|
||||
oldaddr = inet_addr(inet_ntoa(sin->sin_addr));
|
||||
strl = strlen(inet_ntoa(sin->sin_addr));
|
||||
strncpy(coldaddr,inet_ntoa(sin->sin_addr),strl);
|
||||
close(fd);
|
||||
return 1;
|
||||
} else {
|
||||
@@ -67,7 +66,7 @@ int devcheck(char *dev)
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
printf(": Unknown Address Family (%d)\n",sa->sa_family);
|
||||
pdebug("Unknown Address Family");
|
||||
}
|
||||
|
||||
close(fd);
|
||||
|
||||
32
src/dhsd.h
32
src/dhsd.h
@@ -25,7 +25,7 @@
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#define DHSD_CONFIG "/etc/dhsd.conf"
|
||||
#define DHSD_DEF_CONFIG "/etc/dhsd.conf"
|
||||
|
||||
#define DHS_IP "209.249.50.99"
|
||||
#define DHS_PORT 80
|
||||
@@ -40,16 +40,14 @@
|
||||
// pdetach.c - by dyfet@sourceforge.net
|
||||
void pdetach(void);
|
||||
|
||||
// dprintf.c - by dfx@sourceforge.net
|
||||
void dprintf(int fd, char *format, ...);
|
||||
|
||||
// devcheck.c
|
||||
char *oldaddr;
|
||||
unsigned long int oldaddr;
|
||||
char coldaddr[32];
|
||||
int devcheck(char *dev);
|
||||
|
||||
// updateip.c
|
||||
int sockfd;
|
||||
int updateip(char *ipaddr, char *dhsdom, char *dhshost);
|
||||
int updateip(char *ipaddr, char *host);
|
||||
|
||||
// debug.c
|
||||
void han_segv();
|
||||
@@ -59,11 +57,23 @@ void pdebug(char *dmsg);
|
||||
void encbasic( char *d, const char *u, const char *p );
|
||||
|
||||
// rconfig.c
|
||||
char dhs_username[10];
|
||||
char dhs_passwd[10];
|
||||
char dhs_host[10];
|
||||
char dhs_domain[10];
|
||||
char conf_dev[10];
|
||||
struct cdata config;
|
||||
char dhsd_config[255];
|
||||
int rconfig(char *filename);
|
||||
|
||||
struct cdata
|
||||
{
|
||||
char username[32];
|
||||
char passwd[32];
|
||||
char host[10][32];
|
||||
char device[10];
|
||||
int noofhosts;
|
||||
};
|
||||
|
||||
// utils.c
|
||||
void splitstr(char *src, char delim, char *dest1, char *dest2);
|
||||
|
||||
// UNTESTED BETA
|
||||
void filtercr(char *str);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define BUFLEN 4096
|
||||
|
||||
void dprintf(int fd, char *format, ...)
|
||||
{
|
||||
va_list arglist;
|
||||
char buffer[BUFLEN];
|
||||
|
||||
va_start(arglist, format);
|
||||
vsnprintf(buffer, BUFLEN, format, arglist);
|
||||
va_end(arglist);
|
||||
|
||||
write(fd, buffer, strlen(buffer));
|
||||
}
|
||||
64
src/main.c
64
src/main.c
@@ -34,58 +34,72 @@ void cleanup()
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
||||
int main(void)
|
||||
void sig_hup()
|
||||
{
|
||||
int doext;
|
||||
char verstring[255];
|
||||
int res;
|
||||
#ifdef USE_SYSLOG
|
||||
syslog(LOG_NOTICE,"HUP recived, reloading config");
|
||||
#endif
|
||||
pdebug("Reloading config");
|
||||
if (rconfig(dhsd_config)) {
|
||||
#ifdef USE_SYSLOG
|
||||
syslog(LOG_NOTICE,"Config file cant be found, or invalid...exiting");
|
||||
#endif
|
||||
pdebug("Config not found!");
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int i, res, doext;
|
||||
|
||||
printf("DhsD %s\n\n",VERSION);
|
||||
printf("Detaching to daemon...\n");
|
||||
#ifndef DEBUG
|
||||
pdetach();
|
||||
signal(SIGSEGV,han_segv);
|
||||
#endif
|
||||
signal(SIGINT,cleanup);
|
||||
signal(SIGKILL,cleanup);
|
||||
#ifndef DEBUG
|
||||
signal(SIGSEGV,han_segv);
|
||||
#endif
|
||||
signal(SIGHUP,sig_hup);
|
||||
|
||||
#ifdef HAVE_SYSLOG_H
|
||||
verstring[0] = '\0';
|
||||
openlog("dhsd",LOG_PID,LOG_DAEMON);
|
||||
sprintf(verstring, "DhsD %s loaded...",VERSION);
|
||||
syslog(LOG_NOTICE,verstring);
|
||||
syslog(LOG_NOTICE,"DHSD %s loaded...",VERSION);
|
||||
#endif
|
||||
|
||||
res = rconfig(DHSD_CONFIG);
|
||||
if (res == -1) {
|
||||
/* Loop here for multiple argvs */
|
||||
|
||||
if(argv[1]) {
|
||||
strncpy(dhsd_config,argv[1],strlen(argv[1]));
|
||||
} else {
|
||||
strncpy(dhsd_config,DHSD_DEF_CONFIG,strlen(DHSD_DEF_CONFIG));
|
||||
}
|
||||
if (rconfig(dhsd_config)) {
|
||||
#ifdef USE_SYSLOG
|
||||
syslog(LOG_ERR,"Config file cant be found, or invalid...exiting");
|
||||
syslog(LOG_NOTICE,"Config file cant be found, or invalid...exiting");
|
||||
#endif
|
||||
pdebug("Config not found!");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
do {
|
||||
if (devcheck(conf_dev) == 1) {
|
||||
if (devcheck(config.device)) {
|
||||
#ifdef HAVE_SYSLOG_H
|
||||
syslog(LOG_NOTICE,"device ip has changed, update initiated...");
|
||||
#endif
|
||||
|
||||
i = 0;
|
||||
|
||||
do {
|
||||
res = updateip(oldaddr,dhs_domain,dhs_host);
|
||||
if (res != 0) {
|
||||
while(updateip(coldaddr,config.host[i])) {;
|
||||
sleep(SLEEP_TIME);
|
||||
}
|
||||
} while(res != 0);
|
||||
#ifdef HAVE_SYSLOG_H
|
||||
syslog(LOG_NOTICE,"update complete");
|
||||
#endif
|
||||
};
|
||||
i++;
|
||||
} while(i != config.noofhosts);
|
||||
|
||||
}
|
||||
doext = 0;
|
||||
sleep(SLEEP_TIME);
|
||||
} while(doext == 0);
|
||||
} while(!doext);
|
||||
|
||||
cleanup();
|
||||
return 0;
|
||||
|
||||
@@ -22,40 +22,47 @@
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "dhsd.h"
|
||||
|
||||
void addhost (char *hostname)
|
||||
{
|
||||
strncat(config.host[config.noofhosts], hostname, strlen(hostname));
|
||||
pdebug(hostname);
|
||||
config.noofhosts++;
|
||||
}
|
||||
|
||||
void parseline(char *strbuf)
|
||||
{
|
||||
int strl;
|
||||
int i = 0;
|
||||
char cmd[10];
|
||||
char arg[10];
|
||||
char cmd[20];
|
||||
char arg[20];
|
||||
|
||||
bzero(cmd,10);
|
||||
bzero(arg,10);
|
||||
bzero(cmd,sizeof(cmd));
|
||||
bzero(arg,sizeof(arg));
|
||||
|
||||
strl = strlen(strbuf);
|
||||
//filtercr(strbuf);
|
||||
strbuf[strlen(strbuf)-1] = '\0';
|
||||
|
||||
if (strl > 0) {
|
||||
if (strbuf[0] == '#') return;
|
||||
if (strbuf[0] == '\n') return;
|
||||
while (i < strl) {
|
||||
if (strbuf[i] == '=') {
|
||||
strncpy(cmd, &strbuf[0], i);
|
||||
strncpy(arg, &strbuf[i+1], strlen(strbuf)-i-1);
|
||||
cmd[strlen(cmd)] = '\0';
|
||||
arg[strlen(arg)-1] = '\0';
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
};
|
||||
splitstr(strbuf, '=', cmd, arg);
|
||||
|
||||
if(strcmp("username",cmd) == 0) { strncat(dhs_username, arg, strlen(arg)); return; }
|
||||
if(strcmp("passwd",cmd) == 0) { strncat(dhs_passwd, arg, strlen(arg)); return; }
|
||||
if(strcmp("host",cmd) == 0) { strncat(dhs_host, arg, strlen(arg)); return; }
|
||||
if(strcmp("domain",cmd) == 0) { strncat(dhs_domain, arg, strlen(arg)); return; }
|
||||
if(strcmp("device",cmd) == 0) { strncat(conf_dev, arg, strlen(arg)); return; }
|
||||
if(!strcasecmp("USER",cmd)) {
|
||||
strncat(config.username, arg, strlen(arg));
|
||||
return;
|
||||
}
|
||||
if(!strcasecmp("PASS",cmd)) {
|
||||
strncat(config.passwd, arg, strlen(arg));
|
||||
return;
|
||||
}
|
||||
if(!strcasecmp("HOST",cmd)) {
|
||||
addhost(arg);
|
||||
return;
|
||||
}
|
||||
if(!strcasecmp("DEV",cmd)) {
|
||||
strncat(config.device, arg, strlen(arg));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,21 +75,21 @@ int rconfig(char *filename)
|
||||
{
|
||||
filefd = fopen(filename,"r");
|
||||
} else {
|
||||
filefd = fopen(DHSD_CONFIG,"r");
|
||||
filefd = fopen(DHSD_DEF_CONFIG,"r");
|
||||
}
|
||||
if (filefd == 0) {
|
||||
if (!filefd) {
|
||||
return -1;
|
||||
}
|
||||
/* Zero the strings */
|
||||
bzero(dhs_username,10);
|
||||
bzero(dhs_passwd,10);
|
||||
bzero(dhs_host,10);
|
||||
bzero(dhs_domain,10);
|
||||
bzero(conf_dev,4);
|
||||
bzero(config.username,sizeof(config.username));
|
||||
bzero(config.passwd,sizeof(config.passwd));
|
||||
bzero(config.host,sizeof(config.host));
|
||||
bzero(config.device,sizeof(config.device));
|
||||
config.noofhosts = 0;
|
||||
|
||||
/* Start parsing the file */
|
||||
|
||||
while (fgets(strbuf, 255, filefd)) {
|
||||
while (fgets(strbuf, 255, filefd) != NULL) {
|
||||
if (strbuf) {
|
||||
parseline(strbuf);
|
||||
}
|
||||
@@ -90,6 +97,11 @@ int rconfig(char *filename)
|
||||
|
||||
fclose(filefd);
|
||||
|
||||
return 0;
|
||||
if(config.username && config.passwd && config.device && config.noofhosts) {
|
||||
return 0;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ int sconnect(char *ip)
|
||||
return isock;
|
||||
}
|
||||
|
||||
int updateip(char *ipaddr, char *dhsdom, char *dhshost)
|
||||
int updateip(char *ipaddr, char *host)
|
||||
{
|
||||
char post_data[128];
|
||||
char post_head[128];
|
||||
@@ -60,14 +60,23 @@ int updateip(char *ipaddr, char *dhsdom, char *dhshost)
|
||||
char b64str[64];
|
||||
int ibytes;
|
||||
|
||||
encbasic(b64str,dhs_username,dhs_passwd);
|
||||
sprintf(chostname,"%s.%s",dhshost,dhsdom);
|
||||
char hostn[32];
|
||||
char domn[32];
|
||||
|
||||
bzero(hostn,32);
|
||||
bzero(domn,32);
|
||||
|
||||
splitstr(host, '.', hostn, domn);
|
||||
|
||||
encbasic(b64str,config.username,config.passwd);
|
||||
|
||||
sprintf(auth_head,"Authorization: Basic %s\r\n",b64str);
|
||||
|
||||
sprintf(post_data,"%stype=4&updatetype=Online&hostscmd=edit&hostscmdstage=2&ip=%s&mx=%s&domain=%s&hostname=%s",DHS_ADDR,ipaddr,chostname,dhsdom,dhshost);
|
||||
|
||||
sprintf(post_data,"%stype=4&updatetype=Online&hostscmd=edit&hostscmdstage=2&ip=%s&mx=%s&domain=%s&hostname=%s",DHS_ADDR,ipaddr,host,domn,hostn);
|
||||
sprintf(post_head,"GET %s HTTP/1.0\r\n",post_data);
|
||||
|
||||
pdebug(post_head);
|
||||
|
||||
sockfd = sconnect(DHS_IP);
|
||||
if (sockfd == -1) {
|
||||
pdebug("sconnect() failed");
|
||||
@@ -76,8 +85,6 @@ int updateip(char *ipaddr, char *dhsdom, char *dhshost)
|
||||
|
||||
sprintf(outbuf,"%s%s\r\n\r\n",post_head,auth_head);
|
||||
|
||||
//pdebug(outbuf);
|
||||
|
||||
send(sockfd,outbuf,strlen(outbuf),0);
|
||||
|
||||
do {
|
||||
@@ -87,12 +94,34 @@ int updateip(char *ipaddr, char *dhsdom, char *dhshost)
|
||||
strncat(databuf,tmpdatabuf,strlen(tmpdatabuf));
|
||||
}
|
||||
} while (ibytes > 0);
|
||||
pdebug(databuf);
|
||||
|
||||
fclose(sockfd);
|
||||
close(sockfd);
|
||||
|
||||
/* Some error checking code could be handy... */
|
||||
/* Some very basic error checkin */
|
||||
|
||||
return 0;
|
||||
if(strstr(databuf,"401")) {
|
||||
#if HAVE_SYSLOG_H
|
||||
syslog(LOG_NOTICE,"%s: authorization failed",host);
|
||||
#endif
|
||||
pdebug("Auth Failed");
|
||||
return 0;
|
||||
}
|
||||
if (strstr(databuf,"wombat.dhs.org:")) {
|
||||
#ifdef HAVE_SYSLOG_H
|
||||
syslog(LOG_NOTICE,"%s: update complete",host);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
if (strstr(databuf,"The update has already been done previously.")) {
|
||||
#ifdef HAVE_SYSLOG_H
|
||||
syslog(LOG_NOTICE,"%s: update already occured",host);
|
||||
#endif
|
||||
pdebug("update already occured! returning success...");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* if all else fails...send a error */
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
66
src/utils.c
Normal file
66
src/utils.c
Normal file
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
DHSD utils.c - Utillity code
|
||||
Copyright (C) 2000 Andrew Williams
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
USA
|
||||
|
||||
*/
|
||||
|
||||
|
||||
void splitstr(char *src, char delim, char *dest1, char *dest2)
|
||||
{
|
||||
int strl, i;
|
||||
|
||||
i = 0;
|
||||
strl = strlen(src);
|
||||
|
||||
if (strl > 0) {
|
||||
while (i < strl) {
|
||||
if (src[i] == delim) {
|
||||
strncpy(dest1, &src[0], i);
|
||||
strncpy(dest2, &src[i+1], strlen(src)-i-1);
|
||||
dest1[strlen(dest1)] = '\0';
|
||||
dest2[strlen(dest2)] = '\0';
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
void filtercr(char *str)
|
||||
{
|
||||
int i;
|
||||
int strl;
|
||||
char tmpstr[256];
|
||||
|
||||
i = 0;
|
||||
strl = strlen(str);
|
||||
bzero(tmpstr,256);
|
||||
|
||||
|
||||
if (strl > 0) {
|
||||
while (i < strl) {
|
||||
if (str[i] == '\n') {
|
||||
strncpy(tmpstr, &str[0], i-1);
|
||||
tmpstr[strlen(tmpstr)] = '\0';
|
||||
bzero(str,strl);
|
||||
str = tmpstr;
|
||||
}
|
||||
i++;
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user