From 23e519fc08b489400c88090f1500b1f6a5460aff Mon Sep 17 00:00:00 2001
From: Maxime Bizon <mbizon@freebox.fr>
Date: Thu, 16 Jan 2020 01:00:44 +0100
Subject: [PATCH 03/12] pppd: add notifier when peer auth status change

also move auth_pending/auth_done macros into public header
---
 pppd/auth.c         |  5 +++++
 pppd/main.c         |  1 +
 pppd/pppd-private.h | 18 +-----------------
 pppd/pppd.h         | 18 ++++++++++++++++++
 4 files changed, 25 insertions(+), 17 deletions(-)

diff --git a/pppd/auth.c b/pppd/auth.c
index a78a697..c8d1428 100644
--- a/pppd/auth.c
+++ b/pppd/auth.c
@@ -209,6 +209,9 @@ int (*allowed_address_hook)(u_int32_t addr) = NULL;
    and we are proceeding to the network phase. */
 struct notifier *auth_up_notifier = NULL;
 
+/* A notifier after auth with peer change status */
+struct notifier *auth_with_peer_notifier = NULL;
+
 /* A notifier for when the link goes down. */
 struct notifier *link_down_notifier = NULL;
 
@@ -1107,6 +1110,7 @@ auth_withpeer_fail(int unit, int protocol)
      * authentication secrets.
      */
     ppp_set_status(EXIT_AUTH_TOPEER_FAILED);
+    notify(auth_with_peer_notifier, 0);
     lcp_close(unit, "Failed to authenticate ourselves to peer");
 }
 
@@ -1152,6 +1156,7 @@ auth_withpeer_success(int unit, int protocol, int prot_flavor)
 	bit = 0;
     }
 
+    notify(auth_with_peer_notifier, bit);
     notice("%s authentication succeeded", prot);
 
     /* Save the authentication method for later. */
diff --git a/pppd/main.c b/pppd/main.c
index 8aec5cb..e3e7b87 100644
--- a/pppd/main.c
+++ b/pppd/main.c
@@ -2098,6 +2098,7 @@ struct notifier **get_notifier_by_type(ppp_notify_t type)
         [NF_LINK_DOWN   ] = &link_down_notifier,
         [NF_FORK        ] = &fork_notifier,
         [NF_FIRST_LCP   ] = &first_lcp_notifier,
+        [NF_AUTH_WITH_PEER] = &auth_with_peer_notifier,
     };
     return list[type];
 }
diff --git a/pppd/pppd-private.h b/pppd/pppd-private.h
index 66dd15e..796a0a3 100644
--- a/pppd/pppd-private.h
+++ b/pppd/pppd-private.h
@@ -139,6 +139,7 @@ extern struct notifier *auth_up_notifier; /* peer has authenticated */
 extern struct notifier *link_down_notifier; /* link has gone down */
 extern struct notifier *fork_notifier;	/* we are a new child process */
 extern struct notifier *first_lcp_notifier; /* first LCP packet received */
+extern struct notifier *auth_with_peer_notifier; /* we have authenticated  */
 
 
 /* Values for do_callback and doing_callback */
@@ -263,23 +264,6 @@ extern bool	ms_lanman;	/* Use LanMan password instead of NT */
 				/* Has meaning only with MS-CHAP challenges */
 #endif
 
-/* Values for auth_pending, auth_done */
-#define PAP_WITHPEER	0x1
-#define PAP_PEER	0x2
-#define CHAP_WITHPEER	0x4
-#define CHAP_PEER	0x8
-#define EAP_WITHPEER	0x10
-#define EAP_PEER	0x20
-
-/* Values for auth_done only */
-#define CHAP_MD5_WITHPEER	0x40
-#define CHAP_MD5_PEER		0x80
-#define CHAP_MS_SHIFT		8	/* LSB position for MS auths */
-#define CHAP_MS_WITHPEER	0x100
-#define CHAP_MS_PEER		0x200
-#define CHAP_MS2_WITHPEER	0x400
-#define CHAP_MS2_PEER		0x800
-
 
 /*
  * This structure contains environment variables that are set or unset
diff --git a/pppd/pppd.h b/pppd/pppd.h
index bd9736d..62bb14a 100644
--- a/pppd/pppd.h
+++ b/pppd/pppd.h
@@ -64,6 +64,23 @@ extern "C" {
 #define MAXNAMELEN	256	/* max length of hostname or name for auth */
 #define MAXSECRETLEN	256	/* max length of password or secret */
 
+/* Values for auth_pending, auth_done */
+#define PAP_WITHPEER	0x1
+#define PAP_PEER	0x2
+#define CHAP_WITHPEER	0x4
+#define CHAP_PEER	0x8
+#define EAP_WITHPEER	0x10
+#define EAP_PEER	0x20
+
+/* Values for auth_done only */
+#define CHAP_MD5_WITHPEER	0x40
+#define CHAP_MD5_PEER		0x80
+#define CHAP_MS_SHIFT		8	/* LSB position for MS auths */
+#define CHAP_MS_WITHPEER	0x100
+#define CHAP_MS_PEER		0x200
+#define CHAP_MS2_WITHPEER	0x400
+#define CHAP_MS2_PEER		0x800
+
 
 /*
  * Values for phase.
@@ -131,6 +148,7 @@ typedef enum
     NF_LINK_DOWN,
     NF_FORK,
     NF_FIRST_LCP,
+    NF_AUTH_WITH_PEER,
     NF_MAX_NOTIFY
 } ppp_notify_t;
 
-- 
2.34.1

