Skip to content

Commit

Permalink
Add autoconf, man page and correct dns compression.
Browse files Browse the repository at this point in the history
This is now a working package.
  • Loading branch information
davidl committed May 9, 2006
1 parent a5fff26 commit 2e76097
Show file tree
Hide file tree
Showing 15 changed files with 254 additions and 58 deletions.
9 changes: 0 additions & 9 deletions Makefile

This file was deleted.

24 changes: 24 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# (c) 2006, Quest Software, Inc, All rights reserved.

AUTOMAKE_OPTIONS= foreign

VAS_CFLAGS= `$(VASCONFIG) --cflags vas`
VAS_LIBS= `$(VASCONFIG) --libs vas`

sbin_PROGRAMS = dnsupdate
man_MANS = dnsupdate.8

dnsupdate_SOURCES= dnsupdate.c dns.c dnstcp.c \
dnsdebug.c dnstkey.c dnstsig.c \
common.h dns.h dnsdebug.h dnstcp.h \
dnstkey.h dnstsig.h
dnsupdate_LDADD= $(LIBOBJS)
dnsupdate_CFLAGS= $(VAS_CFLAGS)
dnsupdate_LDFLAGS= $(VAS_LIBS)

dnsupdate.spec: dnsupdate.spec.in
sed -e 's,[@]VERSION[@],$(VERSION),g' < $(srcdir)/dnsupdate.spec.in > $@

EXTRA_DIST= dnsupdate.spec dnsupdate.spec.in $(man_MANS) err.h


48 changes: 48 additions & 0 deletions common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@

#if HAVE_CONFIG_H
# include <config.h>
#endif

#if STDC_HEADERS
# include <stdlib.h>
# include <stdio.h>
# include <string.h>
# include <assert.h>
# include <stddef.h>
# include <stdarg.h>
#else
# if !HAVE_MEMCPY
# define memcpy(d, s, n) bcopy(s, d, n)
# endif
#endif

#if TIME_WITH_SYS_TIME
# include <sys/time.h>
# include <time.h>
#else
# if HAVE_SYS_TIME_H
# include <sys/time.h>
# else
# include <time.h>
# endif
#endif

#if HAVE_NETDB_H
# include <netdb.h>
#endif

#if HAVE_UNISTD_H
# include <unistd.h>
#endif

#if HAVE_SYS_SOCKET_H
# include <sys/socket.h>
#endif

#if HAVE_ERRNO_H
# include <errno.h>
#endif

#if !HAVE_SOCKLEN_T
# define socklen_t int
#endif
39 changes: 39 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# (c) 2006 Quest Software, Inc. All rights reserved.

AC_INIT([dnsupdate],
[1.0.0.]esyscmd(svnversion -n . /trunk || echo 0),
[[email protected]])
AM_INIT_AUTOMAKE
AC_CONFIG_SRCDIR([dnsupdate.c])
AC_CONFIG_FILES([Makefile])
AC_CONFIG_HEADERS([config.h])

AC_PREFIX_DEFAULT([/opt/quest])

AC_PROG_CC
AC_C_CONST
AC_HEADER_STDC
AC_HEADER_TIME
AC_CHECK_HEADERS([netdb.h unistd.h sys/socket.h errno.h netinet/in.h])

AC_PATH_PROG([VASCONFIG], [vas-config], [no], [/opt/quest/bin:$PATH])
if test x"$VASCONFIG" = x"no"; then
AC_MSG_ERROR([vas-config was not found; is the VAS SDK installed?])
fi
AC_SUBST([VASCONFIG])

AC_CHECK_FUNC([getaddrinfo])
AC_CHECK_FUNC([getopt], [], [AC_LIBOBJ([getopt])])
AC_CHECK_FUNCS([err errx warn warnx], [], [AC_LIBOBJ([err])
break])
AC_SEARCH_LIBS([socket], [socket])
AC_SEARCH_LIBS([gethostbyname], [nsl])


AC_CHECK_TYPE([socklen_t],[AC_DEFINE([HAVE_SOCKLEN_T],[1],[socklen_t])],,[
#if HAVE_SYS_SOCKET_H
# include <sys/socket.h>
#endif
])

AC_OUTPUT
26 changes: 20 additions & 6 deletions dns.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
/* (c) 2006 Quest Software, Inc. All rights reserved. */
/* David Leonard, 2006 */
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include <string.h>

#include "common.h"
#include "dns.h"

