Commit Graph

1458 Commits

Author SHA1 Message Date
Andreas Kling
3b80358142 LibCore: Always fail Account authentication on missing shadow entry
If a user is missing from /etc/shadow, we used to just allow anyone to
authenticate as that user without a password.

With this patch, authentication will instead always fail.
2021-01-21 11:34:39 +01:00
Andreas Kling
439f447ba8 LibCore+su+passwd: Don't keep /etc/passwd and /etc/shadow open
Now that we've moved to atomic replacement of these files when altering
them, we don't need to keep them open for the lifetime of Core::Account
so just simplify this and close them when they are not needed.
2021-01-21 11:17:06 +01:00
Andreas Kling
77e0598c6d passwd+LibCore: Make passwd replace /etc files atomically
Before this patch, we had a nasty race condition when changing a user's
password: there was a time window between truncating /etc/shadow and
writing out its new contents, where you could simply "su" to root
without using a password.

Instead of writing directly to /etc/passwd and /etc/shadow, we now
create temporary files in /etc and fill them with the new contents.
Those files are then atomically renamed to /etc/passwd and /etc/shadow.

Sadly, fixing this race requires giving the passwd program a lot more
privileges. This is something we can and should improve upon. :^)
2021-01-21 11:08:20 +01:00
Nico Weber
65570216b4 oss-fuzz: Try harder to fix build
Apparently memfd_create() is newish in glibc, and oss-fuzz
uses Ubuntu 16.04 as base for its docker images, which doens't
yet have memfd_create(). But, not to worry, it does have the syscall
define and that's all we really need :/
2021-01-20 23:41:38 +01:00
Andreas Kling
19d3f8cab7 Kernel+LibC: Turn errno codes into a strongly typed enum
..and allow implicit creation of KResult and KResultOr from ErrnoCode.
This means that kernel functions that return those types can finally
do "return EINVAL;" and it will just work.

There's a handful of functions that still deal with signed integers
that should be converted to return KResults.
2021-01-20 23:20:02 +01:00
Nico Weber
91aa0d9997 LibGfx/Painter: Keep translation and clip_rect in logical coordinates
Moves Painter away from general affine transport support a bit, but
this scale factor business does feel like it's a bit different.

This is conceptually cleaner (everything should use logical coordinates
as much as possible), and it means the code in GUI::Painter() will work
without changes due to that, but the draw function implementations
overall get a bit murkier (draw_rect() becomes nicer though). Still,
feels like the right direction.

No behavior change.
2021-01-20 21:01:48 +01:00
Linus Groh
17f90e72b4 CrashReporter: Show pledge violation in backtrace 2021-01-20 21:01:15 +01:00
Linus Groh
678919e9c1 Kernel: Set "pledge_violation" coredump metadata in REQUIRE_PROMISE()
Similar to LibC storing an assertion message before aborting, process
death by pledge violation now sets a "pledge_violation" key with the
respective pledge name as value in its coredump metadata, which the
CrashReporter will then show.
2021-01-20 21:01:15 +01:00
Nico Weber
2f82854e4a Revert "LibCore: Try to fix fuzzer build"
This reverts commit c5709c0aed.
2021-01-20 21:00:46 +01:00
Nico Weber
8ccd8b4a6f LibJS: Include <typeinfo> in AST.cpp
Without this, the oss-fuzz build says:

../Userland/Libraries/LibJS/AST.cpp:58:34: error: member access into incomplete type 'const std::type_info'
    return demangle(typeid(*this).name()).substring(4);
                                 ^
