Changes for new merged security stuff.
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@4670 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
@@ -1484,7 +1484,7 @@ disconnect(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
cout = NULL;
|
cout = NULL;
|
||||||
connected = 0;
|
connected = 0;
|
||||||
krb4_quit();
|
sec_end();
|
||||||
data = -1;
|
data = -1;
|
||||||
if (!proxy) {
|
if (!proxy) {
|
||||||
macnum = 0;
|
macnum = 0;
|
||||||
|
@@ -177,7 +177,7 @@ login(char *host)
|
|||||||
|
|
||||||
user = pass = acct = 0;
|
user = pass = acct = 0;
|
||||||
|
|
||||||
if(do_klogin(host))
|
if(sec_login(host))
|
||||||
printf("\n*** Using plaintext user and password ***\n\n");
|
printf("\n*** Using plaintext user and password ***\n\n");
|
||||||
else{
|
else{
|
||||||
printf("Kerberos authentication successful.\n\n");
|
printf("Kerberos authentication successful.\n\n");
|
||||||
@@ -202,7 +202,7 @@ login(char *host)
|
|||||||
strcpy(username, user);
|
strcpy(username, user);
|
||||||
n = command("USER %s", user);
|
n = command("USER %s", user);
|
||||||
if (n == CONTINUE) {
|
if (n == CONTINUE) {
|
||||||
if(auth_complete)
|
if(sec_complete)
|
||||||
pass = myname;
|
pass = myname;
|
||||||
else if (pass == NULL) {
|
else if (pass == NULL) {
|
||||||
char prompt[128];
|
char prompt[128];
|
||||||
@@ -281,10 +281,7 @@ command(char *fmt, ...)
|
|||||||
vfprintf(stdout, fmt, ap);
|
vfprintf(stdout, fmt, ap);
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
}
|
}
|
||||||
if(auth_complete)
|
sec_vfprintf(cout, fmt, ap);
|
||||||
krb4_write_enc(cout, fmt, ap);
|
|
||||||
else
|
|
||||||
vfprintf(cout, fmt, ap);
|
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
if(debug){
|
if(debug){
|
||||||
printf("\n");
|
printf("\n");
|
||||||
@@ -348,16 +345,18 @@ getreply(int expecteof)
|
|||||||
if(isdigit(buf[0])){
|
if(isdigit(buf[0])){
|
||||||
sscanf(buf, "%d", &code);
|
sscanf(buf, "%d", &code);
|
||||||
if(code == 631){
|
if(code == 631){
|
||||||
krb4_read_mic(buf);
|
sec_read_msg(buf, prot_safe);
|
||||||
sscanf(buf, "%d", &code);
|
sscanf(buf, "%d", &code);
|
||||||
lead_string = "S:";
|
lead_string = "S:";
|
||||||
} else if(code == 632){
|
} else if(code == 632){
|
||||||
krb4_read_enc(buf);
|
sec_read_msg(buf, prot_private);
|
||||||
sscanf(buf, "%d", &code);
|
sscanf(buf, "%d", &code);
|
||||||
lead_string = "P:";
|
lead_string = "P:";
|
||||||
}else if(code == 633){
|
}else if(code == 633){
|
||||||
printf("Received confidential reply!\n");
|
sec_read_msg(buf, prot_confidential);
|
||||||
}else if(auth_complete)
|
sscanf(buf, "%d", &code);
|
||||||
|
lead_string = "C:";
|
||||||
|
}else if(sec_complete)
|
||||||
lead_string = "!!";
|
lead_string = "!!";
|
||||||
else
|
else
|
||||||
lead_string = "";
|
lead_string = "";
|
||||||
@@ -393,7 +392,7 @@ getreply(int expecteof)
|
|||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
if(verbose > 0 || (verbose > -1 && code > 499)){
|
if(verbose > 0 || (verbose > -1 && code > 499)){
|
||||||
if(auth_complete)
|
if(sec_complete)
|
||||||
fprintf(stdout, "!!");
|
fprintf(stdout, "!!");
|
||||||
fprintf(stdout, "%s\n", buf);
|
fprintf(stdout, "%s\n", buf);
|
||||||
}
|
}
|
||||||
@@ -499,11 +498,13 @@ getreply(int expecteof)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
*cp = '\0';
|
*cp = '\0';
|
||||||
if(auth_complete){
|
if(sec_complete){
|
||||||
if(code == 631)
|
if(code == 631)
|
||||||
krb4_read_mic(reply_string);
|
sec_read_msg(reply_string, prot_safe);
|
||||||
else
|
else if(code == 632)
|
||||||
krb4_read_enc(reply_string);
|
sec_read_msg(reply_string, prot_private);
|
||||||
|
else if(code == 633)
|
||||||
|
sec_read_msg(reply_string, prot_confidential);
|
||||||
n = code / 100 + '0';
|
n = code / 100 + '0';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -127,13 +127,8 @@ extern int LIBPREFIX(fclose) __P((FILE *));
|
|||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "pathnames.h"
|
#include "pathnames.h"
|
||||||
|
|
||||||
#include <des.h>
|
|
||||||
|
|
||||||
#include <krb.h>
|
|
||||||
|
|
||||||
#include "krb4.h"
|
|
||||||
|
|
||||||
#include "roken.h"
|
#include "roken.h"
|
||||||
|
#include "security.h"
|
||||||
|
|
||||||
#if defined(__sun__) && !defined(__svr4)
|
#if defined(__sun__) && !defined(__svr4)
|
||||||
int fclose(FILE*);
|
int fclose(FILE*);
|
||||||
|
@@ -174,7 +174,7 @@ lostpeer(int sig)
|
|||||||
}
|
}
|
||||||
proxflag = 0;
|
proxflag = 0;
|
||||||
pswitch(0);
|
pswitch(0);
|
||||||
krb4_quit();
|
sec_end();
|
||||||
SIGRETURN(0);
|
SIGRETURN(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -44,14 +44,25 @@ LIBROKEN= -L$(LIBTOP)/roken -lroken
|
|||||||
|
|
||||||
PROGS = ftpd$(EXECSUFFIX)
|
PROGS = ftpd$(EXECSUFFIX)
|
||||||
|
|
||||||
ftpd_SOURCES = ftpd.c ftpcmd.c logwtmp.c popen.c auth.c krb4.c kauth.c
|
ftpd_SOURCES = ftpd.c ftpcmd.c logwtmp.c popen.c security.c krb4.c kauth.c
|
||||||
ftpd_OBJS = ftpd.o ftpcmd.o logwtmp.o popen.o auth.o krb4.o kauth.o
|
ftpd_OBJS = ftpd.o ftpcmd.o logwtmp.o popen.o security.o krb4.o kauth.o
|
||||||
|
|
||||||
SOURCES = $(ftpd_SOURCES)
|
SOURCES = $(ftpd_SOURCES)
|
||||||
OBJECTS = $(ftpd_OBJS)
|
OBJECTS = $(ftpd_OBJS)
|
||||||
|
|
||||||
all: $(PROGS)
|
all: $(PROGS)
|
||||||
|
|
||||||
|
$(ftpd_OBJS): security.h
|
||||||
|
|
||||||
|
security.c:
|
||||||
|
$(LN_S) $(srcdir)/../ftp/security.c .
|
||||||
|
security.h:
|
||||||
|
$(LN_S) $(srcdir)/../ftp/security.h .
|
||||||
|
krb4.c:
|
||||||
|
$(LN_S) $(srcdir)/../ftp/krb4.c .
|
||||||
|
gssapi.c:
|
||||||
|
$(LN_S) $(srcdir)/../ftp/gssapi.c .
|
||||||
|
|
||||||
.c.o:
|
.c.o:
|
||||||
$(CC) -c -I$(srcdir) -I$(srcdir)/../common -I$(INCTOP) $(DEFS) $(CFLAGS) $(CPPFLAGS) $<
|
$(CC) -c -I$(srcdir) -I$(srcdir)/../common -I$(INCTOP) $(DEFS) $(CFLAGS) $(CPPFLAGS) $<
|
||||||
|
|
||||||
@@ -77,8 +88,10 @@ ftpcmd.c: ftpcmd.y
|
|||||||
TAGS: $(SOURCES)
|
TAGS: $(SOURCES)
|
||||||
etags $(SOURCES)
|
etags $(SOURCES)
|
||||||
|
|
||||||
|
CLEANFILES = ftpd$(EXECSUFFIX) ftpcmd.c security.c security.h krb4.c gssapi.c
|
||||||
|
|
||||||
clean cleandir:
|
clean cleandir:
|
||||||
rm -f *~ *.o core ftpd$(EXECSUFFIX) ftpcmd.c \#*
|
rm -f *~ *.o core \#* $(CLEANFILES)
|
||||||
|
|
||||||
distclean:
|
distclean:
|
||||||
rm -f Makefile
|
rm -f Makefile
|
||||||
|
@@ -42,73 +42,15 @@
|
|||||||
|
|
||||||
%{
|
%{
|
||||||
|
|
||||||
|
#include "ftpd_locl.h"
|
||||||
#ifdef HAVE_CONFIG_H
|
|
||||||
#include <config.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
RCSID("$Id$");
|
RCSID("$Id$");
|
||||||
|
|
||||||
#ifdef HAVE_SYS_TYPES_H
|
|
||||||
#include <sys/types.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef HAVE_SYS_PARAM_H
|
|
||||||
#include <sys/param.h>
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_SYS_SOCKET_H
|
|
||||||
#include <sys/socket.h>
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_SYS_STAT_H
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef HAVE_NETINET_IN_H
|
|
||||||
#include <netinet/in.h>
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_ARPA_FTP_H
|
|
||||||
#include <arpa/ftp.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <ctype.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include <glob.h>
|
|
||||||
#ifdef HAVE_PWD_H
|
|
||||||
#include <pwd.h>
|
|
||||||
#endif
|
|
||||||
#include <setjmp.h>
|
|
||||||
#include <signal.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#ifdef HAVE_SYSLOG_H
|
|
||||||
#include <syslog.h>
|
|
||||||
#endif
|
|
||||||
#include <time.h>
|
|
||||||
#ifdef HAVE_UNISTD_H
|
|
||||||
#include <unistd.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef HAVE_BSD_BSD_H
|
|
||||||
#include <bsd/bsd.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <roken.h>
|
|
||||||
|
|
||||||
#ifdef SOCKS
|
|
||||||
#include <socks.h>
|
|
||||||
extern int LIBPREFIX(fclose) __P((FILE *));
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "extern.h"
|
|
||||||
#include "auth.h"
|
|
||||||
|
|
||||||
off_t restart_point;
|
off_t restart_point;
|
||||||
|
|
||||||
static int cmd_type;
|
static int cmd_type;
|
||||||
static int cmd_form;
|
static int cmd_form;
|
||||||
static int cmd_bytesz;
|
static int cmd_bytesz;
|
||||||
char cbuf[512];
|
char cbuf[2048];
|
||||||
char *fromname;
|
char *fromname;
|
||||||
|
|
||||||
struct tab {
|
struct tab {
|
||||||
@@ -170,7 +112,7 @@ static int yylex (void);
|
|||||||
%token <s> STRING
|
%token <s> STRING
|
||||||
%token <i> NUMBER
|
%token <i> NUMBER
|
||||||
|
|
||||||
%type <i> check_login check_login_no_guest octal_number byte_size
|
%type <i> check_login check_login_no_guest check_secure octal_number byte_size
|
||||||
%type <i> struct_code mode_code type_code form_code
|
%type <i> struct_code mode_code type_code form_code
|
||||||
%type <s> pathstring pathname password username
|
%type <s> pathstring pathname password username
|
||||||
|
|
||||||
@@ -218,12 +160,17 @@ cmd
|
|||||||
}
|
}
|
||||||
| MIC SP STRING CRLF
|
| MIC SP STRING CRLF
|
||||||
{
|
{
|
||||||
mic($3);
|
mec($3, prot_safe);
|
||||||
free($3);
|
free($3);
|
||||||
}
|
}
|
||||||
| CONF SP STRING CRLF
|
| CONF SP STRING CRLF
|
||||||
{
|
{
|
||||||
conf($3);
|
mec($3, prot_confidential);
|
||||||
|
free($3);
|
||||||
|
}
|
||||||
|
| ENC SP STRING CRLF
|
||||||
|
{
|
||||||
|
mec($3, prot_private);
|
||||||
free($3);
|
free($3);
|
||||||
}
|
}
|
||||||
| PASS SP password CRLF
|
| PASS SP password CRLF
|
||||||
@@ -704,11 +651,6 @@ rcmd
|
|||||||
(long)restart_point,
|
(long)restart_point,
|
||||||
"Send STORE or RETRIEVE to initiate transfer.");
|
"Send STORE or RETRIEVE to initiate transfer.");
|
||||||
}
|
}
|
||||||
| ENC SP STRING CRLF
|
|
||||||
{
|
|
||||||
enc($3);
|
|
||||||
free($3);
|
|
||||||
}
|
|
||||||
;
|
;
|
||||||
|
|
||||||
username
|
username
|
||||||
@@ -893,19 +835,24 @@ check_login_no_guest : check_login
|
|||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
check_login
|
check_login : check_secure
|
||||||
: /* empty */
|
|
||||||
{
|
{
|
||||||
if(auth_complete && prot_level == prot_clear){
|
if($1) {
|
||||||
reply(533, "Command protection level denied for paranoid reasons.");
|
if(($$ = logged_in) == 0)
|
||||||
$$ = 0;
|
|
||||||
}else
|
|
||||||
if (logged_in)
|
|
||||||
$$ = 1;
|
|
||||||
else {
|
|
||||||
reply(530, "Please login with USER and PASS.");
|
reply(530, "Please login with USER and PASS.");
|
||||||
$$ = 0;
|
} else
|
||||||
}
|
$$ = 0;
|
||||||
|
}
|
||||||
|
;
|
||||||
|
|
||||||
|
check_secure : /* empty */
|
||||||
|
{
|
||||||
|
$$ = 1;
|
||||||
|
if(sec_complete && !secure_command()) {
|
||||||
|
$$ = 0;
|
||||||
|
reply(533, "Command protection level denied "
|
||||||
|
"for paranoid reasons.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
@@ -1014,8 +961,6 @@ lookup(struct tab *p, char *cmd)
|
|||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
#include <arpa/telnet.h>
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* getline - a hacked up version of fgets to ignore TELNET escape codes.
|
* getline - a hacked up version of fgets to ignore TELNET escape codes.
|
||||||
*/
|
*/
|
||||||
@@ -1036,7 +981,6 @@ getline(char *s, int n)
|
|||||||
#endif
|
#endif
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
prot_level = prot_clear;
|
|
||||||
while ((c = getc(stdin)) != EOF) {
|
while ((c = getc(stdin)) != EOF) {
|
||||||
c &= 0377;
|
c &= 0377;
|
||||||
if (c == IAC) {
|
if (c == IAC) {
|
||||||
@@ -1127,10 +1071,10 @@ yylex(void)
|
|||||||
dologout(0);
|
dologout(0);
|
||||||
}
|
}
|
||||||
alarm(0);
|
alarm(0);
|
||||||
#ifdef HASSETPROCTITLE
|
#ifdef HAVE_SETPROCTITLE
|
||||||
if (strncasecmp(cbuf, "PASS", 4) != NULL)
|
if (strncasecmp(cbuf, "PASS", 4) != NULL)
|
||||||
setproctitle("%s: %s", proctitle, cbuf);
|
setproctitle("%s: %s", proctitle, cbuf);
|
||||||
#endif /* HASSETPROCTITLE */
|
#endif
|
||||||
if ((cp = strchr(cbuf, '\r'))) {
|
if ((cp = strchr(cbuf, '\r'))) {
|
||||||
*cp++ = '\n';
|
*cp++ = '\n';
|
||||||
*cp = '\0';
|
*cp = '\0';
|
||||||
|
@@ -31,124 +31,9 @@
|
|||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
|
||||||
#include <config.h>
|
|
||||||
RCSID("$Id$");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
|
||||||
* FTP server.
|
|
||||||
*/
|
|
||||||
#ifdef HAVE_SYS_TYPES_H
|
|
||||||
#include <sys/types.h>
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_SYS_PARAM_H
|
|
||||||
#include <sys/param.h>
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_SYS_STAT_H
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_SYS_SOCKET_H
|
|
||||||
#include <sys/socket.h>
|
|
||||||
#endif
|
|
||||||
#if defined(HAVE_SYS_IOCTL_H) && SunOS != 4
|
|
||||||
#include <sys/ioctl.h>
|
|
||||||
#endif
|
|
||||||
#ifdef TIME_WITH_SYS_TIME
|
|
||||||
#include <sys/time.h>
|
|
||||||
#include <time.h>
|
|
||||||
#elif defined(HAVE_SYS_TIME_H)
|
|
||||||
#include <sys/time.h>
|
|
||||||
#else
|
|
||||||
#include <time.h>
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_SYS_RESOURCE_H
|
|
||||||
#include <sys/resource.h>
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_SYS_WAIT_H
|
|
||||||
#include <sys/wait.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef HAVE_NETINET_IN_H
|
|
||||||
#include <netinet/in.h>
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_NETINET_IN_SYSTM_H
|
|
||||||
#include <netinet/in_systm.h>
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_NETINET_IP_H
|
|
||||||
#include <netinet/ip.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef HAVE_SYS_MMAN_H
|
|
||||||
#include <sys/mman.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define FTP_NAMES
|
#define FTP_NAMES
|
||||||
#include <arpa/ftp.h>
|
#include "ftpd_locl.h"
|
||||||
#ifdef HAVE_ARPA_INET_H
|
RCSID("$Id$");
|
||||||
#include <arpa/inet.h>
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_ARPA_TELNET_H
|
|
||||||
#include <arpa/telnet.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <ctype.h>
|
|
||||||
#ifdef HAVE_DIRENT_H
|
|
||||||
#include <dirent.h>
|
|
||||||
#endif
|
|
||||||
#include <errno.h>
|
|
||||||
#ifdef HAVE_FCNTL_H
|
|
||||||
#include <fcntl.h>
|
|
||||||
#endif
|
|
||||||
#include <glob.h>
|
|
||||||
#include <limits.h>
|
|
||||||
#ifdef HAVE_PWD_H
|
|
||||||
#include <pwd.h>
|
|
||||||
#endif
|
|
||||||
#include <setjmp.h>
|
|
||||||
#include <signal.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdarg.h>
|
|
||||||
#include <string.h>
|
|
||||||
#ifdef HAVE_SYSLOG_H
|
|
||||||
#include <syslog.h>
|
|
||||||
#endif
|
|
||||||
#include <time.h>
|
|
||||||
#ifdef HAVE_UNISTD_H
|
|
||||||
#include <unistd.h>
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_GRP_H
|
|
||||||
#include <grp.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <err.h>
|
|
||||||
|
|
||||||
#include "pathnames.h"
|
|
||||||
#include "extern.h"
|
|
||||||
#include "common.h"
|
|
||||||
|
|
||||||
#include "auth.h"
|
|
||||||
|
|
||||||
#include <krb.h>
|
|
||||||
|
|
||||||
#include <kafs.h>
|
|
||||||
#include "roken.h"
|
|
||||||
|
|
||||||
#ifdef OTP
|
|
||||||
#include <otp.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef SOCKS
|
|
||||||
#include <socks.h>
|
|
||||||
extern int LIBPREFIX(fclose) __P((FILE *));
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void yyparse();
|
|
||||||
|
|
||||||
#ifndef LOG_FTP
|
|
||||||
#define LOG_FTP LOG_DAEMON
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static char version[] = "Version 6.00";
|
static char version[] = "Version 6.00";
|
||||||
|
|
||||||
@@ -317,18 +202,20 @@ main(int argc, char **argv)
|
|||||||
int not_inetd = 0;
|
int not_inetd = 0;
|
||||||
int port;
|
int port;
|
||||||
struct servent *sp;
|
struct servent *sp;
|
||||||
char tkfile[1024];
|
|
||||||
|
|
||||||
set_progname (argv[0]);
|
set_progname (argv[0]);
|
||||||
|
|
||||||
|
#ifdef KRB4
|
||||||
/* detach from any tickets and tokens */
|
/* detach from any tickets and tokens */
|
||||||
|
{
|
||||||
snprintf(tkfile, sizeof(tkfile),
|
char tkfile[1024];
|
||||||
"/tmp/ftp_%u", (unsigned)getpid());
|
snprintf(tkfile, sizeof(tkfile),
|
||||||
krb_set_tkt_string(tkfile);
|
"/tmp/ftp_%u", (unsigned)getpid());
|
||||||
if(k_hasafs())
|
krb_set_tkt_string(tkfile);
|
||||||
k_setpag();
|
if(k_hasafs())
|
||||||
|
k_setpag();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
sp = getservbyname("ftp", "tcp");
|
sp = getservbyname("ftp", "tcp");
|
||||||
if(sp)
|
if(sp)
|
||||||
port = sp->s_port;
|
port = sp->s_port;
|
||||||
@@ -443,8 +330,6 @@ main(int argc, char **argv)
|
|||||||
syslog(LOG_ERR, "signal: %m");
|
syslog(LOG_ERR, "signal: %m");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
auth_init();
|
|
||||||
|
|
||||||
/* Try to handle urgent data inline */
|
/* Try to handle urgent data inline */
|
||||||
#if defined(SO_OOBINLINE) && defined(HAVE_SETSOCKOPT)
|
#if defined(SO_OOBINLINE) && defined(HAVE_SETSOCKOPT)
|
||||||
if (setsockopt(0, SOL_SOCKET, SO_OOBINLINE, (void *)&on,
|
if (setsockopt(0, SOL_SOCKET, SO_OOBINLINE, (void *)&on,
|
||||||
@@ -490,8 +375,15 @@ main(int argc, char **argv)
|
|||||||
/* reply(220,) must follow */
|
/* reply(220,) must follow */
|
||||||
}
|
}
|
||||||
gethostname(hostname, sizeof(hostname));
|
gethostname(hostname, sizeof(hostname));
|
||||||
|
#ifdef KRB5
|
||||||
|
reply(220, "%s FTP server (%s+%s) ready.", hostname,
|
||||||
|
version, heimdal_version);
|
||||||
|
#elif defined(KRB4)
|
||||||
reply(220, "%s FTP server (%s+%s) ready.", hostname,
|
reply(220, "%s FTP server (%s+%s) ready.", hostname,
|
||||||
version, krb4_version);
|
version, krb4_version);
|
||||||
|
#else
|
||||||
|
reply(220, "%s FTP server (%s) ready.", hostname, version);
|
||||||
|
#endif
|
||||||
setjmp(errcatch);
|
setjmp(errcatch);
|
||||||
for (;;)
|
for (;;)
|
||||||
yyparse();
|
yyparse();
|
||||||
@@ -575,7 +467,7 @@ user(char *name)
|
|||||||
{
|
{
|
||||||
char *cp, *shell;
|
char *cp, *shell;
|
||||||
|
|
||||||
if(auth_level == 0 && !auth_complete){
|
if(auth_level == 0 && !sec_complete){
|
||||||
reply(530, "No login allowed without authorization.");
|
reply(530, "No login allowed without authorization.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -610,7 +502,7 @@ user(char *name)
|
|||||||
remotehost, inet_ntoa(his_addr.sin_addr));
|
remotehost, inet_ntoa(his_addr.sin_addr));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if((auth_level & AUTH_PLAIN) == 0 && !auth_complete){
|
if((auth_level & AUTH_PLAIN) == 0 && !sec_complete){
|
||||||
reply(530, "Only authorized and anonymous login allowed.");
|
reply(530, "Only authorized and anonymous login allowed.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -636,9 +528,12 @@ user(char *name)
|
|||||||
}
|
}
|
||||||
if (logging)
|
if (logging)
|
||||||
strncpy(curname, name, sizeof(curname)-1);
|
strncpy(curname, name, sizeof(curname)-1);
|
||||||
if(auth_ok())
|
if(sec_complete) {
|
||||||
ct->userok(name);
|
if(sec_userok(name) == 0)
|
||||||
else {
|
do_login(232, name);
|
||||||
|
else
|
||||||
|
reply(530, "User %s access denied.", name);
|
||||||
|
} else {
|
||||||
char ss[256];
|
char ss[256];
|
||||||
|
|
||||||
#ifdef OTP
|
#ifdef OTP
|
||||||
@@ -655,7 +550,7 @@ user(char *name)
|
|||||||
char *s;
|
char *s;
|
||||||
|
|
||||||
#ifdef OTP
|
#ifdef OTP
|
||||||
if (s = otp_error (&otp_ctx))
|
if ((s = otp_error (&otp_ctx)) != NULL)
|
||||||
lreply(530, "OTP: %s", s);
|
lreply(530, "OTP: %s", s);
|
||||||
#endif
|
#endif
|
||||||
reply(530,
|
reply(530,
|
||||||
@@ -888,6 +783,7 @@ pass(char *passwd)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
else if((auth_level & AUTH_OTP) == 0) {
|
else if((auth_level & AUTH_OTP) == 0) {
|
||||||
|
#ifdef KRB4
|
||||||
char realm[REALM_SZ];
|
char realm[REALM_SZ];
|
||||||
if((rval = krb_get_lrealm(realm, 1)) == KSUCCESS)
|
if((rval = krb_get_lrealm(realm, 1)) == KSUCCESS)
|
||||||
rval = krb_verify_user(pw->pw_name, "", realm,
|
rval = krb_verify_user(pw->pw_name, "", realm,
|
||||||
@@ -897,12 +793,13 @@ pass(char *passwd)
|
|||||||
if(k_hasafs())
|
if(k_hasafs())
|
||||||
krb_afslog(0, 0);
|
krb_afslog(0, 0);
|
||||||
} else
|
} else
|
||||||
|
#endif
|
||||||
rval = unix_verify_user(pw->pw_name, passwd);
|
rval = unix_verify_user(pw->pw_name, passwd);
|
||||||
} else {
|
} else {
|
||||||
char *s;
|
char *s;
|
||||||
|
|
||||||
#ifdef OTP
|
#ifdef OTP
|
||||||
if (s = otp_error(&otp_ctx))
|
if ((s = otp_error(&otp_ctx)) != NULL)
|
||||||
lreply(530, "OTP: %s", s);
|
lreply(530, "OTP: %s", s);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@@ -1268,8 +1165,6 @@ send_data(FILE *instr, FILE *outstr)
|
|||||||
int c, cnt, filefd, netfd;
|
int c, cnt, filefd, netfd;
|
||||||
static char *buf;
|
static char *buf;
|
||||||
static size_t bufsize;
|
static size_t bufsize;
|
||||||
int i = 0;
|
|
||||||
char s[1024];
|
|
||||||
|
|
||||||
transflag++;
|
transflag++;
|
||||||
if (setjmp(urgcatch)) {
|
if (setjmp(urgcatch)) {
|
||||||
@@ -1279,27 +1174,20 @@ send_data(FILE *instr, FILE *outstr)
|
|||||||
switch (type) {
|
switch (type) {
|
||||||
|
|
||||||
case TYPE_A:
|
case TYPE_A:
|
||||||
while ((c = getc(instr)) != EOF) {
|
while ((c = getc(instr)) != EOF) {
|
||||||
byte_count++;
|
byte_count++;
|
||||||
if(i > 1022){
|
if(c == '\n')
|
||||||
auth_write(fileno(outstr), s, i);
|
sec_putc('\r', outstr);
|
||||||
i = 0;
|
sec_putc(c, outstr);
|
||||||
}
|
}
|
||||||
if(c == '\n')
|
sec_fflush(outstr);
|
||||||
s[i++] = '\r';
|
transflag = 0;
|
||||||
s[i++] = c;
|
if (ferror(instr))
|
||||||
}
|
goto file_err;
|
||||||
if(i)
|
if (ferror(outstr))
|
||||||
auth_write(fileno(outstr), s, i);
|
goto data_err;
|
||||||
auth_write(fileno(outstr), s, 0);
|
reply(226, "Transfer complete.");
|
||||||
fflush(outstr);
|
return;
|
||||||
transflag = 0;
|
|
||||||
if (ferror(instr))
|
|
||||||
goto file_err;
|
|
||||||
if (ferror(outstr))
|
|
||||||
goto data_err;
|
|
||||||
reply(226, "Transfer complete.");
|
|
||||||
return;
|
|
||||||
|
|
||||||
case TYPE_I:
|
case TYPE_I:
|
||||||
case TYPE_L:
|
case TYPE_L:
|
||||||
@@ -1315,11 +1203,11 @@ send_data(FILE *instr, FILE *outstr)
|
|||||||
chunk = mmap(0, st.st_size, PROT_READ, MAP_SHARED, in, 0);
|
chunk = mmap(0, st.st_size, PROT_READ, MAP_SHARED, in, 0);
|
||||||
if(chunk != (void *)MAP_FAILED) {
|
if(chunk != (void *)MAP_FAILED) {
|
||||||
cnt = st.st_size - restart_point;
|
cnt = st.st_size - restart_point;
|
||||||
auth_write(fileno(outstr),
|
sec_write(fileno(outstr),
|
||||||
chunk + restart_point,
|
chunk + restart_point,
|
||||||
cnt);
|
cnt);
|
||||||
munmap(chunk, st.st_size);
|
munmap(chunk, st.st_size);
|
||||||
auth_write(fileno(outstr), NULL, 0);
|
sec_fflush(outstr);
|
||||||
byte_count = cnt;
|
byte_count = cnt;
|
||||||
transflag = 0;
|
transflag = 0;
|
||||||
}
|
}
|
||||||
@@ -1340,9 +1228,9 @@ send_data(FILE *instr, FILE *outstr)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
while ((cnt = read(filefd, buf, bufsize)) > 0 &&
|
while ((cnt = read(filefd, buf, bufsize)) > 0 &&
|
||||||
auth_write(netfd, buf, cnt) == cnt)
|
sec_write(netfd, buf, cnt) == cnt)
|
||||||
byte_count += cnt;
|
byte_count += cnt;
|
||||||
auth_write(netfd, buf, 0); /* to end an encrypted stream */
|
sec_fflush(outstr); /* to end an encrypted stream */
|
||||||
transflag = 0;
|
transflag = 0;
|
||||||
if (cnt != 0) {
|
if (cnt != 0) {
|
||||||
if (cnt < 0)
|
if (cnt < 0)
|
||||||
@@ -1400,7 +1288,7 @@ receive_data(FILE *instr, FILE *outstr)
|
|||||||
|
|
||||||
case TYPE_I:
|
case TYPE_I:
|
||||||
case TYPE_L:
|
case TYPE_L:
|
||||||
while ((cnt = auth_read(fileno(instr), buf, bufsize)) > 0) {
|
while ((cnt = sec_read(fileno(instr), buf, bufsize)) > 0) {
|
||||||
if (write(fileno(outstr), buf, cnt) != cnt)
|
if (write(fileno(outstr), buf, cnt) != cnt)
|
||||||
goto file_err;
|
goto file_err;
|
||||||
byte_count += cnt;
|
byte_count += cnt;
|
||||||
@@ -1419,7 +1307,7 @@ receive_data(FILE *instr, FILE *outstr)
|
|||||||
{
|
{
|
||||||
char *p, *q;
|
char *p, *q;
|
||||||
int cr_flag = 0;
|
int cr_flag = 0;
|
||||||
while ((cnt = auth_read(fileno(instr),
|
while ((cnt = sec_read(fileno(instr),
|
||||||
buf + cr_flag,
|
buf + cr_flag,
|
||||||
bufsize - cr_flag)) > 0){
|
bufsize - cr_flag)) > 0){
|
||||||
byte_count += cnt;
|
byte_count += cnt;
|
||||||
@@ -1582,21 +1470,21 @@ __attribute__ ((format (printf, 3, 0)))
|
|||||||
static void
|
static void
|
||||||
int_reply(int n, char *c, const char *fmt, va_list ap)
|
int_reply(int n, char *c, const char *fmt, va_list ap)
|
||||||
{
|
{
|
||||||
char buf[10240];
|
char buf[10240];
|
||||||
char *p;
|
char *p;
|
||||||
p=buf;
|
p=buf;
|
||||||
if(n){
|
if(n){
|
||||||
snprintf(p, sizeof(buf), "%d%s", n, c);
|
snprintf(p, sizeof(buf), "%d%s", n, c);
|
||||||
p+=strlen(p);
|
p+=strlen(p);
|
||||||
}
|
}
|
||||||
vsnprintf(p, sizeof(buf) - strlen(p), fmt, ap);
|
vsnprintf(p, sizeof(buf) - strlen(p), fmt, ap);
|
||||||
p+=strlen(p);
|
p+=strlen(p);
|
||||||
snprintf(p, sizeof(buf) - strlen(p), "\r\n");
|
snprintf(p, sizeof(buf) - strlen(p), "\r\n");
|
||||||
p+=strlen(p);
|
p+=strlen(p);
|
||||||
auth_printf("%s", buf);
|
sec_fprintf(stdout, "%s", buf);
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
if (debug)
|
if (debug)
|
||||||
syslog(LOG_DEBUG, "<--- %s- ", buf);
|
syslog(LOG_DEBUG, "<--- %s- ", buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -1999,7 +1887,7 @@ send_file_list(char *whichf)
|
|||||||
}
|
}
|
||||||
snprintf(buf, sizeof(buf), "%s%s\n", dirname,
|
snprintf(buf, sizeof(buf), "%s%s\n", dirname,
|
||||||
type == TYPE_A ? "\r" : "");
|
type == TYPE_A ? "\r" : "");
|
||||||
auth_write(fileno(dout), buf, strlen(buf));
|
sec_write(fileno(dout), buf, strlen(buf));
|
||||||
byte_count += strlen(dirname) + 1;
|
byte_count += strlen(dirname) + 1;
|
||||||
continue;
|
continue;
|
||||||
} else if (!S_ISDIR(st.st_mode))
|
} else if (!S_ISDIR(st.st_mode))
|
||||||
@@ -2036,7 +1924,7 @@ send_file_list(char *whichf)
|
|||||||
else
|
else
|
||||||
snprintf(buf, sizeof(buf), "%s%s\n", nbuf,
|
snprintf(buf, sizeof(buf), "%s%s\n", nbuf,
|
||||||
type == TYPE_A ? "\r" : "");
|
type == TYPE_A ? "\r" : "");
|
||||||
auth_write(fileno(dout), buf, strlen(buf));
|
sec_write(fileno(dout), buf, strlen(buf));
|
||||||
byte_count += strlen(nbuf) + 1;
|
byte_count += strlen(nbuf) + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2051,7 +1939,7 @@ send_file_list(char *whichf)
|
|||||||
|
|
||||||
transflag = 0;
|
transflag = 0;
|
||||||
if (dout != NULL){
|
if (dout != NULL){
|
||||||
auth_write(fileno(dout), buf, 0); /* XXX flush */
|
sec_write(fileno(dout), buf, 0); /* XXX flush */
|
||||||
|
|
||||||
fclose(dout);
|
fclose(dout);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user