sftpserver-0.2.1/0000775000175000017500000000000012415610132010713 500000000000000sftpserver-0.2.1/xfns.h0000664000175000017500000000325311626752072012002 00000000000000/* * This file is part of the Green End SFTP Server. * Copyright (C) 2007, 2011 Richard Kettlewell * * 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 2 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, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA */ /** @file xfns.h @brief Die-on-error utility function interface */ #ifndef XFNS_H #define XFNS_H /** @brief Close @p fd * @param fd File descriptor to close * * Calls fatal() on error. */ void xclose(int fd); /** @brief Duplicate @p fd * @param fd File descriptor to duplicate * @param newfd New file descriptor * * Calls fatal() on error. */ void xdup2(int fd, int newfd); /** @brief Create a pipe * @param pfd Where to store endpoint file descriptors * * Calls fatal() on error. */ void xpipe(int *pfd); /** @brief Write to stdout * @param fmt Format string as per @c printf() * @param ... Arguments * @return Number of characters written * * Calls fatal() on error. */ int xprintf(const char *fmt, ...) attribute((format(printf,1,2))); #endif /* XFNS_H */ /* Local Variables: c-basic-offset:2 comment-column:40 fill-column:79 indent-tabs-mode:nil End: */ sftpserver-0.2.1/pwtest.c0000664000175000017500000000352312343154460012337 00000000000000/* * This file is part of the Green End SFTP Server. * Copyright (C) 2014 Richard Kettlewell * * 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 2 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, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA */ #include "sftpcommon.h" #include "putword.h" #include #include int main() { unsigned char buffer[16]; int n, m; for(n = 0; n <= 14; ++n) { memset(buffer, 0xAF, 16); put16(buffer + n, 0x0102); assert(get16(buffer + n) == 0x0102); for(m = 0; m < 16; ++m) { if(m >= n && m < n + 2) assert(buffer[m] == 1 + m - n); else assert(buffer[m] == 0xAF); } } for(n = 0; n <= 12; ++n) { memset(buffer, 0xAF, 16); put32(buffer + n, 0x01020304); //assert(get32(buffer + n) == 0x01020304); for(m = 0; m < 16; ++m) { if(m >= n && m < n + 4) assert(buffer[m] == 1 + m - n); else assert(buffer[m] == 0xAF); } } for(n = 0; n <= 8; ++n) { memset(buffer, 0xAF, 16); put64(buffer + n, 0x0102030405060708ULL); //assert(get64(buffer + n) == 0x0102030405060708ULL); for(m = 0; m < 16; ++m) { if(m >= n && m < n + 8) assert(buffer[m] == 1 + m - n); else assert(buffer[m] == 0xAF); } } return 0; } sftpserver-0.2.1/getopt1.c0000664000175000017500000001070611625765051012403 00000000000000/* getopt_long and getopt_long_only entry points for GNU getopt. Copyright (C) 1987,88,89,90,91,92,93,94,96,97,98 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. The GNU C Library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with the GNU C Library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifdef HAVE_CONFIG_H #include #endif #include "getopt.h" #if !defined __STDC__ || !__STDC__ /* This is a separate conditional since some stdc systems reject `defined (const)'. */ #ifndef const #define const #endif #endif #include /* Comment out all this code if we are using the GNU C Library, and are not actually compiling the library itself. This code is part of the GNU C Library, but also included in many other GNU distributions. Compiling and linking in this code is a waste when using the GNU C library (especially if it is a shared library). Rather than having every GNU program understand `configure --with-gnu-libc' and omit the object files, it is simpler to just do this in the source for each such file. */ #define GETOPT_INTERFACE_VERSION 2 #if !defined _LIBC && defined __GLIBC__ && __GLIBC__ >= 2 #include #if _GNU_GETOPT_INTERFACE_VERSION == GETOPT_INTERFACE_VERSION #define ELIDE_CODE #endif #endif #ifndef ELIDE_CODE /* This needs to come after some library #include to get __GNU_LIBRARY__ defined. */ #ifdef __GNU_LIBRARY__ #include #endif #ifndef NULL #define NULL 0 #endif int getopt_long (argc, argv, options, long_options, opt_index) int argc; char *const *argv; const char *options; const struct option *long_options; int *opt_index; { return _getopt_internal (argc, argv, options, long_options, opt_index, 0); } /* Like getopt_long, but '-' as well as '--' can indicate a long option. If an option that starts with '-' (not '--') doesn't match a long option, but does match a short option, it is parsed as a short option instead. */ int getopt_long_only (argc, argv, options, long_options, opt_index) int argc; char *const *argv; const char *options; const struct option *long_options; int *opt_index; { return _getopt_internal (argc, argv, options, long_options, opt_index, 1); } #endif /* Not ELIDE_CODE. */ #ifdef TEST #include int main (argc, argv) int argc; char **argv; { int c; int digit_optind = 0; while (1) { int this_option_optind = optind ? optind : 1; int option_index = 0; static struct option long_options[] = { {"add", 1, 0, 0}, {"append", 0, 0, 0}, {"delete", 1, 0, 0}, {"verbose", 0, 0, 0}, {"create", 0, 0, 0}, {"file", 1, 0, 0}, {0, 0, 0, 0} }; c = getopt_long (argc, argv, "abc:d:0123456789", long_options, &option_index); if (c == -1) break; switch (c) { case 0: printf ("option %s", long_options[option_index].name); if (optarg) printf (" with arg %s", optarg); printf ("\n"); break; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': if (digit_optind != 0 && digit_optind != this_option_optind) printf ("digits occur in two different argv-elements.\n"); digit_optind = this_option_optind; printf ("option %c\n", c); break; case 'a': printf ("option a\n"); break; case 'b': printf ("option b\n"); break; case 'c': printf ("option c with value `%s'\n", optarg); break; case 'd': printf ("option d with value `%s'\n", optarg); break; case '?': break; default: printf ("?? getopt returned character code 0%o ??\n", c); } } if (optind < argc) { printf ("non-option ARGV-elements: "); while (optind < argc) printf ("%s ", argv[optind++]); printf ("\n"); } exit (0); } #endif /* TEST */ sftpserver-0.2.1/gesftpserver.8.in0000664000175000017500000000415311626166333014067 00000000000000.\" This file is part of the Green End SFTP Server. .\" Copyright (C) 2007, 2011 Richard Kettlewell .\" .\" 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 2 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, write to the Free Software .\" Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 .\" USA .TH gesftpserver 8 .SH NAME gesftpserver - Green End SFTP Server .SH SYNOPSIS .B __libexecdir__/gesftpserver .RI [OPTIONS] .SH DESCRIPTION .B gesftpserver implements the SFTP protocol. It is normally run as an SSH subsystem but can be run in other contexts if necessary. .SH "CONFIGURING OPENSSH" By default, OpenSSH will use its native SFTP server in response to requests for the SFTP subsystem. To use gesftpserver instead, add a suitable .B Subsystem command to .I sshd_config (and remove the existing one if present). For example: .PP .nf Subsystem sftp __libexecdir__/gesftpserver .fi .SH "IMPLEMENTATION DETAILS" .B gesftpserver supports up to version 6 of the SFTP protocol and the following extensions: .TP .B newline Reports the server's newline convention to the client. .TP .B space-available Equivalent to .BR df (1). .TP .B supported v5 capability details .TP .B supported2 v6 capability details .TP .B text-seek Used for resuming text file downloads. .TP .B vendor-id Reports server name and version to client. .B gesftpserver reports a vendor of "Green End" and a server name of "Green End SFTP Server". .TP .B versions Lists available versions. .TP .B version-select Select version. .TP .B posix-rename@openssh.org Provides POSIX rename semantics even in pre-v5 SFTP. .SH "SEE ALSO" .BR sshd_config (5) sftpserver-0.2.1/sftp.h0000664000175000017500000004640011626752072012001 00000000000000/* * This file is part of the Green End SFTP Server. * Copyright (C) 2007, 2011 Richard Kettlewell * * 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 2 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, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA */ /** @file sftp.h @brief SFTP definitions * * Specifications: * - http://tools.ietf.org/wg/secsh/draft-ietf-secsh-filexfer/draft-ietf-secsh-filexfer-02.txt * - http://tools.ietf.org/wg/secsh/draft-ietf-secsh-filexfer/draft-ietf-secsh-filexfer-04.txt * - http://tools.ietf.org/wg/secsh/draft-ietf-secsh-filexfer/draft-ietf-secsh-filexfer-05.txt * - http://tools.ietf.org/wg/secsh/draft-ietf-secsh-filexfer/draft-ietf-secsh-filexfer-13.txt * * See also: * - @ref type * - @ref valid_attribute_flags * - @ref attrib_bits * - @ref text_hint * - @ref request_flags * - @ref rename_flags * - @ref realpath_control * - @ref open_pflags * - @ref status * */ #ifndef SFTP_H #define SFTP_H /** @defgroup type SFTP 'type' definitions * @{ */ /** @brief Protocol initialization */ #define SSH_FXP_INIT 1 /** @brief Server version */ #define SSH_FXP_VERSION 2 /** @brief Open file */ #define SSH_FXP_OPEN 3 /** @brief Close handle */ #define SSH_FXP_CLOSE 4 /** @brief Read bytes */ #define SSH_FXP_READ 5 /** @brief Write bytes */ #define SSH_FXP_WRITE 6 /** @brief Get file attributes by name * * Do not follow symlinks. */ #define SSH_FXP_LSTAT 7 /** @brief Get file attributes by handle */ #define SSH_FXP_FSTAT 8 /** @brief Set file attributes by name */ #define SSH_FXP_SETSTAT 9 /** @brief Set file attributes by handle */ #define SSH_FXP_FSETSTAT 10 /* 0x0A */ /** @brief Open directory */ #define SSH_FXP_OPENDIR 11 /* 0x0B */ /** @brief Read from directory */ #define SSH_FXP_READDIR 12 /* 0x0C */ /** @brief Remove file */ #define SSH_FXP_REMOVE 13 /* 0x0D */ /** @brief Create directory */ #define SSH_FXP_MKDIR 14 /* 0x0E */ /** @brief Remove directory */ #define SSH_FXP_RMDIR 15 /* 0x0F */ /** @brief Canonicalize path */ #define SSH_FXP_REALPATH 16 /* 0x10 */ /** @brief Get file attributes by name * * Do follow symlinks. */ #define SSH_FXP_STAT 17 /* 0x11 */ /** @brief Rename file */ #define SSH_FXP_RENAME 18 /* 0x12 */ /** @brief Read symbolic link */ #define SSH_FXP_READLINK 19 /* 0x13 */ /** @brief Create symbolic link */ #define SSH_FXP_SYMLINK 20 /* 0x14 */ /** @brief Create hard link */ #define SSH_FXP_LINK 21 /* 0x15 */ /** @brief Lock byte range */ #define SSH_FXP_BLOCK 22 /* 0x16 */ /** @brief Unlock byte range */ #define SSH_FXP_UNBLOCK 23 /* 0x17 */ /** @brief Response with a status */ #define SSH_FXP_STATUS 101 /* 0x65 */ /** @brief Response with a handle */ #define SSH_FXP_HANDLE 102 /* 0x66 */ /** @brief Response with data bytes */ #define SSH_FXP_DATA 103 /* 0x67 */ /** @brief Response with a name */ #define SSH_FXP_NAME 104 /* 0x68 */ /** @brief Response with attributes */ #define SSH_FXP_ATTRS 105 /* 0x69 */ /** @brief Execute an extended command */ #define SSH_FXP_EXTENDED 200 /* 0xC8 */ /** @brief Extended response format */ #define SSH_FXP_EXTENDED_REPLY 201 /* 0xC9 */ /** @} */ #define SSH_ACL_CAP_ALLOW 0x00000001 #define SSH_ACL_CAP_DENY 0x00000002 #define SSH_ACL_CAP_AUDIT 0x00000004 #define SSH_ACL_CAP_ALARM 0x00000008 #define SSH_ACL_CAP_INHERIT_ACCESS 0x00000010 #define SSH_ACL_CAP_INHERIT_AUDIT_ALARM 0x00000020 /** @defgroup valid_attribute_flags SFTP 'valid-attribute-flags' definitions * @{ */ /** @brief @c size field is present */ #define SSH_FILEXFER_ATTR_SIZE 0x00000001 /** @brief @c uid and @c gid fiels are present * * This is for v3 only. */ #define SSH_FILEXFER_ATTR_UIDGID 0x00000002 /** @brief @c permissions field is present */ #define SSH_FILEXFER_ATTR_PERMISSIONS 0x00000004 /** @brief @c atime field is present * * This is for v4 and later. */ #define SSH_FILEXFER_ATTR_ACCESSTIME 0x00000008 /** @brief @c atime and @c mtime fiels are present * * This is for v3 only. */ #define SSH_FILEXFER_ACMODTIME 0x00000008 /** @brief @c createtime field is present */ #define SSH_FILEXFER_ATTR_CREATETIME 0x00000010 /** @brief @c mtime field is present */ #define SSH_FILEXFER_ATTR_MODIFYTIME 0x00000020 /** @brief @c ACL field is present */ #define SSH_FILEXFER_ATTR_ACL 0x00000040 /** @brief @c owner and @c group fields are present */ #define SSH_FILEXFER_ATTR_OWNERGROUP 0x00000080 /** @brief Times include subsecond fields */ #define SSH_FILEXFER_ATTR_SUBSECOND_TIMES 0x00000100 /** @brief @c attrib-bits and @c attrib-bits-valid fields are present */ #define SSH_FILEXFER_ATTR_BITS 0x00000200 /** @brief @c allocaiton-size field is present */ #define SSH_FILEXFER_ATTR_ALLOCATION_SIZE 0x00000400 /** @brief @c text-hint field is present */ #define SSH_FILEXFER_ATTR_TEXT_HINT 0x00000800 /** @brief @c mime-type field is present */ #define SSH_FILEXFER_ATTR_MIME_TYPE 0x00001000 /** @brief @c link-count field is present */ #define SSH_FILEXFER_ATTR_LINK_COUNT 0x00002000 /** @brief @c untranslated-name field is present */ #define SSH_FILEXFER_ATTR_UNTRANSLATED_NAME 0x00004000 /** @brief @c time field is present */ #define SSH_FILEXFER_ATTR_CTIME 0x00008000 /** @brief Extended attributes present */ #define SSH_FILEXFER_ATTR_EXTENDED 0x80000000 /** @} */ /** @defgroup file_type SFTP file types * @{ */ /** @brief Regular file */ #define SSH_FILEXFER_TYPE_REGULAR 1 /** @brief Directory */ #define SSH_FILEXFER_TYPE_DIRECTORY 2 /** @brief Symbolic link */ #define SSH_FILEXFER_TYPE_SYMLINK 3 /** @brief Special file * * This is for files where the type is known but cannot be exprssed in SFTP. */ #define SSH_FILEXFER_TYPE_SPECIAL 4 /** @brief Unknown file type */ #define SSH_FILEXFER_TYPE_UNKNOWN 5 /** @brief Socket */ #define SSH_FILEXFER_TYPE_SOCKET 6 /** @brief Character device */ #define SSH_FILEXFER_TYPE_CHAR_DEVICE 7 /** @brief Block device */ #define SSH_FILEXFER_TYPE_BLOCK_DEVICE 8 /** @brief Named pipe */ #define SSH_FILEXFER_TYPE_FIFO 9 /** @} */ #define SFX_ACL_CONTROL_INCLUDED 0x00000001 #define SFX_ACL_CONTROL_PRESENT 0x00000002 #define SFX_ACL_CONTROL_INHERITED 0x00000004 #define SFX_ACL_AUDIT_ALARM_INCLUDED 0x00000010 #define ACE4_ACCESS_ALLOWED_ACE_TYPE 0x00000000 #define ACE4_ACCESS_DENIED_ACE_TYPE 0x00000001 #define ACE4_SYSTEM_AUDIT_ACE_TYPE 0x00000002 #define ACE4_SYSTEM_ALARM_ACE_TYPE 0x00000003 #define ACE4_FILE_INHERIT_ACE 0x00000001 #define ACE4_DIRECTORY_INHERIT_ACE 0x00000002 #define ACE4_NO_PROPAGATE_INHERIT_ACE 0x00000004 #define ACE4_INHERIT_ONLY_ACE 0x00000008 #define ACE4_SUCCESSFUL_ACCESS_ACE_FLAG 0x00000010 #define ACE4_FAILED_ACCESS_ACE_FLAG 0x00000020 #define ACE4_IDENTIFIER_GROUP 0x00000040 #define ACE4_READ_DATA 0x00000001 #define ACE4_LIST_DIRECTORY 0x00000001 #define ACE4_WRITE_DATA 0x00000002 #define ACE4_ADD_FILE 0x00000002 #define ACE4_APPEND_DATA 0x00000004 #define ACE4_ADD_SUBDIRECTORY 0x00000004 #define ACE4_READ_NAMED_ATTRS 0x00000008 #define ACE4_WRITE_NAMED_ATTRS 0x00000010 #define ACE4_EXECUTE 0x00000020 #define ACE4_DELETE_CHILD 0x00000040 #define ACE4_READ_ATTRIBUTES 0x00000080 #define ACE4_WRITE_ATTRIBUTES 0x00000100 #define ACE4_DELETE 0x00010000 #define ACE4_READ_ACL 0x00020000 #define ACE4_WRITE_ACL 0x00040000 #define ACE4_WRITE_OWNER 0x00080000 #define ACE4_SYNCHRONIZE 0x00100000 /** @defgroup attrib_bits SFTP 'attrib-bits' definitions * @{ */ /** @brief File is read-only (advisory) */ #define SSH_FILEXFER_ATTR_FLAGS_READONLY 0x00000001 /** @brief File is part of the OS */ #define SSH_FILEXFER_ATTR_FLAGS_SYSTEM 0x00000002 /** @brief File is hidden */ #define SSH_FILEXFER_ATTR_FLAGS_HIDDEN 0x00000004 /** @brief Filenames in this directory are case-insensitive */ #define SSH_FILEXFER_ATTR_FLAGS_CASE_INSENSITIVE 0x00000008 /** @brief File should be archived */ #define SSH_FILEXFER_ATTR_FLAGS_ARCHIVE 0x00000010 /** @brief File is stored on encrypted media */ #define SSH_FILEXFER_ATTR_FLAGS_ENCRYPTED 0x00000020 /** @brief File is stored on compressed media */ #define SSH_FILEXFER_ATTR_FLAGS_COMPRESSED 0x00000040 /** @brief File is sparse */ #define SSH_FILEXFER_ATTR_FLAGS_SPARSE 0x00000080 /** @brief File is append-only */ #define SSH_FILEXFER_ATTR_FLAGS_APPEND_ONLY 0x00000100 /** @brief File cannot be delete, renamed, linked to or written */ #define SSH_FILEXFER_ATTR_FLAGS_IMMUTABLE 0x00000200 /** @brief Modifications to file are synchronous */ #define SSH_FILEXFER_ATTR_FLAGS_SYNC 0x00000400 /** @brief Filename could not be converted to UTF-8 */ #define SSH_FILEXFER_ATTR_FLAGS_TRANSLATION_ERR 0x00000800 /** @} */ /** @defgroup text_hint SFTP 'text-hint' definitions * @{ */ /** @brief Server knows file is a text file */ #define SSH_FILEXFER_ATTR_KNOWN_TEXT 0x00 /** @brief Server believes file is a text file */ #define SSH_FILEXFER_ATTR_GUESSED_TEXT 0x01 /** @brief Server knows file is a binary file */ #define SSH_FILEXFER_ATTR_KNOWN_BINARY 0x02 /** @brief Server believes file is a binary file */ #define SSH_FILEXFER_ATTR_GUESSED_BINARY 0x03 /** @} */ /** @defgroup request_flags SFTP operation 'flags' definitions * @{ */ /** @brief Mask of file open bits */ #define SSH_FXF_ACCESS_DISPOSITION 0x00000007 /** @brief Must create a new file */ #define SSH_FXF_CREATE_NEW 0x00000000 /** @brief Create new file or truncate existing one */ #define SSH_FXF_CREATE_TRUNCATE 0x00000001 /** @brief File must already exist */ #define SSH_FXF_OPEN_EXISTING 0x00000002 /** @brief Open existing file or create new one */ #define SSH_FXF_OPEN_OR_CREATE 0x00000003 /** @brief Truncate an existing file */ #define SSH_FXF_TRUNCATE_EXISTING 0x00000004 /** @brief Lossy append only */ #define SSH_FXF_APPEND_DATA 0x00000008 /** @brief Append only */ #define SSH_FXF_APPEND_DATA_ATOMIC 0x00000010 /** @brief Convert newlines */ #define SSH_FXF_TEXT_MODE 0x00000020 /** @brief Exclusive read access */ #define SSH_FXF_BLOCK_READ 0x00000040 /** @brief Exclusive write access */ #define SSH_FXF_BLOCK_WRITE 0x00000080 /** @brief Exclusive delete access */ #define SSH_FXF_BLOCK_DELETE 0x00000100 /** @brief Other @c SSH_FXF_BLOCK_... bits are advisory */ #define SSH_FXF_BLOCK_ADVISORY 0x00000200 /** @brief Do not follow symlinks */ #define SSH_FXF_NOFOLLOW 0x00000400 /** @brief Delete when last handle closed */ #define SSH_FXF_DELETE_ON_CLOSE 0x00000800 /** @brief Enable audit/alarm privileges */ #define SSH_FXF_ACCESS_AUDIT_ALARM_INFO 0x00001000 /** @brief Enable backup privileges */ #define SSH_FXF_ACCESS_BACKUP 0x00002000 /** @brief Read or write backup stream */ #define SSH_FXF_BACKUP_STREAM 0x00004000 /** @brief Enable owner privileges */ #define SSH_FXF_OVERRIDE_OWNER 0x00008000 /** @} */ /** @defgroup rename_flags SFTP rename flag definitions * @{ */ /** @brief Overwrite target if it exists */ #define SSH_FXF_RENAME_OVERWRITE 0x00000001 /** @brief Ensure target name always exists and refers to original or new file */ #define SSH_FXF_RENAME_ATOMIC 0x00000002 /** @brief Remove requirements on server */ #define SSH_FXF_RENAME_NATIVE 0x00000004 /** @} */ /** @defgroup realpath_control SFTP realpath control byte definitions * @{ */ /** @brief Don't check for existence or accessibility, don't resolve links */ #define SSH_FXP_REALPATH_NO_CHECK 0x00000001 /** @brief Get file attribtues if it exists */ #define SSH_FXP_REALPATH_STAT_IF 0x00000002 /** @brief Get file attributes, fail if unavailable */ #define SSH_FXP_REALPATH_STAT_ALWAYS 0x00000003 /** @} */ /** @defgroup open_pflags SFTP open/create 'pflags' definitions * @{ */ /** @brief Open file for reading */ #define SSH_FXF_READ 0x00000001 /** @brief Open file for writing */ #define SSH_FXF_WRITE 0x00000002 /** @brief Append to end of file */ #define SSH_FXF_APPEND 0x00000004 /** @brief Create file if it does not exist */ #define SSH_FXF_CREAT 0x00000008 /** @brief Truncate file if it already exists */ #define SSH_FXF_TRUNC 0x00000010 /** @brief File must not exist */ #define SSH_FXF_EXCL 0x00000020 /** @brief Convert newlines */ #define SSH_FXF_TEXT 0x00000040 /** @} */ /** @defgroup status SFTP error/status codes * @{ */ /** @brief Success */ #define SSH_FX_OK 0 /** @brief End of file */ #define SSH_FX_EOF 1 /** @brief File does not exist */ #define SSH_FX_NO_SUCH_FILE 2 /** @brief Insufficient permission */ #define SSH_FX_PERMISSION_DENIED 3 /** @brief Unknown error */ #define SSH_FX_FAILURE 4 /** @brief Badly formatted packet */ #define SSH_FX_BAD_MESSAGE 5 /** @brief No connection to server */ #define SSH_FX_NO_CONNECTION 6 /** @brief Connection to server lost */ #define SSH_FX_CONNECTION_LOST 7 /** @brief Operation not supported by server */ #define SSH_FX_OP_UNSUPPORTED 8 /** @brief Invalid handle value */ #define SSH_FX_INVALID_HANDLE 9 /* v4+ */ /** @brief File path does not exist or is invalid */ #define SSH_FX_NO_SUCH_PATH 10 /* 0x0A */ /** @brief File already exists */ #define SSH_FX_FILE_ALREADY_EXISTS 11 /* 0x0B */ /** @brief File is on read-only or write-protected media */ #define SSH_FX_WRITE_PROTECT 12 /* 0x0C */ /** @brief No medium in drive */ #define SSH_FX_NO_MEDIA 13 /* 0x0D */ /** @brief Insufficient free space */ #define SSH_FX_NO_SPACE_ON_FILESYSTEM 14 /* 0x0E v5+ */ /** @brief User's storage quota would be exceeded */ #define SSH_FX_QUOTA_EXCEEDED 15 /* 0x0F */ /** @brief Unknown principal in ACL */ #define SSH_FX_UNKNOWN_PRINCIPAL 16 /* 0x10 */ /** @brief File is locked by another process */ #define SSH_FX_LOCK_CONFLICT 17 /* 0x11 */ /** @brief Directory is not empty */ #define SSH_FX_DIR_NOT_EMPTY 18 /* 0x12 v6+ */ /** @brief File is not a director */ #define SSH_FX_NOT_A_DIRECTORY 19 /* 0x13 */ /** @brief Filename is invalid */ #define SSH_FX_INVALID_FILENAME 20 /* 0x14 */ /** @brief Too many symbolic links or link found by @ref SSH_FXF_NOFOLLOW */ #define SSH_FX_LINK_LOOP 21 /* 0x15 */ /** @brief File cannot be deleted */ #define SSH_FX_CANNOT_DELETE 22 /* 0x16 */ /** @brief Parameter out of range or conflicting */ #define SSH_FX_INVALID_PARAMETER 23 /* 0x17 */ /** @brief File is a directory */ #define SSH_FX_FILE_IS_A_DIRECTORY 24 /* 0x18 */ /** @brief Mandatory lock conflict when reading or writing */ #define SSH_FX_BYTE_RANGE_LOCK_CONFLICT 25 /* 0x19 */ /** @brief Lock request refused */ #define SSH_FX_BYTE_RANGE_LOCK_REFUSED 26 /* 0x1A */ /** @brief Delete operation pending on faile */ #define SSH_FX_DELETE_PENDING 27 /* 0x1B */ /** @brief File is corrupt */ #define SSH_FX_FILE_CORRUPT 28 /* 0x1C */ /** @brief Principal cannot become file owner */ #define SSH_FX_OWNER_INVALID 29 /* 0x1D */ /** @brief Principal cannot become file group */ #define SSH_FX_GROUP_INVALID 30 /* 0x1E */ /** @brief Specified lock range has not been granted */ #define SSH_FX_NO_MATCHING_BYTE_RANGE_LOCK 31 /* 0x1F */ /** @} */ /** @mainpage Green End SFTP Server * * This is the internal documentation for the Green End SFTP server. * It is intended for developers of the server, not users. * * @section structure Server Structure * * @subsection concurrency Concurrency * * The server is designed to be able to execute * multiple requests concurrently. To this end, sftp_service() reads * requests from its input and (once initialization is complete) adds * them to a @ref queue in the form of an @ref sftpjob. The queue is * serviced by a pool of worker threads, which are responsible for * executing the requests and sending responses. * * Each thread has a separate memory @ref allocator. All memory * allocated to it is released after each request is processed. * * The SFTP specification makes certain demands about the order in * which responses appear. These are implemented in @ref serialize.c. * * @subsection versions Protocol Versions * * The server supports the four proposed versions of the protocol. * Each protocol version has a separate table of request * implementations and other details, in an @ref sftpprotocol object. * Much, though not all, of the implementation is shared between them. * * The convention for request implementation naming can be observed in * @ref sftpserver.h. Each function is named @c * sftp_vVERSIONS_REQUEST, where @c VERSIONS is replaced with by the * list of versions supported or by @c any if the implementation is * completely generic. * * @subsection Attributes * * Although attribute specifications vary between the protocol * versions they are represented inside the server in a common @ref * sftpattr structure. Each protocol version has a @c parseattrs and a * @c sendattrs callback which convert between wire and internal * format. * * @section specs Specifications * * - http://www.ietf.org/rfc/rfc4251.txt * - http://tools.ietf.org/wg/secsh/draft-ietf-secsh-filexfer/draft-ietf-secsh-filexfer-02.txt * - http://tools.ietf.org/wg/secsh/draft-ietf-secsh-filexfer/draft-ietf-secsh-filexfer-04.txt * - http://tools.ietf.org/wg/secsh/draft-ietf-secsh-filexfer/draft-ietf-secsh-filexfer-05.txt * - http://tools.ietf.org/wg/secsh/draft-ietf-secsh-filexfer/draft-ietf-secsh-filexfer-13.txt * * @section links Links * * - http://www.greenend.org.uk/rjk/sftpserver/ * - https://github.com/ewxrjk/sftpserver * - http://www.greenend.org.uk/rjk/2007/sftpversions.html */ #endif /* SFTP_H */ /* Local Variables: c-basic-offset:2 comment-column:40 fill-column:79 indent-tabs-mode:nil #define End: */ sftpserver-0.2.1/xfns.c0000664000175000017500000000311111625765051011766 00000000000000/* * This file is part of the Green End SFTP Server. * Copyright (C) 2007 Richard Kettlewell * * 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 2 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, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA */ #include "sftpserver.h" #include "utils.h" #include "xfns.h" #include #include #include #include #include void xclose(int fd) { if(close(fd) < 0) fatal("error calling close: %s", strerror(errno)); } void xdup2(int fd, int newfd) { if(dup2(fd, newfd) < 0) fatal("error calling dup2: %s", strerror(errno)); } void xpipe(int *pfd) { if(pipe(pfd) < 0) fatal("error calling pipe: %s", strerror(errno)); } int xprintf(const char *fmt, ...) { va_list ap; int rc; va_start(ap, fmt); rc = vfprintf(stdout, fmt, ap); va_end(ap); if(rc < 0) fatal("error writing to stdout: %s", strerror(errno)); return rc; } /* Local Variables: c-basic-offset:2 comment-column:40 fill-column:79 indent-tabs-mode:nil End: */ sftpserver-0.2.1/getopt.c0000664000175000017500000007300411625765051012322 00000000000000/* Getopt for GNU. NOTE: getopt is now part of the C library, so if you don't know what "Keep this file name-space clean" means, talk to drepper@gnu.org before changing it! Copyright (C) 1987, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 2000 Free Software Foundation, Inc. The GNU C Library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. The GNU C Library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with the GNU C Library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* This tells Alpha OSF/1 not to define a getopt prototype in . Ditto for AIX 3.2 and . */ #ifndef _NO_PROTO # define _NO_PROTO #endif #ifdef HAVE_CONFIG_H # include #endif #if !defined __STDC__ || !__STDC__ /* This is a separate conditional since some stdc systems reject `defined (const)'. */ # ifndef const # define const # endif #endif #include /* Comment out all this code if we are using the GNU C Library, and are not actually compiling the library itself. This code is part of the GNU C Library, but also included in many other GNU distributions. Compiling and linking in this code is a waste when using the GNU C library (especially if it is a shared library). Rather than having every GNU program understand `configure --with-gnu-libc' and omit the object files, it is simpler to just do this in the source for each such file. */ #define GETOPT_INTERFACE_VERSION 2 #if !defined _LIBC && defined __GLIBC__ && __GLIBC__ >= 2 # include # if _GNU_GETOPT_INTERFACE_VERSION == GETOPT_INTERFACE_VERSION # define ELIDE_CODE # endif #endif #ifndef ELIDE_CODE /* This needs to come after some library #include to get __GNU_LIBRARY__ defined. */ #ifdef __GNU_LIBRARY__ /* Don't include stdlib.h for non-GNU C libraries because some of them contain conflicting prototypes for getopt. */ # include # include #endif /* GNU C library. */ #ifdef VMS # include # if HAVE_STRING_H - 0 # include # endif #endif #ifndef _ /* This is for other GNU distributions with internationalized messages. When compiling libc, the _ macro is predefined. */ # ifdef HAVE_LIBINTL_H # include # define _(msgid) gettext (msgid) # else # define _(msgid) (msgid) # endif #endif /* This version of `getopt' appears to the caller like standard Unix `getopt' but it behaves differently for the user, since it allows the user to intersperse the options with the other arguments. As `getopt' works, it permutes the elements of ARGV so that, when it is done, all the options precede everything else. Thus all application programs are extended to handle flexible argument order. Setting the environment variable POSIXLY_CORRECT disables permutation. Then the behavior is completely standard. GNU application programs can use a third alternative mode in which they can distinguish the relative order of options and other arguments. */ #include "getopt.h" /* For communication from `getopt' to the caller. When `getopt' finds an option that takes an argument, the argument value is returned here. Also, when `ordering' is RETURN_IN_ORDER, each non-option ARGV-element is returned here. */ char *optarg; /* Index in ARGV of the next element to be scanned. This is used for communication to and from the caller and for communication between successive calls to `getopt'. On entry to `getopt', zero means this is the first call; initialize. When `getopt' returns -1, this is the index of the first of the non-option elements that the caller should itself scan. Otherwise, `optind' communicates from one call to the next how much of ARGV has been scanned so far. */ /* 1003.2 says this must be 1 before any call. */ int optind = 1; /* Formerly, initialization of getopt depended on optind==0, which causes problems with re-calling getopt as programs generally don't know that. */ int __getopt_initialized; /* The next char to be scanned in the option-element in which the last option character we returned was found. This allows us to pick up the scan where we left off. If this is zero, or a null string, it means resume the scan by advancing to the next ARGV-element. */ static char *nextchar; /* Callers store zero here to inhibit the error message for unrecognized options. */ int opterr = 1; /* Set to an option character which was unrecognized. This must be initialized on some systems to avoid linking in the system's own getopt implementation. */ int optopt = '?'; /* Describe how to deal with options that follow non-option ARGV-elements. If the caller did not specify anything, the default is REQUIRE_ORDER if the environment variable POSIXLY_CORRECT is defined, PERMUTE otherwise. REQUIRE_ORDER means don't recognize them as options; stop option processing when the first non-option is seen. This is what Unix does. This mode of operation is selected by either setting the environment variable POSIXLY_CORRECT, or using `+' as the first character of the list of option characters. PERMUTE is the default. We permute the contents of ARGV as we scan, so that eventually all the non-options are at the end. This allows options to be given in any order, even with programs that were not written to expect this. RETURN_IN_ORDER is an option available to programs that were written to expect options and other ARGV-elements in any order and that care about the ordering of the two. We describe each non-option ARGV-element as if it were the argument of an option with character code 1. Using `-' as the first character of the list of option characters selects this mode of operation. The special argument `--' forces an end of option-scanning regardless of the value of `ordering'. In the case of RETURN_IN_ORDER, only `--' can cause `getopt' to return -1 with `optind' != ARGC. */ static enum { REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER } ordering; /* Value of POSIXLY_CORRECT environment variable. */ static char *posixly_correct; #ifdef __GNU_LIBRARY__ /* We want to avoid inclusion of string.h with non-GNU libraries because there are many ways it can cause trouble. On some systems, it contains special magic macros that don't work in GCC. */ # include # define my_index strchr #else # if HAVE_STRING_H # include # else # include # endif /* Avoid depending on library functions or files whose names are inconsistent. */ #ifndef getenv extern char *getenv (); #endif static char * my_index (str, chr) const char *str; int chr; { while (*str) { if (*str == chr) return (char *) str; str++; } return 0; } /* If using GCC, we can safely declare strlen this way. If not using GCC, it is ok not to declare it. */ #ifdef __GNUC__ /* Note that Motorola Delta 68k R3V7 comes with GCC but not stddef.h. That was relevant to code that was here before. */ # if (!defined __STDC__ || !__STDC__) && !defined strlen /* gcc with -traditional declares the built-in strlen to return int, and has done so at least since version 2.4.5. -- rms. */ extern int strlen (const char *); # endif /* not __STDC__ */ #endif /* __GNUC__ */ #endif /* not __GNU_LIBRARY__ */ /* Handle permutation of arguments. */ /* Describe the part of ARGV that contains non-options that have been skipped. `first_nonopt' is the index in ARGV of the first of them; `last_nonopt' is the index after the last of them. */ static int first_nonopt; static int last_nonopt; #ifdef _LIBC /* Bash 2.0 gives us an environment variable containing flags indicating ARGV elements that should not be considered arguments. */ /* Defined in getopt_init.c */ extern char *__getopt_nonoption_flags; static int nonoption_flags_max_len; static int nonoption_flags_len; static int original_argc; static char *const *original_argv; /* Make sure the environment variable bash 2.0 puts in the environment is valid for the getopt call we must make sure that the ARGV passed to getopt is that one passed to the process. */ static void __attribute__ ((unused)) store_args_and_env (int argc, char *const *argv) { /* XXX This is no good solution. We should rather copy the args so that we can compare them later. But we must not use malloc(3). */ original_argc = argc; original_argv = argv; } # ifdef text_set_element text_set_element (__libc_subinit, store_args_and_env); # endif /* text_set_element */ # define SWAP_FLAGS(ch1, ch2) \ if (nonoption_flags_len > 0) \ { \ char __tmp = __getopt_nonoption_flags[ch1]; \ __getopt_nonoption_flags[ch1] = __getopt_nonoption_flags[ch2]; \ __getopt_nonoption_flags[ch2] = __tmp; \ } #else /* !_LIBC */ # define SWAP_FLAGS(ch1, ch2) #endif /* _LIBC */ /* Exchange two adjacent subsequences of ARGV. One subsequence is elements [first_nonopt,last_nonopt) which contains all the non-options that have been skipped so far. The other is elements [last_nonopt,optind), which contains all the options processed since those non-options were skipped. `first_nonopt' and `last_nonopt' are relocated so that they describe the new indices of the non-options in ARGV after they are moved. */ #if defined __STDC__ && __STDC__ static void exchange (char **); #endif static void exchange (argv) char **argv; { int bottom = first_nonopt; int middle = last_nonopt; int top = optind; char *tem; /* Exchange the shorter segment with the far end of the longer segment. That puts the shorter segment into the right place. It leaves the longer segment in the right place overall, but it consists of two parts that need to be swapped next. */ #ifdef _LIBC /* First make sure the handling of the `__getopt_nonoption_flags' string can work normally. Our top argument must be in the range of the string. */ if (nonoption_flags_len > 0 && top >= nonoption_flags_max_len) { /* We must extend the array. The user plays games with us and presents new arguments. */ char *new_str = malloc (top + 1); if (new_str == NULL) nonoption_flags_len = nonoption_flags_max_len = 0; else { memset (__mempcpy (new_str, __getopt_nonoption_flags, nonoption_flags_max_len), '\0', top + 1 - nonoption_flags_max_len); nonoption_flags_max_len = top + 1; __getopt_nonoption_flags = new_str; } } #endif while (top > middle && middle > bottom) { if (top - middle > middle - bottom) { /* Bottom segment is the short one. */ int len = middle - bottom; register int i; /* Swap it with the top part of the top segment. */ for (i = 0; i < len; i++) { tem = argv[bottom + i]; argv[bottom + i] = argv[top - (middle - bottom) + i]; argv[top - (middle - bottom) + i] = tem; SWAP_FLAGS (bottom + i, top - (middle - bottom) + i); } /* Exclude the moved bottom segment from further swapping. */ top -= len; } else { /* Top segment is the short one. */ int len = top - middle; register int i; /* Swap it with the bottom part of the bottom segment. */ for (i = 0; i < len; i++) { tem = argv[bottom + i]; argv[bottom + i] = argv[middle + i]; argv[middle + i] = tem; SWAP_FLAGS (bottom + i, middle + i); } /* Exclude the moved top segment from further swapping. */ bottom += len; } } /* Update records for the slots the non-options now occupy. */ first_nonopt += (optind - last_nonopt); last_nonopt = optind; } /* Initialize the internal data when the first call is made. */ #if defined __STDC__ && __STDC__ static const char *_getopt_initialize (int, char *const *, const char *); #endif static const char * _getopt_initialize (argc, argv, optstring) int argc; char *const *argv; const char *optstring; { /* Start processing options with ARGV-element 1 (since ARGV-element 0 is the program name); the sequence of previously skipped non-option ARGV-elements is empty. */ first_nonopt = last_nonopt = optind; nextchar = NULL; posixly_correct = getenv ("POSIXLY_CORRECT"); /* Determine how to handle the ordering of options and nonoptions. */ if (optstring[0] == '-') { ordering = RETURN_IN_ORDER; ++optstring; } else if (optstring[0] == '+') { ordering = REQUIRE_ORDER; ++optstring; } else if (posixly_correct != NULL) ordering = REQUIRE_ORDER; else ordering = PERMUTE; #ifdef _LIBC if (posixly_correct == NULL && argc == original_argc && argv == original_argv) { if (nonoption_flags_max_len == 0) { if (__getopt_nonoption_flags == NULL || __getopt_nonoption_flags[0] == '\0') nonoption_flags_max_len = -1; else { const char *orig_str = __getopt_nonoption_flags; int len = nonoption_flags_max_len = strlen (orig_str); if (nonoption_flags_max_len < argc) nonoption_flags_max_len = argc; __getopt_nonoption_flags = (char *) malloc (nonoption_flags_max_len); if (__getopt_nonoption_flags == NULL) nonoption_flags_max_len = -1; else memset (__mempcpy (__getopt_nonoption_flags, orig_str, len), '\0', nonoption_flags_max_len - len); } } nonoption_flags_len = nonoption_flags_max_len; } else nonoption_flags_len = 0; #endif return optstring; } /* Scan elements of ARGV (whose length is ARGC) for option characters given in OPTSTRING. If an element of ARGV starts with '-', and is not exactly "-" or "--", then it is an option element. The characters of this element (aside from the initial '-') are option characters. If `getopt' is called repeatedly, it returns successively each of the option characters from each of the option elements. If `getopt' finds another option character, it returns that character, updating `optind' and `nextchar' so that the next call to `getopt' can resume the scan with the following option character or ARGV-element. If there are no more option characters, `getopt' returns -1. Then `optind' is the index in ARGV of the first ARGV-element that is not an option. (The ARGV-elements have been permuted so that those that are not options now come last.) OPTSTRING is a string containing the legitimate option characters. If an option character is seen that is not listed in OPTSTRING, return '?' after printing an error message. If you set `opterr' to zero, the error message is suppressed but we still return '?'. If a char in OPTSTRING is followed by a colon, that means it wants an arg, so the following text in the same ARGV-element, or the text of the following ARGV-element, is returned in `optarg'. Two colons mean an option that wants an optional arg; if there is text in the current ARGV-element, it is returned in `optarg', otherwise `optarg' is set to zero. If OPTSTRING starts with `-' or `+', it requests different methods of handling the non-option ARGV-elements. See the comments about RETURN_IN_ORDER and REQUIRE_ORDER, above. Long-named options begin with `--' instead of `-'. Their names may be abbreviated as long as the abbreviation is unique or is an exact match for some defined option. If they have an argument, it follows the option name in the same ARGV-element, separated from the option name by a `=', or else the in next ARGV-element. When `getopt' finds a long-named option, it returns 0 if that option's `flag' field is nonzero, the value of the option's `val' field if the `flag' field is zero. The elements of ARGV aren't really const, because we permute them. But we pretend they're const in the prototype to be compatible with other systems. LONGOPTS is a vector of `struct option' terminated by an element containing a name which is zero. LONGIND returns the index in LONGOPT of the long-named option found. It is only valid when a long-named option has been found by the most recent call. If LONG_ONLY is nonzero, '-' as well as '--' can introduce long-named options. */ int _getopt_internal (argc, argv, optstring, longopts, longind, long_only) int argc; char *const *argv; const char *optstring; const struct option *longopts; int *longind; int long_only; { int print_errors = opterr; if (optstring[0] == ':') print_errors = 0; optarg = NULL; if (optind == 0 || !__getopt_initialized) { if (optind == 0) optind = 1; /* Don't scan ARGV[0], the program name. */ optstring = _getopt_initialize (argc, argv, optstring); __getopt_initialized = 1; } /* Test whether ARGV[optind] points to a non-option argument. Either it does not have option syntax, or there is an environment flag from the shell indicating it is not an option. The later information is only used when the used in the GNU libc. */ #ifdef _LIBC # define NONOPTION_P (argv[optind][0] != '-' || argv[optind][1] == '\0' \ || (optind < nonoption_flags_len \ && __getopt_nonoption_flags[optind] == '1')) #else # define NONOPTION_P (argv[optind][0] != '-' || argv[optind][1] == '\0') #endif if (nextchar == NULL || *nextchar == '\0') { /* Advance to the next ARGV-element. */ /* Give FIRST_NONOPT & LAST_NONOPT rational values if OPTIND has been moved back by the user (who may also have changed the arguments). */ if (last_nonopt > optind) last_nonopt = optind; if (first_nonopt > optind) first_nonopt = optind; if (ordering == PERMUTE) { /* If we have just processed some options following some non-options, exchange them so that the options come first. */ if (first_nonopt != last_nonopt && last_nonopt != optind) exchange ((char **) argv); else if (last_nonopt != optind) first_nonopt = optind; /* Skip any additional non-options and extend the range of non-options previously skipped. */ while (optind < argc && NONOPTION_P) optind++; last_nonopt = optind; } /* The special ARGV-element `--' means premature end of options. Skip it like a null option, then exchange with previous non-options as if it were an option, then skip everything else like a non-option. */ if (optind != argc && !strcmp (argv[optind], "--")) { optind++; if (first_nonopt != last_nonopt && last_nonopt != optind) exchange ((char **) argv); else if (first_nonopt == last_nonopt) first_nonopt = optind; last_nonopt = argc; optind = argc; } /* If we have done all the ARGV-elements, stop the scan and back over any non-options that we skipped and permuted. */ if (optind == argc) { /* Set the next-arg-index to point at the non-options that we previously skipped, so the caller will digest them. */ if (first_nonopt != last_nonopt) optind = first_nonopt; return -1; } /* If we have come to a non-option and did not permute it, either stop the scan or describe it to the caller and pass it by. */ if (NONOPTION_P) { if (ordering == REQUIRE_ORDER) return -1; optarg = argv[optind++]; return 1; } /* We have found another option-ARGV-element. Skip the initial punctuation. */ nextchar = (argv[optind] + 1 + (longopts != NULL && argv[optind][1] == '-')); } /* Decode the current option-ARGV-element. */ /* Check whether the ARGV-element is a long option. If long_only and the ARGV-element has the form "-f", where f is a valid short option, don't consider it an abbreviated form of a long option that starts with f. Otherwise there would be no way to give the -f short option. On the other hand, if there's a long option "fubar" and the ARGV-element is "-fu", do consider that an abbreviation of the long option, just like "--fu", and not "-f" with arg "u". This distinction seems to be the most useful approach. */ if (longopts != NULL && (argv[optind][1] == '-' || (long_only && (argv[optind][2] || !my_index (optstring, argv[optind][1]))))) { char *nameend; const struct option *p; const struct option *pfound = NULL; int exact = 0; int ambig = 0; int indfound = -1; int option_index; for (nameend = nextchar; *nameend && *nameend != '='; nameend++) /* Do nothing. */ ; /* Test all long options for either exact match or abbreviated matches. */ for (p = longopts, option_index = 0; p->name; p++, option_index++) if (!strncmp (p->name, nextchar, nameend - nextchar)) { if ((unsigned int) (nameend - nextchar) == (unsigned int) strlen (p->name)) { /* Exact match found. */ pfound = p; indfound = option_index; exact = 1; break; } else if (pfound == NULL) { /* First nonexact match found. */ pfound = p; indfound = option_index; } else /* Second or later nonexact match found. */ ambig = 1; } if (ambig && !exact) { if (print_errors) fprintf (stderr, _("%s: option `%s' is ambiguous\n"), argv[0], argv[optind]); nextchar += strlen (nextchar); optind++; optopt = 0; return '?'; } if (pfound != NULL) { option_index = indfound; optind++; if (*nameend) { /* Don't test has_arg with >, because some C compilers don't allow it to be used on enums. */ if (pfound->has_arg) optarg = nameend + 1; else { if (print_errors) { if (argv[optind - 1][1] == '-') /* --option */ fprintf (stderr, _("%s: option `--%s' doesn't allow an argument\n"), argv[0], pfound->name); else /* +option or -option */ fprintf (stderr, _("%s: option `%c%s' doesn't allow an argument\n"), argv[0], argv[optind - 1][0], pfound->name); } nextchar += strlen (nextchar); optopt = pfound->val; return '?'; } } else if (pfound->has_arg == 1) { if (optind < argc) optarg = argv[optind++]; else { if (print_errors) fprintf (stderr, _("%s: option `%s' requires an argument\n"), argv[0], argv[optind - 1]); nextchar += strlen (nextchar); optopt = pfound->val; return optstring[0] == ':' ? ':' : '?'; } } nextchar += strlen (nextchar); if (longind != NULL) *longind = option_index; if (pfound->flag) { *(pfound->flag) = pfound->val; return 0; } return pfound->val; } /* Can't find it as a long option. If this is not getopt_long_only, or the option starts with '--' or is not a valid short option, then it's an error. Otherwise interpret it as a short option. */ if (!long_only || argv[optind][1] == '-' || my_index (optstring, *nextchar) == NULL) { if (print_errors) { if (argv[optind][1] == '-') /* --option */ fprintf (stderr, _("%s: unrecognized option `--%s'\n"), argv[0], nextchar); else /* +option or -option */ fprintf (stderr, _("%s: unrecognized option `%c%s'\n"), argv[0], argv[optind][0], nextchar); } nextchar = (char *) ""; optind++; optopt = 0; return '?'; } } /* Look at and handle the next short option-character. */ { char c = *nextchar++; char *temp = my_index (optstring, c); /* Increment `optind' when we start to process its last character. */ if (*nextchar == '\0') ++optind; if (temp == NULL || c == ':') { if (print_errors) { if (posixly_correct) /* 1003.2 specifies the format of this message. */ fprintf (stderr, _("%s: illegal option -- %c\n"), argv[0], c); else fprintf (stderr, _("%s: invalid option -- %c\n"), argv[0], c); } optopt = c; return '?'; } /* Convenience. Treat POSIX -W foo same as long option --foo */ if (temp[0] == 'W' && temp[1] == ';') { char *nameend; const struct option *p; const struct option *pfound = NULL; int exact = 0; int ambig = 0; int indfound = 0; int option_index; /* This is an option that requires an argument. */ if (*nextchar != '\0') { optarg = nextchar; /* If we end this ARGV-element by taking the rest as an arg, we must advance to the next element now. */ optind++; } else if (optind == argc) { if (print_errors) { /* 1003.2 specifies the format of this message. */ fprintf (stderr, _("%s: option requires an argument -- %c\n"), argv[0], c); } optopt = c; if (optstring[0] == ':') c = ':'; else c = '?'; return c; } else /* We already incremented `optind' once; increment it again when taking next ARGV-elt as argument. */ optarg = argv[optind++]; /* optarg is now the argument, see if it's in the table of longopts. */ for (nextchar = nameend = optarg; *nameend && *nameend != '='; nameend++) /* Do nothing. */ ; /* Test all long options for either exact match or abbreviated matches. */ for (p = longopts, option_index = 0; p->name; p++, option_index++) if (!strncmp (p->name, nextchar, nameend - nextchar)) { if ((unsigned int) (nameend - nextchar) == strlen (p->name)) { /* Exact match found. */ pfound = p; indfound = option_index; exact = 1; break; } else if (pfound == NULL) { /* First nonexact match found. */ pfound = p; indfound = option_index; } else /* Second or later nonexact match found. */ ambig = 1; } if (ambig && !exact) { if (print_errors) fprintf (stderr, _("%s: option `-W %s' is ambiguous\n"), argv[0], argv[optind]); nextchar += strlen (nextchar); optind++; return '?'; } if (pfound != NULL) { option_index = indfound; if (*nameend) { /* Don't test has_arg with >, because some C compilers don't allow it to be used on enums. */ if (pfound->has_arg) optarg = nameend + 1; else { if (print_errors) fprintf (stderr, _("\ %s: option `-W %s' doesn't allow an argument\n"), argv[0], pfound->name); nextchar += strlen (nextchar); return '?'; } } else if (pfound->has_arg == 1) { if (optind < argc) optarg = argv[optind++]; else { if (print_errors) fprintf (stderr, _("%s: option `%s' requires an argument\n"), argv[0], argv[optind - 1]); nextchar += strlen (nextchar); return optstring[0] == ':' ? ':' : '?'; } } nextchar += strlen (nextchar); if (longind != NULL) *longind = option_index; if (pfound->flag) { *(pfound->flag) = pfound->val; return 0; } return pfound->val; } nextchar = NULL; return 'W'; /* Let the application handle it. */ } if (temp[1] == ':') { if (temp[2] == ':') { /* This is an option that accepts an argument optionally. */ if (*nextchar != '\0') { optarg = nextchar; optind++; } else optarg = NULL; nextchar = NULL; } else { /* This is an option that requires an argument. */ if (*nextchar != '\0') { optarg = nextchar; /* If we end this ARGV-element by taking the rest as an arg, we must advance to the next element now. */ optind++; } else if (optind == argc) { if (print_errors) { /* 1003.2 specifies the format of this message. */ fprintf (stderr, _("%s: option requires an argument -- %c\n"), argv[0], c); } optopt = c; if (optstring[0] == ':') c = ':'; else c = '?'; } else /* We already incremented `optind' once; increment it again when taking next ARGV-elt as argument. */ optarg = argv[optind++]; nextchar = NULL; } } return c; } } int getopt (argc, argv, optstring) int argc; char *const *argv; const char *optstring; { return _getopt_internal (argc, argv, optstring, (const struct option *) 0, (int *) 0, 0); } #endif /* Not ELIDE_CODE. */ #ifdef TEST /* Compile with -DTEST to make an executable for use in testing the above definition of `getopt'. */ int main (argc, argv) int argc; char **argv; { int c; int digit_optind = 0; while (1) { int this_option_optind = optind ? optind : 1; c = getopt (argc, argv, "abc:d:0123456789"); if (c == -1) break; switch (c) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': if (digit_optind != 0 && digit_optind != this_option_optind) printf ("digits occur in two different argv-elements.\n"); digit_optind = this_option_optind; printf ("option %c\n", c); break; case 'a': printf ("option a\n"); break; case 'b': printf ("option b\n"); break; case 'c': printf ("option c with value `%s'\n", optarg); break; case '?': break; default: printf ("?? getopt returned character code 0%o ??\n", c); } } if (optind < argc) { printf ("non-option ARGV-elements: "); while (optind < argc) printf ("%s ", argv[optind++]); printf ("\n"); } exit (0); } #endif /* TEST */ sftpserver-0.2.1/utils.h0000664000175000017500000001347711626705056012175 00000000000000/* * This file is part of the Green End SFTP Server. * Copyright (C) 2007, 2011 Richard Kettlewell * * 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 2 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, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA */ /** @file utils.h @brief Utility functions interface */ #ifndef UTILS_H #define UTILS_H /** @brief Read bytes from @p fd * @param fd File descriptor to read from * @param buffer Buffer to store data in * @param size Number of bytes to read * @return 0 on success, non-0 if EOF before @p size bytes read * * Loops if necessary to cope with short reads. Calls fatal() on error. */ int do_read(int fd, void *buffer, size_t size); /* libreadliine contains xmalloc/xrealloc! We use some #defines to work around * the problem. */ #define xmalloc sftp__xmalloc #define xrealloc sftp__xrealloc /** @brief Allocate memory * @param n Number of bytes to allocate * @return Pointer to allocated memory * * Equivalent to @c malloc() but calls fatal() on error. * * Does not zero-fill. */ void *xmalloc(size_t n); /** @brief Allocate memory * @param n Number of objects to allocate * @param size Size of one object * @return Pointer to allocated memory * * Equivalent to @c calloc() but calls fatal() on error. */ void *xcalloc(size_t n, size_t size); /** @brief Reallocate memory * @param ptr Existing allocation * @param n Number of bytes to allocate * @return Pointer to allocated memory * * Equivalent to @c realloc() but calls fatal() on error. * * Does not zero-fill. */ void *xrealloc(void *ptr, size_t n); /** @brief Reallocate memory * @param ptr Existing allocation * @param n Number of objects to allocate * @param size Size of one object * @return Pointer to allocated memory * * Equivalent to @c realloc() but calls fatal() on error. * * Does not zero-fill. */ void *xrecalloc(void *ptr, size_t n, size_t size); /** @brief Duplicate a string * @param s String to duplicate * @return Duplicated string * * Equivalent to @c strdup() but calls fatal() on error. */ char *xstrdup(const char *s); /** @brief Append to a string * @param a Allocator * @param s Existing string * @param ns Where length of @p s is stored * @param t String to append * @return New string */ char *append(struct allocator *a, char *s, size_t *ns, const char *t); /** @brief Append to a string * @param a Allocator * @param s Existing string * @param ns Where length of @p s is stored * @param t String to append * @param lt Length of @p t * @return New string */ char *appendn(struct allocator *a, char *s, size_t *ns, const char *t, size_t lt); /** @brief Convenient wrapper for readlink(2) * @param a Allocator to store result * @param path Path name to inspect * @return Value of symbolic link or a null pointer on error * * Sets @c errno on erorr. */ char *sftp_do_readlink(struct allocator *a, const char *path); /** @brief Return the real (canonical) name of @p path * @param a Allocator to store result * @param path Path name to inspect * @param flags Flags * @return Canonical path name or a null pointer * * Valid flags are: * - @ref RP_READLINK * - @ref RP_MUST_EXIST * * If @ref RP_READLINK is set then symbolic links are followed. Otherwise they * are * not and the transformation is purely lexical. * * If @ref RP_MUST_EXIST is set then the path will be converted even if it * does * not exist or cannot be accessed. If it is clear but the path does not exist * or cannot be accessed then an error _may_ be returned (but this is not * guaranteed). * * Setting @ref RP_MUST_EXIST is an optimization for the case where you're * later * going to do an existence test. * * Sets @c errno on erorr. */ char *sftp_find_realpath(struct allocator *a, const char *path, unsigned flags); /** @brief Follow symlinks * * See sftp_find_realpath(). */ #define RP_READLINK 0x0001 /** @brief Path must exist * * See sftp_find_realpath(). */ #define RP_MUST_EXIST 0x0002 /** @brief Compute the name of the current directory * @param a Allocator to store result * @return Name of current directory, or a null pointer */ char *sftp_getcwd(struct allocator *a); /** @brief Compute the directory name part of @p path * @param a Allocator to store result * @param path Path name to extract directory from * @return Directory name */ const char *sftp_dirname(struct allocator *a, const char *path); /** @brief Write an error and terminate * @param msg Format string as per @c printf(3) * @param ... Arguments * * The error is written either to standard error or syslog; see @ref * log_syslog. * * Terminates the process. */ void fatal(const char *msg, ...) attribute((noreturn)) attribute((format(printf,1,2))); /** @brief Fork a subprocess * @return 0 in the child, process ID in the parent * * Calls fatal() on error. */ pid_t xfork(void); /** @brief Called after forking * * Affects the way that fatal() terminates the process. * * xfork() already calls it, any other calls to @c fork() should call it * explicitly. */ void forked(void); /** @brief Whether to log to syslog * * Affects where fatal() writes to. */ extern int log_syslog; #endif /* UTILS_H */ /* Local Variables: c-basic-offset:2 comment-column:40 fill-column:79 indent-tabs-mode:nil End: */ sftpserver-0.2.1/debug.c0000664000175000017500000000503511626705056012105 00000000000000/* * This file is part of the Green End SFTP Server. * Copyright (C) 2007, 2011 Richard Kettlewell * * 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 2 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, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA */ /** @file debug.c @brief Debug support implementation */ #include "sftpserver.h" #include "debug.h" #include #include #include #include #include #include #include /** @brief Output file for debug information */ static FILE *debugfp; const char *sftp_debugpath; int sftp_debugging; /** @brief Ensure that @ref debugfp is open */ static void opendebug(void) { assert(sftp_debugging); if(!debugfp) { if(sftp_debugpath) { int fd; if((fd = open(sftp_debugpath, O_WRONLY|O_CREAT|O_TRUNC, 0600)) >= 0) debugfp = fdopen(fd, "w"); else fprintf(stderr, "%s: %s\n", sftp_debugpath, strerror(errno)); } if(!debugfp) debugfp = stderr; } } void sftp_debug_hexdump(const void *ptr, size_t n) { const unsigned char *p = ptr; size_t i, j; char buffer[80], *output; opendebug(); for(i = 0; i < n; i += 16) { output = buffer; output += sprintf(output, "%4lx ", (unsigned long)i); for(j = 0; j < 16; ++j) if(i + j < n) output += sprintf(output, " %02x", p[i + j]); else { strcpy(output, " "); output += 3; } strcpy(output, " "); output += 2; for(j = 0; j < 16; ++j) if(i + j < n) *output++ = isprint(p[i + j]) ? p[i+j] : '.'; *output++ = '\n'; *output = 0; fputs(buffer, debugfp); } fflush(debugfp); } void sftp_debug_printf(const char *fmt, ...) { va_list ap; const int save_errno = errno; opendebug(); va_start(ap, fmt); vfprintf(debugfp, fmt, ap); va_end(ap); fputc('\n', debugfp); fflush(debugfp); errno = save_errno; } /* Local Variables: c-basic-offset:2 comment-column:40 fill-column:79 indent-tabs-mode:nil End: */ sftpserver-0.2.1/serialize.c0000664000175000017500000002010011626752072012774 00000000000000/* * This file is part of the Green End SFTP Server. * Copyright (C) 2007, 2011 Richard Kettlewell * * 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 2 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, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA */ #include "sftpserver.h" #include "types.h" #include "thread.h" #include "utils.h" #include "handle.h" #include "sftp.h" #include "parse.h" #include "serialize.h" #include "debug.h" #include "globals.h" #include #include /** @file serialize.c @brief Request serialization implementation * * Implement serialization requirements as per draft-ietf-secsh-filexfer-02.txt * s6, or -13.txt s4.1. Two points worth noting: * * 1) The language there is in terms of 'files'. That implies that there's * more than just a requirement on (potentially) overlapping reads and writes. * * 2) The language says you "MUST" process requests in the order received but * then backs off a bit and allows non-overlapping requests to be re-ordered or * parallelized. I interpret this to mean that there's an unstated 'as-if' * model going on, i.e. the requirement is that the file contents or returned * data is the same as if you'd done your operations in order, rather than that * the actual operation system calls have to happen in a specific order even if * more efficient orderings are available that give the same end result. * * 3) We are willing to re-order read and write requests (up to a point) but we * don't re-order opens, deletes, renames, etc. So you can stack up an open * and a delete and rely on the order in which they are executed. We don't try * to be clever and allow re-ordering of operations where different orders * couldn't make a difference. * * 4) Reads don't include @ref SSH_FXP_READDIR. Therefore such requests are always * serialized, which saves us having to worry about the thread safety of the * functions. Indeed you could say this about any other operation * but readdir() is the most obvious one to worry about. * */ /** @brief One job in the serialization queue */ struct sqnode { /** @brief The next job in the queue */ struct sqnode *older; /** @brief This job */ struct sftpjob *job; /** @brief Handle used by this job */ struct handleid hid; /** @brief Flags for the handle */ unsigned handleflags; /** @brief Offset of the read or write */ uint64_t offset; /** @brief Length of the read or write */ uint64_t len; /** @brief Request type */ uint8_t type; }; /** @brief The newest job in the queue */ static struct sqnode *newest; /** @brief Lock protecting the serialization queue */ static pthread_mutex_t sq_mutex = PTHREAD_MUTEX_INITIALIZER; /** @brief Condition variable signaling changes to the queue */ static pthread_cond_t sq_cond = PTHREAD_COND_INITIALIZER; /** @brief Test whether two handles are identical * @param h1 Handle * @param h2 Handle * @return Nonzero if @p h1 matches @p h2 */ static inline int handles_equal(const struct handleid *h1, const struct handleid *h2) { return h1->id == h2->id && h1->tag == h2->tag; } /** @brief Test whether two IO ranges overlap * @param a Serialization queue entry * @param b Serialization queue entry * @return Nonzero if the IO ranges for @p a and @p b overlap */ static int ranges_overlap(const struct sqnode *a, const struct sqnode *b) { if(a->len && b->len) { const uint64_t aend = a->offset + a->len - 1; const uint64_t bend = b->offset + b->len - 1; if(aend >= b->offset && aend <= bend) return 1; if(bend >= a->offset && bend <= aend) return 1; } return 0; } /** @brief Test wether two jobs may be re-ordered * @param q1 Serialization queue entry * @param q2 Serialization queue entry * @param flags Flags for @p q1 * @return Nonzero if the @p q1 and @p q2 may be re-ordered * * @todo Reordering is currently partially disabled because it breaks Paramiko. * See https://github.com/robey/paramiko/issues/34 for details. */ static int reorderable(const struct sqnode *q1, const struct sqnode *q2, unsigned flags) { if((q1->type == SSH_FXP_READ || q1->type == SSH_FXP_WRITE) && (q2->type == SSH_FXP_READ || q2->type == SSH_FXP_WRITE)) { /* We allow reads and writes to be re-ordered up to a point */ if(!handles_equal(&q1->hid, &q2->hid)) { /* Operations on different handles can always be re-ordered. */ return 1; } /* Paramiko's prefetch algorithm assumes that response order matches * request order. As a workaround we avoid re-ordering reads until a fix * is adequately widely deployed ("in Debian stable" seems like a good * measure). */ if(q1->type == SSH_FXP_READ && q2->type == SSH_FXP_READ) return 0; if(flags & (HANDLE_TEXT|HANDLE_APPEND)) /* Operations on text or append-write files cannot be re-oredered. */ return 0; if(q1->type == SSH_FXP_WRITE || q2->type == SSH_FXP_WRITE) if(ranges_overlap(q1, q2)) /* If one of the operations is a write and the ranges overlap then no * re-ordering is allowed. */ return 0; return 1; } else /* Nothing else may be re-ordered with respect to anything */ return 0; } void queue_serializable_job(struct sftpjob *job) { uint8_t type; uint32_t id; uint64_t offset, len64; uint32_t len; struct handleid hid; unsigned handleflags; struct sqnode *q; job->ptr = job->data; job->left = job->len; if(!sftp_parse_uint8(job, &type) && (type == SSH_FXP_READ || type == SSH_FXP_WRITE) && sftp_parse_uint32(job, &id) == SSH_FX_OK && sftp_parse_handle(job, &hid) == SSH_FX_OK && sftp_parse_uint64(job, &offset) == SSH_FX_OK && sftp_parse_uint32(job, &len) == SSH_FX_OK) { /* This is a well-formed read or write operation */ len64 = len; handleflags = sftp_handle_flags(&hid); } else { /* Anything else has dummy values */ memset(&hid, 0, sizeof hid); offset = 0; len64 = ~(uint64_t)0; handleflags = 0; } ferrcheck(pthread_mutex_lock(&sq_mutex)); q = xmalloc(sizeof *q); q->older = newest; q->job = job; q->type = type; q->hid = hid; q->handleflags = handleflags; q->offset = offset; q->len = len64; newest = q; ferrcheck(pthread_mutex_unlock(&sq_mutex)); } void serialize(struct sftpjob *job) { struct sqnode *q, *oq; ferrcheck(pthread_mutex_lock(&sq_mutex)); for(;;) { for(q = newest; q && q->job != job; q = q->older) ; /* If the job isn't in the queue then we process it straight away. This * shouldn't happen... */ if(!q) break; /* We've found our position in the queue. See if there is any request on * the same handle which blocks our request. */ for(oq = q->older; oq; oq = oq->older) if(!reorderable(q, oq, q->handleflags)) break; if(!oq) break; /* We found an blocking request. Wait for it to be removed. */ ferrcheck(pthread_cond_wait(&sq_cond, &sq_mutex)); } /* We did not find any blocking request. We proceed. */ ferrcheck(pthread_mutex_unlock(&sq_mutex)); } void serialize_remove_job(struct sftpjob *job) { struct sqnode *q, **qq; ferrcheck(pthread_mutex_lock(&sq_mutex)); for(qq = &newest; (q = *qq) && q->job != job; qq = &q->older) ; if(q) { *qq = q->older; free(q); /* Wake up anything that's waiting */ ferrcheck(pthread_cond_broadcast(&sq_cond)); } ferrcheck(pthread_mutex_unlock(&sq_mutex)); } /* Local Variables: c-basic-offset:2 comment-column:40 fill-column:79 indent-tabs-mode:nil End: */ sftpserver-0.2.1/configure0000775000175000017500000063363212415610055012563 00000000000000#! /bin/sh # Guess values for system-dependent variables and create Makefiles. # Generated by GNU Autoconf 2.69 for sftpserver 0.2.1. # # Report bugs to . # # # Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc. # # # This configure script is free software; the Free Software Foundation # gives unlimited permission to copy, distribute and modify it. ## -------------------- ## ## M4sh Initialization. ## ## -------------------- ## # Be more Bourne compatible DUALCASE=1; export DUALCASE # for MKS sh if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then : emulate sh NULLCMD=: # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which # is contrary to our usage. Disable this feature. alias -g '${1+"$@"}'='"$@"' setopt NO_GLOB_SUBST else case `(set -o) 2>/dev/null` in #( *posix*) : set -o posix ;; #( *) : ;; esac fi as_nl=' ' export as_nl # Printing a long string crashes Solaris 7 /usr/bin/printf. as_echo='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\' as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo$as_echo # Prefer a ksh shell builtin over an external printf program on Solaris, # but without wasting forks for bash or zsh. if test -z "$BASH_VERSION$ZSH_VERSION" \ && (test "X`print -r -- $as_echo`" = "X$as_echo") 2>/dev/null; then as_echo='print -r --' as_echo_n='print -rn --' elif (test "X`printf %s $as_echo`" = "X$as_echo") 2>/dev/null; then as_echo='printf %s\n' as_echo_n='printf %s' else if test "X`(/usr/ucb/echo -n -n $as_echo) 2>/dev/null`" = "X-n $as_echo"; then as_echo_body='eval /usr/ucb/echo -n "$1$as_nl"' as_echo_n='/usr/ucb/echo -n' else as_echo_body='eval expr "X$1" : "X\\(.*\\)"' as_echo_n_body='eval arg=$1; case $arg in #( *"$as_nl"*) expr "X$arg" : "X\\(.*\\)$as_nl"; arg=`expr "X$arg" : ".*$as_nl\\(.*\\)"`;; esac; expr "X$arg" : "X\\(.*\\)" | tr -d "$as_nl" ' export as_echo_n_body as_echo_n='sh -c $as_echo_n_body as_echo' fi export as_echo_body as_echo='sh -c $as_echo_body as_echo' fi # The user is always right. if test "${PATH_SEPARATOR+set}" != set; then PATH_SEPARATOR=: (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && { (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 || PATH_SEPARATOR=';' } fi # IFS # We need space, tab and new line, in precisely that order. Quoting is # there to prevent editors from complaining about space-tab. # (If _AS_PATH_WALK were called with IFS unset, it would disable word # splitting by setting IFS to empty value.) IFS=" "" $as_nl" # Find who we are. Look in the path if we contain no directory separator. as_myself= case $0 in #(( *[\\/]* ) as_myself=$0 ;; *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break done IFS=$as_save_IFS ;; esac # We did not find ourselves, most probably we were run as `sh COMMAND' # in which case we are not to be found in the path. if test "x$as_myself" = x; then as_myself=$0 fi if test ! -f "$as_myself"; then $as_echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2 exit 1 fi # Unset variables that we do not need and which cause bugs (e.g. in # pre-3.0 UWIN ksh). But do not cause bugs in bash 2.01; the "|| exit 1" # suppresses any "Segmentation fault" message there. '((' could # trigger a bug in pdksh 5.2.14. for as_var in BASH_ENV ENV MAIL MAILPATH do eval test x\${$as_var+set} = xset \ && ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || : done PS1='$ ' PS2='> ' PS4='+ ' # NLS nuisances. LC_ALL=C export LC_ALL LANGUAGE=C export LANGUAGE # CDPATH. (unset CDPATH) >/dev/null 2>&1 && unset CDPATH # Use a proper internal environment variable to ensure we don't fall # into an infinite loop, continuously re-executing ourselves. if test x"${_as_can_reexec}" != xno && test "x$CONFIG_SHELL" != x; then _as_can_reexec=no; export _as_can_reexec; # We cannot yet assume a decent shell, so we have to provide a # neutralization value for shells without unset; and this also # works around shells that cannot unset nonexistent variables. # Preserve -v and -x to the replacement shell. BASH_ENV=/dev/null ENV=/dev/null (unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV case $- in # (((( *v*x* | *x*v* ) as_opts=-vx ;; *v* ) as_opts=-v ;; *x* ) as_opts=-x ;; * ) as_opts= ;; esac exec $CONFIG_SHELL $as_opts "$as_myself" ${1+"$@"} # Admittedly, this is quite paranoid, since all the known shells bail # out after a failed `exec'. $as_echo "$0: could not re-execute with $CONFIG_SHELL" >&2 as_fn_exit 255 fi # We don't want this to propagate to other subprocesses. { _as_can_reexec=; unset _as_can_reexec;} if test "x$CONFIG_SHELL" = x; then as_bourne_compatible="if test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then : emulate sh NULLCMD=: # Pre-4.2 versions of Zsh do word splitting on \${1+\"\$@\"}, which # is contrary to our usage. Disable this feature. alias -g '\${1+\"\$@\"}'='\"\$@\"' setopt NO_GLOB_SUBST else case \`(set -o) 2>/dev/null\` in #( *posix*) : set -o posix ;; #( *) : ;; esac fi " as_required="as_fn_return () { (exit \$1); } as_fn_success () { as_fn_return 0; } as_fn_failure () { as_fn_return 1; } as_fn_ret_success () { return 0; } as_fn_ret_failure () { return 1; } exitcode=0 as_fn_success || { exitcode=1; echo as_fn_success failed.; } as_fn_failure && { exitcode=1; echo as_fn_failure succeeded.; } as_fn_ret_success || { exitcode=1; echo as_fn_ret_success failed.; } as_fn_ret_failure && { exitcode=1; echo as_fn_ret_failure succeeded.; } if ( set x; as_fn_ret_success y && test x = \"\$1\" ); then : else exitcode=1; echo positional parameters were not saved. fi test x\$exitcode = x0 || exit 1 test -x / || exit 1" as_suggested=" as_lineno_1=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_1a=\$LINENO as_lineno_2=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_2a=\$LINENO eval 'test \"x\$as_lineno_1'\$as_run'\" != \"x\$as_lineno_2'\$as_run'\" && test \"x\`expr \$as_lineno_1'\$as_run' + 1\`\" = \"x\$as_lineno_2'\$as_run'\"' || exit 1 test \$(( 1 + 1 )) = 2 || exit 1" if (eval "$as_required") 2>/dev/null; then : as_have_required=yes else as_have_required=no fi if test x$as_have_required = xyes && (eval "$as_suggested") 2>/dev/null; then : else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR as_found=false for as_dir in /bin$PATH_SEPARATOR/usr/bin$PATH_SEPARATOR$PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. as_found=: case $as_dir in #( /*) for as_base in sh bash ksh sh5; do # Try only shells that exist, to save several forks. as_shell=$as_dir/$as_base if { test -f "$as_shell" || test -f "$as_shell.exe"; } && { $as_echo "$as_bourne_compatible""$as_required" | as_run=a "$as_shell"; } 2>/dev/null; then : CONFIG_SHELL=$as_shell as_have_required=yes if { $as_echo "$as_bourne_compatible""$as_suggested" | as_run=a "$as_shell"; } 2>/dev/null; then : break 2 fi fi done;; esac as_found=false done $as_found || { if { test -f "$SHELL" || test -f "$SHELL.exe"; } && { $as_echo "$as_bourne_compatible""$as_required" | as_run=a "$SHELL"; } 2>/dev/null; then : CONFIG_SHELL=$SHELL as_have_required=yes fi; } IFS=$as_save_IFS if test "x$CONFIG_SHELL" != x; then : export CONFIG_SHELL # We cannot yet assume a decent shell, so we have to provide a # neutralization value for shells without unset; and this also # works around shells that cannot unset nonexistent variables. # Preserve -v and -x to the replacement shell. BASH_ENV=/dev/null ENV=/dev/null (unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV case $- in # (((( *v*x* | *x*v* ) as_opts=-vx ;; *v* ) as_opts=-v ;; *x* ) as_opts=-x ;; * ) as_opts= ;; esac exec $CONFIG_SHELL $as_opts "$as_myself" ${1+"$@"} # Admittedly, this is quite paranoid, since all the known shells bail # out after a failed `exec'. $as_echo "$0: could not re-execute with $CONFIG_SHELL" >&2 exit 255 fi if test x$as_have_required = xno; then : $as_echo "$0: This script requires a shell more modern than all" $as_echo "$0: the shells that I found on your system." if test x${ZSH_VERSION+set} = xset ; then $as_echo "$0: In particular, zsh $ZSH_VERSION has bugs and should" $as_echo "$0: be upgraded to zsh 4.3.4 or later." else $as_echo "$0: Please tell bug-autoconf@gnu.org and $0: richard+sftpserver@sfere.greenend.org.uk about your $0: system, including any error possibly output before this $0: message. Then install a modern shell, or manually run $0: the script under such a shell if you do have one." fi exit 1 fi fi fi SHELL=${CONFIG_SHELL-/bin/sh} export SHELL # Unset more variables known to interfere with behavior of common tools. CLICOLOR_FORCE= GREP_OPTIONS= unset CLICOLOR_FORCE GREP_OPTIONS ## --------------------- ## ## M4sh Shell Functions. ## ## --------------------- ## # as_fn_unset VAR # --------------- # Portably unset VAR. as_fn_unset () { { eval $1=; unset $1;} } as_unset=as_fn_unset # as_fn_set_status STATUS # ----------------------- # Set $? to STATUS, without forking. as_fn_set_status () { return $1 } # as_fn_set_status # as_fn_exit STATUS # ----------------- # Exit the shell with STATUS, even in a "trap 0" or "set -e" context. as_fn_exit () { set +e as_fn_set_status $1 exit $1 } # as_fn_exit # as_fn_mkdir_p # ------------- # Create "$as_dir" as a directory, including parents if necessary. as_fn_mkdir_p () { case $as_dir in #( -*) as_dir=./$as_dir;; esac test -d "$as_dir" || eval $as_mkdir_p || { as_dirs= while :; do case $as_dir in #( *\'*) as_qdir=`$as_echo "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'( *) as_qdir=$as_dir;; esac as_dirs="'$as_qdir' $as_dirs" as_dir=`$as_dirname -- "$as_dir" || $as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ X"$as_dir" : 'X\(//\)[^/]' \| \ X"$as_dir" : 'X\(//\)$' \| \ X"$as_dir" : 'X\(/\)' \| . 2>/dev/null || $as_echo X"$as_dir" | sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/ q } /^X\(\/\/\)[^/].*/{ s//\1/ q } /^X\(\/\/\)$/{ s//\1/ q } /^X\(\/\).*/{ s//\1/ q } s/.*/./; q'` test -d "$as_dir" && break done test -z "$as_dirs" || eval "mkdir $as_dirs" } || test -d "$as_dir" || as_fn_error $? "cannot create directory $as_dir" } # as_fn_mkdir_p # as_fn_executable_p FILE # ----------------------- # Test if FILE is an executable regular file. as_fn_executable_p () { test -f "$1" && test -x "$1" } # as_fn_executable_p # as_fn_append VAR VALUE # ---------------------- # Append the text in VALUE to the end of the definition contained in VAR. Take # advantage of any shell optimizations that allow amortized linear growth over # repeated appends, instead of the typical quadratic growth present in naive # implementations. if (eval "as_var=1; as_var+=2; test x\$as_var = x12") 2>/dev/null; then : eval 'as_fn_append () { eval $1+=\$2 }' else as_fn_append () { eval $1=\$$1\$2 } fi # as_fn_append # as_fn_arith ARG... # ------------------ # Perform arithmetic evaluation on the ARGs, and store the result in the # global $as_val. Take advantage of shells that can avoid forks. The arguments # must be portable across $(()) and expr. if (eval "test \$(( 1 + 1 )) = 2") 2>/dev/null; then : eval 'as_fn_arith () { as_val=$(( $* )) }' else as_fn_arith () { as_val=`expr "$@" || test $? -eq 1` } fi # as_fn_arith # as_fn_error STATUS ERROR [LINENO LOG_FD] # ---------------------------------------- # Output "`basename $0`: error: ERROR" to stderr. If LINENO and LOG_FD are # provided, also output the error to LOG_FD, referencing LINENO. Then exit the # script with STATUS, using 1 if that was 0. as_fn_error () { as_status=$1; test $as_status -eq 0 && as_status=1 if test "$4"; then as_lineno=${as_lineno-"$3"} as_lineno_stack=as_lineno_stack=$as_lineno_stack $as_echo "$as_me:${as_lineno-$LINENO}: error: $2" >&$4 fi $as_echo "$as_me: error: $2" >&2 as_fn_exit $as_status } # as_fn_error if expr a : '\(a\)' >/dev/null 2>&1 && test "X`expr 00001 : '.*\(...\)'`" = X001; then as_expr=expr else as_expr=false fi if (basename -- /) >/dev/null 2>&1 && test "X`basename -- / 2>&1`" = "X/"; then as_basename=basename else as_basename=false fi if (as_dir=`dirname -- /` && test "X$as_dir" = X/) >/dev/null 2>&1; then as_dirname=dirname else as_dirname=false fi as_me=`$as_basename -- "$0" || $as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \ X"$0" : 'X\(//\)$' \| \ X"$0" : 'X\(/\)' \| . 2>/dev/null || $as_echo X/"$0" | sed '/^.*\/\([^/][^/]*\)\/*$/{ s//\1/ q } /^X\/\(\/\/\)$/{ s//\1/ q } /^X\/\(\/\).*/{ s//\1/ q } s/.*/./; q'` # Avoid depending upon Character Ranges. as_cr_letters='abcdefghijklmnopqrstuvwxyz' as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ' as_cr_Letters=$as_cr_letters$as_cr_LETTERS as_cr_digits='0123456789' as_cr_alnum=$as_cr_Letters$as_cr_digits as_lineno_1=$LINENO as_lineno_1a=$LINENO as_lineno_2=$LINENO as_lineno_2a=$LINENO eval 'test "x$as_lineno_1'$as_run'" != "x$as_lineno_2'$as_run'" && test "x`expr $as_lineno_1'$as_run' + 1`" = "x$as_lineno_2'$as_run'"' || { # Blame Lee E. McMahon (1931-1989) for sed's syntax. :-) sed -n ' p /[$]LINENO/= ' <$as_myself | sed ' s/[$]LINENO.*/&-/ t lineno b :lineno N :loop s/[$]LINENO\([^'$as_cr_alnum'_].*\n\)\(.*\)/\2\1\2/ t loop s/-\n.*// ' >$as_me.lineno && chmod +x "$as_me.lineno" || { $as_echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2; as_fn_exit 1; } # If we had to re-execute with $CONFIG_SHELL, we're ensured to have # already done that, so ensure we don't try to do so again and fall # in an infinite loop. This has already happened in practice. _as_can_reexec=no; export _as_can_reexec # Don't try to exec as it changes $[0], causing all sort of problems # (the dirname of $[0] is not the place where we might find the # original and so on. Autoconf is especially sensitive to this). . "./$as_me.lineno" # Exit status is that of the last command. exit } ECHO_C= ECHO_N= ECHO_T= case `echo -n x` in #((((( -n*) case `echo 'xy\c'` in *c*) ECHO_T=' ';; # ECHO_T is single tab character. xy) ECHO_C='\c';; *) echo `echo ksh88 bug on AIX 6.1` > /dev/null ECHO_T=' ';; esac;; *) ECHO_N='-n';; esac rm -f conf$$ conf$$.exe conf$$.file if test -d conf$$.dir; then rm -f conf$$.dir/conf$$.file else rm -f conf$$.dir mkdir conf$$.dir 2>/dev/null fi if (echo >conf$$.file) 2>/dev/null; then if ln -s conf$$.file conf$$ 2>/dev/null; then as_ln_s='ln -s' # ... but there are two gotchas: # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail. # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable. # In both cases, we have to default to `cp -pR'. ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe || as_ln_s='cp -pR' elif ln conf$$.file conf$$ 2>/dev/null; then as_ln_s=ln else as_ln_s='cp -pR' fi else as_ln_s='cp -pR' fi rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file rmdir conf$$.dir 2>/dev/null if mkdir -p . 2>/dev/null; then as_mkdir_p='mkdir -p "$as_dir"' else test -d ./-p && rmdir ./-p as_mkdir_p=false fi as_test_x='test -x' as_executable_p=as_fn_executable_p # Sed expression to map a string onto a valid CPP name. as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'" # Sed expression to map a string onto a valid variable name. as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'" test -n "$DJDIR" || exec 7<&0 &1 # Name of the host. # hostname on some systems (SVR3.2, old GNU/Linux) returns a bogus exit status, # so uname gets run too. ac_hostname=`(hostname || uname -n) 2>/dev/null | sed 1q` # # Initializations. # ac_default_prefix=/usr/local ac_clean_files= ac_config_libobj_dir=. LIBOBJS= cross_compiling=no subdirs= MFLAGS= MAKEFLAGS= # Identity of this package. PACKAGE_NAME='sftpserver' PACKAGE_TARNAME='sftpserver' PACKAGE_VERSION='0.2.1' PACKAGE_STRING='sftpserver 0.2.1' PACKAGE_BUGREPORT='richard+sftpserver@sfere.greenend.org.uk' PACKAGE_URL='' ac_unique_file="alloc.c" # Factoring default headers for most tests. ac_includes_default="\ #include #ifdef HAVE_SYS_TYPES_H # include #endif #ifdef HAVE_SYS_STAT_H # include #endif #ifdef STDC_HEADERS # include # include #else # ifdef HAVE_STDLIB_H # include # endif #endif #ifdef HAVE_STRING_H # if !defined STDC_HEADERS && defined HAVE_MEMORY_H # include # endif # include #endif #ifdef HAVE_STRINGS_H # include #endif #ifdef HAVE_INTTYPES_H # include #endif #ifdef HAVE_STDINT_H # include #endif #ifdef HAVE_UNISTD_H # include #endif" ac_subst_vars='am__EXEEXT_FALSE am__EXEEXT_TRUE LTLIBOBJS GCOV PYTHON24 LIBOBJS LIBREADLINE EGREP GREP CPP RANLIB host_os host_vendor host_cpu host build_os build_vendor build_cpu build am__fastdepCC_FALSE am__fastdepCC_TRUE CCDEPMODE am__nodep AMDEPBACKSLASH AMDEP_FALSE AMDEP_TRUE am__quote am__include DEPDIR OBJEXT EXEEXT ac_ct_CC CPPFLAGS LDFLAGS CFLAGS CC am__untar am__tar AMTAR am__leading_dot SET_MAKE AWK mkdir_p MKDIR_P INSTALL_STRIP_PROGRAM STRIP install_sh MAKEINFO AUTOHEADER AUTOMAKE AUTOCONF ACLOCAL VERSION PACKAGE CYGPATH_W am__isrc INSTALL_DATA INSTALL_SCRIPT INSTALL_PROGRAM target_alias host_alias build_alias LIBS ECHO_T ECHO_N ECHO_C DEFS mandir localedir libdir psdir pdfdir dvidir htmldir infodir docdir oldincludedir includedir localstatedir sharedstatedir sysconfdir datadir datarootdir libexecdir sbindir bindir program_transform_name prefix exec_prefix PACKAGE_URL PACKAGE_BUGREPORT PACKAGE_STRING PACKAGE_VERSION PACKAGE_TARNAME PACKAGE_NAME PATH_SEPARATOR SHELL' ac_subst_files='' ac_user_opts=' enable_option_checking enable_dependency_tracking enable_largefile enable_warnings enable_warnings_as_errors enable_reversed_symlink enable_daemon with_gcov ' ac_precious_vars='build_alias host_alias target_alias CC CFLAGS LDFLAGS LIBS CPPFLAGS CPP' # Initialize some variables set by options. ac_init_help= ac_init_version=false ac_unrecognized_opts= ac_unrecognized_sep= # The variables have the same names as the options, with # dashes changed to underlines. cache_file=/dev/null exec_prefix=NONE no_create= no_recursion= prefix=NONE program_prefix=NONE program_suffix=NONE program_transform_name=s,x,x, silent= site= srcdir= verbose= x_includes=NONE x_libraries=NONE # Installation directory options. # These are left unexpanded so users can "make install exec_prefix=/foo" # and all the variables that are supposed to be based on exec_prefix # by default will actually change. # Use braces instead of parens because sh, perl, etc. also accept them. # (The list follows the same order as the GNU Coding Standards.) bindir='${exec_prefix}/bin' sbindir='${exec_prefix}/sbin' libexecdir='${exec_prefix}/libexec' datarootdir='${prefix}/share' datadir='${datarootdir}' sysconfdir='${prefix}/etc' sharedstatedir='${prefix}/com' localstatedir='${prefix}/var' includedir='${prefix}/include' oldincludedir='/usr/include' docdir='${datarootdir}/doc/${PACKAGE_TARNAME}' infodir='${datarootdir}/info' htmldir='${docdir}' dvidir='${docdir}' pdfdir='${docdir}' psdir='${docdir}' libdir='${exec_prefix}/lib' localedir='${datarootdir}/locale' mandir='${datarootdir}/man' ac_prev= ac_dashdash= for ac_option do # If the previous option needs an argument, assign it. if test -n "$ac_prev"; then eval $ac_prev=\$ac_option ac_prev= continue fi case $ac_option in *=?*) ac_optarg=`expr "X$ac_option" : '[^=]*=\(.*\)'` ;; *=) ac_optarg= ;; *) ac_optarg=yes ;; esac # Accept the important Cygnus configure options, so we can diagnose typos. case $ac_dashdash$ac_option in --) ac_dashdash=yes ;; -bindir | --bindir | --bindi | --bind | --bin | --bi) ac_prev=bindir ;; -bindir=* | --bindir=* | --bindi=* | --bind=* | --bin=* | --bi=*) bindir=$ac_optarg ;; -build | --build | --buil | --bui | --bu) ac_prev=build_alias ;; -build=* | --build=* | --buil=* | --bui=* | --bu=*) build_alias=$ac_optarg ;; -cache-file | --cache-file | --cache-fil | --cache-fi \ | --cache-f | --cache- | --cache | --cach | --cac | --ca | --c) ac_prev=cache_file ;; -cache-file=* | --cache-file=* | --cache-fil=* | --cache-fi=* \ | --cache-f=* | --cache-=* | --cache=* | --cach=* | --cac=* | --ca=* | --c=*) cache_file=$ac_optarg ;; --config-cache | -C) cache_file=config.cache ;; -datadir | --datadir | --datadi | --datad) ac_prev=datadir ;; -datadir=* | --datadir=* | --datadi=* | --datad=*) datadir=$ac_optarg ;; -datarootdir | --datarootdir | --datarootdi | --datarootd | --dataroot \ | --dataroo | --dataro | --datar) ac_prev=datarootdir ;; -datarootdir=* | --datarootdir=* | --datarootdi=* | --datarootd=* \ | --dataroot=* | --dataroo=* | --dataro=* | --datar=*) datarootdir=$ac_optarg ;; -disable-* | --disable-*) ac_useropt=`expr "x$ac_option" : 'x-*disable-\(.*\)'` # Reject names that are not valid shell variable names. expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && as_fn_error $? "invalid feature name: $ac_useropt" ac_useropt_orig=$ac_useropt ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` case $ac_user_opts in *" "enable_$ac_useropt" "*) ;; *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--disable-$ac_useropt_orig" ac_unrecognized_sep=', ';; esac eval enable_$ac_useropt=no ;; -docdir | --docdir | --docdi | --doc | --do) ac_prev=docdir ;; -docdir=* | --docdir=* | --docdi=* | --doc=* | --do=*) docdir=$ac_optarg ;; -dvidir | --dvidir | --dvidi | --dvid | --dvi | --dv) ac_prev=dvidir ;; -dvidir=* | --dvidir=* | --dvidi=* | --dvid=* | --dvi=* | --dv=*) dvidir=$ac_optarg ;; -enable-* | --enable-*) ac_useropt=`expr "x$ac_option" : 'x-*enable-\([^=]*\)'` # Reject names that are not valid shell variable names. expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && as_fn_error $? "invalid feature name: $ac_useropt" ac_useropt_orig=$ac_useropt ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` case $ac_user_opts in *" "enable_$ac_useropt" "*) ;; *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--enable-$ac_useropt_orig" ac_unrecognized_sep=', ';; esac eval enable_$ac_useropt=\$ac_optarg ;; -exec-prefix | --exec_prefix | --exec-prefix | --exec-prefi \ | --exec-pref | --exec-pre | --exec-pr | --exec-p | --exec- \ | --exec | --exe | --ex) ac_prev=exec_prefix ;; -exec-prefix=* | --exec_prefix=* | --exec-prefix=* | --exec-prefi=* \ | --exec-pref=* | --exec-pre=* | --exec-pr=* | --exec-p=* | --exec-=* \ | --exec=* | --exe=* | --ex=*) exec_prefix=$ac_optarg ;; -gas | --gas | --ga | --g) # Obsolete; use --with-gas. with_gas=yes ;; -help | --help | --hel | --he | -h) ac_init_help=long ;; -help=r* | --help=r* | --hel=r* | --he=r* | -hr*) ac_init_help=recursive ;; -help=s* | --help=s* | --hel=s* | --he=s* | -hs*) ac_init_help=short ;; -host | --host | --hos | --ho) ac_prev=host_alias ;; -host=* | --host=* | --hos=* | --ho=*) host_alias=$ac_optarg ;; -htmldir | --htmldir | --htmldi | --htmld | --html | --htm | --ht) ac_prev=htmldir ;; -htmldir=* | --htmldir=* | --htmldi=* | --htmld=* | --html=* | --htm=* \ | --ht=*) htmldir=$ac_optarg ;; -includedir | --includedir | --includedi | --included | --include \ | --includ | --inclu | --incl | --inc) ac_prev=includedir ;; -includedir=* | --includedir=* | --includedi=* | --included=* | --include=* \ | --includ=* | --inclu=* | --incl=* | --inc=*) includedir=$ac_optarg ;; -infodir | --infodir | --infodi | --infod | --info | --inf) ac_prev=infodir ;; -infodir=* | --infodir=* | --infodi=* | --infod=* | --info=* | --inf=*) infodir=$ac_optarg ;; -libdir | --libdir | --libdi | --libd) ac_prev=libdir ;; -libdir=* | --libdir=* | --libdi=* | --libd=*) libdir=$ac_optarg ;; -libexecdir | --libexecdir | --libexecdi | --libexecd | --libexec \ | --libexe | --libex | --libe) ac_prev=libexecdir ;; -libexecdir=* | --libexecdir=* | --libexecdi=* | --libexecd=* | --libexec=* \ | --libexe=* | --libex=* | --libe=*) libexecdir=$ac_optarg ;; -localedir | --localedir | --localedi | --localed | --locale) ac_prev=localedir ;; -localedir=* | --localedir=* | --localedi=* | --localed=* | --locale=*) localedir=$ac_optarg ;; -localstatedir | --localstatedir | --localstatedi | --localstated \ | --localstate | --localstat | --localsta | --localst | --locals) ac_prev=localstatedir ;; -localstatedir=* | --localstatedir=* | --localstatedi=* | --localstated=* \ | --localstate=* | --localstat=* | --localsta=* | --localst=* | --locals=*) localstatedir=$ac_optarg ;; -mandir | --mandir | --mandi | --mand | --man | --ma | --m) ac_prev=mandir ;; -mandir=* | --mandir=* | --mandi=* | --mand=* | --man=* | --ma=* | --m=*) mandir=$ac_optarg ;; -nfp | --nfp | --nf) # Obsolete; use --without-fp. with_fp=no ;; -no-create | --no-create | --no-creat | --no-crea | --no-cre \ | --no-cr | --no-c | -n) no_create=yes ;; -no-recursion | --no-recursion | --no-recursio | --no-recursi \ | --no-recurs | --no-recur | --no-recu | --no-rec | --no-re | --no-r) no_recursion=yes ;; -oldincludedir | --oldincludedir | --oldincludedi | --oldincluded \ | --oldinclude | --oldinclud | --oldinclu | --oldincl | --oldinc \ | --oldin | --oldi | --old | --ol | --o) ac_prev=oldincludedir ;; -oldincludedir=* | --oldincludedir=* | --oldincludedi=* | --oldincluded=* \ | --oldinclude=* | --oldinclud=* | --oldinclu=* | --oldincl=* | --oldinc=* \ | --oldin=* | --oldi=* | --old=* | --ol=* | --o=*) oldincludedir=$ac_optarg ;; -prefix | --prefix | --prefi | --pref | --pre | --pr | --p) ac_prev=prefix ;; -prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=* | --pr=* | --p=*) prefix=$ac_optarg ;; -program-prefix | --program-prefix | --program-prefi | --program-pref \ | --program-pre | --program-pr | --program-p) ac_prev=program_prefix ;; -program-prefix=* | --program-prefix=* | --program-prefi=* \ | --program-pref=* | --program-pre=* | --program-pr=* | --program-p=*) program_prefix=$ac_optarg ;; -program-suffix | --program-suffix | --program-suffi | --program-suff \ | --program-suf | --program-su | --program-s) ac_prev=program_suffix ;; -program-suffix=* | --program-suffix=* | --program-suffi=* \ | --program-suff=* | --program-suf=* | --program-su=* | --program-s=*) program_suffix=$ac_optarg ;; -program-transform-name | --program-transform-name \ | --program-transform-nam | --program-transform-na \ | --program-transform-n | --program-transform- \ | --program-transform | --program-transfor \ | --program-transfo | --program-transf \ | --program-trans | --program-tran \ | --progr-tra | --program-tr | --program-t) ac_prev=program_transform_name ;; -program-transform-name=* | --program-transform-name=* \ | --program-transform-nam=* | --program-transform-na=* \ | --program-transform-n=* | --program-transform-=* \ | --program-transform=* | --program-transfor=* \ | --program-transfo=* | --program-transf=* \ | --program-trans=* | --program-tran=* \ | --progr-tra=* | --program-tr=* | --program-t=*) program_transform_name=$ac_optarg ;; -pdfdir | --pdfdir | --pdfdi | --pdfd | --pdf | --pd) ac_prev=pdfdir ;; -pdfdir=* | --pdfdir=* | --pdfdi=* | --pdfd=* | --pdf=* | --pd=*) pdfdir=$ac_optarg ;; -psdir | --psdir | --psdi | --psd | --ps) ac_prev=psdir ;; -psdir=* | --psdir=* | --psdi=* | --psd=* | --ps=*) psdir=$ac_optarg ;; -q | -quiet | --quiet | --quie | --qui | --qu | --q \ | -silent | --silent | --silen | --sile | --sil) silent=yes ;; -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb) ac_prev=sbindir ;; -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \ | --sbi=* | --sb=*) sbindir=$ac_optarg ;; -sharedstatedir | --sharedstatedir | --sharedstatedi \ | --sharedstated | --sharedstate | --sharedstat | --sharedsta \ | --sharedst | --shareds | --shared | --share | --shar \ | --sha | --sh) ac_prev=sharedstatedir ;; -sharedstatedir=* | --sharedstatedir=* | --sharedstatedi=* \ | --sharedstated=* | --sharedstate=* | --sharedstat=* | --sharedsta=* \ | --sharedst=* | --shareds=* | --shared=* | --share=* | --shar=* \ | --sha=* | --sh=*) sharedstatedir=$ac_optarg ;; -site | --site | --sit) ac_prev=site ;; -site=* | --site=* | --sit=*) site=$ac_optarg ;; -srcdir | --srcdir | --srcdi | --srcd | --src | --sr) ac_prev=srcdir ;; -srcdir=* | --srcdir=* | --srcdi=* | --srcd=* | --src=* | --sr=*) srcdir=$ac_optarg ;; -sysconfdir | --sysconfdir | --sysconfdi | --sysconfd | --sysconf \ | --syscon | --sysco | --sysc | --sys | --sy) ac_prev=sysconfdir ;; -sysconfdir=* | --sysconfdir=* | --sysconfdi=* | --sysconfd=* | --sysconf=* \ | --syscon=* | --sysco=* | --sysc=* | --sys=* | --sy=*) sysconfdir=$ac_optarg ;; -target | --target | --targe | --targ | --tar | --ta | --t) ac_prev=target_alias ;; -target=* | --target=* | --targe=* | --targ=* | --tar=* | --ta=* | --t=*) target_alias=$ac_optarg ;; -v | -verbose | --verbose | --verbos | --verbo | --verb) verbose=yes ;; -version | --version | --versio | --versi | --vers | -V) ac_init_version=: ;; -with-* | --with-*) ac_useropt=`expr "x$ac_option" : 'x-*with-\([^=]*\)'` # Reject names that are not valid shell variable names. expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && as_fn_error $? "invalid package name: $ac_useropt" ac_useropt_orig=$ac_useropt ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` case $ac_user_opts in *" "with_$ac_useropt" "*) ;; *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--with-$ac_useropt_orig" ac_unrecognized_sep=', ';; esac eval with_$ac_useropt=\$ac_optarg ;; -without-* | --without-*) ac_useropt=`expr "x$ac_option" : 'x-*without-\(.*\)'` # Reject names that are not valid shell variable names. expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && as_fn_error $? "invalid package name: $ac_useropt" ac_useropt_orig=$ac_useropt ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` case $ac_user_opts in *" "with_$ac_useropt" "*) ;; *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--without-$ac_useropt_orig" ac_unrecognized_sep=', ';; esac eval with_$ac_useropt=no ;; --x) # Obsolete; use --with-x. with_x=yes ;; -x-includes | --x-includes | --x-include | --x-includ | --x-inclu \ | --x-incl | --x-inc | --x-in | --x-i) ac_prev=x_includes ;; -x-includes=* | --x-includes=* | --x-include=* | --x-includ=* | --x-inclu=* \ | --x-incl=* | --x-inc=* | --x-in=* | --x-i=*) x_includes=$ac_optarg ;; -x-libraries | --x-libraries | --x-librarie | --x-librari \ | --x-librar | --x-libra | --x-libr | --x-lib | --x-li | --x-l) ac_prev=x_libraries ;; -x-libraries=* | --x-libraries=* | --x-librarie=* | --x-librari=* \ | --x-librar=* | --x-libra=* | --x-libr=* | --x-lib=* | --x-li=* | --x-l=*) x_libraries=$ac_optarg ;; -*) as_fn_error $? "unrecognized option: \`$ac_option' Try \`$0 --help' for more information" ;; *=*) ac_envvar=`expr "x$ac_option" : 'x\([^=]*\)='` # Reject names that are not valid shell variable names. case $ac_envvar in #( '' | [0-9]* | *[!_$as_cr_alnum]* ) as_fn_error $? "invalid variable name: \`$ac_envvar'" ;; esac eval $ac_envvar=\$ac_optarg export $ac_envvar ;; *) # FIXME: should be removed in autoconf 3.0. $as_echo "$as_me: WARNING: you should use --build, --host, --target" >&2 expr "x$ac_option" : ".*[^-._$as_cr_alnum]" >/dev/null && $as_echo "$as_me: WARNING: invalid host type: $ac_option" >&2 : "${build_alias=$ac_option} ${host_alias=$ac_option} ${target_alias=$ac_option}" ;; esac done if test -n "$ac_prev"; then ac_option=--`echo $ac_prev | sed 's/_/-/g'` as_fn_error $? "missing argument to $ac_option" fi if test -n "$ac_unrecognized_opts"; then case $enable_option_checking in no) ;; fatal) as_fn_error $? "unrecognized options: $ac_unrecognized_opts" ;; *) $as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2 ;; esac fi # Check all directory arguments for consistency. for ac_var in exec_prefix prefix bindir sbindir libexecdir datarootdir \ datadir sysconfdir sharedstatedir localstatedir includedir \ oldincludedir docdir infodir htmldir dvidir pdfdir psdir \ libdir localedir mandir do eval ac_val=\$$ac_var # Remove trailing slashes. case $ac_val in */ ) ac_val=`expr "X$ac_val" : 'X\(.*[^/]\)' \| "X$ac_val" : 'X\(.*\)'` eval $ac_var=\$ac_val;; esac # Be sure to have absolute directory names. case $ac_val in [\\/$]* | ?:[\\/]* ) continue;; NONE | '' ) case $ac_var in *prefix ) continue;; esac;; esac as_fn_error $? "expected an absolute directory name for --$ac_var: $ac_val" done # There might be people who depend on the old broken behavior: `$host' # used to hold the argument of --host etc. # FIXME: To remove some day. build=$build_alias host=$host_alias target=$target_alias # FIXME: To remove some day. if test "x$host_alias" != x; then if test "x$build_alias" = x; then cross_compiling=maybe elif test "x$build_alias" != "x$host_alias"; then cross_compiling=yes fi fi ac_tool_prefix= test -n "$host_alias" && ac_tool_prefix=$host_alias- test "$silent" = yes && exec 6>/dev/null ac_pwd=`pwd` && test -n "$ac_pwd" && ac_ls_di=`ls -di .` && ac_pwd_ls_di=`cd "$ac_pwd" && ls -di .` || as_fn_error $? "working directory cannot be determined" test "X$ac_ls_di" = "X$ac_pwd_ls_di" || as_fn_error $? "pwd does not report name of working directory" # Find the source files, if location was not specified. if test -z "$srcdir"; then ac_srcdir_defaulted=yes # Try the directory containing this script, then the parent directory. ac_confdir=`$as_dirname -- "$as_myself" || $as_expr X"$as_myself" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ X"$as_myself" : 'X\(//\)[^/]' \| \ X"$as_myself" : 'X\(//\)$' \| \ X"$as_myself" : 'X\(/\)' \| . 2>/dev/null || $as_echo X"$as_myself" | sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/ q } /^X\(\/\/\)[^/].*/{ s//\1/ q } /^X\(\/\/\)$/{ s//\1/ q } /^X\(\/\).*/{ s//\1/ q } s/.*/./; q'` srcdir=$ac_confdir if test ! -r "$srcdir/$ac_unique_file"; then srcdir=.. fi else ac_srcdir_defaulted=no fi if test ! -r "$srcdir/$ac_unique_file"; then test "$ac_srcdir_defaulted" = yes && srcdir="$ac_confdir or .." as_fn_error $? "cannot find sources ($ac_unique_file) in $srcdir" fi ac_msg="sources are in $srcdir, but \`cd $srcdir' does not work" ac_abs_confdir=`( cd "$srcdir" && test -r "./$ac_unique_file" || as_fn_error $? "$ac_msg" pwd)` # When building in place, set srcdir=. if test "$ac_abs_confdir" = "$ac_pwd"; then srcdir=. fi # Remove unnecessary trailing slashes from srcdir. # Double slashes in file names in object file debugging info # mess up M-x gdb in Emacs. case $srcdir in */) srcdir=`expr "X$srcdir" : 'X\(.*[^/]\)' \| "X$srcdir" : 'X\(.*\)'`;; esac for ac_var in $ac_precious_vars; do eval ac_env_${ac_var}_set=\${${ac_var}+set} eval ac_env_${ac_var}_value=\$${ac_var} eval ac_cv_env_${ac_var}_set=\${${ac_var}+set} eval ac_cv_env_${ac_var}_value=\$${ac_var} done # # Report the --help message. # if test "$ac_init_help" = "long"; then # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF \`configure' configures sftpserver 0.2.1 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... To assign environment variables (e.g., CC, CFLAGS...), specify them as VAR=VALUE. See below for descriptions of some of the useful variables. Defaults for the options are specified in brackets. Configuration: -h, --help display this help and exit --help=short display options specific to this package --help=recursive display the short help of all the included packages -V, --version display version information and exit -q, --quiet, --silent do not print \`checking ...' messages --cache-file=FILE cache test results in FILE [disabled] -C, --config-cache alias for \`--cache-file=config.cache' -n, --no-create do not create output files --srcdir=DIR find the sources in DIR [configure dir or \`..'] Installation directories: --prefix=PREFIX install architecture-independent files in PREFIX [$ac_default_prefix] --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX [PREFIX] By default, \`make install' will install all the files in \`$ac_default_prefix/bin', \`$ac_default_prefix/lib' etc. You can specify an installation prefix other than \`$ac_default_prefix' using \`--prefix', for instance \`--prefix=\$HOME'. For better control, use the options below. Fine tuning of the installation directories: --bindir=DIR user executables [EPREFIX/bin] --sbindir=DIR system admin executables [EPREFIX/sbin] --libexecdir=DIR program executables [EPREFIX/libexec] --sysconfdir=DIR read-only single-machine data [PREFIX/etc] --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com] --localstatedir=DIR modifiable single-machine data [PREFIX/var] --libdir=DIR object code libraries [EPREFIX/lib] --includedir=DIR C header files [PREFIX/include] --oldincludedir=DIR C header files for non-gcc [/usr/include] --datarootdir=DIR read-only arch.-independent data root [PREFIX/share] --datadir=DIR read-only architecture-independent data [DATAROOTDIR] --infodir=DIR info documentation [DATAROOTDIR/info] --localedir=DIR locale-dependent data [DATAROOTDIR/locale] --mandir=DIR man documentation [DATAROOTDIR/man] --docdir=DIR documentation root [DATAROOTDIR/doc/sftpserver] --htmldir=DIR html documentation [DOCDIR] --dvidir=DIR dvi documentation [DOCDIR] --pdfdir=DIR pdf documentation [DOCDIR] --psdir=DIR ps documentation [DOCDIR] _ACEOF cat <<\_ACEOF Program names: --program-prefix=PREFIX prepend PREFIX to installed program names --program-suffix=SUFFIX append SUFFIX to installed program names --program-transform-name=PROGRAM run sed PROGRAM on installed program names System types: --build=BUILD configure for building on BUILD [guessed] --host=HOST cross-compile to build programs to run on HOST [BUILD] _ACEOF fi if test -n "$ac_init_help"; then case $ac_init_help in short | recursive ) echo "Configuration of sftpserver 0.2.1:";; esac cat <<\_ACEOF Optional Features: --disable-option-checking ignore unrecognized --enable/--with options --disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no) --enable-FEATURE[=ARG] include FEATURE [ARG=yes] --disable-dependency-tracking speeds up one-time build --enable-dependency-tracking do not reject slow dependency extractors --disable-largefile omit support for large files --disable-warnings Disable compiler warnings --enable-warnings-as-errors Treat compiler warnings as errors --enable-reversed-symlink Reverse SSH_FXP_SYMLINK arguments --enable-daemon Turn on daemon mode support Optional Packages: --with-PACKAGE[=ARG] use PACKAGE [ARG=yes] --without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no) --with-gcov Enable coverage testing Some influential environment variables: CC C compiler command CFLAGS C compiler flags LDFLAGS linker flags, e.g. -L if you have libraries in a nonstandard directory LIBS libraries to pass to the linker, e.g. -l CPPFLAGS (Objective) C/C++ preprocessor flags, e.g. -I if you have headers in a nonstandard directory CPP C preprocessor Use these variables to override the choices made by `configure' or to help it to find libraries and programs with nonstandard names/locations. Report bugs to . _ACEOF ac_status=$? fi if test "$ac_init_help" = "recursive"; then # If there are subdirs, report their specific --help. for ac_dir in : $ac_subdirs_all; do test "x$ac_dir" = x: && continue test -d "$ac_dir" || { cd "$srcdir" && ac_pwd=`pwd` && srcdir=. && test -d "$ac_dir"; } || continue ac_builddir=. case "$ac_dir" in .) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;; *) ac_dir_suffix=/`$as_echo "$ac_dir" | sed 's|^\.[\\/]||'` # A ".." for each directory in $ac_dir_suffix. ac_top_builddir_sub=`$as_echo "$ac_dir_suffix" | sed 's|/[^\\/]*|/..|g;s|/||'` case $ac_top_builddir_sub in "") ac_top_builddir_sub=. ac_top_build_prefix= ;; *) ac_top_build_prefix=$ac_top_builddir_sub/ ;; esac ;; esac ac_abs_top_builddir=$ac_pwd ac_abs_builddir=$ac_pwd$ac_dir_suffix # for backward compatibility: ac_top_builddir=$ac_top_build_prefix case $srcdir in .) # We are building in place. ac_srcdir=. ac_top_srcdir=$ac_top_builddir_sub ac_abs_top_srcdir=$ac_pwd ;; [\\/]* | ?:[\\/]* ) # Absolute name. ac_srcdir=$srcdir$ac_dir_suffix; ac_top_srcdir=$srcdir ac_abs_top_srcdir=$srcdir ;; *) # Relative name. ac_srcdir=$ac_top_build_prefix$srcdir$ac_dir_suffix ac_top_srcdir=$ac_top_build_prefix$srcdir ac_abs_top_srcdir=$ac_pwd/$srcdir ;; esac ac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix cd "$ac_dir" || { ac_status=$?; continue; } # Check for guested configure. if test -f "$ac_srcdir/configure.gnu"; then echo && $SHELL "$ac_srcdir/configure.gnu" --help=recursive elif test -f "$ac_srcdir/configure"; then echo && $SHELL "$ac_srcdir/configure" --help=recursive else $as_echo "$as_me: WARNING: no configuration information is in $ac_dir" >&2 fi || ac_status=$? cd "$ac_pwd" || { ac_status=$?; break; } done fi test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF sftpserver configure 0.2.1 generated by GNU Autoconf 2.69 Copyright (C) 2012 Free Software Foundation, Inc. This configure script is free software; the Free Software Foundation gives unlimited permission to copy, distribute and modify it. _ACEOF exit fi ## ------------------------ ## ## Autoconf initialization. ## ## ------------------------ ## # ac_fn_c_try_compile LINENO # -------------------------- # Try to compile conftest.$ac_ext, and return whether this succeeded. ac_fn_c_try_compile () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack rm -f conftest.$ac_objext if { { ac_try="$ac_compile" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_compile") 2>conftest.err ac_status=$? if test -s conftest.err; then grep -v '^ *+' conftest.err >conftest.er1 cat conftest.er1 >&5 mv -f conftest.er1 conftest.err fi $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } && { test -z "$ac_c_werror_flag" || test ! -s conftest.err } && test -s conftest.$ac_objext; then : ac_retval=0 else $as_echo "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 ac_retval=1 fi eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno as_fn_set_status $ac_retval } # ac_fn_c_try_compile # ac_fn_c_try_link LINENO # ----------------------- # Try to link conftest.$ac_ext, and return whether this succeeded. ac_fn_c_try_link () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack rm -f conftest.$ac_objext conftest$ac_exeext if { { ac_try="$ac_link" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_link") 2>conftest.err ac_status=$? if test -s conftest.err; then grep -v '^ *+' conftest.err >conftest.er1 cat conftest.er1 >&5 mv -f conftest.er1 conftest.err fi $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } && { test -z "$ac_c_werror_flag" || test ! -s conftest.err } && test -s conftest$ac_exeext && { test "$cross_compiling" = yes || test -x conftest$ac_exeext }; then : ac_retval=0 else $as_echo "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 ac_retval=1 fi # Delete the IPA/IPO (Inter Procedural Analysis/Optimization) information # created by the PGI compiler (conftest_ipa8_conftest.oo), as it would # interfere with the next link command; also delete a directory that is # left behind by Apple's compiler. We do this before executing the actions. rm -rf conftest.dSYM conftest_ipa8_conftest.oo eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno as_fn_set_status $ac_retval } # ac_fn_c_try_link # ac_fn_c_try_cpp LINENO # ---------------------- # Try to preprocess conftest.$ac_ext, and return whether this succeeded. ac_fn_c_try_cpp () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack if { { ac_try="$ac_cpp conftest.$ac_ext" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_cpp conftest.$ac_ext") 2>conftest.err ac_status=$? if test -s conftest.err; then grep -v '^ *+' conftest.err >conftest.er1 cat conftest.er1 >&5 mv -f conftest.er1 conftest.err fi $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } > conftest.i && { test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" || test ! -s conftest.err }; then : ac_retval=0 else $as_echo "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 ac_retval=1 fi eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno as_fn_set_status $ac_retval } # ac_fn_c_try_cpp # ac_fn_c_check_header_mongrel LINENO HEADER VAR INCLUDES # ------------------------------------------------------- # Tests whether HEADER exists, giving a warning if it cannot be compiled using # the include files in INCLUDES and setting the cache variable VAR # accordingly. ac_fn_c_check_header_mongrel () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack if eval \${$3+:} false; then : { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 $as_echo_n "checking for $2... " >&6; } if eval \${$3+:} false; then : $as_echo_n "(cached) " >&6 fi eval ac_res=\$$3 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 $as_echo "$ac_res" >&6; } else # Is the header compilable? { $as_echo "$as_me:${as_lineno-$LINENO}: checking $2 usability" >&5 $as_echo_n "checking $2 usability... " >&6; } cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $4 #include <$2> _ACEOF if ac_fn_c_try_compile "$LINENO"; then : ac_header_compiler=yes else ac_header_compiler=no fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_header_compiler" >&5 $as_echo "$ac_header_compiler" >&6; } # Is the header present? { $as_echo "$as_me:${as_lineno-$LINENO}: checking $2 presence" >&5 $as_echo_n "checking $2 presence... " >&6; } cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include <$2> _ACEOF if ac_fn_c_try_cpp "$LINENO"; then : ac_header_preproc=yes else ac_header_preproc=no fi rm -f conftest.err conftest.i conftest.$ac_ext { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_header_preproc" >&5 $as_echo "$ac_header_preproc" >&6; } # So? What about this header? case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in #(( yes:no: ) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: accepted by the compiler, rejected by the preprocessor!" >&5 $as_echo "$as_me: WARNING: $2: accepted by the compiler, rejected by the preprocessor!" >&2;} { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: proceeding with the compiler's result" >&5 $as_echo "$as_me: WARNING: $2: proceeding with the compiler's result" >&2;} ;; no:yes:* ) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: present but cannot be compiled" >&5 $as_echo "$as_me: WARNING: $2: present but cannot be compiled" >&2;} { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: check for missing prerequisite headers?" >&5 $as_echo "$as_me: WARNING: $2: check for missing prerequisite headers?" >&2;} { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: see the Autoconf documentation" >&5 $as_echo "$as_me: WARNING: $2: see the Autoconf documentation" >&2;} { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: section \"Present But Cannot Be Compiled\"" >&5 $as_echo "$as_me: WARNING: $2: section \"Present But Cannot Be Compiled\"" >&2;} { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: proceeding with the compiler's result" >&5 $as_echo "$as_me: WARNING: $2: proceeding with the compiler's result" >&2;} ( $as_echo "## ------------------------------------------------------- ## ## Report this to richard+sftpserver@sfere.greenend.org.uk ## ## ------------------------------------------------------- ##" ) | sed "s/^/$as_me: WARNING: /" >&2 ;; esac { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 $as_echo_n "checking for $2... " >&6; } if eval \${$3+:} false; then : $as_echo_n "(cached) " >&6 else eval "$3=\$ac_header_compiler" fi eval ac_res=\$$3 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 $as_echo "$ac_res" >&6; } fi eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno } # ac_fn_c_check_header_mongrel # ac_fn_c_try_run LINENO # ---------------------- # Try to link conftest.$ac_ext, and return whether this succeeded. Assumes # that executables *can* be run. ac_fn_c_try_run () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack if { { ac_try="$ac_link" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_link") 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } && { ac_try='./conftest$ac_exeext' { { case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_try") 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; }; then : ac_retval=0 else $as_echo "$as_me: program exited with status $ac_status" >&5 $as_echo "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 ac_retval=$ac_status fi rm -rf conftest.dSYM conftest_ipa8_conftest.oo eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno as_fn_set_status $ac_retval } # ac_fn_c_try_run # ac_fn_c_check_header_compile LINENO HEADER VAR INCLUDES # ------------------------------------------------------- # Tests whether HEADER exists and can be compiled using the include files in # INCLUDES, setting the cache variable VAR accordingly. ac_fn_c_check_header_compile () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 $as_echo_n "checking for $2... " >&6; } if eval \${$3+:} false; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $4 #include <$2> _ACEOF if ac_fn_c_try_compile "$LINENO"; then : eval "$3=yes" else eval "$3=no" fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi eval ac_res=\$$3 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 $as_echo "$ac_res" >&6; } eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno } # ac_fn_c_check_header_compile # ac_fn_c_check_func LINENO FUNC VAR # ---------------------------------- # Tests whether FUNC exists, setting the cache variable VAR accordingly ac_fn_c_check_func () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 $as_echo_n "checking for $2... " >&6; } if eval \${$3+:} false; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ /* Define $2 to an innocuous variant, in case declares $2. For example, HP-UX 11i declares gettimeofday. */ #define $2 innocuous_$2 /* System header to define __stub macros and hopefully few prototypes, which can conflict with char $2 (); below. Prefer to if __STDC__ is defined, since exists even on freestanding compilers. */ #ifdef __STDC__ # include #else # include #endif #undef $2 /* Override any GCC internal prototype to avoid an error. Use char because int might match the return type of a GCC builtin and then its argument prototype would still apply. */ #ifdef __cplusplus extern "C" #endif char $2 (); /* The GNU C library defines this for functions which it implements to always fail with ENOSYS. Some functions are actually named something starting with __ and the normal name is an alias. */ #if defined __stub_$2 || defined __stub___$2 choke me #endif int main () { return $2 (); ; return 0; } _ACEOF if ac_fn_c_try_link "$LINENO"; then : eval "$3=yes" else eval "$3=no" fi rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext fi eval ac_res=\$$3 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 $as_echo "$ac_res" >&6; } eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno } # ac_fn_c_check_func # ac_fn_c_check_decl LINENO SYMBOL VAR INCLUDES # --------------------------------------------- # Tests whether SYMBOL is declared in INCLUDES, setting cache variable VAR # accordingly. ac_fn_c_check_decl () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack as_decl_name=`echo $2|sed 's/ *(.*//'` as_decl_use=`echo $2|sed -e 's/(/((/' -e 's/)/) 0&/' -e 's/,/) 0& (/g'` { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $as_decl_name is declared" >&5 $as_echo_n "checking whether $as_decl_name is declared... " >&6; } if eval \${$3+:} false; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $4 int main () { #ifndef $as_decl_name #ifdef __cplusplus (void) $as_decl_use; #else (void) $as_decl_name; #endif #endif ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : eval "$3=yes" else eval "$3=no" fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi eval ac_res=\$$3 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 $as_echo "$ac_res" >&6; } eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno } # ac_fn_c_check_decl # ac_fn_c_compute_int LINENO EXPR VAR INCLUDES # -------------------------------------------- # Tries to find the compile-time value of EXPR in a program that includes # INCLUDES, setting VAR accordingly. Returns whether the value could be # computed ac_fn_c_compute_int () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack if test "$cross_compiling" = yes; then # Depending upon the size, compute the lo and hi bounds. cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $4 int main () { static int test_array [1 - 2 * !(($2) >= 0)]; test_array [0] = 0; return test_array [0]; ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : ac_lo=0 ac_mid=0 while :; do cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $4 int main () { static int test_array [1 - 2 * !(($2) <= $ac_mid)]; test_array [0] = 0; return test_array [0]; ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : ac_hi=$ac_mid; break else as_fn_arith $ac_mid + 1 && ac_lo=$as_val if test $ac_lo -le $ac_mid; then ac_lo= ac_hi= break fi as_fn_arith 2 '*' $ac_mid + 1 && ac_mid=$as_val fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext done else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $4 int main () { static int test_array [1 - 2 * !(($2) < 0)]; test_array [0] = 0; return test_array [0]; ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : ac_hi=-1 ac_mid=-1 while :; do cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $4 int main () { static int test_array [1 - 2 * !(($2) >= $ac_mid)]; test_array [0] = 0; return test_array [0]; ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : ac_lo=$ac_mid; break else as_fn_arith '(' $ac_mid ')' - 1 && ac_hi=$as_val if test $ac_mid -le $ac_hi; then ac_lo= ac_hi= break fi as_fn_arith 2 '*' $ac_mid && ac_mid=$as_val fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext done else ac_lo= ac_hi= fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext # Binary search between lo and hi bounds. while test "x$ac_lo" != "x$ac_hi"; do as_fn_arith '(' $ac_hi - $ac_lo ')' / 2 + $ac_lo && ac_mid=$as_val cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $4 int main () { static int test_array [1 - 2 * !(($2) <= $ac_mid)]; test_array [0] = 0; return test_array [0]; ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : ac_hi=$ac_mid else as_fn_arith '(' $ac_mid ')' + 1 && ac_lo=$as_val fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext done case $ac_lo in #(( ?*) eval "$3=\$ac_lo"; ac_retval=0 ;; '') ac_retval=1 ;; esac else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $4 static long int longval () { return $2; } static unsigned long int ulongval () { return $2; } #include #include int main () { FILE *f = fopen ("conftest.val", "w"); if (! f) return 1; if (($2) < 0) { long int i = longval (); if (i != ($2)) return 1; fprintf (f, "%ld", i); } else { unsigned long int i = ulongval (); if (i != ($2)) return 1; fprintf (f, "%lu", i); } /* Do not output a trailing newline, as this causes \r\n confusion on some platforms. */ return ferror (f) || fclose (f) != 0; ; return 0; } _ACEOF if ac_fn_c_try_run "$LINENO"; then : echo >>conftest.val; read $3 &5 $as_echo_n "checking for $2.$3... " >&6; } if eval \${$4+:} false; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $5 int main () { static $2 ac_aggr; if (ac_aggr.$3) return 0; ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : eval "$4=yes" else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $5 int main () { static $2 ac_aggr; if (sizeof ac_aggr.$3) return 0; ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : eval "$4=yes" else eval "$4=no" fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi eval ac_res=\$$4 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 $as_echo "$ac_res" >&6; } eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno } # ac_fn_c_check_member cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. It was created by sftpserver $as_me 0.2.1, which was generated by GNU Autoconf 2.69. Invocation command line was $ $0 $@ _ACEOF exec 5>>config.log { cat <<_ASUNAME ## --------- ## ## Platform. ## ## --------- ## hostname = `(hostname || uname -n) 2>/dev/null | sed 1q` uname -m = `(uname -m) 2>/dev/null || echo unknown` uname -r = `(uname -r) 2>/dev/null || echo unknown` uname -s = `(uname -s) 2>/dev/null || echo unknown` uname -v = `(uname -v) 2>/dev/null || echo unknown` /usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null || echo unknown` /bin/uname -X = `(/bin/uname -X) 2>/dev/null || echo unknown` /bin/arch = `(/bin/arch) 2>/dev/null || echo unknown` /usr/bin/arch -k = `(/usr/bin/arch -k) 2>/dev/null || echo unknown` /usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null || echo unknown` /usr/bin/hostinfo = `(/usr/bin/hostinfo) 2>/dev/null || echo unknown` /bin/machine = `(/bin/machine) 2>/dev/null || echo unknown` /usr/bin/oslevel = `(/usr/bin/oslevel) 2>/dev/null || echo unknown` /bin/universe = `(/bin/universe) 2>/dev/null || echo unknown` _ASUNAME as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. $as_echo "PATH: $as_dir" done IFS=$as_save_IFS } >&5 cat >&5 <<_ACEOF ## ----------- ## ## Core tests. ## ## ----------- ## _ACEOF # Keep a trace of the command line. # Strip out --no-create and --no-recursion so they do not pile up. # Strip out --silent because we don't want to record it for future runs. # Also quote any args containing shell meta-characters. # Make two passes to allow for proper duplicate-argument suppression. ac_configure_args= ac_configure_args0= ac_configure_args1= ac_must_keep_next=false for ac_pass in 1 2 do for ac_arg do case $ac_arg in -no-create | --no-c* | -n | -no-recursion | --no-r*) continue ;; -q | -quiet | --quiet | --quie | --qui | --qu | --q \ | -silent | --silent | --silen | --sile | --sil) continue ;; *\'*) ac_arg=`$as_echo "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` ;; esac case $ac_pass in 1) as_fn_append ac_configure_args0 " '$ac_arg'" ;; 2) as_fn_append ac_configure_args1 " '$ac_arg'" if test $ac_must_keep_next = true; then ac_must_keep_next=false # Got value, back to normal. else case $ac_arg in *=* | --config-cache | -C | -disable-* | --disable-* \ | -enable-* | --enable-* | -gas | --g* | -nfp | --nf* \ | -q | -quiet | --q* | -silent | --sil* | -v | -verb* \ | -with-* | --with-* | -without-* | --without-* | --x) case "$ac_configure_args0 " in "$ac_configure_args1"*" '$ac_arg' "* ) continue ;; esac ;; -* ) ac_must_keep_next=true ;; esac fi as_fn_append ac_configure_args " '$ac_arg'" ;; esac done done { ac_configure_args0=; unset ac_configure_args0;} { ac_configure_args1=; unset ac_configure_args1;} # When interrupted or exit'd, cleanup temporary files, and complete # config.log. We remove comments because anyway the quotes in there # would cause problems or look ugly. # WARNING: Use '\'' to represent an apostrophe within the trap. # WARNING: Do not start the trap code with a newline, due to a FreeBSD 4.0 bug. trap 'exit_status=$? # Save into config.log some information that might help in debugging. { echo $as_echo "## ---------------- ## ## Cache variables. ## ## ---------------- ##" echo # The following way of writing the cache mishandles newlines in values, ( for ac_var in `(set) 2>&1 | sed -n '\''s/^\([a-zA-Z_][a-zA-Z0-9_]*\)=.*/\1/p'\''`; do eval ac_val=\$$ac_var case $ac_val in #( *${as_nl}*) case $ac_var in #( *_cv_*) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline" >&5 $as_echo "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;; esac case $ac_var in #( _ | IFS | as_nl) ;; #( BASH_ARGV | BASH_SOURCE) eval $ac_var= ;; #( *) { eval $ac_var=; unset $ac_var;} ;; esac ;; esac done (set) 2>&1 | case $as_nl`(ac_space='\'' '\''; set) 2>&1` in #( *${as_nl}ac_space=\ *) sed -n \ "s/'\''/'\''\\\\'\'''\''/g; s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\''\\2'\''/p" ;; #( *) sed -n "/^[_$as_cr_alnum]*_cv_[_$as_cr_alnum]*=/p" ;; esac | sort ) echo $as_echo "## ----------------- ## ## Output variables. ## ## ----------------- ##" echo for ac_var in $ac_subst_vars do eval ac_val=\$$ac_var case $ac_val in *\'\''*) ac_val=`$as_echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;; esac $as_echo "$ac_var='\''$ac_val'\''" done | sort echo if test -n "$ac_subst_files"; then $as_echo "## ------------------- ## ## File substitutions. ## ## ------------------- ##" echo for ac_var in $ac_subst_files do eval ac_val=\$$ac_var case $ac_val in *\'\''*) ac_val=`$as_echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;; esac $as_echo "$ac_var='\''$ac_val'\''" done | sort echo fi if test -s confdefs.h; then $as_echo "## ----------- ## ## confdefs.h. ## ## ----------- ##" echo cat confdefs.h echo fi test "$ac_signal" != 0 && $as_echo "$as_me: caught signal $ac_signal" $as_echo "$as_me: exit $exit_status" } >&5 rm -f core *.core core.conftest.* && rm -f -r conftest* confdefs* conf$$* $ac_clean_files && exit $exit_status ' 0 for ac_signal in 1 2 13 15; do trap 'ac_signal='$ac_signal'; as_fn_exit 1' $ac_signal done ac_signal=0 # confdefs.h avoids OS command line length limits that DEFS can exceed. rm -f -r conftest* confdefs.h $as_echo "/* confdefs.h */" > confdefs.h # Predefined preprocessor variables. cat >>confdefs.h <<_ACEOF #define PACKAGE_NAME "$PACKAGE_NAME" _ACEOF cat >>confdefs.h <<_ACEOF #define PACKAGE_TARNAME "$PACKAGE_TARNAME" _ACEOF cat >>confdefs.h <<_ACEOF #define PACKAGE_VERSION "$PACKAGE_VERSION" _ACEOF cat >>confdefs.h <<_ACEOF #define PACKAGE_STRING "$PACKAGE_STRING" _ACEOF cat >>confdefs.h <<_ACEOF #define PACKAGE_BUGREPORT "$PACKAGE_BUGREPORT" _ACEOF cat >>confdefs.h <<_ACEOF #define PACKAGE_URL "$PACKAGE_URL" _ACEOF # Let the site file select an alternate cache file if it wants to. # Prefer an explicitly selected file to automatically selected ones. ac_site_file1=NONE ac_site_file2=NONE if test -n "$CONFIG_SITE"; then # We do not want a PATH search for config.site. case $CONFIG_SITE in #(( -*) ac_site_file1=./$CONFIG_SITE;; */*) ac_site_file1=$CONFIG_SITE;; *) ac_site_file1=./$CONFIG_SITE;; esac elif test "x$prefix" != xNONE; then ac_site_file1=$prefix/share/config.site ac_site_file2=$prefix/etc/config.site else ac_site_file1=$ac_default_prefix/share/config.site ac_site_file2=$ac_default_prefix/etc/config.site fi for ac_site_file in "$ac_site_file1" "$ac_site_file2" do test "x$ac_site_file" = xNONE && continue if test /dev/null != "$ac_site_file" && test -r "$ac_site_file"; then { $as_echo "$as_me:${as_lineno-$LINENO}: loading site script $ac_site_file" >&5 $as_echo "$as_me: loading site script $ac_site_file" >&6;} sed 's/^/| /' "$ac_site_file" >&5 . "$ac_site_file" \ || { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "failed to load site script $ac_site_file See \`config.log' for more details" "$LINENO" 5; } fi done if test -r "$cache_file"; then # Some versions of bash will fail to source /dev/null (special files # actually), so we avoid doing that. DJGPP emulates it as a regular file. if test /dev/null != "$cache_file" && test -f "$cache_file"; then { $as_echo "$as_me:${as_lineno-$LINENO}: loading cache $cache_file" >&5 $as_echo "$as_me: loading cache $cache_file" >&6;} case $cache_file in [\\/]* | ?:[\\/]* ) . "$cache_file";; *) . "./$cache_file";; esac fi else { $as_echo "$as_me:${as_lineno-$LINENO}: creating cache $cache_file" >&5 $as_echo "$as_me: creating cache $cache_file" >&6;} >$cache_file fi # Check that the precious variables saved in the cache have kept the same # value. ac_cache_corrupted=false for ac_var in $ac_precious_vars; do eval ac_old_set=\$ac_cv_env_${ac_var}_set eval ac_new_set=\$ac_env_${ac_var}_set eval ac_old_val=\$ac_cv_env_${ac_var}_value eval ac_new_val=\$ac_env_${ac_var}_value case $ac_old_set,$ac_new_set in set,) { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&5 $as_echo "$as_me: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&2;} ac_cache_corrupted=: ;; ,set) { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' was not set in the previous run" >&5 $as_echo "$as_me: error: \`$ac_var' was not set in the previous run" >&2;} ac_cache_corrupted=: ;; ,);; *) if test "x$ac_old_val" != "x$ac_new_val"; then # differences in whitespace do not lead to failure. ac_old_val_w=`echo x $ac_old_val` ac_new_val_w=`echo x $ac_new_val` if test "$ac_old_val_w" != "$ac_new_val_w"; then { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' has changed since the previous run:" >&5 $as_echo "$as_me: error: \`$ac_var' has changed since the previous run:" >&2;} ac_cache_corrupted=: else { $as_echo "$as_me:${as_lineno-$LINENO}: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&5 $as_echo "$as_me: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&2;} eval $ac_var=\$ac_old_val fi { $as_echo "$as_me:${as_lineno-$LINENO}: former value: \`$ac_old_val'" >&5 $as_echo "$as_me: former value: \`$ac_old_val'" >&2;} { $as_echo "$as_me:${as_lineno-$LINENO}: current value: \`$ac_new_val'" >&5 $as_echo "$as_me: current value: \`$ac_new_val'" >&2;} fi;; esac # Pass precious variables to config.status. if test "$ac_new_set" = set; then case $ac_new_val in *\'*) ac_arg=$ac_var=`$as_echo "$ac_new_val" | sed "s/'/'\\\\\\\\''/g"` ;; *) ac_arg=$ac_var=$ac_new_val ;; esac case " $ac_configure_args " in *" '$ac_arg' "*) ;; # Avoid dups. Use of quotes ensures accuracy. *) as_fn_append ac_configure_args " '$ac_arg'" ;; esac fi done if $ac_cache_corrupted; then { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} { $as_echo "$as_me:${as_lineno-$LINENO}: error: changes in the environment can compromise the build" >&5 $as_echo "$as_me: error: changes in the environment can compromise the build" >&2;} as_fn_error $? "run \`make distclean' and/or \`rm $cache_file' and start over" "$LINENO" 5 fi ## -------------------- ## ## Main body of script. ## ## -------------------- ## ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_c_compiler_gnu ac_aux_dir= for ac_dir in config.aux "$srcdir"/config.aux; do if test -f "$ac_dir/install-sh"; then ac_aux_dir=$ac_dir ac_install_sh="$ac_aux_dir/install-sh -c" break elif test -f "$ac_dir/install.sh"; then ac_aux_dir=$ac_dir ac_install_sh="$ac_aux_dir/install.sh -c" break elif test -f "$ac_dir/shtool"; then ac_aux_dir=$ac_dir ac_install_sh="$ac_aux_dir/shtool install -c" break fi done if test -z "$ac_aux_dir"; then as_fn_error $? "cannot find install-sh, install.sh, or shtool in config.aux \"$srcdir\"/config.aux" "$LINENO" 5 fi # These three variables are undocumented and unsupported, # and are intended to be withdrawn in a future Autoconf release. # They can cause serious problems if a builder's source tree is in a directory # whose full name contains unusual characters. ac_config_guess="$SHELL $ac_aux_dir/config.guess" # Please don't use this var. ac_config_sub="$SHELL $ac_aux_dir/config.sub" # Please don't use this var. ac_configure="$SHELL $ac_aux_dir/configure" # Please don't use this var. am__api_version='1.11' # Find a good install program. We prefer a C program (faster), # so one script is as good as another. But avoid the broken or # incompatible versions: # SysV /etc/install, /usr/sbin/install # SunOS /usr/etc/install # IRIX /sbin/install # AIX /bin/install # AmigaOS /C/install, which installs bootblocks on floppy discs # AIX 4 /usr/bin/installbsd, which doesn't work without a -g flag # AFS /usr/afsws/bin/install, which mishandles nonexistent args # SVR4 /usr/ucb/install, which tries to use the nonexistent group "staff" # OS/2's system install, which has a completely different semantic # ./install, which can be erroneously created by make from ./install.sh. # Reject install programs that cannot install multiple files. { $as_echo "$as_me:${as_lineno-$LINENO}: checking for a BSD-compatible install" >&5 $as_echo_n "checking for a BSD-compatible install... " >&6; } if test -z "$INSTALL"; then if ${ac_cv_path_install+:} false; then : $as_echo_n "(cached) " >&6 else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. # Account for people who put trailing slashes in PATH elements. case $as_dir/ in #(( ./ | .// | /[cC]/* | \ /etc/* | /usr/sbin/* | /usr/etc/* | /sbin/* | /usr/afsws/bin/* | \ ?:[\\/]os2[\\/]install[\\/]* | ?:[\\/]OS2[\\/]INSTALL[\\/]* | \ /usr/ucb/* ) ;; *) # OSF1 and SCO ODT 3.0 have their own names for install. # Don't use installbsd from OSF since it installs stuff as root # by default. for ac_prog in ginstall scoinst install; do for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir/$ac_prog$ac_exec_ext"; then if test $ac_prog = install && grep dspmsg "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then # AIX install. It has an incompatible calling convention. : elif test $ac_prog = install && grep pwplus "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then # program-specific install script used by HP pwplus--don't use. : else rm -rf conftest.one conftest.two conftest.dir echo one > conftest.one echo two > conftest.two mkdir conftest.dir if "$as_dir/$ac_prog$ac_exec_ext" -c conftest.one conftest.two "`pwd`/conftest.dir" && test -s conftest.one && test -s conftest.two && test -s conftest.dir/conftest.one && test -s conftest.dir/conftest.two then ac_cv_path_install="$as_dir/$ac_prog$ac_exec_ext -c" break 3 fi fi fi done done ;; esac done IFS=$as_save_IFS rm -rf conftest.one conftest.two conftest.dir fi if test "${ac_cv_path_install+set}" = set; then INSTALL=$ac_cv_path_install else # As a last resort, use the slow shell script. Don't cache a # value for INSTALL within a source directory, because that will # break other packages using the cache if that directory is # removed, or if the value is a relative name. INSTALL=$ac_install_sh fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $INSTALL" >&5 $as_echo "$INSTALL" >&6; } # Use test -z because SunOS4 sh mishandles braces in ${var-val}. # It thinks the first close brace ends the variable substitution. test -z "$INSTALL_PROGRAM" && INSTALL_PROGRAM='${INSTALL}' test -z "$INSTALL_SCRIPT" && INSTALL_SCRIPT='${INSTALL}' test -z "$INSTALL_DATA" && INSTALL_DATA='${INSTALL} -m 644' { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether build environment is sane" >&5 $as_echo_n "checking whether build environment is sane... " >&6; } # Just in case sleep 1 echo timestamp > conftest.file # Reject unsafe characters in $srcdir or the absolute working directory # name. Accept space and tab only in the latter. am_lf=' ' case `pwd` in *[\\\"\#\$\&\'\`$am_lf]*) as_fn_error $? "unsafe absolute working directory name" "$LINENO" 5;; esac case $srcdir in *[\\\"\#\$\&\'\`$am_lf\ \ ]*) as_fn_error $? "unsafe srcdir value: \`$srcdir'" "$LINENO" 5;; esac # Do `set' in a subshell so we don't clobber the current shell's # arguments. Must try -L first in case configure is actually a # symlink; some systems play weird games with the mod time of symlinks # (eg FreeBSD returns the mod time of the symlink's containing # directory). if ( set X `ls -Lt "$srcdir/configure" conftest.file 2> /dev/null` if test "$*" = "X"; then # -L didn't work. set X `ls -t "$srcdir/configure" conftest.file` fi rm -f conftest.file if test "$*" != "X $srcdir/configure conftest.file" \ && test "$*" != "X conftest.file $srcdir/configure"; then # If neither matched, then we have a broken ls. This can happen # if, for instance, CONFIG_SHELL is bash and it inherits a # broken ls alias from the environment. This has actually # happened. Such a system could not be considered "sane". as_fn_error $? "ls -t appears to fail. Make sure there is not a broken alias in your environment" "$LINENO" 5 fi test "$2" = conftest.file ) then # Ok. : else as_fn_error $? "newly created file is older than distributed files! Check your system clock" "$LINENO" 5 fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 $as_echo "yes" >&6; } test "$program_prefix" != NONE && program_transform_name="s&^&$program_prefix&;$program_transform_name" # Use a double $ so make ignores it. test "$program_suffix" != NONE && program_transform_name="s&\$&$program_suffix&;$program_transform_name" # Double any \ or $. # By default was `s,x,x', remove it if useless. ac_script='s/[\\$]/&&/g;s/;s,x,x,$//' program_transform_name=`$as_echo "$program_transform_name" | sed "$ac_script"` # expand $ac_aux_dir to an absolute path am_aux_dir=`cd $ac_aux_dir && pwd` if test x"${MISSING+set}" != xset; then case $am_aux_dir in *\ * | *\ *) MISSING="\${SHELL} \"$am_aux_dir/missing\"" ;; *) MISSING="\${SHELL} $am_aux_dir/missing" ;; esac fi # Use eval to expand $SHELL if eval "$MISSING --run true"; then am_missing_run="$MISSING --run " else am_missing_run= { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: \`missing' script is too old or missing" >&5 $as_echo "$as_me: WARNING: \`missing' script is too old or missing" >&2;} fi if test x"${install_sh}" != xset; then case $am_aux_dir in *\ * | *\ *) install_sh="\${SHELL} '$am_aux_dir/install-sh'" ;; *) install_sh="\${SHELL} $am_aux_dir/install-sh" esac fi # Installed binaries are usually stripped using `strip' when the user # run `make install-strip'. However `strip' might not be the right # tool to use in cross-compilation environments, therefore Automake # will honor the `STRIP' environment variable to overrule this program. if test "$cross_compiling" != no; then if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}strip", so it can be a program name with args. set dummy ${ac_tool_prefix}strip; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_prog_STRIP+:} false; then : $as_echo_n "(cached) " >&6 else if test -n "$STRIP"; then ac_cv_prog_STRIP="$STRIP" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_STRIP="${ac_tool_prefix}strip" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi STRIP=$ac_cv_prog_STRIP if test -n "$STRIP"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $STRIP" >&5 $as_echo "$STRIP" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi fi if test -z "$ac_cv_prog_STRIP"; then ac_ct_STRIP=$STRIP # Extract the first word of "strip", so it can be a program name with args. set dummy strip; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_prog_ac_ct_STRIP+:} false; then : $as_echo_n "(cached) " >&6 else if test -n "$ac_ct_STRIP"; then ac_cv_prog_ac_ct_STRIP="$ac_ct_STRIP" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_ac_ct_STRIP="strip" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi ac_ct_STRIP=$ac_cv_prog_ac_ct_STRIP if test -n "$ac_ct_STRIP"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_STRIP" >&5 $as_echo "$ac_ct_STRIP" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi if test "x$ac_ct_STRIP" = x; then STRIP=":" else case $cross_compiling:$ac_tool_warned in yes:) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 $as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac STRIP=$ac_ct_STRIP fi else STRIP="$ac_cv_prog_STRIP" fi fi INSTALL_STRIP_PROGRAM="\$(install_sh) -c -s" { $as_echo "$as_me:${as_lineno-$LINENO}: checking for a thread-safe mkdir -p" >&5 $as_echo_n "checking for a thread-safe mkdir -p... " >&6; } if test -z "$MKDIR_P"; then if ${ac_cv_path_mkdir+:} false; then : $as_echo_n "(cached) " >&6 else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH$PATH_SEPARATOR/opt/sfw/bin do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_prog in mkdir gmkdir; do for ac_exec_ext in '' $ac_executable_extensions; do as_fn_executable_p "$as_dir/$ac_prog$ac_exec_ext" || continue case `"$as_dir/$ac_prog$ac_exec_ext" --version 2>&1` in #( 'mkdir (GNU coreutils) '* | \ 'mkdir (coreutils) '* | \ 'mkdir (fileutils) '4.1*) ac_cv_path_mkdir=$as_dir/$ac_prog$ac_exec_ext break 3;; esac done done done IFS=$as_save_IFS fi test -d ./--version && rmdir ./--version if test "${ac_cv_path_mkdir+set}" = set; then MKDIR_P="$ac_cv_path_mkdir -p" else # As a last resort, use the slow shell script. Don't cache a # value for MKDIR_P within a source directory, because that will # break other packages using the cache if that directory is # removed, or if the value is a relative name. MKDIR_P="$ac_install_sh -d" fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $MKDIR_P" >&5 $as_echo "$MKDIR_P" >&6; } mkdir_p="$MKDIR_P" case $mkdir_p in [\\/$]* | ?:[\\/]*) ;; */*) mkdir_p="\$(top_builddir)/$mkdir_p" ;; esac for ac_prog in gawk mawk nawk awk do # Extract the first word of "$ac_prog", so it can be a program name with args. set dummy $ac_prog; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_prog_AWK+:} false; then : $as_echo_n "(cached) " >&6 else if test -n "$AWK"; then ac_cv_prog_AWK="$AWK" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_AWK="$ac_prog" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi AWK=$ac_cv_prog_AWK if test -n "$AWK"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $AWK" >&5 $as_echo "$AWK" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi test -n "$AWK" && break done { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${MAKE-make} sets \$(MAKE)" >&5 $as_echo_n "checking whether ${MAKE-make} sets \$(MAKE)... " >&6; } set x ${MAKE-make} ac_make=`$as_echo "$2" | sed 's/+/p/g; s/[^a-zA-Z0-9_]/_/g'` if eval \${ac_cv_prog_make_${ac_make}_set+:} false; then : $as_echo_n "(cached) " >&6 else cat >conftest.make <<\_ACEOF SHELL = /bin/sh all: @echo '@@@%%%=$(MAKE)=@@@%%%' _ACEOF # GNU make sometimes prints "make[1]: Entering ...", which would confuse us. case `${MAKE-make} -f conftest.make 2>/dev/null` in *@@@%%%=?*=@@@%%%*) eval ac_cv_prog_make_${ac_make}_set=yes;; *) eval ac_cv_prog_make_${ac_make}_set=no;; esac rm -f conftest.make fi if eval test \$ac_cv_prog_make_${ac_make}_set = yes; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 $as_echo "yes" >&6; } SET_MAKE= else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } SET_MAKE="MAKE=${MAKE-make}" fi rm -rf .tst 2>/dev/null mkdir .tst 2>/dev/null if test -d .tst; then am__leading_dot=. else am__leading_dot=_ fi rmdir .tst 2>/dev/null if test "`cd $srcdir && pwd`" != "`pwd`"; then # Use -I$(srcdir) only when $(srcdir) != ., so that make's output # is not polluted with repeated "-I." am__isrc=' -I$(srcdir)' # test to see if srcdir already configured if test -f $srcdir/config.status; then as_fn_error $? "source directory already configured; run \"make distclean\" there first" "$LINENO" 5 fi fi # test whether we have cygpath if test -z "$CYGPATH_W"; then if (cygpath --version) >/dev/null 2>/dev/null; then CYGPATH_W='cygpath -w' else CYGPATH_W=echo fi fi # Define the identity of the package. PACKAGE='sftpserver' VERSION='0.2.1' cat >>confdefs.h <<_ACEOF #define PACKAGE "$PACKAGE" _ACEOF cat >>confdefs.h <<_ACEOF #define VERSION "$VERSION" _ACEOF # Some tools Automake needs. ACLOCAL=${ACLOCAL-"${am_missing_run}aclocal-${am__api_version}"} AUTOCONF=${AUTOCONF-"${am_missing_run}autoconf"} AUTOMAKE=${AUTOMAKE-"${am_missing_run}automake-${am__api_version}"} AUTOHEADER=${AUTOHEADER-"${am_missing_run}autoheader"} MAKEINFO=${MAKEINFO-"${am_missing_run}makeinfo"} # We need awk for the "check" target. The system "awk" is bad on # some platforms. # Always define AMTAR for backward compatibility. Yes, it's still used # in the wild :-( We should find a proper way to deprecate it ... AMTAR='$${TAR-tar}' am__tar='$${TAR-tar} chof - "$$tardir"' am__untar='$${TAR-tar} xf -' ac_config_headers="$ac_config_headers config.h" ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_c_compiler_gnu if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}gcc", so it can be a program name with args. set dummy ${ac_tool_prefix}gcc; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_prog_CC+:} false; then : $as_echo_n "(cached) " >&6 else if test -n "$CC"; then ac_cv_prog_CC="$CC" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_CC="${ac_tool_prefix}gcc" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi CC=$ac_cv_prog_CC if test -n "$CC"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 $as_echo "$CC" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi fi if test -z "$ac_cv_prog_CC"; then ac_ct_CC=$CC # Extract the first word of "gcc", so it can be a program name with args. set dummy gcc; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_prog_ac_ct_CC+:} false; then : $as_echo_n "(cached) " >&6 else if test -n "$ac_ct_CC"; then ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_ac_ct_CC="gcc" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi ac_ct_CC=$ac_cv_prog_ac_ct_CC if test -n "$ac_ct_CC"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5 $as_echo "$ac_ct_CC" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi if test "x$ac_ct_CC" = x; then CC="" else case $cross_compiling:$ac_tool_warned in yes:) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 $as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac CC=$ac_ct_CC fi else CC="$ac_cv_prog_CC" fi if test -z "$CC"; then if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}cc", so it can be a program name with args. set dummy ${ac_tool_prefix}cc; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_prog_CC+:} false; then : $as_echo_n "(cached) " >&6 else if test -n "$CC"; then ac_cv_prog_CC="$CC" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_CC="${ac_tool_prefix}cc" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi CC=$ac_cv_prog_CC if test -n "$CC"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 $as_echo "$CC" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi fi fi if test -z "$CC"; then # Extract the first word of "cc", so it can be a program name with args. set dummy cc; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_prog_CC+:} false; then : $as_echo_n "(cached) " >&6 else if test -n "$CC"; then ac_cv_prog_CC="$CC" # Let the user override the test. else ac_prog_rejected=no as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then if test "$as_dir/$ac_word$ac_exec_ext" = "/usr/ucb/cc"; then ac_prog_rejected=yes continue fi ac_cv_prog_CC="cc" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS if test $ac_prog_rejected = yes; then # We found a bogon in the path, so make sure we never use it. set dummy $ac_cv_prog_CC shift if test $# != 0; then # We chose a different compiler from the bogus one. # However, it has the same basename, so the bogon will be chosen # first if we set CC to just the basename; use the full file name. shift ac_cv_prog_CC="$as_dir/$ac_word${1+' '}$@" fi fi fi fi CC=$ac_cv_prog_CC if test -n "$CC"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 $as_echo "$CC" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi fi if test -z "$CC"; then if test -n "$ac_tool_prefix"; then for ac_prog in cl.exe do # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args. set dummy $ac_tool_prefix$ac_prog; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_prog_CC+:} false; then : $as_echo_n "(cached) " >&6 else if test -n "$CC"; then ac_cv_prog_CC="$CC" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_CC="$ac_tool_prefix$ac_prog" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi CC=$ac_cv_prog_CC if test -n "$CC"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 $as_echo "$CC" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi test -n "$CC" && break done fi if test -z "$CC"; then ac_ct_CC=$CC for ac_prog in cl.exe do # Extract the first word of "$ac_prog", so it can be a program name with args. set dummy $ac_prog; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_prog_ac_ct_CC+:} false; then : $as_echo_n "(cached) " >&6 else if test -n "$ac_ct_CC"; then ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_ac_ct_CC="$ac_prog" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi ac_ct_CC=$ac_cv_prog_ac_ct_CC if test -n "$ac_ct_CC"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5 $as_echo "$ac_ct_CC" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi test -n "$ac_ct_CC" && break done if test "x$ac_ct_CC" = x; then CC="" else case $cross_compiling:$ac_tool_warned in yes:) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 $as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac CC=$ac_ct_CC fi fi fi test -z "$CC" && { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "no acceptable C compiler found in \$PATH See \`config.log' for more details" "$LINENO" 5; } # Provide some information about the compiler. $as_echo "$as_me:${as_lineno-$LINENO}: checking for C compiler version" >&5 set X $ac_compile ac_compiler=$2 for ac_option in --version -v -V -qversion; do { { ac_try="$ac_compiler $ac_option >&5" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_compiler $ac_option >&5") 2>conftest.err ac_status=$? if test -s conftest.err; then sed '10a\ ... rest of stderr output deleted ... 10q' conftest.err >conftest.er1 cat conftest.er1 >&5 fi rm -f conftest.er1 conftest.err $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } done cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main () { ; return 0; } _ACEOF ac_clean_files_save=$ac_clean_files ac_clean_files="$ac_clean_files a.out a.out.dSYM a.exe b.out" # Try to create an executable without -o first, disregard a.out. # It will help us diagnose broken compilers, and finding out an intuition # of exeext. { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the C compiler works" >&5 $as_echo_n "checking whether the C compiler works... " >&6; } ac_link_default=`$as_echo "$ac_link" | sed 's/ -o *conftest[^ ]*//'` # The possible output files: ac_files="a.out conftest.exe conftest a.exe a_out.exe b.out conftest.*" ac_rmfiles= for ac_file in $ac_files do case $ac_file in *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ;; * ) ac_rmfiles="$ac_rmfiles $ac_file";; esac done rm -f $ac_rmfiles if { { ac_try="$ac_link_default" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_link_default") 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; then : # Autoconf-2.13 could set the ac_cv_exeext variable to `no'. # So ignore a value of `no', otherwise this would lead to `EXEEXT = no' # in a Makefile. We should not override ac_cv_exeext if it was cached, # so that the user can short-circuit this test for compilers unknown to # Autoconf. for ac_file in $ac_files '' do test -f "$ac_file" || continue case $ac_file in *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ;; [ab].out ) # We found the default executable, but exeext='' is most # certainly right. break;; *.* ) if test "${ac_cv_exeext+set}" = set && test "$ac_cv_exeext" != no; then :; else ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'` fi # We set ac_cv_exeext here because the later test for it is not # safe: cross compilers may not add the suffix if given an `-o' # argument, so we may need to know it at that point already. # Even if this section looks crufty: it has the advantage of # actually working. break;; * ) break;; esac done test "$ac_cv_exeext" = no && ac_cv_exeext= else ac_file='' fi if test -z "$ac_file"; then : { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } $as_echo "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error 77 "C compiler cannot create executables See \`config.log' for more details" "$LINENO" 5; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 $as_echo "yes" >&6; } fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for C compiler default output file name" >&5 $as_echo_n "checking for C compiler default output file name... " >&6; } { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_file" >&5 $as_echo "$ac_file" >&6; } ac_exeext=$ac_cv_exeext rm -f -r a.out a.out.dSYM a.exe conftest$ac_cv_exeext b.out ac_clean_files=$ac_clean_files_save { $as_echo "$as_me:${as_lineno-$LINENO}: checking for suffix of executables" >&5 $as_echo_n "checking for suffix of executables... " >&6; } if { { ac_try="$ac_link" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_link") 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; then : # If both `conftest.exe' and `conftest' are `present' (well, observable) # catch `conftest.exe'. For instance with Cygwin, `ls conftest' will # work properly (i.e., refer to `conftest.exe'), while it won't with # `rm'. for ac_file in conftest.exe conftest conftest.*; do test -f "$ac_file" || continue case $ac_file in *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ;; *.* ) ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'` break;; * ) break;; esac done else { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "cannot compute suffix of executables: cannot compile and link See \`config.log' for more details" "$LINENO" 5; } fi rm -f conftest conftest$ac_cv_exeext { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_exeext" >&5 $as_echo "$ac_cv_exeext" >&6; } rm -f conftest.$ac_ext EXEEXT=$ac_cv_exeext ac_exeext=$EXEEXT cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include int main () { FILE *f = fopen ("conftest.out", "w"); return ferror (f) || fclose (f) != 0; ; return 0; } _ACEOF ac_clean_files="$ac_clean_files conftest.out" # Check that the compiler produces executables we can run. If not, either # the compiler is broken, or we cross compile. { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are cross compiling" >&5 $as_echo_n "checking whether we are cross compiling... " >&6; } if test "$cross_compiling" != yes; then { { ac_try="$ac_link" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_link") 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } if { ac_try='./conftest$ac_cv_exeext' { { case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_try") 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; }; then cross_compiling=no else if test "$cross_compiling" = maybe; then cross_compiling=yes else { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "cannot run C compiled programs. If you meant to cross compile, use \`--host'. See \`config.log' for more details" "$LINENO" 5; } fi fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $cross_compiling" >&5 $as_echo "$cross_compiling" >&6; } rm -f conftest.$ac_ext conftest$ac_cv_exeext conftest.out ac_clean_files=$ac_clean_files_save { $as_echo "$as_me:${as_lineno-$LINENO}: checking for suffix of object files" >&5 $as_echo_n "checking for suffix of object files... " >&6; } if ${ac_cv_objext+:} false; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main () { ; return 0; } _ACEOF rm -f conftest.o conftest.obj if { { ac_try="$ac_compile" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_compile") 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; then : for ac_file in conftest.o conftest.obj conftest.*; do test -f "$ac_file" || continue; case $ac_file in *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM ) ;; *) ac_cv_objext=`expr "$ac_file" : '.*\.\(.*\)'` break;; esac done else $as_echo "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "cannot compute suffix of object files: cannot compile See \`config.log' for more details" "$LINENO" 5; } fi rm -f conftest.$ac_cv_objext conftest.$ac_ext fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_objext" >&5 $as_echo "$ac_cv_objext" >&6; } OBJEXT=$ac_cv_objext ac_objext=$OBJEXT { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are using the GNU C compiler" >&5 $as_echo_n "checking whether we are using the GNU C compiler... " >&6; } if ${ac_cv_c_compiler_gnu+:} false; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main () { #ifndef __GNUC__ choke me #endif ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : ac_compiler_gnu=yes else ac_compiler_gnu=no fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext ac_cv_c_compiler_gnu=$ac_compiler_gnu fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_compiler_gnu" >&5 $as_echo "$ac_cv_c_compiler_gnu" >&6; } if test $ac_compiler_gnu = yes; then GCC=yes else GCC= fi ac_test_CFLAGS=${CFLAGS+set} ac_save_CFLAGS=$CFLAGS { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC accepts -g" >&5 $as_echo_n "checking whether $CC accepts -g... " >&6; } if ${ac_cv_prog_cc_g+:} false; then : $as_echo_n "(cached) " >&6 else ac_save_c_werror_flag=$ac_c_werror_flag ac_c_werror_flag=yes ac_cv_prog_cc_g=no CFLAGS="-g" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main () { ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : ac_cv_prog_cc_g=yes else CFLAGS="" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main () { ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : else ac_c_werror_flag=$ac_save_c_werror_flag CFLAGS="-g" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main () { ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : ac_cv_prog_cc_g=yes fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext ac_c_werror_flag=$ac_save_c_werror_flag fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_g" >&5 $as_echo "$ac_cv_prog_cc_g" >&6; } if test "$ac_test_CFLAGS" = set; then CFLAGS=$ac_save_CFLAGS elif test $ac_cv_prog_cc_g = yes; then if test "$GCC" = yes; then CFLAGS="-g -O2" else CFLAGS="-g" fi else if test "$GCC" = yes; then CFLAGS="-O2" else CFLAGS= fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $CC option to accept ISO C89" >&5 $as_echo_n "checking for $CC option to accept ISO C89... " >&6; } if ${ac_cv_prog_cc_c89+:} false; then : $as_echo_n "(cached) " >&6 else ac_cv_prog_cc_c89=no ac_save_CC=$CC cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include #include struct stat; /* Most of the following tests are stolen from RCS 5.7's src/conf.sh. */ struct buf { int x; }; FILE * (*rcsopen) (struct buf *, struct stat *, int); static char *e (p, i) char **p; int i; { return p[i]; } static char *f (char * (*g) (char **, int), char **p, ...) { char *s; va_list v; va_start (v,p); s = g (p, va_arg (v,int)); va_end (v); return s; } /* OSF 4.0 Compaq cc is some sort of almost-ANSI by default. It has function prototypes and stuff, but not '\xHH' hex character constants. These don't provoke an error unfortunately, instead are silently treated as 'x'. The following induces an error, until -std is added to get proper ANSI mode. Curiously '\x00'!='x' always comes out true, for an array size at least. It's necessary to write '\x00'==0 to get something that's true only with -std. */ int osf4_cc_array ['\x00' == 0 ? 1 : -1]; /* IBM C 6 for AIX is almost-ANSI by default, but it replaces macro parameters inside strings and character constants. */ #define FOO(x) 'x' int xlc6_cc_array[FOO(a) == 'x' ? 1 : -1]; int test (int i, double x); struct s1 {int (*f) (int a);}; struct s2 {int (*f) (double a);}; int pairnames (int, char **, FILE *(*)(struct buf *, struct stat *, int), int, int); int argc; char **argv; int main () { return f (e, argv, 0) != argv[0] || f (e, argv, 1) != argv[1]; ; return 0; } _ACEOF for ac_arg in '' -qlanglvl=extc89 -qlanglvl=ansi -std \ -Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__" do CC="$ac_save_CC $ac_arg" if ac_fn_c_try_compile "$LINENO"; then : ac_cv_prog_cc_c89=$ac_arg fi rm -f core conftest.err conftest.$ac_objext test "x$ac_cv_prog_cc_c89" != "xno" && break done rm -f conftest.$ac_ext CC=$ac_save_CC fi # AC_CACHE_VAL case "x$ac_cv_prog_cc_c89" in x) { $as_echo "$as_me:${as_lineno-$LINENO}: result: none needed" >&5 $as_echo "none needed" >&6; } ;; xno) { $as_echo "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5 $as_echo "unsupported" >&6; } ;; *) CC="$CC $ac_cv_prog_cc_c89" { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_c89" >&5 $as_echo "$ac_cv_prog_cc_c89" >&6; } ;; esac if test "x$ac_cv_prog_cc_c89" != xno; then : fi ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_c_compiler_gnu DEPDIR="${am__leading_dot}deps" ac_config_commands="$ac_config_commands depfiles" am_make=${MAKE-make} cat > confinc << 'END' am__doit: @echo this is the am__doit target .PHONY: am__doit END # If we don't find an include directive, just comment out the code. { $as_echo "$as_me:${as_lineno-$LINENO}: checking for style of include used by $am_make" >&5 $as_echo_n "checking for style of include used by $am_make... " >&6; } am__include="#" am__quote= _am_result=none # First try GNU make style include. echo "include confinc" > confmf # Ignore all kinds of additional output from `make'. case `$am_make -s -f confmf 2> /dev/null` in #( *the\ am__doit\ target*) am__include=include am__quote= _am_result=GNU ;; esac # Now try BSD make style include. if test "$am__include" = "#"; then echo '.include "confinc"' > confmf case `$am_make -s -f confmf 2> /dev/null` in #( *the\ am__doit\ target*) am__include=.include am__quote="\"" _am_result=BSD ;; esac fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $_am_result" >&5 $as_echo "$_am_result" >&6; } rm -f confinc confmf # Check whether --enable-dependency-tracking was given. if test "${enable_dependency_tracking+set}" = set; then : enableval=$enable_dependency_tracking; fi if test "x$enable_dependency_tracking" != xno; then am_depcomp="$ac_aux_dir/depcomp" AMDEPBACKSLASH='\' am__nodep='_no' fi if test "x$enable_dependency_tracking" != xno; then AMDEP_TRUE= AMDEP_FALSE='#' else AMDEP_TRUE='#' AMDEP_FALSE= fi depcc="$CC" am_compiler_list= { $as_echo "$as_me:${as_lineno-$LINENO}: checking dependency style of $depcc" >&5 $as_echo_n "checking dependency style of $depcc... " >&6; } if ${am_cv_CC_dependencies_compiler_type+:} false; then : $as_echo_n "(cached) " >&6 else if test -z "$AMDEP_TRUE" && test -f "$am_depcomp"; then # We make a subdir and do the tests there. Otherwise we can end up # making bogus files that we don't know about and never remove. For # instance it was reported that on HP-UX the gcc test will end up # making a dummy file named `D' -- because `-MD' means `put the output # in D'. rm -rf conftest.dir mkdir conftest.dir # Copy depcomp to subdir because otherwise we won't find it if we're # using a relative directory. cp "$am_depcomp" conftest.dir cd conftest.dir # We will build objects and dependencies in a subdirectory because # it helps to detect inapplicable dependency modes. For instance # both Tru64's cc and ICC support -MD to output dependencies as a # side effect of compilation, but ICC will put the dependencies in # the current directory while Tru64 will put them in the object # directory. mkdir sub am_cv_CC_dependencies_compiler_type=none if test "$am_compiler_list" = ""; then am_compiler_list=`sed -n 's/^#*\([a-zA-Z0-9]*\))$/\1/p' < ./depcomp` fi am__universal=false case " $depcc " in #( *\ -arch\ *\ -arch\ *) am__universal=true ;; esac for depmode in $am_compiler_list; do # Setup a source with many dependencies, because some compilers # like to wrap large dependency lists on column 80 (with \), and # we should not choose a depcomp mode which is confused by this. # # We need to recreate these files for each test, as the compiler may # overwrite some of them when testing with obscure command lines. # This happens at least with the AIX C compiler. : > sub/conftest.c for i in 1 2 3 4 5 6; do echo '#include "conftst'$i'.h"' >> sub/conftest.c # Using `: > sub/conftst$i.h' creates only sub/conftst1.h with # Solaris 8's {/usr,}/bin/sh. touch sub/conftst$i.h done echo "${am__include} ${am__quote}sub/conftest.Po${am__quote}" > confmf # We check with `-c' and `-o' for the sake of the "dashmstdout" # mode. It turns out that the SunPro C++ compiler does not properly # handle `-M -o', and we need to detect this. Also, some Intel # versions had trouble with output in subdirs am__obj=sub/conftest.${OBJEXT-o} am__minus_obj="-o $am__obj" case $depmode in gcc) # This depmode causes a compiler race in universal mode. test "$am__universal" = false || continue ;; nosideeffect) # after this tag, mechanisms are not by side-effect, so they'll # only be used when explicitly requested if test "x$enable_dependency_tracking" = xyes; then continue else break fi ;; msvc7 | msvc7msys | msvisualcpp | msvcmsys) # This compiler won't grok `-c -o', but also, the minuso test has # not run yet. These depmodes are late enough in the game, and # so weak that their functioning should not be impacted. am__obj=conftest.${OBJEXT-o} am__minus_obj= ;; none) break ;; esac if depmode=$depmode \ source=sub/conftest.c object=$am__obj \ depfile=sub/conftest.Po tmpdepfile=sub/conftest.TPo \ $SHELL ./depcomp $depcc -c $am__minus_obj sub/conftest.c \ >/dev/null 2>conftest.err && grep sub/conftst1.h sub/conftest.Po > /dev/null 2>&1 && grep sub/conftst6.h sub/conftest.Po > /dev/null 2>&1 && grep $am__obj sub/conftest.Po > /dev/null 2>&1 && ${MAKE-make} -s -f confmf > /dev/null 2>&1; then # icc doesn't choke on unknown options, it will just issue warnings # or remarks (even with -Werror). So we grep stderr for any message # that says an option was ignored or not supported. # When given -MP, icc 7.0 and 7.1 complain thusly: # icc: Command line warning: ignoring option '-M'; no argument required # The diagnosis changed in icc 8.0: # icc: Command line remark: option '-MP' not supported if (grep 'ignoring option' conftest.err || grep 'not supported' conftest.err) >/dev/null 2>&1; then :; else am_cv_CC_dependencies_compiler_type=$depmode break fi fi done cd .. rm -rf conftest.dir else am_cv_CC_dependencies_compiler_type=none fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $am_cv_CC_dependencies_compiler_type" >&5 $as_echo "$am_cv_CC_dependencies_compiler_type" >&6; } CCDEPMODE=depmode=$am_cv_CC_dependencies_compiler_type if test "x$enable_dependency_tracking" != xno \ && test "$am_cv_CC_dependencies_compiler_type" = gcc3; then am__fastdepCC_TRUE= am__fastdepCC_FALSE='#' else am__fastdepCC_TRUE='#' am__fastdepCC_FALSE= fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${MAKE-make} sets \$(MAKE)" >&5 $as_echo_n "checking whether ${MAKE-make} sets \$(MAKE)... " >&6; } set x ${MAKE-make} ac_make=`$as_echo "$2" | sed 's/+/p/g; s/[^a-zA-Z0-9_]/_/g'` if eval \${ac_cv_prog_make_${ac_make}_set+:} false; then : $as_echo_n "(cached) " >&6 else cat >conftest.make <<\_ACEOF SHELL = /bin/sh all: @echo '@@@%%%=$(MAKE)=@@@%%%' _ACEOF # GNU make sometimes prints "make[1]: Entering ...", which would confuse us. case `${MAKE-make} -f conftest.make 2>/dev/null` in *@@@%%%=?*=@@@%%%*) eval ac_cv_prog_make_${ac_make}_set=yes;; *) eval ac_cv_prog_make_${ac_make}_set=no;; esac rm -f conftest.make fi if eval test \$ac_cv_prog_make_${ac_make}_set = yes; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 $as_echo "yes" >&6; } SET_MAKE= else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } SET_MAKE="MAKE=${MAKE-make}" fi #AC_PROG_LIBTOOL #AC_LIBTOOL_DLOPEN #AC_DISABLE_STATIC #RJK_BUILDSYS_FINK # Make sure we can run config.sub. $SHELL "$ac_aux_dir/config.sub" sun4 >/dev/null 2>&1 || as_fn_error $? "cannot run $SHELL $ac_aux_dir/config.sub" "$LINENO" 5 { $as_echo "$as_me:${as_lineno-$LINENO}: checking build system type" >&5 $as_echo_n "checking build system type... " >&6; } if ${ac_cv_build+:} false; then : $as_echo_n "(cached) " >&6 else ac_build_alias=$build_alias test "x$ac_build_alias" = x && ac_build_alias=`$SHELL "$ac_aux_dir/config.guess"` test "x$ac_build_alias" = x && as_fn_error $? "cannot guess build type; you must specify one" "$LINENO" 5 ac_cv_build=`$SHELL "$ac_aux_dir/config.sub" $ac_build_alias` || as_fn_error $? "$SHELL $ac_aux_dir/config.sub $ac_build_alias failed" "$LINENO" 5 fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_build" >&5 $as_echo "$ac_cv_build" >&6; } case $ac_cv_build in *-*-*) ;; *) as_fn_error $? "invalid value of canonical build" "$LINENO" 5;; esac build=$ac_cv_build ac_save_IFS=$IFS; IFS='-' set x $ac_cv_build shift build_cpu=$1 build_vendor=$2 shift; shift # Remember, the first character of IFS is used to create $*, # except with old shells: build_os=$* IFS=$ac_save_IFS case $build_os in *\ *) build_os=`echo "$build_os" | sed 's/ /-/g'`;; esac { $as_echo "$as_me:${as_lineno-$LINENO}: checking host system type" >&5 $as_echo_n "checking host system type... " >&6; } if ${ac_cv_host+:} false; then : $as_echo_n "(cached) " >&6 else if test "x$host_alias" = x; then ac_cv_host=$ac_cv_build else ac_cv_host=`$SHELL "$ac_aux_dir/config.sub" $host_alias` || as_fn_error $? "$SHELL $ac_aux_dir/config.sub $host_alias failed" "$LINENO" 5 fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_host" >&5 $as_echo "$ac_cv_host" >&6; } case $ac_cv_host in *-*-*) ;; *) as_fn_error $? "invalid value of canonical host" "$LINENO" 5;; esac host=$ac_cv_host ac_save_IFS=$IFS; IFS='-' set x $ac_cv_host shift host_cpu=$1 host_vendor=$2 shift; shift # Remember, the first character of IFS is used to create $*, # except with old shells: host_os=$* IFS=$ac_save_IFS case $host_os in *\ *) host_os=`echo "$host_os" | sed 's/ /-/g'`;; esac { $as_echo "$as_me:${as_lineno-$LINENO}: checking for extra include directories" >&5 $as_echo_n "checking for extra include directories... " >&6; } if ${rjk_cv_extraincludes+:} false; then : $as_echo_n "(cached) " >&6 else rjk_cv_extraincludes=none # If we're cross-compiling then we've no idea where to look for # extra includes if test "$host" = "$build"; then case $host_os in freebsd* ) rjk_cv_extraincludes=/usr/local/include ;; esac fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $rjk_cv_extraincludes" >&5 $as_echo "$rjk_cv_extraincludes" >&6; } if test $rjk_cv_extraincludes != none; then if test $GCC = yes; then CPPFLAGS="-isystem $rjk_cv_extraincludes" else CPPFLAGS="-I$rjk_cv_extraincludes" fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for extra library directories" >&5 $as_echo_n "checking for extra library directories... " >&6; } if ${rjk_cv_extralibs+:} false; then : $as_echo_n "(cached) " >&6 else rjk_cv_extralibs=none if test "$host" = "$build"; then case $host_os in freebsd* ) rjk_cv_extralibs=/usr/local/lib ;; esac fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $rjk_cv_extralibs" >&5 $as_echo "$rjk_cv_extralibs" >&6; } if test $rjk_cv_extralibs != none; then LDFLAGS="-L$rjk_cv_extralibs" fi #RJK_GTKFLAGS if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}ranlib", so it can be a program name with args. set dummy ${ac_tool_prefix}ranlib; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_prog_RANLIB+:} false; then : $as_echo_n "(cached) " >&6 else if test -n "$RANLIB"; then ac_cv_prog_RANLIB="$RANLIB" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_RANLIB="${ac_tool_prefix}ranlib" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi RANLIB=$ac_cv_prog_RANLIB if test -n "$RANLIB"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $RANLIB" >&5 $as_echo "$RANLIB" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi fi if test -z "$ac_cv_prog_RANLIB"; then ac_ct_RANLIB=$RANLIB # Extract the first word of "ranlib", so it can be a program name with args. set dummy ranlib; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_prog_ac_ct_RANLIB+:} false; then : $as_echo_n "(cached) " >&6 else if test -n "$ac_ct_RANLIB"; then ac_cv_prog_ac_ct_RANLIB="$ac_ct_RANLIB" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_ac_ct_RANLIB="ranlib" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi ac_ct_RANLIB=$ac_cv_prog_ac_ct_RANLIB if test -n "$ac_ct_RANLIB"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_RANLIB" >&5 $as_echo "$ac_ct_RANLIB" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi if test "x$ac_ct_RANLIB" = x; then RANLIB=":" else case $cross_compiling:$ac_tool_warned in yes:) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 $as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac RANLIB=$ac_ct_RANLIB fi else RANLIB="$ac_cv_prog_RANLIB" fi # If you're cross-compiling then you're on your own { $as_echo "$as_me:${as_lineno-$LINENO}: checking how to build threaded code" >&5 $as_echo_n "checking how to build threaded code... " >&6; } if test "$host" = "$build"; then case $host_os in solaris2* ) case "$GCC" in yes ) { $as_echo "$as_me:${as_lineno-$LINENO}: result: -lpthread" >&5 $as_echo "-lpthread" >&6; } { $as_echo "$as_me:${as_lineno-$LINENO}: checking for pthread_create in -lpthread" >&5 $as_echo_n "checking for pthread_create in -lpthread... " >&6; } if ${ac_cv_lib_pthread_pthread_create+:} false; then : $as_echo_n "(cached) " >&6 else ac_check_lib_save_LIBS=$LIBS LIBS="-lpthread $LIBS" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ /* Override any GCC internal prototype to avoid an error. Use char because int might match the return type of a GCC builtin and then its argument prototype would still apply. */ #ifdef __cplusplus extern "C" #endif char pthread_create (); int main () { return pthread_create (); ; return 0; } _ACEOF if ac_fn_c_try_link "$LINENO"; then : ac_cv_lib_pthread_pthread_create=yes else ac_cv_lib_pthread_pthread_create=no fi rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext LIBS=$ac_check_lib_save_LIBS fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_pthread_pthread_create" >&5 $as_echo "$ac_cv_lib_pthread_pthread_create" >&6; } if test "x$ac_cv_lib_pthread_pthread_create" = xyes; then : cat >>confdefs.h <<_ACEOF #define HAVE_LIBPTHREAD 1 _ACEOF LIBS="-lpthread $LIBS" fi ;; * ) { $as_echo "$as_me:${as_lineno-$LINENO}: result: -mt option" >&5 $as_echo "-mt option" >&6; } CC="${CC} -mt" ;; esac ;; linux* | freebsd* | darwin* ) { $as_echo "$as_me:${as_lineno-$LINENO}: result: -lpthread" >&5 $as_echo "-lpthread" >&6; } { $as_echo "$as_me:${as_lineno-$LINENO}: checking for pthread_create in -lpthread" >&5 $as_echo_n "checking for pthread_create in -lpthread... " >&6; } if ${ac_cv_lib_pthread_pthread_create+:} false; then : $as_echo_n "(cached) " >&6 else ac_check_lib_save_LIBS=$LIBS LIBS="-lpthread $LIBS" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ /* Override any GCC internal prototype to avoid an error. Use char because int might match the return type of a GCC builtin and then its argument prototype would still apply. */ #ifdef __cplusplus extern "C" #endif char pthread_create (); int main () { return pthread_create (); ; return 0; } _ACEOF if ac_fn_c_try_link "$LINENO"; then : ac_cv_lib_pthread_pthread_create=yes else ac_cv_lib_pthread_pthread_create=no fi rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext LIBS=$ac_check_lib_save_LIBS fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_pthread_pthread_create" >&5 $as_echo "$ac_cv_lib_pthread_pthread_create" >&6; } if test "x$ac_cv_lib_pthread_pthread_create" = xyes; then : cat >>confdefs.h <<_ACEOF #define HAVE_LIBPTHREAD 1 _ACEOF LIBS="-lpthread $LIBS" fi ;; * ) { $as_echo "$as_me:${as_lineno-$LINENO}: result: unknown" >&5 $as_echo "unknown" >&6; } as_fn_error $? "don't know how to build threaded code on this system" "$LINENO" 5 ;; esac fi # We always ask for this. $as_echo "#define _REENTRANT 1" >>confdefs.h ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_c_compiler_gnu { $as_echo "$as_me:${as_lineno-$LINENO}: checking how to run the C preprocessor" >&5 $as_echo_n "checking how to run the C preprocessor... " >&6; } # On Suns, sometimes $CPP names a directory. if test -n "$CPP" && test -d "$CPP"; then CPP= fi if test -z "$CPP"; then if ${ac_cv_prog_CPP+:} false; then : $as_echo_n "(cached) " >&6 else # Double quotes because CPP needs to be expanded for CPP in "$CC -E" "$CC -E -traditional-cpp" "/lib/cpp" do ac_preproc_ok=false for ac_c_preproc_warn_flag in '' yes do # Use a header file that comes with gcc, so configuring glibc # with a fresh cross-compiler works. # Prefer to if __STDC__ is defined, since # exists even on freestanding compilers. # On the NeXT, cc -E runs the code through the compiler's parser, # not just through cpp. "Syntax error" is here to catch this case. cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #ifdef __STDC__ # include #else # include #endif Syntax error _ACEOF if ac_fn_c_try_cpp "$LINENO"; then : else # Broken: fails on valid input. continue fi rm -f conftest.err conftest.i conftest.$ac_ext # OK, works on sane cases. Now check whether nonexistent headers # can be detected and how. cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include _ACEOF if ac_fn_c_try_cpp "$LINENO"; then : # Broken: success on invalid input. continue else # Passes both tests. ac_preproc_ok=: break fi rm -f conftest.err conftest.i conftest.$ac_ext done # Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. rm -f conftest.i conftest.err conftest.$ac_ext if $ac_preproc_ok; then : break fi done ac_cv_prog_CPP=$CPP fi CPP=$ac_cv_prog_CPP else ac_cv_prog_CPP=$CPP fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CPP" >&5 $as_echo "$CPP" >&6; } ac_preproc_ok=false for ac_c_preproc_warn_flag in '' yes do # Use a header file that comes with gcc, so configuring glibc # with a fresh cross-compiler works. # Prefer to if __STDC__ is defined, since # exists even on freestanding compilers. # On the NeXT, cc -E runs the code through the compiler's parser, # not just through cpp. "Syntax error" is here to catch this case. cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #ifdef __STDC__ # include #else # include #endif Syntax error _ACEOF if ac_fn_c_try_cpp "$LINENO"; then : else # Broken: fails on valid input. continue fi rm -f conftest.err conftest.i conftest.$ac_ext # OK, works on sane cases. Now check whether nonexistent headers # can be detected and how. cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include _ACEOF if ac_fn_c_try_cpp "$LINENO"; then : # Broken: success on invalid input. continue else # Passes both tests. ac_preproc_ok=: break fi rm -f conftest.err conftest.i conftest.$ac_ext done # Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. rm -f conftest.i conftest.err conftest.$ac_ext if $ac_preproc_ok; then : else { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "C preprocessor \"$CPP\" fails sanity check See \`config.log' for more details" "$LINENO" 5; } fi ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_c_compiler_gnu { $as_echo "$as_me:${as_lineno-$LINENO}: checking for grep that handles long lines and -e" >&5 $as_echo_n "checking for grep that handles long lines and -e... " >&6; } if ${ac_cv_path_GREP+:} false; then : $as_echo_n "(cached) " >&6 else if test -z "$GREP"; then ac_path_GREP_found=false # Loop through the user's path and test for each of PROGNAME-LIST as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_prog in grep ggrep; do for ac_exec_ext in '' $ac_executable_extensions; do ac_path_GREP="$as_dir/$ac_prog$ac_exec_ext" as_fn_executable_p "$ac_path_GREP" || continue # Check for GNU ac_path_GREP and select it if it is found. # Check for GNU $ac_path_GREP case `"$ac_path_GREP" --version 2>&1` in *GNU*) ac_cv_path_GREP="$ac_path_GREP" ac_path_GREP_found=:;; *) ac_count=0 $as_echo_n 0123456789 >"conftest.in" while : do cat "conftest.in" "conftest.in" >"conftest.tmp" mv "conftest.tmp" "conftest.in" cp "conftest.in" "conftest.nl" $as_echo 'GREP' >> "conftest.nl" "$ac_path_GREP" -e 'GREP$' -e '-(cannot match)-' < "conftest.nl" >"conftest.out" 2>/dev/null || break diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break as_fn_arith $ac_count + 1 && ac_count=$as_val if test $ac_count -gt ${ac_path_GREP_max-0}; then # Best one so far, save it but keep looking for a better one ac_cv_path_GREP="$ac_path_GREP" ac_path_GREP_max=$ac_count fi # 10*(2^10) chars as input seems more than enough test $ac_count -gt 10 && break done rm -f conftest.in conftest.tmp conftest.nl conftest.out;; esac $ac_path_GREP_found && break 3 done done done IFS=$as_save_IFS if test -z "$ac_cv_path_GREP"; then as_fn_error $? "no acceptable grep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" "$LINENO" 5 fi else ac_cv_path_GREP=$GREP fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_GREP" >&5 $as_echo "$ac_cv_path_GREP" >&6; } GREP="$ac_cv_path_GREP" { $as_echo "$as_me:${as_lineno-$LINENO}: checking for egrep" >&5 $as_echo_n "checking for egrep... " >&6; } if ${ac_cv_path_EGREP+:} false; then : $as_echo_n "(cached) " >&6 else if echo a | $GREP -E '(a|b)' >/dev/null 2>&1 then ac_cv_path_EGREP="$GREP -E" else if test -z "$EGREP"; then ac_path_EGREP_found=false # Loop through the user's path and test for each of PROGNAME-LIST as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_prog in egrep; do for ac_exec_ext in '' $ac_executable_extensions; do ac_path_EGREP="$as_dir/$ac_prog$ac_exec_ext" as_fn_executable_p "$ac_path_EGREP" || continue # Check for GNU ac_path_EGREP and select it if it is found. # Check for GNU $ac_path_EGREP case `"$ac_path_EGREP" --version 2>&1` in *GNU*) ac_cv_path_EGREP="$ac_path_EGREP" ac_path_EGREP_found=:;; *) ac_count=0 $as_echo_n 0123456789 >"conftest.in" while : do cat "conftest.in" "conftest.in" >"conftest.tmp" mv "conftest.tmp" "conftest.in" cp "conftest.in" "conftest.nl" $as_echo 'EGREP' >> "conftest.nl" "$ac_path_EGREP" 'EGREP$' < "conftest.nl" >"conftest.out" 2>/dev/null || break diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break as_fn_arith $ac_count + 1 && ac_count=$as_val if test $ac_count -gt ${ac_path_EGREP_max-0}; then # Best one so far, save it but keep looking for a better one ac_cv_path_EGREP="$ac_path_EGREP" ac_path_EGREP_max=$ac_count fi # 10*(2^10) chars as input seems more than enough test $ac_count -gt 10 && break done rm -f conftest.in conftest.tmp conftest.nl conftest.out;; esac $ac_path_EGREP_found && break 3 done done done IFS=$as_save_IFS if test -z "$ac_cv_path_EGREP"; then as_fn_error $? "no acceptable egrep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" "$LINENO" 5 fi else ac_cv_path_EGREP=$EGREP fi fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_EGREP" >&5 $as_echo "$ac_cv_path_EGREP" >&6; } EGREP="$ac_cv_path_EGREP" { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ANSI C header files" >&5 $as_echo_n "checking for ANSI C header files... " >&6; } if ${ac_cv_header_stdc+:} false; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include #include #include #include int main () { ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : ac_cv_header_stdc=yes else ac_cv_header_stdc=no fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext if test $ac_cv_header_stdc = yes; then # SunOS 4.x string.h does not declare mem*, contrary to ANSI. cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include _ACEOF if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | $EGREP "memchr" >/dev/null 2>&1; then : else ac_cv_header_stdc=no fi rm -f conftest* fi if test $ac_cv_header_stdc = yes; then # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI. cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include _ACEOF if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | $EGREP "free" >/dev/null 2>&1; then : else ac_cv_header_stdc=no fi rm -f conftest* fi if test $ac_cv_header_stdc = yes; then # /bin/cc in Irix-4.0.5 gets non-ANSI ctype macros unless using -ansi. if test "$cross_compiling" = yes; then : : else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include #include #if ((' ' & 0x0FF) == 0x020) # define ISLOWER(c) ('a' <= (c) && (c) <= 'z') # define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c)) #else # define ISLOWER(c) \ (('a' <= (c) && (c) <= 'i') \ || ('j' <= (c) && (c) <= 'r') \ || ('s' <= (c) && (c) <= 'z')) # define TOUPPER(c) (ISLOWER(c) ? ((c) | 0x40) : (c)) #endif #define XOR(e, f) (((e) && !(f)) || (!(e) && (f))) int main () { int i; for (i = 0; i < 256; i++) if (XOR (islower (i), ISLOWER (i)) || toupper (i) != TOUPPER (i)) return 2; return 0; } _ACEOF if ac_fn_c_try_run "$LINENO"; then : else ac_cv_header_stdc=no fi rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ conftest.$ac_objext conftest.beam conftest.$ac_ext fi fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_header_stdc" >&5 $as_echo "$ac_cv_header_stdc" >&6; } if test $ac_cv_header_stdc = yes; then $as_echo "#define STDC_HEADERS 1" >>confdefs.h fi # On IRIX 5.3, sys/types and inttypes.h are conflicting. for ac_header in sys/types.h sys/stat.h stdlib.h string.h memory.h strings.h \ inttypes.h stdint.h unistd.h do : as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` ac_fn_c_check_header_compile "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default " if eval test \"x\$"$as_ac_Header"\" = x"yes"; then : cat >>confdefs.h <<_ACEOF #define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1 _ACEOF fi done for ac_header in endian.h sys/prctl.h do : as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` ac_fn_c_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default" if eval test \"x\$"$as_ac_Header"\" = x"yes"; then : cat >>confdefs.h <<_ACEOF #define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1 _ACEOF fi done { $as_echo "$as_me:${as_lineno-$LINENO}: checking for socket in -lsocket" >&5 $as_echo_n "checking for socket in -lsocket... " >&6; } if ${ac_cv_lib_socket_socket+:} false; then : $as_echo_n "(cached) " >&6 else ac_check_lib_save_LIBS=$LIBS LIBS="-lsocket $LIBS" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ /* Override any GCC internal prototype to avoid an error. Use char because int might match the return type of a GCC builtin and then its argument prototype would still apply. */ #ifdef __cplusplus extern "C" #endif char socket (); int main () { return socket (); ; return 0; } _ACEOF if ac_fn_c_try_link "$LINENO"; then : ac_cv_lib_socket_socket=yes else ac_cv_lib_socket_socket=no fi rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext LIBS=$ac_check_lib_save_LIBS fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_socket_socket" >&5 $as_echo "$ac_cv_lib_socket_socket" >&6; } if test "x$ac_cv_lib_socket_socket" = xyes; then : cat >>confdefs.h <<_ACEOF #define HAVE_LIBSOCKET 1 _ACEOF LIBS="-lsocket $LIBS" fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for readline in -lreadline" >&5 $as_echo_n "checking for readline in -lreadline... " >&6; } if ${ac_cv_lib_readline_readline+:} false; then : $as_echo_n "(cached) " >&6 else ac_check_lib_save_LIBS=$LIBS LIBS="-lreadline $LIBS" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ /* Override any GCC internal prototype to avoid an error. Use char because int might match the return type of a GCC builtin and then its argument prototype would still apply. */ #ifdef __cplusplus extern "C" #endif char readline (); int main () { return readline (); ; return 0; } _ACEOF if ac_fn_c_try_link "$LINENO"; then : ac_cv_lib_readline_readline=yes else ac_cv_lib_readline_readline=no fi rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext LIBS=$ac_check_lib_save_LIBS fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_readline_readline" >&5 $as_echo "$ac_cv_lib_readline_readline" >&6; } if test "x$ac_cv_lib_readline_readline" = xyes; then : LIBREADLINE=-lreadline $as_echo "#define HAVE_READLINE 1" >>confdefs.h fi # MacOS has a rather odd iconv (presumably for some good reason) { $as_echo "$as_me:${as_lineno-$LINENO}: checking for iconv_open in -liconv" >&5 $as_echo_n "checking for iconv_open in -liconv... " >&6; } if ${ac_cv_lib_iconv_iconv_open+:} false; then : $as_echo_n "(cached) " >&6 else ac_check_lib_save_LIBS=$LIBS LIBS="-liconv $LIBS" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ /* Override any GCC internal prototype to avoid an error. Use char because int might match the return type of a GCC builtin and then its argument prototype would still apply. */ #ifdef __cplusplus extern "C" #endif char iconv_open (); int main () { return iconv_open (); ; return 0; } _ACEOF if ac_fn_c_try_link "$LINENO"; then : ac_cv_lib_iconv_iconv_open=yes else ac_cv_lib_iconv_iconv_open=no fi rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext LIBS=$ac_check_lib_save_LIBS fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_iconv_iconv_open" >&5 $as_echo "$ac_cv_lib_iconv_iconv_open" >&6; } if test "x$ac_cv_lib_iconv_iconv_open" = xyes; then : cat >>confdefs.h <<_ACEOF #define HAVE_LIBICONV 1 _ACEOF LIBS="-liconv $LIBS" fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for libiconv_open in -liconv" >&5 $as_echo_n "checking for libiconv_open in -liconv... " >&6; } if ${ac_cv_lib_iconv_libiconv_open+:} false; then : $as_echo_n "(cached) " >&6 else ac_check_lib_save_LIBS=$LIBS LIBS="-liconv $LIBS" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ /* Override any GCC internal prototype to avoid an error. Use char because int might match the return type of a GCC builtin and then its argument prototype would still apply. */ #ifdef __cplusplus extern "C" #endif char libiconv_open (); int main () { return libiconv_open (); ; return 0; } _ACEOF if ac_fn_c_try_link "$LINENO"; then : ac_cv_lib_iconv_libiconv_open=yes else ac_cv_lib_iconv_libiconv_open=no fi rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext LIBS=$ac_check_lib_save_LIBS fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_iconv_libiconv_open" >&5 $as_echo "$ac_cv_lib_iconv_libiconv_open" >&6; } if test "x$ac_cv_lib_iconv_libiconv_open" = xyes; then : cat >>confdefs.h <<_ACEOF #define HAVE_LIBICONV 1 _ACEOF LIBS="-liconv $LIBS" fi $as_echo "#define _GNU_SOURCE 1" >>confdefs.h { $as_echo "$as_me:${as_lineno-$LINENO}: checking for inline" >&5 $as_echo_n "checking for inline... " >&6; } if ${ac_cv_c_inline+:} false; then : $as_echo_n "(cached) " >&6 else ac_cv_c_inline=no for ac_kw in inline __inline__ __inline; do cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #ifndef __cplusplus typedef int foo_t; static $ac_kw foo_t static_foo () {return 0; } $ac_kw foo_t foo () {return 0; } #endif _ACEOF if ac_fn_c_try_compile "$LINENO"; then : ac_cv_c_inline=$ac_kw fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext test "$ac_cv_c_inline" != no && break done fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_inline" >&5 $as_echo "$ac_cv_c_inline" >&6; } case $ac_cv_c_inline in inline | yes) ;; *) case $ac_cv_c_inline in no) ac_val=;; *) ac_val=$ac_cv_c_inline;; esac cat >>confdefs.h <<_ACEOF #ifndef __cplusplus #define inline $ac_val #endif _ACEOF ;; esac # Check whether --enable-largefile was given. if test "${enable_largefile+set}" = set; then : enableval=$enable_largefile; fi if test "$enable_largefile" != no; then { $as_echo "$as_me:${as_lineno-$LINENO}: checking for special C compiler options needed for large files" >&5 $as_echo_n "checking for special C compiler options needed for large files... " >&6; } if ${ac_cv_sys_largefile_CC+:} false; then : $as_echo_n "(cached) " >&6 else 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. cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include /* 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]; int main () { ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : break fi rm -f core conftest.err conftest.$ac_objext CC="$CC -n32" if ac_fn_c_try_compile "$LINENO"; then : ac_cv_sys_largefile_CC=' -n32'; break fi rm -f core conftest.err conftest.$ac_objext break done CC=$ac_save_CC rm -f conftest.$ac_ext fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_sys_largefile_CC" >&5 $as_echo "$ac_cv_sys_largefile_CC" >&6; } if test "$ac_cv_sys_largefile_CC" != no; then CC=$CC$ac_cv_sys_largefile_CC fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for _FILE_OFFSET_BITS value needed for large files" >&5 $as_echo_n "checking for _FILE_OFFSET_BITS value needed for large files... " >&6; } if ${ac_cv_sys_file_offset_bits+:} false; then : $as_echo_n "(cached) " >&6 else while :; do cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include /* 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]; int main () { ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : ac_cv_sys_file_offset_bits=no; break fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #define _FILE_OFFSET_BITS 64 #include /* 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]; int main () { ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : ac_cv_sys_file_offset_bits=64; break fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext ac_cv_sys_file_offset_bits=unknown break done fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_sys_file_offset_bits" >&5 $as_echo "$ac_cv_sys_file_offset_bits" >&6; } case $ac_cv_sys_file_offset_bits in #( no | unknown) ;; *) cat >>confdefs.h <<_ACEOF #define _FILE_OFFSET_BITS $ac_cv_sys_file_offset_bits _ACEOF ;; esac rm -rf conftest* if test $ac_cv_sys_file_offset_bits = unknown; then { $as_echo "$as_me:${as_lineno-$LINENO}: checking for _LARGE_FILES value needed for large files" >&5 $as_echo_n "checking for _LARGE_FILES value needed for large files... " >&6; } if ${ac_cv_sys_large_files+:} false; then : $as_echo_n "(cached) " >&6 else while :; do cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include /* 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]; int main () { ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : ac_cv_sys_large_files=no; break fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #define _LARGE_FILES 1 #include /* 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]; int main () { ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : ac_cv_sys_large_files=1; break fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext ac_cv_sys_large_files=unknown break done fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_sys_large_files" >&5 $as_echo "$ac_cv_sys_large_files" >&6; } case $ac_cv_sys_large_files in #( no | unknown) ;; *) cat >>confdefs.h <<_ACEOF #define _LARGE_FILES $ac_cv_sys_large_files _ACEOF ;; esac rm -rf conftest* fi fi ac_fn_c_check_func "$LINENO" "daemon" "ac_cv_func_daemon" if test "x$ac_cv_func_daemon" = xyes; then : $as_echo "#define HAVE_DAEMON 1" >>confdefs.h else case " $LIBOBJS " in *" daemon.$ac_objext "* ) ;; *) LIBOBJS="$LIBOBJS daemon.$ac_objext" ;; esac fi ac_fn_c_check_func "$LINENO" "futimes" "ac_cv_func_futimes" if test "x$ac_cv_func_futimes" = xyes; then : $as_echo "#define HAVE_FUTIMES 1" >>confdefs.h else case " $LIBOBJS " in *" futimes.$ac_objext "* ) ;; *) LIBOBJS="$LIBOBJS futimes.$ac_objext" ;; esac fi for ac_func in futimesat getaddrinfo prctl do : as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var" if eval test \"x\$"$as_ac_var"\" = x"yes"; then : cat >>confdefs.h <<_ACEOF #define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1 _ACEOF fi done ac_fn_c_check_decl "$LINENO" "be64toh" "ac_cv_have_decl_be64toh" "$ac_includes_default" if test "x$ac_cv_have_decl_be64toh" = xyes; then : ac_have_decl=1 else ac_have_decl=0 fi cat >>confdefs.h <<_ACEOF #define HAVE_DECL_BE64TOH $ac_have_decl _ACEOF ac_fn_c_check_decl "$LINENO" "htobe64" "ac_cv_have_decl_htobe64" "$ac_includes_default" if test "x$ac_cv_have_decl_htobe64" = xyes; then : ac_have_decl=1 else ac_have_decl=0 fi cat >>confdefs.h <<_ACEOF #define HAVE_DECL_HTOBE64 $ac_have_decl _ACEOF { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether byte ordering is bigendian" >&5 $as_echo_n "checking whether byte ordering is bigendian... " >&6; } if ${ac_cv_c_bigendian+:} false; then : $as_echo_n "(cached) " >&6 else ac_cv_c_bigendian=unknown # See if we're dealing with a universal compiler. cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #ifndef __APPLE_CC__ not a universal capable compiler #endif typedef int dummy; _ACEOF if ac_fn_c_try_compile "$LINENO"; then : # Check for potential -arch flags. It is not universal unless # there are at least two -arch flags with different values. ac_arch= ac_prev= for ac_word in $CC $CFLAGS $CPPFLAGS $LDFLAGS; do if test -n "$ac_prev"; then case $ac_word in i?86 | x86_64 | ppc | ppc64) if test -z "$ac_arch" || test "$ac_arch" = "$ac_word"; then ac_arch=$ac_word else ac_cv_c_bigendian=universal break fi ;; esac ac_prev= elif test "x$ac_word" = "x-arch"; then ac_prev=arch fi done fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext if test $ac_cv_c_bigendian = unknown; then # See if sys/param.h defines the BYTE_ORDER macro. cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include #include int main () { #if ! (defined BYTE_ORDER && defined BIG_ENDIAN \ && defined LITTLE_ENDIAN && BYTE_ORDER && BIG_ENDIAN \ && LITTLE_ENDIAN) bogus endian macros #endif ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : # It does; now see whether it defined to BIG_ENDIAN or not. cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include #include int main () { #if BYTE_ORDER != BIG_ENDIAN not big endian #endif ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : ac_cv_c_bigendian=yes else ac_cv_c_bigendian=no fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi if test $ac_cv_c_bigendian = unknown; then # See if defines _LITTLE_ENDIAN or _BIG_ENDIAN (e.g., Solaris). cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include int main () { #if ! (defined _LITTLE_ENDIAN || defined _BIG_ENDIAN) bogus endian macros #endif ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : # It does; now see whether it defined to _BIG_ENDIAN or not. cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include int main () { #ifndef _BIG_ENDIAN not big endian #endif ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : ac_cv_c_bigendian=yes else ac_cv_c_bigendian=no fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi if test $ac_cv_c_bigendian = unknown; then # Compile a test program. if test "$cross_compiling" = yes; then : # Try to guess by grepping values from an object file. cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ short int ascii_mm[] = { 0x4249, 0x4765, 0x6E44, 0x6961, 0x6E53, 0x7953, 0 }; short int ascii_ii[] = { 0x694C, 0x5454, 0x656C, 0x6E45, 0x6944, 0x6E61, 0 }; int use_ascii (int i) { return ascii_mm[i] + ascii_ii[i]; } short int ebcdic_ii[] = { 0x89D3, 0xE3E3, 0x8593, 0x95C5, 0x89C4, 0x9581, 0 }; short int ebcdic_mm[] = { 0xC2C9, 0xC785, 0x95C4, 0x8981, 0x95E2, 0xA8E2, 0 }; int use_ebcdic (int i) { return ebcdic_mm[i] + ebcdic_ii[i]; } extern int foo; int main () { return use_ascii (foo) == use_ebcdic (foo); ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : if grep BIGenDianSyS conftest.$ac_objext >/dev/null; then ac_cv_c_bigendian=yes fi if grep LiTTleEnDian conftest.$ac_objext >/dev/null ; then if test "$ac_cv_c_bigendian" = unknown; then ac_cv_c_bigendian=no else # finding both strings is unlikely to happen, but who knows? ac_cv_c_bigendian=unknown fi fi fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $ac_includes_default int main () { /* Are we little or big endian? From Harbison&Steele. */ union { long int l; char c[sizeof (long int)]; } u; u.l = 1; return u.c[sizeof (long int) - 1] == 1; ; return 0; } _ACEOF if ac_fn_c_try_run "$LINENO"; then : ac_cv_c_bigendian=no else ac_cv_c_bigendian=yes fi rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ conftest.$ac_objext conftest.beam conftest.$ac_ext fi fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_bigendian" >&5 $as_echo "$ac_cv_c_bigendian" >&6; } case $ac_cv_c_bigendian in #( yes) $as_echo "#define WORDS_BIGENDIAN 1" >>confdefs.h ;; #( no) ;; #( universal) $as_echo "#define AC_APPLE_UNIVERSAL_BUILD 1" >>confdefs.h ;; #( *) as_fn_error $? "unknown endianness presetting ac_cv_c_bigendian=no (or yes) will help" "$LINENO" 5 ;; esac # The cast to long int works around a bug in the HP C Compiler # version HP92453-01 B.11.11.23709.GP, which incorrectly rejects # declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'. # This bug is HP SR number 8606223364. { $as_echo "$as_me:${as_lineno-$LINENO}: checking size of unsigned short" >&5 $as_echo_n "checking size of unsigned short... " >&6; } if ${ac_cv_sizeof_unsigned_short+:} false; then : $as_echo_n "(cached) " >&6 else if ac_fn_c_compute_int "$LINENO" "(long int) (sizeof (unsigned short))" "ac_cv_sizeof_unsigned_short" "$ac_includes_default"; then : else if test "$ac_cv_type_unsigned_short" = yes; then { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error 77 "cannot compute sizeof (unsigned short) See \`config.log' for more details" "$LINENO" 5; } else ac_cv_sizeof_unsigned_short=0 fi fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_sizeof_unsigned_short" >&5 $as_echo "$ac_cv_sizeof_unsigned_short" >&6; } cat >>confdefs.h <<_ACEOF #define SIZEOF_UNSIGNED_SHORT $ac_cv_sizeof_unsigned_short _ACEOF # The cast to long int works around a bug in the HP C Compiler # version HP92453-01 B.11.11.23709.GP, which incorrectly rejects # declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'. # This bug is HP SR number 8606223364. { $as_echo "$as_me:${as_lineno-$LINENO}: checking size of unsigned int" >&5 $as_echo_n "checking size of unsigned int... " >&6; } if ${ac_cv_sizeof_unsigned_int+:} false; then : $as_echo_n "(cached) " >&6 else if ac_fn_c_compute_int "$LINENO" "(long int) (sizeof (unsigned int))" "ac_cv_sizeof_unsigned_int" "$ac_includes_default"; then : else if test "$ac_cv_type_unsigned_int" = yes; then { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error 77 "cannot compute sizeof (unsigned int) See \`config.log' for more details" "$LINENO" 5; } else ac_cv_sizeof_unsigned_int=0 fi fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_sizeof_unsigned_int" >&5 $as_echo "$ac_cv_sizeof_unsigned_int" >&6; } cat >>confdefs.h <<_ACEOF #define SIZEOF_UNSIGNED_INT $ac_cv_sizeof_unsigned_int _ACEOF # The cast to long int works around a bug in the HP C Compiler # version HP92453-01 B.11.11.23709.GP, which incorrectly rejects # declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'. # This bug is HP SR number 8606223364. { $as_echo "$as_me:${as_lineno-$LINENO}: checking size of unsigned long" >&5 $as_echo_n "checking size of unsigned long... " >&6; } if ${ac_cv_sizeof_unsigned_long+:} false; then : $as_echo_n "(cached) " >&6 else if ac_fn_c_compute_int "$LINENO" "(long int) (sizeof (unsigned long))" "ac_cv_sizeof_unsigned_long" "$ac_includes_default"; then : else if test "$ac_cv_type_unsigned_long" = yes; then { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error 77 "cannot compute sizeof (unsigned long) See \`config.log' for more details" "$LINENO" 5; } else ac_cv_sizeof_unsigned_long=0 fi fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_sizeof_unsigned_long" >&5 $as_echo "$ac_cv_sizeof_unsigned_long" >&6; } cat >>confdefs.h <<_ACEOF #define SIZEOF_UNSIGNED_LONG $ac_cv_sizeof_unsigned_long _ACEOF # The cast to long int works around a bug in the HP C Compiler # version HP92453-01 B.11.11.23709.GP, which incorrectly rejects # declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'. # This bug is HP SR number 8606223364. { $as_echo "$as_me:${as_lineno-$LINENO}: checking size of unsigned long long" >&5 $as_echo_n "checking size of unsigned long long... " >&6; } if ${ac_cv_sizeof_unsigned_long_long+:} false; then : $as_echo_n "(cached) " >&6 else if ac_fn_c_compute_int "$LINENO" "(long int) (sizeof (unsigned long long))" "ac_cv_sizeof_unsigned_long_long" "$ac_includes_default"; then : else if test "$ac_cv_type_unsigned_long_long" = yes; then { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error 77 "cannot compute sizeof (unsigned long long) See \`config.log' for more details" "$LINENO" 5; } else ac_cv_sizeof_unsigned_long_long=0 fi fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_sizeof_unsigned_long_long" >&5 $as_echo "$ac_cv_sizeof_unsigned_long_long" >&6; } cat >>confdefs.h <<_ACEOF #define SIZEOF_UNSIGNED_LONG_LONG $ac_cv_sizeof_unsigned_long_long _ACEOF # The cast to long int works around a bug in the HP C Compiler # version HP92453-01 B.11.11.23709.GP, which incorrectly rejects # declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'. # This bug is HP SR number 8606223364. { $as_echo "$as_me:${as_lineno-$LINENO}: checking size of size_t" >&5 $as_echo_n "checking size of size_t... " >&6; } if ${ac_cv_sizeof_size_t+:} false; then : $as_echo_n "(cached) " >&6 else if ac_fn_c_compute_int "$LINENO" "(long int) (sizeof (size_t))" "ac_cv_sizeof_size_t" "$ac_includes_default"; then : else if test "$ac_cv_type_size_t" = yes; then { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error 77 "cannot compute sizeof (size_t) See \`config.log' for more details" "$LINENO" 5; } else ac_cv_sizeof_size_t=0 fi fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_sizeof_size_t" >&5 $as_echo "$ac_cv_sizeof_size_t" >&6; } cat >>confdefs.h <<_ACEOF #define SIZEOF_SIZE_T $ac_cv_sizeof_size_t _ACEOF for ac_header in stdint.h do : ac_fn_c_check_header_mongrel "$LINENO" "stdint.h" "ac_cv_header_stdint_h" "$ac_includes_default" if test "x$ac_cv_header_stdint_h" = xyes; then : cat >>confdefs.h <<_ACEOF #define HAVE_STDINT_H 1 _ACEOF fi done { $as_echo "$as_me:${as_lineno-$LINENO}: checking for SIZE_MAX" >&5 $as_echo_n "checking for SIZE_MAX... " >&6; } if ${rjk_cv_size_max+:} false; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include #include #if HAVE_STDINT_H # include #endif int main () { size_t x = SIZE_MAX;++x; ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : rjk_cv_size_max=yes else rjk_cv_size_max=no fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $rjk_cv_size_max" >&5 $as_echo "$rjk_cv_size_max" >&6; } if test "$rjk_cv_size_max" = yes; then $as_echo "#define HAVE_SIZE_MAX 1" >>confdefs.h fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ${CC} warning options" >&5 $as_echo_n "checking for ${CC} warning options... " >&6; } if ${rjk_cv_ccwarnings+:} false; then : $as_echo_n "(cached) " >&6 else if test "$GCC" = yes; then rjk_cv_ccwarnings="-Wall -W -Wpointer-arith -Wbad-function-cast \ -Wwrite-strings -Wmissing-prototypes \ -Wmissing-declarations -Wnested-externs" else rjk_cv_ccwarnings="unknown" fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $rjk_cv_ccwarnings" >&5 $as_echo "$rjk_cv_ccwarnings" >&6; } { $as_echo "$as_me:${as_lineno-$LINENO}: checking how to make ${CC} treat warnings as errors" >&5 $as_echo_n "checking how to make ${CC} treat warnings as errors... " >&6; } if ${rjk_cv_ccwerror+:} false; then : $as_echo_n "(cached) " >&6 else if test "$GCC" = yes; then rjk_cv_ccwerror="-Werror" else rjk_cv_ccwerror="unknown" fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $rjk_cv_ccwerror" >&5 $as_echo "$rjk_cv_ccwerror" >&6; } { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to enable compiler warnings" >&5 $as_echo_n "checking whether to enable compiler warnings... " >&6; } # Check whether --enable-warnings was given. if test "${enable_warnings+set}" = set; then : enableval=$enable_warnings; warnings="$enableval" else warnings=yes fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $warnings" >&5 $as_echo "$warnings" >&6; } { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to treat warnings as errors" >&5 $as_echo_n "checking whether to treat warnings as errors... " >&6; } # Check whether --enable-warnings-as-errors was given. if test "${enable_warnings_as_errors+set}" = set; then : enableval=$enable_warnings_as_errors; warnings_as_errors="$enableval" else warnings_as_errors=no fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $warnings_as_errors" >&5 $as_echo "$warnings_as_errors" >&6; } if test "$warnings" = yes && test "$rjk_cv_ccwarnings" != unknown; then CC="${CC} $rjk_cv_ccwarnings" fi if test "$warnings_as_errors" = yes && test "$rjk_cv_ccwerror" != unknown; then CC="${CC} $rjk_cv_ccwerror" fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether macros produce warnings" >&5 $as_echo_n "checking whether macros produce warnings... " >&6; } if ${rjk_cv_inttypeswarnings+:} false; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include #include #include int main () { uint64_t x=0;size_t sz=0;printf("%"PRIu64" %zu\n", x, sz); ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : rjk_cv_inttypeswarnings=no else rjk_cv_inttypeswarnings=yes fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $rjk_cv_inttypeswarnings" >&5 $as_echo "$rjk_cv_inttypeswarnings" >&6; } if test $rjk_cv_inttypeswarnings = yes && test "$GCC" = yes; then CC="${CC} -Wno-format" fi ac_fn_c_check_member "$LINENO" "struct stat" "st_atimespec" "ac_cv_member_struct_stat_st_atimespec" "#include " if test "x$ac_cv_member_struct_stat_st_atimespec" = xyes; then : $as_echo "#define HAVE_STAT_TIMESPEC 1" >>confdefs.h else rjk_cv_stat_timespec=no fi ac_fn_c_check_func "$LINENO" "getopt_long" "ac_cv_func_getopt_long" if test "x$ac_cv_func_getopt_long" = xyes; then : else case " $LIBOBJS " in *" getopt.$ac_objext "* ) ;; *) LIBOBJS="$LIBOBJS getopt.$ac_objext" ;; esac case " $LIBOBJS " in *" getopt1.$ac_objext "* ) ;; *) LIBOBJS="$LIBOBJS getopt1.$ac_objext" ;; esac fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for Python 2.4 or better" >&5 $as_echo_n "checking for Python 2.4 or better... " >&6; } if ${rjk_cv_python24+:} false; then : $as_echo_n "(cached) " >&6 else if python24 -V >/dev/null 2>&1; then rjk_cv_python24=python24 elif python2.4 -V >/dev/null 2>&1; then rjk_cv_python24=python2.4 elif python -V >confpyver 2>&1; then read p v < confpyver case "$v" in 1* | 2.0* | 2.1* | 2.2* | 2.3* ) ;; * ) rjk_cv_python24=python ;; esac fi rm -f confpyver if test "$rjk_cv_python24" = ""; then as_fn_error $? "cannot find Python 2.4 or better" "$LINENO" 5 fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $rjk_cv_python24" >&5 $as_echo "$rjk_cv_python24" >&6; } PYTHON24=$rjk_cv_python24 { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to reverse SSH_FXP_SYMLINK arguments" >&5 $as_echo_n "checking whether to reverse SSH_FXP_SYMLINK arguments... " >&6; } # Check whether --enable-reversed-symlink was given. if test "${enable_reversed_symlink+set}" = set; then : enableval=$enable_reversed_symlink; revlink="$enableval" else revlink=no fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $revlink" >&5 $as_echo "$revlink" >&6; } if test $revlink = yes; then $as_echo "#define REVERSE_SYMLINK 1" >>confdefs.h fi # Check whether --enable-daemon was given. if test "${enable_daemon+set}" = set; then : enableval=$enable_daemon; daemon="$enableval" else daemon=no fi if test $daemon = yes; then $as_echo "#define DAEMON 1" >>confdefs.h fi GCOV=${GCOV:-true} # Check whether --with-gcov was given. if test "${with_gcov+set}" = set; then : withval=$with_gcov; if test $withval = yes; then CFLAGS="${CFLAGS} -O0 -fprofile-arcs -ftest-coverage" GCOV=`echo $CC | sed s'/gcc/gcov/;s/ .*$//'`; fi fi GCOV=$GCOV ac_config_files="$ac_config_files Makefile" cat >confcache <<\_ACEOF # This file is a shell script that caches the results of configure # tests run on this system so they can be shared between configure # scripts and configure runs, see configure's option --config-cache. # It is not useful on other systems. If it contains results you don't # want to keep, you may remove or edit it. # # config.status only pays attention to the cache file if you give it # the --recheck option to rerun configure. # # `ac_cv_env_foo' variables (set or unset) will be overridden when # loading this file, other *unset* `ac_cv_foo' will be assigned the # following values. _ACEOF # The following way of writing the cache mishandles newlines in values, # but we know of no workaround that is simple, portable, and efficient. # So, we kill variables containing newlines. # Ultrix sh set writes to stderr and can't be redirected directly, # and sets the high bit in the cache file unless we assign to the vars. ( for ac_var in `(set) 2>&1 | sed -n 's/^\([a-zA-Z_][a-zA-Z0-9_]*\)=.*/\1/p'`; do eval ac_val=\$$ac_var case $ac_val in #( *${as_nl}*) case $ac_var in #( *_cv_*) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline" >&5 $as_echo "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;; esac case $ac_var in #( _ | IFS | as_nl) ;; #( BASH_ARGV | BASH_SOURCE) eval $ac_var= ;; #( *) { eval $ac_var=; unset $ac_var;} ;; esac ;; esac done (set) 2>&1 | case $as_nl`(ac_space=' '; set) 2>&1` in #( *${as_nl}ac_space=\ *) # `set' does not quote correctly, so add quotes: double-quote # substitution turns \\\\ into \\, and sed turns \\ into \. sed -n \ "s/'/'\\\\''/g; s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\\2'/p" ;; #( *) # `set' quotes correctly as required by POSIX, so do not add quotes. sed -n "/^[_$as_cr_alnum]*_cv_[_$as_cr_alnum]*=/p" ;; esac | sort ) | sed ' /^ac_cv_env_/b end t clear :clear s/^\([^=]*\)=\(.*[{}].*\)$/test "${\1+set}" = set || &/ t end s/^\([^=]*\)=\(.*\)$/\1=${\1=\2}/ :end' >>confcache if diff "$cache_file" confcache >/dev/null 2>&1; then :; else if test -w "$cache_file"; then if test "x$cache_file" != "x/dev/null"; then { $as_echo "$as_me:${as_lineno-$LINENO}: updating cache $cache_file" >&5 $as_echo "$as_me: updating cache $cache_file" >&6;} if test ! -f "$cache_file" || test -h "$cache_file"; then cat confcache >"$cache_file" else case $cache_file in #( */* | ?:*) mv -f confcache "$cache_file"$$ && mv -f "$cache_file"$$ "$cache_file" ;; #( *) mv -f confcache "$cache_file" ;; esac fi fi else { $as_echo "$as_me:${as_lineno-$LINENO}: not updating unwritable cache $cache_file" >&5 $as_echo "$as_me: not updating unwritable cache $cache_file" >&6;} fi fi rm -f confcache test "x$prefix" = xNONE && prefix=$ac_default_prefix # Let make expand exec_prefix. test "x$exec_prefix" = xNONE && exec_prefix='${prefix}' DEFS=-DHAVE_CONFIG_H ac_libobjs= ac_ltlibobjs= U= for ac_i in : $LIBOBJS; do test "x$ac_i" = x: && continue # 1. Remove the extension, and $U if already installed. ac_script='s/\$U\././;s/\.o$//;s/\.obj$//' ac_i=`$as_echo "$ac_i" | sed "$ac_script"` # 2. Prepend LIBOBJDIR. When used with automake>=1.10 LIBOBJDIR # will be set to the directory where LIBOBJS objects are built. as_fn_append ac_libobjs " \${LIBOBJDIR}$ac_i\$U.$ac_objext" as_fn_append ac_ltlibobjs " \${LIBOBJDIR}$ac_i"'$U.lo' done LIBOBJS=$ac_libobjs LTLIBOBJS=$ac_ltlibobjs if test -n "$EXEEXT"; then am__EXEEXT_TRUE= am__EXEEXT_FALSE='#' else am__EXEEXT_TRUE='#' am__EXEEXT_FALSE= fi if test -z "${AMDEP_TRUE}" && test -z "${AMDEP_FALSE}"; then as_fn_error $? "conditional \"AMDEP\" was never defined. Usually this means the macro was only invoked conditionally." "$LINENO" 5 fi if test -z "${am__fastdepCC_TRUE}" && test -z "${am__fastdepCC_FALSE}"; then as_fn_error $? "conditional \"am__fastdepCC\" was never defined. Usually this means the macro was only invoked conditionally." "$LINENO" 5 fi : "${CONFIG_STATUS=./config.status}" ac_write_fail=0 ac_clean_files_save=$ac_clean_files ac_clean_files="$ac_clean_files $CONFIG_STATUS" { $as_echo "$as_me:${as_lineno-$LINENO}: creating $CONFIG_STATUS" >&5 $as_echo "$as_me: creating $CONFIG_STATUS" >&6;} as_write_fail=0 cat >$CONFIG_STATUS <<_ASEOF || as_write_fail=1 #! $SHELL # Generated by $as_me. # Run this file to recreate the current configuration. # Compiler output produced by configure, useful for debugging # configure, is in config.log if it exists. debug=false ac_cs_recheck=false ac_cs_silent=false SHELL=\${CONFIG_SHELL-$SHELL} export SHELL _ASEOF cat >>$CONFIG_STATUS <<\_ASEOF || as_write_fail=1 ## -------------------- ## ## M4sh Initialization. ## ## -------------------- ## # Be more Bourne compatible DUALCASE=1; export DUALCASE # for MKS sh if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then : emulate sh NULLCMD=: # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which # is contrary to our usage. Disable this feature. alias -g '${1+"$@"}'='"$@"' setopt NO_GLOB_SUBST else case `(set -o) 2>/dev/null` in #( *posix*) : set -o posix ;; #( *) : ;; esac fi as_nl=' ' export as_nl # Printing a long string crashes Solaris 7 /usr/bin/printf. as_echo='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\' as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo$as_echo # Prefer a ksh shell builtin over an external printf program on Solaris, # but without wasting forks for bash or zsh. if test -z "$BASH_VERSION$ZSH_VERSION" \ && (test "X`print -r -- $as_echo`" = "X$as_echo") 2>/dev/null; then as_echo='print -r --' as_echo_n='print -rn --' elif (test "X`printf %s $as_echo`" = "X$as_echo") 2>/dev/null; then as_echo='printf %s\n' as_echo_n='printf %s' else if test "X`(/usr/ucb/echo -n -n $as_echo) 2>/dev/null`" = "X-n $as_echo"; then as_echo_body='eval /usr/ucb/echo -n "$1$as_nl"' as_echo_n='/usr/ucb/echo -n' else as_echo_body='eval expr "X$1" : "X\\(.*\\)"' as_echo_n_body='eval arg=$1; case $arg in #( *"$as_nl"*) expr "X$arg" : "X\\(.*\\)$as_nl"; arg=`expr "X$arg" : ".*$as_nl\\(.*\\)"`;; esac; expr "X$arg" : "X\\(.*\\)" | tr -d "$as_nl" ' export as_echo_n_body as_echo_n='sh -c $as_echo_n_body as_echo' fi export as_echo_body as_echo='sh -c $as_echo_body as_echo' fi # The user is always right. if test "${PATH_SEPARATOR+set}" != set; then PATH_SEPARATOR=: (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && { (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 || PATH_SEPARATOR=';' } fi # IFS # We need space, tab and new line, in precisely that order. Quoting is # there to prevent editors from complaining about space-tab. # (If _AS_PATH_WALK were called with IFS unset, it would disable word # splitting by setting IFS to empty value.) IFS=" "" $as_nl" # Find who we are. Look in the path if we contain no directory separator. as_myself= case $0 in #(( *[\\/]* ) as_myself=$0 ;; *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break done IFS=$as_save_IFS ;; esac # We did not find ourselves, most probably we were run as `sh COMMAND' # in which case we are not to be found in the path. if test "x$as_myself" = x; then as_myself=$0 fi if test ! -f "$as_myself"; then $as_echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2 exit 1 fi # Unset variables that we do not need and which cause bugs (e.g. in # pre-3.0 UWIN ksh). But do not cause bugs in bash 2.01; the "|| exit 1" # suppresses any "Segmentation fault" message there. '((' could # trigger a bug in pdksh 5.2.14. for as_var in BASH_ENV ENV MAIL MAILPATH do eval test x\${$as_var+set} = xset \ && ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || : done PS1='$ ' PS2='> ' PS4='+ ' # NLS nuisances. LC_ALL=C export LC_ALL LANGUAGE=C export LANGUAGE # CDPATH. (unset CDPATH) >/dev/null 2>&1 && unset CDPATH # as_fn_error STATUS ERROR [LINENO LOG_FD] # ---------------------------------------- # Output "`basename $0`: error: ERROR" to stderr. If LINENO and LOG_FD are # provided, also output the error to LOG_FD, referencing LINENO. Then exit the # script with STATUS, using 1 if that was 0. as_fn_error () { as_status=$1; test $as_status -eq 0 && as_status=1 if test "$4"; then as_lineno=${as_lineno-"$3"} as_lineno_stack=as_lineno_stack=$as_lineno_stack $as_echo "$as_me:${as_lineno-$LINENO}: error: $2" >&$4 fi $as_echo "$as_me: error: $2" >&2 as_fn_exit $as_status } # as_fn_error # as_fn_set_status STATUS # ----------------------- # Set $? to STATUS, without forking. as_fn_set_status () { return $1 } # as_fn_set_status # as_fn_exit STATUS # ----------------- # Exit the shell with STATUS, even in a "trap 0" or "set -e" context. as_fn_exit () { set +e as_fn_set_status $1 exit $1 } # as_fn_exit # as_fn_unset VAR # --------------- # Portably unset VAR. as_fn_unset () { { eval $1=; unset $1;} } as_unset=as_fn_unset # as_fn_append VAR VALUE # ---------------------- # Append the text in VALUE to the end of the definition contained in VAR. Take # advantage of any shell optimizations that allow amortized linear growth over # repeated appends, instead of the typical quadratic growth present in naive # implementations. if (eval "as_var=1; as_var+=2; test x\$as_var = x12") 2>/dev/null; then : eval 'as_fn_append () { eval $1+=\$2 }' else as_fn_append () { eval $1=\$$1\$2 } fi # as_fn_append # as_fn_arith ARG... # ------------------ # Perform arithmetic evaluation on the ARGs, and store the result in the # global $as_val. Take advantage of shells that can avoid forks. The arguments # must be portable across $(()) and expr. if (eval "test \$(( 1 + 1 )) = 2") 2>/dev/null; then : eval 'as_fn_arith () { as_val=$(( $* )) }' else as_fn_arith () { as_val=`expr "$@" || test $? -eq 1` } fi # as_fn_arith if expr a : '\(a\)' >/dev/null 2>&1 && test "X`expr 00001 : '.*\(...\)'`" = X001; then as_expr=expr else as_expr=false fi if (basename -- /) >/dev/null 2>&1 && test "X`basename -- / 2>&1`" = "X/"; then as_basename=basename else as_basename=false fi if (as_dir=`dirname -- /` && test "X$as_dir" = X/) >/dev/null 2>&1; then as_dirname=dirname else as_dirname=false fi as_me=`$as_basename -- "$0" || $as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \ X"$0" : 'X\(//\)$' \| \ X"$0" : 'X\(/\)' \| . 2>/dev/null || $as_echo X/"$0" | sed '/^.*\/\([^/][^/]*\)\/*$/{ s//\1/ q } /^X\/\(\/\/\)$/{ s//\1/ q } /^X\/\(\/\).*/{ s//\1/ q } s/.*/./; q'` # Avoid depending upon Character Ranges. as_cr_letters='abcdefghijklmnopqrstuvwxyz' as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ' as_cr_Letters=$as_cr_letters$as_cr_LETTERS as_cr_digits='0123456789' as_cr_alnum=$as_cr_Letters$as_cr_digits ECHO_C= ECHO_N= ECHO_T= case `echo -n x` in #((((( -n*) case `echo 'xy\c'` in *c*) ECHO_T=' ';; # ECHO_T is single tab character. xy) ECHO_C='\c';; *) echo `echo ksh88 bug on AIX 6.1` > /dev/null ECHO_T=' ';; esac;; *) ECHO_N='-n';; esac rm -f conf$$ conf$$.exe conf$$.file if test -d conf$$.dir; then rm -f conf$$.dir/conf$$.file else rm -f conf$$.dir mkdir conf$$.dir 2>/dev/null fi if (echo >conf$$.file) 2>/dev/null; then if ln -s conf$$.file conf$$ 2>/dev/null; then as_ln_s='ln -s' # ... but there are two gotchas: # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail. # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable. # In both cases, we have to default to `cp -pR'. ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe || as_ln_s='cp -pR' elif ln conf$$.file conf$$ 2>/dev/null; then as_ln_s=ln else as_ln_s='cp -pR' fi else as_ln_s='cp -pR' fi rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file rmdir conf$$.dir 2>/dev/null # as_fn_mkdir_p # ------------- # Create "$as_dir" as a directory, including parents if necessary. as_fn_mkdir_p () { case $as_dir in #( -*) as_dir=./$as_dir;; esac test -d "$as_dir" || eval $as_mkdir_p || { as_dirs= while :; do case $as_dir in #( *\'*) as_qdir=`$as_echo "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'( *) as_qdir=$as_dir;; esac as_dirs="'$as_qdir' $as_dirs" as_dir=`$as_dirname -- "$as_dir" || $as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ X"$as_dir" : 'X\(//\)[^/]' \| \ X"$as_dir" : 'X\(//\)$' \| \ X"$as_dir" : 'X\(/\)' \| . 2>/dev/null || $as_echo X"$as_dir" | sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/ q } /^X\(\/\/\)[^/].*/{ s//\1/ q } /^X\(\/\/\)$/{ s//\1/ q } /^X\(\/\).*/{ s//\1/ q } s/.*/./; q'` test -d "$as_dir" && break done test -z "$as_dirs" || eval "mkdir $as_dirs" } || test -d "$as_dir" || as_fn_error $? "cannot create directory $as_dir" } # as_fn_mkdir_p if mkdir -p . 2>/dev/null; then as_mkdir_p='mkdir -p "$as_dir"' else test -d ./-p && rmdir ./-p as_mkdir_p=false fi # as_fn_executable_p FILE # ----------------------- # Test if FILE is an executable regular file. as_fn_executable_p () { test -f "$1" && test -x "$1" } # as_fn_executable_p as_test_x='test -x' as_executable_p=as_fn_executable_p # Sed expression to map a string onto a valid CPP name. as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'" # Sed expression to map a string onto a valid variable name. as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'" exec 6>&1 ## ----------------------------------- ## ## Main body of $CONFIG_STATUS script. ## ## ----------------------------------- ## _ASEOF test $as_write_fail = 0 && chmod +x $CONFIG_STATUS || ac_write_fail=1 cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # Save the log message, to keep $0 and so on meaningful, and to # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" This file was extended by sftpserver $as_me 0.2.1, which was generated by GNU Autoconf 2.69. Invocation command line was CONFIG_FILES = $CONFIG_FILES CONFIG_HEADERS = $CONFIG_HEADERS CONFIG_LINKS = $CONFIG_LINKS CONFIG_COMMANDS = $CONFIG_COMMANDS $ $0 $@ on `(hostname || uname -n) 2>/dev/null | sed 1q` " _ACEOF case $ac_config_files in *" "*) set x $ac_config_files; shift; ac_config_files=$*;; esac case $ac_config_headers in *" "*) set x $ac_config_headers; shift; ac_config_headers=$*;; esac cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 # Files that config.status was made for. config_files="$ac_config_files" config_headers="$ac_config_headers" config_commands="$ac_config_commands" _ACEOF cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 ac_cs_usage="\ \`$as_me' instantiates files and other configuration actions from templates according to the current configuration. Unless the files and actions are specified as TAGs, all are instantiated by default. Usage: $0 [OPTION]... [TAG]... -h, --help print this help, then exit -V, --version print version number and configuration settings, then exit --config print configuration, then exit -q, --quiet, --silent do not print progress messages -d, --debug don't remove temporary files --recheck update $as_me by reconfiguring in the same conditions --file=FILE[:TEMPLATE] instantiate the configuration file FILE --header=FILE[:TEMPLATE] instantiate the configuration header FILE Configuration files: $config_files Configuration headers: $config_headers Configuration commands: $config_commands Report bugs to ." _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" ac_cs_version="\\ sftpserver config.status 0.2.1 configured by $0, generated by GNU Autoconf 2.69, with options \\"\$ac_cs_config\\" Copyright (C) 2012 Free Software Foundation, Inc. This config.status script is free software; the Free Software Foundation gives unlimited permission to copy, distribute and modify it." ac_pwd='$ac_pwd' srcdir='$srcdir' INSTALL='$INSTALL' MKDIR_P='$MKDIR_P' AWK='$AWK' test -n "\$AWK" || AWK=awk _ACEOF cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # The default lists apply if the user does not specify any file. ac_need_defaults=: while test $# != 0 do case $1 in --*=?*) ac_option=`expr "X$1" : 'X\([^=]*\)='` ac_optarg=`expr "X$1" : 'X[^=]*=\(.*\)'` ac_shift=: ;; --*=) ac_option=`expr "X$1" : 'X\([^=]*\)='` ac_optarg= ac_shift=: ;; *) ac_option=$1 ac_optarg=$2 ac_shift=shift ;; esac case $ac_option in # Handling of the options. -recheck | --recheck | --rechec | --reche | --rech | --rec | --re | --r) ac_cs_recheck=: ;; --version | --versio | --versi | --vers | --ver | --ve | --v | -V ) $as_echo "$ac_cs_version"; exit ;; --config | --confi | --conf | --con | --co | --c ) $as_echo "$ac_cs_config"; exit ;; --debug | --debu | --deb | --de | --d | -d ) debug=: ;; --file | --fil | --fi | --f ) $ac_shift case $ac_optarg in *\'*) ac_optarg=`$as_echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"` ;; '') as_fn_error $? "missing file argument" ;; esac as_fn_append CONFIG_FILES " '$ac_optarg'" ac_need_defaults=false;; --header | --heade | --head | --hea ) $ac_shift case $ac_optarg in *\'*) ac_optarg=`$as_echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"` ;; esac as_fn_append CONFIG_HEADERS " '$ac_optarg'" ac_need_defaults=false;; --he | --h) # Conflict between --help and --header as_fn_error $? "ambiguous option: \`$1' Try \`$0 --help' for more information.";; --help | --hel | -h ) $as_echo "$ac_cs_usage"; exit ;; -q | -quiet | --quiet | --quie | --qui | --qu | --q \ | -silent | --silent | --silen | --sile | --sil | --si | --s) ac_cs_silent=: ;; # This is an error. -*) as_fn_error $? "unrecognized option: \`$1' Try \`$0 --help' for more information." ;; *) as_fn_append ac_config_targets " $1" ac_need_defaults=false ;; esac shift done ac_configure_extra_args= if $ac_cs_silent; then exec 6>/dev/null ac_configure_extra_args="$ac_configure_extra_args --silent" fi _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 if \$ac_cs_recheck; then set X $SHELL '$0' $ac_configure_args \$ac_configure_extra_args --no-create --no-recursion shift \$as_echo "running CONFIG_SHELL=$SHELL \$*" >&6 CONFIG_SHELL='$SHELL' export CONFIG_SHELL exec "\$@" fi _ACEOF cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 exec 5>>config.log { echo sed 'h;s/./-/g;s/^.../## /;s/...$/ ##/;p;x;p;x' <<_ASBOX ## Running $as_me. ## _ASBOX $as_echo "$ac_log" } >&5 _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 # # INIT-COMMANDS # AMDEP_TRUE="$AMDEP_TRUE" ac_aux_dir="$ac_aux_dir" _ACEOF cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # Handling of arguments. for ac_config_target in $ac_config_targets do case $ac_config_target in "config.h") CONFIG_HEADERS="$CONFIG_HEADERS config.h" ;; "depfiles") CONFIG_COMMANDS="$CONFIG_COMMANDS depfiles" ;; "Makefile") CONFIG_FILES="$CONFIG_FILES Makefile" ;; *) as_fn_error $? "invalid argument: \`$ac_config_target'" "$LINENO" 5;; esac done # If the user did not use the arguments to specify the items to instantiate, # then the envvar interface is used. Set only those that are not. # We use the long form for the default assignment because of an extremely # bizarre bug on SunOS 4.1.3. if $ac_need_defaults; then test "${CONFIG_FILES+set}" = set || CONFIG_FILES=$config_files test "${CONFIG_HEADERS+set}" = set || CONFIG_HEADERS=$config_headers test "${CONFIG_COMMANDS+set}" = set || CONFIG_COMMANDS=$config_commands fi # Have a temporary directory for convenience. Make it in the build tree # simply because there is no reason against having it here, and in addition, # creating and moving files from /tmp can sometimes cause problems. # Hook for its removal unless debugging. # Note that there is a small window in which the directory will not be cleaned: # after its creation but before its name has been assigned to `$tmp'. $debug || { tmp= ac_tmp= trap 'exit_status=$? : "${ac_tmp:=$tmp}" { test ! -d "$ac_tmp" || rm -fr "$ac_tmp"; } && exit $exit_status ' 0 trap 'as_fn_exit 1' 1 2 13 15 } # Create a (secure) tmp directory for tmp files. { tmp=`(umask 077 && mktemp -d "./confXXXXXX") 2>/dev/null` && test -d "$tmp" } || { tmp=./conf$$-$RANDOM (umask 077 && mkdir "$tmp") } || as_fn_error $? "cannot create a temporary directory in ." "$LINENO" 5 ac_tmp=$tmp # Set up the scripts for CONFIG_FILES section. # No need to generate them if there are no CONFIG_FILES. # This happens for instance with `./config.status config.h'. if test -n "$CONFIG_FILES"; then ac_cr=`echo X | tr X '\015'` # On cygwin, bash can eat \r inside `` if the user requested igncr. # But we know of no other shell where ac_cr would be empty at this # point, so we can use a bashism as a fallback. if test "x$ac_cr" = x; then eval ac_cr=\$\'\\r\' fi ac_cs_awk_cr=`$AWK 'BEGIN { print "a\rb" }' /dev/null` if test "$ac_cs_awk_cr" = "a${ac_cr}b"; then ac_cs_awk_cr='\\r' else ac_cs_awk_cr=$ac_cr fi echo 'BEGIN {' >"$ac_tmp/subs1.awk" && _ACEOF { echo "cat >conf$$subs.awk <<_ACEOF" && echo "$ac_subst_vars" | sed 's/.*/&!$&$ac_delim/' && echo "_ACEOF" } >conf$$subs.sh || as_fn_error $? "could not make $CONFIG_STATUS" "$LINENO" 5 ac_delim_num=`echo "$ac_subst_vars" | grep -c '^'` ac_delim='%!_!# ' for ac_last_try in false false false false false :; do . ./conf$$subs.sh || as_fn_error $? "could not make $CONFIG_STATUS" "$LINENO" 5 ac_delim_n=`sed -n "s/.*$ac_delim\$/X/p" conf$$subs.awk | grep -c X` if test $ac_delim_n = $ac_delim_num; then break elif $ac_last_try; then as_fn_error $? "could not make $CONFIG_STATUS" "$LINENO" 5 else ac_delim="$ac_delim!$ac_delim _$ac_delim!! " fi done rm -f conf$$subs.sh cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 cat >>"\$ac_tmp/subs1.awk" <<\\_ACAWK && _ACEOF sed -n ' h s/^/S["/; s/!.*/"]=/ p g s/^[^!]*!// :repl t repl s/'"$ac_delim"'$// t delim :nl h s/\(.\{148\}\)..*/\1/ t more1 s/["\\]/\\&/g; s/^/"/; s/$/\\n"\\/ p n b repl :more1 s/["\\]/\\&/g; s/^/"/; s/$/"\\/ p g s/.\{148\}// t nl :delim h s/\(.\{148\}\)..*/\1/ t more2 s/["\\]/\\&/g; s/^/"/; s/$/"/ p b :more2 s/["\\]/\\&/g; s/^/"/; s/$/"\\/ p g s/.\{148\}// t delim ' >$CONFIG_STATUS || ac_write_fail=1 rm -f conf$$subs.awk cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 _ACAWK cat >>"\$ac_tmp/subs1.awk" <<_ACAWK && for (key in S) S_is_set[key] = 1 FS = "" } { line = $ 0 nfields = split(line, field, "@") substed = 0 len = length(field[1]) for (i = 2; i < nfields; i++) { key = field[i] keylen = length(key) if (S_is_set[key]) { value = S[key] line = substr(line, 1, len) "" value "" substr(line, len + keylen + 3) len += length(value) + length(field[++i]) substed = 1 } else len += 1 + keylen } print line } _ACAWK _ACEOF cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 if sed "s/$ac_cr//" < /dev/null > /dev/null 2>&1; then sed "s/$ac_cr\$//; s/$ac_cr/$ac_cs_awk_cr/g" else cat fi < "$ac_tmp/subs1.awk" > "$ac_tmp/subs.awk" \ || as_fn_error $? "could not setup config files machinery" "$LINENO" 5 _ACEOF # VPATH may cause trouble with some makes, so we remove sole $(srcdir), # ${srcdir} and @srcdir@ entries from VPATH if srcdir is ".", strip leading and # trailing colons and then remove the whole line if VPATH becomes empty # (actually we leave an empty line to preserve line numbers). if test "x$srcdir" = x.; then ac_vpsub='/^[ ]*VPATH[ ]*=[ ]*/{ h s/// s/^/:/ s/[ ]*$/:/ s/:\$(srcdir):/:/g s/:\${srcdir}:/:/g s/:@srcdir@:/:/g s/^:*// s/:*$// x s/\(=[ ]*\).*/\1/ G s/\n// s/^[^=]*=[ ]*$// }' fi cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 fi # test -n "$CONFIG_FILES" # Set up the scripts for CONFIG_HEADERS section. # No need to generate them if there are no CONFIG_HEADERS. # This happens for instance with `./config.status Makefile'. if test -n "$CONFIG_HEADERS"; then cat >"$ac_tmp/defines.awk" <<\_ACAWK || BEGIN { _ACEOF # Transform confdefs.h into an awk script `defines.awk', embedded as # here-document in config.status, that substitutes the proper values into # config.h.in to produce config.h. # Create a delimiter string that does not exist in confdefs.h, to ease # handling of long lines. ac_delim='%!_!# ' for ac_last_try in false false :; do ac_tt=`sed -n "/$ac_delim/p" confdefs.h` if test -z "$ac_tt"; then break elif $ac_last_try; then as_fn_error $? "could not make $CONFIG_HEADERS" "$LINENO" 5 else ac_delim="$ac_delim!$ac_delim _$ac_delim!! " fi done # For the awk script, D is an array of macro values keyed by name, # likewise P contains macro parameters if any. Preserve backslash # newline sequences. ac_word_re=[_$as_cr_Letters][_$as_cr_alnum]* sed -n ' s/.\{148\}/&'"$ac_delim"'/g t rset :rset s/^[ ]*#[ ]*define[ ][ ]*/ / t def d :def s/\\$// t bsnl s/["\\]/\\&/g s/^ \('"$ac_word_re"'\)\(([^()]*)\)[ ]*\(.*\)/P["\1"]="\2"\ D["\1"]=" \3"/p s/^ \('"$ac_word_re"'\)[ ]*\(.*\)/D["\1"]=" \2"/p d :bsnl s/["\\]/\\&/g s/^ \('"$ac_word_re"'\)\(([^()]*)\)[ ]*\(.*\)/P["\1"]="\2"\ D["\1"]=" \3\\\\\\n"\\/p t cont s/^ \('"$ac_word_re"'\)[ ]*\(.*\)/D["\1"]=" \2\\\\\\n"\\/p t cont d :cont n s/.\{148\}/&'"$ac_delim"'/g t clear :clear s/\\$// t bsnlc s/["\\]/\\&/g; s/^/"/; s/$/"/p d :bsnlc s/["\\]/\\&/g; s/^/"/; s/$/\\\\\\n"\\/p b cont ' >$CONFIG_STATUS || ac_write_fail=1 cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 for (key in D) D_is_set[key] = 1 FS = "" } /^[\t ]*#[\t ]*(define|undef)[\t ]+$ac_word_re([\t (]|\$)/ { line = \$ 0 split(line, arg, " ") if (arg[1] == "#") { defundef = arg[2] mac1 = arg[3] } else { defundef = substr(arg[1], 2) mac1 = arg[2] } split(mac1, mac2, "(") #) macro = mac2[1] prefix = substr(line, 1, index(line, defundef) - 1) if (D_is_set[macro]) { # Preserve the white space surrounding the "#". print prefix "define", macro P[macro] D[macro] next } else { # Replace #undef with comments. This is necessary, for example, # in the case of _POSIX_SOURCE, which is predefined and required # on some systems where configure will not decide to define it. if (defundef == "undef") { print "/*", prefix defundef, macro, "*/" next } } } { print } _ACAWK _ACEOF cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 as_fn_error $? "could not setup config headers machinery" "$LINENO" 5 fi # test -n "$CONFIG_HEADERS" eval set X " :F $CONFIG_FILES :H $CONFIG_HEADERS :C $CONFIG_COMMANDS" shift for ac_tag do case $ac_tag in :[FHLC]) ac_mode=$ac_tag; continue;; esac case $ac_mode$ac_tag in :[FHL]*:*);; :L* | :C*:*) as_fn_error $? "invalid tag \`$ac_tag'" "$LINENO" 5;; :[FH]-) ac_tag=-:-;; :[FH]*) ac_tag=$ac_tag:$ac_tag.in;; esac ac_save_IFS=$IFS IFS=: set x $ac_tag IFS=$ac_save_IFS shift ac_file=$1 shift case $ac_mode in :L) ac_source=$1;; :[FH]) ac_file_inputs= for ac_f do case $ac_f in -) ac_f="$ac_tmp/stdin";; *) # Look for the file first in the build tree, then in the source tree # (if the path is not absolute). The absolute path cannot be DOS-style, # because $ac_f cannot contain `:'. test -f "$ac_f" || case $ac_f in [\\/$]*) false;; *) test -f "$srcdir/$ac_f" && ac_f="$srcdir/$ac_f";; esac || as_fn_error 1 "cannot find input file: \`$ac_f'" "$LINENO" 5;; esac case $ac_f in *\'*) ac_f=`$as_echo "$ac_f" | sed "s/'/'\\\\\\\\''/g"`;; esac as_fn_append ac_file_inputs " '$ac_f'" done # Let's still pretend it is `configure' which instantiates (i.e., don't # use $as_me), people would be surprised to read: # /* config.h. Generated by config.status. */ configure_input='Generated from '` $as_echo "$*" | sed 's|^[^:]*/||;s|:[^:]*/|, |g' `' by configure.' if test x"$ac_file" != x-; then configure_input="$ac_file. $configure_input" { $as_echo "$as_me:${as_lineno-$LINENO}: creating $ac_file" >&5 $as_echo "$as_me: creating $ac_file" >&6;} fi # Neutralize special characters interpreted by sed in replacement strings. case $configure_input in #( *\&* | *\|* | *\\* ) ac_sed_conf_input=`$as_echo "$configure_input" | sed 's/[\\\\&|]/\\\\&/g'`;; #( *) ac_sed_conf_input=$configure_input;; esac case $ac_tag in *:-:* | *:-) cat >"$ac_tmp/stdin" \ || as_fn_error $? "could not create $ac_file" "$LINENO" 5 ;; esac ;; esac ac_dir=`$as_dirname -- "$ac_file" || $as_expr X"$ac_file" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ X"$ac_file" : 'X\(//\)[^/]' \| \ X"$ac_file" : 'X\(//\)$' \| \ X"$ac_file" : 'X\(/\)' \| . 2>/dev/null || $as_echo X"$ac_file" | sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/ q } /^X\(\/\/\)[^/].*/{ s//\1/ q } /^X\(\/\/\)$/{ s//\1/ q } /^X\(\/\).*/{ s//\1/ q } s/.*/./; q'` as_dir="$ac_dir"; as_fn_mkdir_p ac_builddir=. case "$ac_dir" in .) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;; *) ac_dir_suffix=/`$as_echo "$ac_dir" | sed 's|^\.[\\/]||'` # A ".." for each directory in $ac_dir_suffix. ac_top_builddir_sub=`$as_echo "$ac_dir_suffix" | sed 's|/[^\\/]*|/..|g;s|/||'` case $ac_top_builddir_sub in "") ac_top_builddir_sub=. ac_top_build_prefix= ;; *) ac_top_build_prefix=$ac_top_builddir_sub/ ;; esac ;; esac ac_abs_top_builddir=$ac_pwd ac_abs_builddir=$ac_pwd$ac_dir_suffix # for backward compatibility: ac_top_builddir=$ac_top_build_prefix case $srcdir in .) # We are building in place. ac_srcdir=. ac_top_srcdir=$ac_top_builddir_sub ac_abs_top_srcdir=$ac_pwd ;; [\\/]* | ?:[\\/]* ) # Absolute name. ac_srcdir=$srcdir$ac_dir_suffix; ac_top_srcdir=$srcdir ac_abs_top_srcdir=$srcdir ;; *) # Relative name. ac_srcdir=$ac_top_build_prefix$srcdir$ac_dir_suffix ac_top_srcdir=$ac_top_build_prefix$srcdir ac_abs_top_srcdir=$ac_pwd/$srcdir ;; esac ac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix case $ac_mode in :F) # # CONFIG_FILE # case $INSTALL in [\\/$]* | ?:[\\/]* ) ac_INSTALL=$INSTALL ;; *) ac_INSTALL=$ac_top_build_prefix$INSTALL ;; esac ac_MKDIR_P=$MKDIR_P case $MKDIR_P in [\\/$]* | ?:[\\/]* ) ;; */*) ac_MKDIR_P=$ac_top_build_prefix$MKDIR_P ;; esac _ACEOF cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # If the template does not know about datarootdir, expand it. # FIXME: This hack should be removed a few years after 2.60. ac_datarootdir_hack=; ac_datarootdir_seen= ac_sed_dataroot=' /datarootdir/ { p q } /@datadir@/p /@docdir@/p /@infodir@/p /@localedir@/p /@mandir@/p' case `eval "sed -n \"\$ac_sed_dataroot\" $ac_file_inputs"` in *datarootdir*) ac_datarootdir_seen=yes;; *@datadir@*|*@docdir@*|*@infodir@*|*@localedir@*|*@mandir@*) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&5 $as_echo "$as_me: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&2;} _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_datarootdir_hack=' s&@datadir@&$datadir&g s&@docdir@&$docdir&g s&@infodir@&$infodir&g s&@localedir@&$localedir&g s&@mandir@&$mandir&g s&\\\${datarootdir}&$datarootdir&g' ;; esac _ACEOF # Neutralize VPATH when `$srcdir' = `.'. # Shell code in configure.ac might set extrasub. # FIXME: do we really want to maintain this feature? cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_sed_extra="$ac_vpsub $extrasub _ACEOF cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 :t /@[a-zA-Z_][a-zA-Z_0-9]*@/!b s|@configure_input@|$ac_sed_conf_input|;t t s&@top_builddir@&$ac_top_builddir_sub&;t t s&@top_build_prefix@&$ac_top_build_prefix&;t t s&@srcdir@&$ac_srcdir&;t t s&@abs_srcdir@&$ac_abs_srcdir&;t t s&@top_srcdir@&$ac_top_srcdir&;t t s&@abs_top_srcdir@&$ac_abs_top_srcdir&;t t s&@builddir@&$ac_builddir&;t t s&@abs_builddir@&$ac_abs_builddir&;t t s&@abs_top_builddir@&$ac_abs_top_builddir&;t t s&@INSTALL@&$ac_INSTALL&;t t s&@MKDIR_P@&$ac_MKDIR_P&;t t $ac_datarootdir_hack " eval sed \"\$ac_sed_extra\" "$ac_file_inputs" | $AWK -f "$ac_tmp/subs.awk" \ >$ac_tmp/out || as_fn_error $? "could not create $ac_file" "$LINENO" 5 test -z "$ac_datarootdir_hack$ac_datarootdir_seen" && { ac_out=`sed -n '/\${datarootdir}/p' "$ac_tmp/out"`; test -n "$ac_out"; } && { ac_out=`sed -n '/^[ ]*datarootdir[ ]*:*=/p' \ "$ac_tmp/out"`; test -z "$ac_out"; } && { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file contains a reference to the variable \`datarootdir' which seems to be undefined. Please make sure it is defined" >&5 $as_echo "$as_me: WARNING: $ac_file contains a reference to the variable \`datarootdir' which seems to be undefined. Please make sure it is defined" >&2;} rm -f "$ac_tmp/stdin" case $ac_file in -) cat "$ac_tmp/out" && rm -f "$ac_tmp/out";; *) rm -f "$ac_file" && mv "$ac_tmp/out" "$ac_file";; esac \ || as_fn_error $? "could not create $ac_file" "$LINENO" 5 ;; :H) # # CONFIG_HEADER # if test x"$ac_file" != x-; then { $as_echo "/* $configure_input */" \ && eval '$AWK -f "$ac_tmp/defines.awk"' "$ac_file_inputs" } >"$ac_tmp/config.h" \ || as_fn_error $? "could not create $ac_file" "$LINENO" 5 if diff "$ac_file" "$ac_tmp/config.h" >/dev/null 2>&1; then { $as_echo "$as_me:${as_lineno-$LINENO}: $ac_file is unchanged" >&5 $as_echo "$as_me: $ac_file is unchanged" >&6;} else rm -f "$ac_file" mv "$ac_tmp/config.h" "$ac_file" \ || as_fn_error $? "could not create $ac_file" "$LINENO" 5 fi else $as_echo "/* $configure_input */" \ && eval '$AWK -f "$ac_tmp/defines.awk"' "$ac_file_inputs" \ || as_fn_error $? "could not create -" "$LINENO" 5 fi # Compute "$ac_file"'s index in $config_headers. _am_arg="$ac_file" _am_stamp_count=1 for _am_header in $config_headers :; do case $_am_header in $_am_arg | $_am_arg:* ) break ;; * ) _am_stamp_count=`expr $_am_stamp_count + 1` ;; esac done echo "timestamp for $_am_arg" >`$as_dirname -- "$_am_arg" || $as_expr X"$_am_arg" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ X"$_am_arg" : 'X\(//\)[^/]' \| \ X"$_am_arg" : 'X\(//\)$' \| \ X"$_am_arg" : 'X\(/\)' \| . 2>/dev/null || $as_echo X"$_am_arg" | sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/ q } /^X\(\/\/\)[^/].*/{ s//\1/ q } /^X\(\/\/\)$/{ s//\1/ q } /^X\(\/\).*/{ s//\1/ q } s/.*/./; q'`/stamp-h$_am_stamp_count ;; :C) { $as_echo "$as_me:${as_lineno-$LINENO}: executing $ac_file commands" >&5 $as_echo "$as_me: executing $ac_file commands" >&6;} ;; esac case $ac_file$ac_mode in "depfiles":C) test x"$AMDEP_TRUE" != x"" || { # Autoconf 2.62 quotes --file arguments for eval, but not when files # are listed without --file. Let's play safe and only enable the eval # if we detect the quoting. case $CONFIG_FILES in *\'*) eval set x "$CONFIG_FILES" ;; *) set x $CONFIG_FILES ;; esac shift for mf do # Strip MF so we end up with the name of the file. mf=`echo "$mf" | sed -e 's/:.*$//'` # Check whether this is an Automake generated Makefile or not. # We used to match only the files named `Makefile.in', but # some people rename them; so instead we look at the file content. # Grep'ing the first line is not enough: some people post-process # each Makefile.in and add a new line on top of each file to say so. # Grep'ing the whole file is not good either: AIX grep has a line # limit of 2048, but all sed's we know have understand at least 4000. if sed -n 's,^#.*generated by automake.*,X,p' "$mf" | grep X >/dev/null 2>&1; then dirpart=`$as_dirname -- "$mf" || $as_expr X"$mf" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ X"$mf" : 'X\(//\)[^/]' \| \ X"$mf" : 'X\(//\)$' \| \ X"$mf" : 'X\(/\)' \| . 2>/dev/null || $as_echo X"$mf" | sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/ q } /^X\(\/\/\)[^/].*/{ s//\1/ q } /^X\(\/\/\)$/{ s//\1/ q } /^X\(\/\).*/{ s//\1/ q } s/.*/./; q'` else continue fi # Extract the definition of DEPDIR, am__include, and am__quote # from the Makefile without running `make'. DEPDIR=`sed -n 's/^DEPDIR = //p' < "$mf"` test -z "$DEPDIR" && continue am__include=`sed -n 's/^am__include = //p' < "$mf"` test -z "am__include" && continue am__quote=`sed -n 's/^am__quote = //p' < "$mf"` # When using ansi2knr, U may be empty or an underscore; expand it U=`sed -n 's/^U = //p' < "$mf"` # Find all dependency output files, they are included files with # $(DEPDIR) in their names. We invoke sed twice because it is the # simplest approach to changing $(DEPDIR) to its actual value in the # expansion. for file in `sed -n " s/^$am__include $am__quote\(.*(DEPDIR).*\)$am__quote"'$/\1/p' <"$mf" | \ sed -e 's/\$(DEPDIR)/'"$DEPDIR"'/g' -e 's/\$U/'"$U"'/g'`; do # Make sure the directory exists. test -f "$dirpart/$file" && continue fdir=`$as_dirname -- "$file" || $as_expr X"$file" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ X"$file" : 'X\(//\)[^/]' \| \ X"$file" : 'X\(//\)$' \| \ X"$file" : 'X\(/\)' \| . 2>/dev/null || $as_echo X"$file" | sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/ q } /^X\(\/\/\)[^/].*/{ s//\1/ q } /^X\(\/\/\)$/{ s//\1/ q } /^X\(\/\).*/{ s//\1/ q } s/.*/./; q'` as_dir=$dirpart/$fdir; as_fn_mkdir_p # echo "creating $dirpart/$file" echo '# dummy' > "$dirpart/$file" done done } ;; esac done # for ac_tag as_fn_exit 0 _ACEOF ac_clean_files=$ac_clean_files_save test $ac_write_fail = 0 || as_fn_error $? "write failure creating $CONFIG_STATUS" "$LINENO" 5 # configure is writing to config.log, and then calls config.status. # config.status does its own redirection, appending to config.log. # Unfortunately, on DOS this fails, as config.log is still kept open # by configure, so config.status won't be able to write to it; its # output is simply discarded. So we exec the FD to /dev/null, # effectively closing config.log, so it can be properly (re)opened and # appended to by config.status. When coming back to configure, we # need to make the FD available again. if test "$no_create" != yes; then ac_cs_success=: ac_config_status_args= test "$silent" = yes && ac_config_status_args="$ac_config_status_args --quiet" exec 5>/dev/null $SHELL $CONFIG_STATUS $ac_config_status_args || ac_cs_success=false exec 5>>config.log # Use ||, not &&, to avoid exiting from the if with $? = 1, which # would make configure fail if this is the last instruction. $ac_cs_success || as_fn_exit 1 fi if test -n "$ac_unrecognized_opts" && test "$enable_option_checking" != no; then { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: unrecognized options: $ac_unrecognized_opts" >&5 $as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2;} fi sftpserver-0.2.1/rotests/0000775000175000017500000000000011625765051012433 500000000000000sftpserver-0.2.1/rotests/rotest560000664000175000017500000000012511625765051013767 00000000000000!touch foo mv -o foo bar #.*permission denied.* mv -n foo bar #.*permission denied.* sftpserver-0.2.1/rotests/rotest60000664000175000017500000000005311625765051013702 00000000000000!touch foo link a b #.*permission denied.* sftpserver-0.2.1/rotests/rotest34560000664000175000017500000000045311625765051014142 00000000000000!touch foo !mkdir dir put foo dest #.*permission denied.* chmod 600 foo #.*permission denied.* rm foo #.*permission denied.* mkdir spong #.*permission denied.* rmdir dir #.*permission denied.* mv foo bar #.*permission denied.* mv -p foo bar #.*permission denied.* symlink a b #.*permission denied.* sftpserver-0.2.1/sftpclient.c0000664000175000017500000025237412344655337013210 00000000000000/* * This file is part of the Green End SFTP Server. * Copyright (C) 2007, 2010, 2011, 2014 Richard Kettlewell * * 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 2 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, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA */ #include "sftpclient.h" #include "utils.h" #include "xfns.h" #include "send.h" #include "globals.h" #include "types.h" #include "alloc.h" #include "parse.h" #include "sftp.h" #include "debug.h" #include "thread.h" #include "stat.h" #include "charset.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #if HAVE_READLINE # include # include #endif struct command { const char *name; int minargs, maxargs; int (*handler)(int ac, char **av); const char *args; const char *help; }; struct client_handle { size_t len; char *data; }; static int sftpin; static struct allocator allocator; static struct sftpjob fakejob; static struct worker fakeworker; static char *cwd; static const char *inputpath; static int inputline; static int progress_indicators = 1; static int terminal_width; static int textmode; static char *newline; static char *vendorname, *servername, *serverversion, *serverversions; static uint64_t serverbuild; static int stoponerror; static int echo; static uint32_t attrmask; const struct sftpprotocol *protocol = &sftp_v3; const char sendtype[] = "request"; /* Command line */ static size_t buffersize = 32768; static int nrequests = 16; static const char *subsystem; static const char *program; static const char *batchfile; static int sshversion; static int compress; static const char *sshconf; static const char *sshoptions[1024]; static int nsshoptions; static int sshverbose; static int sftpversion = 6; static int quirk_reverse_symlink; static int forceversion; static char *sftp_realpath(const char *path); static const struct option options[] = { { "help", no_argument, 0, 'h' }, { "version", no_argument, 0, 'V' }, { "dropbear", no_argument, 0, 'r' }, { "buffer", required_argument, 0, 'B' }, { "batch", required_argument, 0, 'b' }, { "program", required_argument, 0, 'P' }, { "requests", required_argument, 0, 'R' }, { "subsystem", required_argument, 0, 's' }, { "sftp-version", required_argument, 0, 'S' }, { "quirk-reverse-symlink", no_argument, 0, 256 }, { "stop-on-error", no_argument, 0, 257 }, { "no-stop-on-error", no_argument, 0, 258 }, { "progress", no_argument, 0, 259 }, { "no-progress", no_argument, 0, 260 }, { "echo", no_argument, 0, 261 }, { "fix-sigpipe", no_argument, 0, 262 }, { "force-version", required_argument, 0, 263 }, { "debug", no_argument, 0, 'd' }, { "debug-path", required_argument, 0, 'D' }, { "host", required_argument, 0, 'H' }, { "port", required_argument, 0, 'p' }, { "ipv4", no_argument, 0, '4' }, { "ipv6", no_argument, 0, '6' }, { "1", no_argument, 0, '1' }, { "2", no_argument, 0, '2' }, { "C", no_argument, 0, 'C' }, { "F", required_argument, 0, 'F' }, { "o", required_argument, 0, 'o' }, { "v", no_argument, 0, 'v' }, { 0, 0, 0, 0 } }; /* display usage message and terminate */ static void help(void) { xprintf("Usage:\n" " sftpclient [OPTIONS] [USER@]HOST\n" "\n" "Quick and dirty SFTP client\n" "\n"); xprintf("Options:\n" " --help, -h Display usage message\n" " --version, -V Display version number\n" " -r, --dropbear Use dbclient instead of ssh\n" " -B, --buffer BYTES Select buffer size (default 8192)\n" " -b, --batch PATH Read batch file\n" " -P, --program PATH Execute program as SFTP server\n"); xprintf(" -R, --requests COUNT Maximum outstanding requests (default 8)\n" " -s, --subsystem NAME Remote subsystem name\n" " -S, --sftp-version VER Protocol version to request (default 3)\n" " --quirk-openssh Server gets SSH_FXP_SYMLINK backwards\n"); xprintf("Options passed to SSH:\n" " -1, -2 Select protocol version\n" " -C Enable compression\n" " -F PATH Use alternative config file\n" " -o OPTION Pass option to client\n" " -v Raise logging level\n"); exit(0); } /* display version number and terminate */ static void version(void) { xprintf("sftp client version %s\n", VERSION); exit(0); } /* Utilities */ static int attribute((format(printf,1,2))) error(const char *fmt, ...) { va_list ap; if(inputpath) fprintf(stderr, "%s:%d ", inputpath, inputline); va_start(ap, fmt); vfprintf(stderr, fmt, ap); va_end(ap); fputc('\n', stderr); fflush(stderr); return -1; } static int status(void) { uint32_t status; char *msg; /* Cope with half-parsed responses */ fakejob.ptr = fakejob.data + 5; fakejob.left = fakejob.len - 5; cpcheck(sftp_parse_uint32(&fakejob, &status)); cpcheck(sftp_parse_string(&fakejob, &msg, 0)); if(status) { error("%s (%s)", msg, status_to_string(status)); return -1; } else return 0; } /* Get a response. Picks out the type and ID. */ static uint8_t getresponse(int expected, uint32_t expected_id, const char *what) { uint32_t len; uint8_t type; if(do_read(sftpin, &len, sizeof len)) fatal("unexpected EOF from server while reading %s response length", what); free(fakejob.data); /* free last job */ fakejob.len = ntohl(len); fakejob.data = xmalloc(fakejob.len); if(do_read(sftpin, fakejob.data, fakejob.len)) fatal("unexpected EOF from server while reading %s response data", what); if(sftp_debugging) { D(("%s response:", what)); sftp_debug_hexdump(fakejob.data, fakejob.len); } fakejob.left = fakejob.len; fakejob.ptr = fakejob.data; cpcheck(sftp_parse_uint8(&fakejob, &type)); if(type != SSH_FXP_VERSION) { cpcheck(sftp_parse_uint32(&fakejob, &fakejob.id)); if(expected_id && fakejob.id != expected_id) fatal("wrong ID in response to %s (want %"PRIu32 " got %"PRIu32" type was %d)", what, expected_id, fakejob.id, type); } if(expected > 0 && type != expected) { if(type == SSH_FXP_STATUS) status(); else fatal("expected %s response %d got %d", what, expected, type); } return type; } /* Split a command line */ static int split(char *line, char **av) { char *arg; int ac = 0; while(*line) { if(isspace((unsigned char)*line)) { ++line; continue; } if(*line == '"') { arg = av[ac++] = line++; while(*line && *line != '"') { if(*line == '\\' && line[1]) ++line; *arg++ = *line++; } if(!*line) { error("unterminated string"); return -1; } *arg++ = 0; line++; } else { av[ac++] = line; while(*line && !isspace((unsigned char)*line)) ++line; if(*line) *line++ = 0; } } av[ac] = 0; return ac; } static uint32_t newid(void) { static uint32_t latestid; do { ++latestid; } while(!latestid); return latestid; } /* Find path to current directory */ static char *remote_cwd(void) { if(!cwd) { if(!(cwd = sftp_realpath("."))) exit(1); cwd = xstrdup(cwd); } return cwd; } static const char *makeabspath(const char *name) { char *resolved; assert(cwd != 0); if(name[0] == '/') return name; resolved = sftp_alloc(fakejob.a, strlen(cwd) + strlen(name) + 2); sprintf(resolved, "%s/%s", cwd, name); return resolved; } static void progress(const char *path, uint64_t sofar, uint64_t total) { if(progress_indicators) { if(!total) xprintf("\r%*s\r", terminal_width, ""); else if(total == (uint64_t)-1) xprintf("\r%.60s: %12"PRIu64"b", path, sofar); else xprintf("\r%.60s: %12"PRIu64"b %3d%%", path, sofar, (int)(100 * sofar / total)); if(fflush(stdout) < 0) fatal("error writing to stdout: %s", strerror(errno)); } } /* SFTP operation stubs */ static int sftp_init(void) { uint32_t version, u32; uint16_t u16; /* Send SSH_FXP_INIT */ sftp_send_begin(&fakeworker); sftp_send_uint8(&fakeworker, SSH_FXP_INIT); sftp_send_uint32(&fakeworker, sftpversion); sftp_send_end(&fakeworker); /* Parse the version reponse */ if(getresponse(SSH_FXP_VERSION, 0, "SSH_FXP_INIT") != SSH_FXP_VERSION) return -1; cpcheck(sftp_parse_uint32(&fakejob, &version)); switch(version) { case 3: protocol = &sftp_v3; break; case 4: protocol = &sftp_v4; break; case 5: protocol = &sftp_v5; break; case 6: protocol = &sftp_v6; break; default: return error("server wanted protocol version %"PRIu32, version); } attrmask = protocol->attrmask; /* Extension data */ while(fakejob.left) { char *xname, *xdata; size_t xdatalen; cpcheck(sftp_parse_string(&fakejob, &xname, 0)); cpcheck(sftp_parse_string(&fakejob, &xdata, &xdatalen)); D(("server sent extension '%s'", xname)); /* TODO table-driven extension parsing */ if(!strcmp(xname, "newline")) { free(newline); newline = xstrdup(xdata); if(!*newline) return error("cannot cope with empty newline sequence"); /* TODO check newline sequence doesn't contain repeats */ } else if(!strcmp(xname, "vendor-id")) { struct sftpjob xjob; char *vn ,*sn, *sv; xjob.a = &allocator; xjob.ptr = (void *)xdata; xjob.left = xdatalen; cpcheck(sftp_parse_string(&xjob, &vn, 0)); cpcheck(sftp_parse_string(&xjob, &sn, 0)); cpcheck(sftp_parse_string(&xjob, &sv, 0)); cpcheck(sftp_parse_uint64(&xjob, &serverbuild)); free(vendorname); vendorname = xstrdup(vn); free(servername); servername = xstrdup(sn); free(serverversion); serverversion = xstrdup(sv); } else if(!strcmp(xname, "versions")) { free(serverversions); serverversions = xstrdup(xdata); } else if(!strcmp(xname, "symlink-order@rjk.greenend.org.uk")) { /* See commentary in v3.c */ if(!strcmp(xdata, "targetpath-linkpath")) quirk_reverse_symlink = 1; else if(!strcmp(xdata, "linkpath-targetpath")) quirk_reverse_symlink = 0; else error("unknown %s value '%s'", xname, xdata); } else if(!strcmp(xname, "supported")) { struct sftpjob xjob; xjob.a = &allocator; xjob.ptr = (void *)xdata; xjob.left = xdatalen; cpcheck(sftp_parse_uint32(&xjob, &attrmask)); cpcheck(sftp_parse_uint32(&xjob, &u32)); /* supported-attribute-bits */ cpcheck(sftp_parse_uint32(&xjob, &u32)); /* supported-open-flags */ cpcheck(sftp_parse_uint32(&xjob, &u32)); /* supported-access-mask */ cpcheck(sftp_parse_uint32(&xjob, &u32)); /* max-read-size */ while(xjob.left) cpcheck(sftp_parse_string(&xjob, 0, 0)); /* extension-names */ } else if(!strcmp(xname, "supported2")) { struct sftpjob xjob; xjob.a = &allocator; xjob.ptr = (void *)xdata; xjob.left = xdatalen; cpcheck(sftp_parse_uint32(&xjob, &attrmask)); /* supported-attribute-mask */ assert(!(attrmask & SSH_FILEXFER_ATTR_CTIME)); cpcheck(sftp_parse_uint32(&xjob, &u32)); /* supported-attribute-bits */ cpcheck(sftp_parse_uint32(&xjob, &u32)); /* supported-open-flags */ cpcheck(sftp_parse_uint32(&xjob, &u32)); /* supported-access-mask */ cpcheck(sftp_parse_uint32(&xjob, &u32)); /* max-read-size */ cpcheck(sftp_parse_uint16(&xjob, &u16)); /* supported-open-block-vector */ cpcheck(sftp_parse_uint16(&xjob, &u16)); /* supported-block-vector */ cpcheck(sftp_parse_uint32(&xjob, &u32)); /* attrib-extension-count */ while(u32 > 0) { cpcheck(sftp_parse_string(&xjob, 0, 0)); /* attrib-extension-names */ --u32; } cpcheck(sftp_parse_uint32(&xjob, &u32)); /* extension-count */ while(u32 > 0) { cpcheck(sftp_parse_string(&xjob, 0, 0)); /* extension-names */ --u32; } } } /* Make sure outbound translation will actually work */ if(buffersize < strlen(newline)) buffersize = strlen(newline); return 0; } static char *sftp_realpath(const char *path) { char *resolved; uint32_t u32, id; sftp_send_begin(&fakeworker); sftp_send_uint8(&fakeworker, SSH_FXP_REALPATH); sftp_send_uint32(&fakeworker, id = newid()); sftp_send_path(&fakejob, &fakeworker, path); sftp_send_end(&fakeworker); if(getresponse(SSH_FXP_NAME, id, "SSH_FXP_REALPATH") != SSH_FXP_NAME) return 0; cpcheck(sftp_parse_uint32(&fakejob, &u32)); if(u32 != 1) fatal("wrong count in SSH_FXP_REALPATH reply"); cpcheck(sftp_parse_path(&fakejob, &resolved)); return resolved; } static char *sftp_realpath_v6(const char *path, int control_byte, char **compose, struct sftpattr *attrs) { char *resolved; uint32_t u32, id; sftp_send_begin(&fakeworker); sftp_send_uint8(&fakeworker, SSH_FXP_REALPATH); sftp_send_uint32(&fakeworker, id = newid()); sftp_send_path(&fakejob, &fakeworker, path); if(control_byte >= 0) { sftp_send_uint8(&fakeworker, control_byte); if(compose) while(*compose) sftp_send_path(&fakejob, &fakeworker, *compose++); } sftp_send_end(&fakeworker); if(getresponse(SSH_FXP_NAME, id, "SSH_FXP_REALPATH") != SSH_FXP_NAME) return 0; cpcheck(sftp_parse_uint32(&fakejob, &u32)); if(u32 != 1) fatal("wrong count in SSH_FXP_REALPATH reply"); cpcheck(sftp_parse_path(&fakejob, &resolved)); cpcheck(protocol->parseattrs(&fakejob, attrs)); return resolved; } static int sftp_stat(const char *path, struct sftpattr *attrs, uint8_t type) { uint32_t id; remote_cwd(); sftp_send_begin(&fakeworker); sftp_send_uint8(&fakeworker, type); sftp_send_uint32(&fakeworker, id = newid()); sftp_send_path(&fakejob, &fakeworker, makeabspath(path)); if(protocol->version > 3) sftp_send_uint32(&fakeworker, 0xFFFFFFFF); sftp_send_end(&fakeworker); if(getresponse(SSH_FXP_ATTRS, id, "SSH_FXP_*STAT") != SSH_FXP_ATTRS) return -1; cpcheck(protocol->parseattrs(&fakejob, attrs)); attrs->name = path; attrs->wname = sftp_mbs2wcs(attrs->name); return 0; } static int sftp_fstat(const struct client_handle *hp, struct sftpattr *attrs) { uint32_t id; sftp_send_begin(&fakeworker); sftp_send_uint8(&fakeworker, SSH_FXP_FSTAT); sftp_send_uint32(&fakeworker, id = newid()); sftp_send_bytes(&fakeworker, hp->data, hp->len); if(protocol->version > 3) sftp_send_uint32(&fakeworker, 0xFFFFFFFF); sftp_send_end(&fakeworker); if(getresponse(SSH_FXP_ATTRS, id, "SSH_FXP_FSTAT") != SSH_FXP_ATTRS) return -1; cpcheck(protocol->parseattrs(&fakejob, attrs)); return 0; } static int sftp_opendir(const char *path, struct client_handle *hp) { uint32_t id; remote_cwd(); sftp_send_begin(&fakeworker); sftp_send_uint8(&fakeworker, SSH_FXP_OPENDIR); sftp_send_uint32(&fakeworker, id = newid()); sftp_send_path(&fakejob, &fakeworker, makeabspath(path)); sftp_send_end(&fakeworker); if(getresponse(SSH_FXP_HANDLE, id, "SSH_FXP_OPENDIR") != SSH_FXP_HANDLE) return -1; cpcheck(sftp_parse_string(&fakejob, &hp->data, &hp->len)); return 0; } static int sftp_readdir(const struct client_handle *hp, struct sftpattr **attrsp, size_t *nattrsp) { uint32_t id, n; struct sftpattr *attrs; char *name, *longname = 0; sftp_send_begin(&fakeworker); sftp_send_uint8(&fakeworker, SSH_FXP_READDIR); sftp_send_uint32(&fakeworker, id = newid()); sftp_send_bytes(&fakeworker, hp->data, hp->len); sftp_send_end(&fakeworker); switch(getresponse(-1, id, "SSH_FXP_READDIR")) { case SSH_FXP_NAME: cpcheck(sftp_parse_uint32(&fakejob, &n)); if(n > SIZE_MAX / sizeof(struct sftpattr)) fatal("too many attributes in SSH_FXP_READDIR response"); attrs = sftp_alloc(fakejob.a, n * sizeof(struct sftpattr)); if(nattrsp) *nattrsp = n; if(attrsp) *attrsp = attrs; while(n > 0) { cpcheck(sftp_parse_path(&fakejob, &name)); if(protocol->version <= 3) cpcheck(sftp_parse_path(&fakejob, &longname)); cpcheck(protocol->parseattrs(&fakejob, attrs)); attrs->name = name; attrs->longname = longname; attrs->wname = sftp_mbs2wcs(attrs->name); ++attrs; --n; } return 0; case SSH_FXP_STATUS: cpcheck(sftp_parse_uint32(&fakejob, &n)); if(n == SSH_FX_EOF) { if(nattrsp) *nattrsp = 0; if(attrsp) *attrsp = 0; return 0; } status(); return -1; default: fatal("bogus response to SSH_FXP_READDIR"); } } static int sftp_close(const struct client_handle *hp) { uint32_t id; sftp_send_begin(&fakeworker); sftp_send_uint8(&fakeworker, SSH_FXP_CLOSE); sftp_send_uint32(&fakeworker, id = newid()); sftp_send_bytes(&fakeworker, hp->data, hp->len); sftp_send_end(&fakeworker); getresponse(SSH_FXP_STATUS, id, "SSH_FXP_CLOSE"); return status(); } static int sftp_setstat(const char *path, const struct sftpattr *attrs) { uint32_t id; remote_cwd(); sftp_send_begin(&fakeworker); sftp_send_uint8(&fakeworker, SSH_FXP_SETSTAT); sftp_send_uint32(&fakeworker, id = newid()); sftp_send_path(&fakejob, &fakeworker, makeabspath(path)); protocol->sendattrs(&fakejob, attrs); sftp_send_end(&fakeworker); getresponse(SSH_FXP_STATUS, id, "SSH_FXP_SETSTAT"); return status(); } static int sftp_fsetstat(const struct client_handle *hp, const struct sftpattr *attrs) { uint32_t id; sftp_send_begin(&fakeworker); sftp_send_uint8(&fakeworker, SSH_FXP_FSETSTAT); sftp_send_uint32(&fakeworker, id = newid()); sftp_send_bytes(&fakeworker, hp->data, hp->len); protocol->sendattrs(&fakejob, attrs); sftp_send_end(&fakeworker); getresponse(SSH_FXP_STATUS, id, "SSH_FXP_FSETSTAT"); return status(); } static int sftp_rmdir(const char *path) { uint32_t id; remote_cwd(); sftp_send_begin(&fakeworker); sftp_send_uint8(&fakeworker, SSH_FXP_RMDIR); sftp_send_uint32(&fakeworker, id = newid()); sftp_send_path(&fakejob, &fakeworker, makeabspath(path)); sftp_send_end(&fakeworker); getresponse(SSH_FXP_STATUS, id, "SSH_FXP_RMDIR"); return status(); } static int sftp_remove(const char *path) { uint32_t id; remote_cwd(); sftp_send_begin(&fakeworker); sftp_send_uint8(&fakeworker, SSH_FXP_REMOVE); sftp_send_uint32(&fakeworker, id = newid()); sftp_send_path(&fakejob, &fakeworker, makeabspath(path)); sftp_send_end(&fakeworker); getresponse(SSH_FXP_STATUS, id, "SSH_FXP_REMOVE"); return status(); } static int sftp_rename(const char *oldpath, const char *newpath, unsigned flags) { uint32_t id; remote_cwd(); /* In v3/4 atomic is assumed, overwrite and native are not available */ if(protocol->version <= 4 && (flags & ~SSH_FXF_RENAME_ATOMIC) != 0) return error("cannot emulate rename flags %#x in protocol %d", flags, protocol->version); sftp_send_begin(&fakeworker); sftp_send_uint8(&fakeworker, SSH_FXP_RENAME); sftp_send_uint32(&fakeworker, id = newid()); sftp_send_path(&fakejob, &fakeworker, makeabspath(oldpath)); sftp_send_path(&fakejob, &fakeworker, makeabspath(newpath)); if(protocol->version >= 5) sftp_send_uint32(&fakeworker, flags); sftp_send_end(&fakeworker); getresponse(SSH_FXP_STATUS, id, "SSH_FXP_RENAME"); return status(); } static int sftp_prename(const char *oldpath, const char *newpath) { uint32_t id; remote_cwd(); sftp_send_begin(&fakeworker); sftp_send_uint8(&fakeworker, SSH_FXP_EXTENDED); sftp_send_uint32(&fakeworker, id = newid()); sftp_send_string(&fakeworker, "posix-rename@openssh.org"); sftp_send_path(&fakejob, &fakeworker, makeabspath(oldpath)); sftp_send_path(&fakejob, &fakeworker, makeabspath(newpath)); sftp_send_end(&fakeworker); getresponse(SSH_FXP_STATUS, id, "posix-rename@openssh.org"); return status(); } static int sftp_link(const char *targetpath, const char *linkpath, int sftp_send_symlink) { uint32_t id; if(protocol->version < 6 && !sftp_send_symlink) return error("hard links not supported in protocol %"PRIu32, protocol->version); remote_cwd(); sftp_send_begin(&fakeworker); sftp_send_uint8(&fakeworker, (protocol->version >= 6 ? SSH_FXP_LINK : SSH_FXP_SYMLINK)); sftp_send_uint32(&fakeworker, id = newid()); if(quirk_reverse_symlink) { /* OpenSSH server gets SSH_FXP_SYMLINK args back to front * - see http://bugzilla.mindrot.org/show_bug.cgi?id=861 */ sftp_send_path(&fakejob, &fakeworker, targetpath); sftp_send_path(&fakejob, &fakeworker, makeabspath(linkpath)); } else { sftp_send_path(&fakejob, &fakeworker, makeabspath(linkpath)); sftp_send_path(&fakejob, &fakeworker, sftp_send_symlink ? targetpath : makeabspath(targetpath)); } if(protocol->version >= 6) sftp_send_uint8(&fakeworker, !!sftp_send_symlink); sftp_send_end(&fakeworker); getresponse(SSH_FXP_STATUS, id, "SSH_FXP_*LINK"); return status(); } static int sftp_open(const char *path, uint32_t desired_access, uint32_t flags, const struct sftpattr *attrs, struct client_handle *hp) { uint32_t id, pflags = 0; remote_cwd(); if(protocol->version <= 4) { /* We must translate the v5/6 style parameters back down to v3/4 */ if(desired_access & ACE4_READ_DATA) pflags |= SSH_FXF_READ; if(desired_access & ACE4_WRITE_DATA) pflags |= SSH_FXF_WRITE; switch(flags & SSH_FXF_ACCESS_DISPOSITION) { case SSH_FXF_CREATE_NEW: pflags |= SSH_FXF_CREAT|SSH_FXF_EXCL; break; case SSH_FXF_CREATE_TRUNCATE: pflags |= SSH_FXF_CREAT|SSH_FXF_TRUNC; break; case SSH_FXF_OPEN_OR_CREATE: pflags |= SSH_FXF_CREAT; break; case SSH_FXF_OPEN_EXISTING: break; case SSH_FXF_TRUNCATE_EXISTING: pflags |= SSH_FXF_TRUNC; break; default: return error("unknown SSH_FXF_ACCESS_DISPOSITION %#"PRIx32, flags); } if(flags & (SSH_FXF_APPEND_DATA|SSH_FXF_APPEND_DATA_ATOMIC)) pflags |= SSH_FXF_APPEND; if(flags & SSH_FXF_TEXT_MODE) { if(protocol->version < 4) return error("SSH_FXF_TEXT_MODE cannot be emulated in protocol %d", protocol->version); else pflags |= SSH_FXF_TEXT; } if(flags & ~(SSH_FXF_ACCESS_DISPOSITION |SSH_FXF_APPEND_DATA |SSH_FXF_APPEND_DATA_ATOMIC |SSH_FXF_TEXT_MODE)) return error("future SSH_FXP_OPEN flags (%#"PRIx32") cannot be emulated in protocol %d", flags, protocol->version); sftp_send_begin(&fakeworker); sftp_send_uint8(&fakeworker, SSH_FXP_OPEN); sftp_send_uint32(&fakeworker, id = newid()); sftp_send_path(&fakejob, &fakeworker, makeabspath(path)); sftp_send_uint32(&fakeworker, pflags); protocol->sendattrs(&fakejob, attrs); sftp_send_end(&fakeworker); } else { sftp_send_begin(&fakeworker); sftp_send_uint8(&fakeworker, SSH_FXP_OPEN); sftp_send_uint32(&fakeworker, id = newid()); sftp_send_path(&fakejob, &fakeworker, makeabspath(path)); sftp_send_uint32(&fakeworker, desired_access); sftp_send_uint32(&fakeworker, flags); protocol->sendattrs(&fakejob, attrs); sftp_send_end(&fakeworker); } if(getresponse(SSH_FXP_HANDLE, id, "SSH_FXP_OPEN") != SSH_FXP_HANDLE) return -1; cpcheck(sftp_parse_string(&fakejob, &hp->data, &hp->len)); return 0; } struct space_available { uint64_t bytes_on_device; uint64_t unused_bytes_on_device; uint64_t bytes_available_to_user; uint64_t unused_bytes_available_to_user; uint32_t bytes_per_allocation_unit; }; static int sftp_space_available(const char *path, struct space_available *as) { uint32_t id; remote_cwd(); sftp_send_begin(&fakeworker); sftp_send_uint8(&fakeworker, SSH_FXP_EXTENDED); sftp_send_uint32(&fakeworker, id = newid()); sftp_send_string(&fakeworker, "space-available"); sftp_send_path(&fakejob, &fakeworker, makeabspath(path)); sftp_send_end(&fakeworker); if(getresponse(SSH_FXP_EXTENDED_REPLY, id, "space-available") != SSH_FXP_EXTENDED_REPLY) return -1; cpcheck(sftp_parse_uint64(&fakejob, &as->bytes_on_device)); cpcheck(sftp_parse_uint64(&fakejob, &as->unused_bytes_on_device)); cpcheck(sftp_parse_uint64(&fakejob, &as->bytes_available_to_user)); cpcheck(sftp_parse_uint64(&fakejob, &as->unused_bytes_available_to_user)); cpcheck(sftp_parse_uint32(&fakejob, &as->bytes_per_allocation_unit)); return 0; } static int sftp_mkdir(const char *path, mode_t mode) { struct sftpattr attrs; uint32_t id; remote_cwd(); if(mode == (mode_t)-1) attrs.valid = 0; else { attrs.valid = SSH_FILEXFER_ATTR_PERMISSIONS; attrs.permissions = mode; } sftp_send_begin(&fakeworker); sftp_send_uint8(&fakeworker, SSH_FXP_MKDIR); sftp_send_uint32(&fakeworker, id = newid()); sftp_send_path(&fakejob, &fakeworker, makeabspath(path)); protocol->sendattrs(&fakejob, &attrs); sftp_send_end(&fakeworker); getresponse(SSH_FXP_STATUS, id, "SSH_FXP_MKDIR"); return status(); } static char *sftp_readlink(const char *path) { char *resolved; uint32_t u32, id; remote_cwd(); sftp_send_begin(&fakeworker); sftp_send_uint8(&fakeworker, SSH_FXP_READLINK); sftp_send_uint32(&fakeworker, id = newid()); sftp_send_path(&fakejob, &fakeworker, makeabspath(path)); sftp_send_end(&fakeworker); if(getresponse(SSH_FXP_NAME, id, "SSH_FXP_READLINK") != SSH_FXP_NAME) return 0; cpcheck(sftp_parse_uint32(&fakejob, &u32)); if(u32 != 1) fatal("wrong count in SSH_FXP_READLINK reply"); cpcheck(sftp_parse_path(&fakejob, &resolved)); return resolved; } static int sftp_text_seek(const struct client_handle *hp, uint64_t line) { uint32_t id; sftp_send_begin(&fakeworker); sftp_send_uint8(&fakeworker, SSH_FXP_EXTENDED); sftp_send_uint32(&fakeworker, id = newid()); sftp_send_string(&fakeworker, "text-seek"); sftp_send_bytes(&fakeworker, hp->data, hp->len); sftp_send_uint64(&fakeworker, line); sftp_send_end(&fakeworker); getresponse(SSH_FXP_STATUS, id, "text-seek"); return status(); } /* Command line operations */ static int cmd_pwd(int attribute((unused)) ac, char attribute((unused)) **av) { xprintf("%s\n", remote_cwd()); return 0; } static int cmd_cd(int attribute((unused)) ac, char **av) { const char *newcwd; struct sftpattr attrs; remote_cwd(); if(protocol->version >= 6) { /* We can do this more efficiently */ newcwd = sftp_realpath_v6(cwd, SSH_FXP_REALPATH_STAT_ALWAYS, av, &attrs); if(!newcwd) return -1; } else { newcwd = sftp_realpath(makeabspath(av[0])); if(!newcwd) return -1; /* Check it's really a directory */ if(sftp_stat(newcwd, &attrs, SSH_FXP_LSTAT)) return -1; } if(attrs.type != SSH_FILEXFER_TYPE_DIRECTORY) { error("%s is not a directory (type %d)", av[0], attrs.type); return -1; } free(cwd); cwd = xstrdup(newcwd); return 0; } static int cmd_quit(int attribute((unused)) ac, char attribute((unused)) **av) { exit(0); } static int cmd_help(int attribute((unused)) ac, char attribute((unused)) **av); static int cmd_lpwd(int attribute((unused)) ac, char attribute((unused)) **av) { char *lpwd; if(!(lpwd = sftp_getcwd(fakejob.a))) { error("error calling getcwd: %s", strerror(errno)); return -1; } xprintf("%s\n", lpwd); return 0; } static int cmd_lcd(int attribute((unused)) ac, char **av) { if(chdir(av[0]) < 0) { error("error calling chdir: %s", strerror(errno)); return -1; } return 0; } static int sort_by_name(const void *av, const void *bv) { const struct sftpattr *const a = av, *const b = bv; return strcmp(a->name, b->name); } static int sort_by_size(const void *av, const void *bv) { const struct sftpattr *const a = av, *const b = bv; if(a->valid & b->valid & SSH_FILEXFER_ATTR_SIZE) { if(a->size < b->size) return -1; else if(a->size > b->size) return 1; } return sort_by_name(av, bv); } static int sort_by_mtime(const void *av, const void *bv) { const struct sftpattr *const a = av, *const b = bv; if(a->valid & b->valid & SSH_FILEXFER_ATTR_MODIFYTIME) { if(a->mtime.seconds < b->mtime.seconds) return -1; else if(a->mtime.seconds > b->mtime.seconds) return 1; if(a->valid & b->valid & SSH_FILEXFER_ATTR_SUBSECOND_TIMES) { if(a->mtime.nanoseconds < b->mtime.nanoseconds) return -1; else if(a->mtime.nanoseconds > b->mtime.nanoseconds) return 1; } } return sort_by_name(av, bv); } /* Reverse an array in place */ static void reverse(void *array, size_t count, size_t size) { if(array) { void *tmp = xmalloc(size); char *const base = array; size_t n; /* If size is even then size/2 is the first half of the array and that's fine. * If size is odd then size/2 goes up to but excludes the middle member * which is also fine. */ for(n = 0; n < size / 2; ++n) { memcpy(tmp, base + n * size, size); memcpy(base + n * size, base + (count - n - 1) * size, size); memcpy(base + (count - n - 1) * size, tmp, size); } free(tmp); } } static int cmd_ls(int ac, char **av) { const char *options, *path; struct sftpattr *attrs, *allattrs = 0, fileattrs; size_t nattrs, nallattrs = 0, n, m, i, maxnamewidth = 0; struct client_handle h; size_t cols, rows; int singlefile; remote_cwd(); if(ac > 0 && av[0][0] == '-') { options = *av++; --ac; } else options = ""; path = ac > 0 ? av[0] : remote_cwd(); /* See what type the file is */ if(sftp_stat(path, &fileattrs, SSH_FXP_LSTAT)) return -1; if(fileattrs.type != SSH_FILEXFER_TYPE_DIRECTORY || strchr(options, 'd')) { /* The file is not a directory, or we used -d */ allattrs = &fileattrs; nallattrs = 1; singlefile = 1; } else { const int include_dotfiles = !!strchr(options, 'a'); /* The file is a directory and we did not use -d */ singlefile = 0; if(sftp_opendir(path, &h)) return -1; for(;;) { if(sftp_readdir(&h, &attrs, &nattrs)) { sftp_close(&h); free(allattrs); return -1; } if(!nattrs) break; /* eof */ allattrs = xrecalloc(allattrs, nattrs + nallattrs, sizeof *attrs); for(n = 0; n < nattrs; ++n) { const size_t w = wcswidth(attrs[n].wname, SIZE_MAX); if(include_dotfiles || attrs[n].name[0] != '.') { if(w > maxnamewidth) maxnamewidth = w; allattrs[nallattrs++] = attrs[n]; } } } sftp_close(&h); } if(!strchr(options, 'f')) { int (*sorter)(const void *, const void *); if(strchr(options, 'S')) sorter = sort_by_size; else if(strchr(options, 't')) sorter = sort_by_mtime; else sorter = sort_by_name; if(nallattrs) qsort(allattrs, nallattrs, sizeof *allattrs, sorter); if(strchr(options, 'r')) reverse(allattrs, nallattrs, sizeof *allattrs); } if(strchr(options, 'l') || strchr(options, 'n')) { /* long listing */ time_t now; struct tm nowtime; const unsigned long flags = (strchr(options, 'n') ? FORMAT_PREFER_NUMERIC_UID : 0)|FORMAT_PREFER_LOCALTIME|FORMAT_ATTRS; /* We'd like to know what year we're in for dates in longname */ time(&now); gmtime_r(&now, &nowtime); for(n = 0; n < nallattrs; ++n) { struct sftpattr *const attrs = &allattrs[n]; if(attrs->type == SSH_FILEXFER_TYPE_SYMLINK && !attrs->target) { if(singlefile) attrs->target = sftp_readlink(attrs->name); else { char *const fullname = sftp_alloc(fakejob.a, strlen(path) + strlen(attrs->name) + 2); strcpy(fullname, path); strcat(fullname, "/"); strcat(fullname, attrs->name); D(("%s -> %s", attrs->name, fullname)); attrs->target = sftp_readlink(fullname); } } xprintf("%s\n", sftp_format_attr(fakejob.a, attrs, nowtime.tm_year, flags)); } } else if(strchr(options, '1')) { /* single-column listing */ for(n = 0; n < nallattrs; ++n) xprintf("%s\n", allattrs[n].name); } else { /* multi-column listing. First figure out the terminal width. */ /* We have C columns of width M, with C-1 single-character blank columns * between them. So the total width is C * M + (C - 1). The lot had * better fit into W columns in total. * * We want to find the maximum C such that: * C * M + C - 1 <= W * <=> C * (M + 1) <= W + 1 * <=> C <= (W + 1) / (M + 1) * * Therefore we calculate C=floor[(W + 1) / (M + 1)]. * * For instance W=80 and M=40 gives 81/41 = 1 * W=80 and M=39 gives 81/39 = 2 * W=80 and M=27 gives 81/28 = 2 * W=80 and M=26 gives 81/27 = 3 * and so on. * * If we end up with 0 columns we round it up to 1 and put up with the * overflow. */ cols = (terminal_width + 1) / (maxnamewidth + 1); if(!cols) cols = 1; /* Now we have the number of columns. The N files are conventionally * listed down the columns, in this sort of order: * * 0 4 8 * 1 5 9 * 2 6 10 * 3 7 11 * * Up to the last C-1 columns may be missing their final row. So there * must be ceil(N / C) rows. We calculate this slightly indirectly. */ rows = (nallattrs + cols - 1) / cols; for(n = 0; n < rows; ++n) { for(m = 0; m < cols && (i = n + m * rows) < nallattrs; ++m) { const size_t w = wcswidth(allattrs[i].wname, SIZE_MAX); xprintf("%s%*s", allattrs[i].name, (m + 1 < cols && i + rows < nallattrs ? (int)(maxnamewidth - w + 1) : 0), ""); } xprintf("\n"); } } if(allattrs != &fileattrs) free(allattrs); return 0; } static int cmd_lls(int ac, char **av) { const char **args = sftp_alloc(fakejob.a, (ac + 2) * sizeof (char *)); int n = 0; pid_t pid; args[n++] = "ls"; while(ac--) args[n++] = *av++; args[n] = 0; if(!(pid = xfork())) { execvp(args[0], (void *)args); fatal("executing ls: %s", strerror(errno)); } if(waitpid(pid, &n, 0) < 0) { fatal("error calling waitpid: %s", strerror(errno)); if(n) { error("ls returned status %#x", n); return -1; } } return 0; } static int cmd_lumask(int ac, char **av) { mode_t n; if(ac) { errno = 0; n = strtol(av[0], 0, 8); if(errno) { error("invalid umask: %s", strerror(errno)); return -1; } if(n != (n & 0777)) { error("umask out of range"); return -1; } umask(n); } else { n = umask(0); umask(n); xprintf("%03o\n", (unsigned)n); } return 0; } static int cmd_lmkdir(int attribute((unused)) ac, char **av) { if(mkdir(av[0], 0777) < 0) { error("creating directory %s: %s", av[0], strerror(errno)); return -1; } return 0; } static int cmd_chown(int attribute((unused)) ac, char **av) { struct sftpattr attrs; if(sftp_stat(av[1], &attrs, SSH_FXP_STAT)) return -1; if(protocol->version >= 4) { if(!(attrs.valid & SSH_FILEXFER_ATTR_OWNERGROUP)) return error("cannot determine former owner/group"); attrs.owner = av[0]; } else { if(!(attrs.valid & SSH_FILEXFER_ATTR_UIDGID)) return error("cannot determine former UID/GID"); attrs.uid = atoi(av[0]); } return sftp_setstat(av[1], &attrs); } static int cmd_chgrp(int attribute((unused)) ac, char **av) { struct sftpattr attrs; if(sftp_stat(av[1], &attrs, SSH_FXP_STAT)) return -1; if(protocol->version >= 4) { if(!(attrs.valid & SSH_FILEXFER_ATTR_OWNERGROUP)) return error("cannot determine former owner/group"); attrs.group = av[0]; } else { if(!(attrs.valid & SSH_FILEXFER_ATTR_UIDGID)) return error("cannot determine former UID/GID"); attrs.gid = atoi(av[0]); } return sftp_setstat(av[1], &attrs); } static int cmd_chmod(int attribute((unused)) ac, char **av) { struct sftpattr attrs; attrs.valid = SSH_FILEXFER_ATTR_PERMISSIONS; errno = 0; attrs.permissions = strtol(av[0], 0, 8); if(errno || attrs.permissions != (attrs.permissions & 07777)) error("invalid permissions: %s", strerror(errno)); return sftp_setstat(av[1], &attrs); } static int cmd_rm(int attribute((unused)) ac, char **av) { return sftp_remove(av[0]); } static int cmd_rmdir(int attribute((unused)) ac, char **av) { return sftp_rmdir(av[0]); } static int cmd_mv(int attribute((unused)) ac, char **av) { if(ac == 3) { const char *ptr = av[0]; int c; unsigned flags = 0; int posixrename = 0; if(*ptr++ != '-') return error("invalid options '%s'", av[0]); while((c = *ptr++)) { switch(c) { case 'n': flags |= SSH_FXF_RENAME_NATIVE; break; case 'a': flags |= SSH_FXF_RENAME_ATOMIC; break; case 'o': flags |= SSH_FXF_RENAME_OVERWRITE; break; case 'p': posixrename = 1; break; default: return error("invalid options '%s'", av[0]); } } if(posixrename) return sftp_prename(av[1], av[2]); else return sftp_rename(av[1], av[2], flags); } else return sftp_rename(av[0], av[1], 0); } static int cmd_symlink(int attribute((unused)) ac, char **av) { return sftp_link(av[0], av[1], 1); } static int cmd_link(int attribute((unused)) ac, char **av) { return sftp_link(av[0], av[1], 0); } /* cmd_get uses a background thread to send requests */ struct outstanding_read { uint32_t id; /* 0 or a request ID */ off_t offset; /* offset in source file */ }; struct reader_data { pthread_mutex_t m; /* protects everything here */ pthread_cond_t c1; /* signaled when a response received */ pthread_cond_t c2; /* signaled when a request sent */ struct client_handle h; /* target handle */ struct outstanding_read *reqs; /* in-flight requests */ uint64_t next_offset; /* next offset */ int outstanding, eof, failed; uint64_t size; /* file size */ uint64_t written; /* byte written so far */ int fd; /* file to write to */ char *local, *tmp; /* output filename */ /* For text translation: */ FILE *translated_fp; /* file to write to (in stdio-speak) */ size_t translated_state; /* how far thru newline we've seen */ }; static void *reader_thread(void *arg) { struct reader_data *const r = arg; int n; uint32_t id, len; ferrcheck(pthread_mutex_lock(&r->m)); while(!r->eof && !r->failed) { /* Wait for a job to be reaped */ while(r->outstanding == nrequests && !r->eof) ferrcheck(pthread_cond_wait(&r->c1, &r->m)); /* Send as many jobs as we can */ while(r->outstanding < nrequests && !r->eof) { /* Find a spare slot */ for(n = 0; n < nrequests && r->reqs[n].id; ++n) ; assert(n < nrequests); id = newid(); sftp_send_begin(&fakeworker); sftp_send_uint8(&fakeworker, SSH_FXP_READ); sftp_send_uint32(&fakeworker, id); sftp_send_bytes(&fakeworker, r->h.data, r->h.len); sftp_send_uint64(&fakeworker, r->next_offset); if(r->size == (uint64_t)-1 || r->size - r->next_offset > buffersize) len = buffersize; else { len = (uint32_t)(r->size - r->next_offset); r->eof = 1; } sftp_send_uint32(&fakeworker, len); /* Fill in the outstanding_read once we've sent it */ r->reqs[n].id = id; r->reqs[n].offset = r->next_offset; ++r->outstanding; r->next_offset += buffersize; /* Don't hold the lock while doing the send itself */ ferrcheck(pthread_mutex_unlock(&r->m)); sftp_send_end(&fakeworker); ferrcheck(pthread_mutex_lock(&r->m)); /* Notify the main threader that we set off a request */ ferrcheck(pthread_cond_signal(&r->c2)); } } ferrcheck(pthread_mutex_unlock(&r->m)); return 0; } /* Inbound text file translation */ static int write_translated_init(struct reader_data *r) { if(!(r->translated_fp = fdopen(r->fd, "w"))) return error("error calling fdopen: %s", strerror(errno)); r->translated_state = 0; return 0; } static int write_translated(struct reader_data *r, const void *vptr, size_t bytes) { const char *ptr = vptr; while(bytes > 0) { const int c = (unsigned char)*ptr++; --bytes; if(c == newline[r->translated_state]) { /* We've seen part of a newline */ ++r->translated_state; if(!newline[r->translated_state]) { /* We must have seen a whole newline */ if(putc('\n', r->translated_fp) < 0) return -1; r->translated_state = 0; } else { /* We're part way thru something that might be a newline. Keep * going. */ } } else { if(r->translated_state) { /* We're part way thru something that turned out not to be a newline. */ if(fwrite(newline, 1, r->translated_state, r->translated_fp) != r->translated_state) return -1; r->translated_state = 0; /* Try again from the current point. */ /* Note that we assume that the newline sequence doesn't contain * repetitions. If you have a (completely bonkers!) platform that * violates this assumption then you'll have to write a cleverer state * machine here. */ continue; } else { if(putc(c, r->translated_fp) < 0) return -1; } } } return 0; } static int write_translated_done(struct reader_data *r) { int rc = 0; if(r->translated_fp) { if(r->translated_state) { /* The file ends part way thru something that starts out like a newline * sequence but turns out not to be one. */ if(fwrite(newline, 1, r->translated_state, r->translated_fp) != r->translated_state) rc = -1; r->translated_state = 0; } if(fclose(r->translated_fp) < 0) rc = -1; r->translated_fp = 0; } return rc; } static void reap_write_response(struct reader_data *r) { uint8_t rtype; uint32_t st, len; int n, rc; /* Get the next response and count it down. We don't hold the lock while * were awaiting the response. */ ferrcheck(pthread_mutex_unlock(&r->m)); rtype = getresponse(-1, 0, "SSH_FXP_READ"); ferrcheck(pthread_mutex_lock(&r->m)); --r->outstanding; /* If we've already failed then we don't care what the response was */ if(r->failed) return; switch(rtype) { case SSH_FXP_STATUS: cpcheck(sftp_parse_uint32(&fakejob, &st)); if(st == SSH_FX_EOF) r->eof = 1; else { status(); r->failed = 1; } break; case SSH_FXP_DATA: /* Find the right request */ for(n = 0; n < nrequests && fakejob.id != r->reqs[n].id; ++n) ; assert(n < nrequests); /* Free up this slot */ r->reqs[n].id = 0; /* We don't fully parse the string but instead write it out from the * input buffer it's sitting in. */ cpcheck(sftp_parse_uint32(&fakejob, &len)); /* We don't care what order the responses come in, we just write them to * the right place in the file according to what we asked for. There's * not much point releasing the lock while doing the write - the * background thread will have done all it wants while we were awaiting * the response. * * In text mode we can rely on the responses arriving in the correct * order. */ if(textmode) { /* We must replace each instance of the newline string with \n */ rc = write_translated(r, fakejob.ptr, len); } else rc = pwrite(r->fd, fakejob.ptr, len, r->reqs[n].offset); if(rc < 0) { error("error writing to %s: %s", r->tmp, strerror(errno)); r->failed = 1; return; } r->written += len; progress(r->local, r->written, r->size); break; default: fatal("unexpected response %d to SSH_FXP_READ", rtype); } } static int cmd_get(int ac, char **av) { int preserve = 0; const char *e; char *remote; struct reader_data r; struct sftpattr attrs; pthread_t tid; struct timeval started, finished; double elapsed; uint32_t flags = 0; int seek = 0; uint64_t line = 0; memset(&attrs, 0, sizeof attrs); memset(&r, 0, sizeof r); r.fd = -1; if(av[0][0] == '-') { const char *s = *av++; ++s; while(*s) { switch(*s++) { case 'P': preserve = 1; break; case 'f': flags |= SSH_FXF_NOFOLLOW; break; case 'L': seek = 1; line = (uint64_t)strtoull(s, 0, 10); s = ""; break; default: return error("unknown get option -%c'", s[-1]); } } --ac; } remote = *av++; --ac; if(ac) { r.local = *av++; --ac; } else r.local = basename(remote); /* we'll write to a temporary file */ r.tmp = sftp_alloc(fakejob.a, strlen(r.local) + 5); sprintf(r.tmp, "%s.new", r.local); if((r.fd = open(r.tmp, O_WRONLY|O_TRUNC|O_CREAT, 0666)) < 0) { error("error opening %s: %s", r.tmp, strerror(errno)); goto error; } if(textmode) { flags |= SSH_FXF_TEXT_MODE; if(write_translated_init(&r)) goto error; r.fd = -1; } /* open the remote file */ if(sftp_open(remote, ACE4_READ_DATA|ACE4_READ_ATTRIBUTES, SSH_FXF_OPEN_EXISTING|flags, &attrs, &r.h)) goto error; /* stat the file */ if(sftp_fstat(&r.h, &attrs)) goto error; if(!textmode && (attrs.valid & SSH_FILEXFER_ATTR_SIZE)) { /* We know how big the file is. Check we can fit it! */ if((uint64_t)(off_t)attrs.size != attrs.size) { error("remote file %s is too large (%"PRIu64" bytes)", remote, attrs.size); goto error; } r.size = attrs.size; } else /* We don't know how big the file is. We'll just keep on reading until we * get an EOF. This includes text files where translation may make the * size read back with fstat a lie. */ r.size = (uint64_t)-1; if(textmode && seek) { if(sftp_text_seek(&r.h, line)) goto error; } gettimeofday(&started, 0); ferrcheck(pthread_mutex_init(&r.m, 0)); ferrcheck(pthread_cond_init(&r.c1, 0)); ferrcheck(pthread_cond_init(&r.c2, 0)); r.reqs = sftp_alloc(fakejob.a, nrequests * sizeof *r.reqs); ferrcheck(pthread_create(&tid, 0, reader_thread, &r)); ferrcheck(pthread_mutex_lock(&r.m)); /* If there are requests in flight, we must keep going whatever else * is happening in order to process their replies. * If there are no requests in flight then we keep going until * we reach EOF or an error is detected. */ while(!r.eof && !r.failed) { /* Wait until there's at least one request in flight */ while(!r.outstanding) ferrcheck(pthread_cond_wait(&r.c2, &r.m)); reap_write_response(&r); /* Notify the background thread that something changed. */ ferrcheck(pthread_cond_signal(&r.c1)); } ferrcheck(pthread_mutex_unlock(&r.m)); /* Wait for the background thread to finish up */ ferrcheck(pthread_join(tid, 0)); /* Reap any remaining jobs */ ferrcheck(pthread_mutex_lock(&r.m)); while(r.outstanding) reap_write_response(&r); ferrcheck(pthread_mutex_unlock(&r.m)); /* Tear all the thread objects down */ ferrcheck(pthread_mutex_destroy(&r.m)); ferrcheck(pthread_cond_destroy(&r.c1)); ferrcheck(pthread_cond_destroy(&r.c2)); progress(0, 0, 0); if(r.failed) goto error; gettimeofday(&finished, 0); if(progress_indicators) { elapsed = ((finished.tv_sec - started.tv_sec) + (finished.tv_usec - started.tv_usec) / 1000000.0); xprintf("%"PRIu64" bytes in %.1f seconds", r.written, elapsed); if(elapsed > 0.1) xprintf(" %.0f bytes/sec", r.written / elapsed); xprintf("\n"); } /* Close the handle */ sftp_close(&r.h); r.h.len = 0; if(preserve) { /* Set permissions etc */ attrs.valid &= ~SSH_FILEXFER_ATTR_SIZE; /* don't truncate */ attrs.valid &= ~SSH_FILEXFER_ATTR_UIDGID; /* different mapping! */ if(sftp_set_fstatus(fakejob.a, r.fd, &attrs, &e) != SSH_FX_OK) { error("cannot %s %s: %s", e, r.tmp, strerror(errno)); goto error; } } if(textmode) { if(write_translated_done(&r)) { error("error writing to %s: %s", r.tmp, strerror(errno)); goto error; } } else if(close(r.fd) < 0) { error("error closing %s: %s", r.tmp, strerror(errno)); r.fd = -1; goto error; } if(rename(r.tmp, r.local) < 0) { error("error renaming %s: %s", r.tmp, strerror(errno)); goto error; } return 0; error: write_translated_done(&r); /* ok to call if not initialized */ if(r.fd >= 0) close(r.fd); if(r.tmp) unlink(r.tmp); if(r.h.len) sftp_close(&r.h); return -1; } /* put uses a thread to gather responses */ struct outstanding_write { uint32_t id; /* or 0 for empty slot */ ssize_t n; /* size of this request */ }; struct writer_data { pthread_mutex_t m; /* protects everything here */ pthread_cond_t c1; /* signal when writer modifies */ pthread_cond_t c2; /* signal when reader modifies */ int failed; /* set on failure */ int outstanding; /* number of outstanding requests */ int finished; /* set when writer finished */ struct outstanding_write *reqs; /* outstanding requests */ const char *remote; /* remote path */ uint64_t written, total; /* total size */ }; static void *writer_thread(void *arg) { struct writer_data *const w = arg; int i; uint32_t st; ferrcheck(pthread_mutex_lock(&w->m)); /* Keep going until the writer has finished and there are no outstanding * requests left */ while(!w->finished || w->outstanding) { /* Wait until there's at least one request outstanding */ if(!w->outstanding) { ferrcheck(pthread_cond_wait(&w->c1, &w->m)); continue; } /* Await the incoming response */ getresponse(SSH_FXP_STATUS, 0/*don't care about id*/, "SSH_FXP_WRITE"); ferrcheck(pthread_cond_signal(&w->c2)); /* Find the request ID */ for(i = 0; i < nrequests && w->reqs[i].id != fakejob.id; ++i) ; assert(i < nrequests); --w->outstanding; cpcheck(sftp_parse_uint32(&fakejob, &st)); if(st == SSH_FX_OK) { w->written += w->reqs[i].n; w->reqs[i].id = 0; progress(w->remote, w->written, w->total); } else if(!w->failed) { /* Only report the first error */ status(); w->failed = 1; } } progress(0, 0, 0); /* clear progress indicator */ ferrcheck(pthread_mutex_unlock(&w->m)); return 0; } static int cmd_put(int ac, char **av) { char *local; const char *remote; struct sftpattr attrs; struct stat sb; int fd = -1, i, preserve = 0, failed = 0, eof = 0; struct client_handle h; off_t offset; ssize_t n; struct writer_data w; pthread_t tid; struct timeval started, finished; double elapsed; uint32_t id; FILE *fp = 0; uint32_t disp = SSH_FXF_CREATE_TRUNCATE, flags = 0; int setmode = 0; mode_t mode = 0; memset(&h, 0, sizeof h); memset(&attrs, 0, sizeof attrs); memset(&w, 0, sizeof w); if(av[0][0] == '-') { const char *s = *av++; ++s; while(*s) { switch(*s++) { case 'P': preserve = 1; break; case 'a': disp = SSH_FXF_OPEN_OR_CREATE; flags |= SSH_FXF_APPEND_DATA; break; case 'A': disp = SSH_FXF_OPEN_EXISTING; flags |= SSH_FXF_APPEND_DATA; break; case 'f': flags |= SSH_FXF_NOFOLLOW; break; case 't': disp = SSH_FXF_CREATE_NEW; break; case 'e': disp = SSH_FXF_TRUNCATE_EXISTING; break; case 'd': flags |= SSH_FXF_DELETE_ON_CLOSE; break; case 'm': setmode = 1; mode = strtoul(s, 0, 8); s = ""; break; default: return error("unknown put option -%c'", s[-1]); } } --ac; } local = *av++; --ac; if(ac) { remote = *av++; --ac; } else remote = basename(local); if((fd = open(local, O_RDONLY)) < 0) { error("cannot open %s: %s", local, strerror(errno)); goto error; } if(fstat(fd, &sb) < 0) { error("cannot stat %s: %s", local, strerror(errno)); goto error; } if(S_ISDIR(sb.st_mode)) { error("%s is a directory", local); goto error; } if(S_ISREG(sb.st_mode)) { w.total = (uint64_t)sb.st_size; if((off_t)w.total != sb.st_size) { error("%s is too large to upload via SFTP", local); goto error; } } else w.total = (uint64_t)-1; if(preserve) { sftp_stat_to_attrs(fakejob.a, &sb, &attrs, 0xFFFFFFFF, local); /* Mask out things that don't make sense: we set the size by dint of * uploading data, we don't want to try to set a numeric UID or GID, and we * cannot set the allocation size or link count. */ attrs.valid &= ~(SSH_FILEXFER_ATTR_SIZE |SSH_FILEXFER_ATTR_LINK_COUNT |SSH_FILEXFER_ATTR_UIDGID); /* Mask off attributes that don't work in this protocol version */ attrs.valid &= attrmask; assert(!(attrs.valid & SSH_FILEXFER_ATTR_CTIME)); attrs.attrib_bits &= ~SSH_FILEXFER_ATTR_FLAGS_HIDDEN; } if(setmode) { attrs.valid |= SSH_FILEXFER_ATTR_PERMISSIONS; attrs.permissions = mode; } if(textmode) flags |= SSH_FXF_TEXT_MODE; if(sftp_open(remote, ACE4_WRITE_DATA|ACE4_WRITE_ATTRIBUTES, disp | flags, &attrs, &h)) goto error; if(textmode) { if(!(fp = fdopen(fd, "r"))) { error("error calling fdopen: %s", strerror(errno)); goto error; } fd = -1; } w.reqs = sftp_alloc(fakejob.a, nrequests * sizeof *w.reqs); w.remote = remote; gettimeofday(&started, 0); ferrcheck(pthread_mutex_init(&w.m, 0)); ferrcheck(pthread_cond_init(&w.c1, 0)); ferrcheck(pthread_cond_init(&w.c2, 0)); ferrcheck(pthread_create(&tid, 0, writer_thread, &w)); ferrcheck(pthread_mutex_lock(&w.m)); offset = 0; while(!w.failed && !eof && !failed) { /* Wait until we're allowed to send another request */ if(w.outstanding >= nrequests) { ferrcheck(pthread_cond_wait(&w.c2, &w.m)); continue; } /* Release the lock while we mess around with IO */ ferrcheck(pthread_mutex_unlock(&w.m)); /* Construct a write command */ sftp_send_begin(&fakeworker); sftp_send_uint8(&fakeworker, SSH_FXP_WRITE); sftp_send_uint32(&fakeworker, id = newid()); sftp_send_bytes(&fakeworker, h.data, h.len); sftp_send_uint64(&fakeworker, offset); sftp_send_need(fakejob.worker, buffersize + 4); if(textmode) { char *const start = ((char *)fakejob.worker->buffer + fakejob.worker->bufused + 4); char *ptr = start; size_t left = buffersize; const size_t newline_len = strlen(newline); int c; /* We will need to perform a translation step. We read from stdio into * our buffer expanding newlines as necessary. */ while(left > 0 && (c = getc(fp)) != EOF) { if(c == '\n') { /* We found a newline. Let us translated it to the desired wire * format. */ if(left >= newline_len) { /* We can fit a translated newline here */ strcpy(ptr, newline); ptr += newline_len; left -= newline_len; } else { /* Whoops, we cannot fit a translated newline in. */ if(ungetc(c, fp) < 0) fatal("ungetc: %s", strerror(errno)); } } else { /* This character is not a newline. */ *ptr++ = c; --left; } } /* Fake up n to look like the result of read() */ if(ferror(fp)) n = -1; else n = ptr - start; /* There is always space to write at least one translated newline (see * main() below) so n will only be 0 if we genuinely are at EOF. */ } else { /* We read straight into our output buffer */ n = read(fd, fakejob.worker->buffer + fakejob.worker->bufused + 4, buffersize); } if(n > 0) { /* Update the reqs[] array first, so that a reply can't arrive before its * ID is listed */ ferrcheck(pthread_mutex_lock(&w.m)); for(i = 0; i < nrequests && w.reqs[i].id; ++i) ; assert(i < nrequests); w.reqs[i].id = id; w.reqs[i].n = n; ++w.outstanding; ferrcheck(pthread_mutex_unlock(&w.m)); /* Send off the write request with however much data we read */ sftp_send_uint32(&fakeworker, n); fakejob.worker->bufused += n; sftp_send_end(&fakeworker); offset += n; } else if(n == 0) { /* We reached EOF on the input file */ eof = 1; } else { /* Error reading the input file */ error("error reading %s: %s", local, strerror(errno)); failed = 1; } ferrcheck(pthread_mutex_lock(&w.m)); ferrcheck(pthread_cond_signal(&w.c1)); } w.finished = 1; ferrcheck(pthread_cond_signal(&w.c1)); ferrcheck(pthread_mutex_unlock(&w.m)); ferrcheck(pthread_join(tid, 0)); assert(w.outstanding == 0); ferrcheck(pthread_mutex_destroy(&w.m)); ferrcheck(pthread_cond_destroy(&w.c1)); ferrcheck(pthread_cond_destroy(&w.c2)); if(failed || w.failed) goto error; gettimeofday(&finished, 0); if(progress_indicators) { elapsed = ((finished.tv_sec - started.tv_sec) + (finished.tv_usec - started.tv_usec) / 1000000.0); xprintf("%"PRIu64" bytes in %.1f seconds", w.written, elapsed); if(elapsed > 0.1) xprintf(" %.0f bytes/sec", w.written / elapsed); xprintf("\n"); } if(fd >= 0) { close(fd); fd = -1; } if(fp) { fclose(fp); fp = 0; } if(preserve) { /* mtime at least will be nadgered */ if(sftp_fsetstat(&h, &attrs)) goto error; } sftp_close(&h); return 0; error: if(fp) fclose(fp); if(fd >= 0) close(fd); if(h.len) { sftp_close(&h); sftp_remove(remote); /* tidy up our mess */ } return -1; } static int cmd_progress(int ac, char **av) { if(ac) { if(!strcmp(av[0], "on")) progress_indicators = 1; else if(!strcmp(av[0], "off")) progress_indicators = 0; else return error("invalid progress option '%s'", av[0]); } else progress_indicators ^= 1; return 0; } static int cmd_text(int attribute((unused)) ac, char attribute((unused)) **av) { if(protocol->version < 4) return error("text mode not supported in protocol version %d", protocol->version); textmode = 1; return 0; } static int cmd_binary(int attribute((unused)) ac, char attribute((unused)) **av) { textmode = 0; return 0; } static int cmd_version(int ac, char attribute((unused)) **av) { if(ac == 1) { const uint32_t id = newid(); sftp_send_begin(&fakeworker); sftp_send_uint8(&fakeworker, SSH_FXP_EXTENDED); sftp_send_uint32(&fakeworker, id); sftp_send_string(&fakeworker, "version-select"); sftp_send_path(&fakejob, &fakeworker, av[0]); sftp_send_end(&fakeworker); getresponse(SSH_FXP_STATUS, id, "version-select"); if(status()) return -1; if(!strcmp(av[0], "3")) protocol = &sftp_v3; else if(!strcmp(av[0], "4")) protocol = &sftp_v4; else if(!strcmp(av[0], "5")) protocol = &sftp_v5; else if(!strcmp(av[0], "6")) protocol = &sftp_v6; else fatal("unknown protocol %s", av[0]); return 0; } else { xprintf("Protocol version: %d\n", protocol->version); if(servername) xprintf("Server vendor: %s\n" "Server name: %s\n" "Server version: %s\n" "Server build: %"PRIu64"\n", vendorname, servername, serverversion, serverbuild); if(serverversions) xprintf("Server supports: %s\n", serverversions); return 0; } } static int cmd_debug(int attribute((unused)) ac, char attribute((unused)) **av) { sftp_debugging = !sftp_debugging; D(("sftp_debugging enabled")); return 0; } static void report_bytes(int width, const char *what, uint64_t howmuch) { static const uint64_t gbyte = (uint64_t)1 << 30; static const uint64_t mbyte = (uint64_t)1 << 20; static const uint64_t kbyte = (uint64_t)1 << 10; if(!howmuch) return; xprintf("%s:%*s ", what, width - (int)strlen(what), ""); if(howmuch >= 8 * gbyte) xprintf("%"PRIu64" Gbytes\n", howmuch / gbyte); else if(howmuch >= 8 * mbyte) xprintf("%"PRIu64" Mbytes\n", howmuch / mbyte); else if(howmuch >= 8 * kbyte) xprintf("%"PRIu64" Kbytes\n", howmuch / kbyte); else xprintf("%"PRIu64" bytes\n", howmuch); } static int cmd_df(int ac, char **av) { struct space_available as; if(sftp_space_available(ac ? av[0] : remote_cwd(), &as)) return -1; report_bytes(32, "Bytes on device", as.bytes_on_device); report_bytes(32, "Unused bytes on device", as.unused_bytes_on_device); report_bytes(32, "Available bytes on device", as.bytes_available_to_user); report_bytes(32, "Unused available bytes on device", as.unused_bytes_available_to_user); report_bytes(32, "Bytes per allocation unit", as.bytes_per_allocation_unit); return 0; } static int cmd_mkdir(int ac, char **av) { const char *path; mode_t mode; if(ac == 2) { mode = strtoul(av[0], 0, 8); path = av[1]; } else { mode = -1; path = av[0]; } return sftp_mkdir(path, mode); } static int cmd_init(int attribute((unused)) ac, char attribute((unused)) **av) { return sftp_init(); } static int cmd_unsupported(int attribute((unused)) ac, char attribute((unused)) **av) { sftp_send_begin(&fakeworker); sftp_send_uint8(&fakeworker, 0xFFFFFFFF); sftp_send_uint32(&fakeworker, 0); /* id */ sftp_send_end(&fakeworker); getresponse(SSH_FXP_STATUS, 0, "_unsupported"); status(); return 0; } static int cmd_ext_unsupported(int attribute((unused)) ac, char attribute((unused)) **av) { sftp_send_begin(&fakeworker); sftp_send_uint8(&fakeworker, SSH_FXP_EXTENDED); sftp_send_uint32(&fakeworker, 0); /* id */ sftp_send_string(&fakeworker, "no-such-sftp-extension@rjk.greenend.org.uk"); sftp_send_end(&fakeworker); getresponse(SSH_FXP_STATUS, 0, "_unsupported"); status(); return 0; } static int cmd_readlink(int attribute((unused)) ac, char **av) { char *r = sftp_readlink(av[0]); if(r) { xprintf("%s\n", r); return 0; } else return -1; } static int cmd_realpath(int attribute((unused)) ac, char **av) { char *r = sftp_realpath(av[0]); if(r) { xprintf("%s\n", r); return 0; } else return -1; } static int cmd_realpath6(int attribute((unused)) ac, char **av) { int control_byte; char *resolved; struct sftpattr attrs; time_t now; struct tm nowtime; if(!strcmp(av[0], "no-check")) control_byte = SSH_FXP_REALPATH_NO_CHECK; else if(!strcmp(av[0], "stat-if")) control_byte = SSH_FXP_REALPATH_STAT_IF; else if(!strcmp(av[0], "stat-always")) control_byte = SSH_FXP_REALPATH_STAT_ALWAYS; else return error("unknown control string '%s'", av[0]); resolved = sftp_realpath_v6(av[1], control_byte, av + 2, &attrs); if(!resolved) return -1; if(attrs.valid) { attrs.name = resolved; time(&now); gmtime_r(&now, &nowtime); xprintf("%s\n", sftp_format_attr(fakejob.a, &attrs, nowtime.tm_year, 0)); } else xprintf("%s\n", resolved); return 0; } static int cmd_lrealpath(int attribute((unused)) ac, char **av) { char *r; unsigned flags; if(!strcmp(av[0], "no-check")) flags = 0; else if(!strcmp(av[0], "stat-if")) flags = RP_READLINK; else if(!strcmp(av[0], "stat-always")) flags = RP_READLINK|RP_MUST_EXIST; else return error("unknown control string '%s'", av[0]); r = sftp_find_realpath(fakejob.a, av[1], flags); if(r) { xprintf("%s\n", r); return 0; } else { perror(0); return -1; } } static int cmd_bad_handle(int attribute((unused)) ac, char attribute((unused)) **av) { struct client_handle h; h.len = 8; h.data = (void *)"\x0\x0\x0\x0\x0\x0\x0\x0"; sftp_readdir(&h, 0, 0); sftp_close(&h); sftp_send_begin(&fakeworker); sftp_send_uint8(&fakeworker, SSH_FXP_READ); sftp_send_uint32(&fakeworker, 0); sftp_send_bytes(&fakeworker, h.data, h.len); sftp_send_uint64(&fakeworker, 0); sftp_send_uint32(&fakeworker, 64); sftp_send_end(&fakeworker); getresponse(SSH_FXP_STATUS, 0, "_bad_handle"); status(); return 0; } static int cmd_bad_packet(int attribute((unused)) ac, char attribute((unused)) **av) { sftp_send_begin(&fakeworker); sftp_send_uint8(&fakeworker, SSH_FXP_READ); /* completely missing ID */ sftp_send_end(&fakeworker); getresponse(SSH_FXP_STATUS, 0, "_bad_packet"); status(); sftp_send_begin(&fakeworker); sftp_send_uint8(&fakeworker, SSH_FXP_READ); sftp_send_uint8(&fakeworker, 0); /* broken ID */ sftp_send_end(&fakeworker); getresponse(SSH_FXP_STATUS, 0, "_bad_packet"); status(); sftp_send_begin(&fakeworker); sftp_send_uint8(&fakeworker, SSH_FXP_READ); sftp_send_uint32(&fakeworker, 0); sftp_send_uint8(&fakeworker, 0); /* truncated handle length */ sftp_send_end(&fakeworker); getresponse(SSH_FXP_STATUS, 0, "_bad_packet"); status(); sftp_send_begin(&fakeworker); sftp_send_uint8(&fakeworker, SSH_FXP_READ); sftp_send_uint32(&fakeworker, 0); sftp_send_uint32(&fakeworker, 64); /* truncated handle */ sftp_send_end(&fakeworker); getresponse(SSH_FXP_STATUS, 0, "_bad_packet"); status(); sftp_send_begin(&fakeworker); sftp_send_uint8(&fakeworker, SSH_FXP_READ); sftp_send_uint32(&fakeworker, 0); sftp_send_uint32(&fakeworker, 0xFFFFFFFF); /* impossibly long handle */ sftp_send_end(&fakeworker); getresponse(SSH_FXP_STATUS, 0, "_bad_packet"); status(); sftp_send_begin(&fakeworker); sftp_send_uint8(&fakeworker, SSH_FXP_READ); sftp_send_uint32(&fakeworker, 0); sftp_send_string(&fakeworker, "12345678"); sftp_send_uint32(&fakeworker, 0); /* truncated uint64 */ sftp_send_end(&fakeworker); getresponse(SSH_FXP_STATUS, 0, "_bad_packet"); status(); sftp_send_begin(&fakeworker); sftp_send_uint8(&fakeworker, SSH_FXP_READLINK); sftp_send_uint32(&fakeworker, 0); sftp_send_uint32(&fakeworker, 0xFFFFFFFF); /* impossibly long string */ sftp_send_end(&fakeworker); getresponse(SSH_FXP_STATUS, 0, "_bad_packet"); status(); sftp_send_begin(&fakeworker); sftp_send_uint8(&fakeworker, SSH_FXP_READLINK); sftp_send_uint32(&fakeworker, 0); sftp_send_uint32(&fakeworker, 32); /* truncated string */ sftp_send_end(&fakeworker); getresponse(SSH_FXP_STATUS, 0, "_bad_packet"); status(); sftp_send_begin(&fakeworker); sftp_send_uint8(&fakeworker, SSH_FXP_READLINK); sftp_send_uint32(&fakeworker, 0); sftp_send_uint8(&fakeworker, 0); /* truncated string length */ sftp_send_end(&fakeworker); getresponse(SSH_FXP_STATUS, 0, "_bad_packet"); status(); return 0; } static int cmd_bad_packet456(int attribute((unused)) ac, char attribute((unused)) **av) { sftp_send_begin(&fakeworker); sftp_send_uint8(&fakeworker, SSH_FXP_SETSTAT); sftp_send_uint32(&fakeworker, 0); sftp_send_string(&fakeworker, "path"); sftp_send_uint32(&fakeworker, 0); /* valid attributes */ /* missing type field */ sftp_send_end(&fakeworker); getresponse(SSH_FXP_STATUS, 0, "_bad_packet"); status(); return 0; } static int cmd_bad_path(int attribute((unused)) ac, char attribute((unused)) **av) { sftp_send_begin(&fakeworker); sftp_send_uint8(&fakeworker, SSH_FXP_OPENDIR); sftp_send_uint32(&fakeworker, 0); sftp_send_string(&fakeworker, "\xC0"); /* can't be the start of a UTF-8 * sequence */ /* missing type field */ sftp_send_end(&fakeworker); getresponse(SSH_FXP_STATUS, 0, "_bad_path"); status(); return 0; } static int cmd_stat(int attribute((unused)) ac, char **av) { struct sftpattr attrs; time_t now; struct tm nowtime; if(sftp_stat(av[0], &attrs, SSH_FXP_STAT)) return -1; time(&now); gmtime_r(&now, &nowtime); xprintf("%s\n", sftp_format_attr(fakejob.a, &attrs, nowtime.tm_year, 0)); return 0; } static int cmd_lstat(int attribute((unused)) ac, char **av) { struct sftpattr attrs; time_t now; struct tm nowtime; if(sftp_stat(av[0], &attrs, SSH_FXP_LSTAT)) return -1; time(&now); gmtime_r(&now, &nowtime); xprintf("%s\n", sftp_format_attr(fakejob.a, &attrs, nowtime.tm_year, 0)); return 0; } static int cmd_truncate(int attribute((unused)) ac, char **av) { struct sftpattr attrs; memset(&attrs, 0, sizeof attrs); attrs.valid = SSH_FILEXFER_ATTR_SIZE; attrs.size = strtoull(av[0], 0, 0); return sftp_setstat(av[1], &attrs); } static int cmd_overlap(int attribute((unused)) ac, char attribute((unused)) **av) { struct sftpattr attrs; static const char a[] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; static const char b[] = "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"; static const char c[] = "cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc"; static const char d[] = "dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd"; static const char expect[] = "aaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbccccccccccccccccdddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd"; char buffer[128]; int n, r, rc = -1; uint32_t ida, idb, idc, idd; int fd = -1; struct client_handle h; memset(&attrs, 0, sizeof attrs); if(sftp_open("dest", ACE4_WRITE_DATA, SSH_FXF_CREATE_TRUNCATE, &attrs, &h)) goto error; if((fd = open("dest", O_RDWR)) < 0) { perror("open dest"); goto error; } for(n = 0; n < 1024; ++n) { sftp_send_begin(&fakeworker); sftp_send_uint8(&fakeworker, SSH_FXP_WRITE); sftp_send_uint32(&fakeworker, ida = newid()); sftp_send_bytes(&fakeworker, h.data, h.len); sftp_send_uint64(&fakeworker, 0); sftp_send_bytes(&fakeworker, a, 64); sftp_send_end(&fakeworker); sftp_send_begin(&fakeworker); sftp_send_uint8(&fakeworker, SSH_FXP_WRITE); sftp_send_uint32(&fakeworker, idb = newid()); sftp_send_bytes(&fakeworker, h.data, h.len); sftp_send_uint64(&fakeworker, 16); sftp_send_bytes(&fakeworker, b, 64); sftp_send_end(&fakeworker); sftp_send_begin(&fakeworker); sftp_send_uint8(&fakeworker, SSH_FXP_WRITE); sftp_send_uint32(&fakeworker, idc = newid()); sftp_send_bytes(&fakeworker, h.data, h.len); sftp_send_uint64(&fakeworker, 32); sftp_send_bytes(&fakeworker, c, 64); sftp_send_end(&fakeworker); sftp_send_begin(&fakeworker); sftp_send_uint8(&fakeworker, SSH_FXP_WRITE); sftp_send_uint32(&fakeworker, idd = newid()); sftp_send_bytes(&fakeworker, h.data, h.len); sftp_send_uint64(&fakeworker, 48); sftp_send_bytes(&fakeworker, d, 64); sftp_send_end(&fakeworker); /* Await responses */ getresponse(SSH_FXP_STATUS, 0, "SSH_FXP_WRITE"); getresponse(SSH_FXP_STATUS, 0, "SSH_FXP_WRITE"); getresponse(SSH_FXP_STATUS, 0, "SSH_FXP_WRITE"); getresponse(SSH_FXP_STATUS, 0, "SSH_FXP_WRITE"); if(lseek(fd, 0, SEEK_SET) < 0) { perror("lseek"); goto error; } r = read(fd, buffer, sizeof buffer); if(r != 48+64) { fprintf(stderr, "expected %d bytes got %d\n", 48+64, r); goto error; } buffer[r] = 0; /* ensure buffer terminated */ if(memcmp(buffer, expect, 48+64)) { fprintf(stderr, "buffer contents mismatch\n" "expect: %s\n" " got: %s\n", expect, buffer); goto error; } if(ftruncate(fd, 0) < 0) { perror("ftruncate"); goto error; } } rc = 0; error: if(fd >= 0) close(fd); return rc; } /* Table of command line operations */ static const struct command commands[] = { { "_bad_handle", 0, 0, cmd_bad_handle, 0, "operate on a bogus handle" }, { "_bad_packet", 0, 0, cmd_bad_packet, 0, "send bad packets" }, { "_bad_packet456", 0, 0, cmd_bad_packet456, 0, "send bad packets (protos >= 4 only)" }, { "_bad_path", 0, 0, cmd_bad_path, 0, "send bad paths" }, { "_ext_unsupported", 0, 0, cmd_ext_unsupported, 0, "send an unsupported extension" }, { "_init", 0, 0, cmd_init, 0, "resend SSH_FXP_INIT" }, { "_lrealpath", 2, 2, cmd_lrealpath, "CONTROL PATH", "expand a local path name" }, { "_overlap", 0, 0, cmd_overlap, "", "test overlapping writes" }, { "_unsupported", 0, 0, cmd_unsupported, 0, "send an unsupported command" }, { "binary", 0, 0, cmd_binary, 0, "binary mode" }, { "bye", 0, 0, cmd_quit, 0, "quit" }, { "cd", 1, 1, cmd_cd, "DIR", "change remote directory" }, { "chgrp", 2, 2, cmd_chgrp, "GID PATH", "change remote file group" }, { "chmod", 2, 2, cmd_chmod, "OCTAL PATH", "change remote file permissions" }, { "chown", 2, 2, cmd_chown, "UID PATH", "change remote file ownership" }, { "debug", 0, 0, cmd_debug, 0, "toggle sftp_debugging" }, { "df", 0, 1, cmd_df, "[PATH]", "query available space" }, { "exit", 0, 0, cmd_quit, 0, "quit" }, { "get", 1, 3, cmd_get, "[-PfL] REMOTE-PATH [LOCAL-PATH]", "retrieve a remote file" }, { "help", 0, 0, cmd_help, 0, "display help" }, { "lcd", 1, 1, cmd_lcd, "DIR", "change local directory" }, { "link", 2, 2, cmd_link, "OLDPATH NEWPATH", "create a remote hard link" }, { "lpwd", 0, 0, cmd_lpwd, "DIR", "display current local directory" }, { "lls", 0, INT_MAX, cmd_lls, "[OPTIONS] [LOCAL-PATH]", "list local directory" }, { "lmkdir", 1, 1, cmd_lmkdir, "LOCAL-PATH", "create local directory" }, { "ls", 0, 2, cmd_ls, "[OPTIONS] [PATH]", "list remote directory" }, { "lstat", 1, 1, cmd_lstat, "PATH", "lstat a file" }, { "lumask", 0, 1, cmd_lumask, "OCTAL", "get or set local umask" }, { "mkdir", 1, 2, cmd_mkdir, "[MODE] DIRECTORY", "create a remote directory" }, { "mv", 2, 3, cmd_mv, "[-naop] OLDPATH NEWPATH", "rename a remote file" }, { "progress", 0, 1, cmd_progress, "[on|off]", "set or toggle progress indicators" }, { "put", 1, 3, cmd_put, "[-PaftemMODE] LOCAL-PATH [REMOTE-PATH]", "upload a file" }, { "pwd", 0, 0, cmd_pwd, 0, "display current remote directory" }, { "quit", 0, 0, cmd_quit, 0, "quit" }, { "readlink", 1, 1, cmd_readlink, "PATH", "inspect a symlink" }, { "realpath", 1, 1, cmd_realpath, "PATH", "expand a path name" }, { "realpath6", 2, INT_MAX, cmd_realpath6, "CONTROL PATH [COMPOSE...]", "expand a path name" }, { "rename", 2, 2, cmd_mv, "OLDPATH NEWPATH", "rename a remote file" }, { "rm", 1, 1, cmd_rm, "PATH", "remove remote file" }, { "rmdir", 1, 1, cmd_rmdir, "PATH", "remove remote directory" }, { "symlink", 2, 2, cmd_symlink, "TARGET NEWPATH", "create a remote symlink" }, { "stat", 1, 1, cmd_stat, "PATH", "stat a file" }, { "text", 0, 0, cmd_text, 0, "text mode" }, { "truncate", 2, 2, cmd_truncate, "LENGTH FILE", "truncate a file" }, { "version", 0, 1, cmd_version, 0, "set or display protocol version" }, { 0, 0, 0, 0, 0, 0 } }; static int cmd_help(int attribute((unused)) ac, char attribute((unused)) **av) { int n; size_t max = 0, len = 0; for(n = 0; commands[n].name; ++n) { if(commands[n].name[0] == '_') continue; len = strlen(commands[n].name); if(commands[n].args) len += strlen(commands[n].args) + 1; if(len > max) max = len; } for(n = 0; commands[n].name; ++n) { if(commands[n].name[0] == '_') continue; len = strlen(commands[n].name); xprintf("%s", commands[n].name); if(commands[n].args) { len += strlen(commands[n].args) + 1; xprintf(" %s", commands[n].args); } xprintf("%*s %s\n", (int)(max - len), "", commands[n].help); } return 0; } static char *input(const char *prompt, FILE *fp) { char buffer[4096]; if(prompt) { #if HAVE_READLINE char *const s = readline(prompt); if(s) { const char *t = s; while(isspace((unsigned char)*t)) ++t; if(*t) add_history(s); } return s; #else xprintf("%s", prompt); if(fflush(stdout) < 0) fatal("error calling fflush: %s", strerror(errno)); #endif } if(!fgets(buffer, sizeof buffer, fp)) return 0; return xstrdup(buffer); } /* Input processing loop */ static void process(const char *prompt, FILE *fp) { char *line; int ac, n; char *avbuf[256], **av; while((line = input(prompt, fp))) { ++inputline; if(line[0] == '#') goto next; if(echo) { xprintf("%s", line); if(fflush(stdout) < 0) fatal("error calling fflush: %s", strerror(errno)); } if(line[0] == '!') { if(line[1] != '\n') system(line + 1); else system(getenv("SHELL")); goto next; } if((ac = split(line, av = avbuf)) < 0) { if(stoponerror) fatal("stopping on error"); goto next; } if(!ac) goto next; for(n = 0; commands[n].name && strcmp(av[0], commands[n].name); ++n) ; if(!commands[n].name) { error("unknown command: '%s'", av[0]); if(stoponerror) fatal("stopping on error"); goto next; } ++av; --ac; if(ac < commands[n].minargs || ac > commands[n].maxargs) { error("wrong number of arguments (got %d, want %d-%d)", ac, commands[n].minargs, commands[n].maxargs); if(stoponerror) fatal("stopping on error"); goto next; } if(commands[n].handler(ac, av) && stoponerror) fatal("stopping on error"); next: if(fflush(stdout) < 0) fatal("error calling fflush: %s", strerror(errno)); sftp_alloc_destroy(fakejob.a); free(line); } if(ferror(fp)) fatal("error reading %s: %s", inputpath, strerror(errno)); if(prompt) xprintf("\n"); } int main(int argc, char **argv) { int n; #if HAVE_GETADDRINFO struct addrinfo hints; #endif const char *host = 0, *port = 0; int dropbear = 0; #if HAVE_GETADDRINFO memset(&hints, 0, sizeof hints); hints.ai_flags = 0; hints.ai_family = PF_UNSPEC; hints.ai_socktype = SOCK_STREAM; #endif setlocale(LC_ALL, ""); newline = xstrdup("\r\n"); /* Figure out terminal width */ { struct winsize ws; const char *e; if((e = getenv("COLUMNS"))) terminal_width = (size_t)strtoul(e, 0, 10); else if(ioctl(1, TIOCGWINSZ, &ws) >= 0) terminal_width = ws.ws_col; else terminal_width = 80; } while((n = getopt_long(argc, argv, "hVrB:b:P:R:s:S:12CF:o:vdH:p:46D:", options, 0)) >= 0) { switch(n) { case 'h': help(); case 'V': version(); case 'r': dropbear++; break; case 'B': buffersize = atoi(optarg); break; case 'b': batchfile = optarg; stoponerror = 1; progress_indicators = 0; break; case 'P': program = optarg; break; case 'R': nrequests = atoi(optarg); break; case 's': subsystem = optarg; break; case 'S': sftpversion = atoi(optarg); break; case '1': sshversion = 1; break; case '2': sshversion = 2; break; case 'C': compress = 1; break; case 'F': sshconf = optarg; break; case 'o': sshoptions[nsshoptions++] = optarg; break; case 'v': sshverbose++; break; case 'd': sftp_debugging = 1; break; case 'D': sftp_debugging = 1; sftp_debugpath = optarg; break; case 256: quirk_reverse_symlink = 1; break; case 257: stoponerror = 1; break; case 258: stoponerror = 0; break; case 259: progress_indicators = 1; break; case 260: progress_indicators = 0; break; case 261: echo = 1; break; case 262: signal(SIGPIPE, SIG_DFL); break; /* stupid python */ case 263: sftpversion = atoi(optarg); forceversion = 1; break; case 'H': host = optarg; break; case 'p': port = optarg; break; #if HAVE_GETADDRINFO case '4': hints.ai_family = PF_INET; break; case '6': hints.ai_family = PF_INET6; break; #endif default: exit(1); } } /* sanity checking */ if(nrequests <= 0) nrequests = 1; if(nrequests > 128) nrequests = 128; if(buffersize < 64) buffersize = 64; if(buffersize > 1048576) buffersize = 1048576; if((sftpversion < 3 || sftpversion > 6) && !forceversion) fatal("unknown SFTP version %d", sftpversion); if(host || port) { #if HAVE_GETADDRINFO struct addrinfo *res; int rc, fd; if(!(host && port) || program || subsystem) fatal("inconsistent options"); if((rc = getaddrinfo(host, port, &hints, &res))) fatal("error resolving host %s port %s: %s", host, port, gai_strerror(rc)); if((fd = socket(res->ai_family, res->ai_socktype, res->ai_protocol)) < 0) fatal("error calling socket: %s", strerror(errno)); if(connect(fd, res->ai_addr, res->ai_addrlen) < 0) fatal("error connecting to host %s port %s: %s", host, port, strerror(errno)); sftpin = sftpout = fd; #else /* It's hardly a core feature... */ fatal("--host is not supported on this platform"); #endif } else { const char *cmdline[2048]; int ncmdline = 0; int ip[2], op[2]; pid_t pid; if(program) { cmdline[ncmdline++] = program; } else { if(optind >= argc) fatal("missing USER@HOST argument"); if(dropbear) { cmdline[ncmdline++] = "dbclient"; } else { cmdline[ncmdline++] = "ssh"; if(sshversion == 1) cmdline[ncmdline++] = "-1"; if(sshversion == 2) cmdline[ncmdline++] = "-2"; if(compress) cmdline[ncmdline++] = "-C"; if(sshconf) { cmdline[ncmdline++] = "-F"; cmdline[ncmdline++] = sshconf; } for(n = 0; n < nsshoptions; ++n) { cmdline[ncmdline++] = "-o"; cmdline[ncmdline++] = sshoptions[n++]; } while(sshverbose-- > 0) cmdline[ncmdline++] = "-v"; } cmdline[ncmdline++] = "-s"; cmdline[ncmdline++] = argv[optind++]; cmdline[ncmdline++] = subsystem ? subsystem : "sftp"; } cmdline[ncmdline] = 0; xpipe(ip); xpipe(op); if(!(pid = xfork())) { xclose(ip[0]); xclose(op[1]); xdup2(ip[1], 1); xdup2(op[0], 0); execvp(cmdline[0], (void *)cmdline); fatal("executing %s: %s", cmdline[0], strerror(errno)); } xclose(ip[1]); xclose(op[0]); sftpin = ip[0]; sftpout = op[1]; } fakejob.a = sftp_alloc_init(&allocator); fakejob.worker = &fakeworker; if((fakeworker.utf8_to_local = iconv_open(nl_langinfo(CODESET), "UTF-8")) == (iconv_t)-1) fatal("error calling iconv_open: %s", strerror(errno)); if((fakeworker.local_to_utf8 = iconv_open("UTF-8", nl_langinfo(CODESET))) == (iconv_t)-1) fatal("error calling iconv_open: %s", strerror(errno)); if(sftp_init()) return 1; if(batchfile) { FILE *fp; inputpath = batchfile; if(!(fp = fopen(batchfile, "r"))) fatal("error opening %s: %s", batchfile, strerror(errno)); process(0, fp); } else { inputpath = "stdin"; process("sftp> ", stdin); } /* We let the OS reap the SSH process */ return 0; } /* Local Variables: c-basic-offset:2 comment-column:40 fill-column:79 indent-tabs-mode:nil End: */ sftpserver-0.2.1/v3.c0000664000175000017500000006362411626752072011357 00000000000000/* * This file is part of the Green End SFTP Server. * Copyright (C) 2007, 2011 Richard Kettlewell * * 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 2 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, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA */ #include "sftpserver.h" #include "alloc.h" #include "users.h" #include "debug.h" #include "sftp.h" #include "handle.h" #include "send.h" #include "parse.h" #include "types.h" #include "globals.h" #include "stat.h" #include "utils.h" #include "serialize.h" #include #include #include #include #include #include #include #include #include #include #include int reverse_symlink; /* Callbacks */ /* Encode/decode path names. v3 does not know what encoding filenames use. I * assume that the client and the server use the same encoding and so don't * perform any translation. */ int sftp_v3_encode(struct sftpjob attribute((unused)) *job, char attribute((unused)) **path) { return 0; } static uint32_t v3_decode(struct sftpjob attribute((unused)) *job, char attribute((unused)) **path) { return SSH_FX_OK; } /* Send a filename list as found in an SSH_FXP_NAME response. The response * header and so on must be generated by the caller. */ static void v3_sendnames(struct sftpjob *job, int nnames, const struct sftpattr *names) { time_t now; struct tm nowtime; /* We'd like to know what year we're in for dates in longname */ time(&now); gmtime_r(&now, &nowtime); sftp_send_uint32(job->worker, nnames); while(nnames > 0) { sftp_send_path(job, job->worker, names->name); sftp_send_string(job->worker, sftp_format_attr(job->a, names, nowtime.tm_year, 0)); protocol->sendattrs(job, names); ++names; --nnames; } } static void v3_sendattrs(struct sftpjob *job, const struct sftpattr *attrs) { uint32_t v3bits, m, a; /* The timestamp flags change between v3 and v4. In the structure we always * use the v4+ bits, so we must translate. */ if((attrs->valid & (SSH_FILEXFER_ATTR_ACCESSTIME |SSH_FILEXFER_ATTR_MODIFYTIME)) == (SSH_FILEXFER_ATTR_ACCESSTIME |SSH_FILEXFER_ATTR_MODIFYTIME)) v3bits = ((attrs->valid & (SSH_FILEXFER_ATTR_SIZE |SSH_FILEXFER_ATTR_UIDGID |SSH_FILEXFER_ATTR_PERMISSIONS)) |SSH_FILEXFER_ACMODTIME); else v3bits = (attrs->valid & (SSH_FILEXFER_ATTR_SIZE |SSH_FILEXFER_ATTR_UIDGID |SSH_FILEXFER_ATTR_PERMISSIONS)); sftp_send_uint32(job->worker, v3bits); if(v3bits & SSH_FILEXFER_ATTR_SIZE) sftp_send_uint64(job->worker, attrs->size); if(v3bits & SSH_FILEXFER_ATTR_UIDGID) { sftp_send_uint32(job->worker, attrs->uid); sftp_send_uint32(job->worker, attrs->gid); } if(v3bits & SSH_FILEXFER_ATTR_PERMISSIONS) sftp_send_uint32(job->worker, attrs->permissions); if(v3bits & SSH_FILEXFER_ACMODTIME) { m = attrs->mtime.seconds; a = attrs->atime.seconds; /* Check that the conversion was sound. SFTP v3 becomes unsound in 2038CE. * If you're looking at this code then, I suggest using a later protocol * version. If that's not acceptable, and you either don't care about * bogus timestamps or have some other workaround, then delete the * checks. */ if(m != attrs->mtime.seconds) fatal("sending out-of-range mtime"); if(a != attrs->atime.seconds) fatal("sending out-of-range mtime"); sftp_send_uint32(job->worker, m); sftp_send_uint32(job->worker, a); } /* Note that we just discard unknown bits rather than reporting errors. */ } static uint32_t v3_parseattrs(struct sftpjob *job, struct sftpattr *attrs) { uint32_t n, rc; memset(attrs, 0, sizeof *attrs); if((rc = sftp_parse_uint32(job, &attrs->valid)) != SSH_FX_OK) return rc; /* Translate v3 bits t v4+ bits */ if(attrs->valid & SSH_FILEXFER_ACMODTIME) attrs->valid |= (SSH_FILEXFER_ATTR_ACCESSTIME |SSH_FILEXFER_ATTR_MODIFYTIME); /* Read the v3 fields */ if(attrs->valid & SSH_FILEXFER_ATTR_SIZE) if((rc = sftp_parse_uint64(job, &attrs->size)) != SSH_FX_OK) return rc; if(attrs->valid & SSH_FILEXFER_ATTR_UIDGID) { if((rc = sftp_parse_uint32(job, &attrs->uid)) != SSH_FX_OK) return rc; if((rc = sftp_parse_uint32(job, &attrs->gid)) != SSH_FX_OK) return rc; } if(attrs->valid & SSH_FILEXFER_ATTR_PERMISSIONS) { if((rc = sftp_parse_uint32(job, &attrs->permissions)) != SSH_FX_OK) return rc; /* Fake up type field */ switch(attrs->permissions & S_IFMT) { case S_IFIFO: attrs->type = SSH_FILEXFER_TYPE_FIFO; break; case S_IFCHR: attrs->type = SSH_FILEXFER_TYPE_CHAR_DEVICE; break; case S_IFDIR: attrs->type = SSH_FILEXFER_TYPE_DIRECTORY; break; case S_IFBLK: attrs->type = SSH_FILEXFER_TYPE_BLOCK_DEVICE; break; case S_IFREG: attrs->type = SSH_FILEXFER_TYPE_REGULAR; break; case S_IFLNK: attrs->type = SSH_FILEXFER_TYPE_SYMLINK; break; case S_IFSOCK: attrs->type = SSH_FILEXFER_TYPE_SOCKET; break; default: attrs->type = SSH_FILEXFER_TYPE_UNKNOWN; break; } } else attrs->type = SSH_FILEXFER_TYPE_UNKNOWN; if(attrs->valid & SSH_FILEXFER_ATTR_ACCESSTIME) { if((rc = sftp_parse_uint32(job, &n)) != SSH_FX_OK) return rc; attrs->atime.seconds = n; } if(attrs->valid & SSH_FILEXFER_ATTR_MODIFYTIME) { if((rc = sftp_parse_uint32(job, &n)) != SSH_FX_OK) return rc; attrs->mtime.seconds = n; } if(attrs->valid & SSH_FILEXFER_ATTR_EXTENDED) { if((rc = sftp_parse_uint32(job, &n)) != SSH_FX_OK) return rc; while(n-- > 0) { if((rc = sftp_parse_string(job, 0, 0)) != SSH_FX_OK || (rc = sftp_parse_string(job, 0, 0)) != SSH_FX_OK) return rc; } } return SSH_FX_OK;; } /* Command implementations */ uint32_t sftp_vany_already_init(struct sftpjob attribute((unused)) *job) { /* Cannot initialize more than once */ return SSH_FX_FAILURE; } uint32_t sftp_vany_remove(struct sftpjob *job) { char *path; struct stat sb; if(readonly) return SSH_FX_PERMISSION_DENIED; pcheck(sftp_parse_path(job, &path)); D(("sftp_vany_remove %s", path)); if(unlink(path) < 0) { if(errno == EPERM) { if(lstat(path, &sb) == 0 && S_ISDIR(sb.st_mode)) return SSH_FX_FILE_IS_A_DIRECTORY; errno = EPERM; /* put errno back */ } return HANDLER_ERRNO; } else return SSH_FX_OK; } uint32_t sftp_vany_rmdir(struct sftpjob *job) { char *path; if(readonly) return SSH_FX_PERMISSION_DENIED; pcheck(sftp_parse_path(job, &path)); D(("sftp_vany_rmdir %s", path)); if(rmdir(path) < 0) if(errno == EEXIST) return SSH_FX_DIR_NOT_EMPTY; else return HANDLER_ERRNO; else return SSH_FX_OK; } uint32_t sftp_v34_rename(struct sftpjob *job) { char *oldpath, *newpath; if(readonly) return SSH_FX_PERMISSION_DENIED; pcheck(sftp_parse_path(job, &oldpath)); pcheck(sftp_parse_path(job, &newpath)); D(("sftp_v34_rename %s %s", oldpath, newpath)); /* newpath is not allowed to exist. We enforce this atomically by attempting to link() from oldpath to newpath and unlinking oldpath if it succeeds. */ if(link(oldpath, newpath) < 0) { if(errno != EEXIST) { /* On Linux we always get EEXIST if the destination already exists. We * get EPERM if we're trying to link a directory (and the destination * doesn't exist) or we're trying to use a non-link-capable filesytem * (and the destination doesn't exist). * * On BSD we get EPERM if we're trying to link a directory even if the * destination does exist. * * So all we can be sure is that EEXIST means the destination definitely * exists. Other errors don't mean it doesn't exist. * * We give up on atomicity for such cases (v3/v4 drafts do not state a * requirement for it) and have other useful semantics instead. * * This has the slightly odd effect of giving rename(2) semantics only * for directories and on primitive filesystems. If you want such * semantics reliably you need SFTP v5 or better. * * TODO: do a configure check for the local link() semantics. */ #ifndef __linux__ { struct stat sb; if(lstat(newpath, &sb) == 0) return SSH_FX_FILE_ALREADY_EXISTS; } #endif if(rename(oldpath, newpath) < 0) return HANDLER_ERRNO; else return SSH_FX_OK; } else return HANDLER_ERRNO; } else if(unlink(oldpath) < 0) { const int save_errno = errno; unlink(newpath); errno = save_errno; return HANDLER_ERRNO; } else return SSH_FX_OK; } uint32_t sftp_v345_symlink(struct sftpjob *job) { char *targetpath, *linkpath; if(readonly) return SSH_FX_PERMISSION_DENIED; /* The spec is fairly clear. linkpath is first, targetpath is second. * linkpath is the name of the symlink to be created and targetpath is the * contents. This is the reverse of the symlink() call and the ln command, * where the first argument is the contents and the second argument the path * of the symlink to be created. * * * Implementations that get it right: * - Gnome's Nautilus gets the arguments the right way round. * - The sshtools.com Java SFTP talks the talk but obviously depends on its * caller getting the arguments in the right order. CyberDuck (the client I * have to hand that uses it) doesn't seem to have a way to make links. * * Implementations that get it wrong: * - The OpenSSH server and client both this wrong (at the time of writing) * and don't seem to be immediately interested in fixing it - see * http://bugzilla.mindrot.org/show_bug.cgi?id=861 for further details. * - WinSCP knows the right way round but if it thinks it's talking to an * OpenSSH SSH server (NB not necessarily the OpenSSH SFTP server) then it * reverses them as a workaround. * - Paramiko's client symlink command sends source then dest, which * is the wrong way around (at least as of revno 434/Feb 07). * - Paramiko's server also gets it wrong. * * Implementations that apparently can't make links: * - lftp and Konqueror don't seem to be able to create remote symlinks. * * * So what to do? There's a configure option to select the desired * behaviour, and an extension to report to clients what was chosen, but we * need to pick a default. The option of "follow the implementation" doesn't * yield a definitive answer as some implementations get it right and some * wrong. * * I go with the specification for the time being but this may be revisited * in the light of experience. * * Currently I assume that any v6 implementations (which has a different link * command) will follow the spec but of course I may yet be disappointed. An * extension documenting server behaviour is sent in that case too. */ if(reverse_symlink) { pcheck(sftp_parse_path(job, &targetpath)); pcheck(sftp_parse_path(job, &linkpath)); } else { pcheck(sftp_parse_path(job, &linkpath)); pcheck(sftp_parse_path(job, &targetpath)); } D(("sftp_v345_symlink %s %s", targetpath, linkpath)); if(symlink(targetpath, linkpath) < 0) return HANDLER_ERRNO; else return SSH_FX_OK; } uint32_t sftp_vany_readlink(struct sftpjob *job) { char *path, *result; struct sftpattr attr; pcheck(sftp_parse_path(job, &path)); D(("sftp_vany_readlink %s", path)); if(!(result = sftp_do_readlink(job->a, path))) { if(errno == E2BIG) { sftp_send_status(job, SSH_FX_FAILURE, "link name is too long"); return HANDLER_RESPONDED; } return HANDLER_ERRNO; } memset(&attr, 0, sizeof attr); attr.name = result; sftp_send_begin(job->worker); sftp_send_uint8(job->worker, SSH_FXP_NAME); sftp_send_uint32(job->worker, job->id); protocol->sendnames(job, 1, &attr); sftp_send_end(job->worker); return HANDLER_RESPONDED; } uint32_t sftp_vany_opendir(struct sftpjob *job) { char *path; DIR *dp; struct handleid id; pcheck(sftp_parse_path(job, &path)); D(("sftp_vany_opendir %s", path)); if(!(dp = opendir(path))) return HANDLER_ERRNO; sftp_handle_new_dir(&id, dp, path); D(("...handle is %"PRIu32" %"PRIu32, id.id, id.tag)); sftp_send_begin(job->worker); sftp_send_uint8(job->worker, SSH_FXP_HANDLE); sftp_send_uint32(job->worker, job->id); sftp_send_handle(job->worker, &id); sftp_send_end(job->worker); return HANDLER_RESPONDED; } uint32_t sftp_vany_readdir(struct sftpjob *job) { struct handleid id; DIR *dp; uint32_t rc; struct sftpattr d[MAXNAMES]; int n; struct dirent *de; const char *path; char *childpath, *fullpath; struct stat sb; pcheck(sftp_parse_handle(job, &id)); D(("sftp_vany_readdir %"PRIu32" %"PRIu32, id.id, id.tag)); if((rc = sftp_handle_get_dir(&id, &dp, &path))) { sftp_send_status(job, rc, "invalid directory handle"); return HANDLER_RESPONDED; } memset(d, 0, sizeof d); for(n = 0; n < MAXNAMES;) { /* readdir() has a slightly shonky interface - a null return can mean EOF * or error, and there is no guarantee that errno is reset to 0 on EOF. */ errno = 0; de = readdir(dp); if(!de) break; /* We include . and .. in the list - if the cliient doesn't like them it * can filter them out itself. */ childpath = strcpy(sftp_alloc(job->a, strlen(de->d_name) + 1), de->d_name); /* We need the full path to be able to stat the file */ fullpath = sftp_alloc(job->a, strlen(path) + strlen(childpath) + 2); strcpy(fullpath, path); strcat(fullpath, "/"); strcat(fullpath, childpath); if(lstat(fullpath, &sb)) return HANDLER_ERRNO; sftp_stat_to_attrs(job->a, &sb, &d[n], 0xFFFFFFFF, childpath); d[n].name = childpath; ++n; errno = 0; /* avoid error slippage from * e.g. getpwuid() failure */ } if(errno) return HANDLER_ERRNO; if(n) { sftp_send_begin(job->worker); sftp_send_uint8(job->worker, SSH_FXP_NAME); sftp_send_uint32(job->worker, job->id); protocol->sendnames(job, n, d); sftp_send_end(job->worker); return HANDLER_RESPONDED; } else return SSH_FX_EOF; } uint32_t sftp_vany_close(struct sftpjob *job) { struct handleid id; pcheck(sftp_parse_handle(job, &id)); D(("sftp_vany_close %"PRIu32" %"PRIu32, id.id, id.tag)); return sftp_handle_close(&id); } uint32_t sftp_v345_realpath(struct sftpjob *job) { char *path; struct sftpattr attr; pcheck(sftp_parse_path(job, &path)); D(("sftp_v345_realpath %s", path)); memset(&attr, 0, sizeof attr); attr.name = sftp_find_realpath(job->a, path, RP_READLINK); if(attr.name) { D(("...real path is %s", attr.name)); sftp_send_begin(job->worker); sftp_send_uint8(job->worker, SSH_FXP_NAME); sftp_send_uint32(job->worker, job->id); protocol->sendnames(job, 1, &attr); sftp_send_end(job->worker); return HANDLER_RESPONDED; } else return HANDLER_ERRNO; } /* Command code for the various _*STAT calls. rc is the return value * from *stat() and SB is the buffer. */ static uint32_t sftp_v3_stat_core(struct sftpjob *job, int rc, const struct stat *sb) { struct sftpattr attrs; if(!rc) { /* We suppress owner/group name lookup since there is no way to communicate * it in protocol version 3 */ sftp_stat_to_attrs(job->a, sb, &attrs, ~(uint32_t)SSH_FILEXFER_ATTR_OWNERGROUP, 0); sftp_send_begin(job->worker); sftp_send_uint8(job->worker, SSH_FXP_ATTRS); sftp_send_uint32(job->worker, job->id); protocol->sendattrs(job, &attrs); sftp_send_end(job->worker); return HANDLER_RESPONDED; } else return HANDLER_ERRNO; } static uint32_t sftp_v3_lstat(struct sftpjob *job) { char *path; struct stat sb; pcheck(sftp_parse_path(job, &path)); D(("sftp_v3_lstat %s", path)); return sftp_v3_stat_core(job, lstat(path, &sb), &sb); } static uint32_t sftp_v3_stat(struct sftpjob *job) { char *path; struct stat sb; pcheck(sftp_parse_path(job, &path)); D(("sftp_v3_stat %s", path)); return sftp_v3_stat_core(job, stat(path, &sb), &sb); } static uint32_t sftp_v3_fstat(struct sftpjob *job) { int fd; struct handleid id; struct stat sb; uint32_t rc; pcheck(sftp_parse_handle(job, &id)); D(("sftp_v3_fstat %"PRIu32" %"PRIu32, id.id, id.tag)); if((rc = sftp_handle_get_fd(&id, &fd, 0))) return rc; return sftp_v3_stat_core(job, fstat(fd, &sb), &sb); } uint32_t sftp_vany_setstat(struct sftpjob *job) { char *path; struct sftpattr attrs; uint32_t rc; if(readonly) return SSH_FX_PERMISSION_DENIED; pcheck(sftp_parse_path(job, &path)); pcheck(protocol->parseattrs(job, &attrs)); D(("sftp_vany_setstat %s", path)); /* Check owner/group */ if((rc = sftp_normalize_ownergroup(job->a, &attrs)) != SSH_FX_OK) return rc; return sftp_set_status(job->a, path, &attrs, 0); } uint32_t sftp_vany_fsetstat(struct sftpjob *job) { struct handleid id; struct sftpattr attrs; int fd; uint32_t rc; if(readonly) return SSH_FX_PERMISSION_DENIED; pcheck(sftp_parse_handle(job, &id)); pcheck(protocol->parseattrs(job, &attrs)); D(("sftp_vany_fsetstat %"PRIu32" %"PRIu32, id.id, id.tag)); /* Check owner/group */ if((rc = sftp_normalize_ownergroup(job->a, &attrs)) != SSH_FX_OK) return rc; if((rc = sftp_handle_get_fd(&id, &fd, 0))) return rc; return sftp_set_fstatus(job->a, fd, &attrs, 0); } uint32_t sftp_vany_mkdir(struct sftpjob *job) { char *path; struct sftpattr attrs; uint32_t rc; if(readonly) return SSH_FX_PERMISSION_DENIED; pcheck(sftp_parse_path(job, &path)); pcheck(protocol->parseattrs(job, &attrs)); D(("sftp_vany_mkdir %s", path)); attrs.valid &= ~SSH_FILEXFER_ATTR_SIZE; /* makes no sense */ if(attrs.valid & SSH_FILEXFER_ATTR_PERMISSIONS) { D(("initial permissions are %#o (%d decimal)", attrs.permissions, attrs.permissions)); /* If we're given initial permissions, use them */ if(mkdir(path, attrs.permissions & 07777) < 0) return HANDLER_ERRNO; /* Don't modify permissions later unless necessary */ if(attrs.permissions == (attrs.permissions & 0777)) attrs.valid ^= SSH_FILEXFER_ATTR_PERMISSIONS; } else { /* Otherwise be conservative */ if(mkdir(path, DEFAULT_PERMISSIONS) < 0) return HANDLER_ERRNO; } if((rc = sftp_set_status(job->a, path, &attrs, 0))) { const int save_errno = errno; /* If we can't have the desired permissions, don't have the directory at * all */ rmdir(path); errno = save_errno; return rc; } return SSH_FX_OK; } uint32_t sftp_v34_open(struct sftpjob *job) { char *path; uint32_t pflags; struct sftpattr attrs; uint32_t desired_access = 0; uint32_t flags; pcheck(sftp_parse_path(job, &path)); pcheck(sftp_parse_uint32(job, &pflags)); pcheck(protocol->parseattrs(job, &attrs)); D(("sftp_v34_open %s %#"PRIx32, path, pflags)); /* Translate to v5/6 bits */ switch(pflags & (SSH_FXF_CREAT|SSH_FXF_TRUNC|SSH_FXF_EXCL)) { case 0: flags = SSH_FXF_OPEN_EXISTING; break; case SSH_FXF_TRUNC: /* The drafts demand that SSH_FXF_CREAT also be sent making this formally * invalid, though there doesn't seem any good reason for them to do so: * the client intent seems clear.*/ flags = SSH_FXF_TRUNCATE_EXISTING; break; case SSH_FXF_CREAT: flags = SSH_FXF_OPEN_OR_CREATE; break; case SSH_FXF_CREAT|SSH_FXF_TRUNC: flags = SSH_FXF_CREATE_TRUNCATE; break; case SSH_FXF_CREAT|SSH_FXF_EXCL: case SSH_FXF_CREAT|SSH_FXF_TRUNC|SSH_FXF_EXCL: /* nonsensical */ flags = SSH_FXF_CREATE_NEW; break; default: return SSH_FX_BAD_MESSAGE; } if(pflags & SSH_FXF_TEXT) flags |= SSH_FXF_TEXT_MODE; if(pflags & SSH_FXF_READ) desired_access |= ACE4_READ_DATA|ACE4_READ_ATTRIBUTES; if(pflags & SSH_FXF_WRITE) desired_access |= ACE4_WRITE_DATA|ACE4_WRITE_ATTRIBUTES; if(pflags & SSH_FXF_APPEND) { flags |= SSH_FXF_APPEND_DATA; desired_access |= ACE4_APPEND_DATA; } return sftp_generic_open(job, path, desired_access, flags, &attrs); } uint32_t sftp_vany_read(struct sftpjob *job) { struct handleid id; uint64_t offset; uint32_t len, rc; ssize_t n; int fd; unsigned flags; pcheck(sftp_parse_handle(job, &id)); pcheck(sftp_parse_uint64(job, &offset)); pcheck(sftp_parse_uint32(job, &len)); D(("sftp_vany_read %"PRIx32" %"PRIu32" %"PRIu32": %"PRIu32" bytes at %"PRIu64, job->id, id.id, id.tag, len, offset)); if(len > MAXREAD) len = MAXREAD; if((rc = sftp_handle_get_fd(&id, &fd, &flags))) return rc; /* We read straight into our own output buffer to save a copy. */ sftp_send_begin(job->worker); sftp_send_uint8(job->worker, SSH_FXP_DATA); sftp_send_uint32(job->worker, job->id); sftp_send_need(job->worker, len + 4); if(flags & (HANDLE_TEXT|HANDLE_APPEND)) n = read(fd, job->worker->buffer + job->worker->bufused + 4, len); else n = pread(fd, job->worker->buffer + job->worker->bufused + 4, len, offset); /* Short reads are allowed so we don't try to read more */ if(n > 0) { /* Fix up the buffer */ sftp_send_uint32(job->worker, n); job->worker->bufused += n; sftp_send_end(job->worker); return HANDLER_RESPONDED; } /* The error-sending code calls sftp_send_begin(), so we don't get half a * SSH_FXP_DATA response first */ if(n == 0) return SSH_FX_EOF; else return HANDLER_ERRNO; } uint32_t sftp_vany_write(struct sftpjob *job) { struct handleid id; uint64_t offset; uint32_t len, rc; ssize_t n; int fd; unsigned flags; if(readonly) return SSH_FX_PERMISSION_DENIED; pcheck(sftp_parse_handle(job, &id)); pcheck(sftp_parse_uint64(job, &offset)); pcheck(sftp_parse_uint32(job, &len)); if(len > job->left) return SSH_FX_BAD_MESSAGE; D(("sftp_vany_write %"PRIu32" %"PRIu32": %"PRIu32" bytes at %"PRIu64, id.id, id.tag, len, offset)); if((rc = sftp_handle_get_fd(&id, &fd, &flags))) return rc; while(len > 0) { /* Short writes aren't allowed so we loop around writing more */ if(flags & (HANDLE_TEXT|HANDLE_APPEND)) n = write(fd, job->ptr, len); else n = pwrite(fd, job->ptr, len, offset); if(n < 0) return HANDLER_ERRNO; job->ptr += n; job->left += n; len -= n; offset += n; } return SSH_FX_OK; } uint32_t sftp_vany_posix_rename(struct sftpjob *job) { char *oldpath, *newpath; if(readonly) return SSH_FX_PERMISSION_DENIED; pcheck(sftp_parse_path(job, &oldpath)); pcheck(sftp_parse_path(job, &newpath)); D(("sftp_vany_posix_rename %s %s", oldpath, newpath)); if(rename(oldpath, newpath) < 0) return HANDLER_ERRNO; else return SSH_FX_OK; } uint32_t sftp_vany_statfs(struct sftpjob *job) { char *path; struct statvfs fs; pcheck(sftp_parse_path(job, &path)); D(("sftp_vany_statfs %s", path)); if(statvfs(path, &fs) < 0) return HANDLER_ERRNO; sftp_send_begin(job->worker); sftp_send_uint8(job->worker, SSH_FXP_EXTENDED_REPLY); sftp_send_uint32(job->worker, job->id); /* FUSE's version uses 'struct statfs', we use 'struct statvfs'. So some of * the names are a little different. However the overall semantics should be * the same. */ sftp_send_uint32(job->worker, fs.f_frsize); sftp_send_uint64(job->worker, fs.f_blocks); sftp_send_uint64(job->worker, fs.f_bfree); sftp_send_uint64(job->worker, fs.f_bavail); sftp_send_uint64(job->worker, fs.f_files); sftp_send_uint64(job->worker, fs.f_ffree); sftp_send_end(job->worker); return HANDLER_RESPONDED; } static const struct sftpcmd sftpv3tab[] = { { SSH_FXP_INIT, sftp_vany_already_init }, { SSH_FXP_OPEN, sftp_v34_open }, { SSH_FXP_CLOSE, sftp_vany_close }, { SSH_FXP_READ, sftp_vany_read }, { SSH_FXP_WRITE, sftp_vany_write }, { SSH_FXP_LSTAT, sftp_v3_lstat }, { SSH_FXP_FSTAT, sftp_v3_fstat }, { SSH_FXP_SETSTAT, sftp_vany_setstat }, { SSH_FXP_FSETSTAT, sftp_vany_fsetstat }, { SSH_FXP_OPENDIR, sftp_vany_opendir }, { SSH_FXP_READDIR, sftp_vany_readdir }, { SSH_FXP_REMOVE, sftp_vany_remove }, { SSH_FXP_MKDIR, sftp_vany_mkdir }, { SSH_FXP_RMDIR, sftp_vany_rmdir }, { SSH_FXP_REALPATH, sftp_v345_realpath }, { SSH_FXP_STAT, sftp_v3_stat }, { SSH_FXP_RENAME, sftp_v34_rename }, { SSH_FXP_READLINK, sftp_vany_readlink }, { SSH_FXP_SYMLINK, sftp_v345_symlink }, { SSH_FXP_EXTENDED, sftp_vany_extended } }; static const struct sftpextension v3_extensions[] = { { "posix-rename@openssh.org", sftp_vany_posix_rename }, { "space-available", sftp_vany_space_available }, { "statfs@openssh.org", sftp_vany_statfs }, }; const struct sftpprotocol sftp_v3 = { sizeof sftpv3tab / sizeof (struct sftpcmd), /* ncommands */ sftpv3tab, /* commands */ 3, /* version */ (SSH_FILEXFER_ATTR_SIZE |SSH_FILEXFER_ATTR_PERMISSIONS |SSH_FILEXFER_ATTR_ACCESSTIME |SSH_FILEXFER_ATTR_MODIFYTIME |SSH_FILEXFER_ATTR_UIDGID), /* attrmask */ SSH_FX_OP_UNSUPPORTED, /* maxstatus */ v3_sendnames, v3_sendattrs, v3_parseattrs, sftp_v3_encode, v3_decode, sizeof v3_extensions / sizeof (struct sftpextension), v3_extensions, /* extensions */ }; /* Local Variables: c-basic-offset:2 comment-column:40 fill-column:79 indent-tabs-mode:nil End: */ sftpserver-0.2.1/Makefile.am0000664000175000017500000000601412340114433012670 00000000000000# This file is part of the Green End SFTP Server. # Copyright (C) 2007, 2011, 2014 Richard Kettlewell # # 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 2 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, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 # USA # Programs noinst_PROGRAMS=sftpclient pwtest noinst_SCRIPTS=run-tests libexec_PROGRAMS=gesftpserver noinst_LIBRARIES=libsftp.a gesftpserver_SOURCES=sftpserver.c readwrite.c gesftpserver_LDADD=libsftp.a sftpclient_SOURCES=sftpclient.c readwrite.c sftpclient_LDADD=libsftp.a $(LIBREADLINE) libsftp_a_SOURCES=alloc.c alloc.h debug.c debug.h globals.h handle.c \ handle.h parse.c parse.h queue.c queue.h send.c send.h sftp.h \ sftpclient.h sftpcommon.h sftpserver.h status.c thread.h types.h \ users.c users.h utils.c utils.h v3.c xfns.c xfns.h stat.c charset.c \ charset.h serialize.h serialize.c v4.c realpath.c readlink.c v5.c v6.c \ stat.h getcwd.c globals.c dirname.c putword.h libsftp_a_LIBADD=$(LIBOBJS) pwtest_SOURCES=pwtest.c # Documentation man_MANS=gesftpserver.8 gesftpserver.8: gesftpserver.8.in config.status sed < ${srcdir}/gesftpserver.8.in > $@.new \ -e "s,__libexecdir__,${libexecdir},g" mv $@.new $@ # Build and test all: ${SEDOUTPUTS} check: all aliases rm -f *.gcda *.gcov ./pwtest srcdir=${srcdir} ${PYTHON24} ${srcdir}/run-tests --directory tests $(TESTS) srcdir=${srcdir} ${PYTHON24} ${srcdir}/run-tests --directory rotests --server ./gesftpserver-ro $(ROTESTS) ${GCOV} ${srcdir}/*.c | ${PYTHON24} ${srcdir}/format-gconv-report --html . #${srcdir}/paramiko-test check-valgrind: all aliases rm -f ,valgrind* srcdir=${srcdir} ${PYTHON24} ${srcdir}/run-tests --directory tests --server ./gesftpserver-valgrind $(TESTS) aliases: gesftpserver-ro gesftpserver-debug gesftpserver-ro-debug \ gesftpserver-valgrind gesftpserver-ro: rm -f $@ ln -s gesftpserver $@ gesftpserver-debug: rm -f $@ ln -s gesftpserver $@ gesftpserver-ro-debug: rm -f $@ ln -s gesftpserver $@ gesftpserver-valgrind: echo "#! /bin/sh" > $@.new echo "set -e" >> $@.new echo "exec valgrind --leak-check=full -q --log-file=/dev/tty --num-callers=50 `pwd`/gesftpserver \"\$$@\"" >> $@.new chmod +x $@.new mv $@.new $@ # Cleaning DISTCLEANFILES=${SEDOUTPUTS} gesftpserver.8 CLEANFILES=*.gcno *.gcda *.gcov gesftpserver-ro gesftpserver-debug gesftpserver-ro-debug gesftpserver-valgrind # Distribution EXTRA_DIST=gesftpserver.8.in testing.txt tests rotests README run-tests \ format-gconv-report getopt.c getopt1.c getopt.h %.s: %.c $(COMPILE) -o $@ -S $< sftpserver-0.2.1/handle.c0000664000175000017500000001260111626705056012247 00000000000000/* * This file is part of the Green End SFTP Server. * Copyright (C) 2007, 2011 Richard Kettlewell * * 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 2 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, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA */ /** @file handle.c @brief File handle implementation */ #include "sftpserver.h" #include "debug.h" #include "utils.h" #include "sftp.h" #include "handle.h" #include "thread.h" #include "types.h" #include #include #include #include /** @brief Handle data structure */ struct handle { int type; /**< @brief @ref SSH_FXP_OPEN or @ref SSH_FXP_OPENDIR */ uint32_t tag; /**< @brief Unique tag or 0 for unused */ union { int fd; /**< @brief File descriptor for a file */ DIR *dir; /**< @brief Directory stream */ } u; char *path; /**< @brief Name of file or directory */ unsigned flags; /**< @brief Flags */ }; /** @brief Table of handles */ static struct handle *handles; /** @brief Size of @p handles array */ static size_t nhandles; /** @brief Next sequence number */ static uint32_t sequence; /** @brief Lock protecting handles data structure */ static pthread_mutex_t sftp_handle_lock = PTHREAD_MUTEX_INITIALIZER; /** @brief Find a free slot in @ref handles * @param id Where to store handle * @param type @ref SSH_FXP_OPEN or @ref SSH_FXP_OPENDIR */ static void find_free_handle(struct handleid *id, int type) { size_t n; for(n = 0; n < nhandles && handles[n].tag; ++n) ; if(n == nhandles && nhandles < MAXHANDLES) { /* need more space */ nhandles = (nhandles ? 2 * nhandles : 16); assert(nhandles != 0); handles = xrecalloc(handles, nhandles, sizeof (*handles)); memset(handles + n, 0, (nhandles - n) * sizeof (*handles)); } while(!sequence) ++sequence; /* never have a tag of 0 */ handles[n].tag = sequence++; handles[n].type = type; id->id = n; id->tag = handles[n].tag; } void sftp_handle_new_file(struct handleid *id, int fd, const char *path, unsigned flags) { ferrcheck(pthread_mutex_lock(&sftp_handle_lock)); find_free_handle(id, SSH_FXP_OPEN); handles[id->id].u.fd = fd; handles[id->id].path = xstrdup(path); handles[id->id].flags = flags; ferrcheck(pthread_mutex_unlock(&sftp_handle_lock)); } void sftp_handle_new_dir(struct handleid *id, DIR *dp, const char *path) { ferrcheck(pthread_mutex_lock(&sftp_handle_lock)); find_free_handle(id, SSH_FXP_OPENDIR); handles[id->id].u.dir = dp; handles[id->id].path = xstrdup(path); ferrcheck(pthread_mutex_unlock(&sftp_handle_lock)); } uint32_t sftp_handle_get_fd(const struct handleid *id, int *fd, unsigned *flagsp) { uint32_t rc; ferrcheck(pthread_mutex_lock(&sftp_handle_lock)); if(id->id < nhandles && id->tag == handles[id->id].tag && handles[id->id].type == SSH_FXP_OPEN) { *fd = handles[id->id].u.fd; if(flagsp) *flagsp = handles[id->id].flags; rc = 0; } else rc = SSH_FX_INVALID_HANDLE; ferrcheck(pthread_mutex_unlock(&sftp_handle_lock)); return rc; } uint32_t sftp_handle_get_dir(const struct handleid *id, DIR **dp, const char **pathp) { uint32_t rc; ferrcheck(pthread_mutex_lock(&sftp_handle_lock)); if(id->id < nhandles && id->tag == handles[id->id].tag && handles[id->id].type == SSH_FXP_OPENDIR) { *dp = handles[id->id].u.dir; if(pathp) *pathp = handles[id->id].path; rc = 0; } else rc = SSH_FX_INVALID_HANDLE; ferrcheck(pthread_mutex_unlock(&sftp_handle_lock)); return rc; } uint32_t sftp_handle_close(const struct handleid *id) { uint32_t rc; ferrcheck(pthread_mutex_lock(&sftp_handle_lock)); if(id->id < nhandles && id->tag == handles[id->id].tag) { handles[id->id].tag = 0; /* free up */ switch(handles[id->id].type) { case SSH_FXP_OPEN: if(close(handles[id->id].u.fd) < 0) rc = HANDLER_ERRNO; else rc = 0; break; case SSH_FXP_OPENDIR: if(closedir(handles[id->id].u.dir) < 0) rc = HANDLER_ERRNO; else rc = 0; break; default: rc = SSH_FX_INVALID_HANDLE; } free(handles[id->id].path); } else rc = SSH_FX_INVALID_HANDLE; ferrcheck(pthread_mutex_unlock(&sftp_handle_lock)); return rc; } unsigned sftp_handle_flags(const struct handleid *id) { unsigned rc; ferrcheck(pthread_mutex_lock(&sftp_handle_lock)); if(id->id < nhandles && id->tag == handles[id->id].tag) rc = handles[id->id].flags; else rc = 0; ferrcheck(pthread_mutex_unlock(&sftp_handle_lock)); return rc; } /* Local Variables: c-basic-offset:2 comment-column:40 fill-column:79 indent-tabs-mode:nil End: */ sftpserver-0.2.1/readwrite.c0000664000175000017500000000150011625765051012776 00000000000000/* * This file is part of the Green End SFTP Server. * Copyright (C) 2007 Richard Kettlewell * * 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 2 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, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA */ int readonly; sftpserver-0.2.1/getcwd.c0000664000175000017500000000264111625765051012274 00000000000000/* * This file is part of the Green End SFTP Server. * Copyright (C) 2007 Richard Kettlewell * * 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 2 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, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA */ #include "sftpcommon.h" #include "alloc.h" #include "debug.h" #include "utils.h" #include #include #include char *sftp_getcwd(struct allocator *a) { char *buffer = 0; size_t size = 32, oldsize = 0; do { buffer = sftp_alloc_more(a, buffer, oldsize, size); if(getcwd(buffer, size)) return buffer; else if(errno != ERANGE) { D(("getcwd returned error %s", strerror(errno))); return 0; } oldsize = size; size *= 2; } while(size); return 0; } /* Local Variables: c-basic-offset:2 comment-column:40 fill-column:79 indent-tabs-mode:nil End: */ sftpserver-0.2.1/COPYING0000644000175000017500000004325411625767463011722 00000000000000 GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Lesser General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 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 2 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, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. sftpserver-0.2.1/users.h0000664000175000017500000000225711625765051012170 00000000000000/* * This file is part of the Green End SFTP Server. * Copyright (C) 2007 Richard Kettlewell * * 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 2 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, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA */ #ifndef USERS_H #define USERS_H #include struct allocator; char *sftp_uid2name(struct allocator *a, uid_t uid); char *sftp_gid2name(struct allocator *a, gid_t gid); uid_t sftp_name2uid(const char *name); gid_t sftp_name2gid(const char *name); #endif /* USERS_H */ /* Local Variables: c-basic-offset:2 comment-column:40 fill-column:79 indent-tabs-mode:nil End: */ sftpserver-0.2.1/queue.h0000664000175000017500000000456111626705056012153 00000000000000/* * This file is part of the Green End SFTP Server. * Copyright (C) 2007, 2011 Richard Kettlewell * * 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 2 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, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA */ /** @file queue.h @brief Thread pool/queue interface */ #ifndef QUEUE_H #define QUEUE_H struct allocator; /** @brief Queue-specific callbacks */ struct queuedetails { /** @brief Per-thread initialization * @return Per-thread value to be passed to other callbacks */ void *(*init)(); /** @brief Worker method * @param job Job to process * @param workerdata Per-thread value from @c init() * @param a Per-thread allocator to use for any memory requirements */ void (*worker)(void *job, void *workerdata, struct allocator *a); /** @brief Per-thread cleanup * @param workerdata Per-thread value from @c init() */ void (*cleanup)(void *workerdata); }; /** @brief Create a thread pool and queue * @param qp Where store queue pointer * @param details Queue-specific callbacks (not copied) * @param nthreads Number of threads to create */ void queue_init(struct queue **qp, const struct queuedetails *details, int nthreads); /** @brief Add a job to a thread pool's queue * @param q Queue pointer * @param job Job to add to queue * * Add a JOB to Q. Jobs are executed in order but if NTHREADS>1 then * their processing may overlap in time. On non-threaded systems, the * job is executed before returning from queue_add(). */ void queue_add(struct queue *q, void *job); /** @brief Destroy a queue * @param q Queue pointer * * All unprocessed jobs are executed before completion. */ void queue_destroy(struct queue *q); #endif /* QUEUE_H */ /* Local Variables: c-basic-offset:2 comment-column:40 fill-column:79 indent-tabs-mode:nil End: */ sftpserver-0.2.1/configure.ac0000664000175000017500000000513512415610034013126 00000000000000# This file is part of the Green End SFTP Server. # Copyright (C) 2007, 2011, 2014 Richard Kettlewell # # 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 2 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, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 # USA # Process this file with autoconf to produce a configure script. AC_INIT(sftpserver, 0.2.1, richard+sftpserver@sfere.greenend.org.uk) AC_CONFIG_AUX_DIR([config.aux]) AM_INIT_AUTOMAKE([foreign]) AC_CONFIG_SRCDIR([alloc.c]) AM_CONFIG_HEADER([config.h]) AC_PROG_CC AC_SET_MAKE #AC_PROG_LIBTOOL #AC_LIBTOOL_DLOPEN #AC_DISABLE_STATIC #RJK_BUILDSYS_FINK RJK_BUILDSYS_MISC #RJK_GTKFLAGS AC_PROG_RANLIB RJK_THREADS AC_CHECK_HEADERS([endian.h sys/prctl.h]) AC_CHECK_LIB([socket],[socket]) AC_CHECK_LIB([readline],[readline], [AC_SUBST([LIBREADLINE],[-lreadline]) AC_DEFINE([HAVE_READLINE],[1],[define if you have a readline library])]) RJK_ICONV AC_DEFINE([_GNU_SOURCE], [1], [required for e.g. strsignal]) AC_C_INLINE AC_SYS_LARGEFILE AC_REPLACE_FUNCS([daemon futimes]) AC_CHECK_FUNCS([futimesat getaddrinfo prctl]) AC_CHECK_DECLS([be64toh, htobe64]) AC_C_BIGENDIAN RJK_SIZE_MAX RJK_GCC_WARNINGS RJK_GCC_ATTRS RJK_STAT_TIMESPEC RJK_GETOPT RJK_PYTHON24 dnl See commentary in v3.c for what's going on here AC_MSG_CHECKING([whether to reverse SSH_FXP_SYMLINK arguments]) AC_ARG_ENABLE([reversed-symlink], [AS_HELP_STRING([--enable-reversed-symlink], [Reverse SSH_FXP_SYMLINK arguments])], [revlink="$enableval"], [revlink=no]) AC_MSG_RESULT([$revlink]) if test $revlink = yes; then AC_DEFINE([REVERSE_SYMLINK],[1],[define to reverse SSH_FXP_SYMLINK args]) fi AC_ARG_ENABLE([daemon], [AS_HELP_STRING([--enable-daemon], [Turn on daemon mode support])], [daemon="$enableval"], [daemon=no]) if test $daemon = yes; then AC_DEFINE([DAEMON],[1],[define to enable daemon mode]) fi RJK_GCOV AC_CONFIG_FILES([Makefile]) AC_OUTPUT dnl Local Variables: dnl indent-tabs-mode:nil dnl End: sftpserver-0.2.1/v6.c0000664000175000017500000001600611625765051011352 00000000000000/* * This file is part of the Green End SFTP Server. * Copyright (C) 2007 Richard Kettlewell * * 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 2 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, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA */ #include "sftpserver.h" #include "types.h" #include "sftp.h" #include "alloc.h" #include "stat.h" #include "parse.h" #include "send.h" #include "debug.h" #include "utils.h" #include "globals.h" #include #include #include #include uint32_t sftp_v6_realpath(struct sftpjob *job) { char *path, *compose, *resolvedpath; uint8_t control_byte = SSH_FXP_REALPATH_NO_CHECK; unsigned rpflags = 0; struct stat sb; struct sftpattr attrs; pcheck(sftp_parse_path(job, &path)); if(job->left) { pcheck(sftp_parse_uint8(job, &control_byte)); while(job->left) { pcheck(sftp_parse_path(job, &compose)); if(compose[0] == '/') path = compose; else { char *newpath = sftp_alloc(job->a, strlen(path) + strlen(compose) + 2); strcpy(newpath, path); strcat(newpath, "/"); strcat(newpath, compose); path = newpath; } } } D(("sftp_v6_realpath %s %#x", path, control_byte)); switch(control_byte) { case SSH_FXP_REALPATH_NO_CHECK: /* Don't follow links and don't fail if the path doesn't exist */ rpflags = 0; break; case SSH_FXP_REALPATH_STAT_IF: /* Follow links but don't fail if the path doesn't exist */ rpflags = RP_READLINK; break; case SSH_FXP_REALPATH_STAT_ALWAYS: /* Follow links and fail if the path doesn't exist */ rpflags = RP_READLINK|RP_MUST_EXIST; break; default: return SSH_FX_BAD_MESSAGE; } if(!(resolvedpath = sftp_find_realpath(job->a, path, rpflags))) return HANDLER_ERRNO; D(("...real path is %s", resolvedpath)); switch(control_byte) { case SSH_FXP_REALPATH_NO_CHECK: /* Don't stat, send dummy attributes */ memset(&attrs, 0, sizeof attrs); attrs.name = resolvedpath; break; case SSH_FXP_REALPATH_STAT_IF: /* stat as hard as we can but accept failure if it's just not there */ if(stat(resolvedpath, &sb) >= 0 || lstat(resolvedpath, &sb) >= 0) sftp_stat_to_attrs(job->a, &sb, &attrs, 0xFFFFFFFF, resolvedpath); else { memset(&attrs, 0, sizeof attrs); attrs.name = resolvedpath; } break; case SSH_FXP_REALPATH_STAT_ALWAYS: /* stat and error on failure */ if(stat(resolvedpath, &sb) >= 0 || lstat(resolvedpath, &sb) >= 0) sftp_stat_to_attrs(job->a, &sb, &attrs, 0xFFFFFFFF, resolvedpath); else /* Can only happen if path is deleted between realpath call and stat */ return HANDLER_ERRNO; break; } sftp_send_begin(job->worker); sftp_send_uint8(job->worker, SSH_FXP_NAME); sftp_send_uint32(job->worker, job->id); protocol->sendnames(job, 1, &attrs); sftp_send_end(job->worker); return HANDLER_RESPONDED; } uint32_t sftp_v6_link(struct sftpjob *job) { char *oldpath, *newlinkpath; uint8_t symbolic; struct stat sb; /* See also comment in v3.c for SSH_FXP_SYMLINK */ if(readonly) return SSH_FX_PERMISSION_DENIED; pcheck(sftp_parse_path(job, &newlinkpath)); pcheck(sftp_parse_path(job, &oldpath)); /* aka existing-path/target-paths */ pcheck(sftp_parse_uint8(job, &symbolic)); D(("sftp_link %s %s [%s]", oldpath, newlinkpath, symbolic ? "symbolic" : "hard")); if((symbolic ? symlink : link)(oldpath, newlinkpath) < 0) { switch(errno) { case EPERM: if(!symbolic && stat(oldpath, &sb) >= 0 && S_ISDIR(sb.st_mode)) /* Can't hard-link directories */ return SSH_FX_FILE_IS_A_DIRECTORY; else /* e.g. Linux returns EPERM for symlink or link on a FAT32 fs */ return SSH_FX_OP_UNSUPPORTED; break; default: return HANDLER_ERRNO; } } else return SSH_FX_OK; } uint32_t sftp_v6_version_select(struct sftpjob *job) { char *newversion; /* If we've already created the work queue then this can't be the first * message. */ if(!workqueue) { pcheck(sftp_parse_path(job, &newversion)); /* Handle known versions */ if(!strcmp(newversion, "3")) { protocol = &sftp_v3; return SSH_FX_OK; } if(!strcmp(newversion, "4")) { protocol = &sftp_v4; return SSH_FX_OK; } if(!strcmp(newversion, "5")) { protocol = &sftp_v5; return SSH_FX_OK; } if(!strcmp(newversion, "6")) { protocol = &sftp_v6; return SSH_FX_OK; } sftp_send_status(job, SSH_FX_INVALID_PARAMETER, "unknown version"); } else sftp_send_status(job, SSH_FX_INVALID_PARAMETER, "badly timed version-select"); /* We MUST close the channel. (-13, s5.5). */ exit(-1); } static const struct sftpcmd sftpv6tab[] = { { SSH_FXP_INIT, sftp_vany_already_init }, { SSH_FXP_OPEN, sftp_v56_open }, { SSH_FXP_CLOSE, sftp_vany_close }, { SSH_FXP_READ, sftp_vany_read }, { SSH_FXP_WRITE, sftp_vany_write }, { SSH_FXP_LSTAT, sftp_v456_lstat }, { SSH_FXP_FSTAT, sftp_v456_fstat }, { SSH_FXP_SETSTAT, sftp_vany_setstat }, { SSH_FXP_FSETSTAT, sftp_vany_fsetstat }, { SSH_FXP_OPENDIR, sftp_vany_opendir }, { SSH_FXP_READDIR, sftp_vany_readdir }, { SSH_FXP_REMOVE, sftp_vany_remove }, { SSH_FXP_MKDIR, sftp_vany_mkdir }, { SSH_FXP_RMDIR, sftp_vany_rmdir }, { SSH_FXP_REALPATH, sftp_v6_realpath }, { SSH_FXP_STAT, sftp_v456_stat }, { SSH_FXP_RENAME, sftp_v56_rename }, { SSH_FXP_READLINK, sftp_vany_readlink }, { SSH_FXP_LINK, sftp_v6_link }, { SSH_FXP_EXTENDED, sftp_vany_extended } }; /* TODO: file locking */ static const struct sftpextension sftp_v6_extensions[] = { { "posix-rename@openssh.org", sftp_vany_posix_rename }, { "space-available", sftp_vany_space_available }, { "statfs@openssh.org", sftp_vany_statfs }, { "text-seek", sftp_vany_text_seek }, { "version-select", sftp_v6_version_select }, }; const struct sftpprotocol sftp_v6 = { sizeof sftpv6tab / sizeof (struct sftpcmd), sftpv6tab, 6, (SSH_FILEXFER_ATTR_SIZE |SSH_FILEXFER_ATTR_PERMISSIONS |SSH_FILEXFER_ATTR_ACCESSTIME |SSH_FILEXFER_ATTR_CTIME |SSH_FILEXFER_ATTR_MODIFYTIME |SSH_FILEXFER_ATTR_OWNERGROUP |SSH_FILEXFER_ATTR_SUBSECOND_TIMES |SSH_FILEXFER_ATTR_BITS |SSH_FILEXFER_ATTR_LINK_COUNT), SSH_FX_NO_MATCHING_BYTE_RANGE_LOCK, sftp_v456_sendnames, sftp_v456_sendattrs, sftp_v456_parseattrs, sftp_v456_encode, sftp_v456_decode, sizeof sftp_v6_extensions / sizeof (struct sftpextension), sftp_v6_extensions, }; /* Local Variables: c-basic-offset:2 comment-column:40 fill-column:79 indent-tabs-mode:nil End: */ sftpserver-0.2.1/sftpclient.h0000664000175000017500000000203511625765051013174 00000000000000/* * This file is part of the Green End SFTP Server. * Copyright (C) 2007 Richard Kettlewell * * 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 2 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, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA */ #ifndef SFTPCLIENT_H #define SFTPCLIENT_H #define CLIENT 1 #include "sftpcommon.h" #include #endif /* SFTPCLIENT_H */ /* Local Variables: c-basic-offset:2 comment-column:40 fill-column:79 indent-tabs-mode:nil End: */ sftpserver-0.2.1/debug.h0000664000175000017500000000371311626705056012113 00000000000000/* * This file is part of the Green End SFTP Server. * Copyright (C) 2007 Richard Kettlewell * * 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 2 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, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA */ /** @file debug.h @brief Debug support interface */ #ifndef DEBUG_H #define DEBUG_H /* Debug support */ /** @brief True if debug information is to be written */ extern int sftp_debugging; /** @brief Filename for debug information */ extern const char *sftp_debugpath; /** @brief Debug output of bytes in hex * @param ptr Start of region to dump * @param n Number of bytes to dump * * @ref sftp_debugging must be nonzero. */ void sftp_debug_hexdump(const void *ptr, size_t n); /** @brief Write a debug message * @param fmt Format string as per printf(3) * @param ... Arguments * * @ref sftp_debugging must be nonzero. */ void sftp_debug_printf(const char *fmt, ...) attribute((format(printf,1,2))); /** @brief Issue a debug message * @param x Parenthesized format string and arguments * * Typical usage would be: * * @code * D(("the value of x is %d", x)); * @endcode */ #define D(x) do { \ if(sftp_debugging) \ sftp_debug_printf x; \ } while(0) #endif /* DEBUG_H */ /* Local Variables: c-basic-offset:2 comment-column:40 fill-column:79 indent-tabs-mode:nil End: */ sftpserver-0.2.1/handle.h0000664000175000017500000000725511626705056012265 00000000000000/* * This file is part of the Green End SFTP Server. * Copyright (C) 2007, 2011 Richard Kettlewell * * 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 2 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, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA */ /** @file handle.h @brief File handle interface */ #ifndef HANDLE_H #define HANDLE_H #include /** @brief Definition of a handle */ struct handleid { /** @brief Handle ID * * This is an index into the @ref handles array. At any given moment no two * valid handles have the same ID, but handles that do not overlap in * lifetime will often have matching IDs. */ uint32_t id; /** @brief Handle tag * * This is a sequence number, used to distinguish handles with the same ID. */ uint32_t tag; }; /** @brief Create a new file handle * @param id Where to store new handle * @param fd File descriptor to attach to handle * @param path Path name to attach to handle (will be copied) * @param flags Handle flags * * Valid handle flags are: * - @ref HANDLE_TEXT * - @ref HANDLE_APPEND */ void sftp_handle_new_file(struct handleid *id, int fd, const char *path, unsigned flags); /** @brief Handle flag for text files * * See sftp_handle_new_file(). */ #define HANDLE_TEXT 0x0001 /** @brief Handle flag for append-mode files * * See sftp_handle_new_file(). */ #define HANDLE_APPEND 0x0002 /** @brief Create a new directory handle * @param id Where to store new handle * @param dp Directory stream to attach to handle * @param path Path name to attach to handle (will be copied) */ void sftp_handle_new_dir(struct handleid *id, DIR *dp, const char *path); /** @brief Retrieve the flags for handle @p id * @param id Handle * @return Flag values * * If the handle is not valid, 0 is returned. */ unsigned sftp_handle_flags(const struct handleid *id); /** @brief Retrieve the file descriptor attached to handle @p id * @param id Handle * @param fd Where to store file descriptor * @param flagsp Where to store flags, or a null pointer * @return 0 on success, @ref SSH_FX_INVALID_HANDLE on error */ uint32_t sftp_handle_get_fd(const struct handleid *id, int *fd, unsigned *flagsp); /** @brief Retrieve the directory stream attached to handle @p id * @param id Handle * @param dp Where to store directory stream * @param pathp Where to store path, or a null pointer * @return 0 on success, @ref SSH_FX_INVALID_HANDLE on error * * If @p pathp is not a null pointer then the value assigned to @c *pathp * points to the handle's copy of the path name. It will not outlive the * handle. */ uint32_t sftp_handle_get_dir(const struct handleid *id, DIR **dp, const char **pathp); /** @brief Destroy a handle * @param id Handle to close * @return 0 on success, SFTP error code or HANDLER_ERRNO on error * * The attached file descriptor or director stream is closed. */ uint32_t sftp_handle_close(const struct handleid *id); #endif /* HANDLE_H */ /* Local Variables: c-basic-offset:2 comment-column:40 fill-column:79 indent-tabs-mode:nil End: */ sftpserver-0.2.1/stat.c0000664000175000017500000004453312344640542011774 00000000000000/* * This file is part of the Green End SFTP Server. * Copyright (C) 2007, 2011, 2014 Richard Kettlewell * * 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 2 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, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA */ /** @file stat.c @brief SFTP attribute support implementation */ #include "sftpserver.h" #include "types.h" #include "users.h" #include "sftp.h" #include "alloc.h" #include "debug.h" #include "stat.h" #include "utils.h" #include #include #include #include #include #include #if ! HAVE_FUTIMES int futimes(int fd, const struct timeval *times); #endif void sftp_stat_to_attrs(struct allocator *a, const struct stat *sb, struct sftpattr *attrs, uint32_t flags, const char *path) { memset(attrs, 0, sizeof *attrs); attrs->valid = (SSH_FILEXFER_ATTR_SIZE |SSH_FILEXFER_ATTR_PERMISSIONS |SSH_FILEXFER_ATTR_ACCESSTIME |SSH_FILEXFER_ATTR_MODIFYTIME |SSH_FILEXFER_ATTR_UIDGID |SSH_FILEXFER_ATTR_ALLOCATION_SIZE |SSH_FILEXFER_ATTR_LINK_COUNT |SSH_FILEXFER_ATTR_CTIME |SSH_FILEXFER_ATTR_BITS); switch(sb->st_mode & S_IFMT) { case S_IFIFO: attrs->type = SSH_FILEXFER_TYPE_FIFO; break; case S_IFCHR: attrs->type = SSH_FILEXFER_TYPE_CHAR_DEVICE; break; case S_IFDIR: attrs->type = SSH_FILEXFER_TYPE_DIRECTORY; break; case S_IFBLK: attrs->type = SSH_FILEXFER_TYPE_BLOCK_DEVICE; break; case S_IFREG: attrs->type = SSH_FILEXFER_TYPE_REGULAR; break; case S_IFLNK: attrs->type = SSH_FILEXFER_TYPE_SYMLINK; break; case S_IFSOCK: attrs->type = SSH_FILEXFER_TYPE_SOCKET; break; default: attrs->type = SSH_FILEXFER_TYPE_SPECIAL; break; } attrs->size = sb->st_size; /* The cast ensures we don't do the multiply in a small word and overflow */ attrs->allocation_size = (uint64_t)sb->st_blksize * sb->st_blocks; /* Only look up owner/group info if wanted */ if((flags & SSH_FILEXFER_ATTR_OWNERGROUP) && (attrs->owner = sftp_uid2name(a, sb->st_uid)) && (attrs->group = sftp_gid2name(a, sb->st_gid))) attrs->valid |= SSH_FILEXFER_ATTR_OWNERGROUP; attrs->uid = sb->st_uid; attrs->gid = sb->st_gid; attrs->permissions = sb->st_mode; attrs->atime.seconds = sb->st_atime; attrs->mtime.seconds = sb->st_mtime; attrs->ctime.seconds = sb->st_ctime; #if HAVE_STAT_TIMESPEC if(sb->st_atimespec.tv_nsec >= 0 && sb->st_atimespec.tv_nsec < 1000000000 && sb->st_mtimespec.tv_nsec >= 0 && sb->st_mtimespec.tv_nsec < 1000000000 && sb->st_ctimespec.tv_nsec >= 0 && sb->st_ctimespec.tv_nsec < 1000000000) { /* Only send subsecond times if they are in range */ attrs->atime.nanoseconds = sb->st_atimespec.tv_nsec; attrs->mtime.nanoseconds = sb->st_mtimespec.tv_nsec; attrs->ctime.nanoseconds = sb->st_ctimespec.tv_nsec; attrs->valid |= SSH_FILEXFER_ATTR_SUBSECOND_TIMES; } #endif attrs->link_count = sb->st_nlink; /* If we know the path we can determine whether the file is hidden or not */ if(path) { const char *s = path + strlen(path); /* Ignore trailing slashes */ while(s > path && s[-1] == '/') --s; while(s > path && s[-1] != '/') --s; if(*s == '.') attrs->attrib_bits |= SSH_FILEXFER_ATTR_FLAGS_HIDDEN; attrs->attrib_bits_valid |= SSH_FILEXFER_ATTR_FLAGS_HIDDEN; } /* TODO: SSH_FILEXFER_ATTR_FLAGS_CASE_INSENSITIVE for directories on * case-independent filesystems */ /* TODO: SSH_FILEXFER_ATTR_FLAGS_IMMUTABLE for immutable files. Perhaps when * I can find some documentation on the subject. */ attrs->name = path; } /** @brief Table of attribute bit names */ static const struct { uint32_t bit; const char *description; } attr_bits[] = { { SSH_FILEXFER_ATTR_FLAGS_READONLY, "ro" }, { SSH_FILEXFER_ATTR_FLAGS_SYSTEM, "sys" }, { SSH_FILEXFER_ATTR_FLAGS_HIDDEN, "hide" }, { SSH_FILEXFER_ATTR_FLAGS_CASE_INSENSITIVE, "ci"}, { SSH_FILEXFER_ATTR_FLAGS_ARCHIVE, "arc" }, { SSH_FILEXFER_ATTR_FLAGS_ENCRYPTED, "enc" }, { SSH_FILEXFER_ATTR_FLAGS_COMPRESSED, "comp" }, { SSH_FILEXFER_ATTR_FLAGS_SPARSE, "sp" }, { SSH_FILEXFER_ATTR_FLAGS_APPEND_ONLY, "app" }, { SSH_FILEXFER_ATTR_FLAGS_IMMUTABLE, "imm" }, { SSH_FILEXFER_ATTR_FLAGS_SYNC, "sync" }, { SSH_FILEXFER_ATTR_FLAGS_TRANSLATION_ERR, "trans" } }; const char *sftp_format_attr(struct allocator *a, const struct sftpattr *attrs, int thisyear, unsigned long flags) { char perms[64], linkcount[64], size[64], date[64], nowner[64], ngroup[64]; char *formatted, *p, *bits; size_t nbits; const char *owner, *group; static const char typedetails[] = "?-dl??scbp"; size_t n; /* permissions */ p = perms; *p++ = typedetails[attrs->type]; if(attrs->valid & SSH_FILEXFER_ATTR_PERMISSIONS) { *p++ = (attrs->permissions & 00400) ? 'r' : '-'; *p++ = (attrs->permissions & 00200) ? 'w' : '-'; switch(attrs->permissions & 04100) { case 00000: *p++ = '-'; break; case 00100: *p++ = 'x'; break; case 04000: *p++ = 'S'; break; case 04100: *p++ = 's'; break; } *p++ = (attrs->permissions & 00040) ? 'r' : '-'; *p++ = (attrs->permissions & 00020) ? 'w' : '-'; switch(attrs->permissions & 02010) { case 00000: *p++ = '-'; break; case 00010: *p++ = 'x'; break; case 02000: *p++ = 'S'; break; case 02010: *p++ = 's'; break; } *p++ = (attrs->permissions & 00004) ? 'r' : '-'; *p++ = (attrs->permissions & 00002) ? 'w' : '-'; switch(attrs->permissions & 01001) { case 00000: *p++ = '-'; break; case 00001: *p++ = 'x'; break; case 01000: *p++ = 'T'; break; case 01001: *p++ = 't'; break; } *p = 0; } else strcpy(p, "?????????"); /* link count */ if(attrs->valid & SSH_FILEXFER_ATTR_LINK_COUNT) sprintf(linkcount, "%"PRIu32, attrs->link_count); else strcpy(linkcount, "?"); /* size */ if(attrs->valid & SSH_FILEXFER_ATTR_SIZE) sprintf(size, "%"PRIu64, attrs->size); else strcpy(size, "?"); /* ownership */ if(attrs->valid & SSH_FILEXFER_ATTR_UIDGID) { sprintf(nowner, "%"PRIu32, attrs->uid); sprintf(ngroup, "%"PRIu32, attrs->gid); } owner = group = "?"; if(flags & FORMAT_PREFER_NUMERIC_UID) { if(attrs->valid & SSH_FILEXFER_ATTR_UIDGID) { owner = nowner; group = ngroup; } else if(attrs->valid & SSH_FILEXFER_ATTR_OWNERGROUP) { owner = attrs->owner; group = attrs->group; } } else { if(attrs->valid & SSH_FILEXFER_ATTR_OWNERGROUP) { owner = attrs->owner; group = attrs->group; } else if(attrs->valid & SSH_FILEXFER_ATTR_UIDGID) { owner = nowner; group = ngroup; } } /* timestamp */ if(attrs->valid & SSH_FILEXFER_ATTR_MODIFYTIME) { struct tm mtime; const time_t m = attrs->mtime.seconds; (flags & FORMAT_PREFER_LOCALTIME ? localtime_r : gmtime_r)(&m, &mtime); /* Timestamps in the current year we give down to seconds. For * timestamps in other years we give the year. */ if(mtime.tm_year == thisyear) strftime(date, sizeof date, "%b %d %H:%M", &mtime); else strftime(date, sizeof date, "%b %d %Y", &mtime); } else strcpy(date, "?"); /* attribute bits */ bits = NULL; nbits = 0; if(flags & FORMAT_ATTRS && (attrs->valid & SSH_FILEXFER_ATTR_BITS) && attrs->attrib_bits) { bits = append(a, bits, &nbits, "["); for(n = 0; n < sizeof attr_bits / sizeof *attr_bits; ++n) { if(attrs->attrib_bits & attr_bits[n].bit) { if(bits[1]) bits = append(a, bits, &nbits, ","); bits = append(a, bits, &nbits, attr_bits[n].description); } } bits = append(a, bits, &nbits, "]"); } /* Format the result */ formatted = sftp_alloc(a, 80 + strlen(attrs->name)); /* The draft is pretty specific about field widths */ sprintf(formatted, "%10.10s %3.3s %-8.8s %-8.8s %8.8s %12.12s %s%s%s%s%s", perms, linkcount, owner, group, size, date, attrs->name, attrs->target ? " -> " : "", attrs->target ? attrs->target : "", flags & FORMAT_ATTRS ? " " : "", flags & FORMAT_ATTRS ? bits : ""); return formatted; } uint32_t sftp_normalize_ownergroup(struct allocator *a, struct sftpattr *attrs) { uint32_t rc = SSH_FX_OK; switch(attrs->valid & (SSH_FILEXFER_ATTR_UIDGID |SSH_FILEXFER_ATTR_OWNERGROUP)) { case SSH_FILEXFER_ATTR_UIDGID: if((attrs->owner = sftp_uid2name(a, attrs->uid)) && (attrs->group = sftp_gid2name(a, attrs->gid))) attrs->valid |= SSH_FILEXFER_ATTR_OWNERGROUP; break; case SSH_FILEXFER_ATTR_OWNERGROUP: if((attrs->uid = sftp_name2uid(attrs->owner)) == (uid_t)-1) rc = SSH_FX_OWNER_INVALID; if((attrs->gid = sftp_name2gid(attrs->group)) == (gid_t)-1) rc = SSH_FX_GROUP_INVALID; if(rc == SSH_FX_OK) attrs->valid |= SSH_FILEXFER_ATTR_UIDGID; break; } return rc; } /** @brief Callbacks for do_sftp_set_status() */ struct sftp_set_status_callbacks { /** @brief Truncate callback * @param what Object to truncate * @param size New size * @return 0 on success, -ve on error */ int (*do_truncate)(const void *what, off_t size); /** @brief Change ownership callback * @param what Object to modify * @param uid New UID * @param gid New GID * @return 0 on success, -ve on error */ int (*do_chown)(const void *what, uid_t uid, gid_t gid); /** @brief Change mode callback * @param what Object to modify * @param mode New mode * @return 0 on success, -ve on error */ int (*do_chmod)(const void *what, mode_t mode); /** @brief Get attributes callback * @param what Object to inspect * @param sb Where to store information * @return 0 on success, -ve on error */ int (*do_stat)(const void *what, struct stat *sb); /** @brief Set file times * @param what Object to modify * @param tv New times * @return 0 on success, -ve on error */ int (*do_utimes)(const void *what, struct timeval *tv); }; /* Horrendous ugliness for SETSTAT/FSETSTAT */ #if HAVE_STAT_TIMESPEC /** @brief Helper macro to set fractional part of timestamps */ #define SET_STATUS_NANOSEC do { \ times[0].tv_usec = ((attrs.valid & SSH_FILEXFER_ATTR_ACCESSTIME) \ ? (long)attrs.atime.nanoseconds \ : current.st_atimespec.tv_nsec) / 1000; \ times[1].tv_usec = ((attrs.valid & SSH_FILEXFER_ATTR_MODIFYTIME) \ ? (long)attrs.mtime.nanoseconds \ : current.st_mtimespec.tv_nsec) / 1000; \ } while(0) #else #define SET_STATUS_NANOSEC ((void)0) #endif /** @brief Implementation of sftp_set_status() and sftp_set_fstatus() * @param a Allocator * @param what Object to modify * @param attrsp Attributes to set * @param cb Callbacks for object type * @param whyp Where to store error string, or a null pointer * @return 0 on success or an error code on failure */ static uint32_t do_sftp_set_status(struct allocator *a, const void *what, const struct sftpattr *attrsp, const struct sftp_set_status_callbacks *cb, const char **whyp) { struct timeval times[2]; struct stat current; struct sftpattr attrs = *attrsp; const char *why; if(!whyp) whyp = &why; *whyp = 0; if((attrs.valid & (SSH_FILEXFER_ATTR_SIZE|SSH_FILEXFER_ATTR_ALLOCATION_SIZE)) == (SSH_FILEXFER_ATTR_SIZE|SSH_FILEXFER_ATTR_ALLOCATION_SIZE) && attrs.allocation_size < attrs.size) { /* This is a MUST, e.g. draft -13 s7.4. We honor it even though we don't * honor allocation-size. */ *whyp = "size exceeds allocation-size"; return SSH_FX_INVALID_PARAMETER; } if(attrs.valid & (SSH_FILEXFER_ATTR_LINK_COUNT |SSH_FILEXFER_ATTR_TEXT_HINT)) /* Client has violated a MUST NOT */ return SSH_FX_INVALID_PARAMETER; if((attrs.valid & (SSH_FILEXFER_ATTR_SIZE |SSH_FILEXFER_ATTR_PERMISSIONS |SSH_FILEXFER_ATTR_ACCESSTIME |SSH_FILEXFER_ATTR_MODIFYTIME |SSH_FILEXFER_ATTR_UIDGID |SSH_FILEXFER_ATTR_OWNERGROUP |SSH_FILEXFER_ATTR_SUBSECOND_TIMES |SSH_FILEXFER_ATTR_ALLOCATION_SIZE)) != attrs.valid) { /* SHOULD not change any attributes if we cannot perform as required. We * have a SHOULD which allows us to ignore allocation-size. */ *whyp = "unsupported flags"; return SSH_FX_OP_UNSUPPORTED; } if(attrs.valid & SSH_FILEXFER_ATTR_SIZE) { D(("...truncate to %"PRIu64, attrs.size)); if(cb->do_truncate(what, attrs.size) < 0) { *whyp = "truncate"; return HANDLER_ERRNO; } } sftp_normalize_ownergroup(a, &attrs); if(attrs.valid & SSH_FILEXFER_ATTR_UIDGID) { D(("...chown to %"PRId32"/%"PRId32, attrs.uid, attrs.gid)); if(cb->do_chown(what, attrs.uid, attrs.gid) < 0) { *whyp = "chown"; return HANDLER_ERRNO; } } if(attrs.valid & SSH_FILEXFER_ATTR_PERMISSIONS) { const mode_t mode = attrs.permissions & 07777; D(("...chmod to %#o", (unsigned)mode)); if(cb->do_chmod(what, mode) < 0) { *whyp = "chmod"; return HANDLER_ERRNO; } } if(attrs.valid & (SSH_FILEXFER_ATTR_ACCESSTIME |SSH_FILEXFER_ATTR_MODIFYTIME)) { if(cb->do_stat(what, ¤t) < 0) { D(("cannot stat")); *whyp = "stat"; return HANDLER_ERRNO; } memset(times, 0, sizeof times); times[0].tv_sec = ((attrs.valid & SSH_FILEXFER_ATTR_ACCESSTIME) ? (time_t)attrs.atime.seconds : current.st_atime); times[1].tv_sec = ((attrs.valid & SSH_FILEXFER_ATTR_MODIFYTIME) ? (time_t)attrs.mtime.seconds : current.st_mtime); #if HAVE_STAT_TIMESPEC if(attrs.valid & SSH_FILEXFER_ATTR_SUBSECOND_TIMES) { times[0].tv_usec = ((attrs.valid & SSH_FILEXFER_ATTR_ACCESSTIME) ? (long)attrs.atime.nanoseconds : current.st_atimespec.tv_nsec) / 1000; times[1].tv_usec = ((attrs.valid & SSH_FILEXFER_ATTR_MODIFYTIME) ? (long)attrs.mtime.nanoseconds : current.st_mtimespec.tv_nsec) / 1000; } #endif D(("...utimes to atime %lu.%06lu mtime %lu.%06lu", (unsigned long)times[0].tv_sec, (unsigned long)times[0].tv_usec, (unsigned long)times[1].tv_sec, (unsigned long)times[1].tv_usec)); if(cb->do_utimes(what, times) < 0) { *whyp = "utimes"; return HANDLER_ERRNO; } } return SSH_FX_OK; } /** @brief Truncate a file by name * @param what Object to truncate * @param size New size * @return 0 on success, -ve on error */ static int name_truncate(const void *what, off_t size) { return truncate(what, size); } /** @brief Change ownership by name * @param what Object to modify * @param uid New UID * @param gid New GID * @return 0 on success, -ve on error */ static int name_chown(const void *what, uid_t uid, gid_t gid) { return chown(what, uid, gid); } /** @brief Change mode by name * @param what Object to modify * @param mode New mode * @return 0 on success, -ve on error */ static int name_chmod(const void *what, mode_t mode) { return chmod(what, mode); } /** @brief Get attributes by name * @param what Object to inspect * @param sb Where to store information * @return 0 on success, -ve on error */ static int name_lstat(const void *what, struct stat *sb) { return lstat(what, sb); } /** @brief Set file times by name * @param what Object to modify * @param tv New times * @return 0 on success, -ve on error */ static int name_utimes(const void *what, struct timeval *tv) { return utimes(what, tv); } /** @brief Table of callbacks for sftp_set_status() */ static const struct sftp_set_status_callbacks name_callbacks = { name_truncate, name_chown, name_chmod, name_lstat, name_utimes }; uint32_t sftp_set_status(struct allocator *a, const char *path, const struct sftpattr *attrsp, const char **whyp) { return do_sftp_set_status(a, path, attrsp, &name_callbacks, whyp); } /** @brief Truncate a file by fd * @param what Object to truncate * @param size New size * @return 0 on success, -ve on error */ static int fd_truncate(const void *what, off_t size) { return ftruncate(*(const int *)what, size); } /** @brief Change ownership by fd * @param what Object to modify * @param uid New UID * @param gid New GID * @return 0 on success, -ve on error */ static int fd_chown(const void *what, uid_t uid, gid_t gid) { return fchown(*(const int *)what, uid, gid); } /** @brief Change mode by fd * @param what Object to modify * @param mode New mode * @return 0 on success, -ve on error */ static int fd_chmod(const void *what, mode_t mode) { return fchmod(*(const int *)what, mode); } /** @brief Get attributes by fd * @param what Object to inspect * @param sb Where to store information * @return 0 on success, -ve on error */ static int fd_stat(const void *what, struct stat *sb) { return fstat(*(const int *)what, sb); } /** @brief Set file times by fd * @param what Object to modify * @param tv New times * @return 0 on success, -ve on error */ static int fd_utimes(const void *what, struct timeval *tv) { return futimes(*(const int *)what, tv); } /** @brief Table of callbacks for sftp_set_fstatus() */ static const struct sftp_set_status_callbacks fd_callbacks = { fd_truncate, fd_chown, fd_chmod, fd_stat, fd_utimes }; uint32_t sftp_set_fstatus(struct allocator *a, int fd, const struct sftpattr *attrsp, const char **whyp) { return do_sftp_set_status(a, &fd, attrsp, &fd_callbacks, whyp); } /* Local Variables: c-basic-offset:2 comment-column:40 fill-column:79 indent-tabs-mode:nil End: */ sftpserver-0.2.1/send.c0000664000175000017500000001131212340114433011726 00000000000000/* * This file is part of the Green End SFTP Server. * Copyright (C) 2007, 2011 Richard Kettlewell * * 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 2 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, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA */ /** @file send.c @brief Message sending implementation */ #include "sftpserver.h" #include "debug.h" #include "utils.h" #include "handle.h" #include "send.h" #include "thread.h" #include "types.h" #include "globals.h" #include #include #include #include #include #include #include "putword.h" /** @brief Mutex to serialize IO */ static pthread_mutex_t output_lock = PTHREAD_MUTEX_INITIALIZER; int sftpout = 1; /* default is stdout */ /** @brief Store a 16-bit value */ #define sftp_send_raw16(u) do { \ put16(&w->buffer[w->bufused], u); \ w->bufused += 2; \ } while(0) /** @brief Store a 32-bit value */ #define sftp_send_raw32(u) do { \ put32(&w->buffer[w->bufused], u); \ w->bufused += 4; \ } while(0) /** @brief Store a 64-bit value */ #define sftp_send_raw64(u) do { \ put64(&w->buffer[w->bufused], u); \ w->bufused += 8; \ } while(0) void sftp_send_need(struct worker *w, size_t n) { assert(w->bufused < 0x80000000); if(n > w->bufsize - w->bufused) { size_t newsize = w->bufsize ? w->bufsize : 64; while(newsize && newsize < w->bufsize + n) newsize <<= 1; if(!newsize) fatal("sftp_send_need: out of memory (%zu)", n); w->buffer = xrealloc(w->buffer, w->bufsize = newsize); } } void sftp_send_begin(struct worker *w) { w->bufused = 0; sftp_send_uint32(w, 0); /* placeholder for length */ } void sftp_send_end(struct worker *w) { ssize_t n, written; assert(w->bufused < 0x80000000); /* Fill in length word. The malloc'd area is assumed to be aligned * suitably. */ *(uint32_t *)w->buffer = htonl(w->bufused - 4); /* Write the complete output, protecting stdout with a lock to avoid * interleaving different responses. */ ferrcheck(pthread_mutex_lock(&output_lock)); if(sftp_debugging) { D(("%s:", sendtype)); sftp_debug_hexdump(w->buffer + 4, w->bufused - 4); } /* Write the whole buffer, coping with short writes */ written = 0; while((size_t)written < w->bufused) if((n = write(sftpout, w->buffer + written, w->bufused - written)) > 0) written += n; else if(n < 0) fatal("error sending response: %s", strerror(errno)); ferrcheck(pthread_mutex_unlock(&output_lock)); w->bufused = 0x80000000; } void sftp_send_uint8(struct worker *w, int n) { sftp_send_need(w, 1); w->buffer[w->bufused++] = (uint8_t)n; } void sftp_send_uint16(struct worker *w, uint16_t u) { sftp_send_need(w, 2); sftp_send_raw16(u); } void sftp_send_uint32(struct worker *w, uint32_t u) { sftp_send_need(w, 4); sftp_send_raw32(u); } void sftp_send_uint64(struct worker *w, uint64_t u) { sftp_send_need(w, 8); sftp_send_raw64(u); } void sftp_send_bytes(struct worker *w, const void *bytes, size_t n) { sftp_send_need(w, n + 4); sftp_send_raw32(n); memcpy(w->buffer + w->bufused, bytes, n); w->bufused += n; } void sftp_send_string(struct worker *w, const char *s) { sftp_send_bytes(w, s, strlen(s)); } void sftp_send_path(struct sftpjob *job, struct worker *w, const char *path) { if(protocol->encode(job, (char **)&path)) fatal("cannot encode local path name '%s'", path); sftp_send_string(w, path); } void sftp_send_handle(struct worker *w, const struct handleid *id) { sftp_send_need(w, 12); sftp_send_raw32(8); sftp_send_raw32(id->id); sftp_send_raw32(id->tag); } size_t sftp_send_sub_begin(struct worker *w) { sftp_send_need(w, 4); w->bufused += 4; return w->bufused; } void sftp_send_sub_end(struct worker *w, size_t offset) { const size_t latest = w->bufused; w->bufused = offset - 4; sftp_send_raw32(latest - offset); w->bufused = latest; } /* Local Variables: c-basic-offset:2 comment-column:40 fill-column:79 indent-tabs-mode:nil End: */ sftpserver-0.2.1/sftpserver.c0000644000175000017500000005112612415610023013204 00000000000000/* * This file is part of the Green End SFTP Server. * Copyright (C) 2007, 2009, 2011, 2014 Richard Kettlewell * * 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 2 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, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA */ /** @file sftpserver.c @brief SFTP server implementation */ #include "sftpserver.h" #include "queue.h" #include "alloc.h" #include "debug.h" #include "utils.h" #include "sftp.h" #include "send.h" #include "parse.h" #include "types.h" #include "globals.h" #include "serialize.h" #include "xfns.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #if HAVE_SYS_PRCTL_H # include #endif /* Linux and BSD have daemon() but other UNIX platforms tend not to */ #if ! HAVE_DAEMON int daemon(int, int); #endif /* LOG_FTP doesn't exist everywhere */ #ifndef LOG_FTP # define LOG_FTP LOG_DAEMON #endif /* Forward declarations */ static void *worker_init(void); static void worker_cleanup(void *wdv); static void process_sftpjob(void *jv, void *wdv, struct allocator *a); static void sftp_service(void); /** @brief Local character encoding */ static const char *local_encoding; /** @brief Queue-specific callbacks for processing SFTP requests */ static const struct queuedetails workqueue_details = { worker_init, process_sftpjob, worker_cleanup }; const struct sftpprotocol *protocol = &sftp_preinit; const char sendtype[] = "response"; /* Options */ static const struct option options[] = { { "help", no_argument, 0, 'h' }, { "version", no_argument, 0, 'V' }, { "debug", no_argument, 0, 'd' }, { "debug-file", required_argument, 0, 'D' }, #if DAEMON { "chroot", required_argument, 0, 'r' }, { "user", required_argument, 0, 'u' }, { "listen", required_argument, 0, 'L' }, { "host", required_argument, 0, 'H' }, { "background", no_argument, 0, 'b' }, { "ipv4", no_argument, 0, '4' }, { "ipv6", no_argument, 0, '6' }, #endif { "readonly", no_argument, 0, 'R' }, { 0, 0, 0, 0 } }; /* display usage message and terminate */ static void help(void) { xprintf("Usage:\n" " gesftpserver [OPTIONS]\n" "\n" "Green End SFTP server. Not intended for interactive use!\n" "\n"); xprintf("Options:\n" " --help, -h Display usage message\n" " --version, -V Display version number\n" #if DAEMON " --chroot, -r PATH Change root to PATH\n" " --user, -u USER Change to user USER\n" " --listen, -L PORT Listen on PORT\n" " --host, -H HOSTNAME Bind to HOSTNAME (default *)\n" " -4|-6 Force IPv4 or IPv6 for --listen\n" " --background, -b Daemonize\n" #endif " --readonly, -R Read-only mode\n"); exit(0); } /* display version number and terminate */ static void version(void) { xprintf("Green End SFTP server version %s\n", VERSION); exit(0); } /* Initialization */ /** @brief Implementation of @ref SSH_FXP_INIT * @param job Job * @return Error code */ static uint32_t sftp_init(struct sftpjob *job) { uint32_t version; size_t offset; int n; /* Cannot initialize more than once */ if(protocol != &sftp_preinit) return SSH_FX_FAILURE; pcheck(sftp_parse_uint32(job, &version)); switch(version) { case 0: case 1: case 2: return SSH_FX_OP_UNSUPPORTED; case 3: protocol = &sftp_v3; #if REVERSE_SYMLINK reverse_symlink = 1; #endif break; case 4: protocol = &sftp_v4; break; case 5: protocol = &sftp_v5; break; default: protocol = &sftp_v6; break; } sftp_send_begin(job->worker); sftp_send_uint8(job->worker, SSH_FXP_VERSION); sftp_send_uint32(job->worker, protocol->version); if(protocol->version >= 4) { /* e.g. draft-ietf-secsh-filexfer-04.txt, 4.3. This allows us to assume the * client always sends \n, freeing us from the burden of translating text * files. However we still have to deal with the different rules for reads * and writes on text files. */ sftp_send_string(job->worker, "newline"); sftp_send_string(job->worker, "\n"); } if(protocol->version == 5) { /* draft-ietf-secsh-filexfer-05.txt 4.4 */ sftp_send_string(job->worker, "supported"); offset = sftp_send_sub_begin(job->worker); sftp_send_uint32(job->worker, (SSH_FILEXFER_ATTR_SIZE |SSH_FILEXFER_ATTR_PERMISSIONS |SSH_FILEXFER_ATTR_ACCESSTIME |SSH_FILEXFER_ATTR_MODIFYTIME |SSH_FILEXFER_ATTR_OWNERGROUP |SSH_FILEXFER_ATTR_SUBSECOND_TIMES)); sftp_send_uint32(job->worker, 0); /* supported-attribute-bits */ sftp_send_uint32(job->worker, (SSH_FXF_ACCESS_DISPOSITION |SSH_FXF_APPEND_DATA |SSH_FXF_APPEND_DATA_ATOMIC |SSH_FXF_TEXT_MODE)); sftp_send_uint32(job->worker, 0xFFFFFFFF); /* If we send a non-0 max-read-size then we promise to return that many * bytes if asked for it and to mean EOF or error if we return less. * * This is completely useless. If we end up reading from something like a * pipe then we may get a short read before EOF. If we've sent a non-0 * max-read-size then the client will wrongly interpret this as EOF. * * Therefore we send 0 here. */ sftp_send_uint32(job->worker, 0); for(n = 0; n < protocol->nextensions; ++n) sftp_send_string(job->worker, protocol->extensions[n].name); sftp_send_sub_end(job->worker, offset); } if(protocol->version >= 6) { /* draft-ietf-secsh-filexfer-13.txt 5.4 */ sftp_send_string(job->worker, "supported2"); offset = sftp_send_sub_begin(job->worker); sftp_send_uint32(job->worker, (SSH_FILEXFER_ATTR_SIZE |SSH_FILEXFER_ATTR_PERMISSIONS |SSH_FILEXFER_ATTR_ACCESSTIME |SSH_FILEXFER_ATTR_MODIFYTIME |SSH_FILEXFER_ATTR_OWNERGROUP |SSH_FILEXFER_ATTR_SUBSECOND_TIMES)); /* Note - the client is invited to only send these bits, rather than * promised that we never send anything else. Therefore 'supported-' is a * misnomer. In particular we will send SSH_FILEXFER_ATTR_CTIME but cannot * set the ctime of files and so follow the SHOULD that tells us to reject * attempts to do so. */ sftp_send_uint32(job->worker, 0); /* supported-attribute-bits */ sftp_send_uint32(job->worker, (SSH_FXF_ACCESS_DISPOSITION |SSH_FXF_APPEND_DATA |SSH_FXF_APPEND_DATA_ATOMIC |SSH_FXF_TEXT_MODE |SSH_FXF_NOFOLLOW |SSH_FXF_DELETE_ON_CLOSE)); /* supported-open-flags */ sftp_send_uint32(job->worker, 0xFFFFFFFF); /* supported-access-mask */ sftp_send_uint32(job->worker, 0); /* max-read-size - see above */ sftp_send_uint16(job->worker, 1); /* supported-open-block-vector */ sftp_send_uint16(job->worker, 1); /* supported-block-vector */ sftp_send_uint32(job->worker, 0); /* attrib-extension-count */ /* attrib-extensions would go here */ sftp_send_uint32(job->worker, protocol->nextensions); /* extension-count */ for(n = 0; n < protocol->nextensions; ++n) sftp_send_string(job->worker, protocol->extensions[n].name); sftp_send_sub_end(job->worker, offset); /* e.g. draft-ietf-secsh-filexfer-13.txt, 5.5 */ sftp_send_string(job->worker, "versions"); sftp_send_string(job->worker, "3,4,5,6"); } { /* vendor-id is defined in some of the SFTP drafts but not all. * Whatever. */ sftp_send_string(job->worker, "vendor-id"); offset = sftp_send_sub_begin(job->worker); sftp_send_string(job->worker, "Green End"); sftp_send_string(job->worker, "Green End SFTP Server"); sftp_send_string(job->worker, VERSION); sftp_send_uint64(job->worker, 0); sftp_send_sub_end(job->worker, offset); } /* This simple extension documents the order we expect for SSH_FXP_SYMLINK * args. See the comment in v3.c for further details. */ sftp_send_string(job->worker, "symlink-order@rjk.greenend.org.uk"); if(reverse_symlink) sftp_send_string(job->worker, "targetpath-linkpath"); else sftp_send_string(job->worker, "linkpath-targetpath"); if(protocol->version >= 6) { /* Just in case l-) */ sftp_send_string(job->worker, "link-order@rjk.greenend.org.uk"); sftp_send_string(job->worker, "linkpath-targetpath"); } sftp_send_end(job->worker); if(protocol->version < 6) { /* Now we are initialized we can safely process other jobs in the * background. We can't do this for v6 because the first request might be * version-select. */ D(("normal work queue creation")); queue_init(&workqueue, &workqueue_details, 4); } return HANDLER_RESPONDED; } /** @brief Requests supported prior to initialization */ static const struct sftpcmd sftppreinittab[] = { { SSH_FXP_INIT, sftp_init } }; /** @brief Protocol supported prior to initialization * * Only @ref SSH_FXP_INIT is supported at first. */ const struct sftpprotocol sftp_preinit = { sizeof sftppreinittab / sizeof (struct sftpcmd), sftppreinittab, 3, 0xFFFFFFFF, /* never used */ SSH_FX_OP_UNSUPPORTED, 0, 0, 0, sftp_v3_encode, 0, 0, 0 }; /* Worker setup/teardown */ /** @brief Worker thread setup for processing SFTP requests * @return Initialized worker state */ static void *worker_init(void) { struct worker *w = xmalloc(sizeof *w); memset(w, 0, sizeof *w); w->buffer = 0; if((w->utf8_to_local = iconv_open(local_encoding, "UTF-8")) == (iconv_t)-1) fatal("error calling iconv_open(%s,UTF-8): %s", local_encoding, strerror(errno)); if((w->local_to_utf8 = iconv_open("UTF-8", local_encoding)) == (iconv_t)-1) fatal("error calling iconv_open(UTF-8,%s): %s", local_encoding, strerror(errno)); return w; } /** @brief Worker thread cleanup after processing SFTP requests * @param wdv Worker state created by worker_init() */ static void worker_cleanup(void *wdv) { struct worker *w = wdv; iconv_close(w->utf8_to_local); iconv_close(w->local_to_utf8); free(w->buffer); free(w); } /* Main loop */ /** @brief Worker thread function to process an SFTP job * @param jv Job from queue * @param wdv Worker state created by worker_init() * @param a Allocator to use * * Only called in a worker thread, except prior to @ref SSH_FXP_INIT * completing. */ static void process_sftpjob(void *jv, void *wdv, struct allocator *a) { struct sftpjob *const job = jv; int l, r, type = 0; uint32_t status, rc; job->a = a; job->id = 0; job->worker = wdv; job->ptr = job->data; job->left = job->len; /* Empty messages are never valid */ if(!job->left) { sftp_send_status(job, SSH_FX_BAD_MESSAGE, "empty request"); goto done; } /* Get the type */ type = *job->ptr++; --job->left; /* Everything but SSH_FXP_INIT has an ID field */ if(type != SSH_FXP_INIT) if((rc = sftp_parse_uint32(job, &job->id)) != SSH_FX_OK) { sftp_send_status(job, rc, "missing ID field"); goto done; } /* Locate the handler for the command */ l = 0; r = protocol->ncommands - 1; while(l <= r) { const int m = (l + r) / 2; const int mtype = protocol->commands[m].type; if(type < mtype) r = m - 1; else if(type > mtype) l = m + 1; else { /* Serialize */ serialize(job); /* Run the handler */ status = protocol->commands[m].handler(job); /* Send a response if necessary */ switch(status) { case HANDLER_RESPONDED: break; default: sftp_send_status(job, status, 0); break; } goto done; } } /* We did not find a handler */ sftp_send_status(job, SSH_FX_OP_UNSUPPORTED, 0); done: serialize_remove_job(job); free(job->data); free(job); if(type != SSH_FXP_INIT && workqueue == 0) { /* This must have been the first job after initializing to version 6. It * might or might not have been version-select but either way it's now safe * to go multithreaded. */ D(("late work queue creation")); queue_init(&workqueue, &workqueue_details, 4); } return; } #if DAEMON static void sigchld_handler(int attribute((unused)) sig) { const int save_errno = errno; int w; while(waitpid(-1, &w, WNOHANG) > 0) ; errno = save_errno; } #endif int main(int argc, char **argv) { int n; const char *bn; #if DAEMON iconv_t cd; int listenfd = -1; const char *root = 0, *user = 0; struct passwd *pw = 0; const char *host = 0, *port = 0; int daemonize = 0; struct addrinfo hints; memset(&hints, 0, sizeof hints); hints.ai_flags = AI_PASSIVE; hints.ai_family = PF_UNSPEC; hints.ai_socktype = SOCK_STREAM; #endif /* Find basename of executable */ if(!(bn = strrchr(argv[0], '/'))) bn = argv[0]; /* Run in debug mode */ if(strstr(bn, "-debug")) { const char *home = getenv("HOME"); sftp_debugpath = xmalloc(strlen(home) + 40); sprintf((char *)sftp_debugpath, "%s/.gesftpserver.%ju", home, (uintmax_t)getpid()); sftp_debugging = 1; } /* Run in readonly mode */ if(strstr(bn, "-ro")) readonly = 1; /* We need I18N support for filename encoding */ setlocale(LC_CTYPE, ""); local_encoding = nl_langinfo(CODESET); while((n = getopt_long(argc, argv, "hVdD:r:u:H:L:b46R", options, 0)) >= 0) { switch(n) { case 'h': help(); case 'V': version(); case 'd': sftp_debugging = 1; break; case 'D': sftp_debugging = 1; sftp_debugpath = optarg; break; #if DAEMON case 'r': root = optarg; break; case 'u': user = optarg; break; case 'H': host = optarg; break; case 'L': port = optarg; break; case 'b': daemonize = 1; break; case '4': hints.ai_family = PF_INET; break; case '6': hints.ai_family = PF_INET6; break; #endif case 'R': readonly = 1; break; default: exit(1); } } #if DAEMON if(daemonize && !port) fatal("--background requires --port"); #endif /* If writes to the client fail then we'll get EPIPE. Arguably it might * better just to die the SIGPIPE but reporting an EPIPE is pretty harmless. * * If by some chance we end up writing to a pipe then we'd rather have an * EPIPE so we can report it back to the client than a SIGPIPE which will * (from the client's POV) cause us to close the connection without * responding to at least one command. * * Therefore, we ignore SIGPIPE. * * * As for other signals, we assume that if someone invokes us with an unusual * signal disposition, they have a good reason for it. */ signal(SIGPIPE, SIG_IGN); #if HAVE_PRCTL if(prctl(PR_SET_DUMPABLE, 0L) < 0) fatal("error calling prctl: %s", strerror(errno)); #endif #if DAEMON if(user) { /* Look up the user */ if(!(pw = getpwnam(user))) fatal("no such user as %s", user); if(initgroups(user, pw->pw_gid)) fatal("error calling initgroups: %s", strerror(errno)); } if(port) { struct addrinfo *res; int rc; static const int one = 1; struct sigaction sa; sa.sa_handler = sigchld_handler; sa.sa_flags = SA_RESTART; sigemptyset(&sa.sa_mask); if(sigaction(SIGCHLD, &sa, 0) < 0) fatal("error calling sigaction: %s", strerror(errno)); if((rc = getaddrinfo(host, port, &hints, &res))) { if(host) fatal("error resolving host %s port %s: %s", host, port, gai_strerror(rc)); else fatal("error resolving port %s: %s", port, gai_strerror(rc)); } if((listenfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol)) < 0) fatal("error calling socket: %s", strerror(errno)); if(setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof one) < 0) fatal("error calling setsockopt: %s", strerror(errno)); if(bind(listenfd, res->ai_addr, res->ai_addrlen) < 0) fatal("error calling socket: %s", strerror(errno)); if(listen(listenfd, SOMAXCONN) < 0) fatal("error calling listen: %s", strerror(errno)); } else if(host) fatal("--host makes no sense without --port"); if((cd = iconv_open(local_encoding, "UTF-8")) == (iconv_t)-1) fatal("error calling iconv_open(%s,UTF-8): %s", local_encoding, strerror(errno)); iconv_close(cd); if((cd = iconv_open("UTF-8", local_encoding)) == (iconv_t)-1) fatal("error calling iconv_open(UTF-8, %s): %s", local_encoding, strerror(errno)); iconv_close(cd); if(root) { /* Enter our chroot */ if(chdir(root) < 0) fatal("error calling chdir %s: %s", root, strerror(errno)); if(chroot(".") < 0) fatal("error calling chroot: %s", strerror(errno)); } if(user) { /* Become the right user */ assert(pw != 0); if(setgid(pw->pw_gid) < 0) fatal("error calling setgid: %s", strerror(errno)); if(setuid(pw->pw_uid) < 0) fatal("error calling setuid: %s", strerror(errno)); if(setuid(0) >= 0) fatal("setuid(0) unexpectedly succeeded"); } if(daemonize) { openlog(bn, LOG_PID, LOG_FTP); log_syslog = 1; if(daemon(0, 0) < 0) fatal("error calling daemon: %s", strerror(errno)); } if(!port) { sftp_service(); return 0; } else { for(;;) { union { struct sockaddr_in sin; struct sockaddr_in6 sin6; struct sockaddr sa; } addr; socklen_t addrlen = sizeof addr; int fd; if((fd = accept(listenfd, &addr.sa, &addrlen)) >= 0) { switch(fork()) { case -1: /* If we can't fork then we stop trying for a minute */ fprintf(stderr, "fork: %s\n", strerror(errno)); close(fd); sleep(60); break; case 0: forked(); signal(SIGCHLD, SIG_DFL); /* XXX */ if(dup2(fd, 0) < 0 || dup2(fd, 1) < 0) fatal("dup2: %s", strerror(errno)); if(close(fd) < 0 || close(listenfd) < 0) fatal("close: %s", strerror(errno)); sftp_service(); _exit(0); default: close(fd); break; } } } } #else sftp_service(); return 0; #endif } /** @brief Process SFTP requests * * Requests are always read from FD 0 and responses written to FD 1. */ static void sftp_service(void) { uint32_t len; struct sftpjob *job; struct allocator a; void *const wdv = worker_init(); D(("gesftpserver %s starting up", VERSION)); /* draft -13 s7.6 "The server SHOULD NOT apply a 'umask' to the mode * bits". */ umask(0); while(!do_read(0, &len, sizeof len)) { job = xmalloc(sizeof *job); job->len = ntohl(len); if(!job->len || job->len > MAXREQUEST) fatal("invalid request size"); job->data = xmalloc(job->len); if(do_read(0, job->data, job->len)) /* Job data missing or truncated - the other end is not playing the game * fair so we give up straight away */ fatal("read error: unexpected eof"); if(sftp_debugging) { D(("request:")); sftp_debug_hexdump(job->data, job->len); } /* See serialize.c for the serialization rules we follow */ queue_serializable_job(job); /* We process the job in a background thread, except that the background * threads don't exist until SSH_FXP_INIT has succeeded. */ if(workqueue) queue_add(workqueue, job); else { sftp_alloc_init(&a); process_sftpjob(job, wdv, &a); sftp_alloc_destroy(&a); } /* process_sftpjob() frees JOB when it has finished with it */ } queue_destroy(workqueue); worker_cleanup(wdv); } /* Local Variables: c-basic-offset:2 comment-column:40 fill-column:79 indent-tabs-mode:nil End: */ sftpserver-0.2.1/format-gconv-report0000775000175000017500000000606311626166333014515 00000000000000#! /usr/bin/env python # This file is part of the Green End SFTP Server. # Copyright (C) 2007 Richard Kettlewell # # 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 2 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, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 # USA import re,sys,os,string def fatal(msg): sys.stderr.write("%s\n" % msg) sys.exit(1) def sgmlquotechar(c): if c == '&' or c == '<' or ord(c) < 32 or ord(c) > 126: return "&#%d;" % ord(c) else: return c def sgmlquote(s): return string.join(map(sgmlquotechar, s),'') percent = {} total_lines = 0 covered_lines = 0 args = sys.argv[1:] htmldir = None while len(args) > 0: if args[0] == "--html": htmldir = args[1] args = args[2:] else: fatal("unknown option '%s'" % args[0]) name = None for line in sys.stdin: line = line[:-1] r = re.match("File ['`](?:.*/)?([^/]+.c)'", line) if r: name = r.group(1) r = re.match("Lines executed:([0-9\\.]+)% of ([0-9]+)", line) if r: if name: this_pc = float(r.group(1)) this_lines = int(r.group(2)) percent[name] = this_pc total_lines += this_lines covered_lines += this_lines * this_pc / 100.0 name = None def cmp(a,b): if percent[a] < percent[b]: return -1 elif percent[a] > percent[b]: return 1 else: return 0 keys = percent.keys() keys.sort(cmp) if len(keys): for k in keys: print "%20s: %d%%" % (k, percent[k]) print "Total coverage: %d%%" % (100 * (covered_lines / total_lines)) if htmldir is not None and len(keys): index = open(os.path.join(htmldir, "index.html"), "w") index.write("gcov report\n") index.write("

gcov report

\n") index.write("\n") for k in keys: index.write("
FileCoverage
%s%d%%\n" % (sgmlquote(k), sgmlquote(k), percent[k])) index.write("
\n") index.write("

Total coverage: %d%%

\n" % (100 * (covered_lines / total_lines))) for k in keys: html = open(os.path.join(htmldir, "%s.html" % k), "w") html.write("%s\n" % sgmlquote(k)) html.write("

%s

\n" % sgmlquote(k)) html.write("
")
    r = re.compile("^ *#####:.*")
    for line in open("%s.gcov" % k, "r"):
      if len(line) > 0 and line[-1] == '\n':
        line = line[:-1]
      if r.match(line):
        html.write("%s\n" % sgmlquote(line))
      else:
        html.write("%s\n" % sgmlquote(line))
    html.write("
\n") sftpserver-0.2.1/alloc.c0000664000175000017500000001202612344641303012077 00000000000000/* * This file is part of the Green End SFTP Server. * Copyright (C) 2007, 2011, 2014 Richard Kettlewell * * 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 2 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, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA */ /** @file alloc.c @brief Allocator implementation */ #include "sftpserver.h" #include "alloc.h" #include "utils.h" #include "debug.h" #include #include #include union block; /** @brief One chunk in an allocator * * A chunk is a contiguous region of memory, divided into @ref block objects, * supporting efficient allocation. */ struct chunk { /** @brief Next chunk */ struct chunk *next; /** @brief Pointer to next allocatable block */ union block *ptr; /** @brief Number of blocks left in this chunk */ size_t left; /** @brief Padding * * size_t will usually have the same size as a pointer; by chucking an extra * one in we become 4 * the size of a pointer, which is much more likely to * be a power of 2 than 3 *. */ size_t spare; }; /** @brief Alignment block for an allocator */ union block { int i; long l; float f; double d; void *vp; double *ip; int (*fnp)(void); struct chunk c; }; /** @brief Default number of blocks in a new chunk * * A chunk may be bigger than this if a large allocation was requested. */ #define NBLOCKS 512 struct allocator *sftp_alloc_init(struct allocator *a) { a->chunks = 0; return a; } /** @brief Convert @p nbytes to a block count * @param nbytes Number of bytes * @return Number of blocks necessary to contain @p nbytes */ static inline size_t blocks(size_t nbytes) { return nbytes / sizeof (union block) + !!(nbytes % sizeof (union block)); } void *sftp_alloc(struct allocator *a, size_t n) { /* calculate number of blocks */ const size_t m = blocks(n); struct chunk *c; if(!m) return 0; assert(a != 0); assert(m != SIZE_MAX); /* ...and so m+1 > 0 */ /* See if there's enough room */ if(!(c = a->chunks) || c->left < m) { /* Make sure we allocate enough space */ const size_t cs = m >= NBLOCKS ? m + 1 : NBLOCKS; /* xcalloc -> calloc which 0-fills */ union block *nb; nb = xcalloc(cs, sizeof (union block)); c = &nb->c; c->next = a->chunks; c->ptr = nb + 1; c->left = cs - 1; a->chunks = c; } assert(m <= c->left); /* We always return 0-filled memory. In this case we fill by block, which is * guaranteed to be at least enough (compare below). */ memset(c->ptr, 0, m * sizeof (union block)); c->left -= m; c->ptr += m; return c->ptr - m; } void *sftp_alloc_more(struct allocator *a, void *ptr, size_t oldn, size_t newn) { const size_t oldm = blocks(oldn), newm = blocks(newn); void *newptr; if(ptr) { assert(a->chunks != 0); D(("ptr=%p oldm=%zu a->chunks->ptr=%p blocksize=%zu", ptr, oldm, a->chunks->ptr, sizeof(union block))); if((union block *)ptr + oldm == a->chunks->ptr) { /* ptr is the most recently allocated block. We could do better and * search all the chunks for it. */ if(newm <= oldm) { /* We can always shrink. We capture the no-change case here too. */ a->chunks->ptr -= oldm - newm; a->chunks->left += oldm - newm; return ptr; } else if(a->chunks->left >= newm - oldm) { /* There is space to expand */ a->chunks->ptr += newm - oldm; a->chunks->left -= newm - oldm; /* 0-fill the new space. Note that we do this in byte terms (compare * above), to deal with the case where the allocation shrinks by (say) * a single non-zero byte but then expands again. */ memset((char *)ptr + oldn, 0, newn - oldn); return ptr; } /* If we get here then we are expanding but there is not enough space to * do so in the same chunk */ } else if(newm == oldm) { /* This is not the most recently block but we're not changing its size * anyway */ return ptr; } /* We have no choice but to allocate new space */ newptr = sftp_alloc(a, newn); memcpy(newptr, ptr, oldn); return newptr; } else /* There was no old allocation, just create a new one the easy way */ return sftp_alloc(a, newn); } void sftp_alloc_destroy(struct allocator *a) { struct chunk *c, *d; c = a->chunks; while((d = c)) { c = c->next; free(d); } a->chunks = 0; } /* Local Variables: c-basic-offset:2 comment-column:40 fill-column:79 indent-tabs-mode:nil End: */ sftpserver-0.2.1/testing.txt0000664000175000017500000000524311625765051013072 00000000000000* Built-in Tests 'make check' will use the Python script run-tests to run the built-in tests which all in the tests/ directory. These test the server against a separate though not very independent client implementation. ** Interface To Tests Each of these scripts is an input to the sftpclient program. They are invoked with both the client and the server sitting in the same (initially empty) directory; if your test requires separate directories then use !mkdir and cd/lcd. Any line in the script starting with a "#" is a regular expression. The script is expected to produce output matching the regexp at this point. For example, mkdir3456 starts off as follows: mkdir defperms ls -ld defperms #drwxr-[xs]r-x +[\?\d] +\S+ +\S+ +\d+ +[a-zA-Z]+ +\d+ +\d+:\d+ defperms Here we create a directory with default permissions and then list. The regexp matches the expected ls output. ** Per-Protocol Tests The filename of the scripts is significant. It should contain the protocol version numbers it applies to. For instance mkdir3456 applies to all four known protocol versions. Similarly ls3, ls45 and ls6 provide similar tests against different protocol versions. ls3, ls45 and ls6 are testing stat and attributes in detail so it is worth producing separate scripts for each of them. mkdir3456 however compares more about the mkdir and rmdir operations so there is not much point in having separate versions for each protocol; therefore its regexps will match the output produced in all the different versions. The other reason for having protocol-specific tests is of course to test facilities that only exist in a subset of the protocols. ** Hit-List Things that still particularly want testing: * read-write opens * serialization logic * encoding translation * reverse symlink logic * non-regular files (in lots of ways) * invalid UIDs/GIDs and owner/group names * run tests under valgrind Untested but lower priority: * "anonymous sftp" code * the client (if I decide to promote it to a proper client rather than a test tool) * Interoperability Tests ** Programmable Clients It is possible in principle to do something similar to the above for command line clients such as lftp, psftp and the OpenSSH client, though I have not done so yet. Similarly it should be possible to write mechanical tests for libraries such as Paramiko or even to repurpose their own tests, where they exist. ** Graphical Clients Graphical clients such as WinSCP are less convenient to test this way; instead it is necessary to build up a library of activities which tests as many protocol features as possible in the minimum number of user actions. This hasn't been done yet l-) sftpserver-0.2.1/charset.h0000664000175000017500000000331111626705056012450 00000000000000/* * This file is part of the Green End SFTP Server. * Copyright (C) 2007, 2011 Richard Kettlewell * * 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 2 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, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA */ /** @file charset.h @brief Character conversion interface */ #ifndef CHARSET_H #define CHARSET_H #include #include /** @brief Convert a multibyte string to a wide string * @param s Multibyte string to convert * @return Wide-character equivalent of @p s, or a null pointer on error */ wchar_t *sftp_mbs2wcs(const char *s); /** @brief Generic string converter * @param a Allocator in which to store result * @param cd Conversion descriptor created by @c iconv_open() * @param sp Input/output string * @return 0 on success, -1 on error * * On input, @c *sp points to the string to convert. * * On success, @c *sp is replaced with a pointer to converted string. On error * it is not modified. */ int sftp_iconv(struct allocator *a, iconv_t cd, char **sp); #endif /* CHARSET_H */ /* Local Variables: c-basic-offset:2 comment-column:40 fill-column:79 indent-tabs-mode:nil End: */ sftpserver-0.2.1/realpath.c0000664000175000017500000001110211626705056012607 00000000000000/* * This file is part of the Green End SFTP Server. * Copyright (C) 2007, 2011 Richard Kettlewell * * 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 2 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, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA */ /** @file realpath.c @brief Implementation of sftp_find_realpath() */ #include "sftpcommon.h" #include "utils.h" #include "alloc.h" #include "debug.h" #include #include #include #include #include #include static char *process_path(struct allocator *a, char *result, size_t *nresultp, const char *path, unsigned flags); char *sftp_find_realpath(struct allocator *a, const char *path, unsigned flags) { char *cwd, *abspath, *result = 0; size_t nresult = 0; D(("sftp_find_realpath '%s' %#x", path, flags)); /* Default is current directory */ if(path[0] == 0) path = "."; /* Convert relative paths to absolute paths */ if(path[0] != '/') { if(!(cwd = sftp_getcwd(a))) return 0; assert(cwd[0] == '/'); abspath = sftp_alloc(a, strlen(cwd) + strlen(path) + 2); strcpy(abspath, cwd); strcat(abspath, "/"); strcat(abspath, path); path = abspath; D(("convert relative path to '%s'", path)); } /* The result always starts with a / */ result = append(a, result, &nresult, "/"); /* All the work happens below */ return process_path(a, result, &nresult, path, flags); } /** @brief Canonicalize a path * @param a Allocator for result * @param result Result so far * @param nresultp Size of current result * @param path Path to process * @param flags Flags as for sftp_find_realpath() * @return Modified result */ static char *process_path(struct allocator *a, char *result, size_t *nresultp, const char *path, unsigned flags) { D(("process_path path='%s' result='%s'", path, result)); while(*path) { if(*path == '/') ++path; else { /* Find the next path element */ const size_t elementlen = strcspn(path, "/"); if(elementlen == 1 && path[0] == '.') /* Stay where we are */ ; else if(elementlen == 2 && path[0] == '.' && path[1] == '.') { /* Go up one level */ char *const ls = strrchr(result, '/'); assert(ls != 0); if(ls != result) *ls = 0; else strcpy(result, "/"); /* /.. = / */ D(("result[0] -> '%s'", result)); } else { const size_t oldresultlen = strlen(result); /* Append the new path element */ if(result[1]) result = append(a, result, nresultp, "/"); result = appendn(a, result, nresultp, path, elementlen); D(("result[1] -> '%s'", result)); /* If we're following symlinks, see if the path so far points to a * link */ if(flags & RP_READLINK) { const char *const target = sftp_do_readlink(a, result); if(target) { if(target[0] == '/') /* Absolute symlink, go back to the root */ strcpy(result, "/"); else /* Relative symlink, lose the last path element */ result[oldresultlen] = 0; /* Process all! the elements of the link target */ if(!(result = process_path(a, result, nresultp, target, flags))) return result; } else { switch(errno) { case EINVAL: /* Not a link. Proceed. */ break; default: if((flags & RP_MUST_EXIST)) { /* Nonexistent files are bad. Return an error. */ D(("error reading link: %s", strerror(errno))); return 0; } /* Nonexistent files are OK. Proceed. */ break; } } } D(("result[2] -> '%s'", result)); } path += elementlen; } } D(("returning '%s'", result)); return result; } /* Local Variables: c-basic-offset:2 comment-column:40 fill-column:79 indent-tabs-mode:nil End: */ sftpserver-0.2.1/acinclude.m40000664000175000017500000001764412340114433013040 00000000000000# This file is part of the Green End SFTP Server. # Copyright (C) 2007, 2011 Richard Kettlewell # # 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 2 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, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 # USA AC_DEFUN([RJK_BUILDSYS_FINK],[ AC_CANONICAL_BUILD AC_CANONICAL_HOST AC_PATH_PROG([FINK],[fink],[none],[$PATH:/sw/bin]) if test "x$FINK" != xnone && test "$host" = "$build"; then AC_CACHE_CHECK([fink install directory],[rjk_cv_finkprefix],[ rjk_cv_finkprefix="`echo "$FINK" | sed 's,/bin/fink$,,'`" ]) CPPFLAGS="${CPPFLAGS} -isystem /usr/include -isystem ${rjk_cv_finkprefix}/include" LDFLAGS="${LDFLAGS} -L/usr/lib -L${rjk_cv_finkprefix}/lib" fi ]) AC_DEFUN([RJK_BUILDSYS_MISC],[ AC_CANONICAL_BUILD AC_CANONICAL_HOST AC_CACHE_CHECK([for extra include directories],[rjk_cv_extraincludes],[ rjk_cv_extraincludes=none # If we're cross-compiling then we've no idea where to look for # extra includes if test "$host" = "$build"; then case $host_os in freebsd* ) rjk_cv_extraincludes=/usr/local/include ;; esac fi ]) if test $rjk_cv_extraincludes != none; then if test $GCC = yes; then CPPFLAGS="-isystem $rjk_cv_extraincludes" else CPPFLAGS="-I$rjk_cv_extraincludes" fi fi AC_CACHE_CHECK([for extra library directories],[rjk_cv_extralibs],[ rjk_cv_extralibs=none if test "$host" = "$build"; then case $host_os in freebsd* ) rjk_cv_extralibs=/usr/local/lib ;; esac fi ]) if test $rjk_cv_extralibs != none; then LDFLAGS="-L$rjk_cv_extralibs" fi ]) AC_DEFUN([RJK_GCC_WARNINGS],[ AC_CACHE_CHECK([for ${CC} warning options],[rjk_cv_ccwarnings],[ if test "$GCC" = yes; then rjk_cv_ccwarnings="-Wall -W -Wpointer-arith -Wbad-function-cast \ -Wwrite-strings -Wmissing-prototypes \ -Wmissing-declarations -Wnested-externs" else rjk_cv_ccwarnings="unknown" fi ]) AC_CACHE_CHECK([how to make ${CC} treat warnings as errors], [rjk_cv_ccwerror],[ if test "$GCC" = yes; then rjk_cv_ccwerror="-Werror" else rjk_cv_ccwerror="unknown" fi ]) AC_MSG_CHECKING([whether to enable compiler warnings]) AC_ARG_ENABLE([warnings], [AS_HELP_STRING([--disable-warnings], [Disable compiler warnings])], [warnings="$enableval"], [warnings=yes]) AC_MSG_RESULT([$warnings]) AC_MSG_CHECKING([whether to treat warnings as errors]) AC_ARG_ENABLE([warnings-as-errors], [AS_HELP_STRING([--enable-warnings-as-errors], [Treat compiler warnings as errors])], [warnings_as_errors="$enableval"], [warnings_as_errors=no]) AC_MSG_RESULT([$warnings_as_errors]) if test "$warnings" = yes && test "$rjk_cv_ccwarnings" != unknown; then CC="${CC} $rjk_cv_ccwarnings" fi if test "$warnings_as_errors" = yes && test "$rjk_cv_ccwerror" != unknown; then CC="${CC} $rjk_cv_ccwerror" fi AC_CACHE_CHECK([whether macros produce warnings], [rjk_cv_inttypeswarnings],[ AC_TRY_COMPILE([#include #include #include ], [uint64_t x=0;size_t sz=0;printf("%"PRIu64" %zu\n", x, sz);], [rjk_cv_inttypeswarnings=no], [rjk_cv_inttypeswarnings=yes]) ]) if test $rjk_cv_inttypeswarnings = yes && test "$GCC" = yes; then CC="${CC} -Wno-format" fi ]) AC_DEFUN([RJK_GTKFLAGS],[ AM_PATH_GLIB_2_0([],[],[missing_libraries="$missing_libraries libglib"]) AM_PATH_GTK_2_0([],[],[missing_libraries="$missing_libraries libgtk"]) if test "$GCC" = yes; then GTK_CFLAGS="`echo \"$GTK_CFLAGS\"|sed 's/-I/-isystem /g'`" GLIB_CFLAGS="`echo \"$GLIB_CFLAGS\"|sed 's/-I/-isystem /g'`" fi ]) AC_DEFUN([RJK_STAT_TIMESPEC],[ AC_CHECK_MEMBER([struct stat.st_atimespec], [AC_DEFINE([HAVE_STAT_TIMESPEC],[1], [define if struct stat uses struct timespec])], [rjk_cv_stat_timespec=no], [#include ]) ]) ]) AC_DEFUN([RJK_GCC_ATTRS],[ AH_BOTTOM([#ifdef __GNUC__ # define attribute(x) __attribute__(x) #else # define attribute(x) #endif]) ]) ]) AC_DEFUN([RJK_ICONV],[ # MacOS has a rather odd iconv (presumably for some good reason) AC_CHECK_LIB([iconv],[iconv_open]) AC_CHECK_LIB([iconv],[libiconv_open]) ]) AC_DEFUN([RJK_GCOV],[ GCOV=${GCOV:-true} AC_ARG_WITH([gcov], [AS_HELP_STRING([--with-gcov], [Enable coverage testing])], [if test $withval = yes; then CFLAGS="${CFLAGS} -O0 -fprofile-arcs -ftest-coverage" GCOV=`echo $CC | sed s'/gcc/gcov/;s/ .*$//'`; fi]) AC_SUBST([GCOV],[$GCOV]) ]) AC_DEFUN([RJK_THREADS],[ AC_CANONICAL_BUILD AC_CANONICAL_HOST # If you're cross-compiling then you're on your own AC_MSG_CHECKING([how to build threaded code]) if test "$host" = "$build"; then case $host_os in solaris2* ) case "$GCC" in yes ) AC_MSG_RESULT([-lpthread]) AC_CHECK_LIB([pthread],[pthread_create]) ;; * ) AC_MSG_RESULT([-mt option]) CC="${CC} -mt" ;; esac ;; linux* | freebsd* | darwin* ) AC_MSG_RESULT([-lpthread]) AC_CHECK_LIB([pthread],[pthread_create]) ;; * ) AC_MSG_RESULT([unknown]) AC_MSG_ERROR([don't know how to build threaded code on this system]) ;; esac fi # We always ask for this. AC_DEFINE([_REENTRANT],[1],[define for re-entrant functions]) ]) AC_DEFUN([RJK_SIZE_MAX],[ AC_CHECK_SIZEOF([unsigned short]) AC_CHECK_SIZEOF([unsigned int]) AC_CHECK_SIZEOF([unsigned long]) AC_CHECK_SIZEOF([unsigned long long]) AC_CHECK_SIZEOF([size_t]) AC_CHECK_HEADERS([stdint.h]) AC_CACHE_CHECK([for SIZE_MAX],[rjk_cv_size_max],[ AC_TRY_COMPILE([#include #include #if HAVE_STDINT_H # include #endif], [size_t x = SIZE_MAX;++x;], [rjk_cv_size_max=yes], [rjk_cv_size_max=no]) ]) if test "$rjk_cv_size_max" = yes; then AC_DEFINE([HAVE_SIZE_MAX],[1], [define if you have SIZE_MAX]) fi AH_BOTTOM([#if ! HAVE_SIZE_MAX # if SIZEOF_SIZE_T == SIZEOF_UNSIGNED_SHORT # define SIZE_MAX USHRT_MAX # elif SIZEOF_SIZE_T == SIZEOF_UNSIGNED_INT # define SIZE_MAX UINT_MAX # elif SIZEOF_SIZE_T == SIZEOF_UNSIGNED_LONG # define SIZE_MAX ULONG_MAX # elif SIZEOF_SIZE_T == SIZEOF_UNSIGNED_LONG_LONG # define SIZE_MAX ULLONG_MAX # else # error Cannot deduce SIZE_MAX # endif #endif ]) ]) AC_DEFUN([RJK_GETOPT],[ AC_CHECK_FUNC([getopt_long],[],[ AC_LIBOBJ([getopt]) AC_LIBOBJ([getopt1]) ]) ]) AC_DEFUN([RJK_PYTHON24],[ AC_CACHE_CHECK([for Python 2.4 or better],[rjk_cv_python24],[ if python24 -V >/dev/null 2>&1; then rjk_cv_python24=python24 elif python2.4 -V >/dev/null 2>&1; then rjk_cv_python24=python2.4 elif python -V >confpyver 2>&1; then read p v < confpyver case "$v" in 1* | 2.0* | 2.1* | 2.2* | 2.3* ) ;; * ) rjk_cv_python24=python ;; esac fi rm -f confpyver if test "$rjk_cv_python24" = ""; then AC_MSG_ERROR([cannot find Python 2.4 or better]) fi ]) AC_SUBST([PYTHON24],[$rjk_cv_python24]) ]) dnl Local Variables: dnl mode:autoconf dnl indent-tabs-mode:nil dnl End: sftpserver-0.2.1/parse.c0000664000175000017500000000564112340114433012117 00000000000000/* * This file is part of the Green End SFTP Server. * Copyright (C) 2007, 2011, 2014 Richard Kettlewell * * 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 2 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, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA */ #include "sftpserver.h" #include "alloc.h" #include "debug.h" #include "handle.h" #include "parse.h" #include "types.h" #include "sftp.h" #include "globals.h" #include "putword.h" #include uint32_t sftp_parse_uint8(struct sftpjob *job, uint8_t *ur) { if(job->left < 1) return SSH_FX_BAD_MESSAGE; *ur = *job->ptr++; --job->left; return SSH_FX_OK; } uint32_t sftp_parse_uint16(struct sftpjob *job, uint16_t *ur) { if(job->left < 2) return SSH_FX_BAD_MESSAGE; *ur = get16(job->ptr); job->ptr += 2; job->left -= 2; return SSH_FX_OK; } uint32_t sftp_parse_uint32(struct sftpjob *job, uint32_t *ur) { if(job->left < 4) return SSH_FX_BAD_MESSAGE; *ur = get32(job->ptr); job->ptr += 4; job->left -= 4; return SSH_FX_OK; } uint32_t sftp_parse_uint64(struct sftpjob *job, uint64_t *ur) { if(job->left < 8) return SSH_FX_BAD_MESSAGE; *ur = get64(job->ptr); job->ptr += 8; job->left -= 8; return SSH_FX_OK; } uint32_t sftp_parse_string(struct sftpjob *job, char **strp, size_t *lenp) { uint32_t len, rc; char *str; if((rc = sftp_parse_uint32(job, &len)) != SSH_FX_OK) return rc; if(len == 0xFFFFFFFF) return SSH_FX_BAD_MESSAGE; /* overflow */ if(job->left < len) return SSH_FX_BAD_MESSAGE; /* not enough bytes to satisfy */ if(lenp) *lenp = len; if(strp) { str = sftp_alloc(job->a, len + 1); /* 0-fills */ memcpy(str, job->ptr, len); *strp = str; } job->ptr += len; job->left -= len; return SSH_FX_OK; } uint32_t sftp_parse_path(struct sftpjob *job, char **strp) { uint32_t rc; if((rc = sftp_parse_string(job, strp, 0)) != SSH_FX_OK) return rc; return protocol->decode(job, strp); } uint32_t sftp_parse_handle(struct sftpjob *job, struct handleid *id) { uint32_t len, rc; if((rc = sftp_parse_uint32(job, &len)) != SSH_FX_OK || len != 8 || (rc = sftp_parse_uint32(job, &id->id)) != SSH_FX_OK || (rc = sftp_parse_uint32(job, &id->tag) != SSH_FX_OK)) return rc; return SSH_FX_OK; } /* LOCAL Variables: c-basic-offset:2 comment-column:40 fill-column:79 indent-tabs-mode:nil End: */ sftpserver-0.2.1/futimes.c0000664000175000017500000000215111625765051012467 00000000000000/* * This file is part of the Green End SFTP Server. * Copyright (C) 2007 Richard Kettlewell * * 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 2 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, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA */ #include #include #include int futimes(int fd, const struct timeval *times) { #if HAVE_FUTIMESAT return futimesat(fd, 0, times); #else errno = ENOSYS; return -1; #endif } /* Local Variables: c-basic-offset:2 comment-column:40 fill-column:79 indent-tabs-mode:nil End: */ sftpserver-0.2.1/thread.h0000664000175000017500000000310611626705056012270 00000000000000/* * This file is part of the Green End SFTP Server. * Copyright (C) 2007, 2011 Richard Kettlewell * * 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 2 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, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA */ /** @file thread.h @brief Thread utilities */ #ifndef THREAD_H #define THREAD_H #include #include /** @brief Error-checking macro for @c pthread_... functions */ #define ferrcheck(E) do { \ const int frc = (E); \ if(frc) { \ fatal("%s:%d: %s: %s\n", __FILE__, __LINE__, \ #E, strerror(frc)); \ exit(1); \ } \ } while(0) #endif /* THREAD_H */ /* Local Variables: c-basic-offset:2 comment-column:40 fill-column:79 indent-tabs-mode:nil End: */ sftpserver-0.2.1/charset.c0000664000175000017500000000404111625765051012444 00000000000000/* * This file is part of the Green End SFTP Server. * Copyright (C) 2007 Richard Kettlewell * * 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 2 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, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA */ #include "sftpcommon.h" #include "utils.h" #include "charset.h" #include "alloc.h" #include "debug.h" #include #include #include #include wchar_t *sftp_mbs2wcs(const char *s) { wchar_t *ws; size_t len; mbstate_t ps; memset(&ps, 0, sizeof ps); len = mbsrtowcs(0, &s, 0, &ps); if(len == (size_t)-1) return 0; ws = xcalloc(len + 1, sizeof *ws); memset(&ps, 0, sizeof ps); mbsrtowcs(ws, &s, len, &ps); return ws; } int sftp_iconv(struct allocator *a, iconv_t cd, char **sp) { const char *const input = *sp; const size_t inputsize = strlen(input); size_t outputsize = 2 * strlen(input) + 1; size_t rc; const char *inbuf; char *outbuf, *output; size_t inbytesleft, outbytesleft; assert(cd != 0); do { output = sftp_alloc(a, outputsize); iconv(cd, 0, 0, 0, 0); inbuf = input; inbytesleft = inputsize; outbuf = output; outbytesleft = outputsize; rc = iconv(cd, (void *)&inbuf, &inbytesleft, &outbuf, &outbytesleft); outputsize *= 2; } while(rc == (size_t)-1 && errno == E2BIG); if(rc == (size_t)-1) return -1; *sp = output; return 0; } /* Local Variables: c-basic-offset:2 comment-column:40 fill-column:79 indent-tabs-mode:nil End: */ sftpserver-0.2.1/tests/0000775000175000017500000000000011626166333012071 500000000000000sftpserver-0.2.1/tests/badpacket4560000664000175000017500000000005611625765051014113 00000000000000_bad_packet456 #.*badly encoded SFTP packet.* sftpserver-0.2.1/tests/version50000664000175000017500000000015511625765051013510 00000000000000version #Protocol version: +5 #Server vendor: +.+ #Server name: +.+ #Server version: +.+ #Server build: +\d+ sftpserver-0.2.1/tests/mkdir34560000664000175000017500000000072411625765051013370 00000000000000mkdir defperms ls -ld defperms #drwxr-[xs]r-x +[\?\d] +\S+ +\S+ +\d+ +[a-zA-Z]+ +\d+ +\d+:\d+ defperms mkdir defperms #.*File exists.* mkdir 2700 fixedperms mkdir 2700 fixedperms #.*File exists.* mkdir 700 fixedsimpleperms ls -ld fixedperms #drwx--S--- +[\?\d] +\S+ +\S+ +\d+ +[a-zA-Z]+ +\d+ +\d+:\d+ fixedperms rmdir defperms ls -ld defperms #.*file does not exist.* rmdir fixedperms ls -ld fixedperms #.*file does not exist.* rmdir defprems #.*file does not exist.* sftpserver-0.2.1/tests/chmod450000664000175000017500000000036311625765051013202 00000000000000!touch input chmod 600 input ls -l input #-rw------- +\? +\S+ +\S+ +0 +[a-zA-Z]+ +\d+ +\d+:\d\d input put -P input output ls -l output #-rw------- +\? +\S+ +\S+ +0 +[a-zA-Z]+ +\d+ +\d+:\d\d output chmod 600 nosuchfile #.*file does not exist.* sftpserver-0.2.1/tests/vsel6bad0000664000175000017500000000003711625765051013443 00000000000000version 7 #.*unknown version.* sftpserver-0.2.1/tests/link3450000664000175000017500000000007011625765051013123 00000000000000link foo bar #.*hard links not supported in protocol \d sftpserver-0.2.1/tests/rmdir60000664000175000017500000000024411625765051013140 00000000000000!mkdir nonempty !touch nonempty/foo rmdir nonempty/foo #.*file is not a directory.* rm nonempty #.*file is a directory.* rmdir nonempty #.*directory is not empty.* sftpserver-0.2.1/tests/vsel6six0000664000175000017500000000022211625765051013514 00000000000000version 6 version #Protocol version: +6 #Server vendor: +.+ #Server name: +.+ #Server version: +.+ #Server build: +\d+ #Server supports: +3,4,5,6 sftpserver-0.2.1/tests/truncate34560000664000175000017500000000027311625765051014106 00000000000000!if type seq >/dev/null 2>/dev/null; then seq 999; else jot 999; fi > f999 !if type seq >/dev/null 2>/dev/null; then seq 100; else jot 100; fi > f100 truncate 292 f999 !diff -u f100 f999 sftpserver-0.2.1/tests/textseek4560000664000175000017500000000055011625765051014030 00000000000000!if type seq >/dev/null 2>&1; then seq 999; else jot 999; fi > input text get -L0 input output !wc -l < output # *999 !diff -u input output get -L1 input output !wc -l < output # *998 get -L10 input output !wc -l < output # *989 get -L100 input output !wc -l < output # *899 get -L1000 input output #.*end of file.* get -L999 input output !wc -l < output # *0 sftpserver-0.2.1/tests/remove34560000664000175000017500000000016511625765051013556 00000000000000put /dev/null file ls -1 file #file rm file ls -1 file #.*file does not exist.* rm nonesuch #.*file does not exist.* sftpserver-0.2.1/tests/textupload4560000664000175000017500000000027111625765051014365 00000000000000text !while echo 'spong\n'; do :; done | dd of=original bs=10 count=10 2>/dev/null put original uploaded !diff -u original uploaded get uploaded downloaded !diff -u original downloaded sftpserver-0.2.1/tests/realpath60000664000175000017500000000433011625765051013623 00000000000000!mkdir dir !mkdir dir/subdir !mkdir dir/subdir/contents !ln -s nowhere dir/dangling !ln -s subdir dir/followable !ln -s / root !ln -s /./.././.././.. root-wonky realpath6 no-check "" #/.*/,testroot/realpath6\.6 realpath6 no-check dir #/.*/dir realpath6 no-check dir/subdir #/.*/subdir realpath6 no-check dir/subdir/contents #/.*/subdir/contents realpath6 no-check dir/dangling #/.*/dir/dangling realpath6 no-check dir/dangling/.. #/.*/dir realpath6 no-check dir/dangling/contents #/.*/dir/dangling/contents realpath6 no-check dir/followable #/.*/followable realpath6 no-check dir/followable/contents #/.*/followable/contents realpath6 stat-if dir #drwxr.[sx]r.x +\d+ +\S+ +\S+ +\d+ +\S+ +\d+ +\d+:\d+ .*/dir realpath6 stat-if dir/subdir #drwxr.[sx]r.x +\d+ +\S+ +\S+ +\d+ +\S+ +\d+ +\d+:\d+ .*/subdir realpath6 stat-if dir/subdir/contents #drwxr.[sx]r.x +\d+ +\S+ +\S+ +\d+ +\S+ +\d+ +\d+:\d+ .*/subdir/contents realpath6 stat-if dir/dangling #/.*/dir/nowhere realpath6 stat-if dir/dangling/.. #drwxr.[sx]r.x +\d+ +\S+ +\S+ +\d+ +\S+ +\d+ +\d+:\d+ .*/dir realpath6 stat-if dir/dangling/contents #/.*/dir/nowhere/contents realpath6 stat-if dir/followable #drwxr.[sx]r.x +\d+ +\S+ +\S+ +\d+ +\S+ +\d+ +\d+:\d+ .*/subdir realpath6 stat-if dir/followable/contents #drwxr.[sx]r.x +\d+ +\S+ +\S+ +\d+ +\S+ +\d+ +\d+:\d+ .*/subdir/contents realpath6 stat-always dir #drwxr.[sx]r.x +\d+ +\S+ +\S+ +\d+ +\S+ +\d+ +\d+:\d+ .*/dir realpath6 stat-always dir/subdir #drwxr.[sx]r.x +\d+ +\S+ +\S+ +\d+ +\S+ +\d+ +\d+:\d+ .*/subdir realpath6 stat-always dir/subdir/contents #drwxr.[sx]r.x +\d+ +\S+ +\S+ +\d+ +\S+ +\d+ +\d+:\d+ .*/subdir/contents realpath6 stat-always dir/dangling #.*file does not exist.* realpath6 stat-always dir/dangling/.. #.*file does not exist.* realpath6 stat-always dir/dangling/contents #.*file does not exist.* realpath6 stat-always dir/followable #drwxr.[sx]r.x +\d+ +\S+ +\S+ +\d+ +\S+ +\d+ +\d+:\d+ .*/subdir realpath6 stat-always dir/followable/contents #drwxr.[sx]r.x +\d+ +\S+ +\S+ +\d+ +\S+ +\d+ +\d+:\d+ .*/subdir/contents realpath6 no-check / #/ realpath6 no-check /.. #/ realpath6 stat-if root #d......... +\d+ +\S+ +\S+ +\d+ +\S+ +\d+ +(\d+:\d+|\d+) / realpath6 stat-if root-wonky #d......... +\d+ +\S+ +\S+ +\d+ +\S+ +\d+ +(\d+:\d+|\d+) / sftpserver-0.2.1/tests/split34560000664000175000017500000000012111625765051013404 00000000000000!mkdir 'My Downloads' ls -1 #My Downloads cd "My Downloads" pwd #.*/My Downloads sftpserver-0.2.1/tests/readlink30000664000175000017500000000056211625765051013614 00000000000000!ln -s a b ls -l b #lrwxr.xr.x +\? +\d+ +\d+ +\d+ +[a-zA-Z]+ +\d+ +\d+:\d\d b -> a readlink b #a !mkdir noreadperm !ln -s ../a noreadperm/b !chmod 000 noreadperm readlink noreadperm/b #.*permission denied.* !ln -s afairlylonglinkbutwerestillgoingtohavetomakethebufferartificiallysmall t readlink t #afairlylonglinkbutwerestillgoingtohavetomakethebufferartificiallysmall sftpserver-0.2.1/tests/chmod30000664000175000017500000000036311625765051013114 00000000000000!touch input chmod 600 input ls -l input #-rw------- +\? +\d+ +\d+ +0 +[a-zA-Z]+ +\d+ +\d+:\d\d input put -P input output ls -l output #-rw------- +\? +\d+ +\d+ +0 +[a-zA-Z]+ +\d+ +\d+:\d\d output chmod 600 nosuchfile #.*file does not exist.* sftpserver-0.2.1/tests/isdir60000664000175000017500000000013411625765051013133 00000000000000!mkdir dir !touch foo get dir #.*file is a directory.* put foo dir #.*file is a directory.* sftpserver-0.2.1/tests/realpath34560000664000175000017500000000027411625765051014062 00000000000000realpath does/not/exist #.*/does/not/exist mkdir spong mkdir spong/wibble realpath spong/wibble/.. #.*/spong realpath spong/./wibble/ #.*/spong/wibble realpath spong/../wibble/ #.*/wibble sftpserver-0.2.1/tests/readlink60000664000175000017500000000056311625765051013620 00000000000000!ln -s a b ls -l b #lrwxr.xr.x +\d+ +\S+ +\S+ +\d+ +[a-zA-Z]+ +\d+ +\d+:\d\d b -> a readlink b #a !mkdir noreadperm !ln -s ../a noreadperm/b !chmod 000 noreadperm readlink noreadperm/b #.*permission denied.* !ln -s afairlylonglinkbutwerestillgoingtohavetomakethebufferartificiallysmall t readlink t #afairlylonglinkbutwerestillgoingtohavetomakethebufferartificiallysmall sftpserver-0.2.1/tests/rename560000664000175000017500000000107611625765051013363 00000000000000put /dev/null file ls -1 file #file mv file newname ls -1 file #.*file does not exist.* ls -1 newname #newname put /dev/null otherfile mv newname otherfile #.*file already exists* mv -o newname otherfile ls -1 newname #.*file does not exist.* ls -1 otherfile #otherfile !mkdir dir mv dir anotherdir !mkdir dir2 mv dir2 anotherdir #.*file already exists.* !mkdir nowritedir !touch nowritedir/file !chmod 555 nowritedir mv dir2 nowritedir/spong #.*permission denied.* mv -o dir2 nowritedir/spong #.*permission denied.* mv nowritedir/file cant_rm_source #.*permission denied.* sftpserver-0.2.1/tests/chmod60000664000175000017500000000036111625765051013115 00000000000000!touch input chmod 600 input ls -l input #-rw------- +1 +\S+ +\S+ +0 +[a-zA-Z]+ +\d+ +\d+:\d\d input put -P input output ls -l output #-rw------- +1 +\S+ +\S+ +0 +[a-zA-Z]+ +\d+ +\d+:\d\d output chmod 600 nosuchfile #.*file does not exist.* sftpserver-0.2.1/tests/vsel6four0000664000175000017500000000022211625765051013664 00000000000000version 4 version #Protocol version: +4 #Server vendor: +.+ #Server name: +.+ #Server version: +.+ #Server build: +\d+ #Server supports: +3,4,5,6 sftpserver-0.2.1/tests/readlink450000664000175000017500000000056211625765051013702 00000000000000!ln -s a b ls -l b #lrwxr.xr.x +\? +\S+ +\S+ +\d+ +[a-zA-Z]+ +\d+ +\d+:\d\d b -> a readlink b #a !mkdir noreadperm !ln -s ../a noreadperm/b !chmod 000 noreadperm readlink noreadperm/b #.*permission denied.* !ln -s afairlylonglinkbutwerestillgoingtohavetomakethebufferartificiallysmall t readlink t #afairlylonglinkbutwerestillgoingtohavetomakethebufferartificiallysmall sftpserver-0.2.1/tests/rename40000664000175000017500000000075611625765051013300 00000000000000put /dev/null file ls -1 file #file mv file newname ls -1 file #.*file does not exist.* ls -1 newname #newname put /dev/null otherfile mv newname otherfile #.*file already exists.* !mkdir dir mv dir anotherdir !mkdir dir2 mv dir2 anotherdir #.*file already exists.* !mkdir nowritedir !touch nowritedir/file !chmod 555 nowritedir mv dir2 nowritedir/spong #.*permission denied.* mv nowritedir/file cant_rm_source #.*permission denied.* mv -o a b #.*cannot emulate rename flags \S+ in protocol \d sftpserver-0.2.1/tests/version670000664000175000017500000000021011625765051013570 00000000000000version #Protocol version: +6 #Server vendor: +.+ #Server name: +.+ #Server version: +.+ #Server build: +\d+ #Server supports: +3,4,5,6 sftpserver-0.2.1/tests/version40000664000175000017500000000015511625765051013507 00000000000000version #Protocol version: +4 #Server vendor: +.+ #Server name: +.+ #Server version: +.+ #Server build: +\d+ sftpserver-0.2.1/tests/rmdir3450000664000175000017500000000022411625765051013304 00000000000000!mkdir nonempty !touch nonempty/foo rmdir nonempty/foo #.*operation failed.* rm nonempty #.*operation failed.* rmdir nonempty #.*operation failed.* sftpserver-0.2.1/tests/vsel6mistimed0000664000175000017500000000005711625765051014532 00000000000000cd / version 7 #.*badly timed version-select.* sftpserver-0.2.1/tests/open34560000664000175000017500000000040411625765051013216 00000000000000!echo 1 > one !echo 2 > two put -t one two #.*file already exists.* put -t one three !diff -u one three put -A one two !wc -l < two # *2 put -a one two !wc -l < two # *3 put -A one nonesuch #.*file does not exist.* put -e one nonesuch #.*file does not exist.* sftpserver-0.2.1/tests/isdir3450000664000175000017500000000012611625765051013302 00000000000000!mkdir dir !touch foo get dir #.*operation failed.* put foo dir #.*operation failed.* sftpserver-0.2.1/tests/badpath60000664000175000017500000000004011625765051013420 00000000000000_bad_path #.*invalid filename.* sftpserver-0.2.1/tests/df34560000664000175000017500000000032711625765051012652 00000000000000df #Bytes on device: +\d+ [GMK]?bytes #Unused bytes on device: +\d+ [GMK]?bytes #Unused available bytes on device: \d+ [GMK]?bytes #Bytes per allocation unit: +\d+ [GMK]?bytes df nosuchpath #.*file does not exist.* sftpserver-0.2.1/tests/ls50000664000175000017500000000176611625765051012452 00000000000000!touch empty !echo spong > small !dd if=/dev/zero of=large bs=1024 count=1024 2>/dev/null !ln -s a b !ln small wibble ls -la #drwxr.[xs]r.x +\? +\S+ +\S+ +\S+ +[a-zA-Z]+ +\d+ +\d+:\d+ \. \[hide\] #drwxr.[xs]r.x +\? +\S+ +\S+ +\S+ +[a-zA-Z]+ +\d+ +\d+:\d+ \.\. \[hide\] #lrwxr.[xs]r.x +\? +\S+ +\S+ +\S+ +[a-zA-Z]+ +\d+ +\d+:\d+ b -> a #-rw-r--r-- +\? +\S+ +\S+ +0 +[a-zA-Z]+ +\d+ +\d+:\d+ empty #-rw-r--r-- +\? +\S+ +\S+ +1048576 +[a-zA-Z]+ +\d+ +\d+:\d+ large #-rw-r--r-- +\? +\S+ +\S+ +6 +[a-zA-Z]+ +\d+ +\d+:\d+ small #-rw-r--r-- +\? +\S+ +\S+ +6 +[a-zA-Z]+ +\d+ +\d+:\d+ wibble !mkdir noreadperm !chmod 000 noreadperm ls noreadperm #.*permission denied.* lstat b #lrwxr.[xs]r.x +\? +\S+ +\S+ +\S+ +[a-zA-Z]+ +\d+ +\d+:\d+ b stat b #.*file does not exist stat large #-rw-r--r-- +\? +\S+ +\S+ +1048576 +[a-zA-Z]+ +\d+ +\d+:\d+ large !mkdir dir chmod 7755 dir stat dir #drwsr-sr-t +\? +\S+ +\S+ +\d+ +[a-zA-Z]+ +\d+ +\d+:\d+ dir chmod 7000 dir stat dir #d--S--S--T +\? +\S+ +\S+ +\d+ +[a-zA-Z]+ +\d+ +\d+:\d+ dir sftpserver-0.2.1/tests/version30000664000175000017500000000015511625765051013506 00000000000000version #Protocol version: +3 #Server vendor: +.+ #Server name: +.+ #Server version: +.+ #Server build: +\d+ sftpserver-0.2.1/tests/text4560000664000175000017500000000050611625765051013161 00000000000000!echo spong > 1 !ls -l > 2 !echo wibble > 3 !printf nofinalnewline >> 3 !if type > /dev/null seq 2>/dev/null; then seq 999; else jot 999; fi > 4 text get 1 1dl !diff 1 1dl get 2 2dl !diff 2 2dl get 3 3dl !diff 3 3dl get 4 4dl !diff 4 4dl put 1 1ul !diff 1 1ul put 2 2ul !diff 2 2ul put 3 3ul !diff 3 3ul put 4 4ul !diff 4 4ul sftpserver-0.2.1/tests/upload34560000664000175000017500000000074611625765051013552 00000000000000!while echo 'spong\n'; do :; done | dd of=original bs=1024 count=1024 2>/dev/null put original uploaded !diff -u original uploaded get uploaded downloaded !diff -u original downloaded put -m601 original upload2 ls -l upload2 #-rw------x +\S+ +\S+ +\S+ +\d+ +[a-zA-Z]+ +\d+ +\d+:\d+ upload2 !if type seq >/dev/null 2>/dev/null; then seq 999999; else jot 999999; fi > original put original uploaded !diff -u original uploaded get uploaded downloaded !diff -u original downloaded _overlap sftpserver-0.2.1/tests/reinit34560000664000175000017500000000003411625765051013546 00000000000000_init #.*operation failed.* sftpserver-0.2.1/tests/vsel6three0000664000175000017500000000022211625765051014020 00000000000000version 3 version #Protocol version: +3 #Server vendor: +.+ #Server name: +.+ #Server version: +.+ #Server build: +\d+ #Server supports: +3,4,5,6 sftpserver-0.2.1/tests/ls40000664000175000017500000000174411625765051012445 00000000000000!touch empty !echo spong > small !dd if=/dev/zero of=large bs=1024 count=1024 2>/dev/null !ln -s a b !ln small wibble ls -la #drwxr.[xs]r.x +\? +\S+ +\S+ +\S+ +[a-zA-Z]+ +\d+ +\d+:\d+ \. #drwxr.[xs]r.x +\? +\S+ +\S+ +\S+ +[a-zA-Z]+ +\d+ +\d+:\d+ \.\. #lrwxr.[xs]r.x +\? +\S+ +\S+ +\S+ +[a-zA-Z]+ +\d+ +\d+:\d+ b -> a #-rw-r--r-- +\? +\S+ +\S+ +0 +[a-zA-Z]+ +\d+ +\d+:\d+ empty #-rw-r--r-- +\? +\S+ +\S+ +1048576 +[a-zA-Z]+ +\d+ +\d+:\d+ large #-rw-r--r-- +\? +\S+ +\S+ +6 +[a-zA-Z]+ +\d+ +\d+:\d+ small #-rw-r--r-- +\? +\S+ +\S+ +6 +[a-zA-Z]+ +\d+ +\d+:\d+ wibble !mkdir noreadperm !chmod 000 noreadperm ls noreadperm #.*permission denied.* lstat b #lrwxr.[xs]r.x +\? +\S+ +\S+ +\S+ +[a-zA-Z]+ +\d+ +\d+:\d+ b stat b #.*file does not exist stat large #-rw-r--r-- +\? +\S+ +\S+ +1048576 +[a-zA-Z]+ +\d+ +\d+:\d+ large !mkdir dir chmod 7755 dir stat dir #drwsr-sr-t +\? +\S+ +\S+ +\d+ +[a-zA-Z]+ +\d+ +\d+:\d+ dir chmod 7000 dir stat dir #d--S--S--T +\? +\S+ +\S+ +\d+ +[a-zA-Z]+ +\d+ +\d+:\d+ dir sftpserver-0.2.1/tests/nosuchpath30000664000175000017500000000007111625765051014172 00000000000000!touch foo put -A foo bar/spong #.*file does not exist.* sftpserver-0.2.1/tests/local34560000664000175000017500000000037711625765051013360 00000000000000!mkdir dir !mkdir dir/subdir lcd dir/subdir lpwd #/.*/dir/subdir lcd .. lpwd #/.*/dir lls #subdir !touch \\ lls -1 "\\" #\\ anything " #.*unterminated string nosuchcommand #.*unknown command:.* cd stupid stupid stupid #.*wrong number of arguments.* quit sftpserver-0.2.1/tests/version20000664000175000017500000000003511626166333013501 00000000000000#.*operation not supported.* sftpserver-0.2.1/tests/filetype34560000664000175000017500000000023011625765051014073 00000000000000!mkfifo -m 644 fifo stat fifo #prw-r--r-- +\S+ +\S+ +\S+ +\d+ +\S+ +[\d :]+ fifo stat /dev/null #crw-rw-rw- +\S+ +\S+ +\S+ +\d+ +\S+ +[\d :]+ /dev/null sftpserver-0.2.1/tests/ls30000664000175000017500000000264211625765051012442 00000000000000!touch empty !echo spong > small !dd if=/dev/zero of=large bs=1024 count=1024 2>/dev/null !ln -s a b !ln small wibble ls -la #drwxr.[xs]r.x +\? +\d+ +\d+ +\S+ +[a-zA-Z]+ +\d+ +\d+:\d+ \. #drwxr.[xs]r.x +\? +\d+ +\d+ +\S+ +[a-zA-Z]+ +\d+ +\d+:\d+ \.\. #lrwxr.[xs]r.x +\? +\d+ +\d+ +\S+ +[a-zA-Z]+ +\d+ +\d+:\d+ b -> a #-rw-r--r-- +\? +\d+ +\d+ +0 +[a-zA-Z]+ +\d+ +\d+:\d+ empty #-rw-r--r-- +\? +\d+ +\d+ +1048576 +[a-zA-Z]+ +\d+ +\d+:\d+ large #-rw-r--r-- +\? +\d+ +\d+ +6 +[a-zA-Z]+ +\d+ +\d+:\d+ small #-rw-r--r-- +\? +\d+ +\d+ +6 +[a-zA-Z]+ +\d+ +\d+:\d+ wibble ls -na #drwxr.[xs]r.x +\? +\d+ +\d+ +\S+ +[a-zA-Z]+ +\d+ +\d+:\d+ \. #drwxr.[xs]r.x +\? +\d+ +\d+ +\S+ +[a-zA-Z]+ +\d+ +\d+:\d+ \.\. #lrwxr.[xs]r.x +\? +\d+ +\d+ +\S+ +[a-zA-Z]+ +\d+ +\d+:\d+ b -> a #-rw-r--r-- +\? +\d+ +\d+ +0 +[a-zA-Z]+ +\d+ +\d+:\d+ empty #-rw-r--r-- +\? +\d+ +\d+ +1048576 +[a-zA-Z]+ +\d+ +\d+:\d+ large #-rw-r--r-- +\? +\d+ +\d+ +6 +[a-zA-Z]+ +\d+ +\d+:\d+ small #-rw-r--r-- +\? +\d+ +\d+ +6 +[a-zA-Z]+ +\d+ +\d+:\d+ wibble !mkdir noreadperm !chmod 000 noreadperm ls noreadperm #.*permission denied.* lstat b #lrwxr.[xs]r.x +\? +\d+ +\d+ +\S+ +[a-zA-Z]+ +\d+ +\d+:\d+ b stat b #.*file does not exist stat large #-rw-r--r-- +\? +\d+ +\d+ +1048576 +[a-zA-Z]+ +\d+ +\d+:\d+ large !mkdir dir chmod 7755 dir stat dir #drwsr-sr-t +\? +\d+ +\d+ +\d+ +[a-zA-Z]+ +\d+ +\d+:\d+ dir chmod 7000 dir stat dir #d--S--S--T +\? +\d+ +\d+ +\d+ +[a-zA-Z]+ +\d+ +\d+:\d+ dir sftpserver-0.2.1/tests/badpacket34560000664000175000017500000000044311625765051014176 00000000000000_bad_packet #.*badly encoded SFTP packet.* #.*badly encoded SFTP packet.* #.*badly encoded SFTP packet.* #.*badly encoded SFTP packet.* #.*badly encoded SFTP packet.* #.*badly encoded SFTP packet.* #.*badly encoded SFTP packet.* #.*badly encoded SFTP packet.* #.*badly encoded SFTP packet.* sftpserver-0.2.1/tests/textupload30000664000175000017500000000006611625765051014213 00000000000000text #.*text mode not supported in protocol version 3 sftpserver-0.2.1/tests/link60000664000175000017500000000032111625765051012754 00000000000000!mkdir dir put /dev/null foo put /dev/null wibble link foo bar ls -l bar #-rw-r--r-- +2 +\S+ +\S+ +0 +[a-zA-Z]+ \d+ \d+:\d+ bar link wibble bar #.*file already exists.* link dir spong #.*file is a directory.* sftpserver-0.2.1/tests/symlink30000664000175000017500000000011511625765051013503 00000000000000put /dev/null foo symlink notexist foo #.*File exists.* symlink foo notexist sftpserver-0.2.1/tests/rename30000664000175000017500000000074311625765051013273 00000000000000put /dev/null file ls -1 file #file mv file newname ls -1 file #.*file does not exist.* ls -1 newname #newname put /dev/null otherfile mv newname otherfile #.*File exists.* !mkdir dir mv dir anotherdir !mkdir dir2 mv dir2 anotherdir #.*operation failed.* !mkdir nowritedir !touch nowritedir/file !chmod 555 nowritedir mv dir2 nowritedir/spong #.*permission denied.* mv nowritedir/file cant_rm_source #.*permission denied.* mv -o a b #.*cannot emulate rename flags \S+ in protocol \d sftpserver-0.2.1/tests/open560000664000175000017500000000115511625765051013053 00000000000000!echo 1 > one !echo 2 > two !ln -s two link !ln -s three dangling put -e one nonesuch #.*file does not exist.* put -f one link #.*too many symbolic links.* put -f one dangling #.*too many symbolic links.* put -ft one link #.*too many symbolic links.* put -ft one dangling #.*too many symbolic links.* put -fe one link #.*too many symbolic links.* put -fe one dangling #.*too many symbolic links.* get link two-dl !diff two two-dl get -f link two-dont #.*too many symbolic links.* put -f one one-ul !diff one one-ul put -f one one-ul !diff one one-ul put -d one one-del ![ -f one-del ] && echo one-del unexpectedly exists sftpserver-0.2.1/tests/cd34560000664000175000017500000000043211625765051012644 00000000000000!mkdir dir !ln -s dir link !touch dir/file cd dir pwd #.*/dir ls -1 #file cd .. ls -1 #dir #link cd link pwd #.*/dir ls -1 #file cd .. ls -1 #dir #link cd / pwd #/ lcd dir !cd .. && rm -rf dir lpwd #.*No such file or directory.* _lrealpath no-check . #.*No such file or directory.* sftpserver-0.2.1/tests/vsel6five0000664000175000017500000000022211625765051013642 00000000000000version 5 version #Protocol version: +5 #Server vendor: +.+ #Server name: +.+ #Server version: +.+ #Server build: +\d+ #Server supports: +3,4,5,6 sftpserver-0.2.1/tests/nosuchpath4560000664000175000017500000000014411625765051014347 00000000000000!touch foo put -A foo bar/spong #.*path does not exist.* put -A foo /spong #.*file does not exist.* sftpserver-0.2.1/tests/ls60000664000175000017500000000176311625765051012450 00000000000000!touch empty !echo spong > small !dd if=/dev/zero of=large bs=1024 count=1024 2>/dev/null !ln -s a b !ln small wibble ls -la #drwxr.[xs]r.x +\d+ +\S+ +\S+ +\S+ +[a-zA-Z]+ +\d+ +\d+:\d+ \. \[hide\] #drwxr.[xs]r.x +\d+ +\S+ +\S+ +\S+ +[a-zA-Z]+ +\d+ +\d+:\d+ \.\. \[hide\] #lrwxr.[xs]r.x +1 +\S+ +\S+ +\S+ +[a-zA-Z]+ +\d+ +\d+:\d+ b -> a #-rw-r--r-- +1 +\S+ +\S+ +0 +[a-zA-Z]+ +\d+ +\d+:\d+ empty #-rw-r--r-- +1 +\S+ +\S+ +1048576 +[a-zA-Z]+ +\d+ +\d+:\d+ large #-rw-r--r-- +2 +\S+ +\S+ +6 +[a-zA-Z]+ +\d+ +\d+:\d+ small #-rw-r--r-- +2 +\S+ +\S+ +6 +[a-zA-Z]+ +\d+ +\d+:\d+ wibble !mkdir noreadperm !chmod 000 noreadperm ls noreadperm #.*permission denied.* lstat b #lrwxr.[xs]r.x +1 +\S+ +\S+ +\S+ +[a-zA-Z]+ +\d+ +\d+:\d+ b stat b #.*file does not exist stat large #-rw-r--r-- +1 +\S+ +\S+ +1048576 +[a-zA-Z]+ +\d+ +\d+:\d+ large !mkdir dir chmod 7755 dir stat dir #drwsr-sr-t +\d+ +\S+ +\S+ +\d+ +[a-zA-Z]+ +\d+ +\d+:\d+ dir chmod 7000 dir stat dir #d--S--S--T +\d+ +\S+ +\S+ +\d+ +[a-zA-Z]+ +\d+ +\d+:\d+ dir sftpserver-0.2.1/tests/symlink4560000664000175000017500000000012511625765051013660 00000000000000put /dev/null foo symlink notexist foo #.*file already exists.* symlink foo notexist sftpserver-0.2.1/tests/unsupported34560000664000175000017500000000033111625765051014644 00000000000000_unsupported #.*operation not supported.* _ext_unsupported #.*operation not supported.* _bad_handle #.*(operation failed|invalid handle).* #.*(operation failed|invalid handle).* #.*(operation failed|invalid handle).* sftpserver-0.2.1/tests/posix-rename34560000664000175000017500000000041111625765051014662 00000000000000!touch file ls -1 file #file mv -p file newname ls -1 file #.*file does not exist.* ls -1 newname #newname !touch otherfile mv -p newname otherfile ls -1 newname #.*file does not exist.* ls -1 otherfile #otherfile mv -p nosuchfile anything #.*file does not exist.* sftpserver-0.2.1/tests/version2~0000664000175000017500000000015511625765051013703 00000000000000version #Protocol version: +3 #Server vendor: +.+ #Server name: +.+ #Server version: +.+ #Server build: +\d+ sftpserver-0.2.1/tests/badpath450000664000175000017500000000005111625765051013505 00000000000000_bad_path #.*badly encoded SFTP packet.* sftpserver-0.2.1/parse.h0000664000175000017500000001057111626705056012137 00000000000000/* * This file is part of the Green End SFTP Server. * Copyright (C) 2007, 2011 Richard Kettlewell * * 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 2 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, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA */ /** @file parse.h @brief Message parsing interface */ #ifndef PARSE_H #define PARSE_H /** @brief Retrieve the next byte from a message * @param job Job containing message * @param ur Where to store value * @return 0 on success, @ref SSH_FX_BAD_MESSAGE on error */ uint32_t sftp_parse_uint8(struct sftpjob *job, uint8_t *ur); /** @brief Retrieve the next 16-bit value from a message * @param job Job containing message * @param ur Where to store value * @return 0 on success, @ref SSH_FX_BAD_MESSAGE on error */ uint32_t sftp_parse_uint16(struct sftpjob *job, uint16_t *ur); /** @brief Retrieve the next 32-bit value from a message * @param job Job containing message * @param ur Where to store value * @return 0 on success, @ref SSH_FX_BAD_MESSAGE on error */ uint32_t sftp_parse_uint32(struct sftpjob *job, uint32_t *ur); /** @brief Retrieve the next 64-bit value from a message * @param job Job containing message * @param ur Where to store byte value * @return 0 on success, @ref SSH_FX_BAD_MESSAGE on error */ uint32_t sftp_parse_uint64(struct sftpjob *job, uint64_t *ur); /** @brief Retrieve the next string value from a message * @param job Job containing message * @param strp Where to store string * @param lenp Where to store length * @return 0 on success, @ref SSH_FX_BAD_MESSAGE on error * * The string will be allocated using the job's allocator and will not be * 0-terminated. * * @todo Could we just point into the message? */ uint32_t sftp_parse_string(struct sftpjob *job, char **strp, size_t *lenp); /** @brief Retrieve the next path value from a message * @param job Job containing message * @param strp Where to store path * @return 0 on success, error code on error * * The path will be allocated using the job's allocator and will be * 0-terminated. For protocols other than v3 it will be converted from UTF-8 * to the current locale's encoding. */ uint32_t sftp_parse_path(struct sftpjob *job, char **strp); /** @brief Retrieve the next handle value from a message * @param job Job containing message * @param id Where to store handle * @return 0 on success, @ref SSH_FX_BAD_MESSAGE on error * * No attempt is made to validate the handle */ uint32_t sftp_parse_handle(struct sftpjob *job, struct handleid *id); #if CLIENT /** @brief Error checking wrapper for sftp_parse_... functions * @param E expression to check * * If the parse fails, @ref fatal() is called. This macro is only used in the * client. */ #define cpcheck(E) do { \ const uint32_t rc = (E); \ if(rc) { \ D(("%s:%d: %s returned %"PRIu32, __FILE__, __LINE__, #E, rc)); \ fatal("error parsing response from server"); \ } \ } while(0) #else /** @brief Error checking wrapper for sftp_parse_... functions * @param E expression to check * * If the parse fails, @c return is invoked with the error code. */ #define pcheck(E) do { \ const uint32_t rc = (E); \ if(rc != SSH_FX_OK) { \ D(("%s:%d: %s: %"PRIu32, __FILE__, __LINE__, #E, rc)); \ return rc; \ } \ } while(0) #endif #endif /* PARSE_H */ /* Local Variables: c-basic-offset:2 comment-column:40 fill-column:79 indent-tabs-mode:nil End: */ sftpserver-0.2.1/alloc.h0000664000175000017500000000513311626705056012115 00000000000000/* * This file is part of the Green End SFTP Server. * Copyright (C) 2007, 2011 Richard Kettlewell * * 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 2 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, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA */ /** @file alloc.h @brief Allocator interface */ #ifndef ALLOC_H #define ALLOC_H struct chunk; /** @brief An allocator * * This kind of allocator supports quick allocation but does not support * freeing of single allocations. The only way to release resources is to free * all allocations. It is not thread safe. */ struct allocator { /** @brief Head of linked list of chunks * * This is the most recently created chunk, or a null pointer. */ struct chunk *chunks; }; /** @brief Initialize an allocator * @param a Allocator to initialize * @return @p a */ struct allocator *sftp_alloc_init(struct allocator *a); /** @brief Allocate space from an allocator * @param a Allocator * @param n Number of bytes to allocate * @return Pointer to allocated memory * * If @p n is 0 then the return value is a null pointer. * If memory cannot be allocated, the process is terminated. * * Newly allocate memory is always 0-filled. */ void *sftp_alloc(struct allocator *a, size_t n); /** @brief Expand an allocation within an allocator * @param a Allocator * @param ptr Allocation to expand, or a null pointer * @param oldn Old size in bytes * @param newn New size in bytes * @return New allocation * * If @p ptr is a null pointer then @p oldn must be 0. The new allocation may * be the same or different to @p ptr. If the new allocation is larger then * the extra space is 0-filled. */ void *sftp_alloc_more(struct allocator *a, void *ptr, size_t oldn, size_t newn); /** @brief Destroy an allocator * @param a Allocator * * All memory allocated through the allocator is freed. The allocator remains * initialized. */ void sftp_alloc_destroy(struct allocator *a); #endif /* ALLOC_H */ /* Local Variables: c-basic-offset:2 comment-column:40 fill-column:79 indent-tabs-mode:nil End: */ sftpserver-0.2.1/sftpcommon.h0000664000175000017500000000476412340114433013204 00000000000000/* * This file is part of the Green End SFTP Server. * Copyright (C) 2007, 2011, 2014 Richard Kettlewell * * 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 2 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, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA */ #ifndef SFTPCOMMON_H #define SFTPCOMMON_H /** @file sftpcommon.h @brief Common definitions */ #include #include #include #if HAVE_ENDIAN_H # include #endif #ifndef ASM # define ASM 1 #endif #if __GNUC__ && __amd64__ && ASM /** @brief Byte-swap a 64-bit value */ #define BSWAP64(N) \ ({uint64_t __n = (N); __asm__("bswap %0" : "+q"(__n)); __n;}) #endif #if __GNUC__ && !defined BSWAP64 /** @brief Byte-swap a 64-bit value */ #define BSWAP64(N) \ ({uint64_t __n = (N); __n = ntohl(__n >> 32) | ((uint64_t)ntohl(__n) << 32); __n;}) #endif #if WORDS_BIGENDIAN /** @brief Convert a 64-bit value to network byte order */ # define NTOHLL(n) (n) /** @brief Convert a 64-bit value to host byte order */ # define HTONLL(n) (n) #endif #if HAVE_DECL_BE64TOH && !defined NTOHLL /** @brief Convert a 64-bit value to network byte order */ # define NTOHLL be64toh #endif #if HAVE_DECL_HTOBE64 && !defined HTONLL /** @brief Convert a 64-bit value to host byte order */ #define HTONLL htobe64 #endif #if defined BSWAP64 && !defined NTOHLL /** @brief Convert a 64-bit value to network byte order */ # define NTOHLL BSWAP64 #endif #if defined BSWAP64 && !defined HTONLL /** @brief Convert a 64-bit value to host byte order */ # define HTONLL BSWAP64 #endif struct queue; struct allocator; struct handleid; struct sftpjob; struct sftpattr; struct worker; struct stat; /** @brief Return a human-readable description of @p status * @param status SFTP status code * @return Human-readable string */ const char *status_to_string(uint32_t status); #endif /* SFTPCOMMON_H */ /* Local Variables: c-basic-offset:2 comment-column:40 fill-column:79 indent-tabs-mode:nil End: */ sftpserver-0.2.1/INSTALL0000644000175000000000000003660011777117217011672 00000000000000Installation Instructions ************************* Copyright (C) 1994-1996, 1999-2002, 2004-2011 Free Software Foundation, Inc. Copying and distribution of this file, with or without modification, are permitted in any medium without royalty provided the copyright notice and this notice are preserved. This file is offered as-is, without warranty of any kind. Basic Installation ================== Briefly, the shell commands `./configure; make; make install' should configure, build, and install this package. The following more-detailed instructions are generic; see the `README' file for instructions specific to this package. Some packages provide this `INSTALL' file but do not implement all of the features documented below. The lack of an optional feature in a given package is not necessarily a bug. More recommendations for GNU packages can be found in *note Makefile Conventions: (standards)Makefile Conventions. The `configure' shell script attempts to guess correct values for various system-dependent variables used during compilation. It uses those values to create a `Makefile' in each directory of the package. It may also create one or more `.h' files containing system-dependent definitions. Finally, it creates a shell script `config.status' that you can run in the future to recreate the current configuration, and a file `config.log' containing compiler output (useful mainly for debugging `configure'). It can also use an optional file (typically called `config.cache' and enabled with `--cache-file=config.cache' or simply `-C') that saves the results of its tests to speed up reconfiguring. Caching is disabled by default to prevent problems with accidental use of stale cache files. If you need to do unusual things to compile the package, please try to figure out how `configure' could check whether to do them, and mail diffs or instructions to the address given in the `README' so they can be considered for the next release. If you are using the cache, and at some point `config.cache' contains results you don't want to keep, you may remove or edit it. The file `configure.ac' (or `configure.in') is used to create `configure' by a program called `autoconf'. You need `configure.ac' if you want to change it or regenerate `configure' using a newer version of `autoconf'. The simplest way to compile this package is: 1. `cd' to the directory containing the package's source code and type `./configure' to configure the package for your system. Running `configure' might take a while. While running, it prints some messages telling which features it is checking for. 2. Type `make' to compile the package. 3. Optionally, type `make check' to run any self-tests that come with the package, generally using the just-built uninstalled binaries. 4. Type `make install' to install the programs and any data files and documentation. When installing into a prefix owned by root, it is recommended that the package be configured and built as a regular user, and only the `make install' phase executed with root privileges. 5. Optionally, type `make installcheck' to repeat any self-tests, but this time using the binaries in their final installed location. This target does not install anything. Running this target as a regular user, particularly if the prior `make install' required root privileges, verifies that the installation completed correctly. 6. You can remove the program binaries and object files from the source code directory by typing `make clean'. To also remove the files that `configure' created (so you can compile the package for a different kind of computer), type `make distclean'. There is also a `make maintainer-clean' target, but that is intended mainly for the package's developers. If you use it, you may have to get all sorts of other programs in order to regenerate files that came with the distribution. 7. Often, you can also type `make uninstall' to remove the installed files again. In practice, not all packages have tested that uninstallation works correctly, even though it is required by the GNU Coding Standards. 8. Some packages, particularly those that use Automake, provide `make distcheck', which can by used by developers to test that all other targets like `make install' and `make uninstall' work correctly. This target is generally not run by end users. Compilers and Options ===================== Some systems require unusual options for compilation or linking that the `configure' script does not know about. Run `./configure --help' for details on some of the pertinent environment variables. You can give `configure' initial values for configuration parameters by setting variables in the command line or in the environment. Here is an example: ./configure CC=c99 CFLAGS=-g LIBS=-lposix *Note Defining Variables::, for more details. Compiling For Multiple Architectures ==================================== You can compile the package for more than one kind of computer at the same time, by placing the object files for each architecture in their own directory. To do this, you can use GNU `make'. `cd' to the directory where you want the object files and executables to go and run the `configure' script. `configure' automatically checks for the source code in the directory that `configure' is in and in `..'. This is known as a "VPATH" build. With a non-GNU `make', it is safer to compile the package for one architecture at a time in the source code directory. After you have installed the package for one architecture, use `make distclean' before reconfiguring for another architecture. On MacOS X 10.5 and later systems, you can create libraries and executables that work on multiple system types--known as "fat" or "universal" binaries--by specifying multiple `-arch' options to the compiler but only a single `-arch' option to the preprocessor. Like this: ./configure CC="gcc -arch i386 -arch x86_64 -arch ppc -arch ppc64" \ CXX="g++ -arch i386 -arch x86_64 -arch ppc -arch ppc64" \ CPP="gcc -E" CXXCPP="g++ -E" This is not guaranteed to produce working output in all cases, you may have to build one architecture at a time and combine the results using the `lipo' tool if you have problems. Installation Names ================== By default, `make install' installs the package's commands under `/usr/local/bin', include files under `/usr/local/include', etc. You can specify an installation prefix other than `/usr/local' by giving `configure' the option `--prefix=PREFIX', where PREFIX must be an absolute file name. You can specify separate installation prefixes for architecture-specific files and architecture-independent files. If you pass the option `--exec-prefix=PREFIX' to `configure', the package uses PREFIX as the prefix for installing programs and libraries. Documentation and other data files still use the regular prefix. In addition, if you use an unusual directory layout you can give options like `--bindir=DIR' to specify different values for particular kinds of files. Run `configure --help' for a list of the directories you can set and what kinds of files go in them. In general, the default for these options is expressed in terms of `${prefix}', so that specifying just `--prefix' will affect all of the other directory specifications that were not explicitly provided. The most portable way to affect installation locations is to pass the correct locations to `configure'; however, many packages provide one or both of the following shortcuts of passing variable assignments to the `make install' command line to change installation locations without having to reconfigure or recompile. The first method involves providing an override variable for each affected directory. For example, `make install prefix=/alternate/directory' will choose an alternate location for all directory configuration variables that were expressed in terms of `${prefix}'. Any directories that were specified during `configure', but not in terms of `${prefix}', must each be overridden at install time for the entire installation to be relocated. The approach of makefile variable overrides for each directory variable is required by the GNU Coding Standards, and ideally causes no recompilation. However, some platforms have known limitations with the semantics of shared libraries that end up requiring recompilation when using this method, particularly noticeable in packages that use GNU Libtool. The second method involves providing the `DESTDIR' variable. For example, `make install DESTDIR=/alternate/directory' will prepend `/alternate/directory' before all installation names. The approach of `DESTDIR' overrides is not required by the GNU Coding Standards, and does not work on platforms that have drive letters. On the other hand, it does better at avoiding recompilation issues, and works well even when some directory options were not specified in terms of `${prefix}' at `configure' time. Optional Features ================= If the package supports it, you can cause programs to be installed with an extra prefix or suffix on their names by giving `configure' the option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'. Some packages pay attention to `--enable-FEATURE' options to `configure', where FEATURE indicates an optional part of the package. They may also pay attention to `--with-PACKAGE' options, where PACKAGE is something like `gnu-as' or `x' (for the X Window System). The `README' should mention any `--enable-' and `--with-' options that the package recognizes. For packages that use the X Window System, `configure' can usually find the X include and library files automatically, but if it doesn't, you can use the `configure' options `--x-includes=DIR' and `--x-libraries=DIR' to specify their locations. Some packages offer the ability to configure how verbose the execution of `make' will be. For these packages, running `./configure --enable-silent-rules' sets the default to minimal output, which can be overridden with `make V=1'; while running `./configure --disable-silent-rules' sets the default to verbose, which can be overridden with `make V=0'. Particular systems ================== On HP-UX, the default C compiler is not ANSI C compatible. If GNU CC is not installed, it is recommended to use the following options in order to use an ANSI C compiler: ./configure CC="cc -Ae -D_XOPEN_SOURCE=500" and if that doesn't work, install pre-built binaries of GCC for HP-UX. HP-UX `make' updates targets which have the same time stamps as their prerequisites, which makes it generally unusable when shipped generated files such as `configure' are involved. Use GNU `make' instead. On OSF/1 a.k.a. Tru64, some versions of the default C compiler cannot parse its `' header file. The option `-nodtk' can be used as a workaround. If GNU CC is not installed, it is therefore recommended to try ./configure CC="cc" and if that doesn't work, try ./configure CC="cc -nodtk" On Solaris, don't put `/usr/ucb' early in your `PATH'. This directory contains several dysfunctional programs; working variants of these programs are available in `/usr/bin'. So, if you need `/usr/ucb' in your `PATH', put it _after_ `/usr/bin'. On Haiku, software installed for all users goes in `/boot/common', not `/usr/local'. It is recommended to use the following options: ./configure --prefix=/boot/common Specifying the System Type ========================== There may be some features `configure' cannot figure out automatically, but needs to determine by the type of machine the package will run on. Usually, assuming the package is built to be run on the _same_ architectures, `configure' can figure that out, but if it prints a message saying it cannot guess the machine type, give it the `--build=TYPE' option. TYPE can either be a short name for the system type, such as `sun4', or a canonical name which has the form: CPU-COMPANY-SYSTEM where SYSTEM can have one of these forms: OS KERNEL-OS See the file `config.sub' for the possible values of each field. If `config.sub' isn't included in this package, then this package doesn't need to know the machine type. If you are _building_ compiler tools for cross-compiling, you should use the option `--target=TYPE' to select the type of system they will produce code for. If you want to _use_ a cross compiler, that generates code for a platform different from the build platform, you should specify the "host" platform (i.e., that on which the generated programs will eventually be run) with `--host=TYPE'. Sharing Defaults ================ If you want to set default values for `configure' scripts to share, you can create a site shell script called `config.site' that gives default values for variables like `CC', `cache_file', and `prefix'. `configure' looks for `PREFIX/share/config.site' if it exists, then `PREFIX/etc/config.site' if it exists. Or, you can set the `CONFIG_SITE' environment variable to the location of the site script. A warning: not all `configure' scripts look for a site script. Defining Variables ================== Variables not defined in a site shell script can be set in the environment passed to `configure'. However, some packages may run configure again during the build, and the customized values of these variables may be lost. In order to avoid this problem, you should set them in the `configure' command line, using `VAR=value'. For example: ./configure CC=/usr/local2/bin/gcc causes the specified `gcc' to be used as the C compiler (unless it is overridden in the site shell script). Unfortunately, this technique does not work for `CONFIG_SHELL' due to an Autoconf bug. Until the bug is fixed you can use this workaround: CONFIG_SHELL=/bin/bash /bin/bash ./configure CONFIG_SHELL=/bin/bash `configure' Invocation ====================== `configure' recognizes the following options to control how it operates. `--help' `-h' Print a summary of all of the options to `configure', and exit. `--help=short' `--help=recursive' Print a summary of the options unique to this package's `configure', and exit. The `short' variant lists options used only in the top level, while the `recursive' variant lists options also present in any nested packages. `--version' `-V' Print the version of Autoconf used to generate the `configure' script, and exit. `--cache-file=FILE' Enable the cache: use and save the results of the tests in FILE, traditionally `config.cache'. FILE defaults to `/dev/null' to disable caching. `--config-cache' `-C' Alias for `--cache-file=config.cache'. `--quiet' `--silent' `-q' Do not print messages saying which checks are being made. To suppress all normal output, redirect it to `/dev/null' (any error messages will still be shown). `--srcdir=DIR' Look for the package's source code in directory DIR. Usually `configure' can determine that directory automatically. `--prefix=DIR' Use DIR as the installation prefix. *note Installation Names:: for more details, including other options available for fine-tuning the installation locations. `--no-create' `-n' Run the configure checks, but stop before creating any output files. `configure' also accepts some other, not widely useful, options. Run `configure --help' for more details. sftpserver-0.2.1/serialize.h0000664000175000017500000000317011626705056013011 00000000000000/* * This file is part of the Green End SFTP Server. * Copyright (C) 2007, 2011 Richard Kettlewell * * 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 2 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, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA */ /** @file serialize.h @brief Request serialization interface */ #ifndef SERIALIZE_H #define SERIALIZE_H /** @brief Establish a job's place in the serialization queue * @param job Job to establish * * Called for @ref SSH_FXP_READ and @ref SSH_FXP_WRITE. */ void queue_serializable_job(struct sftpjob *job); /** @brief Serialize a job * @param job Job to serialize * * Wait until there are no jobs conflicting with @p job that were established * before it in the serialization queue. */ void serialize(struct sftpjob *job); /** @brief Remove a job from the serialization queue * @param job Job to remove * * Called when the job is completed. */ void serialize_remove_job(struct sftpjob *job); #endif /* SERIALIZE_H */ /* Local Variables: c-basic-offset:2 comment-column:40 fill-column:79 indent-tabs-mode:nil End: */ sftpserver-0.2.1/Makefile.in0000664000175000017500000007747512415610055012730 00000000000000# Makefile.in generated by automake 1.11.6 from Makefile.am. # @configure_input@ # Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, # 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software # Foundation, Inc. # This Makefile.in 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. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY, to the extent permitted by law; without # even the implied warranty of MERCHANTABILITY or FITNESS FOR A # PARTICULAR PURPOSE. @SET_MAKE@ # This file is part of the Green End SFTP Server. # Copyright (C) 2007, 2011, 2014 Richard Kettlewell # # 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 2 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, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 # USA VPATH = @srcdir@ am__make_dryrun = \ { \ am__dry=no; \ case $$MAKEFLAGS in \ *\\[\ \ ]*) \ echo 'am--echo: ; @echo "AM" OK' | $(MAKE) -f - 2>/dev/null \ | grep '^AM OK$$' >/dev/null || am__dry=yes;; \ *) \ for am__flg in $$MAKEFLAGS; do \ case $$am__flg in \ *=*|--*) ;; \ *n*) am__dry=yes; break;; \ esac; \ done;; \ esac; \ test $$am__dry = yes; \ } pkgdatadir = $(datadir)/@PACKAGE@ pkgincludedir = $(includedir)/@PACKAGE@ pkglibdir = $(libdir)/@PACKAGE@ pkglibexecdir = $(libexecdir)/@PACKAGE@ am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd install_sh_DATA = $(install_sh) -c -m 644 install_sh_PROGRAM = $(install_sh) -c install_sh_SCRIPT = $(install_sh) -c INSTALL_HEADER = $(INSTALL_DATA) transform = $(program_transform_name) NORMAL_INSTALL = : PRE_INSTALL = : POST_INSTALL = : NORMAL_UNINSTALL = : PRE_UNINSTALL = : POST_UNINSTALL = : build_triplet = @build@ host_triplet = @host@ noinst_PROGRAMS = sftpclient$(EXEEXT) pwtest$(EXEEXT) libexec_PROGRAMS = gesftpserver$(EXEEXT) subdir = . DIST_COMMON = README $(am__configure_deps) $(srcdir)/Makefile.am \ $(srcdir)/Makefile.in $(srcdir)/config.h.in \ $(top_srcdir)/configure COPYING INSTALL \ config.aux/config.guess config.aux/config.sub \ config.aux/depcomp config.aux/install-sh config.aux/missing \ daemon.c futimes.c getopt.c getopt1.c ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/acinclude.m4 \ $(top_srcdir)/configure.ac am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) am__CONFIG_DISTCLEAN_FILES = config.status config.cache config.log \ configure.lineno config.status.lineno mkinstalldirs = $(install_sh) -d CONFIG_HEADER = config.h CONFIG_CLEAN_FILES = CONFIG_CLEAN_VPATH_FILES = LIBRARIES = $(noinst_LIBRARIES) AR = ar ARFLAGS = cru libsftp_a_AR = $(AR) $(ARFLAGS) libsftp_a_DEPENDENCIES = $(LIBOBJS) am_libsftp_a_OBJECTS = alloc.$(OBJEXT) debug.$(OBJEXT) \ handle.$(OBJEXT) parse.$(OBJEXT) queue.$(OBJEXT) \ send.$(OBJEXT) status.$(OBJEXT) users.$(OBJEXT) \ utils.$(OBJEXT) v3.$(OBJEXT) xfns.$(OBJEXT) stat.$(OBJEXT) \ charset.$(OBJEXT) serialize.$(OBJEXT) v4.$(OBJEXT) \ realpath.$(OBJEXT) readlink.$(OBJEXT) v5.$(OBJEXT) \ v6.$(OBJEXT) getcwd.$(OBJEXT) globals.$(OBJEXT) \ dirname.$(OBJEXT) libsftp_a_OBJECTS = $(am_libsftp_a_OBJECTS) am__installdirs = "$(DESTDIR)$(libexecdir)" "$(DESTDIR)$(man8dir)" PROGRAMS = $(libexec_PROGRAMS) $(noinst_PROGRAMS) am_gesftpserver_OBJECTS = sftpserver.$(OBJEXT) readwrite.$(OBJEXT) gesftpserver_OBJECTS = $(am_gesftpserver_OBJECTS) gesftpserver_DEPENDENCIES = libsftp.a am_pwtest_OBJECTS = pwtest.$(OBJEXT) pwtest_OBJECTS = $(am_pwtest_OBJECTS) pwtest_LDADD = $(LDADD) am_sftpclient_OBJECTS = sftpclient.$(OBJEXT) readwrite.$(OBJEXT) sftpclient_OBJECTS = $(am_sftpclient_OBJECTS) am__DEPENDENCIES_1 = sftpclient_DEPENDENCIES = libsftp.a $(am__DEPENDENCIES_1) SCRIPTS = $(noinst_SCRIPTS) DEFAULT_INCLUDES = -I.@am__isrc@ depcomp = $(SHELL) $(top_srcdir)/config.aux/depcomp am__depfiles_maybe = depfiles am__mv = mv -f COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) CCLD = $(CC) LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@ SOURCES = $(libsftp_a_SOURCES) $(gesftpserver_SOURCES) \ $(pwtest_SOURCES) $(sftpclient_SOURCES) DIST_SOURCES = $(libsftp_a_SOURCES) $(gesftpserver_SOURCES) \ $(pwtest_SOURCES) $(sftpclient_SOURCES) am__can_run_installinfo = \ case $$AM_UPDATE_INFO_DIR in \ n|no|NO) false;; \ *) (install-info --version) >/dev/null 2>&1;; \ esac am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; am__vpath_adj = case $$p in \ $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ *) f=$$p;; \ esac; am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`; am__install_max = 40 am__nobase_strip_setup = \ srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'` am__nobase_strip = \ for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||" am__nobase_list = $(am__nobase_strip_setup); \ for p in $$list; do echo "$$p $$p"; done | \ sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \ $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \ if (++n[$$2] == $(am__install_max)) \ { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \ END { for (dir in files) print dir, files[dir] }' am__base_list = \ sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \ sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g' am__uninstall_files_from_dir = { \ test -z "$$files" \ || { test ! -d "$$dir" && test ! -f "$$dir" && test ! -r "$$dir"; } \ || { echo " ( cd '$$dir' && rm -f" $$files ")"; \ $(am__cd) "$$dir" && rm -f $$files; }; \ } man8dir = $(mandir)/man8 NROFF = nroff MANS = $(man_MANS) ETAGS = etags CTAGS = ctags DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) distdir = $(PACKAGE)-$(VERSION) top_distdir = $(distdir) am__remove_distdir = \ if test -d "$(distdir)"; then \ find "$(distdir)" -type d ! -perm -200 -exec chmod u+w {} ';' \ && rm -rf "$(distdir)" \ || { sleep 5 && rm -rf "$(distdir)"; }; \ else :; fi DIST_ARCHIVES = $(distdir).tar.gz GZIP_ENV = --best distuninstallcheck_listfiles = find . -type f -print am__distuninstallcheck_listfiles = $(distuninstallcheck_listfiles) \ | sed 's|^\./|$(prefix)/|' | grep -v '$(infodir)/dir$$' distcleancheck_listfiles = find . -type f -print ACLOCAL = @ACLOCAL@ AMTAR = @AMTAR@ AUTOCONF = @AUTOCONF@ AUTOHEADER = @AUTOHEADER@ AUTOMAKE = @AUTOMAKE@ AWK = @AWK@ CC = @CC@ CCDEPMODE = @CCDEPMODE@ CFLAGS = @CFLAGS@ CPP = @CPP@ CPPFLAGS = @CPPFLAGS@ CYGPATH_W = @CYGPATH_W@ DEFS = @DEFS@ DEPDIR = @DEPDIR@ ECHO_C = @ECHO_C@ ECHO_N = @ECHO_N@ ECHO_T = @ECHO_T@ EGREP = @EGREP@ EXEEXT = @EXEEXT@ GCOV = @GCOV@ GREP = @GREP@ INSTALL = @INSTALL@ INSTALL_DATA = @INSTALL_DATA@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ INSTALL_SCRIPT = @INSTALL_SCRIPT@ INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ LDFLAGS = @LDFLAGS@ LIBOBJS = @LIBOBJS@ LIBREADLINE = @LIBREADLINE@ LIBS = @LIBS@ LTLIBOBJS = @LTLIBOBJS@ MAKEINFO = @MAKEINFO@ MKDIR_P = @MKDIR_P@ OBJEXT = @OBJEXT@ PACKAGE = @PACKAGE@ PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ PACKAGE_NAME = @PACKAGE_NAME@ PACKAGE_STRING = @PACKAGE_STRING@ PACKAGE_TARNAME = @PACKAGE_TARNAME@ PACKAGE_URL = @PACKAGE_URL@ PACKAGE_VERSION = @PACKAGE_VERSION@ PATH_SEPARATOR = @PATH_SEPARATOR@ PYTHON24 = @PYTHON24@ RANLIB = @RANLIB@ SET_MAKE = @SET_MAKE@ SHELL = @SHELL@ STRIP = @STRIP@ VERSION = @VERSION@ abs_builddir = @abs_builddir@ abs_srcdir = @abs_srcdir@ abs_top_builddir = @abs_top_builddir@ abs_top_srcdir = @abs_top_srcdir@ ac_ct_CC = @ac_ct_CC@ am__include = @am__include@ am__leading_dot = @am__leading_dot@ am__quote = @am__quote@ am__tar = @am__tar@ am__untar = @am__untar@ bindir = @bindir@ build = @build@ build_alias = @build_alias@ build_cpu = @build_cpu@ build_os = @build_os@ build_vendor = @build_vendor@ builddir = @builddir@ datadir = @datadir@ datarootdir = @datarootdir@ docdir = @docdir@ dvidir = @dvidir@ exec_prefix = @exec_prefix@ host = @host@ host_alias = @host_alias@ host_cpu = @host_cpu@ host_os = @host_os@ host_vendor = @host_vendor@ htmldir = @htmldir@ includedir = @includedir@ infodir = @infodir@ install_sh = @install_sh@ libdir = @libdir@ libexecdir = @libexecdir@ localedir = @localedir@ localstatedir = @localstatedir@ mandir = @mandir@ mkdir_p = @mkdir_p@ oldincludedir = @oldincludedir@ pdfdir = @pdfdir@ prefix = @prefix@ program_transform_name = @program_transform_name@ psdir = @psdir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ sysconfdir = @sysconfdir@ target_alias = @target_alias@ top_build_prefix = @top_build_prefix@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ noinst_SCRIPTS = run-tests noinst_LIBRARIES = libsftp.a gesftpserver_SOURCES = sftpserver.c readwrite.c gesftpserver_LDADD = libsftp.a sftpclient_SOURCES = sftpclient.c readwrite.c sftpclient_LDADD = libsftp.a $(LIBREADLINE) libsftp_a_SOURCES = alloc.c alloc.h debug.c debug.h globals.h handle.c \ handle.h parse.c parse.h queue.c queue.h send.c send.h sftp.h \ sftpclient.h sftpcommon.h sftpserver.h status.c thread.h types.h \ users.c users.h utils.c utils.h v3.c xfns.c xfns.h stat.c charset.c \ charset.h serialize.h serialize.c v4.c realpath.c readlink.c v5.c v6.c \ stat.h getcwd.c globals.c dirname.c putword.h libsftp_a_LIBADD = $(LIBOBJS) pwtest_SOURCES = pwtest.c # Documentation man_MANS = gesftpserver.8 # Cleaning DISTCLEANFILES = ${SEDOUTPUTS} gesftpserver.8 CLEANFILES = *.gcno *.gcda *.gcov gesftpserver-ro gesftpserver-debug gesftpserver-ro-debug gesftpserver-valgrind # Distribution EXTRA_DIST = gesftpserver.8.in testing.txt tests rotests README run-tests \ format-gconv-report getopt.c getopt1.c getopt.h all: config.h $(MAKE) $(AM_MAKEFLAGS) all-am .SUFFIXES: .SUFFIXES: .c .o .obj am--refresh: Makefile @: $(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) @for dep in $?; do \ case '$(am__configure_deps)' in \ *$$dep*) \ echo ' cd $(srcdir) && $(AUTOMAKE) --foreign'; \ $(am__cd) $(srcdir) && $(AUTOMAKE) --foreign \ && exit 0; \ exit 1;; \ esac; \ done; \ echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign Makefile'; \ $(am__cd) $(top_srcdir) && \ $(AUTOMAKE) --foreign Makefile .PRECIOUS: Makefile Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status @case '$?' in \ *config.status*) \ echo ' $(SHELL) ./config.status'; \ $(SHELL) ./config.status;; \ *) \ echo ' cd $(top_builddir) && $(SHELL) ./config.status $@ $(am__depfiles_maybe)'; \ cd $(top_builddir) && $(SHELL) ./config.status $@ $(am__depfiles_maybe);; \ esac; $(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) $(SHELL) ./config.status --recheck $(top_srcdir)/configure: $(am__configure_deps) $(am__cd) $(srcdir) && $(AUTOCONF) $(ACLOCAL_M4): $(am__aclocal_m4_deps) $(am__cd) $(srcdir) && $(ACLOCAL) $(ACLOCAL_AMFLAGS) $(am__aclocal_m4_deps): config.h: stamp-h1 @if test ! -f $@; then rm -f stamp-h1; else :; fi @if test ! -f $@; then $(MAKE) $(AM_MAKEFLAGS) stamp-h1; else :; fi stamp-h1: $(srcdir)/config.h.in $(top_builddir)/config.status @rm -f stamp-h1 cd $(top_builddir) && $(SHELL) ./config.status config.h $(srcdir)/config.h.in: $(am__configure_deps) ($(am__cd) $(top_srcdir) && $(AUTOHEADER)) rm -f stamp-h1 touch $@ distclean-hdr: -rm -f config.h stamp-h1 clean-noinstLIBRARIES: -test -z "$(noinst_LIBRARIES)" || rm -f $(noinst_LIBRARIES) libsftp.a: $(libsftp_a_OBJECTS) $(libsftp_a_DEPENDENCIES) $(EXTRA_libsftp_a_DEPENDENCIES) -rm -f libsftp.a $(libsftp_a_AR) libsftp.a $(libsftp_a_OBJECTS) $(libsftp_a_LIBADD) $(RANLIB) libsftp.a install-libexecPROGRAMS: $(libexec_PROGRAMS) @$(NORMAL_INSTALL) @list='$(libexec_PROGRAMS)'; test -n "$(libexecdir)" || list=; \ if test -n "$$list"; then \ echo " $(MKDIR_P) '$(DESTDIR)$(libexecdir)'"; \ $(MKDIR_P) "$(DESTDIR)$(libexecdir)" || exit 1; \ fi; \ for p in $$list; do echo "$$p $$p"; done | \ sed 's/$(EXEEXT)$$//' | \ while read p p1; do if test -f $$p; \ then echo "$$p"; echo "$$p"; else :; fi; \ done | \ sed -e 'p;s,.*/,,;n;h' -e 's|.*|.|' \ -e 'p;x;s,.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/' | \ sed 'N;N;N;s,\n, ,g' | \ $(AWK) 'BEGIN { files["."] = ""; dirs["."] = 1 } \ { d=$$3; if (dirs[d] != 1) { print "d", d; dirs[d] = 1 } \ if ($$2 == $$4) files[d] = files[d] " " $$1; \ else { print "f", $$3 "/" $$4, $$1; } } \ END { for (d in files) print "f", d, files[d] }' | \ while read type dir files; do \ if test "$$dir" = .; then dir=; else dir=/$$dir; fi; \ test -z "$$files" || { \ echo " $(INSTALL_PROGRAM_ENV) $(INSTALL_PROGRAM) $$files '$(DESTDIR)$(libexecdir)$$dir'"; \ $(INSTALL_PROGRAM_ENV) $(INSTALL_PROGRAM) $$files "$(DESTDIR)$(libexecdir)$$dir" || exit $$?; \ } \ ; done uninstall-libexecPROGRAMS: @$(NORMAL_UNINSTALL) @list='$(libexec_PROGRAMS)'; test -n "$(libexecdir)" || list=; \ files=`for p in $$list; do echo "$$p"; done | \ sed -e 'h;s,^.*/,,;s/$(EXEEXT)$$//;$(transform)' \ -e 's/$$/$(EXEEXT)/' `; \ test -n "$$list" || exit 0; \ echo " ( cd '$(DESTDIR)$(libexecdir)' && rm -f" $$files ")"; \ cd "$(DESTDIR)$(libexecdir)" && rm -f $$files clean-libexecPROGRAMS: -test -z "$(libexec_PROGRAMS)" || rm -f $(libexec_PROGRAMS) clean-noinstPROGRAMS: -test -z "$(noinst_PROGRAMS)" || rm -f $(noinst_PROGRAMS) gesftpserver$(EXEEXT): $(gesftpserver_OBJECTS) $(gesftpserver_DEPENDENCIES) $(EXTRA_gesftpserver_DEPENDENCIES) @rm -f gesftpserver$(EXEEXT) $(LINK) $(gesftpserver_OBJECTS) $(gesftpserver_LDADD) $(LIBS) pwtest$(EXEEXT): $(pwtest_OBJECTS) $(pwtest_DEPENDENCIES) $(EXTRA_pwtest_DEPENDENCIES) @rm -f pwtest$(EXEEXT) $(LINK) $(pwtest_OBJECTS) $(pwtest_LDADD) $(LIBS) sftpclient$(EXEEXT): $(sftpclient_OBJECTS) $(sftpclient_DEPENDENCIES) $(EXTRA_sftpclient_DEPENDENCIES) @rm -f sftpclient$(EXEEXT) $(LINK) $(sftpclient_OBJECTS) $(sftpclient_LDADD) $(LIBS) mostlyclean-compile: -rm -f *.$(OBJEXT) distclean-compile: -rm -f *.tab.c @AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/daemon.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/futimes.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/getopt.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/getopt1.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/alloc.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/charset.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/debug.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dirname.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/getcwd.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/globals.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/handle.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/parse.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pwtest.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/queue.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/readlink.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/readwrite.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/realpath.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/send.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/serialize.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sftpclient.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sftpserver.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/stat.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/status.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/users.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/utils.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/v3.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/v4.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/v5.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/v6.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xfns.Po@am__quote@ .c.o: @am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< @am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(COMPILE) -c $< .c.obj: @am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` @am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'` install-man8: $(man_MANS) @$(NORMAL_INSTALL) @list1=''; \ list2='$(man_MANS)'; \ test -n "$(man8dir)" \ && test -n "`echo $$list1$$list2`" \ || exit 0; \ echo " $(MKDIR_P) '$(DESTDIR)$(man8dir)'"; \ $(MKDIR_P) "$(DESTDIR)$(man8dir)" || exit 1; \ { for i in $$list1; do echo "$$i"; done; \ if test -n "$$list2"; then \ for i in $$list2; do echo "$$i"; done \ | sed -n '/\.8[a-z]*$$/p'; \ fi; \ } | while read p; do \ if test -f $$p; then d=; else d="$(srcdir)/"; fi; \ echo "$$d$$p"; echo "$$p"; \ done | \ sed -e 'n;s,.*/,,;p;h;s,.*\.,,;s,^[^8][0-9a-z]*$$,8,;x' \ -e 's,\.[0-9a-z]*$$,,;$(transform);G;s,\n,.,' | \ sed 'N;N;s,\n, ,g' | { \ list=; while read file base inst; do \ if test "$$base" = "$$inst"; then list="$$list $$file"; else \ echo " $(INSTALL_DATA) '$$file' '$(DESTDIR)$(man8dir)/$$inst'"; \ $(INSTALL_DATA) "$$file" "$(DESTDIR)$(man8dir)/$$inst" || exit $$?; \ fi; \ done; \ for i in $$list; do echo "$$i"; done | $(am__base_list) | \ while read files; do \ test -z "$$files" || { \ echo " $(INSTALL_DATA) $$files '$(DESTDIR)$(man8dir)'"; \ $(INSTALL_DATA) $$files "$(DESTDIR)$(man8dir)" || exit $$?; }; \ done; } uninstall-man8: @$(NORMAL_UNINSTALL) @list=''; test -n "$(man8dir)" || exit 0; \ files=`{ for i in $$list; do echo "$$i"; done; \ l2='$(man_MANS)'; for i in $$l2; do echo "$$i"; done | \ sed -n '/\.8[a-z]*$$/p'; \ } | sed -e 's,.*/,,;h;s,.*\.,,;s,^[^8][0-9a-z]*$$,8,;x' \ -e 's,\.[0-9a-z]*$$,,;$(transform);G;s,\n,.,'`; \ dir='$(DESTDIR)$(man8dir)'; $(am__uninstall_files_from_dir) ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ unique=`for i in $$list; do \ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ done | \ $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ END { if (nonempty) { for (i in files) print i; }; }'`; \ mkid -fID $$unique tags: TAGS TAGS: $(HEADERS) $(SOURCES) config.h.in $(TAGS_DEPENDENCIES) \ $(TAGS_FILES) $(LISP) set x; \ here=`pwd`; \ list='$(SOURCES) $(HEADERS) config.h.in $(LISP) $(TAGS_FILES)'; \ unique=`for i in $$list; do \ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ done | \ $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ END { if (nonempty) { for (i in files) print i; }; }'`; \ shift; \ if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ test -n "$$unique" || unique=$$empty_fix; \ if test $$# -gt 0; then \ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ "$$@" $$unique; \ else \ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ $$unique; \ fi; \ fi ctags: CTAGS CTAGS: $(HEADERS) $(SOURCES) config.h.in $(TAGS_DEPENDENCIES) \ $(TAGS_FILES) $(LISP) list='$(SOURCES) $(HEADERS) config.h.in $(LISP) $(TAGS_FILES)'; \ unique=`for i in $$list; do \ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ done | \ $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ END { if (nonempty) { for (i in files) print i; }; }'`; \ test -z "$(CTAGS_ARGS)$$unique" \ || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ $$unique GTAGS: here=`$(am__cd) $(top_builddir) && pwd` \ && $(am__cd) $(top_srcdir) \ && gtags -i $(GTAGS_ARGS) "$$here" distclean-tags: -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags distdir: $(DISTFILES) @list='$(MANS)'; if test -n "$$list"; then \ list=`for p in $$list; do \ if test -f $$p; then d=; else d="$(srcdir)/"; fi; \ if test -f "$$d$$p"; then echo "$$d$$p"; else :; fi; done`; \ if test -n "$$list" && \ grep 'ab help2man is required to generate this page' $$list >/dev/null; then \ echo "error: found man pages containing the \`missing help2man' replacement text:" >&2; \ grep -l 'ab help2man is required to generate this page' $$list | sed 's/^/ /' >&2; \ echo " to fix them, install help2man, remove and regenerate the man pages;" >&2; \ echo " typically \`make maintainer-clean' will remove them" >&2; \ exit 1; \ else :; fi; \ else :; fi $(am__remove_distdir) test -d "$(distdir)" || mkdir "$(distdir)" @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ list='$(DISTFILES)'; \ dist_files=`for file in $$list; do echo $$file; done | \ sed -e "s|^$$srcdirstrip/||;t" \ -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ case $$dist_files in \ */*) $(MKDIR_P) `echo "$$dist_files" | \ sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ sort -u` ;; \ esac; \ for file in $$dist_files; do \ if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ if test -d $$d/$$file; then \ dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ if test -d "$(distdir)/$$file"; then \ find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ fi; \ if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ fi; \ cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ else \ test -f "$(distdir)/$$file" \ || cp -p $$d/$$file "$(distdir)/$$file" \ || exit 1; \ fi; \ done -test -n "$(am__skip_mode_fix)" \ || find "$(distdir)" -type d ! -perm -755 \ -exec chmod u+rwx,go+rx {} \; -o \ ! -type d ! -perm -444 -links 1 -exec chmod a+r {} \; -o \ ! -type d ! -perm -400 -exec chmod a+r {} \; -o \ ! -type d ! -perm -444 -exec $(install_sh) -c -m a+r {} {} \; \ || chmod -R a+r "$(distdir)" dist-gzip: distdir tardir=$(distdir) && $(am__tar) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).tar.gz $(am__remove_distdir) dist-bzip2: distdir tardir=$(distdir) && $(am__tar) | BZIP2=$${BZIP2--9} bzip2 -c >$(distdir).tar.bz2 $(am__remove_distdir) dist-lzip: distdir tardir=$(distdir) && $(am__tar) | lzip -c $${LZIP_OPT--9} >$(distdir).tar.lz $(am__remove_distdir) dist-lzma: distdir tardir=$(distdir) && $(am__tar) | lzma -9 -c >$(distdir).tar.lzma $(am__remove_distdir) dist-xz: distdir tardir=$(distdir) && $(am__tar) | XZ_OPT=$${XZ_OPT--e} xz -c >$(distdir).tar.xz $(am__remove_distdir) dist-tarZ: distdir tardir=$(distdir) && $(am__tar) | compress -c >$(distdir).tar.Z $(am__remove_distdir) dist-shar: distdir shar $(distdir) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).shar.gz $(am__remove_distdir) dist-zip: distdir -rm -f $(distdir).zip zip -rq $(distdir).zip $(distdir) $(am__remove_distdir) dist dist-all: distdir tardir=$(distdir) && $(am__tar) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).tar.gz $(am__remove_distdir) # This target untars the dist file and tries a VPATH configuration. Then # it guarantees that the distribution is self-contained by making another # tarfile. distcheck: dist case '$(DIST_ARCHIVES)' in \ *.tar.gz*) \ GZIP=$(GZIP_ENV) gzip -dc $(distdir).tar.gz | $(am__untar) ;;\ *.tar.bz2*) \ bzip2 -dc $(distdir).tar.bz2 | $(am__untar) ;;\ *.tar.lzma*) \ lzma -dc $(distdir).tar.lzma | $(am__untar) ;;\ *.tar.lz*) \ lzip -dc $(distdir).tar.lz | $(am__untar) ;;\ *.tar.xz*) \ xz -dc $(distdir).tar.xz | $(am__untar) ;;\ *.tar.Z*) \ uncompress -c $(distdir).tar.Z | $(am__untar) ;;\ *.shar.gz*) \ GZIP=$(GZIP_ENV) gzip -dc $(distdir).shar.gz | unshar ;;\ *.zip*) \ unzip $(distdir).zip ;;\ esac chmod -R a-w $(distdir); chmod u+w $(distdir) mkdir $(distdir)/_build mkdir $(distdir)/_inst chmod a-w $(distdir) test -d $(distdir)/_build || exit 0; \ dc_install_base=`$(am__cd) $(distdir)/_inst && pwd | sed -e 's,^[^:\\/]:[\\/],/,'` \ && dc_destdir="$${TMPDIR-/tmp}/am-dc-$$$$/" \ && am__cwd=`pwd` \ && $(am__cd) $(distdir)/_build \ && ../configure --srcdir=.. --prefix="$$dc_install_base" \ $(AM_DISTCHECK_CONFIGURE_FLAGS) \ $(DISTCHECK_CONFIGURE_FLAGS) \ && $(MAKE) $(AM_MAKEFLAGS) \ && $(MAKE) $(AM_MAKEFLAGS) dvi \ && $(MAKE) $(AM_MAKEFLAGS) check \ && $(MAKE) $(AM_MAKEFLAGS) install \ && $(MAKE) $(AM_MAKEFLAGS) installcheck \ && $(MAKE) $(AM_MAKEFLAGS) uninstall \ && $(MAKE) $(AM_MAKEFLAGS) distuninstallcheck_dir="$$dc_install_base" \ distuninstallcheck \ && chmod -R a-w "$$dc_install_base" \ && ({ \ (cd ../.. && umask 077 && mkdir "$$dc_destdir") \ && $(MAKE) $(AM_MAKEFLAGS) DESTDIR="$$dc_destdir" install \ && $(MAKE) $(AM_MAKEFLAGS) DESTDIR="$$dc_destdir" uninstall \ && $(MAKE) $(AM_MAKEFLAGS) DESTDIR="$$dc_destdir" \ distuninstallcheck_dir="$$dc_destdir" distuninstallcheck; \ } || { rm -rf "$$dc_destdir"; exit 1; }) \ && rm -rf "$$dc_destdir" \ && $(MAKE) $(AM_MAKEFLAGS) dist \ && rm -rf $(DIST_ARCHIVES) \ && $(MAKE) $(AM_MAKEFLAGS) distcleancheck \ && cd "$$am__cwd" \ || exit 1 $(am__remove_distdir) @(echo "$(distdir) archives ready for distribution: "; \ list='$(DIST_ARCHIVES)'; for i in $$list; do echo $$i; done) | \ sed -e 1h -e 1s/./=/g -e 1p -e 1x -e '$$p' -e '$$x' distuninstallcheck: @test -n '$(distuninstallcheck_dir)' || { \ echo 'ERROR: trying to run $@ with an empty' \ '$$(distuninstallcheck_dir)' >&2; \ exit 1; \ }; \ $(am__cd) '$(distuninstallcheck_dir)' || { \ echo 'ERROR: cannot chdir into $(distuninstallcheck_dir)' >&2; \ exit 1; \ }; \ test `$(am__distuninstallcheck_listfiles) | wc -l` -eq 0 \ || { echo "ERROR: files left after uninstall:" ; \ if test -n "$(DESTDIR)"; then \ echo " (check DESTDIR support)"; \ fi ; \ $(distuninstallcheck_listfiles) ; \ exit 1; } >&2 distcleancheck: distclean @if test '$(srcdir)' = . ; then \ echo "ERROR: distcleancheck can only run from a VPATH build" ; \ exit 1 ; \ fi @test `$(distcleancheck_listfiles) | wc -l` -eq 0 \ || { echo "ERROR: files left in build directory after distclean:" ; \ $(distcleancheck_listfiles) ; \ exit 1; } >&2 check-am: all-am check: check-am all-am: Makefile $(LIBRARIES) $(PROGRAMS) $(SCRIPTS) $(MANS) config.h installdirs: for dir in "$(DESTDIR)$(libexecdir)" "$(DESTDIR)$(man8dir)"; do \ test -z "$$dir" || $(MKDIR_P) "$$dir"; \ done install: install-am install-exec: install-exec-am install-data: install-data-am uninstall: uninstall-am install-am: all-am @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am installcheck: installcheck-am install-strip: if test -z '$(STRIP)'; then \ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ install; \ else \ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \ fi mostlyclean-generic: clean-generic: -test -z "$(CLEANFILES)" || rm -f $(CLEANFILES) distclean-generic: -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) -test -z "$(DISTCLEANFILES)" || rm -f $(DISTCLEANFILES) maintainer-clean-generic: @echo "This command is intended for maintainers to use" @echo "it deletes files that may require special tools to rebuild." clean: clean-am clean-am: clean-generic clean-libexecPROGRAMS clean-noinstLIBRARIES \ clean-noinstPROGRAMS mostlyclean-am distclean: distclean-am -rm -f $(am__CONFIG_DISTCLEAN_FILES) -rm -rf $(DEPDIR) ./$(DEPDIR) -rm -f Makefile distclean-am: clean-am distclean-compile distclean-generic \ distclean-hdr distclean-tags dvi: dvi-am dvi-am: html: html-am html-am: info: info-am info-am: install-data-am: install-man install-dvi: install-dvi-am install-dvi-am: install-exec-am: install-libexecPROGRAMS install-html: install-html-am install-html-am: install-info: install-info-am install-info-am: install-man: install-man8 install-pdf: install-pdf-am install-pdf-am: install-ps: install-ps-am install-ps-am: installcheck-am: maintainer-clean: maintainer-clean-am -rm -f $(am__CONFIG_DISTCLEAN_FILES) -rm -rf $(top_srcdir)/autom4te.cache -rm -rf $(DEPDIR) ./$(DEPDIR) -rm -f Makefile maintainer-clean-am: distclean-am maintainer-clean-generic mostlyclean: mostlyclean-am mostlyclean-am: mostlyclean-compile mostlyclean-generic pdf: pdf-am pdf-am: ps: ps-am ps-am: uninstall-am: uninstall-libexecPROGRAMS uninstall-man uninstall-man: uninstall-man8 .MAKE: all install-am install-strip .PHONY: CTAGS GTAGS all all-am am--refresh check check-am clean \ clean-generic clean-libexecPROGRAMS clean-noinstLIBRARIES \ clean-noinstPROGRAMS ctags dist dist-all dist-bzip2 dist-gzip \ dist-lzip dist-lzma dist-shar dist-tarZ dist-xz dist-zip \ distcheck distclean distclean-compile distclean-generic \ distclean-hdr distclean-tags distcleancheck distdir \ distuninstallcheck dvi dvi-am html html-am info info-am \ install install-am install-data install-data-am install-dvi \ install-dvi-am install-exec install-exec-am install-html \ install-html-am install-info install-info-am \ install-libexecPROGRAMS install-man install-man8 install-pdf \ install-pdf-am install-ps install-ps-am install-strip \ installcheck installcheck-am installdirs maintainer-clean \ maintainer-clean-generic mostlyclean mostlyclean-compile \ mostlyclean-generic pdf pdf-am ps ps-am tags uninstall \ uninstall-am uninstall-libexecPROGRAMS uninstall-man \ uninstall-man8 gesftpserver.8: gesftpserver.8.in config.status sed < ${srcdir}/gesftpserver.8.in > $@.new \ -e "s,__libexecdir__,${libexecdir},g" mv $@.new $@ # Build and test all: ${SEDOUTPUTS} check: all aliases rm -f *.gcda *.gcov ./pwtest srcdir=${srcdir} ${PYTHON24} ${srcdir}/run-tests --directory tests $(TESTS) srcdir=${srcdir} ${PYTHON24} ${srcdir}/run-tests --directory rotests --server ./gesftpserver-ro $(ROTESTS) ${GCOV} ${srcdir}/*.c | ${PYTHON24} ${srcdir}/format-gconv-report --html . #${srcdir}/paramiko-test check-valgrind: all aliases rm -f ,valgrind* srcdir=${srcdir} ${PYTHON24} ${srcdir}/run-tests --directory tests --server ./gesftpserver-valgrind $(TESTS) aliases: gesftpserver-ro gesftpserver-debug gesftpserver-ro-debug \ gesftpserver-valgrind gesftpserver-ro: rm -f $@ ln -s gesftpserver $@ gesftpserver-debug: rm -f $@ ln -s gesftpserver $@ gesftpserver-ro-debug: rm -f $@ ln -s gesftpserver $@ gesftpserver-valgrind: echo "#! /bin/sh" > $@.new echo "set -e" >> $@.new echo "exec valgrind --leak-check=full -q --log-file=/dev/tty --num-callers=50 `pwd`/gesftpserver \"\$$@\"" >> $@.new chmod +x $@.new mv $@.new $@ %.s: %.c $(COMPILE) -o $@ -S $< # Tell versions [3.59,3.63) of GNU make to not export all variables. # Otherwise a system limit (for SysV at least) may be exceeded. .NOEXPORT: sftpserver-0.2.1/globals.c0000664000175000017500000000176311625765051012446 00000000000000/* * This file is part of the Green End SFTP Server. * Copyright (C) 2007 Richard Kettlewell * * 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 2 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, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA */ #include "sftpcommon.h" #include "types.h" #include "globals.h" struct queue *workqueue = 0; /* Local Variables: c-basic-offset:2 comment-column:40 fill-column:79 indent-tabs-mode:nil End: */ sftpserver-0.2.1/aclocal.m40000664000175000017500000010507012415610054012501 00000000000000# generated automatically by aclocal 1.11.6 -*- Autoconf -*- # Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, # 2005, 2006, 2007, 2008, 2009, 2010, 2011 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. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY, to the extent permitted by law; without # even the implied warranty of MERCHANTABILITY or FITNESS FOR A # PARTICULAR PURPOSE. m4_ifndef([AC_AUTOCONF_VERSION], [m4_copy([m4_PACKAGE_VERSION], [AC_AUTOCONF_VERSION])])dnl m4_if(m4_defn([AC_AUTOCONF_VERSION]), [2.69],, [m4_warning([this file was generated for autoconf 2.69. You have another version of autoconf. It may work, but is not guaranteed to. If you have problems, you may need to regenerate the build system entirely. To do so, use the procedure documented by the package, typically `autoreconf'.])]) # Copyright (C) 2002, 2003, 2005, 2006, 2007, 2008, 2011 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. # serial 1 # AM_AUTOMAKE_VERSION(VERSION) # ---------------------------- # Automake X.Y traces this macro to ensure aclocal.m4 has been # generated from the m4 files accompanying Automake X.Y. # (This private macro should not be called outside this file.) AC_DEFUN([AM_AUTOMAKE_VERSION], [am__api_version='1.11' dnl Some users find AM_AUTOMAKE_VERSION and mistake it for a way to dnl require some minimum version. Point them to the right macro. m4_if([$1], [1.11.6], [], [AC_FATAL([Do not call $0, use AM_INIT_AUTOMAKE([$1]).])])dnl ]) # _AM_AUTOCONF_VERSION(VERSION) # ----------------------------- # aclocal traces this macro to find the Autoconf version. # This is a private macro too. Using m4_define simplifies # the logic in aclocal, which can simply ignore this definition. m4_define([_AM_AUTOCONF_VERSION], []) # AM_SET_CURRENT_AUTOMAKE_VERSION # ------------------------------- # Call AM_AUTOMAKE_VERSION and AM_AUTOMAKE_VERSION so they can be traced. # This function is AC_REQUIREd by AM_INIT_AUTOMAKE. AC_DEFUN([AM_SET_CURRENT_AUTOMAKE_VERSION], [AM_AUTOMAKE_VERSION([1.11.6])dnl m4_ifndef([AC_AUTOCONF_VERSION], [m4_copy([m4_PACKAGE_VERSION], [AC_AUTOCONF_VERSION])])dnl _AM_AUTOCONF_VERSION(m4_defn([AC_AUTOCONF_VERSION]))]) # AM_AUX_DIR_EXPAND -*- Autoconf -*- # Copyright (C) 2001, 2003, 2005, 2011 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. # serial 1 # For projects using AC_CONFIG_AUX_DIR([foo]), Autoconf sets # $ac_aux_dir to `$srcdir/foo'. In other projects, it is set to # `$srcdir', `$srcdir/..', or `$srcdir/../..'. # # Of course, Automake must honor this variable whenever it calls a # tool from the auxiliary directory. The problem is that $srcdir (and # therefore $ac_aux_dir as well) can be either absolute or relative, # depending on how configure is run. This is pretty annoying, since # it makes $ac_aux_dir quite unusable in subdirectories: in the top # source directory, any form will work fine, but in subdirectories a # relative path needs to be adjusted first. # # $ac_aux_dir/missing # fails when called from a subdirectory if $ac_aux_dir is relative # $top_srcdir/$ac_aux_dir/missing # fails if $ac_aux_dir is absolute, # fails when called from a subdirectory in a VPATH build with # a relative $ac_aux_dir # # The reason of the latter failure is that $top_srcdir and $ac_aux_dir # are both prefixed by $srcdir. In an in-source build this is usually # harmless because $srcdir is `.', but things will broke when you # start a VPATH build or use an absolute $srcdir. # # So we could use something similar to $top_srcdir/$ac_aux_dir/missing, # iff we strip the leading $srcdir from $ac_aux_dir. That would be: # am_aux_dir='\$(top_srcdir)/'`expr "$ac_aux_dir" : "$srcdir//*\(.*\)"` # and then we would define $MISSING as # MISSING="\${SHELL} $am_aux_dir/missing" # This will work as long as MISSING is not called from configure, because # unfortunately $(top_srcdir) has no meaning in configure. # However there are other variables, like CC, which are often used in # configure, and could therefore not use this "fixed" $ac_aux_dir. # # Another solution, used here, is to always expand $ac_aux_dir to an # absolute PATH. The drawback is that using absolute paths prevent a # configured tree to be moved without reconfiguration. AC_DEFUN([AM_AUX_DIR_EXPAND], [dnl Rely on autoconf to set up CDPATH properly. AC_PREREQ([2.50])dnl # expand $ac_aux_dir to an absolute path am_aux_dir=`cd $ac_aux_dir && pwd` ]) # AM_CONDITIONAL -*- Autoconf -*- # Copyright (C) 1997, 2000, 2001, 2003, 2004, 2005, 2006, 2008 # 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. # serial 9 # AM_CONDITIONAL(NAME, SHELL-CONDITION) # ------------------------------------- # Define a conditional. AC_DEFUN([AM_CONDITIONAL], [AC_PREREQ(2.52)dnl ifelse([$1], [TRUE], [AC_FATAL([$0: invalid condition: $1])], [$1], [FALSE], [AC_FATAL([$0: invalid condition: $1])])dnl AC_SUBST([$1_TRUE])dnl AC_SUBST([$1_FALSE])dnl _AM_SUBST_NOTMAKE([$1_TRUE])dnl _AM_SUBST_NOTMAKE([$1_FALSE])dnl m4_define([_AM_COND_VALUE_$1], [$2])dnl if $2; then $1_TRUE= $1_FALSE='#' else $1_TRUE='#' $1_FALSE= fi AC_CONFIG_COMMANDS_PRE( [if test -z "${$1_TRUE}" && test -z "${$1_FALSE}"; then AC_MSG_ERROR([[conditional "$1" was never defined. Usually this means the macro was only invoked conditionally.]]) fi])]) # Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2009, # 2010, 2011 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. # serial 12 # There are a few dirty hacks below to avoid letting `AC_PROG_CC' be # written in clear, in which case automake, when reading aclocal.m4, # will think it sees a *use*, and therefore will trigger all it's # C support machinery. Also note that it means that autoscan, seeing # CC etc. in the Makefile, will ask for an AC_PROG_CC use... # _AM_DEPENDENCIES(NAME) # ---------------------- # See how the compiler implements dependency checking. # NAME is "CC", "CXX", "GCJ", or "OBJC". # We try a few techniques and use that to set a single cache variable. # # We don't AC_REQUIRE the corresponding AC_PROG_CC since the latter was # modified to invoke _AM_DEPENDENCIES(CC); we would have a circular # dependency, and given that the user is not expected to run this macro, # just rely on AC_PROG_CC. AC_DEFUN([_AM_DEPENDENCIES], [AC_REQUIRE([AM_SET_DEPDIR])dnl AC_REQUIRE([AM_OUTPUT_DEPENDENCY_COMMANDS])dnl AC_REQUIRE([AM_MAKE_INCLUDE])dnl AC_REQUIRE([AM_DEP_TRACK])dnl ifelse([$1], CC, [depcc="$CC" am_compiler_list=], [$1], CXX, [depcc="$CXX" am_compiler_list=], [$1], OBJC, [depcc="$OBJC" am_compiler_list='gcc3 gcc'], [$1], UPC, [depcc="$UPC" am_compiler_list=], [$1], GCJ, [depcc="$GCJ" am_compiler_list='gcc3 gcc'], [depcc="$$1" am_compiler_list=]) AC_CACHE_CHECK([dependency style of $depcc], [am_cv_$1_dependencies_compiler_type], [if test -z "$AMDEP_TRUE" && test -f "$am_depcomp"; then # We make a subdir and do the tests there. Otherwise we can end up # making bogus files that we don't know about and never remove. For # instance it was reported that on HP-UX the gcc test will end up # making a dummy file named `D' -- because `-MD' means `put the output # in D'. rm -rf conftest.dir mkdir conftest.dir # Copy depcomp to subdir because otherwise we won't find it if we're # using a relative directory. cp "$am_depcomp" conftest.dir cd conftest.dir # We will build objects and dependencies in a subdirectory because # it helps to detect inapplicable dependency modes. For instance # both Tru64's cc and ICC support -MD to output dependencies as a # side effect of compilation, but ICC will put the dependencies in # the current directory while Tru64 will put them in the object # directory. mkdir sub am_cv_$1_dependencies_compiler_type=none if test "$am_compiler_list" = ""; then am_compiler_list=`sed -n ['s/^#*\([a-zA-Z0-9]*\))$/\1/p'] < ./depcomp` fi am__universal=false m4_case([$1], [CC], [case " $depcc " in #( *\ -arch\ *\ -arch\ *) am__universal=true ;; esac], [CXX], [case " $depcc " in #( *\ -arch\ *\ -arch\ *) am__universal=true ;; esac]) for depmode in $am_compiler_list; do # Setup a source with many dependencies, because some compilers # like to wrap large dependency lists on column 80 (with \), and # we should not choose a depcomp mode which is confused by this. # # We need to recreate these files for each test, as the compiler may # overwrite some of them when testing with obscure command lines. # This happens at least with the AIX C compiler. : > sub/conftest.c for i in 1 2 3 4 5 6; do echo '#include "conftst'$i'.h"' >> sub/conftest.c # Using `: > sub/conftst$i.h' creates only sub/conftst1.h with # Solaris 8's {/usr,}/bin/sh. touch sub/conftst$i.h done echo "${am__include} ${am__quote}sub/conftest.Po${am__quote}" > confmf # We check with `-c' and `-o' for the sake of the "dashmstdout" # mode. It turns out that the SunPro C++ compiler does not properly # handle `-M -o', and we need to detect this. Also, some Intel # versions had trouble with output in subdirs am__obj=sub/conftest.${OBJEXT-o} am__minus_obj="-o $am__obj" case $depmode in gcc) # This depmode causes a compiler race in universal mode. test "$am__universal" = false || continue ;; nosideeffect) # after this tag, mechanisms are not by side-effect, so they'll # only be used when explicitly requested if test "x$enable_dependency_tracking" = xyes; then continue else break fi ;; msvc7 | msvc7msys | msvisualcpp | msvcmsys) # This compiler won't grok `-c -o', but also, the minuso test has # not run yet. These depmodes are late enough in the game, and # so weak that their functioning should not be impacted. am__obj=conftest.${OBJEXT-o} am__minus_obj= ;; none) break ;; esac if depmode=$depmode \ source=sub/conftest.c object=$am__obj \ depfile=sub/conftest.Po tmpdepfile=sub/conftest.TPo \ $SHELL ./depcomp $depcc -c $am__minus_obj sub/conftest.c \ >/dev/null 2>conftest.err && grep sub/conftst1.h sub/conftest.Po > /dev/null 2>&1 && grep sub/conftst6.h sub/conftest.Po > /dev/null 2>&1 && grep $am__obj sub/conftest.Po > /dev/null 2>&1 && ${MAKE-make} -s -f confmf > /dev/null 2>&1; then # icc doesn't choke on unknown options, it will just issue warnings # or remarks (even with -Werror). So we grep stderr for any message # that says an option was ignored or not supported. # When given -MP, icc 7.0 and 7.1 complain thusly: # icc: Command line warning: ignoring option '-M'; no argument required # The diagnosis changed in icc 8.0: # icc: Command line remark: option '-MP' not supported if (grep 'ignoring option' conftest.err || grep 'not supported' conftest.err) >/dev/null 2>&1; then :; else am_cv_$1_dependencies_compiler_type=$depmode break fi fi done cd .. rm -rf conftest.dir else am_cv_$1_dependencies_compiler_type=none fi ]) AC_SUBST([$1DEPMODE], [depmode=$am_cv_$1_dependencies_compiler_type]) AM_CONDITIONAL([am__fastdep$1], [ test "x$enable_dependency_tracking" != xno \ && test "$am_cv_$1_dependencies_compiler_type" = gcc3]) ]) # AM_SET_DEPDIR # ------------- # Choose a directory name for dependency files. # This macro is AC_REQUIREd in _AM_DEPENDENCIES AC_DEFUN([AM_SET_DEPDIR], [AC_REQUIRE([AM_SET_LEADING_DOT])dnl AC_SUBST([DEPDIR], ["${am__leading_dot}deps"])dnl ]) # AM_DEP_TRACK # ------------ AC_DEFUN([AM_DEP_TRACK], [AC_ARG_ENABLE(dependency-tracking, [ --disable-dependency-tracking speeds up one-time build --enable-dependency-tracking do not reject slow dependency extractors]) if test "x$enable_dependency_tracking" != xno; then am_depcomp="$ac_aux_dir/depcomp" AMDEPBACKSLASH='\' am__nodep='_no' fi AM_CONDITIONAL([AMDEP], [test "x$enable_dependency_tracking" != xno]) AC_SUBST([AMDEPBACKSLASH])dnl _AM_SUBST_NOTMAKE([AMDEPBACKSLASH])dnl AC_SUBST([am__nodep])dnl _AM_SUBST_NOTMAKE([am__nodep])dnl ]) # Generate code to set up dependency tracking. -*- Autoconf -*- # Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2008 # 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. #serial 5 # _AM_OUTPUT_DEPENDENCY_COMMANDS # ------------------------------ AC_DEFUN([_AM_OUTPUT_DEPENDENCY_COMMANDS], [{ # Autoconf 2.62 quotes --file arguments for eval, but not when files # are listed without --file. Let's play safe and only enable the eval # if we detect the quoting. case $CONFIG_FILES in *\'*) eval set x "$CONFIG_FILES" ;; *) set x $CONFIG_FILES ;; esac shift for mf do # Strip MF so we end up with the name of the file. mf=`echo "$mf" | sed -e 's/:.*$//'` # Check whether this is an Automake generated Makefile or not. # We used to match only the files named `Makefile.in', but # some people rename them; so instead we look at the file content. # Grep'ing the first line is not enough: some people post-process # each Makefile.in and add a new line on top of each file to say so. # Grep'ing the whole file is not good either: AIX grep has a line # limit of 2048, but all sed's we know have understand at least 4000. if sed -n 's,^#.*generated by automake.*,X,p' "$mf" | grep X >/dev/null 2>&1; then dirpart=`AS_DIRNAME("$mf")` else continue fi # Extract the definition of DEPDIR, am__include, and am__quote # from the Makefile without running `make'. DEPDIR=`sed -n 's/^DEPDIR = //p' < "$mf"` test -z "$DEPDIR" && continue am__include=`sed -n 's/^am__include = //p' < "$mf"` test -z "am__include" && continue am__quote=`sed -n 's/^am__quote = //p' < "$mf"` # When using ansi2knr, U may be empty or an underscore; expand it U=`sed -n 's/^U = //p' < "$mf"` # Find all dependency output files, they are included files with # $(DEPDIR) in their names. We invoke sed twice because it is the # simplest approach to changing $(DEPDIR) to its actual value in the # expansion. for file in `sed -n " s/^$am__include $am__quote\(.*(DEPDIR).*\)$am__quote"'$/\1/p' <"$mf" | \ sed -e 's/\$(DEPDIR)/'"$DEPDIR"'/g' -e 's/\$U/'"$U"'/g'`; do # Make sure the directory exists. test -f "$dirpart/$file" && continue fdir=`AS_DIRNAME(["$file"])` AS_MKDIR_P([$dirpart/$fdir]) # echo "creating $dirpart/$file" echo '# dummy' > "$dirpart/$file" done done } ])# _AM_OUTPUT_DEPENDENCY_COMMANDS # AM_OUTPUT_DEPENDENCY_COMMANDS # ----------------------------- # This macro should only be invoked once -- use via AC_REQUIRE. # # This code is only required when automatic dependency tracking # is enabled. FIXME. This creates each `.P' file that we will # need in order to bootstrap the dependency handling code. AC_DEFUN([AM_OUTPUT_DEPENDENCY_COMMANDS], [AC_CONFIG_COMMANDS([depfiles], [test x"$AMDEP_TRUE" != x"" || _AM_OUTPUT_DEPENDENCY_COMMANDS], [AMDEP_TRUE="$AMDEP_TRUE" ac_aux_dir="$ac_aux_dir"]) ]) # Copyright (C) 1996, 1997, 2000, 2001, 2003, 2005 # 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. # serial 8 # AM_CONFIG_HEADER is obsolete. It has been replaced by AC_CONFIG_HEADERS. AU_DEFUN([AM_CONFIG_HEADER], [AC_CONFIG_HEADERS($@)]) # Do all the work for Automake. -*- Autoconf -*- # Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, # 2005, 2006, 2008, 2009 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. # serial 16 # This macro actually does too much. Some checks are only needed if # your package does certain things. But this isn't really a big deal. # AM_INIT_AUTOMAKE(PACKAGE, VERSION, [NO-DEFINE]) # AM_INIT_AUTOMAKE([OPTIONS]) # ----------------------------------------------- # The call with PACKAGE and VERSION arguments is the old style # call (pre autoconf-2.50), which is being phased out. PACKAGE # and VERSION should now be passed to AC_INIT and removed from # the call to AM_INIT_AUTOMAKE. # We support both call styles for the transition. After # the next Automake release, Autoconf can make the AC_INIT # arguments mandatory, and then we can depend on a new Autoconf # release and drop the old call support. AC_DEFUN([AM_INIT_AUTOMAKE], [AC_PREREQ([2.62])dnl dnl Autoconf wants to disallow AM_ names. We explicitly allow dnl the ones we care about. m4_pattern_allow([^AM_[A-Z]+FLAGS$])dnl AC_REQUIRE([AM_SET_CURRENT_AUTOMAKE_VERSION])dnl AC_REQUIRE([AC_PROG_INSTALL])dnl if test "`cd $srcdir && pwd`" != "`pwd`"; then # Use -I$(srcdir) only when $(srcdir) != ., so that make's output # is not polluted with repeated "-I." AC_SUBST([am__isrc], [' -I$(srcdir)'])_AM_SUBST_NOTMAKE([am__isrc])dnl # test to see if srcdir already configured if test -f $srcdir/config.status; then AC_MSG_ERROR([source directory already configured; run "make distclean" there first]) fi fi # test whether we have cygpath if test -z "$CYGPATH_W"; then if (cygpath --version) >/dev/null 2>/dev/null; then CYGPATH_W='cygpath -w' else CYGPATH_W=echo fi fi AC_SUBST([CYGPATH_W]) # Define the identity of the package. dnl Distinguish between old-style and new-style calls. m4_ifval([$2], [m4_ifval([$3], [_AM_SET_OPTION([no-define])])dnl AC_SUBST([PACKAGE], [$1])dnl AC_SUBST([VERSION], [$2])], [_AM_SET_OPTIONS([$1])dnl dnl Diagnose old-style AC_INIT with new-style AM_AUTOMAKE_INIT. m4_if(m4_ifdef([AC_PACKAGE_NAME], 1)m4_ifdef([AC_PACKAGE_VERSION], 1), 11,, [m4_fatal([AC_INIT should be called with package and version arguments])])dnl AC_SUBST([PACKAGE], ['AC_PACKAGE_TARNAME'])dnl AC_SUBST([VERSION], ['AC_PACKAGE_VERSION'])])dnl _AM_IF_OPTION([no-define],, [AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE", [Name of package]) AC_DEFINE_UNQUOTED(VERSION, "$VERSION", [Version number of package])])dnl # Some tools Automake needs. AC_REQUIRE([AM_SANITY_CHECK])dnl AC_REQUIRE([AC_ARG_PROGRAM])dnl AM_MISSING_PROG(ACLOCAL, aclocal-${am__api_version}) AM_MISSING_PROG(AUTOCONF, autoconf) AM_MISSING_PROG(AUTOMAKE, automake-${am__api_version}) AM_MISSING_PROG(AUTOHEADER, autoheader) AM_MISSING_PROG(MAKEINFO, makeinfo) AC_REQUIRE([AM_PROG_INSTALL_SH])dnl AC_REQUIRE([AM_PROG_INSTALL_STRIP])dnl AC_REQUIRE([AM_PROG_MKDIR_P])dnl # We need awk for the "check" target. The system "awk" is bad on # some platforms. AC_REQUIRE([AC_PROG_AWK])dnl AC_REQUIRE([AC_PROG_MAKE_SET])dnl AC_REQUIRE([AM_SET_LEADING_DOT])dnl _AM_IF_OPTION([tar-ustar], [_AM_PROG_TAR([ustar])], [_AM_IF_OPTION([tar-pax], [_AM_PROG_TAR([pax])], [_AM_PROG_TAR([v7])])]) _AM_IF_OPTION([no-dependencies],, [AC_PROVIDE_IFELSE([AC_PROG_CC], [_AM_DEPENDENCIES(CC)], [define([AC_PROG_CC], defn([AC_PROG_CC])[_AM_DEPENDENCIES(CC)])])dnl AC_PROVIDE_IFELSE([AC_PROG_CXX], [_AM_DEPENDENCIES(CXX)], [define([AC_PROG_CXX], defn([AC_PROG_CXX])[_AM_DEPENDENCIES(CXX)])])dnl AC_PROVIDE_IFELSE([AC_PROG_OBJC], [_AM_DEPENDENCIES(OBJC)], [define([AC_PROG_OBJC], defn([AC_PROG_OBJC])[_AM_DEPENDENCIES(OBJC)])])dnl ]) _AM_IF_OPTION([silent-rules], [AC_REQUIRE([AM_SILENT_RULES])])dnl dnl The `parallel-tests' driver may need to know about EXEEXT, so add the dnl `am__EXEEXT' conditional if _AM_COMPILER_EXEEXT was seen. This macro dnl is hooked onto _AC_COMPILER_EXEEXT early, see below. AC_CONFIG_COMMANDS_PRE(dnl [m4_provide_if([_AM_COMPILER_EXEEXT], [AM_CONDITIONAL([am__EXEEXT], [test -n "$EXEEXT"])])])dnl ]) dnl Hook into `_AC_COMPILER_EXEEXT' early to learn its expansion. Do not dnl add the conditional right here, as _AC_COMPILER_EXEEXT may be further dnl mangled by Autoconf and run in a shell conditional statement. m4_define([_AC_COMPILER_EXEEXT], m4_defn([_AC_COMPILER_EXEEXT])[m4_provide([_AM_COMPILER_EXEEXT])]) # When config.status generates a header, we must update the stamp-h file. # This file resides in the same directory as the config header # that is generated. The stamp files are numbered to have different names. # Autoconf calls _AC_AM_CONFIG_HEADER_HOOK (when defined) in the # loop where config.status creates the headers, so we can generate # our stamp files there. AC_DEFUN([_AC_AM_CONFIG_HEADER_HOOK], [# Compute $1's index in $config_headers. _am_arg=$1 _am_stamp_count=1 for _am_header in $config_headers :; do case $_am_header in $_am_arg | $_am_arg:* ) break ;; * ) _am_stamp_count=`expr $_am_stamp_count + 1` ;; esac done echo "timestamp for $_am_arg" >`AS_DIRNAME(["$_am_arg"])`/stamp-h[]$_am_stamp_count]) # Copyright (C) 2001, 2003, 2005, 2008, 2011 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. # serial 1 # AM_PROG_INSTALL_SH # ------------------ # Define $install_sh. AC_DEFUN([AM_PROG_INSTALL_SH], [AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl if test x"${install_sh}" != xset; then case $am_aux_dir in *\ * | *\ *) install_sh="\${SHELL} '$am_aux_dir/install-sh'" ;; *) install_sh="\${SHELL} $am_aux_dir/install-sh" esac fi AC_SUBST(install_sh)]) # Copyright (C) 2003, 2005 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. # serial 2 # Check whether the underlying file-system supports filenames # with a leading dot. For instance MS-DOS doesn't. AC_DEFUN([AM_SET_LEADING_DOT], [rm -rf .tst 2>/dev/null mkdir .tst 2>/dev/null if test -d .tst; then am__leading_dot=. else am__leading_dot=_ fi rmdir .tst 2>/dev/null AC_SUBST([am__leading_dot])]) # Check to see how 'make' treats includes. -*- Autoconf -*- # Copyright (C) 2001, 2002, 2003, 2005, 2009 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. # serial 4 # AM_MAKE_INCLUDE() # ----------------- # Check to see how make treats includes. AC_DEFUN([AM_MAKE_INCLUDE], [am_make=${MAKE-make} cat > confinc << 'END' am__doit: @echo this is the am__doit target .PHONY: am__doit END # If we don't find an include directive, just comment out the code. AC_MSG_CHECKING([for style of include used by $am_make]) am__include="#" am__quote= _am_result=none # First try GNU make style include. echo "include confinc" > confmf # Ignore all kinds of additional output from `make'. case `$am_make -s -f confmf 2> /dev/null` in #( *the\ am__doit\ target*) am__include=include am__quote= _am_result=GNU ;; esac # Now try BSD make style include. if test "$am__include" = "#"; then echo '.include "confinc"' > confmf case `$am_make -s -f confmf 2> /dev/null` in #( *the\ am__doit\ target*) am__include=.include am__quote="\"" _am_result=BSD ;; esac fi AC_SUBST([am__include]) AC_SUBST([am__quote]) AC_MSG_RESULT([$_am_result]) rm -f confinc confmf ]) # Fake the existence of programs that GNU maintainers use. -*- Autoconf -*- # Copyright (C) 1997, 1999, 2000, 2001, 2003, 2004, 2005, 2008 # 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. # serial 6 # AM_MISSING_PROG(NAME, PROGRAM) # ------------------------------ AC_DEFUN([AM_MISSING_PROG], [AC_REQUIRE([AM_MISSING_HAS_RUN]) $1=${$1-"${am_missing_run}$2"} AC_SUBST($1)]) # AM_MISSING_HAS_RUN # ------------------ # Define MISSING if not defined so far and test if it supports --run. # If it does, set am_missing_run to use it, otherwise, to nothing. AC_DEFUN([AM_MISSING_HAS_RUN], [AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl AC_REQUIRE_AUX_FILE([missing])dnl if test x"${MISSING+set}" != xset; then case $am_aux_dir in *\ * | *\ *) MISSING="\${SHELL} \"$am_aux_dir/missing\"" ;; *) MISSING="\${SHELL} $am_aux_dir/missing" ;; esac fi # Use eval to expand $SHELL if eval "$MISSING --run true"; then am_missing_run="$MISSING --run " else am_missing_run= AC_MSG_WARN([`missing' script is too old or missing]) fi ]) # Copyright (C) 2003, 2004, 2005, 2006, 2011 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. # serial 1 # AM_PROG_MKDIR_P # --------------- # Check for `mkdir -p'. AC_DEFUN([AM_PROG_MKDIR_P], [AC_PREREQ([2.60])dnl AC_REQUIRE([AC_PROG_MKDIR_P])dnl dnl Automake 1.8 to 1.9.6 used to define mkdir_p. We now use MKDIR_P, dnl while keeping a definition of mkdir_p for backward compatibility. dnl @MKDIR_P@ is magic: AC_OUTPUT adjusts its value for each Makefile. dnl However we cannot define mkdir_p as $(MKDIR_P) for the sake of dnl Makefile.ins that do not define MKDIR_P, so we do our own dnl adjustment using top_builddir (which is defined more often than dnl MKDIR_P). AC_SUBST([mkdir_p], ["$MKDIR_P"])dnl case $mkdir_p in [[\\/$]]* | ?:[[\\/]]*) ;; */*) mkdir_p="\$(top_builddir)/$mkdir_p" ;; esac ]) # Helper functions for option handling. -*- Autoconf -*- # Copyright (C) 2001, 2002, 2003, 2005, 2008, 2010 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. # serial 5 # _AM_MANGLE_OPTION(NAME) # ----------------------- AC_DEFUN([_AM_MANGLE_OPTION], [[_AM_OPTION_]m4_bpatsubst($1, [[^a-zA-Z0-9_]], [_])]) # _AM_SET_OPTION(NAME) # -------------------- # Set option NAME. Presently that only means defining a flag for this option. AC_DEFUN([_AM_SET_OPTION], [m4_define(_AM_MANGLE_OPTION([$1]), 1)]) # _AM_SET_OPTIONS(OPTIONS) # ------------------------ # OPTIONS is a space-separated list of Automake options. AC_DEFUN([_AM_SET_OPTIONS], [m4_foreach_w([_AM_Option], [$1], [_AM_SET_OPTION(_AM_Option)])]) # _AM_IF_OPTION(OPTION, IF-SET, [IF-NOT-SET]) # ------------------------------------------- # Execute IF-SET if OPTION is set, IF-NOT-SET otherwise. AC_DEFUN([_AM_IF_OPTION], [m4_ifset(_AM_MANGLE_OPTION([$1]), [$2], [$3])]) # Check to make sure that the build environment is sane. -*- Autoconf -*- # Copyright (C) 1996, 1997, 2000, 2001, 2003, 2005, 2008 # 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. # serial 5 # AM_SANITY_CHECK # --------------- AC_DEFUN([AM_SANITY_CHECK], [AC_MSG_CHECKING([whether build environment is sane]) # Just in case sleep 1 echo timestamp > conftest.file # Reject unsafe characters in $srcdir or the absolute working directory # name. Accept space and tab only in the latter. am_lf=' ' case `pwd` in *[[\\\"\#\$\&\'\`$am_lf]]*) AC_MSG_ERROR([unsafe absolute working directory name]);; esac case $srcdir in *[[\\\"\#\$\&\'\`$am_lf\ \ ]]*) AC_MSG_ERROR([unsafe srcdir value: `$srcdir']);; esac # Do `set' in a subshell so we don't clobber the current shell's # arguments. Must try -L first in case configure is actually a # symlink; some systems play weird games with the mod time of symlinks # (eg FreeBSD returns the mod time of the symlink's containing # directory). if ( set X `ls -Lt "$srcdir/configure" conftest.file 2> /dev/null` if test "$[*]" = "X"; then # -L didn't work. set X `ls -t "$srcdir/configure" conftest.file` fi rm -f conftest.file if test "$[*]" != "X $srcdir/configure conftest.file" \ && test "$[*]" != "X conftest.file $srcdir/configure"; then # If neither matched, then we have a broken ls. This can happen # if, for instance, CONFIG_SHELL is bash and it inherits a # broken ls alias from the environment. This has actually # happened. Such a system could not be considered "sane". AC_MSG_ERROR([ls -t appears to fail. Make sure there is not a broken alias in your environment]) fi test "$[2]" = conftest.file ) then # Ok. : else AC_MSG_ERROR([newly created file is older than distributed files! Check your system clock]) fi AC_MSG_RESULT(yes)]) # Copyright (C) 2001, 2003, 2005, 2011 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. # serial 1 # AM_PROG_INSTALL_STRIP # --------------------- # One issue with vendor `install' (even GNU) is that you can't # specify the program used to strip binaries. This is especially # annoying in cross-compiling environments, where the build's strip # is unlikely to handle the host's binaries. # Fortunately install-sh will honor a STRIPPROG variable, so we # always use install-sh in `make install-strip', and initialize # STRIPPROG with the value of the STRIP variable (set by the user). AC_DEFUN([AM_PROG_INSTALL_STRIP], [AC_REQUIRE([AM_PROG_INSTALL_SH])dnl # Installed binaries are usually stripped using `strip' when the user # run `make install-strip'. However `strip' might not be the right # tool to use in cross-compilation environments, therefore Automake # will honor the `STRIP' environment variable to overrule this program. dnl Don't test for $cross_compiling = yes, because it might be `maybe'. if test "$cross_compiling" != no; then AC_CHECK_TOOL([STRIP], [strip], :) fi INSTALL_STRIP_PROGRAM="\$(install_sh) -c -s" AC_SUBST([INSTALL_STRIP_PROGRAM])]) # Copyright (C) 2006, 2008, 2010 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. # serial 3 # _AM_SUBST_NOTMAKE(VARIABLE) # --------------------------- # Prevent Automake from outputting VARIABLE = @VARIABLE@ in Makefile.in. # This macro is traced by Automake. AC_DEFUN([_AM_SUBST_NOTMAKE]) # AM_SUBST_NOTMAKE(VARIABLE) # -------------------------- # Public sister of _AM_SUBST_NOTMAKE. AC_DEFUN([AM_SUBST_NOTMAKE], [_AM_SUBST_NOTMAKE($@)]) # Check how to create a tarball. -*- Autoconf -*- # Copyright (C) 2004, 2005, 2012 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. # serial 2 # _AM_PROG_TAR(FORMAT) # -------------------- # Check how to create a tarball in format FORMAT. # FORMAT should be one of `v7', `ustar', or `pax'. # # Substitute a variable $(am__tar) that is a command # writing to stdout a FORMAT-tarball containing the directory # $tardir. # tardir=directory && $(am__tar) > result.tar # # Substitute a variable $(am__untar) that extract such # a tarball read from stdin. # $(am__untar) < result.tar AC_DEFUN([_AM_PROG_TAR], [# Always define AMTAR for backward compatibility. Yes, it's still used # in the wild :-( We should find a proper way to deprecate it ... AC_SUBST([AMTAR], ['$${TAR-tar}']) m4_if([$1], [v7], [am__tar='$${TAR-tar} chof - "$$tardir"' am__untar='$${TAR-tar} xf -'], [m4_case([$1], [ustar],, [pax],, [m4_fatal([Unknown tar format])]) AC_MSG_CHECKING([how to create a $1 tar archive]) # Loop over all known methods to create a tar archive until one works. _am_tools='gnutar m4_if([$1], [ustar], [plaintar]) pax cpio none' _am_tools=${am_cv_prog_tar_$1-$_am_tools} # Do not fold the above two line into one, because Tru64 sh and # Solaris sh will not grok spaces in the rhs of `-'. for _am_tool in $_am_tools do case $_am_tool in gnutar) for _am_tar in tar gnutar gtar; do AM_RUN_LOG([$_am_tar --version]) && break done am__tar="$_am_tar --format=m4_if([$1], [pax], [posix], [$1]) -chf - "'"$$tardir"' am__tar_="$_am_tar --format=m4_if([$1], [pax], [posix], [$1]) -chf - "'"$tardir"' am__untar="$_am_tar -xf -" ;; plaintar) # Must skip GNU tar: if it does not support --format= it doesn't create # ustar tarball either. (tar --version) >/dev/null 2>&1 && continue am__tar='tar chf - "$$tardir"' am__tar_='tar chf - "$tardir"' am__untar='tar xf -' ;; pax) am__tar='pax -L -x $1 -w "$$tardir"' am__tar_='pax -L -x $1 -w "$tardir"' am__untar='pax -r' ;; cpio) am__tar='find "$$tardir" -print | cpio -o -H $1 -L' am__tar_='find "$tardir" -print | cpio -o -H $1 -L' am__untar='cpio -i -H $1 -d' ;; none) am__tar=false am__tar_=false am__untar=false ;; esac # If the value was cached, stop now. We just wanted to have am__tar # and am__untar set. test -n "${am_cv_prog_tar_$1}" && break # tar/untar a dummy directory, and stop if the command works rm -rf conftest.dir mkdir conftest.dir echo GrepMe > conftest.dir/file AM_RUN_LOG([tardir=conftest.dir && eval $am__tar_ >conftest.tar]) rm -rf conftest.dir if test -s conftest.tar; then AM_RUN_LOG([$am__untar /dev/null 2>&1 && break fi done rm -rf conftest.dir AC_CACHE_VAL([am_cv_prog_tar_$1], [am_cv_prog_tar_$1=$_am_tool]) AC_MSG_RESULT([$am_cv_prog_tar_$1])]) AC_SUBST([am__tar]) AC_SUBST([am__untar]) ]) # _AM_PROG_TAR m4_include([acinclude.m4]) sftpserver-0.2.1/putword.h0000664000175000017500000000745312340115006012516 00000000000000/* * This file is part of the Green End SFTP Server. * Copyright (C) 2007, 2011, 2014 Richard Kettlewell * * 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 2 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, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA */ /** @file putword.h @brief Macros for storing network-order values */ #ifndef PUTWORD_H #define PUTWORD_H #include #ifndef ASM # define ASM 1 #endif /** @brief Unaligned 16-bit network-order store * @param where Where to store value * @param u Value to store */ static inline void put16(void *where, uint16_t u) { #if (__i386__ || __amd64__) && __GNUC__ && ASM __asm__ volatile("xchg %h[U],%b[U]\n\tmovw %[U],%[WHERE]" : [U] "+Q" (u) : [WHERE] "m" (*(uint16_t *)where)); #else uint8_t *ptr = where; *ptr++ = (uint8_t)(u >> 8); *ptr = (uint8_t)u; #endif } /** @brief Unaligned 32-bit network-order store * @param where Where to store value * @param u Value to store */ static inline void put32(void *where, uint32_t u) { #if (__i386__ || __amd64__) && __GNUC__ && ASM __asm__ volatile("bswapl %[U]\n\tmovl %[U],%[WHERE]" : [U] "+r" (u) : [WHERE] "m" (*(uint32_t *)where)); #else uint8_t *ptr = where; *ptr++ = (uint8_t)(u >> 24); *ptr++ = (uint8_t)(u >> 16); *ptr++ = (uint8_t)(u >> 8); *ptr++ = (uint8_t)(u); #endif } /** @brief Unaligned 64-bit network-order store * @param where Where to store value * @param u Value to store */ static inline void put64(void *where, uint64_t u) { #if __amd64__ && __GNUC__ && ASM __asm__ volatile("bswapq %[U]\n\tmovq %[U],%[WHERE]" : [U] "+r" (u) : [WHERE] "m" (*(uint64_t *)where)); #else put32(where, u >> 32); put32((char *)where + 4, (uint32_t)u); #endif } /** @brief Unaligned 16-bit network-order fetch * @param where Where to fetch from * @return Fetched value */ static inline uint16_t get16(const void *where) { #if (__i386__ || __amd64__) && __GNUC__ && ASM uint16_t r; __asm__("movw %[WHERE],%[R]\t\nxchg %h[R],%b[R]" : [R] "=Q" (r) : [WHERE] "m" (*(const uint16_t *)where)); return r; #else const uint8_t *ptr = where; return (ptr[0] << 8) + ptr[1]; #endif } /** @brief Unaligned 32-bit network-order fetch * @param where Where to fetch from * @return Fetched value */ static inline uint32_t get32(const void *where) { #if (__i386__ || __amd64__) && __GNUC__ && ASM uint32_t r; __asm__("movl %[WHERE],%[R]\n\tbswapl %[R]" : [R] "=r" (r) : [WHERE] "m" (*(const uint32_t *)where)); return r; #else const uint8_t *ptr = where; return ((unsigned)ptr[0] << 24) + (ptr[1] << 16) + (ptr[2] << 8) + ptr[3]; #endif } /** @brief Unaligned 64-bit network-order fetch * @param where Where to fetch from * @return Fetched value */ static inline uint64_t get64(const void *where) { #if __amd64__ && __GNUC__ && ASM uint64_t r; __asm__("movq %[WHERE],%[R]\n\tbswapq %[R]" : [R] "=r" (r) : [WHERE] "m" (*(const uint64_t *)where)); return r; #else return ((uint64_t)get32(where) << 32) + get32((const char *)where + 4); #endif } #endif /* PUTWORD_H */ /* Local Variables: c-basic-offset:2 comment-column:40 fill-column:79 indent-tabs-mode:nil End: */ sftpserver-0.2.1/dirname.c0000664000175000017500000000255611625765051012443 00000000000000/* * This file is part of the Green End SFTP Server. * Copyright (C) 2007 Richard Kettlewell * * 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 2 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, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA */ #include "sftpcommon.h" #include "alloc.h" #include "debug.h" #include "utils.h" #include #include const char *sftp_dirname(struct allocator *a, const char *path) { const char *ls = strrchr(path, '/'); if(ls) { if(ls != path) { const size_t len = ls - path; char *d; assert(len + 1 != 0); d = sftp_alloc(a, len + 1); memcpy(d, path, len); return d; } else return "/"; } else return "."; } /* Local Variables: c-basic-offset:2 comment-column:40 fill-column:79 indent-tabs-mode:nil End: */ sftpserver-0.2.1/v4.c0000664000175000017500000002520211625765051011346 00000000000000/* * This file is part of the Green End SFTP Server. * Copyright (C) 2007 Richard Kettlewell * * 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 2 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, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA */ #include "sftpserver.h" #include "types.h" #include "sftp.h" #include "parse.h" #include "send.h" #include "charset.h" #include "globals.h" #include "debug.h" #include "stat.h" #include "handle.h" #include "serialize.h" #include int sftp_v456_encode(struct sftpjob *job, char **path) { /* Translate local to UTF-8 */ return sftp_iconv(job->a, job->worker->local_to_utf8, path); } uint32_t sftp_v456_decode(struct sftpjob *job, char **path) { /* Translate UTF-8 to local */ if(sftp_iconv(job->a, job->worker->utf8_to_local, path)) return SSH_FX_INVALID_FILENAME; else return SSH_FX_OK; } void sftp_v456_sendattrs(struct sftpjob *job, const struct sftpattr *attrs) { const uint32_t valid = attrs->valid & protocol->attrmask; sftp_send_uint32(job->worker, valid); sftp_send_uint8(job->worker, attrs->type); if(valid & SSH_FILEXFER_ATTR_SIZE) sftp_send_uint64(job->worker, attrs->size); if(valid & SSH_FILEXFER_ATTR_OWNERGROUP) { sftp_send_path(job, job->worker, attrs->owner); sftp_send_path(job, job->worker, attrs->group); } if(valid & SSH_FILEXFER_ATTR_PERMISSIONS) sftp_send_uint32(job->worker, attrs->permissions); /* lftp 3.1.3 expects subsecond time fields even if the corresonding time is * absent. It sends no identifying information so we cannot enable a * workaround for this bizarre bug. lftp 3.5.9 gets this right as does * WinSCP. */ if(valid & SSH_FILEXFER_ATTR_ACCESSTIME) { sftp_send_uint64(job->worker, attrs->atime.seconds); if(valid & SSH_FILEXFER_ATTR_SUBSECOND_TIMES) sftp_send_uint32(job->worker, attrs->atime.nanoseconds); } if(valid & SSH_FILEXFER_ATTR_CREATETIME) { sftp_send_uint64(job->worker, attrs->createtime.seconds); if(valid & SSH_FILEXFER_ATTR_SUBSECOND_TIMES) sftp_send_uint32(job->worker, attrs->createtime.nanoseconds); } if(valid & SSH_FILEXFER_ATTR_MODIFYTIME) { sftp_send_uint64(job->worker, attrs->mtime.seconds); if(valid & SSH_FILEXFER_ATTR_SUBSECOND_TIMES) sftp_send_uint32(job->worker, attrs->mtime.nanoseconds); } if(valid & SSH_FILEXFER_ATTR_CTIME) { sftp_send_uint64(job->worker, attrs->ctime.seconds); if(valid & SSH_FILEXFER_ATTR_SUBSECOND_TIMES) sftp_send_uint32(job->worker, attrs->ctime.nanoseconds); } if(valid & SSH_FILEXFER_ATTR_ACL) { sftp_send_string(job->worker, attrs->acl); } if(valid & SSH_FILEXFER_ATTR_BITS) { sftp_send_uint32(job->worker, attrs->attrib_bits); if(protocol->version >= 6) sftp_send_uint32(job->worker, attrs->attrib_bits_valid); } if(valid & SSH_FILEXFER_ATTR_TEXT_HINT) { sftp_send_uint8(job->worker, attrs->text_hint); } if(valid & SSH_FILEXFER_ATTR_MIME_TYPE) { sftp_send_string(job->worker, attrs->mime_type); } if(valid & SSH_FILEXFER_ATTR_LINK_COUNT) { sftp_send_uint32(job->worker, attrs->link_count); } /* We don't implement untranslated-name yet */ } uint32_t sftp_v456_parseattrs(struct sftpjob *job, struct sftpattr *attrs) { uint32_t n, rc; memset(attrs, 0, sizeof *attrs); if((rc = sftp_parse_uint32(job, &attrs->valid)) != SSH_FX_OK) return rc; if((rc = sftp_parse_uint8(job, &attrs->type)) != SSH_FX_OK) return rc; if(attrs->valid & SSH_FILEXFER_ATTR_SIZE) if((rc = sftp_parse_uint64(job, &attrs->size)) != SSH_FX_OK) return rc; if(attrs->valid & SSH_FILEXFER_ATTR_OWNERGROUP) { if((rc = sftp_parse_path(job, &attrs->owner)) != SSH_FX_OK) return rc; if((rc = sftp_parse_path(job, &attrs->group)) != SSH_FX_OK) return rc; } if(attrs->valid & SSH_FILEXFER_ATTR_PERMISSIONS) { if((rc = sftp_parse_uint32(job, &attrs->permissions)) != SSH_FX_OK) return rc; } if(attrs->valid & SSH_FILEXFER_ATTR_ACCESSTIME) { if((rc = sftp_parse_uint64(job, (uint64_t *)&attrs->atime.seconds)) != SSH_FX_OK) return rc; if(attrs->valid & SSH_FILEXFER_ATTR_SUBSECOND_TIMES) if((rc = sftp_parse_uint32(job, &attrs->atime.nanoseconds)) != SSH_FX_OK) return rc; } if(attrs->valid & SSH_FILEXFER_ATTR_CREATETIME) { if((rc = sftp_parse_uint64(job, (uint64_t *)&attrs->createtime.seconds)) != SSH_FX_OK) return rc; if(attrs->valid & SSH_FILEXFER_ATTR_SUBSECOND_TIMES) if((rc = sftp_parse_uint32(job, &attrs->createtime.nanoseconds)) != SSH_FX_OK) return rc; } if(attrs->valid & SSH_FILEXFER_ATTR_MODIFYTIME) { if((rc = sftp_parse_uint64(job, (uint64_t *)&attrs->mtime.seconds)) != SSH_FX_OK) return rc; if(attrs->valid & SSH_FILEXFER_ATTR_SUBSECOND_TIMES) if((rc = sftp_parse_uint32(job, &attrs->mtime.nanoseconds)) != SSH_FX_OK) return rc; } if(attrs->valid & SSH_FILEXFER_ATTR_CTIME) { if((rc = sftp_parse_uint64(job, (uint64_t *)&attrs->ctime.seconds)) != SSH_FX_OK) return rc; if(attrs->valid & SSH_FILEXFER_ATTR_SUBSECOND_TIMES) if((rc = sftp_parse_uint32(job, &attrs->ctime.nanoseconds)) != SSH_FX_OK) return rc; } if(attrs->valid & SSH_FILEXFER_ATTR_ACL) { if((rc = sftp_parse_string(job, &attrs->acl, 0)) != SSH_FX_OK) return rc; } if(attrs->valid & SSH_FILEXFER_ATTR_BITS) { if((rc = sftp_parse_uint32(job, &attrs->attrib_bits)) != SSH_FX_OK) return rc; if(protocol->version >= 6) { if((rc = sftp_parse_uint32(job, &attrs->attrib_bits_valid)) != SSH_FX_OK) return rc; } else attrs->attrib_bits_valid = 0x7ff; /* -05 s5.8 */ } if(attrs->valid & SSH_FILEXFER_ATTR_TEXT_HINT) { if((rc = sftp_parse_uint8(job, &attrs->text_hint)) != SSH_FX_OK) return rc; } if(attrs->valid & SSH_FILEXFER_ATTR_MIME_TYPE) { if((rc = sftp_parse_string(job, &attrs->mime_type, 0)) != SSH_FX_OK) return rc; } if(attrs->valid & SSH_FILEXFER_ATTR_LINK_COUNT) { if((rc = sftp_parse_uint32(job, &attrs->link_count)) != SSH_FX_OK) return rc; } if(attrs->valid & SSH_FILEXFER_ATTR_UNTRANSLATED_NAME) { if((rc = sftp_parse_string(job, &attrs->mime_type, 0)) != SSH_FX_OK) return rc; } if(attrs->valid & SSH_FILEXFER_ATTR_EXTENDED) { if((rc = sftp_parse_uint32(job, &n)) != SSH_FX_OK) return rc; while(n-- > 0) { if((rc = sftp_parse_string(job, 0, 0)) != SSH_FX_OK) return rc; if((rc = sftp_parse_string(job, 0, 0)) != SSH_FX_OK) return rc; } } return SSH_FX_OK; } /* Send a filename list as found in an SSH_FXP_NAME response. The response * header and so on must be generated by the caller. */ void sftp_v456_sendnames(struct sftpjob *job, int nnames, const struct sftpattr *names) { /* We'd like to know what year we're in for dates in longname */ sftp_send_uint32(job->worker, nnames); while(nnames > 0) { sftp_send_path(job, job->worker, names->name); protocol->sendattrs(job, names); ++names; --nnames; } } /* Command code for the various _*STAT calls. rc is the return value * from *stat() and SB is the buffer. */ static uint32_t sftp_v456_stat_core(struct sftpjob *job, int rc, const struct stat *sb, const char *path) { struct sftpattr attrs; uint32_t flags; if(!rc) { pcheck(sftp_parse_uint32(job, &flags)); sftp_stat_to_attrs(job->a, sb, &attrs, flags, path); sftp_send_begin(job->worker); sftp_send_uint8(job->worker, SSH_FXP_ATTRS); sftp_send_uint32(job->worker, job->id); protocol->sendattrs(job, &attrs); sftp_send_end(job->worker); return HANDLER_RESPONDED; } else return HANDLER_ERRNO; } uint32_t sftp_v456_lstat(struct sftpjob *job) { char *path; struct stat sb; pcheck(sftp_parse_path(job, &path)); D(("sftp_lstat %s", path)); return sftp_v456_stat_core(job, lstat(path, &sb), &sb, path); } uint32_t sftp_v456_stat(struct sftpjob *job) { char *path; struct stat sb; pcheck(sftp_parse_path(job, &path)); D(("sftp_stat %s", path)); return sftp_v456_stat_core(job, stat(path, &sb), &sb, path); } uint32_t sftp_v456_fstat(struct sftpjob *job) { int fd; struct handleid id; struct stat sb; uint32_t rc; pcheck(sftp_parse_handle(job, &id)); D(("sftp_fstat %"PRIu32" %"PRIu32, id.id, id.tag)); if((rc = sftp_handle_get_fd(&id, &fd, 0))) return rc; return sftp_v456_stat_core(job, fstat(fd, &sb), &sb, 0); } static const struct sftpcmd sftpv4tab[] = { { SSH_FXP_INIT, sftp_vany_already_init }, { SSH_FXP_OPEN, sftp_v34_open }, { SSH_FXP_CLOSE, sftp_vany_close }, { SSH_FXP_READ, sftp_vany_read }, { SSH_FXP_WRITE, sftp_vany_write }, { SSH_FXP_LSTAT, sftp_v456_lstat }, { SSH_FXP_FSTAT, sftp_v456_fstat }, { SSH_FXP_SETSTAT, sftp_vany_setstat }, { SSH_FXP_FSETSTAT, sftp_vany_fsetstat }, { SSH_FXP_OPENDIR, sftp_vany_opendir }, { SSH_FXP_READDIR, sftp_vany_readdir }, { SSH_FXP_REMOVE, sftp_vany_remove }, { SSH_FXP_MKDIR, sftp_vany_mkdir }, { SSH_FXP_RMDIR, sftp_vany_rmdir }, { SSH_FXP_REALPATH, sftp_v345_realpath }, { SSH_FXP_STAT, sftp_v456_stat }, { SSH_FXP_RENAME, sftp_v34_rename }, { SSH_FXP_READLINK, sftp_vany_readlink }, { SSH_FXP_SYMLINK, sftp_v345_symlink }, { SSH_FXP_EXTENDED, sftp_vany_extended } }; static const struct sftpextension v4_extensions[] = { { "posix-rename@openssh.org", sftp_vany_posix_rename }, { "space-available", sftp_vany_space_available }, { "statfs@openssh.org", sftp_vany_statfs }, { "text-seek", sftp_vany_text_seek }, }; const struct sftpprotocol sftp_v4 = { sizeof sftpv4tab / sizeof (struct sftpcmd), sftpv4tab, 4, (SSH_FILEXFER_ATTR_SIZE |SSH_FILEXFER_ATTR_PERMISSIONS |SSH_FILEXFER_ATTR_ACCESSTIME |SSH_FILEXFER_ATTR_MODIFYTIME |SSH_FILEXFER_ATTR_OWNERGROUP |SSH_FILEXFER_ATTR_SUBSECOND_TIMES), SSH_FX_NO_MEDIA, sftp_v456_sendnames, sftp_v456_sendattrs, sftp_v456_parseattrs, sftp_v456_encode, sftp_v456_decode, sizeof v4_extensions / sizeof (struct sftpextension), v4_extensions, /* extensions */ }; /* Local Variables: c-basic-offset:2 comment-column:40 fill-column:79 indent-tabs-mode:nil End: */ sftpserver-0.2.1/status.c0000664000175000017500000001302311626705056012336 00000000000000/* * This file is part of the Green End SFTP Server. * Copyright (C) 2007, 2011 Richard Kettlewell * * 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 2 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, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA */ /** @file status.c @brief Status code implementation */ #include "sftpserver.h" #include "sftp.h" #include "send.h" #include "types.h" #include "globals.h" #include #include #include const char *status_to_string(uint32_t status) { switch(status) { case SSH_FX_OK: return "OK"; case SSH_FX_EOF: return "end of file"; case SSH_FX_NO_SUCH_FILE: return "file does not exist"; case SSH_FX_PERMISSION_DENIED: return "permission denied"; case SSH_FX_FAILURE: return "operation failed"; case SSH_FX_BAD_MESSAGE: return "badly encoded SFTP packet"; case SSH_FX_NO_CONNECTION: return "no connection"; case SSH_FX_CONNECTION_LOST: return "connection lost"; case SSH_FX_OP_UNSUPPORTED: return "operation not supported"; case SSH_FX_INVALID_HANDLE: return "invalid handle"; case SSH_FX_NO_SUCH_PATH: return "path does not exist or is invalid"; case SSH_FX_FILE_ALREADY_EXISTS: return "file already exists"; case SSH_FX_WRITE_PROTECT: return "file is on read-only medium"; case SSH_FX_NO_MEDIA: return "no medium in drive"; case SSH_FX_NO_SPACE_ON_FILESYSTEM: return "no space on filesystem"; case SSH_FX_QUOTA_EXCEEDED: return "quota exceeded"; case SSH_FX_UNKNOWN_PRINCIPAL: return "unknown principal"; case SSH_FX_LOCK_CONFLICT: return "file is locked"; case SSH_FX_DIR_NOT_EMPTY: return "directory is not empty"; case SSH_FX_NOT_A_DIRECTORY: return "file is not a directory"; case SSH_FX_INVALID_FILENAME: return "invalid filename"; case SSH_FX_LINK_LOOP: return "too many symbolic links"; case SSH_FX_CANNOT_DELETE: return "file cannot be deleted"; case SSH_FX_INVALID_PARAMETER: return "invalid parameter"; case SSH_FX_FILE_IS_A_DIRECTORY: return "file is a directory"; case SSH_FX_BYTE_RANGE_LOCK_CONFLICT: return "byte range is locked"; case SSH_FX_BYTE_RANGE_LOCK_REFUSED: return "cannot lock byte range"; case SSH_FX_DELETE_PENDING: return "file deletion pending"; case SSH_FX_FILE_CORRUPT: return "file is corrupt"; case SSH_FX_OWNER_INVALID: return "invalid owner"; case SSH_FX_GROUP_INVALID: return "invalid group"; case SSH_FX_NO_MATCHING_BYTE_RANGE_LOCK: return "no such lock"; default: return "unknown status"; } } void sftp_send_status(struct sftpjob *job, uint32_t status, const char *msg) { if(status == HANDLER_ERRNO) { /* Bodge to allow us to treat -1 as a magical status meaning 'consult * errno'. This goes back via the protocol-specific status callback, so * statuses out of range for the current protocol version get properly * laundered. */ sftp_send_errno_status(job); return; } /* If there is no message, fill one in */ if(!msg) msg = status_to_string(status); /* Limit to status values known to this version of the protocol */ if(status > protocol->maxstatus) { switch(status) { case SSH_FX_INVALID_FILENAME: status = SSH_FX_BAD_MESSAGE; break; case SSH_FX_NO_SUCH_PATH: status = SSH_FX_NO_SUCH_FILE; break; default: status = SSH_FX_FAILURE; break; } } sftp_send_begin(job->worker); sftp_send_uint8(job->worker, SSH_FXP_STATUS); sftp_send_uint32(job->worker, job->id); sftp_send_uint32(job->worker, status); sftp_send_path(job, job->worker, msg); /* needs to be UTF-8 */ /* We are not I18N'd yet. Doing so will require the following: * - determine an RFC1766 interpretation of the current LC_MESSAGES * setting * - set LC_MESSAGES in setlocale() * - send the right tag for messages from strerror() * - _if_ we have a localization for one of our own messages, send the * right tag (otherwise still send "en") */ sftp_send_string(job->worker, "en"); sftp_send_end(job->worker); } /** @brief Mapping of @c errno values to SFTP status codes */ static const struct { int errno_value; uint32_t status_value; } errnotab[] = { { 0, SSH_FX_OK }, { EPERM, SSH_FX_PERMISSION_DENIED }, { EACCES, SSH_FX_PERMISSION_DENIED }, { ENOENT, SSH_FX_NO_SUCH_FILE }, { EIO, SSH_FX_FILE_CORRUPT }, { ENOSPC, SSH_FX_NO_SPACE_ON_FILESYSTEM }, { ENOTDIR, SSH_FX_NOT_A_DIRECTORY }, { EISDIR, SSH_FX_FILE_IS_A_DIRECTORY }, { EEXIST, SSH_FX_FILE_ALREADY_EXISTS }, { EROFS, SSH_FX_WRITE_PROTECT }, { ELOOP, SSH_FX_LINK_LOOP }, { ENAMETOOLONG, SSH_FX_INVALID_FILENAME }, { ENOTEMPTY, SSH_FX_DIR_NOT_EMPTY }, { EDQUOT, SSH_FX_QUOTA_EXCEEDED }, { -1, SSH_FX_FAILURE }, }; void sftp_send_errno_status(struct sftpjob *job) { int n; const int errno_value = errno; for(n = 0; errnotab[n].errno_value != errno_value && errnotab[n].errno_value != -1; ++n) ; sftp_send_status(job, errnotab[n].status_value, strerror(errno_value)); } /* Local Variables: c-basic-offset:2 comment-column:40 fill-column:79 indent-tabs-mode:nil End: */ sftpserver-0.2.1/config.h.in0000664000175000017500000001112212415610061012654 00000000000000/* config.h.in. Generated from configure.ac by autoheader. */ /* Define if building universal (internal helper macro) */ #undef AC_APPLE_UNIVERSAL_BUILD /* define to enable daemon mode */ #undef DAEMON /* Define to 1 if you have the `daemon' function. */ #undef HAVE_DAEMON /* Define to 1 if you have the declaration of `be64toh', and to 0 if you don't. */ #undef HAVE_DECL_BE64TOH /* Define to 1 if you have the declaration of `htobe64', and to 0 if you don't. */ #undef HAVE_DECL_HTOBE64 /* Define to 1 if you have the header file. */ #undef HAVE_ENDIAN_H /* Define to 1 if you have the `futimes' function. */ #undef HAVE_FUTIMES /* Define to 1 if you have the `futimesat' function. */ #undef HAVE_FUTIMESAT /* Define to 1 if you have the `getaddrinfo' function. */ #undef HAVE_GETADDRINFO /* Define to 1 if you have the header file. */ #undef HAVE_INTTYPES_H /* Define to 1 if you have the `iconv' library (-liconv). */ #undef HAVE_LIBICONV /* Define to 1 if you have the `pthread' library (-lpthread). */ #undef HAVE_LIBPTHREAD /* Define to 1 if you have the `socket' library (-lsocket). */ #undef HAVE_LIBSOCKET /* Define to 1 if you have the header file. */ #undef HAVE_MEMORY_H /* Define to 1 if you have the `prctl' function. */ #undef HAVE_PRCTL /* define if you have a readline library */ #undef HAVE_READLINE /* define if you have SIZE_MAX */ #undef HAVE_SIZE_MAX /* define if struct stat uses struct timespec */ #undef HAVE_STAT_TIMESPEC /* Define to 1 if you have the header file. */ #undef HAVE_STDINT_H /* Define to 1 if you have the header file. */ #undef HAVE_STDLIB_H /* Define to 1 if you have the header file. */ #undef HAVE_STRINGS_H /* Define to 1 if you have the header file. */ #undef HAVE_STRING_H /* Define to 1 if you have the header file. */ #undef HAVE_SYS_PRCTL_H /* Define to 1 if you have the header file. */ #undef HAVE_SYS_STAT_H /* Define to 1 if you have the header file. */ #undef HAVE_SYS_TYPES_H /* Define to 1 if you have the header file. */ #undef HAVE_UNISTD_H /* Name of package */ #undef PACKAGE /* Define to the address where bug reports for this package should be sent. */ #undef PACKAGE_BUGREPORT /* Define to the full name of this package. */ #undef PACKAGE_NAME /* Define to the full name and version of this package. */ #undef PACKAGE_STRING /* Define to the one symbol short name of this package. */ #undef PACKAGE_TARNAME /* Define to the home page for this package. */ #undef PACKAGE_URL /* Define to the version of this package. */ #undef PACKAGE_VERSION /* define to reverse SSH_FXP_SYMLINK args */ #undef REVERSE_SYMLINK /* The size of `size_t', as computed by sizeof. */ #undef SIZEOF_SIZE_T /* The size of `unsigned int', as computed by sizeof. */ #undef SIZEOF_UNSIGNED_INT /* The size of `unsigned long', as computed by sizeof. */ #undef SIZEOF_UNSIGNED_LONG /* The size of `unsigned long long', as computed by sizeof. */ #undef SIZEOF_UNSIGNED_LONG_LONG /* The size of `unsigned short', as computed by sizeof. */ #undef SIZEOF_UNSIGNED_SHORT /* Define to 1 if you have the ANSI C header files. */ #undef STDC_HEADERS /* Version number of package */ #undef VERSION /* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most significant byte first (like Motorola and SPARC, unlike Intel). */ #if defined AC_APPLE_UNIVERSAL_BUILD # if defined __BIG_ENDIAN__ # define WORDS_BIGENDIAN 1 # endif #else # ifndef WORDS_BIGENDIAN # undef WORDS_BIGENDIAN # endif #endif /* Enable large inode numbers on Mac OS X 10.5. */ #ifndef _DARWIN_USE_64_BIT_INODE # define _DARWIN_USE_64_BIT_INODE 1 #endif /* Number of bits in a file offset, on hosts where this is settable. */ #undef _FILE_OFFSET_BITS /* required for e.g. strsignal */ #undef _GNU_SOURCE /* Define for large files, on AIX-style hosts. */ #undef _LARGE_FILES /* define for re-entrant functions */ #undef _REENTRANT /* Define to `__inline__' or `__inline' if that's what the C compiler calls it, or to nothing if 'inline' is not supported under any name. */ #ifndef __cplusplus #undef inline #endif #if ! HAVE_SIZE_MAX # if SIZEOF_SIZE_T == SIZEOF_UNSIGNED_SHORT # define SIZE_MAX USHRT_MAX # elif SIZEOF_SIZE_T == SIZEOF_UNSIGNED_INT # define SIZE_MAX UINT_MAX # elif SIZEOF_SIZE_T == SIZEOF_UNSIGNED_LONG # define SIZE_MAX ULONG_MAX # elif SIZEOF_SIZE_T == SIZEOF_UNSIGNED_LONG_LONG # define SIZE_MAX ULLONG_MAX # else # error Cannot deduce SIZE_MAX # endif #endif #ifdef __GNUC__ # define attribute(x) __attribute__(x) #else # define attribute(x) #endif sftpserver-0.2.1/types.h0000664000175000017500000002131011626705056012162 00000000000000/* * This file is part of the Green End SFTP Server. * Copyright (C) 2007, 2011 Richard Kettlewell * * 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 2 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, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA */ /** @file types.h @brief Data types */ #ifndef TYPES_H #define TYPES_H #include #include #include /** @brief An SFTP timestamp */ struct sftptime { /** @brief Seconds since Jan 1 1970 UTC * * Presumably excludes leap-seconds per usual Unix convention. */ int64_t seconds; /** @brief Nanoseconds * * May be forced to 0 if the implementation does not support high-resolution * file timestamps. */ uint32_t nanoseconds; }; /** @brief SFTP file attributes * * In this structure V6-compatible definitions are used; particular protocol * implementations must convert when (de-)serializing. Many of the fields are * only valid if an appropriate bit is set in the @c valid field. */ struct sftpattr { /** @brief Validity mask * * Present in all versions, but the V6 bit values are always used here. See * @ref valid_attribute_flags for a list of bits. */ uint32_t valid; /** @brief File type * * Always valid. See @ref file_type for a list of bits. */ uint8_t type; /** @brief File size * * Only if @ref SSH_FILEXFER_ATTR_SIZE is set. */ uint64_t size; /** @brief Allocation size (i.e. total bytes consumed) * * Only v6+, only if @ref SSH_FILEXFER_ATTR_ALLOCATION_SIZE is set. */ uint64_t allocation_size; /** @brief File owner UID * * Only v3. */ uint32_t uid; /** @brief File group GID * * Only v3. */ uint32_t gid; /** @brief File owner name * * Only v4+, only if @ref SSH_FILEXFER_ATTR_OWNERGROUP is set. */ char *owner; /** @brief File group name * * Only v4+, only if @ref SSH_FILEXFER_ATTR_OWNERGROUP is set. */ char *group; /** @brief File permissions * * Only if @ref SSH_FILEXFER_ATTR_PERMISSIONS is set. See @ref permissions * for a list of bits. */ uint32_t permissions; /** @brief File access time * * Only if @ref SSH_FILEXFER_ATTR_ACCESSTIME is set. */ struct sftptime atime; /** @brief File create time * * Only v4+, only if @ref SSH_FILEXFER_ATTR_CREATETIME is set. */ struct sftptime createtime; /** @brief File modification time * * Only if @ref SSH_FILEXFER_ATTR_MODIFYTIME is set. */ struct sftptime mtime; /** @brief File inode change time * * Only v6+, only if @ref SSH_FILEXFER_ATTR_CTIME is set. */ struct sftptime ctime; /** @brief File ACL * * ACLs are not really supported. We parse them but ignore them. * * Only v5+, only if @ref SSH_FILEXFER_ATTR_ACL is set. */ char *acl; /** @brief Attribute bits * * Only v5+, only if @ref SSH_FILEXFER_ATTR_BITS. * See @ref attrib_bits for bits. */ uint32_t attrib_bits; /* all v6+: */ /** @brief Validity mask for attribute bits * * Only v6+, only if @ref SSH_FILEXFER_ATTR_BITS. * See @ref attrib_bits for bits. */ uint32_t attrib_bits_valid; /** @brief Server's knowledge about file contents * * Only v6+, only if @ref SSH_FILEXFER_ATTR_TEXT_HINT. * See @ref text_hint for bits. */ uint8_t text_hint; /** @brief File MIME type * * Only v6+, only if @ref SSH_FILEXFER_ATTR_MIME_TYPE. */ char *mime_type; /** @brief File link count * * Only v6+, only if @ref SSH_FILEXFER_ATTR_LINK_COUNT. */ uint32_t link_count; /** @brief Untranslated form of name * * Only v6+, only if @ref SSH_FILEXFER_ATTR_UNTRANSLATED_NAME. */ char *untranslated_name; /* We stuff these in here too so we can conveniently use sftpattrs for * name lists */ /** @brief Local encoding of filename * * Not part of the SFTP attributes. Just used for convenience by a number of * functions. * * @todo Document exactly how sftpattrs::name is used. */ const char *name; /** @brief V3 @c longname file description * * Not part of the SFTP attributes. Instead used by the client to capture * the @c longname field sent in v3 @ref SSH_FXP_NAME responses. */ const char *longname; /** @brief Local wide encoding of filename * * Equivalent to @c name but converted to wide characters. */ const wchar_t *wname; /** @brief Symbolic link target * * Not part of the SFTP attributes. Instead used by the client and * sftp_format_attr() to capture the target of a symbolic link. */ const char *target; }; /** @brief A worker (i.e. one thread processing SFTP requests) * * Also used by the client to serialize requests. */ struct worker { /** @brief Output buffer size */ size_t bufsize; /** @brief Bytes used so far in the output buffer * * Set to 0x80000000 when the message has been sent. */ size_t bufused; /** @brief Output buffer */ uint8_t *buffer; /** @brief Conversion descriptor mapping the local encoding to UTF-8 */ iconv_t local_to_utf8; /** @brief Conversion descriptor mapping the UTF-8 to the local encoding */ iconv_t utf8_to_local; }; /* Thread-specific data */ /** @brief An SFTP job (i.e. a request) * * Also used in a couple of places by the client. */ struct sftpjob { /** @brief Length of request */ size_t len; /** @brief Complete bytes of request */ unsigned char *data; /** @brief Bytes remaining to parse */ size_t left; /** @brief Next byte to parse */ const unsigned char *ptr; /** @brief Allocator to use */ struct allocator *a; /** @brief Request ID or 0 */ uint32_t id; /** @brief Worker processing this job */ struct worker *worker; /* worker processing this job */ }; /** @brief An SFTP request */ struct sftpcmd { /** @brief Message type */ uint8_t type; /** @brief Request handler */ uint32_t (*handler)(struct sftpjob *job); }; /** @brief An SFTP extension request */ struct sftpextension { /** @brief Extension request name */ const char *name; /** @brief Extension request handler */ uint32_t (*handler)(struct sftpjob *job); }; /** @brief Internal error code meaning "already responded" */ #define HANDLER_RESPONDED ((uint32_t)-1) /** @brief Internal error code meaning "consult errno" */ #define HANDLER_ERRNO ((uint32_t)-2) /** @brief Definition of an SFTP protocol version */ struct sftpprotocol { /** @brief Number of request types supported */ int ncommands; /** @brief Supported request types * * Sorted by the request type code. */ const struct sftpcmd *commands; /** @brief Protocol version number */ int version; /** @brief Attribute validity mask */ uint32_t attrmask; /** @brief Maximum known error/status code */ uint32_t maxstatus; /** @brief Send a filename list as found in an @ref SSH_FXP_NAME response * @param job Job * @param nnames Number of names * @param names Filenames (and attributes) to send * @return Error code */ void (*sendnames)(struct sftpjob *job, int nnames, const struct sftpattr *names); /** @brief Send file attributes * @param job Job * @param attrs File attributes * @return Error code */ void (*sendattrs)(struct sftpjob *job, const struct sftpattr *filestat); /** @brief Parse file attributes * @param job Job * @param attrs Where to put file attributes * @return Error code */ uint32_t (*parseattrs)(struct sftpjob *job, struct sftpattr *filestat); /** @brief Encode a filename for transmission * @param job Job * @param path Input/output filename * @return 0 on success, -1 on error (as per sftp_iconv()) */ int (*encode)(struct sftpjob *job, char **path); /** @brief Decode a filename * @param job Job * @param path Input/output filename * @return Error code */ uint32_t (*decode)(struct sftpjob *job, char **path); /** @brief Number of extension types supported */ int nextensions; /** @brief Supported extension types * * Sorted by the extension name. */ const struct sftpextension *extensions; }; /* An SFTP protocol version */ #endif /* TYPES_H */ /* Local Variables: c-basic-offset:2 comment-column:40 fill-column:79 indent-tabs-mode:nil End: */ sftpserver-0.2.1/sftpserver.h0000664000175000017500000002140711626705056013230 00000000000000/* * This file is part of the Green End SFTP Server. * Copyright (C) 2007, 2011 Richard Kettlewell * * 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 2 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, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA */ /** @file sftpserver.h @brief SFTP server parameters and common declarations */ #ifndef SFTPSERVER_H #define SFTPSERVER_H #include "sftpcommon.h" #include #ifndef MAXNAMES /** @brief Maximum size of an @ref SSH_FXP_READDIR response */ # define MAXNAMES 32 #endif #ifndef MAXHANDLES /** @brief Maximum number of concurrent handles */ # define MAXHANDLES 128 #endif #ifndef MAXREAD /** @brief Maximum read size */ # define MAXREAD 1048576 #endif #ifndef MAXREQUEST /** @brief Maximum request size */ # define MAXREQUEST 1048576 #endif #ifndef DEFAULT_PERMISSIONS /** @brief Default file permissions */ # define DEFAULT_PERMISSIONS 0755 #endif /** @brief Send an @ref SSH_FXP_STATUS message * @param job Job * @param status Status code * @param msg Human-readable message */ void sftp_send_status(struct sftpjob *job, uint32_t status, const char *msg); /** @brief @ref SSH_FXP_INIT stub for use after initialization * @param job Job * @return Error code */ uint32_t sftp_vany_already_init(struct sftpjob *job); /** @brief Generic @ref SSH_FXP_REMOVE implementation * @param job Job * @return Error code */ uint32_t sftp_vany_remove(struct sftpjob *job); /** @brief Generic @ref SSH_FXP_RMDIR implementation * @param job Job * @return Error code */ uint32_t sftp_vany_rmdir(struct sftpjob *job); /** @brief Generic @ref SSH_FXP_SYMLINK implementation * @param job Job * @return Error code * * This for protocols 4 and above. */ uint32_t sftp_v345_symlink(struct sftpjob *job); /** @brief Generic @ref SSH_FXP_READLINK implementation * @param job Job * @return Error code */ uint32_t sftp_vany_readlink(struct sftpjob *job); /** @brief Generic @ref SSH_FXP_CLOSE implementation * @param job Job * @return Error code */ uint32_t sftp_vany_close(struct sftpjob *job); /** @brief Generic @ref SSH_FXP_READ implementation * @param job Job * @return Error code */ uint32_t sftp_vany_read(struct sftpjob *job); /** @brief Generic @ref SSH_FXP_WRITE implementation * @param job Job * @return Error code */ uint32_t sftp_vany_write(struct sftpjob *job); /** @brief Generic @ref SSH_FXP_SETSTAT implementation * @param job Job * @return Error code */ uint32_t sftp_vany_setstat(struct sftpjob *job); /** @brief Generic @ref SSH_FXP_FSETSTAT implementation * @param job Job * @return Error code */ uint32_t sftp_vany_fsetstat(struct sftpjob *job); /** @brief Generic @ref SSH_FXP_OPENDIR implementation * @param job Job * @return Error code */ uint32_t sftp_vany_opendir(struct sftpjob *job); /** @brief Generic @ref SSH_FXP_READDIR implementation * @param job Job * @return Error code */ uint32_t sftp_vany_readdir(struct sftpjob *job); /** @brief Generic @ref SSH_FXP_MKDIR implementation * @param job Job * @return Error code */ uint32_t sftp_vany_mkdir(struct sftpjob *job); /** @brief Generic @ref SSH_FXP_EXTENDED implementation * @param job Job * @return Error code */ uint32_t sftp_vany_extended(struct sftpjob *job); /** @brief Send a filename list as found in an @ref SSH_FXP_NAME response * @param job Job * @param nnames Number of names * @param names Filenames (and attributes) to send * @return Error code * * This is for protocols 4 and above. */ void sftp_v456_sendnames(struct sftpjob *job, int nnames, const struct sftpattr *names); /** @brief Send file attributes * @param job Job * @param attrs File attributes * @return Error code * * This is for protocols 4 and above. */ void sftp_v456_sendattrs(struct sftpjob *job, const struct sftpattr *attrs); /** @brief Parse file attributes * @param job Job * @param attrs Where to put file attributes * @return Error code * * This is for protocols 4 and above. */ uint32_t sftp_v456_parseattrs(struct sftpjob *job, struct sftpattr *attrs); /** @brief Encode a filename for transmission * @param job Job * @param path Input/output filename * @return 0 on success, -1 on error (as per sftp_iconv()) * * This is for protocol 3 only; @c *path is not modified. */ int sftp_v3_encode(struct sftpjob *job, char **path); /** @brief Encode a filename for transmission * @param job Job * @param path Input/output filename * @return 0 on success, -1 on error (as per sftp_iconv()) * * This is for protocols 4 and above; @c *path is replaced with the UTF-8 * version of the filename. */ int sftp_v456_encode(struct sftpjob *job, char **path); /** @brief Decode a filename * @param job Job * @param path Input/output filename * @return Error code * * This is for protocols 4 and above; @c *path is translated from UTF-8 to the * current multibyte encoding. */ uint32_t sftp_v456_decode(struct sftpjob *job, char **path); /** @brief Generic @ref SSH_FXP_RENAME implementation * @param job Job * @return Error code * * This is for protocols 3 and 4. */ uint32_t sftp_v34_rename(struct sftpjob *job); /** @brief Generic @ref SSH_FXP_OPEN implementation * @param job Job * @return Error code * * This is for protocols 3 and 4. */ uint32_t sftp_v34_open(struct sftpjob *job); /** @brief Generic @ref SSH_FXP_LSTAT implementation * @param job Job * @return Error code * * This is for protocols 4 and above. */ uint32_t sftp_v456_lstat(struct sftpjob *job); /** @brief Generic @ref SSH_FXP_STAT implementation * @param job Job * @return Error code * * This is for protocols 4 and above. */ uint32_t sftp_v456_stat(struct sftpjob *job); /** @brief Generic @ref SSH_FXP_FSTAT implementation * @param job Job * @return Error code * * This is for protocols 4 and above. */ uint32_t sftp_v456_fstat(struct sftpjob *job); /** @brief Generic @ref SSH_FXP_REALPATH implementation * @param job Job * @return Error code * * This is for protocols 3-5. */ uint32_t sftp_v345_realpath(struct sftpjob *job); /** @brief Generic @ref SSH_FXP_OPEN implementation * @param job Job * @return Error code * * This is for protocols 5 and above. */ uint32_t sftp_v56_open(struct sftpjob *job); /** @brief Generic @ref SSH_FXP_RENAME implementation * @param job Job * @return Error code * * This is for protocols 5 and above. */ uint32_t sftp_v56_rename(struct sftpjob *job); /** @brief @ref SSH_FXP_REALPATH implementation * @param job Job * @return Error code * * This is for protocol 6 only. */ uint32_t sftp_v6_realpath(struct sftpjob *job); /** @brief @ref SSH_FXP_LINK implementation * @param job Job * @return Error code * * This is for protocol 6 only. */ uint32_t sftp_v6_link(struct sftpjob *job); /** @brief @c text-seek extension implementation * @param job Job * @return Error code */ uint32_t sftp_vany_text_seek(struct sftpjob *job); /** @brief Common code for @ref SSH_FXP_OPEN * @param job Job * @param path Path to open (should already have been translated) * @param desired_access Access required (TODO link to valid bits) * @param flags Open flags (TODO link to valid bits) * @param attrs Initial attributes for new files * @return Error code */ uint32_t sftp_generic_open(struct sftpjob *job, const char *path, uint32_t desired_access, uint32_t flags, struct sftpattr *attrs); /** @brief @c space-available extension implementation * @param job Job * @return Error code */ uint32_t sftp_vany_space_available(struct sftpjob *job); /** @brief @c version-select extension implementation * @param job Job * @return Error code */ uint32_t sftp_v6_version_select(struct sftpjob *job); /** @brief @c posix-rename@openssh.org extension implementation * @param job Job * @return Error code */ uint32_t sftp_vany_posix_rename(struct sftpjob *job); /** @brief @c statfs@openssh.org extension implementation * @param job Job * @return Error code */ uint32_t sftp_vany_statfs(struct sftpjob *job); /** @brief Send an @ref SSH_FXP_STATUS message based on @c errno * @param job Job */ void sftp_send_errno_status(struct sftpjob *job); #endif /* SFTPSERVER_H */ /* Local Variables: c-basic-offset:2 comment-column:40 fill-column:79 indent-tabs-mode:nil End: */ sftpserver-0.2.1/config.aux/0000775000175000017500000000000012415610132012754 500000000000000sftpserver-0.2.1/config.aux/config.sub0000755000175000000000000010532711764422452014664 00000000000000#! /bin/sh # Configuration validation subroutine script. # Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, # 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, # 2011, 2012 Free Software Foundation, Inc. timestamp='2012-04-18' # This file is (in principle) common to ALL GNU software. # The presence of a machine in this file suggests that SOME GNU software # can handle that machine. It does not imply ALL GNU software can. # # This file 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 2 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 . # # As a special exception to the GNU General Public License, if you # distribute this file as part of a program that contains a # configuration script generated by Autoconf, you may include it under # the same distribution terms that you use for the rest of that program. # Please send patches to . Submit a context # diff and a properly formatted GNU ChangeLog entry. # # Configuration subroutine to validate and canonicalize a configuration type. # Supply the specified configuration type as an argument. # If it is invalid, we print an error message on stderr and exit with code 1. # Otherwise, we print the canonical config type on stdout and succeed. # You can get the latest version of this script from: # http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub;hb=HEAD # This file is supposed to be the same for all GNU packages # and recognize all the CPU types, system types and aliases # that are meaningful with *any* GNU software. # Each package is responsible for reporting which valid configurations # it does not support. The user should be able to distinguish # a failure to support a valid configuration from a meaningless # configuration. # The goal of this file is to map all the various variations of a given # machine specification into a single specification in the form: # CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM # or in some cases, the newer four-part form: # CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM # It is wrong to echo any other type of specification. me=`echo "$0" | sed -e 's,.*/,,'` usage="\ Usage: $0 [OPTION] CPU-MFR-OPSYS $0 [OPTION] ALIAS Canonicalize a configuration name. Operation modes: -h, --help print this help, then exit -t, --time-stamp print date of last modification, then exit -v, --version print version number, then exit Report bugs and patches to ." version="\ GNU config.sub ($timestamp) Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." help=" Try \`$me --help' for more information." # Parse command line while test $# -gt 0 ; do case $1 in --time-stamp | --time* | -t ) echo "$timestamp" ; exit ;; --version | -v ) echo "$version" ; exit ;; --help | --h* | -h ) echo "$usage"; exit ;; -- ) # Stop option processing shift; break ;; - ) # Use stdin as input. break ;; -* ) echo "$me: invalid option $1$help" exit 1 ;; *local*) # First pass through any local machine types. echo $1 exit ;; * ) break ;; esac done case $# in 0) echo "$me: missing argument$help" >&2 exit 1;; 1) ;; *) echo "$me: too many arguments$help" >&2 exit 1;; esac # Separate what the user gave into CPU-COMPANY and OS or KERNEL-OS (if any). # Here we must recognize all the valid KERNEL-OS combinations. maybe_os=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\2/'` case $maybe_os in nto-qnx* | linux-gnu* | linux-android* | linux-dietlibc | linux-newlib* | \ linux-uclibc* | uclinux-uclibc* | uclinux-gnu* | kfreebsd*-gnu* | \ knetbsd*-gnu* | netbsd*-gnu* | \ kopensolaris*-gnu* | \ storm-chaos* | os2-emx* | rtmk-nova*) os=-$maybe_os basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'` ;; android-linux) os=-linux-android basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'`-unknown ;; *) basic_machine=`echo $1 | sed 's/-[^-]*$//'` if [ $basic_machine != $1 ] then os=`echo $1 | sed 's/.*-/-/'` else os=; fi ;; esac ### Let's recognize common machines as not being operating systems so ### that things like config.sub decstation-3100 work. We also ### recognize some manufacturers as not being operating systems, so we ### can provide default operating systems below. case $os in -sun*os*) # Prevent following clause from handling this invalid input. ;; -dec* | -mips* | -sequent* | -encore* | -pc532* | -sgi* | -sony* | \ -att* | -7300* | -3300* | -delta* | -motorola* | -sun[234]* | \ -unicom* | -ibm* | -next | -hp | -isi* | -apollo | -altos* | \ -convergent* | -ncr* | -news | -32* | -3600* | -3100* | -hitachi* |\ -c[123]* | -convex* | -sun | -crds | -omron* | -dg | -ultra | -tti* | \ -harris | -dolphin | -highlevel | -gould | -cbm | -ns | -masscomp | \ -apple | -axis | -knuth | -cray | -microblaze) os= basic_machine=$1 ;; -bluegene*) os=-cnk ;; -sim | -cisco | -oki | -wec | -winbond) os= basic_machine=$1 ;; -scout) ;; -wrs) os=-vxworks basic_machine=$1 ;; -chorusos*) os=-chorusos basic_machine=$1 ;; -chorusrdb) os=-chorusrdb basic_machine=$1 ;; -hiux*) os=-hiuxwe2 ;; -sco6) os=-sco5v6 basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` ;; -sco5) os=-sco3.2v5 basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` ;; -sco4) os=-sco3.2v4 basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` ;; -sco3.2.[4-9]*) os=`echo $os | sed -e 's/sco3.2./sco3.2v/'` basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` ;; -sco3.2v[4-9]*) # Don't forget version if it is 3.2v4 or newer. basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` ;; -sco5v6*) # Don't forget version if it is 3.2v4 or newer. basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` ;; -sco*) os=-sco3.2v2 basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` ;; -udk*) basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` ;; -isc) os=-isc2.2 basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` ;; -clix*) basic_machine=clipper-intergraph ;; -isc*) basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` ;; -lynx*178) os=-lynxos178 ;; -lynx*5) os=-lynxos5 ;; -lynx*) os=-lynxos ;; -ptx*) basic_machine=`echo $1 | sed -e 's/86-.*/86-sequent/'` ;; -windowsnt*) os=`echo $os | sed -e 's/windowsnt/winnt/'` ;; -psos*) os=-psos ;; -mint | -mint[0-9]*) basic_machine=m68k-atari os=-mint ;; esac # Decode aliases for certain CPU-COMPANY combinations. case $basic_machine in # Recognize the basic CPU types without company name. # Some are omitted here because they have special meanings below. 1750a | 580 \ | a29k \ | aarch64 | aarch64_be \ | alpha | alphaev[4-8] | alphaev56 | alphaev6[78] | alphapca5[67] \ | alpha64 | alpha64ev[4-8] | alpha64ev56 | alpha64ev6[78] | alpha64pca5[67] \ | am33_2.0 \ | arc | arm | arm[bl]e | arme[lb] | armv[2345] | armv[345][lb] | avr | avr32 \ | be32 | be64 \ | bfin \ | c4x | clipper \ | d10v | d30v | dlx | dsp16xx \ | epiphany \ | fido | fr30 | frv \ | h8300 | h8500 | hppa | hppa1.[01] | hppa2.0 | hppa2.0[nw] | hppa64 \ | hexagon \ | i370 | i860 | i960 | ia64 \ | ip2k | iq2000 \ | le32 | le64 \ | lm32 \ | m32c | m32r | m32rle | m68000 | m68k | m88k \ | maxq | mb | microblaze | mcore | mep | metag \ | mips | mipsbe | mipseb | mipsel | mipsle \ | mips16 \ | mips64 | mips64el \ | mips64octeon | mips64octeonel \ | mips64orion | mips64orionel \ | mips64r5900 | mips64r5900el \ | mips64vr | mips64vrel \ | mips64vr4100 | mips64vr4100el \ | mips64vr4300 | mips64vr4300el \ | mips64vr5000 | mips64vr5000el \ | mips64vr5900 | mips64vr5900el \ | mipsisa32 | mipsisa32el \ | mipsisa32r2 | mipsisa32r2el \ | mipsisa64 | mipsisa64el \ | mipsisa64r2 | mipsisa64r2el \ | mipsisa64sb1 | mipsisa64sb1el \ | mipsisa64sr71k | mipsisa64sr71kel \ | mipstx39 | mipstx39el \ | mn10200 | mn10300 \ | moxie \ | mt \ | msp430 \ | nds32 | nds32le | nds32be \ | nios | nios2 \ | ns16k | ns32k \ | open8 \ | or32 \ | pdp10 | pdp11 | pj | pjl \ | powerpc | powerpc64 | powerpc64le | powerpcle \ | pyramid \ | rl78 | rx \ | score \ | sh | sh[1234] | sh[24]a | sh[24]aeb | sh[23]e | sh[34]eb | sheb | shbe | shle | sh[1234]le | sh3ele \ | sh64 | sh64le \ | sparc | sparc64 | sparc64b | sparc64v | sparc86x | sparclet | sparclite \ | sparcv8 | sparcv9 | sparcv9b | sparcv9v \ | spu \ | tahoe | tic4x | tic54x | tic55x | tic6x | tic80 | tron \ | ubicom32 \ | v850 | v850e | v850e1 | v850e2 | v850es | v850e2v3 \ | we32k \ | x86 | xc16x | xstormy16 | xtensa \ | z8k | z80) basic_machine=$basic_machine-unknown ;; c54x) basic_machine=tic54x-unknown ;; c55x) basic_machine=tic55x-unknown ;; c6x) basic_machine=tic6x-unknown ;; m6811 | m68hc11 | m6812 | m68hc12 | m68hcs12x | picochip) basic_machine=$basic_machine-unknown os=-none ;; m88110 | m680[12346]0 | m683?2 | m68360 | m5200 | v70 | w65 | z8k) ;; ms1) basic_machine=mt-unknown ;; strongarm | thumb | xscale) basic_machine=arm-unknown ;; xgate) basic_machine=$basic_machine-unknown os=-none ;; xscaleeb) basic_machine=armeb-unknown ;; xscaleel) basic_machine=armel-unknown ;; # We use `pc' rather than `unknown' # because (1) that's what they normally are, and # (2) the word "unknown" tends to confuse beginning users. i*86 | x86_64) basic_machine=$basic_machine-pc ;; # Object if more than one company name word. *-*-*) echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2 exit 1 ;; # Recognize the basic CPU types with company name. 580-* \ | a29k-* \ | aarch64-* | aarch64_be-* \ | alpha-* | alphaev[4-8]-* | alphaev56-* | alphaev6[78]-* \ | alpha64-* | alpha64ev[4-8]-* | alpha64ev56-* | alpha64ev6[78]-* \ | alphapca5[67]-* | alpha64pca5[67]-* | arc-* \ | arm-* | armbe-* | armle-* | armeb-* | armv*-* \ | avr-* | avr32-* \ | be32-* | be64-* \ | bfin-* | bs2000-* \ | c[123]* | c30-* | [cjt]90-* | c4x-* \ | clipper-* | craynv-* | cydra-* \ | d10v-* | d30v-* | dlx-* \ | elxsi-* \ | f30[01]-* | f700-* | fido-* | fr30-* | frv-* | fx80-* \ | h8300-* | h8500-* \ | hppa-* | hppa1.[01]-* | hppa2.0-* | hppa2.0[nw]-* | hppa64-* \ | hexagon-* \ | i*86-* | i860-* | i960-* | ia64-* \ | ip2k-* | iq2000-* \ | le32-* | le64-* \ | lm32-* \ | m32c-* | m32r-* | m32rle-* \ | m68000-* | m680[012346]0-* | m68360-* | m683?2-* | m68k-* \ | m88110-* | m88k-* | maxq-* | mcore-* | metag-* | microblaze-* \ | mips-* | mipsbe-* | mipseb-* | mipsel-* | mipsle-* \ | mips16-* \ | mips64-* | mips64el-* \ | mips64octeon-* | mips64octeonel-* \ | mips64orion-* | mips64orionel-* \ | mips64r5900-* | mips64r5900el-* \ | mips64vr-* | mips64vrel-* \ | mips64vr4100-* | mips64vr4100el-* \ | mips64vr4300-* | mips64vr4300el-* \ | mips64vr5000-* | mips64vr5000el-* \ | mips64vr5900-* | mips64vr5900el-* \ | mipsisa32-* | mipsisa32el-* \ | mipsisa32r2-* | mipsisa32r2el-* \ | mipsisa64-* | mipsisa64el-* \ | mipsisa64r2-* | mipsisa64r2el-* \ | mipsisa64sb1-* | mipsisa64sb1el-* \ | mipsisa64sr71k-* | mipsisa64sr71kel-* \ | mipstx39-* | mipstx39el-* \ | mmix-* \ | mt-* \ | msp430-* \ | nds32-* | nds32le-* | nds32be-* \ | nios-* | nios2-* \ | none-* | np1-* | ns16k-* | ns32k-* \ | open8-* \ | orion-* \ | pdp10-* | pdp11-* | pj-* | pjl-* | pn-* | power-* \ | powerpc-* | powerpc64-* | powerpc64le-* | powerpcle-* \ | pyramid-* \ | rl78-* | romp-* | rs6000-* | rx-* \ | sh-* | sh[1234]-* | sh[24]a-* | sh[24]aeb-* | sh[23]e-* | sh[34]eb-* | sheb-* | shbe-* \ | shle-* | sh[1234]le-* | sh3ele-* | sh64-* | sh64le-* \ | sparc-* | sparc64-* | sparc64b-* | sparc64v-* | sparc86x-* | sparclet-* \ | sparclite-* \ | sparcv8-* | sparcv9-* | sparcv9b-* | sparcv9v-* | sv1-* | sx?-* \ | tahoe-* \ | tic30-* | tic4x-* | tic54x-* | tic55x-* | tic6x-* | tic80-* \ | tile*-* \ | tron-* \ | ubicom32-* \ | v850-* | v850e-* | v850e1-* | v850es-* | v850e2-* | v850e2v3-* \ | vax-* \ | we32k-* \ | x86-* | x86_64-* | xc16x-* | xps100-* \ | xstormy16-* | xtensa*-* \ | ymp-* \ | z8k-* | z80-*) ;; # Recognize the basic CPU types without company name, with glob match. xtensa*) basic_machine=$basic_machine-unknown ;; # Recognize the various machine names and aliases which stand # for a CPU type and a company and sometimes even an OS. 386bsd) basic_machine=i386-unknown os=-bsd ;; 3b1 | 7300 | 7300-att | att-7300 | pc7300 | safari | unixpc) basic_machine=m68000-att ;; 3b*) basic_machine=we32k-att ;; a29khif) basic_machine=a29k-amd os=-udi ;; abacus) basic_machine=abacus-unknown ;; adobe68k) basic_machine=m68010-adobe os=-scout ;; alliant | fx80) basic_machine=fx80-alliant ;; altos | altos3068) basic_machine=m68k-altos ;; am29k) basic_machine=a29k-none os=-bsd ;; amd64) basic_machine=x86_64-pc ;; amd64-*) basic_machine=x86_64-`echo $basic_machine | sed 's/^[^-]*-//'` ;; amdahl) basic_machine=580-amdahl os=-sysv ;; amiga | amiga-*) basic_machine=m68k-unknown ;; amigaos | amigados) basic_machine=m68k-unknown os=-amigaos ;; amigaunix | amix) basic_machine=m68k-unknown os=-sysv4 ;; apollo68) basic_machine=m68k-apollo os=-sysv ;; apollo68bsd) basic_machine=m68k-apollo os=-bsd ;; aros) basic_machine=i386-pc os=-aros ;; aux) basic_machine=m68k-apple os=-aux ;; balance) basic_machine=ns32k-sequent os=-dynix ;; blackfin) basic_machine=bfin-unknown os=-linux ;; blackfin-*) basic_machine=bfin-`echo $basic_machine | sed 's/^[^-]*-//'` os=-linux ;; bluegene*) basic_machine=powerpc-ibm os=-cnk ;; c54x-*) basic_machine=tic54x-`echo $basic_machine | sed 's/^[^-]*-//'` ;; c55x-*) basic_machine=tic55x-`echo $basic_machine | sed 's/^[^-]*-//'` ;; c6x-*) basic_machine=tic6x-`echo $basic_machine | sed 's/^[^-]*-//'` ;; c90) basic_machine=c90-cray os=-unicos ;; cegcc) basic_machine=arm-unknown os=-cegcc ;; convex-c1) basic_machine=c1-convex os=-bsd ;; convex-c2) basic_machine=c2-convex os=-bsd ;; convex-c32) basic_machine=c32-convex os=-bsd ;; convex-c34) basic_machine=c34-convex os=-bsd ;; convex-c38) basic_machine=c38-convex os=-bsd ;; cray | j90) basic_machine=j90-cray os=-unicos ;; craynv) basic_machine=craynv-cray os=-unicosmp ;; cr16 | cr16-*) basic_machine=cr16-unknown os=-elf ;; crds | unos) basic_machine=m68k-crds ;; crisv32 | crisv32-* | etraxfs*) basic_machine=crisv32-axis ;; cris | cris-* | etrax*) basic_machine=cris-axis ;; crx) basic_machine=crx-unknown os=-elf ;; da30 | da30-*) basic_machine=m68k-da30 ;; decstation | decstation-3100 | pmax | pmax-* | pmin | dec3100 | decstatn) basic_machine=mips-dec ;; decsystem10* | dec10*) basic_machine=pdp10-dec os=-tops10 ;; decsystem20* | dec20*) basic_machine=pdp10-dec os=-tops20 ;; delta | 3300 | motorola-3300 | motorola-delta \ | 3300-motorola | delta-motorola) basic_machine=m68k-motorola ;; delta88) basic_machine=m88k-motorola os=-sysv3 ;; dicos) basic_machine=i686-pc os=-dicos ;; djgpp) basic_machine=i586-pc os=-msdosdjgpp ;; dpx20 | dpx20-*) basic_machine=rs6000-bull os=-bosx ;; dpx2* | dpx2*-bull) basic_machine=m68k-bull os=-sysv3 ;; ebmon29k) basic_machine=a29k-amd os=-ebmon ;; elxsi) basic_machine=elxsi-elxsi os=-bsd ;; encore | umax | mmax) basic_machine=ns32k-encore ;; es1800 | OSE68k | ose68k | ose | OSE) basic_machine=m68k-ericsson os=-ose ;; fx2800) basic_machine=i860-alliant ;; genix) basic_machine=ns32k-ns ;; gmicro) basic_machine=tron-gmicro os=-sysv ;; go32) basic_machine=i386-pc os=-go32 ;; h3050r* | hiux*) basic_machine=hppa1.1-hitachi os=-hiuxwe2 ;; h8300hms) basic_machine=h8300-hitachi os=-hms ;; h8300xray) basic_machine=h8300-hitachi os=-xray ;; h8500hms) basic_machine=h8500-hitachi os=-hms ;; harris) basic_machine=m88k-harris os=-sysv3 ;; hp300-*) basic_machine=m68k-hp ;; hp300bsd) basic_machine=m68k-hp os=-bsd ;; hp300hpux) basic_machine=m68k-hp os=-hpux ;; hp3k9[0-9][0-9] | hp9[0-9][0-9]) basic_machine=hppa1.0-hp ;; hp9k2[0-9][0-9] | hp9k31[0-9]) basic_machine=m68000-hp ;; hp9k3[2-9][0-9]) basic_machine=m68k-hp ;; hp9k6[0-9][0-9] | hp6[0-9][0-9]) basic_machine=hppa1.0-hp ;; hp9k7[0-79][0-9] | hp7[0-79][0-9]) basic_machine=hppa1.1-hp ;; hp9k78[0-9] | hp78[0-9]) # FIXME: really hppa2.0-hp basic_machine=hppa1.1-hp ;; hp9k8[67]1 | hp8[67]1 | hp9k80[24] | hp80[24] | hp9k8[78]9 | hp8[78]9 | hp9k893 | hp893) # FIXME: really hppa2.0-hp basic_machine=hppa1.1-hp ;; hp9k8[0-9][13679] | hp8[0-9][13679]) basic_machine=hppa1.1-hp ;; hp9k8[0-9][0-9] | hp8[0-9][0-9]) basic_machine=hppa1.0-hp ;; hppa-next) os=-nextstep3 ;; hppaosf) basic_machine=hppa1.1-hp os=-osf ;; hppro) basic_machine=hppa1.1-hp os=-proelf ;; i370-ibm* | ibm*) basic_machine=i370-ibm ;; i*86v32) basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` os=-sysv32 ;; i*86v4*) basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` os=-sysv4 ;; i*86v) basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` os=-sysv ;; i*86sol2) basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` os=-solaris2 ;; i386mach) basic_machine=i386-mach os=-mach ;; i386-vsta | vsta) basic_machine=i386-unknown os=-vsta ;; iris | iris4d) basic_machine=mips-sgi case $os in -irix*) ;; *) os=-irix4 ;; esac ;; isi68 | isi) basic_machine=m68k-isi os=-sysv ;; m68knommu) basic_machine=m68k-unknown os=-linux ;; m68knommu-*) basic_machine=m68k-`echo $basic_machine | sed 's/^[^-]*-//'` os=-linux ;; m88k-omron*) basic_machine=m88k-omron ;; magnum | m3230) basic_machine=mips-mips os=-sysv ;; merlin) basic_machine=ns32k-utek os=-sysv ;; microblaze) basic_machine=microblaze-xilinx ;; mingw32) basic_machine=i386-pc os=-mingw32 ;; mingw32ce) basic_machine=arm-unknown os=-mingw32ce ;; miniframe) basic_machine=m68000-convergent ;; *mint | -mint[0-9]* | *MiNT | *MiNT[0-9]*) basic_machine=m68k-atari os=-mint ;; mips3*-*) basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'` ;; mips3*) basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'`-unknown ;; monitor) basic_machine=m68k-rom68k os=-coff ;; morphos) basic_machine=powerpc-unknown os=-morphos ;; msdos) basic_machine=i386-pc os=-msdos ;; ms1-*) basic_machine=`echo $basic_machine | sed -e 's/ms1-/mt-/'` ;; msys) basic_machine=i386-pc os=-msys ;; mvs) basic_machine=i370-ibm os=-mvs ;; nacl) basic_machine=le32-unknown os=-nacl ;; ncr3000) basic_machine=i486-ncr os=-sysv4 ;; netbsd386) basic_machine=i386-unknown os=-netbsd ;; netwinder) basic_machine=armv4l-rebel os=-linux ;; news | news700 | news800 | news900) basic_machine=m68k-sony os=-newsos ;; news1000) basic_machine=m68030-sony os=-newsos ;; news-3600 | risc-news) basic_machine=mips-sony os=-newsos ;; necv70) basic_machine=v70-nec os=-sysv ;; next | m*-next ) basic_machine=m68k-next case $os in -nextstep* ) ;; -ns2*) os=-nextstep2 ;; *) os=-nextstep3 ;; esac ;; nh3000) basic_machine=m68k-harris os=-cxux ;; nh[45]000) basic_machine=m88k-harris os=-cxux ;; nindy960) basic_machine=i960-intel os=-nindy ;; mon960) basic_machine=i960-intel os=-mon960 ;; nonstopux) basic_machine=mips-compaq os=-nonstopux ;; np1) basic_machine=np1-gould ;; neo-tandem) basic_machine=neo-tandem ;; nse-tandem) basic_machine=nse-tandem ;; nsr-tandem) basic_machine=nsr-tandem ;; op50n-* | op60c-*) basic_machine=hppa1.1-oki os=-proelf ;; openrisc | openrisc-*) basic_machine=or32-unknown ;; os400) basic_machine=powerpc-ibm os=-os400 ;; OSE68000 | ose68000) basic_machine=m68000-ericsson os=-ose ;; os68k) basic_machine=m68k-none os=-os68k ;; pa-hitachi) basic_machine=hppa1.1-hitachi os=-hiuxwe2 ;; paragon) basic_machine=i860-intel os=-osf ;; parisc) basic_machine=hppa-unknown os=-linux ;; parisc-*) basic_machine=hppa-`echo $basic_machine | sed 's/^[^-]*-//'` os=-linux ;; pbd) basic_machine=sparc-tti ;; pbb) basic_machine=m68k-tti ;; pc532 | pc532-*) basic_machine=ns32k-pc532 ;; pc98) basic_machine=i386-pc ;; pc98-*) basic_machine=i386-`echo $basic_machine | sed 's/^[^-]*-//'` ;; pentium | p5 | k5 | k6 | nexgen | viac3) basic_machine=i586-pc ;; pentiumpro | p6 | 6x86 | athlon | athlon_*) basic_machine=i686-pc ;; pentiumii | pentium2 | pentiumiii | pentium3) basic_machine=i686-pc ;; pentium4) basic_machine=i786-pc ;; pentium-* | p5-* | k5-* | k6-* | nexgen-* | viac3-*) basic_machine=i586-`echo $basic_machine | sed 's/^[^-]*-//'` ;; pentiumpro-* | p6-* | 6x86-* | athlon-*) basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'` ;; pentiumii-* | pentium2-* | pentiumiii-* | pentium3-*) basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'` ;; pentium4-*) basic_machine=i786-`echo $basic_machine | sed 's/^[^-]*-//'` ;; pn) basic_machine=pn-gould ;; power) basic_machine=power-ibm ;; ppc | ppcbe) basic_machine=powerpc-unknown ;; ppc-* | ppcbe-*) basic_machine=powerpc-`echo $basic_machine | sed 's/^[^-]*-//'` ;; ppcle | powerpclittle | ppc-le | powerpc-little) basic_machine=powerpcle-unknown ;; ppcle-* | powerpclittle-*) basic_machine=powerpcle-`echo $basic_machine | sed 's/^[^-]*-//'` ;; ppc64) basic_machine=powerpc64-unknown ;; ppc64-*) basic_machine=powerpc64-`echo $basic_machine | sed 's/^[^-]*-//'` ;; ppc64le | powerpc64little | ppc64-le | powerpc64-little) basic_machine=powerpc64le-unknown ;; ppc64le-* | powerpc64little-*) basic_machine=powerpc64le-`echo $basic_machine | sed 's/^[^-]*-//'` ;; ps2) basic_machine=i386-ibm ;; pw32) basic_machine=i586-unknown os=-pw32 ;; rdos) basic_machine=i386-pc os=-rdos ;; rom68k) basic_machine=m68k-rom68k os=-coff ;; rm[46]00) basic_machine=mips-siemens ;; rtpc | rtpc-*) basic_machine=romp-ibm ;; s390 | s390-*) basic_machine=s390-ibm ;; s390x | s390x-*) basic_machine=s390x-ibm ;; sa29200) basic_machine=a29k-amd os=-udi ;; sb1) basic_machine=mipsisa64sb1-unknown ;; sb1el) basic_machine=mipsisa64sb1el-unknown ;; sde) basic_machine=mipsisa32-sde os=-elf ;; sei) basic_machine=mips-sei os=-seiux ;; sequent) basic_machine=i386-sequent ;; sh) basic_machine=sh-hitachi os=-hms ;; sh5el) basic_machine=sh5le-unknown ;; sh64) basic_machine=sh64-unknown ;; sparclite-wrs | simso-wrs) basic_machine=sparclite-wrs os=-vxworks ;; sps7) basic_machine=m68k-bull os=-sysv2 ;; spur) basic_machine=spur-unknown ;; st2000) basic_machine=m68k-tandem ;; stratus) basic_machine=i860-stratus os=-sysv4 ;; strongarm-* | thumb-*) basic_machine=arm-`echo $basic_machine | sed 's/^[^-]*-//'` ;; sun2) basic_machine=m68000-sun ;; sun2os3) basic_machine=m68000-sun os=-sunos3 ;; sun2os4) basic_machine=m68000-sun os=-sunos4 ;; sun3os3) basic_machine=m68k-sun os=-sunos3 ;; sun3os4) basic_machine=m68k-sun os=-sunos4 ;; sun4os3) basic_machine=sparc-sun os=-sunos3 ;; sun4os4) basic_machine=sparc-sun os=-sunos4 ;; sun4sol2) basic_machine=sparc-sun os=-solaris2 ;; sun3 | sun3-*) basic_machine=m68k-sun ;; sun4) basic_machine=sparc-sun ;; sun386 | sun386i | roadrunner) basic_machine=i386-sun ;; sv1) basic_machine=sv1-cray os=-unicos ;; symmetry) basic_machine=i386-sequent os=-dynix ;; t3e) basic_machine=alphaev5-cray os=-unicos ;; t90) basic_machine=t90-cray os=-unicos ;; tile*) basic_machine=$basic_machine-unknown os=-linux-gnu ;; tx39) basic_machine=mipstx39-unknown ;; tx39el) basic_machine=mipstx39el-unknown ;; toad1) basic_machine=pdp10-xkl os=-tops20 ;; tower | tower-32) basic_machine=m68k-ncr ;; tpf) basic_machine=s390x-ibm os=-tpf ;; udi29k) basic_machine=a29k-amd os=-udi ;; ultra3) basic_machine=a29k-nyu os=-sym1 ;; v810 | necv810) basic_machine=v810-nec os=-none ;; vaxv) basic_machine=vax-dec os=-sysv ;; vms) basic_machine=vax-dec os=-vms ;; vpp*|vx|vx-*) basic_machine=f301-fujitsu ;; vxworks960) basic_machine=i960-wrs os=-vxworks ;; vxworks68) basic_machine=m68k-wrs os=-vxworks ;; vxworks29k) basic_machine=a29k-wrs os=-vxworks ;; w65*) basic_machine=w65-wdc os=-none ;; w89k-*) basic_machine=hppa1.1-winbond os=-proelf ;; xbox) basic_machine=i686-pc os=-mingw32 ;; xps | xps100) basic_machine=xps100-honeywell ;; xscale-* | xscalee[bl]-*) basic_machine=`echo $basic_machine | sed 's/^xscale/arm/'` ;; ymp) basic_machine=ymp-cray os=-unicos ;; z8k-*-coff) basic_machine=z8k-unknown os=-sim ;; z80-*-coff) basic_machine=z80-unknown os=-sim ;; none) basic_machine=none-none os=-none ;; # Here we handle the default manufacturer of certain CPU types. It is in # some cases the only manufacturer, in others, it is the most popular. w89k) basic_machine=hppa1.1-winbond ;; op50n) basic_machine=hppa1.1-oki ;; op60c) basic_machine=hppa1.1-oki ;; romp) basic_machine=romp-ibm ;; mmix) basic_machine=mmix-knuth ;; rs6000) basic_machine=rs6000-ibm ;; vax) basic_machine=vax-dec ;; pdp10) # there are many clones, so DEC is not a safe bet basic_machine=pdp10-unknown ;; pdp11) basic_machine=pdp11-dec ;; we32k) basic_machine=we32k-att ;; sh[1234] | sh[24]a | sh[24]aeb | sh[34]eb | sh[1234]le | sh[23]ele) basic_machine=sh-unknown ;; sparc | sparcv8 | sparcv9 | sparcv9b | sparcv9v) basic_machine=sparc-sun ;; cydra) basic_machine=cydra-cydrome ;; orion) basic_machine=orion-highlevel ;; orion105) basic_machine=clipper-highlevel ;; mac | mpw | mac-mpw) basic_machine=m68k-apple ;; pmac | pmac-mpw) basic_machine=powerpc-apple ;; *-unknown) # Make sure to match an already-canonicalized machine name. ;; *) echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2 exit 1 ;; esac # Here we canonicalize certain aliases for manufacturers. case $basic_machine in *-digital*) basic_machine=`echo $basic_machine | sed 's/digital.*/dec/'` ;; *-commodore*) basic_machine=`echo $basic_machine | sed 's/commodore.*/cbm/'` ;; *) ;; esac # Decode manufacturer-specific aliases for certain operating systems. if [ x"$os" != x"" ] then case $os in # First match some system type aliases # that might get confused with valid system types. # -solaris* is a basic system type, with this one exception. -auroraux) os=-auroraux ;; -solaris1 | -solaris1.*) os=`echo $os | sed -e 's|solaris1|sunos4|'` ;; -solaris) os=-solaris2 ;; -svr4*) os=-sysv4 ;; -unixware*) os=-sysv4.2uw ;; -gnu/linux*) os=`echo $os | sed -e 's|gnu/linux|linux-gnu|'` ;; # First accept the basic system types. # The portable systems comes first. # Each alternative MUST END IN A *, to match a version number. # -sysv* is not here because it comes later, after sysvr4. -gnu* | -bsd* | -mach* | -minix* | -genix* | -ultrix* | -irix* \ | -*vms* | -sco* | -esix* | -isc* | -aix* | -cnk* | -sunos | -sunos[34]*\ | -hpux* | -unos* | -osf* | -luna* | -dgux* | -auroraux* | -solaris* \ | -sym* | -kopensolaris* \ | -amigaos* | -amigados* | -msdos* | -newsos* | -unicos* | -aof* \ | -aos* | -aros* \ | -nindy* | -vxsim* | -vxworks* | -ebmon* | -hms* | -mvs* \ | -clix* | -riscos* | -uniplus* | -iris* | -rtu* | -xenix* \ | -hiux* | -386bsd* | -knetbsd* | -mirbsd* | -netbsd* \ | -openbsd* | -solidbsd* \ | -ekkobsd* | -kfreebsd* | -freebsd* | -riscix* | -lynxos* \ | -bosx* | -nextstep* | -cxux* | -aout* | -elf* | -oabi* \ | -ptx* | -coff* | -ecoff* | -winnt* | -domain* | -vsta* \ | -udi* | -eabi* | -lites* | -ieee* | -go32* | -aux* \ | -chorusos* | -chorusrdb* | -cegcc* \ | -cygwin* | -msys* | -pe* | -psos* | -moss* | -proelf* | -rtems* \ | -mingw32* | -linux-gnu* | -linux-android* \ | -linux-newlib* | -linux-uclibc* \ | -uxpv* | -beos* | -mpeix* | -udk* \ | -interix* | -uwin* | -mks* | -rhapsody* | -darwin* | -opened* \ | -openstep* | -oskit* | -conix* | -pw32* | -nonstopux* \ | -storm-chaos* | -tops10* | -tenex* | -tops20* | -its* \ | -os2* | -vos* | -palmos* | -uclinux* | -nucleus* \ | -morphos* | -superux* | -rtmk* | -rtmk-nova* | -windiss* \ | -powermax* | -dnix* | -nx6 | -nx7 | -sei* | -dragonfly* \ | -skyos* | -haiku* | -rdos* | -toppers* | -drops* | -es*) # Remember, each alternative MUST END IN *, to match a version number. ;; -qnx*) case $basic_machine in x86-* | i*86-*) ;; *) os=-nto$os ;; esac ;; -nto-qnx*) ;; -nto*) os=`echo $os | sed -e 's|nto|nto-qnx|'` ;; -sim | -es1800* | -hms* | -xray | -os68k* | -none* | -v88r* \ | -windows* | -osx | -abug | -netware* | -os9* | -beos* | -haiku* \ | -macos* | -mpw* | -magic* | -mmixware* | -mon960* | -lnews*) ;; -mac*) os=`echo $os | sed -e 's|mac|macos|'` ;; -linux-dietlibc) os=-linux-dietlibc ;; -linux*) os=`echo $os | sed -e 's|linux|linux-gnu|'` ;; -sunos5*) os=`echo $os | sed -e 's|sunos5|solaris2|'` ;; -sunos6*) os=`echo $os | sed -e 's|sunos6|solaris3|'` ;; -opened*) os=-openedition ;; -os400*) os=-os400 ;; -wince*) os=-wince ;; -osfrose*) os=-osfrose ;; -osf*) os=-osf ;; -utek*) os=-bsd ;; -dynix*) os=-bsd ;; -acis*) os=-aos ;; -atheos*) os=-atheos ;; -syllable*) os=-syllable ;; -386bsd) os=-bsd ;; -ctix* | -uts*) os=-sysv ;; -nova*) os=-rtmk-nova ;; -ns2 ) os=-nextstep2 ;; -nsk*) os=-nsk ;; # Preserve the version number of sinix5. -sinix5.*) os=`echo $os | sed -e 's|sinix|sysv|'` ;; -sinix*) os=-sysv4 ;; -tpf*) os=-tpf ;; -triton*) os=-sysv3 ;; -oss*) os=-sysv3 ;; -svr4) os=-sysv4 ;; -svr3) os=-sysv3 ;; -sysvr4) os=-sysv4 ;; # This must come after -sysvr4. -sysv*) ;; -ose*) os=-ose ;; -es1800*) os=-ose ;; -xenix) os=-xenix ;; -*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*) os=-mint ;; -aros*) os=-aros ;; -kaos*) os=-kaos ;; -zvmoe) os=-zvmoe ;; -dicos*) os=-dicos ;; -nacl*) ;; -none) ;; *) # Get rid of the `-' at the beginning of $os. os=`echo $os | sed 's/[^-]*-//'` echo Invalid configuration \`$1\': system \`$os\' not recognized 1>&2 exit 1 ;; esac else # Here we handle the default operating systems that come with various machines. # The value should be what the vendor currently ships out the door with their # machine or put another way, the most popular os provided with the machine. # Note that if you're going to try to match "-MANUFACTURER" here (say, # "-sun"), then you have to tell the case statement up towards the top # that MANUFACTURER isn't an operating system. Otherwise, code above # will signal an error saying that MANUFACTURER isn't an operating # system, and we'll never get to this point. case $basic_machine in score-*) os=-elf ;; spu-*) os=-elf ;; *-acorn) os=-riscix1.2 ;; arm*-rebel) os=-linux ;; arm*-semi) os=-aout ;; c4x-* | tic4x-*) os=-coff ;; hexagon-*) os=-elf ;; tic54x-*) os=-coff ;; tic55x-*) os=-coff ;; tic6x-*) os=-coff ;; # This must come before the *-dec entry. pdp10-*) os=-tops20 ;; pdp11-*) os=-none ;; *-dec | vax-*) os=-ultrix4.2 ;; m68*-apollo) os=-domain ;; i386-sun) os=-sunos4.0.2 ;; m68000-sun) os=-sunos3 ;; m68*-cisco) os=-aout ;; mep-*) os=-elf ;; mips*-cisco) os=-elf ;; mips*-*) os=-elf ;; or32-*) os=-coff ;; *-tti) # must be before sparc entry or we get the wrong os. os=-sysv3 ;; sparc-* | *-sun) os=-sunos4.1.1 ;; *-be) os=-beos ;; *-haiku) os=-haiku ;; *-ibm) os=-aix ;; *-knuth) os=-mmixware ;; *-wec) os=-proelf ;; *-winbond) os=-proelf ;; *-oki) os=-proelf ;; *-hp) os=-hpux ;; *-hitachi) os=-hiux ;; i860-* | *-att | *-ncr | *-altos | *-motorola | *-convergent) os=-sysv ;; *-cbm) os=-amigaos ;; *-dg) os=-dgux ;; *-dolphin) os=-sysv3 ;; m68k-ccur) os=-rtu ;; m88k-omron*) os=-luna ;; *-next ) os=-nextstep ;; *-sequent) os=-ptx ;; *-crds) os=-unos ;; *-ns) os=-genix ;; i370-*) os=-mvs ;; *-next) os=-nextstep3 ;; *-gould) os=-sysv ;; *-highlevel) os=-bsd ;; *-encore) os=-bsd ;; *-sgi) os=-irix ;; *-siemens) os=-sysv4 ;; *-masscomp) os=-rtu ;; f30[01]-fujitsu | f700-fujitsu) os=-uxpv ;; *-rom68k) os=-coff ;; *-*bug) os=-coff ;; *-apple) os=-macos ;; *-atari*) os=-mint ;; *) os=-none ;; esac fi # Here we handle the case where we know the os, and the CPU type, but not the # manufacturer. We pick the logical manufacturer. vendor=unknown case $basic_machine in *-unknown) case $os in -riscix*) vendor=acorn ;; -sunos*) vendor=sun ;; -cnk*|-aix*) vendor=ibm ;; -beos*) vendor=be ;; -hpux*) vendor=hp ;; -mpeix*) vendor=hp ;; -hiux*) vendor=hitachi ;; -unos*) vendor=crds ;; -dgux*) vendor=dg ;; -luna*) vendor=omron ;; -genix*) vendor=ns ;; -mvs* | -opened*) vendor=ibm ;; -os400*) vendor=ibm ;; -ptx*) vendor=sequent ;; -tpf*) vendor=ibm ;; -vxsim* | -vxworks* | -windiss*) vendor=wrs ;; -aux*) vendor=apple ;; -hms*) vendor=hitachi ;; -mpw* | -macos*) vendor=apple ;; -*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*) vendor=atari ;; -vos*) vendor=stratus ;; esac basic_machine=`echo $basic_machine | sed "s/unknown/$vendor/"` ;; esac echo $basic_machine$os exit # Local variables: # eval: (add-hook 'write-file-hooks 'time-stamp) # time-stamp-start: "timestamp='" # time-stamp-format: "%:y-%02m-%02d" # time-stamp-end: "'" # End: sftpserver-0.2.1/config.aux/config.guess0000755000175000000000000012743211764422452015222 00000000000000#! /bin/sh # Attempt to guess a canonical system name. # Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, # 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, # 2011, 2012 Free Software Foundation, Inc. timestamp='2012-02-10' # This file 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 2 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 . # # As a special exception to the GNU General Public License, if you # distribute this file as part of a program that contains a # configuration script generated by Autoconf, you may include it under # the same distribution terms that you use for the rest of that program. # Originally written by Per Bothner. Please send patches (context # diff format) to and include a ChangeLog # entry. # # This script attempts to guess a canonical system name similar to # config.sub. If it succeeds, it prints the system name on stdout, and # exits with 0. Otherwise, it exits with 1. # # You can get the latest version of this script from: # http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb=HEAD me=`echo "$0" | sed -e 's,.*/,,'` usage="\ Usage: $0 [OPTION] Output the configuration name of the system \`$me' is run on. Operation modes: -h, --help print this help, then exit -t, --time-stamp print date of last modification, then exit -v, --version print version number, then exit Report bugs and patches to ." version="\ GNU config.guess ($timestamp) Originally written by Per Bothner. Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." help=" Try \`$me --help' for more information." # Parse command line while test $# -gt 0 ; do case $1 in --time-stamp | --time* | -t ) echo "$timestamp" ; exit ;; --version | -v ) echo "$version" ; exit ;; --help | --h* | -h ) echo "$usage"; exit ;; -- ) # Stop option processing shift; break ;; - ) # Use stdin as input. break ;; -* ) echo "$me: invalid option $1$help" >&2 exit 1 ;; * ) break ;; esac done if test $# != 0; then echo "$me: too many arguments$help" >&2 exit 1 fi trap 'exit 1' 1 2 15 # CC_FOR_BUILD -- compiler used by this script. Note that the use of a # compiler to aid in system detection is discouraged as it requires # temporary files to be created and, as you can see below, it is a # headache to deal with in a portable fashion. # Historically, `CC_FOR_BUILD' used to be named `HOST_CC'. We still # use `HOST_CC' if defined, but it is deprecated. # Portable tmp directory creation inspired by the Autoconf team. set_cc_for_build=' trap "exitcode=\$?; (rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null) && exit \$exitcode" 0 ; trap "rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null; exit 1" 1 2 13 15 ; : ${TMPDIR=/tmp} ; { tmp=`(umask 077 && mktemp -d "$TMPDIR/cgXXXXXX") 2>/dev/null` && test -n "$tmp" && test -d "$tmp" ; } || { test -n "$RANDOM" && tmp=$TMPDIR/cg$$-$RANDOM && (umask 077 && mkdir $tmp) ; } || { tmp=$TMPDIR/cg-$$ && (umask 077 && mkdir $tmp) && echo "Warning: creating insecure temp directory" >&2 ; } || { echo "$me: cannot create a temporary directory in $TMPDIR" >&2 ; exit 1 ; } ; dummy=$tmp/dummy ; tmpfiles="$dummy.c $dummy.o $dummy.rel $dummy" ; case $CC_FOR_BUILD,$HOST_CC,$CC in ,,) echo "int x;" > $dummy.c ; for c in cc gcc c89 c99 ; do if ($c -c -o $dummy.o $dummy.c) >/dev/null 2>&1 ; then CC_FOR_BUILD="$c"; break ; fi ; done ; if test x"$CC_FOR_BUILD" = x ; then CC_FOR_BUILD=no_compiler_found ; fi ;; ,,*) CC_FOR_BUILD=$CC ;; ,*,*) CC_FOR_BUILD=$HOST_CC ;; esac ; set_cc_for_build= ;' # This is needed to find uname on a Pyramid OSx when run in the BSD universe. # (ghazi@noc.rutgers.edu 1994-08-24) if (test -f /.attbin/uname) >/dev/null 2>&1 ; then PATH=$PATH:/.attbin ; export PATH fi UNAME_MACHINE=`(uname -m) 2>/dev/null` || UNAME_MACHINE=unknown UNAME_RELEASE=`(uname -r) 2>/dev/null` || UNAME_RELEASE=unknown UNAME_SYSTEM=`(uname -s) 2>/dev/null` || UNAME_SYSTEM=unknown UNAME_VERSION=`(uname -v) 2>/dev/null` || UNAME_VERSION=unknown # Note: order is significant - the case branches are not exclusive. case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in *:NetBSD:*:*) # NetBSD (nbsd) targets should (where applicable) match one or # more of the tuples: *-*-netbsdelf*, *-*-netbsdaout*, # *-*-netbsdecoff* and *-*-netbsd*. For targets that recently # switched to ELF, *-*-netbsd* would select the old # object file format. This provides both forward # compatibility and a consistent mechanism for selecting the # object file format. # # Note: NetBSD doesn't particularly care about the vendor # portion of the name. We always set it to "unknown". sysctl="sysctl -n hw.machine_arch" UNAME_MACHINE_ARCH=`(/sbin/$sysctl 2>/dev/null || \ /usr/sbin/$sysctl 2>/dev/null || echo unknown)` case "${UNAME_MACHINE_ARCH}" in armeb) machine=armeb-unknown ;; arm*) machine=arm-unknown ;; sh3el) machine=shl-unknown ;; sh3eb) machine=sh-unknown ;; sh5el) machine=sh5le-unknown ;; *) machine=${UNAME_MACHINE_ARCH}-unknown ;; esac # The Operating System including object format, if it has switched # to ELF recently, or will in the future. case "${UNAME_MACHINE_ARCH}" in arm*|i386|m68k|ns32k|sh3*|sparc|vax) eval $set_cc_for_build if echo __ELF__ | $CC_FOR_BUILD -E - 2>/dev/null \ | grep -q __ELF__ then # Once all utilities can be ECOFF (netbsdecoff) or a.out (netbsdaout). # Return netbsd for either. FIX? os=netbsd else os=netbsdelf fi ;; *) os=netbsd ;; esac # The OS release # Debian GNU/NetBSD machines have a different userland, and # thus, need a distinct triplet. However, they do not need # kernel version information, so it can be replaced with a # suitable tag, in the style of linux-gnu. case "${UNAME_VERSION}" in Debian*) release='-gnu' ;; *) release=`echo ${UNAME_RELEASE}|sed -e 's/[-_].*/\./'` ;; esac # Since CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM: # contains redundant information, the shorter form: # CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM is used. echo "${machine}-${os}${release}" exit ;; *:OpenBSD:*:*) UNAME_MACHINE_ARCH=`arch | sed 's/OpenBSD.//'` echo ${UNAME_MACHINE_ARCH}-unknown-openbsd${UNAME_RELEASE} exit ;; *:ekkoBSD:*:*) echo ${UNAME_MACHINE}-unknown-ekkobsd${UNAME_RELEASE} exit ;; *:SolidBSD:*:*) echo ${UNAME_MACHINE}-unknown-solidbsd${UNAME_RELEASE} exit ;; macppc:MirBSD:*:*) echo powerpc-unknown-mirbsd${UNAME_RELEASE} exit ;; *:MirBSD:*:*) echo ${UNAME_MACHINE}-unknown-mirbsd${UNAME_RELEASE} exit ;; alpha:OSF1:*:*) case $UNAME_RELEASE in *4.0) UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $3}'` ;; *5.*) UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $4}'` ;; esac # According to Compaq, /usr/sbin/psrinfo has been available on # OSF/1 and Tru64 systems produced since 1995. I hope that # covers most systems running today. This code pipes the CPU # types through head -n 1, so we only detect the type of CPU 0. ALPHA_CPU_TYPE=`/usr/sbin/psrinfo -v | sed -n -e 's/^ The alpha \(.*\) processor.*$/\1/p' | head -n 1` case "$ALPHA_CPU_TYPE" in "EV4 (21064)") UNAME_MACHINE="alpha" ;; "EV4.5 (21064)") UNAME_MACHINE="alpha" ;; "LCA4 (21066/21068)") UNAME_MACHINE="alpha" ;; "EV5 (21164)") UNAME_MACHINE="alphaev5" ;; "EV5.6 (21164A)") UNAME_MACHINE="alphaev56" ;; "EV5.6 (21164PC)") UNAME_MACHINE="alphapca56" ;; "EV5.7 (21164PC)") UNAME_MACHINE="alphapca57" ;; "EV6 (21264)") UNAME_MACHINE="alphaev6" ;; "EV6.7 (21264A)") UNAME_MACHINE="alphaev67" ;; "EV6.8CB (21264C)") UNAME_MACHINE="alphaev68" ;; "EV6.8AL (21264B)") UNAME_MACHINE="alphaev68" ;; "EV6.8CX (21264D)") UNAME_MACHINE="alphaev68" ;; "EV6.9A (21264/EV69A)") UNAME_MACHINE="alphaev69" ;; "EV7 (21364)") UNAME_MACHINE="alphaev7" ;; "EV7.9 (21364A)") UNAME_MACHINE="alphaev79" ;; esac # A Pn.n version is a patched version. # A Vn.n version is a released version. # A Tn.n version is a released field test version. # A Xn.n version is an unreleased experimental baselevel. # 1.2 uses "1.2" for uname -r. echo ${UNAME_MACHINE}-dec-osf`echo ${UNAME_RELEASE} | sed -e 's/^[PVTX]//' | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'` # Reset EXIT trap before exiting to avoid spurious non-zero exit code. exitcode=$? trap '' 0 exit $exitcode ;; Alpha\ *:Windows_NT*:*) # How do we know it's Interix rather than the generic POSIX subsystem? # Should we change UNAME_MACHINE based on the output of uname instead # of the specific Alpha model? echo alpha-pc-interix exit ;; 21064:Windows_NT:50:3) echo alpha-dec-winnt3.5 exit ;; Amiga*:UNIX_System_V:4.0:*) echo m68k-unknown-sysv4 exit ;; *:[Aa]miga[Oo][Ss]:*:*) echo ${UNAME_MACHINE}-unknown-amigaos exit ;; *:[Mm]orph[Oo][Ss]:*:*) echo ${UNAME_MACHINE}-unknown-morphos exit ;; *:OS/390:*:*) echo i370-ibm-openedition exit ;; *:z/VM:*:*) echo s390-ibm-zvmoe exit ;; *:OS400:*:*) echo powerpc-ibm-os400 exit ;; arm:RISC*:1.[012]*:*|arm:riscix:1.[012]*:*) echo arm-acorn-riscix${UNAME_RELEASE} exit ;; arm:riscos:*:*|arm:RISCOS:*:*) echo arm-unknown-riscos exit ;; SR2?01:HI-UX/MPP:*:* | SR8000:HI-UX/MPP:*:*) echo hppa1.1-hitachi-hiuxmpp exit ;; Pyramid*:OSx*:*:* | MIS*:OSx*:*:* | MIS*:SMP_DC-OSx*:*:*) # akee@wpdis03.wpafb.af.mil (Earle F. Ake) contributed MIS and NILE. if test "`(/bin/universe) 2>/dev/null`" = att ; then echo pyramid-pyramid-sysv3 else echo pyramid-pyramid-bsd fi exit ;; NILE*:*:*:dcosx) echo pyramid-pyramid-svr4 exit ;; DRS?6000:unix:4.0:6*) echo sparc-icl-nx6 exit ;; DRS?6000:UNIX_SV:4.2*:7* | DRS?6000:isis:4.2*:7*) case `/usr/bin/uname -p` in sparc) echo sparc-icl-nx7; exit ;; esac ;; s390x:SunOS:*:*) echo ${UNAME_MACHINE}-ibm-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` exit ;; sun4H:SunOS:5.*:*) echo sparc-hal-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` exit ;; sun4*:SunOS:5.*:* | tadpole*:SunOS:5.*:*) echo sparc-sun-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` exit ;; i86pc:AuroraUX:5.*:* | i86xen:AuroraUX:5.*:*) echo i386-pc-auroraux${UNAME_RELEASE} exit ;; i86pc:SunOS:5.*:* | i86xen:SunOS:5.*:*) eval $set_cc_for_build SUN_ARCH="i386" # If there is a compiler, see if it is configured for 64-bit objects. # Note that the Sun cc does not turn __LP64__ into 1 like gcc does. # This test works for both compilers. if [ "$CC_FOR_BUILD" != 'no_compiler_found' ]; then if (echo '#ifdef __amd64'; echo IS_64BIT_ARCH; echo '#endif') | \ (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) | \ grep IS_64BIT_ARCH >/dev/null then SUN_ARCH="x86_64" fi fi echo ${SUN_ARCH}-pc-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` exit ;; sun4*:SunOS:6*:*) # According to config.sub, this is the proper way to canonicalize # SunOS6. Hard to guess exactly what SunOS6 will be like, but # it's likely to be more like Solaris than SunOS4. echo sparc-sun-solaris3`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` exit ;; sun4*:SunOS:*:*) case "`/usr/bin/arch -k`" in Series*|S4*) UNAME_RELEASE=`uname -v` ;; esac # Japanese Language versions have a version number like `4.1.3-JL'. echo sparc-sun-sunos`echo ${UNAME_RELEASE}|sed -e 's/-/_/'` exit ;; sun3*:SunOS:*:*) echo m68k-sun-sunos${UNAME_RELEASE} exit ;; sun*:*:4.2BSD:*) UNAME_RELEASE=`(sed 1q /etc/motd | awk '{print substr($5,1,3)}') 2>/dev/null` test "x${UNAME_RELEASE}" = "x" && UNAME_RELEASE=3 case "`/bin/arch`" in sun3) echo m68k-sun-sunos${UNAME_RELEASE} ;; sun4) echo sparc-sun-sunos${UNAME_RELEASE} ;; esac exit ;; aushp:SunOS:*:*) echo sparc-auspex-sunos${UNAME_RELEASE} exit ;; # The situation for MiNT is a little confusing. The machine name # can be virtually everything (everything which is not # "atarist" or "atariste" at least should have a processor # > m68000). The system name ranges from "MiNT" over "FreeMiNT" # to the lowercase version "mint" (or "freemint"). Finally # the system name "TOS" denotes a system which is actually not # MiNT. But MiNT is downward compatible to TOS, so this should # be no problem. atarist[e]:*MiNT:*:* | atarist[e]:*mint:*:* | atarist[e]:*TOS:*:*) echo m68k-atari-mint${UNAME_RELEASE} exit ;; atari*:*MiNT:*:* | atari*:*mint:*:* | atarist[e]:*TOS:*:*) echo m68k-atari-mint${UNAME_RELEASE} exit ;; *falcon*:*MiNT:*:* | *falcon*:*mint:*:* | *falcon*:*TOS:*:*) echo m68k-atari-mint${UNAME_RELEASE} exit ;; milan*:*MiNT:*:* | milan*:*mint:*:* | *milan*:*TOS:*:*) echo m68k-milan-mint${UNAME_RELEASE} exit ;; hades*:*MiNT:*:* | hades*:*mint:*:* | *hades*:*TOS:*:*) echo m68k-hades-mint${UNAME_RELEASE} exit ;; *:*MiNT:*:* | *:*mint:*:* | *:*TOS:*:*) echo m68k-unknown-mint${UNAME_RELEASE} exit ;; m68k:machten:*:*) echo m68k-apple-machten${UNAME_RELEASE} exit ;; powerpc:machten:*:*) echo powerpc-apple-machten${UNAME_RELEASE} exit ;; RISC*:Mach:*:*) echo mips-dec-mach_bsd4.3 exit ;; RISC*:ULTRIX:*:*) echo mips-dec-ultrix${UNAME_RELEASE} exit ;; VAX*:ULTRIX*:*:*) echo vax-dec-ultrix${UNAME_RELEASE} exit ;; 2020:CLIX:*:* | 2430:CLIX:*:*) echo clipper-intergraph-clix${UNAME_RELEASE} exit ;; mips:*:*:UMIPS | mips:*:*:RISCos) eval $set_cc_for_build sed 's/^ //' << EOF >$dummy.c #ifdef __cplusplus #include /* for printf() prototype */ int main (int argc, char *argv[]) { #else int main (argc, argv) int argc; char *argv[]; { #endif #if defined (host_mips) && defined (MIPSEB) #if defined (SYSTYPE_SYSV) printf ("mips-mips-riscos%ssysv\n", argv[1]); exit (0); #endif #if defined (SYSTYPE_SVR4) printf ("mips-mips-riscos%ssvr4\n", argv[1]); exit (0); #endif #if defined (SYSTYPE_BSD43) || defined(SYSTYPE_BSD) printf ("mips-mips-riscos%sbsd\n", argv[1]); exit (0); #endif #endif exit (-1); } EOF $CC_FOR_BUILD -o $dummy $dummy.c && dummyarg=`echo "${UNAME_RELEASE}" | sed -n 's/\([0-9]*\).*/\1/p'` && SYSTEM_NAME=`$dummy $dummyarg` && { echo "$SYSTEM_NAME"; exit; } echo mips-mips-riscos${UNAME_RELEASE} exit ;; Motorola:PowerMAX_OS:*:*) echo powerpc-motorola-powermax exit ;; Motorola:*:4.3:PL8-*) echo powerpc-harris-powermax exit ;; Night_Hawk:*:*:PowerMAX_OS | Synergy:PowerMAX_OS:*:*) echo powerpc-harris-powermax exit ;; Night_Hawk:Power_UNIX:*:*) echo powerpc-harris-powerunix exit ;; m88k:CX/UX:7*:*) echo m88k-harris-cxux7 exit ;; m88k:*:4*:R4*) echo m88k-motorola-sysv4 exit ;; m88k:*:3*:R3*) echo m88k-motorola-sysv3 exit ;; AViiON:dgux:*:*) # DG/UX returns AViiON for all architectures UNAME_PROCESSOR=`/usr/bin/uname -p` if [ $UNAME_PROCESSOR = mc88100 ] || [ $UNAME_PROCESSOR = mc88110 ] then if [ ${TARGET_BINARY_INTERFACE}x = m88kdguxelfx ] || \ [ ${TARGET_BINARY_INTERFACE}x = x ] then echo m88k-dg-dgux${UNAME_RELEASE} else echo m88k-dg-dguxbcs${UNAME_RELEASE} fi else echo i586-dg-dgux${UNAME_RELEASE} fi exit ;; M88*:DolphinOS:*:*) # DolphinOS (SVR3) echo m88k-dolphin-sysv3 exit ;; M88*:*:R3*:*) # Delta 88k system running SVR3 echo m88k-motorola-sysv3 exit ;; XD88*:*:*:*) # Tektronix XD88 system running UTekV (SVR3) echo m88k-tektronix-sysv3 exit ;; Tek43[0-9][0-9]:UTek:*:*) # Tektronix 4300 system running UTek (BSD) echo m68k-tektronix-bsd exit ;; *:IRIX*:*:*) echo mips-sgi-irix`echo ${UNAME_RELEASE}|sed -e 's/-/_/g'` exit ;; ????????:AIX?:[12].1:2) # AIX 2.2.1 or AIX 2.1.1 is RT/PC AIX. echo romp-ibm-aix # uname -m gives an 8 hex-code CPU id exit ;; # Note that: echo "'`uname -s`'" gives 'AIX ' i*86:AIX:*:*) echo i386-ibm-aix exit ;; ia64:AIX:*:*) if [ -x /usr/bin/oslevel ] ; then IBM_REV=`/usr/bin/oslevel` else IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE} fi echo ${UNAME_MACHINE}-ibm-aix${IBM_REV} exit ;; *:AIX:2:3) if grep bos325 /usr/include/stdio.h >/dev/null 2>&1; then eval $set_cc_for_build sed 's/^ //' << EOF >$dummy.c #include main() { if (!__power_pc()) exit(1); puts("powerpc-ibm-aix3.2.5"); exit(0); } EOF if $CC_FOR_BUILD -o $dummy $dummy.c && SYSTEM_NAME=`$dummy` then echo "$SYSTEM_NAME" else echo rs6000-ibm-aix3.2.5 fi elif grep bos324 /usr/include/stdio.h >/dev/null 2>&1; then echo rs6000-ibm-aix3.2.4 else echo rs6000-ibm-aix3.2 fi exit ;; *:AIX:*:[4567]) IBM_CPU_ID=`/usr/sbin/lsdev -C -c processor -S available | sed 1q | awk '{ print $1 }'` if /usr/sbin/lsattr -El ${IBM_CPU_ID} | grep ' POWER' >/dev/null 2>&1; then IBM_ARCH=rs6000 else IBM_ARCH=powerpc fi if [ -x /usr/bin/oslevel ] ; then IBM_REV=`/usr/bin/oslevel` else IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE} fi echo ${IBM_ARCH}-ibm-aix${IBM_REV} exit ;; *:AIX:*:*) echo rs6000-ibm-aix exit ;; ibmrt:4.4BSD:*|romp-ibm:BSD:*) echo romp-ibm-bsd4.4 exit ;; ibmrt:*BSD:*|romp-ibm:BSD:*) # covers RT/PC BSD and echo romp-ibm-bsd${UNAME_RELEASE} # 4.3 with uname added to exit ;; # report: romp-ibm BSD 4.3 *:BOSX:*:*) echo rs6000-bull-bosx exit ;; DPX/2?00:B.O.S.:*:*) echo m68k-bull-sysv3 exit ;; 9000/[34]??:4.3bsd:1.*:*) echo m68k-hp-bsd exit ;; hp300:4.4BSD:*:* | 9000/[34]??:4.3bsd:2.*:*) echo m68k-hp-bsd4.4 exit ;; 9000/[34678]??:HP-UX:*:*) HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'` case "${UNAME_MACHINE}" in 9000/31? ) HP_ARCH=m68000 ;; 9000/[34]?? ) HP_ARCH=m68k ;; 9000/[678][0-9][0-9]) if [ -x /usr/bin/getconf ]; then sc_cpu_version=`/usr/bin/getconf SC_CPU_VERSION 2>/dev/null` sc_kernel_bits=`/usr/bin/getconf SC_KERNEL_BITS 2>/dev/null` case "${sc_cpu_version}" in 523) HP_ARCH="hppa1.0" ;; # CPU_PA_RISC1_0 528) HP_ARCH="hppa1.1" ;; # CPU_PA_RISC1_1 532) # CPU_PA_RISC2_0 case "${sc_kernel_bits}" in 32) HP_ARCH="hppa2.0n" ;; 64) HP_ARCH="hppa2.0w" ;; '') HP_ARCH="hppa2.0" ;; # HP-UX 10.20 esac ;; esac fi if [ "${HP_ARCH}" = "" ]; then eval $set_cc_for_build sed 's/^ //' << EOF >$dummy.c #define _HPUX_SOURCE #include #include int main () { #if defined(_SC_KERNEL_BITS) long bits = sysconf(_SC_KERNEL_BITS); #endif long cpu = sysconf (_SC_CPU_VERSION); switch (cpu) { case CPU_PA_RISC1_0: puts ("hppa1.0"); break; case CPU_PA_RISC1_1: puts ("hppa1.1"); break; case CPU_PA_RISC2_0: #if defined(_SC_KERNEL_BITS) switch (bits) { case 64: puts ("hppa2.0w"); break; case 32: puts ("hppa2.0n"); break; default: puts ("hppa2.0"); break; } break; #else /* !defined(_SC_KERNEL_BITS) */ puts ("hppa2.0"); break; #endif default: puts ("hppa1.0"); break; } exit (0); } EOF (CCOPTS= $CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null) && HP_ARCH=`$dummy` test -z "$HP_ARCH" && HP_ARCH=hppa fi ;; esac if [ ${HP_ARCH} = "hppa2.0w" ] then eval $set_cc_for_build # hppa2.0w-hp-hpux* has a 64-bit kernel and a compiler generating # 32-bit code. hppa64-hp-hpux* has the same kernel and a compiler # generating 64-bit code. GNU and HP use different nomenclature: # # $ CC_FOR_BUILD=cc ./config.guess # => hppa2.0w-hp-hpux11.23 # $ CC_FOR_BUILD="cc +DA2.0w" ./config.guess # => hppa64-hp-hpux11.23 if echo __LP64__ | (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) | grep -q __LP64__ then HP_ARCH="hppa2.0w" else HP_ARCH="hppa64" fi fi echo ${HP_ARCH}-hp-hpux${HPUX_REV} exit ;; ia64:HP-UX:*:*) HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'` echo ia64-hp-hpux${HPUX_REV} exit ;; 3050*:HI-UX:*:*) eval $set_cc_for_build sed 's/^ //' << EOF >$dummy.c #include int main () { long cpu = sysconf (_SC_CPU_VERSION); /* The order matters, because CPU_IS_HP_MC68K erroneously returns true for CPU_PA_RISC1_0. CPU_IS_PA_RISC returns correct results, however. */ if (CPU_IS_PA_RISC (cpu)) { switch (cpu) { case CPU_PA_RISC1_0: puts ("hppa1.0-hitachi-hiuxwe2"); break; case CPU_PA_RISC1_1: puts ("hppa1.1-hitachi-hiuxwe2"); break; case CPU_PA_RISC2_0: puts ("hppa2.0-hitachi-hiuxwe2"); break; default: puts ("hppa-hitachi-hiuxwe2"); break; } } else if (CPU_IS_HP_MC68K (cpu)) puts ("m68k-hitachi-hiuxwe2"); else puts ("unknown-hitachi-hiuxwe2"); exit (0); } EOF $CC_FOR_BUILD -o $dummy $dummy.c && SYSTEM_NAME=`$dummy` && { echo "$SYSTEM_NAME"; exit; } echo unknown-hitachi-hiuxwe2 exit ;; 9000/7??:4.3bsd:*:* | 9000/8?[79]:4.3bsd:*:* ) echo hppa1.1-hp-bsd exit ;; 9000/8??:4.3bsd:*:*) echo hppa1.0-hp-bsd exit ;; *9??*:MPE/iX:*:* | *3000*:MPE/iX:*:*) echo hppa1.0-hp-mpeix exit ;; hp7??:OSF1:*:* | hp8?[79]:OSF1:*:* ) echo hppa1.1-hp-osf exit ;; hp8??:OSF1:*:*) echo hppa1.0-hp-osf exit ;; i*86:OSF1:*:*) if [ -x /usr/sbin/sysversion ] ; then echo ${UNAME_MACHINE}-unknown-osf1mk else echo ${UNAME_MACHINE}-unknown-osf1 fi exit ;; parisc*:Lites*:*:*) echo hppa1.1-hp-lites exit ;; C1*:ConvexOS:*:* | convex:ConvexOS:C1*:*) echo c1-convex-bsd exit ;; C2*:ConvexOS:*:* | convex:ConvexOS:C2*:*) if getsysinfo -f scalar_acc then echo c32-convex-bsd else echo c2-convex-bsd fi exit ;; C34*:ConvexOS:*:* | convex:ConvexOS:C34*:*) echo c34-convex-bsd exit ;; C38*:ConvexOS:*:* | convex:ConvexOS:C38*:*) echo c38-convex-bsd exit ;; C4*:ConvexOS:*:* | convex:ConvexOS:C4*:*) echo c4-convex-bsd exit ;; CRAY*Y-MP:*:*:*) echo ymp-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' exit ;; CRAY*[A-Z]90:*:*:*) echo ${UNAME_MACHINE}-cray-unicos${UNAME_RELEASE} \ | sed -e 's/CRAY.*\([A-Z]90\)/\1/' \ -e y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/ \ -e 's/\.[^.]*$/.X/' exit ;; CRAY*TS:*:*:*) echo t90-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' exit ;; CRAY*T3E:*:*:*) echo alphaev5-cray-unicosmk${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' exit ;; CRAY*SV1:*:*:*) echo sv1-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' exit ;; *:UNICOS/mp:*:*) echo craynv-cray-unicosmp${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' exit ;; F30[01]:UNIX_System_V:*:* | F700:UNIX_System_V:*:*) FUJITSU_PROC=`uname -m | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'` FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'` FUJITSU_REL=`echo ${UNAME_RELEASE} | sed -e 's/ /_/'` echo "${FUJITSU_PROC}-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}" exit ;; 5000:UNIX_System_V:4.*:*) FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'` FUJITSU_REL=`echo ${UNAME_RELEASE} | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/ /_/'` echo "sparc-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}" exit ;; i*86:BSD/386:*:* | i*86:BSD/OS:*:* | *:Ascend\ Embedded/OS:*:*) echo ${UNAME_MACHINE}-pc-bsdi${UNAME_RELEASE} exit ;; sparc*:BSD/OS:*:*) echo sparc-unknown-bsdi${UNAME_RELEASE} exit ;; *:BSD/OS:*:*) echo ${UNAME_MACHINE}-unknown-bsdi${UNAME_RELEASE} exit ;; *:FreeBSD:*:*) UNAME_PROCESSOR=`/usr/bin/uname -p` case ${UNAME_PROCESSOR} in amd64) echo x86_64-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;; *) echo ${UNAME_PROCESSOR}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;; esac exit ;; i*:CYGWIN*:*) echo ${UNAME_MACHINE}-pc-cygwin exit ;; *:MINGW*:*) echo ${UNAME_MACHINE}-pc-mingw32 exit ;; i*:MSYS*:*) echo ${UNAME_MACHINE}-pc-msys exit ;; i*:windows32*:*) # uname -m includes "-pc" on this system. echo ${UNAME_MACHINE}-mingw32 exit ;; i*:PW*:*) echo ${UNAME_MACHINE}-pc-pw32 exit ;; *:Interix*:*) case ${UNAME_MACHINE} in x86) echo i586-pc-interix${UNAME_RELEASE} exit ;; authenticamd | genuineintel | EM64T) echo x86_64-unknown-interix${UNAME_RELEASE} exit ;; IA64) echo ia64-unknown-interix${UNAME_RELEASE} exit ;; esac ;; [345]86:Windows_95:* | [345]86:Windows_98:* | [345]86:Windows_NT:*) echo i${UNAME_MACHINE}-pc-mks exit ;; 8664:Windows_NT:*) echo x86_64-pc-mks exit ;; i*:Windows_NT*:* | Pentium*:Windows_NT*:*) # How do we know it's Interix rather than the generic POSIX subsystem? # It also conflicts with pre-2.0 versions of AT&T UWIN. Should we # UNAME_MACHINE based on the output of uname instead of i386? echo i586-pc-interix exit ;; i*:UWIN*:*) echo ${UNAME_MACHINE}-pc-uwin exit ;; amd64:CYGWIN*:*:* | x86_64:CYGWIN*:*:*) echo x86_64-unknown-cygwin exit ;; p*:CYGWIN*:*) echo powerpcle-unknown-cygwin exit ;; prep*:SunOS:5.*:*) echo powerpcle-unknown-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` exit ;; *:GNU:*:*) # the GNU system echo `echo ${UNAME_MACHINE}|sed -e 's,[-/].*$,,'`-unknown-gnu`echo ${UNAME_RELEASE}|sed -e 's,/.*$,,'` exit ;; *:GNU/*:*:*) # other systems with GNU libc and userland echo ${UNAME_MACHINE}-unknown-`echo ${UNAME_SYSTEM} | sed 's,^[^/]*/,,' | tr '[A-Z]' '[a-z]'``echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`-gnu exit ;; i*86:Minix:*:*) echo ${UNAME_MACHINE}-pc-minix exit ;; aarch64:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-gnu exit ;; aarch64_be:Linux:*:*) UNAME_MACHINE=aarch64_be echo ${UNAME_MACHINE}-unknown-linux-gnu exit ;; alpha:Linux:*:*) case `sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' < /proc/cpuinfo` in EV5) UNAME_MACHINE=alphaev5 ;; EV56) UNAME_MACHINE=alphaev56 ;; PCA56) UNAME_MACHINE=alphapca56 ;; PCA57) UNAME_MACHINE=alphapca56 ;; EV6) UNAME_MACHINE=alphaev6 ;; EV67) UNAME_MACHINE=alphaev67 ;; EV68*) UNAME_MACHINE=alphaev68 ;; esac objdump --private-headers /bin/sh | grep -q ld.so.1 if test "$?" = 0 ; then LIBC="libc1" ; else LIBC="" ; fi echo ${UNAME_MACHINE}-unknown-linux-gnu${LIBC} exit ;; arm*:Linux:*:*) eval $set_cc_for_build if echo __ARM_EABI__ | $CC_FOR_BUILD -E - 2>/dev/null \ | grep -q __ARM_EABI__ then echo ${UNAME_MACHINE}-unknown-linux-gnu else if echo __ARM_PCS_VFP | $CC_FOR_BUILD -E - 2>/dev/null \ | grep -q __ARM_PCS_VFP then echo ${UNAME_MACHINE}-unknown-linux-gnueabi else echo ${UNAME_MACHINE}-unknown-linux-gnueabihf fi fi exit ;; avr32*:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-gnu exit ;; cris:Linux:*:*) echo ${UNAME_MACHINE}-axis-linux-gnu exit ;; crisv32:Linux:*:*) echo ${UNAME_MACHINE}-axis-linux-gnu exit ;; frv:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-gnu exit ;; hexagon:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-gnu exit ;; i*86:Linux:*:*) LIBC=gnu eval $set_cc_for_build sed 's/^ //' << EOF >$dummy.c #ifdef __dietlibc__ LIBC=dietlibc #endif EOF eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep '^LIBC'` echo "${UNAME_MACHINE}-pc-linux-${LIBC}" exit ;; ia64:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-gnu exit ;; m32r*:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-gnu exit ;; m68*:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-gnu exit ;; mips:Linux:*:* | mips64:Linux:*:*) eval $set_cc_for_build sed 's/^ //' << EOF >$dummy.c #undef CPU #undef ${UNAME_MACHINE} #undef ${UNAME_MACHINE}el #if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL) CPU=${UNAME_MACHINE}el #else #if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB) CPU=${UNAME_MACHINE} #else CPU= #endif #endif EOF eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep '^CPU'` test x"${CPU}" != x && { echo "${CPU}-unknown-linux-gnu"; exit; } ;; or32:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-gnu exit ;; padre:Linux:*:*) echo sparc-unknown-linux-gnu exit ;; parisc64:Linux:*:* | hppa64:Linux:*:*) echo hppa64-unknown-linux-gnu exit ;; parisc:Linux:*:* | hppa:Linux:*:*) # Look for CPU level case `grep '^cpu[^a-z]*:' /proc/cpuinfo 2>/dev/null | cut -d' ' -f2` in PA7*) echo hppa1.1-unknown-linux-gnu ;; PA8*) echo hppa2.0-unknown-linux-gnu ;; *) echo hppa-unknown-linux-gnu ;; esac exit ;; ppc64:Linux:*:*) echo powerpc64-unknown-linux-gnu exit ;; ppc:Linux:*:*) echo powerpc-unknown-linux-gnu exit ;; s390:Linux:*:* | s390x:Linux:*:*) echo ${UNAME_MACHINE}-ibm-linux exit ;; sh64*:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-gnu exit ;; sh*:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-gnu exit ;; sparc:Linux:*:* | sparc64:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-gnu exit ;; tile*:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-gnu exit ;; vax:Linux:*:*) echo ${UNAME_MACHINE}-dec-linux-gnu exit ;; x86_64:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-gnu exit ;; xtensa*:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-gnu exit ;; i*86:DYNIX/ptx:4*:*) # ptx 4.0 does uname -s correctly, with DYNIX/ptx in there. # earlier versions are messed up and put the nodename in both # sysname and nodename. echo i386-sequent-sysv4 exit ;; i*86:UNIX_SV:4.2MP:2.*) # Unixware is an offshoot of SVR4, but it has its own version # number series starting with 2... # I am not positive that other SVR4 systems won't match this, # I just have to hope. -- rms. # Use sysv4.2uw... so that sysv4* matches it. echo ${UNAME_MACHINE}-pc-sysv4.2uw${UNAME_VERSION} exit ;; i*86:OS/2:*:*) # If we were able to find `uname', then EMX Unix compatibility # is probably installed. echo ${UNAME_MACHINE}-pc-os2-emx exit ;; i*86:XTS-300:*:STOP) echo ${UNAME_MACHINE}-unknown-stop exit ;; i*86:atheos:*:*) echo ${UNAME_MACHINE}-unknown-atheos exit ;; i*86:syllable:*:*) echo ${UNAME_MACHINE}-pc-syllable exit ;; i*86:LynxOS:2.*:* | i*86:LynxOS:3.[01]*:* | i*86:LynxOS:4.[02]*:*) echo i386-unknown-lynxos${UNAME_RELEASE} exit ;; i*86:*DOS:*:*) echo ${UNAME_MACHINE}-pc-msdosdjgpp exit ;; i*86:*:4.*:* | i*86:SYSTEM_V:4.*:*) UNAME_REL=`echo ${UNAME_RELEASE} | sed 's/\/MP$//'` if grep Novell /usr/include/link.h >/dev/null 2>/dev/null; then echo ${UNAME_MACHINE}-univel-sysv${UNAME_REL} else echo ${UNAME_MACHINE}-pc-sysv${UNAME_REL} fi exit ;; i*86:*:5:[678]*) # UnixWare 7.x, OpenUNIX and OpenServer 6. case `/bin/uname -X | grep "^Machine"` in *486*) UNAME_MACHINE=i486 ;; *Pentium) UNAME_MACHINE=i586 ;; *Pent*|*Celeron) UNAME_MACHINE=i686 ;; esac echo ${UNAME_MACHINE}-unknown-sysv${UNAME_RELEASE}${UNAME_SYSTEM}${UNAME_VERSION} exit ;; i*86:*:3.2:*) if test -f /usr/options/cb.name; then UNAME_REL=`sed -n 's/.*Version //p' /dev/null >/dev/null ; then UNAME_REL=`(/bin/uname -X|grep Release|sed -e 's/.*= //')` (/bin/uname -X|grep i80486 >/dev/null) && UNAME_MACHINE=i486 (/bin/uname -X|grep '^Machine.*Pentium' >/dev/null) \ && UNAME_MACHINE=i586 (/bin/uname -X|grep '^Machine.*Pent *II' >/dev/null) \ && UNAME_MACHINE=i686 (/bin/uname -X|grep '^Machine.*Pentium Pro' >/dev/null) \ && UNAME_MACHINE=i686 echo ${UNAME_MACHINE}-pc-sco$UNAME_REL else echo ${UNAME_MACHINE}-pc-sysv32 fi exit ;; pc:*:*:*) # Left here for compatibility: # uname -m prints for DJGPP always 'pc', but it prints nothing about # the processor, so we play safe by assuming i586. # Note: whatever this is, it MUST be the same as what config.sub # prints for the "djgpp" host, or else GDB configury will decide that # this is a cross-build. echo i586-pc-msdosdjgpp exit ;; Intel:Mach:3*:*) echo i386-pc-mach3 exit ;; paragon:*:*:*) echo i860-intel-osf1 exit ;; i860:*:4.*:*) # i860-SVR4 if grep Stardent /usr/include/sys/uadmin.h >/dev/null 2>&1 ; then echo i860-stardent-sysv${UNAME_RELEASE} # Stardent Vistra i860-SVR4 else # Add other i860-SVR4 vendors below as they are discovered. echo i860-unknown-sysv${UNAME_RELEASE} # Unknown i860-SVR4 fi exit ;; mini*:CTIX:SYS*5:*) # "miniframe" echo m68010-convergent-sysv exit ;; mc68k:UNIX:SYSTEM5:3.51m) echo m68k-convergent-sysv exit ;; M680?0:D-NIX:5.3:*) echo m68k-diab-dnix exit ;; M68*:*:R3V[5678]*:*) test -r /sysV68 && { echo 'm68k-motorola-sysv'; exit; } ;; 3[345]??:*:4.0:3.0 | 3[34]??A:*:4.0:3.0 | 3[34]??,*:*:4.0:3.0 | 3[34]??/*:*:4.0:3.0 | 4400:*:4.0:3.0 | 4850:*:4.0:3.0 | SKA40:*:4.0:3.0 | SDS2:*:4.0:3.0 | SHG2:*:4.0:3.0 | S7501*:*:4.0:3.0) OS_REL='' test -r /etc/.relid \ && OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid` /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ && { echo i486-ncr-sysv4.3${OS_REL}; exit; } /bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \ && { echo i586-ncr-sysv4.3${OS_REL}; exit; } ;; 3[34]??:*:4.0:* | 3[34]??,*:*:4.0:*) /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ && { echo i486-ncr-sysv4; exit; } ;; NCR*:*:4.2:* | MPRAS*:*:4.2:*) OS_REL='.3' test -r /etc/.relid \ && OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid` /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ && { echo i486-ncr-sysv4.3${OS_REL}; exit; } /bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \ && { echo i586-ncr-sysv4.3${OS_REL}; exit; } /bin/uname -p 2>/dev/null | /bin/grep pteron >/dev/null \ && { echo i586-ncr-sysv4.3${OS_REL}; exit; } ;; m68*:LynxOS:2.*:* | m68*:LynxOS:3.0*:*) echo m68k-unknown-lynxos${UNAME_RELEASE} exit ;; mc68030:UNIX_System_V:4.*:*) echo m68k-atari-sysv4 exit ;; TSUNAMI:LynxOS:2.*:*) echo sparc-unknown-lynxos${UNAME_RELEASE} exit ;; rs6000:LynxOS:2.*:*) echo rs6000-unknown-lynxos${UNAME_RELEASE} exit ;; PowerPC:LynxOS:2.*:* | PowerPC:LynxOS:3.[01]*:* | PowerPC:LynxOS:4.[02]*:*) echo powerpc-unknown-lynxos${UNAME_RELEASE} exit ;; SM[BE]S:UNIX_SV:*:*) echo mips-dde-sysv${UNAME_RELEASE} exit ;; RM*:ReliantUNIX-*:*:*) echo mips-sni-sysv4 exit ;; RM*:SINIX-*:*:*) echo mips-sni-sysv4 exit ;; *:SINIX-*:*:*) if uname -p 2>/dev/null >/dev/null ; then UNAME_MACHINE=`(uname -p) 2>/dev/null` echo ${UNAME_MACHINE}-sni-sysv4 else echo ns32k-sni-sysv fi exit ;; PENTIUM:*:4.0*:*) # Unisys `ClearPath HMP IX 4000' SVR4/MP effort # says echo i586-unisys-sysv4 exit ;; *:UNIX_System_V:4*:FTX*) # From Gerald Hewes . # How about differentiating between stratus architectures? -djm echo hppa1.1-stratus-sysv4 exit ;; *:*:*:FTX*) # From seanf@swdc.stratus.com. echo i860-stratus-sysv4 exit ;; i*86:VOS:*:*) # From Paul.Green@stratus.com. echo ${UNAME_MACHINE}-stratus-vos exit ;; *:VOS:*:*) # From Paul.Green@stratus.com. echo hppa1.1-stratus-vos exit ;; mc68*:A/UX:*:*) echo m68k-apple-aux${UNAME_RELEASE} exit ;; news*:NEWS-OS:6*:*) echo mips-sony-newsos6 exit ;; R[34]000:*System_V*:*:* | R4000:UNIX_SYSV:*:* | R*000:UNIX_SV:*:*) if [ -d /usr/nec ]; then echo mips-nec-sysv${UNAME_RELEASE} else echo mips-unknown-sysv${UNAME_RELEASE} fi exit ;; BeBox:BeOS:*:*) # BeOS running on hardware made by Be, PPC only. echo powerpc-be-beos exit ;; BeMac:BeOS:*:*) # BeOS running on Mac or Mac clone, PPC only. echo powerpc-apple-beos exit ;; BePC:BeOS:*:*) # BeOS running on Intel PC compatible. echo i586-pc-beos exit ;; BePC:Haiku:*:*) # Haiku running on Intel PC compatible. echo i586-pc-haiku exit ;; SX-4:SUPER-UX:*:*) echo sx4-nec-superux${UNAME_RELEASE} exit ;; SX-5:SUPER-UX:*:*) echo sx5-nec-superux${UNAME_RELEASE} exit ;; SX-6:SUPER-UX:*:*) echo sx6-nec-superux${UNAME_RELEASE} exit ;; SX-7:SUPER-UX:*:*) echo sx7-nec-superux${UNAME_RELEASE} exit ;; SX-8:SUPER-UX:*:*) echo sx8-nec-superux${UNAME_RELEASE} exit ;; SX-8R:SUPER-UX:*:*) echo sx8r-nec-superux${UNAME_RELEASE} exit ;; Power*:Rhapsody:*:*) echo powerpc-apple-rhapsody${UNAME_RELEASE} exit ;; *:Rhapsody:*:*) echo ${UNAME_MACHINE}-apple-rhapsody${UNAME_RELEASE} exit ;; *:Darwin:*:*) UNAME_PROCESSOR=`uname -p` || UNAME_PROCESSOR=unknown case $UNAME_PROCESSOR in i386) eval $set_cc_for_build if [ "$CC_FOR_BUILD" != 'no_compiler_found' ]; then if (echo '#ifdef __LP64__'; echo IS_64BIT_ARCH; echo '#endif') | \ (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) | \ grep IS_64BIT_ARCH >/dev/null then UNAME_PROCESSOR="x86_64" fi fi ;; unknown) UNAME_PROCESSOR=powerpc ;; esac echo ${UNAME_PROCESSOR}-apple-darwin${UNAME_RELEASE} exit ;; *:procnto*:*:* | *:QNX:[0123456789]*:*) UNAME_PROCESSOR=`uname -p` if test "$UNAME_PROCESSOR" = "x86"; then UNAME_PROCESSOR=i386 UNAME_MACHINE=pc fi echo ${UNAME_PROCESSOR}-${UNAME_MACHINE}-nto-qnx${UNAME_RELEASE} exit ;; *:QNX:*:4*) echo i386-pc-qnx exit ;; NEO-?:NONSTOP_KERNEL:*:*) echo neo-tandem-nsk${UNAME_RELEASE} exit ;; NSE-?:NONSTOP_KERNEL:*:*) echo nse-tandem-nsk${UNAME_RELEASE} exit ;; NSR-?:NONSTOP_KERNEL:*:*) echo nsr-tandem-nsk${UNAME_RELEASE} exit ;; *:NonStop-UX:*:*) echo mips-compaq-nonstopux exit ;; BS2000:POSIX*:*:*) echo bs2000-siemens-sysv exit ;; DS/*:UNIX_System_V:*:*) echo ${UNAME_MACHINE}-${UNAME_SYSTEM}-${UNAME_RELEASE} exit ;; *:Plan9:*:*) # "uname -m" is not consistent, so use $cputype instead. 386 # is converted to i386 for consistency with other x86 # operating systems. if test "$cputype" = "386"; then UNAME_MACHINE=i386 else UNAME_MACHINE="$cputype" fi echo ${UNAME_MACHINE}-unknown-plan9 exit ;; *:TOPS-10:*:*) echo pdp10-unknown-tops10 exit ;; *:TENEX:*:*) echo pdp10-unknown-tenex exit ;; KS10:TOPS-20:*:* | KL10:TOPS-20:*:* | TYPE4:TOPS-20:*:*) echo pdp10-dec-tops20 exit ;; XKL-1:TOPS-20:*:* | TYPE5:TOPS-20:*:*) echo pdp10-xkl-tops20 exit ;; *:TOPS-20:*:*) echo pdp10-unknown-tops20 exit ;; *:ITS:*:*) echo pdp10-unknown-its exit ;; SEI:*:*:SEIUX) echo mips-sei-seiux${UNAME_RELEASE} exit ;; *:DragonFly:*:*) echo ${UNAME_MACHINE}-unknown-dragonfly`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` exit ;; *:*VMS:*:*) UNAME_MACHINE=`(uname -p) 2>/dev/null` case "${UNAME_MACHINE}" in A*) echo alpha-dec-vms ; exit ;; I*) echo ia64-dec-vms ; exit ;; V*) echo vax-dec-vms ; exit ;; esac ;; *:XENIX:*:SysV) echo i386-pc-xenix exit ;; i*86:skyos:*:*) echo ${UNAME_MACHINE}-pc-skyos`echo ${UNAME_RELEASE}` | sed -e 's/ .*$//' exit ;; i*86:rdos:*:*) echo ${UNAME_MACHINE}-pc-rdos exit ;; i*86:AROS:*:*) echo ${UNAME_MACHINE}-pc-aros exit ;; x86_64:VMkernel:*:*) echo ${UNAME_MACHINE}-unknown-esx exit ;; esac #echo '(No uname command or uname output not recognized.)' 1>&2 #echo "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" 1>&2 eval $set_cc_for_build cat >$dummy.c < # include #endif main () { #if defined (sony) #if defined (MIPSEB) /* BFD wants "bsd" instead of "newsos". Perhaps BFD should be changed, I don't know.... */ printf ("mips-sony-bsd\n"); exit (0); #else #include printf ("m68k-sony-newsos%s\n", #ifdef NEWSOS4 "4" #else "" #endif ); exit (0); #endif #endif #if defined (__arm) && defined (__acorn) && defined (__unix) printf ("arm-acorn-riscix\n"); exit (0); #endif #if defined (hp300) && !defined (hpux) printf ("m68k-hp-bsd\n"); exit (0); #endif #if defined (NeXT) #if !defined (__ARCHITECTURE__) #define __ARCHITECTURE__ "m68k" #endif int version; version=`(hostinfo | sed -n 's/.*NeXT Mach \([0-9]*\).*/\1/p') 2>/dev/null`; if (version < 4) printf ("%s-next-nextstep%d\n", __ARCHITECTURE__, version); else printf ("%s-next-openstep%d\n", __ARCHITECTURE__, version); exit (0); #endif #if defined (MULTIMAX) || defined (n16) #if defined (UMAXV) printf ("ns32k-encore-sysv\n"); exit (0); #else #if defined (CMU) printf ("ns32k-encore-mach\n"); exit (0); #else printf ("ns32k-encore-bsd\n"); exit (0); #endif #endif #endif #if defined (__386BSD__) printf ("i386-pc-bsd\n"); exit (0); #endif #if defined (sequent) #if defined (i386) printf ("i386-sequent-dynix\n"); exit (0); #endif #if defined (ns32000) printf ("ns32k-sequent-dynix\n"); exit (0); #endif #endif #if defined (_SEQUENT_) struct utsname un; uname(&un); if (strncmp(un.version, "V2", 2) == 0) { printf ("i386-sequent-ptx2\n"); exit (0); } if (strncmp(un.version, "V1", 2) == 0) { /* XXX is V1 correct? */ printf ("i386-sequent-ptx1\n"); exit (0); } printf ("i386-sequent-ptx\n"); exit (0); #endif #if defined (vax) # if !defined (ultrix) # include # if defined (BSD) # if BSD == 43 printf ("vax-dec-bsd4.3\n"); exit (0); # else # if BSD == 199006 printf ("vax-dec-bsd4.3reno\n"); exit (0); # else printf ("vax-dec-bsd\n"); exit (0); # endif # endif # else printf ("vax-dec-bsd\n"); exit (0); # endif # else printf ("vax-dec-ultrix\n"); exit (0); # endif #endif #if defined (alliant) && defined (i860) printf ("i860-alliant-bsd\n"); exit (0); #endif exit (1); } EOF $CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null && SYSTEM_NAME=`$dummy` && { echo "$SYSTEM_NAME"; exit; } # Apollos put the system type in the environment. test -d /usr/apollo && { echo ${ISP}-apollo-${SYSTYPE}; exit; } # Convex versions that predate uname can use getsysinfo(1) if [ -x /usr/convex/getsysinfo ] then case `getsysinfo -f cpu_type` in c1*) echo c1-convex-bsd exit ;; c2*) if getsysinfo -f scalar_acc then echo c32-convex-bsd else echo c2-convex-bsd fi exit ;; c34*) echo c34-convex-bsd exit ;; c38*) echo c38-convex-bsd exit ;; c4*) echo c4-convex-bsd exit ;; esac fi cat >&2 < in order to provide the needed information to handle your system. config.guess timestamp = $timestamp uname -m = `(uname -m) 2>/dev/null || echo unknown` uname -r = `(uname -r) 2>/dev/null || echo unknown` uname -s = `(uname -s) 2>/dev/null || echo unknown` uname -v = `(uname -v) 2>/dev/null || echo unknown` /usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null` /bin/uname -X = `(/bin/uname -X) 2>/dev/null` hostinfo = `(hostinfo) 2>/dev/null` /bin/universe = `(/bin/universe) 2>/dev/null` /usr/bin/arch -k = `(/usr/bin/arch -k) 2>/dev/null` /bin/arch = `(/bin/arch) 2>/dev/null` /usr/bin/oslevel = `(/usr/bin/oslevel) 2>/dev/null` /usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null` UNAME_MACHINE = ${UNAME_MACHINE} UNAME_RELEASE = ${UNAME_RELEASE} UNAME_SYSTEM = ${UNAME_SYSTEM} UNAME_VERSION = ${UNAME_VERSION} EOF exit 1 # Local variables: # eval: (add-hook 'write-file-hooks 'time-stamp) # time-stamp-start: "timestamp='" # time-stamp-format: "%:y-%02m-%02d" # time-stamp-end: "'" # End: sftpserver-0.2.1/config.aux/depcomp0000755000175000000000000005064311777117217014262 00000000000000#! /bin/sh # depcomp - compile a program generating dependencies as side-effects scriptversion=2012-03-27.16; # UTC # Copyright (C) 1999, 2000, 2003, 2004, 2005, 2006, 2007, 2009, 2010, # 2011, 2012 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 2, 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 . # As a special exception to the GNU General Public License, if you # distribute this file as part of a program that contains a # configuration script generated by Autoconf, you may include it under # the same distribution terms that you use for the rest of that program. # Originally written by Alexandre Oliva . case $1 in '') echo "$0: No command. Try '$0 --help' for more information." 1>&2 exit 1; ;; -h | --h*) cat <<\EOF Usage: depcomp [--help] [--version] PROGRAM [ARGS] Run PROGRAMS ARGS to compile a file, generating dependencies as side-effects. Environment variables: depmode Dependency tracking mode. source Source file read by 'PROGRAMS ARGS'. object Object file output by 'PROGRAMS ARGS'. DEPDIR directory where to store dependencies. depfile Dependency file to output. tmpdepfile Temporary file to use when outputting dependencies. libtool Whether libtool is used (yes/no). Report bugs to . EOF exit $? ;; -v | --v*) echo "depcomp $scriptversion" exit $? ;; esac # A tabulation character. tab=' ' # A newline character. nl=' ' if test -z "$depmode" || test -z "$source" || test -z "$object"; then echo "depcomp: Variables source, object and depmode must be set" 1>&2 exit 1 fi # Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po. depfile=${depfile-`echo "$object" | sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`} tmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`} rm -f "$tmpdepfile" # Some modes work just like other modes, but use different flags. We # parameterize here, but still list the modes in the big case below, # to make depend.m4 easier to write. Note that we *cannot* use a case # here, because this file can only contain one case statement. if test "$depmode" = hp; then # HP compiler uses -M and no extra arg. gccflag=-M depmode=gcc fi if test "$depmode" = dashXmstdout; then # This is just like dashmstdout with a different argument. dashmflag=-xM depmode=dashmstdout fi cygpath_u="cygpath -u -f -" if test "$depmode" = msvcmsys; then # This is just like msvisualcpp but w/o cygpath translation. # Just convert the backslash-escaped backslashes to single forward # slashes to satisfy depend.m4 cygpath_u='sed s,\\\\,/,g' depmode=msvisualcpp fi if test "$depmode" = msvc7msys; then # This is just like msvc7 but w/o cygpath translation. # Just convert the backslash-escaped backslashes to single forward # slashes to satisfy depend.m4 cygpath_u='sed s,\\\\,/,g' depmode=msvc7 fi if test "$depmode" = xlc; then # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency informations. gccflag=-qmakedep=gcc,-MF depmode=gcc fi case "$depmode" in gcc3) ## gcc 3 implements dependency tracking that does exactly what ## we want. Yay! Note: for some reason libtool 1.4 doesn't like ## it if -MD -MP comes after the -MF stuff. Hmm. ## Unfortunately, FreeBSD c89 acceptance of flags depends upon ## the command line argument order; so add the flags where they ## appear in depend2.am. Note that the slowdown incurred here ## affects only configure: in makefiles, %FASTDEP% shortcuts this. for arg do case $arg in -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;; *) set fnord "$@" "$arg" ;; esac shift # fnord shift # $arg done "$@" stat=$? if test $stat -eq 0; then : else rm -f "$tmpdepfile" exit $stat fi mv "$tmpdepfile" "$depfile" ;; gcc) ## There are various ways to get dependency output from gcc. Here's ## why we pick this rather obscure method: ## - Don't want to use -MD because we'd like the dependencies to end ## up in a subdir. Having to rename by hand is ugly. ## (We might end up doing this anyway to support other compilers.) ## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like ## -MM, not -M (despite what the docs say). ## - Using -M directly means running the compiler twice (even worse ## than renaming). if test -z "$gccflag"; then gccflag=-MD, fi "$@" -Wp,"$gccflag$tmpdepfile" stat=$? if test $stat -eq 0; then : else rm -f "$tmpdepfile" exit $stat fi rm -f "$depfile" echo "$object : \\" > "$depfile" alpha=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz ## The second -e expression handles DOS-style file names with drive letters. sed -e 's/^[^:]*: / /' \ -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile" ## This next piece of magic avoids the "deleted header file" problem. ## The problem is that when a header file which appears in a .P file ## is deleted, the dependency causes make to die (because there is ## typically no way to rebuild the header). We avoid this by adding ## dummy dependencies for each header file. Too bad gcc doesn't do ## this for us directly. tr ' ' "$nl" < "$tmpdepfile" | ## Some versions of gcc put a space before the ':'. On the theory ## that the space means something, we add a space to the output as ## well. hp depmode also adds that space, but also prefixes the VPATH ## to the object. Take care to not repeat it in the output. ## Some versions of the HPUX 10.20 sed can't process this invocation ## correctly. Breaking it into two sed invocations is a workaround. sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \ | sed -e 's/$/ :/' >> "$depfile" rm -f "$tmpdepfile" ;; hp) # This case exists only to let depend.m4 do its work. It works by # looking at the text of this script. This case will never be run, # since it is checked for above. exit 1 ;; sgi) if test "$libtool" = yes; then "$@" "-Wp,-MDupdate,$tmpdepfile" else "$@" -MDupdate "$tmpdepfile" fi stat=$? if test $stat -eq 0; then : else rm -f "$tmpdepfile" exit $stat fi rm -f "$depfile" if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files echo "$object : \\" > "$depfile" # Clip off the initial element (the dependent). Don't try to be # clever and replace this with sed code, as IRIX sed won't handle # lines with more than a fixed number of characters (4096 in # IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines; # the IRIX cc adds comments like '#:fec' to the end of the # dependency line. tr ' ' "$nl" < "$tmpdepfile" \ | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' | \ tr "$nl" ' ' >> "$depfile" echo >> "$depfile" # The second pass generates a dummy entry for each header file. tr ' ' "$nl" < "$tmpdepfile" \ | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \ >> "$depfile" else # The sourcefile does not contain any dependencies, so just # store a dummy comment line, to avoid errors with the Makefile # "include basename.Plo" scheme. echo "#dummy" > "$depfile" fi rm -f "$tmpdepfile" ;; xlc) # This case exists only to let depend.m4 do its work. It works by # looking at the text of this script. This case will never be run, # since it is checked for above. exit 1 ;; aix) # The C for AIX Compiler uses -M and outputs the dependencies # in a .u file. In older versions, this file always lives in the # current directory. Also, the AIX compiler puts '$object:' at the # start of each line; $object doesn't have directory information. # Version 6 uses the directory in both cases. dir=`echo "$object" | sed -e 's|/[^/]*$|/|'` test "x$dir" = "x$object" && dir= base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'` if test "$libtool" = yes; then tmpdepfile1=$dir$base.u tmpdepfile2=$base.u tmpdepfile3=$dir.libs/$base.u "$@" -Wc,-M else tmpdepfile1=$dir$base.u tmpdepfile2=$dir$base.u tmpdepfile3=$dir$base.u "$@" -M fi stat=$? if test $stat -eq 0; then : else rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" exit $stat fi for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" do test -f "$tmpdepfile" && break done if test -f "$tmpdepfile"; then # Each line is of the form 'foo.o: dependent.h'. # Do two passes, one to just change these to # '$object: dependent.h' and one to simply 'dependent.h:'. sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile" sed -e 's,^.*\.[a-z]*:['"$tab"' ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile" else # The sourcefile does not contain any dependencies, so just # store a dummy comment line, to avoid errors with the Makefile # "include basename.Plo" scheme. echo "#dummy" > "$depfile" fi rm -f "$tmpdepfile" ;; icc) # Intel's C compiler anf tcc (Tiny C Compiler) understand '-MD -MF file'. # However on # $CC -MD -MF foo.d -c -o sub/foo.o sub/foo.c # ICC 7.0 will fill foo.d with something like # foo.o: sub/foo.c # foo.o: sub/foo.h # which is wrong. We want # sub/foo.o: sub/foo.c # sub/foo.o: sub/foo.h # sub/foo.c: # sub/foo.h: # ICC 7.1 will output # foo.o: sub/foo.c sub/foo.h # and will wrap long lines using '\': # foo.o: sub/foo.c ... \ # sub/foo.h ... \ # ... # tcc 0.9.26 (FIXME still under development at the moment of writing) # will emit a similar output, but also prepend the continuation lines # with horizontal tabulation characters. "$@" -MD -MF "$tmpdepfile" stat=$? if test $stat -eq 0; then : else rm -f "$tmpdepfile" exit $stat fi rm -f "$depfile" # Each line is of the form 'foo.o: dependent.h', # or 'foo.o: dep1.h dep2.h \', or ' dep3.h dep4.h \'. # Do two passes, one to just change these to # '$object: dependent.h' and one to simply 'dependent.h:'. sed -e "s/^[ $tab][ $tab]*/ /" -e "s,^[^:]*:,$object :," \ < "$tmpdepfile" > "$depfile" sed ' s/[ '"$tab"'][ '"$tab"']*/ /g s/^ *// s/ *\\*$// s/^[^:]*: *// /^$/d /:$/d s/$/ :/ ' < "$tmpdepfile" >> "$depfile" rm -f "$tmpdepfile" ;; hp2) # The "hp" stanza above does not work with aCC (C++) and HP's ia64 # compilers, which have integrated preprocessors. The correct option # to use with these is +Maked; it writes dependencies to a file named # 'foo.d', which lands next to the object file, wherever that # happens to be. # Much of this is similar to the tru64 case; see comments there. dir=`echo "$object" | sed -e 's|/[^/]*$|/|'` test "x$dir" = "x$object" && dir= base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'` if test "$libtool" = yes; then tmpdepfile1=$dir$base.d tmpdepfile2=$dir.libs/$base.d "$@" -Wc,+Maked else tmpdepfile1=$dir$base.d tmpdepfile2=$dir$base.d "$@" +Maked fi stat=$? if test $stat -eq 0; then : else rm -f "$tmpdepfile1" "$tmpdepfile2" exit $stat fi for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" do test -f "$tmpdepfile" && break done if test -f "$tmpdepfile"; then sed -e "s,^.*\.[a-z]*:,$object:," "$tmpdepfile" > "$depfile" # Add 'dependent.h:' lines. sed -ne '2,${ s/^ *// s/ \\*$// s/$/:/ p }' "$tmpdepfile" >> "$depfile" else echo "#dummy" > "$depfile" fi rm -f "$tmpdepfile" "$tmpdepfile2" ;; tru64) # The Tru64 compiler uses -MD to generate dependencies as a side # effect. 'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'. # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put # dependencies in 'foo.d' instead, so we check for that too. # Subdirectories are respected. dir=`echo "$object" | sed -e 's|/[^/]*$|/|'` test "x$dir" = "x$object" && dir= base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'` if test "$libtool" = yes; then # With Tru64 cc, shared objects can also be used to make a # static library. This mechanism is used in libtool 1.4 series to # handle both shared and static libraries in a single compilation. # With libtool 1.4, dependencies were output in $dir.libs/$base.lo.d. # # With libtool 1.5 this exception was removed, and libtool now # generates 2 separate objects for the 2 libraries. These two # compilations output dependencies in $dir.libs/$base.o.d and # in $dir$base.o.d. We have to check for both files, because # one of the two compilations can be disabled. We should prefer # $dir$base.o.d over $dir.libs/$base.o.d because the latter is # automatically cleaned when .libs/ is deleted, while ignoring # the former would cause a distcleancheck panic. tmpdepfile1=$dir.libs/$base.lo.d # libtool 1.4 tmpdepfile2=$dir$base.o.d # libtool 1.5 tmpdepfile3=$dir.libs/$base.o.d # libtool 1.5 tmpdepfile4=$dir.libs/$base.d # Compaq CCC V6.2-504 "$@" -Wc,-MD else tmpdepfile1=$dir$base.o.d tmpdepfile2=$dir$base.d tmpdepfile3=$dir$base.d tmpdepfile4=$dir$base.d "$@" -MD fi stat=$? if test $stat -eq 0; then : else rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4" exit $stat fi for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4" do test -f "$tmpdepfile" && break done if test -f "$tmpdepfile"; then sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile" sed -e 's,^.*\.[a-z]*:['"$tab"' ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile" else echo "#dummy" > "$depfile" fi rm -f "$tmpdepfile" ;; msvc7) if test "$libtool" = yes; then showIncludes=-Wc,-showIncludes else showIncludes=-showIncludes fi "$@" $showIncludes > "$tmpdepfile" stat=$? grep -v '^Note: including file: ' "$tmpdepfile" if test "$stat" = 0; then : else rm -f "$tmpdepfile" exit $stat fi rm -f "$depfile" echo "$object : \\" > "$depfile" # The first sed program below extracts the file names and escapes # backslashes for cygpath. The second sed program outputs the file # name when reading, but also accumulates all include files in the # hold buffer in order to output them again at the end. This only # works with sed implementations that can handle large buffers. sed < "$tmpdepfile" -n ' /^Note: including file: *\(.*\)/ { s//\1/ s/\\/\\\\/g p }' | $cygpath_u | sort -u | sed -n ' s/ /\\ /g s/\(.*\)/'"$tab"'\1 \\/p s/.\(.*\) \\/\1:/ H $ { s/.*/'"$tab"'/ G p }' >> "$depfile" rm -f "$tmpdepfile" ;; msvc7msys) # This case exists only to let depend.m4 do its work. It works by # looking at the text of this script. This case will never be run, # since it is checked for above. exit 1 ;; #nosideeffect) # This comment above is used by automake to tell side-effect # dependency tracking mechanisms from slower ones. dashmstdout) # Important note: in order to support this mode, a compiler *must* # always write the preprocessed file to stdout, regardless of -o. "$@" || exit $? # Remove the call to Libtool. if test "$libtool" = yes; then while test "X$1" != 'X--mode=compile'; do shift done shift fi # Remove '-o $object'. IFS=" " for arg do case $arg in -o) shift ;; $object) shift ;; *) set fnord "$@" "$arg" shift # fnord shift # $arg ;; esac done test -z "$dashmflag" && dashmflag=-M # Require at least two characters before searching for ':' # in the target name. This is to cope with DOS-style filenames: # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise. "$@" $dashmflag | sed 's:^['"$tab"' ]*[^:'"$tab"' ][^:][^:]*\:['"$tab"' ]*:'"$object"'\: :' > "$tmpdepfile" rm -f "$depfile" cat < "$tmpdepfile" > "$depfile" tr ' ' "$nl" < "$tmpdepfile" | \ ## Some versions of the HPUX 10.20 sed can't process this invocation ## correctly. Breaking it into two sed invocations is a workaround. sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile" rm -f "$tmpdepfile" ;; dashXmstdout) # This case only exists to satisfy depend.m4. It is never actually # run, as this mode is specially recognized in the preamble. exit 1 ;; makedepend) "$@" || exit $? # Remove any Libtool call if test "$libtool" = yes; then while test "X$1" != 'X--mode=compile'; do shift done shift fi # X makedepend shift cleared=no eat=no for arg do case $cleared in no) set ""; shift cleared=yes ;; esac if test $eat = yes; then eat=no continue fi case "$arg" in -D*|-I*) set fnord "$@" "$arg"; shift ;; # Strip any option that makedepend may not understand. Remove # the object too, otherwise makedepend will parse it as a source file. -arch) eat=yes ;; -*|$object) ;; *) set fnord "$@" "$arg"; shift ;; esac done obj_suffix=`echo "$object" | sed 's/^.*\././'` touch "$tmpdepfile" ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@" rm -f "$depfile" # makedepend may prepend the VPATH from the source file name to the object. # No need to regex-escape $object, excess matching of '.' is harmless. sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile" sed '1,2d' "$tmpdepfile" | tr ' ' "$nl" | \ ## Some versions of the HPUX 10.20 sed can't process this invocation ## correctly. Breaking it into two sed invocations is a workaround. sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile" rm -f "$tmpdepfile" "$tmpdepfile".bak ;; cpp) # Important note: in order to support this mode, a compiler *must* # always write the preprocessed file to stdout. "$@" || exit $? # Remove the call to Libtool. if test "$libtool" = yes; then while test "X$1" != 'X--mode=compile'; do shift done shift fi # Remove '-o $object'. IFS=" " for arg do case $arg in -o) shift ;; $object) shift ;; *) set fnord "$@" "$arg" shift # fnord shift # $arg ;; esac done "$@" -E | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' | sed '$ s: \\$::' > "$tmpdepfile" rm -f "$depfile" echo "$object : \\" > "$depfile" cat < "$tmpdepfile" >> "$depfile" sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile" rm -f "$tmpdepfile" ;; msvisualcpp) # Important note: in order to support this mode, a compiler *must* # always write the preprocessed file to stdout. "$@" || exit $? # Remove the call to Libtool. if test "$libtool" = yes; then while test "X$1" != 'X--mode=compile'; do shift done shift fi IFS=" " for arg do case "$arg" in -o) shift ;; $object) shift ;; "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI") set fnord "$@" shift shift ;; *) set fnord "$@" "$arg" shift shift ;; esac done "$@" -E 2>/dev/null | sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile" rm -f "$depfile" echo "$object : \\" > "$depfile" sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile" echo "$tab" >> "$depfile" sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile" rm -f "$tmpdepfile" ;; msvcmsys) # This case exists only to let depend.m4 do its work. It works by # looking at the text of this script. This case will never be run, # since it is checked for above. exit 1 ;; none) exec "$@" ;; *) echo "Unknown depmode $depmode" 1>&2 exit 1 ;; esac exit 0 # Local Variables: # mode: shell-script # sh-indentation: 2 # eval: (add-hook 'write-file-hooks 'time-stamp) # time-stamp-start: "scriptversion=" # time-stamp-format: "%:y-%02m-%02d.%02H" # time-stamp-time-zone: "UTC" # time-stamp-end: "; # UTC" # End: sftpserver-0.2.1/config.aux/missing0000755000175000000000000002415211777117217014300 00000000000000#! /bin/sh # Common stub for a few missing GNU programs while installing. scriptversion=2012-01-06.13; # UTC # Copyright (C) 1996, 1997, 1999, 2000, 2002, 2003, 2004, 2005, 2006, # 2008, 2009, 2010, 2011, 2012 Free Software Foundation, Inc. # Originally by Fran,cois Pinard , 1996. # 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 2, 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 . # As a special exception to the GNU General Public License, if you # distribute this file as part of a program that contains a # configuration script generated by Autoconf, you may include it under # the same distribution terms that you use for the rest of that program. if test $# -eq 0; then echo 1>&2 "Try \`$0 --help' for more information" exit 1 fi run=: sed_output='s/.* --output[ =]\([^ ]*\).*/\1/p' sed_minuso='s/.* -o \([^ ]*\).*/\1/p' # In the cases where this matters, `missing' is being run in the # srcdir already. if test -f configure.ac; then configure_ac=configure.ac else configure_ac=configure.in fi msg="missing on your system" case $1 in --run) # Try to run requested program, and just exit if it succeeds. run= shift "$@" && exit 0 # Exit code 63 means version mismatch. This often happens # when the user try to use an ancient version of a tool on # a file that requires a minimum version. In this case we # we should proceed has if the program had been absent, or # if --run hadn't been passed. if test $? = 63; then run=: msg="probably too old" fi ;; -h|--h|--he|--hel|--help) echo "\ $0 [OPTION]... PROGRAM [ARGUMENT]... Handle \`PROGRAM [ARGUMENT]...' for when PROGRAM is missing, or return an error status if there is no known handling for PROGRAM. Options: -h, --help display this help and exit -v, --version output version information and exit --run try to run the given command, and emulate it if it fails Supported PROGRAM values: aclocal touch file \`aclocal.m4' autoconf touch file \`configure' autoheader touch file \`config.h.in' autom4te touch the output file, or create a stub one automake touch all \`Makefile.in' files bison create \`y.tab.[ch]', if possible, from existing .[ch] flex create \`lex.yy.c', if possible, from existing .c help2man touch the output file lex create \`lex.yy.c', if possible, from existing .c makeinfo touch the output file yacc create \`y.tab.[ch]', if possible, from existing .[ch] Version suffixes to PROGRAM as well as the prefixes \`gnu-', \`gnu', and \`g' are ignored when checking the name. Send bug reports to ." exit $? ;; -v|--v|--ve|--ver|--vers|--versi|--versio|--version) echo "missing $scriptversion (GNU Automake)" exit $? ;; -*) echo 1>&2 "$0: Unknown \`$1' option" echo 1>&2 "Try \`$0 --help' for more information" exit 1 ;; esac # normalize program name to check for. program=`echo "$1" | sed ' s/^gnu-//; t s/^gnu//; t s/^g//; t'` # Now exit if we have it, but it failed. Also exit now if we # don't have it and --version was passed (most likely to detect # the program). This is about non-GNU programs, so use $1 not # $program. case $1 in lex*|yacc*) # Not GNU programs, they don't have --version. ;; *) if test -z "$run" && ($1 --version) > /dev/null 2>&1; then # We have it, but it failed. exit 1 elif test "x$2" = "x--version" || test "x$2" = "x--help"; then # Could not run --version or --help. This is probably someone # running `$TOOL --version' or `$TOOL --help' to check whether # $TOOL exists and not knowing $TOOL uses missing. exit 1 fi ;; esac # If it does not exist, or fails to run (possibly an outdated version), # try to emulate it. case $program in aclocal*) echo 1>&2 "\ WARNING: \`$1' is $msg. You should only need it if you modified \`acinclude.m4' or \`${configure_ac}'. You might want to install the \`Automake' and \`Perl' packages. Grab them from any GNU archive site." touch aclocal.m4 ;; autoconf*) echo 1>&2 "\ WARNING: \`$1' is $msg. You should only need it if you modified \`${configure_ac}'. You might want to install the \`Autoconf' and \`GNU m4' packages. Grab them from any GNU archive site." touch configure ;; autoheader*) echo 1>&2 "\ WARNING: \`$1' is $msg. You should only need it if you modified \`acconfig.h' or \`${configure_ac}'. You might want to install the \`Autoconf' and \`GNU m4' packages. Grab them from any GNU archive site." files=`sed -n 's/^[ ]*A[CM]_CONFIG_HEADER(\([^)]*\)).*/\1/p' ${configure_ac}` test -z "$files" && files="config.h" touch_files= for f in $files; do case $f in *:*) touch_files="$touch_files "`echo "$f" | sed -e 's/^[^:]*://' -e 's/:.*//'`;; *) touch_files="$touch_files $f.in";; esac done touch $touch_files ;; automake*) echo 1>&2 "\ WARNING: \`$1' is $msg. You should only need it if you modified \`Makefile.am', \`acinclude.m4' or \`${configure_ac}'. You might want to install the \`Automake' and \`Perl' packages. Grab them from any GNU archive site." find . -type f -name Makefile.am -print | sed 's/\.am$/.in/' | while read f; do touch "$f"; done ;; autom4te*) echo 1>&2 "\ WARNING: \`$1' is needed, but is $msg. You might have modified some files without having the proper tools for further handling them. You can get \`$1' as part of \`Autoconf' from any GNU archive site." file=`echo "$*" | sed -n "$sed_output"` test -z "$file" && file=`echo "$*" | sed -n "$sed_minuso"` if test -f "$file"; then touch $file else test -z "$file" || exec >$file echo "#! /bin/sh" echo "# Created by GNU Automake missing as a replacement of" echo "# $ $@" echo "exit 0" chmod +x $file exit 1 fi ;; bison*|yacc*) echo 1>&2 "\ WARNING: \`$1' $msg. You should only need it if you modified a \`.y' file. You may need the \`Bison' package in order for those modifications to take effect. You can get \`Bison' from any GNU archive site." rm -f y.tab.c y.tab.h if test $# -ne 1; then eval LASTARG=\${$#} case $LASTARG in *.y) SRCFILE=`echo "$LASTARG" | sed 's/y$/c/'` if test -f "$SRCFILE"; then cp "$SRCFILE" y.tab.c fi SRCFILE=`echo "$LASTARG" | sed 's/y$/h/'` if test -f "$SRCFILE"; then cp "$SRCFILE" y.tab.h fi ;; esac fi if test ! -f y.tab.h; then echo >y.tab.h fi if test ! -f y.tab.c; then echo 'main() { return 0; }' >y.tab.c fi ;; lex*|flex*) echo 1>&2 "\ WARNING: \`$1' is $msg. You should only need it if you modified a \`.l' file. You may need the \`Flex' package in order for those modifications to take effect. You can get \`Flex' from any GNU archive site." rm -f lex.yy.c if test $# -ne 1; then eval LASTARG=\${$#} case $LASTARG in *.l) SRCFILE=`echo "$LASTARG" | sed 's/l$/c/'` if test -f "$SRCFILE"; then cp "$SRCFILE" lex.yy.c fi ;; esac fi if test ! -f lex.yy.c; then echo 'main() { return 0; }' >lex.yy.c fi ;; help2man*) echo 1>&2 "\ WARNING: \`$1' is $msg. You should only need it if you modified a dependency of a manual page. You may need the \`Help2man' package in order for those modifications to take effect. You can get \`Help2man' from any GNU archive site." file=`echo "$*" | sed -n "$sed_output"` test -z "$file" && file=`echo "$*" | sed -n "$sed_minuso"` if test -f "$file"; then touch $file else test -z "$file" || exec >$file echo ".ab help2man is required to generate this page" exit $? fi ;; makeinfo*) echo 1>&2 "\ WARNING: \`$1' is $msg. You should only need it if you modified a \`.texi' or \`.texinfo' file, or any other file indirectly affecting the aspect of the manual. The spurious call might also be the consequence of using a buggy \`make' (AIX, DU, IRIX). You might want to install the \`Texinfo' package or the \`GNU make' package. Grab either from any GNU archive site." # The file to touch is that specified with -o ... file=`echo "$*" | sed -n "$sed_output"` test -z "$file" && file=`echo "$*" | sed -n "$sed_minuso"` if test -z "$file"; then # ... or it is the one specified with @setfilename ... infile=`echo "$*" | sed 's/.* \([^ ]*\) *$/\1/'` file=`sed -n ' /^@setfilename/{ s/.* \([^ ]*\) *$/\1/ p q }' $infile` # ... or it is derived from the source name (dir/f.texi becomes f.info) test -z "$file" && file=`echo "$infile" | sed 's,.*/,,;s,.[^.]*$,,'`.info fi # If the file does not exist, the user really needs makeinfo; # let's fail without touching anything. test -f $file || exit 1 touch $file ;; *) echo 1>&2 "\ WARNING: \`$1' is needed, and is $msg. You might have modified some files without having the proper tools for further handling them. Check the \`README' file, it often tells you about the needed prerequisites for installing this package. You may also peek at any GNU archive site, in case some other package would contain this missing \`$1' program." exit 1 ;; esac exit 0 # Local variables: # eval: (add-hook 'write-file-hooks 'time-stamp) # time-stamp-start: "scriptversion=" # time-stamp-format: "%:y-%02m-%02d.%02H" # time-stamp-time-zone: "UTC" # time-stamp-end: "; # UTC" # End: sftpserver-0.2.1/config.aux/install-sh0000755000175000000000000003325611777117217014712 00000000000000#!/bin/sh # install - install a program, script, or datafile scriptversion=2011-01-19.21; # UTC # This originates from X11R5 (mit/util/scripts/install.sh), which was # later released in X11R6 (xc/config/util/install.sh) with the # following copyright and license. # # Copyright (C) 1994 X Consortium # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to # deal in the Software without restriction, including without limitation the # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or # sell copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN # AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC- # TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # # Except as contained in this notice, the name of the X Consortium shall not # be used in advertising or otherwise to promote the sale, use or other deal- # ings in this Software without prior written authorization from the X Consor- # tium. # # # FSF changes to this file are in the public domain. # # Calling this script install-sh is preferred over install.sh, to prevent # `make' implicit rules from creating a file called install from it # when there is no Makefile. # # This script is compatible with the BSD install script, but was written # from scratch. nl=' ' IFS=" "" $nl" # set DOITPROG to echo to test this script # Don't use :- since 4.3BSD and earlier shells don't like it. doit=${DOITPROG-} if test -z "$doit"; then doit_exec=exec else doit_exec=$doit fi # Put in absolute file names if you don't have them in your path; # or use environment vars. chgrpprog=${CHGRPPROG-chgrp} chmodprog=${CHMODPROG-chmod} chownprog=${CHOWNPROG-chown} cmpprog=${CMPPROG-cmp} cpprog=${CPPROG-cp} mkdirprog=${MKDIRPROG-mkdir} mvprog=${MVPROG-mv} rmprog=${RMPROG-rm} stripprog=${STRIPPROG-strip} posix_glob='?' initialize_posix_glob=' test "$posix_glob" != "?" || { if (set -f) 2>/dev/null; then posix_glob= else posix_glob=: fi } ' posix_mkdir= # Desired mode of installed file. mode=0755 chgrpcmd= chmodcmd=$chmodprog chowncmd= mvcmd=$mvprog rmcmd="$rmprog -f" stripcmd= src= dst= dir_arg= dst_arg= copy_on_change=false no_target_directory= usage="\ Usage: $0 [OPTION]... [-T] SRCFILE DSTFILE or: $0 [OPTION]... SRCFILES... DIRECTORY or: $0 [OPTION]... -t DIRECTORY SRCFILES... or: $0 [OPTION]... -d DIRECTORIES... In the 1st form, copy SRCFILE to DSTFILE. In the 2nd and 3rd, copy all SRCFILES to DIRECTORY. In the 4th, create DIRECTORIES. Options: --help display this help and exit. --version display version info and exit. -c (ignored) -C install only if different (preserve the last data modification time) -d create directories instead of installing files. -g GROUP $chgrpprog installed files to GROUP. -m MODE $chmodprog installed files to MODE. -o USER $chownprog installed files to USER. -s $stripprog installed files. -t DIRECTORY install into DIRECTORY. -T report an error if DSTFILE is a directory. Environment variables override the default commands: CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG RMPROG STRIPPROG " while test $# -ne 0; do case $1 in -c) ;; -C) copy_on_change=true;; -d) dir_arg=true;; -g) chgrpcmd="$chgrpprog $2" shift;; --help) echo "$usage"; exit $?;; -m) mode=$2 case $mode in *' '* | *' '* | *' '* | *'*'* | *'?'* | *'['*) echo "$0: invalid mode: $mode" >&2 exit 1;; esac shift;; -o) chowncmd="$chownprog $2" shift;; -s) stripcmd=$stripprog;; -t) dst_arg=$2 # Protect names problematic for `test' and other utilities. case $dst_arg in -* | [=\(\)!]) dst_arg=./$dst_arg;; esac shift;; -T) no_target_directory=true;; --version) echo "$0 $scriptversion"; exit $?;; --) shift break;; -*) echo "$0: invalid option: $1" >&2 exit 1;; *) break;; esac shift done if test $# -ne 0 && test -z "$dir_arg$dst_arg"; then # When -d is used, all remaining arguments are directories to create. # When -t is used, the destination is already specified. # Otherwise, the last argument is the destination. Remove it from $@. for arg do if test -n "$dst_arg"; then # $@ is not empty: it contains at least $arg. set fnord "$@" "$dst_arg" shift # fnord fi shift # arg dst_arg=$arg # Protect names problematic for `test' and other utilities. case $dst_arg in -* | [=\(\)!]) dst_arg=./$dst_arg;; esac done fi if test $# -eq 0; then if test -z "$dir_arg"; then echo "$0: no input file specified." >&2 exit 1 fi # It's OK to call `install-sh -d' without argument. # This can happen when creating conditional directories. exit 0 fi if test -z "$dir_arg"; then do_exit='(exit $ret); exit $ret' trap "ret=129; $do_exit" 1 trap "ret=130; $do_exit" 2 trap "ret=141; $do_exit" 13 trap "ret=143; $do_exit" 15 # Set umask so as not to create temps with too-generous modes. # However, 'strip' requires both read and write access to temps. case $mode in # Optimize common cases. *644) cp_umask=133;; *755) cp_umask=22;; *[0-7]) if test -z "$stripcmd"; then u_plus_rw= else u_plus_rw='% 200' fi cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;; *) if test -z "$stripcmd"; then u_plus_rw= else u_plus_rw=,u+rw fi cp_umask=$mode$u_plus_rw;; esac fi for src do # Protect names problematic for `test' and other utilities. case $src in -* | [=\(\)!]) src=./$src;; esac if test -n "$dir_arg"; then dst=$src dstdir=$dst test -d "$dstdir" dstdir_status=$? else # Waiting for this to be detected by the "$cpprog $src $dsttmp" command # might cause directories to be created, which would be especially bad # if $src (and thus $dsttmp) contains '*'. if test ! -f "$src" && test ! -d "$src"; then echo "$0: $src does not exist." >&2 exit 1 fi if test -z "$dst_arg"; then echo "$0: no destination specified." >&2 exit 1 fi dst=$dst_arg # If destination is a directory, append the input filename; won't work # if double slashes aren't ignored. if test -d "$dst"; then if test -n "$no_target_directory"; then echo "$0: $dst_arg: Is a directory" >&2 exit 1 fi dstdir=$dst dst=$dstdir/`basename "$src"` dstdir_status=0 else # Prefer dirname, but fall back on a substitute if dirname fails. dstdir=` (dirname "$dst") 2>/dev/null || expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ X"$dst" : 'X\(//\)[^/]' \| \ X"$dst" : 'X\(//\)$' \| \ X"$dst" : 'X\(/\)' \| . 2>/dev/null || echo X"$dst" | sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/ q } /^X\(\/\/\)[^/].*/{ s//\1/ q } /^X\(\/\/\)$/{ s//\1/ q } /^X\(\/\).*/{ s//\1/ q } s/.*/./; q' ` test -d "$dstdir" dstdir_status=$? fi fi obsolete_mkdir_used=false if test $dstdir_status != 0; then case $posix_mkdir in '') # Create intermediate dirs using mode 755 as modified by the umask. # This is like FreeBSD 'install' as of 1997-10-28. umask=`umask` case $stripcmd.$umask in # Optimize common cases. *[2367][2367]) mkdir_umask=$umask;; .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;; *[0-7]) mkdir_umask=`expr $umask + 22 \ - $umask % 100 % 40 + $umask % 20 \ - $umask % 10 % 4 + $umask % 2 `;; *) mkdir_umask=$umask,go-w;; esac # With -d, create the new directory with the user-specified mode. # Otherwise, rely on $mkdir_umask. if test -n "$dir_arg"; then mkdir_mode=-m$mode else mkdir_mode= fi posix_mkdir=false case $umask in *[123567][0-7][0-7]) # POSIX mkdir -p sets u+wx bits regardless of umask, which # is incompatible with FreeBSD 'install' when (umask & 300) != 0. ;; *) tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0 if (umask $mkdir_umask && exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1 then if test -z "$dir_arg" || { # Check for POSIX incompatibilities with -m. # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or # other-writeable bit of parent directory when it shouldn't. # FreeBSD 6.1 mkdir -m -p sets mode of existing directory. ls_ld_tmpdir=`ls -ld "$tmpdir"` case $ls_ld_tmpdir in d????-?r-*) different_mode=700;; d????-?--*) different_mode=755;; *) false;; esac && $mkdirprog -m$different_mode -p -- "$tmpdir" && { ls_ld_tmpdir_1=`ls -ld "$tmpdir"` test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" } } then posix_mkdir=: fi rmdir "$tmpdir/d" "$tmpdir" else # Remove any dirs left behind by ancient mkdir implementations. rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null fi trap '' 0;; esac;; esac if $posix_mkdir && ( umask $mkdir_umask && $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir" ) then : else # The umask is ridiculous, or mkdir does not conform to POSIX, # or it failed possibly due to a race condition. Create the # directory the slow way, step by step, checking for races as we go. case $dstdir in /*) prefix='/';; [-=\(\)!]*) prefix='./';; *) prefix='';; esac eval "$initialize_posix_glob" oIFS=$IFS IFS=/ $posix_glob set -f set fnord $dstdir shift $posix_glob set +f IFS=$oIFS prefixes= for d do test X"$d" = X && continue prefix=$prefix$d if test -d "$prefix"; then prefixes= else if $posix_mkdir; then (umask=$mkdir_umask && $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break # Don't fail if two instances are running concurrently. test -d "$prefix" || exit 1 else case $prefix in *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;; *) qprefix=$prefix;; esac prefixes="$prefixes '$qprefix'" fi fi prefix=$prefix/ done if test -n "$prefixes"; then # Don't fail if two instances are running concurrently. (umask $mkdir_umask && eval "\$doit_exec \$mkdirprog $prefixes") || test -d "$dstdir" || exit 1 obsolete_mkdir_used=true fi fi fi if test -n "$dir_arg"; then { test -z "$chowncmd" || $doit $chowncmd "$dst"; } && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } && { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false || test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1 else # Make a couple of temp file names in the proper directory. dsttmp=$dstdir/_inst.$$_ rmtmp=$dstdir/_rm.$$_ # Trap to clean up those temp files at exit. trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0 # Copy the file name to the temp name. (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") && # and set any options; do chmod last to preserve setuid bits. # # If any of these fail, we abort the whole thing. If we want to # ignore errors from any of these, just make sure not to ignore # errors from the above "$doit $cpprog $src $dsttmp" command. # { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } && { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } && { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } && # If -C, don't bother to copy if it wouldn't change the file. if $copy_on_change && old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` && new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` && eval "$initialize_posix_glob" && $posix_glob set -f && set X $old && old=:$2:$4:$5:$6 && set X $new && new=:$2:$4:$5:$6 && $posix_glob set +f && test "$old" = "$new" && $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1 then rm -f "$dsttmp" else # Rename the file to the real destination. $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null || # The rename failed, perhaps because mv can't rename something else # to itself, or perhaps because mv is so ancient that it does not # support -f. { # Now remove or move aside any old file at destination location. # We try this two ways since rm can't unlink itself on some # systems and the destination file might be busy for other # reasons. In this case, the final cleanup might fail but the new # file should still install successfully. { test ! -f "$dst" || $doit $rmcmd -f "$dst" 2>/dev/null || { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null && { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; } } || { echo "$0: cannot unlink or rename $dst" >&2 (exit 1); exit 1 } } && # Now rename the file to the real destination. $doit $mvcmd "$dsttmp" "$dst" } fi || exit 1 trap '' 0 fi done # Local variables: # eval: (add-hook 'write-file-hooks 'time-stamp) # time-stamp-start: "scriptversion=" # time-stamp-format: "%:y-%02m-%02d.%02H" # time-stamp-time-zone: "UTC" # time-stamp-end: "; # UTC" # End: sftpserver-0.2.1/readlink.c0000664000175000017500000000344311625765051012611 00000000000000/* * This file is part of the Green End SFTP Server. * Copyright (C) 2007 Richard Kettlewell * * 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 2 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, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA */ #include "sftpcommon.h" #include "utils.h" #include "alloc.h" #include "debug.h" #include #include char *sftp_do_readlink(struct allocator *a, const char *path) { size_t nresult = 32, oldnresult = 0; char *result = 0; int n; /* readlink(2) has a rather stupid interface */ while(nresult > 0 && nresult <= 65536) { result = sftp_alloc_more(a, result, oldnresult, nresult); n = readlink(path, result, nresult); if(n < 0) return 0; if((unsigned)n < nresult) { result[n] = 0; return result; } oldnresult = nresult; nresult *= 2; } /* We should have wasted at most about 128Kbyte if we get here, * perhaps less due to use of sftp_alloc_more(). If you have symlinks * with targets bigger than 64K then (i) you'll need to update the * bound above (ii) what color is the sky on your planet? */ errno = E2BIG; return 0; } /* Local Variables: c-basic-offset:2 comment-column:40 fill-column:79 indent-tabs-mode:nil End: */ sftpserver-0.2.1/run-tests0000775000175000017500000001076011626166333012545 00000000000000#! /usr/bin/env python # # This file is part of the Green End SFTP Server. # Copyright (C) 2007, 2011 Richard Kettlewell # # 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 2 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, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 # USA import os,sys,re,string from subprocess import Popen,PIPE,STDOUT srcdir = os.path.abspath(os.getenv('srcdir')) builddir = os.path.abspath('.') client = os.path.abspath("sftpclient") server = "gesftpserver" def rmrf(path): if os.path.lexists(path): if (not os.path.islink(path)) and os.path.isdir(path): os.chmod(path, 0700) for name in os.listdir(path): rmrf(os.path.join(path,name)) os.rmdir(path) else: os.remove(path) def fatal(msg): sys.stderr.write("%s\n" % msg) sys.exit(1) if os.getuid() == 0: fatal("These tests are not suitable for running as root.") os.umask(022) # for consistent permissions failed = 0 protocols = ['2', '3', '4', '5', '6', '7'] dir = 'tests' args = sys.argv[1:] while len(args) > 0 and args[0][0] == '-': if args[0] == "--protocols": protocols = args[1].split(',') args = args[2:] elif args[0] == "--server": server = args[1] args = args[2:] elif args[0] == "--directory": dir = args[1] args = args[2:] else: fatal("unknown option '%s'" % args[0]) server = os.path.abspath(server) if len(args) > 0: tests = args else: tests = os.listdir(os.path.join(srcdir, dir)) tests.sort() # Clean up rmrf(os.path.join(builddir, ',testroot')) for test in tests: for proto in protocols: if ('.' in test or not proto in test or '#' in test or '~' in test): continue sys.stderr.write("Testing %s/%s protocol %s ... " % (dir, test, proto)) root = os.path.join(builddir, ',testroot','%s.%s' % (test, proto)) os.makedirs(root) os.chdir(root) output = Popen([client, "--force-version", proto, "-P", server, "-b", os.path.join(srcdir, dir, test), '--echo', '--fix-sigpipe', # stupid Python '--no-stop-on-error'], stdout=PIPE, stderr=STDOUT).communicate()[0].split('\n') if output[len(output)-1] == "": output = output[:-1] n = 0 errors = [] for expected in file(os.path.join(srcdir, dir, '%s' % test)): expected = expected[:-1] # strip newline if n >= len(output): errors.append("EXPECTED: %s" % expected) errors.append(" GOT: EOF") break got = output[n] n += 1 if len(expected) > 0 and expected[0] == '#': expected = expected[1:] try: if not re.match(expected, got): errors.append("EXPECTED: %s" % expected) errors.append(" GOT: %s" % got) except: print "\n\nPossible invalid regexp:\n%s\n" % expected raise else: if expected != got: errors.append("EXPECTED: %s" % expected) errors.append(" GOT: %s" % got) if n < len(output): errors.append(" EXTRA: %s" % output[n]) if len(errors) > 0: sys.stderr.write("FAILED\n") sys.stderr.write(string.join(errors, '\n')) sys.stderr.write("\n") failed += 1 else: sys.stderr.write("passed\n") if failed: print "%d tests failed" % failed sys.exit(1) else: os.chdir("/") rmrf(os.path.join(builddir, ',testroot')) print "OK" # Local Variables: # mode:python # indent-tabs-mode:nil # py-indent-offset:4 # End: sftpserver-0.2.1/README0000664000175000017500000000707012340114433011517 00000000000000Green End SFTP Server ===================== This is an SFTP server supporting up to protocol version 6. It is possible to use it as a drop-in replacement for the OpenSSH server. Requirements ------------ This software runs under Linux, Mac OS X and FreeBSD. It may work on other UNIX platforms. Installation ------------ The general procedure is: ./configure make # builds software and runs tests make install # probably as root See INSTALL for generic instructions. Local configure options include: --enable-reversed-symlink Some (but annoyingly not all) SFTP clients get the arguments to the symlink operation the wrong way round. This option reverses the server's interpretation of the arguments so that such clients can be made to work (while breaking correctly written clients). --enable-warnings-as-errors Enable treatment of warnings-as-errors. Developers should use this but end users probably don't care. You will need iconv and readline libraries. It's best to run 'make check' before installing, but this requires Python (see http://www.python.org/) and the Paramiko SSH module (see http://www.lag.net/paramiko/) to be installed. Status ------ This server is currently experimental and still under development. Don't trust your critical data to it. The code has an extensive and growing test suite (invoke 'make check' to run it) but bugs may yet remain. The code is written to be secure against malicious clients but not currently tested against malicious clients. In the typical usage pattern for an SFTP server this is academic: why bother exploiting a SFTP server bug when you can log in as the same user? However it is also possible to arrange for the SFTP server to run on a security boundary, for instance listening directly on a TCP port or running under a login that is only allowed to run the SFTP server. Until such time as the test suite is expanded to include actively hostile clients, it is not recommended that this server be used in such configurations without some additional form of protection against malicious use. Online Resources ---------------- Mailing lists: http://www.chiark.greenend.org.uk/mailman/listinfo/sgo-software-discuss - discussion of the server (and others), bug reports, etc http://www.chiark.greenend.org.uk/mailman/listinfo/sgo-software-announce - announcements of new versions Home page: http://www.greenend.org.uk/rjk/sftpserver To get the latest source (to within 24 hours): git clone git://github.com/ewxrjk/sftpserver.git Bugs, Patches, etc ------------------ Please send bug reports, improvements, etc either to sgo-software-discuss (see URL above). If you send patches, please use "diff -u" format. Licence ------- Copyright (C) 2007, 2009-2011, 2014 Richard Kettlewell 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 2 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, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA sftpserver-0.2.1/queue.c0000664000175000017500000000776111626705056012153 00000000000000/* * This file is part of the Green End SFTP Server. * Copyright (C) 2007, 2011 Richard Kettlewell * * 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 2 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, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA */ /** @file queue.h @brief Thread pool/queue implementation */ #include "sftpserver.h" #include "queue.h" #include "alloc.h" #include "debug.h" #include "utils.h" #include "thread.h" #include #include /** @brief One job in a queue */ struct queuejob { /** @brief Next job or a null pointer */ struct queuejob *next; /** @brief Job */ void *job; }; /** @brief Definition of a queue */ struct queue { /** @brief Head of queue */ struct queuejob *jobs; /** @brief Where to store new tail of queue */ struct queuejob **jobstail; /** @brief Mutex protecting queue */ pthread_mutex_t m; /** @brief Condition variable for signaling changes to queue */ pthread_cond_t c; /** @brief Queue-specific callbacks */ const struct queuedetails *details; /** @brief Number of worker threads */ int nthreads; /** @brief Table of worker thread IDs */ pthread_t *threads; /** @brief Set when queue is being destroyed */ int join; }; /** @brief Implementation of worker thread * @param vq Queue pointer * @return A null pointer */ static void *queue_thread(void *vq) { struct queue *const q = vq; struct queuejob *qj; struct allocator a; void *workerdata; workerdata = q->details->init(); ferrcheck(pthread_mutex_lock(&q->m)); while(q->jobs || !q->join) { if(q->jobs) { /* Pick job of front of queue */ qj = q->jobs; if(!(q->jobs = qj->next)) q->jobstail = &q->jobs; /* Don't hold lock while executing job */ ferrcheck(pthread_mutex_unlock(&q->m)); sftp_alloc_init(&a); q->details->worker(qj->job, workerdata, &a); sftp_alloc_destroy(&a); free(qj); ferrcheck(pthread_mutex_lock(&q->m)); } else { /* Nothing's happening, wait for a signal */ ferrcheck(pthread_cond_wait(&q->c, &q->m)); } } ferrcheck(pthread_mutex_unlock(&q->m)); q->details->cleanup(workerdata); return 0; } void queue_init(struct queue **qr, const struct queuedetails *details, int nthreads) { int n; struct queue *q; q = xmalloc(sizeof *q); memset(q, 0, sizeof *q); q->jobs = 0; q->jobstail = &q->jobs; ferrcheck(pthread_mutex_init(&q->m, 0)); ferrcheck(pthread_cond_init(&q->c, 0)); q->details = details; q->nthreads = nthreads; q->threads = xcalloc(nthreads, sizeof (pthread_t)); q->join = 0; for(n = 0; n < q->nthreads; ++n) ferrcheck(pthread_create(&q->threads[n], 0, queue_thread, q)); *qr = q; } void queue_add(struct queue *q, void *job) { struct queuejob *qj; qj = xmalloc(sizeof *qj); qj->next = 0; qj->job = job; ferrcheck(pthread_mutex_lock(&q->m)); *q->jobstail = qj; q->jobstail = &qj->next; ferrcheck(pthread_cond_signal(&q->c)); /* any one thread */ ferrcheck(pthread_mutex_unlock(&q->m)); } void queue_destroy(struct queue *q) { int n; if(q) { ferrcheck(pthread_mutex_lock(&q->m)); q->join = 1; ferrcheck(pthread_cond_broadcast(&q->c)); /* all threads */ ferrcheck(pthread_mutex_unlock(&q->m)); for(n = 0; n < q->nthreads; ++n) ferrcheck(pthread_join(q->threads[n], 0)); free(q->threads); free(q); } } /* Local Variables: c-basic-offset:2 comment-column:40 fill-column:79 indent-tabs-mode:nil End: */ sftpserver-0.2.1/users.c0000664000175000017500000000451511625765051012162 00000000000000/* * This file is part of the Green End SFTP Server. * Copyright (C) 2007 Richard Kettlewell * * 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 2 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, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA */ #include "sftpserver.h" #include "users.h" #include "alloc.h" #include "thread.h" #include "utils.h" #include #include #include #include #include /* We don't rely on the C library doing the right thing */ static pthread_mutex_t user_lock = PTHREAD_MUTEX_INITIALIZER; char *sftp_uid2name(struct allocator *a, uid_t uid) { char *s; const struct passwd *pw; ferrcheck(pthread_mutex_lock(&user_lock)); if((pw = getpwuid(uid))) s = strcpy(sftp_alloc(a, strlen(pw->pw_name) + 1), pw->pw_name); else s = 0; ferrcheck(pthread_mutex_unlock(&user_lock)); return s; } char *sftp_gid2name(struct allocator *a, gid_t gid) { char *s; const struct group *gr; ferrcheck(pthread_mutex_lock(&user_lock)); if((gr = getgrgid(gid))) s = strcpy(sftp_alloc(a, strlen(gr->gr_name) + 1), gr->gr_name); else s = 0; ferrcheck(pthread_mutex_unlock(&user_lock)); return s; } uid_t sftp_name2uid(const char *name) { const struct passwd *pw; uid_t uid; ferrcheck(pthread_mutex_lock(&user_lock)); if((pw = getpwnam(name))) uid = pw->pw_uid; else uid = -1; ferrcheck(pthread_mutex_unlock(&user_lock)); return uid; } gid_t sftp_name2gid(const char *name) { const struct group *gr; gid_t gid; ferrcheck(pthread_mutex_lock(&user_lock)); if((gr = getgrnam(name))) gid = gr->gr_gid; else gid = -1; ferrcheck(pthread_mutex_unlock(&user_lock)); return gid; } /* Local Variables: c-basic-offset:2 comment-column:40 fill-column:79 indent-tabs-mode:nil End: */ sftpserver-0.2.1/utils.c0000664000175000017500000000724011625766222012160 00000000000000/* * This file is part of the Green End SFTP Server. * Copyright (C) 2007, 2010, 2011 Richard Kettlewell * * 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 2 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, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA */ #include "sftpserver.h" #include "utils.h" #include "debug.h" #include "alloc.h" #include #include #include #include #include #include #include #include #include int log_syslog; int do_read(int fd, void *buffer, size_t size) { size_t sofar = 0; ssize_t n; char *ptr = buffer; while(sofar < size) { n = read(fd, ptr + sofar, size - sofar); if(n > 0) sofar += n; else if(n == 0) return -1; /* eof */ else fatal("read error: %s", strerror(errno)); } return 0; /* ok */ } void *xmalloc(size_t n) { void *ptr; if(n) { if(!(ptr = malloc(n))) fatal("xmalloc: out of memory (%zu)", n); return ptr; } else return 0; } void *xcalloc(size_t n, size_t size) { void *ptr; if(n && size) { if(!(ptr = calloc(n, size))) fatal("xcalloc: out of memory (%zu, %zu)", n, size); return ptr; } else return 0; } void *xrecalloc(void *ptr, size_t n, size_t size) { if(n > SIZE_MAX / size) fatal("xrecalloc: out of memory (%zu, %zu)", n, size); n *= size; if(n) { if(!(ptr = realloc(ptr, n))) fatal("xrecalloc: out of memory (%zu)", n); return ptr; } else { free(ptr); return 0; } } void *xrealloc(void *ptr, size_t n) { if(n) { if(!(ptr = realloc(ptr, n))) fatal("xrealloc: out of memory (%zu)", n); return ptr; } else { free(ptr); return 0; } } char *xstrdup(const char *s) { return strcpy(xmalloc(strlen(s) + 1), s); } static void (*exitfn)(int) attribute((noreturn)) = exit; void fatal(const char *msg, ...) { va_list ap; va_start(ap, msg); if(log_syslog) vsyslog(LOG_ERR, msg, ap); else { fprintf(stderr, "FATAL: "); vfprintf(stderr, msg, ap); fputc('\n', stderr); } va_end(ap); exitfn(-1); } void forked(void) { exitfn = _exit; } pid_t xfork(void) { pid_t pid; if((pid = fork()) < 0) fatal("fork: %s", strerror(errno)); if(!pid) forked(); return pid; } char *appendn(struct allocator *a, char *s, size_t *ns, const char *t, size_t lt) { const size_t ls = s ? strlen(s) : 0, need = lt + ls + 1; if(need > *ns) { size_t newsize = *ns ? *ns : 16; while(need > newsize && newsize) newsize *= 2; if(!newsize) fatal("appendn: out of memory (%zu, %zu)", ls, need); s = sftp_alloc_more(a, s, *ns, newsize); *ns = newsize; } else { // need should always be at least 1 so need<=*ns => *ns > 0 => s != 0. assert(s); } memcpy(s + ls, t, lt); s[ls + lt] = 0; return s; } char *append(struct allocator *a, char *s, size_t *ns, const char *t) { return appendn(a, s, ns, t, strlen(t)); } /* Local Variables: c-basic-offset:2 comment-column:40 fill-column:79 indent-tabs-mode:nil End: */ sftpserver-0.2.1/getopt.h0000664000175000017500000001334511625765051012331 00000000000000/* Declarations for getopt. Copyright (C) 1989,90,91,92,93,94,96,97,98 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. The GNU C Library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with the GNU C Library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef _GETOPT_H #ifndef __need_getopt # define _GETOPT_H 1 #endif #ifdef __cplusplus extern "C" { #endif /* For communication from `getopt' to the caller. When `getopt' finds an option that takes an argument, the argument value is returned here. Also, when `ordering' is RETURN_IN_ORDER, each non-option ARGV-element is returned here. */ extern char *optarg; /* Index in ARGV of the next element to be scanned. This is used for communication to and from the caller and for communication between successive calls to `getopt'. On entry to `getopt', zero means this is the first call; initialize. When `getopt' returns -1, this is the index of the first of the non-option elements that the caller should itself scan. Otherwise, `optind' communicates from one call to the next how much of ARGV has been scanned so far. */ extern int optind; /* Callers store zero here to inhibit the error message `getopt' prints for unrecognized options. */ extern int opterr; /* Set to an option character which was unrecognized. */ extern int optopt; #ifndef __need_getopt /* Describe the long-named options requested by the application. The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector of `struct option' terminated by an element containing a name which is zero. The field `has_arg' is: no_argument (or 0) if the option does not take an argument, required_argument (or 1) if the option requires an argument, optional_argument (or 2) if the option takes an optional argument. If the field `flag' is not NULL, it points to a variable that is set to the value given in the field `val' when the option is found, but left unchanged if the option is not found. To have a long-named option do something other than set an `int' to a compiled-in constant, such as set a value from `optarg', set the option's `flag' field to zero and its `val' field to a nonzero value (the equivalent single-letter option character, if there is one). For long options that have a zero `flag' field, `getopt' returns the contents of the `val' field. */ struct option { # if defined __STDC__ && __STDC__ const char *name; # else char *name; # endif /* has_arg can't be an enum because some compilers complain about type mismatches in all the code that assumes it is an int. */ int has_arg; int *flag; int val; }; /* Names for the values of the `has_arg' field of `struct option'. */ # define no_argument 0 # define required_argument 1 # define optional_argument 2 #endif /* need getopt */ /* Get definitions and prototypes for functions to process the arguments in ARGV (ARGC of them, minus the program name) for options given in OPTS. Return the option character from OPTS just read. Return -1 when there are no more options. For unrecognized options, or options missing arguments, `optopt' is set to the option letter, and '?' is returned. The OPTS string is a list of characters which are recognized option letters, optionally followed by colons, specifying that that letter takes an argument, to be placed in `optarg'. If a letter in OPTS is followed by two colons, its argument is optional. This behavior is specific to the GNU `getopt'. The argument `--' causes premature termination of argument scanning, explicitly telling `getopt' that there are no more options. If OPTS begins with `--', then non-option arguments are treated as arguments to the option '\0'. This behavior is specific to the GNU `getopt'. */ #if defined __STDC__ && __STDC__ # ifdef __GNU_LIBRARY__ /* Many other libraries have conflicting prototypes for getopt, with differences in the consts, in stdlib.h. To avoid compilation errors, only prototype getopt for the GNU C library. */ extern int getopt (int __argc, char *const *__argv, const char *__shortopts); # else /* not __GNU_LIBRARY__ */ extern int getopt (); # endif /* __GNU_LIBRARY__ */ # ifndef __need_getopt extern int getopt_long (int __argc, char *const *__argv, const char *__shortopts, const struct option *__longopts, int *__longind); extern int getopt_long_only (int __argc, char *const *__argv, const char *__shortopts, const struct option *__longopts, int *__longind); /* Internal only. Users should not call this directly. */ extern int _getopt_internal (int __argc, char *const *__argv, const char *__shortopts, const struct option *__longopts, int *__longind, int __long_only); # endif #else /* not __STDC__ */ extern int getopt (); # ifndef __need_getopt extern int getopt_long (); extern int getopt_long_only (); extern int _getopt_internal (); # endif #endif /* __STDC__ */ #ifdef __cplusplus } #endif /* Make sure we later can get all the definitions and declarations. */ #undef __need_getopt #endif /* getopt.h */ sftpserver-0.2.1/daemon.c0000664000175000017500000000443511625765051012265 00000000000000/*- * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #if defined(LIBC_SCCS) && !defined(lint) static char sccsid[] = "@(#)daemon.c 8.1 (Berkeley) 6/4/93"; #endif /* LIBC_SCCS and not lint */ #include #include #include #include int daemon(int nochdir, int noclose) { int fd; switch (fork()) { case -1: return (-1); case 0: break; default: _exit(0); } if(setsid() == -1) return (-1); if(!nochdir) chdir("/"); if(!noclose && (fd = open("/dev/null", O_RDWR, 0)) != -1) { dup2(fd, 0); dup2(fd, 1); dup2(fd, 2); if (fd > 2) close (fd); } else return -1; return 0; } /* Local Variables: c-basic-offset:2 comment-column:40 fill-column:79 indent-tabs-mode:nil End: */ sftpserver-0.2.1/send.h0000664000175000017500000000747011626705056011762 00000000000000/* * This file is part of the Green End SFTP Server. * Copyright (C) 2007, 2011 Richard Kettlewell * * 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 2 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, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA */ /** @file send.h @brief Message sending interface */ #ifndef SEND_H #define SEND_H /** @brief Ensure there are @p n bytes spare in the message buffer * @param w Worker containing message * @param n Bytes required * * If memory cannot be allocated the process is terminated. */ void sftp_send_need(struct worker *w, size_t n); /** @brief Start to construct a message * @param w Worker containing message * * Any previous or partial message is discarded. */ void sftp_send_begin(struct worker *w); /** @brief Complete a message * @param w Worker containing message * * The message is sent to @ref sftpout. All sends are serialized so if two * messages are sent concurrently, they are not interleaved. * * After this call the message cannot be further modified; sftp_send_begin() * must be called again. Failure to do so will trigger an assert. */ void sftp_send_end(struct worker *w); /** @brief Add an 8-bit value to a message * @param w Worker containing message * @param n Value to add to message */ void sftp_send_uint8(struct worker *w, int n); /** @brief Add a 16-bit value to a message * @param w Worker containing message * @param u Value to add to message */ void sftp_send_uint16(struct worker *w, uint16_t u); /** @brief Add a 32-bit value to a message * @param w Worker containing message * @param u Value to add to message */ void sftp_send_uint32(struct worker *w, uint32_t u); /** @brief Add a 64-bit value to a message * @param w Worker containing message * @param u Value to add to message */ void sftp_send_uint64(struct worker *w, uint64_t u); /** @brief Add a byte block to a message * @param w Worker containing message * @param bytes Start of byte block * @param n Size of byte block */ void sftp_send_bytes(struct worker *w, const void *bytes, size_t n); /** @brief Add a handle a message * @param w Worker containing message * @param id Handle to add to message */ void sftp_send_handle(struct worker *w, const struct handleid *id); /** @brief Add a string a message * @param w Worker containing message * @param s String to add to message */ void sftp_send_string(struct worker *w, const char *s); /** @brief Add a path a message * @param job Job to borrow allocator from * @param w Worker containing message * @param path Path to add to message */ void sftp_send_path(struct sftpjob *job, struct worker *w, const char *path); /** @brief Start a sub-message * @param w Worker containing message * @return Offset to pass to sftp_send_sub_end() * * Sub-messages have their own initial length word. */ size_t sftp_send_sub_begin(struct worker *w); /** @brief Complete a sub-message * @param w Worker containing message * @param offset Return value of previous sftp_send_sub_begin() */ void sftp_send_sub_end(struct worker *w, size_t offset); /** @brief File descriptor to send messages to * * The default value is 1, i.e. standard output. */ extern int sftpout; #endif /* SEND_H */ /* Local Variables: c-basic-offset:2 comment-column:40 fill-column:79 indent-tabs-mode:nil End: */ sftpserver-0.2.1/globals.h0000664000175000017500000000356311626705056012453 00000000000000/* * This file is part of the Green End SFTP Server. * Copyright (C) 2007, 2011 Richard Kettlewell * * 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 2 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, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA */ /** @file globals.h @brief Global variables interface */ #ifndef GLOBALS_H #define GLOBALS_H /** @brief Work queue for the thread pool */ extern struct queue *workqueue; /** @brief V6 protocol callbacks */ extern const struct sftpprotocol sftp_v6; /** @brief V5 protocol callbacks */ extern const struct sftpprotocol sftp_v5; /** @brief V4 protocol callbacks */ extern const struct sftpprotocol sftp_v4; /** @brief V3 protocol callbacks */ extern const struct sftpprotocol sftp_v3; /** @brief Pre-initialization protocol callbacks */ extern const struct sftpprotocol sftp_preinit; /** @brief Selected protocol */ extern const struct sftpprotocol *protocol; /** @brief What messages this process sends * * Separately defined as @c request or @c response in the client and server * respectively. */ extern const char sendtype[]; /** @brief Read-only mode */ extern int readonly; /** @brief Reverse symlink arguments */ extern int reverse_symlink; #endif /* GLOBALS_H */ /* Local Variables: c-basic-offset:2 comment-column:40 fill-column:79 indent-tabs-mode:nil End: */ sftpserver-0.2.1/v5.c0000664000175000017500000004317612344637631011362 00000000000000/* * This file is part of the Green End SFTP Server. * Copyright (C) 2007 Richard Kettlewell * * 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 2 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, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA */ #include "sftpserver.h" #include "types.h" #include "sftp.h" #include "parse.h" #include "send.h" #include "debug.h" #include "sftp.h" #include "handle.h" #include "globals.h" #include "stat.h" #include "utils.h" #include #include #include #include #include #include uint32_t sftp_v56_open(struct sftpjob *job) { char *path; uint32_t desired_access, flags; struct sftpattr attrs; pcheck(sftp_parse_path(job, &path)); pcheck(sftp_parse_uint32(job, &desired_access)); pcheck(sftp_parse_uint32(job, &flags)); pcheck(protocol->parseattrs(job, &attrs)); D(("sftp_v56_open %s %#"PRIx32" %#"PRIx32, path, desired_access, flags)); return sftp_generic_open(job, path, desired_access, flags, &attrs); } uint32_t sftp_generic_open(struct sftpjob *job, const char *path, uint32_t desired_access, uint32_t flags, struct sftpattr *attrs) { mode_t initial_permissions; int created, open_flags, fd; struct stat sb; struct handleid id; unsigned sftp_handle_flags = 0; uint32_t rc; D(("sftp_generic_open %s %#"PRIx32" %#"PRIx32, path, desired_access, flags)); /* Check owner/group */ if((rc = sftp_normalize_ownergroup(job->a, attrs)) != SSH_FX_OK) return rc; /* For opens, the size indicates the planned total size, and doesn't affect * the file creation. */ attrs->valid &= ~(uint32_t)SSH_FILEXFER_ATTR_SIZE; /* The v6 spec says implementations "SHOULD" pre-allocate according to the * allocation-size field if present. This is impossible on UNIX so we ignore * it. * * This means that the MUST later in the same section, that the queried * allocation-size must exceed the requested one, cannot be honored. Since * the specification taken literally prohibits UNIX implementations, I assume * that it is in error. */ switch(desired_access & (ACE4_READ_DATA|ACE4_WRITE_DATA)) { case 0: /* probably a broken client */ case ACE4_READ_DATA: D(("O_RDONLY")); open_flags = O_RDONLY; if(desired_access & (ACE4_WRITE_NAMED_ATTRS |ACE4_WRITE_ATTRIBUTES |ACE4_WRITE_ACL |ACE4_WRITE_OWNER)) return SSH_FX_PERMISSION_DENIED; break; case ACE4_WRITE_DATA: if(readonly) return SSH_FX_PERMISSION_DENIED; D(("O_WRONLY")); open_flags = O_WRONLY; if(desired_access & (ACE4_READ_NAMED_ATTRS |ACE4_READ_ATTRIBUTES |ACE4_READ_ACL)) return SSH_FX_PERMISSION_DENIED; break; case ACE4_READ_DATA|ACE4_WRITE_DATA: if(readonly) return SSH_FX_PERMISSION_DENIED; D(("O_RDWR")); open_flags = O_RDWR; break; default: fatal("bitwise operators have broken"); } /* UNIX systems generally do not allow the owner to be changed by * non-superusers. */ if((desired_access & ACE4_WRITE_OWNER) && getuid()) return SSH_FX_PERMISSION_DENIED; /* LIST_DIRECTORY, ADD_FILE, ADD_SUBDIRECTORY and DELETE_CHILD don't make * sense for regular files. We ignore them, regarding a grant of permission * as not implying that the operation can possibly work. * * Similary SYNCHRONIZE and EXECUTE we're happy to grant permission for even * if there's no way to take advantage of that permission. * * DELETE is always possible and nothing to do with opening the file. */ #ifdef O_NOCTTY /* We don't want to accidentally acquire a controlling terminal. */ open_flags |= O_NOCTTY; #endif if(flags & (SSH_FXF_APPEND_DATA|SSH_FXF_APPEND_DATA_ATOMIC)) { /* We always use O_APPEND for appending so we always give atomic append. */ D(("O_APPEND")); open_flags |= O_APPEND; sftp_handle_flags |= HANDLE_APPEND; } if(flags & SSH_FXF_TEXT_MODE) sftp_handle_flags |= HANDLE_TEXT; if(flags & (SSH_FXF_BLOCK_READ|SSH_FXF_BLOCK_WRITE|SSH_FXF_BLOCK_DELETE)) return SSH_FX_OP_UNSUPPORTED; if(flags & SSH_FXF_NOFOLLOW) { #ifdef O_NOFOLLOW /* We have a built-in way of avoiding following links */ open_flags |= O_NOFOLLOW; D(("O_NOFOLLOW")); #else /* We avoid following links in a racy steam-driven way */ D(("emulating O_NOFOLLOW")); if(lstat(path, &sb) == 0 && S_ISLNK(sb.st_mode)) return SSH_FX_LINK_LOOP; #endif } if(attrs->valid & SSH_FILEXFER_ATTR_PERMISSIONS) { /* If we're given permissions use them */ initial_permissions = attrs->permissions & 07777; /* Don't modify permissions later unless necessary */ if(attrs->permissions == (attrs->permissions & 0777)) attrs->valid ^= SSH_FILEXFER_ATTR_PERMISSIONS; D(("using initial permission %#o", (unsigned)initial_permissions)); } else /* Otherwise be conservative */ initial_permissions = DEFAULT_PERMISSIONS & 0666; if(readonly && ((flags & SSH_FXF_ACCESS_DISPOSITION) != SSH_FXF_OPEN_EXISTING || (flags & SSH_FXF_DELETE_ON_CLOSE))) { return SSH_FX_PERMISSION_DENIED; } switch(flags & SSH_FXF_ACCESS_DISPOSITION) { case SSH_FXF_CREATE_NEW: /* We create the file anew and if it exists we return an error. */ if(flags & SSH_FXF_NOFOLLOW) { /* O_EXCL is just right if we don't want to follow links. */ D(("SSH_FXF_CREATE_NEW|SSH_FXF_NOFOLLOW -> O_CREAT|O_EXCL")); fd = open(path, open_flags|O_CREAT|O_EXCL, initial_permissions); created = 1; } else { /* O_EXCL will refuse to follow links so that's no good here. We do a * racy test and open since that's the best available. */ D(("SSH_FXF_CREATE_NEW -> test for existence")); if(stat(path, &sb) == 0) return SSH_FX_FILE_ALREADY_EXISTS; D(("SSH_FXF_CREATE_NEW -> O_CREAT")); fd = open(path, open_flags|O_CREAT, initial_permissions); created = 1; } break; case SSH_FXF_CREATE_TRUNCATE: case SSH_FXF_OPEN_OR_CREATE: /* These cases differ only in whether existing files are truncated. */ if((flags & SSH_FXF_ACCESS_DISPOSITION) == SSH_FXF_CREATE_TRUNCATE) { D(("SSH_FXF_CREATE_TRUNCATE -> O_TRUNC")); open_flags |= O_TRUNC; } else D(("SSH_FXF_OPEN_OR_TRUNCATE -> not O_TRUNC")); if(flags & SSH_FXF_NOFOLLOW) { D(("SSH_FXF_*|SSH_FXF_NOFOLLOW -> O_CREAT|O_EXCL")); fd = open(path, open_flags|O_CREAT|O_EXCL, initial_permissions); if(fd >= 0) /* The file did not exist before */ created = 1; else if(errno == EEXIST) { /* The file already exists. If it's not a link then open and maybe * truncate. If it got deleted in the meantime then you get an * error. */ D(("SSH_FXF_*|SSH_FXF_NOFOLLOW -> EEXIST")); if(lstat(path, &sb) < 0) return HANDLER_ERRNO; if(S_ISLNK(sb.st_mode)) return SSH_FX_LINK_LOOP; fd = open(path, open_flags, initial_permissions); created = 0; } else created = 0; /* quieten compiler */ } else { /* As above we cannot use O_EXCL in this case as it'll refuse to follow * symlinks. */ D(("SSH_FXF_* -> test for existence")); if(stat(path, &sb) == 0) { /* The file exists. Open and maybe truncate. If it got deleted in the * meantime then you get an error. */ D(("SSH_FXF_* -> open")); fd = open(path, open_flags, initial_permissions); created = 0; } else { /* The file does not exist yet. If it was created in the meantime then * you get that file (perhaps truncated)! We can't use O_EXCL here * because as observed so there is really no way round this. */ D(("SSH_FXF_* -> O_CREAT")); fd = open(path, open_flags|O_CREAT, initial_permissions); created = 0; } } break; case SSH_FXF_OPEN_EXISTING: /* The file has to exist already so this case is simple. O_NOFOLLOW * doesn't work reliably in this case. */ #ifdef O_NOFOLLOW if(flags & SSH_FXF_NOFOLLOW) { D(("emulating O_NOFOLLOW")); if(lstat(path, &sb) == 0 && S_ISLNK(sb.st_mode)) return SSH_FX_LINK_LOOP; } #endif D(("SSH_FXF_OPEN_EXISTING -> open")); fd = open(path, open_flags, initial_permissions); created = 0; break; case SSH_FXF_TRUNCATE_EXISTING: /* Again the file has to exist already so this is also simple - except that * O_NOFOLLOW doesn't inhibit following in this case. */ #ifdef O_NOFOLLOW if(flags & SSH_FXF_NOFOLLOW) { D(("emulating O_NOFOLLOW")); if(lstat(path, &sb) == 0 && S_ISLNK(sb.st_mode)) return SSH_FX_LINK_LOOP; } #endif D(("SSH_FXF_TRUNCATE_EXISTING -> O_TRUNC")); fd = open(path, open_flags|O_TRUNC, initial_permissions); created = 0; break; default: return SSH_FX_OP_UNSUPPORTED; } /* BSD lets us open directories, but we MUST return an error */ if(fd >= 0 && fstat(fd, &sb) == 0 && S_ISDIR(sb.st_mode)) { close(fd); return SSH_FX_FILE_IS_A_DIRECTORY; } if(fd < 0) { if(((flags & SSH_FXF_ACCESS_DISPOSITION) == SSH_FXF_OPEN_EXISTING || (flags & SSH_FXF_ACCESS_DISPOSITION) == SSH_FXF_TRUNCATE_EXISTING) && errno == ENOENT) { /* The client could do the extra check but at the cost of a round trip, * so it makes some sense to do it and return the alternative status. * This is of rather limited use as the client has no way to know that we * reliably send SSH_FX_NO_SUCH_PATH when appropriate, but the * alternative error message might clue in users occasionally. */ if(lstat(sftp_dirname(job->a, path), &sb) < 0) return SSH_FX_NO_SUCH_PATH; errno = ENOENT; /* restore errno just in case */ } #ifdef O_NOFOLLOW /* If we couldn't open the file because we declined to follow a symlink * then we need an unusual error code. (But if we had to emulate * O_NOFOLLOW then the test already happened long ago.) */ if((flags & SSH_FXF_NOFOLLOW) && (errno == ENOENT || errno == EEXIST)) { if(lstat(path, &sb) < 0) return HANDLER_ERRNO; if(S_ISLNK(sb.st_mode)) return SSH_FX_LINK_LOOP; } #endif return HANDLER_ERRNO; } /* Set initial attributrs if we created the file */ if(created && attrs->valid && (rc = sftp_set_fstatus(job->a, fd, attrs, 0))) { const int save_errno = errno; close(fd); unlink(path); errno = save_errno; return rc; } /* The draft says "It is implementation specific whether the directory entry * is removed immediately or when the handle is closed". I interpret * 'immediately' to refer to the open operation. */ if(flags & SSH_FXF_DELETE_ON_CLOSE) { D(("SSH_FXF_DELETE_ON_CLOSE")); unlink(path); } sftp_handle_new_file(&id, fd, path, sftp_handle_flags); D(("...handle is %"PRIu32" %"PRIu32, id.id, id.tag)); sftp_send_begin(job->worker); sftp_send_uint8(job->worker, SSH_FXP_HANDLE); sftp_send_uint32(job->worker, job->id); sftp_send_handle(job->worker, &id); sftp_send_end(job->worker); return HANDLER_RESPONDED; } uint32_t sftp_v56_rename(struct sftpjob *job) { char *oldpath, *newpath; uint32_t flags; if(readonly) return SSH_FX_PERMISSION_DENIED; pcheck(sftp_parse_path(job, &oldpath)); pcheck(sftp_parse_path(job, &newpath)); pcheck(sftp_parse_uint32(job, &flags)); D(("sftp_v56_rename %s %s %#"PRIx32, oldpath, newpath, flags)); if(flags & (SSH_FXF_RENAME_NATIVE|SSH_FXF_RENAME_OVERWRITE)) { /* We asked for an overwriting rename (or a native one, in which case we're * allowed to do any old thing). We are guaranteed that rename() is atomic * in the required sense on UNIX systems ("In this case, a link named new * shall remain visible to other processes throughout the renaming * operation and refer either to the file referred to by new or old before * the operation began.") so we don't bother checking the atomic bit. */ if(rename(oldpath, newpath) < 0) return HANDLER_ERRNO; else return SSH_FX_OK; } else { /* We want a non-overwriting rename. We use the same strategy as * in v3.c. */ if(link(oldpath, newpath) < 0) { if(errno != EEXIST) { #ifndef __linux__ { struct stat sb; if(lstat(newpath, &sb) == 0) return SSH_FX_FILE_ALREADY_EXISTS; } #endif if(rename(oldpath, newpath) < 0) return HANDLER_ERRNO; else return SSH_FX_OK; } else return SSH_FX_FILE_ALREADY_EXISTS; } else if(unlink(oldpath) < 0) { const int save_errno = errno; unlink(newpath); errno = save_errno; return HANDLER_ERRNO; } else return SSH_FX_OK; } } uint32_t sftp_vany_text_seek(struct sftpjob *job) { struct handleid id; uint64_t line; int fd; char buffer[8192]; ssize_t n, i; uint32_t rc; pcheck(sftp_parse_handle(job, &id)); pcheck(sftp_parse_uint64(job, &line)); if((rc = sftp_handle_get_fd(&id, &fd, 0))) return rc; /* Seek back to line 0 */ if(lseek(fd, 0, SEEK_SET) < 0) return HANDLER_ERRNO; /* TODO currently if we ask for the line 'just beyond' the end of the file we * succeed. We should actually return SSH_FX_EOF in this case. */ if(line == 0) { /* If we're after line 0 then we're already in the right place */ return SSH_FX_OK; } /* Look for the right line */ i = 0; n = 0; /* quieten compiler */ D(("on entry: line=%"PRIu64, line)); while(line > 0 && (n = read(fd, buffer, sizeof buffer)) > 0) { D(("outer: line=%"PRIu64" n=%zd", line, n)); i = 0; while(line > 0 && i < n) { if(buffer[i++] == '\n') --line; } } D(("exited:: line=%"PRIu64" n=%zd i=%zd", line, n, i)); if(n < 0) return HANDLER_ERRNO; else if(n == 0) return SSH_FX_EOF; else { /* Seek back to the start of the line */ if(lseek(fd, i - n, SEEK_CUR) < 0) return HANDLER_ERRNO; return SSH_FX_OK; } } uint32_t sftp_vany_space_available(struct sftpjob *job) { char *path; struct statvfs fs; pcheck(sftp_parse_string(job, &path, 0)); D(("sftp_space_available %s", path)); if(statvfs(path, &fs) < 0) return HANDLER_ERRNO; sftp_send_begin(job->worker); sftp_send_uint8(job->worker, SSH_FXP_EXTENDED_REPLY); sftp_send_uint32(job->worker, job->id); /* bytes-on-device */ sftp_send_uint64(job->worker, (uint64_t)fs.f_frsize * (uint64_t)fs.f_blocks); /* unused-bytes-on-device */ sftp_send_uint64(job->worker, (uint64_t)fs.f_frsize * (uint64_t)fs.f_bfree); /* bytes-available-to-user (i.e. both used and unused) */ sftp_send_uint64(job->worker, 0); /* unused-bytes-available-to-user (i.e. unused) */ sftp_send_uint64(job->worker, (uint64_t)fs.f_frsize * (uint64_t)fs.f_bavail); /* bytes-per-allocation-unit */ sftp_send_uint32(job->worker, fs.f_frsize); sftp_send_end(job->worker); return HANDLER_RESPONDED; } uint32_t sftp_vany_extended(struct sftpjob *job) { char *name; int n; pcheck(sftp_parse_string(job, &name, 0)); D(("extension %s", name)); /* TODO when we have nontrivially many extensions we should use a binary * search here. */ for(n = 0; (n < protocol->nextensions && strcmp(name, protocol->extensions[n].name)); ++n) ; if(n >= protocol->nextensions) return SSH_FX_OP_UNSUPPORTED; else return protocol->extensions[n].handler(job); } static const struct sftpcmd sftpv5tab[] = { { SSH_FXP_INIT, sftp_vany_already_init }, { SSH_FXP_OPEN, sftp_v56_open }, { SSH_FXP_CLOSE, sftp_vany_close }, { SSH_FXP_READ, sftp_vany_read }, { SSH_FXP_WRITE, sftp_vany_write }, { SSH_FXP_LSTAT, sftp_v456_lstat }, { SSH_FXP_FSTAT, sftp_v456_fstat }, { SSH_FXP_SETSTAT, sftp_vany_setstat }, { SSH_FXP_FSETSTAT, sftp_vany_fsetstat }, { SSH_FXP_OPENDIR, sftp_vany_opendir }, { SSH_FXP_READDIR, sftp_vany_readdir }, { SSH_FXP_REMOVE, sftp_vany_remove }, { SSH_FXP_MKDIR, sftp_vany_mkdir }, { SSH_FXP_RMDIR, sftp_vany_rmdir }, { SSH_FXP_REALPATH, sftp_v345_realpath }, { SSH_FXP_STAT, sftp_v456_stat }, { SSH_FXP_RENAME, sftp_v56_rename }, { SSH_FXP_READLINK, sftp_vany_readlink }, { SSH_FXP_SYMLINK, sftp_v345_symlink }, { SSH_FXP_EXTENDED, sftp_vany_extended } }; static const struct sftpextension sftp_v5_extensions[] = { { "posix-rename@openssh.org", sftp_vany_posix_rename }, { "space-available", sftp_vany_space_available }, { "statfs@openssh.org", sftp_vany_statfs }, { "text-seek", sftp_vany_text_seek }, }; const struct sftpprotocol sftp_v5 = { sizeof sftpv5tab / sizeof (struct sftpcmd), sftpv5tab, 5, (SSH_FILEXFER_ATTR_SIZE |SSH_FILEXFER_ATTR_PERMISSIONS |SSH_FILEXFER_ATTR_ACCESSTIME |SSH_FILEXFER_ATTR_MODIFYTIME |SSH_FILEXFER_ATTR_OWNERGROUP |SSH_FILEXFER_ATTR_SUBSECOND_TIMES |SSH_FILEXFER_ATTR_BITS), SSH_FX_LOCK_CONFLICT, sftp_v456_sendnames, sftp_v456_sendattrs, sftp_v456_parseattrs, sftp_v456_encode, sftp_v456_decode, sizeof sftp_v5_extensions / sizeof (struct sftpextension), sftp_v5_extensions, }; /* Local Variables: c-basic-offset:2 comment-column:40 fill-column:79 indent-tabs-mode:nil End: */ sftpserver-0.2.1/stat.h0000664000175000017500000000753211626705056012003 00000000000000/* * This file is part of the Green End SFTP Server. * Copyright (C) 2007, 2011 Richard Kettlewell * * 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 2 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, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA */ /** @file stat.h @brief SFTP attribute support interface */ #ifndef STAT_H #define STAT_H /** @brief Produce a human-readable representation of file attributes * @param a Allocator * @param attrs Attributes to format * @param thisyear This year-1900 * @param flags Flags * @return Formatted attributes * * Flag values: * - @ref FORMAT_PREFER_NUMERIC_UID * - @ref FORMAT_PREFER_LOCALTIME * - @ref FORMAT_ATTRS */ const char *sftp_format_attr(struct allocator *a, const struct sftpattr *attrs, int thisyear, unsigned long flags); /** @brief User numeric instead of named user and group IDs * * See sftp_format_attr(). */ #define FORMAT_PREFER_NUMERIC_UID 0x00000001 /** @brief Use local time instead of UTC * * See sftp_format_attr(). */ #define FORMAT_PREFER_LOCALTIME 0x00000002 /** @brief Include attribute bits * * See sftp_format_attr(). */ #define FORMAT_ATTRS 0x00000004 /** @brief Fill in missing owner/group attributes * @param a Allocator * @param attrs Attributes * @return 0 on success, status code on error * * If exactly one of @ref SSH_FILEXFER_ATTR_UIDGID and @ref * SSH_FILEXFER_ATTR_OWNERGROUP is present then attempt to fill in the other. */ uint32_t sftp_normalize_ownergroup(struct allocator *a, struct sftpattr *attrs); /** @brief Set the attributes on a path name * @param a Allocator * @param path Path to modify * @param attrs Attributes to set * @param whyp Where to store error string, or a null pointer * @return 0 on success or an error code on failure */ uint32_t sftp_set_status(struct allocator *a, const char *path, const struct sftpattr *attrs, const char **whyp); /** @brief Set the attributes on an open file * @param a Allocator * @param fd File descriptor to modify * @param attrs Attributes to set * @param whyp Where to store error string, or a null pointer * @return 0 on success or an error code on failure */ uint32_t sftp_set_fstatus(struct allocator *a, int fd, const struct sftpattr *attrs, const char **whyp); /** @brief Convert @c stat() output to SFTP attributes * @param a Allocator * @param sb Result of calling @c stat() or similar * @param attrs Where to store SFTP attributes * @param flags Requested attributes * @param path Path name or a null pointer * * The only meaningful bit in @p flags currently is @ref * SSH_FILEXFER_ATTR_OWNERGROUP, which causes the owner and group names to be * filled in. * * @todo @ref SSH_FILEXFER_ATTR_FLAGS_CASE_INSENSITIVE is not implemented. * * @todo @ref SSH_FILEXFER_ATTR_FLAGS_IMMUTABLE is not implemented. */ void sftp_stat_to_attrs(struct allocator *a, const struct stat *sb, struct sftpattr *attrs, uint32_t flags, const char *path); #endif /* STAT_H */ /* Local Variables: c-basic-offset:2 comment-column:40 fill-column:79 indent-tabs-mode:nil End: */