Deleted Added
full compact
opieftpd.c (62877) opieftpd.c (92914)
1/* opieftpd.c: Main program for an FTP daemon.
2
3%%% portions-copyright-cmetz-96
1/* opieftpd.c: Main program for an FTP daemon.
2
3%%% portions-copyright-cmetz-96
4Portions of this software are Copyright 1996-1998 by Craig Metz, All Rights
4Portions of this software are Copyright 1996-1999 by Craig Metz, All Rights
5Reserved. The Inner Net License Version 2 applies to these portions of
6the software.
7You should have received a copy of the license with this software. If
8you didn't get a copy, you may request one from <license@inner.net>.
9
10Portions of this software are Copyright 1995 by Randall Atkinson and Dan
11McDonald, All Rights Reserved. All Rights under this copyright are assigned
12to the U.S. Naval Research Laboratory (NRL). The NRL Copyright Notice and
13License Agreement applies to this software.
14
15 History:
16
5Reserved. The Inner Net License Version 2 applies to these portions of
6the software.
7You should have received a copy of the license with this software. If
8you didn't get a copy, you may request one from <license@inner.net>.
9
10Portions of this software are Copyright 1995 by Randall Atkinson and Dan
11McDonald, All Rights Reserved. All Rights under this copyright are assigned
12to the U.S. Naval Research Laboratory (NRL). The NRL Copyright Notice and
13License Agreement applies to this software.
14
15 History:
16
17 Modified by cmetz for OPIE 2.4. Add id parameter to opielogwtmp. Use
18 opiestrncpy(). Fix incorrect use of setproctitle().
17 Modified by cmetz for OPIE 2.32. Remove include of dirent.h here; it's
18 done already (and conditionally) in opie_cfg.h.
19 Modified by cmetz for OPIE 2.31. Merged in some 4.4BSD-Lite changes.
20 Merged in a security fix to BSD-derived ftpds.
21 Modified by cmetz for OPIE 2.3. Fixed the filename at the top.
22 Moved LS_COMMAND here.
23 Modified by cmetz for OPIE 2.2. Use FUNCTION definition et al.
24 Removed useless strings (I don't think that removing the

--- 16 unchanged lines hidden (view full) ---

41 user accounts properly if login fails because of /etc/shells.
42 Make sure to close syslog by function to avoid problems with
43 drain bamaged syslog implementations.
44 Modified at NRL for OPIE 2.0.
45 Originally from BSD Net/2.
46
47 There is some really, really ugly code in here.
48
19 Modified by cmetz for OPIE 2.32. Remove include of dirent.h here; it's
20 done already (and conditionally) in opie_cfg.h.
21 Modified by cmetz for OPIE 2.31. Merged in some 4.4BSD-Lite changes.
22 Merged in a security fix to BSD-derived ftpds.
23 Modified by cmetz for OPIE 2.3. Fixed the filename at the top.
24 Moved LS_COMMAND here.
25 Modified by cmetz for OPIE 2.2. Use FUNCTION definition et al.
26 Removed useless strings (I don't think that removing the

--- 16 unchanged lines hidden (view full) ---

43 user accounts properly if login fails because of /etc/shells.
44 Make sure to close syslog by function to avoid problems with
45 drain bamaged syslog implementations.
46 Modified at NRL for OPIE 2.0.
47 Originally from BSD Net/2.
48
49 There is some really, really ugly code in here.
50
49$FreeBSD: head/contrib/opie/opieftpd.c 62877 2000-07-10 07:30:28Z kris $
51$FreeBSD: head/contrib/opie/opieftpd.c 92914 2002-03-21 23:42:52Z markm $
50*/
51/*
52 * Copyright (c) 1985, 1988, 1990 Regents of the University of California.
53 * All rights reserved.
54 *
55 * Redistribution and use in source and binary forms, with or without
56 * modification, are permitted provided that the following conditions
57 * are met:

--- 180 unchanged lines hidden (view full) ---

238static FILE *dataconn __P((char *, off_t, char *));
239static int checkuser __P((char *));
240static VOIDRET end_login __P((void));
241static VOIDRET send_data __P((FILE *, FILE *, off_t));
242static int receive_data __P((FILE *, FILE *));
243static char *gunique __P((char *));
244static char *sgetsave __P((char *));
245
52*/
53/*
54 * Copyright (c) 1985, 1988, 1990 Regents of the University of California.
55 * All rights reserved.
56 *
57 * Redistribution and use in source and binary forms, with or without
58 * modification, are permitted provided that the following conditions
59 * are met:

--- 180 unchanged lines hidden (view full) ---

240static FILE *dataconn __P((char *, off_t, char *));
241static int checkuser __P((char *));
242static VOIDRET end_login __P((void));
243static VOIDRET send_data __P((FILE *, FILE *, off_t));
244static int receive_data __P((FILE *, FILE *));
245static char *gunique __P((char *));
246static char *sgetsave __P((char *));
247
246int opielogwtmp __P((char *, char *, char *));
248int opielogwtmp __P((char *, char *, char *, char *));
247
248int fclose __P((FILE *));
249
250#ifdef HAVE_ANSISTDARG
251VOIDRET reply FUNCTION((stdarg is ANSI only), int n AND char *fmt AND ...)
252{
253 va_list ap;
254 char buffer[1024];

--- 250 unchanged lines hidden (view full) ---

505 * used when USER command is given or login fails.
506 */
507static VOIDRET end_login FUNCTION_NOARGS
508{
509 disable_signalling();
510 if (seteuid((uid_t) 0))
511 syslog(LOG_ERR, "Can't set euid");
512 if (logged_in)
249
250int fclose __P((FILE *));
251
252#ifdef HAVE_ANSISTDARG
253VOIDRET reply FUNCTION((stdarg is ANSI only), int n AND char *fmt AND ...)
254{
255 va_list ap;
256 char buffer[1024];

--- 250 unchanged lines hidden (view full) ---

507 * used when USER command is given or login fails.
508 */
509static VOIDRET end_login FUNCTION_NOARGS
510{
511 disable_signalling();
512 if (seteuid((uid_t) 0))
513 syslog(LOG_ERR, "Can't set euid");
514 if (logged_in)
513 opielogwtmp(ttyline, "", "");
515 opielogwtmp(ttyline, "", "", "ftp");
514 pw = NULL;
515 logged_in = 0;
516#if DOANONYMOUS
517 guest = 0;
518#endif /* DOANONYMOUS */
519 enable_signalling();
520}
521

--- 37 unchanged lines hidden (view full) ---

559 reply(550, "Can't set gid.");
560 syslog(LOG_DEBUG, "gid = %d, errno = %s(%d)", pw->pw_gid, strerror(errno), errno);
561 return;
562 }
563 initgroups(pw->pw_name, pw->pw_gid);
564
565 /* open wtmp before chroot */
566 sprintf(ttyline, "ftp%d", getpid());
516 pw = NULL;
517 logged_in = 0;
518#if DOANONYMOUS
519 guest = 0;
520#endif /* DOANONYMOUS */
521 enable_signalling();
522}
523

