summary refs log tree commit diff
diff options
context:
space:
mode:
authorAlexander Barton <alex@barton.de>2010-07-11 17:03:43 +0200
committerAlexander Barton <alex@barton.de>2010-07-11 17:03:43 +0200
commit1995af0ed62a4bbf544e0b5d9e0613fc912c9e3b (patch)
tree113762d3764261155428085ef773afe4473d25d7
parent761b2284b953de0d5c2f847e55e3fbc030243178 (diff)
downloadngircd-1995af0ed62a4bbf544e0b5d9e0613fc912c9e3b.tar.gz
ngircd-1995af0ed62a4bbf544e0b5d9e0613fc912c9e3b.zip
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.
-rw-r--r--src/ngircd/client.c48
-rw-r--r--src/ngircd/client.h7
-rw-r--r--src/ngircd/irc-login.c3
3 files changed, 57 insertions, 1 deletions
diff --git a/src/ngircd/client.c b/src/ngircd/client.c
index e6dbf156..44123eaa 100644
--- a/src/ngircd/client.c
+++ b/src/ngircd/client.c
@@ -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 )
 {
diff --git a/src/ngircd/client.h b/src/ngircd/client.h
index 90fd6f28..352ddf38 100644
--- a/src/ngircd/client.h
+++ b/src/ngircd/client.h
@@ -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 ));
diff --git a/src/ngircd/irc-login.c b/src/ngircd/irc-login.c
index 5a52d3cb..906b669b 100644
--- a/src/ngircd/irc-login.c
+++ b/src/ngircd/irc-login.c
@@ -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 */