Made reply() be supplied a clientenv structure rather than an fdbuf one
authorMatthew Mondor <mmondor@pulsar-zone.net>
Tue, 8 Feb 2011 00:54:41 +0000 (00:54 +0000)
committerMatthew Mondor <mmondor@pulsar-zone.net>
Tue, 8 Feb 2011 00:54:41 +0000 (00:54 +0000)
so that all lines are logged with the session ID prefix.

mmsoftware/mmftpd/src/mmftpd.c
mmsoftware/mmftpd/src/mmftpd.h

index a0d8d61..1cfbdef 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: mmftpd.c,v 1.78 2009/01/17 03:29:05 mmondor Exp $ */
+/* $Id: mmftpd.c,v 1.79 2011/02/08 00:54:40 mmondor Exp $ */
 
 /*
  * Copyright (C) 2001-2008, Matthew Mondor
@@ -92,7 +92,7 @@
 
 MMCOPYRIGHT("@(#) Copyright (c) 2001-2004\n\
 \tMatthew Mondor. All rights reserved.\n");
-MMRCSID("$Id: mmftpd.c,v 1.78 2009/01/17 03:29:05 mmondor Exp $");
+MMRCSID("$Id: mmftpd.c,v 1.79 2011/02/08 00:54:40 mmondor Exp $");
 
 
 
@@ -335,7 +335,7 @@ static char                 *pasv_map_string = NULL;
 static int
 all_quit(clientenv *clenv)
 {
-    reply(clenv->fdb, 221, FALSE, "%s Closing connection",
+    reply(clenv, 221, FALSE, "%s Closing connection",
                clenv->iface->hostname);
 
     return (STATE_END);
@@ -347,8 +347,8 @@ all_help(clientenv *clenv)
 {
     char *args[3], *tmp, *tmp3;
     register int col;
-    fdbuf *fdb = clenv->fdb;
     register char *tmp2;
+    fdbuf *fdb = clenv->fdb;
 
     if ((mm_straspl(args, clenv->buffer, 2)) == 2) {
        register struct commandnode *nod;
@@ -363,27 +363,27 @@ all_help(clientenv *clenv)
            tmp = nod->command->name;
            if ((tmp2 = nod->command->args) == NULL) {
                REGISTER_ERROR();
-               reply(fdb, 214, FALSE,
+               reply(clenv, 214, FALSE,
                            "No help information for this command");
            } else {
                if ((tmp3 = nod->command->desc) == NULL)
-                   reply(fdb, 214, FALSE,
+                   reply(clenv, 214, FALSE,
                                "Syntax: %s %s ; (not implemented)",
                                tmp, tmp2);
                else
-                   reply(fdb, 214, FALSE, "Syntax: %s %s ; %s", tmp,
+                   reply(clenv, 214, FALSE, "Syntax: %s %s ; %s", tmp,
                                tmp2, tmp3);
            }
        } else {
            REGISTER_ERROR();
-           reply(fdb, 502, FALSE, "Unknown command");
+           reply(clenv, 502, FALSE, "Unknown command");
        }
 
     } else {
        register int i;
 
        /* Show all available topics */
-       reply(fdb, 214, TRUE,
+       reply(clenv, 214, TRUE,
                    "Available commands ('-' = not implemented)");
        fdbwrite(fdb, "    ", 4);
 
@@ -406,7 +406,7 @@ all_help(clientenv *clenv)
        }
 
        fdbwrite(fdb, "\r\n", 2);
-       reply(fdb, 214, FALSE, "HELP <command> for more information");
+       reply(clenv, 214, FALSE, "HELP <command> for more information");
 
     }
 
@@ -417,7 +417,7 @@ all_help(clientenv *clenv)
 static int
 all_noop(clientenv *clenv)
 {
-    reply(clenv->fdb, 200, FALSE, "Nothing performed");
+    reply(clenv, 200, FALSE, "Nothing performed");
 
     return (STATE_CURRENT);
 }
@@ -426,7 +426,7 @@ all_noop(clientenv *clenv)
 static int
 all_beer(clientenv *clenv)
 {
-    reply(clenv->fdb, 420, FALSE, "Here, enjoy!");
+    reply(clenv, 420, FALSE, "Here, enjoy!");
 
     return (STATE_CURRENT);
 }
@@ -436,7 +436,7 @@ static int
 all_user(clientenv *clenv)
 {
     REGISTER_ERROR();
-    reply(clenv->fdb, 530, FALSE, "Can't change user");
+    reply(clenv, 530, FALSE, "Can't change user");
 
     return (STATE_CURRENT);
 }
@@ -446,7 +446,7 @@ static int
 all_pass(clientenv *clenv)
 {
     REGISTER_ERROR();
-    reply(clenv->fdb, 503, FALSE, "Login with USER first");
+    reply(clenv, 503, FALSE, "Login with USER first");
 
     return (STATE_CURRENT);
 }
