From: Subrata <sub...@us...> - 2009-07-07 14:30:56
|
Update of /cvsroot/ltp/ltp In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv27640/ltp Modified Files: IDcheck.sh Log Message: Make IDcheck.sh DESTDIR aware and less strict: The end goal of this patch is to make IDcheck.sh more rootfs- / cross- compilation friendly, such that it can be run from the primary compile instance, and instead of attempting to manipulate the target system data, manipulate the sys-root / rootfs data through the use of DESTDIR and by relaxing certain checks. Most of the checks were unnecessary anyhow (am i root?), etc and can be easily remedied by just relying on the other checks made by touch(1)'ing files and the post-process operation, as ENOPERM will be returned if one cannot access the configuration file of interest. Also, use awk for all operations instead of grep because it will reduces the potential for random failures when dealing with /etc/group and /etc/passwd files, and we can switch over to one subroutine instead of multiple subroutines for checks. Signed-off-by: Garrett Cooper <yan...@gm...>. Index: IDcheck.sh =================================================================== RCS file: /cvsroot/ltp/ltp/IDcheck.sh,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** IDcheck.sh 29 Sep 2008 18:12:16 -0000 1.18 --- IDcheck.sh 7 Jul 2009 14:30:27 -0000 1.19 *************** *** 36,68 **** NO_USERS_GRP=1 NO_SYS_GRP=1 - I_AM_ROOT=0 ! # ! # id(1) for entry. ! # ! ife() { ! id "$@" > /dev/null ! } ! # ! # grep(1) for entry. ! # ! gfe() { ! grep -q "$@" } prompt_for_create() { ! if [ -n "$CREATE_ENTRIES" ] ; then ! ! if [ $I_AM_ROOT -eq 0 ] ; then ! echo "Not root; can't create user / group entries on local machine". ! CREATE_ENTRIES=0 ! fi ! echo "CREATE_ENTRIES variable set to $CREATE_ENTRIES ..." ! echo ! ! else ! if [ $NO_NOBODY_ID -ne 0 -o $NO_BIN_ID -ne 0 -o $NO_DAEMON_ID -ne 0 -o $NO_NOBODY_GRP -ne 0 -o $NO_BIN_GRP -ne 0 -o $NO_DAEMON_GRP -ne 0 -o $NO_USERS_GRP -ne 0 -o $NO_SYS_GRP -ne 0 -a $I_AM_ROOT -ne 0 ] ; then echo -n "If any required user ids and/or groups are missing, would you like these created? [y/N]" read ans --- 36,57 ---- NO_USERS_GRP=1 NO_SYS_GRP=1 ! group="$DESTDIR/etc/group" ! passwd="$DESTDIR/etc/passwd" ! # find entry. ! fe() { ! ID=$1; shift ! FILE=$1; shift ! awk "/^$ID:/ { FOUND=1 } END { if (\$FOUND == 1) { exit 0; } exit 1; }" \ ! "$FILE" ! ec=$? ! echo "$ID => $ec" } prompt_for_create() { ! if [ -z "$CREATE_ENTRIES" ] ; then ! if [ $NO_NOBODY_ID -ne 0 -o $NO_BIN_ID -ne 0 -o $NO_DAEMON_ID -ne 0 -o $NO_NOBODY_GRP -ne 0 -o $NO_BIN_GRP -ne 0 -o $NO_DAEMON_GRP -ne 0 -o $NO_USERS_GRP -ne 0 -o $NO_SYS_GRP -ne 0 ] ; then echo -n "If any required user ids and/or groups are missing, would you like these created? [y/N]" read ans *************** *** 82,106 **** fi ! if [ -e /etc/passwd -a ! -r /etc/passwd ] ; then echo "/etc/passwd not readable by uid $EUID" exit 1 ! elif [ -e /etc/group -a ! -r /etc/group ] ; then ! echo "/etc/group not readable by uid $EUID" exit 1 fi ! ife bin; NO_BIN_ID=$? ! ife daemon; NO_DAEMON_ID=$? ! ife nobody; NO_NOBODY_ID=$? ! ! gfe '^bin:' /etc/group; NO_BIN_GRP=$? ! gfe '^daemon:' /etc/group; NO_DAEMON_GRP=$? ! gfe '^nobody:' /etc/group; NO_NOBODY_GRP=$? ! gfe '^sys:' /etc/group; NO_SYS_GRP=$? ! gfe '^users:' /etc/group; NO_USERS_GRP=$? ! if [ $EUID -eq 0 ] ; then ! I_AM_ROOT=1 ! fi prompt_for_create --- 71,91 ---- fi ! if [ -e "$passwd" -a ! -r "$passwd" ] ; then echo "/etc/passwd not readable by uid $EUID" exit 1 ! elif [ -e "$group" -a ! -r "$group" ] ; then ! echo "$group not readable by uid $EUID" exit 1 fi ! fe bin "$passwd"; NO_BIN_ID=$? ! fe daemon "$passwd"; NO_DAEMON_ID=$? ! fe nobody "$passwd"; NO_NOBODY_ID=$? ! fe bin "$group"; NO_BIN_GRP=$? ! fe daemon "$group"; NO_DAEMON_GRP=$? ! fe nobody "$group"; NO_NOBODY_GRP=$? ! fe sys "$group"; NO_SYS_GRP=$? ! fe users "$group"; NO_USERS_GRP=$? prompt_for_create *************** *** 109,112 **** --- 94,99 ---- echo "Missing the following group / user entries:" + echo "Group file: $group" + echo "Password file: $passwd" echo "nobody: $NO_NOBODY_ID" echo "bin: $NO_BIN_ID" *************** *** 118,123 **** echo "users grp: $NO_USERS_GRP" echo "" - echo "i am root: $I_AM_ROOT" - echo "" } --- 105,108 ---- *************** *** 126,131 **** if [ $CREATE_ENTRIES -ne 0 ] ; then ! if ! touch /etc/group ; then ! echo "Couldn't touch /etc/group" exit 1 fi --- 111,116 ---- if [ $CREATE_ENTRIES -ne 0 ] ; then ! if ! touch "$group" ; then ! echo "Couldn't touch $group" exit 1 fi *************** *** 142,150 **** # Avoid chicken and egg issue with id(1) call # made above and below. ! if ! gfe "^${name}:" /etc/passwd && [ $no_id -ne 0 ] ; then ! echo "${name}:x:${id}:${id}:${name}::" >> /etc/passwd fi if [ $no_grp -ne 0 ] ; then ! echo "${name}:x:$(id -u ${name}):" >> /etc/group fi fi --- 127,135 ---- # Avoid chicken and egg issue with id(1) call # made above and below. ! if ! fe "$name" "$passwd" && [ $no_id -ne 0 ] ; then ! echo "${name}:x:${id}:${id}:${name}::" >> "$passwd" fi if [ $no_grp -ne 0 ] ; then ! echo "${name}:x:$(id -u ${name}):" >> "$group" fi fi *************** *** 157,161 **** echo "Users group found." elif [ $CREATE_ENTRIES -ne 0 ] ; then ! echo 'users:x:100:' >> /etc/group fi --- 142,146 ---- echo "Users group found." elif [ $CREATE_ENTRIES -ne 0 ] ; then ! echo 'users:x:100:' >> "$group" fi *************** *** 163,177 **** echo "Sys group found." elif [ $CREATE_ENTRIES -ne 0 ] ; then ! echo 'sys:x:3:' >> /etc/group fi ! if ife nobody && ife bin && ife daemon && ! ife -g nobody && ife -g bin && ife -g daemon && ! gfe '^users:' /etc/group && gfe '^sys:' /etc/group && ! gfe '^nobody:' /etc/group ! then ! echo "" ! echo "Required users/groups exist." ! exit 0 fi --- 148,179 ---- echo "Sys group found." elif [ $CREATE_ENTRIES -ne 0 ] ; then ! echo 'sys:x:3:' >> "$group" fi ! MISSING_ENTRY=0 ! ! # For entries that exist in both $group and $passwd. ! for i in nobody bin daemon; do ! for file in "$group" "$passwd"; do ! if ! fe "$i" "$file"; then ! MISSING_ENTRY=1 ! break ! fi ! done ! if [ $MISSING_ENTRY -ne 0 ]; then ! break ! fi ! done ! ! # For entries that only exist in $group. ! for i in users sys; do ! if ! fe "$i" "$file"; then ! MISSING_ENTRY=1 ! fi ! done ! ! if [ $MISSING_ENTRY -eq 0 ] ; then ! echo "Required users/groups exist." ! exit 0 fi |