]> git.ozlabs.org Git - ppp.git/blobdiff - pppd/auth.c
Use systemd's sd_notify with option up_sdnotify
[ppp.git] / pppd / auth.c
index f615fd3ac11f94fc46a13b4008fa3f77ab694c08..7457eda227bf19c2d09b79dd4e0b031da6bc1bf9 100644 (file)
@@ -68,7 +68,7 @@
  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
-#define RCSID  "$Id: auth.c,v 1.116 2008/06/25 10:30:36 paulus Exp $"
+#define RCSID  "$Id: auth.c,v 1.117 2008/07/01 12:27:56 paulus Exp $"
 
 #include <stdio.h>
 #include <stddef.h>
 #endif
 #include <time.h>
 
+#ifdef SYSTEMD
+#include <systemd/sd-daemon.h>
+#endif
+
 #include "pppd.h"
 #include "fsm.h"
 #include "lcp.h"
@@ -553,12 +557,11 @@ link_required(unit)
 void start_link(unit)
     int unit;
 {
-    char *msg;
-
+    status = EXIT_CONNECT_FAILED;
     new_phase(PHASE_SERIALCONN);
 
+    hungup = 0;
     devfd = the_channel->connect();
-    msg = "Connect script failed";
     if (devfd < 0)
        goto fail;
 
@@ -571,7 +574,6 @@ void start_link(unit)
      * gives us.  Thus we don't need the tdb_writelock/tdb_writeunlock.
      */
     fd_ppp = the_channel->establish_ppp(devfd);
-    msg = "ppp establishment failed";
     if (fd_ppp < 0) {
        status = EXIT_FATAL_ERROR;
        goto disconnect;
@@ -668,9 +670,11 @@ link_terminated(unit)
        (*the_channel->cleanup)();
 
     if (doing_multilink && multilink_master) {
-       if (!bundle_terminating)
+       if (!bundle_terminating) {
            new_phase(PHASE_MASTER);
-       else
+           if (master_detach && !detached)
+               detach();
+       } else
            mp_bundle_terminated();
     } else
        new_phase(PHASE_DEAD);
@@ -1099,8 +1103,15 @@ np_up(unit, proto)
        /*
         * Detach now, if the updetach option was given.
         */
-       if (updetach && !nodetach)
+       if (updetach && !nodetach) {
+           dbglog("updetach is set. Now detaching.");
            detach();
+#ifdef SYSTEMD
+       } else if (nodetach && up_sdnotify) {
+           dbglog("up_sdnotify is set. Now notifying systemd: READY=1");
+           sd_notify(0, "READY=1");
+#endif
+       }
     }
     ++num_np_up;
 }
@@ -1441,9 +1452,11 @@ check_passwd(unit, auser, userlen, apasswd, passwdlen, msg)
            }
            if (secret[0] != 0 && !login_secret) {
                /* password given in pap-secrets - must match */
-               if ((cryptpap || strcmp(passwd, secret) != 0)
-                   && strcmp(crypt(passwd, secret), secret) != 0)
-                   ret = UPAP_AUTHNAK;
+               if (cryptpap || strcmp(passwd, secret) != 0) {
+                   char *cbuf = crypt(passwd, secret);
+                   if (!cbuf || strcmp(cbuf, secret) != 0)
+                       ret = UPAP_AUTHNAK;
+               }
            }
        }
        fclose(f);