admin scripts
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
2.0 KiB

  1. #!/bin/bash
  2. #Get Gids from LDAP
  3. names=`ldapsearch -xLLL "(objectClass=posixGroup)" gidNumber | grep dn | awk -F = '{print $2}' | awk -F , '{print $1}'`
  4. ids=`ldapsearch -xLLL "(objectClass=posixGroup)" gidNumber | grep gidNumber | awk '{print $2}'`
  5. count=`ldapsearch -xLLL "(objectClass=posixGroup)" gidNumber | grep -c dn`
  6. #Convet strings to Arrays
  7. acount=`expr $count - 1`
  8. for i in `seq 1 $count`; do
  9. # echo loop debug $i
  10. ai=`expr $i - 1`
  11. a_names[$ai]=`echo $names | awk '{print $'$i'}'`
  12. # echo ${a_names[$ai]}
  13. a_ids[$ai]=`echo $ids | awk '{print $'$i'}'`
  14. # echo ${a_ids[$ai]}
  15. done
  16. #Compare LDAP GIDS to System GIDS
  17. for a in `seq 0 $acount`; do
  18. # echo ${a_names[$a]}
  19. # Check for group name in /etc/groups
  20. # [ `grep -c ${a_names[$a]} /etc/group` -eq 1 ] && echo "${a_names[$a]} in /etc/group" || echo "${a_names[$a]} not in /etc/group"
  21. if [ `grep -c ${a_names[$a]} /etc/group` -gt 0 ]; then
  22. # Check its been assigned the right gid
  23. [ `grep ${a_names[$a]} /etc/group | awk -F : '{print $3}'` = ${a_ids[$a]} ] || echo FUCK UP IN ${a_names[$a]} Group is not assigned the correct GID
  24. else
  25. #IF Group is not there WARN AND ASK TO FIX
  26. echo "${a_names[$a]}:x:${a_ids[$a]} not in /etc/group"
  27. # Check for GID in use
  28. # [ `grep -c ${a_ids[$a]} /etc/group` -gt 0 ] && echo GID ${a_ids[$a]} in use || echo GID ${a_ids[$a]} not in use
  29. if [ `grep -c :${a_ids[$a]}: /etc/group` -gt 0 ]; then
  30. #GID is in use
  31. echo GID ${a_ids[$a]} in use by `grep :${a_ids[$a]}: /etc/group | awk -F : '{print $1}'`
  32. #This is complicated bit that requires finding and chgrping files in use by GID
  33. #genetate new gid
  34. RANDOM=$a
  35. newgid=$RANDOM
  36. while [ `grep -c :$newgid: /etc/group` -gt 0 ]; do
  37. newgid=$RANDOM
  38. done
  39. echo New GID is $newgid
  40. else
  41. echo GID ${a_ids[$a]} not in use
  42. # Append GID and name to /etc/group possible ask first
  43. echo "${a_names[$a]}:x:${a_ids[$a]}:" >> /etc/group
  44. #may use a fix variable for this instead and do writing at the end
  45. fi
  46. fi
  47. done
  48. #ASSIGN NEW GIDS
  49. #CHECH AND FIX GIDS of FILES NOT IN /STORAGE OR /FAST-STORAGE or TMP Dirs