This function is a different beast compared to previous ones.
But yet again, nothing surprising is happening here.
Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
---
tools/nss/libvirt_nss.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++
tools/nss/libvirt_nss.h | 4 +++
tools/nss/libvirt_nss.syms | 1 +
3 files changed, 89 insertions(+)
diff --git a/tools/nss/libvirt_nss.c b/tools/nss/libvirt_nss.c
index f044074..a8514f4 100644
--- a/tools/nss/libvirt_nss.c
+++ b/tools/nss/libvirt_nss.c
@@ -350,3 +350,87 @@ _nss_libvirt_gethostbyname3_r(const char *name, int af, struct
hostent *result,
cleanup:
return ret;
}
+
+enum nss_status
+_nss_libvirt_gethostbyname4_r(const char *name, struct gaih_addrtuple **pat,
+ char *buffer, size_t buflen, int *errnop,
+ int *herrnop, int32_t *ttlp)
+{
+ enum nss_status ret = NSS_STATUS_UNAVAIL;
+ unsigned char addr[16];
+ int alen;
+ const int af = AF_INET;
+ int r;
+ size_t nameLen, need, idx;
+ struct gaih_addrtuple *r_tuple_first = NULL;
+ char *r_name;
+
+ if ((r = findLease(name, af, addr, &alen, errnop)) < 0) {
+ /* Error occurred. Return immediately. */
+ if (*errnop == EAGAIN) {
+ *herrnop = TRY_AGAIN;
+ return NSS_STATUS_TRYAGAIN;
+ } else {
+ *herrnop = NO_RECOVERY;
+ return NSS_STATUS_UNAVAIL;
+ }
+ } else if (r == 0) {
+ /* NOT found */
+ *errnop = ESRCH;
+ *herrnop = HOST_NOT_FOUND;
+ return NSS_STATUS_NOTFOUND;
+ } else if (r == 1) {
+ /* Found, but no data */
+ *errnop = ENXIO;
+ *herrnop = NO_DATA;
+ return NSS_STATUS_UNAVAIL;
+ }
+
+ /* Found and have data */
+
+ nameLen = strlen(name);
+ /* We need space for:
+ * a) name
+ * b) address */
+ need = ALIGN(nameLen + 1) + ALIGN(sizeof(struct gaih_addrtuple));
+
+ if (buflen < need) {
+ *errnop = ENOMEM;
+ *herrnop = TRY_AGAIN;
+ ret = NSS_STATUS_TRYAGAIN;
+ goto cleanup;
+ }
+
+ /* First, append name */
+ r_name = buffer;
+ memcpy(r_name, name, nameLen + 1);
+ idx = ALIGN(nameLen + 1);
+
+
+ /* Second, append addresses */
+ r_tuple_first = (struct gaih_addrtuple*) (buffer + idx);
+ r_tuple_first->next = NULL;
+ r_tuple_first->name = r_name;
+ r_tuple_first->family = af;
+ r_tuple_first->scopeid = 0;
+ memcpy(r_tuple_first->addr, addr, alen);
+ idx += ALIGN(sizeof(struct gaih_addrtuple));
+
+ /* At this point, idx == need */
+ DEBUG("Done idx:%zd need:%zd", idx, need);
+
+ if (*pat)
+ **pat = *r_tuple_first;
+ else
+ *pat = r_tuple_first;
+
+ if (ttlp)
+ *ttlp = 0;
+
+ /* Explicitly reset all error variables */
+ *errnop = 0;
+ *herrnop = NETDB_SUCCESS;
+ ret = NSS_STATUS_SUCCESS;
+ cleanup:
+ return ret;
+}
diff --git a/tools/nss/libvirt_nss.h b/tools/nss/libvirt_nss.h
index dd037f5..589c1e6 100644
--- a/tools/nss/libvirt_nss.h
+++ b/tools/nss/libvirt_nss.h
@@ -45,4 +45,8 @@ enum nss_status
_nss_libvirt_gethostbyname3_r(const char *name, int af, struct hostent *result,
char *buffer, size_t buflen, int *errnop,
int *herrnop, int32_t *ttlp, char **canonp);
+enum nss_status
+_nss_libvirt_gethostbyname4_r(const char *name, struct gaih_addrtuple **pat,
+ char *buffer, size_t buflen, int *errnop,
+ int *herrnop, int32_t *ttlp);
#endif /* __LIBVIRT_NSS_H__ */
diff --git a/tools/nss/libvirt_nss.syms b/tools/nss/libvirt_nss.syms
index b88b8be..5a793e4 100644
--- a/tools/nss/libvirt_nss.syms
+++ b/tools/nss/libvirt_nss.syms
@@ -7,5 +7,6 @@ global:
_nss_libvirt_gethostbyname_r;
_nss_libvirt_gethostbyname2_r;
_nss_libvirt_gethostbyname3_r;
+ _nss_libvirt_gethostbyname4_r;
local: *;
};
--
2.4.10