summaryrefslogtreecommitdiffstats
path: root/rtemsbsd/ftpd/ftpd.c
diff options
context:
space:
mode:
Diffstat (limited to 'rtemsbsd/ftpd/ftpd.c')
-rw-r--r--rtemsbsd/ftpd/ftpd.c81
1 files changed, 45 insertions, 36 deletions
diff --git a/rtemsbsd/ftpd/ftpd.c b/rtemsbsd/ftpd/ftpd.c
index fddc03e6..0f1577e1 100644
--- a/rtemsbsd/ftpd/ftpd.c
+++ b/rtemsbsd/ftpd/ftpd.c
@@ -13,18 +13,18 @@
* Changed by: Sergei Organov <osv@javad.ru> (OSV)
* Arnout Vandecappelle <arnout@mind.be> (AV)
* Sebastien Bourdeauducq <sebastien@milkymist.org> (MM)
- *
+ *
*
* Changes:
*
* 2010-12-02 Sebastien Bourdeauducq <sebastien@milkymist.org>
*
* * Support spaces in filenames
- *
+ *
* 2010-04-29 Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
- *
+ *
* * Added USER/PASS authentication.
- *
+ *
* 2001-01-31 Sergei Organov <osv@javad.ru>
*
* * Hacks with current dir and root dir removed in favor of new libio
@@ -244,7 +244,7 @@ enum
};
/* Configuration table */
-extern struct rtems_ftpd_configuration rtems_ftpd_configuration;
+static struct rtems_ftpd_configuration* ftpd_config;
/* this is not prototyped in strict ansi mode */
FILE *fdopen (int fildes, const char *mode);
@@ -953,7 +953,7 @@ command_store(FTPD_SessionInfo_t *info, char const *filename)
wrt = &discard;
}
- if (!null && rtems_ftpd_configuration.hooks != NULL)
+ if (!null && ftpd_config->hooks != NULL)
{
/* Search our list of hooks to see if we need to do something special. */
@@ -961,7 +961,7 @@ command_store(FTPD_SessionInfo_t *info, char const *filename)
int i;
i = 0;
- hook = &rtems_ftpd_configuration.hooks[i++];
+ hook = &ftpd_config->hooks[i++];
while (hook->filename != NULL)
{
if (!strcmp(hook->filename, filename))
@@ -969,7 +969,7 @@ command_store(FTPD_SessionInfo_t *info, char const *filename)
usehook = hook;
break;
}
- hook = &rtems_ftpd_configuration.hooks[i++];
+ hook = &ftpd_config->hooks[i++];
}
}
@@ -982,8 +982,8 @@ command_store(FTPD_SessionInfo_t *info, char const *filename)
* given name.
*/
- char *bigBufr;
- size_t filesize = rtems_ftpd_configuration.max_hook_filesize + 1;
+ char *bigBufr;
+ size_t filesize = ftpd_config->max_hook_filesize + 1;
/*
* Allocate space for our "file".
@@ -1766,8 +1766,8 @@ exec_command(FTPD_SessionInfo_t *info, char* cmd, char* args)
free(info->pass);
info->pass = NULL;
info->user = strdup(fname);
- if (rtems_ftpd_configuration.login &&
- !rtems_ftpd_configuration.login(info->user, NULL)) {
+ if (ftpd_config->login &&
+ !ftpd_config->login(info->user, NULL)) {
info->auth = false;
send_reply(info, 331, "User name okay, need password.");
} else {
@@ -1784,8 +1784,8 @@ exec_command(FTPD_SessionInfo_t *info, char* cmd, char* args)
if (!info->user) {
send_reply(info, 332, "Need account to log in");
} else {
- if (rtems_ftpd_configuration.login &&
- !rtems_ftpd_configuration.login(info->user, info->pass)) {
+ if (ftpd_config->login &&
+ !ftpd_config->login(info->user, info->pass)) {
info->auth = false;
send_reply(info, 530, "Not logged in.");
} else {
@@ -1826,7 +1826,7 @@ exec_command(FTPD_SessionInfo_t *info, char* cmd, char* args)
else {
char *c;
c = strchr(args, ' ');
- if((c != NULL) && (sscanf(args, "%o", &mask) == 1) && strncpy(fname, c+1, 254)
+ if((c != NULL) && (sscanf(args, "%o", &mask) == 1) && strncpy(fname, c+1, 254)
&& (chmod(fname, (mode_t)mask) == 0))
send_reply(info, 257, "CHMOD successful.");
else
@@ -2009,7 +2009,7 @@ ftpd_daemon(rtems_task_argument args __attribute__((unused)))
syslog(LOG_ERR, "ftpd: Error creating socket: %s", serr());
addr.sin_family = AF_INET;
- addr.sin_port = htons(rtems_ftpd_configuration.port);
+ addr.sin_port = htons(ftpd_config->port);
addr.sin_addr.s_addr = htonl(INADDR_ANY);
memset(addr.sin_zero, 0, sizeof(addr.sin_zero));
@@ -2064,7 +2064,7 @@ ftpd_daemon(rtems_task_argument args __attribute__((unused)))
info->idle = ftpd_timeout;
info->user = NULL;
info->pass = NULL;
- if (rtems_ftpd_configuration.login)
+ if (ftpd_config->login)
info->auth = false;
else
info->auth = true;
@@ -2088,46 +2088,54 @@ ftpd_daemon(rtems_task_argument args __attribute__((unused)))
*
*
* Input parameters:
- *
+ * config: constant initial setup.
* Output parameters:
* returns RTEMS_SUCCESSFUL on successful start of the daemon.
*/
int
-rtems_initialize_ftpd(void)
+rtems_ftpd_start(const struct rtems_ftpd_configuration* config)
{
rtems_status_code sc;
rtems_id tid;
rtems_task_priority priority;
int count;
- if (rtems_ftpd_configuration.port == 0)
+ if (ftpd_config != NULL)
+ return RTEMS_RESOURCE_IN_USE;
+
+ ftpd_config = malloc(sizeof(*ftpd_config));
+ if (ftpd_config == NULL)
+ return RTEMS_NO_MEMORY;
+
+ *ftpd_config = *config;
+
+ if (ftpd_config->port == 0)
{
- rtems_ftpd_configuration.port = FTPD_CONTROL_PORT;
+ ftpd_config->port = FTPD_CONTROL_PORT;
}
- if (rtems_ftpd_configuration.priority == 0)
+ if (ftpd_config->priority == 0)
{
- rtems_ftpd_configuration.priority = 40;
+ ftpd_config->priority = 40;
}
- priority = rtems_ftpd_configuration.priority;
+ priority = ftpd_config->priority;
- ftpd_timeout = rtems_ftpd_configuration.idle;
+ ftpd_timeout = ftpd_config->idle;
if (ftpd_timeout < 0)
ftpd_timeout = 0;
- rtems_ftpd_configuration.idle = ftpd_timeout;
+ ftpd_config->idle = ftpd_timeout;
- ftpd_access = rtems_ftpd_configuration.access;
+ ftpd_access = ftpd_config->access;
ftpd_root = "/";
- if ( rtems_ftpd_configuration.root &&
- rtems_ftpd_configuration.root[0] == '/' )
- ftpd_root = rtems_ftpd_configuration.root;
+ if (ftpd_config->root && ftpd_config->root[0] == '/' )
+ ftpd_root = ftpd_config->root;
- rtems_ftpd_configuration.root = ftpd_root;
+ ftpd_config->root = ftpd_root;
- if (rtems_ftpd_configuration.tasks_count <= 0)
- rtems_ftpd_configuration.tasks_count = 1;
- count = rtems_ftpd_configuration.tasks_count;
+ if (ftpd_config->tasks_count <= 0)
+ ftpd_config->tasks_count = 1;
+ count = ftpd_config->tasks_count;
if (!task_pool_init(count, priority))
{
@@ -2157,8 +2165,9 @@ rtems_initialize_ftpd(void)
return RTEMS_UNSATISFIED;
}
- syslog(LOG_INFO, "ftpd: FTP daemon started (%d session%s max)",
- count, ((count > 1) ? "s" : ""));
+ if (ftpd_config->verbose)
+ syslog(LOG_INFO, "ftpd: FTP daemon started (%d session%s max)",
+ count, ((count > 1) ? "s" : ""));
return RTEMS_SUCCESSFUL;
}