forked from collegiumv/cv_account
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kadmin.py
32 lines (26 loc) · 1.06 KB
/
kadmin.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import logging
import subprocess
import os
class KAdmin:
def __init__(self, kprinc, ktab):
self.kprinc = kprinc
self.ktab = ktab
self.logger = logging.getLogger("pyKAdmin")
def createPrinc(self, uid, password):
FNULL = open(os.devnull, 'w')
cmd = ['kadmin','-p'+self.kprinc, '-q', 'addprinc -pw '+password+' '+uid, '-k', '-t'+self.ktab]
if not bool(subprocess.call(cmd, shell=False, stdout=FNULL, stderr=FNULL)):
self.logger.debug("Kerberos Create Success!")
return True
else:
self.logger.error("Kerberos Create Error")
return False
def chPassword(self, uid, password):
FNULL = open(os.devnull, 'w')
cmd = ['kadmin','-p'+self.kprinc, '-q', 'cpw -pw '+password+' '+uid, '-k', '-t'+self.ktab]
if not bool(subprocess.call(cmd, shell=False, stdout=FNULL, stderr=FNULL)):
self.logger.debug("Kerberos Change Success!")
return True
else:
self.logger.error("Kerberos Change Error")
return False