Commit Graph

163 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
andvar 279d5541d3 fix typos in comments. 2021-10-15 22:32:28 +00:00
kre 5cea56c875 Correct typo in previous. 2020-12-04 23:04:58 +00:00
christos fe1e39fb82 Add __null_sentinel 2020-12-04 20:39:10 +00:00
nia 796e3f7c10 remove getentropy bits 2020-09-22 21:37:47 +00:00
christos 9aa2a9c323 Add ACL support for FFS. From FreeBSD. 2020-05-16 18:31:45 +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
kamil 1c8bb7d153 Add getsid(2) to the XOPEN namespace (again) 2020-03-31 16:50:31 +00:00
kamil 221d32f6a2 Expose getsid(2) to POSIX >= 2008 2020-03-31 16:49:06 +00:00
christos e33ef9b983 one fexecve declaration should be enough. 2019-09-15 23:41:41 +00:00
christos 9dd780b230 Remove the _INCOMPLETE_XOPEN_C063 stuff. 2019-09-15 23:41:00 +00:00
christos cedcb5f35f Declare fexecve 2019-09-15 22:32:48 +00:00
christos fb69ccbd92 more type protection macro lossage. 2018-11-18 19:22:23 +00:00
martin a9fb6a0f33 PR standards/53525: move getsubopt() to stdlib.h 2018-08-15 10:21:42 +00:00
christos 3c15acfdbe fix typo 2018-02-06 20:22:41 +00:00
christos 4e8153bc86 detect duplicate declaration of pthread_atfork() in pthread.h 2018-02-06 20:21:21 +00:00
dholland ae3b3bcc2b PR 51287 Ralf Nolden: posix_fallocate belongs in <fcntl.h> 2016-06-30 15:29:20 +00:00
kamil e3d1905862 Use generic types in the profil(2) function prototype (<unistd.h>) 2016-06-18 14:39:15 +00:00
wiz fc5db8c0e8 Put fseeko, ftello, pread, and pwrite in the POSIX 2001 namespace.
Ok christos, apb, martin
2015-03-24 07:44:52 +00:00
christos 5a70401cf6 PR/49684: Pierre Pronchery: readlinkat(2) return type is wrong. 2015-02-22 00:50:30 +00:00
christos 718924c8d3 add execvpe, execlpe (reviewed by phone) 2014-09-26 19:28:03 +00:00
dholland d0352e761c Add userlevel manifestations of posix_fallocate and fdiscard, in
unistd.h and libc, and add a man page.

Allow wiggle room in the man page for implementations of fallocate
that either (a) don't fully unwind on failure, leaving new blocks
allocated without changing the file size, or (b) create only in-memory
transient reservations that disappear when crashing or rebooting.

Also, add crossreference to fdiscard from ftruncate(2), and remove the
old BUGS entry from there that called for a generalized version that
allows discarding ranges of a file: that's what fdiscard is.
2014-07-25 08:30:47 +00:00
christos e00a3615cf add mkostemp{s,} mkstemps from FreeBSD 2014-06-18 17:48:22 +00:00
christos a012ad3d35 PR/4891: Wiz: readlink moved from xopen to base at issue 5. 2014-01-02 23:33:50 +00:00
njoly 0d88813605 Follow OpenGroup online specification[1], move
fchmodat/mkdirat/mkfifoat/mknodat prototypes to <sys.stat.h>.

[1] http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_stat.h.html
2013-10-09 09:38:21 +00:00
dholland 196f95b039 Remove #if defined(_KERNEL) around a userlevel function. 2013-01-12 17:17:26 +00:00
skrll 6da0cd6163 Check for _NETBSD_SOURCE being defined wherever we check for
_INCOMPLETE_XOPEN_C063 so that we expose the new POSIX extended API set
recently added.
2012-12-01 13:28:18 +00:00
manu a76c1cc17f Add most system calls for POSIX extended API set, part 2, with test cases:
faccessat(2), fchmodat(2), fchownat(2), fstatat(2), mkdirat(2), mkfifoat(2),
mknodat(2), linkat(2), readlinkat(2), symlinkat(2), renameat(2), unlinkat(2),
utimensat(2), openat(2).

Also implement O_SEARCH for openat(2)

