]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
oci-template: Add logic for no /etc/passwd, group 2657/head
authorJungsub Shin <supsup5642@gmail.com>
Fri, 28 Sep 2018 10:21:08 +0000 (19:21 +0900)
committerJungsub Shin <supsup5642@gmail.com>
Fri, 28 Sep 2018 10:24:09 +0000 (19:24 +0900)
OCI image spec dosen't specify action when there is
no /etc/passwd or /etc/group. So if there is no
/etc/passwd with string user info, set uid to 0. If there
is no /etc/group with string group info, set gid to 0.

Signed-off-by: Jungsub Shin jungsub_shin@tmax.co.kr
templates/lxc-oci.in

index 6ce31a046605e42a1a413da5823625c0b8f8f66e..110d03cb623d369ec932d62b4acca95a417b5b85 100644 (file)
@@ -151,17 +151,27 @@ getuidgid() {
   usergroup=(${usergroup//:/ })
 
   user=${usergroup[0]:-0}
-  if ! isdecimal "${user}" && [ -f ${passwdpath} ]; then
-    user=$(grep "^${user}:" "${passwdpath}" | awk -F: '{print $3}')
-  else
-    user=0
+  if ! isdecimal "${user}"; then
+    if [ -f ${passwdpath} ]; then
+      user=$(grep "^${user}:" "${passwdpath}" | awk -F: '{print $3}')
+    else
+      user=0
+    fi
   fi
 
   group=${usergroup[1]:-}
-  if [ -z "${group}" ] && [ -f "${passwdpath}" ]; then
-    group=$(grep "^[^:]*:[^:]*:${user}:" "${passwdpath}" | awk -F: '{print $4}')
-  elif ! isdecimal "${group}" && [ -f "${grouppath}" ]; then
-    group=$(grep "^${group}:" "${grouppath}" | awk -F: '{print $3}')
+  if [ -z "${group}" ]; then
+    if [ -f "${passwdpath}" ]; then
+      group=$(grep "^[^:]*:[^:]*:${user}:" "${passwdpath}" | awk -F: '{print $4}')
+    else
+      group=0
+    fi
+  elif ! isdecimal "${group}"; then
+    if [ -f "${grouppath}" ]; then
+      group=$(grep "^${group}:" "${grouppath}" | awk -F: '{print $3}')
+    else
+      group=0
+    fi
   fi
 
   echo "${user:-0} ${group:-0}"