static int _nss_nisplus_parse_etherent (nis_result *result, struct etherent *ether, char *buffer, size_t buflen, int *errnop) { char *p = buffer; size_t room_left = buflen; if (result == NULL) return 0; if ((result->status != NIS_SUCCESS && result->status != NIS_S_SUCCESS) || NIS_RES_NUMOBJ (result) != 1 || __type_of (NIS_RES_OBJECT (result)) != NIS_ENTRY_OBJ || strcmp (NIS_RES_OBJECT (result)->EN_data.en_type, "ethers_tbl") != 0 || NIS_RES_OBJECT (result)->EN_data.en_cols.en_cols_len < 2) return 0; /* Generate the ether entry format and use the normal parser */ if (NISENTRYLEN (0, 0, result) + 1 > room_left) { *errnop = ERANGE; return -1; } char *cp = __stpncpy (p, NISENTRYVAL (0, 0, result), NISENTRYLEN (0, 0, result)); *cp = '\0'; room_left -= NISENTRYLEN (0, 0, result) + 1; ether->e_name = p; struct ether_addr *ea = ether_aton (NISENTRYVAL (0, 1, result)); if (ea == NULL) { *errnop = EINVAL; return -2; } ether->e_addr = *ea; return 1; }
enum nss_status _nss_nisplus_getnetgrent_r (struct __netgrent *result, char *buffer, size_t buflen, int *errnop) { enum nss_status status; /* Some sanity checks. */ if (result->data == NULL || result->data_size == 0) return NSS_STATUS_NOTFOUND; if (result->position == result->data_size) return result->first ? NSS_STATUS_NOTFOUND : NSS_STATUS_RETURN; unsigned int entrylen = NISENTRYLEN (result->position, 1, (nis_result *) result->data); if (entrylen > 0) { /* We have a list of other netgroups. */ result->type = group_val; if (entrylen >= buflen) { *errnop = ERANGE; return NSS_STATUS_TRYAGAIN; } strncpy (buffer, NISENTRYVAL (result->position, 1, (nis_result *) result->data), entrylen); buffer[entrylen] = '\0'; result->val.group = buffer; ++result->position; result->first = 0; return NSS_STATUS_SUCCESS; } /* Before we can copy the entry to the private buffer we have to make sure it is big enough. */ unsigned int hostlen = NISENTRYLEN (result->position, 2, (nis_result *) result->data); unsigned int userlen = NISENTRYLEN (result->position, 3, (nis_result *) result->data); unsigned int domainlen = NISENTRYLEN (result->position, 4, (nis_result *) result->data); if (hostlen + userlen + domainlen + 6 > buflen) { *errnop = ERANGE; status = NSS_STATUS_TRYAGAIN; } else { char *cp = buffer; result->type = triple_val; if (hostlen == 0 || NISENTRYVAL (result->position, 2, (nis_result *) result->data)[0] == '\0') result->val.triple.host = NULL; else { result->val.triple.host = cp; cp = __stpncpy (cp, NISENTRYVAL (result->position, 2, (nis_result *) result->data), hostlen); *cp++ = '\0'; } if (userlen == 0 || NISENTRYVAL (result->position, 3, (nis_result *) result->data)[0] == '\0') result->val.triple.user = NULL; else { result->val.triple.user = cp; cp = __stpncpy (cp, NISENTRYVAL (result->position, 3, (nis_result *) result->data), userlen); *cp++ = '\0'; } if (domainlen == 0 || NISENTRYVAL (result->position, 4, (nis_result *) result->data)[0] == '\0') result->val.triple.domain = NULL; else { result->val.triple.domain = cp; cp = __stpncpy (cp, NISENTRYVAL (result->position, 4, (nis_result *) result->data), domainlen); *cp = '\0'; } status = NSS_STATUS_SUCCESS; /* Remember where we stopped reading. */ ++result->position; result->first = 0; } return status; }