mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 19:17:41 +00:00
Kernel+Userland: Add "settime" pledge promise for setting system time
We now require the "settime" promise from pledged processes who want to change the system time.
This commit is contained in:
parent
1cddb1055f
commit
5bfd893292
4 changed files with 29 additions and 22 deletions
|
@ -44,6 +44,7 @@ If `promises` or `execpromises` is null, the corresponding value is unchanged.
|
|||
* `shared_buffer`: Shared memory buffers (\*)
|
||||
* `chroot`: The [`chroot(2)`](chroot.md) syscall (\*)
|
||||
* `video`: May use [`ioctl(2)`](ioctl.md) and [`mmap(2)`](mmap.md) on framebuffer video devices
|
||||
* `settime`: Changing the system time and date
|
||||
|
||||
Promises marked with an asterisk (\*) are SerenityOS specific extensions not supported by the original OpenBSD `pledge()`.
|
||||
|
||||
|
|
|
@ -4360,7 +4360,7 @@ int Process::sys$clock_gettime(clockid_t clock_id, timespec* user_ts)
|
|||
|
||||
int Process::sys$clock_settime(clockid_t clock_id, timespec* user_ts)
|
||||
{
|
||||
REQUIRE_PROMISE(stdio);
|
||||
REQUIRE_PROMISE(settime);
|
||||
|
||||
if (!is_superuser())
|
||||
return -EPERM;
|
||||
|
|
|
@ -71,6 +71,7 @@ extern VirtualAddress g_return_to_ring3_from_signal_trampoline;
|
|||
__ENUMERATE_PLEDGE_PROMISE(thread) \
|
||||
__ENUMERATE_PLEDGE_PROMISE(video) \
|
||||
__ENUMERATE_PLEDGE_PROMISE(accept) \
|
||||
__ENUMERATE_PLEDGE_PROMISE(settime) \
|
||||
__ENUMERATE_PLEDGE_PROMISE(shared_buffer)
|
||||
|
||||
enum class Pledge : u32 {
|
||||
|
|
|
@ -26,13 +26,14 @@
|
|||
|
||||
#include <AK/String.h>
|
||||
#include <LibCore/DateTime.h>
|
||||
#include <LibCore/DateTime.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
if (pledge("stdio", nullptr) < 0) {
|
||||
if (pledge("stdio settime", nullptr) < 0) {
|
||||
perror("pledge");
|
||||
return 1;
|
||||
}
|
||||
|
@ -47,10 +48,14 @@ int main(int argc, char** argv)
|
|||
bool ok;
|
||||
timespec ts = { String(argv[2]).to_uint(ok), 0 };
|
||||
if (!ok) {
|
||||
printf("date: Invalid timestamp value\n");
|
||||
fprintf(stderr, "date: Invalid timestamp value");
|
||||
return 1;
|
||||
}
|
||||
return clock_settime(CLOCK_REALTIME, &ts);
|
||||
if (clock_settime(CLOCK_REALTIME, &ts) < 0) {
|
||||
perror("clock_settime");
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
printf("%s\n", Core::DateTime::from_timestamp(now).to_string().characters());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue