Example #1
0
	def add(self, did, domain, flags=None, force=False):
		dflags = self.default_flags()
		fmask  = parse_flags(flags)
		flags  = new_flags(dflags, fmask)
		canonical = is_canonical(flags)

		if self.exist(did, domain):
			if force: return
			raise Error (EDUPL, errstr(did=did, domain=domain))

		# set digest realm attr
		da = self.Domain_attrs(self.dburi, self.db)
		da.set_default(did, 'digest_realm', domain)

		# update canonical flag
		cnd, err = cond(CND_NO_DELETED, did=did)
		rows = self.db.select(self.TABLE, self.COLUMNS, cnd)
		canon_exist = False
		for row in rows:
			if not is_canonical(row[self.FLAGIDX]):
				continue
			if not canonical:
				canon_exist = True
				break
			f = clear_canonical(row[self.FLAGIDX])
			cnd = full_cond(self.COLUMNS, row)
			self.db.update(self.TABLE, {'flags':f}, cnd)
		if not canonical and not canon_exist:
			flags = set_canonical(flags)

		# add new domain
		ins = { 'did' : did, 'domain' : domain, 'flags' : flags }
		self.db.insert(self.TABLE, ins)
Example #2
0
	def rm(self, attr, value=None, force=False):
		if not self.exist(attr, value):
			if force: return
                        if value is None:
				raise Error (ENOREC, errstr(attr=attr))
			else:
				raise Error (ENOREC, errstr(attr=attr, value=value))

		cnd, err = cond(CND_NO_DELETED, name=attr, value=value)
		rows = self.db.select(self.TABLE, self.COLUMNS, cnd)
		for row in rows:
			nf = set_deleted(row[self.FLAGIDX])
			cnd = full_cond(self.COLUMNS, row)
			self.db.update(self.TABLE, {'flags': nf}, cnd)

		# FIX: purge hack
		self.purge()
Example #3
0
	def rm_did_for_domain(self, domain, force):
		try:
			did = self.get_did(domain)
		except:
			if force: return
			raise
		if self.is_used(did) and not force:
			raise Error (EDOMAIN, errstr(did=did))
		self.rm_did(did, force)
Example #4
0
	def add(self, domain, aliases=[], idtype=ID_URI, force=False):
		do = Domain(self.dburi, self.db)

		did = id(domain, idtype)
		if do.exist_did(did) and not force:
			raise Error (EDOMAIN, errstr(did=did))

		if do.exist_domain(domain) and not force:
			raise Error (EDOMAIN, domain)

		ualiases = uniq(aliases)
		naliases = []
		for alias in ualiases:
			if do.exist(did, alias):
				if force: continue
				raise Error (EDUPL, errstr(did=did, domain=alias))
			else:
				naliases.append(alias)

		do.add(did, domain, None, force)
		for alias in naliases:
			do.add(did, alias, None, force)
		self._reload()
Example #5
0
	def add(self, uri, aliases, password, idtype=ID_URI, force=False):
		do = Domain(self.dburi, self.db)
		da = Domain_attrs(self.dburi, self.db)
		ur = Uri(self.dburi, self.db)
		cr = Cred(self.dburi, self.db)
		us = User(self.dburi, self.db)

		user, domain = split_sip_uri(uri)
		aliases = uniq(aliases)
		try:
			n = aliases.index(uri)
			aliases = aliases[:n] + aliases[n+1:]
		except:
			pass
		aliases = [ split_sip_uri(a) for a in aliases ]

		uid = id(user + '@' + domain, idtype)
		if us.exist(uid):
			if not force:
				raise Error (EDUPL, errstr(uid=uid))
		if cr.exist(user, domain):
			if not force:
				raise Error (EDUPL, errstr(auth_username=user, domain=domain))
		if not do.exist_domain(domain):
			if force:
				i = id(domain, idtype)
				do.add(i, domain, force=force)
			else:
				raise Error (ENODOMAIN, domain)
		did = do.get_did(domain)
		try:
			realm = da.get(did, 'digest_realm')
		except:
			if force:
				realm = domain
			else:
				raise
		for u, d in aliases:
			if not do.exist_domain(d):
				if force:
					i = id(d, idtype)
					do.add(i, d, force=force)
				else:
					raise Error (ENODOMAIN, d)
			did = do.get_did(d)
			if ur.exist_username_did(u, did) and not force:
				raise Error (EDUPL, '%s@%s' % (u, d))
		did = do.get_did(domain)
		if ur.exist(uid, user, did):
			if not force:
				raise Error(EDUPL, errstr(uid=uid, username=user, did=did))

		us.add(uid, force=force)
		cr.add(uid, user, did, realm, password, force=force)
		ur.add(uid, uri, force=force)
		for u, d in aliases:
			uri = '%s@%s' % (u, d)
			try:
				ur.add(uid, uri, force=force)
			except Error, inst:
				warning(str(inst))