--- 37 unchanged lines hidden (view full) ---

561 reply(550, "Can't set gid.");
562 syslog(LOG_DEBUG, "gid = %d, errno = %s(%d)", pw->pw_gid, strerror(errno), errno);
563 return;
564 }
565 initgroups(pw->pw_name, pw->pw_gid);
566
567 /* open wtmp before chroot */
568 sprintf(ttyline, "ftp%d", getpid());
567 opielogwtmp(ttyline, pw->pw_name, remotehost);
569 opielogwtmp(ttyline, pw->pw_name, remotehost, "ftp");
568 logged_in = 1;
569
570#if DOANONYMOUS
571 if (guest) {
572 /* We MUST do a chdir() after the chroot. Otherwise the old current
573 directory will be accessible as "." outside the new root! */
574 if (chroot(pw->pw_dir) < 0 || chdir("/") < 0) {
575 reply(550, "Can't set guest privileges.");

--- 50 unchanged lines hidden (view full) ---

626 (void) fflush(stdout);
627 (void) fclose(fd);
628 }
629 }
630#if DOANONYMOUS
631 if (guest) {
632 reply(230, "Guest login ok, access restrictions apply.");
633#if DOTITLE
570 logged_in = 1;
571
572#if DOANONYMOUS
573 if (guest) {
574 /* We MUST do a chdir() after the chroot. Otherwise the old current
575 directory will be accessible as "." outside the new root! */
576 if (chroot(pw->pw_dir) < 0 || chdir("/") < 0) {
577 reply(550, "Can't set guest privileges.");

--- 50 unchanged lines hidden (view full) ---

628 (void) fflush(stdout);
629 (void) fclose(fd);
630 }
631 }
632#if DOANONYMOUS
633 if (guest) {
634 reply(230, "Guest login ok, access restrictions apply.");
635#if DOTITLE
634 snprintf(proctitle, sizeof(proctitle), "%s: anonymous/%s", remotehost,
635 passwd);
636 setproctitle("%s", proctitle);
637#endif /* DOTITLE */
636 setproctitle("%s: anonymous/%.*s", remotehost,
637 sizeof(proctitle) - sizeof(remotehost) - sizeof(": anonymous/"),
638 passwd);
639#endif /* DOTITLE */
638 syslog(LOG_NOTICE, "ANONYMOUS FTP login from %s with ID %s",
639 remotehost, passwd);
640 } else
641#endif /* DOANONYMOUS */
642 {
643 reply(230, "User %s logged in.", pw->pw_name);
644
645#if DOTITLE
640 syslog(LOG_NOTICE, "ANONYMOUS FTP login from %s with ID %s",
641 remotehost, passwd);
642 } else
643#endif /* DOANONYMOUS */
644 {
645 reply(230, "User %s logged in.", pw->pw_name);
646
647#if DOTITLE
646 snprintf(proctitle, sizeof(proctitle), "%s: %s", remotehost, pw->pw_name);
647 setproctitle("%s", proctitle);
648#endif /* DOTITLE */
648 setproctitle("%s: %s", remotehost, pw->pw_name);
649#endif /* DOTITLE */
649 syslog(LOG_INFO, "FTP login from %s with user name %s", remotehost, pw->pw_name);
650 }
651 home = pw->pw_dir; /* home dir for globbing */
652 umask(defumask);
653 return;
654
655bad:
656 /* Forget all about it... */

--- 594 unchanged lines hidden (view full) ---

1251
1252static VOIDRET dolog FUNCTION((sin), struct sockaddr_in *sin)
1253{
1254 struct hostent *hp = gethostbyaddr((char *) &sin->sin_addr,
1255 sizeof(struct in_addr), AF_INET);
1256 time_t t, time();
1257
1258 if (hp)
650 syslog(LOG_INFO, "FTP login from %s with user name %s", remotehost, pw->pw_name);
651 }
652 home = pw->pw_dir; /* home dir for globbing */
653 umask(defumask);
654 return;
655
656bad:
657 /* Forget all about it... */

--- 594 unchanged lines hidden (view full) ---

1252
1253static VOIDRET dolog FUNCTION((sin), struct sockaddr_in *sin)
1254{
1255 struct hostent *hp = gethostbyaddr((char *) &sin->sin_addr,
1256 sizeof(struct in_addr), AF_INET);
1257 time_t t, time();
1258
1259 if (hp)
1259 strncpy(remotehost, hp->h_name, sizeof(remotehost));
1260 opiestrncpy(remotehost, hp->h_name, sizeof(remotehost));
1260 else
1261 else
1261 strncpy(remotehost, inet_ntoa(sin->sin_addr), sizeof(remotehost));
1262 remotehost[sizeof(remotehost) - 1] = '\0';
1262 opiestrncpy(remotehost, inet_ntoa(sin->sin_addr), sizeof(remotehost));
1263#if DOTITLE
1263#if DOTITLE
1264 snprintf(proctitle, sizeof(proctitle), "%s: connected", remotehost);
1265 setproctitle("%s", proctitle);
1264 setproctitle("%s: connected", remotehost);
1266#endif /* DOTITLE */
1267
1268 t = time((time_t *) 0);
1269 syslog(LOG_INFO, "connection from %s at %s",
1270 remotehost, ctime(&t));
1271}
1272
1273/*
1274 * Record logout in wtmp file
1275 * and exit with supplied status.
1276 */
1277VOIDRET dologout FUNCTION((status), int status)
1278{
1279 disable_signalling();
1280 if (logged_in) {
1281 if (seteuid((uid_t) 0))
1282 syslog(LOG_ERR, "Can't set euid");
1265#endif /* DOTITLE */
1266
1267 t = time((time_t *) 0);
1268 syslog(LOG_INFO, "connection from %s at %s",
1269 remotehost, ctime(&t));
1270}
1271
1272/*
1273 * Record logout in wtmp file
1274 * and exit with supplied status.
1275 */
1276VOIDRET dologout FUNCTION((status), int status)
1277{
1278 disable_signalling();
1279 if (logged_in) {
1280 if (seteuid((uid_t) 0))
1281 syslog(LOG_ERR, "Can't set euid");
1283 opielogwtmp(ttyline, "", "");
1282 opielogwtmp(ttyline, "", "", "ftp");
1284 }
1285 /* beware of flushing buffers after a SIGPIPE */
1286 _exit(status);
1287}
1288
1289static VOIDRET myoob FUNCTION((input), int input)
1290{
1291 char *cp;

--- 425 unchanged lines hidden ---
1283 }
1284 /* beware of flushing buffers after a SIGPIPE */
1285 _exit(status);
1286}
1287
1288static VOIDRET myoob FUNCTION((input), int input)
1289{
1290 char *cp;

--- 425 unchanged lines hidden ---