Still missing:
- some flags for openat(2)
- fexecve(2) implementation
2012-11-18 17:41:51 +00:00
darrenr 3ec957d580 bin/46703: BSD r-commands use wrong source address for stderr
http://gnats.netbsd.org/cgi-bin/query-pr-single.pl?number=46703
Bump libc minor for the addition of rresvport_af_addr()
2012-07-14 15:06:26 +00:00
christos e457beb983 new flag. 2012-04-14 01:34:08 +00:00
christos ffed4f27af add more options. 2012-04-13 23:29:14 +00:00
christos 5d7ab7f99c add timeout to getpassfd. 2012-04-13 14:39:49 +00:00
christos 311b90b920 add GETPASS_ECHO_STAR 2012-04-12 23:16:38 +00:00
christos 7def94a8ad add getpassfd 2012-04-12 22:08:02 +00:00
christos eead6b2f0e add getpass_r 2012-04-12 19:36:34 +00:00
joerg 0b50389a15 Add __returns_twice for the attribute of the same name. This makes the
attribute explicit based on the functions GCC gives it too.
2011-11-05 09:27:06 +00:00
manu 9db30be448 First stage of support for Extended API set 2. Most of the think is
unimplemented, except enough of linkat(2) to hardlink to a symlink.

Everything new in headers is guarded #ifdef _INCOMPLETE_XOPEN_C063 since
some software (e.g.: xcvs in our own tree) will assume they can use openat(2)
when AT_FDCWD is defined. _INCOMPLETE_XOPEN_C063 will go away once support
will be completed.
2011-08-08 12:08:52 +00:00
christos e2bebf7172 * Arrange for interfaces that create new file descriptors to be able to
set close-on-exec on creation (http://udrepper.livejournal.com/20407.html).

    - Add F_DUPFD_CLOEXEC to fcntl(2).
    - Add MSG_CMSG_CLOEXEC to recvmsg(2) for unix file descriptor passing.
    - Add dup3(2) syscall with a flags argument for O_CLOEXEC, O_NONBLOCK.
    - Add pipe2(2) syscall with a flags argument for O_CLOEXEC, O_NONBLOCK.
    - Add flags SOCK_CLOEXEC, SOCK_NONBLOCK to the socket type parameter
      for socket(2) and socketpair(2).
    - Add new paccept(2) syscall that takes an additional sigset_t to alter
      the sigmask temporarily and a flags argument to set SOCK_CLOEXEC,
      SOCK_NONBLOCK.
    - Add new mode character 'e' to fopen(3) and popen(3) to open pipes
      and file descriptors for close on exec.
    - Add new kqueue1(2) syscall with a new flags argument to open the
      kqueue file descriptor with O_CLOEXEC, O_NONBLOCK.

* Fix the system calls that take socklen_t arguments to actually do so.

* Don't include userland header files (signal.h) from system header files
  (rump_syscallargs.h).

* Bump libc version for the new syscalls.
2011-06-26 16:42:39 +00:00
christos 416c220c02 Re-do ssp hijacking by defining inline functions and using the weak libc
symbols to do the indirection for unistd.h instead of #define tricks.
Fixes compilation for things that define struct { ssize_t read(int fd, ...); }.
2011-01-19 19:21:29 +00:00
christos 6a4804166f The signal number argument in psignal is int not unsigned int.
Add psiginfo.
2010-08-27 08:40:38 +00:00
christos bb83e0e3c9 change size_t to ssize_t for POSIX compliance. 2010-04-17 17:51:47 +00:00
christos 244f534022 PR/43172: Jukka Ruohonen: swab(3) lacks restrict-keyword 2010-04-17 17:48:34 +00:00
kleink 9be4603670 Declare strsignal(3) in <string.h>, per POSIX-2008, and adjust
documentation accordingly.

Fixes PR standards/41325 from Perry E. Metzger.
2009-07-22 19:48:27 +00:00
christos 50728e7823 merge christos-time_t 2009-01-11 02:57:17 +00:00
lukem 4a94e73441 Change the second argument of getlogin_r() from int to size_t, per POSIX. 2009-01-06 11:16:46 +00:00
ad f778b05135 SUS says that pthread_atfork() must also be in unistd.h 2008-06-25 11:45:38 +00:00
ad 5f64faa3a9 Add getlogin_r. Manual page changes mostly lifted from FreeBSD. 2008-06-25 11:10:24 +00:00
martin ce099b4099 Remove clause 3 and 4 from TNF licenses 2008-04-28 20:22:51 +00:00
drochner 7cc98087b6 everyone else assumes that defining "_XOPEN_SOURCE" means XPG4.2,
so remove comparisions against the numerical values "3" or "4"
2008-04-01 19:23:28 +00:00
perry fc883a791d change some __attribute__s to __keywords 2007-12-24 17:26:09 +00:00