Skip to content

Commit b5a0c0c

Browse files
committed
Add a guard against systems with broken /etc/login.defs
1 parent c7572aa commit b5a0c0c

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

CMakeLists.txt

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,14 +167,24 @@ endif()
167167

168168
if(NOT DEFINED UID_MIN)
169169
file(STRINGS "${LOGIN_DEFS_PATH}" UID_MIN LIMIT_COUNT 1 REGEX "^UID_MIN")
170-
STRING(REGEX REPLACE "^UID_MIN[\t ]+([0-9]+)" "\\1" UID_MIN "${UID_MIN}")
171-
message(STATUS "Autodetected UID_MIN=${UID_MIN} from ${LOGIN_DEFS_PATH}")
170+
string(REGEX REPLACE "^UID_MIN[\t ]+([0-9]+)" "\\1" UID_MIN "${UID_MIN}")
171+
if(NOT UID_MIN MATCHES "[0-9]+")
172+
message(WARNING "Could not detect a valid UID_MIN (got '${UID_MIN}'). You should review your login.defs file.")
173+
set(UID_MIN 1000)
174+
else()
175+
message(STATUS "Autodetected UID_MIN=${UID_MIN} from ${LOGIN_DEFS_PATH}")
176+
endif()
172177
endif()
173178

174179
if(NOT DEFINED UID_MAX)
175180
file(STRINGS "${LOGIN_DEFS_PATH}" UID_MAX LIMIT_COUNT 1 REGEX "^UID_MAX")
176-
STRING(REGEX REPLACE "^UID_MAX[\t ]+([0-9]+)" "\\1" UID_MAX "${UID_MAX}")
177-
message(STATUS "Autodetected UID_MAX=${UID_MAX} from ${LOGIN_DEFS_PATH}")
181+
string(REGEX REPLACE "^UID_MAX[\t ]+([0-9]+)" "\\1" UID_MAX "${UID_MAX}")
182+
if(NOT UID_MAX MATCHES "[0-9]+")
183+
message(WARNING "Could not detect a valid UID_MAX (got '${UID_MAX}'). You should review your login.defs file.")
184+
set(UID_MAX 65000)
185+
else()
186+
message(STATUS "Autodetected UID_MAX=${UID_MAX} from ${LOGIN_DEFS_PATH}")
187+
endif()
178188
endif()
179189

180190
# Add subdirectories

0 commit comments

Comments
 (0)