3 cdef import from "afs/ptuser.h":
13 ctypedef char prname[PR_MAXNAMELEN]
16 unsigned int namelist_len
20 unsigned int idlist_len
23 int ubik_PR_NameToID(ubik_client *, afs_int32, namelist *, idlist *)
24 int ubik_PR_IDToName(ubik_client *, afs_int32, idlist *, namelist *)
25 int ubik_PR_INewEntry(ubik_client *, afs_int32, char *, afs_int32, afs_int32)
26 int ubik_PR_NewEntry(ubik_client *, afs_int32, char *, afs_int32, afs_int32, afs_int32 *)
27 int ubik_PR_Delete(ubik_client *, afs_int32, afs_int32)
30 cdef ubik_client * client
32 def __cinit__(self, cell=None, sec=1):
34 cdef afsconf_dir *cdir
35 cdef afsconf_cell info
37 cdef ktc_principal prin
39 cdef rx_securityClass *sc
40 cdef rx_connection *serverconns[MAXSERVERS]
52 raise Exception(code, "Error initializing Rx")
54 cdir = afsconf_Open(AFSDIR_CLIENT_ETC_DIRPATH)
57 "Error opening configuration directory (%s): %s" % \
58 (AFSDIR_CLIENT_ETC_DIRPATH, strerror(errno)))
59 code = afsconf_GetCellInfo(cdir, c_cell, "afsprot", &info)
61 raise Exception(code, "GetCellInfo: %s" % afs_error_message(code))
64 strncpy(prin.cell, info.name, sizeof(prin.cell))
66 strncpy(prin.name, "afs", sizeof(prin.name))
68 code = ktc_GetToken(&prin, &token, sizeof(token), NULL);
71 # No really - we wanted authentication
72 raise Exception(code, "Failed to get token for service AFS: %s" % afs_error_message(code))
79 sc = rxkad_NewClientSecurityObject(level, &token.sessionKey,
80 token.kvno, token.ticketLen,
84 sc = rxnull_NewClientSecurityObject()
88 memset(serverconns, 0, sizeof(serverconns))
89 for 0 <= i < info.numServers:
90 serverconns[i] = rx_NewConnection(info.hostAddr[i].sin_addr.s_addr,
91 info.hostAddr[i].sin_port,
96 code = ubik_ClientInit(serverconns, &self.client)
98 raise Exception("Failed to initialize ubik connection to Protection server: %s" % afs_error_message(code))
100 code = rxs_Release(sc)
102 def __dealloc__(self):
103 ubik_ClientDestroy(self.client)
106 def NameToId(self, name):
109 cdef afs_int32 code, id
113 lids.idlist_val = NULL
114 lnames.namelist_len = 1
115 lnames.namelist_val = <prname *>malloc(PR_MAXNAMELEN)
116 strncpy(lnames.namelist_val[0], name, PR_MAXNAMELEN)
117 code = ubik_PR_NameToID(self.client, 0, &lnames, &lids)
118 if lids.idlist_val is not NULL:
119 id = lids.idlist_val[0]
120 free(lids.idlist_val)
122 raise Exception("Failed to lookup PTS name: %s" % afs_error_message(code))
125 def IdToName(self, id):
129 cdef char name[PR_MAXNAMELEN]
132 lids.idlist_val = <afs_int32 *>malloc(sizeof(afs_int32))
133 lids.idlist_val[0] = id
134 lnames.namelist_len = 0
135 lnames.namelist_val = NULL
136 code = ubik_PR_IDToName(self.client, 0, &lids, &lnames)
137 if lnames.namelist_val is not NULL:
138 strncpy(name, lnames.namelist_val[0], sizeof(name))
139 free(lnames.namelist_val)
140 if lids.idlist_val is not NULL:
141 free(lids.idlist_val)
143 raise Exception("Failed to lookup PTS ID: %s" % afs_error_message(code))
146 def CreateUser(self, name, id=None):
149 name = name[:PR_MAXNAMELEN].lower()
155 code = ubik_PR_INewEntry(self.client, 0, name, cid, 0)
157 code = ubik_PR_NewEntry(self.client, 0, name, 0, 0, &cid)
160 raise Exception("Failed to create user: %s" % afs_error_message(code))
163 def CreateGroup(self, name, owner, id=None):
164 cdef afs_int32 code, cid
166 name = name[:PR_MAXNAMELEN].lower()
167 oid = self.NameToId(owner)
168 if oid == ANONYMOUSID:
169 raise Exception("Error creating group: owner does not exist")
173 code = ubik_PR_INewEntry(self.client, 0, name, cid, oid)
175 code = ubik_PR_NewEntry(self.client, 0, name, PRGRP, oid, &cid)
178 raise Exception("Failed to create group: %s" % afs_error_message(code))
181 def Delete(self, id):
184 code = ubik_PR_Delete(self.client, 0, id)
186 raise Exception("Failed to delete user: %s" % afs_error_message(code))