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
This commit is contained in:
pauget 2004-09-10 20:27:55 +02:00
parent fd0dd3e6d9
commit a4508682f4

35
gestion/chsh.py Executable file
View file

@ -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()