diff --git a/Changes b/Changes index 2cdd3de5b..f00d04cdf 100644 --- a/Changes +++ b/Changes @@ -597,3 +597,4 @@ - Fixed some more -Wall warnings - ./update now checks when you specify wget if it exists, if not it tries lynx - Cached MOTDs are now dynamically allocated (saves alot of memory) +- Made aClient->passwd dynamically allocated (saves 32bytes per user/server) [may need debugging] diff --git a/include/struct.h b/include/struct.h index fe9ab38d8..bd8ae47f7 100644 --- a/include/struct.h +++ b/include/struct.h @@ -866,7 +866,7 @@ struct Client { ** and after which the connection was ** accepted. */ - char passwd[PASSWDLEN + 1]; + char *passwd; #ifdef DEBUGMODE TS cputime; #endif diff --git a/src/s_serv.c b/src/s_serv.c index 0435145e4..48d2ab9c7 100644 --- a/src/s_serv.c +++ b/src/s_serv.c @@ -1109,7 +1109,8 @@ int m_server_estab(cptr) sendto_ops("Access denied (passwd mismatch) %s", inpath); return exit_client(cptr, cptr, cptr, "Bad Password"); } - bzero(cptr->passwd, sizeof(cptr->passwd)); + if (cptr->passwd) + MyFree(cptr->passwd); #ifndef HUB for (i = 0; i <= highest_fd; i++) if (local[i] && IsServer(local[i])) diff --git a/src/s_user.c b/src/s_user.c index 1be3dd5b6..db89aeff9 100644 --- a/src/s_user.c +++ b/src/s_user.c @@ -802,7 +802,7 @@ static int register_user(cptr, sptr, nick, username, umode, virthost) * - Wizzu */ else - sptr->passwd[0] = '\0'; + MyFree(sptr->passwd); } /* @@ -962,6 +962,7 @@ static int register_user(cptr, sptr, nick, username, umode, virthost) */ if (MyConnect(sptr)) { + if (sptr->passwd[0]) if (sptr->passwd[0] && (nsptr = find_person(NickServ, NULL))) sendto_one(nsptr, ":%s PRIVMSG %s@%s :IDENTIFY %s", sptr->name, NickServ, SERVICES_NAME, sptr->passwd); @@ -980,9 +981,10 @@ static int register_user(cptr, sptr, nick, username, umode, virthost) } } - if (MyConnect(sptr) && !BadPtr(sptr->passwd)) - bzero(sptr->passwd, sizeof(sptr->passwd)); - + if (MyConnect(sptr) && !BadPtr(sptr->passwd)) { + MyFree(sptr->passwd); + ircd_log("%s freed", sptr->passwd); + } return 0; } @@ -3988,7 +3990,7 @@ int m_pass(cptr, sptr, parc, parv) char *parv[]; { char *password = parc > 1 ? parv[1] : NULL; - + int PassLen = 0; if (BadPtr(password)) { sendto_one(cptr, err_str(ERR_NEEDMOREPARAMS), @@ -4001,7 +4003,13 @@ int m_pass(cptr, sptr, parc, parv) me.name, parv[0]); return 0; } - strncpyzt(cptr->passwd, password, sizeof(cptr->passwd)); + PassLen = strlen(password); + if (cptr->passwd) + MyFree(cptr->passwd); + if (PassLen > (PASSWDLEN)) + PassLen = PASSWDLEN; + cptr->passwd = MyMalloc(PassLen + 1); + strncpyzt(cptr->passwd, password, PassLen +1); return 0; }