#! /usr/bin/env python # -*- coding: iso-8859-15 -*- """ Changement du shell de l'utilisateur lancant le programme DOIT ETRE LANCE PAR SUDO Copyright (C) Frédéric Pauget Licence : GPLv2 """ import os, sys from affich_tools import prompt from ldap_crans import crans_ldap db = crans_ldap() uid = os.getenv('SUDO_UID') if not uid : print "Impossible de déterminer l'utilisateur" sys.exit(1) adh = db.search('uidNumber=%s' % os.getenv('SUDO_UID'),'w')['adherent'] if len(adh) != 1 : print 'Erreur fatale lors de la consultation de la base LDAP' sys.exit(2) adh = adh[0] shell = prompt('Nouveau shell :') fd=open('/etc/shells') if not shell in map(str.strip,fd.readlines()) : print map(str.strip,fd.readlines()) print 'Shell invalide' sys.exit(3) adh.chsh(shell) adh.save()