Date: Sun, 22 Feb 1998 10:17:03 +1100 (EST) From: danny@FreeBSD.ORG To: FreeBSD-gnats-submit@FreeBSD.ORG Subject: bin/5812: ftpd's INTERNAL_LS can't find spwd.db and complains Message-ID: <199802212317.KAA26992@news.hilink.com.au>
next in thread | raw e-mail | index | archive | help
>Number: 5812 >Category: bin >Synopsis: ftpd with INTERNAL_LS and ftpchroot user causes errors to be logged >Confidential: no >Severity: non-critical >Priority: medium >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Sat Feb 21 15:20:00 PST 1998 >Last-Modified: >Originator: Daniel O'Callaghan >Organization: HiLink Internet >Release: FreeBSD 2.2.2-RELEASE and above >Environment: ftpd compile with FTPD_INTERNAL_LS, an ftpchroot user >Description: When an ftpchroot user uses 'ls' with the INTERNAL_LS, the ls command attempts to translate uid/gid into names. Because the ftpd has access to the syslog socket, logged errors do appear, rather than disappearing as in the case where a separate ls(1) is run within the chrooted area. The error is of the form 'spwd.db: no such file or directory'. While harmless, these error messages can be quite irritating for sysadmins, especially on busy systems. >How-To-Repeat: Build ftpd with INTERNAL_LS Define a user listed in /etc/ftpchroot or with ftpchroot login.conf boolean. ftp to system as the user and perform ls operation tail /var/log/messages >Fix: Below are diffs to ls.c which (a) add a -N flag to allow suppression of ugid -> ugname conversion; and (b) automatically invoke -N if _PATH_SMP_DB is not available. --- ls.c.orig Thu Dec 18 17:09:16 1997 +++ ls.c Fri Feb 20 23:04:15 1998 @@ -59,6 +59,8 @@ #include <string.h> #include <unistd.h> #include <locale.h> +#include <pwd.h> +#include <fcntl.h> #include "ls.h" #include "extern.h" @@ -85,6 +87,7 @@ int f_newline; /* if precede with newline */ int f_nonprint; /* show unprintables as ? */ int f_nosort; /* don't sort output */ +int f_numeric; /* don't translate uid/gid */ int f_recursive; /* ls subdirectories also */ int f_reversesort; /* reverse whatever sort is used */ int f_sectime; /* print the real time for all files */ @@ -131,7 +134,7 @@ f_listdot = 1; fts_options = FTS_PHYSICAL; - while ((ch = getopt(argc, argv, "1ACFLRTacdfgikloqrstu")) != EOF) { + while ((ch = getopt(argc, argv, "1ACFLNRTacdfgikloqrstu")) != EOF) { switch (ch) { /* * The -1, -C and -l options all override each other so shell @@ -165,6 +168,9 @@ fts_options &= ~FTS_PHYSICAL; fts_options |= FTS_LOGICAL; break; + case 'N': + f_numeric = 1; + break; case 'R': f_recursive = 1; break; @@ -269,6 +275,12 @@ else printfcn = printcol; + /* Is the password db available? */ + if ((notused = open(_PATH_SMP_DB, O_RDONLY, 0)) > 0) + close(notused); + else + f_numeric = 1; + if (argc) traverse(argc, argv, fts_options); else @@ -362,7 +374,10 @@ u_long btotal, maxblock, maxinode, maxlen, maxnlink; int bcfile, flen, glen, ulen, maxflags, maxgroup, maxuser; int entries, needstats; - char *user, *group, *flags, buf[20]; /* 32 bits == 10 digits */ + char *flags, buf[20]; /* 32 bits == 10 digits */ +# define UGIDLEN 6 + char uid[UGIDLEN], gid[UGIDLEN]; + char *user, *group; /* * If list is NULL there are two possibilities: that the parent @@ -424,10 +439,17 @@ btotal += sp->st_blocks; if (f_longform) { - user = user_from_uid(sp->st_uid, 0); + if (f_numeric) { + snprintf(uid, UGIDLEN, "%u", sp->st_uid); + user = uid; + snprintf(gid, UGIDLEN, "%u", sp->st_gid); + group = gid; + } else { + user = user_from_uid(sp->st_uid, 0); + group = group_from_gid(sp->st_gid, 0); + } if ((ulen = strlen(user)) > maxuser) maxuser = ulen; - group = group_from_gid(sp->st_gid, 0); if ((glen = strlen(group)) > maxgroup) maxgroup = glen; if (f_flags) { --- ls.1.orig Sun Feb 22 10:14:02 1998 +++ ls.1 Sun Feb 22 10:13:15 1998 @@ -43,7 +43,7 @@ .Nd list directory contents .Sh SYNOPSIS .Nm ls -.Op Fl ACFLRTacdfgikloqrstu1 +.Op Fl ACFLNRTacdfgikloqrstu1 .Op Ar file ... .Sh DESCRIPTION For each operand that names a @@ -89,6 +89,8 @@ .It Fl L If argument is a symbolic link, list the file or directory the link references rather than the link itself. +.It Fl N +Don't translate uid/gid to uname/group. .It Fl R Recursively list subdirectories encountered. .It Fl T >Audit-Trail: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199802212317.KAA26992>