enum nss_status _nss_nisplus_setnetgrent (const char *group, struct __netgrent *netgrp) { char buf[strlen (group) + 25]; if (group == NULL || group[0] == '\0') return NSS_STATUS_UNAVAIL; enum nss_status status = NSS_STATUS_SUCCESS; snprintf (buf, sizeof (buf), "[name=%s],netgroup.org_dir", group); netgrp->data = (char *) nis_list (buf, EXPAND_NAME, NULL, NULL); if (netgrp->data == NULL) { __set_errno (ENOMEM); status = NSS_STATUS_TRYAGAIN; } else if (niserr2nss (((nis_result *) netgrp->data)->status) != NSS_STATUS_SUCCESS) { status = niserr2nss (((nis_result *) netgrp->data)->status); internal_endnetgrent (netgrp); } else { netgrp->data_size = ((nis_result *) netgrp->data)->objects.objects_len; netgrp->position = 0; netgrp->first = 1; } return status; }
enum nss_status _nss_nisplus_getgrnam_r (const char *name, struct group *gr, char *buffer, size_t buflen, int *errnop) { int parse_res; if (grp_tablename_val == NULL) { enum nss_status status = _nss_grp_create_tablename (errnop); if (status != NSS_STATUS_SUCCESS) return status; } if (name == NULL) { *errnop = EINVAL; return NSS_STATUS_NOTFOUND; } nis_result *result; char buf[strlen (name) + 9 + grp_tablename_len]; int olderr = errno; snprintf (buf, sizeof (buf), "[name=%s],%s", name, grp_tablename_val); result = nis_list (buf, FOLLOW_LINKS | FOLLOW_PATH, NULL, NULL); if (result == NULL) { *errnop = ENOMEM; return NSS_STATUS_TRYAGAIN; } if (__glibc_unlikely (niserr2nss (result->status) != NSS_STATUS_SUCCESS)) { enum nss_status status = niserr2nss (result->status); nis_freeresult (result); return status; } parse_res = _nss_nisplus_parse_grent (result, gr, buffer, buflen, errnop); nis_freeresult (result); if (__glibc_unlikely (parse_res < 1)) { if (parse_res == -1) { *errnop = ERANGE; return NSS_STATUS_TRYAGAIN; } else { __set_errno (olderr); return NSS_STATUS_NOTFOUND; } } return NSS_STATUS_SUCCESS; }
static enum nss_status internal_nisplus_getspent_r (struct spwd *sp, char *buffer, size_t buflen, int *errnop) { int parse_res; /* Get the next entry until we found a correct one. */ do { nis_result *saved_res; if (result == NULL) { saved_res = NULL; if (tablename_val == NULL) { enum nss_status status = _nss_create_tablename (errnop); if (status != NSS_STATUS_SUCCESS) return status; } result = nis_first_entry (tablename_val); if (niserr2nss (result->status) != NSS_STATUS_SUCCESS) return niserr2nss (result->status); } else { nis_result *res; saved_res = result; res = nis_next_entry (tablename_val, &result->cookie); result = res; if (niserr2nss (result->status) != NSS_STATUS_SUCCESS) { nis_freeresult (saved_res); return niserr2nss (result->status); } } parse_res = _nss_nisplus_parse_spent (result, sp, buffer, buflen, errnop); if (parse_res == -1) { nis_freeresult (result); result = saved_res; *errnop = ERANGE; return NSS_STATUS_TRYAGAIN; } else { if (saved_res) nis_freeresult (saved_res); } } while (!parse_res); return NSS_STATUS_SUCCESS; }
enum nss_status _nss_nisplus_getpwuid_r (const uid_t uid, struct passwd *pw, char *buffer, size_t buflen, int *errnop) { if (pwd_tablename_val == NULL) { enum nss_status status = _nss_pwd_create_tablename (errnop); if (status != NSS_STATUS_SUCCESS) return status; } int parse_res; nis_result *result; char buf[8 + 3 * sizeof (unsigned long int) + pwd_tablename_len]; int olderr = errno; snprintf (buf, sizeof (buf), "[uid=%lu],%s", (unsigned long int) uid, pwd_tablename_val); result = nis_list (buf, FOLLOW_PATH | FOLLOW_LINKS | USE_DGRAM, NULL, NULL); if (result == NULL) { *errnop = ENOMEM; return NSS_STATUS_TRYAGAIN; } if (niserr2nss (result->status) != NSS_STATUS_SUCCESS) { enum nss_status status = niserr2nss (result->status); errno = olderr; nis_freeresult (result); return status; } parse_res = _nss_nisplus_parse_pwent (result, pw, buffer, buflen, errnop); nis_freeresult (result); if (parse_res < 1) { if (parse_res == -1) { *errnop = ERANGE; return NSS_STATUS_TRYAGAIN; } else { errno = olderr; return NSS_STATUS_NOTFOUND; } } return NSS_STATUS_SUCCESS; }
enum nss_status _nss_nisplus_gethostton_r (const char *name, struct etherent *eth, char *buffer, size_t buflen, int *errnop) { if (tablename_val == NULL) { enum nss_status status = _nss_create_tablename (errnop); if (status != NSS_STATUS_SUCCESS) return status; } if (name == NULL) { *errnop = EINVAL; return NSS_STATUS_UNAVAIL; } char buf[strlen (name) + 9 + tablename_len]; int olderr = errno; snprintf (buf, sizeof (buf), "[name=%s],%s", name, tablename_val); nis_result *result = nis_list (buf, FOLLOW_PATH | FOLLOW_LINKS | USE_DGRAM, NULL, NULL); if (result == NULL) { *errnop = ENOMEM; return NSS_STATUS_TRYAGAIN; } if (__glibc_unlikely (niserr2nss (result->status) != NSS_STATUS_SUCCESS)) { enum nss_status status = niserr2nss (result->status); nis_freeresult (result); return status; } int parse_res = _nss_nisplus_parse_etherent (result, eth, buffer, buflen, errnop); /* We do not need the lookup result anymore. */ nis_freeresult (result); if (__glibc_unlikely (parse_res < 1)) { __set_errno (olderr); if (parse_res == -1) return NSS_STATUS_TRYAGAIN; return NSS_STATUS_NOTFOUND; } return NSS_STATUS_SUCCESS; }
enum nss_status _nss_nisplus_getgrgid_r (const gid_t gid, struct group *gr, char *buffer, size_t buflen, int *errnop) { if (grp_tablename_val == NULL) { enum nss_status status = _nss_grp_create_tablename (errnop); if (status != NSS_STATUS_SUCCESS) return status; } int parse_res; nis_result *result; char buf[8 + 3 * sizeof (unsigned long int) + grp_tablename_len]; int olderr = errno; snprintf (buf, sizeof (buf), "[gid=%lu],%s", (unsigned long int) gid, grp_tablename_val); result = nis_list (buf, FOLLOW_PATH | FOLLOW_LINKS, NULL, NULL); if (result == NULL) { *errnop = ENOMEM; return NSS_STATUS_TRYAGAIN; } if (__glibc_unlikely (niserr2nss (result->status) != NSS_STATUS_SUCCESS)) { enum nss_status status = niserr2nss (result->status); __set_errno (olderr); nis_freeresult (result); return status; } parse_res = _nss_nisplus_parse_grent (result, gr, buffer, buflen, errnop); nis_freeresult (result); if (__glibc_unlikely (parse_res < 1)) { __set_errno (olderr); if (parse_res == -1) { *errnop = ERANGE; return NSS_STATUS_TRYAGAIN; } else return NSS_STATUS_NOTFOUND; } return NSS_STATUS_SUCCESS; }
enum nss_status _nss_nisplus_getpwnam_r (const char *name, struct passwd *pw, char *buffer, size_t buflen, int *errnop) { int parse_res; if (tablename_val == NULL) { enum nss_status status = _nss_create_tablename (errnop); if (status != NSS_STATUS_SUCCESS) return status; } if (name == NULL) { *errnop = EINVAL; return NSS_STATUS_UNAVAIL; } else { nis_result *result; char buf[strlen (name) + 24 + tablename_len]; sprintf (buf, "[name=%s],%s", name, tablename_val); result = nis_list(buf, FOLLOW_PATH | FOLLOW_LINKS, NULL, NULL); if (niserr2nss (result->status) != NSS_STATUS_SUCCESS) { enum nss_status status = niserr2nss (result->status); nis_freeresult (result); return status; } parse_res = _nss_nisplus_parse_pwent (result, pw, buffer, buflen, errnop); nis_freeresult (result); if (parse_res < 1) { if (parse_res == -1) { *errnop = ERANGE; return NSS_STATUS_TRYAGAIN; } else return NSS_STATUS_NOTFOUND; } return NSS_STATUS_SUCCESS; } }
static enum nss_status internal_setgrent (int *errnop) { enum nss_status status = NSS_STATUS_SUCCESS; if (grp_tablename_val == NULL) status = _nss_grp_create_tablename (errnop); if (status == NSS_STATUS_SUCCESS) { ibreq = __create_ib_request (grp_tablename_val, 0); if (ibreq == NULL) { *errnop = errno; return NSS_STATUS_TRYAGAIN; } nis_error retcode = __prepare_niscall (grp_tablename_val, &dir, &bptr, 0); if (retcode != NIS_SUCCESS) { nis_free_request (ibreq); ibreq = NULL; status = niserr2nss (retcode); } } return status; }
static enum nss_status internal_nisplus_getgrent_r (struct group *gr, char *buffer, size_t buflen, int *errnop) { int parse_res = -1; enum nss_status retval = NSS_STATUS_SUCCESS; /* Get the next entry until we found a correct one. */ do { nis_error status; nis_result result; memset (&result, '\0', sizeof (result)); if (cursor.n_bytes == NULL) { if (ibreq == NULL) { retval = internal_setgrent (errnop); if (retval != NSS_STATUS_SUCCESS) return retval; } status = __do_niscall3 (&bptr, NIS_IBFIRST, (xdrproc_t) _xdr_ib_request, (caddr_t) ibreq, (xdrproc_t) _xdr_nis_result, (caddr_t) &result, 0, NULL); } else { ibreq->ibr_cookie.n_bytes = cursor.n_bytes; ibreq->ibr_cookie.n_len = cursor.n_len; status = __do_niscall3 (&bptr, NIS_IBNEXT, (xdrproc_t) _xdr_ib_request, (caddr_t) ibreq, (xdrproc_t) _xdr_nis_result, (caddr_t) &result, 0, NULL); ibreq->ibr_cookie.n_bytes = NULL; ibreq->ibr_cookie.n_len = 0; } if (status != NIS_SUCCESS) return niserr2nss (status); if (NIS_RES_STATUS (&result) == NIS_NOTFOUND) { /* No more entries on this server. This means we have to go to the next server on the path. */ status = __follow_path (&tablepath, &tableptr, ibreq, &bptr); if (status != NIS_SUCCESS) return niserr2nss (status); directory_obj *newdir = NULL; dir_binding newbptr; status = __prepare_niscall (ibreq->ibr_name, &newdir, &newbptr, 0); if (status != NIS_SUCCESS) return niserr2nss (status); nis_free_directory (dir); dir = newdir; __nisbind_destroy (&bptr); bptr = newbptr; xdr_free ((xdrproc_t) xdr_netobj, (char *) &result.cookie); result.cookie.n_bytes = NULL; result.cookie.n_len = 0; parse_res = 0; goto next; } else if (NIS_RES_STATUS (&result) != NIS_SUCCESS) return niserr2nss (NIS_RES_STATUS (&result)); parse_res = _nss_nisplus_parse_grent (&result, gr, buffer, buflen, errnop); if (__glibc_unlikely (parse_res == -1)) { *errnop = ERANGE; retval = NSS_STATUS_TRYAGAIN; goto freeres; } next: /* Free the old cursor. */ xdr_free ((xdrproc_t) xdr_netobj, (char *) &cursor); /* Remember the new one. */ cursor.n_bytes = result.cookie.n_bytes; cursor.n_len = result.cookie.n_len; /* Free the result structure. NB: we do not remove the cookie. */ result.cookie.n_bytes = NULL; result.cookie.n_len = 0; freeres: xdr_free ((xdrproc_t) _xdr_nis_result, (char *) &result); memset (&result, '\0', sizeof (result)); } while (!parse_res); return retval; }
enum nss_status _nss_nisplus_getntohost_r (const struct ether_addr *addr, struct etherent *eth, char *buffer, size_t buflen, int *errnop) { if (tablename_val == NULL) { __libc_lock_lock (lock); enum nss_status status = _nss_create_tablename (errnop); __libc_lock_unlock (lock); if (status != NSS_STATUS_SUCCESS) return status; } if (addr == NULL) { *errnop = EINVAL; return NSS_STATUS_UNAVAIL; } char buf[26 + tablename_len]; snprintf (buf, sizeof (buf), "[addr=%" PRIx8 ":%" PRIx8 ":%" PRIx8 ":%" PRIx8 ":%" PRIx8 ":%" PRIx8 "],%s", addr->ether_addr_octet[0], addr->ether_addr_octet[1], addr->ether_addr_octet[2], addr->ether_addr_octet[3], addr->ether_addr_octet[4], addr->ether_addr_octet[5], tablename_val); nis_result *result = nis_list (buf, FOLLOW_PATH | FOLLOW_LINKS | USE_DGRAM, NULL, NULL); if (result == NULL) { *errnop = ENOMEM; return NSS_STATUS_TRYAGAIN; } if (__glibc_unlikely (niserr2nss (result->status) != NSS_STATUS_SUCCESS)) { enum nss_status status = niserr2nss (result->status); nis_freeresult (result); return status; } int parse_res = _nss_nisplus_parse_etherent (result, eth, buffer, buflen, errnop); /* We do not need the lookup result anymore. */ nis_freeresult (result); if (__glibc_unlikely (parse_res < 1)) { if (parse_res == -1) return NSS_STATUS_TRYAGAIN; return NSS_STATUS_NOTFOUND; } return NSS_STATUS_SUCCESS; }
enum nss_status _nss_nisplus_getspnam_r (const char *name, struct spwd *sp, char *buffer, size_t buflen, int *errnop) { int parse_res; if (pwd_tablename_val == NULL) { enum nss_status status = _nss_pwd_create_tablename (errnop); if (status != NSS_STATUS_SUCCESS) return status; } if (name == NULL) { *errnop = EINVAL; return NSS_STATUS_NOTFOUND; } nis_result *result; char buf[strlen (name) + 9 + pwd_tablename_len]; int olderr = errno; snprintf (buf, sizeof (buf), "[name=%s],%s", name, pwd_tablename_val); result = nis_list (buf, FOLLOW_PATH | FOLLOW_LINKS, NULL, NULL); if (result == NULL) { *errnop = ENOMEM; return NSS_STATUS_TRYAGAIN; } if (__builtin_expect (niserr2nss (result->status) != NSS_STATUS_SUCCESS, 0)) { enum nss_status status = niserr2nss (result->status); __set_errno (olderr); nis_freeresult (result); return status; } parse_res = _nss_nisplus_parse_spent (result, sp, buffer, buflen, errnop); nis_freeresult (result); if (__builtin_expect (parse_res < 1, 0)) { if (parse_res == -1) { *errnop = ERANGE; return NSS_STATUS_TRYAGAIN; } else { __set_errno (olderr); return NSS_STATUS_NOTFOUND; } } return NSS_STATUS_SUCCESS; }
enum nss_status _nss_nisplus_initgroups_dyn (const char *user, gid_t group, long int *start, long int *size, gid_t **groupsp, long int limit, int *errnop) { if (grp_tablename_val == NULL) { enum nss_status status = _nss_grp_create_tablename (errnop); if (status != NSS_STATUS_SUCCESS) return status; } nis_result *result; char buf[strlen (user) + 12 + grp_tablename_len]; snprintf (buf, sizeof (buf), "[members=%s],%s", user, grp_tablename_val); result = nis_list (buf, FOLLOW_LINKS | FOLLOW_PATH | ALL_RESULTS, NULL, NULL); if (result == NULL) { *errnop = ENOMEM; return NSS_STATUS_TRYAGAIN; } if (__builtin_expect (niserr2nss (result->status) != NSS_STATUS_SUCCESS, 0)) { enum nss_status status = niserr2nss (result->status); nis_freeresult (result); return status; } if (NIS_RES_NUMOBJ (result) == 0) { errout: nis_freeresult (result); return NSS_STATUS_NOTFOUND; } gid_t *groups = *groupsp; nis_object *obj = NIS_RES_OBJECT (result); for (unsigned int cnt = 0; cnt < NIS_RES_NUMOBJ (result); ++cnt, ++obj) { if (__type_of (obj) != NIS_ENTRY_OBJ || strcmp (obj->EN_data.en_type, "group_tbl") != 0 || obj->EN_data.en_cols.en_cols_len < 4) continue; char *numstr = NISOBJVAL (2, obj); size_t len = NISOBJLEN (2, obj); if (len == 0 || numstr[0] == '\0') continue; gid_t gid; char *endp; if (__builtin_expect (numstr[len - 1] != '\0', 0)) { char numstrbuf[len + 1]; memcpy (numstrbuf, numstr, len); numstrbuf[len] = '\0'; gid = strtoul (numstrbuf, &endp, 10); if (*endp) continue; } else { gid = strtoul (numstr, &endp, 10); if (*endp) continue; } if (gid == group) continue; /* Insert this group. */ if (*start == *size) { /* Need a bigger buffer. */ long int newsize; if (limit > 0 && *size == limit) /* We reached the maximum. */ break; if (limit <= 0) newsize = 2 * *size; else newsize = MIN (limit, 2 * *size); gid_t *newgroups = realloc (groups, newsize * sizeof (*groups)); if (newgroups == NULL) goto errout; *groupsp = groups = newgroups; *size = newsize; } groups[*start] = gid; *start += 1; } nis_freeresult (result); return NSS_STATUS_SUCCESS; }