From: Jungsub Shin Date: Fri, 28 Sep 2018 10:21:08 +0000 (+0900) Subject: oci-template: Add logic for no /etc/passwd, group X-Git-Tag: lxc-3.1.0~77^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a2ade420c061173b9055e0db2efb225dcf267fe3;p=thirdparty%2Flxc.git 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@tmax.co.kr --- 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}"