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 *)
29 cdef ubik_client * client
31 def __cinit__(self, cell=None, sec=1):
33 cdef afsconf_dir *cdir
34 cdef afsconf_cell info
36 cdef ktc_principal prin
38 cdef rx_securityClass *sc
39 cdef rx_connection *serverconns[MAXSERVERS]
51 raise Exception(code, "Error initializing Rx")
53 cdir = afsconf_Open(AFSDIR_CLIENT_ETC_DIRPATH)
56 "Error opening configuration directory (%s): %s" % \
57 (AFSDIR_CLIENT_ETC_DIRPATH, strerror(errno)))
58 code = afsconf_GetCellInfo(cdir, c_cell, "afsprot", &info)
60 raise Exception(code, "GetCellInfo: %s" % afs_error_message(code))
63 strncpy(prin.cell, info.name, sizeof(prin.cell))
65 strncpy(prin.name, "afs", sizeof(prin.name))
67 code = ktc_GetToken(&prin, &token, sizeof(token), NULL);
70 # No really - we wanted authentication
71 raise Exception(code, "Failed to get token for service AFS: %s" % afs_error_message(code))
78 sc = rxkad_NewClientSecurityObject(level, &token.sessionKey,
79 token.kvno, token.ticketLen,
83 sc = rxnull_NewClientSecurityObject()
87 memset(serverconns, 0, sizeof(serverconns))
88 for 0 <= i < info.numServers:
89 serverconns[i] = rx_NewConnection(info.hostAddr[i].sin_addr.s_addr,
90 info.hostAddr[i].sin_port,
95 code = ubik_ClientInit(serverconns, &self.client)
97 raise Exception("Failed to initialize ubik connection to Protection server: %s" % afs_error_message(code))
99 code = rxs_Release(sc)
101 def __dealloc__(self):
102 ubik_ClientDestroy(self.client)
105 def NameToId(self, name):
108 cdef afs_int32 code, id
112 lids.idlist_val = NULL
113 lnames.namelist_len = 1
114 lnames.namelist_val = <prname *>malloc(PR_MAXNAMELEN)
115 strncpy(lnames.namelist_val[0], name, PR_MAXNAMELEN)
116 code = ubik_PR_NameToID(self.client, 0, &lnames, &lids)
117 if lids.idlist_val is not NULL:
118 id = lids.idlist_val[0]
119 free(lids.idlist_val)
121 raise Exception("Failed to lookup PTS name: %s" % afs_error_message(code))
124 def IdToName(self, id):
128 cdef char name[PR_MAXNAMELEN]
131 lids.idlist_val = <afs_int32 *>malloc(sizeof(afs_int32))
132 lids.idlist_val[0] = id
133 lnames.namelist_len = 0
134 lnames.namelist_val = NULL
135 code = ubik_PR_IDToName(self.client, 0, &lids, &lnames)
136 if lnames.namelist_val is not NULL:
137 strncpy(name, lnames.namelist_val[0], sizeof(name))
138 free(lnames.namelist_val)
139 if lids.idlist_val is not NULL:
140 free(lids.idlist_val)
142 raise Exception("Failed to lookup PTS ID: %s" % afs_error_message(code))
145 def CreateUser(self, name, id=None):
148 name = name[:PR_MAXNAMELEN].lower()
154 code = ubik_PR_INewEntry(self.client, 0, name, cid, 0)
156 code = ubik_PR_NewEntry(self.client, 0, name, 0, 0, &cid)
159 raise Exception("Failed to create user: %s" % afs_error_message(code))
162 def CreateGroup(self, name, owner, id=None):
163 cdef afs_int32 code, cid
165 name = name[:PR_MAXNAMELEN].lower()
166 oid = self.NameToId(owner)
167 if oid == ANONYMOUSID:
168 raise Exception("Error creating group: owner does not exist")
172 code = ubik_PR_INewEntry(self.client, 0, name, cid, oid)
174 code = ubik_PR_NewEntry(self.client, 0, name, PRGRP, oid, &cid)
177 raise Exception("Failed to create group: %s" % afs_error_message(code))