
Pour changer le shell d'un utilisateur utiliser le script crans. darcs-hash:20040910182755-41617-93de910dc29600a74580ddab6c83df337fb8306c.gz
35 lines
834 B
Python
Executable file
35 lines
834 B
Python
Executable file
#! /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()
|