1
0

001-debian_subset.patch 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936
  1. --- a/hosts_access.c
  2. +++ b/hosts_access.c
  3. @@ -240,6 +240,26 @@ struct request_info *request;
  4. }
  5. }
  6. +/* hostfile_match - look up host patterns from file */
  7. +
  8. +static int hostfile_match(path, host)
  9. +char *path;
  10. +struct hosts_info *host;
  11. +{
  12. + char tok[BUFSIZ];
  13. + int match = NO;
  14. + FILE *fp;
  15. +
  16. + if ((fp = fopen(path, "r")) != 0) {
  17. + while (fscanf(fp, "%s", tok) == 1 && !(match = host_match(tok, host)))
  18. + /* void */ ;
  19. + fclose(fp);
  20. + } else if (errno != ENOENT) {
  21. + tcpd_warn("open %s: %m", path);
  22. + }
  23. + return (match);
  24. +}
  25. +
  26. /* host_match - match host name and/or address against pattern */
  27. static int host_match(tok, host)
  28. @@ -267,6 +287,8 @@ struct host_info *host;
  29. tcpd_warn("netgroup support is disabled"); /* not tcpd_jump() */
  30. return (NO);
  31. #endif
  32. + } else if (tok[0] == '/') { /* /file hack */
  33. + return (hostfile_match(tok, host));
  34. } else if (STR_EQ(tok, "KNOWN")) { /* check address and name */
  35. char *name = eval_hostname(host);
  36. return (STR_NE(eval_hostaddr(host), unknown) && HOSTNAME_KNOWN(name));
  37. --- a/tcpd.h
  38. +++ b/tcpd.h
  39. @@ -4,6 +4,25 @@
  40. * Author: Wietse Venema, Eindhoven University of Technology, The Netherlands.
  41. */
  42. +#ifndef _TCPWRAPPERS_TCPD_H
  43. +#define _TCPWRAPPERS_TCPD_H
  44. +
  45. +/* someone else may have defined this */
  46. +#undef __P
  47. +
  48. +/* use prototypes if we have an ANSI C compiler or are using C++ */
  49. +#if defined(__STDC__) || defined(__cplusplus)
  50. +#define __P(args) args
  51. +#else
  52. +#define __P(args) ()
  53. +#endif
  54. +
  55. +/* Need definitions of struct sockaddr_in and FILE. */
  56. +#include <netinet/in.h>
  57. +#include <stdio.h>
  58. +
  59. +__BEGIN_DECLS
  60. +
  61. /* Structure to describe one communications endpoint. */
  62. #define STRING_LENGTH 128 /* hosts, users, processes */
  63. @@ -25,10 +44,10 @@ struct request_info {
  64. char pid[10]; /* access via eval_pid(request) */
  65. struct host_info client[1]; /* client endpoint info */
  66. struct host_info server[1]; /* server endpoint info */
  67. - void (*sink) (); /* datagram sink function or 0 */
  68. - void (*hostname) (); /* address to printable hostname */
  69. - void (*hostaddr) (); /* address to printable address */
  70. - void (*cleanup) (); /* cleanup function or 0 */
  71. + void (*sink) __P((int)); /* datagram sink function or 0 */
  72. + void (*hostname) __P((struct host_info *)); /* address to printable hostname */
  73. + void (*hostaddr) __P((struct host_info *)); /* address to printable address */
  74. + void (*cleanup) __P((struct request_info *)); /* cleanup function or 0 */
  75. struct netconfig *config; /* netdir handle */
  76. };
  77. @@ -61,25 +80,30 @@ extern char paranoid[];
  78. /* Global functions. */
  79. #if defined(TLI) || defined(PTX) || defined(TLI_SEQUENT)
  80. -extern void fromhost(); /* get/validate client host info */
  81. +extern void fromhost __P((struct request_info *)); /* get/validate client host info */
  82. #else
  83. #define fromhost sock_host /* no TLI support needed */
  84. #endif
  85. -extern int hosts_access(); /* access control */
  86. -extern void shell_cmd(); /* execute shell command */
  87. -extern char *percent_x(); /* do %<char> expansion */
  88. -extern void rfc931(); /* client name from RFC 931 daemon */
  89. -extern void clean_exit(); /* clean up and exit */
  90. -extern void refuse(); /* clean up and exit */
  91. -extern char *xgets(); /* fgets() on steroids */
  92. -extern char *split_at(); /* strchr() and split */
  93. -extern unsigned long dot_quad_addr(); /* restricted inet_addr() */
  94. +extern void shell_cmd __P((char *)); /* execute shell command */
  95. +extern char *percent_x __P((char *, int, char *, struct request_info *)); /* do %<char> expansion */
  96. +extern void rfc931 __P((struct sockaddr_in *, struct sockaddr_in *, char *)); /* client name from RFC 931 daemon */
  97. +extern void clean_exit __P((struct request_info *)); /* clean up and exit */
  98. +extern void refuse __P((struct request_info *)); /* clean up and exit */
  99. +extern char *xgets __P((char *, int, FILE *)); /* fgets() on steroids */
  100. +extern char *split_at __P((char *, int)); /* strchr() and split */
  101. +extern unsigned long dot_quad_addr __P((char *)); /* restricted inet_addr() */
  102. /* Global variables. */
  103. +#ifdef HAVE_WEAKSYMS
  104. +extern int allow_severity __attribute__ ((weak)); /* for connection logging */
  105. +extern int deny_severity __attribute__ ((weak)); /* for connection logging */
  106. +#else
  107. extern int allow_severity; /* for connection logging */
  108. extern int deny_severity; /* for connection logging */
  109. +#endif
  110. +
  111. extern char *hosts_allow_table; /* for verification mode redirection */
  112. extern char *hosts_deny_table; /* for verification mode redirection */
  113. extern int hosts_access_verbose; /* for verbose matching mode */
  114. @@ -92,9 +116,14 @@ extern int resident; /* > 0 if residen
  115. */
  116. #ifdef __STDC__
  117. +extern int hosts_access(struct request_info *request);
  118. +extern int hosts_ctl(char *daemon, char *client_name, char *client_addr,
  119. + char *client_user);
  120. extern struct request_info *request_init(struct request_info *,...);
  121. extern struct request_info *request_set(struct request_info *,...);
  122. #else
  123. +extern int hosts_access();
  124. +extern int hosts_ctl();
  125. extern struct request_info *request_init(); /* initialize request */
  126. extern struct request_info *request_set(); /* update request structure */
  127. #endif
  128. @@ -117,27 +146,31 @@ extern struct request_info *request_set(
  129. * host_info structures serve as caches for the lookup results.
  130. */
  131. -extern char *eval_user(); /* client user */
  132. -extern char *eval_hostname(); /* printable hostname */
  133. -extern char *eval_hostaddr(); /* printable host address */
  134. -extern char *eval_hostinfo(); /* host name or address */
  135. -extern char *eval_client(); /* whatever is available */
  136. -extern char *eval_server(); /* whatever is available */
  137. +extern char *eval_user __P((struct request_info *)); /* client user */
  138. +extern char *eval_hostname __P((struct host_info *)); /* printable hostname */
  139. +extern char *eval_hostaddr __P((struct host_info *)); /* printable host address */
  140. +extern char *eval_hostinfo __P((struct host_info *)); /* host name or address */
  141. +extern char *eval_client __P((struct request_info *)); /* whatever is available */
  142. +extern char *eval_server __P((struct request_info *)); /* whatever is available */
  143. #define eval_daemon(r) ((r)->daemon) /* daemon process name */
  144. #define eval_pid(r) ((r)->pid) /* process id */
  145. /* Socket-specific methods, including DNS hostname lookups. */
  146. -extern void sock_host(); /* look up endpoint addresses */
  147. -extern void sock_hostname(); /* translate address to hostname */
  148. -extern void sock_hostaddr(); /* address to printable address */
  149. +/* look up endpoint addresses */
  150. +extern void sock_host __P((struct request_info *));
  151. +/* translate address to hostname */
  152. +extern void sock_hostname __P((struct host_info *));
  153. +/* address to printable address */
  154. +extern void sock_hostaddr __P((struct host_info *));
  155. +
  156. #define sock_methods(r) \
  157. { (r)->hostname = sock_hostname; (r)->hostaddr = sock_hostaddr; }
  158. /* The System V Transport-Level Interface (TLI) interface. */
  159. #if defined(TLI) || defined(PTX) || defined(TLI_SEQUENT)
  160. -extern void tli_host(); /* look up endpoint addresses etc. */
  161. +extern void tli_host __P((struct request_info *)); /* look up endpoint addresses etc. */
  162. #endif
  163. /*
  164. @@ -178,7 +211,7 @@ extern struct tcpd_context tcpd_context;
  165. * behavior.
  166. */
  167. -extern void process_options(); /* execute options */
  168. +extern void process_options __P((char *, struct request_info *)); /* execute options */
  169. extern int dry_run; /* verification flag */
  170. /* Bug workarounds. */
  171. @@ -217,3 +250,7 @@ extern char *fix_strtok();
  172. #define strtok my_strtok
  173. extern char *my_strtok();
  174. #endif
  175. +
  176. +__END_DECLS
  177. +
  178. +#endif /* tcpd.h */
  179. --- a/Makefile
  180. +++ b/Makefile
  181. @@ -1,5 +1,10 @@
  182. +GLIBC=$(shell grep -s -c __GLIBC__ /usr/include/features.h)
  183. +
  184. # @(#) Makefile 1.23 97/03/21 19:27:20
  185. +# unset the HOSTNAME environment variable
  186. +HOSTNAME =
  187. +
  188. what:
  189. @echo
  190. @echo "Usage: edit the REAL_DAEMON_DIR definition in the Makefile then:"
  191. @@ -19,7 +24,7 @@ what:
  192. @echo " generic (most bsd-ish systems with sys5 compatibility)"
  193. @echo " 386bsd aix alpha apollo bsdos convex-ultranet dell-gcc dgux dgux543"
  194. @echo " dynix epix esix freebsd hpux irix4 irix5 irix6 isc iunix"
  195. - @echo " linux machten mips(untested) ncrsvr4 netbsd next osf power_unix_211"
  196. + @echo " linux gnu machten mips(untested) ncrsvr4 netbsd next osf power_unix_211"
  197. @echo " ptx-2.x ptx-generic pyramid sco sco-nis sco-od2 sco-os5 sinix sunos4"
  198. @echo " sunos40 sunos5 sysv4 tandem ultrix unicos7 unicos8 unixware1 unixware2"
  199. @echo " uts215 uxp"
  200. @@ -43,8 +48,8 @@ what:
  201. # Ultrix 4.x SunOS 4.x ConvexOS 10.x Dynix/ptx
  202. #REAL_DAEMON_DIR=/usr/etc
  203. #
  204. -# SysV.4 Solaris 2.x OSF AIX
  205. -#REAL_DAEMON_DIR=/usr/sbin
  206. +# SysV.4 Solaris 2.x OSF AIX Linux
  207. +REAL_DAEMON_DIR=/usr/sbin
  208. #
  209. # BSD 4.4
  210. #REAL_DAEMON_DIR=/usr/libexec
  211. @@ -141,10 +146,21 @@ freebsd:
  212. LIBS= RANLIB=ranlib ARFLAGS=rv AUX_OBJ= NETGROUP= TLI= \
  213. EXTRA_CFLAGS=-DSYS_ERRLIST_DEFINED VSYSLOG= all
  214. +ifneq ($(GLIBC),0)
  215. +MYLIB=-lnsl
  216. +endif
  217. +
  218. linux:
  219. @make REAL_DAEMON_DIR=$(REAL_DAEMON_DIR) STYLE=$(STYLE) \
  220. - LIBS= RANLIB=ranlib ARFLAGS=rv AUX_OBJ=setenv.o \
  221. - NETGROUP= TLI= EXTRA_CFLAGS="-DBROKEN_SO_LINGER" all
  222. + LIBS=$(MYLIB) RANLIB=ranlib ARFLAGS=rv AUX_OBJ=weak_symbols.o \
  223. + NETGROUP=-DNETGROUP TLI= VSYSLOG= BUGS= all \
  224. + EXTRA_CFLAGS="-DSYS_ERRLIST_DEFINED -DHAVE_WEAKSYMS -D_REENTRANT"
  225. +
  226. +gnu:
  227. + @make REAL_DAEMON_DIR=$(REAL_DAEMON_DIR) STYLE=$(STYLE) \
  228. + LIBS=$(MYLIB) RANLIB=ranlib ARFLAGS=rv AUX_OBJ=weak_symbols.o \
  229. + NETGROUP=-DNETGROUP TLI= VSYSLOG= BUGS= all \
  230. + EXTRA_CFLAGS="-DHAVE_STRERROR -DHAVE_WEAKSYMS -D_REENTRANT"
  231. # This is good for many SYSV+BSD hybrids with NIS, probably also for HP-UX 7.x.
  232. hpux hpux8 hpux9 hpux10:
  233. @@ -391,7 +407,7 @@ AR = ar
  234. # the ones provided with this source distribution. The environ.c module
  235. # implements setenv(), getenv(), and putenv().
  236. -AUX_OBJ= setenv.o
  237. +#AUX_OBJ= setenv.o
  238. #AUX_OBJ= environ.o
  239. #AUX_OBJ= environ.o strcasecmp.o
  240. @@ -454,7 +470,8 @@ AUX_OBJ= setenv.o
  241. # host name aliases. Compile with -DSOLARIS_24_GETHOSTBYNAME_BUG to work
  242. # around this. The workaround does no harm on other Solaris versions.
  243. -BUGS = -DGETPEERNAME_BUG -DBROKEN_FGETS -DLIBC_CALLS_STRTOK
  244. +BUGS =
  245. +#BUGS = -DGETPEERNAME_BUG -DBROKEN_FGETS -DLIBC_CALLS_STRTOK
  246. #BUGS = -DGETPEERNAME_BUG -DBROKEN_FGETS -DINET_ADDR_BUG
  247. #BUGS = -DGETPEERNAME_BUG -DBROKEN_FGETS -DSOLARIS_24_GETHOSTBYNAME_BUG
  248. @@ -464,7 +481,7 @@ BUGS = -DGETPEERNAME_BUG -DBROKEN_FGETS
  249. # If your system supports NIS or YP-style netgroups, enable the following
  250. # macro definition. Netgroups are used only for host access control.
  251. #
  252. -#NETGROUP= -DNETGROUP
  253. +NETGROUP= -DNETGROUP
  254. ###############################################################
  255. # System dependencies: whether or not your system has vsyslog()
  256. @@ -491,7 +508,7 @@ VSYSLOG = -Dvsyslog=myvsyslog
  257. # Uncomment the next definition to turn on the language extensions
  258. # (examples: allow, deny, banners, twist and spawn).
  259. #
  260. -#STYLE = -DPROCESS_OPTIONS # Enable language extensions.
  261. +STYLE = -DPROCESS_OPTIONS # Enable language extensions.
  262. ################################################################
  263. # Optional: Changing the default disposition of logfile records
  264. @@ -514,7 +531,7 @@ VSYSLOG = -Dvsyslog=myvsyslog
  265. #
  266. # The LOG_XXX names below are taken from the /usr/include/syslog.h file.
  267. -FACILITY= LOG_MAIL # LOG_MAIL is what most sendmail daemons use
  268. +FACILITY= LOG_DAEMON # LOG_MAIL is what most sendmail daemons use
  269. # The syslog priority at which successful connections are logged.
  270. @@ -610,7 +627,7 @@ TABLES = -DHOSTS_DENY=\"/etc/hosts.deny\
  271. # Paranoid mode implies hostname lookup. In order to disable hostname
  272. # lookups altogether, see the next section.
  273. -PARANOID= -DPARANOID
  274. +#PARANOID= -DPARANOID
  275. ########################################
  276. # Optional: turning off hostname lookups
  277. @@ -623,7 +640,7 @@ PARANOID= -DPARANOID
  278. # In order to perform selective hostname lookups, disable paranoid
  279. # mode (see previous section) and comment out the following definition.
  280. -HOSTNAME= -DALWAYS_HOSTNAME
  281. +#HOSTNAME= -DALWAYS_HOSTNAME
  282. #############################################
  283. # Optional: Turning on host ADDRESS checking
  284. @@ -649,28 +666,46 @@ HOSTNAME= -DALWAYS_HOSTNAME
  285. # source-routed traffic in the kernel. Examples: 4.4BSD derivatives,
  286. # Solaris 2.x, and Linux. See your system documentation for details.
  287. #
  288. -# KILL_OPT= -DKILL_IP_OPTIONS
  289. +KILL_OPT= -DKILL_IP_OPTIONS
  290. ## End configuration options
  291. ############################
  292. # Protection against weird shells or weird make programs.
  293. +CC = gcc
  294. SHELL = /bin/sh
  295. -.c.o:; $(CC) $(CFLAGS) -c $*.c
  296. +.c.o:; $(CC) $(CFLAGS) -o $*.o -c $*.c
  297. +
  298. +SOMAJOR = 0
  299. +SOMINOR = 7.6
  300. +
  301. +LIB = libwrap.a
  302. +SHLIB = shared/libwrap.so.$(SOMAJOR).$(SOMINOR)
  303. +SHLIBSOMAJ= shared/libwrap.so.$(SOMAJOR)
  304. +SHLIBSO = shared/libwrap.so
  305. +SHLIBFLAGS = -Lshared -lwrap
  306. -CFLAGS = -O -DFACILITY=$(FACILITY) $(ACCESS) $(PARANOID) $(NETGROUP) \
  307. +shared/%.o: %.c
  308. + $(CC) $(CFLAGS) $(SHCFLAGS) -c $< -o $@
  309. +
  310. +CFLAGS = -O2 -g -DFACILITY=$(FACILITY) $(ACCESS) $(PARANOID) $(NETGROUP) \
  311. $(BUGS) $(SYSTYPE) $(AUTH) $(UMASK) \
  312. -DREAL_DAEMON_DIR=\"$(REAL_DAEMON_DIR)\" $(STYLE) $(KILL_OPT) \
  313. -DSEVERITY=$(SEVERITY) -DRFC931_TIMEOUT=$(RFC931_TIMEOUT) \
  314. $(UCHAR) $(TABLES) $(STRINGS) $(TLI) $(EXTRA_CFLAGS) $(DOT) \
  315. $(VSYSLOG) $(HOSTNAME)
  316. +SHLINKFLAGS = -shared -Xlinker -soname -Xlinker libwrap.so.$(SOMAJOR) -lc $(LIBS)
  317. +SHCFLAGS = -fPIC -shared -D_REENTRANT
  318. +
  319. LIB_OBJ= hosts_access.o options.o shell_cmd.o rfc931.o eval.o \
  320. hosts_ctl.o refuse.o percent_x.o clean_exit.o $(AUX_OBJ) \
  321. $(FROM_OBJ) fix_options.o socket.o tli.o workarounds.o \
  322. update.o misc.o diag.o percent_m.o myvsyslog.o
  323. +SHLIB_OBJ= $(addprefix shared/, $(LIB_OBJ));
  324. +
  325. FROM_OBJ= fromhost.o
  326. KIT = README miscd.c tcpd.c fromhost.c hosts_access.c shell_cmd.c \
  327. @@ -684,46 +719,78 @@ KIT = README miscd.c tcpd.c fromhost.c h
  328. refuse.c tcpdchk.8 setenv.c inetcf.c inetcf.h scaffold.c \
  329. scaffold.h tcpdmatch.8 README.NIS
  330. -LIB = libwrap.a
  331. -
  332. -all other: config-check tcpd tcpdmatch try-from safe_finger tcpdchk
  333. +all other: config-check tcpd tcpdmatch try-from safe_finger tcpdchk $(LIB)
  334. # Invalidate all object files when the compiler options (CFLAGS) have changed.
  335. config-check:
  336. @set +e; test -n "$(REAL_DAEMON_DIR)" || { make; exit 1; }
  337. - @set +e; echo $(CFLAGS) >/tmp/cflags.$$$$ ; \
  338. - if cmp cflags /tmp/cflags.$$$$ ; \
  339. - then rm /tmp/cflags.$$$$ ; \
  340. - else mv /tmp/cflags.$$$$ cflags ; \
  341. + @set +e; echo $(CFLAGS) >cflags.new ; \
  342. + if cmp cflags cflags.new ; \
  343. + then rm cflags.new ; \
  344. + else mv cflags.new cflags ; \
  345. fi >/dev/null 2>/dev/null
  346. + @if [ ! -d shared ]; then mkdir shared; fi
  347. $(LIB): $(LIB_OBJ)
  348. rm -f $(LIB)
  349. $(AR) $(ARFLAGS) $(LIB) $(LIB_OBJ)
  350. -$(RANLIB) $(LIB)
  351. -tcpd: tcpd.o $(LIB)
  352. - $(CC) $(CFLAGS) -o $@ tcpd.o $(LIB) $(LIBS)
  353. +$(SHLIB): $(SHLIB_OBJ)
  354. + rm -f $(SHLIB)
  355. + $(CC) -o $(SHLIB) $(SHLINKFLAGS) $(SHLIB_OBJ)
  356. + ln -s $(notdir $(SHLIB)) $(SHLIBSOMAJ)
  357. + ln -s $(notdir $(SHLIBSOMAJ)) $(SHLIBSO)
  358. +
  359. +tcpd: tcpd.o $(SHLIB)
  360. + $(CC) $(CFLAGS) -o $@ tcpd.o $(SHLIBFLAGS)
  361. -miscd: miscd.o $(LIB)
  362. - $(CC) $(CFLAGS) -o $@ miscd.o $(LIB) $(LIBS)
  363. +miscd: miscd.o $(SHLIB)
  364. + $(CC) $(CFLAGS) -o $@ miscd.o $(SHLIBFLAGS)
  365. -safe_finger: safe_finger.o $(LIB)
  366. - $(CC) $(CFLAGS) -o $@ safe_finger.o $(LIB) $(LIBS)
  367. +safe_finger: safe_finger.o $(SHLIB)
  368. + $(CC) $(CFLAGS) -o $@ safe_finger.o $(SHLIBFLAGS)
  369. TCPDMATCH_OBJ = tcpdmatch.o fakelog.o inetcf.o scaffold.o
  370. -tcpdmatch: $(TCPDMATCH_OBJ) $(LIB)
  371. - $(CC) $(CFLAGS) -o $@ $(TCPDMATCH_OBJ) $(LIB) $(LIBS)
  372. +tcpdmatch: $(TCPDMATCH_OBJ) $(SHLIB)
  373. + $(CC) $(CFLAGS) -o $@ $(TCPDMATCH_OBJ) $(SHLIBFLAGS)
  374. -try-from: try-from.o fakelog.o $(LIB)
  375. - $(CC) $(CFLAGS) -o $@ try-from.o fakelog.o $(LIB) $(LIBS)
  376. +try-from: try-from.o fakelog.o $(SHLIB)
  377. + $(CC) $(CFLAGS) -o $@ try-from.o fakelog.o $(SHLIBFLAGS)
  378. TCPDCHK_OBJ = tcpdchk.o fakelog.o inetcf.o scaffold.o
  379. -tcpdchk: $(TCPDCHK_OBJ) $(LIB)
  380. - $(CC) $(CFLAGS) -o $@ $(TCPDCHK_OBJ) $(LIB) $(LIBS)
  381. +tcpdchk: $(TCPDCHK_OBJ) $(SHLIB)
  382. + $(CC) $(CFLAGS) -o $@ $(TCPDCHK_OBJ) $(SHLIBFLAGS)
  383. +
  384. +install: install-lib install-bin install-dev
  385. +
  386. +install-lib:
  387. + install -o root -g root -m 0644 $(SHLIB) ${DESTDIR}/lib/
  388. + ln -s $(notdir $(SHLIB)) ${DESTDIR}/lib/$(notdir $(SHLIBSOMAJ))
  389. +
  390. +install-bin:
  391. + install -o root -g root -m 0755 tcpd ${DESTDIR}/usr/sbin/
  392. + install -o root -g root -m 0755 tcpdchk ${DESTDIR}/usr/sbin/
  393. + install -o root -g root -m 0755 tcpdmatch ${DESTDIR}/usr/sbin/
  394. + install -o root -g root -m 0755 try-from ${DESTDIR}/usr/sbin/
  395. + install -o root -g root -m 0755 safe_finger ${DESTDIR}/usr/sbin/
  396. + install -o root -g root -m 0644 tcpd.8 ${DESTDIR}/usr/share/man/man8/
  397. + install -o root -g root -m 0644 tcpdchk.8 ${DESTDIR}/usr/share/man/man8/
  398. + install -o root -g root -m 0644 tcpdmatch.8 ${DESTDIR}/usr/share/man/man8/
  399. + install -o root -g root -m 0644 hosts_access.5 ${DESTDIR}/usr/share/man/man5/
  400. + install -o root -g root -m 0644 hosts_options.5 ${DESTDIR}/usr/share/man/man5/
  401. +
  402. +install-dev:
  403. + ln -s /lib/$(notdir $(SHLIBSOMAJ)) ${DESTDIR}/usr/lib/$(notdir $(SHLIBSO))
  404. + install -o root -g root -m 0644 hosts_access.3 ${DESTDIR}/usr/share/man/man3/
  405. + install -o root -g root -m 0644 tcpd.h ${DESTDIR}/usr/include/
  406. + install -o root -g root -m 0644 $(LIB) ${DESTDIR}/usr/lib/
  407. + ln -s hosts_access.3 ${DESTDIR}/usr/share/man/man3/hosts_ctl.3
  408. + ln -s hosts_access.3 ${DESTDIR}/usr/share/man/man3/request_init.3
  409. + ln -s hosts_access.3 ${DESTDIR}/usr/share/man/man3/request_set.3
  410. shar: $(KIT)
  411. @shar $(KIT)
  412. @@ -739,7 +806,8 @@ archive:
  413. clean:
  414. rm -f tcpd miscd safe_finger tcpdmatch tcpdchk try-from *.[oa] core \
  415. - cflags
  416. + cflags libwrap*.so*
  417. + rm -rf shared
  418. tidy: clean
  419. chmod -R a+r .
  420. @@ -885,5 +953,6 @@ update.o: cflags
  421. update.o: mystdarg.h
  422. update.o: tcpd.h
  423. vfprintf.o: cflags
  424. +weak_symbols.o: tcpd.h
  425. workarounds.o: cflags
  426. workarounds.o: tcpd.h
  427. --- a/hosts_access.5
  428. +++ b/hosts_access.5
  429. @@ -8,9 +8,9 @@ name, host name/address) patterns. Exam
  430. impatient reader is encouraged to skip to the EXAMPLES section for a
  431. quick introduction.
  432. .PP
  433. -An extended version of the access control language is described in the
  434. -\fIhosts_options\fR(5) document. The extensions are turned on at
  435. -program build time by building with -DPROCESS_OPTIONS.
  436. +The extended version of the access control language is described in the
  437. +\fIhosts_options\fR(5) document. \fBNote that this language supersedes
  438. +the meaning of \fIshell_command\fB as documented below.\fR
  439. .PP
  440. In the following text, \fIdaemon\fR is the the process name of a
  441. network daemon process, and \fIclient\fR is the name and/or address of
  442. @@ -40,7 +40,7 @@ A newline character is ignored when it i
  443. character. This permits you to break up long lines so that they are
  444. easier to edit.
  445. .IP \(bu
  446. -Blank lines or lines that begin with a `#\' character are ignored.
  447. +Blank lines or lines that begin with a `#' character are ignored.
  448. This permits you to insert comments and whitespace so that the tables
  449. are easier to read.
  450. .IP \(bu
  451. @@ -69,26 +69,33 @@ checks are case insensitive.
  452. .SH PATTERNS
  453. The access control language implements the following patterns:
  454. .IP \(bu
  455. -A string that begins with a `.\' character. A host name is matched if
  456. +A string that begins with a `.' character. A host name is matched if
  457. the last components of its name match the specified pattern. For
  458. -example, the pattern `.tue.nl\' matches the host name
  459. -`wzv.win.tue.nl\'.
  460. +example, the pattern `.tue.nl' matches the host name
  461. +`wzv.win.tue.nl'.
  462. .IP \(bu
  463. -A string that ends with a `.\' character. A host address is matched if
  464. +A string that ends with a `.' character. A host address is matched if
  465. its first numeric fields match the given string. For example, the
  466. -pattern `131.155.\' matches the address of (almost) every host on the
  467. +pattern `131.155.' matches the address of (almost) every host on the
  468. Eind\%hoven University network (131.155.x.x).
  469. .IP \(bu
  470. -A string that begins with an `@\' character is treated as an NIS
  471. +A string that begins with an `@' character is treated as an NIS
  472. (formerly YP) netgroup name. A host name is matched if it is a host
  473. member of the specified netgroup. Netgroup matches are not supported
  474. for daemon process names or for client user names.
  475. .IP \(bu
  476. -An expression of the form `n.n.n.n/m.m.m.m\' is interpreted as a
  477. -`net/mask\' pair. A host address is matched if `net\' is equal to the
  478. -bitwise AND of the address and the `mask\'. For example, the net/mask
  479. -pattern `131.155.72.0/255.255.254.0\' matches every address in the
  480. -range `131.155.72.0\' through `131.155.73.255\'.
  481. +An expression of the form `n.n.n.n/m.m.m.m' is interpreted as a
  482. +`net/mask' pair. A host address is matched if `net' is equal to the
  483. +bitwise AND of the address and the `mask'. For example, the net/mask
  484. +pattern `131.155.72.0/255.255.254.0' matches every address in the
  485. +range `131.155.72.0' through `131.155.73.255'.
  486. +.IP \(bu
  487. +A string that begins with a `/' character is treated as a file
  488. +name. A host name or address is matched if it matches any host name
  489. +or address pattern listed in the named file. The file format is
  490. +zero or more lines with zero or more host name or address patterns
  491. +separated by whitespace. A file name pattern can be used anywhere
  492. +a host name or address pattern can be used.
  493. .SH WILDCARDS
  494. The access control language supports explicit wildcards:
  495. .IP ALL
  496. @@ -115,19 +122,19 @@ without -DPARANOID when you want more co
  497. .ne 6
  498. .SH OPERATORS
  499. .IP EXCEPT
  500. -Intended use is of the form: `list_1 EXCEPT list_2\'; this construct
  501. +Intended use is of the form: `list_1 EXCEPT list_2'; this construct
  502. matches anything that matches \fIlist_1\fR unless it matches
  503. \fIlist_2\fR. The EXCEPT operator can be used in daemon_lists and in
  504. client_lists. The EXCEPT operator can be nested: if the control
  505. -language would permit the use of parentheses, `a EXCEPT b EXCEPT c\'
  506. -would parse as `(a EXCEPT (b EXCEPT c))\'.
  507. +language would permit the use of parentheses, `a EXCEPT b EXCEPT c'
  508. +would parse as `(a EXCEPT (b EXCEPT c))'.
  509. .br
  510. .ne 6
  511. .SH SHELL COMMANDS
  512. If the first-matched access control rule contains a shell command, that
  513. command is subjected to %<letter> substitutions (see next section).
  514. The result is executed by a \fI/bin/sh\fR child process with standard
  515. -input, output and error connected to \fI/dev/null\fR. Specify an `&\'
  516. +input, output and error connected to \fI/dev/null\fR. Specify an `&'
  517. at the end of the command if you do not want to wait until it has
  518. completed.
  519. .PP
  520. @@ -159,7 +166,7 @@ depending on how much information is ava
  521. .IP %u
  522. The client user name (or "unknown").
  523. .IP %%
  524. -Expands to a single `%\' character.
  525. +Expands to a single `%' character.
  526. .PP
  527. Characters in % expansions that may confuse the shell are replaced by
  528. underscores.
  529. @@ -243,9 +250,9 @@ A positive IDENT lookup result (the clie
  530. less trustworthy. It is possible for an intruder to spoof both the
  531. client connection and the IDENT lookup, although doing so is much
  532. harder than spoofing just a client connection. It may also be that
  533. -the client\'s IDENT server is lying.
  534. +the client's IDENT server is lying.
  535. .PP
  536. -Note: IDENT lookups don\'t work with UDP services.
  537. +Note: IDENT lookups don't work with UDP services.
  538. .SH EXAMPLES
  539. The language is flexible enough that different types of access control
  540. policy can be expressed with a minimum of fuss. Although the language
  541. @@ -285,7 +292,7 @@ ALL: LOCAL @some_netgroup
  542. .br
  543. ALL: .foobar.edu EXCEPT terminalserver.foobar.edu
  544. .PP
  545. -The first rule permits access from hosts in the local domain (no `.\'
  546. +The first rule permits access from hosts in the local domain (no `.'
  547. in the host name) and from members of the \fIsome_netgroup\fP
  548. netgroup. The second rule permits access from all hosts in the
  549. \fIfoobar.edu\fP domain (notice the leading dot), with the exception of
  550. @@ -322,8 +329,8 @@ in.tftpd: LOCAL, .my.domain
  551. /etc/hosts.deny:
  552. .in +3
  553. .nf
  554. -in.tftpd: ALL: (/some/where/safe_finger -l @%h | \\
  555. - /usr/ucb/mail -s %d-%h root) &
  556. +in.tftpd: ALL: (/usr/sbin/safe_finger -l @%h | \\
  557. + /usr/bin/mail -s %d-%h root) &
  558. .fi
  559. .PP
  560. The safe_finger command comes with the tcpd wrapper and should be
  561. @@ -349,7 +356,7 @@ control rule; when the length of an acce
  562. capacity of an internal buffer; when an access control rule is not
  563. terminated by a newline character; when the result of %<letter>
  564. expansion would overflow an internal buffer; when a system call fails
  565. -that shouldn\'t. All problems are reported via the syslog daemon.
  566. +that shouldn't. All problems are reported via the syslog daemon.
  567. .SH FILES
  568. .na
  569. .nf
  570. --- a/rfc931.c
  571. +++ b/rfc931.c
  572. @@ -33,7 +33,7 @@ static char sccsid[] = "@(#) rfc931.c 1.
  573. int rfc931_timeout = RFC931_TIMEOUT;/* Global so it can be changed */
  574. -static jmp_buf timebuf;
  575. +static sigjmp_buf timebuf;
  576. /* fsocket - open stdio stream on top of socket */
  577. @@ -62,7 +62,7 @@ int protocol;
  578. static void timeout(sig)
  579. int sig;
  580. {
  581. - longjmp(timebuf, sig);
  582. + siglongjmp(timebuf, sig);
  583. }
  584. /* rfc931 - return remote user name, given socket structures */
  585. @@ -99,7 +99,7 @@ char *dest;
  586. * Set up a timer so we won't get stuck while waiting for the server.
  587. */
  588. - if (setjmp(timebuf) == 0) {
  589. + if (sigsetjmp(timebuf,1) == 0) {
  590. signal(SIGALRM, timeout);
  591. alarm(rfc931_timeout);
  592. --- a/tcpd.8
  593. +++ b/tcpd.8
  594. @@ -94,7 +94,7 @@ configuration files.
  595. .PP
  596. The example assumes that the network daemons live in /usr/etc. On some
  597. systems, network daemons live in /usr/sbin or in /usr/libexec, or have
  598. -no `in.\' prefix to their name.
  599. +no `in.' prefix to their name.
  600. .SH EXAMPLE 2
  601. This example applies when \fItcpd\fR expects that the network daemons
  602. are left in their original place.
  603. @@ -110,26 +110,26 @@ finger stream tcp nowait nobody /us
  604. becomes:
  605. .sp
  606. .ti +5
  607. -finger stream tcp nowait nobody /some/where/tcpd in.fingerd
  608. +finger stream tcp nowait nobody /usr/sbin/tcpd in.fingerd
  609. .sp
  610. .fi
  611. .PP
  612. The example assumes that the network daemons live in /usr/etc. On some
  613. systems, network daemons live in /usr/sbin or in /usr/libexec, the
  614. -daemons have no `in.\' prefix to their name, or there is no userid
  615. +daemons have no `in.' prefix to their name, or there is no userid
  616. field in the inetd configuration file.
  617. .PP
  618. Similar changes will be needed for the other services that are to be
  619. -covered by \fItcpd\fR. Send a `kill -HUP\' to the \fIinetd\fR(8)
  620. +covered by \fItcpd\fR. Send a `kill -HUP' to the \fIinetd\fR(8)
  621. process to make the changes effective. AIX users may also have to
  622. -execute the `inetimp\' command.
  623. +execute the `inetimp' command.
  624. .SH EXAMPLE 3
  625. In the case of daemons that do not live in a common directory ("secret"
  626. or otherwise), edit the \fIinetd\fR configuration file so that it
  627. specifies an absolute path name for the process name field. For example:
  628. .nf
  629. .sp
  630. - ntalk dgram udp wait root /some/where/tcpd /usr/local/lib/ntalkd
  631. + ntalk dgram udp wait root /usr/sbin/tcpd /usr/sbin/in.ntalkd
  632. .sp
  633. .fi
  634. .PP
  635. --- a/hosts_access.3
  636. +++ b/hosts_access.3
  637. @@ -3,7 +3,7 @@
  638. hosts_access, hosts_ctl, request_init, request_set \- access control library
  639. .SH SYNOPSIS
  640. .nf
  641. -#include "tcpd.h"
  642. +#include <tcpd.h>
  643. extern int allow_severity;
  644. extern int deny_severity;
  645. --- a/options.c
  646. +++ b/options.c
  647. @@ -473,6 +473,9 @@ static struct syslog_names log_fac[] = {
  648. #ifdef LOG_CRON
  649. "cron", LOG_CRON,
  650. #endif
  651. +#ifdef LOG_FTP
  652. + "ftp", LOG_FTP,
  653. +#endif
  654. #ifdef LOG_LOCAL0
  655. "local0", LOG_LOCAL0,
  656. #endif
  657. --- a/fix_options.c
  658. +++ b/fix_options.c
  659. @@ -35,7 +35,12 @@ struct request_info *request;
  660. #ifdef IP_OPTIONS
  661. unsigned char optbuf[BUFFER_SIZE / 3], *cp;
  662. char lbuf[BUFFER_SIZE], *lp;
  663. +#if !defined(__GLIBC__)
  664. int optsize = sizeof(optbuf), ipproto;
  665. +#else /* __GLIBC__ */
  666. + size_t optsize = sizeof(optbuf);
  667. + int ipproto;
  668. +#endif /* __GLIBC__ */
  669. struct protoent *ip;
  670. int fd = request->fd;
  671. unsigned int opt;
  672. --- a/workarounds.c
  673. +++ b/workarounds.c
  674. @@ -163,7 +163,11 @@ int *fromlen;
  675. int fix_getpeername(sock, sa, len)
  676. int sock;
  677. struct sockaddr *sa;
  678. +#if !defined(__GLIBC__)
  679. int *len;
  680. +#else /* __GLIBC__ */
  681. +size_t *len;
  682. +#endif /* __GLIBC__ */
  683. {
  684. int ret;
  685. struct sockaddr_in *sin = (struct sockaddr_in *) sa;
  686. --- a/socket.c
  687. +++ b/socket.c
  688. @@ -76,7 +76,11 @@ struct request_info *request;
  689. {
  690. static struct sockaddr_in client;
  691. static struct sockaddr_in server;
  692. +#if !defined (__GLIBC__)
  693. int len;
  694. +#else /* __GLIBC__ */
  695. + size_t len;
  696. +#endif /* __GLIBC__ */
  697. char buf[BUFSIZ];
  698. int fd = request->fd;
  699. @@ -224,7 +228,11 @@ int fd;
  700. {
  701. char buf[BUFSIZ];
  702. struct sockaddr_in sin;
  703. +#if !defined(__GLIBC__)
  704. int size = sizeof(sin);
  705. +#else /* __GLIBC__ */
  706. + size_t size = sizeof(sin);
  707. +#endif /* __GLIBC__ */
  708. /*
  709. * Eat up the not-yet received datagram. Some systems insist on a
  710. --- a/safe_finger.c
  711. +++ b/safe_finger.c
  712. @@ -26,21 +26,24 @@ static char sccsid[] = "@(#) safe_finger
  713. #include <stdio.h>
  714. #include <ctype.h>
  715. #include <pwd.h>
  716. +#include <syslog.h>
  717. extern void exit();
  718. /* Local stuff */
  719. -char path[] = "PATH=/bin:/usr/bin:/usr/ucb:/usr/bsd:/etc:/usr/etc:/usr/sbin";
  720. +char path[] = "PATH=/bin:/usr/bin:/sbin:/usr/sbin";
  721. #define TIME_LIMIT 60 /* Do not keep listinging forever */
  722. #define INPUT_LENGTH 100000 /* Do not keep listinging forever */
  723. #define LINE_LENGTH 128 /* Editors can choke on long lines */
  724. #define FINGER_PROGRAM "finger" /* Most, if not all, UNIX systems */
  725. #define UNPRIV_NAME "nobody" /* Preferred privilege level */
  726. -#define UNPRIV_UGID 32767 /* Default uid and gid */
  727. +#define UNPRIV_UGID 65534 /* Default uid and gid */
  728. int finger_pid;
  729. +int allow_severity = SEVERITY;
  730. +int deny_severity = LOG_WARNING;
  731. void cleanup(sig)
  732. int sig;
  733. --- a/hosts_options.5
  734. +++ b/hosts_options.5
  735. @@ -58,12 +58,12 @@ Notice the leading dot on the domain nam
  736. Execute, in a child process, the specified shell command, after
  737. performing the %<letter> expansions described in the hosts_access(5)
  738. manual page. The command is executed with stdin, stdout and stderr
  739. -connected to the null device, so that it won\'t mess up the
  740. +connected to the null device, so that it won't mess up the
  741. conversation with the client host. Example:
  742. .sp
  743. .nf
  744. .ti +3
  745. -spawn (/some/where/safe_finger -l @%h | /usr/ucb/mail root) &
  746. +spawn (/usr/sbin/safe_finger -l @%h | /usr/bin/mail root) &
  747. .fi
  748. .sp
  749. executes, in a background child process, the shell command "safe_finger
  750. --- a/tcpdchk.c
  751. +++ b/tcpdchk.c
  752. @@ -350,6 +350,8 @@ char *pat;
  753. {
  754. if (pat[0] == '@') {
  755. tcpd_warn("%s: daemon name begins with \"@\"", pat);
  756. + } else if (pat[0] == '/') {
  757. + tcpd_warn("%s: daemon name begins with \"/\"", pat);
  758. } else if (pat[0] == '.') {
  759. tcpd_warn("%s: daemon name begins with dot", pat);
  760. } else if (pat[strlen(pat) - 1] == '.') {
  761. @@ -382,6 +384,8 @@ char *pat;
  762. {
  763. if (pat[0] == '@') { /* @netgroup */
  764. tcpd_warn("%s: user name begins with \"@\"", pat);
  765. + } else if (pat[0] == '/') {
  766. + tcpd_warn("%s: user name begins with \"/\"", pat);
  767. } else if (pat[0] == '.') {
  768. tcpd_warn("%s: user name begins with dot", pat);
  769. } else if (pat[strlen(pat) - 1] == '.') {
  770. @@ -402,8 +406,13 @@ char *pat;
  771. static int check_host(pat)
  772. char *pat;
  773. {
  774. + char buf[BUFSIZ];
  775. char *mask;
  776. int addr_count = 1;
  777. + FILE *fp;
  778. + struct tcpd_context saved_context;
  779. + char *cp;
  780. + char *wsp = " \t\r\n";
  781. if (pat[0] == '@') { /* @netgroup */
  782. #ifdef NO_NETGRENT
  783. @@ -422,6 +431,21 @@ char *pat;
  784. tcpd_warn("netgroup support disabled");
  785. #endif
  786. #endif
  787. + } else if (pat[0] == '/') { /* /path/name */
  788. + if ((fp = fopen(pat, "r")) != 0) {
  789. + saved_context = tcpd_context;
  790. + tcpd_context.file = pat;
  791. + tcpd_context.line = 0;
  792. + while (fgets(buf, sizeof(buf), fp)) {
  793. + tcpd_context.line++;
  794. + for (cp = strtok(buf, wsp); cp; cp = strtok((char *) 0, wsp))
  795. + check_host(cp);
  796. + }
  797. + tcpd_context = saved_context;
  798. + fclose(fp);
  799. + } else if (errno != ENOENT) {
  800. + tcpd_warn("open %s: %m", pat);
  801. + }
  802. } else if (mask = split_at(pat, '/')) { /* network/netmask */
  803. if (dot_quad_addr(pat) == INADDR_NONE
  804. || dot_quad_addr(mask) == INADDR_NONE)
  805. --- a/percent_m.c
  806. +++ b/percent_m.c
  807. @@ -13,7 +13,7 @@ static char sccsid[] = "@(#) percent_m.c
  808. #include <string.h>
  809. extern int errno;
  810. -#ifndef SYS_ERRLIST_DEFINED
  811. +#if !defined(SYS_ERRLIST_DEFINED) && !defined(HAVE_STRERROR)
  812. extern char *sys_errlist[];
  813. extern int sys_nerr;
  814. #endif
  815. @@ -29,11 +29,15 @@ char *ibuf;
  816. while (*bp = *cp)
  817. if (*cp == '%' && cp[1] == 'm') {
  818. +#ifdef HAVE_STRERROR
  819. + strcpy(bp, strerror(errno));
  820. +#else
  821. if (errno < sys_nerr && errno > 0) {
  822. strcpy(bp, sys_errlist[errno]);
  823. } else {
  824. sprintf(bp, "Unknown error %d", errno);
  825. }
  826. +#endif
  827. bp += strlen(bp);
  828. cp += 2;
  829. } else {
  830. --- a/scaffold.c
  831. +++ b/scaffold.c
  832. @@ -180,10 +180,12 @@ struct request_info *request;
  833. /* ARGSUSED */
  834. -void rfc931(request)
  835. -struct request_info *request;
  836. +void rfc931(rmt_sin, our_sin, dest)
  837. +struct sockaddr_in *rmt_sin;
  838. +struct sockaddr_in *our_sin;
  839. +char *dest;
  840. {
  841. - strcpy(request->user, unknown);
  842. + strcpy(dest, unknown);
  843. }
  844. /* check_path - examine accessibility */
  845. --- /dev/null
  846. +++ b/weak_symbols.c
  847. @@ -0,0 +1,11 @@
  848. + /*
  849. + * @(#) weak_symbols.h 1.5 99/12/29 23:50
  850. + *
  851. + * Author: Anthony Towns <ajt@debian.org>
  852. + */
  853. +
  854. +#ifdef HAVE_WEAKSYMS
  855. +#include <syslog.h>
  856. +int deny_severity = LOG_WARNING;
  857. +int allow_severity = SEVERITY;
  858. +#endif