ircu2.10.12 pk910 fork
[ircu2.10.12-pk.git] / patches / diffs / sline.diff
1 diff -urdb doc/example.conf ircu2.10.11.06/doc/example.conf
2 --- doc/example.conf    Wed Jan 28 22:28:05 2004
3 +++ doc/example.conf    Wed Jan 28 23:20:26 2004
4 @@ -365,6 +365,30 @@
5  # Y:10:90:0:100:160000
6  
7  
8 +# [S:lines]
9 +# Opers may wish to hide their IP mask and hostname, even if they are on
10 +# a bnc. This can prevent the risk of opers or their providers getting
11 +# dos'd or whatever the case may be.
12 +#
13 +# When a client connects, his or her IP is compared to the incoming_IP in 
14 +# each of the S:lines in the conf. If it finds an exact match (NOT a mask 
15 +# match, but a simple comparison), it will substitute the client's ip with 
16 +# modified_IP and the client's real hostname with modified_hostname (as 
17 +# shown below).
18 +#
19 +# Syntax:
20 +# S:<incoming_IP>:<modified_IP>:<modifed_hostname>
21 +#
22 +# Example:
23 +# S:193.178.138.13:192.168.128.1:undernet.org
24 +#
25 +# If a user connects to the server with the IP 193.178.138.13, it is
26 +# automatically changed to 192.168.128.1 and the user's host is set to
27 +# undernet.org.
28 +#
29 +# If no modified_IP is provided, only the host is modified.
30 +
31 +
32  # [P:lines]
33  # When your server gets more full, you will notice delays when trying to
34  # connect to your server's primary listening port. It is possible via the
35 diff -urdb include/client.h ircu2.10.11.06/include/client.h
36 --- include/client.h    Wed Jan 28 22:28:05 2004
37 +++ include/client.h    Wed Jan 28 23:20:26 2004
38 @@ -127,6 +127,7 @@
39      FLAG_GOTID,                     /* successful ident lookup achieved */
40      FLAG_DOID,                      /* I-lines say must use ident return */
41      FLAG_NONL,                      /* No \n in buffer */
42 +    FLAG_SLINE,                     /* User is S-lined */
43      FLAG_TS8,                       /* Why do you want to know? */
44      FLAG_MAP,                       /* Show server on the map */
45      FLAG_JUNCTION,                  /* Junction causing the net.burst */
46 @@ -429,6 +430,7 @@
47  #define IsAccount(x)            HasFlag(x, FLAG_ACCOUNT)
48  #define IsHiddenHost(x)                HasFlag(x, FLAG_HIDDENHOST)
49  #define HasHiddenHost(x)       (IsAccount(x) && IsHiddenHost(x))
50 +#define HasSLine(x)             HasFlag(x, FLAG_SLINE)
51  
52  #define IsPrivileged(x)         (IsAnOper(x) || IsServer(x))
53  
54 @@ -451,6 +453,7 @@
55  #define SetService(x)           SetFlag(x, FLAG_SERVICE)
56  #define SetAccount(x)           SetFlag(x, FLAG_ACCOUNT)
57  #define SetHiddenHost(x)       SetFlag(x, FLAG_HIDDENHOST)
58 +#define SetSLined(x)            SetFlag(x, FLAG_SLINE)
59  
60  #define ClearAccess(x)          ClrFlag(x, FLAG_CHKACCESS)
61  #define ClearBurst(x)           ClrFlag(x, FLAG_BURST)
62 diff -urdb include/s_conf.h ircu2.10.11.06/include/s_conf.h
63 --- include/s_conf.h    Wed Jan 28 22:28:05 2004
64 +++ include/s_conf.h    Wed Jan 28 23:20:26 2004
65 @@ -33,6 +33,7 @@
66  
67  #define CONF_ILLEGAL            0x80000000
68  #define CONF_MATCH              0x40000000
69 +#define CONF_SPOOF              0x20000000
70  #define CONF_CLIENT             0x0002
71  #define CONF_SERVER             0x0004
72  #define CONF_LOCOP              0x0010
73 diff -urdb ircd/s_auth.c ircu2.10.11.06/ircd/s_auth.c
74 --- ircd/s_auth.c       Wed Jan 28 22:28:05 2004
75 +++ ircd/s_auth.c       Wed Jan 28 23:20:26 2004
76 @@ -46,6 +46,7 @@
77  #include "querycmds.h"
78  #include "res.h"
79  #include "s_bsd.h"
80 +#include "s_conf.h"
81  #include "s_debug.h"
82  #include "s_misc.h"
83  #include "send.h"
84 @@ -82,6 +83,7 @@
85    { "NOTICE AUTH :*** No ident response\r\n",              36 },
86    { "NOTICE AUTH :*** Your forward and reverse DNS do not match, " \
87      "ignoring hostname.\r\n",                              80 },
88 +  { "NOTICE AUTH :*** Using S-line privilege\r\n",         41 },
89    { "NOTICE AUTH :*** Invalid hostname\r\n",               35 }
90  };
91  
92 @@ -94,6 +96,7 @@
93    REPORT_FIN_ID,
94    REPORT_FAIL_ID,
95    REPORT_IP_MISMATCH,
96 +  REPORT_USING_SLINE,
97    REPORT_INVAL_DNS
98  } ReportType;
99  
100 @@ -595,6 +598,13 @@
101    struct AuthRequest* auth = 0;
102  
103    assert(0 != client);
104 +
105 +  if (conf_check_slines(client)) {
106 +    sendheader(client, REPORT_USING_SLINE);
107 +    SetSLined(client);
108 +    release_auth_client(client);
109 +    return;
110 +  }
111  
112    auth = make_auth_request(client);
113    assert(0 != auth);
114 diff -urdb ircd/s_conf.c ircu2.10.11.06/ircd/s_conf.c
115 --- ircd/s_conf.c       Wed Jan 28 22:28:05 2004
116 +++ ircd/s_conf.c       Wed Jan 28 23:20:26 2004
117 @@ -1170,6 +1170,10 @@
118        conf_add_quarantine(field_vector, field_count);
119        aconf->status = CONF_ILLEGAL;
120        break;
121 +    case 'S':
122 +    case 's':
123 +      aconf->status = CONF_SPOOF;
124 +      break;
125      case 'T':                /* print out different motd's */
126      case 't':                /* based on hostmask - CONF_TLINES */
127        motd_add(field_vector[1], field_vector[2]);
128 @@ -1272,6 +1276,9 @@
129      if ((aconf->status == CONF_UWORLD) && (aconf->passwd) && (*aconf->passwd))
130        addNickJupes(aconf->passwd);
131  
132 +    if (aconf->status & CONF_SPOOF)
133 +      lookup_confhost(aconf);
134 +
135      collapse(aconf->host);
136      collapse(aconf->name);
137      Debug((DEBUG_NOTICE,
138 @@ -1647,6 +1654,70 @@
139      c_conf->ipnum.s_addr = cli_ip(cptr).s_addr;
140  
141    Debug((DEBUG_DNS, "sv_cl: access ok: %s[%s]", cli_name(cptr), cli_sockhost(cptr)));
142 +  return 0;
143 +}
144 +
145 +/*
146 + * conf_check_slines()
147 + *
148 + * Check S lines for the specified client, passed in cptr struct.
149 + * If the client's IP is S-lined, process the substitution here.
150 + * 1. cptr->cli_ip                    (cli_ip(cptr))
151 + * 2. cptr->cli_connect->con_sock_ip  (cli_sock_ip(cptr))
152 + * 3. cptr->cli_connect->sockhost     (cli_sockhost(cptr))
153 + *
154 + * If no substitued IP are specified, only change sockhost.
155 + *
156 + * Precondition
157 + *  cptr != NULL
158 + *
159 + * Returns
160 + *  0 = No S-line found
161 + *  1 = S-line found and substitution done.
162 + *
163 + * -mbuna 9/2001
164 + *
165 + */
166 +
167 +int
168 +conf_check_slines(struct Client *cptr)
169 +{
170 +  struct ConfItem* aconf;
171 +  struct in_addr iptemp;
172 +  char* hostonly;
173 +
174 +  for (aconf = GlobalConfList; aconf; aconf = aconf->next) {
175 +    if (aconf->status != CONF_SPOOF)
176 +      continue;
177 +    if ((aconf->dns_pending)
178 +      || (INADDR_NONE == aconf->ipnum.s_addr)
179 +      || EmptyString(aconf->name))
180 +      continue;
181 +
182 +    if (cli_ip(cptr).s_addr == aconf->ipnum.s_addr) {
183 +
184 +                               /* Ignore user part if u@h. */
185 +      if ((hostonly = strchr(aconf->name, '@')))
186 +        hostonly++;
187 +      else
188 +        hostonly = aconf->name;
189 +
190 +      if(!*hostonly)
191 +        continue;
192 +
193 +      if (!EmptyString(aconf->passwd)) {
194 +        iptemp.s_addr = inet_addr(aconf->passwd);
195 +        if (INADDR_NONE == iptemp.s_addr)
196 +          continue;
197 +        cli_ip(cptr).s_addr = iptemp.s_addr;
198 +      }
199 +
200 +                               /* Perform a luxurious ircd_ntoa for sanity. */
201 +      ircd_strncpy(cli_sock_ip(cptr), ircd_ntoa((const char*) &cli_ip(cptr)), SOCKIPLEN);
202 +      ircd_strncpy(cli_sockhost(cptr), hostonly, HOSTLEN);
203 +      return 1;
204 +    }
205 +  }
206    return 0;
207  }
208  
209 diff -urdb ircd/s_user.c ircu2.10.11.06/ircd/s_user.c
210 --- ircd/s_user.c       Wed Jan 28 22:28:05 2004
211 +++ ircd/s_user.c       Wed Jan 28 23:20:26 2004
212 @@ -422,7 +422,8 @@
213  
214      clean_user_id(user->username,
215          HasFlag(sptr, FLAG_GOTID) ? cli_username(sptr) : username,
216 -        HasFlag(sptr, FLAG_DOID) && !HasFlag(sptr, FLAG_GOTID));
217 +        HasFlag(sptr, FLAG_DOID) && !HasFlag(sptr, FLAG_GOTID)
218 +        && !(HasSLine(sptr))); /* No tilde for S-lined users. */       
219  
220      if ((user->username[0] == '\0')
221          || ((user->username[0] == '~') && (user->username[1] == '\000')))