Subject: static ls for Solaris 2.5

From: Udo Winkelmann <[email-masked]>
Date: Thu, 12 Dec 1996 11:53:50 +0000

Hi,
does anybody has a static compiled ls for Solaris 2.5?
Dynamic ls is much to slow...

Udo
kind regards / Mit freundlichen Gruessen
----------------------------------------------------
Udo Winkelmann
Diplom Informatiker (FH)
Dornier Satellitensysteme GmbH
Department RST 67
D-88039 Friedrichshafen, Germany
Phone  +49 7545 8 - 9770
Fax    +49 7545 8 - 3210
email  [email-masked] (preferred address)
email  [email-masked]  (not read regulary)

privat email [email-masked]
----------------------------------------------------

---

From: Webmaster <[email-masked]>
Date: Fri, 13 Dec 1996 11:44:32 -0500

> Dynamic ls is much to slow...
No such animal. SUN neglected one needed .a file (can't remember which
one) for a successful static ls to be built.

---

From: Emil Isberg <[email-masked]>
Date: Fri, 13 Dec 1996 18:04:06 +0100 (MET)

> Dynamic ls is much to slow...

get gnu fileutil 3.13 .. you can get it at
<ftp://prep.ai.mit.edu/pub/gnu/fileutils-3.13.tar.gz>

(perhaps does the patch also work for 3.14.. then it's
 <ftp://prep.ai.mit.edu/pub/gnu/fileutils-3.14.tar.gz>)

gunzip fileutils-3.13.tar.gz
tar xf fileutils-3.13.tar

patch <fileutils-3.13_static-ls.patch

################# fileutils-3.13_static-ls.patch ##############
## delete everything .. included this line
*** fileutils-3.13/src/Makefile	Fri Dec 13 17:24:37 1996
--- old/fileutils-3.13/src/Makefile	Fri Dec 13 16:18:22 1996
***************
*** 68,74 ****
  cp_SOURCES = cp.c cp-aux.c cp-hash.c
  dir_SOURCES = ls.c ls-dir.c
  vdir_SOURCES = ls.c ls-vdir.c
! ls_SOURCES = ls.c ls-ls.c
  
  BUILT_SOURCES = #M#dircolors.h
  PERL = /home/sdu/cel95eig/bin/mine/perl
--- 68,75 ----
  cp_SOURCES = cp.c cp-aux.c cp-hash.c
  dir_SOURCES = ls.c ls-dir.c
  vdir_SOURCES = ls.c ls-vdir.c
! static-ls_SOURCES = static-ls.c
! ls_SOURCES = ls.c ls-ls.c $(static-ls_SOURCES)
  
  BUILT_SOURCES = #M#dircolors.h
  PERL = /home/sdu/cel95eig/bin/mine/perl
***************
*** 87,94 ****
  LEX = @LEX@
  YACC = byacc
  CPPFLAGS = 
! CFLAGS = -g -O
! LDFLAGS = 
  LIBS = -lintl -lgen 
  
  COMPILE = $(CC) -c $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS)
--- 88,95 ----
  LEX = @LEX@
  YACC = byacc
  CPPFLAGS = 
! CFLAGS = -static -g -O
! LDFLAGS = -static
  LIBS = -lintl -lgen 
  
  COMPILE = $(CC) -c $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS)
***************
*** 136,142 ****
  vdir_OBJECTS = ls$o ls-vdir$o
  EXTRA_vdir_SOURCES =
  vdir_LDADD = $(LDADD)
! ls_OBJECTS = ls$o ls-ls$o
  EXTRA_ls_SOURCES =
  ls_LDADD = $(LDADD)
  mkdir_SOURCES = mkdir.c
--- 137,144 ----
  vdir_OBJECTS = ls$o ls-vdir$o
  EXTRA_vdir_SOURCES =
  vdir_LDADD = $(LDADD)
! static-ls_OBJECTS = static-ls$o
! ls_OBJECTS = ls$o ls-ls$o $(static-ls_OBJECTS)
  EXTRA_ls_SOURCES =
  ls_LDADD = $(LDADD)
  mkdir_SOURCES = mkdir.c
