13_shlib_weaksym 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. --- a/Makefile
  2. +++ b/Makefile
  3. @@ -150,15 +150,15 @@ netbsd:
  4. linux:
  5. @make REAL_DAEMON_DIR=$(REAL_DAEMON_DIR) STYLE=$(STYLE) \
  6. - LIBS=-lnsl RANLIB=ranlib ARFLAGS=rv AUX_OBJ= \
  7. + LIBS=-lnsl RANLIB=ranlib ARFLAGS=rv AUX_OBJ=weak_symbols.o \
  8. NETGROUP="-DNETGROUP" TLI= VSYSLOG= BUGS= \
  9. - EXTRA_CFLAGS="-DSYS_ERRLIST_DEFINED -DHAVE_STRERROR -DINET6=1 -Dss_family=__ss_family -Dss_len=__ss_len" all
  10. + EXTRA_CFLAGS="-DSYS_ERRLIST_DEFINED -DHAVE_STRERROR -DHAVE_WEAKSYMS -DINET6=1 -Dss_family=__ss_family -Dss_len=__ss_len" all
  11. gnu:
  12. @make REAL_DAEMON_DIR=$(REAL_DAEMON_DIR) STYLE=$(STYLE) \
  13. - LIBS=-lnsl RANLIB=ranlib ARFLAGS=rv AUX_OBJ= \
  14. + LIBS=-lnsl RANLIB=ranlib ARFLAGS=rv AUX_OBJ=weak_symbols.o \
  15. NETGROUP=-DNETGROUP TLI= VSYSLOG= BUGS= \
  16. - EXTRA_CFLAGS="-DSYS_ERRLIST_DEFINED -DHAVE_STRERROR -DINET6=1" all
  17. + EXTRA_CFLAGS="-DSYS_ERRLIST_DEFINED -DHAVE_STRERROR -DINET6=1 -DHAVE_WEAKSYMS -D_REENTRANT" all
  18. # This is good for many SYSV+BSD hybrids with NIS, probably also for HP-UX 7.x.
  19. hpux hpux8 hpux9 hpux10:
  20. @@ -692,6 +692,7 @@ CFLAGS = $(COPTS) -DFACILITY=$(FACILITY)
  21. -DSEVERITY=$(SEVERITY) -DRFC931_TIMEOUT=$(RFC931_TIMEOUT) \
  22. $(UCHAR) $(TABLES) $(STRINGS) $(TLI) $(EXTRA_CFLAGS) $(DOT) \
  23. $(VSYSLOG) $(HOSTNAME)
  24. +LDFLAGS = $(LDOPTS)
  25. LIB_OBJ= hosts_access.o options.o shell_cmd.o rfc931.o eval.o \
  26. hosts_ctl.o refuse.o percent_x.o clean_exit.o $(AUX_OBJ) \
  27. @@ -713,7 +714,22 @@ KIT = README miscd.c tcpd.c fromhost.c h
  28. LIB = libwrap.a
  29. -all other: config-check tcpd tcpdmatch try-from safe_finger tcpdchk
  30. +shared/%.o: %.c
  31. + $(CC) $(CFLAGS) $(SHCFLAGS) -c $< -o $@
  32. +
  33. +SOMAJOR = 0
  34. +SOMINOR = 7.6
  35. +
  36. +SHLIB = shared/libwrap.so.$(SOMAJOR).$(SOMINOR)
  37. +SHLIBSOMAJ = shared/libwrap.so.$(SOMAJOR)
  38. +SHLIBSO = shared/libwrap.so
  39. +SHLIBFLAGS = -Lshared -lwrap
  40. +
  41. +SHLINKFLAGS = -Bsymbolic-functions -shared -Wl,-soname=libwrap.so.$(SOMAJOR) -Wl,--version-script=libwrap.lds
  42. +SHCFLAGS = -fpic
  43. +SHLIB_OBJ= $(addprefix shared/, $(LIB_OBJ))
  44. +
  45. +all other: config-check tcpd tcpdmatch try-from safe_finger tcpdchk $(LIB)
  46. # Invalidate all object files when the compiler options (CFLAGS) have changed.
  47. @@ -731,27 +747,33 @@ $(LIB): $(LIB_OBJ)
  48. $(AR) $(ARFLAGS) $(LIB) $(LIB_OBJ)
  49. -$(RANLIB) $(LIB)
  50. -tcpd: tcpd.o $(LIB)
  51. - $(CC) $(CFLAGS) -o $@ tcpd.o $(LIB) $(LIBS)
  52. +$(SHLIB): libwrap.lds $(SHLIB_OBJ)
  53. + rm -f $(SHLIB)
  54. + $(CC) $(CFLAGS) $(LDFLAGS) -o $(SHLIB) $(SHLINKFLAGS) $(SHLIB_OBJ) $(LIBS)
  55. + ln -sf $(notdir $(SHLIB)) $(SHLIBSOMAJ)
  56. + ln -sf $(notdir $(SHLIBSOMAJ)) $(SHLIBSO)
  57. +
  58. +tcpd: tcpd.o $(SHLIB)
  59. + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ tcpd.o $(SHLIBFLAGS)
  60. miscd: miscd.o $(LIB)
  61. - $(CC) $(CFLAGS) -o $@ miscd.o $(LIB) $(LIBS)
  62. + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ miscd.o $(LIB) $(LIBS)
  63. -safe_finger: safe_finger.o $(LIB)
  64. - $(CC) $(CFLAGS) -o $@ safe_finger.o $(LIB) $(LIBS)
  65. +safe_finger: safe_finger.o
  66. + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ safe_finger.o
  67. TCPDMATCH_OBJ = tcpdmatch.o fakelog.o inetcf.o scaffold.o
  68. -tcpdmatch: $(TCPDMATCH_OBJ) $(LIB)
  69. - $(CC) $(CFLAGS) -o $@ $(TCPDMATCH_OBJ) $(LIB) $(LIBS)
  70. +tcpdmatch: $(TCPDMATCH_OBJ) $(SHLIB)
  71. + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(TCPDMATCH_OBJ) $(SHLIBFLAGS)
  72. -try-from: try-from.o fakelog.o $(LIB)
  73. - $(CC) $(CFLAGS) -o $@ try-from.o fakelog.o $(LIB) $(LIBS)
  74. +try-from: try-from.o fakelog.o $(SHLIB)
  75. + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ try-from.o fakelog.o $(SHLIBFLAGS)
  76. TCPDCHK_OBJ = tcpdchk.o fakelog.o inetcf.o scaffold.o
  77. -tcpdchk: $(TCPDCHK_OBJ) $(LIB)
  78. - $(CC) $(CFLAGS) -o $@ $(TCPDCHK_OBJ) $(LIB) $(LIBS)
  79. +tcpdchk: $(TCPDCHK_OBJ) $(SHLIB)
  80. + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(TCPDCHK_OBJ) $(SHLIBFLAGS)
  81. shar: $(KIT)
  82. @shar $(KIT)
  83. @@ -767,7 +789,9 @@ archive:
  84. clean:
  85. rm -f tcpd miscd safe_finger tcpdmatch tcpdchk try-from *.[oa] core \
  86. + libwrap*.so* \
  87. cflags
  88. + rm -rf shared/
  89. tidy: clean
  90. chmod -R a+r .
  91. @@ -913,5 +937,6 @@ update.o: cflags
  92. update.o: mystdarg.h
  93. update.o: tcpd.h
  94. vfprintf.o: cflags
  95. +weak_symbols.o: tcpd.h
  96. workarounds.o: cflags
  97. workarounds.o: tcpd.h
  98. --- a/tcpd.h
  99. +++ b/tcpd.h
  100. @@ -4,6 +4,15 @@
  101. * Author: Wietse Venema, Eindhoven University of Technology, The Netherlands.
  102. */
  103. +#ifndef _TCPWRAPPERS_TCPD_H
  104. +#define _TCPWRAPPERS_TCPD_H
  105. +
  106. +/* Need definitions of struct sockaddr_in and FILE. */
  107. +#include <netinet/in.h>
  108. +#include <stdio.h>
  109. +
  110. +__BEGIN_DECLS
  111. +
  112. /* Structure to describe one communications endpoint. */
  113. #define STRING_LENGTH 128 /* hosts, users, processes */
  114. @@ -29,10 +38,10 @@ struct request_info {
  115. char pid[10]; /* access via eval_pid(request) */
  116. struct host_info client[1]; /* client endpoint info */
  117. struct host_info server[1]; /* server endpoint info */
  118. - void (*sink) (); /* datagram sink function or 0 */
  119. - void (*hostname) (); /* address to printable hostname */
  120. - void (*hostaddr) (); /* address to printable address */
  121. - void (*cleanup) (); /* cleanup function or 0 */
  122. + void (*sink) (int); /* datagram sink function or 0 */
  123. + void (*hostname) (struct host_info *); /* address to printable hostname */
  124. + void (*hostaddr) (struct host_info *); /* address to printable address */
  125. + void (*cleanup) (struct request_info *); /* cleanup function or 0 */
  126. struct netconfig *config; /* netdir handle */
  127. };
  128. @@ -70,20 +79,27 @@ extern void fromhost(); /* get/validat
  129. #define fromhost sock_host /* no TLI support needed */
  130. #endif
  131. -extern int hosts_access(); /* access control */
  132. -extern void shell_cmd(); /* execute shell command */
  133. -extern char *percent_x(); /* do %<char> expansion */
  134. -extern void rfc931(); /* client name from RFC 931 daemon */
  135. -extern void clean_exit(); /* clean up and exit */
  136. -extern void refuse(); /* clean up and exit */
  137. -extern char *xgets(); /* fgets() on steroids */
  138. -extern char *split_at(); /* strchr() and split */
  139. -extern unsigned long dot_quad_addr(); /* restricted inet_addr() */
  140. +extern int hosts_access(struct request_info *request); /* access control */
  141. +extern void shell_cmd(char *); /* execute shell command */
  142. +extern char *percent_x(char *, int, char *, struct request_info *);
  143. + /* do %<char> expansion */
  144. +extern void rfc931(struct sockaddr *, struct sockaddr *, char *);
  145. + /* client name from RFC 931 daemon */
  146. +extern void clean_exit(struct request_info *); /* clean up and exit */
  147. +extern void refuse(struct request_info *); /* clean up and exit */
  148. +extern char *xgets(char *, int, FILE *); /* fgets() on steroids */
  149. +extern char *split_at(char *, int); /* strchr() and split */
  150. +extern unsigned long dot_quad_addr(char *); /* restricted inet_addr() */
  151. /* Global variables. */
  152. +#ifdef HAVE_WEAKSYMS
  153. +extern int allow_severity __attribute__ ((weak)); /* for connection logging */
  154. +extern int deny_severity __attribute__ ((weak)); /* for connection logging */
  155. +#else
  156. extern int allow_severity; /* for connection logging */
  157. extern int deny_severity; /* for connection logging */
  158. +#endif
  159. extern char *hosts_allow_table; /* for verification mode redirection */
  160. extern char *hosts_deny_table; /* for verification mode redirection */
  161. extern int hosts_access_verbose; /* for verbose matching mode */
  162. @@ -98,6 +114,8 @@ extern int resident; /* > 0 if residen
  163. #ifdef __STDC__
  164. extern struct request_info *request_init(struct request_info *,...);
  165. extern struct request_info *request_set(struct request_info *,...);
  166. +extern int hosts_ctl(char *daemon, char *client_name, char *client_addr,
  167. + char *client_user);
  168. #else
  169. extern struct request_info *request_init(); /* initialize request */
  170. extern struct request_info *request_set(); /* update request structure */
  171. @@ -121,20 +139,23 @@ extern struct request_info *request_set(
  172. * host_info structures serve as caches for the lookup results.
  173. */
  174. -extern char *eval_user(); /* client user */
  175. -extern char *eval_hostname(); /* printable hostname */
  176. -extern char *eval_hostaddr(); /* printable host address */
  177. -extern char *eval_hostinfo(); /* host name or address */
  178. -extern char *eval_client(); /* whatever is available */
  179. -extern char *eval_server(); /* whatever is available */
  180. +extern char *eval_user(struct request_info *); /* client user */
  181. +extern char *eval_hostname(struct host_info *); /* printable hostname */
  182. +extern char *eval_hostaddr(struct host_info *); /* printable host address */
  183. +extern char *eval_hostinfo(struct host_info *); /* host name or address */
  184. +extern char *eval_client(struct request_info *);/* whatever is available */
  185. +extern char *eval_server(struct request_info *);/* whatever is available */
  186. #define eval_daemon(r) ((r)->daemon) /* daemon process name */
  187. #define eval_pid(r) ((r)->pid) /* process id */
  188. /* Socket-specific methods, including DNS hostname lookups. */
  189. -extern void sock_host(); /* look up endpoint addresses */
  190. -extern void sock_hostname(); /* translate address to hostname */
  191. -extern void sock_hostaddr(); /* address to printable address */
  192. +/* look up endpoint addresses */
  193. +extern void sock_host(struct request_info *);
  194. +/* translate address to hostname */
  195. +extern void sock_hostname(struct host_info *);
  196. +/* address to printable address */
  197. +extern void sock_hostaddr(struct host_info *);
  198. #define sock_methods(r) \
  199. { (r)->hostname = sock_hostname; (r)->hostaddr = sock_hostaddr; }
  200. @@ -182,7 +203,7 @@ extern struct tcpd_context tcpd_context;
  201. * behavior.
  202. */
  203. -extern void process_options(); /* execute options */
  204. +extern void process_options(char *, struct request_info *);/* execute options */
  205. extern int dry_run; /* verification flag */
  206. /* Bug workarounds. */
  207. @@ -221,3 +242,7 @@ extern char *fix_strtok();
  208. #define strtok my_strtok
  209. extern char *my_strtok();
  210. #endif
  211. +
  212. +__END_DECLS
  213. +
  214. +#endif
  215. --- /dev/null
  216. +++ b/weak_symbols.c
  217. @@ -0,0 +1,10 @@
  218. + /*
  219. + * Author: Anthony Towns <ajt@debian.org>
  220. + */
  221. +
  222. +#ifdef HAVE_WEAKSYMS
  223. +#include "tcpd.h"
  224. +#include <syslog.h>
  225. +int deny_severity = LOG_WARNING;
  226. +int allow_severity = SEVERITY;
  227. +#endif
  228. --- /dev/null
  229. +++ b/libwrap.lds
  230. @@ -0,0 +1,4 @@
  231. +{
  232. + local:
  233. + aclexec_matched;
  234. +};