@@ -455,14 +455,13 @@ all_pass(clientenv *clenv)
 static int
 all_syst(clientenv *clenv)
 {
-    fdbuf *fdb = clenv->fdb;
     char *args[2];
 
     if ((mm_straspl(args, clenv->buffer, 1)) == 1) {
-       reply(fdb, 215, FALSE,
+       reply(clenv, 215, FALSE,
                    "UNIX Type: L8 - IEEE Std 1003 (``POSIX'')");
     } else {
-       reply(fdb, 550, FALSE, "Command syntax error");
+       reply(clenv, 550, FALSE, "Command syntax error");
        REGISTER_ERROR();
     }
 
@@ -478,7 +477,6 @@ static int
 auth_user(clientenv *clenv)
 {
     int nextstate = STATE_CURRENT;
-    fdbuf *fdb = clenv->fdb;
     char *args[3];
 
     if (clenv->user || clenv->tuser) {
@@ -500,9 +498,9 @@ auth_user(clientenv *clenv)
                 */
                clenv->anonymous = TRUE;
                clenv->tuser = NULL;
-               reply(fdb, 331, FALSE, "Enter your name for password");
+               reply(clenv, 331, FALSE, "Enter your name for password");
            } else {
-               reply(fdb, 530, FALSE,
+               reply(clenv, 530, FALSE,
                            "No anonymous access on this server");
                if (CONF.STATFAIL_LOGIN)
                    mmstat(&clenv->pstat, STAT_UPDATE, 1,
@@ -522,12 +520,12 @@ auth_user(clientenv *clenv)
                nextstate = STATE_ERROR;
            }
            clenv->anonymous = FALSE;
-           reply(fdb, 331, FALSE, "Password required for this user");
+           reply(clenv, 331, FALSE, "Password required for this user");
 
        }
 
     } else {
-       reply(fdb, 500, FALSE, "Command syntax error");
+       reply(clenv, 500, FALSE, "Command syntax error");
        REGISTER_ERROR();
     }
 
@@ -539,12 +537,12 @@ static int
 auth_pass(clientenv *clenv)
 {
     int nextstate = STATE_CURRENT;
-    fdbuf *fdb = clenv->fdb;
     char *pw;
+    fdbuf *fdb = clenv->fdb;
 
     if (!clenv->user && !clenv->tuser) {
 
-       reply(fdb, 503, FALSE, "Specify username first");
+       reply(clenv, 503, FALSE, "Specify username first");
        REGISTER_ERROR();
 
     } else {
@@ -636,7 +634,7 @@ auth_pass(clientenv *clenv)
            REGISTER_ERROR();
            if (clenv->user) clenv->user = mmstrfree(clenv->user);
            if (clenv->tuser) clenv->tuser = mmstrfree(clenv->tuser);
-           reply(fdb, 530, FALSE, "Invalid login");
+           reply(clenv, 530, FALSE, "Invalid login");
        }
 
     }
@@ -649,7 +647,7 @@ auth_pass(clientenv *clenv)
        size_t len;
 
        if (*CONF.MOTD_FILE) {
-           reply(fdb, 230, TRUE, NULL);
+           reply(clenv, 230, TRUE, NULL);
            if (!file_out(fdb, CONF.MOTD_FILE))
                mmsyslog(0, LOGLEVEL, "%08X Error opening MOTD_FILE \"%s\"",
                        clenv->id, CONF.MOTD_FILE);
@@ -676,11 +674,11 @@ auth_pass(clientenv *clenv)
            if (lok) {
                clenv->unode = lun;
                if (clenv->anonymous)
-                   reply(fdb, 230, FALSE, "Restricted anonymous login ok");
+                   reply(clenv, 230, FALSE, "Restricted anonymous login ok");
                else
-                   reply(fdb, 230, FALSE, "User login ok");
+                   reply(clenv, 230, FALSE, "User login ok");
            } else {
-               reply(fdb, 530, FALSE,
+               reply(clenv, 530, FALSE,
                            "Maximum allowed logins exceeded for this user");
                nextstate = STATE_CURRENT;
            }
@@ -712,13 +710,13 @@ auth_pass(clientenv *clenv)
                    hashtable_link(&lusers_table, (hashnode_t *)lun, lun->user,
                            len, FALSE);
                    if (clenv->anonymous)
-                       reply(fdb, 230, FALSE,
+                       reply(clenv, 230, FALSE,
                                "Restricted anonymous login ok");
                    else
-                       reply(fdb, 230, FALSE, "User login ok");
+                       reply(clenv, 230, FALSE, "User login ok");
                }
            } else {
-               reply(fdb, 530, FALSE,
+               reply(clenv, 530, FALSE,
                            "Maximum allowed logins exceeded for this user");
                nextstate = STATE_CURRENT;
            }
@@ -750,17 +748,17 @@ main_cwd(clientenv *clenv)
            if (t == MMPATH_DIR) {
                mm_strncpy(clenv->cwd, path, MMPATH_MAX - 1);
                if (!directory_message(clenv, 250)) return (STATE_ERROR);
-               reply(clenv->fdb, 250, FALSE, "Command successful");
+               reply(clenv, 250, FALSE, "Command successful");
 
                return (STATE_CURRENT);
            } else
-               reply(clenv->fdb, 550, FALSE, "No such file or directory");
+               reply(clenv, 550, FALSE, "No such file or directory");
        } else {
-           reply(clenv->fdb, 502, FALSE, "Permission denied");
+           reply(clenv, 502, FALSE, "Permission denied");
            REGISTER_PERMISSION();
        }
     } else
-       reply(clenv->fdb, 550, FALSE, "Invalid pathname");
+       reply(clenv, 550, FALSE, "Invalid pathname");
 
     REGISTER_ERROR();
 
@@ -778,9 +776,9 @@ main_cdup(clientenv *clenv)
        path_parent(clenv->cwd);
        if (!directory_message(clenv, 250))
            nextstate = STATE_ERROR;
-       reply(clenv->fdb, 250, FALSE, "Command successful");
+       reply(clenv, 250, FALSE, "Command successful");
     } else {
-       reply(clenv->fdb, 550, FALSE, "Command syntax error");
+       reply(clenv, 550, FALSE, "Command syntax error");
        REGISTER_ERROR();
     }
 
@@ -792,7 +790,6 @@ static int
 main_port(clientenv *clenv)
 {
     uint16_t port;
-    fdbuf *fdb = clenv->fdb;
     char *args[7];
     uint8_t p[2];
     transfermsg *msg = &(clenv->tmsg);
@@ -800,7 +797,7 @@ main_port(clientenv *clenv)
     /* PORT 127,0,0,1,255,26 */
 
     if (clenv->advaddr_s == NULL) {
-       reply(fdb, 500, FALSE, "Protocol requires LPRT or EPRT");
+       reply(clenv, 500, FALSE, "Protocol requires LPRT or EPRT");
        REGISTER_ERROR();
        return STATE_CURRENT;
     }
@@ -823,35 +820,36 @@ main_port(clientenv *clenv)
                        msg->port = port;
                        msg->passive = FALSE;
                        if (transfer_request(REQ_NEWPORT, TRUE, clenv))
-                           reply(fdb, 200, FALSE, "PORT command successful");
+                           reply(clenv, 200, FALSE,
+                                   "PORT command successful");
                        else {
-                           reply(fdb, 500, FALSE, "Error");
+                           reply(clenv, 500, FALSE, "Error");
                            REGISTER_ERROR();
                            DEBUG_PRINTF("main_port",
                                    "transfer_request(REQ_NEWPORT)");
                        }
                    } else {
-                       reply(fdb, 500, FALSE, "Transfer ongoing");
+                       reply(clenv, 500, FALSE, "Transfer ongoing");
                        REGISTER_ERROR();
                    }
                } else {
-                   reply(fdb, 500, FALSE, "Error");
+                   reply(clenv, 500, FALSE, "Error");
                    REGISTER_ERROR();
                    DEBUG_PRINTF("main_port", "transfer_reqiest(REQ_STATUS)");
                }
            } else {
                mmsyslog(0, LOGLEVEL, "%08X Illegal port %u",
                        clenv->id, port);
-               reply(fdb, 500, FALSE, "Illegal port or address");
+               reply(clenv, 500, FALSE, "Illegal port or address");
                REGISTER_PORT();
                REGISTER_ERROR();
            }
        } else {
-           reply(fdb, 550, FALSE, "Command syntax error");
+           reply(clenv, 550, FALSE, "Command syntax error");
            REGISTER_ERROR();
        }
     } else {
-       reply(fdb, 550, FALSE, "Command syntax error");
+       reply(clenv, 550, FALSE, "Command syntax error");
        REGISTER_ERROR();
     }
 
@@ -865,7 +863,6 @@ main_lprt(clientenv *clenv)
     bool ok;
     int i;
     uint16_t port;
-    fdbuf *fdb = clenv->fdb;
     char *args[22];
     uint8_t p[2];
     transfermsg *msg = &(clenv->tmsg);
@@ -900,20 +897,20 @@ main_lprt(clientenv *clenv)
                        msg->port = port;
                        msg->passive = FALSE;
                        if (transfer_request(REQ_NEWPORT, TRUE, clenv))
-                           reply(fdb, 200, FALSE,
+                           reply(clenv, 200, FALSE,
                                    "LPRT command successful");
                        else {
-                           reply(fdb, 500, FALSE, "Error");
+                           reply(clenv, 500, FALSE, "Error");
                            REGISTER_ERROR();
                            DEBUG_PRINTF("main_lprt",
                                    "transfer_request(REQ_NEWPORT)");
                        }
                    } else {
-                       reply(fdb, 500, FALSE, "Transfer ongoing");
+                       reply(clenv, 500, FALSE, "Transfer ongoing");
                        REGISTER_ERROR();
                    }
                } else {
-                   reply(fdb, 500, FALSE, "Error");
+                   reply(clenv, 500, FALSE, "Error");
                    REGISTER_ERROR();
                    DEBUG_PRINTF("main_lptr",
                            "transfer_request(REQ_STATUS)");
@@ -921,16 +918,16 @@ main_lprt(clientenv *clenv)
            } else {
                mmsyslog(0, LOGLEVEL, "%08X Illegal port %u",
                        clenv->id, port);
-               reply(fdb, 500, FALSE, "Illegal port or address");
+               reply(clenv, 500, FALSE, "Illegal port or address");
                REGISTER_PORT();
                REGISTER_ERROR();
            }
        } else {
-           reply(fdb, 550, FALSE, "Command syntax error");
+           reply(clenv, 550, FALSE, "Command syntax error");
            REGISTER_ERROR();
        }
     } else {
-       reply(fdb, 550, FALSE, "Command syntax error");
+       reply(clenv, 550, FALSE, "Command syntax error");
        REGISTER_ERROR();
     }
 
