From owner-freebsd-hackers@FreeBSD.ORG Mon Oct 24 19:31:55 2011 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 48F7F1065673 for ; Mon, 24 Oct 2011 19:31:55 +0000 (UTC) (envelope-from cjr@cruwe.de) Received: from cruwe.de (cruwe.de [188.40.164.98]) by mx1.freebsd.org (Postfix) with ESMTP id 9BCE98FC1B for ; Mon, 24 Oct 2011 19:31:54 +0000 (UTC) Received: from cruwe.de (unknown [127.0.0.4]) by cruwe.de (Postfix) with ESMTP id 2E1D828BA2 for ; Mon, 24 Oct 2011 19:31:53 +0000 (UTC) Received: by cruwe.de (Postfix, from userid 65534) id 0720B28BA1; Mon, 24 Oct 2011 19:31:52 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.cruwe.de X-Spam-Level: X-Spam-Status: No, score=-1.0 required=4.0 tests=ALL_TRUSTED autolearn=unavailable version=3.3.1 Received: from dijkstra (p5B37B849.dip.t-dialin.net [91.55.184.73]) (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) by cruwe.de (Postfix) with ESMTPSA id 4F43428B9B for ; Mon, 24 Oct 2011 19:31:50 +0000 (UTC) Date: Mon, 24 Oct 2011 21:31:40 +0200 From: "Christopher J. Ruwe" To: freebsd-hackers@freebsd.org Message-ID: <20111024213140.491467d9@dijkstra> In-Reply-To: <20111024001034.GE93709@dan.emsphone.com> References: <20111023235231.71f73ea3@dijkstra> <20111024001034.GE93709@dan.emsphone.com> X-Mailer: Claws Mail 3.7.10 (GTK+ 2.24.6; amd64-portbld-freebsd8.2) Mime-Version: 1.0 Content-Type: multipart/signed; micalg=PGP-SHA1; boundary="Sig_/P5vaMaWNyyCijVwDjLdeATL"; protocol="application/pgp-signature" X-Virus-Scanned: ClamAV on mail.cruwe.de using ClamSMTP Subject: Re: _SC_GETPW_R_SIZE_MAX undefined in sysconf.c, what is correct value? X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 24 Oct 2011 19:31:55 -0000 --Sig_/P5vaMaWNyyCijVwDjLdeATL Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable On Sun, 23 Oct 2011 19:10:34 -0500 Dan Nelson wrote: > In the last episode (Oct 23), Christopher J. Ruwe said: > > I need to get the maximum size of an pwd-entry to determine the > > correct buffersize for calling getpwnam_r("uname",&pwd, buf, > > bufsize, &pwdp). I would like to use sysconf(_SC_GETPW_R_SIZE_MAX) > > to determine bufsize, which unfornutately fails (returns -1). > > Currently, I used 16384, which seems to be too much, bit works for > > the time being. > >=20 > > From recent mails I get that _SC_GETPW_R_SIZE_MAX is not available > > on FreeBSD, e.g., > > http://lists.freebsd.org/pipermail/freebsd-ports-bugs/2009-September/17= 3081.html > > and > > http://www.redhat.com/archives/libvir-list/2011-May/msg01013.html. > > This assertion seems to be backed > > by /usr/srclib/libc/gen/sysconf.c, line 374. > >=20 > > From Stevens & Rago, Adavanced Programming in the UNIX Environment, > > I can get that FreeBSD supports all possible members in the passwd > > structure, but where can I determine the maximum size of these so > > that I can calculate the ax size of the pwd struct therefrom? Does > > anybody know or know where to look what maximum size a pwd-entry > > can have? > >=20 > > Knowing the maximum size a pwd structure can have, it seems like to > > be an idea to define the correct value in sysconf.c. As that is > > not done though suggested in the code, are there any obstacles in > > defining that value so nobody has done that so far? >=20 > >From looking at the libc/gen/getpwent.c file, it looks like a > >maximum size > might be 1MB. The wrapper functions that convert getpw*_r functions > into ones that simply return a pointer to malloced data all use the > getpw() helper function, which starts with a 1k buffer and keeps > doubling its size until the data fits or it hits PWD_STORAGE_MAX > (1MB). PWD_STORAGE_MAX is only checked within that getpw() function, > though, so it's possible that an nss library might return an even > longer string to a get*_r call. It's up to you to decide what your > own limit is :) >=20 Uh ... it's just that I hoped I had not to decide ;-) However, 1M seems to be rather large to me. Let's see (pwd.h): 116 struct passwd { 117 char *pw_name; /* user name */ 118 char *pw_passwd; /* encrypted password */ 119 uid_t pw_uid; /* user uid */ 120 gid_t pw_gid; /* user gid */ 121 time_t pw_change; /* password change time */ 122 char *pw_class; /* user access class */ 123 char *pw_gecos; /* Honeywell login info */ 124 char *pw_dir; /* home directory */ 125 char *pw_shell; /* default shell */ 126 time_t pw_expire; /* account expiration */ 127 int pw_fields; /* internal: fields filled in */ 128 }; So pw_name -> MAXLOGNAME (from param.h) =3D 17. pw_passwd -> http://www.fre= ebsd.org/doc/handbook/one-time-passwords.html =3D 129. pw_uid & pw_gid each= sizeof(__uint32_t) ?=3D 32b. time_t -> sizeof(__int64_t) ?=3D 64b. At some point, I would just sum it up and reach some size which might be ma= chine dependant, but should be somewhere (guessing/estimating now) between = 4k and 16k. I am short on time just now, am I on the right track or am I mi= ssing something which should be obvious to someone with experience, but is = not to me (lacking experience)? Thanks and regards, --=20 Christopher J. Ruwe TZ GMT + 2 --Sig_/P5vaMaWNyyCijVwDjLdeATL Content-Type: application/pgp-signature; name=signature.asc Content-Disposition: attachment; filename=signature.asc -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.18 (FreeBSD) iQIcBAEBAgAGBQJOpb0jAAoJEJTIKW/o3iwUa6sP/0yAryZNwL/gT0WGAXjkm7Th hjxhJnD27nlTPl1GCCVvbvLHlS0+hRoZnGK/Ud9ftTcAzMKaVk3MHTKM+U8JUUmZ xWwBnw1sIGJFyf2yKxyaRJV0EYIk1q7+p0gfvDbnKEmV3lIPjsy+yeVQB1B73TXK w2wF27tzvngOK8STPlxh/kRfiw7UYRiD5tAbf6EoE8iUr+5xKMTRfmGtK/s5wWpW 2OTX2bz4yx2rzvpV5tuTllsIavmVa8mZM03+9km8lG6XwRAWc8FK4HdpN2CYpFnP U6OFvq+smFSFYlGAthErXJ/K6UfJLPYjAUeWLojUiiCqGil6lEKPeUDTDjk/PuvB +stFLKAYxMEUIksk9hgRJmtMQzFWAGvQSpgxn2TFxK1RV/dgLGMjUOI0KuHElzr1 3otzDwZRJpDvN4svAYpfnAF17X4qAJLaFGVLg/0bq2xUZvRjooqub/FAl7cneAFV dXlqnRaRMppvOLxvohfQtambnweKaAcZyTdfM9MI3hy2L+bHALHWdHNocDOuILW/ c+bp/bx6bBbuXvagw5Uwf573nLZbiKYDXz5MkY/4X9/Z/MLALjNLTbYhX7N9bHZ4 E2MWojnurWjiEDXrsxiJsg+x6dxaNEX7zH0qwSUgOoEF1wyyppa2Coq+m3cCAtxk 5aMFPi//89XLMdmjhghi =i4ql -----END PGP SIGNATURE----- --Sig_/P5vaMaWNyyCijVwDjLdeATL--