]> git.ozlabs.org Git - ppp.git/blobdiff - pppd/session.c
Add set and reset options to control environment variables for scripts.
[ppp.git] / pppd / session.c
index f9f8fc011b1b27b3098a80cec3364dfa9f2bc910..32901a24546f5913b67cdced816f002de9edc6e3 100644 (file)
@@ -73,7 +73,9 @@
 #include <string.h>
 #include <pwd.h>
 #include <crypt.h>
+#ifdef HAS_SHADOW
 #include <shadow.h>
+#endif
 #include <time.h>
 #include <utmp.h>
 #include <fcntl.h>
@@ -294,9 +296,11 @@ session_start(flags, user, passwd, ttyName, msg)
 #else /* #ifdef USE_PAM */
 
 /*
- * Use the non-PAM methods directly
+ * Use the non-PAM methods directly.  'pw' will remain NULL if the user
+ * has not been authenticated using local UNIX system services.
  */
 
+    pw = NULL;
     if ((SESS_AUTH & flags)) {
        pw = getpwnam(user);
 
@@ -362,14 +366,21 @@ session_start(flags, user, passwd, ttyName, msg)
        logged_in = 1;
 
 #if defined(_PATH_LASTLOG) && !defined(USE_PAM)
-       {
+       /*
+        * Enter the user in lastlog only if he has been authenticated using
+        * local system services.  If he has not, then we don't know what his
+        * UID might be, and lastlog is indexed by UID.
+        */
+       if (pw != NULL) {
             struct lastlog ll;
             int fd;
+           time_t tnow;
 
             if ((fd = open(_PATH_LASTLOG, O_RDWR, 0)) >= 0) {
                 (void)lseek(fd, (off_t)(pw->pw_uid * sizeof(ll)), SEEK_SET);
                 memset((void *)&ll, 0, sizeof(ll));
-                (void)time(&ll.ll_time);
+               (void)time(&tnow);
+                ll.ll_time = tnow;
                 (void)strncpy(ll.ll_line, ttyName, sizeof(ll.ll_line));
                 (void)strncpy(ll.ll_host, ifname, sizeof(ll.ll_host));
                 (void)write(fd, (char *)&ll, sizeof(ll));