Lines Matching +full:dout +full:- +full:default +full:- +full:2

1 /*-
2 * SPDX-License-Identifier: BSD-3-Clause
12 * 2. Redistributions in binary form must reproduce the above copyright
98 int hostinfo = 1; /* print host-specific info in messages */
104 int maxtimeout = 7200;/* don't allow idle time to be set beyond 2 hours */
110 int assumeutf8 = 0; /* Assume that server file names are in UTF-8 */
116 int statfd = -1;
122 int pdata = -1; /* for passive mode */
137 int defumask = CMASK; /* default umask value */
166 char *pid_file = NULL; /* means default location to pidfile(3) */
190 #define LOGCMD(cmd, file) logcmd((cmd), (file), NULL, -1)
191 #define LOGCMD2(cmd, file1, file2) logcmd((cmd), (file1), (file2), -1)
236 static void appendf(char **, char *, ...) __printflike(2, 3);
273 "468a:ABdDEhlmMnoOp:P:rRSt:T:u:UvW")) != -1) { in main()
381 syslog(LOG_WARNING, "bad value for -u"); in main()
398 default: in main()
399 syslog(LOG_WARNING, "unknown flag -%c ignored", optopt); in main()
405 syslog(LOG_ERR, "-n and -A are mutually exclusive"); in main()
414 int *ctl_sock, fd, maxfd = -1, nfds, i; in main()
436 if (pfh != NULL && pidfile_write(pfh) == -1) in main()
478 pid = -1; in main()
485 if (fd == -1) { in main()
501 case -1: in main()
504 default: in main()
550 dataport = ntohs(ctrl_addr.su_port) - 1; /* as per RFC 959 */ in main()
570 data_source.su_port = htons(ntohs(ctrl_addr.su_port) - 1); in main()
581 if (fcntl(s, F_SETOWN, getpid()) == -1) in main()
586 * Set up default state in main()
588 data = -1; in main()
608 fd = fopen(thishost->welcome, "r"); in main()
625 if (gethostname(hostname, MAXHOSTNAMELEN - 1) < 0) in main()
627 hostname[MAXHOSTNAMELEN - 1] = '\0'; in main()
674 * Fill in the default host information in inithosts()
678 if (gethostname(hostname, MAXHOSTNAMELEN - 1) < 0) in inithosts()
680 hostname[MAXHOSTNAMELEN - 1] = '\0'; in inithosts()
683 hrp->hostname = hostname; in inithosts()
684 hrp->hostinfo = NULL; in inithosts()
690 if (getaddrinfo(hrp->hostname, NULL, &hints, &res) == 0) in inithosts()
691 hrp->hostinfo = res; in inithosts()
692 hrp->statfile = _PATH_FTPDSTATFILE; in inithosts()
693 hrp->welcome = _PATH_FTPWELCOME; in inithosts()
694 hrp->loginmsg = _PATH_FTPLOGINMESG; in inithosts()
695 hrp->anonuser = "ftp"; in inithosts()
696 hrp->next = NULL; in inithosts()
709 if (line[len - 1] == '\n') { in inithosts()
710 line[len - 1] = '\0'; in inithosts()
740 if (*cp != '-' && (cp = strdup(cp))) in inithosts()
745 case 2: /* statistics file */ in inithosts()
754 default: /* programming error */ in inithosts()
764 for (ai = res; ai != NULL && ai->ai_addr != NULL; in inithosts()
765 ai = ai->ai_next) { in inithosts()
768 for (hrp = firsthost; hrp != NULL; hrp = hrp->next) { in inithosts()
771 for (hi = hrp->hostinfo; hi != NULL; in inithosts()
772 hi = hi->ai_next) in inithosts()
773 if (hi->ai_addrlen == ai->ai_addrlen && in inithosts()
774 memcmp(hi->ai_addr, in inithosts()
775 ai->ai_addr, in inithosts()
776 ai->ai_addr->sa_len) == 0) { in inithosts()
786 hrp->hostname = NULL; in inithosts()
789 if (hrp->hostinfo && hrp->hostinfo != res) in inithosts()
790 freeaddrinfo(hrp->hostinfo); in inithosts()
793 hrp->hostinfo = res; in inithosts()
801 switch(hrp->hostinfo->ai_family) { in inithosts()
803 addr = &((struct sockaddr_in *)hrp->hostinfo->ai_addr)->sin_addr; in inithosts()
807 addr = &((struct sockaddr_in6 *)hrp->hostinfo->ai_addr)->sin6_addr; in inithosts()
810 default: in inithosts()
812 freeaddrinfo(hrp->hostinfo); in inithosts()
816 hrp->hostinfo = NULL; /*mark as blank*/ in inithosts()
821 hrp->hostinfo->ai_family, in inithosts()
823 if (strcmp(vhost, hp->h_name) != 0) { in inithosts()
824 if (hp->h_aliases == NULL) in inithosts()
825 vhost = hp->h_name; in inithosts()
828 while (hp->h_aliases[i] && in inithosts()
829 strcmp(vhost, hp->h_aliases[i]) != 0) in inithosts()
831 if (hp->h_aliases[i] == NULL) in inithosts()
832 vhost = hp->h_name; in inithosts()
836 if (hrp->hostname && in inithosts()
837 strcmp(hrp->hostname, vhost) != 0) { in inithosts()
838 free(hrp->hostname); in inithosts()
839 hrp->hostname = NULL; in inithosts()
841 if (hrp->hostname == NULL && in inithosts()
842 (hrp->hostname = strdup(vhost)) == NULL) { in inithosts()
843 freeaddrinfo(hrp->hostinfo); in inithosts()
844 hrp->hostinfo = NULL; /* mark as blank */ in inithosts()
849 hrp->anonuser = anonuser; in inithosts()
850 hrp->statfile = statfile; in inithosts()
851 hrp->welcome = welcome; in inithosts()
852 hrp->loginmsg = loginmsg; in inithosts()
854 hrp->next = NULL; in inithosts()
855 lhrp->next = hrp; in inithosts()
884 if (su->su_family == AF_INET6 && in selecthost()
885 IN6_IS_ADDR_V4MAPPED(&su->su_sin6.sin6_addr)) in selecthost()
886 mapped_in6 = &su->su_sin6.sin6_addr; in selecthost()
889 hrp = thishost = firsthost; /* default */ in selecthost()
890 port = su->su_port; in selecthost()
891 su->su_port = 0; in selecthost()
893 for (hi = hrp->hostinfo; hi != NULL; hi = hi->ai_next) { in selecthost()
894 if (memcmp(su, hi->ai_addr, hi->ai_addrlen) == 0) { in selecthost()
900 if (hi->ai_addr->sa_family == AF_INET && mapped_in6 != NULL && in selecthost()
901 (memcmp(&mapped_in6->s6_addr[12], in selecthost()
902 &((struct sockaddr_in *)hi->ai_addr)->sin_addr, in selecthost()
909 hrp = hrp->next; in selecthost()
912 su->su_port = port; in selecthost()
914 hostname = thishost->hostname; in selecthost()
915 ftpuser = thishost->anonuser; in selecthost()
961 save.pw_name = sgetsave(p->pw_name); in sgetpwnam()
962 save.pw_passwd = sgetsave(p->pw_passwd); in sgetpwnam()
963 save.pw_class = sgetsave(p->pw_class); in sgetpwnam()
964 save.pw_gecos = sgetsave(p->pw_gecos); in sgetpwnam()
965 save.pw_dir = sgetsave(p->pw_dir); in sgetpwnam()
966 save.pw_shell = sgetsave(p->pw_shell); in sgetpwnam()
1004 pw = sgetpwnam(thishost->anonuser); in user()
1034 if ((shell = pw->pw_shell) == NULL || *shell == 0) in user()
1061 * attempt to slow down passwd-guessing programs. in user()
1087 if (line[len - 1] == '\n') { in checkuser()
1088 line[len - 1] = '\0'; in checkuser()
1115 * Check user's default group in checkuser()
1117 if (pwset && grp->gr_gid == pw->pw_gid) in checkuser()
1122 while (!found && grp->gr_mem[i]) in checkuser()
1124 grp->gr_mem[i++]) in checkuser()
1194 * the following code is stolen from imap-uw PAM authentication module and
1218 switch (msg[i]->msg_style) { in auth_conv()
1221 reply[i].resp = COPY_STRING(cred->uname); in auth_conv()
1226 reply[i].resp = COPY_STRING(cred->pass); in auth_conv()
1234 default: /* unknown message style */ in auth_conv()
1248 * function returns -1. This can be used as an indication that we should
1258 cred_t auth_cred = { (*ppw)->pw_name, pass }; in auth_pam()
1261 e = pam_start("ftpd", (*ppw)->pw_name, &conv, &pamh); in auth_pam()
1268 return -1; in auth_pam()
1279 return -1; in auth_pam()
1305 if (strcmp((*ppw)->pw_name, tmpl_user) != 0) in auth_pam()
1319 default: in auth_pam()
1321 rval = -1; in auth_pam()
1375 xpasswd = crypt(passwd, pw->pw_passwd); in pass()
1376 if (passwd[0] == '\0' && pw->pw_passwd[0] != '\0') in pass()
1378 rval = strcmp(pw->pw_passwd, xpasswd); in pass()
1379 if (pw->pw_expire && time(NULL) >= pw->pw_expire) in pass()
1411 if (setegid(pw->pw_gid) < 0) { in pass()
1422 remote_ip, sizeof(remote_ip) - 1, NULL, 0, in pass()
1425 remote_ip[sizeof(remote_ip) - 1] = 0; in pass()
1429 pw->pw_name); in pass()
1443 setlogin(pw->pw_name); in pass()
1444 (void) initgroups(pw->pw_name, pw->pw_gid); in pass()
1458 checkuser(_PATH_FTPCHROOT, pw->pw_name, 1, &residue, &ecode) in pass()
1460 || login_getcapbool(lc, "ftp-chroot", 0) in pass()
1465 * If this is the case, report that logins are un-available, since we in pass()
1479 ftpd_logwtmp(wtmpid, pw->pw_name, in pass()
1489 statfd = open(thishost->statfile, O_WRONLY|O_APPEND); in pass()
1506 asprintf(&chrootdir, "%s/%s", pw->pw_dir, chrootdir); in pass()
1515 * Copy it so it can be modified while pw->pw_dir stays intact. in pass()
1518 (chrootdir = strdup(pw->pw_dir)) == NULL) in pass()
1544 homedir = pw->pw_dir; in pass()
1552 if (seteuid(pw->pw_uid) < 0) { in pass()
1581 fd = fopen(thishost->loginmsg, "r"); in pass()
1622 "access restrictions apply.", pw->pw_name); in pass()
1624 reply(230, "User %s logged in.", pw->pw_name); in pass()
1628 "%s: user/%s", remotehost, pw->pw_name); in pass()
1633 remotehost, pw->pw_name); in pass()
1656 FILE *fin, *dout; in retrieve() local
1669 st.st_size = -1; in retrieve()
1681 byte_count = -1; in retrieve()
1699 st.st_size = -1; in retrieve()
1723 dout = dataconn(name, st.st_size, "w"); in retrieve()
1724 if (dout == NULL) in retrieve()
1727 send_data(fin, dout, st.st_blksize, st.st_size, in retrieve()
1731 (void) fclose(dout); in retrieve()
1732 data = -1; in retrieve()
1733 pdata = -1; in retrieve()
1782 byte_count = -1; in store()
1812 din = dataconn(name, -1, "r"); in store()
1823 data = -1; in store()
1824 pdata = -1; in store()
1847 /* anchor socket to avoid multi-homing problems */ in getdatasock()
1868 (void) seteuid(pw->pw_uid); in getdatasock()
1890 (void) seteuid(pw->pw_uid); in getdatasock()
1905 if (size != -1) in dataconn()
1927 * Therefore set the non-blocking I/O flag here. in dataconn()
1929 if ((flags = fcntl(pdata, F_GETFL, 0)) == -1 || in dataconn()
1930 fcntl(pdata, F_SETFL, flags | O_NONBLOCK) == -1) in dataconn()
1938 * Unset the inherited non-blocking I/O flag in dataconn()
1941 if ((flags = fcntl(pdata, F_GETFL, 0)) == -1 || in dataconn()
1942 fcntl(pdata, F_SETFL, flags & ~O_NONBLOCK) == -1) in dataconn()
1958 pdata = -1; in dataconn()
1977 hostbuf, sizeof(hostbuf) - 1, in dataconn()
1978 portbuf, sizeof(portbuf) - 1, in dataconn()
1981 hostbuf[sizeof(hostbuf) - 1] = 0; in dataconn()
1982 portbuf[sizeof(portbuf) - 1] = 0; in dataconn()
1994 data = -1; in dataconn()
2029 CHECKOOB(return (-1)) \
2056 CHECKOOB(return (-1)) in send_data()
2080 CHECKOOB(return (-1)) in send_data()
2119 filesize -= cnt; in send_data()
2120 CHECKOOB(return (-1)) in send_data()
2121 else if (err == -1) { in send_data()
2127 if (err == -1) /* resume after OOB */ in send_data()
2148 return (-1); in send_data()
2156 CHECKOOB(free(buf); return (-1)) in send_data()
2167 CHECKOOB(free(buf); return (-1)) in send_data()
2174 len -= cnt; in send_data()
2183 default: in send_data()
2186 return (-1); in send_data()
2192 return (-1); in send_data()
2197 return (-1); in send_data()
2224 CHECKOOB(return (-1)) in receive_data()
2233 CHECKOOB(return (-1)) in receive_data()
2238 len -= cnt; in receive_data()
2249 return (-1); in receive_data()
2255 CHECKOOB(return (-1)) in receive_data()
2290 CHECKOOB(return (-1)) in receive_data()
2308 default: in receive_data()
2311 return (-1); in receive_data()
2317 return (-1); in receive_data()
2322 return (-1); in receive_data()
2335 (void)snprintf(line, sizeof(line), _PATH_LS " -lA %s", filename); in statfilecmd()
2360 * a leading 3-digit number followed by whitespace, but in statfilecmd()
2388 hname, sizeof(hname) - 1, NULL, 0, NI_NUMERICHOST)) { in statcmd()
2389 hname[sizeof(hname) - 1] = 0; in statcmd()
2398 printf(" Logged in as %s\r\n", pw->pw_name); in statcmd()
2414 if (data != -1) in statcmd()
2416 else if (pdata != -1) { in statcmd()
2431 if (su->su_family == AF_INET) { in statcmd()
2432 a = (u_char *) &su->su_sin.sin_addr; in statcmd()
2433 p = (u_char *) &su->su_sin.sin_port; in statcmd()
2436 UC(a[0]), UC(a[1]), UC(a[2]), UC(a[3]), in statcmd()
2444 switch (su->su_family) { in statcmd()
2446 a = (u_char *) &su->su_sin.sin_addr; in statcmd()
2447 p = (u_char *) &su->su_sin.sin_port; in statcmd()
2448 alen = sizeof(su->su_sin.sin_addr); in statcmd()
2452 a = (u_char *) &su->su_sin6.sin6_addr; in statcmd()
2453 p = (u_char *) &su->su_sin6.sin6_port; in statcmd()
2454 alen = sizeof(su->su_sin6.sin6_addr); in statcmd()
2457 default: in statcmd()
2466 printf("%d,%d,%d)\r\n", 2, UC(p[0]), UC(p[1])); in statcmd()
2475 switch (su->su_family) { in statcmd()
2480 af = 2; in statcmd()
2482 default: in statcmd()
2493 hname, sizeof(hname) - 1, NULL, 0, in statcmd()
2495 hname[sizeof(hname) - 1] = 0; in statcmd()
2530 syslog(LOG_DEBUG, "<--- %d ", n); in reply()
2542 (void)printf("%d- ", n); in lreply()
2549 syslog(LOG_DEBUG, "<--- %d- ", n); in lreply()
2704 realhostname_sa(remotehost, sizeof(remotehost) - 1, who, who->sa_len); in dolog()
2705 remotehost[sizeof(remotehost) - 1] = 0; in dolog()
2706 if (getnameinfo(who, who->sa_len, in dolog()
2707 who_name, sizeof(who_name) - 1, NULL, 0, NI_NUMERICHOST)) in dolog()
2709 who_name[sizeof(who_name) - 1] = 0; in dolog()
2801 * Returns 0 if OK to resume or -1 if abort requested.
2815 if (ret == -1) { in myoob()
2818 } else if (ret == -2) { in myoob()
2827 return (-1); in myoob()
2831 if (file_size != -1) in myoob()
2894 (void) seteuid(pw->pw_uid); in passive()
2914 UC(a[1]), UC(a[2]), UC(a[3]), UC(p[0]), UC(p[1])); in passive()
2918 (void) seteuid(pw->pw_uid); in passive()
2920 pdata = -1; in passive()
2948 pf = 2; in long_passive()
2950 default: in long_passive()
3007 (void) seteuid(pw->pw_uid); in long_passive()
3024 4, 4, UC(a[0]), UC(a[1]), UC(a[2]), UC(a[3]), in long_passive()
3025 2, UC(p[0]), UC(p[1])); in long_passive()
3036 6, 16, UC(a[0]), UC(a[1]), UC(a[2]), UC(a[3]), in long_passive()
3040 2, UC(p[0]), UC(p[1])); in long_passive()
3056 (void) seteuid(pw->pw_uid); in long_passive()
3058 pdata = -1; in long_passive()
3066 * Try "local" first, then "local.1", "local.2" etc, up to "local.99".
3085 return (-1); in guniquefd()
3090 * -4 is for /nn\0 in guniquefd()
3093 if (strlen(local) > sizeof(new) - 4) { in guniquefd()
3095 return (-1); in guniquefd()
3099 /* -4 is for the .nn<null> we put on the end below */ in guniquefd()
3100 (void) snprintf(new, sizeof(new) - 4, "%s", local); in guniquefd()
3107 if (cp > new && cp[-1] != '/') in guniquefd()
3120 return (-1); in guniquefd()
3124 return (-1); in guniquefd()
3148 FILE *dout = NULL; in send_file_list() local
3179 * If user typed "ls -l", etc, and the client in send_file_list()
3182 if (dirname[0] == '-' && *dirlist == NULL && in send_file_list()
3183 dout == NULL) in send_file_list()
3191 if (dout == NULL) { in send_file_list()
3192 dout = dataconn("file list", -1, "w"); in send_file_list()
3193 if (dout == NULL) in send_file_list()
3198 fprintf(dout, "%s%s\n", dirname, in send_file_list()
3201 if (ferror(dout)) in send_file_list()
3204 (type == TYPE_A ? 2 : 1); in send_file_list()
3218 if (dir->d_name[0] == '.' && dir->d_namlen == 1) in send_file_list()
3220 if (dir->d_name[0] == '.' && dir->d_name[1] == '.' && in send_file_list()
3221 dir->d_namlen == 2) in send_file_list()
3225 "%s/%s", dirname, dir->d_name); in send_file_list()
3233 if (dout == NULL) { in send_file_list()
3234 dout = dataconn("file list", -1, "w"); in send_file_list()
3235 if (dout == NULL) in send_file_list()
3241 fprintf(dout, "%s%s\n", &nbuf[2], in send_file_list()
3244 fprintf(dout, "%s%s\n", nbuf, in send_file_list()
3247 if (ferror(dout)) in send_file_list()
3250 (type == TYPE_A ? 2 : 1); in send_file_list()
3258 if (dout == NULL) in send_file_list()
3260 else if (ferror(dout)) in send_file_list()
3265 if (dout) { in send_file_list()
3268 (void) fclose(dout); in send_file_list()
3269 data = -1; in send_file_list()
3270 pdata = -1; in send_file_list()
3283 while (waitpid(-1, NULL, WNOHANG) > 0); in reapchild()
3317 if (getcwd(wd, sizeof(wd) - 1) == NULL) in logcmd()
3351 (long)(now - start + (now == start))); in logxfer()
3366 if ((s2 = malloc(p - s + n + 1)) == NULL) in doublequote()
3401 for (maxs = 0, r = res; r; r = r->ai_next, maxs++) in socksetup()
3412 for (r = res; r; r = r->ai_next) { in socksetup()
3413 *s = socket(r->ai_family, r->ai_socktype, r->ai_protocol); in socksetup()
3422 if (r->ai_family == AF_INET6) { in socksetup()
3428 if (bind(*s, r->ai_addr, r->ai_addrlen) < 0) { in socksetup()