2020-07-30 21:38:15 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
2021-04-22 08:24:48 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-07-30 21:38:15 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <Kernel/Process.h>
|
|
|
|
|
|
|
|
namespace Kernel {
|
|
|
|
|
2021-06-28 18:59:35 +00:00
|
|
|
KResultOr<FlatPtr> Process::sys$gethostname(Userspace<char*> buffer, size_t size)
|
2020-07-30 21:38:15 +00:00
|
|
|
{
|
2021-07-18 18:27:13 +00:00
|
|
|
VERIFY_NO_PROCESS_BIG_LOCK(this)
|
2020-07-30 21:38:15 +00:00
|
|
|
REQUIRE_PROMISE(stdio);
|
2021-06-16 14:44:15 +00:00
|
|
|
if (size > NumericLimits<ssize_t>::max())
|
2021-03-01 12:49:16 +00:00
|
|
|
return EINVAL;
|
2021-07-18 13:00:48 +00:00
|
|
|
return hostname().with_shared([&](const auto& name) -> KResultOr<FlatPtr> {
|
|
|
|
if (size < (name.length() + 1))
|
|
|
|
return ENAMETOOLONG;
|
|
|
|
if (!copy_to_user(buffer, name.characters(), name.length() + 1))
|
|
|
|
return EFAULT;
|
|
|
|
return 0;
|
|
|
|
});
|
2020-07-30 21:38:15 +00:00
|
|
|
}
|
|
|
|
|
2021-07-18 13:00:48 +00:00
|
|
|
KResultOr<FlatPtr> Process::sys$sethostname(Userspace<const char*> buffer, size_t length)
|
2020-07-30 21:38:15 +00:00
|
|
|
{
|
2021-07-18 18:27:13 +00:00
|
|
|
VERIFY_NO_PROCESS_BIG_LOCK(this)
|
2020-07-30 21:38:15 +00:00
|
|
|
REQUIRE_NO_PROMISES;
|
|
|
|
if (!is_superuser())
|
2021-03-01 12:49:16 +00:00
|
|
|
return EPERM;
|
2020-07-30 21:38:15 +00:00
|
|
|
if (length > 64)
|
2021-03-01 12:49:16 +00:00
|
|
|
return ENAMETOOLONG;
|
2021-07-18 13:00:48 +00:00
|
|
|
return hostname().with_exclusive([&](auto& name) -> KResultOr<FlatPtr> {
|
|
|
|
auto copied_hostname = copy_string_from_user(buffer, length);
|
|
|
|
if (copied_hostname.is_null())
|
|
|
|
return EFAULT;
|
|
|
|
name = move(copied_hostname);
|
|
|
|
return 0;
|
|
|
|
});
|
2020-07-30 21:38:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|