/*
Expand Down Expand Up @@ -32,6 +30,8 @@
/* Functions to call on error */
static void (*error_handler)(const char *, void *);
static void *error_handler_closure;
static void rd_name(struct dns_msg *msg, char *buf, size_t bufsz,
int canon_only);

int dns_never_compress = 0;

Expand Down Expand Up @@ -319,8 +319,8 @@ dns_msg_getbuf(const struct dns_msg *msg, void **bufp, size_t *szp)
* Reads a domain name from the buffer. Automatically decompresses.
* The buffer is filled in with dot (.) used as a delimiter
*/
void
dns_rd_name(struct dns_msg *msg, char *buf, size_t bufsz)
static void
rd_name(struct dns_msg *msg, char *buf, size_t bufsz, int canon_only)
{
unsigned char b, b2;
char *p = buf;
Expand All @@ -345,6 +345,8 @@ dns_rd_name(struct dns_msg *msg, char *buf, size_t bufsz)
dns_rd_data_raw(msg, p, b);
p += b;
} else { /* compression pointer */
if (canon_only)
rd_error("invalid name compression");
if (pos_save)
rd_error("multiple compression");
dns_rd_data_raw(msg, &b2, sizeof b2);
Expand Down Expand Up @@ -372,6 +374,18 @@ dns_rd_name(struct dns_msg *msg, char *buf, size_t bufsz)
rd_error("buffer is too small");
}

void
dns_rd_name(struct dns_msg *msg, char *buf, size_t bufsz)
{
rd_name(msg, buf, bufsz, 0);
}

void
dns_rd_name_canon(struct dns_msg *msg, char *buf, size_t bufsz)
{
rd_name(msg, buf, bufsz, 1);
}

/* Writes/appends binary data to the packet buffer */
void
dns_wr_data_raw(struct dns_msg *msg, const void *buf, size_t bufsz)
Expand Down
2 changes: 2 additions & 0 deletions dns.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ void dns_rd_header(struct dns_msg *msg, struct dns_header *header);
void dns_rd_skip(struct dns_msg *msg, uint16_t len);
/* Reads a domain name from the buffer and stores as a dot-delimited string */
void dns_rd_name(struct dns_msg *msg, char *buf, size_t bufsz);
/* Reads a canonical-only domain name from the buffer and stores */
void dns_rd_name_canon(struct dns_msg *msg, char *buf, size_t bufsz);
/* Reads binary data into the buffer */
void dns_rd_data_raw(struct dns_msg *msg, void *buf, uint16_t len);
/* Reads a uint16_t followed by binary data into a buffer */
Expand Down
5 changes: 2 additions & 3 deletions dnsdebug.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
/* (c) 2006, Quest Software Inc. All rights reserved */
/* David Leonard, 2006 */

#include <stdio.h>
#include <time.h>
#include <assert.h>
#include "common.h"
#include "dns.h"
#include "dnsdebug.h"

Expand Down Expand Up @@ -270,6 +268,7 @@ dumpmsg(struct dns_msg *msg)
dumpname(msg, "tsig.algorithm");
timehi = dns_rd_uint16(msg);
timelo = dns_rd_uint32(msg);
/* Note: on 32-bit time_t systems, higher order bits are lost */
t = timehi << 32 | timelo;
printf("\t%-20s: 0x%x:%08x (%.24s)\n", "tsig.time",
timehi, timelo, ctime(&t));
Expand Down
26 changes: 13 additions & 13 deletions dnstcp.c
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
/* (c) 2006, Quest Software Inc. All rights reserved. */
/* David Leonard, 2006 */

#include <err.h>
#include <stdio.h>
#include <assert.h>
#include <netdb.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/socket.h>
#include "common.h"

#include "err.h"
#include "dns.h"
#include "dnstcp.h"
Expand All @@ -23,7 +17,7 @@
static int tcp_connect(const char *host, const char *service);
extern int vflag;

#if !defined(HPUX)
#if HAVE_GETADDRINFO
/* Connects to a TCP service. Returns socket descriptor or -1 on failure. */
static int
tcp_connect(const char *host, const char *service)
Expand Down Expand Up @@ -62,9 +56,13 @@ tcp_connect(const char *host, const char *service)

return s;
}
#else

#include <netinet/in.h>
#else /* ! HAVE_GETADDRINFO */

# if HAVE_NETINET_IN_H
# include <netinet/in.h>
# endif