@@ -942,7 +939,6 @@ static int
 main_eprt(clientenv *clenv)
 {
     int port, i;
-    fdbuf *fdb = clenv->fdb;
     char *args[5];
     transfermsg *msg = &(clenv->tmsg);
 
@@ -968,20 +964,20 @@ main_eprt(clientenv *clenv)
                            msg->port = (uint16_t)port;
                            msg->passive = FALSE;
                            if (transfer_request(REQ_NEWPORT, TRUE, clenv))
-                               reply(fdb, 200, FALSE,
+                               reply(clenv, 200, FALSE,
                                            "EPRT command successful");
                            else {
-                               reply(fdb, 500, FALSE, "Error");
+                               reply(clenv, 500, FALSE, "Error");
                                REGISTER_ERROR();
                                DEBUG_PRINTF("main_eprt",
                                        "transfer_request(REQ_NEWPORT)");
                            }
                        } else {
-                           reply(fdb, 500, FALSE, "Transfer ongoing");
+                           reply(clenv, 500, FALSE, "Transfer ongoing");
                            REGISTER_ERROR();
                        }
                    } else {
-                       reply(fdb, 500, FALSE, "Error");
+                       reply(clenv, 500, FALSE, "Error");
                        REGISTER_ERROR();
                        DEBUG_PRINTF("main_eprt",
                                "transfer_request(REQ_STATUS)");
@@ -989,20 +985,20 @@ main_eprt(clientenv *clenv)
                } else {
                    mmsyslog(0, LOGLEVEL, "%08X Illegal port %d",
                            clenv->id, port);
-                   reply(fdb, 500, FALSE, "Illegal port or address");
+                   reply(clenv, 500, FALSE, "Illegal port or address");
                    REGISTER_PORT();
                    REGISTER_ERROR();
                }
            } else {
-               reply(fdb, 522, FALSE, "Unimplemented protocol");
+               reply(clenv, 522, FALSE, "Unimplemented protocol");
                REGISTER_ERROR();
            }
        } else {
-           reply(fdb, 550, FALSE, "Command syntax error");
+           reply(clenv, 550, FALSE, "Command syntax error");
            REGISTER_ERROR();
        }
     } else {
-       reply(fdb, 550, FALSE, "Command syntax error");
+       reply(clenv, 550, FALSE, "Command syntax error");
        REGISTER_ERROR();
     }
 
@@ -1013,12 +1009,11 @@ main_eprt(clientenv *clenv)
 static int
 main_pasv(clientenv *clenv)
 {
-    fdbuf *fdb = clenv->fdb;
     transfermsg *msg = &(clenv->tmsg);
     uint8_t a, b;
 
     if (clenv->advaddr_s == NULL) {
-       reply(fdb, 500, FALSE, "Protocol requires LPSV or EPSV");
+       reply(clenv, 500, FALSE, "Protocol requires LPSV or EPSV");
        REGISTER_ERROR();
        return STATE_CURRENT;
     }
@@ -1038,26 +1033,26 @@ main_pasv(clientenv *clenv)
                    a = msg->port / 256;
                    b = msg->port % 256;
                    */
-                   reply(fdb, 227, FALSE,
+                   reply(clenv, 227, FALSE,
                                "Entering passive mode (%s,%u,%u)",
                                clenv->advaddr_s, a, b);
                } else {
-                   reply(fdb, 500, FALSE, "Error");
+                   reply(clenv, 500, FALSE, "Error");
                    REGISTER_ERROR();
                    DEBUG_PRINTF("main_pasv",
                            "transfer_request(REQ_NEWPORT)");
                }
            } else {
-               reply(fdb, 500, FALSE, "Transfer ongoing");
+               reply(clenv, 500, FALSE, "Transfer ongoing");
                REGISTER_ERROR();
            }
        } else {
-           reply(fdb, 500, FALSE, "Error");
+           reply(clenv, 500, FALSE, "Error");
            REGISTER_ERROR();
            DEBUG_PRINTF("main_pasv", "transfer_request(REQ_STATUS)");
        }
     } else {
-       reply(fdb, 501, FALSE, "Command syntax error");
+       reply(clenv, 501, FALSE, "Command syntax error");
        REGISTER_ERROR();
     }
 
@@ -1068,7 +1063,6 @@ main_pasv(clientenv *clenv)
 static int
 main_lpsv(clientenv *clenv)
 {
-    fdbuf *fdb = clenv->fdb;
     transfermsg *msg = &(clenv->tmsg);
     uint8_t a, b;
 
@@ -1087,26 +1081,26 @@ main_lpsv(clientenv *clenv)
                    a = msg->port / 256;
                    b = msg->port % 256;
                    */
-                   reply(fdb, 228, FALSE,
+                   reply(clenv, 228, FALSE,
                                "Entering long passive mode (%s,2,%u,%u)",
                                clenv->advaddr_l, a, b);
                } else {
-                   reply(fdb, 500, FALSE, "Error");
+                   reply(clenv, 500, FALSE, "Error");
                    REGISTER_ERROR();
                    DEBUG_PRINTF("main_lpsv",
                            "transfer_request(REQ_NEWPORT)");
                }
            } else {
-               reply(fdb, 500, FALSE, "Transfer ongoing");
+               reply(clenv, 500, FALSE, "Transfer ongoing");
                REGISTER_ERROR();
            }
        } else {
-           reply(fdb, 500, FALSE, "Error");
+           reply(clenv, 500, FALSE, "Error");
            REGISTER_ERROR();
            DEBUG_PRINTF("main_lpsv", "transfer_request(REQ_STATUS)");
        }
     } else {
-       reply(fdb, 501, FALSE, "Command syntax error");
+       reply(clenv, 501, FALSE, "Command syntax error");
        REGISTER_ERROR();
     }
 
@@ -1117,7 +1111,6 @@ main_lpsv(clientenv *clenv)
 static int
 main_epsv(clientenv *clenv)
 {
-    fdbuf *fdb = clenv->fdb;
     transfermsg *msg = &(clenv->tmsg);
 
     if (!clenv->buffer[4]) {
@@ -1127,26 +1120,26 @@ main_epsv(clientenv *clenv)
                /* Send our PASV transfer request */
                msg->passive = TRUE;
                if (transfer_request(REQ_NEWPORT, TRUE, clenv)) {
-                   reply(fdb, 229, FALSE,
+                   reply(clenv, 229, FALSE,
                                "Entering extended passive mode (|||%u|)",
                                msg->port);
                } else {
-                   reply(fdb, 500, FALSE, "Error");
+                   reply(clenv, 500, FALSE, "Error");
                    REGISTER_ERROR();
                    DEBUG_PRINTF("main_epsv",
                            "transfer_request(REQ_NEWPORT)");
                }
            } else {
-               reply(fdb, 500, FALSE, "Transfer ongoing");
+               reply(clenv, 500, FALSE, "Transfer ongoing");
                REGISTER_ERROR();
            }
        } else {
-           reply(fdb, 500, FALSE, "Error");
+           reply(clenv, 500, FALSE, "Error");
            REGISTER_ERROR();
            DEBUG_PRINTF("main_epsv", "transfer_request(REQ_STATUS)");
        }
     } else {
-       reply(fdb, 501, FALSE, "Command syntax error");
+       reply(clenv, 501, FALSE, "Command syntax error");
        REGISTER_ERROR();
     }
 
