Commit graph

135 commits

Author SHA1 Message Date
cinap_lenrek a7a08647b6 ape: re-implement getlogin() by stating /proc/$pid/status 2020-12-23 02:32:13 +01:00
cinap_lenrek fc5070c600 libauth: add procsetuser() function to change user id of the calling process
Provide a central function to change the user id
of the calling process.

This is mostly used by programs to become the none
user, followed by a call to newns().
2020-12-19 17:46:55 +01:00
cinap_lenrek 672cf179a1 libc: implement getppid() reading /proc/$pid/ppid instead of /dev/ppid
The devcons driver is really the wrong place to
serve per process information.
2020-12-19 15:15:38 +01:00
Ori Bernstein 2db3642b8d strndup: don't assume buffer is terminated
Using strlen in strndup will walk past the first
n bytes up to the terminator, which may not be
present. This is not what we want.

While we're here, do some cleanups.
2020-12-18 07:16:29 -08:00
Ori Bernstein 658c1b9f68 libap: add strndup
strndup is part of POSIX.1, so APE should provide it.
This patch adds it, so need to patch it out of fewer
programs going forward.
2020-12-17 19:20:04 -08:00
Ori Bernstein ec533a1ad8 ape/ctype.h: add isblank, fix functions (thanks staalmannen)
Our ctype.h mistakenly ommitted isblank. Add it in.

While we're here, the make the 'isfoo()' functions
are broken: they're offsetting into the array, and
don't work with negative character values.

Sync the function bodies with the macros, and make
them produce correct results.
2020-08-29 11:09:20 -07:00
Ori Bernstein db6e26d55e libplumb: add missing mkfile 2020-06-09 12:23:24 -07:00
Ori Bernstein 702bb7a508 ape: add missing rerrstr.c 2020-06-05 18:52:22 -07:00
Ori Bernstein f08e95cd93 ape: make libplumb available under ape.
This adds the mkfiles and plumb.h to ape,
similar to how libdraw is made available.
This is used for ports such as netsurf.
2020-06-05 11:28:47 -07:00
Ori Bernstein 5cd7f7b0ec ape/libdraw: add missing eenter (thanks phil9) 2020-05-30 10:06:21 -07:00
Ori Bernstein 78aec6d5c6 Fix scans of more than one character in %[]
This got broken in d8e877a89dae, where we returned 0 on the
first mismatch; we want to return 0 only when we consumed no
characters.
2020-05-15 16:46:20 -07:00
cinap_lenrek 1c4c82277e ape: fix name clash, have to use _SLEEP syscall instead of ape sleep in plan9 code (thanks jamos)
this fixes etimer() from ape built libdraw as posix sleep() uses
seconds while plan9 uses miliseconds.
2020-05-13 00:17:07 +02:00
Ori Bernstein 73f38fc546 [ape] add missing conversion flags for scanf
We're missing type flags for:

	hh: char
	ll: vlong
	z:  size_t
	t:  ptrdiff_t
	j:  intmax_t

The lack of '%lld' was causing us to fail when parsing
timezone files. This brings us in line with the specifiers
in the C99 standard, section 7.19.6.2p11
2020-05-12 10:48:33 -07:00
Ori Bernstein bfc8cdfff5 fix '%[]' specifiers and '%n' (thanks phil9)
When a match() fails, we need to unget the character we
tried to match against, rather than leaving it consumed.

Also, we can't break out of a conversion before we reach
the end of a format string, because things like the '%n'
conversion do not consume anything, and should still be
handled.
2020-05-09 15:10:39 -07:00
Ori Bernstein 698837e715 fix alignment in ape malloc
We used to have a padding int in the structure
after the next pointer, to align it to 16 bytes.
On 64 bit architectures, the pointer was already
8 bits, so the padding misaligned things to 20
bytes.

