35 Commits

Author SHA1 Message Date
Rich Felker
91d34c4533 fix regression in getspnam[_r] error code for insufficient buffer size
commit 2d7d05f031e014068a61d3076c6178513395d2ae wrongly changed ERANGE
to EINVAL, likely as the result of copy-and-paste error.
2017-06-21 19:06:45 -04:00
Rich Felker
2d7d05f031 set errno when getpw*_r, getgr*_r, and getspnam_r fail
these functions return an error code, and are not explicitly
documented to set errno, but they are nonstandard and the historical
implementations do set errno as well, and some applications expect
this behavior. do likewise for compatibility.

patch by Rudolph Pereira.
2017-06-15 13:01:34 -04:00
Rich Felker
39494a273e revert unrelated change that slipped into last commit 2016-07-13 15:23:01 -04:00
Rich Felker
cff5747c74 fix regression in tcsetattr on all mips archs
revert commit 8c316e9e49d37ad92c2e7493e16166a2afca419f. it was wrong
and does not match how the kernel API works.
2016-07-13 15:04:30 -04:00
Rich Felker
bd1eaceaa3 fix spurious errors from pwd/grp functions when nscd backend is absent
for several pwd/grp functions, the only way the caller can distinguish
between a successful negative result ("no such user/group") and an
internal error is by clearing errno before the call and checking errno
afterwards. the nscd backend support code correctly simulated a
not-found response on systems where such a backend is not running, but
failed to restore errno.

this commit also fixed an outdated/incorrect comment.
2015-06-09 20:15:49 +00:00
Rich Felker
58fa856960 fix mishandling of ENOMEM return case in internal getgrent_a function
due to an incorrect return statement in this error case, the
previously blocked cancellation state was not restored and no result
was stored. this could lead to invalid (read) accesses in the caller
resulting in crashes or nonsensical result data in the event of memory
exhaustion.
2015-05-01 12:25:01 -04:00
Rich Felker
4b5ca13fb1 avoid sending huge names as nscd passwd/group queries
overly long user/group names are potentially a DoS vector and source
of other problems like partial writes by sendmsg, and not useful.
2015-03-15 23:46:22 -04:00
Rich Felker
49d1e7f931 simplify nscd lookup code for alt passwd/group backends
previously, a sentinel value of (FILE *)-1 was used to inform the
caller of __nscd_query that nscd is not in use. aside from being an
ugly hack, this resulted in duplicate code paths for two logically
equivalent cases: no nscd, and "not found" result from nscd.

now, __nscd_query simply skips closing the socket and returns a valid
FILE pointer when nscd is not in use, and produces a fake "not found"
response header. the caller is then responsible for closing the socket
just like it would do if it had gotten a real "not found" response.
2015-03-15 23:33:59 -04:00
Josiah Worcester
2894a44b40 add alternate backend support for getgrouplist
This completes the alternate backend support that was previously added
to the getpw* and getgr* functions. Unlike those, though, it
unconditionally queries nscd. Any groups from nscd that aren't in the
/etc/groups file are added to the returned list, and any that are
present in the file are ignored. The purpose of this behavior is to
provide a view of the group database consistent with what is observed
by the getgr* functions. If group memberships reported by nscd were
honored when the corresponding group already has a definition in the
/etc/groups file, the user's getgrouplist-based membership in the
group would conflict with their non-membership in the reported
gr_mem[] for the group.

The changes made also make getgrouplist thread-safe and eliminate its
clobbering of the global getgrent state.
2015-03-15 22:32:22 -04:00
Josiah Worcester
34b423d207 support alternate backends for the passwd and group dbs
when we fail to find the entry in the commonly accepted files,  we
query a server over a Unix domain socket on /var/run/nscd/socket.
the protocol used here is compatible with glibc's nscd protocol on
most systems (all that use 32-bit numbers for all the protocol fields,
which appears to be everything but Alpha).
2015-02-23 01:02:14 -05:00
Rich Felker
0afef1aa24 fix spurious errors in refactored passwd/group code
errno was treated as the error status when the return value of getline
was negative, but this condition can simply indicate EOF and is not
necessarily an error.

