def add(self, uid, username, did, realm, password, flags=None, force=False): dflags = self.default_flags() fmask = parse_flags(flags) flags = new_flags(dflags, fmask) if not did: do = self.Domain(self.dburi, self.db) try: did = do.get_did(realm) except: if force: return raise us = self.User(self.dburi, self.db) if not us.exist(uid) and not force: raise Error (ENOUSER, 'uid='+uid) if self.exist(username, realm): if force: return raise Error (EDUPL, ) # compute hashes ha1, ha1b = self.hashes(username, realm, password) # add new cred ins = { 'uid' : uid, 'auth_username' : username, \ 'did' : did, 'realm' : realm, 'password' : password, \ 'ha1' : ha1, 'ha1b' : ha1b, 'flags' : flags \ } self.db.insert(self.TABLE, ins)
def change(self, uid, uri, flags=None, force=False): fmask = parse_flags(flags) nflags = new_flags(0, fmask) canonical = is_canonical(nflags) try: username, did = self.uri2id(uri) except: if force: return raise cndt, err = cond(CND_NO_DELETED, uid=uid, username=username, did=did) if not self.exist(uid, username, did): if force: return raise Error (ENOREC, err) # clear canon if canonical: cnd, err = cond(CND_NO_DELETED, uid=uid) cnd.append(CND_CANONICAL) rows = self.db.select(self.TABLE, self.COLUMNS, cnd) for row in rows: nf = clear_canonical(row[self.FLAGIDX]) cnd = full_cond(self.COLUMNS, row) self.db.update(self.TABLE, {'flags':nf}, cnd) # update flags rows = self.db.select(self.TABLE, self.COLUMNS, cndt) if not rows and not force: raise Error (ENOREC, err) for row in rows: nf = new_flags(row[self.FLAGIDX], fmask) cnd = full_cond(self.COLUMNS, row) self.db.update(self.TABLE, {'flags':nf}, cnd)
def change_domain(self, domain, flags=None, force=False): upd = {} fmask = parse_flags(flags) nflags = new_flags(0, fmask) canonical = is_canonical(nflags) # get did try: did = self.get_did(domain) except: if force: return raise # clear canon if canonical: cnd, err = cond(CND_NO_DELETED, did=did) cnd.append(CND_CANONICAL) rows = self.db.select(self.TABLE, self.COLUMNS, cnd) for row in rows: nf = clear_canonical(row[self.FLAGIDX]) cnd = full_cond(self.COLUMNS, row) upd = {'flags':nf} self.db.update(self.TABLE, upd, cnd) # update flags cnd, err = cond(CND_NO_DELETED, domain=domain) rows = self.db.select(self.TABLE, self.COLUMNS, cnd) if not rows and not force: raise Error (ENOREC, err) for row in rows: nf = new_flags(row[self.FLAGIDX], fmask) cnd = full_cond(self.COLUMNS, row) self.db.update(self.TABLE, {'flags':nf}, cnd)
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)
def change(self, uid=None, flags=None, force=False): fmask = parse_flags(flags) cnd, err = cond(CND_NO_DELETED, uid=uid) # update flags rows = self.db.select(self.TABLE, self.COLUMNS, cnd) if not rows and not force: raise Error (ENOREC, err) for row in rows: nf = new_flags(row[self.FLAGIDX], fmask) cnd = full_cond(self.COLUMNS, row) self.db.update(self.TABLE, {'flags':nf}, cnd)
def add(self, uid, flags=None, force=False): dflags = self.default_flags() fmask = parse_flags(flags) flags = new_flags(dflags, fmask) # exist uid? cnd, err = cond(CND_NO_DELETED, uid=uid) rows = self.db.select(self.TABLE, 'uid', cnd, limit=1) if rows: if force: return raise Error (EDUPL, uid) # user add ins = {'uid': uid, 'name': 'datetime_created', \ 'value': timestamp(), 'type': 2, 'flags': flags } self.db.insert(self.TABLE, ins)
def add(self, attr, value, flags=None, force=False): if not value: if force: return raise Error (ENOVAL, attr) at = Attr_types(self.dburi, self.db) dflags = at.get_default_flags(attr) fmask = parse_flags(flags) flags = new_flags(dflags, fmask) at = Attr_types(self.dburi, self.db) try: type = at.get_type(attr) except: if force: return raise # add new attr ins = { 'name' : attr, 'type' : type, 'value' : value, \ 'flags' : flags } self.db.insert(self.TABLE, ins)
def change(self, username, realm, password=None, flags=None, force=False): upd = {} # username & realm is required for password change if password is not None: # compute hashes ha1, ha1b = self.hashes(username, realm, password) upd = {'ha1': ha1, 'ha1b': ha1b, 'password': password} fmask = parse_flags(flags) # update cnd, err = cond(CND_NO_DELETED, auth_username=username, realm=realm) rows = self.db.select(self.TABLE, self.COLUMNS, cnd) if not rows and not force: raise Error (ENOREC, err) for row in rows: cnd = full_cond(self.COLUMNS, row) if flags is not None: nf = new_flags(row[self.FLAGIDX], fmask) upd['flags'] = nf self.db.update(self.TABLE, upd, cnd)
def add(self, uid, uri, flags=None, force=False): dflags = self.default_flags() fmask = parse_flags(flags) flags = new_flags(dflags, fmask) canonical = is_canonical(flags) try: username, did = self.uri2id(uri) except: if force: return raise us = self.User(self.dburi, self.db) if not us.exist(uid) and not force: raise Error (ENOUSER, uid) if self.exist(uid, username, did): if force: return raise Error (EDUPL, username) # update canonical flag cnd, err = cond(CND_NO_DELETED, uid=uid) 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 URI ins = { 'uid' : uid, 'did' : did, 'username' : username, \ 'flags' : flags } self.db.insert(self.TABLE, ins)