crypt(3) is used in the plain password file.

In addition, ocpasswd program was added to generate password file entries.
This commit is contained in:
Nikos Mavrogiannopoulos
2013-03-14 19:43:03 +01:00
parent 8d6af501c0
commit 0be2b2a054
40 changed files with 3358 additions and 45 deletions

3
.gitignore vendored
View File

@@ -31,3 +31,6 @@ gl/sys/types.h
src/version.def src/version.def
gl/stdio.h gl/stdio.h
gl/stdlib.h gl/stdlib.h
gl/sys/stat.h
gl/sys/time.h
gl/sys/types.h

3
NEWS
View File

@@ -3,6 +3,9 @@
- Corrected issue with ocsp-response configuration field. - Corrected issue with ocsp-response configuration field.
- Added ability to specify multiple certificate and key pairs. - Added ability to specify multiple certificate and key pairs.
- Added support for TLS session tickets. - Added support for TLS session tickets.
- Added the "plain" authentication option, which allows a simple password
file format. The ocpasswd tool can be used to generate entries for this
file.
* Version 0.0.2 (released 2013-03-05) * Version 0.0.2 (released 2013-03-05)

2
TODO
View File

@@ -1,5 +1,3 @@
* Add a simple username/password back-end in addition to PAM
* Fix SIGHUP handling on the main server. * Fix SIGHUP handling on the main server.
* Think how the DTLS part can use better negotiation of algorithms and DTLS * Think how the DTLS part can use better negotiation of algorithms and DTLS

View File

@@ -57,6 +57,15 @@
/* Define to 1 when the gnulib module fcntl should be tested. */ /* Define to 1 when the gnulib module fcntl should be tested. */
#undef GNULIB_TEST_FCNTL #undef GNULIB_TEST_FCNTL
/* Define to 1 when the gnulib module fseek should be tested. */
#undef GNULIB_TEST_FSEEK
/* Define to 1 when the gnulib module fseeko should be tested. */
#undef GNULIB_TEST_FSEEKO
/* Define to 1 when the gnulib module fstat should be tested. */
#undef GNULIB_TEST_FSTAT
/* Define to 1 when the gnulib module getdelim should be tested. */ /* Define to 1 when the gnulib module getdelim should be tested. */
#undef GNULIB_TEST_GETDELIM #undef GNULIB_TEST_GETDELIM
@@ -69,6 +78,12 @@
/* Define to 1 when the gnulib module gettimeofday should be tested. */ /* Define to 1 when the gnulib module gettimeofday should be tested. */
#undef GNULIB_TEST_GETTIMEOFDAY #undef GNULIB_TEST_GETTIMEOFDAY
/* Define to 1 when the gnulib module lseek should be tested. */
#undef GNULIB_TEST_LSEEK
/* Define to 1 when the gnulib module malloc-posix should be tested. */
#undef GNULIB_TEST_MALLOC_POSIX
/* Define to 1 when the gnulib module memchr should be tested. */ /* Define to 1 when the gnulib module memchr should be tested. */
#undef GNULIB_TEST_MEMCHR #undef GNULIB_TEST_MEMCHR
@@ -78,6 +93,9 @@
/* Define to 1 when the gnulib module realloc-posix should be tested. */ /* Define to 1 when the gnulib module realloc-posix should be tested. */
#undef GNULIB_TEST_REALLOC_POSIX #undef GNULIB_TEST_REALLOC_POSIX
/* Define to 1 when the gnulib module strdup should be tested. */
#undef GNULIB_TEST_STRDUP
/* Define to 1 if you have the <bp-sym.h> header file. */ /* Define to 1 if you have the <bp-sym.h> header file. */
#undef HAVE_BP_SYM_H #undef HAVE_BP_SYM_H
@@ -93,6 +111,26 @@
/* Define to 1 if you have the `clock_settime' function. */ /* Define to 1 if you have the `clock_settime' function. */
#undef HAVE_CLOCK_SETTIME #undef HAVE_CLOCK_SETTIME
/* Define to 1 if you have the declaration of `fflush_unlocked', and to 0 if
you don't. */
#undef HAVE_DECL_FFLUSH_UNLOCKED
/* Define to 1 if you have the declaration of `flockfile', and to 0 if you
don't. */
#undef HAVE_DECL_FLOCKFILE
/* Define to 1 if you have the declaration of `fputs_unlocked', and to 0 if
you don't. */
#undef HAVE_DECL_FPUTS_UNLOCKED
/* Define to 1 if you have the declaration of `fseeko', and to 0 if you don't.
*/
#undef HAVE_DECL_FSEEKO
/* Define to 1 if you have the declaration of `funlockfile', and to 0 if you
don't. */
#undef HAVE_DECL_FUNLOCKFILE
/* Define to 1 if you have the declaration of `getc_unlocked', and to 0 if you /* Define to 1 if you have the declaration of `getc_unlocked', and to 0 if you
don't. */ don't. */
#undef HAVE_DECL_GETC_UNLOCKED #undef HAVE_DECL_GETC_UNLOCKED
@@ -105,10 +143,26 @@
don't. */ don't. */
#undef HAVE_DECL_GETLINE #undef HAVE_DECL_GETLINE
/* Define to 1 if you have the declaration of `getpass', and to 0 if you
don't. */
#undef HAVE_DECL_GETPASS
/* Define to 1 if you have the declaration of `memmem', and to 0 if you don't. /* Define to 1 if you have the declaration of `memmem', and to 0 if you don't.
*/ */
#undef HAVE_DECL_MEMMEM #undef HAVE_DECL_MEMMEM
/* Define to 1 if you have the declaration of `putc_unlocked', and to 0 if you
don't. */
#undef HAVE_DECL_PUTC_UNLOCKED
/* Define to 1 if you have the declaration of `strdup', and to 0 if you don't.
*/
#undef HAVE_DECL_STRDUP
/* Define to 1 if you have the declaration of `__fsetlocking', and to 0 if you
don't. */
#undef HAVE_DECL___FSETLOCKING
/* Define this if /dev/zero is readable device */ /* Define this if /dev/zero is readable device */
#undef HAVE_DEV_ZERO #undef HAVE_DEV_ZERO
@@ -143,6 +197,9 @@
/* Define to 1 if you have the `fork' function. */ /* Define to 1 if you have the `fork' function. */
#undef HAVE_FORK #undef HAVE_FORK
/* Define to 1 if fseeko (and presumably ftello) exists and is declared. */
#undef HAVE_FSEEKO
/* Define to 1 if you have the `fstat' function. */ /* Define to 1 if you have the `fstat' function. */
#undef HAVE_FSTAT #undef HAVE_FSTAT
@@ -158,6 +215,9 @@
/* Define to 1 if you have the `getdtablesize' function. */ /* Define to 1 if you have the `getdtablesize' function. */
#undef HAVE_GETDTABLESIZE #undef HAVE_GETDTABLESIZE
/* Define to 1 if you have the `getpass' function. */
#undef HAVE_GETPASS
/* Define to 1 if you have the `gettimeofday' function. */ /* Define to 1 if you have the `gettimeofday' function. */
#undef HAVE_GETTIMEOFDAY #undef HAVE_GETTIMEOFDAY
@@ -176,6 +236,9 @@
/* Define to 1 if you have the <inttypes.h> header file. */ /* Define to 1 if you have the <inttypes.h> header file. */
#undef HAVE_INTTYPES_H #undef HAVE_INTTYPES_H
/* Define if you have the libcrypt library. */
#undef HAVE_LIBCRYPT
/* Define to 1 if you have the `gen' library (-lgen). */ /* Define to 1 if you have the `gen' library (-lgen). */
#undef HAVE_LIBGEN #undef HAVE_LIBGEN
@@ -197,6 +260,9 @@
/* Define to 1 if the system has the type 'long long int'. */ /* Define to 1 if the system has the type 'long long int'. */
#undef HAVE_LONG_LONG_INT #undef HAVE_LONG_LONG_INT
/* Define if the 'malloc' function is POSIX compliant. */
#undef HAVE_MALLOC_POSIX
/* Define to 1 if mmap()'s MAP_ANONYMOUS flag is available after including /* Define to 1 if mmap()'s MAP_ANONYMOUS flag is available after including
config.h and <sys/mman.h>. */ config.h and <sys/mman.h>. */
#undef HAVE_MAP_ANONYMOUS #undef HAVE_MAP_ANONYMOUS
@@ -207,6 +273,12 @@
/* Define to 1 if you have the <memory.h> header file. */ /* Define to 1 if you have the <memory.h> header file. */
#undef HAVE_MEMORY_H #undef HAVE_MEMORY_H
/* Define to 1 if <limits.h> defines the MIN and MAX macros. */
#undef HAVE_MINMAX_IN_LIMITS_H
/* Define to 1 if <sys/param.h> defines the MIN and MAX macros. */
#undef HAVE_MINMAX_IN_SYS_PARAM_H
/* Define to 1 if you have the `mmap' function. */ /* Define to 1 if you have the `mmap' function. */
#undef HAVE_MMAP #undef HAVE_MMAP
@@ -278,6 +350,9 @@
/* Define to 1 if fchdir is declared even after undefining macros. */ /* Define to 1 if fchdir is declared even after undefining macros. */
#undef HAVE_RAW_DECL_FCHDIR #undef HAVE_RAW_DECL_FCHDIR
/* Define to 1 if fchmodat is declared even after undefining macros. */
#undef HAVE_RAW_DECL_FCHMODAT
/* Define to 1 if fchownat is declared even after undefining macros. */ /* Define to 1 if fchownat is declared even after undefining macros. */
#undef HAVE_RAW_DECL_FCHOWNAT #undef HAVE_RAW_DECL_FCHOWNAT
@@ -299,6 +374,12 @@
/* Define to 1 if fseeko is declared even after undefining macros. */ /* Define to 1 if fseeko is declared even after undefining macros. */
#undef HAVE_RAW_DECL_FSEEKO #undef HAVE_RAW_DECL_FSEEKO
/* Define to 1 if fstat is declared even after undefining macros. */
#undef HAVE_RAW_DECL_FSTAT
/* Define to 1 if fstatat is declared even after undefining macros. */
#undef HAVE_RAW_DECL_FSTATAT
/* Define to 1 if fsync is declared even after undefining macros. */ /* Define to 1 if fsync is declared even after undefining macros. */
#undef HAVE_RAW_DECL_FSYNC #undef HAVE_RAW_DECL_FSYNC
@@ -308,6 +389,9 @@
/* Define to 1 if ftruncate is declared even after undefining macros. */ /* Define to 1 if ftruncate is declared even after undefining macros. */
#undef HAVE_RAW_DECL_FTRUNCATE #undef HAVE_RAW_DECL_FTRUNCATE
/* Define to 1 if futimens is declared even after undefining macros. */
#undef HAVE_RAW_DECL_FUTIMENS
/* Define to 1 if getcwd is declared even after undefining macros. */ /* Define to 1 if getcwd is declared even after undefining macros. */
#undef HAVE_RAW_DECL_GETCWD #undef HAVE_RAW_DECL_GETCWD
@@ -368,6 +452,9 @@
/* Define to 1 if isatty is declared even after undefining macros. */ /* Define to 1 if isatty is declared even after undefining macros. */
#undef HAVE_RAW_DECL_ISATTY #undef HAVE_RAW_DECL_ISATTY
/* Define to 1 if lchmod is declared even after undefining macros. */
#undef HAVE_RAW_DECL_LCHMOD
/* Define to 1 if lchown is declared even after undefining macros. */ /* Define to 1 if lchown is declared even after undefining macros. */
#undef HAVE_RAW_DECL_LCHOWN #undef HAVE_RAW_DECL_LCHOWN
@@ -380,6 +467,9 @@
/* Define to 1 if lseek is declared even after undefining macros. */ /* Define to 1 if lseek is declared even after undefining macros. */
#undef HAVE_RAW_DECL_LSEEK #undef HAVE_RAW_DECL_LSEEK
/* Define to 1 if lstat is declared even after undefining macros. */
#undef HAVE_RAW_DECL_LSTAT
/* Define to 1 if memmem is declared even after undefining macros. */ /* Define to 1 if memmem is declared even after undefining macros. */
#undef HAVE_RAW_DECL_MEMMEM #undef HAVE_RAW_DECL_MEMMEM
@@ -389,9 +479,24 @@
/* Define to 1 if memrchr is declared even after undefining macros. */ /* Define to 1 if memrchr is declared even after undefining macros. */
#undef HAVE_RAW_DECL_MEMRCHR #undef HAVE_RAW_DECL_MEMRCHR
/* Define to 1 if mkdirat is declared even after undefining macros. */
#undef HAVE_RAW_DECL_MKDIRAT
/* Define to 1 if mkdtemp is declared even after undefining macros. */ /* Define to 1 if mkdtemp is declared even after undefining macros. */
#undef HAVE_RAW_DECL_MKDTEMP #undef HAVE_RAW_DECL_MKDTEMP
/* Define to 1 if mkfifo is declared even after undefining macros. */
#undef HAVE_RAW_DECL_MKFIFO
/* Define to 1 if mkfifoat is declared even after undefining macros. */
#undef HAVE_RAW_DECL_MKFIFOAT
/* Define to 1 if mknod is declared even after undefining macros. */
#undef HAVE_RAW_DECL_MKNOD
/* Define to 1 if mknodat is declared even after undefining macros. */
#undef HAVE_RAW_DECL_MKNODAT
/* Define to 1 if mkostemp is declared even after undefining macros. */ /* Define to 1 if mkostemp is declared even after undefining macros. */
#undef HAVE_RAW_DECL_MKOSTEMP #undef HAVE_RAW_DECL_MKOSTEMP
@@ -491,6 +596,9 @@
/* Define to 1 if srandom_r is declared even after undefining macros. */ /* Define to 1 if srandom_r is declared even after undefining macros. */
#undef HAVE_RAW_DECL_SRANDOM_R #undef HAVE_RAW_DECL_SRANDOM_R
/* Define to 1 if stat is declared even after undefining macros. */
#undef HAVE_RAW_DECL_STAT
/* Define to 1 if stpcpy is declared even after undefining macros. */ /* Define to 1 if stpcpy is declared even after undefining macros. */
#undef HAVE_RAW_DECL_STPCPY #undef HAVE_RAW_DECL_STPCPY
@@ -569,6 +677,9 @@
/* Define to 1 if usleep is declared even after undefining macros. */ /* Define to 1 if usleep is declared even after undefining macros. */
#undef HAVE_RAW_DECL_USLEEP #undef HAVE_RAW_DECL_USLEEP
/* Define to 1 if utimensat is declared even after undefining macros. */
#undef HAVE_RAW_DECL_UTIMENSAT
/* Define to 1 if vdprintf is declared even after undefining macros. */ /* Define to 1 if vdprintf is declared even after undefining macros. */
#undef HAVE_RAW_DECL_VDPRINTF #undef HAVE_RAW_DECL_VDPRINTF
@@ -614,6 +725,9 @@
/* Define to 1 if you have the <stdint.h> header file. */ /* Define to 1 if you have the <stdint.h> header file. */
#undef HAVE_STDINT_H #undef HAVE_STDINT_H
/* Define to 1 if you have the <stdio_ext.h> header file. */
#undef HAVE_STDIO_EXT_H
/* Define to 1 if you have the <stdlib.h> header file. */ /* Define to 1 if you have the <stdlib.h> header file. */
#undef HAVE_STDLIB_H #undef HAVE_STDLIB_H
@@ -700,6 +814,15 @@
/* Define to 1 if you have the <sys/wait.h> header file. */ /* Define to 1 if you have the <sys/wait.h> header file. */
#undef HAVE_SYS_WAIT_H #undef HAVE_SYS_WAIT_H
/* Define to 1 if you have the `tcgetattr' function. */
#undef HAVE_TCGETATTR
/* Define to 1 if you have the `tcsetattr' function. */
#undef HAVE_TCSETATTR
/* Define to 1 if you have the <termios.h> header file. */
#undef HAVE_TERMIOS_H
/* Define to 1 if the system has the type `uint16_t'. */ /* Define to 1 if the system has the type `uint16_t'. */
#undef HAVE_UINT16_T #undef HAVE_UINT16_T
@@ -766,12 +889,21 @@
/* Define to 1 if the system has the type `_Bool'. */ /* Define to 1 if the system has the type `_Bool'. */
#undef HAVE__BOOL #undef HAVE__BOOL
/* Define to 1 if you have the `_fseeki64' function. */
#undef HAVE__FSEEKI64
/* Define to 1 if you have the `_ftime' function. */ /* Define to 1 if you have the `_ftime' function. */
#undef HAVE__FTIME #undef HAVE__FTIME
/* Define to 1 if you have the `_set_invalid_parameter_handler' function. */ /* Define to 1 if you have the `_set_invalid_parameter_handler' function. */
#undef HAVE__SET_INVALID_PARAMETER_HANDLER #undef HAVE__SET_INVALID_PARAMETER_HANDLER
/* Define to 1 if you have the `__fsetlocking' function. */
#undef HAVE___FSETLOCKING
/* Define to 1 if lseek does not detect pipes. */
#undef LSEEK_PIPE_BROKEN
/* Define to a substitute value for mmap()'s MAP_ANONYMOUS flag. */ /* Define to a substitute value for mmap()'s MAP_ANONYMOUS flag. */
#undef MAP_ANONYMOUS #undef MAP_ANONYMOUS
@@ -835,6 +967,9 @@
'size_t'. */ 'size_t'. */
#undef SIZE_T_SUFFIX #undef SIZE_T_SUFFIX
/* Define to 1 if the `S_IS*' macros in <sys/stat.h> do not work properly. */
#undef STAT_MACROS_BROKEN
/* Define to 1 if you have the ANSI C header files. */ /* Define to 1 if you have the ANSI C header files. */
#undef STDC_HEADERS #undef STDC_HEADERS
@@ -896,6 +1031,22 @@
# endif # endif
#endif #endif
/* Enable large inode numbers on Mac OS X 10.5. */
#undef _DARWIN_USE_64_BIT_INODE
/* Number of bits in a file offset, on hosts where this is settable. */
#undef _FILE_OFFSET_BITS
/* Define to 1 if Gnulib overrides 'struct stat' on Windows so that struct
stat.st_size becomes 64-bit. */
#undef _GL_WINDOWS_64_BIT_ST_SIZE
/* Define to 1 to make fseeko visible on some hosts (e.g. glibc 2.2). */
#undef _LARGEFILE_SOURCE
/* Define for large files, on AIX-style hosts. */
#undef _LARGE_FILES
/* Define to 1 if on MINIX. */ /* Define to 1 if on MINIX. */
#undef _MINIX #undef _MINIX
@@ -997,6 +1148,9 @@
/* Define to `int' if <sys/types.h> does not define. */ /* Define to `int' if <sys/types.h> does not define. */
#undef mode_t #undef mode_t
/* Define to the type of st_nlink in struct stat, or a supertype. */
#undef nlink_t
/* Define to `int' if <sys/types.h> does not define. */ /* Define to `int' if <sys/types.h> does not define. */
#undef pid_t #undef pid_t

View File

