From:           	"Seth Chaiklin" <seth@psy.au.dk>
Organization:   	Dept. of Psychology, University of Aarhus
To:             	<valja@TARTU.CUSTOMS.EE>
Date sent:      	Mon, 16 Nov 1998 17:52:07 MEST
Subject:        	(Fwd) Re: UID in pppd (resolved)
Priority:       	normal

Here is the message that mentioned with the patch.

By the way, Paul Mackerras was wrong in his analysis.  bash
was never used.  But the problem was arising from the /bin/login
(from util-linux).  Anyway, here it is.


------- Forwarded Message Follows -------
From:           	Self <PSY/SETH>
To:             	Paul Mackerras <paulus@cs.anu.edu.au>
Subject:        	Re: UID in pppd (resolved)
Copies to:      	longyear@pobox.com
Date sent:      	Fri, 13 Nov 1998 17:14:58 MEST

On 11 Nov 98, at 9:32, Paul Mackerras wrote:

  |> My question.  I can see in the log files that the name and uid
  |> of the user in the first case are available to ppp.  They appear 
  |> in the syslog entry:  ppp 2.3.5 started by [username], uid [uid] 
  |> So why is the UID 0 in that case in my ip-up script? 
  | 
  |Because bash (at least, and probably other shells) sets the UID 
  |environment variable itself, overwriting the value that pppd set. If you 
  |change the pppd source so it sets ORIG_UID instead of UID (look for the 
  |calls to script_setenv in pppd/main.c), you will get the ORIG_UID 
  |environment variable set correctly for your script. 
  |
Dear Paul,

Ok, I have now succeeded in  testing the changes, and this message is just
to report the positive results and send the patch that was used (it is at
the end of  this message.).  And that should be it from me.  

Thanks, 

Seth Chaiklin

----- Results of test changes to pppd/main.c for environmental variables ------

Maybe you noticed that the example that I sent before had SPEED with a
value of 0.  This was happening because the value is set before the tty
was being set, so that the correct value could be obtained.  So I figured
that as long as I was playing with the environment variables, I might as
well get that one to work right.

So I simply moved that line to a place after the tty is set. I suspect
this is a general problem with pppd, not Linux specific.

I also added PPPUSER, to get the username.   In principle, at least 
according to the login(1) page, LOGNAME is supposed to be set by login,
but that is empirically false.  So I am suggesting that PPPUSER be added
as an environment variable to pppd.  That way, one can test for PEERNAME
and if that is null, then use PPPUSER (in ip-up).  It is more useful to
run a script from ip-up, because auth-up only comes up if  there is a
peername (as you already know).

Here was the output with ppp-2.3.5 before the changes:


PEERNAME:
UID: 0
SPEED: 0
DEVICE: /dev/ttyC0

PEERNAME: mikael
UID: 0
SPEED: 0
DEVICE: /dev/ttyC0 

And here is the output after the patches.  The things to notice are:

(a) PPPUID shows uid for who started pppd
(b) when no PEERNAME (because not AutoPPP, but called from login), then
PPPUSER is set with the username. (c) UID is still always 0, as you
explained. (d) LOGNAME is never set (which is strange, because it is set
on a "normal" login (and not set in an profile scripts) (e)  SPEED has the
"right" value.

PEERNAME: mikael
PPPUSER: ppp
LOGNAME:
UID: 0
PPPUID: 15
SPEED: 115200
DEVICE: /dev/ttyC0

PEERNAME: volker
PPPUSER: ppp
LOGNAME:
UID: 0
PPPUID: 15
SPEED: 115200
DEVICE: /dev/ttyC2

PEERNAME:
PPPUSER: erlavil
LOGNAME:      
UID: 0
PPPUID: 523
SPEED: 115200
DEVICE: /dev/ttyC0

PEERNAME:
PPPUSER: hulda
LOGNAME:
UID: 0
PPPUID: 555
SPEED: 115200
DEVICE: /dev/ttyC0

PEERNAME: tia
PPPUSER: ppp
LOGNAME:
UID: 0
PPPUID: 15
SPEED: 115200
DEVICE: /dev/ttyC1   


---------------------------

It is possible that this patch will fuzzy match, because I had made some
other patches to main.c

--- ppp-2.3.5/pppd/main.c.uid   Thu Nov 12 09:36:27 1998
+++ ppp-2.3.5/pppd/main.c       Fri Nov 13 12:14:57 1998
@@ -199,7 +199,7 @@
     uid = getuid();
     privileged = uid == 0;
     sprintf(numbuf, "%d", uid);
-    script_setenv("UID", numbuf);
+    script_setenv("PPPUID", numbuf);

     /*
      * Initialize to the standard option set, then parse, in order,
@@ -247,8 +247,6 @@
     }

     script_setenv("DEVICE", devnam);
-    sprintf(numbuf, "%d", baud_rate);
-    script_setenv("SPEED", numbuf);

     /*
      * If the user has specified the default device name explicitly, @@
-284,6 +282,7 @@
     }
     }
     syslog(LOG_NOTICE, "pppd %s.%d%s started by %s, uid %d",
           VERSION, PATCHLEVEL, IMPLEMENTATION, p, uid);
+    script_setenv("PPPUSER", p);

     /*
      * Compute mask of all interesting signals and install signal
      handlers
@@ -498,6 +497,9 @@
            }
            close(i);
        }
+
+       sprintf(numbuf, "%d", baud_rate);
+       script_setenv("SPEED", numbuf);

        /* run welcome script, if any */
        if (welcomer && welcomer[0]) {                     

--
seth@psy.au.dk
seth@schutz.psy.aau.dk
psykseth@aau.dk

------------------------------------------------------------------

From:                   "Seth Chaiklin" <seth@psy.au.dk>
Organization:   	Dept. of Psychology, University of Aarhus
To:             	<valja@TARTU.CUSTOMS.EE>
Date sent:      	Fri, 20 Nov 1998 20:41:25 MEST
Subject:        	Re: (Fwd) Re: UID in pppd (resolved)
Priority:       	normal

  
Here are some fragments from my /etc/ppp/ip-up

I wanted to be able to have a simple way to see who was
using PPP.  There was no problem with PEERNAME.  But
that is only set when AutoPPP (with mgetty) is used.

The other people login in manually (and then have pppd as
their shell).  According to various docs, they should have
USER or LOGNAME set, but it was not being set.
(This was a problem with an interaction between pppd and login,
so I made PPPUSER).  If PEERNAME is not defined, but
use PPPUSER.

if [ -z $PEERNAME ] ; then
echo -e "`date +%T`  $PPPUSER     \t $2   UP"  
>>/home/seth/adm/daily.users
else
echo -e "`date +%T`  $PEERNAME    \t $2   UP"  
>>/home/seth/adm/daily.users
fi

And here is what I did to test the values of the variables
but you know this already.  If  you use $4 (is that the one for speed, then
it comes out right, but what happens if you use $SPEED (description
in the man page).

echo PEERNAME: $PEERNAME >> /tmp/findit
echo PPPUSER: $PPPUSER >> /tmp/findit
echo LOGNAME: $LOGNAME >> /tmp/findit
echo UID: $UID >> /tmp/findit
echo PPPUID: $PPPUID >> /tmp/findit
echo SPEED: $SPEED >> /tmp/findit     
echo -e "DEVICE: $DEVICE\n" >> /tmp/findit
 
Like i mentioned, these things are interesting only if you want to run
scripts based on these values...

No performance implications.

Cheers,
  Seth

--
seth@psy.au.dk
seth@schutz.psy.aau.dk
psykseth@aau.dk

