]> git.sesse.net Git - betaftpd/blob - cmds.h
Fixed a security problem where the custom snprintf() would always be used. Thanks...
[betaftpd] / cmds.h
1 /*  cmds.c: BetaFTPD command handler prototypes
2     Copyright (C) 1999-2000 Steinar H. Gunderson
3
4     This program is is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License, version 2 of the
6     License as published by the Free Software Foundation.
7
8     This program is distributed in the hope that it will be useful,
9     but WITHOUT ANY WARRANTY; without even the implied warranty of
10     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11     GNU General Public License for more details.
12
13     You should have received a copy of the GNU General Public License
14     along with this program; if not, write to the Free Software
15     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16 */
17
18 #ifndef _CMDS_H
19 #define _CMDS_H 1
20
21 #include <ftpd.h>
22
23 /*
24  * TRAP_ERROR:  This is a quick way of doing a test for an error condition.
25  *              if an error occurs (or more precisely, if the value supplied is
26  *              true), an error message is sent back to the client. This is _not_
27  *              a debugging macro. The condition is allowed to have side effects,
28  *              and is only evaluated once.
29  *
30  *              The second argument is the FTP error code to send back, in case
31  *              of an error (the error message itself will be supplied by the
32  *              system). The third argument is code to execute after the FTP error
33  *              has been sent (typically `return' or `return -1').
34  *
35  *              If TRAP_ERROR_DEBUG is defined, some extra debugging info is
36  *              sent. Don't enable this for a normal server, it could be a
37  *              security risk.
38  */
39 #undef TRAP_ERROR_DEBUG
40 /* #define TRAP_ERROR_DEBUG 1 */
41
42 #ifdef TRAP_ERROR_DEBUG
43 #define TRAP_ERROR(x, num, y) TRAP_ERROR_INTERNAL(x, num, y, __FILE__, __LINE__)
44 #define TRAP_ERROR_INTERNAL(x, num, y, fl, ln) \
45         if (x) { \
46                 numeric(c, num, "%s (%s:%d)", strerror(errno), fl, ln); \
47                 y; \
48         }
49 #else
50 #define TRAP_ERROR(x, num, y) \
51         if (x) { \
52                 numeric(c, num, strerror(errno)); \
53                 y; \
54         }
55 #endif
56
57 #define CMD_PROTO(cmd) void cmd_ ## cmd (struct conn * const c)
58
59 int do_chdir(struct conn * const c, const char * const newd);
60 CMD_PROTO(user);
61 CMD_PROTO(pass);
62 CMD_PROTO(acct);
63 CMD_PROTO(port);
64 CMD_PROTO(pasv);
65 CMD_PROTO(pwd);
66 CMD_PROTO(cwd);
67 CMD_PROTO(cdup);
68 CMD_PROTO(rest);
69 CMD_PROTO(retr);
70 CMD_PROTO(size);
71 CMD_PROTO(mdtm);
72 CMD_PROTO(abor);
73 CMD_PROTO(dele);
74 CMD_PROTO(rnfr);
75 CMD_PROTO(rnto);
76 CMD_PROTO(mkd);
77 CMD_PROTO(rmd);
78 CMD_PROTO(allo);
79 CMD_PROTO(stat);
80 CMD_PROTO(list);
81 CMD_PROTO(nlst);
82 CMD_PROTO(syst);
83 CMD_PROTO(noop);
84 CMD_PROTO(type);
85 CMD_PROTO(mode);
86 CMD_PROTO(stru);
87 CMD_PROTO(help);
88 CMD_PROTO(quit);
89 CMD_PROTO(rein);
90
91 #if WANT_UPLOAD
92 CMD_PROTO(stor);
93 CMD_PROTO(appe);
94 #endif
95
96 #if DOING_PROFILING
97 CMD_PROTO(exit);        
98 #endif
99
100 void cmd_cwd_internal(struct conn * const c, const char * const newd);
101 void parse_command(struct conn *c);
102 void prepare_for_transfer(struct ftran *f);
103 char decode_mode(mode_t mode);
104 char *translate_path(struct conn * const c, char * const path);
105 int do_openfile(struct conn * const c, char * const path,
106                 char * const filename, const int flags
107 #if WANT_NONROOT
108                 , const int check_permission
109 #endif
110 );
111 int prepare_for_listing(struct conn * const c, char ** const ptr,
112                         struct list_options * const lo);
113 void do_listing(struct conn * const c, struct list_options * const lo);
114 int get_num_files(struct conn * const c, const char * const pathname,
115                    struct list_options * const lo);
116 int list_core(struct conn * const c, const char * const pathname,
117                    char * const disp_pathname, struct list_options * const lo
118 #if HAVE_MMAP
119                 , const int size, int pos
120 #endif
121 );
122 char classify(const mode_t mode);
123 void do_store(struct conn * const c, int append);
124 char *do_pwd(struct conn * const c, char * const retbuf, const char * const dir);
125
126 #ifndef HAVE_POLL
127 /*
128  * Even on select()-only systems, we use some poll() constants, so
129  * we'll have to make them up if we don't already have them. These
130  * are taken from my glibc 2.1 system.
131  */
132 #define POLLIN          0x001
133 #define POLLOUT         0x004
134 #endif
135
136 #endif