@@ -1,5 +1,5 @@
AC_PREREQ(2.61) AC_PREREQ(2.61)
AC_INIT([ocserv], [0.0.2], [nmav@gnutls.org]) AC_INIT([ocserv], [0.0.3], [nmav@gnutls.org])
PKG_PROG_PKG_CONFIG PKG_PROG_PKG_CONFIG
AC_CONFIG_AUX_DIR([build-aux]) AC_CONFIG_AUX_DIR([build-aux])
AC_CONFIG_MACRO_DIR([m4]) AC_CONFIG_MACRO_DIR([m4])
@@ -79,6 +79,7 @@ LIBS="$oldlibs"
gl_INIT gl_INIT
AC_LIB_HAVE_LINKFLAGS(crypt,, [#include <unistd.h>], [crypt(0,0);])
AC_LIB_HAVE_LINKFLAGS(util,, [#include <utmpx.h>], [pututxline(0);]) AC_LIB_HAVE_LINKFLAGS(util,, [#include <utmpx.h>], [pututxline(0);])
AC_LIB_HAVE_LINKFLAGS(wrap,, [#include <tcpd.h>], [hosts_access(0);]) AC_LIB_HAVE_LINKFLAGS(wrap,, [#include <tcpd.h>], [hosts_access(0);])

View File

@@ -21,7 +21,7 @@
# the same distribution terms as the rest of that program. # the same distribution terms as the rest of that program.
# #
# Generated by gnulib-tool. # Generated by gnulib-tool.
# Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=gl --m4-base=gl/m4 --doc-base=doc --tests-base=gl/tests --aux-dir=build-aux --no-conditional-dependencies --no-libtool --macro-prefix=gl cloexec getline gettime memmem # Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=gl --m4-base=gl/m4 --doc-base=doc --tests-base=gl/tests --aux-dir=build-aux --no-conditional-dependencies --no-libtool --macro-prefix=gl cloexec getline getpass gettime memmem minmax
AUTOMAKE_OPTIONS = 1.5 gnits AUTOMAKE_OPTIONS = 1.5 gnits
@@ -161,6 +161,33 @@ EXTRA_DIST += fd-hook.h
## end gnulib module fd-hook ## end gnulib module fd-hook
## begin gnulib module fseek
EXTRA_DIST += fseek.c
EXTRA_libgnu_a_SOURCES += fseek.c
## end gnulib module fseek
## begin gnulib module fseeko
EXTRA_DIST += fseeko.c stdio-impl.h
EXTRA_libgnu_a_SOURCES += fseeko.c
## end gnulib module fseeko
## begin gnulib module fstat
EXTRA_DIST += fstat.c
EXTRA_libgnu_a_SOURCES += fstat.c
## end gnulib module fstat
## begin gnulib module getdelim ## begin gnulib module getdelim
@@ -188,6 +215,15 @@ EXTRA_libgnu_a_SOURCES += getline.c
## end gnulib module getline ## end gnulib module getline
## begin gnulib module getpass
EXTRA_DIST += getpass.c getpass.h
EXTRA_libgnu_a_SOURCES += getpass.c
## end gnulib module getpass
## begin gnulib module gettime ## begin gnulib module gettime
libgnu_a_SOURCES += gettime.c libgnu_a_SOURCES += gettime.c
@@ -203,6 +239,24 @@ EXTRA_libgnu_a_SOURCES += gettimeofday.c
## end gnulib module gettimeofday ## end gnulib module gettimeofday
## begin gnulib module lseek
EXTRA_DIST += lseek.c
EXTRA_libgnu_a_SOURCES += lseek.c
## end gnulib module lseek
## begin gnulib module malloc-posix
EXTRA_DIST += malloc.c
EXTRA_libgnu_a_SOURCES += malloc.c
## end gnulib module malloc-posix
## begin gnulib module memchr ## begin gnulib module memchr
@@ -221,6 +275,12 @@ EXTRA_libgnu_a_SOURCES += memmem.c
## end gnulib module memmem-simple ## end gnulib module memmem-simple
## begin gnulib module minmax
libgnu_a_SOURCES += minmax.h
## end gnulib module minmax
## begin gnulib module msvc-inval ## begin gnulib module msvc-inval
@@ -663,6 +723,15 @@ EXTRA_DIST += stdlib.in.h
## end gnulib module stdlib ## end gnulib module stdlib
## begin gnulib module strdup-posix
EXTRA_DIST += strdup.c
EXTRA_libgnu_a_SOURCES += strdup.c
## end gnulib module strdup-posix
## begin gnulib module string ## begin gnulib module string
BUILT_SOURCES += string.h BUILT_SOURCES += string.h
@@ -763,6 +832,68 @@ EXTRA_DIST += string.in.h
## end gnulib module string ## end gnulib module string
## begin gnulib module sys_stat
BUILT_SOURCES += sys/stat.h
# We need the following in order to create <sys/stat.h> when the system
# has one that is incomplete.
sys/stat.h: sys_stat.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H)
$(AM_V_at)$(MKDIR_P) sys
$(AM_V_GEN)rm -f $@-t $@ && \
{ echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
sed -e 's|@''GUARD_PREFIX''@|GL|g' \
-e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
-e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
-e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
-e 's|@''NEXT_SYS_STAT_H''@|$(NEXT_SYS_STAT_H)|g' \
-e 's|@''WINDOWS_64_BIT_ST_SIZE''@|$(WINDOWS_64_BIT_ST_SIZE)|g' \
-e 's/@''GNULIB_FCHMODAT''@/$(GNULIB_FCHMODAT)/g' \
-e 's/@''GNULIB_FSTAT''@/$(GNULIB_FSTAT)/g' \
-e 's/@''GNULIB_FSTATAT''@/$(GNULIB_FSTATAT)/g' \
-e 's/@''GNULIB_FUTIMENS''@/$(GNULIB_FUTIMENS)/g' \
-e 's/@''GNULIB_LCHMOD''@/$(GNULIB_LCHMOD)/g' \
-e 's/@''GNULIB_LSTAT''@/$(GNULIB_LSTAT)/g' \
-e 's/@''GNULIB_MKDIRAT''@/$(GNULIB_MKDIRAT)/g' \
-e 's/@''GNULIB_MKFIFO''@/$(GNULIB_MKFIFO)/g' \
-e 's/@''GNULIB_MKFIFOAT''@/$(GNULIB_MKFIFOAT)/g' \
-e 's/@''GNULIB_MKNOD''@/$(GNULIB_MKNOD)/g' \
-e 's/@''GNULIB_MKNODAT''@/$(GNULIB_MKNODAT)/g' \
-e 's/@''GNULIB_STAT''@/$(GNULIB_STAT)/g' \
-e 's/@''GNULIB_UTIMENSAT''@/$(GNULIB_UTIMENSAT)/g' \
-e 's|@''HAVE_FCHMODAT''@|$(HAVE_FCHMODAT)|g' \
-e 's|@''HAVE_FSTATAT''@|$(HAVE_FSTATAT)|g' \
-e 's|@''HAVE_FUTIMENS''@|$(HAVE_FUTIMENS)|g' \
-e 's|@''HAVE_LCHMOD''@|$(HAVE_LCHMOD)|g' \
-e 's|@''HAVE_LSTAT''@|$(HAVE_LSTAT)|g' \
-e 's|@''HAVE_MKDIRAT''@|$(HAVE_MKDIRAT)|g' \
-e 's|@''HAVE_MKFIFO''@|$(HAVE_MKFIFO)|g' \
-e 's|@''HAVE_MKFIFOAT''@|$(HAVE_MKFIFOAT)|g' \
-e 's|@''HAVE_MKNOD''@|$(HAVE_MKNOD)|g' \
-e 's|@''HAVE_MKNODAT''@|$(HAVE_MKNODAT)|g' \
-e 's|@''HAVE_UTIMENSAT''@|$(HAVE_UTIMENSAT)|g' \
-e 's|@''REPLACE_FSTAT''@|$(REPLACE_FSTAT)|g' \
-e 's|@''REPLACE_FSTATAT''@|$(REPLACE_FSTATAT)|g' \
-e 's|@''REPLACE_FUTIMENS''@|$(REPLACE_FUTIMENS)|g' \
-e 's|@''REPLACE_LSTAT''@|$(REPLACE_LSTAT)|g' \
-e 's|@''REPLACE_MKDIR''@|$(REPLACE_MKDIR)|g' \
-e 's|@''REPLACE_MKFIFO''@|$(REPLACE_MKFIFO)|g' \
-e 's|@''REPLACE_MKNOD''@|$(REPLACE_MKNOD)|g' \
-e 's|@''REPLACE_STAT''@|$(REPLACE_STAT)|g' \
-e 's|@''REPLACE_UTIMENSAT''@|$(REPLACE_UTIMENSAT)|g' \
-e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
-e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \
-e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \
< $(srcdir)/sys_stat.in.h; \
} > $@-t && \
mv $@-t $@
MOSTLYCLEANFILES += sys/stat.h sys/stat.h-t
MOSTLYCLEANDIRS += sys
EXTRA_DIST += sys_stat.in.h
## end gnulib module sys_stat
## begin gnulib module sys_time ## begin gnulib module sys_time
BUILT_SOURCES += sys/time.h BUILT_SOURCES += sys/time.h

30
gl/fseek.c Normal file
View File

@@ -0,0 +1,30 @@
/* An fseek() function that, together with fflush(), is POSIX compliant.
Copyright (C) 2007, 2009-2013 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include <config.h>
/* Specification. */
#include <stdio.h>
/* Get off_t. */
#include <unistd.h>
int
fseek (FILE *fp, long offset, int whence)
{
/* Use the replacement fseeko function with all its workarounds. */
return fseeko (fp, (off_t)offset, whence);
}

153
gl/fseeko.c Normal file
View File

@@ -0,0 +1,153 @@
/* An fseeko() function that, together with fflush(), is POSIX compliant.
Copyright (C) 2007-2013 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, see <http://www.gnu.org/licenses/>. */
#include <config.h>
/* Specification. */
#include <stdio.h>
/* Get off_t and lseek. */
#include <unistd.h>
#include "stdio-impl.h"
int
fseeko (FILE *fp, off_t offset, int whence)
#undef fseeko
#if !HAVE_FSEEKO
# undef fseek
# define fseeko fseek
#endif
#if _GL_WINDOWS_64_BIT_OFF_T
# undef fseeko
# if HAVE__FSEEKI64 /* msvc, mingw64 */
# define fseeko _fseeki64
# else /* mingw */
# define fseeko fseeko64
# endif
#endif
{
#if LSEEK_PIPE_BROKEN
/* mingw gives bogus answers rather than failure on non-seekable files. */
if (lseek (fileno (fp), 0, SEEK_CUR) == -1)
return EOF;
#endif
/* These tests are based on fpurge.c. */
#if defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
if (fp->_IO_read_end == fp->_IO_read_ptr
&& fp->_IO_write_ptr == fp->_IO_write_base
&& fp->_IO_save_base == NULL)
#elif defined __sferror || defined __DragonFly__ /* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin */
# if defined __SL64 && defined __SCLE /* Cygwin */
if ((fp->_flags & __SL64) == 0)
{
/* Cygwin 1.5.0 through 1.5.24 failed to open stdin in 64-bit
mode; but has an fseeko that requires 64-bit mode. */
FILE *tmp = fopen ("/dev/null", "r");
if (!tmp)
return -1;
fp->_flags |= __SL64;
fp->_seek64 = tmp->_seek64;
fclose (tmp);
}
# endif
if (fp_->_p == fp_->_bf._base
&& fp_->_r == 0
&& fp_->_w == ((fp_->_flags & (__SLBF | __SNBF | __SRD)) == 0 /* fully buffered and not currently reading? */
? fp_->_bf._size
: 0)
&& fp_ub._base == NULL)
#elif defined __EMX__ /* emx+gcc */
if (fp->_ptr == fp->_buffer
&& fp->_rcount == 0
&& fp->_wcount == 0
&& fp->_ungetc_count == 0)
#elif defined __minix /* Minix */
if (fp_->_ptr == fp_->_buf
&& (fp_->_ptr == NULL || fp_->_count == 0))
#elif defined _IOERR /* AIX, HP-UX, IRIX, OSF/1, Solaris, OpenServer, mingw, NonStop Kernel */
if (fp_->_ptr == fp_->_base
&& (fp_->_ptr == NULL || fp_->_cnt == 0))
#elif defined __UCLIBC__ /* uClibc */
if (((fp->__modeflags & __FLAG_WRITING) == 0
|| fp->__bufpos == fp->__bufstart)
&& ((fp->__modeflags & (__FLAG_READONLY | __FLAG_READING)) == 0
|| fp->__bufpos == fp->__bufread))
#elif defined __QNX__ /* QNX */
if ((fp->_Mode & 0x2000 /* _MWRITE */ ? fp->_Next == fp->_Buf : fp->_Next == fp->_Rend)
&& fp->_Rback == fp->_Back + sizeof (fp->_Back)
&& fp->_Rsave == NULL)
#elif defined __MINT__ /* Atari FreeMiNT */
if (fp->__bufp == fp->__buffer
&& fp->__get_limit == fp->__bufp
&& fp->__put_limit == fp->__bufp
&& !fp->__pushed_back)
#elif defined EPLAN9 /* Plan9 */
if (fp->rp == fp->buf
&& fp->wp == fp->buf)
#else
#error "Please port gnulib fseeko.c to your platform! Look at the code in fpurge.c, then report this to bug-gnulib."
#endif
{
/* We get here when an fflush() call immediately preceded this one (or
if ftell() has created buffers but no I/O has occurred on a
newly-opened stream). We know there are no buffers. */
off_t pos = lseek (fileno (fp), offset, whence);
if (pos == -1)
{
#if defined __sferror || defined __DragonFly__ /* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin */
fp_->_flags &= ~__SOFF;
#endif
return -1;
}
#if defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
fp->_flags &= ~_IO_EOF_SEEN;
fp->_offset = pos;
#elif defined __sferror || defined __DragonFly__ /* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin */
# if defined __CYGWIN__
/* fp_->_offset is typed as an integer. */
fp_->_offset = pos;
# else
/* fp_->_offset is an fpos_t. */
{
/* Use a union, since on NetBSD, the compilation flags
determine whether fpos_t is typedef'd to off_t or a struct
containing a single off_t member. */
union
{
fpos_t f;
off_t o;
} u;
u.o = pos;
fp_->_offset = u.f;
}
# endif
fp_->_flags |= __SOFF;
fp_->_flags &= ~__SEOF;
#elif defined __EMX__ /* emx+gcc */
fp->_flags &= ~_IOEOF;
#elif defined _IOERR /* AIX, HP-UX, IRIX, OSF/1, Solaris, OpenServer, mingw, NonStop Kernel */
fp->_flag &= ~_IOEOF;
#elif defined __MINT__ /* Atari FreeMiNT */
fp->__offset = pos;
fp->__eof = 0;
#endif
return 0;
}
return fseeko (fp, offset, whence);
}

88
gl/fstat.c Normal file
View File

@@ -0,0 +1,88 @@
/* fstat() replacement.
Copyright (C) 2011-2013 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* If the user's config.h happens to include <sys/stat.h>, let it include only
the system's <sys/stat.h> here, so that orig_fstat doesn't recurse to
rpl_fstat. */
#define __need_system_sys_stat_h
#include <config.h>
/* Get the original definition of fstat. It might be defined as a macro. */
#include <sys/types.h>
#include <sys/stat.h>
#if _GL_WINDOWS_64_BIT_ST_SIZE
# undef stat /* avoid warning on mingw64 with _FILE_OFFSET_BITS=64 */
# define stat _stati64
# undef fstat /* avoid warning on mingw64 with _FILE_OFFSET_BITS=64 */
# define fstat _fstati64
#endif
#undef __need_system_sys_stat_h
static int
orig_fstat (int fd, struct stat *buf)
{
return fstat (fd, buf);
}
/* Specification. */
/* Write "sys/stat.h" here, not <sys/stat.h>, otherwise OSF/1 5.1 DTK cc
eliminates this include because of the preliminary #include <sys/stat.h>
above. */
#include "sys/stat.h"
#include <errno.h>
#include <unistd.h>
#if HAVE_MSVC_INVALID_PARAMETER_HANDLER
# include "msvc-inval.h"
#endif
#if HAVE_MSVC_INVALID_PARAMETER_HANDLER
static int
fstat_nothrow (int fd, struct stat *buf)
{
int result;
TRY_MSVC_INVAL
{
result = orig_fstat (fd, buf);
}
CATCH_MSVC_INVAL
{
result = -1;
errno = EBADF;
}
DONE_MSVC_INVAL;
return result;
}
#else
# define fstat_nothrow orig_fstat
#endif
int
rpl_fstat (int fd, struct stat *buf)
{
#if REPLACE_FCHDIR && REPLACE_OPEN_DIRECTORY
/* Handle the case when rpl_open() used a dummy file descriptor to work
around an open() that can't normally visit directories. */
const char *name = _gl_directory_name (fd);
if (name != NULL)
return stat (name, buf);
#endif
return fstat_nothrow (fd, buf);
}

229
gl/getpass.c Normal file
View File

@@ -0,0 +1,229 @@
/* Copyright (C) 1992-2001, 2003-2007, 2009-2013 Free Software Foundation, Inc.
This file is part of the GNU C Library.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, see <http://www.gnu.org/licenses/>. */
#ifndef _LIBC
# include <config.h>
#endif
#include "getpass.h"
#include <stdio.h>
#if !((defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__)
# include <stdbool.h>
# if HAVE_DECL___FSETLOCKING && HAVE___FSETLOCKING
# if HAVE_STDIO_EXT_H
# include <stdio_ext.h>
# endif
# else
# define __fsetlocking(stream, type) /* empty */
# endif
# if HAVE_TERMIOS_H
# include <termios.h>
# endif
# if USE_UNLOCKED_IO
# include "unlocked-io.h"
# else
# if !HAVE_DECL_FFLUSH_UNLOCKED
# undef fflush_unlocked
# define fflush_unlocked(x) fflush (x)
# endif
# if !HAVE_DECL_FLOCKFILE
# undef flockfile
# define flockfile(x) ((void) 0)
# endif
# if !HAVE_DECL_FUNLOCKFILE
# undef funlockfile
# define funlockfile(x) ((void) 0)
# endif
# if !HAVE_DECL_FPUTS_UNLOCKED
# undef fputs_unlocked
# define fputs_unlocked(str,stream) fputs (str, stream)
# endif
# if !HAVE_DECL_PUTC_UNLOCKED
# undef putc_unlocked
# define putc_unlocked(c,stream) putc (c, stream)
# endif
# endif
/* It is desirable to use this bit on systems that have it.
The only bit of terminal state we want to twiddle is echoing, which is
done in software; there is no need to change the state of the terminal
hardware. */
# ifndef TCSASOFT
# define TCSASOFT 0
# endif
static void
call_fclose (void *arg)
{
if (arg != NULL)
fclose (arg);
}
char *
getpass (const char *prompt)
{
FILE *tty;
FILE *in, *out;
struct termios s, t;
bool tty_changed = false;
static char *buf;
static size_t bufsize;
ssize_t nread;
/* Try to write to and read from the terminal if we can.
If we can't open the terminal, use stderr and stdin. */
tty = fopen ("/dev/tty", "w+");
if (tty == NULL)
{
in = stdin;
out = stderr;
}
else
{
/* We do the locking ourselves. */
__fsetlocking (tty, FSETLOCKING_BYCALLER);
out = in = tty;
}
flockfile (out);
/* Turn echoing off if it is on now. */
# if HAVE_TCGETATTR
if (tcgetattr (fileno (in), &t) == 0)
{
/* Save the old one. */
s = t;
/* Tricky, tricky. */
t.c_lflag &= ~(ECHO | ISIG);
tty_changed = (tcsetattr (fileno (in), TCSAFLUSH | TCSASOFT, &t) == 0);
}
# endif
/* Write the prompt. */
fputs_unlocked (prompt, out);
fflush_unlocked (out);
/* Read the password. */
nread = getline (&buf, &bufsize, in);
/* According to the C standard, input may not be followed by output
on the same stream without an intervening call to a file
positioning function. Suppose in == out; then without this fseek
call, on Solaris, HP-UX, AIX, OSF/1, the previous input gets
echoed, whereas on IRIX, the following newline is not output as
it should be. POSIX imposes similar restrictions if fileno (in)
== fileno (out). The POSIX restrictions are tricky and change
from POSIX version to POSIX version, so play it safe and invoke
fseek even if in != out. */
fseeko (out, 0, SEEK_CUR);
if (buf != NULL)
{
if (nread < 0)
buf[0] = '\0';
else if (buf[nread - 1] == '\n')
{
/* Remove the newline. */
buf[nread - 1] = '\0';
if (tty_changed)
{
/* Write the newline that was not echoed. */
putc_unlocked ('\n', out);
}
}
}
/* Restore the original setting. */
# if HAVE_TCSETATTR
if (tty_changed)
tcsetattr (fileno (in), TCSAFLUSH | TCSASOFT, &s);
# endif
funlockfile (out);
call_fclose (tty);
return buf;
}
#else /* W32 native */
/* Windows implementation by Martin Lambers <marlam@marlam.de>,
improved by Simon Josefsson. */
/* For PASS_MAX. */
# include <limits.h>
/* For _getch(). */
# include <conio.h>
/* For strdup(). */
# include <string.h>
# ifndef PASS_MAX
# define PASS_MAX 512
# endif
char *
getpass (const char *prompt)
{
char getpassbuf[PASS_MAX + 1];
size_t i = 0;
int c;
if (prompt)
{
fputs (prompt, stderr);
fflush (stderr);
}
for (;;)
{
c = _getch ();
if (c == '\r')
{
getpassbuf[i] = '\0';
break;
}
else if (i < PASS_MAX)
{
getpassbuf[i++] = c;
}
if (i >= PASS_MAX)
{
getpassbuf[i] = '\0';
break;
}
}
if (prompt)
{
fputs ("\r\n", stderr);
fflush (stderr);
}
return strdup (getpassbuf);
}
#endif

30
gl/getpass.h Normal file
View File

@@ -0,0 +1,30 @@
/* getpass.h -- Read a password of arbitrary length from /dev/tty or stdin.
Copyright (C) 2004, 2009-2013 Free Software Foundation, Inc.
Contributed by Simon Josefsson <jas@extundo.com>, 2004.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, see <http://www.gnu.org/licenses/>. */
#ifndef GETPASS_H
# define GETPASS_H
/* Get getpass declaration, if available. */
# include <unistd.h>
# if !HAVE_DECL_GETPASS
/* Read a password of arbitrary length from /dev/tty or stdin. */
char *getpass (const char *prompt);
# endif
#endif /* GETPASS_H */

67
gl/lseek.c Normal file
View File

@@ -0,0 +1,67 @@
/* An lseek() function that detects pipes.
Copyright (C) 2007, 2009-2013 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, see <http://www.gnu.org/licenses/>. */
#include <config.h>
/* Specification. */
#include <unistd.h>
#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
/* Windows platforms. */
/* Get GetFileType. */
# include <windows.h>
/* Get _get_osfhandle. */
# include "msvc-nothrow.h"
#else
# include <sys/stat.h>
#endif
#include <errno.h>
#undef lseek
off_t
rpl_lseek (int fd, off_t offset, int whence)
{
#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
/* mingw lseek mistakenly succeeds on pipes, sockets, and terminals. */
HANDLE h = (HANDLE) _get_osfhandle (fd);
if (h == INVALID_HANDLE_VALUE)
{
errno = EBADF;
return -1;
}
if (GetFileType (h) != FILE_TYPE_DISK)
{
errno = ESPIPE;
return -1;
}
#else
/* BeOS lseek mistakenly succeeds on pipes... */
struct stat statbuf;
if (fstat (fd, &statbuf) < 0)
return -1;
if (!S_ISREG (statbuf.st_mode))
{
errno = ESPIPE;
return -1;
}
#endif
#if _GL_WINDOWS_64_BIT_OFF_T
return _lseeki64 (fd, offset, whence);
#else
return lseek (fd, offset, whence);
#endif
}

15
gl/m4/fseek.m4 Normal file
View File

@@ -0,0 +1,15 @@
# fseek.m4 serial 4
dnl Copyright (C) 2007, 2009-2013 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
AC_DEFUN([gl_FUNC_FSEEK],
[
AC_REQUIRE([gl_STDIO_H_DEFAULTS])
AC_REQUIRE([gl_FUNC_FSEEKO])
dnl When fseeko needs fixes, fseek needs them too.
if test $HAVE_FSEEKO = 0 || test $REPLACE_FSEEKO = 1; then
REPLACE_FSEEK=1
fi
])

73
gl/m4/fseeko.m4 Normal file
View File

@@ -0,0 +1,73 @@
# fseeko.m4 serial 16
dnl Copyright (C) 2007-2013 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
AC_DEFUN([gl_FUNC_FSEEKO],
[
AC_REQUIRE([gl_STDIO_H_DEFAULTS])
AC_REQUIRE([gl_STDIN_LARGE_OFFSET])
AC_REQUIRE([gl_SYS_TYPES_H])
AC_REQUIRE([AC_PROG_CC])
dnl Persuade glibc <stdio.h> to declare fseeko().
AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
AC_CACHE_CHECK([for fseeko], [gl_cv_func_fseeko],
[
AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <stdio.h>
]], [fseeko (stdin, 0, 0);])],
[gl_cv_func_fseeko=yes], [gl_cv_func_fseeko=no])
])
AC_CHECK_DECLS_ONCE([fseeko])
if test $ac_cv_have_decl_fseeko = no; then
HAVE_DECL_FSEEKO=0
fi
if test $gl_cv_func_fseeko = no; then
HAVE_FSEEKO=0
else
if test $WINDOWS_64_BIT_OFF_T = 1; then
REPLACE_FSEEKO=1
fi
if test $gl_cv_var_stdin_large_offset = no; then
REPLACE_FSEEKO=1
fi
m4_ifdef([gl_FUNC_FFLUSH_STDIN], [
gl_FUNC_FFLUSH_STDIN
if test $gl_cv_func_fflush_stdin = no; then
REPLACE_FSEEKO=1
fi
])
fi
])
dnl Code shared by fseeko and ftello. Determine if large files are supported,
dnl but stdin does not start as a large file by default.
AC_DEFUN([gl_STDIN_LARGE_OFFSET],
[
AC_CACHE_CHECK([whether stdin defaults to large file offsets],
[gl_cv_var_stdin_large_offset],
[AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <stdio.h>]],
[[#if defined __SL64 && defined __SCLE /* cygwin */
/* Cygwin 1.5.24 and earlier fail to put stdin in 64-bit mode, making
fseeko/ftello needlessly fail. This bug was fixed in 1.5.25, and
it is easier to do a version check than building a runtime test. */
# include <cygwin/version.h>
# if CYGWIN_VERSION_DLL_COMBINED < CYGWIN_VERSION_DLL_MAKE_COMBINED (1005, 25)
choke me
# endif
#endif]])],
[gl_cv_var_stdin_large_offset=yes],
[gl_cv_var_stdin_large_offset=no])])
])
# Prerequisites of lib/fseeko.c.
AC_DEFUN([gl_PREREQ_FSEEKO],
[
dnl Native Windows has the function _fseeki64. mingw hides it, but mingw64
dnl makes it usable again.
AC_CHECK_FUNCS([_fseeki64])
])

