[uClinux-dev] FTPD compiling problems

Heiko Degenhardt heiko.degenhardt at sentec-elektronik.de
Wed Mar 26 10:23:46 EST 2003


Hi Rene, 

* On Mon, Mar 24, 2003 at 10:48:37AM +0100, Rene Gegusch wrote:
> Does someone ever made it to compile the ftpd and/or does anyone
> has any help for me to solve this problem(s) easily.  NEED URGENT
> HELP

sorry, this help isn't really "urgent". ;)

But:
Please find attached a small patch I prepared to get the ftpd
working on a M5249 board. To apply it you should:

- Use the original source of uClinux-dist-20030305
- Copy the patch into the user/ directory:
  cp ftpd-20030305-v20030326.diff uClinux-dist/user
- Clean up the user/ftpd tree (just to be shure):
  cd uClinux-dist
  make -C user/ftpd clean
- Change to the original source and patch it:
  cd user/ftpd
  patch -p1 < ../ftpd-20030305-v20030326.diff
  (You should only see lines with "patching file...", no
  errors or rejects).
- Change to the toplevel and make the user tree:
  cd ..
  cd ..
  make user_only 2>&1 |tee errs-user
  (this "tee..." stuff logs the messages in a file errs-user
  so you can look for problems there)
- This should compile the ftpd

You will also need the following:
- A line "ftp  stream tcp nowait root /bin/ftpd -l" in your
  /etc/inetd.conf
  (I currently start the ftpd from inetd. If you don't want
  that, you don't need that entry. You can also start
  ftpd later from the command line with "/bin/ftpd -D")
- A file /etc/passwd with the user name. My entry is for instance:
  hede:wn8evjj9EZ.4.:0:0:Web User:/:/bin/sh
  (For the hackers here: The password is "Test". And yes, it
  is another one as for my home banking stuff. ;))
  I copied one example passwd from an vendors dir and modified it.
  The password entry has to be created using "crypt". I used the
  tool htpasswd to encrypt the password.
- I also created a file /etc/ftpusers that lists the users that
  are not allowed to use ftp
- I created a small textfile /etc/ftpwelcome with a welcome message
- I included the busybox syslog and busybox ls in the image, too

How you create this files depends on your preferences.
I created them under the vendors dir so that they are not
overwritten during "make romfs".

Create the image, download it, and try it out.
If everything goes well you should see something as:
...
hede at sentec09:~$ ftp 192.168.100.2
Connected to 192.168.100.2.
220- 
220- Welcome to the uClinux ftpd!
220- 
220 uClinux FTP server (GNU inetutils 1.4.1) ready.
Name (192.168.100.2:hede): hede
331 Password required for hede.
Password:
230- Welcome to
230-           ____ _  _
230-          /  __| ||_|                 
230-     _   _| |  | | _ ____  _   _  _  _ 
230-    | | | | |  | || |  _ \| | | |\ \/ /
230-    | |_| | |__| || | | | | |_| |/    \
230-    |  ___\____|_||_|_| |_|\____|\_/\_/
230-    | |
230-    |_|
230- 
230- For further information check:
230- http://www.uclinux.org/
230- 
230 User hede logged in.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> 
...
HINT: The "ls" command in ftp only seems to work if
you are in an writable directory! "get", "put", "cd",
"pwd", "lcd" etc. worked for me.

ATTENTION!
This is a really ugly patch and nothing that could be used
for reference! It _has_ to be checked by some uClinux gurus.
I only did everything to get it working so far here, but
there definitely are very much things to be tested/solved!
May be I did something completely wrong, so please use it
on your own risk!

I send it just to get you starting with that stuff.

Rgds.
Heiko.

-------------- next part --------------
diff -Naur ftpd-orig/Makefile ftpd/Makefile
--- ftpd-orig/Makefile	Tue Mar  4 15:56:37 2003
+++ ftpd/Makefile	Wed Mar 26 09:32:32 2003
@@ -7,13 +7,15 @@
 CFLAGS += -DPATH_FTPLOGINMESG=\"/etc/motd\"
 CFLAGS += -DPATH_FTPUSERS=\"/etc/ftpusers\"
 CFLAGS += -DPATH_BSHELL=\"/bin/sh\"
