PLUGINS 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. Starting with version 2.3.10, pppd includes support for `plugins' -
  2. pieces of code which can be loaded into pppd at runtime and which can
  3. affect its behaviour in various ways. The idea of plugins is to
  4. provide a way for people to customize the behaviour of pppd without
  5. having to either apply local patches to each version or get their
  6. patches accepted into the standard distribution.
  7. A plugin is a standard shared library object, typically with a name
  8. ending in .so. They are loaded using the standard dlopen() library
  9. call, so plugins are only supported on systems which support shared
  10. libraries and the dlopen call. At present pppd is compiled with
  11. plugin support only under Linux and Solaris.
  12. Plugins are loaded into pppd using the `plugin' option, which takes
  13. one argument, the name of a shared object file. The plugin option is
  14. a privileged option. If the name given does not contain a slash, pppd
  15. will look in the /usr/lib/pppd/<version> directory for the file, where
  16. <version> is the version number of pppd, for example, 2.4.2. I
  17. suggest that you either give the full path name of the shared object
  18. file or just the base name; if you don't, it may be possible for
  19. unscrupulous users to substitute another shared object file for the
  20. one you mean to load, e.g. by setting the LD_LIBRARY_PATH variable.
  21. Plugins are usually written in C and compiled and linked to a shared
  22. object file in the appropriate manner for your platform. Using gcc
  23. under Linux, a plugin called `xyz' could be compiled and linked with
  24. the following commands:
  25. gcc -c -O xyz.c
  26. gcc -shared -o xyz.so xyz.o
  27. There are some example plugins in the pppd/plugins directory in the
  28. ppp distribution. Currently there is one example, minconn.c, which
  29. implements a `minconnect' option, which specifies a minimum connect
  30. time before the idle timeout applies.
  31. Plugins can access global variables within pppd, so it is useful for
  32. them to #include "pppd.h" from the pppd source directory.
  33. Every plugin must contain a global procedure called `plugin_init'.
  34. This procedure will get called (with no arguments) immediately after
  35. the plugin is loaded. Every plugin should also contain a variable
  36. called pppd_version declared as follows:
  37. char pppd_version[] = VERSION;
  38. If this declaration is included, pppd will not load the module if its
  39. version number differs from that compiled into the plugin binary.
  40. Plugins can affect the behaviour of pppd in at least four ways:
  41. 1. They can add extra options which pppd will then recognize. This is
  42. done by calling the add_options() procedure with a pointer to an
  43. array of option_t structures. The last entry in the array must
  44. have its name field set to NULL.
  45. 2. Pppd contains `hook' variables which are procedure pointers. If a
  46. given hook is not NULL, pppd will call the procedure it points to
  47. at the appropriate point in its processing. The plugin can set any
  48. of these hooks to point to its own procedures. See below for a
  49. description of the hooks which are currently implemented.
  50. 3. Plugin code can call any global procedures and access any global
  51. variables in pppd.
  52. 4. Plugins can register procedures to be called when particular events
  53. occur, using the `notifier' mechanism in pppd. The differences
  54. between hooks and notifiers are that a hook will only call one
  55. function, whereas a notifier can call an arbitrary number, and that
  56. a hook usually returns some value to pppd, whereas a notifier
  57. function returns nothing.
  58. Here is a list of the currently implemented hooks in pppd.
  59. int (*idle_time_hook)(struct ppp_idle *idlep);
  60. The idle_time_hook is called when the link first comes up (i.e. when
  61. the first network protocol comes up) and at intervals thereafter. On
  62. the first call, the idlep parameter is NULL, and the return value is
  63. the number of seconds before pppd should check the link activity, or 0
  64. if there is to be no idle timeout.
  65. On subsequent calls, idlep points to a structure giving the number of
  66. seconds since the last packets were sent and received. If the return
  67. value is > 0, pppd will wait that many seconds before checking again.
  68. If it is <= 0, that indicates that the link should be terminated due
  69. to lack of activity.
  70. int (*holdoff_hook)(void);
  71. The holdoff_hook is called when an attempt to bring up the link fails,
  72. or the link is terminated, and the persist or demand option was used.
  73. It returns the number of seconds that pppd should wait before trying
  74. to reestablish the link (0 means immediately).
  75. int (*pap_check_hook)(void);
  76. int (*pap_passwd_hook)(char *user, char *passwd);
  77. int (*pap_auth_hook)(char *user, char *passwd, char **msgp,
  78. struct wordlist **paddrs,
  79. struct wordlist **popts);
  80. void (*pap_logout_hook)(void);
  81. These hooks are designed to allow a plugin to replace the normal PAP
  82. password processing in pppd with something different (e.g. contacting
  83. an external server).
  84. The pap_check_hook is called to check whether there is any possibility
  85. that the peer could authenticate itself to us. If it returns 1, pppd
  86. will ask the peer to authenticate itself. If it returns 0, pppd will
  87. not ask the peer to authenticate itself (but if authentication is
  88. required, pppd may exit, or terminate the link before network protocol
  89. negotiation). If it returns -1, pppd will look in the pap-secrets
  90. file as it would normally.
  91. The pap_passwd_hook is called to determine what username and password
  92. pppd should use in authenticating itself to the peer with PAP. The
  93. user string will already be initialized, by the `user' option, the
  94. `name' option, or from the hostname, but can be changed if necessary.
  95. MAXNAMELEN bytes of space are available at *user, and MAXSECRETLEN
  96. bytes of space at *passwd. If this hook returns 0, pppd will use the
  97. values at *user and *passwd; if it returns -1, pppd will look in the
  98. pap-secrets file, or use the value from the +ua or password option, as
  99. it would normally.
  100. The pap_auth_hook is called to determine whether the username and
  101. password supplied by the peer are valid. user and passwd point to
  102. null-terminated strings containing the username and password supplied
  103. by the peer, with non-printable characters converted to a printable
  104. form. The pap_auth_hook function should set msg to a string to be
  105. returned to the peer and return 1 if the username/password was valid
  106. and 0 if not. If the hook returns -1, pppd will look in the
  107. pap-secrets file as usual.
  108. If the username/password was valid, the hook can set *paddrs to point
  109. to a wordlist containing the IP address(es) which the peer is
  110. permitted to use, formatted as in the pap-secrets file. It can also
  111. set *popts to a wordlist containing any extra options for this user
  112. which pppd should apply at this point.
  113. The pap_logout_hook is called when the link is terminated, instead of
  114. pppd's internal `plogout' function. It can be used for accounting
  115. purposes. This hook is deprecated and will be replaced by a notifier.
  116. int (*chap_check_hook)(void);
  117. int (*chap_passwd_hook)(char *user, char *passwd);
  118. int (*chap_verify_hook)(char *name, char *ourname, int id,
  119. struct chap_digest_type *digest,
  120. unsigned char *challenge, unsigned char *response,
  121. char *message, int message_space)
  122. These hooks are designed to allow a plugin to replace the normal CHAP
  123. password processing in pppd with something different (e.g. contacting
  124. an external server).
  125. The chap_check_hook is called to check whether there is any possibility
  126. that the peer could authenticate itself to us. If it returns 1, pppd
  127. will ask the peer to authenticate itself. If it returns 0, pppd will
  128. not ask the peer to authenticate itself (but if authentication is
  129. required, pppd may exit, or terminate the link before network protocol
  130. negotiation). If it returns -1, pppd will look in the chap-secrets
  131. file as it would normally.
  132. The chap_passwd_hook is called to determine what password
  133. pppd should use in authenticating itself to the peer with CHAP. The
  134. user string will already be initialized, by the `user' option, the
  135. `name' option, or from the hostname, but can be changed if necessary.
  136. This hook is called only if pppd is a client, not if it is a server.
  137. MAXSECRETLEN bytes of space are available at *passwd. If this hook
  138. returns 0, pppd will use the value *passwd; if it returns -1, pppd
  139. will fail to authenticate.
  140. The chap_verify_hook is called to determine whether the peer's
  141. response to our CHAP challenge is valid -- it should return 1 if valid
  142. or 0 if not. The parameters are:
  143. * name points to a null-terminated string containing the username
  144. supplied by the peer, or the remote name specified with the
  145. "remotename" option.
  146. * ourname points to a null-terminated string containing the name of
  147. the local machine (the hostname, or the name specified with the
  148. "name" option).
  149. * id is the value of the id field from the challenge.
  150. * digest points to a chap_digest_type struct, which contains an
  151. identifier for the type of digest in use plus function pointers for
  152. functions for dealing with digests of that type.
  153. * challenge points to the challenge as a counted string (length byte
  154. followed by the actual challenge bytes).
  155. * response points to the response as a counted string.
  156. * message points to an area of message_space bytes in which to store
  157. any message that should be returned to the peer.
  158. int (*null_auth_hook)(struct wordlist **paddrs,
  159. struct wordlist **popts);
  160. This hook allows a plugin to determine what the policy should be if
  161. the peer refuses to authenticate when it is requested to. If the
  162. return value is 0, the link will be terminated; if it is 1, the
  163. connection is allowed to proceed, and in this case *paddrs and *popts
  164. can be set as for pap_auth_hook, to specify what IP addresses are
  165. permitted and any extra options to be applied. If the return value is
  166. -1, pppd will look in the pap-secrets file as usual.
  167. void (*ip_choose_hook)(u_int32_t *addrp);
  168. This hook is called at the beginning of IPCP negotiation. It gives a
  169. plugin the opportunity to set the IP address for the peer; the address
  170. should be stored in *addrp. If nothing is stored in *addrp, pppd will
  171. determine the peer's address in the usual manner.
  172. int (*allowed_address_hook)(u_int32_t addr)
  173. This hook is called to see if a peer is allowed to use the specified
  174. address. If the hook returns 1, the address is accepted. If it returns
  175. 0, the address is rejected. If it returns -1, the address is verified
  176. in the normal away against the appropriate options and secrets files.
  177. void (*snoop_recv_hook)(unsigned char *p, int len)
  178. void (*snoop_send_hook)(unsigned char *p, int len)
  179. These hooks are called whenever pppd receives or sends a packet. The
  180. packet is in p; its length is len. This allows plugins to "snoop in"
  181. on the pppd conversation. The hooks may prove useful in implmenting
  182. L2TP.
  183. void (*multilink_join_hook)();
  184. This is called whenever a new link completes LCP negotiation and joins
  185. the bundle, if we are doing multilink.
  186. A plugin registers itself with a notifier by declaring a procedure of
  187. the form:
  188. void my_notify_proc(void *opaque, int arg);
  189. and then registering the procedure with the appropriate notifier with
  190. a call of the form
  191. add_notifier(&interesting_notifier, my_notify_proc, opaque);
  192. The `opaque' parameter in the add_notifier call will be passed to
  193. my_notify_proc every time it is called. The `arg' parameter to
  194. my_notify_proc depends on the notifier.
  195. A notify procedure can be removed from the list for a notifier with a
  196. call of the form
  197. remove_notifier(&interesting_notifier, my_notify_proc, opaque);
  198. Here is a list of the currently-implemented notifiers in pppd.
  199. * pidchange. This notifier is called in the parent when pppd has
  200. forked and the child is continuing pppd's processing, i.e. when pppd
  201. detaches from its controlling terminal. The argument is the pid of
  202. the child.
  203. * phasechange. This is called when pppd moves from one phase of
  204. operation to another. The argument is the new phase number.
  205. * exitnotify. This is called just before pppd exits. The argument is
  206. the status with which pppd will exit (i.e. the argument to exit()).
  207. * sigreceived. This is called when a signal is received, from within
  208. the signal handler. The argument is the signal number.
  209. * ip_up_notifier. This is called when IPCP has come up.
  210. * ip_down_notifier. This is called when IPCP goes down.
  211. * auth_up_notifier. This is called when the peer has successfully
  212. authenticated itself.
  213. * link_down_notifier. This is called when the link goes down.
  214. ## $Id: PLUGINS,v 1.8 2008/06/15 07:02:18 paulus Exp $ ##