@@ -1158,38 +1151,37 @@ static int
 main_type(clientenv *clenv)
 {
     int  a;
-    fdbuf *fdb = clenv->fdb;
     char *args[4];
 
     if ((a = mm_straspl(args, clenv->buffer, 3)) == 2) {
        if (!(mm_strcasecmp(args[1], "A"))) {
            clenv->type = TYPE_ASCII;
-           reply(fdb, 200, FALSE, "Type ASCII set");
+           reply(clenv, 200, FALSE, "Type ASCII set");
        } else if (!(mm_strcasecmp(args[1], "I"))) {
            clenv->type = TYPE_IMAGE;
-           reply(fdb, 200, FALSE, "Type IMAGE set");
+           reply(clenv, 200, FALSE, "Type IMAGE set");
        } else if (!(mm_strcasecmp(args[1], "L"))) {
            clenv->type = TYPE_LOCAL;
-           reply(fdb, 200, FALSE, "Type LOCAL set (8 bits per byte)");
+           reply(clenv, 200, FALSE, "Type LOCAL set (8 bits per byte)");
        } else {
-           reply(fdb, 504, FALSE, "Unimplemented type");
+           reply(clenv, 504, FALSE, "Unimplemented type");
            REGISTER_ERROR();
        }
     } else if (a == 3) {
        if (!(mm_strcasecmp(args[1], "L"))) {
            if (atoi(args[2]) == 8) {
                clenv->type = TYPE_LOCAL;
-               reply(fdb, 200, FALSE, "Type LOCAL set (8 bits per byte)");
+               reply(clenv, 200, FALSE, "Type LOCAL set (8 bits per byte)");
            } else {
-               reply(fdb, 504, FALSE, "Only 8-bit bytes allowed");
+               reply(clenv, 504, FALSE, "Only 8-bit bytes allowed");
                REGISTER_ERROR();
            }
        } else {
-           reply(fdb, 550, FALSE, "Command syntax error");
+           reply(clenv, 550, FALSE, "Command syntax error");
            REGISTER_ERROR();
        }
     } else {
-       reply(fdb, 550, FALSE, "Command syntax error");
+       reply(clenv, 550, FALSE, "Command syntax error");
        REGISTER_ERROR();
     }
 
@@ -1200,18 +1192,17 @@ main_type(clientenv *clenv)
 static int
 main_stru(clientenv *clenv)
 {
-    fdbuf *fdb = clenv->fdb;
     char *args[3];
 
     if ((mm_straspl(args, clenv->buffer, 2)) == 2) {
        if (!(mm_strcasecmp(args[1], "F")))
-           reply(fdb, 200, FALSE, "Structure FILE set");
+           reply(clenv, 200, FALSE, "Structure FILE set");
        else {
-           reply(fdb, 504, FALSE, "Unimplemented structure");
+           reply(clenv, 504, FALSE, "Unimplemented structure");
            REGISTER_ERROR();
        }
     } else {
-       reply(fdb, 550, FALSE, "Command syntax error");
+       reply(clenv, 550, FALSE, "Command syntax error");
        REGISTER_ERROR();
     }
 
@@ -1222,18 +1213,17 @@ main_stru(clientenv *clenv)
 static int
 main_mode(clientenv *clenv)
 {
-    fdbuf *fdb = clenv->fdb;
     char *args[3];
 
     if ((mm_straspl(args, clenv->buffer, 2)) == 2) {
        if (!(mm_strcasecmp(args[1], "S")))
-           reply(fdb, 200, FALSE, "Mode STREAM set");
+           reply(clenv, 200, FALSE, "Mode STREAM set");
        else {
-           reply(fdb, 502, FALSE, "Unimplemented mode");
+           reply(clenv, 502, FALSE, "Unimplemented mode");
            REGISTER_ERROR();
        }
     } else {
-       reply(fdb, 550, FALSE, "Command syntax error");
+       reply(clenv, 550, FALSE, "Command syntax error");
        REGISTER_ERROR();
     }
 
@@ -1245,7 +1235,6 @@ static int
 main_retr(clientenv *clenv)
 {
     int file;
-    fdbuf *fdb = clenv->fdb;
     char path[MMPATH_MAX], cpath[MMPATH_MAX];
     transfermsg *msg = &(clenv->tmsg);
 
@@ -1278,29 +1267,30 @@ main_retr(clientenv *clenv)
                                        cpath);
                            }
                        } else {
-                           reply(fdb, 425, FALSE, "Error");
+                           reply(clenv, 425, FALSE, "Error");
                            REGISTER_ERROR();
                            DEBUG_PRINTF("main_retr", "open(%s)", path);
                        }
                    } else {
-                       reply(fdb, 425, FALSE, "Transfer already ongoing");
+                       reply(clenv, 425, FALSE, "Transfer already ongoing");
                        REGISTER_ERROR();
                    }
                } else {
-                   reply(fdb, 425, FALSE, "Can't establish data connection");
+                   reply(clenv, 425, FALSE,
+                           "Can't establish data connection");
                    REGISTER_ERROR();
                }
            } else {
-               reply(fdb, 425, FALSE, "Error");
+               reply(clenv, 425, FALSE, "Error");
                REGISTER_ERROR();
                DEBUG_PRINTF("main_retr", "transfer_request(REQ_STATUS)");
            }
        } else {
-           reply(fdb, 550, FALSE, "Not a plain file");
+           reply(clenv, 550, FALSE, "Not a plain file");
            REGISTER_ERROR();
        }
     } else {
-       reply(fdb, 550, FALSE, "No such file or directory");
+       reply(clenv, 550, FALSE, "No such file or directory");
        REGISTER_ERROR();
     }
 
@@ -1317,7 +1307,6 @@ static int
 main_stor(clientenv *clenv)
 {
     int file, i;
-    fdbuf *fdb = clenv->fdb;
     char path[MMPATH_MAX], cpath[MMPATH_MAX];
     transfermsg *msg = &(clenv->tmsg);
     mode_t mode;
@@ -1388,49 +1377,49 @@ main_stor(clientenv *clenv)
                                            close(file);
                                        }
                                    } else {
-                                       reply(fdb, 425, FALSE, "Error");
+                                       reply(clenv, 425, FALSE, "Error");
                                        REGISTER_ERROR();
                                        DEBUG_PRINTF("main_stor",
                                                "open(%s)", path);
                                    }
                                } else {
-                                   reply(fdb, 502, FALSE, "Quota exceeded");
+                                   reply(clenv, 502, FALSE, "Quota exceeded");
                                    REGISTER_ERROR();
                                    mmsyslog(0, LOGLEVEL,
                                            "%08X Quota exceeded",
                                            clenv->id);
                                }
                            } else {
-                               reply(fdb, 425, FALSE,
+                               reply(clenv, 425, FALSE,
                                        "Transfer already ongoing");
                                REGISTER_ERROR();
                            }
                        } else {
-                           reply(fdb, 425, FALSE,
+                           reply(clenv, 425, FALSE,
                                        "Can't establish data connection");
                            REGISTER_ERROR();
                        }
                    } else {
-                       reply(fdb, 425, FALSE, "Error");
+                       reply(clenv, 425, FALSE, "Error");
                        REGISTER_ERROR();
                        DEBUG_PRINTF("main_stor",
                                "transfer_request(REQ_STATUS)");
                    }
                } else {
-                   reply(fdb, 502, FALSE, "Permission denied");
+                   reply(clenv, 502, FALSE, "Permission denied");
                    REGISTER_PERMISSION();
                    REGISTER_ERROR();
                }
            } else {
-               reply(fdb, 550, FALSE, "Not a plain file");
+               reply(clenv, 550, FALSE, "Not a plain file");
                REGISTER_ERROR();
            }
        } else {
-           reply(fdb, 550, FALSE, "Invalid filename");
+           reply(clenv, 550, FALSE, "Invalid filename");
            REGISTER_ERROR();
        }
     } else {
-       reply(fdb, 502, FALSE, "Permission denied");
+       reply(clenv, 502, FALSE, "Permission denied");
        REGISTER_PERMISSION();
        REGISTER_ERROR();
     }
