Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

NSD OpenDNSSEC Notifier

View .gitignore
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
.PHONY: all clean
 
CHGRP := /bin/chgrp
CHMOD := /bin/chmod
CFLAGS := -Wall -Wextra -Werror
 
all: nsd-notify
 
clean:
$(RM) nsd-notify
 
nsd-notify: nsd-notify.c
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $<
$(CHGRP) opendnssec $@
$(CHMOD) o=,g=x,u=rwxs $@
View .gitignore
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
/*
* This program is useful for opendnssec's NotifyCommand when using nsd.
* It should be setuid root.
*
* Authored by Russell Harmon <russ@eatnumber1.com>
*/
 
#define _XOPEN_SOURCE
#define _XOPEN_SOURCE_EXTENDED
 
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>
 
static void spawn( char * const argv[] ) {
pid_t pid = fork();
if( pid == -1 ) {
perror("fork");
exit(EXIT_FAILURE);
} else if( pid == 0 ) {
// Child
execv(argv[0], argv);
perror("execvp");
exit(EXIT_FAILURE);
} else {
// Parent
siginfo_t siginfo;
if( waitid(P_PID, pid, &siginfo, WEXITED) == -1 ) {
perror("waitid");
exit(EXIT_FAILURE);
}
if( siginfo.si_code != CLD_EXITED || siginfo.si_status != EXIT_SUCCESS ) {
fprintf(stderr, "Abnormal child exit\n");
exit(EXIT_FAILURE);
}
}
}
 
int main() {
if( setuid(0) == -1 ) {
perror("setuid");
exit(EXIT_FAILURE);
}
char *args[3] = { [2] = NULL };
char **command = &args[1], **binary = &args[0];
*binary = "/usr/sbin/nsdc";
 
*command = "rebuild";
spawn(args);
*command = "reload";
spawn(args);
*command = "notify";
spawn(args);
return EXIT_SUCCESS;
}

Thanks, it works for me and is very helpful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.