From a4508682f4c45e031ccad36142c166334816eb52 Mon Sep 17 00:00:00 2001 From: pauget Date: Fri, 10 Sep 2004 20:27:55 +0200 Subject: [PATCH] Un chsh pour les changer son propre shell. Pour changer le shell d'un utilisateur utiliser le script crans. darcs-hash:20040910182755-41617-93de910dc29600a74580ddab6c83df337fb8306c.gz --- gestion/chsh.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100755 gestion/chsh.py diff --git a/gestion/chsh.py b/gestion/chsh.py new file mode 100755 index 00000000..b4361583 --- /dev/null +++ b/gestion/chsh.py @@ -0,0 +1,35 @@ +#! /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()