This fixes it so that we're explcit about the
data alignment we want, instead of hoping that
the various sizes line up.
2020-03-09 08:02:22 -07:00
cinap_lenrek 64640083de libsec: remove hash pickle functions, document ripemd160, cleanup sechash(2) manpage 2020-03-01 15:07:44 +01:00
Ori Bernstein 98374d6eea remove C99_SPRINTF_EXTENSION define.
It's been 20 years since c99 came out. By now, if code
hasn't been fixed, it's not going to be. Requiring this
define just confuses porters.
2020-02-10 19:26:39 -08:00
cinap_lenrek f8de863602 ape: don't hardcode list of ape library directories in /sys/src/ape/lib/mkfile
this change allows one to drop library directories (like
freetype) into /sys/src/ape/lib/ and have them built without
having to change the mkfile.
2019-09-16 16:21:40 +02:00
Roberto E. Vargas Caballero 42240127a7 ape: Add mkstemp to /sys/src/ape/lib/ap/gen/mkfile 2019-09-09 17:27:57 +01:00
Roberto E. Vargas Caballero e0720a48b0 Add mkstemp to stdlib.h
q
2019-09-09 15:58:39 +01:00
cinap_lenrek 6118d77858 ape: reimplement rename() - fixing compiler warnings and handling more error cases
handle empty filename, dot and dotdot. handle mismatching from/to directory/file
type. cleanup destination file on error. error when attempting to copy non-empty
directories.

little test program:

#include <unistd.h>
#include <stdio.h>

int
main(int argc, char *argv[])
{
	if(argc != 3){
		fprintf(stderr, "usage: %s old new\n", argv[0]);
		return 1;
	}
	if(rename(argv[1], argv[2])){
		perror("rename");
		return 1;
	}
	return 0;
}
2019-06-24 20:09:04 +02:00
cinap_lenrek 7d3cc1c55a ape: revert rename() change
new implementation gets stuck in a infinite loop. backing
this out for now.
2019-06-23 22:35:14 +02:00
Ori Bernstein d4bc9052be Turn on warnings when building libap.
For ape, we never enabled warnings in cflags.
Turning it on brings up a lot of warnings. Most are noise,
but a few caught unused variables and trunctaions of pointers.
to smaller integers (int, long).

A few warnings remain.
2019-06-21 10:00:58 -07:00
cinap_lenrek addb36ee48 ape: fix malloc to deal with more than 4GB of memory on 64 bit systems 2019-05-10 12:10:02 +02:00
cinap_lenrek a375c9ac38 libc: fix return value for arm64 memset() and memove() 2019-05-09 12:40:03 +02:00
cinap_lenrek 57e0786595 libc: use MOVP instruction for arm64 memmove() and memset() 2019-05-09 11:40:54 +02:00
cinap_lenrek 4e7fbabfc9 libc: provide arm64 assembly versions for memmove() and memset()
just a first approximation, uses unaligned 8 byte loads and stores.
MOVP not yet implemented by the linker. no ZVA cache magic yet.
2019-05-09 02:32:09 +02:00
cinap_lenrek 2994fccbe1 ape: initial support for arm64 2019-05-03 21:06:46 +02:00
spew 77ca4e0056 ape: fix MAXSIG 2018-07-03 14:41:14 -04:00
spew ede15f38e5 ape: remove getitimer setitimer implemenations 2018-07-03 12:28:05 -04:00
spew 2e05af858e ape: improve setitimer 2018-07-01 23:35:23 -04:00
spew 91d0343627 ape: an implemenation of getitimer setitimer 2018-07-01 18:48:12 -04:00
spew 55c122d59f ape: add strnlen 2018-06-21 11:56:37 -04:00
spew 3b376b43af ape: provide bogus chroot implementation 2018-06-20 22:19:37 -04:00
spew 583c6d269b ape: add some common fields for stat, grp and pwd 2018-06-17 17:38:00 -04:00
aiju be3809866c ape: floating point improvements (thanks spew) 2018-05-24 13:40:44 +01:00
cinap_lenrek 743f65c878 ape/libauth: remove auth_wep.$O from mkfile 2018-01-02 06:05:47 +01:00
cinap_lenrek ea212266a1 ape: make encXchr()/decXchr() functions available 2017-12-31 10:53:50 +01:00
cinap_lenrek 077e719dfb libsec: write optimized _chachablock() function for amd64 / sse2
doing 4 quarterround's in parallel using 128-bit
vector registers. for second round shuffle the columns and
then shuffle back.

