2016-03-03 22:54:15 +08:00
|
|
|
/*
|
|
|
|
|
|
|
|
nsjail - CLONE_NEWUSER routines
|
|
|
|
-----------------------------------------
|
|
|
|
|
|
|
|
Copyright 2014 Google Inc. All Rights Reserved.
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "user.h"
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <grp.h>
|
2017-10-18 20:27:34 +08:00
|
|
|
#include <limits.h>
|
2017-10-01 22:11:46 +08:00
|
|
|
#include <linux/securebits.h>
|
2017-05-27 05:07:47 +08:00
|
|
|
#include <pwd.h>
|
2016-03-03 22:54:15 +08:00
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stddef.h>
|
2017-10-18 20:46:17 +08:00
|
|
|
#include <stdint.h>
|
2016-03-03 22:54:15 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2017-10-01 22:11:46 +08:00
|
|
|
#include <sys/prctl.h>
|
2017-02-08 01:31:50 +08:00
|
|
|
#include <sys/syscall.h>
|
2017-05-27 05:07:47 +08:00
|
|
|
#include <sys/types.h>
|
2016-03-03 22:54:15 +08:00
|
|
|
#include <unistd.h>
|
|
|
|
|
2018-02-11 00:49:15 +08:00
|
|
|
#include "logs.h"
|
2018-02-10 12:25:55 +08:00
|
|
|
#include "macros.h"
|
2018-02-10 01:08:11 +08:00
|
|
|
#include "subproc.h"
|
2018-02-10 01:45:50 +08:00
|
|
|
#include "util.h"
|
2018-02-10 01:08:11 +08:00
|
|
|
|
|
|
|
namespace user {
|
2016-03-03 22:54:15 +08:00
|
|
|
|
2018-02-10 01:08:11 +08:00
|
|
|
static bool setResGid(gid_t gid) {
|
2017-10-17 21:16:27 +08:00
|
|
|
LOG_D("setresgid(%d)", gid);
|
|
|
|
#if defined(__NR_setresgid32)
|
2019-01-22 05:37:30 +08:00
|
|
|
if (util::syscall(__NR_setresgid32, (uintptr_t)gid, (uintptr_t)gid, (uintptr_t)gid) == -1) {
|
2017-10-17 21:16:27 +08:00
|
|
|
PLOG_W("setresgid32(%d)", (int)gid);
|
|
|
|
return false;
|
|
|
|
}
|
2017-10-26 06:26:02 +08:00
|
|
|
#else /* defined(__NR_setresgid32) */
|
2019-01-22 05:37:30 +08:00
|
|
|
if (util::syscall(__NR_setresgid, (uintptr_t)gid, (uintptr_t)gid, (uintptr_t)gid) == -1) {
|
2017-10-17 21:16:27 +08:00
|
|
|
PLOG_W("setresgid(%d)", gid);
|
|
|
|
return false;
|
|
|
|
}
|
2017-10-19 08:14:58 +08:00
|
|
|
#endif /* defined(__NR_setresuid32) */
|
2017-10-17 21:16:27 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-02-10 01:08:11 +08:00
|
|
|
static bool setResUid(uid_t uid) {
|
2017-10-17 21:16:27 +08:00
|
|
|
LOG_D("setresuid(%d)", uid);
|
|
|
|
#if defined(__NR_setresuid32)
|
2019-01-22 05:37:30 +08:00
|
|
|
if (util::syscall(__NR_setresuid32, (uintptr_t)uid, (uintptr_t)uid, (uintptr_t)uid) == -1) {
|
2017-10-17 21:16:27 +08:00
|
|
|
PLOG_W("setresuid32(%d)", (int)uid);
|
|
|
|
return false;
|
|
|
|
}
|
2017-10-26 06:26:02 +08:00
|
|
|
#else /* defined(__NR_setresuid32) */
|
2019-01-22 05:37:30 +08:00
|
|
|
if (util::syscall(__NR_setresuid, (uintptr_t)uid, (uintptr_t)uid, (uintptr_t)uid) == -1) {
|
2017-10-17 21:16:27 +08:00
|
|
|
PLOG_W("setresuid(%d)", uid);
|
|
|
|
return false;
|
|
|
|
}
|
2017-10-19 08:14:58 +08:00
|
|
|
#endif /* defined(__NR_setresuid32) */
|
2017-10-17 21:16:27 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-03-31 21:16:24 +08:00
|
|
|
static bool setGroupsDeny(nsjconf_t* nsjconf, pid_t pid) {
|
2016-03-03 22:54:15 +08:00
|
|
|
/*
|
2017-10-17 21:22:23 +08:00
|
|
|
* No need to write 'deny' to /proc/pid/setgroups if our euid==0, as writing to
|
|
|
|
* uid_map/gid_map will succeed anyway
|
2016-03-03 22:54:15 +08:00
|
|
|
*/
|
2019-03-30 04:38:14 +08:00
|
|
|
if (!nsjconf->clone_newuser || nsjconf->orig_euid == 0) {
|
2016-03-03 22:54:15 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
char fname[PATH_MAX];
|
|
|
|
snprintf(fname, sizeof(fname), "/proc/%d/setgroups", pid);
|
2019-06-29 01:08:21 +08:00
|
|
|
const char* const denystr = "deny";
|
2018-02-10 01:45:50 +08:00
|
|
|
if (!util::writeBufToFile(fname, denystr, strlen(denystr), O_WRONLY | O_CLOEXEC)) {
|
|
|
|
LOG_E("util::writeBufToFile('%s', '%s') failed", fname, denystr);
|
2016-03-03 22:54:15 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-02-10 22:50:12 +08:00
|
|
|
static bool uidMapSelf(nsjconf_t* nsjconf, pid_t pid) {
|
2018-02-11 11:02:14 +08:00
|
|
|
std::string map;
|
2018-02-10 07:37:23 +08:00
|
|
|
for (const auto& uid : nsjconf->uids) {
|
|
|
|
if (uid.is_newidmap) {
|
2017-05-28 07:05:27 +08:00
|
|
|
continue;
|
|
|
|
}
|
2018-02-11 11:02:14 +08:00
|
|
|
map.append(std::to_string(uid.inside_id));
|
|
|
|
map.append(" ");
|
|
|
|
map.append(std::to_string(uid.outside_id));
|
|
|
|
map.append(" ");
|
|
|
|
map.append(std::to_string(uid.count));
|
|
|
|
map.append("\n");
|
|
|
|
}
|
|
|
|
if (map.empty()) {
|
2017-05-28 07:05:27 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-02-11 11:02:14 +08:00
|
|
|
char fname[PATH_MAX];
|
|
|
|
snprintf(fname, sizeof(fname), "/proc/%d/uid_map", pid);
|
|
|
|
LOG_D("Writing '%s' to '%s'", map.c_str(), fname);
|
|
|
|
if (!util::writeBufToFile(fname, map.data(), map.length(), O_WRONLY | O_CLOEXEC)) {
|
|
|
|
LOG_E("util::writeBufToFile('%s', '%s') failed", fname, map.c_str());
|
2016-03-03 22:54:15 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-09-25 20:30:19 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-02-10 22:50:12 +08:00
|
|
|
static bool gidMapSelf(nsjconf_t* nsjconf, pid_t pid) {
|
2018-02-11 11:02:14 +08:00
|
|
|
std::string map;
|
2018-02-10 07:37:23 +08:00
|
|
|
for (const auto& gid : nsjconf->gids) {
|
|
|
|
if (gid.is_newidmap) {
|
2017-05-28 07:05:27 +08:00
|
|
|
continue;
|
|
|
|
}
|
2018-02-11 11:02:14 +08:00
|
|
|
map.append(std::to_string(gid.inside_id));
|
|
|
|
map.append(" ");
|
|
|
|
map.append(std::to_string(gid.outside_id));
|
|
|
|
map.append(" ");
|
|
|
|
map.append(std::to_string(gid.count));
|
|
|
|
map.append("\n");
|
|
|
|
}
|
|
|
|
if (map.empty()) {
|
2017-05-28 07:05:27 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-02-11 11:02:14 +08:00
|
|
|
char fname[PATH_MAX];
|
|
|
|
snprintf(fname, sizeof(fname), "/proc/%d/gid_map", pid);
|
|
|
|
LOG_D("Writing '%s' to '%s'", map.c_str(), fname);
|
|
|
|
if (!util::writeBufToFile(fname, map.data(), map.length(), O_WRONLY | O_CLOEXEC)) {
|
|
|
|
LOG_E("util::writeBufToFile('%s', '%s') failed", fname, map.c_str());
|
2016-03-03 22:54:15 +08:00
|
|
|
return false;
|
|
|
|
}
|
2017-02-08 07:36:32 +08:00
|
|
|
|
2016-03-03 22:54:15 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-10-12 08:01:12 +08:00
|
|
|
/* Use /usr/bin/newgidmap for writing the gid map */
|
2018-02-10 22:50:12 +08:00
|
|
|
static bool gidMapExternal(nsjconf_t* nsjconf, pid_t pid UNUSED) {
|
2017-05-28 07:16:48 +08:00
|
|
|
bool use = false;
|
2018-02-11 11:02:14 +08:00
|
|
|
|
2018-02-11 11:02:43 +08:00
|
|
|
std::vector<std::string> argv = {"/usr/bin/newgidmap", std::to_string(pid)};
|
2018-02-10 07:37:23 +08:00
|
|
|
for (const auto& gid : nsjconf->gids) {
|
2018-02-11 11:02:14 +08:00
|
|
|
if (!gid.is_newidmap) {
|
2017-05-28 07:05:27 +08:00
|
|
|
continue;
|
|
|
|
}
|
2017-05-28 07:16:48 +08:00
|
|
|
use = true;
|
2016-10-12 08:01:12 +08:00
|
|
|
|
2018-02-11 11:02:14 +08:00
|
|
|
argv.push_back(std::to_string(gid.inside_id));
|
|
|
|
argv.push_back(std::to_string(gid.outside_id));
|
|
|
|
argv.push_back(std::to_string(gid.count));
|
2016-09-25 20:30:19 +08:00
|
|
|
}
|
2017-05-28 07:16:48 +08:00
|
|
|
if (!use) {
|
2017-05-28 07:05:27 +08:00
|
|
|
return true;
|
|
|
|
}
|
2018-02-10 01:45:50 +08:00
|
|
|
if (subproc::systemExe(argv, environ) != 0) {
|
2016-10-12 08:01:12 +08:00
|
|
|
LOG_E("'/usr/bin/newgidmap' failed");
|
2016-10-12 06:59:10 +08:00
|
|
|
return false;
|
2016-09-25 20:30:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-10-12 08:01:12 +08:00
|
|
|
/* Use /usr/bin/newuidmap for writing the uid map */
|
2018-02-10 22:50:12 +08:00
|
|
|
static bool uidMapExternal(nsjconf_t* nsjconf, pid_t pid UNUSED) {
|
2017-05-28 07:16:48 +08:00
|
|
|
bool use = false;
|
2018-02-11 11:02:14 +08:00
|
|
|
|
2018-02-11 11:02:43 +08:00
|
|
|
std::vector<std::string> argv = {"/usr/bin/newuidmap", std::to_string(pid)};
|
2018-02-10 07:37:23 +08:00
|
|
|
for (const auto& uid : nsjconf->uids) {
|
2018-02-11 11:02:14 +08:00
|
|
|
if (!uid.is_newidmap) {
|
2017-05-28 07:05:27 +08:00
|
|
|
continue;
|
|
|
|
}
|
2017-05-28 07:16:48 +08:00
|
|
|
use = true;
|
2016-10-12 08:01:12 +08:00
|
|
|
|
2018-02-11 11:02:14 +08:00
|
|
|
argv.push_back(std::to_string(uid.inside_id));
|
|
|
|
argv.push_back(std::to_string(uid.outside_id));
|
|
|
|
argv.push_back(std::to_string(uid.count));
|
2016-09-25 20:30:19 +08:00
|
|
|
}
|
2017-05-28 07:16:48 +08:00
|
|
|
if (!use) {
|
2017-05-28 07:05:27 +08:00
|
|
|
return true;
|
|
|
|
}
|
2018-02-10 01:45:50 +08:00
|
|
|
if (subproc::systemExe(argv, environ) != 0) {
|
2016-10-12 08:01:12 +08:00
|
|
|
LOG_E("'/usr/bin/newuidmap' failed");
|
2016-10-12 06:59:10 +08:00
|
|
|
return false;
|
2016-09-25 20:30:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-02-10 22:50:12 +08:00
|
|
|
static bool uidGidMap(nsjconf_t* nsjconf, pid_t pid) {
|
2019-01-01 18:36:02 +08:00
|
|
|
RETURN_ON_FAILURE(gidMapSelf(nsjconf, pid));
|
|
|
|
RETURN_ON_FAILURE(gidMapExternal(nsjconf, pid));
|
|
|
|
RETURN_ON_FAILURE(uidMapSelf(nsjconf, pid));
|
|
|
|
RETURN_ON_FAILURE(uidMapExternal(nsjconf, pid));
|
|
|
|
|
2017-05-28 07:05:27 +08:00
|
|
|
return true;
|
2016-09-25 20:30:19 +08:00
|
|
|
}
|
|
|
|
|
2018-02-10 22:50:12 +08:00
|
|
|
bool initNsFromParent(nsjconf_t* nsjconf, pid_t pid) {
|
2019-03-31 21:16:24 +08:00
|
|
|
if (!setGroupsDeny(nsjconf, pid)) {
|
2016-03-03 22:54:15 +08:00
|
|
|
return false;
|
|
|
|
}
|
2018-02-12 22:17:33 +08:00
|
|
|
if (!nsjconf->clone_newuser) {
|
2017-10-01 21:54:04 +08:00
|
|
|
return true;
|
|
|
|
}
|
2018-02-12 22:17:33 +08:00
|
|
|
if (!uidGidMap(nsjconf, pid)) {
|
2016-03-03 22:54:15 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2017-02-08 01:31:50 +08:00
|
|
|
|
2018-02-10 22:50:12 +08:00
|
|
|
bool initNsFromChild(nsjconf_t* nsjconf) {
|
2019-03-30 04:38:14 +08:00
|
|
|
if (!nsjconf->clone_newuser && nsjconf->orig_euid != 0) {
|
|
|
|
return true;
|
2017-02-08 01:31:50 +08:00
|
|
|
}
|
2017-10-01 11:16:01 +08:00
|
|
|
|
2017-10-02 01:01:36 +08:00
|
|
|
/*
|
2017-10-17 21:22:23 +08:00
|
|
|
* Make sure all capabilities are retained after the subsequent setuid/setgid, as they will
|
|
|
|
* be needed for privileged operations: mounts, uts change etc.
|
2017-10-02 01:01:36 +08:00
|
|
|
*/
|
2017-10-26 06:26:02 +08:00
|
|
|
if (prctl(PR_SET_SECUREBITS, SECBIT_KEEP_CAPS | SECBIT_NO_SETUID_FIXUP, 0UL, 0UL, 0UL) ==
|
|
|
|
-1) {
|
2017-10-02 01:01:36 +08:00
|
|
|
PLOG_E("prctl(PR_SET_SECUREBITS, SECBIT_KEEP_CAPS | SECBIT_NO_SETUID_FIXUP)");
|
2017-10-01 22:11:46 +08:00
|
|
|
return false;
|
2017-10-01 11:16:01 +08:00
|
|
|
}
|
|
|
|
|
2019-03-30 04:38:14 +08:00
|
|
|
/*
|
2019-06-20 17:45:27 +08:00
|
|
|
* Best effort because of /proc/self/setgroups. We deny
|
|
|
|
* setgroups(2) calls only if user namespaces are in use.
|
2019-03-30 04:38:14 +08:00
|
|
|
*/
|
2019-06-20 17:45:27 +08:00
|
|
|
std::vector<gid_t> groups;
|
|
|
|
std::string groupsString = "[";
|
|
|
|
if (!nsjconf->clone_newuser && nsjconf->gids.size() > 1) {
|
|
|
|
for (auto it = nsjconf->gids.begin() + 1; it != nsjconf->gids.end(); it++) {
|
|
|
|
groups.push_back(it->inside_id);
|
|
|
|
groupsString += std::to_string(it->inside_id);
|
2019-06-28 19:31:43 +08:00
|
|
|
if (it < nsjconf->gids.end() - 1) groupsString += ", ";
|
2019-06-20 17:45:27 +08:00
|
|
|
}
|
2019-03-30 04:38:14 +08:00
|
|
|
}
|
2019-06-20 17:45:27 +08:00
|
|
|
groupsString += "]";
|
2019-03-30 04:38:14 +08:00
|
|
|
|
2018-02-10 07:37:23 +08:00
|
|
|
if (!setResGid(nsjconf->gids[0].inside_id)) {
|
|
|
|
PLOG_E("setresgid(%u)", nsjconf->gids[0].inside_id);
|
2017-02-08 01:31:50 +08:00
|
|
|
return false;
|
|
|
|
}
|
2019-06-20 17:45:27 +08:00
|
|
|
|
|
|
|
LOG_D("setgroups(%lu, %s)", groups.size(), groupsString.c_str());
|
|
|
|
if (setgroups(groups.size(), groups.data()) == -1) {
|
2019-06-29 01:08:21 +08:00
|
|
|
/* Indicate error if specific groups were requested */
|
2019-06-28 19:31:43 +08:00
|
|
|
if (groups.size() > 0) {
|
|
|
|
PLOG_E("setgroups(%lu, %s) failed", groups.size(), groupsString.c_str());
|
|
|
|
return false;
|
|
|
|
}
|
2019-06-20 17:45:27 +08:00
|
|
|
PLOG_D("setgroups(%lu, %s) failed", groups.size(), groupsString.c_str());
|
|
|
|
}
|
|
|
|
|
2018-02-10 07:37:23 +08:00
|
|
|
if (!setResUid(nsjconf->uids[0].inside_id)) {
|
|
|
|
PLOG_E("setresuid(%u)", nsjconf->uids[0].inside_id);
|
2017-02-08 01:31:50 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-07-01 20:51:32 +08:00
|
|
|
/*
|
|
|
|
* Disable securebits again to avoid spawned programs
|
|
|
|
* unexpectedly retaining capabilities after a UID/GID
|
|
|
|
* change.
|
|
|
|
*/
|
|
|
|
if (prctl(PR_SET_SECUREBITS, 0UL, 0UL, 0UL, 0UL) == -1) {
|
|
|
|
PLOG_E("prctl(PR_SET_SECUREBITS, 0)");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-02-08 01:31:50 +08:00
|
|
|
return true;
|
|
|
|
}
|
2017-05-27 05:07:47 +08:00
|
|
|
|
2018-02-11 21:56:30 +08:00
|
|
|
static uid_t parseUid(const std::string& id) {
|
|
|
|
if (id.empty()) {
|
2017-05-27 05:07:47 +08:00
|
|
|
return getuid();
|
|
|
|
}
|
2018-02-11 21:56:30 +08:00
|
|
|
struct passwd* pw = getpwnam(id.c_str());
|
2017-05-27 05:07:47 +08:00
|
|
|
if (pw != NULL) {
|
|
|
|
return pw->pw_uid;
|
|
|
|
}
|
2018-02-11 21:56:30 +08:00
|
|
|
if (util::isANumber(id.c_str())) {
|
2018-05-26 19:54:17 +08:00
|
|
|
return (uid_t)strtoimax(id.c_str(), NULL, 0);
|
2017-05-27 05:07:47 +08:00
|
|
|
}
|
2017-12-02 09:53:32 +08:00
|
|
|
return (uid_t)-1;
|
2017-05-27 05:07:47 +08:00
|
|
|
}
|
|
|
|
|
2018-02-11 21:56:30 +08:00
|
|
|
static gid_t parseGid(const std::string& id) {
|
|
|
|
if (id.empty()) {
|
2017-05-27 05:07:47 +08:00
|
|
|
return getgid();
|
|
|
|
}
|
2018-02-11 21:56:30 +08:00
|
|
|
struct group* gr = getgrnam(id.c_str());
|
2017-05-27 05:07:47 +08:00
|
|
|
if (gr != NULL) {
|
|
|
|
return gr->gr_gid;
|
|
|
|
}
|
2018-02-11 21:56:30 +08:00
|
|
|
if (util::isANumber(id.c_str())) {
|
2018-05-26 19:54:17 +08:00
|
|
|
return (gid_t)strtoimax(id.c_str(), NULL, 0);
|
2017-05-27 05:07:47 +08:00
|
|
|
}
|
2017-12-02 09:53:32 +08:00
|
|
|
return (gid_t)-1;
|
2017-05-27 05:07:47 +08:00
|
|
|
}
|
|
|
|
|
2018-02-11 21:56:30 +08:00
|
|
|
bool parseId(nsjconf_t* nsjconf, const std::string& i_id, const std::string& o_id, size_t cnt,
|
|
|
|
bool is_gid, bool is_newidmap) {
|
|
|
|
if (cnt < 1) {
|
|
|
|
cnt = 1;
|
|
|
|
}
|
|
|
|
|
2017-05-27 05:07:47 +08:00
|
|
|
uid_t inside_id;
|
|
|
|
uid_t outside_id;
|
|
|
|
|
|
|
|
if (is_gid) {
|
2018-02-10 01:08:11 +08:00
|
|
|
inside_id = parseGid(i_id);
|
2017-10-09 05:00:45 +08:00
|
|
|
if (inside_id == (uid_t)-1) {
|
2018-02-11 21:56:30 +08:00
|
|
|
LOG_W("Cannot parse '%s' as GID", i_id.c_str());
|
2017-05-28 07:05:27 +08:00
|
|
|
return false;
|
2017-05-27 05:07:47 +08:00
|
|
|
}
|
2018-02-10 01:08:11 +08:00
|
|
|
outside_id = parseGid(o_id);
|
2017-12-02 09:53:32 +08:00
|
|
|
if (outside_id == (uid_t)-1) {
|
2018-02-11 21:56:30 +08:00
|
|
|
LOG_W("Cannot parse '%s' as GID", o_id.c_str());
|
2017-05-28 07:05:27 +08:00
|
|
|
return false;
|
2017-05-27 05:07:47 +08:00
|
|
|
}
|
|
|
|
} else {
|
2018-02-10 01:08:11 +08:00
|
|
|
inside_id = parseUid(i_id);
|
2017-10-09 05:00:45 +08:00
|
|
|
if (inside_id == (uid_t)-1) {
|
2018-02-11 21:56:30 +08:00
|
|
|
LOG_W("Cannot parse '%s' as UID", i_id.c_str());
|
2017-05-28 07:05:27 +08:00
|
|
|
return false;
|
2017-05-27 05:07:47 +08:00
|
|
|
}
|
2018-02-10 01:08:11 +08:00
|
|
|
outside_id = parseUid(o_id);
|
2017-12-02 09:53:32 +08:00
|
|
|
if (outside_id == (uid_t)-1) {
|
2018-02-11 21:56:30 +08:00
|
|
|
LOG_W("Cannot parse '%s' as UID", o_id.c_str());
|
2017-05-28 07:05:27 +08:00
|
|
|
return false;
|
2017-05-27 05:07:47 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-10 22:50:12 +08:00
|
|
|
idmap_t id;
|
2018-02-10 07:37:23 +08:00
|
|
|
id.inside_id = inside_id;
|
|
|
|
id.outside_id = outside_id;
|
|
|
|
id.count = cnt;
|
|
|
|
id.is_newidmap = is_newidmap;
|
2017-05-28 07:05:27 +08:00
|
|
|
|
|
|
|
if (is_gid) {
|
2018-02-10 07:37:23 +08:00
|
|
|
nsjconf->gids.push_back(id);
|
2017-05-28 07:05:27 +08:00
|
|
|
} else {
|
2018-02-10 07:37:23 +08:00
|
|
|
nsjconf->uids.push_back(id);
|
2017-05-28 07:05:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2017-05-27 05:07:47 +08:00
|
|
|
}
|
2018-02-10 01:08:11 +08:00
|
|
|
|
|
|
|
} // namespace user
|