@@ -1443,7 +1432,6 @@ static int
 main_stou(clientenv *clenv)
 {
     int file, i, i2, i3;
-    fdbuf *fdb = clenv->fdb;
     char path[MMPATH_MAX], cpath[MMPATH_MAX], prefix[MMPATH_MAX],
        uniquepath[MMPATH_MAX], *tmp;
     transfermsg *msg = &(clenv->tmsg);
@@ -1520,44 +1508,46 @@ main_stou(clientenv *clenv)
                                        close(file);
                                    }
                                } else {
-                                   reply(fdb, 425, FALSE, "Error");
+                                   reply(clenv, 425, FALSE, "Error");
                                    REGISTER_ERROR();
                                    DEBUG_PRINTF("main_stou", "open(%s)",
                                            uniquepath);
                                }
                            } else {
-                               reply(fdb, 502, FALSE, "Quota exceeded");
+                               reply(clenv, 502, FALSE, "Quota exceeded");
                                REGISTER_ERROR();
                                mmsyslog(0, LOGLEVEL,
                                        "%08X Quota exceeded", clenv->id);
                            }
                        } else {
-                           reply(fdb, 425, FALSE, "Transfer already ongoing");
+                           reply(clenv, 425, FALSE,
+                                   "Transfer already ongoing");
                            REGISTER_ERROR();
                        }
                    } else {
-                       reply(fdb, 425, FALSE,
+                       reply(clenv, 425, FALSE,
                                "Can't establish data connection");
                        REGISTER_ERROR();
                    }
                } else {
-                   reply(fdb, 425, FALSE, "Error");
+                   reply(clenv, 425, FALSE, "Error");
                    REGISTER_ERROR();
                    DEBUG_PRINTF("main_stou",
                            "transfer_request(REQ_STATUS)");
                }
            } else {
-               reply(fdb, 425, FALSE, "Coundn't generate unique filename");
+               reply(clenv, 425, FALSE,
+                       "Coundn't generate unique filename");
                REGISTER_ERROR();
                DEBUG_PRINTF("main_stou",
                        "Couldn't generate unique filename");
            }
        } else {
-           reply(fdb, 550, FALSE, "Invalid filename");
+           reply(clenv, 550, FALSE, "Invalid filename");
            REGISTER_ERROR();
        }
     } else {
-       reply(fdb, 502, FALSE, "Permission denied");
+       reply(clenv, 502, FALSE, "Permission denied");
        REGISTER_PERMISSION();
        REGISTER_ERROR();
     }
@@ -1570,7 +1560,6 @@ static int
 main_appe(clientenv *clenv)
 {
     int file = -1, i;
-    fdbuf *fdb = clenv->fdb;
     char path[MMPATH_MAX], cpath[MMPATH_MAX];
     transfermsg *msg = &(clenv->tmsg);
     mode_t mode;
@@ -1598,7 +1587,7 @@ main_appe(clientenv *clenv)
                                        file = open(path, O_WRONLY | O_CREAT,
                                                mode);
                                    } else {
-                                       reply(fdb, 502, FALSE,
+                                       reply(clenv, 502, FALSE,
                                                "Quota exceeded");
                                        REGISTER_ERROR();
                                        mmsyslog(0, LOGLEVEL,
@@ -1627,42 +1616,42 @@ main_appe(clientenv *clenv)
                                        close(file);
                                    }
                                } else {
-                                   reply(fdb, 425, FALSE, "Error");
+                                   reply(clenv, 425, FALSE, "Error");
                                    REGISTER_ERROR();
                                    DEBUG_PRINTF("main_appe",
                                            "open(%s)", path);
                                }
                            } else {
-                               reply(fdb, 425, FALSE,
+                               reply(clenv, 425, FALSE,
                                        "Transfer already ongoing");
                                REGISTER_ERROR();
                            }
                        } else {
-                           reply(fdb, 425, FALSE,
+                           reply(clenv, 425, FALSE,
                                        "Can't establish data connection");
                            REGISTER_ERROR();
                        }
                    } else {
-                       reply(fdb, 425, FALSE, "Error");
+                       reply(clenv, 425, FALSE, "Error");
                        REGISTER_ERROR();
                        DEBUG_PRINTF("main_appe",
                                "transfer_request(REQ_STATUS");
                    }
                } else {
-                   reply(fdb, 502, FALSE, "Permission denied");
+                   reply(clenv, 502, FALSE, "Permission denied");
                    REGISTER_PERMISSION();
                    REGISTER_ERROR();
                }
            } else {
-               reply(fdb, 550, FALSE, "Not a plain file");
+               reply(clenv, 550, FALSE, "Not a plain file");
                REGISTER_ERROR();
            }
        } else {
-           reply(fdb, 550, FALSE, "Invalid filename");
+           reply(clenv, 550, FALSE, "Invalid filename");
            REGISTER_ERROR();
        }
     } else {
-       reply(fdb, 502, FALSE, "Permission denied");
+       reply(clenv, 502, FALSE, "Permission denied");
        REGISTER_PERMISSION();
        REGISTER_ERROR();
     }
@@ -1677,9 +1666,9 @@ main_allo(clientenv *clenv)
     char *args[3];
 
     if ((mm_straspl(args, clenv->buffer, 2)) == 2)
-       reply(clenv->fdb, 202, FALSE, "Nothing done");
+       reply(clenv, 202, FALSE, "Nothing done");
     else {
-       reply(clenv->fdb, 550, FALSE, "Command syntax error");
+       reply(clenv, 550, FALSE, "Command syntax error");
        REGISTER_ERROR();
     }
 
@@ -1698,15 +1687,15 @@ main_rest(clientenv *clenv)
        rest = (off_t)strtoull(args[1], &t, 10);
        if (*args[1] != '\0' && *t == '\0' && rest != 0) {
            clenv->rest = rest;
-           reply(clenv->fdb, 350, FALSE,
+           reply(clenv, 350, FALSE,
                    "Restarting at %lld, waiting for STOR/RETR",
                    (int64_t)clenv->rest);
        } else {
-           reply(clenv->fdb, 550, FALSE, "Invalid value");
+           reply(clenv, 550, FALSE, "Invalid value");
            REGISTER_ERROR();
        }
     } else {
-       reply(clenv->fdb, 550, FALSE, "Command syntax error");
+       reply(clenv, 550, FALSE, "Command syntax error");
        REGISTER_ERROR();
     }
 
@@ -1718,7 +1707,6 @@ static int
 main_rnfr(clientenv *clenv)
 {
     int t = MMPATH_DENIED;
-    fdbuf *fdb = clenv->fdb;
     char path[MMPATH_MAX];
 
     if (clenv->modify) {
@@ -1737,14 +1725,14 @@ main_rnfr(clientenv *clenv)
        }
 
        if (clenv->rnfr)
-           reply(fdb, 350, FALSE, "Exists, specify new name");
+           reply(clenv, 350, FALSE, "Exists, specify new name");
        else {
-           reply(fdb, 550, FALSE, "No such file or directory");
+           reply(clenv, 550, FALSE, "No such file or directory");
            REGISTER_ERROR();
        }
 
     } else {
-       reply(fdb, 502, FALSE, "Permission denied");
+       reply(clenv, 502, FALSE, "Permission denied");
        REGISTER_PERMISSION();
        REGISTER_ERROR();
     }
@@ -1756,7 +1744,6 @@ main_rnfr(clientenv *clenv)
 static int
 main_rnto(clientenv *clenv)
 {
-    fdbuf *fdb = clenv->fdb;
     char path[MMPATH_MAX];
 
     if (clenv->modify) {
@@ -1769,29 +1756,29 @@ main_rnto(clientenv *clenv)
                        MMPATH_NONE) {
                    /* Rename file */
                    if ((rename(clenv->rnfr, path)) != -1)
-                       reply(fdb, 250, FALSE, "Command successful");
+                       reply(clenv, 250, FALSE, "Command successful");
                    else {
-                       reply(fdb, 521, FALSE, "Error renaming file");
+                       reply(clenv, 521, FALSE, "Error renaming file");
                        REGISTER_ERROR();
                        mmsyslog(0, LOGLEVEL,
                                "%08X main_rnto() - rename(%s,%s)",
                                clenv->id, clenv->rnfr, path);
                    }
                } else {
-                   reply(fdb, 521, FALSE, "File exists");
+                   reply(clenv, 521, FALSE, "File exists");
                    REGISTER_ERROR();
                }
            } else {
-               reply(fdb, 550, FALSE, "Command syntax error");
+               reply(clenv, 550, FALSE, "Command syntax error");
                REGISTER_ERROR();
            }
            clenv->rnfr = mmstrfree(clenv->rnfr);
        } else {
-           reply(fdb, 503, FALSE, "RNFR expected first");
+           reply(clenv, 503, FALSE, "RNFR expected first");
            REGISTER_ERROR();
        }
     } else {
-       reply(fdb, 502, FALSE, "Permission denied");
+       reply(clenv, 502, FALSE, "Permission denied");
        REGISTER_PERMISSION();
        REGISTER_ERROR();
     }