code is rather obvious. only trick here is for the first
quaterround PSHUFLW/PSHUFHW is used to swap the halfwords
for the <<<16 rotation.
2017-11-20 00:10:35 +01:00
cinap_lenrek 3356e0e731 libsec: AES-NI support for amd64
Add assembler versions for aes_encrypt/aes_decrypt and the key
setup using AES-NI instruction set. This makes aes_encrypt and
aes_decrypt into function pointers which get initialized by
the first call to setupAESstate().

Note that the expanded round key words are *NOT* stored in big
endian order as with the portable implementation. For that reason
the AESstate.ekey and AESstate.dkey fields have been changed to
void* forcing an error when someone is accessing the roundkey
words. One offender was aesXCBmac, which doesnt appear to be
used and the code looks horrible so it has been deleted.

The AES-NI implementation is for amd64 only as it requires the
kernel to save/restore the FPU state across syscalls and
pagefaults.
2017-11-12 23:15:15 +01:00
cinap_lenrek 3794b1c14f libc: improve alignment of QLp structure on amd64, cosmetics
the QLp structure used to occupy 24 bytes on amd64.
with some rearranging the fields we can get it to 16 bytes,
saving 8K in the data section for the 1024 preallocated
structs in the ql arena.

the rest of the changes are of cosmetic nature:

- getqlp() zeros the next pointer, so there is no need to set
  it when queueing the entry.

- always explicitely compare pointers to nil.

- delete unused code from ape's qlock.c
2017-10-28 18:53:27 +02:00
cinap_lenrek 45b7d60bf3 libsec: add AES CFB and AES OFB stream ciphers 2017-10-17 21:34:01 +02:00
cinap_lenrek 346f5828e0 libsec: sha256 support for thumbprint files, use it in ssh as well
initThumbprints() now takes an application tag argument
so x509 and ssh can coexist.

the thumbprint entries can now hold both sha1 and sha256
hashes. okThumbprint() now takes a len argument for the
hash length used.

the new function okCertificate() hashes the certificate
with both and checks for any matches.

on failure, okCertificate() returns 0 and sets error string.

we also check for include loops now in thumbfiles, limiting
the number of includes to 8.
2017-04-23 19:00:08 +02:00
cinap_lenrek 6d42467411 stdio: fix sclose() buffer overrun when terminating string, realloc() error handling (thanks porlock)
theres a bug is in sclose() where it doesnt check if wp is beyond
the buffer. also wp was not updated after realloc().

bug was reported by porlock on 9fans:

Plan 9's implementation of the standard C functions snprintf and
vsnprintf have a buffer overrun bug.

If the buffer length equals the output length (without the terminating
null), then one too many characters is written to the buffer.

For example,
              snprintf(buf, 4, "ABCD");

will write 5 characters to buf.
2016-11-27 21:20:27 +01:00
cinap_lenrek 62d3108646 ape/libsec: add secp384r1 curve parameters for tls 2016-10-30 20:32:03 +01:00
cinap_lenrek 7bcbef11eb ape: fix format clash, %z is for size_t (which is a long currently), not pointer sized 2016-09-14 00:18:45 +02:00
cinap_lenrek a0150376df ape: bring strtod() in line with plan9's libc version 2016-09-11 23:20:55 +02:00
cinap_lenrek 5debddf8af ape: add d_stat struct in dirent struct allowing the avoidance of stats 2016-08-28 03:39:49 +02:00
cinap_lenrek ad6bb37e33 ape/libauth: add PASSWDLEN constant to compile passtokey.c from native libauthsrv (thanks lawler) 2016-08-04 10:38:20 +02:00
cinap_lenrek 1492f46f87 libsec: add scrypt password based key derivation function 2016-07-10 21:41:57 +02:00