36
gl/m4/fstat.m4 Normal file
View File

@@ -0,0 +1,36 @@
# fstat.m4 serial 4
dnl Copyright (C) 2011-2013 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
AC_DEFUN([gl_FUNC_FSTAT],
[
AC_REQUIRE([gl_SYS_STAT_H_DEFAULTS])
AC_REQUIRE([gl_MSVC_INVAL])
if test $HAVE_MSVC_INVALID_PARAMETER_HANDLER = 1; then
REPLACE_FSTAT=1
fi
AC_REQUIRE([gl_HEADER_SYS_STAT_H])
if test $WINDOWS_64_BIT_ST_SIZE = 1; then
REPLACE_FSTAT=1
fi
dnl Replace fstat() for supporting the gnulib-defined open() on directories.
m4_ifdef([gl_FUNC_FCHDIR], [
gl_TEST_FCHDIR
if test $HAVE_FCHDIR = 0; then
case "$gl_cv_func_open_directory_works" in
*yes) ;;
*)
REPLACE_FSTAT=1
;;
esac
fi
])
])
# Prerequisites of lib/fstat.c.
AC_DEFUN([gl_PREREQ_FSTAT], [:])

58
gl/m4/getpass.m4 Normal file
View File

@@ -0,0 +1,58 @@
# getpass.m4 serial 14
dnl Copyright (C) 2002-2003, 2005-2006, 2009-2013 Free Software Foundation,
dnl Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
# Provide a getpass() function if the system doesn't have it.
AC_DEFUN([gl_FUNC_GETPASS],
[
dnl Persuade Solaris <unistd.h> and <stdlib.h> to declare getpass().
AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
AC_CHECK_FUNCS([getpass])
AC_CHECK_DECLS_ONCE([getpass])
if test $ac_cv_func_getpass = yes; then
HAVE_GETPASS=1
else
HAVE_GETPASS=0
fi
])
# Provide the GNU getpass() implementation. It supports passwords of
# arbitrary length (not just 8 bytes as on HP-UX).
AC_DEFUN([gl_FUNC_GETPASS_GNU],
[
dnl Persuade Solaris <unistd.h> and <stdlib.h> to declare getpass().
AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
AC_CHECK_DECLS_ONCE([getpass])
dnl TODO: Detect when GNU getpass() is already found in glibc.
REPLACE_GETPASS=1
if test $REPLACE_GETPASS = 1; then
dnl We must choose a different name for our function, since on ELF systems
dnl an unusable getpass() in libc.so would override our getpass() if it is
dnl compiled into a shared library.
AC_DEFINE([getpass], [gnu_getpass],
[Define to a replacement function name for getpass().])
fi
])
# Prerequisites of lib/getpass.c.
AC_DEFUN([gl_PREREQ_GETPASS], [
AC_CHECK_HEADERS_ONCE([stdio_ext.h termios.h])
AC_CHECK_FUNCS_ONCE([__fsetlocking tcgetattr tcsetattr])
AC_CHECK_DECLS([__fsetlocking],,,
[[#include <stdio.h>
#if HAVE_STDIO_EXT_H
#include <stdio_ext.h>
#endif]])
AC_CHECK_DECLS_ONCE([fflush_unlocked])
AC_CHECK_DECLS_ONCE([flockfile])
AC_CHECK_DECLS_ONCE([fputs_unlocked])
AC_CHECK_DECLS_ONCE([funlockfile])
AC_CHECK_DECLS_ONCE([putc_unlocked])
:
])

View File

@@ -27,15 +27,17 @@
# Specification in the form of a command-line invocation: # Specification in the form of a command-line invocation:
# gnulib-tool --import --dir=. --lib=libgnu --source-base=gl --m4-base=gl/m4 --doc-base=doc --tests-base=gl/tests --aux-dir=build-aux --no-conditional-dependencies --no-libtool --macro-prefix=gl cloexec getline gettime memmem # gnulib-tool --import --dir=. --lib=libgnu --source-base=gl --m4-base=gl/m4 --doc-base=doc --tests-base=gl/tests --aux-dir=build-aux --no-conditional-dependencies --no-libtool --macro-prefix=gl cloexec getline getpass gettime memmem minmax
# Specification in the form of a few gnulib-tool.m4 macro invocations: # Specification in the form of a few gnulib-tool.m4 macro invocations:
gl_LOCAL_DIR([]) gl_LOCAL_DIR([])
gl_MODULES([ gl_MODULES([
cloexec cloexec
getline getline
getpass
gettime gettime
memmem memmem
minmax
]) ])
gl_AVOID([]) gl_AVOID([])
gl_SOURCE_BASE([gl]) gl_SOURCE_BASE([gl])

View File

@@ -49,15 +49,25 @@ AC_DEFUN([gl_EARLY],
# Code from module fcntl: # Code from module fcntl:
# Code from module fcntl-h: # Code from module fcntl-h:
# Code from module fd-hook: # Code from module fd-hook:
# Code from module fseek:
# Code from module fseeko:
AC_REQUIRE([AC_FUNC_FSEEKO])
# Code from module fstat:
# Code from module getdelim: # Code from module getdelim:
# Code from module getdtablesize: # Code from module getdtablesize:
# Code from module getline: # Code from module getline:
# Code from module getpass:
# Code from module gettime: # Code from module gettime:
# Code from module gettimeofday: # Code from module gettimeofday:
# Code from module include_next: # Code from module include_next:
# Code from module largefile:
AC_REQUIRE([AC_SYS_LARGEFILE])
# Code from module lseek:
# Code from module malloc-posix:
# Code from module memchr: # Code from module memchr:
# Code from module memmem: # Code from module memmem:
# Code from module memmem-simple: # Code from module memmem-simple:
# Code from module minmax:
# Code from module msvc-inval: # Code from module msvc-inval:
# Code from module msvc-nothrow: # Code from module msvc-nothrow:
# Code from module multiarch: # Code from module multiarch:
@@ -72,7 +82,9 @@ AC_DEFUN([gl_EARLY],
# Code from module stdint: # Code from module stdint:
# Code from module stdio: # Code from module stdio:
# Code from module stdlib: # Code from module stdlib:
# Code from module strdup-posix:
# Code from module string: # Code from module string:
# Code from module sys_stat:
# Code from module sys_time: # Code from module sys_time:
# Code from module sys_types: # Code from module sys_types:
# Code from module time: # Code from module time:
@@ -117,6 +129,23 @@ AC_DEFUN([gl_INIT],
fi fi
gl_FCNTL_MODULE_INDICATOR([fcntl]) gl_FCNTL_MODULE_INDICATOR([fcntl])
gl_FCNTL_H gl_FCNTL_H
gl_FUNC_FSEEK
if test $REPLACE_FSEEK = 1; then
AC_LIBOBJ([fseek])
fi
gl_STDIO_MODULE_INDICATOR([fseek])
gl_FUNC_FSEEKO
if test $HAVE_FSEEKO = 0 || test $REPLACE_FSEEKO = 1; then
AC_LIBOBJ([fseeko])
gl_PREREQ_FSEEKO
fi
gl_STDIO_MODULE_INDICATOR([fseeko])
gl_FUNC_FSTAT
if test $REPLACE_FSTAT = 1; then
AC_LIBOBJ([fstat])
gl_PREREQ_FSTAT
fi
gl_SYS_STAT_MODULE_INDICATOR([fstat])
gl_FUNC_GETDELIM gl_FUNC_GETDELIM
if test $HAVE_GETDELIM = 0 || test $REPLACE_GETDELIM = 1; then if test $HAVE_GETDELIM = 0 || test $REPLACE_GETDELIM = 1; then
AC_LIBOBJ([getdelim]) AC_LIBOBJ([getdelim])
@@ -135,6 +164,11 @@ AC_DEFUN([gl_INIT],
gl_PREREQ_GETLINE gl_PREREQ_GETLINE
fi fi
gl_STDIO_MODULE_INDICATOR([getline]) gl_STDIO_MODULE_INDICATOR([getline])
gl_FUNC_GETPASS
if test $HAVE_GETPASS = 0; then
AC_LIBOBJ([getpass])
gl_PREREQ_GETPASS
fi
gl_GETTIME gl_GETTIME
gl_FUNC_GETTIMEOFDAY gl_FUNC_GETTIMEOFDAY
if test $HAVE_GETTIMEOFDAY = 0 || test $REPLACE_GETTIMEOFDAY = 1; then if test $HAVE_GETTIMEOFDAY = 0 || test $REPLACE_GETTIMEOFDAY = 1; then
@@ -142,6 +176,17 @@ AC_DEFUN([gl_INIT],
gl_PREREQ_GETTIMEOFDAY gl_PREREQ_GETTIMEOFDAY
fi fi
gl_SYS_TIME_MODULE_INDICATOR([gettimeofday]) gl_SYS_TIME_MODULE_INDICATOR([gettimeofday])
AC_REQUIRE([gl_LARGEFILE])
gl_FUNC_LSEEK
if test $REPLACE_LSEEK = 1; then
AC_LIBOBJ([lseek])
fi
gl_UNISTD_MODULE_INDICATOR([lseek])
gl_FUNC_MALLOC_POSIX
if test $REPLACE_MALLOC = 1; then
AC_LIBOBJ([malloc])
fi
gl_STDLIB_MODULE_INDICATOR([malloc-posix])
gl_FUNC_MEMCHR gl_FUNC_MEMCHR
if test $HAVE_MEMCHR = 0 || test $REPLACE_MEMCHR = 1; then if test $HAVE_MEMCHR = 0 || test $REPLACE_MEMCHR = 1; then
AC_LIBOBJ([memchr]) AC_LIBOBJ([memchr])
@@ -157,6 +202,7 @@ AC_DEFUN([gl_INIT],
AC_LIBOBJ([memmem]) AC_LIBOBJ([memmem])
fi fi
gl_STRING_MODULE_INDICATOR([memmem]) gl_STRING_MODULE_INDICATOR([memmem])
gl_MINMAX
gl_MSVC_INVAL gl_MSVC_INVAL
if test $HAVE_MSVC_INVALID_PARAMETER_HANDLER = 1; then if test $HAVE_MSVC_INVALID_PARAMETER_HANDLER = 1; then
AC_LIBOBJ([msvc-inval]) AC_LIBOBJ([msvc-inval])
@@ -177,7 +223,15 @@ AC_DEFUN([gl_INIT],
gl_STDINT_H gl_STDINT_H
gl_STDIO_H gl_STDIO_H
gl_STDLIB_H gl_STDLIB_H
gl_FUNC_STRDUP_POSIX
if test $ac_cv_func_strdup = no || test $REPLACE_STRDUP = 1; then
AC_LIBOBJ([strdup])
gl_PREREQ_STRDUP
fi
gl_STRING_MODULE_INDICATOR([strdup])
gl_HEADER_STRING_H gl_HEADER_STRING_H
gl_HEADER_SYS_STAT_H
AC_PROG_MKDIR_P
gl_HEADER_SYS_TIME_H gl_HEADER_SYS_TIME_H
AC_PROG_MKDIR_P AC_PROG_MKDIR_P
gl_SYS_TYPES_H gl_SYS_TYPES_H
@@ -338,14 +392,22 @@ AC_DEFUN([gl_FILE_LIST], [
lib/fcntl.in.h lib/fcntl.in.h
lib/fd-hook.c lib/fd-hook.c
lib/fd-hook.h lib/fd-hook.h
lib/fseek.c
lib/fseeko.c
lib/fstat.c
lib/getdelim.c lib/getdelim.c
lib/getdtablesize.c lib/getdtablesize.c
lib/getline.c lib/getline.c
lib/getpass.c
lib/getpass.h
lib/gettime.c lib/gettime.c
lib/gettimeofday.c lib/gettimeofday.c
lib/lseek.c
lib/malloc.c
lib/memchr.c lib/memchr.c
lib/memchr.valgrind lib/memchr.valgrind
lib/memmem.c lib/memmem.c
lib/minmax.h
lib/msvc-inval.c lib/msvc-inval.c
lib/msvc-inval.h lib/msvc-inval.h
lib/msvc-nothrow.c lib/msvc-nothrow.c
@@ -354,10 +416,13 @@ AC_DEFUN([gl_FILE_LIST], [
lib/stdbool.in.h lib/stdbool.in.h
lib/stddef.in.h lib/stddef.in.h
lib/stdint.in.h lib/stdint.in.h
lib/stdio-impl.h
lib/stdio.in.h lib/stdio.in.h
lib/stdlib.in.h lib/stdlib.in.h
lib/str-two-way.h lib/str-two-way.h
lib/strdup.c
lib/string.in.h lib/string.in.h
lib/sys_stat.in.h
lib/sys_time.in.h lib/sys_time.in.h
lib/sys_types.in.h lib/sys_types.in.h
lib/time.in.h lib/time.in.h
@@ -375,17 +440,24 @@ AC_DEFUN([gl_FILE_LIST], [
m4/fcntl-o.m4 m4/fcntl-o.m4
m4/fcntl.m4 m4/fcntl.m4
m4/fcntl_h.m4 m4/fcntl_h.m4
m4/fseek.m4
m4/fseeko.m4
m4/fstat.m4
m4/getdelim.m4 m4/getdelim.m4
m4/getdtablesize.m4 m4/getdtablesize.m4
m4/getline.m4 m4/getline.m4
m4/getpass.m4
m4/gettime.m4 m4/gettime.m4
m4/gettimeofday.m4 m4/gettimeofday.m4
m4/gnulib-common.m4 m4/gnulib-common.m4
m4/include_next.m4 m4/include_next.m4
m4/largefile.m4
m4/longlong.m4 m4/longlong.m4
m4/lseek.m4
m4/malloc.m4 m4/malloc.m4
m4/memchr.m4 m4/memchr.m4
m4/memmem.m4 m4/memmem.m4
m4/minmax.m4
m4/mmap-anon.m4 m4/mmap-anon.m4
m4/msvc-inval.m4 m4/msvc-inval.m4
m4/msvc-nothrow.m4 m4/msvc-nothrow.m4
@@ -398,8 +470,10 @@ AC_DEFUN([gl_FILE_LIST], [
m4/stdint.m4 m4/stdint.m4
m4/stdio_h.m4 m4/stdio_h.m4
m4/stdlib_h.m4 m4/stdlib_h.m4
m4/strdup.m4
m4/string_h.m4 m4/string_h.m4
m4/sys_socket_h.m4 m4/sys_socket_h.m4
m4/sys_stat_h.m4
m4/sys_time_h.m4 m4/sys_time_h.m4
m4/sys_types_h.m4 m4/sys_types_h.m4
m4/time_h.m4 m4/time_h.m4

146
gl/m4/largefile.m4 Normal file
View File

@@ -0,0 +1,146 @@
# Enable large files on systems where this is not the default.
# Copyright 1992-1996, 1998-2013 Free Software Foundation, Inc.
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
# The following implementation works around a problem in autoconf <= 2.69;
# AC_SYS_LARGEFILE does not configure for large inodes on Mac OS X 10.5,
# or configures them incorrectly in some cases.
m4_version_prereq([2.70], [] ,[
# _AC_SYS_LARGEFILE_TEST_INCLUDES
# -------------------------------
m4_define([_AC_SYS_LARGEFILE_TEST_INCLUDES],
[@%:@include <sys/types.h>
/* Check that off_t can represent 2**63 - 1 correctly.
We can't simply define LARGE_OFF_T to be 9223372036854775807,
since some C++ compilers masquerading as C compilers
incorrectly reject 9223372036854775807. */
@%:@define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
int off_t_is_large[[(LARGE_OFF_T % 2147483629 == 721
&& LARGE_OFF_T % 2147483647 == 1)
? 1 : -1]];[]dnl
])
# _AC_SYS_LARGEFILE_MACRO_VALUE(C-MACRO, VALUE,
# CACHE-VAR,
# DESCRIPTION,
# PROLOGUE, [FUNCTION-BODY])
# --------------------------------------------------------
m4_define([_AC_SYS_LARGEFILE_MACRO_VALUE],
[AC_CACHE_CHECK([for $1 value needed for large files], [$3],
[while :; do
m4_ifval([$6], [AC_LINK_IFELSE], [AC_COMPILE_IFELSE])(
[AC_LANG_PROGRAM([$5], [$6])],
[$3=no; break])
m4_ifval([$6], [AC_LINK_IFELSE], [AC_COMPILE_IFELSE])(
[AC_LANG_PROGRAM([@%:@define $1 $2
$5], [$6])],
[$3=$2; break])
$3=unknown
break
done])
case $$3 in #(
no | unknown) ;;
*) AC_DEFINE_UNQUOTED([$1], [$$3], [$4]);;
esac
rm -rf conftest*[]dnl
])# _AC_SYS_LARGEFILE_MACRO_VALUE
# AC_SYS_LARGEFILE
# ----------------
# By default, many hosts won't let programs access large files;
# one must use special compiler options to get large-file access to work.
# For more details about this brain damage please see:
# http://www.unix-systems.org/version2/whatsnew/lfs20mar.html
AC_DEFUN([AC_SYS_LARGEFILE],
[AC_ARG_ENABLE(largefile,
[ --disable-largefile omit support for large files])
if test "$enable_largefile" != no; then
AC_CACHE_CHECK([for special C compiler options needed for large files],
ac_cv_sys_largefile_CC,
[ac_cv_sys_largefile_CC=no
if test "$GCC" != yes; then
ac_save_CC=$CC
while :; do
# IRIX 6.2 and later do not support large files by default,
# so use the C compiler's -n32 option if that helps.
AC_LANG_CONFTEST([AC_LANG_PROGRAM([_AC_SYS_LARGEFILE_TEST_INCLUDES])])
AC_COMPILE_IFELSE([], [break])
CC="$CC -n32"
AC_COMPILE_IFELSE([], [ac_cv_sys_largefile_CC=' -n32'; break])
break
done
CC=$ac_save_CC
rm -f conftest.$ac_ext
fi])
if test "$ac_cv_sys_largefile_CC" != no; then
CC=$CC$ac_cv_sys_largefile_CC
fi
_AC_SYS_LARGEFILE_MACRO_VALUE(_FILE_OFFSET_BITS, 64,
ac_cv_sys_file_offset_bits,
[Number of bits in a file offset, on hosts where this is settable.],
[_AC_SYS_LARGEFILE_TEST_INCLUDES])
if test $ac_cv_sys_file_offset_bits = unknown; then
_AC_SYS_LARGEFILE_MACRO_VALUE(_LARGE_FILES, 1,
ac_cv_sys_large_files,
[Define for large files, on AIX-style hosts.],
[_AC_SYS_LARGEFILE_TEST_INCLUDES])
fi
AC_DEFINE([_DARWIN_USE_64_BIT_INODE], [1],
[Enable large inode numbers on Mac OS X 10.5.])
fi
])# AC_SYS_LARGEFILE
])# m4_version_prereq 2.70
# Enable large files on systems where this is implemented by Gnulib, not by the
# system headers.
# Set the variables WINDOWS_64_BIT_OFF_T, WINDOWS_64_BIT_ST_SIZE if Gnulib
# overrides ensure that off_t or 'struct size.st_size' are 64-bit, respectively.
AC_DEFUN([gl_LARGEFILE],
[
AC_REQUIRE([AC_CANONICAL_HOST])
case "$host_os" in
mingw*)
dnl Native Windows.
dnl mingw64 defines off_t to a 64-bit type already, if
dnl _FILE_OFFSET_BITS=64, which is ensured by AC_SYS_LARGEFILE.
AC_CACHE_CHECK([for 64-bit off_t], [gl_cv_type_off_t_64],
[AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM(
[[#include <sys/types.h>
int verify_off_t_size[sizeof (off_t) >= 8 ? 1 : -1];
]],
[[]])],
[gl_cv_type_off_t_64=yes], [gl_cv_type_off_t_64=no])
])
if test $gl_cv_type_off_t_64 = no; then
WINDOWS_64_BIT_OFF_T=1
else
WINDOWS_64_BIT_OFF_T=0
fi
dnl But all native Windows platforms (including mingw64) have a 32-bit
dnl st_size member in 'struct stat'.
WINDOWS_64_BIT_ST_SIZE=1
;;
*)
dnl Nothing to do on gnulib's side.
dnl A 64-bit off_t is
dnl - already the default on Mac OS X, FreeBSD, NetBSD, OpenBSD, IRIX,
dnl OSF/1, Cygwin,
dnl - enabled by _FILE_OFFSET_BITS=64 (ensured by AC_SYS_LARGEFILE) on
dnl glibc, HP-UX, Solaris,
dnl - enabled by _LARGE_FILES=1 (ensured by AC_SYS_LARGEFILE) on AIX,
dnl - impossible to achieve on Minix 3.1.8.
WINDOWS_64_BIT_OFF_T=0
WINDOWS_64_BIT_ST_SIZE=0
;;
esac
])

71
gl/m4/lseek.m4 Normal file
View File

@@ -0,0 +1,71 @@
# lseek.m4 serial 10
dnl Copyright (C) 2007, 2009-2013 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
AC_DEFUN([gl_FUNC_LSEEK],
[
AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
AC_REQUIRE([AC_CANONICAL_HOST])
AC_REQUIRE([AC_PROG_CC])
AC_CHECK_HEADERS_ONCE([unistd.h])
AC_CACHE_CHECK([whether lseek detects pipes], [gl_cv_func_lseek_pipe],
[case "$host_os" in
mingw*)
dnl Native Windows.
dnl The result of lseek (fd, (off_t)0, SEEK_CUR) or
dnl SetFilePointer(handle, 0, NULL, FILE_CURRENT)
dnl for a pipe depends on the environment: In a Cygwin 1.5
dnl environment it succeeds (wrong); in a Cygwin 1.7 environment
dnl it fails with a wrong errno value.
gl_cv_func_lseek_pipe=no
;;
*)
if test $cross_compiling = no; then
AC_LINK_IFELSE([AC_LANG_PROGRAM([[
#include <sys/types.h> /* for off_t */
#include <stdio.h> /* for SEEK_CUR */
#if HAVE_UNISTD_H
# include <unistd.h>
#else /* on Windows with MSVC */
# include <io.h>
#endif
]], [[
/* Exit with success only if stdin is seekable. */
return lseek (0, (off_t)0, SEEK_CUR) < 0;
]])],
[if test -s conftest$ac_exeext \
&& ./conftest$ac_exeext < conftest.$ac_ext \
&& test 1 = "`echo hi \
| { ./conftest$ac_exeext; echo $?; cat >/dev/null; }`"; then
gl_cv_func_lseek_pipe=yes
else
gl_cv_func_lseek_pipe=no
fi
],
[gl_cv_func_lseek_pipe=no])
else
AC_COMPILE_IFELSE(
[AC_LANG_SOURCE([[
#if defined __BEOS__
/* BeOS mistakenly return 0 when trying to seek on pipes. */
Choke me.
#endif]])],
[gl_cv_func_lseek_pipe=yes], [gl_cv_func_lseek_pipe=no])
fi
;;
esac
])
if test $gl_cv_func_lseek_pipe = no; then
REPLACE_LSEEK=1
AC_DEFINE([LSEEK_PIPE_BROKEN], [1],
[Define to 1 if lseek does not detect pipes.])
fi
AC_REQUIRE([gl_SYS_TYPES_H])
if test $WINDOWS_64_BIT_OFF_T = 1; then
REPLACE_LSEEK=1
fi
])

44
gl/m4/minmax.m4 Normal file
View File

@@ -0,0 +1,44 @@
# minmax.m4 serial 4
dnl Copyright (C) 2005, 2009-2013 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
AC_PREREQ([2.53])
AC_DEFUN([gl_MINMAX],
[
AC_REQUIRE([gl_PREREQ_MINMAX])
])
# Prerequisites of lib/minmax.h.
AC_DEFUN([gl_PREREQ_MINMAX],
[
gl_MINMAX_IN_HEADER([limits.h])
gl_MINMAX_IN_HEADER([sys/param.h])
])
dnl gl_MINMAX_IN_HEADER(HEADER)
dnl The parameter has to be a literal header name; it cannot be macro,
dnl nor a shell variable. (Because autoheader collects only AC_DEFINE
dnl invocations with a literal macro name.)
AC_DEFUN([gl_MINMAX_IN_HEADER],
[
m4_pushdef([header], AS_TR_SH([$1]))
m4_pushdef([HEADER], AS_TR_CPP([$1]))
AC_CACHE_CHECK([whether <$1> defines MIN and MAX],
[gl_cv_minmax_in_]header,
[AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM(
[[#include <$1>
int x = MIN (42, 17);]],
[[]])],
[gl_cv_minmax_in_]header[=yes],
[gl_cv_minmax_in_]header[=no])])
if test $gl_cv_minmax_in_[]header = yes; then
AC_DEFINE([HAVE_MINMAX_IN_]HEADER, 1,
[Define to 1 if <$1> defines the MIN and MAX macros.])
fi
m4_popdef([HEADER])
m4_popdef([header])
])

36
gl/m4/strdup.m4 Normal file
View File

@@ -0,0 +1,36 @@
# strdup.m4 serial 13
dnl Copyright (C) 2002-2013 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
AC_DEFUN([gl_FUNC_STRDUP],
[
AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS])
AC_CHECK_FUNCS_ONCE([strdup])
AC_CHECK_DECLS_ONCE([strdup])
if test $ac_cv_have_decl_strdup = no; then
HAVE_DECL_STRDUP=0
fi
])
AC_DEFUN([gl_FUNC_STRDUP_POSIX],
[
AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS])
AC_REQUIRE([gl_CHECK_MALLOC_POSIX])
AC_CHECK_FUNCS_ONCE([strdup])
if test $ac_cv_func_strdup = yes; then
if test $gl_cv_func_malloc_posix != yes; then
REPLACE_STRDUP=1
fi
fi
AC_CHECK_DECLS_ONCE([strdup])
if test $ac_cv_have_decl_strdup = no; then
HAVE_DECL_STRDUP=0
fi
])
# Prerequisites of lib/strdup.c.
AC_DEFUN([gl_PREREQ_STRDUP], [:])

96
gl/m4/sys_stat_h.m4 Normal file
View File

@@ -0,0 +1,96 @@
# sys_stat_h.m4 serial 28 -*- Autoconf -*-
dnl Copyright (C) 2006-2013 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
dnl From Eric Blake.
dnl Provide a GNU-like <sys/stat.h>.
AC_DEFUN([gl_HEADER_SYS_STAT_H],
[
AC_REQUIRE([gl_SYS_STAT_H_DEFAULTS])
dnl Check for broken stat macros.
AC_REQUIRE([AC_HEADER_STAT])
gl_CHECK_NEXT_HEADERS([sys/stat.h])
dnl Ensure the type mode_t gets defined.
AC_REQUIRE([AC_TYPE_MODE_T])
dnl Whether to override 'struct stat'.
m4_ifdef([gl_LARGEFILE], [
AC_REQUIRE([gl_LARGEFILE])
], [
WINDOWS_64_BIT_ST_SIZE=0
])
AC_SUBST([WINDOWS_64_BIT_ST_SIZE])
if test $WINDOWS_64_BIT_ST_SIZE = 1; then
AC_DEFINE([_GL_WINDOWS_64_BIT_ST_SIZE], [1],
[Define to 1 if Gnulib overrides 'struct stat' on Windows so that
struct stat.st_size becomes 64-bit.])
fi
dnl Define types that are supposed to be defined in <sys/types.h> or
dnl <sys/stat.h>.
AC_CHECK_TYPE([nlink_t], [],
[AC_DEFINE([nlink_t], [int],
[Define to the type of st_nlink in struct stat, or a supertype.])],
[#include <sys/types.h>
#include <sys/stat.h>])
dnl Check for declarations of anything we want to poison if the
dnl corresponding gnulib module is not in use.
gl_WARN_ON_USE_PREPARE([[#include <sys/stat.h>
]], [fchmodat fstat fstatat futimens lchmod lstat mkdirat mkfifo mkfifoat
mknod mknodat stat utimensat])
]) # gl_HEADER_SYS_STAT_H
AC_DEFUN([gl_SYS_STAT_MODULE_INDICATOR],
[
dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
AC_REQUIRE([gl_SYS_STAT_H_DEFAULTS])
gl_MODULE_INDICATOR_SET_VARIABLE([$1])
dnl Define it also as a C macro, for the benefit of the unit tests.
gl_MODULE_INDICATOR_FOR_TESTS([$1])
])
AC_DEFUN([gl_SYS_STAT_H_DEFAULTS],
[
AC_REQUIRE([gl_UNISTD_H_DEFAULTS]) dnl for REPLACE_FCHDIR
GNULIB_FCHMODAT=0; AC_SUBST([GNULIB_FCHMODAT])
GNULIB_FSTAT=0; AC_SUBST([GNULIB_FSTAT])
GNULIB_FSTATAT=0; AC_SUBST([GNULIB_FSTATAT])
GNULIB_FUTIMENS=0; AC_SUBST([GNULIB_FUTIMENS])
GNULIB_LCHMOD=0; AC_SUBST([GNULIB_LCHMOD])
GNULIB_LSTAT=0; AC_SUBST([GNULIB_LSTAT])
GNULIB_MKDIRAT=0; AC_SUBST([GNULIB_MKDIRAT])
GNULIB_MKFIFO=0; AC_SUBST([GNULIB_MKFIFO])
GNULIB_MKFIFOAT=0; AC_SUBST([GNULIB_MKFIFOAT])
GNULIB_MKNOD=0; AC_SUBST([GNULIB_MKNOD])
GNULIB_MKNODAT=0; AC_SUBST([GNULIB_MKNODAT])
GNULIB_STAT=0; AC_SUBST([GNULIB_STAT])
GNULIB_UTIMENSAT=0; AC_SUBST([GNULIB_UTIMENSAT])
dnl Assume proper GNU behavior unless another module says otherwise.
HAVE_FCHMODAT=1; AC_SUBST([HAVE_FCHMODAT])
HAVE_FSTATAT=1; AC_SUBST([HAVE_FSTATAT])
HAVE_FUTIMENS=1; AC_SUBST([HAVE_FUTIMENS])
HAVE_LCHMOD=1; AC_SUBST([HAVE_LCHMOD])
HAVE_LSTAT=1; AC_SUBST([HAVE_LSTAT])
HAVE_MKDIRAT=1; AC_SUBST([HAVE_MKDIRAT])
HAVE_MKFIFO=1; AC_SUBST([HAVE_MKFIFO])
HAVE_MKFIFOAT=1; AC_SUBST([HAVE_MKFIFOAT])
HAVE_MKNOD=1; AC_SUBST([HAVE_MKNOD])
HAVE_MKNODAT=1; AC_SUBST([HAVE_MKNODAT])
HAVE_UTIMENSAT=1; AC_SUBST([HAVE_UTIMENSAT])
REPLACE_FSTAT=0; AC_SUBST([REPLACE_FSTAT])
REPLACE_FSTATAT=0; AC_SUBST([REPLACE_FSTATAT])
REPLACE_FUTIMENS=0; AC_SUBST([REPLACE_FUTIMENS])
REPLACE_LSTAT=0; AC_SUBST([REPLACE_LSTAT])
REPLACE_MKDIR=0; AC_SUBST([REPLACE_MKDIR])
REPLACE_MKFIFO=0; AC_SUBST([REPLACE_MKFIFO])
REPLACE_MKNOD=0; AC_SUBST([REPLACE_MKNOD])
REPLACE_STAT=0; AC_SUBST([REPLACE_STAT])
REPLACE_UTIMENSAT=0; AC_SUBST([REPLACE_UTIMENSAT])
])

View File

@@ -1,10 +1,10 @@
# sys_types_h.m4 serial 4 # sys_types_h.m4 serial 5
dnl Copyright (C) 2011-2013 Free Software Foundation, Inc. dnl Copyright (C) 2011-2013 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it, dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved. dnl with or without modifications, as long as this notice is preserved.
AC_DEFUN([gl_SYS_TYPES_H], AC_DEFUN_ONCE([gl_SYS_TYPES_H],
[ [
AC_REQUIRE([gl_SYS_TYPES_H_DEFAULTS]) AC_REQUIRE([gl_SYS_TYPES_H_DEFAULTS])
gl_NEXT_HEADERS([sys/types.h]) gl_NEXT_HEADERS([sys/types.h])

56
gl/malloc.c Normal file
View File

@@ -0,0 +1,56 @@
/* malloc() function that is glibc compatible.
Copyright (C) 1997-1998, 2006-2007, 2009-2013 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, see <http://www.gnu.org/licenses/>. */
/* written by Jim Meyering and Bruno Haible */
#define _GL_USE_STDLIB_ALLOC 1
#include <config.h>
/* Only the AC_FUNC_MALLOC macro defines 'malloc' already in config.h. */
#ifdef malloc
# define NEED_MALLOC_GNU 1
# undef malloc
/* Whereas the gnulib module 'malloc-gnu' defines HAVE_MALLOC_GNU. */
#elif GNULIB_MALLOC_GNU && !HAVE_MALLOC_GNU
# define NEED_MALLOC_GNU 1
#endif
#include <stdlib.h>
#include <errno.h>
/* Allocate an N-byte block of memory from the heap.
If N is zero, allocate a 1-byte block. */
void *
rpl_malloc (size_t n)
{
void *result;
#if NEED_MALLOC_GNU
if (n == 0)
n = 1;
#endif
result = malloc (n);
#if !HAVE_MALLOC_POSIX
if (result == NULL)
errno = ENOMEM;
#endif
return result;
}

60
gl/minmax.h Normal file
View File

@@ -0,0 +1,60 @@
/* MIN, MAX macros.
Copyright (C) 1995, 1998, 2001, 2003, 2005, 2009-2013 Free Software
Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, see <http://www.gnu.org/licenses/>. */
#ifndef _MINMAX_H
#define _MINMAX_H
/* Note: MIN, MAX are also defined in <sys/param.h> on some systems
(glibc, IRIX, HP-UX, OSF/1). Therefore you might get warnings about
MIN, MAX macro redefinitions on some systems; the workaround is to
#include this file as the last one among the #include list. */
/* Before we define the following symbols we get the <limits.h> file
since otherwise we get redefinitions on some systems if <limits.h> is
included after this file. Likewise for <sys/param.h>.
If more than one of these system headers define MIN and MAX, pick just
one of the headers (because the definitions most likely are the same). */
#if HAVE_MINMAX_IN_LIMITS_H
# include <limits.h>
#elif HAVE_MINMAX_IN_SYS_PARAM_H
# include <sys/param.h>
#endif
/* Note: MIN and MAX should be used with two arguments of the
same type. They might not return the minimum and maximum of their two
arguments, if the arguments have different types or have unusual
floating-point values. For example, on a typical host with 32-bit 'int',
64-bit 'long long', and 64-bit IEEE 754 'double' types:
MAX (-1, 2147483648) returns 4294967295.
MAX (9007199254740992.0, 9007199254740993) returns 9007199254740992.0.
MAX (NaN, 0.0) returns 0.0.
MAX (+0.0, -0.0) returns -0.0.
and in each case the answer is in some sense bogus. */
/* MAX(a,b) returns the maximum of A and B. */
#ifndef MAX
# define MAX(a,b) ((a) > (b) ? (a) : (b))
#endif
/* MIN(a,b) returns the minimum of A and B. */
#ifndef MIN
# define MIN(a,b) ((a) < (b) ? (a) : (b))
#endif
#endif /* _MINMAX_H */

112
gl/stdio-impl.h Normal file
View File

@@ -0,0 +1,112 @@
/* Implementation details of FILE streams.
Copyright (C) 2007-2008, 2010-2013 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* Many stdio implementations have the same logic and therefore can share
the same implementation of stdio extension API, except that some fields
have different naming conventions, or their access requires some casts. */
/* BSD stdio derived implementations. */
#if defined __NetBSD__ /* NetBSD */
/* Get __NetBSD_Version__. */
# include <sys/param.h>
#endif
#include <errno.h> /* For detecting Plan9. */
#if defined __sferror || defined __DragonFly__ /* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin */
# if defined __DragonFly__ /* DragonFly */
/* See <http://www.dragonflybsd.org/cvsweb/src/lib/libc/stdio/priv_stdio.h?rev=HEAD&content-type=text/x-cvsweb-markup>. */
# define fp_ ((struct { struct __FILE_public pub; \
struct { unsigned char *_base; int _size; } _bf; \
void *cookie; \
void *_close; \
void *_read; \
void *_seek; \
void *_write; \
struct { unsigned char *_base; int _size; } _ub; \
int _ur; \
unsigned char _ubuf[3]; \
unsigned char _nbuf[1]; \
struct { unsigned char *_base; int _size; } _lb; \
int _blksize; \
fpos_t _offset; \
/* More fields, not relevant here. */ \
} *) fp)
/* See <http://www.dragonflybsd.org/cvsweb/src/include/stdio.h?rev=HEAD&content-type=text/x-cvsweb-markup>. */
# define _p pub._p
# define _flags pub._flags
# define _r pub._r
# define _w pub._w
# else
# define fp_ fp
# endif
# if (defined __NetBSD__ && __NetBSD_Version__ >= 105270000) || defined __OpenBSD__ /* NetBSD >= 1.5ZA, OpenBSD */
/* See <http://cvsweb.netbsd.org/bsdweb.cgi/src/lib/libc/stdio/fileext.h?rev=HEAD&content-type=text/x-cvsweb-markup>
and <http://www.openbsd.org/cgi-bin/cvsweb/src/lib/libc/stdio/fileext.h?rev=HEAD&content-type=text/x-cvsweb-markup> */
struct __sfileext
{
struct __sbuf _ub; /* ungetc buffer */
/* More fields, not relevant here. */
};
# define fp_ub ((struct __sfileext *) fp->_ext._base)->_ub
# else /* FreeBSD, NetBSD <= 1.5Z, DragonFly, Mac OS X, Cygwin */
# define fp_ub fp_->_ub
# endif
# define HASUB(fp) (fp_ub._base != NULL)
#endif
/* SystemV derived implementations. */
#ifdef __TANDEM /* NonStop Kernel */
# ifndef _IOERR
/* These values were determined by the program 'stdioext-flags' at
<http://lists.gnu.org/archive/html/bug-gnulib/2010-12/msg00165.html>. */
# define _IOERR 0x40
# define _IOREAD 0x80
# define _IOWRT 0x4
# define _IORW 0x100
# endif
#endif
#if defined _IOERR
# if defined __sun && defined _LP64 /* Solaris/{SPARC,AMD64} 64-bit */
# define fp_ ((struct { unsigned char *_ptr; \
unsigned char *_base; \
unsigned char *_end; \
long _cnt; \
int _file; \
unsigned int _flag; \
} *) fp)
# else
# define fp_ fp
# endif
# if defined _SCO_DS /* OpenServer */
# define _cnt __cnt
# define _ptr __ptr
# define _base __base
# define _flag __flag
# endif
#endif

54
gl/strdup.c Normal file
View File

@@ -0,0 +1,54 @@
/* Copyright (C) 1991, 1996-1998, 2002-2004, 2006-2007, 2009-2013 Free Software
Foundation, Inc.
This file is part of the GNU C Library.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, see <http://www.gnu.org/licenses/>. */
#ifndef _LIBC
# include <config.h>
#endif
/* Get specification. */
#include <string.h>
#include <stdlib.h>
#undef __strdup
#ifdef _LIBC
# undef strdup
#endif
#ifndef weak_alias
# define __strdup strdup
#endif
/* Duplicate S, returning an identical malloc'd string. */
char *
__strdup (const char *s)
{
size_t len = strlen (s) + 1;
void *new = malloc (len);
if (new == NULL)
return NULL;
return (char *) memcpy (new, s, len);
}
#ifdef libc_hidden_def
libc_hidden_def (__strdup)
#endif
#ifdef weak_alias
weak_alias (__strdup, strdup)
#endif

732
gl/sys_stat.in.h Normal file
View File

@@ -0,0 +1,732 @@
/* Provide a more complete sys/stat header file.
Copyright (C) 2005-2013 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, see <http://www.gnu.org/licenses/>. */
/* Written by Eric Blake, Paul Eggert, and Jim Meyering. */
/* This file is supposed to be used on platforms where <sys/stat.h> is
incomplete. It is intended to provide definitions and prototypes
needed by an application. Start with what the system provides. */
#if __GNUC__ >= 3
@PRAGMA_SYSTEM_HEADER@
#endif
@PRAGMA_COLUMNS@
#if defined __need_system_sys_stat_h
/* Special invocation convention. */
#@INCLUDE_NEXT@ @NEXT_SYS_STAT_H@
#else
/* Normal invocation convention. */
#ifndef _@GUARD_PREFIX@_SYS_STAT_H
/* Get nlink_t.
May also define off_t to a 64-bit type on native Windows. */
#include <sys/types.h>
/* Get struct timespec. */
#include <time.h>
/* The include_next requires a split double-inclusion guard. */
#@INCLUDE_NEXT@ @NEXT_SYS_STAT_H@
#ifndef _@GUARD_PREFIX@_SYS_STAT_H
#define _@GUARD_PREFIX@_SYS_STAT_H
/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
/* The definition of _GL_ARG_NONNULL is copied here. */
/* The definition of _GL_WARN_ON_USE is copied here. */
/* Before doing "#define mkdir rpl_mkdir" below, we need to include all
headers that may declare mkdir(). Native Windows platforms declare mkdir
in <io.h> and/or <direct.h>, not in <unistd.h>. */
#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
# include <io.h> /* mingw32, mingw64 */
# include <direct.h> /* mingw64, MSVC 9 */
#endif
/* Native Windows platforms declare umask() in <io.h>. */
#if 0 && ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__)
# include <io.h>
#endif
/* Large File Support on native Windows. */
#if @WINDOWS_64_BIT_ST_SIZE@
# define stat _stati64
#endif
#ifndef S_IFIFO
# ifdef _S_IFIFO
# define S_IFIFO _S_IFIFO
# endif
#endif
#ifndef S_IFMT
# define S_IFMT 0170000
#endif
#if STAT_MACROS_BROKEN
# undef S_ISBLK
# undef S_ISCHR
# undef S_ISDIR
# undef S_ISFIFO
# undef S_ISLNK
# undef S_ISNAM
# undef S_ISMPB
# undef S_ISMPC
# undef S_ISNWK
# undef S_ISREG
# undef S_ISSOCK
#endif
#ifndef S_ISBLK
# ifdef S_IFBLK
# define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
# else
# define S_ISBLK(m) 0
# endif
#endif
#ifndef S_ISCHR
# ifdef S_IFCHR
# define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
# else
# define S_ISCHR(m) 0
# endif
#endif
#ifndef S_ISDIR
# ifdef S_IFDIR
# define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
# else
# define S_ISDIR(m) 0
# endif
#endif
#ifndef S_ISDOOR /* Solaris 2.5 and up */
# define S_ISDOOR(m) 0
#endif
#ifndef S_ISFIFO
# ifdef S_IFIFO
# define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
# else
# define S_ISFIFO(m) 0
# endif
#endif
#ifndef S_ISLNK
# ifdef S_IFLNK
# define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
# else
# define S_ISLNK(m) 0
# endif
#endif
#ifndef S_ISMPB /* V7 */
# ifdef S_IFMPB
# define S_ISMPB(m) (((m) & S_IFMT) == S_IFMPB)
# define S_ISMPC(m) (((m) & S_IFMT) == S_IFMPC)
# else
# define S_ISMPB(m) 0
# define S_ISMPC(m) 0
# endif
#endif
#ifndef S_ISMPX /* AIX */
# define S_ISMPX(m) 0
#endif
#ifndef S_ISNAM /* Xenix */
# ifdef S_IFNAM
# define S_ISNAM(m) (((m) & S_IFMT) == S_IFNAM)
# else
# define S_ISNAM(m) 0
# endif
#endif
#ifndef S_ISNWK /* HP/UX */
# ifdef S_IFNWK
# define S_ISNWK(m) (((m) & S_IFMT) == S_IFNWK)
# else
# define S_ISNWK(m) 0
# endif
#endif
#ifndef S_ISPORT /* Solaris 10 and up */
# define S_ISPORT(m) 0
#endif
#ifndef S_ISREG
# ifdef S_IFREG
# define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
# else
# define S_ISREG(m) 0
# endif
#endif
#ifndef S_ISSOCK
# ifdef S_IFSOCK
# define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
# else
# define S_ISSOCK(m) 0
# endif
#endif
#ifndef S_TYPEISMQ
# define S_TYPEISMQ(p) 0
#endif
#ifndef S_TYPEISTMO
# define S_TYPEISTMO(p) 0
#endif
#ifndef S_TYPEISSEM
# ifdef S_INSEM
# define S_TYPEISSEM(p) (S_ISNAM ((p)->st_mode) && (p)->st_rdev == S_INSEM)
# else
# define S_TYPEISSEM(p) 0
# endif
#endif
#ifndef S_TYPEISSHM
# ifdef S_INSHD
# define S_TYPEISSHM(p) (S_ISNAM ((p)->st_mode) && (p)->st_rdev == S_INSHD)
# else
# define S_TYPEISSHM(p) 0
# endif
#endif
/* high performance ("contiguous data") */
#ifndef S_ISCTG
# define S_ISCTG(p) 0
#endif
/* Cray DMF (data migration facility): off line, with data */
#ifndef S_ISOFD
# define S_ISOFD(p) 0
#endif
/* Cray DMF (data migration facility): off line, with no data */
#ifndef S_ISOFL
# define S_ISOFL(p) 0
#endif
/* 4.4BSD whiteout */
#ifndef S_ISWHT
# define S_ISWHT(m) 0
#endif
/* If any of the following are undefined,
define them to their de facto standard values. */
#if !S_ISUID
# define S_ISUID 04000
#endif
#if !S_ISGID
# define S_ISGID 02000
#endif
/* S_ISVTX is a common extension to POSIX. */
#ifndef S_ISVTX
# define S_ISVTX 01000
#endif
#if !S_IRUSR && S_IREAD
# define S_IRUSR S_IREAD
#endif
#if !S_IRUSR
# define S_IRUSR 00400
#endif
#if !S_IRGRP
# define S_IRGRP (S_IRUSR >> 3)
#endif
#if !S_IROTH
# define S_IROTH (S_IRUSR >> 6)
#endif
#if !S_IWUSR && S_IWRITE
# define S_IWUSR S_IWRITE
#endif
#if !S_IWUSR
# define S_IWUSR 00200
#endif
#if !S_IWGRP
# define S_IWGRP (S_IWUSR >> 3)
#endif
#if !S_IWOTH
# define S_IWOTH (S_IWUSR >> 6)
#endif
#if !S_IXUSR && S_IEXEC
# define S_IXUSR S_IEXEC
#endif
#if !S_IXUSR
# define S_IXUSR 00100
#endif
#if !S_IXGRP
# define S_IXGRP (S_IXUSR >> 3)
#endif
#if !S_IXOTH
# define S_IXOTH (S_IXUSR >> 6)
#endif
#if !S_IRWXU
# define S_IRWXU (S_IRUSR | S_IWUSR | S_IXUSR)
#endif
#if !S_IRWXG
# define S_IRWXG (S_IRGRP | S_IWGRP | S_IXGRP)
#endif
#if !S_IRWXO
# define S_IRWXO (S_IROTH | S_IWOTH | S_IXOTH)
#endif
/* S_IXUGO is a common extension to POSIX. */
#if !S_IXUGO
# define S_IXUGO (S_IXUSR | S_IXGRP | S_IXOTH)
#endif
#ifndef S_IRWXUGO
# define S_IRWXUGO (S_IRWXU | S_IRWXG | S_IRWXO)
#endif
/* Macros for futimens and utimensat. */
#ifndef UTIME_NOW
# define UTIME_NOW (-1)
# define UTIME_OMIT (-2)
#endif
#if @GNULIB_FCHMODAT@
# if !@HAVE_FCHMODAT@
_GL_FUNCDECL_SYS (fchmodat, int,
(int fd, char const *file, mode_t mode, int flag)
_GL_ARG_NONNULL ((2)));
# endif
_GL_CXXALIAS_SYS (fchmodat, int,
(int fd, char const *file, mode_t mode, int flag));
_GL_CXXALIASWARN (fchmodat);
#elif defined GNULIB_POSIXCHECK
# undef fchmodat
# if HAVE_RAW_DECL_FCHMODAT
_GL_WARN_ON_USE (fchmodat, "fchmodat is not portable - "
"use gnulib module openat for portability");
# endif
#endif
#if @GNULIB_FSTAT@
# if @REPLACE_FSTAT@
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
# undef fstat
# define fstat rpl_fstat
# endif
_GL_FUNCDECL_RPL (fstat, int, (int fd, struct stat *buf) _GL_ARG_NONNULL ((2)));
_GL_CXXALIAS_RPL (fstat, int, (int fd, struct stat *buf));
# else
_GL_CXXALIAS_SYS (fstat, int, (int fd, struct stat *buf));
# endif
_GL_CXXALIASWARN (fstat);
#elif @WINDOWS_64_BIT_ST_SIZE@
/* Above, we define stat to _stati64. */
# define fstat _fstati64
#elif defined GNULIB_POSIXCHECK
# undef fstat
# if HAVE_RAW_DECL_FSTAT
_GL_WARN_ON_USE (fstat, "fstat has portability problems - "
"use gnulib module fstat for portability");
# endif
#endif
#if @GNULIB_FSTATAT@
# if @REPLACE_FSTATAT@
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
# undef fstatat
# define fstatat rpl_fstatat
# endif
_GL_FUNCDECL_RPL (fstatat, int,
(int fd, char const *name, struct stat *st, int flags)
_GL_ARG_NONNULL ((2, 3)));
_GL_CXXALIAS_RPL (fstatat, int,
(int fd, char const *name, struct stat *st, int flags));
# else
# if !@HAVE_FSTATAT@
_GL_FUNCDECL_SYS (fstatat, int,
(int fd, char const *name, struct stat *st, int flags)
_GL_ARG_NONNULL ((2, 3)));
# endif
_GL_CXXALIAS_SYS (fstatat, int,
(int fd, char const *name, struct stat *st, int flags));
# endif
_GL_CXXALIASWARN (fstatat);
#elif defined GNULIB_POSIXCHECK
# undef fstatat
# if HAVE_RAW_DECL_FSTATAT
_GL_WARN_ON_USE (fstatat, "fstatat is not portable - "
"use gnulib module openat for portability");
# endif
#endif
#if @GNULIB_FUTIMENS@
/* Use the rpl_ prefix also on Solaris <= 9, because on Solaris 9 our futimens
implementation relies on futimesat, which on Solaris 10 makes an invocation
to futimens that is meant to invoke the libc's futimens(), not gnulib's
futimens(). */
# if @REPLACE_FUTIMENS@ || (!@HAVE_FUTIMENS@ && defined __sun)
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
# undef futimens
# define futimens rpl_futimens
# endif
_GL_FUNCDECL_RPL (futimens, int, (int fd, struct timespec const times[2]));
_GL_CXXALIAS_RPL (futimens, int, (int fd, struct timespec const times[2]));
# else
# if !@HAVE_FUTIMENS@
_GL_FUNCDECL_SYS (futimens, int, (int fd, struct timespec const times[2]));
# endif
_GL_CXXALIAS_SYS (futimens, int, (int fd, struct timespec const times[2]));
# endif
# if @HAVE_FUTIMENS@
_GL_CXXALIASWARN (futimens);
# endif
#elif defined GNULIB_POSIXCHECK
# undef futimens
# if HAVE_RAW_DECL_FUTIMENS
_GL_WARN_ON_USE (futimens, "futimens is not portable - "
"use gnulib module futimens for portability");
# endif
#endif
#if @GNULIB_LCHMOD@
/* Change the mode of FILENAME to MODE, without dereferencing it if FILENAME
denotes a symbolic link. */
# if !@HAVE_LCHMOD@
/* The lchmod replacement follows symbolic links. Callers should take
this into account; lchmod should be applied only to arguments that
are known to not be symbolic links. On hosts that lack lchmod,
this can lead to race conditions between the check and the
invocation of lchmod, but we know of no workarounds that are
reliable in general. You might try requesting support for lchmod
from your operating system supplier. */
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
# define lchmod chmod
# endif
/* Need to cast, because on mingw, the second parameter of chmod is
int mode. */
_GL_CXXALIAS_RPL_CAST_1 (lchmod, chmod, int,
(const char *filename, mode_t mode));
# else
# if 0 /* assume already declared */
_GL_FUNCDECL_SYS (lchmod, int, (const char *filename, mode_t mode)
_GL_ARG_NONNULL ((1)));
# endif
_GL_CXXALIAS_SYS (lchmod, int, (const char *filename, mode_t mode));
# endif
# if @HAVE_LCHMOD@
_GL_CXXALIASWARN (lchmod);
# endif
#elif defined GNULIB_POSIXCHECK
# undef lchmod
# if HAVE_RAW_DECL_LCHMOD
_GL_WARN_ON_USE (lchmod, "lchmod is unportable - "
"use gnulib module lchmod for portability");
# endif
#endif
#if @GNULIB_LSTAT@
# if ! @HAVE_LSTAT@
/* mingw does not support symlinks, therefore it does not have lstat. But
without links, stat does just fine. */
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
# define lstat stat
# endif
_GL_CXXALIAS_RPL_1 (lstat, stat, int, (const char *name, struct stat *buf));
# elif @REPLACE_LSTAT@
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
# undef lstat
# define lstat rpl_lstat
# endif
_GL_FUNCDECL_RPL (lstat, int, (const char *name, struct stat *buf)
_GL_ARG_NONNULL ((1, 2)));
_GL_CXXALIAS_RPL (lstat, int, (const char *name, struct stat *buf));
# else
_GL_CXXALIAS_SYS (lstat, int, (const char *name, struct stat *buf));
# endif
# if @HAVE_LSTAT@
_GL_CXXALIASWARN (lstat);
# endif
#elif defined GNULIB_POSIXCHECK
# undef lstat
# if HAVE_RAW_DECL_LSTAT
_GL_WARN_ON_USE (lstat, "lstat is unportable - "
"use gnulib module lstat for portability");
# endif
#endif
#if @REPLACE_MKDIR@
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
# undef mkdir
# define mkdir rpl_mkdir
# endif
_GL_FUNCDECL_RPL (mkdir, int, (char const *name, mode_t mode)
_GL_ARG_NONNULL ((1)));
_GL_CXXALIAS_RPL (mkdir, int, (char const *name, mode_t mode));
#else
/* mingw's _mkdir() function has 1 argument, but we pass 2 arguments.
Additionally, it declares _mkdir (and depending on compile flags, an
alias mkdir), only in the nonstandard includes <direct.h> and <io.h>,
which are included above. */
# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
# if !GNULIB_defined_rpl_mkdir
static int
rpl_mkdir (char const *name, mode_t mode)
{
return _mkdir (name);
}
# define GNULIB_defined_rpl_mkdir 1
# endif
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
# define mkdir rpl_mkdir
# endif
_GL_CXXALIAS_RPL (mkdir, int, (char const *name, mode_t mode));
# else
_GL_CXXALIAS_SYS (mkdir, int, (char const *name, mode_t mode));
# endif
#endif
_GL_CXXALIASWARN (mkdir);
#if @GNULIB_MKDIRAT@
# if !@HAVE_MKDIRAT@
_GL_FUNCDECL_SYS (mkdirat, int, (int fd, char const *file, mode_t mode)
_GL_ARG_NONNULL ((2)));
# endif
_GL_CXXALIAS_SYS (mkdirat, int, (int fd, char const *file, mode_t mode));
_GL_CXXALIASWARN (mkdirat);
#elif defined GNULIB_POSIXCHECK
# undef mkdirat
# if HAVE_RAW_DECL_MKDIRAT
_GL_WARN_ON_USE (mkdirat, "mkdirat is not portable - "
"use gnulib module openat for portability");
# endif
#endif
#if @GNULIB_MKFIFO@
# if @REPLACE_MKFIFO@
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
# undef mkfifo
# define mkfifo rpl_mkfifo
# endif
_GL_FUNCDECL_RPL (mkfifo, int, (char const *file, mode_t mode)
_GL_ARG_NONNULL ((1)));
_GL_CXXALIAS_RPL (mkfifo, int, (char const *file, mode_t mode));
# else
# if !@HAVE_MKFIFO@
_GL_FUNCDECL_SYS (mkfifo, int, (char const *file, mode_t mode)
_GL_ARG_NONNULL ((1)));
# endif
_GL_CXXALIAS_SYS (mkfifo, int, (char const *file, mode_t mode));
# endif
_GL_CXXALIASWARN (mkfifo);
#elif defined GNULIB_POSIXCHECK
# undef mkfifo
# if HAVE_RAW_DECL_MKFIFO
_GL_WARN_ON_USE (mkfifo, "mkfifo is not portable - "
"use gnulib module mkfifo for portability");
# endif
#endif
#if @GNULIB_MKFIFOAT@
# if !@HAVE_MKFIFOAT@
_GL_FUNCDECL_SYS (mkfifoat, int, (int fd, char const *file, mode_t mode)
_GL_ARG_NONNULL ((2)));
# endif
_GL_CXXALIAS_SYS (mkfifoat, int, (int fd, char const *file, mode_t mode));
_GL_CXXALIASWARN (mkfifoat);
#elif defined GNULIB_POSIXCHECK
# undef mkfifoat
# if HAVE_RAW_DECL_MKFIFOAT
_GL_WARN_ON_USE (mkfifoat, "mkfifoat is not portable - "
"use gnulib module mkfifoat for portability");
# endif
#endif
#if @GNULIB_MKNOD@
# if @REPLACE_MKNOD@
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
# undef mknod
# define mknod rpl_mknod
# endif
_GL_FUNCDECL_RPL (mknod, int, (char const *file, mode_t mode, dev_t dev)
_GL_ARG_NONNULL ((1)));
_GL_CXXALIAS_RPL (mknod, int, (char const *file, mode_t mode, dev_t dev));
# else
# if !@HAVE_MKNOD@
_GL_FUNCDECL_SYS (mknod, int, (char const *file, mode_t mode, dev_t dev)
_GL_ARG_NONNULL ((1)));
# endif
/* Need to cast, because on OSF/1 5.1, the third parameter is '...'. */
_GL_CXXALIAS_SYS_CAST (mknod, int, (char const *file, mode_t mode, dev_t dev));
# endif
_GL_CXXALIASWARN (mknod);
#elif defined GNULIB_POSIXCHECK
# undef mknod
# if HAVE_RAW_DECL_MKNOD
_GL_WARN_ON_USE (mknod, "mknod is not portable - "
"use gnulib module mknod for portability");
# endif
#endif
#if @GNULIB_MKNODAT@
# if !@HAVE_MKNODAT@
_GL_FUNCDECL_SYS (mknodat, int,
(int fd, char const *file, mode_t mode, dev_t dev)
_GL_ARG_NONNULL ((2)));
# endif
_GL_CXXALIAS_SYS (mknodat, int,
(int fd, char const *file, mode_t mode, dev_t dev));
_GL_CXXALIASWARN (mknodat);
#elif defined GNULIB_POSIXCHECK
# undef mknodat
# if HAVE_RAW_DECL_MKNODAT
_GL_WARN_ON_USE (mknodat, "mknodat is not portable - "
"use gnulib module mkfifoat for portability");
# endif
#endif
#if @GNULIB_STAT@
# if @REPLACE_STAT@
/* We can't use the object-like #define stat rpl_stat, because of
struct stat. This means that rpl_stat will not be used if the user
does (stat)(a,b). Oh well. */
# if defined _AIX && defined stat && defined _LARGE_FILES
/* With _LARGE_FILES defined, AIX (only) defines stat to stat64,
so we have to replace stat64() instead of stat(). */
# undef stat64
# define stat64(name, st) rpl_stat (name, st)
# elif @WINDOWS_64_BIT_ST_SIZE@
/* Above, we define stat to _stati64. */
# if defined __MINGW32__ && defined _stati64
# ifndef _USE_32BIT_TIME_T
/* The system headers define _stati64 to _stat64. */
# undef _stat64
# define _stat64(name, st) rpl_stat (name, st)
# endif
# elif defined _MSC_VER && defined _stati64
# ifdef _USE_32BIT_TIME_T
/* The system headers define _stati64 to _stat32i64. */
# undef _stat32i64
# define _stat32i64(name, st) rpl_stat (name, st)
# else
/* The system headers define _stati64 to _stat64. */
# undef _stat64
# define _stat64(name, st) rpl_stat (name, st)
# endif
# else
# undef _stati64
# define _stati64(name, st) rpl_stat (name, st)
# endif
# elif defined __MINGW32__ && defined stat
# ifdef _USE_32BIT_TIME_T
/* The system headers define stat to _stat32i64. */
# undef _stat32i64
# define _stat32i64(name, st) rpl_stat (name, st)
# else
/* The system headers define stat to _stat64. */
# undef _stat64
# define _stat64(name, st) rpl_stat (name, st)
# endif
# elif defined _MSC_VER && defined stat
# ifdef _USE_32BIT_TIME_T
/* The system headers define stat to _stat32. */
# undef _stat32
# define _stat32(name, st) rpl_stat (name, st)
# else
/* The system headers define stat to _stat64i32. */
# undef _stat64i32
# define _stat64i32(name, st) rpl_stat (name, st)
# endif
# else /* !(_AIX ||__MINGW32__ || _MSC_VER) */
# undef stat
# define stat(name, st) rpl_stat (name, st)
# endif /* !_LARGE_FILES */
_GL_EXTERN_C int stat (const char *name, struct stat *buf)
_GL_ARG_NONNULL ((1, 2));
# endif
#elif defined GNULIB_POSIXCHECK
# undef stat
# if HAVE_RAW_DECL_STAT
_GL_WARN_ON_USE (stat, "stat is unportable - "
"use gnulib module stat for portability");
# endif
#endif
#if @GNULIB_UTIMENSAT@
/* Use the rpl_ prefix also on Solaris <= 9, because on Solaris 9 our utimensat
implementation relies on futimesat, which on Solaris 10 makes an invocation
to utimensat that is meant to invoke the libc's utimensat(), not gnulib's
utimensat(). */
# if @REPLACE_UTIMENSAT@ || (!@HAVE_UTIMENSAT@ && defined __sun)
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
# undef utimensat
# define utimensat rpl_utimensat
# endif
_GL_FUNCDECL_RPL (utimensat, int, (int fd, char const *name,
struct timespec const times[2], int flag)
_GL_ARG_NONNULL ((2)));
_GL_CXXALIAS_RPL (utimensat, int, (int fd, char const *name,
struct timespec const times[2], int flag));
# else
# if !@HAVE_UTIMENSAT@
_GL_FUNCDECL_SYS (utimensat, int, (int fd, char const *name,
struct timespec const times[2], int flag)
_GL_ARG_NONNULL ((2)));
# endif
_GL_CXXALIAS_SYS (utimensat, int, (int fd, char const *name,
struct timespec const times[2], int flag));
# endif
# if @HAVE_UTIMENSAT@
_GL_CXXALIASWARN (utimensat);
# endif
#elif defined GNULIB_POSIXCHECK
# undef utimensat
# if HAVE_RAW_DECL_UTIMENSAT
_GL_WARN_ON_USE (utimensat, "utimensat is not portable - "
"use gnulib module utimensat for portability");
# endif
#endif
#endif /* _@GUARD_PREFIX@_SYS_STAT_H */
#endif /* _@GUARD_PREFIX@_SYS_STAT_H */
#endif

View File

@@ -61,8 +61,10 @@
/* mingw, MSVC, BeOS, Haiku declare environ in <stdlib.h>, not in /* mingw, MSVC, BeOS, Haiku declare environ in <stdlib.h>, not in
<unistd.h>. */ <unistd.h>. */
/* Solaris declares getcwd not only in <unistd.h> but also in <stdlib.h>. */ /* Solaris declares getcwd not only in <unistd.h> but also in <stdlib.h>. */
/* OSF Tru64 Unix cannot see gnulib rpl_strtod when system <stdlib.h> is
included here. */
/* But avoid namespace pollution on glibc systems. */ /* But avoid namespace pollution on glibc systems. */
#ifndef __GLIBC__ #if !defined __GLIBC__ && !defined __osf__
# define __need_system_stdlib_h # define __need_system_stdlib_h
# include <stdlib.h> # include <stdlib.h>
# undef __need_system_stdlib_h # undef __need_system_stdlib_h

View File

@@ -24,9 +24,15 @@ ocserv_SOURCES += ocserv-args.def ocserv-args.c ocserv-args.h
ocserv_LDADD = ../gl/libgnu.a ../libopts/libopts.a ocserv_LDADD = ../gl/libgnu.a ../libopts/libopts.a
ocserv_LDADD += $(LIBGNUTLS_LIBS) $(GDBM_LIBS) $(PAM_LIBS) $(LIBUTIL) \ ocserv_LDADD += $(LIBGNUTLS_LIBS) $(GDBM_LIBS) $(PAM_LIBS) $(LIBUTIL) \
$(LIBSECCOMP) $(LIBWRAP) $(LIBSECCOMP) $(LIBWRAP) $(LIBCRYPT)
ocserv-args.c ocserv-args.h: $(srcdir)/ocserv-args.def ocserv-args.c ocserv-args.h: $(srcdir)/ocserv-args.def
@AUTOGEN@ $< @AUTOGEN@ $<
ocpasswd_SOURCES += ocpasswd.c ocpasswd_SOURCES = ocpasswd.c ocpasswd-args.def ocpasswd-args.c ocpasswd-args.h
ocpasswd_LDADD = ../gl/libgnu.a ../libopts/libopts.a
ocpasswd_LDADD += $(LIBGNUTLS_LIBS) $(LIBCRYPT)
ocpasswd-args.c ocpasswd-args.h: $(srcdir)/ocpasswd-args.def
@AUTOGEN@ $<

490
src/ocpasswd-args.c Normal file
View File

@@ -0,0 +1,490 @@
/* -*- buffer-read-only: t -*- vi: set ro:
*
* DO NOT EDIT THIS FILE (ocpasswd-args.c)
*
* It has been AutoGen-ed March 14, 2013 at 01:27:04 PM by AutoGen 5.16
* From the definitions ocpasswd-args.def
* and the template file options
*
* Generated from AutoOpts 36:4:11 templates.
*
* AutoOpts is a copyrighted work. This source file is not encumbered
* by AutoOpts licensing, but is provided under the licensing terms chosen
* by the ocpasswd author or copyright holder. AutoOpts is
* licensed under the terms of the LGPL. The redistributable library
* (``libopts'') is licensed under the terms of either the LGPL or, at the
* users discretion, the BSD license. See the AutoOpts and/or libopts sources
* for details.
*
* The ocpasswd program is copyrighted and licensed
* under the following terms:
*
* Copyright (C) 2013 Nikos Mavrogiannopoulos, all rights reserved.
* This is free software. It is licensed for use, modification and
* redistribution under the terms of the
* GNU General Public License, version 2 <http://gnu.org/licenses/gpl.html>
*
* ocpasswd is free software: you can redistribute it and/or modify it
* under the terms of version 2 of the GNU General Public License,
* as published by the Free Software Foundation.
*
* ocpasswd is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License,
* version 2, along with this program.
* If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __doxygen__
#define OPTION_CODE_COMPILE 1
#include "ocpasswd-args.h"
#include <sys/types.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#ifdef __cplusplus
extern "C" {
#endif
extern FILE * option_usage_fp;
/* TRANSLATORS: choose the translation for option names wisely because you
cannot ever change your mind. */
#define zCopyright (ocpasswd_opt_strs+0)
#define zLicenseDescrip (ocpasswd_opt_strs+256)
#ifndef NULL
# define NULL 0
#endif
/*
* ocpasswd option static const strings
*/
static char const ocpasswd_opt_strs[1443] =
/* 0 */ "ocpasswd 0.0.3\n"
"Copyright (C) 2013 Nikos Mavrogiannopoulos, all rights reserved.\n"
"This is free software. It is licensed for use, modification and\n"
"redistribution under the terms of the\n"
"GNU General Public License, version 2 <http://gnu.org/licenses/gpl.html>\n\0"
/* 256 */ "ocpasswd is free software: you can redistribute it and/or modify it under\n"
"the terms of version 2 of the GNU General Public License, as published by\n"
"the Free Software Foundation.\n\n"
"ocpasswd is distributed in the hope that it will be useful, but WITHOUT ANY\n"
"WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\n"
"FOR A PARTICULAR PURPOSE. See the GNU General Public License for more\n"
"details.\n\n"
"You should have received a copy of the GNU General Public License, version\n"
"2, along with this program. If not, see <http://www.gnu.org/licenses/>.\n\0"
/* 815 */ "Password file\0"
/* 829 */ "PASSWD\0"
/* 836 */ "passwd\0"
/* 843 */ "User name\0"
/* 853 */ "USERNAME\0"
/* 862 */ "username\0"
/* 871 */ "User's group name\0"
/* 889 */ "GROUPNAME\0"
/* 899 */ "groupname\0"
/* 909 */ "Display extended usage information and exit\0"
/* 953 */ "help\0"
/* 958 */ "Extended usage information passed thru pager\0"
/* 1003 */ "more-help\0"
/* 1013 */ "Output version information and exit\0"
/* 1049 */ "version\0"
/* 1057 */ "OCPASSWD\0"
/* 1066 */ "ocpasswd - OpenConnect server - Ver. 0.0.3\n"
"USAGE: %s [ -<flag> [<val>] | --<name>[{=| }<val>] ]...\n\0"
/* 1167 */ "openconnect-devel@lists.infradead.org\0"
/* 1205 */ "\n\n\0"
/* 1208 */ "\n"
"This program is openconnect password (ocpasswd) utility. It allows the\n"
"generation and handling of a 'plain' password file used by ocserv.\n\0"
/* 1349 */ "ocpasswd 0.0.3\0"
/* 1364 */ "Usage: ocpasswd [options] -c [passwd]\n"
"ocpasswd --help for usage instructions.\n";
/*
* passwd option description:
*/
#define PASSWD_DESC (ocpasswd_opt_strs+815)
#define PASSWD_NAME (ocpasswd_opt_strs+829)
#define PASSWD_name (ocpasswd_opt_strs+836)
#define PASSWD_FLAGS (OPTST_DISABLED \
| OPTST_SET_ARGTYPE(OPARG_TYPE_FILE))
/*
* username option description:
*/
#define USERNAME_DESC (ocpasswd_opt_strs+843)
#define USERNAME_NAME (ocpasswd_opt_strs+853)
#define USERNAME_name (ocpasswd_opt_strs+862)
#define USERNAME_FLAGS (OPTST_DISABLED \
| OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
/*
* groupname option description:
*/
#define GROUPNAME_DESC (ocpasswd_opt_strs+871)
#define GROUPNAME_NAME (ocpasswd_opt_strs+889)
#define GROUPNAME_name (ocpasswd_opt_strs+899)
#define GROUPNAME_FLAGS (OPTST_DISABLED \
| OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
/*
* Help/More_Help/Version option descriptions:
*/
#define HELP_DESC (ocpasswd_opt_strs+909)
#define HELP_name (ocpasswd_opt_strs+953)
#ifdef HAVE_WORKING_FORK
#define MORE_HELP_DESC (ocpasswd_opt_strs+958)
#define MORE_HELP_name (ocpasswd_opt_strs+1003)
#define MORE_HELP_FLAGS (OPTST_IMM | OPTST_NO_INIT)
#else
#define MORE_HELP_DESC NULL
#define MORE_HELP_name NULL
#define MORE_HELP_FLAGS (OPTST_OMITTED | OPTST_NO_INIT)
#endif
#ifdef NO_OPTIONAL_OPT_ARGS
# define VER_FLAGS (OPTST_IMM | OPTST_NO_INIT)
#else
# define VER_FLAGS (OPTST_SET_ARGTYPE(OPARG_TYPE_STRING) | \
OPTST_ARG_OPTIONAL | OPTST_IMM | OPTST_NO_INIT)
#endif
#define VER_DESC (ocpasswd_opt_strs+1013)
#define VER_name (ocpasswd_opt_strs+1049)
/*
* Declare option callback procedures
*/
extern tOptProc
optionBooleanVal, optionNestedVal, optionNumericVal,
optionPagedUsage, optionPrintVersion, optionResetOpt,
optionStackArg, optionTimeDate, optionTimeVal,
optionUnstackArg, optionVendorOption;
static tOptProc
doOptPasswd, doUsageOpt;
#define VER_PROC optionPrintVersion
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/**
* Define the ocpasswd Option Descriptions.
* This is an array of OPTION_CT entries, one for each
* option that the ocpasswd program responds to.
*/
static tOptDesc optDesc[OPTION_CT] = {
{ /* entry idx, value */ 0, VALUE_OPT_PASSWD,
/* equiv idx, value */ 0, VALUE_OPT_PASSWD,
/* equivalenced to */ NO_EQUIVALENT,
/* min, max, act ct */ 0, 1, 0,
/* opt state flags */ PASSWD_FLAGS, 0,
/* last opt argumnt */ { NULL }, /* --passwd */
/* arg list/cookie */ NULL,
/* must/cannot opts */ NULL, NULL,
/* option proc */ doOptPasswd,
/* desc, NAME, name */ PASSWD_DESC, PASSWD_NAME, PASSWD_name,
/* disablement strs */ NULL, NULL },
{ /* entry idx, value */ 1, VALUE_OPT_USERNAME,
/* equiv idx, value */ 1, VALUE_OPT_USERNAME,
/* equivalenced to */ NO_EQUIVALENT,
/* min, max, act ct */ 0, 1, 0,
/* opt state flags */ USERNAME_FLAGS, 0,
/* last opt argumnt */ { NULL }, /* --username */
/* arg list/cookie */ NULL,
/* must/cannot opts */ NULL, NULL,
/* option proc */ NULL,
/* desc, NAME, name */ USERNAME_DESC, USERNAME_NAME, USERNAME_name,
/* disablement strs */ NULL, NULL },
{ /* entry idx, value */ 2, VALUE_OPT_GROUPNAME,
/* equiv idx, value */ 2, VALUE_OPT_GROUPNAME,
/* equivalenced to */ NO_EQUIVALENT,
/* min, max, act ct */ 0, 1, 0,
/* opt state flags */ GROUPNAME_FLAGS, 0,
/* last opt argumnt */ { NULL }, /* --groupname */
/* arg list/cookie */ NULL,
/* must/cannot opts */ NULL, NULL,
/* option proc */ NULL,
/* desc, NAME, name */ GROUPNAME_DESC, GROUPNAME_NAME, GROUPNAME_name,
/* disablement strs */ NULL, NULL },
{ /* entry idx, value */ INDEX_OPT_VERSION, VALUE_OPT_VERSION,
/* equiv idx value */ NO_EQUIVALENT, VALUE_OPT_VERSION,
/* equivalenced to */ NO_EQUIVALENT,
/* min, max, act ct */ 0, 1, 0,
/* opt state flags */ VER_FLAGS, 0,
/* last opt argumnt */ { NULL },
/* arg list/cookie */ NULL,
/* must/cannot opts */ NULL, NULL,
/* option proc */ VER_PROC,
/* desc, NAME, name */ VER_DESC, NULL, VER_name,
/* disablement strs */ NULL, NULL },
{ /* entry idx, value */ INDEX_OPT_HELP, VALUE_OPT_HELP,
/* equiv idx value */ NO_EQUIVALENT, VALUE_OPT_HELP,
/* equivalenced to */ NO_EQUIVALENT,
/* min, max, act ct */ 0, 1, 0,
/* opt state flags */ OPTST_IMM | OPTST_NO_INIT, 0,
/* last opt argumnt */ { NULL },
/* arg list/cookie */ NULL,
/* must/cannot opts */ NULL, NULL,
/* option proc */ doUsageOpt,
/* desc, NAME, name */ HELP_DESC, NULL, HELP_name,
/* disablement strs */ NULL, NULL },
{ /* entry idx, value */ INDEX_OPT_MORE_HELP, VALUE_OPT_MORE_HELP,
/* equiv idx value */ NO_EQUIVALENT, VALUE_OPT_MORE_HELP,
/* equivalenced to */ NO_EQUIVALENT,
/* min, max, act ct */ 0, 1, 0,
/* opt state flags */ MORE_HELP_FLAGS, 0,
/* last opt argumnt */ { NULL },
/* arg list/cookie */ NULL,
/* must/cannot opts */ NULL, NULL,
/* option proc */ optionPagedUsage,
/* desc, NAME, name */ MORE_HELP_DESC, NULL, MORE_HELP_name,
/* disablement strs */ NULL, NULL }
};
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* Define the ocpasswd Option Environment
*/
#define zPROGNAME (ocpasswd_opt_strs+1057)
#define zUsageTitle (ocpasswd_opt_strs+1066)
#define zRcName NULL
#define apzHomeList NULL
#define zBugsAddr (ocpasswd_opt_strs+1167)
#define zExplain (ocpasswd_opt_strs+1205)
#define zDetail (ocpasswd_opt_strs+1208)
#define zFullVersion (ocpasswd_opt_strs+1349)
/* extracted from optcode.tlib near line 350 */
#if defined(ENABLE_NLS)
# define OPTPROC_BASE OPTPROC_TRANSLATE | OPTPROC_NXLAT_OPT
static tOptionXlateProc translate_option_strings;
#else
# define OPTPROC_BASE OPTPROC_NONE
# define translate_option_strings NULL
#endif /* ENABLE_NLS */
#define ocpasswd_full_usage (NULL)
#define ocpasswd_short_usage (ocpasswd_opt_strs+1364)
#endif /* not defined __doxygen__ */
/*
* Create the static procedure(s) declared above.
*/
/**
* The callout function that invokes the optionUsage function.
*
* @param pOptions the AutoOpts option description structure
* @param pOptDesc the descriptor for the "help" (usage) option.
* @noreturn
*/
static void
doUsageOpt(tOptions * pOptions, tOptDesc * pOptDesc)
{
optionUsage(&ocpasswdOptions, OCPASSWD_EXIT_SUCCESS);
/* NOTREACHED */
(void)pOptDesc;
(void)pOptions;
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/**
* Code to handle the passwd option.
*
* @param pOptions the ocpasswd options data structure
* @param pOptDesc the option descriptor for this option.
*/
static void
doOptPasswd(tOptions* pOptions, tOptDesc* pOptDesc)
{
static teOptFileType const type =
FTYPE_MODE_MUST_EXIST + FTYPE_MODE_NO_OPEN;
static tuFileMode mode;
#ifndef O_CLOEXEC
# define O_CLOEXEC 0
#endif
mode.file_flags = O_CLOEXEC;
optionFileCheck(pOptions, pOptDesc, type, mode);
}
/* extracted from optmain.tlib near line 1113 */
/**
* The directory containing the data associated with ocpasswd.
*/
#ifndef PKGDATADIR
# define PKGDATADIR ""
#endif
/**
* Information about the person or institution that packaged ocpasswd
* for the current distribution.
*/
#ifndef WITH_PACKAGER
# define ocpasswd_packager_info NULL
#else
static char const ocpasswd_packager_info[] =
"Packaged by " WITH_PACKAGER
# ifdef WITH_PACKAGER_VERSION
" ("WITH_PACKAGER_VERSION")"
# endif
# ifdef WITH_PACKAGER_BUG_REPORTS
"\nReport ocpasswd bugs to " WITH_PACKAGER_BUG_REPORTS
# endif
"\n";
#endif
#ifndef __doxygen__
#endif /* __doxygen__ */
/**
* The option definitions for ocpasswd. The one structure that
* binds them all.
*/
tOptions ocpasswdOptions = {
OPTIONS_STRUCT_VERSION,
0, NULL, /* original argc + argv */
( OPTPROC_BASE
+ OPTPROC_ERRSTOP
+ OPTPROC_SHORTOPT
+ OPTPROC_LONGOPT
+ OPTPROC_NO_REQ_OPT
+ OPTPROC_NO_ARGS
+ OPTPROC_GNUUSAGE
+ OPTPROC_MISUSE ),
0, NULL, /* current option index, current option */
NULL, NULL, zPROGNAME,
zRcName, zCopyright, zLicenseDescrip,
zFullVersion, apzHomeList, zUsageTitle,
zExplain, zDetail, optDesc,
zBugsAddr, /* address to send bugs to */
NULL, NULL, /* extensions/saved state */
optionUsage, /* usage procedure */
translate_option_strings, /* translation procedure */
/*
* Indexes to special options
*/
{ INDEX_OPT_MORE_HELP, /* more-help option index */
NO_EQUIVALENT, /* save option index */
NO_EQUIVALENT, /* '-#' option index */
NO_EQUIVALENT /* index of default opt */
},
6 /* full option count */, 3 /* user option count */,
ocpasswd_full_usage, ocpasswd_short_usage,
NULL, NULL,
PKGDATADIR, ocpasswd_packager_info
};
#if ENABLE_NLS
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <autoopts/usage-txt.h>
static char* AO_gettext(char const* pz);
static void coerce_it(void** s);
/**
* AutoGen specific wrapper function for gettext.
* It relies on the macro _() to convert from English to the target
* language, then strdup-duplicates the result string.
*
* @param[in] pz the input text used as a lookup key.
* @returns the translated text (if there is one),
* or the original text (if not).
*/
static char *
AO_gettext(char const* pz)
{
char* pzRes;
if (pz == NULL)
return NULL;
pzRes = _(pz);
if (pzRes == pz)
return pzRes;
pzRes = strdup(pzRes);
if (pzRes == NULL) {
fputs(_("No memory for duping translated strings\n"), stderr);
exit(OCPASSWD_EXIT_FAILURE);
}
return pzRes;
}
static void coerce_it(void** s) { *s = AO_gettext(*s);
}
/**
* Translate all the translatable strings in the ocpasswdOptions
* structure defined above. This is done only once.
*/
static void
translate_option_strings(void)
{
tOptions * const pOpt = &ocpasswdOptions;
/*
* Guard against re-translation. It won't work. The strings will have
* been changed by the first pass through this code. One shot only.
*/
if (option_usage_text.field_ct != 0) {
/*
* Do the translations. The first pointer follows the field count
* field. The field count field is the size of a pointer.
*/
tOptDesc * pOD = pOpt->pOptDesc;
char ** ppz = (char**)(void*)&(option_usage_text);
int ix = option_usage_text.field_ct;
do {
ppz++;
*ppz = AO_gettext(*ppz);
} while (--ix > 0);
coerce_it((void*)&(pOpt->pzCopyright));
coerce_it((void*)&(pOpt->pzCopyNotice));
coerce_it((void*)&(pOpt->pzFullVersion));
coerce_it((void*)&(pOpt->pzUsageTitle));
coerce_it((void*)&(pOpt->pzExplain));
coerce_it((void*)&(pOpt->pzDetail));
coerce_it((void*)&(pOpt->pzPackager));
coerce_it((void*)&(pOpt->pzShortUsage));
option_usage_text.field_ct = 0;
for (ix = pOpt->optCt; ix > 0; ix--, pOD++)
coerce_it((void*)&(pOD->pzText));
}
if ((pOpt->fOptSet & OPTPROC_NXLAT_OPT_CFG) == 0) {
tOptDesc * pOD = pOpt->pOptDesc;
int ix;
for (ix = pOpt->optCt; ix > 0; ix--, pOD++) {
coerce_it((void*)&(pOD->pz_Name));
coerce_it((void*)&(pOD->pz_DisableName));
coerce_it((void*)&(pOD->pz_DisablePfx));
}
/* prevent re-translation */
ocpasswdOptions.fOptSet |= OPTPROC_NXLAT_OPT_CFG | OPTPROC_NXLAT_OPT;
}
}
#endif /* ENABLE_NLS */
#ifdef __cplusplus
}
#endif
/* ocpasswd-args.c ends here */

69
src/ocpasswd-args.def Normal file
View File

@@ -0,0 +1,69 @@
AutoGen Definitions options;
prog-name = ocpasswd;
prog-title = "OpenConnect server";
prog-desc = "OpenConnect VPN server.";
disable-save;
no-xlate = opt;
gnu-usage;
config-header = config.h;
long-opts;
no-misuse-usage;
short-usage = "Usage: ocpasswd [options] -c [passwd]\nocpasswd --help for usage instructions.\n";
explain = "";
#include version.def
detail = "This program is openconnect password (ocpasswd) utility. It allows the generation
and handling of a 'plain' password file used by ocserv.";
copyright = {
date = "2013";
owner = "Nikos Mavrogiannopoulos";
author = "Nikos Mavrogiannopoulos";
eaddr = "openconnect-devel@lists.infradead.org";
type = gplv2;
};
flag = {
name = passwd;
value = c;
arg-type = file;
file-exists = yes;
descrip = "Password file";
doc = "";
};
flag = {
name = username;
value = u;
arg-type = string;
descrip = "User name";
doc = "";
};
flag = {
name = groupname;
value = g;
arg-type = string;
descrip = "User's group name";
doc = "";
};
help-value = h;
doc-section = {
ds-type = 'FILES';
ds-format = 'texi';
ds-text = <<-_EOT_
@subheading Password file format
The password format of ocpasswd is as follows.
@example
username:groupname:encoded-password
@end example
The crypt(3) encoding is used for the encoded-password.
_EOT_;
};

180
src/ocpasswd-args.h Normal file
View File

@@ -0,0 +1,180 @@
/* -*- buffer-read-only: t -*- vi: set ro:
*
* DO NOT EDIT THIS FILE (ocpasswd-args.h)
*
* It has been AutoGen-ed March 14, 2013 at 01:27:04 PM by AutoGen 5.16
* From the definitions ocpasswd-args.def
* and the template file options
*
* Generated from AutoOpts 36:4:11 templates.
*
* AutoOpts is a copyrighted work. This header file is not encumbered
* by AutoOpts licensing, but is provided under the licensing terms chosen
* by the ocpasswd author or copyright holder. AutoOpts is
* licensed under the terms of the LGPL. The redistributable library
* (``libopts'') is licensed under the terms of either the LGPL or, at the
* users discretion, the BSD license. See the AutoOpts and/or libopts sources
* for details.
*
* The ocpasswd program is copyrighted and licensed
* under the following terms:
*
* Copyright (C) 2013 Nikos Mavrogiannopoulos, all rights reserved.
* This is free software. It is licensed for use, modification and
* redistribution under the terms of the
* GNU General Public License, version 2 <http://gnu.org/licenses/gpl.html>
*
* ocpasswd is free software: you can redistribute it and/or modify it
* under the terms of version 2 of the GNU General Public License,
* as published by the Free Software Foundation.
*
* ocpasswd is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License,
* version 2, along with this program.
* If not, see <http://www.gnu.org/licenses/>.
*/
/*
* This file contains the programmatic interface to the Automated
* Options generated for the ocpasswd program.
* These macros are documented in the AutoGen info file in the
* "AutoOpts" chapter. Please refer to that doc for usage help.
*/
#ifndef AUTOOPTS_OCPASSWD_ARGS_H_GUARD
#define AUTOOPTS_OCPASSWD_ARGS_H_GUARD 1
#include "config.h"
#include <autoopts/options.h>
/*
* Ensure that the library used for compiling this generated header is at
* least as new as the version current when the header template was released
* (not counting patch version increments). Also ensure that the oldest
* tolerable version is at least as old as what was current when the header
* template was released.
*/
#define AO_TEMPLATE_VERSION 147460
#if (AO_TEMPLATE_VERSION < OPTIONS_MINIMUM_VERSION) \
|| (AO_TEMPLATE_VERSION > OPTIONS_STRUCT_VERSION)
# error option template version mismatches autoopts/options.h header
Choke Me.
#endif
/*
* Enumeration of each option:
*/
typedef enum {
INDEX_OPT_PASSWD = 0,
INDEX_OPT_USERNAME = 1,
INDEX_OPT_GROUPNAME = 2,
INDEX_OPT_VERSION = 3,
INDEX_OPT_HELP = 4,
INDEX_OPT_MORE_HELP = 5
} teOptIndex;
#define OPTION_CT 6
#define OCPASSWD_VERSION "0.0.3"
#define OCPASSWD_FULL_VERSION "ocpasswd 0.0.3"
/*
* Interface defines for all options. Replace "n" with the UPPER_CASED
* option name (as in the teOptIndex enumeration above).
* e.g. HAVE_OPT(PASSWD)
*/
#define DESC(n) (ocpasswdOptions.pOptDesc[INDEX_OPT_## n])
#define HAVE_OPT(n) (! UNUSED_OPT(& DESC(n)))
#define OPT_ARG(n) (DESC(n).optArg.argString)
#define STATE_OPT(n) (DESC(n).fOptState & OPTST_SET_MASK)
#define COUNT_OPT(n) (DESC(n).optOccCt)
#define ISSEL_OPT(n) (SELECTED_OPT(&DESC(n)))
#define ISUNUSED_OPT(n) (UNUSED_OPT(& DESC(n)))
#define ENABLED_OPT(n) (! DISABLED_OPT(& DESC(n)))
#define STACKCT_OPT(n) (((tArgList*)(DESC(n).optCookie))->useCt)
#define STACKLST_OPT(n) (((tArgList*)(DESC(n).optCookie))->apzArgs)
#define CLEAR_OPT(n) STMTS( \
DESC(n).fOptState &= OPTST_PERSISTENT_MASK; \
if ((DESC(n).fOptState & OPTST_INITENABLED) == 0) \
DESC(n).fOptState |= OPTST_DISABLED; \
DESC(n).optCookie = NULL )
/* * * * * *
*
* Enumeration of ocpasswd exit codes
*/
typedef enum {
OCPASSWD_EXIT_SUCCESS = 0,
OCPASSWD_EXIT_FAILURE = 1,
OCPASSWD_EXIT_LIBOPTS_FAILURE = 70
} ocpasswd_exit_code_t;
/* * * * * *
*
* Interface defines for specific options.
*/
#define VALUE_OPT_PASSWD 'c'
#define VALUE_OPT_USERNAME 'u'
#define VALUE_OPT_GROUPNAME 'g'
#define VALUE_OPT_HELP 'h'
#define VALUE_OPT_MORE_HELP '!'
#define VALUE_OPT_VERSION 'v'
/*
* Interface defines not associated with particular options
*/
#define ERRSKIP_OPTERR STMTS(ocpasswdOptions.fOptSet &= ~OPTPROC_ERRSTOP)
#define ERRSTOP_OPTERR STMTS(ocpasswdOptions.fOptSet |= OPTPROC_ERRSTOP)
#define RESTART_OPT(n) STMTS( \
ocpasswdOptions.curOptIdx = (n); \
ocpasswdOptions.pzCurOpt = NULL)
#define START_OPT RESTART_OPT(1)
#define USAGE(c) (*ocpasswdOptions.pUsageProc)(&ocpasswdOptions, c)
/* extracted from opthead.tlib near line 484 */
#ifdef __cplusplus
extern "C" {
#endif
/* * * * * *
*
* Declare the ocpasswd option descriptor.
*/
extern tOptions ocpasswdOptions;
#if defined(ENABLE_NLS)
# ifndef _
# include <stdio.h>
static inline char* aoGetsText(char const* pz) {
if (pz == NULL) return NULL;
return (char*)gettext(pz);
}
# define _(s) aoGetsText(s)
# endif /* _() */
# define OPT_NO_XLAT_CFG_NAMES STMTS(ocpasswdOptions.fOptSet |= \
OPTPROC_NXLAT_OPT_CFG;)
# define OPT_NO_XLAT_OPT_NAMES STMTS(ocpasswdOptions.fOptSet |= \
OPTPROC_NXLAT_OPT|OPTPROC_NXLAT_OPT_CFG;)
# define OPT_XLAT_CFG_NAMES STMTS(ocpasswdOptions.fOptSet &= \
~(OPTPROC_NXLAT_OPT|OPTPROC_NXLAT_OPT_CFG);)
# define OPT_XLAT_OPT_NAMES STMTS(ocpasswdOptions.fOptSet &= \
~OPTPROC_NXLAT_OPT;)
#else /* ENABLE_NLS */
# define OPT_NO_XLAT_CFG_NAMES
# define OPT_NO_XLAT_OPT_NAMES
# define OPT_XLAT_CFG_NAMES
# define OPT_XLAT_OPT_NAMES
# ifndef _
# define _(_s) _s
# endif
#endif /* ENABLE_NLS */
#ifdef __cplusplus
}
#endif
#endif /* AUTOOPTS_OCPASSWD_ARGS_H_GUARD */
/* ocpasswd-args.h ends here */

