Commit Graph

216 Commits

Author SHA1 Message Date
riastradh 2b5e567d9c libc: Reintroduce getentropy.
This was introduced two years ago when the getrandom/getentropy API
question was still open, and removed because the discussion was
ongoing.  Now getentropy is more widely adopted and soon to be in
POSIX.  So reintroduce the symbol into libc since we'll be keeping it
anyway.  Discussion of details of the semantics, as interpreted by
NetBSD, is ongoing, but the symbol needs to get in before the
netbsd-10 branch.  The draft POSIX text is
(https://www.opengroup.org/austin/docs/austin_1110.pdf):

    SYNOPSIS
        #include <unistd.h>

        int getentropy(void *buffer, size_t length);

    DESCRIPTION
        The getentropy() function shall write length bytes of data
        starting at the location pointed to by buffer. The output
        shall be unpredictable high quality random data, generated by
        a cryptographically secure pseudo-random number
        generator. The maximum permitted value for the length
        argument is given by the {GETENTROPY_MAX} symbolic constant
        defined in <limits.h>.

    RETURN VALUES
        Upon successful completion, getentropy() shall return 0;
        otherwise, -1 shall be retunred and errno set to indicate the
        error.

    ERRORS
        The getentropy() function shall fail if:

        [EINVAL]        The value of length is greater than
                        {GETENTROPY_MAX}.

        The getentropy() function may fail if:

        [ENOSYS]        The system does not provide the necessary
                        source of entropy.

    RATIONALE
        The getentropy() function is not a cancellation point.

Minor changes from the previous introduction of getentropy into libc:

- Return EINVAL, not EIO, on buflen > 256.
- Define GETENTROPY_MAX in limits.h.

The declaration of getentropy in unistd.h and definition of
GETENTROPY_MAX in limits.h are currently conditional on
_NETBSD_SOURCE.  When the next revision of POSIX is finalized, we can
expose them also under _POSIX_C_SOURCE > 20yymmL as usual -- and this
can be done as a pullup without breaking existing compiled programs.
2022-05-31 13:42:58 +00:00
christos 18b914f008 Add man pages for posix_spawn_file_actions_add{f,}chdir from piyush 2021-11-15 14:01:50 +00:00
simonb e85380d6f9 Add links for the other functions documented in arc4random(3). 2021-05-03 11:07:55 +00:00
simonb 0cdd944264 Whitespace police. 2021-05-03 08:30:30 +00:00
christos c510facea2 Instead of compiling files with -fcommon, create an include file and declare
the 3 symbols that need to be common using an attribute. Put all the 3 symbol
definitions in libc in one place (initfini.c). Reviewed by joerg@
2021-04-20 21:42:31 +00:00
mrg 4084f973da use -fcommon where necessary. 2021-04-12 03:57:06 +00:00
simonb b2de856f1a Add manpage links for asysctl(3) and asysctlbyname(3), already described
in sysctl(3).
2021-03-10 13:30:34 +00:00
rin e0b51b0024 Add missing endutent.3 to MAN. 2021-02-26 04:28:14 +00:00
christos af5f2d14c6 put back line accidentally removed. 2021-02-26 03:19:34 +00:00
christos 64f644717c PR/56012: Kouichi Hashikawa: getutent(3) man page is missing 2021-02-26 03:05:01 +00:00
nia 796e3f7c10 remove getentropy bits 2020-09-22 21:37:47 +00:00
christos 65c5691e7d revert previous; utmpxname is already documented in getlastlogx.3. Should
probably be moved.
2020-07-05 01:09:48 +00:00
christos 20e726508c document utmpxname(3) 2020-07-05 01:05:50 +00:00
maya b47e7497df Don't add getentropy.c to the build (remove symbol from libc)
Still being discussed in tech-userlevel. If we wait any longer someone
is going to try the excuse that the discussion is entirely pointless, since
removing symbols is too hard.
2020-05-10 19:36:49 +00:00
nia 5e1fba1a1e Add getentropy() to libc - a simple wrapper to access the kernel CSPRNG.
Posted to tech-userlevel@ a week ago and reviewed by riastradh@.

GETENTROPY(3)		   Library Functions Manual		 GETENTROPY(3)

NAME
     getentropy - fill a buffer with high quality random data

LIBRARY
     Standard C Library (libc, -lc)

SYNOPSIS
     #include <unistd.h>

     int
     getentropy(void *buf, size_t buflen);

DESCRIPTION
     The getentropy() function fills a buffer with high quality random data,
     suitable for seeding cryptographically secure psuedorandom number
     generators.

     getentropy() is only intended for seeding random number generators and is
     not intended for use by regular code which simply needs secure random
     data.  For this purpose, please use arc4random(3).

     The maximum value for buflen is 256 bytes.

IMPLEMENTATION NOTES
     getentropy() reads from the sysctl(7) variable kern.arandom.

RETURN VALUES
     The getentropy() function returns 0 on success, and -1 if an error
     occurred.

ERRORS
     getentropy() will succeed unless:

     [EFAULT]		The buf argument points to an invalid memory address.

     [EIO]		Too many bytes were requested.

SEE ALSO
     arc4random(3), rnd(4)

STANDARDS
     The getentropy() function is non-standard.

HISTORY
     The getentropy() function first appeared in OpenBSD 5.6, then in
     FreeBSD 12.0, and NetBSD 10.
2020-05-06 16:17:36 +00:00
joerg 18796b949c Explicitly use -fcommon for globals shared between libc and CSU. 2020-04-22 23:32:25 +00:00
kamil d4fa9170e4 Install new man-page devname_r(3).
This is a link to devname(3).
2017-09-09 18:18:27 +00:00
kre 486691905e Add the new signalname/signalnext/signalnumber interface to libc.
This as discussed on current-users in the thread
entitled:
  Proposal: new libc/libutil functions to map SIGXXXX <-> "XXXX"
that can be found (starting at):
  http://mail-index.netbsd.org/current-users/2017/04/28/msg031600.html

These functions provide the mechanism to enable applications
to divorce themselves from internal details of the signal
implementation.

Libc minor bumped, prototypes in <signal.h>, sets lists updated (and sorted).

One and all: feel free to improve the sources & man page (etc), but
please do not change the function signatures without discussion.
2017-05-09 11:14:16 +00:00
kamil 5acf460d25 Mark exect(3) obsolete and bind it to plain execve(2) on all platforms
The original exect(2) from BSD4.2 was enabling bit for tracing
(single-step mode) and calling execve(2). The purpose of it was to generate
a signal for a tracer once the application will change its image to a new
program.

This approach no longer works as:
 - exect(2) traces (single-steps) libc and it requires hundreds or
   thousands steps before entering a new image
 - it's vax and x86 specific code
 - this functionality has been moved to the kernel - once a process is
   traced it will generate SIGTRAP with si_code TRAP_EXEC and route it to
   its debugger
 - the side effects and unportability make this interface unusable
 - there are no known users of this interface
 - it apparently never worked better since day0 of NetBSD ("day0 bug")

Users are requested to move to other execve(2) variants. Calling current
execve(2) as it is the most similar behavior to this one from BSD4.2.

Discussed several times on mailing lists and in PR/51700.

Add warning to exect(3) telling about marking this function obsolete.

This function is prepared to be removed in next libc major bump.

Sponsored by <The NetBSD Foundation>
2017-02-07 19:29:39 +00:00
christos 820e172c78 Split syslog.c to:
- syslog_ss.c *_ss api functions (don't use stdio, time)
- syslog.c: *syslog* non _ss api functions (use stdio, time)
- xsyslog.c> common guts.

The motivation for this is not to drag in stdio/locale/floating point/time
for every binary, since syslog_ss() is used in __stack_check_fail() for SSP.
2017-01-12 00:38:01 +00:00
kamil 7f4b5eb156 Add timespec_get(3) in <time.h> and enable unconditionally struct timespec
These changes conforms to the C11 standard
References:
 - 7.27.1/3 Components of time (struct timespec)
 - 7.27.2.5 The timespec_get function

According to ISO/IEC 9899:201x (draft) <time.h> defines the timespec
structure and declares the timespec_get(3) function with TIME_UTC
definition.

According to a C++17 standard draft <ctime> offers the same interface in
the std:: namespace.

The timespec_get function modifies the timespec object pointed by ts
to hold the current calendar time in the given base. The standard notes
only the TIME_UTC base with implementation defined value, set it to 1
as zero is reserved for error handling. Once operation was successful this
function returns passed base, otherwise exits with zero.

The timespec struct was already part of the POSIX standard in <time.h>.

Enable this interface unconditionally in the header to allow to use it
in a code prior C11 and C++17 as an extension.

Review notes from <christos>
2016-10-04 09:41:40 +00:00
christos 78cbc4ca75 Document bsd_signal (From GSoC 2016 by Charles Cui) 2016-06-05 17:16:44 +00:00
christos 406ebcd6ac userland bits for wait6/waitid. 2016-04-03 00:19:42 +00:00
christos 607e9de17b add stravis(3) from OpenBSD 2016-01-14 20:41:23 +00:00
pooka 3a6246a644 Don't include daemon.c in RUMPRUN=yes mode.
The standard implementation uses fork(), needs an alternative
implementation for Rumprun.
2015-10-25 16:01:04 +00:00
christos 9226f39def Factor out popen() code into separate functions and create popenve()
using the new functions, a safer version of popen() that does not
involve a shell. Correct manual page inaccuracies.
2015-01-20 17:28:00 +00:00
pooka dc3c2e9560 Add two more Makefile conditionals required for RUMPRUN=yes
* do not build _errno.c (different thread/tls handling)
 * do not build either phk- or jemalloc (different backing page allocation)

Somehow I missed these in the previous commit, but now libc built with
RUMPRUN=yes works also with rumprun-posix, so there's reasonably high
confidence that I didn't miss anything anymore.
2014-12-10 16:55:54 +00:00
christos 718924c8d3 add execvpe, execlpe (reviewed by phone) 2014-09-26 19:28:03 +00:00
joerg 3adc1c7681 Add asysctl(3) and asysctlbyname(3) wrappers for the common idiom of
fetching dynamically sized data via sysctl.
2014-06-13 15:45:05 +00:00
christos cc46e26df3 "soon" is "now". Remove all __indr_reference crap. 2014-01-16 20:31:42 +00:00
christos eaffbb929f Add the {v,}{err,warn}c flavors, from FreeBSD. 2014-01-16 17:21:38 +00:00
christos ff84366ca6 add utimens and lutimens wrappers using utimensat. 2012-11-03 19:39:21 +00:00
christos dd362f33aa man page for getpassfd 2012-04-12 22:08:32 +00:00
christos 48c7acbcd7 Add a new getpass implementation that does not mess with signals, and
include getpass_r
2012-04-12 19:36:19 +00:00
martin 19f52532ad Add userland part of posix_spawn. Libc functions imported from FreeBSD.
Based on Charles Zhang's summer of code project.
2012-02-11 23:31:22 +00:00
wiz a107b19ebf Split extattr(3) into two man pages to get rid of ugly duplicate Nd.
Work done by Abhinav Upadhyay with minimal cleanup.
2011-12-16 12:46:00 +00:00
joerg d24dcc0dc7 Uses non-literal format strings 2011-08-25 18:20:22 +00:00
manu 32c00d6291 Make cp -p and mv preverve extended attributes, and complain if they cannot.
Also introduce library functions for copying extended attributes from one
file to another:
- extattr_copy_file, extattr_copy_fd, extattr_copy_link, with FreeBSD style,
  where a namespace is to be supplied
- cpxattr, fcpxattr, lcpxattr, with Linux style, where all namespaces
  accessible to the caller are copied, and the others are silently ignored.
2011-08-03 04:11:15 +00:00
christos 2587e6e437 add fpgetprec/fpsetprec 2011-03-26 19:51:41 +00:00
erh dba1735a6e Remove one last reference to commaize_number.3 2011-03-16 01:30:24 +00:00
christos ab077958c3 goodbye short-live commaize_number(3), if you liked it:
#define commaize_number(s, l, n) snprintf(s, l, "%'llu", (unsigned long long)n)
2011-03-16 00:50:28 +00:00
erh 9a5590a540 PR#7540, add a commaize_number function, which inserts comma into a string
of digits to make it more readable.  This is soon to be used in /bin/ls.
2011-03-15 03:47:04 +00:00
christos 2d8f83e77b Fix various vis/unvis issues:
- no need for all the weak symbols
- define a new _VIS_END flag for UNVIS_END so that there are no collisions
  between and vis and unvis flags.
- add bound versions of the vis and unvis functions that take the length of
  the destination buffer. Unlike the OpenBSD ones they return -1 or NULL if
  the buffer is not large enough, instead of silently truncating.
2011-03-12 19:52:45 +00:00
christos b3ddcb3ea2 errlist.c is automatically generated now. 2010-12-12 20:22:48 +00:00
yamt ab5972b02c fix rewinddir on nfs. fix PR/42879 (and probably PR/40229.) 2010-09-26 02:26:59 +00:00
christos 3991ffd1e1 add psiginfo. 2010-08-27 08:38:41 +00:00
tnozaki 64a7d4fa9a 1. hide _CTYPE_PRIVATE section in ctype.h, move them to private header ctype_local.h.
2. do not use _CTYPE_NUM_CHARS macro to read data from LC_CTYPE(old BSDCTYPE style) database.
   because 1<<CHAR_BIT is MD, so i added MI macro _CTYPE_CACHE_SIZE(1<<8).
3. remove _NB_CACHED_RUNE macro, use _CTYPE_CACHE_SIZE instead.
2010-05-22 06:38:15 +00:00
jruoho 08cdc5df90 Build links for syslogp(3), syslogp_r(3), vsyslogp(3), and vsyslogp_r(3).
From Takahiro Kambe in PR lib/43301.
2010-05-13 17:48:50 +00:00
wiz 68bd1a898e Link glob(3) to glob_pattern_p(3). 2009-04-08 19:28:48 +00:00
christos 461a86f9bd merge christos-time_t 2009-01-11 02:45:45 +00:00