[lxc-devel] [lxc/master] oci-template: Add logic for no /etc/passwd, group

ssup2 on Github lxc-bot at linuxcontainers.org
Fri Sep 28 10:27:17 UTC 2018


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 574 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20180928/f480f435/attachment.bin>
-------------- next part --------------
From a2ade420c061173b9055e0db2efb225dcf267fe3 Mon Sep 17 00:00:00 2001
From: Jungsub Shin <supsup5642 at gmail.com>
Date: Fri, 28 Sep 2018 19:21:08 +0900
Subject: [PATCH] oci-template: Add logic for no /etc/passwd, group

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 at tmax.co.kr
---
 templates/lxc-oci.in | 26 ++++++++++++++++++--------
 1 file changed, 18 insertions(+), 8 deletions(-)

diff --git a/templates/lxc-oci.in b/templates/lxc-oci.in
index 6ce31a046..110d03cb6 100644
--- a/templates/lxc-oci.in
+++ b/templates/lxc-oci.in
@@ -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}"


More information about the lxc-devel mailing list