2021-01-20 21:00:27 +01:00
Ben Wiederhake
de98f69bfe Userland: Implement shuf for basic shuffling 2021-01-20 19:19:34 +01:00
Ben Wiederhake
9c8efcd17e Userland: Fix broken newlines in 'sort' 2021-01-20 19:19:34 +01:00
Ben Wiederhake
ab07a713bf LibC: Implement uniform random sampling without modulo bias 2021-01-20 19:19:34 +01:00
Ben Wiederhake
e849c62f55 Conway: Don't run misleading srand()
The randomness is taken from arc4random() which is independent from srand/rand/rand_r,
so there's no need to call srand(). At best, it confuses the reader to think that
there would eventually be a call to rand().
2021-01-20 19:19:34 +01:00
Nico Weber
e2dfd028f9 LibGfxScaleDemo: Add coverage for blit_with_alpha 2021-01-20 19:15:03 +01:00
Linus Groh
ea80ff882d Run: Fix newline in info label
This apparently was a workaround for escape sequences in GML at some
point (see #4937), but it now literally inserts "\n" and no newline, as
the backslash itself is escaped.
2021-01-20 19:14:40 +01:00
Nico Weber
c5709c0aed LibCore: Try to fix fuzzer build
This might fix https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=29675
See also `man memfd_create`.
2021-01-20 19:14:04 +01:00
Nico Weber
98637bd549 WindowServer: In HighDPI mode, load high-res window buttons and high-res cursors
Bitmap::load_from_file("foo.png", 2) will now look for "foo-2x.png" and
try load that as a bitmap with scale factor 2 if it exists. If it
doesn't, it falls back to the 1x bitmap as normal.
Only places that know that they'll draw the bitmap to a 2x painter
should pass "2" for the second argument.

Use this new API in WindowServer for loading window buttons and
cursors.

As a testing aid, ctrl-shift-super-i can force HighDPI icons off in
HighDPI mode. Toggling between low-res and high-res icons makes it easy
to see if the high-res version of an icon looks right: It should look
like the low-res version, just less jaggy.

We'll likely have to grow a better API for loading scaled resources, but
for now this suffices.

Things to check:
- `chres 640 480` followed by `chres 640 480 2` followed by
  `chres 640 480`
- window buttons in window context menu (in task bar and on title bar)
  still have low-res icons
- ctrl-shift-super-i in high-res mode toggles sharpness of window
  buttons and of arrow cursorf
- arrow cursor hotspot is still where you'd expect
2021-01-20 10:28:27 +01:00
Nico Weber
5f9c42c404 LibGfx: Give Bitmap a scale factor
Gfx::Bitmap can now store its scale factor. Normally it's 1, but
in high dpi mode it can be 2.

If a Bitmap with a scale factor of 2 is blitted to a Painter with
scale factor of 2, the pixels can be copied over without any resampling.
(When blitting a Bitmap with a scale factor of 1 to a Painter with scale
factor of 2, the Bitmap is painted at twice its width and height at
paint time. Blitting a Bitmap with a scale factor of 2 to a Painter with
scale factor 1 is not supported.)

A Bitmap with scale factor of 2 reports the same width() and height() as
one with scale factor 1. That's important because many places in the
codebase use a bitmap's width() and height() to layout Widgets, and all
widget coordinates are in logical coordinates as well, per
Documentation/HighDPI.md.

Bitmap grows physical_width() / physical_height() to access the actual
pixel size. Update a few callers that work with pixels to call this
instead.

Make Painter's constructor take its scale factor from the target bitmap
that's passed in, and update its various blit() methods to handle
blitting a 2x bitmap to a 2x painter. This allows removing some gnarly
code in Compositor. (In return, put some new gnarly code in
LibGfxScaleDemo to preserve behavior there.)

No intended behavior change.
2021-01-20 10:28:27 +01:00
Linus Groh
c6726f331e WindowServer: Rename WallpaperMode::{Scaled => Stretch}
This option was renamed from scaled to stretch in DisplaySettings in
699ba84, but since WindowServer receives a plain string and was not
updated, it wouldn't recognize the new renamed value as a valid option.
Turns out sending plain strings via IPC and only mapping them to enum
values on the receiving end is brittle, we should probably update
Desktop::set_wallpaper_mode() to use an enum as well at some point.

Fixes #5006.
2021-01-20 09:16:27 +01:00
AnotherTest
cb29dca029 Shell: Don't spam perror() on kill_job()
That function is allowed to be given a dead job, so don't bother with
perror()
2021-01-19 08:19:43 +01:00
AnotherTest
86f50aa74e Shell: Make tests use PASS/FAIL instead of exit codes
There's no guarantee that the last executed command will have a zero
exit code, and so the shell exit code may or may not be zero, even if
all the tests pass.
Also changes the `test || echo fail && exit` to
`if not test { echo fail && exit }`, since that's nicer-looking.
2021-01-19 08:19:43 +01:00
AnotherTest
5ec139e728 Shell: Make 'if' expressions return the unevaluated value of blocks
This makes it possible to actually put them in a sequence and cast them
to commands.
2021-01-19 08:19:43 +01:00
AnotherTest
50473003be Shell: Add a not builtin
`not` just takes a command, runs it, then negates its exit code (0->1,
non-zero->0).
2021-01-19 08:19:43 +01:00
AnotherTest
2843526513 Shell: Mark control structures to be executed in the current process 2021-01-19 08:19:43 +01:00
AnotherTest
1c78d12f1c Shell: Implement for_each_entry() for syntactic list nodes
This allows correct iteration over nested lists.
Also store values to variables without resolving them, to delay the
resolution step as much as possible (this helps with storing nested
lists in variables).
2021-01-19 08:19:43 +01:00
AnotherTest
fc7a06af9d Shell: Consider numbers as word characters too
Otherwise `foobar2` wouldn't be a valid identifier
2021-01-19 08:19:43 +01:00
AnotherTest
8cfda86a45 Shell: Actually return the exit code of the file when running a file 2021-01-19 08:19:43 +01:00
AnotherTest
cd6e5c064b Shell: Add a builtin that parses its sole argument and dumps its AST
Pretty useful for debugging.
2021-01-19 08:19:43 +01:00
Linus Groh
c46056122a LibM: Add nextafter() and nexttoward() stubs
Only thing missing for Python to build the _math module! :^)
2021-01-18 22:28:56 +01:00
Linus Groh
8db54f9ef4 LibC: Return ENOSYS from clock_getres() rather than asserting
This is only a stub function for now, but we can make it even more
useful by just hardcoding an error return value rather than asserting.
2021-01-18 22:28:56 +01:00
Linus Groh
22b56d6a82 LibC: Make tzset() set daylight to 0
Quoting POSIX:

    https://pubs.opengroup.org/onlinepubs/009695399/functions/tzset.html

    The tzset() function also shall set the external variable daylight
    to 0 if Daylight Savings Time conversions should never be applied
    for the timezone in use; otherwise, non-zero.

