0007-Run-etc-ppp-auth-fail-script-if-exists-and-authentic.patch 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. From 27ac7224d354abba7b726519af0b552917002f4a Mon Sep 17 00:00:00 2001
  2. From: Mike Frysinger <vapier@gentoo.org>
  3. Date: Tue, 5 Jan 2021 11:56:33 +0100
  4. Subject: [PATCH 07/14] Run etc/ppp/auth-fail script if exists and
  5. authentication failed
  6. ---
  7. pppd/auth.c | 21 ++++++++++++++-------
  8. pppd/pathnames.h | 1 +
  9. pppd/pppd.8 | 14 ++++++++++++--
  10. 3 files changed, 27 insertions(+), 9 deletions(-)
  11. diff --git a/pppd/auth.c b/pppd/auth.c
  12. index a1a831e..00b885e 100644
  13. --- a/pppd/auth.c
  14. +++ b/pppd/auth.c
  15. @@ -294,7 +294,7 @@ static int scan_authfile(FILE *, char *, char *, char *,
  16. struct wordlist **, struct wordlist **,
  17. char *, int);
  18. static void free_wordlist (struct wordlist *);
  19. -static void auth_script (char *);
  20. +static void auth_script (char *, int);
  21. static void auth_script_done (void *);
  22. static void set_allowed_addrs (int, struct wordlist *, struct wordlist *);
  23. static int some_ip_ok (struct wordlist *);
  24. @@ -732,7 +732,7 @@ link_down(int unit)
  25. if (auth_script_state == s_up && auth_script_pid == 0) {
  26. update_link_stats(unit);
  27. auth_script_state = s_down;
  28. - auth_script(_PATH_AUTHDOWN);
  29. + auth_script(_PATH_AUTHDOWN, 0);
  30. }
  31. }
  32. if (!doing_multilink) {
  33. @@ -881,7 +881,7 @@ network_phase(int unit)
  34. auth_state = s_up;
  35. if (auth_script_state == s_down && auth_script_pid == 0) {
  36. auth_script_state = s_up;
  37. - auth_script(_PATH_AUTHUP);
  38. + auth_script(_PATH_AUTHUP, 0);
  39. }
  40. }
  41. @@ -979,6 +979,7 @@ auth_peer_fail(int unit, int protocol)
  42. * Authentication failure: take the link down
  43. */
  44. status = EXIT_PEER_AUTH_FAILED;
  45. + auth_script(_PATH_AUTHFAIL, 1);
  46. lcp_close(unit, "Authentication failed");
  47. }
  48. @@ -1054,6 +1055,7 @@ auth_withpeer_fail(int unit, int protocol)
  49. * authentication secrets.
  50. */
  51. status = EXIT_AUTH_TOPEER_FAILED;
  52. + auth_script(_PATH_AUTHFAIL, 1);
  53. lcp_close(unit, "Failed to authenticate ourselves to peer");
  54. }
  55. @@ -1286,6 +1288,8 @@ auth_check_options(void)
  56. if (user[0] == 0 && !explicit_user)
  57. strlcpy(user, our_name, sizeof(user));
  58. + script_setenv("LOCALNAME", user, 0);
  59. +
  60. /*
  61. * If we have a default route, require the peer to authenticate
  62. * unless the noauth option was given or the real user is root.
  63. @@ -2345,13 +2349,13 @@ auth_script_done(void *arg)
  64. case s_up:
  65. if (auth_state == s_down) {
  66. auth_script_state = s_down;
  67. - auth_script(_PATH_AUTHDOWN);
  68. + auth_script(_PATH_AUTHDOWN, 0);
  69. }
  70. break;
  71. case s_down:
  72. if (auth_state == s_up) {
  73. auth_script_state = s_up;
  74. - auth_script(_PATH_AUTHUP);
  75. + auth_script(_PATH_AUTHUP, 0);
  76. }
  77. break;
  78. }
  79. @@ -2362,7 +2366,7 @@ auth_script_done(void *arg)
  80. * interface-name peer-name real-user tty speed
  81. */
  82. static void
  83. -auth_script(char *script)
  84. +auth_script(char *script, int wait)
  85. {
  86. char strspeed[32];
  87. struct passwd *pw;
  88. @@ -2386,7 +2390,10 @@ auth_script(char *script)
  89. argv[5] = strspeed;
  90. argv[6] = NULL;
  91. - auth_script_pid = run_program(script, argv, 0, auth_script_done, NULL, 0);
  92. + if (wait)
  93. + run_program(script, argv, 0, NULL, NULL, 1);
  94. + else
  95. + auth_script_pid = run_program(script, argv, 0, auth_script_done, NULL, 0);
  96. }
  97. diff --git a/pppd/pathnames.h b/pppd/pathnames.h
  98. index 524d608..7647d49 100644
  99. --- a/pppd/pathnames.h
  100. +++ b/pppd/pathnames.h
  101. @@ -32,6 +32,7 @@
  102. #define _PATH_IPPREUP _ROOT_PATH "/etc/ppp/ip-pre-up"
  103. #define _PATH_AUTHUP _ROOT_PATH "/etc/ppp/auth-up"
  104. #define _PATH_AUTHDOWN _ROOT_PATH "/etc/ppp/auth-down"
  105. +#define _PATH_AUTHFAIL _ROOT_PATH "/etc/ppp/auth-fail"
  106. #define _PATH_TTYOPT _ROOT_PATH "/etc/ppp/options."
  107. #define _PATH_CONNERRS _ROOT_PATH "/etc/ppp/connect-errors"
  108. #define _PATH_PEERFILES _ROOT_PATH "/etc/ppp/peers/"
  109. diff --git a/pppd/pppd.8 b/pppd/pppd.8
  110. index 36156d6..fae91b2 100644
  111. --- a/pppd/pppd.8
  112. +++ b/pppd/pppd.8
  113. @@ -1725,8 +1725,8 @@ We failed to authenticate ourselves to the peer.
  114. Pppd invokes scripts at various stages in its processing which can be
  115. used to perform site-specific ancillary processing. These scripts are
  116. usually shell scripts, but could be executable code files instead.
  117. -Pppd does not wait for the scripts to finish (except for the ip-pre-up
  118. -script). The scripts are
  119. +Pppd does not wait for the scripts to finish (except for the ip-pre-up,
  120. +and auth-fail scripts). The scripts are
  121. executed as root (with the real and effective user-id set to 0), so
  122. that they can do things such as update routing tables or run
  123. privileged daemons. Be careful that the contents of these scripts do
  124. @@ -1754,6 +1754,11 @@ IPCP has come up.
  125. The authenticated name of the peer. This is only set if the peer
  126. authenticates itself.
  127. .TP
  128. +.B LOCALNAME
  129. +The username passed to the user option of the pppd daemon. This is
  130. +handy to identify which account was used for authentication purposes
  131. +when multiple accounts are available.
  132. +.TP
  133. .B SPEED
  134. The baud rate of the tty device.
  135. .TP
  136. @@ -1811,6 +1816,11 @@ A program or script which is executed when the link goes down, if
  137. /etc/ppp/auth\-up was previously executed. It is executed in the same
  138. manner with the same parameters as /etc/ppp/auth\-up.
  139. .TP
  140. +.B /etc/ppp/auth\-fail
  141. +A program or script which is executed should authentication fail. pppd
  142. +waits for this script to finish. It is executed in the same manner, with
  143. +the same parameters as /etc/ppp/auth\-up.
  144. +.TP
  145. .B /etc/ppp/ip\-pre\-up
  146. A program or script which is executed just before the ppp network
  147. interface is brought up. It is executed with the same parameters as
  148. --
  149. 2.30.0