-CFLAGS += -DPATH_FTPCHROOT=\"/usr/sbin/chroot\"
+#CFLAGS += -DPATH_FTPCHROOT=\"/usr/sbin/chroot\"
 CFLAGS += -DPATH_FTPDPID=\"/var/run/ftpd.pid\"
 CFLAGS += -DPATH_DEVNULL=\"/dev/null\"
-CFLAGS += -DPATH_NOLOGIN=\"/etc/nologin\"
-CFLAGS += -DPATH_WTMP=\"/etc/wtmp\"
+#CFLAGS += -DPATH_NOLOGIN=\"/etc/nologin\"
+#CFLAGS += -DPATH_WTMP=\"/etc/wtmp\"
 
 CFLAGS += -DKEEP_OPEN=1
+
+#CFLAGS += -DDEBUG=1
 
 EXTRALIBS = $(LIBCRYPT)
 
diff -Naur ftpd-orig/auth.c ftpd/auth.c
--- ftpd-orig/auth.c	Tue Mar  4 15:56:37 2003
+++ ftpd/auth.c	Wed Mar 26 13:43:09 2003
@@ -115,8 +115,10 @@
 	  }
 	else
 	  return 1;
+#ifdef PATH_FTPCHROOT
 	pcred->dochroot = checkuser(PATH_FTPCHROOT, pcred->name);
-	snprintf (pcred->message, len,
+#endif
+   snprintf (pcred->message, len,
 		  "Password required for %s.", pcred->name);
 	return 0;
       }
@@ -153,7 +155,7 @@
 	/* Try to authenticate the user.  */
 	if (pcred->passwd == NULL || *pcred->passwd == '\0')
 	  return 1; /* Failed. */
-	xpasswd = CRYPT (passwd, salt);
+	xpasswd = crypt(passwd, salt);
 	return  (!xpasswd || strcmp (xpasswd, pcred->passwd) != 0);
       }
     } /* switch (auth_type) */
diff -Naur ftpd-orig/config.h ftpd/config.h
--- ftpd-orig/config.h	Tue Mar  4 15:56:37 2003
+++ ftpd/config.h	Wed Mar 26 13:39:15 2003
@@ -63,7 +63,7 @@
 
 /* Define to 1 if you have the declaration of `crypt', and to 0 if you don't.
    */
-#define HAVE_DECL_CRYPT 0
+#define HAVE_DECL_CRYPT 1
 
 /* Define to 1 if you have the declaration of `environ', and to 0 if you
    don't. */
@@ -156,10 +156,12 @@
 #define HAVE_FLOCK 1
 
 /* Define to 1 if you have the `fork' function. */
-#define HAVE_FORK 1
+/*#define HAVE_FORK 1*/
+#undef HAVE_FORK
 
 /* Define to 1 if you have the `forkpty' function. */
-#define HAVE_FORKPTY 1
+/*#define HAVE_FORKPTY 1*/
+#undef HAVE_FORKPTY
 
 /* Define to 1 if you have the `fpathconf' function. */
 #define HAVE_FPATHCONF 1
@@ -180,7 +182,8 @@
 #define HAVE_GETPASS 1
 
 /* Define to 1 if you have the `getspnam' function. */
-#define HAVE_GETSPNAM 1
+/* #define HAVE_GETSPNAM 1 */
+#undef HAVE_GETSPNAM
 
 /* Define to 1 if you have the `getusershell' function. */
 #define HAVE_GETUSERSHELL 1
@@ -597,7 +600,8 @@
 #define HAVE_WEAK_REFS 1
 
 /* Define to 1 if `fork' works. */
-#define HAVE_WORKING_FORK 1
+/*#define HAVE_WORKING_FORK 1*/
+#undef HAVE_WORKING_FORK
 
 /* Define to 1 if `vfork' works. */
 #define HAVE_WORKING_VFORK 1
@@ -606,7 +610,8 @@
 #define HAVE___P 1
 
 /* Define to one if you have __progname */
-#define HAVE___PROGNAME 1
+/* #define HAVE___PROGNAME 1 */
+#undef HAVE___PROGNAME
 
 /* Define to one if you have Kerberos */
 /* #undef KERBEROS */
