diff options
author | Ulrich Drepper <drepper@redhat.com> | 1997-12-08 03:06:47 +0000 |
---|---|---|
committer | Ulrich Drepper <drepper@redhat.com> | 1997-12-08 03:06:47 +0000 |
commit | d71b808a96f0fd1b6cd82c41698b518bf345692b (patch) | |
tree | 7b86cfd6b465c72888d7e85a61c08cafabf5747b /nis/nss_nisplus | |
parent | 6195235142bd246d972cf1d88b4e208071a3e318 (diff) | |
download | glibc-d71b808a96f0fd1b6cd82c41698b518bf345692b.tar.gz glibc-d71b808a96f0fd1b6cd82c41698b518bf345692b.tar.xz glibc-d71b808a96f0fd1b6cd82c41698b518bf345692b.zip |
Update. cvs/libc-ud-971207
1997-12-08 03:24 Ulrich Drepper <drepper@cygnus.com> * Makeconfig: Define $(rt) to rt if linuxthreads is available. * Makefile (subdirs): Replace rt by $(rt). * shlib-versions: Use version .2 for NSS modules. * grp/fgetgrent_r.c (LINE_PARSER): Call parse_line with extra argument. * pwd/fgetpwent_r.c: Likewise. * spwd/fgetspent_r.c: Likewise. * spwd/sgetspent_r.c: Likewise. * hesiod/nss_hesiod/hesiod-grp.c (lookup): Add new argument. Store error number in *ERRNOP. Little optimization. * hesiod/nss_hesiod/hesiod-pwd.c: Likewise. * hesiod/nss_hesiod/hesiod-service.c: Likewise. * inet/getnetgrent_r.c (__internal_setnetgrent_reuse): Likewise. (__internal_getnetgrent_r): New argument. Call __internal_setnetgrent_reuse with new argument. (__getnetgrent_r): Call __internal_getnetgrent_r with new argument. * inet/netgroup.h: Add argument to prototypes. * nis/nisplus-parser.h: Likewise. * nis/nss_compat/compat-grp.c: Change everything to store error code through provided pointer and not use errno. * nis/nss_compat/compat-pwd.c: Likewise. * nis/nss_compat/compat-spwd.c: Likewise. * nis/nss_nis/nis-alias.c: Likewise. * nis/nss_nis/nis-ethers.c: Likewise. * nis/nss_nis/nis-grp.c: Likewise. * nis/nss_nis/nis-hosts.c: Likewise. * nis/nss_nis/nis-netgrp.c: Likewise. * nis/nss_nis/nis-network.c: Likewise. * nis/nss_nis/nis-proto.c: Likewise. * nis/nss_nis/nis-publickey.c: Likewise. * nis/nss_nis/nis-pwd.c: Likewise. * nis/nss_nis/nis-rpc.c: Likewise. * nis/nss_nis/nis-service.c: Likewise. * nis/nss_nis/nis-spwd.c: Likewise. * nis/nss_nisplus/nisplus-alias.c: Likewise. * nis/nss_nisplus/nisplus-ethers.c: Likewise. * nis/nss_nisplus/nisplus-grp.c: Likewise. * nis/nss_nisplus/nisplus-hosts.c: Likewise. * nis/nss_nisplus/nisplus-netgrp.c: Likewise. * nis/nss_nisplus/nisplus-network.c: Likewise. * nis/nss_nisplus/nisplus-parser.c: Likewise. * nis/nss_nisplus/nisplus-proto.c: Likewise. * nis/nss_nisplus/nisplus-publickey.c: Likewise. * nis/nss_nisplus/nisplus-pwd.c: Likewise. * nis/nss_nisplus/nisplus-rpc.c: Likewise. * nis/nss_nisplus/nisplus-service.c: Likewise. * nis/nss_nisplus/nisplus-spwd.c: Likewise. * nss/nss_db/db-XXX.c: Likewise. * nss/nss_db/db-alias.c: Likewise. * nss/nss_db/db-netgrp.c: Likewise. * nss/nss_files/files-XXX.c: Likewise * nss/nss_files/files-alias.c: Likewise * nss/nss_files/files-netgrp.c: Likewise * nss/nss_files/files-parse.c: Likewise * nss/getXXbyYY_r.c: Call with __errno_location() as value for new parameter of get functions. * nss/getXXent_r.c: Likewise. * localedata/tst-fmon.c: Print debug info if test fails. * rt/Makefile (routines): Add aio_notify. * rt/aio.h: Remove non-public definitions. Add aioinit stuff. * rt/aio_cancel.c: Rewrite to support lio_listio and aio_suspend. * rt/aio_fsync.c: Likewise. * rt/aio_misc.c: Likewise. * rt/aio_misc.h: Likewise. * rt/aio_read.c: Likewise. * rt/aio_read64.c: Likewise. * rt/aio_suspend.c: Likewise. * rt/aio_write.c: Likewise. * rt/aio_write64.c: Likewise. * rt/lio_listio.c: Likewise. * rt/lio_listio64.c: Likewise. * rt/aio_notify.c: New file. * sysdeps/generic/bits/sigset.h: Pretty print. * sysdeps/posix/pwrite.c: Define weak alias only if function is really defined as __pwrite. * sysdeps/unix/sysv/linux/pread.c: Rewrite to use syscall directly instead of pread64. * sysdeps/unix/sysv/linux/pwrite.c: Likewise. * sysdeps/unix/sysv/linux/Makefile [$(subdir)=signal] (sysdep_routines): Add rt_sigpending and rt_sigreturn. * sysdeps/unix/sysv/linux/sigaction.c: Use correct value for sigset_t size in syscall. * sysdeps/unix/sysv/linux/sigpending.c: Likewise. * sysdeps/unix/sysv/linux/sigprocmask.c: Likewise. * sysdeps/unix/sysv/linux/sigreturn.c: Likewise. * sysdeps/unix/sysv/linux/sigsuspend.c: Likewise. * sysdeps/unix/sysv/linux/sigtimedwait.c: Likewise. * sysdeps/unix/sysv/linux/sigwaitinfo.c: Likewise. * sysdeps/unix/sysv/linux/i386/sigaction.c: Likewise. Take care for ACT being NULL. * sysdeps/unix/sysv/linux/syscalls.list: Don't mention user for RT signals. * sysdeps/unix/sysv/linux/i386/s_pread64.s: Return ENOSYS if __NR_pread is not defined. * sysdeps/unix/sysv/linux/i386/s_pwrite64.s: Return ENOSYS if __NR_pwrite is not defined. 1997-12-07 11:15 Thorsten Kukuk <kukuk@vt.uni-paderborn.de> * nis/nss_compat/compat-grp.c: If buffer is to small, set the file handle for /etc/group back in some more cases. * nis/nss_compat/compat-pwd.c: If buffer is to small, set the file handle for /etc/passwd back in some more cases. * nis/nss_compat/compat-spwd.c: If buffer is to small, set the file handle for /etc/shadow back in some more cases. 1997-12-06 17:00 H.J. Lu <hjl@gnu.org> * sysdeps/posix/sigblock.c (__sigblock): Don't check int mask beyound its size. * sysdeps/posix/sigsetmask.c (__sigsetmask): Ditto. * sysdeps/posix/sigvec.c (convert_mask, __sigvec): Ditto. 1997-12-06 04:38 Ulrich Drepper <drepper@cygnus.com> * sysdeps/wordsize-32/inttypes.h: Rewrite {str,wcs}to{i,u}max handling. Don't use macros, we need functions. Use inline functions for optimization. * sysdeps/wordsize-64/inttypes.h: Likewise. * sysdeps/wordsize-32/Makefile: Add strtoimax, stroumax, wcstoimax, and wcstoumax. * sysdeps/wordsize-64/Makefile: Likewise. * sysdeps/wordsize-32/Dist: Likewise. * sysdeps/wordsize-64/Dist: Likewise. * sysdeps/wordsize-32/strtoimax.c: New file. * sysdeps/wordsize-32/strtoumax.c: New file. * sysdeps/wordsize-32/wcstoimax.c: New file. * sysdeps/wordsize-32/wcstoumax.c: New file. * sysdeps/wordsize-64/strtoimax.c: New file. * sysdeps/wordsize-64/strtoumax.c: New file. * sysdeps/wordsize-64/wcstoimax.c: New file. * sysdeps/wordsize-64/wcstoumax.c: New file. 1997-12-04 10:40 Philip Blundell <pb@nexus.co.uk> * sysdeps/generic/wait3.c (__wait3): Use ANSI-style definition so that transparent union works. * sysdeps/generic/wait4.c (__wait4): Likewise. * sysdeps/generic/wait.c (__wait): Likewise. * sysdeps/generic/getpeername.c (getpeername): Use socklen_t not size_t. * sysdeps/generic/syscall.c (syscall): Return value and arg are long, to match prototype. * malloc/malloc.c (HAVE_MREMAP): Set to 0 for ARM, as we don't have mremap() yet. * sysdeps/generic/usleep.c (usleep): Returns void, to match prototype. * sysdeps/unix/sysv/linux/arm/syscalls.list: New file. * sysdeps/generic/bits/time.h: Use __time_t not time_t. * sysdeps/generic/bits/resource.h: Include <bits/types.h> for __rlim_t. * sysdeps/standalone/arm/bits/errno.h (ENOTTY): Added. * sysdeps/generic/bits/dirent.h (struct dirent64): Added. * io/sys/stat.h (S_ISLNK): Always false if we don't have __S_IFLNK. * sysdeps/standalone/close.c (_STDIO_H): Define before including <bits/stdio_lim.h>. * sysdeps/standalone/filedesc.h (_STDIO_H): Likewise. 1997-12-06 01:09 Ulrich Drepper <drepper@cygnus.com> * posix/sys/wait.h: Don't use transparent unions in C++. 1997-12-05 Andreas Jaeger <aj@arthur.rhein-neckar.de> * time/time.h: Add strfxtime. * libc.map: Add tcgetsid, strcasestr, wmemrtombs, wmemrtowcs, sysv_signal, strfxtime, pread64, pwrite64. 1997-11-30 21:57 Richard Henderson <rth@cygnus.com> Alpha changes for EGCS: * config.h.in (ASM_ALPHA_NG_SYMBOL_PREFIX): New entry. * configure.in (libc_cv_gcc_alpha_ng_prefix): New check. * sysdeps/alpha/dl-machine.h (_dl_runtime_resolve): Care for prefix. (_start): Likewise. * sysdeps/unix/sysv/linux/alpha/init-first.h: Likewise.
Diffstat (limited to 'nis/nss_nisplus')
-rw-r--r-- | nis/nss_nisplus/nisplus-alias.c | 73 | ||||
-rw-r--r-- | nis/nss_nisplus/nisplus-ethers.c | 96 | ||||
-rw-r--r-- | nis/nss_nisplus/nisplus-grp.c | 59 | ||||
-rw-r--r-- | nis/nss_nisplus/nisplus-hosts.c | 131 | ||||
-rw-r--r-- | nis/nss_nisplus/nisplus-netgrp.c | 16 | ||||
-rw-r--r-- | nis/nss_nisplus/nisplus-network.c | 125 | ||||
-rw-r--r-- | nis/nss_nisplus/nisplus-parser.c | 96 | ||||
-rw-r--r-- | nis/nss_nisplus/nisplus-proto.c | 93 | ||||
-rw-r--r-- | nis/nss_nisplus/nisplus-publickey.c | 60 | ||||
-rw-r--r-- | nis/nss_nisplus/nisplus-pwd.c | 78 | ||||
-rw-r--r-- | nis/nss_nisplus/nisplus-rpc.c | 103 | ||||
-rw-r--r-- | nis/nss_nisplus/nisplus-service.c | 99 | ||||
-rw-r--r-- | nis/nss_nisplus/nisplus-spwd.c | 50 |
13 files changed, 654 insertions, 425 deletions
diff --git a/nis/nss_nisplus/nisplus-alias.c b/nis/nss_nisplus/nisplus-alias.c index 76c6f25813..381ad18228 100644 --- a/nis/nss_nisplus/nisplus-alias.c +++ b/nis/nss_nisplus/nisplus-alias.c @@ -41,7 +41,7 @@ static u_long tablename_len = 0; ((res)->objects.objects_val[(idx)].EN_data.en_cols.en_cols_val[(col)].ec_value.ec_value_len) static enum nss_status -_nss_create_tablename (void) +_nss_create_tablename (int *errnop) { if (tablename_val == NULL) { @@ -52,7 +52,10 @@ _nss_create_tablename (void) p = __stpcpy (p, nis_local_directory ()); tablename_val = __strdup (buf); if (tablename_val == NULL) - return NSS_STATUS_TRYAGAIN; + { + *errnop = errno; + return NSS_STATUS_TRYAGAIN; + } tablename_len = strlen (tablename_val); } return NSS_STATUS_SUCCESS; @@ -61,38 +64,38 @@ _nss_create_tablename (void) static int _nss_nisplus_parse_aliasent (nis_result *result, unsigned long entry, struct aliasent *alias, char *buffer, - size_t buflen) + size_t buflen, int *errnop) { if (result == NULL) return 0; - if ((result->status != NIS_SUCCESS && result->status != NIS_S_SUCCESS) || - __type_of (&result->objects.objects_val[entry]) != NIS_ENTRY_OBJ || - strcmp(result->objects.objects_val[entry].EN_data.en_type, - "mail_aliases") != 0 || - result->objects.objects_val[entry].EN_data.en_cols.en_cols_len < 2) + if ((result->status != NIS_SUCCESS && result->status != NIS_S_SUCCESS) + || __type_of (&result->objects.objects_val[entry]) != NIS_ENTRY_OBJ + || strcmp (result->objects.objects_val[entry].EN_data.en_type, + "mail_aliases") != 0 + || result->objects.objects_val[entry].EN_data.en_cols.en_cols_len < 2) return 0; else { - char *first_unused = buffer + NISENTRYLEN(0, 1, result) + 1; + char *first_unused = buffer + NISENTRYLEN (0, 1, result) + 1; size_t room_left = buflen - (buflen % __alignof__ (char *)) - - NISENTRYLEN(0, 1, result) - 2; + NISENTRYLEN (0, 1, result) - 2; char *line; char *cp; - if (NISENTRYLEN(entry, 1, result) >= buflen) + if (NISENTRYLEN (entry, 1, result) >= buflen) { /* The line is too long for our buffer. */ no_more_room: - __set_errno (ERANGE); + *errnop = ERANGE; return -1; } else { - strncpy (buffer, NISENTRYVAL(entry, 1, result), - NISENTRYLEN(entry, 1, result)); - buffer[NISENTRYLEN(entry, 1, result)] = '\0'; + strncpy (buffer, NISENTRYVAL (entry, 1, result), + NISENTRYLEN (entry, 1, result)); + buffer[NISENTRYLEN (entry, 1, result)] = '\0'; } if (NISENTRYLEN(entry, 0, result) >= room_left) @@ -102,8 +105,8 @@ _nss_nisplus_parse_aliasent (nis_result *result, unsigned long entry, alias->alias_members_len = 0; *first_unused = '\0'; ++first_unused; - strcpy (first_unused, NISENTRYVAL(entry, 0, result)); - first_unused[NISENTRYLEN(entry, 0, result)] = '\0'; + strcpy (first_unused, NISENTRYVAL (entry, 0, result)); + first_unused[NISENTRYLEN (entry, 0, result)] = '\0'; alias->alias_name = first_unused; /* Terminate the line for any case. */ @@ -153,16 +156,17 @@ static enum nss_status internal_setaliasent (void) { enum nss_status status; + int err; if (result) nis_freeresult (result); result = NULL; - if (_nss_create_tablename () != NSS_STATUS_SUCCESS) + if (_nss_create_tablename (&err) != NSS_STATUS_SUCCESS) return NSS_STATUS_UNAVAIL; next_entry = 0; - result = nis_list(tablename_val, FOLLOW_PATH | FOLLOW_LINKS, NULL, NULL); + result = nis_list (tablename_val, FOLLOW_PATH | FOLLOW_LINKS, NULL, NULL); status = niserr2nss (result->status); if (status != NSS_STATUS_SUCCESS) { @@ -203,7 +207,7 @@ _nss_nisplus_endaliasent (void) static enum nss_status internal_nisplus_getaliasent_r (struct aliasent *alias, - char *buffer, size_t buflen) + char *buffer, size_t buflen, int *errnop) { int parse_res; @@ -222,8 +226,9 @@ internal_nisplus_getaliasent_r (struct aliasent *alias, if (next_entry >= result->objects.objects_len) return NSS_STATUS_NOTFOUND; - if ((parse_res = _nss_nisplus_parse_aliasent (result, next_entry, alias, - buffer, buflen)) == -1) + parse_res = _nss_nisplus_parse_aliasent (result, next_entry, alias, + buffer, buflen, errnop); + if (parse_res == -1) return NSS_STATUS_TRYAGAIN; ++next_entry; @@ -234,13 +239,13 @@ internal_nisplus_getaliasent_r (struct aliasent *alias, enum nss_status _nss_nisplus_getaliasent_r (struct aliasent *result, char *buffer, - size_t buflen) + size_t buflen, int *errnop) { int status; __libc_lock_lock (lock); - status = internal_nisplus_getaliasent_r (result, buffer, buflen); + status = internal_nisplus_getaliasent_r (result, buffer, buflen, errnop); __libc_lock_unlock (lock); @@ -249,28 +254,32 @@ _nss_nisplus_getaliasent_r (struct aliasent *result, char *buffer, enum nss_status _nss_nisplus_getaliasbyname_r (const char *name, struct aliasent *alias, - char *buffer, size_t buflen) + char *buffer, size_t buflen, int *errnop) { int parse_res; if (tablename_val == NULL) - if (_nss_create_tablename() != NSS_STATUS_SUCCESS) - return NSS_STATUS_UNAVAIL; + { + enum nss_status status = _nss_create_tablename (errnop); + if (status != NSS_STATUS_SUCCESS) + return status; + } - if (name != NULL || strlen(name) <= 8) + if (name != NULL || strlen (name) <= 8) { nis_result *result; char buf[strlen (name) + 30 + tablename_len]; - sprintf(buf, "[name=%s],%s", name, tablename_val); + sprintf (buf, "[name=%s],%s", name, tablename_val); - result = nis_list(buf, FOLLOW_PATH | FOLLOW_LINKS, NULL, NULL); + result = nis_list (buf, FOLLOW_PATH | FOLLOW_LINKS, NULL, NULL); if (niserr2nss (result->status) != NSS_STATUS_SUCCESS) return niserr2nss (result->status); - if ((parse_res = _nss_nisplus_parse_aliasent (result, 0, alias, - buffer, buflen)) == -1) + parse_res = _nss_nisplus_parse_aliasent (result, 0, alias, + buffer, buflen, errnop); + if (parse_res == -1) return NSS_STATUS_TRYAGAIN; if (parse_res) diff --git a/nis/nss_nisplus/nisplus-ethers.c b/nis/nss_nisplus/nisplus-ethers.c index 8ca6935cc7..76805f1403 100644 --- a/nis/nss_nisplus/nisplus-ethers.c +++ b/nis/nss_nisplus/nisplus-ethers.c @@ -53,7 +53,7 @@ struct etherent_data {}; static int _nss_nisplus_parse_etherent (nis_result *result, struct etherent *ether, - char *buffer, size_t buflen) + char *buffer, size_t buflen, int *errnop) { char *p = buffer; size_t room_left = buflen; @@ -61,18 +61,18 @@ _nss_nisplus_parse_etherent (nis_result *result, struct etherent *ether, if (result == NULL) return 0; - if ((result->status != NIS_SUCCESS && result->status != NIS_S_SUCCESS) || - result->objects.objects_len != 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) + if ((result->status != NIS_SUCCESS && result->status != NIS_S_SUCCESS) + || result->objects.objects_len != 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) { - __set_errno (ERANGE); + *errnop = ERANGE; return -1; } strncpy (p, NISENTRYVAL (0, 0, result), NISENTRYLEN (0, 0, result)); @@ -85,7 +85,7 @@ _nss_nisplus_parse_etherent (nis_result *result, struct etherent *ether, } static enum nss_status -_nss_create_tablename (void) +_nss_create_tablename (int *errnop) { if (tablename_val == NULL) { @@ -96,7 +96,10 @@ _nss_create_tablename (void) p = __stpcpy (p, nis_local_directory ()); tablename_val = __strdup (buf); if (tablename_val == NULL) - return NSS_STATUS_TRYAGAIN; + { + *errnop = errno; + return NSS_STATUS_TRYAGAIN; + } tablename_len = strlen (tablename_val); } return NSS_STATUS_SUCCESS; @@ -107,6 +110,7 @@ enum nss_status _nss_nisplus_setetherent (void) { enum nss_status status; + int err; status = NSS_STATUS_SUCCESS; @@ -116,7 +120,7 @@ _nss_nisplus_setetherent (void) nis_freeresult (result); result = NULL; - if (_nss_create_tablename () != NSS_STATUS_SUCCESS) + if (_nss_create_tablename (&err) != NSS_STATUS_SUCCESS) status = NSS_STATUS_UNAVAIL; __libc_lock_unlock (lock); @@ -140,13 +144,17 @@ _nss_nisplus_endetherent (void) static enum nss_status internal_nisplus_getetherent_r (struct etherent *ether, char *buffer, - size_t buflen) + size_t buflen, int *errnop) { int parse_res; if (tablename_val == NULL) - if (_nss_create_tablename () != NSS_STATUS_SUCCESS) - return NSS_STATUS_UNAVAIL; + { + enum nss_status status = _nss_create_tablename (errnop); + + if (status != NSS_STATUS_SUCCESS) + return status; + } /* Get the next entry until we found a correct one. */ do @@ -156,7 +164,7 @@ internal_nisplus_getetherent_r (struct etherent *ether, char *buffer, if (result == NULL) { saved_result = NULL; - result = nis_first_entry(tablename_val); + result = nis_first_entry (tablename_val); if (niserr2nss (result->status) != NSS_STATUS_SUCCESS) return niserr2nss (result->status); } @@ -174,10 +182,12 @@ internal_nisplus_getetherent_r (struct etherent *ether, char *buffer, } } - if ((parse_res = _nss_nisplus_parse_etherent (result, ether, buffer, - buflen)) == -1) + parse_res = _nss_nisplus_parse_etherent (result, ether, buffer, + buflen, errnop); + if (parse_res == -1) { nis_freeresult (result); + *errnop = ERANGE; result = saved_result; return NSS_STATUS_TRYAGAIN; } @@ -194,13 +204,13 @@ internal_nisplus_getetherent_r (struct etherent *ether, char *buffer, enum nss_status _nss_nisplus_getetherent_r (struct etherent *result, char *buffer, - size_t buflen) + size_t buflen, int *errnop) { int status; __libc_lock_lock (lock); - status = internal_nisplus_getetherent_r (result, buffer, buflen); + status = internal_nisplus_getetherent_r (result, buffer, buflen, errnop); __libc_lock_unlock (lock); @@ -209,22 +219,26 @@ _nss_nisplus_getetherent_r (struct etherent *result, char *buffer, enum nss_status _nss_nisplus_gethostton_r (const char *name, struct etherent *eth, - char *buffer, size_t buflen) + char *buffer, size_t buflen, int *errnop) { int parse_res; if (tablename_val == NULL) - if (_nss_create_tablename () != NSS_STATUS_SUCCESS) - return NSS_STATUS_UNAVAIL; + { + enum nss_status status = _nss_create_tablename (errnop); + + if (status != NSS_STATUS_SUCCESS) + return status; + } if (name != NULL) { nis_result *result; char buf[strlen (name) + 40 + tablename_len]; - sprintf(buf, "[name=%s],%s", name, tablename_val); + sprintf (buf, "[name=%s],%s", name, tablename_val); - result = nis_list(buf, FOLLOW_PATH | FOLLOW_LINKS, NULL, NULL); + result = nis_list (buf, FOLLOW_PATH | FOLLOW_LINKS, NULL, NULL); if (niserr2nss (result->status) != NSS_STATUS_SUCCESS) { @@ -233,10 +247,12 @@ _nss_nisplus_gethostton_r (const char *name, struct etherent *eth, return status; } - if ((parse_res = _nss_nisplus_parse_etherent (result, eth, buffer, - buflen)) == -1) + parse_res = _nss_nisplus_parse_etherent (result, eth, buffer, + buflen, errnop); + if (parse_res == -1) { nis_freeresult (result); + *errnop = ERANGE; return NSS_STATUS_TRYAGAIN; } @@ -249,15 +265,19 @@ _nss_nisplus_gethostton_r (const char *name, struct etherent *eth, enum nss_status _nss_nisplus_getntohost_r (const struct ether_addr *addr, struct etherent *eth, - char *buffer, size_t buflen) + char *buffer, size_t buflen, int *errnop) { if (tablename_val == NULL) - if (_nss_create_tablename () != NSS_STATUS_SUCCESS) - return NSS_STATUS_UNAVAIL; + { + enum nss_status status = _nss_create_tablename (errnop); + + if (status != NSS_STATUS_SUCCESS) + return status; + } if (addr == NULL) { - __set_errno (EINVAL); + *errnop = EINVAL; return NSS_STATUS_UNAVAIL; } else @@ -267,12 +287,12 @@ _nss_nisplus_getntohost_r (const struct ether_addr *addr, char buf[255 + tablename_len]; memset (&buf, '\0', sizeof (buf)); - sprintf(buf, "[addr=%x:%x:%x:%x:%x:%x],ethers.org_dir", - 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]); + sprintf (buf, "[addr=%x:%x:%x:%x:%x:%x],ethers.org_dir", + 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]); - result = nis_list(buf, FOLLOW_PATH | FOLLOW_LINKS, NULL, NULL); + result = nis_list (buf, FOLLOW_PATH | FOLLOW_LINKS, NULL, NULL); if (niserr2nss (result->status) != NSS_STATUS_SUCCESS) { @@ -281,10 +301,12 @@ _nss_nisplus_getntohost_r (const struct ether_addr *addr, return status; } - if ((parse_res = _nss_nisplus_parse_etherent (result, eth, buffer, - buflen)) == -1) + parse_res = _nss_nisplus_parse_etherent (result, eth, buffer, + buflen, errnop); + if (parse_res == -1) { nis_freeresult (result); + *errnop = ERANGE; return NSS_STATUS_TRYAGAIN; } diff --git a/nis/nss_nisplus/nisplus-grp.c b/nis/nss_nisplus/nisplus-grp.c index fb200321d2..4ac048ef05 100644 --- a/nis/nss_nisplus/nisplus-grp.c +++ b/nis/nss_nisplus/nisplus-grp.c @@ -36,7 +36,7 @@ static nis_name tablename_val = NULL; static u_long tablename_len = 0; static enum nss_status -_nss_create_tablename (void) +_nss_create_tablename (int *errnop) { if (tablename_val == NULL) { @@ -47,7 +47,10 @@ _nss_create_tablename (void) p = __stpcpy (p, nis_local_directory ()); tablename_val = __strdup (buf); if (tablename_val == NULL) - return NSS_STATUS_TRYAGAIN; + { + *errnop = errno; + return NSS_STATUS_TRYAGAIN; + } tablename_len = strlen (tablename_val); } return NSS_STATUS_SUCCESS; @@ -57,6 +60,7 @@ static enum nss_status internal_setgrent (void) { enum nss_status status; + int err; if (result) nis_freeresult (result); @@ -64,7 +68,7 @@ internal_setgrent (void) next_entry = 0; if (tablename_val == NULL) - if (_nss_create_tablename () != NSS_STATUS_SUCCESS) + if (_nss_create_tablename (&err) != NSS_STATUS_SUCCESS) return NSS_STATUS_UNAVAIL; result = nis_list (tablename_val, FOLLOW_LINKS | FOLLOW_PATH, NULL, NULL); @@ -106,7 +110,8 @@ _nss_nisplus_endgrent (void) } static enum nss_status -internal_nisplus_getgrent_r (struct group *gr, char *buffer, size_t buflen) +internal_nisplus_getgrent_r (struct group *gr, char *buffer, size_t buflen, + int *errnop) { int parse_res; @@ -125,8 +130,9 @@ internal_nisplus_getgrent_r (struct group *gr, char *buffer, size_t buflen) if (next_entry >= result->objects.objects_len) return NSS_STATUS_NOTFOUND; - if ((parse_res = _nss_nisplus_parse_grent (result, next_entry, gr, - buffer, buflen)) == -1) + parse_res = _nss_nisplus_parse_grent (result, next_entry, gr, + buffer, buflen, errnop); + if (parse_res == -1) return NSS_STATUS_TRYAGAIN; ++next_entry; @@ -137,13 +143,14 @@ internal_nisplus_getgrent_r (struct group *gr, char *buffer, size_t buflen) } enum nss_status -_nss_nisplus_getgrent_r (struct group *result, char *buffer, size_t buflen) +_nss_nisplus_getgrent_r (struct group *result, char *buffer, size_t buflen, + int *errnop) { int status; __libc_lock_lock (lock); - status = internal_nisplus_getgrent_r (result, buffer, buflen); + status = internal_nisplus_getgrent_r (result, buffer, buflen, errnop); __libc_lock_unlock (lock); @@ -152,13 +159,17 @@ _nss_nisplus_getgrent_r (struct group *result, char *buffer, size_t buflen) enum nss_status _nss_nisplus_getgrnam_r (const char *name, struct group *gr, - char *buffer, size_t buflen) + char *buffer, size_t buflen, int *errnop) { int parse_res; if (tablename_val == NULL) - if (_nss_create_tablename() != NSS_STATUS_SUCCESS) - return NSS_STATUS_UNAVAIL; + { + enum nss_status status = _nss_create_tablename (errnop); + + if (status != NSS_STATUS_SUCCESS) + return status; + } if (name == NULL || strlen (name) > 8) return NSS_STATUS_NOTFOUND; @@ -179,11 +190,15 @@ _nss_nisplus_getgrnam_r (const char *name, struct group *gr, return status; } - parse_res = _nss_nisplus_parse_grent (result, 0, gr, buffer, buflen); + parse_res = _nss_nisplus_parse_grent (result, 0, gr, buffer, buflen, + errnop); nis_freeresult (result); if (parse_res == -1) - return NSS_STATUS_TRYAGAIN; + { + *errnop = ERANGE; + return NSS_STATUS_TRYAGAIN; + } if (parse_res) return NSS_STATUS_SUCCESS; @@ -193,11 +208,15 @@ _nss_nisplus_getgrnam_r (const char *name, struct group *gr, enum nss_status _nss_nisplus_getgrgid_r (const gid_t gid, struct group *gr, - char *buffer, size_t buflen) + char *buffer, size_t buflen, int *errnop) { if (tablename_val == NULL) - if (_nss_create_tablename() != NSS_STATUS_SUCCESS) - return NSS_STATUS_UNAVAIL; + { + enum nss_status status = _nss_create_tablename (errnop); + + if (status != NSS_STATUS_SUCCESS) + return status; + } { int parse_res; @@ -216,12 +235,16 @@ _nss_nisplus_getgrgid_r (const gid_t gid, struct group *gr, return status; } - parse_res = _nss_nisplus_parse_grent (result, 0, gr, buffer, buflen); + parse_res = _nss_nisplus_parse_grent (result, 0, gr, buffer, buflen, + errnop); nis_freeresult (result); if (parse_res == -1) - return NSS_STATUS_TRYAGAIN; + { + *errnop = ERANGE; + return NSS_STATUS_TRYAGAIN; + } if (parse_res) return NSS_STATUS_SUCCESS; diff --git a/nis/nss_nisplus/nisplus-hosts.c b/nis/nss_nisplus/nisplus-hosts.c index d1aa5ef787..8514a63e8a 100644 --- a/nis/nss_nisplus/nisplus-hosts.c +++ b/nis/nss_nisplus/nisplus-hosts.c @@ -42,11 +42,11 @@ static u_long tablename_len = 0; ((res)->objects.objects_val[(idx)].EN_data.en_cols.en_cols_val[(col)].ec_value.ec_value_len) /* Get implementation for some internal functions. */ -#include "../../resolv/mapv4v6addr.h" +#include <resolv/mapv4v6addr.h> static int _nss_nisplus_parse_hostent (nis_result *result, int af, struct hostent *host, - char *buffer, size_t buflen) + char *buffer, size_t buflen, int *errnop) { unsigned int i; char *first_unused = buffer; @@ -66,7 +66,7 @@ _nss_nisplus_parse_hostent (nis_result *result, int af, struct hostent *host, if (room_left < NISENTRYLEN (0, 2, result) + 1) { no_more_room: - __set_errno (ERANGE); + *errnop = ERANGE; return -1; } @@ -169,7 +169,7 @@ _nss_nisplus_parse_hostent (nis_result *result, int af, struct hostent *host, } static enum nss_status -_nss_create_tablename (void) +_nss_create_tablename (int *errnop) { if (tablename_val == NULL) { @@ -180,7 +180,10 @@ _nss_create_tablename (void) p = __stpcpy (p, nis_local_directory ()); tablename_val = __strdup (buf); if (tablename_val == NULL) - return NSS_STATUS_TRYAGAIN; + { + *errnop = errno; + return NSS_STATUS_TRYAGAIN; + } tablename_len = strlen (tablename_val); } return NSS_STATUS_SUCCESS; @@ -190,6 +193,7 @@ enum nss_status _nss_nisplus_sethostent (void) { enum nss_status status = NSS_STATUS_SUCCESS; + int err; __libc_lock_lock (lock); @@ -198,8 +202,7 @@ _nss_nisplus_sethostent (void) result = NULL; if (tablename_val == NULL) - if (_nss_create_tablename() != NSS_STATUS_SUCCESS) - status = NSS_STATUS_UNAVAIL; + status = _nss_create_tablename (&err); __libc_lock_unlock (lock); @@ -222,7 +225,7 @@ _nss_nisplus_endhostent (void) static enum nss_status internal_nisplus_gethostent_r (struct hostent *host, char *buffer, - size_t buflen, int *herrnop) + size_t buflen, int *errnop, int *herrnop) { int parse_res; @@ -235,17 +238,21 @@ internal_nisplus_gethostent_r (struct hostent *host, char *buffer, { saved_res = NULL; if (tablename_val == NULL) - if (_nss_create_tablename() != NSS_STATUS_SUCCESS) - return NSS_STATUS_UNAVAIL; + { + enum nss_status status = _nss_create_tablename (errnop); - result = nis_first_entry(tablename_val); + if (status != NSS_STATUS_SUCCESS) + return status; + } + + result = nis_first_entry (tablename_val); if (niserr2nss (result->status) != NSS_STATUS_SUCCESS) { enum nss_status retval = niserr2nss (result->status); if (retval == NSS_STATUS_TRYAGAIN) { *herrnop = NETDB_INTERNAL; - __set_errno (EAGAIN); + *errnop = errno; } return retval; } @@ -267,22 +274,23 @@ internal_nisplus_gethostent_r (struct hostent *host, char *buffer, if (retval == NSS_STATUS_TRYAGAIN) { *herrnop = NETDB_INTERNAL; - __set_errno (EAGAIN); + *errnop = errno; } return retval; } } - parse_res = _nss_nisplus_parse_hostent (result, AF_INET6, - host, buffer, buflen); - if (parse_res < 1 && errno != ERANGE) + parse_res = _nss_nisplus_parse_hostent (result, AF_INET6, host, buffer, + buflen, errnop); + if (parse_res < 1 && *errnop != ERANGE) parse_res = _nss_nisplus_parse_hostent (result, AF_INET, host, - buffer, buflen); - if (parse_res < 1 && errno == ERANGE) + buffer, buflen, errnop); + if (parse_res < 1 && *errnop == ERANGE) { nis_freeresult (result); result = saved_res; *herrnop = NETDB_INTERNAL; + *errnop = ERANGE; return NSS_STATUS_TRYAGAIN; } if (saved_res != NULL) @@ -295,13 +303,14 @@ internal_nisplus_gethostent_r (struct hostent *host, char *buffer, enum nss_status _nss_nisplus_gethostent_r (struct hostent *result, char *buffer, - size_t buflen, int *herrnop) + size_t buflen, int *errnop, int *herrnop) { int status; __libc_lock_lock (lock); - status = internal_nisplus_gethostent_r (result, buffer, buflen, herrnop); + status = internal_nisplus_gethostent_r (result, buffer, buflen, errnop, + herrnop); __libc_lock_unlock (lock); @@ -310,20 +319,25 @@ _nss_nisplus_gethostent_r (struct hostent *result, char *buffer, enum nss_status _nss_nisplus_gethostbyname2_r (const char *name, int af, struct hostent *host, - char *buffer, size_t buflen, int *herrnop) + char *buffer, size_t buflen, int *errnop, + int *herrnop) { int parse_res, retval; if (tablename_val == NULL) - if (_nss_create_tablename() != NSS_STATUS_SUCCESS) - { - *herrnop = NETDB_INTERNAL; - return NSS_STATUS_UNAVAIL; - } + { + enum nss_status status = _nss_create_tablename (errnop); + + if (status != NSS_STATUS_SUCCESS) + { + *herrnop = NETDB_INTERNAL; + return NSS_STATUS_UNAVAIL; + } + } if (name == NULL) { - __set_errno (EINVAL); + *errnop = EINVAL; *herrnop = NETDB_INTERNAL; return NSS_STATUS_NOTFOUND; } @@ -334,38 +348,38 @@ _nss_nisplus_gethostbyname2_r (const char *name, int af, struct hostent *host, /* Search at first in the alias list, and use the correct name for the next search */ - sprintf(buf, "[name=%s],%s", name, tablename_val); - result = nis_list(buf, FOLLOW_PATH | FOLLOW_LINKS, NULL, NULL); + sprintf (buf, "[name=%s],%s", name, tablename_val); + result = nis_list (buf, FOLLOW_PATH | FOLLOW_LINKS, NULL, NULL); /* If we do not find it, try it as original name. But if the database is correct, we should find it in the first case, too */ - if ((result->status != NIS_SUCCESS && result->status != NIS_S_SUCCESS) || - __type_of (result->objects.objects_val) != NIS_ENTRY_OBJ || - strcmp(result->objects.objects_val->EN_data.en_type, - "hosts_tbl") != 0 || - result->objects.objects_val->EN_data.en_cols.en_cols_len < 3) - sprintf(buf, "[cname=%s],%s", name, tablename_val); + if ((result->status != NIS_SUCCESS && result->status != NIS_S_SUCCESS) + || __type_of (result->objects.objects_val) != NIS_ENTRY_OBJ + || strcmp (result->objects.objects_val->EN_data.en_type, + "hosts_tbl") != 0 + || result->objects.objects_val->EN_data.en_cols.en_cols_len < 3) + sprintf (buf, "[cname=%s],%s", name, tablename_val); else - sprintf(buf, "[cname=%s],%s", NISENTRYVAL(0, 0, result), - tablename_val); + sprintf (buf, "[cname=%s],%s", NISENTRYVAL(0, 0, result), + tablename_val); nis_freeresult (result); - result = nis_list(buf, FOLLOW_PATH | FOLLOW_LINKS, NULL, NULL); + result = nis_list (buf, FOLLOW_PATH | FOLLOW_LINKS, NULL, NULL); retval = niserr2nss (result->status); if (retval != NSS_STATUS_SUCCESS) { if (retval == NSS_STATUS_TRYAGAIN) { - __set_errno (EAGAIN); + *errnop = errno; *herrnop = NETDB_INTERNAL; } nis_freeresult (result); return retval; } - parse_res = - _nss_nisplus_parse_hostent (result, af, host, buffer, buflen); + parse_res = _nss_nisplus_parse_hostent (result, af, host, buffer, + buflen, errnop); nis_freeresult (result); @@ -374,7 +388,10 @@ _nss_nisplus_gethostbyname2_r (const char *name, int af, struct hostent *host, *herrnop = NETDB_INTERNAL; if (parse_res == -1) - return NSS_STATUS_TRYAGAIN; + { + *errnop = ERANGE; + return NSS_STATUS_TRYAGAIN; + } else return NSS_STATUS_NOTFOUND; } @@ -382,30 +399,35 @@ _nss_nisplus_gethostbyname2_r (const char *name, int af, struct hostent *host, enum nss_status _nss_nisplus_gethostbyname_r (const char *name, struct hostent *host, - char *buffer, size_t buflen, int *h_errnop) + char *buffer, size_t buflen, int *errnop, + int *h_errnop) { if (_res.options & RES_USE_INET6) { enum nss_status status; status = _nss_nisplus_gethostbyname2_r (name, AF_INET6, host, buffer, - buflen, h_errnop); + buflen, errnop, h_errnop); if (status == NSS_STATUS_SUCCESS) return status; } return _nss_nisplus_gethostbyname2_r (name, AF_INET, host, buffer, - buflen, h_errnop); + buflen, errnop, h_errnop); } enum nss_status _nss_nisplus_gethostbyaddr_r (const char *addr, int addrlen, int type, struct hostent *host, char *buffer, - size_t buflen, int *herrnop) + size_t buflen, int *errnop, int *herrnop) { if (tablename_val == NULL) - if (_nss_create_tablename() != NSS_STATUS_SUCCESS) - return NSS_STATUS_UNAVAIL; + { + enum nss_status status = _nss_create_tablename (errnop); + + if (status != NSS_STATUS_SUCCESS) + return status; + } if (addr == NULL) return NSS_STATUS_NOTFOUND; @@ -416,15 +438,15 @@ _nss_nisplus_gethostbyaddr_r (const char *addr, int addrlen, int type, int retval, parse_res; sprintf (buf, "[addr=%s],%s", - inet_ntoa (*(struct in_addr *)addr), tablename_val); - result = nis_list(buf, FOLLOW_PATH | FOLLOW_LINKS, NULL, NULL); + inet_ntoa (*(struct in_addr *) addr), tablename_val); + result = nis_list (buf, FOLLOW_PATH | FOLLOW_LINKS, NULL, NULL); retval = niserr2nss (result->status); if (retval != NSS_STATUS_SUCCESS) { if (retval == NSS_STATUS_TRYAGAIN) { - __set_errno (EAGAIN); + *errnop = errno; *herrnop = NETDB_INTERNAL; } nis_freeresult (result); @@ -432,7 +454,7 @@ _nss_nisplus_gethostbyaddr_r (const char *addr, int addrlen, int type, } parse_res = _nss_nisplus_parse_hostent (result, type, host, - buffer, buflen); + buffer, buflen, errnop); nis_freeresult (result); if (parse_res > 0) @@ -440,7 +462,10 @@ _nss_nisplus_gethostbyaddr_r (const char *addr, int addrlen, int type, *herrnop = NETDB_INTERNAL; if (parse_res == -1) - return NSS_STATUS_TRYAGAIN; + { + *errnop = ERANGE; + return NSS_STATUS_TRYAGAIN; + } else return NSS_STATUS_NOTFOUND; } diff --git a/nis/nss_nisplus/nisplus-netgrp.c b/nis/nss_nisplus/nisplus-netgrp.c index 2a2f4b5ec9..5d5b727292 100644 --- a/nis/nss_nisplus/nisplus-netgrp.c +++ b/nis/nss_nisplus/nisplus-netgrp.c @@ -42,7 +42,7 @@ static unsigned long position = 0; static enum nss_status _nss_nisplus_parse_netgroup (struct __netgrent *result, char *buffer, - size_t buflen) + size_t buflen, int *errnop) { enum nss_status status; @@ -60,7 +60,7 @@ _nss_nisplus_parse_netgroup (struct __netgrent *result, char *buffer, result->type = group_val; if (NISENTRYLEN (position, 1, data) >= buflen) { - __set_errno (ERANGE); + *errnop = ERANGE; return NSS_STATUS_TRYAGAIN; } strncpy (buffer, NISENTRYVAL (position, 1, data), @@ -78,7 +78,7 @@ _nss_nisplus_parse_netgroup (struct __netgrent *result, char *buffer, if (NISENTRYLEN (position, 2, data) + NISENTRYLEN (position, 3, data) + NISENTRYLEN (position, 4, data) + 6 > buflen) { - __set_errno (ERANGE); + *errnop = ERANGE; status = NSS_STATUS_TRYAGAIN; } else @@ -94,8 +94,7 @@ _nss_nisplus_parse_netgroup (struct __netgrent *result, char *buffer, result->val.triple.host = cp; cp = __stpncpy (cp, NISENTRYVAL (position, 2, data), NISENTRYLEN (position, 2, data)); - *cp = '\0'; - ++cp; + *cp++ = '\0'; } if (NISENTRYLEN (position, 3, data) == 0) @@ -105,8 +104,7 @@ _nss_nisplus_parse_netgroup (struct __netgrent *result, char *buffer, result->val.triple.user = cp; cp = __stpncpy (cp, NISENTRYVAL (position, 3, data), NISENTRYLEN (position, 3, data)); - *cp = '\0'; - ++cp; + *cp++ = '\0'; } if (NISENTRYLEN (position, 4, data) == 0) @@ -190,13 +188,13 @@ _nss_nisplus_endnetgrent (void) enum nss_status _nss_nisplus_getnetgrent_r (struct __netgrent *result, - char *buffer, size_t buflen) + char *buffer, size_t buflen, int *errnop) { enum nss_status status; __libc_lock_lock (lock); - status = _nss_nisplus_parse_netgroup (result, buffer, buflen); + status = _nss_nisplus_parse_netgroup (result, buffer, buflen, errnop); __libc_lock_unlock (lock); diff --git a/nis/nss_nisplus/nisplus-network.c b/nis/nss_nisplus/nisplus-network.c index e548017068..b39a54fe03 100644 --- a/nis/nss_nisplus/nisplus-network.c +++ b/nis/nss_nisplus/nisplus-network.c @@ -43,7 +43,7 @@ static u_long tablename_len = 0; static int _nss_nisplus_parse_netent (nis_result *result, struct netent *network, - char *buffer, size_t buflen) + char *buffer, size_t buflen, int *errnop) { char *first_unused = buffer; size_t room_left = buflen; @@ -53,24 +53,24 @@ _nss_nisplus_parse_netent (nis_result *result, struct netent *network, if (result == NULL) return 0; - if ((result->status != NIS_SUCCESS && result->status != NIS_S_SUCCESS) || - __type_of (result->objects.objects_val) != NIS_ENTRY_OBJ || - strcmp(result->objects.objects_val[0].EN_data.en_type, - "networks_tbl") != 0 || - result->objects.objects_val[0].EN_data.en_cols.en_cols_len < 3) + if ((result->status != NIS_SUCCESS && result->status != NIS_S_SUCCESS) + || __type_of (result->objects.objects_val) != NIS_ENTRY_OBJ + || strcmp (result->objects.objects_val[0].EN_data.en_type, + "networks_tbl") != 0 + || result->objects.objects_val[0].EN_data.en_cols.en_cols_len < 3) return 0; if (NISENTRYLEN(0, 0, result) >= room_left) { /* The line is too long for our buffer. */ no_more_room: - __set_errno (ERANGE); + *errnop = ERANGE; return -1; } strncpy (first_unused, NISENTRYVAL(0, 0, result), NISENTRYLEN (0, 0, result)); - first_unused[NISENTRYLEN(0, 0, result)] = '\0'; + first_unused[NISENTRYLEN (0, 0, result)] = '\0'; network->n_name = first_unused; room_left -= (strlen (first_unused) +1); first_unused += strlen (first_unused) +1; @@ -142,7 +142,7 @@ _nss_nisplus_parse_netent (nis_result *result, struct netent *network, } static enum nss_status -_nss_create_tablename (void) +_nss_create_tablename (int *errnop) { if (tablename_val == NULL) { @@ -153,7 +153,10 @@ _nss_create_tablename (void) p = __stpcpy (p, nis_local_directory ()); tablename_val = __strdup (buf); if (tablename_val == NULL) - return NSS_STATUS_TRYAGAIN; + { + *errnop = errno; + return NSS_STATUS_TRYAGAIN; + } tablename_len = strlen (tablename_val); } return NSS_STATUS_SUCCESS; @@ -163,6 +166,7 @@ enum nss_status _nss_nisplus_setnetent (void) { enum nss_status status = NSS_STATUS_SUCCESS; + int err; __libc_lock_lock (lock); @@ -171,8 +175,7 @@ _nss_nisplus_setnetent (void) result = NULL; if (tablename_val == NULL) - if (_nss_create_tablename () != NSS_STATUS_SUCCESS) - status = NSS_STATUS_UNAVAIL; + status = _nss_create_tablename (&err); __libc_lock_unlock (lock); @@ -195,7 +198,7 @@ _nss_nisplus_endnetent (void) static enum nss_status internal_nisplus_getnetent_r (struct netent *network, char *buffer, - size_t buflen, int *herrnop) + size_t buflen, int *errnop, int *herrnop) { int parse_res; @@ -209,10 +212,14 @@ internal_nisplus_getnetent_r (struct netent *network, char *buffer, saved_res = NULL; if (tablename_val == NULL) - if (_nss_create_tablename() != NSS_STATUS_SUCCESS) - return NSS_STATUS_UNAVAIL; + { + enum nss_status status = _nss_create_tablename (errnop); + + if (status != NSS_STATUS_SUCCESS) + return status; + } - result = nis_first_entry(tablename_val); + result = nis_first_entry (tablename_val); if (niserr2nss (result->status) != NSS_STATUS_SUCCESS) { int retval; @@ -223,7 +230,7 @@ internal_nisplus_getnetent_r (struct netent *network, char *buffer, if (retval == NSS_STATUS_TRYAGAIN) { *herrnop = NETDB_INTERNAL; - __set_errno (EAGAIN); + *errnop = errno; return retval; } else @@ -234,7 +241,7 @@ internal_nisplus_getnetent_r (struct netent *network, char *buffer, { nis_result *res; - res = nis_next_entry(tablename_val, &result->cookie); + res = nis_next_entry (tablename_val, &result->cookie); saved_res = result; result = res; if (niserr2nss (result->status) != NSS_STATUS_SUCCESS) @@ -247,14 +254,15 @@ internal_nisplus_getnetent_r (struct netent *network, char *buffer, if (retval == NSS_STATUS_TRYAGAIN) { *herrnop = NETDB_INTERNAL; - __set_errno (EAGAIN); + *errnop = errno; } return retval; } } - if ((parse_res = _nss_nisplus_parse_netent (result, network, buffer, - buflen)) == -1) + parse_res = _nss_nisplus_parse_netent (result, network, buffer, + buflen, errnop); + if (parse_res == -1) { *herrnop = NETDB_INTERNAL; return NSS_STATUS_TRYAGAIN; @@ -267,13 +275,14 @@ internal_nisplus_getnetent_r (struct netent *network, char *buffer, enum nss_status _nss_nisplus_getnetent_r (struct netent *result, char *buffer, - size_t buflen, int *herrnop) + size_t buflen, int *errnop, int *herrnop) { int status; __libc_lock_lock (lock); - status = internal_nisplus_getnetent_r (result, buffer, buflen, herrnop); + status = internal_nisplus_getnetent_r (result, buffer, buflen, errnop, + herrnop); __libc_lock_unlock (lock); @@ -282,17 +291,22 @@ _nss_nisplus_getnetent_r (struct netent *result, char *buffer, enum nss_status _nss_nisplus_getnetbyname_r (const char *name, struct netent *network, - char *buffer, size_t buflen, int *herrnop) + char *buffer, size_t buflen, int *errnop, + int *herrnop) { int parse_res, retval; if (tablename_val == NULL) - if (_nss_create_tablename() != NSS_STATUS_SUCCESS) - return NSS_STATUS_UNAVAIL; + { + enum nss_status status = _nss_create_tablename (errnop); + + if (status != NSS_STATUS_SUCCESS) + return status; + } if (name == NULL) { - __set_errno (EINVAL); + *errnop = EINVAL; *herrnop = NETDB_INTERNAL; return NSS_STATUS_UNAVAIL; } @@ -303,38 +317,38 @@ _nss_nisplus_getnetbyname_r (const char *name, struct netent *network, /* Search at first in the alias list, and use the correct name for the next search */ - sprintf(buf, "[name=%s],%s", name, tablename_val); - result = nis_list(buf, FOLLOW_LINKS | FOLLOW_PATH, NULL, NULL); + sprintf (buf, "[name=%s],%s", name, tablename_val); + result = nis_list (buf, FOLLOW_LINKS | FOLLOW_PATH, NULL, NULL); /* If we do not find it, try it as original name. But if the database is correct, we should find it in the first case, too */ - if ((result->status != NIS_SUCCESS && - result->status != NIS_S_SUCCESS) || - __type_of (result->objects.objects_val) != NIS_ENTRY_OBJ || - strcmp(result->objects.objects_val[0].EN_data.en_type, - "networks_tbl") != 0 || - result->objects.objects_val[0].EN_data.en_cols.en_cols_len < 3) - sprintf(buf, "[cname=%s],%s", name, tablename_val); + if ((result->status != NIS_SUCCESS && result->status != NIS_S_SUCCESS) + || __type_of (result->objects.objects_val) != NIS_ENTRY_OBJ + || strcmp (result->objects.objects_val[0].EN_data.en_type, + "networks_tbl") != 0 + || result->objects.objects_val[0].EN_data.en_cols.en_cols_len < 3) + sprintf (buf, "[cname=%s],%s", name, tablename_val); else - sprintf(buf, "[cname=%s],%s", NISENTRYVAL(0, 0, result), - tablename_val); + sprintf (buf, "[cname=%s],%s", NISENTRYVAL (0, 0, result), + tablename_val); nis_freeresult (result); - result = nis_list(buf, FOLLOW_LINKS | FOLLOW_PATH, NULL, NULL); + result = nis_list (buf, FOLLOW_LINKS | FOLLOW_PATH, NULL, NULL); retval = niserr2nss (result->status); if (retval != NSS_STATUS_SUCCESS) { if (retval == NSS_STATUS_TRYAGAIN) { - __set_errno (EAGAIN); + *errnop = errno; *herrnop = NETDB_INTERNAL; } nis_freeresult (result); return retval; } - parse_res = _nss_nisplus_parse_netent (result, network, buffer, buflen); + parse_res = _nss_nisplus_parse_netent (result, network, buffer, buflen, + errnop); nis_freeresult (result); @@ -343,7 +357,10 @@ _nss_nisplus_getnetbyname_r (const char *name, struct netent *network, *herrnop = NETDB_INTERNAL; if (parse_res == -1) - return NSS_STATUS_TRYAGAIN; + { + *errnop = ERANGE; + return NSS_STATUS_TRYAGAIN; + } else return NSS_STATUS_NOTFOUND; } @@ -352,12 +369,16 @@ _nss_nisplus_getnetbyname_r (const char *name, struct netent *network, /* XXX type is ignored, SUN's NIS+ table doesn't support it */ enum nss_status _nss_nisplus_getnetbyaddr_r (const unsigned long addr, const int type, - struct netent *network, - char *buffer, size_t buflen, int *herrnop) + struct netent *network, char *buffer, + size_t buflen, int *errnop, int *herrnop) { if (tablename_val == NULL) - if (_nss_create_tablename() != NSS_STATUS_SUCCESS) - return NSS_STATUS_UNAVAIL; + { + enum nss_status status = _nss_create_tablename (errnop); + + if (status != NSS_STATUS_SUCCESS) + return status; + } { int parse_res, retval; @@ -368,21 +389,22 @@ _nss_nisplus_getnetbyaddr_r (const unsigned long addr, const int type, in = inet_makeaddr (addr, 0); sprintf (buf, "[addr=%s],%s", inet_ntoa (in), tablename_val); - result = nis_list(buf, EXPAND_NAME, NULL, NULL); + result = nis_list (buf, EXPAND_NAME, NULL, NULL); retval = niserr2nss (result->status); if (retval != NSS_STATUS_SUCCESS) { if (retval == NSS_STATUS_TRYAGAIN) { - __set_errno (EAGAIN); + *errnop = errno; *herrnop = NETDB_INTERNAL; } nis_freeresult (result); return retval; } - parse_res = _nss_nisplus_parse_netent (result, network, buffer, buflen); + parse_res = _nss_nisplus_parse_netent (result, network, buffer, buflen, + errnop); nis_freeresult (result); @@ -391,7 +413,10 @@ _nss_nisplus_getnetbyaddr_r (const unsigned long addr, const int type, *herrnop = NETDB_INTERNAL; if (parse_res == -1) - return NSS_STATUS_TRYAGAIN; + { + *errnop = ERANGE; + return NSS_STATUS_TRYAGAIN; + } else return NSS_STATUS_NOTFOUND; } diff --git a/nis/nss_nisplus/nisplus-parser.c b/nis/nss_nisplus/nisplus-parser.c index b700fa66b4..fa4073e6d8 100644 --- a/nis/nss_nisplus/nisplus-parser.c +++ b/nis/nss_nisplus/nisplus-parser.c @@ -34,7 +34,7 @@ int _nss_nisplus_parse_pwent (nis_result *result, struct passwd *pw, - char *buffer, size_t buflen) + char *buffer, size_t buflen, int *errnop) { char *first_unused = buffer; size_t room_left = buflen; @@ -42,35 +42,35 @@ _nss_nisplus_parse_pwent (nis_result *result, struct passwd *pw, if (result == NULL) return 0; - if ((result->status != NIS_SUCCESS && result->status != NIS_S_SUCCESS) || - result->objects.objects_len != 1 || - __type_of (result->objects.objects_val) != NIS_ENTRY_OBJ || - strcmp(result->objects.objects_val->EN_data.en_type, - "passwd_tbl") != 0 || - result->objects.objects_val->EN_data.en_cols.en_cols_len < 7) + if ((result->status != NIS_SUCCESS && result->status != NIS_S_SUCCESS) + || result->objects.objects_len != 1 + || __type_of (result->objects.objects_val) != NIS_ENTRY_OBJ + || strcmp (result->objects.objects_val->EN_data.en_type, + "passwd_tbl") != 0 + || result->objects.objects_val->EN_data.en_cols.en_cols_len < 7) return 0; if (NISENTRYLEN (0, 0, result) >= room_left) { /* The line is too long for our buffer. */ no_more_room: - __set_errno (ERANGE); + *errnop = ERANGE; return -1; } - strncpy (first_unused, NISENTRYVAL(0, 0, result), + strncpy (first_unused, NISENTRYVAL (0, 0, result), NISENTRYLEN (0, 0, result)); - first_unused[NISENTRYLEN(0, 0, result)] = '\0'; + first_unused[NISENTRYLEN (0, 0, result)] = '\0'; pw->pw_name = first_unused; room_left -= (strlen (first_unused) +1); first_unused += strlen (first_unused) +1; - if (NISENTRYLEN(0, 1, result) >= room_left) + if (NISENTRYLEN (0, 1, result) >= room_left) goto no_more_room; - strncpy (first_unused, NISENTRYVAL(0, 1, result), + strncpy (first_unused, NISENTRYVAL (0, 1, result), NISENTRYLEN (0, 1, result)); - first_unused[NISENTRYLEN(0, 1, result)] = '\0'; + first_unused[NISENTRYLEN (0, 1, result)] = '\0'; pw->pw_passwd = first_unused; room_left -= (strlen (first_unused) +1); first_unused += strlen (first_unused) +1; @@ -80,17 +80,17 @@ _nss_nisplus_parse_pwent (nis_result *result, struct passwd *pw, strncpy (first_unused, NISENTRYVAL (0, 2, result), NISENTRYLEN (0, 2, result)); - first_unused[NISENTRYLEN(0, 2, result)] = '\0'; + first_unused[NISENTRYLEN (0, 2, result)] = '\0'; pw->pw_uid = atoi (first_unused); room_left -= (strlen (first_unused) +1); first_unused += strlen (first_unused) +1; - if (NISENTRYLEN(0, 3, result) >= room_left) + if (NISENTRYLEN (0, 3, result) >= room_left) goto no_more_room; - strncpy (first_unused, NISENTRYVAL(0, 3, result), + strncpy (first_unused, NISENTRYVAL (0, 3, result), NISENTRYLEN (0, 3, result)); - first_unused[NISENTRYLEN(0, 3, result)] = '\0'; + first_unused[NISENTRYLEN (0, 3, result)] = '\0'; pw->pw_gid = atoi (first_unused); room_left -= (strlen (first_unused) +1); first_unused += strlen (first_unused) +1; @@ -98,24 +98,24 @@ _nss_nisplus_parse_pwent (nis_result *result, struct passwd *pw, if (NISENTRYLEN(0, 4, result) >= room_left) goto no_more_room; - strncpy (first_unused, NISENTRYVAL(0, 4, result), + strncpy (first_unused, NISENTRYVAL (0, 4, result), NISENTRYLEN (0, 4, result)); - first_unused[NISENTRYLEN(0, 4, result)] = '\0'; + first_unused[NISENTRYLEN (0, 4, result)] = '\0'; pw->pw_gecos = first_unused; room_left -= (strlen (first_unused) +1); first_unused += strlen (first_unused) +1; - if (NISENTRYLEN(0, 5, result) >= room_left) + if (NISENTRYLEN (0, 5, result) >= room_left) goto no_more_room; strncpy (first_unused, NISENTRYVAL (0, 5, result), NISENTRYLEN (0, 5, result)); - first_unused[NISENTRYLEN(0, 5, result)] = '\0'; + first_unused[NISENTRYLEN (0, 5, result)] = '\0'; pw->pw_dir = first_unused; room_left -= (strlen (first_unused) +1); first_unused += strlen (first_unused) +1; - if (NISENTRYLEN(0, 6, result) >= room_left) + if (NISENTRYLEN (0, 6, result) >= room_left) goto no_more_room; strncpy (first_unused, NISENTRYVAL (0, 6, result), @@ -129,8 +129,8 @@ _nss_nisplus_parse_pwent (nis_result *result, struct passwd *pw, } int -_nss_nisplus_parse_grent (nis_result *result, u_long entry, - struct group *gr, char *buffer, size_t buflen) +_nss_nisplus_parse_grent (nis_result *result, u_long entry, struct group *gr, + char *buffer, size_t buflen, int *errnop) { char *first_unused = buffer; size_t room_left = buflen; @@ -140,18 +140,18 @@ _nss_nisplus_parse_grent (nis_result *result, u_long entry, if (result == NULL) return 0; - if ((result->status != NIS_SUCCESS && result->status != NIS_S_SUCCESS) || - __type_of(result->objects.objects_val) != NIS_ENTRY_OBJ || - strcmp (result->objects.objects_val[entry].EN_data.en_type, - "group_tbl") != 0 || - result->objects.objects_val[entry].EN_data.en_cols.en_cols_len < 4) + if ((result->status != NIS_SUCCESS && result->status != NIS_S_SUCCESS) + || __type_of(result->objects.objects_val) != NIS_ENTRY_OBJ + || strcmp (result->objects.objects_val[entry].EN_data.en_type, + "group_tbl") != 0 + || result->objects.objects_val[entry].EN_data.en_cols.en_cols_len < 4) return 0; if (NISENTRYLEN (entry, 0, result) >= room_left) { /* The line is too long for our buffer. */ no_more_room: - __set_errno (ERANGE); + *errnop = ERANGE; return -1; } @@ -240,7 +240,7 @@ _nss_nisplus_parse_grent (nis_result *result, u_long entry, int _nss_nisplus_parse_spent (nis_result *result, struct spwd *sp, - char *buffer, size_t buflen) + char *buffer, size_t buflen, int *errnop) { char *first_unused = buffer; size_t room_left = buflen; @@ -248,35 +248,35 @@ _nss_nisplus_parse_spent (nis_result *result, struct spwd *sp, if (result == NULL) return 0; - if ((result->status != NIS_SUCCESS && result->status != NIS_S_SUCCESS) || - result->objects.objects_len != 1 || - __type_of(result->objects.objects_val) != NIS_ENTRY_OBJ || - strcmp (result->objects.objects_val->EN_data.en_type, - "passwd_tbl") != 0 || - result->objects.objects_val[0].EN_data.en_cols.en_cols_len < 8) + if ((result->status != NIS_SUCCESS && result->status != NIS_S_SUCCESS) + || result->objects.objects_len != 1 + || __type_of(result->objects.objects_val) != NIS_ENTRY_OBJ + || strcmp (result->objects.objects_val->EN_data.en_type, + "passwd_tbl") != 0 + || result->objects.objects_val[0].EN_data.en_cols.en_cols_len < 8) return 0; - if (NISENTRYLEN(0, 0, result) >= room_left) + if (NISENTRYLEN (0, 0, result) >= room_left) { /* The line is too long for our buffer. */ no_more_room: - __set_errno (ERANGE); + *errnop = ERANGE; return -1; } strncpy (first_unused, NISENTRYVAL (0, 0, result), NISENTRYLEN (0, 0, result)); - first_unused[NISENTRYLEN(0, 0, result)] = '\0'; + first_unused[NISENTRYLEN (0, 0, result)] = '\0'; sp->sp_namp = first_unused; room_left -= (strlen (first_unused) +1); first_unused += strlen (first_unused) +1; - if (NISENTRYLEN(0, 1, result) >= room_left) + if (NISENTRYLEN (0, 1, result) >= room_left) goto no_more_room; strncpy (first_unused, NISENTRYVAL (0, 1, result), NISENTRYLEN (0, 1, result)); - first_unused[NISENTRYLEN(0, 1, result)] = '\0'; + first_unused[NISENTRYLEN (0, 1, result)] = '\0'; sp->sp_pwdp = first_unused; room_left -= (strlen (first_unused) +1); first_unused += strlen (first_unused) +1; @@ -300,40 +300,40 @@ _nss_nisplus_parse_spent (nis_result *result, struct spwd *sp, if (cp == NULL) return 0; *cp++ = '\0'; - sp->sp_min = atol(line); + sp->sp_min = atol (line); line = cp; cp = strchr (line, ':'); if (cp == NULL) return 0; *cp++ = '\0'; - sp->sp_max = atol(line); + sp->sp_max = atol (line); line = cp; cp = strchr (line, ':'); if (cp == NULL) return 0; *cp++ = '\0'; - sp->sp_warn = atol(line); + sp->sp_warn = atol (line); line = cp; cp = strchr (line, ':'); if (cp == NULL) return 0; *cp++ = '\0'; - sp->sp_inact = atol(line); + sp->sp_inact = atol (line); line = cp; cp = strchr (line, ':'); if (cp == NULL) return 0; *cp++ = '\0'; - sp->sp_expire = atol(line); + sp->sp_expire = atol (line); line = cp; if (line == NULL) return 0; - sp->sp_flag = atol(line); + sp->sp_flag = atol (line); } return 1; diff --git a/nis/nss_nisplus/nisplus-proto.c b/nis/nss_nisplus/nisplus-proto.c index 2cbd9fe2fa..262276f301 100644 --- a/nis/nss_nisplus/nisplus-proto.c +++ b/nis/nss_nisplus/nisplus-proto.c @@ -41,7 +41,7 @@ static u_long tablename_len = 0; static int _nss_nisplus_parse_protoent (nis_result * result, struct protoent *proto, - char *buffer, size_t buflen) + char *buffer, size_t buflen, int *errnop) { char *first_unused = buffer; size_t room_left = buflen; @@ -51,9 +51,10 @@ _nss_nisplus_parse_protoent (nis_result * result, struct protoent *proto, if (result == NULL) return 0; - if ((result->status != NIS_SUCCESS && result->status != NIS_S_SUCCESS) || - __type_of (NIS_RES_OBJECT (result)) != NIS_ENTRY_OBJ || - strcmp (NIS_RES_OBJECT (result)->EN_data.en_type, "protocols_tbl") != 0 + if ((result->status != NIS_SUCCESS && result->status != NIS_S_SUCCESS) + || __type_of (NIS_RES_OBJECT (result)) != NIS_ENTRY_OBJ + || strcmp (NIS_RES_OBJECT (result)->EN_data.en_type, + "protocols_tbl") != 0 || NIS_RES_OBJECT (result)->EN_data.en_cols.en_cols_len < 3) return 0; @@ -61,7 +62,7 @@ _nss_nisplus_parse_protoent (nis_result * result, struct protoent *proto, if (NISENTRYLEN (0, 0, result) + 1 > room_left) { no_more_room: - __set_errno (ERANGE); + *errnop = ERANGE; return -1; } strncpy (first_unused, NISENTRYVAL (0, 0, result), @@ -101,7 +102,7 @@ _nss_nisplus_parse_protoent (nis_result * result, struct protoent *proto, proto->p_aliases = (char **) first_unused; if (room_left < sizeof (char *)) goto no_more_room; - room_left -= (sizeof (char *)); + room_left -= sizeof (char *); proto->p_aliases[0] = NULL; i = 0; @@ -136,7 +137,7 @@ _nss_nisplus_parse_protoent (nis_result * result, struct protoent *proto, } static enum nss_status -_nss_create_tablename (void) +_nss_create_tablename (int *errnop) { if (tablename_val == NULL) { @@ -147,7 +148,10 @@ _nss_create_tablename (void) p = __stpcpy (p, nis_local_directory ()); tablename_val = __strdup (buf); if (tablename_val == NULL) - return NSS_STATUS_TRYAGAIN; + { + *errnop = errno; + return NSS_STATUS_TRYAGAIN; + } tablename_len = strlen (tablename_val); } return NSS_STATUS_SUCCESS; @@ -165,7 +169,10 @@ _nss_nisplus_setprotoent (void) result = NULL; if (tablename_val == NULL) - status = _nss_create_tablename (); + { + int err; + status = _nss_create_tablename (&err); + } __libc_lock_unlock (lock); @@ -188,7 +195,7 @@ _nss_nisplus_endprotoent (void) static enum nss_status internal_nisplus_getprotoent_r (struct protoent *proto, char *buffer, - size_t buflen) + size_t buflen, int *errnop) { int parse_res; @@ -201,8 +208,12 @@ internal_nisplus_getprotoent_r (struct protoent *proto, char *buffer, { saved_res = NULL; if (tablename_val == NULL) - if (_nss_create_tablename () != NSS_STATUS_SUCCESS) - return NSS_STATUS_UNAVAIL; + { + 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) @@ -223,11 +234,13 @@ internal_nisplus_getprotoent_r (struct protoent *proto, char *buffer, } } - if ((parse_res = _nss_nisplus_parse_protoent (result, proto, buffer, - buflen)) == -1) + parse_res = _nss_nisplus_parse_protoent (result, proto, buffer, + buflen, errnop); + if (parse_res == -1) { nis_freeresult (result); result = saved_res; + *errnop = ERANGE; return NSS_STATUS_TRYAGAIN; } else @@ -243,13 +256,13 @@ internal_nisplus_getprotoent_r (struct protoent *proto, char *buffer, enum nss_status _nss_nisplus_getprotoent_r (struct protoent *result, char *buffer, - size_t buflen) + size_t buflen, int *errnop) { int status; __libc_lock_lock (lock); - status = internal_nisplus_getprotoent_r (result, buffer, buflen); + status = internal_nisplus_getprotoent_r (result, buffer, buflen, errnop); __libc_lock_unlock (lock); @@ -258,13 +271,17 @@ _nss_nisplus_getprotoent_r (struct protoent *result, char *buffer, enum nss_status _nss_nisplus_getprotobyname_r (const char *name, struct protoent *proto, - char *buffer, size_t buflen) + char *buffer, size_t buflen, int *errnop) { int parse_res; if (tablename_val == NULL) - if (_nss_create_tablename () != NSS_STATUS_SUCCESS) - return NSS_STATUS_UNAVAIL; + { + enum nss_status status = _nss_create_tablename (errnop); + + if (status != NSS_STATUS_SUCCESS) + return status; + } if (name == NULL) return NSS_STATUS_NOTFOUND; @@ -280,12 +297,11 @@ _nss_nisplus_getprotobyname_r (const char *name, struct protoent *proto, /* If we do not find it, try it as original name. But if the database is correct, we should find it in the first case, too */ - if ((result->status != NIS_SUCCESS && - result->status != NIS_S_SUCCESS) || - __type_of (result->objects.objects_val) != NIS_ENTRY_OBJ || - strcmp (result->objects.objects_val->EN_data.en_type, - "protocols_tbl") != 0 || - result->objects.objects_val->EN_data.en_cols.en_cols_len < 3) + if ((result->status != NIS_SUCCESS && result->status != NIS_S_SUCCESS) + || __type_of (result->objects.objects_val) != NIS_ENTRY_OBJ + || strcmp (result->objects.objects_val->EN_data.en_type, + "protocols_tbl") != 0 + || result->objects.objects_val->EN_data.en_cols.en_cols_len < 3) sprintf (buf, "[cname=%s],%s", name, tablename_val); else sprintf (buf, "[cname=%s],%s", NISENTRYVAL (0, 0, result), @@ -302,12 +318,16 @@ _nss_nisplus_getprotobyname_r (const char *name, struct protoent *proto, return status; } - parse_res = _nss_nisplus_parse_protoent (result, proto, buffer, buflen); + parse_res = _nss_nisplus_parse_protoent (result, proto, buffer, buflen, + errnop); nis_freeresult (result); if (parse_res == -1) - return NSS_STATUS_TRYAGAIN; + { + *errnop = ERANGE; + return NSS_STATUS_TRYAGAIN; + } if (parse_res) return NSS_STATUS_SUCCESS; @@ -317,11 +337,16 @@ _nss_nisplus_getprotobyname_r (const char *name, struct protoent *proto, enum nss_status _nss_nisplus_getprotobynumber_r (const int number, struct protoent *proto, - char *buffer, size_t buflen) + char *buffer, size_t buflen, int *errnop) { if (tablename_val == NULL) - if (_nss_create_tablename () != NSS_STATUS_SUCCESS) - return NSS_STATUS_UNAVAIL; + { + enum nss_status status = _nss_create_tablename (errnop); + + if (status != NSS_STATUS_SUCCESS) + return status; + } + { int parse_res; nis_result *result; @@ -339,12 +364,16 @@ _nss_nisplus_getprotobynumber_r (const int number, struct protoent *proto, return status; } - parse_res = _nss_nisplus_parse_protoent (result, proto, buffer, buflen); + parse_res = _nss_nisplus_parse_protoent (result, proto, buffer, buflen, + errnop); nis_freeresult (result); if (parse_res == -1) - return NSS_STATUS_TRYAGAIN; + { + *errnop = ERANGE; + return NSS_STATUS_TRYAGAIN; + } if (parse_res) return NSS_STATUS_SUCCESS; diff --git a/nis/nss_nisplus/nisplus-publickey.c b/nis/nss_nisplus/nisplus-publickey.c index aa2a6f0c3a..24d217b804 100644 --- a/nis/nss_nisplus/nisplus-publickey.c +++ b/nis/nss_nisplus/nisplus-publickey.c @@ -32,7 +32,7 @@ extern int xdecrypt (char *, char *); /* If we haven't found the entry, we give a SUCCESS and an empty key back. */ enum nss_status -_nss_nisplus_getpublickey (const char *netname, char *pkey) +_nss_nisplus_getpublickey (const char *netname, char *pkey, int *errnop) { nis_result *res; enum nss_status retval; @@ -45,7 +45,7 @@ _nss_nisplus_getpublickey (const char *netname, char *pkey) if (netname == NULL) { - __set_errno (EINVAL); + *errnop = EINVAL; return NSS_STATUS_UNAVAIL; } @@ -72,7 +72,7 @@ _nss_nisplus_getpublickey (const char *netname, char *pkey) if (retval != NSS_STATUS_SUCCESS) { if (retval == NSS_STATUS_TRYAGAIN) - __set_errno (EAGAIN); + *errnop = errno; if (res->status == NIS_NOTFOUND) retval = NSS_STATUS_SUCCESS; nis_freeresult (res); @@ -103,7 +103,8 @@ _nss_nisplus_getpublickey (const char *netname, char *pkey) } enum nss_status -_nss_nisplus_getsecretkey (const char *netname, char *skey, char *passwd) +_nss_nisplus_getsecretkey (const char *netname, char *skey, char *passwd, + int *errnop) { nis_result *res; enum nss_status retval; @@ -116,7 +117,7 @@ _nss_nisplus_getsecretkey (const char *netname, char *skey, char *passwd) if (netname == NULL) { - __set_errno (EINVAL); + *errnop = EINVAL; return NSS_STATUS_UNAVAIL; } @@ -143,7 +144,7 @@ _nss_nisplus_getsecretkey (const char *netname, char *skey, char *passwd) if (retval != NSS_STATUS_SUCCESS) { if (retval == NSS_STATUS_TRYAGAIN) - __set_errno (EAGAIN); + *errnop = errno; nis_freeresult (res); return retval; } @@ -183,7 +184,8 @@ _nss_nisplus_getsecretkey (const char *netname, char *skey, char *passwd) /* Parse information from the passed string. The format of the string passed is gid,grp,grp, ... */ static enum nss_status -parse_grp_str (const char *s, gid_t *gidp, int *gidlenp, gid_t *gidlist) +parse_grp_str (const char *s, gid_t *gidp, int *gidlenp, gid_t *gidlist, + int *errnop) { int gidlen; @@ -209,7 +211,7 @@ parse_grp_str (const char *s, gid_t *gidp, int *gidlenp, gid_t *gidlist) enum nss_status _nss_nisplus_netname2user (char netname[MAXNETNAMELEN + 1], uid_t *uidp, - gid_t *gidp, int *gidlenp, gid_t *gidlist) + gid_t *gidp, int *gidlenp, gid_t *gidlist, int *errnop) { char *domain; nis_result *res; @@ -223,7 +225,7 @@ _nss_nisplus_netname2user (char netname[MAXNETNAMELEN + 1], uid_t *uidp, if (! domain) return NSS_STATUS_UNAVAIL; - domain++; /* skip '@' */ + ++domain; /* skip '@' */ /* 2. Get user's nisplus principal name. */ if ((strlen (netname) + strlen (domain)+45) > @@ -260,6 +262,7 @@ _nss_nisplus_netname2user (char netname[MAXNETNAMELEN + 1], uid_t *uidp, syslog (LOG_ERR, _("netname2user: (nis+ lookup): %s\n"), nis_sperrno (res->status)); nis_freeresult (res); + *errnop = errno; return NSS_STATUS_TRYAGAIN; default: syslog (LOG_ERR, _("netname2user: (nis+ lookup): %s\n"), @@ -269,16 +272,14 @@ _nss_nisplus_netname2user (char netname[MAXNETNAMELEN + 1], uid_t *uidp, } if (res->objects.objects_len > 1) - { - /* - * A netname belonging to more than one principal? - * Something wrong with cred table. should be unique. - * Warn user and continue. - */ - syslog (LOG_ALERT, - _("netname2user: DES entry for %s in directory %s not unique"), - netname, domain); - } + /* + * A netname belonging to more than one principal? + * Something wrong with cred table. should be unique. + * Warn user and continue. + */ + syslog (LOG_ALERT, + _("netname2user: DES entry for %s in directory %s not unique"), + netname, domain); len = ENTRY_LEN (res->objects.objects_val, 0); strncpy (principal, ENTRY_VAL (res->objects.objects_val, 0), len); @@ -326,6 +327,7 @@ _nss_nisplus_netname2user (char netname[MAXNETNAMELEN + 1], uid_t *uidp, syslog (LOG_ERR, _("netname2user: (nis+ lookup): %s\n"), nis_sperrno (res->status)); nis_freeresult (res); + *errnop = errno; return NSS_STATUS_TRYAGAIN; case NIS_SUCCESS: case NIS_S_SUCCESS: @@ -338,16 +340,14 @@ _nss_nisplus_netname2user (char netname[MAXNETNAMELEN + 1], uid_t *uidp, } if (res->objects.objects_len > 1) - { - /* - * A principal can have more than one LOCAL entry? - * Something wrong with cred table. - * Warn user and continue. - */ - syslog (LOG_ALERT, - _("netname2user: LOCAL entry for %s in directory %s not unique"), - netname, domain); - } + /* + * A principal can have more than one LOCAL entry? + * Something wrong with cred table. + * Warn user and continue. + */ + syslog (LOG_ALERT, + _("netname2user: LOCAL entry for %s in directory %s not unique"), + netname, domain); /* Fetch the uid */ *uidp = atoi (ENTRY_VAL (res->objects.objects_val, 2)); @@ -358,7 +358,7 @@ _nss_nisplus_netname2user (char netname[MAXNETNAMELEN + 1], uid_t *uidp, } parse_grp_str (ENTRY_VAL (res->objects.objects_val, 3), - gidp, gidlenp, gidlist); + gidp, gidlenp, gidlist, errnop); nis_freeresult (res); return NSS_STATUS_SUCCESS; diff --git a/nis/nss_nisplus/nisplus-pwd.c b/nis/nss_nisplus/nisplus-pwd.c index 3974defa47..18114ad7e5 100644 --- a/nis/nss_nisplus/nisplus-pwd.c +++ b/nis/nss_nisplus/nisplus-pwd.c @@ -33,10 +33,10 @@ static nis_name tablename_val = NULL; static u_long tablename_len = 0; extern int _nss_nisplus_parse_pwent (nis_result *res, struct passwd *pw, - char *buffer, size_t buflen); + char *buffer, size_t buflen, int *errnop); static enum nss_status -_nss_create_tablename (void) +_nss_create_tablename (int *errnop) { if (tablename_val == NULL) { @@ -47,7 +47,10 @@ _nss_create_tablename (void) p = __stpcpy (p, nis_local_directory ()); tablename_val = __strdup (buf); if (tablename_val == NULL) - return NSS_STATUS_TRYAGAIN; + { + *errnop = errno; + return NSS_STATUS_TRYAGAIN; + } tablename_len = strlen (tablename_val); } return NSS_STATUS_SUCCESS; @@ -58,6 +61,7 @@ enum nss_status _nss_nisplus_setpwent (void) { enum nss_status status = NSS_STATUS_SUCCESS; + int err; __libc_lock_lock (lock); @@ -66,7 +70,7 @@ _nss_nisplus_setpwent (void) result = NULL; if (tablename_val == NULL) - status = _nss_create_tablename (); + status = _nss_create_tablename (&err); __libc_lock_unlock (lock); @@ -88,7 +92,8 @@ _nss_nisplus_endpwent (void) } static enum nss_status -internal_nisplus_getpwent_r (struct passwd *pw, char *buffer, size_t buflen) +internal_nisplus_getpwent_r (struct passwd *pw, char *buffer, size_t buflen, + int *errnop) { int parse_res; @@ -101,10 +106,14 @@ internal_nisplus_getpwent_r (struct passwd *pw, char *buffer, size_t buflen) { saved_res = NULL; if (tablename_val == NULL) - if (_nss_create_tablename () != NSS_STATUS_SUCCESS) - return NSS_STATUS_UNAVAIL; + { + enum nss_status status = _nss_create_tablename (errnop); + + if (status != NSS_STATUS_SUCCESS) + return status; + } - result = nis_first_entry(tablename_val); + result = nis_first_entry (tablename_val); if (niserr2nss (result->status) != NSS_STATUS_SUCCESS) return niserr2nss (result->status); } @@ -113,7 +122,7 @@ internal_nisplus_getpwent_r (struct passwd *pw, char *buffer, size_t buflen) nis_result *res; saved_res = result; - res = nis_next_entry(tablename_val, &result->cookie); + res = nis_next_entry (tablename_val, &result->cookie); result = res; if (niserr2nss (result->status) != NSS_STATUS_SUCCESS) { @@ -122,11 +131,13 @@ internal_nisplus_getpwent_r (struct passwd *pw, char *buffer, size_t buflen) } } - if ((parse_res = _nss_nisplus_parse_pwent (result, pw, buffer, - buflen)) == -1) + parse_res = _nss_nisplus_parse_pwent (result, pw, buffer, + buflen, errnop); + if (parse_res == -1) { nis_freeresult (result); result = saved_res; + *errnop = ERANGE; return NSS_STATUS_TRYAGAIN; } else @@ -140,13 +151,14 @@ internal_nisplus_getpwent_r (struct passwd *pw, char *buffer, size_t buflen) } enum nss_status -_nss_nisplus_getpwent_r (struct passwd *result, char *buffer, size_t buflen) +_nss_nisplus_getpwent_r (struct passwd *result, char *buffer, size_t buflen, + int *errnop) { int status; __libc_lock_lock (lock); - status = internal_nisplus_getpwent_r (result, buffer, buflen); + status = internal_nisplus_getpwent_r (result, buffer, buflen, errnop); __libc_lock_unlock (lock); @@ -155,13 +167,17 @@ _nss_nisplus_getpwent_r (struct passwd *result, char *buffer, size_t buflen) enum nss_status _nss_nisplus_getpwnam_r (const char *name, struct passwd *pw, - char *buffer, size_t buflen) + char *buffer, size_t buflen, int *errnop) { int parse_res; if (tablename_val == NULL) - if (_nss_create_tablename () != NSS_STATUS_SUCCESS) - return NSS_STATUS_UNAVAIL; + { + enum nss_status status = _nss_create_tablename (errnop); + + if (status != NSS_STATUS_SUCCESS) + return status; + } if (name == NULL || strlen (name) > 8) return NSS_STATUS_NOTFOUND; @@ -170,7 +186,7 @@ _nss_nisplus_getpwnam_r (const char *name, struct passwd *pw, nis_result *result; char buf[strlen (name) + 24 + tablename_len]; - sprintf(buf, "[name=%s],%s", name, tablename_val); + sprintf (buf, "[name=%s],%s", name, tablename_val); result = nis_list(buf, FOLLOW_PATH | FOLLOW_LINKS, NULL, NULL); @@ -182,12 +198,16 @@ _nss_nisplus_getpwnam_r (const char *name, struct passwd *pw, return status; } - parse_res = _nss_nisplus_parse_pwent (result, pw, buffer, buflen); + parse_res = _nss_nisplus_parse_pwent (result, pw, buffer, buflen, + errnop); nis_freeresult (result); if (parse_res == -1) - return NSS_STATUS_TRYAGAIN; + { + *errnop = ERANGE; + return NSS_STATUS_TRYAGAIN; + } if (parse_res) return NSS_STATUS_SUCCESS; @@ -198,17 +218,22 @@ _nss_nisplus_getpwnam_r (const char *name, struct passwd *pw, enum nss_status _nss_nisplus_getpwuid_r (const uid_t uid, struct passwd *pw, - char *buffer, size_t buflen) + char *buffer, size_t buflen, int *errnop) { if (tablename_val == NULL) - if (_nss_create_tablename () != NSS_STATUS_SUCCESS) - return NSS_STATUS_UNAVAIL; + { + enum nss_status status = _nss_create_tablename (errnop); + + if (status != NSS_STATUS_SUCCESS) + return status; + } + { int parse_res; nis_result *result; char buf[100 + tablename_len]; - sprintf(buf, "[uid=%d],%s", uid, tablename_val); + sprintf (buf, "[uid=%d],%s", uid, tablename_val); result = nis_list(buf, FOLLOW_PATH | FOLLOW_LINKS, NULL, NULL); @@ -220,12 +245,15 @@ _nss_nisplus_getpwuid_r (const uid_t uid, struct passwd *pw, return status; } - parse_res = _nss_nisplus_parse_pwent (result, pw, buffer, buflen); + parse_res = _nss_nisplus_parse_pwent (result, pw, buffer, buflen, errnop); nis_freeresult (result); if (parse_res == -1) - return NSS_STATUS_TRYAGAIN; + { + *errnop = ERANGE; + return NSS_STATUS_TRYAGAIN; + } if (parse_res) return NSS_STATUS_SUCCESS; diff --git a/nis/nss_nisplus/nisplus-rpc.c b/nis/nss_nisplus/nisplus-rpc.c index 77a7248305..452fb4cc5e 100644 --- a/nis/nss_nisplus/nisplus-rpc.c +++ b/nis/nss_nisplus/nisplus-rpc.c @@ -41,7 +41,7 @@ static u_long tablename_len = 0; static int _nss_nisplus_parse_rpcent (nis_result *result, struct rpcent *rpc, - char *buffer, size_t buflen) + char *buffer, size_t buflen, int *errnop) { char *first_unused = buffer; size_t room_left = buflen; @@ -52,25 +52,25 @@ _nss_nisplus_parse_rpcent (nis_result *result, struct rpcent *rpc, if (result == NULL) return 0; - if ((result->status != NIS_SUCCESS && result->status != NIS_S_SUCCESS) || - __type_of (result->objects.objects_val) != NIS_ENTRY_OBJ || - strcmp(result->objects.objects_val[0].EN_data.en_type, - "rpc_tbl") != 0 || - result->objects.objects_val[0].EN_data.en_cols.en_cols_len < 3) + if ((result->status != NIS_SUCCESS && result->status != NIS_S_SUCCESS) + || __type_of (result->objects.objects_val) != NIS_ENTRY_OBJ + || strcmp (result->objects.objects_val[0].EN_data.en_type, + "rpc_tbl") != 0 + || result->objects.objects_val[0].EN_data.en_cols.en_cols_len < 3) return 0; if (NISENTRYLEN (0, 0, result) >= room_left) { no_more_room: - __set_errno (ERANGE); + *errnop = ERANGE; return -1; } strncpy (first_unused, NISENTRYVAL (0, 0, result), NISENTRYLEN (0, 0, result)); first_unused[NISENTRYLEN (0, 0, result)] = '\0'; rpc->r_name = first_unused; - room_left -= (strlen (first_unused) +1); - first_unused += strlen (first_unused) +1; + room_left -= strlen (first_unused) + 1; + first_unused += strlen (first_unused) + 1; rpc->r_number = atoi (NISENTRYVAL (0, 2, result)); p = first_unused; @@ -98,7 +98,7 @@ _nss_nisplus_parse_rpcent (nis_result *result, struct rpcent *rpc, rpc->r_aliases = (char **) first_unused; if (room_left < sizeof (char *)) goto no_more_room; - room_left -= (sizeof (char *)); + room_left -= sizeof (char *); rpc->r_aliases[0] = NULL; i = 0; @@ -137,7 +137,7 @@ _nss_nisplus_parse_rpcent (nis_result *result, struct rpcent *rpc, } static enum nss_status -_nss_create_tablename (void) +_nss_create_tablename (int *errnop) { if (tablename_val == NULL) { @@ -148,7 +148,10 @@ _nss_create_tablename (void) p = __stpcpy (p, nis_local_directory ()); tablename_val = __strdup (buf); if (tablename_val == NULL) - return NSS_STATUS_TRYAGAIN; + { + *errnop = errno; + return NSS_STATUS_TRYAGAIN; + } tablename_len = strlen (tablename_val); } return NSS_STATUS_SUCCESS; @@ -159,6 +162,7 @@ enum nss_status _nss_nisplus_setrpcent (void) { enum nss_status status = NSS_STATUS_SUCCESS; + int err; __libc_lock_lock (lock); @@ -167,7 +171,7 @@ _nss_nisplus_setrpcent (void) result = NULL; if (tablename_val == NULL) - status = _nss_create_tablename (); + status = _nss_create_tablename (&err); __libc_lock_unlock (lock); @@ -190,7 +194,7 @@ _nss_nisplus_endrpcent (void) static enum nss_status internal_nisplus_getrpcent_r (struct rpcent *rpc, char *buffer, - size_t buflen) + size_t buflen, int *errnop) { int parse_res; @@ -203,10 +207,14 @@ internal_nisplus_getrpcent_r (struct rpcent *rpc, char *buffer, { saved_res = NULL; if (tablename_val == NULL) - if (_nss_create_tablename () != NSS_STATUS_SUCCESS) - return NSS_STATUS_UNAVAIL; + { + enum nss_status status = _nss_create_tablename (errnop); + + if (status != NSS_STATUS_SUCCESS) + return status; + } - result = nis_first_entry(tablename_val); + result = nis_first_entry (tablename_val); if (niserr2nss (result->status) != NSS_STATUS_SUCCESS) return niserr2nss (result->status); } @@ -224,11 +232,13 @@ internal_nisplus_getrpcent_r (struct rpcent *rpc, char *buffer, } } - if ((parse_res = _nss_nisplus_parse_rpcent (result, rpc, buffer, - buflen)) == -1) + parse_res = _nss_nisplus_parse_rpcent (result, rpc, buffer, + buflen, errnop); + if (parse_res == -1) { nis_freeresult (result); result = saved_res; + *errnop = ERANGE; return NSS_STATUS_TRYAGAIN; } else @@ -243,13 +253,13 @@ internal_nisplus_getrpcent_r (struct rpcent *rpc, char *buffer, enum nss_status _nss_nisplus_getrpcent_r (struct rpcent *result, char *buffer, - size_t buflen) + size_t buflen, int *errnop) { int status; __libc_lock_lock (lock); - status = internal_nisplus_getrpcent_r (result, buffer, buflen); + status = internal_nisplus_getrpcent_r (result, buffer, buflen, errnop); __libc_lock_unlock (lock); @@ -258,13 +268,17 @@ _nss_nisplus_getrpcent_r (struct rpcent *result, char *buffer, enum nss_status _nss_nisplus_getrpcbyname_r (const char *name, struct rpcent *rpc, - char *buffer, size_t buflen) + char *buffer, size_t buflen, int *errnop) { int parse_res; if (tablename_val == NULL) - if (_nss_create_tablename () != NSS_STATUS_SUCCESS) - return NSS_STATUS_UNAVAIL; + { + enum nss_status status = _nss_create_tablename (errnop); + + if (status != NSS_STATUS_SUCCESS) + return status; + } if (name == NULL) return NSS_STATUS_NOTFOUND; @@ -280,19 +294,18 @@ _nss_nisplus_getrpcbyname_r (const char *name, struct rpcent *rpc, /* If we do not find it, try it as original name. But if the database is correct, we should find it in the first case, too */ - if ((result->status != NIS_SUCCESS && - result->status != NIS_S_SUCCESS) || - __type_of (result->objects.objects_val) != NIS_ENTRY_OBJ || - strcmp (result->objects.objects_val->EN_data.en_type, - "rpc_tbl") != 0 || - result->objects.objects_val->EN_data.en_cols.en_cols_len < 3) + if ((result->status != NIS_SUCCESS && result->status != NIS_S_SUCCESS) + || __type_of (result->objects.objects_val) != NIS_ENTRY_OBJ + || strcmp (result->objects.objects_val->EN_data.en_type, + "rpc_tbl") != 0 + || result->objects.objects_val->EN_data.en_cols.en_cols_len < 3) sprintf (buf, "[cname=%s],%s", name, tablename_val); else - sprintf (buf, "[cname=%s],%s", NISENTRYVAL(0, 0, result), + sprintf (buf, "[cname=%s],%s", NISENTRYVAL (0, 0, result), tablename_val); nis_freeresult (result); - result = nis_list(buf, FOLLOW_PATH | FOLLOW_LINKS , NULL, NULL); + result = nis_list (buf, FOLLOW_PATH | FOLLOW_LINKS , NULL, NULL); if (niserr2nss (result->status) != NSS_STATUS_SUCCESS) { @@ -302,12 +315,16 @@ _nss_nisplus_getrpcbyname_r (const char *name, struct rpcent *rpc, return status; } - parse_res = _nss_nisplus_parse_rpcent (result, rpc, buffer, buflen); + parse_res = _nss_nisplus_parse_rpcent (result, rpc, buffer, buflen, + errnop); nis_freeresult (result); if (parse_res == -1) - return NSS_STATUS_TRYAGAIN; + { + *errnop = ERANGE; + return NSS_STATUS_TRYAGAIN; + } if (parse_res) return NSS_STATUS_SUCCESS; @@ -318,11 +335,15 @@ _nss_nisplus_getrpcbyname_r (const char *name, struct rpcent *rpc, enum nss_status _nss_nisplus_getrpcbynumber_r (const int number, struct rpcent *rpc, - char *buffer, size_t buflen) + char *buffer, size_t buflen, int *errnop) { if (tablename_val == NULL) - if (_nss_create_tablename () != NSS_STATUS_SUCCESS) - return NSS_STATUS_UNAVAIL; + { + enum nss_status status = _nss_create_tablename (errnop); + + if (status != NSS_STATUS_SUCCESS) + return status; + } { int parse_res; @@ -341,12 +362,16 @@ _nss_nisplus_getrpcbynumber_r (const int number, struct rpcent *rpc, return status; } - parse_res = _nss_nisplus_parse_rpcent (result, rpc, buffer, buflen); + parse_res = _nss_nisplus_parse_rpcent (result, rpc, buffer, buflen, + errnop); nis_freeresult (result); if (parse_res == -1) - return NSS_STATUS_TRYAGAIN; + { + *errnop = ERANGE; + return NSS_STATUS_TRYAGAIN; + } if (parse_res) return NSS_STATUS_SUCCESS; diff --git a/nis/nss_nisplus/nisplus-service.c b/nis/nss_nisplus/nisplus-service.c index 95a8cfa74b..1cb1aec8d7 100644 --- a/nis/nss_nisplus/nisplus-service.c +++ b/nis/nss_nisplus/nisplus-service.c @@ -41,7 +41,7 @@ static u_long tablename_len = 0; static int _nss_nisplus_parse_servent (nis_result *result, struct servent *serv, - char *buffer, size_t buflen) + char *buffer, size_t buflen, int *errnop) { char *first_unused = buffer; size_t room_left = buflen; @@ -51,17 +51,17 @@ _nss_nisplus_parse_servent (nis_result *result, struct servent *serv, if (result == NULL) return 0; - if ((result->status != NIS_SUCCESS && result->status != NIS_S_SUCCESS) || - __type_of (result->objects.objects_val) != NIS_ENTRY_OBJ || - strcmp (result->objects.objects_val->EN_data.en_type, - "services_tbl") != 0 || - result->objects.objects_val->EN_data.en_cols.en_cols_len < 4) + if ((result->status != NIS_SUCCESS && result->status != NIS_S_SUCCESS) + || __type_of (result->objects.objects_val) != NIS_ENTRY_OBJ + || strcmp (result->objects.objects_val->EN_data.en_type, + "services_tbl") != 0 + || result->objects.objects_val->EN_data.en_cols.en_cols_len < 4) return 0; if (NISENTRYLEN (0, 0, result) >= room_left) { no_more_room: - __set_errno (ERANGE); + *errnop = ERANGE; return -1; } strncpy (first_unused, NISENTRYVAL (0, 0, result), @@ -77,8 +77,8 @@ _nss_nisplus_parse_servent (nis_result *result, struct servent *serv, NISENTRYLEN (0, 2, result)); first_unused[NISENTRYLEN (0, 2, result)] = '\0'; serv->s_proto = first_unused; - room_left -= (strlen (first_unused) +1); - first_unused += strlen (first_unused) +1; + room_left -= strlen (first_unused) + 1; + first_unused += strlen (first_unused) + 1; serv->s_port = atoi (NISENTRYVAL (0, 3, result)); p = first_unused; @@ -143,7 +143,7 @@ _nss_nisplus_parse_servent (nis_result *result, struct servent *serv, } static enum nss_status -_nss_create_tablename (void) +_nss_create_tablename (int *errnop) { if (tablename_val == NULL) { @@ -154,7 +154,10 @@ _nss_create_tablename (void) p = __stpcpy (p, nis_local_directory ()); tablename_val = __strdup (buf); if (tablename_val == NULL) - return NSS_STATUS_TRYAGAIN; + { + *errnop = errno; + return NSS_STATUS_TRYAGAIN; + } tablename_len = strlen (tablename_val); } return NSS_STATUS_SUCCESS; @@ -165,6 +168,7 @@ enum nss_status _nss_nisplus_setservent (void) { enum nss_status status = NSS_STATUS_SUCCESS; + int err; __libc_lock_lock (lock); @@ -173,7 +177,7 @@ _nss_nisplus_setservent (void) result = NULL; if (tablename_val == NULL) - status = _nss_create_tablename (); + status = _nss_create_tablename (&err); __libc_lock_unlock (lock); @@ -196,7 +200,7 @@ _nss_nisplus_endservent (void) static enum nss_status internal_nisplus_getservent_r (struct servent *serv, char *buffer, - size_t buflen) + size_t buflen, int *errnop) { int parse_res; @@ -209,8 +213,12 @@ internal_nisplus_getservent_r (struct servent *serv, char *buffer, { saved_res = NULL; if (tablename_val == NULL) - if (_nss_create_tablename () != NSS_STATUS_SUCCESS) - return NSS_STATUS_UNAVAIL; + { + 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) @@ -230,11 +238,13 @@ internal_nisplus_getservent_r (struct servent *serv, char *buffer, } } - if ((parse_res = _nss_nisplus_parse_servent (result, serv, buffer, - buflen)) == -1) + parse_res = _nss_nisplus_parse_servent (result, serv, buffer, + buflen, errnop); + if (parse_res == -1) { nis_freeresult (result); result = saved_res; + *errnop = ERANGE; return NSS_STATUS_TRYAGAIN; } else @@ -250,13 +260,13 @@ internal_nisplus_getservent_r (struct servent *serv, char *buffer, enum nss_status _nss_nisplus_getservent_r (struct servent *result, char *buffer, - size_t buflen) + size_t buflen, int *errnop) { int status; __libc_lock_lock (lock); - status = internal_nisplus_getservent_r (result, buffer, buflen); + status = internal_nisplus_getservent_r (result, buffer, buflen, errnop); __libc_lock_unlock (lock); @@ -266,17 +276,21 @@ _nss_nisplus_getservent_r (struct servent *result, char *buffer, enum nss_status _nss_nisplus_getservbyname_r (const char *name, const char *protocol, struct servent *serv, - char *buffer, size_t buflen) + char *buffer, size_t buflen, int *errnop) { int parse_res; if (tablename_val == NULL) - if (_nss_create_tablename () != NSS_STATUS_SUCCESS) - return NSS_STATUS_UNAVAIL; + { + enum nss_status status = _nss_create_tablename (errnop); + + if (status != NSS_STATUS_SUCCESS) + return status; + } if (name == NULL || protocol == NULL) { - __set_errno (EINVAL); + *errnop = EINVAL; return NSS_STATUS_NOTFOUND; } else @@ -292,12 +306,11 @@ _nss_nisplus_getservbyname_r (const char *name, const char *protocol, /* If we do not find it, try it as original name. But if the database is correct, we should find it in the first case, too */ - if ((result->status != NIS_SUCCESS && - result->status != NIS_S_SUCCESS) || - __type_of (result->objects.objects_val) != NIS_ENTRY_OBJ || - strcmp (result->objects.objects_val->EN_data.en_type, - "services_tbl") != 0 || - result->objects.objects_val->EN_data.en_cols.en_cols_len < 4) + if ((result->status != NIS_SUCCESS && result->status != NIS_S_SUCCESS) + || __type_of (result->objects.objects_val) != NIS_ENTRY_OBJ + || strcmp (result->objects.objects_val->EN_data.en_type, + "services_tbl") != 0 + || result->objects.objects_val->EN_data.en_cols.en_cols_len < 4) sprintf (buf, "[cname=%s,proto=%s],%s", name, protocol, tablename_val); else @@ -315,11 +328,15 @@ _nss_nisplus_getservbyname_r (const char *name, const char *protocol, return status; } - parse_res = _nss_nisplus_parse_servent (result, serv, buffer, buflen); + parse_res = _nss_nisplus_parse_servent (result, serv, buffer, buflen, + errnop); nis_freeresult (result); if (parse_res == -1) - return NSS_STATUS_TRYAGAIN; + { + *errnop = ERANGE; + return NSS_STATUS_TRYAGAIN; + } if (parse_res) return NSS_STATUS_SUCCESS; @@ -331,15 +348,19 @@ _nss_nisplus_getservbyname_r (const char *name, const char *protocol, enum nss_status _nss_nisplus_getservbynumber_r (const int number, const char *protocol, struct servent *serv, - char *buffer, size_t buflen) + char *buffer, size_t buflen, int *errnop) { if (tablename_val == NULL) - if (_nss_create_tablename () != NSS_STATUS_SUCCESS) - return NSS_STATUS_UNAVAIL; + { + enum nss_status status = _nss_create_tablename (errnop); + + if (status != NSS_STATUS_SUCCESS) + return status; + } if (protocol == NULL) { - __set_errno (EINVAL); + *errnop = EINVAL; return NSS_STATUS_NOTFOUND; } else @@ -361,11 +382,15 @@ _nss_nisplus_getservbynumber_r (const int number, const char *protocol, return status; } - parse_res = _nss_nisplus_parse_servent (result, serv, buffer, buflen); + parse_res = _nss_nisplus_parse_servent (result, serv, buffer, buflen, + errnop); nis_freeresult (result); if (parse_res == -1) - return NSS_STATUS_TRYAGAIN; + { + *errnop = ERANGE; + return NSS_STATUS_TRYAGAIN; + } if (parse_res) return NSS_STATUS_SUCCESS; diff --git a/nis/nss_nisplus/nisplus-spwd.c b/nis/nss_nisplus/nisplus-spwd.c index 1b3f68325e..54bbc32f3c 100644 --- a/nis/nss_nisplus/nisplus-spwd.c +++ b/nis/nss_nisplus/nisplus-spwd.c @@ -34,7 +34,7 @@ static nis_name tablename_val = NULL; static u_long tablename_len = 0; static enum nss_status -_nss_create_tablename (void) +_nss_create_tablename (int *errnop) { if (tablename_val == NULL) { @@ -45,7 +45,10 @@ _nss_create_tablename (void) p = __stpcpy (p, nis_local_directory ()); tablename_val = __strdup (buf); if (tablename_val == NULL) - return NSS_STATUS_TRYAGAIN; + { + *errnop = errno; + return NSS_STATUS_TRYAGAIN; + } tablename_len = strlen (tablename_val); } return NSS_STATUS_SUCCESS; @@ -55,6 +58,7 @@ enum nss_status _nss_nisplus_setspent (void) { enum nss_status status = NSS_STATUS_SUCCESS; + int err; __libc_lock_lock (lock); @@ -63,7 +67,7 @@ _nss_nisplus_setspent (void) result = NULL; if (tablename_val == NULL) - status = _nss_create_tablename (); + status = _nss_create_tablename (&err); __libc_lock_unlock (lock); @@ -85,7 +89,8 @@ _nss_nisplus_endspent (void) } static enum nss_status -internal_nisplus_getspent_r (struct spwd *sp, char *buffer, size_t buflen) +internal_nisplus_getspent_r (struct spwd *sp, char *buffer, size_t buflen, + int *errnop) { int parse_res; @@ -99,8 +104,12 @@ internal_nisplus_getspent_r (struct spwd *sp, char *buffer, size_t buflen) saved_res = NULL; if (tablename_val == NULL) - if (_nss_create_tablename () != NSS_STATUS_SUCCESS) - return NSS_STATUS_UNAVAIL; + { + 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) @@ -120,11 +129,13 @@ internal_nisplus_getspent_r (struct spwd *sp, char *buffer, size_t buflen) } } - if ((parse_res = _nss_nisplus_parse_spent (result, sp, buffer, - buflen)) == -1) + 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 @@ -138,13 +149,14 @@ internal_nisplus_getspent_r (struct spwd *sp, char *buffer, size_t buflen) } enum nss_status -_nss_nisplus_getspent_r (struct spwd *result, char *buffer, size_t buflen) +_nss_nisplus_getspent_r (struct spwd *result, char *buffer, size_t buflen, + int *errnop) { int status; __libc_lock_lock (lock); - status = internal_nisplus_getspent_r (result, buffer, buflen); + status = internal_nisplus_getspent_r (result, buffer, buflen, errnop); __libc_lock_unlock (lock); @@ -153,13 +165,17 @@ _nss_nisplus_getspent_r (struct spwd *result, char *buffer, size_t buflen) enum nss_status _nss_nisplus_getspnam_r (const char *name, struct spwd *sp, - char *buffer, size_t buflen) + char *buffer, size_t buflen, int *errnop) { int parse_res; if (tablename_val == NULL) - if (_nss_create_tablename () != NSS_STATUS_SUCCESS) - return NSS_STATUS_UNAVAIL; + { + enum nss_status status = _nss_create_tablename (errnop); + + if (status != NSS_STATUS_SUCCESS) + return status; + } if (name == NULL || strlen (name) > 8) return NSS_STATUS_NOTFOUND; @@ -180,11 +196,15 @@ _nss_nisplus_getspnam_r (const char *name, struct spwd *sp, return status; } - parse_res = _nss_nisplus_parse_spent (result, sp, buffer, buflen); + parse_res = _nss_nisplus_parse_spent (result, sp, buffer, buflen, + errnop); nis_freeresult (result); if (parse_res == -1) - return NSS_STATUS_TRYAGAIN; + { + *errnop = ERANGE; + return NSS_STATUS_TRYAGAIN; + } if (parse_res) return NSS_STATUS_SUCCESS; |