match_port 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. diff -ruNp tcp_wrappers_7.6.orig/hosts_access.c tcp_wrappers_7.6/hosts_access.c
  2. --- tcp_wrappers_7.6.orig/hosts_access.c 2007-01-08 01:31:32.000000000 +0100
  3. +++ tcp_wrappers_7.6/hosts_access.c 2007-01-08 01:31:08.000000000 +0100
  4. @@ -232,6 +232,36 @@ int (*match_fn) ();
  5. return (NO);
  6. }
  7. +/*
  8. + * daemon_or_port_match - match server information: if the server endpoint
  9. + * pattern is a port number, match against port number of connection;
  10. + * otherwise match against daemon executable name
  11. + */
  12. +
  13. +static int daemon_or_port_match(char *tok, struct request_info *request) {
  14. + unsigned int port, sin_port;
  15. + char junk;
  16. +
  17. + /* daemon name */
  18. + if (sscanf(tok, "%u%c", &port, &junk) != 1 || port > 65535)
  19. + return (string_match(tok, eval_daemon(request)));
  20. +
  21. + /* port number */
  22. + if (!request->server->sin)
  23. + return (NO);
  24. +
  25. +#ifdef INET6
  26. + sin_port = ntohs(((struct sockaddr_in *)request->server->sin)->sin_port);
  27. +#else
  28. + sin_port = ntohs(request->server->sin->sin_port);
  29. +#endif
  30. +
  31. + if (port == sin_port)
  32. + return (YES);
  33. + else
  34. + return (NO);
  35. +}
  36. +
  37. /* server_match - match server information */
  38. static int server_match(tok, request)
  39. @@ -241,9 +271,9 @@ struct request_info *request;
  40. char *host;
  41. if ((host = split_at(tok + 1, '@')) == 0) { /* plain daemon */
  42. - return (string_match(tok, eval_daemon(request)));
  43. + return (daemon_or_port_match(tok, request));
  44. } else { /* daemon@host */
  45. - return (string_match(tok, eval_daemon(request))
  46. + return (daemon_or_port_match(tok, request)
  47. && host_match(host, request->server));
  48. }
  49. }
  50. diff -ruNp tcp_wrappers_7.6.orig/hosts_access.5 tcp_wrappers_7.6/hosts_access.5
  51. --- tcp_wrappers_7.6.orig/hosts_access.5 2007-01-08 01:31:32.000000000 +0100
  52. +++ tcp_wrappers_7.6/hosts_access.5 2007-01-08 01:30:18.000000000 +0100
  53. @@ -51,7 +51,7 @@ being optional:
  54. daemon_list : client_list [ : shell_command ]
  55. .PP
  56. \fIdaemon_list\fR is a list of one or more daemon process names
  57. -(argv[0] values) or wildcards (see below).
  58. +(argv[0] values) or server port numbers or wildcards (see below).
  59. .PP
  60. \fIclient_list\fR is a list
  61. of one or more host names, host addresses, patterns or wildcards (see