*** fileutils-3.13/src/static-ls.c	Fri Dec 13 16:13:44 1996
--- fileutils-3.13/src/static-ls.c	Fri Dec 11 15:29:46 1996
***************
*** 0 ****
--- 1,230 ----
+ /* static-ls.c rec.1, by Emil Isberg <[email-masked]> */
+ /* static-ls.c rev.2, by Brett Porter <[email-masked]>*/
+ /* static-ls.c rev.2.1, by Emil Isberg <[email-masked]> */
+ /*  for gnufileutils ..  under Solaris 2.5 */
+ /* To compile .. get the lates version of gnufileutil .. */
+ /*  add this file */
+ 
+ #include <stdio.h>
+ #include <stdlib.h>
+ #include <string.h>
+ #include <limits.h>
+ #include <sys/types.h>
+ #include <sys/uio.h>
+ #include <unistd.h>
+ #include <sys/stat.h>
+ #include <fcntl.h>
+ 
+ #define FPASSWD "/etc/passwd"
+ #define FGROUP  "/etc/group"
+ 
+ char *dlopen()  { return 0;}
+ int   dlclose() { return 0;}
+ char *dlsym()   { return 0;}
+ char *dlerror() { return "dynamic linking not loaded";}
+ 
+ typedef struct {
+   uid_t uid;
+   char *user_name;
+ } pw_entry;
+ 
+ typedef struct {
+   gid_t gid;
+   char *group_name;
+ } group_entry;
+ 
+ static pw_entry    *pw_array = NULL;
+ static group_entry *group_array = NULL;
+ 
+ static void fill_pw_array (void);
+ static void fill_group_array (void);
+ 
+ static void
+ fill_pw_array (void)
+ {
+   int fd;
+   int ok;
+   static char *pw_buf;
+   struct stat statbuf;
+   char *cp;
+   int n_entries;
+   int n_read;
+   int entry;
+ 
+   fd = open (FPASSWD, O_RDONLY);
+   if (fd < 0) {
+     fprintf (stderr, "Error opening password file.\n");
+     return;
+   }
+ 
+   ok = fstat (fd, &statbuf);
+   if (ok != 0) {
+     fprintf (stderr, "Error stat-ing passwd file.\n");
+     close (fd);
+     return;
+   }
+ 
+   pw_buf = malloc (statbuf.st_size + 1);
+   if (pw_buf == NULL) {
+     fprintf (stderr, "Error allocating memory.\n");
+     close (fd);
+     return;
+   }
+ 
+   n_read = read (fd, pw_buf, (size_t) statbuf.st_size);
+   if (n_read !=  statbuf.st_size) {
+     perror (NULL);
+     fprintf (stderr, "Error reading password file.\n");
+     free (pw_buf);
+     close (fd);
+     return;
+   }
+   pw_buf [statbuf.st_size] = '\0';
+   close (fd);
+ 
+   n_entries = 0;
+   for (cp = pw_buf; *cp != '\0'; cp++) {
+     if (*cp == '\n')
+       n_entries++;
+   }
+ 
+   pw_array = (pw_entry *) malloc ((n_entries + 1) * sizeof (pw_entry));
+   if (pw_array == NULL) {
+     fprintf (stderr, "Error allocating memory.\n");
+     free (pw_buf);
+     return;
+   }
+ 
+   pw_array [n_entries].uid = -1;
+   cp = pw_buf;
+   for (entry = 0; entry < n_entries; entry++) {
+     pw_array [entry].user_name = cp;
+     while (*cp != ':')
+       cp++;
+     *cp++ = '\0';
+     while (*cp != ':')
+       cp++;
+     cp++;
+     pw_array [entry].uid = atoi (cp);
+     while (*cp != '\n')
+       cp++;
+     cp++;
+   }
+ }
+ 
+ 
+ static void
+ fill_group_array (void)
+ {
+   int fd;
+   int ok;
+   static char *group_buf;
+   struct stat statbuf;
+   char *cp;
+   int n_entries;
+   int n_read;
+   int entry;
+ 
+   fd = open (FGROUP, O_RDONLY);
+   if (fd < 0) {
+     fprintf (stderr, "Error opening group file.\n");
+     return;
+   }
+ 
+   ok = fstat (fd, &statbuf);
+   if (ok != 0) {
+     fprintf (stderr, "Error stat-ing group file.\n");
+     close (fd);
+     return;
+   }
+ 
+   group_buf = malloc (statbuf.st_size + 1);
+   if (group_buf == NULL) {
+     fprintf (stderr, "Error allocating memory.\n");
+     close (fd);
+     return;
+   }
+ 
+   n_read = read (fd, group_buf, (size_t) statbuf.st_size);
+   if (n_read !=  statbuf.st_size) {
+     perror (NULL);
+     fprintf (stderr, "Error reading group file.\n");
+     free (group_buf);
+     close (fd);
+     return;
+   }
+   group_buf [statbuf.st_size] = '\0';
+   close (fd);
+ 
+   n_entries = 0;
+   for (cp = group_buf; *cp != '\0'; cp++) {
+     if (*cp == '\n')
+       n_entries++;
+   }
+ 
+   group_array =
+     (group_entry *) malloc ((n_entries + 1) * sizeof (group_entry));
+   if (group_array == NULL) {
+     fprintf (stderr, "Error allocating memory.\n");
+     free (group_buf);
+     return;
+   }
+ 
+   group_array [n_entries].gid = -1;
+   cp = group_buf;
+   for (entry = 0; entry < n_entries; entry++) {
+     group_array [entry].group_name = cp;
+     while (*cp != ':')
+       cp++;
+     *cp++ = '\0';
+     while (*cp != ':')
+       cp++;
+     cp++;
+     group_array [entry].gid = atoi (cp);
+     while (*cp != '\n')
+       cp++;
+     cp++;
+   }
+ }
+ 
+ char *
+ getuser(uid_t uid)
+ {
+   pw_entry *p_pw;
+   static char uid_str [11];
+ 
+   if (pw_array == NULL)
+     fill_pw_array ();
+   if (pw_array == NULL) {
+     sprintf (uid_str, "%lu", uid);
+     return uid_str;
+   }
+ 
+   for (p_pw = pw_array; p_pw->uid != -1; p_pw++) {
+     if (p_pw->uid == uid)
+       return p_pw->user_name;
+   }
+   sprintf (uid_str, "%lu", uid);
+   return uid_str;
+ }
+  
+ char *
+ getgroup(gid_t gid)
+ {
+   group_entry *p_group;
+   static char gid_str [11];
+ 
+   if (group_array == NULL)
+     fill_group_array ();
+   if (group_array == NULL) {
+     sprintf (gid_str, "%lu", gid);
+     return gid_str;
+   }
+ 
+   for (p_group = group_array; p_group->gid != -1; p_group++) {
+     if (p_group->gid == gid)
+       return p_group->group_name;
+   }
+   sprintf (gid_str, "%lu", gid);
+   return gid_str;
+ }

