]> git.sesse.net Git - betaftpd/blob - configure.in
Fixed a security problem where the custom snprintf() would always be used. Thanks...
[betaftpd] / configure.in
1 AC_INIT(cmds.c)
2 AC_PREFIX_PROGRAM(ftpd)
3 AC_CONFIG_HEADER(config.h)
4 AC_PROG_CC
5
6 dnl
7 dnl Set of libraries to use
8 dnl
9 LIBS=""
10 AC_SUBST(LIBS)
11
12 AC_C_CONST
13 AC_FUNC_MMAP
14 AC_TYPE_SIGNAL
15 AC_CHECK_FUNCS(snprintf vsnprintf)
16
17 dnl
18 dnl Check if we need -lsocket -- taken from wu-ftpd
19 dnl
20 AC_CHECK_LIB(socket,socket,result=yes,result=no)
21 if test "$result" = "yes"; then
22   LIBS="$LIBS -lsocket"
23 else
24   AC_CHECK_LIB(socket,connect,result=yes,result=no)
25   if test "$result" = "yes"; then
26     LIBS="$LIBS -lsocket"
27   fi
28 fi
29
30 dnl
31 dnl Check if we need -lcrypt
32 dnl
33 AC_CHECK_LIB(crypt,crypt,result=yes,result=no)
34 if test "$result" = "yes"; then
35   LIBS="$LIBS -lcrypt"
36 fi
37
38 dnl
39 dnl The following weirdness is to support --disable as well as --enable
40 dnl (but long live m4!)
41 dnl 
42 define(ARG_ENABLE_BETAFTPD,[
43 AC_MSG_CHECKING(whether to enable $1)
44 AC_ARG_ENABLE($1,[$2],result=yes,result=no)
45 if test "$result" = "no"; then
46         enableval=no
47 fi
48
49 if test "$enableval" = "yes"; then
50         $3
51 fi
52 AC_MSG_RESULT($enableval)
53 ])
54
55 dnl
56 dnl Check for options
57 dnl
58 ARG_ENABLE_BETAFTPD(xferlog,[  --enable-xferlog        Enable transfer log support],AC_DEFINE(WANT_XFERLOG))
59 ARG_ENABLE_BETAFTPD(ascii,[  --enable-ascii          Enable ASCII mode support],AC_DEFINE(WANT_ASCII))
60 ARG_ENABLE_BETAFTPD(fullscreen,[  --enable-fullscreen     Run in fullscreen mode (implies --disable-fork)],AC_DEFINE(WANT_FULLSCREEN))
61
62 if test "$enableval" = "no"; then
63         ARG_ENABLE_BETAFTPD(fork,[  --enable-fork           Make the server fork into the background],AC_DEFINE(WANT_FORK))
64 fi
65
66 ARG_ENABLE_BETAFTPD(upload,[  --enable-upload         Enable upload support],AC_DEFINE(WANT_UPLOAD))
67 ARG_ENABLE_BETAFTPD(stat,[  --enable-stat           Enable STAT command (see README first)],AC_DEFINE(WANT_STAT))
68 ARG_ENABLE_BETAFTPD(dcache,[  --enable-dcache         Enable directory listing cache],AC_DEFINE(WANT_DCACHE))
69 ARG_ENABLE_BETAFTPD(message,[  --enable-message        Enable .message files etc.],AC_DEFINE(WANT_MESSAGE))
70
71 dnl
72 dnl The following line _must_ be last...
73 dnl
74 ARG_ENABLE_BETAFTPD(shadow,[  --enable-shadow         Enable shadow password support],AC_DEFINE(WANT_SHADOW))
75
76 nonroot_support=yes
77
78 if test "$enableval" = "yes"; then
79         AC_CHECK_HEADERS(shadow.h)
80         nonroot_support=no
81 else
82         dnl Causes unknown trouble on SunOS, so it's disabled
83         dnl if test -e "/etc/shadow"; then
84         dnl     AC_MSG_WARN()
85         dnl     AC_MSG_WARN([It looks like you're using shadow passwords, consider])
86         dnl     AC_MSG_WARN([giving the --enable-shadow flag to configure. Proceeding])
87         dnl     AC_MSG_WARN([_without_ support for shadow passwords -- you might not])
88         dnl     AC_MSG_WARN([be able to log in!])
89         dnl     AC_MSG_WARN()
90         dnl fi
91         echo
92 fi
93
94 if test "$nonroot_support" = "yes"; then
95         ARG_ENABLE_BETAFTPD(nonroot,[  --enable-nonroot        Do not need root access (EXPERIMENTAL)],AC_DEFINE(WANT_NONROOT))
96 else
97         enableval=no
98 fi
99
100 if test "$enableval" = "yes"; then
101         AC_MSG_WARN()
102         AC_MSG_WARN([Please read the README.nonroot file before using --enable-nonroot])
103         AC_MSG_WARN()
104 else
105
106 dnl
107 dnl Try to find our effective userid (use our own C program?)
108 dnl
109         AC_MSG_CHECKING(how to get effective uid)
110         if test -n "$EUID"; then
111                 B_UID=$EUID
112                 AC_MSG_RESULT([\$EUID ($EUID)])
113         elif test -n "$euid"; then
114                 B_UID=$euid
115                 AC_MSG_RESULT([\$euid ($euid)])
116         elif test -n "$UID"; then
117                 B_UID=$UID
118                 AC_MSG_RESULT([\$UID ($UID)])
119         elif test -n "$uid"; then
120                 B_UID=$uid
121                 AC_MSG_RESULT([\$uid ($uid)])
122         elif test "`whoami 2>/dev/null`" = "root"; then
123                 B_UID=0
124                 AC_MSG_RESULT([whoami (root)])
125         else
126                 # assume we're not root
127                 B_UID=1
128                 AC_MSG_RESULT(not found, assuming not root)
129         fi
130
131         if test "$B_UID" -ne 0; then
132                 AC_MSG_WARN()
133                 AC_MSG_WARN([You do not seem to have root privilegies. If you])
134                 AC_MSG_WARN([want to run BetaFTPD without being root, please])
135                 AC_MSG_WARN([consider giving the --enable-nonroot flag to])
136                 AC_MSG_WARN([configure, and read the README.nonroot file.])
137                 AC_MSG_WARN()
138         fi
139 fi
140
141 AC_CHECK_TYPE(uid_t,int)
142 AC_CHECK_TYPE(gid_t,int)
143
144 AC_CHECK_HEADERS(crypt.h unistd.h time.h sys/time.h errno.h netinet/in.h)
145 AC_CHECK_HEADERS(netinet/ip.h stropts.h sys/conf.h arpa/inet.h sys/filio.h)
146 AC_CHECK_HEADERS(netinet/tcp.h sys/types.h netdb.h glob.h stdio.h)
147 AC_CHECK_HEADERS(stdlib.h stdarg.h stdlib.h string.h strings.h fcntl.h)
148 AC_CHECK_HEADERS(sys/ioctl.h sys/socket.h sys/stat.h sys/param.h signal.h)
149 AC_CHECK_HEADERS(sys/signal.h dirent.h pwd.h grp.h netinet/in_systm.h)
150 AC_CHECK_HEADERS(assert.h)
151
152 AC_CHECK_HEADER(netinet/tcp.h,result=yes,result=no)
153
154 dnl
155 dnl linux/socket.h can create some problems on Debian GNU/Linux systems
156 dnl
157
158 if test "$result" = "yes"; then
159      AC_MSG_CHECKING(if netinet/tcp.h is enough)
160      AC_EGREP_CPP(yes,
161      [#include <netinet/tcp.h>
162 #ifndef TCP_NODELAY
163       yes
164 #endif
165      ], result=no, result=yes)
166      AC_MSG_RESULT($result)
167 fi
168
169 if test "$result" = "no"; then
170         AC_CHECK_HEADERS(linux/socket.h linux/tcp.h)
171 fi
172
173 AC_CHECK_HEADERS(sys/poll.h)
174
175 AC_MSG_CHECKING([for poll()])
176 AC_TRY_COMPILE([
177 #if HAVE_SYS_POLL_H
178 #include <sys/poll.h>
179 #endif
180 ],[
181         struct pollfd fds[1];
182         fds[0].fd = 0;
183         fds[0].events = POLLIN | POLLOUT | POLLERR | POLLHUP | POLLNVAL;
184
185         poll(fds, 1, 1000);
186 ],enableval=yes,enableval=no)
187 AC_MSG_RESULT($enableval)
188
189 if test "$enableval" = "yes"; then
190         AC_DEFINE(HAVE_POLL, 1, [Define if you have poll().])
191 fi
192
193 dnl
194 dnl sendfile() is not standard -- we'll have to check the different
195 dnl versions one by one :-)
196 dnl
197 dnl Unfortunately, we'll have to run the program too -- this is a
198 dnl problem with newer libc's and not-so-new kernels :-)
199 dnl
200 AC_CHECK_HEADERS(sys/sendfile.h,result=yes,result=no)
201
202 if test "$result" = "yes"; then
203         AC_MSG_CHECKING([for Linux sendfile()])
204         AC_TRY_COMPILE([
205 #if HAVE_SYS_SOCKET_H
206 #include <sys/socket.h>
207 #endif
208
209 #if HAVE_SYS_LIMITS_H
210 #include <sys/limits.h>
211 #endif
212
213 #if HAVE_UNISTD_H
214 #include <unistd.h>
215 #endif
216
217 #if HAVE_SYS_SENDFILE_H
218 #include <sys/sendfile.h>
219 #endif
220
221 #if HAVE_SYS_TYPES_H
222 #include <sys/types.h>
223 #endif
224
225 #if HAVE_ERRNO_H
226 #include <errno.h>
227 #endif
228
229 #if HAVE_SYS_UIO_H
230 #include <sys/uio.h>
231 #endif
232 ],[
233         int out_fd = 1, in_fd = 0;
234         off_t offset = 0;
235         size_t size = 1024;
236
237         sendfile(out_fd, in_fd, &offset, size);
238 ],enableval=yes,enableval=no)
239         AC_MSG_RESULT($enableval)
240
241         if test "$enableval" = "yes"; then
242                 dnl
243                 dnl If the compile fails now, we assume sendfile() exists (since this
244                 dnl is by far the most common case)
245                 dnl
246                 AC_MSG_CHECKING([that sendfile() really is implemented])
247
248                 AC_TRY_RUN([
249 #if HAVE_SYS_SOCKET_H
250 #include <sys/socket.h>
251 #endif
252
253 #if HAVE_SYS_LIMITS_H
254 #include <sys/limits.h>
255 #endif
256
257 #if HAVE_UNISTD_H
258 #include <unistd.h>
259 #endif
260
261 #if HAVE_SYS_SENDFILE_H
262 #include <sys/sendfile.h>
263 #endif
264
265 #if HAVE_SYS_TYPES_H
266 #include <sys/types.h>
267 #endif
268
269 #if HAVE_ERRNO_H
270 #include <errno.h>
271 #endif
272
273 #if HAVE_SYS_UIO_H
274 #include <sys/uio.h>
275 #endif
276
277 int main() {
278         int out_fd = 1, in_fd = 0;
279         off_t offset = 0;
280         size_t size = 1024;
281
282         errno = 0;
283         sendfile(out_fd, in_fd, &offset, size);
284         if (errno == ENOSYS)
285                 return 0;
286         else
287                 return 1;
288 }],
289                 enableval=no,enableval=yes,[enableval="cross-compiling, not checked"])
290                 AC_MSG_RESULT($enableval)
291
292                 has_sendfile=$enableval
293
294                 dnl
295                 dnl Force sendfile() `state' if the user tells us to
296                 dnl
297                 AC_ARG_WITH(linux-sendfile,[  --with-linux-sendfile   Force sendfile() support],has_sendfile=$withval)
298
299                 if test $has_sendfile != "no"; then
300                         AC_DEFINE(HAVE_LINUX_SENDFILE, 1, [Define if you have sendfile() with the Linux semantics.])
301                         has_sendfile=enabled
302                 else
303                         has_sendfile=disabled
304                 fi
305                 AC_MSG_CHECKING([final status of Linux sendfile() support])
306                 AC_MSG_RESULT($has_sendfile)
307         fi
308 fi
309
310 AC_CHECK_HEADER(sys/uio.h,result=yes,result=no)
311 if test "$result" = "yes"; then
312         AC_MSG_CHECKING([for BSD sendfile()])
313         AC_TRY_COMPILE([
314 #if HAVE_SYS_LIMITS_H
315 #include <sys/limits.h>
316 #endif
317
318 #if HAVE_UNISTD_H
319 #include <unistd.h>
320 #endif
321
322 #if HAVE_SYS_SENDFILE_H
323 #include <sys/sendfile.h>
324 #endif
325
326 #if HAVE_SYS_TYPES_H
327 #include <sys/types.h>
328 #endif
329
330 #if HAVE_SYS_SOCKET_H
331 #include <sys/socket.h>
332 #endif
333
334 #if HAVE_SYS_UIO_H
335 #include <sys/uio.h>
336 #endif
337 ],[
338         int in_fd = 0, out_sock = 3;
339         off_t offset;
340         size_t size = 1024;
341         struct sf_hdtr hdtr;
342
343         hdtr.hdr_cnt = 0;
344         hdtr.trl_cnt = 0;
345
346         sendfile(in_fd, out_sock, offset, size, &hdtr, &offset, 0);
347 ],enableval=yes,enableval=no)
348         AC_MSG_RESULT($enableval)
349
350         if test "$enableval" = "yes"; then
351                 AC_DEFINE(HAVE_BSD_SENDFILE, 1, [Define if you have sendfile() with the BSD semantics.])
352         fi
353 fi
354
355 AC_OUTPUT(Makefile)