@@ -861,3 +866,18 @@
 /* Declare our own silly version.  */
 extern void memset __P ((void *mem, int val, size_t sz));
 #endif
+
+/* Some more things I think are needed for us on uClinux */
+#ifdef DEBUG
+#define DBG(x) x
+#else
+#define DBG(x)
+#endif
+
+#ifdef __uClinux__
+#undef fork
+#define fork vfork
+#endif
+
+#undef HAVE_DAEMON
+
diff -Naur ftpd-orig/crypt.h ftpd/crypt.h
--- ftpd-orig/crypt.h	Tue Mar  4 15:56:37 2003
+++ ftpd/crypt.h	Wed Mar 26 13:13:38 2003
@@ -45,7 +45,7 @@
 
 /* Call crypt, or just return STR if there is none.  */
 #ifdef HAVE_CRYPT
-#define CRYPT(str, salt) crypt (str, salt)
+#define CRYPT(str, salt) crypt(str, salt)
 #else  /* !HAVE_CRYPT */
 #ifdef HAVE_WEAK_REFS
 #ifdef __GNUC__
diff -Naur ftpd-orig/ftpd.c ftpd/ftpd.c
--- ftpd-orig/ftpd.c	Tue Mar  4 15:56:37 2003
+++ ftpd/ftpd.c	Wed Mar 26 11:27:42 2003
@@ -133,7 +133,11 @@
 extern int fclose __P ((FILE *));
 #endif
 
-extern char *__progname;
+#ifndef HAVE___PROGNAME
+   char *__progname;  
+#else
+   extern char *__progname;
+#endif
 
 /* Exported to ftpcmd.h.  */
 struct	sockaddr_in data_dest; /* Data port.  */
@@ -447,7 +451,9 @@
   if (daemon_mode)
     {
       if (server_mode (pid_file, &his_addr) < 0)
-	exit (1);
+      {
+	      exit (1);
+      }
     }
   else
     {
diff -Naur ftpd-orig/server_mode.c ftpd/server_mode.c
--- ftpd-orig/server_mode.c	Tue Mar  4 15:56:37 2003
+++ ftpd/server_mode.c	Wed Mar 26 11:21:05 2003
@@ -83,17 +83,21 @@
   int port;
   static struct  sockaddr_in server_addr;  /* Our address.  */
 
+#ifdef HAVE_DAEMON 
   /* Become a daemon.  */
   if (daemon(1,1) < 0)
     {
       syslog (LOG_ERR, "failed to become a daemon");
       return -1;
     }
+#endif
+
   (void) signal (SIGCHLD, reapchild);
 
   /* Get port for ftp/tcp.  */
   sv = getservbyname ("ftp", "tcp");
   port = (sv == NULL) ? DEFPORT : sv->s_port;
+  DBG(printf("Got Port: %i\n", port));
 
   /* Open socket, bind and start listen.  */
   ctl_sock = socket (AF_INET, SOCK_STREAM, 0);
@@ -102,7 +106,7 @@
       syslog (LOG_ERR, "control socket: %m");
       return -1;
     }
-
+  DBG(printf("Got Socket: %i\n", ctl_sock));
   /* Enable local address reuse.  */
   {
     int on = 1;
@@ -134,6 +138,7 @@
     else
       {
 	fprintf (pid_fp, "%d\n", getpid());
+   DBG(printf("Got PID: %i\n", getpid()));
 	fchmod (fileno(pid_fp), S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
 	fclose (pid_fp);
       }
diff -Naur ftpd-orig/xmalloc.c ftpd/xmalloc.c
--- ftpd-orig/xmalloc.c	Tue Mar  4 15:56:37 2003
+++ ftpd/xmalloc.c	Tue Mar 25 16:27:18 2003
@@ -73,7 +73,9 @@
   if (n == 0)
     p = malloc ((size_t) 1);
   if (p == 0)
+    #ifndef __uClinux__
     err (xmalloc_exit_failure, _("Memory exhausted"));
+    #endif
   return p;
 }
 


More information about the uClinux-dev mailing list