]> jfr.im git - irc/quakenet/newserv.git/commitdiff
Add TRUST_RELIABLE_USERNAME flag and clean up how we print flags.
authorGunnar Beutner <redacted>
Fri, 5 Jul 2013 16:32:21 +0000 (18:32 +0200)
committerGunnar Beutner <redacted>
Fri, 5 Jul 2013 16:32:21 +0000 (18:32 +0200)
--HG--
branch : shroudtrusts

glines/glines.c
trusts/formats.c
trusts/trusts.h
trusts/trusts_commands.c
trusts/trusts_management.c

index 2070b658b1fc17fc0eb3ba96650cf1d93cbbb970..74c9a31517b6ae0bfb79b7c2c7dca6f7330ab42f 100644 (file)
@@ -51,7 +51,7 @@ int glinesuggestbyip(const char *user, struct irc_in_addr *ip, unsigned char bit
   if (!(flags & GLINE_IGNORE_TRUST)) {
     th = th_getbyhost(ip);
 
-    if(th && (th->group->flags & TRUST_ENFORCE_IDENT)) { /* Trust with enforceident enabled */
+    if(th && (th->group->flags & TRUST_RELIABLE_USERNAME)) { /* Trust with reliable usernames */
       count = 0;
 
       for(oth=th->group->hosts;oth;oth=oth->next)
index b570af1f536808b06d0da2881713eb5bf68b1dad..46709e8b4543a91c8175e2621d224e49cbd01837 100644 (file)
@@ -113,6 +113,9 @@ int parsetg(char *buf, trustgroup *tg, int oformat) {
     r = sscanf(line, "%*u,%u,%u,%u,%u,%lu,%lu,%lu,%n",
                /*current, */ &tg->trustedfor, &tg->flags, &tg->maxperident,
                &tg->maxusage, &expires, &lastseen, &lastmaxusereset, &pos);
+
+    if(tg->maxperident > 0)
+      tg->flags |= TRUST_RELIABLE_USERNAME;
   } else {
     r = sscanf(line, "%u,%u,%u,%u,%lu,%lu,%lu,%n",
                &tg->trustedfor, &tg->flags, &tg->maxperident,
index 7691dfdf328a2ff205b3864210bcf440c52d9db1..5d8e547ca79c8b3b4f0a67b5ccfc998f4d43965c 100644 (file)
@@ -42,6 +42,7 @@
 #define TRUST_ENFORCE_IDENT 1 /* This must be 1 for compatibility with O. */
 #define TRUST_NO_CLEANUP 2
 #define TRUST_PROTECTED 4
+#define TRUST_RELIABLE_USERNAME 8
 
 #define TRUST_MIN_UNPRIVILEGED_BITS_IPV4 (96 + 20)
 #define TRUST_MIN_UNPRIVILEGED_BITS_IPV6 32
index cc57edbee0f4b7362a39e003df487b1293660671..f94e5c4328005b1acf169da7123d81e1808065ed 100644 (file)
@@ -117,6 +117,51 @@ static void outputtree(nick *np, unsigned int marker, trustgroup *originalgroup,
     outputtree(np, marker, originalgroup, th, depth + 1, showchildren);
 }
 
+static char *formatflags(int flags) {
+  static char buf[512];
+
+  buf[0] = '\0';
+
+  if(flags & TRUST_ENFORCE_IDENT)
+    strncat(buf, "enforcing ident", 512);
+
+  if(flags & TRUST_NO_CLEANUP) {
+    if(buf[0])
+      strncat(buf, ", ", 512);
+
+    strncat(buf, "exempt from cleanup", 512);
+  }
+
+  if(flags & TRUST_PROTECTED) {
+    if(buf[0])
+      strncat(buf, ", ", 512);
+
+    strncat(buf, "protected", 512);
+  }
+
+  if(flags & TRUST_RELIABLE_USERNAME) {
+    if(buf[0])
+      strncat(buf, ", ", 512);
+
+    strncat(buf, "reliable username", 512);
+  }
+
+  buf[512-1] = '\0';
+
+  return buf;
+}
+
+static char *formatlimit(unsigned int limit) {
+  static char buf[64];
+
+  if(limit)
+    snprintf(buf, sizeof(buf), "%u", limit);
+  else
+    strncpy(buf, "unlimited", sizeof(buf));
+
+  return buf;
+}
+
 static void displaygroup(nick *sender, trustgroup *tg, int showchildren) {
   trusthost *th, **p2;
   unsigned int marker;
@@ -126,13 +171,12 @@ static void displaygroup(nick *sender, trustgroup *tg, int showchildren) {
 
   /* abusing the ternary operator a bit :( */
   controlreply(sender, "Name:            : %s", tg->name->content);
-  controlreply(sender, "Trusted for      : %d", tg->trustedfor);
+  controlreply(sender, "Trusted for      : %s", formatlimit(tg->trustedfor));
   controlreply(sender, "Currently using  : %d", tg->count);
-  controlreply(sender, "Clients per user : %d (%senforcing ident)", tg->maxperident, (tg->flags & TRUST_ENFORCE_IDENT)?"":"not ");
+  controlreply(sender, "Clients per user : %s", formatlimit(tg->maxperident));
+  controlreply(sender, "Flags            : %s", formatflags(tg->flags));
   controlreply(sender, "Contact:         : %s", tg->contact->content);
   controlreply(sender, "Expires in       : %s", (tg->expires)?((tg->expires>t)?longtoduration(tg->expires - t, 2):"the past (will be removed during next cleanup)"):"never");
-  controlreply(sender, "CIDR cleanup     : %s", (tg->flags & TRUST_NO_CLEANUP)?"disabled":"enabled");
-  controlreply(sender, "Protected        : %s", (tg->flags & TRUST_PROTECTED)?"yes":"no");
   controlreply(sender, "Created by       : %s", tg->createdby->content);
   controlreply(sender, "Comment:         : %s", tg->comment->content);
   controlreply(sender, "ID:              : %u", tg->id);
index 4ad5ca10050a5e7e7a3049ed72a4f40a7e2df6f3..35001327f0f485f3f6b55082919def08ae2ecaf2 100644 (file)
@@ -120,7 +120,7 @@ static int trusts_cmdtrustgroupadd(void *source, int cargc, char **cargv) {
   char *name, *contact, *comment, createdby[ACCOUNTLEN + 2];
   unsigned int howmany, maxperident, enforceident;
   trustgroup *tg, itg;
-  int override;
+  int override, flags;
 
   if(cargc < 5)
     return CMD_USAGE;
@@ -168,8 +168,16 @@ static int trusts_cmdtrustgroupadd(void *source, int cargc, char **cargv) {
 
   snprintf(createdby, sizeof(createdby), "#%s", sender->authname);
 
+  flags = 0;
+
+  if(maxperident > 0)
+    flags |= TRUST_RELIABLE_USERNAME;
+
+  if(enforceident)
+    flags |= TRUST_ENFORCE_IDENT;
+
   itg.trustedfor = howmany;
-  itg.flags = enforceident?TRUST_ENFORCE_IDENT:0;
+  itg.flags = flags;
   itg.maxperident = maxperident;
   itg.expires = 0;
   itg.createdby = getsstring(createdby, CREATEDBYLEN);
@@ -360,6 +368,12 @@ static int modifymaxperident(void *arg, char *num, nick *source, int override) {
     return 0;
   }
 
+  if(maxperident > 0) {
+    tg->flags |= TRUST_RELIABLE_USERNAME;
+  } else {
+    tg->flags &= ~TRUST_RELIABLE_USERNAME;
+  }
+
   tg->maxperident = maxperident;
 
   return 1;