We're already pretending to be in UTC+0 and setting timezone to 0
accordingly, we can also fake the absence of Daylight Savings Time.
2021-01-18 22:28:56 +01:00
Linus Groh
0d58e75910 LibC: Make tzset() set tzname to { "UTC", "UTC" }
Since tzset() itself pretends to succeed (it just sets timezone = 0 for
now), it seems unwise to leave tzname uninitialized. Since Serenity
already assumes UTC pretty much everywhere time is used, let's continue
that trend here. Quoting POSIX:

    https://pubs.opengroup.org/onlinepubs/009695399/functions/tzset.html

    The tzset() function shall use the value of the environment variable
    TZ to set time conversion information used by ctime(), localtime(),
    mktime(), and strftime(). If TZ is absent from the environment,
    implementation-defined default timezone information shall be used.

So we still don't care about TZ at all, but the program doesn't need to
know! :^)

This matches what musl libc ("UTC") and glibc ("GMT") do, see:

- https://sourceware.org/git/?p=glibc.git;a=blob;f=time/tzset.c
- https://git.musl-libc.org/cgit/musl/tree/src/time/__tz.c
2021-01-18 22:28:56 +01:00
Linus Groh
3c68f557a9 LibC: Add wcstol() and wcstoll() stubs 2021-01-18 22:28:56 +01:00
Linus Groh
ec42f864d4 LibC: Add wcsncmp()
Taken from strncmp(), like wcscmp() in ef40ebb. :^)
2021-01-18 22:28:56 +01:00
Linus Groh
2cc3d68615 Kernel+LibC: Add _SC_TTY_NAME_MAX 2021-01-18 22:28:56 +01:00
Linus Groh
b432fd0bc0 LibC: Add TTY_NAME_MAX (32) 2021-01-18 22:28:56 +01:00
Andreas Kling
93831ef456 LibWeb: Very basic support for CSS flex-direction
The FFC now supports both vertical and horizontal flex layout, based on
the flex-direction property. It's still extremely naive, but at least
now you can be naive in two directions! :^)

