1
2
3
4
5
6
7
8
9
10
11 import sys
12 import os
13 import re
14 from certificate import getGridProxyPath
15 from mdclient import MDClient
16 from mdinterface import CommandException
17
18 DEBUG = False
19
20
21
23 """Represents db interface for user management"""
24
25 - def __init__(self,
26 host = 'gangamd.cern.ch',
27 port = 8822,
28 login = 'root',
29 password = '',
30 keepalive = False,
31 reqSSL = True,
32 **kwds):
33
34 self._client = MDClient(host = host,
35 port = port,
36 login = login,
37 password = password,
38 keepalive = keepalive)
39
40 if reqSSL:
41 fn = getGridProxyPath()
42 key = kwds.get('key')
43 if not key:
44 key = fn
45 cert = kwds.get('cert')
46 if not cert:
47 cert = fn
48
49 self._client.requireSSL(key, cert)
50 self._client.connect()
51
52
54 """Lists all users known to the authentication subsustem"""
55 res = []
56 cmd = 'user_list'
57 self._client.execute(cmd)
58 while not self._client.eot():
59 row = self._client.fetchRow()
60 if DEBUG:
61 print row
62 res.append(row)
63 return res
64
65
67 """Lists the credentials with which the user can be authenticated"""
68 res = []
69 cmd = 'user_listcred ' + user
70 self._client.execute(cmd)
71 while not self._client.eot():
72 row = self._client.fetchRow()
73 if DEBUG:
74 print row
75 res.append(row)
76 return res
77
78
80 """Creates a new user and assigns a password if given."""
81 cmd = 'user_create ' + user
82 if password:
83 cmd += ' ' + password
84 self._client.execute(cmd)
85
86
87
89 """Deletes a user"""
90 cmd = 'user_remove ' + user
91 self._client.execute(cmd)
92
93
94
96 """Changes the password of a user"""
97 cmd = 'user_password_change ' + user + ' ' + password
98 self._client.execute(cmd)
99
100
102 """Adds a certificate identified by its subject line to be used to
103 authenticate a user"""
104 cmd = 'user_subject_add ' + user + ' ' + '\'' + subject + '\''
105 self._client.execute(cmd)
106
107
108
109 usage = """
110 """
111