]> jfr.im git - solanum.git/blobdiff - ircd/s_newconf.c
whowas.c: store account name in whowas (#323)
[solanum.git] / ircd / s_newconf.c
index 8fc86af58d9b25017c0f55c0bbd5f668ae7936d8..31fcc959585d91387dbd1224dbc220ef207e8b6a 100644 (file)
@@ -685,23 +685,44 @@ time_t
 valid_temp_time(const char *p)
 {
        time_t result = 0;
+       long current = 0;
 
-       while(*p)
-       {
-               if(IsDigit(*p))
-               {
-                       result *= 10;
-                       result += ((*p) & 0xF);
-                       p++;
-               }
-               else
+       while (*p) {
+               char *endp;
+
+               errno = 0;
+               current = strtol(p, &endp, 10);
+
+               if (errno == ERANGE)
+                       return -1;
+               if (endp == p)
                        return -1;
-       }
 
-       if(result > (60 * 24 * 7 * 52))
-               result = (60 * 24 * 7 * 52);
+               switch (*endp) {
+               case '\0': /* No unit was given so send it back as minutes */
+               case 'm':
+                       result += current * 60;
+                       break;
+               case 'h':
+                       result += current * 3600;
+                       break;
+               case 'd':
+                       result += current * 86400;
+                       break;
+               case 'w':
+                       result += current * 604800;
+                       break;
+               default:
+                       return -1;
+               }
+
+               if (*endp == '\0')
+                       break;
+
+               p = endp + 1;
+       }
 
-       return(result * 60);
+       return MIN(result, 60 * 60 * 24 * 7 * 52);
 }
 
 /* Propagated bans are expired elsewhere. */