]> arthur.barton.de Git - ngircd-alex.git/commitdiff
New functions Client_[Set]OrigUser() to get/set user specified by peer
authorAlexander Barton <alex@barton.de>
Sun, 11 Jul 2010 15:03:43 +0000 (17:03 +0200)
committerAlexander Barton <alex@barton.de>
Sun, 11 Jul 2010 15:03:43 +0000 (17:03 +0200)
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.

src/ngircd/client.c
src/ngircd/client.h
src/ngircd/irc-login.c

index e6dbf1563c78e1f919954b91400a040d8b997d73..44123eaa0b8d9af5444f0098b5fe1d656017b2b2 100644 (file)
@@ -200,8 +200,10 @@ Init_New_Client(CONN_ID Idx, CLIENT *Introducer, CLIENT *TopServer,
        client->type = Type;
        if (ID)
                Client_SetID(client, ID);
        client->type = Type;
        if (ID)
                Client_SetID(client, ID);
-       if (User)
+       if (User) {
                Client_SetUser(client, User, Idented);
                Client_SetUser(client, User, Idented);
+               Client_SetOrigUser(client, User);
+       }
        if (Hostname)
                Client_SetHostname(client, Hostname);
        if (Info)
        if (Hostname)
                Client_SetHostname(client, Hostname);
        if (Info)
@@ -352,6 +354,25 @@ Client_SetUser( CLIENT *Client, const char *User, bool Idented )
 } /* Client_SetUser */
 
 
 } /* 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 )
 {
 GLOBAL void
 Client_SetInfo( CLIENT *Client, const char *Info )
 {
@@ -601,6 +622,31 @@ Client_User( CLIENT *Client )
 } /* Client_User */
 
 
 } /* 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 )
 {
 GLOBAL char *
 Client_Hostname( CLIENT *Client )
 {
index 90fd6f286832a3d2faf67bc22b15b58b42d35b58..352ddf3898550b28f19baeca77558f8bd808f3c4 100644 (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") */
        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) */
        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 ));
 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 ));
 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_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 ));
 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 ));
index 5a52d3cb68a9955079e75d4053f50ca61841ef19..906b669ba3f748210fe9849db1e2ca4ed5cba46e 100644 (file)
@@ -401,6 +401,7 @@ IRC_USER(CLIENT * Client, REQUEST * Req)
 #else
                Client_SetUser(Client, Req->argv[0], false);
 #endif
 #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"
 
                /* "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);
                                                  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]);
 
                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_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 */
        Client_SetHostname(Client, Req->argv[2]);
        return CONNECTED;
 } /* IRC_WEBIRC */