ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libptytty/ptytty.m4
Revision: 1.13
Committed: Sun Nov 4 10:16:58 2007 UTC (16 years, 6 months ago) by ayin
Branch: MAIN
Changes since 1.12: +0 -3 lines
Log Message:
Detect if LASTLOG_FILE is a directory or a file at runtime.

File Contents

# User Rev Content
1 root 1.2 dnl this file is part of libptytty, do not make local modifications
2     dnl http://software.schmorp.de/pkg/libptytty
3    
4 ayin 1.1 AC_DEFUN([PTY_CHECK],
5     [
6     AC_CHECK_HEADERS( \
7     pty.h \
8     util.h \
9     libutil.h \
10     sys/ioctl.h \
11     sys/stropts.h \
12     )
13    
14     AC_CHECK_FUNCS( \
15     revoke \
16     _getpty \
17     getpt \
18     posix_openpt \
19     isastream \
20 root 1.7 setuid \
21     seteuid \
22     setreuid \
23     setresuid \
24 ayin 1.1 )
25    
26     have_clone=no
27    
28     AC_MSG_CHECKING(for /dev/ptym/clone)
29     if test -e /dev/ptym/clone; then
30     AC_MSG_RESULT(yes)
31     AC_DEFINE(HAVE_DEV_CLONE, 1, [Define to 1 if you have /dev/ptym/clone])
32     AC_DEFINE(CLONE_DEVICE, "/dev/ptym/clone", [clone device filename])
33     have_clone=yes
34     else
35     AC_MSG_RESULT(no)
36     fi
37    
38     AC_MSG_CHECKING(for /dev/ptc)
39     if test -e /dev/ptc; then
40     AC_MSG_RESULT(yes)
41     AC_DEFINE(HAVE_DEV_PTC, 1, [Define to 1 if you have /dev/ptc])
42     AC_DEFINE(CLONE_DEVICE, "/dev/ptc", [clone device filename])
43     have_clone=yes
44     else
45     AC_MSG_RESULT(no)
46     fi
47    
48     case $host in
49     *-*-cygwin*)
50     have_clone=yes
51     AC_DEFINE(CLONE_DEVICE, "/dev/ptmx", [clone device filename])
52     ;;
53     *)
54     AC_MSG_CHECKING(for /dev/ptmx)
55     if test -e /dev/ptmx; then
56     AC_MSG_RESULT(yes)
57     AC_DEFINE(HAVE_DEV_PTMX, 1, [Define to 1 if you have /dev/ptmx])
58     AC_DEFINE(CLONE_DEVICE, "/dev/ptmx", [clone device filename])
59     have_clone=yes
60     else
61     AC_MSG_RESULT(no)
62     fi
63     ;;
64     esac
65    
66     if test x$ac_cv_func_getpt = xyes -o x$ac_cv_func_posix_openpt = xyes -o x$have_clone = xyes; then
67     AC_MSG_CHECKING(for UNIX98 ptys)
68     AC_TRY_LINK([#include <stdlib.h>],
69     [grantpt(0);unlockpt(0);ptsname(0);],
70     [unix98_pty=yes
71     AC_DEFINE(UNIX98_PTY, 1, "")
72     AC_MSG_RESULT(yes)],
73     [AC_MSG_RESULT(no)])
74     fi
75    
76     if test -z "$unix98_pty"; then
77     AC_CHECK_FUNCS(openpty, [], [AC_CHECK_LIB(util, openpty, [AC_DEFINE(HAVE_OPENPTY) LIBS="$LIBS -lutil"])])
78     fi
79     ])
80    
81     AC_DEFUN([UTMP_CHECK],
82     [
83 ayin 1.5 support_utmp=yes
84     support_wtmp=yes
85     support_lastlog=yes
86    
87 ayin 1.4 AC_ARG_ENABLE(utmp,
88 ayin 1.11 [AS_HELP_STRING([--enable-utmp],[enable utmp (utmpx) support])],
89 ayin 1.4 [if test x$enableval = xyes -o x$enableval = xno; then
90     support_utmp=$enableval
91     fi])
92    
93     AC_ARG_ENABLE(wtmp,
94 ayin 1.11 [AS_HELP_STRING([--enable-wtmp],[enable wtmp (wtmpx) support (requires --enable-utmp)])],
95 ayin 1.4 [if test x$enableval = xyes -o x$enableval = xno; then
96     support_wtmp=$enableval
97     fi])
98    
99     AC_ARG_ENABLE(lastlog,
100 ayin 1.11 [AS_HELP_STRING([--enable-lastlog],[enable lastlog support (requires --enable-utmp)])],
101 ayin 1.4 [if test x$enableval = xyes -o x$enableval = xno; then
102     support_lastlog=$enableval
103     fi])
104    
105     if test x$support_utmp = xyes; then
106     AC_DEFINE(UTMP_SUPPORT, 1, Define if you want to have utmp/utmpx support)
107     fi
108     if test x$support_wtmp = xyes; then
109     AC_DEFINE(WTMP_SUPPORT, 1, Define if you want to have wtmp support when utmp/utmpx is enabled)
110     fi
111     if test x$support_lastlog = xyes; then
112     AC_DEFINE(LASTLOG_SUPPORT, 1, Define if you want to have lastlog support when utmp/utmpx is enabled)
113     fi
114    
115 ayin 1.1 AC_CHECK_FUNCS( \
116     ttyslot \
117     updwtmp \
118     updwtmpx \
119 ayin 1.12 updlastlogx \
120 ayin 1.1 )
121    
122     AC_CHECK_HEADERS( \
123     utmp.h \
124     utmpx.h \
125     lastlog.h \
126     )
127    
128     dnl# --------------------------------------------------------------------------
129     dnl# DO ALL UTMP AND WTMP CHECKING
130     dnl# --------------------------------------------------------------------------
131     dnl# check for host field in utmp structure
132    
133     dnl# --------------------------------------------
134     AC_CHECK_HEADER(utmp.h,
135     [AC_CACHE_CHECK([for struct utmp], struct_utmp,
136     [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
137     #include <utmp.h>]], [[struct utmp ut;]])],[struct_utmp=yes],[struct_utmp=no])])
138     if test x$struct_utmp = xyes; then
139     AC_DEFINE(HAVE_STRUCT_UTMP, 1, Define if utmp.h has struct utmp)
140     fi
141     ]
142    
143     AC_CACHE_CHECK(for ut_host in utmp struct, struct_utmp_host,
144     [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
145     #include <utmp.h>]], [[struct utmp ut; ut.ut_host;]])],[struct_utmp_host=yes],[struct_utmp_host=no])])
146     if test x$struct_utmp_host = xyes; then
147     AC_DEFINE(HAVE_UTMP_HOST, 1, Define if struct utmp contains ut_host)
148     fi
149    
150     AC_CACHE_CHECK(for ut_pid in utmp struct, struct_utmp_pid,
151     [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
152     #include <utmp.h>]], [[struct utmp ut; ut.ut_pid;]])],[struct_utmp_pid=yes],[struct_utmp_pid=no])])
153     if test x$struct_utmp_pid = xyes; then
154     AC_DEFINE(HAVE_UTMP_PID, 1, Define if struct utmp contains ut_pid)
155     fi
156     ) dnl# AC_CHECK_HEADER(utmp.h
157    
158     dnl# --------------------------------------------
159    
160     AC_CHECK_HEADER(utmpx.h,
161     [AC_CACHE_CHECK([for struct utmpx], struct_utmpx,
162     [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
163     #include <utmpx.h>]], [[struct utmpx ut;]])],[struct_utmpx=yes],[struct_utmpx=no])])
164     if test x$struct_utmpx = xyes; then
165     AC_DEFINE(HAVE_STRUCT_UTMPX, 1, Define if utmpx.h has struct utmpx)
166     fi
167     ]
168    
169     AC_CACHE_CHECK(for host in utmpx struct, struct_utmpx_host,
170     [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
171     #include <utmpx.h>]], [[struct utmpx utx; utx.ut_host;]])],[struct_utmpx_host=yes],[struct_utmpx_host=no])])
172     if test x$struct_utmpx_host = xyes; then
173     AC_DEFINE(HAVE_UTMPX_HOST, 1, Define if struct utmpx contains ut_host)
174     fi
175    
176     AC_CACHE_CHECK(for session in utmpx struct, struct_utmpx_session,
177     [AC_TRY_COMPILE([#include <sys/types.h>
178     #include <utmpx.h>],
179     [struct utmpx utx; utx.ut_session;],
180     struct_utmpx_session=yes, struct_utmpx_session=no)])
181     if test x$struct_utmpx_session = xyes; then
182     AC_DEFINE(HAVE_UTMPX_SESSION, 1, Define if struct utmpx contains ut_session)
183     fi
184     ) dnl# AC_CHECK_HEADER(utmpx.h
185    
186     dnl# --------------------------------------------------------------------------
187     dnl# check for struct lastlog
188     AC_CACHE_CHECK(for struct lastlog, struct_lastlog,
189     [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
190     #include <utmp.h>
191     #ifdef HAVE_LASTLOG_H
192     #include <lastlog.h>
193     #endif
194     ]], [[struct lastlog ll;]])],[struct_lastlog=yes],[struct_lastlog=no])])
195     if test x$struct_lastlog = xyes; then
196     AC_DEFINE(HAVE_STRUCT_LASTLOG, 1, Define if utmp.h or lastlog.h has struct lastlog)
197     fi
198    
199     dnl# check for struct lastlogx
200     AC_CACHE_CHECK(for struct lastlogx, struct_lastlogx,
201     [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
202     #include <utmpx.h>
203     #ifdef HAVE_LASTLOG_H
204     #include <lastlog.h>
205     #endif
206     ]], [[struct lastlogx ll;]])],[struct_lastlogx=yes],[struct_lastlogx=no])])
207     if test x$struct_lastlogx = xyes; then
208     AC_DEFINE(HAVE_STRUCT_LASTLOGX, 1, Define if utmpx.h or lastlog.h has struct lastlogx)
209     fi
210    
211     dnl# --------------------------------------------------------------------------
212     dnl# FIND FILES
213     dnl# --------------------------------------------------------------------------
214    
215     dnl# find utmp
216     AC_CACHE_CHECK(where utmp is located, path_utmp,
217     [AC_RUN_IFELSE([AC_LANG_SOURCE([[#include <stdio.h>
218 ayin 1.9 #include <stdlib.h>
219 ayin 1.1 #include <sys/types.h>
220     #include <utmp.h>
221     #include <errno.h>
222     main()
223     {
224     char **u, *utmplist[] = {
225     "/var/run/utmp", "/var/adm/utmp", "/etc/utmp", "/usr/etc/utmp", "/usr/adm/utmp", NULL };
226     FILE *a, *f=fopen("conftestval", "w");
227     if (!f) exit(1);
228     #ifdef UTMP_FILE
229     fprintf(f, "%s\n", UTMP_FILE);
230     exit(0);
231     #endif
232     #ifdef _PATH_UTMP
233     fprintf(f, "%s\n", _PATH_UTMP);
234     exit(0);
235     #endif
236     for (u = utmplist; *u; u++) {
237     if ((a = fopen(*u, "r")) != NULL || errno == EACCES) {
238     fprintf(f, "%s\n", *u);
239     exit(0);
240     }
241     }
242     exit(0);
243     }]])],[path_utmp=`cat conftestval`],[path_utmp=],[dnl
244     AC_MSG_WARN(Define UTMP_FILE in config.h manually)])])
245     if test x$path_utmp != x; then
246     AC_DEFINE_UNQUOTED(UTMP_FILE, "$path_utmp", Define location of utmp)
247     fi
248    
249     dnl# --------------------------------------------------------------------------
250    
251     dnl# find utmpx - if a utmp file exists at the same location and is more than
252     dnl# a day newer, then dump the utmpx. People leave lots of junk around.
253     AC_CACHE_CHECK(where utmpx is located, path_utmpx,
254     [AC_RUN_IFELSE([AC_LANG_SOURCE([[#include <stdio.h>
255 ayin 1.9 #include <stdlib.h>
256 ayin 1.1 #include <sys/types.h>
257     #include <utmpx.h>
258     #include <errno.h>
259     #include <sys/stat.h>
260     #ifdef HAVE_STRING_H
261     #include <string.h>
262     #endif
263     main()
264     {
265     char **u, *p, *utmplist[] = {
266     #ifdef UTMPX_FILE
267     UTMPX_FILE,
268     #endif
269     #ifdef _PATH_UTMPX
270     _PATH_UTMPX,
271     #endif
272     "/var/adm/utmpx", "/etc/utmpx", NULL };
273     FILE *a, *f=fopen("conftestval", "w");
274     struct stat statu, statux;
275     if (!f) exit(1);
276     for (u = utmplist; *u; u++) {
277     if ((a = fopen(*u, "r")) != NULL || errno == EACCES) {
278     if (stat(*u, &statux) < 0)
279     continue;
280     p = strdup(*u);
281     p[strlen(p) - 1] = '\0';
282     if (stat(p, &statu) >= 0
283     && (statu.st_mtime - statux.st_mtime > 86400))
284     continue;
285     fprintf(f, "%s\n", *u);
286     exit(0);
287     }
288     }
289     exit(0);
290     }]])],[path_utmpx=`cat conftestval`],[path_utmpx=],[dnl
291     AC_MSG_WARN(Define UTMPX_FILE in config.h manually)])])
292     if test x$path_utmpx != x; then
293     AC_DEFINE_UNQUOTED(UTMPX_FILE, "$path_utmpx", Define location of utmpx)
294     fi
295    
296     dnl# --------------------------------------------------------------------------
297    
298     dnl# find wtmp
299     AC_CACHE_CHECK(where wtmp is located, path_wtmp,
300     [AC_RUN_IFELSE([AC_LANG_SOURCE([[#include <stdio.h>
301 ayin 1.9 #include <stdlib.h>
302 ayin 1.1 #include <sys/types.h>
303     #ifdef HAVE_UTMP_H
304     #include <utmp.h>
305     #endif
306     #include <errno.h>
307     main()
308     {
309     char **w, *wtmplist[] = {
310 ayin 1.10 "/var/log/wtmp", "/var/adm/wtmp", "/etc/wtmp", "/usr/etc/wtmp", "/usr/adm/wtmp", NULL };
311 ayin 1.1 FILE *a, *f=fopen("conftestval", "w");
312     if (!f) exit(1);
313     #ifdef WTMP_FILE
314     fprintf(f, "%s\n", WTMP_FILE);
315     exit(0);
316     #endif
317     #ifdef _PATH_WTMP
318     fprintf(f, "%s\n", _PATH_WTMP);
319     exit(0);
320     #endif
321     for (w = wtmplist; *w; w++) {
322     if ((a = fopen(*w, "r")) != NULL || errno == EACCES) {
323     fprintf(f, "%s\n", *w);
324     exit(0);
325     }
326     }
327     exit(0);
328     }]])],[path_wtmp=`cat conftestval`],[path_wtmp=],[dnl
329     AC_MSG_WARN(Define WTMP_FILE in config.h manually)])])
330     if test x$path_wtmp != x; then
331     AC_DEFINE_UNQUOTED(WTMP_FILE, "$path_wtmp", Define location of wtmp)
332     fi
333     dnl# --------------------------------------------------------------------------
334    
335     dnl# find wtmpx
336     AC_CACHE_CHECK(where wtmpx is located, path_wtmpx,
337     [AC_RUN_IFELSE([AC_LANG_SOURCE([[#include <stdio.h>
338 ayin 1.9 #include <stdlib.h>
339 ayin 1.1 #ifdef HAVE_UTMPX_H
340     #include <utmpx.h>
341     #endif
342     #include <errno.h>
343     main()
344     {
345     char **w, *wtmplist[] = {
346 ayin 1.10 "/var/log/wtmpx", "/var/adm/wtmpx", NULL };
347 ayin 1.1 FILE *a, *f=fopen("conftestval", "w");
348     if (!f) exit(1);
349     #ifdef WTMPX_FILE
350     fprintf(f, "%s\n", WTMPX_FILE);
351     exit(0);
352     #endif
353     #ifdef _PATH_WTMPX
354     fprintf(f, "%s\n", _PATH_WTMPX);
355     exit(0);
356     #endif
357     for (w = wtmplist; *w; w++) {
358     if ((a = fopen(*w, "r")) != NULL || errno == EACCES) {
359     fprintf(f, "%s\n", *w);
360     exit(0);
361     }
362     }
363     exit(0);
364     }]])],[path_wtmpx=`cat conftestval`],[path_wtmpx=],[dnl
365     AC_MSG_WARN(Define WTMPX_FILE in config.h manually)])])
366     if test x$path_wtmpx != x; then
367     AC_DEFINE_UNQUOTED(WTMPX_FILE, "$path_wtmpx", Define location of wtmpx)
368     fi
369     dnl# --------------------------------------------------------------------------
370    
371     dnl# find lastlog
372     AC_CACHE_CHECK(where lastlog is located, path_lastlog,
373     [AC_RUN_IFELSE([AC_LANG_SOURCE([[#include <stdio.h>
374 ayin 1.9 #include <stdlib.h>
375 ayin 1.1 #include <sys/types.h>
376     #ifdef HAVE_UTMPX_H
377     #include <utmpx.h>
378     #elif defined(HAVE_UTMP_H)
379     #include <utmp.h>
380     #endif
381     #ifdef HAVE_LASTLOG_H
382     #include <lastlog.h>
383     #endif
384     #include <errno.h>
385     main()
386     {
387     char **w, *lastloglist[] = { "/var/log/lastlog", NULL };
388     FILE *a, *f=fopen("conftestval", "w");
389     if (!f) exit(1);
390     #ifdef LASTLOG_FILE
391     fprintf(f, "%s\n", LASTLOG_FILE);
392     exit(0);
393     #endif
394     #ifdef _PATH_LASTLOG
395     fprintf(f, "%s\n", _PATH_LASTLOG);
396     exit(0);
397     #endif
398     for (w = lastloglist; *w; w++) {
399     if ((a = fopen(*w, "r")) != NULL || errno == EACCES) {
400     fprintf(f, "%s\n", *w);
401     exit(0);
402     }
403     }
404     exit(0);
405     }]])],[path_lastlog=`cat conftestval`],[path_lastlog=],[dnl
406     AC_MSG_WARN(Define LASTLOG_FILE in config.h manually)])])
407     if test x$path_lastlog != x; then
408     AC_DEFINE_UNQUOTED(LASTLOG_FILE, "$path_lastlog", Define location of lastlog)
409     fi
410     dnl# --------------------------------------------------------------------------
411    
412     dnl# find lastlogx
413     AC_CACHE_CHECK(where lastlogx is located, path_lastlogx,
414     [AC_RUN_IFELSE([AC_LANG_SOURCE([[#include <stdio.h>
415 ayin 1.9 #include <stdlib.h>
416 ayin 1.1 #ifdef HAVE_UTMPX_H
417     #include <utmpx.h>
418     #endif
419     #include <errno.h>
420     main()
421     {
422     char **w, *wtmplist[] = { "/var/log/lastlogx", "/var/adm/lastlogx", NULL };
423     FILE *a, *f=fopen("conftestval", "w");
424     if (!f) exit(1);
425     #ifdef LASTLOGX_FILE
426     fprintf(f, "%s\n", LASTLOGX_FILE);
427     exit(0);
428     #endif
429     #ifdef _PATH_LASTLOGX
430     fprintf(f, "%s\n", _PATH_LASTLOGX);
431     exit(0);
432     #endif
433     for (w = wtmplist; *w; w++) {
434     if ((a = fopen(*w, "r")) != NULL || errno == EACCES) {
435     fprintf(f, "%s\n", *w);
436     exit(0);
437     }
438     }
439     exit(0);
440     }]])],[path_lastlogx=`cat conftestval`],[path_lastlogx=],[dnl
441     AC_MSG_WARN(Define LASTLOGX_FILE in config.h manually)])])
442     if test x$path_lastlogx != x; then
443     AC_DEFINE_UNQUOTED(LASTLOGX_FILE, "$path_lastlogx", Define location of lastlogx)
444     fi
445     ])
446    
447     AC_DEFUN([SCM_RIGHTS_CHECK],
448     [
449     AC_CACHE_CHECK(for unix-compliant filehandle passing ability, can_pass_fds,
450     [AC_TRY_LINK([
451 root 1.6 #include <cstddef> // broken bsds (is that redundant?) need this
452 ayin 1.1 #include <sys/types.h>
453     #include <sys/socket.h>
454     #include <sys/uio.h>
455     ],[
456     {
457     msghdr msg;
458     iovec iov;
459     char buf [100];
460     char data = 0;
461    
462     iov.iov_base = &data;
463     iov.iov_len = 1;
464    
465     msg.msg_iov = &iov;
466     msg.msg_iovlen = 1;
467     msg.msg_control = buf;
468     msg.msg_controllen = sizeof buf;
469    
470     cmsghdr *cmsg = CMSG_FIRSTHDR (&msg);
471     cmsg->cmsg_level = SOL_SOCKET;
472     cmsg->cmsg_type = SCM_RIGHTS;
473     cmsg->cmsg_len = 100;
474    
475     *(int *)CMSG_DATA (cmsg) = 5;
476    
477     return sendmsg (3, &msg, 0);
478     }
479     ],[can_pass_fds=yes],[can_pass_fds=no])])
480     if test x$can_pass_fds = xyes; then
481     AC_DEFINE(HAVE_UNIX_FDPASS, 1, Define if sys/socket.h defines the necessary macros/functions for file handle passing)
482     else
483     AC_MSG_ERROR([libptytty requires unix-compliant filehandle passing ability])
484     fi
485     ])
486 ayin 1.3
487     AC_DEFUN([TTY_GROUP_CHECK],
488     [
489     AC_CACHE_CHECK([for tty group], tty_group,
490     [AC_TRY_RUN([
491     #include <sys/types.h>
492     #include <sys/stat.h>
493     #include <unistd.h>
494     #include <grp.h>
495    
496     main()
497     {
498     struct stat st;
499     struct group *gr;
500     char *tty;
501     gr = getgrnam("tty");
502     tty = ttyname(0);
503     if (gr != 0
504     && tty != 0
505     && (stat(tty, &st)) == 0
506     && st.st_gid == gr->gr_gid)
507     return 0;
508     else
509     return 1;
510     }],
511     [tty_group=yes],[tty_group=no],[tty_group=no])])
512     if test x$tty_group = xyes; then
513     AC_DEFINE(TTY_GID_SUPPORT, 1, "")
514     fi])
515