the spurious errors caused by this bug masked the bug which was fixed
in commit fc5a96c9c8aa186effad7520d5df6b616bbfd29d.
2015-02-23 00:42:40 -05:00
Rich Felker
fc5a96c9c8 fix crashes in refactored passwd/group code
the wrong condition was used in determining the presence of a result
that needs space/copying for the _r functions. a zero return value
does not necessarily mean success; it can also be a non-error negative
result: no such user/group.
2015-02-23 00:35:47 -05:00
Josiah Worcester
7c5f0a5212 refactor group file access code
this allows getgrnam and getgrgid to share code with the _r versions
in preparation for alternate backend support.
2015-02-13 01:46:51 -05:00
Josiah Worcester
700e08993c refactor passwd file access code
this allows getpwnam and getpwuid to share code with the _r versions
in preparation for alternate backend support.
2015-02-10 22:57:02 -05:00
Rich Felker
ecb608192a fix erroneous return of partial username matches by getspnam[_r]
when using /etc/shadow (rather than tcb) as its backend, getspnam_r
matched any username starting with the caller-provided string rather
than requiring an exact match. in practice this seems to have affected
only systems where one valid username is a prefix for another valid
username, and where the longer username appears first in the shadow
file.
2015-01-21 14:26:05 -05:00
Szabolcs Nagy
571744447c include cleanups: remove unused headers and add feature test macros 2013-12-12 05:09:18 +00:00
Michael Forney
7e771e62e7 shadow: Implement fgetspent 2013-11-24 21:04:53 -05:00
Michael Forney
b3646b30d6 shadow: Move spent parsing to internal function 2013-11-24 20:57:10 -05:00
Michael Forney
22f29bfebe shadow: Implement putspent 2013-11-24 09:36:28 -05:00
Michael Forney
3fd1acbfee putgrent: Add missing newline 2013-11-23 16:20:56 -05:00
Michael Forney
a3b98a11a9 putgrent: Stop writing output on first failure
This way, if an fprintf fails, we get an incomplete group entry rather
than a corrupted one.
2013-11-23 16:20:51 -05:00
Rich Felker
23b8e3bc95 fix off-by-one error in getgrnam_r and getgrgid_r, clobbering gr_name
bug report and patch by Michael Forney. the terminating null pointer
at the end of the gr_mem array was overwriting the beginning of the
string data, causing the gr_name member to always be a zero-length
string.
2013-09-29 02:52:33 -04:00
Rich Felker
648c3b4e18 change uid_t, gid_t, and id_t to unsigned types
this change is both to fix one of the remaining type (and thus C++
ABI) mismatches with glibc/LSB and to allow use of the full range of
uid and gid values, if so desired.

passwd/group access functions were not prepared to deal with unsigned
values, so they too have been fixed with this commit.
2013-07-19 01:34:28 -04:00
Rich Felker
ddfb267b0e add put*ent functions for passwd/group files and similar for shadow
since shadow does not yet support enumeration (getspent), the
corresponding FILE-based get and put versions are also subbed out for
now. this is partly out of laziness and partly because it's not clear
how they should work in the presence of TCB shadow files. the stubs
should make it possible to compile some software that expects them to
exist, but such software still may not work properly.
2013-04-04 19:23:47 -04:00
Rich Felker
cac872957e add fgetgrent function
based on patch by Isaac Dunham, moved to its own file to avoid
increasing bss on static linked programs not using this nonstandard
function but using the standard getgrent function, and vice versa.
2013-02-17 13:21:56 -05:00
Rich Felker
d712dd396d more close-on-exec fixes, mostly using new "e" flag to fopen 2012-09-29 18:14:46 -04:00
Rich Felker
4948a24df2 make passwd/group functions safe against cancellation in stdio
these changes are a prerequisite to making stdio cancellable.
2012-02-01 23:51:19 -05:00
Rich Felker
5e9314ff03 add fgetpwent (nonstandard function)
based on patch by Jeremy Huntwork
2012-01-29 11:54:18 -05:00
Rich Felker
aef84ca7ec fix clobbering of errno in get(pw|gr)([ug]id|nam) by fclose 2011-09-27 16:45:29 -04:00
Rich Felker
0d4d94efd5 protect against/handle cancellation reading shadow passwords 2011-09-21 23:57:51 -04:00
Rich Felker
fb62ae74d0 fix buffer overrun in getgrent code when there are no group members 2011-06-30 08:11:06 -04:00
Rich Felker
c19a6be5a1 it's called getgrgid_r, not getgruid_r... 2011-06-08 16:47:08 -04:00
Rich Felker
18bca57510 shadow password fixes: empty fields should read as -1 not 0 2011-04-20 19:05:59 -04:00
Rich Felker
976f42d1f1 guard against hard links to non-ordinary-files when reading tcb shadow 2011-02-14 21:15:07 -05:00
Rich Felker
0b44a0315b initial check-in, version 0.5.0 2011-02-12 00:22:29 -05:00