Deleted Added
sdiff udiff text old ( 62877 ) new ( 92914 )
full compact
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
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.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
49$FreeBSD: head/contrib/opie/opieftpd.c 62877 2000-07-10 07:30:28Z kris $
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
246int opielogwtmp __P((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)
513 opielogwtmp(ttyline, "", "");
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());
567 opielogwtmp(ttyline, pw->pw_name, remotehost);
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
634 snprintf(proctitle, sizeof(proctitle), "%s: anonymous/%s", remotehost,
635 passwd);
636 setproctitle("%s", proctitle);
637#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
646 snprintf(proctitle, sizeof(proctitle), "%s: %s", remotehost, pw->pw_name);
647 setproctitle("%s", proctitle);
648#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)
1259 strncpy(remotehost, hp->h_name, sizeof(remotehost));
1260 else
1261 strncpy(remotehost, inet_ntoa(sin->sin_addr), sizeof(remotehost));
1262 remotehost[sizeof(remotehost) - 1] = '\0';
1263#if DOTITLE
1264 snprintf(proctitle, sizeof(proctitle), "%s: connected", remotehost);
1265 setproctitle("%s", proctitle);
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");
1283 opielogwtmp(ttyline, "", "");
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 ---