Last active
April 10, 2026 18:36
-
-
Save walkure/33e7eecf547d25eda56e1931e5a0a9ef to your computer and use it in GitHub Desktop.
pfclientのログを黙らせ、NTP問い合わせをNICTに変更
This file contains hidden or 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
| /* | |
| $ gcc -Wall -fPIC -shared -o pfnull.so pfnull.c -ldl | |
| export LD_PRELOAD=/usr/local/lib/pfnull.so | |
| */ | |
| #define _GNU_SOURCE | |
| #include <stdio.h> | |
| #include <dlfcn.h> | |
| #include <stdarg.h> | |
| #include <string.h> | |
| #include <errno.h> | |
| #include <netdb.h> | |
| #include <arpa/inet.h> | |
| FILE *fopen(const char *pathname, const char *mode) { | |
| static FILE *(*original_fopen)(const char *, const char *) = NULL; | |
| if (!original_fopen) { | |
| original_fopen = dlsym(RTLD_NEXT, "fopen"); | |
| } | |
| if (pathname != NULL && strstr(pathname, "pfclient-log") != NULL) { | |
| //fprintf(stderr, "[FAKE ERROR] Simulating Disk Full (ENOSPC) for: %s\n", pathname); | |
| errno = ENOSPC; | |
| return NULL; | |
| } | |
| return original_fopen(pathname, mode); | |
| } | |
| int getaddrinfo(const char *node, const char *service, | |
| const struct addrinfo *hints, | |
| struct addrinfo **res) { | |
| static int (*original_getaddrinfo)(const char *, const char *, | |
| const struct addrinfo *, | |
| struct addrinfo **) = NULL; | |
| if (!original_getaddrinfo) { | |
| original_getaddrinfo = dlsym(RTLD_NEXT, "getaddrinfo"); | |
| } | |
| const char *final_node = node; | |
| if (node != NULL && strstr(node, ".planefinder.pool.ntp.org") != NULL) { | |
| if (service != NULL && strcmp(service, "123") == 0) { | |
| final_node = "ntp.nict.jp"; | |
| } | |
| } | |
| return original_getaddrinfo(final_node, service, hints, res); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment