Created
July 9, 2011 05:32
-
-
Save eatnumber1/1073357 to your computer and use it in GitHub Desktop.
NSD OpenDNSSEC Notifier
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
nsd-notify |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.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 $@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* This program is useful for opendnssec's NotifyCommand when using nsd. | |
* It should be setuid root. | |
* | |
* Authored by Russell Harmon <[email protected]> | |
*/ | |
#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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks, it works for me and is very helpful.