@@ -1810,7 +1797,7 @@ main_abor(clientenv *clenv)
        clenv->rest = 0;
        if (clenv->rnfr)
            clenv->rnfr = mmstrfree(clenv->rnfr);
-       reply(clenv->fdb, 226, FALSE, "Aborted");
+       reply(clenv, 226, FALSE, "Aborted");
        if (transfer_request(REQ_STATUS, TRUE, clenv)) {
            if (msg->ongoing) {
                if (!transfer_request(REQ_ABORT, TRUE, clenv))
@@ -1819,7 +1806,7 @@ main_abor(clientenv *clenv)
        } else
            DEBUG_PRINTF("main_abor", "transfer_request(REQ_STATUS)");
     } else {
-       reply(clenv->fdb, 550, FALSE, "Command syntax error");
+       reply(clenv, 550, FALSE, "Command syntax error");
        REGISTER_ERROR();
     }
 
@@ -1830,7 +1817,6 @@ main_abor(clientenv *clenv)
 static int
 main_dele(clientenv *clenv)
 {
-    fdbuf *fdb = clenv->fdb;
     char path[MMPATH_MAX];
     register int i, t;
     long fsize;
@@ -1847,23 +1833,23 @@ main_dele(clientenv *clenv)
                        treesize_edit(clenv, -fsize);
                    else
                        treesize_edit(clenv, -clenv->minfilesize);
-                   reply(fdb, 250, FALSE, "Command successful");
+                   reply(clenv, 250, FALSE, "Command successful");
                } else {
-                   reply(fdb, 521, FALSE, "Error deleting file");
+                   reply(clenv, 521, FALSE, "Error deleting file");
                    REGISTER_ERROR();
                    mmsyslog(0, LOGLEVEL, "%08X main_dele() - unlink(%s)",
                            clenv->id, path);
                }
            } else {
-               reply(fdb, 550, FALSE, "No such file or directory");
+               reply(clenv, 550, FALSE, "No such file or directory");
                REGISTER_ERROR();
            }
        } else {
-           reply(fdb, 550, FALSE, "Command syntax error");
+           reply(clenv, 550, FALSE, "Command syntax error");
            REGISTER_ERROR();
        }
     } else {
-       reply(fdb, 502, FALSE, "Permission denied");
+       reply(clenv, 502, FALSE, "Permission denied");
        REGISTER_PERMISSION();
        REGISTER_ERROR();
     }
@@ -1875,7 +1861,6 @@ main_dele(clientenv *clenv)
 static int
 main_rmd(clientenv *clenv)
 {
-    fdbuf *fdb = clenv->fdb;
     char path[MMPATH_MAX];
 
     if (clenv->modify) {
@@ -1885,24 +1870,24 @@ main_rmd(clientenv *clenv)
                    MMPATH_DIR) {
                if (!(rmdir(path))) {
                    treesize_edit(clenv, -clenv->minfilesize);
-                   reply(fdb, 250, FALSE, "Command successful");
+                   reply(clenv, 250, FALSE, "Command successful");
                } else {
-                   reply(fdb, 521, FALSE,
+                   reply(clenv, 521, FALSE,
                                "Error deleting directory (not empty?)");
                    REGISTER_ERROR();
                    mmsyslog(0, LOGLEVEL, "%08X main_rmd() - rmdir(%s)",
                            clenv->id, path);
                }
            } else {
-               reply(fdb, 550, FALSE, "No such file or directory");
+               reply(clenv, 550, FALSE, "No such file or directory");
                REGISTER_ERROR();
            }
        } else {
-           reply(fdb, 550, FALSE, "No such file or directory");
+           reply(clenv, 550, FALSE, "No such file or directory");
            REGISTER_ERROR();
        }
     } else {
-       reply(fdb, 502, FALSE, "Permission denied");
+       reply(clenv, 502, FALSE, "Permission denied");
        REGISTER_PERMISSION();
        REGISTER_ERROR();
     }
@@ -1914,7 +1899,6 @@ main_rmd(clientenv *clenv)
 static int
 main_mdtm(clientenv *clenv)
 {
-    fdbuf *fdb = clenv->fdb;
     char path[MMPATH_MAX], timebuf[16];
     register int t;
 
@@ -1923,17 +1907,17 @@ main_mdtm(clientenv *clenv)
        if ((t = path_exists(path, NULL, timebuf, clenv->checkowner)) !=
                MMPATH_NONE && t != MMPATH_DENIED) {
            if (t == MMPATH_FILE)
-               reply(fdb, 213, FALSE, timebuf);
+               reply(clenv, 213, FALSE, timebuf);
            else {
-               reply(fdb, 550, FALSE, "Not a regular file");
+               reply(clenv, 550, FALSE, "Not a regular file");
                REGISTER_ERROR();
            }
        } else {
-           reply(fdb, 550, FALSE, "No such file or directory");
+           reply(clenv, 550, FALSE, "No such file or directory");
            REGISTER_ERROR();
        }
     } else {
-       reply(fdb, 550, FALSE, "No such file or directory");
+       reply(clenv, 550, FALSE, "No such file or directory");
        REGISTER_ERROR();
     }
 
@@ -1947,9 +1931,9 @@ main_pwd(clientenv *clenv)
     char *args[2];
 
     if ((mm_straspl(args, clenv->buffer, 1)) == 1)
-       reply(clenv->fdb, 257, FALSE, "\"%s\"", clenv->cwd);
+       reply(clenv, 257, FALSE, "\"%s\"", clenv->cwd);
     else {
-       reply(clenv->fdb, 550, FALSE, "Command syntax error");
+       reply(clenv, 550, FALSE, "Command syntax error");
        REGISTER_ERROR();
     }
 
@@ -1960,7 +1944,6 @@ main_pwd(clientenv *clenv)
 static int
 main_mkd(clientenv *clenv)
 {
-    fdbuf *fdb = clenv->fdb;
     char path[MMPATH_MAX];
     mode_t mode;
 
@@ -1976,27 +1959,27 @@ main_mkd(clientenv *clenv)
                    if ((mkdir(path, mode)) != -1) {
                        if ((lchown(path, -1, clenv->gid)) == -1)
                            DEBUG_PRINTF("main_mkd", "lchown(%s)", path);
-                       reply(fdb, 250, FALSE, "Command successful");
+                       reply(clenv, 250, FALSE, "Command successful");
                    } else {
-                       reply(fdb, 521, FALSE, "Error creating directory");
+                       reply(clenv, 521, FALSE, "Error creating directory");
                        REGISTER_ERROR();
                        DEBUG_PRINTF("main_mkd", "mkdir(%s)", path);
                    }
                } else {
-                   reply(fdb, 502, FALSE, "Quota exceeded");
+                   reply(clenv, 502, FALSE, "Quota exceeded");
                    REGISTER_ERROR();
                    mmsyslog(0, LOGLEVEL, "%08X Quota exceeded", clenv->id);
                }
            } else {
-               reply(fdb, 550, FALSE, "File exists");
+               reply(clenv, 550, FALSE, "File exists");
                REGISTER_ERROR();
            }
        } else {
-           reply(fdb, 550, FALSE, "Command syntax error");
+           reply(clenv, 550, FALSE, "Command syntax error");
            REGISTER_ERROR();
        }
     } else {
-       reply(fdb, 502, FALSE, "Permission denied");
+       reply(clenv, 502, FALSE, "Permission denied");
        REGISTER_PERMISSION();
        REGISTER_ERROR();
     }
