You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
118 lines
2.1 KiB
118 lines
2.1 KiB
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include <errno.h>
|
|
#include <string.h>
|
|
#include <unistd.h>
|
|
|
|
#include <arpa/inet.h>
|
|
#include <netdb.h>
|
|
extern int h_errno;
|
|
|
|
#include <nss.h>
|
|
|
|
#define ALIGN(idx) { \
|
|
if (idx % sizeof(void*)) \
|
|
idx += (sizeof(void*) - idx % sizeof(void*)); /* Align on 32 bit boundary */ \
|
|
}
|
|
|
|
|
|
enum nss_status _nss_vdn_gethostbyname2_r(
|
|
const char *name,
|
|
int af,
|
|
struct hostent * result,
|
|
char *buffer,
|
|
size_t buflen,
|
|
int *errnop,
|
|
int *h_errnop)
|
|
{
|
|
//fprintf(stderr, "vdn_gethostbyname2_r : %s\n", name);
|
|
|
|
FILE *fp;
|
|
char line[80];
|
|
int s;
|
|
|
|
size_t idx=0;
|
|
|
|
if(af != AF_INET) {
|
|
*errnop = EAFNOSUPPORT;
|
|
*h_errnop = HOST_NOT_FOUND;
|
|
return NSS_STATUS_UNAVAIL;
|
|
}
|
|
|
|
char cmd[200]="/etc/vdn/allocators/resolv";
|
|
|
|
if (access(cmd, F_OK) != 0)
|
|
strcpy(cmd, "/home/davalan/vdn-bullseye/allocators/resolv");
|
|
|
|
if (access(cmd, F_OK) != 0) {
|
|
perror("access");
|
|
*errnop = EAFNOSUPPORT;
|
|
*h_errnop = HOST_NOT_FOUND;
|
|
return NSS_STATUS_UNAVAIL;
|
|
}
|
|
|
|
strcat(cmd, " ");
|
|
strcat(cmd, name);
|
|
if((fp = popen(cmd , "r")) == NULL) {
|
|
perror("open");
|
|
exit(1);
|
|
}
|
|
|
|
if(fgets(line, sizeof line, fp) == NULL) {
|
|
*errnop = EAFNOSUPPORT;
|
|
*h_errnop = HOST_NOT_FOUND;
|
|
return NSS_STATUS_UNAVAIL;
|
|
}
|
|
|
|
line[strlen(line)-1]=0;
|
|
|
|
//fprintf(stderr,"line:%s\n", line);
|
|
|
|
pclose(fp);
|
|
|
|
//char *bufStart=buffer;
|
|
|
|
strcpy(buffer+idx, name);
|
|
result->h_name=buffer;
|
|
|
|
idx+=strlen(name)+1;
|
|
ALIGN(idx);
|
|
|
|
result->h_addrtype=AF_INET;
|
|
result->h_length=4;
|
|
|
|
//fprintf(stderr, "name ok\n");
|
|
|
|
s = inet_pton(AF_INET, line, buffer+idx);
|
|
if (s <= 0) {
|
|
if (s == 0) {
|
|
*errnop = EAFNOSUPPORT;
|
|
*h_errnop = HOST_NOT_FOUND;
|
|
return NSS_STATUS_UNAVAIL;
|
|
}
|
|
else {
|
|
perror("inet_pton");
|
|
exit(1);
|
|
}
|
|
}
|
|
|
|
result->h_addr_list=(char **)buffer+idx;
|
|
|
|
result->h_addr_list[0]=buffer+idx;
|
|
result->h_addr_list[1]=NULL;
|
|
|
|
idx+=2*sizeof(char *);
|
|
|
|
result->h_aliases=(char **)buffer+idx;
|
|
|
|
result->h_aliases[0]=NULL;
|
|
|
|
*errnop = 0;
|
|
*h_errnop = 0;
|
|
|
|
return NSS_STATUS_SUCCESS;
|
|
}
|
|
|
|
|
|
|