static int
tcp_connect(const char *host, const char *service)
{
Expand Down Expand Up @@ -97,7 +95,8 @@ tcp_connect(const char *host, const char *service)
sin.sin_port = servent->s_port; /* htons()?? */
memcpy(&sin.sin_addr, hostent->h_addr, sizeof sin.sin_addr);

printf("port = %u\n", servent->s_port);
if (vflag > 2)
fprintf(stderr, "connecting to port %u\n", servent->s_port);

if (connect(s, &sin, sizeof sin) < 0) {
warn("connect");
Expand All @@ -107,7 +106,8 @@ tcp_connect(const char *host, const char *service)

return s;
}
#endif

#endif /* ! HAVE_GETADDRINFO */

/*
* Connects to a DNS server using TCP.
Expand Down
3 changes: 2 additions & 1 deletion dnstkey.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* (c) 2006 Quest Software, Inc. All rights reserved. */
/* David Leonard, 2006 */
#include <stddef.h>

#include "common.h"
#include "dns.h"
#include "dnstkey.h"

Expand Down
14 changes: 5 additions & 9 deletions dnstsig.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
/* (c) 2006, Quest Software, Inc. All rights reserved. */
/* David Leonard, 2006 */
#include <stdio.h>
#include <stddef.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <assert.h>
#include <err.h>

#include "common.h"
#include "err.h"
#include "dns.h"
#include "dnstsig.h"

Expand Down Expand Up @@ -47,7 +43,7 @@ dns_tsig_wr(struct dns_msg *msg, const struct dns_tsig *tsig)
{
uint16_t mark;
dns_wr_begin(msg, &mark);
dns_wr_name(msg, tsig->algorithm);
dns_wr_name_canon(msg, tsig->algorithm);
dns_tsig_wr_time(msg, &tsig->time);
dns_wr_uint16(msg, tsig->fudge);
dns_wr_data(msg, tsig->mac, tsig->maclen);
Expand All @@ -62,7 +58,7 @@ void
dns_tsig_rd(struct dns_msg *msg, struct dns_tsig *tsig)
{
dns_rd_begin(msg);
dns_rd_name(msg, tsig->algorithm, sizeof tsig->algorithm);
dns_rd_name_canon(msg, tsig->algorithm, sizeof tsig->algorithm);
dns_tsig_rd_time(msg, &tsig->time);
tsig->fudge = dns_rd_uint16(msg);
tsig->maclen = dns_rd_datap(msg, &tsig->mac);
Expand Down
44 changes: 44 additions & 0 deletions dnsupdate.8
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
.\" (c) 2006, Quest Software, Inc. All rights reserved.
.TH DNSUPDATE 8
.SH NAME
dnsupdate \- authenticated DNS update for Active Directory hosts
.SH SYNOPSIS
.B dnsupdate
.RI [\-d\ domain ]
.RI [\-h\ hostname ]
.RI [\-s\ nameserver ]
.RI [\-t\ ttl ]
[\-v]
.I ip-addr
.SH DESCRIPTION
The
.B dnsupdate
tool updates the IP address of an Active Directory DNS entry.
It should be run when the primary interface's IP address is configured
(e.g. from a DHCP hook).
.SS OPTIONS
.TP
.RI \-d\ domain
the Active Directory domain (realm) in which to authenticate,
defaults to the currently joined domain
.TP
.RI \-h\ hostname
the fully qualified hostname entry to update,
defaults to the DNS hostname associated with the current AD computer object
.TP
.RI \-s\ nameserver
the nameserver to perform the dynamic DNS update operation on,
defaults to the nearest domain controller with automatic fallback
.TP
.RI \-t\ ttl
the cache lifetime in seconds to store with the new DNS entry,
defaults to one hour
.TP
\-v
increases the level of verbosity
.SS "EXIT STATUS"
The
.B dnsupdate
tool exits with status 0 only if the update operation failed.
.SH AUTHORS
David Leonard, Quest Software, Inc.
14 changes: 6 additions & 8 deletions dnsupdate.c
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#include <err.h>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
/* (c) 2006, Quest Software, Inc. All rights reserved. */

#include "common.h"

#include <vas.h>
#include <vas_gss.h>

#include "err.h"
#include "dns.h"
#include "dnsdebug.h"
#include "dnstcp.h"
Expand Down Expand Up @@ -465,9 +466,6 @@ main(int argc, char **argv)
int ch;
int opterror = 0;

/* XXX This is needed */
dns_never_compress = 1;

while ((ch = getopt(argc, argv, "d:h:s:t:v")) != -1)
switch (ch) {
case 'd':
Expand Down
Loading

0 comments on commit 2e76097

Please sign in to comment.