@@ -2008,7 +1991,6 @@ main_mkd(clientenv *clenv)
 static int
 main_list(clientenv *clenv)
 {
-    fdbuf *fdb = clenv->fdb;
     transfermsg *msg = &(clenv->tmsg);
     char path[MMPATH_MAX];
 
@@ -2039,15 +2021,15 @@ main_list(clientenv *clenv)
                    DEBUG_PRINTF("main_list",
                            "transfer_request(REQ_TRANSFER)");
            } else {
-               reply(fdb, 425, FALSE, "Transfer already ongoing");
+               reply(clenv, 425, FALSE, "Transfer already ongoing");
                REGISTER_ERROR();
            }
        } else {
-           reply(fdb, 425, FALSE, "Can't establish data connection");
+           reply(clenv, 425, FALSE, "Can't establish data connection");
            REGISTER_ERROR();
        }
     } else {
-       reply(fdb, 425, FALSE, "Error");
+       reply(clenv, 425, FALSE, "Error");
        REGISTER_ERROR();
        DEBUG_PRINTF("main_list", "transfer_request(REQ_STATUS)");
     }
@@ -2059,7 +2041,6 @@ main_list(clientenv *clenv)
 static int
 main_nlst(clientenv *clenv)
 {
-    fdbuf *fdb = clenv->fdb;
     transfermsg *msg = &(clenv->tmsg);
     char path[MMPATH_MAX];
 
@@ -2088,15 +2069,15 @@ main_nlst(clientenv *clenv)
                    DEBUG_PRINTF("main_nlst",
                            "transfer_request(REQ_TRANSFER)");
            } else {
-               reply(fdb, 425, FALSE, "Transfer already ongoing");
+               reply(clenv, 425, FALSE, "Transfer already ongoing");
                REGISTER_ERROR();
            }
        } else {
-           reply(fdb, 425, FALSE, "Can't establish data connection");
+           reply(clenv, 425, FALSE, "Can't establish data connection");
            REGISTER_ERROR();
        }
     } else {
-       reply(fdb, 425, FALSE, "Error");
+       reply(clenv, 425, FALSE, "Error");
        REGISTER_ERROR();
        DEBUG_PRINTF("main_nlst", "transfer_request(REQ_STATUS)");
     }
@@ -2109,7 +2090,6 @@ static int
 main_site(clientenv *clenv)
 {
     int i;
-    fdbuf *fdb = clenv->fdb;
     char *args[5], path[MMPATH_MAX];
     mode_t mode;
 
@@ -2117,20 +2097,20 @@ main_site(clientenv *clenv)
        if (!(mm_strcasecmp(args[1], "UMASK"))) {
            if (clenv->modify && clenv->mumask) {
                if (i == 2)
-                   reply(fdb, 200, FALSE, "Current UMASK is %04o",
+                   reply(clenv, 200, FALSE, "Current UMASK is %04o",
                            clenv->umask);
                else if (i == 3) {
                    sscanf(args[2], "%o", &clenv->umask);
                    if (clenv->umask > 07000) clenv->umask = 0;
                    clenv->umask &= ~0700;
                    clenv->umask |= 07000;
-                   reply(fdb, 200, FALSE, "UMASK set to %04o", clenv->umask);
+                   reply(clenv, 200, FALSE, "UMASK set to %04o", clenv->umask);
                } else {
-                   reply(fdb, 550, FALSE, "Command syntax error");
+                   reply(clenv, 550, FALSE, "Command syntax error");
                    REGISTER_ERROR();
                }
            } else {
-               reply(fdb, 502, FALSE, "Permission denied");
+               reply(clenv, 502, FALSE, "Permission denied");
                REGISTER_PERMISSION();
                REGISTER_ERROR();
            }
@@ -2167,34 +2147,34 @@ main_site(clientenv *clenv)
                                        "%08X main_site() - lchmod(%s)",
                                        path);
 #endif
-                           reply(fdb, 200, FALSE,
+                           reply(clenv, 200, FALSE,
                                        "CHMOD %04o command successful",
                                        mode);
                        } else {
-                           reply(fdb, 550, FALSE,
+                           reply(clenv, 550, FALSE,
                                    "No such file or directory");
                            REGISTER_ERROR();
                        }
                    } else {
-                       reply(fdb, 550, FALSE,
+                       reply(clenv, 550, FALSE,
                                    "No such file or directory");
                        REGISTER_ERROR();
                    }
                } else {
-                   reply(fdb, 550, FALSE, "Command syntax error");
+                   reply(clenv, 550, FALSE, "Command syntax error");
                    REGISTER_ERROR();
                }
            } else {
-               reply(fdb, 502, FALSE, "Permission denied");
+               reply(clenv, 502, FALSE, "Permission denied");
                REGISTER_PERMISSION();
                REGISTER_ERROR();
            }
        } else {
-           reply(fdb, 500, FALSE, "Unknown command");
+           reply(clenv, 500, FALSE, "Unknown command");
            REGISTER_ERROR();
        }
     } else {
-       reply(fdb, 500, FALSE, "Unknown command");
+       reply(clenv, 500, FALSE, "Unknown command");
        REGISTER_ERROR();
     }
 
@@ -2205,7 +2185,6 @@ main_site(clientenv *clenv)
 static int
 main_size(clientenv *clenv)
 {
-    fdbuf *fdb = clenv->fdb;
     char path[MMPATH_MAX];
     register int t;
     long size;
@@ -2216,17 +2195,17 @@ main_size(clientenv *clenv)
                MMPATH_NONE
                && t != MMPATH_DENIED) {
            if (t == MMPATH_FILE)
-               reply(fdb, 213, FALSE, "%ld", size);
+               reply(clenv, 213, FALSE, "%ld", size);
            else {
-               reply(fdb, 550, FALSE, "Not a regular file");
+               reply(clenv, 550, FALSE, "Not a regular file");
                REGISTER_ERROR();
            }
        } else {
-           reply(fdb, 550, FALSE, "No such file or directory");
+           reply(clenv, 550, FALSE, "No such file or directory");
            REGISTER_ERROR();
        }
     } else {
-       reply(fdb, 550, FALSE, "No such file or directory");
+       reply(clenv, 550, FALSE, "No such file or directory");
        REGISTER_ERROR();
     }
 
@@ -2237,9 +2216,9 @@ main_size(clientenv *clenv)
 static int
 main_stat(clientenv *clenv)
 {
-    fdbuf *fdb = clenv->fdb;
     char path[MMPATH_MAX], cpath[MMPATH_MAX], *str;
     transfermsg *msg = &(clenv->tmsg);
+    fdbuf *fdb = clenv->fdb;
 
     if (path_valid(path, cpath, clenv->home, clenv->cwd, &clenv->buffer[4],
                TRUE, FALSE, FALSE)) {
@@ -2249,21 +2228,21 @@ main_stat(clientenv *clenv)
 
        i = path_exists(path, NULL, NULL, clenv->checkowner);
        if (i == MMPATH_FILE || i == MMPATH_DIR) {
-           reply(fdb, 211, TRUE, "Status of '%s':", cpath);
+           reply(clenv, 211, TRUE, "Status of '%s':", cpath);
            if (clenv->checkowner)
                flags |= MMLS_OWNERONLY;
            if (!(clenv->modify || clenv->upload))
                flags |= MMLS_READONLY;
            if (!path_ls(fdb, path, clenv->user, clenv->group, flags))
                DEBUG_PRINTF("main_stat", "path_ls(%s)", path);
-           reply(fdb, 211, FALSE, "End of status information");
+           reply(clenv, 211, FALSE, "End of status information");
        } else {
-           reply(clenv->fdb, 550, FALSE, "No such file or directory");
+           reply(clenv, 550, FALSE, "No such file or directory");
            REGISTER_ERROR();
        }
     } else {
        /* Normal ftpd status report */
-       reply(fdb, 211, TRUE, "FTP server status:");
+       reply(clenv, 211, TRUE, "FTP server status:");
        fdbprintf(fdb, "    Version: %s (%s)\r\n", DAEMON_NAME,
                DAEMON_VERSION);
        if (clenv->c_hostname)
@@ -2368,7 +2347,7 @@ main_stat(clientenv *clenv)
            return (STATE_ERROR);
 
        fdbprintf(fdb, "\r\n    Umask: %04o\r\n", clenv->umask);
-       reply(fdb, 211, FALSE, "End of status information");
+       reply(clenv, 211, FALSE, "End of status information");
     }
 
     return (STATE_CURRENT);
@@ -2738,7 +2717,7 @@ commandnode_keycmp(const void *src, const void *dst, size_t len)
  * fdbgets().
  */
 static bool
-reply(fdbuf *fdb, int code, bool cont, char *fmt, ...)
+reply(clientenv *clenv, int code, bool cont, const char *fmt, ...)
 {
     char buf[1024];
     va_list arg_ptr;
@@ -2751,10 +2730,9 @@ reply(fdbuf *fdb, int code, bool cont, char *fmt, ...)
        va_start(arg_ptr, fmt);
        vsnprintf(&buf[4], 1018, fmt, arg_ptr);
        va_end(arg_ptr);
-       if (!fdbprintf(fdb, "%s\r\n", buf)) ok = FALSE;
-       /* XXX Should be able to show the clenv->id */
-       mmsyslog(3, LOGLEVEL, "> %s", buf);
-    } else if (!fdbprintf(fdb, "%s\r\n", buf))
+       if (!fdbprintf(clenv->fdb, "%s\r\n", buf)) ok = FALSE;
+       mmsyslog(3, LOGLEVEL, "%08X > %s", clenv->id, buf);
+    } else if (!fdbprintf(clenv->fdb, "%s\r\n", buf))
        ok = FALSE;
 
     return (ok);
