From 1260ad59bb7b6aefd322c66ced710c51d5933bd3 Mon Sep 17 00:00:00 2001 From: Michael Poole Date: Sat, 18 Dec 2004 18:07:16 +0000 Subject: [PATCH] Move unreg, privs, capab and active fields from struct Client to struct Connection. git-svn-id: file:///home/klmitch/undernet-ircu/undernet-ircu-svn/ircu2/trunk@1285 c9e4aea6-c8fd-4c43-8297-357d70d61c8c --- ChangeLog | 13 +++++++++++++ include/client.h | 30 +++++++++++++++++++++--------- ircd/client.c | 40 +++++++++++++++++----------------------- ircd/m_server.c | 2 ++ 4 files changed, 53 insertions(+), 32 deletions(-) diff --git a/ChangeLog b/ChangeLog index 038041e..c02fdcc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2004-12-18 Michael Poole + + * include/client.h: Move unreg, privs, capab and active fields + from struct Client to struct Connection since that is how they + are really associated. Adjust macros to match. + (SetPriv, ClrPriv): New macros. + + * ircd/client.c (client_set_privs): Exit earlier for remote + clients. Adjust macro use to correspond. + + * ircd/m_server.c (mr_server): Grant all privileges except + PRIV_SET to peer servers. + 2004-12-18 Michael Poole * ircd/s_user.c (hide_hostmask): Add a missing "break;" to fix bug diff --git a/include/client.h b/include/client.h index 7b97409..42881b1 100644 --- a/include/client.h +++ b/include/client.h @@ -212,6 +212,7 @@ struct Connection struct DNSReply* con_dns_reply; /**< DNS reply received during client registration. */ struct ListingArgs* con_listing; /**< Current LIST status. */ + unsigned long con_unreg; /**< Indicate what still needs to be done */ unsigned int con_max_sendq; /**< cached max send queue for client */ unsigned int con_ping_freq; /**< cached ping freq */ unsigned short con_lastsq; /**< # 2k blocks when sendqueued @@ -230,6 +231,9 @@ struct Connection client */ struct Timer con_proc; /**< process latent messages from client */ + struct Privs con_privs; /**< Oper privileges */ + struct CapSet con_capab; /**< Client capabilities */ + struct CapSet con_active; /**< Active client capabilities */ struct AuthRequest* con_auth; /**< auth request for client */ struct IAuthRequest* con_iauth; /**< iauth request for client */ }; @@ -256,10 +260,6 @@ struct Client { unsigned int cli_hopcount; /**< number of servers to this 0 = local */ struct irc_in_addr cli_ip; /**< Real IP of client */ short cli_status; /**< Client type */ - struct Privs cli_privs; /**< Oper privileges */ - struct CapSet cli_capab; /**< Client capabilities */ - struct CapSet cli_active; /**< Active client capabilities */ - unsigned long cli_unreg; /**< Indicate what still needs to be done */ char cli_name[HOSTLEN + 1]; /**< Unique name of the client, nick or host */ char cli_username[USERLEN + 1]; /**< username here now for auth stuff */ char cli_info[REALLEN + 1]; /**< Free form additional client information */ @@ -318,13 +318,13 @@ struct Client { /** Return non-zero if the client is local. */ #define cli_local(cli) (cli_from(cli) == cli) /** Get oper privileges for client. */ -#define cli_privs(cli) ((cli)->cli_privs) +#define cli_privs(cli) con_privs(cli_connect(cli)) /** Get client capabilities for client */ -#define cli_capab(cli) (&((cli)->cli_capab)) +#define cli_capab(cli) con_capab(cli_connect(cli)) /** Get active client capabilities for client */ -#define cli_active(cli) (&((cli)->cli_active)) +#define cli_active(cli) con_active(cli_connect(cli)) /** Get flags for remaining registration tasks */ -#define cli_unreg(cli) ((cli)->cli_unreg) +#define cli_unreg(cli) con_unreg(cli_connect(cli)) /** Get client name. */ #define cli_name(cli) ((cli)->cli_name) /** Get client username (ident). */ @@ -451,6 +451,8 @@ struct Client { #define con_dns_reply(con) ((con)->con_dns_reply) /** Get the LIST status for the connection. */ #define con_listing(con) ((con)->con_listing) +/** Get remining steps before registration completes. */ +#define con_unreg(con) ((con)->con_unreg) /** Get the maximum permitted SendQ size for the connection. */ #define con_max_sendq(con) ((con)->con_max_sendq) /** Get the ping frequency for the connection. */ @@ -471,6 +473,12 @@ struct Client { #define con_socket(con) ((con)->con_socket) /** Get the Timer for processing more data from the connection. */ #define con_proc(con) ((con)->con_proc) +/** Get the oper privilege set for the connection. */ +#define con_privs(con) (&(con)->con_privs) +/** Get the peer's capabilities for the connection. */ +#define con_capab(con) (&(con)->con_capab) +/** Get the active capabilities for the connection. */ +#define con_active(con) (&(con)->con_active) /** Get the auth request for the connection. */ #define con_auth(con) ((con)->con_auth) /** Get the iauth request for the connection. */ @@ -734,7 +742,11 @@ struct Client { #define SNO_NOISY (SNO_SERVKILL|SNO_UNAUTH) /** Test whether a privilege has been granted to a client. */ -#define HasPriv(cli, priv) FlagHas(&cli_privs(cli), priv) +#define HasPriv(cli, priv) FlagHas(cli_privs(cli), priv) +/** Grant a privilege to a client. */ +#define SetPriv(cli, priv) FlagSet(cli_privs(cli), priv) +/** Revoke a privilege from a client. */ +#define ClrPriv(cli, priv) FlagClr(cli_privs(cli), priv) /** Test whether a client has a capability */ #define HasCap(cli, cap) CapHas(cli_capab(cli), (cap)) diff --git a/ircd/client.c b/ircd/client.c index 6860d0c..e8bf6c9 100644 --- a/ircd/client.c +++ b/ircd/client.c @@ -140,6 +140,15 @@ client_set_privs(struct Client *client, struct ConfItem *oper) struct Privs *source, *defaults; enum Priv priv; + if (!MyConnect(client)) + return; + + /* Clear out client's privileges. */ + memset(cli_privs(client), 0, sizeof(struct Privs)); + + if (!IsAnOper(client) || !oper) + return; + if (!privs_defaults_set) { memset(&privs_global, -1, sizeof(privs_global)); @@ -158,21 +167,6 @@ client_set_privs(struct Client *client, struct ConfItem *oper) FlagSet(&privs_local, PRIV_FORCE_LOCAL_OPMODE); privs_defaults_set = 1; } - memset(&(cli_privs(client)), 0, sizeof(struct Privs)); - - if (!IsAnOper(client)) - return; - else if (!MyConnect(client)) - { - memset(&(cli_privs(client)), 255, sizeof(struct Privs)); - FlagClr(&(cli_privs(client)), PRIV_SET); - return; - } - else if (oper == NULL) - return; - - /* Clear out client's privileges. */ - memset(&cli_privs(client), 0, sizeof(struct Privs)); /* Decide whether to use global or local oper defaults. */ if (FlagHas(&oper->privs_dirty, PRIV_PROPAGATE)) @@ -199,23 +193,23 @@ client_set_privs(struct Client *client, struct ConfItem *oper) /* Set it if necessary (privileges were already cleared). */ if (FlagHas(source, priv)) - FlagSet(&cli_privs(client), priv); + SetPriv(client, priv); } /* This should be handled in the config, but lets be sure... */ - if (FlagHas(&cli_privs(client), PRIV_PROPAGATE)) + if (HasPriv(client, PRIV_PROPAGATE)) { /* force propagating opers to display */ - FlagSet(&cli_privs(client), PRIV_DISPLAY); + SetPriv(client, PRIV_DISPLAY); } else { /* if they don't propagate oper status, prevent desyncs */ - FlagClr(&cli_privs(client), PRIV_KILL); - FlagClr(&cli_privs(client), PRIV_GLINE); - FlagClr(&cli_privs(client), PRIV_JUPE); - FlagClr(&cli_privs(client), PRIV_OPMODE); - FlagClr(&cli_privs(client), PRIV_BADCHAN); + ClrPriv(client, PRIV_KILL); + ClrPriv(client, PRIV_GLINE); + ClrPriv(client, PRIV_JUPE); + ClrPriv(client, PRIV_OPMODE); + ClrPriv(client, PRIV_BADCHAN); } } diff --git a/ircd/m_server.c b/ircd/m_server.c index 934fd3a..7d57cd5 100644 --- a/ircd/m_server.c +++ b/ircd/m_server.c @@ -610,6 +610,8 @@ int mr_server(struct Client* cptr, struct Client* sptr, int parc, char* parv[]) cli_serv(cptr)->timestamp = timestamp; cli_serv(cptr)->prot = prot; cli_serv(cptr)->ghost = ghost; + memset(cli_privs(cptr), 255, sizeof(struct Privs)); + ClrPriv(cptr, PRIV_SET); SetServerYXX(cptr, cptr, parv[6]); /* Attach any necessary UWorld config items. */ -- 2.20.1