Skip to content
Snippets Groups Projects
Commit f16a389d authored by Pavel Kácha's avatar Pavel Kácha
Browse files

* Server is now in line with Idea spec concerning client names - they are...

 * Server is now in line with Idea spec concerning client names - they are stored in db and compared lowercase
 * Fixed duplicity check when adding/modifying client
 * Secret is not secret anyway, simplify Client and logging code
parent af619a0a
No related branches found
No related tags found
No related merge requests found
...@@ -207,19 +207,9 @@ def SysLogger(req, socket="/dev/log", facility=logging.handlers.SysLogHandler.LO ...@@ -207,19 +207,9 @@ def SysLogger(req, socket="/dev/log", facility=logging.handlers.SysLogHandler.LO
class Client(namedtuple("ClientTuple", Client = namedtuple("Client",
["id", "registered", "requestor", "hostname", "note", ["id", "registered", "requestor", "hostname", "name", "note",
"valid", "name", "secret", "read", "debug", "write", "test"])): "valid", "secret", "read", "debug", "write", "test"])
def __str__(self):
return (
"%s(id=%i, registered=%s, requestor=\"%s\", hostname=\"%s\", "
"note=\"%s\", name=\"%s\", secret=%s, "
"valid=%i read=%i, debug=%i, write=%i, test=%i)") % (
type(self).__name__, self.id, self.registered,
self.requestor, self.hostname, self.note,
self.name, "..." if self.secret is not None else "None",
self.valid, self.read, self.debug, self.write, self.test)
...@@ -342,7 +332,7 @@ class X509Authenticator(NoAuthenticator): ...@@ -342,7 +332,7 @@ class X509Authenticator(NoAuthenticator):
if not client: if not client:
logging.info("authenticate: client not found by name: \"%s\", secret: %s, cert_names: %s" % ( logging.info("authenticate: client not found by name: \"%s\", secret: %s, cert_names: %s" % (
name, "..." if secret else "None", str(cert_names))) name, secret, str(cert_names)))
return None return None
# Clients with 'secret' set muset get authorized by it. # Clients with 'secret' set muset get authorized by it.
...@@ -522,12 +512,12 @@ class MySQL(ObjectReq): ...@@ -522,12 +512,12 @@ class MySQL(ObjectReq):
params = [] params = []
if name: if name:
query.append(" AND name = %s") query.append(" AND name = %s")
params.append(name) params.append(name.lower())
if secret: if secret:
query.append(" AND secret = %s") query.append(" AND secret = %s")
params.append(secret) params.append(secret)
query.append(" AND hostname IN (%s)" % self._get_comma_perc(cert_names)) query.append(" AND hostname IN (%s)" % self._get_comma_perc(cert_names))
params.extend(cert_names) params.extend(n.lower() for n in cert_names)
rows = self.query("".join(query), params) rows = self.query("".join(query), params)
if len(rows)>1: if len(rows)>1:
...@@ -562,6 +552,8 @@ class MySQL(ObjectReq): ...@@ -562,6 +552,8 @@ class MySQL(ObjectReq):
"valid", "read", "write", "debug", "test"]: "valid", "read", "write", "debug", "test"]:
val = kwargs.get(attr, None) val = kwargs.get(attr, None)
if val is not None: if val is not None:
if attr in ["name", "hostname"]:
val = val.lower()
uquery.append("`%s` = %%s" % attr) uquery.append("`%s` = %%s" % attr)
params.append(val) params.append(val)
if not uquery: if not uquery:
...@@ -1354,10 +1346,13 @@ def modify_client(id, name, hostname, requestor, secret, note, valid, read, writ ...@@ -1354,10 +1346,13 @@ def modify_client(id, name, hostname, requestor, secret, note, valid, read, writ
print >>sys.stderr, "Invalid id \"%s\"." % id print >>sys.stderr, "Invalid id \"%s\"." % id
return 254 return 254
existing_clients = server.handler.db.get_client_by_name([hostname], name=name, secret=secret) for c in server.handler.db.get_clients():
if existing_clients: if name is not None and name.lower()==c.name:
print >>sys.stderr, "Clash with existing hostname/name/secret: %s" % str(existing_clients) print >>sys.stderr, "Clash with existing name: %s" % str(c)
return 254 return 254
if secret is not None and secret==c.secret:
print >>sys.stderr, "Clash with existing secret: %s" % str(c)
return 254
newid = server.handler.db.add_modify_client( newid = server.handler.db.add_modify_client(
id=id, name=name, hostname=hostname, id=id, name=name, hostname=hostname,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment