New functions Client_[Set]OrigUser() to get/set user specified by peer

The Client_SetOrigUser() function is used to store the peer-provided
user name (see USER command) in its original form, not changed by
IDENT results, for example.
This commit is contained in:
Alexander Barton 2010-07-11 17:03:43 +02:00
parent 761b2284b9
commit 1995af0ed6
3 changed files with 57 additions and 1 deletions

View File

@ -200,8 +200,10 @@ Init_New_Client(CONN_ID Idx, CLIENT *Introducer, CLIENT *TopServer,
client->type = Type;
if (ID)
Client_SetID(client, ID);
if (User)
if (User) {
Client_SetUser(client, User, Idented);
Client_SetOrigUser(client, User);
}
if (Hostname)
Client_SetHostname(client, Hostname);
if (Info)
@ -352,6 +354,25 @@ Client_SetUser( CLIENT *Client, const char *User, bool Idented )
} /* Client_SetUser */
/**
* Set "original" user name of a client.
* This function saves the "original" user name, the user name specified by
* the peer using the USER command, into the CLIENT structure. This user
* name may be used for authentication, for example.
* @param Client The client.
* @param User User name to set.
*/
GLOBAL void
Client_SetOrigUser(CLIENT *Client, const char *User) {
assert(Client != NULL);
assert(User != NULL);
#ifdef PAM & IDENTAUTH
strlcpy(Client->orig_user, User, sizeof(Client->orig_user));
#endif
} /* Client_SetOrigUser */
GLOBAL void
Client_SetInfo( CLIENT *Client, const char *Info )
{
@ -601,6 +622,31 @@ Client_User( CLIENT *Client )
} /* Client_User */
#ifdef PAM
/**
* Get the "original" user name as supplied by the USER command.
* The user name as given by the client is used for authentication instead
* of the one detected using IDENT requests.
* @param Client The client.
* @return Original user name.
*/
GLOBAL char *
Client_OrigUser(CLIENT *Client) {
#ifndef IDENTAUTH
char *user = Client->user;
if (user[0] == '~')
user++;
return user;
#else
return Client->orig_user;
#endif
} /* Client_OrigUser */
#endif
GLOBAL char *
Client_Hostname( CLIENT *Client )
{

View File

@ -43,6 +43,9 @@ typedef struct _CLIENT
char pwd[CLIENT_PASS_LEN]; /* password received of the client */
char host[CLIENT_HOST_LEN]; /* hostname of the client */
char user[CLIENT_USER_LEN]; /* user name ("login") */
#ifdef PAM & IDENTAUTH
char orig_user[CLIENT_USER_LEN];/* user name supplied by USER command */
#endif
char info[CLIENT_INFO_LEN]; /* long user name (user) / info text (server) */
char modes[CLIENT_MODE_LEN]; /* client modes */
int hops, token, mytoken; /* "hops" and "Token" (see SERVER command) */
@ -92,6 +95,9 @@ GLOBAL char *Client_ID PARAMS(( CLIENT *Client ));
GLOBAL char *Client_Mask PARAMS(( CLIENT *Client ));
GLOBAL char *Client_Info PARAMS(( CLIENT *Client ));
GLOBAL char *Client_User PARAMS(( CLIENT *Client ));
#ifdef PAM
GLOBAL char *Client_OrigUser PARAMS(( CLIENT *Client ));
#endif
GLOBAL char *Client_Hostname PARAMS(( CLIENT *Client ));
GLOBAL char *Client_Password PARAMS(( CLIENT *Client ));
GLOBAL char *Client_Modes PARAMS(( CLIENT *Client ));
@ -111,6 +117,7 @@ GLOBAL bool Client_HasMode PARAMS(( CLIENT *Client, char Mode ));
GLOBAL void Client_SetHostname PARAMS(( CLIENT *Client, const char *Hostname ));
GLOBAL void Client_SetID PARAMS(( CLIENT *Client, const char *Nick ));
GLOBAL void Client_SetUser PARAMS(( CLIENT *Client, const char *User, bool Idented ));
GLOBAL void Client_SetOrigUser PARAMS(( CLIENT *Client, const char *User ));
GLOBAL void Client_SetInfo PARAMS(( CLIENT *Client, const char *Info ));
GLOBAL void Client_SetPassword PARAMS(( CLIENT *Client, const char *Pwd ));
GLOBAL void Client_SetType PARAMS(( CLIENT *Client, int Type ));

View File

@ -401,6 +401,7 @@ IRC_USER(CLIENT * Client, REQUEST * Req)
#else
Client_SetUser(Client, Req->argv[0], false);
#endif
Client_SetOrigUser(Client, Req->argv[0]);
/* "Real name" or user info text: Don't set it to the empty
* string, the original ircd can't deal with such "real names"
@ -433,6 +434,7 @@ IRC_USER(CLIENT * Client, REQUEST * Req)
Req->prefix);
Client_SetUser(c, Req->argv[0], true);
Client_SetOrigUser(c, Req->argv[0]);
Client_SetHostname(c, Req->argv[1]);
Client_SetInfo(c, Req->argv[3]);
@ -575,6 +577,7 @@ IRC_WEBIRC(CLIENT *Client, REQUEST *Req)
Client_Conn(Client), Req->argv[1], Req->argv[2], Req->argv[3]);
Client_SetUser(Client, Req->argv[1], true);
Client_SetOrigUser(Client, Req->argv[1]);
Client_SetHostname(Client, Req->argv[2]);
return CONNECTED;
} /* IRC_WEBIRC */