goto not_found;
/* Synthesize entries for the root and nobody users, in case they are missing in /etc/passwd */
- if (streq(name, root_passwd.pw_name)) {
- *pwd = root_passwd;
- *errnop = 0;
- return NSS_STATUS_SUCCESS;
- }
- if (streq(name, nobody_passwd.pw_name)) {
- *pwd = nobody_passwd;
- *errnop = 0;
- return NSS_STATUS_SUCCESS;
+ if (getenv_bool("SYSTEMD_NSS_BYPASS_SYNTHETIC") <= 0) {
+ if (streq(name, root_passwd.pw_name)) {
+ *pwd = root_passwd;
+ *errnop = 0;
+ return NSS_STATUS_SUCCESS;
+ }
+ if (streq(name, nobody_passwd.pw_name)) {
+ *pwd = nobody_passwd;
+ *errnop = 0;
+ return NSS_STATUS_SUCCESS;
+ }
}
/* Make sure that we don't go in circles when allocating a dynamic UID by checking our own database */
goto not_found;
/* Synthesize data for the root user and for nobody in case they are missing from /etc/passwd */
- if (uid == root_passwd.pw_uid) {
- *pwd = root_passwd;
- *errnop = 0;
- return NSS_STATUS_SUCCESS;
- }
- if (uid == nobody_passwd.pw_uid) {
- *pwd = nobody_passwd;
- *errnop = 0;
- return NSS_STATUS_SUCCESS;
+ if (getenv_bool("SYSTEMD_NSS_BYPASS_SYNTHETIC") <= 0) {
+ if (uid == root_passwd.pw_uid) {
+ *pwd = root_passwd;
+ *errnop = 0;
+ return NSS_STATUS_SUCCESS;
+ }
+ if (uid == nobody_passwd.pw_uid) {
+ *pwd = nobody_passwd;
+ *errnop = 0;
+ return NSS_STATUS_SUCCESS;
+ }
}
if (uid <= SYSTEM_UID_MAX)
goto not_found;
/* Synthesize records for root and nobody, in case they are missing form /etc/group */
- if (streq(name, root_group.gr_name)) {
- *gr = root_group;
- *errnop = 0;
- return NSS_STATUS_SUCCESS;
- }
- if (streq(name, nobody_group.gr_name)) {
- *gr = nobody_group;
- *errnop = 0;
- return NSS_STATUS_SUCCESS;
+ if (getenv_bool("SYSTEMD_NSS_BYPASS_SYNTHETIC") <= 0) {
+ if (streq(name, root_group.gr_name)) {
+ *gr = root_group;
+ *errnop = 0;
+ return NSS_STATUS_SUCCESS;
+ }
+ if (streq(name, nobody_group.gr_name)) {
+ *gr = nobody_group;
+ *errnop = 0;
+ return NSS_STATUS_SUCCESS;
+ }
}
if (getenv_bool("SYSTEMD_NSS_DYNAMIC_BYPASS") > 0)
goto not_found;
/* Synthesize records for root and nobody, in case they are missing from /etc/group */
- if (gid == root_group.gr_gid) {
- *gr = root_group;
- *errnop = 0;
- return NSS_STATUS_SUCCESS;
- }
- if (gid == nobody_group.gr_gid) {
- *gr = nobody_group;
- *errnop = 0;
- return NSS_STATUS_SUCCESS;
+ if (getenv_bool("SYSTEMD_NSS_BYPASS_SYNTHETIC") <= 0) {
+ if (gid == root_group.gr_gid) {
+ *gr = root_group;
+ *errnop = 0;
+ return NSS_STATUS_SUCCESS;
+ }
+ if (gid == nobody_group.gr_gid) {
+ *gr = nobody_group;
+ *errnop = 0;
+ return NSS_STATUS_SUCCESS;
+ }
}
if (gid <= SYSTEM_GID_MAX)
}
}
+ /* Let's tell nss-systemd not to synthesize the "root" and "nobody" entries for it, so that our detection
+ * whether the names or UID/GID area already used otherwise doesn't get confused. After all, even though
+ * nss-systemd synthesizes these users/groups, they should still appear in /etc/passwd and /etc/group, as the
+ * synthesizing logic is merely supposed to be fallback for cases where we run with a completely unpopulated
+ * /etc. */
+ if (setenv("SYSTEMD_NSS_BYPASS_SYNTHETIC", "1", 1) < 0) {
+ r = log_error_errno(errno, "Failed to set SYSTEMD_NSS_BYPASS_SYNTHETIC environment variable: %m");
+ goto finish;
+ }
+
if (!uid_range) {
/* Default to default range of 1..SYSTEMD_UID_MAX */
r = uid_range_add(&uid_range, &n_uid_range, 1, SYSTEM_UID_MAX);