| 1 |
/* |
| 2 |
Copyright (C) 1994-2026 Free Software Foundation, Inc. |
| 3 |
|
| 4 |
This file is part of GNU Inetutils. |
| 5 |
|
| 6 |
GNU Inetutils is free software: you can redistribute it and/or modify |
| 7 |
it under the terms of the GNU General Public License as published by |
| 8 |
the Free Software Foundation, either version 3 of the License, or (at |
| 9 |
your option) any later version. |
| 10 |
|
| 11 |
GNU Inetutils is distributed in the hope that it will be useful, but |
| 12 |
WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 |
General Public License for more details. |
| 15 |
|
| 16 |
You should have received a copy of the GNU General Public License |
| 17 |
along with this program. If not, see `http://www.gnu.org/licenses/'. */ |
| 18 |
|
| 19 |
/* |
| 20 |
* Copyright (c) 1992, 1993 |
| 21 |
* The Regents of the University of California. All rights reserved. |
| 22 |
* |
| 23 |
* Redistribution and use in source and binary forms, with or without |
| 24 |
* modification, are permitted provided that the following conditions |
| 25 |
* are met: |
| 26 |
* 1. Redistributions of source code must retain the above copyright |
| 27 |
* notice, this list of conditions and the following disclaimer. |
| 28 |
* 2. Redistributions in binary form must reproduce the above copyright |
| 29 |
* notice, this list of conditions and the following disclaimer in the |
| 30 |
* documentation and/or other materials provided with the distribution. |
| 31 |
* 3. Neither the name of the University nor the names of its contributors |
| 32 |
* may be used to endorse or promote products derived from this software |
| 33 |
* without specific prior written permission. |
| 34 |
* |
| 35 |
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
| 36 |
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 37 |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 38 |
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
| 39 |
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 40 |
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 41 |
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 42 |
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 43 |
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 44 |
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 45 |
* SUCH DAMAGE. |
| 46 |
*/ |
| 47 |
|
| 48 |
#include <stdio.h> |
| 49 |
#include <unistd.h> |
| 50 |
#include <setjmp.h> |
| 51 |
#include <getopt.h> |
| 52 |
#include <sys/types.h> |
| 53 |
#include <sys/socket.h> |
| 54 |
#include <netinet/in.h> |
| 55 |
|
| 56 |
extern void cwd (const char *); |
| 57 |
extern int checkuser (const char *filename, const char *name); |
| 58 |
extern void delete (const char *); |
| 59 |
extern int display_file (const char *name, int code); |
| 60 |
extern void dologout (int); |
| 61 |
extern void fatal (const char *); |
| 62 |
extern int ftpd_pclose (FILE *); |
| 63 |
extern FILE *ftpd_popen (char *, const char *); |
| 64 |
extern void lreply (int, const char *, ...); |
| 65 |
extern void lreply_multiline (int n, const char *text); |
| 66 |
extern void makedir (const char *); |
| 67 |
extern void nack (const char *); |
| 68 |
extern void pass (const char *); |
| 69 |
extern void passive (int, int); |
| 70 |
extern void perror_reply (int, const char *); |
| 71 |
extern void pwd (void); |
| 72 |
extern void removedir (const char *); |
| 73 |
extern void renamecmd (const char *, const char *); |
| 74 |
extern char *renamefrom (const char *); |
| 75 |
extern void reply (int, const char *, ...); |
| 76 |
extern void retrieve (const char *, const char *); |
| 77 |
extern void send_file_list (const char *); |
| 78 |
extern void setproctitle (const char *, ...); |
| 79 |
extern void statcmd (void); |
| 80 |
extern void statfilecmd (const char *); |
| 81 |
extern void store (const char *, const char *, int); |
| 82 |
extern void toolong (int); |
| 83 |
extern char *telnet_fgets (char *, int, FILE *); |
| 84 |
extern void upper (char *); |
| 85 |
extern void user (const char *); |
| 86 |
extern char *sgetsave (const char *); |
| 87 |
|
| 88 |
/* Exported from ftpd.c. */ |
| 89 |
extern jmp_buf errcatch; |
| 90 |
extern struct sockaddr_storage data_dest; |
| 91 |
extern socklen_t data_dest_len; |
| 92 |
extern struct sockaddr_storage his_addr; |
| 93 |
extern socklen_t his_addrlen; |
| 94 |
extern struct passwd *pw; |
| 95 |
extern int guest; |
| 96 |
extern int logging; |
| 97 |
extern int no_version; |
| 98 |
extern int type; |
| 99 |
extern int form; |
| 100 |
extern int debug; |
| 101 |
extern int rfc2577; |
| 102 |
extern int timeout; |
| 103 |
extern int maxtimeout; |
| 104 |
extern int pdata; |
| 105 |
extern char *hostname; |
| 106 |
extern char *remotehost; |
| 107 |
extern char proctitle[]; |
| 108 |
extern int usedefault; |
| 109 |
extern char tmpline[]; |
| 110 |
|
| 111 |
/* Exported from ftpcmd.y. */ |
| 112 |
extern off_t restart_point; |
| 113 |
|
| 114 |
/* Distinguish passive address modes. */ |
| 115 |
#define PASSIVE_PASV 0 |
| 116 |
#define PASSIVE_EPSV 1 |
| 117 |
#define PASSIVE_LPSV 2 |
| 118 |
|
| 119 |
/* Exported from server_mode.c. */ |
| 120 |
extern int usefamily; |
| 121 |
extern int server_mode (const char *pidfile, struct sockaddr *phis_addr, |
| 122 |
socklen_t * phis_addrlen, char *argv[]); |
| 123 |
|
| 124 |
/* Credential for the request. */ |
| 125 |
struct credentials |
| 126 |
{ |
| 127 |
char *name; |
| 128 |
char *homedir; |
| 129 |
char *rootdir; |
| 130 |
char *shell; |
| 131 |
char *remotehost; |
| 132 |
char *passwd; |
| 133 |
char *pass; |
| 134 |
char *message; /* Sending back custom messages. */ |
| 135 |
uid_t uid; |
| 136 |
gid_t gid; |
| 137 |
int guest; |
| 138 |
int dochroot; |
| 139 |
int logged_in; |
| 140 |
int delayed_reject; |
| 141 |
#define AUTH_EXPIRED_NOT 0 |
| 142 |
#define AUTH_EXPIRED_ACCT 1 |
| 143 |
#define AUTH_EXPIRED_PASS 2 |
| 144 |
int expired; |
| 145 |
#define AUTH_TYPE_PASSWD 0 |
| 146 |
#define AUTH_TYPE_PAM 1 |
| 147 |
#define AUTH_TYPE_KERBEROS 2 |
| 148 |
#define AUTH_TYPE_KERBEROS5 3 |
| 149 |
#define AUTH_TYPE_OPIE 4 |
| 150 |
int auth_type; |
| 151 |
}; |
| 152 |
|
| 153 |
/* Exported from ftpd.c */ |
| 154 |
extern struct credentials cred; |
| 155 |
|
| 156 |
/* Exported from auth.c */ |
| 157 |
extern int sgetcred (const char *, struct credentials *); |
| 158 |
extern int auth_user (const char *, struct credentials *); |
| 159 |
extern int auth_pass (const char *, struct credentials *); |
| 160 |
|
| 161 |
/* Exported from pam.c */ |
| 162 |
#ifdef WITH_PAM |
| 163 |
extern int pam_user (const char *, struct credentials *); |
| 164 |
extern int pam_pass (const char *, struct credentials *); |
| 165 |
extern void pam_end_login (struct credentials *); |
| 166 |
#endif /* WITH_PAM */ |