View File

@@ -23,37 +23,42 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdint.h>
#include <unistd.h> #include <unistd.h>
#include <gnutls/gnutls.h>
#include <gnutls/crypto.h> /* for random */ #include <gnutls/crypto.h> /* for random */
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <ocpasswd-args.h>
/* Gnulib portability files. */ /* Gnulib portability files. */
#include <getpass.h> #include <getpass.h>
#include <minmax.h> #include <minmax.h>
#include <version-etc.h>
static const char *alphabet[] = static const char alphabet[] =
"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ./";
#define SALT_SIZE 16
static void static void
crypt_int(const char *fpasswd, const char *username, const char *groupname, crypt_int(const char *fpasswd, const char *username, const char *groupname,
const char *passwd) const char *passwd)
{ {
uint8_t _salt[8]; uint8_t _salt[SALT_SIZE];
char salt[16]; char salt[SALT_SIZE+16];
char *p, *cr_passwd; char *p, *cr_passwd;
char *tmp_passwd; char *tmp_passwd;
unsigned i; unsigned i;
unsigned fpasswd_len = strlen(fpasswd); unsigned fpasswd_len = strlen(fpasswd);
unsigned tpm_passwd_len; unsigned tmp_passwd_len;
unsigned username_len = strlen(username); unsigned username_len = strlen(username);
struct stat st; struct stat st;
FILE *fd, *fd2; FILE *fd, *fd2;
char *line = NULL; char *line = NULL;
size_t line_size, len; size_t line_size;
ssize_t len;
int ret;
ret = _gnutls_rnd(GNUTLS_RND_NONCE, _salt, 8); ret = gnutls_rnd(GNUTLS_RND_NONCE, _salt, sizeof(_salt));
if (ret < 0) { if (ret < 0) {
fprintf(stderr, "Error generating nonce: %s\n", fprintf(stderr, "Error generating nonce: %s\n",
gnutls_strerror(ret)); gnutls_strerror(ret));
@@ -61,9 +66,9 @@ crypt_int(const char *fpasswd, const char *username, const char *groupname,
} }
p = salt; p = salt;
p += snprintf(salt, sizeof(salt), "$1$"); p += snprintf(salt, sizeof(salt), "$5$");
for (i = 0; i < 8; i++) { for (i = 0; i < sizeof(_salt); i++) {
*p = alphabet[_salt[i] % (sizeof(alphabet) - 1)]; *p = alphabet[_salt[i] % (sizeof(alphabet) - 1)];
p++; p++;
} }
@@ -73,6 +78,10 @@ crypt_int(const char *fpasswd, const char *username, const char *groupname,
p++; p++;
cr_passwd = crypt(passwd, salt); cr_passwd = crypt(passwd, salt);
if (cr_passwd == NULL) { /* try MD5 */
salt[1] = 1;
cr_passwd = crypt(passwd, salt);
}
if (cr_passwd == NULL) { if (cr_passwd == NULL) {
fprintf(stderr, "Error in crypt()\n"); fprintf(stderr, "Error in crypt()\n");
exit(1); exit(1);
@@ -88,20 +97,19 @@ crypt_int(const char *fpasswd, const char *username, const char *groupname,
snprintf(tmp_passwd, tmp_passwd_len, "%s.tmp", fpasswd); snprintf(tmp_passwd, tmp_passwd_len, "%s.tmp", fpasswd);
if (stat(tmp_passwd, &st) != -1) { if (stat(tmp_passwd, &st) != -1) {
fprintf(stderr, "file '%s' is locked\n", fpasswd); fprintf(stderr, "file '%s' is locked\n", fpasswd);
return -1; exit(1);
} }
fd = fopen(fpasswd, "r"); fd = fopen(fpasswd, "r");
if (fd == NULL) { if (fd == NULL) {
fprintf(stderr, "Cannot open '%s' for write\n", dst); fprintf(stderr, "Cannot open '%s' for read\n", fpasswd);
return -1; exit(1);
} }
fd2 = fopen(tmp_passwd, "w"); fd2 = fopen(tmp_passwd, "w");
if (fd2 == NULL) { if (fd2 == NULL) {
/* empty file */ fprintf(stderr, "Cannot open '%s' for write\n", tmp_passwd);
fclose(fd); exit(1);
return 0;
} }
while ((len = getline(&line, &line_size, fd)) > 0) { while ((len = getline(&line, &line_size, fd)) > 0) {
@@ -125,8 +133,9 @@ crypt_int(const char *fpasswd, const char *username, const char *groupname,
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
int ret; int ret, optct;
const char *username, *groupname, *fpasswd; const char *username, *groupname, *fpasswd;
const char* passwd;
if ((ret = gnutls_global_init()) < 0) { if ((ret = gnutls_global_init()) < 0) {
fprintf(stderr, "global_init: %s\n", gnutls_strerror(ret)); fprintf(stderr, "global_init: %s\n", gnutls_strerror(ret));
@@ -142,7 +151,7 @@ int main(int argc, char **argv)
if (HAVE_OPT(PASSWD)) if (HAVE_OPT(PASSWD))
fpasswd = OPT_ARG(PASSWD); fpasswd = OPT_ARG(PASSWD);
else { else {
fprintf(stderr, "passwd was not specified\n"); fprintf(stderr, "Password file was not specified\n");
exit(1); exit(1);
} }
@@ -165,6 +174,9 @@ int main(int argc, char **argv)
return -1; return -1;
} }
return crypt_int(fpasswd, username, passwd); crypt_int(fpasswd, username, groupname, passwd);
gnutls_global_deinit();
return 0;
} }

View File

@@ -2,7 +2,7 @@
* *
* DO NOT EDIT THIS FILE (ocserv-args.c) * DO NOT EDIT THIS FILE (ocserv-args.c)
* *
* It has been AutoGen-ed March 13, 2013 at 06:29:47 PM by AutoGen 5.16 * It has been AutoGen-ed March 14, 2013 at 01:42:30 PM by AutoGen 5.16
* From the definitions ocserv-args.def * From the definitions ocserv-args.def
* and the template file options * and the template file options
* *
@@ -66,7 +66,7 @@ extern FILE * option_usage_fp;
* ocserv option static const strings * ocserv option static const strings
*/ */
static char const ocserv_opt_strs[1840] = static char const ocserv_opt_strs[1840] =
/* 0 */ "ocserv 0.0.2\n" /* 0 */ "ocserv 0.0.3\n"
"Copyright (C) 2013 Nikos Mavrogiannopoulos, all rights reserved.\n" "Copyright (C) 2013 Nikos Mavrogiannopoulos, all rights reserved.\n"
"This is free software. It is licensed for use, modification and\n" "This is free software. It is licensed for use, modification and\n"
"redistribution under the terms of the\n" "redistribution under the terms of the\n"
@@ -99,7 +99,7 @@ static char const ocserv_opt_strs[1840] =
/* 1129 */ "Output version information and exit\0" /* 1129 */ "Output version information and exit\0"
/* 1165 */ "version\0" /* 1165 */ "version\0"
/* 1173 */ "OCSERV\0" /* 1173 */ "OCSERV\0"
/* 1180 */ "ocserv - OpenConnect server - Ver. 0.0.2\n" /* 1180 */ "ocserv - OpenConnect server - Ver. 0.0.3\n"
"USAGE: %s [ -<flag> [<val>] | --<name>[{=| }<val>] ]...\n\0" "USAGE: %s [ -<flag> [<val>] | --<name>[{=| }<val>] ]...\n\0"
/* 1279 */ "openconnect-devel@lists.infradead.org\0" /* 1279 */ "openconnect-devel@lists.infradead.org\0"
/* 1317 */ "\n\n\0" /* 1317 */ "\n\n\0"
@@ -111,7 +111,7 @@ static char const ocserv_opt_strs[1840] =
"authentication. Authenticated users are assigned an unprivileged worker\n" "authentication. Authenticated users are assigned an unprivileged worker\n"
"process and obtain a networking (tun) device and IP from a configurable\n" "process and obtain a networking (tun) device and IP from a configurable\n"
"pool of addresses.\n\0" "pool of addresses.\n\0"
/* 1752 */ "ocserv 0.0.2\0" /* 1752 */ "ocserv 0.0.3\0"
/* 1765 */ "Usage: ocserv [options] -c [config]\n" /* 1765 */ "Usage: ocserv [options] -c [config]\n"
"ocserv --help for usage instructions.\n"; "ocserv --help for usage instructions.\n";

View File

@@ -21,8 +21,6 @@ authentication.
Authenticated users are assigned an unprivileged worker process and obtain Authenticated users are assigned an unprivileged worker process and obtain
a networking (tun) device and IP from a configurable pool of addresses."; a networking (tun) device and IP from a configurable pool of addresses.";
copyright = { copyright = {
date = "2013"; date = "2013";
owner = "Nikos Mavrogiannopoulos"; owner = "Nikos Mavrogiannopoulos";
@@ -81,8 +79,9 @@ auth = "pam"
# The plain option requires specifying a password file which contains # The plain option requires specifying a password file which contains
# entries of the following format. # entries of the following format.
# "username:groupname:password" # "username:groupname:encoded-password"
# One entry must be listed per line. # One entry must be listed per line, and 'ocpasswd' can be used
# to generate password entries.
#auth = "plain[/etc/ocserv-passwd]" #auth = "plain[/etc/ocserv-passwd]"
# A banner to be displayed on clients # A banner to be displayed on clients

View File

@@ -2,7 +2,7 @@
* *
* DO NOT EDIT THIS FILE (ocserv-args.h) * DO NOT EDIT THIS FILE (ocserv-args.h)
* *
* It has been AutoGen-ed March 13, 2013 at 06:29:46 PM by AutoGen 5.16 * It has been AutoGen-ed March 14, 2013 at 01:42:30 PM by AutoGen 5.16
* From the definitions ocserv-args.def * From the definitions ocserv-args.def
* and the template file options * and the template file options
* *
@@ -76,8 +76,8 @@ typedef enum {
} teOptIndex; } teOptIndex;
#define OPTION_CT 7 #define OPTION_CT 7
#define OCSERV_VERSION "0.0.2" #define OCSERV_VERSION "0.0.3"
#define OCSERV_FULL_VERSION "ocserv 0.0.2" #define OCSERV_FULL_VERSION "ocserv 0.0.3"
/* /*
* Interface defines for all options. Replace "n" with the UPPER_CASED * Interface defines for all options. Replace "n" with the UPPER_CASED

View File

@@ -3,6 +3,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <syslog.h> #include <syslog.h>
#include <unistd.h>
#include <plain.h> #include <plain.h>
/* Returns 0 if the user is successfully authenticated, and sets the appropriate group name. /* Returns 0 if the user is successfully authenticated, and sets the appropriate group name.
@@ -11,7 +12,8 @@ int plain_auth_user(const char* passwd, const char* user, const char* pass, char
{ {
FILE* fp; FILE* fp;
char * line = NULL; char * line = NULL;
size_t len, ll; size_t len;
ssize_t ll;
char* p; char* p;
int ret; int ret;
@@ -35,7 +37,10 @@ int ret;
if (p != NULL && strcmp(user, p) == 0) { if (p != NULL && strcmp(user, p) == 0) {
p = strtok(NULL, ":"); p = strtok(NULL, ":");
if (p != NULL) { if (p != NULL) {
snprintf(groupname, groupname_size, "%s", p); groupname_size = snprintf(groupname, groupname_size, "%s", p);
if (groupname_size == 1) /* values like '*' or 'x' indicate empty group */
groupname[0] = 0;
p = strtok(NULL, ":"); p = strtok(NULL, ":");
if (p != NULL && strcmp(crypt(pass, p), p) == 0) { if (p != NULL && strcmp(crypt(pass, p), p) == 0) {
ret = 0; ret = 0;

View File

@@ -10,6 +10,7 @@
#include <sys/socket.h> #include <sys/socket.h>
#include <unistd.h> #include <unistd.h>
#include <net/if.h> #include <net/if.h>
#include <minmax.h>
#define AC_PKT_DATA 0 /* Uncompressed data */ #define AC_PKT_DATA 0 /* Uncompressed data */
#define AC_PKT_DPD_OUT 3 /* Dead Peer Detection */ #define AC_PKT_DPD_OUT 3 /* Dead Peer Detection */
@@ -21,9 +22,6 @@
extern int syslog_open; extern int syslog_open;
#define MAX(x,y) ((x)>(y)?(x):(y))
#define MIN(x,y) ((x)<(y)?(x):(y))
/* the first is generic, for the methods that require a username password */ /* the first is generic, for the methods that require a username password */
#define AUTH_TYPE_USERNAME_PASS (1<<0) #define AUTH_TYPE_USERNAME_PASS (1<<0)
#define AUTH_TYPE_PAM (1<<1 | AUTH_TYPE_USERNAME_PASS) #define AUTH_TYPE_PAM (1<<1 | AUTH_TYPE_USERNAME_PASS)