Changeset 778
- Timestamp:
- 10/02/06 00:41:20 (6 years ago)
- Location:
- branches/ithildin-1.1
- Files:
-
- 5 edited
-
include/ithildin/socket.h (modified) (1 diff)
-
modules/ircd/addons/hostmask.c (modified) (3 diffs)
-
modules/ircd/commands/pass.c (modified) (1 diff)
-
source/socket.c (modified) (1 diff)
-
source/string.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/ithildin-1.1/include/ithildin/socket.h
r578 r778 144 144 #endif 145 145 146 /* Functions for handling network address type detection */ 147 int get_address_type(const char *); 148 146 149 /* if we don't have a system getaddrinfo, use the ones that will be included 147 150 * from source/contrib/gailib.c */ -
branches/ithildin-1.1/modules/ircd/addons/hostmask.c
r777 r778 26 26 HOOK_FUNCTION(hostmask_conf_hook); 27 27 HOOK_FUNCTION(hostmask_cc_hook); 28 static int validate_cgiirc_host(const char *, char **, char **); 28 29 29 30 MODULE_LOADER(hostmask) { … … 72 73 HOOK_FUNCTION(hostmask_cc_hook) { 73 74 client_t *cli = (client_t *)data; 74 char *mask ;75 char *mask, *ip; 75 76 76 77 if (cli->conn == NULL) 77 78 return NULL; /* nothing to do */ 78 79 80 mask = ip = NULL; 81 79 82 mask = mdext(cli->conn->cls, class_hostmask_mdi); 80 83 if (mask != NULL && *mask != '\0') { 81 84 if (!strcasecmp(mask, CGI_IRC_SPECIAL_MASK)) { 82 /* Special CGI:IRC hack. We take the password, if supplied, an d83 * use it as a hostname (as long as it's valid) */85 /* Special CGI:IRC hack. We take the password, if supplied, an 86 * use it as a hostname (as long as it's valid). Good stuff. */ 84 87 if (cli->conn->pass != NULL && *cli->conn->pass != '\0' && 85 istr_okay(ircd.maps.host, cli->conn->pass)) 86 mask = cli->conn->pass; 87 else { 88 validate_cgiirc_host(cli->conn->pass, &ip, &mask)) { 89 log_debug("cgi:irc connection masked as %s / %s", ip, mask); 90 strcpy(cli->ip, ip); /* set the IP as well */ 91 } else { 88 92 log_warn("cgi:irc hostmasked connection provided invalid " 89 93 "host (%s) (%s!%s@%s)", … … 102 106 } 103 107 108 /* CGIIRC(6)+__(2)+\0(1)+ip+host */ 109 #define CGIIRC_HOST_SIZE 9 + IPADDR_MAXLEN + HOSTLEN 110 111 /* validate the string from a CGI:IRC connection. The string is of the form 112 * CGIIRC_<ip>_<host>. We ensure that both the IP and hostname are valid. */ 113 static int validate_cgiirc_host(const char *in, char **ip, char **host) { 114 static char str[CGIIRC_HOST_SIZE]; 115 char *s_ip, *s_host; 116 117 *ip = *host = NULL; 118 strlcpy(str, in, CGIIRC_HOST_SIZE); 119 120 if (strncmp(str, "CGIIRC_", 7)) 121 return 0; 122 123 s_ip = str + 7; 124 if ((s_host = strchr(s_ip, '_')) == NULL) 125 return 0; /* no hostname */ 126 *s_host++ = '\0'; 127 128 /* now we have ip/host, let's validate */ 129 if (*s_ip == '\0' || *s_host == '\0') 130 return 0; 131 132 if (get_address_type(s_ip) == PF_UNSPEC) 133 return 0; /* bad IP */ 134 135 if (strchr(s_host, '.') == NULL || !istr_okay(ircd.maps.host, s_host)) 136 return 0; /* bogus host */ 137 138 *ip = s_ip; 139 *host = s_host; 140 return 1; 141 } 142 104 143 /* vi:set ts=8 sts=4 sw=4 tw=76 et: */ -
branches/ithildin-1.1/modules/ircd/commands/pass.c
r772 r778 39 39 if (conn->pass != NULL) 40 40 free(conn->pass); /* dump whatever was there before.. */ 41 conn->pass = malloc(HOSTLEN + 1); 42 strlcpy(conn->pass, pass, HOSTLEN + 1); 41 conn->pass = strdup(pass); 43 42 } 44 43 -
branches/ithildin-1.1/source/socket.c
r610 r778 1008 1008 #endif 1009 1009 1010 /* Function to determine the type of an address. We do cheap best effort 1011 * here. If it looks IPv6-y we try inet_pton with AF_INET6, if it looks 1012 * IPv4-y we try inet_pton with AF_INET, and as long as one succeeds we 1013 * return that type. */ 1014 int get_address_type(const char *addr) { 1015 const char *s = addr; 1016 unsigned char buf[IPADDR_SIZE]; 1017 1018 #ifdef INET6 1019 if ((s = strchr(addr, ':') != NULL) && strchr(s + 1, ':') != NULL) { 1020 /* either IPv6 or nothing, let's see */ 1021 if (inet_pton(PF_INET6, addr, buf) == 1) 1022 return PF_INET6; 1023 return PF_UNSPEC; 1024 } 1025 #endif 1026 1027 if (inet_pton(PF_INET, addr, buf) == 1) 1028 return PF_INET; 1029 return PF_UNSPEC; 1030 } 1031 1010 1032 /* vi:set ts=8 sts=4 sw=4 tw=76 et: */ -
branches/ithildin-1.1/source/string.c
r592 r778 647 647 int imask = 0; 648 648 int i; 649 char * s;649 char *mask; 650 650 651 651 memset(bitmask, 0xff, IPADDR_SIZE); 652 652 strlcpy(addr, wild, IPADDR_MAXLEN + 1); 653 /* First figure out what kind of address we've got. We no longer support 654 * IPv4 mask form (ip:mask), but IPv6 addresses need at least two colons. 655 * If we find only one, just return 0 right away. */ 656 if ((s = strchr(wild, ':')) != NULL) { 657 if (strchr(s + 1, ':') != NULL) 658 family = PF_INET6; /* actually, inet6.. */ 659 else 660 return 0; /* no mask support */ 661 } 662 663 if ((s = strchr(wild, '/')) != NULL) { 653 654 /* strip off the mask portion if it is there */ 655 if ((mask = strchr(wild, '/')) != NULL) { 664 656 /* mask form. mask specifies significant bits from left to right. 665 * simple enough. */ 666 if (IPADDR_MAXLEN > s - wild) 667 addr[s - wild] = '\0'; 668 s++; 669 imask = str_conv_int(s, 32); 657 * we must make sure to truncate addr at the point where the mask 658 * starts as well, if it starts before IPADDR_MAXLEN. */ 659 if (IPADDR_MAXLEN > mask - wild) 660 addr[mask - wild] = '\0'; 661 mask++; 662 } 663 664 /* now determine the address family */ 665 family = get_address_type(addr); 666 if (family != PF_INET && family != PF_INET6) 667 return 0; 668 669 /* and handle the bitmasking if need-be */ 670 if (mask != NULL) { 671 imask = str_conv_int(mask, 0); 672 670 673 if (family == PF_INET6) { 671 674 if (imask <= 0) … … 684 687 bitmask[(i - 1) / 8] = 0xff << (i % 8 ? (8 - (i % 8)) : 0); 685 688 } 686 addr[IPADDR_MAXLEN] = '\0';687 689 688 690 /* now copy our addresses into bitmasks. if either pton fails, assume no
Note: See TracChangeset
for help on using the changeset viewer.
