]> git.sesse.net Git - betaftpd/blob - configure.in
Updated documentation to tell that root can't FTP anymore.
[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 (implies --disable-shadow)],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_HEADER(linux/socket.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 AC_CHECK_HEADER(sys/sendfile.h,result=yes,result=no)
198
199 dnl
200 dnl For some reason, we have to check it AGAIN... Otherwise it's never defined!
201 dnl
202 AC_CHECK_HEADERS(sys/sendfile.h)
203
204 if test "$result" = "yes"; then
205         AC_MSG_CHECKING([for Linux sendfile()])
206         AC_TRY_COMPILE([
207 #if HAVE_SYS_SOCKET_H
208 #include <sys/socket.h>
209 #endif
210
211 #if HAVE_SYS_LIMITS_H
212 #include <sys/limits.h>
213 #endif
214
215 #if HAVE_UNISTD_H
216 #include <unistd.h>
217 #endif
218
219 #if HAVE_SYS_SENDFILE_H
220 #include <sys/sendfile.h>
221 #endif
222
223 #if HAVE_SYS_TYPES_H
224 #include <sys/types.h>
225 #endif
226
227 #if HAVE_SYS_UIO_H
228 #include <sys/uio.h>
229 #endif],[
230         int out_fd = 1, in_fd = 0;
231         off_t offset = 0;
232         size_t size = 1024;
233
234         sendfile(out_fd, in_fd, &offset, size);
235 ],enableval=yes,enableval=no)
236         AC_MSG_RESULT($enableval)
237
238         if test "$enableval" = "yes"; then
239                 AC_DEFINE(HAVE_LINUX_SENDFILE, 1, [Define if you have sendfile() with the Linux semantics.])
240         fi
241 fi
242
243 AC_CHECK_HEADER(sys/uio.h,result=yes,result=no)
244 if test "$result" = "yes"; then
245         AC_MSG_CHECKING([for BSD sendfile()])
246         AC_TRY_COMPILE([
247 #if HAVE_SYS_LIMITS_H
248 #include <sys/limits.h>
249 #endif
250
251 #if HAVE_UNISTD_H
252 #include <unistd.h>
253 #endif
254
255 #if HAVE_SYS_SENDFILE_H
256 #include <sys/sendfile.h>
257 #endif
258
259 #if HAVE_SYS_TYPES_H
260 #include <sys/types.h>
261 #endif
262
263 #if HAVE_SYS_SOCKET_H
264 #include <sys/socket.h>
265 #endif
266
267 #if HAVE_SYS_UIO_H
268 #include <sys/uio.h>
269 #endif
270 ],[
271         int in_fd = 0, out_sock = 3;
272         off_t offset;
273         size_t size = 1024;
274         struct sf_hdtr hdtr;
275
276         hdtr.hdr_cnt = 0;
277         hdtr.trl_cnt = 0;
278
279         sendfile(in_fd, out_sock, offset, size, &hdtr, &offset, 0);
280 ],enableval=yes,enableval=no)
281         AC_MSG_RESULT($enableval)
282
283         if test "$enableval" = "yes"; then
284                 AC_DEFINE(HAVE_BSD_SENDFILE, 1, [Define if you have sendfile() with the BSD semantics.])
285         fi
286 fi
287
288 AC_OUTPUT(Makefile)