* Ported FreeBSD's ftpd to Haiku.
* Added it to the image, and configured it to be used. * Currently, it cannot transfer files over 64 KB for some reason ("Message too long"). git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23843 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
43711de9d2
commit
0481936536
@ -28,7 +28,8 @@ BEOS_BIN = "[" addattr alert arp base64 basename bc beep bison bzip2 cal cat
|
||||
cp copyattr $(X86_ONLY)CortexAddOnHost
|
||||
csplit ctags cut date dc dd desklink df diff diff3 dircolors dirname
|
||||
driveinfo dstcheck du echo eject env error expand expr
|
||||
expr factor false fdinfo ffm find finddir fmt fold fortune frcode ftp funzip fwcontrol
|
||||
expr factor false fdinfo ffm find finddir fmt fold fortune frcode ftp ftpd
|
||||
funzip fwcontrol
|
||||
gawk $(X86_ONLY)gdb grep groups gzip gzexe hd head hey hostname id ident
|
||||
ideinfo idestatus ifconfig <bin>install installsound iroster isvolume join
|
||||
keymap kill less lessecho lesskey link listarea listattr listdev listimage
|
||||
|
@ -1,3 +1,7 @@
|
||||
service telnet {
|
||||
launch telnetd
|
||||
}
|
||||
|
||||
service ftp {
|
||||
launch ftpd
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ SubDir HAIKU_TOP src bin network ;
|
||||
SubInclude HAIKU_TOP src bin network arp ;
|
||||
SubInclude HAIKU_TOP src bin network atftpd ;
|
||||
SubInclude HAIKU_TOP src bin network ftp ;
|
||||
SubInclude HAIKU_TOP src bin network ftpd ;
|
||||
SubInclude HAIKU_TOP src bin network ifconfig ;
|
||||
SubInclude HAIKU_TOP src bin network login ;
|
||||
SubInclude HAIKU_TOP src bin network mount_nfs ;
|
||||
|
24
src/bin/network/ftpd/Jamfile
Normal file
24
src/bin/network/ftpd/Jamfile
Normal file
@ -0,0 +1,24 @@
|
||||
SubDir HAIKU_TOP src bin network ftpd ;
|
||||
|
||||
SetSubDirSupportedPlatforms $(HAIKU_BONE_COMPATIBLE_PLATFORMS) ;
|
||||
|
||||
if ! $(TARGET_PLATFORM_HAIKU_COMPATIBLE) {
|
||||
UseHeaders [ FDirName $(HAIKU_TOP) headers posix ] : true ;
|
||||
# We need the public network headers also when not compiling for Haiku.
|
||||
# Unfortunately we get more than we want, namely all POSIX headers.
|
||||
}
|
||||
|
||||
UseHeaders [ FDirName $(HAIKU_TOP) headers compatibility bsd ] : true ;
|
||||
UseHeaders $(SUBDIR) : true ;
|
||||
|
||||
BinCommand ftpd :
|
||||
ftpd.c
|
||||
ftpcmd.y
|
||||
logwtmp.c
|
||||
popen.c
|
||||
|
||||
# from libmd
|
||||
md5c.c
|
||||
md5hl.c
|
||||
: libutil.a libbsd.so $(TARGET_NETWORK_LIBS)
|
||||
;
|
284
src/bin/network/ftpd/config.h
Normal file
284
src/bin/network/ftpd/config.h
Normal file
@ -0,0 +1,284 @@
|
||||
/* $FreeBSD: src/libexec/ftpd/config.h,v 1.1 2001/07/19 17:45:14 obrien Exp $ */
|
||||
|
||||
|
||||
/* config.h. Generated automatically by configure. */
|
||||
/* config.h.in. Generated automatically from configure.in by autoheader. */
|
||||
/* $Id: config.h.in,v 1.15 2001/04/28 07:11:46 lukem Exp $ */
|
||||
|
||||
|
||||
/* Define if the closedir function returns void instead of int. */
|
||||
/* #undef CLOSEDIR_VOID */
|
||||
|
||||
/* Define to empty if the keyword does not work. */
|
||||
/* #undef const */
|
||||
|
||||
/* Define if your C compiler doesn't accept -c and -o together. */
|
||||
/* #undef NO_MINUS_C_MINUS_O */
|
||||
|
||||
/* Define if your Fortran 77 compiler doesn't accept -c and -o together. */
|
||||
/* #undef F77_NO_MINUS_C_MINUS_O */
|
||||
|
||||
/* Define to `long' if <sys/types.h> doesn't define. */
|
||||
/* #undef off_t */
|
||||
|
||||
/* Define to the type of arg1 for select(). */
|
||||
/* #undef SELECT_TYPE_ARG1 */
|
||||
|
||||
/* Define to the type of args 2, 3 and 4 for select(). */
|
||||
/* #undef SELECT_TYPE_ARG234 */
|
||||
|
||||
/* Define to the type of arg5 for select(). */
|
||||
/* #undef SELECT_TYPE_ARG5 */
|
||||
|
||||
/* Define if you have the ANSI C header files. */
|
||||
#define STDC_HEADERS 1
|
||||
|
||||
/* Define if you can safely include both <sys/time.h> and <time.h>. */
|
||||
#define TIME_WITH_SYS_TIME 1
|
||||
|
||||
/* Define if the closedir function returns void instead of int. */
|
||||
/* #undef VOID_CLOSEDIR */
|
||||
|
||||
/* The number of bytes in a off_t. */
|
||||
#define SIZEOF_OFF_T 0
|
||||
|
||||
/* Define if you have the err function. */
|
||||
#define HAVE_ERR 1
|
||||
|
||||
/* Define if you have the fgetln function. */
|
||||
#define HAVE_FGETLN 1
|
||||
|
||||
/* Define if you have the flock function. */
|
||||
#define HAVE_FLOCK 1
|
||||
|
||||
/* Define if you have the fparseln function. */
|
||||
#define HAVE_FPARSELN 1
|
||||
|
||||
/* Define if you have the fts_open function. */
|
||||
#define HAVE_FTS_OPEN 1
|
||||
|
||||
/* Define if you have the getaddrinfo function. */
|
||||
#define HAVE_GETADDRINFO 1
|
||||
|
||||
/* Define if you have the getgrouplist function. */
|
||||
#define HAVE_GETGROUPLIST 1
|
||||
|
||||
/* Define if you have the getnameinfo function. */
|
||||
#define HAVE_GETNAMEINFO 1
|
||||
|
||||
/* Define if you have the getspnam function. */
|
||||
/* #undef HAVE_GETSPNAM */
|
||||
|
||||
/* Define if you have the getusershell function. */
|
||||
#define HAVE_GETUSERSHELL 1
|
||||
|
||||
/* Define if you have the inet_net_pton function. */
|
||||
#define HAVE_INET_NET_PTON 1
|
||||
|
||||
/* Define if you have the inet_ntop function. */
|
||||
#define HAVE_INET_NTOP 1
|
||||
|
||||
/* Define if you have the inet_pton function. */
|
||||
#define HAVE_INET_PTON 1
|
||||
|
||||
/* Define if you have the lockf function. */
|
||||
#define HAVE_LOCKF 1
|
||||
|
||||
/* Define if you have the mkstemp function. */
|
||||
#define HAVE_MKSTEMP 1
|
||||
|
||||
/* Define if you have the setlogin function. */
|
||||
#define HAVE_SETLOGIN 1
|
||||
|
||||
/* Define if you have the setproctitle function. */
|
||||
#define HAVE_SETPROCTITLE 1
|
||||
|
||||
/* Define if you have the sl_init function. */
|
||||
#define HAVE_SL_INIT 1
|
||||
|
||||
/* Define if you have the snprintf function. */
|
||||
#define HAVE_SNPRINTF 1
|
||||
|
||||
/* Define if you have the strdup function. */
|
||||
#define HAVE_STRDUP 1
|
||||
|
||||
/* Define if you have the strerror function. */
|
||||
#define HAVE_STRERROR 1
|
||||
|
||||
/* Define if you have the strlcat function. */
|
||||
#define HAVE_STRLCAT 1
|
||||
|
||||
/* Define if you have the strlcpy function. */
|
||||
#define HAVE_STRLCPY 1
|
||||
|
||||
/* Define if you have the strmode function. */
|
||||
#define HAVE_STRMODE 1
|
||||
|
||||
/* Define if you have the strsep function. */
|
||||
#define HAVE_STRSEP 1
|
||||
|
||||
/* Define if you have the strtoll function. */
|
||||
#define HAVE_STRTOLL 1
|
||||
|
||||
/* Define if you have the user_from_uid function. */
|
||||
#define HAVE_USER_FROM_UID 1
|
||||
|
||||
/* Define if you have the usleep function. */
|
||||
#define HAVE_USLEEP 1
|
||||
|
||||
/* Define if you have the vfork function. */
|
||||
#define HAVE_VFORK 1
|
||||
|
||||
/* Define if you have the vsyslog function. */
|
||||
#define HAVE_VSYSLOG 1
|
||||
|
||||
/* Define if you have the <arpa/nameser.h> header file. */
|
||||
#define HAVE_ARPA_NAMESER_H 1
|
||||
|
||||
/* Define if you have the <dirent.h> header file. */
|
||||
#define HAVE_DIRENT_H 1
|
||||
|
||||
/* Define if you have the <err.h> header file. */
|
||||
#define HAVE_ERR_H 1
|
||||
|
||||
/* Define if you have the <fts.h> header file. */
|
||||
#define HAVE_FTS_H 1
|
||||
|
||||
/* Define if you have the <libutil.h> header file. */
|
||||
#define HAVE_LIBUTIL_H 1
|
||||
|
||||
/* Define if you have the <ndir.h> header file. */
|
||||
/* #undef HAVE_NDIR_H */
|
||||
|
||||
/* Define if you have the <paths.h> header file. */
|
||||
#define HAVE_PATHS_H 1
|
||||
|
||||
/* Define if you have the <sys/dir.h> header file. */
|
||||
#define HAVE_SYS_DIR_H 1
|
||||
|
||||
/* Define if you have the <sys/ndir.h> header file. */
|
||||
/* #undef HAVE_SYS_NDIR_H */
|
||||
|
||||
/* Define if you have the <sys/sysmacros.h> header file. */
|
||||
/* #undef HAVE_SYS_SYSMACROS_H */
|
||||
|
||||
/* Define if you have the <util.h> header file. */
|
||||
/* #undef HAVE_UTIL_H */
|
||||
|
||||
/* Define if you have the crypt library (-lcrypt). */
|
||||
#define HAVE_LIBCRYPT 1
|
||||
|
||||
/* Define if you have the nsl library (-lnsl). */
|
||||
/* #undef HAVE_LIBNSL */
|
||||
|
||||
/* Define if you have the skey library (-lskey). */
|
||||
/* #undef HAVE_LIBSKEY */
|
||||
|
||||
/* Define if you have the opie library (-lopie). */
|
||||
/* #undef HAVE_LIBOPIE */
|
||||
|
||||
/* Define if you have the socket library (-lsocket). */
|
||||
/* #undef HAVE_LIBSOCKET */
|
||||
|
||||
/* Define if you have the util library (-lutil). */
|
||||
#define HAVE_LIBUTIL 1
|
||||
|
||||
/* Define if your compiler supports `long long' */
|
||||
#define HAVE_LONG_LONG 1
|
||||
|
||||
/* Define if *printf() uses %qd to print `long long' (otherwise uses %lld) */
|
||||
#define HAVE_PRINTF_QD 1
|
||||
|
||||
/* Define if in_port_t exists */
|
||||
#define HAVE_IN_PORT_T 1
|
||||
|
||||
/* Define if struct sockaddr.sa_len exists (implies sockaddr_in.sin_len, etc) */
|
||||
#define HAVE_SOCKADDR_SA_LEN 1
|
||||
|
||||
/* Define if socklen_t exists */
|
||||
#define HAVE_SOCKLEN_T 1
|
||||
|
||||
/* Define if AF_INET6 exists in <sys/socket.h> */
|
||||
/* #define HAVE_AF_INET6 1 */
|
||||
|
||||
/* Define if `struct sockaddr_in6' exists in <netinet/in.h> */
|
||||
#define HAVE_SOCKADDR_IN6 1
|
||||
|
||||
/* Define if `struct addrinfo' exists in <netdb.h> */
|
||||
#define HAVE_ADDRINFO 1
|
||||
|
||||
/*
|
||||
* Define if <netdb.h> contains AI_NUMERICHOST et al.
|
||||
* Systems which only implement RFC2133 will need this.
|
||||
*/
|
||||
#define HAVE_RFC2553_NETDB 1
|
||||
|
||||
/* Define if `struct direct' has a d_namlen element */
|
||||
#define HAVE_D_NAMLEN 1
|
||||
|
||||
/* Define if struct passwd.pw_expire exists. */
|
||||
#define HAVE_PW_EXPIRE 1
|
||||
|
||||
/* Define if GLOB_BRACE, gl_path and gl_match exist in <glob.h> */
|
||||
#define HAVE_WORKING_GLOB 1
|
||||
|
||||
/* Define if crypt() is declared in <unistd.h> */
|
||||
#define HAVE_CRYPT_D 1
|
||||
|
||||
/* Define if fclose() is declared in <stdio.h> */
|
||||
#define HAVE_FCLOSE_D 1
|
||||
|
||||
/* Define if optarg is declared in <stdlib.h> or <unistd.h> */
|
||||
#define HAVE_OPTARG_D 1
|
||||
|
||||
/* Define if optind is declared in <stdlib.h> or <unistd.h> */
|
||||
#define HAVE_OPTIND_D 1
|
||||
|
||||
/* Define if optreset exists */
|
||||
#define HAVE_OPTRESET 1
|
||||
|
||||
/* Define if pclose() is declared in <stdio.h> */
|
||||
#define HAVE_PCLOSE_D 1
|
||||
|
||||
/* Define if getusershell() is declared in <unistd.h> */
|
||||
#define HAVE_GETUSERSHELL_D 1
|
||||
|
||||
/* Define if `long long' is supported and sizeof(off_t) >= 8 */
|
||||
#define HAVE_QUAD_SUPPORT 1
|
||||
|
||||
/* Define if not using in-built /bin/ls code */
|
||||
/* #undef NO_INTERNAL_LS */
|
||||
|
||||
/* Define if using S/Key */
|
||||
/* #undef SKEY */
|
||||
|
||||
/*
|
||||
* Define this if compiling with SOCKS (the firewall traversal library).
|
||||
* Also, you must define connect, getsockname, bind, accept, listen, and
|
||||
* select to their R-versions.
|
||||
*/
|
||||
/* #undef SOCKS */
|
||||
/* #undef SOCKS4 */
|
||||
/* #undef SOCKS5 */
|
||||
/* #undef connect */
|
||||
/* #undef getsockname */
|
||||
/* #undef bind */
|
||||
/* #undef accept */
|
||||
/* #undef listen */
|
||||
/* #undef select */
|
||||
/* #undef dup */
|
||||
/* #undef dup2 */
|
||||
/* #undef fclose */
|
||||
/* #undef gethostbyname */
|
||||
/* #undef getpeername */
|
||||
/* #undef read */
|
||||
/* #undef recv */
|
||||
/* #undef recvfrom */
|
||||
/* #undef rresvport */
|
||||
/* #undef send */
|
||||
/* #undef sendto */
|
||||
/* #undef shutdown */
|
||||
/* #undef write */
|
||||
|
||||
/* Define if you have the <arpa/ftp.h> header file. */
|
||||
#define HAVE_FTP_NAMES 1
|
89
src/bin/network/ftpd/extern.h
Normal file
89
src/bin/network/ftpd/extern.h
Normal file
@ -0,0 +1,89 @@
|
||||
/*-
|
||||
* Copyright (c) 1992, 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.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 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.
|
||||
*
|
||||
* @(#)extern.h 8.2 (Berkeley) 4/4/94
|
||||
* $FreeBSD: src/libexec/ftpd/extern.h,v 1.19 2002/02/04 01:23:44 kris Exp $
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
void blkfree(char **);
|
||||
char **copyblk(char **);
|
||||
void cwd(char *);
|
||||
void delete(char *);
|
||||
void dologout(int);
|
||||
void fatalerror(char *);
|
||||
void ftpd_logwtmp(char *, char *, struct sockaddr *addr);
|
||||
int ftpd_pclose(FILE *);
|
||||
FILE *ftpd_popen(char *, char *);
|
||||
char *getline(char *, int, FILE *);
|
||||
void lreply(int, const char *, ...) __printflike(2, 3);
|
||||
void makedir(char *);
|
||||
void nack(char *);
|
||||
void pass(char *);
|
||||
void passive(void);
|
||||
void long_passive(char *, int);
|
||||
void perror_reply(int, char *);
|
||||
void pwd(void);
|
||||
void removedir(char *);
|
||||
void renamecmd(char *, char *);
|
||||
char *renamefrom(char *);
|
||||
void reply(int, const char *, ...) __printflike(2, 3);
|
||||
void retrieve(char *, char *);
|
||||
void send_file_list(char *);
|
||||
#ifdef OLD_SETPROCTITLE
|
||||
void setproctitle(const char *, ...);
|
||||
#endif
|
||||
void statcmd(void);
|
||||
void statfilecmd(char *);
|
||||
void store(char *, char *, int);
|
||||
void upper(char *);
|
||||
void user(char *);
|
||||
void yyerror(char *);
|
||||
int yyparse(void);
|
||||
int ls_main(int, char **);
|
||||
|
||||
struct sockaddr_in;
|
||||
struct sockaddr_in6;
|
||||
union sockunion {
|
||||
struct sockinet {
|
||||
u_char si_len;
|
||||
u_char si_family;
|
||||
u_short si_port;
|
||||
} su_si;
|
||||
struct sockaddr_in su_sin;
|
||||
struct sockaddr_in6 su_sin6;
|
||||
};
|
||||
#define su_len su_si.si_len
|
||||
#define su_family su_si.si_family
|
||||
#define su_port su_si.si_port
|
1829
src/bin/network/ftpd/ftpcmd.y
Normal file
1829
src/bin/network/ftpd/ftpcmd.y
Normal file
File diff suppressed because it is too large
Load Diff
3502
src/bin/network/ftpd/ftpd.c
Normal file
3502
src/bin/network/ftpd/ftpd.c
Normal file
File diff suppressed because it is too large
Load Diff
96
src/bin/network/ftpd/logwtmp.c
Normal file
96
src/bin/network/ftpd/logwtmp.c
Normal file
@ -0,0 +1,96 @@
|
||||
/*
|
||||
* Copyright (c) 1988, 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.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)logwtmp.c 8.1 (Berkeley) 6/4/93";
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD: src/libexec/ftpd/logwtmp.c,v 1.13 2004/11/18 13:46:29 yar Exp $");
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <time.h>
|
||||
#ifndef __BEOS__
|
||||
#include <timeconv.h>
|
||||
#include <utmp.h>
|
||||
#endif
|
||||
#include <netdb.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <libutil.h>
|
||||
#include "extern.h"
|
||||
|
||||
static int fd = -1;
|
||||
|
||||
/*
|
||||
* Modified version of logwtmp that holds wtmp file open
|
||||
* after first call, for use with ftp (which may chroot
|
||||
* after login, but before logout).
|
||||
*/
|
||||
void
|
||||
ftpd_logwtmp(line, name, addr)
|
||||
char *line, *name;
|
||||
struct sockaddr *addr;
|
||||
{
|
||||
#ifndef __BEOS__
|
||||
struct utmp ut;
|
||||
struct stat buf;
|
||||
char host[UT_HOSTSIZE];
|
||||
|
||||
if (addr == NULL)
|
||||
host[0] = '\0';
|
||||
else
|
||||
realhostname_sa(host, sizeof(host), addr, addr->sa_len);
|
||||
|
||||
if (fd < 0 && (fd = open(_PATH_WTMP, O_WRONLY|O_APPEND, 0)) < 0)
|
||||
return;
|
||||
if (fstat(fd, &buf) == 0) {
|
||||
(void)strncpy(ut.ut_line, line, sizeof(ut.ut_line));
|
||||
(void)strncpy(ut.ut_name, name, sizeof(ut.ut_name));
|
||||
(void)strncpy(ut.ut_host, host, sizeof(ut.ut_host));
|
||||
ut.ut_time = _time_to_time32(time(NULL));
|
||||
if (write(fd, &ut, sizeof(struct utmp)) !=
|
||||
sizeof(struct utmp))
|
||||
(void)ftruncate(fd, buf.st_size);
|
||||
}
|
||||
#endif
|
||||
}
|
56
src/bin/network/ftpd/md5.h
Normal file
56
src/bin/network/ftpd/md5.h
Normal file
@ -0,0 +1,56 @@
|
||||
/* MD5.H - header file for MD5C.C
|
||||
* $FreeBSD: src/sys/sys/md5.h,v 1.20 2006/03/15 19:47:12 andre Exp $
|
||||
*/
|
||||
|
||||
/*-
|
||||
Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
|
||||
rights reserved.
|
||||
|
||||
License to copy and use this software is granted provided that it
|
||||
is identified as the "RSA Data Security, Inc. MD5 Message-Digest
|
||||
Algorithm" in all material mentioning or referencing this software
|
||||
or this function.
|
||||
|
||||
License is also granted to make and use derivative works provided
|
||||
that such works are identified as "derived from the RSA Data
|
||||
Security, Inc. MD5 Message-Digest Algorithm" in all material
|
||||
mentioning or referencing the derived work.
|
||||
|
||||
RSA Data Security, Inc. makes no representations concerning either
|
||||
the merchantability of this software or the suitability of this
|
||||
software for any particular purpose. It is provided "as is"
|
||||
without express or implied warranty of any kind.
|
||||
|
||||
These notices must be retained in any copies of any part of this
|
||||
documentation and/or software.
|
||||
*/
|
||||
|
||||
#ifndef _SYS_MD5_H_
|
||||
#define _SYS_MD5_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define MD5_BLOCK_LENGTH 64
|
||||
#define MD5_DIGEST_LENGTH 16
|
||||
#define MD5_DIGEST_STRING_LENGTH (MD5_DIGEST_LENGTH * 2 + 1)
|
||||
|
||||
/* MD5 context. */
|
||||
typedef struct MD5Context {
|
||||
u_int32_t state[4]; /* state (ABCD) */
|
||||
u_int32_t count[2]; /* number of bits, modulo 2^64 (lsb first) */
|
||||
unsigned char buffer[64]; /* input buffer */
|
||||
} MD5_CTX;
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
void MD5Init(MD5_CTX *);
|
||||
void MD5Update(MD5_CTX *, const void *, unsigned int);
|
||||
void MD5Final(unsigned char [16], MD5_CTX *);
|
||||
void MD5Pad(MD5_CTX *context);
|
||||
char * MD5End(MD5_CTX *, char *);
|
||||
char * MD5File(const char *, char *);
|
||||
char * MD5FileChunk(const char *, char *, off_t, off_t);
|
||||
char * MD5Data(const void *, unsigned int, char *);
|
||||
__END_DECLS
|
||||
#endif /* _SYS_MD5_H_ */
|
340
src/bin/network/ftpd/md5c.c
Normal file
340
src/bin/network/ftpd/md5c.c
Normal file
@ -0,0 +1,340 @@
|
||||
/*
|
||||
* MD5C.C - RSA Data Security, Inc., MD5 message-digest algorithm
|
||||
*
|
||||
* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
|
||||
* rights reserved.
|
||||
*
|
||||
* License to copy and use this software is granted provided that it
|
||||
* is identified as the "RSA Data Security, Inc. MD5 Message-Digest
|
||||
* Algorithm" in all material mentioning or referencing this software
|
||||
* or this function.
|
||||
*
|
||||
* License is also granted to make and use derivative works provided
|
||||
* that such works are identified as "derived from the RSA Data
|
||||
* Security, Inc. MD5 Message-Digest Algorithm" in all material
|
||||
* mentioning or referencing the derived work.
|
||||
*
|
||||
* RSA Data Security, Inc. makes no representations concerning either
|
||||
* the merchantability of this software or the suitability of this
|
||||
* software for any particular purpose. It is provided "as is"
|
||||
* without express or implied warranty of any kind.
|
||||
*
|
||||
* These notices must be retained in any copies of any part of this
|
||||
* documentation and/or software.
|
||||
*
|
||||
* This code is the same as the code published by RSA Inc. It has been
|
||||
* edited for clarity and style only.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD: src/lib/libmd/md5c.c,v 1.17 2006/01/17 15:35:56 phk Exp $");
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#ifdef _KERNEL
|
||||
#include <sys/systm.h>
|
||||
#else
|
||||
#include <string.h>
|
||||
#endif
|
||||
|
||||
#ifndef __BEOS__
|
||||
#include <machine/endian.h>
|
||||
#include <sys/endian.h>
|
||||
#endif
|
||||
#include <stdint.h>
|
||||
#include <md5.h>
|
||||
|
||||
static void MD5Transform(u_int32_t [4], const unsigned char [64]);
|
||||
|
||||
#ifdef _KERNEL
|
||||
#define memset(x,y,z) bzero(x,z);
|
||||
#define memcpy(x,y,z) bcopy(y, x, z)
|
||||
#endif
|
||||
|
||||
#if (BYTE_ORDER == LITTLE_ENDIAN)
|
||||
#define Encode memcpy
|
||||
#define Decode memcpy
|
||||
#else
|
||||
|
||||
/*
|
||||
* Encodes input (u_int32_t) into output (unsigned char). Assumes len is
|
||||
* a multiple of 4.
|
||||
*/
|
||||
|
||||
static void
|
||||
Encode (unsigned char *output, u_int32_t *input, unsigned int len)
|
||||
{
|
||||
unsigned int i;
|
||||
u_int32_t *op = (u_int32_t *)output;
|
||||
|
||||
for (i = 0; i < len / 4; i++)
|
||||
op[i] = htole32(input[i]);
|
||||
}
|
||||
|
||||
/*
|
||||
* Decodes input (unsigned char) into output (u_int32_t). Assumes len is
|
||||
* a multiple of 4.
|
||||
*/
|
||||
|
||||
static void
|
||||
Decode (u_int32_t *output, const unsigned char *input, unsigned int len)
|
||||
{
|
||||
unsigned int i;
|
||||
const u_int32_t *ip = (const u_int32_t *)input;
|
||||
|
||||
for (i = 0; i < len / 4; i++)
|
||||
output[i] = le32toh(ip[i]);
|
||||
}
|
||||
#endif
|
||||
|
||||
static unsigned char PADDING[64] = {
|
||||
0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
||||
};
|
||||
|
||||
/* F, G, H and I are basic MD5 functions. */
|
||||
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
|
||||
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
|
||||
#define H(x, y, z) ((x) ^ (y) ^ (z))
|
||||
#define I(x, y, z) ((y) ^ ((x) | (~z)))
|
||||
|
||||
/* ROTATE_LEFT rotates x left n bits. */
|
||||
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
|
||||
|
||||
/*
|
||||
* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
|
||||
* Rotation is separate from addition to prevent recomputation.
|
||||
*/
|
||||
#define FF(a, b, c, d, x, s, ac) { \
|
||||
(a) += F ((b), (c), (d)) + (x) + (u_int32_t)(ac); \
|
||||
(a) = ROTATE_LEFT ((a), (s)); \
|
||||
(a) += (b); \
|
||||
}
|
||||
#define GG(a, b, c, d, x, s, ac) { \
|
||||
(a) += G ((b), (c), (d)) + (x) + (u_int32_t)(ac); \
|
||||
(a) = ROTATE_LEFT ((a), (s)); \
|
||||
(a) += (b); \
|
||||
}
|
||||
#define HH(a, b, c, d, x, s, ac) { \
|
||||
(a) += H ((b), (c), (d)) + (x) + (u_int32_t)(ac); \
|
||||
(a) = ROTATE_LEFT ((a), (s)); \
|
||||
(a) += (b); \
|
||||
}
|
||||
#define II(a, b, c, d, x, s, ac) { \
|
||||
(a) += I ((b), (c), (d)) + (x) + (u_int32_t)(ac); \
|
||||
(a) = ROTATE_LEFT ((a), (s)); \
|
||||
(a) += (b); \
|
||||
}
|
||||
|
||||
/* MD5 initialization. Begins an MD5 operation, writing a new context. */
|
||||
|
||||
void
|
||||
MD5Init (context)
|
||||
MD5_CTX *context;
|
||||
{
|
||||
|
||||
context->count[0] = context->count[1] = 0;
|
||||
|
||||
/* Load magic initialization constants. */
|
||||
context->state[0] = 0x67452301;
|
||||
context->state[1] = 0xefcdab89;
|
||||
context->state[2] = 0x98badcfe;
|
||||
context->state[3] = 0x10325476;
|
||||
}
|
||||
|
||||
/*
|
||||
* MD5 block update operation. Continues an MD5 message-digest
|
||||
* operation, processing another message block, and updating the
|
||||
* context.
|
||||
*/
|
||||
|
||||
void
|
||||
MD5Update (context, in, inputLen)
|
||||
MD5_CTX *context;
|
||||
const void *in;
|
||||
unsigned int inputLen;
|
||||
{
|
||||
unsigned int i, idx, partLen;
|
||||
const unsigned char *input = in;
|
||||
|
||||
/* Compute number of bytes mod 64 */
|
||||
idx = (unsigned int)((context->count[0] >> 3) & 0x3F);
|
||||
|
||||
/* Update number of bits */
|
||||
if ((context->count[0] += ((u_int32_t)inputLen << 3))
|
||||
< ((u_int32_t)inputLen << 3))
|
||||
context->count[1]++;
|
||||
context->count[1] += ((u_int32_t)inputLen >> 29);
|
||||
|
||||
partLen = 64 - idx;
|
||||
|
||||
/* Transform as many times as possible. */
|
||||
if (inputLen >= partLen) {
|
||||
memcpy((void *)&context->buffer[idx], (const void *)input,
|
||||
partLen);
|
||||
MD5Transform (context->state, context->buffer);
|
||||
|
||||
for (i = partLen; i + 63 < inputLen; i += 64)
|
||||
MD5Transform (context->state, &input[i]);
|
||||
|
||||
idx = 0;
|
||||
}
|
||||
else
|
||||
i = 0;
|
||||
|
||||
/* Buffer remaining input */
|
||||
memcpy ((void *)&context->buffer[idx], (const void *)&input[i],
|
||||
inputLen-i);
|
||||
}
|
||||
|
||||
/*
|
||||
* MD5 padding. Adds padding followed by original length.
|
||||
*/
|
||||
|
||||
void
|
||||
MD5Pad (context)
|
||||
MD5_CTX *context;
|
||||
{
|
||||
unsigned char bits[8];
|
||||
unsigned int idx, padLen;
|
||||
|
||||
/* Save number of bits */
|
||||
Encode (bits, context->count, 8);
|
||||
|
||||
/* Pad out to 56 mod 64. */
|
||||
idx = (unsigned int)((context->count[0] >> 3) & 0x3f);
|
||||
padLen = (idx < 56) ? (56 - idx) : (120 - idx);
|
||||
MD5Update (context, PADDING, padLen);
|
||||
|
||||
/* Append length (before padding) */
|
||||
MD5Update (context, bits, 8);
|
||||
}
|
||||
|
||||
/*
|
||||
* MD5 finalization. Ends an MD5 message-digest operation, writing the
|
||||
* the message digest and zeroizing the context.
|
||||
*/
|
||||
|
||||
void
|
||||
MD5Final (digest, context)
|
||||
unsigned char digest[16];
|
||||
MD5_CTX *context;
|
||||
{
|
||||
/* Do padding. */
|
||||
MD5Pad (context);
|
||||
|
||||
/* Store state in digest */
|
||||
Encode (digest, context->state, 16);
|
||||
|
||||
/* Zeroize sensitive information. */
|
||||
memset ((void *)context, 0, sizeof (*context));
|
||||
}
|
||||
|
||||
/* MD5 basic transformation. Transforms state based on block. */
|
||||
|
||||
static void
|
||||
MD5Transform (state, block)
|
||||
u_int32_t state[4];
|
||||
const unsigned char block[64];
|
||||
{
|
||||
u_int32_t a = state[0], b = state[1], c = state[2], d = state[3], x[16];
|
||||
|
||||
Decode (x, block, 64);
|
||||
|
||||
/* Round 1 */
|
||||
#define S11 7
|
||||
#define S12 12
|
||||
#define S13 17
|
||||
#define S14 22
|
||||
FF (a, b, c, d, x[ 0], S11, 0xd76aa478); /* 1 */
|
||||
FF (d, a, b, c, x[ 1], S12, 0xe8c7b756); /* 2 */
|
||||
FF (c, d, a, b, x[ 2], S13, 0x242070db); /* 3 */
|
||||
FF (b, c, d, a, x[ 3], S14, 0xc1bdceee); /* 4 */
|
||||
FF (a, b, c, d, x[ 4], S11, 0xf57c0faf); /* 5 */
|
||||
FF (d, a, b, c, x[ 5], S12, 0x4787c62a); /* 6 */
|
||||
FF (c, d, a, b, x[ 6], S13, 0xa8304613); /* 7 */
|
||||
FF (b, c, d, a, x[ 7], S14, 0xfd469501); /* 8 */
|
||||
FF (a, b, c, d, x[ 8], S11, 0x698098d8); /* 9 */
|
||||
FF (d, a, b, c, x[ 9], S12, 0x8b44f7af); /* 10 */
|
||||
FF (c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */
|
||||
FF (b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */
|
||||
FF (a, b, c, d, x[12], S11, 0x6b901122); /* 13 */
|
||||
FF (d, a, b, c, x[13], S12, 0xfd987193); /* 14 */
|
||||
FF (c, d, a, b, x[14], S13, 0xa679438e); /* 15 */
|
||||
FF (b, c, d, a, x[15], S14, 0x49b40821); /* 16 */
|
||||
|
||||
/* Round 2 */
|
||||
#define S21 5
|
||||
#define S22 9
|
||||
#define S23 14
|
||||
#define S24 20
|
||||
GG (a, b, c, d, x[ 1], S21, 0xf61e2562); /* 17 */
|
||||
GG (d, a, b, c, x[ 6], S22, 0xc040b340); /* 18 */
|
||||
GG (c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */
|
||||
GG (b, c, d, a, x[ 0], S24, 0xe9b6c7aa); /* 20 */
|
||||
GG (a, b, c, d, x[ 5], S21, 0xd62f105d); /* 21 */
|
||||
GG (d, a, b, c, x[10], S22, 0x2441453); /* 22 */
|
||||
GG (c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */
|
||||
GG (b, c, d, a, x[ 4], S24, 0xe7d3fbc8); /* 24 */
|
||||
GG (a, b, c, d, x[ 9], S21, 0x21e1cde6); /* 25 */
|
||||
GG (d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */
|
||||
GG (c, d, a, b, x[ 3], S23, 0xf4d50d87); /* 27 */
|
||||
GG (b, c, d, a, x[ 8], S24, 0x455a14ed); /* 28 */
|
||||
GG (a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */
|
||||
GG (d, a, b, c, x[ 2], S22, 0xfcefa3f8); /* 30 */
|
||||
GG (c, d, a, b, x[ 7], S23, 0x676f02d9); /* 31 */
|
||||
GG (b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */
|
||||
|
||||
/* Round 3 */
|
||||
#define S31 4
|
||||
#define S32 11
|
||||
#define S33 16
|
||||
#define S34 23
|
||||
HH (a, b, c, d, x[ 5], S31, 0xfffa3942); /* 33 */
|
||||
HH (d, a, b, c, x[ 8], S32, 0x8771f681); /* 34 */
|
||||
HH (c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */
|
||||
HH (b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */
|
||||
HH (a, b, c, d, x[ 1], S31, 0xa4beea44); /* 37 */
|
||||
HH (d, a, b, c, x[ 4], S32, 0x4bdecfa9); /* 38 */
|
||||
HH (c, d, a, b, x[ 7], S33, 0xf6bb4b60); /* 39 */
|
||||
HH (b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */
|
||||
HH (a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */
|
||||
HH (d, a, b, c, x[ 0], S32, 0xeaa127fa); /* 42 */
|
||||
HH (c, d, a, b, x[ 3], S33, 0xd4ef3085); /* 43 */
|
||||
HH (b, c, d, a, x[ 6], S34, 0x4881d05); /* 44 */
|
||||
HH (a, b, c, d, x[ 9], S31, 0xd9d4d039); /* 45 */
|
||||
HH (d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */
|
||||
HH (c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */
|
||||
HH (b, c, d, a, x[ 2], S34, 0xc4ac5665); /* 48 */
|
||||
|
||||
/* Round 4 */
|
||||
#define S41 6
|
||||
#define S42 10
|
||||
#define S43 15
|
||||
#define S44 21
|
||||
II (a, b, c, d, x[ 0], S41, 0xf4292244); /* 49 */
|
||||
II (d, a, b, c, x[ 7], S42, 0x432aff97); /* 50 */
|
||||
II (c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */
|
||||
II (b, c, d, a, x[ 5], S44, 0xfc93a039); /* 52 */
|
||||
II (a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */
|
||||
II (d, a, b, c, x[ 3], S42, 0x8f0ccc92); /* 54 */
|
||||
II (c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */
|
||||
II (b, c, d, a, x[ 1], S44, 0x85845dd1); /* 56 */
|
||||
II (a, b, c, d, x[ 8], S41, 0x6fa87e4f); /* 57 */
|
||||
II (d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */
|
||||
II (c, d, a, b, x[ 6], S43, 0xa3014314); /* 59 */
|
||||
II (b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */
|
||||
II (a, b, c, d, x[ 4], S41, 0xf7537e82); /* 61 */
|
||||
II (d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */
|
||||
II (c, d, a, b, x[ 2], S43, 0x2ad7d2bb); /* 63 */
|
||||
II (b, c, d, a, x[ 9], S44, 0xeb86d391); /* 64 */
|
||||
|
||||
state[0] += a;
|
||||
state[1] += b;
|
||||
state[2] += c;
|
||||
state[3] += d;
|
||||
|
||||
/* Zeroize sensitive information. */
|
||||
memset ((void *)x, 0, sizeof (x));
|
||||
}
|
98
src/bin/network/ftpd/md5hl.c
Normal file
98
src/bin/network/ftpd/md5hl.c
Normal file
@ -0,0 +1,98 @@
|
||||
/* mdXhl.c * ----------------------------------------------------------------------------
|
||||
* "THE BEER-WARE LICENSE" (Revision 42):
|
||||
* <phk@FreeBSD.org> wrote this file. As long as you retain this notice you
|
||||
* can do whatever you want with this stuff. If we meet some day, and you think
|
||||
* this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD: src/lib/libmd/mdXhl.c,v 1.19 2006/01/17 15:35:56 phk Exp $");
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "md5.h"
|
||||
|
||||
char *
|
||||
MD5End(MD5_CTX *ctx, char *buf)
|
||||
{
|
||||
int i;
|
||||
unsigned char digest[MD5_DIGEST_LENGTH];
|
||||
static const char hex[]="0123456789abcdef";
|
||||
|
||||
if (!buf)
|
||||
buf = malloc(2*MD5_DIGEST_LENGTH + 1);
|
||||
if (!buf)
|
||||
return 0;
|
||||
MD5Final(digest, ctx);
|
||||
for (i = 0; i < MD5_DIGEST_LENGTH; i++) {
|
||||
buf[i+i] = hex[digest[i] >> 4];
|
||||
buf[i+i+1] = hex[digest[i] & 0x0f];
|
||||
}
|
||||
buf[i+i] = '\0';
|
||||
return buf;
|
||||
}
|
||||
|
||||
char *
|
||||
MD5File(const char *filename, char *buf)
|
||||
{
|
||||
return (MD5FileChunk(filename, buf, 0, 0));
|
||||
}
|
||||
|
||||
char *
|
||||
MD5FileChunk(const char *filename, char *buf, off_t ofs, off_t len)
|
||||
{
|
||||
unsigned char buffer[BUFSIZ];
|
||||
MD5_CTX ctx;
|
||||
struct stat stbuf;
|
||||
int f, i, e;
|
||||
off_t n;
|
||||
|
||||
MD5Init(&ctx);
|
||||
f = open(filename, O_RDONLY);
|
||||
if (f < 0)
|
||||
return 0;
|
||||
if (fstat(f, &stbuf) < 0)
|
||||
return 0;
|
||||
if (ofs > stbuf.st_size)
|
||||
ofs = stbuf.st_size;
|
||||
if ((len == 0) || (len > stbuf.st_size - ofs))
|
||||
len = stbuf.st_size - ofs;
|
||||
if (lseek(f, ofs, SEEK_SET) < 0)
|
||||
return 0;
|
||||
n = len;
|
||||
i = 0;
|
||||
while (n > 0) {
|
||||
if (n > sizeof(buffer))
|
||||
i = read(f, buffer, sizeof(buffer));
|
||||
else
|
||||
i = read(f, buffer, n);
|
||||
if (i < 0)
|
||||
break;
|
||||
MD5Update(&ctx, buffer, i);
|
||||
n -= i;
|
||||
}
|
||||
e = errno;
|
||||
close(f);
|
||||
errno = e;
|
||||
if (i < 0)
|
||||
return 0;
|
||||
return (MD5End(&ctx, buf));
|
||||
}
|
||||
|
||||
char *
|
||||
MD5Data (const void *data, unsigned int len, char *buf)
|
||||
{
|
||||
MD5_CTX ctx;
|
||||
|
||||
MD5Init(&ctx);
|
||||
MD5Update(&ctx,data,len);
|
||||
return (MD5End(&ctx, buf));
|
||||
}
|
44
src/bin/network/ftpd/pathnames.h
Normal file
44
src/bin/network/ftpd/pathnames.h
Normal file
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (c) 1989, 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.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 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.
|
||||
*
|
||||
* @(#)pathnames.h 8.1 (Berkeley) 6/4/93
|
||||
* $FreeBSD: src/libexec/ftpd/pathnames.h,v 1.11 1999/08/28 00:09:31 peter Exp $
|
||||
*/
|
||||
|
||||
#include <paths.h>
|
||||
|
||||
#define _PATH_FTPCHROOT "/etc/ftpchroot"
|
||||
#define _PATH_FTPWELCOME "/etc/ftpwelcome"
|
||||
#define _PATH_FTPLOGINMESG "/etc/ftpmotd"
|
||||
#define _PATH_FTPHOSTS "/etc/ftphosts"
|
||||
#define _PATH_FTPDSTATFILE "/var/log/ftpd"
|
||||
#define _PATH_LS "/bin/ls"
|
207
src/bin/network/ftpd/popen.c
Normal file
207
src/bin/network/ftpd/popen.c
Normal file
@ -0,0 +1,207 @@
|
||||
/*
|
||||
* Copyright (c) 1988, 1993, 1994
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software written by Ken Arnold and
|
||||
* published in UNIX Review, Vol. 6, No. 8.
|
||||
*
|
||||
* 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.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)popen.c 8.3 (Berkeley) 4/6/94";
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD: src/libexec/ftpd/popen.c,v 1.26 2004/11/18 13:46:29 yar Exp $");
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <glob.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "extern.h"
|
||||
#include "pathnames.h"
|
||||
#include <syslog.h>
|
||||
#include <time.h>
|
||||
|
||||
#define MAXUSRARGS 100
|
||||
#define MAXGLOBARGS 1000
|
||||
|
||||
/*
|
||||
* Special version of popen which avoids call to shell. This ensures noone
|
||||
* may create a pipe to a hidden program as a side effect of a list or dir
|
||||
* command.
|
||||
*/
|
||||
static int *pids;
|
||||
static int fds;
|
||||
|
||||
FILE *
|
||||
ftpd_popen(char *program, char *type)
|
||||
{
|
||||
char *cp;
|
||||
FILE *iop;
|
||||
int argc, gargc, pdes[2], pid;
|
||||
char **pop, *argv[MAXUSRARGS], *gargv[MAXGLOBARGS];
|
||||
|
||||
if (((*type != 'r') && (*type != 'w')) || type[1])
|
||||
return (NULL);
|
||||
|
||||
if (!pids) {
|
||||
if ((fds = getdtablesize()) <= 0)
|
||||
return (NULL);
|
||||
if ((pids = malloc(fds * sizeof(int))) == NULL)
|
||||
return (NULL);
|
||||
memset(pids, 0, fds * sizeof(int));
|
||||
}
|
||||
if (pipe(pdes) < 0)
|
||||
return (NULL);
|
||||
|
||||
/* break up string into pieces */
|
||||
for (argc = 0, cp = program; argc < MAXUSRARGS; cp = NULL) {
|
||||
if (!(argv[argc++] = strtok(cp, " \t\n")))
|
||||
break;
|
||||
}
|
||||
argv[argc - 1] = NULL;
|
||||
|
||||
/* glob each piece */
|
||||
gargv[0] = argv[0];
|
||||
for (gargc = argc = 1; argv[argc] && gargc < (MAXGLOBARGS-1); argc++) {
|
||||
glob_t gl;
|
||||
int flags = GLOB_BRACE|GLOB_NOCHECK|GLOB_TILDE;
|
||||
|
||||
memset(&gl, 0, sizeof(gl));
|
||||
gl.gl_matchc = MAXGLOBARGS;
|
||||
flags |= GLOB_LIMIT;
|
||||
if (glob(argv[argc], flags, NULL, &gl))
|
||||
gargv[gargc++] = strdup(argv[argc]);
|
||||
else
|
||||
for (pop = gl.gl_pathv; *pop && gargc < (MAXGLOBARGS-1);
|
||||
pop++)
|
||||
gargv[gargc++] = strdup(*pop);
|
||||
globfree(&gl);
|
||||
}
|
||||
gargv[gargc] = NULL;
|
||||
|
||||
iop = NULL;
|
||||
fflush(NULL);
|
||||
#ifdef BUILTIN_LS
|
||||
pid = (strcmp(gargv[0], _PATH_LS) == 0) ? fork() : vfork();
|
||||
#else
|
||||
pid = fork();
|
||||
#endif
|
||||
switch(pid) {
|
||||
case -1: /* error */
|
||||
(void)close(pdes[0]);
|
||||
(void)close(pdes[1]);
|
||||
goto pfree;
|
||||
/* NOTREACHED */
|
||||
case 0: /* child */
|
||||
if (*type == 'r') {
|
||||
if (pdes[1] != STDOUT_FILENO) {
|
||||
dup2(pdes[1], STDOUT_FILENO);
|
||||
(void)close(pdes[1]);
|
||||
}
|
||||
dup2(STDOUT_FILENO, STDERR_FILENO); /* stderr too! */
|
||||
(void)close(pdes[0]);
|
||||
} else {
|
||||
if (pdes[0] != STDIN_FILENO) {
|
||||
dup2(pdes[0], STDIN_FILENO);
|
||||
(void)close(pdes[0]);
|
||||
}
|
||||
(void)close(pdes[1]);
|
||||
}
|
||||
#ifdef BUILTIN_LS
|
||||
if (strcmp(gargv[0], _PATH_LS) == 0) {
|
||||
/* Reset getopt for ls_main() */
|
||||
optreset = optind = optopt = 1;
|
||||
/* Close syslogging to remove pwd.db missing msgs */
|
||||
closelog();
|
||||
/* Trigger to sense new /etc/localtime after chroot */
|
||||
if (getenv("TZ") == NULL) {
|
||||
setenv("TZ", "", 0);
|
||||
tzset();
|
||||
unsetenv("TZ");
|
||||
tzset();
|
||||
}
|
||||
exit(ls_main(gargc, gargv));
|
||||
}
|
||||
#endif
|
||||
execv(gargv[0], gargv);
|
||||
_exit(1);
|
||||
}
|
||||
/* parent; assume fdopen can't fail... */
|
||||
if (*type == 'r') {
|
||||
iop = fdopen(pdes[0], type);
|
||||
(void)close(pdes[1]);
|
||||
} else {
|
||||
iop = fdopen(pdes[1], type);
|
||||
(void)close(pdes[0]);
|
||||
}
|
||||
pids[fileno(iop)] = pid;
|
||||
|
||||
pfree: for (argc = 1; gargv[argc] != NULL; argc++)
|
||||
free(gargv[argc]);
|
||||
|
||||
return (iop);
|
||||
}
|
||||
|
||||
int
|
||||
ftpd_pclose(FILE *iop)
|
||||
{
|
||||
int fdes, omask, status;
|
||||
pid_t pid;
|
||||
|
||||
/*
|
||||
* pclose returns -1 if stream is not associated with a
|
||||
* `popened' command, or, if already `pclosed'.
|
||||
*/
|
||||
if (pids == 0 || pids[fdes = fileno(iop)] == 0)
|
||||
return (-1);
|
||||
(void)fclose(iop);
|
||||
omask = sigblock(sigmask(SIGINT)|sigmask(SIGQUIT)|sigmask(SIGHUP));
|
||||
while ((pid = waitpid(pids[fdes], &status, 0)) < 0 && errno == EINTR)
|
||||
continue;
|
||||
(void)sigsetmask(omask);
|
||||
pids[fdes] = 0;
|
||||
if (pid < 0)
|
||||
return (pid);
|
||||
if (WIFEXITED(status))
|
||||
return (WEXITSTATUS(status));
|
||||
return (1);
|
||||
}
|
Loading…
Reference in New Issue
Block a user