/usr/share/pyaimt/src/xdb/legacyaimtransport.py is in pyaimt 0.8.0.1-4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 | # Copyright 2004-2006 Daniel Henninger <jadestorm@nc.rr.com>
# Licensed for distribution under the GPL version 2, check COPYING for details
import utils
from twisted.words.xish.domish import Element
import os
import os.path
import config
from debug import LogEvent, INFO, WARN, ERROR
X = os.path.sep
SPOOL_UMASK = 0177
XDBNS_PREFIX = "aimtrans:"
XDBNS_REGISTER = XDBNS_PREFIX+"data"
class XDB:
"""
Class for storage of data.
"""
def __init__(self, name):
""" Creates an XDB object. """
self.name = os.path.join(os.path.abspath(config.spooldir), name)
if not os.path.exists(self.name):
os.makedirs(self.name)
def __getFile(self, file):
file = utils.mangle(file)
document = utils.parseFile(self.name + X + file + ".xml")
return document
def __writeFile(self, file, text):
file = utils.mangle(file)
prev_umask = os.umask(SPOOL_UMASK)
f = open(self.name + X + file + ".xml", "w")
f.write(text)
f.close()
os.umask(prev_umask)
def request(self, file, xdbns):
""" Requests a specific xdb namespace from the XDB 'file' """
try:
document = self.__getFile(file)
for child in document.elements():
if child.getAttribute("xdbns") == xdbns:
return child
except:
return None
def files(self):
""" Returns a list containing the files in the current XDB database """
files=os.listdir(self.name);
for i in range(len(files)):
files[i]=utils.unmangle(files[i])
files[i]=files[i][:len(files[i])-4]
return files
def set(self, file, xdbns, element):
""" Sets a specific xdb namespace in the XDB 'file' to element """
try:
element.attributes["xdbns"] = xdbns
document = None
try:
document = self.__getFile(file)
except IOError:
pass
if not document:
document = Element((None, "xdb"))
# Remove the existing node (if any)
for child in document.elements():
if child.getAttribute("xdbns") == xdbns:
document.children.remove(child)
# Add the new one
document.addChild(element)
self.__writeFile(file, document.toXml())
except:
LogEvent(INFO, msg="XDB error writing entry %s to file %s" % (xdbns, file))
raise
def remove(self, file):
""" Removes an XDB file """
file = self.name + X + file + ".xml"
file = utils.mangle(file)
try:
os.remove(file)
except:
LogEvent(INFO, msg="XDB error removing file " + file)
raise
def formRegEntry(self, username, password):
""" Returns a domish.Element representation of the data passed. This element will be written to the XDB spool file """
reginfo = Element((None, "aimtrans"))
logoninfo = reginfo.addElement("logon")
logoninfo.attributes["id"] = username
logoninfo.attributes["pass"] = password
return reginfo
reginfo = Element((None, "query"))
reginfo.attributes["xmlns"] = XDBNS_REGISTER
userEl = reginfo.addElement("username")
userEl.addContent(username)
passEl = reginfo.addElement("password")
passEl.addContent(password)
return reginfo
def getAttributes(self, base):
""" This function should, given a spool domish.Element, pull the username, password,
and out of it and return them """
username = ""
password = ""
for child in base.elements():
try:
if child.name == "logon":
username = child.getAttribute("id")
password = child.getAttribute("pass")
except AttributeError:
continue
return username, password
def getRegistration(self, jabberID):
""" Retrieve registration information from the XDB.
Returns a username and password. """
result = self.request(jabberID, XDBNS_REGISTER)
if result == None:
return None
username, password = self.getAttributes(result)
if username and password and len(username) > 0 and len(password) > 0:
return (username,password)
else:
return None
def getRegistrationList(self):
""" Returns an array of all of the registered jids. """
return self.files()
def setRegistration(self, jabberID, username, password):
""" Sets up or creates a registration in the XDB.
username and password are for the legacy account. """
if len(password) == 0:
password = (self.getRegistration(jabberID))[1]
reginfo = self.formRegEntry(username, password)
self.set(jabberID, XDBNS_REGISTER, reginfo)
def removeRegistration(self, jabberID):
""" Removes a registration from the XDB. """
self.remove(jabberID)
def getSettingList(self, jabberID):
""" Gets a list of all settings for a user from the XDB. """
return {}
def getSetting(self, jabberID, variable):
""" Gets a user setting from the XDB. """
return None
def setSetting(self, jabberID, variable, value):
""" Sets a user setting in the XDB. """
pass
def getListEntry(self, type, jabberID, legacyID):
""" Retrieves a legacy ID entry from a list in
the XDB, based off the type and jabberID you provide.
Returns a dict of attributes, empty of no attributes, and
None if the entry does not exist. """
if type != "roster": return None
xdbns = XDBNS_PREFIX+type
result = self.request(jabberID, xdbns)
if result == None:
return None
attributes = None
for child in result.elements():
try:
if child.name == "buddies":
for child2 in child.elements():
if child2.getAttribute("name") == legacyID:
attributes = {}
except AttributeError:
continue
return attributes
def getListTypes(self, jabberID):
""" Returns an array containing a list of all list types
associated with a user. """
return ["roster"]
def getList(self, type, jabberID):
""" Returns an array containing an entire list of a
jabberID's from the XDB, based off the type and jabberID
you provide. Array entries are in the format of
(legacyID, attributes) where attributes is a dict. """
if type != "roster": return None
xdbns = XDBNS_PREFIX+type
result = self.request(jabberID, xdbns)
if result == None:
return None
entities = []
for child in result.elements():
try:
if child.name == "buddies":
for child2 in child.elements():
if child2.hasAttribute("name"):
entity = []
entity.append(child2.getAttribute("name"))
attributes = {}
entity.append(attributes)
entities.append(entity)
except AttributeError:
continue
return entities
def setListEntry(self, type, jabberID, legacyID, payload = {}):
""" Updates or adds a legacy ID entry to a list in
the XDB, based off the type and jabberID you provide. """
if type != "roster": return
xdbns = XDBNS_PREFIX+type
list = self.request(jabberID, xdbns)
if list == None:
list = Element((None, "aimtrans"))
list.attributes["xmlns"] = xdbns
buddies = None
for child in list.elements():
try:
if child.name == "buddies":
buddies = child
break
except AttributeError:
continue
if buddies == None:
buddies = list.addElement("buddies")
# Remove the existing element
for child in buddies.elements():
try:
if child.getAttribute("name") == legacyID:
buddies.children.remove(child)
except AttributeError:
continue
newentry = buddies.addElement("item")
newentry["name"] = legacyID
self.set(jabberID, xdbns, list)
def removeListEntry(self, type, jabberID, legacyID):
""" Removes a legacy ID entry from a list in
the XDB, based off the type and jabberID you provide. """
if type != "roster": return
xdbns = XDBNS_PREFIX+type
list = self.request(jabberID, xdbns)
if list == None:
list = Element((None, "aimtrans"))
list.attributes["xmlns"] = xdbns
buddies = None
for child in list.elements():
try:
if child.name == "buddies":
buddies = child
break
except AttributeError:
continue
if buddies == None:
buddies = list.addElement("buddies")
# Remove the existing element
for child in buddies.elements():
try:
if child.getAttribute("name") == legacyID:
buddies.children.remove(child)
except AttributeError:
continue
self.set(jabberID, xdbns, list)
def housekeep():
pass
|