mirror of https://gitee.com/openkylin/libvirt.git
nss: remove last usages of libvirt headers
Use the plain libc APIs to avoid a dependancy on the main libvirt code from the nss module. Reviewed-by: Michal Privoznik <mprivozn@redhat.com> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
parent
bb7c531911
commit
8ee34c4ca8
|
@ -31,13 +31,15 @@
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
|
||||||
#if defined(HAVE_BSD_NSS)
|
#if defined(HAVE_BSD_NSS)
|
||||||
# include <nsswitch.h>
|
# include <nsswitch.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "viralloc.h"
|
|
||||||
#include "virtime.h"
|
|
||||||
#include "configmake.h"
|
#include "configmake.h"
|
||||||
|
|
||||||
#include "libvirt_nss_leases.h"
|
#include "libvirt_nss_leases.h"
|
||||||
|
@ -146,10 +148,10 @@ findLease(const char *name,
|
||||||
|
|
||||||
DEBUG("Processing %s", path);
|
DEBUG("Processing %s", path);
|
||||||
if (findMACs(path, name, &macs, &nmacs) < 0) {
|
if (findMACs(path, name, &macs, &nmacs) < 0) {
|
||||||
VIR_FREE(path);
|
free(path);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
VIR_FREE(path);
|
free(path);
|
||||||
#endif /* LIBVIRT_NSS_GUEST */
|
#endif /* LIBVIRT_NSS_GUEST */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -243,7 +245,7 @@ NSS_NAME(gethostbyname3)(const char *name, int af, struct hostent *result,
|
||||||
{
|
{
|
||||||
enum nss_status ret = NSS_STATUS_UNAVAIL;
|
enum nss_status ret = NSS_STATUS_UNAVAIL;
|
||||||
char *r_name, **r_aliases, *r_addr, *r_addr_next, **r_addr_list;
|
char *r_name, **r_aliases, *r_addr, *r_addr_next, **r_addr_list;
|
||||||
VIR_AUTOFREE(leaseAddress *) addr = NULL;
|
leaseAddress *addr = NULL;
|
||||||
size_t naddr, i;
|
size_t naddr, i;
|
||||||
bool found = false;
|
bool found = false;
|
||||||
size_t nameLen, need, idx = 0;
|
size_t nameLen, need, idx = 0;
|
||||||
|
@ -259,6 +261,7 @@ NSS_NAME(gethostbyname3)(const char *name, int af, struct hostent *result,
|
||||||
af = AF_INET;
|
af = AF_INET;
|
||||||
|
|
||||||
if ((r = findLease(name, af, &addr, &naddr, &found, errnop)) < 0) {
|
if ((r = findLease(name, af, &addr, &naddr, &found, errnop)) < 0) {
|
||||||
|
free(addr);
|
||||||
/* Error occurred. Return immediately. */
|
/* Error occurred. Return immediately. */
|
||||||
if (*errnop == EAGAIN) {
|
if (*errnop == EAGAIN) {
|
||||||
*herrnop = TRY_AGAIN;
|
*herrnop = TRY_AGAIN;
|
||||||
|
@ -273,11 +276,13 @@ NSS_NAME(gethostbyname3)(const char *name, int af, struct hostent *result,
|
||||||
/* NOT found */
|
/* NOT found */
|
||||||
*errnop = ESRCH;
|
*errnop = ESRCH;
|
||||||
*herrnop = HOST_NOT_FOUND;
|
*herrnop = HOST_NOT_FOUND;
|
||||||
|
free(addr);
|
||||||
return NSS_STATUS_NOTFOUND;
|
return NSS_STATUS_NOTFOUND;
|
||||||
} else if (!naddr) {
|
} else if (!naddr) {
|
||||||
/* Found, but no data */
|
/* Found, but no data */
|
||||||
*errnop = ENXIO;
|
*errnop = ENXIO;
|
||||||
*herrnop = NO_DATA;
|
*herrnop = NO_DATA;
|
||||||
|
free(addr);
|
||||||
return NSS_STATUS_UNAVAIL;
|
return NSS_STATUS_UNAVAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -349,6 +354,7 @@ NSS_NAME(gethostbyname3)(const char *name, int af, struct hostent *result,
|
||||||
|
|
||||||
ret = NSS_STATUS_SUCCESS;
|
ret = NSS_STATUS_SUCCESS;
|
||||||
cleanup:
|
cleanup:
|
||||||
|
free(addr);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,13 +30,14 @@
|
||||||
|
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
# include "virerror.h"
|
# include <errno.h>
|
||||||
# define ERROR(...) \
|
# define ERROR(...) \
|
||||||
do { \
|
do { \
|
||||||
char ebuf[1024]; \
|
char ebuf[1024]; \
|
||||||
|
strerror_r(errno, ebuf, sizeof(ebuf)); \
|
||||||
fprintf(stderr, "ERROR %s:%d : ", __FUNCTION__, __LINE__); \
|
fprintf(stderr, "ERROR %s:%d : ", __FUNCTION__, __LINE__); \
|
||||||
fprintf(stderr, __VA_ARGS__); \
|
fprintf(stderr, __VA_ARGS__); \
|
||||||
fprintf(stderr, " : %s\n", virStrerror(errno, ebuf, sizeof(ebuf))); \
|
fprintf(stderr, " : %s\n", ebuf); \
|
||||||
fprintf(stderr, "\n"); \
|
fprintf(stderr, "\n"); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,6 @@
|
||||||
|
|
||||||
#include "libvirt_nss_leases.h"
|
#include "libvirt_nss_leases.h"
|
||||||
#include "libvirt_nss.h"
|
#include "libvirt_nss.h"
|
||||||
#include "viralloc.h"
|
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
FIND_LEASES_STATE_START,
|
FIND_LEASES_STATE_START,
|
||||||
|
@ -79,6 +78,7 @@ appendAddr(const char *name ATTRIBUTE_UNUSED,
|
||||||
} sa;
|
} sa;
|
||||||
unsigned char addr[16];
|
unsigned char addr[16];
|
||||||
int err;
|
int err;
|
||||||
|
leaseAddress *newAddr;
|
||||||
|
|
||||||
DEBUG("IP address: %s", ipAddr);
|
DEBUG("IP address: %s", ipAddr);
|
||||||
|
|
||||||
|
@ -131,10 +131,12 @@ appendAddr(const char *name ATTRIBUTE_UNUSED,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (VIR_REALLOC_N_QUIET(*tmpAddress, *ntmpAddress + 1) < 0) {
|
newAddr = realloc(*tmpAddress, sizeof(*newAddr) * (*ntmpAddress + 1));
|
||||||
|
if (!newAddr) {
|
||||||
ERROR("Out of memory");
|
ERROR("Out of memory");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
*tmpAddress = newAddr;
|
||||||
|
|
||||||
(*tmpAddress)[*ntmpAddress].expirytime = expirytime;
|
(*tmpAddress)[*ntmpAddress].expirytime = expirytime;
|
||||||
(*tmpAddress)[*ntmpAddress].af = family;
|
(*tmpAddress)[*ntmpAddress].af = family;
|
||||||
|
|
Loading…
Reference in New Issue