[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/se3master/usr/share/se3/sbin/ -> se3_dedoublonnage_uidNumber.sh (source)

   1  #!/bin/bash
   2  
   3  # $Id: se3_dedoublonnage_uidNumber.sh 7745 2013-03-31 23:53:39Z keyser $
   4  #
   5  # Script de dedoublonnage des uidNumber
   6  
   7  ladate=$(date +%Y%m%d%H%M%S)
   8  
   9  dosstmp=/root/tmp/recherche_uidnumber_en_doublons_$(date +%Y%m%d)
  10  mkdir -p $dosstmp
  11  fichcsv=$dosstmp/doublons.csv
  12  
  13  echo "Initialisation des variables BASEDN, ROOTDN et PASSDN"
  14  t=$(ps aux|grep mysqld|grep "^mysql")
  15  #echo "t=$t"
  16  if [ -n "$t" ]; then
  17      WWWPATH="/var/www"
  18  
  19      if [ -e $WWWPATH/se3/includes/config.inc.php ]; then
  20          dbhost=`cat $WWWPATH/se3/includes/config.inc.php | grep "dbhost=" | cut -d = -f 2 |cut -d \" -f 2`
  21          dbname=`cat $WWWPATH/se3/includes/config.inc.php | grep "dbname=" | cut -d = -f 2 |cut -d \" -f 2`
  22          dbuser=`cat $WWWPATH/se3/includes/config.inc.php | grep "dbuser=" | cut -d = -f 2 |cut -d \" -f 2`
  23          dbpass=`cat $WWWPATH/se3/includes/config.inc.php | grep "dbpass=" | cut -d = -f 2 |cut -d \" -f 2`
  24      else
  25          echo "Fichier de conf inaccessible"
  26          exit 1
  27      fi
  28  
  29      BASE_DN=`echo "SELECT value FROM params WHERE name='ldap_base_dn'" | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N`
  30      if [ -z "$BASE_DN" ]; then
  31          echo "Impossible d'acceder au parametre BASE_DN"
  32          exit 1
  33      fi
  34      BASEDN=$BASE_DN
  35      ADMINRDN=`echo "SELECT value FROM params WHERE name='adminRdn'" | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N`
  36      if [ -z "$ADMINRDN" ]; then
  37          echo "Impossible d'acceder au parametre ADMINRDN"
  38          exit 1
  39      fi
  40      #ROOTDN=$ADMINRDN
  41      ROOTDN=$ADMINRDN,$BASEDN
  42      ADMINPW=`echo "SELECT value FROM params WHERE name='adminPw'" | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N`
  43      if [ -z "$ADMINPW" ]; then
  44          echo "Impossible d'acceder au parametre ADMINPW"
  45          exit 1
  46      fi
  47      PASSDN=$ADMINPW
  48      PEOPLERDN=`echo "SELECT value FROM params WHERE name='peopleRdn'" | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N`
  49      if [ -z "$PEOPLERDN" ]; then
  50          echo "Impossible d'acceder au parametre PEOPLERDN"
  51          exit 1
  52      fi
  53      GROUPSRDN=`echo "SELECT value FROM params WHERE name='groupsRdn'" | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N`
  54      if [ -z "$GROUPSRDN" ]; then
  55          echo "Impossible d'acceder au parametre GROUPSRDN"
  56          exit 1
  57      fi
  58      RIGHTSRDN=`echo "SELECT value FROM params WHERE name='rightsRdn'" | mysql -h $dbhost $dbname -u $dbuser -p$dbpass -N`
  59      if [ -z "$RIGHTSRDN" ]; then
  60          echo "Impossible d'acceder au parametre RIGHTSRDN"
  61          exit 1
  62      fi
  63  else
  64      echo "Le service MySQL ne semble pas accessible."
  65      echo "Utilisation des parametres locaux."
  66      echo "Ils ne sont valides que si le service LDAP tourne sur le SE3 lui-meme."
  67  
  68      BASEDN=$(cat /etc/ldap/ldap.conf | grep "^BASE" | tr "\t" " " | sed -e "s/ \{2,\}/ /g" | cut -d" " -f2)
  69      ROOTDN=$(cat /etc/ldap/slapd.conf | grep "^rootdn" | tr "\t" " " | cut -d'"' -f2)
  70      PASSDN=$(cat /etc/ldap.secret)
  71      PEOPLERDN="ou=People"
  72      GROUPSRDN="ou=Groups"
  73      RIGHTSRDN="ou=People"
  74  fi
  75  
  76  GET_UIDNUMBER() {
  77      for i in $(seq 1000 4999)
  78      do
  79          t=$(ldapsearch -xLLL uidNumber=$i uidNumber)
  80          if [ -z "$t" ]; then
  81              echo $i
  82              #break
  83              exit 0
  84          fi
  85      done
  86      echo "-1"
  87  }
  88  
  89  if [ "$1" = "go" -a -e $fichcsv ]; then
  90      # Faire une sauvegarde de l'annuaire
  91      echo "Sauvegarde initiale de l'annuaire..."
  92      ldapsearch -xLLL -D "$ROOTDN" -w "$PASSDN" > $dosstmp/ldapsearch_$ladate}.ldif
  93      if [ "$?" != "0" ]; then
  94          echo "ERREUR lors de la sauvegarde."
  95          echo "Abandon par précaution."
  96          exit
  97      fi
  98  
  99      sambaSID=$(net getlocalsid|cut -d":" -f2|sed -e "s/ //g")
 100  
 101      uidnumprec=1
 102      while read A
 103      do
 104          uidnumber=$(echo "$A" | cut -d";" -f1)
 105          uid=$(echo "$A" | cut -d";" -f2)
 106  
 107          if [ "$uidnumber}" = "$uidnumprec}" ]; then
 108              uidnumnew=$(GET_UIDNUMBER)
 109              if [ "$uidnumnew}" != "-1" ]; then
 110                  echo "Changement pour $uid: $uidnumber} -> $uidnumnew}"
 111                  nouvelrid=$((2*$uidnumnew}+1000))
 112                  echo "dn: uid=$uid,$PEOPLERDN,$BASEDN
 113  changetype: modify
 114  replace: uidNumber
 115  uidNumber: $uidnumnew}
 116  -
 117  replace: sambaSID
 118  sambaSID: $sambaSID-$nouvelrid
 119  " > $dosstmp/modif_$uid.ldif
 120  
 121                  ldapmodify -x -D $ROOTDN -w $PASSDN -f $dosstmp/modif_$uid.ldif
 122  
 123                  ## Correction des proprios:
 124                  #find /home/$uid -uid ${uidNumber} | while read B
 125                  #do
 126                  #    chown $uid "$B"
 127                  #done
 128              else
 129                  echo "Il n'y a plus d'uidNumber libre."
 130                  exit
 131              fi
 132          fi
 133          uidnumprec=$uidnumber}
 134      done < $fichcsv
 135  
 136      echo "ATTENTION: Lancez maintenant le script restore_droits.sh pour corriger"
 137      echo "           les proprios."
 138  else
 139      rm -f $fichcsv
 140      for i in $(seq 1000 5000)
 141      do
 142          j=$(ldapsearch -x uidNumber=$i uid |grep numEntries | cut -d: -f 2)
 143          if [ ! $j = 1 ]; then
 144              ldapsearch -xLLL uidNumber=$i uid | grep "^uid: " | sed "s/^uid: //" | while read uid
 145              do
 146                  echo "$i;$uid" | tee -a $fichcsv
 147              done
 148          fi
 149      done
 150      echo "Vous pouvez relancer le script avec le paramètre 'go' pour changer l'uidNumber du doublon."
 151  fi
 152  


Generated: Tue Mar 17 22:47:18 2015 Cross-referenced by PHPXref 0.7.1