1/* opieftpd.c: Main program for an FTP daemon. 2 3%%% portions-copyright-cmetz-96 |
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 |
17 Modified by cmetz for OPIE 2.4. Add id parameter to opielogwtmp. Use 18 opiestrncpy(). Fix incorrect use of setproctitle(). |
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 |
51$FreeBSD: head/contrib/opie/opieftpd.c 92914 2002-03-21 23:42:52Z markm $ |
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 |
248int opielogwtmp __P((char *, char *, char *, char *)); |
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) |
515 opielogwtmp(ttyline, "", "", "ftp"); |
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()); |
569 opielogwtmp(ttyline, pw->pw_name, remotehost, "ftp"); |
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 |
636 setproctitle("%s: anonymous/%.*s", remotehost, 637 sizeof(proctitle) - sizeof(remotehost) - sizeof(": anonymous/"), 638 passwd); 639#endif /* 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 |
648 setproctitle("%s: %s", remotehost, pw->pw_name); 649#endif /* DOTITLE */ |
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) |
1260 opiestrncpy(remotehost, hp->h_name, sizeof(remotehost)); |
1261 else |
1262 opiestrncpy(remotehost, inet_ntoa(sin->sin_addr), sizeof(remotehost)); |
1263#if DOTITLE |
1264 setproctitle("%s: connected", remotehost); |
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"); |
1282 opielogwtmp(ttyline, "", "", "ftp"); |
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 --- |