---

From: Emil Isberg <[email-masked]>
Date: Fri, 13 Dec 1996 21:05:14 +0100 (MET)

> one) for a successful static ls to be built.

libdl.a

---

From: Alain Magloire <[email-masked]>
Date: Fri, 13 Dec 1996 16:40:55 -0500 (EST)

> > one) for a successful static ls to be built.

Can you be so kind to give a __FULL__ path of that library

To compile ls statically I had to provide
stubs (dlclose.o, etc..) on the command line
see Solaris FAQ

--
alain

---

From: Alain Magloire <[email-masked]>
Date: Fri, 13 Dec 1996 22:43:26 -0500 (EST)

According to `Emil Isberg':
...
> patch <fileutils-3.13_static-ls.patch
[..patch deleted ..]

The major pains in the ... neck, of wu-ftpd are:
 - the chroot()
 - the external execution of ``bin/ls''
this two are probably 80%++ of this mailing list traffic.

Seing your static-ls patch(previous post) made me wonder
I hard will it be to have a BUILT_IN ``ls''
in wu-ftpd.

Having built_in ``ls'' may:
 - improve performance
 - will alleviate the needs 
   for those (*#&@^*&$) <-- put your best(worst) blasphemy here
     ~ftp/dev/*
     ~ftp/lib/*

Especially on Solaris well to have ``bin/ls'' kicking,
you must populate ~ftp/lib/* ... sigh

Unfortunatly, I will not have time to explore this (I promised
my girlfriend that I would not even look at a computer this chrismas).

But if someone have try this or have
Comments/suggestions/etc.. let me know.

P.S: The Net can be such a small world, just in case ...
     #ifdef GIRL_FRIEND
       (I love you dear ;-)
     #else
       (hello there)
     #endif
--
Joyeux Noe:l, alain

---

From: [email-masked]
Date: Sat, 14 Dec 1996 11:03:45 -0500 (EST)

> From: Alain Magloire <[email-masked]>

    Indeed I can't understand why wuftpd never used a built-in 'ls'. This
should not be impossible as anonftpd has one. But external libraries & co
will still be needed if you want to use tar/gtar/compress/gzip ( these might
be also implemented as built-in ) .

-- 
>Edit-Online<  International translations, multilanguage WWW creation & hosting
 Europe, Tokyo, Beijing, Seoul, Bangkok, Bombay, Washington, Rio, Buenos-Aires
  <(=-  [http://www.edit-online.com/] <*> [ftp://ftp.edit-online.com/]  -=)>
Frank DENIS aka Jedi/Sector One, network system administrator. Email: [email-masked]

---

From: Emil Isberg <[email-masked]>
Date: Sat, 14 Dec 1996 16:47:26 +0100 (MET)

> Can you be so kind to give a __FULL__ path of that library

The thing is that libdl.a is the .a file that sun neglected to ship with
Solaris 2.5 ..

> stubs (dlclose.o, etc..) on the command line

That is why you needed libdl.a .. to get those functions .. but as a
static-ls it really don't need those functions .. dlopen(), dlclose() ..
is handling the dunamically linked library ..

And for getting uid to user conversion you (according to solaris manuals)
really need the dl-functions .. or you can do as Brett Porter 
<[email-masked]> and I did .. patch the gnu ls ..
to fix the uid to user mapping .. and include the stubs .. It workes great
..
(I have sent it to the list ones .. I wont do it twice .. it should be in
the archive somewhere ..)

/Emil

---

From: Emil Isberg <[email-masked]>
Date: Sat, 14 Dec 1996 18:29:43 +0100 (MET)

> this two are probably 80%++ of this mailing list traffic.
hmm .. you are perhaps correct .. but I think I have seen more RQST for
FAQ (or similar) ..

> I hard will it be to have a BUILT_IN ``ls''
The patch is not an ls itself .. it is just a patch to include something
that already is in the gnufileutils .. the uid to user mapping ..

It wouldn't be hard to include that in wu-ftpd though .. a simple stat
will return the uid and .. and naturally is ls -lR not possible (if it
isn't coded) ..

and also it could be configured so that it uses the built in long_ls()
only if it is in chrooted environment ..

>    for those (*#&@^*&$) <-- put your best(worst) blasphemy here
hmm .. those libs would perhaps still be needed if you would want to run
extern programs .. (SITE_EXEC) ..

> you must populate ~ftp/lib/* ... sigh
Or you could patch gnufileutils .. and do a make ls ..
..

> my girlfriend that I would not even look at a computer this chrismas).
Hmm .. my gf is trying to force me to do the same.. :-( .. and I guess she
is really successful too .. :-)
But as I have work to do with my student union .. I have time to patch
(and learn how to patch) ..

> Comments/suggestions/etc.. let me know.
Hmm .. what about all of us out there on solaris2.5^ (the last ^ stands
for and up)

> be also implemented as built-in ) .
Hmm .. if all unix hackers (not cracker hacker, I ment programmer hacker)..
come together it wouldn't be that hard to fix that ..
you could do it as easy as a <hacked this function>.c with a header file
<hacked this function>.h that is included where the wu-ftpd-staff want it
to be called ..
ls -l could be called long_ls .. (long_ls.c,long_ls.h)
gtar -> gtar() .. (gtar.c,gtar.h) ..

but I think it is easier to use external commands ..

/Emil

---

From: Jim Davis <[email-masked]>
Date: Sun, 15 Dec 1996 16:58:45 -0700 (MST)

> you must populate ~ftp/lib/* ... sigh

You'll need stuff in ~/ftp/dev and ~/ftp/lib for other things, even with a
builtin (or static) ls. 

While a builtin ls shouldn't be difficult to add, and might be a useful
efficiency hack, under Solaris you'd still need stuff in ~ftp/lib if you
want a builtin ls to support all the different lookup options for user
names and groups.