X-Git-Url: https://code.wpia.club/?a=blobdiff_plain;f=src%2Forg%2Fcacert%2Fgigi%2FdbObjects%2FDomain.java;h=fa6a6d0e10240b75b37d205c0a33e7645d02980f;hb=2f50dbb24105e6345329b8e9ecb5ef4d67ab2a8c;hp=1d31db61c2dee3dcf95dc122d74f4e5694344271;hpb=a0232b6e40e7e09767f0444d24e18bf12dafc362;p=gigi.git diff --git a/src/org/cacert/gigi/dbObjects/Domain.java b/src/org/cacert/gigi/dbObjects/Domain.java index 1d31db61..fa6a6d0e 100644 --- a/src/org/cacert/gigi/dbObjects/Domain.java +++ b/src/org/cacert/gigi/dbObjects/Domain.java @@ -51,6 +51,7 @@ public class Domain implements IdCachable, Verifyable { } public Domain(User actor, CertificateOwner owner, String suffix) throws GigiApiException { + suffix = suffix.toLowerCase(); synchronized (Domain.class) { checkCertifyableDomain(suffix, actor.isInGroup(Group.CODESIGNING)); this.owner = owner; @@ -73,6 +74,12 @@ public class Domain implements IdCachable, Verifyable { if ( !s.equals(publicSuffix)) { throw new GigiApiException("You may only register a domain with exactly one lable before the public suffix."); } + if (("." + s).matches("(\\.[0-9]*)*")) { + // This is not reached because we currently have no TLD that is + // numbers only. But who knows.. + // Better safe than sorry. + throw new GigiApiException("IP Addresses are not allowed"); + } checkPunycode(parts[0], s.substring(parts[0].length() + 1)); } @@ -123,7 +130,7 @@ public class Domain implements IdCachable, Verifyable { boolean existed = rs.next(); rs.close(); if (existed) { - throw new GigiApiException("Domain could not be inserted. Domain is already valid."); + throw new GigiApiException("Domain could not be inserted. Domain is already known to the system."); } } } @@ -171,7 +178,7 @@ public class Domain implements IdCachable, Verifyable { LinkedList configs = this.configs; if (configs == null) { configs = new LinkedList<>(); - try (GigiPreparedStatement ps = new GigiPreparedStatement("SELECT id FROM pingconfig WHERE domainid=?")) { + try (GigiPreparedStatement ps = new GigiPreparedStatement("SELECT id FROM pingconfig WHERE domainid=? AND `deleted` IS NULL")) { ps.setInt(1, id); GigiResultSet rs = ps.executeQuery(); while (rs.next()) { @@ -194,6 +201,14 @@ public class Domain implements IdCachable, Verifyable { configs = null; } + public void clearPings() throws GigiApiException { + try (GigiPreparedStatement ps = new GigiPreparedStatement("UPDATE `pingconfig` SET `deleted`=CURRENT_TIMESTAMP WHERE `deleted` is NULL AND `domainid`=?")) { + ps.setInt(1, id); + ps.execute(); + } + configs = null; + } + public synchronized void verify(String hash) throws GigiApiException { try (GigiPreparedStatement ps = new GigiPreparedStatement("UPDATE `domainPinglog` SET `state`='success' WHERE `challenge`=? AND `state`='open' AND `configId` IN (SELECT `id` FROM `pingconfig` WHERE `domainid`=? AND `type`='email')")) { ps.setString(1, hash); @@ -235,14 +250,14 @@ public class Domain implements IdCachable, Verifyable { return em; } - public static int searchUserIdByDomain(String domain) { - try (GigiPreparedStatement ps = new GigiPreparedStatement("SELECT `memid` FROM `domains` WHERE `domain` = ?")) { + public static Domain searchUserIdByDomain(String domain) { + try (GigiPreparedStatement ps = new GigiPreparedStatement("SELECT `id` FROM `domains` WHERE `domain` = ?")) { ps.setString(1, domain); GigiResultSet res = ps.executeQuery(); if (res.next()) { - return res.getInt(1); + return getById(res.getInt(1)); } else { - return -1; + return null; } } }