Changeset 2664 for trunk/locker/sbin


Ignore:
Timestamp:
Jan 30, 2015, 3:08:26 AM (9 years ago)
Author:
andersk
Message:
check-users: Improve error diagnosis and script hygiene
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/locker/sbin/check-users

    r981 r2664  
    11#!/bin/bash
    2 set -e
     2set -eu
    33
    44err() {
     5    ok=
    56    echo "$@"
    67}
    78
    8 if [ -z "$1" ]; then
     9if [ $# -eq 0 ]; then
    910    filter="objectClass=posixAccount"
    1011else
     
    1819unset "${!l_@}"
    1920while read attr value; do
     21    ok=t
    2022    if [ -n "$attr" ]; then
    2123        declare "l_${attr%:}=$value"
     
    2325    fi
    2426
    25     read f_type f_data < <(hesinfo "$l_uid" filsys) || :
     27    read f_type f_data < <(hesinfo -- "$l_uid" filsys | sort -nk5,5) || :
    2628    if [ -z "$f_type" ]; then
    2729        err "$l_uid" "no_hesiod"
     
    3133        read f_path f_perm f_link z \
    3234            < <(echo "$f_data")
    33         [ "$l_homeDirectory" = "$f_path" ] || \
    34             err "$l_uid" "hesiod_path $f_path"
     35        [ "${l_homeDirectory#/disabled}" = "$f_path" ] || \
     36            err "$l_uid" "hesiod_path $f_path (LDAP $l_homeDirectory)"
    3537    else
    3638        err "$l_uid" "wrong_hesiod $f_type"
    3739    fi
    3840
    39     IFS=/ read p_empty p_top p_cell p \
    40         < <(echo "$l_homeDirectory")
    41     [ -z "${p_empty}" ] || \
    42         err "$l_uid" "relative_home $l_homeDirectory"
    43     [ "${p_top}" = "afs" ] || \
    44         err "$l_uid" "not_afs $l_homeDirectory"
     41    p_cell=
     42    case "$l_homeDirectory" in
     43        /afs/*)
     44            p_cell="${l_homeDirectory#/afs/}"
     45            p_cell="${p_cell%%/*}"
     46            ;;
     47        /disabled/afs/*)
     48            err "$l_uid" "disabled $l_homeDirectory"
     49            l_homeDirectory="${l_homeDirectory#/disabled}"
     50            p_cell="${l_homeDirectory#/afs/}"
     51            p_cell="${p_cell%%/*}"
     52            ;;
     53        /*)
     54            err "$l_uid" "not_afs $l_homeDirectory"
     55            ;;
     56        *)
     57            err "$l_uid" "relative_home $l_homeDirectory"
     58            ;;
     59    esac
    4560
    4661    read v_vname v_vol v \
    47         < <(vos exa -noauth "$l_uidNumber" -cell "$p_cell" 2>/dev/null) || :
     62        < <(vos examine -noauth -id "$l_uidNumber" -cell "${p_cell#.}" 2>/dev/null) || :
    4863    [ "$v_vol" = "$l_uidNumber" ] ||
    49         err "$l_uid" "no_vol $l_uidNumber"
     64        err "$l_uid" "no_vol ${p_cell#.} $l_uidNumber"
    5065
    5166    if ! [ -d "$l_homeDirectory" ]; then
    5267        if ! [ -e "$l_homeDirectory" ]; then
    53             err "$l_uid" "deleted $l_homeDirectory"
     68            err "$l_uid" "no_home $l_homeDirectory"
    5469        else
    5570            err "$l_uid" "not_dir $l_homeDirectory"
     
    5772    else
    5873        read c c_path c c c c_cell \
    59             < <(fs whichcell "$l_homeDirectory" 2>/dev/null) || :
     74            < <(fs whichcell -path "$l_homeDirectory" 2>/dev/null) || :
    6075        [ "$c_path" = "$l_homeDirectory" ] || \
    6176            err "$l_uid" "no_cell $l_homeDirectory"
    62         [ "$c_cell" = "'$p_cell'" ] || \
    63             err "$l_uid" "wrong_cell $l_homeDirectory"
     77        [ "$c_cell" = "'${p_cell#.}'" ] || \
     78            err "$l_uid" "wrong_cell $p_cell $l_homeDirectory $c_cell"
    6479
    6580        read m_path m m m m m m m_vname \
    66             < <(fs lsmount "$l_homeDirectory" 2>/dev/null) || :
     81            < <(fs lsmount -dir "$l_homeDirectory" 2>/dev/null) || :
    6782        [ "$m_path" = "'$l_homeDirectory'" ] || \
    6883            err "$l_uid" "no_mount $l_homeDirectory"
    69         [ "$m_vname" = "'#$v_vname'" ] || [ "$m_vname" = "'%$v_vname'" ] || \
    70             err "$l_uid" "wrong_mount $m_vname ($l_uidNumber = $v_vname)"
     84
     85        case "$m_vname" in
     86            "'#$v_vname'" | "'%$v_vname'" | "'#${p_cell#.}:$v_vname'" | "'%{p_cell#.}:$v_vname'")
     87                ;;
     88            *)
     89                m_vname2="${m_vname#\'[#%]}"
     90                m_vname2="${m_vname2%\'}"
     91                m_cell="${m_vname2%%:*}"
     92                [ "$m_cell" != "$m_vname2" ] || m_cell="${p_cell#.}"
     93                m_vname2="${m_vname2#*:}"
     94                read m_vname2 m_vol m \
     95                    < <(vos examine -noauth -id "$m_vname2" -cell "$m_cell" 2>/dev/null) || :
     96                err "$l_uid" "wrong_mount ${m_cell} $m_vname = $m_vol (${p_cell#.} $l_uidNumber = $v_vname)"
     97                ;;
     98        esac
     99    fi
     100
     101    if [ "$ok" = t ]; then
     102        err "$l_uid" "ok"
    71103    fi
    72104
Note: See TracChangeset for help on using the changeset viewer.