bug-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Replace history's "<remote>" with client's IP


From: Mark D. Baushke
Subject: Re: Replace history's "<remote>" with client's IP
Date: Tue, 18 Oct 2005 12:23:25 -0700

Marcel Brouillet <address@hidden> writes:

> I run CVS from several machines via :ext: (ssh) protocol with the
> repository on a single server.

Good!

> When run cvs from a remote machine, I get lines in the history like:
> "[...] <remote>/mypath/myfile" and I wish to replace "<remote>" with the
> IP of the client.

Yes.

> I changed the occurence of "<remote>" in main.c to be the (C variable)
> hostname, and checked the effect of this new build of cvs:
>    - on the client: no effect
>    - on the server: "<remote>" is replaced with the server's name
> This is not what I wanted: I want to have it replaced with the client's
> name.

Then you need to either look at the IP address associated with the STDIN
file descriptor, or you need to trust something like the SSH_CLIENT
environment variable that ssh sets for you.

> In main.c it states "Keep track of this separately since the client can
> change HOSTNAME on the server".
> 
> QUESTION: is what I am looking for already implemented (as hinted from
> this comment) ?  what is the best way to implement this ?

Well, I did something like this once for a test version of cvs. My
recollection is that it does not always work. There are no tests for
sanity.sh for this patch. I do not guarentee anything about this patch.
I doubt that it will be put into the canonical version of CVS anytime
soon as it would need changes to sanity.sh and it would need to deal
with missing getpeername or security concerns of using an environment
variable that may be subject to change based on the sshd being used.

> One option I had in mind was to expand $CVS_RSH to export an evironment
> variable which cvs, if set, would use for logging.  Good idea ?  Bad
> idea ?

It might work, but assumes that the user on your client will remember to
do that and not accidentally tell you an untruth.

        -- Mark

The following patch against branch cvs1-11-x-branch from the ccvs module
of CVSROOT=:ext:address@hidden:/cvsroot/cvs ... it may also
work on the feature branch, but I have not done much with it at all in
a long time.

log message:

        * main.c (main): Try to get an IPv4 or IPv6 address to use in
          the CVSROOT/history file instead of <remote>.

Index: main.c
===================================================================
RCS file: /cvsroot/cvs/ccvs/src/main.c,v
retrieving revision 1.172.4.16
diff -u -p -u -p -r1.172.4.16 main.c
--- main.c      2 Sep 2005 19:37:34 -0000       1.172.4.16
+++ main.c      18 Oct 2005 19:08:51 -0000
@@ -24,6 +24,10 @@
 #include <winsock.h>
 #else
 extern int gethostname ();
+#ifdef SERVER_SUPPORT
+#include <sys/socket.h>
+#include <netinet/in.h>
+#endif
 #endif
 
 const char *program_name;
@@ -716,7 +720,62 @@ distribution kit for a complete list of 
           it is worth the trouble.  */
 
        if (server_active)
-           CurDir = xstrdup ("<remote>");
+       {
+#ifdef SERVER_SUPPORT
+           int len, indx, ip;
+           char buf[32]; /* hold at least @[xxx.xxx.xxx.xxx] */
+           union bigsockaddr
+           {
+               struct sockaddr         sa;     /* general version */
+               struct sockaddr_in      sin;    /* INET family */
+           } peer;
+           char *cp;
+
+           CurDir = NULL;
+
+           /* Note: It may not be desirable to trust the SSH_CLIENT
+            * environment variable, but a quick test shows that using
+            * ssh differs from using rsh as to being able to check
+            * the family of the STDIN to get the hostname of the
+            * remote host.
+            */
+           if ((cp = getenv ("SSH_CLIENT")) != NULL)
+           {
+               char *ind;
+
+               strncpy (buf, cp, sizeof buf);
+               buf[sizeof(buf) - 1] = '\0';
+
+               if ((ind = strchr (buf, ' ')) != NULL)
+               {
+                   *ind = '\0';
+                   CurDir = strdup (buf);
+               }
+           }
+#ifdef AF_INET
+           else
+           {
+               len = sizeof peer;
+               if ((getpeername (0, &peer.sa, &len) >= 0))
+               {
+                   if (peer.sa.sa_family == AF_INET)
+                   {
+                       memcpy (&ip, &peer.sin.sin_addr, sizeof ip);
+                       ip = htonl (ip);
+                       if (snprintf (buf, sizeof buf, "%d.%d.%d.%d",
+                                     (ip >> 24) & 0xff,
+                                     (ip >> 16) & 0xff,
+                                     (ip >> 8) & 0xff,
+                                     ip & 0xff) < sizeof buf)
+                           CurDir = strdup(buf);
+                   }
+               }
+           }
+#endif
+           if (CurDir == NULL)
+               CurDir = xstrdup ("<remote>");
+#endif
+       }
        else
        {
            CurDir = xgetwd ();




reply via email to

[Prev in Thread] Current Thread [Next in Thread]