This implementation of flexbox is going to take a lot of work, but at
least now we've gotten started.
2021-01-18 20:20:24 +01:00
Andreas Kling
3e8873b63e LibWeb: Add Layout::Box::margin_box_height() 2021-01-18 20:20:20 +01:00
Andreas Kling
149f10b0b9 LibWeb: Parse the CSS "flex-direction" property 2021-01-18 20:20:16 +01:00
Andreas Kling
fd7920fa8f LibWeb: Add a very naive Layout::FlexFormattingContext :^)
This is very dumb and only lays out its child boxes on a horizontal
line with their shrink-to-fit widths.

You have to start somewhere! :^)
2021-01-18 20:20:13 +01:00
Andreas Kling
d18bc9ccd2 LibWeb: Add Layout::Box::margin_box_width() 2021-01-18 20:20:07 +01:00
Andreas Kling
140463e833 LibWeb: Parse "display: flex" and create BlockBox layout nodes for them
I'm not 100% sure that BlockBox is the right layout node for flex
containers, but it's the most obviously fitting one we already have.
2021-01-18 20:20:00 +01:00
Linus Groh
6715ca3e16 LibELF: Remove unused m_global_symbol_lookup_func from DynamicObject
This was refactored in 3e815ad, leaving this unused member behind.
2021-01-18 19:17:52 +01:00
Andreas Kling
9e45594dc8 LibWeb: Stub out the PerformanceTiming object from Navigation Timing
Just have all the timing functions return 0 for now.

We can now run the Shynet JS on https://linus.dev/ although the XHR
is rejected by our same-origin policy.
2021-01-18 15:11:20 +01:00
Andreas Kling
c99e35485a LibWeb: Add support for XMLHttpRequest request headers
Implement XMLHttpRequest.setRequestHeader() and include the headers in
the outgoing HTTP request.
2021-01-18 14:02:58 +01:00
Andreas Kling
0639e77898 LibWeb: Make the Window object "inherit" from EventTarget :^)
Since Web::Bindings::WindowObject inherits from JS::GlobalObject, it
cannot also inherit from Web::Bindings::EventTargetWrapper.

However, that's not actually necessary. Instead, we simply set the
Window object's prototype to the EventTargetPrototype, and add a little
extra branch in the impl_from() function that turns the JS "this" value
into a DOM::EventTarget*.

With this, you can now call window.addEventListener()! Very cool :^)

Fixes #4758.
2021-01-18 12:18:29 +01:00
Andreas Kling
fd83918476 LibWeb: Move IDL attributes and functions to the prototype
Instead of each IDL interface wrapper having its own set of all the
attributes and functions, they are moved to the prototype. This matches
what we already do in LibJS.

Also, this should be spec compliant with the web as well, though there
may be *some* content out there that expects some things to be directly
on the wrapper since that's how things used to work in major browsers
a long time ago. But let's just not worry about that for now.

More work towards #4789
2021-01-18 12:18:29 +01:00
Andreas Kling
630cbc947a LibWeb: Construct the IDL interface prototype chains automatically
Have each IDL prototype trigger the construction of its own prototype.
2021-01-18 12:18:29 +01:00
Andreas Kling
ee7fa49b88 LibWeb: Actually instantiate all the web constructors/prototypes
We now instantiate all the generated web API constructors and expose
them on the window object. We also set the generated prototypes on
instantiated wrappers.

Also, we should obviously find a way to generate this code. :^)
2021-01-18 12:18:29 +01:00