copy fakeuser also into Client struct
[ircu2.10.12-pk.git] / ircd / s_user.c
index 87c006d77396183992b008a34489a1fbf9e86520..c10eb72360d8b152f0241489e197f3346f2bbb77 100644 (file)
@@ -491,7 +491,15 @@ int register_user(struct Client *cptr, struct Client *sptr)
   if (IsOper(sptr))
     ++UserStats.opers;
   if (MyUser(sptr))
-    client_set_uprivs(sptr, cli_confs(sptr)->value.aconf);
+  {
+    if(IsOper(sptr)) {
+      FlagSet(&cli_confs(sptr)->value.aconf->conn_class->privs_dirty, PRIV_PROPAGATE);
+      client_set_privs(sptr, cli_confs(sptr)->value.aconf);
+      cli_handler(sptr) = OPER_HANDLER;
+    }
+    else
+      client_set_uprivs(sptr, cli_confs(sptr)->value.aconf);
+  }
   if (MyUser(sptr) && HasPriv(sptr, PRIV_SEE_IDLETIME))
     SetSeeIdletime(sptr);
 
@@ -531,13 +539,10 @@ int register_user(struct Client *cptr, struct Client *sptr)
 
     if(IsOper(sptr)) {
       send_reply(sptr, RPL_YOUREOPER);
-      FlagSet(&cli_confs(sptr)->value.aconf->conn_class->privs_dirty, PRIV_PROPAGATE);
-      client_set_privs(sptr, cli_confs(sptr)->value.aconf);
       sendto_opmask_butone(0, SNO_OLDSNO, "%s (%s@%s) is now operator (%c)",
                            cli_name(sptr), cli_user(sptr)->username, cli_sockhost(sptr),
                            IsOper(sptr) ? 'O' : 'o');
       log_write(LS_OPER, L_INFO, 0, "OPER (<OOC>) by (%#C)", sptr);
-      cli_handler(sptr) = OPER_HANDLER;
     }
     
     if(*cli_connclass(sptr)) 
@@ -729,24 +734,6 @@ int set_nick_name(struct Client* cptr, struct Client* sptr,
   return 0;
 }
 
-/* Refreshs the users host to the current fakehost. If no fakehost
- * is set, the account-host is created. If no Account is set,
- * nothing is done.
- * Returns 1 if the host changed and 0 if not.
- */
-int apply_fakehost(struct Client *cptr) {
-    char buf[HOSTLEN];
-    if(IsFakeHost(cptr)) {
-        ircd_strncpy(buf, cli_user(cptr)->fakehost, HOSTLEN);
-    }
-    else if (IsAccount(cptr)) {
-        ircd_snprintf(0, buf, HOSTLEN, "%s.%s", cli_user(cptr)->account, feature_str(FEAT_HIDDEN_HOST));
-    }
-    if(strncmp(buf, cli_user(cptr)->host, HOSTLEN) == 0) return 0;
-    ircd_strncpy(cli_user(cptr)->host, buf, HOSTLEN);
-    return 1;
-}
-
 /** Calculate the hash value for a target.
  * @param[in] target Pointer to target, cast to unsigned int.
  * @return Hash value constructed from the pointer.
@@ -985,6 +972,7 @@ void send_user_info(struct Client* sptr, char* names, int rpl, InfoFormatter fmt
  * @param[in] flag Some flag that affects host-hiding (FLAG_HIDDENHOST, FLAG_ACCOUNT, FLAG_FAKEHOST).
  * @return Zero.
  */
 int
 hide_hostmask(struct Client *cptr, unsigned int flag)
 {
@@ -999,6 +987,7 @@ hide_hostmask(struct Client *cptr, unsigned int flag)
     break;
   case FLAG_ACCOUNT:
   case FLAG_FAKEHOST:
+  case FLAG_FAKEIDENT:
     /* Invalidate all bans against the user so we check them again */
     for (chan = (cli_user(cptr))->channel; chan;
          chan = chan->next_channel)
@@ -1018,7 +1007,7 @@ hide_hostmask(struct Client *cptr, unsigned int flag)
   if(IsFakeHost(cptr)) ircd_strncpy(buf, cli_user(cptr)->fakehost, HOSTLEN);
   else if (IsAccount(cptr)) ircd_snprintf(0, buf, HOSTLEN, "%s.%s", cli_user(cptr)->account, feature_str(FEAT_HIDDEN_HOST));
   else return 0;
-  if(strncmp(buf, cli_user(cptr)->host, HOSTLEN) == 0) return 0;
+  if(strncmp(buf, cli_user(cptr)->host, HOSTLEN) == 0 && (!IsFakeIdent(cptr) || strncmp(cli_user(cptr)->fakeuser, cli_user(cptr)->username, USERLEN) == 0)) return 0;
 
   /* Remove all "valid" marks on the bans. This forces them to be
    * rechecked if the ban is accessed again.
@@ -1031,9 +1020,20 @@ hide_hostmask(struct Client *cptr, unsigned int flag)
   sendcmdto_common_channels_butone(cptr, CMD_QUIT, cptr, ":Registered");
   ircd_strncpy(cli_user(cptr)->host, buf, HOSTLEN);
 
-  /* ok, the client is now fully hidden, so let them know -- hikari */
-  if (MyConnect(cptr))
-   send_reply(cptr, RPL_HOSTHIDDEN, cli_user(cptr)->host);
+  /* spoof also the username if username is passed */
+  if(IsFakeIdent(cptr)) {
+    if(strncmp(cli_user(cptr)->username, cli_user(cptr)->fakeuser, USERLEN) != 0) {
+      ircd_strncpy(cli_username(cptr), cli_user(cptr)->fakeuser, USERLEN);
+      ircd_strncpy(cli_user(cptr)->username, cli_user(cptr)->fakeuser, USERLEN);
+    }
+    /* ok, the client is now fully hidden, so let them know -- hikari */
+    if (MyConnect(cptr))
+      send_reply(cptr, RPL_HOSTUSERHIDDEN, cli_user(cptr)->username, cli_user(cptr)->host);
+  } else {
+    /* ok, the client is now fully hidden, so let them know -- hikari */
+    if (MyConnect(cptr))
+      send_reply(cptr, RPL_HOSTHIDDEN, cli_user(cptr)->host);
+  }
 
   /*
    * Go through all channels the client was on, rejoin him