@@ -3260,7 +3238,7 @@ directory_message(clientenv *clenv, int code)
            FIFO_FIND(&clenv->visited, &ptr, &dhash);
            if (ptr == NULL) {
                /* This directory was not visited recently, send out file */
-               if (!reply(clenv->fdb, code, TRUE, NULL))
+               if (!reply(clenv, code, TRUE, NULL))
                    res = FALSE;
                file_out(clenv->fdb, path);
            }
@@ -3611,14 +3589,14 @@ handleclient(unsigned long cid, int fd, clientlistnode *clientlnode,
                    msg = &(clenv->tmsg);
 
                    if (*CONF.WELCOME_FILE) {
-                       reply(fdb, 220, TRUE, NULL);
+                       reply(clenv, 220, TRUE, NULL);
                        if (!file_out(fdb, CONF.WELCOME_FILE))
                            mmsyslog(0, LOGLEVEL,
                                    "%08X Error opening WELCOME_FILE \"%s\"",
                                    clenv->id, CONF.WELCOME_FILE);
                    }
 
-                   reply(fdb, 220, FALSE, "%s FTP server (%s (%s)) ready",
+                   reply(clenv, 220, FALSE, "%s FTP server (%s (%s)) ready",
                            iface->hostname, DAEMON_NAME, DAEMON_VERSION);
                    state = STATE_AUTH;
                    dstatus = MMS_NORMAL;
@@ -3634,7 +3612,7 @@ handleclient(unsigned long cid, int fd, clientlistnode *clientlnode,
 
                            /* If there were too many errors, exit */
                            if (clenv->errors > CONF.MAX_ERRORS) {
-                               reply(fdb, 421, FALSE, "Too many errors");
+                               reply(clenv, 421, FALSE, "Too many errors");
                                dstatus = MMS_MANY_ERRORS;
                                break;
                            }
@@ -3672,7 +3650,7 @@ handleclient(unsigned long cid, int fd, clientlistnode *clientlnode,
                                } else {
                                    /* Unimplemented command for this state */
                                    REGISTER_ERROR();
-                                   if (!reply(fdb, states[state].errcode,
+                                   if (!reply(clenv, states[state].errcode,
                                                FALSE, states[state].errtext))
                                        break;
                                }
@@ -3681,7 +3659,8 @@ handleclient(unsigned long cid, int fd, clientlistnode *clientlnode,
                                mmsyslog(3, LOGLEVEL, "%08X < %s", cid,
                                        buffer);
                                REGISTER_ERROR();
-                               if (!reply(fdb, 500, FALSE, "Unknown command"))
+                               if (!reply(clenv, 500, FALSE,
+                                           "Unknown command"))
                                    break;
                            }
 
@@ -4223,7 +4202,7 @@ transferthread_main(clientenv *clenv, fdbuf *fdb)
                            mmsyslog(1, LOGLEVEL,
                                    "%08X PORT data connection failure",
                                    clenv->id);
-                           reply(clenv->fdb, 425, FALSE,
+                           reply(clenv, 425, FALSE,
                                    "Can't establish data connection");
                            fdbflushw(clenv->fdb);
                            REGISTER_ERROR();
@@ -4238,7 +4217,7 @@ transferthread_main(clientenv *clenv, fdbuf *fdb)
                            err = 0;
                    } else {
                        DEBUG_PRINTF("transferthread_main-2", "socket()");
-                       reply(clenv->fdb, 425, FALSE,
+                       reply(clenv, 425, FALSE,
                                "Can't establish data connection");
                        fdbflushw(clenv->fdb);
                        REGISTER_ERROR();
@@ -4250,7 +4229,7 @@ transferthread_main(clientenv *clenv, fdbuf *fdb)
                if (err == ETIMEDOUT) {
                    mmsyslog(1, LOGLEVEL, "%08X Data connection timeout",
                            clenv->id);
-                   reply(clenv->fdb, 425, FALSE,
+                   reply(clenv, 425, FALSE,
                            "Can't establish data connection");
                    fdbflushw(clenv->fdb);
                    REGISTER_ERROR();
@@ -4342,7 +4321,7 @@ transferthread_main(clientenv *clenv, fdbuf *fdb)
                    int flags = MMLS_GLOB;
 
                    shutdown(fd, SHUT_RD);
-                   reply(clenv->fdb, 150, FALSE,
+                   reply(clenv, 150, FALSE,
                          "Opening ASCII mode data connection for '/bin/ls'");
                    fdbflushw(clenv->fdb);
                    /* List request, simply send the data to the connected
@@ -4370,11 +4349,11 @@ transferthread_main(clientenv *clenv, fdbuf *fdb)
                 * direction
                 */
                if (clenv->type == TYPE_ASCII)
-                   reply(clenv->fdb, 150, FALSE,
+                   reply(clenv, 150, FALSE,
                            "Opening ASCII mode data connection for '%s'",
                            path);
                else
-                   reply(clenv->fdb, 150, FALSE,
+                   reply(clenv, 150, FALSE,
                            "Opening BINARY mode data connection for '%s'",
                            path);
                fdbflushw(clenv->fdb);
@@ -4640,8 +4619,7 @@ transferthread_main(clientenv *clenv, fdbuf *fdb)
            }
 
            /* State exit cleanup */
-           reply(clenv->fdb, tr_msg[-reason].code, FALSE,
-                   tr_msg[-reason].msg);
+           reply(clenv, tr_msg[-reason].code, FALSE, tr_msg[-reason].msg);
            fdbflushw(clenv->fdb);
            /* State 1's setup will ensure to close the fds */
 
index 1b215fc..ac47628 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: mmftpd.h,v 1.34 2009/07/23 18:04:59 mmondor Exp $ */
+/* $Id: mmftpd.h,v 1.35 2011/02/08 00:54:41 mmondor Exp $ */
 
 /*
  * Copyright (C) 2001-2008, Matthew Mondor
@@ -69,7 +69,7 @@
 /* DEFINITIONS */
 
 #define DAEMON_NAME            "mmftpd"
-#define DAEMON_VERSION         "0.3.1"
+#define DAEMON_VERSION         "0.3.2"
 
 /* Transfer buffer size */
 #define T_BUFSIZE              16384
@@ -403,7 +403,7 @@ int main(int, char **);
 static bool hash_commands(struct command *, size_t);
 static uint32_t commandnode_keyhash(const void *, size_t);
 static int commandnode_keycmp(const void *, const void *, size_t);
-static bool reply(fdbuf *, int, bool, char *, ...);
+static bool reply(clientenv *, int, bool, const char *, ...);
 static int readconfline(char *, fdbuf *, int, int, char **);
 static void stripoptions(char *);
 static off_t recursive_treesize(char *, off_t);